1532ed618SSoby Mathew /* 28c56a788SJayanth Dodderi Chidanand * Copyright (c) 2013-2024, Arm Limited and Contributors. All rights reserved. 3532ed618SSoby Mathew * 482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause 5532ed618SSoby Mathew */ 6532ed618SSoby Mathew 7a0fee747SAntonio Nino Diaz #ifndef CONTEXT_H 8a0fee747SAntonio Nino Diaz #define CONTEXT_H 9532ed618SSoby Mathew 1042e35d2fSJayanth Dodderi Chidanand #include <lib/el3_runtime/context_el1.h> 11d6af2344SJayanth Dodderi Chidanand #include <lib/el3_runtime/context_el2.h> 12461c0a5dSElizabeth Ho #include <lib/el3_runtime/cpu_data.h> 13308ebfa1SMadhukar Pappireddy #include <lib/el3_runtime/simd_ctx.h> 1409d40e0eSAntonio Nino Diaz #include <lib/utils_def.h> 1576454abfSJeenu Viswambharan 16532ed618SSoby Mathew /******************************************************************************* 17532ed618SSoby Mathew * Constants that allow assembler code to access members of and the 'gp_regs' 18532ed618SSoby Mathew * structure at their correct offsets. 19532ed618SSoby Mathew ******************************************************************************/ 20030567e6SVarun Wadekar #define CTX_GPREGS_OFFSET U(0x0) 21030567e6SVarun Wadekar #define CTX_GPREG_X0 U(0x0) 22030567e6SVarun Wadekar #define CTX_GPREG_X1 U(0x8) 23030567e6SVarun Wadekar #define CTX_GPREG_X2 U(0x10) 24030567e6SVarun Wadekar #define CTX_GPREG_X3 U(0x18) 25030567e6SVarun Wadekar #define CTX_GPREG_X4 U(0x20) 26030567e6SVarun Wadekar #define CTX_GPREG_X5 U(0x28) 27030567e6SVarun Wadekar #define CTX_GPREG_X6 U(0x30) 28030567e6SVarun Wadekar #define CTX_GPREG_X7 U(0x38) 29030567e6SVarun Wadekar #define CTX_GPREG_X8 U(0x40) 30030567e6SVarun Wadekar #define CTX_GPREG_X9 U(0x48) 31030567e6SVarun Wadekar #define CTX_GPREG_X10 U(0x50) 32030567e6SVarun Wadekar #define CTX_GPREG_X11 U(0x58) 33030567e6SVarun Wadekar #define CTX_GPREG_X12 U(0x60) 34030567e6SVarun Wadekar #define CTX_GPREG_X13 U(0x68) 35030567e6SVarun Wadekar #define CTX_GPREG_X14 U(0x70) 36030567e6SVarun Wadekar #define CTX_GPREG_X15 U(0x78) 37030567e6SVarun Wadekar #define CTX_GPREG_X16 U(0x80) 38030567e6SVarun Wadekar #define CTX_GPREG_X17 U(0x88) 39030567e6SVarun Wadekar #define CTX_GPREG_X18 U(0x90) 40030567e6SVarun Wadekar #define CTX_GPREG_X19 U(0x98) 41030567e6SVarun Wadekar #define CTX_GPREG_X20 U(0xa0) 42030567e6SVarun Wadekar #define CTX_GPREG_X21 U(0xa8) 43030567e6SVarun Wadekar #define CTX_GPREG_X22 U(0xb0) 44030567e6SVarun Wadekar #define CTX_GPREG_X23 U(0xb8) 45030567e6SVarun Wadekar #define CTX_GPREG_X24 U(0xc0) 46030567e6SVarun Wadekar #define CTX_GPREG_X25 U(0xc8) 47030567e6SVarun Wadekar #define CTX_GPREG_X26 U(0xd0) 48030567e6SVarun Wadekar #define CTX_GPREG_X27 U(0xd8) 49030567e6SVarun Wadekar #define CTX_GPREG_X28 U(0xe0) 50030567e6SVarun Wadekar #define CTX_GPREG_X29 U(0xe8) 51030567e6SVarun Wadekar #define CTX_GPREG_LR U(0xf0) 52030567e6SVarun Wadekar #define CTX_GPREG_SP_EL0 U(0xf8) 53030567e6SVarun Wadekar #define CTX_GPREGS_END U(0x100) 54532ed618SSoby Mathew 55532ed618SSoby Mathew /******************************************************************************* 56532ed618SSoby Mathew * Constants that allow assembler code to access members of and the 'el3_state' 57532ed618SSoby Mathew * structure at their correct offsets. Note that some of the registers are only 58532ed618SSoby Mathew * 32-bits wide but are stored as 64-bit values for convenience 59532ed618SSoby Mathew ******************************************************************************/ 60d9bd656cSDimitris Papastamos #define CTX_EL3STATE_OFFSET (CTX_GPREGS_OFFSET + CTX_GPREGS_END) 61030567e6SVarun Wadekar #define CTX_SCR_EL3 U(0x0) 6276454abfSJeenu Viswambharan #define CTX_ESR_EL3 U(0x8) 6376454abfSJeenu Viswambharan #define CTX_RUNTIME_SP U(0x10) 6476454abfSJeenu Viswambharan #define CTX_SPSR_EL3 U(0x18) 6576454abfSJeenu Viswambharan #define CTX_ELR_EL3 U(0x20) 66e290a8fcSAlexei Fedorov #define CTX_PMCR_EL0 U(0x28) 67c2d32a5fSMadhukar Pappireddy #define CTX_IS_IN_EL3 U(0x30) 68123002f9SJayanth Dodderi Chidanand #define CTX_MDCR_EL3 U(0x38) 69d04c04a4SManish Pandey /* Constants required in supporting nested exception in EL3 */ 70123002f9SJayanth Dodderi Chidanand #define CTX_SAVED_ELR_EL3 U(0x40) 71d04c04a4SManish Pandey /* 72d04c04a4SManish Pandey * General purpose flag, to save various EL3 states 73d04c04a4SManish Pandey * FFH mode : Used to identify if handling nested exception 74d04c04a4SManish Pandey * KFH mode : Used as counter value 75d04c04a4SManish Pandey */ 76123002f9SJayanth Dodderi Chidanand #define CTX_NESTED_EA_FLAG U(0x48) 77f87e54f7SManish Pandey #if FFH_SUPPORT 78123002f9SJayanth Dodderi Chidanand #define CTX_SAVED_ESR_EL3 U(0x50) 79123002f9SJayanth Dodderi Chidanand #define CTX_SAVED_SPSR_EL3 U(0x58) 80123002f9SJayanth Dodderi Chidanand #define CTX_SAVED_GPREG_LR U(0x60) 81123002f9SJayanth Dodderi Chidanand #define CTX_EL3STATE_END U(0x70) /* Align to the next 16 byte boundary */ 82d04c04a4SManish Pandey #else 83d04c04a4SManish Pandey #define CTX_EL3STATE_END U(0x50) /* Align to the next 16 byte boundary */ 84ac4f6aafSArvind Ram Prakash #endif /* FFH_SUPPORT */ 85532ed618SSoby Mathew 86532ed618SSoby Mathew 874d1ccf0eSAntonio Nino Diaz /******************************************************************************* 884d1ccf0eSAntonio Nino Diaz * Registers related to CVE-2018-3639 894d1ccf0eSAntonio Nino Diaz ******************************************************************************/ 90*3e840ec8SMadhukar Pappireddy #define CTX_CVE_2018_3639_OFFSET (CTX_EL3STATE_OFFSET + CTX_EL3STATE_END) 91fe007b2eSDimitris Papastamos #define CTX_CVE_2018_3639_DISABLE U(0) 92fe007b2eSDimitris Papastamos #define CTX_CVE_2018_3639_END U(0x10) /* Align to the next 16 byte boundary */ 93fe007b2eSDimitris Papastamos 945283962eSAntonio Nino Diaz /******************************************************************************* 9559b7c0a0SJayanth Dodderi Chidanand * Registers related to ERRATA_SPECULATIVE_AT 9659b7c0a0SJayanth Dodderi Chidanand * 9759b7c0a0SJayanth Dodderi Chidanand * This is essential as with EL1 and EL2 context registers being decoupled, 9859b7c0a0SJayanth Dodderi Chidanand * both will not be present for a given build configuration. 9959b7c0a0SJayanth Dodderi Chidanand * As ERRATA_SPECULATIVE_AT errata requires SCTLR_EL1 and TCR_EL1 registers 10059b7c0a0SJayanth Dodderi Chidanand * independent of the above logic, we need explicit context entries to be 10159b7c0a0SJayanth Dodderi Chidanand * reserved for these registers. 10259b7c0a0SJayanth Dodderi Chidanand * 10359b7c0a0SJayanth Dodderi Chidanand * NOTE: Based on this we end up with following different configurations depending 10459b7c0a0SJayanth Dodderi Chidanand * on the presence of errata and inclusion of EL1 or EL2 context. 10559b7c0a0SJayanth Dodderi Chidanand * 10659b7c0a0SJayanth Dodderi Chidanand * ============================================================================ 10759b7c0a0SJayanth Dodderi Chidanand * | ERRATA_SPECULATIVE_AT | EL1 context| Memory allocation(Sctlr_el1,Tcr_el1)| 10859b7c0a0SJayanth Dodderi Chidanand * ============================================================================ 10959b7c0a0SJayanth Dodderi Chidanand * | 0 | 0 | None | 11059b7c0a0SJayanth Dodderi Chidanand * | 0 | 1 | EL1 C-Context structure | 11159b7c0a0SJayanth Dodderi Chidanand * | 1 | 0 | Errata Context Offset Entries | 11259b7c0a0SJayanth Dodderi Chidanand * | 1 | 1 | Errata Context Offset Entries | 11359b7c0a0SJayanth Dodderi Chidanand * ============================================================================ 11459b7c0a0SJayanth Dodderi Chidanand * 11559b7c0a0SJayanth Dodderi Chidanand * In the above table, when ERRATA_SPECULATIVE_AT=1, EL1_Context=0, it implies 11659b7c0a0SJayanth Dodderi Chidanand * there is only EL2 context and memory for SCTLR_EL1 and TCR_EL1 registers is 11759b7c0a0SJayanth Dodderi Chidanand * reserved explicitly under ERRATA_SPECULATIVE_AT build flag here. 11859b7c0a0SJayanth Dodderi Chidanand * 11959b7c0a0SJayanth Dodderi Chidanand * In situations when EL1_Context=1 and ERRATA_SPECULATIVE_AT=1, since SCTLR_EL1 12059b7c0a0SJayanth Dodderi Chidanand * and TCR_EL1 registers will be modified under errata and it happens at the 12159b7c0a0SJayanth Dodderi Chidanand * early in the codeflow prior to el1 context (save and restore operations), 12259b7c0a0SJayanth Dodderi Chidanand * context memory still will be reserved under the errata logic here explicitly. 12359b7c0a0SJayanth Dodderi Chidanand * These registers will not be part of EL1 context save & restore routines. 12459b7c0a0SJayanth Dodderi Chidanand * 12559b7c0a0SJayanth Dodderi Chidanand * Only when ERRATA_SPECULATIVE_AT=0, EL1_Context=1, for this combination, 12659b7c0a0SJayanth Dodderi Chidanand * SCTLR_EL1 and TCR_EL1 will be part of EL1 context structure (context_el1.h) 12759b7c0a0SJayanth Dodderi Chidanand * ----------------------------------------------------------------------------- 12859b7c0a0SJayanth Dodderi Chidanand ******************************************************************************/ 12959b7c0a0SJayanth Dodderi Chidanand #define CTX_ERRATA_SPEC_AT_OFFSET (CTX_CVE_2018_3639_OFFSET + CTX_CVE_2018_3639_END) 13059b7c0a0SJayanth Dodderi Chidanand #if ERRATA_SPECULATIVE_AT 13159b7c0a0SJayanth Dodderi Chidanand #define CTX_ERRATA_SPEC_AT_SCTLR_EL1 U(0x0) 13259b7c0a0SJayanth Dodderi Chidanand #define CTX_ERRATA_SPEC_AT_TCR_EL1 U(0x8) 13359b7c0a0SJayanth Dodderi Chidanand #define CTX_ERRATA_SPEC_AT_END U(0x10) /* Align to the next 16 byte boundary */ 13459b7c0a0SJayanth Dodderi Chidanand #else 13559b7c0a0SJayanth Dodderi Chidanand #define CTX_ERRATA_SPEC_AT_END U(0x0) 13659b7c0a0SJayanth Dodderi Chidanand #endif /* ERRATA_SPECULATIVE_AT */ 13759b7c0a0SJayanth Dodderi Chidanand 13859b7c0a0SJayanth Dodderi Chidanand /******************************************************************************* 1395283962eSAntonio Nino Diaz * Registers related to ARMv8.3-PAuth. 1405283962eSAntonio Nino Diaz ******************************************************************************/ 14159b7c0a0SJayanth Dodderi Chidanand #define CTX_PAUTH_REGS_OFFSET (CTX_ERRATA_SPEC_AT_OFFSET + CTX_ERRATA_SPEC_AT_END) 1425283962eSAntonio Nino Diaz #if CTX_INCLUDE_PAUTH_REGS 1435283962eSAntonio Nino Diaz #define CTX_PACIAKEY_LO U(0x0) 1445283962eSAntonio Nino Diaz #define CTX_PACIAKEY_HI U(0x8) 1455283962eSAntonio Nino Diaz #define CTX_PACIBKEY_LO U(0x10) 1465283962eSAntonio Nino Diaz #define CTX_PACIBKEY_HI U(0x18) 1475283962eSAntonio Nino Diaz #define CTX_PACDAKEY_LO U(0x20) 1485283962eSAntonio Nino Diaz #define CTX_PACDAKEY_HI U(0x28) 1495283962eSAntonio Nino Diaz #define CTX_PACDBKEY_LO U(0x30) 1505283962eSAntonio Nino Diaz #define CTX_PACDBKEY_HI U(0x38) 1515283962eSAntonio Nino Diaz #define CTX_PACGAKEY_LO U(0x40) 1525283962eSAntonio Nino Diaz #define CTX_PACGAKEY_HI U(0x48) 153ed108b56SAlexei Fedorov #define CTX_PAUTH_REGS_END U(0x50) /* Align to the next 16 byte boundary */ 1545283962eSAntonio Nino Diaz #else 1555283962eSAntonio Nino Diaz #define CTX_PAUTH_REGS_END U(0) 1565283962eSAntonio Nino Diaz #endif /* CTX_INCLUDE_PAUTH_REGS */ 1575283962eSAntonio Nino Diaz 158461c0a5dSElizabeth Ho /******************************************************************************* 159461c0a5dSElizabeth Ho * Registers initialised in a per-world context. 160461c0a5dSElizabeth Ho ******************************************************************************/ 161461c0a5dSElizabeth Ho #define CTX_CPTR_EL3 U(0x0) 162461c0a5dSElizabeth Ho #define CTX_ZCR_EL3 U(0x8) 163ac4f6aafSArvind Ram Prakash #define CTX_MPAM3_EL3 U(0x10) 164ac4f6aafSArvind Ram Prakash #define CTX_PERWORLD_EL3STATE_END U(0x18) 165461c0a5dSElizabeth Ho 166d5dfdeb6SJulius Werner #ifndef __ASSEMBLER__ 167532ed618SSoby Mathew 168532ed618SSoby Mathew #include <stdint.h> 169532ed618SSoby Mathew 17009d40e0eSAntonio Nino Diaz #include <lib/cassert.h> 17109d40e0eSAntonio Nino Diaz 172532ed618SSoby Mathew /* 173532ed618SSoby Mathew * Common constants to help define the 'cpu_context' structure and its 174532ed618SSoby Mathew * members below. 175532ed618SSoby Mathew */ 176030567e6SVarun Wadekar #define DWORD_SHIFT U(3) 177532ed618SSoby Mathew #define DEFINE_REG_STRUCT(name, num_regs) \ 178532ed618SSoby Mathew typedef struct name { \ 1792fe75a2dSZelalem uint64_t ctx_regs[num_regs]; \ 180532ed618SSoby Mathew } __aligned(16) name##_t 181532ed618SSoby Mathew 182532ed618SSoby Mathew /* Constants to determine the size of individual context structures */ 183532ed618SSoby Mathew #define CTX_GPREG_ALL (CTX_GPREGS_END >> DWORD_SHIFT) 184d6af2344SJayanth Dodderi Chidanand 185532ed618SSoby Mathew #define CTX_EL3STATE_ALL (CTX_EL3STATE_END >> DWORD_SHIFT) 186fe007b2eSDimitris Papastamos #define CTX_CVE_2018_3639_ALL (CTX_CVE_2018_3639_END >> DWORD_SHIFT) 18759b7c0a0SJayanth Dodderi Chidanand 18859b7c0a0SJayanth Dodderi Chidanand #if ERRATA_SPECULATIVE_AT 18959b7c0a0SJayanth Dodderi Chidanand #define CTX_ERRATA_SPEC_AT_ALL (CTX_ERRATA_SPEC_AT_END >> DWORD_SHIFT) 19059b7c0a0SJayanth Dodderi Chidanand #endif 1915283962eSAntonio Nino Diaz #if CTX_INCLUDE_PAUTH_REGS 1925283962eSAntonio Nino Diaz # define CTX_PAUTH_REGS_ALL (CTX_PAUTH_REGS_END >> DWORD_SHIFT) 1935283962eSAntonio Nino Diaz #endif 194532ed618SSoby Mathew 195532ed618SSoby Mathew /* 196532ed618SSoby Mathew * AArch64 general purpose register context structure. Usually x0-x18, 197532ed618SSoby Mathew * lr are saved as the compiler is expected to preserve the remaining 198532ed618SSoby Mathew * callee saved registers if used by the C runtime and the assembler 199532ed618SSoby Mathew * does not touch the remaining. But in case of world switch during 200532ed618SSoby Mathew * exception handling, we need to save the callee registers too. 201532ed618SSoby Mathew */ 202532ed618SSoby Mathew DEFINE_REG_STRUCT(gp_regs, CTX_GPREG_ALL); 203532ed618SSoby Mathew 204532ed618SSoby Mathew /* 205532ed618SSoby Mathew * Miscellaneous registers used by EL3 firmware to maintain its state 206532ed618SSoby Mathew * across exception entries and exits 207532ed618SSoby Mathew */ 208532ed618SSoby Mathew DEFINE_REG_STRUCT(el3_state, CTX_EL3STATE_ALL); 209532ed618SSoby Mathew 210fe007b2eSDimitris Papastamos /* Function pointer used by CVE-2018-3639 dynamic mitigation */ 211fe007b2eSDimitris Papastamos DEFINE_REG_STRUCT(cve_2018_3639, CTX_CVE_2018_3639_ALL); 212fe007b2eSDimitris Papastamos 21359b7c0a0SJayanth Dodderi Chidanand /* Registers associated to Errata_Speculative */ 21459b7c0a0SJayanth Dodderi Chidanand #if ERRATA_SPECULATIVE_AT 21559b7c0a0SJayanth Dodderi Chidanand DEFINE_REG_STRUCT(errata_speculative_at, CTX_ERRATA_SPEC_AT_ALL); 21659b7c0a0SJayanth Dodderi Chidanand #endif 21759b7c0a0SJayanth Dodderi Chidanand 2185283962eSAntonio Nino Diaz /* Registers associated to ARMv8.3-PAuth */ 2195283962eSAntonio Nino Diaz #if CTX_INCLUDE_PAUTH_REGS 2205283962eSAntonio Nino Diaz DEFINE_REG_STRUCT(pauth, CTX_PAUTH_REGS_ALL); 2215283962eSAntonio Nino Diaz #endif 2225283962eSAntonio Nino Diaz 223532ed618SSoby Mathew /* 224532ed618SSoby Mathew * Macros to access members of any of the above structures using their 225532ed618SSoby Mathew * offsets 226532ed618SSoby Mathew */ 2272fe75a2dSZelalem #define read_ctx_reg(ctx, offset) ((ctx)->ctx_regs[(offset) >> DWORD_SHIFT]) 2282fe75a2dSZelalem #define write_ctx_reg(ctx, offset, val) (((ctx)->ctx_regs[(offset) >> DWORD_SHIFT]) \ 229ba6e5ca6SJeenu Viswambharan = (uint64_t) (val)) 230532ed618SSoby Mathew 231532ed618SSoby Mathew /* 232c5ea4f8aSZelalem Aweke * Top-level context structure which is used by EL3 firmware to preserve 233c5ea4f8aSZelalem Aweke * the state of a core at the next lower EL in a given security state and 234c5ea4f8aSZelalem Aweke * save enough EL3 meta data to be able to return to that EL and security 235c5ea4f8aSZelalem Aweke * state. The context management library will be used to ensure that 236c5ea4f8aSZelalem Aweke * SP_EL3 always points to an instance of this structure at exception 237c5ea4f8aSZelalem Aweke * entry and exit. 238532ed618SSoby Mathew */ 239532ed618SSoby Mathew typedef struct cpu_context { 240532ed618SSoby Mathew gp_regs_t gpregs_ctx; 241532ed618SSoby Mathew el3_state_t el3state_ctx; 242d6af2344SJayanth Dodderi Chidanand 243fe007b2eSDimitris Papastamos cve_2018_3639_t cve_2018_3639_ctx; 244d6af2344SJayanth Dodderi Chidanand 24559b7c0a0SJayanth Dodderi Chidanand #if ERRATA_SPECULATIVE_AT 24659b7c0a0SJayanth Dodderi Chidanand errata_speculative_at_t errata_speculative_at_ctx; 24759b7c0a0SJayanth Dodderi Chidanand #endif 24859b7c0a0SJayanth Dodderi Chidanand 2495283962eSAntonio Nino Diaz #if CTX_INCLUDE_PAUTH_REGS 2505283962eSAntonio Nino Diaz pauth_t pauth_ctx; 2515283962eSAntonio Nino Diaz #endif 252d6af2344SJayanth Dodderi Chidanand 25342e35d2fSJayanth Dodderi Chidanand el1_sysregs_t el1_sysregs_ctx; 25442e35d2fSJayanth Dodderi Chidanand 255d6af2344SJayanth Dodderi Chidanand #if CTX_INCLUDE_EL2_REGS 256d6af2344SJayanth Dodderi Chidanand el2_sysregs_t el2_sysregs_ctx; 257d6af2344SJayanth Dodderi Chidanand #endif 258d6af2344SJayanth Dodderi Chidanand 259532ed618SSoby Mathew } cpu_context_t; 260532ed618SSoby Mathew 261461c0a5dSElizabeth Ho /* 262461c0a5dSElizabeth Ho * Per-World Context. 263461c0a5dSElizabeth Ho * It stores registers whose values can be shared across CPUs. 264461c0a5dSElizabeth Ho */ 265461c0a5dSElizabeth Ho typedef struct per_world_context { 266461c0a5dSElizabeth Ho uint64_t ctx_cptr_el3; 267461c0a5dSElizabeth Ho uint64_t ctx_zcr_el3; 268ac4f6aafSArvind Ram Prakash uint64_t ctx_mpam3_el3; 269461c0a5dSElizabeth Ho } per_world_context_t; 270461c0a5dSElizabeth Ho 271461c0a5dSElizabeth Ho extern per_world_context_t per_world_context[CPU_DATA_CONTEXT_NUM]; 272461c0a5dSElizabeth Ho 273532ed618SSoby Mathew /* Macros to access members of the 'cpu_context_t' structure */ 274532ed618SSoby Mathew #define get_el3state_ctx(h) (&((cpu_context_t *) h)->el3state_ctx) 2752825946eSMax Shvetsov #define get_el1_sysregs_ctx(h) (&((cpu_context_t *) h)->el1_sysregs_ctx) 2762825946eSMax Shvetsov #if CTX_INCLUDE_EL2_REGS 2772825946eSMax Shvetsov # define get_el2_sysregs_ctx(h) (&((cpu_context_t *) h)->el2_sysregs_ctx) 2782825946eSMax Shvetsov #endif 279532ed618SSoby Mathew #define get_gpregs_ctx(h) (&((cpu_context_t *) h)->gpregs_ctx) 2806f03bc77SDimitris Papastamos #define get_cve_2018_3639_ctx(h) (&((cpu_context_t *) h)->cve_2018_3639_ctx) 28159b7c0a0SJayanth Dodderi Chidanand 28259b7c0a0SJayanth Dodderi Chidanand #if ERRATA_SPECULATIVE_AT 28359b7c0a0SJayanth Dodderi Chidanand #define get_errata_speculative_at_ctx(h) (&((cpu_context_t *) h)->errata_speculative_at_ctx) 28459b7c0a0SJayanth Dodderi Chidanand #endif 28559b7c0a0SJayanth Dodderi Chidanand 2865283962eSAntonio Nino Diaz #if CTX_INCLUDE_PAUTH_REGS 2875283962eSAntonio Nino Diaz # define get_pauth_ctx(h) (&((cpu_context_t *) h)->pauth_ctx) 2885283962eSAntonio Nino Diaz #endif 289532ed618SSoby Mathew 290532ed618SSoby Mathew /* 291532ed618SSoby Mathew * Compile time assertions related to the 'cpu_context' structure to 292532ed618SSoby Mathew * ensure that the assembler and the compiler view of the offsets of 293532ed618SSoby Mathew * the structure members is the same. 294532ed618SSoby Mathew */ 2959a90d720SElyes Haouas CASSERT(CTX_GPREGS_OFFSET == __builtin_offsetof(cpu_context_t, gpregs_ctx), 296532ed618SSoby Mathew assert_core_context_gp_offset_mismatch); 297d6af2344SJayanth Dodderi Chidanand 298d6af2344SJayanth Dodderi Chidanand CASSERT(CTX_EL3STATE_OFFSET == __builtin_offsetof(cpu_context_t, el3state_ctx), 299d6af2344SJayanth Dodderi Chidanand assert_core_context_el3state_offset_mismatch); 300d6af2344SJayanth Dodderi Chidanand 301d6af2344SJayanth Dodderi Chidanand 3029a90d720SElyes Haouas CASSERT(CTX_CVE_2018_3639_OFFSET == __builtin_offsetof(cpu_context_t, cve_2018_3639_ctx), 303fe007b2eSDimitris Papastamos assert_core_context_cve_2018_3639_offset_mismatch); 304d6af2344SJayanth Dodderi Chidanand 30559b7c0a0SJayanth Dodderi Chidanand #if ERRATA_SPECULATIVE_AT 30659b7c0a0SJayanth Dodderi Chidanand CASSERT(CTX_ERRATA_SPEC_AT_OFFSET == __builtin_offsetof(cpu_context_t, errata_speculative_at_ctx), 30759b7c0a0SJayanth Dodderi Chidanand assert_core_context_errata_speculative_at_offset_mismatch); 30859b7c0a0SJayanth Dodderi Chidanand #endif 30959b7c0a0SJayanth Dodderi Chidanand 3105283962eSAntonio Nino Diaz #if CTX_INCLUDE_PAUTH_REGS 3119a90d720SElyes Haouas CASSERT(CTX_PAUTH_REGS_OFFSET == __builtin_offsetof(cpu_context_t, pauth_ctx), 3125283962eSAntonio Nino Diaz assert_core_context_pauth_offset_mismatch); 313d6af2344SJayanth Dodderi Chidanand #endif /* CTX_INCLUDE_PAUTH_REGS */ 314d6af2344SJayanth Dodderi Chidanand 315532ed618SSoby Mathew /* 316532ed618SSoby Mathew * Helper macro to set the general purpose registers that correspond to 317532ed618SSoby Mathew * parameters in an aapcs_64 call i.e. x0-x7 318532ed618SSoby Mathew */ 319532ed618SSoby Mathew #define set_aapcs_args0(ctx, x0) do { \ 320532ed618SSoby Mathew write_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X0, x0); \ 321532ed618SSoby Mathew } while (0) 322532ed618SSoby Mathew #define set_aapcs_args1(ctx, x0, x1) do { \ 323532ed618SSoby Mathew write_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X1, x1); \ 324532ed618SSoby Mathew set_aapcs_args0(ctx, x0); \ 325532ed618SSoby Mathew } while (0) 326532ed618SSoby Mathew #define set_aapcs_args2(ctx, x0, x1, x2) do { \ 327532ed618SSoby Mathew write_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X2, x2); \ 328532ed618SSoby Mathew set_aapcs_args1(ctx, x0, x1); \ 329532ed618SSoby Mathew } while (0) 330532ed618SSoby Mathew #define set_aapcs_args3(ctx, x0, x1, x2, x3) do { \ 331532ed618SSoby Mathew write_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X3, x3); \ 332532ed618SSoby Mathew set_aapcs_args2(ctx, x0, x1, x2); \ 333532ed618SSoby Mathew } while (0) 334532ed618SSoby Mathew #define set_aapcs_args4(ctx, x0, x1, x2, x3, x4) do { \ 335532ed618SSoby Mathew write_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X4, x4); \ 336532ed618SSoby Mathew set_aapcs_args3(ctx, x0, x1, x2, x3); \ 337532ed618SSoby Mathew } while (0) 338532ed618SSoby Mathew #define set_aapcs_args5(ctx, x0, x1, x2, x3, x4, x5) do { \ 339532ed618SSoby Mathew write_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X5, x5); \ 340532ed618SSoby Mathew set_aapcs_args4(ctx, x0, x1, x2, x3, x4); \ 341532ed618SSoby Mathew } while (0) 342532ed618SSoby Mathew #define set_aapcs_args6(ctx, x0, x1, x2, x3, x4, x5, x6) do { \ 343532ed618SSoby Mathew write_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X6, x6); \ 344532ed618SSoby Mathew set_aapcs_args5(ctx, x0, x1, x2, x3, x4, x5); \ 345532ed618SSoby Mathew } while (0) 346532ed618SSoby Mathew #define set_aapcs_args7(ctx, x0, x1, x2, x3, x4, x5, x6, x7) do { \ 347532ed618SSoby Mathew write_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X7, x7); \ 348532ed618SSoby Mathew set_aapcs_args6(ctx, x0, x1, x2, x3, x4, x5, x6); \ 349532ed618SSoby Mathew } while (0) 350532ed618SSoby Mathew 351532ed618SSoby Mathew /******************************************************************************* 352532ed618SSoby Mathew * Function prototypes 353532ed618SSoby Mathew ******************************************************************************/ 354532ed618SSoby Mathew #if CTX_INCLUDE_FPREGS 355308ebfa1SMadhukar Pappireddy void fpregs_context_save(simd_regs_t *regs); 356308ebfa1SMadhukar Pappireddy void fpregs_context_restore(simd_regs_t *regs); 357532ed618SSoby Mathew #endif 358532ed618SSoby Mathew 359d5dfdeb6SJulius Werner #endif /* __ASSEMBLER__ */ 360532ed618SSoby Mathew 361a0fee747SAntonio Nino Diaz #endif /* CONTEXT_H */ 362