summaryrefslogtreecommitdiff
path: root/makefile
blob: 25582d1cf8a4cb49980e1d0a3746c8960ae591af (plain) (blame)
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
kgccargs = -Wall -Wsuggest-attribute=pure -Wsuggest-attribute=const -m32 -Og -ffreestanding -fno-asynchronous-unwind-tables
ugccargs = ${kgccargs} -Isrc/user/include
nasmargs = -f elf32
partlink = -r -m elf_i386

out/disk.vdi: out/disk.img
	rm out/disk.vdi || true
	VBoxManage convertfromraw out/disk.img out/disk.vdi --uuid a61929ed-3bf2-45ff-b98a-44f87c616dba

out/disk.img: out/kernel.bin out/boot.bin out/fs
	#TODO: have this regenerate after out/fs
	mkdir -p obj
	/sbin/mkfs.fat -C -f 1 -F 16 -n "PORTLAND OS" -R 65 -s 1 -S 512 obj/shadow.img 8192
	echo -n -e '\xeb\x3c' > obj/jmp.bin
	dd if=obj/jmp.bin of=obj/shadow.img obs=2 conv=notrunc
	dd if=out/boot.bin of=obj/shadow.img obs=1 seek=62 conv=notrunc
	dd if=out/kernel.bin of=obj/shadow.img seek=1 conv=notrunc
	mv obj/shadow.img out/disk.img
	mcopy -i out/disk.img -s out/fs/* ::/

debug: out/disk.img
	gdb -x qemu-debug.gdb

clean:
	rm -r obj out || true

out/fs/bin/%: obj/%.elf
	mkdir -p $(shell dirname $@)
	objcopy -S $< $@

out/fs: out/fs/bin/init  out/fs/bin/meminfo  out/fs/bin/highway \
        out/fs/bin/hello out/fs/bin/dumptext out/fs/bin/dumphex
	mkdir -p out/fs
	cp -r fs-skel/* out/fs/

obj/kernel/%.ko: src/kernel/%.c
	mkdir -p $(shell dirname $@)
	gcc ${kgccargs} -c $< -o $@

obj/kernel/%.kao: src/kernel/%.asm
	mkdir -p $(shell dirname $@)
	nasm ${nasmargs} $< -o $@

out/kernel.bin: obj/kernel/drive.ko  obj/kernel/fat.ko   obj/kernel/ide.ko    \
                obj/kernel/idt.ko    obj/kernel/log.ko   obj/kernel/main.ko   \
                obj/kernel/main2.ko  obj/kernel/pmap.ko  obj/kernel/paging.ko \
                obj/kernel/panic.ko  obj/kernel/pci.ko   obj/kernel/elf.ko    \
                obj/kernel/serial.ko obj/kernel/task.ko  obj/kernel/util.ko   \
                obj/kernel/vga.ko    obj/kernel/isrs.kao obj/kernel/kbd.ko
	mkdir -p out
	ld -T src/kernel/elf-link.ld obj/kernel/* -o obj/kernel.elf
	objcopy -O binary obj/kernel.elf out/kernel.bin

out/boot.bin: src/boot.asm
	mkdir -p out
	nasm src/boot.asm -o out/boot.bin

obj/%.o: src/user/%.c
	mkdir -p $(shell dirname $@)
	gcc ${ugccargs} -c $< -o $@

obj/%.ao: src/user/%.asm
	mkdir -p $(shell dirname $@)
	nasm ${nasmargs} $< -o $@

obj/knob.so: obj/knob/env.o  obj/knob/file.o   obj/knob/format.o \
             obj/knob/heap.o obj/knob/quit.o   obj/knob/user.o   \
             obj/knob/task.o obj/knob/entry.ao obj/knob/block.o
	ld ${partlink} obj/knob/* -o obj/knob.so

obj/init.elf: obj/init/init.o obj/knob.so
	ld -T src/user/elf.ld obj/init/* obj/knob.so -o obj/init.elf

obj/meminfo.elf: obj/meminfo/meminfo.o obj/knob.so
	ld -T src/user/elf.ld obj/meminfo/* obj/knob.so -o obj/meminfo.elf

obj/highway.elf: obj/highway/highway.o obj/knob.so
	ld -T src/user/elf.ld obj/highway/* obj/knob.so -o obj/highway.elf

obj/hello.elf: obj/hello/hello.ao
	ld -T src/user/elf.ld obj/hello/* -o obj/hello.elf

obj/dumptext.elf: obj/dumptext/dumptext.o
	ld -T src/user/elf.ld obj/dumptext/* obj/knob.so -o obj/dumptext.elf

obj/dumphex.elf: obj/dumphex/dumphex.o
	ld -T src/user/elf.ld obj/dumphex/* obj/knob.so -o obj/dumphex.elf