doublefault.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #include <linux/mm.h>
  2. #include <linux/sched.h>
  3. #include <linux/init_task.h>
  4. #include <linux/fs.h>
  5. #include <asm/uaccess.h>
  6. #include <asm/pgtable.h>
  7. #include <asm/processor.h>
  8. #include <asm/desc.h>
  9. #ifdef CONFIG_X86_32
  10. #define DOUBLEFAULT_STACKSIZE (1024)
  11. static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
  12. #define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
  13. #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
  14. static void doublefault_fn(void)
  15. {
  16. struct desc_ptr gdt_desc = {0, 0};
  17. unsigned long gdt, tss;
  18. native_store_gdt(&gdt_desc);
  19. gdt = gdt_desc.address;
  20. printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
  21. if (ptr_ok(gdt)) {
  22. gdt += GDT_ENTRY_TSS << 3;
  23. tss = get_desc_base((struct desc_struct *)gdt);
  24. printk(KERN_EMERG "double fault, tss at %08lx\n", tss);
  25. if (ptr_ok(tss)) {
  26. struct x86_hw_tss *t = (struct x86_hw_tss *)tss;
  27. printk(KERN_EMERG "eip = %08lx, esp = %08lx\n",
  28. t->ip, t->sp);
  29. printk(KERN_EMERG "eax = %08lx, ebx = %08lx, ecx = %08lx, edx = %08lx\n",
  30. t->ax, t->bx, t->cx, t->dx);
  31. printk(KERN_EMERG "esi = %08lx, edi = %08lx\n",
  32. t->si, t->di);
  33. }
  34. }
  35. for (;;)
  36. cpu_relax();
  37. }
  38. struct tss_struct doublefault_tss __cacheline_aligned = {
  39. .x86_tss = {
  40. .sp0 = STACK_START,
  41. .ss0 = __KERNEL_DS,
  42. .ldt = 0,
  43. .io_bitmap_base = INVALID_IO_BITMAP_OFFSET,
  44. .ip = (unsigned long) doublefault_fn,
  45. /* 0x2 bit is always set */
  46. .flags = X86_EFLAGS_SF | 0x2,
  47. .sp = STACK_START,
  48. .es = __USER_DS,
  49. .cs = __KERNEL_CS,
  50. .ss = __KERNEL_DS,
  51. .ds = __USER_DS,
  52. .fs = __KERNEL_PERCPU,
  53. .__cr3 = __pa_nodebug(swapper_pg_dir),
  54. }
  55. };
  56. /* dummy for do_double_fault() call */
  57. void df_debug(struct pt_regs *regs, long error_code) {}
  58. #else /* !CONFIG_X86_32 */
  59. void df_debug(struct pt_regs *regs, long error_code)
  60. {
  61. pr_emerg("PANIC: double fault, error_code: 0x%lx\n", error_code);
  62. show_regs(regs);
  63. panic("Machine halted.");
  64. }
  65. #endif