Skip to content
Snippets Groups Projects
Commit 3f7007a9 authored by Jacob Lorentzon's avatar Jacob Lorentzon
Browse files

Support loading filesystems from MBR partitions.

parent bc43dbb6
No related branches found
No related tags found
1 merge request!3Support booting from MBR disks
...@@ -150,6 +150,7 @@ DAPACK: ...@@ -150,6 +150,7 @@ DAPACK:
.seg: dw 0 ; in memory page zero .seg: dw 0 ; in memory page zero
.addr: dq 0 ; put the lba to read in this spot .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 0x55
db 0xaa db 0xaa
...@@ -22,12 +22,10 @@ startup_end: ...@@ -22,12 +22,10 @@ startup_end:
%else %else
align BLOCK_SIZE, db 0 align BLOCK_SIZE, db 0
%ifdef FILESYSTEM %ifdef FILESYSTEM
filesystem: filesystem:
%defstr FILESYSTEM_STR %[FILESYSTEM] %defstr FILESYSTEM_STR %[FILESYSTEM]
incbin FILESYSTEM_STR incbin FILESYSTEM_STR
.end: align BLOCK_SIZE, db 0
align BLOCK_SIZE, db 0 .end:
%else
filesystem:
%endif %endif
%endif %endif
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
...@@ -37,7 +37,12 @@ struc Header ...@@ -37,7 +37,12 @@ struc Header
.padding: resb (BLOCK_SIZE - 56) .padding: resb (BLOCK_SIZE - 56)
endstruc endstruc
; IN
; eax - the first sector of the filesystem
; edx - the amount of sectors in the filesystem
redoxfs: redoxfs:
mov [.first_sector], eax
mov [.sector_count], ebx
call redoxfs.open call redoxfs.open
test eax, eax test eax, eax
jz .good_header jz .good_header
...@@ -53,7 +58,7 @@ redoxfs: ...@@ -53,7 +58,7 @@ redoxfs:
; node in eax, buffer in bx ; node in eax, buffer in bx
.node: .node:
shl eax, (BLOCK_SHIFT - 9) shl eax, (BLOCK_SHIFT - 9)
add eax, (filesystem - boot)/512 add eax, [redoxfs.first_sector]
mov cx, (BLOCK_SIZE/512) mov cx, (BLOCK_SIZE/512)
mov dx, 0 mov dx, 0
call load call load
...@@ -71,6 +76,9 @@ redoxfs: ...@@ -71,6 +76,9 @@ redoxfs:
.file: .file:
times BLOCK_SIZE db 0 times BLOCK_SIZE db 0
.first_sector: dd 0
.sector_count: dd 0
.env: .env:
db "REDOXFS_BLOCK=" db "REDOXFS_BLOCK="
.env.block: .env.block:
...@@ -111,7 +119,15 @@ redoxfs.open: ...@@ -111,7 +119,15 @@ redoxfs.open:
mov al, ' ' mov al, ' '
call print_char 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 mov di, redoxfs.env.block_end - 1
.block: .block:
mov al, bl mov al, bl
...@@ -314,7 +330,7 @@ redoxfs.kernel: ...@@ -314,7 +330,7 @@ redoxfs.kernel:
shl eax, (BLOCK_SHIFT - 9) shl eax, (BLOCK_SHIFT - 9)
add eax, (filesystem - boot)/512 add eax, [redoxfs.first_sector]
add ecx, BLOCK_SIZE add ecx, BLOCK_SIZE
dec ecx dec ecx
shr ecx, 9 shr ecx, 9
......
...@@ -25,6 +25,14 @@ startup: ...@@ -25,6 +25,14 @@ startup:
shr ecx, 9 shr ecx, 9
call load_extent call load_extent
%else %else
%ifdef FILESYSTEM
mov eax, (filesystem - boot) / 512
mov ebx, (filesystem.end - filesystem) / 512
%else
call find_redoxfs_partition
%endif
call redoxfs call redoxfs
test eax, eax test eax, eax
jnz error jnz error
...@@ -50,10 +58,10 @@ startup: ...@@ -50,10 +58,10 @@ startup:
jmp startup_arch jmp startup_arch
# load a disk extent into high memory ; load a disk extent into high memory
# eax - sector address ; eax - sector address
# ecx - sector count ; ecx - sector count
# edi - destination ; edi - destination
load_extent: load_extent:
; loading kernel to 1MiB ; loading kernel to 1MiB
; move part of kernel to startup_end via bootsector#load and then copy it up ; move part of kernel to startup_end via bootsector#load and then copy it up
...@@ -132,6 +140,9 @@ load_extent: ...@@ -132,6 +140,9 @@ load_extent:
%include "initialize.asm" %include "initialize.asm"
%ifndef KERNEL %ifndef KERNEL
%include "redoxfs.asm" %include "redoxfs.asm"
%ifndef FILESYSTEM
%include "partitions.asm"
%endif
%endif %endif
init_fpu_msg: db "Init FPU",13,10,0 init_fpu_msg: db "Init FPU",13,10,0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment