From patchwork Wed Dec 22 15:06:16 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gleb Natapov X-Patchwork-Id: 427871 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 oBMF6Zq0013672 for ; Wed, 22 Dec 2010 15:06:36 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753110Ab0LVPGc (ORCPT ); Wed, 22 Dec 2010 10:06:32 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51806 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752400Ab0LVPGb (ORCPT ); Wed, 22 Dec 2010 10:06:31 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oBMF6VkA026618 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 22 Dec 2010 10:06:31 -0500 Received: from dhcp-1-237.tlv.redhat.com (dhcp-1-237.tlv.redhat.com [10.35.1.237]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id oBMF6Uea021219; Wed, 22 Dec 2010 10:06:30 -0500 Received: by dhcp-1-237.tlv.redhat.com (Postfix, from userid 13519) id 7E45318D3EC; Wed, 22 Dec 2010 17:06:29 +0200 (IST) From: Gleb Natapov To: avi@redhat.com, mtosatti@redhat.com Cc: kvm@vger.kernel.org Subject: [PATCH unit-tests 03/16] Remove duplicated idt code from apic test. Date: Wed, 22 Dec 2010 17:06:16 +0200 Message-Id: <1293030389-1143-4-git-send-email-gleb@redhat.com> In-Reply-To: <1293030389-1143-1-git-send-email-gleb@redhat.com> References: <1293030389-1143-1-git-send-email-gleb@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 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]); Wed, 22 Dec 2010 15:06:36 +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();