Skip to content

Commit

Permalink
arch: remove up_current_regs in common code
Browse files Browse the repository at this point in the history
  • Loading branch information
hujun260 authored and xiaoxiang781216 committed Dec 24, 2024
1 parent b6a118b commit c1601be
Show file tree
Hide file tree
Showing 50 changed files with 304 additions and 170 deletions.
2 changes: 2 additions & 0 deletions arch/arm/src/arm/arm_sigdeliver.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,7 @@ void arm_sigdeliver(void)
/* Then restore the correct state for this thread of execution. */

board_autoled_off(LED_SIGNAL);

g_running_tasks[this_cpu()] = NULL;
arm_fullcontextrestore(regs);
}
32 changes: 11 additions & 21 deletions arch/arm/src/arm/arm_syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,23 @@

uint32_t *arm_syscall(uint32_t *regs)
{
struct tcb_s *tcb = this_task();
struct tcb_s **running_task = &g_running_tasks[this_cpu()];
FAR struct tcb_s *tcb = this_task();
uint32_t cmd;
int cpu;

/* Nested interrupts are not supported */

DEBUGASSERT(up_current_regs() == NULL);

if (*running_task != NULL)
{
(*running_task)->xcp.regs = regs;
}

/* Current regs non-zero indicates that we are processing an interrupt;
* current_regs is also used to manage interrupt level context switches.
*/

tcb->xcp.regs = regs;
up_set_current_regs(regs);

/* The SYSCALL command is in R0 on entry. Parameters follow in R1..R7 */
Expand Down Expand Up @@ -118,11 +122,6 @@ uint32_t *arm_syscall(uint32_t *regs)
*/

case SYS_switch_context:
{
DEBUGASSERT(regs[REG_R1] != 0 && regs[REG_R2] != 0);
*(uint32_t **)regs[REG_R1] = regs;
up_set_current_regs((uint32_t *)regs[REG_R2]);
}
break;

default:
Expand All @@ -134,7 +133,7 @@ uint32_t *arm_syscall(uint32_t *regs)
break;
}

if (regs != tcb->xcp.regs)
if (*running_task != tcb)
{
#ifdef CONFIG_ARCH_ADDRENV
/* Make sure that the address environment for the previously
Expand All @@ -145,25 +144,16 @@ uint32_t *arm_syscall(uint32_t *regs)

addrenv_switch(NULL);
#endif

/* Record the new "running" task. g_running_tasks[] is only used by
* assertion logic for reporting crashes.
*/

cpu = this_cpu();
tcb = current_task(cpu);

/* Update scheduler parameters */

nxsched_suspend_scheduler(g_running_tasks[cpu]);
nxsched_suspend_scheduler(*running_task);
nxsched_resume_scheduler(tcb);

g_running_tasks[cpu] = tcb;
*running_task = tcb;

/* Restore the cpu lock */

restore_critical_section(tcb, cpu);
regs = up_current_regs();
restore_critical_section(tcb, this_cpu());
}

/* Set current_regs to NULL to indicate that we are no longer in an
Expand Down
16 changes: 9 additions & 7 deletions arch/arm/src/armv6-m/arm_doirq.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ void exception_direct(void)

uint32_t *arm_doirq(int irq, uint32_t *regs)
{
struct tcb_s *tcb = this_task();
struct tcb_s **running_task = &g_running_tasks[this_cpu()];
FAR struct tcb_s *tcb;

if (*running_task != NULL)
{
(*running_task)->xcp.regs = regs;
}

board_autoled_on(LED_INIRQ);
#ifdef CONFIG_SUPPRESS_INTERRUPTS
Expand All @@ -80,13 +86,9 @@ uint32_t *arm_doirq(int irq, uint32_t *regs)
#endif

up_irq_save();
g_running_tasks[this_cpu()]->xcp.regs = regs;
}
else
{
/* Dispatch irq */

tcb->xcp.regs = regs;
irq_dispatch(irq, regs);
}

Expand All @@ -110,15 +112,15 @@ uint32_t *arm_doirq(int irq, uint32_t *regs)

/* Update scheduler parameters */

nxsched_suspend_scheduler(g_running_tasks[this_cpu()]);
nxsched_suspend_scheduler(*running_task);
nxsched_resume_scheduler(tcb);

/* Record the new "running" task when context switch occurred.
* g_running_tasks[] is only used by assertion logic for reporting
* crashes.
*/

g_running_tasks[this_cpu()] = tcb;
*running_task = tcb;
regs = tcb->xcp.regs;
#endif

Expand Down
9 changes: 5 additions & 4 deletions arch/arm/src/armv6-m/arm_svcall.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ 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;
uint32_t cmd;

cmd = regs[REG_R0];
Expand Down Expand Up @@ -167,6 +168,7 @@ int arm_svcall(int irq, void *context, void *arg)
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;
Expand All @@ -191,8 +193,7 @@ int arm_svcall(int irq, void *context, void *arg)
case SYS_switch_context:
{
DEBUGASSERT(regs[REG_R1] != 0 && regs[REG_R2] != 0);
*(uint32_t **)regs[REG_R1] = regs;
tcb->xcp.regs = (uint32_t *)regs[REG_R2];
new_regs = (uint32_t *)regs[REG_R2];
}
break;

Expand Down Expand Up @@ -446,12 +447,12 @@ int arm_svcall(int irq, void *context, void *arg)
* switch.
*/

