CC := gcc CFLAGS := -std=c99 -m32 -ffreestanding -O0 -g -Wall -Werror LD := ld all: 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, 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 12) truncate -s 6656 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 console.o vga.o serial.o port.o port_asm.o string.o stdlib.o $(LD) -o kernel.bin -N -n -Ttext 0x8400 --oformat binary \ kernel.o console.o vga.o serial.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) -c -o kernel.o kernel.c port.o: port.c port.h $(CC) $(CFLAGS) -c -o port.o port.c console.o: console.c console.h vga.h serial.h $(CC) $(CFLAGS) -c -o console.o console.c vga.o: vga.c vga.h $(CC) $(CFLAGS) -c -o vga.o vga.c serial.o: serial.c serial.h $(CC) $(CFLAGS) -c -o serial.o serial.c port_asm.o: port.asm nasm port.asm -f elf32 -o port_asm.o string.o: string.c string.h $(CC) $(CFLAGS) -c -o string.o string.c stdlib.o: stdlib.c stdlib.h $(CC) $(CFLAGS) -c -o stdlib.o stdlib.c clean: -rm -f boot.bin kernel.bin image.bin magic.bin *.o kernel.map image.tmp run-qemu: image.bin qemu-system-i386 -m 32 -drive "file=image.bin,if=ide,format=raw" \ -serial file:serial.log run-bochs: bochs -q -f bochs.config 'boot:floppy' 'floppya: 1_44=image.bin, status=inserted'