From 17630f637e9e8807278960388d20f80ca66db87a Mon Sep 17 00:00:00 2001 From: Ioannis Glaropoulos Date: Mon, 7 Oct 2019 11:03:18 +0200 Subject: [PATCH] arch: arm: internal API to check return execution mode We add an ARM internal API which allows the kernel to infer the execution mode we are going to return after the current exception. Signed-off-by: Ioannis Glaropoulos --- arch/arm/include/cortex_m/exc.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/arch/arm/include/cortex_m/exc.h b/arch/arm/include/cortex_m/exc.h index bc63c4873b7..e4f57aab646 100644 --- a/arch/arm/include/cortex_m/exc.h +++ b/arch/arm/include/cortex_m/exc.h @@ -48,6 +48,32 @@ static ALWAYS_INLINE bool z_arch_is_in_isr(void) return (__get_IPSR()) ? (true) : (false); } +/** + * @brief Find out if we were in ISR context + * before the current exception occurred. + * + * A function that determines, based on inspecting the current + * ESF, whether the processor was in handler mode before entering + * the current exception state (i.e. nested exception) or not. + * + * Notes: + * - The function shall only be called from ISR context. + * - We do not use ARM processor state flags to determine + * whether we are in a nested exception; we rely on the + * RETPSR value stacked on the ESF. Hence, the function + * assumes that the ESF stack frame has a valid RETPSR + * value. + * + * @param esf the exception stack frame (cannot be NULL) + * @return true if execution state was in handler mode, before + * the current exception occurred, otherwise false. + */ +static ALWAYS_INLINE bool z_arch_is_in_nested_exception( + const z_arch_esf_t *esf) +{ + return (esf->basic.xpsr & IPSR_ISR_Msk) ? (true) : (false); +} + /** * @brief Setup system exceptions *