##################### # # # FoolOS Build Sys. # # # ##################### ############ phony targets ############ .PHONY: all clean run stick new newrun ############ some constants ############ USB_STICK=/dev/sdf #take care! #here our kernel will be loaded by the bootloader. KERNEL_START=0x100000 #use our cross compiler CC=i686-elf-gcc ############ flags ############ CFLAGS=-ffreestanding -nostdlib -lgcc -std=gnu11 CFLAGS+= -I. CFLAGS+= -Wno-implicit-function-declaration #CFLAGS+= -O0 #CFLAGS+=-fdata-sections -ffunction-sections #CFLAGS+= -Werror ############ source and object files ############ #kernel sources (asm and c) SOURCES=$(wildcard ./kernel/*.c) SOURCES+=$(wildcard ./lib/*/*.c) SOURCES+=$(wildcard ./fs/*.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=./boot0/mbr.bin #stage 2 bootloader STAGE2=./boot/stage2.bin #multiprocessor binary entry MP_BIN=./boot/mp.bin #some fillup data (zeros) FILLUP=./data/fill.bin ############ final image (default target) ############ all: FoolOS.vdi new: clean all newrun: clean run ############ 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) $(CC) $(CFLAGS) -o $@ -Wl,-Ttext,$(KERNEL_START),--oformat,binary $^ #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) $(STAGE2) kernel.bin $(FILLUP) FoolData.img cp $(FILLUP) $@ dd if=$(MBR) of=$@ bs=512 seek=0 conv=notrunc dd if=$(STAGE2) of=$@ bs=512 seek=1 conv=notrunc dd if=kernel.bin of=$@ bs=512 seek=10 conv=notrunc #will end up at 0x100000 in ram (this is what the booloader starts loading secotr: 10) dd if=FoolData.img of=$@ bs=512 seek=842 conv=notrunc #data starts at 0x168000 binfont.img: binfont.bin cat $^ > $@ FoolData.img: binfont.bin $(MP_BIN) userspace/ext2.img dd if=$(MP_BIN) of=$@ bs=512 seek=0 conv=notrunc dd if=binfont.bin of=$@ bs=512 seek=1 conv=notrunc dd if=userspace/ext2.img of=$@ bs=512 seek=4 conv=notrunc #will end up at 0x80800 in ram FoolOS.vdi: FoolOS.img VBoxManage convertfromraw FoolOS.img FoolOS.vdi --uuid 2f11ca11-c35d-4240-b77e-79e37d32616c ############ vm stuff ############ # run in our local bochs (we need cirrus support for our vesa mode) run: all ~/opt/bochs-2.6.6/bochs -q -f bochs/bochsrc -rc bochs/bochsdebug ############ cleanup ############ clean_release: -rm *.bin FoolData.img binfont.img bochs.log $(KERNEL_ENTRY) $(ASMOBJECTS) $(OBJECTS) $(FILLUP) $(MBR) $(MP_BIN) bochs.out ne2k-tx.log ne2k-txdump.txt $(STAGE2) make -C userspace clean clean: clean_release -rm FoolOS.img FoolOS.vdi release: new -mv FoolOS.img release/ make clean_release userspace/ext2.img: make -C userspace ############ test stuff ############ stick: FoolOS.img cat FoolOS.img > $(USB_STICK) && sync xxd $(USB_STICK) | head -n 50