aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorAvi Kivity <avi@redhat.com>2010-08-18 11:54:34 -0400
committerAvi Kivity <avi@redhat.com>2010-10-24 04:51:14 -0400
commit48bb5d3c401679e41e7a7f06ca31b3e54a6168f7 (patch)
tree0dd588a481026f84755307fdc98fca155d353c5d /arch
parent7077aec0bcd2f827aeb84ccc56c6f4367c376436 (diff)
KVM: x86 emulator: implement RDTSC (opcode 0F 31)
Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch')
-rw-r--r--arch/x86/kvm/emulate.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 7f7fc646678a..ed192d220201 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -2279,6 +2279,22 @@ static int em_imul_3op(struct x86_emulate_ctxt *ctxt)
2279 return em_imul(ctxt); 2279 return em_imul(ctxt);
2280} 2280}
2281 2281
2282static int em_rdtsc(struct x86_emulate_ctxt *ctxt)
2283{
2284 unsigned cpl = ctxt->ops->cpl(ctxt->vcpu);
2285 struct decode_cache *c = &ctxt->decode;
2286 u64 tsc = 0;
2287
2288 if (cpl > 0 && (ctxt->ops->get_cr(4, ctxt->vcpu) & X86_CR4_TSD)) {
2289 emulate_gp(ctxt, 0);
2290 return X86EMUL_PROPAGATE_FAULT;
2291 }
2292 ctxt->ops->get_msr(ctxt->vcpu, MSR_IA32_TSC, &tsc);
2293 c->regs[VCPU_REGS_RAX] = (u32)tsc;
2294 c->regs[VCPU_REGS_RDX] = tsc >> 32;
2295 return X86EMUL_CONTINUE;
2296}
2297
2282#define D(_y) { .flags = (_y) } 2298#define D(_y) { .flags = (_y) }
2283#define N D(0) 2299#define N D(0)
2284#define G(_f, _g) { .flags = ((_f) | Group), .u.group = (_g) } 2300#define G(_f, _g) { .flags = ((_f) | Group), .u.group = (_g) }
@@ -2469,7 +2485,8 @@ static struct opcode twobyte_table[256] = {
2469 N, N, N, N, 2485 N, N, N, N,
2470 N, N, N, N, N, N, N, N, 2486 N, N, N, N, N, N, N, N,
2471 /* 0x30 - 0x3F */ 2487 /* 0x30 - 0x3F */
2472 D(ImplicitOps | Priv), N, D(ImplicitOps | Priv), N, 2488 D(ImplicitOps | Priv), I(ImplicitOps, em_rdtsc),
2489 D(ImplicitOps | Priv), N,
2473 D(ImplicitOps), D(ImplicitOps | Priv), N, N, 2490 D(ImplicitOps), D(ImplicitOps | Priv), N, N,
2474 N, N, N, N, N, N, N, N, 2491 N, N, N, N, N, N, N, N,
2475 /* 0x40 - 0x4F */ 2492 /* 0x40 - 0x4F */