xen-vtx-unstable

annotate xen/arch/x86/x86_64/traps.c @ 3822:1413266e3117

bitkeeper revision 1.1196 (420e70da1IwWQhyIdvfGOYQgoJQsJA)

Fix SYSCALL RFLAGS mask.
Signed-off-by: keir@xensource.com
author kaf24@viper.(none)
date Sat Feb 12 21:10:50 2005 +0000 (2005-02-12)
parents 0069a2f1f55d
children be135facb9ee cf2f74cc53af a13b9052d91d a01199a95070
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@3602 13 static int kstack_depth_to_print = 8*20;
kaf24@3602 14
kaf24@3602 15 static inline int kernel_text_address(unsigned long addr)
kaf24@3602 16 {
kaf24@3602 17 if (addr >= (unsigned long) &_stext &&
kaf24@3602 18 addr <= (unsigned long) &_etext)
kaf24@3602 19 return 1;
kaf24@3602 20 return 0;
kaf24@3602 21
kaf24@3602 22 }
kaf24@3602 23
kaf24@3602 24 void show_guest_stack(void)
kaf24@3602 25 {
kaf24@3602 26 int i;
kaf24@3602 27 execution_context_t *ec = get_execution_context();
kaf24@3602 28 unsigned long *stack = (unsigned long *)ec->rsp;
kaf24@3621 29 printk("Guest RIP is %lx\n ", ec->rip);
kaf24@3602 30
kaf24@3602 31 for ( i = 0; i < kstack_depth_to_print; i++ )
kaf24@3602 32 {
kaf24@3602 33 if ( ((long)stack & (STACK_SIZE-1)) == 0 )
kaf24@3602 34 break;
kaf24@3602 35 if ( i && ((i % 8) == 0) )
kaf24@3621 36 printk("\n ");
kaf24@3621 37 printk("%p ", *stack++);
kaf24@3602 38 }
kaf24@3602 39 printk("\n");
kaf24@3602 40
kaf24@3602 41 }
kaf24@3602 42
kaf24@3602 43 void show_trace(unsigned long *rsp)
kaf24@3602 44 {
kaf24@3602 45 unsigned long *stack, addr;
kaf24@3602 46 int i;
kaf24@3602 47
kaf24@3621 48 printk("Call Trace from RSP=%p:\n ", rsp);
kaf24@3602 49 stack = rsp;
kaf24@3602 50 i = 0;
kaf24@3602 51 while (((long) stack & (STACK_SIZE-1)) != 0) {
kaf24@3602 52 addr = *stack++;
kaf24@3602 53 if (kernel_text_address(addr)) {
kaf24@3602 54 if (i && ((i % 6) == 0))
kaf24@3602 55 printk("\n ");
kaf24@3621 56 printk("[<%p>] ", addr);
kaf24@3602 57 i++;
kaf24@3602 58 }
kaf24@3602 59 }
kaf24@3602 60 printk("\n");
kaf24@3602 61 }
kaf24@3602 62
kaf24@3602 63 void show_stack(unsigned long *rsp)
kaf24@3602 64 {
kaf24@3602 65 unsigned long *stack;
kaf24@3602 66 int i;
kaf24@3602 67
kaf24@3621 68 printk("Stack trace from RSP=%p:\n ", rsp);
kaf24@3602 69
kaf24@3602 70 stack = rsp;
kaf24@3602 71 for ( i = 0; i < kstack_depth_to_print; i++ )
kaf24@3602 72 {
kaf24@3602 73 if ( ((long)stack & (STACK_SIZE-1)) == 0 )
kaf24@3602 74 break;
kaf24@3602 75 if ( i && ((i % 8) == 0) )
kaf24@3621 76 printk("\n ");
kaf24@3602 77 if ( kernel_text_address(*stack) )
kaf24@3621 78 printk("[%p] ", *stack++);
kaf24@3602 79 else
kaf24@3621 80 printk("%p ", *stack++);
kaf24@3602 81 }
kaf24@3602 82 printk("\n");
kaf24@3602 83
kaf24@3602 84 show_trace(rsp);
kaf24@3602 85 }
kaf24@3602 86
kaf24@3602 87 void show_registers(struct xen_regs *regs)
kaf24@3602 88 {
kaf24@3621 89 printk("CPU: %d\nEIP: %04lx:[<%p>] \nEFLAGS: %p\n",
kaf24@3602 90 smp_processor_id(), 0xffff & regs->cs, regs->rip, regs->eflags);
kaf24@3621 91 printk("rax: %p rbx: %p rcx: %p rdx: %p\n",
kaf24@3602 92 regs->rax, regs->rbx, regs->rcx, regs->rdx);
kaf24@3621 93 printk("rsi: %p rdi: %p rbp: %p rsp: %p\n",
kaf24@3621 94 regs->rsi, regs->rdi, regs->rbp, regs->rsp);
kaf24@3621 95 printk("r8: %p r9: %p r10: %p r11: %p\n",
kaf24@3602 96 regs->r8, regs->r9, regs->r10, regs->r11);
kaf24@3621 97 printk("r12: %p r13: %p r14: %p r15: %p\n",
kaf24@3602 98 regs->r12, regs->r13, regs->r14, regs->r15);
kaf24@3602 99
kaf24@3602 100 show_stack((unsigned long *)regs->rsp);
kaf24@3602 101 }
kaf24@3602 102
kaf24@3630 103 void show_page_walk(unsigned long addr)
kaf24@3630 104 {
kaf24@3630 105 unsigned long page = read_cr3();
kaf24@3630 106
kaf24@3630 107 printk("Pagetable walk from %p:\n", addr);
kaf24@3630 108
kaf24@3630 109 page &= PAGE_MASK;
kaf24@3630 110 page = ((unsigned long *) __va(page))[l4_table_offset(addr)];
kaf24@3630 111 printk(" L4 = %p\n", page);
kaf24@3630 112 if ( !(page & _PAGE_PRESENT) )
kaf24@3630 113 return;
kaf24@3630 114
kaf24@3630 115 page &= PAGE_MASK;
kaf24@3630 116 page = ((unsigned long *) __va(page))[l3_table_offset(addr)];
kaf24@3630 117 printk(" L3 = %p\n", page);
kaf24@3630 118 if ( !(page & _PAGE_PRESENT) )
kaf24@3630 119 return;
kaf24@3630 120
kaf24@3630 121 page &= PAGE_MASK;
kaf24@3630 122 page = ((unsigned long *) __va(page))[l2_table_offset(addr)];
kaf24@3630 123 printk(" L2 = %p %s\n", page, (page & _PAGE_PSE) ? "(2MB)" : "");
kaf24@3630 124 if ( !(page & _PAGE_PRESENT) || (page & _PAGE_PSE) )
kaf24@3630 125 return;
kaf24@3630 126
kaf24@3630 127 page &= PAGE_MASK;
kaf24@3630 128 page = ((unsigned long *) __va(page))[l1_table_offset(addr)];
kaf24@3630 129 printk(" L1 = %p\n", page);
kaf24@3630 130 }
kaf24@3630 131
kaf24@3630 132 asmlinkage void double_fault(void);
kaf24@3630 133 asmlinkage void do_double_fault(struct xen_regs *regs)
kaf24@3630 134 {
kaf24@3630 135 /* Disable the NMI watchdog. It's useless now. */
kaf24@3630 136 watchdog_on = 0;
kaf24@3630 137
kaf24@3686 138 console_force_unlock();
kaf24@3686 139
kaf24@3630 140 /* Find information saved during fault and dump it to the console. */
kaf24@3630 141 printk("************************************\n");
kaf24@3695 142 show_registers(regs);
kaf24@3630 143 printk("************************************\n");
kaf24@3695 144 printk("CPU%d DOUBLE FAULT -- system shutdown\n", smp_processor_id());
kaf24@3630 145 printk("System needs manual reset.\n");
kaf24@3630 146 printk("************************************\n");
kaf24@3630 147
kaf24@3630 148 /* Lock up the console to prevent spurious output from other CPUs. */
kaf24@3630 149 console_force_lock();
kaf24@3630 150
kaf24@3630 151 /* Wait for manual reset. */
kaf24@3630 152 for ( ; ; )
kaf24@3630 153 __asm__ __volatile__ ( "hlt" );
kaf24@3630 154 }
kaf24@3630 155
kaf24@3761 156 asmlinkage void syscall_enter(void);
kaf24@3650 157 void __init percpu_traps_init(void)
kaf24@3650 158 {
kaf24@3761 159 char *stack_bottom, *stack;
kaf24@3761 160 int cpu = smp_processor_id();
kaf24@3761 161
kaf24@3774 162 if ( cpu == 0 )
kaf24@3774 163 {
kaf24@3774 164 /* Specify dedicated interrupt stacks for NMIs and double faults. */
kaf24@3774 165 set_intr_gate(TRAP_double_fault, &double_fault);
kaf24@3774 166 idt_table[TRAP_double_fault].a |= 1UL << 32; /* IST1 */
kaf24@3774 167 idt_table[TRAP_nmi].a |= 2UL << 32; /* IST2 */
kaf24@3774 168 }
kaf24@3774 169
kaf24@3761 170 stack_bottom = (char *)get_stack_bottom();
kaf24@3761 171 stack = (char *)((unsigned long)stack_bottom & ~(STACK_SIZE - 1));
kaf24@3695 172
kaf24@3695 173 /* Double-fault handler has its own per-CPU 1kB stack. */
kaf24@3695 174 init_tss[cpu].ist[0] = (unsigned long)&stack[1024];
kaf24@3695 175
kaf24@3695 176 /* NMI handler has its own per-CPU 1kB stack. */
kaf24@3695 177 init_tss[cpu].ist[1] = (unsigned long)&stack[2048];
kaf24@3695 178
kaf24@3695 179 /*
kaf24@3695 180 * Trampoline for SYSCALL entry from long mode.
kaf24@3695 181 */
kaf24@3695 182
kaf24@3695 183 /* Skip the NMI and DF stacks. */
kaf24@3695 184 stack = &stack[2048];
kaf24@3695 185 wrmsr(MSR_LSTAR, (unsigned long)stack, ((unsigned long)stack>>32));
kaf24@3650 186
kaf24@3650 187 /* movq %rsp, saversp(%rip) */
kaf24@3650 188 stack[0] = 0x48;
kaf24@3650 189 stack[1] = 0x89;
kaf24@3650 190 stack[2] = 0x25;
kaf24@3761 191 *(u32 *)&stack[3] = (stack_bottom - &stack[7]) - 16;
kaf24@3650 192
kaf24@3650 193 /* leaq saversp(%rip), %rsp */
kaf24@3650 194 stack[7] = 0x48;
kaf24@3650 195 stack[8] = 0x8d;
kaf24@3650 196 stack[9] = 0x25;
kaf24@3761 197 *(u32 *)&stack[10] = (stack_bottom - &stack[14]) - 16;
kaf24@3650 198
kaf24@3783 199 /* pushq %r11 */
kaf24@3783 200 stack[14] = 0x41;
kaf24@3783 201 stack[15] = 0x53;
kaf24@3783 202
kaf24@3783 203 /* pushq $__GUEST_CS64 */
kaf24@3783 204 stack[16] = 0x68;
kaf24@3783 205 *(u32 *)&stack[17] = __GUEST_CS64;
kaf24@3783 206
kaf24@3761 207 /* jmp syscall_enter */
kaf24@3783 208 stack[21] = 0xe9;
kaf24@3783 209 *(u32 *)&stack[22] = (char *)syscall_enter - &stack[26];
kaf24@3650 210
kaf24@3695 211 /*
kaf24@3695 212 * Trampoline for SYSCALL entry from compatibility mode.
kaf24@3695 213 */
kaf24@3695 214
kaf24@3695 215 /* Skip the long-mode entry trampoline. */
kaf24@3783 216 stack = &stack[26];
kaf24@3695 217 wrmsr(MSR_CSTAR, (unsigned long)stack, ((unsigned long)stack>>32));
kaf24@3695 218
kaf24@3695 219 /* movq %rsp, saversp(%rip) */
kaf24@3695 220 stack[0] = 0x48;
kaf24@3695 221 stack[1] = 0x89;
kaf24@3695 222 stack[2] = 0x25;
kaf24@3761 223 *(u32 *)&stack[3] = (stack_bottom - &stack[7]) - 16;
kaf24@3695 224
kaf24@3695 225 /* leaq saversp(%rip), %rsp */
kaf24@3695 226 stack[7] = 0x48;
kaf24@3695 227 stack[8] = 0x8d;
kaf24@3695 228 stack[9] = 0x25;
kaf24@3761 229 *(u32 *)&stack[10] = (stack_bottom - &stack[14]) - 16;
kaf24@3695 230
kaf24@3783 231 /* pushq %r11 */
kaf24@3783 232 stack[14] = 0x41;
kaf24@3783 233 stack[15] = 0x53;
kaf24@3783 234
kaf24@3783 235 /* pushq $__GUEST_CS32 */
kaf24@3783 236 stack[16] = 0x68;
kaf24@3783 237 *(u32 *)&stack[17] = __GUEST_CS32;
kaf24@3783 238
kaf24@3761 239 /* jmp syscall_enter */
kaf24@3783 240 stack[21] = 0xe9;
kaf24@3783 241 *(u32 *)&stack[22] = (char *)syscall_enter - &stack[26];
kaf24@3695 242
kaf24@3695 243 /*
kaf24@3695 244 * Common SYSCALL parameters.
kaf24@3695 245 */
kaf24@3695 246
kaf24@3696 247 wrmsr(MSR_STAR, 0, (FLAT_RING3_CS32<<16) | __HYPERVISOR_CS);
kaf24@3822 248 wrmsr(MSR_SYSCALL_MASK, EF_VM|EF_RF|EF_NT|EF_DF|EF_IE|EF_TF, 0U);
kaf24@3650 249 }
kaf24@3650 250
kaf24@3602 251 void *decode_reg(struct xen_regs *regs, u8 b)
kaf24@3602 252 {
kaf24@3602 253 switch ( b )
kaf24@3602 254 {
kaf24@3602 255 case 0: return &regs->rax;
kaf24@3602 256 case 1: return &regs->rcx;
kaf24@3602 257 case 2: return &regs->rdx;
kaf24@3602 258 case 3: return &regs->rbx;
kaf24@3602 259 case 4: return &regs->rsp;
kaf24@3602 260 case 5: return &regs->rbp;
kaf24@3602 261 case 6: return &regs->rsi;
kaf24@3602 262 case 7: return &regs->rdi;
kaf24@3602 263 case 8: return &regs->r8;
kaf24@3602 264 case 9: return &regs->r9;
kaf24@3602 265 case 10: return &regs->r10;
kaf24@3602 266 case 11: return &regs->r11;
kaf24@3602 267 case 12: return &regs->r12;
kaf24@3602 268 case 13: return &regs->r13;
kaf24@3602 269 case 14: return &regs->r14;
kaf24@3602 270 case 15: return &regs->r15;
kaf24@3602 271 }
kaf24@3602 272
kaf24@3602 273 return NULL;
kaf24@3602 274 }
kaf24@3780 275
kaf24@3780 276 long do_set_callbacks(unsigned long event_address,
kaf24@3780 277 unsigned long failsafe_address,
kaf24@3780 278 unsigned long syscall_address)
kaf24@3780 279 {
kaf24@3780 280 struct exec_domain *d = current;
kaf24@3780 281
kaf24@3780 282 d->arch.event_address = event_address;
kaf24@3780 283 d->arch.failsafe_address = failsafe_address;
kaf24@3780 284 d->arch.syscall_address = syscall_address;
kaf24@3780 285
kaf24@3780 286 return 0;
kaf24@3780 287 }