idt_zero_divide.S 836 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. # IDT Zero Divide
  3. Division by zero causes a Divide Error which Intel notes as `#DE`.
  4. Expected output: "division by zero handled"
  5. It is then handled by IDT 0.
  6. Remember that DE is not *only* for division by zero: it also happens on overflow!
  7. Thus the name: Division Error, and not Division by zero.
  8. - http://stackoverflow.com/questions/33029457/what-to-do-in-interrupt-handler-for-divide-by-zero
  9. */
  10. #include "common.h"
  11. BEGIN
  12. STAGE2
  13. CLEAR
  14. PROTECTED_MODE
  15. IDT_SETUP_ENTRY $0, $handler
  16. lidt idt_descriptor
  17. mov $0, %edx
  18. mov $1, %eax
  19. mov $0, %ecx
  20. /* The iret jumps back here! */
  21. div %ecx
  22. jmp .
  23. IDT_START
  24. IDT_ENTRY
  25. IDT_END
  26. handler:
  27. VGA_PRINT_STRING $message
  28. /* If we don't do this, we get an infinite loop! */
  29. mov $1, %ecx
  30. iret
  31. message:
  32. .asciz "division by zero handled"