xen-vtx-unstable

annotate xen/arch/x86/x86_64/traps.c @ 6477:872e94f8eb69

Fix x86/64 Xen register and stack dumps so they don't
wrap on an 80-column display.
Signed-off-by: Jan Beulich <jbeulich@novell.com>
author kaf24@firebug.cl.cam.ac.uk
date Tue Aug 30 16:44:05 2005 +0000 (2005-08-30)
parents 9312a3e8a6f8
children 1fc6473ecc01 287d36b46fa3 f0dc15fd3c1b
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@5824 9 #include <xen/symbols.h>
kaf24@3630 10 #include <xen/console.h>
kaf24@3650 11 #include <xen/sched.h>
cl349@5291 12 #include <asm/current.h>
kaf24@5159 13 #include <asm/flushtlb.h>
kaf24@3650 14 #include <asm/msr.h>
kaf24@3602 15
kaf24@4683 16 void show_registers(struct cpu_user_regs *regs)
kaf24@3602 17 {
kaf24@6477 18 printk("CPU: %d\nRIP: %04x:[<%016lx>]",
kaf24@5824 19 smp_processor_id(), 0xffff & regs->cs, regs->rip);
kaf24@6232 20 if ( !GUEST_MODE(regs) )
kaf24@6233 21 print_symbol(" %s", regs->rip);
kaf24@6477 22 printk("\nRFLAGS: %016lx\n", regs->eflags);
kaf24@6477 23 printk("rax: %016lx rbx: %016lx rcx: %016lx\n",
kaf24@6477 24 regs->rax, regs->rbx, regs->rcx);
kaf24@6477 25 printk("rdx: %016lx rsi: %016lx rdi: %016lx\n",
kaf24@6477 26 regs->rdx, regs->rsi, regs->rdi);
kaf24@6477 27 printk("rbp: %016lx rsp: %016lx r8: %016lx\n",
kaf24@6477 28 regs->rbp, regs->rsp, regs->r8);
kaf24@6477 29 printk("r9: %016lx r10: %016lx r11: %016lx\n",
kaf24@6477 30 regs->r9, regs->r10, regs->r11);
kaf24@6477 31 printk("r12: %016lx r13: %016lx r14: %016lx\n",
kaf24@6477 32 regs->r12, regs->r13, regs->r14);
kaf24@6477 33 printk("r15: %016lx\n", regs->r15);
kaf24@3602 34
kaf24@4923 35 if ( GUEST_MODE(regs) )
kaf24@4923 36 show_guest_stack();
kaf24@5073 37 else
kaf24@5073 38 show_stack((unsigned long *)regs->rsp);
kaf24@5073 39 }
kaf24@3602 40
kaf24@3630 41 void show_page_walk(unsigned long addr)
kaf24@3630 42 {
kaf24@3630 43 unsigned long page = read_cr3();
kaf24@3630 44
kaf24@4654 45 printk("Pagetable walk from %016lx:\n", addr);
kaf24@3630 46
kaf24@3630 47 page &= PAGE_MASK;
kaf24@3630 48 page = ((unsigned long *) __va(page))[l4_table_offset(addr)];
kaf24@4654 49 printk(" L4 = %016lx\n", page);
kaf24@3630 50 if ( !(page & _PAGE_PRESENT) )
kaf24@3630 51 return;
kaf24@3630 52
kaf24@3630 53 page &= PAGE_MASK;
kaf24@3630 54 page = ((unsigned long *) __va(page))[l3_table_offset(addr)];
kaf24@4654 55 printk(" L3 = %016lx\n", page);
kaf24@3630 56 if ( !(page & _PAGE_PRESENT) )
kaf24@3630 57 return;
kaf24@3630 58
kaf24@3630 59 page &= PAGE_MASK;
kaf24@3630 60 page = ((unsigned long *) __va(page))[l2_table_offset(addr)];
kaf24@4654 61 printk(" L2 = %016lx %s\n", page, (page & _PAGE_PSE) ? "(2MB)" : "");
kaf24@3630 62 if ( !(page & _PAGE_PRESENT) || (page & _PAGE_PSE) )
kaf24@3630 63 return;
kaf24@3630 64
kaf24@3630 65 page &= PAGE_MASK;
kaf24@3630 66 page = ((unsigned long *) __va(page))[l1_table_offset(addr)];
kaf24@4654 67 printk(" L1 = %016lx\n", page);
kaf24@3630 68 }
kaf24@3630 69
kaf24@3630 70 asmlinkage void double_fault(void);
kaf24@4683 71 asmlinkage void do_double_fault(struct cpu_user_regs *regs)
kaf24@3630 72 {
kaf24@4926 73 watchdog_disable();
kaf24@3630 74
kaf24@3686 75 console_force_unlock();
kaf24@3686 76
kaf24@3630 77 /* Find information saved during fault and dump it to the console. */
kaf24@3630 78 printk("************************************\n");
kaf24@3695 79 show_registers(regs);
kaf24@3630 80 printk("************************************\n");
kaf24@3695 81 printk("CPU%d DOUBLE FAULT -- system shutdown\n", smp_processor_id());
kaf24@3630 82 printk("System needs manual reset.\n");
kaf24@3630 83 printk("************************************\n");
kaf24@3630 84
kaf24@3630 85 /* Lock up the console to prevent spurious output from other CPUs. */
kaf24@3630 86 console_force_lock();
kaf24@3630 87
kaf24@3630 88 /* Wait for manual reset. */
kaf24@3630 89 for ( ; ; )
kaf24@3630 90 __asm__ __volatile__ ( "hlt" );
kaf24@3630 91 }
kaf24@3630 92
kaf24@3761 93 asmlinkage void syscall_enter(void);
kaf24@3650 94 void __init percpu_traps_init(void)
kaf24@3650 95 {
kaf24@3761 96 char *stack_bottom, *stack;
kaf24@3761 97 int cpu = smp_processor_id();
kaf24@3761 98
kaf24@3774 99 if ( cpu == 0 )
kaf24@3774 100 {
kaf24@3774 101 /* Specify dedicated interrupt stacks for NMIs and double faults. */
kaf24@3774 102 set_intr_gate(TRAP_double_fault, &double_fault);
kaf24@3774 103 idt_table[TRAP_double_fault].a |= 1UL << 32; /* IST1 */
kaf24@3774 104 idt_table[TRAP_nmi].a |= 2UL << 32; /* IST2 */
kaf24@3774 105 }
kaf24@3774 106
kaf24@3761 107 stack_bottom = (char *)get_stack_bottom();
kaf24@3761 108 stack = (char *)((unsigned long)stack_bottom & ~(STACK_SIZE - 1));
kaf24@3695 109
kaf24@3695 110 /* Double-fault handler has its own per-CPU 1kB stack. */
kaf24@3695 111 init_tss[cpu].ist[0] = (unsigned long)&stack[1024];
kaf24@3695 112
kaf24@3695 113 /* NMI handler has its own per-CPU 1kB stack. */
kaf24@3695 114 init_tss[cpu].ist[1] = (unsigned long)&stack[2048];
kaf24@3695 115
kaf24@3695 116 /*
kaf24@3695 117 * Trampoline for SYSCALL entry from long mode.
kaf24@3695 118 */
kaf24@3695 119
kaf24@3695 120 /* Skip the NMI and DF stacks. */
kaf24@3695 121 stack = &stack[2048];
kaf24@3695 122 wrmsr(MSR_LSTAR, (unsigned long)stack, ((unsigned long)stack>>32));
kaf24@3650 123
kaf24@3650 124 /* movq %rsp, saversp(%rip) */
kaf24@3650 125 stack[0] = 0x48;
kaf24@3650 126 stack[1] = 0x89;
kaf24@3650 127 stack[2] = 0x25;
kaf24@3761 128 *(u32 *)&stack[3] = (stack_bottom - &stack[7]) - 16;
kaf24@3650 129
kaf24@3650 130 /* leaq saversp(%rip), %rsp */
kaf24@3650 131 stack[7] = 0x48;
kaf24@3650 132 stack[8] = 0x8d;
kaf24@3650 133 stack[9] = 0x25;
kaf24@3761 134 *(u32 *)&stack[10] = (stack_bottom - &stack[14]) - 16;
kaf24@3650 135
kaf24@3783 136 /* pushq %r11 */
kaf24@3783 137 stack[14] = 0x41;
kaf24@3783 138 stack[15] = 0x53;
kaf24@3783 139
kaf24@3783 140 /* pushq $__GUEST_CS64 */
kaf24@3783 141 stack[16] = 0x68;
kaf24@3783 142 *(u32 *)&stack[17] = __GUEST_CS64;
kaf24@3783 143
kaf24@3761 144 /* jmp syscall_enter */
kaf24@3783 145 stack[21] = 0xe9;
kaf24@3783 146 *(u32 *)&stack[22] = (char *)syscall_enter - &stack[26];
kaf24@3650 147
kaf24@3695 148 /*
kaf24@3695 149 * Trampoline for SYSCALL entry from compatibility mode.
kaf24@3695 150 */
kaf24@3695 151
kaf24@3695 152 /* Skip the long-mode entry trampoline. */
kaf24@3783 153 stack = &stack[26];
kaf24@3695 154 wrmsr(MSR_CSTAR, (unsigned long)stack, ((unsigned long)stack>>32));
kaf24@3695 155
kaf24@3695 156 /* movq %rsp, saversp(%rip) */
kaf24@3695 157 stack[0] = 0x48;
kaf24@3695 158 stack[1] = 0x89;
kaf24@3695 159 stack[2] = 0x25;
kaf24@3761 160 *(u32 *)&stack[3] = (stack_bottom - &stack[7]) - 16;
kaf24@3695 161
kaf24@3695 162 /* leaq saversp(%rip), %rsp */
kaf24@3695 163 stack[7] = 0x48;
kaf24@3695 164 stack[8] = 0x8d;
kaf24@3695 165 stack[9] = 0x25;
kaf24@3761 166 *(u32 *)&stack[10] = (stack_bottom - &stack[14]) - 16;
kaf24@3695 167
kaf24@3783 168 /* pushq %r11 */
kaf24@3783 169 stack[14] = 0x41;
kaf24@3783 170 stack[15] = 0x53;
kaf24@3783 171
kaf24@3783 172 /* pushq $__GUEST_CS32 */
kaf24@3783 173 stack[16] = 0x68;
kaf24@3783 174 *(u32 *)&stack[17] = __GUEST_CS32;
kaf24@3783 175
kaf24@3761 176 /* jmp syscall_enter */
kaf24@3783 177 stack[21] = 0xe9;
kaf24@3783 178 *(u32 *)&stack[22] = (char *)syscall_enter - &stack[26];
kaf24@3695 179
kaf24@3695 180 /*
kaf24@3695 181 * Common SYSCALL parameters.
kaf24@3695 182 */
kaf24@3695 183
kaf24@3696 184 wrmsr(MSR_STAR, 0, (FLAT_RING3_CS32<<16) | __HYPERVISOR_CS);
kaf24@3822 185 wrmsr(MSR_SYSCALL_MASK, EF_VM|EF_RF|EF_NT|EF_DF|EF_IE|EF_TF, 0U);
kaf24@3650 186 }
kaf24@3650 187
kaf24@3780 188 long do_set_callbacks(unsigned long event_address,
kaf24@3780 189 unsigned long failsafe_address,
kaf24@3780 190 unsigned long syscall_address)
kaf24@3780 191 {
kaf24@5289 192 struct vcpu *d = current;
kaf24@3780 193
kaf24@4689 194 d->arch.guest_context.event_callback_eip = event_address;
kaf24@4689 195 d->arch.guest_context.failsafe_callback_eip = failsafe_address;
kaf24@4689 196 d->arch.guest_context.syscall_callback_eip = syscall_address;
kaf24@3780 197
kaf24@3780 198 return 0;
kaf24@3780 199 }