commit whatever is in my worktree rn

This commit is contained in:
Nero 2021-12-10 10:41:02 +00:00
parent 1dea0c40bc
commit a3ef693059
5 changed files with 211 additions and 197 deletions

View File

@ -7,11 +7,8 @@ banner: db "RDOS KERNEL ", V, 0x0A, 0x0D, '$', 0x1A
%include "kernel/far.asm" %include "kernel/far.asm"
%include "kernel/char.asm" %include "kernel/char.asm"
%include "inc/bpb.asm"
%include "kernel/drive.asm" %include "kernel/drive.asm"
%include "kernel/fcb.asm" %include "kernel/fat.asm"
%include "kernel/rootdir.asm"
%include "kernel/cluster.asm"
section .text section .text
@ -21,32 +18,15 @@ init: call rstseg
mov dx, banner mov dx, banner
call puts call puts
call rstseg mov dl, 0
mov dx, testdta call select
push ds
call norm
call setdta
pop ds
mov dx, testfcb mov dx, 3
call norm call setclus
call rdfat
call open mov dx, bx
inc dx
call read call wdfat
mov ax, [cs:testdta]
mov cx, [cs:testdta+2]
int 3
hlt: hlt hlt: hlt
jmp hlt jmp hlt
section .data
testfcb db 0, "HELLO ","COM"
times FCBSIZ db 0
section .bss
testdta resb 128

View File

@ -43,10 +43,6 @@ dmpdx3: int 0x10
free dw 0 ; free ram size free dw 0 ; free ram size
lncnt dw 0 ; line count lncnt dw 0 ; line count
rdptr dw 0xFFFF ; infile blk ptr rdptr dw 0xFFFF ; infile blk ptr
symbol dw 0 ; symbol of current line
offset dw 0 ; byte offset in outfile
len db 0 ; len for wrd (must be before it)
wrd dw 0,0,0,0,0,0,0,0 ; 16 byte word buf
getc mov bx, [rdptr] getc mov bx, [rdptr]
cmp bx, 0x80 cmp bx, 0x80
@ -72,12 +68,6 @@ l02 mov al, 0x1A
l03 cmp al, eof l03 cmp al, eof
ret ret
;getc2 call peek
; cmp al, eof
; jne getc_
; inc word [rdptr]
;getc_ ret
newlin mov dl, 0x0A newlin mov dl, 0x0A
mov ah, 2 mov ah, 2
int 0x21 int 0x21
@ -99,145 +89,32 @@ error mov dl, [bx]
e_eof db "EOF " e_eof db "EOF "
e_dup db "DUPSYM " e_dup db "DUPSYM "
; scan word tok1:
scawrd mov si, wrd s_ws db " " ; also used for tabs
l04 call getc s_com db ","
; EOF is fatal s_obr db "["
mov bx, e_eof s_cbr db "]"
jz error s_plu db "+"
; tab=end s_min db "-"
cmp al, 9
je pad
; space=end
cmp al, 0x20
je pad
; if lbl full, continue eating
cmp si, wrd+0x10
jnc l04
; insert
mov [si], al
inc si
jmp l04
; pad with spaces
pad mov cx, si
sub cx, wrd
mov [len], cl
cmp si, wrd+0x10
jnc l06
mov ah, 0x20
xchg ah, [si]
inc si
cmp ah, 0x20
jne pad
l06 ret
; print wrd align 2
dmpwrd mov si, wrd tok2:
mov cx, 0x10 reg8 db "AL","CL","DL","BL","AH","CH","DH","BH"
mov ah, 2 reg16 db "AX","CX","DX","BX","SP","BP","SI","DI"
l05 mov dl, [si] sreg db "ES","CS","SS","DS"
cmp dl, 0x20 s_db db "DB"
je l07 s_dw db "DW"
inc si
int 0x21
loop l05
l07 call newlin
ret
; create symbol table entry tok3:
; name is read from [wrd] s_org db "ORG"
; offset is written to [symbol] s_equ db "EQU"
symins cmp byte [wrd], 0x20
je nosym
mov bx, init ; walk ptr
mov bp, [free]
add bp, bx ; end addr
jmp l09
l08 add bx, 8
l09 mov al, [bx]
cmp al, 0
je l10
call symcmp
jnz l08
mov bx, e_dup
jmp error
; copy str to table
l10 mov si, wrd
mov di, bx
movsw
movsw
movsw
xor ax, ax
stosw
mov byte [bx+8], 0
mov [symbol], bx
ret
nosym xor ax, ax ; TODO: parse a line into wordlist of tokens and ptrs to strings
mov [symbol], ax rline: ret
ret
; compares 6 bytes [bx] with [wrd]
; bit 7 of each byte is ignored
symcmp mov si, wrd
xor ax, ax
mov dx, [wrd]
xor dx, [bx]
or ax, dx
mov dx, [wrd+2]
xor dx, [bx+2]
or ax, dx
mov dx, [wrd+4]
xor dx, [bx+4]
or ax, dx
test ax, 0x8F8F
ret
; look up keyword in wrd
; result is stored in bx
lookup mov ch, 0
mov bx, s_org
l11 mov si, bx
mov di, len ; wrd immediately follows
mov cl, [bx]
test cx, cx
jz l13
inc cl
mov dx, cx
rep cmpsb
je l12
add bx, dx
jmp l11
; found!
l12 clc
ret
; give up
l13 xor bx, bx
stc
ret
s_org db 3, "org"
s_equ db 3, "equ"
db 0
; clear symbol table ; clear symbol table
main mov byte [init], 0 main mov byte [init], 0
; scan and create label call rline
mloop call scawrd
call symins
; scan instruction word
call scawrd
call lookup
; special stuff
cmp bx, s_org
je iorg
mov ax, bx
call dumpax
int 0x20
; org pseudo instruction
iorg mov ax, 0x5A5A
call dumpax
int 0x20 int 0x20
align 16 align 16

