-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathMakefile
288 lines (247 loc) · 7.92 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# Custom config file? Otherwise use defaults.
-include config.mk
# Quiet. Run "make Q=" for a verbose build.
Q ?= @
# Prefix to use for ELF build tools, if the native toolchain isn't
# ELF. E.g., x86_64-jos-elf-
TOOLPREFIX ?=
# QEMU binary
QEMU ?= qemu-system-x86_64
# Number of CPUs to emulate
QEMUSMP ?= 8
# RAM to simulate (in MB)
QEMUMEM ?= 512
# Default hardware build target. See param.h for others.
HW ?= qemu
# Enable C++ exception handling in the kernel.
EXCEPTIONS ?= y
# Shell command to run in VM after booting
RUN ?= $(empty)
# Python binary
PYTHON ?= python
# Directory containing mtrace-magic.h for HW=mtrace
MTRACESRC ?= ../mtrace
# Mtrace-enabled QEMU binary
MTRACE ?= $(MTRACESRC)/x86_64-softmmu/qemu-system-x86_64
O = o.$(HW)
ifeq ($(HW),linux)
PLATFORM := native
TOOLPREFIX :=
else
ifeq ($(HW),linuxmtrace)
# Build the user space for mtrace'ing under Linux. This builds an
# initramfs of xv6's user space that can be booted on a Linux kernel.
# Make targets like qemu and mtrace.out are supported if the user
# provides KERN=path/to/Linux/bzImage to make.
PLATFORM := native
TOOLPREFIX :=
else
PLATFORM := xv6
endif
endif
ifeq ($(HW),codex)
CODEXINC = -Icodexinc
else
CODEXINC =
endif
ifdef USE_CLANG
CC = $(TOOLPREFIX)clang
CXX = $(TOOLPREFIX)clang++
CXXFLAGS = -Wno-delete-non-virtual-dtor -Wno-gnu-designator -Wno-tautological-compare -Wno-unused-private-field
CFLAGS = -no-integrated-as
ASFLAGS =
else
CC ?= $(TOOLPREFIX)gcc
CXX ?= $(TOOLPREFIX)g++
CXXFLAGS = -Wno-delete-non-virtual-dtor
CFLAGS =
ASFLAGS = -Wa,--divide
endif
LD = $(TOOLPREFIX)ld
NM = $(TOOLPREFIX)nm
OBJCOPY = $(TOOLPREFIX)objcopy
STRIP = $(TOOLPREFIX)strip
ifeq ($(PLATFORM),xv6)
INCLUDES = --sysroot=$(O)/sysroot \
-iquote include -iquote$(O)/include \
-iquote libutil/include \
-Istdinc $(CODEXINC) -I$(MTRACESRC) \
-include param.h -include libutil/include/compiler.h
COMFLAGS = -static -DXV6_HW=$(HW) -DXV6 \
-fno-builtin -fno-strict-aliasing -fno-omit-frame-pointer -fms-extensions \
-mno-red-zone
COMFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector) -I$(shell $(CC) -print-file-name=include)
COMFLAGS += -Wl,-m,elf_x86_64 -nostdlib -ffreestanding
LDFLAGS = -m elf_x86_64
else
INCLUDES := -include param.h -iquote libutil/include -I$(MTRACESRC)
COMFLAGS := -pthread -Wno-unused-result
LDFLAGS := -pthread
endif
COMFLAGS += -g -MD -MP -O3 -Wall -Werror -DHW_$(HW) $(INCLUDES)
CFLAGS := $(COMFLAGS) -std=c99 $(CFLAGS)
CXXFLAGS := $(COMFLAGS) -std=c++0x -Wno-sign-compare $(CXXFLAGS)
ASFLAGS := $(ASFLAGS) -Iinclude -I$(O)/include -m64 -gdwarf-2 -MD -MP -DHW_$(HW) -include param.h
ifeq ($(EXCEPTIONS),y)
# Include C++ support libraries for stack unwinding and RTTI. Some of
# the objects in these archives depend on symbols we don't define, but
# we provide our own definitions for any symbols we do use from such
# objects, so the linker ignores these objects entirely. If you start
# getting "multiple definition" and "undefined reference" errors,
# there's probably a new ABI symbol we need to define ourselves.
CXXRUNTIME = $(shell $(CC) -print-file-name=libgcc_eh.a) \
$(shell $(CC) -print-file-name=libsupc++.a)
CXXFLAGS += -DEXCEPTIONS=1
ifndef USE_CLANG
CXXFLAGS += -fnothrow-opt -Wnoexcept
endif
else
CXXRUNTIME =
CXXFLAGS += -fno-exceptions -fno-rtti -DEXCEPTIONS=0
endif
HAVE_TESTGEN = $(shell (test -e libutil/testgen.c && echo y) || echo n)
ALL :=
all:
define SYSCALLGEN
@echo " GEN $@"
$(Q)mkdir -p $(@D)
$(Q)$(PYTHON) tools/syscalls.py $(1) kernel/*.cc > [email protected]
$(Q)cmp -s [email protected] $@ || mv [email protected] $@
endef
ifeq ($(PLATFORM),xv6)
include net/Makefrag
include kernel/Makefrag
include lib/Makefrag
endif
include libutil/Makefrag
include bin/Makefrag
include tools/Makefrag
include metis/Makefrag
$(O)/%.o: %.c $(O)/sysroot
@echo " CC $@"
$(Q)mkdir -p $(@D)
$(Q)$(CC) $(CFLAGS) -c -o $@ $<
$(O)/%.o: %.cc $(O)/sysroot
@echo " CXX $@"
$(Q)mkdir -p $(@D)
$(Q)$(CXX) $(CXXFLAGS) -c -o $@ $<
$(O)/%.o: $(O)/%.cc $(O)/sysroot
@echo " CXX $@"
$(Q)mkdir -p $(@D)
$(Q)$(CXX) $(CXXFLAGS) -c -o $@ $<
$(O)/%.o: %.S
@echo " CC $@"
$(Q)mkdir -p $(@D)
$(Q)$(CC) $(ASFLAGS) -c -o $@ $<
$(O)/%.o: $(O)/%.S
@echo " CC $@"
$(Q)mkdir -p $(@D)
$(Q)$(CC) $(ASFLAGS) -c -o $@ $<
# Construct an alternate "system include root" by copying headers from
# the host that are part of C++'s freestanding implementation. These
# headers are distributed across several directories, so we reproduce
# that directory tree here and let GCC use its standard (large)
# include path, but re-rooted at this new directory.
$(O)/sysroot: include/host_hdrs.hh
rm -rf [email protected] $@
mkdir -p [email protected]
tar c $$($(CXX) -E -H -std=c++0x -ffreestanding $< -o /dev/null 2>&1 \
| awk '/^[.]/ {print $$2}') | tar xC [email protected]
mv [email protected] $@
xv6memfs.img: bootblock kernelmemfs
dd if=/dev/zero of=xv6memfs.img count=10000
dd if=bootblock of=xv6memfs.img conv=notrunc
dd if=kernelmemfs of=xv6memfs.img seek=1 conv=notrunc
$(O)/fs.img: $(O)/tools/mkfs $(FSEXTRA) $(UPROGS)
@echo " MKFS $@"
$(Q)$(O)/tools/mkfs $@ $(FSEXTRA) $(UPROGS)
.PRECIOUS: $(O)/%.o
.PHONY: clean qemu gdb rsync codex
##
## qemu
##
ifeq ($(PLATFORM),native)
override QEMUAPPEND += console=ttyS0
# Exit qemu on panic
override QEMUAPPEND += panic=-1
QEMUOPTS += -no-reboot
endif
## One NUMA node per CPU when mtrace'ing
ifeq ($(HW),linuxmtrace)
QEMUSMP := 4
QEMUMEM := 1024
else ifeq ($(HW),mtrace)
QEMUSMP := 4
QEMUMEM := 1024
endif
ifneq ($(RUN),)
override QEMUAPPEND += \$$ $(RUN)
endif
QEMUOPTS += -smp $(QEMUSMP) -m $(QEMUMEM) \
$(if $(QEMUOUTPUT),-serial file:$(QEMUOUTPUT),-serial mon:stdio) \
-nographic \
-numa node -numa node \
-net user -net nic,model=e1000 \
$(if $(QEMUNOREDIR),,-redir tcp:2323::23 -redir tcp:8080::80) \
$(if $(QEMUAPPEND),-append "$(QEMUAPPEND)",) \
## One NUMA node per CPU when mtrace'ing
ifeq ($(HW),linuxmtrace)
QEMUOPTS += -numa node -numa node
else ifeq ($(HW),mtrace)
QEMUOPTS += -numa node -numa node
endif
ifeq ($(PLATFORM),xv6)
QEMUOPTS += -device ahci,id=ahci0 \
-drive if=none,file=$(O)/fs.img,format=raw,id=drive-sata0-0-0 \
-device ide-drive,bus=ahci0.0,drive=drive-sata0-0-0,id=sata0-0-0
qemu: $(O)/fs.img
endif
ifeq ($(PLATFORM),native)
QEMUOPTS += -initrd $(O)/initramfs
endif
# User-provided QEMU options
QEMUOPTS += $(QEMUEXTRA)
qemu: $(KERN)
$(QEMU) $(QEMUOPTS) $(QEMUKVMFLAGS) -kernel $(KERN)
gdb: $(KERN)
$(QEMU) $(QEMUOPTS) $(QEMUKVMFLAGS) -kernel $(KERN) -s
codex: $(KERN)
##
## mtrace
##
MTRACEOUT ?= mtrace.out
MTRACEOPTS = -rtc clock=vm -mtrace-enable -mtrace-file $(MTRACEOUT) \
-mtrace-calls -snapshot
$(MTRACEOUT): $(KERN)
$(Q)rm -f $(MTRACEOUT)
$(MTRACE) $(QEMUOPTS) $(MTRACEOPTS) -kernel $(KERN) -s
$(MTRACEOUT)-scripted:
$(Q)rm -f $(MTRACEOUT)
$(MTRACE) $(QEMUOPTS) $(MTRACEOPTS) -kernel $(KERN)
.PHONY: $(MTRACEOUT) $(MTRACEOUT)-scripted
mscan.out: $(MTRACESRC)/mtrace-tools/mscan $(MTRACEOUT)
$(MTRACESRC)/mtrace-tools/mscan --kernel $(KERN) > $@ || (rm -f $@; exit 2)
mscan.sorted: mscan.out $(MTRACESRC)/mtrace-tools/sersec-sort
$(MTRACESRC)/mtrace-tools/sersec-sort < $< > $@
rsync: $(KERN)
rsync -avP $(KERN) amsterdam.csail.mit.edu:/tftpboot/$(HW)/kernel.xv6
ifneq ($(HW),tom)
IPMIOPTS = -A MD5 -U ADMIN
endif
reboot-xv6: setup-xv6
ssh amsterdam.csail.mit.edu \
ipmitool -I lanplus $(IPMIOPTS) -H $(HW)adm.csail.mit.edu -f/home/am6/mpdev/.ipmipassword power reset
setup-xv6:
ssh amsterdam.csail.mit.edu \
sed -i .bak "'s/^default /#&/;/^# *default xv6/s/^# *//'" /tftpboot/$(HW)/pxelinux.cfg
reboot-linux: setup-linux
ssh amsterdam.csail.mit.edu \
ipmitool -I lanplus $(IPMIOPTS) -H $(HW)adm.csail.mit.edu -f/home/am6/mpdev/.ipmipassword power reset
setup-linux:
ssh amsterdam.csail.mit.edu \
sed -i .bak "'s/^default /#&/;/^# *default localboot/s/^# *//'" /tftpboot/$(HW)/pxelinux.cfg
bench:
/bin/echo -ne "xv6\\nbench\\nexit\\n" | nc $(HW).csail.mit.edu 23
clean:
rm -fr $(O)
all: $(ALL)