diff --git a/arch/xtensa/src/common/xtensa.h b/arch/xtensa/src/common/xtensa.h index 3f21f511fed..a657afc0be4 100644 --- a/arch/xtensa/src/common/xtensa.h +++ b/arch/xtensa/src/common/xtensa.h @@ -107,11 +107,9 @@ /* Context switching via system calls ***************************************/ -#define xtensa_context_restore(regs)\ - sys_call1(SYS_restore_context, (uintptr_t)regs) +#define xtensa_context_restore() sys_call0(SYS_restore_context) -#define xtensa_switchcontext(saveregs, restoreregs)\ - sys_call2(SYS_switch_context, (uintptr_t)saveregs, (uintptr_t)restoreregs) +#define xtensa_switchcontext() sys_call0(SYS_switch_context) /* Interrupt codes from other CPUs: */ diff --git a/arch/xtensa/src/common/xtensa_exit.c b/arch/xtensa/src/common/xtensa_exit.c index 44cedb9a299..fccc0ed3950 100644 --- a/arch/xtensa/src/common/xtensa_exit.c +++ b/arch/xtensa/src/common/xtensa_exit.c @@ -56,25 +56,17 @@ void up_exit(int status) { - struct tcb_s *tcb = this_task(); - /* Destroy the task at the head of the ready to run list. */ nxtask_exit(); - /* Now, perform the context switch to the new ready-to-run task at the - * head of the list. - */ - - tcb = this_task(); - /* Update g_running_tasks */ - g_running_tasks[this_cpu()] = tcb; + g_running_tasks[this_cpu()] = this_task(); /* Then switch contexts */ - xtensa_context_restore(tcb->xcp.regs); + xtensa_context_restore(); /* xtensa_context_restore() should not return but could if the * software interrupts are disabled. diff --git a/arch/xtensa/src/common/xtensa_sigdeliver.c b/arch/xtensa/src/common/xtensa_sigdeliver.c index b8ddd875955..c0914df6894 100644 --- a/arch/xtensa/src/common/xtensa_sigdeliver.c +++ b/arch/xtensa/src/common/xtensa_sigdeliver.c @@ -161,5 +161,8 @@ retry: leave_critical_section((regs[REG_PS])); rtcb->irqcount--; #endif - xtensa_context_restore(regs); + + rtcb->xcp.regs = rtcb->xcp.saved_regs; + xtensa_context_restore(); + UNUSED(regs); } diff --git a/arch/xtensa/src/common/xtensa_swint.c b/arch/xtensa/src/common/xtensa_swint.c index 9899543749f..5a356a8bcbc 100644 --- a/arch/xtensa/src/common/xtensa_swint.c +++ b/arch/xtensa/src/common/xtensa_swint.c @@ -61,7 +61,6 @@ int xtensa_swint(int irq, void *context, void *arg) { uint32_t *regs = (uint32_t *)context; struct tcb_s *tcb = this_task(); - uintptr_t *new_regs = regs; uint32_t cmd; DEBUGASSERT(regs != NULL); @@ -101,52 +100,14 @@ int xtensa_swint(int irq, void *context, void *arg) } break; - /* A2=SYS_restore_context: This is a restore context command: - * - * void xtensa_fullcontextrestore(uint32_t *restoreregs) - * noreturn_function; - * - * At this point, the following values are saved in context: - * - * A2 = SYS_restore_context - * A3 = restoreregs - * - * In this case, we simply need to set current_regs to restore - * register area referenced in the saved A3. context == current_regs - * is the normal exception return. By setting current_regs = - * context[A3], we force the return to the saved context referenced - * in A3. - */ - case SYS_restore_context: - { - DEBUGASSERT(regs[REG_A3] != 0); - new_regs = (uint32_t *)regs[REG_A3]; - tcb->xcp.regs = (uint32_t *)regs[REG_A3]; - } - break; - - /* A2=SYS_switch_context: This is a switch context command: - * - * void xtensa_switchcontext - * (uint32_t *saveregs, uint32_t *restoreregs); - * - * At this point, the following values are saved in context: - * - * A2 = SYS_switch_context - * A3 = saveregs - * A4 = restoreregs - * - * In this case, we do both: We save the context registers to the save - * register area reference by the saved contents of A3 and then set - * current_regs to the save register area referenced by the saved - * contents of A4. - */ - case SYS_switch_context: { - DEBUGASSERT(regs[REG_A4] != 0); - new_regs = (uint32_t *)regs[REG_A4]; + restore_critical_section(tcb, this_cpu()); +#ifdef CONFIG_DEBUG_SYSCALL_INFO + svcinfo("SYSCALL Return: Context switch!\n"); + up_dump_register(tcb->xcp.regs); +#endif } break; @@ -429,26 +390,5 @@ int xtensa_swint(int irq, void *context, void *arg) tcb->xcp.regs[REG_PS] &= ~PS_EXCM_MASK; } - /* Report what happened. That might difficult in the case of a context - * switch. - */ - -#ifdef CONFIG_DEBUG_SYSCALL_INFO - if (regs != new_regs) - { - svcinfo("SYSCALL Return: Context switch!\n"); - up_dump_register(new_regs); - } - else - { - svcinfo("SYSCALL Return: %" PRIu32 "\n", cmd); - } -#endif - - if (regs != new_regs) - { - restore_critical_section(this_task(), this_cpu()); - } - return OK; } diff --git a/arch/xtensa/src/common/xtensa_switchcontext.c b/arch/xtensa/src/common/xtensa_switchcontext.c index 58449456ab0..645b7f0f0f0 100644 --- a/arch/xtensa/src/common/xtensa_switchcontext.c +++ b/arch/xtensa/src/common/xtensa_switchcontext.c @@ -67,7 +67,7 @@ void up_switch_context(struct tcb_s *tcb, struct tcb_s *rtcb) * ready to run list. */ - xtensa_switchcontext(&rtcb->xcp.regs, tcb->xcp.regs); + xtensa_switchcontext(); /* xtensa_switchcontext forces a context switch to the task at the * head of the ready-to-run list. It does not 'return' in the diff --git a/arch/xtensa/src/esp32/esp32_cpustart.c b/arch/xtensa/src/esp32/esp32_cpustart.c index 61bd4a3ca9a..ed2fac49fca 100644 --- a/arch/xtensa/src/esp32/esp32_cpustart.c +++ b/arch/xtensa/src/esp32/esp32_cpustart.c @@ -188,7 +188,7 @@ void IRAM_ATTR xtensa_appcpu_start(void) * be the CPUs NULL task. */ - xtensa_context_restore(tcb->xcp.regs); + xtensa_context_restore(); } /**************************************************************************** diff --git a/arch/xtensa/src/esp32s3/esp32s3_cpustart.c b/arch/xtensa/src/esp32s3/esp32s3_cpustart.c index 1f933770fc3..13763c643ad 100644 --- a/arch/xtensa/src/esp32s3/esp32s3_cpustart.c +++ b/arch/xtensa/src/esp32s3/esp32s3_cpustart.c @@ -173,7 +173,7 @@ void xtensa_appcpu_start(void) * be the CPUs NULL task. */ - xtensa_context_restore(tcb->xcp.regs); + xtensa_context_restore(); } /****************************************************************************