crt1.S 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 an initial stack frame, and clear the LR. */
  59. li r0,0
  60. stwu r1,-16(r1)
  61. mtlr r0
  62. stw r0,0(r1)
  63. /* find argc from the stack pointer */
  64. lwz r4,0(r9)
  65. /* find argv one word offset from the stack pointer */
  66. addi r5,r9,4
  67. mr r8,r3 /* Pass _dl_fini from ldso or NULL if statically linked
  68. Note: using r3 instead of r7, since linux 2.6 clobbers r7 */
  69. /* Ok, now run uClibc's main() -- shouldn't return */
  70. #ifdef __PIC__
  71. lwz r6,_init@got(r31)
  72. lwz r7,_fini@got(r31)
  73. lwz r3,main@got(r31)
  74. b __uClibc_main@plt
  75. #else
  76. lis r6,_init@ha # load top 16 bits
  77. addi r6,r6,_init@l # load bottom 16 bits
  78. lis r7,_fini@ha # load top 16 bits
  79. addi r7,r7,_fini@l # load bottom 16 bits
  80. lis r3,main@ha # load top 16 bits
  81. addi r3,r3,main@l # load bottom 16 bits
  82. b __uClibc_main
  83. #endif
  84. .size _start,.-_start
  85. /* Define a symbol for the first piece of initialized data. */
  86. .data
  87. .globl __data_start
  88. __data_start:
  89. .long 0
  90. .weak data_start
  91. data_start = __data_start