From 0bd59dd2521a6754ef9fb1128aaf27156dddd36b Mon Sep 17 00:00:00 2001 From: Nero <41307858+nero@users.noreply.github.com> Date: Sat, 1 Jan 2022 21:22:57 +0000 Subject: [PATCH] Remove remnants from earlier kernel attempts --- Makefile | 2 - kernel/cluster.asm | 95 ---------------------------------- kernel/fat.asm | 125 --------------------------------------------- kernel/fcb.asm | 59 --------------------- kernel/main.asm | 8 --- kernel/printf.asm | 66 ------------------------ kernel/psp.asm | 62 ---------------------- kernel/rootdir.asm | 113 ---------------------------------------- kernel/syscall.asm | 102 ------------------------------------ 9 files changed, 632 deletions(-) delete mode 100644 kernel/cluster.asm delete mode 100644 kernel/fat.asm delete mode 100644 kernel/fcb.asm delete mode 100644 kernel/main.asm delete mode 100644 kernel/printf.asm delete mode 100644 kernel/psp.asm delete mode 100644 kernel/rootdir.asm delete mode 100644 kernel/syscall.asm diff --git a/Makefile b/Makefile index 4000af6..be6baf8 100644 --- a/Makefile +++ b/Makefile @@ -40,8 +40,6 @@ host/%.elf: host/%.c %.bs: boot/%.asm $(NASM) $(NASM_ARGS) -o $@ $< -@rdos.com: kernel/*.asm - # Special case: variations of FAT vbr fat1.bs: boot/fat.asm $(NASM) $(NASM_ARGS) -DFAT12 -DCHS -o $@ $< diff --git a/kernel/cluster.asm b/kernel/cluster.asm deleted file mode 100644 index f66a74e..0000000 --- a/kernel/cluster.asm +++ /dev/null @@ -1,95 +0,0 @@ -; read/write data from FAT clusters -; requires defines from fcb.asm - -section .rodata - - ; sector sizes for fast lookup -sstab dw 0x800,0x400,0x200,0x100,0x80 - -section .text - - ; Map part of cluster into dskbuf - ; IN DX:AX sector number within cluster area -mapclus mov bx, [cs:bpb+BPBRDE] - mov cl, 4 - shr bx, cl ; 32 bytes per entry - add ax, bx - adc dx, 0 - ; counting from beginning of dir - ; add fat table sizes -maprde xor ch, ch - mov cl, byte [cs:bpb+BPBFN] -.loop add ax, [cs:bpb+BPBFS] - adc dx, 0 - loop .loop - ; counting from beginning of FAT - ; add reserved sector count -mapfat add ax, [cs:bpb+BPBRSC] - adc dx, 0 - - jmp maprel - - ; split AX at a bit boundary - ; basically a DIV 2^CX - ; IN ax divident - ; cx integer log2(divisor) - ; OUT ax quotient - ; dx remainder (lower CX bits) -split mov dx, 1 - shl dx, cl - dec dx - and dx, ax - shr ax, cl - ret - -filesec call fcbdrv - mov bx, dx - - ; find sector size scale factor - mov ax, cs - mov es, ax - mov ax, [cs:bpb+BPBSS] - mov di, sstab - mov cx, 5 - repne scasw - ; CX is now sector size div 128 - ; same format as in DPT - mov ah, 0 - mov al, [ds:bx+FCBRN] - call split - ; ax = sector within current cluster - ; dx = record number - push dx - mov di, ax - - mov ax, [ds:bx+FCBCLUS] - sub ax, 2 - mov ch, 0 - mov cl, [cs:bpb+BPBSC] - mul cx - add ax, di - call mapclus - - pop bx - mov cl, 7 - shl bx, cl - add bx, dskbuf - mov dx, bx - mov ax, cs - mov ds, ax - ret - -read mov bp, sp - call filesec - call getdta - mov cx, 0x80 - call stofar - ret - -write mov bp, sp - call filesec - call getdta - mov cx, 0x80 - call lodfar - call dirty - ret diff --git a/kernel/fat.asm b/kernel/fat.asm deleted file mode 100644 index aad99bb..0000000 --- a/kernel/fat.asm +++ /dev/null @@ -1,125 +0,0 @@ -section .bss - -clus resw 1 - -section .text - - ; Set cluster for next operations - ; IN dx cluster number -setclus mov [clus], dx - ret - - ; get ptr to single byte in fat table - ; IN dx position byte in fat table - ; OUT bx ptr to byte in dskbuf -_fat1 push dx - mov ax, dx - xor dx, dx - mov cl, 9 - shr ax, cl - add ax, [bpb+BPBRSC] - adc dx, 0 - call map - pop dx - mov bx, dx - and bx, 0x1FF - add bx, dskbuf - ret - - ; get ptr to word in fat table -_fat2 push dx - mov ax, dx - xor dx, dx - mov cl, 8 - shr ax, cl - add ax, [bpb+BPBRSC] - adc dx, 0 - call map - pop dx - mov bl, dl - mov bh, 0 - add bx, bx - add bx, dskbuf - ret - - ; read value from fat table - ; index given with setclus - ; OUT bx value - ; carry set if EOF marker -rdfat mov dx, [clus] - mov ax, dx - shr ax, 1 - add dx, ax - call _fat1 - push word [bx] - inc dx - call _fat1 - mov si, bx - pop bx - mov bh, [si] - test word [clus], 1 - jz l001 - mov cl, 4 - shr bx, cl -l001 and bx, 0xFFF - cmp bx, 0xFF0 - cmc - ret - - ; set value in FAT table - ; IN dx value -wrfat and dh, 0x0F - push dx - ; DX = index * 1.5 - mov dx, [clus] - mov ax, dx - shr dx, 1 - add dx, ax - call _fat1 - pop ax - test [clus], 1 - jnz l004 - ; even, first byte full - mov [bx], al - push ax - call dirty - ; DX = index * 1.5 - mov dx, [clus] - mov ax, dx - shr dx, 1 - add dx, ax - inc dx - call _fat1 - pop ax - mov al, [bx] - and al, 0xF0 - or al, ah - mov [bx], al - call dirty - jmp l005 - ; odd, second byte full -l004: mov ch, [bx] - ; concat existing and our nib - and ch, 0x0F - mov cl, 4 - shl ax, cl - or al, ch - ; write back lower 4 bits - mov [bx], al - call dirty - push ax - ; re-calculate offset - mov ax, dx - shr dx, 1 - add dx, ax - inc dx - ; map second byte - call _fat1 - pop ax - ; write higher 8 bits - mov [bx], ah - call dirty -l005: ret - - ; wrfat from above, FAT16 flavour -wf16: ret diff --git a/kernel/fcb.asm b/kernel/fcb.asm deleted file mode 100644 index e6764ae..0000000 --- a/kernel/fcb.asm +++ /dev/null @@ -1,59 +0,0 @@ -; FCB layout - -struc FCB - -FCBDRV resb 1 ; BYTE drive (0=default, 1=A:, 2=B:, ...) -FCBFN resb 11 ; 11 BYTES filename -FCBCLUS resw 1 ; DWORD current cluster -FCBRN resb 1 ; BYTE record in cluster - -endstruc - -FCBSIZ equ FCB_size - -section .data - -defdrv db 0 -dta dd 0 - -section .text - - ; auto-complete drive field in fcb - ; also logs in the drive - ; IN ds:dx far ptr FCB -fcbdrv push ds - push dx - mov si, dx - ; if currently zero, ... - mov dl, [si] ; 1-based - test dl, dl - jnz .log - ; replace with current drive - mov dl, [cs:defdrv] ; 0-based - inc dl - mov [si], dl ; 1-based -.log dec dl - mov ax, cs - mov ds, ax - call logdrv ; 0-based - pop dx - pop ds - ; if carry flag set, resume stack at bp - ; this instant-returns some higher level procs - jnc .ret - mov sp, bp - ; duplicate carry bit into all 8 AL bits - ; similar to SALC instruction -.ret sbb al, al - ret - - ; set disk transfer address - ; IN DS:DX dta ptr -setdta mov [cs:dta], dx - mov [cs:dta+2], ds - ret - - ; get disk transfer address - ; OUT ES:BX dta ptr -getdta les bx, [cs:dta] - ret diff --git a/kernel/main.asm b/kernel/main.asm deleted file mode 100644 index 19a325e..0000000 --- a/kernel/main.asm +++ /dev/null @@ -1,8 +0,0 @@ - org 0 - jmp init - -init: mov ax, 0x0e37 - int 0x10 - -hlt: hlt - jmp hlt diff --git a/kernel/printf.asm b/kernel/printf.asm deleted file mode 100644 index bda3f30..0000000 --- a/kernel/printf.asm +++ /dev/null @@ -1,66 +0,0 @@ -section .bss - -printr: -.ax: resw 1 -.cx: resw 1 -.dx: resw 1 -.bx: resw 1 - -section .text - -; Stack contents -; ret-addr arg1 arg2 arg3 ... - -printf: mov [printr.ax], ax - mov [printr.cx], cx - mov [printr.dx], dx - mov [printr.bx], bx - pop bx - -.loop: mov al, [cs:bx] - inc bx - - cmp al, 0 - je .end - cmp al, 2 - je .word - - call pputc - - jmp .loop - -.end: push bx - mov ax, [printr.ax] - mov cx, [printr.cx] - mov dx, [printr.dx] - mov bx, [printr.bx] - ret - -.word: pop dx - call pdx - jmp printf.loop - -pdx: ; this double-call is essentially a 4 times repeating loop - call .l1 -.l1: call .l2 -.l2: ; set up cl for bit shifts - mov cl, 4 - ; grab highest nibble from dx - mov al, dh - ; remove highest nibble from dx - shl dx, cl - ; shift away second-highest nibble that we accidentally copied - shr al, cl - ; map 0-9 to ascii codes for '0' to '9' - add al, 0x30 - ; if result is larger than '9', ... - cmp al, 0x3a - jl pputc - ; ... add 7 so we continue at 'A' - add al, 7 -pputc: push bx - mov ah, 0x0e - xor bx, bx - int 0x10 - pop bx - ret diff --git a/kernel/psp.asm b/kernel/psp.asm deleted file mode 100644 index 523979b..0000000 --- a/kernel/psp.asm +++ /dev/null @@ -1,62 +0,0 @@ -; Program segment prefix headers and constants - -section .bss - -curpsp: resw 1 - -absolute 0 - - resb 2 ; ret 0 exit - resb 2 ; next unusable segment -PSPDD: resb 1 ; BYTE default drive - ; CP/M entry point - resb 1 ; instruction byte - resw 1 ; usable length of segment (needs to be here for compata) - resb 4 ; opcodes to call us - - ; saved userdata -PSPAX: resw 1 -PSPCX: resw 1 - ; SS:SP -PSPSP: resw 1 -PSPSS: resw 1 - ; DS:DX -PSPDX: resw 1 -PSPDS: resw 1 - ; ES:BX -PSPBX: resw 1 -PSPES: resw 1 - -PSPDTA: resd 1 ; DWORD ptr to disk transfer area - -section .text - - ; set default drive for current process - ; IN dl drive number -setdd: push es - mov es, [curpsp] - mov [es:PSPDD], dl - pop es - ret - - ; get default drive for current process - ; OUT al drive number -getdd: push es - mov es, [curpsp] - mov al, [es:PSPDD] - pop es - ret - - ; set DTA ptr - ; IN es:bx far ptr -setdta: push ds - mov ds, [curpsp] - mov [PSPDTA], bx - mov [PSPDTA+2], es - pop ds - - ; get DTA ptr - ; OUT es:bx far ptr -getdta: mov es, [curpsp] - les bx, [es:PSPDTA] - ret diff --git a/kernel/rootdir.asm b/kernel/rootdir.asm deleted file mode 100644 index 4432b04..0000000 --- a/kernel/rootdir.asm +++ /dev/null @@ -1,113 +0,0 @@ - ; Load root directory entry into buffer - ; IN ax number of directory entry - ; OUT cs:di ptr to directory entry -lddir push ax - push ax - call rstseg - pop ax - mov cl, 4 - shr ax, cl - xor dx, dx - ; dx:ax = sector number in rootdir - ; add sizes of FAT tables - xor ch, ch - mov cl, byte [bpb+BPBFN] -.loop: add ax, [bpb+BPBFS] - adc dx, 0 - loop .loop - ; add reserved sector count - add ax, [bpb+BPBRSC] - adc dx, 0 - ; fetch sector (relative to partition) - call maprel - ; get di to point to entry - pop di - mov cl, 5 - shl di, cl - and di, 0x1FF - add di, dskbuf - ret - - ; find first matching file - ; IN DS:DX input fcb -fndfst mov bp, sp - call fcbdrv - ; set search state to zero - les di, [cs:dta] - xor ax, ax - mov [es:di+FCBSIZ], ax - ; find next matching file - ; state is kept in DTA -fndnxt mov bp, sp - call fcbdrv - ; get next direntry to fetch - ; get number of current entry from DTA -.loop les di, [cs:dta] - mov ax, [es:di+FCBSIZ] - inc word [es:di+FCBSIZ] - ; bail out if we are at end of dir - cmp ax, [cs:bpb+BPBRDE] - jnc .err - ; load entry and first byte - push ds - push dx - call lddir - pop dx - pop ds - ; next if hidden, dir or vol label - test byte [cs:di+0x0B], 0xDA - jnz .loop - ; bail out if end of dir - mov al, [cs:di] - cmp al, 0 - je .err - ; next if deleted entry - cmp al, 0xE5 - je .loop - ; DS:SI := FCB+1 - ; ES:DI := CS:dirent - mov si, dx - push si - inc si - mov ax, cs - mov es, ax - ; compare and ; try next if mismatch - mov cx, 11 - push di - rep cmpsb - pop di - pop si - jne .loop - ; create FCB in DTA - call getdta - xchg bx, di - ; copy over drive byte - movsb - ; copy filename - push ds - push si - mov ax, cs - mov ds, ax - mov si, bx - mov cx, 11 - rep movsb - pop si - pop ds - ; done! - xor ax, ax - ret - -.err: stc -.ret: sbb al, al - ret - -open call fndfst - test al, al - jnz .ret - ; read start cluster - mov ax, [cs:bx+0x1A] - mov bx, dx - mov [ds:bx+FCBCLUS], ax - ; reset record number - mov byte [ds:bx+FCBRN], 0 -.ret ret diff --git a/kernel/syscall.asm b/kernel/syscall.asm deleted file mode 100644 index ec8555b..0000000 --- a/kernel/syscall.asm +++ /dev/null @@ -1,102 +0,0 @@ -; This is the syscall gateway: -; - backs up the data from user space (kernel funcs trash many regs) -; - sets up the kernel stack -; - calls kernel funcs -; - exports a specified set of registers back to userspace -; -; The syscall table acts as a "export"-list for kernel near funcs. -; Kernel code can expect CS = DS - -section .rodata - -stab: ; syscall table - ; cells: ptr to handler, ptr to sysret - ; 0-7 - dw restart, sret - dw getc, sretb - dw putc, sret - dw err, sret ; reader input - dw err, sret ; punch outout - dw err, sret ; list output - dw conio, sret ; direct console i/o - dw err, sret - ; 8-f - dw err, sret - dw err, sret ; print string - dw err, sret ; read into buffer - dw err, sret ; console status - dw err, sret ; return version num - dw err, sret ; reset disks - dw setdd, sret ; select disk - dw open, sretb ; open file -.end: - -section .text - -; WARNING: BP, SI and DI are not saved -; If kernel code uses them, they need to be saved to the stack -int21: push ds - ; load program PSP and save userdata - mov ds, [cs:curpsp] - pop word [PSPDS] - mov [PSPES], es - - mov [PSPAX], ax - mov [PSPCX], cx - mov [PSPDX], dx - mov [PSPBX], bx - - mov [PSPSS], ss - mov [PSPSP], sp - - xor bx, bx - mov ss, bx - mov sp, stack - ; get ptr into syscall table - mov bl, [PSPAX+1] ; bh is still 0 - shl bx, 1 - shl bx, 1 - add bx, stab - ; load sysret and handler ptr - push word [cs:bx+2] - push word [cs:bx] - ; DS is always our segment - push cs - pop ds - ; ES:BX is syscall argument - mov bx, [PSPDX] - mov es, [PSPDS] - ret - -err: mov ah, 0xFF - ret - - ; sysret handlers - ; return ES:BX to user -sretd: mov ds, [cs:curpsp] - jmp sret.l02 - - ; return BX to user -sretw: mov ds, [cs:curpsp] - mov es, [PSPES] - jmp sret.l02 - - ; return carry flag in AL -sretc: mov ds, [cs:curpsp] - sbb al, al - - ; return AL to user -sretb: mov ds, [cs:curpsp] - mov ah, [PSPAX+1] - les bx, [PSPBX] - jmp sret.l03 - - ; return without result -sret: mov ds, [cs:curpsp] - les bx, [PSPBX] -.l02: mov ax, [PSPAX] -.l03: mov ss, [PSPSS] - mov sp, [PSPSP] - mov cx, [PSPCX] - lds dx, [PSPDX] ; DS last - iret