Most of read and write now works; filename-based operations partially work; but

there's a nasty memory corruption somewhere which needs investigating.
This commit is contained in:
David Given 2022-08-19 00:08:57 +02:00
parent 5329c98b81
commit dc1f69be83
17 changed files with 155 additions and 84 deletions

View file

@ -46,7 +46,7 @@ name led
program {EM}/lib/ack/em_led
mapflag -l* LNAME={PLATFORMDIR}/lib*
mapflag -fp FLOATS={EM}/{ILIB}fp
args {ALIGN} {SEPID} \
args {ALIGN} \
({RTS}:.b=-u _i_main) \
(.e:{HEAD}={PLATFORMDIR}/boot.o) \
({RTS}:.ocm.bas.b={PLATFORMDIR}/c-ansi.o) \
@ -66,7 +66,6 @@ name led
{PLATFORMDIR}/libc.a \
{PLATFORMDIR}/libem.a \
{PLATFORMDIR}/libend.a)
linker
end
name cv

View file

@ -7,17 +7,12 @@
.sect .text
.extern realloc_ptr
.define _brk
_brk:
enter 0, 0
newsize = 2*4
mov eax, newsize(ebp)
mov ebx, esp
mov eax, 1*4(ebx)
callf (realloc_ptr)
xor eax, eax
leave
ret

View file

@ -16,8 +16,8 @@
.define _close
_close:
mov ebx, sp
mov ebx, 4(ebx)
mov ebx, esp
mov ebx, 1*4(esp)
movb ah, 0x3E
int 0x21
jmp .sys_zret

View file

@ -16,7 +16,7 @@
.define _isatty
_isatty:
mov ebx, sp
mov ebx, esp
mov ebx, 4(ebx)
o16 mov ax, 0x4400
int 0x21

View file

@ -16,12 +16,39 @@
.define _rename
_rename:
int 3
mov bx, sp
push di
mov dx, 2(bx)
mov di, 4(bx)
mov ebx, esp
push esi
push edi
! Source filename.
mov esi, 4(ebx)
movzx edi, (transfer_buffer_ptr)
mov es, (pmode_ds)
cld
1:
lodsb
stosb
testb al, al
jnz 1b
! Destination filename.
mov eax, edi
mov esi, 8(ebx)
1:
lodsb
stosb
testb al, al
jnz 1b
! Make the DOS call.
o16 mov dx, (transfer_buffer_ptr)
o16 mov di, ax
movb ah, 0x56
int 0x21
pop di
or ebx, 0x210000
callf (interrupt_ptr)
pop edi
pop esi
jmp .sys_zret

View file

@ -16,11 +16,10 @@
.define __sys_exists
__sys_exists:
int 3
mov bx, sp
mov dx, 2(bx)
mov ax, 0x4300
mov ebx, esp
mov edx, 4(ebx)
mov eax, 0x4300
int 0x21
sbb ax, ax
inc ax
sbb eax, eax
inc eax
ret

View file

@ -16,11 +16,10 @@
.define __sys_getdate
__sys_getdate:
int 3
movb ah, 0x2a
int 0x21
mov bx, sp
mov bx, 2(bx)
mov (bx), dx
mov 2(bx), cx
mov ebx, esp
mov ebx, 4(ebx)
o16 mov 0(ebx), dx
o16 mov 2(ebx), cx
ret

View file

@ -16,11 +16,10 @@
.define __sys_gettime
__sys_gettime:
int 3
movb ah, 0x2c
int 0x21
mov bx, sp
mov bx, 2(bx)
mov (bx), cx
mov 2(bx), dx
mov ebx, esp
mov ebx, 2(ebx)
o16 mov 0(ebx), cx
o16 mov 2(ebx), dx
ret

View file

@ -17,11 +17,10 @@
.define __sys_isopen
__sys_isopen:
int 3
mov bx, sp
mov bx, 2(bx)
mov ax, 0x4400
mov ebx, esp
mov ebx, 4(bx)
mov eax, 0x4400
int 0x21
sbb ax, ax
inc ax
sbb eax, eax
inc eax
ret

View file

@ -17,13 +17,13 @@
.define __sys_isreadyr
__sys_isreadyr:
mov ebx, sp
mov ebx, esp
mov eax, 0x4406
mov ebx, 4(ebx)
int 0x21
jnc ok
movb al, 0
ok:
cbw
cwd
o16 cbw
cwde
ret

View file

@ -16,10 +16,30 @@
.define __sys_rawcreat
__sys_rawcreat:
int 3
! Copy filename to transfer buffer.
mov ebx, esp
push esi
push edi
mov esi, 4(ebx)
movzx edi, (transfer_buffer_ptr)
mov es, (pmode_ds)
cld
1:
lodsb
stosb
testb al, al
jnz 1b
! Make the DOS call.
movb ah, 0x3c
mov bx, sp
mov dx, 2(bx)
mov cx, 4(bx)
int 0x21
movzx edx, (transfer_buffer_ptr)
movb al, 8(ebx)
or ebx, 0x210000
callf (interrupt_ptr)
pop edi
pop esi
jmp .sys_axret

