about summary refs log tree commit diff stats
path: root/src/tools
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2024-06-24 16:07:10 +0200
committerptitSeb <sebastien.chev@gmail.com>2024-06-24 16:07:10 +0200
commitfa702c0240d0741def3955697067b562cc7a7fcd (patch)
tree9c6e9cc3cedffc9ba8249b933c75e88094cd4c64 /src/tools
parent34bc807bd5218d42e16757ed5dc7edd2751f5bf0 (diff)
downloadbox64-fa702c0240d0741def3955697067b562cc7a7fcd.tar.gz
box64-fa702c0240d0741def3955697067b562cc7a7fcd.zip
Improved CPUID a bit more, adding RDRAND (helps geekbench6 avx2 version)
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/my_cpuid.c59
1 files changed, 55 insertions, 4 deletions
diff --git a/src/tools/my_cpuid.c b/src/tools/my_cpuid.c
index 6bbc6ab0..49579792 100644
--- a/src/tools/my_cpuid.c
+++ b/src/tools/my_cpuid.c
@@ -231,7 +231,15 @@ void my_cpuid(x64emu_t* emu, uint32_t tmp32u)
             R_ECX = 0x6C65746E;
             break;
         case 0x1:
-            R_EAX = 0x00000601; // family and all
+            R_EAX = (0x1<<0) | // stepping
+                    (0x6<<4) | // model
+                    (0x6<<8) | // familly
+                    (0x0<<12)| // Processor type
+                    (0x0<<14)| // reserved
+                    (0x4<<16)| // extended model
+                    (0x0<<20)| // extended familly
+
+                    0 ; // family and all, simulating Haswell type of cpu
             R_EBX = 0 | (8<<0x8) | (ncluster<<16);          // Brand index, CLFlush (8), Max APIC ID (16-23), Local APIC ID (24-31)
             /*{
                 int cpu = sched_getcpu();
@@ -265,6 +273,7 @@ void my_cpuid(x64emu_t* emu, uint32_t tmp32u)
                     | box64_avx<<27 // osxsave
                     | box64_avx<<28 // AVX
                     | box64_avx<<29 // F16C
+                    | box64_avx2<<30     // RDRAND
                     ; 
             break;
         case 0x2:   // TLB and Cache info. Sending 1st gen P4 info...
@@ -326,10 +335,15 @@ void my_cpuid(x64emu_t* emu, uint32_t tmp32u)
                         box64_avx<<3 |  // BMI1 
                         box64_avx2<<5 |  //AVX2
                         box64_avx2<<8 | //BMI2
-                        box64_avx<<9 | //VAES
                         box64_avx2<<19 | //ADX
                         1<<29|  // SHA extension
                         0;
+                R_RCX = 
+                        box64_avx<<9   | //VAES
+                        box64_avx2<<10 | //VPCLMULQDQ.
+                        0;
+                R_RDX = 0;
+
             } else {R_EAX = R_ECX = R_EBX = R_EDX = 0;}
             break;
         case 0xB:   // Extended Topology Enumeration Leaf
@@ -414,7 +428,9 @@ void my_cpuid(x64emu_t* emu, uint32_t tmp32u)
         case 0x80000001:        //Extended Processor Signature and Feature Bits
             R_EAX = 0;  // reserved
             R_EBX = 0;  // reserved
-            R_ECX = (1<<0) | (1<<5) | (1<<8); // LAHF_LM | LZCNT | PREFETCHW
+            R_ECX = (1<<0)  // LAHF_LM 
+                | (1<<5)    // LZCNT
+                | (1<<8);   // PREFETCHW
             R_EDX = 1       // x87 FPU 
                 | (1<<8)    // cx8: cmpxchg8b opcode
                 | (1<<11)   // syscall
@@ -478,4 +494,39 @@ uint32_t helper_getcpu(x64emu_t* emu) {
     #endif
     #endif
     return 0;
-}
\ No newline at end of file
+}
+
+uint32_t fallback_random32()
+{
+    return random() ^ (random()<<1);
+}
+
+uint32_t get_random32()
+{
+    uint32_t ret;
+    FILE* f = fopen("/dev/urandom", "rb");
+    if(f) {
+        if(fread(&ret, sizeof(ret), 1, f)!=1)
+            ret = fallback_random32();
+        fclose(f);
+    } else
+        ret = fallback_random32();
+    return ret;
+}
+uint64_t fallback_random64()
+{
+    return random() ^ (((uint64_t)random())<<18) ^ (((uint64_t)random())<<41);
+}
+
+uint64_t get_random64()
+{
+    uint64_t ret;
+    FILE* f = fopen("/dev/urandom", "rb");
+    if(f) {
+        if(fread(&ret, sizeof(ret), 1, f)!=1)
+            ret = fallback_random64();
+        fclose(f);
+    } else
+        ret = fallback_random64();
+    return ret;
+}