prt0.as 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /* Startup code for ARM & ELF
  2. Copyright (C) 1995, 1996, 1997, 1998, 2001, 2002 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  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. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, write to the Free
  14. Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  15. MA 02110-1301, USA. */
  16. /* This is the canonical entry point, usually the first thing in the text
  17. segment.
  18. Note that the code in the .init section has already been run.
  19. This includes _init and _libc_init
  20. At this entry point, most registers' values are unspecified, except:
  21. a1 Contains a function pointer to be registered with `atexit'.
  22. This is how the dynamic linker arranges to have DT_FINI
  23. functions called for shared libraries that have been loaded
  24. before this code runs.
  25. sp The stack contains the arguments and environment:
  26. 0(sp) argc
  27. 4(sp) argv[0]
  28. ...
  29. (4*argc)(sp) NULL
  30. (4*(argc+1))(sp) envp[0]
  31. ...
  32. NULL
  33. */
  34. .text
  35. .globl _dynamic_start
  36. .type _dynamic_start,#function
  37. _dynamic_start:
  38. .ifdef __thumb__
  39. ldr r7,=__dl_fini
  40. str a1,[r7]
  41. .else
  42. ldr ip,=__dl_fini
  43. str a1,[ip]
  44. .endif
  45. b _start
  46. .text
  47. .globl _start
  48. .type _start,#function
  49. _start:
  50. .ifdef __thumb__
  51. pop {a2}
  52. /* Pop argc off the stack and save a pointer to argv */
  53. ldr r7,=operatingsystem_parameter_argc
  54. str a2,[r7]
  55. ldr r7,=operatingsystem_parameter_argv
  56. mov a3,sp
  57. str a3,[r7]
  58. /* calc envp */
  59. ldr r7,=operatingsystem_parameter_envp
  60. add a2,a2,#1
  61. lsl a2,a2,#2
  62. add a2,sp,a2
  63. str a2,[r7]
  64. /* Save initial stackpointer */
  65. ldr r7,=__stkptr
  66. str a3,[r7]
  67. /* Clear the frame pointer since this is the outermost frame. */
  68. mov r7, #0
  69. .else
  70. mov fp, #0
  71. ldmia sp!, {a2}
  72. /* Pop argc off the stack and save a pointer to argv */
  73. ldr ip,=operatingsystem_parameter_argc
  74. ldr a3,=operatingsystem_parameter_argv
  75. str a2,[ip]
  76. /* calc envp */
  77. add a2,a2,#1
  78. add a2,sp,a2,LSL #2
  79. ldr ip,=operatingsystem_parameter_envp
  80. str sp,[a3]
  81. str a2,[ip]
  82. /* Save initial stackpointer */
  83. ldr ip,=__stkptr
  84. str sp,[ip]
  85. .endif
  86. /* align sp again to 8 byte boundary, needed by eabi */
  87. sub sp,sp,#4
  88. /* Initialize TLS */
  89. bl FPC_INITTLS
  90. /* Call main program, it will never return */
  91. bl PASCALMAIN
  92. .globl _haltproc
  93. .type _haltproc,#function
  94. _haltproc:
  95. /* r0 contains exitcode */
  96. .ifdef __thumb__
  97. ldr r0,=operatingsystem_result
  98. ldr r0,[r0]
  99. mov r7,#248 /* exit group call */
  100. swi 0x0
  101. .else
  102. swi 0x900001
  103. .endif
  104. b _haltproc
  105. .globl _haltproc_eabi
  106. .type _haltproc_eabi,#function
  107. _haltproc_eabi:
  108. ldr r0,=__dl_fini
  109. ldr r0,[r0]
  110. cmp r0,#0
  111. .ifdef __thumb__
  112. beq .Lnobranch
  113. /* only branch if not equal zero */
  114. mov lr,pc
  115. bx r0 /* we require armv5 anyway, so use bx here */
  116. .Lnobranch:
  117. .else
  118. /* only branch if not equal zero */
  119. movne lr,pc
  120. bxne r0 /* we require armv5 anyway, so use bx here */
  121. .endif
  122. .Lloop:
  123. ldr r0,=operatingsystem_result
  124. ldr r0,[r0]
  125. mov r7,#248 /* exit group call */
  126. swi 0x0
  127. b .Lloop
  128. /* Define a symbol for the first piece of initialized data. */
  129. .data
  130. .globl __data_start
  131. __data_start:
  132. .long 0
  133. .weak data_start
  134. data_start = __data_start
  135. .bss
  136. .comm __dl_fini,4
  137. .comm __stkptr,4
  138. .comm operatingsystem_parameter_envp,4
  139. .comm operatingsystem_parameter_argc,4
  140. .comm operatingsystem_parameter_argv,4
  141. .section ".comment"
  142. .byte 0
  143. .ascii "generated by FPC http://www.freepascal.org\0"
  144. /* We need this stuff to make gdb behave itself, otherwise
  145. gdb will chokes with SIGILL when trying to debug apps.
  146. */
  147. .section ".note.ABI-tag", "a"
  148. .align 4
  149. .long 1f - 0f
  150. .long 3f - 2f
  151. .long 1
  152. 0: .asciz "GNU"
  153. 1: .align 4
  154. 2: .long 0
  155. .long 2,0,0
  156. 3: .align 4
  157. .section .note.GNU-stack,"",%progbits