Miasm2
 All Classes Namespaces Files Functions Variables Typedefs Properties Macros
Macros | Functions
vm_mngr.c File Reference
#include <Python.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <stdint.h>
#include <inttypes.h>
#include <math.h>
#include "queue.h"
#include "vm_mngr.h"
+ Include dependency graph for vm_mngr.c:

Go to the source code of this file.

Macros

#define MIN(a, b)   (((a)<(b))?(a):(b))
 
#define MAX(a, b)   (((a)>(b))?(a):(b))
 

Functions

uint16_t set_endian16 (vm_mngr_t *vm_mngr, uint16_t val)
 
uint32_t set_endian32 (vm_mngr_t *vm_mngr, uint32_t val)
 
uint64_t set_endian64 (vm_mngr_t *vm_mngr, uint64_t val)
 
void print_val (uint64_t base, uint64_t addr)
 
int is_mem_mapped (vm_mngr_t *vm_mngr, uint64_t ad)
 
uint64_t get_mem_base_addr (vm_mngr_t *vm_mngr, uint64_t ad, uint64_t *addr_base)
 
struct memory_page_nodeget_memory_page_from_address (vm_mngr_t *vm_mngr, uint64_t ad)
 
static uint64_t memory_page_read (vm_mngr_t *vm_mngr, unsigned int my_size, uint64_t ad)
 
static void memory_page_write (vm_mngr_t *vm_mngr, unsigned int my_size, uint64_t ad, uint64_t src)
 
uint16_t bcdadd_16 (uint16_t a, uint16_t b)
 
uint16_t bcdadd_cf_16 (uint16_t a, uint16_t b)
 
void dump_code_bloc (vm_mngr_t *vm_mngr)
 
void check_write_code_bloc (vm_mngr_t *vm_mngr, uint64_t my_size, uint64_t addr)
 
PyObject * addr2BlocObj (vm_mngr_t *vm_mngr, uint64_t addr)
 
void vm_MEM_WRITE_08 (vm_mngr_t *vm_mngr, uint64_t addr, unsigned char src)
 
void vm_MEM_WRITE_16 (vm_mngr_t *vm_mngr, uint64_t addr, unsigned short src)
 
void vm_MEM_WRITE_32 (vm_mngr_t *vm_mngr, uint64_t addr, unsigned int src)
 
void vm_MEM_WRITE_64 (vm_mngr_t *vm_mngr, uint64_t addr, uint64_t src)
 
unsigned char vm_MEM_LOOKUP_08 (vm_mngr_t *vm_mngr, uint64_t addr)
 
unsigned short vm_MEM_LOOKUP_16 (vm_mngr_t *vm_mngr, uint64_t addr)
 
unsigned int vm_MEM_LOOKUP_32 (vm_mngr_t *vm_mngr, uint64_t addr)
 
uint64_t vm_MEM_LOOKUP_64 (vm_mngr_t *vm_mngr, uint64_t addr)
 
int vm_read_mem (vm_mngr_t *vm_mngr, uint64_t addr, char **buffer_ptr, uint64_t size)
 
int vm_write_mem (vm_mngr_t *vm_mngr, uint64_t addr, char *buffer, uint64_t size)
 
unsigned int parity (unsigned int a)
 
int shift_right_arith (unsigned int size, int a, unsigned int b)
 
uint64_t shift_right_logic (uint64_t size, uint64_t a, uint64_t b)
 
uint64_t shift_left_logic (uint64_t size, uint64_t a, uint64_t b)
 
unsigned int mul_lo_op (unsigned int size, unsigned int a, unsigned int b)
 
unsigned int mul_hi_op (unsigned int size, unsigned int a, unsigned int b)
 
unsigned int imul_lo_op_08 (char a, char b)
 
unsigned int imul_lo_op_16 (short a, short b)
 
unsigned int imul_lo_op_32 (int a, int b)
 
int imul_hi_op_08 (char a, char b)
 
int imul_hi_op_16 (short a, short b)
 
int imul_hi_op_32 (int a, int b)
 
unsigned int umul16_lo (unsigned short a, unsigned short b)
 
unsigned int umul16_hi (unsigned short a, unsigned short b)
 
unsigned int div_op (unsigned int size, unsigned int a, unsigned int b, unsigned int c)
 
unsigned int rem_op (unsigned int size, unsigned int a, unsigned int b, unsigned int c)
 
uint64_t rot_left (uint64_t size, uint64_t a, uint64_t b)
 
uint64_t rot_right (uint64_t size, uint64_t a, uint64_t b)
 
int rcl_rez_op (unsigned int size, unsigned int a, unsigned int b, unsigned int cf)
 
int rcr_rez_op (unsigned int size, unsigned int a, unsigned int b, unsigned int cf)
 
int rcl_cf_op (unsigned int size, unsigned int a, unsigned int b, unsigned int cf)
 
int rcr_cf_op (unsigned int size, unsigned int a, unsigned int b, unsigned int cf)
 
unsigned int x86_bsr (uint64_t src, unsigned int size)
 
unsigned int x86_bsf (uint64_t src, unsigned int size)
 
unsigned int my_imul08 (unsigned int a, unsigned int b)
 
unsigned int cpuid (unsigned int a, unsigned int reg_num)
 
void dump_float (void)
 
double mem_32_to_double (unsigned int m)
 
double mem_64_to_double (uint64_t m)
 
double int_16_to_double (unsigned int m)
 
double int_32_to_double (unsigned int m)
 
double int_64_to_double (uint64_t m)
 
int32_t double_to_int_32 (double d)
 
int64_t double_to_int_64 (double d)
 
double fadd (double a, double b)
 
double fsub (double a, double b)
 
double fmul (double a, double b)
 
double fdiv (double a, double b)
 
double ftan (double a)
 
double frndint (double a)
 
double fsin (double a)
 
double fcos (double a)
 
double fscale (double a, double b)
 
double f2xm1 (double a)
 
double fsqrt (double a)
 
double fabs (double a)
 
unsigned int fcom_c0 (double a, double b)
 
unsigned int fcom_c1 (double a, double b)
 
unsigned int fcom_c2 (double a, double b)
 
unsigned int fcom_c3 (double a, double b)
 
unsigned int double_to_mem_32 (double d)
 
uint64_t double_to_mem_64 (double d)
 
struct memory_page_nodecreate_memory_page_node (uint64_t ad, unsigned int size, unsigned int access)
 
struct code_bloc_nodecreate_code_bloc_node (uint64_t ad_start, uint64_t ad_stop)
 
void add_code_bloc (vm_mngr_t *vm_mngr, struct code_bloc_node *cbp)
 
void dump_code_bloc_pool (vm_mngr_t *vm_mngr)
 
void init_memory_page_pool (vm_mngr_t *vm_mngr)
 
void init_code_bloc_pool (vm_mngr_t *vm_mngr)
 
void init_memory_breakpoint (vm_mngr_t *vm_mngr)
 
void reset_memory_page_pool (vm_mngr_t *vm_mngr)
 
void reset_code_bloc_pool (vm_mngr_t *vm_mngr)
 
void reset_memory_breakpoint (vm_mngr_t *vm_mngr)
 
int is_mpn_in_tab (vm_mngr_t *vm_mngr, struct memory_page_node *mpn_a)
 
void insert_mpn_in_tab (struct memory_page_node *mpn_a)
 
void add_memory_page (vm_mngr_t *vm_mngr, struct memory_page_node *mpn_a)
 
char * dump (vm_mngr_t *vm_mngr)
 
void dump_memory_breakpoint_pool (vm_mngr_t *vm_mngr)
 
void add_memory_breakpoint (vm_mngr_t *vm_mngr, uint64_t ad, uint64_t size, unsigned int access)
 
void remove_memory_breakpoint (vm_mngr_t *vm_mngr, uint64_t ad, unsigned int access)
 
unsigned int get_memory_page_next (vm_mngr_t *vm_mngr, unsigned int n_ad)
 
void hexdump (char *m, unsigned int l)
 
unsigned int access_segment (unsigned int d)
 
unsigned int access_segment_ok (unsigned int d)
 
unsigned int load_segment_limit (unsigned int d)
 
unsigned int load_segment_limit_ok (unsigned int d)
 
unsigned int load_tr_segment_selector (unsigned int d)
 
uint64_t get_exception_flag (vm_mngr_t *vm_mngr)
 

Macro Definition Documentation

#define MAX (   a,
 
)    (((a)>(b))?(a):(b))

Definition at line 48 of file vm_mngr.c.

#define MIN (   a,
 
)    (((a)<(b))?(a):(b))

Definition at line 47 of file vm_mngr.c.

Function Documentation

unsigned int access_segment ( unsigned int  d)

Definition at line 1668 of file vm_mngr.c.

1669 {
1670  // XXX TODO
1671  printf("access segment %X\n", d);
1672  return 0;
1673 }
unsigned int access_segment_ok ( unsigned int  d)

Definition at line 1674 of file vm_mngr.c.

1675 {
1676  // XXX TODO
1677  printf("access segment ok %X\n", d);
1678  return 0;
1679 }
void add_code_bloc ( vm_mngr_t vm_mngr,
struct code_bloc_node cbp 
)

Definition at line 1337 of file vm_mngr.c.

1338 {
1339  LIST_INSERT_HEAD(&vm_mngr->code_bloc_pool, cbp, next);
1340  if (vm_mngr->code_bloc_pool_ad_min> cbp->ad_start)
1341  vm_mngr->code_bloc_pool_ad_min = cbp->ad_start;
1342  if (vm_mngr->code_bloc_pool_ad_max< cbp->ad_stop)
1343  vm_mngr->code_bloc_pool_ad_max = cbp->ad_stop;
1344 }
unsigned int code_bloc_pool_ad_min
Definition: vm_mngr.h:77
#define LIST_INSERT_HEAD(head, elm, field)
Definition: queue.h:361
unsigned int code_bloc_pool_ad_max
Definition: vm_mngr.h:78
uint64_t ad_stop
Definition: vm_mngr.h:108
uint64_t ad_start
Definition: vm_mngr.h:107
struct code_bloc_list_head code_bloc_pool
Definition: vm_mngr.h:71

