xref: /rk3399_ARM-atf/include/lib/el3_runtime/aarch64/context.h (revision 59b7c0a03fa8adfc9272f959bd8b4228ddd2607a)
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 
10d6af2344SJayanth Dodderi Chidanand #include <lib/el3_runtime/context_el2.h>
11461c0a5dSElizabeth Ho #include <lib/el3_runtime/cpu_data.h>
1209d40e0eSAntonio Nino Diaz #include <lib/utils_def.h>
1376454abfSJeenu Viswambharan 
14532ed618SSoby Mathew /*******************************************************************************
15532ed618SSoby Mathew  * Constants that allow assembler code to access members of and the 'gp_regs'
16532ed618SSoby Mathew  * structure at their correct offsets.
17532ed618SSoby Mathew  ******************************************************************************/
18030567e6SVarun Wadekar #define CTX_GPREGS_OFFSET	U(0x0)
19030567e6SVarun Wadekar #define CTX_GPREG_X0		U(0x0)
20030567e6SVarun Wadekar #define CTX_GPREG_X1		U(0x8)
21030567e6SVarun Wadekar #define CTX_GPREG_X2		U(0x10)
22030567e6SVarun Wadekar #define CTX_GPREG_X3		U(0x18)
23030567e6SVarun Wadekar #define CTX_GPREG_X4		U(0x20)
24030567e6SVarun Wadekar #define CTX_GPREG_X5		U(0x28)
25030567e6SVarun Wadekar #define CTX_GPREG_X6		U(0x30)
26030567e6SVarun Wadekar #define CTX_GPREG_X7		U(0x38)
27030567e6SVarun Wadekar #define CTX_GPREG_X8		U(0x40)
28030567e6SVarun Wadekar #define CTX_GPREG_X9		U(0x48)
29030567e6SVarun Wadekar #define CTX_GPREG_X10		U(0x50)
30030567e6SVarun Wadekar #define CTX_GPREG_X11		U(0x58)
31030567e6SVarun Wadekar #define CTX_GPREG_X12		U(0x60)
32030567e6SVarun Wadekar #define CTX_GPREG_X13		U(0x68)
33030567e6SVarun Wadekar #define CTX_GPREG_X14		U(0x70)
34030567e6SVarun Wadekar #define CTX_GPREG_X15		U(0x78)
35030567e6SVarun Wadekar #define CTX_GPREG_X16		U(0x80)
36030567e6SVarun Wadekar #define CTX_GPREG_X17		U(0x88)
37030567e6SVarun Wadekar #define CTX_GPREG_X18		U(0x90)
38030567e6SVarun Wadekar #define CTX_GPREG_X19		U(0x98)
39030567e6SVarun Wadekar #define CTX_GPREG_X20		U(0xa0)
40030567e6SVarun Wadekar #define CTX_GPREG_X21		U(0xa8)
41030567e6SVarun Wadekar #define CTX_GPREG_X22		U(0xb0)
42030567e6SVarun Wadekar #define CTX_GPREG_X23		U(0xb8)
43030567e6SVarun Wadekar #define CTX_GPREG_X24		U(0xc0)
44030567e6SVarun Wadekar #define CTX_GPREG_X25		U(0xc8)
45030567e6SVarun Wadekar #define CTX_GPREG_X26		U(0xd0)
46030567e6SVarun Wadekar #define CTX_GPREG_X27		U(0xd8)
47030567e6SVarun Wadekar #define CTX_GPREG_X28		U(0xe0)
48030567e6SVarun Wadekar #define CTX_GPREG_X29		U(0xe8)
49030567e6SVarun Wadekar #define CTX_GPREG_LR		U(0xf0)
50030567e6SVarun Wadekar #define CTX_GPREG_SP_EL0	U(0xf8)
51030567e6SVarun Wadekar #define CTX_GPREGS_END		U(0x100)
52532ed618SSoby Mathew 
53532ed618SSoby Mathew /*******************************************************************************
54532ed618SSoby Mathew  * Constants that allow assembler code to access members of and the 'el3_state'
55532ed618SSoby Mathew  * structure at their correct offsets. Note that some of the registers are only
56532ed618SSoby Mathew  * 32-bits wide but are stored as 64-bit values for convenience
57532ed618SSoby Mathew  ******************************************************************************/
58d9bd656cSDimitris Papastamos #define CTX_EL3STATE_OFFSET	(CTX_GPREGS_OFFSET + CTX_GPREGS_END)
59030567e6SVarun Wadekar #define CTX_SCR_EL3		U(0x0)
6076454abfSJeenu Viswambharan #define CTX_ESR_EL3		U(0x8)
6176454abfSJeenu Viswambharan #define CTX_RUNTIME_SP		U(0x10)
6276454abfSJeenu Viswambharan #define CTX_SPSR_EL3		U(0x18)
6376454abfSJeenu Viswambharan #define CTX_ELR_EL3		U(0x20)
64e290a8fcSAlexei Fedorov #define CTX_PMCR_EL0		U(0x28)
65c2d32a5fSMadhukar Pappireddy #define CTX_IS_IN_EL3		U(0x30)
66123002f9SJayanth Dodderi Chidanand #define CTX_MDCR_EL3		U(0x38)
67d04c04a4SManish Pandey /* Constants required in supporting nested exception in EL3 */
68123002f9SJayanth Dodderi Chidanand #define CTX_SAVED_ELR_EL3	U(0x40)
69d04c04a4SManish Pandey /*
70d04c04a4SManish Pandey  * General purpose flag, to save various EL3 states
71d04c04a4SManish Pandey  * FFH mode : Used to identify if handling nested exception
72d04c04a4SManish Pandey  * KFH mode : Used as counter value
73d04c04a4SManish Pandey  */
74123002f9SJayanth Dodderi Chidanand #define CTX_NESTED_EA_FLAG	U(0x48)
75f87e54f7SManish Pandey #if FFH_SUPPORT
76123002f9SJayanth Dodderi Chidanand  #define CTX_SAVED_ESR_EL3	U(0x50)
77123002f9SJayanth Dodderi Chidanand  #define CTX_SAVED_SPSR_EL3	U(0x58)
78123002f9SJayanth Dodderi Chidanand  #define CTX_SAVED_GPREG_LR	U(0x60)
79123002f9SJayanth Dodderi Chidanand  #define CTX_EL3STATE_END	U(0x70) /* Align to the next 16 byte boundary */
80d04c04a4SManish Pandey #else
81d04c04a4SManish Pandey  #define CTX_EL3STATE_END	U(0x50) /* Align to the next 16 byte boundary */
82ac4f6aafSArvind Ram Prakash #endif /* FFH_SUPPORT */
83532ed618SSoby Mathew 
84532ed618SSoby Mathew /*******************************************************************************
85532ed618SSoby Mathew  * Constants that allow assembler code to access members of and the
86532ed618SSoby Mathew  * 'el1_sys_regs' structure at their correct offsets. Note that some of the
87532ed618SSoby Mathew  * registers are only 32-bits wide but are stored as 64-bit values for
88532ed618SSoby Mathew  * convenience
89532ed618SSoby Mathew  ******************************************************************************/
902825946eSMax Shvetsov #define CTX_EL1_SYSREGS_OFFSET	(CTX_EL3STATE_OFFSET + CTX_EL3STATE_END)
91030567e6SVarun Wadekar #define CTX_SPSR_EL1		U(0x0)
92030567e6SVarun Wadekar #define CTX_ELR_EL1		U(0x8)
93030567e6SVarun Wadekar #define CTX_SCTLR_EL1		U(0x10)
94cb55615cSManish V Badarkhe #define CTX_TCR_EL1		U(0x18)
95030567e6SVarun Wadekar #define CTX_CPACR_EL1		U(0x20)
96030567e6SVarun Wadekar #define CTX_CSSELR_EL1		U(0x28)
97030567e6SVarun Wadekar #define CTX_SP_EL1		U(0x30)
98030567e6SVarun Wadekar #define CTX_ESR_EL1		U(0x38)
99030567e6SVarun Wadekar #define CTX_TTBR0_EL1		U(0x40)
100030567e6SVarun Wadekar #define CTX_TTBR1_EL1		U(0x48)
101030567e6SVarun Wadekar #define CTX_MAIR_EL1		U(0x50)
102030567e6SVarun Wadekar #define CTX_AMAIR_EL1		U(0x58)
103cb55615cSManish V Badarkhe #define CTX_ACTLR_EL1		U(0x60)
104030567e6SVarun Wadekar #define CTX_TPIDR_EL1		U(0x68)
105030567e6SVarun Wadekar #define CTX_TPIDR_EL0		U(0x70)
106030567e6SVarun Wadekar #define CTX_TPIDRRO_EL0		U(0x78)
107030567e6SVarun Wadekar #define CTX_PAR_EL1		U(0x80)
108030567e6SVarun Wadekar #define CTX_FAR_EL1		U(0x88)
109030567e6SVarun Wadekar #define CTX_AFSR0_EL1		U(0x90)
110030567e6SVarun Wadekar #define CTX_AFSR1_EL1		U(0x98)
111030567e6SVarun Wadekar #define CTX_CONTEXTIDR_EL1	U(0xa0)
112030567e6SVarun Wadekar #define CTX_VBAR_EL1		U(0xa8)
113ed9bb824SMadhukar Pappireddy #define CTX_MDCCINT_EL1		U(0xb0)
114ed9bb824SMadhukar Pappireddy #define CTX_MDSCR_EL1		U(0xb8)
115ed9bb824SMadhukar Pappireddy 
116ed9bb824SMadhukar Pappireddy #define CTX_AARCH64_END		U(0xc0) /* Align to the next 16 byte boundary */
117532ed618SSoby Mathew 
118532ed618SSoby Mathew /*
119532ed618SSoby Mathew  * If the platform is AArch64-only, there is no need to save and restore these
120532ed618SSoby Mathew  * AArch32 registers.
121532ed618SSoby Mathew  */
122532ed618SSoby Mathew #if CTX_INCLUDE_AARCH32_REGS
123ed9bb824SMadhukar Pappireddy #define CTX_SPSR_ABT		(CTX_AARCH64_END + U(0x0))
124ed9bb824SMadhukar Pappireddy #define CTX_SPSR_UND		(CTX_AARCH64_END + U(0x8))
125ed9bb824SMadhukar Pappireddy #define CTX_SPSR_IRQ		(CTX_AARCH64_END + U(0x10))
126ed9bb824SMadhukar Pappireddy #define CTX_SPSR_FIQ		(CTX_AARCH64_END + U(0x18))
127ed9bb824SMadhukar Pappireddy #define CTX_DACR32_EL2		(CTX_AARCH64_END + U(0x20))
128ed9bb824SMadhukar Pappireddy #define CTX_IFSR32_EL2		(CTX_AARCH64_END + U(0x28))
129ed9bb824SMadhukar Pappireddy #define CTX_AARCH32_END		(CTX_AARCH64_END + U(0x30)) /* Align to the next 16 byte boundary */
130532ed618SSoby Mathew #else
131ed9bb824SMadhukar Pappireddy #define CTX_AARCH32_END		CTX_AARCH64_END
1324d1ccf0eSAntonio Nino Diaz #endif /* CTX_INCLUDE_AARCH32_REGS */
133532ed618SSoby Mathew 
134532ed618SSoby Mathew /*
135532ed618SSoby Mathew  * If the timer registers aren't saved and restored, we don't have to reserve
136532ed618SSoby Mathew  * space for them in the context
137532ed618SSoby Mathew  */
138532ed618SSoby Mathew #if NS_TIMER_SWITCH
1394d1ccf0eSAntonio Nino Diaz #define CTX_CNTP_CTL_EL0	(CTX_AARCH32_END + U(0x0))
1404d1ccf0eSAntonio Nino Diaz #define CTX_CNTP_CVAL_EL0	(CTX_AARCH32_END + U(0x8))
1414d1ccf0eSAntonio Nino Diaz #define CTX_CNTV_CTL_EL0	(CTX_AARCH32_END + U(0x10))
1424d1ccf0eSAntonio Nino Diaz #define CTX_CNTV_CVAL_EL0	(CTX_AARCH32_END + U(0x18))
1434d1ccf0eSAntonio Nino Diaz #define CTX_CNTKCTL_EL1		(CTX_AARCH32_END + U(0x20))
1444d1ccf0eSAntonio Nino Diaz #define CTX_TIMER_SYSREGS_END	(CTX_AARCH32_END + U(0x30)) /* Align to the next 16 byte boundary */
145532ed618SSoby Mathew #else
1464d1ccf0eSAntonio Nino Diaz #define CTX_TIMER_SYSREGS_END	CTX_AARCH32_END
1474d1ccf0eSAntonio Nino Diaz #endif /* NS_TIMER_SWITCH */
1484d1ccf0eSAntonio Nino Diaz 
149c282384dSGovindraj Raja #if ENABLE_FEAT_MTE2
1509dd94382SJustin Chadwell #define CTX_TFSRE0_EL1		(CTX_TIMER_SYSREGS_END + U(0x0))
1519dd94382SJustin Chadwell #define CTX_TFSR_EL1		(CTX_TIMER_SYSREGS_END + U(0x8))
1529dd94382SJustin Chadwell #define CTX_RGSR_EL1		(CTX_TIMER_SYSREGS_END + U(0x10))
1539dd94382SJustin Chadwell #define CTX_GCR_EL1		(CTX_TIMER_SYSREGS_END + U(0x18))
154ed9bb824SMadhukar Pappireddy #define CTX_MTE_REGS_END	(CTX_TIMER_SYSREGS_END + U(0x20)) /* Align to the next 16 byte boundary */
1559dd94382SJustin Chadwell #else
1569dd94382SJustin Chadwell #define CTX_MTE_REGS_END	CTX_TIMER_SYSREGS_END
157c282384dSGovindraj Raja #endif /* ENABLE_FEAT_MTE2 */
1589dd94382SJustin Chadwell 
159ed9bb824SMadhukar Pappireddy #if ENABLE_FEAT_RAS
160ed9bb824SMadhukar Pappireddy #define CTX_DISR_EL1		(CTX_MTE_REGS_END + U(0x0))
161ed9bb824SMadhukar Pappireddy #define CTX_RAS_REGS_END	(CTX_MTE_REGS_END + U(0x10)) /* Align to the next 16 byte boundary */
162ed9bb824SMadhukar Pappireddy #else
163ed9bb824SMadhukar Pappireddy #define CTX_RAS_REGS_END        CTX_MTE_REGS_END
164ed9bb824SMadhukar Pappireddy #endif /* ENABLE_FEAT_RAS */
165ed9bb824SMadhukar Pappireddy 
166ed9bb824SMadhukar Pappireddy #if ENABLE_FEAT_S1PIE
167ed9bb824SMadhukar Pappireddy #define CTX_PIRE0_EL1		(CTX_RAS_REGS_END + U(0x0))
168ed9bb824SMadhukar Pappireddy #define CTX_PIR_EL1		(CTX_RAS_REGS_END + U(0x8))
169ed9bb824SMadhukar Pappireddy #define CTX_S1PIE_REGS_END	(CTX_RAS_REGS_END + U(0x10)) /* Align to the next 16 byte boundary */
170ed9bb824SMadhukar Pappireddy #else
171ed9bb824SMadhukar Pappireddy #define CTX_S1PIE_REGS_END	CTX_RAS_REGS_END
172ed9bb824SMadhukar Pappireddy #endif /* ENABLE_FEAT_S1PIE */
173ed9bb824SMadhukar Pappireddy 
174ed9bb824SMadhukar Pappireddy #if ENABLE_FEAT_S1POE
175ed9bb824SMadhukar Pappireddy #define CTX_POR_EL1		(CTX_S1PIE_REGS_END + U(0x0))
176ed9bb824SMadhukar Pappireddy #define CTX_S1POE_REGS_END	(CTX_S1PIE_REGS_END + U(0x10)) /* Align to the next 16 byte boundary */
177ed9bb824SMadhukar Pappireddy #else
178ed9bb824SMadhukar Pappireddy #define CTX_S1POE_REGS_END	CTX_S1PIE_REGS_END
179ed9bb824SMadhukar Pappireddy #endif /* ENABLE_FEAT_S1POE */
180ed9bb824SMadhukar Pappireddy 
181ed9bb824SMadhukar Pappireddy #if ENABLE_FEAT_S2POE
182ed9bb824SMadhukar Pappireddy #define CTX_S2POR_EL1		(CTX_S1POE_REGS_END + U(0x0))
183ed9bb824SMadhukar Pappireddy #define CTX_S2POE_REGS_END	(CTX_S1POE_REGS_END + U(0x10)) /* Align to the next 16 byte boundary */
184ed9bb824SMadhukar Pappireddy #else
185ed9bb824SMadhukar Pappireddy #define CTX_S2POE_REGS_END	CTX_S1POE_REGS_END
186ed9bb824SMadhukar Pappireddy #endif /* ENABLE_FEAT_S2POE */
187ed9bb824SMadhukar Pappireddy 
188ed9bb824SMadhukar Pappireddy #if ENABLE_FEAT_TCR2
189ed9bb824SMadhukar Pappireddy #define CTX_TCR2_EL1		(CTX_S2POE_REGS_END + U(0x0))
190ed9bb824SMadhukar Pappireddy #define CTX_TCR2_REGS_END	(CTX_S2POE_REGS_END + U(0x10)) /* Align to the next 16 byte boundary */
191ed9bb824SMadhukar Pappireddy #else
192ed9bb824SMadhukar Pappireddy #define CTX_TCR2_REGS_END       CTX_S2POE_REGS_END
193ed9bb824SMadhukar Pappireddy #endif /* ENABLE_FEAT_TCR2 */
194ed9bb824SMadhukar Pappireddy 
195d6c76e6cSMadhukar Pappireddy #if ENABLE_TRF_FOR_NS
196d6c76e6cSMadhukar Pappireddy #define CTX_TRFCR_EL1		(CTX_TCR2_REGS_END + U(0x0))
197d6c76e6cSMadhukar Pappireddy #define CTX_TRF_REGS_END	(CTX_TCR2_REGS_END + U(0x10)) /* Align to the next 16 byte boundary */
198d6c76e6cSMadhukar Pappireddy #else
199d6c76e6cSMadhukar Pappireddy #define CTX_TRF_REGS_END	CTX_TCR2_REGS_END
200d6c76e6cSMadhukar Pappireddy #endif /* ENABLE_TRF_FOR_NS */
201d6c76e6cSMadhukar Pappireddy 
202d6c76e6cSMadhukar Pappireddy #if ENABLE_FEAT_CSV2_2
203d6c76e6cSMadhukar Pappireddy #define CTX_SCXTNUM_EL0		(CTX_TRF_REGS_END + U(0x0))
204d6c76e6cSMadhukar Pappireddy #define CTX_SCXTNUM_EL1		(CTX_TRF_REGS_END + U(0x8))
205d6c76e6cSMadhukar Pappireddy #define CTX_CSV2_2_REGS_END	(CTX_TRF_REGS_END + U(0x10)) /* Align to the next 16 byte boundary */
206d6c76e6cSMadhukar Pappireddy #else
207d6c76e6cSMadhukar Pappireddy #define CTX_CSV2_2_REGS_END	CTX_TRF_REGS_END
208d6c76e6cSMadhukar Pappireddy #endif /* ENABLE_FEAT_CSV2_2 */
209d6c76e6cSMadhukar Pappireddy 
210d6c76e6cSMadhukar Pappireddy #if ENABLE_FEAT_GCS
211d6c76e6cSMadhukar Pappireddy #define CTX_GCSCR_EL1		(CTX_CSV2_2_REGS_END + U(0x0))
212d6c76e6cSMadhukar Pappireddy #define CTX_GCSCRE0_EL1		(CTX_CSV2_2_REGS_END + U(0x8))
213d6c76e6cSMadhukar Pappireddy #define CTX_GCSPR_EL1		(CTX_CSV2_2_REGS_END + U(0x10))
214d6c76e6cSMadhukar Pappireddy #define CTX_GCSPR_EL0		(CTX_CSV2_2_REGS_END + U(0x18))
215d6c76e6cSMadhukar Pappireddy #define CTX_GCS_REGS_END	(CTX_CSV2_2_REGS_END + U(0x20)) /* Align to the next 16 byte boundary */
216d6c76e6cSMadhukar Pappireddy #else
217d6c76e6cSMadhukar Pappireddy #define CTX_GCS_REGS_END	CTX_CSV2_2_REGS_END
218d6c76e6cSMadhukar Pappireddy #endif /* ENABLE_FEAT_GCS */
219d6c76e6cSMadhukar Pappireddy 
2204d1ccf0eSAntonio Nino Diaz /*
221d6c76e6cSMadhukar Pappireddy  * End of EL1 system registers.
2222825946eSMax Shvetsov  */
223d6c76e6cSMadhukar Pappireddy #define CTX_EL1_SYSREGS_END	CTX_GCS_REGS_END
2242825946eSMax Shvetsov 
225532ed618SSoby Mathew /*******************************************************************************
226532ed618SSoby Mathew  * Constants that allow assembler code to access members of and the 'fp_regs'
227532ed618SSoby Mathew  * structure at their correct offsets.
228532ed618SSoby Mathew  ******************************************************************************/
2292825946eSMax Shvetsov # define CTX_FPREGS_OFFSET	(CTX_EL1_SYSREGS_OFFSET + CTX_EL1_SYSREGS_END)
230fe007b2eSDimitris Papastamos #if CTX_INCLUDE_FPREGS
231030567e6SVarun Wadekar #define CTX_FP_Q0		U(0x0)
232030567e6SVarun Wadekar #define CTX_FP_Q1		U(0x10)
233030567e6SVarun Wadekar #define CTX_FP_Q2		U(0x20)
234030567e6SVarun Wadekar #define CTX_FP_Q3		U(0x30)
235030567e6SVarun Wadekar #define CTX_FP_Q4		U(0x40)
236030567e6SVarun Wadekar #define CTX_FP_Q5		U(0x50)
237030567e6SVarun Wadekar #define CTX_FP_Q6		U(0x60)
238030567e6SVarun Wadekar #define CTX_FP_Q7		U(0x70)
239030567e6SVarun Wadekar #define CTX_FP_Q8		U(0x80)
240030567e6SVarun Wadekar #define CTX_FP_Q9		U(0x90)
241030567e6SVarun Wadekar #define CTX_FP_Q10		U(0xa0)
242030567e6SVarun Wadekar #define CTX_FP_Q11		U(0xb0)
243030567e6SVarun Wadekar #define CTX_FP_Q12		U(0xc0)
244030567e6SVarun Wadekar #define CTX_FP_Q13		U(0xd0)
245030567e6SVarun Wadekar #define CTX_FP_Q14		U(0xe0)
246030567e6SVarun Wadekar #define CTX_FP_Q15		U(0xf0)
247030567e6SVarun Wadekar #define CTX_FP_Q16		U(0x100)
248030567e6SVarun Wadekar #define CTX_FP_Q17		U(0x110)
249030567e6SVarun Wadekar #define CTX_FP_Q18		U(0x120)
250030567e6SVarun Wadekar #define CTX_FP_Q19		U(0x130)
251030567e6SVarun Wadekar #define CTX_FP_Q20		U(0x140)
252030567e6SVarun Wadekar #define CTX_FP_Q21		U(0x150)
253030567e6SVarun Wadekar #define CTX_FP_Q22		U(0x160)
254030567e6SVarun Wadekar #define CTX_FP_Q23		U(0x170)
255030567e6SVarun Wadekar #define CTX_FP_Q24		U(0x180)
256030567e6SVarun Wadekar #define CTX_FP_Q25		U(0x190)
257030567e6SVarun Wadekar #define CTX_FP_Q26		U(0x1a0)
258030567e6SVarun Wadekar #define CTX_FP_Q27		U(0x1b0)
259030567e6SVarun Wadekar #define CTX_FP_Q28		U(0x1c0)
260030567e6SVarun Wadekar #define CTX_FP_Q29		U(0x1d0)
261030567e6SVarun Wadekar #define CTX_FP_Q30		U(0x1e0)
262030567e6SVarun Wadekar #define CTX_FP_Q31		U(0x1f0)
263030567e6SVarun Wadekar #define CTX_FP_FPSR		U(0x200)
264030567e6SVarun Wadekar #define CTX_FP_FPCR		U(0x208)
26591089f36SDavid Cunado #if CTX_INCLUDE_AARCH32_REGS
26691089f36SDavid Cunado #define CTX_FP_FPEXC32_EL2	U(0x210)
26791089f36SDavid Cunado #define CTX_FPREGS_END		U(0x220) /* Align to the next 16 byte boundary */
26891089f36SDavid Cunado #else
26991089f36SDavid Cunado #define CTX_FPREGS_END		U(0x210) /* Align to the next 16 byte boundary */
270d6af2344SJayanth Dodderi Chidanand #endif /* CTX_INCLUDE_AARCH32_REGS */
271fe007b2eSDimitris Papastamos #else
272fe007b2eSDimitris Papastamos #define CTX_FPREGS_END		U(0)
273d6af2344SJayanth Dodderi Chidanand #endif /* CTX_INCLUDE_FPREGS */
274532ed618SSoby Mathew 
2754d1ccf0eSAntonio Nino Diaz /*******************************************************************************
2764d1ccf0eSAntonio Nino Diaz  * Registers related to CVE-2018-3639
2774d1ccf0eSAntonio Nino Diaz  ******************************************************************************/
278fe007b2eSDimitris Papastamos #define CTX_CVE_2018_3639_OFFSET	(CTX_FPREGS_OFFSET + CTX_FPREGS_END)
279fe007b2eSDimitris Papastamos #define CTX_CVE_2018_3639_DISABLE	U(0)
280fe007b2eSDimitris Papastamos #define CTX_CVE_2018_3639_END		U(0x10) /* Align to the next 16 byte boundary */
281fe007b2eSDimitris Papastamos 
2825283962eSAntonio Nino Diaz /*******************************************************************************
283*59b7c0a0SJayanth Dodderi Chidanand  * Registers related to ERRATA_SPECULATIVE_AT
284*59b7c0a0SJayanth Dodderi Chidanand  *
285*59b7c0a0SJayanth Dodderi Chidanand  * This is essential as with EL1 and EL2 context registers being decoupled,
286*59b7c0a0SJayanth Dodderi Chidanand  * both will not be present for a given build configuration.
287*59b7c0a0SJayanth Dodderi Chidanand  * As ERRATA_SPECULATIVE_AT errata requires SCTLR_EL1 and TCR_EL1 registers
288*59b7c0a0SJayanth Dodderi Chidanand  * independent of the above logic, we need explicit context entries to be
289*59b7c0a0SJayanth Dodderi Chidanand  * reserved for these registers.
290*59b7c0a0SJayanth Dodderi Chidanand  *
291*59b7c0a0SJayanth Dodderi Chidanand  * NOTE: Based on this we end up with following different configurations depending
292*59b7c0a0SJayanth Dodderi Chidanand  * on the presence of errata and inclusion of EL1 or EL2 context.
293*59b7c0a0SJayanth Dodderi Chidanand  *
294*59b7c0a0SJayanth Dodderi Chidanand  * ============================================================================
295*59b7c0a0SJayanth Dodderi Chidanand  * | ERRATA_SPECULATIVE_AT | EL1 context| Memory allocation(Sctlr_el1,Tcr_el1)|
296*59b7c0a0SJayanth Dodderi Chidanand  * ============================================================================
297*59b7c0a0SJayanth Dodderi Chidanand  * |        0              |      0     |            None                     |
298*59b7c0a0SJayanth Dodderi Chidanand  * |        0              |      1     |    EL1 C-Context structure          |
299*59b7c0a0SJayanth Dodderi Chidanand  * |        1              |      0     |    Errata Context Offset Entries    |
300*59b7c0a0SJayanth Dodderi Chidanand  * |        1              |      1     |    Errata Context Offset Entries    |
301*59b7c0a0SJayanth Dodderi Chidanand  * ============================================================================
302*59b7c0a0SJayanth Dodderi Chidanand  *
303*59b7c0a0SJayanth Dodderi Chidanand  * In the above table, when ERRATA_SPECULATIVE_AT=1, EL1_Context=0, it implies
304*59b7c0a0SJayanth Dodderi Chidanand  * there is only EL2 context and memory for SCTLR_EL1 and TCR_EL1 registers is
305*59b7c0a0SJayanth Dodderi Chidanand  * reserved explicitly under ERRATA_SPECULATIVE_AT build flag here.
306*59b7c0a0SJayanth Dodderi Chidanand  *
307*59b7c0a0SJayanth Dodderi Chidanand  * In situations when EL1_Context=1 and  ERRATA_SPECULATIVE_AT=1, since SCTLR_EL1
308*59b7c0a0SJayanth Dodderi Chidanand  * and TCR_EL1 registers will be modified under errata and it happens at the
309*59b7c0a0SJayanth Dodderi Chidanand  * early in the codeflow prior to el1 context (save and restore operations),
310*59b7c0a0SJayanth Dodderi Chidanand  * context memory still will be reserved under the errata logic here explicitly.
311*59b7c0a0SJayanth Dodderi Chidanand  * These registers will not be part of EL1 context save & restore routines.
312*59b7c0a0SJayanth Dodderi Chidanand  *
313*59b7c0a0SJayanth Dodderi Chidanand  * Only when ERRATA_SPECULATIVE_AT=0, EL1_Context=1, for this combination,
314*59b7c0a0SJayanth Dodderi Chidanand  * SCTLR_EL1 and TCR_EL1 will be part of EL1 context structure (context_el1.h)
315*59b7c0a0SJayanth Dodderi Chidanand  * -----------------------------------------------------------------------------
316*59b7c0a0SJayanth Dodderi Chidanand  ******************************************************************************/
317*59b7c0a0SJayanth Dodderi Chidanand #define CTX_ERRATA_SPEC_AT_OFFSET	(CTX_CVE_2018_3639_OFFSET + CTX_CVE_2018_3639_END)
318*59b7c0a0SJayanth Dodderi Chidanand #if ERRATA_SPECULATIVE_AT
319*59b7c0a0SJayanth Dodderi Chidanand #define CTX_ERRATA_SPEC_AT_SCTLR_EL1	U(0x0)
320*59b7c0a0SJayanth Dodderi Chidanand #define CTX_ERRATA_SPEC_AT_TCR_EL1	U(0x8)
321*59b7c0a0SJayanth Dodderi Chidanand #define CTX_ERRATA_SPEC_AT_END		U(0x10) /* Align to the next 16 byte boundary */
322*59b7c0a0SJayanth Dodderi Chidanand #else
323*59b7c0a0SJayanth Dodderi Chidanand #define CTX_ERRATA_SPEC_AT_END		U(0x0)
324*59b7c0a0SJayanth Dodderi Chidanand #endif /* ERRATA_SPECULATIVE_AT */
325*59b7c0a0SJayanth Dodderi Chidanand 
326*59b7c0a0SJayanth Dodderi Chidanand /*******************************************************************************
3275283962eSAntonio Nino Diaz  * Registers related to ARMv8.3-PAuth.
3285283962eSAntonio Nino Diaz  ******************************************************************************/
329*59b7c0a0SJayanth Dodderi Chidanand #define CTX_PAUTH_REGS_OFFSET	(CTX_ERRATA_SPEC_AT_OFFSET + CTX_ERRATA_SPEC_AT_END)
3305283962eSAntonio Nino Diaz #if CTX_INCLUDE_PAUTH_REGS
3315283962eSAntonio Nino Diaz #define CTX_PACIAKEY_LO		U(0x0)
3325283962eSAntonio Nino Diaz #define CTX_PACIAKEY_HI		U(0x8)
3335283962eSAntonio Nino Diaz #define CTX_PACIBKEY_LO		U(0x10)
3345283962eSAntonio Nino Diaz #define CTX_PACIBKEY_HI		U(0x18)
3355283962eSAntonio Nino Diaz #define CTX_PACDAKEY_LO		U(0x20)
3365283962eSAntonio Nino Diaz #define CTX_PACDAKEY_HI		U(0x28)
3375283962eSAntonio Nino Diaz #define CTX_PACDBKEY_LO		U(0x30)
3385283962eSAntonio Nino Diaz #define CTX_PACDBKEY_HI		U(0x38)
3395283962eSAntonio Nino Diaz #define CTX_PACGAKEY_LO		U(0x40)
3405283962eSAntonio Nino Diaz #define CTX_PACGAKEY_HI		U(0x48)
341ed108b56SAlexei Fedorov #define CTX_PAUTH_REGS_END	U(0x50) /* Align to the next 16 byte boundary */
3425283962eSAntonio Nino Diaz #else
3435283962eSAntonio Nino Diaz #define CTX_PAUTH_REGS_END	U(0)
3445283962eSAntonio Nino Diaz #endif /* CTX_INCLUDE_PAUTH_REGS */
3455283962eSAntonio Nino Diaz 
346461c0a5dSElizabeth Ho /*******************************************************************************
347461c0a5dSElizabeth Ho  * Registers initialised in a per-world context.
348461c0a5dSElizabeth Ho  ******************************************************************************/
349461c0a5dSElizabeth Ho #define CTX_CPTR_EL3			U(0x0)
350461c0a5dSElizabeth Ho #define CTX_ZCR_EL3			U(0x8)
351ac4f6aafSArvind Ram Prakash #define CTX_MPAM3_EL3			U(0x10)
352ac4f6aafSArvind Ram Prakash #define CTX_PERWORLD_EL3STATE_END	U(0x18)
353461c0a5dSElizabeth Ho 
354d5dfdeb6SJulius Werner #ifndef __ASSEMBLER__
355532ed618SSoby Mathew 
356532ed618SSoby Mathew #include <stdint.h>
357532ed618SSoby Mathew 
35809d40e0eSAntonio Nino Diaz #include <lib/cassert.h>
35909d40e0eSAntonio Nino Diaz 
360532ed618SSoby Mathew /*
361532ed618SSoby Mathew  * Common constants to help define the 'cpu_context' structure and its
362532ed618SSoby Mathew  * members below.
363532ed618SSoby Mathew  */
364030567e6SVarun Wadekar #define DWORD_SHIFT		U(3)
365532ed618SSoby Mathew #define DEFINE_REG_STRUCT(name, num_regs)	\
366532ed618SSoby Mathew 	typedef struct name {			\
3672fe75a2dSZelalem 		uint64_t ctx_regs[num_regs];	\
368532ed618SSoby Mathew 	}  __aligned(16) name##_t
369532ed618SSoby Mathew 
370532ed618SSoby Mathew /* Constants to determine the size of individual context structures */
371532ed618SSoby Mathew #define CTX_GPREG_ALL		(CTX_GPREGS_END >> DWORD_SHIFT)
3722825946eSMax Shvetsov #define CTX_EL1_SYSREGS_ALL	(CTX_EL1_SYSREGS_END >> DWORD_SHIFT)
373d6af2344SJayanth Dodderi Chidanand 
374532ed618SSoby Mathew #if CTX_INCLUDE_FPREGS
375532ed618SSoby Mathew # define CTX_FPREG_ALL		(CTX_FPREGS_END >> DWORD_SHIFT)
376532ed618SSoby Mathew #endif
377532ed618SSoby Mathew #define CTX_EL3STATE_ALL	(CTX_EL3STATE_END >> DWORD_SHIFT)
378fe007b2eSDimitris Papastamos #define CTX_CVE_2018_3639_ALL	(CTX_CVE_2018_3639_END >> DWORD_SHIFT)
379*59b7c0a0SJayanth Dodderi Chidanand 
380*59b7c0a0SJayanth Dodderi Chidanand #if ERRATA_SPECULATIVE_AT
381*59b7c0a0SJayanth Dodderi Chidanand #define CTX_ERRATA_SPEC_AT_ALL	(CTX_ERRATA_SPEC_AT_END >> DWORD_SHIFT)
382*59b7c0a0SJayanth Dodderi Chidanand #endif
3835283962eSAntonio Nino Diaz #if CTX_INCLUDE_PAUTH_REGS
3845283962eSAntonio Nino Diaz # define CTX_PAUTH_REGS_ALL	(CTX_PAUTH_REGS_END >> DWORD_SHIFT)
3855283962eSAntonio Nino Diaz #endif
386532ed618SSoby Mathew 
387532ed618SSoby Mathew /*
388532ed618SSoby Mathew  * AArch64 general purpose register context structure. Usually x0-x18,
389532ed618SSoby Mathew  * lr are saved as the compiler is expected to preserve the remaining
390532ed618SSoby Mathew  * callee saved registers if used by the C runtime and the assembler
391532ed618SSoby Mathew  * does not touch the remaining. But in case of world switch during
392532ed618SSoby Mathew  * exception handling, we need to save the callee registers too.
393532ed618SSoby Mathew  */
394532ed618SSoby Mathew DEFINE_REG_STRUCT(gp_regs, CTX_GPREG_ALL);
395532ed618SSoby Mathew 
396532ed618SSoby Mathew /*
3972825946eSMax Shvetsov  * AArch64 EL1 system register context structure for preserving the
39828f39f02SMax Shvetsov  * architectural state during world switches.
399532ed618SSoby Mathew  */
4002825946eSMax Shvetsov DEFINE_REG_STRUCT(el1_sysregs, CTX_EL1_SYSREGS_ALL);
4012825946eSMax Shvetsov 
402532ed618SSoby Mathew /*
403532ed618SSoby Mathew  * AArch64 floating point register context structure for preserving
404532ed618SSoby Mathew  * the floating point state during switches from one security state to
405532ed618SSoby Mathew  * another.
406532ed618SSoby Mathew  */
407532ed618SSoby Mathew #if CTX_INCLUDE_FPREGS
408532ed618SSoby Mathew DEFINE_REG_STRUCT(fp_regs, CTX_FPREG_ALL);
409532ed618SSoby Mathew #endif
410532ed618SSoby Mathew 
411532ed618SSoby Mathew /*
412532ed618SSoby Mathew  * Miscellaneous registers used by EL3 firmware to maintain its state
413532ed618SSoby Mathew  * across exception entries and exits
414532ed618SSoby Mathew  */
415532ed618SSoby Mathew DEFINE_REG_STRUCT(el3_state, CTX_EL3STATE_ALL);
416532ed618SSoby Mathew 
417fe007b2eSDimitris Papastamos /* Function pointer used by CVE-2018-3639 dynamic mitigation */
418fe007b2eSDimitris Papastamos DEFINE_REG_STRUCT(cve_2018_3639, CTX_CVE_2018_3639_ALL);
419fe007b2eSDimitris Papastamos 
420*59b7c0a0SJayanth Dodderi Chidanand /* Registers associated to Errata_Speculative */
421*59b7c0a0SJayanth Dodderi Chidanand #if ERRATA_SPECULATIVE_AT
422*59b7c0a0SJayanth Dodderi Chidanand DEFINE_REG_STRUCT(errata_speculative_at, CTX_ERRATA_SPEC_AT_ALL);
423*59b7c0a0SJayanth Dodderi Chidanand #endif
424*59b7c0a0SJayanth Dodderi Chidanand 
4255283962eSAntonio Nino Diaz /* Registers associated to ARMv8.3-PAuth */
4265283962eSAntonio Nino Diaz #if CTX_INCLUDE_PAUTH_REGS
4275283962eSAntonio Nino Diaz DEFINE_REG_STRUCT(pauth, CTX_PAUTH_REGS_ALL);
4285283962eSAntonio Nino Diaz #endif
4295283962eSAntonio Nino Diaz 
430532ed618SSoby Mathew /*
431532ed618SSoby Mathew  * Macros to access members of any of the above structures using their
432532ed618SSoby Mathew  * offsets
433532ed618SSoby Mathew  */
4342fe75a2dSZelalem #define read_ctx_reg(ctx, offset)	((ctx)->ctx_regs[(offset) >> DWORD_SHIFT])
4352fe75a2dSZelalem #define write_ctx_reg(ctx, offset, val)	(((ctx)->ctx_regs[(offset) >> DWORD_SHIFT]) \
436ba6e5ca6SJeenu Viswambharan 					 = (uint64_t) (val))
437532ed618SSoby Mathew 
438532ed618SSoby Mathew /*
439c5ea4f8aSZelalem Aweke  * Top-level context structure which is used by EL3 firmware to preserve
440c5ea4f8aSZelalem Aweke  * the state of a core at the next lower EL in a given security state and
441c5ea4f8aSZelalem Aweke  * save enough EL3 meta data to be able to return to that EL and security
442c5ea4f8aSZelalem Aweke  * state. The context management library will be used to ensure that
443c5ea4f8aSZelalem Aweke  * SP_EL3 always points to an instance of this structure at exception
444c5ea4f8aSZelalem Aweke  * entry and exit.
445532ed618SSoby Mathew  */
446532ed618SSoby Mathew typedef struct cpu_context {
447532ed618SSoby Mathew 	gp_regs_t gpregs_ctx;
448532ed618SSoby Mathew 	el3_state_t el3state_ctx;
4492825946eSMax Shvetsov 	el1_sysregs_t el1_sysregs_ctx;
450d6af2344SJayanth Dodderi Chidanand 
451532ed618SSoby Mathew #if CTX_INCLUDE_FPREGS
452532ed618SSoby Mathew 	fp_regs_t fpregs_ctx;
453532ed618SSoby Mathew #endif
454fe007b2eSDimitris Papastamos 	cve_2018_3639_t cve_2018_3639_ctx;
455d6af2344SJayanth Dodderi Chidanand 
456*59b7c0a0SJayanth Dodderi Chidanand #if ERRATA_SPECULATIVE_AT
457*59b7c0a0SJayanth Dodderi Chidanand 	errata_speculative_at_t errata_speculative_at_ctx;
458*59b7c0a0SJayanth Dodderi Chidanand #endif
459*59b7c0a0SJayanth Dodderi Chidanand 
4605283962eSAntonio Nino Diaz #if CTX_INCLUDE_PAUTH_REGS
4615283962eSAntonio Nino Diaz 	pauth_t pauth_ctx;
4625283962eSAntonio Nino Diaz #endif
463d6af2344SJayanth Dodderi Chidanand 
464d6af2344SJayanth Dodderi Chidanand #if CTX_INCLUDE_EL2_REGS
465d6af2344SJayanth Dodderi Chidanand 	el2_sysregs_t el2_sysregs_ctx;
466d6af2344SJayanth Dodderi Chidanand #endif
467d6af2344SJayanth Dodderi Chidanand 
468532ed618SSoby Mathew } cpu_context_t;
469532ed618SSoby Mathew 
470461c0a5dSElizabeth Ho /*
471461c0a5dSElizabeth Ho  * Per-World Context.
472461c0a5dSElizabeth Ho  * It stores registers whose values can be shared across CPUs.
473461c0a5dSElizabeth Ho  */
474461c0a5dSElizabeth Ho typedef struct per_world_context {
475461c0a5dSElizabeth Ho 	uint64_t ctx_cptr_el3;
476461c0a5dSElizabeth Ho 	uint64_t ctx_zcr_el3;
477ac4f6aafSArvind Ram Prakash 	uint64_t ctx_mpam3_el3;
478461c0a5dSElizabeth Ho } per_world_context_t;
479461c0a5dSElizabeth Ho 
480461c0a5dSElizabeth Ho extern per_world_context_t per_world_context[CPU_DATA_CONTEXT_NUM];
481461c0a5dSElizabeth Ho 
482532ed618SSoby Mathew /* Macros to access members of the 'cpu_context_t' structure */
483532ed618SSoby Mathew #define get_el3state_ctx(h)	(&((cpu_context_t *) h)->el3state_ctx)
484532ed618SSoby Mathew #if CTX_INCLUDE_FPREGS
485532ed618SSoby Mathew # define get_fpregs_ctx(h)	(&((cpu_context_t *) h)->fpregs_ctx)
486532ed618SSoby Mathew #endif
4872825946eSMax Shvetsov #define get_el1_sysregs_ctx(h)	(&((cpu_context_t *) h)->el1_sysregs_ctx)
4882825946eSMax Shvetsov #if CTX_INCLUDE_EL2_REGS
4892825946eSMax Shvetsov # define get_el2_sysregs_ctx(h)	(&((cpu_context_t *) h)->el2_sysregs_ctx)
4902825946eSMax Shvetsov #endif
491532ed618SSoby Mathew #define get_gpregs_ctx(h)	(&((cpu_context_t *) h)->gpregs_ctx)
4926f03bc77SDimitris Papastamos #define get_cve_2018_3639_ctx(h)	(&((cpu_context_t *) h)->cve_2018_3639_ctx)
493*59b7c0a0SJayanth Dodderi Chidanand 
494*59b7c0a0SJayanth Dodderi Chidanand #if ERRATA_SPECULATIVE_AT
495*59b7c0a0SJayanth Dodderi Chidanand #define get_errata_speculative_at_ctx(h)	(&((cpu_context_t *) h)->errata_speculative_at_ctx)
496*59b7c0a0SJayanth Dodderi Chidanand #endif
497*59b7c0a0SJayanth Dodderi Chidanand 
4985283962eSAntonio Nino Diaz #if CTX_INCLUDE_PAUTH_REGS
4995283962eSAntonio Nino Diaz # define get_pauth_ctx(h)	(&((cpu_context_t *) h)->pauth_ctx)
5005283962eSAntonio Nino Diaz #endif
501532ed618SSoby Mathew 
502532ed618SSoby Mathew /*
503532ed618SSoby Mathew  * Compile time assertions related to the 'cpu_context' structure to
504532ed618SSoby Mathew  * ensure that the assembler and the compiler view of the offsets of
505532ed618SSoby Mathew  * the structure members is the same.
506532ed618SSoby Mathew  */
5079a90d720SElyes Haouas CASSERT(CTX_GPREGS_OFFSET == __builtin_offsetof(cpu_context_t, gpregs_ctx),
508532ed618SSoby Mathew 	assert_core_context_gp_offset_mismatch);
509d6af2344SJayanth Dodderi Chidanand 
510d6af2344SJayanth Dodderi Chidanand CASSERT(CTX_EL3STATE_OFFSET == __builtin_offsetof(cpu_context_t, el3state_ctx),
511d6af2344SJayanth Dodderi Chidanand 	assert_core_context_el3state_offset_mismatch);
512d6af2344SJayanth Dodderi Chidanand 
5139a90d720SElyes Haouas CASSERT(CTX_EL1_SYSREGS_OFFSET == __builtin_offsetof(cpu_context_t, el1_sysregs_ctx),
5142825946eSMax Shvetsov 	assert_core_context_el1_sys_offset_mismatch);
515d6af2344SJayanth Dodderi Chidanand 
516532ed618SSoby Mathew #if CTX_INCLUDE_FPREGS
5179a90d720SElyes Haouas CASSERT(CTX_FPREGS_OFFSET == __builtin_offsetof(cpu_context_t, fpregs_ctx),
518532ed618SSoby Mathew 	assert_core_context_fp_offset_mismatch);
519d6af2344SJayanth Dodderi Chidanand #endif /* CTX_INCLUDE_FPREGS */
520d6af2344SJayanth Dodderi Chidanand 
5219a90d720SElyes Haouas CASSERT(CTX_CVE_2018_3639_OFFSET == __builtin_offsetof(cpu_context_t, cve_2018_3639_ctx),
522fe007b2eSDimitris Papastamos 	assert_core_context_cve_2018_3639_offset_mismatch);
523d6af2344SJayanth Dodderi Chidanand 
524*59b7c0a0SJayanth Dodderi Chidanand #if ERRATA_SPECULATIVE_AT
525*59b7c0a0SJayanth Dodderi Chidanand CASSERT(CTX_ERRATA_SPEC_AT_OFFSET == __builtin_offsetof(cpu_context_t, errata_speculative_at_ctx),
526*59b7c0a0SJayanth Dodderi Chidanand 	assert_core_context_errata_speculative_at_offset_mismatch);
527*59b7c0a0SJayanth Dodderi Chidanand #endif
528*59b7c0a0SJayanth Dodderi Chidanand 
5295283962eSAntonio Nino Diaz #if CTX_INCLUDE_PAUTH_REGS
5309a90d720SElyes Haouas CASSERT(CTX_PAUTH_REGS_OFFSET == __builtin_offsetof(cpu_context_t, pauth_ctx),
5315283962eSAntonio Nino Diaz 	assert_core_context_pauth_offset_mismatch);
532d6af2344SJayanth Dodderi Chidanand #endif /* CTX_INCLUDE_PAUTH_REGS */
533d6af2344SJayanth Dodderi Chidanand 
534532ed618SSoby Mathew /*
535532ed618SSoby Mathew  * Helper macro to set the general purpose registers that correspond to
536532ed618SSoby Mathew  * parameters in an aapcs_64 call i.e. x0-x7
537532ed618SSoby Mathew  */
538532ed618SSoby Mathew #define set_aapcs_args0(ctx, x0)				do {	\
539532ed618SSoby Mathew 		write_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X0, x0);	\
540532ed618SSoby Mathew 	} while (0)
541532ed618SSoby Mathew #define set_aapcs_args1(ctx, x0, x1)				do {	\
542532ed618SSoby Mathew 		write_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X1, x1);	\
543532ed618SSoby Mathew 		set_aapcs_args0(ctx, x0);				\
544532ed618SSoby Mathew 	} while (0)
545532ed618SSoby Mathew #define set_aapcs_args2(ctx, x0, x1, x2)			do {	\
546532ed618SSoby Mathew 		write_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X2, x2);	\
547532ed618SSoby Mathew 		set_aapcs_args1(ctx, x0, x1);				\
548532ed618SSoby Mathew 	} while (0)
549532ed618SSoby Mathew #define set_aapcs_args3(ctx, x0, x1, x2, x3)			do {	\
550532ed618SSoby Mathew 		write_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X3, x3);	\
551532ed618SSoby Mathew 		set_aapcs_args2(ctx, x0, x1, x2);			\
552532ed618SSoby Mathew 	} while (0)
553532ed618SSoby Mathew #define set_aapcs_args4(ctx, x0, x1, x2, x3, x4)		do {	\
554532ed618SSoby Mathew 		write_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X4, x4);	\
555532ed618SSoby Mathew 		set_aapcs_args3(ctx, x0, x1, x2, x3);			\
556532ed618SSoby Mathew 	} while (0)
557532ed618SSoby Mathew #define set_aapcs_args5(ctx, x0, x1, x2, x3, x4, x5)		do {	\
558532ed618SSoby Mathew 		write_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X5, x5);	\
559532ed618SSoby Mathew 		set_aapcs_args4(ctx, x0, x1, x2, x3, x4);		\
560532ed618SSoby Mathew 	} while (0)
561532ed618SSoby Mathew #define set_aapcs_args6(ctx, x0, x1, x2, x3, x4, x5, x6)	do {	\
562532ed618SSoby Mathew 		write_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X6, x6);	\
563532ed618SSoby Mathew 		set_aapcs_args5(ctx, x0, x1, x2, x3, x4, x5);		\
564532ed618SSoby Mathew 	} while (0)
565532ed618SSoby Mathew #define set_aapcs_args7(ctx, x0, x1, x2, x3, x4, x5, x6, x7)	do {	\
566532ed618SSoby Mathew 		write_ctx_reg(get_gpregs_ctx(ctx), CTX_GPREG_X7, x7);	\
567532ed618SSoby Mathew 		set_aapcs_args6(ctx, x0, x1, x2, x3, x4, x5, x6);	\
568532ed618SSoby Mathew 	} while (0)
569532ed618SSoby Mathew 
570532ed618SSoby Mathew /*******************************************************************************
571532ed618SSoby Mathew  * Function prototypes
572532ed618SSoby Mathew  ******************************************************************************/
573532ed618SSoby Mathew #if CTX_INCLUDE_FPREGS
574532ed618SSoby Mathew void fpregs_context_save(fp_regs_t *regs);
575532ed618SSoby Mathew void fpregs_context_restore(fp_regs_t *regs);
576532ed618SSoby Mathew #endif
577532ed618SSoby Mathew 
578d5dfdeb6SJulius Werner #endif /* __ASSEMBLER__ */
579532ed618SSoby Mathew 
580a0fee747SAntonio Nino Diaz #endif /* CONTEXT_H */
581