From: Jan Kiszka <[email protected]> This will allow to share it between interrupt and exception handling, both being optional.
MAX_INTERRUPT_VECTORS is introduced as public API, defining how many interrupts can be registered at most via int_set_handler(). Signed-off-by: Jan Kiszka <[email protected]> --- inmates/lib/x86/include/inmate.h | 4 ++++ inmates/lib/x86/int.c | 23 +++-------------------- inmates/lib/x86/setup.c | 12 ++++++++++++ 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/inmates/lib/x86/include/inmate.h b/inmates/lib/x86/include/inmate.h index b6bc6145..07a6275b 100644 --- a/inmates/lib/x86/include/inmate.h +++ b/inmates/lib/x86/include/inmate.h @@ -218,6 +218,10 @@ static inline unsigned int cpu_id(void) return read_msr(X2APIC_ID); } +#define MAX_INTERRUPT_VECTORS 32 + +extern unsigned long idt[]; + typedef void(*int_handler_t)(void); void int_init(void); diff --git a/inmates/lib/x86/int.c b/inmates/lib/x86/int.c index 503f68a6..4f760589 100644 --- a/inmates/lib/x86/int.c +++ b/inmates/lib/x86/int.c @@ -45,30 +45,13 @@ #define APIC_EOI_ACK 0 -struct desc_table_reg { - u16 limit; - u64 base; -} __attribute__((packed)); - -static u32 idt[NUM_IDT_DESC * 4]; static int_handler_t int_handler[NUM_IDT_DESC]; extern u8 irq_entry[]; -static inline void write_idtr(struct desc_table_reg *val) -{ - asm volatile("lidt %0" : : "m" (*val)); -} - void int_init(void) { - struct desc_table_reg dtr; - write_msr(X2APIC_SPIV, 0x1ff); - - dtr.limit = NUM_IDT_DESC * 16 - 1; - dtr.base = (u64)&idt; - write_idtr(&dtr); } static void __attribute__((used)) handle_interrupt(unsigned int vector) @@ -83,9 +66,9 @@ void int_set_handler(unsigned int vector, int_handler_t handler) int_handler[vector] = handler; - idt[vector * 4] = (entry & 0xffff) | (INMATE_CS64 << 16); - idt[vector * 4 + 1] = 0x8e00 | (entry & 0xffff0000); - idt[vector * 4 + 2] = entry >> 32; + idt[vector * 2] = (entry & 0xffff) | (INMATE_CS64 << 16) | + ((0x8e00 | (entry & 0xffff0000)) << 32); + idt[vector * 2 + 1] = entry >> 32; } #ifdef __x86_64__ diff --git a/inmates/lib/x86/setup.c b/inmates/lib/x86/setup.c index 869e0962..a1455993 100644 --- a/inmates/lib/x86/setup.c +++ b/inmates/lib/x86/setup.c @@ -42,10 +42,18 @@ #define AUTHENTIC_AMD(n) (((const u32 *)"AuthenticAMD")[n]) +struct desc_table_reg { + u16 limit; + unsigned long base; +} __attribute__((packed)); + bool jailhouse_use_vmcall = true; +unsigned long idt[(32 + MAX_INTERRUPT_VECTORS) * 2]; + void arch_init_early(void) { + struct desc_table_reg dtr; u32 eax, ebx, ecx, edx; asm volatile("cpuid" @@ -58,4 +66,8 @@ void arch_init_early(void) edx == AUTHENTIC_AMD(1) && ecx == AUTHENTIC_AMD(2)) jailhouse_use_vmcall = false; + + dtr.limit = sizeof(idt) - 1; + dtr.base = (unsigned long)&idt; + asm volatile("lidt %0" : : "m" (dtr)); } -- 2.16.4 -- You received this message because you are subscribed to the Google Groups "Jailhouse" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jailhouse-dev/cc7c3b6c5b2473f4fc09d61f218a8bf00b43a887.1557914551.git.jan.kiszka%40web.de. For more options, visit https://groups.google.com/d/optout.
