prt0.as 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 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. ldr ip,=__dl_fini
  39. str a1,[ip]
  40. b _start
  41. .text
  42. .globl _start
  43. .type _start,#function
  44. _start:
  45. /* Clear the frame pointer since this is the outermost frame. */
  46. mov fp, #0
  47. ldmia sp!, {a2}
  48. /* Pop argc off the stack and save a pointer to argv */
  49. ldr ip,=operatingsystem_parameter_argc
  50. ldr a3,=operatingsystem_parameter_argv
  51. str a2,[ip]
  52. /* calc envp */
  53. add a2,a2,#1
  54. add a2,sp,a2,LSL #2
  55. ldr ip,=operatingsystem_parameter_envp
  56. str sp,[a3]
  57. str a2,[ip]
  58. /* Save initial stackpointer */
  59. ldr ip,=__stkptr
  60. str sp,[ip]
  61. /* align sp again to 8 byte boundary, needed by eabi */
  62. sub sp,sp,#4
  63. /* Let the libc call main and exit with its return code. */
  64. bl PASCALMAIN
  65. .globl _haltproc
  66. .type _haltproc,#function
  67. _haltproc:
  68. /* r0 contains exitcode */
  69. swi 0x900001
  70. b _haltproc
  71. .globl _haltproc_eabi
  72. .type _haltproc_eabi,#function
  73. _haltproc_eabi:
  74. ldr r0,=__dl_fini
  75. ldr r0,[r0]
  76. cmp r0,#0
  77. /* only branch if not equal zero */
  78. movne lr,pc
  79. bxne r0 /* we require armv5 anyway, so use bx here */
  80. .Lloop:
  81. ldr r0,=operatingsystem_result
  82. ldr r0,[r0]
  83. mov r7,#248 /* exit group call */
  84. swi 0x0
  85. b .Lloop
  86. /* Define a symbol for the first piece of initialized data. */
  87. .data
  88. .globl __data_start
  89. __data_start:
  90. .long 0
  91. .weak data_start
  92. data_start = __data_start
  93. .bss
  94. .comm __dl_fini,4
  95. .comm __stkptr,4
  96. .comm operatingsystem_parameter_envp,4
  97. .comm operatingsystem_parameter_argc,4
  98. .comm operatingsystem_parameter_argv,4
  99. .section ".comment"
  100. .byte 0
  101. .ascii "generated by FPC http://www.freepascal.org\0"
  102. /* We need this stuff to make gdb behave itself, otherwise
  103. gdb will chokes with SIGILL when trying to debug apps.
  104. */
  105. .section ".note.ABI-tag", "a"
  106. .align 4
  107. .long 1f - 0f
  108. .long 3f - 2f
  109. .long 1
  110. 0: .asciz "GNU"
  111. 1: .align 4
  112. 2: .long 0
  113. .long 2,0,0
  114. 3: .align 4
  115. .section .note.GNU-stack,"",%progbits