v2prt0.as 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863
  1. /*
  2. $Id$
  3. */
  4. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  5. /*****************************************************************************\
  6. * Interface to 32-bit executable (from stub.asm)
  7. *
  8. * cs:eip according to COFF header
  9. * ds 32-bit data segment for COFF program
  10. * fs selector for our data segment (fs:0 is stubinfo)
  11. * ss:sp our stack (ss to be freed)
  12. * <others> All unspecified registers have unspecified values in them.
  13. \*****************************************************************************/
  14. /* modified by Pierre Muller to become the prt0.s for FPC Pascal */
  15. .file "v2prt0.as"
  16. /* #include "stubinfo.h" */
  17. STUBINFO = 0
  18. STUBINFO_MAGIC = 0
  19. STUBINFO_SIZE = 0x10
  20. STUBINFO_MINSTACK = 0x14
  21. STUBINFO_MEMORY_HANDLE = 0x18
  22. STUBINFO_INITIAL_SIZE = 0x1c
  23. STUBINFO_MINKEEP = 0x20
  24. STUBINFO_DS_SELECTOR = 0x22
  25. STUBINFO_DS_SEGMENT = 0x24
  26. STUBINFO_PSP_SELECTOR = 0x26
  27. STUBINFO_CS_SELECTOR = 0x28
  28. STUBINFO_ENV_SIZE = 0x2a
  29. STUBINFO_BASENAME = 0x2c
  30. STUBINFO_ARGV0 = 0x34
  31. STUBINFO_DPMI_SERVER = 0x44
  32. STUBINFO_END = 0x54
  33. /* .comm __stklen, 4
  34. this is added to the compiler so that we can specify
  35. the stack size */
  36. .comm __stkbottom,4
  37. .comm __stubinfo, 4
  38. .comm ___djgpp_base_address, 4
  39. .comm ___djgpp_selector_limit, 4
  40. .comm ___djgpp_stack_limit, 4
  41. .lcomm sel_buf, 8
  42. /* ___djgpp_ds_alias defined in go32/exceptn.s */
  43. /* inserted at the end of this file */
  44. /* we use a local copy that will be copied to exceptn.s */
  45. .globl ___v2prt0_ds_alias
  46. ___v2prt0_ds_alias:
  47. .long 0
  48. .data
  49. ___djgpp_memory_handle_pointer:
  50. .long ___djgpp_memory_handle_list+8 /* Next free, first for stub */
  51. .comm ___djgpp_memory_handle_list, 2048 /* Enough for 256 handles */
  52. sbrk16_first_byte:
  53. .include "sbrk16.ah"
  54. sbrk16_last_byte:
  55. sbrk16_api_ofs:
  56. .long 0
  57. sbrk16_api_seg:
  58. .word 0
  59. zero:
  60. .long 0
  61. exit16_first_byte:
  62. .include "exit16.ah"
  63. exit16_last_byte:
  64. /* hook_387_emulator:
  65. .long ___emu387_load_hook */
  66. /* this is for when main comes from a library */
  67. .long _main
  68. .text
  69. .globl start
  70. start:
  71. pushl %ds /* set %es same as %ds */
  72. popl %es /* push/pop 4 bytes shorter than ax */
  73. /* Enable NULL pointer protection if DPMI supports it */
  74. testb $0x1, __crt0_startup_flags+1 /* include/crt0.h */
  75. jnz 1f
  76. movl $start, %eax
  77. cmpl $0x1000, %eax
  78. jl 1f
  79. movw $0x507, %ax
  80. .byte 0x64 /* fs: */
  81. movl STUBINFO_MEMORY_HANDLE, %esi
  82. xorl %ebx, %ebx /* Offset 0 in mem block */
  83. movl $1, %ecx /* Set one page */
  84. movl $zero, %edx
  85. int $0x31 /* Make null page uncommitted */
  86. 1:
  87. /* Create an alias for DS to be used by real-mode callbacks (exception handler messes with DS itself) */
  88. movw %ds, %bx
  89. movw $0x000a, %ax
  90. int $0x31
  91. jnc ds_alias_ok
  92. movb $0x4c, %ah
  93. int $0x21
  94. ds_alias_ok:
  95. movw %ax, ___v2prt0_ds_alias
  96. movl %eax, %ebx
  97. movw $0x0009, %ax
  98. movw %cs, %cx /* get CPL from %cs */
  99. andl $3, %ecx
  100. shll $5, %ecx /* move it into place */
  101. orw $0xc093, %cx
  102. int $0x31 /* set access rights for alias */
  103. /* Maybe set our DS limit to 4Gb in size if flag set */
  104. testb $0x80, __crt0_startup_flags /* include/crt0.h */
  105. jz 2f
  106. movw $0xffff, %cx
  107. movl %ecx, %edx
  108. movw $0x0008, %ax /* reset alias limit to -1 */
  109. int $0x31
  110. movw %cs, %bx
  111. movw $0x0008, %ax /* reset DS limit to -1 */
  112. int $0x31
  113. movw %ds, %bx
  114. movw $0x0008, %ax /* reset DS limit to -1 */
  115. int $0x31
  116. lsl %ebx, %ebx /* Should be -1 */
  117. incl %ebx
  118. jz 2f
  119. andb $0x7f, __crt0_startup_flags /* clear it if failure */
  120. 2:
  121. /* Allocate some DOS memory and copy our sbrk helper into it. */
  122. movl $sbrk16_first_byte, %esi
  123. movzwl 8(%esi), %ebx
  124. shrl $4, %ebx
  125. movw $0x0100, %ax
  126. int $0x31
  127. jnc dos_alloc_ok
  128. movb $0x4c, %ah
  129. int $0x21
  130. dos_alloc_ok:
  131. movw %cs, 2(%esi)
  132. /* store API information */
  133. movw %ds, 4(%esi)
  134. movw %dx, 6(%esi)
  135. /* selector for allocated block */
  136. movzwl (%esi), %eax /* calculate API address */
  137. movl %eax, sbrk16_api_ofs
  138. pushl %es /* move the data */
  139. movw %dx, %es
  140. movl $(sbrk16_last_byte - sbrk16_first_byte), %ecx
  141. shrl $2,%ecx
  142. xorl %edi, %edi
  143. cld
  144. rep
  145. movsl
  146. popl %es
  147. movl %edx, %ebx /* dos memory selector */
  148. movw $0x000b, %ax /* get descriptor */
  149. movl $sel_buf, %edi
  150. int $0x31
  151. andb $0xbf, sel_buf+6 /* make 16-bit */
  152. andb $0xf0, sel_buf+5 /* remove old type */
  153. orb $0x0a, sel_buf+5 /* set new type to code/read */
  154. xorl %eax, %eax /* allocate new selector */
  155. movw $0x0001, %cx
  156. int $0x31
  157. movw %ax, sbrk16_api_seg
  158. movl %eax, %ebx
  159. movw $0x000c, %ax /* set descriptor */
  160. movl $sel_buf, %edi
  161. int $0x31
  162. /* Initialize the brk/sbrk variables */
  163. /* movl $end, __what_size_app_thinks_it_is */
  164. .byte 0x64 /* fs: */
  165. movl STUBINFO_INITIAL_SIZE, %eax
  166. movl %eax, __what_size_dpmi_thinks_we_are
  167. /* Maybe lock the initial block, expects BX:CX */
  168. movl %ecx,%ebx
  169. movl %edx,%ecx
  170. addw $4096,%cx /* Skip null page */
  171. adcl $0,%ebx
  172. subl $4096,%eax
  173. pushl %eax
  174. call lock_memory
  175. .byte 0x64 /* fs: */
  176. movl STUBINFO_MEMORY_HANDLE, %eax
  177. movl %eax, ___djgpp_memory_handle_list
  178. .byte 0x64 /* fs: */ /* copy stubinfo into local memory */
  179. movl STUBINFO_SIZE, %eax
  180. pushl %eax
  181. call ___sbrk
  182. movl %eax, __stubinfo
  183. movl %eax,U_SYSTEM_STUB_INFO
  184. movl %eax, %edi
  185. .byte 0x64 /* fs: */
  186. movl STUBINFO_SIZE, %ecx
  187. shrl $2, %ecx
  188. xorl %esi, %esi /* Zero */
  189. pushl %ds
  190. pushl %fs
  191. popl %ds
  192. cld
  193. rep
  194. movsl
  195. popl %ds
  196. movl __stklen, %eax /* get program-requested stack size */
  197. .byte 0x64 /* fs: */
  198. movl STUBINFO_MINSTACK, %ecx /* get stub-requested stack size */
  199. cmpl %ecx, %eax
  200. jge use_stubinfo_stack_size /* use the larger of the two */
  201. movl %ecx, %eax
  202. movl %eax, __stklen /* store the actual stack length */
  203. use_stubinfo_stack_size:
  204. pushl %eax
  205. call ___sbrk /* allocate the memory */
  206. cmpl $-1, %eax
  207. je no_memory
  208. movl %eax, ___djgpp_stack_limit /* Bottom of stack */
  209. addl $256,%eax
  210. movl %eax,__stkbottom /* for stack checks */
  211. movl %eax,U_SYSTEM_STACKBOTTOM
  212. movl ___djgpp_stack_limit,%eax /* Bottom of stack */
  213. addl __stklen, %eax
  214. movw %ds, %dx /* set stack */
  215. movw %dx, %ss
  216. movl %eax, %esp
  217. xorl %ebp, %ebp
  218. call ___prt1_startup /* run program */
  219. jmp exit
  220. no_memory:
  221. movb $0xff, %al
  222. jmp exit
  223. /*-----------------------------------------------------------------------------*/
  224. /* #define FREESEL(x) movw x, %bx; movw $0x0001, %ax; int $0x31 */
  225. .macro FREESEL x
  226. movw \x,%bx
  227. movw $0x0001,%ax
  228. int $0x31
  229. .endm
  230. .global ___exit
  231. .align 2
  232. ___exit:
  233. /* special exit from dpmiexcp.c */
  234. .global __exit
  235. __exit:
  236. movb 4(%esp), %al
  237. exit:
  238. movb %al, %cl
  239. xorl %eax,%eax
  240. movw %ax,%fs
  241. movw %ax,%gs
  242. cmpl $0,_exception_exit
  243. jz no_exception
  244. pushl %ecx
  245. call *_exception_exit
  246. popl %ecx
  247. no_exception:
  248. cli /* Just in case they didn't unhook ints */
  249. FREESEL U_SYSTEM_GO32_INFO_BLOCK+26 /* selector for linear memory */
  250. FREESEL ___v2prt0_ds_alias /* DS alias for rmcb exceptions */
  251. FREESEL sbrk16_api_seg /* sbrk cs */
  252. movw sbrk16_first_byte+6,%dx /* selector for allocated DOS mem */
  253. movw $0x101, %ax
  254. int $0x31 /* Free block and selector */
  255. 9:
  256. movl __stubinfo, %edx
  257. movl STUBINFO_CS_SELECTOR(%edx), %eax
  258. movw %ax, sbrk16_api_seg
  259. xorl %edi, %edi
  260. movl %edi, sbrk16_api_ofs /* Offset is zero */
  261. movw STUBINFO_DS_SELECTOR(%edx), %es
  262. movb %cl, %dl /* Exit status */
  263. movl $exit16_first_byte, %esi
  264. movl $(exit16_last_byte - exit16_first_byte), %ecx
  265. cld
  266. rep
  267. movsb
  268. movw %es,%ax /* We will free stack! */
  269. movw %ax,%ss
  270. movl $0x400,%esp /* Transfer buffer >= 1024 bytes */
  271. xorl %ebp, %ebp /* V1.10 bug fix */
  272. movl ___djgpp_memory_handle_list, %edi
  273. movl ___djgpp_memory_handle_list+2, %esi /* Skip word prefixes */
  274. FREESEL %ds
  275. movw %cs, %bx
  276. /* Call exit procedure with BX=32-bit CS; SI+DI=32-bit handle; DL=exit status */
  277. .byte 0x2e
  278. ljmp sbrk16_api_ofs
  279. /*-----------------------------------------------------------------------------*/
  280. /* .lcomm __what_size_app_thinks_it_is, 4 */
  281. __what_size_app_thinks_it_is:
  282. .long end
  283. .lcomm __what_we_return_to_app_as_old_size, 4
  284. .lcomm __what_size_dpmi_thinks_we_are, 4
  285. lock_memory:
  286. /* BX:CX should be linear address; size is pushed on stack */
  287. testb $0x10, __crt0_startup_flags+1 /* include/crt0.h */
  288. jz 13f
  289. pushl %esi
  290. pushl %edi
  291. pushl %eax
  292. movl 16(%esp),%edi
  293. movw 18(%esp),%si
  294. movw $0x600,%ax
  295. int $0x31
  296. popl %eax
  297. popl %edi
  298. popl %esi
  299. 13: ret $4 /* Pop the argument */
  300. .global ___sbrk
  301. .align 2
  302. ___sbrk:
  303. movl __what_size_app_thinks_it_is, %eax
  304. movl 4(%esp), %ecx /* Increment size */
  305. addl %ecx, %eax
  306. jnc brk_common
  307. /* Carry is only set if a negative increment or wrap happens. Negative
  308. increment is semi-OK, wrap (only for multiple zone sbrk) isn't. */
  309. test $0x80000000, %ecx /* Clears carry */
  310. jnz brk_common
  311. stc /* Put carry back */
  312. jmp brk_common
  313. .globl ___brk
  314. .align 2
  315. ___brk:
  316. movl 4(%esp), %eax
  317. clc
  318. brk_common:
  319. pushl %esi
  320. pushl %edi
  321. pushl %ebx
  322. movl __what_size_app_thinks_it_is, %edx /* save info */
  323. movl %edx, __what_we_return_to_app_as_old_size
  324. movl %eax, __what_size_app_thinks_it_is
  325. jc 10f /* Wrap for multi-zone */
  326. cmpl __what_size_dpmi_thinks_we_are, %eax /* don't bother shrinking */
  327. jbe brk_nochange
  328. addl $0x0000ffff, %eax /* round up to 64K block */
  329. andl $0xffff0000, %eax
  330. push %eax /* size - save for later */
  331. movl ___djgpp_memory_handle_list, %edi /* request new size */
  332. movw ___djgpp_memory_handle_list+2, %si
  333. movl %eax, %ecx /* size not limit */
  334. movl %eax, %ebx /* size not limit */
  335. shrl $16, %ebx /* BX:CX size */
  336. movw $0x0900, %ax /* disable interrupts */
  337. int $0x31
  338. pushl %eax
  339. lcall sbrk16_api_ofs
  340. setc %dl /* Save carry */
  341. popl %eax /* restore interrupts */
  342. int $0x31
  343. test %dl,%dl
  344. popl %edx
  345. jne brk_error
  346. movl %edi, ___djgpp_memory_handle_list /* store new handle */
  347. movw %si, ___djgpp_memory_handle_list+2
  348. movl %ecx, ___djgpp_base_address /* store new base address */
  349. movw %bx, ___djgpp_base_address+2
  350. movl %edx, %eax
  351. movl __what_size_dpmi_thinks_we_are, %ecx
  352. subl %ecx, %eax
  353. addl ___djgpp_base_address, %ecx
  354. movl %ecx, %ebx
  355. shrl $16, %ebx /* BX:CX addr */
  356. pushl %eax /* Size */
  357. call lock_memory
  358. decl %edx /* limit now, not size */
  359. 5: movl %edx, ___djgpp_selector_limit
  360. orw $0x0fff, %dx /* low bits set */
  361. movw $0x0008, %ax /* reset CS limit */
  362. movw %cs, %bx
  363. movl %edx, %ecx
  364. shrl $16, %ecx
  365. int $0x31 /* CX:DX is limit */
  366. testb $0x80, __crt0_startup_flags /* include/crt0.h */
  367. jnz 3f
  368. movw $0x0008, %ax /* reset DS limit */
  369. movw %ds, %bx
  370. int $0x31
  371. movw $0x0008, %ax /* reset DS alias limit */
  372. movl ___v2prt0_ds_alias, %ebx
  373. int $0x31
  374. 3:
  375. movw $0x0007, %ax /* reset DS alias base */
  376. movl ___v2prt0_ds_alias, %ebx
  377. movl ___djgpp_base_address, %edx
  378. movw ___djgpp_base_address+2, %cx
  379. int $0x31
  380. movl ___djgpp_selector_limit, %edx
  381. 12: incl %edx /* Size not limit */
  382. testb $0x60, __crt0_startup_flags /* include/crt0.h */
  383. jz no_fill_sbrk_memory
  384. pushl %ds
  385. popl %es
  386. movl __what_size_dpmi_thinks_we_are, %edi /* set all newly resized bytes zero */
  387. movl %edx, %ecx /* Limit */
  388. subl %edi, %ecx /* Adjust count for base */
  389. xorl %eax, %eax
  390. testb $0x40, __crt0_startup_flags
  391. jz no_deadbeef
  392. movl $0xdeadbeef, %eax /* something really easy to spot */
  393. no_deadbeef:
  394. shrl $2, %ecx /* div 4 Longwords not bytes */
  395. cld
  396. rep
  397. stosl
  398. no_fill_sbrk_memory:
  399. movl %edx, __what_size_dpmi_thinks_we_are
  400. brk_nochange: /* successful return */
  401. movl __what_we_return_to_app_as_old_size, %eax
  402. jmp brk_return
  403. brk_error: /* error return */
  404. movl __what_we_return_to_app_as_old_size, %eax
  405. movl %eax, __what_size_app_thinks_it_is
  406. movl $-1, %eax
  407. brk_return:
  408. popl %ebx
  409. popl %edi
  410. popl %esi
  411. ret
  412. /* From here on this are parts of crt1.c converted to assembler
  413. and without any call to libc, so that it works without anything else
  414. additions made by Pierre Muller*/
  415. /* from dpmidefs.h * /
  416. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  417. /* from include <libc/asmdefs.h> */
  418. /* all macros removed here */
  419. /* #define FUNC(x) .globl x; x: */
  420. /* #define ENTER pushl %ebp; movl %esp,%ebp */
  421. /* #define LEAVE(x) movl %ebp,%esp; popl %ebp; ret $(x) */
  422. /* #define ARG1 8(%ebp)
  423. #define ARG1h 10(%ebp)
  424. #define ARG2 12(%ebp)
  425. #define ARG2h 14(%ebp)
  426. #define ARG3 16(%ebp)
  427. #define ARG4 20(%ebp)
  428. #define ARG5 24(%ebp)
  429. #define ARG6 28(%ebp)
  430. #define ARG7 32(%ebp)
  431. #define ARG8 36(%ebp) */
  432. .comm ___dpmi_error,2
  433. /* from dpmi0000.s */
  434. /* .globl ___dpmi_allocate_ldt_descriptors */
  435. /* using pascal convention => not usabel by C code */
  436. ___dpmi_allocate_ldt_descriptors:
  437. pushl %ebp; movl %esp,%ebp
  438. movl 8(%ebp), %ecx
  439. movl $0x0000, %eax
  440. int $0x31
  441. jnc .L_noerror0000
  442. movw %ax,___dpmi_error
  443. movl $-1,%eax
  444. jmp .L_leave0000
  445. .L_noerror0000:
  446. movzwl %ax,%eax
  447. .L_leave0000:
  448. movl %ebp,%esp
  449. popl %ebp
  450. ret $4
  451. /* from file dpmi0008.s */
  452. /* .globl ___dpmi_set_segment_limit */
  453. ___dpmi_set_segment_limit:
  454. pushl %ebp; movl %esp,%ebp
  455. movl 8(%ebp), %ebx
  456. movzwl 12(%ebp), %edx
  457. movzwl 14(%ebp),%ecx
  458. movl $0x0008,%eax
  459. int $0x31
  460. jnc .L_noerror0008
  461. movw %ax,___dpmi_error
  462. movl $-1,%eax
  463. jmp .L_leave0008
  464. .L_noerror0008:
  465. xorl %eax,%eax
  466. .L_leave0008:
  467. movl %ebp,%esp
  468. popl %ebp
  469. ret $8
  470. /* .globl ___dpmi_get_version */
  471. ___dpmi_get_version:
  472. pushl %ebp; movl %esp,%ebp
  473. movl $0x0400,%eax
  474. int $0x31
  475. jnc .L_noerror0400
  476. movw %ax,___dpmi_error
  477. movl $-1,%eax
  478. jmp .L_leave0400
  479. .L_noerror0400:
  480. movl 8(%ebp), %esi
  481. movb %ah, (%esi)
  482. movb %al, 1(%esi)
  483. movw %bx, 2(%esi)
  484. movb %cl, 4(%esi)
  485. movb %dh, 5(%esi)
  486. movb %dl, 6(%esi)
  487. xorl %eax,%eax
  488. .L_leave0400:
  489. movl %ebp,%esp
  490. popl %ebp
  491. ret $4
  492. /* .globl ___dpmi_get_segment_base_address*/
  493. ___dpmi_get_segment_base_address:
  494. pushl %ebp; movl %esp,%ebp
  495. movl 8(%ebp), %ebx
  496. movl $0x0006,%eax
  497. int $0x31
  498. jnc .L_noerror0006
  499. movw %ax,___dpmi_error
  500. movl $-1,%eax
  501. jmp .L_leave0006
  502. .L_noerror0006:
  503. movl 12(%ebp), %ebx
  504. movl %edx, (%ebx)
  505. movw %cx, 2(%ebx)
  506. xorl %eax,%eax
  507. .L_leave0006:
  508. movl %ebp,%esp
  509. popl %ebp
  510. ret $8
  511. .globl ___bss_count
  512. .data
  513. .align 2
  514. ___bss_count:
  515. .long 1
  516. .text
  517. .align 2
  518. .globl _setup_core_selector
  519. _setup_core_selector:
  520. pushl %ebp
  521. movl %esp,%ebp
  522. pushl $1
  523. call ___dpmi_allocate_ldt_descriptors
  524. /* addl $4,%esp */
  525. cmpl $-1,%eax
  526. jne .L24
  527. movw $0,U_SYSTEM_GO32_INFO_BLOCK+26
  528. leave
  529. ret
  530. .align 2,0x90
  531. .L24:
  532. movw %ax,U_SYSTEM_GO32_INFO_BLOCK+26
  533. movw %ax,_core_selector
  534. pushl $0x10ffff
  535. andl $0xffff,%eax
  536. pushl %eax
  537. call ___dpmi_set_segment_limit
  538. leave
  539. ret
  540. .align 2
  541. .globl _setup_screens
  542. _setup_screens:
  543. pushl %ebp
  544. movl %esp,%ebp
  545. movw U_SYSTEM_GO32_INFO_BLOCK+26,%dx
  546. movl $1048563,%ecx
  547. /APP
  548. movw %dx, %gs
  549. .byte 0x65
  550. movw (%ecx),%ax
  551. /NO_APP
  552. cmpw $64896,%ax
  553. jne .L26
  554. movl $655360,U_SYSTEM_GO32_INFO_BLOCK+8
  555. movl $655360,U_SYSTEM_GO32_INFO_BLOCK+4
  556. leave
  557. ret
  558. .align 2,0x90
  559. .L26:
  560. movl $1097,%ecx
  561. /APP
  562. movw %dx,%gs
  563. .byte 0x65
  564. movb (%ecx),%al
  565. /NO_APP
  566. cmpb $7,%al
  567. jne .L29
  568. movl $720896,U_SYSTEM_GO32_INFO_BLOCK+4
  569. movl $753664,U_SYSTEM_GO32_INFO_BLOCK+8
  570. leave
  571. ret
  572. .align 2,0x90
  573. .L29:
  574. movl $753664,U_SYSTEM_GO32_INFO_BLOCK+4
  575. movl $720896,U_SYSTEM_GO32_INFO_BLOCK+8
  576. leave
  577. ret
  578. .align 2
  579. .globl _setup_go32_info_block
  580. _setup_go32_info_block:
  581. pushl %ebp
  582. movl %esp,%ebp
  583. subl $8,%esp
  584. leal -8(%ebp),%eax
  585. pushl %eax
  586. call ___dpmi_get_version
  587. movl $40,U_SYSTEM_GO32_INFO_BLOCK
  588. movl __stubinfo,%edx
  589. movzwl 36(%edx),%eax
  590. sall $4,%eax
  591. movl %eax,U_SYSTEM_GO32_INFO_BLOCK+12
  592. movzwl 32(%edx),%ecx
  593. movl %ecx,U_SYSTEM_GO32_INFO_BLOCK+16
  594. movzwl 38(%edx),%ecx
  595. movl %ecx,U_SYSTEM_GO32_INFO_BLOCK+20
  596. movb -3(%ebp),%al
  597. movb %al,U_SYSTEM_GO32_INFO_BLOCK+24
  598. movb -2(%ebp),%al
  599. movb %al,U_SYSTEM_GO32_INFO_BLOCK+25
  600. movl $-1,U_SYSTEM_GO32_INFO_BLOCK+28
  601. pushl $U_SYSTEM_GO32_INFO_BLOCK+32
  602. movzwl 38(%edx),%eax
  603. pushl %eax
  604. call ___dpmi_get_segment_base_address
  605. movw $4,U_SYSTEM_GO32_INFO_BLOCK+36
  606. movb -8(%ebp),%dl
  607. salw $8,%dx
  608. movzbw -7(%ebp),%ax
  609. orw %ax,%dx
  610. movw %dx,U_SYSTEM_GO32_INFO_BLOCK+38
  611. call copy_to_c_go32_info_block
  612. leave
  613. ret
  614. copy_to_c_go32_info_block:
  615. leal U_SYSTEM_GO32_INFO_BLOCK,%esi
  616. leal __go32_info_block,%edi
  617. movl $10,%ecx
  618. rep
  619. movsl
  620. ret
  621. .data
  622. /* fpu codeword */
  623. ___fpucw:
  624. .long 0x1332
  625. /* __go32_info_block for C programs */
  626. .align 2
  627. .globl __go32_info_block
  628. .comm __go32_info_block,40
  629. /*
  630. -- prt1_startup --
  631. */
  632. .text
  633. .align 2
  634. .globl ___prt1_startup
  635. ___prt1_startup:
  636. pushl %ebp
  637. movl %esp,%ebp
  638. pushl %ebx
  639. incl ___bss_count
  640. movl $0,___crt0_argv
  641. call _setup_core_selector
  642. call _setup_screens
  643. call _setup_go32_info_block
  644. incl ___environ_changed
  645. finit /* initialize fpu */
  646. fwait
  647. fldcw ___fpucw
  648. pushl U_SYSTEM_ENVP
  649. pushl ___crt0_argv
  650. pushl ___crt0_argc
  651. call _pascal_start
  652. pushl %eax
  653. /* call _exit changed to */
  654. call exit
  655. .align 2,0x90
  656. /* .comm U_SYSTEM_DOS_ARGV0,4 */
  657. .comm ___dos_argv0,4
  658. .comm ___crt0_argc,4
  659. .comm ___crt0_argv,4
  660. .globl ___environ_changed
  661. ___environ_changed:
  662. .long 0
  663. .globl _exception_exit
  664. _exception_exit:
  665. .long 0
  666. .globl _swap_in
  667. _swap_in:
  668. .long 0
  669. .globl _swap_out
  670. _swap_out:
  671. .long 0
  672. .global _v2prt0_exceptions_on
  673. _v2prt0_exceptions_on:
  674. .long 0
  675. /* this was the prt0.s from the go32v1 version */
  676. //
  677. // call as start(argc, argv, envp) (C-calling convention)
  678. //
  679. .globl _pascal_start
  680. _pascal_start:
  681. /* %ebx doesn't contain ScreenPrimary */
  682. movl U_SYSTEM_GO32_INFO_BLOCK+4,%ebx
  683. movl %ebx,_ScreenPrimary
  684. /* core selector in %fs */
  685. movw _core_selector,%ax
  686. movw %ax,%fs
  687. // Top of frame
  688. movl $0x0,%ebp
  689. movl %esp,%ebx
  690. movl 12(%ebx),%eax
  691. movl %eax,U_SYSTEM_ENVP
  692. movl %eax,_environ
  693. movl 8(%ebx),%eax
  694. movl %eax,_args
  695. movl 4(%ebx),%eax
  696. movl %eax,_argc
  697. call PASCALMAIN
  698. movl $0,%eax
  699. /* no error if passing here */
  700. /* movl $0x4c00,%eax
  701. int $0x21 */
  702. ret
  703. .data
  704. /* .comm U_SYSTEM_ENVP,4 */
  705. .globl _ScreenPrimary
  706. _ScreenPrimary:
  707. .long 0
  708. .globl _argc
  709. _argc:
  710. .long 0
  711. .globl _args
  712. _args:
  713. .long 0
  714. .globl _run_mode
  715. _run_mode:
  716. .word 4
  717. .globl _core_selector
  718. _core_selector:
  719. .word 0
  720. .globl _environ
  721. _environ:
  722. .long 0
  723. /* Here Pierre Muller added all what was in crt1.c */
  724. /* in assembler */
  725. /* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
  726. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  727. /* adapted to assembler for FPC by Pierre Muller */
  728. /* Global variables */
  729. /* This gets incremented each time the program is started.
  730. Programs (such as Emacs) which dump their code to create
  731. a new executable, cause this to be larger than 2. Library
  732. functions that cache info in static variables should check
  733. the value of `__bss_count' if they need to reinitialize
  734. the static storage. */
  735. .data
  736. .globl ___bss_count
  737. ___bs_count:
  738. .long 1
  739. .globl __crt0_startup_flags
  740. __crt0_startup_flags:
  741. .long 0
  742. .globl __dos_ds
  743. __dos_ds:
  744. .long 0
  745. /*
  746. $Log$
  747. Revision 1.4 1998-10-14 21:28:45 peter
  748. * initialize fpu so sigfpe is finally generated for fpu errors
  749. Revision 1.3 1998/08/19 10:56:35 pierre
  750. + added some special code for C interface
  751. to avoid loading of crt1.o or dpmiexcp.o from the libc.a
  752. Revision 1.2 1998/05/22 00:39:38 peter
  753. * go32v1, go32v2 recompiles with the new objects
  754. * remake3 works again with go32v2
  755. - removed some "optimizes" from daniel which were wrong
  756. */