doc: document fatfs

This commit is contained in:
d0p1 🏳️‍⚧️ 2024-07-19 09:53:03 +02:00
parent 0ce1e73a09
commit 23e5bf0045
10 changed files with 146 additions and 20 deletions

View file

@ -1,4 +1,6 @@
INCS = coff.h elf.h INCS = coff.h elf.h
SYSINCS = sys/errno.h
INCSYSDIR = $(INCDIR)/sys
.PHONY: all .PHONY: all
all: all:
@ -7,8 +9,10 @@ all:
clean: clean:
.PHONY: install .PHONY: install
install: $(INCS) install: $(INCS) $(INCSYSDIR)
@ mkdir -p $(DESTDIR)$(INCDIR) @ mkdir -p $(DESTDIR)$(INCDIR)
install $< $(DESTDIR)$(INCDIR) install $(INCS) $(DESTDIR)$(INCDIR)
@ mkdir -p $(DESTDIR)$(INCSYSDIR)
install $(SYSINCS) $(DESTDIR)$(INCSYSDIR)
.PHONY: all clean install .PHONY: all clean install

View file

@ -2,6 +2,15 @@ AS = fasm
RM = rm -f RM = rm -f
INSTALL = install INSTALL = install
ASMINCS = sys/bootinfo.inc \
sys/coff.inc \
sys/cpu.inc \
sys/errno.inc \
sys/macro.inc \
sys/mmu.inc \
sys/process.inc \
sys/register.inc
KERNEL = vmstupid.sys KERNEL = vmstupid.sys
SRCS = kernel.asm \ SRCS = kernel.asm \
const.inc \ const.inc \
@ -23,7 +32,9 @@ SRCS = kernel.asm \
fs/fat.inc \ fs/fat.inc \
fs/stpdfs.inc \ fs/stpdfs.inc \
fs/xv6fs.inc \ fs/xv6fs.inc \
vfs.inc vfs.inc \
proc.inc \
$(ASMINCS)
.PHONY: all .PHONY: all
all: $(KERNEL) all: $(KERNEL)
@ -42,6 +53,8 @@ clean:
.PHONY: install .PHONY: install
install: $(KERNEL) install: $(KERNEL)
@ mkdir -p $(DESTDIR) @ mkdir -p $(DESTDIR)
install $< $(DESTDIR) install $(KERNEL) $(DESTDIR)
@ mkdir -p $(DESTDIR)$(ASMDIR)/sys
install $(ASMINCS) $(DESTDIR)$(ASMDIR)/sys
.PHONY: all clean install .PHONY: all clean install

View file

@ -40,3 +40,7 @@ com_irq2:
pusha pusha
popa popa
iret iret
com_device:
db 'com', 0, 0, 0, 0, 0
dd com_init

View file

@ -78,3 +78,7 @@ ne2k_probe:
ne2k_irq: ne2k_irq:
iret iret
ne2k_device:
db 'ne2k', 0, 0, 0, 0
dd ne2k_init

View file

@ -38,6 +38,8 @@ aDevices:
dd floppy_device dd floppy_device
dd kbd_device dd kbd_device
dd console_device dd console_device
dd com_device
dd ne2k_device
.end: .end:
dev_init: dev_init:

View file

