-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
83 lines (71 loc) · 2.15 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
# basic information
BOOT_TARGET ?= x86_64-uefi
KERNEL_TARGET ?= x86_64-demos
# build artifact locations
BUILD_BOOT_DIR = target/$(BOOT_TARGET)/debug
EFI_EXE ?= boot.efi
EFI_IN = $(BUILD_BOOT_DIR)/$(EFI_EXE)
BUILD_KERNEL_DIR = target/$(KERNEL_TARGET)/debug
KERNEL_IN = $(BUILD_KERNEL_DIR)/kernel
# output structure
ESP_DIR = target/esp
BOOT_DIR = $(ESP_DIR)/efi/boot
EFI_OUT = $(BOOT_DIR)/bootx64.efi
KERNEL_OUT = $(ESP_DIR)/kernel
# binary names
QEMU = qemu-system-x86_64
CARGO = cargo
# ovmf firmware information
FIRMWARE = firmware
OVMF_CODE = $(FIRMWARE)/ovmf_code.fd
OVMF_VARS = $(FIRMWARE)/ovmf_vars.fd
# a massive declaration of all the qemu flags we need
QEMU_FLAGS ?=
# disable machine defaults, we are in control
QFLAGS = -nodefaults
# use standard vga for graphics output
# QFLAGS += -vga std
# just kidding. use a serial console for now.
QFLAGS += -nographic
QFLAGS += -serial stdio
# use a modern machine, preferably with acceleration
QFLAGS += -machine q35,accel=kvm:tcg
# give us plenty of memory to work with (relatively...)
QFLAGS += -m 128M
# hook in ovmf
QFLAGS += -drive if=pflash,format=raw,file=$(OVMF_CODE),readonly=on
QFLAGS += -drive if=pflash,format=raw,file=$(OVMF_VARS),readonly=on
# create an ahci controller (what is this?)
QFLAGS += -device ahci,id=ahci,multifunction=on
# mount our local esp directory in as a FAT partition
QFLAGS += -drive if=none,format=raw,file=fat:rw:$(ESP_DIR),id=esp
QFLAGS += -device ide-drive,bus=ahci.0,drive=esp
# some debugging stuff I don't understand
QFLAGS += -debugcon file:demos.log -global isa-debugcon.iobase=0xE9
# QFLAGS += -debugcon file:debug.log -global isa-debugcon.iobase=0x402
# allow arbitrary flags to get plugged in
QFLAGS += $(QEMU_FLAGS)
all: boot kernel
.PHONY: all
boot:
$(CARGO) xbuild --target $(BOOT_TARGET).json --package boot
.PHONY: boot
kernel:
$(CARGO) xbuild --target $(KERNEL_TARGET).json --package kernel
.PHONY: kernel
esp: boot kernel
# copy the build artifact
mkdir -p $(BOOT_DIR)
cp $(EFI_IN) $(EFI_OUT)
cp $(KERNEL_IN) $(KERNEL_OUT)
.PHONY: esp
debug: esp
$(QEMU) -s -S $(QFLAGS)
.PHONY: debug
run: esp
# run qemu
$(QEMU) $(QFLAGS)
.PHONY: run
clean:
$(CARGO) clean
.PHONY: clean