cprt0.as 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 12.1
  27. # FreeBSD 13.1 1301000
  28. .file "cprt0.as"
  29. .ident "FreePascal 2.6.x/2.7.x series dynlinked to libc"
  30. .section .note.ABI-tag,"a",@progbits
  31. .p2align 2
  32. .type abitag, @object
  33. .size abitag, 24
  34. abitag:
  35. .long 8
  36. .long 4
  37. .long 1
  38. .string "FreeBSD"
  39. .long 1201000
  40. .section .rodata.str1.1,"aMS",@progbits,1
  41. .LC0:
  42. .string ""
  43. .data
  44. .p2align 2
  45. .globl __progname
  46. .type __progname,@object
  47. .size __progname,4
  48. __progname:
  49. .long .LC0
  50. .text
  51. .p2align 2,,3
  52. .type __fpucw,@object
  53. .size __fpucw,4
  54. .global __fpucw
  55. ___fpucw:
  56. .long 0x1332
  57. .globl ___fpc_brk_addr /* heap management */
  58. .type ___fpc_brk_addr,@object
  59. .size ___fpc_brk_addr,4
  60. ___fpc_brk_addr:
  61. .long 0
  62. .text
  63. .p2align 4,,15
  64. .globl _start
  65. .type _start,@function
  66. _start:
  67. pushl %ebp
  68. movl %esp,%ebp
  69. subl $40,%esp
  70. call get_rtld_cleanup
  71. movl %eax,%edx
  72. pushl %edi
  73. pushl %esi
  74. pushl %ebx
  75. #APP
  76. movl %edx,%edx
  77. #NO_APP
  78. leal 8(%ebp),%edi
  79. movl %edi,operatingsystem_parameter_argv
  80. mov -4(%edi),%eax
  81. movl %eax,operatingsystem_parameter_argc
  82. movl 4(%ebp),%ebx
  83. leal 12(%ebp,%ebx,4),%esi
  84. movl %esi,operatingsystem_parameter_envp
  85. movl %esi,environ
  86. testl %ebx,%ebx
  87. jle .L2
  88. movl 8(%ebp),%eax
  89. testl %eax,%eax
  90. je .L2
  91. movl %eax,__progname
  92. cmpb $0,(%eax)
  93. je .L2
  94. .p2align 2,0x90
  95. .L6:
  96. cmpb $47,(%eax)
  97. jne .L5
  98. leal 1(%eax),%ecx
  99. movl %ecx,__progname
  100. .L5:
  101. incl %eax
  102. cmpb $0,(%eax)
  103. jne .L6
  104. .L2:
  105. movl $_DYNAMIC,%eax
  106. testl %eax,%eax
  107. je .LTLS
  108. pushl %edx
  109. call atexit
  110. addl $4,%esp
  111. .L9:
  112. pushl $_fini
  113. call atexit
  114. call _init
  115. # pushl %esi
  116. # pushl %edi
  117. # pushl %ebx
  118. # call main
  119. # pushl %eax
  120. # call exit
  121. finit /* initialize fpu */
  122. fwait
  123. fldcw ___fpucw
  124. xorl %ebp,%ebp
  125. call main
  126. pushl %eax
  127. jmp _haltproc
  128. .LTLS:
  129. call _init_tls
  130. jmp .L9
  131. .p2align 2,0x90
  132. .globl _haltproc
  133. .type _haltproc,@function
  134. _haltproc:
  135. mov $1,%eax
  136. movzwl operatingsystem_result,%ebx
  137. pushl %ebx
  138. call .Lactualsyscall
  139. addl $4,%esp
  140. jmp _haltproc
  141. .Lactualsyscall:
  142. int $0x80
  143. jb .LErrorcode
  144. xor %ebx,%ebx
  145. ret
  146. .LErrorcode:
  147. mov %eax,%ebx
  148. mov $-1,%eax
  149. ret
  150. .p2align 2,0x90
  151. .Lfe1:
  152. .size _start,.Lfe1-_start
  153. .comm environ,4,4
  154. .p2align 4,,15
  155. .type get_rtld_cleanup, @function
  156. get_rtld_cleanup:
  157. pushl %ebp
  158. movl %esp, %ebp
  159. subl $4, %esp
  160. #APP
  161. movl %edx,-4(%ebp)
  162. #NO_APP
  163. movl -4(%ebp), %eax
  164. leave
  165. ret
  166. .weak _DYNAMIC
  167. .ident "GCC: (GNU) 3.4.2 - FPC: 2.0.2"
  168. .bss
  169. .type __stkptr,@object
  170. .size __stkptr,4
  171. .global __stkptr
  172. __stkptr:
  173. .skip 4
  174. .type operatingsystem_parameters,@object
  175. .size operatingsystem_parameters,12
  176. operatingsystem_parameters:
  177. .skip 3*4
  178. .global operatingsystem_parameter_envp
  179. .global operatingsystem_parameter_argc
  180. .global operatingsystem_parameter_argv
  181. .set operatingsystem_parameter_envp,operatingsystem_parameters+0
  182. .set operatingsystem_parameter_argc,operatingsystem_parameters+4
  183. .set operatingsystem_parameter_argv,operatingsystem_parameters+8
  184. //.section .threadvar,"aw",@nobits
  185. .comm ___fpc_threadvar_offset,4