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