feat(boot): loader read stpdfs root dir

This commit is contained in:
d0p1 🏳️‍⚧️ 2024-09-01 11:53:44 +02:00
parent 1cd67eec0a
commit e5a7a87a58
4 changed files with 66 additions and 12 deletions

View file

@ -11,7 +11,8 @@ LOADER_SRCS = loader.asm \
logger.inc \
a20.inc \
multiboot.inc \
stpdfs.inc
stpdfs.inc \
disk.inc
.PHONY: all
all: $(TARGET)

View file

@ -7,8 +7,8 @@
;; CX - Sector count
;; ES:BX - buffer
disk_read_sectors:
; test byte [bDriveLBA], TRUE
; je .lba_read
cmp byte [bDriveLBA], TRUE
je .lba_read
push ax
push bx
push cx
@ -40,14 +40,17 @@ disk_read_sectors:
call bios_print
ret
.lba_read:
push si
mov word [disk_packet.sectors], cx
mov word [disk_packet.segment], es
mov word [disk_packet.offset], bx
mov word [disk_packet.lba], ax
mov ds, [disk_packet]
mov dword [disk_packet.lba], eax
mov si, disk_packet
mov dl, [uDrive]
mov ah, 0x42
int 0x13
jc @b
pop si
ret
C dw 0x00
@ -59,10 +62,10 @@ disk_packet:
db 0
.sectors:
dw 0
.segment:
dw 0
.offset:
dw 0
.segment:
dw 0
.lba:
dd 0
dd 0

View file

@ -46,7 +46,7 @@ _start:
mov dl, [uDrive]
cmp dl, 0x7F
; skip disk extension check
jle @f
jbe @f
; check disk extensions
mov ah, 0x41
@ -54,6 +54,7 @@ _start:
int 0x13
jc @f
mov [bDriveLBA], TRUE
@@:
; detect filesystem (FAT12/16 or StpdFS)
; load kernel from filesystem
@ -261,6 +262,8 @@ _edata:
boot_structure BootInfo
inode_cache rb sizeof.Inode
align 4096
boot_page_directory:
rb 4096

View file

@ -1,7 +1,7 @@
STPDFS_NAME_MAX = 28
;; Struct: inode
struc inode {
struc Inode {
.inode dw ?
.nlink dw ?
.uid dw ?
@ -12,7 +12,7 @@ struc inode {
.actime dq ?
.modtime dq ?
}
DEFN inode
DEFN Inode
;; Struct: dirent
struc dirent {
@ -31,12 +31,23 @@ stpdfs_load_rootdir:
mov ax, 2
mov cx, 1
xor bx, bx
call disk_read_sectors
; root dir is inode 1
mov dword eax, [DISK_BUFFER + sizeof.inode * 2 + inode.size]
xor ax, ax
mov es, ax
mov ecx, sizeof.Inode
mov esi, DISK_BUFFER + sizeof.Inode
mov edi, inode_cache
rep movsb
mov ax, DISK_BUFFER/0x10
mov es, ax
call stpdfs_copy_data
xchg bx, bx
ret
@ -51,5 +62,41 @@ stpdfs_search:
ret
;; Function: stpdfs_copy_data
;;
;; In:
;; ES - Buffer
stpdfs_copy_data:
xor edx, edx
mov bx, es
movzx ebx, bx
@@:
mov ax, es
movzx ecx, ax
sub ecx, ebx
cmp ecx, dword [inode_cache + Inode.size]
jg .all_read
mov eax, edx
shl eax, 2
add eax, dword [inode_cache + Inode.zones]
push edx
push ebx
mov cx, 1
xor bx, bx
call disk_read_sectors
pop ebx
pop edx
mov ax, es
add ax, 512
mov es, ax
inc edx
cmp edx, 8
jbe @b
.indirect_read:
.all_read:
ret