about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--miasm2/jitter/emulatedsymbexec.py27
-rwxr-xr-xtest/arch/x86/unit/mn_cpuid.py21
-rwxr-xr-xtest/test_all.py1
3 files changed, 48 insertions, 1 deletions
diff --git a/miasm2/jitter/emulatedsymbexec.py b/miasm2/jitter/emulatedsymbexec.py
index 6a0882ba..ff9e5eaa 100644
--- a/miasm2/jitter/emulatedsymbexec.py
+++ b/miasm2/jitter/emulatedsymbexec.py
@@ -5,6 +5,21 @@ from miasm2.ir.symbexec import symbexec
 class EmulatedSymbExec(symbexec):
     """Symbolic exec instance linked with a jitter"""
 
+    cpuid = {
+        0: {
+            0: 0xa,
+            1: 0x756E6547,
+            2: 0x6C65746E,
+            3: 0x49656E69,
+        },
+        1: {
+            0: 0x00020652,
+            1: 0x00000800,
+            2: 0x00000209,
+            3: 0x078bf9ff
+        },
+    }
+
     def __init__(self, cpu, vm, *args, **kwargs):
         """Instanciate an EmulatedSymbExec, associated to CPU @cpu and bind
         memory accesses.
@@ -96,10 +111,20 @@ class EmulatedSymbExec(symbexec):
                                   m2_expr.ExprInt(segmaddr, expr.size),
                                   expr.args[1]))
 
+    def _simp_handle_cpuid(self, e_s, expr):
+        """From miasm2/jitter/vm_mngr.h: cpuid"""
+        if expr.op != "cpuid":
+            return expr
+
+        a, reg_num = (int(x) for x in expr.args)
+
+        # Not found error is keeped on purpose
+        return m2_expr.ExprInt(self.cpuid[a][reg_num], expr.size)
+
     def enable_emulated_simplifications(self):
         """Enable simplifications needing a CPU instance on associated
         ExpressionSimplifier
         """
         self.expr_simp.enable_passes({
-            m2_expr.ExprOp: [self._simp_handle_segm]
+            m2_expr.ExprOp: [self._simp_handle_segm, self._simp_handle_cpuid],
         })
diff --git a/test/arch/x86/unit/mn_cpuid.py b/test/arch/x86/unit/mn_cpuid.py
new file mode 100755
index 00000000..026de207
--- /dev/null
+++ b/test/arch/x86/unit/mn_cpuid.py
@@ -0,0 +1,21 @@
+#! /usr/bin/env python2
+
+import sys
+
+from asm_test import Asm_Test_32
+
+class Test_CPUID(Asm_Test_32):
+    """Check for cpuid support (and not for arbitrary returned values)"""
+    TXT = '''
+    main:
+       XOR EAX, EAX
+       CPUID
+       RET
+    '''
+
+    def check(self):
+        assert self.myjit.cpu.EAX == 0xa
+
+
+if __name__ == "__main__":
+    [test(*sys.argv[1:])() for test in [Test_CPUID]]
diff --git a/test/test_all.py b/test/test_all.py
index e49ce514..ab9e4b9b 100755
--- a/test/test_all.py
+++ b/test/test_all.py
@@ -77,6 +77,7 @@ for script in ["x86/sem.py",
                "x86/unit/mn_pmovmskb.py",
                "x86/unit/mn_pushpop.py",
                "x86/unit/mn_seh.py",
+               "x86/unit/mn_cpuid.py",
                "arm/arch.py",
                "arm/sem.py",
                "aarch64/unit/mn_ubfm.py",