crt1.S 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /* Startup code compliant to the ELF Xtensa ABI.
  2. Copyright (C) 2001, 2007 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. <http://www.gnu.org/licenses/>. */
  30. #include <features.h>
  31. #ifndef __UCLIBC_CTOR_DTOR__
  32. .weak _init
  33. .weak _fini
  34. #endif
  35. /* This is the canonical entry point, usually the first thing in the text
  36. segment. When the entry point runs, most register values are unspecified,
  37. except for:
  38. a2 Contains a function pointer to be registered with `atexit'.
  39. This is how the dynamic linker arranges to have DT_FINI
  40. functions called for shared libraries that have been loaded
  41. before this code runs.
  42. a1 The stack (i.e., a1+16) contains the arguments and environment:
  43. a1+0 argc
  44. a1+4 argv[0]
  45. ...
  46. a1+(4*argc) NULL
  47. a1+(4*(argc+1)) envp[0]
  48. ...
  49. NULL
  50. Setup parameters accordingly (for a call4). See function prototype
  51. from sysdeps/generic/libc-start.c
  52. a6 = *main
  53. a7 = argc
  54. a8 = ubp_av
  55. a9 = *init
  56. a10 = *fini
  57. a11 = *rtld_fini
  58. [sp+0] = stack_end
  59. */
  60. .text
  61. .align 4
  62. .literal_position
  63. .global _start
  64. .type _start, @function
  65. _start:
  66. #if defined(__XTENSA_WINDOWED_ABI__)
  67. /* Clear a0 to obviously mark the outermost frame. */
  68. movi a0, 0
  69. /* Load up the user's main function. */
  70. movi a6, main
  71. /* Extract the arguments as encoded on the stack and set up
  72. the arguments for `main': argc, argv. envp will be determined
  73. later in __uClibc_main. */
  74. l32i a7, a1, 0 /* Load the argument count. */
  75. addi a8, a1, 4 /* Compute the argv pointer. */
  76. /* Push address of our own entry points to .fini and .init. */
  77. movi a9, _init
  78. movi a10, _fini
  79. /* Setup the shared library termination function. */
  80. mov a11, a2
  81. /* Provide the highest stack address to the user code (for stacks
  82. which grow downwards). Note that we destroy the stack version
  83. of argc here. */
  84. s32i a1, a1, 0
  85. /* Call the user's main function, and exit with its value.
  86. But let the libc call main. */
  87. movi a4, __uClibc_main
  88. callx4 a4
  89. #elif defined(__XTENSA_CALL0_ABI__)
  90. /* Setup the shared library termination function. */
  91. mov a7, a2
  92. /* Load up the user's main function. */
  93. movi a2, main
  94. /* Extract the arguments as encoded on the stack and set up
  95. the arguments for `main': argc, argv. envp will be determined
  96. later in __uClibc_main. */
  97. l32i a3, a1, 0 /* Load the argument count. */
  98. addi a4, a1, 4 /* Compute the argv pointer. */
  99. /* Push address of our own entry points to .fini and .init. */
  100. movi a5, _init
  101. movi a6, _fini
  102. /* Provide the highest stack address to the user code (for stacks
  103. which grow downwards). Note that we destroy the stack version
  104. of argc here. */
  105. s32i a1, a1, 0
  106. /* Call the user's main function, and exit with its value.
  107. But let the libc call main. */
  108. movi a0, __uClibc_main
  109. callx0 a0
  110. #else
  111. #error Unsupported Xtensa ABI
  112. #endif
  113. /* Crash if somehow `exit' does return. */
  114. ill
  115. /* Define a symbol for the first piece of initialized data. */
  116. .data
  117. .align 4
  118. .global __data_start
  119. __data_start:
  120. .long 0
  121. .weak data_start
  122. data_start = __data_start