blob: 1ea19ca7c53c3123fe3786d02e9b64af076eefb0 [file] [log] [blame]
Soby Mathew748be1d2016-05-05 14:10:46 +01001/*
Antonio Nino Diaz864ca6f2018-10-31 15:25:35 +00002 * Copyright (c) 2016-2018, ARM Limited and Contributors. All rights reserved.
Soby Mathew748be1d2016-05-05 14:10:46 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Soby Mathew748be1d2016-05-05 14:10:46 +01005 */
6
Antonio Nino Diaz864ca6f2018-10-31 15:25:35 +00007#ifndef CONTEXT_H
8#define CONTEXT_H
9
10#include <utils_def.h>
Soby Mathew748be1d2016-05-05 14:10:46 +010011
12/*******************************************************************************
13 * Constants that allow assembler code to access members of and the 'regs'
14 * structure at their correct offsets.
15 ******************************************************************************/
Antonio Nino Diaz864ca6f2018-10-31 15:25:35 +000016#define CTX_REGS_OFFSET U(0x0)
17#define CTX_GPREG_R0 U(0x0)
18#define CTX_GPREG_R1 U(0x4)
19#define CTX_GPREG_R2 U(0x8)
20#define CTX_GPREG_R3 U(0xC)
21#define CTX_LR U(0x10)
22#define CTX_SCR U(0x14)
23#define CTX_SPSR U(0x18)
24#define CTX_NS_SCTLR U(0x1C)
25#define CTX_REGS_END U(0x20)
Soby Mathew748be1d2016-05-05 14:10:46 +010026
27#ifndef __ASSEMBLY__
28
29#include <cassert.h>
30#include <stdint.h>
31
32/*
33 * Common constants to help define the 'cpu_context' structure and its
34 * members below.
35 */
Antonio Nino Diaz864ca6f2018-10-31 15:25:35 +000036#define WORD_SHIFT U(2)
Soby Mathew748be1d2016-05-05 14:10:46 +010037#define DEFINE_REG_STRUCT(name, num_regs) \
38 typedef struct name { \
39 uint32_t _regs[num_regs]; \
40 } __aligned(8) name##_t
41
42/* Constants to determine the size of individual context structures */
43#define CTX_REG_ALL (CTX_REGS_END >> WORD_SHIFT)
44
45DEFINE_REG_STRUCT(regs, CTX_REG_ALL);
46
47#undef CTX_REG_ALL
48
49#define read_ctx_reg(ctx, offset) ((ctx)->_regs[offset >> WORD_SHIFT])
50#define write_ctx_reg(ctx, offset, val) (((ctx)->_regs[offset >> WORD_SHIFT]) \
51 = val)
52typedef struct cpu_context {
53 regs_t regs_ctx;
54} cpu_context_t;
55
56/* Macros to access members of the 'cpu_context_t' structure */
57#define get_regs_ctx(h) (&((cpu_context_t *) h)->regs_ctx)
58
59/*
60 * Compile time assertions related to the 'cpu_context' structure to
61 * ensure that the assembler and the compiler view of the offsets of
62 * the structure members is the same.
63 */
64CASSERT(CTX_REGS_OFFSET == __builtin_offsetof(cpu_context_t, regs_ctx), \
65 assert_core_context_regs_offset_mismatch);
66
67#endif /* __ASSEMBLY__ */
68
Antonio Nino Diaz864ca6f2018-10-31 15:25:35 +000069#endif /* CONTEXT_H */