* [PATCH kvm-unit-tests 0/3] DIV exception tests
@ 2010-08-24 11:01 Avi Kivity
2010-08-24 11:01 ` [PATCH kvm-unit-tests 1/3] Support #DE (divide error) exception handlers Avi Kivity
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Avi Kivity @ 2010-08-24 11:01 UTC (permalink / raw)
To: Marcelo Tosatti, kvm
DIV may raise an exception if dividing by zero or causing an overflow. Test
it.
Avi Kivity (3):
Support #DE (divide error) exception handlers
Allow emulation tests to trap exceptions
Add DIV tests
config-x86-common.mak | 3 ++-
x86/emulator.c | 20 ++++++++++++++++++++
x86/idt.c | 8 +++++++-
3 files changed, 29 insertions(+), 2 deletions(-)
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH kvm-unit-tests 1/3] Support #DE (divide error) exception handlers
2010-08-24 11:01 [PATCH kvm-unit-tests 0/3] DIV exception tests Avi Kivity
@ 2010-08-24 11:01 ` Avi Kivity
2010-08-24 11:01 ` [PATCH kvm-unit-tests 2/3] Allow emulation tests to trap exceptions Avi Kivity
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Avi Kivity @ 2010-08-24 11:01 UTC (permalink / raw)
To: Marcelo Tosatti, kvm
Signed-off-by: Avi Kivity <avi@redhat.com>
---
x86/idt.c | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/x86/idt.c b/x86/idt.c
index 590839f..4480833 100644
--- a/x86/idt.c
+++ b/x86/idt.c
@@ -100,6 +100,11 @@ asm (".pushsection .text \n\t"
"pushq $13 \n\t"
"jmp handle_exception \n\t"
+ "de_fault: \n\t"
+ "pushq $0 \n\t"
+ "pushq $0 \n\t"
+ "jmp handle_exception \n\t"
+
"handle_exception: \n\t"
"push %r15; push %r14; push %r13; push %r12 \n\t"
"push %r11; push %r10; push %r9; push %r8 \n\t"
@@ -118,9 +123,10 @@ asm (".pushsection .text \n\t"
void setup_idt(void)
{
- extern char ud_fault, gp_fault;
+ extern char ud_fault, gp_fault, de_fault;
lidt(idt, 256);
+ set_idt_entry(&idt[0], &de_fault, 0);
set_idt_entry(&idt[6], &ud_fault, 0);
set_idt_entry(&idt[13], &gp_fault, 0);
}
--
1.7.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH kvm-unit-tests 2/3] Allow emulation tests to trap exceptions
2010-08-24 11:01 [PATCH kvm-unit-tests 0/3] DIV exception tests Avi Kivity
2010-08-24 11:01 ` [PATCH kvm-unit-tests 1/3] Support #DE (divide error) exception handlers Avi Kivity
@ 2010-08-24 11:01 ` Avi Kivity
2010-08-24 11:01 ` [PATCH kvm-unit-tests 3/3] Add DIV tests Avi Kivity
2010-08-25 20:23 ` [PATCH kvm-unit-tests 0/3] DIV exception tests Marcelo Tosatti
3 siblings, 0 replies; 5+ messages in thread
From: Avi Kivity @ 2010-08-24 11:01 UTC (permalink / raw)
To: Marcelo Tosatti, kvm
Some instructions trap on execution, we need a way to see if they raise an
exception as expected.
Signed-off-by: Avi Kivity <avi@redhat.com>
---
config-x86-common.mak | 3 ++-
x86/emulator.c | 2 ++
2 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/config-x86-common.mak b/config-x86-common.mak
index 19bffd4..0ed13e4 100644
--- a/config-x86-common.mak
+++ b/config-x86-common.mak
@@ -45,7 +45,8 @@ $(TEST_DIR)/vmexit.flat: $(cstart.o) $(TEST_DIR)/vmexit.o
$(TEST_DIR)/smptest.flat: $(cstart.o) $(TEST_DIR)/smptest.o
$(TEST_DIR)/emulator.flat: $(cstart.o) $(TEST_DIR)/emulator.o \
- $(TEST_DIR)/vm.o $(TEST_DIR)/print.o
+ $(TEST_DIR)/vm.o $(TEST_DIR)/print.o \
+ $(TEST_DIR)/idt.o
$(TEST_DIR)/port80.flat: $(cstart.o) $(TEST_DIR)/port80.o
diff --git a/x86/emulator.c b/x86/emulator.c
index b0d15c0..5d1659f 100644
--- a/x86/emulator.c
+++ b/x86/emulator.c
@@ -1,6 +1,7 @@
#include "ioram.h"
#include "vm.h"
#include "libcflat.h"
+#include "idt.h"
#define memset __builtin_memset
#define TESTDEV_IO_PORT 0xe0
@@ -582,6 +583,7 @@ int main()
unsigned long t1, t2;
setup_vm();
+ setup_idt();
mem = vmap(IORAM_BASE_PHYS, IORAM_LEN);
// test mov reg, r/m and mov r/m, reg
--
1.7.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH kvm-unit-tests 3/3] Add DIV tests
2010-08-24 11:01 [PATCH kvm-unit-tests 0/3] DIV exception tests Avi Kivity
2010-08-24 11:01 ` [PATCH kvm-unit-tests 1/3] Support #DE (divide error) exception handlers Avi Kivity
2010-08-24 11:01 ` [PATCH kvm-unit-tests 2/3] Allow emulation tests to trap exceptions Avi Kivity
@ 2010-08-24 11:01 ` Avi Kivity
2010-08-25 20:23 ` [PATCH kvm-unit-tests 0/3] DIV exception tests Marcelo Tosatti
3 siblings, 0 replies; 5+ messages in thread
From: Avi Kivity @ 2010-08-24 11:01 UTC (permalink / raw)
To: Marcelo Tosatti, kvm
Test divide-by-zero and normal cases.
Signed-off-by: Avi Kivity <avi@redhat.com>
---
x86/emulator.c | 18 ++++++++++++++++++
1 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/x86/emulator.c b/x86/emulator.c
index 5d1659f..845e7a0 100644
--- a/x86/emulator.c
+++ b/x86/emulator.c
@@ -577,6 +577,23 @@ static void test_imul(ulong *mem)
report("imul rax, mem, imm", a == 0x1D950BDE1D950BC8L);
}
+static void test_div(long *mem)
+{
+ long a, d;
+ u8 ex = 1;
+
+ *mem = 0; a = 1; d = 2;
+ asm (ASM_TRY("1f") "divq %3; movb $0, %2; 1:"
+ : "+a"(a), "+d"(d), "+q"(ex) : "m"(*mem));
+ report("divq (fault)", a == 1 && d == 2 && ex);
+
+ *mem = 987654321098765UL; a = 123456789012345UL; d = 123456789012345UL;
+ asm (ASM_TRY("1f") "divq %3; movb $0, %2; 1:"
+ : "+a"(a), "+d"(d), "+q"(ex) : "m"(*mem));
+ report("divq (1)",
+ a == 0x1ffffffb1b963b33ul && d == 0x273ba4384ede2ul && !ex);
+}
+
int main()
{
void *mem;
@@ -614,6 +631,7 @@ int main()
test_btc(mem);
test_bsfbsr(mem);
test_imul(mem);
+ test_div(mem);
printf("\nSUMMARY: %d tests, %d failures\n", tests, fails);
return fails ? 1 : 0;
--
1.7.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH kvm-unit-tests 0/3] DIV exception tests
2010-08-24 11:01 [PATCH kvm-unit-tests 0/3] DIV exception tests Avi Kivity
` (2 preceding siblings ...)
2010-08-24 11:01 ` [PATCH kvm-unit-tests 3/3] Add DIV tests Avi Kivity
@ 2010-08-25 20:23 ` Marcelo Tosatti
3 siblings, 0 replies; 5+ messages in thread
From: Marcelo Tosatti @ 2010-08-25 20:23 UTC (permalink / raw)
To: Avi Kivity; +Cc: kvm
On Tue, Aug 24, 2010 at 02:01:08PM +0300, Avi Kivity wrote:
> DIV may raise an exception if dividing by zero or causing an overflow. Test
> it.
>
> Avi Kivity (3):
> Support #DE (divide error) exception handlers
> Allow emulation tests to trap exceptions
> Add DIV tests
>
> config-x86-common.mak | 3 ++-
> x86/emulator.c | 20 ++++++++++++++++++++
> x86/idt.c | 8 +++++++-
> 3 files changed, 29 insertions(+), 2 deletions(-)
Applied, thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-08-25 21:23 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-24 11:01 [PATCH kvm-unit-tests 0/3] DIV exception tests Avi Kivity
2010-08-24 11:01 ` [PATCH kvm-unit-tests 1/3] Support #DE (divide error) exception handlers Avi Kivity
2010-08-24 11:01 ` [PATCH kvm-unit-tests 2/3] Allow emulation tests to trap exceptions Avi Kivity
2010-08-24 11:01 ` [PATCH kvm-unit-tests 3/3] Add DIV tests Avi Kivity
2010-08-25 20:23 ` [PATCH kvm-unit-tests 0/3] DIV exception tests Marcelo Tosatti
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).