about summary refs log tree commit diff stats
path: root/src/emu
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2024-02-23 16:41:44 +0100
committerptitSeb <sebastien.chev@gmail.com>2024-02-23 16:41:44 +0100
commitffda782c3d88d977acc12a3c2c2738719f9304ed (patch)
treea0e1893fb28090c4f0f2a26c7a67bb40ae71f6b5 /src/emu
parent3a6df996dc85257a5496ecb28a72579df225a176 (diff)
downloadbox64-ffda782c3d88d977acc12a3c2c2738719f9304ed.tar.gz
box64-ffda782c3d88d977acc12a3c2c2738719f9304ed.zip
Better handling of Hardware counter for rdtsc emulation (ARM64 only for now), more cpuid leafs, and introduce BOX64_RDTSC env.var. with a profile that use it
Diffstat (limited to 'src/emu')
-rw-r--r--src/emu/x64emu.c36
1 files changed, 28 insertions, 8 deletions
diff --git a/src/emu/x64emu.c b/src/emu/x64emu.c
index 77626fdc..4d8bf629 100644
--- a/src/emu/x64emu.c
+++ b/src/emu/x64emu.c
@@ -583,15 +583,16 @@ uint64_t ReadTSC(x64emu_t* emu)
 {
     (void)emu;
     
-    //TODO: implement hardware counter read? (only available in kernel space?)
-    // Read the TimeStamp Counter as 64bits.
-    // this is supposed to be the number of cycle executed since last reset
-    // fall back to gettime...
+    // Hardware counter, per architecture
 #ifdef ARM64
-    uint64_t val;
-    asm volatile("mrs %0, cntvct_el0" : "=r" (val));
-    return val;
-#elif !defined(NOGETCLOCK)
+    if(!box64_rdtsc) {
+        uint64_t val;
+        asm volatile("mrs %0, cntvct_el0" : "=r" (val));
+        return val;
+    }
+#endif
+    // fall back to gettime...
+#if !defined(NOGETCLOCK)
     struct timespec ts;
     clock_gettime(CLOCK_MONOTONIC_COARSE, &ts);
     return (uint64_t)(ts.tv_sec) * 1000000000LL + ts.tv_nsec;
@@ -602,6 +603,25 @@ uint64_t ReadTSC(x64emu_t* emu)
 #endif
 }
 
+uint64_t ReadTSCFrequency(x64emu_t* emu)
+{
+    (void)emu;
+    // Hardware counter, per architecture
+#ifdef ARM64
+    if(!box64_rdtsc) {
+        uint64_t val;
+        asm volatile("mrs %0, cntfrq_el0" : "=r" (val));
+        return val;
+    }
+#endif
+    // fall back to get time
+#if !defined(NOGETCLOCK)
+    return 1000000000LL;
+#else
+    return 1000000;
+#endif
+}
+
 void ResetSegmentsCache(x64emu_t *emu)
 {
     if(!emu)