Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure that the sancus examples can be compiled with the SLLVM-based toolchain #7

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
84252b5
Make sure that the sancus examples can be compiled with the SLLVM too…
Dec 28, 2018
25c90fd
Use correct .s name
Dec 28, 2018
54c8b2c
Add missing include
Dec 28, 2018
87680f7
Make sure that the sancus examples can be compiled with the SLLVM too…
Dec 28, 2018
912214c
Make sure to garbage collect unused trusted rt functions
Dec 29, 2018
22124ec
Make sure that the sancus examples can be compiled with the SLLVM too…
Dec 29, 2018
d050e95
Make sure that the sancus examples can be compiled with the SLLVM too…
Dec 30, 2018
1ce063e
Make sure that the sancus examples can be compiled with the SLLVM too…
Dec 30, 2018
6f7b080
Make sure that the sancus examples can be compiled with the SLLVM too…
Dec 31, 2018
dbab966
Make sure that the sancus examples can be compiled with the SLLVM too…
Dec 31, 2018
8245866
Fixed typo
Dec 31, 2018
a995b55
Make sure that the sancus examples can be compiled with the SLLVM too…
Jan 1, 2019
74dd26e
Make sure that the sancus examples can be compiled with the SLLVM too…
Jan 1, 2019
4f204ae
Add support for secure MMIO (SLLVM-based toolchain)
Jan 4, 2019
95eb0ba
Automate returning from mmio entry funcs
Jan 4, 2019
47cd06e
Specify key size via command line
Jan 8, 2019
12b5ff6
Support cross compilation unit protected modules
Jan 15, 2019
3b11dc5
Keep intermediate files
Jan 15, 2019
a5d475d
https://bugs.llvm.org/show_bug.cgi?id=39993 should be fixed
Jan 16, 2019
b66830c
Add llc debug flag
Jan 19, 2019
7d8e175
Add Sancus transformation options
Jan 25, 2019
38960dd
Rename secure linking sections
Jan 31, 2019
c0799b4
Fix merge conflict
Mar 27, 2019
f0fa669
Merge remote-tracking branch 'upstream/master'
Mar 27, 2019
0db7821
Temporary disable timer example due to broken build since latest upst…
Mar 27, 2019
36db83a
Fix broken build due to sancus-step commit on upstream master
Mar 28, 2019
9ef42cf
Add support for sancus-step
Mar 28, 2019
c02b7e4
Add support for sancus-step
Mar 28, 2019
a6fddaa
Add support for sancus-step
Mar 28, 2019
3e81ad3
Add support for sancus-step
Mar 28, 2019
529b82c
Merge remote-tracking branch 'upstream/master'
Jul 1, 2019
4dacbec
Merge remote-tracking branch 'upstream/master'
Jul 2, 2019
3e591aa
Fix broken build after last sync with Sancus upstream
Jul 2, 2019
3623c55
Merge remote-tracking branch 'upstream/master'
Nov 26, 2019
50af5e1
Merge remote-tracking branch 'upstream/master'
Feb 28, 2020
3f46b88
(Temporary) disable failing hello-library example
Mar 2, 2020
dab4688
Merge remote-tracking branch 'upstream/master'
Mar 5, 2020
52abe34
Merge remote-tracking branch 'upstream/master'
May 27, 2020
a37a6e5
Merge remote-tracking branch 'upstream/master'
Jul 13, 2020
732e331
Use iverilog based simulator
Jul 29, 2020
167892f
Use Verilator-based Sancus simulator
Aug 6, 2020
9977329
Adapt to LLVM 14
Oct 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
*.fst
*.fst.*
*.out
*.ll
*.s
168 changes: 137 additions & 31 deletions Makefile.include
Original file line number Diff line number Diff line change
@@ -1,40 +1,146 @@
ifndef SANCUS_DIR
SANCUS_SUPPORT_DIR = "/usr/local/share/sancus-support"
ifndef SANCUS_SECURITY
SANCUS_SECURITY = 64
endif

ifeq ($(SANCUS_SECURITY), 64)
SANCUS_KEY = deadbeefcafebabe
else
SANCUS_SUPPORT_DIR = ${SANCUS_DIR}/share/sancus-support
SANCUS_KEY = deadbeefcafebabec0defeeddefec8ed
endif

