crt1.S 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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; see the file COPYING.LIB. If not, see
  16. * <http://www.gnu.org/licenses/>.
  17. */
  18. #include <features.h>
  19. /* Integer registers. */
  20. #define r0 0
  21. #define r1 1
  22. #define r2 2
  23. #define r3 3
  24. #define r4 4
  25. #define r5 5
  26. #define r6 6
  27. #define r7 7
  28. #define r8 8
  29. #define r9 9
  30. #define r10 10
  31. #define r13 13
  32. #define r31 31
  33. .text
  34. .globl _start
  35. .type _start,%function
  36. .type _init,%function
  37. .type _fini,%function
  38. #ifndef __UCLIBC_CTOR_DTOR__
  39. .weak _init
  40. .weak _fini
  41. #endif
  42. .type main,%function
  43. .type __uClibc_main,%function
  44. _start:
  45. mr r9,r1 /* Save the stack pointer and pass it to __uClibc_main */
  46. clrrwi r1,r1,4 /* Align stack ptr to 16 bytes */
  47. #ifdef __PIC__
  48. # ifdef HAVE_ASM_PPC_REL16
  49. bcl 20,31,1f
  50. 1: mflr r31
  51. addis r31,r31,_GLOBAL_OFFSET_TABLE_-1b@ha
  52. addi r31,r31,_GLOBAL_OFFSET_TABLE_-1b@l
  53. # else
  54. bl _GLOBAL_OFFSET_TABLE_-4@local
  55. mflr r31
  56. # endif
  57. /* in PIC/PIE, plt stubs need r30 to point to the GOT if using secure-plt */
  58. # ifdef PPC_HAS_SECUREPLT
  59. mr 30,31
  60. # endif
  61. #endif
  62. /* Set up the small data pointer in r13. */
  63. #ifdef __PIC__
  64. lwz r13,_SDA_BASE_@got(r31)
  65. #else
  66. lis r13,_SDA_BASE_@ha
  67. addi r13,r13,_SDA_BASE_@l
  68. #endif
  69. /* Set up an initial stack frame, and clear the LR. */
  70. li r0,0
  71. stwu r1,-16(r1)
  72. mtlr r0
  73. stw r0,0(r1)
  74. /* find argc from the stack pointer */
  75. lwz r4,0(r9)
  76. /* find argv one word offset from the stack pointer */
  77. addi r5,r9,4
  78. mr r8,r3 /* Pass _dl_fini from ldso or NULL if statically linked */
  79. /* Note: PPC depends on the kernel to zero r3 before */
  80. /* handing over to user space, otherwise static apps */
  81. /* will SEGV during exit() */
  82. /* Ok, now run uClibc's main() -- shouldn't return */
  83. #ifdef __PIC__
  84. lwz r6,_init@got(r31)
  85. lwz r7,_fini@got(r31)
  86. lwz r3,main@got(r31)
  87. b __uClibc_main@plt
  88. #else
  89. lis r6,_init@ha # load top 16 bits
  90. addi r6,r6,_init@l # load bottom 16 bits
  91. lis r7,_fini@ha # load top 16 bits
  92. addi r7,r7,_fini@l # load bottom 16 bits
  93. lis r3,main@ha # load top 16 bits
  94. addi r3,r3,main@l # load bottom 16 bits
  95. b __uClibc_main
  96. #endif
  97. .size _start,.-_start
  98. /* Define a symbol for the first piece of initialized data. */
  99. .data
  100. .globl __data_start
  101. __data_start:
  102. .long 0
  103. .weak data_start
  104. data_start = __data_start