xref: /kvm-unit-tests/x86/idt_test.c (revision a322d4c597bb7a4de7985e7b51b80504f7e4fdda)
1 #include "libcflat.h"
2 #include "desc.h"
3 
4 int test_ud2(void)
5 {
6     asm volatile(ASM_TRY("1f")
7                  "ud2 \n\t"
8                  "1:" :);
9     return exception_vector();
10 }
11 
12 int test_gp(void)
13 {
14     unsigned long tmp;
15 
16     asm volatile("mov $0xffffffff, %0 \n\t"
17                  ASM_TRY("1f")
18 		 "mov %0, %%cr4\n\t"
19                  "1:"
20                  : "=a"(tmp));
21     return exception_vector();
22 }
23 
24 int main(void)
25 {
26     int r;
27 
28     printf("Starting IDT test\n");
29     setup_idt();
30     r = test_gp();
31     report("Testing #GP", r == GP_VECTOR);
32     r = test_ud2();
33     report("Testing #UD", r == UD_VECTOR);
34 
35     return report_summary();
36 }
37