View File

@ -5,6 +5,34 @@
; - dirty: inform that dskbuf has been written to ; - dirty: inform that dskbuf has been written to
; access is done by accessing dskbuf directly ; access is done by accessing dskbuf directly
BPBOFF equ 0xB
; DOS 2.0 BPB
BPBSS equ 0 ; word
BPBSC equ 2 ; byte
BPBRSC equ 3 ; word
BPBFN equ 5 ; byte
BPBRDE equ 6 ; word
BPBTS equ 8 ; word
BPBMD equ 10 ; byte
BPBFS equ 11 ; word
BPBSIZ2 equ 13 ; size constant
; DOS 3.31 BPB
BPBSPT equ 0x0D ; word
BPBNOS equ 0x0F ; word
BPBHS equ 0x11 ; dword
BPBLTS equ 0x15 ; dword
BPBSIZ3 equ 25 ; size constant
; DOS 3.4 EBPB
BPBDN equ 0x19 ; byte
BPBFALG equ 0x1A ; byte
BPBSIG equ 0x1B ; byte
BPBSER equ 0x1C ; dword serial number
BPBSIZ4 equ 32 ; size constant
; Disk parameter table (int 1E)
DPTSIZE equ 11 DPTSIZE equ 11
DPTSPT equ 4 DPTSPT equ 4
@ -94,10 +122,10 @@ getprm test byte [dskflag], 4
call lodfar call lodfar
.ret ret .ret ret
; log in drive ; select a drive for io
; IN dl drive number ; IN dl drive number
; dont do anything if drive already selected ; dont do anything if drive already selected
logdrv cmp dl, [dsknum] select cmp dl, [dsknum]
je logfdd.ret je logfdd.ret
; clear out current contents ; clear out current contents
push dx push dx
@ -191,35 +219,42 @@ loghdd sub dl, 2
logerr stc logerr stc
ret ret
; count from partition start ; map sector into dskbuf
; sector number from partition start
; IN dx:ax sector number ; IN dx:ax sector number
maprel add ax, [bpb+BPBHS] map add ax, [bpb+BPBHS]
add dx, [bpb+BPBHS+2] add dx, [bpb+BPBHS+2]
; absolute sector count ; absolute sector count
; skip doing a read if sector number matches ; skip doing a read if sector number matches
; IN dx:ax sector number ; IN dx:ax sector number
mapabs cmp ax, [dskseek] mapabs cmp ax, [dskseek]
jne dskread jne l003
cmp dx, [dskseek+2] cmp dx, [dskseek+2]
jne dskread je l002
ret ; flush and read other sector
l003 push ax
dskread push ax
push dx push dx
call flush call flush
pop dx pop dx
pop ax pop ax
; store the sector number ; store the sector number
mov [cs:dskseek], ax mov [dskseek], ax
mov [cs:dskseek+2], dx mov [dskseek+2], dx
; do the actual read jmp _read
; mark dskbuf as containing unwritten changes
dirty or byte [cs:dskflag], 1 ; dirty
l002 ret
; flush buffer if dirty
flush test byte [cs:dskflag], 1
jz l002
; low level read and write ; low level read and write
; call again to retry, no input registers ; call again to retry, no input registers
; read or write is configured in cx ; read or write is configured in cx
_read mov ch, 2
db 0x3D ; cmp ax, imm16: causes next instr to be skipped
_write mov ch, 3 _write mov ch, 3
db 0x3D ; cmp ax, imm16: causes next 2 bytes to be skipped
_read mov ch, 2
mov cl, 1 ; read len mov cl, 1 ; read len
; DS := ES := CS ; DS := ES := CS
mov ax, cs mov ax, cs
@ -286,14 +321,3 @@ _write mov ch, 3
; exit with carry flag set ; exit with carry flag set
stc stc
ret ret
; mark dskbuf as containing unwritten changes
dirty or byte [cs:dskflag], 1 ; dirty
ret
; flush buffer if dirty
flush test byte [cs:dskflag], 1
jz .ret
; TODO: error handling & retries
jmp _write
.ret ret

125
kernel/fat.asm Normal file
View File

@ -0,0 +1,125 @@
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

8
kernel/main.asm Normal file
View File

@ -0,0 +1,8 @@
org 0
jmp init
init: mov ax, 0x0e37
int 0x10
hlt: hlt
jmp hlt