if (regs != tcb->xcp.regs)
if (regs != new_regs)
{
restore_critical_section(tcb, this_cpu());

#ifdef CONFIG_DEBUG_SYSCALL_INFO
regs = (uint32_t *)tcb->xcp.regs;
regs = new_regs;

svcinfo("SVCall Return:\n");
svcinfo(" R0: %08x %08x %08x %08x %08x %08x %08x %08x\n",
Expand Down
2 changes: 2 additions & 0 deletions arch/arm/src/armv7-a/arm_sigdeliver.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,7 @@ void arm_sigdeliver(void)
leave_critical_section(regs[REG_CPSR]);
rtcb->irqcount--;
#endif

g_running_tasks[this_cpu()] = NULL;
arm_fullcontextrestore(regs);
}
23 changes: 9 additions & 14 deletions arch/arm/src/armv7-a/arm_syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ static void dispatch_syscall(void)

uint32_t *arm_syscall(uint32_t *regs)
{
struct tcb_s **running_task = &g_running_tasks[this_cpu()];
struct tcb_s *tcb = this_task();
uint32_t cmd;
int cpu;
#ifdef CONFIG_BUILD_KERNEL
uint32_t cpsr;
#endif
Expand All @@ -170,7 +170,10 @@ uint32_t *arm_syscall(uint32_t *regs)

DEBUGASSERT(up_current_regs() == NULL);

tcb->xcp.regs = regs;
if (*running_task != NULL)
{
(*running_task)->xcp.regs = regs;
}

/* Current regs non-zero indicates that we are processing an interrupt;
* current_regs is also used to manage interrupt level context switches.
Expand Down Expand Up @@ -296,11 +299,6 @@ uint32_t *arm_syscall(uint32_t *regs)
*/

case SYS_switch_context:
{
DEBUGASSERT(regs[REG_R1] != 0 && regs[REG_R2] != 0);
*(uint32_t **)regs[REG_R1] = regs;
tcb->xcp.regs = (uint32_t *)regs[REG_R2];
}
break;

/* R0=SYS_task_start: This a user task start
Expand Down Expand Up @@ -566,7 +564,7 @@ uint32_t *arm_syscall(uint32_t *regs)
break;
}

if (regs != tcb->xcp.regs)
if (*running_task != tcb)
{
#ifdef CONFIG_ARCH_ADDRENV
/* Make sure that the address environment for the previously
Expand All @@ -578,23 +576,20 @@ uint32_t *arm_syscall(uint32_t *regs)
addrenv_switch(NULL);
#endif

cpu = this_cpu();
tcb = current_task(cpu);

/* Update scheduler parameters */

nxsched_suspend_scheduler(g_running_tasks[cpu]);
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.
*/

g_running_tasks[cpu] = tcb;
*running_task = tcb;

/* Restore the cpu lock */

restore_critical_section(tcb, cpu);
restore_critical_section(tcb, this_cpu());
regs = tcb->xcp.regs;
}

Expand Down
16 changes: 9 additions & 7 deletions arch/arm/src/armv7-m/arm_doirq.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ void exception_direct(void)

uint32_t *arm_doirq(int irq, uint32_t *regs)
{
struct tcb_s *tcb = this_task();
struct tcb_s **running_task = &g_running_tasks[this_cpu()];
FAR struct tcb_s *tcb;

if (*running_task != NULL)
{
(*running_task)->xcp.regs = regs;
}

board_autoled_on(LED_INIRQ);
#ifdef CONFIG_SUPPRESS_INTERRUPTS
Expand All @@ -80,13 +86,9 @@ uint32_t *arm_doirq(int irq, uint32_t *regs)
#endif

up_irq_save();
g_running_tasks[this_cpu()]->xcp.regs = regs;
}
else
{
/* Dispatch irq */

tcb->xcp.regs = regs;
irq_dispatch(irq, regs);
}

Expand All @@ -110,15 +112,15 @@ uint32_t *arm_doirq(int irq, uint32_t *regs)

/* Update scheduler parameters */

nxsched_suspend_scheduler(g_running_tasks[this_cpu()]);
nxsched_suspend_scheduler(*running_task);
nxsched_resume_scheduler(tcb);

/* Record the new "running" task when context switch occurred.
* g_running_tasks[] is only used by assertion logic for reporting
* crashes.
*/

g_running_tasks[this_cpu()] = tcb;
*running_task = tcb;
regs = tcb->xcp.regs;
#endif

Expand Down
9 changes: 5 additions & 4 deletions arch/arm/src/armv7-m/arm_svcall.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ 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;
uint32_t cmd;

cmd = regs[REG_R0];
Expand Down Expand Up @@ -176,6 +177,7 @@ int arm_svcall(int irq, void *context, void *arg)
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;
Expand All @@ -200,8 +202,7 @@ int arm_svcall(int irq, void *context, void *arg)
case SYS_switch_context:
{
DEBUGASSERT(regs[REG_R1] != 0 && regs[REG_R2] != 0);
*(uint32_t **)regs[REG_R1] = regs;
tcb->xcp.regs = (uint32_t *)regs[REG_R2];
new_regs = (uint32_t *)regs[REG_R2];
}
break;

Expand Down Expand Up @@ -456,12 +457,12 @@ int arm_svcall(int irq, void *context, void *arg)
* switch.
*/

if (regs != tcb->xcp.regs)
if (regs != new_regs)
{
restore_critical_section(tcb, this_cpu());

#ifdef CONFIG_DEBUG_SYSCALL_INFO
regs = (uint32_t *)tcb->xcp.regs;
regs = new_regs;

svcinfo("SVCall Return:\n");
svcinfo(" R0: %08x %08x %08x %08x %08x %08x %08x %08x\n",
Expand Down
2 changes: 2 additions & 0 deletions arch/arm/src/armv7-r/arm_sigdeliver.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,7 @@ void arm_sigdeliver(void)
leave_critical_section(regs[REG_CPSR]);
rtcb->irqcount--;
#endif

g_running_tasks[this_cpu()] = NULL;
arm_fullcontextrestore(regs);
}
Loading

0 comments on commit c1601be

Please sign in to comment.