test: Add IDT framework
PATCH 1/2 test: Add IDT framework
--- kvm/test/config-x86-common.mak | 2 + kvm/test/config-x86_64.mak | 2 +- kvm/test/lib/x86/idt.h | 19 +++++++++ kvm/test/x86/idt.c | 85 ++++++++++++++++++++++++++++++++++++++++ kvm/test/x86/idt_test.c | 48 ++++++++++++++++++++++ 5 files changed, 155 insertions(+), 1 deletions(-) create mode 100644 kvm/test/lib/x86/idt.h create mode 100644 kvm/test/x86/idt.c create mode 100644 kvm/test/x86/idt_test.c
kvm/test/config-x86-common.mak +2 -0
@@ -59,6 +59,8 @@ $(TEST_DIR)/realmode.o: bits = 32 $(TEST_DIR)/msr.flat: $(cstart.o) $(TEST_DIR)/msr.o +$(TEST_DIR)/idt_test.flat: $(cstart.o) $(TEST_DIR)/idt.o $(TEST_DIR)/idt_test.o + arch_clean: $(RM) $(TEST_DIR)/*.o $(TEST_DIR)/*.flat \ $(TEST_DIR)/.*.d $(TEST_DIR)/lib/.*.d $(TEST_DIR)/lib/*.o
kvm/test/config-x86_64.mak +1 -1
@@ -5,6 +5,6 @@ ldarch = elf64-x86-64 CFLAGS += -D__x86_64__ tests = $(TEST_DIR)/access.flat $(TEST_DIR)/apic.flat \ - $(TEST_DIR)/emulator.flat + $(TEST_DIR)/emulator.flat $(TEST_DIR)/idt_test.flat include config-x86-common.mak
kvm/test/lib/x86/idt.h new file +19 -0
@@ -0,0 +1,19 @@ +#ifndef __IDT_TEST__ +#define __IDT_TEST__ + +void setup_idt (void ); + +#define EXCEPTION_REGION_BEGIN (r, lb) \ + asm volatile("pushq $"lb"\n\t" \ + "mov $2, %0\n\t" \ + : "=r"(r)) +#define EXCEPTION_REGION_END (r, lb) \ + asm volatile("popq %%rdx\n\t" \ + "mov $0, %0\n\t" \ + lb":\n\t": \ + "=r"(r) :: "%rdx") + +#define UD_VECTOR 6 +#define GP_VECTOR 13 + +#endif
kvm/test/x86/idt.c new file +85 -0
85 lines not on this page · raw message
kvm/test/x86/idt_test.c new file +48 -0
48 lines not on this page · raw message
Signature · 1 line
1.7.0.1
PATCH 2/2 test: Add XSAVE unit test
--- kvm/test/config-x86-common.mak | 2 + kvm/test/config-x86_64.mak | 3 +- kvm/test/x86/xsave.c | 263 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 267 insertions(+), 1 deletions(-) create mode 100644 kvm/test/x86/xsave.c
kvm/test/config-x86-common.mak +2 -0
@@ -61,6 +61,8 @@ $(TEST_DIR)/msr.flat: $(cstart.o) $(TEST_DIR)/msr.o $(TEST_DIR)/idt_test.flat: $(cstart.o) $(TEST_DIR)/idt.o $(TEST_DIR)/idt_test.o +$(TEST_DIR)/xsave.flat: $(cstart.o) $(TEST_DIR)/idt.o $(TEST_DIR)/xsave.o + arch_clean: $(RM) $(TEST_DIR)/*.o $(TEST_DIR)/*.flat \ $(TEST_DIR)/.*.d $(TEST_DIR)/lib/.*.d $(TEST_DIR)/lib/*.o
kvm/test/config-x86_64.mak +2 -1
@@ -5,6 +5,7 @@ ldarch = elf64-x86-64 CFLAGS += -D__x86_64__ tests = $(TEST_DIR)/access.flat $(TEST_DIR)/apic.flat \ - $(TEST_DIR)/emulator.flat $(TEST_DIR)/idt_test.flat + $(TEST_DIR)/emulator.flat $(TEST_DIR)/idt_test.flat \ + $(TEST_DIR)/xsave.flat include config-x86-common.mak
kvm/test/x86/xsave.c new file +263 -0
263 lines not on this page · raw message
Signature · 1 line
1.7.0.1
kvm/test/lib/x86/idt.h line 14
Quoted 11 lines · Sheng Yang
kvm/test/lib/x86/idt.h new file +10
-0+ +#define EXCEPTION_REGION_BEGIN (r, lb) \ + asm volatile("pushq $"lb"\n\t" \ + "mov $2, %0\n\t" \ + : "=r"(r)) +#define EXCEPTION_REGION_END (r, lb) \ + asm volatile("popq %%rdx\n\t" \ + "mov $0, %0\n\t" \ + lb":\n\t": \ + "=r"(r) :: "%rdx")
These mess up the stack, no? So if any intervening code uses %rsp based addressing, it will get incorrect information.
I suggest using a special data section like the kernel.
Also, most tests that use asm don't need an exception region, but will want to trap an exception on a single address. So need a macro designed to be placed in asm in front of the faulting instruction.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 14 lines · On Thursday 10 June 2010 17:49:16 Avi Kivity wrote:
kvm/test/lib/x86/idt.h line 14
Quoted 10 lines · Sheng Yang
kvm/test/lib/x86/idt.h new file +10
-0+ +#define EXCEPTION_REGION_BEGIN (r, lb) \ + asm volatile("pushq $"lb"\n\t" \ + "mov $2, %0\n\t" \ + : "=r"(r)) +#define EXCEPTION_REGION_END (r, lb) \ + asm volatile("popq %%rdx\n\t" \ + "mov $0, %0\n\t" \ + lb":\n\t": \ + "=r"(r) :: "%rdx")These mess up the stack, no? So if any intervening code uses %rsp based addressing, it will get incorrect information.
Yes, but I meant to only include instruction directly in the “region”, and support nobody should touch $rsp then. It's directly and simple enough.
Quoted 2 lines
I suggest using a special data section like the kernel.
Kind of more complex...
Quoted 4 lines
Also, most tests that use asm don't need an exception region, but will want to trap an exception on a single address. So need a macro designed to be placed in asm in front of the faulting instruction.
Use region here is due to we don't know the size of instruction(or I don't know how to get it)... Use a label here seems the simplest way to get the address right.
--
regards
Yang, Sheng
Quoted 18 lines · Sheng Yang
Quoted 16 lines · On Thursday 10 June 2010 17:49:16 Avi Kivity wrote:
kvm/test/lib/x86/idt.h line 14
Quoted 11 lines · Sheng Yang
kvm/test/lib/x86/idt.h new file +10
-0+ +#define EXCEPTION_REGION_BEGIN (r, lb) \ + asm volatile("pushq $"lb"\n\t" \ + "mov $2, %0\n\t" \ + : "=r"(r)) +#define EXCEPTION_REGION_END (r, lb) \ + asm volatile("popq %%rdx\n\t" \ + "mov $0, %0\n\t" \ + lb":\n\t": \ + "=r"(r) :: "%rdx")These mess up the stack, no? So if any intervening code uses %rsp based addressing, it will get incorrect information.
Quoted 3 lines
Yes, but I meant to only include instruction directly in the “region”, and support nobody should touch $rsp then. It's directly and simple enough.
Something like "=m"(blah) can cause access to %rsp, usually when compiling without frame pointers.
Quoted 4 lines
Quoted 2 lines
I suggest using a special data section like the kernel.
Kind of more complex...
Makes it more fun. I'll have a go.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 7 lines · Avi Kivity
Something like "=m"(blah) can cause access to %rsp, usually when compiling without frame pointers.
Quoted 2 lines
Quoted 1 line
I suggest using a special data section like the kernel.
Kind of more complex...
Makes it more fun. I'll have a go.
Posted. Currently fails due to a bug in kvm (writing to cr4 causes the fault rip to point to the following instruction, patch to follow).
Signature · 1 line
error compiling committee.c: too many arguments to function