diff --git a/arch/arm/include/irq.h b/arch/arm/include/irq.h index d6fd08cdddb23..6f96b99511557 100644 --- a/arch/arm/include/irq.h +++ b/arch/arm/include/irq.h @@ -82,13 +82,13 @@ #ifndef __ASSEMBLY__ #ifndef up_switch_context -#define up_switch_context(tcb, rtcb) \ - do { \ - if (!up_interrupt_context()) \ - { \ - sys_call2(SYS_switch_context, (uintptr_t)&rtcb->xcp.regs, \ - (uintptr_t)tcb->xcp.regs); \ - } \ +#define up_switch_context(tcb, rtcb) \ + do { \ + if (!up_interrupt_context()) \ + { \ + sys_call0(SYS_switch_context); \ + } \ + UNUSED(rtcb); \ } while (0) #endif diff --git a/arch/arm/src/arm/arm_allocpage.c b/arch/arm/src/arm/arm_allocpage.c index 003ffa7267a4a..359fc60a03d24 100644 --- a/arch/arm/src/arm/arm_allocpage.c +++ b/arch/arm/src/arm/arm_allocpage.c @@ -36,8 +36,8 @@ #include -#include "pg_macros.h" #include "arm_internal.h" +#include "pg_macros.h" /**************************************************************************** * Pre-processor Definitions diff --git a/arch/arm/src/arm/arm_sigdeliver.c b/arch/arm/src/arm/arm_sigdeliver.c index b55e820604f65..a0ab5f36fb7c4 100644 --- a/arch/arm/src/arm/arm_sigdeliver.c +++ b/arch/arm/src/arm/arm_sigdeliver.c @@ -54,7 +54,6 @@ void arm_sigdeliver(void) { struct tcb_s *rtcb = this_task(); - uint32_t *regs = rtcb->xcp.saved_regs; board_autoled_on(LED_SIGNAL); @@ -98,6 +97,6 @@ void arm_sigdeliver(void) board_autoled_off(LED_SIGNAL); - g_running_tasks[this_cpu()] = NULL; - arm_fullcontextrestore(regs); + rtcb->xcp.regs = rtcb->xcp.saved_regs; + arm_fullcontextrestore(); } diff --git a/arch/arm/src/arm/arm_syscall.c b/arch/arm/src/arm/arm_syscall.c index 338c2216e6857..3903159bfdada 100644 --- a/arch/arm/src/arm/arm_syscall.c +++ b/arch/arm/src/arm/arm_syscall.c @@ -54,7 +54,8 @@ uint32_t *arm_syscall(uint32_t *regs) { - struct tcb_s **running_task = &g_running_tasks[this_cpu()]; + int cpu = this_cpu(); + struct tcb_s **running_task = &g_running_tasks[cpu]; FAR struct tcb_s *tcb = this_task(); uint32_t cmd; @@ -62,12 +63,9 @@ uint32_t *arm_syscall(uint32_t *regs) DEBUGASSERT(!up_interrupt_context()); - if (*running_task != NULL) - { - (*running_task)->xcp.regs = regs; - } - - /* Set irq flag */ + /* Current regs non-zero indicates that we are processing an interrupt; + * current_regs is also used to manage interrupt level context switches. + */ up_set_interrupt_context(true); @@ -75,51 +73,35 @@ uint32_t *arm_syscall(uint32_t *regs) cmd = regs[REG_R0]; + /* if cmd == SYS_restore_context (*running_task)->xcp.regs is valid + * should not be overwriten + */ + + if (cmd != SYS_restore_context) + { + (*running_task)->xcp.regs = regs; + } + /* Handle the SVCall according to the command in R0 */ switch (cmd) { - /* R0=SYS_restore_context: Restore task context - * - * void arm_fullcontextrestore(uint32_t *restoreregs) - * noreturn_function; - * - * At this point, the following values are saved in context: - * - * R0 = SYS_restore_context - * R1 = restoreregs - */ + case SYS_switch_context: - case SYS_restore_context: - { - /* Replace 'regs' with the pointer to the register set in - * regs[REG_R1]. On return from the system call, that register - * set will determine the restored context. - */ + /* Update scheduler parameters */ - tcb->xcp.regs = (uint32_t *)regs[REG_R1]; - DEBUGASSERT(up_interrupt_context()); - } - break; + nxsched_resume_scheduler(tcb); + + case SYS_restore_context: + nxsched_suspend_scheduler(*running_task); + *running_task = tcb; - /* R0=SYS_switch_context: This a switch context command: - * - * void arm_switchcontext(uint32_t **saveregs, - * uint32_t *restoreregs); - * - * At this point, the following values are saved in context: - * - * R0 = SYS_switch_context - * R1 = saveregs - * R2 = restoreregs - * - * In this case, we do both: We save the context registers to the save - * register area reference by the saved contents of R1 and then set - * regs to the save register area referenced by the saved - * contents of R2. - */ + /* Restore the cpu lock */ - case SYS_switch_context: + restore_critical_section(tcb, cpu); +#ifdef CONFIG_ARCH_ADDRENV + addrenv_switch(tcb); +#endif break; default: @@ -131,29 +113,6 @@ uint32_t *arm_syscall(uint32_t *regs) break; } - if (*running_task != tcb) - { -#ifdef CONFIG_ARCH_ADDRENV - /* Make sure that the address environment for the previously - * running task is closed down gracefully (data caches dump, - * MMU flushed) and set up the address environment for the new - * thread at the head of the ready-to-run list. - */ - - addrenv_switch(NULL); -#endif - /* Update scheduler parameters */ - - nxsched_suspend_scheduler(*running_task); - nxsched_resume_scheduler(tcb); - - *running_task = tcb; - - /* Restore the cpu lock */ - - restore_critical_section(tcb, this_cpu()); - } - /* Set irq flag */ up_set_interrupt_context(false); diff --git a/arch/arm/src/armv6-m/arm_doirq.c b/arch/arm/src/armv6-m/arm_doirq.c index 9c9e78d3cfd00..e3e6383e48a71 100644 --- a/arch/arm/src/armv6-m/arm_doirq.c +++ b/arch/arm/src/armv6-m/arm_doirq.c @@ -59,7 +59,11 @@ uint32_t *arm_doirq(int irq, uint32_t *regs) struct tcb_s **running_task = &g_running_tasks[this_cpu()]; FAR struct tcb_s *tcb; - if (*running_task != NULL) + /* This judgment proves that (*running_task)->xcp.regs + * is invalid, and we can safely overwrite it. + */ + + if (!(NVIC_IRQ_SVCALL == irq && regs[REG_R0] == SYS_restore_context)) { (*running_task)->xcp.regs = regs; } diff --git a/arch/arm/src/armv6-m/arm_sigdeliver.c b/arch/arm/src/armv6-m/arm_sigdeliver.c index fa6797351d086..73ad65e14ad73 100644 --- a/arch/arm/src/armv6-m/arm_sigdeliver.c +++ b/arch/arm/src/armv6-m/arm_sigdeliver.c @@ -162,5 +162,8 @@ void arm_sigdeliver(void) leave_critical_section((uint16_t)regs[REG_PRIMASK]); rtcb->irqcount--; #endif - arm_fullcontextrestore(regs); + + rtcb->xcp.regs = rtcb->xcp.saved_regs; + arm_fullcontextrestore(); + UNUSED(regs); } diff --git a/arch/arm/src/armv6-m/arm_svcall.c b/arch/arm/src/armv6-m/arm_svcall.c index 2ae54ac4ec2bd..3ef29e4c4773a 100644 --- a/arch/arm/src/armv6-m/arm_svcall.c +++ b/arch/arm/src/armv6-m/arm_svcall.c @@ -117,9 +117,8 @@ static void dispatch_syscall(void) int arm_svcall(int irq, void *context, void *arg) { - struct tcb_s *tcb = this_task(); uint32_t *regs = (uint32_t *)context; - uint32_t *new_regs = regs; + struct tcb_s *tcb; uint32_t cmd; cmd = regs[REG_R0]; @@ -149,41 +148,15 @@ int arm_svcall(int irq, void *context, void *arg) switch (cmd) { - /* R0=SYS_restore_context: This a restore context command: - * - * void arm_fullcontextrestore(uint32_t *restoreregs) - * noreturn_function; - * - * At this point, the following values are saved in context: - * - * R0 = SYS_restore_context - * R1 = restoreregs - */ - case SYS_restore_context: - { - DEBUGASSERT(regs[REG_R1] != 0); - new_regs = (uint32_t *)regs[REG_R1]; - tcb->xcp.regs = (uint32_t *)regs[REG_R1]; - } - break; - - /* R0=SYS_switch_context: This a switch context command: - * - * void arm_switchcontext(uint32_t **saveregs, - * uint32_t *restoreregs); - * - * At this point, the following values are saved in context: - * - * R0 = SYS_switch_context - * R1 = saveregs - * R2 = restoreregs - */ - case SYS_switch_context: { - DEBUGASSERT(regs[REG_R1] != 0 && regs[REG_R2] != 0); - new_regs = (uint32_t *)regs[REG_R2]; + tcb = this_task(); + restore_critical_section(tcb, this_cpu()); + +#ifdef CONFIG_DEBUG_SYSCALL_INFO + regs = tcb->xcp.regs; +#endif } break; @@ -437,13 +410,11 @@ int arm_svcall(int irq, void *context, void *arg) * switch. */ - if (regs != new_regs) - { - restore_critical_section(tcb, this_cpu()); - #ifdef CONFIG_DEBUG_SYSCALL_INFO - regs = new_regs; - +# ifndef CONFIG_DEBUG_SVCALL + if (cmd > SYS_switch_context) +# endif + { svcinfo("SVCall Return:\n"); svcinfo(" R0: %08x %08x %08x %08x %08x %08x %08x %08x\n", regs[REG_R0], regs[REG_R1], regs[REG_R2], regs[REG_R3], @@ -453,14 +424,9 @@ int arm_svcall(int irq, void *context, void *arg) regs[REG_R12], regs[REG_R13], regs[REG_R14], regs[REG_R15]); svcinfo(" PSR: %08x EXC_RETURN: %08x CONTROL: %08x\n", regs[REG_XPSR], regs[REG_EXC_RETURN], regs[REG_CONTROL]); -#endif - } -#ifdef CONFIG_DEBUG_SYSCALL_INFO - else - { - svcinfo("SVCall Return: %d\n", regs[REG_R0]); } #endif + UNUSED(tcb); return OK; } diff --git a/arch/arm/src/armv7-a/arm_sigdeliver.c b/arch/arm/src/armv7-a/arm_sigdeliver.c index 1867aa8844605..5de0caa880af6 100644 --- a/arch/arm/src/armv7-a/arm_sigdeliver.c +++ b/arch/arm/src/armv7-a/arm_sigdeliver.c @@ -161,6 +161,7 @@ void arm_sigdeliver(void) rtcb->irqcount--; #endif - g_running_tasks[this_cpu()] = NULL; - arm_fullcontextrestore(regs); + rtcb->xcp.regs = rtcb->xcp.saved_regs; + arm_fullcontextrestore(); + UNUSED(regs); } diff --git a/arch/arm/src/armv7-a/arm_syscall.c b/arch/arm/src/armv7-a/arm_syscall.c index 3e43e961bfd83..df7f68d1ffc38 100644 --- a/arch/arm/src/armv7-a/arm_syscall.c +++ b/arch/arm/src/armv7-a/arm_syscall.c @@ -159,7 +159,8 @@ static void dispatch_syscall(void) uint32_t *arm_syscall(uint32_t *regs) { - struct tcb_s **running_task = &g_running_tasks[this_cpu()]; + int cpu = this_cpu(); + struct tcb_s **running_task = &g_running_tasks[cpu]; struct tcb_s *tcb = this_task(); uint32_t cmd; #ifdef CONFIG_BUILD_KERNEL @@ -170,12 +171,9 @@ uint32_t *arm_syscall(uint32_t *regs) DEBUGASSERT(!up_interrupt_context()); - if (*running_task != NULL) - { - (*running_task)->xcp.regs = regs; - } - - /* Set irq flag */ + /* Current regs non-zero indicates that we are processing an interrupt; + * current_regs is also used to manage interrupt level context switches. + */ up_set_interrupt_context(true); @@ -183,6 +181,15 @@ uint32_t *arm_syscall(uint32_t *regs) cmd = regs[REG_R0]; + /* if cmd == SYS_restore_context (*running_task)->xcp.regs is valid + * should not be overwriten + */ + + if (cmd != SYS_restore_context) + { + (*running_task)->xcp.regs = regs; + } + /* The SVCall software interrupt is called with R0 = system call command * and R1..R7 = variable number of arguments depending on the system call. */ @@ -256,47 +263,23 @@ uint32_t *arm_syscall(uint32_t *regs) break; #endif - /* R0=SYS_restore_context: Restore task context - * - * void arm_fullcontextrestore(uint32_t *restoreregs) - * noreturn_function; - * - * At this point, the following values are saved in context: - * - * R0 = SYS_restore_context - * R1 = restoreregs - */ + case SYS_switch_context: - case SYS_restore_context: - { - /* Replace 'regs' with the pointer to the register set in - * regs[REG_R1]. On return from the system call, that register - * set will determine the restored context. - */ + /* Update scheduler parameters */ - tcb->xcp.regs = (uint32_t *)regs[REG_R1]; - DEBUGASSERT(up_interrupt_context()); - } - break; + nxsched_resume_scheduler(tcb); - /* R0=SYS_switch_context: This a switch context command: - * - * void arm_switchcontext(uint32_t **saveregs, - * uint32_t *restoreregs); - * - * At this point, the following values are saved in context: - * - * R0 = SYS_switch_context - * R1 = saveregs - * R2 = restoreregs - * - * In this case, we do both: We save the context registers to the save - * register area reference by the saved contents of R1 and then set - * regs to the save register area referenced by the saved - * contents of R2. - */ + case SYS_restore_context: + nxsched_suspend_scheduler(*running_task); + *running_task = tcb; - case SYS_switch_context: + /* Restore the cpu lock */ + + restore_critical_section(tcb, cpu); + regs = tcb->xcp.regs; +#ifdef CONFIG_ARCH_ADDRENV + addrenv_switch(tcb); +#endif break; /* R0=SYS_task_start: This a user task start @@ -562,35 +545,6 @@ uint32_t *arm_syscall(uint32_t *regs) break; } - if (*running_task != tcb) - { -#ifdef CONFIG_ARCH_ADDRENV - /* Make sure that the address environment for the previously - * running task is closed down gracefully (data caches dump, - * MMU flushed) and set up the address environment for the new - * thread at the head of the ready-to-run list. - */ - - addrenv_switch(NULL); -#endif - - /* Update scheduler parameters */ - - nxsched_suspend_scheduler(*running_task); - nxsched_resume_scheduler(tcb); - - /* Record the new "running" task. g_running_tasks[] is only used by - * assertion logic for reporting crashes. - */ - - *running_task = tcb; - - /* Restore the cpu lock */ - - restore_critical_section(tcb, this_cpu()); - regs = tcb->xcp.regs; - } - /* Report what happened */ dump_syscall("Exit", cmd, regs); diff --git a/arch/arm/src/armv7-m/arm_doirq.c b/arch/arm/src/armv7-m/arm_doirq.c index 9989437e4752c..dcbdd9dc12a8f 100644 --- a/arch/arm/src/armv7-m/arm_doirq.c +++ b/arch/arm/src/armv7-m/arm_doirq.c @@ -59,7 +59,11 @@ uint32_t *arm_doirq(int irq, uint32_t *regs) struct tcb_s **running_task = &g_running_tasks[this_cpu()]; FAR struct tcb_s *tcb; - if (*running_task != NULL) + /* This judgment proves that (*running_task)->xcp.regs + * is invalid, and we can safely overwrite it. + */ + + if (!(NVIC_IRQ_SVCALL == irq && regs[REG_R0] == SYS_restore_context)) { (*running_task)->xcp.regs = regs; } diff --git a/arch/arm/src/armv7-m/arm_sigdeliver.c b/arch/arm/src/armv7-m/arm_sigdeliver.c index 524f2c445b691..3d617ea46a5e4 100644 --- a/arch/arm/src/armv7-m/arm_sigdeliver.c +++ b/arch/arm/src/armv7-m/arm_sigdeliver.c @@ -174,5 +174,8 @@ void arm_sigdeliver(void) #endif rtcb->irqcount--; #endif - arm_fullcontextrestore(regs); + + rtcb->xcp.regs = rtcb->xcp.saved_regs; + arm_fullcontextrestore(); + UNUSED(regs); } diff --git a/arch/arm/src/armv7-m/arm_svcall.c b/arch/arm/src/armv7-m/arm_svcall.c index cd3a7e214a667..03e9a43abbb77 100644 --- a/arch/arm/src/armv7-m/arm_svcall.c +++ b/arch/arm/src/armv7-m/arm_svcall.c @@ -125,9 +125,8 @@ static void dispatch_syscall(void) int arm_svcall(int irq, void *context, void *arg) { - struct tcb_s *tcb = this_task(); uint32_t *regs = (uint32_t *)context; - uint32_t *new_regs = regs; + struct tcb_s *tcb; uint32_t cmd; cmd = regs[REG_R0]; @@ -157,41 +156,15 @@ int arm_svcall(int irq, void *context, void *arg) switch (cmd) { - /* R0=SYS_restore_context: This a restore context command: - * - * void arm_fullcontextrestore(uint32_t *restoreregs) - * noreturn_function; - * - * At this point, the following values are saved in context: - * - * R0 = SYS_restore_context - * R1 = restoreregs - */ - case SYS_restore_context: - { - DEBUGASSERT(regs[REG_R1] != 0); - new_regs = (uint32_t *)regs[REG_R1]; - tcb->xcp.regs = (uint32_t *)regs[REG_R1]; - } - break; - - /* R0=SYS_switch_context: This a switch context command: - * - * void arm_switchcontext(uint32_t **saveregs, - * uint32_t *restoreregs); - * - * At this point, the following values are saved in context: - * - * R0 = SYS_switch_context - * R1 = saveregs - * R2 = restoreregs - */ - case SYS_switch_context: { - DEBUGASSERT(regs[REG_R1] != 0 && regs[REG_R2] != 0); - new_regs = (uint32_t *)regs[REG_R2]; + tcb = this_task(); + restore_critical_section(tcb, this_cpu()); + +#ifdef CONFIG_DEBUG_SYSCALL_INFO + regs = tcb->xcp.regs; +#endif } break; @@ -446,13 +419,11 @@ int arm_svcall(int irq, void *context, void *arg) * switch. */ - if (regs != new_regs) - { - restore_critical_section(tcb, this_cpu()); - #ifdef CONFIG_DEBUG_SYSCALL_INFO - regs = new_regs; - +# ifndef CONFIG_DEBUG_SVCALL + if (cmd > SYS_switch_context) +# endif + { svcinfo("SVCall Return:\n"); svcinfo(" R0: %08x %08x %08x %08x %08x %08x %08x %08x\n", regs[REG_R0], regs[REG_R1], regs[REG_R2], regs[REG_R3], @@ -462,14 +433,9 @@ int arm_svcall(int irq, void *context, void *arg) regs[REG_R12], regs[REG_R13], regs[REG_R14], regs[REG_R15]); svcinfo(" PSR: %08x EXC_RETURN: %08x CONTROL: %08x\n", regs[REG_XPSR], regs[REG_EXC_RETURN], regs[REG_CONTROL]); -#endif - } -#ifdef CONFIG_DEBUG_SYSCALL_INFO - else - { - svcinfo("SVCall Return: %d\n", regs[REG_R0]); } #endif + UNUSED(tcb); return OK; } diff --git a/arch/arm/src/armv7-r/arm_sigdeliver.c b/arch/arm/src/armv7-r/arm_sigdeliver.c index 5a63458b9b04f..bd715470cd519 100644 --- a/arch/arm/src/armv7-r/arm_sigdeliver.c +++ b/arch/arm/src/armv7-r/arm_sigdeliver.c @@ -158,6 +158,7 @@ void arm_sigdeliver(void) rtcb->irqcount--; #endif - g_running_tasks[this_cpu()] = NULL; - arm_fullcontextrestore(regs); + rtcb->xcp.regs = rtcb->xcp.saved_regs; + arm_fullcontextrestore(); + UNUSED(regs); } diff --git a/arch/arm/src/armv7-r/arm_syscall.c b/arch/arm/src/armv7-r/arm_syscall.c index 414518012e88f..179b27baaeff9 100644 --- a/arch/arm/src/armv7-r/arm_syscall.c +++ b/arch/arm/src/armv7-r/arm_syscall.c @@ -156,7 +156,8 @@ static void dispatch_syscall(void) uint32_t *arm_syscall(uint32_t *regs) { - struct tcb_s **running_task = &g_running_tasks[this_cpu()]; + int cpu = this_cpu(); + struct tcb_s **running_task = &g_running_tasks[cpu]; FAR struct tcb_s *tcb = this_task(); uint32_t cmd; #ifdef CONFIG_BUILD_PROTECTED @@ -167,12 +168,9 @@ uint32_t *arm_syscall(uint32_t *regs) DEBUGASSERT(!up_interrupt_context()); - if (*running_task != NULL) - { - (*running_task)->xcp.regs = regs; - } - - /* Set irq flag */ + /* Current regs non-zero indicates that we are processing an interrupt; + * current_regs is also used to manage interrupt level context switches. + */ up_set_interrupt_context(true); @@ -180,6 +178,15 @@ uint32_t *arm_syscall(uint32_t *regs) cmd = regs[REG_R0]; + /* if cmd == SYS_restore_context (*running_task)->xcp.regs is valid + * should not be overwriten + */ + + if (cmd != SYS_restore_context) + { + (*running_task)->xcp.regs = regs; + } + /* The SVCall software interrupt is called with R0 = system call command * and R1..R7 = variable number of arguments depending on the system call. */ @@ -253,47 +260,23 @@ uint32_t *arm_syscall(uint32_t *regs) break; #endif - /* R0=SYS_restore_context: Restore task context - * - * void arm_fullcontextrestore(uint32_t *restoreregs) - * noreturn_function; - * - * At this point, the following values are saved in context: - * - * R0 = SYS_restore_context - * R1 = restoreregs - */ + case SYS_switch_context: - case SYS_restore_context: - { - /* Replace 'regs' with the pointer to the register set in - * regs[REG_R1]. On return from the system call, that register - * set will determine the restored context. - */ + /* Update scheduler parameters */ - tcb->xcp.regs = (uint32_t *)regs[REG_R1]; - DEBUGASSERT(up_interrupt_context()); - } - break; + nxsched_resume_scheduler(tcb); - /* R0=SYS_switch_context: This a switch context command: - * - * void arm_switchcontext(uint32_t **saveregs, - * uint32_t *restoreregs); - * - * At this point, the following values are saved in context: - * - * R0 = SYS_switch_context - * R1 = saveregs - * R2 = restoreregs - * - * In this case, we do both: We save the context registers to the save - * register area reference by the saved contents of R1 and then set - * regs to the save register area referenced by the saved - * contents of R2. - */ + case SYS_restore_context: + nxsched_suspend_scheduler(*running_task); + *running_task = tcb; - case SYS_switch_context: + /* Restore the cpu lock */ + + restore_critical_section(tcb, cpu); + regs = tcb->xcp.regs; +#ifdef CONFIG_ARCH_ADDRENV + addrenv_switch(tcb); +#endif break; /* R0=SYS_task_start: This a user task start @@ -559,25 +542,6 @@ uint32_t *arm_syscall(uint32_t *regs) break; } - if (*running_task != tcb) - { - /* Update scheduler parameters */ - - nxsched_suspend_scheduler(*running_task); - nxsched_resume_scheduler(tcb); - - /* Record the new "running" task. g_running_tasks[] is only used by - * assertion logic for reporting crashes. - */ - - *running_task = tcb; - - /* Restore the cpu lock */ - - restore_critical_section(tcb, this_cpu()); - regs = tcb->xcp.regs; - } - /* Report what happened */ dump_syscall("Exit", cmd, regs); diff --git a/arch/arm/src/armv8-m/arm_doirq.c b/arch/arm/src/armv8-m/arm_doirq.c index 3cd28ae2989f3..55183573a54fb 100644 --- a/arch/arm/src/armv8-m/arm_doirq.c +++ b/arch/arm/src/armv8-m/arm_doirq.c @@ -70,7 +70,11 @@ uint32_t *arm_doirq(int irq, uint32_t *regs) struct tcb_s **running_task = &g_running_tasks[this_cpu()]; FAR struct tcb_s *tcb; - if (*running_task != NULL) + /* This judgment proves that (*running_task)->xcp.regs + * is invalid, and we can safely overwrite it. + */ + + if (!(NVIC_IRQ_SVCALL == irq && regs[REG_R0] == SYS_restore_context)) { (*running_task)->xcp.regs = regs; } diff --git a/arch/arm/src/armv8-m/arm_sigdeliver.c b/arch/arm/src/armv8-m/arm_sigdeliver.c index 2db03f17d166b..43d72e35a8da8 100644 --- a/arch/arm/src/armv8-m/arm_sigdeliver.c +++ b/arch/arm/src/armv8-m/arm_sigdeliver.c @@ -174,5 +174,8 @@ void arm_sigdeliver(void) #endif rtcb->irqcount--; #endif - arm_fullcontextrestore(regs); + + rtcb->xcp.regs = rtcb->xcp.saved_regs; + arm_fullcontextrestore(); + UNUSED(regs); } diff --git a/arch/arm/src/armv8-m/arm_svcall.c b/arch/arm/src/armv8-m/arm_svcall.c index 2a42d19dc7dc8..5082ee952e321 100644 --- a/arch/arm/src/armv8-m/arm_svcall.c +++ b/arch/arm/src/armv8-m/arm_svcall.c @@ -125,9 +125,8 @@ static void dispatch_syscall(void) int arm_svcall(int irq, void *context, void *arg) { - struct tcb_s *tcb = this_task(); uint32_t *regs = (uint32_t *)context; - uint32_t *new_regs = regs; + struct tcb_s *tcb; uint32_t cmd; cmd = regs[REG_R0]; @@ -157,41 +156,15 @@ int arm_svcall(int irq, void *context, void *arg) switch (cmd) { - /* R0=SYS_restore_context: This a restore context command: - * - * void arm_fullcontextrestore(uint32_t *restoreregs) - * noreturn_function; - * - * At this point, the following values are saved in context: - * - * R0 = SYS_restore_context - * R1 = restoreregs - */ - case SYS_restore_context: - { - DEBUGASSERT(regs[REG_R1] != 0); - new_regs = (uint32_t *)regs[REG_R1]; - tcb->xcp.regs = (uint32_t *)regs[REG_R1]; - } - break; - - /* R0=SYS_switch_context: This a switch context command: - * - * void arm_switchcontext(uint32_t **saveregs, - * uint32_t *restoreregs); - * - * At this point, the following values are saved in context: - * - * R0 = SYS_switch_context - * R1 = saveregs - * R2 = restoreregs - */ - case SYS_switch_context: { - DEBUGASSERT(regs[REG_R1] != 0 && regs[REG_R2] != 0); - new_regs = (uint32_t *)regs[REG_R2]; + tcb = this_task(); + restore_critical_section(tcb, this_cpu()); + +#ifdef CONFIG_DEBUG_SYSCALL_INFO + regs = tcb->xcp.regs; +#endif } break; @@ -446,13 +419,11 @@ int arm_svcall(int irq, void *context, void *arg) * switch. */ - if (regs != new_regs) - { - restore_critical_section(tcb, this_cpu()); - #ifdef CONFIG_DEBUG_SYSCALL_INFO - regs = new_regs; - +# ifndef CONFIG_DEBUG_SVCALL + if (cmd > SYS_switch_context) +# endif + { svcinfo("SVCall Return:\n"); svcinfo(" R0: %08x %08x %08x %08x %08x %08x %08x %08x\n", regs[REG_R0], regs[REG_R1], regs[REG_R2], regs[REG_R3], @@ -462,14 +433,9 @@ int arm_svcall(int irq, void *context, void *arg) regs[REG_R12], regs[REG_R13], regs[REG_R14], regs[REG_R15]); svcinfo(" PSR: %08x EXC_RETURN: %08x CONTROL: %08x\n", regs[REG_XPSR], regs[REG_EXC_RETURN], regs[REG_CONTROL]); -#endif - } -#ifdef CONFIG_DEBUG_SYSCALL_INFO - else - { - svcinfo("SVCall Return: %d\n", regs[REG_R0]); } #endif + UNUSED(tcb); return OK; } diff --git a/arch/arm/src/armv8-r/arm_sigdeliver.c b/arch/arm/src/armv8-r/arm_sigdeliver.c index e4a8ad59353b1..17fbc7b19839e 100644 --- a/arch/arm/src/armv8-r/arm_sigdeliver.c +++ b/arch/arm/src/armv8-r/arm_sigdeliver.c @@ -156,6 +156,7 @@ void arm_sigdeliver(void) rtcb->irqcount--; #endif - g_running_tasks[this_cpu()] = NULL; - arm_fullcontextrestore(regs); + rtcb->xcp.regs = rtcb->xcp.saved_regs; + arm_fullcontextrestore(); + UNUSED(regs); } diff --git a/arch/arm/src/armv8-r/arm_syscall.c b/arch/arm/src/armv8-r/arm_syscall.c index f1a4d8175b08e..d003166840754 100644 --- a/arch/arm/src/armv8-r/arm_syscall.c +++ b/arch/arm/src/armv8-r/arm_syscall.c @@ -156,7 +156,8 @@ static void dispatch_syscall(void) uint32_t *arm_syscall(uint32_t *regs) { - struct tcb_s **running_task = &g_running_tasks[this_cpu()]; + int cpu = this_cpu(); + struct tcb_s **running_task = &g_running_tasks[cpu]; FAR struct tcb_s *tcb = this_task(); uint32_t cmd; #ifdef CONFIG_BUILD_PROTECTED @@ -167,12 +168,9 @@ uint32_t *arm_syscall(uint32_t *regs) DEBUGASSERT(!up_interrupt_context()); - if (*running_task != NULL) - { - (*running_task)->xcp.regs = regs; - } - - /* Set irq flag */ + /* Current regs non-zero indicates that we are processing an interrupt; + * current_regs is also used to manage interrupt level context switches. + */ up_set_interrupt_context(true); @@ -180,6 +178,15 @@ uint32_t *arm_syscall(uint32_t *regs) cmd = regs[REG_R0]; + /* if cmd == SYS_restore_context (*running_task)->xcp.regs is valid + * should not be overwriten + */ + + if (cmd != SYS_restore_context) + { + (*running_task)->xcp.regs = regs; + } + /* The SVCall software interrupt is called with R0 = system call command * and R1..R7 = variable number of arguments depending on the system call. */ @@ -253,47 +260,23 @@ uint32_t *arm_syscall(uint32_t *regs) break; #endif - /* R0=SYS_restore_context: Restore task context - * - * void arm_fullcontextrestore(uint32_t *restoreregs) - * noreturn_function; - * - * At this point, the following values are saved in context: - * - * R0 = SYS_restore_context - * R1 = restoreregs - */ + case SYS_switch_context: - case SYS_restore_context: - { - /* Replace 'regs' with the pointer to the register set in - * regs[REG_R1]. On return from the system call, that register - * set will determine the restored context. - */ + /* Update scheduler parameters */ - tcb->xcp.regs = (uint32_t *)regs[REG_R1]; - DEBUGASSERT(up_interrupt_context()); - } - break; + nxsched_resume_scheduler(tcb); - /* R0=SYS_switch_context: This a switch context command: - * - * void arm_switchcontext(uint32_t **saveregs, - * uint32_t *restoreregs); - * - * At this point, the following values are saved in context: - * - * R0 = SYS_switch_context - * R1 = saveregs - * R2 = restoreregs - * - * In this case, we do both: We save the context registers to the save - * register area reference by the saved contents of R1 and then set - * regs to the save register area referenced by the saved - * contents of R2. - */ + case SYS_restore_context: + nxsched_suspend_scheduler(*running_task); + *running_task = tcb; - case SYS_switch_context: + /* Restore the cpu lock */ + + restore_critical_section(tcb, cpu); + regs = tcb->xcp.regs; +#ifdef CONFIG_ARCH_ADDRENV + addrenv_switch(tcb); +#endif break; /* R0=SYS_task_start: This a user task start @@ -559,25 +542,6 @@ uint32_t *arm_syscall(uint32_t *regs) break; } - if (*running_task != tcb) - { - /* Update scheduler parameters */ - - nxsched_suspend_scheduler(*running_task); - nxsched_resume_scheduler(tcb); - - /* Record the new "running" task. g_running_tasks[] is only used by - * assertion logic for reporting crashes. - */ - - *running_task = tcb; - - /* Restore the cpu lock */ - - restore_critical_section(tcb, this_cpu()); - regs = tcb->xcp.regs; - } - /* Report what happened */ dump_syscall("Exit", cmd, regs); diff --git a/arch/arm/src/common/arm_exit.c b/arch/arm/src/common/arm_exit.c index f238dfa5f3fb6..1b6cafbf80432 100644 --- a/arch/arm/src/common/arm_exit.c +++ b/arch/arm/src/common/arm_exit.c @@ -54,25 +54,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(); - /* Scheduler parameters will update inside syscall */ - g_running_tasks[this_cpu()] = NULL; + g_running_tasks[this_cpu()] = this_task(); /* Then switch contexts */ - arm_fullcontextrestore(tcb->xcp.regs); + arm_fullcontextrestore(); /* arm_fullcontextrestore() should not return but could if the software * interrupts are disabled. diff --git a/arch/arm/src/common/arm_internal.h b/arch/arm/src/common/arm_internal.h index 6303c6fc96da4..c7e4243cae6ab 100644 --- a/arch/arm/src/common/arm_internal.h +++ b/arch/arm/src/common/arm_internal.h @@ -33,6 +33,8 @@ # include # include # include + +# include "chip.h" #endif /**************************************************************************** @@ -147,10 +149,7 @@ /* Context switching */ #ifndef arm_fullcontextrestore -# define arm_fullcontextrestore(restoreregs) \ - sys_call1(SYS_restore_context, (uintptr_t)restoreregs); -#else -extern void arm_fullcontextrestore(uint32_t *restoreregs); +# define arm_fullcontextrestore() sys_call0(SYS_restore_context) #endif /* Redefine the linker symbols as armlink style */ diff --git a/arch/arm/src/lc823450/lc823450_cpuindex.c b/arch/arm/src/lc823450/lc823450_cpuindex.c index 573b89c142f80..dcce257fb2795 100644 --- a/arch/arm/src/lc823450/lc823450_cpuindex.c +++ b/arch/arm/src/lc823450/lc823450_cpuindex.c @@ -32,10 +32,6 @@ * Pre-processor Definitions ****************************************************************************/ -#define LC823450_CORE_BASE 0xe00fe000 -#define CORE_COREID (LC823450_CORE_BASE + 0x0) -#define CORE_COREID_ID (0x1 << 0) - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/arch/arm/src/tlsr82/Make.defs b/arch/arm/src/tlsr82/Make.defs index f1fe854475fea..9ae208705507e 100644 --- a/arch/arm/src/tlsr82/Make.defs +++ b/arch/arm/src/tlsr82/Make.defs @@ -64,5 +64,3 @@ ifeq ($(CONFIG_TLSR82_SOFT_FPU),y) EXTRA_LIBPATHS += -L$(TOPDIR)/$(CONFIG_TLSR82_SOFT_FPU_LIB_PATH) EXTRA_LIBS += -l$(CONFIG_TLSR82_SOFT_FPU_LIB_NAME) endif - -CFLAGS += -Darm_fullcontextrestore=tc32_fullcontextrestore diff --git a/arch/arm/src/tlsr82/chip.h b/arch/arm/src/tlsr82/chip.h index dfc81861bde5b..18be19cf38367 100644 --- a/arch/arm/src/tlsr82/chip.h +++ b/arch/arm/src/tlsr82/chip.h @@ -33,6 +33,8 @@ #define ARMV6M_PERIPHERAL_INTERRUPTS NR_IRQS +#define arm_fullcontextrestore() tc32_fullcontextrestore(this_task()->xcp.regs) + /* Include the memory map file. * Other chip hardware files should then include this file for the proper * setup.