crt1.S 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public License as
  5. published by the Free Software Foundation; either version 2 of the
  6. License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with the GNU C Library; see the file COPYING.LIB. If
  13. not, see <http://www.gnu.org/licenses/>. */
  14. /* When we enter this piece of code, the user stack looks like this:
  15. * argc argument counter (integer)
  16. * argv[0] program name (pointer)
  17. * argv[1...N] program args (pointers)
  18. * NULL
  19. * env[0...N] environment variables (pointers)
  20. * NULL
  21. * When we are done here, we want
  22. * R0=argc
  23. * R1=*argv[0]
  24. * R2=*envp[0]
  25. */
  26. #include <features.h>
  27. #undef USE_GOT
  28. #if defined (__UCLIBC_FORMAT_SHARED_FLAT__) || defined (__UCLIBC_FORMAT_FLAT_SEP_DATA__)
  29. #define USE_GOT
  30. #endif
  31. #if !(defined L_Scrt1 && defined __UCLIBC_FORMAT_SHARED_FLAT__)
  32. .text
  33. .align 2
  34. .global __start;
  35. .type __start,STT_FUNC;
  36. .weak __init;
  37. .weak __fini;
  38. .global ___uClibc_main;
  39. .type ___uClibc_main,STT_FUNC;
  40. /* Stick in a dummy reference to main(), so that if an application
  41. * is linking when the main() function is in a static library (.a)
  42. * we can be sure that main() actually gets linked in */
  43. .type _main,STT_FUNC;
  44. __start:
  45. #if defined(__BFIN_FDPIC__) && !defined(L_Scrt1)
  46. /* P0 contains a pointer to the program's load map. */
  47. call .Lcall;
  48. .Lcall:
  49. R4 = RETS;
  50. SP += -12;
  51. R0.L = .Lcall;
  52. R0.H = .Lcall;
  53. R1.L = __ROFIXUP_LIST__;
  54. R1.H = __ROFIXUP_LIST__;
  55. R2.L = __ROFIXUP_END__;
  56. R2.H = __ROFIXUP_END__;
  57. R1 = R1 - R0;
  58. R1 = R1 + R4;
  59. R2 = R2 - R0;
  60. R2 = R2 + R4;
  61. R0 = P0;
  62. CALL ___self_reloc;
  63. SP += 12;
  64. P3 = R0;
  65. #endif
  66. /* clear the frame pointer and the L registers. */
  67. FP = 0;
  68. L0 = 0;
  69. L1 = 0;
  70. L2 = 0;
  71. L3 = 0;
  72. #ifdef __ID_SHARED_LIB__
  73. /* We know we have a local copy, so we can avoid the GOT. */
  74. CALL ___shared_flat_add_library;
  75. #endif
  76. /* Load register R1 (argc) from the stack to its final resting place */
  77. P0 = SP;
  78. R1 = [P0++];
  79. /* Copy argv pointer into R2 -- which its final resting place */
  80. R2 = P0;
  81. SP += -28;
  82. #ifndef __BFIN_FDPIC__
  83. R7 = 0;
  84. #endif
  85. /* Pass highest stack pointer to the app. */
  86. [SP + 24] = P2;
  87. /* Store the pointer to ld.so's fini that we got in P1. */
  88. [SP + 20] = R7;
  89. /* Ok, now run uClibc's main() -- shouldn't return */
  90. #if (defined L_crt1 || defined L_Scrt1) && defined __UCLIBC_CTOR_DTOR__
  91. #ifdef __BFIN_FDPIC__
  92. R3 = [P3 + __init@FUNCDESC_GOT17M4];
  93. #elif defined USE_GOT
  94. R3 = [P5 + ___shared_flat_init@GOT];
  95. #else
  96. R3.H = __init;
  97. R3.L = __init;
  98. #endif
  99. [SP+12] = R3;
  100. #ifdef __BFIN_FDPIC__
  101. R3 = [P3 + __fini@FUNCDESC_GOT17M4];
  102. #elif defined USE_GOT
  103. R3 = [P5 + ___shared_flat_fini@GOT];
  104. #else
  105. R3.H = __fini;
  106. R3.L = __fini;
  107. #endif
  108. [SP+16] = R3;
  109. #else /* no ctor/dtor handling */
  110. R3 = 0;
  111. [SP + 12] = R3;
  112. [SP + 16] = R3;
  113. #endif
  114. #ifdef __BFIN_FDPIC__
  115. R0 = [P3 + _main@FUNCDESC_GOT17M4];
  116. #elif defined USE_GOT
  117. R0 = [P5 + _main@GOT];
  118. #else
  119. R0.H = _main;
  120. R0.L = _main;
  121. #endif
  122. #ifdef USE_GOT
  123. P0 = [P5 + ___uClibc_main@GOT];
  124. jump (P0)
  125. #else
  126. jump.l ___uClibc_main;
  127. #endif
  128. #else
  129. .text
  130. .global lib_main
  131. .hidden lib_main
  132. .type lib_main,@function
  133. lib_main:
  134. RETS = [SP++];
  135. /* We know we have a local copy, so we can avoid the GOT. */
  136. JUMP.L ___shared_flat_add_library;
  137. .hidden _current_shared_library_p5_offset_
  138. #endif
  139. .section .note.GNU-stack,"",%progbits