]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Implement RDTSC on x86.
authorJulian Seward <jseward@acm.org>
Tue, 23 Aug 2005 19:24:29 +0000 (19:24 +0000)
committerJulian Seward <jseward@acm.org>
Tue, 23 Aug 2005 19:24:29 +0000 (19:24 +0000)
git-svn-id: svn://svn.valgrind.org/vex/trunk@1344

VEX/priv/guest-x86/gdefs.h
VEX/priv/guest-x86/ghelpers.c
VEX/priv/guest-x86/toIR.c

index 1df4a446e3b0c1d82889042cf5643d9b060ce921..d1d3d29037607b865835badb1bfa9d18592e679a 100644 (file)
@@ -151,6 +151,8 @@ extern void  x86g_dirtyhelper_FXSAVE ( VexGuestX86State*, HWord );
 extern void  x86g_dirtyhelper_FSAVE  ( VexGuestX86State*, HWord );
 extern void  x86g_dirtyhelper_FSTENV ( VexGuestX86State*, HWord );
 
+extern ULong x86g_dirtyhelper_RDTSC ( void );
+
 extern VexEmWarn
             x86g_dirtyhelper_FRSTOR ( VexGuestX86State*, HWord );
 
index 5aaaf9a45b98b2fcb40121f884fd8aa1f51e2730..b188718b8df31249168f6c9e5f8b156f6f12c5f2 100644 (file)
@@ -1693,6 +1693,21 @@ ULong x86g_calculate_RCL ( UInt arg, UInt rot_amt, UInt eflags_in, UInt sz )
 }
 
 
+/* CALLED FROM GENERATED CODE */
+/* DIRTY HELPER (non-referentially-transparent) */
+/* Horrible hack.  On non-x86 platforms, return 1. */
+ULong x86g_dirtyhelper_RDTSC ( void )
+{
+#  if defined(__i386__)
+   ULong res;
+   __asm__ __volatile__("rdtsc" : "=A" (res));
+   return res;
+#  else
+   return 1ULL;
+#  endif
+}
+
+
 /* CALLED FROM GENERATED CODE */
 /* DIRTY HELPER (modifies guest state) */
 /* Claim to be a P55C (Intel Pentium/MMX) */
index 18e647f15c68cbdd5ec3ffedd9ff808aea7ad4b3..515785dd5d685a705c601d8b9da785f21ccf267d 100644 (file)
@@ -11967,34 +11967,23 @@ DisResult disInstr_X86_WRK (
          break;
 
       /* =-=-=-=-=-=-=-=-=- RDTSC -=-=-=-=-=-=-=-=-=-=-= */
-
-      case 0x31: /* RDTSC */
-         if (0) vex_printf("vex x86->IR: kludged rdtsc\n");
-         putIReg(4, R_EAX, mkU32(1));
-         putIReg(4, R_EDX, mkU32(0));
-
-//--          t1 = newTemp(cb);
-//--          t2 = newTemp(cb);
-//--          t3 = newTemp(cb);
-//--          uInstr0(cb, CALLM_S, 0);
-//--          // Nb: even though these args aren't used by RDTSC_helper, need
-//--          // them to be defined (for Memcheck).  The TempRegs pushed must
-//--          // also be distinct.
-//--          uInstr2(cb, MOV,   4, Literal, 0, TempReg, t1);
-//--          uLiteral(cb, 0);
-//--          uInstr1(cb, PUSH,  4, TempReg, t1);
-//--          uInstr2(cb, MOV,   4, Literal, 0, TempReg, t2);
-//--          uLiteral(cb, 0);
-//--          uInstr1(cb, PUSH,  4, TempReg, t2);
-//--          uInstr1(cb, CALLM, 0, Lit16,   VGOFF_(helper_RDTSC));
-//--          uFlagsRWU(cb, FlagsEmpty, FlagsEmpty, FlagsEmpty);
-//--          uInstr1(cb, POP,   4, TempReg, t3);
-//--          uInstr2(cb, PUT,   4, TempReg, t3, ArchReg, R_EDX);
-//--          uInstr1(cb, POP,   4, TempReg, t3);
-//--          uInstr2(cb, PUT,   4, TempReg, t3, ArchReg, R_EAX);
-//--          uInstr0(cb, CALLM_E, 0);
-         DIP("rdtsc\n");
-         break;
+      case 0x31: { /* RDTSC */
+         IRTemp   val  = newTemp(Ity_I64);
+         IRExpr** args = mkIRExprVec_0();
+         IRDirty* d    = unsafeIRDirty_1_N ( 
+                            val, 
+                            0/*regparms*/, 
+                            "x86g_dirtyhelper_RDTSC", 
+                            &x86g_dirtyhelper_RDTSC, 
+                            args 
+                         );
+          /* execute the dirty call, dumping the result in val. */
+          stmt( IRStmt_Dirty(d) );
+          putIReg(4, R_EDX, unop(Iop_64HIto32, mkexpr(val)));
+          putIReg(4, R_EAX, unop(Iop_64to32, mkexpr(val)));
+          DIP("rdtsc\n");
+          break;
+      }
 
       /* =-=-=-=-=-=-=-=-=- PUSH/POP Sreg =-=-=-=-=-=-=-=-=-= */