From 4e779c5a22650eb01f2a7c6d90c69a0c278e6f73 Mon Sep 17 00:00:00 2001 From: Nero <41307858+nero@users.noreply.github.com> Date: Sun, 11 Oct 2020 21:33:01 +0000 Subject: [PATCH] Lay out skeletons for FCB handling --- Makefile | 5 +- boot/fat.asm | 3 + boot/kernel.asm | 10 ++- kernel/drive.asm | 167 +++++++---------------------------------------- kernel/fcb.asm | 55 ++++++++++++++++ 5 files changed, 93 insertions(+), 147 deletions(-) create mode 100644 kernel/fcb.asm diff --git a/Makefile b/Makefile index 8ef9ee4..f114152 100644 --- a/Makefile +++ b/Makefile @@ -6,10 +6,11 @@ QEMU = qemu-system-i386 QEMU_ARGS = $(addprefix --option-rom ,$(ROMS)) VERSION = $(shell git log -1 --format=%cd --date=format:%Y%m%d) -LABEL = RDOS $(VERSION) +PRODUCT = rdos +LABEL = $(PRODUCT) $(VERSION) NASM = nasm -NASM_ARGS = -s -Ilib -DVERSION=$(VERSION) +NASM_ARGS = -s -Ilib -DPRODUCT=$(PRODUCT) -DVERSION=$(VERSION) KVM = $(shell test -w /dev/kvm && echo 1) diff --git a/boot/fat.asm b/boot/fat.asm index 96e1317..5a71de7 100644 --- a/boot/fat.asm +++ b/boot/fat.asm @@ -14,6 +14,9 @@ bootsect: equ 0x7C00 ; our origin before reloc %include "inc/bpb.asm" + %define V 0x %+ VERSION + dd V, V + times ( 0x0B - ($-$$) ) db 0 params: times bpb_size db 0 diff --git a/boot/kernel.asm b/boot/kernel.asm index a430c74..7ea98a5 100644 --- a/boot/kernel.asm +++ b/boot/kernel.asm @@ -22,12 +22,18 @@ print_banner: mov si, banner cmp al, 0x0D jnz .loop + call dskrst + + mov dl, 0 + call dsksel + hlt: hlt jmp hlt -banner: db "rdos kernel", 0x0A, 0x0D +%defstr VERSIONSTR VERSION +banner: db "RDOS ", VERSIONSTR, 0x0A, 0x0D -end: align 512 +%include "kernel/drive.asm" section .bss diff --git a/kernel/drive.asm b/kernel/drive.asm index 8c3e66f..1ee0729 100644 --- a/kernel/drive.asm +++ b/kernel/drive.asm @@ -1,159 +1,40 @@ section .bss -drives: equ 16 - - ; ptr into currently selected drive -drive_ptr: resw 1 - -drive_table: resb (drives * drive_size) - - ; DX and CX for int 13 CHS access -chs_dx: resw 1 -chs_cx: resw 1 + ; drive selected for I/O +dsknum: resb 1 + ; current sector number +dskseek: resd 1 ; disk buffer for I/O operations -diskbuf: resb 1024 +dskbuf: resb 512 section .text -drives_init: ; CX = number of floppy drives in the system - int 0x11 - mov cl, 6 - shr ax, cl - inc ax - and ax, 3 - mov cx, ax - - mov bx, drive_table - xor dx, dx - -.loop: push cx - push dx - mov [bx+drive.biosnum], dl - mov byte [bx+drive.flag], 1 ; 1 = drive letter used - ; query bios for floppy format - mov ah, 8 - push bx - int 0x13 - pop bx - ; set up defaults if invalid data or fail - jc .defs - test cx, cx - jnz .load -.defs: ; use defaults: 360k, 40 cyl, 9 sects - les di, [0x1e * 4] - mov cx, 0x270 - mov dh, 1 -.load: ; copy dpt - push es - push ds - pop es - pop ds - push cx - mov si, di - lea di, [bx+drive.dpt] - mov cx, 11 - rep movsb - pop cx - ; restore ds - push cs - pop ds - ; get and save number of cylinders - mov ax, cx - xchg al, ah - rol ah, 1 - rol ah, 1 - and ax, 0x03FF - inc ax - mov [bx+drive.cylinders], ax - ; save spt - mov ax, cx - and al, 0x3F - mov [bx+drive.dpt+dpt.lastsector], al - ; multiply with heads and save sectors per cylinder - inc dh - mul dh ; ax = al * dh - mov [bx+drive.spc], ax - ; advance loop - pop dx - pop cx - inc dl - add bx, drive_size - loop .loop - ret +ret: ret ; select drive ; IN dl drive number -drive_select: xor dh, dh - mov ax, drive_size - mul dx - add ax, drive_table - mov word [drive_ptr], ax - ret - - ; reset currently selected drive -drive_reset: mov bx, [drive_ptr] - mov dl, [bx+drive.biosnum] - ; our ptr = CX:BX - lea bx, [bx+drive.dpt] - mov cx, ds - ; toggle in our ptr - mov si, [0x1E*4] - xchg bx, [si] - xchg cx, [si+2] - ; do the call - xor ax, ax - int 0x13 - pushf - ; restore original ptr - xchg bx, [si] - xchg cx, [si+2] - ; pass int 13 flags - popf - ret - - ; query status of selected drive - ; OUT ah -drive_status: mov bx, [drive_ptr] - mov dl, [bx+drive.biosnum] - mov ah, 1 - int 0x13 - ret - - ; set sector for read/write operation - ; IN dx:ax 32-bit sector number -drive_seek: mov bx, [drive_ptr] - div word [bx+drive.spc] - xchg ax, dx - ; dx = cylinder, ax = head * spt + sector - div byte [bx+drive.dpt+dpt.lastsector] - ; dx = cylinder, al = head, ah = sector - xchg dl, dh +dsksel: cmp dl, 1 + jnc ret + mov al, dl + and al, 0x02 ror dl, 1 ror dl, 1 - or dl, ah - inc dx - ; al: head number - ; dh bit 0-7: cylinder bits 0-7 - ; dl bit 0-5: sector bits 0-5 - ; dl bit 6-7: cylinder bits 8-9 - xchg al, ah - mov al, [bx+drive.biosnum] - ; store - mov word [chs_dx], ax - mov word [chs_cx], dx + cmp dl, byte [dsknum] + je ret + + call dskrst + + int 3 + ret -drive_read: mov ax, 0x0201 - mov cx, [chs_cx] - mov dx, [chs_dx] - mov bx, diskbuf - int 0x13 +dskrst: call flush + mov ax, 0xFFFF + mov [dsknum], al + mov [dskseek], ax + mov [dskseek+2], ax ret -drive_write: mov ax, 0x0301 - mov cx, [chs_cx] - mov dx, [chs_dx] - mov bx, diskbuf - int 0x13 - ret + ; flush buffer if dirty +flush: ret diff --git a/kernel/fcb.asm b/kernel/fcb.asm new file mode 100644 index 0000000..bcec2df --- /dev/null +++ b/kernel/fcb.asm @@ -0,0 +1,55 @@ +; in FCB required +; word offset in rootdir +; used for search +; word current cluster +; byte record num in cluster + + ; FCB open +fcbopn: ; call fcbfst + ; copy match + ; store cluster number in fcb + ; record = 0 + ret + + ; FCB close +fcbcls: ; flush disk buffer + ret + + ; FCB find first +fcbfst: ; init search state in FCB + ; jmp to fcbnxt + ret + + ; FCB find next +fcbnxt: ; load rootdir sector from state + ; search until next match + ; next sec & loop if mismatch + ; err exit if no further matches + ret + + ; FCB delete file +fcbdel: ; call fcbfst + ; get search state, load root dir from there + ; mark file as deleted + ret + + ; FCB read + ; read sector from cluster into diskbuf +fcbrd: ; read record from sector + ; advance record num, carry over to cluster + ret + + ; FCB write +fcbwr: ; read sector from cluster into diskbuf + ; write record into sector + ; mark buffer dirty + ; advance record num, carry over to cluster + ret + + ; FCB create +fcbcre: + ret + + ; FCB rename +fcbren: + ret