write() system calls work; start going through the libsys.

This commit is contained in:
David Given 2022-08-17 22:34:06 +02:00
parent 680b6b9857
commit 48398b072a
19 changed files with 172 additions and 49 deletions

View file

@ -18,15 +18,24 @@ begtext:
! On entry, the stub has cs and ds pointing at the 32-bit ! On entry, the stub has cs and ds pointing at the 32-bit
! segment, but ss is still pointing at the 16-bit segment. ! segment, but ss is still pointing at the 16-bit segment.
! !
! si:di memory handle of linear block
! ax: pmode code segment of stub ! ax: pmode code segment of stub
! dx: pointer to realloc routine ! bx: pmode data segment of stub
! fs: data segment (just a clone of the code segment) ! cx: rmode segment of stub
! dx: pointer to realloc routine (in stub)e
! si: pointer to interrupt routine (in stub)
! di: pointer to transfer buffer (in stub)
! Resize the segment to include the BSS. ! Resize the segment to include the BSS.
o16 cseg mov (realloc_ptr+4), ax o16 cseg mov (realloc_ptr+4), ax
cseg mov (realloc_ptr+0), edx cseg mov (realloc_ptr+0), edx
cseg o16 mov (pmode_cs), ax
cseg o16 mov (pmode_ds), bx
cseg o16 mov (rmode), cx
cseg o16 mov (interrupt_ptr+4), ax
cseg mov (interrupt_ptr+0), esi
cseg o16 mov (transfer_buffer_ptr), di
mov eax, endbss mov eax, endbss
cseg callf (realloc_ptr) cseg callf (realloc_ptr)
@ -180,10 +189,19 @@ al_exit:
movb ah, 0x4c movb ah, 0x4c
int 0x21 int 0x21
! This must be in the code segment due to bootstrap issues. ! These must be in the code segment due to bootstrap issues.
realloc_ptr: realloc_ptr: .space 6 ! far
.data2 0 interrupt_ptr: .space 6 ! far
.data4 0 transfer_buffer_ptr: .space 2 ! near
rmode: .space 2
pmode_cs: .space 2
pmode_ds: .space 2
.define interrupt_ptr
.define rmode
.define pmode_cs
.define pmode_ds
.define transfer_buffer_ptr
! Define symbols at the beginning of our various segments, so that we can find ! Define symbols at the beginning of our various segments, so that we can find
! them. (Except .text, which has already been done.) ! them. (Except .text, which has already been done.)
@ -210,7 +228,7 @@ no_room_msg: .ascii 'No room$'
.comm _psp, 256 .comm _psp, 256
.sect .bss .sect .bss
.space 512 .space 32*1024
.stack: .stack:
! vim: ts=4 sw=4 et ft=asm ! vim: ts=4 sw=4 et ft=asm

View file

@ -39,7 +39,6 @@ name as
program {EM}/lib/ack/{PLATFORM}/as program {EM}/lib/ack/{PLATFORM}/as
args - -o > < args - -o > <
prep cond prep cond
end end
name led name led
from .o.a from .o.a

View file

