
BOOTSECT = scboot.o
LOADER = scbtest.o

CFLAGS += -std=c99 -c -m32 -fno-built-in -fno-stack-protector
LDFLAGS += -melf_i386

all: bootsect loader fd0.img hd0.img

bootsect: $(BOOTSECT)
	$(LD) $(LDFLAGS) -T bootsect.ld $(BOOTSECT)

loader: $(LOADER)
	$(LD) $(LDFLAGS) -Map loader.map -T loader.ld $(LOADER)

# 1.44 MB floppy drive
fd0.img: bootsect loader
	# disk size
	dd if=/dev/zero of=fd0.img bs=512 count=2880
	# boot sector address
	dd conv=notrunc if=bootsect of=fd0.img bs=512 count=1 seek=0 
	# boot loader address
	dd conv=notrunc if=loader of=fd0.img bs=512 seek=1 

# 20 MB hard drive
hd0.img: bootsect loader
	# disk size (cylinders=count, heads=16, sectors/track=63, bytes=512)
	dd if=/dev/zero of=hd0.img bs=516096c count=40
	# boot sector address
	dd conv=notrunc if=bootsect of=hd0.img bs=512 count=1 seek=0 
	# boot loader address
	dd conv=notrunc if=loader of=hd0.img bs=512 seek=1 
	
clean:
	rm -f bootsect loader *.map *.img *.o
	
.s.o:
	nasm -f elf32 $<

