crt1.S 4.1 KB

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