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

View file

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

View file

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

View file

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

View file

@ -16,12 +16,39 @@
.define _rename .define _rename
_rename: _rename:
int 3 mov ebx, esp
mov bx, sp push esi
push di push edi
mov dx, 2(bx)
mov di, 4(bx) ! 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 movb ah, 0x56
int 0x21 or ebx, 0x210000
pop di callf (interrupt_ptr)
pop edi
pop esi
jmp .sys_zret jmp .sys_zret

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -16,10 +16,30 @@
.define __sys_rawcreat .define __sys_rawcreat
__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 movb ah, 0x3c
mov bx, sp movzx edx, (transfer_buffer_ptr)
mov dx, 2(bx) movb al, 8(ebx)
mov cx, 4(bx) or ebx, 0x210000
int 0x21 callf (interrupt_ptr)
pop edi
pop esi
jmp .sys_axret jmp .sys_axret

View file

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

View file

@ -16,10 +16,30 @@
.define __sys_rawopen .define __sys_rawopen
__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 movb ah, 0x3d
mov bx, sp o16 mov dx, (transfer_buffer_ptr)
mov dx, 2(bx) movb al, 8(ebx)
movb al, 4(bx) or ebx, 0x210000
int 0x21 callf (interrupt_ptr)
pop edi
pop esi
jmp .sys_axret jmp .sys_axret

View file

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

View file

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

View file

@ -16,8 +16,29 @@
.define _unlink .define _unlink
_unlink: _unlink:
mov bx, sp ! Copy filename to transfer buffer.
mov dx, 2(bx)
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 movb ah, 0x41
int 0x21 or ebx, 0x210000
callf (interrupt_ptr)
pop edi
pop esi
jmp .sys_zret jmp .sys_zret

View file

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