2023-02-14 23:48:11 -06:00
|
|
|
objects = entry.o kernel.o task.o handler.o interrupt.o v86.o print.o tss.o gdt.o\
|
|
|
|
paging.o fault.o tests.o kbd.o helper.o disk.o file.o fs.o dosfs/dosfs.o fs_dos.o\
|
|
|
|
progs.o hexedit.o textedit.o
|
2023-02-10 19:20:17 -06:00
|
|
|
CFLAGS = -target "i686-elf" -m32 -mgeneral-regs-only -ffreestanding\
|
|
|
|
-march=i686 -fno-stack-protector -Wno-int-conversion -nostdlib -c
|
|
|
|
LFLAGS = -Wl,--gc-sections -Wl,--print-gc-sections -m32 -nostartfiles -nostdlib
|
|
|
|
|
|
|
|
ifeq ($(OUTFILE),)
|
|
|
|
OUTFILE = virtdisk.bin
|
|
|
|
endif
|
2023-02-13 18:23:33 -06:00
|
|
|
ifeq ($(PARTSTART),)
|
|
|
|
PARTSTART = 2048
|
|
|
|
endif
|
|
|
|
|
|
|
|
PARTVBR=$(shell echo "$(PARTSTART) * (2^9)" | bc)
|
|
|
|
PARTVBRBOOT=$(shell echo "$(PARTVBR) + 90" | bc)
|
|
|
|
KERNSEC=$(shell echo "$(PARTSTART) + 4" | bc)
|
2023-02-10 19:20:17 -06:00
|
|
|
|
|
|
|
.PHONY: $(OUTFILE)
|
|
|
|
|
|
|
|
all: $(OUTFILE)
|
|
|
|
|
2023-02-13 18:23:33 -06:00
|
|
|
$(OUTFILE): boot.bin boot_partition.bin kernel.bin
|
|
|
|
# Copy system bootloader to boot sector, don't overwrite MBR
|
2023-02-10 19:20:17 -06:00
|
|
|
dd bs=400 count=1 conv=notrunc if=boot.bin of=$@
|
2023-02-13 18:23:33 -06:00
|
|
|
# Ensure partition VBR contains EB 5A
|
|
|
|
echo -n -e '\xeb\x5a' | dd bs=1 seek=$(PARTVBR) count=2 conv=notrunc of=$@
|
|
|
|
# Copy kernel bootloader to partition VBR
|
|
|
|
dd bs=1 count=420 seek=$(PARTVBRBOOT) conv=notrunc if=boot_partition.bin of=$@
|
|
|
|
# TODO Check that disk has enough reserved sectors,
|
|
|
|
# currently this will overwrite the disk if too few
|
|
|
|
# Write kernel beyond boot sector, maximum 64K (128 sectors)
|
|
|
|
dd bs=512 count=128 seek=$(KERNSEC) conv=notrunc if=kernel.bin of=$@
|
2023-02-10 19:20:17 -06:00
|
|
|
|
2023-02-12 00:42:14 -06:00
|
|
|
kernel.bin: out.o link.ld usermode.o
|
|
|
|
clang $(LFLAGS) -Wl,-M -Tlink.ld -ffreestanding -o $@ out.o usermode.o
|
|
|
|
|
|
|
|
usermode.o: usermode.bin
|
|
|
|
objcopy -I binary -O elf32-i386 -B i386 $< $@
|
2023-02-10 19:20:17 -06:00
|
|
|
|
2023-02-12 00:42:14 -06:00
|
|
|
%.bin: %.nasm
|
|
|
|
nasm -o $@ $<
|
2023-02-10 19:20:17 -06:00
|
|
|
|
|
|
|
out.o: $(objects)
|
|
|
|
clang $(LFLAGS) -e entry -r -o $@ $^
|
2022-09-16 15:50:58 -05:00
|
|
|
|
|
|
|
%.o: %.nasm
|
|
|
|
nasm -f elf32 -o $@ $<
|
|
|
|
|
|
|
|
%.o: %.c
|
2023-02-10 19:20:17 -06:00
|
|
|
clang $(CFLAGS) -ffunction-sections -fdata-sections -Os -o $@ $<
|
|
|
|
|
2022-09-14 16:50:44 -05:00
|
|
|
virtdisk:
|
2023-02-13 18:23:33 -06:00
|
|
|
cp virtdisk.bin.ex virtdisk.bin
|
2022-09-16 15:50:58 -05:00
|
|
|
|
2022-09-21 17:14:11 -05:00
|
|
|
clean:
|
2023-02-12 00:42:14 -06:00
|
|
|
rm -f $(objects) out.o kernel.bin boot.bin usermode.bin
|