arm: remove up_set_current_regs/up_current_regs

reason:
up_set_current_regs initially had two functions:

1: To mark the entry into an interrupt state.
2: To record the context before an interrupt/exception. If we switch to
   a new task, we need to store the upcoming context regs by calling up_set_current_regs(regs).

Currently, we record the context in other ways, so the second function is obsolete.
Therefore, we need to rename up_set_current_regs to better reflect its actual meaning,
which is solely to mark an interrupt.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
hujun5
2024-11-20 14:41:25 +08:00
committed by Xiang Xiao
parent 95ed02ec22
commit 03af486d68
19 changed files with 71 additions and 325 deletions
+7 -7
View File
@@ -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
+2
View File
@@ -283,6 +283,8 @@ static inline_function void up_set_interrupt_context(bool flag)
#endif
}
#define arm_fullcontextrestore() tc32_fullcontextrestore(this_task()->xcp.regs)
#define up_switch_context(tcb, rtcb) \
do { \
if (!up_interrupt_context()) \
+2 -2
View File
@@ -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);
@@ -99,5 +98,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();
}
-39
View File
@@ -79,46 +79,7 @@ uint32_t *arm_syscall(uint32_t *regs)
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_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.
*/
tcb->xcp.regs = (uint32_t *)regs[REG_R1];
DEBUGASSERT(up_interrupt_context());
}
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
*
* 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_switch_context:
break;
+4 -1
View File
@@ -162,5 +162,8 @@ retry:
leave_critical_section((uint16_t)regs[REG_PRIMASK]);
rtcb->irqcount--;
#endif
arm_fullcontextrestore(regs);
g_running_tasks[this_cpu()] = NULL;
rtcb->xcp.regs = rtcb->xcp.saved_regs;
arm_fullcontextrestore();
UNUSED(regs);
}
+12 -46
View File
@@ -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;
}
+3 -1
View File
@@ -162,5 +162,7 @@ retry:
#endif
g_running_tasks[this_cpu()] = NULL;
arm_fullcontextrestore(regs);
rtcb->xcp.regs = rtcb->xcp.saved_regs;
arm_fullcontextrestore();
UNUSED(regs);
}
-40
View File
@@ -255,47 +255,7 @@ 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_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.
*/
tcb->xcp.regs = (uint32_t *)regs[REG_R1];
DEBUGASSERT(up_interrupt_context());
}
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
*
* 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_switch_context:
break;
+5 -1
View File
@@ -174,5 +174,9 @@ retry:
#endif
rtcb->irqcount--;
#endif
arm_fullcontextrestore(regs);
g_running_tasks[this_cpu()] = NULL;
rtcb->xcp.regs = rtcb->xcp.saved_regs;
arm_fullcontextrestore();
UNUSED(regs);
}
+12 -46
View File
@@ -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;
}
+3 -1
View File
@@ -159,5 +159,7 @@ retry:
#endif
g_running_tasks[this_cpu()] = NULL;
arm_fullcontextrestore(regs);
rtcb->xcp.regs = rtcb->xcp.saved_regs;
arm_fullcontextrestore();
UNUSED(regs);
}
-39
View File
@@ -253,46 +253,7 @@ 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_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.
*/
tcb->xcp.regs = (uint32_t *)regs[REG_R1];
DEBUGASSERT(up_interrupt_context());
}
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
*
* 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_switch_context:
break;
+4 -1
View File
@@ -174,5 +174,8 @@ retry:
#endif
rtcb->irqcount--;
#endif
arm_fullcontextrestore(regs);
g_running_tasks[this_cpu()] = NULL;
rtcb->xcp.regs = rtcb->xcp.saved_regs;
arm_fullcontextrestore();
UNUSED(regs);
}
+12 -46
View File
@@ -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;
}
+3 -1
View File
@@ -157,5 +157,7 @@ retry:
#endif
g_running_tasks[this_cpu()] = NULL;
arm_fullcontextrestore(regs);
rtcb->xcp.regs = rtcb->xcp.saved_regs;
arm_fullcontextrestore();
UNUSED(regs);
}
-39
View File
@@ -253,46 +253,7 @@ 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_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.
*/
tcb->xcp.regs = (uint32_t *)regs[REG_R1];
DEBUGASSERT(up_interrupt_context());
}
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
*
* 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_switch_context:
break;
+1 -9
View File
@@ -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;
/* Then switch contexts */
arm_fullcontextrestore(tcb->xcp.regs);
arm_fullcontextrestore();
/* arm_fullcontextrestore() should not return but could if the software
* interrupts are disabled.
+1 -4
View File
@@ -147,10 +147,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 */
-2
View File
@@ -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