From 30596991abc9e452fbad8372f1ddcce12b87ce72 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Thu, 11 May 2017 22:10:07 +0200 Subject: better documentation for the boot loading process and how much sectors each part needs, fixed truncation problem started a magic signature at the end of the image and started to check it in stage 2 of the boot loader to avoid truncated images in the future --- src/Makefile | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) (limited to 'src/Makefile') diff --git a/src/Makefile b/src/Makefile index c983fb6..4e0755a 100644 --- a/src/Makefile +++ b/src/Makefile @@ -4,30 +4,47 @@ LD := ld all: image.bin -image.bin: boot.bin kernel.bin - cat boot.bin kernel.bin > image.bin +image.bin: boot.bin kernel.bin magic.bin + cat boot.bin kernel.bin > image.tmp # truncate to correct number of sectors, we have - # 512 (boot, first stage) + N * 512 (N currenty is 3) + M * 512 (M is currently 3) - truncate -s 4096 image.bin + # 512 (boot, stage 1) + N * 512 (N currenty is 3, stage 2) = 2048 for boot.bin + # + M * 512 (M is currently 7) = 3144 for kernel.bin + # + 1 * 512 = 512 for magic.bin + # (M + N + 1 is the number of sectors to be read in stage 2, as stage 1 + # loads only the first sector, so adapt NOF_LOAD_SECTORS to 10) + truncate -s 5632 image.tmp + cat image.tmp magic.bin > image.bin boot.bin: boot.asm gdt.asm stage1_functions.asm stage2_functions.asm switch_mode.asm nasm boot.asm -f bin -o boot.bin -kernel.bin: kernel.o vga.o string.o +kernel.bin: kernel.o vga.o port.o port_asm.o string.o stdlib.o $(LD) -o kernel.bin -n -Ttext 0x8000 --oformat binary \ - kernel.o vga.o string.o + kernel.o vga.o port.o port_asm.o string.o stdlib.o +magic.bin: magic.asm + nasm magic.asm -f bin -o magic.bin + kernel.o: kernel.c - $(CC) $(CFLAGS) -O0 -c -o kernel.o kernel.c + $(CC) $(CFLAGS) -c -o kernel.o kernel.c + +port.o: port.c + $(CC) $(CFLAGS) -c -o port.o port.c vga.o: vga.c - $(CC) $(CFLAGS) -O0 -c -o vga.o vga.c + $(CC) $(CFLAGS) -c -o vga.o vga.c + +port_asm.o: port.asm + nasm port.asm -f elf32 -o port_asm.o string.o: string.c - $(CC) $(CFLAGS) -O0 -c -o string.o string.c + $(CC) $(CFLAGS) -c -o string.o string.c + +stdlib.o: stdlib.c + $(CC) $(CFLAGS) -c -o stdlib.o stdlib.c clean: - -rm -f boot.bin kernel.bin image.bin *.o + -rm -f boot.bin kernel.bin image.bin magic.bin *.o run-qemu: image.bin qemu-system-i386 -m 32 -drive "file=image.bin,if=ide,format=raw" -- cgit v1.2.3-54-g00ecf