commit whatever is in my worktree rn
This commit is contained in:
parent
1dea0c40bc
commit
a3ef693059
5 changed files with 211 additions and 197 deletions
|
@ -5,6 +5,34 @@
|
|||
; - dirty: inform that dskbuf has been written to
|
||||
; 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
|
||||
DPTSPT equ 4
|
||||
|
||||
|
@ -94,10 +122,10 @@ getprm test byte [dskflag], 4
|
|||
call lodfar
|
||||
.ret ret
|
||||
|
||||
; log in drive
|
||||
; select a drive for io
|
||||
; IN dl drive number
|
||||
; dont do anything if drive already selected
|
||||
logdrv cmp dl, [dsknum]
|
||||
select cmp dl, [dsknum]
|
||||
je logfdd.ret
|
||||
; clear out current contents
|
||||
push dx
|
||||
|
@ -191,35 +219,42 @@ loghdd sub dl, 2
|
|||
logerr stc
|
||||
ret
|
||||
|
||||
; count from partition start
|
||||
; map sector into dskbuf
|
||||
; sector number from partition start
|
||||
; IN dx:ax sector number
|
||||
maprel add ax, [bpb+BPBHS]
|
||||
map add ax, [bpb+BPBHS]
|
||||
add dx, [bpb+BPBHS+2]
|
||||
; absolute sector count
|
||||
; skip doing a read if sector number matches
|
||||
; IN dx:ax sector number
|
||||
mapabs cmp ax, [dskseek]
|
||||
jne dskread
|
||||
jne l003
|
||||
cmp dx, [dskseek+2]
|
||||
jne dskread
|
||||
ret
|
||||
|
||||
dskread push ax
|
||||
je l002
|
||||
; flush and read other sector
|
||||
l003 push ax
|
||||
push dx
|
||||
call flush
|
||||
pop dx
|
||||
pop ax
|
||||
; store the sector number
|
||||
mov [cs:dskseek], ax
|
||||
mov [cs:dskseek+2], dx
|
||||
; do the actual read
|
||||
mov [dskseek], ax
|
||||
mov [dskseek+2], dx
|
||||
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
|
||||
; call again to retry, no input registers
|
||||
; 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
|
||||
db 0x3D ; cmp ax, imm16: causes next 2 bytes to be skipped
|
||||
_read mov ch, 2
|
||||
mov cl, 1 ; read len
|
||||
; DS := ES := CS
|
||||
mov ax, cs
|
||||
|
@ -286,14 +321,3 @@ _write mov ch, 3
|
|||
; exit with carry flag set
|
||||
stc
|
||||
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
125
kernel/fat.asm
Normal 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
8
kernel/main.asm
Normal file
|
@ -0,0 +1,8 @@
|
|||
org 0
|
||||
jmp init
|
||||
|
||||
init: mov ax, 0x0e37
|
||||
int 0x10
|
||||
|
||||
hlt: hlt
|
||||
jmp hlt
|
Loading…
Add table
Add a link
Reference in a new issue