loading root directory to disk, will have to work on a tool to transfer kernel binary to filesystem as i cannot mount the fs to WSL

This commit is contained in:
notsomeidiot123 2024-09-17 15:00:16 -04:00
parent 21417fd70f
commit 85bf36c2d1
4 changed files with 59 additions and 2 deletions

BIN
diskwrite Executable file

Binary file not shown.

View File

@ -2,10 +2,13 @@ CC := gcc
AS := nasm
BL_ASFLAGS := -f bin
all: bootloader
all: bootloader tools
cp bin/bootloader.bin image.bin
qemu-img resize -f raw image.bin 512M
qemu-system-i386 -hda bin/bootloader.bin --no-reboot --no-shutdown -m 32m -smp 2 -serial mon:stdio
tools:
$(CC) tools/diskwrite.c -o diskwrite
bootloader:
$(AS) src/bootloader/main.s $(BL_ASFLAGS) -o bin/bootloader.bin
@ -15,6 +18,9 @@ init:
@mkdir bin/boot
@mkdir bin/kernel
.PHONY: tools
clean:
@rm diskwrite
@rm -rf bin/
@rm -rf mount/

View File

@ -181,6 +181,7 @@ load_gdt:
mov cr0, eax
jmp 0x0:.real
.real:;no actual code here, just label for readability and organization
pop ds
load_part2:
mov ah, 0x42
xor edx, edx
@ -201,6 +202,7 @@ load_part2:
push 0
pop ds
mov si, DAP
jmp $
int 0x13
jc load_fail
jmp part_2
@ -298,6 +300,7 @@ times 1024-($-$$) db 0
part_2:
call get_mmap
call paging_en
call open_file
jmp $
load_kernel:
get_mmap:
@ -360,6 +363,46 @@ paging_en:
ret
open_file:
;only looks in the root directory
xor esi, esi
xor ecx, ecx
xor edx, edx
mov esi, [fat_bpb.part_start];
add si, [fat_bpb.reserved_sectors]
mov cl, [fat_bpb.fat_count]
mov dx, [fat_ebpb32.sectors_per_fat]
.addlp:
add esi, edx
dec ecx
or ecx, ecx
jnz .addlp
xor dx, dx
mov ecx, [fat_ebpb32.root_dir_cluster]
mov dl, [fat_bpb.sectors_per_cluster]
.addlp1:
add esi, edx
dec ecx
or ecx, ecx
jnz .addlp1
mov [DAP.sector_start], esi
mov [DAP.read_count], dx
mov [DAP.offset], word 0xd000
mov [DAP.segment], word 0x0000
mov eax, [DAP.sector_start]
mov ebx, [DAP.sector_start + 4]
mov ecx, [DAP.offset]
mov dx, [DAP.read_count]
push 0
pop ds
push 0
pop es
;sector start now contains the sector number of the first data sector of the root directory
mov ah, 0x42
mov dl, byte [data.boot_disc]
mov si, DAP
int 0x13
jc load_fail
debug
read_file:
;reads all data from file
load_elf:
@ -369,7 +412,7 @@ k_info:
.memory_map_ptr: dd 0x2000
.memory_map_count: dw 0
.padding: db 0
.bpp: db 0
.bpp: db 0;if depth == 0 then video is text mode
.xres: dw 0
.yres: dw 0
.framebuffer_ptr: dd 0

8
tools/diskwrite.c Normal file
View File

@ -0,0 +1,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char **argv){
printf("Hello, World!\n");
return 0;
}