ia64/xen-unstable

view xen/arch/x86/x86_32/entry.S @ 16185:42d8dadb5864

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