forked from lezione-os/lezione
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
184 lines (156 loc) · 5.11 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# List of defined commands
# build rule is not to be used by the user, however it is included in this list to make makefile
# evaluate it
.PHONY: build-debug build-release clean kernel-clean run-release run-debug run-safe run-ci cloc
# Use timestamp of the commit to ensure that builds are reproducible
export SOURCE_DATE_EPOCH=$(shell git show -s --format=%ct)
XORRISO_DATE=$(shell git log -1 --format="%at" | xargs -I{} date -d @{} +%Y%m%d%H%M%S00)
# Machine to test on
MACHINE=numa-distances
# Rule for xbstrap init
build/bootstrap.link:
mkdir -p build
cd build && xbstrap init .
# Build image with release kernel
ricerca-release.iso: KERNEL_PKG = "release-kernel"
ricerca-release.iso: IMAGE = "ricerca-release.iso"
ricerca-release.iso: image
# Build image with debug kernel
ricerca-debug.iso: KERNEL_PKG = "debug-kernel"
ricerca-debug.iso: IMAGE = "ricerca-debug.iso"
ricerca-debug.iso: image
# Build image with safe kernel
ricerca-safe.iso: KERNEL_PKG = "safe-kernel"
ricerca-safe.iso: IMAGE = "ricerca-safe.iso"
ricerca-safe.iso: image
# Build image with profile kernel
ricerca-profile.iso: KERNEL_PKG = "profile-kernel"
ricerca-profile.iso: IMAGE = "ricerca-profile.iso"
ricerca-profile.iso: image
# Generic image build rule
image: build/bootstrap.link
# Clean sysroot
rm -rf build/system-root/*
# Install limine
cd build && xbstrap install-tool limine
# Reinstall system files
cd build && xbstrap install system-files --rebuild
# Reinstall kernel
cd build && xbstrap install $(KERNEL_PKG) --rebuild
# Reinstall limine CD files
cd build && xbstrap install limine-cd --rebuild
# Add limine files for network boot
cd build && xbstrap install limine-pxe --rebuild
# Delete existing image
rm -f $(IMAGE)
# Create image with xorriso
echo $(SOURCE_DATE_EPOCH)
xorriso -volume_date "all_file_dates" $(XORRISO_DATE) \
-as mkisofs -b boot/limine-cd.bin \
-no-emul-boot -boot-load-size 4 -boot-info-table \
--efi-boot boot/limine-eltorito-efi.bin \
-efi-boot-part --efi-boot-image --protective-msdos-label \
build/system-root -o $(IMAGE)
# Install limine for legacy BIOS boot
build/build-tools/limine/limine-install $(IMAGE)
# Clean rule
# Deletes kernel object files, kernel binaries, and images
clean:
make -C src/kernel clean
rm -rf ricerca-debug.iso ricerca-release.iso ricerca-safe.iso ricerca-profile.iso
# Binary clean rule
# Clears only kenrel binaries and object files
kernel-clean:
LAIPATH=$(shell pwd)/build/libraries/lai make -C src/kernel clean
# Run release image in QEMU with KVM enabled
run-release-kvm: ricerca-release.iso
qemu-system-x86_64 \
-cdrom ricerca-release.iso \
-debugcon file:e9.vt100 \
-no-shutdown -no-reboot \
--enable-kvm \
`cat machines/$(MACHINE) | tr '\n' ' '`
# Run safe image in QEMU with KVM enabled
run-safe-kvm: ricerca-safe.iso
qemu-system-x86_64 \
-cdrom ricerca-safe.iso \
-debugcon file:e9.vt100 \
-no-shutdown -no-reboot \
--enable-kvm \
`cat machines/$(MACHINE) | tr '\n' ' '`
# Run release image in QEMU without KVM enabled
run-release-tcg: ricerca-release.iso
qemu-system-x86_64 \
-cdrom ricerca-release.iso \
-debugcon file:e9.vt100 \
-no-shutdown -no-reboot \
-d int \
`cat machines/$(MACHINE) | tr '\n' ' '`
# Run safe image in QEMU without KVM enabled
run-safe-tcg: ricerca-safe.iso
qemu-system-x86_64 \
-cdrom ricerca-safe.iso \
-debugcon file:e9.vt100 \
-no-shutdown -no-reboot \
-d int \
`cat machines/$(MACHINE) | tr '\n' ' '`
# Run profiling kernel build in QEMU with KVM enabled
profile-kvm: ricerca-profile.iso
qemu-system-x86_64 \
-cdrom ricerca-profile.iso \
-debugcon file:profiling/dump \
-no-shutdown -no-reboot \
--enable-kvm \
`cat machines/$(MACHINE) | tr '\n' ' '`
python3 profile/process.py
# Run profiling kernel build in QEMU without KVM enabled
profile-tcg: ricerca-profile.iso
qemu-system-x86_64 \
-cdrom ricerca-profile.iso \
-debugcon file:profiling/dump \
-no-shutdown -no-reboot \
`cat machines/$(MACHINE) | tr '\n' ' '`
python3 profile/process.py
# Run image on CI rule.
# Image runs in TCG with 2 minute timeout
run-ci: ricerca-safe.iso
qemu-system-x86_64 \
-cdrom ricerca-safe.iso \
-debugcon file:e9.vt100 \
-display none \
-no-shutdown -no-reboot \
`cat machines/$(MACHINE) | tr '\n' ' '`
# Start QEMU with debug image and wait for debugger to attach
debug: ricerca-debug.iso
qemu-system-x86_64 \
-cdrom ricerca-debug.iso \
-debugcon file:e9.vt100 \
-S -s \
-no-shutdown -no-reboot \
`cat machines/$(MACHINE) | tr '\n' ' '`
# Attach GDB to running session
gdb-attach:
gdb -x gdb-startup
# Release build rule
build-release: ricerca-release.iso
# Debug build rule
build-debug: ricerca-debug.iso
# Safe build rule
build-safe: ricerca-safe.iso
# Profile build rule
build-profile: ricerca-profile.iso
# Find symbol by address rule
kernel-addr2line:
addr2line -e build/system-root/boot/ricerca-kernel.elf $(SYMBOL)
# List kernel symbols
kernel-nm:
nm -n build/system-root/boot/ricerca-kernel.elf
# Output lines of code info
kernel-cloc:
cloc src/kernel
# Run bloaty on kernel binary
kernel-bloaty:
bloaty build/system-root/boot/ricerca-kernel.elf -d compileunits
# Run radare2 on kernel binary
kernel-radare2:
radare2 build/system-root/boot/ricerca-kernel.elf