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 \ logger.inc \
a20.inc \ a20.inc \
multiboot.inc \ multiboot.inc \
stpdfs.inc stpdfs.inc \
disk.inc
.PHONY: all .PHONY: all
all: $(TARGET) all: $(TARGET)

View file

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

View file

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

View file

@ -1,7 +1,7 @@
STPDFS_NAME_MAX = 28 STPDFS_NAME_MAX = 28
;; Struct: inode ;; Struct: inode
struc inode { struc Inode {
.inode dw ? .inode dw ?
.nlink dw ? .nlink dw ?
.uid dw ? .uid dw ?
@ -12,7 +12,7 @@ struc inode {
.actime dq ? .actime dq ?
.modtime dq ? .modtime dq ?
} }
DEFN inode DEFN Inode
;; Struct: dirent ;; Struct: dirent
struc dirent { struc dirent {
@ -31,12 +31,23 @@ stpdfs_load_rootdir:
mov ax, 2 mov ax, 2
mov cx, 1 mov cx, 1
xor bx, bx xor bx, bx
call disk_read_sectors call disk_read_sectors
; root dir is inode 1 ; 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 ret
@ -51,5 +62,41 @@ stpdfs_search:
ret ret
;; Function: stpdfs_copy_data
;;
;; In:
;; ES - Buffer
stpdfs_copy_data: 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 ret