-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
54 lines (42 loc) · 1.5 KB
/
Makefile
File metadata and controls
54 lines (42 loc) · 1.5 KB
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
C_SOURCES = $(wildcard kernel/*.c drivers/*.c cpu/*.c libc/*.c OS-relavent/*.c)
HEADERS = $(wildcard kernel/*.h drivers/*.h cpu/*.h libc/*.h OS-relavent/*.h)
# $@ = target file
# $< = first dependency
# $^ = all dependencies
OBJ = ${C_SOURCES:.c=.o cpu/interrupt.o}
CFLAGS = -m32 -ffreestanding -c
# First rule is the one executed when no parameters are fed to the Makefile
all: run
# Notice how dependencies are built as needed
kernel.bin: boot/kernel_entry.o ${OBJ}
ld -m elf_i386 -o $@ -Ttext 0x1000 $^ --oformat binary
#i386-elf-ld
kernel/kernel_entry.o: boot/kernel_entry.asm
nasm $< -f elf32 -o $@
# compilation in 64-bit
kernel/kernel.o: kernel/kernel.c drivers/ports.h drivers/ports.c
gcc -m32 -ffreestanding -Wall -c $< -o $@
# i386-elf-gcc -ffreestanding -c
# Rule to disassemble the kernel - may be useful to debug
kernel.dis: kernel.bin
ndisasm -b 32 $< > $@
bootsect.bin: boot/boot.asm
nasm $< -f bin -o $@
os-image.bin: bootsect.bin kernel.bin
cat $^ > $@
run: os-image.bin
qemu-system-x86_64 -drive format=raw,file=os-image.bin
kernel.elf: boot/kernel_entry.o ${OBJ}
ld -m elf_i386 -o $@ -Ttext 0x1000 $^
debug: os-image.bin kernel.elf
qemu-system-x64_86 -s -fda os-image.bin &
gdb -ex "target remote localhost:1234" -ex "symbol-file kernel.elf"
%.o: %.c ${HEADERS}
gcc ${CFLAGS} $< -o $@
%.o: %.asm
nasm $< -f elf -o $@
%.bin: %.asm
nasm $< -f bin -o $@
clean:
rm -rf *.bin *.dis *.o os-image.bin *.elf
rm -rf kernel/*.o boot/*.bin drivers/*.o boot/*.o cpu/*.o libc/*.o OS-relavent/*.o