summaryrefslogtreecommitdiff
path: root/src/makefile
blob: bb92e5f62e2b80517ddbee4e02795d27b224f668 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
LD=../compiler/indigo_gcc/bin/x86_64-elf-ld
CC=../compiler/indigo_gcc/bin/x86_64-pc-linux-gnu-gcc
OBJCPY=../compiler/indigo_gcc/bin/x86_64-elf-objcopy
INC=-I./include

EMU_CORES=4
EMU_RAM=5G
XRES=1024
YRES=768

CFLAGS=-g -ffreestanding -mcmodel=kernel -masm=intel -Wall -O0

C_SRCFILES := $(wildcard kernel/*.c)
C_SRCFILES := $(filter-out kernel/isv.c, $(C_SRCFILES))
C_OBJFILES := $(patsubst kernel/%.c,%.o,$(C_SRCFILES))

ASM_SRCFILES := $(wildcard kernel/*.asm)
ASM_SRCFILES := $(filter-out kernel/smp_trampoline.asm, $(ASM_SRCFILES))
ASM_OBJFILES := $(patsubst kernel/%.asm,%.o,$(ASM_SRCFILES))


MISC_OBJFILES := isv.o #this will probably expand over time for files that require special treatment
OBJFILES_PATH := $(patsubst %,objects/%,$(C_OBJFILES) $(ASM_OBJFILES) $(MISC_OBJFILES))

QEMU_OPTS=-smp $(EMU_CORES) -m $(EMU_RAM) -no-reboot -drive format=raw,file=./indigo_os

QEMU_CPU=-cpu host,+invtsc,+tsc-deadline

ifndef disable-kvm
	QEMU_OPTS := $(QEMU_OPTS) -enable-kvm $(QEMU_CPU)
endif

QEMU_PRINTDEBUG=-d int,guest_errors



all: $(ASM_OBJFILES) $(C_OBJFILES) $(MISC_OBJFILES) bootloader.o smp_trampoline.o
	$(LD) -o indigo_os.elf --no-check-sections --oformat=elf64-x86-64 -T link.ld $(OBJFILES_PATH)
	$(OBJCPY) --only-keep-debug indigo_os.elf debug/debug_syms.o
	$(OBJCPY) -O binary --strip-all indigo_os.elf indigo_os
	compiledb make --dry-run > /dev/null


isv.o: kernel/isv.c
	$(CC) $(CFLAGS) $(INC) -mgeneral-regs-only -MMD -MP -c kernel/isv.c -o objects/$@

%.o: kernel/%.c makefile
	$(CC) $(CFLAGS) $(INC) -MMD -MP -c $< -o objects/$@

%.o: kernel/%.asm makefile
	nasm -g -felf64 $< -o objects/$@

bootloader.o: 
	nasm -g -felf64 bootloader/bootloader.asm -o objects/bootloader.o

smp_trampoline.o:
	nasm -g -felf64 kernel/smp_trampoline.asm -o objects/smp_trampoline.o

run:
	qemu-system-x86_64 $(QEMU_OPTS) $(QEMU_PRINTDEBUG) -nographic

run_quiet:
	qemu-system-x86_64 $(QEMU_OPTS) $(QEMU_PRINTDEBUG) -nographic 2>/dev/null

gdb: indigo_os
	tmux new-session -s os_gdb "qemu-system-x86_64 -S -s $(QEMU_OPTS) -nographic"\;\
		split-window -h "gdb -x debug/gdbinit.gdb; killall qemu-system-x86_64"

run-graphical:
	qemu-system-x86_64 -device VGA,edid=on,xres=$(XRES),yres=$(YRES) -S -s $(QEMU_OPTS) &\
		gdb -x debug/gdbinit.gdb; killall qemu-system-x86_64


install-sandisk: indigo_os
	test -h /dev/disk/by-id/usb-SanDisk_Cruzer_Fit_4C531001351010112404-0:0 && \
	sudo dd if=indigo_os of=/dev/disk/by-id/usb-SanDisk_Cruzer_Fit_4C531001351010112404-0:0 && \
	sync

install-trav: indigo_os
	test -h /dev/disk/by-id/usb-Kingston_DataTraveler_3.0_E0D55EA573F1E3A11963008B-0:0 && \
	sudo dd if=indigo_os of=/dev/disk/by-id/usb-Kingston_DataTraveler_3.0_E0D55EA573F1E3A11963008B-0:0	&& \
	sync

	
clean:
	rm -f objects/*
	rm -f indigo_os
	rm -f indigo_os.elf
	rm -f bin/*
	rm -f debug/debug_syms.o