2 * Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved.
4 * SPDX-License-Identifier: BSD-3-Clause
8 #include <assert_macros.S>
9 #include <asm_macros.S>
10 #include <assert_macros.S>
11 #include <bl31/ea_handle.h>
13 #include <lib/extensions/ras_arch.h>
16 .globl handle_lower_el_ea_esb
17 .globl enter_lower_el_sync_ea
18 .globl enter_lower_el_async_ea
22 * Function to delegate External Aborts synchronized by ESB instruction at EL3
23 * vector entry. This function assumes GP registers x0-x29 have been saved, and
24 * are available for use. It delegates the handling of the EA to platform
25 * handler, and returns only upon successfully handling the EA; otherwise
26 * panics. On return from this function, the original exception handler is
29 func handle_lower_el_ea_esb
33 endfunc handle_lower_el_ea_esb
37 * This function forms the tail end of Synchronous Exception entry from lower
38 * EL, and expects to handle only Synchronous External Aborts from lower EL. If
39 * any other kind of exception is detected, then this function reports unhandled
42 * Since it's part of exception vector, this function doesn't expect any GP
43 * registers to have been saved. It delegates the handling of the EA to platform
44 * handler, and upon successfully handling the EA, exits EL3; otherwise panics.
46 func enter_lower_el_sync_ea
48 * Explicitly save x30 so as to free up a register and to enable
51 str x30, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_LR]
54 ubfx x30, x30, #ESR_EC_SHIFT, #ESR_EC_LENGTH
56 /* Check for I/D aborts from lower EL */
57 cmp x30, #EC_IABORT_LOWER_EL
60 cmp x30, #EC_DABORT_LOWER_EL
64 /* Test for EA bit in the instruction syndrome */
66 tbz x30, #ESR_ISS_EABORT_EA_BIT, 2f
69 * Save general purpose and ARMv8.3-PAuth registers (if enabled).
70 * If Secure Cycle Counter is not disabled in MDCR_EL3 when
71 * ARMv8.5-PMU is implemented, save PMCR_EL0 and disable Cycle Counter.
73 bl save_gp_pmcr_pauth_regs
76 /* Load and program APIAKey firmware key */
77 bl pauth_load_bl31_apiakey
80 /* Setup exception class and syndrome arguments for platform handler */
81 mov x0, #ERROR_EA_SYNC
87 /* Synchronous exceptions other than the above are assumed to be EA */
88 ldr x30, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_LR]
89 no_ret report_unhandled_exception
90 endfunc enter_lower_el_sync_ea
94 * This function handles SErrors from lower ELs.
96 * Since it's part of exception vector, this function doesn't expect any GP
97 * registers to have been saved. It delegates the handling of the EA to platform
98 * handler, and upon successfully handling the EA, exits EL3; otherwise panics.
100 func enter_lower_el_async_ea
102 * Explicitly save x30 so as to free up a register and to enable
105 str x30, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_LR]
108 * Save general purpose and ARMv8.3-PAuth registers (if enabled).
109 * If Secure Cycle Counter is not disabled in MDCR_EL3 when
110 * ARMv8.5-PMU is implemented, save PMCR_EL0 and disable Cycle Counter.
112 bl save_gp_pmcr_pauth_regs
115 /* Load and program APIAKey firmware key */
116 bl pauth_load_bl31_apiakey
119 /* Setup exception class and syndrome arguments for platform handler */
120 mov x0, #ERROR_EA_ASYNC
124 endfunc enter_lower_el_async_ea
128 * Prelude for Synchronous External Abort handling. This function assumes that
129 * all GP registers have been saved by the caller.
134 func delegate_sync_ea
137 * Check for Uncontainable error type. If so, route to the platform
138 * fatal error handler rather than the generic EA one.
140 ubfx x2, x1, #EABORT_SET_SHIFT, #EABORT_SET_WIDTH
141 cmp x2, #ERROR_STATUS_SET_UC
144 /* Check fault status code */
145 ubfx x3, x1, #EABORT_DFSC_SHIFT, #EABORT_DFSC_WIDTH
149 no_ret plat_handle_uncontainable_ea
154 endfunc delegate_sync_ea
158 * Prelude for Asynchronous External Abort handling. This function assumes that
159 * all GP registers have been saved by the caller.
164 func delegate_async_ea
167 * Check for Implementation Defined Syndrome. If so, skip checking
168 * Uncontainable error type from the syndrome as the format is unknown.
170 tbnz x1, #SERROR_IDS_BIT, 1f
173 * Check for Uncontainable error type. If so, route to the platform
174 * fatal error handler rather than the generic EA one.
176 ubfx x2, x1, #EABORT_AET_SHIFT, #EABORT_AET_WIDTH
177 cmp x2, #ERROR_STATUS_UET_UC
180 /* Check DFSC for SError type */
181 ubfx x3, x1, #EABORT_DFSC_SHIFT, #EABORT_DFSC_WIDTH
185 no_ret plat_handle_uncontainable_ea
190 endfunc delegate_async_ea
194 * Delegate External Abort handling to platform's EA handler. This function
195 * assumes that all GP registers have been saved by the caller.
202 * If the ESR loaded earlier is not zero, we were processing an EA
203 * already, and this is a double fault.
205 ldr x5, [sp, #CTX_EL3STATE_OFFSET + CTX_ESR_EL3]
207 no_ret plat_handle_double_fault
213 stp x2, x3, [sp, #CTX_EL3STATE_OFFSET + CTX_SPSR_EL3]
216 * Save ESR as handling might involve lower ELs, and returning back to
217 * EL3 from there would trample the original ESR.
221 stp x4, x5, [sp, #CTX_EL3STATE_OFFSET + CTX_SCR_EL3]
224 * Setup rest of arguments, and call platform External Abort handler.
226 * x0: EA reason (already in place)
227 * x1: Exception syndrome (already in place).
228 * x2: Cookie (unused for now).
229 * x3: Context pointer.
230 * x4: Flags (security state from SCR for now).
236 /* Switch to runtime stack */
237 ldr x5, [sp, #CTX_EL3STATE_OFFSET + CTX_RUNTIME_SP]
238 msr spsel, #MODE_SP_EL0
242 #if ENABLE_ASSERTIONS
243 /* Stash the stack pointer */
248 #if ENABLE_ASSERTIONS
250 * Error handling flows might involve long jumps; so upon returning from
251 * the platform error handler, validate that the we've completely
259 /* Make SP point to context */
260 msr spsel, #MODE_SP_ELX
262 /* Restore EL3 state and ESR */
263 ldp x1, x2, [sp, #CTX_EL3STATE_OFFSET + CTX_SPSR_EL3]
267 /* Restore ESR_EL3 and SCR_EL3 */
268 ldp x3, x4, [sp, #CTX_EL3STATE_OFFSET + CTX_SCR_EL3]
272 #if ENABLE_ASSERTIONS
277 /* Clear ESR storage */
278 str xzr, [sp, #CTX_EL3STATE_OFFSET + CTX_ESR_EL3]