crt0.S 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. r4 Contains a function pointer to be registered with `atexit'.
  23. This is how the dynamic linker arranges to have DT_FINI
  24. functions called for shared libraries that have been loaded
  25. before this code runs.
  26. WARNING: At that stage only static linker is supported. For
  27. uCLinux we won't bother with r4.
  28. sp The stack contains the arguments and environment:
  29. 0(sp) argc
  30. 4(sp) argv[0]
  31. ...
  32. (4*argc)(sp) NULL
  33. (4*(argc+1))(sp) envp[0]
  34. ...
  35. NULL
  36. */
  37. .text
  38. .globl _start
  39. _start:
  40. /* Clear the frame pointer since this is the outermost frame. */
  41. mov #0, r14
  42. /* Pop argc off the stack and save a pointer to argv */
  43. mov.l @r15+,r4
  44. mov r15, r5
  45. /* set up the value for the environment pointer
  46. r6 = (argc+1)*4+argv
  47. */
  48. mov r4,r6
  49. add #1,r6
  50. shll2 r6
  51. add r5,r6
  52. ! Clear BSS area
  53. mov.l 3f, r1
  54. add #4, r1
  55. mov.l 4f, r2
  56. mov #0, r0
  57. 9: cmp/hs r2, r1
  58. bf/s 9b ! while (r1 < r2)
  59. mov.l r0,@-r2
  60. /* call main */
  61. mov.l L_main,r1
  62. jsr @r1
  63. nop
  64. /* should never get here....*/
  65. mov.l L_abort,r1
  66. jsr @r1
  67. nop
  68. .align 2
  69. 3: .long __bss_start
  70. 4: .long _end
  71. L_main:
  72. .long __uClibc_main
  73. L_abort:
  74. .long abort
  75. /* Stick in a dummy reference to main(), so that if an application
  76. * is linking when the main() function is in a static library (.a)
  77. * we can be sure that main() actually gets linked in */
  78. L_dummy_main_reference:
  79. .long main
  80. .data