context.h 1.93 KB
Newer Older
1
/*
Zelalem's avatar
Zelalem committed
2
 * Copyright (c) 2016-2020, 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
9
#ifndef CONTEXT_H
#define CONTEXT_H

10
#include <lib/utils_def.h>
11
12
13
14
15

/*******************************************************************************
 * Constants that allow assembler code to access members of and the 'regs'
 * structure at their correct offsets.
 ******************************************************************************/
16
17
18
19
20
21
22
23
24
25
#define CTX_REGS_OFFSET		U(0x0)
#define CTX_GPREG_R0		U(0x0)
#define CTX_GPREG_R1		U(0x4)
#define CTX_GPREG_R2		U(0x8)
#define CTX_GPREG_R3		U(0xC)
#define CTX_LR			U(0x10)
#define CTX_SCR			U(0x14)
#define CTX_SPSR		U(0x18)
#define CTX_NS_SCTLR		U(0x1C)
#define CTX_REGS_END		U(0x20)
26

27
#ifndef __ASSEMBLER__
28
29
30

#include <stdint.h>

31
32
#include <lib/cassert.h>

33
34
35
36
/*
 * Common constants to help define the 'cpu_context' structure and its
 * members below.
 */
37
#define WORD_SHIFT		U(2)
38
39
#define DEFINE_REG_STRUCT(name, num_regs)	\
	typedef struct name {			\
Zelalem's avatar
Zelalem committed
40
		uint32_t ctx_regs[num_regs];	\
41
42
43
44
45
46
47
48
49
	}  __aligned(8) name##_t

/* Constants to determine the size of individual context structures */
#define CTX_REG_ALL		(CTX_REGS_END >> WORD_SHIFT)

DEFINE_REG_STRUCT(regs, CTX_REG_ALL);

#undef CTX_REG_ALL

Zelalem's avatar
Zelalem committed
50
51
#define read_ctx_reg(ctx, offset)	((ctx)->ctx_regs[offset >> WORD_SHIFT])
#define write_ctx_reg(ctx, offset, val)	(((ctx)->ctx_regs[offset >> WORD_SHIFT]) \
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
					 = val)
typedef struct cpu_context {
	regs_t regs_ctx;
} cpu_context_t;

/* Macros to access members of the 'cpu_context_t' structure */
#define get_regs_ctx(h)		(&((cpu_context_t *) h)->regs_ctx)

/*
 * Compile time assertions related to the 'cpu_context' structure to
 * ensure that the assembler and the compiler view of the offsets of
 * the structure members is the same.
 */
CASSERT(CTX_REGS_OFFSET == __builtin_offsetof(cpu_context_t, regs_ctx), \
	assert_core_context_regs_offset_mismatch);

68
#endif /* __ASSEMBLER__ */
69

70
#endif /* CONTEXT_H */