kernel: add syscall handling stub

This commit is contained in:
Nero 2021-12-31 02:08:21 +00:00
parent c0b8c107c4
commit 576b2c6546
1 changed files with 149 additions and 50 deletions

View File

@ -2,15 +2,13 @@
cseg equ 0x0
jmp init
%include "bpb.inc"
%include "farptr.inc"
;;; Character I/O
; dflags bitfields
DRVLOG equ 0x01 ; bit 0 - drive logged in (see drvnum)
DRVCTL equ 0x02 ; bit 1 - controller configured
DRVEXT equ 0x04 ; bit 2 - EBIOS supported
DIRTY equ 0x08 ; bit 3 - dskbuf dirty
DRVCHS equ 0x10 ; bit 4 - CHS geometry known
; direct console I/O
; IN dl character to output or 0xFF if input
; OUT al character to read
conio cmp dl, 0xFF
je conin
; raw console output
; IN dl character
@ -20,16 +18,6 @@ conout xchg ax, dx
int 0x10
ret
; check if character has characters ready
; OUT al 0xFF if data, 0 if none
const mov ah, 1
int 0x16
jz .emp
mov ax, 0xFF
ret
.emp mov al, 0
ret
; read character from console
; OUT al character or zero
conin call const
@ -39,6 +27,16 @@ conin call const
int 0x16
.ret ret
; check if character has characters ready
; OUT al 0xFF if data, 0 if none
const mov ah, 1
int 0x16
jz .emp
mov ax, 0xFF
ret
.emp mov al, 0
ret
; dummy: write to auxillary dev
auxout ret
@ -71,13 +69,6 @@ readc call const
; IN dl character
putc jmp conout
; direct console I/O
; IN dl character to output or 0xFF if input
; OUT al character to read
dcon cmp dl, 0xFF
je conin
jmp conout
; output character string
; IN ds:dx far ptr to string, '$'-terminated
puts push si
@ -147,6 +138,18 @@ gets mov si, dx
call putc
ret
;;; Disk i/o
%include "bpb.inc"
%include "farptr.inc"
; dflags bitfields
DRVLOG equ 0x01 ; bit 0 - drive logged in (see drvnum)
DRVCTL equ 0x02 ; bit 1 - controller configured
DRVEXT equ 0x04 ; bit 2 - EBIOS supported
DIRTY equ 0x08 ; bit 3 - dskbuf dirty
DRVCHS equ 0x10 ; bit 4 - CHS geometry known
align 16
; IBM Interrupt Sharing Protocol structure
i13isp jmp short int13i
@ -436,29 +439,6 @@ diskio mov cl, 1 ; read len
stc
ret
; Get interrupt vector
; IN al interrupt number
; OUT es:bx vector
getint mov bl, al
mov bh, 0
; multiply with 4
add bx, bx
add bx, bx
les bx, [cs:bx]
ret
; Set interrupt vector
; IN al interrupt number
; ds:dx vector
setint mov bl, al
mov bh, 0
; multiply with 4
add bx, bx
add bx, bx
mov [cs:bx], dx
mov [cs:bx+2], ds
ret
init mov ax, cs
; boot failure if loaded wrong
cmp ax, cseg
@ -481,11 +461,130 @@ init mov ax, cs
mov word [4*0x13], int13i
mov [4*0x13+2], cs
mov ax, 0x0e37
int 0x10
; install int21h handler
mov word [4*0x21], int21h
mov [4*0x21+2], cs
mov dl, 0x36
mov ah, 2
int 0x21
halt hlt
jmp halt
;;; Export functions as syscalls
; SP, BP, SI, DI and ES must be preserved by kernel code
; DL, DX or DS:DX is input argument from prog
; AL, BX or ES:BX is return value to prog
srb equ 0x8000
srw equ 0x4000
; DOS style syscall interface
int21h push bx
xor bx, bx
mov bl, ah
jmp sysc
; CP/M-86 style syscall interface
intE0h push bx
xor bx, bx
mov bl, cl
; bx = syscall number
; stack must be -> BX IP CS FL
; for return to prog
sysc add bx, bx
mov bx, [cs:bx+stab]
test bh, srw >> 8 ; fork off bx returns
jnz .l02
test bh, srb >> 8 ; fork off al returns
jnz .l01
; syscall with no return value
push dx
push cx
push ax
push ds
call bx
pop ds
pop ax
pop cx
pop dx
pop bx
iret
; syscalls returning byte in al
.l01 push dx
push cx
push ds
and bh, ~(srb >> 8)
call bx
pop ds
pop cx
pop dx
pop bx
iret
; syscalls returning bx or es:bx
.l02 add sp, 2 ; discard bx on the stack
push dx
push cx
push ax
push ds
and bh, ~(srw >> 8)
call bx
pop ds
pop ax
pop cx
pop dx
ret
section .rodata
; syscall table
stab dw 0 ; 0 reboot
dw getc + srb ; 1 console input
dw putc ; 2 console output
dw auxin ; 3 reader in
dw auxout + srb ; 4 puncher out
dw lstout ; 5 lister out
dw 0 ; 6 direct console i/o
dw 0 ; 7 read i/o byte
dw 0 ; 8 get i/o byte
dw 0 ; 9 string output
dw 0 ; 10 string input
dw 0 ; 11 console status
dw 0 ; 12 get version number
dw 0 ; 13 reset disks
dw 0 ; 14 set drive
dw 0 ; 15 open file
dw 0 ; 16 close file
dw 0 ; 17 find first
dw 0 ; 18 find next
dw 0 ; 19 delete file
dw 0 ; 20 sequential read
dw 0 ; 21 sequential write
dw 0 ; 22 create file
dw 0 ; 23 rename file
dw 0 ; 24 get login vector
dw 0 ; 25 get drive
dw 0 ; 26 set dma addr
dw 0 ; 27 alloc vector
dw 0 ; 28 set drive r/o
dw 0 ; 29 get r/o vector
dw 0 ; 30 file attr
dw 0 ; 31 get addr of disk parameter block
dw 0 ; 32 get user number
dw 0 ; 33 random read
dw 0 ; 34 random write
dw 0 ; 35 calculate file size
dw 0 ; 36 calculate cur record number
dw 0 ; 37 reset drive
dw 0 ; 38
dw 0 ; 39
dw 0 ; 40 random write with block init
stab_e nop
section .data
dap db 0x10, 0
dw 1
dw dskbuf, cseg