blob: 3c2fe4443339accd4f1044c8c753aa86d982cfb0 [file] [log] [blame]
Soby Mathewb911cc72017-02-13 12:46:28 +00001/*
2 * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
3 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Soby Mathewb911cc72017-02-13 12:46:28 +00005 */
6
7#ifndef __EP_INFO_H__
8#define __EP_INFO_H__
9
10#include <param_header.h>
Varun Wadekarc6a11f62017-05-25 18:04:48 -070011#include <utils_def.h>
Soby Mathewb911cc72017-02-13 12:46:28 +000012
Varun Wadekarc6a11f62017-05-25 18:04:48 -070013#define SECURE U(0x0)
14#define NON_SECURE U(0x1)
Soby Mathewb911cc72017-02-13 12:46:28 +000015#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 Wadekarc6a11f62017-05-25 18:04:48 -070021#define ENTRY_POINT_INFO_PC_OFFSET U(0x08)
Soby Mathewb911cc72017-02-13 12:46:28 +000022#ifdef AARCH32
Etienne Carriere094041d2018-02-02 13:16:18 +010023#define ENTRY_POINT_INFO_LR_SVC_OFFSET U(0x10)
24#define ENTRY_POINT_INFO_ARGS_OFFSET U(0x14)
Soby Mathewb911cc72017-02-13 12:46:28 +000025#else
Varun Wadekarc6a11f62017-05-25 18:04:48 -070026#define ENTRY_POINT_INFO_ARGS_OFFSET U(0x18)
Soby Mathewb911cc72017-02-13 12:46:28 +000027#endif
28
29/* The following are used to set/get image attributes. */
Varun Wadekarc6a11f62017-05-25 18:04:48 -070030#define PARAM_EP_SECURITY_MASK U(0x1)
Soby Mathewb911cc72017-02-13 12:46:28 +000031
32#define GET_SECURITY_STATE(x) (x & PARAM_EP_SECURITY_MASK)
33#define SET_SECURITY_STATE(x, security) \
34 ((x) = ((x) & ~PARAM_EP_SECURITY_MASK) | (security))
35
Varun Wadekarc6a11f62017-05-25 18:04:48 -070036#define EP_EE_MASK U(0x2)
David Cunadofee86532017-04-13 22:38:29 +010037#define EP_EE_SHIFT 1
Varun Wadekarc6a11f62017-05-25 18:04:48 -070038#define EP_EE_LITTLE U(0x0)
39#define EP_EE_BIG U(0x2)
Soby Mathewb911cc72017-02-13 12:46:28 +000040#define EP_GET_EE(x) (x & EP_EE_MASK)
41#define EP_SET_EE(x, ee) ((x) = ((x) & ~EP_EE_MASK) | (ee))
42
Varun Wadekarc6a11f62017-05-25 18:04:48 -070043#define EP_ST_MASK U(0x4)
44#define EP_ST_DISABLE U(0x0)
45#define EP_ST_ENABLE U(0x4)
Soby Mathewb911cc72017-02-13 12:46:28 +000046#define EP_GET_ST(x) (x & EP_ST_MASK)
47#define EP_SET_ST(x, ee) ((x) = ((x) & ~EP_ST_MASK) | (ee))
48
Varun Wadekarc6a11f62017-05-25 18:04:48 -070049#define EP_EXE_MASK U(0x8)
50#define NON_EXECUTABLE U(0x0)
51#define EXECUTABLE U(0x8)
Soby Mathewb911cc72017-02-13 12:46:28 +000052#define EP_GET_EXE(x) (x & EP_EXE_MASK)
53#define EP_SET_EXE(x, ee) ((x) = ((x) & ~EP_EXE_MASK) | (ee))
54
Varun Wadekarc6a11f62017-05-25 18:04:48 -070055#define EP_FIRST_EXE_MASK U(0x10)
56#define EP_FIRST_EXE U(0x10)
Soby Mathewb911cc72017-02-13 12:46:28 +000057#define EP_GET_FIRST_EXE(x) ((x) & EP_FIRST_EXE_MASK)
58#define EP_SET_FIRST_EXE(x, ee) ((x) = ((x) & ~EP_FIRST_EXE_MASK) | (ee))
59
60#ifndef __ASSEMBLY__
61
62#include <cassert.h>
63#include <types.h>
64
65typedef struct aapcs64_params {
66 u_register_t arg0;
67 u_register_t arg1;
68 u_register_t arg2;
69 u_register_t arg3;
70 u_register_t arg4;
71 u_register_t arg5;
72 u_register_t arg6;
73 u_register_t arg7;
74} aapcs64_params_t;
75
76typedef struct aapcs32_params {
77 u_register_t arg0;
78 u_register_t arg1;
79 u_register_t arg2;
80 u_register_t arg3;
81} aapcs32_params_t;
82
83/*****************************************************************************
84 * This structure represents the superset of information needed while
85 * switching exception levels. The only two mechanisms to do so are
86 * ERET & SMC. Security state is indicated using bit zero of header
87 * attribute
88 * NOTE: BL1 expects entrypoint followed by spsr at an offset from the start
89 * of this structure defined by the macro `ENTRY_POINT_INFO_PC_OFFSET` while
90 * processing SMC to jump to BL31.
91 *****************************************************************************/
92typedef struct entry_point_info {
93 param_header_t h;
94 uintptr_t pc;
95 uint32_t spsr;
96#ifdef AARCH32
Etienne Carriere094041d2018-02-02 13:16:18 +010097 uintptr_t lr_svc;
Soby Mathewb911cc72017-02-13 12:46:28 +000098 aapcs32_params_t args;
99#else
100 aapcs64_params_t args;
101#endif
102} entry_point_info_t;
103
104/*
105 * Compile time assertions related to the 'entry_point_info' structure to
106 * ensure that the assembler and the compiler view of the offsets of
107 * the structure members is the same.
108 */
109CASSERT(ENTRY_POINT_INFO_PC_OFFSET ==
110 __builtin_offsetof(entry_point_info_t, pc), \
111 assert_BL31_pc_offset_mismatch);
112
Etienne Carriere094041d2018-02-02 13:16:18 +0100113#ifdef AARCH32
114CASSERT(ENTRY_POINT_INFO_LR_SVC_OFFSET ==
115 __builtin_offsetof(entry_point_info_t, lr_svc),
116 assert_entrypoint_lr_offset_error);
117#endif
118
Soby Mathewb911cc72017-02-13 12:46:28 +0000119CASSERT(ENTRY_POINT_INFO_ARGS_OFFSET == \
120 __builtin_offsetof(entry_point_info_t, args), \
121 assert_BL31_args_offset_mismatch);
122
123CASSERT(sizeof(uintptr_t) ==
124 __builtin_offsetof(entry_point_info_t, spsr) - \
125 __builtin_offsetof(entry_point_info_t, pc), \
126 assert_entrypoint_and_spsr_should_be_adjacent);
127
128#endif /*__ASSEMBLY__*/
129
130#endif /* __EP_INFO_H__ */
131