xen-vtx-unstable

annotate xen/arch/x86/x86_64/traps.c @ 3630:d55d523078f7

bitkeeper revision 1.1159.212.77 (4202221693AFbvFZWeMHHIjQfbzTIQ)

More x86_64 prgress. Many more gaps filled in. Next step is DOM0
construction.
Signed-off-by: keir.fraser@cl.cam.ac.uk
author kaf24@scramble.cl.cam.ac.uk
date Thu Feb 03 13:07:34 2005 +0000 (2005-02-03)
parents bf2c38625b39
children bbe8541361dd 8c6281ec8860
rev   line source
kaf24@3602 1
kaf24@3602 2 #include <xen/config.h>
kaf24@3602 3 #include <xen/init.h>
kaf24@3602 4 #include <xen/sched.h>
kaf24@3602 5 #include <xen/lib.h>
kaf24@3602 6 #include <xen/errno.h>
kaf24@3602 7 #include <xen/mm.h>
kaf24@3602 8 #include <xen/irq.h>
kaf24@3630 9 #include <xen/console.h>
kaf24@3602 10
kaf24@3602 11 static int kstack_depth_to_print = 8*20;
kaf24@3602 12
kaf24@3602 13 static inline int kernel_text_address(unsigned long addr)
kaf24@3602 14 {
kaf24@3602 15 if (addr >= (unsigned long) &_stext &&
kaf24@3602 16 addr <= (unsigned long) &_etext)
kaf24@3602 17 return 1;
kaf24@3602 18 return 0;
kaf24@3602 19
kaf24@3602 20 }
kaf24@3602 21
kaf24@3602 22 void show_guest_stack(void)
kaf24@3602 23 {
kaf24@3602 24 int i;
kaf24@3602 25 execution_context_t *ec = get_execution_context();
kaf24@3602 26 unsigned long *stack = (unsigned long *)ec->rsp;
kaf24@3621 27 printk("Guest RIP is %lx\n ", ec->rip);
kaf24@3602 28
kaf24@3602 29 for ( i = 0; i < kstack_depth_to_print; i++ )
kaf24@3602 30 {
kaf24@3602 31 if ( ((long)stack & (STACK_SIZE-1)) == 0 )
kaf24@3602 32 break;
kaf24@3602 33 if ( i && ((i % 8) == 0) )
kaf24@3621 34 printk("\n ");
kaf24@3621 35 printk("%p ", *stack++);
kaf24@3602 36 }
kaf24@3602 37 printk("\n");
kaf24@3602 38
kaf24@3602 39 }
kaf24@3602 40
kaf24@3602 41 void show_trace(unsigned long *rsp)
kaf24@3602 42 {
kaf24@3602 43 unsigned long *stack, addr;
kaf24@3602 44 int i;
kaf24@3602 45
kaf24@3621 46 printk("Call Trace from RSP=%p:\n ", rsp);
kaf24@3602 47 stack = rsp;
kaf24@3602 48 i = 0;
kaf24@3602 49 while (((long) stack & (STACK_SIZE-1)) != 0) {
kaf24@3602 50 addr = *stack++;
kaf24@3602 51 if (kernel_text_address(addr)) {
kaf24@3602 52 if (i && ((i % 6) == 0))
kaf24@3602 53 printk("\n ");
kaf24@3621 54 printk("[<%p>] ", addr);
kaf24@3602 55 i++;
kaf24@3602 56 }
kaf24@3602 57 }
kaf24@3602 58 printk("\n");
kaf24@3602 59 }
kaf24@3602 60
kaf24@3602 61 void show_stack(unsigned long *rsp)
kaf24@3602 62 {
kaf24@3602 63 unsigned long *stack;
kaf24@3602 64 int i;
kaf24@3602 65
kaf24@3621 66 printk("Stack trace from RSP=%p:\n ", rsp);
kaf24@3602 67
kaf24@3602 68 stack = rsp;
kaf24@3602 69 for ( i = 0; i < kstack_depth_to_print; i++ )
kaf24@3602 70 {
kaf24@3602 71 if ( ((long)stack & (STACK_SIZE-1)) == 0 )
kaf24@3602 72 break;
kaf24@3602 73 if ( i && ((i % 8) == 0) )
kaf24@3621 74 printk("\n ");
kaf24@3602 75 if ( kernel_text_address(*stack) )
kaf24@3621 76 printk("[%p] ", *stack++);
kaf24@3602 77 else
kaf24@3621 78 printk("%p ", *stack++);
kaf24@3602 79 }
kaf24@3602 80 printk("\n");
kaf24@3602 81
kaf24@3602 82 show_trace(rsp);
kaf24@3602 83 }
kaf24@3602 84
kaf24@3602 85 void show_registers(struct xen_regs *regs)
kaf24@3602 86 {
kaf24@3621 87 printk("CPU: %d\nEIP: %04lx:[<%p>] \nEFLAGS: %p\n",
kaf24@3602 88 smp_processor_id(), 0xffff & regs->cs, regs->rip, regs->eflags);
kaf24@3621 89 printk("rax: %p rbx: %p rcx: %p rdx: %p\n",
kaf24@3602 90 regs->rax, regs->rbx, regs->rcx, regs->rdx);
kaf24@3621 91 printk("rsi: %p rdi: %p rbp: %p rsp: %p\n",
kaf24@3621 92 regs->rsi, regs->rdi, regs->rbp, regs->rsp);
kaf24@3621 93 printk("r8: %p r9: %p r10: %p r11: %p\n",
kaf24@3602 94 regs->r8, regs->r9, regs->r10, regs->r11);
kaf24@3621 95 printk("r12: %p r13: %p r14: %p r15: %p\n",
kaf24@3602 96 regs->r12, regs->r13, regs->r14, regs->r15);
kaf24@3602 97
kaf24@3602 98 show_stack((unsigned long *)regs->rsp);
kaf24@3602 99 }
kaf24@3602 100
kaf24@3630 101 void show_page_walk(unsigned long addr)
kaf24@3630 102 {
kaf24@3630 103 unsigned long page = read_cr3();
kaf24@3630 104
kaf24@3630 105 printk("Pagetable walk from %p:\n", addr);
kaf24@3630 106
kaf24@3630 107 page &= PAGE_MASK;
kaf24@3630 108 page = ((unsigned long *) __va(page))[l4_table_offset(addr)];
kaf24@3630 109 printk(" L4 = %p\n", page);
kaf24@3630 110 if ( !(page & _PAGE_PRESENT) )
kaf24@3630 111 return;
kaf24@3630 112
kaf24@3630 113 page &= PAGE_MASK;
kaf24@3630 114 page = ((unsigned long *) __va(page))[l3_table_offset(addr)];
kaf24@3630 115 printk(" L3 = %p\n", page);
kaf24@3630 116 if ( !(page & _PAGE_PRESENT) )
kaf24@3630 117 return;
kaf24@3630 118
kaf24@3630 119 page &= PAGE_MASK;
kaf24@3630 120 page = ((unsigned long *) __va(page))[l2_table_offset(addr)];
kaf24@3630 121 printk(" L2 = %p %s\n", page, (page & _PAGE_PSE) ? "(2MB)" : "");
kaf24@3630 122 if ( !(page & _PAGE_PRESENT) || (page & _PAGE_PSE) )
kaf24@3630 123 return;
kaf24@3630 124
kaf24@3630 125 page &= PAGE_MASK;
kaf24@3630 126 page = ((unsigned long *) __va(page))[l1_table_offset(addr)];
kaf24@3630 127 printk(" L1 = %p\n", page);
kaf24@3630 128 }
kaf24@3630 129
kaf24@3630 130 #define DOUBLEFAULT_STACK_SIZE 1024
kaf24@3630 131 static unsigned char doublefault_stack[DOUBLEFAULT_STACK_SIZE];
kaf24@3630 132 asmlinkage void double_fault(void);
kaf24@3630 133
kaf24@3630 134 asmlinkage void do_double_fault(struct xen_regs *regs)
kaf24@3630 135 {
kaf24@3630 136 /* Disable the NMI watchdog. It's useless now. */
kaf24@3630 137 watchdog_on = 0;
kaf24@3630 138
kaf24@3630 139 /* Find information saved during fault and dump it to the console. */
kaf24@3630 140 printk("************************************\n");
kaf24@3630 141 printk("EIP: %04lx:[<%p>] \nEFLAGS: %p\n",
kaf24@3630 142 0xffff & regs->cs, regs->rip, regs->eflags);
kaf24@3630 143 printk("rax: %p rbx: %p rcx: %p rdx: %p\n",
kaf24@3630 144 regs->rax, regs->rbx, regs->rcx, regs->rdx);
kaf24@3630 145 printk("rsi: %p rdi: %p rbp: %p rsp: %p\n",
kaf24@3630 146 regs->rsi, regs->rdi, regs->rbp, regs->rsp);
kaf24@3630 147 printk("r8: %p r9: %p r10: %p r11: %p\n",
kaf24@3630 148 regs->r8, regs->r9, regs->r10, regs->r11);
kaf24@3630 149 printk("r12: %p r13: %p r14: %p r15: %p\n",
kaf24@3630 150 regs->r12, regs->r13, regs->r14, regs->r15);
kaf24@3630 151 printk("************************************\n");
kaf24@3630 152 printk("CPU%d DOUBLE FAULT -- system shutdown\n",
kaf24@3630 153 logical_smp_processor_id());
kaf24@3630 154 printk("System needs manual reset.\n");
kaf24@3630 155 printk("************************************\n");
kaf24@3630 156
kaf24@3630 157 /* Lock up the console to prevent spurious output from other CPUs. */
kaf24@3630 158 console_force_lock();
kaf24@3630 159
kaf24@3630 160 /* Wait for manual reset. */
kaf24@3630 161 for ( ; ; )
kaf24@3630 162 __asm__ __volatile__ ( "hlt" );
kaf24@3630 163 }
kaf24@3630 164
kaf24@3602 165 void __init doublefault_init(void)
kaf24@3602 166 {
kaf24@3630 167 int i;
kaf24@3630 168
kaf24@3630 169 /* Initialise IST1 for each CPU. Note the handler is non-reentrant. */
kaf24@3630 170 for ( i = 0; i < NR_CPUS; i++ )
kaf24@3630 171 init_tss[i].ist[0] = (unsigned long)
kaf24@3630 172 &doublefault_stack[DOUBLEFAULT_STACK_SIZE];
kaf24@3630 173
kaf24@3630 174 /* Set interrupt gate for double faults, specifying IST1. */
kaf24@3630 175 set_intr_gate(TRAP_double_fault, &double_fault);
kaf24@3630 176 idt_table[TRAP_double_fault].a |= 1UL << 32; /* IST1 */
kaf24@3602 177 }
kaf24@3602 178
kaf24@3602 179 void *decode_reg(struct xen_regs *regs, u8 b)
kaf24@3602 180 {
kaf24@3602 181 switch ( b )
kaf24@3602 182 {
kaf24@3602 183 case 0: return &regs->rax;
kaf24@3602 184 case 1: return &regs->rcx;
kaf24@3602 185 case 2: return &regs->rdx;
kaf24@3602 186 case 3: return &regs->rbx;
kaf24@3602 187 case 4: return &regs->rsp;
kaf24@3602 188 case 5: return &regs->rbp;
kaf24@3602 189 case 6: return &regs->rsi;
kaf24@3602 190 case 7: return &regs->rdi;
kaf24@3602 191 case 8: return &regs->r8;
kaf24@3602 192 case 9: return &regs->r9;
kaf24@3602 193 case 10: return &regs->r10;
kaf24@3602 194 case 11: return &regs->r11;
kaf24@3602 195 case 12: return &regs->r12;
kaf24@3602 196 case 13: return &regs->r13;
kaf24@3602 197 case 14: return &regs->r14;
kaf24@3602 198 case 15: return &regs->r15;
kaf24@3602 199 }
kaf24@3602 200
kaf24@3602 201 return NULL;
kaf24@3602 202 }