ucprt0.as 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /* Startup code for ARM & ELF
  2. Copyright (C) 1995, 1996, 1997, 1998, 2001, 2002, 2005
  3. Free Software Foundation, Inc.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. In addition to the permissions in the GNU Lesser General Public
  9. License, the Free Software Foundation gives you unlimited
  10. permission to link the compiled version of this file with other
  11. programs, and to distribute those programs without any restriction
  12. coming from the use of this file. (The GNU Lesser General Public
  13. License restrictions do apply in other respects; for example, they
  14. cover modification of the file, and distribution when not linked
  15. into another program.)
  16. Note that people who make modified versions of this file are not
  17. obligated to grant this special exception for their modified
  18. versions; it is their choice whether to do so. The GNU Lesser
  19. General Public License gives permission to release a modified
  20. version without this exception; this exception also makes it
  21. possible to release a modified version which carries forward this
  22. exception.
  23. The GNU C Library is distributed in the hope that it will be useful,
  24. but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  26. Lesser General Public License for more details.
  27. You should have received a copy of the GNU Lesser General Public
  28. License along with the GNU C Library; if not, write to the Free
  29. Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  30. 02110-1301 USA. */
  31. /* This is the canonical entry point, usually the first thing in the text
  32. segment.
  33. Note that the code in the .init section has already been run.
  34. This includes _init and _libc_init
  35. At this entry point, most registers' values are unspecified, except:
  36. a1 Contains a function pointer to be registered with `atexit'.
  37. This is how the dynamic linker arranges to have DT_FINI
  38. functions called for shared libraries that have been loaded
  39. before this code runs.
  40. sp The stack contains the arguments and environment:
  41. 0(sp) argc
  42. 4(sp) argv[0]
  43. ...
  44. (4*argc)(sp) NULL
  45. (4*(argc+1))(sp) envp[0]
  46. ...
  47. NULL
  48. */
  49. /*
  50. For uClinux it looks like this:
  51. argc argument counter (integer)
  52. argv char *argv[]
  53. envp char *envp[]
  54. argv[0] program name (pointer)
  55. argv[1...N] program args (pointers)
  56. argv[argc-1] end of args (integer)
  57. NULL
  58. env[0...N] environment variables (pointers)
  59. NULL
  60. ARM register quick reference:
  61. Name Number ARM Procedure Calling Standard Role
  62. a1 r0 argument 1 / integer result / scratch register / argc
  63. a2 r1 argument 2 / scratch register / argv
  64. a3 r2 argument 3 / scratch register / envp
  65. a4 r3 argument 4 / scratch register
  66. v1 r4 register variable
  67. v2 r5 register variable
  68. v3 r6 register variable
  69. v4 r7 register variable
  70. v5 r8 register variable
  71. sb/v6 r9 static base / register variable
  72. sl/v7 r10 stack limit / stack chunk handle / reg. variable
  73. fp r11 frame pointer
  74. ip r12 scratch register / new-sb in inter-link-unit calls
  75. sp r13 lower end of current stack frame
  76. lr r14 link address / scratch register
  77. pc r15 program counter
  78. */
  79. .text
  80. .globl _start
  81. .type _start,%function
  82. .type _init,%function
  83. .type _fini,%function
  84. .weak _init
  85. .weak _fini
  86. _start:
  87. /* Clear the frame pointer and link register since this is the outermost frame. */
  88. mov fp, #0
  89. mov lr, #0
  90. /* Pop argc off the stack and save a pointer to argv */
  91. ldr a2, [sp], #4
  92. mov a3, sp
  93. /* calc envp */
  94. add a4, a3, a2, lsl #2
  95. ldr ip,=operatingsystem_parameter_argc
  96. str a2, [ip]
  97. ldr ip,=operatingsystem_parameter_argv
  98. str a3, [ip]
  99. ldr ip,=operatingsystem_parameter_envp
  100. str a4, [ip]
  101. ldr ip,=__stkptr
  102. str sp, [ip]
  103. /* keep stack aligned as required by eabi */
  104. sub sp,sp,#4
  105. /* Push stack limit */
  106. str a3, [sp, #-4]!
  107. /* Push rtld_fini */
  108. str a1, [sp, #-4]!
  109. /* Fetch address of fini */
  110. ldr ip, =_fini
  111. /* Push fini */
  112. str ip, [sp, #-4]!
  113. /* Set up the other arguments in registers */
  114. ldr a1, =PASCALMAIN
  115. ldr a4, =_init
  116. /* __uClibc_main (main, argc, argv, init, fini, rtld_fini, stack_end) */
  117. /* Let the libc call main and exit with its return code. */
  118. b __uClibc_main
  119. /* should never get here....*/
  120. bl abort
  121. .globl _haltproc
  122. .type _haltproc,#function
  123. _haltproc:
  124. swi 0x900001
  125. b _haltproc
  126. /* Define a symbol for the first piece of initialized data. */
  127. .data
  128. .globl __data_start
  129. __data_start:
  130. .long 0
  131. .weak data_start
  132. data_start = __data_start
  133. .bss
  134. .comm __stkptr,4
  135. .comm operatingsystem_parameter_envp,4
  136. .comm operatingsystem_parameter_argc,4
  137. .comm operatingsystem_parameter_argv,4