From 8e87cf0f759d58e9dc7a426ef93a7c6570b5fb1d Mon Sep 17 00:00:00 2001 From: Nero <41307858+nero@users.noreply.github.com> Date: Thu, 17 Sep 2020 05:57:46 +0000 Subject: [PATCH] Load kernel from reserved sectors in fatfs --- Makefile | 25 +++++++++++-------------- boot/kernel.asm | 27 ++++++++++++++++++++++++--- boot/mbr.asm | 2 +- 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index 8acbb1d..b6027c6 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,5 @@ -FLOPPY = 1440 - PROGRAMS = hello.com -DISTFILES = $(PROGRAMS) kernel.bs +DISTFILES = $(PROGRAMS) ROMS = QEMU_ARCH = $(shell uname -m) @@ -9,7 +7,7 @@ QEMU = qemu-system-$(QEMU_ARCH) QEMU_ARGS = $(addprefix --option-rom ,$(ROMS)) NASM = nasm -NASM_ARGS = -s -Ilib -DFLOPPY=$(FLOPPY) +NASM_ARGS = -s -Ilib EMUL = utils/emul @@ -28,7 +26,7 @@ endif .PHONY: default bootstrap clean qemu-rom qemu-floppy qemu-pxe -default: fdimage.img +default: fd1440.img # Host utils utils/%: %.c @@ -59,14 +57,13 @@ fat6.bs: boot/fat.asm %.rom: rom/%.asm utils/fix-rom $(NASM) $(NASM_ARGS) -o $@ $< && utils/fix-rom $@ -fdimage.img: fat1.bs $(DISTFILES) - mformat -C -i $@ -f $(FLOPPY) -B fat1.bs :: - mmd -i $@ ::rdos - mcopy -i $@ $(DISTFILES) ::rdos - mattrib -i $@ +s ::rdos ::rdos/kernel.bs +fd%.img: kernel.bs $(DISTFILES) + mformat -C -i $@ -f $* -R 8 -B kernel.bs :: + dd if=kernel.bs conv=notrunc bs=512 skip=1 seek=1 of=$@ + mcopy -i $@ $(DISTFILES) :: -hdimage.img: mbr.bs fdimage.img - cat mbr.bs fdimage.img >$@ +hdimage.img: mbr.bs fd1440.img + cat mbr.bs fd1440 >$@ part.img: fatc.bs $(DISTFILES) dd if=/dev/zero bs=1024 count=33k of=$@ @@ -82,8 +79,8 @@ clean: rm -f *.com *.bs *.0 *.lst *.img *.bin *.rom rm -rf utils -qemu-floppy: fdimage.img $(ROMS) - $(QEMU) $(QEMU_ARGS) -boot a -fda fdimage.img +qemu-floppy: fd1440.img $(ROMS) + $(QEMU) $(QEMU_ARGS) -boot a -fda fd1440.img qemu-hdd: hdd.img $(ROMS) $(QEMU) $(QEMU_ARGS) -boot c -hda hdd.img diff --git a/boot/kernel.asm b/boot/kernel.asm index 1b37760..b742457 100644 --- a/boot/kernel.asm +++ b/boot/kernel.asm @@ -7,11 +7,12 @@ ; kernel stack size in words %define stacksize 512 - jmp init + jmp near init - times ( 0x0B - ($-$$) ) db " " + db "LOVELAIN" - times bpb_size db 0 + ; mformat writes stuff until 0x3E +params: times ( 0x3E - ($-$$) ) nop init: cli xor ax, ax @@ -20,11 +21,31 @@ init: cli mov ss, ax mov sp, ( stack+stacksize ) + mov ax, [params+bpb.sectoroffset] + mov dx, [params+bpb.sectoroffset+2] + + mov ax, 0x0201 + mov cx, 0x0002 + mov dh, 0 + mov bx, 0x7E00 + int 0x13 + + mov ax, [0x7E00] + mov cx, [0x7E02] + mov dx, [0x7E04] + int 3 hlt: hlt jmp hlt + times (0x1FE - ($-$$)) db 0 + dw 0xAA55 + + db "rdos kernel" + +end: align 512 + section .bss stack: resb stacksize diff --git a/boot/mbr.asm b/boot/mbr.asm index 6655e48..c6b7bce 100644 --- a/boot/mbr.asm +++ b/boot/mbr.asm @@ -131,7 +131,7 @@ part1: db 0x80 db 0x01 db 0xFF, 0xFF, 0xFF dd 1 - dd (FLOPPY * 2) + dd (1440 * 2) times (0x1FE - ($-$$)) db 0