crt1.S 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 r10 10
  30. #define r13 13
  31. #define r31 31
  32. #include <features.h>
  33. .text
  34. .globl _start
  35. .type _start,%function
  36. .type _init,%function
  37. .type _fini,%function
  38. .type main,%function
  39. .type __uClibc_start_main,%function
  40. _start:
  41. mr r9,r1 /* Save the stack pointer */
  42. clrrwi r1,r1,4 /* Align stack ptr to 16 bytes */
  43. mr r10,r1 /* Pass aligned stack ptr */
  44. #if defined L_Scrt1
  45. bl _GLOBAL_OFFSET_TABLE_-4@local
  46. mflr r31
  47. #endif
  48. /* Set up an initial stack frame, and clear the LR. */
  49. li r0,0
  50. stwu r1,-16(r1)
  51. mtlr r0
  52. stw r0,0(r1)
  53. /* find argc from the stack pointer */
  54. lwz r4,0(r9)
  55. /* find argv one word offset from the stack pointer */
  56. addi r5,r9,4
  57. /* find environment pointer (argv+argc+1) */
  58. lwz r6,0(r9)
  59. addi r6,r6,1
  60. rlwinm r6,r6,2,0,29
  61. add r6,r6,r5
  62. mr r9,r7 /* Pass _dl_fini from ldso or NULL if statically linked */
  63. /* Ok, now run uClibc's main() -- shouldn't return */
  64. # ifdef L_Scrt1
  65. lwz r7,_init@got(r31)
  66. lwz r8,_fini@got(r31)
  67. lwz r3,main@got(r31)
  68. b __uClibc_start_main@plt
  69. # else
  70. lis r7,_init@ha # load top 16 bits
  71. addi r7,r7,_init@l # load bottom 16 bits
  72. lis r8,_fini@ha # load top 16 bits
  73. addi r8,r8,_fini@l # load bottom 16 bits
  74. lis r3,main@ha # load top 16 bits
  75. addi r3,r3,main@l # load bottom 16 bits
  76. b __uClibc_start_main
  77. # endif
  78. .size _start,.-_start
  79. /* Define a symbol for the first piece of initialized data. */
  80. .data
  81. .globl __data_start
  82. __data_start:
  83. .long 0
  84. .weak data_start
  85. data_start = __data_start