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