##################### # # # FoolOS Build Sys. # # # ##################### ############ phony targets ############ .PHONY: all clean run ############ some constants ############ #lets use the size of a 1.44 floppy for a start for our boot img IMAGE_SIZE=1474560 #floppy #ap bin : MP_IMG_START=26112 #multiboot is initially at 0x6600 #font data starts here: FONT_DATA_START=26624 #fool font initially at 0x6800 USB_STICK=/dev/sdd KERNEL_START=0x10000 ############ flags ############ CFLAGS=-ffreestanding -std=gnu99 -m32 -fno-asynchronous-unwind-tables -O0 CFLAGS+= -I. #CFLAGS+=-fdata-sections -ffunction-sections #CFLAGS+= -Werror ############ source and object files ############ #kernel sources (asm and c) SOURCES=$(wildcard ./kernel/*.c) SOURCES+=$(wildcard ./lib/*/*.c) ASMSOURCES=$(wildcard ./asm/*.asm) #kernel object files OBJECTS=$(patsubst %.c, %.o, $(SOURCES)) ASMOBJECTS=$(patsubst %.asm, %.o, $(ASMSOURCES)) KERNEL_ENTRY=./boot/kernel_entry.o #master boot record asm MBR=./boot/mbr.bin #multiprocessor binary entry MP_BIN=./boot/mp.bin #some fillup data (zeros) FILLUP=./data/fill.bin ############ final image (default target) ############ all: FoolOS.img ############ nasm assembling rules ############ %.o: %.asm nasm -f elf $^ -o $@ %.bin: %.asm nasm -f bin $^ -o $@ ############ linking kernel binary ############ # the kernel_entry.o needs to be FIRST!! kernel.bin: $(KERNEL_ENTRY) $(ASMOBJECTS) $(OBJECTS) ld -o $@ -Ttext $(KERNEL_START) --oformat binary -melf_i386 $^ -O0 # --gc-sections --entry=kernel_main -v ############ fool-font ############ binfont.bin: data/binfont.src python tools/binarize.py $< $@ ############ assembling of final image ############ # master boot record, kernel binary and fool-font FoolOS.img: mbr_kernel_mp.img binfont.img $(FILLUP) cat $^ | head -c $(IMAGE_SIZE) > $@ mbr_kernel_mp.img: mbr_kernel.img $(MP_BIN) $(FILLUP) cat $^ | head -c $(FONT_DATA_START) > $@ mbr_kernel.img: $(MBR) kernel.bin $(FILLUP) cat $^ | head -c $(MP_IMG_START) > $@ binfont.img: binfont.bin cat $^ > $@ ############ vm stuff ############ # run in our local bochs (we need cirrus support for our vesa mode) run: FoolOS.img ~/opt/bochs-2.6.6/bochs -q -rc bochsdebug ############ cleanup ############ clean: -rm *.bin *.img bochs.log $(KERNEL_ENTRY) $(ASMOBJECTS) $(OBJECTS) $(FILLUP) $(MBR) $(MP_BIN) bochs.out ne2k-tx.log ne2k-txdump.txt ############ test stuff ############ stick: FoolOS.img cat FoolOS.img > $(USB_STICK) && sync xxd $(USB_STICK) | head -n 50 ##### floppy operations ####### floppy_losetup_on: sudo losetup /dev/loop0 data/floppy.img floppy_losetup_off: sudo losetup -d /dev/loop0 floppy_init: sudo dd if=/dev/zero of=data/floppy.img count=2880 bs=512