ia64/xen-unstable

view xen/include/asm-x86/x86_emulate.h @ 15812:86a154e1ef5d

[HVM] Shadow: don't shadow the p2m table.
For HVM vcpus with paging disabled, we used to shadow the p2m table,
and skip the p2m lookup to go from gfn to mfn. Instead, we now
provide a simple pagetable that gives a one-to-one mapping of 4GB, and
shadow that, making the translations from gfn to mfn via the p2m.
This removes the paging-disabled special-case code from the shadow
fault handler, and allows us to expand the p2m interface, since all HVM
translations now go through the same p2m lookups.
Signed-off-by: Tim Deegan <Tim.Deegan@xensource.com>
author Tim Deegan <Tim.Deegan@xensource.com>
date Fri Aug 31 11:06:22 2007 +0100 (2007-08-31)
parents b010e556fe2c
children d5c396128897
line source
1 /******************************************************************************
2 * x86_emulate.h
3 *
4 * Generic x86 (32-bit and 64-bit) instruction decoder and emulator.
5 *
6 * Copyright (c) 2005-2007 Keir Fraser
7 * Copyright (c) 2005-2007 XenSource Inc.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
24 #ifndef __X86_EMULATE_H__
25 #define __X86_EMULATE_H__
27 struct x86_emulate_ctxt;
29 /*
30 * Comprehensive enumeration of x86 segment registers. Note that the system
31 * registers (TR, LDTR, GDTR, IDTR) are never referenced by the emulator.
32 */
33 enum x86_segment {
34 /* General purpose. */
35 x86_seg_cs,
36 x86_seg_ss,
37 x86_seg_ds,
38 x86_seg_es,
39 x86_seg_fs,
40 x86_seg_gs,
41 /* System. */
42 x86_seg_tr,
43 x86_seg_ldtr,
44 x86_seg_gdtr,
45 x86_seg_idtr
46 };
48 /*
49 * Return codes from state-accessor functions and from x86_emulate().
50 */
51 /* Completed successfully. State modified appropriately. */
52 #define X86EMUL_OKAY 0
53 /* Unhandleable access or emulation. No state modified. */
54 #define X86EMUL_UNHANDLEABLE 1
55 /* Exception raised and requires delivery. */
56 #define X86EMUL_EXCEPTION 2
57 /* Retry the emulation for some reason. No state modified. */
58 #define X86EMUL_RETRY 3
59 /* (cmpxchg accessor): CMPXCHG failed. Maps to X86EMUL_RETRY in caller. */
60 #define X86EMUL_CMPXCHG_FAILED 3
62 /*
63 * These operations represent the instruction emulator's interface to memory.
64 *
65 * NOTES:
66 * 1. If the access fails (cannot emulate, or a standard access faults) then
67 * it is up to the memop to propagate the fault to the guest VM via
68 * some out-of-band mechanism, unknown to the emulator. The memop signals
69 * failure by returning X86EMUL_EXCEPTION to the emulator, which will
70 * then immediately bail.
71 * 2. Valid access sizes are 1, 2, 4 and 8 bytes. On x86/32 systems only
72 * cmpxchg8b_emulated need support 8-byte accesses.
73 * 3. The emulator cannot handle 64-bit mode emulation on an x86/32 system.
74 */
75 struct x86_emulate_ops
76 {
77 /*
78 * All functions:
79 * @ctxt: [IN ] Emulation context info as passed to the emulator.
80 * All memory-access functions:
81 * @seg: [IN ] Segment being dereferenced (specified as x86_seg_??).
82 * @offset:[IN ] Offset within segment.
83 * Read functions:
84 * @val: [OUT] Value read, zero-extended to 'ulong'.
85 * Write functions:
86 * @val: [IN ] Value to write (low-order bytes used as req'd).
87 * Variable-length access functions:
88 * @bytes: [IN ] Number of bytes to read or write.
89 */
91 /* read: Emulate a memory read. */
92 int (*read)(
93 enum x86_segment seg,
94 unsigned long offset,
95 unsigned long *val,
96 unsigned int bytes,
97 struct x86_emulate_ctxt *ctxt);
99 /*
100 * insn_fetch: Emulate fetch from instruction byte stream.
101 * Parameters are same as for 'read'. @seg is always x86_seg_cs.
102 */
103 int (*insn_fetch)(
104 enum x86_segment seg,
105 unsigned long offset,
106 unsigned long *val,
107 unsigned int bytes,
108 struct x86_emulate_ctxt *ctxt);
110 /* write: Emulate a memory write. */
111 int (*write)(
112 enum x86_segment seg,
113 unsigned long offset,
114 unsigned long val,
115 unsigned int bytes,
116 struct x86_emulate_ctxt *ctxt);
118 /*
119 * cmpxchg: Emulate an atomic (LOCKed) CMPXCHG operation.
120 * @old: [IN ] Value expected to be current at @addr.
121 * @new: [IN ] Value to write to @addr.
122 */
123 int (*cmpxchg)(
124 enum x86_segment seg,
125 unsigned long offset,
126 unsigned long old,
127 unsigned long new,
128 unsigned int bytes,
129 struct x86_emulate_ctxt *ctxt);
131 /*
132 * cmpxchg8b: Emulate an atomic (LOCKed) CMPXCHG8B operation.
133 * @old: [IN ] Value expected to be current at @addr.
134 * @new: [IN ] Value to write to @addr.
135 * NOTES:
136 * 1. This function is only ever called when emulating a real CMPXCHG8B.
137 * 2. This function is *never* called on x86/64 systems.
138 * 2. Not defining this function (i.e., specifying NULL) is equivalent
139 * to defining a function that always returns X86EMUL_UNHANDLEABLE.
140 */
141 int (*cmpxchg8b)(
142 enum x86_segment seg,
143 unsigned long offset,
144 unsigned long old_lo,
145 unsigned long old_hi,
146 unsigned long new_lo,
147 unsigned long new_hi,
148 struct x86_emulate_ctxt *ctxt);
150 /*
151 * read_io: Read from I/O port(s).
152 * @port: [IN ] Base port for access.
153 */
154 int (*read_io)(
155 unsigned int port,
156 unsigned int bytes,
157 unsigned long *val,
158 struct x86_emulate_ctxt *ctxt);
160 /*
161 * write_io: Write to I/O port(s).
162 * @port: [IN ] Base port for access.
163 */
164 int (*write_io)(
165 unsigned int port,
166 unsigned int bytes,
167 unsigned long val,
168 struct x86_emulate_ctxt *ctxt);
170 /*
171 * read_cr: Read from control register.
172 * @reg: [IN ] Register to read (0-15).
173 */
174 int (*read_cr)(
175 unsigned int reg,
176 unsigned long *val,
177 struct x86_emulate_ctxt *ctxt);
179 /*
180 * write_cr: Write to control register.
181 * @reg: [IN ] Register to write (0-15).
182 */
183 int (*write_cr)(
184 unsigned int reg,
185 unsigned long val,
186 struct x86_emulate_ctxt *ctxt);
188 /*
189 * read_dr: Read from debug register.
190 * @reg: [IN ] Register to read (0-15).
191 */
192 int (*read_dr)(
193 unsigned int reg,
194 unsigned long *val,
195 struct x86_emulate_ctxt *ctxt);
197 /*
198 * write_dr: Write to debug register.
199 * @reg: [IN ] Register to write (0-15).
200 */
201 int (*write_dr)(
202 unsigned int reg,
203 unsigned long val,
204 struct x86_emulate_ctxt *ctxt);
206 /*
207 * read_msr: Read from model-specific register.
208 * @reg: [IN ] Register to read.
209 */
210 int (*read_msr)(
211 unsigned long reg,
212 uint64_t *val,
213 struct x86_emulate_ctxt *ctxt);
215 /*
216 * write_dr: Write to model-specific register.
217 * @reg: [IN ] Register to write.
218 */
219 int (*write_msr)(
220 unsigned long reg,
221 uint64_t val,
222 struct x86_emulate_ctxt *ctxt);
224 /* write_rflags: Modify privileged bits in RFLAGS. */
225 int (*write_rflags)(
226 unsigned long val,
227 struct x86_emulate_ctxt *ctxt);
229 /* wbinvd: Write-back and invalidate cache contents. */
230 int (*wbinvd)(
231 struct x86_emulate_ctxt *ctxt);
232 };
234 struct cpu_user_regs;
236 struct x86_emulate_ctxt
237 {
238 /* Register state before/after emulation. */
239 struct cpu_user_regs *regs;
241 /* Default address size in current execution mode (16, 32, or 64). */
242 unsigned int addr_size;
244 /* Stack pointer width in bits (16, 32 or 64). */
245 unsigned int sp_size;
246 };
248 /*
249 * x86_emulate: Emulate an instruction.
250 * Returns -1 on failure, 0 on success.
251 */
252 int
253 x86_emulate(
254 struct x86_emulate_ctxt *ctxt,
255 struct x86_emulate_ops *ops);
257 /*
258 * Given the 'reg' portion of a ModRM byte, and a register block, return a
259 * pointer into the block that addresses the relevant register.
260 * @highbyte_regs specifies whether to decode AH,CH,DH,BH.
261 */
262 void *
263 decode_register(
264 uint8_t modrm_reg, struct cpu_user_regs *regs, int highbyte_regs);
266 #endif /* __X86_EMULATE_H__ */