crt1.S 2.4 KB

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