cprt0.as 4.5 KB

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