crt0.S 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* Startup code for SH & ELF.
  2. Copyright (C) 1999 Free Software Foundation, Inc.
  3. Copyright (C) 2001 Hewlett-Packard Australia
  4. This program is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU Library General Public License as published by the Free
  6. Software Foundation; either version 2 of the License, or (at your option) any
  7. later version.
  8. This program is distributed in the hope that it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  10. FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more
  11. details.
  12. You should have received a copy of the GNU Library General Public License
  13. along with this program; if not, write to the Free Software Foundation, Inc.,
  14. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15. Derived in part from the Linux-8086 C library, the GNU C Library, and several
  16. other sundry sources. Files within this library are copyright by their
  17. respective copyright holders.
  18. */
  19. /* This is the canonical entry point, usually the first thing in the text
  20. segment.
  21. At this entry point, most registers' values are unspecified, except:
  22. sp The stack contains the arguments and environment:
  23. 0(sp) argc
  24. 4(sp) argv[0]
  25. ...
  26. (4*argc)(sp) NULL
  27. (4*(argc+1))(sp) envp[0]
  28. ...
  29. NULL
  30. */
  31. .file "crt0.S"
  32. .text
  33. .globl _start
  34. .type _start,@function
  35. .size _start,_start_end - _start
  36. _start:
  37. /* Clear the frame pointer since this is the outermost frame. */
  38. mov #0, r14
  39. /* Pop argc off the stack and save a pointer to argv */
  40. mov.l @r15+,r4
  41. mov r15, r5
  42. /* Push the finip argument to __uClibc_start_main() onto the stack */
  43. mov.l L_fini,r6
  44. mov.l r6,@-r15
  45. /* Setup the value for the initp argument */
  46. mov.l L_init, r7
  47. /*
  48. * Setup the value for the environment pointer:
  49. * r6 = (argc + 1) * 4
  50. * r6 += argv (in delay slot)
  51. */
  52. mov r4,r6
  53. add #1,r6
  54. shll2 r6
  55. /* jump to __uClibc_start_main (argc, argv, envp, app_init, app_fini) */
  56. mov.l L_main, r0
  57. jsr @r0
  58. add r5, r6 /* delay slot */
  59. /* We should not get here. */
  60. mov.l L_abort, r0
  61. jmp @r0
  62. nop
  63. _start_end:
  64. .align 2
  65. .weak _init
  66. .type _init,@function
  67. _init:
  68. rts
  69. nop
  70. .Lfe1:
  71. .size _init,.Lfe1-_init
  72. .weak _fini
  73. .set _fini,_init
  74. L_main:
  75. .long __uClibc_start_main /* in libuClibc.*.so */
  76. L_init:
  77. .long _init
  78. L_fini:
  79. .long _fini
  80. L_abort:
  81. .long abort
  82. /* Stick in a dummy reference to main(), so that if an application
  83. * is linking when the main() function is in a static library (.a)
  84. * we can be sure that main() actually gets linked in */
  85. L_dummy_main_reference:
  86. .long main