crt1.S 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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, write to the Free
  29. Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
  30. Boston, MA 02110-1301, USA. */
  31. #include <features.h>
  32. #ifndef __UCLIBC_CTOR_DTOR__
  33. .weak _init
  34. .weak _fini
  35. #endif
  36. /* This is the canonical entry point, usually the first thing in the text
  37. segment. When the entry point runs, most register values are unspecified,
  38. except for:
  39. a2 Contains a function pointer to be registered with `atexit'.
  40. This is how the dynamic linker arranges to have DT_FINI
  41. functions called for shared libraries that have been loaded
  42. before this code runs.
  43. a1 The stack (i.e., a1+16) contains the arguments and environment:
  44. a1+0 argc
  45. a1+4 argv[0]
  46. ...
  47. a1+(4*argc) NULL
  48. a1+(4*(argc+1)) envp[0]
  49. ...
  50. NULL
  51. Setup parameters accordingly (for a call4). See function prototype
  52. from sysdeps/generic/libc-start.c
  53. a6 = *main
  54. a7 = argc
  55. a8 = ubp_av
  56. a9 = *init
  57. a10 = *fini
  58. a11 = *rtld_fini
  59. [sp+0] = stack_end
  60. */
  61. .text
  62. .align 4
  63. .literal_position
  64. .global _start
  65. .type _start, @function
  66. _start:
  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. /* Crash if somehow `exit' does return. */
  90. ill
  91. /* Define a symbol for the first piece of initialized data. */
  92. .data
  93. .align 4
  94. .global __data_start
  95. __data_start:
  96. .long 0
  97. .weak data_start
  98. data_start = __data_start