ifndef SANCUS_SECURITY
SANCUS_SECURITY = 64
ifndef SLLVM_INSTALL_DIR
CC = sancus-cc
LD = sancus-ld
SANCUS_CRYPTO = sancus-crypto
SANCUS_SIM = sancus-sim
else
SANCUS_DIR = $(SLLVM_INSTALL_DIR)
CC = $(SLLVM_INSTALL_DIR)/bin/clang
OPT = $(SLLVM_INSTALL_DIR)/bin/opt
LLC = $(SLLVM_INSTALL_DIR)/bin/llc
LD = $(SLLVM_INSTALL_DIR)/bin/msp430-elf-gcc
SANCUS_CRYPTO = $(SLLVM_INSTALL_DIR)/bin/crypto.py
SANCUS_SIM = $(SLLVM_INSTALL_DIR)/bin/sancus-sim
AS = $(SLLVM_INSTALL_DIR)/bin/msp430-elf-gcc
endif
ifeq ($(SANCUS_SECURITY), 64)
SANCUS_KEY = deadbeefcafebabe

ifndef SANCUS_DIR
SANCUS_SUPPORT_DIR = "/usr/local/share/sancus-support"
else
SANCUS_KEY = deadbeefcafebabec0defeeddefec8ed
SANCUS_SUPPORT_DIR = $(SANCUS_DIR)/share/sancus-support
endif

CC = sancus-cc
LD = sancus-ld
SANCUS_CRYPTO = sancus-crypto
SANCUS_SIM = sancus-sim
SANCUS_LOAD = sancus-loader
RM = rm -f

VENDOR_ID = 1234
RAM_SIZE = 16K
ROM_SIZE = 41K
FPGA_DEV = /dev/ttyUSB0
FPGA_RATE = 115200

VENDOR_KEY = $(shell $(SANCUS_CRYPTO) --key $(SANCUS_KEY) --gen-vendor-key $(VENDOR_ID) | xxd -p)
MEMFLAGS = --ram $(RAM_SIZE) --rom $(ROM_SIZE)

CFLAGS = -I$(SANCUS_SUPPORT_DIR)/include/ -Wfatal-errors -fcolor-diagnostics -Os -g
LDFLAGS = -L$(SANCUS_SUPPORT_DIR)/lib/ $(MEMFLAGS) -lsm-io -ldev --inline-arithmetic --standalone --verbose
SIMFLAGS = $(MEMFLAGS)
CRYPTOFLAGS = --key $(VENDOR_KEY) --verbose
LOADFLAGS = -device $(FPGA_DEV) -baudrate $(FPGA_RATE)

ifeq ($(QUIET),1)
MCU = msp430sancus

SANCUS_LOAD = sancus-loader
RM = rm -f

VENDOR_ID = 1234
STACK_SIZE = 128
RAM_SIZE = 16K
ROM_SIZE = 41K
FPGA_DEV = /dev/ttyUSB0
FPGA_RATE = 115200
VENDOR_KEY = $(shell $(SANCUS_CRYPTO) --key $(SANCUS_KEY) --gen-vendor-key $(VENDOR_ID) | xxd -p)

CFLAGS =
CFLAGS += -Wfatal-errors
CFLAGS += -fcolor-diagnostics

LDFLAGS =
LDFLAGS += -L$(SANCUS_SUPPORT_DIR)/lib/
LDFLAGS += -lsm-io
LDFLAGS += -ldev

ifndef SLLVM_INSTALL_DIR
CFLAGS += -I$(SANCUS_SUPPORT_DIR)/include/
CFLAGS += -Os
CFLAGS += -g

ifeq ($(QUIET),1)
CFLAGS += -DQUIET
endif

LDFLAGS += --inline-arithmetic
LDFLAGS += --standalone
LDFLAGS += --verbose
else
INCFLAGS =
INCFLAGS += -I $(SLLVM_INSTALL_DIR)/include
INCFLAGS += -I $(SLLVM_INSTALL_DIR)/msp430-elf/include
INCFLAGS += -I $(SLLVM_INSTALL_DIR)/share/sancus-support/include
INCFLAGS += -I $(SLLVM_INSTALL_DIR)/share/sancus-compiler/include

