mirror of
https://github.com/apache/nuttx.git
synced 2026-05-23 23:28:29 +08:00
riscv: 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:
+25
-36
@@ -673,17 +673,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.
|
||||
*/
|
||||
/* g_interrupt_context store irq status */
|
||||
|
||||
/* For the case of architectures with multiple CPUs, then there must be one
|
||||
* such value for each processor that can receive an interrupt.
|
||||
*/
|
||||
|
||||
EXTERN volatile uintreg_t *g_current_regs[CONFIG_SMP_NCPUS];
|
||||
EXTERN volatile bool g_interrupt_context[CONFIG_SMP_NCPUS];
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
@@ -726,24 +718,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
|
||||
*
|
||||
@@ -792,6 +766,24 @@ noinstrument_function static inline void up_irq_restore(irqstate_t flags)
|
||||
);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_set_interrupt_context
|
||||
*
|
||||
* Description:
|
||||
* Set the interrupt handler context.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
noinstrument_function
|
||||
static inline_function void up_set_interrupt_context(bool flag)
|
||||
{
|
||||
#ifdef CONFIG_SMP
|
||||
g_interrupt_context[up_this_cpu()] = flag;
|
||||
#else
|
||||
g_interrupt_context[0] = flag;
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_interrupt_context
|
||||
*
|
||||
@@ -805,15 +797,12 @@ 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_this_cpu()];
|
||||
up_irq_restore(flags);
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
#else
|
||||
return g_interrupt_context[0];
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@@ -821,7 +810,7 @@ noinstrument_function static inline_function bool up_interrupt_context(void)
|
||||
****************************************************************************/
|
||||
|
||||
#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)
|
||||
|
||||
@@ -164,8 +164,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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,26 +83,20 @@ 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_current_regs() == NULL);
|
||||
up_set_current_regs(regs);
|
||||
DEBUGASSERT(!up_interrupt_context());
|
||||
|
||||
/* Set irq flag */
|
||||
|
||||
up_set_interrupt_context(true);
|
||||
|
||||
/* 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
|
||||
* interrupt level context switch has occurred, then restore the floating
|
||||
* point state and the establish the correct address environment before
|
||||
* returning from the interrupt.
|
||||
*/
|
||||
/* Check for a context switch. */
|
||||
|
||||
if (*running_task != tcb)
|
||||
{
|
||||
@@ -129,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);
|
||||
up_set_interrupt_context(false);
|
||||
|
||||
#endif
|
||||
board_autoled_off(LED_INIRQ);
|
||||
|
||||
@@ -112,22 +112,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] = _exit;
|
||||
running_regs()[REG_A0] = (void *)SIGSEGV;
|
||||
((uintreg_t *)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] = tcb->xcp.ktopstk;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
_alert("PANIC!!! Exception = %" PRIxREG "\n", cause);
|
||||
up_irq_save();
|
||||
up_set_current_regs(regs);
|
||||
up_set_interrupt_context(true);
|
||||
PANIC_WITH_REGS("panic", regs);
|
||||
}
|
||||
|
||||
@@ -199,7 +199,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);
|
||||
up_set_interrupt_context(true);
|
||||
PANIC_WITH_REGS("panic", regs);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,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
|
||||
|
||||
@@ -55,7 +55,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? */
|
||||
|
||||
|
||||
@@ -47,9 +47,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);
|
||||
up_set_interrupt_context(true);
|
||||
|
||||
/* Run the system call handler (swint) */
|
||||
|
||||
@@ -79,7 +79,9 @@ void *riscv_perform_syscall(uintreg_t *regs)
|
||||
*running_task = tcb;
|
||||
}
|
||||
|
||||
up_set_current_regs(NULL);
|
||||
/* Set irq flag */
|
||||
|
||||
up_set_interrupt_context(false);
|
||||
|
||||
return tcb->xcp.regs;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user