test: Add IDT framework
PATCH v2 1/1 test: Add IDT framework
Signed-off-by Sheng Yang <[email protected]>
Signed-off-by Avi Kivity <[email protected]>
--- kvm/test/config-x86-common.mak | 2 + kvm/test/config-x86_64.mak | 2 +- kvm/test/flat.lds | 7 ++- kvm/test/lib/x86/idt.h | 19 +++++ kvm/test/x86/idt.c | 154 ++++++++++++++++++++++++++++++++++++++++ kvm/test/x86/idt_test.c | 53 ++++++++++++++ 6 files changed, 235 insertions(+), 2 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/flat.lds +6 -1
@@ -4,7 +4,12 @@ SECTIONS stext = .; .text : { *(.init) *(.text) *(.text.*) } . = ALIGN(4K); - .data : { *(.data) } + .data : { + *(.data) + exception_table_start = .; + *(.data.ex) + exception_table_end = .; + } . = ALIGN(16); .rodata : { *(.rodata) } . = ALIGN(16);
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 ASM_TRY (catch) \ + "movl $0, %%gs:4 \n\t" \ + ".pushsection .data.ex \n\t" \ + ".quad 1111f, " catch "\n\t" \ + ".popsection \n\t" \ + "1111:" + +#define UD_VECTOR 6 +#define GP_VECTOR 13 + +unsigned exception_vector (void ); +unsigned exception_error_code (void ); + +#endif
kvm/test/x86/idt.c new file +154 -0
154 lines not on this page · raw message
kvm/test/x86/idt_test.c new file +53 -0
53 lines not on this page · raw message
Signature · 1 line
1.7.1
Quoted 2 lines · On Thursday 10 June 2010 21:30:14 Avi Kivity wrote:
Signed-off-by Sheng Yang <[email protected]>Signed-off-by Avi Kivity <[email protected]>
Really great work!
Quoted 12 lines
--- kvm/test/config-x86-common.mak | 2 + kvm/test/config-x86_64.mak | 2 +- kvm/test/flat.lds | 7 ++- kvm/test/lib/x86/idt.h | 19 +++++ kvm/test/x86/idt.c | 154 ++++++++++++++++++++++++++++++++++++++++ kvm/test/x86/idt_test.c | 53 ++++++++++++++ 6 files changed, 235 insertions(+), 2 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
[...]
Quoted 4 lines
kvm/test/x86/idt.c new file +4
-0+void do_handle_exception (struct ex_regs *regs) +{ +struct ex_record *ex; +unsigned ex_val;
kvm/test/x86/idt.c line 95
Quoted 10 lines
kvm/test/x86/idt.c new file +10
-0+ +printf ("exception: vector %ld error %lx rip %lx\n" , regs->vector, + regs->error_code, regs->rip); + + ex_val = regs->vector | (regs->error_code <<16 ); + + asm("mov %0, %%gs:4" : :"r" (ex_val)); + +for (ex = &exception_table_start; ex != &exception_table_end; ++ex) { +printf ("ex_table: %lx %lx\n" , ex->rip, ex->handler);
How about use something like #ifdef VERBOSE? (Well, in fact I didn't use unit test much, if you don't mind the format of output, it's also fine.)
kvm/test/x86/idt_test.c line 44
Quoted 10 lines
kvm/test/x86/idt_test.c new file +10
-0+int test (void ) +{ +int r; + +setup_idt (); +printf ("GP testing: " ); + r =test_gp (); +report (r ==GP_VECTOR ,"#GP" ); + r =test_ud2 (); +report (r ==UD_VECTOR ,"#UD" );
Miss a "UD testing"?
--
regards
Yang, Sheng
Quoted 9 lines
kvm/test/x86/idt_test.c new file +9
-0+return !nr_fail ?0 :1 ; +} + +int main (void ) +{ +printf ("start testing\n" ); +test (); +return 0 ; +}
Quoted 11 lines · Sheng Yang
Quoted 11 lines
kvm/test/x86/idt.c new file +9
-0+void do_handle_exception (struct ex_regs *regs) +{ +struct ex_record *ex; +unsigned ex_val; + +printf ("exception: vector %ld error %lx rip %lx\n" , regs->vector, + regs->error_code, regs->rip); + + ex_val = regs->vector | (regs->error_code<<16 );
Quoted 9 lines
kvm/test/x86/idt.c line 95
Quoted 6 lines
kvm/test/x86/idt.c new file +5
-0+ + asm("mov %0, %%gs:4" : :"r" (ex_val)); + +for (ex =&exception_table_start; ex !=&exception_table_end; ++ex) { +printf ("ex_table: %lx %lx\n" , ex->rip, ex->handler);How about use something like #ifdef VERBOSE? (Well, in fact I didn't use unit test much, if you don't mind the format of output, it's also fine.)
That was just debugging code I forgot to remove. It shouldn't be there except for the unhandled exception case.
Quoted 14 lines
kvm/test/x86/idt_test.c line 44
Quoted 12 lines
kvm/test/x86/idt_test.c new file +10
-0+int test (void ) +{ +int r; + +setup_idt (); +printf ("GP testing: " ); + r =test_gp (); +report (r ==GP_VECTOR ,"#GP" ); + r =test_ud2 (); +report (r ==UD_VECTOR ,"#UD" );Miss a "UD testing"?
Yeah :(
Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this signature is too narrow to contain.