prt0.as 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. #
  2. # $Id$
  3. # This file is part of the Free Pascal run time library.
  4. # Copyright (c) 1998-2000 by the Free Pascal development team.
  5. #
  6. # Go32V1 Startup code
  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. # Called as start(argc, argv, envp)
  18. #
  19. # gs:edx points to prog_info structure. All other registers are OBSOLETE
  20. # but included for backwards compatibility
  21. #
  22. .text
  23. .globl _start
  24. _start:
  25. .globl start
  26. start:
  27. # the first instruction must be movl %eax,
  28. # because that is the way GO32V2 makes the difference between V1 and V2 coff format
  29. movl %eax,__hard_master
  30. movl %esi,___pid
  31. movl %edi,___transfer_buffer
  32. movl %ebx,_ScreenPrimary
  33. movl %ebp,_ScreenSecondary
  34. cmpl $0, %edx
  35. je Lcopy_none
  36. movw %gs,%cx
  37. movw %ds,%ax
  38. cmpw %cx,%ax
  39. je Lcopy_none
  40. # set the right size
  41. movl $40,U_SYSTEM_GO32_INFO_BLOCK
  42. movl %gs:(%edx), %ecx
  43. cmpl U_SYSTEM_GO32_INFO_BLOCK, %ecx
  44. jbe Lcopy_less
  45. movl U_SYSTEM_GO32_INFO_BLOCK, %ecx
  46. Lcopy_less:
  47. movl $U_SYSTEM_GO32_INFO_BLOCK, %edi
  48. addl $3, %ecx
  49. andl $0xfffffffc, %ecx
  50. movl %ecx, (%edi)
  51. addl $4, %edi
  52. addl $4, %edx
  53. subl $4, %ecx
  54. Lcopy_more:
  55. movl %gs:(%edx), %eax
  56. movl %eax, (%edi)
  57. addl $4, %edx
  58. addl $4, %edi
  59. subl $4, %ecx
  60. jnz Lcopy_more
  61. movl U_SYSTEM_GO32_INFO_BLOCK+4, %eax
  62. movl %eax, _ScreenPrimary
  63. movl U_SYSTEM_GO32_INFO_BLOCK+8, %eax
  64. movl %eax, _ScreenSecondary
  65. movl U_SYSTEM_GO32_INFO_BLOCK+12, %eax
  66. movl %eax, ___transfer_buffer
  67. movl U_SYSTEM_GO32_INFO_BLOCK+20, %eax
  68. movl %eax, ___pid
  69. movl U_SYSTEM_GO32_INFO_BLOCK+24, %eax
  70. movl %eax, __hard_master
  71. jmp Lcopy_done
  72. Lcopy_none:
  73. movl %ebx,U_SYSTEM_GO32_INFO_BLOCK+4
  74. movl %ebp,U_SYSTEM_GO32_INFO_BLOCK+8
  75. movl %edi,U_SYSTEM_GO32_INFO_BLOCK+12
  76. movl $4096,U_SYSTEM_GO32_INFO_BLOCK+16
  77. movl %esi,U_SYSTEM_GO32_INFO_BLOCK+20
  78. movl %eax,U_SYSTEM_GO32_INFO_BLOCK+24
  79. movl $28, U_SYSTEM_GO32_INFO_BLOCK
  80. Lcopy_done:
  81. movw U_SYSTEM_GO32_INFO_BLOCK+36,%ax
  82. movw %ax,_run_mode
  83. # I need a value for the stack bottom,
  84. # According to Pierre, from the source code of go32v1
  85. # the stack is 256Kb in length
  86. movl %esp,%eax
  87. subl $0x40000,%eax
  88. movl %eax,__stkbottom
  89. movw U_SYSTEM_GO32_INFO_BLOCK+26,%ax
  90. movw %ax,_core_selector
  91. movl U_SYSTEM_GO32_INFO_BLOCK+28,%eax
  92. movl %eax,U_SYSTEM_STUB_INFO
  93. xorl %esi,%esi
  94. xorl %edi,%edi
  95. xorl %ebp,%ebp
  96. xorl %ebx,%ebx
  97. movl %esp,%ebx
  98. movl $0x0,%ebp
  99. movl %esp,%ebx
  100. movl 8(%ebx),%eax
  101. movl %eax,_environ
  102. movl %eax,U_SYSTEM_ENVP
  103. movl 4(%ebx),%eax
  104. movl %eax,_args
  105. movl %eax,U_SYSTEM_ARGV
  106. movl (%ebx),%eax
  107. movl %eax,_argc
  108. movl %eax,U_SYSTEM_ARGC
  109. call PASCALMAIN
  110. exit_again:
  111. movl $0x4c00,%eax
  112. int $0x21
  113. jmp exit_again
  114. ret
  115. .data
  116. .globl _argc
  117. _argc:
  118. .long 0
  119. .globl _args
  120. _args:
  121. .long 0
  122. .globl _environ
  123. _environ:
  124. .long 0
  125. .globl __stkbottom
  126. __stkbottom:
  127. .long 0
  128. .globl _run_mode
  129. _run_mode:
  130. .word 0
  131. .globl _core_selector
  132. _core_selector:
  133. .word 0
  134. .globl ___pid
  135. ___pid:
  136. .long 42
  137. .globl ___transfer_buffer
  138. ___transfer_buffer:
  139. .long 0
  140. .globl _ScreenPrimary
  141. _ScreenPrimary:
  142. .long 0
  143. .globl _ScreenSecondary
  144. _ScreenSecondary:
  145. .long 0
  146. .globl __hard_master
  147. __hard_master:
  148. .byte 0
  149. .globl __hard_slave
  150. __hard_slave:
  151. .byte 0
  152. .globl __core_select
  153. __core_select:
  154. .short 0
  155. #
  156. # $Log$
  157. # Revision 1.2 2000-01-07 16:32:23 daniel
  158. # * copyright 2000 added
  159. #
  160. # Revision 1.1 1998/12/21 13:07:02 peter
  161. # * use -FE
  162. #
  163. # Revision 1.4 1998/08/04 13:35:34 carl
  164. # * stack size default is 256Kb! not 16K! as information stated by Pierre
  165. #
  166. # Revision 1.3 1998/05/22 00:39:32 peter
  167. # * go32v1, go32v2 recompiles with the new objects
  168. # * remake3 works again with go32v2
  169. # - removed some "optimizes" from daniel which were wrong
  170. #
  171. #