crt1.S 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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, write to the Free
  30. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  31. 02111-1307 USA. */
  32. /* Originally based on glibc's sysdeps/sparc/sparc{32,64}/elf/start.S */
  33. #include <features.h>
  34. #include <bits/wordsize.h>
  35. /* macro out the 32 / 64 bit differences */
  36. #if __WORDSIZE == 32
  37. # define STACK_BIAS 0
  38. # define ELE_SIZE 4
  39. # define LD ld
  40. #else
  41. # define STACK_BIAS 2047 /* see glibc/sysdeps/unix/sysv/linux/sparc/sparc64/sysdep.h */
  42. # define ELE_SIZE 8
  43. # define LD ldx
  44. #endif
  45. .text
  46. .align 4
  47. .global _start
  48. .type _start,%function
  49. #if defined(__UCLIBC_CTOR_DTOR__)
  50. .type _init,%function
  51. .type _fini,%function
  52. #else
  53. .weak _init
  54. .weak _fini
  55. #endif
  56. .type __uClibc_main,%function
  57. /* Stick in a dummy reference to main(), so that if an application
  58. * is linking when the main() function is in a static library (.a)
  59. * we can be sure that main() actually gets linked in */
  60. .global main
  61. .type main,%function
  62. #ifdef __PIC__
  63. .LLGETPC0:
  64. retl
  65. add %o7, %l7, %l7
  66. #endif
  67. _start:
  68. #ifdef __PIC__
  69. sethi %hi(_GLOBAL_OFFSET_TABLE_-4), %l7
  70. call .LLGETPC0
  71. add %l7, %lo(_GLOBAL_OFFSET_TABLE_+4), %l7
  72. #endif
  73. /* Terminate the stack frame, and reserve space for functions to
  74. * drop their arguments. */
  75. mov %g0, %fp
  76. sub %sp, 6*ELE_SIZE, %sp
  77. /* Extract the arguments and environment as encoded on the stack. The
  78. * argument info starts after one register window (16 words) past the SP. */
  79. LD [%sp+STACK_BIAS+22*ELE_SIZE], %o1 /* %o1 = argc */
  80. add %sp, STACK_BIAS+23*ELE_SIZE, %o2 /* %o2 = argv */
  81. /* Load the addresses of the user entry points. */
  82. sethi %hi(main), %o0
  83. sethi %hi(_init), %o3
  84. sethi %hi(_fini), %o4
  85. or %o0, %lo(main), %o0
  86. or %o3, %lo(_init), %o3
  87. or %o4, %lo(_fini), %o4
  88. #ifdef __PIC__
  89. /* Need a little more magic when building PIC to get addr of main */
  90. LD [%l7 + %o0], %o0
  91. LD [%l7 + %o3], %o3
  92. LD [%l7 + %o4], %o4
  93. #endif
  94. /* When starting a binary via the dynamic linker, %g1 contains the
  95. * address of the shared library termination function, which will be
  96. * registered with atexit(). If we are statically linked, this will
  97. * be NULL. */
  98. mov %g1, %o5
  99. /* Let libc do the rest of the initialization, and call main. */
  100. call __uClibc_main
  101. nop
  102. /* Die very horribly if exit returns. */
  103. #if __WORDSIZE == 32
  104. unimp
  105. #else
  106. illtrap 0
  107. #endif
  108. .size _start,.-_start
  109. /* Define a symbol for the first piece of initialized data. */
  110. .data
  111. .global __data_start
  112. __data_start:
  113. .long 0
  114. .weak data_start
  115. data_start = __data_start