+ Here is the caller graph for this function:

void add_memory_breakpoint ( vm_mngr_t vm_mngr,
uint64_t  ad,
uint64_t  size,
unsigned int  access 
)

Definition at line 1543 of file vm_mngr.c.

1544 {
1545  struct memory_breakpoint_info * mpn_a;
1546  mpn_a = malloc(sizeof(*mpn_a));
1547  if (!mpn_a) {
1548  printf("cannot alloc\n");
1549  exit(0);
1550  }
1551  mpn_a->ad = ad;
1552  mpn_a->size = size;
1553  mpn_a->access = access;
1554 
1555  LIST_INSERT_HEAD(&vm_mngr->memory_breakpoint_pool, mpn_a, next);
1556 
1557 }
struct memory_breakpoint_info_head memory_breakpoint_pool
Definition: vm_mngr.h:72
#define LIST_INSERT_HEAD(head, elm, field)
Definition: queue.h:361

+ Here is the caller graph for this function:

void add_memory_page ( vm_mngr_t vm_mngr,
struct memory_page_node mpn_a 
)

Definition at line 1467 of file vm_mngr.c.

1468 {
1469  struct memory_page_node * mpn;
1470  struct memory_page_node * lmpn;
1471 
1472  if (LIST_EMPTY(&vm_mngr->memory_page_pool)){
1473  LIST_INSERT_HEAD(&vm_mngr->memory_page_pool, mpn_a, next);
1474  insert_mpn_in_tab(mpn_a);
1475  return;
1476  }
1477  LIST_FOREACH(mpn, &vm_mngr->memory_page_pool, next){
1478  lmpn = mpn;
1479  if (mpn->ad < mpn_a->ad)
1480  continue;
1481  LIST_INSERT_BEFORE(mpn, mpn_a, next);
1482  insert_mpn_in_tab(mpn_a);
1483  return;
1484  }
1485  LIST_INSERT_AFTER(lmpn, mpn_a, next);
1486  insert_mpn_in_tab(mpn_a);
1487 
1488 }
void insert_mpn_in_tab(struct memory_page_node *mpn_a)
Definition: vm_mngr.c:1451
#define LIST_FOREACH(var, head, field)
Definition: queue.h:332
#define LIST_INSERT_AFTER(listelm, elm, field)
Definition: queue.h:346
#define LIST_INSERT_HEAD(head, elm, field)
Definition: queue.h:361
struct memory_page_list_head memory_page_pool
Definition: vm_mngr.h:70
#define LIST_EMPTY(head)
Definition: queue.h:328
#define LIST_INSERT_BEFORE(listelm, elm, field)
Definition: queue.h:354
uint64_t ad
Definition: vm_mngr.h:97

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PyObject* addr2BlocObj ( vm_mngr_t vm_mngr,
uint64_t  addr 
)

Definition at line 415 of file vm_mngr.c.

416 {
417  PyObject* pyaddr;
418  PyObject* b;
419 
420  //printf("addr2blocobj %"PRIx64"\n", addr);
421  pyaddr = PyLong_FromUnsignedLongLong(addr);
422  /*
423  Py_INCREF(pyaddr);
424  return pyaddr;
425  */
426  b = PyDict_GetItem(vm_mngr->addr2obj, pyaddr);
427  if (b == NULL) {
428  Py_INCREF(Py_None);
429  return Py_None;
430  }
431 
432  //printf("addr2blocobj OBJ %p\n", b);
433  Py_INCREF(b);
434  return b;
435 }
PyObject * addr2obj
Definition: vm_mngr.h:82

+ Here is the call graph for this function:

uint16_t bcdadd_16 ( uint16_t  a,
uint16_t  b 
)

Definition at line 335 of file vm_mngr.c.

336 {
337  int carry = 0;
338  int i,j = 0;
339  uint16_t res = 0;
340  int nib_a, nib_b;
341  for (i = 0; i < 16; i += 4) {
342  nib_a = (a >> i) & (0xF);
343  nib_b = (b >> i) & (0xF);
344 
345  j = (carry + nib_a + nib_b);
346  if (j >= 10) {
347  carry = 1;
348  j -= 10;
349  j &=0xf;
350  }
351  else {
352  carry = 0;
353  }
354  res += j << i;
355  }
356  return res;
357 }

+ Here is the call graph for this function:

uint16_t bcdadd_cf_16 ( uint16_t  a,
uint16_t  b 
)

Definition at line 359 of file vm_mngr.c.

360 {
361  int carry = 0;
362  int i,j = 0;
363  int nib_a, nib_b;
364  for (i = 0; i < 16; i += 4) {
365  nib_a = (a >> i) & (0xF);
366  nib_b = (b >> i) & (0xF);
367 
368  j = (carry + nib_a + nib_b);
369  if (j >= 10) {
370  carry = 1;
371  j -= 10;
372  j &=0xf;
373  }
374  else {
375  carry = 0;
376  }
377  }
378  return carry;
379 }

+ Here is the call graph for this function:

void check_write_code_bloc ( vm_mngr_t vm_mngr,
uint64_t  my_size,
uint64_t  addr 
)

Definition at line 391 of file vm_mngr.c.

392 {
393  struct code_bloc_node * cbp;
394 
395  if (!(addr + my_size/8 <= vm_mngr->code_bloc_pool_ad_min ||
396  addr >=vm_mngr->code_bloc_pool_ad_max)){
397  LIST_FOREACH(cbp, &vm_mngr->code_bloc_pool, next){
398  if ((cbp->ad_start < addr + my_size/8) &&
399  (addr < cbp->ad_stop)){
400 #ifdef DEBUG_MIASM_AUTOMOD_CODE
401  fprintf(stderr, "**********************************\n");
402  fprintf(stderr, "self modifying code %"PRIX64" %.8X\n",
403  addr, my_size);
404  fprintf(stderr, "**********************************\n");
405  //dump_code_bloc(vm_mngr);
406 #endif
408 
409  break;
410  }
411  }
412  }
413 }
#define EXCEPT_CODE_AUTOMOD
Definition: vm_mngr.h:130
#define LIST_FOREACH(var, head, field)
Definition: queue.h:332
unsigned int code_bloc_pool_ad_min
Definition: vm_mngr.h:77
unsigned int code_bloc_pool_ad_max
Definition: vm_mngr.h:78
uint64_t exception_flags
Definition: vm_mngr.h:80
uint64_t ad_stop
Definition: vm_mngr.h:108
uint64_t ad_start
Definition: vm_mngr.h:107
struct code_bloc_list_head code_bloc_pool
Definition: vm_mngr.h:71

+ Here is the caller graph for this function:

unsigned int cpuid ( unsigned int  a,
unsigned int  reg_num 
)

Definition at line 965 of file vm_mngr.c.

966 {
967  if (reg_num >3){
968  fprintf(stderr, "not implemented cpuid reg %x\n", reg_num);
969  exit(-1);
970  }
971 
972  if (a == 0){
973  switch(reg_num){
974  case 0:
975  return 0xa;
976  case 1:
977  return 0x756E6547;
978  case 2:
979  return 0x6C65746E;
980  case 3:
981  return 0x49656E69;
982  }
983  }
984 
985  else if (a == 1){
986  switch(reg_num){
987  case 0:
988  //return 0x000006FB;
989  return 0x00020652;
990  case 1:
991  //return 0x02040800;
992  return 0x00000800;
993  case 2:
994  //return 0x0004E3BD;
995  return 0x00000209;
996  case 3:
997  //return 0xBFEBFBFF;
998  return 0x078bf9ff;
999  }
1000  }
1001  else{
1002  fprintf(stderr, "WARNING not implemented cpuid index %X!\n", a);
1003  //exit(-1);
1004  }
1005  return 0;
1006 }
struct code_bloc_node* create_code_bloc_node ( uint64_t  ad_start,
uint64_t  ad_stop 
)

Definition at line 1320 of file vm_mngr.c.

1321 {
1322  struct code_bloc_node * cbp;
1323 
1324  cbp = malloc(sizeof(*cbp));
1325  if (!cbp){
1326  fprintf(stderr, "cannot alloc cbp\n");
1327  exit(-1);
1328  }
1329 
1330  cbp->ad_start = ad_start;
1331  cbp->ad_stop = ad_stop;
1332 
1333  return cbp;
1334 }
uint64_t ad_stop
Definition: vm_mngr.h:108
uint64_t ad_start
Definition: vm_mngr.h:107

+ Here is the caller graph for this function:

struct memory_page_node* create_memory_page_node ( uint64_t  ad,
unsigned int  size,
unsigned int  access 
)

Definition at line 1295 of file vm_mngr.c.

1296 {
1297  struct memory_page_node * mpn;
1298  void* p;
1299 
1300  mpn = malloc(sizeof(*mpn));
1301  if (!mpn){
1302  fprintf(stderr, "cannot alloc mpn\n");
1303  return NULL;
1304  }
1305  p = malloc(size);
1306  if (!p){
1307  free(mpn);
1308  fprintf(stderr, "cannot alloc %d\n", size);
1309  return NULL;
1310  }
1311  mpn->ad = ad;
1312  mpn->size = size;
1313  mpn->access = access;
1314  mpn->ad_hp = p;
1315 
1316  return mpn;
1317 }
uint64_t access
Definition: vm_mngr.h:99
void * ad_hp
Definition: vm_mngr.h:100
uint64_t ad
Definition: vm_mngr.h:97
uint64_t size
Definition: vm_mngr.h:98

+ Here is the caller graph for this function:

unsigned int div_op ( unsigned int  size,
unsigned int  a,
unsigned int  b,
unsigned int  c 
)

Definition at line 769 of file vm_mngr.c.

