crt1.S 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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, write to the Free Software Foundation, Inc.,
  15. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. /* This is the canonical entry point, usually the first thing in the text
  18. segment.
  19. At this entry point, most registers' values are unspecified, except:
  20. r4 Contains a function pointer to be registered with `atexit'.
  21. This is how the dynamic linker arranges to have DT_FINI
  22. functions called for shared libraries that have been loaded
  23. before this code runs.
  24. sp The stack contains the arguments and environment:
  25. 0(sp) argc
  26. 4(sp) argv[0]
  27. ...
  28. (4*argc)(sp) NULL
  29. (4*(argc+1))(sp) envp[0]
  30. ...
  31. NULL
  32. */
  33. #include <features.h>
  34. .text
  35. .globl _start
  36. .type _start,%function
  37. .type main,%function
  38. _start:
  39. /* Clear the frame pointer since this is the outermost frame. */
  40. mov #0, r14
  41. /* Pop argc off the stack and save a pointer to argv */
  42. mov.l @r15+,r5
  43. mov r15, r6
  44. /* Push the stack_end, rtld_fini and fini func onto the stack */
  45. mov.l r6,@-r15
  46. mov.l r4,@-r15
  47. #ifdef __PIC__
  48. mova L_got, r0
  49. mov.l L_got, r12
  50. add r0, r12
  51. mov.l L_fini,r0
  52. add r12, r0
  53. mov.l r0,@-r15
  54. /* Set up the main/init funcs that go in registers */
  55. mov.l L_main, r4
  56. add r12, r4
  57. mov.l L_init, r7
  58. add r12, r7
  59. /* __uClibc_main (main, argc, argv, init, fini, rtld_fini, stack_end) */
  60. /* Let the libc call main and exit with its return code. */
  61. mov.l L_uClibc_main,r0
  62. mov.l @(r0,r12),r1
  63. jsr @r1
  64. nop
  65. /* We should not get here. */
  66. mov.l L_abort,r0
  67. mov.l @(r0,r12),r1
  68. jsr @r1
  69. nop
  70. #else
  71. mov.l L_fini,r0
  72. mov.l r0,@-r15
  73. /* Set up the main/init funcs that go in registers */
  74. mov.l L_main,r4
  75. mov.l L_init,r7
  76. /* __uClibc_main (main, argc, argv, init, fini, rtld_fini, stack_end) */
  77. /* Let the libc call main and exit with its return code. */
  78. mov.l L_uClibc_main,r1
  79. jsr @r1
  80. nop
  81. /* We should not get here. */
  82. mov.l L_abort,r1
  83. jmp @r1
  84. nop
  85. #endif
  86. .size _start,.-_start
  87. .align 2
  88. #ifdef __PIC__
  89. L_got:
  90. .long _GLOBAL_OFFSET_TABLE_
  91. L_main:
  92. .long main@GOTOFF
  93. L_init:
  94. .long _init@GOTOFF
  95. L_fini:
  96. .long _fini@GOTOFF
  97. L_uClibc_main:
  98. .long __uClibc_main@GOT
  99. L_abort:
  100. .long abort@GOT
  101. #else
  102. L_main:
  103. .long main
  104. L_init:
  105. .long _init
  106. L_fini:
  107. .long _fini
  108. L_uClibc_main:
  109. .long __uClibc_main
  110. L_abort:
  111. .long abort
  112. #endif
  113. /* Define a symbol for the first piece of initialized data. */
  114. .data
  115. .globl __data_start
  116. __data_start:
  117. .long 0
  118. .weak data_start
  119. data_start = __data_start