-
Notifications
You must be signed in to change notification settings - Fork 32
/
Makefile
152 lines (122 loc) · 3.1 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
# SPDX-License-Identifier: MIT
GCC = gcc
SHELL := /bin/bash
A_FLAGS := -D__ASSEMBLY__
C_FLAGS := -g -O2
C_FLAGS += -m64 -march=x86-64 -mno-sse2
C_FLAGS += -fno-stack-protector
C_FLAGS += -ffreestanding
C_FLAGS += -Wall -Wstrict-prototypes -Wno-address-of-packed-member
LD_FLAGS := -m64
LD_FLAGS += -nostdlib
LD_FLAGS += -Wl,-Tsrc/start/svsm.lds -Wl,--build-id=none
TARGET_DIR := target
TARGET := $(TARGET_DIR)/svsm-target/debug
OBJS := src/start/start.o
OBJS += $(TARGET)/liblinux_svsm.a
FEATURES := ""
## Memory layout
SVSM_GPA := 0x8000000000
SVSM_MEM := 0x10000000
LDS_FLAGS += -DSVSM_GPA="$(SVSM_GPA)"
LDS_FLAGS += -DSVSM_MEM="$(SVSM_MEM)"
EXT_LIBS := external/libcrt/libcrt.a
EXT_LIBS += external/openssl/libcrypto.a
.PHONY: all doc prereq clean clean_all superclean libcrt libcrypto
all: .prereq libcrt libcrypto svsm.bin
doc: .prereq
cargo doc --open
external/libcrt/libcrt.a: libcrt
libcrt:
$(MAKE) -C external/libcrt
external/openssl/libcrypto.a: libcrypto
libcrypto: external/openssl/Makefile libcrt
$(MAKE) -C external/openssl -j$$(nproc)
svsm.bin: svsm.bin.elf
objcopy -g -O binary $< $@
# "-Wl,-u,malloc" prevents the linker from removing the wrapper.rs symbols
svsm.bin.elf: $(EXT_LIBS) $(OBJS) src/start/svsm.lds
$(GCC) $(LD_FLAGS) -o $@ $(OBJS) -Wl,-u,malloc -Wl,--start-group $(EXT_LIBS) -Wl,--end-group
%.a: src/*.rs src/cpu/*.rs src/mem/*.rs src/protocols/*.rs src/util/*.rs
@xargo build --features $(FEATURES)
%.o: %.S src/start/svsm.h
$(GCC) $(C_FLAGS) $(LDS_FLAGS) $(A_FLAGS) -c -o $@ $<
%.lds: %.lds.S src/start/svsm.h
$(GCC) $(A_FLAGS) $(LDS_FLAGS) -E -P -o $@ $<
test:
cargo test --features $(FEATURES) --target=x86_64-unknown-linux-gnu -Z build-std
prereq: .prereq
.prereq:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $(HOME)/.cargo/env
echo "source $(HOME)/.cargo/env" >> ~/.bashrc
rustup component add rust-src
rustup component add llvm-tools-preview
cargo install xargo
cargo install bootimage
touch .prereq
external/openssl/Makefile:
git submodule update --init
(cd external/openssl && git checkout OpenSSL_1_1_1q && \
./Configure \
--config=../openssl_svsm.conf \
SVSM \
no-afalgeng \
no-async \
no-autoerrinit \
no-autoload-config \
no-bf \
no-blake2 \
no-capieng \
no-cast \
no-chacha \
no-cms \
no-ct \
no-deprecated \
no-des \
no-dgram \
no-dsa \
no-dynamic-engine \
no-ec2m \
no-engine \
no-err \
no-filenames \
no-gost \
no-hw \
no-idea \
no-md4 \
no-mdc2 \
no-pic \
no-ocb \
no-poly1305 \
no-posix-io \
no-rc2 \
no-rc4 \
no-rfc3779 \
no-rmd160 \
no-scrypt \
no-seed \
no-sock \
no-srp \
no-ssl \
no-stdio \
no-threads \
no-ts \
no-whirlpool \
no-shared \
no-sse2 \
no-ui-console \
no-asm \
--with-rand-seed=none \
-I../libcrt/include \
-Wl,rpath=../libcrt -lcrt )
clean:
@xargo clean
rm -f svsm.bin svsm.bin.elf $(OBJS)
rm -rf $(TARGET_DIR)
rm -f src/start/svsm.lds
clean_all: clean
$(MAKE) -C external/libcrt clean
$(MAKE) -C external/openssl clean
superclean: clean_all
rm -f .prereq