Skip to contentSkip to conversation

RDSTC TSD Flag Support

PATCH New Matthew Schulkind 1 participant 1 message Aug 15, 2005

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RDSTC TSD Flag Support

I'm not on the list, so any replies should be CC'ed to me personally.

I have attached a very small patch to implement TSD flag checking when the RDTSC instruction is executed on the x86 guest architecture. A GPF is supposed to be raised if the CPL is not 0 and the TSD flag in the CR4 register is enabled.

-Matt Schulkind

target-i386/helper.c +4 -0
diff -U4 -r --exclude=CVS qemu-orig/target-i386/helper.c qemu/target-i386/helper.c
@@ -2328,8 +2328,12 @@
 
 void helper_rdtsc(void)
 {
     uint64_t val;
+
+    if( (env->cr[4] & CR4_TSD_MASK) && ((env->hflags & HF_CPL_MASK) != 0) ) {
+        raise_exception( EXCP0D_GPF );
+    }
     
     val = cpu_get_tsc(env);
     EAX = (uint32_t)(val);
     EDX = (uint32_t)(val >> 32);
target-i386/translate.c +1 -0
diff -U4 -r --exclude=CVS qemu-orig/target-i386/translate.c qemu/target-i386/translate.c
@@ -5365,8 +5365,9 @@
                 gen_op_wrmsr();
         }
         break;
     case 0x131: /* rdtsc */
+        gen_jmp_im(pc_start - s->cs_base);
         gen_op_rdtsc();
         break;
     case 0x134: /* sysenter */
         if (CODE64(s))