prt0.as 3.8 KB

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