Miasm2
 All Classes Namespaces Files Functions Variables Typedefs Properties Macros
JitCore_mips32.c
Go to the documentation of this file.
1 #include <Python.h>
2 #include "../JitCore.h"
3 #include "structmember.h"
4 #include <stdint.h>
5 #include <inttypes.h>
6 #include "../queue.h"
7 #include "../vm_mngr.h"
8 #include "../vm_mngr_py.h"
9 #include "JitCore_mips32.h"
10 
11 
12 
13 reg_dict gpreg_dict[] = { {.name = "ZERO", .offset = offsetof(vm_cpu_t, ZERO)},
14  {.name = "AT", .offset = offsetof(vm_cpu_t, AT)},
15  {.name = "V0", .offset = offsetof(vm_cpu_t, V0)},
16  {.name = "V1", .offset = offsetof(vm_cpu_t, V1)},
17  {.name = "A0", .offset = offsetof(vm_cpu_t, A0)},
18  {.name = "A1", .offset = offsetof(vm_cpu_t, A1)},
19  {.name = "A2", .offset = offsetof(vm_cpu_t, A2)},
20  {.name = "A3", .offset = offsetof(vm_cpu_t, A3)},
21  {.name = "T0", .offset = offsetof(vm_cpu_t, T0)},
22  {.name = "T1", .offset = offsetof(vm_cpu_t, T1)},
23  {.name = "T2", .offset = offsetof(vm_cpu_t, T2)},
24  {.name = "T3", .offset = offsetof(vm_cpu_t, T3)},
25  {.name = "T4", .offset = offsetof(vm_cpu_t, T4)},
26  {.name = "T5", .offset = offsetof(vm_cpu_t, T5)},
27  {.name = "T6", .offset = offsetof(vm_cpu_t, T6)},
28  {.name = "T7", .offset = offsetof(vm_cpu_t, T7)},
29  {.name = "S0", .offset = offsetof(vm_cpu_t, S0)},
30  {.name = "S1", .offset = offsetof(vm_cpu_t, S1)},
31  {.name = "S2", .offset = offsetof(vm_cpu_t, S2)},
32  {.name = "S3", .offset = offsetof(vm_cpu_t, S3)},
33  {.name = "S4", .offset = offsetof(vm_cpu_t, S4)},
34  {.name = "S5", .offset = offsetof(vm_cpu_t, S5)},
35  {.name = "S6", .offset = offsetof(vm_cpu_t, S6)},
36  {.name = "S7", .offset = offsetof(vm_cpu_t, S7)},
37  {.name = "T8", .offset = offsetof(vm_cpu_t, T8)},
38  {.name = "T9", .offset = offsetof(vm_cpu_t, T9)},
39  {.name = "K0", .offset = offsetof(vm_cpu_t, K0)},
40  {.name = "K1", .offset = offsetof(vm_cpu_t, K1)},
41  {.name = "GP", .offset = offsetof(vm_cpu_t, GP)},
42  {.name = "SP", .offset = offsetof(vm_cpu_t, SP)},
43  {.name = "FP", .offset = offsetof(vm_cpu_t, FP)},
44  {.name = "RA", .offset = offsetof(vm_cpu_t, RA)},
45  {.name = "PC", .offset = offsetof(vm_cpu_t, PC)},
46  {.name = "PC_FETCH", .offset = offsetof(vm_cpu_t, PC_FETCH)},
47  {.name = "R_LO", .offset = offsetof(vm_cpu_t, R_LO)},
48  {.name = "R_HI", .offset = offsetof(vm_cpu_t, R_HI)},
49 };
50 
51 /************************** JitCpu object **************************/
52 
53 
54 
55 PyObject* cpu_get_gpreg(JitCpu* self)
56 {
57  PyObject *dict = PyDict_New();
58  PyObject *o;
59 
60  get_reg(ZERO);
61  get_reg(AT);
62  get_reg(V0);
63  get_reg(V1);
64  get_reg(A0);
65  get_reg(A1);
66  get_reg(A2);
67  get_reg(A3);
68  get_reg(T0);
69  get_reg(T1);
70  get_reg(T2);
71  get_reg(T3);
72  get_reg(T4);
73  get_reg(T5);
74  get_reg(T6);
75  get_reg(T7);
76  get_reg(S0);
77  get_reg(S1);
78  get_reg(S2);
79  get_reg(S3);
80  get_reg(S4);
81  get_reg(S5);
82  get_reg(S6);
83  get_reg(S7);
84  get_reg(T8);
85  get_reg(T9);
86  get_reg(K0);
87  get_reg(K1);
88  get_reg(GP);
89  get_reg(SP);
90  get_reg(FP);
91  get_reg(RA);
92  get_reg(PC);
93  get_reg(PC_FETCH);
94  get_reg(R_LO);
95  get_reg(R_HI);
96 
97  return dict;
98 }
99 
100 
101 
102 
103 PyObject* cpu_set_gpreg(JitCpu* self, PyObject *args)
104 {
105  PyObject* dict;
106  PyObject *d_key, *d_value = NULL;
107  Py_ssize_t pos = 0;
108  uint64_t val;
109  unsigned int i, found;
110 
111  if (!PyArg_ParseTuple(args, "O", &dict))
112  return NULL;
113  if(!PyDict_Check(dict))
114  RAISE(PyExc_TypeError, "arg must be dict");
115  while(PyDict_Next(dict, &pos, &d_key, &d_value)){
116  if(!PyString_Check(d_key))
117  RAISE(PyExc_TypeError, "key must be str");
118 
119  PyGetInt(d_value, val);
120 
121  found = 0;
122  for (i=0; i < sizeof(gpreg_dict)/sizeof(reg_dict); i++){
123  if (strcmp(PyString_AsString(d_key), gpreg_dict[i].name))
124  continue;
125  *((uint32_t*)(((char*)(self->cpu)) + gpreg_dict[i].offset)) = val;
126  found = 1;
127  break;
128  }
129 
130  if (found)
131  continue;
132  fprintf(stderr, "unkown key: %s\n", PyString_AsString(d_key));
133  RAISE(PyExc_ValueError, "unkown reg");
134  }
135  Py_INCREF(Py_None);
136  return Py_None;
137 }
138 
139 
140 
141 
142 PyObject * cpu_init_regs(JitCpu* self)
143 {
144  memset(self->cpu, 0, sizeof(vm_cpu_t));
145 
146  Py_INCREF(Py_None);
147  return Py_None;
148 
149 }
150 
151 
152 void dump_gpregs(vm_cpu_t* vmcpu)
153 {
154 
155  printf("ZR %.8"PRIX32" AT %.8"PRIX32" V0 %.8"PRIX32" V1 %.8"PRIX32" ",
156  vmcpu->ZERO, vmcpu->AT, vmcpu->V0, vmcpu->V1);
157  printf("A0 %.8"PRIX32" A1 %.8"PRIX32" A2 %.8"PRIX32" A3 %.8"PRIX32" ",
158  vmcpu->A0, vmcpu->A1, vmcpu->A2, vmcpu->A3);
159  printf("T0 %.8"PRIX32" T1 %.8"PRIX32" T2 %.8"PRIX32" T3 %.8"PRIX32" ",
160  vmcpu->T0, vmcpu->T1, vmcpu->T2, vmcpu->T3);
161  printf("T4 %.8"PRIX32" T5 %.8"PRIX32" T6 %.8"PRIX32" T7 %.8"PRIX32"\n",
162  vmcpu->T4, vmcpu->T5, vmcpu->T6, vmcpu->T7);
163  printf("S0 %.8"PRIX32" S1 %.8"PRIX32" S2 %.8"PRIX32" S3 %.8"PRIX32" ",
164  vmcpu->S0, vmcpu->S1, vmcpu->S2, vmcpu->S3);
165  printf("S4 %.8"PRIX32" S5 %.8"PRIX32" S6 %.8"PRIX32" S7 %.8"PRIX32" ",
166  vmcpu->S4, vmcpu->S5, vmcpu->S6, vmcpu->S7);
167  printf("T8 %.8"PRIX32" T9 %.8"PRIX32" K0 %.8"PRIX32" K1 %.8"PRIX32" ",
168  vmcpu->T8, vmcpu->T9, vmcpu->K0, vmcpu->K1);
169  printf("GP %.8"PRIX32" SP %.8"PRIX32" FP %.8"PRIX32" RA %.8"PRIX32"\n",
170  vmcpu->GP, vmcpu->SP, vmcpu->FP, vmcpu->RA);
171  printf("PC %.8"PRIX32"\n",
172  vmcpu->PC);
173 }
174 
175 
176 PyObject * cpu_dump_gpregs(JitCpu* self, PyObject* args)
177 {
178  vm_cpu_t* vmcpu;
179 
180  vmcpu = self->cpu;
181  dump_gpregs(vmcpu);
182  Py_INCREF(Py_None);
183  return Py_None;
184 }
185 
186 
187 PyObject* cpu_set_exception(JitCpu* self, PyObject* args)
188 {
189  PyObject *item1;
190  uint64_t i;
191 
192  if (!PyArg_ParseTuple(args, "O", &item1))
193  return NULL;
194 
195  PyGetInt(item1, i);
196 
197  ((vm_cpu_t*)self->cpu)->exception_flags = i;
198  Py_INCREF(Py_None);
199  return Py_None;
200 }
201 
202 PyObject* cpu_get_exception(JitCpu* self, PyObject* args)
203 {
204  return PyLong_FromUnsignedLongLong((uint64_t)(((vm_cpu_t*)self->cpu)->exception_flags));
205 }
206 
207 
208 
209 
210 
211 
212 void check_automod(JitCpu* jitcpu, uint64_t addr, uint64_t size)
213 {
214  PyObject *result;
215 
216  if (!(((VmMngr*)jitcpu->pyvm)->vm_mngr.exception_flags & EXCEPT_CODE_AUTOMOD))
217  return;
218  result = PyObject_CallMethod(jitcpu->jitter, "automod_cb", "LL", addr, size);
219  Py_DECREF(result);
220 
221 }
222 
223 void MEM_WRITE_08(JitCpu* jitcpu, uint64_t addr, uint8_t src)
224 {
225  vm_MEM_WRITE_08(&((VmMngr*)jitcpu->pyvm)->vm_mngr, addr, src);
226  check_automod(jitcpu, addr, 8);
227 }
228 
229 void MEM_WRITE_16(JitCpu* jitcpu, uint64_t addr, uint16_t src)
230 {
231  vm_MEM_WRITE_16(&((VmMngr*)jitcpu->pyvm)->vm_mngr, addr, src);
232  check_automod(jitcpu, addr, 16);
233 }
234 
235 void MEM_WRITE_32(JitCpu* jitcpu, uint64_t addr, uint32_t src)
236 {
237  vm_MEM_WRITE_32(&((VmMngr*)jitcpu->pyvm)->vm_mngr, addr, src);
238  check_automod(jitcpu, addr, 32);
239 }
240 
241 void MEM_WRITE_64(JitCpu* jitcpu, uint64_t addr, uint64_t src)
242 {
243  vm_MEM_WRITE_64(&((VmMngr*)jitcpu->pyvm)->vm_mngr, addr, src);
244  check_automod(jitcpu, addr, 64);
245 }
246 
247 
248 PyObject* vm_set_mem(JitCpu *self, PyObject* args)
249 {
250  PyObject *py_addr;
251  PyObject *py_buffer;
252  Py_ssize_t py_length;
253 
254  char * buffer;
255  uint64_t size;
256  uint64_t addr;
257  int ret = 0x1337;
258 
259  if (!PyArg_ParseTuple(args, "OO", &py_addr, &py_buffer))
260  return NULL;
261 
262  PyGetInt(py_addr, addr);
263 
264  if(!PyString_Check(py_buffer))
265  RAISE(PyExc_TypeError,"arg must be str");
266 
267  size = PyString_Size(py_buffer);
268  PyString_AsStringAndSize(py_buffer, &buffer, &py_length);
269 
270  ret = vm_write_mem(&(((VmMngr*)self->pyvm)->vm_mngr), addr, buffer, size);
271  if (ret < 0)
272  RAISE(PyExc_TypeError,"arg must be str");
273  check_automod(self, addr, size*8);
274 
275  Py_INCREF(Py_None);
276  return Py_None;
277 }
278 
279 static PyMemberDef JitCpu_members[] = {
280  {NULL} /* Sentinel */
281 };
282 
283 static PyMethodDef JitCpu_methods[] = {
284  {"init_regs", (PyCFunction)cpu_init_regs, METH_NOARGS,
285  "X"},
286  {"dump_gpregs", (PyCFunction)cpu_dump_gpregs, METH_NOARGS,
287  "X"},
288  {"get_gpreg", (PyCFunction)cpu_get_gpreg, METH_NOARGS,
289  "X"},
290  {"set_gpreg", (PyCFunction)cpu_set_gpreg, METH_VARARGS,
291  "X"},
292  {"get_exception", (PyCFunction)cpu_get_exception, METH_VARARGS,
293  "X"},
294  {"set_exception", (PyCFunction)cpu_set_exception, METH_VARARGS,
295  "X"},
296  {"set_mem", (PyCFunction)vm_set_mem, METH_VARARGS,
297  "X"},
298  {"get_mem", (PyCFunction)vm_get_mem, METH_VARARGS,
299  "X"},
300  {NULL} /* Sentinel */
301 };
302 
303 
304 static int
305 JitCpu_init(JitCpu *self, PyObject *args, PyObject *kwds)
306 {
307  self->cpu = malloc(sizeof(vm_cpu_t));
308  if (self->cpu == NULL) {
309  fprintf(stderr, "cannot alloc vm_cpu_t\n");
310  exit(0);
311  }
312  return 0;
313 }
314 
315 getset_reg_u32(ZERO);
316 getset_reg_u32(AT);
317 getset_reg_u32(V0);
318 getset_reg_u32(V1);
319 getset_reg_u32(A0);
320 getset_reg_u32(A1);
321 getset_reg_u32(A2);
322 getset_reg_u32(A3);
323 getset_reg_u32(T0);
324 getset_reg_u32(T1);
325 getset_reg_u32(T2);
326 getset_reg_u32(T3);
327 getset_reg_u32(T4);
328 getset_reg_u32(T5);
329 getset_reg_u32(T6);
330 getset_reg_u32(T7);
331 getset_reg_u32(S0);
332 getset_reg_u32(S1);
333 getset_reg_u32(S2);
334 getset_reg_u32(S3);
335 getset_reg_u32(S4);
336 getset_reg_u32(S5);
337 getset_reg_u32(S6);
338 getset_reg_u32(S7);
339 getset_reg_u32(T8);
340 getset_reg_u32(T9);
341 getset_reg_u32(K0);
342 getset_reg_u32(K1);
343 getset_reg_u32(GP);
345 getset_reg_u32(FP);
346 getset_reg_u32(RA);
348 getset_reg_u32(PC_FETCH);
351 
352 
353 PyObject* get_gpreg_offset_all(void)
354 {
355  PyObject *dict = PyDict_New();
356  PyObject *o;
357 
359  get_reg_off(exception_flags_new);
360 
361 
362  get_reg_off(ZERO);
363  get_reg_off(AT);
364  get_reg_off(V0);
365  get_reg_off(V1);
366  get_reg_off(A0);
367  get_reg_off(A1);
368  get_reg_off(A2);
369  get_reg_off(A3);
370  get_reg_off(T0);
371  get_reg_off(T1);
372  get_reg_off(T2);
373  get_reg_off(T3);
374  get_reg_off(T4);
375  get_reg_off(T5);
376  get_reg_off(T6);
377  get_reg_off(T7);
378  get_reg_off(S0);
379  get_reg_off(S1);
380  get_reg_off(S2);
381  get_reg_off(S3);
382  get_reg_off(S4);
383  get_reg_off(S5);
384  get_reg_off(S6);
385  get_reg_off(S7);
386  get_reg_off(T8);
387  get_reg_off(T9);
388  get_reg_off(K0);
389  get_reg_off(K1);
390  get_reg_off(GP);
391  get_reg_off(SP);
392  get_reg_off(FP);
393  get_reg_off(RA);
394  get_reg_off(PC);
395  get_reg_off(PC_FETCH);
396  get_reg_off(R_LO);
397  get_reg_off(R_HI);
398 
399  get_reg_off(ZERO_new);
400  get_reg_off(AT_new);
401  get_reg_off(V0_new);
402  get_reg_off(V1_new);
403  get_reg_off(A0_new);
404  get_reg_off(A1_new);
405  get_reg_off(A2_new);
406  get_reg_off(A3_new);
407  get_reg_off(T0_new);
408  get_reg_off(T1_new);
409  get_reg_off(T2_new);
410  get_reg_off(T3_new);
411  get_reg_off(T4_new);
412  get_reg_off(T5_new);
413  get_reg_off(T6_new);
414  get_reg_off(T7_new);
415  get_reg_off(S0_new);
416  get_reg_off(S1_new);
417  get_reg_off(S2_new);
418  get_reg_off(S3_new);
419  get_reg_off(S4_new);
420  get_reg_off(S5_new);
421  get_reg_off(S6_new);
422  get_reg_off(S7_new);
423  get_reg_off(T8_new);
424  get_reg_off(T9_new);
425  get_reg_off(K0_new);
426  get_reg_off(K1_new);
427  get_reg_off(GP_new);
428  get_reg_off(SP_new);
429  get_reg_off(FP_new);
430  get_reg_off(RA_new);
431  get_reg_off(PC_new);
432  get_reg_off(PC_FETCH_new);
433  get_reg_off(R_LO_new);
434  get_reg_off(R_HI_new);
435 
436 
437 
438  get_reg_off(pfmem08_0);
439  get_reg_off(pfmem08_1);
440  get_reg_off(pfmem08_2);
441  get_reg_off(pfmem08_3);
442  get_reg_off(pfmem08_4);
443  get_reg_off(pfmem08_5);
444  get_reg_off(pfmem08_6);
445  get_reg_off(pfmem08_7);
446  get_reg_off(pfmem08_8);
447  get_reg_off(pfmem08_9);
448  get_reg_off(pfmem08_10);
449  get_reg_off(pfmem08_11);
450  get_reg_off(pfmem08_12);
451  get_reg_off(pfmem08_13);
452  get_reg_off(pfmem08_14);
453  get_reg_off(pfmem08_15);
454  get_reg_off(pfmem08_16);
455  get_reg_off(pfmem08_17);
456  get_reg_off(pfmem08_18);
457  get_reg_off(pfmem08_19);
458 
459 
460  get_reg_off(pfmem16_0);
461  get_reg_off(pfmem16_1);
462  get_reg_off(pfmem16_2);
463  get_reg_off(pfmem16_3);
464  get_reg_off(pfmem16_4);
465  get_reg_off(pfmem16_5);
466  get_reg_off(pfmem16_6);
467  get_reg_off(pfmem16_7);
468  get_reg_off(pfmem16_8);
469  get_reg_off(pfmem16_9);
470  get_reg_off(pfmem16_10);
471  get_reg_off(pfmem16_11);
472  get_reg_off(pfmem16_12);
473  get_reg_off(pfmem16_13);
474  get_reg_off(pfmem16_14);
475  get_reg_off(pfmem16_15);
476  get_reg_off(pfmem16_16);
477  get_reg_off(pfmem16_17);
478  get_reg_off(pfmem16_18);
479  get_reg_off(pfmem16_19);
480 
481 
482  get_reg_off(pfmem32_0);
483  get_reg_off(pfmem32_1);
484  get_reg_off(pfmem32_2);
485  get_reg_off(pfmem32_3);
486  get_reg_off(pfmem32_4);
487  get_reg_off(pfmem32_5);
488  get_reg_off(pfmem32_6);
489  get_reg_off(pfmem32_7);
490  get_reg_off(pfmem32_8);
491  get_reg_off(pfmem32_9);
492  get_reg_off(pfmem32_10);
493  get_reg_off(pfmem32_11);
494  get_reg_off(pfmem32_12);
495  get_reg_off(pfmem32_13);
496  get_reg_off(pfmem32_14);
497  get_reg_off(pfmem32_15);
498  get_reg_off(pfmem32_16);
499  get_reg_off(pfmem32_17);
500  get_reg_off(pfmem32_18);
501  get_reg_off(pfmem32_19);
502 
503 
504  get_reg_off(pfmem64_0);
505  get_reg_off(pfmem64_1);
506  get_reg_off(pfmem64_2);
507  get_reg_off(pfmem64_3);
508  get_reg_off(pfmem64_4);
509  get_reg_off(pfmem64_5);
510  get_reg_off(pfmem64_6);
511  get_reg_off(pfmem64_7);
512  get_reg_off(pfmem64_8);
513  get_reg_off(pfmem64_9);
514  get_reg_off(pfmem64_10);
515  get_reg_off(pfmem64_11);
516  get_reg_off(pfmem64_12);
517  get_reg_off(pfmem64_13);
518  get_reg_off(pfmem64_14);
519  get_reg_off(pfmem64_15);
520  get_reg_off(pfmem64_16);
521  get_reg_off(pfmem64_17);
522  get_reg_off(pfmem64_18);
523  get_reg_off(pfmem64_19);
524 
525  return dict;
526 }
527 
528 
529 static PyGetSetDef JitCpu_getseters[] = {
530  {"vmmngr",
531  (getter)JitCpu_get_vmmngr, (setter)JitCpu_set_vmmngr,
532  "vmmngr",
533  NULL},
534 
535  {"jitter",
536  (getter)JitCpu_get_jitter, (setter)JitCpu_set_jitter,
537  "jitter",
538  NULL},
539 
540  {"ZERO" , (getter)JitCpu_get_ZERO , (setter)JitCpu_set_ZERO , "ZERO" , NULL},
541  {"AT" , (getter)JitCpu_get_AT , (setter)JitCpu_set_AT , "AT" , NULL},
542  {"V0" , (getter)JitCpu_get_V0 , (setter)JitCpu_set_V0 , "V0" , NULL},
543  {"V1" , (getter)JitCpu_get_V1 , (setter)JitCpu_set_V1 , "V1" , NULL},
544  {"A0" , (getter)JitCpu_get_A0 , (setter)JitCpu_set_A0 , "A0" , NULL},
545  {"A1" , (getter)JitCpu_get_A1 , (setter)JitCpu_set_A1 , "A1" , NULL},
546  {"A2" , (getter)JitCpu_get_A2 , (setter)JitCpu_set_A2 , "A2" , NULL},
547  {"A3" , (getter)JitCpu_get_A3 , (setter)JitCpu_set_A3 , "A3" , NULL},
548  {"T0" , (getter)JitCpu_get_T0 , (setter)JitCpu_set_T0 , "T0" , NULL},
549  {"T1" , (getter)JitCpu_get_T1 , (setter)JitCpu_set_T1 , "T1" , NULL},
550  {"T2" , (getter)JitCpu_get_T2 , (setter)JitCpu_set_T2 , "T2" , NULL},
551  {"T3" , (getter)JitCpu_get_T3 , (setter)JitCpu_set_T3 , "T3" , NULL},
552  {"T4" , (getter)JitCpu_get_T4 , (setter)JitCpu_set_T4 , "T4" , NULL},
553  {"T5" , (getter)JitCpu_get_T5 , (setter)JitCpu_set_T5 , "T5" , NULL},
554  {"T6" , (getter)JitCpu_get_T6 , (setter)JitCpu_set_T6 , "T6" , NULL},
555  {"T7" , (getter)JitCpu_get_T7 , (setter)JitCpu_set_T7 , "T7" , NULL},
556  {"S0" , (getter)JitCpu_get_S0 , (setter)JitCpu_set_S0 , "S0" , NULL},
557  {"S1" , (getter)JitCpu_get_S1 , (setter)JitCpu_set_S1 , "S1" , NULL},
558  {"S2" , (getter)JitCpu_get_S2 , (setter)JitCpu_set_S2 , "S2" , NULL},
559  {"S3" , (getter)JitCpu_get_S3 , (setter)JitCpu_set_S3 , "S3" , NULL},
560  {"S4" , (getter)JitCpu_get_S4 , (setter)JitCpu_set_S4 , "S4" , NULL},
561  {"S5" , (getter)JitCpu_get_S5 , (setter)JitCpu_set_S5 , "S5" , NULL},
562  {"S6" , (getter)JitCpu_get_S6 , (setter)JitCpu_set_S6 , "S6" , NULL},
563  {"S7" , (getter)JitCpu_get_S7 , (setter)JitCpu_set_S7 , "S7" , NULL},
564  {"T8" , (getter)JitCpu_get_T8 , (setter)JitCpu_set_T8 , "T8" , NULL},
565  {"T9" , (getter)JitCpu_get_T9 , (setter)JitCpu_set_T9 , "T9" , NULL},
566  {"K0" , (getter)JitCpu_get_K0 , (setter)JitCpu_set_K0 , "K0" , NULL},
567  {"K1" , (getter)JitCpu_get_K1 , (setter)JitCpu_set_K1 , "K1" , NULL},
568  {"GP" , (getter)JitCpu_get_GP , (setter)JitCpu_set_GP , "GP" , NULL},
569  {"SP" , (getter)JitCpu_get_SP , (setter)JitCpu_set_SP , "SP" , NULL},
570  {"FP" , (getter)JitCpu_get_FP , (setter)JitCpu_set_FP , "FP" , NULL},
571  {"RA" , (getter)JitCpu_get_RA , (setter)JitCpu_set_RA , "RA" , NULL},
572  {"PC" , (getter)JitCpu_get_PC , (setter)JitCpu_set_PC , "PC" , NULL},
573  {"PC_FETCH" , (getter)JitCpu_get_PC_FETCH , (setter)JitCpu_set_PC_FETCH , "PC_FETCH" , NULL},
574  {"R_LO" , (getter)JitCpu_get_R_LO , (setter)JitCpu_set_R_LO , "R_LO" , NULL},
575  {"R_HI" , (getter)JitCpu_get_R_HI , (setter)JitCpu_set_R_HI , "R_HI" , NULL},
576 
577  {NULL} /* Sentinel */
578 };
579 
580 
581 static PyTypeObject JitCpuType = {
582  PyObject_HEAD_INIT(NULL)
583  0, /*ob_size*/
584  "JitCore_mips32.JitCpu", /*tp_name*/
585  sizeof(JitCpu), /*tp_basicsize*/
586  0, /*tp_itemsize*/
587  (destructor)JitCpu_dealloc,/*tp_dealloc*/
588  0, /*tp_print*/
589  0, /*tp_getattr*/
590  0, /*tp_setattr*/
591  0, /*tp_compare*/
592  0, /*tp_repr*/
593  0, /*tp_as_number*/
594  0, /*tp_as_sequence*/
595  0, /*tp_as_mapping*/
596  0, /*tp_hash */
597  0, /*tp_call*/
598  0, /*tp_str*/
599  0, /*tp_getattro*/
600  0, /*tp_setattro*/
601  0, /*tp_as_buffer*/
602  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
603  "JitCpu objects", /* tp_doc */
604  0, /* tp_traverse */
605  0, /* tp_clear */
606  0, /* tp_richcompare */
607  0, /* tp_weaklistoffset */
608  0, /* tp_iter */
609  0, /* tp_iternext */
610  JitCpu_methods, /* tp_methods */
611  JitCpu_members, /* tp_members */
612  JitCpu_getseters, /* tp_getset */
613  0, /* tp_base */
614  0, /* tp_dict */
615  0, /* tp_descr_get */
616  0, /* tp_descr_set */
617  0, /* tp_dictoffset */
618  (initproc)JitCpu_init, /* tp_init */
619  0, /* tp_alloc */
620  JitCpu_new, /* tp_new */
621 };
622 
623 
624 
625 static PyMethodDef JitCore_mips32_Methods[] = {
626 
627  /*
628 
629  */
630  {"get_gpreg_offset_all", (PyCFunction)get_gpreg_offset_all, METH_NOARGS},
631  {NULL, NULL, 0, NULL} /* Sentinel */
632 
633 };
634 
635 static PyObject *JitCore_mips32_Error;
636 
637 PyMODINIT_FUNC
639 {
640  PyObject *m;
641 
642  if (PyType_Ready(&JitCpuType) < 0)
643  return;
644 
645  m = Py_InitModule("JitCore_mips32", JitCore_mips32_Methods);
646  if (m == NULL)
647  return;
648 
649  JitCore_mips32_Error = PyErr_NewException("JitCore_mips32.error", NULL, NULL);
650  Py_INCREF(JitCore_mips32_Error);
651  PyModule_AddObject(m, "error", JitCore_mips32_Error);
652 
653  Py_INCREF(&JitCpuType);
654  PyModule_AddObject(m, "JitCpu", (PyObject *)&JitCpuType);
655 
656 }
657 
uint32_t S3
PyObject * cpu_init_regs(JitCpu *self)
void MEM_WRITE_32(JitCpu *jitcpu, uint64_t addr, uint32_t src)
getset_reg_u32(ZERO)
#define EXCEPT_CODE_AUTOMOD
Definition: vm_mngr.h:130
uint32_t A3
uint32_t AT
Definition: JitCore_mips32.h:9
uint32_t S2
uint32_t K0
uint32_t T9
uint64_t PC
uint32_t S5
void MEM_WRITE_64(JitCpu *jitcpu, uint64_t addr, uint64_t src)
uint32_t ZERO
Definition: JitCore_mips32.h:8
uint32_t T1
PyObject * JitCpu_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
Definition: JitCore.c:17
#define RAISE(errtype, msg)
Definition: JitCore.h:4
#define PyGetInt(item, value)
Definition: JitCore.h:8
string name
Definition: ir2C.py:22
PyObject * vm_get_mem(JitCpu *self, PyObject *args)
uint32_t FP
PyObject * jitter
Definition: JitCore.h:96
PyObject * cpu_get_exception(JitCpu *self, PyObject *args)
uint32_t GP
uint32_t T7
int vm_write_mem(vm_mngr_t *vm_mngr, uint64_t addr, char *buffer, uint64_t size)
Definition: vm_mngr.c:518
static PyMethodDef JitCore_mips32_Methods[]
uint32_t T4
size_t offset
Definition: JitCore.h:103
void MEM_WRITE_16(JitCpu *jitcpu, uint64_t addr, uint16_t src)
uint32_t T2
PyObject * get_gpreg_offset_all(void)
void vm_MEM_WRITE_64(vm_mngr_t *vm_mngr, uint64_t addr, uint64_t src)
Definition: vm_mngr.c:454
void check_automod(JitCpu *jitcpu, uint64_t addr, uint64_t size)
PyObject * vm_set_mem(JitCpu *self, PyObject *args)
PyObject * JitCpu_set_vmmngr(JitCpu *self, PyObject *value, void *closure)
Definition: JitCore.c:35
static PyTypeObject JitCpuType
PyObject * JitCpu_get_vmmngr(JitCpu *self, void *closure)
Definition: JitCore.c:25
void vm_MEM_WRITE_16(vm_mngr_t *vm_mngr, uint64_t addr, unsigned short src)
Definition: vm_mngr.c:444
PyObject * JitCpu_set_jitter(JitCpu *self, PyObject *value, void *closure)
Definition: JitCore.c:51
#define get_reg(reg)
Definition: JitCore.h:74
PyObject_HEAD PyObject * pyvm
Definition: JitCore.h:95
uint32_t S1
uint32_t S4
void MEM_WRITE_08(JitCpu *jitcpu, uint64_t addr, uint8_t src)
static PyMemberDef JitCpu_members[]
static PyGetSetDef JitCpu_getseters[]
void vm_MEM_WRITE_08(vm_mngr_t *vm_mngr, uint64_t addr, unsigned char src)
Definition: vm_mngr.c:438
uint32_t RA
PyObject * cpu_get_gpreg(JitCpu *self)
void dump_gpregs(vm_cpu_t *vmcpu)
PyMODINIT_FUNC initJitCore_mips32(void)
char * name
Definition: JitCore.h:102
uint32_t S0
uint32_t T6
uint32_t A2
uint32_t T8
PyObject * cpu_set_exception(JitCpu *self, PyObject *args)
uint32_t T3
PyObject * cpu_dump_gpregs(JitCpu *self, PyObject *args)
uint32_t V1
static PyMethodDef JitCpu_methods[]
uint32_t A1
void JitCpu_dealloc(JitCpu *self)
Definition: JitCore.c:11
Definition: JitCore.h:93
uint64_t SP
uint32_t V0
uint32_t T5
uint32_t S7
reg_dict gpreg_dict[]
uint32_t A0
#define get_reg_off(reg)
Definition: JitCore.h:81
static PyObject * JitCore_mips32_Error
uint32_t K1
PyObject * cpu_set_gpreg(JitCpu *self, PyObject *args)
uint32_t T0
tuple exception_flags
Definition: regs.py:7
uint32_t S6
void vm_MEM_WRITE_32(vm_mngr_t *vm_mngr, uint64_t addr, unsigned int src)
Definition: vm_mngr.c:449
static int JitCpu_init(JitCpu *self, PyObject *args, PyObject *kwds)
PyObject * JitCpu_get_jitter(JitCpu *self, void *closure)
Definition: JitCore.c:41