direct-io.hg

view xen/arch/x86/x86_32/entry.S @ 15417:015d9abeacfb

i386: Simplify failsafe callback handling.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Thu Jun 21 21:36:26 2007 +0100 (2007-06-21)
parents 3cf5052ba5e5
children
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 #else
185 /*
186 * We need shadow parameters even on non-debug builds. We depend on the
187 * original versions not being clobbered (needed to create a hypercall
188 * continuation). But that isn't guaranteed by the function-call ABI.
189 */
190 pushl 20(%esp) # EBP
191 pushl 20(%esp) # EDI
192 pushl 20(%esp) # ESI
193 pushl 20(%esp) # EDX
194 pushl 20(%esp) # ECX
195 pushl 20(%esp) # EBX
196 #endif
197 call *hypercall_table(,%eax,4)
198 addl $24,%esp # Discard the shadow parameters
199 #ifndef NDEBUG
200 /* Deliberately corrupt real parameter regs used by this hypercall. */
201 popl %ecx # Shadow EIP
202 cmpl %ecx,UREGS_eip+4(%esp)
203 popl %ecx # Shadow hypercall index
204 jne skip_clobber # If EIP has changed then don't clobber
205 movzb hypercall_args_table(,%ecx,1),%ecx
206 movl %esp,%edi
207 movl %eax,%esi
208 movl $0xDEADBEEF,%eax
209 rep stosl
210 movl %esi,%eax
211 skip_clobber:
212 #endif
213 movl %eax,UREGS_eax(%esp) # save the return value
215 test_all_events:
216 xorl %ecx,%ecx
217 notl %ecx
218 cli # tests must not race interrupts
219 /*test_softirqs:*/
220 movl VCPU_processor(%ebx),%eax
221 shl $IRQSTAT_shift,%eax
222 test %ecx,irq_stat(%eax,1)
223 jnz process_softirqs
224 testb $1,VCPU_nmi_pending(%ebx)
225 jnz process_nmi
226 test_guest_events:
227 movl VCPU_vcpu_info(%ebx),%eax
228 testb $0xFF,VCPUINFO_upcall_mask(%eax)
229 jnz restore_all_guest
230 testb $0xFF,VCPUINFO_upcall_pending(%eax)
231 jz restore_all_guest
232 /*process_guest_events:*/
233 sti
234 leal VCPU_trap_bounce(%ebx),%edx
235 movl VCPU_event_addr(%ebx),%eax
236 movl %eax,TRAPBOUNCE_eip(%edx)
237 movl VCPU_event_sel(%ebx),%eax
238 movw %ax,TRAPBOUNCE_cs(%edx)
239 movb $TBF_INTERRUPT,TRAPBOUNCE_flags(%edx)
240 call create_bounce_frame
241 jmp test_all_events
243 ALIGN
244 process_softirqs:
245 sti
246 call do_softirq
247 jmp test_all_events
249 ALIGN
250 process_nmi:
251 testb $1,VCPU_nmi_masked(%ebx)
252 jnz test_guest_events
253 movb $0,VCPU_nmi_pending(%ebx)
254 movl VCPU_nmi_addr(%ebx),%eax
255 test %eax,%eax
256 jz test_guest_events
257 movb $1,VCPU_nmi_masked(%ebx)
258 sti
259 leal VCPU_trap_bounce(%ebx),%edx
260 movl %eax,TRAPBOUNCE_eip(%edx)
261 movw $FLAT_KERNEL_CS,TRAPBOUNCE_cs(%edx)
262 movb $TBF_INTERRUPT,TRAPBOUNCE_flags(%edx)
263 call create_bounce_frame
264 jmp test_all_events
266 bad_hypercall:
267 movl $-ENOSYS,UREGS_eax(%esp)
268 jmp test_all_events
270 /* CREATE A BASIC EXCEPTION FRAME ON GUEST OS (RING-1) STACK: */
271 /* {EIP, CS, EFLAGS, [ESP, SS]} */
272 /* %edx == trap_bounce, %ebx == struct vcpu */
273 /* %eax,%ecx are clobbered. %gs:%esi contain new UREGS_ss/UREGS_esp. */
274 create_bounce_frame:
275 ASSERT_INTERRUPTS_ENABLED
276 movl UREGS_eflags+4(%esp),%ecx
277 movb UREGS_cs+4(%esp),%cl
278 testl $(2|X86_EFLAGS_VM),%ecx
279 jz ring1 /* jump if returning to an existing ring-1 activation */
280 movl VCPU_kernel_sp(%ebx),%esi
281 .Lft6: mov VCPU_kernel_ss(%ebx),%gs
282 testl $X86_EFLAGS_VM,UREGS_eflags+4(%esp)
283 jz .Lnvm86_1
284 subl $16,%esi /* push ES/DS/FS/GS (VM86 stack frame) */
285 movl UREGS_es+4(%esp),%eax
286 .Lft7: movl %eax,%gs:(%esi)
287 movl UREGS_ds+4(%esp),%eax
288 .Lft8: movl %eax,%gs:4(%esi)
289 movl UREGS_fs+4(%esp),%eax
290 .Lft9: movl %eax,%gs:8(%esi)
291 movl UREGS_gs+4(%esp),%eax
292 .Lft10: movl %eax,%gs:12(%esi)
293 .Lnvm86_1:
294 subl $8,%esi /* push SS/ESP (inter-priv iret) */
295 movl UREGS_esp+4(%esp),%eax
296 .Lft11: movl %eax,%gs:(%esi)
297 movl UREGS_ss+4(%esp),%eax
298 .Lft12: movl %eax,%gs:4(%esi)
299 jmp 1f
300 ring1: /* obtain ss/esp from oldss/oldesp -- a ring-1 activation exists */
301 movl UREGS_esp+4(%esp),%esi
302 .Lft13: mov UREGS_ss+4(%esp),%gs
303 1: /* Construct a stack frame: EFLAGS, CS/EIP */
304 movb TRAPBOUNCE_flags(%edx),%cl
305 subl $12,%esi
306 movl UREGS_eip+4(%esp),%eax
307 .Lft14: movl %eax,%gs:(%esi)
308 movl VCPU_vcpu_info(%ebx),%eax
309 pushl VCPUINFO_upcall_mask(%eax)
310 testb $TBF_INTERRUPT,%cl
311 setnz %ch # TBF_INTERRUPT -> set upcall mask
312 orb %ch,VCPUINFO_upcall_mask(%eax)
313 popl %eax
314 shll $16,%eax # Bits 16-23: saved_upcall_mask
315 movw UREGS_cs+4(%esp),%ax # Bits 0-15: CS
316 #ifdef CONFIG_X86_SUPERVISOR_MODE_KERNEL
317 testw $2,%ax
318 jnz .Lft15
319 and $~3,%ax # RPL 1 -> RPL 0
320 #endif
321 .Lft15: movl %eax,%gs:4(%esi)
322 test $0x00FF0000,%eax # Bits 16-23: saved_upcall_mask
323 setz %ch # %ch == !saved_upcall_mask
324 movl UREGS_eflags+4(%esp),%eax
325 andl $~X86_EFLAGS_IF,%eax
326 shlb $1,%ch # Bit 9 (EFLAGS.IF)
327 orb %ch,%ah # Fold EFLAGS.IF into %eax
328 .Lft16: movl %eax,%gs:8(%esi)
329 test $TBF_EXCEPTION_ERRCODE,%cl
330 jz 1f
331 subl $4,%esi # push error_code onto guest frame
332 movl TRAPBOUNCE_error_code(%edx),%eax
333 .Lft17: movl %eax,%gs:(%esi)
334 1: testb $TBF_FAILSAFE,%cl
335 jz 2f
336 subl $16,%esi # add DS/ES/FS/GS to failsafe stack frame
337 testl $X86_EFLAGS_VM,UREGS_eflags+4(%esp)
338 jz .Lnvm86_2
339 xorl %eax,%eax # VM86: we write zero selector values
340 .Lft18: movl %eax,%gs:(%esi)
341 .Lft19: movl %eax,%gs:4(%esi)
342 .Lft20: movl %eax,%gs:8(%esi)
343 .Lft21: movl %eax,%gs:12(%esi)
344 jmp 2f
345 .Lnvm86_2:
346 movl UREGS_ds+4(%esp),%eax # non-VM86: write real selector values
347 .Lft22: movl %eax,%gs:(%esi)
348 movl UREGS_es+4(%esp),%eax
349 .Lft23: movl %eax,%gs:4(%esi)
350 movl UREGS_fs+4(%esp),%eax
351 .Lft24: movl %eax,%gs:8(%esi)
352 movl UREGS_gs+4(%esp),%eax
353 .Lft25: movl %eax,%gs:12(%esi)
354 2: testl $X86_EFLAGS_VM,UREGS_eflags+4(%esp)
355 jz .Lnvm86_3
356 xorl %eax,%eax /* zero DS-GS, just as a real CPU would */
357 movl %eax,UREGS_ds+4(%esp)
358 movl %eax,UREGS_es+4(%esp)
359 movl %eax,UREGS_fs+4(%esp)
360 movl %eax,UREGS_gs+4(%esp)
361 .Lnvm86_3:
362 /* Rewrite our stack frame and return to ring 1. */
363 /* IA32 Ref. Vol. 3: TF, VM, RF and NT flags are cleared on trap. */
364 andl $~(X86_EFLAGS_VM|X86_EFLAGS_RF|\
365 X86_EFLAGS_NT|X86_EFLAGS_TF),UREGS_eflags+4(%esp)
366 mov %gs,UREGS_ss+4(%esp)
367 movl %esi,UREGS_esp+4(%esp)
368 movzwl TRAPBOUNCE_cs(%edx),%eax
369 /* Null selectors (0-3) are not allowed. */
370 testl $~3,%eax
371 jz domain_crash_synchronous
372 movl %eax,UREGS_cs+4(%esp)
373 movl TRAPBOUNCE_eip(%edx),%eax
374 movl %eax,UREGS_eip+4(%esp)
375 ret
376 .section __ex_table,"a"
377 .long .Lft6,domain_crash_synchronous , .Lft7,domain_crash_synchronous
378 .long .Lft8,domain_crash_synchronous , .Lft9,domain_crash_synchronous
379 .long .Lft10,domain_crash_synchronous , .Lft11,domain_crash_synchronous
380 .long .Lft12,domain_crash_synchronous , .Lft13,domain_crash_synchronous
381 .long .Lft14,domain_crash_synchronous , .Lft15,domain_crash_synchronous
382 .long .Lft16,domain_crash_synchronous , .Lft17,domain_crash_synchronous
383 .long .Lft18,domain_crash_synchronous , .Lft19,domain_crash_synchronous
384 .long .Lft20,domain_crash_synchronous , .Lft21,domain_crash_synchronous
385 .long .Lft22,domain_crash_synchronous , .Lft23,domain_crash_synchronous
386 .long .Lft24,domain_crash_synchronous , .Lft25,domain_crash_synchronous
387 .previous
389 domain_crash_synchronous_string:
390 .asciz "domain_crash_sync called from entry.S (%lx)\n"
392 domain_crash_synchronous:
393 pushl $domain_crash_synchronous_string
394 call printk
395 jmp __domain_crash_synchronous
397 ALIGN
398 ENTRY(ret_from_intr)
399 GET_CURRENT(%ebx)
400 movl UREGS_eflags(%esp),%eax
401 movb UREGS_cs(%esp),%al
402 testl $(3|X86_EFLAGS_VM),%eax
403 jnz test_all_events
404 jmp restore_all_xen
406 ENTRY(divide_error)
407 pushl $TRAP_divide_error<<16
408 ALIGN
409 handle_exception:
410 FIXUP_RING0_GUEST_STACK
411 SAVE_ALL(1f,2f)
412 .text 1
413 /* Exception within Xen: make sure we have valid %ds,%es. */
414 1: mov %ecx,%ds
415 mov %ecx,%es
416 jmp 2f
417 .previous
418 2: testb $X86_EFLAGS_IF>>8,UREGS_eflags+1(%esp)
419 jz exception_with_ints_disabled
420 sti # re-enable interrupts
421 1: xorl %eax,%eax
422 movw UREGS_entry_vector(%esp),%ax
423 movl %esp,%edx
424 pushl %edx # push the cpu_user_regs pointer
425 GET_CURRENT(%ebx)
426 PERFC_INCR(PERFC_exceptions, %eax, %ebx)
427 call *exception_table(,%eax,4)
428 addl $4,%esp
429 movl UREGS_eflags(%esp),%eax
430 movb UREGS_cs(%esp),%al
431 testl $(3|X86_EFLAGS_VM),%eax
432 jz restore_all_xen
433 leal VCPU_trap_bounce(%ebx),%edx
434 testb $TBF_EXCEPTION,TRAPBOUNCE_flags(%edx)
435 jz test_all_events
436 call create_bounce_frame
437 movb $0,TRAPBOUNCE_flags(%edx)
438 jmp test_all_events
440 exception_with_ints_disabled:
441 movl UREGS_eflags(%esp),%eax
442 movb UREGS_cs(%esp),%al
443 testl $(3|X86_EFLAGS_VM),%eax # interrupts disabled outside Xen?
444 jnz FATAL_exception_with_ints_disabled
445 pushl %esp
446 call search_pre_exception_table
447 addl $4,%esp
448 testl %eax,%eax # no fixup code for faulting EIP?
449 jz 1b
450 movl %eax,UREGS_eip(%esp)
451 movl %esp,%esi
452 subl $4,%esp
453 movl %esp,%edi
454 movl $UREGS_kernel_sizeof/4,%ecx
455 rep; movsl # make room for error_code/entry_vector
456 movl UREGS_error_code(%esp),%eax # error_code/entry_vector
457 movl %eax,UREGS_kernel_sizeof(%esp)
458 jmp restore_all_xen # return to fixup code
460 FATAL_exception_with_ints_disabled:
461 xorl %esi,%esi
462 movw UREGS_entry_vector(%esp),%si
463 movl %esp,%edx
464 pushl %edx # push the cpu_user_regs pointer
465 pushl %esi # push the trapnr (entry vector)
466 call fatal_trap
467 ud2
469 ENTRY(coprocessor_error)
470 pushl $TRAP_copro_error<<16
471 jmp handle_exception
473 ENTRY(simd_coprocessor_error)
474 pushl $TRAP_simd_error<<16
475 jmp handle_exception
477 ENTRY(device_not_available)
478 pushl $TRAP_no_device<<16
479 jmp handle_exception
481 ENTRY(debug)
482 pushl $TRAP_debug<<16
483 jmp handle_exception
485 ENTRY(int3)
486 pushl $TRAP_int3<<16
487 jmp handle_exception
489 ENTRY(overflow)
490 pushl $TRAP_overflow<<16
491 jmp handle_exception
493 ENTRY(bounds)
494 pushl $TRAP_bounds<<16
495 jmp handle_exception
497 ENTRY(invalid_op)
498 pushl $TRAP_invalid_op<<16
499 jmp handle_exception
501 ENTRY(coprocessor_segment_overrun)
502 pushl $TRAP_copro_seg<<16
503 jmp handle_exception
505 ENTRY(invalid_TSS)
506 movw $TRAP_invalid_tss,2(%esp)
507 jmp handle_exception
509 ENTRY(segment_not_present)
510 movw $TRAP_no_segment,2(%esp)
511 jmp handle_exception
513 ENTRY(stack_segment)
514 movw $TRAP_stack_error,2(%esp)
515 jmp handle_exception
517 ENTRY(general_protection)
518 movw $TRAP_gp_fault,2(%esp)
519 jmp handle_exception
521 ENTRY(alignment_check)
522 movw $TRAP_alignment_check,2(%esp)
523 jmp handle_exception
525 ENTRY(page_fault)
526 movw $TRAP_page_fault,2(%esp)
527 jmp handle_exception
529 ENTRY(spurious_interrupt_bug)
530 pushl $TRAP_spurious_int<<16
531 jmp handle_exception
533 ENTRY(early_page_fault)
534 SAVE_ALL(1f,1f)
535 1: movl %esp,%eax
536 pushl %eax
537 call do_early_page_fault
538 addl $4,%esp
539 jmp restore_all_xen
541 handle_nmi_mce:
542 #ifdef CONFIG_X86_SUPERVISOR_MODE_KERNEL
543 # NMI/MCE entry protocol is incompatible with guest kernel in ring 0.
544 addl $4,%esp
545 iret
546 #else
547 # Save state but do not trash the segment registers!
548 SAVE_ALL(.Lnmi_mce_xen,.Lnmi_mce_common)
549 .Lnmi_mce_common:
550 xorl %eax,%eax
551 movw UREGS_entry_vector(%esp),%ax
552 movl %esp,%edx
553 pushl %edx
554 call *exception_table(,%eax,4)
555 addl $4,%esp
556 /*
557 * NB. We may return to Xen context with polluted %ds/%es. But in such
558 * cases we have put guest DS/ES on the guest stack frame, which will
559 * be detected by SAVE_ALL(), or we have rolled back restore_guest.
560 */
561 jmp ret_from_intr
562 .Lnmi_mce_xen:
563 /* Check the outer (guest) context for %ds/%es state validity. */
564 GET_GUEST_REGS(%ebx)
565 testl $X86_EFLAGS_VM,%ss:UREGS_eflags(%ebx)
566 mov %ds,%eax
567 mov %es,%edx
568 jnz .Lnmi_mce_vm86
569 /* We may have interrupted Xen while messing with %ds/%es... */
570 cmpw %ax,%cx
571 mov %ecx,%ds /* Ensure %ds is valid */
572 cmove UREGS_ds(%ebx),%eax /* Grab guest DS if it wasn't in %ds */
573 cmpw %dx,%cx
574 movl %eax,UREGS_ds(%ebx) /* Ensure guest frame contains guest DS */
575 cmove UREGS_es(%ebx),%edx /* Grab guest ES if it wasn't in %es */
576 mov %ecx,%es /* Ensure %es is valid */
577 movl $.Lrestore_sregs_guest,%ecx
578 movl %edx,UREGS_es(%ebx) /* Ensure guest frame contains guest ES */
579 cmpl %ecx,UREGS_eip(%esp)
580 jbe .Lnmi_mce_common
581 cmpl $.Lrestore_iret_guest,UREGS_eip(%esp)
582 ja .Lnmi_mce_common
583 /* Roll outer context restore_guest back to restoring %ds/%es. */
584 movl %ecx,UREGS_eip(%esp)
585 jmp .Lnmi_mce_common
586 .Lnmi_mce_vm86:
587 /* vm86 is easy: the CPU saved %ds/%es so we can safely stomp them. */
588 mov %ecx,%ds
589 mov %ecx,%es
590 jmp .Lnmi_mce_common
591 #endif /* !CONFIG_X86_SUPERVISOR_MODE_KERNEL */
593 ENTRY(nmi)
594 pushl $TRAP_nmi<<16
595 jmp handle_nmi_mce
597 ENTRY(machine_check)
598 pushl $TRAP_machine_check<<16
599 jmp handle_nmi_mce
601 ENTRY(setup_vm86_frame)
602 mov %ecx,%ds
603 mov %ecx,%es
604 # Copies the entire stack frame forwards by 16 bytes.
605 .macro copy_vm86_words count=18
606 .if \count
607 pushl ((\count-1)*4)(%esp)
608 popl ((\count-1)*4)+16(%esp)
609 copy_vm86_words "(\count-1)"
610 .endif
611 .endm
612 copy_vm86_words
613 addl $16,%esp
614 ret
616 .data
618 ENTRY(exception_table)
619 .long do_divide_error
620 .long do_debug
621 .long do_nmi
622 .long do_int3
623 .long do_overflow
624 .long do_bounds
625 .long do_invalid_op
626 .long math_state_restore
627 .long 0 # double fault
628 .long do_coprocessor_segment_overrun
629 .long do_invalid_TSS
630 .long do_segment_not_present
631 .long do_stack_segment
632 .long do_general_protection
633 .long do_page_fault
634 .long do_spurious_interrupt_bug
635 .long do_coprocessor_error
636 .long do_alignment_check
637 .long do_machine_check
638 .long do_simd_coprocessor_error
640 ENTRY(hypercall_table)
641 .long do_set_trap_table /* 0 */
642 .long do_mmu_update
643 .long do_set_gdt
644 .long do_stack_switch
645 .long do_set_callbacks
646 .long do_fpu_taskswitch /* 5 */
647 .long do_sched_op_compat
648 .long do_platform_op
649 .long do_set_debugreg
650 .long do_get_debugreg
651 .long do_update_descriptor /* 10 */
652 .long do_ni_hypercall
653 .long do_memory_op
654 .long do_multicall
655 .long do_update_va_mapping
656 .long do_set_timer_op /* 15 */
657 .long do_event_channel_op_compat
658 .long do_xen_version
659 .long do_console_io
660 .long do_physdev_op_compat
661 .long do_grant_table_op /* 20 */
662 .long do_vm_assist
663 .long do_update_va_mapping_otherdomain
664 .long do_iret
665 .long do_vcpu_op
666 .long do_ni_hypercall /* 25 */
667 .long do_mmuext_op
668 .long do_acm_op
669 .long do_nmi_op
670 .long do_sched_op
671 .long do_callback_op /* 30 */
672 .long do_xenoprof_op
673 .long do_event_channel_op
674 .long do_physdev_op
675 .long do_hvm_op
676 .long do_sysctl /* 35 */
677 .long do_domctl
678 .long do_kexec_op
679 .rept NR_hypercalls-((.-hypercall_table)/4)
680 .long do_ni_hypercall
681 .endr
683 ENTRY(hypercall_args_table)
684 .byte 1 /* do_set_trap_table */ /* 0 */
685 .byte 4 /* do_mmu_update */
686 .byte 2 /* do_set_gdt */
687 .byte 2 /* do_stack_switch */
688 .byte 4 /* do_set_callbacks */
689 .byte 1 /* do_fpu_taskswitch */ /* 5 */
690 .byte 2 /* do_sched_op_compat */
691 .byte 1 /* do_platform_op */
692 .byte 2 /* do_set_debugreg */
693 .byte 1 /* do_get_debugreg */
694 .byte 4 /* do_update_descriptor */ /* 10 */
695 .byte 0 /* do_ni_hypercall */
696 .byte 2 /* do_memory_op */
697 .byte 2 /* do_multicall */
698 .byte 4 /* do_update_va_mapping */
699 .byte 2 /* do_set_timer_op */ /* 15 */
700 .byte 1 /* do_event_channel_op_compat */
701 .byte 2 /* do_xen_version */
702 .byte 3 /* do_console_io */
703 .byte 1 /* do_physdev_op_compat */
704 .byte 3 /* do_grant_table_op */ /* 20 */
705 .byte 2 /* do_vm_assist */
706 .byte 5 /* do_update_va_mapping_otherdomain */
707 .byte 0 /* do_iret */
708 .byte 3 /* do_vcpu_op */
709 .byte 0 /* do_ni_hypercall */ /* 25 */
710 .byte 4 /* do_mmuext_op */
711 .byte 1 /* do_acm_op */
712 .byte 2 /* do_nmi_op */
713 .byte 2 /* do_sched_op */
714 .byte 2 /* do_callback_op */ /* 30 */
715 .byte 2 /* do_xenoprof_op */
716 .byte 2 /* do_event_channel_op */
717 .byte 2 /* do_physdev_op */
718 .byte 2 /* do_hvm_op */
719 .byte 1 /* do_sysctl */ /* 35 */
720 .byte 1 /* do_domctl */
721 .byte 2 /* do_kexec_op */
722 .rept NR_hypercalls-(.-hypercall_args_table)
723 .byte 0 /* do_ni_hypercall */
724 .endr