crt0.S 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (C) 2003 by Erik Andersen
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU Library General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or (at your
  7. * option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
  12. * for more details.
  13. *
  14. * You should have received a copy of the GNU Library General Public License
  15. * along with this program; if not, write to the Free Software Foundation,
  16. * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. /* Integer registers. */
  19. #define r0 0
  20. #define r1 1
  21. #define r2 2
  22. #define r3 3
  23. #define r4 4
  24. #define r5 5
  25. #define r6 6
  26. #define r7 7
  27. #define r8 8
  28. #define r9 9
  29. #define r13 13
  30. #define r31 31
  31. #include <features.h>
  32. .section ".text"
  33. .globl _start
  34. .type _start,@function
  35. #if defined L_crt0 || defined L_Scrt0 || ! defined __UCLIBC_CTOR_DTOR__
  36. .type __uClibc_main,%function
  37. #else
  38. .weak _init
  39. .weak _fini
  40. .type __uClibc_start_main,%function
  41. #endif
  42. /* Stick in a dummy reference to main(), so that if an application
  43. * is linking when the main() function is in a static library (.a)
  44. * we can be sure that main() actually gets linked in */
  45. .type main,%function
  46. _start:
  47. /* Save the stack pointer, in case we're statically linked under Linux. */
  48. mr r9,r1
  49. /* Set up an initial stack frame, and clear the LR. */
  50. clrrwi r1,r1,4
  51. li r0,0
  52. stwu r1,-16(r1)
  53. mtlr r0
  54. stw r0,0(r1)
  55. /* find argc from the stack pointer */
  56. lwz r3,0(r9)
  57. /* find argv one word offset from the stack pointer */
  58. addi r4,r9,4
  59. /* find environment pointer (argv+argc+1) */
  60. lwz r5,0(r9)
  61. addi r5,r5,1
  62. rlwinm r5,r5,2,0,29
  63. add r5,r5,r4
  64. #if defined L_Scrt0 || defined L_Scrt1
  65. bl _GLOBAL_OFFSET_TABLE_-4@local
  66. mflr r31
  67. #endif
  68. /* Ok, now run uClibc's main() -- shouldn't return */
  69. #if (defined L_crt1 || defined L_Scrt1) && defined __UCLIBC_CTOR_DTOR__
  70. # ifdef L_Scrt1
  71. lwz r6,_init@got(r31)
  72. lwz r7,_fini@got(r31)
  73. bl __uClibc_start_main@plt
  74. # else
  75. lis r6,_init@ha # load top 16 bits
  76. addi r6,r6,_init@l # load bottom 16 bits
  77. lis r7,_fini@ha # load top 16 bits of &msg
  78. addi r7,r7,_fini@l # load bottom 16 bits
  79. bl __uClibc_start_main
  80. # endif
  81. #else
  82. # ifdef L_Scrt0
  83. bl __uClibc_main@plt
  84. # else
  85. bl __uClibc_main
  86. # endif
  87. #endif
  88. .size _start,.-_start
  89. /* Define a symbol for the first piece of initialized data. */
  90. .data
  91. .globl __data_start
  92. __data_start:
  93. .long 0
  94. .weak data_start
  95. data_start = __data_start