xen-vtx-unstable

annotate xen/arch/x86/x86_64/traps.c @ 5073:6dda721a273a

bitkeeper revision 1.1503 (428f1042Yao-1v9mZSxNem0DoJz-Yw)

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