| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #include <linux/mm.h> | 
|  | 2 | #include <linux/sched.h> | 
|  | 3 | #include <linux/init.h> | 
|  | 4 | #include <linux/init_task.h> | 
|  | 5 | #include <linux/fs.h> | 
|  | 6 |  | 
|  | 7 | #include <asm/uaccess.h> | 
|  | 8 | #include <asm/pgtable.h> | 
|  | 9 | #include <asm/processor.h> | 
|  | 10 | #include <asm/desc.h> | 
|  | 11 |  | 
|  | 12 | #define DOUBLEFAULT_STACKSIZE (1024) | 
|  | 13 | static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE]; | 
|  | 14 | #define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE) | 
|  | 15 |  | 
| Chuck Ebbert | 3dab307 | 2007-08-10 22:31:11 +0200 | [diff] [blame] | 16 | #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 |  | 
|  | 18 | static void doublefault_fn(void) | 
|  | 19 | { | 
| Glauber de Oliveira Costa | 6b68f01 | 2008-01-30 13:31:12 +0100 | [diff] [blame] | 20 | struct desc_ptr gdt_desc = {0, 0}; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | unsigned long gdt, tss; | 
|  | 22 |  | 
| Zachary Amsden | 4d37e7e | 2005-09-03 15:56:38 -0700 | [diff] [blame] | 23 | store_gdt(&gdt_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | gdt = gdt_desc.address; | 
|  | 25 |  | 
| Chuck Ebbert | 3dab307 | 2007-08-10 22:31:11 +0200 | [diff] [blame] | 26 | printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 |  | 
|  | 28 | if (ptr_ok(gdt)) { | 
|  | 29 | gdt += GDT_ENTRY_TSS << 3; | 
| Akinobu Mita | 254e0a6 | 2009-07-19 00:08:54 +0900 | [diff] [blame] | 30 | tss = get_desc_base((struct desc_struct *)gdt); | 
| Chuck Ebbert | 3dab307 | 2007-08-10 22:31:11 +0200 | [diff] [blame] | 31 | printk(KERN_EMERG "double fault, tss at %08lx\n", tss); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 |  | 
|  | 33 | if (ptr_ok(tss)) { | 
| Glauber de Oliveira Costa | ca241c7 | 2008-01-30 13:31:31 +0100 | [diff] [blame] | 34 | struct x86_hw_tss *t = (struct x86_hw_tss *)tss; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 |  | 
| H. Peter Anvin | faca622 | 2008-01-30 13:31:02 +0100 | [diff] [blame] | 36 | printk(KERN_EMERG "eip = %08lx, esp = %08lx\n", | 
|  | 37 | t->ip, t->sp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 |  | 
| Chuck Ebbert | 3dab307 | 2007-08-10 22:31:11 +0200 | [diff] [blame] | 39 | printk(KERN_EMERG "eax = %08lx, ebx = %08lx, ecx = %08lx, edx = %08lx\n", | 
| H. Peter Anvin | faca622 | 2008-01-30 13:31:02 +0100 | [diff] [blame] | 40 | t->ax, t->bx, t->cx, t->dx); | 
| Chuck Ebbert | 3dab307 | 2007-08-10 22:31:11 +0200 | [diff] [blame] | 41 | printk(KERN_EMERG "esi = %08lx, edi = %08lx\n", | 
| H. Peter Anvin | faca622 | 2008-01-30 13:31:02 +0100 | [diff] [blame] | 42 | t->si, t->di); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | } | 
|  | 44 | } | 
|  | 45 |  | 
| Chuck Ebbert | caad3c2 | 2006-06-25 05:46:53 -0700 | [diff] [blame] | 46 | for (;;) | 
|  | 47 | cpu_relax(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | } | 
|  | 49 |  | 
|  | 50 | struct tss_struct doublefault_tss __cacheline_aligned = { | 
| Rusty Russell | a75c54f | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 51 | .x86_tss = { | 
| H. Peter Anvin | faca622 | 2008-01-30 13:31:02 +0100 | [diff] [blame] | 52 | .sp0		= STACK_START, | 
| Rusty Russell | a75c54f | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 53 | .ss0		= __KERNEL_DS, | 
|  | 54 | .ldt		= 0, | 
|  | 55 | .io_bitmap_base	= INVALID_IO_BITMAP_OFFSET, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 |  | 
| H. Peter Anvin | faca622 | 2008-01-30 13:31:02 +0100 | [diff] [blame] | 57 | .ip		= (unsigned long) doublefault_fn, | 
| Rusty Russell | a75c54f | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 58 | /* 0x2 bit is always set */ | 
| H. Peter Anvin | faca622 | 2008-01-30 13:31:02 +0100 | [diff] [blame] | 59 | .flags		= X86_EFLAGS_SF | 0x2, | 
|  | 60 | .sp		= STACK_START, | 
| Rusty Russell | a75c54f | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 61 | .es		= __USER_DS, | 
|  | 62 | .cs		= __KERNEL_CS, | 
|  | 63 | .ss		= __KERNEL_DS, | 
|  | 64 | .ds		= __USER_DS, | 
| Chuck Ebbert | 3dab307 | 2007-08-10 22:31:11 +0200 | [diff] [blame] | 65 | .fs		= __KERNEL_PERCPU, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 |  | 
| Vegard Nossum | af5c2bd | 2008-10-03 17:54:25 +0200 | [diff] [blame] | 67 | .__cr3		= __pa_nodebug(swapper_pg_dir), | 
| Rusty Russell | a75c54f | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 68 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | }; |