blob: b4f14c6c09d9b12971c1673ebac761515e91a4be [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#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)
13static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
15
Chuck Ebbert3dab3072007-08-10 22:31:11 +020016#define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18static void doublefault_fn(void)
19{
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +010020 struct desc_ptr gdt_desc = {0, 0};
Linus Torvalds1da177e2005-04-16 15:20:36 -070021 unsigned long gdt, tss;
22
Zachary Amsden4d37e7e2005-09-03 15:56:38 -070023 store_gdt(&gdt_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 gdt = gdt_desc.address;
25
Chuck Ebbert3dab3072007-08-10 22:31:11 +020026 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
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 Ebbert3dab3072007-08-10 22:31:11 +020033 printk(KERN_EMERG "double fault, tss at %08lx\n", tss);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35 if (ptr_ok(tss)) {
Glauber de Oliveira Costaca241c72008-01-30 13:31:31 +010036 struct x86_hw_tss *t = (struct x86_hw_tss *)tss;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
H. Peter Anvinfaca6222008-01-30 13:31:02 +010038 printk(KERN_EMERG "eip = %08lx, esp = %08lx\n",
39 t->ip, t->sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Chuck Ebbert3dab3072007-08-10 22:31:11 +020041 printk(KERN_EMERG "eax = %08lx, ebx = %08lx, ecx = %08lx, edx = %08lx\n",
H. Peter Anvinfaca6222008-01-30 13:31:02 +010042 t->ax, t->bx, t->cx, t->dx);
Chuck Ebbert3dab3072007-08-10 22:31:11 +020043 printk(KERN_EMERG "esi = %08lx, edi = %08lx\n",
H. Peter Anvinfaca6222008-01-30 13:31:02 +010044 t->si, t->di);
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 }
46 }
47
Chuck Ebbertcaad3c22006-06-25 05:46:53 -070048 for (;;)
49 cpu_relax();
Linus Torvalds1da177e2005-04-16 15:20:36 -070050}
51
52struct tss_struct doublefault_tss __cacheline_aligned = {
Rusty Russella75c54f2007-05-02 19:27:13 +020053 .x86_tss = {
H. Peter Anvinfaca6222008-01-30 13:31:02 +010054 .sp0 = STACK_START,
Rusty Russella75c54f2007-05-02 19:27:13 +020055 .ss0 = __KERNEL_DS,
56 .ldt = 0,
57 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET,
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
H. Peter Anvinfaca6222008-01-30 13:31:02 +010059 .ip = (unsigned long) doublefault_fn,
Rusty Russella75c54f2007-05-02 19:27:13 +020060 /* 0x2 bit is always set */
H. Peter Anvinfaca6222008-01-30 13:31:02 +010061 .flags = X86_EFLAGS_SF | 0x2,
62 .sp = STACK_START,
Rusty Russella75c54f2007-05-02 19:27:13 +020063 .es = __USER_DS,
64 .cs = __KERNEL_CS,
65 .ss = __KERNEL_DS,
66 .ds = __USER_DS,
Chuck Ebbert3dab3072007-08-10 22:31:11 +020067 .fs = __KERNEL_PERCPU,
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Vegard Nossumaf5c2bd2008-10-03 17:54:25 +020069 .__cr3 = __pa_nodebug(swapper_pg_dir),
Rusty Russella75c54f2007-05-02 19:27:13 +020070 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070071};