prt0.as 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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,U_SYSTEM_ENVP
  75. movl 8(%ebp),%eax
  76. movl %eax,U_SYSTEM_ARGC
  77. movl 12(%ebp),%eax
  78. movl %eax,U_SYSTEM_ARGV
  79. movl (%eax),%edx
  80. movl %edx,__progname
  81. testl %edx,%edx
  82. je .L2
  83. pushl $47
  84. movl __progname,%eax
  85. pushl %eax
  86. call _strrchr
  87. addl $8,%esp
  88. movl %eax,%eax
  89. movl %eax,__progname
  90. cmpl $0,__progname
  91. jne .L3
  92. movl 12(%ebp),%eax
  93. movl (%eax),%edx
  94. movl %edx,__progname
  95. jmp .L2
  96. .align 4
  97. .L3:
  98. incl __progname
  99. .L4:
  100. .L2:
  101. cmpl $0,28(%ebp)
  102. je .L5
  103. movl 28(%ebp),%eax
  104. movl %eax,__ps_strings
  105. .L5:
  106. # pushl $_fini
  107. # call atexit
  108. # addl $4,%esp
  109. # call _init
  110. # copied from linux
  111. finit /* initialize fpu */
  112. fwait
  113. fldcw ___fpucw
  114. xorl %ebp,%ebp
  115. call _main
  116. pushl %eax
  117. jmp _haltproc
  118. .p2align 2,0x90
  119. .globl _haltproc
  120. .type _haltproc,@function
  121. _haltproc:
  122. mov $1,%eax
  123. movzwl U_SYSTEM_EXITCODE,%ebx
  124. pushl %ebx
  125. call _actualsyscall
  126. addl $4,%esp
  127. jmp _haltproc
  128. _actualsyscall:
  129. int $0x80
  130. jb .LErrorcode
  131. xor %ebx,%ebx
  132. ret
  133. .LErrorcode:
  134. mov %eax,%ebx
  135. mov $-1,%eax
  136. ret
  137. .p2align 2,0x90
  138. # This section is needed for NetBSD to recognize a NetBSD binary as such.
  139. # otherwise it will be startup in Linux emulation mode.
  140. .section ".note.netbsd.ident","a"
  141. .p2align 2
  142. .long 7
  143. .long 4
  144. # ELF NOTE TYPE NETBSD TAG
  145. .long 1
  146. .ascii "NetBSD\0\0"
  147. .long 199905