]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Implement RDTSC (amd64).
authorJulian Seward <jseward@acm.org>
Tue, 23 Aug 2005 23:16:51 +0000 (23:16 +0000)
committerJulian Seward <jseward@acm.org>
Tue, 23 Aug 2005 23:16:51 +0000 (23:16 +0000)
git-svn-id: svn://svn.valgrind.org/vex/trunk@1346

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

index 8f6814d57992bc5bf1da4057a34e7364c5c0e3b1..2ac553c6d9abba231efd021d586f40070630ff3f 100644 (file)
@@ -145,6 +145,8 @@ extern void  amd64g_storeF80le ( ULong/*addr*/, ULong/*data*/ );
 
 extern void amd64g_dirtyhelper_CPUID ( VexGuestAMD64State* st );
 
+extern ULong amd64g_dirtyhelper_RDTSC ( void );
+
 //extern void  amd64g_dirtyhelper_CPUID_sse0 ( VexGuestAMD64State* );
 //extern void  amd64g_dirtyhelper_CPUID_sse1 ( VexGuestAMD64State* );
 //extern void  amd64g_dirtyhelper_CPUID_sse2 ( VexGuestAMD64State* );
index 7958bb72ecb5843df3487462173f889dc9d5a78e..ee8688b4c4d87f94ec6d09b73241dc139e9ccd7a 100644 (file)
@@ -1676,6 +1676,21 @@ ULong amd64g_calculate_RCR ( ULong arg,
 }
 
 
+/* CALLED FROM GENERATED CODE */
+/* DIRTY HELPER (non-referentially-transparent) */
+/* Horrible hack.  On non-amd64 platforms, return 1. */
+ULong amd64g_dirtyhelper_RDTSC ( void )
+{
+#  if defined(__x86_64__)
+   UInt  eax, edx;
+   __asm__ __volatile__("rdtsc" : "=a" (eax), "=d" (edx));
+   return (((ULong)edx) << 32) | ((ULong)eax);
+#  else
+   return 1ULL;
+#  endif
+}
+
+
 /*---------------------------------------------------------------*/
 /*--- Helpers for MMX/SSE/SSE2.                               ---*/
 /*---------------------------------------------------------------*/
index 327d60effa2a42d28fe7c63b9554e8c95824c52d..0a27bef0890d3e0190a343f083561b82133e5f23 100644 (file)
@@ -13084,35 +13084,24 @@ DisResult disInstr_AMD64_WRK (
          break;
 
       /* =-=-=-=-=-=-=-=-=- RDTSC -=-=-=-=-=-=-=-=-=-=-= */
-
-      case 0x31: /* RDTSC */
-         if (haveF2orF3(pfx)) goto decode_failure;
-         if (0) vex_printf("vex amd64->IR: kludged rdtsc\n");
-         putIRegRAX(4, mkU32(1));
-         putIRegRDX(4, 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);
+      case 0x31: { /* RDTSC */
+         IRTemp   val  = newTemp(Ity_I64);
+         IRExpr** args = mkIRExprVec_0();
+         IRDirty* d    = unsafeIRDirty_1_N ( 
+                            val, 
+                            0/*regparms*/, 
+                            "amd64g_dirtyhelper_RDTSC", 
+                            &amd64g_dirtyhelper_RDTSC, 
+                            args 
+                         );
+         if (have66orF2orF3(pfx)) goto decode_failure;
+         /* execute the dirty call, dumping the result in val. */
+         stmt( IRStmt_Dirty(d) );
+         putIRegRDX(4, unop(Iop_64HIto32, mkexpr(val)));
+         putIRegRAX(4, unop(Iop_64to32, mkexpr(val)));
          DIP("rdtsc\n");
          break;
+      }
 
 //..       /* =-=-=-=-=-=-=-=-=- PUSH/POP Sreg =-=-=-=-=-=-=-=-=-= */
 //..