2019-04-22 16:42:34 -05:00
|
|
|
PLAT=x86_64
|
2019-03-30 11:44:01 -05:00
|
|
|
C_SOURCES = $(wildcard kernel/*.c drivers/$(PLAT)/*.c drivers/$(PLAT)/*/*.c cpu/$(PLAT)/*.c fs/*.c)
|
2019-04-22 08:39:46 -05:00
|
|
|
ASM = $(wildcard cpu/$(PLAT)/*.asm)
|
|
|
|
S_ASM = $(wildcard cpu/$(PLAT)/*.s)
|
2019-03-30 11:44:01 -05:00
|
|
|
LIBC_SOURCES = $(wildcard libc/*.c libc/*/*.c)
|
2019-03-31 13:10:40 -05:00
|
|
|
LIBC_HEADERS = $(wildcard libc/*.h libc/*/*.h)
|
2019-04-22 08:39:46 -05:00
|
|
|
OBJ = $(C_SOURCES:.c=.o cpu/$(PLAT)/boot.o)
|
|
|
|
ASM_OBJ = $(S_ASM:.s=.o)
|
|
|
|
S_ASM_OBJ = $(ASM:.asm=.o)
|
2019-03-30 11:44:01 -05:00
|
|
|
LIBC_OBJ = $(LIBC_SOURCES:.c=.o)
|
2019-02-09 12:52:45 -06:00
|
|
|
CC = $(shell cat psinfo/$(PLAT)/cc.txt)
|
2019-04-22 08:39:46 -05:00
|
|
|
AS = $(shell cat psinfo/$(PLAT)/as.txt)
|
|
|
|
AR = $(shell cat psinfo/$(PLAT)/ar.txt)
|
2019-04-22 13:16:50 -05:00
|
|
|
NASM = $(shell cat psinfo/$(PLAT)/nasm.txt)
|
2019-04-22 08:39:46 -05:00
|
|
|
EMU = $(shell cat psinfo/$(PLAT)/emu.txt)
|
2019-02-09 12:52:45 -06:00
|
|
|
GDB = $(shell cat psinfo/$(PLAT)/gdb.txt)
|
2019-03-31 13:10:40 -05:00
|
|
|
CFLAGS = -Isysroot/usr/include -Wextra -Wall -Wno-unused-parameter -g -ffreestanding
|
2019-04-21 07:38:55 -05:00
|
|
|
QFLAGS = -hda image.img -m 2G -boot d -cdrom os.iso -serial stdio #-chardev socket,id=s1,port=3000,host=localhost -serial chardev:s1
|
2019-02-09 12:52:45 -06:00
|
|
|
|
2019-03-31 13:10:40 -05:00
|
|
|
.PHONY: sysroot
|
|
|
|
|
2019-02-09 12:52:45 -06:00
|
|
|
all: os.iso
|
|
|
|
|
|
|
|
run: os.iso
|
2019-04-22 08:39:46 -05:00
|
|
|
$(EMU) $(QFLAGS) > drv_log # -monitor stdio
|
2019-02-09 12:52:45 -06:00
|
|
|
|
|
|
|
debug: os.iso kernel/kernel.elf
|
2019-04-22 16:42:34 -05:00
|
|
|
$(EMU) -s $(QFLAGS) &
|
2019-02-09 12:52:45 -06:00
|
|
|
$(GDB) -ex "target remote localhost:1234" -ex "symbol-file kernel/kernel.elf"
|
|
|
|
|
2019-03-17 18:04:50 -05:00
|
|
|
os.iso: kernel/kernel.elf initrd/* initrd/prog.elf
|
2019-02-09 12:52:45 -06:00
|
|
|
cp kernel/kernel.elf iso/boot
|
|
|
|
ruby makeinitrd.rb initrd iso/boot/initrd
|
|
|
|
grub-mkrescue -o $@ iso
|
|
|
|
|
2019-03-17 18:04:50 -05:00
|
|
|
initrd/prog.elf: prog/*
|
|
|
|
cd prog && make
|
|
|
|
cp prog/prog.elf initrd
|
|
|
|
|
2019-04-22 08:39:46 -05:00
|
|
|
kernel/kernel.elf: $(OBJ) $(ASM_OBJ) $(S_ASM_OBJ) libc/libc.a
|
2019-04-22 13:17:33 -05:00
|
|
|
$(CC) -Xlinker -n -T cpu/$(PLAT)/linker.ld -o $@ $(CFLAGS) -nostdlib $^ -lgcc
|
2019-02-09 12:52:45 -06:00
|
|
|
|
2019-03-31 13:10:40 -05:00
|
|
|
sysroot: $(LIBC_HEADERS)
|
2019-04-06 09:07:19 -05:00
|
|
|
mkdir -p sysroot/usr/include
|
2019-03-31 13:10:40 -05:00
|
|
|
cp -r libc/* sysroot/usr/include
|
|
|
|
rm -f sysroot/usr/include/libc.a sysroot/usr/include/*.o sysroot/usr/include/*/*.o sysroot/usr/include/*.c sysroot/usr/include/*/*.c
|
|
|
|
|
|
|
|
|
2019-03-30 11:44:01 -05:00
|
|
|
libc/libc.a: $(LIBC_OBJ)
|
2019-04-22 08:39:46 -05:00
|
|
|
$(AR) rcs $@ $^
|
2019-03-30 11:44:01 -05:00
|
|
|
|
2019-03-31 13:10:40 -05:00
|
|
|
%.o: %.c sysroot
|
2019-02-09 12:52:45 -06:00
|
|
|
$(CC) $(CFLAGS) -c $< -o $@
|
|
|
|
|
|
|
|
%.o: %.asm
|
2019-04-22 13:16:50 -05:00
|
|
|
$(NASM) $< -o $@
|
2019-02-09 12:52:45 -06:00
|
|
|
|
|
|
|
%.o: %.s
|
2019-04-22 08:39:46 -05:00
|
|
|
$(AS) $< -o $@
|
2019-02-09 12:52:45 -06:00
|
|
|
|
|
|
|
clean:
|
2019-04-22 08:39:46 -05:00
|
|
|
rm -rf $(OBJ) $(OBJ) $(ASM_OBJ) $(S_ASM_OBJ) libc/libc.a kernel/cstart.o cpu/memory.h os.iso */*.elf iso/boot/initrd.tar
|