@ -60,6 +60,12 @@ struc FATFS_BootSector32 {
} }
DEFN FATFS_BootSector32 DEFN FATFS_BootSector32
;; Struc: FATFS_Dirent
;; FAT Filesystem directory entry
;;
;; .name - Filename
;; .ext - File extension
;; .attr - See <FATFS file attributes>
struc FATFS_Dirent { struc FATFS_Dirent {
.name db 8 dup(?) .name db 8 dup(?)
.ext db 3 dup(?) .ext db 3 dup(?)
@ -77,6 +83,21 @@ struc FATFS_Dirent {
} }
DEFN FATFS_Dirent DEFN FATFS_Dirent
;; Enum: FATFS file attributes
;;
;; FATFS_ATTR_READ_ONLY - Mark file as read-only
;; FATFS_ATTR_HIDDEN - TODO
;; FATFS_ATTR_SYSTEM - TODO
;; FATFS_ATTR_VOLUME_ID - The corresponding entry contains the volume label.
;; FATFS_ATTR_DIRECTORY - The corresponding entry represents a directory
;; FATFS_ATTR_ARCHIVE - TODO
FATFS_ATTR_READ_ONLY = 0x01
FATFS_ATTR_HIDDEN = 0x02
FATFS_ATTR_SYSTEM = 0x04
FATFS_ATTR_VOLUME_ID = 0x08
FATFS_ATTR_DIRECTORY = 0x10
FATFS_ATTR_ARCHIVE = 0x20
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
;; Section: Implementation ;; Section: Implementation

View file

@ -1,4 +1,20 @@
;; File: heap.inc ;; File: heap.inc
;; Base on <https://github.com/CCareaga/heap_allocator/blob/master/commented_heap.c>
struc HeapNode {
.hole dd ?
.size dd ?
.next dd ?
.prev dd ?
}
DEFN HeapNode
struc HeapInfo {
.start dd ?
.end dd ?
.bins dd 9 dup(?)
}
DEFN HeapInfo
;; Function: heap_init ;; Function: heap_init
heap_init: heap_init:
@ -13,8 +29,23 @@ heap_init:
mov esi, szMsgHeapInit mov esi, szMsgHeapInit
call klog call klog
; TODO mov eax, [ebp-4]
mov ecx, KERNEL_VIRT_BASE
mov [ecx + HeapNode.hole], dword 1
sub eax, sizeof.HeapNode + 4
mov [ecx + HeapNode.size], eax
add eax, sizeof.HeapNode
add eax, ecx
mov [eax], ecx
mov ecx, KERNEL_VIRT_BASE
mov [kheap + HeapInfo.start], ecx
mov eax, [ebp-4]
add ecx, eax
mov [kheap + HeapInfo.end], ecx
.end:
leave leave
ret ret
@ -24,4 +55,36 @@ heap_alloc:
heap_free: heap_free:
ret ret
;; Function: heap_getbin
;;
;; In:
;; EAX - size
heap_getbin:
push ebp
mov ebp, esp
sub esp, 4
mov [ebp-4], dword 0
cmp eax, 4
jge @f
mov eax, 4
@@:
shr eax, 1
cmp eax, 1
or eax, eax
jz @f
inc dword [ebp-4]
jmp @b
@@:
mov eax, [ebp-4]
sub eax, 2
cmp eax, 8
jbe @f
mov eax, 8
@@:
leave
ret
kheap HeapInfo
szMsgHeapInit db "HEAP: initialize %x - %x", 0 szMsgHeapInit db "HEAP: initialize %x - %x", 0
szMsgErrorHeap db "ERROR: HEAP: not enough memory", 0

View file

@ -54,8 +54,8 @@ kmain:
add ebx, KERNEL_VIRT_BASE add ebx, KERNEL_VIRT_BASE
call pmm_free_range call pmm_free_range
mov eax, [boot_structure.low_mem] ;mov eax, [boot_structure.low_mem]
call heap_init ;call heap_init
call pic_init call pic_init
@ -87,8 +87,6 @@ kmain:
;mov al, 'X' ;mov al, 'X'
;call cga_putc ;call cga_putc
.halt: .halt:
hlt hlt
jmp $ jmp $
@ -115,11 +113,12 @@ kmain:
include 'isr.inc' include 'isr.inc'
include 'idt.inc' include 'idt.inc'
include 'pic.inc' include 'pic.inc'
include 'heap.inc' ;include 'heap.inc'
include 'vfs.inc' include 'vfs.inc'
include 'fs/fat.inc' include 'fs/fat.inc'
include 'fs/stpdfs.inc' include 'fs/stpdfs.inc'
include 'fs/xv6fs.inc' include 'fs/xv6fs.inc'
include 'proc.inc'
szMsgKernelAlive db "Kernel (", VERSION_FULL , ") is alive", 0 szMsgKernelAlive db "Kernel (", VERSION_FULL , ") is alive", 0
@ -129,6 +128,8 @@ boot_structure BootInfo
kTSS TSS kTSS TSS
aProcs rb 64*sizeof.Process
align 4096 align 4096
stack_bottom: stack_bottom:
rb 0x4000 rb 0x4000

11
kernel/proc.inc Normal file
View file

@ -0,0 +1,11 @@
proc_init:
mov ecx, sizeof.Process * 64
xor ax, ax
mov edi, aProcs
rep stosb
ret
uProcLock dd 0
pCurrentProc dd 0

View file

@ -1,18 +1,21 @@
struc ProcessGroup {
}
struc Context { struc Context {
.flags dd ? .edi dd ?
.regs dd ? .esi dd ?
.ebx dd ?
.ebp dd ?
.eip dd ?
} }
DEFN Context
struc Process { struc Process {
.pagedir dd ? .pagedir dd ?
.parent dd ? .kstack dd ?
.context Context .parent dd ?
.next dd ? .trapframe dd ?
.context dd ?
.next dd ?
} }
DEFN Process
PROCESS_STATE_IDL = 0 PROCESS_STATE_IDL = 0
PROCESS_STATE_RUN = 1 PROCESS_STATE_RUN = 1