taskswitch.c 795 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright 2010 Siemens AG
  3. * Author: Jan Kiszka
  4. *
  5. * Released under GPLv2.
  6. */
  7. #include "libcflat.h"
  8. #include "x86/desc.h"
  9. #define TSS_RETURN (FIRST_SPARE_SEL)
  10. void fault_entry(void);
  11. static __attribute__((used, regparm(1))) void
  12. fault_handler(unsigned long error_code)
  13. {
  14. print_current_tss_info();
  15. printf("error code %lx\n", error_code);
  16. tss.eip += 2;
  17. gdt32[TSS_MAIN / 8].access &= ~2;
  18. set_gdt_task_gate(TSS_RETURN, tss_intr.prev);
  19. }
  20. asm (
  21. "fault_entry:\n"
  22. " mov (%esp),%eax\n"
  23. " call fault_handler\n"
  24. " jmp $" xstr(TSS_RETURN) ", $0\n"
  25. );
  26. int main(int ac, char **av)
  27. {
  28. const long invalid_segment = 0x1234;
  29. setup_tss32();
  30. set_intr_task_gate(13, fault_entry);
  31. asm (
  32. "mov %0,%%es\n"
  33. : : "r" (invalid_segment) : "edi"
  34. );
  35. printf("post fault\n");
  36. return 0;
  37. }