crt1.S 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. mov.l L_fini,r0
  48. mov.l r0,@-r15
  49. /* Set up the main/init funcs that go in registers */
  50. mov.l L_main,r4
  51. mov.l L_init,r7
  52. /* __uClibc_main (main, argc, argv, init, fini, rtld_fini, stack_end) */
  53. /* Let the libc call main and exit with its return code. */
  54. mov.l L_uClibc_main,r1
  55. jsr @r1
  56. nop
  57. /* We should not get here. */
  58. mov.l L_abort,r1
  59. jmp @r1
  60. nop
  61. .size _start,.-_start
  62. .align 2
  63. L_main:
  64. .long main
  65. L_init:
  66. .long _init
  67. L_fini:
  68. .long _fini
  69. L_uClibc_main:
  70. .long __uClibc_main
  71. L_abort:
  72. .long abort
  73. /* Define a symbol for the first piece of initialized data. */
  74. .data
  75. .globl __data_start
  76. __data_start:
  77. .long 0
  78. .weak data_start
  79. data_start = __data_start