prt0.as 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. ___fpucw:
  41. .long 0x1332
  42. .globl ___fpc_brk_addr /* heap management */
  43. .type ___fpc_brk_addr,@object
  44. .size ___fpc_brk_addr,4
  45. ___fpc_brk_addr:
  46. .long 0
  47. #APP
  48. .text
  49. .align 4
  50. .globl __start
  51. .globl _start
  52. _start:
  53. __start:
  54. pushl %ebx # ps_strings
  55. pushl %ecx # obj
  56. pushl %edx # cleanup
  57. movl 12(%esp),%eax
  58. leal 20(%esp,%eax,4),%ecx
  59. leal 16(%esp),%edx
  60. pushl %ecx
  61. pushl %edx
  62. pushl %eax
  63. call ___start
  64. #NO_APP
  65. .text
  66. .align 4
  67. .globl ___start
  68. .type ___start,@function
  69. ___start:
  70. pushl %ebp
  71. movl %esp,%ebp
  72. movl 16(%ebp),%eax
  73. movl %eax,environ
  74. movl %eax,operatingsystem_parameter_envp
  75. movl 8(%ebp),%eax
  76. movl %eax,operatingsystem_parameter_argc
  77. movl 12(%ebp),%eax
  78. movl %eax,operatingsystem_parameter_argv
  79. movl (%eax),%edx
  80. movl %edx,__progname
  81. testl %edx,%edx
  82. je .L2
  83. movl __progname,%edx
  84. // Increase until 0 found
  85. movl $0,%ebx
  86. .LL1:
  87. movb (%edx,%ebx),%al
  88. orb %al,%al
  89. je .LL2
  90. incl %ebx
  91. .LL2:
  92. decl %ebx
  93. movb (%edx,%ebx),%al
  94. cmpb $47,%al
  95. je .LL3
  96. cmpl $0,%ebx
  97. je .LL4
  98. .LL3: // slash found
  99. incl %ebx
  100. leal (%edx,%ebx),%eax
  101. movl %eax,__progname
  102. .LL4:
  103. cmpl $0,__progname
  104. jne .L3
  105. movl 12(%ebp),%eax
  106. movl (%eax),%edx
  107. movl %edx,__progname
  108. jmp .L2
  109. .align 4
  110. .L3:
  111. incl __progname
  112. .L4:
  113. .L2:
  114. cmpl $0,28(%ebp)
  115. je .L5
  116. movl 28(%ebp),%eax
  117. movl %eax,__ps_strings
  118. .L5:
  119. # pushl $_fini
  120. # call atexit
  121. # addl $4,%esp
  122. # call _init
  123. # copied from linux
  124. finit /* initialize fpu */
  125. fwait
  126. fldcw ___fpucw
  127. xorl %ebp,%ebp
  128. call _main
  129. pushl %eax
  130. jmp _haltproc
  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 _actualsyscall
  139. addl $4,%esp
  140. jmp _haltproc
  141. _actualsyscall:
  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. # This section is needed for NetBSD to recognize a NetBSD binary as such.
  152. # otherwise it will be startup in Linux emulation mode.
  153. .section ".note.netbsd.ident","a"
  154. .p2align 2
  155. .long 7
  156. .long 4
  157. # ELF NOTE TYPE NETBSD TAG
  158. .long 1
  159. .ascii "NetBSD\0\0"
  160. .long 199905
  161. .comm environ,4
  162. .comm operatingsystem_parameter_envp,4
  163. .comm operatingsystem_parameter_argc,4
  164. .comm operatingsystem_parameter_argv,4