xref: /rk3399_ARM-atf/include/lib/el3_runtime/aarch32/context.h (revision 82cb2c1ad9897473743f08437d0a3995bed561b9)
1e33b78a6SSoby Mathew /*
2e33b78a6SSoby Mathew  * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
3e33b78a6SSoby Mathew  *
4*82cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
5e33b78a6SSoby Mathew  */
6e33b78a6SSoby Mathew 
7e33b78a6SSoby Mathew #ifndef __CONTEXT_H__
8e33b78a6SSoby Mathew #define __CONTEXT_H__
9e33b78a6SSoby Mathew 
10e33b78a6SSoby Mathew /*******************************************************************************
11e33b78a6SSoby Mathew  * Constants that allow assembler code to access members of and the 'regs'
12e33b78a6SSoby Mathew  * structure at their correct offsets.
13e33b78a6SSoby Mathew  ******************************************************************************/
14e33b78a6SSoby Mathew #define CTX_REGS_OFFSET		0x0
15e33b78a6SSoby Mathew #define CTX_GPREG_R0		0x0
16e33b78a6SSoby Mathew #define CTX_GPREG_R1		0x4
17e33b78a6SSoby Mathew #define CTX_GPREG_R2		0x8
18e33b78a6SSoby Mathew #define CTX_GPREG_R3		0xC
19e33b78a6SSoby Mathew #define CTX_LR			0x10
20e33b78a6SSoby Mathew #define CTX_SCR			0x14
21e33b78a6SSoby Mathew #define CTX_SPSR		0x18
22e33b78a6SSoby Mathew #define CTX_NS_SCTLR		0x1C
23e33b78a6SSoby Mathew #define CTX_REGS_END		0x20
24e33b78a6SSoby Mathew 
25e33b78a6SSoby Mathew #ifndef __ASSEMBLY__
26e33b78a6SSoby Mathew 
27e33b78a6SSoby Mathew #include <cassert.h>
28e33b78a6SSoby Mathew #include <stdint.h>
29e33b78a6SSoby Mathew 
30e33b78a6SSoby Mathew /*
31e33b78a6SSoby Mathew  * Common constants to help define the 'cpu_context' structure and its
32e33b78a6SSoby Mathew  * members below.
33e33b78a6SSoby Mathew  */
34e33b78a6SSoby Mathew #define WORD_SHIFT		2
35e33b78a6SSoby Mathew #define DEFINE_REG_STRUCT(name, num_regs)	\
36e33b78a6SSoby Mathew 	typedef struct name {			\
37e33b78a6SSoby Mathew 		uint32_t _regs[num_regs];	\
38e33b78a6SSoby Mathew 	}  __aligned(8) name##_t
39e33b78a6SSoby Mathew 
40e33b78a6SSoby Mathew /* Constants to determine the size of individual context structures */
41e33b78a6SSoby Mathew #define CTX_REG_ALL		(CTX_REGS_END >> WORD_SHIFT)
42e33b78a6SSoby Mathew 
43e33b78a6SSoby Mathew DEFINE_REG_STRUCT(regs, CTX_REG_ALL);
44e33b78a6SSoby Mathew 
45e33b78a6SSoby Mathew #undef CTX_REG_ALL
46e33b78a6SSoby Mathew 
47e33b78a6SSoby Mathew #define read_ctx_reg(ctx, offset)	((ctx)->_regs[offset >> WORD_SHIFT])
48e33b78a6SSoby Mathew #define write_ctx_reg(ctx, offset, val)	(((ctx)->_regs[offset >> WORD_SHIFT]) \
49e33b78a6SSoby Mathew 					 = val)
50e33b78a6SSoby Mathew typedef struct cpu_context {
51e33b78a6SSoby Mathew 	regs_t regs_ctx;
52e33b78a6SSoby Mathew } cpu_context_t;
53e33b78a6SSoby Mathew 
54e33b78a6SSoby Mathew /* Macros to access members of the 'cpu_context_t' structure */
55e33b78a6SSoby Mathew #define get_regs_ctx(h)		(&((cpu_context_t *) h)->regs_ctx)
56e33b78a6SSoby Mathew 
57e33b78a6SSoby Mathew /*
58e33b78a6SSoby Mathew  * Compile time assertions related to the 'cpu_context' structure to
59e33b78a6SSoby Mathew  * ensure that the assembler and the compiler view of the offsets of
60e33b78a6SSoby Mathew  * the structure members is the same.
61e33b78a6SSoby Mathew  */
62e33b78a6SSoby Mathew CASSERT(CTX_REGS_OFFSET == __builtin_offsetof(cpu_context_t, regs_ctx), \
63e33b78a6SSoby Mathew 	assert_core_context_regs_offset_mismatch);
64e33b78a6SSoby Mathew 
65e33b78a6SSoby Mathew #endif /* __ASSEMBLY__ */
66e33b78a6SSoby Mathew 
67e33b78a6SSoby Mathew #endif /* __CONTEXT_H__ */
68