Skip to contentSkip to conversation

x86: move interrupt entry stubs to entry.S

PATCH Superseded Feng Wu 2 participants 2 messages May 15, 2014

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Feng Wu

author
#0 lore raw

PATCH 1/1 x86: move interrupt entry stubs to entry.S

This patch removes the ugly macros in i8259.c and asm_defns.h, which is used to build up the interrupt entry stubs. Move the definition of these stubs to entry.S instead.

---
 xen/arch/x86/i8259.c            | 63 ++---------------------------------------
 xen/arch/x86/x86_64/entry.S     | 20 +++++++++++++
 xen/include/asm-x86/asm_defns.h |  6 +---
 3 files changed, 23 insertions(+), 66 deletions(-)
xen/arch/x86/i8259.c +2 -61
index 9fec490..f207c2c 100644
@@ -23,65 +23,6 @@
 #include <io_ports.h>
 
 /*
- * Common place to define all x86 IRQ vectors
- *
- * This builds up the IRQ handler stubs using some ugly macros in irq.h
- *
- * These macros create the low-level assembly IRQ routines that save
- * register context and call do_IRQ(). do_IRQ() then does all the
- * operations that are needed to keep the AT (or SMP IOAPIC)
- * interrupt-controller happy.
- */
-
-__asm__(".section .text");
-
-#define IRQ_NAME(nr) VEC##nr##_interrupt
-
-#define BI(nr)                                           \
-void IRQ_NAME(nr)(void);                                 \
-__asm__(                                                 \
-".if " STR(0x##nr) " >= " STR(FIRST_DYNAMIC_VECTOR) "\n" \
-__ALIGN_STR "\n"                                         \
-STR(IRQ_NAME(nr)) ":\n\t"                                \
-BUILD_IRQ(0x##nr) "\n"                                   \
-".else\n"                                                \
-".equ " STR(IRQ_NAME(nr)) ", 0\n"                        \
-".endif\n")
-
-#define BUILD_16_IRQS(x) \
-    BI(x##0); BI(x##1); BI(x##2); BI(x##3); \
-    BI(x##4); BI(x##5); BI(x##6); BI(x##7); \
-    BI(x##8); BI(x##9); BI(x##a); BI(x##b); \
-    BI(x##c); BI(x##d); BI(x##e); BI(x##f)
-
-BUILD_16_IRQS(0); BUILD_16_IRQS(1); BUILD_16_IRQS(2); BUILD_16_IRQS(3);
-BUILD_16_IRQS(4); BUILD_16_IRQS(5); BUILD_16_IRQS(6); BUILD_16_IRQS(7);
-BUILD_16_IRQS(8); BUILD_16_IRQS(9); BUILD_16_IRQS(a); BUILD_16_IRQS(b);
-BUILD_16_IRQS(c); BUILD_16_IRQS(d); BUILD_16_IRQS(e); BUILD_16_IRQS(f);
-
-#undef BUILD_16_IRQS
-#undef BI
-
-
-#define IRQ(x,y) IRQ_NAME(x##y)
-
-#define IRQLIST_16(x) \
-    IRQ(x,0), IRQ(x,1), IRQ(x,2), IRQ(x,3), \
-    IRQ(x,4), IRQ(x,5), IRQ(x,6), IRQ(x,7), \
-    IRQ(x,8), IRQ(x,9), IRQ(x,a), IRQ(x,b), \
-    IRQ(x,c), IRQ(x,d), IRQ(x,e), IRQ(x,f)
-
-static void (*__initdata interrupt[NR_VECTORS])(void) = {
-    IRQLIST_16(0), IRQLIST_16(1), IRQLIST_16(2), IRQLIST_16(3),
-    IRQLIST_16(4), IRQLIST_16(5), IRQLIST_16(6), IRQLIST_16(7),
-    IRQLIST_16(8), IRQLIST_16(9), IRQLIST_16(a), IRQLIST_16(b),
-    IRQLIST_16(c), IRQLIST_16(d), IRQLIST_16(e), IRQLIST_16(f)
-};
-
-#undef IRQ
-#undef IRQLIST_16
-
-/*
  * This is the 'legacy' 8259A Programmable Interrupt Controller,
  * present in the majority of PC/AT boxes.
  * plus some generic x86 specific things if generic specifics makes
@@ -407,8 +348,8 @@ void __init init_IRQ(void)
     {
         if (vector == HYPERCALL_VECTOR || vector == LEGACY_SYSCALL_VECTOR)
             continue;
-        BUG_ON(!interrupt[vector]);
-        set_intr_gate(vector, interrupt[vector]);
+        BUG_ON(!interrupt[vector - FIRST_DYNAMIC_VECTOR]);
+        set_intr_gate(vector, interrupt[vector - FIRST_DYNAMIC_VECTOR]);
     }
 
     for (irq = 0; platform_legacy_irq(irq); irq++) {
xen/arch/x86/x86_64/entry.S +20 -0
index 4796e65..8dc0d12 100644
@@ -469,6 +469,26 @@ ENTRY(dom_crash_sync_extable)
         xorl  %edi,%edi
         jmp   asm_domain_crash_synchronous /* Does not return */
 
+        .section .init.data,"a"
+ENTRY(interrupt)
+        .section .text
+ENTRY(irq_entries_start)
+        vector=FIRST_DYNAMIC_VECTOR
+        .rept NR_VECTORS-FIRST_DYNAMIC_VECTOR
+        ALIGN
+        .if vector < NR_VECTORS
+1:      pushq $0x0
+        movl $vector,0x4(%rsp)
+        jmp common_interrupt
+        .previous
+        .quad 1b
+        .section .text
+        vector=vector+1
+        .endif
+        .endr
+        .previous
+        .previous
+
 ENTRY(common_interrupt)
         SAVE_ALL CLAC
         movq %rsp,%rdi
xen/include/asm-x86/asm_defns.h +1 -5
index df4873b..7d620b1 100644
@@ -13,6 +13,7 @@
 
 #ifndef __ASSEMBLY__
 void ret_from_intr(void);
+extern void (*interrupt[])(void);
 #endif
 
 #ifdef CONFIG_FRAME_POINTER
@@ -357,9 +358,4 @@ static inline void stac(void)
 #define REX64_PREFIX "rex64/"
 #endif
 
-#define BUILD_IRQ(nr)                           \
-    "pushq $0\n\t"                              \
-    "movl $"#nr",4(%rsp)\n\t"                   \
-    "jmp common_interrupt"
-
 #endif /* __X86_ASM_DEFNS_H__ */
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 15.05.14 at 07:34, <[email protected]> wrote:

This patch removes the ugly macros in i8259.c and asm_defns.h, which is used to build up the interrupt entry stubs. Move the definition of these stubs to entry.S instead.

Fundamentally fine, but a couple of mechanical adjustments are still needed:

xen/arch/x86/x86_64/entry.S ENTRY(dom_crash_sync_extable) · line 472

Quoted 7 lines
xen/arch/x86/x86_64/entry.S +1 -0
@@ -469,6 +469,26 @@ ENTRY(dom_crash_sync_extable)
         xorl  %edi,%edi
         jmp   asm_domain_crash_synchronous /* Does not return */
 
+        .section .init.data,"a"

Especially with you using "a", this ought to be .init.rodata.

xen/arch/x86/x86_64/entry.S ENTRY(dom_crash_sync_extable) · line 479

Quoted 7 lines
xen/arch/x86/x86_64/entry.S +7 -0
+ENTRY(interrupt)
+        .section .text
+ENTRY(irq_entries_start)
+        vector=FIRST_DYNAMIC_VECTOR
+        .rept NR_VECTORS-FIRST_DYNAMIC_VECTOR
+        ALIGN
+        .if vector < NR_VECTORS

With the .rept operand above, what is this .if good for?

xen/arch/x86/x86_64/entry.S ENTRY(dom_crash_sync_extable) · line 490

Quoted 11 lines
xen/arch/x86/x86_64/entry.S +11 -0
+1:      pushq $0x0
+        movl $vector,0x4(%rsp)
+        jmp common_interrupt
+        .previous
+        .quad 1b
+        .section .text
+        vector=vector+1
+        .endif
+        .endr
+        .previous
+        .previous

I don't think a double previous really does what you expect. Please use .pushsection/.popsection instead for nested section handling.

xen/include/asm-x86/asm_defns.h line 16

Quoted 7 lines
xen/include/asm-x86/asm_defns.h +1 -0
@@ -13,6 +13,7 @@
 
 #ifndef __ASSEMBLY__
 void ret_from_intr(void);
+extern void (*interrupt[])(void);

With the above this is then also missing a const qualifier.

Jan