feat(kernel): block device (WIP)

This commit is contained in:
d0p1 🏳️‍⚧️ 2024-09-11 15:52:55 +02:00
parent b43672d268
commit 75aac14a44
5 changed files with 164 additions and 4 deletions

View file

@ -9,7 +9,9 @@
;; .refcount - refcount ;; .refcount - refcount
;; .data - block data ;; .data - block data
struc Buffer { struc Buffer {
.dev dd ? .dev dw ?
.flags db ?
.bcount db ?
.block dd ? .block dd ?
.ulock dd ? .ulock dd ?
.refcount dd ? .refcount dd ?
@ -17,6 +19,19 @@ struc Buffer {
} }
DEFN Buffer DEFN Buffer
;; Constants: Buffer flags
;;
;; BUFFER_WRITE - XXX
;; BUFFER_READ - XXX
;; BUFFER_ERROR - XXX
;; BUFFER_DIRTY - XXX
;; BUFFER_INVAL - mark buffer as invalid
BUFFER_WRITE = 0x0
BUFFER_READ = 0x1
BUFFER_ERROR = 0x2
BUFFER_DIRTY = 0x4
BUFFER_INVAL = 0x8
;; Function: bio_init ;; Function: bio_init
bio_init: bio_init:
mov ecx, sizeof.Buffer * 30 mov ecx, sizeof.Buffer * 30
@ -25,6 +40,11 @@ bio_init:
rep stosb rep stosb
ret ret
;; Function: bio_getblk
;;
bio_getblk:
ret
;; Function: bio_read ;; Function: bio_read
;; ;;
;; In: ;; In:
@ -46,6 +66,8 @@ bio_bread:
call klog call klog
jmp .end jmp .end
@@: @@:
xchg bx, bx
mov eax, aBuffers
mov ecx, [ecx] mov ecx, [ecx]
mov ecx, [ecx + BlkDev.strategy] mov ecx, [ecx + BlkDev.strategy]

View file

@ -23,6 +23,108 @@ TOTAL_SECTORS = 2880
FLOPPY_MAX = 2 FLOPPY_MAX = 2
;; Constants: Registers
;;
;; FLOPPY_STATUS_REGA - Read-only register
;; FLOPPY_STATUS_REGB - Read-only register
;; FLOPPY_DIGITAL_OUTPUT_REG - XXX
;; FLOPPY_TAPE_DRIVE_REG - XXX
;; FLOPPY_MAIN_STATUS_REG - Read-only register
;; FLOPPY_DATARATE_SELECT_REG - Write-only register
;; FLOPPY_DATA_FIFO - XXX
;; FLOPPY_DIGITAL_INPUT_REG - Read-only register
;; FLOPPY_CONF_CONTROL_REG - Write-only register
FLOPPY_STATUS_REGA = 0x3F0
FLOPPY_STATUS_REGB = 0x3F1
FLOPPY_DIGITAL_OUTPUT_REG = 0x3F2
FLOPPY_TAPE_DRIVE_REG = 0x3F3
FLOPPY_MAIN_STATUS_REG = 0x3F4
FLOPPY_DATARATE_SELECT_REG = 0x3F4
FLOPPY_DATA_FIFO = 0x3F5
FLOPPY_DIGITAL_INPUT_REG = 0x3F7
FLOPPY_CONF_CONTROL_REG = 0x3F7
;; Constants: Floppy commands
;;
;; FLOPPY_READ_TRACK - XXX
;; FLOPPY_SPECIFY - XXX
;; FLOPPY_SENSE_DRIVE_STATUS - XXX
;; FLOPPY_WRITE_DATA - XXX
;; FLOPPY_READ_DATA - XXX
;; FLOPPY_RECALIBRATE - XXX
;; FLOPPY_SENSE_INTERRUPT - XXX
;; FLOPPY_WRITE_DELETED_DATA - XXX
;; FLOPPY_READ_ID - XXX
;; FLOPPY_READ_DELETED_DATA - XXX
;; FLOPPY_FORMAT_TRACK - XXX
;; FLOPPY_DUMPREG - XXX
;; FLOPPY_SEEK - XXX
;; FLOPPY_VERSION - XXX
;; FLOPPY_SCAN_EQUAL - XXX
;; FLOPPY_PERPENDICULAR_MODE - XXX
;; FLOPPY_CONFIGURE - XXX
;; FLOPPY_LOCK - XXX
;; FLOPPY_VERIFY - XXX
;; FLOPPY_SCAN_LOW_OR_EQUAL - XXX
;; FLOPPY_SCAN_HIGH_OR_EQUAL - XXX
FLOPPY_READ_TRACK = 2
FLOPPY_SPECIFY = 3
FLOPPY_SENSE_DRIVE_STATUS = 4
FLOPPY_WRITE_DATA = 5
FLOPPY_READ_DATA = 6
FLOPPY_RECALIBRATE = 7
FLOPPY_SENSE_INTERRUPT = 8
FLOPPY_WRITE_DELETED_DATA = 9
FLOPPY_READ_ID = 10
FLOPPY_READ_DELETED_DATA = 12
FLOPPY_FORMAT_TRACK = 13
FLOPPY_DUMPREG = 14
FLOPPY_SEEK = 15
FLOPPY_VERSION = 16
FLOPPY_SCAN_EQUAL = 17
FLOPPY_PERPENDICULAR_MODE = 18
FLOPPY_CONFIGURE = 19
FLOPPY_LOCK = 20
FLOPPY_VERIFY = 22
FLOPPY_SCAN_LOW_OR_EQUAL = 25
FLOPPY_SCAN_HIGH_OR_EQUAL = 29
;; Constants: DOR bitflag
;;
;; FLOPPY_DOR_MOTD - Set to turn drive 3's motor ON
;; FLOPPY_DOR_MOTC - Set to turn drive 2's motor ON
;; FLOPPY_DOR_MOTB - Set to turn drive 1's motor ON
;; FLOPPY_DOR_MOTA - Set to turn drive 0's motor ON
;; FLOPPY_DOR_IRQ - Set to enable IRQs and DMA
;; FLOPPY_DOR_RESET - Reset on clear
;; FLOPPY_DOR_DSEL - Select drive
FLOPPY_DOR_MOTD = 0x80
FLOPPY_DOR_MOTC = 0x40
FLOPPY_DOR_MOTB = 0x20
FLOPPY_DOR_MOTA = 0x10
FLOPPY_DOR_IRQ = 0x08
FLOPPY_DOR_RESET = 0x04
FLOPPY_DOR_DSEL = 0x03
;; Constants: MSR bitflag
;;
;; FLOPPY_MSR_RQM - XXX
;; FLOPPY_MSR_DIO - XXX
;; FLOPPY_MSR_NDMA - XXX
;; FLOPPY_MSR_CB - XXX
;; FLOPPY_MSR_ACTD - XXX
;; FLOPPY_MSR_ACTC - XXX
;; FLOPPY_MSR_ACTB - XXX
;; FLOPPY_MSR_ACTA - XXX
FLOPPY_MSR_RQM = 0x80
FLOPPY_MSR_DIO = 0x40
FLOPPY_MSR_NDMA = 0x20
FLOPPY_MSR_CB = 0x10
FLOPPY_MSR_ACTD = 0x08
FLOPPY_MSR_ACTC = 0x04
FLOPPY_MSR_ACTB = 0x02
FLOPPY_MSR_ACTA = 0x01
;; Struct: Floppy ;; Struct: Floppy
;; ;;
;; .active - XXX ;; .active - XXX
@ -100,6 +202,22 @@ floppy_lba_to_chs:
;; In: ;; In:
;; EAX - Address of <Buffer> ;; EAX - Address of <Buffer>
floppy_strategy: floppy_strategy:
push ebp
mov esp, ebp
sub esp, 4
mov [ebp-4], eax
push esi
mov esi, szMsgFdStrat
push [eax+Buffer.block]
mov ax, [eax+Buffer.dev]
movzx ecx, al
push ecx
call klog
pop esi
leave
ret ret
;; Function: floppy_open ;; Function: floppy_open
@ -160,3 +278,4 @@ floppy_bdevsw:
szMsgFloppy0Found db "floppy: fd0 found", 0 szMsgFloppy0Found db "floppy: fd0 found", 0
szMsgFloppy1Found db "floppy: fd1 found", 0 szMsgFloppy1Found db "floppy: fd1 found", 0
szMsgFdStrat db "fd%u: strategy (blk: %u)", 0

View file

@ -72,6 +72,9 @@ DEFN Xv6FS_Inode
;; Struc: Xv6FS_Dirent ;; Struc: Xv6FS_Dirent
;; xv6FS directory entry ;; xv6FS directory entry
;;
;; .inum - inode number
;; .name - see <XV6FS_DIRSIZE>
struc Xv6FS_Dirent { struc Xv6FS_Dirent {
.inum dw ? .inum dw ?
.name db XV6FS_DIRSIZE dup(?) .name db XV6FS_DIRSIZE dup(?)

View file

@ -89,11 +89,18 @@ kmain:
call vfs_init call vfs_init
; Root inode
; rootino = newino(dev(0.0), BLK)
; fs_mountroot(rootino);
mov ah, 2 mov ah, 2
call bio_bread call bio_bread
mov eax, SYSCALL_EXIT xor eax, eax
int 0x42 call bio_bread
;mov eax, SYSCALL_EXIT
;int 0x42
;mov al, 'X' ;mov al, 'X'
;call cga_putc ;call cga_putc

View file

@ -30,7 +30,16 @@ struc VFSOps {
.vget dd ? .vget dd ?
} }
;; Constants: vnode types
;; ;;
;; VNODE_TYPE_NON - XXX
;; VNODE_TYPE_REG - XXX
;; VNODE_TYPE_DIR - XXX
;; VNODE_TYPE_BLK - XXX
;; VNODE_TYPE_CHR - XXX
;; VNODE_TYPE_LNK - XXX
;; VNODE_TYPE_SOCK - XXX
;; VNODE_TYPE_BAD - XXX
VNODE_TYPE_NON = 0x0 VNODE_TYPE_NON = 0x0
VNODE_TYPE_REG = 0x1 VNODE_TYPE_REG = 0x1
VNODE_TYPE_DIR = 0x2 VNODE_TYPE_DIR = 0x2