crt1.S 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. #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. #endif
  58. /* Set up the small data pointer in r13. */
  59. #ifdef __PIC__
  60. lwz r13,_SDA_BASE_@got(r31)
  61. #else
  62. lis r13,_SDA_BASE_@ha
  63. addi r13,r13,_SDA_BASE_@l
  64. #endif
  65. /* Set up an initial stack frame, and clear the LR. */
  66. li r0,0
  67. stwu r1,-16(r1)
  68. mtlr r0
  69. stw r0,0(r1)
  70. /* find argc from the stack pointer */
  71. lwz r4,0(r9)
  72. /* find argv one word offset from the stack pointer */
  73. addi r5,r9,4
  74. mr r8,r3 /* Pass _dl_fini from ldso or NULL if statically linked */
  75. /* Note: PPC depends on the kernel to zero r3 before */
  76. /* handing over to user space, otherwise static apps */
  77. /* will SEGV during exit() */
  78. /* Ok, now run uClibc's main() -- shouldn't return */
  79. #ifdef __PIC__
  80. lwz r6,_init@got(r31)
  81. lwz r7,_fini@got(r31)
  82. lwz r3,main@got(r31)
  83. b __uClibc_main@plt
  84. #else
  85. lis r6,_init@ha # load top 16 bits
  86. addi r6,r6,_init@l # load bottom 16 bits
  87. lis r7,_fini@ha # load top 16 bits
  88. addi r7,r7,_fini@l # load bottom 16 bits
  89. lis r3,main@ha # load top 16 bits
  90. addi r3,r3,main@l # load bottom 16 bits
  91. b __uClibc_main
  92. #endif
  93. .size _start,.-_start
  94. /* Define a symbol for the first piece of initialized data. */
  95. .data
  96. .globl __data_start
  97. __data_start:
  98. .long 0
  99. .weak data_start
  100. data_start = __data_start