diff options
| author | Camille Mougey <commial@gmail.com> | 2018-09-19 22:18:00 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-09-19 22:18:00 +0200 |
| commit | 2f9139cbc737978d7308496bb8249a99431320e7 (patch) | |
| tree | cf7cce9019808d29e87a5395d467a4810ad59859 | |
| parent | 22532774f6e6f8807f98e7dd82abcbf83e7d5057 (diff) | |
| parent | 806dabd0f2947466c9634e31354512961b1d2f40 (diff) | |
| download | miasm-2f9139cbc737978d7308496bb8249a99431320e7.tar.gz miasm-2f9139cbc737978d7308496bb8249a99431320e7.zip | |
Merge pull request #853 from serpilliere/fix_xmm_accesses
Fix xmm accesses
| -rw-r--r-- | miasm2/jitter/JitCore.h | 34 | ||||
| -rw-r--r-- | miasm2/jitter/arch/JitCore_aarch64.c | 84 | ||||
| -rw-r--r-- | miasm2/jitter/arch/JitCore_arm.c | 59 | ||||
| -rw-r--r-- | miasm2/jitter/arch/JitCore_mep.c | 114 | ||||
| -rw-r--r-- | miasm2/jitter/arch/JitCore_mips32.c | 72 | ||||
| -rw-r--r-- | miasm2/jitter/arch/JitCore_ppc32.c | 2 | ||||
| -rw-r--r-- | miasm2/jitter/arch/JitCore_x86.c | 204 | ||||
| -rw-r--r-- | miasm2/jitter/bn.c | 5 | ||||
| -rw-r--r-- | test/arch/x86/unit/mn_getset128.py | 52 | ||||
| -rwxr-xr-x | test/arch/x86/unit/mn_pcmpeq.py | 32 | ||||
| -rwxr-xr-x | test/test_all.py | 1 |
11 files changed, 369 insertions, 290 deletions
diff --git a/miasm2/jitter/JitCore.h b/miasm2/jitter/JitCore.h index 0eaf4939..d85b71d9 100644 --- a/miasm2/jitter/JitCore.h +++ b/miasm2/jitter/JitCore.h @@ -36,10 +36,11 @@ } \ -#define getset_reg_bn(regname) \ +#define getset_reg_bn(regname, size) \ static PyObject *JitCpu_get_ ## regname (JitCpu *self, void *closure) \ { \ bn_t bn; \ + int j; \ PyObject* py_long; \ PyObject* py_long_new; \ PyObject* py_tmp; \ @@ -48,13 +49,13 @@ py_long = PyLong_FromLong(0); \ cst_32 = PyLong_FromLong(32); \ bn = ((vm_cpu_t*)(self->cpu))-> regname; \ - while (!bignum_is_zero(bn)) { \ - tmp = bignum_to_uint64(bignum_mask(bn, 32)) & 0xffffffff; \ - bn = bignum_rshift(bn, 32); \ + bn = bignum_mask(bn, (size)); \ + for (j = BN_BYTE_SIZE - 4; j >= 0 ; j -= 4) { \ + tmp = bignum_to_uint64(bignum_mask(bignum_rshift(bn, 8 * j), 32)); \ py_tmp = PyLong_FromUnsignedLong(tmp); \ py_long_new = PyObject_CallMethod(py_long, "__lshift__", "O", cst_32); \ Py_DECREF(py_long); \ - py_long = PyObject_CallMethod(py_long_new, "__add__", "O", py_tmp); \ + py_long = PyObject_CallMethod(py_long_new, "__add__", "O", py_tmp); \ Py_DECREF(py_long_new); \ Py_DECREF(py_tmp); \ } \ @@ -82,7 +83,7 @@ /* Increment ref as we will decement it next */ \ Py_INCREF(py_long); \ } \ - else{ \ + else { \ PyErr_SetString(PyExc_TypeError, "Arg must be int"); \ return -1; \ } \ @@ -93,23 +94,21 @@ \ for (j = 0; j < BN_BYTE_SIZE; j += 4) { \ py_tmp = PyObject_CallMethod(py_long, "__and__", "O", cst_ffffffff); \ - tmp = PyLong_AsUnsignedLongMask(py_tmp); \ - Py_DECREF(py_tmp); \ - bn = bignum_lshift(bn, 32); \ - bn = bignum_or(bn, bignum_from_uint64(tmp)); \ py_long_new = PyObject_CallMethod(py_long, "__rshift__", "O", cst_32); \ Py_DECREF(py_long); \ py_long = py_long_new; \ + tmp = PyLong_AsUnsignedLongMask(py_tmp); \ + Py_DECREF(py_tmp); \ + bn = bignum_or(bn, bignum_lshift(bignum_from_uint64(tmp), 8 * j)); \ } \ \ - ((vm_cpu_t*)(self->cpu))-> regname = bn; \ + ((vm_cpu_t*)(self->cpu))-> regname = bignum_mask(bn, (size)); \ Py_DECREF(py_long); \ Py_DECREF(cst_32); \ Py_DECREF(cst_ffffffff); \ return 0; \ } - #define getset_reg_u64(regname) \ static PyObject *JitCpu_get_ ## regname (JitCpu *self, void *closure) \ { \ @@ -158,8 +157,9 @@ } while(0); -#define get_reg_bn(reg) do { \ +#define get_reg_bn(reg, size) do { \ bn_t bn; \ + int j; \ PyObject* py_long; \ PyObject* py_long_new; \ PyObject* py_tmp; \ @@ -168,10 +168,10 @@ py_long = PyLong_FromLong(0); \ cst_32 = PyLong_FromLong(32); \ bn = ((vm_cpu_t*)(self->cpu))-> reg; \ - while (!bignum_is_zero(bn)) { \ - tmp = bignum_to_uint64(bignum_mask(bn, 32)) & 0xffffffff; \ - bn = bignum_rshift(bn, 32); \ - py_tmp = PyLong_FromLong(tmp); \ + bn = bignum_mask(bn, size); \ + for (j = BN_BYTE_SIZE - 4; j >= 0 ; j -= 4) { \ + tmp = bignum_to_uint64(bignum_mask(bignum_rshift(bn, 8 * j), 32)); \ + py_tmp = PyLong_FromUnsignedLong(tmp); \ py_long_new = PyObject_CallMethod(py_long, "__lshift__", "O", cst_32); \ Py_DECREF(py_long); \ py_long = PyObject_CallMethod(py_long_new, "__add__", "O", py_tmp); \ diff --git a/miasm2/jitter/arch/JitCore_aarch64.c b/miasm2/jitter/arch/JitCore_aarch64.c index f5977308..76452a44 100644 --- a/miasm2/jitter/arch/JitCore_aarch64.c +++ b/miasm2/jitter/arch/JitCore_aarch64.c @@ -13,48 +13,48 @@ reg_dict gpreg_dict[] = { - {.name = "X0", .offset = offsetof(vm_cpu_t, X0)}, - {.name = "X1", .offset = offsetof(vm_cpu_t, X1)}, - {.name = "X2", .offset = offsetof(vm_cpu_t, X2)}, - {.name = "X3", .offset = offsetof(vm_cpu_t, X3)}, - {.name = "X4", .offset = offsetof(vm_cpu_t, X4)}, - {.name = "X5", .offset = offsetof(vm_cpu_t, X5)}, - {.name = "X6", .offset = offsetof(vm_cpu_t, X6)}, - {.name = "X7", .offset = offsetof(vm_cpu_t, X7)}, - {.name = "X8", .offset = offsetof(vm_cpu_t, X8)}, - {.name = "X9", .offset = offsetof(vm_cpu_t, X9)}, - {.name = "X10", .offset = offsetof(vm_cpu_t, X10)}, - {.name = "X11", .offset = offsetof(vm_cpu_t, X11)}, - {.name = "X12", .offset = offsetof(vm_cpu_t, X12)}, - {.name = "X13", .offset = offsetof(vm_cpu_t, X13)}, - {.name = "X14", .offset = offsetof(vm_cpu_t, X14)}, - {.name = "X15", .offset = offsetof(vm_cpu_t, X15)}, - {.name = "X16", .offset = offsetof(vm_cpu_t, X16)}, - {.name = "X17", .offset = offsetof(vm_cpu_t, X17)}, - {.name = "X18", .offset = offsetof(vm_cpu_t, X18)}, - {.name = "X19", .offset = offsetof(vm_cpu_t, X19)}, - {.name = "X20", .offset = offsetof(vm_cpu_t, X20)}, - {.name = "X21", .offset = offsetof(vm_cpu_t, X21)}, - {.name = "X22", .offset = offsetof(vm_cpu_t, X22)}, - {.name = "X23", .offset = offsetof(vm_cpu_t, X23)}, - {.name = "X24", .offset = offsetof(vm_cpu_t, X24)}, - {.name = "X25", .offset = offsetof(vm_cpu_t, X25)}, - {.name = "X26", .offset = offsetof(vm_cpu_t, X26)}, - {.name = "X27", .offset = offsetof(vm_cpu_t, X27)}, - {.name = "X28", .offset = offsetof(vm_cpu_t, X28)}, - {.name = "X29", .offset = offsetof(vm_cpu_t, X29)}, - {.name = "LR", .offset = offsetof(vm_cpu_t, LR)}, - - {.name = "SP", .offset = offsetof(vm_cpu_t, SP)}, - {.name = "PC", .offset = offsetof(vm_cpu_t, PC)}, - - {.name = "zf", .offset = offsetof(vm_cpu_t, zf)}, - {.name = "nf", .offset = offsetof(vm_cpu_t, nf)}, - {.name = "of", .offset = offsetof(vm_cpu_t, of)}, - {.name = "cf", .offset = offsetof(vm_cpu_t, cf)}, - - {.name = "exception_flags", .offset = offsetof(vm_cpu_t, exception_flags)}, - {.name = "interrupt_num", .offset = offsetof(vm_cpu_t, interrupt_num)}, + {.name = "X0", .offset = offsetof(vm_cpu_t, X0), .size = 64}, + {.name = "X1", .offset = offsetof(vm_cpu_t, X1), .size = 64}, + {.name = "X2", .offset = offsetof(vm_cpu_t, X2), .size = 64}, + {.name = "X3", .offset = offsetof(vm_cpu_t, X3), .size = 64}, + {.name = "X4", .offset = offsetof(vm_cpu_t, X4), .size = 64}, + {.name = "X5", .offset = offsetof(vm_cpu_t, X5), .size = 64}, + {.name = "X6", .offset = offsetof(vm_cpu_t, X6), .size = 64}, + {.name = "X7", .offset = offsetof(vm_cpu_t, X7), .size = 64}, + {.name = "X8", .offset = offsetof(vm_cpu_t, X8), .size = 64}, + {.name = "X9", .offset = offsetof(vm_cpu_t, X9), .size = 64}, + {.name = "X10", .offset = offsetof(vm_cpu_t, X10), .size = 64}, + {.name = "X11", .offset = offsetof(vm_cpu_t, X11), .size = 64}, + {.name = "X12", .offset = offsetof(vm_cpu_t, X12), .size = 64}, + {.name = "X13", .offset = offsetof(vm_cpu_t, X13), .size = 64}, + {.name = "X14", .offset = offsetof(vm_cpu_t, X14), .size = 64}, + {.name = "X15", .offset = offsetof(vm_cpu_t, X15), .size = 64}, + {.name = "X16", .offset = offsetof(vm_cpu_t, X16), .size = 64}, + {.name = "X17", .offset = offsetof(vm_cpu_t, X17), .size = 64}, + {.name = "X18", .offset = offsetof(vm_cpu_t, X18), .size = 64}, + {.name = "X19", .offset = offsetof(vm_cpu_t, X19), .size = 64}, + {.name = "X20", .offset = offsetof(vm_cpu_t, X20), .size = 64}, + {.name = "X21", .offset = offsetof(vm_cpu_t, X21), .size = 64}, + {.name = "X22", .offset = offsetof(vm_cpu_t, X22), .size = 64}, + {.name = "X23", .offset = offsetof(vm_cpu_t, X23), .size = 64}, + {.name = "X24", .offset = offsetof(vm_cpu_t, X24), .size = 64}, + {.name = "X25", .offset = offsetof(vm_cpu_t, X25), .size = 64}, + {.name = "X26", .offset = offsetof(vm_cpu_t, X26), .size = 64}, + {.name = "X27", .offset = offsetof(vm_cpu_t, X27), .size = 64}, + {.name = "X28", .offset = offsetof(vm_cpu_t, X28), .size = 64}, + {.name = "X29", .offset = offsetof(vm_cpu_t, X29), .size = 64}, + {.name = "LR", .offset = offsetof(vm_cpu_t, LR), .size = 64}, + + {.name = "SP", .offset = offsetof(vm_cpu_t, SP), .size = 64}, + {.name = "PC", .offset = offsetof(vm_cpu_t, PC), .size = 64}, + + {.name = "zf", .offset = offsetof(vm_cpu_t, zf), .size = 8}, + {.name = "nf", .offset = offsetof(vm_cpu_t, nf), .size = 8}, + {.name = "of", .offset = offsetof(vm_cpu_t, of), .size = 8}, + {.name = "cf", .offset = offsetof(vm_cpu_t, cf), .size = 8}, + + {.name = "exception_flags", .offset = offsetof(vm_cpu_t, exception_flags), .size = 32}, + {.name = "interrupt_num", .offset = offsetof(vm_cpu_t, interrupt_num), .size = 32}, }; diff --git a/miasm2/jitter/arch/JitCore_arm.c b/miasm2/jitter/arch/JitCore_arm.c index f253c45b..ac7d16bf 100644 --- a/miasm2/jitter/arch/JitCore_arm.c +++ b/miasm2/jitter/arch/JitCore_arm.c @@ -12,35 +12,36 @@ -reg_dict gpreg_dict[] = { {.name = "R0", .offset = offsetof(vm_cpu_t, R0)}, - {.name = "R1", .offset = offsetof(vm_cpu_t, R1)}, - {.name = "R2", .offset = offsetof(vm_cpu_t, R2)}, - {.name = "R3", .offset = offsetof(vm_cpu_t, R3)}, - {.name = "R4", .offset = offsetof(vm_cpu_t, R4)}, - {.name = "R5", .offset = offsetof(vm_cpu_t, R5)}, - {.name = "R6", .offset = offsetof(vm_cpu_t, R6)}, - {.name = "R7", .offset = offsetof(vm_cpu_t, R7)}, - {.name = "R8", .offset = offsetof(vm_cpu_t, R8)}, - {.name = "R9", .offset = offsetof(vm_cpu_t, R9)}, - {.name = "R10", .offset = offsetof(vm_cpu_t, R10)}, - {.name = "R11", .offset = offsetof(vm_cpu_t, R11)}, - {.name = "R12", .offset = offsetof(vm_cpu_t, R12)}, - {.name = "SP", .offset = offsetof(vm_cpu_t, SP)}, - {.name = "LR", .offset = offsetof(vm_cpu_t, LR)}, - {.name = "PC", .offset = offsetof(vm_cpu_t, PC)}, - - {.name = "zf", .offset = offsetof(vm_cpu_t, zf)}, - {.name = "nf", .offset = offsetof(vm_cpu_t, nf)}, - {.name = "of", .offset = offsetof(vm_cpu_t, of)}, - {.name = "cf", .offset = offsetof(vm_cpu_t, cf)}, - - {.name = "ge0", .offset = offsetof(vm_cpu_t, ge0)}, - {.name = "ge1", .offset = offsetof(vm_cpu_t, ge1)}, - {.name = "ge2", .offset = offsetof(vm_cpu_t, ge2)}, - {.name = "ge3", .offset = offsetof(vm_cpu_t, ge3)}, - - {.name = "exception_flags", .offset = offsetof(vm_cpu_t, exception_flags)}, - {.name = "interrupt_num", .offset = offsetof(vm_cpu_t, interrupt_num)}, +reg_dict gpreg_dict[] = { + {.name = "R0", .offset = offsetof(vm_cpu_t, R0), .size = 32}, + {.name = "R1", .offset = offsetof(vm_cpu_t, R1), .size = 32}, + {.name = "R2", .offset = offsetof(vm_cpu_t, R2), .size = 32}, + {.name = "R3", .offset = offsetof(vm_cpu_t, R3), .size = 32}, + {.name = "R4", .offset = offsetof(vm_cpu_t, R4), .size = 32}, + {.name = "R5", .offset = offsetof(vm_cpu_t, R5), .size = 32}, + {.name = "R6", .offset = offsetof(vm_cpu_t, R6), .size = 32}, + {.name = "R7", .offset = offsetof(vm_cpu_t, R7), .size = 32}, + {.name = "R8", .offset = offsetof(vm_cpu_t, R8), .size = 32}, + {.name = "R9", .offset = offsetof(vm_cpu_t, R9), .size = 32}, + {.name = "R10", .offset = offsetof(vm_cpu_t, R10), .size = 32}, + {.name = "R11", .offset = offsetof(vm_cpu_t, R11), .size = 32}, + {.name = "R12", .offset = offsetof(vm_cpu_t, R12), .size = 32}, + {.name = "SP", .offset = offsetof(vm_cpu_t, SP), .size = 32}, + {.name = "LR", .offset = offsetof(vm_cpu_t, LR), .size = 32}, + {.name = "PC", .offset = offsetof(vm_cpu_t, PC), .size = 32}, + + {.name = "zf", .offset = offsetof(vm_cpu_t, zf), .size = 8}, + {.name = "nf", .offset = offsetof(vm_cpu_t, nf), .size = 8}, + {.name = "of", .offset = offsetof(vm_cpu_t, of), .size = 8}, + {.name = "cf", .offset = offsetof(vm_cpu_t, cf), .size = 8}, + + {.name = "ge0", .offset = offsetof(vm_cpu_t, ge0), .size = 8}, + {.name = "ge1", .offset = offsetof(vm_cpu_t, ge1), .size = 8}, + {.name = "ge2", .offset = offsetof(vm_cpu_t, ge2), .size = 8}, + {.name = "ge3", .offset = offsetof(vm_cpu_t, ge3), .size = 8}, + + {.name = "exception_flags", .offset = offsetof(vm_cpu_t, exception_flags), .size = 32}, + {.name = "interrupt_num", .offset = offsetof(vm_cpu_t, interrupt_num), .size = 32}, }; /************************** JitCpu object **************************/ diff --git a/miasm2/jitter/arch/JitCore_mep.c b/miasm2/jitter/arch/JitCore_mep.c index dff65dd5..da070016 100644 --- a/miasm2/jitter/arch/JitCore_mep.c +++ b/miasm2/jitter/arch/JitCore_mep.c @@ -14,63 +14,63 @@ reg_dict gpreg_dict[] = { - {.name = "R0", .offset = offsetof(vm_cpu_t, R0)}, - {.name = "R1", .offset = offsetof(vm_cpu_t, R1)}, - {.name = "R2", .offset = offsetof(vm_cpu_t, R2)}, - {.name = "R3", .offset = offsetof(vm_cpu_t, R3)}, - {.name = "R4", .offset = offsetof(vm_cpu_t, R4)}, - {.name = "R5", .offset = offsetof(vm_cpu_t, R5)}, - {.name = "R6", .offset = offsetof(vm_cpu_t, R6)}, - {.name = "R7", .offset = offsetof(vm_cpu_t, R7)}, - {.name = "R8", .offset = offsetof(vm_cpu_t, R8)}, - {.name = "R9", .offset = offsetof(vm_cpu_t, R9)}, - {.name = "R10", .offset = offsetof(vm_cpu_t, R10)}, - {.name = "R11", .offset = offsetof(vm_cpu_t, R11)}, - {.name = "R12", .offset = offsetof(vm_cpu_t, R12)}, - {.name = "TP", .offset = offsetof(vm_cpu_t, TP)}, - {.name = "GP", .offset = offsetof(vm_cpu_t, GP)}, - {.name = "SP", .offset = offsetof(vm_cpu_t, SP)}, - - {.name = "PC", .offset = offsetof(vm_cpu_t, PC)}, - {.name = "LP", .offset = offsetof(vm_cpu_t, LP)}, - {.name = "SAR", .offset = offsetof(vm_cpu_t, SAR)}, - {.name = "S3", .offset = offsetof(vm_cpu_t, S3)}, - {.name = "RPB", .offset = offsetof(vm_cpu_t, RPB)}, - {.name = "RPE", .offset = offsetof(vm_cpu_t, RPE)}, - {.name = "RPC", .offset = offsetof(vm_cpu_t, RPC)}, - {.name = "HI", .offset = offsetof(vm_cpu_t, HI)}, - {.name = "LO", .offset = offsetof(vm_cpu_t, LO)}, - {.name = "S9", .offset = offsetof(vm_cpu_t, S9)}, - {.name = "S10", .offset = offsetof(vm_cpu_t, S10)}, - {.name = "S11", .offset = offsetof(vm_cpu_t, S11)}, - {.name = "MB0", .offset = offsetof(vm_cpu_t, MB0)}, - {.name = "ME0", .offset = offsetof(vm_cpu_t, ME0)}, - {.name = "MB1", .offset = offsetof(vm_cpu_t, MB1)}, - {.name = "ME1", .offset = offsetof(vm_cpu_t, ME1)}, - {.name = "PSW", .offset = offsetof(vm_cpu_t, PSW)}, - {.name = "ID", .offset = offsetof(vm_cpu_t, ID)}, - {.name = "TMP", .offset = offsetof(vm_cpu_t, TMP)}, - {.name = "EPC", .offset = offsetof(vm_cpu_t, EPC)}, - {.name = "EXC", .offset = offsetof(vm_cpu_t, EXC)}, - {.name = "CFG", .offset = offsetof(vm_cpu_t, CFG)}, - {.name = "S22", .offset = offsetof(vm_cpu_t, S22)}, - {.name = "NPC", .offset = offsetof(vm_cpu_t, NPC)}, - {.name = "DBG", .offset = offsetof(vm_cpu_t, DBG)}, - {.name = "DEPC", .offset = offsetof(vm_cpu_t, DEPC)}, - {.name = "OPT", .offset = offsetof(vm_cpu_t, OPT)}, - {.name = "RCFG", .offset = offsetof(vm_cpu_t, RCFG)}, - {.name = "CCFG", .offset = offsetof(vm_cpu_t, CCFG)}, - {.name = "S29", .offset = offsetof(vm_cpu_t, S29)}, - {.name = "S30", .offset = offsetof(vm_cpu_t, S30)}, - {.name = "S31", .offset = offsetof(vm_cpu_t, S31)}, - {.name = "S32", .offset = offsetof(vm_cpu_t, S32)}, - {.name = "take_jmp", .offset = offsetof(vm_cpu_t, take_jmp)}, - {.name = "last_addr", .offset = offsetof(vm_cpu_t, last_addr)}, - {.name = "is_repeat_end", .offset = offsetof(vm_cpu_t, is_repeat_end)}, - - {.name = "PC_end", .offset = offsetof(vm_cpu_t, PC_end)}, - {.name = "RPE_instr_count", .offset = offsetof(vm_cpu_t, RPE_instr_count)}, - {.name = "RPC_current", .offset = offsetof(vm_cpu_t, RPC_current)}, + {.name = "R0", .offset = offsetof(vm_cpu_t, R0), .size = 32}, + {.name = "R1", .offset = offsetof(vm_cpu_t, R1), .size = 32}, + {.name = "R2", .offset = offsetof(vm_cpu_t, R2), .size = 32}, + {.name = "R3", .offset = offsetof(vm_cpu_t, R3), .size = 32}, + {.name = "R4", .offset = offsetof(vm_cpu_t, R4), .size = 32}, + {.name = "R5", .offset = offsetof(vm_cpu_t, R5), .size = 32}, + {.name = "R6", .offset = offsetof(vm_cpu_t, R6), .size = 32}, + {.name = "R7", .offset = offsetof(vm_cpu_t, R7), .size = 32}, + {.name = "R8", .offset = offsetof(vm_cpu_t, R8), .size = 32}, + {.name = "R9", .offset = offsetof(vm_cpu_t, R9), .size = 32}, + {.name = "R10", .offset = offsetof(vm_cpu_t, R10), .size = 32}, + {.name = "R11", .offset = offsetof(vm_cpu_t, R11), .size = 32}, + {.name = "R12", .offset = offsetof(vm_cpu_t, R12), .size = 32}, + {.name = "TP", .offset = offsetof(vm_cpu_t, TP), .size = 32}, + {.name = "GP", .offset = offsetof(vm_cpu_t, GP), .size = 32}, + {.name = "SP", .offset = offsetof(vm_cpu_t, SP), .size = 32}, + + {.name = "PC", .offset = offsetof(vm_cpu_t, PC), .size = 32}, + {.name = "LP", .offset = offsetof(vm_cpu_t, LP), .size = 32}, + {.name = "SAR", .offset = offsetof(vm_cpu_t, SAR), .size = 32}, + {.name = "S3", .offset = offsetof(vm_cpu_t, S3), .size = 32}, + {.name = "RPB", .offset = offsetof(vm_cpu_t, RPB), .size = 32}, + {.name = "RPE", .offset = offsetof(vm_cpu_t, RPE), .size = 32}, + {.name = "RPC", .offset = offsetof(vm_cpu_t, RPC), .size = 32}, + {.name = "HI", .offset = offsetof(vm_cpu_t, HI), .size = 32}, + {.name = "LO", .offset = offsetof(vm_cpu_t, LO), .size = 32}, + {.name = "S9", .offset = offsetof(vm_cpu_t, S9), .size = 32}, + {.name = "S10", .offset = offsetof(vm_cpu_t, S10), .size = 32}, + {.name = "S11", .offset = offsetof(vm_cpu_t, S11), .size = 32}, + {.name = "MB0", .offset = offsetof(vm_cpu_t, MB0), .size = 32}, + {.name = "ME0", .offset = offsetof(vm_cpu_t, ME0), .size = 32}, + {.name = "MB1", .offset = offsetof(vm_cpu_t, MB1), .size = 32}, + {.name = "ME1", .offset = offsetof(vm_cpu_t, ME1), .size = 32}, + {.name = "PSW", .offset = offsetof(vm_cpu_t, PSW), .size = 32}, + {.name = "ID", .offset = offsetof(vm_cpu_t, ID), .size = 32}, + {.name = "TMP", .offset = offsetof(vm_cpu_t, TMP), .size = 32}, + {.name = "EPC", .offset = offsetof(vm_cpu_t, EPC), .size = 32}, + {.name = "EXC", .offset = offsetof(vm_cpu_t, EXC), .size = 32}, + {.name = "CFG", .offset = offsetof(vm_cpu_t, CFG), .size = 32}, + {.name = "S22", .offset = offsetof(vm_cpu_t, S22), .size = 32}, + {.name = "NPC", .offset = offsetof(vm_cpu_t, NPC), .size = 32}, + {.name = "DBG", .offset = offsetof(vm_cpu_t, DBG), .size = 32}, + {.name = "DEPC", .offset = offsetof(vm_cpu_t, DEPC), .size = 32}, + {.name = "OPT", .offset = offsetof(vm_cpu_t, OPT), .size = 32}, + {.name = "RCFG", .offset = offsetof(vm_cpu_t, RCFG), .size = 32}, + {.name = "CCFG", .offset = offsetof(vm_cpu_t, CCFG), .size = 32}, + {.name = "S29", .offset = offsetof(vm_cpu_t, S29), .size = 32}, + {.name = "S30", .offset = offsetof(vm_cpu_t, S30), .size = 32}, + {.name = "S31", .offset = offsetof(vm_cpu_t, S31), .size = 32}, + {.name = "S32", .offset = offsetof(vm_cpu_t, S32), .size = 32}, + {.name = "take_jmp", .offset = offsetof(vm_cpu_t, take_jmp), .size = 32}, + {.name = "last_addr", .offset = offsetof(vm_cpu_t, last_addr), .size = 32}, + {.name = "is_repeat_end", .offset = offsetof(vm_cpu_t, is_repeat_end), .size = 32}, + + {.name = "PC_end", .offset = offsetof(vm_cpu_t, PC_end), .size = 32}, + {.name = "RPE_instr_count", .offset = offsetof(vm_cpu_t, RPE_instr_count), .size = 32}, + {.name = "RPC_current", .offset = offsetof(vm_cpu_t, RPC_current), .size = 32}, }; diff --git a/miasm2/jitter/arch/JitCore_mips32.c b/miasm2/jitter/arch/JitCore_mips32.c index a1bf44f5..2a5dfd0f 100644 --- a/miasm2/jitter/arch/JitCore_mips32.c +++ b/miasm2/jitter/arch/JitCore_mips32.c @@ -12,42 +12,42 @@ -reg_dict gpreg_dict[] = { {.name = "ZERO", .offset = offsetof(vm_cpu_t, ZERO)}, - {.name = "AT", .offset = offsetof(vm_cpu_t, AT)}, - {.name = "V0", .offset = offsetof(vm_cpu_t, V0)}, - {.name = "V1", .offset = offsetof(vm_cpu_t, V1)}, - {.name = "A0", .offset = offsetof(vm_cpu_t, A0)}, - {.name = "A1", .offset = offsetof(vm_cpu_t, A1)}, - {.name = "A2", .offset = offsetof(vm_cpu_t, A2)}, - {.name = "A3", .offset = offsetof(vm_cpu_t, A3)}, - {.name = "T0", .offset = offsetof(vm_cpu_t, T0)}, - {.name = "T1", .offset = offsetof(vm_cpu_t, T1)}, - {.name = "T2", .offset = offsetof(vm_cpu_t, T2)}, - {.name = "T3", .offset = offsetof(vm_cpu_t, T3)}, - {.name = "T4", .offset = offsetof(vm_cpu_t, T4)}, - {.name = "T5", .offset = offsetof(vm_cpu_t, T5)}, - {.name = "T6", .offset = offsetof(vm_cpu_t, T6)}, - {.name = "T7", .offset = offsetof(vm_cpu_t, T7)}, - {.name = "S0", .offset = offsetof(vm_cpu_t, S0)}, - {.name = "S1", .offset = offsetof(vm_cpu_t, S1)}, - {.name = "S2", .offset = offsetof(vm_cpu_t, S2)}, - {.name = "S3", .offset = offsetof(vm_cpu_t, S3)}, - {.name = "S4", .offset = offsetof(vm_cpu_t, S4)}, - {.name = "S5", .offset = offsetof(vm_cpu_t, S5)}, - {.name = "S6", .offset = offsetof(vm_cpu_t, S6)}, - {.name = "S7", .offset = offsetof(vm_cpu_t, S7)}, - {.name = "T8", .offset = offsetof(vm_cpu_t, T8)}, - {.name = "T9", .offset = offsetof(vm_cpu_t, T9)}, - {.name = "K0", .offset = offsetof(vm_cpu_t, K0)}, - {.name = "K1", .offset = offsetof(vm_cpu_t, K1)}, - {.name = "GP", .offset = offsetof(vm_cpu_t, GP)}, - {.name = "SP", .offset = offsetof(vm_cpu_t, SP)}, - {.name = "FP", .offset = offsetof(vm_cpu_t, FP)}, - {.name = "RA", .offset = offsetof(vm_cpu_t, RA)}, - {.name = "PC", .offset = offsetof(vm_cpu_t, PC)}, - {.name = "PC_FETCH", .offset = offsetof(vm_cpu_t, PC_FETCH)}, - {.name = "R_LO", .offset = offsetof(vm_cpu_t, R_LO)}, - {.name = "R_HI", .offset = offsetof(vm_cpu_t, R_HI)}, +reg_dict gpreg_dict[] = { {.name = "ZERO", .offset = offsetof(vm_cpu_t, ZERO), .size = 32}, + {.name = "AT", .offset = offsetof(vm_cpu_t, AT), .size = 32}, + {.name = "V0", .offset = offsetof(vm_cpu_t, V0), .size = 32}, + {.name = "V1", .offset = offsetof(vm_cpu_t, V1), .size = 32}, + {.name = "A0", .offset = offsetof(vm_cpu_t, A0), .size = 32}, + {.name = "A1", .offset = offsetof(vm_cpu_t, A1), .size = 32}, + {.name = "A2", .offset = offsetof(vm_cpu_t, A2), .size = 32}, + {.name = "A3", .offset = offsetof(vm_cpu_t, A3), .size = 32}, + {.name = "T0", .offset = offsetof(vm_cpu_t, T0), .size = 32}, + {.name = "T1", .offset = offsetof(vm_cpu_t, T1), .size = 32}, + {.name = "T2", .offset = offsetof(vm_cpu_t, T2), .size = 32}, + {.name = "T3", .offset = offsetof(vm_cpu_t, T3), .size = 32}, + {.name = "T4", .offset = offsetof(vm_cpu_t, T4), .size = 32}, + {.name = "T5", .offset = offsetof(vm_cpu_t, T5), .size = 32}, + {.name = "T6", .offset = offsetof(vm_cpu_t, T6), .size = 32}, + {.name = "T7", .offset = offsetof(vm_cpu_t, T7), .size = 32}, + {.name = "S0", .offset = offsetof(vm_cpu_t, S0), .size = 32}, + {.name = "S1", .offset = offsetof(vm_cpu_t, S1), .size = 32}, + {.name = "S2", .offset = offsetof(vm_cpu_t, S2), .size = 32}, + {.name = "S3", .offset = offsetof(vm_cpu_t, S3), .size = 32}, + {.name = "S4", .offset = offsetof(vm_cpu_t, S4), .size = 32}, + {.name = "S5", .offset = offsetof(vm_cpu_t, S5), .size = 32}, + {.name = "S6", .offset = offsetof(vm_cpu_t, S6), .size = 32}, + {.name = "S7", .offset = offsetof(vm_cpu_t, S7), .size = 32}, + {.name = "T8", .offset = offsetof(vm_cpu_t, T8), .size = 32}, + {.name = "T9", .offset = offsetof(vm_cpu_t, T9), .size = 32}, + {.name = "K0", .offset = offsetof(vm_cpu_t, K0), .size = 32}, + {.name = "K1", .offset = offsetof(vm_cpu_t, K1), .size = 32}, + {.name = "GP", .offset = offsetof(vm_cpu_t, GP), .size = 32}, + {.name = "SP", .offset = offsetof(vm_cpu_t, SP), .size = 32}, + {.name = "FP", .offset = offsetof(vm_cpu_t, FP), .size = 32}, + {.name = "RA", .offset = offsetof(vm_cpu_t, RA), .size = 32}, + {.name = "PC", .offset = offsetof(vm_cpu_t, PC), .size = 32}, + {.name = "PC_FETCH", .offset = offsetof(vm_cpu_t, PC_FETCH), .size = 32}, + {.name = "R_LO", .offset = offsetof(vm_cpu_t, R_LO), .size = 32}, + {.name = "R_HI", .offset = offsetof(vm_cpu_t, R_HI), .size = 32}, }; /************************** JitCpu object **************************/ diff --git a/miasm2/jitter/arch/JitCore_ppc32.c b/miasm2/jitter/arch/JitCore_ppc32.c index 3acf769a..dfc46c91 100644 --- a/miasm2/jitter/arch/JitCore_ppc32.c +++ b/miasm2/jitter/arch/JitCore_ppc32.c @@ -11,7 +11,7 @@ reg_dict gpreg_dict[] = { #define JITCORE_PPC_REG_EXPAND(_name, _size) \ - { .name = #_name, .offset = offsetof(struct vm_cpu, _name) }, + { .name = #_name, .offset = offsetof(struct vm_cpu, _name), .size = _size }, #include "JitCore_ppc32_regs.h" #undef JITCORE_PPC_REG_EXPAND }; diff --git a/miasm2/jitter/arch/JitCore_x86.c b/miasm2/jitter/arch/JitCore_x86.c index b8d8270d..1782c5ae 100644 --- a/miasm2/jitter/arch/JitCore_x86.c +++ b/miasm2/jitter/arch/JitCore_x86.c @@ -12,72 +12,73 @@ vm_cpu_t ref_arch_regs; -reg_dict gpreg_dict[] = { {.name = "RAX", .offset = offsetof(vm_cpu_t, RAX), .size = 8*sizeof(ref_arch_regs.RAX)}, - {.name = "RBX", .offset = offsetof(vm_cpu_t, RBX), .size = 8*sizeof(ref_arch_regs.RBX)}, - {.name = "RCX", .offset = offsetof(vm_cpu_t, RCX), .size = 8*sizeof(ref_arch_regs.RCX)}, - {.name = "RDX", .offset = offsetof(vm_cpu_t, RDX), .size = 8*sizeof(ref_arch_regs.RDX)}, - {.name = "RSI", .offset = offsetof(vm_cpu_t, RSI), .size = 8*sizeof(ref_arch_regs.RSI)}, - {.name = "RDI", .offset = offsetof(vm_cpu_t, RDI), .size = 8*sizeof(ref_arch_regs.RDI)}, - {.name = "RSP", .offset = offsetof(vm_cpu_t, RSP), .size = 8*sizeof(ref_arch_regs.RSP)}, - {.name = "RBP", .offset = offsetof(vm_cpu_t, RBP), .size = 8*sizeof(ref_arch_regs.RBP)}, - - {.name = "R8", .offset = offsetof(vm_cpu_t, R8), .size = 8*sizeof(ref_arch_regs.R8)}, - {.name = "R9", .offset = offsetof(vm_cpu_t, R9), .size = 8*sizeof(ref_arch_regs.R9)}, - {.name = "R10", .offset = offsetof(vm_cpu_t, R10), .size = 8*sizeof(ref_arch_regs.R10)}, - {.name = "R11", .offset = offsetof(vm_cpu_t, R11), .size = 8*sizeof(ref_arch_regs.R11)}, - {.name = "R12", .offset = offsetof(vm_cpu_t, R12), .size = 8*sizeof(ref_arch_regs.R12)}, - {.name = "R13", .offset = offsetof(vm_cpu_t, R13), .size = 8*sizeof(ref_arch_regs.R13)}, - {.name = "R14", .offset = offsetof(vm_cpu_t, R14), .size = 8*sizeof(ref_arch_regs.R14)}, - {.name = "R15", .offset = offsetof(vm_cpu_t, R15), .size = 8*sizeof(ref_arch_regs.R15)}, - - {.name = "RIP", .offset = offsetof(vm_cpu_t, RIP), .size = 8*sizeof(ref_arch_regs.RIP)}, - - {.name = "zf", .offset = offsetof(vm_cpu_t, zf), .size = 8*sizeof(ref_arch_regs.zf)}, - {.name = "nf", .offset = offsetof(vm_cpu_t, nf), .size = 8*sizeof(ref_arch_regs.nf)}, - {.name = "pf", .offset = offsetof(vm_cpu_t, pf), .size = 8*sizeof(ref_arch_regs.pf)}, - {.name = "of", .offset = offsetof(vm_cpu_t, of), .size = 8*sizeof(ref_arch_regs.of)}, - {.name = "cf", .offset = offsetof(vm_cpu_t, cf), .size = 8*sizeof(ref_arch_regs.cf)}, - {.name = "af", .offset = offsetof(vm_cpu_t, af), .size = 8*sizeof(ref_arch_regs.af)}, - {.name = "df", .offset = offsetof(vm_cpu_t, df), .size = 8*sizeof(ref_arch_regs.df)}, - - {.name = "ES", .offset = offsetof(vm_cpu_t, ES), .size = 8*sizeof(ref_arch_regs.ES)}, - {.name = "CS", .offset = offsetof(vm_cpu_t, CS), .size = 8*sizeof(ref_arch_regs.CS)}, - {.name = "SS", .offset = offsetof(vm_cpu_t, SS), .size = 8*sizeof(ref_arch_regs.SS)}, - {.name = "DS", .offset = offsetof(vm_cpu_t, DS), .size = 8*sizeof(ref_arch_regs.DS)}, - {.name = "FS", .offset = offsetof(vm_cpu_t, FS), .size = 8*sizeof(ref_arch_regs.FS)}, - {.name = "GS", .offset = offsetof(vm_cpu_t, GS), .size = 8*sizeof(ref_arch_regs.GS)}, - - {.name = "MM0", .offset = offsetof(vm_cpu_t, MM0), .size = 8*sizeof(ref_arch_regs.MM0)}, - {.name = "MM1", .offset = offsetof(vm_cpu_t, MM1), .size = 8*sizeof(ref_arch_regs.MM1)}, - {.name = "MM2", .offset = offsetof(vm_cpu_t, MM2), .size = 8*sizeof(ref_arch_regs.MM2)}, - {.name = "MM3", .offset = offsetof(vm_cpu_t, MM3), .size = 8*sizeof(ref_arch_regs.MM3)}, - {.name = "MM4", .offset = offsetof(vm_cpu_t, MM4), .size = 8*sizeof(ref_arch_regs.MM4)}, - {.name = "MM5", .offset = offsetof(vm_cpu_t, MM5), .size = 8*sizeof(ref_arch_regs.MM5)}, - {.name = "MM6", .offset = offsetof(vm_cpu_t, MM6), .size = 8*sizeof(ref_arch_regs.MM6)}, - {.name = "MM7", .offset = offsetof(vm_cpu_t, MM7), .size = 8*sizeof(ref_arch_regs.MM7)}, - - {.name = "XMM0", .offset = offsetof(vm_cpu_t, XMM0), .size = 128}, - {.name = "XMM1", .offset = offsetof(vm_cpu_t, XMM1), .size = 128}, - {.name = "XMM2", .offset = offsetof(vm_cpu_t, XMM2), .size = 128}, - {.name = "XMM3", .offset = offsetof(vm_cpu_t, XMM3), .size = 128}, - {.name = "XMM4", .offset = offsetof(vm_cpu_t, XMM4), .size = 128}, - {.name = "XMM5", .offset = offsetof(vm_cpu_t, XMM5), .size = 128}, - {.name = "XMM6", .offset = offsetof(vm_cpu_t, XMM6), .size = 128}, - {.name = "XMM7", .offset = offsetof(vm_cpu_t, XMM7), .size = 128}, - {.name = "XMM8", .offset = offsetof(vm_cpu_t, XMM8), .size = 128}, - {.name = "XMM9", .offset = offsetof(vm_cpu_t, XMM9), .size = 128}, - {.name = "XMM10", .offset = offsetof(vm_cpu_t, XMM10), .size = 128}, - {.name = "XMM11", .offset = offsetof(vm_cpu_t, XMM11), .size = 128}, - {.name = "XMM12", .offset = offsetof(vm_cpu_t, XMM12), .size = 128}, - {.name = "XMM13", .offset = offsetof(vm_cpu_t, XMM13), .size = 128}, - {.name = "XMM14", .offset = offsetof(vm_cpu_t, XMM14), .size = 128}, - {.name = "XMM15", .offset = offsetof(vm_cpu_t, XMM15), .size = 128}, - - {.name = "tsc1", .offset = offsetof(vm_cpu_t, tsc1), .size = 8*sizeof(ref_arch_regs.tsc1)}, - {.name = "tsc2", .offset = offsetof(vm_cpu_t, tsc2), .size = 8*sizeof(ref_arch_regs.tsc2)}, - - {.name = "exception_flags", .offset = offsetof(vm_cpu_t, exception_flags), .size = 8*sizeof(ref_arch_regs.exception_flags)}, - {.name = "interrupt_num", .offset = offsetof(vm_cpu_t, interrupt_num), .size = 8*sizeof(ref_arch_regs.interrupt_num)}, +reg_dict gpreg_dict[] = { + {.name = "RAX", .offset = offsetof(vm_cpu_t, RAX), .size = 64}, + {.name = "RBX", .offset = offsetof(vm_cpu_t, RBX), .size = 64}, + {.name = "RCX", .offset = offsetof(vm_cpu_t, RCX), .size = 64}, + {.name = "RDX", .offset = offsetof(vm_cpu_t, RDX), .size = 64}, + {.name = "RSI", .offset = offsetof(vm_cpu_t, RSI), .size = 64}, + {.name = "RDI", .offset = offsetof(vm_cpu_t, RDI), .size = 64}, + {.name = "RSP", .offset = offsetof(vm_cpu_t, RSP), .size = 64}, + {.name = "RBP", .offset = offsetof(vm_cpu_t, RBP), .size = 64}, + + {.name = "R8", .offset = offsetof(vm_cpu_t, R8), .size = 64}, + {.name = "R9", .offset = offsetof(vm_cpu_t, R9), .size = 64}, + {.name = "R10", .offset = offsetof(vm_cpu_t, R10), .size = 64}, + {.name = "R11", .offset = offsetof(vm_cpu_t, R11), .size = 64}, + {.name = "R12", .offset = offsetof(vm_cpu_t, R12), .size = 64}, + {.name = "R13", .offset = offsetof(vm_cpu_t, R13), .size = 64}, + {.name = "R14", .offset = offsetof(vm_cpu_t, R14), .size = 64}, + {.name = "R15", .offset = offsetof(vm_cpu_t, R15), .size = 64}, + + {.name = "RIP", .offset = offsetof(vm_cpu_t, RIP), .size = 64}, + + {.name = "zf", .offset = offsetof(vm_cpu_t, zf), .size = 8}, + {.name = "nf", .offset = offsetof(vm_cpu_t, nf), .size = 8}, + {.name = "pf", .offset = offsetof(vm_cpu_t, pf), .size = 8}, + {.name = "of", .offset = offsetof(vm_cpu_t, of), .size = 8}, + {.name = "cf", .offset = offsetof(vm_cpu_t, cf), .size = 8}, + {.name = "af", .offset = offsetof(vm_cpu_t, af), .size = 8}, + {.name = "df", .offset = offsetof(vm_cpu_t, df), .size = 8}, + + {.name = "ES", .offset = offsetof(vm_cpu_t, ES), .size = 16}, + {.name = "CS", .offset = offsetof(vm_cpu_t, CS), .size = 16}, + {.name = "SS", .offset = offsetof(vm_cpu_t, SS), .size = 16}, + {.name = "DS", .offset = offsetof(vm_cpu_t, DS), .size = 16}, + {.name = "FS", .offset = offsetof(vm_cpu_t, FS), .size = 16}, + {.name = "GS", .offset = offsetof(vm_cpu_t, GS), .size = 16}, + + {.name = "MM0", .offset = offsetof(vm_cpu_t, MM0), .size = 64}, + {.name = "MM1", .offset = offsetof(vm_cpu_t, MM1), .size = 64}, + {.name = "MM2", .offset = offsetof(vm_cpu_t, MM2), .size = 64}, + {.name = "MM3", .offset = offsetof(vm_cpu_t, MM3), .size = 64}, + {.name = "MM4", .offset = offsetof(vm_cpu_t, MM4), .size = 64}, + {.name = "MM5", .offset = offsetof(vm_cpu_t, MM5), .size = 64}, + {.name = "MM6", .offset = offsetof(vm_cpu_t, MM6), .size = 64}, + {.name = "MM7", .offset = offsetof(vm_cpu_t, MM7), .size = 64}, + + {.name = "XMM0", .offset = offsetof(vm_cpu_t, XMM0), .size = 128}, + {.name = "XMM1", .offset = offsetof(vm_cpu_t, XMM1), .size = 128}, + {.name = "XMM2", .offset = offsetof(vm_cpu_t, XMM2), .size = 128}, + {.name = "XMM3", .offset = offsetof(vm_cpu_t, XMM3), .size = 128}, + {.name = "XMM4", .offset = offsetof(vm_cpu_t, XMM4), .size = 128}, + {.name = "XMM5", .offset = offsetof(vm_cpu_t, XMM5), .size = 128}, + {.name = "XMM6", .offset = offsetof(vm_cpu_t, XMM6), .size = 128}, + {.name = "XMM7", .offset = offsetof(vm_cpu_t, XMM7), .size = 128}, + {.name = "XMM8", .offset = offsetof(vm_cpu_t, XMM8), .size = 128}, + {.name = "XMM9", .offset = offsetof(vm_cpu_t, XMM9), .size = 128}, + {.name = "XMM10", .offset = offsetof(vm_cpu_t, XMM10), .size = 128}, + {.name = "XMM11", .offset = offsetof(vm_cpu_t, XMM11), .size = 128}, + {.name = "XMM12", .offset = offsetof(vm_cpu_t, XMM12), .size = 128}, + {.name = "XMM13", .offset = offsetof(vm_cpu_t, XMM13), .size = 128}, + {.name = "XMM14", .offset = offsetof(vm_cpu_t, XMM14), .size = 128}, + {.name = "XMM15", .offset = offsetof(vm_cpu_t, XMM15), .size = 128}, + + {.name = "tsc1", .offset = offsetof(vm_cpu_t, tsc1), .size = 32}, + {.name = "tsc2", .offset = offsetof(vm_cpu_t, tsc2), .size = 32}, + + {.name = "exception_flags", .offset = offsetof(vm_cpu_t, exception_flags), .size = 32}, + {.name = "interrupt_num", .offset = offsetof(vm_cpu_t, interrupt_num), .size = 32}, }; @@ -138,22 +139,22 @@ PyObject* cpu_get_gpreg(JitCpu* self) get_reg(MM6); get_reg(MM7); - get_reg_bn(XMM0); - get_reg_bn(XMM1); - get_reg_bn(XMM2); - get_reg_bn(XMM3); - get_reg_bn(XMM4); - get_reg_bn(XMM5); - get_reg_bn(XMM6); - get_reg_bn(XMM7); - get_reg_bn(XMM8); - get_reg_bn(XMM9); - get_reg_bn(XMM10); - get_reg_bn(XMM11); - get_reg_bn(XMM12); - get_reg_bn(XMM13); - get_reg_bn(XMM14); - get_reg_bn(XMM15); + get_reg_bn(XMM0, 128); + get_reg_bn(XMM1, 128); + get_reg_bn(XMM2, 128); + get_reg_bn(XMM3, 128); + get_reg_bn(XMM4, 128); + get_reg_bn(XMM5, 128); + get_reg_bn(XMM6, 128); + get_reg_bn(XMM7, 128); + get_reg_bn(XMM8, 128); + get_reg_bn(XMM9, 128); + get_reg_bn(XMM10, 128); + get_reg_bn(XMM11, 128); + get_reg_bn(XMM12, 128); + get_reg_bn(XMM13, 128); + get_reg_bn(XMM14, 128); + get_reg_bn(XMM15, 128); get_reg(tsc1); get_reg(tsc2); @@ -220,6 +221,7 @@ PyObject* cpu_set_gpreg(JitCpu* self, PyObject *args) py_long = PyLong_FromLong((long)tmp); } else if (PyLong_Check(py_long)){ /* Already PyLong */ + /* Increment ref as we will decement it next */ Py_INCREF(py_long); } else{ @@ -227,7 +229,6 @@ PyObject* cpu_set_gpreg(JitCpu* self, PyObject *args) } - cst_ffffffff = PyLong_FromLong(0xffffffff); cst_32 = PyLong_FromLong(32); bn = bignum_from_int(0); @@ -246,10 +247,7 @@ PyObject* cpu_set_gpreg(JitCpu* self, PyObject *args) Py_DECREF(py_long); Py_DECREF(cst_32); Py_DECREF(cst_ffffffff); - - - - *(bn_t*)(((char*)(self->cpu)) + gpreg_dict[i].offset) = bn; + *(bn_t*)(((char*)(self->cpu)) + gpreg_dict[i].offset) = bignum_mask(bn, 128); } break; } @@ -619,22 +617,22 @@ getset_reg_u64(MM5); getset_reg_u64(MM6); getset_reg_u64(MM7); -getset_reg_bn(XMM0); -getset_reg_bn(XMM1); -getset_reg_bn(XMM2); -getset_reg_bn(XMM3); -getset_reg_bn(XMM4); -getset_reg_bn(XMM5); -getset_reg_bn(XMM6); -getset_reg_bn(XMM7); -getset_reg_bn(XMM8); -getset_reg_bn(XMM9); -getset_reg_bn(XMM10); -getset_reg_bn(XMM11); -getset_reg_bn(XMM12); -getset_reg_bn(XMM13); -getset_reg_bn(XMM14); -getset_reg_bn(XMM15); +getset_reg_bn(XMM0, 128); +getset_reg_bn(XMM1, 128); +getset_reg_bn(XMM2, 128); +getset_reg_bn(XMM3, 128); +getset_reg_bn(XMM4, 128); +getset_reg_bn(XMM5, 128); +getset_reg_bn(XMM6, 128); +getset_reg_bn(XMM7, 128); +getset_reg_bn(XMM8, 128); +getset_reg_bn(XMM9, 128); +getset_reg_bn(XMM10, 128); +getset_reg_bn(XMM11, 128); +getset_reg_bn(XMM12, 128); +getset_reg_bn(XMM13, 128); +getset_reg_bn(XMM14, 128); +getset_reg_bn(XMM15, 128); getset_reg_u32(tsc1); getset_reg_u32(tsc2); diff --git a/miasm2/jitter/bn.c b/miasm2/jitter/bn.c index 9462de2c..96e66f4d 100644 --- a/miasm2/jitter/bn.c +++ b/miasm2/jitter/bn.c @@ -615,10 +615,9 @@ bn_t bignum_mask(bn_t src, int bits) bn_t dst; bn_t mask; - mask = bignum_from_int(1); - mask = bignum_lshift(mask, bits); + mask = bignum_from_int(0); mask = bignum_dec(mask); - + mask = bignum_rshift(mask, BN_BIT_SIZE - bits); dst = bignum_and(src, mask); return dst; } diff --git a/test/arch/x86/unit/mn_getset128.py b/test/arch/x86/unit/mn_getset128.py new file mode 100644 index 00000000..a084d663 --- /dev/null +++ b/test/arch/x86/unit/mn_getset128.py @@ -0,0 +1,52 @@ +#! /usr/bin/env python2 + +import sys + +from asm_test import Asm_Test_32 + + +class Test_get_set_128(Asm_Test_32): + TXT = ''' + main: + MOVD XMM0, ESI + MOVD XMM1, EDI + PCMPEQQ XMM0, XMM1 + JZ ret + MOV EAX, 1 + + PUSH 0x11112222 + PUSH 0x33334444 + PUSH 0x55556666 + PUSH 0x77778888 + MOVAPS XMM2, XMMWORD PTR [ESP] + ADD ESP, 0x10 + ret: + RET + ''' + + def prepare(self): + val = 1 + self.myjit.cpu.ESI = 0x11223344 + self.myjit.cpu.EDI = 0x11223345 + self.myjit.cpu.XMM0 = val + + # Check 128 get / set + assert self.myjit.cpu.XMM0 == val + assert self.myjit.cpu.get_gpreg()['XMM0'] == val + + def check(self): + assert self.myjit.cpu.XMM0 == 0xffffffffffffffff0000000000000000L + assert self.myjit.cpu.XMM1 == 0x11223345 + + # Check 128 get / set + assert self.myjit.cpu.get_gpreg()['XMM0'] == 0xffffffffffffffff0000000000000000L + assert self.myjit.cpu.get_gpreg()['XMM1'] == 0x11223345 + + assert self.myjit.cpu.get_gpreg()['XMM2'] == 0x11112222333344445555666677778888L + assert self.myjit.cpu.get_gpreg()['XMM2'] == 0x11112222333344445555666677778888L + + +if __name__ == "__main__": + [test(*sys.argv[1:])() for test in [ + Test_get_set_128, + ]] diff --git a/test/arch/x86/unit/mn_pcmpeq.py b/test/arch/x86/unit/mn_pcmpeq.py index 22760db4..e934d6b5 100755 --- a/test/arch/x86/unit/mn_pcmpeq.py +++ b/test/arch/x86/unit/mn_pcmpeq.py @@ -4,6 +4,7 @@ import sys from asm_test import Asm_Test_32 + class Test_PCMPEQB(Asm_Test_32): TXT = ''' main: @@ -42,7 +43,6 @@ class Test_PCMPEQW(Asm_Test_32): assert self.myjit.cpu.MM1 == 0xFFFF0000FFFF0000 - class Test_PCMPEQD(Asm_Test_32): TXT = ''' main: @@ -62,5 +62,33 @@ class Test_PCMPEQD(Asm_Test_32): assert self.myjit.cpu.MM1 == 0x00000000FFFFFFFF +class Test_PCMPEQQ(Asm_Test_32): + TXT = ''' + main: + MOVD XMM0, ESI + MOVD XMM1, EDI + PCMPEQQ XMM0, XMM1 + JZ ret + MOV EAX, 1 + ret: + RET + ''' + + def prepare(self): + val = 1 + self.myjit.cpu.ESI = 0x11223344 + self.myjit.cpu.EDI = 0x11223345 + self.myjit.cpu.XMM0 = val + + def check(self): + assert self.myjit.cpu.XMM0 == 0xffffffffffffffff0000000000000000L + assert self.myjit.cpu.XMM1 == 0x11223345 + + if __name__ == "__main__": - [test(*sys.argv[1:])() for test in [Test_PCMPEQB, Test_PCMPEQW, Test_PCMPEQD]] + [test(*sys.argv[1:])() for test in [ + Test_PCMPEQB, + Test_PCMPEQW, + Test_PCMPEQD, + Test_PCMPEQQ, + ]] diff --git a/test/test_all.py b/test/test_all.py index d1ccb19f..77dd04cf 100755 --- a/test/test_all.py +++ b/test/test_all.py @@ -88,6 +88,7 @@ for script in ["x86/sem.py", "x86/unit/mn_cpuid.py", "x86/unit/mn_div.py", "x86/unit/test_asm_x86_64.py", + "x86/unit/mn_getset128.py", "arm/arch.py", "arm/sem.py", "aarch64/unit/mn_ubfm.py", |