plat/msdos386: fix some issues in libsys code

- ensure es = ds = ss upon exit of each C runtime function
 - clear upper 16 bits of ebx before setting them to 0x0021,
   when invoking interrupt_ptr to simulate a RM int 0x21
 - make _sys_exists use the transfer buffer (which it needs)
 - make _sys_rawread properly handle an end-of-file read
   (zero bytes read)
 - make argument to _sys_seterrno short --- after a failed
   int 0x21 call, only the lower 16 bits of eax hold the MS-DOs
   error code
 - _sys_rawlseek accepts only 3 longword arguments, not 4
   (the offset is only 1 longword)
 - other minor fixes
This commit is contained in:
tkchia 2022-08-24 15:17:04 +00:00
parent 249e4b9069
commit 15955282f6
13 changed files with 52 additions and 25 deletions

View file

@ -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
* `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]))
errno = err_map[dos_err];

View file

@ -38,8 +38,9 @@ _getpid:
int 0x21
jnc .eur_dos
movb ah, 0x51
int 0x21
mov ebx, 0x210000
callf (interrupt_ptr)
xchg ebx, eax
.eur_dos:
xor edx, edx
movzx eax, ax
ret

View file

@ -23,9 +23,9 @@ _rename:
! Source filename.
mov esi, 4(ebx)
movzx edi, (transfer_buffer_ptr)
mov es, (pmode_ds)
cld
movzx edi, (transfer_buffer_ptr)
mov es, (pmode_ds)
cld
1:
lodsb
stosb
@ -47,8 +47,10 @@ _rename:
o16 mov dx, (transfer_buffer_ptr)
o16 mov di, ax
movb ah, 0x56
or ebx, 0x210000
mov ebx, 0x210000
callf (interrupt_ptr)
pop edi
pop esi
push ss
pop es
jmp .sys_zret

View file

@ -16,10 +16,22 @@
.define __sys_exists
__sys_exists:
mov ebx, esp
mov edx, 4(ebx)
push esi
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
int 0x21
mov ebx, 0x210000
callf (interrupt_ptr)
push ss
pop es
sbb eax, eax
inc eax
ret

View file

@ -16,7 +16,6 @@
.define __sys_gettime
__sys_gettime:
int 3
movb ah, 0x2c
int 0x21
mov ebx, esp

View file

@ -17,8 +17,7 @@
.define __sys_isopen
__sys_isopen:
mov ebx, esp
mov ebx, 4(bx)
mov ebx, 4(esp)
mov eax, 0x4400
int 0x21
sbb eax, eax

View file

@ -36,10 +36,12 @@ __sys_rawcreat:
movb ah, 0x3c
movzx edx, (transfer_buffer_ptr)
movb al, 8(ebx)
or ebx, 0x210000
mov ebx, 0x210000
callf (interrupt_ptr)
pop edi
pop esi
push ss
pop es
jmp .sys_axret

View file

@ -18,9 +18,10 @@
__sys_rawlseek:
movb ah, 0x42
mov ebx, esp
mov edx, 8(bx)
mov ecx, 12(bx)
movb al, 16(bx)
mov ebx, 4(bx)
mov edx, 8(ebx)
mov ecx, edx
shr ecx, 16
movb al, 12(ebx)
mov ebx, 4(ebx)
int 0x21
jmp .sys_dxaxret

View file

@ -37,9 +37,11 @@ __sys_rawopen:
movb ah, 0x3d
o16 mov dx, (transfer_buffer_ptr)
movb al, 8(ebx)
or ebx, 0x210000
mov ebx, 0x210000
callf (interrupt_ptr)
pop edi
pop esi
push ss
pop es
jmp .sys_axret

View file

@ -38,8 +38,9 @@ amount_to_read = 4*4
movb ah, 0x3f
o16 mov dx, (transfer_buffer_ptr)
movzx esi, dx
mov ebx, 0x210000
o16 mov bx, file_handle(ebp)
or ebx, 0x210000
callf (interrupt_ptr)
jnc success
@ -53,9 +54,10 @@ success:
! Copy eax bytes out of the transfer buffer.
push eax
movzx eax, ax
mov ecx, eax
movzx esi, (transfer_buffer_ptr)
jcxz exit
push eax
mov edi, write_buffer(ebp)
mov es, (pmode_ds)
cld
@ -69,6 +71,8 @@ success:
exit:
pop edi
pop esi
push ss
pop es
leave
ret

View file

@ -48,8 +48,8 @@ amount_to_write = 4*4
movb ah, 0x40
o16 mov dx, (transfer_buffer_ptr)
mov ebx, 0x210000
o16 mov bx, file_handle(ebp)
or ebx, 0x210000
callf (interrupt_ptr)
jnc exit
@ -59,6 +59,8 @@ amount_to_write = 4*4
exit:
pop edi
pop esi
push ss
pop es
leave
ret

View file

@ -20,7 +20,8 @@
! code in ax, and return a shortword -1. If the carry flag is clear, just
! 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_axret

View file

@ -34,11 +34,13 @@ _unlink:
! Make the DOS call.
movzx edi, (transfer_buffer_ptr)
mov dx, (transfer_buffer_ptr)
movb ah, 0x41
or ebx, 0x210000
callf (interrupt_ptr)
pop edi
pop esi
push ss
pop es
jmp .sys_zret