diff --git a/arch/xtensa/include/irq.h b/arch/xtensa/include/irq.h index f680b3dec0..4ff557f1b6 100644 --- a/arch/xtensa/include/irq.h +++ b/arch/xtensa/include/irq.h @@ -360,17 +360,9 @@ extern "C" ****************************************************************************/ #ifndef __ASSEMBLY__ -/* g_current_regs[] holds a references to the current interrupt level - * register storage structure. If is non-NULL only during interrupt - * processing. Access to g_current_regs[] must be through the - * [get/set]_current_regs for portability. - */ +/* g_interrupt_context store irq status */ -/* For the case of architectures with multiple CPUs, then there must be one - * such value for each processor that can receive an interrupt. - */ - -EXTERN volatile uint32_t *g_current_regs[CONFIG_SMP_NCPUS]; +extern volatile bool g_interrupt_context[CONFIG_SMP_NCPUS]; #endif /**************************************************************************** @@ -413,22 +405,21 @@ irqstate_t xtensa_disable_interrupts(irqstate_t mask); int up_cpu_index(void) noinstrument_function; #endif /* CONFIG_ARCH_HAVE_MULTICPU */ -noinstrument_function static inline_function uint32_t *up_current_regs(void) -{ -#ifdef CONFIG_SMP - return (uint32_t *)g_current_regs[up_cpu_index()]; -#else - return (uint32_t *)g_current_regs[0]; -#endif -} +/**************************************************************************** + * Name: up_set_interrupt_context + * + * Description: + * Set the interrupt handler context. + * + ****************************************************************************/ noinstrument_function -static inline_function void up_set_current_regs(uint32_t *regs) +static inline_function void up_set_interrupt_context(bool flag) { #ifdef CONFIG_SMP - g_current_regs[up_cpu_index()] = regs; + g_interrupt_context[up_cpu_index()] = flag; #else - g_current_regs[0] = regs; + g_interrupt_context[0] = flag; #endif } @@ -446,15 +437,12 @@ noinstrument_function static inline_function bool up_interrupt_context(void) { #ifdef CONFIG_SMP irqstate_t flags = up_irq_save(); -#endif - - bool ret = up_current_regs() != NULL; - -#ifdef CONFIG_SMP + bool ret = g_interrupt_context[up_cpu_index()]; up_irq_restore(flags); -#endif - return ret; +#else + return g_interrupt_context[0]; +#endif } #endif @@ -463,7 +451,7 @@ noinstrument_function static inline_function bool up_interrupt_context(void) ****************************************************************************/ #define up_getusrpc(regs) \ - (((uint32_t *)((regs) ? (regs) : up_current_regs()))[REG_PC]) + (((uint32_t *)((regs) ? (regs) : running_regs()))[REG_PC]) #undef EXTERN #ifdef __cplusplus diff --git a/arch/xtensa/src/common/xtensa_assert.c b/arch/xtensa/src/common/xtensa_assert.c index e3a6abbff2..ed9bd61bf9 100644 --- a/arch/xtensa/src/common/xtensa_assert.c +++ b/arch/xtensa/src/common/xtensa_assert.c @@ -65,14 +65,7 @@ void xtensa_panic(int xptcode, uint32_t *regs) { - struct tcb_s **running_task = &g_running_tasks[this_cpu()]; - - if (*running_task != NULL) - { - (*running_task)->xcp.regs = regs; - } - - up_set_current_regs(regs); + up_set_interrupt_context(true); /* We get here when a un-dispatch-able, irrecoverable exception occurs */ @@ -171,7 +164,14 @@ void xtensa_panic(int xptcode, uint32_t *regs) void xtensa_user_panic(int exccause, uint32_t *regs) { - up_set_current_regs(regs); + struct tcb_s **running_task = &g_running_tasks[this_cpu()]; + + if (*running_task != NULL) + { + (*running_task)->xcp.regs = regs; + } + + up_set_interrupt_context(true); /* We get here when a un-dispatch-able, irrecoverable exception occurs */ diff --git a/arch/xtensa/src/common/xtensa_backtrace.c b/arch/xtensa/src/common/xtensa_backtrace.c index fb6da7a144..22a590f5fb 100644 --- a/arch/xtensa/src/common/xtensa_backtrace.c +++ b/arch/xtensa/src/common/xtensa_backtrace.c @@ -277,8 +277,8 @@ int up_backtrace(struct tcb_s *tcb, void **buffer, int size, int skip) #endif ret += backtrace_stack(rtcb->stack_base_ptr, rtcb->stack_base_ptr + rtcb->adj_stack_size, - (void *)up_current_regs()[REG_A1], - (void *)up_current_regs()[REG_A0], + running_regs()[REG_A1], + running_regs()[REG_A0], &buffer[ret], size - ret, &skip); } else diff --git a/arch/xtensa/src/common/xtensa_initialize.c b/arch/xtensa/src/common/xtensa_initialize.c index 4a8af33cf8..9474f3401e 100644 --- a/arch/xtensa/src/common/xtensa_initialize.c +++ b/arch/xtensa/src/common/xtensa_initialize.c @@ -32,17 +32,9 @@ * Public Data ****************************************************************************/ -/* g_current_regs[] holds a reference to the current interrupt level - * register storage structure. It is non-NULL only during interrupt - * processing. Access to g_current_regs[] must be through the - * [get/set]_current_regs for portability. - */ +/* g_interrupt_context store irq status */ -/* For the case of architectures with multiple CPUs, then there must be one - * such value for each processor that can receive an interrupt. - */ - -volatile uint32_t *g_current_regs[CONFIG_SMP_NCPUS]; +volatile bool g_interrupt_context[CONFIG_SMP_NCPUS]; /**************************************************************************** * Private Functions diff --git a/arch/xtensa/src/common/xtensa_irqdispatch.c b/arch/xtensa/src/common/xtensa_irqdispatch.c index 46e848c777..d694ea251d 100644 --- a/arch/xtensa/src/common/xtensa_irqdispatch.c +++ b/arch/xtensa/src/common/xtensa_irqdispatch.c @@ -57,13 +57,11 @@ uint32_t *xtensa_irq_dispatch(int irq, uint32_t *regs) /* Nested interrupts are not supported */ - DEBUGASSERT(up_current_regs() == NULL); + DEBUGASSERT(!up_interrupt_context()); - /* Current regs non-zero indicates that we are processing an interrupt; - * current_regs is also used to manage interrupt level context switches. - */ + /* Set irq flag */ - up_set_current_regs(regs); + up_set_interrupt_context(true); if (*running_task != NULL) { @@ -104,11 +102,9 @@ uint32_t *xtensa_irq_dispatch(int irq, uint32_t *regs) *running_task = tcb; } - /* Set current_regs to NULL to indicate that we are no longer in an - * interrupt handler. - */ + /* Set irq flag */ - up_set_current_regs(NULL); + up_set_interrupt_context(false); #endif board_autoled_off(LED_INIRQ); diff --git a/arch/xtensa/src/common/xtensa_registerdump.c b/arch/xtensa/src/common/xtensa_registerdump.c index 78eaad07af..9bba0b0140 100644 --- a/arch/xtensa/src/common/xtensa_registerdump.c +++ b/arch/xtensa/src/common/xtensa_registerdump.c @@ -53,7 +53,7 @@ uintptr_t up_getusrsp(void *regs) void up_dump_register(void *dumpregs) { - volatile uintptr_t *regs = dumpregs ? dumpregs : up_current_regs(); + volatile uintptr_t *regs = dumpregs ? dumpregs : running_regs(); _alert(" PC: %08lx PS: %08lx\n", (unsigned long)regs[REG_PC], (unsigned long)regs[REG_PS]);