From patchwork Tue Dec 14 15:48:48 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gleb Natapov X-Patchwork-Id: 410511 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oBEFmtL1007091 for ; Tue, 14 Dec 2010 15:49:22 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759416Ab0LNPsx (ORCPT ); Tue, 14 Dec 2010 10:48:53 -0500 Received: from mx1.redhat.com ([209.132.183.28]:5898 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758315Ab0LNPsv (ORCPT ); Tue, 14 Dec 2010 10:48:51 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oBEFmoaU031526 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 14 Dec 2010 10:48:51 -0500 Received: from dhcp-1-237.tlv.redhat.com (dhcp-1-237.tlv.redhat.com [10.35.1.237]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id oBEFmoRB013528; Tue, 14 Dec 2010 10:48:50 -0500 Received: by dhcp-1-237.tlv.redhat.com (Postfix, from userid 13519) id 86EDF133F78; Tue, 14 Dec 2010 17:48:49 +0200 (IST) From: Gleb Natapov To: kvm@vger.kernel.org Cc: avi@redhat.com Subject: [PATCH unit-tests 3/4] Remove duplicated idt code from apic test. Date: Tue, 14 Dec 2010 17:48:48 +0200 Message-Id: <1292341729-20680-3-git-send-email-gleb@redhat.com> In-Reply-To: <1292341729-20680-1-git-send-email-gleb@redhat.com> References: <1292341729-20680-1-git-send-email-gleb@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Tue, 14 Dec 2010 15:49:23 +0000 (UTC) diff --git a/x86/apic.c b/x86/apic.c index 2207040..6d06f9f 100644 --- a/x86/apic.c +++ b/x86/apic.c @@ -2,22 +2,7 @@ #include "apic.h" #include "vm.h" #include "smp.h" - -typedef struct { - unsigned short offset0; - unsigned short selector; - unsigned short ist : 3; - unsigned short : 5; - unsigned short type : 4; - unsigned short : 1; - unsigned short dpl : 2; - unsigned short p : 1; - unsigned short offset1; -#ifdef __x86_64__ - unsigned offset2; - unsigned reserved; -#endif -} idt_entry_t; +#include "idt.h" typedef struct { ulong regs[sizeof(ulong)*2]; @@ -90,8 +75,6 @@ asm ( #endif ); -static idt_entry_t *idt = 0; - static int g_fail; static int g_tests; @@ -128,22 +111,12 @@ void test_enable_x2apic(void) } } -static void set_idt_entry(unsigned vec, void (*func)(isr_regs_t *regs)) +static void handle_irq(unsigned vec, void (*func)(isr_regs_t *regs)) { u8 *thunk = vmalloc(50); - ulong ptr = (ulong)thunk; - idt_entry_t ent = { - .offset0 = ptr, - .selector = read_cs(), - .ist = 0, - .type = 14, - .dpl = 0, - .p = 1, - .offset1 = ptr >> 16, -#ifdef __x86_64__ - .offset2 = ptr >> 32, -#endif - }; + + set_idt_entry(vec, thunk, 0); + #ifdef __x86_64__ /* sub $8, %rsp */ *thunk++ = 0x48; *thunk++ = 0x83; *thunk++ = 0xec; *thunk++ = 0x08; @@ -164,7 +137,6 @@ static void set_idt_entry(unsigned vec, void (*func)(isr_regs_t *regs)) *thunk ++ = 0xe9; *(u32 *)thunk = (ulong)isr_entry_point - (ulong)(thunk + 4); #endif - idt[vec] = ent; } static void irq_disable(void) @@ -194,7 +166,7 @@ static void test_self_ipi(void) { int vec = 0xf1; - set_idt_entry(vec, self_ipi_isr); + handle_irq(vec, self_ipi_isr); irq_enable(); apic_icr_write(APIC_DEST_SELF | APIC_DEST_PHYSICAL | APIC_DM_FIXED | vec, 0); @@ -234,7 +206,7 @@ static void ioapic_isr_77(isr_regs_t *regs) static void test_ioapic_intr(void) { - set_idt_entry(0x77, ioapic_isr_77); + handle_irq(0x77, ioapic_isr_77); set_ioapic_redir(0x10, 0x77); toggle_irq_line(0x10); asm volatile ("nop"); @@ -262,8 +234,8 @@ static void ioapic_isr_66(isr_regs_t *regs) static void test_ioapic_simultaneous(void) { - set_idt_entry(0x78, ioapic_isr_78); - set_idt_entry(0x66, ioapic_isr_66); + handle_irq(0x78, ioapic_isr_78); + handle_irq(0x66, ioapic_isr_66); set_ioapic_redir(0x10, 0x78); set_ioapic_redir(0x11, 0x66); irq_disable(); @@ -323,7 +295,7 @@ static void test_sti_nmi(void) return; } - set_idt_entry(2, nmi_handler); + handle_irq(2, nmi_handler); on_cpu(1, update_cr3, (void *)read_cr3()); sti_loop_active = 1; @@ -343,6 +315,7 @@ int main() { setup_vm(); smp_init(); + setup_idt(); test_lapic_existence();