770 {
771  int64_t num;
772  if (c == 0)
773  {
774  //vmmngr.exception_flags |= EXCEPT_INT_DIV_BY_ZERO;
775  return 0;
776  }
777  num = ((int64_t)a << size) + b;
778  num/=(int64_t)c;
779  return num;
780 }
tuple c
Definition: ir2C.py:23
uint64_t size
Definition: vm_mngr.h:98

+ Here is the call graph for this function:

int32_t double_to_int_32 ( double  d)

Definition at line 1086 of file vm_mngr.c.

1087 {
1088  int32_t i;
1089 
1090  i = (int32_t)d;
1091 #ifdef DEBUG_MIASM_DOUBLE
1092  dump_float();
1093  printf("%e int %d\n", d, i);
1094 #endif
1095  return i;
1096 }
void dump_float(void)
Definition: vm_mngr.c:1010

+ Here is the call graph for this function:

int64_t double_to_int_64 ( double  d)

Definition at line 1098 of file vm_mngr.c.

1099 {
1100  int64_t i;
1101 
1102  i = (int64_t)d;
1103 #ifdef DEBUG_MIASM_DOUBLE
1104  dump_float();
1105  printf("%e int %"PRId64"\n", d, i);
1106 #endif
1107  return i;
1108 }
void dump_float(void)
Definition: vm_mngr.c:1010

+ Here is the call graph for this function:

unsigned int double_to_mem_32 ( double  d)

Definition at line 1271 of file vm_mngr.c.

1272 {
1273  unsigned int m;
1274  float f;
1275  f = d;
1276  m = *((unsigned int*)&f);
1277 #ifdef DEBUG_MIASM_DOUBLE
1278  dump_float();
1279  printf("%d %e\n", m, d);
1280 #endif
1281  return m;
1282 }
void dump_float(void)
Definition: vm_mngr.c:1010

+ Here is the call graph for this function:

uint64_t double_to_mem_64 ( double  d)

Definition at line 1284 of file vm_mngr.c.

1285 {
1286  uint64_t m;
1287  m = *((uint64_t*)&d);
1288 #ifdef DEBUG_MIASM_DOUBLE
1289  dump_float();
1290  printf("%"PRId64" %e\n", m, d);
1291 #endif
1292  return m;
1293 }
void dump_float(void)
Definition: vm_mngr.c:1010

+ Here is the call graph for this function:

char* dump ( vm_mngr_t vm_mngr)

Definition at line 1493 of file vm_mngr.c.

1494 {
1495  char buf[100];
1496  int length;
1497  int total_len = 0;
1498  char *buf_final;
1499  struct memory_page_node * mpn;
1500 
1501  buf_final = malloc(1);
1502  if (buf_final == NULL) {
1503  printf("cannot alloc\n");
1504  exit(0);
1505  }
1506  buf_final[0] = '\x00';
1507  LIST_FOREACH(mpn, &vm_mngr->memory_page_pool, next){
1508 
1509  length = snprintf(buf, sizeof(buf),
1510  "ad 0x%"PRIX64" size 0x%"PRIX64" %c%c%c\n",
1511  (uint64_t)mpn->ad,
1512  (uint64_t)mpn->size,
1513  mpn->access & PAGE_READ? 'R':'_',
1514  mpn->access & PAGE_WRITE? 'W':'_',
1515  mpn->access & PAGE_EXEC? 'X':'_'
1516  );
1517  total_len += length+1;
1518  buf_final = realloc(buf_final, total_len);
1519  if (buf_final == NULL) {
1520  printf("cannot alloc\n");
1521  exit(0);
1522  }
1523  strcat(buf_final, buf);
1524  }
1525 
1526  return buf_final;
1527 }
#define LIST_FOREACH(var, head, field)
Definition: queue.h:332
#define PAGE_EXEC
Definition: vm_mngr.h:125
#define PAGE_WRITE
Definition: vm_mngr.h:124
uint64_t access
Definition: vm_mngr.h:99
struct memory_page_list_head memory_page_pool
Definition: vm_mngr.h:70
#define PAGE_READ
Definition: vm_mngr.h:123
uint64_t ad
Definition: vm_mngr.h:97
uint64_t size
Definition: vm_mngr.h:98

+ Here is the caller graph for this function:

void dump_code_bloc ( vm_mngr_t vm_mngr)

Definition at line 382 of file vm_mngr.c.

383 {
384  struct code_bloc_node * cbp;
385  LIST_FOREACH(cbp, &vm_mngr->code_bloc_pool, next){
386  fprintf(stderr, "%"PRIX64"%"PRIX64"\n", cbp->ad_start, cbp->ad_stop);
387  }
388 
389 }
#define LIST_FOREACH(var, head, field)
Definition: queue.h:332
uint64_t ad_stop
Definition: vm_mngr.h:108
uint64_t ad_start
Definition: vm_mngr.h:107
struct code_bloc_list_head code_bloc_pool
Definition: vm_mngr.h:71
void dump_code_bloc_pool ( vm_mngr_t vm_mngr)

Definition at line 1346 of file vm_mngr.c.

1347 {
1348  struct code_bloc_node * cbp;
1349 
1350  LIST_FOREACH(cbp, &vm_mngr->code_bloc_pool, next){
1351  printf("ad start %"PRIX64" ad_stop %"PRIX64"\n",
1352  cbp->ad_start,
1353  cbp->ad_stop);
1354  }
1355 }
#define LIST_FOREACH(var, head, field)
Definition: queue.h:332
uint64_t ad_stop
Definition: vm_mngr.h:108
uint64_t ad_start
Definition: vm_mngr.h:107
struct code_bloc_list_head code_bloc_pool
Definition: vm_mngr.h:71

+ Here is the caller graph for this function:

void dump_float ( void  )

Definition at line 1010 of file vm_mngr.c.

1011 {
1012  /*
1013  printf("%e\n", vmmngr.float_st0);
1014  printf("%e\n", vmmngr.float_st1);
1015  printf("%e\n", vmmngr.float_st2);
1016  printf("%e\n", vmmngr.float_st3);
1017  printf("%e\n", vmmngr.float_st4);
1018  printf("%e\n", vmmngr.float_st5);
1019  printf("%e\n", vmmngr.float_st6);
1020  printf("%e\n", vmmngr.float_st7);
1021  */
1022 }

+ Here is the caller graph for this function:

void dump_memory_breakpoint_pool ( vm_mngr_t vm_mngr)

Definition at line 1529 of file vm_mngr.c.

1530 {
1531  struct memory_breakpoint_info * mpn;
1532 
1533  LIST_FOREACH(mpn, &vm_mngr->memory_breakpoint_pool, next){
1534  printf("ad %"PRIX64" size %"PRIX64" access %"PRIX64"\n",
1535  mpn->ad,
1536  mpn->size,
1537  mpn->access
1538  );
1539  }
1540 }
struct memory_breakpoint_info_head memory_breakpoint_pool
Definition: vm_mngr.h:72
#define LIST_FOREACH(var, head, field)
Definition: queue.h:332

+ Here is the caller graph for this function:

double f2xm1 ( double  a)

Definition at line 1213 of file vm_mngr.c.

1214 {
1215  double b;
1216  b = exp2(a)-1;
1217 #ifdef DEBUG_MIASM_DOUBLE
1218  dump_float();
1219  printf("%e exp2 -1 %e\n", a, b);
1220 #endif
1221  return b;
1222 }
void dump_float(void)
Definition: vm_mngr.c:1010

+ Here is the call graph for this function:

double fabs ( double  a)

Definition at line 1235 of file vm_mngr.c.

1236 {
1237  double b;
1238  b = abs(a);
1239 #ifdef DEBUG_MIASM_DOUBLE
1240  dump_float();
1241  printf("%e abs %e\n", a, b);
1242 #endif
1243  return b;
1244 }
void dump_float(void)
Definition: vm_mngr.c:1010

+ Here is the call graph for this function:

double fadd ( double  a,
double  b 
)

Definition at line 1111 of file vm_mngr.c.

1112 {
1113  double c;
1114  c = a + b;
1115 #ifdef DEBUG_MIASM_DOUBLE
1116  dump_float();
1117  printf("%e + %e -> %e\n", a, b, c);
1118 #endif
1119  return c;
1120 }
tuple c
Definition: ir2C.py:23
void dump_float(void)
Definition: vm_mngr.c:1010

+ Here is the call graph for this function:

unsigned int fcom_c0 ( double  a,
double  b 
)

Definition at line 1248 of file vm_mngr.c.

1249 {
1250  if (a>=b)
1251  return 0;
1252  return 1;
1253 }
unsigned int fcom_c1 ( double  a,
double  b 
)

Definition at line 1254 of file vm_mngr.c.

1255 {
1256  //XXX
1257  return 0;
1258 }
unsigned int fcom_c2 ( double  a,
double  b 
)

Definition at line 1259 of file vm_mngr.c.

1260 {
1261  return 0;
1262 }
unsigned int fcom_c3 ( double  a,
double  b 
)

Definition at line 1263 of file vm_mngr.c.

1264 {
1265  if (a==b)
1266  return 1;
1267  return 0;
1268 }
double fcos ( double  a)

Definition at line 1190 of file vm_mngr.c.

1191 {
1192  double b;
1193  b = cos(a);
1194 #ifdef DEBUG_MIASM_DOUBLE
1195  dump_float();
1196  printf("%e cos %e\n", a, b);
1197 #endif
1198  return b;
1199 }
void dump_float(void)
Definition: vm_mngr.c:1010

+ Here is the call graph for this function:

double fdiv ( double  a,
double  b 
)

Definition at line 1144 of file vm_mngr.c.

1145 {
1146  double c;
1147  c = a / b;
1148 #ifdef DEBUG_MIASM_DOUBLE
1149  dump_float();
1150  printf("%e / %e -> %e\n", a, b, c);
1151 #endif
1152  return c;
1153 }
tuple c
Definition: ir2C.py:23
void dump_float(void)
Definition: vm_mngr.c:1010

+ Here is the call graph for this function:

double fmul ( double  a,
double  b 
)

Definition at line 1133 of file vm_mngr.c.

