| 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; | 
 | 30 | 		tss = *(u16 *)(gdt+2); | 
 | 31 | 		tss += *(u8 *)(gdt+4) << 16; | 
 | 32 | 		tss += *(u8 *)(gdt+7) << 24; | 
| Chuck Ebbert | 3dab307 | 2007-08-10 22:31:11 +0200 | [diff] [blame] | 33 | 		printk(KERN_EMERG "double fault, tss at %08lx\n", tss); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 |  | 
 | 35 | 		if (ptr_ok(tss)) { | 
| Glauber de Oliveira Costa | ca241c7 | 2008-01-30 13:31:31 +0100 | [diff] [blame] | 36 | 			struct x86_hw_tss *t = (struct x86_hw_tss *)tss; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 |  | 
| H. Peter Anvin | faca622 | 2008-01-30 13:31:02 +0100 | [diff] [blame] | 38 | 			printk(KERN_EMERG "eip = %08lx, esp = %08lx\n", | 
 | 39 | 			       t->ip, t->sp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 |  | 
| Chuck Ebbert | 3dab307 | 2007-08-10 22:31:11 +0200 | [diff] [blame] | 41 | 			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] | 42 | 				t->ax, t->bx, t->cx, t->dx); | 
| Chuck Ebbert | 3dab307 | 2007-08-10 22:31:11 +0200 | [diff] [blame] | 43 | 			printk(KERN_EMERG "esi = %08lx, edi = %08lx\n", | 
| H. Peter Anvin | faca622 | 2008-01-30 13:31:02 +0100 | [diff] [blame] | 44 | 				t->si, t->di); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | 		} | 
 | 46 | 	} | 
 | 47 |  | 
| Chuck Ebbert | caad3c2 | 2006-06-25 05:46:53 -0700 | [diff] [blame] | 48 | 	for (;;) | 
 | 49 | 		cpu_relax(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | } | 
 | 51 |  | 
 | 52 | struct tss_struct doublefault_tss __cacheline_aligned = { | 
| Rusty Russell | a75c54f | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 53 | 	.x86_tss = { | 
| H. Peter Anvin | faca622 | 2008-01-30 13:31:02 +0100 | [diff] [blame] | 54 | 		.sp0		= STACK_START, | 
| Rusty Russell | a75c54f | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 55 | 		.ss0		= __KERNEL_DS, | 
 | 56 | 		.ldt		= 0, | 
 | 57 | 		.io_bitmap_base	= INVALID_IO_BITMAP_OFFSET, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 |  | 
| H. Peter Anvin | faca622 | 2008-01-30 13:31:02 +0100 | [diff] [blame] | 59 | 		.ip		= (unsigned long) doublefault_fn, | 
| Rusty Russell | a75c54f | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 60 | 		/* 0x2 bit is always set */ | 
| H. Peter Anvin | faca622 | 2008-01-30 13:31:02 +0100 | [diff] [blame] | 61 | 		.flags		= X86_EFLAGS_SF | 0x2, | 
 | 62 | 		.sp		= STACK_START, | 
| Rusty Russell | a75c54f | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 63 | 		.es		= __USER_DS, | 
 | 64 | 		.cs		= __KERNEL_CS, | 
 | 65 | 		.ss		= __KERNEL_DS, | 
 | 66 | 		.ds		= __USER_DS, | 
| Chuck Ebbert | 3dab307 | 2007-08-10 22:31:11 +0200 | [diff] [blame] | 67 | 		.fs		= __KERNEL_PERCPU, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 |  | 
| Rusty Russell | a75c54f | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 69 | 		.__cr3		= __pa(swapper_pg_dir) | 
 | 70 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | }; |