Skip to content

Commit e254f20

Browse files
authored
Add files via upload
1 parent ff69b0c commit e254f20

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

Makefile

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# $@ = target file
2+
# $< = first dependency
3+
# $^ = all dependencies
4+
5+
# detect all .o files based on their .c source
6+
C_SOURCES = $(wildcard kernel/*.c drivers/*.c cpu/*.c)
7+
HEADERS = $(wildcard kernel/*.h drivers/*.h cpu/*.h)
8+
OBJ_FILES = ${C_SOURCES:.c=.o cpu/interrupt.o}
9+
10+
# First rule is the one executed when no parameters are fed to the Makefile
11+
all: run
12+
13+
# Notice how dependencies are built as needed
14+
kernel.bin: boot/kernel_entry.o ${OBJ_FILES}
15+
ld -m elf_i386 -o $@ -Ttext 0x1000 $^ --oformat binary
16+
17+
os-image.bin: boot/mbr.bin kernel.bin
18+
cat $^ > $@
19+
20+
run: os-image.bin
21+
qemu-system-i386 -fda $<
22+
23+
echo: os-image.bin
24+
xxd $<
25+
26+
# only for debug
27+
kernel.elf: boot/kernel_entry.o ${OBJ_FILES}
28+
ld -m elf_i386 -o $@ -Ttext 0x1000 $^
29+
30+
debug: os-image.bin kernel.elf
31+
qemu-system-i386 -s -S -fda os-image.bin -d guest_errors,int &
32+
i386-elf-gdb -ex "target remote localhost:1234" -ex "symbol-file kernel.elf"
33+
34+
%.o: %.c ${HEADERS}
35+
gcc -g -m32 -ffreestanding -c $< -o $@ -fno-PIC # -g for debugging
36+
37+
%.o: %.asm
38+
nasm $< -f elf -o $@
39+
40+
%.bin: %.asm
41+
nasm $< -f bin -o $@
42+
43+
%.dis: %.bin
44+
ndisasm -b 32 $< > $@
45+
46+
clean:
47+
$(RM) *.bin *.o *.dis *.elf
48+
$(RM) kernel/*.o
49+
$(RM) boot/*.o boot/*.bin
50+
$(RM) drivers/*.o
51+
$(RM) cpu/*.o

0 commit comments

Comments
 (0)