Skip to content

Commit

Permalink
riscv: g_current_regs is only used to determine if we are in irq,
Browse files Browse the repository at this point in the history
with other functionalities removed.

VELAPLATFO-37214

Change-Id: I386779012ed976d282baa5136f496d45d485846d
Signed-off-by: hujun5 <[email protected]>
  • Loading branch information
hujun260 committed Sep 18, 2024
1 parent b996852 commit f63fe3e
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 315 deletions.
12 changes: 2 additions & 10 deletions arch/risc-v/src/common/riscv_cpupause.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,7 @@ int up_cpu_paused_save(void)
sched_note_cpu_paused(tcb);
#endif

/* Save the current context at current_regs into the TCB at the head
* of the assigned task list for this CPU.
*/

riscv_savecontext(tcb);
UNUSED(tcb);

return OK;
}
Expand Down Expand Up @@ -202,11 +198,7 @@ int up_cpu_paused_restore(void)

nxsched_resume_scheduler(tcb);

/* Then switch contexts. Any necessary address environment changes
* will be made when the interrupt returns.
*/

riscv_restorecontext(tcb);
UNUSED(tcb);

return OK;
}
Expand Down
13 changes: 10 additions & 3 deletions arch/risc-v/src/common/riscv_doirq.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@

uintreg_t *riscv_doirq(int irq, uintreg_t *regs)
{
struct tcb_s *tcb = this_task();

board_autoled_on(LED_INIRQ);
#ifdef CONFIG_SUPPRESS_INTERRUPTS
PANIC();
Expand All @@ -69,6 +71,10 @@ uintreg_t *riscv_doirq(int irq, uintreg_t *regs)
{
regs[REG_EPC] += 4;
}
else
{
tcb->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 All @@ -82,6 +88,7 @@ uintreg_t *riscv_doirq(int irq, uintreg_t *regs)
/* Deliver the IRQ */

irq_dispatch(irq, regs);
tcb = this_task();

/* Check for a context switch. If a context switch occurred, then
* current_regs will have a different value than it did on entry. If an
Expand All @@ -90,7 +97,7 @@ uintreg_t *riscv_doirq(int irq, uintreg_t *regs)
* returning from the interrupt.
*/

if (regs != up_current_regs())
if (regs != tcb->xcp.regs)
{
#ifdef CONFIG_ARCH_ADDRENV
/* Make sure that the address environment for the previously
Expand All @@ -107,15 +114,15 @@ uintreg_t *riscv_doirq(int irq, uintreg_t *regs)
* crashes.
*/

g_running_tasks[this_cpu()] = this_task();
g_running_tasks[this_cpu()] = tcb;

/* If a context switch occurred while processing the interrupt then
* current_regs may have change value. If we return any value
* different from the input regs, then the lower level will know
* that a context switch occurred during interrupt processing.
*/

regs = up_current_regs();
regs = tcb->xcp.regs;
}

/* Set current_regs to NULL to indicate that we are no longer in an
Expand Down
11 changes: 0 additions & 11 deletions arch/risc-v/src/common/riscv_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,6 @@
/* Interrupt Stack macros */
#define INT_STACK_SIZE (STACK_ALIGN_DOWN(CONFIG_ARCH_INTERRUPTSTACK))

/* In the RISC-V model, the state is saved in stack,
* only a reference stored in TCB.
*/

#define riscv_savestate(regs) (regs = up_current_regs())
#define riscv_restorestate(regs) up_set_current_regs(regs)

/* Determine which (if any) console driver to use. If a console is enabled
* and no other console device is specified, then a serial console is
* assumed.
Expand Down Expand Up @@ -322,8 +315,6 @@ static inline uintptr_t *riscv_vpuregs(struct tcb_s *tcb)

static inline void riscv_savecontext(struct tcb_s *tcb)
{
tcb->xcp.regs = (uintreg_t *)up_current_regs();

#ifdef CONFIG_ARCH_FPU
/* Save current process FPU state to TCB */

Expand All @@ -339,8 +330,6 @@ static inline void riscv_savecontext(struct tcb_s *tcb)

static inline void riscv_restorecontext(struct tcb_s *tcb)
{
up_set_current_regs(tcb->xcp.regs);

#ifdef CONFIG_ARCH_FPU
/* Restore FPU state for next process */

Expand Down
Loading

0 comments on commit f63fe3e

Please sign in to comment.