From c748047e25b951eb27822b83b521949870d26b40 Mon Sep 17 00:00:00 2001 From: liwenxiang1 Date: Mon, 9 Dec 2024 11:09:05 +0800 Subject: [PATCH] arch/x86_64: The interrupt context flag is stored in the CPU private data Signed-off-by: liwenxiang1 --- arch/x86_64/include/irq.h | 31 +++++++++++++--------- arch/x86_64/src/intel64/intel64_handlers.c | 27 ++++++++++--------- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/arch/x86_64/include/irq.h b/arch/x86_64/include/irq.h index a361262ca5..42790785bb 100644 --- a/arch/x86_64/include/irq.h +++ b/arch/x86_64/include/irq.h @@ -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))); } /**************************************************************************** diff --git a/arch/x86_64/src/intel64/intel64_handlers.c b/arch/x86_64/src/intel64/intel64_handlers.c index d737c84b2f..623fdb9706 100644 --- a/arch/x86_64/src/intel64/intel64_handlers.c +++ b/arch/x86_64/src/intel64/intel64_handlers.c @@ -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 }