CFLAGS += $(INCFLAGS)
CFLAGS += -D__$(shell echo $(MCU) | tr a-z A-Z)__
CFLAGS += -DCONFIG_SECURITY=$(SANCUS_SECURITY)
CFLAGS += -Werror
CFLAGS += -O0
CFLAGS += -target msp430-elf
CFLAGS += -emit-llvm

SLLVM_TRANSFORM_FLAGS =
SLLVM_TRANSFORM_FLAGS += --load $(SLLVM_INSTALL_DIR)/lib/SLLVM.so
SLLVM_TRANSFORM_FLAGS += --sllvm-transform
SLLVM_TRANSFORM_FLAGS += --enable-new-pm=0

SANCUS_TRANSFORM_FLAGS =
SANCUS_TRANSFORM_FLAGS += --load $(SLLVM_INSTALL_DIR)/lib/SLLVM.so
SANCUS_TRANSFORM_FLAGS += --sancus-transform
SANCUS_TRANSFORM_FLAGS += --key-size $(SANCUS_SECURITY)
SANCUS_TRANSFORM_FLAGS += --stack-size $(STACK_SIZE)
SANCUS_TRANSFORM_FLAGS += --vendor-id 0x$(VENDOR_ID)
SANCUS_TRANSFORM_FLAGS += --enable-new-pm=0

LLCFLAGS =
LLCFLAGS += -O3
#LLCFLAGS += -debug-only=msp430-lower

ASFLAGS =
ASFLAGS += $(INCFLAGS)
ASFLAGS += -mmcu=$(MCU)

LDFLAGS += -L $(SLLVM_INSTALL_DIR)/share/sancus-compiler/lib
LDFLAGS += -l sancus-sm-support
LDFLAGS += -L $(SLLVM_INSTALL_DIR)/include # For devices.csv and $(MCU).ld
LDFLAGS += -Wl,-gc-sections # To garbage collect unused trusted rt functions
LDFLAGS += -mmcu=$(MCU)
endif

SIMFLAGS =

CRYPTOFLAGS =
CRYPTOFLAGS += --key $(VENDOR_KEY)
CRYPTOFLAGS += --verbose

LOADFLAGS =
LOADFLAGS += -device $(FPGA_DEV)
LOADFLAGS += -baudrate $(FPGA_RATE)

#----------------------------------------------------------------------------

ifdef SLLVM_INSTALL_DIR

.SUFFIXES:

.PRECIOUS: %.ll
.PRECIOUS: %.sllvm.ll
.PRECIOUS: %.sancus.ll
.PRECIOUS: %.s

%.ll: %.c
$(CC) $(CFLAGS) -S $< -o $@

%.sllvm.ll: %.ll
$(OPT) $(SLLVM_TRANSFORM_FLAGS) -S $< -o $@ > /dev/null

%.sancus.ll: %.sllvm.ll
$(OPT) $(SANCUS_TRANSFORM_FLAGS) -S $< -o $@ > /dev/null

%.s: %.sancus.ll
$(LLC) $(LLCFLAGS) $< -o $@

%.o: %.s
$(AS) $(ASFLAGS) -c $< -o $@

endif
8 changes: 5 additions & 3 deletions arithmetic/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ TARGET_NO_MAC = no_mac_$(TARGET)
all: $(TARGET)

$(TARGET_NO_MAC): $(OBJECTS)
$(LD) $(LDFLAGS) -o $@ $^
$(LD) $^ $(LDFLAGS) -o $@

$(TARGET): $(TARGET_NO_MAC)
$(SANCUS_CRYPTO) --fill-macs $(CRYPTOFLAGS) -o $@ $<
Expand All @@ -22,5 +22,7 @@ sim: $(TARGET)

clean:
$(RM) $(TARGET) $(TARGET_NO_MAC) $(OBJECTS)
rm -f sim-input.bin sim-output.bin
rm -f *.fst *.vcd
$(RM) sim-input.bin sim-output.bin
$(RM) -f *.fst *.vcd
$(RM) *.ll
$(RM) *.s
9 changes: 9 additions & 0 deletions arithmetic/data.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sllvm_pm_bar_data_start = .;
*(.sllvm.data.bar)
*(.sllvm.data.lr1addr.bar) /* Make sure the pointer to local sp is put last */
sllvm_pm_bar_data_end = .;

