Soby Mathew | b911cc7 | 2017-02-13 12:46:28 +0000 | [diff] [blame] | 1 | /* |
Antonio Nino Diaz | 4b32e62 | 2018-08-16 16:52:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved. |
Soby Mathew | b911cc7 | 2017-02-13 12:46:28 +0000 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Soby Mathew | b911cc7 | 2017-02-13 12:46:28 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef __EP_INFO_H__ |
| 8 | #define __EP_INFO_H__ |
| 9 | |
| 10 | #include <param_header.h> |
Varun Wadekar | c6a11f6 | 2017-05-25 18:04:48 -0700 | [diff] [blame] | 11 | #include <utils_def.h> |
Soby Mathew | b911cc7 | 2017-02-13 12:46:28 +0000 | [diff] [blame] | 12 | |
Varun Wadekar | c6a11f6 | 2017-05-25 18:04:48 -0700 | [diff] [blame] | 13 | #define SECURE U(0x0) |
| 14 | #define NON_SECURE U(0x1) |
Soby Mathew | b911cc7 | 2017-02-13 12:46:28 +0000 | [diff] [blame] | 15 | #define sec_state_is_valid(s) (((s) == SECURE) || ((s) == NON_SECURE)) |
| 16 | |
| 17 | /******************************************************************************* |
| 18 | * Constants that allow assembler code to access members of and the |
| 19 | * 'entry_point_info' structure at their correct offsets. |
| 20 | ******************************************************************************/ |
Varun Wadekar | c6a11f6 | 2017-05-25 18:04:48 -0700 | [diff] [blame] | 21 | #define ENTRY_POINT_INFO_PC_OFFSET U(0x08) |
Soby Mathew | b911cc7 | 2017-02-13 12:46:28 +0000 | [diff] [blame] | 22 | #ifdef AARCH32 |
Etienne Carriere | 094041d | 2018-02-02 13:16:18 +0100 | [diff] [blame] | 23 | #define ENTRY_POINT_INFO_LR_SVC_OFFSET U(0x10) |
| 24 | #define ENTRY_POINT_INFO_ARGS_OFFSET U(0x14) |
Soby Mathew | b911cc7 | 2017-02-13 12:46:28 +0000 | [diff] [blame] | 25 | #else |
Varun Wadekar | c6a11f6 | 2017-05-25 18:04:48 -0700 | [diff] [blame] | 26 | #define ENTRY_POINT_INFO_ARGS_OFFSET U(0x18) |
Soby Mathew | b911cc7 | 2017-02-13 12:46:28 +0000 | [diff] [blame] | 27 | #endif |
| 28 | |
| 29 | /* The following are used to set/get image attributes. */ |
Varun Wadekar | c6a11f6 | 2017-05-25 18:04:48 -0700 | [diff] [blame] | 30 | #define PARAM_EP_SECURITY_MASK U(0x1) |
Soby Mathew | b911cc7 | 2017-02-13 12:46:28 +0000 | [diff] [blame] | 31 | |
Antonio Nino Diaz | 5f658c3 | 2018-06-26 21:42:51 +0100 | [diff] [blame] | 32 | /* Secure or Non-secure image */ |
Soby Mathew | b911cc7 | 2017-02-13 12:46:28 +0000 | [diff] [blame] | 33 | #define GET_SECURITY_STATE(x) (x & PARAM_EP_SECURITY_MASK) |
| 34 | #define SET_SECURITY_STATE(x, security) \ |
| 35 | ((x) = ((x) & ~PARAM_EP_SECURITY_MASK) | (security)) |
| 36 | |
Antonio Nino Diaz | 5f658c3 | 2018-06-26 21:42:51 +0100 | [diff] [blame] | 37 | /* Endianness of the image. */ |
| 38 | #define EP_EE_MASK U(0x2) |
| 39 | #define EP_EE_SHIFT U(1) |
| 40 | #define EP_EE_LITTLE U(0x0) |
| 41 | #define EP_EE_BIG U(0x2) |
| 42 | #define EP_GET_EE(x) ((x) & EP_EE_MASK) |
| 43 | #define EP_SET_EE(x, ee) ((x) = ((x) & ~EP_EE_MASK) | (ee)) |
Soby Mathew | b911cc7 | 2017-02-13 12:46:28 +0000 | [diff] [blame] | 44 | |
Antonio Nino Diaz | 5f658c3 | 2018-06-26 21:42:51 +0100 | [diff] [blame] | 45 | /* Enable or disable access to the secure timer from secure images. */ |
| 46 | #define EP_ST_MASK U(0x4) |
| 47 | #define EP_ST_DISABLE U(0x0) |
| 48 | #define EP_ST_ENABLE U(0x4) |
| 49 | #define EP_GET_ST(x) ((x) & EP_ST_MASK) |
| 50 | #define EP_SET_ST(x, ee) ((x) = ((x) & ~EP_ST_MASK) | (ee)) |
Soby Mathew | b911cc7 | 2017-02-13 12:46:28 +0000 | [diff] [blame] | 51 | |
Antonio Nino Diaz | 5f658c3 | 2018-06-26 21:42:51 +0100 | [diff] [blame] | 52 | /* Determine if an image is executable or not. */ |
| 53 | #define EP_EXE_MASK U(0x8) |
| 54 | #define NON_EXECUTABLE U(0x0) |
| 55 | #define EXECUTABLE U(0x8) |
| 56 | #define EP_GET_EXE(x) ((x) & EP_EXE_MASK) |
| 57 | #define EP_SET_EXE(x, ee) ((x) = ((x) & ~EP_EXE_MASK) | (ee)) |
Soby Mathew | b911cc7 | 2017-02-13 12:46:28 +0000 | [diff] [blame] | 58 | |
Antonio Nino Diaz | 5f658c3 | 2018-06-26 21:42:51 +0100 | [diff] [blame] | 59 | /* Flag to indicate the first image that is executed. */ |
Varun Wadekar | c6a11f6 | 2017-05-25 18:04:48 -0700 | [diff] [blame] | 60 | #define EP_FIRST_EXE_MASK U(0x10) |
| 61 | #define EP_FIRST_EXE U(0x10) |
Antonio Nino Diaz | 5f658c3 | 2018-06-26 21:42:51 +0100 | [diff] [blame] | 62 | #define EP_GET_FIRST_EXE(x) ((x) & EP_FIRST_EXE_MASK) |
| 63 | #define EP_SET_FIRST_EXE(x, ee) ((x) = ((x) & ~EP_FIRST_EXE_MASK) | (ee)) |
Soby Mathew | b911cc7 | 2017-02-13 12:46:28 +0000 | [diff] [blame] | 64 | |
| 65 | #ifndef __ASSEMBLY__ |
| 66 | |
| 67 | #include <cassert.h> |
Antonio Nino Diaz | 4b32e62 | 2018-08-16 16:52:57 +0100 | [diff] [blame] | 68 | #include <stdint.h> |
Soby Mathew | b911cc7 | 2017-02-13 12:46:28 +0000 | [diff] [blame] | 69 | |
| 70 | typedef struct aapcs64_params { |
| 71 | u_register_t arg0; |
| 72 | u_register_t arg1; |
| 73 | u_register_t arg2; |
| 74 | u_register_t arg3; |
| 75 | u_register_t arg4; |
| 76 | u_register_t arg5; |
| 77 | u_register_t arg6; |
| 78 | u_register_t arg7; |
| 79 | } aapcs64_params_t; |
| 80 | |
| 81 | typedef struct aapcs32_params { |
| 82 | u_register_t arg0; |
| 83 | u_register_t arg1; |
| 84 | u_register_t arg2; |
| 85 | u_register_t arg3; |
| 86 | } aapcs32_params_t; |
| 87 | |
| 88 | /***************************************************************************** |
| 89 | * This structure represents the superset of information needed while |
| 90 | * switching exception levels. The only two mechanisms to do so are |
| 91 | * ERET & SMC. Security state is indicated using bit zero of header |
| 92 | * attribute |
| 93 | * NOTE: BL1 expects entrypoint followed by spsr at an offset from the start |
| 94 | * of this structure defined by the macro `ENTRY_POINT_INFO_PC_OFFSET` while |
| 95 | * processing SMC to jump to BL31. |
| 96 | *****************************************************************************/ |
| 97 | typedef struct entry_point_info { |
| 98 | param_header_t h; |
| 99 | uintptr_t pc; |
| 100 | uint32_t spsr; |
| 101 | #ifdef AARCH32 |
Etienne Carriere | 094041d | 2018-02-02 13:16:18 +0100 | [diff] [blame] | 102 | uintptr_t lr_svc; |
Soby Mathew | b911cc7 | 2017-02-13 12:46:28 +0000 | [diff] [blame] | 103 | aapcs32_params_t args; |
| 104 | #else |
| 105 | aapcs64_params_t args; |
| 106 | #endif |
| 107 | } entry_point_info_t; |
| 108 | |
| 109 | /* |
| 110 | * Compile time assertions related to the 'entry_point_info' structure to |
| 111 | * ensure that the assembler and the compiler view of the offsets of |
| 112 | * the structure members is the same. |
| 113 | */ |
| 114 | CASSERT(ENTRY_POINT_INFO_PC_OFFSET == |
| 115 | __builtin_offsetof(entry_point_info_t, pc), \ |
| 116 | assert_BL31_pc_offset_mismatch); |
| 117 | |
Etienne Carriere | 094041d | 2018-02-02 13:16:18 +0100 | [diff] [blame] | 118 | #ifdef AARCH32 |
| 119 | CASSERT(ENTRY_POINT_INFO_LR_SVC_OFFSET == |
| 120 | __builtin_offsetof(entry_point_info_t, lr_svc), |
| 121 | assert_entrypoint_lr_offset_error); |
| 122 | #endif |
| 123 | |
Soby Mathew | b911cc7 | 2017-02-13 12:46:28 +0000 | [diff] [blame] | 124 | CASSERT(ENTRY_POINT_INFO_ARGS_OFFSET == \ |
| 125 | __builtin_offsetof(entry_point_info_t, args), \ |
| 126 | assert_BL31_args_offset_mismatch); |
| 127 | |
| 128 | CASSERT(sizeof(uintptr_t) == |
| 129 | __builtin_offsetof(entry_point_info_t, spsr) - \ |
| 130 | __builtin_offsetof(entry_point_info_t, pc), \ |
| 131 | assert_entrypoint_and_spsr_should_be_adjacent); |
| 132 | |
| 133 | #endif /*__ASSEMBLY__*/ |
| 134 | |
| 135 | #endif /* __EP_INFO_H__ */ |
| 136 | |