crt1.S 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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, write to the Free Software Foundation, Inc., 675 Mass Ave,
  14. Cambridge, MA 02139, USA. */
  15. /* When we enter this piece of code, the user stack looks like this:
  16. * argc argument counter (integer)
  17. * argv[0] program name (pointer)
  18. * argv[1...N] program args (pointers)
  19. * NULL
  20. * env[0...N] environment variables (pointers)
  21. * NULL
  22. * When we are done here, we want
  23. * R0=argc
  24. * R1=*argv[0]
  25. * R2=*envp[0]
  26. */
  27. #include <features.h>
  28. #undef USE_GOT
  29. #if defined (__UCLIBC_FORMAT_SHARED_FLAT__) || defined (__UCLIBC_FORMAT_FLAT_SEP_DATA__)
  30. #define USE_GOT
  31. #endif
  32. #if !(defined L_Scrt1 && defined __UCLIBC_FORMAT_SHARED_FLAT__)
  33. .text
  34. .align 2
  35. .global __start;
  36. .type __start,STT_FUNC;
  37. .weak __init;
  38. .weak __fini;
  39. .global ___uClibc_main;
  40. .type ___uClibc_main,STT_FUNC;
  41. /* Stick in a dummy reference to main(), so that if an application
  42. * is linking when the main() function is in a static library (.a)
  43. * we can be sure that main() actually gets linked in */
  44. .type _main,STT_FUNC;
  45. __start:
  46. #if defined(__BFIN_FDPIC__) && !defined(L_Scrt1)
  47. /* P0 contains a pointer to the program's load map. */
  48. call .Lcall;
  49. .Lcall:
  50. R4 = RETS;
  51. SP += -12;
  52. R0.L = .Lcall;
  53. R0.H = .Lcall;
  54. R1.L = __ROFIXUP_LIST__;
  55. R1.H = __ROFIXUP_LIST__;
  56. R2.L = __ROFIXUP_END__;
  57. R2.H = __ROFIXUP_END__;
  58. R1 = R1 - R0;
  59. R1 = R1 + R4;
  60. R2 = R2 - R0;
  61. R2 = R2 + R4;
  62. R0 = P0;
  63. CALL ___self_reloc;
  64. SP += 12;
  65. P3 = R0;
  66. #endif
  67. /* clear the frame pointer and the L registers. */
  68. FP = 0;
  69. L0 = 0;
  70. L1 = 0;
  71. L2 = 0;
  72. L3 = 0;
  73. #ifdef __ID_SHARED_LIB__
  74. /* We know we have a local copy, so we can avoid the GOT. */
  75. CALL ___shared_flat_add_library;
  76. #endif
  77. /* Load register R1 (argc) from the stack to its final resting place */
  78. P0 = SP;
  79. R1 = [P0++];
  80. /* Copy argv pointer into R2 -- which its final resting place */
  81. R2 = P0;
  82. SP += -28;
  83. #ifndef __BFIN_FDPIC__
  84. R7 = 0;
  85. #endif
  86. /* Pass highest stack pointer to the app. */
  87. [SP + 24] = P2;
  88. /* Store the pointer to ld.so's fini that we got in P1. */
  89. [SP + 20] = R7;
  90. /* Ok, now run uClibc's main() -- shouldn't return */
  91. #if (defined L_crt1 || defined L_Scrt1) && defined __UCLIBC_CTOR_DTOR__
  92. #ifdef __BFIN_FDPIC__
  93. R3 = [P3 + __init@FUNCDESC_GOT17M4];
  94. #elif defined USE_GOT
  95. R3 = [P5 + ___shared_flat_init@GOT];
  96. #else
  97. R3.H = __init;
  98. R3.L = __init;
  99. #endif
  100. [SP+12] = R3;
  101. #ifdef __BFIN_FDPIC__
  102. R3 = [P3 + __fini@FUNCDESC_GOT17M4];
  103. #elif defined USE_GOT
  104. R3 = [P5 + ___shared_flat_fini@GOT];
  105. #else
  106. R3.H = __fini;
  107. R3.L = __fini;
  108. #endif
  109. [SP+16] = R3;
  110. #else /* no ctor/dtor handling */
  111. R3 = 0;
  112. [SP + 12] = R3;
  113. [SP + 16] = R3;
  114. #endif
  115. #ifdef __BFIN_FDPIC__
  116. R0 = [P3 + _main@FUNCDESC_GOT17M4];
  117. #elif defined USE_GOT
  118. R0 = [P5 + _main@GOT];
  119. #else
  120. R0.H = _main;
  121. R0.L = _main;
  122. #endif
  123. #ifdef USE_GOT
  124. P0 = [P5 + ___uClibc_main@GOT];
  125. jump (P0)
  126. #else
  127. jump.l ___uClibc_main;
  128. #endif
  129. #else
  130. .text
  131. .global lib_main
  132. .hidden lib_main
  133. .type lib_main,@function
  134. lib_main:
  135. RETS = [SP++];
  136. /* We know we have a local copy, so we can avoid the GOT. */
  137. JUMP.L ___shared_flat_add_library;
  138. .hidden _current_shared_library_p5_offset_
  139. #endif
  140. .section .note.GNU-stack,"",%progbits