-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
78 lines (59 loc) · 1.95 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
# Find the Root Directory
SM_DIR:=$(realpath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
# Define compiler
PYTHON=python3
CC=riscv64-unknown-elf-gcc
OBJCOPY=riscv64-unknown-elf-objcopy
OBJDUMP=riscv64-unknown-elf-objdump
DEBUG_ENCLAVE=1
# Flags
# -mcmodel=medany is *very* important - it ensures the program addressing is PC-relative. Ensure no global variables are used. To quote from the spec, "the program and its statically defined symbols must lie within any single 2 GiB address range. Addressing for global symbols uses lui/addi instruction pairs, which emit the R_RISCV_PCREL_HI20/R_RISCV_PCREL_LO12_I sequences."
DEBUG_FLAGS := -ggdb3
CFLAGS := -march=rv64g -mcmodel=medany -mabi=lp64 -fno-common -fno-tree-loop-distribute-patterns -std=gnu11 -Wall -O3 $(DEBUG_FLAGS)
LDFLAGS := -nostartfiles -nostdlib -static
FLAGS_DEBUG_ENCLAVE :=
ifeq ($(DEBUG_ENCLAVE), 1)
FLAGS_DEBUG_ENCLAVE += -D DEBUG_ENCLAVE=1
CFLAGS += $(FLAGS_DEBUG_ENCLAVE)
endif
# QEMU
.PHONY: check_env
check_env:
ifndef SANCTUM_QEMU
$(error SANCTUM_QEMU is undefined)
endif
QEMU_FLAGS= -smp cpus=2 -machine sanctum -m 2G -nographic
DEBUG_QEMU_FLAGS= -S -s
# Define Directories
BUILD_DIR:=$(SM_DIR)/build
PLATFORM_DIR := $(SM_DIR)/platform
API_DIR := $(SM_DIR)/api
SM_SRC_DIR := $(SM_DIR)/src
SM_TEST_DIR := $(SM_DIR)/test
ENCLAVE_SRC_DIR := $(SM_DIR)/test/enclave
QUEUE_SRC_DIR := $(SM_DIR)/untrusted_infra/msgq
# Targets
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
ALL:=
include $(SM_SRC_DIR)/Makefrag
include $(SM_TEST_DIR)/Makefrag
.PHONY: all
all: $(ALL)
.PHONY: clean
clean:
-rm -rf $(BUILD_DIR)
ELFS := $(shell find $(BUILD) -name '*.elf')
ELFS_PREF := $(addprefix $(BUILD)/, $(ELFS))
DISASS = $(ELFS:.elf=.disa.out)
DISASS_SOURCES = $(ELFS:.elf=.src.out)
%.disa.out : %.elf
$(OBJDUMP) -D $^ > $@
%.src.out : %.elf
$(OBJDUMP) -S $^ > $@
.PHONY: disassemble-all
disassemble-all:$(DISASS)
.PHONY: source-all
source-all:$(DISASS_SOURCES)
# Print any variable for debug
print-%: ; @echo $*=$($*)