1134 {
1135  double c;
1136  c = a * b;
1137 #ifdef DEBUG_MIASM_DOUBLE
1138  dump_float();
1139  printf("%e * %e -> %e\n", a, b, c);
1140 #endif
1141  return c;
1142 }
tuple c
Definition: ir2C.py:23
void dump_float(void)
Definition: vm_mngr.c:1010

+ Here is the call graph for this function:

double frndint ( double  a)

Definition at line 1166 of file vm_mngr.c.

1167 {
1168  int64_t b;
1169  double c;
1170  b = (int64_t)a;
1171  c = (double)b;
1172 #ifdef DEBUG_MIASM_DOUBLE
1173  dump_float();
1174  printf("%e double %e\n", a, c);
1175 #endif
1176  return c;
1177 }
tuple c
Definition: ir2C.py:23
void dump_float(void)
Definition: vm_mngr.c:1010

+ Here is the call graph for this function:

double fscale ( double  a,
double  b 
)

Definition at line 1202 of file vm_mngr.c.

1203 {
1204  double c;
1205  c = a * exp2(trunc(b));
1206 #ifdef DEBUG_MIASM_DOUBLE
1207  dump_float();
1208  printf("%e *exp2 %e -> %e\n", a, b, c);
1209 #endif
1210  return c;
1211 }
tuple c
Definition: ir2C.py:23
void dump_float(void)
Definition: vm_mngr.c:1010

+ Here is the call graph for this function:

double fsin ( double  a)

Definition at line 1179 of file vm_mngr.c.

1180 {
1181  double b;
1182  b = sin(a);
1183 #ifdef DEBUG_MIASM_DOUBLE
1184  dump_float();
1185  printf("%e sin %e\n", a, b);
1186 #endif
1187  return b;
1188 }
void dump_float(void)
Definition: vm_mngr.c:1010

+ Here is the call graph for this function:

double fsqrt ( double  a)

Definition at line 1224 of file vm_mngr.c.

1225 {
1226  double b;
1227  b = sqrt(a);
1228 #ifdef DEBUG_MIASM_DOUBLE
1229  dump_float();
1230  printf("%e sqrt %e\n", a, b);
1231 #endif
1232  return b;
1233 }
void dump_float(void)
Definition: vm_mngr.c:1010

+ Here is the call graph for this function:

double fsub ( double  a,
double  b 
)

Definition at line 1122 of file vm_mngr.c.

1123 {
1124  double c;
1125  c = a - b;
1126 #ifdef DEBUG_MIASM_DOUBLE
1127  dump_float();
1128  printf("%e - %e -> %e\n", a, b, c);
1129 #endif
1130  return c;
1131 }
tuple c
Definition: ir2C.py:23
void dump_float(void)
Definition: vm_mngr.c:1010

+ Here is the call graph for this function:

double ftan ( double  a)

Definition at line 1155 of file vm_mngr.c.

1156 {
1157  double b;
1158  b = tan(a);
1159 #ifdef DEBUG_MIASM_DOUBLE
1160  dump_float();
1161  printf("%e tan %e\n", a, b);
1162 #endif
1163  return b;
1164 }
void dump_float(void)
Definition: vm_mngr.c:1010

+ Here is the call graph for this function:

uint64_t get_exception_flag ( vm_mngr_t vm_mngr)

Definition at line 1701 of file vm_mngr.c.

1702 {
1703  return vm_mngr->exception_flags;
1704 }
uint64_t exception_flags
Definition: vm_mngr.h:80
uint64_t get_mem_base_addr ( vm_mngr_t vm_mngr,
uint64_t  ad,
uint64_t *  addr_base 
)

Definition at line 107 of file vm_mngr.c.

108 {
109  struct memory_page_node * mpn;
110  /*
111  mpn = memory_page_pool_tab[ad>>MEMORY_PAGE_POOL_MASK_BIT];
112  if ( mpn && (mpn->ad <= ad) && (ad < mpn->ad + mpn->size)){
113  *addr_base = mpn->ad;
114  return 1;
115  }
116  */
117  LIST_FOREACH(mpn, &vm_mngr->memory_page_pool, next){
118  if ((mpn->ad <= ad) && (ad <mpn->ad + mpn->size)) {
119  *addr_base = mpn->ad;
120  return 1;
121  }
122  }
123  return 0;
124 }
#define LIST_FOREACH(var, head, field)
Definition: queue.h:332
struct memory_page_list_head memory_page_pool
Definition: vm_mngr.h:70
uint64_t ad
Definition: vm_mngr.h:97
uint64_t size
Definition: vm_mngr.h:98

+ Here is the caller graph for this function:

struct memory_page_node* get_memory_page_from_address ( vm_mngr_t vm_mngr,
uint64_t  ad 
)

Definition at line 126 of file vm_mngr.c.

127 {
128  struct memory_page_node * mpn;
129 #if 0
130  mpn = memory_page_pool_tab[ad>>MEMORY_PAGE_POOL_MASK_BIT];
131  if ( mpn && (mpn->ad <= ad) && (ad < mpn->ad + mpn->size))
132  return mpn;
133 
134  fprintf(stderr, "WARNING: address 0x%"PRIX64" is not mapped in virtual memory:\n", ad);
135  //dump_gpregs();
136  //exit(-1);
138 
139  return NULL;
140 #else
141 
142  //printf("search for page ad: %X\n", ad);
143  LIST_FOREACH(mpn, &vm_mngr->memory_page_pool, next){
144  if ((mpn->ad <= ad) && (ad < mpn->ad + mpn->size))
145  return mpn;
146  }
147  fprintf(stderr, "WARNING: address 0x%"PRIX64" is not mapped in virtual memory:\n", ad);
148  //dump_gpregs();
149  //exit(-1);
151  return NULL;
152 #endif
153 }
#define LIST_FOREACH(var, head, field)
Definition: queue.h:332
#define MEMORY_PAGE_POOL_MASK_BIT
Definition: vm_mngr.h:63
#define EXCEPT_ACCESS_VIOL
Definition: vm_mngr.h:141
struct memory_page_list_head memory_page_pool
Definition: vm_mngr.h:70
uint64_t exception_flags
Definition: vm_mngr.h:80
uint64_t ad
Definition: vm_mngr.h:97
uint64_t size
Definition: vm_mngr.h:98

+ Here is the caller graph for this function:

unsigned int get_memory_page_next ( vm_mngr_t vm_mngr,
unsigned int  n_ad 
)

Definition at line 1576 of file vm_mngr.c.

1577 {
1578  struct memory_page_node * mpn;
1579  uint64_t ad = 0;
1580 
1581  LIST_FOREACH(mpn, &vm_mngr->memory_page_pool, next){
1582  if (mpn->ad < n_ad)
1583  continue;
1584 
1585  if (ad == 0 || mpn->ad <ad)
1586  ad = mpn->ad;
1587  }
1588  return ad;
1589 }
#define LIST_FOREACH(var, head, field)
Definition: queue.h:332
struct memory_page_list_head memory_page_pool
Definition: vm_mngr.h:70
uint64_t ad
Definition: vm_mngr.h:97
void hexdump ( char *  m,
unsigned int  l 
)

Definition at line 1626 of file vm_mngr.c.

1627 {
1628  int i, j, last;
1629  last = 0;
1630  for (i=0;i<l;i++){
1631  if (!(i%0x10) && i){
1632  last = i;
1633  printf(" ");
1634  for (j=-0x10;j<0;j++){
1635  if (isprint(m[i+j])){
1636  printf("%c", m[i+j]);
1637  }
1638  else{
1639  printf(".");
1640  }
1641  }
1642  printf("\n");
1643  }
1644  printf("%.2X ", m[i]&0xFF);
1645  }
1646  l-=last;
1647  if (l){
1648  for (j=i;j<last+0x10;j++)
1649  printf(" ");
1650  printf(" ");
1651  for (j = 0;l;j++){
1652  if (isprint(m[last+j])){
1653  printf("%c", m[last+j]);
1654  }
1655  else{
1656  printf(".");
1657  }
1658  l--;
1659  }
1660  }
1661  printf("\n");
1662 
1663 }

+ Here is the call graph for this function:

int imul_hi_op_08 ( char  a,
char  b 
)

Definition at line 732 of file vm_mngr.c.

733 {
734  int64_t res = 0;
735  res = a*b;
736  return res>>8;
737 }

+ Here is the call graph for this function:

int imul_hi_op_16 ( short  a,
short  b 
)

Definition at line 739 of file vm_mngr.c.

740 {
741  int64_t res = 0;
742  res = a*b;
743  return res>>16;
744 }

+ Here is the call graph for this function:

int imul_hi_op_32 ( int  a,
int  b 
)

Definition at line 746 of file vm_mngr.c.

747 {
748  int64_t res = 0;
749  res = (int64_t)a*(int64_t)b;
750  //printf("%x %x dd %"PRIx64"\n", a, b, res);
751  return res>>32ULL;
752 }

+ Here is the call graph for this function:

unsigned int imul_lo_op_08 ( char  a,
char  b 
)

Definition at line 717 of file vm_mngr.c.

718 {
719  return a*b;
720 }

+ Here is the call graph for this function:

unsigned int imul_lo_op_16 ( short  a,
short  b 
)

Definition at line 722 of file vm_mngr.c.

723 {
724  return a*b;
725 }

+ Here is the call graph for this function:

unsigned int imul_lo_op_32 ( int  a,
int  b 
)

Definition at line 727 of file vm_mngr.c.

728 {
729  return a*b;
730 }

+ Here is the call graph for this function:

void init_code_bloc_pool ( vm_mngr_t vm_mngr)

Definition at line 1366 of file vm_mngr.c.

1367 {
1368  LIST_INIT(&vm_mngr->code_bloc_pool);
1369  vm_mngr->code_bloc_pool_ad_min = 0xffffffff;
1370  vm_mngr->code_bloc_pool_ad_max = 0;
1371 }
unsigned int code_bloc_pool_ad_min
Definition: vm_mngr.h:77
unsigned int code_bloc_pool_ad_max
Definition: vm_mngr.h:78
#define LIST_INIT(head)
Definition: queue.h:342
struct code_bloc_list_head code_bloc_pool
Definition: vm_mngr.h:71

