ia64/xen-unstable

view xen/arch/x86/x86_64/traps.c @ 3650:8c6281ec8860

bitkeeper revision 1.1159.212.87 (4203b25aTB_XSOA2G0yxgrj0ey-vIA)

Defined per-CPU SYSCALL entry point for hypercalls. We enter the DOM0
kernel and can receive hypercalls. Now probably need to fix the
user-access (uaccess.h) functions and macros.
Signed-off-by: keir.fraser@cl.cam.ac.uk
author kaf24@scramble.cl.cam.ac.uk
date Fri Feb 04 17:35:22 2005 +0000 (2005-02-04)
parents d55d523078f7
children 393483ae9f62 253e8e10e986
line source
2 #include <xen/config.h>
3 #include <xen/init.h>
4 #include <xen/sched.h>
5 #include <xen/lib.h>
6 #include <xen/errno.h>
7 #include <xen/mm.h>
8 #include <xen/irq.h>
9 #include <xen/console.h>
10 #include <xen/sched.h>
11 #include <asm/msr.h>
13 static int kstack_depth_to_print = 8*20;
15 static inline int kernel_text_address(unsigned long addr)
16 {
17 if (addr >= (unsigned long) &_stext &&
18 addr <= (unsigned long) &_etext)
19 return 1;
20 return 0;
22 }
24 void show_guest_stack(void)
25 {
26 int i;
27 execution_context_t *ec = get_execution_context();
28 unsigned long *stack = (unsigned long *)ec->rsp;
29 printk("Guest RIP is %lx\n ", ec->rip);
31 for ( i = 0; i < kstack_depth_to_print; i++ )
32 {
33 if ( ((long)stack & (STACK_SIZE-1)) == 0 )
34 break;
35 if ( i && ((i % 8) == 0) )
36 printk("\n ");
37 printk("%p ", *stack++);
38 }
39 printk("\n");
41 }
43 void show_trace(unsigned long *rsp)
44 {
45 unsigned long *stack, addr;
46 int i;
48 printk("Call Trace from RSP=%p:\n ", rsp);
49 stack = rsp;
50 i = 0;
51 while (((long) stack & (STACK_SIZE-1)) != 0) {
52 addr = *stack++;
53 if (kernel_text_address(addr)) {
54 if (i && ((i % 6) == 0))
55 printk("\n ");
56 printk("[<%p>] ", addr);
57 i++;
58 }
59 }
60 printk("\n");
61 }
63 void show_stack(unsigned long *rsp)
64 {
65 unsigned long *stack;
66 int i;
68 printk("Stack trace from RSP=%p:\n ", rsp);
70 stack = rsp;
71 for ( i = 0; i < kstack_depth_to_print; i++ )
72 {
73 if ( ((long)stack & (STACK_SIZE-1)) == 0 )
74 break;
75 if ( i && ((i % 8) == 0) )
76 printk("\n ");
77 if ( kernel_text_address(*stack) )
78 printk("[%p] ", *stack++);
79 else
80 printk("%p ", *stack++);
81 }
82 printk("\n");
84 show_trace(rsp);
85 }
87 void show_registers(struct xen_regs *regs)
88 {
89 printk("CPU: %d\nEIP: %04lx:[<%p>] \nEFLAGS: %p\n",
90 smp_processor_id(), 0xffff & regs->cs, regs->rip, regs->eflags);
91 printk("rax: %p rbx: %p rcx: %p rdx: %p\n",
92 regs->rax, regs->rbx, regs->rcx, regs->rdx);
93 printk("rsi: %p rdi: %p rbp: %p rsp: %p\n",
94 regs->rsi, regs->rdi, regs->rbp, regs->rsp);
95 printk("r8: %p r9: %p r10: %p r11: %p\n",
96 regs->r8, regs->r9, regs->r10, regs->r11);
97 printk("r12: %p r13: %p r14: %p r15: %p\n",
98 regs->r12, regs->r13, regs->r14, regs->r15);
100 show_stack((unsigned long *)regs->rsp);
101 }
103 void show_page_walk(unsigned long addr)
104 {
105 unsigned long page = read_cr3();
107 printk("Pagetable walk from %p:\n", addr);
109 page &= PAGE_MASK;
110 page = ((unsigned long *) __va(page))[l4_table_offset(addr)];
111 printk(" L4 = %p\n", page);
112 if ( !(page & _PAGE_PRESENT) )
113 return;
115 page &= PAGE_MASK;
116 page = ((unsigned long *) __va(page))[l3_table_offset(addr)];
117 printk(" L3 = %p\n", page);
118 if ( !(page & _PAGE_PRESENT) )
119 return;
121 page &= PAGE_MASK;
122 page = ((unsigned long *) __va(page))[l2_table_offset(addr)];
123 printk(" L2 = %p %s\n", page, (page & _PAGE_PSE) ? "(2MB)" : "");
124 if ( !(page & _PAGE_PRESENT) || (page & _PAGE_PSE) )
125 return;
127 page &= PAGE_MASK;
128 page = ((unsigned long *) __va(page))[l1_table_offset(addr)];
129 printk(" L1 = %p\n", page);
130 }
132 #define DOUBLEFAULT_STACK_SIZE 1024
133 static unsigned char doublefault_stack[DOUBLEFAULT_STACK_SIZE];
134 asmlinkage void double_fault(void);
136 asmlinkage void do_double_fault(struct xen_regs *regs)
137 {
138 /* Disable the NMI watchdog. It's useless now. */
139 watchdog_on = 0;
141 /* Find information saved during fault and dump it to the console. */
142 printk("************************************\n");
143 printk("EIP: %04lx:[<%p>] \nEFLAGS: %p\n",
144 0xffff & regs->cs, regs->rip, regs->eflags);
145 printk("rax: %p rbx: %p rcx: %p rdx: %p\n",
146 regs->rax, regs->rbx, regs->rcx, regs->rdx);
147 printk("rsi: %p rdi: %p rbp: %p rsp: %p\n",
148 regs->rsi, regs->rdi, regs->rbp, regs->rsp);
149 printk("r8: %p r9: %p r10: %p r11: %p\n",
150 regs->r8, regs->r9, regs->r10, regs->r11);
151 printk("r12: %p r13: %p r14: %p r15: %p\n",
152 regs->r12, regs->r13, regs->r14, regs->r15);
153 printk("************************************\n");
154 printk("CPU%d DOUBLE FAULT -- system shutdown\n",
155 logical_smp_processor_id());
156 printk("System needs manual reset.\n");
157 printk("************************************\n");
159 /* Lock up the console to prevent spurious output from other CPUs. */
160 console_force_lock();
162 /* Wait for manual reset. */
163 for ( ; ; )
164 __asm__ __volatile__ ( "hlt" );
165 }
167 void __init doublefault_init(void)
168 {
169 int i;
171 /* Initialise IST1 for each CPU. Note the handler is non-reentrant. */
172 for ( i = 0; i < NR_CPUS; i++ )
173 init_tss[i].ist[0] = (unsigned long)
174 &doublefault_stack[DOUBLEFAULT_STACK_SIZE];
176 /* Set interrupt gate for double faults, specifying IST1. */
177 set_intr_gate(TRAP_double_fault, &double_fault);
178 idt_table[TRAP_double_fault].a |= 1UL << 32; /* IST1 */
179 }
181 asmlinkage void hypercall(void);
182 void __init percpu_traps_init(void)
183 {
184 char *stack_top = (char *)get_stack_top();
185 char *stack = (char *)((unsigned long)stack_top & ~(STACK_SIZE - 1));
187 /* movq %rsp, saversp(%rip) */
188 stack[0] = 0x48;
189 stack[1] = 0x89;
190 stack[2] = 0x25;
191 *(u32 *)&stack[3] = (stack_top - &stack[7]) - 16;
193 /* leaq saversp(%rip), %rsp */
194 stack[7] = 0x48;
195 stack[8] = 0x8d;
196 stack[9] = 0x25;
197 *(u32 *)&stack[10] = (stack_top - &stack[14]) - 16;
199 /* jmp hypercall */
200 stack[14] = 0xe9;
201 *(u32 *)&stack[15] = (char *)hypercall - &stack[19];
203 wrmsr(MSR_STAR, 0, (FLAT_RING3_CS64<<16) | __HYPERVISOR_CS);
204 wrmsr(MSR_LSTAR, (unsigned long)stack, ((unsigned long)stack>>32));
205 wrmsr(MSR_SYSCALL_MASK, 0xFFFFFFFFU, 0U);
206 }
208 void *decode_reg(struct xen_regs *regs, u8 b)
209 {
210 switch ( b )
211 {
212 case 0: return &regs->rax;
213 case 1: return &regs->rcx;
214 case 2: return &regs->rdx;
215 case 3: return &regs->rbx;
216 case 4: return &regs->rsp;
217 case 5: return &regs->rbp;
218 case 6: return &regs->rsi;
219 case 7: return &regs->rdi;
220 case 8: return &regs->r8;
221 case 9: return &regs->r9;
222 case 10: return &regs->r10;
223 case 11: return &regs->r11;
224 case 12: return &regs->r12;
225 case 13: return &regs->r13;
226 case 14: return &regs->r14;
227 case 15: return &regs->r15;
228 }
230 return NULL;
231 }