switched to the 256boss-style disk image creation
[bootcensus] / Makefile
index c4d724a..8a12161 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,22 +1,23 @@
-csrc = $(wildcard src/*.c) $(wildcard src/libc/*.c) $(wildcard src/test/*.c)
-ssrc = $(wildcard src/*.s) $(wildcard src/libc/*.s) $(wildcard src/boot/*.s) $(wildcard src/test/*.s)
+csrc = $(wildcard src/*.c) $(wildcard src/libc/*.c) $(wildcard src/census/*.c)
+ssrc = $(wildcard src/*.s) $(wildcard src/libc/*.s) $(wildcard src/boot/*.s) $(wildcard src/census/*.s)
 Ssrc = $(wildcard src/*.S)
 obj = $(csrc:.c=.o) $(ssrc:.s=.o) $(Ssrc:.S=.o)
 dep = $(obj:.o=.d)
-elf = test
-bin = test.bin
+elf = bcensus
+bin = bcensus.bin
 
 warn = -pedantic -Wall
 #opt = -O2
 dbg = -g
-inc = -Isrc -Isrc/libc -Isrc/test
-gccopt = -fno-pic -ffreestanding -nostdinc -fno-builtin
+inc = -Isrc -Isrc/libc
+gccopt = -fno-pic -ffreestanding -nostdinc -fno-builtin -ffast-math
 
 CFLAGS = $(ccarch) -march=i386 $(warn) $(opt) $(dbg) $(gccopt) $(inc) $(def)
 ASFLAGS = $(asarch) -march=i386 $(dbg) -nostdinc -fno-builtin $(inc)
 LDFLAGS = $(ldarch) -nostdlib -T pcboot.ld -print-gc-sections
 
-QEMU_FLAGS = -fda floppy.img -serial file:serial.log -soundhw sb16
+#QEMU_FLAGS = -fda floppy.img -serial file:serial.log -soundhw sb16
+QEMU_FLAGS = -hda disk.img -serial file:serial.log -soundhw sb16
 
 ifneq ($(shell uname -m), i386)
        ccarch = -m32
@@ -24,6 +25,26 @@ ifneq ($(shell uname -m), i386)
        ldarch = -m elf_i386
 endif
 
+.PHONY: all
+all: disk.img #floppy.img
+
+disk.img: boot.img blank.img
+       @echo
+       @echo - patching pcboot onto the blank disk image ...
+       cp blank.img $@
+       dd if=boot.img of=$@ bs=512 status=none conv=notrunc
+       dd if=blank.img of=$@ bs=1 seek=440 skip=440 count=70 status=none conv=notrunc
+
+blank.img:
+       @echo
+       @echo - generating blank disk image with FAT partition ...
+       dd if=/dev/zero of=part.img bs=1024 count=63488
+       mkfs -t vfat -n PCBOOT part.img
+       dd if=/dev/zero of=$@ bs=1024 count=65536
+       echo start=2048 type=c | sfdisk $@
+       dd if=part.img of=$@ bs=512 seek=2048 conv=notrunc
+       rm part.img
+
 floppy.img: boot.img
        dd if=/dev/zero of=$@ bs=512 count=2880
        dd if=$< of=$@ conv=notrunc
@@ -38,13 +59,13 @@ pcboot.iso: floppy.img
 boot.img: bootldr.bin $(bin)
        cat bootldr.bin $(bin) >$@
 
-# bootldr.bin will contain only .boot and .boot2
+# bootldr.bin will contain .boot, .boot2, .bootend, and .lowtext
 bootldr.bin: $(elf)
-       objcopy -O binary -j '.boot*' $< $@
+       objcopy -O binary -j '.boot*' -j .lowtext $< $@
 
-# the main binary will contain every section *except* .boot and .boot2
+# the main binary will contain every section *except* those
 $(bin): $(elf)
-       objcopy -O binary -R '.boot*' $< $@
+       objcopy -O binary -R '.boot*' -R .lowtext $< $@
 
 $(elf): $(obj)
        $(LD) -o $@ $(obj) -Map link.map $(LDFLAGS)
@@ -59,7 +80,7 @@ $(elf): $(obj)
 
 .PHONY: clean
 clean:
-       rm -f $(obj) $(bin) boot.img floppy.img link.map
+       rm -f $(obj) $(bin) boot.img floppy.img disk.img link.map
 
 .PHONY: cleandep
 cleandep:
@@ -69,10 +90,10 @@ cleandep:
 disasm: bootldr.disasm $(elf).disasm
 
 bootldr.disasm: $(elf)
-       objdump -d $< -j .boot -j .boot2 -m i8086 >$@
+       objdump -d $< -j .boot -j .boot2 -j .lowtext -m i8086 >$@
 
 $(elf).disasm: $(elf)
-       objdump -d $< -j .startup -j .text -m i386 >$@
+       objdump -d $< -j .startup -j .text -j .lowtext -m i386 >$@
 
 $(elf).sym: $(elf)
        objcopy --only-keep-debug $< $@
@@ -87,3 +108,12 @@ debug: $(bin) $(elf).sym
 
 .PHONY: sym
 sym: $(elf).sym
+
+.PHONY: mount
+mount: disk.img
+       mount -o loop,offset=1048576 $< /mnt
+
+.PHONY: data
+data: blank.img
+       mcopy -D o -i $<@@1M data/* ::.data
+       $(MAKE)