Support loading filesystems from MBR partitions.

This commit is contained in:
4lDO2
2020-01-08 17:54:06 +11:00
parent bc43dbb621
commit 3f7007a9a5
5 changed files with 79 additions and 15 deletions
+2 -1
View File
@@ -150,6 +150,7 @@ DAPACK:
.seg: dw 0 ; in memory page zero
.addr: dq 0 ; put the lba to read in this spot
times 510-($-$$) db 0
times 446-($-$$) db 0
partitions: times 4 * 16 db 0
db 0x55
db 0xaa
+5 -7
View File
@@ -22,12 +22,10 @@ startup_end:
%else
align BLOCK_SIZE, db 0
%ifdef FILESYSTEM
filesystem:
%defstr FILESYSTEM_STR %[FILESYSTEM]
incbin FILESYSTEM_STR
.end:
align BLOCK_SIZE, db 0
%else
filesystem:
filesystem:
%defstr FILESYSTEM_STR %[FILESYSTEM]
incbin FILESYSTEM_STR
align BLOCK_SIZE, db 0
.end:
%endif
%endif
+38
View File
@@ -0,0 +1,38 @@
struc mbr_partition_rec
.sys: resb 1
.chs_start: resb 3
.ty: resb 1
.chs_end: resb 3
.lba_start: resd 1
.sector_count: resd 1
endstruc
; Find a partition to load RedoxFS from.
; The partition has to be one of the primary MBR partitions.
; OUT
; eax - start_lba
; edx - sector count
; CLOBBER
; ebx
find_redoxfs_partition:
xor ebx, ebx
.loop:
mov al, byte [partitions + mbr_partition_rec + mbr_partition_rec.ty]
cmp al, 0x83
je .found
add ebx, 1
cmp ebx, 4
jb .loop
jmp .notfound
.found:
mov eax, [partitions + mbr_partition_rec + mbr_partition_rec.lba_start]
mov edx, [partitions + mbr_partition_rec + mbr_partition_rec.sector_count]
ret
.notfound:
mov si, .no_partition_found_msg
call print
.halt:
cli
hlt
jmp .halt
.no_partition_found_msg: db "No MBR partition with type 0x83 found", 0xA, 0xD, 0
+19 -3
View File
@@ -37,7 +37,12 @@ struc Header
.padding: resb (BLOCK_SIZE - 56)
endstruc
; IN
; eax - the first sector of the filesystem
; edx - the amount of sectors in the filesystem
redoxfs:
mov [.first_sector], eax
mov [.sector_count], ebx
call redoxfs.open
test eax, eax
jz .good_header
@@ -53,7 +58,7 @@ redoxfs:
; node in eax, buffer in bx
.node:
shl eax, (BLOCK_SHIFT - 9)
add eax, (filesystem - boot)/512
add eax, [redoxfs.first_sector]
mov cx, (BLOCK_SIZE/512)
mov dx, 0
call load
@@ -71,6 +76,9 @@ redoxfs:
.file:
times BLOCK_SIZE db 0
.first_sector: dd 0
.sector_count: dd 0
.env:
db "REDOXFS_BLOCK="
.env.block:
@@ -111,7 +119,15 @@ redoxfs.open:
mov al, ' '
call print_char
mov ebx, (filesystem - boot)/BLOCK_SIZE
push eax
push edx
xor edx, edx
mov eax, [redoxfs.first_sector]
mov ebx, (BLOCK_SIZE / 512)
div ebx ; EDX:EAX = EDX:EAX / EBX
mov ebx, eax
pop edx
pop eax
mov di, redoxfs.env.block_end - 1
.block:
mov al, bl
@@ -314,7 +330,7 @@ redoxfs.kernel:
shl eax, (BLOCK_SHIFT - 9)
add eax, (filesystem - boot)/512
add eax, [redoxfs.first_sector]
add ecx, BLOCK_SIZE
dec ecx
shr ecx, 9
+15 -4
View File
@@ -25,6 +25,14 @@ startup:
shr ecx, 9
call load_extent
%else
%ifdef FILESYSTEM
mov eax, (filesystem - boot) / 512
mov ebx, (filesystem.end - filesystem) / 512
%else
call find_redoxfs_partition
%endif
call redoxfs
test eax, eax
jnz error
@@ -50,10 +58,10 @@ startup:
jmp startup_arch
# load a disk extent into high memory
# eax - sector address
# ecx - sector count
# edi - destination
; load a disk extent into high memory
; eax - sector address
; ecx - sector count
; edi - destination
load_extent:
; loading kernel to 1MiB
; move part of kernel to startup_end via bootsector#load and then copy it up
@@ -132,6 +140,9 @@ load_extent:
%include "initialize.asm"
%ifndef KERNEL
%include "redoxfs.asm"
%ifndef FILESYSTEM
%include "partitions.asm"
%endif
%endif
init_fpu_msg: db "Init FPU",13,10,0