crt1.S 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* Startup code for SH & ELF.
  2. Copyright (C) 1999 Free Software Foundation, Inc.
  3. Copyright (C) 2001 Hewlett-Packard Australia
  4. Copyright (C) 2002 Stefan Allius
  5. This program is free software; you can redistribute it and/or modify it under
  6. the terms of the GNU Library General Public License as published by the Free
  7. Software Foundation; either version 2 of the License, or (at your option) any
  8. later version.
  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 FITNESS
  11. FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more
  12. details.
  13. You should have received a copy of the GNU Library General Public License
  14. along with this program; if not, see <http://www.gnu.org/licenses/>.
  15. */
  16. /* This is the canonical entry point, usually the first thing in the text
  17. segment.
  18. At this entry point, most registers' values are unspecified, except:
  19. r4 Contains a function pointer to be registered with `atexit'.
  20. This is how the dynamic linker arranges to have DT_FINI
  21. functions called for shared libraries that have been loaded
  22. before this code runs.
  23. sp The stack contains the arguments and environment:
  24. 0(sp) argc
  25. 4(sp) argv[0]
  26. ...
  27. (4*argc)(sp) NULL
  28. (4*(argc+1))(sp) envp[0]
  29. ...
  30. NULL
  31. */
  32. #include <features.h>
  33. .text
  34. .globl _start
  35. .type _start,%function
  36. .type main,%function
  37. _start:
  38. /* Clear the frame pointer since this is the outermost frame. */
  39. mov #0, r14
  40. /* Pop argc off the stack and save a pointer to argv */
  41. mov.l @r15+,r5
  42. mov r15, r6
  43. /* Push the stack_end, rtld_fini and fini func onto the stack */
  44. mov.l r6,@-r15
  45. mov.l r4,@-r15
  46. #ifdef __PIC__
  47. mova L_got, r0
  48. mov.l L_got, r12
  49. add r0, r12
  50. mov.l L_fini,r0
  51. add r12, r0
  52. mov.l r0,@-r15
  53. /* Set up the main/init funcs that go in registers */
  54. mov.l L_main, r4
  55. add r12, r4
  56. mov.l L_init, r7
  57. add r12, r7
  58. /* __uClibc_main (main, argc, argv, init, fini, rtld_fini, stack_end) */
  59. /* Let the libc call main and exit with its return code. */
  60. mov.l L_uClibc_main,r0
  61. mov.l @(r0,r12),r1
  62. jsr @r1
  63. nop
  64. /* We should not get here. */
  65. mov.l L_abort,r0
  66. mov.l @(r0,r12),r1
  67. jsr @r1
  68. nop
  69. #else
  70. mov.l L_fini,r0
  71. mov.l r0,@-r15
  72. /* Set up the main/init funcs that go in registers */
  73. mov.l L_main,r4
  74. mov.l L_init,r7
  75. /* __uClibc_main (main, argc, argv, init, fini, rtld_fini, stack_end) */
  76. /* Let the libc call main and exit with its return code. */
  77. mov.l L_uClibc_main,r1
  78. jsr @r1
  79. nop
  80. /* We should not get here. */
  81. mov.l L_abort,r1
  82. jmp @r1
  83. nop
  84. #endif
  85. .size _start,.-_start
  86. .align 2
  87. #ifdef __PIC__
  88. L_got:
  89. .long _GLOBAL_OFFSET_TABLE_
  90. L_main:
  91. .long main@GOTOFF
  92. L_init:
  93. .long _init@GOTOFF
  94. L_fini:
  95. .long _fini@GOTOFF
  96. L_uClibc_main:
  97. .long __uClibc_main@GOT
  98. L_abort:
  99. .long abort@GOT
  100. #else
  101. L_main:
  102. .long main
  103. L_init:
  104. .long _init
  105. L_fini:
  106. .long _fini
  107. L_uClibc_main:
  108. .long __uClibc_main
  109. L_abort:
  110. .long abort
  111. #endif
  112. /* Define a symbol for the first piece of initialized data. */
  113. .data
  114. .globl __data_start
  115. __data_start:
  116. .long 0
  117. .weak data_start
  118. data_start = __data_start