View file

@ -16,12 +16,11 @@
.define __sys_rawlseek
__sys_rawlseek:
int 3
movb ah, 0x42
mov bx, sp
mov dx, 4(bx)
mov cx, 6(bx)
movb al, 8(bx)
mov bx, 2(bx)
mov ebx, esp
mov edx, 8(bx)
mov ecx, 12(bx)
movb al, 16(bx)
mov ebx, 4(bx)
int 0x21
jmp .sys_dxaxret

View file

@ -16,10 +16,30 @@
.define __sys_rawopen
__sys_rawopen:
int 3
! Copy filename to transfer buffer.
mov ebx, esp
push esi
push edi
mov esi, 4(ebx)
movzx edi, (transfer_buffer_ptr)
mov es, (pmode_ds)
cld
1:
lodsb
stosb
testb al, al
jnz 1b
! Make the DOS call.
movb ah, 0x3d
mov bx, sp
mov dx, 2(bx)
movb al, 4(bx)
int 0x21
o16 mov dx, (transfer_buffer_ptr)
movb al, 8(ebx)
or ebx, 0x210000
callf (interrupt_ptr)
pop edi
pop esi
jmp .sys_axret

View file

@ -12,12 +12,6 @@
.sect .text
.extern pmode_ds
.extern pmode_cs
.extern rmode
.extern transfer_buffer_ptr
.extern interrupt_ptr
! Read bytes from a file descriptor. These routines do not do any
! translation between CRLF and LF line endings.
!
@ -27,6 +21,8 @@
.define __sys_rawread
__sys_rawread:
enter 0, 0
push esi
push edi
file_handle = 2*4
write_buffer = 3*4
amount_to_read = 4*4
@ -43,7 +39,6 @@ amount_to_read = 4*4
movb ah, 0x3f
o16 mov dx, (transfer_buffer_ptr)
o16 mov bx, file_handle(ebp)
mov ecx, 0x80
or ebx, 0x210000
callf (interrupt_ptr)
jnc success
@ -52,8 +47,8 @@ amount_to_read = 4*4
push eax
call __sys_seterrno
leave
ret
pop ecx
jmp exit
success:
! Copy eax bytes out of the transfer buffer.
@ -71,6 +66,9 @@ success:
loop 1b
pop eax
exit:
pop edi
pop esi
leave
ret

View file

@ -12,12 +12,6 @@
.sect .text
.extern pmode_ds
.extern pmode_cs
.extern rmode
.extern transfer_buffer_ptr
.extern interrupt_ptr
! Write bytes to/to a file descriptor. These routines do not do any
! translation between CRLF and LF line endings.
!
@ -27,6 +21,8 @@
.define __sys_rawwrite
__sys_rawwrite:
enter 0, 0
push esi
push edi
file_handle = 2*4
read_buffer = 3*4
amount_to_write = 4*4
@ -59,7 +55,10 @@ amount_to_write = 4*4
push eax
call __sys_seterrno
pop ecx
exit:
pop edi
pop esi
leave
ret

View file

@ -16,8 +16,29 @@
.define _unlink
_unlink:
mov bx, sp
mov dx, 2(bx)
! Copy filename to transfer buffer.
mov ebx, esp
push esi
push edi
mov esi, 4(ebx)
movzx edi, (transfer_buffer_ptr)
mov es, (pmode_ds)
cld
1:
lodsb
stosb
testb al, al
jnz 1b
! Make the DOS call.
movzx edi, (transfer_buffer_ptr)
movb ah, 0x41
int 0x21
or ebx, 0x210000
callf (interrupt_ptr)
pop edi
pop esi
jmp .sys_zret

View file

@ -321,24 +321,21 @@ interrupt:
mov (dpmi_ds), ax
mov (dpmi_ss), ax
push es
push ds
mov ax, dosstack ! auto stack is too small
mov (dpmi_sp), ax
mov (dpmi_sp), dosstack ! auto stack is too small
push ds
pop es
mov di, dpmi_edi
o32 mov edi, dpmi_edi
mov ax, 0x300
o32 shr ebx, 16
int 0x31 ! simulate DOS interrupt
pop ds
pop es
pushf
o32 movzx eax, (dpmi_eax)
o32 movzx ebx, (dpmi_ebx)
o32 movzx ecx, (dpmi_ecx)
o32 movzx edx, (dpmi_edx)
o32 movzx esi, (dpmi_esi)
o32 movzx edi, (dpmi_edi)
push (dpmi_flags)
popf
ret