sllvm_pm_foo_data_start = .;
*(.sllvm.data.foo)
*(.sllvm.data.lr1addr.foo) /* Make sure the pointer to local sp is put last */
sllvm_pm_foo_data_end = .;
1 change: 1 addition & 0 deletions arithmetic/foo.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
extern struct SancusModule foo;

int SM_ENTRY(foo) enter_foo(int i);
int SM_ENTRY(foo) foo_mul(int a, int b, int c);

#endif
14 changes: 14 additions & 0 deletions arithmetic/text.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
sllvm_pm_bar_text_start = .;
*(.sllvm.text.dispatch.bar) /* Make sure the dispatcher is put first */
*(.sllvm.text.bar)
*(.sllvm.text.bar.*) /* Internalized runtime functions */
sllvm_pm_bar_text_end = .;

sllvm_pm_foo_text_start = .;
*(.sllvm.text.dispatch.foo) /* Make sure the dispatcher is put first */
*(.sllvm.text.foo)
*(.sllvm.text.foo.*) /* Internalized runtime functions */
sllvm_pm_foo_text_end = .;

/* Symbols for secure linking */
*(.sllvm.slink.*)
8 changes: 5 additions & 3 deletions fileio/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ CFLAGS += -DTEST_DATA=\"$(TEST_DATA)\"
all: $(TARGET)

$(TARGET_NO_MAC): $(OBJECTS)
$(LD) $(LDFLAGS) -ldev-fileio -o $@ $^
$(LD) $^ $(LDFLAGS) -ldev-fileio -o $@

$(TARGET): $(TARGET_NO_MAC)
$(SANCUS_CRYPTO) --fill-macs $(CRYPTOFLAGS) -o $@ $<
Expand All @@ -28,5 +28,7 @@ sim: $(TARGET)

clean:
$(RM) $(TARGET) $(TARGET_NO_MAC) $(OBJECTS)
rm -f sim-input.bin sim-output.bin
rm -f *.fst *.vcd
$(RM) sim-input.bin sim-output.bin
$(RM) *.fst *.vcd
$(RM) *.ll
$(RM) *.s
14 changes: 11 additions & 3 deletions hello-library/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
include ../Makefile.include # Examples include
include ./Makefile.include # Library project include

ifdef SLLVM_INSTALL_DIR
sim:
clean:
else
LDFLAGS += --prepare-for-sm-text-section-wrapping
LDFLAGS += --scan-libraries-for-sm

SOURCES = $(shell ls *.c)
OBJECTS = $(SOURCES:.c=.o)

Expand All @@ -19,7 +26,7 @@ else
endif

# We need to give the full path of the library so that the linker can detect
LDFLAGS += -L$(LIBRARY_FOLDER) -l:$(CURDIR)/$(LIBRARY_FOLDER)/$(LIBRARY_FILENAME) --scan-libraries-for-sm
LDFLAGS += -L$(LIBRARY_FOLDER) -l:$(CURDIR)/$(LIBRARY_FOLDER)/$(LIBRARY_FILENAME)
CFLAGS += -I$(LIBRARY_FOLDER)

.PHONY: all $(LIBRARY_FOLDER) sim
Expand All @@ -32,12 +39,12 @@ archive: $(LIBRARY_FOLDER)
$(MAKE) -C $(LIBRARY_FOLDER) $(LIB_MODE)

$(TARGET_NO_WRAP): $(OBJECTS)
$(LD) $(LDFLAGS) --prepare-for-sm-text-section-wrapping -o $@ $^
$(LD) $(LDFLAGS) -o $@ $^

$(TARGET): $(TARGET_NO_WRAP)
$(SANCUS_CRYPTO) --wrap-sm-text-sections $(CRYPTOFLAGS) -o $@ $<

load: $(TARGET)
load: thin-archive $(TARGET)
$(SANCUS_LOAD) $(LOADFLAGS) $<

run-simulation: $(TARGET)
Expand All @@ -48,3 +55,4 @@ clean:
$(MAKE) -C $(LIBRARY_FOLDER) clean
rm -f sim-input.bin sim-output.bin
rm -f *.fst *.vcd
endif
12 changes: 9 additions & 3 deletions hello-world/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
include ../Makefile.include