+ Here is the caller graph for this function:

void init_memory_breakpoint ( vm_mngr_t vm_mngr)

Definition at line 1373 of file vm_mngr.c.

1374 {
1375  LIST_INIT(&vm_mngr->memory_breakpoint_pool);
1376 }
struct memory_breakpoint_info_head memory_breakpoint_pool
Definition: vm_mngr.h:72
#define LIST_INIT(head)
Definition: queue.h:342

+ Here is the caller graph for this function:

void init_memory_page_pool ( vm_mngr_t vm_mngr)

Definition at line 1358 of file vm_mngr.c.

1359 {
1360  unsigned int i;
1361  LIST_INIT(&vm_mngr->memory_page_pool);
1362  for (i=0;i<MAX_MEMORY_PAGE_POOL_TAB; i++)
1363  vm_mngr->memory_page_pool_tab[i] = NULL;
1364 }
struct memory_page_node * memory_page_pool_tab[MAX_MEMORY_PAGE_POOL_TAB]
Definition: vm_mngr.h:74
#define MAX_MEMORY_PAGE_POOL_TAB
Definition: vm_mngr.h:62
struct memory_page_list_head memory_page_pool
Definition: vm_mngr.h:70
#define LIST_INIT(head)
Definition: queue.h:342

+ Here is the caller graph for this function:

void insert_mpn_in_tab ( struct memory_page_node mpn_a)

Definition at line 1451 of file vm_mngr.c.

1452 {
1453  /*
1454  for (i=mpn_a->ad >> MEMORY_PAGE_POOL_MASK_BIT;
1455  i<(mpn_a->ad + mpn_a->size + PAGE_SIZE - 1)>>MEMORY_PAGE_POOL_MASK_BIT;
1456  i++){
1457  if (memory_page_pool_tab[i] !=NULL){
1458  fprintf(stderr, "known page in tab\n");
1459  exit(1);
1460  }
1461  memory_page_pool_tab[i] = mpn_a;
1462  }
1463  */
1464 
1465 }

+ Here is the caller graph for this function:

double int_16_to_double ( unsigned int  m)

Definition at line 1050 of file vm_mngr.c.

1051 {
1052  double d;
1053 
1054  d = (double)(m&0xffff);
1055 #ifdef DEBUG_MIASM_DOUBLE
1056  dump_float();
1057  printf("%d double %e\n", m, d);
1058 #endif
1059  return d;
1060 }
void dump_float(void)
Definition: vm_mngr.c:1010

+ Here is the call graph for this function:

double int_32_to_double ( unsigned int  m)

Definition at line 1062 of file vm_mngr.c.

1063 {
1064  double d;
1065 
1066  d = (double)m;
1067 #ifdef DEBUG_MIASM_DOUBLE
1068  dump_float();
1069  printf("%d double %e\n", m, d);
1070 #endif
1071  return d;
1072 }
void dump_float(void)
Definition: vm_mngr.c:1010

+ Here is the call graph for this function:

double int_64_to_double ( uint64_t  m)

Definition at line 1074 of file vm_mngr.c.

1075 {
1076  double d;
1077 
1078  d = (double)m;
1079 #ifdef DEBUG_MIASM_DOUBLE
1080  dump_float();
1081  printf("%"PRId64" double %e\n", m, d);
1082 #endif
1083  return d;
1084 }
void dump_float(void)
Definition: vm_mngr.c:1010

+ Here is the call graph for this function:

int is_mem_mapped ( vm_mngr_t vm_mngr,
uint64_t  ad 
)

Definition at line 87 of file vm_mngr.c.

88 {
89  struct memory_page_node * mpn;
90  /*
91  mpn = memory_page_pool_tab[ad>>MEMORY_PAGE_POOL_MASK_BIT];
92  if ( mpn && (mpn->ad <= ad) && (ad < mpn->ad + mpn->size))
93  return 1;
94  */
95  LIST_FOREACH(mpn, &vm_mngr->memory_page_pool, next){
96  if ((mpn->ad <= ad) && (ad <mpn->ad + mpn->size))
97  return 1;
98  }
99 
100  return 0;
101 }
#define LIST_FOREACH(var, head, field)
Definition: queue.h:332
struct memory_page_list_head memory_page_pool
Definition: vm_mngr.h:70
uint64_t ad
Definition: vm_mngr.h:97
uint64_t size
Definition: vm_mngr.h:98

+ Here is the caller graph for this function:

int is_mpn_in_tab ( vm_mngr_t vm_mngr,
struct memory_page_node mpn_a 
)

Definition at line 1424 of file vm_mngr.c.

1425 {
1426  struct memory_page_node * mpn;
1427 
1428  /*
1429  for (i=mpn_a->ad >> MEMORY_PAGE_POOL_MASK_BIT;
1430  i<(mpn_a->ad + mpn_a->size + PAGE_SIZE - 1)>>MEMORY_PAGE_POOL_MASK_BIT;
1431  i++){
1432  if (memory_page_pool_tab[i] !=NULL){
1433  return 1;
1434  }
1435  }
1436  */
1437  LIST_FOREACH(mpn, &vm_mngr->memory_page_pool, next){
1438  if (mpn->ad >= mpn_a->ad + mpn_a->size)
1439  continue;
1440  if (mpn->ad + mpn->size <= mpn_a->ad)
1441  continue;
1442  printf("is mpn in! %"PRIX64" %"PRIX64" \n", mpn_a->ad, mpn_a->size);
1443  printf("known:! %"PRIX64" %"PRIX64" \n", mpn->ad, mpn->size);
1444 
1445  return 1;
1446  }
1447 
1448  return 0;
1449 }
#define LIST_FOREACH(var, head, field)
Definition: queue.h:332
struct memory_page_list_head memory_page_pool
Definition: vm_mngr.h:70
uint64_t ad
Definition: vm_mngr.h:97
uint64_t size
Definition: vm_mngr.h:98

+ Here is the caller graph for this function:

unsigned int load_segment_limit ( unsigned int  d)

Definition at line 1681 of file vm_mngr.c.

1682 {
1683  // XXX TODO
1684  printf("load segment limit %X\n", d);
1685  return 0;
1686 }
unsigned int load_segment_limit_ok ( unsigned int  d)

Definition at line 1687 of file vm_mngr.c.

1688 {
1689  // XXX TODO
1690  printf("load segment limit ok %X\n", d);
1691  return 0;
1692 }
unsigned int load_tr_segment_selector ( unsigned int  d)

Definition at line 1694 of file vm_mngr.c.

1695 {
1696  // XXX TODO
1697  return 0;
1698 }
double mem_32_to_double ( unsigned int  m)

Definition at line 1024 of file vm_mngr.c.

1025 {
1026  float f;
1027  double d;
1028 
1029  f = *((float*)&m);
1030  d = f;
1031 #ifdef DEBUG_MIASM_DOUBLE
1032  dump_float();
1033  printf("%d float %e\n", m, d);
1034 #endif
1035  return d;
1036 }
void dump_float(void)
Definition: vm_mngr.c:1010

+ Here is the call graph for this function:

double mem_64_to_double ( uint64_t  m)

Definition at line 1039 of file vm_mngr.c.

1040 {
1041  double d;
1042  d = *((double*)&m);
1043 #ifdef DEBUG_MIASM_DOUBLE
1044  dump_float();
1045  printf("%"PRId64" double %e\n", m, d);
1046 #endif
1047  return d;
1048 }
void dump_float(void)
Definition: vm_mngr.c:1010

+ Here is the call graph for this function:

static uint64_t memory_page_read ( vm_mngr_t vm_mngr,
unsigned int  my_size,
uint64_t  ad 
)
static

Definition at line 158 of file vm_mngr.c.

159 {
160  struct memory_page_node * mpn;
161  unsigned char * addr;
162  uint64_t ret = 0;
163  struct memory_breakpoint_info * b;
164 
165 
166  mpn = get_memory_page_from_address(vm_mngr, ad);
167  if (!mpn)
168  return 0;
169 
170  if ((mpn->access & PAGE_READ) == 0){
171  fprintf(stderr, "access to non readable page!! %"PRIX64"\n", ad);
173  return 0;
174  }
175 
176  /* check read breakpoint*/
177  LIST_FOREACH(b, &vm_mngr->memory_breakpoint_pool, next){
178  if ((b->access & BREAKPOINT_READ) == 0)
179  continue;
180  if ((b->ad <= ad) && (ad < b->ad + b->size))
182  }
183 
184 
185  addr = &((unsigned char*)mpn->ad_hp)[ad - mpn->ad];
186 
187  /* read fits in a page */
188  if (ad - mpn->ad + my_size/8 <= mpn->size){
189  switch(my_size){
190  case 8:
191  ret = *((unsigned char*)addr)&0xFF;
192  break;
193  case 16:
194  ret = *((unsigned short*)addr)&0xFFFF;
195  ret = set_endian16(vm_mngr, ret);
196  break;
197  case 32:
198  ret = *((unsigned int*)addr)&0xFFFFFFFF;
199  ret = set_endian32(vm_mngr, ret);
200  break;
201  case 64:
202  ret = *((uint64_t*)addr)&0xFFFFFFFFFFFFFFFFULL;
203  ret = set_endian64(vm_mngr, ret);
204  break;
205  default:
206  exit(0);
207  break;
208  }
209  }
210  /* read is multiple page wide */
211  else{
212  unsigned int new_size = my_size;
213  int index = 0;
214  //fprintf(stderr, "read multiple page! %"PRIX64" %d\n", ad, new_size);
215  while (new_size){
216  mpn = get_memory_page_from_address(vm_mngr, ad);
217  if (!mpn)
218  return 0;
219  addr = &((unsigned char*)mpn->ad_hp)[ad - mpn->ad];
220  ret |= (*((unsigned char*)addr)&0xFF)<<(index);
221  index +=8;
222  new_size -= 8;
223  ad ++;
224  }
225  switch(my_size){
226  case 8:
227  ret = ret;
228  break;
229  case 16:
230  ret = set_endian16(vm_mngr, ret);
231  break;
232  case 32:
233  ret = set_endian32(vm_mngr, ret);
234  break;
235  case 64:
236  ret = set_endian64(vm_mngr, ret);
237  break;
238  default:
239  exit(0);
240  break;
241  }
242  }
243  return ret;
244 }
struct memory_breakpoint_info_head memory_breakpoint_pool
Definition: vm_mngr.h:72
#define BREAKPOINT_READ
Definition: vm_mngr.h:57
#define LIST_FOREACH(var, head, field)
Definition: queue.h:332
uint16_t set_endian16(vm_mngr_t *vm_mngr, uint16_t val)
Definition: vm_mngr.c:55
uint64_t access
Definition: vm_mngr.h:99
uint32_t set_endian32(vm_mngr_t *vm_mngr, uint32_t val)
Definition: vm_mngr.c:63
#define EXCEPT_ACCESS_VIOL
Definition: vm_mngr.h:141
#define EXCEPT_BREAKPOINT_INTERN
Definition: vm_mngr.h:134
void * ad_hp
Definition: vm_mngr.h:100
#define PAGE_READ
Definition: vm_mngr.h:123
uint64_t exception_flags
Definition: vm_mngr.h:80
uint64_t ad
Definition: vm_mngr.h:97
uint64_t set_endian64(vm_mngr_t *vm_mngr, uint64_t val)
Definition: vm_mngr.c:71
uint64_t size
Definition: vm_mngr.h:98
struct memory_page_node * get_memory_page_from_address(vm_mngr_t *vm_mngr, uint64_t ad)
Definition: vm_mngr.c:126

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void memory_page_write ( vm_mngr_t vm_mngr,
unsigned int  my_size,
uint64_t  ad,
uint64_t  src 
)
static

