ep_info.h 3.99 KB
Newer Older
1
/*
2
 * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
3
 *
dp-arm's avatar
dp-arm committed
4
 * SPDX-License-Identifier: BSD-3-Clause
5
6
 */

7
8
#ifndef EP_INFO_H
#define EP_INFO_H
9

10
11
#include <common/param_header.h>
#include <lib/utils_def.h>
12

13
14
#define SECURE		U(0x0)
#define NON_SECURE	U(0x1)
15
16
17
18
19
20
#define sec_state_is_valid(s) (((s) == SECURE) || ((s) == NON_SECURE))

/*******************************************************************************
 * Constants that allow assembler code to access members of and the
 * 'entry_point_info' structure at their correct offsets.
 ******************************************************************************/
21
#define ENTRY_POINT_INFO_PC_OFFSET	U(0x08)
22
#ifdef AARCH32
23
24
#define ENTRY_POINT_INFO_LR_SVC_OFFSET	U(0x10)
#define ENTRY_POINT_INFO_ARGS_OFFSET	U(0x14)
25
#else
26
#define ENTRY_POINT_INFO_ARGS_OFFSET	U(0x18)
27
28
29
#endif

/* The following are used to set/get image attributes. */
30
#define PARAM_EP_SECURITY_MASK		U(0x1)
31

32
/* Secure or Non-secure image */
33
#define GET_SECURITY_STATE(x) ((x) & PARAM_EP_SECURITY_MASK)
34
35
36
#define SET_SECURITY_STATE(x, security) \
			((x) = ((x) & ~PARAM_EP_SECURITY_MASK) | (security))

37
38
39
40
41
42
43
/* Endianness of the image. */
#define EP_EE_MASK		U(0x2)
#define EP_EE_SHIFT		U(1)
#define EP_EE_LITTLE		U(0x0)
#define EP_EE_BIG		U(0x2)
#define EP_GET_EE(x)		((x) & EP_EE_MASK)
#define EP_SET_EE(x, ee)	((x) = ((x) & ~EP_EE_MASK) | (ee))
44

45
46
47
48
49
50
/* Enable or disable access to the secure timer from secure images. */
#define EP_ST_MASK		U(0x4)
#define EP_ST_DISABLE		U(0x0)
#define EP_ST_ENABLE		U(0x4)
#define EP_GET_ST(x)		((x) & EP_ST_MASK)
#define EP_SET_ST(x, ee)	((x) = ((x) & ~EP_ST_MASK) | (ee))
51

52
53
54
55
56
57
/* Determine if an image is executable or not. */
#define EP_EXE_MASK		U(0x8)
#define NON_EXECUTABLE		U(0x0)
#define EXECUTABLE		U(0x8)
#define EP_GET_EXE(x)		((x) & EP_EXE_MASK)
#define EP_SET_EXE(x, ee)	((x) = ((x) & ~EP_EXE_MASK) | (ee))
58

59
/* Flag to indicate the first image that is executed. */
60
61
#define EP_FIRST_EXE_MASK	U(0x10)
#define EP_FIRST_EXE		U(0x10)
62
63
#define EP_GET_FIRST_EXE(x)	((x) & EP_FIRST_EXE_MASK)
#define EP_SET_FIRST_EXE(x, ee)	((x) = ((x) & ~EP_FIRST_EXE_MASK) | (ee))
64
65
66

#ifndef __ASSEMBLY__

67
#include <stdint.h>
68

69
70
#include <lib/cassert.h>

71
typedef struct aapcs64_params {
72
73
74
75
76
77
78
79
	uint64_t arg0;
	uint64_t arg1;
	uint64_t arg2;
	uint64_t arg3;
	uint64_t arg4;
	uint64_t arg5;
	uint64_t arg6;
	uint64_t arg7;
80
81
82
} aapcs64_params_t;

typedef struct aapcs32_params {
83
84
85
86
	uint32_t arg0;
	uint32_t arg1;
	uint32_t arg2;
	uint32_t arg3;
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
} aapcs32_params_t;

/*****************************************************************************
 * This structure represents the superset of information needed while
 * switching exception levels. The only two mechanisms to do so are
 * ERET & SMC. Security state is indicated using bit zero of header
 * attribute
 * NOTE: BL1 expects entrypoint followed by spsr at an offset from the start
 * of this structure defined by the macro `ENTRY_POINT_INFO_PC_OFFSET` while
 * processing SMC to jump to BL31.
 *****************************************************************************/
typedef struct entry_point_info {
	param_header_t h;
	uintptr_t pc;
	uint32_t spsr;
#ifdef AARCH32
103
	uintptr_t lr_svc;
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
	aapcs32_params_t args;
#else
	aapcs64_params_t args;
#endif
} entry_point_info_t;

/*
 * Compile time assertions related to the 'entry_point_info' structure to
 * ensure that the assembler and the compiler view of the offsets of
 * the structure members is the same.
 */
CASSERT(ENTRY_POINT_INFO_PC_OFFSET ==
		__builtin_offsetof(entry_point_info_t, pc), \
		assert_BL31_pc_offset_mismatch);

119
120
121
122
123
124
#ifdef AARCH32
CASSERT(ENTRY_POINT_INFO_LR_SVC_OFFSET ==
		__builtin_offsetof(entry_point_info_t, lr_svc),
		assert_entrypoint_lr_offset_error);
#endif

125
126
127
128
129
130
131
132
133
134
135
CASSERT(ENTRY_POINT_INFO_ARGS_OFFSET == \
		__builtin_offsetof(entry_point_info_t, args), \
		assert_BL31_args_offset_mismatch);

CASSERT(sizeof(uintptr_t) ==
		__builtin_offsetof(entry_point_info_t, spsr) - \
		__builtin_offsetof(entry_point_info_t, pc), \
		assert_entrypoint_and_spsr_should_be_adjacent);

#endif /*__ASSEMBLY__*/

136
#endif /* EP_INFO_H */