ifndef SLLVM_INSTALL_DIR
LDFLAGS += --prepare-for-sm-text-section-wrapping
endif

SOURCES = $(shell ls *.c)
OBJECTS = $(SOURCES:.c=.o)

Expand All @@ -9,7 +13,7 @@ TARGET_NO_WRAP = no_wrap_$(TARGET)
all: $(TARGET)

$(TARGET_NO_WRAP): $(OBJECTS)
$(LD) $(LDFLAGS) --prepare-for-sm-text-section-wrapping -o $@ $^
$(LD) $^ $(LDFLAGS) -o $@

$(TARGET): $(TARGET_NO_WRAP)
$(SANCUS_CRYPTO) --wrap-sm-text-sections $(CRYPTOFLAGS) -o $@ $<
Expand All @@ -22,5 +26,7 @@ sim: $(TARGET)

clean:
$(RM) $(TARGET) $(TARGET_NO_MAC) $(OBJECTS)
rm -f sim-input.bin sim-output.bin
rm -f *.fst *.vcd
$(RM) sim-input.bin sim-output.bin
$(RM) *.fst *.vcd
$(RM) *.ll
$(RM) *.s
4 changes: 4 additions & 0 deletions hello-world/data.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sllvm_pm_hello_data_start = .;
*(.sllvm.data.hello)
*(.sllvm.data.lr1addr.hello) /* Make sure the pointer to local sp is put last */
sllvm_pm_hello_data_end = .;
File renamed without changes.
8 changes: 8 additions & 0 deletions hello-world/text.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sllvm_pm_hello_text_start = .;
*(.sllvm.text.dispatch.hello) /* Make sure the dispatcher is put first */
*(.sllvm.text.hello)
*(.sllvm.text.hello.*) /* Internalized runtime functions */
sllvm_pm_hello_text_end = .;

/* Wrap information */
*(.sllvm.wrap.*)
4 changes: 3 additions & 1 deletion sancus-step/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ TARGET_NO_MAC = no_mac_$(TARGET)
all: $(TARGET)

$(TARGET_NO_MAC): $(OBJECTS)
$(LD) $(LDFLAGS) -lsancus-step -o $@ $^
$(LD) $^ $(LDFLAGS) -lsancus-step -o $@

$(TARGET): $(TARGET_NO_MAC)
$(SANCUS_CRYPTO) --fill-macs $(CRYPTOFLAGS) -o $@ $<
Expand All @@ -24,3 +24,5 @@ clean:
$(RM) $(TARGET) $(TARGET_NO_MAC) $(OBJECTS)
rm -f sim-input.bin sim-output.bin
rm -f *.fst *.vcd
$(RM) *.ll
$(RM) *.s
9 changes: 9 additions & 0 deletions sancus-step/data.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sllvm_pm_foo_data_start = .;
*(.sllvm.data.foo)
*(.sllvm.data.lr1addr.foo) /* Make sure the pointer to local sp is put last */
sllvm_pm_foo_data_end = .;

sllvm_pm_sancus_step_data_start = .;
*(.sllvm.data.sancus_step)
*(.sllvm.data.lr1addr.sancus_step) /* Make sure pointer to local sp is last */
sllvm_pm_sancus_step_data_end = .;
6 changes: 6 additions & 0 deletions sancus-step/main.c → sancus-step/foo.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

#define MAX_COUNTER (0xf)

#if __clang_major__ >= 5
asm(".section __interrupt_vector_10,\"ax\",@progbits \n\t"
".word timerA_isr_entry2 \n\t");
#endif


int counter = 0x0;
int oldCounterValue = 0x0;
int instrAfterCtr = 0;
Expand Down
9 changes: 9 additions & 0 deletions sancus-step/text.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sllvm_pm_foo_text_start = .;
*(.sllvm.text.dispatch.foo) /* Make sure the dispatcher is put first */
*(.sllvm.text.foo)
sllvm_pm_foo_text_end = .;

sllvm_pm_sancus_step_text_start = .;
*(.sllvm.text.dispatch.sancus_step) /* Make sure the dispatcher is put first */
*(.sllvm.text.sancus_step)
sllvm_pm_sancus_step_text_end = .;
Loading