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
INCLUDE = include
KERNEL = kernel.o ide.o console.o ext2.o blockdev.o kmem.o paging.o atpic.o proc.o scheduler.o bitmap.o
HEADERS = $(shell find include/ -type f)
CC = i686-elf-gcc
image: disk1.raw
disk1.qcow2: disk1.raw
qemu-img convert -f raw -O qcow $< $@
boot2.o: boot2.c
$(CC) -c -I $(INCLUDE) -o $@ -nostdinc -ffreestanding -Wall -Wextra -Os -std=gnu99 $<
%.o: %.c $(HEADERS)
$(CC) -c -I $(INCLUDE) -o $@ -nostdinc -ffreestanding -Wall -Wextra -O2 -std=gnu99 $<
#disk1.raw: mbr.bin boot1.bin linked.bin
disk1.raw: mbr.bin boot root.img
dd if=mbr.bin bs=512 conv=notrunc of=$@ count=1 2>/dev/null
dd if=boot of=$@ conv=notrunc bs=512 seek=1 2>/dev/null
dd if=root.img of=$@ conv=notrunc bs=512 seek=10 2>/dev/null
root.img: data.txt kernel bin/init.asm bin/init2.asm
mkdir -p fsroot
mkdir -p fsroot/boot
cp data.txt fsroot
cp kernel fsroot/boot/kernel
nasm -f bin -o fsroot/init bin/init.asm
nasm -f bin -o fsroot/init2 bin/init2.asm
genext2fs -b 20000 -d fsroot $@
mbr.bin: mbr.xxd boot0
xxd -r mbr.xxd $@
dd if=boot0 of=$@ conv=notrunc bs=1 2>/dev/null
boot0: boot0.asm
nasm -f bin -o $@ $<
boot1.o: boot1.asm
nasm -f elf -o $@ $<
interrupt.o: interrupt.asm assym.asm
nasm -f elf -o $@ $<
entry.o: entry.asm assym.asm
nasm -f elf -o $@ $<
assym.asm: genassym.o $(HEADERS)
i686-elf-nm $< | ./genassym.py > $@
boot: linker.ld boot1.o boot2.o
$(CC) -T linker.ld -o $@ -ffreestanding -Os -nostdlib boot1.o boot2.o
kernel: kernel.ld entry.o interrupt.o $(KERNEL)
$(CC) -T kernel.ld -o $@ -ffreestanding -O2 -nostdlib entry.o interrupt.o $(KERNEL)
clean:
rm -f mbr.bin boot0 boot $(KERNEL) boot1.ldbin
rm -f boot1.o boot2.o entry.o interrupt.o
rm -f kernel genassym.o assym.asm
rm -f fsroot/init fsroot/init2 fsroot/boot/kernel
rm -f disk1.raw root.img
rm -f test
.PHONY: clean