1e33b78a6SSoby Mathew /* 2*4c700c15SGovindraj Raja * Copyright (c) 2016-2020, Arm Limited and Contributors. All rights reserved. 3e33b78a6SSoby Mathew * 482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause 5e33b78a6SSoby Mathew */ 6e33b78a6SSoby Mathew 7a0fee747SAntonio Nino Diaz #ifndef CONTEXT_H 8a0fee747SAntonio Nino Diaz #define CONTEXT_H 9a0fee747SAntonio Nino Diaz 1009d40e0eSAntonio Nino Diaz #include <lib/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 ******************************************************************************/ 16a0fee747SAntonio Nino Diaz #define CTX_REGS_OFFSET U(0x0) 17a0fee747SAntonio Nino Diaz #define CTX_GPREG_R0 U(0x0) 18a0fee747SAntonio Nino Diaz #define CTX_GPREG_R1 U(0x4) 19a0fee747SAntonio Nino Diaz #define CTX_GPREG_R2 U(0x8) 20a0fee747SAntonio Nino Diaz #define CTX_GPREG_R3 U(0xC) 21a0fee747SAntonio Nino Diaz #define CTX_LR U(0x10) 22a0fee747SAntonio Nino Diaz #define CTX_SCR U(0x14) 23a0fee747SAntonio Nino Diaz #define CTX_SPSR U(0x18) 24a0fee747SAntonio Nino Diaz #define CTX_NS_SCTLR U(0x1C) 25a0fee747SAntonio Nino Diaz #define CTX_REGS_END U(0x20) 26e33b78a6SSoby Mathew 27d5dfdeb6SJulius Werner #ifndef __ASSEMBLER__ 28e33b78a6SSoby Mathew 29e33b78a6SSoby Mathew #include <stdint.h> 30e33b78a6SSoby Mathew 3109d40e0eSAntonio Nino Diaz #include <lib/cassert.h> 3209d40e0eSAntonio Nino Diaz 33e33b78a6SSoby Mathew /* 34e33b78a6SSoby Mathew * Common constants to help define the 'cpu_context' structure and its 35e33b78a6SSoby Mathew * members below. 36e33b78a6SSoby Mathew */ 37a0fee747SAntonio Nino Diaz #define WORD_SHIFT U(2) 38e33b78a6SSoby Mathew #define DEFINE_REG_STRUCT(name, num_regs) \ 39e33b78a6SSoby Mathew typedef struct name { \ 402fe75a2dSZelalem uint32_t ctx_regs[num_regs]; \ 41e33b78a6SSoby Mathew } __aligned(8) name##_t 42e33b78a6SSoby Mathew 43e33b78a6SSoby Mathew /* Constants to determine the size of individual context structures */ 44e33b78a6SSoby Mathew #define CTX_REG_ALL (CTX_REGS_END >> WORD_SHIFT) 45e33b78a6SSoby Mathew 46e33b78a6SSoby Mathew DEFINE_REG_STRUCT(regs, CTX_REG_ALL); 47e33b78a6SSoby Mathew 48e33b78a6SSoby Mathew #undef CTX_REG_ALL 49e33b78a6SSoby Mathew 502fe75a2dSZelalem #define read_ctx_reg(ctx, offset) ((ctx)->ctx_regs[offset >> WORD_SHIFT]) 512fe75a2dSZelalem #define write_ctx_reg(ctx, offset, val) (((ctx)->ctx_regs[offset >> WORD_SHIFT]) \ 52e33b78a6SSoby Mathew = val) 53e33b78a6SSoby Mathew typedef struct cpu_context { 54e33b78a6SSoby Mathew regs_t regs_ctx; 55e33b78a6SSoby Mathew } cpu_context_t; 56e33b78a6SSoby Mathew 57e33b78a6SSoby Mathew /* Macros to access members of the 'cpu_context_t' structure */ 58e33b78a6SSoby Mathew #define get_regs_ctx(h) (&((cpu_context_t *) h)->regs_ctx) 59e33b78a6SSoby Mathew 60e33b78a6SSoby Mathew /* 61e33b78a6SSoby Mathew * Compile time assertions related to the 'cpu_context' structure to 62e33b78a6SSoby Mathew * ensure that the assembler and the compiler view of the offsets of 63e33b78a6SSoby Mathew * the structure members is the same. 64e33b78a6SSoby Mathew */ 659a90d720SElyes Haouas CASSERT(CTX_REGS_OFFSET == __builtin_offsetof(cpu_context_t, regs_ctx), 66e33b78a6SSoby Mathew assert_core_context_regs_offset_mismatch); 67e33b78a6SSoby Mathew 68d5dfdeb6SJulius Werner #endif /* __ASSEMBLER__ */ 69e33b78a6SSoby Mathew 70a0fee747SAntonio Nino Diaz #endif /* CONTEXT_H */ 71