Implement entrypoint and table for syscalls

This commit is contained in:
Nero 2021-01-02 03:45:03 +00:00
parent 015eea2f2f
commit 1dbfb2f592
3 changed files with 113 additions and 7 deletions

View File

@ -14,7 +14,7 @@ init: cli
mov ds, ax
mov es, ax
mov ss, ax
mov sp, ( stack+stacksize )
mov sp, ax
call printf
%defstr VERSIONSTR VERSION
@ -31,20 +31,25 @@ init: cli
call logdrv
mov bx, testfcb
call open
push ax
call printf
db "AX=",2,0x0A,0x0D,0
mov word [0x21*4], int21
mov word [0x21*4+2], cs
mov word [curpsp], 0x1000
mov ah, 2
mov dl, 0x37
int 0x21
restart:
hlt: hlt
jmp hlt
%include "kernel/bdos.asm"
%include "kernel/far.asm"
%include "kernel/fcb.asm"
%include "kernel/find.asm"
%include "kernel/drive.asm"
%include "kernel/drive.asm"
%include "kernel/printf.asm"
%include "kernel/char.asm"
section .data
@ -54,4 +59,5 @@ testfcb: db 0
section .bss
alignb 2
stack: resb stacksize

89
kernel/bdos.asm Normal file
View File

@ -0,0 +1,89 @@
section .bss
curpsp: resw 1
absolute 0
resb 2 ; ret 0 exit
resb 2 ; allocation length
resb 1
resb 5 ; CP/M entry point
; SS:SP, DS:DX, ES:BX and AX from the program
PSPAX: resw 1
PSPSS: resw 1
PSPSP: resw 1
PSPDS: resw 1
PSPDX: resw 1
PSPES: resw 1
PSPBX: resd 1
section .text
; OUT ds PSP segment
pspds: xor ax, ax
mov ds, ax
mov ds, [curpsp]
ret
int21: push ds
; load program PSP and save userdata
push ax
call pspds
pop word [PSPAX]
pop word [PSPDS]
mov [PSPSS], ss
mov [PSPSP], sp
mov [PSPDX], dx
mov [PSPES], es
mov [PSPBX], bx
mov ss, ax
mov sp, ( stack+stacksize )
mov al, [PSPAX+1]
shl ax, 1
shl ax, 1
call .etbl
; syscall table
; cells: ptr to handler, ptr to sysret
dw restart, sret
dw getc, sretb
dw putc, sret
; set up a return chain and execute it
; first return into handler function
; second return into appropiate sysret
.etbl: pop bx
add bx, ax
push word [cs:bx+2]
push word [cs:bx]
ret
; sysret handlers
; return ES:BX to user
sretd: call pspds
jmp sret.l02
; return BX to user
sretw: call pspds
mov es, [PSPES]
jmp sret.l02
; return AL to user
sretb: push ax
call pspds
pop ax
mov ah, [PSPAX+1]
les bx, [PSPBX]
jmp sret.l03
; return without result
sret: call pspds
.l01: les bx, [PSPBX]
.l02: mov ax, [PSPAX]
.l03: mov ss, [PSPSS]
mov sp, [PSPSP]
lds dx, [PSPDX]
iret

11
kernel/char.asm Normal file
View File

@ -0,0 +1,11 @@
getc: xor ax, ax
int 0x16
test al, al
jz getc
ret
putc: mov al, dl
mov ah, 0x0e
xor bx, bx
int 0x10
ret