crt1.S 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* Startup code for elf{32,64}-sparc
  2. Copyright (C) 1997, 1998, 2002, 2004 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Richard Henderson <richard@gnu.ai.mit.edu>, 1997.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. In addition to the permissions in the GNU Lesser General Public
  10. License, the Free Software Foundation gives you unlimited
  11. permission to link the compiled version of this file with other
  12. programs, and to distribute those programs without any restriction
  13. coming from the use of this file. (The GNU Lesser General Public
  14. License restrictions do apply in other respects; for example, they
  15. cover modification of the file, and distribution when not linked
  16. into another program.)
  17. Note that people who make modified versions of this file are not
  18. obligated to grant this special exception for their modified
  19. versions; it is their choice whether to do so. The GNU Lesser
  20. General Public License gives permission to release a modified
  21. version without this exception; this exception also makes it
  22. possible to release a modified version which carries forward this
  23. exception.
  24. The GNU C Library is distributed in the hope that it will be useful,
  25. but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  27. Lesser General Public License for more details.
  28. You should have received a copy of the GNU Lesser General Public
  29. License along with the GNU C Library; if not, see
  30. <http://www.gnu.org/licenses/>. */
  31. /* Originally based on glibc's sysdeps/sparc/sparc{32,64}/elf/start.S */
  32. #include <features.h>
  33. #include <bits/wordsize.h>
  34. # define STACK_BIAS 0
  35. # define ELE_SIZE 4
  36. # define LD ld
  37. .text
  38. .align 4
  39. .global _start
  40. .type _start,%function
  41. #if defined(__UCLIBC_CTOR_DTOR__)
  42. .type _init,%function
  43. .type _fini,%function
  44. #else
  45. .weak _init
  46. .weak _fini
  47. #endif
  48. .type __uClibc_main,%function
  49. /* Stick in a dummy reference to main(), so that if an application
  50. * is linking when the main() function is in a static library (.a)
  51. * we can be sure that main() actually gets linked in */
  52. .global main
  53. .type main,%function
  54. #ifdef __PIC__
  55. .LLGETPC0:
  56. retl
  57. add %o7, %l7, %l7
  58. #endif
  59. _start:
  60. #ifdef __PIC__
  61. sethi %hi(_GLOBAL_OFFSET_TABLE_-4), %l7
  62. call .LLGETPC0
  63. add %l7, %lo(_GLOBAL_OFFSET_TABLE_+4), %l7
  64. #endif
  65. /* Terminate the stack frame, and reserve space for functions to
  66. * drop their arguments. */
  67. mov %g0, %fp
  68. sub %sp, 6*ELE_SIZE, %sp
  69. /* Extract the arguments and environment as encoded on the stack. The
  70. * argument info starts after one register window (16 words) past the SP. */
  71. LD [%sp+STACK_BIAS+22*ELE_SIZE], %o1 /* %o1 = argc */
  72. add %sp, STACK_BIAS+23*ELE_SIZE, %o2 /* %o2 = argv */
  73. /* Load the addresses of the user entry points. */
  74. sethi %hi(main), %o0
  75. sethi %hi(_init), %o3
  76. sethi %hi(_fini), %o4
  77. or %o0, %lo(main), %o0
  78. or %o3, %lo(_init), %o3
  79. or %o4, %lo(_fini), %o4
  80. #ifdef __PIC__
  81. /* Need a little more magic when building PIC to get addr of main */
  82. LD [%l7 + %o0], %o0
  83. LD [%l7 + %o3], %o3
  84. LD [%l7 + %o4], %o4
  85. #endif
  86. /* When starting a binary via the dynamic linker, %g1 contains the
  87. * address of the shared library termination function, which will be
  88. * registered with atexit(). If we are statically linked, this will
  89. * be NULL. */
  90. mov %g1, %o5
  91. /* Let libc do the rest of the initialization, and call main. */
  92. call __uClibc_main
  93. nop
  94. /* Die very horribly if exit returns. */
  95. unimp
  96. .size _start,.-_start
  97. /* Define a symbol for the first piece of initialized data. */
  98. .data
  99. .global __data_start
  100. __data_start:
  101. .long 0
  102. .weak data_start
  103. data_start = __data_start