Definition at line 246 of file vm_mngr.c.

248 {
249  struct memory_page_node * mpn;
250  unsigned char * addr;
251  struct memory_breakpoint_info * b;
252 
253  mpn = get_memory_page_from_address(vm_mngr, ad);
254  if (!mpn)
255  return;
256 
257  if ((mpn->access & PAGE_WRITE) == 0){
258  fprintf(stderr, "access to non writable page!! %"PRIX64"\n", ad);
260  return ;
261  }
262 
263  /* check read breakpoint*/
264  LIST_FOREACH(b, &vm_mngr->memory_breakpoint_pool, next){
265  if ((b->access & BREAKPOINT_WRITE) == 0)
266  continue;
267  if ((b->ad <= ad) && (ad < b->ad + b->size))
269  }
270 
271  addr = &((unsigned char*)mpn->ad_hp)[ad - mpn->ad];
272 
273  /* write fits in a page */
274  if (ad - mpn->ad + my_size/8 <= mpn->size){
275  switch(my_size){
276  case 8:
277  *((unsigned char*)addr) = src&0xFF;
278  break;
279  case 16:
280  src = set_endian16(vm_mngr, src);
281  *((unsigned short*)addr) = src&0xFFFF;
282  break;
283  case 32:
284  src = set_endian32(vm_mngr, src);
285  *((unsigned int*)addr) = src&0xFFFFFFFF;
286  break;
287  case 64:
288  src = set_endian64(vm_mngr, src);
289  *((uint64_t*)addr) = src&0xFFFFFFFFFFFFFFFFULL;
290  break;
291  default:
292  exit(0);
293  break;
294  }
295  }
296  /* write is multiple page wide */
297  else{
298  //fprintf(stderr, "write multiple page! %"PRIX64" %d\n", ad, my_size);
299  switch(my_size){
300 
301  case 8:
302  src = src;
303  break;
304  case 16:
305  src = set_endian16(vm_mngr, src);
306  break;
307  case 32:
308  src = set_endian32(vm_mngr, src);
309  break;
310  case 64:
311  src = set_endian64(vm_mngr, src);
312  break;
313  default:
314  exit(0);
315  break;
316  }
317  while (my_size){
318  mpn = get_memory_page_from_address(vm_mngr, ad);
319  if (!mpn)
320  return;
321 
322  addr = &((unsigned char*)mpn->ad_hp)[ad - mpn->ad];
323  *((unsigned char*)addr) = src&0xFF;
324  my_size -= 8;
325  src >>=8;
326  ad ++;
327  }
328  }
329 }
struct memory_breakpoint_info_head memory_breakpoint_pool
Definition: vm_mngr.h:72
#define LIST_FOREACH(var, head, field)
Definition: queue.h:332
uint16_t set_endian16(vm_mngr_t *vm_mngr, uint16_t val)
Definition: vm_mngr.c:55
#define PAGE_WRITE
Definition: vm_mngr.h:124
#define BREAKPOINT_WRITE
Definition: vm_mngr.h:58
uint64_t access
Definition: vm_mngr.h:99
uint32_t set_endian32(vm_mngr_t *vm_mngr, uint32_t val)
Definition: vm_mngr.c:63
#define EXCEPT_ACCESS_VIOL
Definition: vm_mngr.h:141
#define EXCEPT_BREAKPOINT_INTERN
Definition: vm_mngr.h:134
void * ad_hp
Definition: vm_mngr.h:100
uint64_t exception_flags
Definition: vm_mngr.h:80
uint64_t ad
Definition: vm_mngr.h:97
uint64_t set_endian64(vm_mngr_t *vm_mngr, uint64_t val)
Definition: vm_mngr.c:71
uint64_t size
Definition: vm_mngr.h:98
struct memory_page_node * get_memory_page_from_address(vm_mngr_t *vm_mngr, uint64_t ad)
Definition: vm_mngr.c:126

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

unsigned int mul_hi_op ( unsigned int  size,
unsigned int  a,
unsigned int  b 
)

Definition at line 698 of file vm_mngr.c.

699 {
700  uint64_t res = 0;
701  unsigned int mask;
702 
703  switch (size) {
704  case 8: mask = 0xff; break;
705  case 16: mask = 0xffff; break;
706  case 32: mask = 0xffffffff; break;
707  default: fprintf(stderr, "inv size in mul %d\n", size); exit(0);
708  }
709 
710  a &= mask;
711  b &= mask;
712  res = ((uint64_t)a * (uint64_t)b);
713  return (res >> 32) & mask;
714 }

+ Here is the call graph for this function:

unsigned int mul_lo_op ( unsigned int  size,
unsigned int  a,
unsigned int  b 
)

Definition at line 682 of file vm_mngr.c.

683 {
684  unsigned int mask;
685 
686  switch (size) {
687  case 8: mask = 0xff; break;
688  case 16: mask = 0xffff; break;
689  case 32: mask = 0xffffffff; break;
690  default: fprintf(stderr, "inv size in mul %d\n", size); exit(0);
691  }
692 
693  a &= mask;
694  b &= mask;
695  return ((int64_t)a * (int64_t) b) & mask;
696 }
unsigned int my_imul08 ( unsigned int  a,
unsigned int  b 
)

Definition at line 952 of file vm_mngr.c.

953 {
954  char a08, b08;
955  short a16;
956 
957  a08 = a&0xFF;
958  b08 = b&0xFF;
959  a16 = a08*b08;
960  return (int)a16;
961 }
unsigned int parity ( unsigned int  a)

Definition at line 545 of file vm_mngr.c.

546 {
547 #if defined(__builtin_parity)
548  return __builtin_parity(a);
549 #else
550  unsigned int tmp, cpt;
551 
552  tmp = a&0xFF;
553  cpt = 1;
554  while (tmp!=0){
555  cpt^=tmp&1;
556  tmp>>=1;
557  }
558  return cpt;
559 #endif
560 }
void print_val ( uint64_t  base,
uint64_t  addr 
)

Definition at line 80 of file vm_mngr.c.

81 {
82  uint64_t *ptr = (uint64_t *) addr;
83  fprintf(stderr, "addr 0x%"PRIX64" val 0x%"PRIX64"\n", addr-base, *ptr);
84 }
int rcl_cf_op ( unsigned int  size,
unsigned int  a,
unsigned int  b,
unsigned int  cf 
)

Definition at line 897 of file vm_mngr.c.

