diff options
author | Greg Bellows <greg.bellows@linaro.org> | 2015-04-14 11:20:04 -0500 |
---|---|---|
committer | Greg Bellows <greg.bellows@linaro.org> | 2015-04-14 12:22:43 -0500 |
commit | 9299b7bc6ebcccb9d6723471c80b9923818018e7 (patch) | |
tree | 26655c7ac3a6b69c82a0812de4d30464b0361944 | |
parent | 7a32277fbcf32bf11c8f3a0319c9e468694ff9e3 (diff) |
Add static EL and secure state constants
Signed-off-by: Greg Bellows <greg.bellows@linaro.org>
-rw-r--r-- | common/debug.h | 2 | ||||
-rw-r--r-- | common/state.h | 16 | ||||
-rw-r--r-- | el0/el0_common.h | 2 | ||||
-rw-r--r-- | el0/nonsecure/el0.h | 11 | ||||
-rw-r--r-- | el0/nonsecure/el0_nsec.c | 2 | ||||
-rw-r--r-- | el0/secure/el0.h | 11 | ||||
-rw-r--r-- | el0/secure/el0_sec.c | 2 | ||||
-rw-r--r-- | el1/aarch64/el1_init.S | 1 | ||||
-rw-r--r-- | el1/arm/el1_init.S | 1 | ||||
-rw-r--r-- | el1/el1.c | 16 | ||||
-rw-r--r-- | el1/el1_common.h | 1 | ||||
-rw-r--r-- | el1/nonsecure/Makefile | 1 | ||||
-rw-r--r-- | el1/nonsecure/aarch64/el1.h | 3 | ||||
-rw-r--r-- | el1/nonsecure/arm/el1.h | 3 | ||||
-rw-r--r-- | el1/nonsecure/el1_nsec.c | 2 | ||||
-rw-r--r-- | el1/secure/Makefile | 1 | ||||
-rw-r--r-- | el1/secure/aarch64/el1.h | 3 | ||||
-rw-r--r-- | el1/secure/arm/el1.h | 3 | ||||
-rw-r--r-- | el1/secure/el1_sec.c | 2 | ||||
-rw-r--r-- | el3/el3.c | 4 | ||||
-rw-r--r-- | tztest/tztest_el0.c | 18 | ||||
-rw-r--r-- | tztest/tztest_internal.h | 9 |
22 files changed, 56 insertions, 58 deletions
diff --git a/common/debug.h b/common/debug.h index c9af5fe..e391240 100644 --- a/common/debug.h +++ b/common/debug.h @@ -1,7 +1,7 @@ #ifndef _DEBUG_H #define _DEBUG_H -extern const char *sec_state_str; +#include "state.h" #ifdef DEBUG #define DEBUG_MSG(_str, ...) \ diff --git a/common/state.h b/common/state.h new file mode 100644 index 0000000..2c70471 --- /dev/null +++ b/common/state.h @@ -0,0 +1,16 @@ +#ifndef _STATE_H +#define _STATE_H + +extern const char *sec_state_str; +extern const uint32_t secure_state; +extern const uint32_t exception_level; + +#define EL0 0 +#define EL1 1 +#define EL2 2 +#define EL3 3 + +#define SECURE 0 +#define NONSECURE 1 + +#endif diff --git a/el0/el0_common.h b/el0/el0_common.h index 5b91ddf..f7a6318 100644 --- a/el0/el0_common.h +++ b/el0/el0_common.h @@ -5,8 +5,8 @@ #include "svc.h" #include "syscntl.h" #include "arm_builtins.h" -#include "el0.h" #include "debug.h" +#include "state.h" extern sys_control_t *syscntl; diff --git a/el0/nonsecure/el0.h b/el0/nonsecure/el0.h deleted file mode 100644 index 0a7da6a..0000000 --- a/el0/nonsecure/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/el0/nonsecure/el0_nsec.c b/el0/nonsecure/el0_nsec.c index b3676c4..3ef4c69 100644 --- a/el0/nonsecure/el0_nsec.c +++ b/el0/nonsecure/el0_nsec.c @@ -2,6 +2,8 @@ #include "tztest.h" const char *sec_state_str = "non-secure"; +const uint32_t secure_state = NONSECURE; +const uint32_t exception_level = EL0; sys_control_t *syscntl = NULL; int main() diff --git a/el0/secure/el0.h b/el0/secure/el0.h deleted file mode 100644 index 492da6b..0000000 --- a/el0/secure/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/el0/secure/el0_sec.c b/el0/secure/el0_sec.c index 43f9e2f..eea62be 100644 --- a/el0/secure/el0_sec.c +++ b/el0/secure/el0_sec.c @@ -2,6 +2,8 @@ #include "tztest.h" const char *sec_state_str = "secure"; +const uint32_t secure_state = SECURE; +const uint32_t exception_level = EL0; sys_control_t *syscntl = NULL; void el0_sec_loop() diff --git a/el1/aarch64/el1_init.S b/el1/aarch64/el1_init.S index 7116a04..f24fe93 100644 --- a/el1/aarch64/el1_init.S +++ b/el1/aarch64/el1_init.S @@ -2,7 +2,6 @@ #include "memory.h" #include "vmsa.h" #include "el1.h" -#include "el0.h" #undef __ASSEMBLY__ .section .init diff --git a/el1/arm/el1_init.S b/el1/arm/el1_init.S index a1d3bd8..ba9bd2c 100644 --- a/el1/arm/el1_init.S +++ b/el1/arm/el1_init.S @@ -4,7 +4,6 @@ #include "cpu.h" #include "vmsa.h" #include "el1.h" -#include "el0.h" #undef __ASSEMBLY__ .arch_extension sec @@ -149,11 +149,11 @@ int el1_handle_svc(uint32_t op, svc_op_desc_t *desc) 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; + if (syscntl->excp_log || syscntl->el1_excp[secure_state].log) { + syscntl->el1_excp[secure_state].taken = true; + syscntl->el1_excp[secure_state].ec = ec; + syscntl->el1_excp[secure_state].iss = iss; + syscntl->el1_excp[secure_state].far = far; } switch (ec) { @@ -168,13 +168,13 @@ void el1_handle_exception(uintptr_t ec, uintptr_t iss, uintptr_t far, * behavior. */ #if AARCH32 - if (syscntl->el1_excp[SEC_STATE].action != EXCP_ACTION_SKIP && + if (syscntl->el1_excp[secure_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 || + if (syscntl->el1_excp[secure_state].action == EXCP_ACTION_SKIP || syscntl->excp_action == EXCP_ACTION_SKIP) { elr +=4; __set_exception_return(elr); @@ -202,7 +202,7 @@ void el1_handle_exception(uintptr_t ec, uintptr_t iss, uintptr_t far, 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 || + if (syscntl->el1_excp[secure_state].action == EXCP_ACTION_SKIP || syscntl->excp_action == EXCP_ACTION_SKIP) { elr +=4; __set_exception_return(elr); diff --git a/el1/el1_common.h b/el1/el1_common.h index cf4fa24..8c07336 100644 --- a/el1/el1_common.h +++ b/el1/el1_common.h @@ -8,6 +8,7 @@ #include "string.h" #include "el1.h" #include "arm_builtins.h" +#include "state.h" #include "debug.h" #include "syscntl.h" diff --git a/el1/nonsecure/Makefile b/el1/nonsecure/Makefile index 71e65d2..b7a3e20 100644 --- a/el1/nonsecure/Makefile +++ b/el1/nonsecure/Makefile @@ -18,7 +18,6 @@ FLATLIBS = ../../libcflat/libcflat.a $(libgcc) ../../libcflat/$(ARCH)/libeabi.a CFLAGS += -I$(ARCH) -I../$(ARCH) -I../ -I../$(ARCH) CFLAGS += -I../../common/$(ARCH) -I../../common/ -CFLAGS += -I../../el0/nonsecure/ ################################################################## diff --git a/el1/nonsecure/aarch64/el1.h b/el1/nonsecure/aarch64/el1.h index 3f84ec6..80e9937 100644 --- a/el1/nonsecure/aarch64/el1.h +++ b/el1/nonsecure/aarch64/el1.h @@ -37,7 +37,6 @@ extern uintptr_t EL1_NS_DATA_SIZE; #define EL1_BASE_VA EL1_NS_BASE_VA #define EL1_VA_HEAP_BASE EL1_NS_VA_HEAP_BASE -#define SEC_STATE_STR "non-secure" -#define SEC_STATE 1 +#define EL0_STACK_BASE EL0_NS_STACK_BASE #endif diff --git a/el1/nonsecure/arm/el1.h b/el1/nonsecure/arm/el1.h index eb4c30b..5a5ede2 100644 --- a/el1/nonsecure/arm/el1.h +++ b/el1/nonsecure/arm/el1.h @@ -40,7 +40,6 @@ extern uintptr_t EL1_NS_DATA_SIZE; #define EL1_BASE_VA EL1_NS_BASE_VA #define EL1_VA_HEAP_BASE EL1_NS_VA_HEAP_BASE -#define SEC_STATE_STR "non-secure" -#define SEC_STATE 1 +#define EL0_STACK_BASE EL0_NS_STACK_BASE #endif diff --git a/el1/nonsecure/el1_nsec.c b/el1/nonsecure/el1_nsec.c index cc2acae..33d40bf 100644 --- a/el1/nonsecure/el1_nsec.c +++ b/el1/nonsecure/el1_nsec.c @@ -10,6 +10,8 @@ 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"; +const uint32_t secure_state = NONSECURE; +const uint32_t exception_level = EL1; void el1_init_el0() { diff --git a/el1/secure/Makefile b/el1/secure/Makefile index 43876d7..a8057df 100644 --- a/el1/secure/Makefile +++ b/el1/secure/Makefile @@ -18,7 +18,6 @@ FLATLIBS = ../../libcflat/libcflat.a $(libgcc) ../../libcflat/$(ARCH)/libeabi.a CFLAGS += -I$(ARCH) -I../$(ARCH) -I../ -I../$(ARCH) CFLAGS += -I../../common/$(ARCH) -I../../common/ -CFLAGS += -I../../el0/secure/ ################################################################## diff --git a/el1/secure/aarch64/el1.h b/el1/secure/aarch64/el1.h index 99cc302..9037ea1 100644 --- a/el1/secure/aarch64/el1.h +++ b/el1/secure/aarch64/el1.h @@ -37,7 +37,6 @@ extern uintptr_t EL1_S_DATA_SIZE; #define EL1_BASE_VA EL1_S_BASE_VA #define EL1_VA_HEAP_BASE EL1_S_VA_HEAP_BASE -#define SEC_STATE_STR "secure" -#define SEC_STATE 0 +#define EL0_STACK_BASE EL0_S_STACK_BASE #endif diff --git a/el1/secure/arm/el1.h b/el1/secure/arm/el1.h index 42dc57a..df05e1f 100644 --- a/el1/secure/arm/el1.h +++ b/el1/secure/arm/el1.h @@ -40,7 +40,6 @@ extern uintptr_t EL1_S_DATA_SIZE; #define EL1_BASE_VA EL1_S_BASE_VA #define EL1_VA_HEAP_BASE EL1_S_VA_HEAP_BASE -#define SEC_STATE_STR "secure" -#define SEC_STATE 0 +#define EL0_STACK_BASE EL0_S_STACK_BASE #endif diff --git a/el1/secure/el1_sec.c b/el1/secure/el1_sec.c index 672a227..7f11670 100644 --- a/el1/secure/el1_sec.c +++ b/el1/secure/el1_sec.c @@ -10,6 +10,8 @@ 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"; +const uint32_t secure_state = SECURE; +const uint32_t exception_level = EL1; #if REMOVE_OR_INTEGRATE void el1_sec_check_init() @@ -14,8 +14,7 @@ #include "arm_builtins.h" #include "syscntl.h" #include "mem_util.h" - -#define SEC_STATE_STR "EL3" +#include "state.h" #include "debug.h" #if DEBUG @@ -32,6 +31,7 @@ const char *smc_op_name[] = { }; const char *sec_state_str = "EL3"; +const uint32_t exception_level = EL3; #endif uintptr_t EL3_TEXT_BASE = (uintptr_t)&_EL3_TEXT_BASE; diff --git a/tztest/tztest_el0.c b/tztest/tztest_el0.c index ce0c60a..c2e6f2f 100644 --- a/tztest/tztest_el0.c +++ b/tztest/tztest_el0.c @@ -3,12 +3,12 @@ #include "syscntl.h" #include "arm_builtins.h" #include "exception.h" -#include "el0.h" +#include "state.h" #include "debug.h" #include "tztest_internal.h" #include "tztest_el0.h" -uint32_t el0_check_smc(uint32_t el) +uint32_t el0_check_smc(uint32_t __attribute__((unused))arg) { TEST_HEAD("smc behavior"); @@ -18,7 +18,7 @@ uint32_t el0_check_smc(uint32_t el) return 0; } -uint32_t el0_check_register_access(uint32_t el) +uint32_t el0_check_register_access(uint32_t __attribute__((unused))arg) { /* Set things to non-secure P1 and attempt accesses */ TEST_HEAD("restricted register access"); @@ -58,7 +58,7 @@ uint32_t el0_check_register_access(uint32_t el) } #ifdef AARCH64 -uint32_t el0_check_cpacr_trap(uint32_t el) +uint32_t el0_check_cpacr_trap(uint32_t __attribute__((unused))arg) { uint64_t cptr_el3, cpacr; @@ -91,7 +91,7 @@ uint32_t el0_check_cpacr_trap(uint32_t el) return 0; } -uint32_t el0_check_wfx_trap(uint32_t el) +uint32_t el0_check_wfx_trap(uint32_t __attribute__((unused))arg) { uint64_t sctlr, scr; @@ -115,7 +115,7 @@ uint32_t el0_check_wfx_trap(uint32_t el) */ SVC_SET_REG(SCR, 3, scr | SCR_WFE); TEST_MSG("Execution of trapped WFE (SCTLR.nTWE clear)", - SEC_STATE_STR); + sec_state_str); TEST_EL3_EXCEPTION(asm volatile("wfe\n"), EC_WFI_WFE); /* Restore SCTLR */ @@ -123,7 +123,7 @@ uint32_t el0_check_wfx_trap(uint32_t el) /* This should trap to EL3 with SCTLR.nTWE set */ TEST_MSG("Execution of trapped WFE (SCTLR.nTWE set)", - SEC_STATE_STR); + sec_state_str); TEST_EL3_EXCEPTION(asm volatile("wfe\n"), EC_WFI_WFE); /* Restore SCR */ @@ -142,14 +142,14 @@ uint32_t el0_check_wfx_trap(uint32_t el) SVC_SET_REG(SCR, 3, scr | SCR_WFI); TEST_MSG("Execution of trapped WFI (SCTLR.nTWI clear)", - SEC_STATE_STR); + 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); + sec_state_str); TEST_EL3_EXCEPTION(asm volatile("wfi\n"), EC_WFI_WFE); /* Restore SCR */ diff --git a/tztest/tztest_internal.h b/tztest/tztest_internal.h index 5be8c78..cc21380 100644 --- a/tztest/tztest_internal.h +++ b/tztest/tztest_internal.h @@ -2,6 +2,7 @@ #define _TZTEST_INTERNAL_H #include "tztest.h" +#include "state.h" typedef enum { TZTEST_SMC = 0, @@ -12,10 +13,12 @@ typedef enum { } tztest_func_id_t; #define TEST_HEAD(_str, ...) \ - printf("\nValidating %s EL%d " _str ":\n", sec_state_str, el, ##__VA_ARGS__) + printf("\nValidating %s EL%d " _str ":\n", \ + sec_state_str, exception_level, ##__VA_ARGS__) #define TEST_MSG(_str, ...) \ - printf("\tEL%d (%s): " _str "... ", el, sec_state_str, ##__VA_ARGS__) + printf("\tEL%d (%s): " _str "... ", \ + exception_level, 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) @@ -51,7 +54,7 @@ typedef enum { } while (0) #define TEST_EL1_EXCEPTION(_fn, _excp) \ - TEST_EXCEPTION(_fn, _excp, el1_excp[SEC_STATE]) + TEST_EXCEPTION(_fn, _excp, el1_excp[secure_state]) #define TEST_EL3_EXCEPTION(_fn, _excp) \ TEST_EXCEPTION(_fn, _excp, el3_excp) |