ia64/xen-unstable

view xen/arch/x86/hvm/vmx/x86_32/exits.S @ 16468:9f61a0add5b6

x86_emulate: Emulate CPUID and HLT.
vmx realmode: Fix decode & emulate loop, add hooks for CPUID, HLT and
WBINVD. Also do not hook realmode entry off of vmentry failure any
more.
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Nov 26 15:32:54 2007 +0000 (2007-11-26)
parents ec3b23d8d544
children 2324110ef2c6
line source
1 /*
2 * exits.S: VMX architecture-specific exit handling.
3 * Copyright (c) 2004, Intel Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16 * Place - Suite 330, Boston, MA 02111-1307 USA.
17 */
18 #include <xen/config.h>
19 #include <xen/errno.h>
20 #include <xen/softirq.h>
21 #include <asm/asm_defns.h>
22 #include <asm/apicdef.h>
23 #include <asm/page.h>
24 #include <public/xen.h>
26 #define VMRESUME .byte 0x0f,0x01,0xc3
27 #define VMLAUNCH .byte 0x0f,0x01,0xc2
28 #define VMREAD(off) .byte 0x0f,0x78,0x44,0x24,off
29 #define VMWRITE(off) .byte 0x0f,0x79,0x44,0x24,off
31 /* VMCS field encodings */
32 #define GUEST_RSP 0x681c
33 #define GUEST_RIP 0x681e
34 #define GUEST_RFLAGS 0x6820
36 #define GET_CURRENT(reg) \
37 movl $STACK_SIZE-4, reg; \
38 orl %esp, reg; \
39 andl $~3,reg; \
40 movl (reg),reg;
42 #define HVM_SAVE_ALL_NOSEGREGS \
43 movl $0, 0xc(%esp); /* XXX why do we need to force eflags==0 ?? */ \
44 pushl %eax; \
45 pushl %ebp; \
46 pushl %edi; \
47 pushl %esi; \
48 pushl %edx; \
49 pushl %ecx; \
50 pushl %ebx;
52 #define HVM_RESTORE_ALL_NOSEGREGS \
53 popl %ebx; \
54 popl %ecx; \
55 popl %edx; \
56 popl %esi; \
57 popl %edi; \
58 popl %ebp; \
59 popl %eax
61 ALIGN
62 ENTRY(vmx_asm_vmexit_handler)
63 HVM_SAVE_ALL_NOSEGREGS
65 movl $GUEST_RIP,%eax
66 VMREAD(UREGS_eip)
67 movl $GUEST_RSP,%eax
68 VMREAD(UREGS_esp)
69 movl $GUEST_RFLAGS,%eax
70 VMREAD(UREGS_eflags)
72 movl %esp,%eax
73 push %eax
74 call vmx_vmexit_handler
75 addl $4,%esp
76 jmp vmx_asm_do_vmentry
78 ALIGN
79 vmx_process_softirqs:
80 sti
81 call do_softirq
82 jmp vmx_asm_do_vmentry
84 ALIGN
85 ENTRY(vmx_asm_do_vmentry)
86 GET_CURRENT(%ebx)
87 cli # tests must not race interrupts
89 movl VCPU_processor(%ebx),%eax
90 shl $IRQSTAT_shift,%eax
91 cmpl $0,irq_stat(%eax,1)
92 jnz vmx_process_softirqs
94 call vmx_intr_assist
95 movl VCPU_hvm_guest_cr2(%ebx),%eax
96 movl %eax,%cr2
97 call vmx_trace_vmentry
99 movl $GUEST_RIP,%eax
100 VMWRITE(UREGS_eip)
101 movl $GUEST_RSP,%eax
102 VMWRITE(UREGS_esp)
103 movl $GUEST_RFLAGS,%eax
104 VMWRITE(UREGS_eflags)
106 #ifndef VMXASSIST
107 testb $X86_CR0_PE,VCPU_hvm_guest_cr0(%ebx)
108 jz vmx_goto_realmode
109 #endif
111 cmpb $0,VCPU_vmx_launched(%ebx)
112 je vmx_launch
114 /*vmx_resume:*/
115 HVM_RESTORE_ALL_NOSEGREGS
116 VMRESUME
117 pushf
118 call vm_resume_fail
119 ud2
121 vmx_launch:
122 movb $1,VCPU_vmx_launched(%ebx)
123 HVM_RESTORE_ALL_NOSEGREGS
124 VMLAUNCH
125 pushf
126 call vm_launch_fail
127 ud2
129 #ifndef VMXASSIST
130 vmx_goto_realmode:
131 sti
132 movl %esp,%eax
133 push %eax
134 call vmx_realmode
135 addl $4,%esp
136 jmp vmx_asm_do_vmentry
137 #endif