crt1.S 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. /* Clear a0 to obviously mark the outermost frame. */
  67. movi a0, 0
  68. /* Load up the user's main function. */
  69. movi a6, main
  70. /* Extract the arguments as encoded on the stack and set up
  71. the arguments for `main': argc, argv. envp will be determined
  72. later in __uClibc_main. */
  73. l32i a7, a1, 0 /* Load the argument count. */
  74. addi a8, a1, 4 /* Compute the argv pointer. */
  75. /* Push address of our own entry points to .fini and .init. */
  76. movi a9, _init
  77. movi a10, _fini
  78. /* Setup the shared library termination function. */
  79. mov a11, a2
  80. /* Provide the highest stack address to the user code (for stacks
  81. which grow downwards). Note that we destroy the stack version
  82. of argc here. */
  83. s32i a1, a1, 0
  84. /* Call the user's main function, and exit with its value.
  85. But let the libc call main. */
  86. movi a4, __uClibc_main
  87. callx4 a4
  88. /* Crash if somehow `exit' does return. */
  89. ill
  90. /* Define a symbol for the first piece of initialized data. */
  91. .data
  92. .align 4
  93. .global __data_start
  94. __data_start:
  95. .long 0
  96. .weak data_start
  97. data_start = __data_start