ia64/xen-unstable

view xen/arch/x86/x86_32/entry.S @ 16195:4970cbf9b19e

x86: Fix xentrace of hypercalls in debug builds of Xen.

Based on a patch by Yosuke Iwamatsu <y-iwamatsu@ab.jp.nec.com>

Signed-off-by: Keir Fraser <keir@xensource.com>
author Keir Fraser <keir@xensource.com>
date Tue Oct 23 09:41:06 2007 +0100 (2007-10-23)
parents 42d8dadb5864
children 23582bcda6e1
line source
1 /*
2 * Hypercall and fault low-level handling routines.
3 *
4 * Copyright (c) 2002-2004, K A Fraser
5 * Copyright (c) 1991, 1992 Linus Torvalds
6 *
7 * Calling back to a guest OS:
8 * ===========================
9 *
10 * First, we require that all callbacks (either via a supplied
11 * interrupt-descriptor-table, or via the special event or failsafe callbacks
12 * in the shared-info-structure) are to ring 1. This just makes life easier,
13 * in that it means we don't have to do messy GDT/LDT lookups to find
14 * out which the privilege-level of the return code-selector. That code
15 * would just be a hassle to write, and would need to account for running
16 * off the end of the GDT/LDT, for example. For all callbacks we check
17 * that the provided return CS is not == __HYPERVISOR_{CS,DS}. Apart from that
18 * we're safe as don't allow a guest OS to install ring-0 privileges into the
19 * GDT/LDT. It's up to the guest OS to ensure all returns via the IDT are to
20 * ring 1. If not, we load incorrect SS/ESP values from the TSS (for ring 1
21 * rather than the correct ring) and bad things are bound to ensue -- IRET is
22 * likely to fault, and we may end up killing the domain (no harm can
23 * come to Xen, though).
24 *
25 * When doing a callback, we check if the return CS is in ring 0. If so,
26 * callback is delayed until next return to ring != 0.
27 * If return CS is in ring 1, then we create a callback frame
28 * starting at return SS/ESP. The base of the frame does an intra-privilege
29 * interrupt-return.
30 * If return CS is in ring > 1, we create a callback frame starting
31 * at SS/ESP taken from appropriate section of the current TSS. The base
32 * of the frame does an inter-privilege interrupt-return.
33 *
34 * Note that the "failsafe callback" uses a special stackframe:
35 * { return_DS, return_ES, return_FS, return_GS, return_EIP,
36 * return_CS, return_EFLAGS[, return_ESP, return_SS] }
37 * That is, original values for DS/ES/FS/GS are placed on stack rather than
38 * in DS/ES/FS/GS themselves. Why? It saves us loading them, only to have them
39 * saved/restored in guest OS. Furthermore, if we load them we may cause
40 * a fault if they are invalid, which is a hassle to deal with. We avoid
41 * that problem if we don't load them :-) This property allows us to use
42 * the failsafe callback as a fallback: if we ever fault on loading DS/ES/FS/GS
43 * on return to ring != 0, we can simply package it up as a return via
44 * the failsafe callback, and let the guest OS sort it out (perhaps by
45 * killing an application process). Note that we also do this for any
46 * faulting IRET -- just let the guest OS handle it via the event
47 * callback.
48 *
49 * We terminate a domain in the following cases:
50 * - creating a callback stack frame (due to bad ring-1 stack).
51 * - faulting IRET on entry to failsafe callback handler.
52 * So, each domain must keep its ring-1 %ss/%esp and failsafe callback
53 * handler in good order (absolutely no faults allowed!).
54 */
56 #include <xen/config.h>
57 #include <xen/errno.h>
58 #include <xen/softirq.h>
59 #include <asm/asm_defns.h>
60 #include <asm/apicdef.h>
61 #include <asm/page.h>
62 #include <public/xen.h>
64 #define GET_GUEST_REGS(reg) \
65 movl $~(STACK_SIZE-1),reg; \
66 andl %esp,reg; \
67 orl $(STACK_SIZE-CPUINFO_sizeof),reg;
69 #define GET_CURRENT(reg) \
70 movl $STACK_SIZE-4, reg; \
71 orl %esp, reg; \
72 andl $~3,reg; \
73 movl (reg),reg;
75 ALIGN
76 restore_all_guest:
77 ASSERT_INTERRUPTS_DISABLED
78 testl $X86_EFLAGS_VM,UREGS_eflags(%esp)
79 popl %ebx
80 popl %ecx
81 popl %edx
82 popl %esi
83 popl %edi
84 popl %ebp
85 popl %eax
86 leal 4(%esp),%esp
87 jnz .Lrestore_iret_guest
88 #ifdef CONFIG_X86_SUPERVISOR_MODE_KERNEL
89 testb $2,UREGS_cs-UREGS_eip(%esp)
90 jnz .Lrestore_sregs_guest
91 call restore_ring0_guest
92 jmp .Lrestore_iret_guest
93 #endif
94 .Lrestore_sregs_guest:
95 .Lft1: mov UREGS_ds-UREGS_eip(%esp),%ds
96 .Lft2: mov UREGS_es-UREGS_eip(%esp),%es
97 .Lft3: mov UREGS_fs-UREGS_eip(%esp),%fs
98 .Lft4: mov UREGS_gs-UREGS_eip(%esp),%gs
99 .Lrestore_iret_guest:
100 .Lft5: iret
101 .section .fixup,"ax"
102 .Lfx1: sti
103 SAVE_ALL_GPRS
104 mov UREGS_error_code(%esp),%esi
105 pushfl # EFLAGS
106 movl $__HYPERVISOR_CS,%eax
107 pushl %eax # CS
108 movl $.Ldf1,%eax
109 pushl %eax # EIP
110 pushl %esi # error_code/entry_vector
111 jmp handle_exception
112 .Ldf1: GET_CURRENT(%ebx)
113 jmp test_all_events
114 failsafe_callback:
115 GET_CURRENT(%ebx)
116 leal VCPU_trap_bounce(%ebx),%edx
117 movl VCPU_failsafe_addr(%ebx),%eax
118 movl %eax,TRAPBOUNCE_eip(%edx)
119 movl VCPU_failsafe_sel(%ebx),%eax
120 movw %ax,TRAPBOUNCE_cs(%edx)
121 movb $TBF_FAILSAFE,TRAPBOUNCE_flags(%edx)
122 bt $_VGCF_failsafe_disables_events,VCPU_guest_context_flags(%ebx)
123 jnc 1f
124 orb $TBF_INTERRUPT,TRAPBOUNCE_flags(%edx)
125 1: call create_bounce_frame
126 xorl %eax,%eax
127 movl %eax,UREGS_ds(%esp)
128 movl %eax,UREGS_es(%esp)
129 movl %eax,UREGS_fs(%esp)
130 movl %eax,UREGS_gs(%esp)
131 jmp test_all_events
132 .previous
133 .section __pre_ex_table,"a"
134 .long .Lft1,.Lfx1
135 .long .Lft2,.Lfx1
136 .long .Lft3,.Lfx1
137 .long .Lft4,.Lfx1
138 .long .Lft5,.Lfx1
139 .previous
140 .section __ex_table,"a"
141 .long .Ldf1,failsafe_callback
142 .previous
144 ALIGN
145 restore_all_xen:
146 popl %ebx
147 popl %ecx
148 popl %edx
149 popl %esi
150 popl %edi
151 popl %ebp
152 popl %eax
153 addl $4,%esp
154 iret
156 ALIGN
157 ENTRY(hypercall)
158 subl $4,%esp
159 FIXUP_RING0_GUEST_STACK
160 SAVE_ALL(1f,1f)
161 1: sti
162 GET_CURRENT(%ebx)
163 cmpl $NR_hypercalls,%eax
164 jae bad_hypercall
165 PERFC_INCR(PERFC_hypercalls, %eax, %ebx)
166 #ifndef NDEBUG
167 /* Create shadow parameters and corrupt those not used by this call. */
168 pushl %eax
169 pushl UREGS_eip+4(%esp)
170 pushl 28(%esp) # EBP
171 pushl 28(%esp) # EDI
172 pushl 28(%esp) # ESI
173 pushl 28(%esp) # EDX
174 pushl 28(%esp) # ECX
175 pushl 28(%esp) # EBX
176 movzb hypercall_args_table(,%eax,1),%ecx
177 leal (%esp,%ecx,4),%edi
178 subl $6,%ecx
179 negl %ecx
180 movl %eax,%esi
181 movl $0xDEADBEEF,%eax
182 rep stosl
183 movl %esi,%eax
184 #define SHADOW_BYTES 32 /* 6 shadow parameters + EIP + hypercall # */
185 #else
186 /*
187 * We need shadow parameters even on non-debug builds. We depend on the
188 * original versions not being clobbered (needed to create a hypercall
189 * continuation). But that isn't guaranteed by the function-call ABI.
190 */
191 pushl 20(%esp) # EBP
192 pushl 20(%esp) # EDI
193 pushl 20(%esp) # ESI
194 pushl 20(%esp) # EDX
195 pushl 20(%esp) # ECX
196 pushl 20(%esp) # EBX
197 #define SHADOW_BYTES 24 /* 6 shadow parameters */
198 #endif
199 cmpb $0,tb_init_done
200 je tracing_off
201 call trace_hypercall
202 /* Now restore all the registers that trace_hypercall clobbered */
203 movl UREGS_eax+SHADOW_BYTES(%esp),%eax /* Hypercall # */
204 #undef SHADOW_BYTES
205 tracing_off:
206 call *hypercall_table(,%eax,4)
207 addl $24,%esp # Discard the shadow parameters
208 #ifndef NDEBUG
209 /* Deliberately corrupt real parameter regs used by this hypercall. */
210 popl %ecx # Shadow EIP
211 cmpl %ecx,UREGS_eip+4(%esp)
212 popl %ecx # Shadow hypercall index
213 jne skip_clobber # If EIP has changed then don't clobber
214 movzb hypercall_args_table(,%ecx,1),%ecx
215 movl %esp,%edi
216 movl %eax,%esi
217 movl $0xDEADBEEF,%eax
218 rep stosl
219 movl %esi,%eax
220 skip_clobber:
221 #endif
222 movl %eax,UREGS_eax(%esp) # save the return value
224 test_all_events:
225 xorl %ecx,%ecx
226 notl %ecx
227 cli # tests must not race interrupts
228 /*test_softirqs:*/
229 movl VCPU_processor(%ebx),%eax
230 shl $IRQSTAT_shift,%eax
231 test %ecx,irq_stat(%eax,1)
232 jnz process_softirqs
233 testb $1,VCPU_nmi_pending(%ebx)
234 jnz process_nmi
235 test_guest_events:
236 movl VCPU_vcpu_info(%ebx),%eax
237 testb $0xFF,VCPUINFO_upcall_mask(%eax)
238 jnz restore_all_guest
239 testb $0xFF,VCPUINFO_upcall_pending(%eax)
240 jz restore_all_guest
241 /*process_guest_events:*/
242 sti
243 leal VCPU_trap_bounce(%ebx),%edx
244 movl VCPU_event_addr(%ebx),%eax
245 movl %eax,TRAPBOUNCE_eip(%edx)
246 movl VCPU_event_sel(%ebx),%eax
247 movw %ax,TRAPBOUNCE_cs(%edx)
248 movb $TBF_INTERRUPT,TRAPBOUNCE_flags(%edx)
249 call create_bounce_frame
250 jmp test_all_events
252 ALIGN
253 process_softirqs:
254 sti
255 call do_softirq
256 jmp test_all_events
258 ALIGN
259 process_nmi:
260 testb $1,VCPU_nmi_masked(%ebx)
261 jnz test_guest_events
262 movb $0,VCPU_nmi_pending(%ebx)
263 movzwl VCPU_nmi_cs(%ebx),%eax
264 movl VCPU_nmi_addr(%ebx),%ecx
265 test %eax,%eax
266 jz test_guest_events
267 movb $1,VCPU_nmi_masked(%ebx)
268 sti
269 leal VCPU_trap_bounce(%ebx),%edx
270 movw %ax,TRAPBOUNCE_cs(%edx)
271 movl %ecx,TRAPBOUNCE_eip(%edx)
272 movw $FLAT_KERNEL_CS,TRAPBOUNCE_cs(%edx)
273 movb $TBF_INTERRUPT,TRAPBOUNCE_flags(%edx)
274 call create_bounce_frame
275 jmp test_all_events
277 bad_hypercall:
278 movl $-ENOSYS,UREGS_eax(%esp)
279 jmp test_all_events
281 /* CREATE A BASIC EXCEPTION FRAME ON GUEST OS (RING-1) STACK: */
282 /* {EIP, CS, EFLAGS, [ESP, SS]} */
283 /* %edx == trap_bounce, %ebx == struct vcpu */
284 /* %eax,%ecx are clobbered. %gs:%esi contain new UREGS_ss/UREGS_esp. */
285 create_bounce_frame:
286 ASSERT_INTERRUPTS_ENABLED
287 movl UREGS_eflags+4(%esp),%ecx
288 movb UREGS_cs+4(%esp),%cl
289 testl $(2|X86_EFLAGS_VM),%ecx
290 jz ring1 /* jump if returning to an existing ring-1 activation */
291 movl VCPU_kernel_sp(%ebx),%esi
292 .Lft6: mov VCPU_kernel_ss(%ebx),%gs
293 testl $X86_EFLAGS_VM,UREGS_eflags+4(%esp)
294 jz .Lnvm86_1
295 subl $16,%esi /* push ES/DS/FS/GS (VM86 stack frame) */
296 movl UREGS_es+4(%esp),%eax
297 .Lft7: movl %eax,%gs:(%esi)
298 movl UREGS_ds+4(%esp),%eax
299 .Lft8: movl %eax,%gs:4(%esi)
300 movl UREGS_fs+4(%esp),%eax
301 .Lft9: movl %eax,%gs:8(%esi)
302 movl UREGS_gs+4(%esp),%eax
303 .Lft10: movl %eax,%gs:12(%esi)
304 .Lnvm86_1:
305 subl $8,%esi /* push SS/ESP (inter-priv iret) */
306 movl UREGS_esp+4(%esp),%eax
307 .Lft11: movl %eax,%gs:(%esi)
308 movl UREGS_ss+4(%esp),%eax
309 .Lft12: movl %eax,%gs:4(%esi)
310 jmp 1f
311 ring1: /* obtain ss/esp from oldss/oldesp -- a ring-1 activation exists */
312 movl UREGS_esp+4(%esp),%esi
313 .Lft13: mov UREGS_ss+4(%esp),%gs
314 1: /* Construct a stack frame: EFLAGS, CS/EIP */
315 movb TRAPBOUNCE_flags(%edx),%cl
316 subl $12,%esi
317 movl UREGS_eip+4(%esp),%eax
318 .Lft14: movl %eax,%gs:(%esi)
319 movl VCPU_vcpu_info(%ebx),%eax
320 pushl VCPUINFO_upcall_mask(%eax)
321 testb $TBF_INTERRUPT,%cl
322 setnz %ch # TBF_INTERRUPT -> set upcall mask
323 orb %ch,VCPUINFO_upcall_mask(%eax)
324 popl %eax
325 shll $16,%eax # Bits 16-23: saved_upcall_mask
326 movw UREGS_cs+4(%esp),%ax # Bits 0-15: CS
327 #ifdef CONFIG_X86_SUPERVISOR_MODE_KERNEL
328 testw $2,%ax
329 jnz .Lft15
330 and $~3,%ax # RPL 1 -> RPL 0
331 #endif
332 .Lft15: movl %eax,%gs:4(%esi)
333 test $0x00FF0000,%eax # Bits 16-23: saved_upcall_mask
334 setz %ch # %ch == !saved_upcall_mask
335 movl UREGS_eflags+4(%esp),%eax
336 andl $~X86_EFLAGS_IF,%eax
337 shlb $1,%ch # Bit 9 (EFLAGS.IF)
338 orb %ch,%ah # Fold EFLAGS.IF into %eax
339 .Lft16: movl %eax,%gs:8(%esi)
340 test $TBF_EXCEPTION_ERRCODE,%cl
341 jz 1f
342 subl $4,%esi # push error_code onto guest frame
343 movl TRAPBOUNCE_error_code(%edx),%eax
344 .Lft17: movl %eax,%gs:(%esi)
345 1: testb $TBF_FAILSAFE,%cl
346 jz 2f
347 subl $16,%esi # add DS/ES/FS/GS to failsafe stack frame
348 testl $X86_EFLAGS_VM,UREGS_eflags+4(%esp)
349 jz .Lnvm86_2
350 xorl %eax,%eax # VM86: we write zero selector values
351 .Lft18: movl %eax,%gs:(%esi)
352 .Lft19: movl %eax,%gs:4(%esi)
353 .Lft20: movl %eax,%gs:8(%esi)
354 .Lft21: movl %eax,%gs:12(%esi)
355 jmp 2f
356 .Lnvm86_2:
357 movl UREGS_ds+4(%esp),%eax # non-VM86: write real selector values
358 .Lft22: movl %eax,%gs:(%esi)
359 movl UREGS_es+4(%esp),%eax
360 .Lft23: movl %eax,%gs:4(%esi)
361 movl UREGS_fs+4(%esp),%eax
362 .Lft24: movl %eax,%gs:8(%esi)
363 movl UREGS_gs+4(%esp),%eax
364 .Lft25: movl %eax,%gs:12(%esi)
365 2: testl $X86_EFLAGS_VM,UREGS_eflags+4(%esp)
366 jz .Lnvm86_3
367 xorl %eax,%eax /* zero DS-GS, just as a real CPU would */
368 movl %eax,UREGS_ds+4(%esp)
369 movl %eax,UREGS_es+4(%esp)
370 movl %eax,UREGS_fs+4(%esp)
371 movl %eax,UREGS_gs+4(%esp)
372 .Lnvm86_3:
373 /* Rewrite our stack frame and return to ring 1. */
374 /* IA32 Ref. Vol. 3: TF, VM, RF and NT flags are cleared on trap. */
375 andl $~(X86_EFLAGS_VM|X86_EFLAGS_RF|\
376 X86_EFLAGS_NT|X86_EFLAGS_TF),UREGS_eflags+4(%esp)
377 mov %gs,UREGS_ss+4(%esp)
378 movl %esi,UREGS_esp+4(%esp)
379 movzwl TRAPBOUNCE_cs(%edx),%eax
380 /* Null selectors (0-3) are not allowed. */
381 testl $~3,%eax
382 jz domain_crash_synchronous
383 movl %eax,UREGS_cs+4(%esp)
384 movl TRAPBOUNCE_eip(%edx),%eax
385 movl %eax,UREGS_eip+4(%esp)
386 ret
387 .section __ex_table,"a"
388 .long .Lft6,domain_crash_synchronous , .Lft7,domain_crash_synchronous
389 .long .Lft8,domain_crash_synchronous , .Lft9,domain_crash_synchronous
390 .long .Lft10,domain_crash_synchronous , .Lft11,domain_crash_synchronous
391 .long .Lft12,domain_crash_synchronous , .Lft13,domain_crash_synchronous
392 .long .Lft14,domain_crash_synchronous , .Lft15,domain_crash_synchronous
393 .long .Lft16,domain_crash_synchronous , .Lft17,domain_crash_synchronous
394 .long .Lft18,domain_crash_synchronous , .Lft19,domain_crash_synchronous
395 .long .Lft20,domain_crash_synchronous , .Lft21,domain_crash_synchronous
396 .long .Lft22,domain_crash_synchronous , .Lft23,domain_crash_synchronous
397 .long .Lft24,domain_crash_synchronous , .Lft25,domain_crash_synchronous
398 .previous
400 domain_crash_synchronous_string:
401 .asciz "domain_crash_sync called from entry.S (%lx)\n"
403 domain_crash_synchronous:
404 pushl $domain_crash_synchronous_string
405 call printk
406 jmp __domain_crash_synchronous
408 ALIGN
409 ENTRY(ret_from_intr)
410 GET_CURRENT(%ebx)
411 movl UREGS_eflags(%esp),%eax
412 movb UREGS_cs(%esp),%al
413 testl $(3|X86_EFLAGS_VM),%eax
414 jnz test_all_events
415 jmp restore_all_xen
417 ENTRY(divide_error)
418 pushl $TRAP_divide_error<<16
419 ALIGN
420 handle_exception:
421 FIXUP_RING0_GUEST_STACK
422 SAVE_ALL(1f,2f)
423 .text 1
424 /* Exception within Xen: make sure we have valid %ds,%es. */
425 1: mov %ecx,%ds
426 mov %ecx,%es
427 jmp 2f
428 .previous
429 2: testb $X86_EFLAGS_IF>>8,UREGS_eflags+1(%esp)
430 jz exception_with_ints_disabled
431 sti # re-enable interrupts
432 1: xorl %eax,%eax
433 movw UREGS_entry_vector(%esp),%ax
434 movl %esp,%edx
435 pushl %edx # push the cpu_user_regs pointer
436 GET_CURRENT(%ebx)
437 PERFC_INCR(PERFC_exceptions, %eax, %ebx)
438 call *exception_table(,%eax,4)
439 addl $4,%esp
440 movl UREGS_eflags(%esp),%eax
441 movb UREGS_cs(%esp),%al
442 testl $(3|X86_EFLAGS_VM),%eax
443 jz restore_all_xen
444 leal VCPU_trap_bounce(%ebx),%edx
445 testb $TBF_EXCEPTION,TRAPBOUNCE_flags(%edx)
446 jz test_all_events
447 call create_bounce_frame
448 movb $0,TRAPBOUNCE_flags(%edx)
449 jmp test_all_events
451 exception_with_ints_disabled:
452 movl UREGS_eflags(%esp),%eax
453 movb UREGS_cs(%esp),%al
454 testl $(3|X86_EFLAGS_VM),%eax # interrupts disabled outside Xen?
455 jnz FATAL_exception_with_ints_disabled
456 pushl %esp
457 call search_pre_exception_table
458 addl $4,%esp
459 testl %eax,%eax # no fixup code for faulting EIP?
460 jz 1b
461 movl %eax,UREGS_eip(%esp)
462 movl %esp,%esi
463 subl $4,%esp
464 movl %esp,%edi
465 movl $UREGS_kernel_sizeof/4,%ecx
466 rep; movsl # make room for error_code/entry_vector
467 movl UREGS_error_code(%esp),%eax # error_code/entry_vector
468 movl %eax,UREGS_kernel_sizeof(%esp)
469 jmp restore_all_xen # return to fixup code
471 FATAL_exception_with_ints_disabled:
472 xorl %esi,%esi
473 movw UREGS_entry_vector(%esp),%si
474 movl %esp,%edx
475 pushl %edx # push the cpu_user_regs pointer
476 pushl %esi # push the trapnr (entry vector)
477 call fatal_trap
478 ud2
480 ENTRY(coprocessor_error)
481 pushl $TRAP_copro_error<<16
482 jmp handle_exception
484 ENTRY(simd_coprocessor_error)
485 pushl $TRAP_simd_error<<16
486 jmp handle_exception
488 ENTRY(device_not_available)
489 pushl $TRAP_no_device<<16
490 jmp handle_exception
492 ENTRY(debug)
493 pushl $TRAP_debug<<16
494 jmp handle_exception
496 ENTRY(int3)
497 pushl $TRAP_int3<<16
498 jmp handle_exception
500 ENTRY(overflow)
501 pushl $TRAP_overflow<<16
502 jmp handle_exception
504 ENTRY(bounds)
505 pushl $TRAP_bounds<<16
506 jmp handle_exception
508 ENTRY(invalid_op)
509 pushl $TRAP_invalid_op<<16
510 jmp handle_exception
512 ENTRY(coprocessor_segment_overrun)
513 pushl $TRAP_copro_seg<<16
514 jmp handle_exception
516 ENTRY(invalid_TSS)
517 movw $TRAP_invalid_tss,2(%esp)
518 jmp handle_exception
520 ENTRY(segment_not_present)
521 movw $TRAP_no_segment,2(%esp)
522 jmp handle_exception
524 ENTRY(stack_segment)
525 movw $TRAP_stack_error,2(%esp)
526 jmp handle_exception
528 ENTRY(general_protection)
529 movw $TRAP_gp_fault,2(%esp)
530 jmp handle_exception
532 ENTRY(alignment_check)
533 movw $TRAP_alignment_check,2(%esp)
534 jmp handle_exception
536 ENTRY(page_fault)
537 movw $TRAP_page_fault,2(%esp)
538 jmp handle_exception
540 ENTRY(spurious_interrupt_bug)
541 pushl $TRAP_spurious_int<<16
542 jmp handle_exception
544 ENTRY(early_page_fault)
545 SAVE_ALL(1f,1f)
546 1: movl %esp,%eax
547 pushl %eax
548 call do_early_page_fault
549 addl $4,%esp
550 jmp restore_all_xen
552 handle_nmi_mce:
553 #ifdef CONFIG_X86_SUPERVISOR_MODE_KERNEL
554 # NMI/MCE entry protocol is incompatible with guest kernel in ring 0.
555 addl $4,%esp
556 iret
557 #else
558 # Save state but do not trash the segment registers!
559 SAVE_ALL(.Lnmi_mce_xen,.Lnmi_mce_common)
560 .Lnmi_mce_common:
561 xorl %eax,%eax
562 movw UREGS_entry_vector(%esp),%ax
563 movl %esp,%edx
564 pushl %edx
565 call *exception_table(,%eax,4)
566 addl $4,%esp
567 /*
568 * NB. We may return to Xen context with polluted %ds/%es. But in such
569 * cases we have put guest DS/ES on the guest stack frame, which will
570 * be detected by SAVE_ALL(), or we have rolled back restore_guest.
571 */
572 jmp ret_from_intr
573 .Lnmi_mce_xen:
574 /* Check the outer (guest) context for %ds/%es state validity. */
575 GET_GUEST_REGS(%ebx)
576 testl $X86_EFLAGS_VM,%ss:UREGS_eflags(%ebx)
577 mov %ds,%eax
578 mov %es,%edx
579 jnz .Lnmi_mce_vm86
580 /* We may have interrupted Xen while messing with %ds/%es... */
581 cmpw %ax,%cx
582 mov %ecx,%ds /* Ensure %ds is valid */
583 cmove UREGS_ds(%ebx),%eax /* Grab guest DS if it wasn't in %ds */
584 cmpw %dx,%cx
585 movl %eax,UREGS_ds(%ebx) /* Ensure guest frame contains guest DS */
586 cmove UREGS_es(%ebx),%edx /* Grab guest ES if it wasn't in %es */
587 mov %ecx,%es /* Ensure %es is valid */
588 movl $.Lrestore_sregs_guest,%ecx
589 movl %edx,UREGS_es(%ebx) /* Ensure guest frame contains guest ES */
590 cmpl %ecx,UREGS_eip(%esp)
591 jbe .Lnmi_mce_common
592 cmpl $.Lrestore_iret_guest,UREGS_eip(%esp)
593 ja .Lnmi_mce_common
594 /* Roll outer context restore_guest back to restoring %ds/%es. */
595 movl %ecx,UREGS_eip(%esp)
596 jmp .Lnmi_mce_common
597 .Lnmi_mce_vm86:
598 /* vm86 is easy: the CPU saved %ds/%es so we can safely stomp them. */
599 mov %ecx,%ds
600 mov %ecx,%es
601 jmp .Lnmi_mce_common
602 #endif /* !CONFIG_X86_SUPERVISOR_MODE_KERNEL */
604 ENTRY(nmi)
605 pushl $TRAP_nmi<<16
606 jmp handle_nmi_mce
608 ENTRY(machine_check)
609 pushl $TRAP_machine_check<<16
610 jmp handle_nmi_mce
612 ENTRY(setup_vm86_frame)
613 mov %ecx,%ds
614 mov %ecx,%es
615 # Copies the entire stack frame forwards by 16 bytes.
616 .macro copy_vm86_words count=18
617 .if \count
618 pushl ((\count-1)*4)(%esp)
619 popl ((\count-1)*4)+16(%esp)
620 copy_vm86_words "(\count-1)"
621 .endif
622 .endm
623 copy_vm86_words
624 addl $16,%esp
625 ret
627 .data
629 ENTRY(exception_table)
630 .long do_divide_error
631 .long do_debug
632 .long do_nmi
633 .long do_int3
634 .long do_overflow
635 .long do_bounds
636 .long do_invalid_op
637 .long do_device_not_available
638 .long 0 # double fault
639 .long do_coprocessor_segment_overrun
640 .long do_invalid_TSS
641 .long do_segment_not_present
642 .long do_stack_segment
643 .long do_general_protection
644 .long do_page_fault
645 .long do_spurious_interrupt_bug
646 .long do_coprocessor_error
647 .long do_alignment_check
648 .long do_machine_check
649 .long do_simd_coprocessor_error
651 ENTRY(hypercall_table)
652 .long do_set_trap_table /* 0 */
653 .long do_mmu_update
654 .long do_set_gdt
655 .long do_stack_switch
656 .long do_set_callbacks
657 .long do_fpu_taskswitch /* 5 */
658 .long do_sched_op_compat
659 .long do_platform_op
660 .long do_set_debugreg
661 .long do_get_debugreg
662 .long do_update_descriptor /* 10 */
663 .long do_ni_hypercall
664 .long do_memory_op
665 .long do_multicall
666 .long do_update_va_mapping
667 .long do_set_timer_op /* 15 */
668 .long do_event_channel_op_compat
669 .long do_xen_version
670 .long do_console_io
671 .long do_physdev_op_compat
672 .long do_grant_table_op /* 20 */
673 .long do_vm_assist
674 .long do_update_va_mapping_otherdomain
675 .long do_iret
676 .long do_vcpu_op
677 .long do_ni_hypercall /* 25 */
678 .long do_mmuext_op
679 .long do_xsm_op
680 .long do_nmi_op
681 .long do_sched_op
682 .long do_callback_op /* 30 */
683 .long do_xenoprof_op
684 .long do_event_channel_op
685 .long do_physdev_op
686 .long do_hvm_op
687 .long do_sysctl /* 35 */
688 .long do_domctl
689 .long do_kexec_op
690 .rept NR_hypercalls-((.-hypercall_table)/4)
691 .long do_ni_hypercall
692 .endr
694 ENTRY(hypercall_args_table)
695 .byte 1 /* do_set_trap_table */ /* 0 */
696 .byte 4 /* do_mmu_update */
697 .byte 2 /* do_set_gdt */
698 .byte 2 /* do_stack_switch */
699 .byte 4 /* do_set_callbacks */
700 .byte 1 /* do_fpu_taskswitch */ /* 5 */
701 .byte 2 /* do_sched_op_compat */
702 .byte 1 /* do_platform_op */
703 .byte 2 /* do_set_debugreg */
704 .byte 1 /* do_get_debugreg */
705 .byte 4 /* do_update_descriptor */ /* 10 */
706 .byte 0 /* do_ni_hypercall */
707 .byte 2 /* do_memory_op */
708 .byte 2 /* do_multicall */
709 .byte 4 /* do_update_va_mapping */
710 .byte 2 /* do_set_timer_op */ /* 15 */
711 .byte 1 /* do_event_channel_op_compat */
712 .byte 2 /* do_xen_version */
713 .byte 3 /* do_console_io */
714 .byte 1 /* do_physdev_op_compat */
715 .byte 3 /* do_grant_table_op */ /* 20 */
716 .byte 2 /* do_vm_assist */
717 .byte 5 /* do_update_va_mapping_otherdomain */
718 .byte 0 /* do_iret */
719 .byte 3 /* do_vcpu_op */
720 .byte 0 /* do_ni_hypercall */ /* 25 */
721 .byte 4 /* do_mmuext_op */
722 .byte 1 /* do_xsm_op */
723 .byte 2 /* do_nmi_op */
724 .byte 2 /* do_sched_op */
725 .byte 2 /* do_callback_op */ /* 30 */
726 .byte 2 /* do_xenoprof_op */
727 .byte 2 /* do_event_channel_op */
728 .byte 2 /* do_physdev_op */
729 .byte 2 /* do_hvm_op */
730 .byte 1 /* do_sysctl */ /* 35 */
731 .byte 1 /* do_domctl */
732 .byte 2 /* do_kexec_op */
733 .rept NR_hypercalls-(.-hypercall_args_table)
734 .byte 0 /* do_ni_hypercall */
735 .endr