idt_test.c 886 B

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