898 {
899  uint64_t tmp;
900 
901  tmp = (cf<< size) | a;
902 
903  size++;
904  b %= size;
905 
906  switch(size){
907  case 8+1:
908  tmp = (tmp << b) | ((tmp&0x1FF) >> (size-b));
909  return (tmp>>8)&1;
910  case 16+1:
911  tmp = (tmp << b) | ((tmp&0x1FFFF) >> (size-b));
912  return (tmp>>16)&1;
913  case 32+1:
914  tmp = (tmp << b) | ((tmp&0x1FFFFFFFFULL) >> (size-b));
915  return (tmp>>32)&1;
916  default:
917  fprintf(stderr, "inv size in rclleft %d\n", size);
918  exit(0);
919  }
920 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int rcl_rez_op ( unsigned int  size,
unsigned int  a,
unsigned int  b,
unsigned int  cf 
)

Definition at line 850 of file vm_mngr.c.

851 {
852  uint64_t tmp;
853 
854 
855  size++;
856  b %= size;
857 
858  if (b == 0) {
859  switch(size){
860  case 8+1:
861  return a&0xff;
862  case 16+1:
863  return a&0xffff;
864  case 32+1:
865  return a&0xffffffff;
866  default:
867  fprintf(stderr, "inv size in rclleft %d\n", size);
868  exit(0);
869  }
870  }
871 
872  tmp = (a<<1) | cf;
873  b -=1;
874  switch(size){
875  case 8+1:
876  tmp = (tmp << b) | ((tmp&0x1FF) >> (size-b));
877  return tmp&0xff;
878  case 16+1:
879  tmp = (tmp << b) | ((tmp&0x1FFFF) >> (size-b));
880  return tmp&0xffff;
881  case 32+1:
882  tmp = (tmp << b) | ((tmp&0x1FFFFFFFFULL) >> (size-b));
883  return tmp&0xffffffff;
884  default:
885  fprintf(stderr, "inv size in rclleft %d\n", size);
886  exit(0);
887  }
888 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int rcr_cf_op ( unsigned int  size,
unsigned int  a,
unsigned int  b,
unsigned int  cf 
)

Definition at line 922 of file vm_mngr.c.

923 {
924  return rcl_cf_op(size, a, size+1-b, cf);
925 }
int rcl_cf_op(unsigned int size, unsigned int a, unsigned int b, unsigned int cf)
Definition: vm_mngr.c:897

+ Here is the call graph for this function:

int rcr_rez_op ( unsigned int  size,
unsigned int  a,
unsigned int  b,
unsigned int  cf 
)

Definition at line 890 of file vm_mngr.c.

891 {
892  return rcl_rez_op(size, a, size+1-b, cf);
893 
894 }
int rcl_rez_op(unsigned int size, unsigned int a, unsigned int b, unsigned int cf)
Definition: vm_mngr.c:850

+ Here is the call graph for this function:

unsigned int rem_op ( unsigned int  size,
unsigned int  a,
unsigned int  b,
unsigned int  c 
)

Definition at line 783 of file vm_mngr.c.

784 {
785  int64_t num;
786 
787  if (c == 0)
788  {
789  //vmmngr.exception_flags |= EXCEPT_INT_DIV_BY_ZERO;
790  return 0;
791  }
792 
793  num = ((int64_t)a << size) + b;
794  num = (int64_t)num-c*(num/c);
795  return num;
796 }
tuple c
Definition: ir2C.py:23

+ Here is the call graph for this function:

void remove_memory_breakpoint ( vm_mngr_t vm_mngr,
uint64_t  ad,
unsigned int  access 
)

Definition at line 1559 of file vm_mngr.c.

1560 {
1561  struct memory_breakpoint_info * mpn;
1562 
1563  LIST_FOREACH(mpn, &vm_mngr->memory_breakpoint_pool, next){
1564  if (mpn->ad == ad && mpn->access == access)
1565  LIST_REMOVE(mpn, next);
1566  }
1567 
1568 }
struct memory_breakpoint_info_head memory_breakpoint_pool
Definition: vm_mngr.h:72
#define LIST_FOREACH(var, head, field)
Definition: queue.h:332
#define LIST_REMOVE(elm, field)
Definition: queue.h:370

+ Here is the caller graph for this function:

void reset_code_bloc_pool ( vm_mngr_t vm_mngr)

Definition at line 1396 of file vm_mngr.c.

1397 {
1398  struct code_bloc_node * cbp;
1399 
1400 
1401  while (!LIST_EMPTY(&vm_mngr->code_bloc_pool)) {
1402  cbp = LIST_FIRST(&vm_mngr->code_bloc_pool);
1403  LIST_REMOVE(cbp, next);
1404  free(cbp);
1405  }
1406  vm_mngr->code_bloc_pool_ad_min = 0xffffffff;
1407  vm_mngr->code_bloc_pool_ad_max = 0;
1408 }
unsigned int code_bloc_pool_ad_min
Definition: vm_mngr.h:77
#define LIST_REMOVE(elm, field)
Definition: queue.h:370
#define LIST_FIRST(head)
Definition: queue.h:330
#define LIST_EMPTY(head)
Definition: queue.h:328
unsigned int code_bloc_pool_ad_max
Definition: vm_mngr.h:78
struct code_bloc_list_head code_bloc_pool
Definition: vm_mngr.h:71

+ Here is the caller graph for this function:

void reset_memory_breakpoint ( vm_mngr_t vm_mngr)

Definition at line 1411 of file vm_mngr.c.

1412 {
1413  struct memory_breakpoint_info * mpn;
1414 
1415  while (!LIST_EMPTY(&vm_mngr->memory_breakpoint_pool)) {
1416  mpn = LIST_FIRST(&vm_mngr->memory_breakpoint_pool);
1417  LIST_REMOVE(mpn, next);
1418  free(mpn);
1419  }
1420 
1421 }
struct memory_breakpoint_info_head memory_breakpoint_pool
Definition: vm_mngr.h:72
#define LIST_REMOVE(elm, field)
Definition: queue.h:370
#define LIST_FIRST(head)
Definition: queue.h:330
#define LIST_EMPTY(head)
Definition: queue.h:328

+ Here is the caller graph for this function:

void reset_memory_page_pool ( vm_mngr_t vm_mngr)

Definition at line 1379 of file vm_mngr.c.

1380 {
1381  struct memory_page_node * mpn;
1382  unsigned int i;
1383 
1384  while (!LIST_EMPTY(&vm_mngr->memory_page_pool)) {
1385  mpn = LIST_FIRST(&vm_mngr->memory_page_pool);
1386  LIST_REMOVE(mpn, next);
1387  free(mpn->ad_hp);
1388  free(mpn);
1389  }
1390  for (i=0;i<MAX_MEMORY_PAGE_POOL_TAB; i++)
1391  vm_mngr->memory_page_pool_tab[i] = NULL;
1392 
1393 }
#define LIST_REMOVE(elm, field)
Definition: queue.h:370
struct memory_page_node * memory_page_pool_tab[MAX_MEMORY_PAGE_POOL_TAB]
Definition: vm_mngr.h:74
#define MAX_MEMORY_PAGE_POOL_TAB
Definition: vm_mngr.h:62
void * ad_hp
Definition: vm_mngr.h:100
#define LIST_FIRST(head)
Definition: queue.h:330
struct memory_page_list_head memory_page_pool
Definition: vm_mngr.h:70
#define LIST_EMPTY(head)
Definition: queue.h:328

+ Here is the caller graph for this function:

uint64_t rot_left ( uint64_t  size,
uint64_t  a,
uint64_t  b 
)

Definition at line 799 of file vm_mngr.c.

800 {
801  uint64_t tmp;
802 
803  b = b&0x3F;
804  b %= size;
805  switch(size){
806  case 8:
807  tmp = (a << b) | ((a&0xFF) >> (size-b));
808  return tmp&0xff;
809  case 16:
810  tmp = (a << b) | ((a&0xFFFF) >> (size-b));
811  return tmp&0xffff;
812  case 32:
813  tmp = (a << b) | ((a&0xFFFFFFFF) >> (size-b));
814  return tmp&0xffffffff;
815  case 64:
816  tmp = (a << b) | ((a&0xFFFFFFFFFFFFFFFF) >> (size-b));
817  return tmp&0xFFFFFFFFFFFFFFFF;
818  default:
819  fprintf(stderr, "inv size in rotleft %"PRIX64"\n", size);
820  exit(0);
821  }
822 }
uint64_t size
Definition: vm_mngr.h:98

+ Here is the call graph for this function:

uint64_t rot_right ( uint64_t  size,
uint64_t  a,
uint64_t  b 
)

Definition at line 824 of file vm_mngr.c.

825 {
826  uint64_t tmp;
827 
828  b = b&0x3F;
829  b %= size;
830  switch(size){
831  case 8:
832  tmp = ((a&0xFF) >> b) | (a << (size-b));
833  return tmp&0xff;
834  case 16:
835  tmp = ((a&0xFFFF) >> b) | (a << (size-b));
836  return tmp&0xffff;
837  case 32:
838  tmp = ((a&0xFFFFFFFF) >> b) | (a << (size-b));
839  return tmp&0xffffffff;
840  case 64:
841  tmp = ((a&0xFFFFFFFFFFFFFFFF) >> b) | (a << (size-b));
842  return tmp&0xFFFFFFFFFFFFFFFF;
843  default:
844  fprintf(stderr, "inv size in rotright %"PRIX64"\n", size);
845  exit(0);
846  }
847 }
uint64_t size
Definition: vm_mngr.h:98

+ Here is the call graph for this function:

uint16_t set_endian16 ( vm_mngr_t vm_mngr,
uint16_t  val 
)

Definition at line 55 of file vm_mngr.c.

56 {
57  if (vm_mngr->sex == __BYTE_ORDER)
58  return val;
59  else
60  return Endian16_Swap(val);
61 }
int sex
Definition: vm_mngr.h:69
#define Endian16_Swap(value)
Definition: vm_mngr.h:29

+ Here is the caller graph for this function:

uint32_t set_endian32 ( vm_mngr_t vm_mngr,
uint32_t  val 
)

Definition at line 63 of file vm_mngr.c.

64 {
65  if (vm_mngr->sex == __BYTE_ORDER)
66  return val;
67  else
68  return Endian32_Swap(val);
69 }
#define Endian32_Swap(value)
Definition: vm_mngr.h:33
int sex
Definition: vm_mngr.h:69

+ Here is the caller graph for this function:

uint64_t set_endian64 ( vm_mngr_t vm_mngr,
uint64_t  val 
)

Definition at line 71 of file vm_mngr.c.

72 {
73  if (vm_mngr->sex == __BYTE_ORDER)
74  return val;
75  else
76  return Endian64_Swap(val);
77 }
int sex
Definition: vm_mngr.h:69
#define Endian64_Swap(value)
Definition: vm_mngr.h:39

+ Here is the caller graph for this function:

uint64_t shift_left_logic ( uint64_t  size,
uint64_t  a,
uint64_t  b 
)

Definition at line 649 of file vm_mngr.c.

650 {
651  switch(size){
652  case 8:
653  return (a<<b)&0xff;
654  case 16:
655  return (a<<b)&0xffff;
656  case 32:
657  return (a<<b)&0xffffffff;
658  case 64:
659  return (a<<b)&0xffffffffffffffff;
660  default:
661  fprintf(stderr, "inv size in shift %"PRIx64"\n", size);
662  exit(0);
663  }
664 }
uint64_t size
Definition: vm_mngr.h:98
int shift_right_arith ( unsigned int  size,
int  a,
unsigned int  b 
)

Definition at line 563 of file vm_mngr.c.

564 {
565  int i32_a;
566  short i16_a;
567  char i8_a;
568  switch(size){
569  case 8:
570  i8_a = a;
571  return (i8_a >> b)&0xff;
572  case 16:
573  i16_a = a;
574  return (i16_a >> b)&0xffff;
575  case 32:
576  i32_a = a;
577  return (i32_a >> b)&0xffffffff;
578  default:
579  fprintf(stderr, "inv size in shift %d\n", size);
580  exit(0);
581  }
582 }
uint64_t size
Definition: vm_mngr.h:98
uint64_t shift_right_logic ( uint64_t  size,
uint64_t  a,
uint64_t  b 
)

Definition at line 605 of file vm_mngr.c.

607 {
608  uint64_t u32_a;
609  unsigned short u16_a;
610  unsigned char u8_a;
611  switch(size){
612  case 8:
613  u8_a = a;
614  return (u8_a >> b)&0xff;
615  case 16:
616  u16_a = a;
617  return (u16_a >> b)&0xffff;
618  case 32:
619  u32_a = a;
620  return (u32_a >> b)&0xffffffff;
621  default:
622  fprintf(stderr, "inv size in shift %"PRIx64"\n", size);
623  exit(0);
624  }
625 }
uint64_t size
Definition: vm_mngr.h:98
unsigned int umul16_hi ( unsigned short  a,
unsigned short  b 
)

Definition at line 759 of file vm_mngr.c.

760 {
761  uint32_t c;
762  c = a*b;
763  return (c>>16) & 0xffff;
764 }
tuple c
Definition: ir2C.py:23

+ Here is the call graph for this function:

unsigned int umul16_lo ( unsigned short  a,
unsigned short  b 
)

Definition at line 754 of file vm_mngr.c.

755 {
756  return (a*b) & 0xffff;
757 }
unsigned char vm_MEM_LOOKUP_08 ( vm_mngr_t vm_mngr,
uint64_t  addr 
)

Definition at line 460 of file vm_mngr.c.

461 {
462  unsigned char ret;
463  ret = memory_page_read(vm_mngr, 8, addr);
464  return ret;
465 }
static uint64_t memory_page_read(vm_mngr_t *vm_mngr, unsigned int my_size, uint64_t ad)
Definition: vm_mngr.c:158

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

unsigned short vm_MEM_LOOKUP_16 ( vm_mngr_t vm_mngr,
uint64_t  addr 
)

Definition at line 466 of file vm_mngr.c.

467 {
468  unsigned short ret;
469  ret = memory_page_read(vm_mngr, 16, addr);
470  return ret;
471 }
static uint64_t memory_page_read(vm_mngr_t *vm_mngr, unsigned int my_size, uint64_t ad)
Definition: vm_mngr.c:158

+ Here is the call graph for this function:

unsigned int vm_MEM_LOOKUP_32 ( vm_mngr_t vm_mngr,
uint64_t  addr 
)

Definition at line 472 of file vm_mngr.c.

473 {
474  unsigned int ret;
475  ret = memory_page_read(vm_mngr, 32, addr);
476  return ret;
477 }
static uint64_t memory_page_read(vm_mngr_t *vm_mngr, unsigned int my_size, uint64_t ad)
Definition: vm_mngr.c:158

+ Here is the call graph for this function:

uint64_t vm_MEM_LOOKUP_64 ( vm_mngr_t vm_mngr,
uint64_t  addr 
)

Definition at line 478 of file vm_mngr.c.

479 {
480  uint64_t ret;
481  ret = memory_page_read(vm_mngr, 64, addr);
482  return ret;
483 }
static uint64_t memory_page_read(vm_mngr_t *vm_mngr, unsigned int my_size, uint64_t ad)
Definition: vm_mngr.c:158

+ Here is the call graph for this function:

void vm_MEM_WRITE_08 ( vm_mngr_t vm_mngr,
uint64_t  addr,
unsigned char  src 
)

Definition at line 438 of file vm_mngr.c.

439 {
440  check_write_code_bloc(vm_mngr, 8, addr);
441  memory_page_write(vm_mngr, 8, addr, src);
442 }
static void memory_page_write(vm_mngr_t *vm_mngr, unsigned int my_size, uint64_t ad, uint64_t src)
Definition: vm_mngr.c:246
void check_write_code_bloc(vm_mngr_t *vm_mngr, uint64_t my_size, uint64_t addr)
Definition: vm_mngr.c:391

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void vm_MEM_WRITE_16 ( vm_mngr_t vm_mngr,
uint64_t  addr,
unsigned short  src 
)

Definition at line 444 of file vm_mngr.c.

445 {
446  check_write_code_bloc(vm_mngr, 16, addr);
447  memory_page_write(vm_mngr, 16, addr, src);
448 }
static void memory_page_write(vm_mngr_t *vm_mngr, unsigned int my_size, uint64_t ad, uint64_t src)
Definition: vm_mngr.c:246
void check_write_code_bloc(vm_mngr_t *vm_mngr, uint64_t my_size, uint64_t addr)
Definition: vm_mngr.c:391

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void vm_MEM_WRITE_32 ( vm_mngr_t vm_mngr,
uint64_t  addr,
unsigned int  src 
)

Definition at line 449 of file vm_mngr.c.

450 {
451  check_write_code_bloc(vm_mngr, 32, addr);
452  memory_page_write(vm_mngr, 32, addr, src);
453 }
static void memory_page_write(vm_mngr_t *vm_mngr, unsigned int my_size, uint64_t ad, uint64_t src)
Definition: vm_mngr.c:246
void check_write_code_bloc(vm_mngr_t *vm_mngr, uint64_t my_size, uint64_t addr)
Definition: vm_mngr.c:391

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void vm_MEM_WRITE_64 ( vm_mngr_t vm_mngr,
uint64_t  addr,
uint64_t  src 
)

Definition at line 454 of file vm_mngr.c.

455 {
456  check_write_code_bloc(vm_mngr, 64, addr);
457  memory_page_write(vm_mngr, 64, addr, src);
458 }
static void memory_page_write(vm_mngr_t *vm_mngr, unsigned int my_size, uint64_t ad, uint64_t src)
Definition: vm_mngr.c:246
void check_write_code_bloc(vm_mngr_t *vm_mngr, uint64_t my_size, uint64_t addr)
Definition: vm_mngr.c:391

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int vm_read_mem ( vm_mngr_t vm_mngr,
uint64_t  addr,
char **  buffer_ptr,
uint64_t  size 
)

Definition at line 486 of file vm_mngr.c.

487 {
488  char* buffer;
489  uint64_t len;
490  struct memory_page_node * mpn;
491 
492  buffer = malloc(size);
493  *buffer_ptr = buffer;
494  if (!buffer){
495  fprintf(stderr, "cannot alloc read\n");
496  exit(-1);
497  }
498 
499  /* read is multiple page wide */
500  while (size){
501  mpn = get_memory_page_from_address(vm_mngr, addr);
502  if (!mpn){
503  free(*buffer_ptr);
504  PyErr_SetString(PyExc_RuntimeError, "cannot find address");
505  return -1;
506  }
507 
508  len = MIN(size, mpn->size - (addr - mpn->ad));
509  memcpy(buffer, (char*)(mpn->ad_hp + (addr - mpn->ad)), len);
510  buffer += len;
511  addr += len;
512  size -= len;
513  }
514 
515  return 0;
516 }
void * ad_hp
Definition: vm_mngr.h:100
uint64_t ad
Definition: vm_mngr.h:97
#define MIN(a, b)
Definition: vm_mngr.c:47
uint64_t size
Definition: vm_mngr.h:98
struct memory_page_node * get_memory_page_from_address(vm_mngr_t *vm_mngr, uint64_t ad)
Definition: vm_mngr.c:126

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int vm_write_mem ( vm_mngr_t vm_mngr,
uint64_t  addr,
char *  buffer,
uint64_t  size 
)

Definition at line 518 of file vm_mngr.c.

519 {
520  uint64_t len;
521  struct memory_page_node * mpn;
522 
523  check_write_code_bloc(vm_mngr, size * 8, addr);
524 
525  /* write is multiple page wide */
526  while (size){
527  mpn = get_memory_page_from_address(vm_mngr, addr);
528  if (!mpn){
529  PyErr_SetString(PyExc_RuntimeError, "cannot find address");
530  return -1;
531  }
532 
533  len = MIN(size, mpn->size - (addr - mpn->ad));
534  memcpy(mpn->ad_hp + (addr-mpn->ad), buffer, len);
535  buffer += len;
536  addr += len;
537  size -= len;
538  }
539 
540  return 0;
541 }
void check_write_code_bloc(vm_mngr_t *vm_mngr, uint64_t my_size, uint64_t addr)
Definition: vm_mngr.c:391
void * ad_hp
Definition: vm_mngr.h:100
uint64_t ad
Definition: vm_mngr.h:97
#define MIN(a, b)
Definition: vm_mngr.c:47
uint64_t size
Definition: vm_mngr.h:98
struct memory_page_node * get_memory_page_from_address(vm_mngr_t *vm_mngr, uint64_t ad)
Definition: vm_mngr.c:126

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

unsigned int x86_bsf ( uint64_t  src,
unsigned int  size 
)

Definition at line 939 of file vm_mngr.c.

940 {
941  int i;
942 
943  for (i=0; i<size; i++){
944  if (src & (1<<i))
945  return i;
946  }
947  fprintf(stderr, "sanity check error bsf\n");
948  exit(0);
949 }
uint64_t size
Definition: vm_mngr.h:98
unsigned int x86_bsr ( uint64_t  src,
unsigned int  size 
)

Definition at line 927 of file vm_mngr.c.

928 {
929  int i;
930 
931  for (i=size-1; i>=0; i--){
932  if (src & (1<<i))
933  return i;
934  }
935  fprintf(stderr, "sanity check error bsr\n");
936  exit(0);
937 }
uint64_t size
Definition: vm_mngr.h:98