aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Bellows <greg.bellows@linaro.org>2015-04-13 14:32:42 -0500
committerGreg Bellows <greg.bellows@linaro.org>2015-04-13 15:22:06 -0500
commit9597f94e86197b72dffe8497e4ec890e504b8e20 (patch)
tree7190efb509c6945b0674aa3557b1784e1c8b4d34
parentccae1336439fe930787857f77b507f337129de53 (diff)
Merge 32-bit and 64-bit codeaarch32
Signed-off-by: Greg Bellows <greg.bellows@linaro.org>
-rw-r--r--.gdbinit23
-rw-r--r--.gdbinit6427
-rw-r--r--Makefile65
-rw-r--r--TESTCASES.txt (renamed from arm/TESTCASES.txt)0
-rw-r--r--aarch64.mk (renamed from aarch64/arch.mk)2
-rw-r--r--aarch64/Makefile46
-rw-r--r--aarch64/common/arch.h11
-rw-r--r--aarch64/common/arm64.h12
-rw-r--r--aarch64/common/interop.h53
-rw-r--r--aarch64/el0_common/el0_common.h18
-rw-r--r--aarch64/el0_ns/Makefile32
-rw-r--r--aarch64/el0_s/Makefile32
-rw-r--r--aarch64/el1_common/el1.c239
-rw-r--r--aarch64/el1_ns/Makefile35
-rw-r--r--aarch64/el1_ns/el1_nsec.c21
-rw-r--r--aarch64/el3/Makefile32
-rw-r--r--aarch64/el3/el3.c294
-rw-r--r--arm.mk3
-rw-r--r--arm/Makefile48
-rw-r--r--arm/arch.mk1
-rw-r--r--arm/common/arch.h11
-rw-r--r--arm/common/debug.h15
-rw-r--r--arm/common/mem_util.h11
-rw-r--r--arm/common/smc.h37
-rw-r--r--arm/common/svc.h50
-rw-r--r--arm/common/syscntl.h37
-rw-r--r--arm/el0_common/el0.c26
-rw-r--r--arm/el0_common/tztest.c173
-rw-r--r--arm/el0_common/tztest.h65
-rw-r--r--arm/el0_ns/el0.h11
-rw-r--r--arm/el0_ns/el0_nsec.lds.S24
-rw-r--r--arm/el0_ns/tztest_nsec.c79
-rw-r--r--arm/el0_s/el0.h11
-rw-r--r--arm/el0_s/el0_sec.lds.S24
-rw-r--r--arm/el0_s/tztest_sec.c83
-rw-r--r--arm/el1_common/el1_common.h18
-rw-r--r--arm/el1_ns/el1_nsec.lds.S35
-rw-r--r--arm/el1_s/Makefile35
-rw-r--r--arm/el1_s/el1_sec.c64
-rw-r--r--arm/el1_s/el1_sec.lds.S35
-rw-r--r--arm/el3/el3.h13
-rw-r--r--arm/el3/el3.lds.S35
-rw-r--r--common/aarch64/arm_builtins.h (renamed from aarch64/common/arm_builtins.h)0
-rw-r--r--common/aarch64/builtins.S (renamed from aarch64/common/builtins.S)0
-rw-r--r--common/aarch64/exception.h (renamed from aarch64/common/armv8_exception.h)0
-rw-r--r--common/aarch64/init_util.S (renamed from aarch64/common/init_util.S)2
-rw-r--r--common/aarch64/mem_util.c (renamed from aarch64/common/mem_util.c)2
-rw-r--r--common/aarch64/memory.h (renamed from aarch64/common/memory.h)0
-rw-r--r--common/aarch64/register.h (renamed from aarch64/common/armv8_regs.h)0
-rw-r--r--common/aarch64/vmsa.h (renamed from aarch64/common/armv8_vmsa.h)0
-rw-r--r--common/arm/arm_builtins.h (renamed from arm/common/arm_builtins.h)0
-rw-r--r--common/arm/builtins.S (renamed from arm/common/builtins.S)0
-rw-r--r--common/arm/exception.h (renamed from arm/common/armv7_exception.h)0
-rw-r--r--common/arm/init_util.S (renamed from arm/common/init_util.S)0
-rw-r--r--common/arm/mem_util.c (renamed from arm/common/mem_util.c)2
-rw-r--r--common/arm/memory.h (renamed from arm/common/memory.h)0
-rw-r--r--common/arm/register.h (renamed from arm/common/armv7_regs.h)0
-rw-r--r--common/arm/vmsa.h (renamed from arm/common/armv7_vmsa.h)0
-rw-r--r--common/debug.h (renamed from aarch64/common/debug.h)0
-rw-r--r--common/interop.h (renamed from arm/common/interop.h)0
-rw-r--r--common/mem_util.h (renamed from aarch64/common/mem_util.h)0
-rw-r--r--common/smc.h (renamed from aarch64/common/smc.h)0
-rw-r--r--common/svc.h (renamed from aarch64/common/svc.h)0
-rw-r--r--common/syscntl.h (renamed from aarch64/common/syscntl.h)0
-rw-r--r--config.mk9
-rwxr-xr-xconfigure14
-rw-r--r--el0/el0.c (renamed from aarch64/el0_common/el0.c)0
-rw-r--r--el0/el0_common.h (renamed from arm/el0_common/el0_common.h)1
-rw-r--r--el0/nonsecure/Makefile (renamed from arm/el0_ns/Makefile)8
-rw-r--r--el0/nonsecure/el0.h (renamed from aarch64/el0_ns/el0.h)0
-rw-r--r--el0/nonsecure/el0_nsec.lds.S (renamed from aarch64/el0_ns/el0_nsec.lds.S)0
-rw-r--r--el0/nonsecure/tztest_nsec.c (renamed from aarch64/el0_ns/tztest_nsec.c)0
-rw-r--r--el0/secure/Makefile (renamed from arm/el0_s/Makefile)8
-rw-r--r--el0/secure/el0.h (renamed from aarch64/el0_s/el0.h)0
-rw-r--r--el0/secure/el0_sec.lds.S (renamed from aarch64/el0_s/el0_sec.lds.S)0
-rw-r--r--el0/secure/tztest_sec.c (renamed from aarch64/el0_s/tztest_sec.c)0
-rw-r--r--el0/tztest.c (renamed from aarch64/el0_common/tztest.c)2
-rw-r--r--el0/tztest.h (renamed from aarch64/el0_common/tztest.h)0
-rw-r--r--el1/aarch64/el1_exception.S (renamed from aarch64/el1_common/aarch64/el1_exception.S)2
-rw-r--r--el1/aarch64/el1_init.S (renamed from aarch64/el1_common/aarch64/el1_init.S)2
-rw-r--r--el1/aarch64/el1_loader.c (renamed from aarch64/el1_common/aarch64/el1_loader.c)1
-rw-r--r--el1/arm/el1_exception.S (renamed from arm/el1_common/arm/el1_exception.S)3
-rw-r--r--el1/arm/el1_init.S (renamed from arm/el1_common/arm/el1_init.S)3
-rw-r--r--el1/arm/el1_loader.c (renamed from arm/el1_common/arm/el1_loader.c)1
-rw-r--r--el1/el1.c (renamed from arm/el1_common/el1.c)2
-rw-r--r--el1/el1_common.h (renamed from aarch64/el1_common/el1_common.h)1
-rw-r--r--el1/nonsecure/Makefile (renamed from arm/el1_ns/Makefile)9
-rw-r--r--el1/nonsecure/aarch64/el1.h (renamed from aarch64/el1_ns/aarch64/el1.h)0
-rw-r--r--el1/nonsecure/arm/el1.h (renamed from arm/el1_ns/arm/el1.h)0
-rw-r--r--el1/nonsecure/el1_nsec.c (renamed from arm/el1_ns/el1_nsec.c)1
-rw-r--r--el1/nonsecure/el1_nsec.lds.S (renamed from aarch64/el1_ns/el1_nsec.lds.S)0
-rw-r--r--el1/secure/Makefile (renamed from aarch64/el1_s/Makefile)9
-rw-r--r--el1/secure/aarch64/el1.h (renamed from aarch64/el1_s/aarch64/el1.h)0
-rw-r--r--el1/secure/arm/el1.h (renamed from arm/el1_s/arm/el1.h)0
-rw-r--r--el1/secure/el1_sec.c (renamed from aarch64/el1_s/el1_sec.c)1
-rw-r--r--el1/secure/el1_sec.lds.S (renamed from aarch64/el1_s/el1_sec.lds.S)0
-rw-r--r--el3/Makefile (renamed from arm/el3/Makefile)5
-rw-r--r--el3/aarch64/el3_exception.S (renamed from aarch64/el3/aarch64/el3_exception.S)3
-rw-r--r--el3/aarch64/el3_init.S (renamed from aarch64/el3/aarch64/el3_init.S)3
-rw-r--r--el3/aarch64/el3_monitor.h (renamed from aarch64/el3/aarch64/el3_monitor.h)0
-rw-r--r--el3/aarch64/el3_monitor_asm.S (renamed from aarch64/el3/aarch64/el3_monitor_asm.S)2
-rw-r--r--el3/arm/el3_exception.S (renamed from arm/el3/arm/el3_exception.S)3
-rw-r--r--el3/arm/el3_init.S (renamed from arm/el3/arm/el3_init.S)5
-rw-r--r--el3/arm/el3_monitor.h (renamed from arm/el3/arm/el3_monitor.h)0
-rw-r--r--el3/arm/el3_monitor_asm.S (renamed from arm/el3/arm/el3_monitor_asm.S)3
-rw-r--r--el3/el3.c (renamed from arm/el3/el3.c)4
-rw-r--r--el3/el3.h (renamed from aarch64/el3/el3.h)0
-rw-r--r--el3/el3.lds.S (renamed from aarch64/el3/el3.lds.S)0
-rw-r--r--tztest/tztest.c (renamed from arm/common/tztest.c)0
-rw-r--r--tztest/tztest.h (renamed from arm/common/tztest.h)0
110 files changed, 145 insertions, 1852 deletions
diff --git a/.gdbinit b/.gdbinit
index 7d31588..a7b8b55 100644
--- a/.gdbinit
+++ b/.gdbinit
@@ -1,26 +1,27 @@
-set arch arm
target remote :1234
set print pretty
define load_el3
-file arm/el3/el3.elf
-add-symbol-file arm/el3/el3.elf &_EL3_TEXT_BASE
+file el3/el3.elf
+add-symbol-file el3/el3.elf &_EL3_TEXT_BASE
end
define load_el1s
-file arm/el1_s/el1_sec.elf
-add-symbol-file arm/el1_s/el1_sec.elf &_EL1_S_TEXT_BASE
+file el1/secure/el1_sec.elf
+add-symbol-file el1/secure/el1_sec.elf &_EL1_S_TEXT_BASE
end
define load_el1ns
-file arm/el1_ns/el1_nsec.elf
-add-symbol-file arm/el1_ns/el1_nsec.elf &_EL1_NS_TEXT_BASE
+file el1/nonsecure/el1_nsec.elf
+add-symbol-file el1/nonsecure/el1_nsec.elf &_EL1_NS_TEXT_BASE
end
-define load_el0ns
-add-symbol-file arm/el0_ns/el0_nsec.elf 0x80000
+define load_el0s
+file el0/secure/el0_sec.elf
+add-symbol-file el0/secure/el0_sec.elf &_EL0_S_TEXT_BASE
end
-define load_el0s
-add-symbol-file arm/el0_s/el0_sec.elf 0xc0000
+define load_el0ns
+file el0/nonsecure/el0_nsec.elf
+add-symbol-file el0/nonsecure/el0_nsec.elf &_EL0_NS_TEXT_BASE
end
diff --git a/.gdbinit64 b/.gdbinit64
deleted file mode 100644
index a8b1876..0000000
--- a/.gdbinit64
+++ /dev/null
@@ -1,27 +0,0 @@
-set arch aarch64
-target remote :1234
-set print pretty
-
-define load_el3
-file aarch64/el3/el3.elf
-add-symbol-file aarch64/el3/el3.elf &_EL3_TEXT_BASE
-end
-
-define load_el1s
-file aarch64/el1_s/el1_sec.elf
-add-symbol-file aarch64/el1_s/el1_sec.elf &_EL1_S_TEXT_BASE
-end
-
-define load_el1ns
-file aarch64/el1_ns/el1_nsec.elf
-add-symbol-file aarch64/el1_ns/el1_nsec.elf &_EL1_NS_TEXT_BASE
-end
-
-define load_el0ns
-add-symbol-file aarch64/el0_ns/el0_nsec.elf 0x80000
-end
-
-define load_el0s
-add-symbol-file aarch64/el0_s/el0_sec.elf 0xc0000
-end
-
diff --git a/Makefile b/Makefile
index ee7a7bb..dbdc10a 100644
--- a/Makefile
+++ b/Makefile
@@ -1,16 +1,15 @@
-ifeq ($(wildcard config.mak),)
+ifeq ($(wildcard config.mk),)
$(error run ./configure first. See ./configure -h)
endif
-include config.mak
-
-.PHONY: arch_clean clean distclean
+# Pick up configuration definitions
+include config.mk
+# Pick up architecture specific build rules
+include $(ARCH).mk
-libgcc := $(shell $(CC) $(CFLAGS) --print-libgcc-file-name)
-export FLATLIBS = ../../libcflat/libcflat.a $(libgcc) ../../libcflat/$(ARCH)/libeabi.a
+.PHONY: clean distclean
-# cc-option
# Usage: OP_CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0)
cc-option = $(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null \
@@ -26,24 +25,60 @@ CFLAGS += -g -O0
CFLAGS += -I. -I/include -I$(ARCH)/include
CFLAGS += -I../libcflat/include
CFLAGS += -I../platform/$(PLAT)
+CFLAGS += -I/usr/$(CROSS)/include
+CFLAGS += -I../../platform/$(PLAT) -I../../libcflat/include
+CFLAGS += -I$(ARCH) -I../common/$(ARCH) -I../common
CFLAGS += $(call cc-option, -fomit-frame-pointer, "")
CFLAGS += $(call cc-option, -fno-stack-protector, "")
CFLAGS += $(call cc-option, -fno-stack-protector-all, "")
-CFLAGS += -I/usr/$(CROSS)/include
-CFLAGS += -I$(ARCH) -DARCH=$(ARCH)
-
-# Pick up architecture specific build rules
-include $(ARCH)/arch.mk
export CFLAGS
-all:
+BIOS_IMAGE = tztest.img
+LIBCFLAT = libcflat.a
+EL3_IMAGE = el3/el3.bin
+EL1_S_IMAGE = el1/secure/el1_sec.bin
+EL1_NS_IMAGE = el1/nonsecure/el1_nsec.bin
+EL0_S_IMAGE = el0/secure/el0_sec.elf
+EL0_NS_IMAGE = el0/nonsecure/el0_nsec.elf
+
+-include .*.d
+
+$(BIOS_IMAGE): $(LIBCFLAT) $(EL3_IMAGE) $(EL1_S_IMAGE) $(EL1_NS_IMAGE) \
+ $(EL0_S_IMAGE) $(EL0_NS_IMAGE)
+ dd if=$(EL3_IMAGE) of=$@ 2> /dev/null
+ dd oflag=seek_bytes seek=65536 if=$(EL1_S_IMAGE) of=$@ 2> /dev/null
+ dd oflag=seek_bytes seek=131072 if=$(EL1_NS_IMAGE) of=$@ 2> /dev/null
+ dd oflag=seek_bytes seek=196608 if=$(EL0_NS_IMAGE) of=$@ 2> /dev/null
+ dd oflag=seek_bytes seek=327680 if=$(EL0_S_IMAGE) of=$@ 2> /dev/null
+ chmod +x $(BIOS_IMAGE)
+
+$(LIBCFLAT):
$(MAKE) -C libcflat all
- $(MAKE) -C $(ARCH) all
+
+$(EL3_IMAGE):
+ $(MAKE) -C el3 all
+
+$(EL1_S_IMAGE):
+ $(MAKE) -C el1/secure all
+
+$(EL1_NS_IMAGE):
+ $(MAKE) -C el1/nonsecure all
+
+$(EL0_S_IMAGE):
+ $(MAKE) -C el0/secure all
+
+$(EL0_NS_IMAGE):
+ $(MAKE) -C el0/nonsecure all
clean:
$(MAKE) -C libcflat clean
- $(MAKE) -C $(ARCH) clean
+ $(MAKE) -C el3 clean
+ $(MAKE) -C el1/secure clean
+ $(MAKE) -C el1/nonsecure clean
+ $(MAKE) -C el0/secure clean
+ $(MAKE) -C el0/nonsecure clean
+ $(RM) $(BIOS_IMAGE) .*.d
distclean: clean
$(RM) config.mak cscope.*
diff --git a/arm/TESTCASES.txt b/TESTCASES.txt
index fb6d080..fb6d080 100644
--- a/arm/TESTCASES.txt
+++ b/TESTCASES.txt
diff --git a/aarch64/arch.mk b/aarch64.mk
index 7a2f13d..5726582 100644
--- a/aarch64/arch.mk
+++ b/aarch64.mk
@@ -1 +1,3 @@
CFLAGS += -DFORMAT="elf64-littleaarch64" -mcmodel=large
+CFLAGS += -DARCH="aarch64"
+CFLAGS += -DAARCH64
diff --git a/aarch64/Makefile b/aarch64/Makefile
deleted file mode 100644
index fc58b07..0000000
--- a/aarch64/Makefile
+++ /dev/null
@@ -1,46 +0,0 @@
-BIOS_IMAGE = tztest.img
-EL3_IMAGE = el3/el3.bin
-EL1_S_IMAGE = el1_s/el1_sec.bin
-EL1_NS_IMAGE = el1_ns/el1_nsec.bin
-TZTEST_NS_IMAGE = el0_ns/el0_nsec.elf
-TZTEST_S_IMAGE = el0_s/el0_sec.elf
-
-CFLAGS += -I../../platform/$(PLAT) -I../../libcflat/include -I../common
-CFLAGS += -DAARCH64
-
--include .*.d
-
-##################################################################
-
-$(BIOS_IMAGE): $(EL3_IMAGE) $(EL1_S_IMAGE) $(EL1_NS_IMAGE) $(TZTEST_NS_IMAGE) $(TZTEST_S_IMAGE)
- dd if=$(EL3_IMAGE) of=$@ 2> /dev/null
- dd oflag=seek_bytes seek=65536 if=$(EL1_S_IMAGE) of=$@ 2> /dev/null
- dd oflag=seek_bytes seek=131072 if=$(EL1_NS_IMAGE) of=$@ 2> /dev/null
- dd oflag=seek_bytes seek=196608 if=$(TZTEST_NS_IMAGE) of=$@ 2> /dev/null
- dd oflag=seek_bytes seek=327680 if=$(TZTEST_S_IMAGE) of=$@ 2> /dev/null
- chmod +x $(BIOS_IMAGE)
-
-$(EL3_IMAGE):
- $(MAKE) -C el3 all
-
-$(EL1_S_IMAGE):
- $(MAKE) -C el1_s all
-
-$(EL1_NS_IMAGE):
- $(MAKE) -C el1_ns all
-
-$(TZTEST_NS_IMAGE):
- $(MAKE) -C el0_ns all
-
-$(TZTEST_S_IMAGE):
- $(MAKE) -C el0_s all
-
-all: $(BIOS_IMAGE)
-
-clean:
- $(MAKE) -C el3 clean
- $(MAKE) -C el1_s clean
- $(MAKE) -C el1_ns clean
- $(MAKE) -C el0_s clean
- $(MAKE) -C el0_ns clean
- $(RM) $(BIOS_IMAGE) .*.d
diff --git a/aarch64/common/arch.h b/aarch64/common/arch.h
deleted file mode 100644
index 6207a54..0000000
--- a/aarch64/common/arch.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#ifndef _ARCH_H
-#define _ARCH_H
-
-/* This is a generic header comprised of the architecture specfic headers and
- * any generic symbol definitions.
- */
-#include "armv8_regs.h"
-#include "armv8_vmsa.h"
-#include "armv8_exception.h"
-
-#endif
diff --git a/aarch64/common/arm64.h b/aarch64/common/arm64.h
deleted file mode 100644
index 58aa28c..0000000
--- a/aarch64/common/arm64.h
+++ /dev/null
@@ -1,12 +0,0 @@
-#ifndef ARM64_H
-#define ARM64_H
-
-#define EL3T 0x0C
-#define EL3H 0x0D
-#define EL2T 0x09
-#define EL2H 0x08
-#define EL1T 0x05
-#define EL1H 0x04
-#define EL0T 0x00
-
-#endif
diff --git a/aarch64/common/interop.h b/aarch64/common/interop.h
deleted file mode 100644
index c4ac039..0000000
--- a/aarch64/common/interop.h
+++ /dev/null
@@ -1,53 +0,0 @@
-#ifndef _INTEROP_H
-#define _INTEROP_H
-#include <stdint.h>
-#include <stddef.h>
-
-#define OP_MAP_NSEC_EL0 0
-#define OP_MAP_SEC_EL0 1
-#define OP_MAP_NSEC_EL1 2
-#define OP_MAP_SEC_EL1 4
-#define OP_MAP_EL3 8
-#define OP_MAP_ALL \
- (OP_MAP_SEC_EL0 | OP_MAP_NSEC_EL1 | OP_MAP_SEC_EL1 | OP_MAP_EL3)
-
-typedef struct {
- uint32_t type;
- size_t len;
- void *addr;
-} op_alloc_mem_t;
-
-typedef struct {
- uint32_t type;
- size_t len;
- void *va;
- void *pa;
-} op_map_mem_t;
-
-typedef struct {
- uintptr_t func_id;
- uintptr_t arg;
- uintptr_t ret;
-} op_dispatch_t;
-
-typedef enum {
- CURRENTEL = 1,
- CPTR_EL3,
- CPACR,
- SCR,
- SCTLR,
-} op_reg_key_t;
-
-typedef struct {
- uint64_t key;
- uint64_t data;
- uint64_t el;
-} op_data_t;
-
-typedef struct {
- uint64_t orig;
- uint64_t val;
- uint64_t count;
- uint64_t fail;
-} op_test_t;
-#endif
diff --git a/aarch64/el0_common/el0_common.h b/aarch64/el0_common/el0_common.h
deleted file mode 100644
index 2e33c5a..0000000
--- a/aarch64/el0_common/el0_common.h
+++ /dev/null
@@ -1,18 +0,0 @@
-#ifndef __EL0_COMMON_H
-#define __EL0_COMMON_H
-
-#include "libcflat.h"
-#include "svc.h"
-#include "syscntl.h"
-#include "arch.h"
-#include "arm_builtins.h"
-#include "el0.h"
-#include "debug.h"
-#include "tztest.h"
-
-extern sys_control_t *syscntl;
-
-extern void *alloc_mem(int type, size_t len);
-extern void map_va(void *va, size_t len, int type);
-
-#endif
diff --git a/aarch64/el0_ns/Makefile b/aarch64/el0_ns/Makefile
deleted file mode 100644
index 5e3cfad..0000000
--- a/aarch64/el0_ns/Makefile
+++ /dev/null
@@ -1,32 +0,0 @@
-VPATH = ../el0_common:../common
-
-EL0_NS_ELF = el0_nsec.elf
-EL0_NS_IMAGE = el0_nsec.bin
-EL0_NS_LOAD = el0_nsec.lds
-EL0_NS_OBJS = tztest_nsec.o \
- tztest.o \
- el0.o \
- builtins.o
-
--include .*.d
-
-CFLAGS += -I../el0_common
-
-##################################################################
-
-$(EL0_NS_ELF): $(EL0_NS_OBJS) $(EL0_NS_LOAD)
- $(LD) -o $@ $(EL0_NS_OBJS) $(FLATLIBS) --script=$(EL0_NS_LOAD)
-
-$(EL0_NS_IMAGE): $(EL0_NS_ELF)
- $(OBJCOPY) -O binary $< $@
-
-$(EL0_NS_LOAD): el0_nsec.lds.S Makefile ../../platform/$(PLAT)/
- $(CC) $(CFLAGS) -E -P -C -o $@ $<
-
-%.o: %.S
- $(CC) $(CFLAGS) -c -nostdlib -o $(notdir $@) $<
-
-all: $(EL0_NS_IMAGE)
-
-clean:
- $(RM) $(EL0_NS_OBJS) $(EL0_NS_LOAD) $(EL0_NS_ELF) $(EL0_NS_IMAGE) .*.d
diff --git a/aarch64/el0_s/Makefile b/aarch64/el0_s/Makefile
deleted file mode 100644
index 336d318..0000000
--- a/aarch64/el0_s/Makefile
+++ /dev/null
@@ -1,32 +0,0 @@
-VPATH = ../el0_common:../common
-
-EL0_S_ELF = el0_sec.elf
-EL0_S_IMAGE = el0_sec.bin
-EL0_S_LOAD = el0_sec.lds
-EL0_S_OBJS = tztest_sec.o \
- tztest.o \
- el0.o \
- builtins.o
-
--include .*.d
-
-CFLAGS += -I../el0_common
-
-##################################################################
-
-$(EL0_S_ELF): $(EL0_S_OBJS) $(EL0_S_LOAD)
- $(LD) -o $@ $(EL0_S_OBJS) $(FLATLIBS) --script=$(EL0_S_LOAD)
-
-$(EL0_S_IMAGE): $(EL0_S_ELF)
- $(OBJCOPY) -O binary $< $@
-
-$(EL0_S_LOAD): el0_sec.lds.S Makefile ../../platform/$(PLAT)/
- $(CC) $(CFLAGS) -E -P -C -o $@ $<
-
-%.o: %.S
- $(CC) $(CFLAGS) -c -nostdlib -o $(notdir $@) $<
-
-all: $(EL0_S_IMAGE)
-
-clean:
- $(RM) $(EL0_S_OBJS) $(EL0_S_LOAD) $(EL0_S_ELF) $(EL0_S_IMAGE) .*.d
diff --git a/aarch64/el1_common/el1.c b/aarch64/el1_common/el1.c
deleted file mode 100644
index a908625..0000000
--- a/aarch64/el1_common/el1.c
+++ /dev/null
@@ -1,239 +0,0 @@
-#include "el1_common.h"
-#include "mem_util.h"
-
-uintptr_t mem_pgtbl_base = EL1_PGTBL_BASE;
-smc_op_desc_t *smc_interop_buf;
-sys_control_t *syscntl;
-uintptr_t mem_next_pa = 0;
-uintptr_t mem_next_l1_page = 0;
-uintptr_t mem_heap_pool = EL1_VA_HEAP_BASE;
-
-const char *svc_op_name[] = {
- [SVC_OP_EXIT] = "SVC_OP_EXIT",
- [SVC_OP_ALLOC] = "SVC_OP_ALLOC",
- [SVC_OP_MAP] = "SVC_OP_MAP",
- [SVC_OP_YIELD] = "SVC_OP_YIELD",
- [SVC_OP_GET_SYSCNTL] = "SVC_OP_GET_SYSCNTL",
- [SVC_OP_GET_REG] = "SVC_OP_GET_REG",
- [SVC_OP_SET_REG] = "SVC_OP_SET_REG",
- [SVC_OP_TEST] = "SVC_OP_TEST",
- [SVC_OP_DISPATCH] = "SVC_OP_DISPATCH"
-};
-
-void el1_alloc_mem(op_alloc_mem_t *alloc)
-{
- alloc->addr = mem_heap_allocate(alloc->len);
-}
-
-void el1_map_secure(op_map_mem_t *map)
-{
- if ((map->type & OP_MAP_EL3) == OP_MAP_EL3) {
- smc_op_desc_t *desc = (smc_op_desc_t *)smc_interop_buf;
- memcpy(desc, map, sizeof(op_map_mem_t));
- if (desc->map.pa) {
- desc->map.pa = mem_lookup_pa(desc->map.va);
- }
- __smc(SMC_OP_MAP, desc);
- } else {
- mem_map_pa((uintptr_t)map->va, (uintptr_t)map->pa, 0, PTE_USER_RW);
- }
-}
-
-void el1_interop_test(op_test_t *desc)
-{
- op_test_t *test = (op_test_t*)smc_interop_buf;
-
- memcpy(smc_interop_buf, desc, sizeof(smc_op_desc_t));
- if (test->val != test->orig >> test->count) {
- test->fail++;
- }
- test->val >>= 1;
- test->count++;
-
- __smc(SMC_OP_TEST, smc_interop_buf);
- if (test->val != test->orig >> test->count) {
- test->fail++;
- }
- test->val >>= 1;
- test->count++;
- memcpy(desc, smc_interop_buf, sizeof(smc_op_desc_t));
-}
-
-int el1_handle_svc(uint32_t op, svc_op_desc_t *desc)
-{
- uint32_t ret = 0;
-
- DEBUG_MSG("Took an svc(%s) - desc = %p\n", svc_op_name[op], desc);
- switch (op) {
- case SVC_OP_EXIT:
- SMC_EXIT();
- break;
- case SVC_OP_YIELD:
- ret = SMC_YIELD();
- memcpy(desc, smc_interop_buf, sizeof(smc_op_desc_t));
- break;
- case SVC_OP_ALLOC:
- el1_alloc_mem((op_alloc_mem_t *)desc);
- break;
- case SVC_OP_MAP:
- el1_map_secure((op_map_mem_t *)desc);
- break;
- case SVC_OP_GET_SYSCNTL:
- desc->get.data = (uintptr_t)syscntl;
- break;
- case SVC_OP_GET_REG:
- if (desc->get.el == 1) {
- switch (desc->get.key) {
-#if AARCH64
- case CURRENTEL:
- desc->get.data = READ_CURRENTEL();
- break;
- case CPTR_EL3:
- desc->get.data = READ_CPTR_EL3();
- break;
- case CPACR:
- desc->get.data = READ_CPACR();
- break;
- case SCR:
- desc->get.data = READ_SCR();
- break;
-#endif
- }
- } else if (desc->get.el == 3) {
- memcpy(smc_interop_buf, desc, sizeof(smc_op_desc_t));
- __smc(SMC_OP_GET_REG, smc_interop_buf);
- memcpy(desc, smc_interop_buf, sizeof(smc_op_desc_t));
- }
- break;
- case SVC_OP_SET_REG:
- if (desc->set.el == 1) {
- switch (desc->set.key) {
-#if AARCH64
- case CURRENTEL:
- WRITE_CURRENTEL(desc->set.data);
- break;
- case CPTR_EL3:
- WRITE_CPTR_EL3(desc->set.data);
- break;
- case CPACR:
- WRITE_CPACR(desc->set.data);
- break;
- case SCR:
- WRITE_SCR(desc->set.data);
- break;
-#endif
- }
- } else if (desc->set.el == 3) {
- memcpy(smc_interop_buf, desc, sizeof(smc_op_desc_t));
- __smc(SMC_OP_SET_REG, smc_interop_buf);
- }
- break;
- case SVC_OP_TEST:
- el1_interop_test((op_test_t *)desc);
- break;
- case SVC_OP_DISPATCH:
- memcpy(smc_interop_buf, desc, sizeof(smc_op_desc_t));
- __smc(SMC_OP_DISPATCH, smc_interop_buf);
- memcpy(desc, smc_interop_buf, sizeof(smc_op_desc_t));
- break;
- default:
- DEBUG_MSG("Unrecognized AArch64 SVC opcode: op = %d\n", op);
- break;
- }
-
- return ret;
-}
-
-void el1_handle_exception(uintptr_t ec, uintptr_t iss, uintptr_t far,
- uintptr_t elr)
-{
- if (syscntl->excp_log || syscntl->el1_excp[SEC_STATE].log) {
- syscntl->el1_excp[SEC_STATE].taken = true;
- syscntl->el1_excp[SEC_STATE].ec = ec;
- syscntl->el1_excp[SEC_STATE].iss = iss;
- syscntl->el1_excp[SEC_STATE].far = far;
- }
-
- switch (ec) {
- case EC_UNKNOWN:
- DEBUG_MSG("Unknown exception far = 0x%lx elr = 0x%lx\n", far, elr);
-
- /* The preferred return address in the case of an undefined instruction
- * is the actual offending instruction. In the case of ARMv7, we need
- * to decrement the address by 4 to get this behavior as the PC has
- * already been moved past this instruction.
- * If SKIP is enabled then we can just do nothing and get the correct
- * behavior.
- */
-#if AARCH32
- if (syscntl->el1_excp[SEC_STATE].action != EXCP_ACTION_SKIP &&
- syscntl->excp_action != EXCP_ACTION_SKIP) {
- elr += 4;
- __set_exception_return(elr);
- }
-#else
- if (syscntl->el1_excp[SEC_STATE].action == EXCP_ACTION_SKIP ||
- syscntl->excp_action == EXCP_ACTION_SKIP) {
- elr +=4;
- __set_exception_return(elr);
- }
-#endif
- break;
- case EC_IABORT_LOWER:
- DEBUG_MSG("Instruction abort at lower level: far = %0lx\n", far);
- SMC_EXIT();
- break;
- case EC_IABORT:
- DEBUG_MSG("Instruction abort at EL1: far = %0lx\n", far);
- SMC_EXIT();
- break;
- case EC_DABORT_LOWER:
- DEBUG_MSG("Data abort at lower level: far = %0lx elr = %0lx\n",
- far, elr);
- SMC_EXIT();
- break;
- case EC_DABORT:
- DEBUG_MSG("Data abort at EL1: far = %0lx elr = %0lx\n", far, elr);
- SMC_EXIT();
- break;
- case EC_WFI_WFE:
- DEBUG_MSG("WFI/WFE instruction exception far = 0x%lx elr = 0x%lx\n",
- far, elr);
-
- if (syscntl->el1_excp[SEC_STATE].action == EXCP_ACTION_SKIP ||
- syscntl->excp_action == EXCP_ACTION_SKIP) {
- elr +=4;
- __set_exception_return(elr);
- }
- break;
- default:
- DEBUG_MSG("Unhandled EL1 exception: ec = %d iss = %d\n", ec, iss);
- SMC_EXIT();
- break;
- }
-}
-
-void el1_start(uintptr_t base, uintptr_t size)
-{
- uintptr_t addr = base;
- size_t len;
-
- printf("EL1 (%s) started...\n", sec_state_str);
-
- /* Unmap the init segement so we don't accidentally use it */
- for (len = 0; len < ((size + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1));
- len += PAGE_SIZE, addr += PAGE_SIZE) {
- mem_unmap_va(addr);
- }
-
- void *pa = syscntl;
- syscntl = (sys_control_t *)mem_heap_allocate(PAGE_SIZE);
- mem_map_pa((uintptr_t)syscntl, (uintptr_t)pa, 0, PTE_USER_RW);
- mem_map_pa((uintptr_t)syscntl->smc_interop.buf_va,
- (uintptr_t)syscntl->smc_interop.buf_pa, 0, PTE_USER_RW);
- smc_interop_buf = syscntl->smc_interop.buf_va;
-
- el1_init_el0();
-
- return;
-}
diff --git a/aarch64/el1_ns/Makefile b/aarch64/el1_ns/Makefile
deleted file mode 100644
index f7ac0fd..0000000
--- a/aarch64/el1_ns/Makefile
+++ /dev/null
@@ -1,35 +0,0 @@
-VPATH = $(ARCH):../el1_common/$(ARCH):../el1_common:../common
-
-EL1_NS_ELF = el1_nsec.elf
-EL1_NS_IMAGE = el1_nsec.bin
-EL1_NS_LOAD = el1_nsec.lds
-EL1_NS_OBJS = el1_init.o \
- el1_exception.o \
- el1.o \
- el1_loader.o \
- el1_nsec.o \
- mem_util.o \
- builtins.o
-
--include .*.d
-
-CFLAGS += -I../el0_ns/ -I../el1_common
-
-##################################################################
-
-$(EL1_NS_ELF): $(EL1_NS_OBJS) $(EL1_NS_LOAD)
- $(LD) -o $@ $(EL1_NS_OBJS) $(FLATLIBS) --script=$(EL1_NS_LOAD)
-
-$(EL1_NS_IMAGE): $(EL1_NS_ELF)
- $(OBJCOPY) -O binary $< $@
-
-$(EL1_NS_LOAD): el1_nsec.lds.S Makefile ../../platform/$(PLAT)/
- $(CC) $(CFLAGS) -E -P -C -o $@ $<
-
-%.o: %.S
- $(CC) $(CFLAGS) -c -nostdlib -o $(notdir $@) $<
-
-all: $(EL1_NS_IMAGE)
-
-clean:
- $(RM) $(EL1_NS_OBJS) $(EL1_NS_LOAD) $(EL1_NS_ELF) $(EL1_NS_IMAGE) .*.d
diff --git a/aarch64/el1_ns/el1_nsec.c b/aarch64/el1_ns/el1_nsec.c
deleted file mode 100644
index 5bd5d22..0000000
--- a/aarch64/el1_ns/el1_nsec.c
+++ /dev/null
@@ -1,21 +0,0 @@
-#include "el1_common.h"
-
-uintptr_t EL1_NS_INIT_BASE = (uintptr_t)&_EL1_NS_INIT_BASE;
-uintptr_t EL1_NS_INIT_SIZE = (uintptr_t)&_EL1_NS_INIT_SIZE;
-uintptr_t EL1_NS_FLASH_TEXT = (uintptr_t)&_EL1_NS_FLASH_TEXT;
-uintptr_t EL1_NS_TEXT_BASE = (uintptr_t)&_EL1_NS_TEXT_BASE;
-uintptr_t EL1_NS_DATA_BASE = (uintptr_t)&_EL1_NS_DATA_BASE;
-uintptr_t EL1_NS_TEXT_SIZE = (uintptr_t)&_EL1_NS_TEXT_SIZE;
-uintptr_t EL1_NS_DATA_SIZE = (uintptr_t)&_EL1_NS_DATA_SIZE;
-
-const char *sec_state_str = "non-secure";
-
-void el1_init_el0()
-{
- uintptr_t main;
-
- el1_load_el0(EL0_NS_FLASH_BASE, &main);
-
- __exception_return(main, SPSR_EL0);
-
-}
diff --git a/aarch64/el3/Makefile b/aarch64/el3/Makefile
deleted file mode 100644
index a0b2373..0000000
--- a/aarch64/el3/Makefile
+++ /dev/null
@@ -1,32 +0,0 @@
-VPATH = ../common:$(ARCH)
-
-EL3_ELF = el3.elf
-EL3_IMAGE = el3.bin
-EL3_LOAD = el3.lds
-EL3_OBJS = el3_init.o \
- el3_exception.o \
- el3.o \
- el3_monitor_asm.o \
- mem_util.o \
- builtins.o
-
--include .*.d
-
-##################################################################
-
-$(EL3_ELF): $(EL3_OBJS) $(EL3_LOAD)
- $(LD) -o $@ $(EL3_OBJS) $(FLATLIBS) --script=$(EL3_LOAD)
-
-$(EL3_IMAGE): $(EL3_ELF)
- $(OBJCOPY) -O binary $< $@
-
-$(EL3_LOAD): el3.lds.S Makefile ../../platform/$(PLAT)/
- $(CC) $(CFLAGS) -E -P -C -o $@ $<
-
-%.o: %.S
- $(CC) $(CFLAGS) -c -nostdlib -o $@ $<
-
-all: $(EL3_IMAGE)
-
-clean:
- $(RM) $(EL3_OBJS) $(EL3_LOAD) $(EL3_ELF) $(EL3_IMAGE) .*.d
diff --git a/aarch64/el3/el3.c b/aarch64/el3/el3.c
deleted file mode 100644
index 49b5f56..0000000
--- a/aarch64/el3/el3.c
+++ /dev/null
@@ -1,294 +0,0 @@
-#include <stdint.h>
-#include <stddef.h>
-#include "platform.h"
-#include "memory.h"
-#include "el3.h"
-#include "string.h"
-#include "libcflat.h"
-#include "smc.h"
-#include "svc.h"
-#include "arch.h"
-#include "el3_monitor.h"
-#include "arm_builtins.h"
-#include "syscntl.h"
-#include "mem_util.h"
-
-#define SEC_STATE_STR "EL3"
-#include "debug.h"
-
-#if DEBUG
-const char *smc_op_name[] = {
- [SMC_OP_NOOP] = "SMC_OP_NOOP",
- [SMC_OP_DISPATCH_MONITOR] = "SMC_DISPATCH_MONITOR",
- [SMC_OP_YIELD] = "SMC_OP_YIELD",
- [SMC_OP_EXIT] = "SMC_OP_EXIT",
- [SMC_OP_MAP] = "SMC_OP_MAP",
- [SMC_OP_GET_REG] = "SMC_OP_GET_REG",
- [SMC_OP_SET_REG] = "SMC_OP_SET_REG",
- [SMC_OP_TEST] = "SMC_OP_TEST",
- [SMC_OP_DISPATCH] = "SMC_OP_DISPATCH",
-};
-
-const char *sec_state_str = "EL3";
-#endif
-
-uintptr_t EL3_TEXT_BASE = (uintptr_t)&_EL3_TEXT_BASE;
-uintptr_t EL3_DATA_BASE = (uintptr_t)&_EL3_DATA_BASE;
-uintptr_t EL3_TEXT_SIZE = (uintptr_t)&_EL3_TEXT_SIZE;
-uintptr_t EL3_DATA_SIZE = (uintptr_t)&_EL3_DATA_SIZE;
-
-state_buf sec_state;
-state_buf nsec_state;
-
-sys_control_t *syscntl;
-smc_op_desc_t *smc_interop_buf;
-
-uintptr_t mem_pgtbl_base = EL3_PGTBL_BASE;
-uintptr_t mem_next_pa = 0;
-uintptr_t mem_next_l1_page = 0;
-uintptr_t mem_heap_pool = EL3_VA_HEAP_BASE;
-
-void el3_shutdown() {
- uintptr_t *sysreg_cfgctrl = (uintptr_t *)(SYSREG_BASE + SYSREG_CFGCTRL);
-
- DEBUG_MSG("Test complete");
-
- *sysreg_cfgctrl = SYS_SHUTDOWN;
-
- while(1); /* Shutdown does not work on all machines */
-}
-
-void el3_alloc_mem(op_alloc_mem_t *alloc)
-{
- alloc->addr = mem_heap_allocate(alloc->len);
-}
-
-uint32_t el3_map_mem(op_map_mem_t *map)
-{
- if ((map->type & OP_MAP_EL3) == OP_MAP_EL3) {
- mem_map_pa((uintptr_t)map->va, (uintptr_t)map->pa, 0, PTE_PRIV_RW);
- DEBUG_MSG("Mapped VA:0x%lx to PA:0x%lx\n", map->va, map->pa);
- }
-
- if ((map->type & OP_MAP_SEC_EL1) == OP_MAP_SEC_EL1) {
- map->type &= ~OP_MAP_EL3;
- DEBUG_MSG("Initiating SVC_OP_MAP\n");
- return SVC_OP_MAP;
- }
-
- return 0;
-}
-
-int el3_handle_smc(uintptr_t op, smc_op_desc_t *desc)
-{
- op_test_t *test = (op_test_t*)desc;
-
- DEBUG_MSG("Took an smc(%s) - desc = %p\n", smc_op_name[op], desc);
- switch (op) {
- case SMC_OP_YIELD:
- return SVC_OP_YIELD;
- break;
- case SMC_OP_MAP:
- return el3_map_mem((op_map_mem_t *)desc);
- break;
- case SMC_OP_NOOP:
- break;
- case SMC_OP_EXIT:
- el3_shutdown();
- break;
- case SMC_OP_DISPATCH:
- return SVC_OP_DISPATCH;
- break;
- case SMC_OP_TEST:
- if (test->val != test->orig >> test->count) {
- test->fail++;
- }
- test->val >>= 1;
- test->count++;
- return SVC_OP_TEST;
- case SMC_OP_GET_REG:
- if (desc->get.el == 3) {
- switch (desc->get.key) {
-#if AARCH64
- case CURRENTEL:
- desc->get.data = READ_CURRENTEL();
- break;
- case CPTR_EL3:
- desc->get.data = READ_CPTR_EL3();
- break;
- case CPACR:
- desc->get.data = READ_CPACR();
- break;
- case SCR:
- desc->get.data = READ_SCR();
- break;
-#endif
- }
- }
- break;
- case SMC_OP_SET_REG:
- if (desc->set.el == 3) {
- switch (desc->set.key) {
-#if AARCH64
- case CURRENTEL:
- WRITE_CURRENTEL(desc->set.data);
- break;
- case CPTR_EL3:
- WRITE_CPTR_EL3(desc->set.data);
- break;
- case CPACR:
- WRITE_CPACR(desc->set.data);
- break;
- case SCR:
- WRITE_SCR(desc->set.data);
- break;
-#endif
- }
- }
- break;
- default:
- printf("Unrecognized AArch64 SMC opcode: op = %d\n", op);
- el3_shutdown();
- break;
- }
-
- return 0;
-}
-
-int el3_handle_exception(uintptr_t ec, uintptr_t iss, uintptr_t far,
- uintptr_t elr)
-{
- if (syscntl->excp_log || syscntl->el3_excp.log) {
- syscntl->el3_excp.taken = true;
- syscntl->el3_excp.ec = ec;
- syscntl->el3_excp.iss = iss;
- syscntl->el3_excp.far = far;
- }
-
- switch (ec) {
- case EC_SMC64:
- case EC_SMC32:
- printf("Took an SMC exception from EL3\n");
- break;
- case EC_IABORT_LOWER:
- printf("Instruction abort at lower level: far = %0lx\n", far);
- el3_shutdown();
- break;
- case EC_IABORT:
- printf("Instruction abort at EL3: far = %0lx\n", far);
- el3_shutdown();
- break;
- case EC_DABORT_LOWER:
- printf("Data abort at lower level: far = %0lx elr = %0lx\n",
- far, elr);
- el3_shutdown();
- break;
- case EC_DABORT:
- printf("Data abort at EL3: far = %0lx elr = %0lx\n", far, elr);
- el3_shutdown();
- break;
- case EC_SYSINSN:
- DEBUG_MSG("System instruction exception far = 0x%lx elr = 0x%lx\n",
- far, elr);
-
- /* Other than system calls, synchronous exceptions return to the
- * offending instruction. The user should have issued a SKIP.
- */
- if (syscntl->el3_excp.action == EXCP_ACTION_SKIP ||
- syscntl->excp_action == EXCP_ACTION_SKIP) {
- elr +=4;
- __set_exception_return(elr);
- }
- break;
- case EC_WFI_WFE:
- DEBUG_MSG("WFI/WFE instruction exception far = 0x%lx elr = 0x%lx\n",
- far, elr);
-
- /* Other than system calls, synchronous exceptions return to the
- * offending instruction. The user should have issued a SKIP.
- */
- if (syscntl->el3_excp.action == EXCP_ACTION_SKIP ||
- syscntl->excp_action == EXCP_ACTION_SKIP) {
- elr +=4;
- __set_exception_return(elr);
- }
- break;
- case EC_SIMD:
- DEBUG_MSG("Adv SIMD or FP access exception - far = 0x%lx elr = 0x%lx\n",
- far, elr);
- /* Other than system calls, synchronous exceptions return to the
- * offending instruction. The user should have issued a SKIP.
- */
- if (syscntl->el3_excp.action == EXCP_ACTION_SKIP ||
- syscntl->excp_action == EXCP_ACTION_SKIP) {
- elr +=4;
- __set_exception_return(elr);
- }
- break;
- default:
- printf("Unhandled EL3 exception: EC = 0x%lx ISS = 0x%lx\n", ec, iss);
- el3_shutdown();
- break;
- }
-
- return 0;
-}
-
-void el3_monitor_init()
-{
- uintptr_t syscntl_pa = (uintptr_t)mem_lookup_pa(syscntl);
-
- /* Clear out our secure and non-secure state buffers */
- memset(&sec_state, 0, sizeof(sec_state));
- memset(&nsec_state, 0, sizeof(nsec_state));
-
- /* Below we setup the initial register states for when we start the secure
- * and non-secure images. In both cases we set up register 4 (index 0) to
- * contain the system control block physical address.
- * In the case of AArch64, we also have to set SPSEL to 1 so that the stack
- * used before and after the switch is the same.
- * In the case of the non-secure state, we also have to set-up the initial
- * exception LR and SPSR as we do an SMC from secure to non-secure. For
- * the secure side, we just perform an exception return with the target LR
- * and SPSR.
- */
-#ifdef AARCH64
- sec_state.spsel = 0x1;
-#endif
- sec_state.reg[0] = syscntl_pa;
-
- nsec_state.elr_el3 = EL1_NS_FLASH_BASE;
- nsec_state.spsr_el3 = SPSR_EL1;
-#ifdef AARCH64
- nsec_state.spsel = 0x1;
-#endif
- nsec_state.reg[0] = syscntl_pa;
-}
-
-void el3_start(uintptr_t base, uintptr_t size)
-{
- uintptr_t addr = base;
- size_t len;
-
- printf("EL3 started...\n");
-
- /* Unmap the init segement so we don't accidentally use it */
- for (len = 0; len < ((size + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1));
- len += PAGE_SIZE, addr += PAGE_SIZE) {
- mem_unmap_va(addr);
- }
-
- syscntl = mem_heap_allocate(PAGE_SIZE);
-
- smc_interop_buf = mem_heap_allocate(PAGE_SIZE);
- syscntl->smc_interop.buf_va = smc_interop_buf;
- syscntl->smc_interop.buf_pa = mem_lookup_pa(smc_interop_buf);
-
- el3_monitor_init();
-
- /* Set-up our state to return to secure EL1 to start its init on exception
- * return.
- */
- monitor_restore_state(&sec_state);
- __exception_return(EL1_S_FLASH_BASE, SPSR_EL1);
-}
diff --git a/arm.mk b/arm.mk
new file mode 100644
index 0000000..903eabe
--- /dev/null
+++ b/arm.mk
@@ -0,0 +1,3 @@
+CFLAGS += -DFORMAT="elf32-littlearm"
+CFLAGS += -DARCH="arm"
+CFLAGS += -DAARCH32
diff --git a/arm/Makefile b/arm/Makefile
deleted file mode 100644
index 4d46736..0000000
--- a/arm/Makefile
+++ /dev/null
@@ -1,48 +0,0 @@
-BIOS_IMAGE = tztest.img
-EL3_IMAGE = el3/el3.bin
-EL1_S_IMAGE = el1_s/el1_sec.bin
-EL1_NS_IMAGE = el1_ns/el1_nsec.bin
-EL0_NS_IMAGE = el0_ns/el0_nsec.elf
-EL0_S_IMAGE = el0_s/el0_sec.elf
-
-CFLAGS += -I../../platform/$(PLAT) -I../../libcflat/include
-CFLAGS += -I../common -I../monitor
-CFLAGS += -DAARCH32
-
--include .*.d
-
-##################################################################
-
-$(BIOS_IMAGE): $(EL3_IMAGE) $(EL1_S_IMAGE) $(EL1_NS_IMAGE) \
- $(EL0_S_IMAGE) $(EL0_NS_IMAGE)
- dd if=$(EL3_IMAGE) of=$@ 2> /dev/null
- dd oflag=seek_bytes seek=65536 if=$(EL1_S_IMAGE) of=$@ 2> /dev/null
- dd oflag=seek_bytes seek=131072 if=$(EL1_NS_IMAGE) of=$@ 2> /dev/null
- dd oflag=seek_bytes seek=196608 if=$(EL0_NS_IMAGE) of=$@ 2> /dev/null
- dd oflag=seek_bytes seek=327680 if=$(EL0_S_IMAGE) of=$@ 2> /dev/null
- chmod +x $(BIOS_IMAGE)
-
-$(EL3_IMAGE):
- $(MAKE) -C el3 all
-
-$(EL1_S_IMAGE):
- $(MAKE) -C el1_s all
-
-$(EL1_NS_IMAGE):
- $(MAKE) -C el1_ns all
-
-$(EL0_NS_IMAGE):
- $(MAKE) -C el0_ns all
-
-$(EL0_S_IMAGE):
- $(MAKE) -C el0_s all
-
-all: $(BIOS_IMAGE)
-
-clean:
- $(MAKE) -C el3 clean
- $(MAKE) -C el1_s clean
- $(MAKE) -C el1_ns clean
- $(MAKE) -C el0_s clean
- $(MAKE) -C el0_ns clean
- $(RM) $(BIOS_IMAGE) .*.d
diff --git a/arm/arch.mk b/arm/arch.mk
deleted file mode 100644
index 67a63c7..0000000
--- a/arm/arch.mk
+++ /dev/null
@@ -1 +0,0 @@
-CFLAGS += -DFORMAT="elf32-littlearm"
diff --git a/arm/common/arch.h b/arm/common/arch.h
deleted file mode 100644
index a88b1d1..0000000
--- a/arm/common/arch.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#ifndef _ARCH_H
-#define _ARCH_H
-
-/* This is a generic header comprised of the architecture specfic headers and
- * any generic symbol definitions.
- */
-#include "armv7_regs.h"
-#include "armv7_vmsa.h"
-#include "armv7_exception.h"
-
-#endif
diff --git a/arm/common/debug.h b/arm/common/debug.h
deleted file mode 100644
index c9af5fe..0000000
--- a/arm/common/debug.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#ifndef _DEBUG_H
-#define _DEBUG_H
-
-extern const char *sec_state_str;
-
-#ifdef DEBUG
-#define DEBUG_MSG(_str, ...) \
- printf("\n[DEBUG] %s (%s): " _str, __FUNCTION__, (sec_state_str)?sec_state_str:"MISSING", ##__VA_ARGS__)
-#define DEBUG_ARG
-#else
-#define DEBUG_MSG(_str, ...)
-#define DEBUG_ARG __attribute__ ((unused))
-#endif
-
-#endif
diff --git a/arm/common/mem_util.h b/arm/common/mem_util.h
deleted file mode 100644
index c7beec8..0000000
--- a/arm/common/mem_util.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#ifndef _MEM_UTIL_H
-#define _MEM_UTIL_H
-
-extern uintptr_t mem_allocate_pa();
-extern void mem_map_pa(uintptr_t, uintptr_t, uintptr_t, uintptr_t);
-extern void mem_map_va(uintptr_t, uintptr_t, uintptr_t);
-extern int mem_unmap_va(uintptr_t addr);
-extern void *mem_heap_allocate(size_t len);
-extern void *mem_lookup_pa(void *va);
-
-#endif
diff --git a/arm/common/smc.h b/arm/common/smc.h
deleted file mode 100644
index b54991e..0000000
--- a/arm/common/smc.h
+++ /dev/null
@@ -1,37 +0,0 @@
-#ifndef _SMC_H
-#define _SMC_H
-
-#define SMC_OP_NOOP 0
-#define SMC_OP_DISPATCH_MONITOR 1
-#define SMC_OP_YIELD 2
-#define SMC_OP_DISPATCH_SECURE_USR 3
-#define SMC_OP_DISPATCH_SECURE_SVC 4
-#define SMC_OP_ALLOCATE_SECURE_MEMORY 4
-#define SMC_OP_EXIT 5
-#define SMC_OP_MAP 8
-#define SMC_OP_GET_REG 11
-#define SMC_OP_SET_REG 12
-#define SMC_OP_TEST 13
-#define SMC_OP_DISPATCH 14
-
-#ifndef __ASSEMBLY__
-#include "interop.h"
-
-extern uint32_t __smc(uint32_t, void *);
-
-typedef union {
- op_dispatch_t dispatch;
- op_map_mem_t map;
- op_test_t test;
- op_data_t get;
- op_data_t set;
-} smc_op_desc_t;
-
-extern smc_op_desc_t *smc_interop_buf;
-
-#define SMC_EXIT() __smc(SMC_OP_EXIT, NULL)
-#define SMC_YIELD() __smc(SMC_OP_YIELD, smc_interop_buf);
-
-#endif
-
-#endif
diff --git a/arm/common/svc.h b/arm/common/svc.h
deleted file mode 100644
index 0bfaff0..0000000
--- a/arm/common/svc.h
+++ /dev/null
@@ -1,50 +0,0 @@
-#ifndef _SVC_H
-#define _SVC_H
-
-#define SVC_OP_EXIT 6
-#define SVC_OP_ALLOC 7
-#define SVC_OP_MAP 8
-#define SVC_OP_YIELD 9
-#define SVC_OP_GET_SYSCNTL 10
-#define SVC_OP_GET_REG 11
-#define SVC_OP_SET_REG 12
-#define SVC_OP_TEST 13
-#define SVC_OP_DISPATCH 14
-
-#ifndef __ASSEMBLY__
-#include "interop.h"
-
-extern const char *svc_op_name[];
-
-typedef union {
- op_alloc_mem_t alloc;
- op_map_mem_t map;
- op_data_t get;
- op_data_t set;
- op_test_t test;
- op_dispatch_t disp;
-} svc_op_desc_t;
-
-extern uint32_t __svc(uint32_t, const svc_op_desc_t *);
-
-#define SVC_GET_REG(__reg, __el, __val) \
- do { \
- svc_op_desc_t desc; \
- desc.get.key = (__reg); \
- desc.get.el = (__el); \
- __svc(SVC_OP_GET_REG, &desc); \
- (__val) = desc.get.data; \
- } while (0)
-
-#define SVC_SET_REG(__reg, __el, __val) \
- do { \
- svc_op_desc_t desc; \
- desc.get.key = (__reg); \
- desc.get.el = (__el); \
- desc.get.data = (__val); \
- __svc(SVC_OP_SET_REG, &desc); \
- } while (0)
-
-#endif
-
-#endif
diff --git a/arm/common/syscntl.h b/arm/common/syscntl.h
deleted file mode 100644
index 75d2637..0000000
--- a/arm/common/syscntl.h
+++ /dev/null
@@ -1,37 +0,0 @@
-#ifndef _SYSCNTL_H
-#define _SYSCNTL_H
-
-typedef struct {
- void *buf_pa;
- void *buf_va;
-} smc_interop_t;
-
-typedef struct {
- uint32_t ec;
- uint32_t iss;
- uint32_t far;
- bool log;
- uint32_t action;
- bool taken;
-} sys_exception_t;
-
-#define EXCP_ACTION_SKIP 1
-
-#define SEC 0
-#define NSEC 1
-
-typedef struct {
- volatile int fail_count;
- volatile int test_count;
-} test_control_t;
-
-typedef struct {
- smc_interop_t smc_interop;
- sys_exception_t el3_excp;
- sys_exception_t el1_excp[2];
- uint32_t excp_action;
- bool excp_log;
- test_control_t *test_cntl;
-} sys_control_t;
-
-#endif
diff --git a/arm/el0_common/el0.c b/arm/el0_common/el0.c
deleted file mode 100644
index de6f7c2..0000000
--- a/arm/el0_common/el0.c
+++ /dev/null
@@ -1,26 +0,0 @@
-#include <stddef.h>
-#include <stdint.h>
-#include "interop.h"
-#include "svc.h"
-
-void *alloc_mem(int type, size_t len)
-{
- svc_op_desc_t op;
- op.alloc.type = type;
- op.alloc.len = len;
- op.alloc.addr = NULL;
- __svc(SVC_OP_ALLOC, &op);
-
- return op.alloc.addr;
-}
-
-void map_va(void *va, size_t len, int type)
-{
- svc_op_desc_t op;
- op.map.va = va;
- op.map.len = len;
- op.map.type = type;
-
- __svc(SVC_OP_MAP, &op);
-}
-
diff --git a/arm/el0_common/tztest.c b/arm/el0_common/tztest.c
deleted file mode 100644
index 2ca969e..0000000
--- a/arm/el0_common/tztest.c
+++ /dev/null
@@ -1,173 +0,0 @@
-#include "libcflat.h"
-#include "svc.h"
-#include "syscntl.h"
-#include "arch.h"
-#include "arm_builtins.h"
-#include "el0.h"
-#include "debug.h"
-#include "el0_common.h"
-#include "tztest.h"
-
-sys_control_t *syscntl = NULL;
-
-uint32_t check_smc(uint32_t el)
-{
- TEST_HEAD("smc behavior");
-
- TEST_MSG("SMC call");
- TEST_EL1_EXCEPTION(asm volatile("smc #0\n"), EC_UNKNOWN);
-
- return 0;
-}
-
-uint32_t check_register_access(uint32_t el)
-{
- /* Set things to non-secure P1 and attempt accesses */
- TEST_HEAD("restricted register access");
-
- TEST_MSG("SCR read");
- TEST_EL1_EXCEPTION(READ_SCR(), EC_UNKNOWN);
-
- TEST_MSG("SCR write");
- TEST_EL1_EXCEPTION(WRITE_SCR(0), EC_UNKNOWN);
-
- TEST_MSG("SDER read");
- TEST_EL1_EXCEPTION(READ_SDER(), EC_UNKNOWN);
-
- TEST_MSG("SDER write");
- TEST_EL1_EXCEPTION(WRITE_SDER(0), EC_UNKNOWN);
-
-#ifdef AARCH32
- TEST_MSG("MVBAR read");
- TEST_EL1_EXCEPTION(READ_MVBAR(), EC_UNKNOWN);
-
- TEST_MSG("MVBAR write");
- TEST_EL1_EXCEPTION(WRITE_MVBAR(0), EC_UNKNOWN);
-
- TEST_MSG("NSACR write");
- TEST_EL1_EXCEPTION(WRITE_NSACR(0), EC_UNKNOWN);
-#endif
-
-#ifdef AARCH64
- TEST_MSG("CPTR_EL3 read");
- TEST_EL1_EXCEPTION(READ_CPTR_EL3(), EC_UNKNOWN);
-
- TEST_MSG("CPTR_EL3 write");
- TEST_EL1_EXCEPTION(WRITE_CPTR_EL3(0), EC_UNKNOWN);
-#endif
-
- return 0;
-}
-
-#ifdef AARCH64
-uint32_t check_cpacr_trap(uint32_t el)
-{
- uint64_t cptr_el3, cpacr;
-
- TEST_HEAD("CPACR trapping");
-
- /* Get the current CPTR so we can restore it later */
- SVC_GET_REG(CPTR_EL3, 3, cptr_el3);
-
- /* Disable CPACR access */
- SVC_SET_REG(CPTR_EL3, 3, cptr_el3 | CPTR_TCPAC);
-
- /* Try to read CPACR */
- TEST_MSG("Read of disabled CPACR");
- TEST_EL3_EXCEPTION(SVC_GET_REG(CPACR, 1, cpacr), EC_SYSINSN);
-
- /* Try to write CPACR */
- TEST_MSG("Write of disabled CPACR");
- TEST_EL3_EXCEPTION(SVC_SET_REG(CPACR, 1, cpacr), EC_SYSINSN);
-
-#ifdef FP_TEST
- /* Disable FP access */
- TEST_MSG("Read of disabled FP reg");
- SVC_SET_REG(CPTR_EL3, 3, cptr_el3 | CPTR_TFP);
- TEST_EL3_EXCEPTION(asm volatile("fcmp s0, #0.0\n"), EC_SIMD);
-#endif
-
- /* Restore the original CPTR */
- SVC_SET_REG(CPTR_EL3, 3, cptr_el3);
-
- return 0;
-}
-
-uint32_t check_wfx_trap(uint32_t el)
-{
- uint64_t sctlr, scr;
-
- TEST_HEAD("WFx traps");
-
- /* Get the current SCR so we can restore it later */
- SVC_GET_REG(SCR, 3, scr);
-
- /* Get the current SCTLR so we can restore it later */
- SVC_GET_REG(SCTLR, 1, sctlr);
-
- /* Clear SCTLR.nTWE to cause WFE instructions to trap to EL1 */
- SVC_SET_REG(SCTLR, 1, sctlr & ~SCTLR_nTWE);
- TEST_MSG("Execution of WFE trapped to EL1");
- TEST_EL1_EXCEPTION(asm volatile("wfe\n"), EC_WFI_WFE);
-
- /* SCTLR.nTWE left as trapping to check precedence */
-
- /* Trap WFE instructions to EL3. This should work even though SCTLR.nTWE
- * is clear
- */
- SVC_SET_REG(SCR, 3, scr | SCR_WFE);
- TEST_MSG("Execution of trapped WFE (SCTLR.nTWE clear)",
- SEC_STATE_STR);
- TEST_EL3_EXCEPTION(asm volatile("wfe\n"), EC_WFI_WFE);
-
- /* Restore SCTLR */
- SVC_SET_REG(SCTLR, 1, sctlr);
-
- /* This should trap to EL3 with SCTLR.nTWE set */
- TEST_MSG("Execution of trapped WFE (SCTLR.nTWE set)",
- SEC_STATE_STR);
- TEST_EL3_EXCEPTION(asm volatile("wfe\n"), EC_WFI_WFE);
-
- /* Restore SCR */
- SVC_SET_REG(SCR, 3, scr);
-
- /* Clear SCTLR.nTWI to cause WFI instructions to trap to EL1 */
- SVC_SET_REG(SCTLR, 1, sctlr & ~SCTLR_nTWI);
- TEST_MSG("Execution of WFI trapped to EL1");
- TEST_EL1_EXCEPTION(asm volatile("wfi\n"), EC_WFI_WFE);
-
- /* SCTLR.nTWI left as trapping to check precedence */
-
- /* Trap WFI instructions to EL3. This should work even though SCTLR.nTWE
- * is clear
- */
- SVC_SET_REG(SCR, 3, scr | SCR_WFI);
-
- TEST_MSG("Execution of trapped WFI (SCTLR.nTWI clear)",
- SEC_STATE_STR);
- TEST_EL3_EXCEPTION(asm volatile("wfi\n"), EC_WFI_WFE);
-
- /* Restore SCTLR */
- SVC_SET_REG(SCTLR, 1, sctlr);
-
- TEST_MSG("Execution of trapped WFI (SCTLR.nTWI set)",
- SEC_STATE_STR);
- TEST_EL3_EXCEPTION(asm volatile("wfi\n"), EC_WFI_WFE);
-
- /* Restore SCR */
- SVC_SET_REG(SCR, 3, scr);
-
- return 0;
-}
-#endif
-
-void tztest_init()
-{
- tztest[TZTEST_SMC] = check_smc;
- tztest[TZTEST_REG_ACCESS] = check_register_access;
-#ifdef AARCH64
- tztest[TZTEST_CPACR_TRAP] = check_cpacr_trap;
- tztest[TZTEST_WFX_TRAP] = check_wfx_trap;
-#endif
-}
-
diff --git a/arm/el0_common/tztest.h b/arm/el0_common/tztest.h
deleted file mode 100644
index be31277..0000000
--- a/arm/el0_common/tztest.h
+++ /dev/null
@@ -1,65 +0,0 @@
-#ifndef _TZTEST_H
-#define _TZTEST_H
-
-typedef uint32_t (*tztest_t)(uint32_t el);
-extern tztest_t tztest[];
-
-extern void tztest_init();
-extern uint32_t check_smc(uint32_t el);
-extern uint32_t check_register_access(uint32_t el);
-extern uint32_t check_cpacr_trap(uint32_t el);
-extern uint32_t check_wfx_trap(uint32_t el);
-
-#define TEST_HEAD(_str, ...) \
- printf("\nValidating %s EL%d " _str ":\n", sec_state_str, el, ##__VA_ARGS__)
-
-#define TEST_MSG(_str, ...) \
- printf("\tEL%d (%s): " _str "... ", el, sec_state_str, ##__VA_ARGS__)
-
-#define INC_TEST_COUNT() (syscntl->test_cntl->test_count += 1)
-#define INC_FAIL_COUNT() (syscntl->test_cntl->fail_count += 1)
-
-#define TEST_CONDITION(_cond) \
- do { \
- if (!(_cond)) { \
- printf("FAILED\n"); \
- INC_FAIL_COUNT(); \
- } else { \
- printf("PASSED\n"); \
- } \
- INC_TEST_COUNT(); \
- } while(0)
-
-#define TEST_FUNCTION(_fn, _cond) \
- do { \
- _fn; \
- TEST_CONDITION(_cond); \
- } while(0)
-
-#define TEST_EXCEPTION(_fn, _excp, _el) \
- do { \
- syscntl->_el.ec = 0; \
- syscntl->excp_action = EXCP_ACTION_SKIP; \
- syscntl->excp_log = true; \
- _fn; \
- TEST_CONDITION(syscntl->_el.taken && \
- syscntl->_el.ec == (_excp)); \
- syscntl->_el.taken = 0; \
- syscntl->excp_action = 0; \
- syscntl->_el.ec = 0; \
- } while (0)
-
-#define TEST_EL1_EXCEPTION(_fn, _excp) \
- TEST_EXCEPTION(_fn, _excp, el1_excp[SEC_STATE])
-#define TEST_EL3_EXCEPTION(_fn, _excp) \
- TEST_EXCEPTION(_fn, _excp, el3_excp)
-
-typedef enum {
- TZTEST_SMC = 0,
- TZTEST_REG_ACCESS,
- TZTEST_CPACR_TRAP,
- TZTEST_WFX_TRAP,
- TZTEST_COUNT
-} tztest_func_id_t;
-
-#endif
diff --git a/arm/el0_ns/el0.h b/arm/el0_ns/el0.h
deleted file mode 100644
index 0a7da6a..0000000
--- a/arm/el0_ns/el0.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#ifndef _EL0_H
-#define _EL0_H
-
-#include "memory.h"
-
-#define EL0_STACK_BASE EL0_NS_STACK_BASE
-
-#define SEC_STATE_STR "non-secure"
-#define SEC_STATE 1
-
-#endif
diff --git a/arm/el0_ns/el0_nsec.lds.S b/arm/el0_ns/el0_nsec.lds.S
deleted file mode 100644
index 6b325c8..0000000
--- a/arm/el0_ns/el0_nsec.lds.S
+++ /dev/null
@@ -1,24 +0,0 @@
-OUTPUT_FORMAT(FORMAT)
-OUTPUT_ARCH(ARCH)
-TARGET(binary)
-ENTRY(main)
-
-#include "memory.h"
-
-SECTIONS
-{
- . = EL0_NS_BASE_VA;
- .text . : {
- _EL0_NS_TEXT_BASE = .;
- *(.text);
- _EL0_NS_TEXT_SIZE = SIZEOF(.text);
- }
-
- . = ALIGN(4k);
- .data . : {
- _EL0_NS_DATA_BASE = .;
- *(.*data);
- *(.*bss);
- _EL0_NS_DATA_SIZE = SIZEOF(.data);
- }
-}
diff --git a/arm/el0_ns/tztest_nsec.c b/arm/el0_ns/tztest_nsec.c
deleted file mode 100644
index b1f3946..0000000
--- a/arm/el0_ns/tztest_nsec.c
+++ /dev/null
@@ -1,79 +0,0 @@
-#include "el0_common.h"
-#include "tztest.h"
-
-tztest_t tztest[TZTEST_COUNT];
-const char *sec_state_str;
-
-void interop_test()
-{
- op_test_t test;
-
- test.orig = test.val = 1024;
- test.fail = test.count = 0;
- printf("\nValidating interop communication between ELs... ");
- __svc(SVC_OP_TEST, (svc_op_desc_t *)&test);
- TEST_CONDITION(!test.fail && test.val == (test.orig >> test.count));
-}
-
-void run_test(tztest_func_id_t fid, uint32_t el)
-{
- op_dispatch_t disp;
-
- tztest[fid](el);
-
- disp.func_id = fid;
- __svc(SVC_OP_DISPATCH, (svc_op_desc_t *)&disp);
-}
-
-int main()
-{
- svc_op_desc_t desc;
-
- /* ISSUE: For some reason, static initialization of the global security
- * state string fails. The pointer ends up being NULL in some cases, but
- * not in others. This likely has something to do with the position
- * independence of the EL0 code. The below workaround works fine.
- */
- const char *str = "non-secure";
- sec_state_str = str;
-
- printf("EL0 (%s) started...\n", sec_state_str);
-
- tztest_init();
-
- /* Fetch the system-wide control structure */
- __svc(SVC_OP_GET_SYSCNTL, &desc);
- syscntl = ((sys_control_t *)desc.get.data);
-
- /* Allocate and globally map test control descriptor */
- syscntl->test_cntl = (test_control_t*)alloc_mem(0, 0x1000);
- map_va(syscntl->test_cntl, 0x1000, OP_MAP_ALL);
-
- printf("Starting TZ test...\n");
-
- /* Test EL to EL communication */
- interop_test();
-
- /* If we didn't get a valid control structure then something has already
- * gone drastically wrong.
- */
- if (!syscntl) {
- DEBUG_MSG("Failed to acquire system control structure\n");
- __svc(SVC_OP_EXIT, &desc);
- }
-
- run_test(TZTEST_SMC, 0);
- run_test(TZTEST_REG_ACCESS, 0);
-#if AARCH64
- run_test(TZTEST_CPACR_TRAP, 0);
- run_test(TZTEST_WFX_TRAP, 0);
-#endif
-
- printf("\nValidation complete. Passed %d of %d tests.\n",
- syscntl->test_cntl->test_count - syscntl->test_cntl->fail_count,
- syscntl->test_cntl->test_count);
-
- __svc(SVC_OP_EXIT, NULL);
-
- return 0;
-}
diff --git a/arm/el0_s/el0.h b/arm/el0_s/el0.h
deleted file mode 100644
index 492da6b..0000000
--- a/arm/el0_s/el0.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#ifndef _EL0_H
-#define _EL0_H
-
-#include "memory.h"
-
-#define EL0_STACK_BASE EL0_S_STACK_BASE
-
-#define SEC_STATE_STR "secure"
-#define SEC_STATE 0
-
-#endif
diff --git a/arm/el0_s/el0_sec.lds.S b/arm/el0_s/el0_sec.lds.S
deleted file mode 100644
index 345ce2d..0000000
--- a/arm/el0_s/el0_sec.lds.S
+++ /dev/null
@@ -1,24 +0,0 @@
-OUTPUT_FORMAT(FORMAT)
-OUTPUT_ARCH(ARCH)
-TARGET(binary)
-ENTRY(main)
-
-#include "memory.h"
-
-SECTIONS
-{
- . = EL0_S_BASE_VA;
- .text . : AT(0x0) {
- _EL0_S_TEXT_BASE = .;
- *(.text);
- _EL0_S_TEXT_SIZE = SIZEOF(.text);
- }
-
- . = ALIGN(4k);
- .data . : {
- _EL0_S_DATA_BASE = .;
- *(.*data);
- *(.*bss);
- _EL0_S_DATA_SIZE = SIZEOF(.data);
- }
-}
diff --git a/arm/el0_s/tztest_sec.c b/arm/el0_s/tztest_sec.c
deleted file mode 100644
index 74e0518..0000000
--- a/arm/el0_s/tztest_sec.c
+++ /dev/null
@@ -1,83 +0,0 @@
-#include "el0_common.h"
-
-const char *sec_state_str;
-tztest_t tztest[TZTEST_COUNT];
-
-void el0_sec_loop()
-{
- svc_op_desc_t _desc , *desc = &_desc;
- uint32_t op = SVC_OP_YIELD;
-
- DEBUG_MSG("Starting loop - desc = %p\n", desc);
-
- while (op != SVC_OP_EXIT) {
- switch (op) {
- case SVC_OP_MAP:
- DEBUG_MSG("Handling a SVC_OP_MAP - desc = %p\n", desc);
- op = SVC_OP_MAP;
- break;
- case SVC_OP_YIELD:
- DEBUG_MSG("Handling a SVC_OP_YIELD - desc = %p\n", desc);
- break;
- case SVC_OP_TEST:
- DEBUG_MSG("Handling a SVC_OP_TEST - desc = %p\n", desc);
- if (desc->test.val != desc->test.orig >> desc->test.count) {
- desc->test.fail++;
- }
- desc->test.val >>= 1;
- desc->test.count++;
- op = SVC_OP_YIELD;
- break;
- case SVC_OP_DISPATCH:
- tztest[desc->disp.func_id](0);
- op = SVC_OP_YIELD;
- break;
- case 0:
- op = SVC_OP_YIELD;
- break;
- default:
- DEBUG_MSG("Unrecognized SVC opcode %d. Exiting ...\n", op);
- op = SVC_OP_EXIT;
- break;
- }
-
- DEBUG_MSG("Calling svc(%d, %p)\n", op, desc);
- op = __svc(op, desc);
- DEBUG_MSG("Returned from svc - op = %d &desc = %p\n", op, desc);
- }
-
- __svc(SVC_OP_EXIT, NULL);
-}
-
-int main()
-{
- svc_op_desc_t desc;
-
- /* ISSUE: For some reason, static initialization of the global security
- * state string fails. The pointer ends up being NULL in some cases, but
- * not in others. This likely has something to do with the position
- * independence of the EL0 code. The below workaround works fine.
- */
- const char *str = "secure";
- sec_state_str = str;
-
- printf("EL0 (%s) started...\n", sec_state_str);
-
- tztest_init();
-
- /* Fetch the system-wide control structure */
- __svc(SVC_OP_GET_SYSCNTL, &desc);
- syscntl = (sys_control_t *)desc.get.data;
-
- /* If we didn't get a valid control structure then something has already
- * gone drastically wrong.
- */
- if (!syscntl) {
- DEBUG_MSG("Failed to acquire system control structure\n");
- __svc(SVC_OP_EXIT, NULL);
- }
-
- el0_sec_loop();
-
- return 0;
-}
diff --git a/arm/el1_common/el1_common.h b/arm/el1_common/el1_common.h
deleted file mode 100644
index 27750bf..0000000
--- a/arm/el1_common/el1_common.h
+++ /dev/null
@@ -1,18 +0,0 @@
-#ifndef __EL1_COMMON_H
-#define __EL1_COMMON_H
-
-#include "libcflat.h"
-#include "memory.h"
-#include "svc.h"
-#include "smc.h"
-#include "string.h"
-#include "el1.h"
-#include "arch.h"
-#include "arm_builtins.h"
-#include "debug.h"
-#include "syscntl.h"
-
-extern void el1_init_el0();
-extern bool el1_load_el0(uintptr_t base, uintptr_t *entry);
-
-#endif
diff --git a/arm/el1_ns/el1_nsec.lds.S b/arm/el1_ns/el1_nsec.lds.S
deleted file mode 100644
index 21c1a33..0000000
--- a/arm/el1_ns/el1_nsec.lds.S
+++ /dev/null
@@ -1,35 +0,0 @@
-OUTPUT_FORMAT(FORMAT)
-OUTPUT_ARCH(ARCH)
-TARGET(binary)
-
-#include "memory.h"
-
-SECTIONS
-{
- . = EL1_NS_FLASH_BASE;
- .init . : {
- _EL1_NS_INIT_BASE = .;
- el1_init.o(.init);
- *(.init);
- }
- _EL1_NS_INIT_SIZE = SIZEOF(.init);
-
- . = ALIGN(4K);
- _EL1_NS_FLASH_TEXT = .;
- . = EL1_NS_BASE_VA;
- .text . : AT(_EL1_NS_FLASH_TEXT) {
- _EL1_NS_TEXT_BASE = .;
- *(.text);
- *(.vectors);
- }
- _EL1_NS_TEXT_SIZE = SIZEOF(.text);
-
- . = ALIGN(4k);
- .data . : {
- _EL1_NS_DATA_BASE = .;
- _EL1_NS_FLASH_DATA = LOADADDR(.data);
- *(.*data);
- *(.*bss);
- }
- _EL1_NS_DATA_SIZE = SIZEOF(.data);
-}
diff --git a/arm/el1_s/Makefile b/arm/el1_s/Makefile
deleted file mode 100644
index 2d46262..0000000
--- a/arm/el1_s/Makefile
+++ /dev/null
@@ -1,35 +0,0 @@
-VPATH = $(ARCH):../el1_common/$(ARCH):../el1_common:../common
-
-EL1_S_ELF = el1_sec.elf
-EL1_S_IMAGE = el1_sec.bin
-EL1_S_LOAD = el1_sec.lds
-EL1_S_OBJS = el1_init.o \
- el1_exception.o \
- el1.o \
- el1_loader.o \
- el1_sec.o \
- mem_util.o \
- builtins.o
-
--include .*.d
-
-CFLAGS += -I../el0_s/ -I../el1_common
-
-##################################################################
-
-$(EL1_S_ELF): $(EL1_S_OBJS) $(EL1_S_LOAD)
- $(LD) -o $@ $(EL1_S_OBJS) $(FLATLIBS) --script=$(EL1_S_LOAD)
-
-$(EL1_S_IMAGE): $(EL1_S_ELF)
- $(OBJCOPY) -O binary $< $@
-
-$(EL1_S_LOAD): el1_sec.lds.S Makefile ../../platform/$(PLAT)/
- $(CC) $(CFLAGS) -E -P -C -o $@ $<
-
-%.o: %.S
- $(CC) $(CFLAGS) -c -nostdlib -o $(notdir $@) $<
-
-all: $(EL1_S_IMAGE)
-
-clean:
- $(RM) $(EL1_S_OBJS) $(EL1_S_LOAD) $(EL1_S_ELF) $(EL1_S_IMAGE) .*.d
diff --git a/arm/el1_s/el1_sec.c b/arm/el1_s/el1_sec.c
deleted file mode 100644
index 36066c9..0000000
--- a/arm/el1_s/el1_sec.c
+++ /dev/null
@@ -1,64 +0,0 @@
-#include "el1_common.h"
-
-uintptr_t EL1_S_INIT_BASE = (uintptr_t)&_EL1_S_INIT_BASE;
-uintptr_t EL1_S_INIT_SIZE = (uintptr_t)&_EL1_S_INIT_SIZE;
-uintptr_t EL1_S_FLASH_TEXT = (uintptr_t)&_EL1_S_FLASH_TEXT;
-uintptr_t EL1_S_TEXT_BASE = (uintptr_t)&_EL1_S_TEXT_BASE;
-uintptr_t EL1_S_DATA_BASE = (uintptr_t)&_EL1_S_DATA_BASE;
-uintptr_t EL1_S_TEXT_SIZE = (uintptr_t)&_EL1_S_TEXT_SIZE;
-uintptr_t EL1_S_DATA_SIZE = (uintptr_t)&_EL1_S_DATA_SIZE;
-
-const char *sec_state_str = "secure";
-
-#if REMOVE_OR_INTEGRATE
-void el1_sec_check_init()
-{
- printf("\nValidating startup state:\n");
-
- printf("\tChecking for security extension ...");
- int idpfr1 = 0;
- /* Read the ID_PFR1 CP register and check that it is marked for support of
- * the security extension.
- */
- __mrc(15, 0, idpfr1, 0, 1, 1);
- if (0x10 != (idpfr1 & 0xf0)) {
- printf("FAILED\n");
- DEBUG_MSG("current IDPFR1 (%d) != expected IDPFR1 (%d)\n",
- (idpfr1 & 0xf0), 0x10);
- exit(1);
- } else {
- printf("PASSED\n");
- }
-
- printf("\tChecking initial processor mode... ");
- if (CPSR_M_SVC != (_read_cpsr() & 0x1f)) {
- printf("FAILED\n");
- DEBUG_MSG("current CPSR (%d) != expected CPSR (%d)\n",
- (_read_cpsr() & 0x1f), CPSR_M_SVC);
- assert(CPSR_M_SVC == (_read_cpsr() & 0x1f));
- } else {
- printf("PASSED\n");
- }
-
- // Test: Check that on reset if sec et present, starts in sec state
- // pg. B1-1204
- printf("\tChecking initial security state... ");
- if (0 != (_read_scr() & SCR_NS)) {
- printf("Failed\n");
- DEBUG_MSG("current SCR.NS (%d) != expected SCR.NS (%d)\n",
- (_read_cpsr() & SCR_NS), 0);
- assert(0 == (_read_scr() & SCR_NS));
- } else {
- printf("PASSED\n");
- }
-}
-#endif
-
-void el1_init_el0()
-{
- uintptr_t main;
-
- el1_load_el0(EL0_S_FLASH_BASE, &main);
-
- __exception_return(main, SPSR_EL0);
-}
diff --git a/arm/el1_s/el1_sec.lds.S b/arm/el1_s/el1_sec.lds.S
deleted file mode 100644
index 14b4b47..0000000
--- a/arm/el1_s/el1_sec.lds.S
+++ /dev/null
@@ -1,35 +0,0 @@
-OUTPUT_FORMAT(FORMAT)
-OUTPUT_ARCH(ARCH)
-TARGET(binary)
-
-#include "memory.h"
-
-SECTIONS
-{
- . = EL1_S_FLASH_BASE;
- .init . : {
- _EL1_S_INIT_BASE = .;
- el1_init.o(.init);
- *(.init);
- }
- _EL1_S_INIT_SIZE = SIZEOF(.init);
-
- . = ALIGN(4K);
- _EL1_S_FLASH_TEXT = .;
- . = EL1_S_BASE_VA;
- .text . : AT(_EL1_S_FLASH_TEXT) {
- _EL1_S_TEXT_BASE = .;
- *(.text);
- *(.vectors);
- }
- _EL1_S_TEXT_SIZE = SIZEOF(.text);
-
- . = ALIGN(4k);
- .data . : {
- _EL1_S_DATA_BASE = .;
- _EL1_S_FLASH_DATA = LOADADDR(.data);
- *(.*data);
- *(.*bss);
- }
- _EL1_S_DATA_SIZE = SIZEOF(.data);
-}
diff --git a/arm/el3/el3.h b/arm/el3/el3.h
deleted file mode 100644
index 930fb5a..0000000
--- a/arm/el3/el3.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#ifndef _EL3_H
-#define _EL3_H
-
-extern uintptr_t _EL3_TEXT_BASE;
-extern uintptr_t EL3_TEXT_BASE;
-extern uintptr_t _EL3_DATA_BASE;
-extern uintptr_t EL3_DATA_BASE;
-extern uintptr_t _EL3_TEXT_SIZE;
-extern uintptr_t EL3_TEXT_SIZE;
-extern uintptr_t _EL3_DATA_SIZE;
-extern uintptr_t EL3_DATA_SIZE;
-
-#endif
diff --git a/arm/el3/el3.lds.S b/arm/el3/el3.lds.S
deleted file mode 100644
index e8f21f0..0000000
--- a/arm/el3/el3.lds.S
+++ /dev/null
@@ -1,35 +0,0 @@
-OUTPUT_FORMAT(FORMAT)
-OUTPUT_ARCH(ARCH)
-TARGET(binary)
-
-#include "memory.h"
-
-SECTIONS
-{
- . = EL3_FLASH_BASE;
- .init . : {
- _EL3_INIT_BASE = .;
- el3_init.o(.init);
- *(.init);
- }
- _EL3_INIT_SIZE = SIZEOF(.init);
-
- . = ALIGN(4K);
- _EL3_FLASH_TEXT = .;
- . = EL3_BASE_VA;
- .text . : AT(_EL3_FLASH_TEXT) {
- _EL3_TEXT_BASE = .;
- *(.text);
- *(.vectors);
- }
- _EL3_TEXT_SIZE = SIZEOF(.text);
-
- . = ALIGN(4k);
- .data . : {
- _EL3_DATA_BASE = .;
- _EL3_FLASH_DATA = LOADADDR(.data);
- *(.*data);
- *(.*bss);
- }
- _EL3_DATA_SIZE = SIZEOF(.data);
-}
diff --git a/aarch64/common/arm_builtins.h b/common/aarch64/arm_builtins.h
index 9d0f1b9..9d0f1b9 100644
--- a/aarch64/common/arm_builtins.h
+++ b/common/aarch64/arm_builtins.h
diff --git a/aarch64/common/builtins.S b/common/aarch64/builtins.S
index cfc8a41..cfc8a41 100644
--- a/aarch64/common/builtins.S
+++ b/common/aarch64/builtins.S
diff --git a/aarch64/common/armv8_exception.h b/common/aarch64/exception.h
index 343cfdc..343cfdc 100644
--- a/aarch64/common/armv8_exception.h
+++ b/common/aarch64/exception.h
diff --git a/aarch64/common/init_util.S b/common/aarch64/init_util.S
index f1dd26b..7ecc56b 100644
--- a/aarch64/common/init_util.S
+++ b/common/aarch64/init_util.S
@@ -1,4 +1,4 @@
-#include "armv8_vmsa.h"
+#include "vmsa.h"
.section .init
/* allocate_pa() - Allocates and returns next pool PA */
diff --git a/aarch64/common/mem_util.c b/common/aarch64/mem_util.c
index 76ea6b8..3ca8f1c 100644
--- a/aarch64/common/mem_util.c
+++ b/common/aarch64/mem_util.c
@@ -1,6 +1,6 @@
#include "libcflat.h"
-#include "arch.h"
#include <stdint.h>
+#include "vmsa.h"
#include <stddef.h>
#include "mem_util.h"
diff --git a/aarch64/common/memory.h b/common/aarch64/memory.h
index f5c8422..f5c8422 100644
--- a/aarch64/common/memory.h
+++ b/common/aarch64/memory.h
diff --git a/aarch64/common/armv8_regs.h b/common/aarch64/register.h
index 5851d1a..5851d1a 100644
--- a/aarch64/common/armv8_regs.h
+++ b/common/aarch64/register.h
diff --git a/aarch64/common/armv8_vmsa.h b/common/aarch64/vmsa.h
index fda6c46..fda6c46 100644
--- a/aarch64/common/armv8_vmsa.h
+++ b/common/aarch64/vmsa.h
diff --git a/arm/common/arm_builtins.h b/common/arm/arm_builtins.h
index ae03bff..ae03bff 100644
--- a/arm/common/arm_builtins.h
+++ b/common/arm/arm_builtins.h
diff --git a/arm/common/builtins.S b/common/arm/builtins.S
index e117a61..e117a61 100644
--- a/arm/common/builtins.S
+++ b/common/arm/builtins.S
diff --git a/arm/common/armv7_exception.h b/common/arm/exception.h
index 056e5e4..056e5e4 100644
--- a/arm/common/armv7_exception.h
+++ b/common/arm/exception.h
diff --git a/arm/common/init_util.S b/common/arm/init_util.S
index eeca515..eeca515 100644
--- a/arm/common/init_util.S
+++ b/common/arm/init_util.S
diff --git a/arm/common/mem_util.c b/common/arm/mem_util.c
index 17e680d..631be06 100644
--- a/arm/common/mem_util.c
+++ b/common/arm/mem_util.c
@@ -1,7 +1,7 @@
#include "libcflat.h"
-#include "arch.h"
#include <stdint.h>
#include <stddef.h>
+#include "vmsa.h"
#include "mem_util.h"
#define SEC_STATE_STR "EL3"
diff --git a/arm/common/memory.h b/common/arm/memory.h
index 0899ae7..0899ae7 100644
--- a/arm/common/memory.h
+++ b/common/arm/memory.h
diff --git a/arm/common/armv7_regs.h b/common/arm/register.h
index 9777a8e..9777a8e 100644
--- a/arm/common/armv7_regs.h
+++ b/common/arm/register.h
diff --git a/arm/common/armv7_vmsa.h b/common/arm/vmsa.h
index 9cefca9..9cefca9 100644
--- a/arm/common/armv7_vmsa.h
+++ b/common/arm/vmsa.h
diff --git a/aarch64/common/debug.h b/common/debug.h
index c9af5fe..c9af5fe 100644
--- a/aarch64/common/debug.h
+++ b/common/debug.h
diff --git a/arm/common/interop.h b/common/interop.h
index 1e47f03..1e47f03 100644
--- a/arm/common/interop.h
+++ b/common/interop.h
diff --git a/aarch64/common/mem_util.h b/common/mem_util.h
index c7beec8..c7beec8 100644
--- a/aarch64/common/mem_util.h
+++ b/common/mem_util.h
diff --git a/aarch64/common/smc.h b/common/smc.h
index b54991e..b54991e 100644
--- a/aarch64/common/smc.h
+++ b/common/smc.h
diff --git a/aarch64/common/svc.h b/common/svc.h
index 0bfaff0..0bfaff0 100644
--- a/aarch64/common/svc.h
+++ b/common/svc.h
diff --git a/aarch64/common/syscntl.h b/common/syscntl.h
index 75d2637..75d2637 100644
--- a/aarch64/common/syscntl.h
+++ b/common/syscntl.h
diff --git a/config.mk b/config.mk
new file mode 100644
index 0000000..82e89ca
--- /dev/null
+++ b/config.mk
@@ -0,0 +1,9 @@
+export ARCH=aarch64
+export PLAT=virt
+export PROCESSOR=cortex-a57
+export CROSS=aarch64-linux-gnu
+export CC=aarch64-linux-gnu-gcc
+export LD=aarch64-linux-gnu-ld
+export OBJCOPY=aarch64-linux-gnu-objcopy
+export AR=aarch64-linux-gnu-ar
+export CFLAGS+=
diff --git a/configure b/configure
index c4ff9e1..4392a76 100755
--- a/configure
+++ b/configure
@@ -10,12 +10,12 @@ usage() {
Usage: $0 [options]
Options include:
- --arch=ARCH architecture to compile for
- --plat=PLATFORM platform to compile for
- --cpu=PROCESSOR cpu to compile for
- --cross-prefix=PREFIX cross compiler prefix
- --cc=CC c compiler to use
- --ld=LD ld linker to use
+ --arch=ARCH Architecture: arm or aarch64
+ --plat=PLATFORM Platform: virt or vexpress-a15
+ --cpu=PROCESSOR CPU: cortex-a15 or cortex-a57
+ --cross-prefix=PREFIX Cross compiler
+ --cc=CC C compiler to use (blank is auto)
+ --ld=LD Loader to use (blank is auto)
EOF
exit 1
}
@@ -88,7 +88,7 @@ if [ "$arch" = "arm" ]; then
fi
# create the config
-cat <<EOF > config.mak
+cat <<EOF > config.mk
export ARCH=$arch
export PLAT=$plat
export PROCESSOR=$cpu
diff --git a/aarch64/el0_common/el0.c b/el0/el0.c
index de6f7c2..de6f7c2 100644
--- a/aarch64/el0_common/el0.c
+++ b/el0/el0.c
diff --git a/arm/el0_common/el0_common.h b/el0/el0_common.h
index 2e33c5a..8177038 100644
--- a/arm/el0_common/el0_common.h
+++ b/el0/el0_common.h
@@ -4,7 +4,6 @@
#include "libcflat.h"
#include "svc.h"
#include "syscntl.h"
-#include "arch.h"
#include "arm_builtins.h"
#include "el0.h"
#include "debug.h"
diff --git a/arm/el0_ns/Makefile b/el0/nonsecure/Makefile
index 5e3cfad..d2b45d4 100644
--- a/arm/el0_ns/Makefile
+++ b/el0/nonsecure/Makefile
@@ -1,4 +1,4 @@
-VPATH = ../el0_common:../common
+VPATH = $(ARCH):../$(ARCH):../../common/$(ARCH):../
EL0_NS_ELF = el0_nsec.elf
EL0_NS_IMAGE = el0_nsec.bin
@@ -8,9 +8,13 @@ EL0_NS_OBJS = tztest_nsec.o \
el0.o \
builtins.o
+libgcc := $(shell $(CC) $(CFLAGS) --print-libgcc-file-name)
+FLATLIBS = ../../libcflat/libcflat.a $(libgcc) ../../libcflat/$(ARCH)/libeabi.a
+
-include .*.d
-CFLAGS += -I../el0_common
+CFLAGS += -I$(ARCH) -I../$(ARCH) -I../ -I../$(ARCH)
+CFLAGS += -I../../common/$(ARCH) -I../../common/
##################################################################
diff --git a/aarch64/el0_ns/el0.h b/el0/nonsecure/el0.h
index 0a7da6a..0a7da6a 100644
--- a/aarch64/el0_ns/el0.h
+++ b/el0/nonsecure/el0.h
diff --git a/aarch64/el0_ns/el0_nsec.lds.S b/el0/nonsecure/el0_nsec.lds.S
index 6b325c8..6b325c8 100644
--- a/aarch64/el0_ns/el0_nsec.lds.S
+++ b/el0/nonsecure/el0_nsec.lds.S
diff --git a/aarch64/el0_ns/tztest_nsec.c b/el0/nonsecure/tztest_nsec.c
index b1f3946..b1f3946 100644
--- a/aarch64/el0_ns/tztest_nsec.c
+++ b/el0/nonsecure/tztest_nsec.c
diff --git a/arm/el0_s/Makefile b/el0/secure/Makefile
index 336d318..d08f143 100644
--- a/arm/el0_s/Makefile
+++ b/el0/secure/Makefile
@@ -1,4 +1,4 @@
-VPATH = ../el0_common:../common
+VPATH = $(ARCH):../$(ARCH):../../common/$(ARCH):../
EL0_S_ELF = el0_sec.elf
EL0_S_IMAGE = el0_sec.bin
@@ -8,9 +8,13 @@ EL0_S_OBJS = tztest_sec.o \
el0.o \
builtins.o
+libgcc := $(shell $(CC) $(CFLAGS) --print-libgcc-file-name)
+FLATLIBS = ../../libcflat/libcflat.a $(libgcc) ../../libcflat/$(ARCH)/libeabi.a
+
-include .*.d
-CFLAGS += -I../el0_common
+CFLAGS += -I$(ARCH) -I../$(ARCH) -I../ -I../$(ARCH)
+CFLAGS += -I../../common/$(ARCH) -I../../common/
##################################################################
diff --git a/aarch64/el0_s/el0.h b/el0/secure/el0.h
index 492da6b..492da6b 100644
--- a/aarch64/el0_s/el0.h
+++ b/el0/secure/el0.h
diff --git a/aarch64/el0_s/el0_sec.lds.S b/el0/secure/el0_sec.lds.S
index 345ce2d..345ce2d 100644
--- a/aarch64/el0_s/el0_sec.lds.S
+++ b/el0/secure/el0_sec.lds.S
diff --git a/aarch64/el0_s/tztest_sec.c b/el0/secure/tztest_sec.c
index 74e0518..74e0518 100644
--- a/aarch64/el0_s/tztest_sec.c
+++ b/el0/secure/tztest_sec.c
diff --git a/aarch64/el0_common/tztest.c b/el0/tztest.c
index 2ca969e..bd15505 100644
--- a/aarch64/el0_common/tztest.c
+++ b/el0/tztest.c
@@ -1,8 +1,8 @@
#include "libcflat.h"
#include "svc.h"
#include "syscntl.h"
-#include "arch.h"
#include "arm_builtins.h"
+#include "exception.h"
#include "el0.h"
#include "debug.h"
#include "el0_common.h"
diff --git a/aarch64/el0_common/tztest.h b/el0/tztest.h
index be31277..be31277 100644
--- a/aarch64/el0_common/tztest.h
+++ b/el0/tztest.h
diff --git a/aarch64/el1_common/aarch64/el1_exception.S b/el1/aarch64/el1_exception.S
index 1c5ca15..9d6ec38 100644
--- a/aarch64/el1_common/aarch64/el1_exception.S
+++ b/el1/aarch64/el1_exception.S
@@ -1,5 +1,5 @@
#define __ASSEMBLY__
-#include "armv8_exception.h"
+#include "exception.h"
#undef __ASSEMBLY__
.section .vectors
diff --git a/aarch64/el1_common/aarch64/el1_init.S b/el1/aarch64/el1_init.S
index b567404..7116a04 100644
--- a/aarch64/el1_common/aarch64/el1_init.S
+++ b/el1/aarch64/el1_init.S
@@ -1,8 +1,8 @@
#define __ASSEMBLY__
#include "memory.h"
+#include "vmsa.h"
#include "el1.h"
#include "el0.h"
-#include "armv8_vmsa.h"
#undef __ASSEMBLY__
.section .init
diff --git a/aarch64/el1_common/aarch64/el1_loader.c b/el1/aarch64/el1_loader.c
index 989195c..8820ec8 100644
--- a/aarch64/el1_common/aarch64/el1_loader.c
+++ b/el1/aarch64/el1_loader.c
@@ -1,4 +1,5 @@
#include "el1_common.h"
+#include "vmsa.h"
#include "elf.h"
#include "mem_util.h"
diff --git a/arm/el1_common/arm/el1_exception.S b/el1/arm/el1_exception.S
index 657302e..943fc20 100644
--- a/arm/el1_common/arm/el1_exception.S
+++ b/el1/arm/el1_exception.S
@@ -1,5 +1,6 @@
#define __ASSEMBLY__
-#include "arch.h"
+#include "register.h"
+#include "exception.h"
#undef __ASSEMBLY__
.section .vectors
diff --git a/arm/el1_common/arm/el1_init.S b/el1/arm/el1_init.S
index 86ec2a6..3768661 100644
--- a/arm/el1_common/arm/el1_init.S
+++ b/el1/arm/el1_init.S
@@ -1,7 +1,8 @@
#define __ASSEMBLY__
-#include "arch.h"
#include "platform.h"
#include "memory.h"
+#include "register.h"
+#include "vmsa.h"
#include "el1.h"
#include "el0.h"
#undef __ASSEMBLY__
diff --git a/arm/el1_common/arm/el1_loader.c b/el1/arm/el1_loader.c
index c25811f..57c7190 100644
--- a/arm/el1_common/arm/el1_loader.c
+++ b/el1/arm/el1_loader.c
@@ -1,4 +1,5 @@
#include "el1_common.h"
+#include "vmsa.h"
#include "elf.h"
#include "mem_util.h"
diff --git a/arm/el1_common/el1.c b/el1/el1.c
index a908625..f47ae9c 100644
--- a/arm/el1_common/el1.c
+++ b/el1/el1.c
@@ -1,4 +1,6 @@
#include "el1_common.h"
+#include "exception.h"
+#include "vmsa.h"
#include "mem_util.h"
uintptr_t mem_pgtbl_base = EL1_PGTBL_BASE;
diff --git a/aarch64/el1_common/el1_common.h b/el1/el1_common.h
index 27750bf..cf4fa24 100644
--- a/aarch64/el1_common/el1_common.h
+++ b/el1/el1_common.h
@@ -7,7 +7,6 @@
#include "smc.h"
#include "string.h"
#include "el1.h"
-#include "arch.h"
#include "arm_builtins.h"
#include "debug.h"
#include "syscntl.h"
diff --git a/arm/el1_ns/Makefile b/el1/nonsecure/Makefile
index f7ac0fd..71e65d2 100644
--- a/arm/el1_ns/Makefile
+++ b/el1/nonsecure/Makefile
@@ -1,4 +1,4 @@
-VPATH = $(ARCH):../el1_common/$(ARCH):../el1_common:../common
+VPATH = $(ARCH):../$(ARCH):../../common/$(ARCH):../
EL1_NS_ELF = el1_nsec.elf
EL1_NS_IMAGE = el1_nsec.bin
@@ -11,9 +11,14 @@ EL1_NS_OBJS = el1_init.o \
mem_util.o \
builtins.o
+libgcc := $(shell $(CC) $(CFLAGS) --print-libgcc-file-name)
+FLATLIBS = ../../libcflat/libcflat.a $(libgcc) ../../libcflat/$(ARCH)/libeabi.a
+
-include .*.d
-CFLAGS += -I../el0_ns/ -I../el1_common
+CFLAGS += -I$(ARCH) -I../$(ARCH) -I../ -I../$(ARCH)
+CFLAGS += -I../../common/$(ARCH) -I../../common/
+CFLAGS += -I../../el0/nonsecure/
##################################################################
diff --git a/aarch64/el1_ns/aarch64/el1.h b/el1/nonsecure/aarch64/el1.h
index 3f84ec6..3f84ec6 100644
--- a/aarch64/el1_ns/aarch64/el1.h
+++ b/el1/nonsecure/aarch64/el1.h
diff --git a/arm/el1_ns/arm/el1.h b/el1/nonsecure/arm/el1.h
index eb4c30b..eb4c30b 100644
--- a/arm/el1_ns/arm/el1.h
+++ b/el1/nonsecure/arm/el1.h
diff --git a/arm/el1_ns/el1_nsec.c b/el1/nonsecure/el1_nsec.c
index 5bd5d22..afc8e48 100644
--- a/arm/el1_ns/el1_nsec.c
+++ b/el1/nonsecure/el1_nsec.c
@@ -1,4 +1,5 @@
#include "el1_common.h"
+#include "register.h"
uintptr_t EL1_NS_INIT_BASE = (uintptr_t)&_EL1_NS_INIT_BASE;
uintptr_t EL1_NS_INIT_SIZE = (uintptr_t)&_EL1_NS_INIT_SIZE;
diff --git a/aarch64/el1_ns/el1_nsec.lds.S b/el1/nonsecure/el1_nsec.lds.S
index 21c1a33..21c1a33 100644
--- a/aarch64/el1_ns/el1_nsec.lds.S
+++ b/el1/nonsecure/el1_nsec.lds.S
diff --git a/aarch64/el1_s/Makefile b/el1/secure/Makefile
index 2d46262..43876d7 100644
--- a/aarch64/el1_s/Makefile
+++ b/el1/secure/Makefile
@@ -1,4 +1,4 @@
-VPATH = $(ARCH):../el1_common/$(ARCH):../el1_common:../common
+VPATH = $(ARCH):../$(ARCH):../../common/$(ARCH):../
EL1_S_ELF = el1_sec.elf
EL1_S_IMAGE = el1_sec.bin
@@ -11,9 +11,14 @@ EL1_S_OBJS = el1_init.o \
mem_util.o \
builtins.o
+libgcc := $(shell $(CC) $(CFLAGS) --print-libgcc-file-name)
+FLATLIBS = ../../libcflat/libcflat.a $(libgcc) ../../libcflat/$(ARCH)/libeabi.a
+
-include .*.d
-CFLAGS += -I../el0_s/ -I../el1_common
+CFLAGS += -I$(ARCH) -I../$(ARCH) -I../ -I../$(ARCH)
+CFLAGS += -I../../common/$(ARCH) -I../../common/
+CFLAGS += -I../../el0/secure/
##################################################################
diff --git a/aarch64/el1_s/aarch64/el1.h b/el1/secure/aarch64/el1.h
index 99cc302..99cc302 100644
--- a/aarch64/el1_s/aarch64/el1.h
+++ b/el1/secure/aarch64/el1.h
diff --git a/arm/el1_s/arm/el1.h b/el1/secure/arm/el1.h
index 42dc57a..42dc57a 100644
--- a/arm/el1_s/arm/el1.h
+++ b/el1/secure/arm/el1.h
diff --git a/aarch64/el1_s/el1_sec.c b/el1/secure/el1_sec.c
index 36066c9..7120c12 100644
--- a/aarch64/el1_s/el1_sec.c
+++ b/el1/secure/el1_sec.c
@@ -1,4 +1,5 @@
#include "el1_common.h"
+#include "register.h"
uintptr_t EL1_S_INIT_BASE = (uintptr_t)&_EL1_S_INIT_BASE;
uintptr_t EL1_S_INIT_SIZE = (uintptr_t)&_EL1_S_INIT_SIZE;
diff --git a/aarch64/el1_s/el1_sec.lds.S b/el1/secure/el1_sec.lds.S
index 14b4b47..14b4b47 100644
--- a/aarch64/el1_s/el1_sec.lds.S
+++ b/el1/secure/el1_sec.lds.S
diff --git a/arm/el3/Makefile b/el3/Makefile
index a0b2373..219855f 100644
--- a/arm/el3/Makefile
+++ b/el3/Makefile
@@ -1,4 +1,4 @@
-VPATH = ../common:$(ARCH)
+VPATH = $(ARCH):../common/$(ARCH):../common
EL3_ELF = el3.elf
EL3_IMAGE = el3.bin
@@ -10,6 +10,9 @@ EL3_OBJS = el3_init.o \
mem_util.o \
builtins.o
+libgcc := $(shell $(CC) $(CFLAGS) --print-libgcc-file-name)
+FLATLIBS = ../libcflat/libcflat.a $(libgcc) ../libcflat/$(ARCH)/libeabi.a
+
-include .*.d
##################################################################
diff --git a/aarch64/el3/aarch64/el3_exception.S b/el3/aarch64/el3_exception.S
index 5410766..42340ba 100644
--- a/aarch64/el3/aarch64/el3_exception.S
+++ b/el3/aarch64/el3_exception.S
@@ -1,5 +1,6 @@
#define __ASSEMBLY__
-#include "armv8_exception.h"
+#include "register.h"
+#include "exception.h"
#undef __ASSEMBLY__
.section .vectors
diff --git a/aarch64/el3/aarch64/el3_init.S b/el3/aarch64/el3_init.S
index 03934fa..3ab35cd 100644
--- a/aarch64/el3/aarch64/el3_init.S
+++ b/el3/aarch64/el3_init.S
@@ -1,6 +1,7 @@
#include "platform.h"
#include "memory.h"
-#include "armv8_vmsa.h"
+#include "register.h"
+#include "vmsa.h"
#define PT_BASE EL3_PGTBL_BASE
diff --git a/aarch64/el3/aarch64/el3_monitor.h b/el3/aarch64/el3_monitor.h
index 7b11611..7b11611 100644
--- a/aarch64/el3/aarch64/el3_monitor.h
+++ b/el3/aarch64/el3_monitor.h
diff --git a/aarch64/el3/aarch64/el3_monitor_asm.S b/el3/aarch64/el3_monitor_asm.S
index 3db33a9..1b989ef 100644
--- a/aarch64/el3/aarch64/el3_monitor_asm.S
+++ b/el3/aarch64/el3_monitor_asm.S
@@ -1,5 +1,7 @@
#define __ASSEMBLY__
#include "smc.h"
+#include "register.h"
+#undef __ASSEMBLY__
.section .text
.macro SAVE_SYS_PAIR reg1, reg2, idx
diff --git a/arm/el3/arm/el3_exception.S b/el3/arm/el3_exception.S
index a2b3e32..8db1e4d 100644
--- a/arm/el3/arm/el3_exception.S
+++ b/el3/arm/el3_exception.S
@@ -1,5 +1,6 @@
#define __ASSEMBLY__
-#include "arch.h"
+#include "register.h"
+#include "exception.h"
#undef __ASSEMBLY__
.section .vectors
diff --git a/arm/el3/arm/el3_init.S b/el3/arm/el3_init.S
index 1d58108..97762ec 100644
--- a/arm/el3/arm/el3_init.S
+++ b/el3/arm/el3_init.S
@@ -1,7 +1,8 @@
#define __ASSEMBLY__
-#include "arch.h"
-#include "platform.h"
#include "memory.h"
+#include "register.h"
+#include "vmsa.h"
+#include "platform.h"
#undef __ASSEMBLY__
.arch_extension sec
diff --git a/arm/el3/arm/el3_monitor.h b/el3/arm/el3_monitor.h
index 6c0727e..6c0727e 100644
--- a/arm/el3/arm/el3_monitor.h
+++ b/el3/arm/el3_monitor.h
diff --git a/arm/el3/arm/el3_monitor_asm.S b/el3/arm/el3_monitor_asm.S
index 98002cc..7349ac3 100644
--- a/arm/el3/arm/el3_monitor_asm.S
+++ b/el3/arm/el3_monitor_asm.S
@@ -1,6 +1,7 @@
#define __ASSEMBLY__
#include "smc.h"
-#include "arch.h"
+#include "register.h"
+#undef __ASSEMBLY__
.section .text
diff --git a/arm/el3/el3.c b/el3/el3.c
index 49b5f56..4ee3b08 100644
--- a/arm/el3/el3.c
+++ b/el3/el3.c
@@ -2,12 +2,14 @@
#include <stddef.h>
#include "platform.h"
#include "memory.h"
+#include "exception.h"
+#include "vmsa.h"
+#include "register.h"
#include "el3.h"
#include "string.h"
#include "libcflat.h"
#include "smc.h"
#include "svc.h"
-#include "arch.h"
#include "el3_monitor.h"
#include "arm_builtins.h"
#include "syscntl.h"
diff --git a/aarch64/el3/el3.h b/el3/el3.h
index 930fb5a..930fb5a 100644
--- a/aarch64/el3/el3.h
+++ b/el3/el3.h
diff --git a/aarch64/el3/el3.lds.S b/el3/el3.lds.S
index e8f21f0..e8f21f0 100644
--- a/aarch64/el3/el3.lds.S
+++ b/el3/el3.lds.S
diff --git a/arm/common/tztest.c b/tztest/tztest.c
index 1a3b79b..1a3b79b 100644
--- a/arm/common/tztest.c
+++ b/tztest/tztest.c
diff --git a/arm/common/tztest.h b/tztest/tztest.h
index 34ced86..34ced86 100644
--- a/arm/common/tztest.h
+++ b/tztest/tztest.h