Linux-libre 3.2.3-gnu1
[librecmc/linux-libre.git] / arch / x86 / kernel / doublefault_32.c
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
16 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
17
18 static void doublefault_fn(void)
19 {
20         struct desc_ptr gdt_desc = {0, 0};
21         unsigned long gdt, tss;
22
23         store_gdt(&gdt_desc);
24         gdt = gdt_desc.address;
25
26         printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
27
28         if (ptr_ok(gdt)) {
29                 gdt += GDT_ENTRY_TSS << 3;
30                 tss = get_desc_base((struct desc_struct *)gdt);
31                 printk(KERN_EMERG "double fault, tss at %08lx\n", tss);
32
33                 if (ptr_ok(tss)) {
34                         struct x86_hw_tss *t = (struct x86_hw_tss *)tss;
35
36                         printk(KERN_EMERG "eip = %08lx, esp = %08lx\n",
37                                t->ip, t->sp);
38
39                         printk(KERN_EMERG "eax = %08lx, ebx = %08lx, ecx = %08lx, edx = %08lx\n",
40                                 t->ax, t->bx, t->cx, t->dx);
41                         printk(KERN_EMERG "esi = %08lx, edi = %08lx\n",
42                                 t->si, t->di);
43                 }
44         }
45
46         for (;;)
47                 cpu_relax();
48 }
49
50 struct tss_struct doublefault_tss __cacheline_aligned = {
51         .x86_tss = {
52                 .sp0            = STACK_START,
53                 .ss0            = __KERNEL_DS,
54                 .ldt            = 0,
55                 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET,
56
57                 .ip             = (unsigned long) doublefault_fn,
58                 /* 0x2 bit is always set */
59                 .flags          = X86_EFLAGS_SF | 0x2,
60                 .sp             = STACK_START,
61                 .es             = __USER_DS,
62                 .cs             = __KERNEL_CS,
63                 .ss             = __KERNEL_DS,
64                 .ds             = __USER_DS,
65                 .fs             = __KERNEL_PERCPU,
66
67                 .__cr3          = __pa_nodebug(swapper_pg_dir),
68         }
69 };