cprt0.as 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. #
  2. # $Id: cprt0.as,v 1.3 2000/11/21 19:03:23 marco Exp $
  3. # This file is part of the Free Pascal run time library.
  4. # Copyright (c) 1999-2000 by Marco van de Voort, Michael Van Canneyt
  5. # and Peter Vreman
  6. # members of the Free Pascal development team.
  7. #
  8. # See the file COPYING.FPC, included in this distribution,
  9. # for details about the copyright.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY;without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. #
  15. #**********************************************************************}
  16. # FreeBSD ELF startup code for Free Pascal for dynamical linking to libc.
  17. #
  18. # To avoid needing a "COMPAT" system, patch the constant following the
  19. # "FreeBSD" field in the abitag to the relevant ABI number
  20. # Some versions of the "file" command support
  21. # visualizing this constant. If not use elfdump, or patch
  22. # automatically using the ../i386/identpatch.sh script
  23. #
  24. # some typical values:
  25. #
  26. # freebsd 5.4 504000
  27. # freebsd 6.3 (prerelease) : 603100
  28. # freebsd 7.0 700055
  29. # freebsd 8.0 800500 (-stable)
  30. # FreeBSD 9.0 900044
  31. # FreeBSD 11.0 1100122
  32. # FreeBSD 11.1 1101001
  33. # FreeBSD 12.1 1201000
  34. .file "cprt0.as"
  35. .ident "FreePascal 2.6.x/2.7.x series dynlinked to libc"
  36. .section .note.ABI-tag,"a",@progbits
  37. .p2align 2
  38. .type abitag, @object
  39. .size abitag, 24
  40. abitag:
  41. .long 8
  42. .long 4
  43. .long 1
  44. .string "FreeBSD"
  45. .long 900044
  46. .section .rodata.str1.1,"aMS",@progbits,1
  47. .LC0:
  48. .string ""
  49. .data
  50. .p2align 2
  51. .globl __progname
  52. .type __progname,@object
  53. .size __progname,4
  54. __progname:
  55. .long .LC0
  56. .text
  57. .p2align 2,,3
  58. .type __fpucw,@object
  59. .size __fpucw,4
  60. .global __fpucw
  61. ___fpucw:
  62. .long 0x1332
  63. .globl ___fpc_brk_addr /* heap management */
  64. .type ___fpc_brk_addr,@object
  65. .size ___fpc_brk_addr,4
  66. ___fpc_brk_addr:
  67. .long 0
  68. .text
  69. .p2align 4,,15
  70. .globl _start
  71. .type _start,@function
  72. _start:
  73. pushl %ebp
  74. movl %esp,%ebp
  75. subl $40,%esp
  76. call get_rtld_cleanup
  77. movl %eax,%edx
  78. pushl %edi
  79. pushl %esi
  80. pushl %ebx
  81. #APP
  82. movl %edx,%edx
  83. #NO_APP
  84. leal 8(%ebp),%edi
  85. movl %edi,operatingsystem_parameter_argv
  86. mov -4(%edi),%eax
  87. movl %eax,operatingsystem_parameter_argc
  88. movl 4(%ebp),%ebx
  89. leal 12(%ebp,%ebx,4),%esi
  90. movl %esi,operatingsystem_parameter_envp
  91. movl %esi,environ
  92. testl %ebx,%ebx
  93. jle .L2
  94. movl 8(%ebp),%eax
  95. testl %eax,%eax
  96. je .L2
  97. movl %eax,__progname
  98. cmpb $0,(%eax)
  99. je .L2
  100. .p2align 2,0x90
  101. .L6:
  102. cmpb $47,(%eax)
  103. jne .L5
  104. leal 1(%eax),%ecx
  105. movl %ecx,__progname
  106. .L5:
  107. incl %eax
  108. cmpb $0,(%eax)
  109. jne .L6
  110. .L2:
  111. movl $_DYNAMIC,%eax
  112. testl %eax,%eax
  113. je .LTLS
  114. pushl %edx
  115. call atexit
  116. addl $4,%esp
  117. .L9:
  118. pushl $_fini
  119. call atexit
  120. call _init
  121. # pushl %esi
  122. # pushl %edi
  123. # pushl %ebx
  124. # call main
  125. # pushl %eax
  126. # call exit
  127. finit /* initialize fpu */
  128. fwait
  129. fldcw ___fpucw
  130. xorl %ebp,%ebp
  131. call main
  132. pushl %eax
  133. jmp _haltproc
  134. .LTLS:
  135. call _init_tls
  136. jmp .L9
  137. .p2align 2,0x90
  138. .globl _haltproc
  139. .type _haltproc,@function
  140. _haltproc:
  141. mov $1,%eax
  142. movzwl operatingsystem_result,%ebx
  143. pushl %ebx
  144. call .Lactualsyscall
  145. addl $4,%esp
  146. jmp _haltproc
  147. .Lactualsyscall:
  148. int $0x80
  149. jb .LErrorcode
  150. xor %ebx,%ebx
  151. ret
  152. .LErrorcode:
  153. mov %eax,%ebx
  154. mov $-1,%eax
  155. ret
  156. .p2align 2,0x90
  157. .Lfe1:
  158. .size _start,.Lfe1-_start
  159. .comm environ,4,4
  160. .p2align 4,,15
  161. .type get_rtld_cleanup, @function
  162. get_rtld_cleanup:
  163. pushl %ebp
  164. movl %esp, %ebp
  165. subl $4, %esp
  166. #APP
  167. movl %edx,-4(%ebp)
  168. #NO_APP
  169. movl -4(%ebp), %eax
  170. leave
  171. ret
  172. .weak _DYNAMIC
  173. .ident "GCC: (GNU) 3.4.2 - FPC: 2.0.2"
  174. .bss
  175. .type __stkptr,@object
  176. .size __stkptr,4
  177. .global __stkptr
  178. __stkptr:
  179. .skip 4
  180. .type operatingsystem_parameters,@object
  181. .size operatingsystem_parameters,12
  182. operatingsystem_parameters:
  183. .skip 3*4
  184. .global operatingsystem_parameter_envp
  185. .global operatingsystem_parameter_argc
  186. .global operatingsystem_parameter_argv
  187. .set operatingsystem_parameter_envp,operatingsystem_parameters+0
  188. .set operatingsystem_parameter_argc,operatingsystem_parameters+4
  189. .set operatingsystem_parameter_argv,operatingsystem_parameters+8
  190. //.section .threadvar,"aw",@nobits
  191. .comm ___fpc_threadvar_offset,4