crt0.S 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. sp The stack contains the arguments and environment:
  21. 0(sp) argc
  22. 4(sp) argv[0]
  23. ...
  24. (4*argc)(sp) NULL
  25. (4*(argc+1))(sp) envp[0]
  26. ...
  27. NULL
  28. */
  29. #include <features.h>
  30. .file "crt0.S"
  31. .text
  32. .globl _start
  33. .type _start,@function
  34. .size _start,_start_end - _start
  35. _start:
  36. /* Clear the frame pointer since this is the outermost frame. */
  37. mov #0, r14
  38. /* Pop argc off the stack and save a pointer to argv */
  39. mov.l @r15+,r4
  40. mov r15, r5
  41. #if defined L_crt0 || ! defined __UCLIBC_CTOR_DTOR__
  42. /*
  43. * Setup the value for the environment pointer:
  44. * r6 = (argc + 1) * 4
  45. * r6 += argv (in delay slot)
  46. */
  47. mov r4,r6
  48. add #1,r6
  49. shll2 r6
  50. /* jump to __uClibc_main (argc, argv, envp) */
  51. mov.l L_main, r0
  52. jsr @r0
  53. add r5, r6 /* delay slot */
  54. /* We should not get here. */
  55. mov.l L_abort, r0
  56. jmp @r0
  57. nop
  58. _start_end:
  59. .align 2
  60. L_main:
  61. .long __uClibc_main /* in libuClibc.*.so */
  62. #else /* L_crt1 && __UCLIBC_CTOR_DTOR__ */
  63. /* Push the finip argument to __uClibc_start_main() onto the stack */
  64. mov.l L_fini,r6
  65. mov.l r6,@-r15
  66. /* Setup the value for the initp argument */
  67. mov.l L_init, r7
  68. /*
  69. * Setup the value for the environment pointer:
  70. * r6 = (argc + 1) * 4
  71. * r6 += argv (in delay slot)
  72. */
  73. mov r4,r6
  74. add #1,r6
  75. shll2 r6
  76. /* jump to __uClibc_start_main (argc, argv, envp, app_init, app_fini) */
  77. mov.l L_main, r0
  78. jsr @r0
  79. add r5, r6 /* delay slot */
  80. /* We should not get here. */
  81. mov.l L_abort, r0
  82. jmp @r0
  83. nop
  84. _start_end:
  85. .align 2
  86. L_main:
  87. .long __uClibc_start_main /* in libuClibc.*.so */
  88. .weak _init
  89. .type _init,@function
  90. _init:
  91. rts
  92. nop
  93. .Lfe1:
  94. .size _init,.Lfe1-_init
  95. .weak _fini
  96. .set _fini,_init
  97. L_init:
  98. .long _init
  99. L_fini:
  100. .long _fini
  101. #endif
  102. L_abort:
  103. .long abort
  104. /* Stick in a dummy reference to main(), so that if an application
  105. * is linking when the main() function is in a static library (.a)
  106. * we can be sure that main() actually gets linked in */
  107. L_dummy_main_reference:
  108. .long main