cprt0.as 5.0 KB

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