chore: work on VFS (wip)

Refs: #24
This commit is contained in:
d0p1 🏳️‍⚧️ 2024-07-16 08:29:16 +02:00
parent 7fec5d45f6
commit 18c807d210
10 changed files with 284 additions and 19 deletions

View file

@ -17,7 +17,11 @@ SRCS = kernel.asm \
dev/at/pit.inc \
dev/at/cga.inc \
dev/at/kbd.inc \
dev/at/floppy.inc
dev/at/floppy.inc \
fs/fat.inc \
fs/stpdfs.inc \
fs/xv6fs.inc \
vfs.inc
.PHONY: all
all: $(KERNEL)

View file

@ -1,13 +1,58 @@
;; File: cmos.inc
;;
;; > +--------------------------------
;; > | 0x00 | RTC seconds
;; > +---------------
;; > | 0x01 | RTC seconds alarm
;; > +--------------------
;; > | 0x02 | RTC minutes
;; > +------------------------
;; > +------+-------------------------+
;; > | 0x00 | RTC seconds |
;; > +------+-------------------------+
;; > | 0x01 | RTC seconds alarm |
;; > +------+-------------------------+
;; > | 0x02 | RTC minutes |
;; > +------+-------------------------+
;; > | 0x03 | RTC minutes alarm |
;; > +------+-------------------------+
;; > | 0x04 | RTC hours |
;; > +------+-------------------------+
;; > | 0x05 | RTC hours alarm |
;; > +------+-------------------------+
;; > | 0x06 | RTC day of week |
;; > +------+-------------------------+
;; > | 0x07 | RTC date day |
;; > +------+-------------------------+
;; > | 0x08 | RTC date month |
;; > +------+-------------------------+
;; > | 0x09 | RTC date year |
;; > +------+-------------------------+
;; > | 0x0A | Status register A |
;; > +------+-------------------------+
;; > | 0x0B | Status register B |
;; > +------+-------------------------+
;; > | 0x0C | Status register C |
;; > +------+-------------------------+
;; > | 0x0D | Status register D |
;; > +------+-------------------------+
;; > | 0x0E | Diagnostic Status |
;; > +------+-------------------------+
;; > | 0x0F | CMOS Shutdown Status |
;; > +------+-------------------------+
;; > | 0x10 | Floppy Disk Drive Type |
;; > +------+-------------------------+
;; > | 0x11 | System Conf Settings |
;; > +------+-------------------------+
;; > | 0x12 | Hard Disk Type |
;; > +------+-------------------------+
;; > | 0x13 | Typematic Parameters |
;; > +------+-------------------------+
;; > | 0x14 | Installed Equipment |
;; > +------+-------------------------+
;; > | 0x15 | Base Memory LO |
;; > +------+-------------------------+
;; > | 0x16 | Base Memory HI |
;; > +------+-------------------------+
;; > | 0x17 | Extended Memory LO |
;; > +------+-------------------------+
;; > | 0x18 | Extended Memory HI |
;; > +------+-------------------------+
;; > | 0x19 | Hard Disk Extended Type |
;; > +------+-------------------------+
CMOS_COMMAND = 0x70
CMOS_DATA = 0x71

View file

@ -18,4 +18,7 @@ console_read:
call lock_release
ret
console_init:
ret
uConsoleLock dd 0

View file

@ -6,3 +6,5 @@ struc Device {
.probe dd ?
}
dev_init:
ret

View file

