Soby Mathew | 748be1d | 2016-05-05 14:10:46 +0100 | [diff] [blame] | 1 | /* |
Zelalem | 91d8061 | 2020-02-12 10:37:03 -0600 | [diff] [blame] | 2 | * Copyright (c) 2016-2020, ARM Limited and Contributors. All rights reserved. |
Soby Mathew | 748be1d | 2016-05-05 14:10:46 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Soby Mathew | 748be1d | 2016-05-05 14:10:46 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
Antonio Nino Diaz | 864ca6f | 2018-10-31 15:25:35 +0000 | [diff] [blame] | 7 | #ifndef CONTEXT_H |
| 8 | #define CONTEXT_H |
| 9 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 10 | #include <lib/utils_def.h> |
Soby Mathew | 748be1d | 2016-05-05 14:10:46 +0100 | [diff] [blame] | 11 | |
| 12 | /******************************************************************************* |
| 13 | * Constants that allow assembler code to access members of and the 'regs' |
| 14 | * structure at their correct offsets. |
| 15 | ******************************************************************************/ |
Antonio Nino Diaz | 864ca6f | 2018-10-31 15:25:35 +0000 | [diff] [blame] | 16 | #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 Mathew | 748be1d | 2016-05-05 14:10:46 +0100 | [diff] [blame] | 26 | |
Julius Werner | 53456fc | 2019-07-09 13:49:11 -0700 | [diff] [blame] | 27 | #ifndef __ASSEMBLER__ |
Soby Mathew | 748be1d | 2016-05-05 14:10:46 +0100 | [diff] [blame] | 28 | |
Soby Mathew | 748be1d | 2016-05-05 14:10:46 +0100 | [diff] [blame] | 29 | #include <stdint.h> |
| 30 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 31 | #include <lib/cassert.h> |
| 32 | |
Soby Mathew | 748be1d | 2016-05-05 14:10:46 +0100 | [diff] [blame] | 33 | /* |
| 34 | * Common constants to help define the 'cpu_context' structure and its |
| 35 | * members below. |
| 36 | */ |
Antonio Nino Diaz | 864ca6f | 2018-10-31 15:25:35 +0000 | [diff] [blame] | 37 | #define WORD_SHIFT U(2) |
Soby Mathew | 748be1d | 2016-05-05 14:10:46 +0100 | [diff] [blame] | 38 | #define DEFINE_REG_STRUCT(name, num_regs) \ |
| 39 | typedef struct name { \ |
Zelalem | 91d8061 | 2020-02-12 10:37:03 -0600 | [diff] [blame] | 40 | uint32_t ctx_regs[num_regs]; \ |
Soby Mathew | 748be1d | 2016-05-05 14:10:46 +0100 | [diff] [blame] | 41 | } __aligned(8) name##_t |
| 42 | |
| 43 | /* Constants to determine the size of individual context structures */ |
| 44 | #define CTX_REG_ALL (CTX_REGS_END >> WORD_SHIFT) |
| 45 | |
| 46 | DEFINE_REG_STRUCT(regs, CTX_REG_ALL); |
| 47 | |
| 48 | #undef CTX_REG_ALL |
| 49 | |
Zelalem | 91d8061 | 2020-02-12 10:37:03 -0600 | [diff] [blame] | 50 | #define read_ctx_reg(ctx, offset) ((ctx)->ctx_regs[offset >> WORD_SHIFT]) |
| 51 | #define write_ctx_reg(ctx, offset, val) (((ctx)->ctx_regs[offset >> WORD_SHIFT]) \ |
Soby Mathew | 748be1d | 2016-05-05 14:10:46 +0100 | [diff] [blame] | 52 | = val) |
| 53 | typedef struct cpu_context { |
| 54 | regs_t regs_ctx; |
| 55 | } cpu_context_t; |
| 56 | |
| 57 | /* Macros to access members of the 'cpu_context_t' structure */ |
| 58 | #define get_regs_ctx(h) (&((cpu_context_t *) h)->regs_ctx) |
| 59 | |
| 60 | /* |
| 61 | * Compile time assertions related to the 'cpu_context' structure to |
| 62 | * ensure that the assembler and the compiler view of the offsets of |
| 63 | * the structure members is the same. |
| 64 | */ |
Elyes Haouas | 183638f | 2023-02-13 10:05:41 +0100 | [diff] [blame] | 65 | CASSERT(CTX_REGS_OFFSET == __builtin_offsetof(cpu_context_t, regs_ctx), |
Soby Mathew | 748be1d | 2016-05-05 14:10:46 +0100 | [diff] [blame] | 66 | assert_core_context_regs_offset_mismatch); |
| 67 | |
Julius Werner | 53456fc | 2019-07-09 13:49:11 -0700 | [diff] [blame] | 68 | #endif /* __ASSEMBLER__ */ |
Soby Mathew | 748be1d | 2016-05-05 14:10:46 +0100 | [diff] [blame] | 69 | |
Antonio Nino Diaz | 864ca6f | 2018-10-31 15:25:35 +0000 | [diff] [blame] | 70 | #endif /* CONTEXT_H */ |