From 1dbfb2f592bcb9c43baad0b69730bfc76b793338 Mon Sep 17 00:00:00 2001 From: Nero <41307858+nero@users.noreply.github.com> Date: Sat, 2 Jan 2021 03:45:03 +0000 Subject: [PATCH] Implement entrypoint and table for syscalls --- boot/kernel.asm | 20 +++++++---- kernel/bdos.asm | 89 +++++++++++++++++++++++++++++++++++++++++++++++++ kernel/char.asm | 11 ++++++ 3 files changed, 113 insertions(+), 7 deletions(-) create mode 100644 kernel/bdos.asm create mode 100644 kernel/char.asm diff --git a/boot/kernel.asm b/boot/kernel.asm index 4cc1913..3a2d07f 100644 --- a/boot/kernel.asm +++ b/boot/kernel.asm @@ -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 diff --git a/kernel/bdos.asm b/kernel/bdos.asm new file mode 100644 index 0000000..6c77233 --- /dev/null +++ b/kernel/bdos.asm @@ -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 diff --git a/kernel/char.asm b/kernel/char.asm new file mode 100644 index 0000000..fc69c09 --- /dev/null +++ b/kernel/char.asm @@ -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