diff --git a/arch/arm/src/armv6-m/arm_doirq.c b/arch/arm/src/armv6-m/arm_doirq.c index aa9578d87dec7..4609bdf6444ba 100644 --- a/arch/arm/src/armv6-m/arm_doirq.c +++ b/arch/arm/src/armv6-m/arm_doirq.c @@ -56,6 +56,17 @@ void exception_direct(void) } } +static inline_function bool restore_context(int irq, uint32_t *regs) +{ + if ((NVIC_IRQ_SVCALL == irq || NVIC_IRQ_HARDFAULT == irq) && + regs[REG_R0] == SYS_restore_context) + { + return true; + } + + return false; +} + uint32_t *arm_doirq(int irq, uint32_t *regs) { struct tcb_s **running_task = &g_running_tasks[this_cpu()]; @@ -65,7 +76,7 @@ uint32_t *arm_doirq(int irq, uint32_t *regs) * is invalid, and we can safely overwrite it. */ - if (!(NVIC_IRQ_SVCALL == irq && regs[REG_R0] == SYS_restore_context)) + if (!restore_context(irq, regs)) { tcb->xcp.regs = regs; } diff --git a/arch/arm/src/armv7-m/arm_doirq.c b/arch/arm/src/armv7-m/arm_doirq.c index 7eff7dd8119a2..5ff94c5cf73a7 100644 --- a/arch/arm/src/armv7-m/arm_doirq.c +++ b/arch/arm/src/armv7-m/arm_doirq.c @@ -56,6 +56,17 @@ void exception_direct(void) } } +static inline_function bool restore_context(int irq, uint32_t *regs) +{ + if ((NVIC_IRQ_SVCALL == irq || NVIC_IRQ_HARDFAULT == irq) && + regs[REG_R0] == SYS_restore_context) + { + return true; + } + + return false; +} + uint32_t *arm_doirq(int irq, uint32_t *regs) { struct tcb_s **running_task = &g_running_tasks[this_cpu()]; @@ -65,7 +76,7 @@ uint32_t *arm_doirq(int irq, uint32_t *regs) * is invalid, and we can safely overwrite it. */ - if (!(NVIC_IRQ_SVCALL == irq && regs[REG_R0] == SYS_restore_context)) + if (!restore_context(irq, regs)) { tcb->xcp.regs = regs; } diff --git a/arch/arm/src/armv8-m/arm_doirq.c b/arch/arm/src/armv8-m/arm_doirq.c index 18f6d1097bed7..178d9af065b22 100644 --- a/arch/arm/src/armv8-m/arm_doirq.c +++ b/arch/arm/src/armv8-m/arm_doirq.c @@ -67,6 +67,17 @@ void exception_direct(void) } } +static inline_function bool restore_context(int irq, uint32_t *regs) +{ + if ((NVIC_IRQ_SVCALL == irq || NVIC_IRQ_HARDFAULT == irq) && + regs[REG_R0] == SYS_restore_context) + { + return true; + } + + return false; +} + uint32_t *arm_doirq(int irq, uint32_t *regs) { struct tcb_s **running_task = &g_running_tasks[this_cpu()]; @@ -76,7 +87,7 @@ uint32_t *arm_doirq(int irq, uint32_t *regs) * is invalid, and we can safely overwrite it. */ - if (!(NVIC_IRQ_SVCALL == irq && regs[REG_R0] == SYS_restore_context)) + if (!restore_context(irq, regs)) { tcb->xcp.regs = regs; }