Merge pull request #270 from tkchia/tkchia/20220823
Some fixes for msdos386 target platform
This commit is contained in:
commit
8891fae303
|
@ -35,7 +35,7 @@ static const signed char err_map[] =
|
||||||
* Map an MS-DOS 2+ system error code to an `errno' value and store that in
|
* Map an MS-DOS 2+ system error code to an `errno' value and store that in
|
||||||
* `errno'. Return a longword -1.
|
* `errno'. Return a longword -1.
|
||||||
*/
|
*/
|
||||||
long _sys_seterrno(unsigned dos_err)
|
long _sys_seterrno(unsigned short dos_err)
|
||||||
{
|
{
|
||||||
if (dos_err < sizeof(err_map) / sizeof(err_map[0]))
|
if (dos_err < sizeof(err_map) / sizeof(err_map[0]))
|
||||||
errno = err_map[dos_err];
|
errno = err_map[dos_err];
|
||||||
|
|
|
@ -21,33 +21,34 @@ begtext:
|
||||||
! ax: pmode code segment of stub
|
! ax: pmode code segment of stub
|
||||||
! bx: pmode data segment of stub
|
! bx: pmode data segment of stub
|
||||||
! cx: rmode segment of stub
|
! cx: rmode segment of stub
|
||||||
! dx: pointer to realloc routine (in stub)e
|
! dx: pointer to realloc routine (in stub)
|
||||||
! si: pointer to interrupt routine (in stub)
|
! si: pointer to interrupt routine (in stub)
|
||||||
! di: pointer to transfer buffer (in stub)
|
! di: pointer to transfer buffer (in stub)
|
||||||
|
! bp: rmode PSP segment
|
||||||
|
|
||||||
! Resize the segment to include the BSS.
|
! Resize the segment to include the BSS.
|
||||||
|
|
||||||
o16 cseg mov (realloc_ptr+4), ax
|
o16 mov (realloc_ptr+4), ax
|
||||||
cseg mov (realloc_ptr+0), edx
|
mov (realloc_ptr+0), edx
|
||||||
cseg o16 mov (pmode_cs), ax
|
o16 mov (pmode_cs), ax
|
||||||
cseg o16 mov (pmode_ds), bx
|
o16 mov (pmode_ds), bx
|
||||||
cseg o16 mov (rmode), cx
|
o16 mov (rmode), cx
|
||||||
cseg o16 mov (interrupt_ptr+4), ax
|
o16 mov (interrupt_ptr+4), ax
|
||||||
cseg mov (interrupt_ptr+0), esi
|
mov (interrupt_ptr+0), esi
|
||||||
cseg o16 mov (transfer_buffer_ptr), di
|
o16 mov (transfer_buffer_ptr), di
|
||||||
|
|
||||||
mov eax, __end
|
mov eax, __end
|
||||||
cseg callf (realloc_ptr)
|
callf (realloc_ptr)
|
||||||
|
|
||||||
! Clear BSS.
|
! Clear BSS.
|
||||||
|
|
||||||
mov edi, begbss
|
mov edi, begbss
|
||||||
mov ecx, endbss+1
|
mov ecx, endbss+3
|
||||||
sub ecx, edi
|
sub ecx, edi
|
||||||
shr ecx, 1
|
shr ecx, 2
|
||||||
xor eax, eax
|
xor eax, eax
|
||||||
cld
|
cld
|
||||||
rep stosw
|
rep stos
|
||||||
|
|
||||||
! It's now safe to switch stacks.
|
! It's now safe to switch stacks.
|
||||||
|
|
||||||
|
@ -62,16 +63,16 @@ begtext:
|
||||||
o16 mov ax, 0x0000
|
o16 mov ax, 0x0000
|
||||||
o16 mov cx, 1
|
o16 mov cx, 1
|
||||||
int 0x31 ! allocate LDT
|
int 0x31 ! allocate LDT
|
||||||
|
o16 mov (.doshandle), ax
|
||||||
mov es, ax
|
mov es, ax
|
||||||
o16 mov bx, ax
|
xchg ebx, eax
|
||||||
o16 mov (.doshandle), bx
|
|
||||||
mov es, bx
|
|
||||||
|
|
||||||
xor ecx, ecx
|
xor ecx, ecx
|
||||||
xor edx, edx
|
xor edx, edx
|
||||||
o16 mov ax, 0x0007
|
o16 mov ax, 0x0007
|
||||||
int 0x31 ! set base address to 0
|
int 0x31 ! set base address to 0
|
||||||
o16 mov cx, 0x0010
|
o16 dec dx
|
||||||
|
o16 mov cx, 0x000f
|
||||||
o16 mov ax, 0x0008
|
o16 mov ax, 0x0008
|
||||||
int 0x31 ! set limit to 1MB
|
int 0x31 ! set limit to 1MB
|
||||||
|
|
||||||
|
@ -84,9 +85,7 @@ begtext:
|
||||||
|
|
||||||
! Locate the PSP.
|
! Locate the PSP.
|
||||||
|
|
||||||
movb ah, 0x62
|
movzx esi, bp
|
||||||
int 0x21
|
|
||||||
movzx esi, bx
|
|
||||||
shl esi, 4 ! convert to linear address
|
shl esi, 4 ! convert to linear address
|
||||||
|
|
||||||
! Copy the whole thing into 32-bit memory.
|
! Copy the whole thing into 32-bit memory.
|
||||||
|
|
|
@ -38,8 +38,9 @@ _getpid:
|
||||||
int 0x21
|
int 0x21
|
||||||
jnc .eur_dos
|
jnc .eur_dos
|
||||||
movb ah, 0x51
|
movb ah, 0x51
|
||||||
int 0x21
|
mov ebx, 0x210000
|
||||||
|
callf (interrupt_ptr)
|
||||||
xchg ebx, eax
|
xchg ebx, eax
|
||||||
.eur_dos:
|
.eur_dos:
|
||||||
xor edx, edx
|
movzx eax, ax
|
||||||
ret
|
ret
|
||||||
|
|
|
@ -47,8 +47,10 @@ _rename:
|
||||||
o16 mov dx, (transfer_buffer_ptr)
|
o16 mov dx, (transfer_buffer_ptr)
|
||||||
o16 mov di, ax
|
o16 mov di, ax
|
||||||
movb ah, 0x56
|
movb ah, 0x56
|
||||||
or ebx, 0x210000
|
mov ebx, 0x210000
|
||||||
callf (interrupt_ptr)
|
callf (interrupt_ptr)
|
||||||
pop edi
|
pop edi
|
||||||
pop esi
|
pop esi
|
||||||
|
push ss
|
||||||
|
pop es
|
||||||
jmp .sys_zret
|
jmp .sys_zret
|
||||||
|
|
|
@ -16,10 +16,22 @@
|
||||||
|
|
||||||
.define __sys_exists
|
.define __sys_exists
|
||||||
__sys_exists:
|
__sys_exists:
|
||||||
mov ebx, esp
|
push esi
|
||||||
mov edx, 4(ebx)
|
mov esi, 4+4(esp)
|
||||||
|
movzx edi, (transfer_buffer_ptr)
|
||||||
|
mov edx, edi
|
||||||
|
mov es, (pmode_ds)
|
||||||
|
cld
|
||||||
|
1:
|
||||||
|
lodsb
|
||||||
|
stosb
|
||||||
|
testb al, al
|
||||||
|
jnz 1b
|
||||||
mov eax, 0x4300
|
mov eax, 0x4300
|
||||||
int 0x21
|
mov ebx, 0x210000
|
||||||
|
callf (interrupt_ptr)
|
||||||
|
push ss
|
||||||
|
pop es
|
||||||
sbb eax, eax
|
sbb eax, eax
|
||||||
inc eax
|
inc eax
|
||||||
ret
|
ret
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
.define __sys_gettime
|
.define __sys_gettime
|
||||||
__sys_gettime:
|
__sys_gettime:
|
||||||
int 3
|
|
||||||
movb ah, 0x2c
|
movb ah, 0x2c
|
||||||
int 0x21
|
int 0x21
|
||||||
mov ebx, esp
|
mov ebx, esp
|
||||||
|
|
|
@ -17,8 +17,7 @@
|
||||||
|
|
||||||
.define __sys_isopen
|
.define __sys_isopen
|
||||||
__sys_isopen:
|
__sys_isopen:
|
||||||
mov ebx, esp
|
mov ebx, 4(esp)
|
||||||
mov ebx, 4(bx)
|
|
||||||
mov eax, 0x4400
|
mov eax, 0x4400
|
||||||
int 0x21
|
int 0x21
|
||||||
sbb eax, eax
|
sbb eax, eax
|
||||||
|
|
|
@ -36,10 +36,12 @@ __sys_rawcreat:
|
||||||
movb ah, 0x3c
|
movb ah, 0x3c
|
||||||
movzx edx, (transfer_buffer_ptr)
|
movzx edx, (transfer_buffer_ptr)
|
||||||
movb al, 8(ebx)
|
movb al, 8(ebx)
|
||||||
or ebx, 0x210000
|
mov ebx, 0x210000
|
||||||
callf (interrupt_ptr)
|
callf (interrupt_ptr)
|
||||||
|
|
||||||
pop edi
|
pop edi
|
||||||
pop esi
|
pop esi
|
||||||
|
push ss
|
||||||
|
pop es
|
||||||
jmp .sys_axret
|
jmp .sys_axret
|
||||||
|
|
||||||
|
|
|
@ -18,9 +18,10 @@
|
||||||
__sys_rawlseek:
|
__sys_rawlseek:
|
||||||
movb ah, 0x42
|
movb ah, 0x42
|
||||||
mov ebx, esp
|
mov ebx, esp
|
||||||
mov edx, 8(bx)
|
mov edx, 8(ebx)
|
||||||
mov ecx, 12(bx)
|
mov ecx, edx
|
||||||
movb al, 16(bx)
|
shr ecx, 16
|
||||||
mov ebx, 4(bx)
|
movb al, 12(ebx)
|
||||||
|
mov ebx, 4(ebx)
|
||||||
int 0x21
|
int 0x21
|
||||||
jmp .sys_dxaxret
|
jmp .sys_dxaxret
|
||||||
|
|
|
@ -37,9 +37,11 @@ __sys_rawopen:
|
||||||
movb ah, 0x3d
|
movb ah, 0x3d
|
||||||
o16 mov dx, (transfer_buffer_ptr)
|
o16 mov dx, (transfer_buffer_ptr)
|
||||||
movb al, 8(ebx)
|
movb al, 8(ebx)
|
||||||
or ebx, 0x210000
|
mov ebx, 0x210000
|
||||||
callf (interrupt_ptr)
|
callf (interrupt_ptr)
|
||||||
|
|
||||||
pop edi
|
pop edi
|
||||||
pop esi
|
pop esi
|
||||||
|
push ss
|
||||||
|
pop es
|
||||||
jmp .sys_axret
|
jmp .sys_axret
|
||||||
|
|
|
@ -38,8 +38,9 @@ amount_to_read = 4*4
|
||||||
|
|
||||||
movb ah, 0x3f
|
movb ah, 0x3f
|
||||||
o16 mov dx, (transfer_buffer_ptr)
|
o16 mov dx, (transfer_buffer_ptr)
|
||||||
|
movzx esi, dx
|
||||||
|
mov ebx, 0x210000
|
||||||
o16 mov bx, file_handle(ebp)
|
o16 mov bx, file_handle(ebp)
|
||||||
or ebx, 0x210000
|
|
||||||
callf (interrupt_ptr)
|
callf (interrupt_ptr)
|
||||||
jnc success
|
jnc success
|
||||||
|
|
||||||
|
@ -53,9 +54,10 @@ success:
|
||||||
|
|
||||||
! Copy eax bytes out of the transfer buffer.
|
! Copy eax bytes out of the transfer buffer.
|
||||||
|
|
||||||
push eax
|
movzx eax, ax
|
||||||
mov ecx, eax
|
mov ecx, eax
|
||||||
movzx esi, (transfer_buffer_ptr)
|
jcxz exit
|
||||||
|
push eax
|
||||||
mov edi, write_buffer(ebp)
|
mov edi, write_buffer(ebp)
|
||||||
mov es, (pmode_ds)
|
mov es, (pmode_ds)
|
||||||
cld
|
cld
|
||||||
|
@ -69,6 +71,8 @@ success:
|
||||||
exit:
|
exit:
|
||||||
pop edi
|
pop edi
|
||||||
pop esi
|
pop esi
|
||||||
|
push ss
|
||||||
|
pop es
|
||||||
leave
|
leave
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
|
@ -48,8 +48,8 @@ amount_to_write = 4*4
|
||||||
|
|
||||||
movb ah, 0x40
|
movb ah, 0x40
|
||||||
o16 mov dx, (transfer_buffer_ptr)
|
o16 mov dx, (transfer_buffer_ptr)
|
||||||
|
mov ebx, 0x210000
|
||||||
o16 mov bx, file_handle(ebp)
|
o16 mov bx, file_handle(ebp)
|
||||||
or ebx, 0x210000
|
|
||||||
callf (interrupt_ptr)
|
callf (interrupt_ptr)
|
||||||
jnc exit
|
jnc exit
|
||||||
|
|
||||||
|
@ -59,6 +59,8 @@ amount_to_write = 4*4
|
||||||
exit:
|
exit:
|
||||||
pop edi
|
pop edi
|
||||||
pop esi
|
pop esi
|
||||||
|
push ss
|
||||||
|
pop es
|
||||||
leave
|
leave
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,8 @@
|
||||||
! code in ax, and return a shortword -1. If the carry flag is clear, just
|
! code in ax, and return a shortword -1. If the carry flag is clear, just
|
||||||
! return ax as a return value.
|
! return ax as a return value.
|
||||||
!
|
!
|
||||||
! .sys_dxaxret: same as .sys_axret, but return -1 or dx:ax as a return value.
|
! .sys_dxaxret: same as .sys_axret, but return -1 or eax := dx:ax as a
|
||||||
|
! return value.
|
||||||
|
|
||||||
.extern .sys_zret
|
.extern .sys_zret
|
||||||
.extern .sys_axret
|
.extern .sys_axret
|
||||||
|
|
|
@ -34,11 +34,13 @@ _unlink:
|
||||||
|
|
||||||
! Make the DOS call.
|
! Make the DOS call.
|
||||||
|
|
||||||
movzx edi, (transfer_buffer_ptr)
|
mov dx, (transfer_buffer_ptr)
|
||||||
movb ah, 0x41
|
movb ah, 0x41
|
||||||
or ebx, 0x210000
|
or ebx, 0x210000
|
||||||
callf (interrupt_ptr)
|
callf (interrupt_ptr)
|
||||||
|
|
||||||
pop edi
|
pop edi
|
||||||
pop esi
|
pop esi
|
||||||
|
push ss
|
||||||
|
pop es
|
||||||
jmp .sys_zret
|
jmp .sys_zret
|
||||||
|
|
|
@ -127,7 +127,7 @@ exe_start:
|
||||||
mov cx, 1
|
mov cx, 1
|
||||||
int 0x31 ! allocate LDT
|
int 0x31 ! allocate LDT
|
||||||
jc bad_dpmi
|
jc bad_dpmi
|
||||||
mov es, ax
|
mov fs, ax
|
||||||
mov (psegcs32), ax
|
mov (psegcs32), ax
|
||||||
|
|
||||||
mov cx, (pmemlen+0)
|
mov cx, (pmemlen+0)
|
||||||
|
@ -140,14 +140,16 @@ exe_start:
|
||||||
|
|
||||||
mov dx, cx
|
mov dx, cx
|
||||||
mov cx, bx
|
mov cx, bx
|
||||||
mov bx, es
|
mov bx, fs
|
||||||
mov ax, 0x0007
|
mov ax, 0x0007
|
||||||
int 0x31 ! set segment base address
|
int 0x31 ! set segment base address
|
||||||
jc bad_dpmi
|
jc bad_dpmi
|
||||||
|
|
||||||
mov bx, es
|
mov bx, fs
|
||||||
mov dx, (pmemlen+0)
|
mov dx, (pmemlen+0)
|
||||||
mov cx, (pmemlen+2)
|
mov cx, (pmemlen+2)
|
||||||
|
sub dx, 1
|
||||||
|
sbb cx, 0
|
||||||
mov ax, 0x0008
|
mov ax, 0x0008
|
||||||
int 0x31 ! set segment limit
|
int 0x31 ! set segment limit
|
||||||
|
|
||||||
|
@ -155,23 +157,23 @@ exe_start:
|
||||||
and cx, 3
|
and cx, 3
|
||||||
shl cx, 5
|
shl cx, 5
|
||||||
or cx, 0xc09b ! 32-bit, big, code, non-conforming, readable
|
or cx, 0xc09b ! 32-bit, big, code, non-conforming, readable
|
||||||
mov bx, es
|
mov bx, fs
|
||||||
mov ax, 0x0009
|
mov ax, 0x0009
|
||||||
int 0x31 ! set descriptor access rights
|
int 0x31 ! set descriptor access rights
|
||||||
|
|
||||||
! Allocate the data segment (as a simple clone of the code segment). (10e)
|
! Allocate the data segment (as a simple clone of the code segment). (10e)
|
||||||
|
|
||||||
mov ax, 0x000a
|
mov ax, 0x000a
|
||||||
mov bx, es
|
mov bx, fs
|
||||||
int 0x31
|
int 0x31
|
||||||
mov fs, ax
|
mov es, ax
|
||||||
mov (psegds32), ax
|
mov (psegds32), ax
|
||||||
|
|
||||||
mov cx, ax
|
mov cx, ax
|
||||||
and cx, 3
|
and cx, 3
|
||||||
shl cx, 5
|
shl cx, 5
|
||||||
or cx, 0xc093 ! 32-bit, big, data, r/w, expand-up
|
or cx, 0xc093 ! 32-bit, big, data, r/w, expand-up
|
||||||
mov bx, fs
|
mov bx, es
|
||||||
mov ax, 0x0009
|
mov ax, 0x0009
|
||||||
int 0x31 ! set descriptor access rights
|
int 0x31 ! set descriptor access rights
|
||||||
|
|
||||||
|
@ -198,7 +200,7 @@ exe_start:
|
||||||
o32 movzx ecx, ax ! number of bytes read
|
o32 movzx ecx, ax ! number of bytes read
|
||||||
o32 mov esi, transfer_buffer
|
o32 mov esi, transfer_buffer
|
||||||
cld
|
cld
|
||||||
o32 rep movsb
|
rep a32 movsb
|
||||||
jmp 1b
|
jmp 1b
|
||||||
2:
|
2:
|
||||||
|
|
||||||
|
@ -216,9 +218,10 @@ exe_start:
|
||||||
o32 mov edx, realloc
|
o32 mov edx, realloc
|
||||||
o32 mov esi, interruptf
|
o32 mov esi, interruptf
|
||||||
o32 mov edi, transfer_buffer
|
o32 mov edi, transfer_buffer
|
||||||
|
o32 movzx ebp, (pspseg)
|
||||||
push es
|
push es
|
||||||
pop ds
|
pop ds
|
||||||
push es
|
push fs
|
||||||
push 0
|
push 0
|
||||||
retf ! 19b
|
retf ! 19b
|
||||||
|
|
||||||
|
@ -226,7 +229,8 @@ exe_start:
|
||||||
! is running from. This can't happen from inside the 32-bit code itself
|
! is running from. This can't happen from inside the 32-bit code itself
|
||||||
! because it might move.
|
! because it might move.
|
||||||
!
|
!
|
||||||
! On entry, ds and ss are ignored. On exit, ds is set to the 32-bit segment.
|
! On entry, ds and ss are ignored. On exit, ds and es are set to the
|
||||||
|
! 32-bit segment.
|
||||||
! eax: new block size
|
! eax: new block size
|
||||||
realloc:
|
realloc:
|
||||||
cseg mov ds, (psegds)
|
cseg mov ds, (psegds)
|
||||||
|
@ -253,19 +257,21 @@ realloc:
|
||||||
mov (pmemaddr+0), cx
|
mov (pmemaddr+0), cx
|
||||||
mov (pmemaddr+2), bx
|
mov (pmemaddr+2), bx
|
||||||
|
|
||||||
mov bx, (psegds32)
|
mov bx, (psegcs32)
|
||||||
mov dx, (pmemlen+0)
|
|
||||||
mov cx, (pmemlen+2)
|
|
||||||
mov ax, 0x0008
|
|
||||||
int 0x31 ! set ds segment limit
|
|
||||||
jc bad_dpmi
|
|
||||||
mov dx, (pmemaddr+0)
|
mov dx, (pmemaddr+0)
|
||||||
mov cx, (pmemaddr+2)
|
mov cx, (pmemaddr+2)
|
||||||
mov ax, 0x0007
|
mov ax, 0x0007
|
||||||
|
int 0x31 ! set cs linear address
|
||||||
|
jc bad_dpmi
|
||||||
|
mov bx, (psegds32)
|
||||||
int 0x31 ! set ds linear address
|
int 0x31 ! set ds linear address
|
||||||
jc bad_dpmi
|
jc bad_dpmi
|
||||||
mov bx, (psegcs32)
|
mov dx, (pmemlen+0)
|
||||||
int 0x31 ! set cs linear address
|
mov cx, (pmemlen+2)
|
||||||
|
sub dx, 1
|
||||||
|
sbb cx, 0
|
||||||
|
mov ax, 0x0008
|
||||||
|
int 0x31 ! set ds segment limit
|
||||||
jc bad_dpmi
|
jc bad_dpmi
|
||||||
|
|
||||||
popa
|
popa
|
||||||
|
@ -273,6 +279,7 @@ realloc:
|
||||||
cli ! atomically switch stacks back
|
cli ! atomically switch stacks back
|
||||||
mov ss, (dpmi_ss)
|
mov ss, (dpmi_ss)
|
||||||
o32 mov esp, (dpmi_ebp)
|
o32 mov esp, (dpmi_ebp)
|
||||||
|
mov es, (psegds32)
|
||||||
mov ds, (psegds32)
|
mov ds, (psegds32)
|
||||||
sti
|
sti
|
||||||
|
|
||||||
|
@ -308,6 +315,7 @@ exit_with_error:
|
||||||
|
|
||||||
! Simulate DOS interrupt.
|
! Simulate DOS interrupt.
|
||||||
int21:
|
int21:
|
||||||
|
o32 movzx ebx, bx
|
||||||
o32 or ebx, 0x210000
|
o32 or ebx, 0x210000
|
||||||
! Simulate interrupt in the high half of ebx.
|
! Simulate interrupt in the high half of ebx.
|
||||||
interrupt:
|
interrupt:
|
||||||
|
@ -317,6 +325,8 @@ interrupt:
|
||||||
mov (dpmi_edx), dx
|
mov (dpmi_edx), dx
|
||||||
mov (dpmi_esi), si
|
mov (dpmi_esi), si
|
||||||
mov (dpmi_edi), di
|
mov (dpmi_edi), di
|
||||||
|
pushf
|
||||||
|
pop (dpmi_flags)
|
||||||
mov ax, (rseg)
|
mov ax, (rseg)
|
||||||
mov (dpmi_ds), ax
|
mov (dpmi_ds), ax
|
||||||
mov (dpmi_ss), ax
|
mov (dpmi_ss), ax
|
||||||
|
@ -327,6 +337,7 @@ interrupt:
|
||||||
o32 mov edi, dpmi_edi
|
o32 mov edi, dpmi_edi
|
||||||
mov ax, 0x300
|
mov ax, 0x300
|
||||||
o32 shr ebx, 16
|
o32 shr ebx, 16
|
||||||
|
xor cx, cx
|
||||||
int 0x31 ! simulate DOS interrupt
|
int 0x31 ! simulate DOS interrupt
|
||||||
pop es
|
pop es
|
||||||
o32 movzx eax, (dpmi_eax)
|
o32 movzx eax, (dpmi_eax)
|
||||||
|
|
Loading…
Reference in a new issue