xref: /rk3399_ARM-atf/lib/el3_runtime/aarch64/context.S (revision 3b8456bd1c9fd2303483f0675786e3fbda81a0af)
1532ed618SSoby Mathew/*
228f39f02SMax Shvetsov * Copyright (c) 2013-2020, ARM Limited and Contributors. All rights reserved.
3532ed618SSoby Mathew *
482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause
5532ed618SSoby Mathew */
6532ed618SSoby Mathew
7532ed618SSoby Mathew#include <arch.h>
8532ed618SSoby Mathew#include <asm_macros.S>
9bb9549baSJan Dabros#include <assert_macros.S>
10532ed618SSoby Mathew#include <context.h>
11*3b8456bdSManish V Badarkhe#include <el3_common_macros.S>
12532ed618SSoby Mathew
1328f39f02SMax Shvetsov#if CTX_INCLUDE_EL2_REGS
1428f39f02SMax Shvetsov	.global	el2_sysregs_context_save
1528f39f02SMax Shvetsov	.global	el2_sysregs_context_restore
1628f39f02SMax Shvetsov#endif
1728f39f02SMax Shvetsov
18532ed618SSoby Mathew	.global	el1_sysregs_context_save
19532ed618SSoby Mathew	.global	el1_sysregs_context_restore
20532ed618SSoby Mathew#if CTX_INCLUDE_FPREGS
21532ed618SSoby Mathew	.global	fpregs_context_save
22532ed618SSoby Mathew	.global	fpregs_context_restore
23532ed618SSoby Mathew#endif
24ed108b56SAlexei Fedorov	.global	save_gp_pmcr_pauth_regs
25ed108b56SAlexei Fedorov	.global	restore_gp_pmcr_pauth_regs
26*3b8456bdSManish V Badarkhe	.global save_and_update_ptw_el1_sys_regs
27532ed618SSoby Mathew	.global	el3_exit
28532ed618SSoby Mathew
2928f39f02SMax Shvetsov#if CTX_INCLUDE_EL2_REGS
3028f39f02SMax Shvetsov
3128f39f02SMax Shvetsov/* -----------------------------------------------------
3228f39f02SMax Shvetsov * The following function strictly follows the AArch64
3328f39f02SMax Shvetsov * PCS to use x9-x17 (temporary caller-saved registers)
342825946eSMax Shvetsov * to save EL2 system register context. It assumes that
352825946eSMax Shvetsov * 'x0' is pointing to a 'el2_sys_regs' structure where
3628f39f02SMax Shvetsov * the register context will be saved.
372825946eSMax Shvetsov *
382825946eSMax Shvetsov * The following registers are not added.
392825946eSMax Shvetsov * AMEVCNTVOFF0<n>_EL2
402825946eSMax Shvetsov * AMEVCNTVOFF1<n>_EL2
412825946eSMax Shvetsov * ICH_AP0R<n>_EL2
422825946eSMax Shvetsov * ICH_AP1R<n>_EL2
432825946eSMax Shvetsov * ICH_LR<n>_EL2
4428f39f02SMax Shvetsov * -----------------------------------------------------
4528f39f02SMax Shvetsov */
462825946eSMax Shvetsov
4728f39f02SMax Shvetsovfunc el2_sysregs_context_save
4828f39f02SMax Shvetsov	mrs	x9, actlr_el2
492825946eSMax Shvetsov	mrs	x10, afsr0_el2
502825946eSMax Shvetsov	stp	x9, x10, [x0, #CTX_ACTLR_EL2]
5128f39f02SMax Shvetsov
522825946eSMax Shvetsov	mrs	x11, afsr1_el2
532825946eSMax Shvetsov	mrs	x12, amair_el2
542825946eSMax Shvetsov	stp	x11, x12, [x0, #CTX_AFSR1_EL2]
5528f39f02SMax Shvetsov
562825946eSMax Shvetsov	mrs	x13, cnthctl_el2
572825946eSMax Shvetsov	mrs	x14, cnthp_ctl_el2
582825946eSMax Shvetsov	stp	x13, x14, [x0, #CTX_CNTHCTL_EL2]
5928f39f02SMax Shvetsov
602825946eSMax Shvetsov	mrs	x15, cnthp_cval_el2
612825946eSMax Shvetsov	mrs	x16, cnthp_tval_el2
622825946eSMax Shvetsov	stp	x15, x16, [x0, #CTX_CNTHP_CVAL_EL2]
6328f39f02SMax Shvetsov
642825946eSMax Shvetsov	mrs	x17, cntvoff_el2
6528f39f02SMax Shvetsov	mrs	x9, cptr_el2
662825946eSMax Shvetsov	stp	x17, x9, [x0, #CTX_CNTVOFF_EL2]
6728f39f02SMax Shvetsov
682825946eSMax Shvetsov	mrs	x10, dbgvcr32_el2
692825946eSMax Shvetsov	mrs	x11, elr_el2
702825946eSMax Shvetsov	stp	x10, x11, [x0, #CTX_DBGVCR32_EL2]
7128f39f02SMax Shvetsov
722825946eSMax Shvetsov	mrs	x14, esr_el2
732825946eSMax Shvetsov	mrs	x15, far_el2
742825946eSMax Shvetsov	stp	x14, x15, [x0, #CTX_ESR_EL2]
7528f39f02SMax Shvetsov
7630ee3755SMax Shvetsov	mrs	x16, hacr_el2
7730ee3755SMax Shvetsov	mrs	x17, hcr_el2
7830ee3755SMax Shvetsov	stp	x16, x17, [x0, #CTX_HACR_EL2]
7928f39f02SMax Shvetsov
8030ee3755SMax Shvetsov	mrs	x9, hpfar_el2
8130ee3755SMax Shvetsov	mrs	x10, hstr_el2
8230ee3755SMax Shvetsov	stp	x9, x10, [x0, #CTX_HPFAR_EL2]
8328f39f02SMax Shvetsov
8430ee3755SMax Shvetsov	mrs	x11, ICC_SRE_EL2
8530ee3755SMax Shvetsov	mrs	x12, ICH_HCR_EL2
8630ee3755SMax Shvetsov	stp	x11, x12, [x0, #CTX_ICC_SRE_EL2]
8728f39f02SMax Shvetsov
8830ee3755SMax Shvetsov	mrs	x13, ICH_VMCR_EL2
8930ee3755SMax Shvetsov	mrs	x14, mair_el2
9030ee3755SMax Shvetsov	stp	x13, x14, [x0, #CTX_ICH_VMCR_EL2]
9128f39f02SMax Shvetsov
9230ee3755SMax Shvetsov	mrs	x15, mdcr_el2
9330ee3755SMax Shvetsov	mrs	x16, PMSCR_EL2
9430ee3755SMax Shvetsov	stp	x15, x16, [x0, #CTX_MDCR_EL2]
9528f39f02SMax Shvetsov
9630ee3755SMax Shvetsov	mrs	x17, sctlr_el2
9730ee3755SMax Shvetsov	mrs	x9, spsr_el2
9830ee3755SMax Shvetsov	stp	x17, x9, [x0, #CTX_SCTLR_EL2]
9928f39f02SMax Shvetsov
10030ee3755SMax Shvetsov	mrs	x10, sp_el2
10130ee3755SMax Shvetsov	mrs	x11, tcr_el2
10230ee3755SMax Shvetsov	stp	x10, x11, [x0, #CTX_SP_EL2]
10328f39f02SMax Shvetsov
10430ee3755SMax Shvetsov	mrs	x12, tpidr_el2
10530ee3755SMax Shvetsov	mrs	x13, ttbr0_el2
10630ee3755SMax Shvetsov	stp	x12, x13, [x0, #CTX_TPIDR_EL2]
10728f39f02SMax Shvetsov
10830ee3755SMax Shvetsov	mrs	x14, vbar_el2
10930ee3755SMax Shvetsov	mrs	x15, vmpidr_el2
11030ee3755SMax Shvetsov	stp	x14, x15, [x0, #CTX_VBAR_EL2]
11128f39f02SMax Shvetsov
11230ee3755SMax Shvetsov	mrs	x16, vpidr_el2
11330ee3755SMax Shvetsov	mrs	x17, vtcr_el2
11430ee3755SMax Shvetsov	stp	x16, x17, [x0, #CTX_VPIDR_EL2]
11528f39f02SMax Shvetsov
11630ee3755SMax Shvetsov	mrs	x9, vttbr_el2
11730ee3755SMax Shvetsov	str	x9, [x0, #CTX_VTTBR_EL2]
11828f39f02SMax Shvetsov
1192825946eSMax Shvetsov#if CTX_INCLUDE_MTE_REGS
12030ee3755SMax Shvetsov	mrs	x10, TFSR_EL2
12130ee3755SMax Shvetsov	str	x10, [x0, #CTX_TFSR_EL2]
1222825946eSMax Shvetsov#endif
12328f39f02SMax Shvetsov
1242825946eSMax Shvetsov#if ENABLE_MPAM_FOR_LOWER_ELS
1252825946eSMax Shvetsov	mrs	x9, MPAM2_EL2
1262825946eSMax Shvetsov	mrs	x10, MPAMHCR_EL2
1272825946eSMax Shvetsov	stp	x9, x10, [x0, #CTX_MPAM2_EL2]
1282825946eSMax Shvetsov
1292825946eSMax Shvetsov	mrs	x11, MPAMVPM0_EL2
1302825946eSMax Shvetsov	mrs	x12, MPAMVPM1_EL2
1312825946eSMax Shvetsov	stp	x11, x12, [x0, #CTX_MPAMVPM0_EL2]
1322825946eSMax Shvetsov
1332825946eSMax Shvetsov	mrs	x13, MPAMVPM2_EL2
1342825946eSMax Shvetsov	mrs	x14, MPAMVPM3_EL2
1352825946eSMax Shvetsov	stp	x13, x14, [x0, #CTX_MPAMVPM2_EL2]
1362825946eSMax Shvetsov
1372825946eSMax Shvetsov	mrs	x15, MPAMVPM4_EL2
1382825946eSMax Shvetsov	mrs	x16, MPAMVPM5_EL2
1392825946eSMax Shvetsov	stp	x15, x16, [x0, #CTX_MPAMVPM4_EL2]
1402825946eSMax Shvetsov
1412825946eSMax Shvetsov	mrs	x17, MPAMVPM6_EL2
1422825946eSMax Shvetsov	mrs	x9, MPAMVPM7_EL2
1432825946eSMax Shvetsov	stp	x17, x9, [x0, #CTX_MPAMVPM6_EL2]
1442825946eSMax Shvetsov
1452825946eSMax Shvetsov	mrs	x10, MPAMVPMV_EL2
1462825946eSMax Shvetsov	str	x10, [x0, #CTX_MPAMVPMV_EL2]
1472825946eSMax Shvetsov#endif
1482825946eSMax Shvetsov
1492825946eSMax Shvetsov
1502825946eSMax Shvetsov#if ARM_ARCH_AT_LEAST(8, 6)
1512825946eSMax Shvetsov	mrs	x11, HAFGRTR_EL2
1522825946eSMax Shvetsov	mrs	x12, HDFGRTR_EL2
1532825946eSMax Shvetsov	stp	x11, x12, [x0, #CTX_HAFGRTR_EL2]
1542825946eSMax Shvetsov
1552825946eSMax Shvetsov	mrs	x13, HDFGWTR_EL2
1562825946eSMax Shvetsov	mrs	x14, HFGITR_EL2
1572825946eSMax Shvetsov	stp	x13, x14, [x0, #CTX_HDFGWTR_EL2]
1582825946eSMax Shvetsov
1592825946eSMax Shvetsov	mrs	x15, HFGRTR_EL2
1602825946eSMax Shvetsov	mrs	x16, HFGWTR_EL2
1612825946eSMax Shvetsov	stp	x15, x16, [x0, #CTX_HFGRTR_EL2]
1622825946eSMax Shvetsov
1632825946eSMax Shvetsov	mrs	x17, CNTPOFF_EL2
1642825946eSMax Shvetsov	str	x17, [x0, #CTX_CNTPOFF_EL2]
1652825946eSMax Shvetsov#endif
1662825946eSMax Shvetsov
1672825946eSMax Shvetsov#if ARM_ARCH_AT_LEAST(8, 4)
1682825946eSMax Shvetsov	mrs	x9, cnthps_ctl_el2
1692825946eSMax Shvetsov	mrs	x10, cnthps_cval_el2
1702825946eSMax Shvetsov	stp	x9, x10, [x0, #CTX_CNTHPS_CTL_EL2]
1712825946eSMax Shvetsov
1722825946eSMax Shvetsov	mrs	x11, cnthps_tval_el2
1732825946eSMax Shvetsov	mrs	x12, cnthvs_ctl_el2
1742825946eSMax Shvetsov	stp	x11, x12, [x0, #CTX_CNTHPS_TVAL_EL2]
1752825946eSMax Shvetsov
1762825946eSMax Shvetsov	mrs	x13, cnthvs_cval_el2
1772825946eSMax Shvetsov	mrs	x14, cnthvs_tval_el2
1782825946eSMax Shvetsov	stp	x13, x14, [x0, #CTX_CNTHVS_CVAL_EL2]
1792825946eSMax Shvetsov
1802825946eSMax Shvetsov	mrs	x15, cnthv_ctl_el2
1812825946eSMax Shvetsov	mrs	x16, cnthv_cval_el2
1822825946eSMax Shvetsov	stp	x15, x16, [x0, #CTX_CNTHV_CTL_EL2]
1832825946eSMax Shvetsov
1842825946eSMax Shvetsov	mrs	x17, cnthv_tval_el2
1852825946eSMax Shvetsov	mrs	x9, contextidr_el2
1862825946eSMax Shvetsov	stp	x17, x9, [x0, #CTX_CNTHV_TVAL_EL2]
1872825946eSMax Shvetsov
1882825946eSMax Shvetsov	mrs	x10, sder32_el2
1892825946eSMax Shvetsov	str	x10, [x0, #CTX_SDER32_EL2]
1902825946eSMax Shvetsov
1912825946eSMax Shvetsov	mrs	x11, ttbr1_el2
1922825946eSMax Shvetsov	str	x11, [x0, #CTX_TTBR1_EL2]
1932825946eSMax Shvetsov
1942825946eSMax Shvetsov	mrs	x12, vdisr_el2
1952825946eSMax Shvetsov	str	x12, [x0, #CTX_VDISR_EL2]
1962825946eSMax Shvetsov
1972825946eSMax Shvetsov	mrs	x13, vncr_el2
1982825946eSMax Shvetsov	str	x13, [x0, #CTX_VNCR_EL2]
1992825946eSMax Shvetsov
2002825946eSMax Shvetsov	mrs	x14, vsesr_el2
2012825946eSMax Shvetsov	str	x14, [x0, #CTX_VSESR_EL2]
2022825946eSMax Shvetsov
2032825946eSMax Shvetsov	mrs	x15, vstcr_el2
2042825946eSMax Shvetsov	str	x15, [x0, #CTX_VSTCR_EL2]
2052825946eSMax Shvetsov
2062825946eSMax Shvetsov	mrs	x16, vsttbr_el2
2072825946eSMax Shvetsov	str	x16, [x0, #CTX_VSTTBR_EL2]
2087f164a83SOlivier Deprez
2097f164a83SOlivier Deprez	mrs	x17, TRFCR_EL2
2107f164a83SOlivier Deprez	str	x17, [x0, #CTX_TRFCR_EL2]
2112825946eSMax Shvetsov#endif
2122825946eSMax Shvetsov
2132825946eSMax Shvetsov#if ARM_ARCH_AT_LEAST(8, 5)
2147f164a83SOlivier Deprez	mrs	x9, scxtnum_el2
2157f164a83SOlivier Deprez	str	x9, [x0, #CTX_SCXTNUM_EL2]
2162825946eSMax Shvetsov#endif
21728f39f02SMax Shvetsov
21828f39f02SMax Shvetsov	ret
21928f39f02SMax Shvetsovendfunc el2_sysregs_context_save
22028f39f02SMax Shvetsov
22128f39f02SMax Shvetsov/* -----------------------------------------------------
22228f39f02SMax Shvetsov * The following function strictly follows the AArch64
22328f39f02SMax Shvetsov * PCS to use x9-x17 (temporary caller-saved registers)
2242825946eSMax Shvetsov * to restore EL2 system register context.  It assumes
2252825946eSMax Shvetsov * that 'x0' is pointing to a 'el2_sys_regs' structure
22628f39f02SMax Shvetsov * from where the register context will be restored
2272825946eSMax Shvetsov
2282825946eSMax Shvetsov * The following registers are not restored
2292825946eSMax Shvetsov * AMEVCNTVOFF0<n>_EL2
2302825946eSMax Shvetsov * AMEVCNTVOFF1<n>_EL2
2312825946eSMax Shvetsov * ICH_AP0R<n>_EL2
2322825946eSMax Shvetsov * ICH_AP1R<n>_EL2
2332825946eSMax Shvetsov * ICH_LR<n>_EL2
23428f39f02SMax Shvetsov * -----------------------------------------------------
23528f39f02SMax Shvetsov */
23628f39f02SMax Shvetsovfunc el2_sysregs_context_restore
23728f39f02SMax Shvetsov
2382825946eSMax Shvetsov	ldp	x9, x10, [x0, #CTX_ACTLR_EL2]
23928f39f02SMax Shvetsov	msr	actlr_el2, x9
2402825946eSMax Shvetsov	msr	afsr0_el2, x10
24128f39f02SMax Shvetsov
2422825946eSMax Shvetsov	ldp	x11, x12, [x0, #CTX_AFSR1_EL2]
2432825946eSMax Shvetsov	msr	afsr1_el2, x11
2442825946eSMax Shvetsov	msr	amair_el2, x12
24528f39f02SMax Shvetsov
2462825946eSMax Shvetsov	ldp	x13, x14, [x0, #CTX_CNTHCTL_EL2]
2472825946eSMax Shvetsov	msr	cnthctl_el2, x13
2482825946eSMax Shvetsov	msr	cnthp_ctl_el2, x14
24928f39f02SMax Shvetsov
2502825946eSMax Shvetsov	ldp	x15, x16, [x0, #CTX_CNTHP_CVAL_EL2]
2512825946eSMax Shvetsov	msr	cnthp_cval_el2, x15
2522825946eSMax Shvetsov	msr	cnthp_tval_el2, x16
25328f39f02SMax Shvetsov
2542825946eSMax Shvetsov	ldp	x17, x9, [x0, #CTX_CNTVOFF_EL2]
2552825946eSMax Shvetsov	msr	cntvoff_el2, x17
25628f39f02SMax Shvetsov	msr	cptr_el2, x9
25728f39f02SMax Shvetsov
2582825946eSMax Shvetsov	ldp	x10, x11, [x0, #CTX_DBGVCR32_EL2]
2592825946eSMax Shvetsov	msr	dbgvcr32_el2, x10
2602825946eSMax Shvetsov	msr	elr_el2, x11
26128f39f02SMax Shvetsov
2622825946eSMax Shvetsov	ldp	x14, x15, [x0, #CTX_ESR_EL2]
2632825946eSMax Shvetsov	msr	esr_el2, x14
2642825946eSMax Shvetsov	msr	far_el2, x15
26528f39f02SMax Shvetsov
26630ee3755SMax Shvetsov	ldp	x16, x17, [x0, #CTX_HACR_EL2]
26730ee3755SMax Shvetsov	msr	hacr_el2, x16
26830ee3755SMax Shvetsov	msr	hcr_el2, x17
26928f39f02SMax Shvetsov
27030ee3755SMax Shvetsov	ldp	x9, x10, [x0, #CTX_HPFAR_EL2]
27130ee3755SMax Shvetsov	msr	hpfar_el2, x9
27230ee3755SMax Shvetsov	msr	hstr_el2, x10
27328f39f02SMax Shvetsov
27430ee3755SMax Shvetsov	ldp	x11, x12, [x0, #CTX_ICC_SRE_EL2]
27530ee3755SMax Shvetsov	msr	ICC_SRE_EL2, x11
27630ee3755SMax Shvetsov	msr	ICH_HCR_EL2, x12
27728f39f02SMax Shvetsov
27830ee3755SMax Shvetsov	ldp	x13, x14, [x0, #CTX_ICH_VMCR_EL2]
27930ee3755SMax Shvetsov	msr	ICH_VMCR_EL2, x13
28030ee3755SMax Shvetsov	msr	mair_el2, x14
28128f39f02SMax Shvetsov
28230ee3755SMax Shvetsov	ldp	x15, x16, [x0, #CTX_MDCR_EL2]
28330ee3755SMax Shvetsov	msr	mdcr_el2, x15
28430ee3755SMax Shvetsov	msr	PMSCR_EL2, x16
28528f39f02SMax Shvetsov
286fb2072b0SManish V Badarkhe	ldp	x17, x9, [x0, #CTX_SCTLR_EL2]
287fb2072b0SManish V Badarkhe	msr	sctlr_el2, x17
288fb2072b0SManish V Badarkhe	msr	spsr_el2, x9
28928f39f02SMax Shvetsov
290fb2072b0SManish V Badarkhe	ldp	x10, x11, [x0, #CTX_SP_EL2]
291fb2072b0SManish V Badarkhe	msr	sp_el2, x10
292fb2072b0SManish V Badarkhe	msr	tcr_el2, x11
29328f39f02SMax Shvetsov
294fb2072b0SManish V Badarkhe	ldp	x12, x13, [x0, #CTX_TPIDR_EL2]
295fb2072b0SManish V Badarkhe	msr	tpidr_el2, x12
296fb2072b0SManish V Badarkhe	msr	ttbr0_el2, x13
29728f39f02SMax Shvetsov
298fb2072b0SManish V Badarkhe	ldp	x13, x14, [x0, #CTX_VBAR_EL2]
299fb2072b0SManish V Badarkhe	msr	vbar_el2, x13
300fb2072b0SManish V Badarkhe	msr	vmpidr_el2, x14
30128f39f02SMax Shvetsov
302fb2072b0SManish V Badarkhe	ldp	x15, x16, [x0, #CTX_VPIDR_EL2]
303fb2072b0SManish V Badarkhe	msr	vpidr_el2, x15
304fb2072b0SManish V Badarkhe	msr	vtcr_el2, x16
305fb2072b0SManish V Badarkhe
306fb2072b0SManish V Badarkhe	ldr	x17, [x0, #CTX_VTTBR_EL2]
307fb2072b0SManish V Badarkhe	msr	vttbr_el2, x17
30828f39f02SMax Shvetsov
3092825946eSMax Shvetsov#if CTX_INCLUDE_MTE_REGS
310fb2072b0SManish V Badarkhe	ldr	x9, [x0, #CTX_TFSR_EL2]
311fb2072b0SManish V Badarkhe	msr	TFSR_EL2, x9
3122825946eSMax Shvetsov#endif
31328f39f02SMax Shvetsov
3142825946eSMax Shvetsov#if ENABLE_MPAM_FOR_LOWER_ELS
315fb2072b0SManish V Badarkhe	ldp	x10, x11, [x0, #CTX_MPAM2_EL2]
316fb2072b0SManish V Badarkhe	msr	MPAM2_EL2, x10
317fb2072b0SManish V Badarkhe	msr	MPAMHCR_EL2, x11
3182825946eSMax Shvetsov
319fb2072b0SManish V Badarkhe	ldp	x12, x13, [x0, #CTX_MPAMVPM0_EL2]
320fb2072b0SManish V Badarkhe	msr	MPAMVPM0_EL2, x12
321fb2072b0SManish V Badarkhe	msr	MPAMVPM1_EL2, x13
3222825946eSMax Shvetsov
323fb2072b0SManish V Badarkhe	ldp	x14, x15, [x0, #CTX_MPAMVPM2_EL2]
324fb2072b0SManish V Badarkhe	msr	MPAMVPM2_EL2, x14
325fb2072b0SManish V Badarkhe	msr	MPAMVPM3_EL2, x15
3262825946eSMax Shvetsov
327fb2072b0SManish V Badarkhe	ldp	x16, x17, [x0, #CTX_MPAMVPM4_EL2]
328fb2072b0SManish V Badarkhe	msr	MPAMVPM4_EL2, x16
329fb2072b0SManish V Badarkhe	msr	MPAMVPM5_EL2, x17
3302825946eSMax Shvetsov
331fb2072b0SManish V Badarkhe	ldp	x9, x10, [x0, #CTX_MPAMVPM6_EL2]
332fb2072b0SManish V Badarkhe	msr	MPAMVPM6_EL2, x9
333fb2072b0SManish V Badarkhe	msr	MPAMVPM7_EL2, x10
3342825946eSMax Shvetsov
335fb2072b0SManish V Badarkhe	ldr	x11, [x0, #CTX_MPAMVPMV_EL2]
336fb2072b0SManish V Badarkhe	msr	MPAMVPMV_EL2, x11
3372825946eSMax Shvetsov#endif
3382825946eSMax Shvetsov
3392825946eSMax Shvetsov#if ARM_ARCH_AT_LEAST(8, 6)
340fb2072b0SManish V Badarkhe	ldp	x12, x13, [x0, #CTX_HAFGRTR_EL2]
341fb2072b0SManish V Badarkhe	msr	HAFGRTR_EL2, x12
342fb2072b0SManish V Badarkhe	msr	HDFGRTR_EL2, x13
3432825946eSMax Shvetsov
344fb2072b0SManish V Badarkhe	ldp	x14, x15, [x0, #CTX_HDFGWTR_EL2]
345fb2072b0SManish V Badarkhe	msr	HDFGWTR_EL2, x14
346fb2072b0SManish V Badarkhe	msr	HFGITR_EL2, x15
3472825946eSMax Shvetsov
348fb2072b0SManish V Badarkhe	ldp	x16, x17, [x0, #CTX_HFGRTR_EL2]
349fb2072b0SManish V Badarkhe	msr	HFGRTR_EL2, x16
350fb2072b0SManish V Badarkhe	msr	HFGWTR_EL2, x17
3512825946eSMax Shvetsov
352fb2072b0SManish V Badarkhe	ldr	x9, [x0, #CTX_CNTPOFF_EL2]
353fb2072b0SManish V Badarkhe	msr	CNTPOFF_EL2, x9
3542825946eSMax Shvetsov#endif
3552825946eSMax Shvetsov
3562825946eSMax Shvetsov#if ARM_ARCH_AT_LEAST(8, 4)
357fb2072b0SManish V Badarkhe	ldp	x10, x11, [x0, #CTX_CNTHPS_CTL_EL2]
358fb2072b0SManish V Badarkhe	msr	cnthps_ctl_el2, x10
359fb2072b0SManish V Badarkhe	msr	cnthps_cval_el2, x11
3602825946eSMax Shvetsov
361fb2072b0SManish V Badarkhe	ldp	x12, x13, [x0, #CTX_CNTHPS_TVAL_EL2]
362fb2072b0SManish V Badarkhe	msr	cnthps_tval_el2, x12
363fb2072b0SManish V Badarkhe	msr	cnthvs_ctl_el2, x13
3642825946eSMax Shvetsov
365fb2072b0SManish V Badarkhe	ldp	x14, x15, [x0, #CTX_CNTHVS_CVAL_EL2]
366fb2072b0SManish V Badarkhe	msr	cnthvs_cval_el2, x14
367fb2072b0SManish V Badarkhe	msr	cnthvs_tval_el2, x15
3682825946eSMax Shvetsov
369fb2072b0SManish V Badarkhe	ldp	x16, x17, [x0, #CTX_CNTHV_CTL_EL2]
370fb2072b0SManish V Badarkhe	msr	cnthv_ctl_el2, x16
371fb2072b0SManish V Badarkhe	msr	cnthv_cval_el2, x17
3722825946eSMax Shvetsov
373fb2072b0SManish V Badarkhe	ldp	x9, x10, [x0, #CTX_CNTHV_TVAL_EL2]
374fb2072b0SManish V Badarkhe	msr	cnthv_tval_el2, x9
375fb2072b0SManish V Badarkhe	msr	contextidr_el2, x10
3762825946eSMax Shvetsov
377fb2072b0SManish V Badarkhe	ldr	x11, [x0, #CTX_SDER32_EL2]
378fb2072b0SManish V Badarkhe	msr	sder32_el2, x11
3792825946eSMax Shvetsov
380fb2072b0SManish V Badarkhe	ldr	x12, [x0, #CTX_TTBR1_EL2]
381fb2072b0SManish V Badarkhe	msr	ttbr1_el2, x12
3822825946eSMax Shvetsov
383fb2072b0SManish V Badarkhe	ldr	x13, [x0, #CTX_VDISR_EL2]
384fb2072b0SManish V Badarkhe	msr	vdisr_el2, x13
3852825946eSMax Shvetsov
386fb2072b0SManish V Badarkhe	ldr	x14, [x0, #CTX_VNCR_EL2]
387fb2072b0SManish V Badarkhe	msr	vncr_el2, x14
3882825946eSMax Shvetsov
389fb2072b0SManish V Badarkhe	ldr	x15, [x0, #CTX_VSESR_EL2]
390fb2072b0SManish V Badarkhe	msr	vsesr_el2, x15
3912825946eSMax Shvetsov
392fb2072b0SManish V Badarkhe	ldr	x16, [x0, #CTX_VSTCR_EL2]
393fb2072b0SManish V Badarkhe	msr	vstcr_el2, x16
3942825946eSMax Shvetsov
395fb2072b0SManish V Badarkhe	ldr	x17, [x0, #CTX_VSTTBR_EL2]
396fb2072b0SManish V Badarkhe	msr	vsttbr_el2, x17
3977f164a83SOlivier Deprez
398fb2072b0SManish V Badarkhe	ldr	x9, [x0, #CTX_TRFCR_EL2]
399fb2072b0SManish V Badarkhe	msr	TRFCR_EL2, x9
4002825946eSMax Shvetsov#endif
4012825946eSMax Shvetsov
4022825946eSMax Shvetsov#if ARM_ARCH_AT_LEAST(8, 5)
403fb2072b0SManish V Badarkhe	ldr	x10, [x0, #CTX_SCXTNUM_EL2]
404fb2072b0SManish V Badarkhe	msr	scxtnum_el2, x10
4052825946eSMax Shvetsov#endif
40628f39f02SMax Shvetsov
40728f39f02SMax Shvetsov	ret
40828f39f02SMax Shvetsovendfunc el2_sysregs_context_restore
40928f39f02SMax Shvetsov
41028f39f02SMax Shvetsov#endif /* CTX_INCLUDE_EL2_REGS */
41128f39f02SMax Shvetsov
412ed108b56SAlexei Fedorov/* ------------------------------------------------------------------
413ed108b56SAlexei Fedorov * The following function strictly follows the AArch64 PCS to use
414ed108b56SAlexei Fedorov * x9-x17 (temporary caller-saved registers) to save EL1 system
415ed108b56SAlexei Fedorov * register context. It assumes that 'x0' is pointing to a
416ed108b56SAlexei Fedorov * 'el1_sys_regs' structure where the register context will be saved.
417ed108b56SAlexei Fedorov * ------------------------------------------------------------------
418532ed618SSoby Mathew */
419532ed618SSoby Mathewfunc el1_sysregs_context_save
420532ed618SSoby Mathew
421532ed618SSoby Mathew	mrs	x9, spsr_el1
422532ed618SSoby Mathew	mrs	x10, elr_el1
423532ed618SSoby Mathew	stp	x9, x10, [x0, #CTX_SPSR_EL1]
424532ed618SSoby Mathew
425*3b8456bdSManish V Badarkhe#if !ERRATA_SPECULATIVE_AT
426532ed618SSoby Mathew	mrs	x15, sctlr_el1
427cb55615cSManish V Badarkhe	mrs	x16, tcr_el1
428532ed618SSoby Mathew	stp	x15, x16, [x0, #CTX_SCTLR_EL1]
429*3b8456bdSManish V Badarkhe#endif
430532ed618SSoby Mathew
431532ed618SSoby Mathew	mrs	x17, cpacr_el1
432532ed618SSoby Mathew	mrs	x9, csselr_el1
433532ed618SSoby Mathew	stp	x17, x9, [x0, #CTX_CPACR_EL1]
434532ed618SSoby Mathew
435532ed618SSoby Mathew	mrs	x10, sp_el1
436532ed618SSoby Mathew	mrs	x11, esr_el1
437532ed618SSoby Mathew	stp	x10, x11, [x0, #CTX_SP_EL1]
438532ed618SSoby Mathew
439532ed618SSoby Mathew	mrs	x12, ttbr0_el1
440532ed618SSoby Mathew	mrs	x13, ttbr1_el1
441532ed618SSoby Mathew	stp	x12, x13, [x0, #CTX_TTBR0_EL1]
442532ed618SSoby Mathew
443532ed618SSoby Mathew	mrs	x14, mair_el1
444532ed618SSoby Mathew	mrs	x15, amair_el1
445532ed618SSoby Mathew	stp	x14, x15, [x0, #CTX_MAIR_EL1]
446532ed618SSoby Mathew
447cb55615cSManish V Badarkhe	mrs	x16, actlr_el1
448532ed618SSoby Mathew	mrs	x17, tpidr_el1
449cb55615cSManish V Badarkhe	stp	x16, x17, [x0, #CTX_ACTLR_EL1]
450532ed618SSoby Mathew
451532ed618SSoby Mathew	mrs	x9, tpidr_el0
452532ed618SSoby Mathew	mrs	x10, tpidrro_el0
453532ed618SSoby Mathew	stp	x9, x10, [x0, #CTX_TPIDR_EL0]
454532ed618SSoby Mathew
455532ed618SSoby Mathew	mrs	x13, par_el1
456532ed618SSoby Mathew	mrs	x14, far_el1
457532ed618SSoby Mathew	stp	x13, x14, [x0, #CTX_PAR_EL1]
458532ed618SSoby Mathew
459532ed618SSoby Mathew	mrs	x15, afsr0_el1
460532ed618SSoby Mathew	mrs	x16, afsr1_el1
461532ed618SSoby Mathew	stp	x15, x16, [x0, #CTX_AFSR0_EL1]
462532ed618SSoby Mathew
463532ed618SSoby Mathew	mrs	x17, contextidr_el1
464532ed618SSoby Mathew	mrs	x9, vbar_el1
465532ed618SSoby Mathew	stp	x17, x9, [x0, #CTX_CONTEXTIDR_EL1]
466532ed618SSoby Mathew
467532ed618SSoby Mathew	/* Save AArch32 system registers if the build has instructed so */
468532ed618SSoby Mathew#if CTX_INCLUDE_AARCH32_REGS
469532ed618SSoby Mathew	mrs	x11, spsr_abt
470532ed618SSoby Mathew	mrs	x12, spsr_und
471532ed618SSoby Mathew	stp	x11, x12, [x0, #CTX_SPSR_ABT]
472532ed618SSoby Mathew
473532ed618SSoby Mathew	mrs	x13, spsr_irq
474532ed618SSoby Mathew	mrs	x14, spsr_fiq
475532ed618SSoby Mathew	stp	x13, x14, [x0, #CTX_SPSR_IRQ]
476532ed618SSoby Mathew
477532ed618SSoby Mathew	mrs	x15, dacr32_el2
478532ed618SSoby Mathew	mrs	x16, ifsr32_el2
479532ed618SSoby Mathew	stp	x15, x16, [x0, #CTX_DACR32_EL2]
480532ed618SSoby Mathew#endif
481532ed618SSoby Mathew
482532ed618SSoby Mathew	/* Save NS timer registers if the build has instructed so */
483532ed618SSoby Mathew#if NS_TIMER_SWITCH
484532ed618SSoby Mathew	mrs	x10, cntp_ctl_el0
485532ed618SSoby Mathew	mrs	x11, cntp_cval_el0
486532ed618SSoby Mathew	stp	x10, x11, [x0, #CTX_CNTP_CTL_EL0]
487532ed618SSoby Mathew
488532ed618SSoby Mathew	mrs	x12, cntv_ctl_el0
489532ed618SSoby Mathew	mrs	x13, cntv_cval_el0
490532ed618SSoby Mathew	stp	x12, x13, [x0, #CTX_CNTV_CTL_EL0]
491532ed618SSoby Mathew
492532ed618SSoby Mathew	mrs	x14, cntkctl_el1
493532ed618SSoby Mathew	str	x14, [x0, #CTX_CNTKCTL_EL1]
494532ed618SSoby Mathew#endif
495532ed618SSoby Mathew
4969dd94382SJustin Chadwell	/* Save MTE system registers if the build has instructed so */
4979dd94382SJustin Chadwell#if CTX_INCLUDE_MTE_REGS
4989dd94382SJustin Chadwell	mrs	x15, TFSRE0_EL1
4999dd94382SJustin Chadwell	mrs	x16, TFSR_EL1
5009dd94382SJustin Chadwell	stp	x15, x16, [x0, #CTX_TFSRE0_EL1]
5019dd94382SJustin Chadwell
5029dd94382SJustin Chadwell	mrs	x9, RGSR_EL1
5039dd94382SJustin Chadwell	mrs	x10, GCR_EL1
5049dd94382SJustin Chadwell	stp	x9, x10, [x0, #CTX_RGSR_EL1]
5059dd94382SJustin Chadwell#endif
5069dd94382SJustin Chadwell
507532ed618SSoby Mathew	ret
508532ed618SSoby Mathewendfunc el1_sysregs_context_save
509532ed618SSoby Mathew
510ed108b56SAlexei Fedorov/* ------------------------------------------------------------------
511ed108b56SAlexei Fedorov * The following function strictly follows the AArch64 PCS to use
512ed108b56SAlexei Fedorov * x9-x17 (temporary caller-saved registers) to restore EL1 system
513ed108b56SAlexei Fedorov * register context.  It assumes that 'x0' is pointing to a
514ed108b56SAlexei Fedorov * 'el1_sys_regs' structure from where the register context will be
515ed108b56SAlexei Fedorov * restored
516ed108b56SAlexei Fedorov * ------------------------------------------------------------------
517532ed618SSoby Mathew */
518532ed618SSoby Mathewfunc el1_sysregs_context_restore
519532ed618SSoby Mathew
520532ed618SSoby Mathew	ldp	x9, x10, [x0, #CTX_SPSR_EL1]
521532ed618SSoby Mathew	msr	spsr_el1, x9
522532ed618SSoby Mathew	msr	elr_el1, x10
523532ed618SSoby Mathew
524*3b8456bdSManish V Badarkhe#if !ERRATA_SPECULATIVE_AT
525fb2072b0SManish V Badarkhe	ldp	x15, x16, [x0, #CTX_SCTLR_EL1]
526fb2072b0SManish V Badarkhe	msr	sctlr_el1, x15
527cb55615cSManish V Badarkhe	msr	tcr_el1, x16
528*3b8456bdSManish V Badarkhe#endif
529532ed618SSoby Mathew
530532ed618SSoby Mathew	ldp	x17, x9, [x0, #CTX_CPACR_EL1]
531532ed618SSoby Mathew	msr	cpacr_el1, x17
532532ed618SSoby Mathew	msr	csselr_el1, x9
533532ed618SSoby Mathew
534532ed618SSoby Mathew	ldp	x10, x11, [x0, #CTX_SP_EL1]
535532ed618SSoby Mathew	msr	sp_el1, x10
536532ed618SSoby Mathew	msr	esr_el1, x11
537532ed618SSoby Mathew
538532ed618SSoby Mathew	ldp	x12, x13, [x0, #CTX_TTBR0_EL1]
539532ed618SSoby Mathew	msr	ttbr0_el1, x12
540532ed618SSoby Mathew	msr	ttbr1_el1, x13
541532ed618SSoby Mathew
542532ed618SSoby Mathew	ldp	x14, x15, [x0, #CTX_MAIR_EL1]
543532ed618SSoby Mathew	msr	mair_el1, x14
544532ed618SSoby Mathew	msr	amair_el1, x15
545532ed618SSoby Mathew
546cb55615cSManish V Badarkhe	ldp 	x16, x17, [x0, #CTX_ACTLR_EL1]
547cb55615cSManish V Badarkhe	msr	actlr_el1, x16
548fb2072b0SManish V Badarkhe	msr	tpidr_el1, x17
549532ed618SSoby Mathew
550532ed618SSoby Mathew	ldp	x9, x10, [x0, #CTX_TPIDR_EL0]
551532ed618SSoby Mathew	msr	tpidr_el0, x9
552532ed618SSoby Mathew	msr	tpidrro_el0, x10
553532ed618SSoby Mathew
554532ed618SSoby Mathew	ldp	x13, x14, [x0, #CTX_PAR_EL1]
555532ed618SSoby Mathew	msr	par_el1, x13
556532ed618SSoby Mathew	msr	far_el1, x14
557532ed618SSoby Mathew
558532ed618SSoby Mathew	ldp	x15, x16, [x0, #CTX_AFSR0_EL1]
559532ed618SSoby Mathew	msr	afsr0_el1, x15
560532ed618SSoby Mathew	msr	afsr1_el1, x16
561532ed618SSoby Mathew
562532ed618SSoby Mathew	ldp	x17, x9, [x0, #CTX_CONTEXTIDR_EL1]
563532ed618SSoby Mathew	msr	contextidr_el1, x17
564532ed618SSoby Mathew	msr	vbar_el1, x9
565532ed618SSoby Mathew
566532ed618SSoby Mathew	/* Restore AArch32 system registers if the build has instructed so */
567532ed618SSoby Mathew#if CTX_INCLUDE_AARCH32_REGS
568532ed618SSoby Mathew	ldp	x11, x12, [x0, #CTX_SPSR_ABT]
569532ed618SSoby Mathew	msr	spsr_abt, x11
570532ed618SSoby Mathew	msr	spsr_und, x12
571532ed618SSoby Mathew
572532ed618SSoby Mathew	ldp	x13, x14, [x0, #CTX_SPSR_IRQ]
573532ed618SSoby Mathew	msr	spsr_irq, x13
574532ed618SSoby Mathew	msr	spsr_fiq, x14
575532ed618SSoby Mathew
576532ed618SSoby Mathew	ldp	x15, x16, [x0, #CTX_DACR32_EL2]
577532ed618SSoby Mathew	msr	dacr32_el2, x15
578532ed618SSoby Mathew	msr	ifsr32_el2, x16
579532ed618SSoby Mathew#endif
580532ed618SSoby Mathew	/* Restore NS timer registers if the build has instructed so */
581532ed618SSoby Mathew#if NS_TIMER_SWITCH
582532ed618SSoby Mathew	ldp	x10, x11, [x0, #CTX_CNTP_CTL_EL0]
583532ed618SSoby Mathew	msr	cntp_ctl_el0, x10
584532ed618SSoby Mathew	msr	cntp_cval_el0, x11
585532ed618SSoby Mathew
586532ed618SSoby Mathew	ldp	x12, x13, [x0, #CTX_CNTV_CTL_EL0]
587532ed618SSoby Mathew	msr	cntv_ctl_el0, x12
588532ed618SSoby Mathew	msr	cntv_cval_el0, x13
589532ed618SSoby Mathew
590532ed618SSoby Mathew	ldr	x14, [x0, #CTX_CNTKCTL_EL1]
591532ed618SSoby Mathew	msr	cntkctl_el1, x14
592532ed618SSoby Mathew#endif
5939dd94382SJustin Chadwell	/* Restore MTE system registers if the build has instructed so */
5949dd94382SJustin Chadwell#if CTX_INCLUDE_MTE_REGS
5959dd94382SJustin Chadwell	ldp	x11, x12, [x0, #CTX_TFSRE0_EL1]
5969dd94382SJustin Chadwell	msr	TFSRE0_EL1, x11
5979dd94382SJustin Chadwell	msr	TFSR_EL1, x12
5989dd94382SJustin Chadwell
5999dd94382SJustin Chadwell	ldp	x13, x14, [x0, #CTX_RGSR_EL1]
6009dd94382SJustin Chadwell	msr	RGSR_EL1, x13
6019dd94382SJustin Chadwell	msr	GCR_EL1, x14
6029dd94382SJustin Chadwell#endif
603532ed618SSoby Mathew
604532ed618SSoby Mathew	/* No explict ISB required here as ERET covers it */
605532ed618SSoby Mathew	ret
606532ed618SSoby Mathewendfunc el1_sysregs_context_restore
607532ed618SSoby Mathew
608ed108b56SAlexei Fedorov/* ------------------------------------------------------------------
609ed108b56SAlexei Fedorov * The following function follows the aapcs_64 strictly to use
610ed108b56SAlexei Fedorov * x9-x17 (temporary caller-saved registers according to AArch64 PCS)
611ed108b56SAlexei Fedorov * to save floating point register context. It assumes that 'x0' is
612ed108b56SAlexei Fedorov * pointing to a 'fp_regs' structure where the register context will
613532ed618SSoby Mathew * be saved.
614532ed618SSoby Mathew *
615ed108b56SAlexei Fedorov * Access to VFP registers will trap if CPTR_EL3.TFP is set.
616ed108b56SAlexei Fedorov * However currently we don't use VFP registers nor set traps in
617ed108b56SAlexei Fedorov * Trusted Firmware, and assume it's cleared.
618532ed618SSoby Mathew *
619532ed618SSoby Mathew * TODO: Revisit when VFP is used in secure world
620ed108b56SAlexei Fedorov * ------------------------------------------------------------------
621532ed618SSoby Mathew */
622532ed618SSoby Mathew#if CTX_INCLUDE_FPREGS
623532ed618SSoby Mathewfunc fpregs_context_save
624532ed618SSoby Mathew	stp	q0, q1, [x0, #CTX_FP_Q0]
625532ed618SSoby Mathew	stp	q2, q3, [x0, #CTX_FP_Q2]
626532ed618SSoby Mathew	stp	q4, q5, [x0, #CTX_FP_Q4]
627532ed618SSoby Mathew	stp	q6, q7, [x0, #CTX_FP_Q6]
628532ed618SSoby Mathew	stp	q8, q9, [x0, #CTX_FP_Q8]
629532ed618SSoby Mathew	stp	q10, q11, [x0, #CTX_FP_Q10]
630532ed618SSoby Mathew	stp	q12, q13, [x0, #CTX_FP_Q12]
631532ed618SSoby Mathew	stp	q14, q15, [x0, #CTX_FP_Q14]
632532ed618SSoby Mathew	stp	q16, q17, [x0, #CTX_FP_Q16]
633532ed618SSoby Mathew	stp	q18, q19, [x0, #CTX_FP_Q18]
634532ed618SSoby Mathew	stp	q20, q21, [x0, #CTX_FP_Q20]
635532ed618SSoby Mathew	stp	q22, q23, [x0, #CTX_FP_Q22]
636532ed618SSoby Mathew	stp	q24, q25, [x0, #CTX_FP_Q24]
637532ed618SSoby Mathew	stp	q26, q27, [x0, #CTX_FP_Q26]
638532ed618SSoby Mathew	stp	q28, q29, [x0, #CTX_FP_Q28]
639532ed618SSoby Mathew	stp	q30, q31, [x0, #CTX_FP_Q30]
640532ed618SSoby Mathew
641532ed618SSoby Mathew	mrs	x9, fpsr
642532ed618SSoby Mathew	str	x9, [x0, #CTX_FP_FPSR]
643532ed618SSoby Mathew
644532ed618SSoby Mathew	mrs	x10, fpcr
645532ed618SSoby Mathew	str	x10, [x0, #CTX_FP_FPCR]
646532ed618SSoby Mathew
64791089f36SDavid Cunado#if CTX_INCLUDE_AARCH32_REGS
64891089f36SDavid Cunado	mrs	x11, fpexc32_el2
64991089f36SDavid Cunado	str	x11, [x0, #CTX_FP_FPEXC32_EL2]
65091089f36SDavid Cunado#endif
651532ed618SSoby Mathew	ret
652532ed618SSoby Mathewendfunc fpregs_context_save
653532ed618SSoby Mathew
654ed108b56SAlexei Fedorov/* ------------------------------------------------------------------
655ed108b56SAlexei Fedorov * The following function follows the aapcs_64 strictly to use x9-x17
656ed108b56SAlexei Fedorov * (temporary caller-saved registers according to AArch64 PCS) to
657ed108b56SAlexei Fedorov * restore floating point register context. It assumes that 'x0' is
658ed108b56SAlexei Fedorov * pointing to a 'fp_regs' structure from where the register context
659532ed618SSoby Mathew * will be restored.
660532ed618SSoby Mathew *
661ed108b56SAlexei Fedorov * Access to VFP registers will trap if CPTR_EL3.TFP is set.
662ed108b56SAlexei Fedorov * However currently we don't use VFP registers nor set traps in
663ed108b56SAlexei Fedorov * Trusted Firmware, and assume it's cleared.
664532ed618SSoby Mathew *
665532ed618SSoby Mathew * TODO: Revisit when VFP is used in secure world
666ed108b56SAlexei Fedorov * ------------------------------------------------------------------
667532ed618SSoby Mathew */
668532ed618SSoby Mathewfunc fpregs_context_restore
669532ed618SSoby Mathew	ldp	q0, q1, [x0, #CTX_FP_Q0]
670532ed618SSoby Mathew	ldp	q2, q3, [x0, #CTX_FP_Q2]
671532ed618SSoby Mathew	ldp	q4, q5, [x0, #CTX_FP_Q4]
672532ed618SSoby Mathew	ldp	q6, q7, [x0, #CTX_FP_Q6]
673532ed618SSoby Mathew	ldp	q8, q9, [x0, #CTX_FP_Q8]
674532ed618SSoby Mathew	ldp	q10, q11, [x0, #CTX_FP_Q10]
675532ed618SSoby Mathew	ldp	q12, q13, [x0, #CTX_FP_Q12]
676532ed618SSoby Mathew	ldp	q14, q15, [x0, #CTX_FP_Q14]
677532ed618SSoby Mathew	ldp	q16, q17, [x0, #CTX_FP_Q16]
678532ed618SSoby Mathew	ldp	q18, q19, [x0, #CTX_FP_Q18]
679532ed618SSoby Mathew	ldp	q20, q21, [x0, #CTX_FP_Q20]
680532ed618SSoby Mathew	ldp	q22, q23, [x0, #CTX_FP_Q22]
681532ed618SSoby Mathew	ldp	q24, q25, [x0, #CTX_FP_Q24]
682532ed618SSoby Mathew	ldp	q26, q27, [x0, #CTX_FP_Q26]
683532ed618SSoby Mathew	ldp	q28, q29, [x0, #CTX_FP_Q28]
684532ed618SSoby Mathew	ldp	q30, q31, [x0, #CTX_FP_Q30]
685532ed618SSoby Mathew
686532ed618SSoby Mathew	ldr	x9, [x0, #CTX_FP_FPSR]
687532ed618SSoby Mathew	msr	fpsr, x9
688532ed618SSoby Mathew
689532ed618SSoby Mathew	ldr	x10, [x0, #CTX_FP_FPCR]
690532ed618SSoby Mathew	msr	fpcr, x10
691532ed618SSoby Mathew
69291089f36SDavid Cunado#if CTX_INCLUDE_AARCH32_REGS
69391089f36SDavid Cunado	ldr	x11, [x0, #CTX_FP_FPEXC32_EL2]
69491089f36SDavid Cunado	msr	fpexc32_el2, x11
69591089f36SDavid Cunado#endif
696532ed618SSoby Mathew	/*
697532ed618SSoby Mathew	 * No explict ISB required here as ERET to
698532ed618SSoby Mathew	 * switch to secure EL1 or non-secure world
699532ed618SSoby Mathew	 * covers it
700532ed618SSoby Mathew	 */
701532ed618SSoby Mathew
702532ed618SSoby Mathew	ret
703532ed618SSoby Mathewendfunc fpregs_context_restore
704532ed618SSoby Mathew#endif /* CTX_INCLUDE_FPREGS */
705532ed618SSoby Mathew
706ed108b56SAlexei Fedorov/* ------------------------------------------------------------------
707ed108b56SAlexei Fedorov * The following function is used to save and restore all the general
708ed108b56SAlexei Fedorov * purpose and ARMv8.3-PAuth (if enabled) registers.
709ed108b56SAlexei Fedorov * It also checks if Secure Cycle Counter is not disabled in MDCR_EL3
710ed108b56SAlexei Fedorov * when ARMv8.5-PMU is implemented, and if called from Non-secure
711ed108b56SAlexei Fedorov * state saves PMCR_EL0 and disables Cycle Counter.
712ed108b56SAlexei Fedorov *
713ed108b56SAlexei Fedorov * Ideally we would only save and restore the callee saved registers
714ed108b56SAlexei Fedorov * when a world switch occurs but that type of implementation is more
715ed108b56SAlexei Fedorov * complex. So currently we will always save and restore these
716ed108b56SAlexei Fedorov * registers on entry and exit of EL3.
717ed108b56SAlexei Fedorov * These are not macros to ensure their invocation fits within the 32
718ed108b56SAlexei Fedorov * instructions per exception vector.
719532ed618SSoby Mathew * clobbers: x18
720ed108b56SAlexei Fedorov * ------------------------------------------------------------------
721532ed618SSoby Mathew */
722ed108b56SAlexei Fedorovfunc save_gp_pmcr_pauth_regs
723532ed618SSoby Mathew	stp	x0, x1, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X0]
724532ed618SSoby Mathew	stp	x2, x3, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X2]
725532ed618SSoby Mathew	stp	x4, x5, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X4]
726532ed618SSoby Mathew	stp	x6, x7, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X6]
727532ed618SSoby Mathew	stp	x8, x9, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X8]
728532ed618SSoby Mathew	stp	x10, x11, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X10]
729532ed618SSoby Mathew	stp	x12, x13, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X12]
730532ed618SSoby Mathew	stp	x14, x15, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X14]
731532ed618SSoby Mathew	stp	x16, x17, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X16]
732532ed618SSoby Mathew	stp	x18, x19, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X18]
733532ed618SSoby Mathew	stp	x20, x21, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X20]
734532ed618SSoby Mathew	stp	x22, x23, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X22]
735532ed618SSoby Mathew	stp	x24, x25, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X24]
736532ed618SSoby Mathew	stp	x26, x27, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X26]
737532ed618SSoby Mathew	stp	x28, x29, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X28]
738532ed618SSoby Mathew	mrs	x18, sp_el0
739532ed618SSoby Mathew	str	x18, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_SP_EL0]
740532ed618SSoby Mathew
741ed108b56SAlexei Fedorov	/* ----------------------------------------------------------
742ed108b56SAlexei Fedorov	 * Check if earlier initialization MDCR_EL3.SCCD to 1 failed,
743ed108b56SAlexei Fedorov	 * meaning that ARMv8-PMU is not implemented and PMCR_EL0
744ed108b56SAlexei Fedorov	 * should be saved in non-secure context.
745ed108b56SAlexei Fedorov	 * ----------------------------------------------------------
746ef653d93SJeenu Viswambharan	 */
747ed108b56SAlexei Fedorov	mrs	x9, mdcr_el3
748ed108b56SAlexei Fedorov	tst	x9, #MDCR_SCCD_BIT
749ed108b56SAlexei Fedorov	bne	1f
750ed108b56SAlexei Fedorov
751ed108b56SAlexei Fedorov	/* Secure Cycle Counter is not disabled */
752ed108b56SAlexei Fedorov	mrs	x9, pmcr_el0
753ed108b56SAlexei Fedorov
754ed108b56SAlexei Fedorov	/* Check caller's security state */
755ed108b56SAlexei Fedorov	mrs	x10, scr_el3
756ed108b56SAlexei Fedorov	tst	x10, #SCR_NS_BIT
757ed108b56SAlexei Fedorov	beq	2f
758ed108b56SAlexei Fedorov
759ed108b56SAlexei Fedorov	/* Save PMCR_EL0 if called from Non-secure state */
760ed108b56SAlexei Fedorov	str	x9, [sp, #CTX_EL3STATE_OFFSET + CTX_PMCR_EL0]
761ed108b56SAlexei Fedorov
762ed108b56SAlexei Fedorov	/* Disable cycle counter when event counting is prohibited */
763ed108b56SAlexei Fedorov2:	orr	x9, x9, #PMCR_EL0_DP_BIT
764ed108b56SAlexei Fedorov	msr	pmcr_el0, x9
765ed108b56SAlexei Fedorov	isb
766ed108b56SAlexei Fedorov1:
767ed108b56SAlexei Fedorov#if CTX_INCLUDE_PAUTH_REGS
768ed108b56SAlexei Fedorov	/* ----------------------------------------------------------
769ed108b56SAlexei Fedorov 	 * Save the ARMv8.3-PAuth keys as they are not banked
770ed108b56SAlexei Fedorov 	 * by exception level
771ed108b56SAlexei Fedorov	 * ----------------------------------------------------------
772ed108b56SAlexei Fedorov	 */
773ed108b56SAlexei Fedorov	add	x19, sp, #CTX_PAUTH_REGS_OFFSET
774ed108b56SAlexei Fedorov
775ed108b56SAlexei Fedorov	mrs	x20, APIAKeyLo_EL1	/* x21:x20 = APIAKey */
776ed108b56SAlexei Fedorov	mrs	x21, APIAKeyHi_EL1
777ed108b56SAlexei Fedorov	mrs	x22, APIBKeyLo_EL1	/* x23:x22 = APIBKey */
778ed108b56SAlexei Fedorov	mrs	x23, APIBKeyHi_EL1
779ed108b56SAlexei Fedorov	mrs	x24, APDAKeyLo_EL1	/* x25:x24 = APDAKey */
780ed108b56SAlexei Fedorov	mrs	x25, APDAKeyHi_EL1
781ed108b56SAlexei Fedorov	mrs	x26, APDBKeyLo_EL1	/* x27:x26 = APDBKey */
782ed108b56SAlexei Fedorov	mrs	x27, APDBKeyHi_EL1
783ed108b56SAlexei Fedorov	mrs	x28, APGAKeyLo_EL1	/* x29:x28 = APGAKey */
784ed108b56SAlexei Fedorov	mrs	x29, APGAKeyHi_EL1
785ed108b56SAlexei Fedorov
786ed108b56SAlexei Fedorov	stp	x20, x21, [x19, #CTX_PACIAKEY_LO]
787ed108b56SAlexei Fedorov	stp	x22, x23, [x19, #CTX_PACIBKEY_LO]
788ed108b56SAlexei Fedorov	stp	x24, x25, [x19, #CTX_PACDAKEY_LO]
789ed108b56SAlexei Fedorov	stp	x26, x27, [x19, #CTX_PACDBKEY_LO]
790ed108b56SAlexei Fedorov	stp	x28, x29, [x19, #CTX_PACGAKEY_LO]
791ed108b56SAlexei Fedorov#endif /* CTX_INCLUDE_PAUTH_REGS */
792ed108b56SAlexei Fedorov
793ed108b56SAlexei Fedorov	ret
794ed108b56SAlexei Fedorovendfunc save_gp_pmcr_pauth_regs
795ed108b56SAlexei Fedorov
796ed108b56SAlexei Fedorov/* ------------------------------------------------------------------
797ed108b56SAlexei Fedorov * This function restores ARMv8.3-PAuth (if enabled) and all general
798ed108b56SAlexei Fedorov * purpose registers except x30 from the CPU context.
799ed108b56SAlexei Fedorov * x30 register must be explicitly restored by the caller.
800ed108b56SAlexei Fedorov * ------------------------------------------------------------------
801ed108b56SAlexei Fedorov */
802ed108b56SAlexei Fedorovfunc restore_gp_pmcr_pauth_regs
803ed108b56SAlexei Fedorov#if CTX_INCLUDE_PAUTH_REGS
804ed108b56SAlexei Fedorov 	/* Restore the ARMv8.3 PAuth keys */
805ed108b56SAlexei Fedorov	add	x10, sp, #CTX_PAUTH_REGS_OFFSET
806ed108b56SAlexei Fedorov
807ed108b56SAlexei Fedorov	ldp	x0, x1, [x10, #CTX_PACIAKEY_LO]	/* x1:x0 = APIAKey */
808ed108b56SAlexei Fedorov	ldp	x2, x3, [x10, #CTX_PACIBKEY_LO]	/* x3:x2 = APIBKey */
809ed108b56SAlexei Fedorov	ldp	x4, x5, [x10, #CTX_PACDAKEY_LO]	/* x5:x4 = APDAKey */
810ed108b56SAlexei Fedorov	ldp	x6, x7, [x10, #CTX_PACDBKEY_LO]	/* x7:x6 = APDBKey */
811ed108b56SAlexei Fedorov	ldp	x8, x9, [x10, #CTX_PACGAKEY_LO]	/* x9:x8 = APGAKey */
812ed108b56SAlexei Fedorov
813ed108b56SAlexei Fedorov	msr	APIAKeyLo_EL1, x0
814ed108b56SAlexei Fedorov	msr	APIAKeyHi_EL1, x1
815ed108b56SAlexei Fedorov	msr	APIBKeyLo_EL1, x2
816ed108b56SAlexei Fedorov	msr	APIBKeyHi_EL1, x3
817ed108b56SAlexei Fedorov	msr	APDAKeyLo_EL1, x4
818ed108b56SAlexei Fedorov	msr	APDAKeyHi_EL1, x5
819ed108b56SAlexei Fedorov	msr	APDBKeyLo_EL1, x6
820ed108b56SAlexei Fedorov	msr	APDBKeyHi_EL1, x7
821ed108b56SAlexei Fedorov	msr	APGAKeyLo_EL1, x8
822ed108b56SAlexei Fedorov	msr	APGAKeyHi_EL1, x9
823ed108b56SAlexei Fedorov#endif /* CTX_INCLUDE_PAUTH_REGS */
824ed108b56SAlexei Fedorov
825ed108b56SAlexei Fedorov	/* ----------------------------------------------------------
826ed108b56SAlexei Fedorov	 * Restore PMCR_EL0 when returning to Non-secure state if
827ed108b56SAlexei Fedorov	 * Secure Cycle Counter is not disabled in MDCR_EL3 when
828ed108b56SAlexei Fedorov	 * ARMv8.5-PMU is implemented.
829ed108b56SAlexei Fedorov	 * ----------------------------------------------------------
830ed108b56SAlexei Fedorov	 */
831ed108b56SAlexei Fedorov	mrs	x0, scr_el3
832ed108b56SAlexei Fedorov	tst	x0, #SCR_NS_BIT
833ed108b56SAlexei Fedorov	beq	2f
834ed108b56SAlexei Fedorov
835ed108b56SAlexei Fedorov	/* ----------------------------------------------------------
836ed108b56SAlexei Fedorov	 * Back to Non-secure state.
837ed108b56SAlexei Fedorov	 * Check if earlier initialization MDCR_EL3.SCCD to 1 failed,
838ed108b56SAlexei Fedorov	 * meaning that ARMv8-PMU is not implemented and PMCR_EL0
839ed108b56SAlexei Fedorov	 * should be restored from non-secure context.
840ed108b56SAlexei Fedorov	 * ----------------------------------------------------------
841ed108b56SAlexei Fedorov	 */
842ed108b56SAlexei Fedorov	mrs	x0, mdcr_el3
843ed108b56SAlexei Fedorov	tst	x0, #MDCR_SCCD_BIT
844ed108b56SAlexei Fedorov	bne	2f
845ed108b56SAlexei Fedorov	ldr	x0, [sp, #CTX_EL3STATE_OFFSET + CTX_PMCR_EL0]
846ed108b56SAlexei Fedorov	msr	pmcr_el0, x0
847ed108b56SAlexei Fedorov2:
848532ed618SSoby Mathew	ldp	x0, x1, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X0]
849532ed618SSoby Mathew	ldp	x2, x3, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X2]
850532ed618SSoby Mathew	ldp	x4, x5, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X4]
851532ed618SSoby Mathew	ldp	x6, x7, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X6]
852532ed618SSoby Mathew	ldp	x8, x9, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X8]
853532ed618SSoby Mathew	ldp	x10, x11, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X10]
854532ed618SSoby Mathew	ldp	x12, x13, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X12]
855532ed618SSoby Mathew	ldp	x14, x15, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X14]
856ef653d93SJeenu Viswambharan	ldp	x16, x17, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X16]
857532ed618SSoby Mathew	ldp	x18, x19, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X18]
858532ed618SSoby Mathew	ldp	x20, x21, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X20]
859532ed618SSoby Mathew	ldp	x22, x23, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X22]
860532ed618SSoby Mathew	ldp	x24, x25, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X24]
861532ed618SSoby Mathew	ldp	x26, x27, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X26]
862ef653d93SJeenu Viswambharan	ldr	x28, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_SP_EL0]
863ef653d93SJeenu Viswambharan	msr	sp_el0, x28
864532ed618SSoby Mathew	ldp	x28, x29, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X28]
865ef653d93SJeenu Viswambharan	ret
866ed108b56SAlexei Fedorovendfunc restore_gp_pmcr_pauth_regs
867ef653d93SJeenu Viswambharan
868*3b8456bdSManish V Badarkhe/*
869*3b8456bdSManish V Badarkhe * In case of ERRATA_SPECULATIVE_AT, save SCTLR_EL1 and TCR_EL1
870*3b8456bdSManish V Badarkhe * registers and update EL1 registers to disable stage1 and stage2
871*3b8456bdSManish V Badarkhe * page table walk
872*3b8456bdSManish V Badarkhe */
873*3b8456bdSManish V Badarkhefunc save_and_update_ptw_el1_sys_regs
874*3b8456bdSManish V Badarkhe	/* ----------------------------------------------------------
875*3b8456bdSManish V Badarkhe	 * Save only sctlr_el1 and tcr_el1 registers
876*3b8456bdSManish V Badarkhe	 * ----------------------------------------------------------
877*3b8456bdSManish V Badarkhe	 */
878*3b8456bdSManish V Badarkhe	mrs	x29, sctlr_el1
879*3b8456bdSManish V Badarkhe	str	x29, [sp, #(CTX_EL1_SYSREGS_OFFSET + CTX_SCTLR_EL1)]
880*3b8456bdSManish V Badarkhe	mrs	x29, tcr_el1
881*3b8456bdSManish V Badarkhe	str	x29, [sp, #(CTX_EL1_SYSREGS_OFFSET + CTX_TCR_EL1)]
882*3b8456bdSManish V Badarkhe
883*3b8456bdSManish V Badarkhe	/* ------------------------------------------------------------
884*3b8456bdSManish V Badarkhe	 * Must follow below order in order to disable page table
885*3b8456bdSManish V Badarkhe	 * walk for lower ELs (EL1 and EL0). First step ensures that
886*3b8456bdSManish V Badarkhe	 * page table walk is disabled for stage1 and second step
887*3b8456bdSManish V Badarkhe	 * ensures that page table walker should use TCR_EL1.EPDx
888*3b8456bdSManish V Badarkhe	 * bits to perform address translation. ISB ensures that CPU
889*3b8456bdSManish V Badarkhe	 * does these 2 steps in order.
890*3b8456bdSManish V Badarkhe	 *
891*3b8456bdSManish V Badarkhe	 * 1. Update TCR_EL1.EPDx bits to disable page table walk by
892*3b8456bdSManish V Badarkhe	 *    stage1.
893*3b8456bdSManish V Badarkhe	 * 2. Enable MMU bit to avoid identity mapping via stage2
894*3b8456bdSManish V Badarkhe	 *    and force TCR_EL1.EPDx to be used by the page table
895*3b8456bdSManish V Badarkhe	 *    walker.
896*3b8456bdSManish V Badarkhe	 * ------------------------------------------------------------
897*3b8456bdSManish V Badarkhe	 */
898*3b8456bdSManish V Badarkhe	orr	x29, x29, #(TCR_EPD0_BIT)
899*3b8456bdSManish V Badarkhe	orr	x29, x29, #(TCR_EPD1_BIT)
900*3b8456bdSManish V Badarkhe	msr	tcr_el1, x29
901*3b8456bdSManish V Badarkhe	isb
902*3b8456bdSManish V Badarkhe	mrs	x29, sctlr_el1
903*3b8456bdSManish V Badarkhe	orr	x29, x29, #SCTLR_M_BIT
904*3b8456bdSManish V Badarkhe	msr	sctlr_el1, x29
905*3b8456bdSManish V Badarkhe	isb
906*3b8456bdSManish V Badarkhe
907*3b8456bdSManish V Badarkhe	ret
908*3b8456bdSManish V Badarkheendfunc save_and_update_ptw_el1_sys_regs
909*3b8456bdSManish V Badarkhe
910ed108b56SAlexei Fedorov/* ------------------------------------------------------------------
911ed108b56SAlexei Fedorov * This routine assumes that the SP_EL3 is pointing to a valid
912ed108b56SAlexei Fedorov * context structure from where the gp regs and other special
913ed108b56SAlexei Fedorov * registers can be retrieved.
914ed108b56SAlexei Fedorov * ------------------------------------------------------------------
915532ed618SSoby Mathew */
916532ed618SSoby Mathewfunc el3_exit
917bb9549baSJan Dabros#if ENABLE_ASSERTIONS
918bb9549baSJan Dabros	/* el3_exit assumes SP_EL0 on entry */
919bb9549baSJan Dabros	mrs	x17, spsel
920bb9549baSJan Dabros	cmp	x17, #MODE_SP_EL0
921bb9549baSJan Dabros	ASM_ASSERT(eq)
922bb9549baSJan Dabros#endif
923bb9549baSJan Dabros
924ed108b56SAlexei Fedorov	/* ----------------------------------------------------------
925ed108b56SAlexei Fedorov	 * Save the current SP_EL0 i.e. the EL3 runtime stack which
926ed108b56SAlexei Fedorov	 * will be used for handling the next SMC.
927ed108b56SAlexei Fedorov	 * Then switch to SP_EL3.
928ed108b56SAlexei Fedorov	 * ----------------------------------------------------------
929532ed618SSoby Mathew	 */
930532ed618SSoby Mathew	mov	x17, sp
931ed108b56SAlexei Fedorov	msr	spsel, #MODE_SP_ELX
932532ed618SSoby Mathew	str	x17, [sp, #CTX_EL3STATE_OFFSET + CTX_RUNTIME_SP]
933532ed618SSoby Mathew
934ed108b56SAlexei Fedorov	/* ----------------------------------------------------------
935532ed618SSoby Mathew	 * Restore SPSR_EL3, ELR_EL3 and SCR_EL3 prior to ERET
936ed108b56SAlexei Fedorov	 * ----------------------------------------------------------
937532ed618SSoby Mathew	 */
938532ed618SSoby Mathew	ldr	x18, [sp, #CTX_EL3STATE_OFFSET + CTX_SCR_EL3]
939532ed618SSoby Mathew	ldp	x16, x17, [sp, #CTX_EL3STATE_OFFSET + CTX_SPSR_EL3]
940532ed618SSoby Mathew	msr	scr_el3, x18
941532ed618SSoby Mathew	msr	spsr_el3, x16
942532ed618SSoby Mathew	msr	elr_el3, x17
943532ed618SSoby Mathew
944fe007b2eSDimitris Papastamos#if IMAGE_BL31 && DYNAMIC_WORKAROUND_CVE_2018_3639
945ed108b56SAlexei Fedorov	/* ----------------------------------------------------------
946ed108b56SAlexei Fedorov	 * Restore mitigation state as it was on entry to EL3
947ed108b56SAlexei Fedorov	 * ----------------------------------------------------------
948ed108b56SAlexei Fedorov	 */
949fe007b2eSDimitris Papastamos	ldr	x17, [sp, #CTX_CVE_2018_3639_OFFSET + CTX_CVE_2018_3639_DISABLE]
950ed108b56SAlexei Fedorov	cbz	x17, 1f
951fe007b2eSDimitris Papastamos	blr	x17
9524d1ccf0eSAntonio Nino Diaz1:
953fe007b2eSDimitris Papastamos#endif
954*3b8456bdSManish V Badarkhe	restore_ptw_el1_sys_regs
955*3b8456bdSManish V Badarkhe
956ed108b56SAlexei Fedorov	/* ----------------------------------------------------------
957ed108b56SAlexei Fedorov	 * Restore general purpose (including x30), PMCR_EL0 and
958ed108b56SAlexei Fedorov	 * ARMv8.3-PAuth registers.
959ed108b56SAlexei Fedorov	 * Exit EL3 via ERET to a lower exception level.
960ed108b56SAlexei Fedorov 	 * ----------------------------------------------------------
961ed108b56SAlexei Fedorov 	 */
962ed108b56SAlexei Fedorov	bl	restore_gp_pmcr_pauth_regs
963ed108b56SAlexei Fedorov	ldr	x30, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_LR]
964fe007b2eSDimitris Papastamos
965ed108b56SAlexei Fedorov#if IMAGE_BL31 && RAS_EXTENSION
966ed108b56SAlexei Fedorov	/* ----------------------------------------------------------
967ed108b56SAlexei Fedorov	 * Issue Error Synchronization Barrier to synchronize SErrors
968ed108b56SAlexei Fedorov	 * before exiting EL3. We're running with EAs unmasked, so
969ed108b56SAlexei Fedorov	 * any synchronized errors would be taken immediately;
970ed108b56SAlexei Fedorov	 * therefore no need to inspect DISR_EL1 register.
971ed108b56SAlexei Fedorov 	 * ----------------------------------------------------------
972ed108b56SAlexei Fedorov	 */
973ed108b56SAlexei Fedorov	esb
9745283962eSAntonio Nino Diaz#endif
975f461fe34SAnthony Steinhauser	exception_return
9765283962eSAntonio Nino Diaz
977532ed618SSoby Mathewendfunc el3_exit
978