-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
156 lines (127 loc) · 4.75 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
.PHONY : \
all \
clean \
run \
run-qemu-cd-grub \
run-qemu-cd-isolinux \
run-qemu-hd-efi
CFLAGS = -W -Wall -nodefaultlibs \
-nostdlib -ffreestanding -O3 -ggdb -mgeneral-regs-only \
-mcmodel=kernel -mno-red-zone -Iinclude/ -fno-pic \
-fno-stack-protector -masm=intel -flto -no-pie
SRC = $(wildcard *.c)
OBJ = $(SRC:.c=.o)
ASMSRC = $(wildcard *.asm)
ASMOBJ = $(ASMSRC:.asm=.o)
BOOT_CD_GRUB_MENU_FILE = output/cdroot/boot/grub/menu.lst
BOOT_CD_ISOLINUX_MENU_FILE = output/cdroot/isolinux/isolinux.cfg
all: kernel.bin boot.bin user.bin
prep:
mkdir -p fs
mount -o loop=/dev/loop1 fs.bin fs/
install: kernel.bin boot.bin user.bin
cp boot/boot.bin fs/boot/
cp kernel.bin fs/boot/
cp user/user.bin fs/boot/
sync
boot.bin:
$(MAKE) -C boot/
user.bin:
$(MAKE) -C user/
kernel.bin: $(OBJ) $(ASMOBJ)
gcc -Wl,-Tlinker.ld $(OBJ) $(ASMOBJ) -o kernel.bin \
-Wl,-z,max-page-size=4096 -Wl,-Map,kernel.map $(CFLAGS)
%.o : %.asm
nasm -felf64 $^ -o $@
%.o : %.c
$(CC) $^ -c -o $@ $(CFLAGS)
output:
mkdir $@
output/boot-cd-grub.iso : user.bin kernel.bin boot.bin output
mkdir -p output/cdroot/boot/grub
cp -f 3rdparty/grub/stage2_eltorito output/cdroot/boot/grub/
cp -f boot/boot.bin output/cdroot/boros.bin
cp -f kernel.bin output/cdroot/kernel.bin
cp -f user/user.bin output/cdroot/user.bin
echo "default 0" > $(BOOT_CD_GRUB_MENU_FILE)
echo "timeout 1" >> $(BOOT_CD_GRUB_MENU_FILE)
echo "title boros" >> $(BOOT_CD_GRUB_MENU_FILE)
echo " root (cd)" >> $(BOOT_CD_GRUB_MENU_FILE)
echo " kernel (cd)/boros.bin" >> $(BOOT_CD_GRUB_MENU_FILE)
echo " module (cd)/kernel.bin" >> $(BOOT_CD_GRUB_MENU_FILE)
echo " module (cd)/user.bin" >> $(BOOT_CD_GRUB_MENU_FILE)
mkisofs \
-o $@ \
-b boot/grub/stage2_eltorito \
-boot-info-table \
-boot-load-size 4 \
-no-emul-boot \
-joliet \
-rational-rock \
-graft-points boot/grub/grub.conf=output/cdroot/boot/grub/menu.lst \
output/cdroot
output/boot-cd-isolinux.iso : kernel.bin boot.bin output
mkdir -p output/cdroot/isolinux
cp -f 3rdparty/syslinux/bios/isolinux.bin output/cdroot/isolinux/
cp -f 3rdparty/syslinux/bios/ldlinux.c32 output/cdroot/isolinux/
cp -f 3rdparty/syslinux/bios/libcom32.c32 output/cdroot/isolinux/
cp -f 3rdparty/syslinux/bios/libmenu.c32 output/cdroot/isolinux/
cp -f 3rdparty/syslinux/bios/libutil.c32 output/cdroot/isolinux/
cp -f 3rdparty/syslinux/bios/mboot.c32 output/cdroot/isolinux/
cp -f 3rdparty/syslinux/bios/menu.c32 output/cdroot/isolinux/
cp -f boot/boot.bin output/cdroot/boros.bin
cp -f kernel.bin output/cdroot/kernel.bin
echo "ui menu.c32" > $(BOOT_CD_ISOLINUX_MENU_FILE)
echo "prompt 0" >> $(BOOT_CD_ISOLINUX_MENU_FILE)
echo "timeout 10" >> $(BOOT_CD_ISOLINUX_MENU_FILE)
echo "default boros" >> $(BOOT_CD_ISOLINUX_MENU_FILE)
echo "label boros" >> $(BOOT_CD_ISOLINUX_MENU_FILE)
echo " kernel /isolinux/mboot.c32" >> $(BOOT_CD_ISOLINUX_MENU_FILE)
echo " append /boros.bin" >> $(BOOT_CD_ISOLINUX_MENU_FILE)
mkisofs \
-o $@ \
-b isolinux/isolinux.bin \
-boot-info-table \
-boot-load-size 4 \
-c boot.cat \
-joliet \
-no-emul-boot \
-rational-rock \
output/cdroot
output/hd-efi.img : kernel.bin boot.bin output
dd if=/dev/zero of=$@ bs=1M count=64
sgdisk --new=1:1M:+62M --typecode=1:ef00 $@
dd if=/dev/zero of=output/fat.img bs=1M count=62
mkdosfs -F 32 output/fat.img
mmd -i output/fat.img ::/EFI
mmd -i output/fat.img ::/EFI/BOOT
mmd -i output/fat.img ::/loader
mmd -i output/fat.img ::/loader/entries
echo "timeout 1" > output/boros.conf
echo "default boros" >> output/boros.conf
echo "title boros" >> output/boros.conf
echo "linux /boros.bin" >> output/boros.conf
echo "timeout 1" > output/loader.conf
echo "default boros" >> output/loader.conf
mcopy -i output/fat.img 3rdparty/systemd/systemd-bootx64.efi ::/EFI/BOOT/bootx64.efi
mcopy -i output/fat.img output/loader.conf ::/loader/
mcopy -i output/fat.img output/boros.conf ::/loader/entries/
mcopy -i output/fat.img boot/boot.bin ::/boros.bin
dd if=output/fat.img of=$@ bs=1M seek=1 conv=notrunc
run: boot.bin kernel.bin install
bochs
run-qemu-cd-grub : output/boot-cd-grub.iso
qemu-system-x86_64 -enable-kvm -m 256 -boot d \
-drive file=$<,format=raw,media=cdrom \
run-qemu-cd-isolinux : output/boot-cd-isolinux.iso
qemu-system-x86_64 -enable-kvm -m 256 -boot d \
-drive file=$<,format=raw,media=cdrom \
run-qemu-hd-efi : output/hd-efi.img
qemu-system-x86_64 -enable-kvm -m 256 -boot c \
-drive file=$<,format=raw \
-bios /usr/share/ovmf/ovmf_code_x64.bin
clean:
$(MAKE) -C boot clean
$(MAKE) -C user clean
-rm *.o kernel.bin kernel.map
-rm -rf output/*