crt1.S 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. #ifndef L_Scrt1
  29. .text
  30. .align 2
  31. .global __start;
  32. .type __start,STT_FUNC;
  33. .weak __init;
  34. .weak __fini;
  35. .global ___uClibc_main;
  36. .type ___uClibc_main,STT_FUNC;
  37. /* Stick in a dummy reference to main(), so that if an application
  38. * is linking when the main() function is in a static library (.a)
  39. * we can be sure that main() actually gets linked in */
  40. .type _main,STT_FUNC;
  41. __start:
  42. #if defined(__BFIN_FDPIC__) && !defined(__pie__)
  43. /* P0 contains a pointer to the program's load map. */
  44. call .Lcall;
  45. .Lcall:
  46. R4 = RETS;
  47. SP += -12;
  48. R0.L = .Lcall;
  49. R0.H = .Lcall;
  50. R1.L = __ROFIXUP_LIST__;
  51. R1.H = __ROFIXUP_LIST__;
  52. R2.L = __ROFIXUP_END__;
  53. R2.H = __ROFIXUP_END__;
  54. R1 = R1 - R0;
  55. R1 = R1 + R4;
  56. R2 = R2 - R0;
  57. R2 = R2 + R4;
  58. R0 = P0;
  59. CALL ___self_reloc;
  60. SP += 12;
  61. P3 = R0;
  62. #endif
  63. /* clear the frame pointer and the L registers. */
  64. FP = 0;
  65. L0 = 0;
  66. L1 = 0;
  67. L2 = 0;
  68. L3 = 0;
  69. #ifdef __ID_SHARED_LIB__
  70. /* We know we have a local copy, so we can avoid the GOT. */
  71. CALL ___shared_flat_add_library;
  72. #endif
  73. /* Load register R1 (argc) from the stack to its final resting place */
  74. P0 = SP;
  75. R1 = [P0++];
  76. /* Copy argv pointer into R2 -- which its final resting place */
  77. R2 = P0;
  78. SP += -28;
  79. #ifndef __BFIN_FDPIC__
  80. R7 = 0;
  81. #endif
  82. /* Pass highest stack pointer to the app. */
  83. [SP + 24] = P2;
  84. /* Store the pointer to ld.so's fini that we got in P1. */
  85. [SP + 20] = R7;
  86. /* Ok, now run uClibc's main() -- shouldn't return */
  87. #if defined L_crt1 && defined __UCLIBC_CTOR_DTOR__
  88. #ifdef __BFIN_FDPIC__
  89. R3 = [P3 + __init@FUNCDESC_GOT17M4];
  90. #elif defined __ID_SHARED_LIB__
  91. P5 = [P5 + _current_shared_library_p5_offset_];
  92. R3 = [P5 + ___shared_flat_init@GOT];
  93. #else
  94. R3.H = __init;
  95. R3.L = __init;
  96. #endif
  97. [SP+12] = R3;
  98. #ifdef __BFIN_FDPIC__
  99. R3 = [P3 + __fini@FUNCDESC_GOT17M4];
  100. #elif defined __ID_SHARED_LIB__
  101. R3 = [P5 + ___shared_flat_fini@GOT];
  102. #else
  103. R3.H = __fini;
  104. R3.L = __fini;
  105. #endif
  106. [SP+16] = R3;
  107. #else /* no ctor/dtor handling */
  108. R3 = 0;
  109. [SP + 12] = R3;
  110. [SP + 16] = R3;
  111. #endif
  112. #ifdef __BFIN_FDPIC__
  113. R0 = [P3 + _main@FUNCDESC_GOT17M4];
  114. #elif defined __ID_SHARED_LIB__
  115. R0 = [P5 + _main@GOT];
  116. #else
  117. R0.H = _main;
  118. R0.L = _main;
  119. #endif
  120. #ifdef __ID_SHARED_LIB__
  121. P0 = [P5 + ___uClibc_main@GOT];
  122. jump (P0)
  123. #else
  124. jump.l ___uClibc_main;
  125. #endif
  126. #else
  127. .text
  128. .global lib_main
  129. .hidden lib_main
  130. .type lib_main,@function
  131. lib_main:
  132. RETS = [SP++];
  133. /* We know we have a local copy, so we can avoid the GOT. */
  134. JUMP.L ___shared_flat_add_library;
  135. .hidden _current_shared_library_p5_offset_
  136. #endif