diff options
| author | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2019-03-26 15:12:03 +0100 |
|---|---|---|
| committer | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2019-03-27 12:30:46 +0100 |
| commit | 183c3e35a699bddd776bdc04f795dd3ffb608ad2 (patch) | |
| tree | aa535ae60d9b69ffc51f4004f6100b059c65aa11 | |
| parent | aa4f5dee5b94fbf14e49063f762892e1cbcdcd29 (diff) | |
| download | miasm-183c3e35a699bddd776bdc04f795dd3ffb608ad2.tar.gz miasm-183c3e35a699bddd776bdc04f795dd3ffb608ad2.zip | |
Jitter: fix vm_cpu typedef
| -rw-r--r-- | miasm/jitter/JitCore.h | 36 | ||||
| -rw-r--r-- | miasm/jitter/Jitllvm.c | 2 | ||||
| -rw-r--r-- | miasm/jitter/arch/JitCore_aarch64.c | 98 | ||||
| -rw-r--r-- | miasm/jitter/arch/JitCore_aarch64.h | 6 | ||||
| -rw-r--r-- | miasm/jitter/arch/JitCore_arm.c | 76 | ||||
| -rw-r--r-- | miasm/jitter/arch/JitCore_arm.h | 6 | ||||
| -rw-r--r-- | miasm/jitter/arch/JitCore_mep.c | 128 | ||||
| -rw-r--r-- | miasm/jitter/arch/JitCore_mep.h | 6 | ||||
| -rw-r--r-- | miasm/jitter/arch/JitCore_mips32.c | 86 | ||||
| -rw-r--r-- | miasm/jitter/arch/JitCore_mips32.h | 6 | ||||
| -rw-r--r-- | miasm/jitter/arch/JitCore_msp430.c | 70 | ||||
| -rw-r--r-- | miasm/jitter/arch/JitCore_msp430.h | 6 | ||||
| -rw-r--r-- | miasm/jitter/arch/JitCore_ppc32.h | 2 | ||||
| -rw-r--r-- | miasm/jitter/arch/JitCore_x86.c | 178 | ||||
| -rw-r--r-- | miasm/jitter/arch/JitCore_x86.h | 8 | ||||
| -rw-r--r-- | miasm/jitter/codegen.py | 2 | ||||
| -rwxr-xr-x | test/ir/ir2C.py | 2 |
17 files changed, 359 insertions, 359 deletions
diff --git a/miasm/jitter/JitCore.h b/miasm/jitter/JitCore.h index 92572fa3..85be57da 100644 --- a/miasm/jitter/JitCore.h +++ b/miasm/jitter/JitCore.h @@ -33,7 +33,7 @@ uint64_t tmp; \ py_long = PyLong_FromLong(0); \ cst_32 = PyLong_FromLong(32); \ - bn = ((vm_cpu_t*)(self->cpu))-> regname; \ + bn = (self->cpu)->regname; \ 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)); \ @@ -78,7 +78,7 @@ bn = bignum_or(bn, bignum_lshift(bignum_from_uint64(tmp), 8 * j)); \ } \ \ - ((vm_cpu_t*)(self->cpu))-> regname = bignum_mask(bn, (size)); \ + (self->cpu)->regname = bignum_mask(bn, (size)); \ Py_DECREF(py_long); \ Py_DECREF(cst_32); \ Py_DECREF(cst_ffffffff); \ @@ -99,7 +99,7 @@ uint64_t tmp; \ py_long = PyLong_FromLong(0); \ cst_32 = PyLong_FromLong(32); \ - bn = ((vm_cpu_t*)(self->cpu))-> regname; \ + bn = (self->cpu)->regname; \ 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)); \ @@ -149,7 +149,7 @@ bn = bignum_or(bn, bignum_lshift(bignum_from_uint64(tmp), 8 * j)); \ } \ \ - ((vm_cpu_t*)(self->cpu))-> regname = bignum_mask(bn, (size)); \ + self->cpu->regname = bignum_mask(bn, (size)); \ Py_DECREF(py_long); \ Py_DECREF(cst_32); \ Py_DECREF(cst_ffffffff); \ @@ -170,26 +170,26 @@ #define getset_reg_u64(regname) \ static PyObject *JitCpu_get_ ## regname (JitCpu *self, void *closure) \ { \ - return PyLong_FromUnsignedLongLong((((vm_cpu_t*)(self->cpu))-> regname )); \ + return PyLong_FromUnsignedLongLong(self->cpu->regname); \ } \ static int JitCpu_set_ ## regname (JitCpu *self, PyObject *value, void *closure) \ { \ uint64_t val; \ PyGetInt_uint64_t_retneg(value, val); \ - ((vm_cpu_t*)(self->cpu))-> regname = val; \ + self->cpu->regname = val; \ return 0; \ } #define getset_reg_u32(regname) \ static PyObject *JitCpu_get_ ## regname (JitCpu *self, void *closure) \ { \ - return PyLong_FromUnsignedLongLong((((vm_cpu_t*)(self->cpu))-> regname )); \ + return PyLong_FromUnsignedLongLong(self->cpu->regname); \ } \ static int JitCpu_set_ ## regname (JitCpu *self, PyObject *value, void *closure) \ { \ uint32_t val; \ PyGetInt_uint32_t_retneg(value, val); \ - ((vm_cpu_t*)(self->cpu))-> regname = val; \ + self->cpu->regname = val; \ return 0; \ } @@ -197,13 +197,13 @@ #define getset_reg_u16(regname) \ static PyObject *JitCpu_get_ ## regname (JitCpu *self, void *closure) \ { \ - return PyLong_FromUnsignedLongLong((((vm_cpu_t*)(self->cpu))-> regname )); \ + return PyLong_FromUnsignedLongLong(self->cpu->regname); \ } \ static int JitCpu_set_ ## regname (JitCpu *self, PyObject *value, void *closure) \ { \ uint16_t val; \ PyGetInt_uint16_t_retneg(value, val); \ - ((vm_cpu_t*)(self->cpu))-> regname = val; \ + self->cpu->regname = val; \ return 0; \ } @@ -211,19 +211,19 @@ #define getset_reg_u8(regname) \ static PyObject *JitCpu_get_ ## regname (JitCpu *self, void *closure) \ { \ - return PyLong_FromUnsignedLongLong((((vm_cpu_t*)(self->cpu))-> regname )); \ + return PyLong_FromUnsignedLongLong(self->cpu->regname); \ } \ static int JitCpu_set_ ## regname (JitCpu *self, PyObject *value, void *closure) \ { \ uint8_t val; \ PyGetInt_uint8_t_retneg(value, val); \ - ((vm_cpu_t*)(self->cpu))-> regname = val; \ + self->cpu->regname = val; \ return 0; \ } #define get_reg(reg) do { \ - o = PyLong_FromUnsignedLongLong((uint64_t)((vm_cpu_t*)(self->cpu))->reg); \ + o = PyLong_FromUnsignedLongLong((uint64_t)self->cpu->reg); \ PyDict_SetItemString(dict, #reg, o); \ Py_DECREF(o); \ } while(0); @@ -239,7 +239,7 @@ uint64_t tmp; \ py_long = PyLong_FromLong(0); \ cst_32 = PyLong_FromLong(32); \ - bn = ((vm_cpu_t*)(self->cpu))-> reg; \ + bn = self->cpu->reg; \ 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)); \ @@ -257,7 +257,7 @@ #define get_reg_off(reg) do { \ - o = PyLong_FromUnsignedLongLong((uint64_t)offsetof(vm_cpu_t, reg)); \ + o = PyLong_FromUnsignedLongLong((uint64_t)offsetof(struct vm_cpu, reg)); \ PyDict_SetItemString(dict, #reg, o); \ Py_DECREF(o); \ } while(0); @@ -270,11 +270,13 @@ typedef struct { uint64_t address; } block_id; +struct vm_cpu; + typedef struct { PyObject_HEAD VmMngr *pyvm; PyObject *jitter; - void* cpu; + struct vm_cpu *cpu; } JitCpu; @@ -321,7 +323,7 @@ _MIASM_EXPORT void MEM_WRITE_INT_BN_FROM_PTR(JitCpu* jitcpu, int size, uint64_t #define VM_exception_flag (jitcpu->pyvm->vm_mngr.exception_flags) -#define CPU_exception_flag (((vm_cpu_t*)jitcpu->cpu)->exception_flags) +#define CPU_exception_flag (((struct vm_cpu*)jitcpu->cpu)->exception_flags) #define CPU_exception_flag_at_instr ((CPU_exception_flag) && ((CPU_exception_flag) > EXCEPT_NUM_UPDT_EIP)) #define JIT_RET_EXCEPTION 1 #define JIT_RET_NO_EXCEPTION 0 diff --git a/miasm/jitter/Jitllvm.c b/miasm/jitter/Jitllvm.c index b42bff89..7617954b 100644 --- a/miasm/jitter/Jitllvm.c +++ b/miasm/jitter/Jitllvm.c @@ -15,7 +15,7 @@ PyObject* llvm_exec_block(PyObject* self, PyObject* args) { uint64_t (*func)(void*, void*, void*, uint8_t*); - vm_cpu_t* cpu; + struct vm_cpu* cpu; vm_mngr_t* vm; uint64_t ret; JitCpu* jitcpu; diff --git a/miasm/jitter/arch/JitCore_aarch64.c b/miasm/jitter/arch/JitCore_aarch64.c index 9878a4ff..e1b5e645 100644 --- a/miasm/jitter/arch/JitCore_aarch64.c +++ b/miasm/jitter/arch/JitCore_aarch64.c @@ -14,48 +14,48 @@ reg_dict gpreg_dict[] = { - {.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}, + {.name = "X0", .offset = offsetof(struct vm_cpu, X0), .size = 64}, + {.name = "X1", .offset = offsetof(struct vm_cpu, X1), .size = 64}, + {.name = "X2", .offset = offsetof(struct vm_cpu, X2), .size = 64}, + {.name = "X3", .offset = offsetof(struct vm_cpu, X3), .size = 64}, + {.name = "X4", .offset = offsetof(struct vm_cpu, X4), .size = 64}, + {.name = "X5", .offset = offsetof(struct vm_cpu, X5), .size = 64}, + {.name = "X6", .offset = offsetof(struct vm_cpu, X6), .size = 64}, + {.name = "X7", .offset = offsetof(struct vm_cpu, X7), .size = 64}, + {.name = "X8", .offset = offsetof(struct vm_cpu, X8), .size = 64}, + {.name = "X9", .offset = offsetof(struct vm_cpu, X9), .size = 64}, + {.name = "X10", .offset = offsetof(struct vm_cpu, X10), .size = 64}, + {.name = "X11", .offset = offsetof(struct vm_cpu, X11), .size = 64}, + {.name = "X12", .offset = offsetof(struct vm_cpu, X12), .size = 64}, + {.name = "X13", .offset = offsetof(struct vm_cpu, X13), .size = 64}, + {.name = "X14", .offset = offsetof(struct vm_cpu, X14), .size = 64}, + {.name = "X15", .offset = offsetof(struct vm_cpu, X15), .size = 64}, + {.name = "X16", .offset = offsetof(struct vm_cpu, X16), .size = 64}, + {.name = "X17", .offset = offsetof(struct vm_cpu, X17), .size = 64}, + {.name = "X18", .offset = offsetof(struct vm_cpu, X18), .size = 64}, + {.name = "X19", .offset = offsetof(struct vm_cpu, X19), .size = 64}, + {.name = "X20", .offset = offsetof(struct vm_cpu, X20), .size = 64}, + {.name = "X21", .offset = offsetof(struct vm_cpu, X21), .size = 64}, + {.name = "X22", .offset = offsetof(struct vm_cpu, X22), .size = 64}, + {.name = "X23", .offset = offsetof(struct vm_cpu, X23), .size = 64}, + {.name = "X24", .offset = offsetof(struct vm_cpu, X24), .size = 64}, + {.name = "X25", .offset = offsetof(struct vm_cpu, X25), .size = 64}, + {.name = "X26", .offset = offsetof(struct vm_cpu, X26), .size = 64}, + {.name = "X27", .offset = offsetof(struct vm_cpu, X27), .size = 64}, + {.name = "X28", .offset = offsetof(struct vm_cpu, X28), .size = 64}, + {.name = "X29", .offset = offsetof(struct vm_cpu, X29), .size = 64}, + {.name = "LR", .offset = offsetof(struct vm_cpu, LR), .size = 64}, + + {.name = "SP", .offset = offsetof(struct vm_cpu, SP), .size = 64}, + {.name = "PC", .offset = offsetof(struct vm_cpu, PC), .size = 64}, + + {.name = "zf", .offset = offsetof(struct vm_cpu, zf), .size = 8}, + {.name = "nf", .offset = offsetof(struct vm_cpu, nf), .size = 8}, + {.name = "of", .offset = offsetof(struct vm_cpu, of), .size = 8}, + {.name = "cf", .offset = offsetof(struct vm_cpu, cf), .size = 8}, + + {.name = "exception_flags", .offset = offsetof(struct vm_cpu, exception_flags), .size = 32}, + {.name = "interrupt_num", .offset = offsetof(struct vm_cpu, interrupt_num), .size = 32}, }; @@ -161,13 +161,13 @@ PyObject* cpu_set_gpreg(JitCpu* self, PyObject *args) PyObject * cpu_init_regs(JitCpu* self) { - memset(self->cpu, 0, sizeof(vm_cpu_t)); + memset(self->cpu, 0, sizeof(struct vm_cpu)); Py_INCREF(Py_None); return Py_None; } -void dump_gpregs(vm_cpu_t* vmcpu) +void dump_gpregs(struct vm_cpu* vmcpu) { printf("X0 %.16"PRIX64" X1 %.16"PRIX64" X2 %.16"PRIX64" X3 %.16"PRIX64" "\ "X4 %.16"PRIX64" X5 %.16"PRIX64" X6 %.16"PRIX64" X7 %.16"PRIX64"\n", @@ -195,7 +195,7 @@ void dump_gpregs(vm_cpu_t* vmcpu) PyObject * cpu_dump_gpregs(JitCpu* self, PyObject* args) { - vm_cpu_t* vmcpu; + struct vm_cpu* vmcpu; vmcpu = self->cpu; dump_gpregs(vmcpu); @@ -220,14 +220,14 @@ PyObject* cpu_set_exception(JitCpu* self, PyObject* args) PyGetInt_uint32_t(item1, exception_flags); - ((vm_cpu_t*)self->cpu)->exception_flags = exception_flags; + ((struct vm_cpu*)self->cpu)->exception_flags = exception_flags; Py_INCREF(Py_None); return Py_None; } PyObject* cpu_get_exception(JitCpu* self, PyObject* args) { - return PyLong_FromUnsignedLongLong((uint64_t)(((vm_cpu_t*)self->cpu)->exception_flags)); + return PyLong_FromUnsignedLongLong((uint64_t)(((struct vm_cpu*)self->cpu)->exception_flags)); } @@ -330,9 +330,9 @@ static PyMethodDef JitCpu_methods[] = { static int JitCpu_init(JitCpu *self, PyObject *args, PyObject *kwds) { - self->cpu = malloc(sizeof(vm_cpu_t)); + self->cpu = malloc(sizeof(struct vm_cpu)); if (self->cpu == NULL) { - fprintf(stderr, "cannot alloc vm_cpu_t\n"); + fprintf(stderr, "cannot alloc struct vm_cpu\n"); exit(EXIT_FAILURE); } return 0; diff --git a/miasm/jitter/arch/JitCore_aarch64.h b/miasm/jitter/arch/JitCore_aarch64.h index fa958244..975a93ec 100644 --- a/miasm/jitter/arch/JitCore_aarch64.h +++ b/miasm/jitter/arch/JitCore_aarch64.h @@ -1,5 +1,5 @@ -typedef struct { +struct vm_cpu { uint32_t exception_flags; uint32_t interrupt_num; @@ -45,9 +45,9 @@ typedef struct { uint32_t nf; uint32_t of; uint32_t cf; -}vm_cpu_t; +}; -_MIASM_EXPORT void dump_gpregs(vm_cpu_t* vmcpu); +_MIASM_EXPORT void dump_gpregs(struct vm_cpu* vmcpu); _MIASM_EXPORT void MEM_WRITE_08(JitCpu* jitcpu, uint64_t addr, uint8_t src); _MIASM_EXPORT void MEM_WRITE_16(JitCpu* jitcpu, uint64_t addr, uint16_t src); diff --git a/miasm/jitter/arch/JitCore_arm.c b/miasm/jitter/arch/JitCore_arm.c index 25595274..823b0f0c 100644 --- a/miasm/jitter/arch/JitCore_arm.c +++ b/miasm/jitter/arch/JitCore_arm.c @@ -14,35 +14,35 @@ 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}, + {.name = "R0", .offset = offsetof(struct vm_cpu, R0), .size = 32}, + {.name = "R1", .offset = offsetof(struct vm_cpu, R1), .size = 32}, + {.name = "R2", .offset = offsetof(struct vm_cpu, R2), .size = 32}, + {.name = "R3", .offset = offsetof(struct vm_cpu, R3), .size = 32}, + {.name = "R4", .offset = offsetof(struct vm_cpu, R4), .size = 32}, + {.name = "R5", .offset = offsetof(struct vm_cpu, R5), .size = 32}, + {.name = "R6", .offset = offsetof(struct vm_cpu, R6), .size = 32}, + {.name = "R7", .offset = offsetof(struct vm_cpu, R7), .size = 32}, + {.name = "R8", .offset = offsetof(struct vm_cpu, R8), .size = 32}, + {.name = "R9", .offset = offsetof(struct vm_cpu, R9), .size = 32}, + {.name = "R10", .offset = offsetof(struct vm_cpu, R10), .size = 32}, + {.name = "R11", .offset = offsetof(struct vm_cpu, R11), .size = 32}, + {.name = "R12", .offset = offsetof(struct vm_cpu, R12), .size = 32}, + {.name = "SP", .offset = offsetof(struct vm_cpu, SP), .size = 32}, + {.name = "LR", .offset = offsetof(struct vm_cpu, LR), .size = 32}, + {.name = "PC", .offset = offsetof(struct vm_cpu, PC), .size = 32}, + + {.name = "zf", .offset = offsetof(struct vm_cpu, zf), .size = 8}, + {.name = "nf", .offset = offsetof(struct vm_cpu, nf), .size = 8}, + {.name = "of", .offset = offsetof(struct vm_cpu, of), .size = 8}, + {.name = "cf", .offset = offsetof(struct vm_cpu, cf), .size = 8}, + + {.name = "ge0", .offset = offsetof(struct vm_cpu, ge0), .size = 8}, + {.name = "ge1", .offset = offsetof(struct vm_cpu, ge1), .size = 8}, + {.name = "ge2", .offset = offsetof(struct vm_cpu, ge2), .size = 8}, + {.name = "ge3", .offset = offsetof(struct vm_cpu, ge3), .size = 8}, + + {.name = "exception_flags", .offset = offsetof(struct vm_cpu, exception_flags), .size = 32}, + {.name = "interrupt_num", .offset = offsetof(struct vm_cpu, interrupt_num), .size = 32}, }; /************************** JitCpu object **************************/ @@ -125,13 +125,13 @@ PyObject* cpu_set_gpreg(JitCpu* self, PyObject *args) PyObject * cpu_init_regs(JitCpu* self) { - memset(self->cpu, 0, sizeof(vm_cpu_t)); + memset(self->cpu, 0, sizeof(struct vm_cpu)); Py_INCREF(Py_None); return Py_None; } -void dump_gpregs(vm_cpu_t* vmcpu) +void dump_gpregs(struct vm_cpu* vmcpu) { printf("R0 %.8"PRIX32" R1 %.8"PRIX32" R2 %.8"PRIX32" R3 %.8"PRIX32" ", vmcpu->R0, vmcpu->R1, vmcpu->R2, vmcpu->R3); @@ -148,7 +148,7 @@ void dump_gpregs(vm_cpu_t* vmcpu) PyObject * cpu_dump_gpregs(JitCpu* self, PyObject* args) { - vm_cpu_t* vmcpu; + struct vm_cpu* vmcpu; vmcpu = self->cpu; dump_gpregs(vmcpu); @@ -174,14 +174,14 @@ PyObject* cpu_set_exception(JitCpu* self, PyObject* args) PyGetInt_uint32_t(item1, exception_flags); - ((vm_cpu_t*)self->cpu)->exception_flags = exception_flags; + ((struct vm_cpu*)self->cpu)->exception_flags = exception_flags; Py_INCREF(Py_None); return Py_None; } PyObject* cpu_get_exception(JitCpu* self, PyObject* args) { - return PyLong_FromUnsignedLongLong((uint64_t)(((vm_cpu_t*)self->cpu)->exception_flags)); + return PyLong_FromUnsignedLongLong((uint64_t)(((struct vm_cpu*)self->cpu)->exception_flags)); } @@ -264,14 +264,14 @@ PyObject* cpu_set_interrupt_num(JitCpu* self, PyObject* args) PyGetInt_uint32_t(item1, exception_flags); - ((vm_cpu_t*)self->cpu)->interrupt_num = exception_flags; + ((struct vm_cpu*)self->cpu)->interrupt_num = exception_flags; Py_INCREF(Py_None); return Py_None; } PyObject* cpu_get_interrupt_num(JitCpu* self, PyObject* args) { - return PyLong_FromUnsignedLongLong((uint64_t)(((vm_cpu_t*)self->cpu)->interrupt_num)); + return PyLong_FromUnsignedLongLong((uint64_t)(((struct vm_cpu*)self->cpu)->interrupt_num)); } static PyMemberDef JitCpu_members[] = { @@ -307,9 +307,9 @@ static PyMethodDef JitCpu_methods[] = { static int JitCpu_init(JitCpu *self, PyObject *args, PyObject *kwds) { - self->cpu = malloc(sizeof(vm_cpu_t)); + self->cpu = malloc(sizeof(struct vm_cpu)); if (self->cpu == NULL) { - fprintf(stderr, "cannot alloc vm_cpu_t\n"); + fprintf(stderr, "cannot alloc struct vm_cpu\n"); exit(EXIT_FAILURE); } return 0; diff --git a/miasm/jitter/arch/JitCore_arm.h b/miasm/jitter/arch/JitCore_arm.h index 67a1096a..30a38344 100644 --- a/miasm/jitter/arch/JitCore_arm.h +++ b/miasm/jitter/arch/JitCore_arm.h @@ -1,5 +1,5 @@ -typedef struct { +struct vm_cpu { uint32_t exception_flags; uint32_t interrupt_num; @@ -34,10 +34,10 @@ typedef struct { uint32_t ge3; uint32_t bp_num; -}vm_cpu_t; +}; -_MIASM_EXPORT void dump_gpregs(vm_cpu_t* vmcpu); +_MIASM_EXPORT void dump_gpregs(struct vm_cpu* vmcpu); _MIASM_EXPORT void MEM_WRITE_08(JitCpu* jitcpu, uint64_t addr, uint8_t src); _MIASM_EXPORT void MEM_WRITE_16(JitCpu* jitcpu, uint64_t addr, uint16_t src); diff --git a/miasm/jitter/arch/JitCore_mep.c b/miasm/jitter/arch/JitCore_mep.c index 969bae27..ebbd6d11 100644 --- a/miasm/jitter/arch/JitCore_mep.c +++ b/miasm/jitter/arch/JitCore_mep.c @@ -15,63 +15,63 @@ 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 = "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}, + {.name = "R0", .offset = offsetof(struct vm_cpu, R0), .size = 32}, + {.name = "R1", .offset = offsetof(struct vm_cpu, R1), .size = 32}, + {.name = "R2", .offset = offsetof(struct vm_cpu, R2), .size = 32}, + {.name = "R3", .offset = offsetof(struct vm_cpu, R3), .size = 32}, + {.name = "R4", .offset = offsetof(struct vm_cpu, R4), .size = 32}, + {.name = "R5", .offset = offsetof(struct vm_cpu, R5), .size = 32}, + {.name = "R6", .offset = offsetof(struct vm_cpu, R6), .size = 32}, + {.name = "R7", .offset = offsetof(struct vm_cpu, R7), .size = 32}, + {.name = "R8", .offset = offsetof(struct vm_cpu, R8), .size = 32}, + {.name = "R9", .offset = offsetof(struct vm_cpu, R9), .size = 32}, + {.name = "R10", .offset = offsetof(struct vm_cpu, R10), .size = 32}, + {.name = "R11", .offset = offsetof(struct vm_cpu, R11), .size = 32}, + {.name = "R12", .offset = offsetof(struct vm_cpu, R12), .size = 32}, + {.name = "TP", .offset = offsetof(struct vm_cpu, TP), .size = 32}, + {.name = "GP", .offset = offsetof(struct vm_cpu, GP), .size = 32}, + {.name = "SP", .offset = offsetof(struct vm_cpu, SP), .size = 32}, + + {.name = "PC", .offset = offsetof(struct vm_cpu, PC), .size = 32}, + {.name = "LP", .offset = offsetof(struct vm_cpu, LP), .size = 32}, + {.name = "SAR", .offset = offsetof(struct vm_cpu, SAR), .size = 32}, + {.name = "S3", .offset = offsetof(struct vm_cpu, S3), .size = 32}, + {.name = "RPB", .offset = offsetof(struct vm_cpu, RPB), .size = 32}, + {.name = "RPE", .offset = offsetof(struct vm_cpu, RPE), .size = 32}, + {.name = "RPC", .offset = offsetof(struct vm_cpu, RPC), .size = 32}, + {.name = "HI", .offset = offsetof(struct vm_cpu, HI), .size = 32}, + {.name = "LO", .offset = offsetof(struct vm_cpu, LO), .size = 32}, + {.name = "S9", .offset = offsetof(struct vm_cpu, S9), .size = 32}, + {.name = "S10", .offset = offsetof(struct vm_cpu, S10), .size = 32}, + {.name = "S11", .offset = offsetof(struct vm_cpu, S11), .size = 32}, + {.name = "MB0", .offset = offsetof(struct vm_cpu, MB0), .size = 32}, + {.name = "ME0", .offset = offsetof(struct vm_cpu, ME0), .size = 32}, + {.name = "MB1", .offset = offsetof(struct vm_cpu, MB1), .size = 32}, + {.name = "ME1", .offset = offsetof(struct vm_cpu, ME1), .size = 32}, + {.name = "PSW", .offset = offsetof(struct vm_cpu, PSW), .size = 32}, + {.name = "ID", .offset = offsetof(struct vm_cpu, ID), .size = 32}, + {.name = "TMP", .offset = offsetof(struct vm_cpu, TMP), .size = 32}, + {.name = "EPC", .offset = offsetof(struct vm_cpu, EPC), .size = 32}, + {.name = "EXC", .offset = offsetof(struct vm_cpu, EXC), .size = 32}, + {.name = "CFG", .offset = offsetof(struct vm_cpu, CFG), .size = 32}, + {.name = "S22", .offset = offsetof(struct vm_cpu, S22), .size = 32}, + {.name = "NPC", .offset = offsetof(struct vm_cpu, NPC), .size = 32}, + {.name = "DBG", .offset = offsetof(struct vm_cpu, DBG), .size = 32}, + {.name = "DEPC", .offset = offsetof(struct vm_cpu, DEPC), .size = 32}, + {.name = "OPT", .offset = offsetof(struct vm_cpu, OPT), .size = 32}, + {.name = "RCFG", .offset = offsetof(struct vm_cpu, RCFG), .size = 32}, + {.name = "CCFG", .offset = offsetof(struct vm_cpu, CCFG), .size = 32}, + {.name = "S29", .offset = offsetof(struct vm_cpu, S29), .size = 32}, + {.name = "S30", .offset = offsetof(struct vm_cpu, S30), .size = 32}, + {.name = "S31", .offset = offsetof(struct vm_cpu, S31), .size = 32}, + {.name = "S32", .offset = offsetof(struct vm_cpu, S32), .size = 32}, + {.name = "take_jmp", .offset = offsetof(struct vm_cpu, take_jmp), .size = 32}, + {.name = "last_addr", .offset = offsetof(struct vm_cpu, last_addr), .size = 32}, + {.name = "is_repeat_end", .offset = offsetof(struct vm_cpu, is_repeat_end), .size = 32}, + + {.name = "PC_end", .offset = offsetof(struct vm_cpu, PC_end), .size = 32}, + {.name = "RPE_instr_count", .offset = offsetof(struct vm_cpu, RPE_instr_count), .size = 32}, + {.name = "RPC_current", .offset = offsetof(struct vm_cpu, RPC_current), .size = 32}, }; @@ -184,14 +184,14 @@ PyObject* cpu_set_gpreg(JitCpu* self, PyObject *args) PyObject * cpu_init_regs(JitCpu* self) { - memset(self->cpu, 0, sizeof(vm_cpu_t)); + memset(self->cpu, 0, sizeof(struct vm_cpu)); Py_INCREF(Py_None); return Py_None; } -void dump_gpregs(vm_cpu_t* vmcpu) +void dump_gpregs(struct vm_cpu* vmcpu) { printf("R0 %.4"PRIX32" ", vmcpu->R0); printf("R1 %.4"PRIX32" ", vmcpu->R1); @@ -215,7 +215,7 @@ void dump_gpregs(vm_cpu_t* vmcpu) PyObject * cpu_dump_gpregs(JitCpu* self, PyObject* args) { - vm_cpu_t* vmcpu; + struct vm_cpu* vmcpu; vmcpu = self->cpu; dump_gpregs(vmcpu); @@ -238,14 +238,14 @@ PyObject* cpu_set_exception(JitCpu* self, PyObject* args) PyGetInt_uint32_t(item1, exception_flags); - ((vm_cpu_t*)self->cpu)->exception_flags = exception_flags; + ((struct vm_cpu*)self->cpu)->exception_flags = exception_flags; Py_INCREF(Py_None); return Py_None; } PyObject* cpu_get_exception(JitCpu* self, PyObject* args) { - return PyLong_FromUnsignedLongLong((uint64_t)(((vm_cpu_t*)self->cpu)->exception_flags)); + return PyLong_FromUnsignedLongLong((uint64_t)(((struct vm_cpu*)self->cpu)->exception_flags)); } void check_automod(JitCpu* jitcpu, uint64_t addr, uint64_t size) @@ -335,9 +335,9 @@ static PyMethodDef JitCpu_methods[] = { static int JitCpu_init(JitCpu *self, PyObject *args, PyObject *kwds) { - self->cpu = malloc(sizeof(vm_cpu_t)); + self->cpu = malloc(sizeof(struct vm_cpu)); if (self->cpu == NULL) { - fprintf(stderr, "cannot alloc vm_cpu_t\n"); + fprintf(stderr, "cannot alloc struct vm_cpu\n"); exit(0); } return 0; diff --git a/miasm/jitter/arch/JitCore_mep.h b/miasm/jitter/arch/JitCore_mep.h index bcf2283e..f656b3a0 100644 --- a/miasm/jitter/arch/JitCore_mep.h +++ b/miasm/jitter/arch/JitCore_mep.h @@ -1,6 +1,6 @@ // Inspired from JitCore_msp430.h -typedef struct { +struct vm_cpu { /* miasm flags */ uint32_t exception_flags; @@ -70,9 +70,9 @@ typedef struct { /* flags */ -} vm_cpu_t; +}; -_MIASM_EXPORT void dump_gpregs(vm_cpu_t* vmcpu); +_MIASM_EXPORT void dump_gpregs(struct vm_cpu* vmcpu); _MIASM_EXPORT void MEM_WRITE_08(JitCpu* jitcpu, uint64_t addr, uint8_t src); _MIASM_EXPORT void MEM_WRITE_16(JitCpu* jitcpu, uint64_t addr, uint16_t src); diff --git a/miasm/jitter/arch/JitCore_mips32.c b/miasm/jitter/arch/JitCore_mips32.c index 1a8748cf..09f0c18b 100644 --- a/miasm/jitter/arch/JitCore_mips32.c +++ b/miasm/jitter/arch/JitCore_mips32.c @@ -13,42 +13,42 @@ -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}, +reg_dict gpreg_dict[] = { {.name = "ZERO", .offset = offsetof(struct vm_cpu, ZERO), .size = 32}, + {.name = "AT", .offset = offsetof(struct vm_cpu, AT), .size = 32}, + {.name = "V0", .offset = offsetof(struct vm_cpu, V0), .size = 32}, + {.name = "V1", .offset = offsetof(struct vm_cpu, V1), .size = 32}, + {.name = "A0", .offset = offsetof(struct vm_cpu, A0), .size = 32}, + {.name = "A1", .offset = offsetof(struct vm_cpu, A1), .size = 32}, + {.name = "A2", .offset = offsetof(struct vm_cpu, A2), .size = 32}, + {.name = "A3", .offset = offsetof(struct vm_cpu, A3), .size = 32}, + {.name = "T0", .offset = offsetof(struct vm_cpu, T0), .size = 32}, + {.name = "T1", .offset = offsetof(struct vm_cpu, T1), .size = 32}, + {.name = "T2", .offset = offsetof(struct vm_cpu, T2), .size = 32}, + {.name = "T3", .offset = offsetof(struct vm_cpu, T3), .size = 32}, + {.name = "T4", .offset = offsetof(struct vm_cpu, T4), .size = 32}, + {.name = "T5", .offset = offsetof(struct vm_cpu, T5), .size = 32}, + {.name = "T6", .offset = offsetof(struct vm_cpu, T6), .size = 32}, + {.name = "T7", .offset = offsetof(struct vm_cpu, T7), .size = 32}, + {.name = "S0", .offset = offsetof(struct vm_cpu, S0), .size = 32}, + {.name = "S1", .offset = offsetof(struct vm_cpu, S1), .size = 32}, + {.name = "S2", .offset = offsetof(struct vm_cpu, S2), .size = 32}, + {.name = "S3", .offset = offsetof(struct vm_cpu, S3), .size = 32}, + {.name = "S4", .offset = offsetof(struct vm_cpu, S4), .size = 32}, + {.name = "S5", .offset = offsetof(struct vm_cpu, S5), .size = 32}, + {.name = "S6", .offset = offsetof(struct vm_cpu, S6), .size = 32}, + {.name = "S7", .offset = offsetof(struct vm_cpu, S7), .size = 32}, + {.name = "T8", .offset = offsetof(struct vm_cpu, T8), .size = 32}, + {.name = "T9", .offset = offsetof(struct vm_cpu, T9), .size = 32}, + {.name = "K0", .offset = offsetof(struct vm_cpu, K0), .size = 32}, + {.name = "K1", .offset = offsetof(struct vm_cpu, K1), .size = 32}, + {.name = "GP", .offset = offsetof(struct vm_cpu, GP), .size = 32}, + {.name = "SP", .offset = offsetof(struct vm_cpu, SP), .size = 32}, + {.name = "FP", .offset = offsetof(struct vm_cpu, FP), .size = 32}, + {.name = "RA", .offset = offsetof(struct vm_cpu, RA), .size = 32}, + {.name = "PC", .offset = offsetof(struct vm_cpu, PC), .size = 32}, + {.name = "PC_FETCH", .offset = offsetof(struct vm_cpu, PC_FETCH), .size = 32}, + {.name = "R_LO", .offset = offsetof(struct vm_cpu, R_LO), .size = 32}, + {.name = "R_HI", .offset = offsetof(struct vm_cpu, R_HI), .size = 32}, }; /************************** JitCpu object **************************/ @@ -143,7 +143,7 @@ PyObject* cpu_set_gpreg(JitCpu* self, PyObject *args) PyObject * cpu_init_regs(JitCpu* self) { - memset(self->cpu, 0, sizeof(vm_cpu_t)); + memset(self->cpu, 0, sizeof(struct vm_cpu)); Py_INCREF(Py_None); return Py_None; @@ -151,7 +151,7 @@ PyObject * cpu_init_regs(JitCpu* self) } -void dump_gpregs(vm_cpu_t* vmcpu) +void dump_gpregs(struct vm_cpu* vmcpu) { printf("ZR %.8"PRIX32" AT %.8"PRIX32" V0 %.8"PRIX32" V1 %.8"PRIX32" ", @@ -177,7 +177,7 @@ void dump_gpregs(vm_cpu_t* vmcpu) PyObject * cpu_dump_gpregs(JitCpu* self, PyObject* args) { - vm_cpu_t* vmcpu; + struct vm_cpu* vmcpu; vmcpu = self->cpu; dump_gpregs(vmcpu); @@ -196,14 +196,14 @@ PyObject* cpu_set_exception(JitCpu* self, PyObject* args) PyGetInt_uint32_t(item1, exception_flags); - ((vm_cpu_t*)self->cpu)->exception_flags = exception_flags; + ((struct vm_cpu*)self->cpu)->exception_flags = exception_flags; Py_INCREF(Py_None); return Py_None; } PyObject* cpu_get_exception(JitCpu* self, PyObject* args) { - return PyLong_FromUnsignedLongLong((uint64_t)(((vm_cpu_t*)self->cpu)->exception_flags)); + return PyLong_FromUnsignedLongLong((uint64_t)(((struct vm_cpu*)self->cpu)->exception_flags)); } @@ -307,9 +307,9 @@ static PyMethodDef JitCpu_methods[] = { static int JitCpu_init(JitCpu *self, PyObject *args, PyObject *kwds) { - self->cpu = malloc(sizeof(vm_cpu_t)); + self->cpu = malloc(sizeof(struct vm_cpu)); if (self->cpu == NULL) { - fprintf(stderr, "cannot alloc vm_cpu_t\n"); + fprintf(stderr, "cannot alloc struct vm_cpu\n"); exit(EXIT_FAILURE); } return 0; diff --git a/miasm/jitter/arch/JitCore_mips32.h b/miasm/jitter/arch/JitCore_mips32.h index e20d5133..74eb35ef 100644 --- a/miasm/jitter/arch/JitCore_mips32.h +++ b/miasm/jitter/arch/JitCore_mips32.h @@ -1,5 +1,5 @@ -typedef struct { +struct vm_cpu { uint32_t exception_flags; /* gpregs */ @@ -331,9 +331,9 @@ typedef struct { uint32_t CPR0_253; uint32_t CPR0_254; uint32_t CPR0_255; -}vm_cpu_t; +}; -_MIASM_EXPORT void dump_gpregs(vm_cpu_t* vmcpu); +_MIASM_EXPORT void dump_gpregs(struct vm_cpu* vmcpu); _MIASM_EXPORT void MEM_WRITE_08(JitCpu* jitcpu, uint64_t addr, uint8_t src); _MIASM_EXPORT void MEM_WRITE_16(JitCpu* jitcpu, uint64_t addr, uint16_t src); diff --git a/miasm/jitter/arch/JitCore_msp430.c b/miasm/jitter/arch/JitCore_msp430.c index 5a4cae2f..b0c03208 100644 --- a/miasm/jitter/arch/JitCore_msp430.c +++ b/miasm/jitter/arch/JitCore_msp430.c @@ -11,34 +11,34 @@ #include "JitCore_msp430.h" -reg_dict gpreg_dict[] = { {.name = "PC", .offset = offsetof(vm_cpu_t, PC)}, - {.name = "SP", .offset = offsetof(vm_cpu_t, SP)}, - //{.name = "SR", .offset = offsetof(vm_cpu_t, SR)}, - {.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 = "R13", .offset = offsetof(vm_cpu_t, R13)}, - {.name = "R14", .offset = offsetof(vm_cpu_t, R14)}, - {.name = "R15", .offset = offsetof(vm_cpu_t, R15)}, - - {.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 = "cpuoff", .offset = offsetof(vm_cpu_t, zf)}, - {.name = "gie", .offset = offsetof(vm_cpu_t, zf)}, - {.name = "osc", .offset = offsetof(vm_cpu_t, zf)}, - {.name = "scg0", .offset = offsetof(vm_cpu_t, zf)}, - {.name = "scg1", .offset = offsetof(vm_cpu_t, zf)}, - {.name = "res", .offset = offsetof(vm_cpu_t, zf)}, +reg_dict gpreg_dict[] = { {.name = "PC", .offset = offsetof(struct vm_cpu, PC)}, + {.name = "SP", .offset = offsetof(struct vm_cpu, SP)}, + //{.name = "SR", .offset = offsetof(struct vm_cpu, SR)}, + {.name = "R3", .offset = offsetof(struct vm_cpu, R3)}, + {.name = "R4", .offset = offsetof(struct vm_cpu, R4)}, + {.name = "R5", .offset = offsetof(struct vm_cpu, R5)}, + {.name = "R6", .offset = offsetof(struct vm_cpu, R6)}, + {.name = "R7", .offset = offsetof(struct vm_cpu, R7)}, + {.name = "R8", .offset = offsetof(struct vm_cpu, R8)}, + {.name = "R9", .offset = offsetof(struct vm_cpu, R9)}, + {.name = "R10", .offset = offsetof(struct vm_cpu, R10)}, + {.name = "R11", .offset = offsetof(struct vm_cpu, R11)}, + {.name = "R12", .offset = offsetof(struct vm_cpu, R12)}, + {.name = "R13", .offset = offsetof(struct vm_cpu, R13)}, + {.name = "R14", .offset = offsetof(struct vm_cpu, R14)}, + {.name = "R15", .offset = offsetof(struct vm_cpu, R15)}, + + {.name = "zf", .offset = offsetof(struct vm_cpu, zf)}, + {.name = "nf", .offset = offsetof(struct vm_cpu, nf)}, + {.name = "of", .offset = offsetof(struct vm_cpu, of)}, + {.name = "cf", .offset = offsetof(struct vm_cpu, cf)}, + + {.name = "cpuoff", .offset = offsetof(struct vm_cpu, zf)}, + {.name = "gie", .offset = offsetof(struct vm_cpu, zf)}, + {.name = "osc", .offset = offsetof(struct vm_cpu, zf)}, + {.name = "scg0", .offset = offsetof(struct vm_cpu, zf)}, + {.name = "scg1", .offset = offsetof(struct vm_cpu, zf)}, + {.name = "res", .offset = offsetof(struct vm_cpu, zf)}, }; @@ -124,14 +124,14 @@ PyObject* cpu_set_gpreg(JitCpu* self, PyObject *args) PyObject * cpu_init_regs(JitCpu* self) { - memset(self->cpu, 0, sizeof(vm_cpu_t)); + memset(self->cpu, 0, sizeof(struct vm_cpu)); Py_INCREF(Py_None); return Py_None; } -void dump_gpregs(vm_cpu_t* vmcpu) +void dump_gpregs(struct vm_cpu* vmcpu) { printf("PC %.4"PRIX32" SP %.4"PRIX32" R3 %.4"PRIX32" ", @@ -149,7 +149,7 @@ void dump_gpregs(vm_cpu_t* vmcpu) PyObject * cpu_dump_gpregs(JitCpu* self, PyObject* args) { - vm_cpu_t* vmcpu; + struct vm_cpu* vmcpu; vmcpu = self->cpu; dump_gpregs(vmcpu); @@ -173,14 +173,14 @@ PyObject* cpu_set_exception(JitCpu* self, PyObject* args) PyGetInt_uint32_t(item1, exception_flags); - ((vm_cpu_t*)self->cpu)->exception_flags = exception_flags; + ((struct vm_cpu*)self->cpu)->exception_flags = exception_flags; Py_INCREF(Py_None); return Py_None; } PyObject* cpu_get_exception(JitCpu* self, PyObject* args) { - return PyLong_FromUnsignedLongLong((uint64_t)(((vm_cpu_t*)self->cpu)->exception_flags)); + return PyLong_FromUnsignedLongLong((uint64_t)(((struct vm_cpu*)self->cpu)->exception_flags)); } @@ -283,9 +283,9 @@ static PyMethodDef JitCpu_methods[] = { static int JitCpu_init(JitCpu *self, PyObject *args, PyObject *kwds) { - self->cpu = malloc(sizeof(vm_cpu_t)); + self->cpu = malloc(sizeof(struct vm_cpu)); if (self->cpu == NULL) { - fprintf(stderr, "cannot alloc vm_cpu_t\n"); + fprintf(stderr, "cannot alloc struct vm_cpu\n"); exit(EXIT_FAILURE); } return 0; diff --git a/miasm/jitter/arch/JitCore_msp430.h b/miasm/jitter/arch/JitCore_msp430.h index 1c802e9e..d7b6a7b9 100644 --- a/miasm/jitter/arch/JitCore_msp430.h +++ b/miasm/jitter/arch/JitCore_msp430.h @@ -1,5 +1,5 @@ -typedef struct { +struct vm_cpu { uint32_t exception_flags; /* gpregs */ @@ -32,11 +32,11 @@ typedef struct { uint32_t scg1; uint32_t res; -}vm_cpu_t; +}; #define RETURN_PC return BlockDst; -_MIASM_EXPORT void dump_gpregs(vm_cpu_t* vmcpu); +_MIASM_EXPORT void dump_gpregs(struct vm_cpu* vmcpu); _MIASM_EXPORT void MEM_WRITE_08(JitCpu* jitcpu, uint64_t addr, uint8_t src); _MIASM_EXPORT void MEM_WRITE_16(JitCpu* jitcpu, uint64_t addr, uint16_t src); diff --git a/miasm/jitter/arch/JitCore_ppc32.h b/miasm/jitter/arch/JitCore_ppc32.h index f2a5200e..abb04941 100644 --- a/miasm/jitter/arch/JitCore_ppc32.h +++ b/miasm/jitter/arch/JitCore_ppc32.h @@ -16,8 +16,6 @@ struct vm_cpu { _MIASM_EXPORT void dump_gpregs(struct vm_cpu *); -typedef struct vm_cpu vm_cpu_t; - _MIASM_EXPORT void MEM_WRITE_08(JitCpu* jitcpu, uint64_t addr, uint8_t src); _MIASM_EXPORT void MEM_WRITE_16(JitCpu* jitcpu, uint64_t addr, uint16_t src); _MIASM_EXPORT void MEM_WRITE_32(JitCpu* jitcpu, uint64_t addr, uint32_t src); diff --git a/miasm/jitter/arch/JitCore_x86.c b/miasm/jitter/arch/JitCore_x86.c index 3225eab5..c073f573 100644 --- a/miasm/jitter/arch/JitCore_x86.c +++ b/miasm/jitter/arch/JitCore_x86.c @@ -12,74 +12,74 @@ #include "JitCore_x86.h" -vm_cpu_t ref_arch_regs; +struct vm_cpu ref_arch_regs; 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 = "tsc", .offset = offsetof(vm_cpu_t, tsc), .size = 64}, - - {.name = "exception_flags", .offset = offsetof(vm_cpu_t, exception_flags), .size = 32}, - {.name = "interrupt_num", .offset = offsetof(vm_cpu_t, interrupt_num), .size = 32}, + {.name = "RAX", .offset = offsetof(struct vm_cpu, RAX), .size = 64}, + {.name = "RBX", .offset = offsetof(struct vm_cpu, RBX), .size = 64}, + {.name = "RCX", .offset = offsetof(struct vm_cpu, RCX), .size = 64}, + {.name = "RDX", .offset = offsetof(struct vm_cpu, RDX), .size = 64}, + {.name = "RSI", .offset = offsetof(struct vm_cpu, RSI), .size = 64}, + {.name = "RDI", .offset = offsetof(struct vm_cpu, RDI), .size = 64}, + {.name = "RSP", .offset = offsetof(struct vm_cpu, RSP), .size = 64}, + {.name = "RBP", .offset = offsetof(struct vm_cpu, RBP), .size = 64}, + + {.name = "R8", .offset = offsetof(struct vm_cpu, R8), .size = 64}, + {.name = "R9", .offset = offsetof(struct vm_cpu, R9), .size = 64}, + {.name = "R10", .offset = offsetof(struct vm_cpu, R10), .size = 64}, + {.name = "R11", .offset = offsetof(struct vm_cpu, R11), .size = 64}, + {.name = "R12", .offset = offsetof(struct vm_cpu, R12), .size = 64}, + {.name = "R13", .offset = offsetof(struct vm_cpu, R13), .size = 64}, + {.name = "R14", .offset = offsetof(struct vm_cpu, R14), .size = 64}, + {.name = "R15", .offset = offsetof(struct vm_cpu, R15), .size = 64}, + + {.name = "RIP", .offset = offsetof(struct vm_cpu, RIP), .size = 64}, + + {.name = "zf", .offset = offsetof(struct vm_cpu, zf), .size = 8}, + {.name = "nf", .offset = offsetof(struct vm_cpu, nf), .size = 8}, + {.name = "pf", .offset = offsetof(struct vm_cpu, pf), .size = 8}, + {.name = "of", .offset = offsetof(struct vm_cpu, of), .size = 8}, + {.name = "cf", .offset = offsetof(struct vm_cpu, cf), .size = 8}, + {.name = "af", .offset = offsetof(struct vm_cpu, af), .size = 8}, + {.name = "df", .offset = offsetof(struct vm_cpu, df), .size = 8}, + + {.name = "ES", .offset = offsetof(struct vm_cpu, ES), .size = 16}, + {.name = "CS", .offset = offsetof(struct vm_cpu, CS), .size = 16}, + {.name = "SS", .offset = offsetof(struct vm_cpu, SS), .size = 16}, + {.name = "DS", .offset = offsetof(struct vm_cpu, DS), .size = 16}, + {.name = "FS", .offset = offsetof(struct vm_cpu, FS), .size = 16}, + {.name = "GS", .offset = offsetof(struct vm_cpu, GS), .size = 16}, + + {.name = "MM0", .offset = offsetof(struct vm_cpu, MM0), .size = 64}, + {.name = "MM1", .offset = offsetof(struct vm_cpu, MM1), .size = 64}, + {.name = "MM2", .offset = offsetof(struct vm_cpu, MM2), .size = 64}, + {.name = "MM3", .offset = offsetof(struct vm_cpu, MM3), .size = 64}, + {.name = "MM4", .offset = offsetof(struct vm_cpu, MM4), .size = 64}, + {.name = "MM5", .offset = offsetof(struct vm_cpu, MM5), .size = 64}, + {.name = "MM6", .offset = offsetof(struct vm_cpu, MM6), .size = 64}, + {.name = "MM7", .offset = offsetof(struct vm_cpu, MM7), .size = 64}, + + {.name = "XMM0", .offset = offsetof(struct vm_cpu, XMM0), .size = 128}, + {.name = "XMM1", .offset = offsetof(struct vm_cpu, XMM1), .size = 128}, + {.name = "XMM2", .offset = offsetof(struct vm_cpu, XMM2), .size = 128}, + {.name = "XMM3", .offset = offsetof(struct vm_cpu, XMM3), .size = 128}, + {.name = "XMM4", .offset = offsetof(struct vm_cpu, XMM4), .size = 128}, + {.name = "XMM5", .offset = offsetof(struct vm_cpu, XMM5), .size = 128}, + {.name = "XMM6", .offset = offsetof(struct vm_cpu, XMM6), .size = 128}, + {.name = "XMM7", .offset = offsetof(struct vm_cpu, XMM7), .size = 128}, + {.name = "XMM8", .offset = offsetof(struct vm_cpu, XMM8), .size = 128}, + {.name = "XMM9", .offset = offsetof(struct vm_cpu, XMM9), .size = 128}, + {.name = "XMM10", .offset = offsetof(struct vm_cpu, XMM10), .size = 128}, + {.name = "XMM11", .offset = offsetof(struct vm_cpu, XMM11), .size = 128}, + {.name = "XMM12", .offset = offsetof(struct vm_cpu, XMM12), .size = 128}, + {.name = "XMM13", .offset = offsetof(struct vm_cpu, XMM13), .size = 128}, + {.name = "XMM14", .offset = offsetof(struct vm_cpu, XMM14), .size = 128}, + {.name = "XMM15", .offset = offsetof(struct vm_cpu, XMM15), .size = 128}, + + {.name = "tsc", .offset = offsetof(struct vm_cpu, tsc), .size = 64}, + + {.name = "exception_flags", .offset = offsetof(struct vm_cpu, exception_flags), .size = 32}, + {.name = "interrupt_num", .offset = offsetof(struct vm_cpu, interrupt_num), .size = 32}, }; @@ -277,15 +277,15 @@ PyObject* cpu_set_gpreg(JitCpu* self, PyObject *args) PyObject * cpu_init_regs(JitCpu* self) { - memset(self->cpu, 0, sizeof(vm_cpu_t)); - ((vm_cpu_t*)self->cpu)->tsc = 0x1122334455667788ULL; - ((vm_cpu_t*)self->cpu)->i_f = 1; + memset(self->cpu, 0, sizeof(struct vm_cpu)); + ((struct vm_cpu*)self->cpu)->tsc = 0x1122334455667788ULL; + ((struct vm_cpu*)self->cpu)->i_f = 1; Py_INCREF(Py_None); return Py_None; } -void dump_gpregs_16(vm_cpu_t* vmcpu) +void dump_gpregs_16(struct vm_cpu* vmcpu) { printf("EAX %.8"PRIX32" EBX %.8"PRIX32" ECX %.8"PRIX32" EDX %.8"PRIX32" ", (uint32_t)(vmcpu->RAX & 0xFFFFFFFF), @@ -306,7 +306,7 @@ void dump_gpregs_16(vm_cpu_t* vmcpu) (uint32_t)(vmcpu->cf & 0x1)); } -void dump_gpregs_32(vm_cpu_t* vmcpu) +void dump_gpregs_32(struct vm_cpu* vmcpu) { printf("EAX %.8"PRIX32" EBX %.8"PRIX32" ECX %.8"PRIX32" EDX %.8"PRIX32" ", @@ -329,7 +329,7 @@ void dump_gpregs_32(vm_cpu_t* vmcpu) } -void dump_gpregs_64(vm_cpu_t* vmcpu) +void dump_gpregs_64(struct vm_cpu* vmcpu) { printf("RAX %.16"PRIX64" RBX %.16"PRIX64" RCX %.16"PRIX64" RDX %.16"PRIX64" ", @@ -351,7 +351,7 @@ void dump_gpregs_64(vm_cpu_t* vmcpu) PyObject * cpu_dump_gpregs(JitCpu* self, PyObject* args) { - vm_cpu_t* vmcpu; + struct vm_cpu* vmcpu; vmcpu = self->cpu; dump_gpregs_64(vmcpu); @@ -362,7 +362,7 @@ PyObject * cpu_dump_gpregs(JitCpu* self, PyObject* args) PyObject * cpu_dump_gpregs_with_attrib(JitCpu* self, PyObject* args) { - vm_cpu_t* vmcpu; + struct vm_cpu* vmcpu; PyObject *item1; uint64_t attrib; @@ -396,14 +396,14 @@ PyObject* cpu_set_exception(JitCpu* self, PyObject* args) PyGetInt_uint32_t(item1, exception_flags); - ((vm_cpu_t*)self->cpu)->exception_flags = exception_flags; + ((struct vm_cpu*)self->cpu)->exception_flags = exception_flags; Py_INCREF(Py_None); return Py_None; } PyObject* cpu_get_exception(JitCpu* self, PyObject* args) { - return PyLong_FromUnsignedLongLong((uint64_t)(((vm_cpu_t*)self->cpu)->exception_flags)); + return PyLong_FromUnsignedLongLong((uint64_t)(((struct vm_cpu*)self->cpu)->exception_flags)); } PyObject* cpu_set_interrupt_num(JitCpu* self, PyObject* args) @@ -416,14 +416,14 @@ PyObject* cpu_set_interrupt_num(JitCpu* self, PyObject* args) PyGetInt_uint32_t(item1, exception_flags); - ((vm_cpu_t*)self->cpu)->interrupt_num = exception_flags; + ((struct vm_cpu*)self->cpu)->interrupt_num = exception_flags; Py_INCREF(Py_None); return Py_None; } PyObject* cpu_get_interrupt_num(JitCpu* self, PyObject* args) { - return PyLong_FromUnsignedLongLong((uint64_t)(((vm_cpu_t*)self->cpu)->interrupt_num)); + return PyLong_FromUnsignedLongLong((uint64_t)(((struct vm_cpu*)self->cpu)->interrupt_num)); } PyObject* cpu_set_segm_base(JitCpu* self, PyObject* args) @@ -436,7 +436,7 @@ PyObject* cpu_set_segm_base(JitCpu* self, PyObject* args) PyGetInt_uint64_t(item1, segm_num); PyGetInt_uint64_t(item2, segm_base); - ((vm_cpu_t*)self->cpu)->segm_base[segm_num] = segm_base; + ((struct vm_cpu*)self->cpu)->segm_base[segm_num] = segm_base; Py_INCREF(Py_None); return Py_None; @@ -451,13 +451,13 @@ PyObject* cpu_get_segm_base(JitCpu* self, PyObject* args) if (!PyArg_ParseTuple(args, "O", &item1)) RAISE(PyExc_TypeError,"Cannot parse arguments"); PyGetInt_uint64_t(item1, segm_num); - v = PyLong_FromLong((long)(((vm_cpu_t*)self->cpu)->segm_base[segm_num])); + v = PyLong_FromLong((long)(((struct vm_cpu*)self->cpu)->segm_base[segm_num])); return v; } uint64_t segm2addr(JitCpu* jitcpu, uint64_t segm, uint64_t addr) { - return addr + ((vm_cpu_t*)jitcpu->cpu)->segm_base[segm]; + return addr + ((struct vm_cpu*)jitcpu->cpu)->segm_base[segm]; } void MEM_WRITE_08(JitCpu* jitcpu, uint64_t addr, uint8_t src) @@ -549,9 +549,9 @@ static PyMethodDef JitCpu_methods[] = { static int JitCpu_init(JitCpu *self, PyObject *args, PyObject *kwds) { - self->cpu = malloc(sizeof(vm_cpu_t)); + self->cpu = malloc(sizeof(struct vm_cpu)); if (self->cpu == NULL) { - fprintf(stderr, "cannot alloc vm_cpu_t\n"); + fprintf(stderr, "cannot alloc struct vm_cpu\n"); exit(EXIT_FAILURE); } return 0; @@ -560,15 +560,15 @@ JitCpu_init(JitCpu *self, PyObject *args, PyObject *kwds) #define getset_reg_E_u32(regname) \ static PyObject *JitCpu_get_E ## regname (JitCpu *self, void *closure) \ { \ - return PyLong_FromUnsignedLongLong((uint32_t)(((vm_cpu_t*)(self->cpu))->R ## regname & 0xFFFFFFFF )); \ + return PyLong_FromUnsignedLongLong((uint32_t)(self->cpu->R ## regname & 0xFFFFFFFF )); \ } \ static int JitCpu_set_E ## regname (JitCpu *self, PyObject *value, void *closure) \ { \ uint64_t val; \ PyGetInt_uint64_t_retneg(value, val); \ val &= 0xFFFFFFFF; \ - val |= ((vm_cpu_t*)(self->cpu))->R ##regname & 0xFFFFFFFF00000000ULL; \ - ((vm_cpu_t*)(self->cpu))->R ## regname = val; \ + val |= self->cpu->R ##regname & 0xFFFFFFFF00000000ULL; \ + self->cpu->R ## regname = val; \ return 0; \ } @@ -577,15 +577,15 @@ JitCpu_init(JitCpu *self, PyObject *args, PyObject *kwds) #define getset_reg_R_u16(regname) \ static PyObject *JitCpu_get_ ## regname (JitCpu *self, void *closure) \ { \ - return PyLong_FromUnsignedLongLong((uint16_t)(((vm_cpu_t*)(self->cpu))->R ## regname & 0xFFFF )); \ + return PyLong_FromUnsignedLongLong((uint16_t)(self->cpu->R ## regname & 0xFFFF )); \ } \ static int JitCpu_set_ ## regname (JitCpu *self, PyObject *value, void *closure) \ { \ uint64_t val; \ PyGetInt_uint64_t_retneg(value, val); \ val &= 0xFFFF; \ - val |= ((vm_cpu_t*)(self->cpu))->R ##regname & 0xFFFFFFFFFFFF0000ULL; \ - ((vm_cpu_t*)(self->cpu))->R ## regname = val; \ + val |= self->cpu->R ##regname & 0xFFFFFFFFFFFF0000ULL; \ + self->cpu->R ## regname = val; \ return 0; \ } diff --git a/miasm/jitter/arch/JitCore_x86.h b/miasm/jitter/arch/JitCore_x86.h index b03fa959..5c005e86 100644 --- a/miasm/jitter/arch/JitCore_x86.h +++ b/miasm/jitter/arch/JitCore_x86.h @@ -6,7 +6,7 @@ #define _MIASM_EXPORT #endif -typedef struct { +struct vm_cpu { uint32_t exception_flags; uint32_t interrupt_num; @@ -122,10 +122,10 @@ typedef struct { uint64_t segm_base[0x10000]; -}vm_cpu_t; +}; -_MIASM_EXPORT void dump_gpregs_32(vm_cpu_t* vmcpu); -_MIASM_EXPORT void dump_gpregs_64(vm_cpu_t* vmcpu); +_MIASM_EXPORT void dump_gpregs_32(struct vm_cpu* vmcpu); +_MIASM_EXPORT void dump_gpregs_64(struct vm_cpu* vmcpu); _MIASM_EXPORT uint64_t segm2addr(JitCpu* jitcpu, uint64_t segm, uint64_t addr); _MIASM_EXPORT void MEM_WRITE_08(JitCpu* jitcpu, uint64_t addr, uint8_t src); diff --git a/miasm/jitter/codegen.py b/miasm/jitter/codegen.py index 0f40fb6e..792feae0 100644 --- a/miasm/jitter/codegen.py +++ b/miasm/jitter/codegen.py @@ -97,7 +97,7 @@ class CGen(object): CODE_INIT = r""" int DST_case; uint64_t DST_value; - vm_cpu_t* mycpu = (vm_cpu_t*)jitcpu->cpu; + struct vm_cpu *mycpu = jitcpu->cpu; goto %s; """ diff --git a/test/ir/ir2C.py b/test/ir/ir2C.py index c41c98c9..61c1bbfd 100755 --- a/test/ir/ir2C.py +++ b/test/ir/ir2C.py @@ -49,7 +49,7 @@ class TestIrIr2C(unittest.TestCase): self.translationTest( ExprOp('segm', *args[:2]), r'segm2addr(jitcpu, 0x0, 0x1)') self.translationTest( - ExprOp('imod', *args[:2]), r'imod32((vm_cpu_t*)jitcpu->cpu, 0x0, 0x1)') + ExprOp('imod', *args[:2]), r'imod32((struct vm_cpu*)jitcpu->cpu, 0x0, 0x1)') self.translationTest( ExprOp('bcdadd', *args[:2]), r'bcdadd_32(0x0, 0x1)') self.assertRaises(NotImplementedError, translator.from_expr, |