arch/x86_64: The interrupt context flag is stored in the CPU private data

Signed-off-by: liwenxiang1 <liwenxiang1@xiaomi.com>
This commit is contained in:
liwenxiang1 2024-12-09 11:09:05 +08:00 committed by Xiang Xiao
parent f344a422e8
commit c748047e25
2 changed files with 34 additions and 24 deletions

View file

@ -68,6 +68,10 @@ struct intel64_cpu_s
uint8_t loapic_id;
bool ready;
/* Interrupt Context */
bool interrupt_context;
/* current_regs holds a references to the current interrupt level
* register storage structure. If is non-NULL only during interrupt
* processing. Access to current_regs must be through
@ -143,7 +147,7 @@ static inline_function uint64_t *up_current_regs(void)
{
uint64_t *regs;
__asm__ volatile("movq %%gs:(%c1), %0"
: "=rm" (regs)
: "=r" (regs)
: "i" (offsetof(struct intel64_cpu_s, current_regs)));
return regs;
}
@ -155,19 +159,22 @@ static inline_function void up_set_current_regs(uint64_t *regs)
current_regs)));
}
/****************************************************************************
* Name: up_interrupt_context
*
* Description:
* Return true is we are currently executing in the interrupt handler
* context.
*
****************************************************************************/
noinstrument_function
static inline_function bool up_interrupt_context(void)
{
return up_current_regs() != NULL;
bool flag;
__asm__ volatile("movb %%gs:(%c1), %0"
: "=qm" (flag)
: "i" (offsetof(struct intel64_cpu_s,
interrupt_context)));
return flag;
}
static inline_function void up_set_interrupt_context(bool flag)
{
__asm__ volatile("movb %0, %%gs:(%c1)"
:: "r" (flag),
"i" (offsetof(struct intel64_cpu_s,
interrupt_context)));
}
/****************************************************************************

View file

@ -75,8 +75,11 @@ static uint64_t *common_handler(int irq, uint64_t *regs)
* 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 */
@ -120,11 +123,10 @@ static uint64_t *common_handler(int irq, uint64_t *regs)
restore_critical_section(tcb, this_cpu());
}
/* Set g_current_regs to NULL to indicate that we are no longer in an
* interrupt handler.
*/
/* Clear irq flag */
up_set_interrupt_context(false);
up_set_current_regs(NULL);
return tcb->xcp.regs;
}
#endif
@ -163,8 +165,11 @@ uint64_t *isr_handler(uint64_t *regs, uint64_t irq)
return regs;
#else
DEBUGASSERT(up_current_regs() == NULL);
up_set_current_regs(regs);
DEBUGASSERT(!up_interrupt_context());
/* Set irq flag */
up_set_interrupt_context(true);
switch (irq)
{
@ -227,11 +232,9 @@ uint64_t *isr_handler(uint64_t *regs, uint64_t irq)
restore_critical_section(tcb, this_cpu());
}
/* Set g_current_regs to NULL to indicate that we are no longer in an
* interrupt handler.
*/
/* Clear irq flag */
up_set_current_regs(NULL);
up_set_interrupt_context(false);
return tcb->xcp.regs;
#endif
}