-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMfmain
277 lines (219 loc) · 10.4 KB
/
Mfmain
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
###############################################################################
# © Université Lille 1, The Pip Development Team (2015-2017) #
# #
# This software is a computer program whose purpose is to run a minimal, #
# hypervisor relying on proven properties such as memory isolation. #
# #
# This software is governed by the CeCILL license under French law and #
# abiding by the rules of distribution of free software. You can use, #
# modify and/ or redistribute the software under the terms of the CeCILL #
# license as circulated by CEA, CNRS and INRIA at the following URL #
# "http://www.cecill.info". #
# #
# As a counterpart to the access to the source code and rights to copy, #
# modify and redistribute granted by the license, users are provided only #
# with a limited warranty and the software's author, the holder of the #
# economic rights, and the successive licensors have only limited #
# liability. #
# #
# In this respect, the user's attention is drawn to the risks associated #
# with loading, using, modifying and/or developing or reproducing the #
# software by the user in light of its specific status of free software, #
# that may mean that it is complicated to manipulate, and that also #
# therefore means that it is reserved for developers and experienced #
# professionals having in-depth computer knowledge. Users are therefore #
# encouraged to load and test the software's suitability as regards their #
# requirements in conditions enabling the security of their systems and/or #
# data to be ensured and, more generally, to use and operate it in the #
# same conditions as regards security. #
# #
# The fact that you are presently reading this means that you have had #
# knowledge of the CeCILL license and that you accept its terms. #
###############################################################################
# Default values
KERNEL_ADDR=0x100000
PARTITION_ADDR=0x700000
STACK_ADDR=0x300000
TARGET=x86_multiboot
PARTITION=minimal
# Include architecture-and-platform-dependent cross-compilation toolchain
include conf/$(TARGET).mk
include conf/toolchain.mk
BUILD_DIR=build
TARGET_DIR=$(BUILD_DIR)/$(TARGET)
SRC_DIR=src
PROOF_DIR=proof
DIGGER_DIR=tools/digger
DIGGER=$(DIGGER_DIR)/digger
COQDEP=coqdep -c
COQC=coqc -q
COQDOC=coqdoc -toc -interpolate -utf8 -html
UNAME_S := $(shell uname -s)
# Doxygen
DOC=doxygen
DOCFILE=doc/doxygen.conf
# Coq Sources
COQCODEDIRS=$(SRC_DIR)/core $(SRC_DIR)/model
COQPROOFDIRS=$(PROOF_DIR) $(PROOF_DIR)/invariants
VCODESOURCES=$(foreach dir, ${COQCODEDIRS}, $(wildcard $(dir)/*.v))
VPROOFSOURCES=$(foreach dir, ${COQPROOFDIRS}, $(wildcard $(dir)/*.v))
VSOURCES=$(VCODESOURCES) $(VPROOFSOURCES)
VOBJECTS=$(VSOURCES:.v=.vo)
# JSON files extracted from Coq
JSONS=Internal.json Services.json
EXTRACTEDCSOURCES=$(addprefix $(TARGET_DIR)/, $(JSONS:.json=.c))
# Coq options
COQOPTS=$(shell cat _CoqProject)
# C and ASM sources
CSOURCES=$(wildcard $(SRC_DIR)/boot/$(TARGET)/*.c)
CSOURCES+=$(wildcard $(SRC_DIR)/MAL/$(TARGET)/*.c)
CSOURCES+=$(wildcard $(SRC_DIR)/IAL/$(TARGET)/*.c)
FULLCSOURCES=$(CSOURCES)
FULLCSOURCES+=$(EXTRACTEDCSOURCES)
ASOURCES=$(wildcard $(SRC_DIR)/boot/$(TARGET)/*.s)
ASOURCES+=$(wildcard $(SRC_DIR)/IAL/$(TARGET)/*.s)
# Generate the subsequent list of objects
COBJ=$(FULLCSOURCES:.c=.o)
AOBJ=$(ASOURCES:.s=.o)
COBJ+=$(TARGET_DIR)/multiplexer.o
# And tamper with it
COBJ:=$(patsubst %,$(TARGET_DIR)/%, $(notdir $(COBJ)))
AOBJ:=$(patsubst %,$(TARGET_DIR)/%, $(notdir $(AOBJ)))
# Includes
CFLAGS+=-I$(SRC_DIR)/MAL
CFLAGS+=-I$(SRC_DIR)/MAL/$(TARGET)
CFLAGS+=-I$(SRC_DIR)/IAL
CFLAGS+=-I$(SRC_DIR)/IAL/$(TARGET)
CFLAGS+=-I$(SRC_DIR)/boot/$(TARGET)/include
CFLAGS+=-I$(TARGET_DIR)/
all: kernel proofs doc
kernel: gitinfo $(TARGET_DIR) linker makefile.dep extract $(COBJ) $(AOBJ)
$(LD) $(AOBJ) $(COBJ) $(LDFLAGS) -T$(SRC_DIR)/boot/$(TARGET)/link.ld -o $(TARGET_DIR)/meso.bin
gitinfo:
printf "#ifndef __GIT__\n#define __GIT__\n#define GIT_REVISION \"`git rev-parse HEAD`\"\n#endif" > $(SRC_DIR)/boot/$(TARGET)/include/git.h
linker:
$(SED) -e "s/__KERNEL_LOAD_ADDR__/$(KERNEL_ADDR)/g" \
-e "s/__MULTIPLEXER_LOAD_ADDR__/$(PARTITION_ADDR)/g" \
-e "s/__KERNEL_STACK_ADDR__/$(STACK_ADDR)/g" \
$(SRC_DIR)/boot/$(TARGET)/link.ld.template \
> $(SRC_DIR)/boot/$(TARGET)/link.ld
# Use GCC to generate rules, convert multi-lines rules to single lines, remove empty lines and use $(BUILD_DIR) as target
makefile.dep:
$(CC) $(CFLAGS) -MM $(CSOURCES) | perl -pe 's/(\\[\r\n]+)//' | awk 'NF > 0' | $(SED) "s|^|$(TARGET_DIR)/|g" > $@
$(DIGGER):
make -C $(DIGGER_DIR)
# Extract C code from Coq source
$(JSONS): src/model/Extraction.vo
src/model/Extraction.vo: src/model/Extraction.v
$(COQC) $(COQOPTS) -w all $<
extract: $(DIGGER) $(TARGET_DIR) $(JSONS)
$(DIGGER) -m Hardware -M coq_LLI \
-m Datatypes -r Coq_true:true -r Coq_false:false -r Coq_tt:tt \
-m MALInternal -d :MALInternal.json \
-m MAL -d :MAL.json \
-m ADT -m Nat \
-q maldefines.h \
--ignore coq_N \
Internal.json \
> $(TARGET_DIR)/Internal.c
$(DIGGER) -m Hardware -M coq_LLI \
-m Datatypes -r Coq_true:true -r Coq_false:false -r Coq_tt:tt \
-m MALInternal -d :MALInternal.json \
-m MAL -d :MAL.json \
-m ADT -m Nat \
-q maldefines.h \
--ignore coq_N \
--header \
Internal.json -o $(TARGET_DIR)/Internal.h
proofs: $(VOBJECTS)
# Generate build directory
$(TARGET_DIR):
mkdir -p $@
include makefile.dep
-include $(addsuffix .d,$(VSOURCES))
# Build boot assembly files
$(TARGET_DIR)/%.o: $(SRC_DIR)/boot/$(TARGET)/%.s
$(AS) $(ASFLAGS) $< -o $@
# Build boot C files
$(TARGET_DIR)/%.o: $(SRC_DIR)/boot/$(TARGET)/%.c
$(CC) $(CFLAGS) $< -o $@
$(TARGET_DIR)/%.o: $(SRC_DIR)/MAL/$(TARGET)/%.c
$(CC) $(CFLAGS) $< -o $@
$(TARGET_DIR)/%.o: $(SRC_DIR)/IAL/$(TARGET)/%.c
$(CC) $(CFLAGS) $< -o $@
$(TARGET_DIR)/%.o: $(SRC_DIR)/IAL/$(TARGET)/%.s
$(AS) $(ASFLAGS) $< -o $@
# Implicit rules for Coq source files
$(addsuffix .d,$(VSOURCES)): %.v.d: %.v
@echo COQDEP "$<"
@$(COQDEP) $(COQOPTS) "$<" > "$@" || ( RV=$$?; rm -f "$@"; exit $${RV} )
%.vo: %.v
$(COQC) $(COQOPTS) $<
$(VSOURCES:.v=.glob): %.glob: %.vo
# This rule generates and builds an object file from the given partition binary
$(TARGET_DIR)/multiplexer.o: $(TARGET_DIR)/$(PARTITION).bin
printf "section .multiplexer\n\tINCBIN \"$<\"\n" > $(TARGET_DIR)/multiplexer.s
$(AS) $(ASFLAGS) -o $@ $(TARGET_DIR)/multiplexer.s
$(TARGET_DIR)/$(PARTITION).bin:
cp $(SRC_DIR)/partitions/$(ARCHITECTURE)/$(PARTITION)/$(PARTITION).bin $@
qemu:
$(QEMU) $(QEMUARGS)
test:
cd tests/MAL && make TARGET=$(TARGET) all
coq-enable-simulation:
$(SED) -i \
-e 's/^\( *\)(\* *BEGIN *SIMULATION *$$/\1(* BEGIN SIMULATION *)/' \
-e 's/^\( *\) END *SIMULATION *\*) *$$/\1(* END SIMULATION *)/' \
-e 's/^\( *\)(\* *BEGIN *NOT *SIMULATION *\*) *$$/\1(* BEGIN NOT SIMULATION/' \
-e 's/^\( *\)(\* *END *NOT *SIMULATION *\*) *$$/\1 END NOT SIMULATION *)/' \
$(VSOURCES)
coq-disable-simulation:
$(SED) -i \
-e 's/^\( *\)(\* *BEGIN *NOT *SIMULATION *$$/\1(* BEGIN NOT SIMULATION *)/' \
-e 's/^\( *\) END *NOT *SIMULATION *\*) *$$/\1(* END NOT SIMULATION *)/' \
-e 's/^\( *\)(\* *BEGIN *SIMULATION *\*) *$$/\1(* BEGIN SIMULATION/' \
-e 's/^\( *\)(\* *END *SIMULATION *\*) *$$/\1 END SIMULATION *)/' \
$(VSOURCES)
doc: doc-c doc-coq gettingstarted doc/Readme.html doc/PipInternals.html
doc-c:
cd doc && doxygen doxygen.conf
gettingstarted:
cd doc/GettingStarted && pdflatex GettingStarted.tex
doc-coq: $(VSOURCES) $(VSOURCES:.v=.glob)
mkdir -p doc/coq-doc
$(COQDOC) $(COQOPTS) -d doc/coq-doc $(VSOURCES)
coqwc:
coqwc $(VSOURCES)
partition:
rm -f $(TARGET_DIR)/$(PARTITION).bin
make -C $(SRC_DIR)/partitions/$(ARCHITECTURE)/$(PARTITION)
grub:
cp $(TARGET_DIR)/meso.bin tools/grub/boot/meso.bin
grub-mkrescue -o $(TARGET_DIR)/meso.iso tools/grub
@echo "Done, you can run "
@echo "$(QEMU) -boot d -cdrom $(TARGET_DIR)/meso.iso -m 8192 -serial stdio -vga std -netdev user,id=mynet0 -device rtl8139,netdev=mynet0"
@echo "to run the generated ISO."
update-headers:
find -\( -name \*.[cvhsS] -o -name \*.hs -o -name \*.ld -o -name \*.ld.template -o -name Makefile -o -name \*.mk -o -name doxygen.conf -\) -print0 | xargs -0 headache -c tools/headache.conf -h tools/copyright_header
clean: clean-c clean-coq
clean-coq:
rm -f Internal.h *.json
rm -f $(VOBJECTS) $(VSOURCES:.v=.v.d) $(VSOURCES:.v=.glob)
clean-c:
rm -rf $(TARGET_DIR)/
clean-mddoc:
rm -f doc/*.html
mrproper: clean-c clean-coq
rm -rf $(BUILD_DIR)
rm -f makefile.dep makefile.autocoq
doc/%.html: %.md
cat doc/mdtemplate.header > $@
$(SED) -i -e "s/###TITLE###/$(basename $<)/g" $@
cat $< >> $@
cat doc/mdtemplate.footer >> $@
bochs: grub
rm -f bochscom
mkfifo bochscom
cat bochscom &
bochs -q
.PHONY: all gitinfo linker extract proofs qemu test coq-enable-simulation coq-disable-simulation doc-c doc-coq doc partition grub clean mrproper clean-c clean-coq kernel gettingstarted clean-mddoc bochs