@ -16,7 +16,8 @@ acklibrary {
"./sys_rawcreat.s", "./sys_rawcreat.s",
"./sys_rawlseek.s", "./sys_rawlseek.s",
"./sys_rawopen.s", "./sys_rawopen.s",
"./sys_rawrw.s", "./sys_rawread.s",
"./sys_rawwrite.s",
"./sys_xret.s", "./sys_xret.s",
"./unlink.s", "./unlink.s",
"plat/msdos/libsys+srcs", "plat/msdos/libsys+srcs",

View file

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

View file

@ -39,7 +39,7 @@ _getpid:
jnc .eur_dos jnc .eur_dos
movb ah, 0x51 movb ah, 0x51
int 0x21 int 0x21
xchg bx, ax xchg ebx, eax
.eur_dos: .eur_dos:
xor dx, dx xor edx, edx
ret ret

View file

@ -16,22 +16,22 @@
.define _isatty .define _isatty
_isatty: _isatty:
mov bx, sp mov ebx, sp
mov bx, 2(bx) mov ebx, 4(ebx)
mov ax, 0x4400 o16 mov ax, 0x4400
int 0x21 int 0x21
jc error jc error
testb dl, dl testb dl, dl
jz not_tty jz not_tty
mov ax, 1 mov eax, 1
ret ret
not_tty: not_tty:
mov (_errno), 25 ! ENOTTY mov (_errno), 25 ! ENOTTY
not_tty_2: not_tty_2:
xor ax, ax xor eax, eax
ret ret
error: error:
push ax push eax
call __sys_seterrno call __sys_seterrno
pop cx pop ecx
jmp not_tty_2 jmp not_tty_2

View file

@ -16,6 +16,7 @@
.define _rename .define _rename
_rename: _rename:
int 3
mov bx, sp mov bx, sp
push di push di
mov dx, 2(bx) mov dx, 2(bx)

View file

@ -16,6 +16,7 @@
.define __sys_exists .define __sys_exists
__sys_exists: __sys_exists:
int 3
mov bx, sp mov bx, sp
mov dx, 2(bx) mov dx, 2(bx)
mov ax, 0x4300 mov ax, 0x4300

View file

@ -16,6 +16,7 @@
.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 bx, sp

View file

@ -16,6 +16,7 @@
.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 bx, sp

View file

@ -17,6 +17,7 @@
.define __sys_isopen .define __sys_isopen
__sys_isopen: __sys_isopen:
int 3
mov bx, sp mov bx, sp
mov bx, 2(bx) mov bx, 2(bx)
mov ax, 0x4400 mov ax, 0x4400

View file

@ -17,6 +17,7 @@
.define __sys_isreadyr .define __sys_isreadyr
__sys_isreadyr: __sys_isreadyr:
int 3
mov bx, sp mov bx, sp
mov ax, 0x4406 mov ax, 0x4406
mov bx, 2(bx) mov bx, 2(bx)

View file

@ -16,6 +16,7 @@
.define __sys_rawcreat .define __sys_rawcreat
__sys_rawcreat: __sys_rawcreat:
int 3
movb ah, 0x3c movb ah, 0x3c
mov bx, sp mov bx, sp
mov dx, 2(bx) mov dx, 2(bx)

View file

@ -16,6 +16,7 @@
.define __sys_rawlseek .define __sys_rawlseek
__sys_rawlseek: __sys_rawlseek:
int 3
movb ah, 0x42 movb ah, 0x42
mov bx, sp mov bx, sp
mov dx, 4(bx) mov dx, 4(bx)

View file

@ -16,6 +16,7 @@
.define __sys_rawopen .define __sys_rawopen
__sys_rawopen: __sys_rawopen:
int 3
movb ah, 0x3d movb ah, 0x3d
mov bx, sp mov bx, sp
mov dx, 2(bx) mov dx, 2(bx)

View file

@ -12,7 +12,13 @@
.sect .text .sect .text
! Read/write bytes to/to a file descriptor. These routines do not do any .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. ! translation between CRLF and LF line endings.
! !
! Note that, for MS-DOS, a raw "write" request of zero bytes will truncate ! Note that, for MS-DOS, a raw "write" request of zero bytes will truncate
@ -20,14 +26,5 @@
.define __sys_rawread .define __sys_rawread
__sys_rawread: __sys_rawread:
movb ah, 0x3f int 3
.data1 0x3d ! eat up the next instruction
.define __sys_rawwrite
__sys_rawwrite:
movb ah, 0x40
mov bx, sp
mov dx, 4(bx)
mov cx, 6(bx)
mov bx, 2(bx)
int 0x21
jmp .sys_axret

View file

@ -0,0 +1,70 @@
#
! $Source$
! $State$
! $Revision$
! Declare segments (the order is important).
.sect .text
.sect .rom
.sect .data
.sect .bss
.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.
!
! Note that, for MS-DOS, a raw "write" request of zero bytes will truncate
! (or extend) the file to the current file position.
.define __sys_rawwrite
__sys_rawwrite:
enter 4, 0
amount_transferred = -1*4
file_handle = 2*4
read_buffer = 3*4
amount_to_write = 4*4
mov es, (pmode_ds)
mov amount_transferred(ebp), 0
mainloop:
mov ecx, 32*1024
cmp amount_to_write(ebp), ecx
jge 2f
mov ecx, amount_to_write(ebp)
test ecx, ecx
jz exit
2:
! Copy ecx bytes into the transfer buffer.
push ecx
mov esi, read_buffer(ebp)
movzx edi, (transfer_buffer_ptr)
rep movsb
pop ecx
movb ah, 0x40
o16 mov dx, (transfer_buffer_ptr)
o16 mov bx, file_handle(ebp)
or ebx, 0x210000
callf (interrupt_ptr)
movzx eax, ax
add read_buffer(ebp), eax
add amount_transferred(ebp), eax
sub amount_to_write(ebp), eax
jmp mainloop
exit:
mov eax, amount_to_write(ebp)
leave
ret

View file

@ -13,29 +13,38 @@
.sect .text .sect .text
! .sys_zret: if the carry flag is set, then set `errno' from the DOS error ! .sys_zret: if the carry flag is set, then set `errno' from the DOS error
! code in ax, and return a shortword -1. If the carry flag is clear, just ! code in ax, and return an int -1. If the carry flag is clear, just
! return a shortword zero. ! return an int zero.
! !
! .sys_axret: if the carry flag is set, then set `errno' from the DOS error ! .sys_axret: if the carry flag is set, then set `errno' from the DOS error
! 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 a longword -1 or dx:ax as a ! .sys_dxaxret: same as .sys_axret, but return -1 or dx:ax as a return value.
! return value.
.extern .sys_zret .extern .sys_zret
.extern .sys_axret .extern .sys_axret
.extern .sys_dxaxret .extern .sys_dxaxret
.sys_zret: .sys_zret:
jc error jc error
xor ax, ax xor eax, eax
no_error: no_error:
ret ret
.sys_axret: .sys_axret:
.sys_dxaxret: jc error
jnc no_error ret
error:
push ax .sys_dxaxret:
call __sys_seterrno jc error
pop cx shl edx, 16
o16 mov dx, ax
mov eax, edx
ret
error:
movzx eax, ax
push eax
call __sys_seterrno
pop ecx
ret ret

View file

@ -210,15 +210,17 @@ exe_start:
! Jump to the new segment and enter 32-bit mode! ! Jump to the new segment and enter 32-bit mode!
mov ax, (psegcs) o32 movzx eax, (psegcs)
mov bx, (psegds) o32 movzx ebx, (psegds)
mov cx, (rseg) o32 movzx ecx, (rseg)
o32 mov edx, realloc o32 mov edx, realloc
o32 mov esi, interruptf
o32 mov edi, transfer_buffer
push es push es
pop ds pop ds
push es push es
push 0 push 0
retf retf ! 19b
! ALL CODE ABOVE THIS POINT DISCARDED ON ENTRY TO 32-BIT CODE ! ALL CODE ABOVE THIS POINT DISCARDED ON ENTRY TO 32-BIT CODE
! (it's reused as the 16-bit stack) ! (it's reused as the 16-bit stack)
@ -271,6 +273,7 @@ realloc:
jc bad_dpmi jc bad_dpmi
popa popa
o32 mov eax, (pmemlen)
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)
@ -309,10 +312,15 @@ exit_with_error:
! Simulate DOS interrupt. ! Simulate DOS interrupt.
int21: int21:
o32 or ebx, 0x210000
! Simulate interrupt in the high half of ebx.
interrupt:
mov (dpmi_eax), ax mov (dpmi_eax), ax
mov (dpmi_ebx), bx mov (dpmi_ebx), bx
mov (dpmi_ecx), cx mov (dpmi_ecx), cx
mov (dpmi_edx), dx mov (dpmi_edx), dx
mov (dpmi_esi), si
mov (dpmi_edi), di
mov ax, (rseg) mov ax, (rseg)
mov (dpmi_ds), ax mov (dpmi_ds), ax
push es push es
@ -324,16 +332,28 @@ int21:
pop es pop es
mov di, dpmi_edi mov di, dpmi_edi
mov ax, 0x300 mov ax, 0x300
mov bx, 0x21 o32 shr ebx, 16
int 0x31 ! simulate DOS interrupt int 0x31 ! simulate DOS interrupt
pop ds pop ds
pop es pop es
pushf
mov ax, (dpmi_eax) mov ax, (dpmi_eax)
mov bx, (dpmi_ebx) mov bx, (dpmi_ebx)
mov cx, (dpmi_ecx) mov cx, (dpmi_ecx)
mov dx, (dpmi_edx) mov dx, (dpmi_edx)
mov si, (dpmi_esi)
mov di, (dpmi_edi)
popf
ret ret
! Far call wrapper around interrupt.
interruptf:
push ds
cseg mov ds, (psegds)
call interrupt
pop ds
o32 retf
bad_dpmi_msg: bad_dpmi_msg:
.asciz "DPMI error during setup" .asciz "DPMI error during setup"
no_file_msg: no_file_msg: