debuggers.hg
changeset 16521:43b7d24acf9c
x86_emulate: Emulate RDTSC instruction.
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author | Keir Fraser <keir.fraser@citrix.com> |
---|---|
date | Wed Nov 28 12:44:46 2007 +0000 (2007-11-28) |
parents | cca2f2fb857d |
children | bb31c9325d5f |
files | xen/arch/x86/x86_emulate.c |
line diff
1.1 --- a/xen/arch/x86/x86_emulate.c Wed Nov 28 12:44:19 2007 +0000 1.2 +++ b/xen/arch/x86/x86_emulate.c Wed Nov 28 12:44:46 2007 +0000 1.3 @@ -191,7 +191,7 @@ static uint8_t twobyte_table[256] = { 1.4 /* 0x28 - 0x2F */ 1.5 0, 0, 0, 0, 0, 0, 0, 0, 1.6 /* 0x30 - 0x37 */ 1.7 - ImplicitOps, 0, ImplicitOps, 0, 0, 0, 0, 0, 1.8 + ImplicitOps, ImplicitOps, ImplicitOps, 0, 0, 0, 0, 0, 1.9 /* 0x38 - 0x3F */ 1.10 0, 0, 0, 0, 0, 0, 0, 0, 1.11 /* 0x40 - 0x47 */ 1.12 @@ -271,6 +271,13 @@ struct operand { 1.13 }; 1.14 }; 1.15 1.16 +/* MSRs. */ 1.17 +#define MSR_TSC 0x10 1.18 + 1.19 +/* Control register flags. */ 1.20 +#define CR0_PE (1<<0) 1.21 +#define CR4_TSD (1<<2) 1.22 + 1.23 /* EFLAGS bit definitions. */ 1.24 #define EFLG_VIP (1<<20) 1.25 #define EFLG_VIF (1<<19) 1.26 @@ -739,7 +746,7 @@ in_realmode( 1.27 return 0; 1.28 1.29 rc = ops->read_cr(0, &cr0, ctxt); 1.30 - return (!rc && !(cr0 & 1)); 1.31 + return (!rc && !(cr0 & CR0_PE)); 1.32 } 1.33 1.34 static int 1.35 @@ -2860,6 +2867,21 @@ x86_emulate( 1.36 break; 1.37 } 1.38 1.39 + case 0x31: /* rdtsc */ { 1.40 + unsigned long cr4; 1.41 + uint64_t val; 1.42 + fail_if(ops->read_cr == NULL); 1.43 + if ( (rc = ops->read_cr(4, &cr4, ctxt)) ) 1.44 + goto done; 1.45 + generate_exception_if((cr4 & CR4_TSD) && !mode_ring0(), EXC_GP); 1.46 + fail_if(ops->read_msr == NULL); 1.47 + if ( (rc = ops->read_msr(MSR_TSC, &val, ctxt)) != 0 ) 1.48 + goto done; 1.49 + _regs.edx = (uint32_t)(val >> 32); 1.50 + _regs.eax = (uint32_t)(val >> 0); 1.51 + break; 1.52 + } 1.53 + 1.54 case 0x32: /* rdmsr */ { 1.55 uint64_t val; 1.56 generate_exception_if(!mode_ring0(), EXC_GP);