@ -1,9 +1,73 @@
;; File: fat.inc
;;
;; Usefull links:
;; - <Spec at https://academy.cba.mit.edu/classes/networking_communications/SD/FAT.pdf>
FAT_SECTOR_SIZE = 512
FAT_MDIR_SIZE = 32
struc FatBootSector {
.jump db 3 dup(?)
.banner db 8 dup(?)
struc FATFS_BootSectorBase {
.jump db 3 dup(?)
.oemName db 8 dup(?)
.byts_per_sec dw ?
.sec_per_clus db ?
.rsvd_sec_cnt dw ?
.num_fats db ?
.root_ent_cnt dw ?
.tot_sec16 dw ?
.media db ?
.fat_sz16 dw ?
.sec_per_trk dw ?
.num_heads dw ?
.hidd_sec dd ?
.tot_sec32 dd ?
}
struc FATFS_BootSector16 {
.base FATFS_BootSectorBase
;; Extended BPB Structure
.drv_num db ?
.reserved1 db 0
.boot_sig db ?
.volume_id dd ?
.volume_label db 11 dup(?)
.filsys_type db 8 dup(?)
.code db 448 dup(?)
.signature dw ?
}
struc FATFS_BootSector32 {
.base FATFS_BootSectorBase
.fat_sz32 dd ?
.ext_flags dw ?
.fs_ver dw ?
.root_clus dd ?
.fs_info dw ?
.bk_boot_sec dw ?
.reserved0 db 12 dup(?)
.drv_num db ?
.reserved1 db ?
.boot_sig db ?
.volume_id dd ?
.volume_label db 11 dup(?)
.filsys_type db 8 dup(?)
.code db 420 dup(?)
.signature dw ?
}
szVfsFatName db 'FATFS', 0
vfs_fatfs:
dd szVfsFatName
dd 0
dd vops_fatfs
vops_fatfs:
dd 0
fatfs_init:
mov eax, vfs_fatfs
call vfs_register
ret

View file

@ -1,5 +1,51 @@
;; File: stpdfs.inc
STPDFS_SB_MAGIC = 0x44505453
STPDFS_SB_REV = 1
STPDFS_SB_REV = 1
STPDFS_BSIZE = 512
STPDFS_ROOTINO = 1
STPDFS_NDIRECT = 7
STPDFS_CLEANLY_UNMOUNTED = 0
STPDFS_ERROR = 1
STPDFS_DIRTY = 1
struc StpdFS_Sb {
.magic dd ?
.isize dd ?
.fsize dd ?
.free dd 100 dup(?)
.nfree db ?
.rev db ?
.state dw ?
.time dq ?
}
DEFN StpdFS_Sb
struc StpdFS_Inode {
.mode dw ?
.nlink dw ?
.uid dw ?
.gid dw ?
.flags dw ?
.size dd ?
.zones dd (STPDFS_NDIRECT + 3) dup(?)
.actime dq ?
.modtime dq ?
}
DEFN StpdFS_Inode
szVfsStpdFSName db 'StupidFS', 0
vops_stpdfs:
dd 0
vfs_stpdfs:
dd szVfsStpdFSName
dd 0
dd vops_stpdfs
stpdfs_init:
mov eax, vfs_stpdfs
call vfs_register
ret

57
kernel/fs/xv6fs.inc Normal file
View file

@ -0,0 +1,57 @@
;; File: xv6fs.inc
;;
;; Usefull links:
;; - <https://github.com/mit-pdos/xv6-riscv/blob/riscv/kernel/fs.h>
;; - <xv6 book at https://pdos.csail.mit.edu/6.1810/2023/xv6/book-riscv-rev3.pdf>
XV6FS_BSIZE = 1024
XV6FS_ROOTINO = 1
XV6FS_MAGIC = 0x10203040
XV6FS_NDIRECT = 12
XV6FS_NINDIRECT = (XV6FS_BSIZE / 4)
XV6FS_MAXFILE = (XV6FS_NDIRECT + XV6FS_NINDIRECT)
XV6FS_IPB = (XV6FS_BSIZE / 64)
XV6FS_DIRSIZE = 14
struc Xv6FS_Sb {
.magic dd ?
.size dd ?
.nblock dd ?
.ninodes dd ?
.nlog dd ?
.nlogstart dd ?
.inodestart dd ?
.bmapstart dd ?
}
DEFN Xv6FS_Sb
struc Xv6FS_Inode {
.type dw ?
.major dw ?
.minor dw ?
.nlink dw ?
.size dd ?
.addrs dd (XV6FS_NDIRECT + 1) dup(?)
}
DEFN Xv6FS_Inode
struc Xv6FS_Dirent {
.inum dw ?
.name db XV6FS_DIRSIZE dup(?)
}
szVfsXv6FSName db 'xv6FS', 0
vops_xv6fs:
dd 0
vfs_xv6fs:
dd szVfsXv6FSName
dd 0
dd vops_xv6fs
xv6fs_init:
mov eax, vfs_xv6fs
call vfs_register
ret

View file

@ -2,6 +2,7 @@
format binary
include 'const.inc'
include 'sys/macro.inc'
include 'sys/bootinfo.inc'
include 'sys/cpu.inc'
@ -64,6 +65,8 @@ kmain:
call pit_init
call vfs_init
mov eax, SYSCALL_EXIT
int 0x42
@ -81,6 +84,11 @@ kmain:
call klog
jmp .halt
include 'dev/at/cmos.inc'
include 'dev/at/pit.inc'
include 'dev/at/kbd.inc'
include 'dev/at/cga.inc'
include 'dev/at/floppy.inc'
include 'klog.inc'
include 'dev/console.inc'
include 'mm/mm.inc'
@ -90,10 +98,10 @@ kmain:
include 'isr.inc'
include 'idt.inc'
include 'pic.inc'
include 'dev/at/pit.inc'
include 'dev/at/kbd.inc'
include 'dev/at/cga.inc'
include 'dev/at/floppy.inc'
include 'vfs.inc'
include 'fs/fat.inc'
include 'fs/stpdfs.inc'
include 'fs/xv6fs.inc'
szMsgKernelAlive db "Kernel (", VERSION_FULL , ") is alive", 0

6
kernel/sys/macro.inc Normal file
View file

@ -0,0 +1,6 @@
macro DEFN x {
virtual at 0
x x
sizeof.#x:
end virtual
}

View file

@ -5,6 +5,13 @@
;;
struc VFS {
.name dd ?
.next dd ?
.op dd ?
}
DEFN VFS
struc Mount {
.next dd ?
.op dd ?
.vnodes dd ?
@ -23,6 +30,7 @@ struc VFSOps {
.vget dd ?
}
;;
VNODE_TYPE_NON = 0x0
VNODE_TYPE_REG = 0x1
VNODE_TYPE_DIR = 0x2
@ -32,6 +40,7 @@ VNODE_TYPE_LNK = 0x5
VNODE_TYPE_SOCK = 0x6
VNODE_TYPE_BAD = 0x7
;; Struc: VNode
struc VNode {
.flag dw ?
.refcount dw ?
@ -72,8 +81,29 @@ struc VNodeOps {
.brelse dd ?
}
vfs_init:
;; Function: vfs_register
;;
;; In:
;; EAX - Pointer to VFS struct
;;
vfs_register:
mov edx, [pVFS]
mov [eax + VFS.next], edx
mov [pVFS], eax
mov eax, [eax + VFS.name]
push eax
mov esi, szMsgVFSRegister
call klog
ret
vfs_init:
call fatfs_init
call stpdfs_init
call xv6fs_init
ret
pVFS dd 0
pRootFS dd 0
szMsgVFSRegister db 'VFS: register %s', 0