crt1.S 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. .text
  29. .align 2
  30. .global __start;
  31. .type __start,STT_FUNC;
  32. .global ___uClibc_main;
  33. .type ___uClibc_main,STT_FUNC;
  34. /* Stick in a dummy reference to main(), so that if an application
  35. * is linking when the main() function is in a static library (.a)
  36. * we can be sure that main() actually gets linked in */
  37. .type _main,STT_FUNC;
  38. __start:
  39. #ifdef __BFIN_FDPIC__
  40. /* P0 contains a pointer to the program's load map. */
  41. call .Lcall;
  42. .Lcall:
  43. R4 = RETS;
  44. SP += -12;
  45. R0.L = .Lcall;
  46. R0.H = .Lcall;
  47. R1.L = __ROFIXUP_LIST__;
  48. R1.H = __ROFIXUP_LIST__;
  49. R2.L = __ROFIXUP_END__;
  50. R2.H = __ROFIXUP_END__;
  51. R1 = R1 - R0;
  52. R1 = R1 + R4;
  53. R2 = R2 - R0;
  54. R2 = R2 + R4;
  55. R0 = P0;
  56. CALL ___self_reloc;
  57. SP += 12;
  58. P3 = R0;
  59. #endif
  60. /* clear the frame pointer and the L registers. */
  61. FP = 0;
  62. L0 = 0;
  63. L1 = 0;
  64. L2 = 0;
  65. L3 = 0;
  66. /* Load register R1 (argc) from the stack to its final resting place */
  67. P0 = SP;
  68. R1 = [P0++];
  69. /* Copy argv pointer into R2 -- which its final resting place */
  70. R2 = P0;
  71. /* Skip to the end of argv and put a pointer to the environment in
  72. [SP + 12] */
  73. R3 = R1;
  74. R3 <<= 2;
  75. R3 += 4;
  76. R3 = R2 + R3;
  77. SP += -24;
  78. [SP + 12] = R3;
  79. /* Ok, now run uClibc's main() -- shouldn't return */
  80. #if defined L_crt1 && defined __UCLIBC_CTOR_DTOR__
  81. #ifdef __BFIN_FDPIC__
  82. R3 = [P3 + __init@FUNCDESC_GOT17M4];
  83. #else
  84. R3.H = __init;
  85. R3.L = __init;
  86. #endif
  87. [SP+16] = R3;
  88. #ifdef __BFIN_FDPIC__
  89. R3 = [P3 + __fini@FUNCDESC_GOT17M4];
  90. #else
  91. R3.H = __fini;
  92. R3.L = __fini;
  93. #endif
  94. [SP+20] = R3;
  95. #else /* no ctor/dtor handling */
  96. R3 = 0;
  97. [SP + 16] = R3;
  98. [SP + 20] = R3;
  99. #endif
  100. #ifdef __BFIN_FDPIC__
  101. R0 = [P3 + _main@FUNCDESC_GOT17M4];
  102. #else
  103. R0.H = _main;
  104. R0.L = _main;
  105. #endif
  106. jump.l ___uClibc_main;