prt0.as 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. #
  2. # $Id$
  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. # NetBSD standard (static) ELF/i386 startup code for Free Pascal
  18. #
  19. .file "prt0.s"
  20. .version "01.01"
  21. gcc2_compiled.:
  22. .globl __progname
  23. .section .rodata
  24. .LC0:
  25. .ascii "\0"
  26. .data
  27. .align 4
  28. .type __progname,@object
  29. .size __progname,4
  30. __progname:
  31. .long .LC0
  32. .globl __ps_strings
  33. .align 4
  34. .type __ps_strings,@object
  35. .size __ps_strings,4
  36. __ps_strings:
  37. .long 0
  38. .align 4
  39. ___fpucw:
  40. .long 0x1332
  41. .globl ___fpc_brk_addr /* heap management */
  42. .type ___fpc_brk_addr,@object
  43. .size ___fpc_brk_addr,4
  44. ___fpc_brk_addr:
  45. .long 0
  46. #APP
  47. .text
  48. .align 4
  49. .globl __start
  50. .globl _start
  51. _start:
  52. __start:
  53. pushl %ebx # ps_strings
  54. pushl %ecx # obj
  55. pushl %edx # cleanup
  56. movl 12(%esp),%eax
  57. leal 20(%esp,%eax,4),%ecx
  58. leal 16(%esp),%edx
  59. pushl %ecx
  60. pushl %edx
  61. pushl %eax
  62. call ___start
  63. #NO_APP
  64. .text
  65. .align 4
  66. .globl ___start
  67. .type ___start,@function
  68. ___start:
  69. pushl %ebp
  70. movl %esp,%ebp
  71. movl 16(%ebp),%eax
  72. movl %eax,environ
  73. movl %eax,U_SYSTEM_ENVP
  74. movl 8(%ebp),%eax
  75. movl %eax,U_SYSTEM_ARGC
  76. movl 12(%ebp),%eax
  77. movl %eax,U_SYSTEM_ARGV
  78. movl (%eax),%edx
  79. movl %edx,__progname
  80. testl %edx,%edx
  81. je .L2
  82. pushl $47
  83. movl __progname,%eax
  84. pushl %eax
  85. call _strrchr
  86. addl $8,%esp
  87. movl %eax,%eax
  88. movl %eax,__progname
  89. cmpl $0,__progname
  90. jne .L3
  91. movl 12(%ebp),%eax
  92. movl (%eax),%edx
  93. movl %edx,__progname
  94. jmp .L2
  95. .align 4
  96. .L3:
  97. incl __progname
  98. .L4:
  99. .L2:
  100. cmpl $0,28(%ebp)
  101. je .L5
  102. movl 28(%ebp),%eax
  103. movl %eax,__ps_strings
  104. .L5:
  105. # pushl $_fini
  106. # call atexit
  107. # addl $4,%esp
  108. # call _init
  109. # copied from linux
  110. finit /* initialize fpu */
  111. fwait
  112. fldcw ___fpucw
  113. xorl %ebp,%ebp
  114. call _main
  115. pushl %eax
  116. jmp _haltproc
  117. .p2align 2,0x90
  118. .globl _haltproc
  119. .type _haltproc,@function
  120. _haltproc:
  121. mov $1,%eax
  122. movzwl U_SYSTEM_EXITCODE,%ebx
  123. pushl %ebx
  124. call _actualsyscall
  125. addl $4,%esp
  126. jmp _haltproc
  127. _actualsyscall:
  128. int $0x80
  129. jb .LErrorcode
  130. xor %ebx,%ebx
  131. ret
  132. .LErrorcode:
  133. mov %eax,%ebx
  134. mov $-1,%eax
  135. ret
  136. .p2align 2,0x90
  137. .Lfe1:
  138. .size ___start,.Lfe1-___start
  139. .align 4
  140. .type _strrchr,@function
  141. _strrchr:
  142. pushl %ebp
  143. movl %esp,%ebp
  144. subl $8,%esp
  145. movl 12(%ebp),%eax
  146. movb %al,-1(%ebp)
  147. movl $0,-8(%ebp)
  148. .align 4
  149. .L7:
  150. movl 8(%ebp),%eax
  151. movb (%eax),%dl
  152. cmpb -1(%ebp),%dl
  153. jne .L10
  154. movl 8(%ebp),%eax
  155. movl %eax,-8(%ebp)
  156. .L10:
  157. movl 8(%ebp),%eax
  158. cmpb $0,(%eax)
  159. jne .L9
  160. movl -8(%ebp),%edx
  161. movl %edx,%eax
  162. jmp .L6
  163. .align 4
  164. .L11:
  165. .L9:
  166. incl 8(%ebp)
  167. jmp .L7
  168. .align 4
  169. .L8:
  170. .L6:
  171. leave
  172. ret
  173. .Lfe2:
  174. .size _strrchr,.Lfe2-_strrchr
  175. .comm environ,4,4
  176. # This section is needed for NetBSD to recognize a NetBSD binary as such.
  177. # otherwise it will be startup in Linux emulation mode.
  178. .section ".note.netbsd.ident","a"
  179. .p2align 2
  180. .long 7
  181. .long 4
  182. # ELF NOTE TYPE NETBSD TAG
  183. .long 1
  184. .ascii "NetBSD\0\0"
  185. .long 199905