FLOPPY = 360 PROGRAMS = hello.com DISTFILES = $(PROGRAMS) kernel.bs ROMS = QEMU_ARCH = $(shell uname -m) QEMU = qemu-system-$(QEMU_ARCH) QEMU_ARGS = $(addprefix --option-rom ,$(ROMS)) NASM = nasm NASM_ARGS = -s -Ilib -DFLOPPY=$(FLOPPY) EMUL = utils/emul ifdef KVM QEMU_ARGS += --enable-kvm endif ifdef DEBUG ROMS += dprintf.rom NASM_ARGS += -l $(basename $@).lst endif ifndef DISPLAY QEMU_ARGS += --display curses endif .PHONY: default bootstrap clean qemu-rom qemu-floppy qemu-pxe default: fdimage.img # Host utils utils/%: %.c mkdir -p utils $(CC) -o $@ $< # COM programs %.com: com/%.asm $(NASM) $(NASM_ARGS) -o $@ $< # Bootloaders, first sector on partition %.bs: boot/%.asm $(NASM) $(NASM_ARGS) -o $@ $< kernel.bs: kernel/*.asm # Special case: variations of FAT vbr fat1.bs: boot/fat.asm $(NASM) $(NASM_ARGS) -DFAT12 -DCHS -o $@ $< fat4.bs: boot/fat.asm $(NASM) $(NASM_ARGS) -DFAT16 -DCHS -o $@ $< fat6.bs: boot/fat.asm $(NASM) $(NASM_ARGS) -DFAT16 -DCHS -DLARGE -o $@ $< fatb.bs: boot/fat.asm $(NASM) $(NASM_ARGS) -DFAT32 -DCHS -DLARGE -o $@ $< fatc.bs: boot/fat.asm $(NASM) $(NASM_ARGS) -DFAT32 -DLBA -DLARGE -o $@ $< fate.bs: boot/fat.asm $(NASM) $(NASM_ARGS) -DFAT16 -DLBA -DLARGE -o $@ $< # BIOS option roms %.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 hdimage.img: mbr.bs fdimage.img cat mbr.bs fdimage.img >$@ part.img: fatc.bs $(DISTFILES) dd if=/dev/zero bs=1024 count=33k of=$@ mformat -i $@ -F -B fatc.bs :: mmd -i $@ ::rdos mcopy -i $@ $(DISTFILES) ::rdos mattrib -i $@ +s ::rdos ::rdos/kernel.bs hdd.img: part.img mbr.bs cat mbr.bs part.img > $@ 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-hdd: hdd.img $(ROMS) $(QEMU) $(QEMU_ARGS) -boot c -hda hdd.img qemu-pxe: pxeboot.0 $(ROMS) $(QEMU) $(QEMU_ARGS) -boot n \ -option-rom /usr/share/qemu/pxe-rtl8139.rom \ -device e1000,netdev=mynet0,mac=52:54:00:12:34:56 \ -netdev user,id=mynet0,net=192.168.76.0/24,dhcpstart=192.168.76.9,tftp=$(CURDIR),bootfile=pxeboot.0 qemu-rom: kernel.rom $(QEMU) $(QEMU_ARGS) --option-rom kernel.rom