-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
63 lines (51 loc) · 1.49 KB
/
Makefile
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
SHELL = /bin/bash
LODEV = /dev/loop0
IMGFN = disk.img
CC = gcc -std=c1x -ggdb -m64 -ffreestanding -mcmodel=kernel -O0 -Wall -Wextra
LD = ld -melf_x86_64 -nostdlib -z max-page-size=0x1000
QEMU = qemu-system-x86_64
QEMUFLAGS = -hda disk.img -net none $(QEMUARGS)
all: rundbg
clean:
rm -f .copy
rm -f boot.o kernel64.o
rm -f kernel
veryclean: clean
rm -f disk.img .disk
.disk:
dd if=/dev/zero bs=4096 count=32768 of=$(IMGFN) status=none
/sbin/parted -s $(IMGFN) mklabel msdos >/dev/null
/sbin/parted -s $(IMGFN) mkpart primary ext2 2048s 100% >/dev/null
sudo losetup $(LODEV) $(IMGFN)
sudo partprobe $(LODEV)
sudo mke2fs -q $(LODEV)p1
sudo mount $(LODEV)p1 /mnt
sudo mkdir -p /mnt/grub
echo -e '(hd0)\t$(LODEV)' | sudo tee /mnt/grub/device.map > /dev/null
sudo grub-install --modules 'part_msdos ext2 normal' --boot-directory /mnt $(LODEV)
sudo chgrp disk -R /mnt
sudo chmod g+w -R /mnt
sudo umount /mnt
sudo losetup -d $(LODEV)
touch $@
.copy: kernel grub.cfg .disk
sudo losetup $(LODEV) $(IMGFN)
sudo partprobe $(LODEV)
sudo mount $(LODEV)p1 /mnt
cp grub.cfg /mnt/grub/
sed -i s/OUTPUT/$</g /mnt/grub/grub.cfg
cp $< /mnt/
touch $@
sudo umount /mnt
sudo losetup -d $(LODEV)
%.o: %.S constants.h
$(CC) -c -o $@ $<
%.o: %.c
$(CC) -c -o $@ $<
kernel: linker.ld boot.o kernel64.o
$(LD) -o $@ -T $^
rundbg: .copy
gdb-multiarch -ex 'break start64' -ex 'target remote | exec $(QEMU) $(QEMUFLAGS) -S -gdb stdio' kernel
run: .copy
$(QEMU) $(QEMUFLAGS)
.PHONY: run rundbg clean veryclean