Skip to content

Commit

Permalink
riscv: remove up_set_current_regs/up_current_regs
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
hujun260 committed Nov 27, 2024
1 parent 825ba8e commit 0bfaeac
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 60 deletions.
43 changes: 7 additions & 36 deletions arch/risc-v/include/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -671,17 +671,9 @@ extern "C"
#define EXTERN extern
#endif

/* g_current_regs[] holds a references to the current interrupt level
* register storage structure. If is non-NULL only during interrupt
* processing. Access to g_current_regs[] must be through the
* [get/set]_current_regs for portability.
*/

/* For the case of architectures with multiple CPUs, then there must be one
* such value for each processor that can receive an interrupt.
*/
/* g_interrupt_context store irq status */

EXTERN volatile uintreg_t *g_current_regs[CONFIG_SMP_NCPUS];
extern volatile bool g_interrupt_context[CONFIG_SMP_NCPUS];

/****************************************************************************
* Public Function Prototypes
Expand Down Expand Up @@ -724,24 +716,6 @@ int up_this_cpu(void);
* Inline Functions
****************************************************************************/

static inline_function uintreg_t *up_current_regs(void)
{
#ifdef CONFIG_SMP
return (uintreg_t *)g_current_regs[up_this_cpu()];
#else
return (uintreg_t *)g_current_regs[0];
#endif
}

static inline_function void up_set_current_regs(uintreg_t *regs)
{
#ifdef CONFIG_SMP
g_current_regs[up_this_cpu()] = regs;
#else
g_current_regs[0] = regs;
#endif
}

/****************************************************************************
* Name: up_irq_save
*
Expand Down Expand Up @@ -803,23 +777,20 @@ noinstrument_function static inline_function bool up_interrupt_context(void)
{
#ifdef CONFIG_SMP
irqstate_t flags = up_irq_save();
#endif

bool ret = up_current_regs() != NULL;

#ifdef CONFIG_SMP
bool ret = g_interrupt_context[up_cpu_index()];
up_irq_restore(flags);
#endif

return ret;
#else
return g_interrupt_context[0];
#endif
}

/****************************************************************************
* Name: up_getusrpc
****************************************************************************/

#define up_getusrpc(regs) \
(((uintptr_t *)((regs) ? (regs) : up_current_regs()))[REG_EPC])
(((uintptr_t *)((regs) ? (regs) : running_regs()))[REG_EPC])

#undef EXTERN
#if defined(__cplusplus)
Expand Down
4 changes: 2 additions & 2 deletions arch/risc-v/src/common/riscv_backtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ int up_backtrace(struct tcb_s *tcb, void **buffer, int size, int skip)
{
ret += backtrace(rtcb->stack_base_ptr,
rtcb->stack_base_ptr + rtcb->adj_stack_size,
(void *)up_current_regs()[REG_FP],
(void *)up_current_regs()[REG_EPC],
running_regs()[REG_FP],
running_regs()[REG_EPC],
&buffer[ret], size - ret, &skip);
}
}
Expand Down
19 changes: 8 additions & 11 deletions arch/risc-v/src/common/riscv_doirq.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,13 @@ uintreg_t *riscv_doirq(int irq, uintreg_t *regs)
(*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.
*
* Nested interrupts are not supported
*/
/* Nested interrupts are not supported */

DEBUGASSERT(!up_interrupt_context());

DEBUGASSERT(up_current_regs() == NULL);
up_set_current_regs(regs);
/* Set irq flag */

riscv_set_interrupt_context(true);

/* Deliver the IRQ */

Expand Down Expand Up @@ -124,11 +123,9 @@ uintreg_t *riscv_doirq(int irq, uintreg_t *regs)
*running_task = tcb;
}

/* Set current_regs to NULL to indicate that we are no longer in an
* interrupt handler.
*/
/* Set irq flag */

up_set_current_regs(NULL);
riscv_set_interrupt_context(false);

#endif
board_autoled_off(LED_INIRQ);
Expand Down
12 changes: 6 additions & 6 deletions arch/risc-v/src/common/riscv_exception.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,22 @@ int riscv_exception(int mcause, void *regs, void *args)

/* Return to _exit function in privileged mode with argument SIGSEGV */

up_current_regs()[REG_EPC] = (uintptr_t)_exit;
up_current_regs()[REG_A0] = SIGSEGV;
up_current_regs()[REG_INT_CTX] |= STATUS_PPP;
running_regs()[REG_EPC] = (uintptr_t)_exit;
running_regs()[REG_A0] = SIGSEGV;
running_regs()[REG_INT_CTX] |= STATUS_PPP;

/* Continue with kernel stack in use. The frame(s) in kernel stack
* are no longer needed, so just set it to top
*/

up_current_regs()[REG_SP] = (uintptr_t)tcb->xcp.ktopstk;
running_regs()[REG_SP] = (uintptr_t)tcb->xcp.ktopstk;
}
else
#endif
{
_alert("PANIC!!! Exception = %" PRIxREG "\n", cause);
up_irq_save();
up_set_current_regs(regs);
riscv_set_interrupt_context(true);
PANIC_WITH_REGS("panic", regs);
}

Expand Down Expand Up @@ -197,7 +197,7 @@ int riscv_fillpage(int mcause, void *regs, void *args)
{
_alert("PANIC!!! virtual address not mappable: %" PRIxPTR "\n", vaddr);
up_irq_save();
up_set_current_regs(regs);
riscv_set_interrupt_context(true);
PANIC_WITH_REGS("panic", regs);
}

Expand Down
4 changes: 3 additions & 1 deletion arch/risc-v/src/common/riscv_initialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
* Public Data
****************************************************************************/

volatile uintreg_t *g_current_regs[CONFIG_SMP_NCPUS];
/* g_interrupt_context store irq status */

volatile bool g_interrupt_context[CONFIG_SMP_NCPUS];

/****************************************************************************
* Private Functions
Expand Down
8 changes: 8 additions & 0 deletions arch/risc-v/src/common/riscv_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,14 @@ static inline uintptr_t *riscv_vpuregs(struct tcb_s *tcb)
# define riscv_vpuregs(tcb)
#endif

/* IRQ Flag */

noinstrument_function
static inline_function void riscv_set_interrupt_context(bool flag)
{
g_interrupt_context[this_cpu()] = flag;
}

/* Save / restore context of task */

static inline void riscv_savecontext(struct tcb_s *tcb)
Expand Down
2 changes: 1 addition & 1 deletion arch/risc-v/src/common/riscv_registerdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ uintptr_t up_getusrsp(void *regs)

void up_dump_register(void *dumpregs)
{
volatile uintreg_t *regs = dumpregs ? dumpregs : up_current_regs();
volatile uintreg_t *regs = dumpregs ? dumpregs : running_regs();

/* Are user registers available from interrupt processing? */

Expand Down
8 changes: 5 additions & 3 deletions arch/risc-v/src/common/supervisor/riscv_perform_syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ void *riscv_perform_syscall(uintreg_t *regs)
(*running_task)->xcp.regs = regs;
}

/* Set up the interrupt register set needed by swint() */
/* Set irq flag */

up_set_current_regs(regs);
riscv_set_interrupt_context(true);

/* Run the system call handler (swint) */

Expand Down Expand Up @@ -77,7 +77,9 @@ void *riscv_perform_syscall(uintreg_t *regs)
*running_task = tcb;
}

up_set_current_regs(NULL);
/* Set irq flag */

riscv_set_interrupt_context(false);

return tcb->xcp.regs;
}

0 comments on commit 0bfaeac

Please sign in to comment.