start.S 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* Startup code for ARC.
  2. Copyright (C) 2020-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. In addition to the permissions in the GNU Lesser General Public
  9. License, the Free Software Foundation gives you unlimited
  10. permission to link the compiled version of this file with other
  11. programs, and to distribute those programs without any restriction
  12. coming from the use of this file. (The GNU Lesser General Public
  13. License restrictions do apply in other respects; for example, they
  14. cover modification of the file, and distribution when not linked
  15. into another program.)
  16. Note that people who make modified versions of this file are not
  17. obligated to grant this special exception for their modified
  18. versions; it is their choice whether to do so. The GNU Lesser
  19. General Public License gives permission to release a modified
  20. version without this exception; this exception also makes it
  21. possible to release a modified version which carries forward this
  22. exception.
  23. The GNU C Library is distributed in the hope that it will be useful,
  24. but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  26. Lesser General Public License for more details.
  27. You should have received a copy of the GNU Lesser General Public
  28. License along with the GNU C Library; if not, see
  29. <https://www.gnu.org/licenses/>. */
  30. #define __ASSEMBLY__ 1
  31. #include <entry.h>
  32. #include <sysdep.h>
  33. #ifndef ENTRY_POINT
  34. # error ENTRY_POINT needs to be defined for ARC
  35. #endif
  36. /* When we enter this piece of code, the program stack looks like this:
  37. argc argument counter (integer)
  38. argv[0] program name (pointer)
  39. argv[1...N] program args (pointers)
  40. argv[argc-1] end of args (integer)
  41. NULL
  42. env[0...N] environment variables (pointers)
  43. NULL. */
  44. ENTRY (ENTRY_POINT)
  45. /* Needed to make gdb backtraces stop here. */
  46. .cfi_label .Ldummy
  47. cfi_undefined (blink)
  48. mov fp, 0
  49. ld_s r1, [sp] /* argc. */
  50. mov_s r5, r0 /* rltd_fini. */
  51. add_s r2, sp, 4 /* argv. */
  52. and sp, sp, -8
  53. mov r6, sp
  54. /* __libc_start_main (main, argc, argv, init, fini, rtld_fini, stack_end). */
  55. mov_s r3, 0 /* Used to be init. */
  56. mov r4, 0 /* Used to be fini. */
  57. #ifdef SHARED
  58. ld r0, [pcl, @main@gotpc]
  59. bl __libc_start_main@plt
  60. #else
  61. mov_s r0, main
  62. bl __libc_start_main
  63. #endif
  64. /* Should never get here. */
  65. flag 1
  66. END (ENTRY_POINT)
  67. /* Define a symbol for the first piece of initialized data. */
  68. .data
  69. .globl __data_start
  70. __data_start:
  71. .long 0
  72. .weak data_start
  73. data_start = __data_start