crt1.S 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* Startup code for elf64-sparc
  2. Copyright (C) 1997-2017 Free Software Foundation, Inc.
  3. Contributed by Richard Henderson <richard@gnu.ai.mit.edu>, 1997.
  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. #include <sysdep.h>
  32. .text
  33. .align 4
  34. .global _start
  35. .type _start,%function
  36. #if defined(__UCLIBC_CTOR_DTOR__)
  37. .type _init,%function
  38. .type _fini,%function
  39. #else
  40. .weak _init
  41. .weak _fini
  42. #endif
  43. .type __uClibc_main,%function
  44. /* Stick in a dummy reference to main(), so that if an application
  45. * is linking when the main() function is in a static library (.a)
  46. * we can be sure that main() actually gets linked in */
  47. .global main
  48. .type main,%function
  49. #ifdef __PIC__
  50. .LLGETPC0:
  51. retl
  52. add %o7, %l7, %l7
  53. #endif
  54. _start:
  55. #ifdef __PIC__
  56. sethi %hi(_GLOBAL_OFFSET_TABLE_-4), %l7
  57. call .LLGETPC0
  58. add %l7, %lo(_GLOBAL_OFFSET_TABLE_+4), %l7
  59. #endif
  60. /* Terminate the stack frame, and reserve space for functions to
  61. * drop their arguments. */
  62. mov %g0, %fp
  63. sub %sp, 6*8, %sp
  64. /* Extract the arguments and environment as encoded on the stack. The
  65. argument info starts after one register window (16 words) past the SP,
  66. plus the bias we added, plus the magic v9 STACK_BIAS. */
  67. ldx [%sp+STACK_BIAS+22*8], %o1 /* %o1 = argc */
  68. add %sp, STACK_BIAS+23*8, %o2 /* %o2 = argv */
  69. /* Load the addresses of the user entry points. */
  70. sethi %hi(main), %o0
  71. sethi %hi(_init), %o3
  72. sethi %hi(_fini), %o4
  73. or %o0, %lo(main), %o0
  74. or %o3, %lo(_init), %o3
  75. or %o4, %lo(_fini), %o4
  76. #ifdef __PIC__
  77. /* Need a little more magic when building PIC to get addr of main */
  78. LD [%l7 + %o0], %o0
  79. LD [%l7 + %o3], %o3
  80. LD [%l7 + %o4], %o4
  81. #endif
  82. /* When starting a binary via the dynamic linker, %g1 contains the
  83. * address of the shared library termination function, which will be
  84. * registered with atexit(). If we are statically linked, this will
  85. * be NULL. */
  86. mov %g1, %o5
  87. /* Let libc do the rest of the initialization, and call main. */
  88. call __uClibc_main
  89. nop
  90. /* Die very horribly if exit returns. */
  91. unimp
  92. .size _start,.-_start
  93. /* Define a symbol for the first piece of initialized data. */
  94. .data
  95. .global __data_start
  96. __data_start:
  97. .long 0
  98. .weak data_start
  99. data_start = __data_start