mirror of
https://github.com/apache/nuttx.git
synced 2026-09-04 16:13:00 +00:00
xtensa: syscall SYS_switch_context and SYS_restore_context use 0 para
reason: simplify context switch sys_call0(SYS_switch_context) sys_call0(SYS_restore_context) size nuttx before text data bss dec hex filename 187620 1436 169296 358352 577d0 nuttx after text data bss dec hex filename 187576 1452 169280 358308 577a4 nuttx size reduce -44 Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
parent
dc8bde8dd5
commit
cc96289e2d
7 changed files with 16 additions and 83 deletions
|
|
@ -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: */
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
|
|||
|
|
@ -173,7 +173,7 @@ void xtensa_appcpu_start(void)
|
|||
* be the CPUs NULL task.
|
||||
*/
|
||||
|
||||
xtensa_context_restore(tcb->xcp.regs);
|
||||
xtensa_context_restore();
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue