From: Gleb Natapov <gleb@redhat.com>
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 [thread overview]
Message-ID: <1292341729-20680-3-git-send-email-gleb@redhat.com> (raw)
In-Reply-To: <1292341729-20680-1-git-send-email-gleb@redhat.com>
Use library idt code instead.
---
x86/apic.c | 49 +++++++++++--------------------------------------
1 files changed, 11 insertions(+), 38 deletions(-)
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();
--
1.7.2.3
next prev parent reply other threads:[~2010-12-14 15:48 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-14 15:48 [PATCH unit-tests 1/4] Move idt.c into lib code Gleb Natapov
2010-12-14 15:48 ` [PATCH unit-tests 2/4] Make access.c use library functions Gleb Natapov
2010-12-14 15:48 ` Gleb Natapov [this message]
2010-12-14 15:48 ` [PATCH unit-tests 4/4] Remove unused function from apic test Gleb Natapov
2010-12-21 16:15 ` [PATCH unit-tests 1/4] Move idt.c into lib code Marcelo Tosatti
2010-12-21 16:38 ` Gleb Natapov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1292341729-20680-3-git-send-email-gleb@redhat.com \
--to=gleb@redhat.com \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox