Rizin
unix-like reverse engineering framework and cli tools
vle.c File Reference
#include "vle.h"
#include "vle_internal.h"
#include <rz_analysis.h>

Go to the source code of this file.

Macros

#define USE_INTERNAL_PPC(x)   ((x)->options & VLE_INTERNAL_PPC)
 
#define E_NONE   0
 
#define E_BD15   1
 
#define E_BD15b   2
 
#define E_BD15c   3
 
#define E_BD24   4
 
#define E_D   5
 
#define E_D8   6
 
#define E_D8_N   7
 
#define E_I16A   8
 
#define E_I16L   9
 
#define E_I16LS   10
 
#define E_IA16   11
 
#define E_IA16U   12
 
#define E_LI20   13
 
#define E_M   14
 
#define E_SCI8   15
 
#define E_SCI8CR   16
 
#define E_SCI8I   17
 
#define E_X   18
 
#define E_XCR   19
 
#define E_XL   20
 
#define E_XLSP   21
 
#define E_XRA   22
 
#define E_MASK_X   0x03FFF800
 
#define E_MASK_XL   0x03FFF801
 
#define E_MASK_D   0x03FFFFFF
 
#define E_MASK_D8   0x03FF00FF
 
#define E_MASK_I16A   0x03FF07FF
 
#define E_MASK_SCI8   0x03FF07FF
 
#define E_MASK_I16L   0x03FF07FF
 
#define E_MASK_BD24   0x03FFFFFE
 
#define E_MASK_BD15   0x000CFFFE
 
#define E_MASK_IA16   0x03FF07FF
 
#define E_MASK_LI20   0x03FF7FFF
 
#define E_MASK_M   0x03FFFFFE
 
#define F_NONE   0
 
#define F_X   1
 
#define F_XO   2
 
#define F_EVX   3
 
#define F_CMP   4
 
#define F_DCBF   5
 
#define F_DCBL   6
 
#define F_DCI   7
 
#define F_EXT   8
 
#define F_A   9
 
#define F_XFX   10
 
#define F_XER   11
 
#define F_MFPR   12
 
#define F_MTPR   13
 
#define F_X_EI   14
 
#define F_XRA   15
 
#define F_MASK_X   0x03FFF800
 
#define F_MASK_XO   0x03FFF800
 
#define F_MASK_EVX   0x03FFF800
 
#define F_MASK_CMP   0x039FF800
 
#define F_MASK_DCBF   0x00FFF800
 
#define F_MASK_DCBL   0x01FFF800
 
#define F_MASK_DCI   0x00FFF800
 
#define F_MASK_EXT   0x03FF0000
 
#define F_MASK_A   0x01FFFFC0
 
#define F_MASK_XFX   0x03FFF800
 
#define F_MASK_XER   0x03FFF800
 
#define F_MASK_MFPR   0x03FFF800
 
#define F_MASK_MTPR   0x03FFF800
 

Functions

static void set_e_fields (vle_t *v, const e_vle_t *p, ut32 data)
 
static void set_ppc_fields (vle_t *v, const ppc_t *p, ut32 data)
 
static vle_tfind_ppc (const ut8 *buffer)
 
static vle_tfind_e (const ut8 *buffer)
 
static vle_tfind_se (const ut8 *buffer)
 
int vle_init (vle_handle *handle, const ut8 *buffer, const ut32 size)
 
int vle_option (vle_handle *handle, ut32 option)
 
vle_tvle_next (vle_handle *handle)
 
void vle_free (vle_t *instr)
 
void vle_snprint (char *str, int size, ut32 addr, vle_t *instr)
 

Variables

const ppc_t ppc_ops []
 
const e_vle_t e_ops []
 
const se_vle_t se_ops []
 

Macro Definition Documentation

◆ E_BD15

#define E_BD15   1

Definition at line 10 of file vle.c.

◆ E_BD15b

#define E_BD15b   2

Definition at line 11 of file vle.c.

◆ E_BD15c

#define E_BD15c   3

Definition at line 12 of file vle.c.

◆ E_BD24

#define E_BD24   4

Definition at line 13 of file vle.c.

◆ E_D

#define E_D   5

Definition at line 14 of file vle.c.

◆ E_D8

#define E_D8   6

Definition at line 15 of file vle.c.

◆ E_D8_N

#define E_D8_N   7

Definition at line 16 of file vle.c.

◆ E_I16A

#define E_I16A   8

Definition at line 17 of file vle.c.

◆ E_I16L

#define E_I16L   9

Definition at line 18 of file vle.c.

◆ E_I16LS

#define E_I16LS   10

Definition at line 19 of file vle.c.

◆ E_IA16

#define E_IA16   11

Definition at line 20 of file vle.c.

◆ E_IA16U

#define E_IA16U   12

Definition at line 21 of file vle.c.

◆ E_LI20

#define E_LI20   13

Definition at line 22 of file vle.c.

◆ E_M

#define E_M   14

Definition at line 23 of file vle.c.

◆ E_MASK_BD15

#define E_MASK_BD15   0x000CFFFE

Definition at line 41 of file vle.c.

◆ E_MASK_BD24

#define E_MASK_BD24   0x03FFFFFE

Definition at line 40 of file vle.c.

◆ E_MASK_D

#define E_MASK_D   0x03FFFFFF

Definition at line 35 of file vle.c.

◆ E_MASK_D8

#define E_MASK_D8   0x03FF00FF

Definition at line 36 of file vle.c.

◆ E_MASK_I16A

#define E_MASK_I16A   0x03FF07FF

Definition at line 37 of file vle.c.

◆ E_MASK_I16L

#define E_MASK_I16L   0x03FF07FF

Definition at line 39 of file vle.c.

◆ E_MASK_IA16

#define E_MASK_IA16   0x03FF07FF

Definition at line 42 of file vle.c.

◆ E_MASK_LI20

#define E_MASK_LI20   0x03FF7FFF

Definition at line 43 of file vle.c.

◆ E_MASK_M

#define E_MASK_M   0x03FFFFFE

Definition at line 44 of file vle.c.

◆ E_MASK_SCI8

#define E_MASK_SCI8   0x03FF07FF

Definition at line 38 of file vle.c.

◆ E_MASK_X

#define E_MASK_X   0x03FFF800

Definition at line 33 of file vle.c.

◆ E_MASK_XL

#define E_MASK_XL   0x03FFF801

Definition at line 34 of file vle.c.

◆ E_NONE

#define E_NONE   0

Definition at line 9 of file vle.c.

◆ E_SCI8

#define E_SCI8   15

Definition at line 24 of file vle.c.

◆ E_SCI8CR

#define E_SCI8CR   16

Definition at line 25 of file vle.c.

◆ E_SCI8I

#define E_SCI8I   17

Definition at line 26 of file vle.c.

◆ E_X

#define E_X   18

Definition at line 27 of file vle.c.

◆ E_XCR

#define E_XCR   19

Definition at line 28 of file vle.c.

◆ E_XL

#define E_XL   20

Definition at line 29 of file vle.c.

◆ E_XLSP

#define E_XLSP   21

Definition at line 30 of file vle.c.

◆ E_XRA

#define E_XRA   22

Definition at line 31 of file vle.c.

◆ F_A

#define F_A   9

Definition at line 55 of file vle.c.

◆ F_CMP

#define F_CMP   4

Definition at line 50 of file vle.c.

◆ F_DCBF

#define F_DCBF   5

Definition at line 51 of file vle.c.

◆ F_DCBL

#define F_DCBL   6

Definition at line 52 of file vle.c.

◆ F_DCI

#define F_DCI   7

Definition at line 53 of file vle.c.

◆ F_EVX

#define F_EVX   3

Definition at line 49 of file vle.c.

◆ F_EXT

#define F_EXT   8

Definition at line 54 of file vle.c.

◆ F_MASK_A

#define F_MASK_A   0x01FFFFC0

Definition at line 71 of file vle.c.

◆ F_MASK_CMP

#define F_MASK_CMP   0x039FF800

Definition at line 66 of file vle.c.

◆ F_MASK_DCBF

#define F_MASK_DCBF   0x00FFF800

Definition at line 67 of file vle.c.

◆ F_MASK_DCBL

#define F_MASK_DCBL   0x01FFF800

Definition at line 68 of file vle.c.

◆ F_MASK_DCI

#define F_MASK_DCI   0x00FFF800

Definition at line 69 of file vle.c.

◆ F_MASK_EVX

#define F_MASK_EVX   0x03FFF800

Definition at line 65 of file vle.c.

◆ F_MASK_EXT

#define F_MASK_EXT   0x03FF0000

Definition at line 70 of file vle.c.

◆ F_MASK_MFPR

#define F_MASK_MFPR   0x03FFF800

Definition at line 74 of file vle.c.

◆ F_MASK_MTPR

#define F_MASK_MTPR   0x03FFF800

Definition at line 75 of file vle.c.

◆ F_MASK_X

#define F_MASK_X   0x03FFF800

Definition at line 63 of file vle.c.

◆ F_MASK_XER

#define F_MASK_XER   0x03FFF800

Definition at line 73 of file vle.c.

◆ F_MASK_XFX

#define F_MASK_XFX   0x03FFF800

Definition at line 72 of file vle.c.

◆ F_MASK_XO

#define F_MASK_XO   0x03FFF800

Definition at line 64 of file vle.c.

◆ F_MFPR

#define F_MFPR   12

Definition at line 58 of file vle.c.

◆ F_MTPR

#define F_MTPR   13

Definition at line 59 of file vle.c.

◆ F_NONE

#define F_NONE   0

Definition at line 46 of file vle.c.

◆ F_X

#define F_X   1

Definition at line 47 of file vle.c.

◆ F_X_EI

#define F_X_EI   14

Definition at line 60 of file vle.c.

◆ F_XER

#define F_XER   11

Definition at line 57 of file vle.c.

◆ F_XFX

#define F_XFX   10

Definition at line 56 of file vle.c.

◆ F_XO

#define F_XO   2

Definition at line 48 of file vle.c.

◆ F_XRA

#define F_XRA   15

Definition at line 61 of file vle.c.

◆ USE_INTERNAL_PPC

#define USE_INTERNAL_PPC (   x)    ((x)->options & VLE_INTERNAL_PPC)

Definition at line 7 of file vle.c.

Function Documentation

◆ find_e()

static vle_t* find_e ( const ut8 buffer)
static

Definition at line 813 of file vle.c.

813  {
814  ut32 i;
815  ut32 data = (buffer[0] << 24) | (buffer[1] << 16) | (buffer[2] << 8) | buffer[3];
816  const e_vle_t *p = NULL;
817  const ut32 size = sizeof(e_ops) / sizeof(e_vle_t);
818  for (i = 0; i < size; i++) {
819  p = &e_ops[i];
820  if ((p->op & data) == p->op && (p->mask & data) == data) {
821  vle_t *ret = RZ_NEW0(vle_t);
822  ret->name = p->name;
823  ret->size = 4;
824  ret->n = 0;
825  ret->analysis_op = p->analysis_op;
826  set_e_fields(ret, p, data);
827  return ret;
828  }
829  }
830  return NULL;
831 }
lzma_index ** i
Definition: index.h:629
#define NULL
Definition: cris-opc.c:27
uint32_t ut32
voidpf void uLong size
Definition: ioapi.h:138
void * p
Definition: libc.cpp:67
#define RZ_NEW0(x)
Definition: rz_types.h:284
Definition: buffer.h:15
Definition: vle.h:30
const char * name
Definition: vle.h:31
ut16 size
Definition: vle.h:34
ut16 n
Definition: vle.h:33
ut32 analysis_op
Definition: vle.h:35
const e_vle_t e_ops[]
Definition: vle.c:240
static void set_e_fields(vle_t *v, const e_vle_t *p, ut32 data)
Definition: vle.c:429

References vle_t::analysis_op, e_ops, i, vle_t::n, vle_t::name, NULL, p, RZ_NEW0, set_e_fields(), and vle_t::size.

Referenced by vle_next().

◆ find_ppc()

static vle_t* find_ppc ( const ut8 buffer)
static

Definition at line 793 of file vle.c.

793  {
794  ut32 i;
795  ut32 data = (buffer[0] << 24) | (buffer[1] << 16) | (buffer[2] << 8) | buffer[3];
796  const ppc_t *p = NULL;
797  const ut32 size = sizeof(ppc_ops) / sizeof(ppc_t);
798  for (i = 0; i < size; i++) {
799  p = &ppc_ops[i];
800  if ((p->op & data) == p->op && (p->mask & data) == data) {
801  vle_t *ret = RZ_NEW0(vle_t);
802  ret->name = p->name;
803  ret->size = 4;
804  ret->n = 0;
805  ret->analysis_op = p->analysis_op;
806  set_ppc_fields(ret, p, data);
807  return ret;
808  }
809  }
810  return NULL;
811 }
static void set_ppc_fields(vle_t *v, const ppc_t *p, ut32 data)
Definition: vle.c:671
const ppc_t ppc_ops[]
Definition: vle.c:77

References vle_t::analysis_op, i, vle_t::n, vle_t::name, NULL, p, ppc_ops, RZ_NEW0, set_ppc_fields(), and vle_t::size.

Referenced by vle_next().

◆ find_se()

static vle_t* find_se ( const ut8 buffer)
static

Definition at line 833 of file vle.c.

833  {
834  ut32 i, j, k;
835  ut16 data = (buffer[0] << 8) | buffer[1];
836  const se_vle_t *p = NULL;
837  const ut32 size = sizeof(se_ops) / sizeof(se_vle_t);
838  for (i = 0; i < size; i++) {
839  p = &se_ops[i];
840  if ((p->op & data) == p->op && (p->mask & data) == data) {
841  vle_t *ret = RZ_NEW0(vle_t);
842  ret->name = p->name;
843  ret->size = 2;
844  ret->analysis_op = p->analysis_op;
845  for (j = 0; j < p->n; j++) {
846  for (k = 0; k < p->n; k++) {
847  if (p->fields[k].idx == j) {
848  ret->fields[j].value = data & p->fields[k].mask;
849  ret->fields[j].value >>= p->fields[k].shr;
850  ret->fields[j].value <<= p->fields[k].shl;
851  ret->fields[j].value += p->fields[k].add;
852  ret->fields[j].value &= 0xFFFF;
853  if (p->fields[k].type == TYPE_REG && ret->fields[j].value & 0x8) {
854  ret->fields[j].value = (ret->fields[j].value & 0x7) + 24;
855  } else if (p->fields[k].type == TYPE_JMP && ret->fields[j].value & 0x0100) {
856  ret->fields[j].value = 0xFFFFFE00 | ret->fields[j].value;
857  }
858  ret->fields[j].type = p->fields[k].type;
859  break;
860  }
861  }
862  }
863  ret->n = p->n;
864  return ret;
865  }
866  }
867  return NULL;
868 }
uint16_t ut16
const char * k
Definition: dsignal.c:11
#define TYPE_REG
Definition: mcore.h:22
#define TYPE_JMP
Definition: mcore.h:25
ut16 type
Definition: vle.h:27
ut32 value
Definition: vle.h:26
vle_field_t fields[10]
Definition: vle.h:32
const se_vle_t se_ops[]
Definition: vle.c:354

References vle_t::analysis_op, vle_t::fields, i, k, vle_t::n, vle_t::name, NULL, p, RZ_NEW0, se_ops, vle_t::size, vle_field_t::type, TYPE_JMP, TYPE_REG, and vle_field_t::value.

Referenced by vle_next().

◆ set_e_fields()

static void set_e_fields ( vle_t v,
const e_vle_t p,
ut32  data 
)
static

Definition at line 429 of file vle.c.

429  {
430  if (!v) {
431  return;
432  }
433  switch (p->type) {
434  case E_X: {
435  v->n = 3;
436  v->fields[0].value = (data & 0x3E00000) >> 21;
437  v->fields[0].type = p->types[0];
438  v->fields[1].value = (data & 0x1F0000) >> 16;
439  v->fields[1].type = p->types[1];
440  v->fields[2].value = (data & 0xF800) >> 11;
441  v->fields[2].type = p->types[2];
442  } break;
443  case E_XRA: {
444  v->n = 3;
445  v->fields[0].value = (data & 0x1F0000) >> 16;
446  v->fields[0].type = p->types[0];
447  v->fields[1].value = (data & 0x3E00000) >> 21;
448  v->fields[1].type = p->types[1];
449  v->fields[2].value = (data & 0xF800) >> 11;
450  v->fields[2].type = p->types[2];
451  } break;
452  case E_XL: {
453  v->n = 3;
454  v->fields[0].value = (data & 0x3E00000) >> 21;
455  v->fields[0].type = p->types[0];
456  v->fields[1].value = (data & 0x1F0000) >> 16;
457  v->fields[1].type = p->types[1];
458  v->fields[2].value = (data & 0xF800) >> 11;
459  v->fields[2].type = p->types[2];
460  } break;
461  case E_D: {
462  v->n = 3;
463  v->fields[0].value = (data & 0x3E00000) >> 21;
464  v->fields[0].type = p->types[0];
465  v->fields[1].value = (data & 0x1F0000) >> 16;
466  v->fields[1].type = p->types[1];
467  v->fields[2].value = data & 0xFFFF;
468  if (v->fields[2].value & 0x8000) {
469  v->fields[2].value = 0xFFFF0000 | v->fields[2].value;
470  }
471  v->fields[2].type = p->types[2];
472  } break;
473  case E_D8: {
474  v->n = 3;
475  v->fields[0].value = (data & 0x3E00000) >> 21;
476  v->fields[0].type = p->types[0];
477  v->fields[1].value = (data & 0x1F0000) >> 16;
478  v->fields[1].type = p->types[1];
479  v->fields[2].value = data & 0xFF;
480  if (v->fields[2].value & 0x80) {
481  v->fields[2].value = 0xFFFFFF00 | v->fields[2].value;
482  }
483  v->fields[2].type = p->types[2];
484  } break;
485  case E_D8_N: {
486  v->n = 2;
487  v->fields[0].value = (data & 0x1F0000) >> 16;
488  v->fields[0].type = p->types[0];
489  v->fields[1].value = data & 0xFF;
490  if (v->fields[1].value & 0x80) {
491  v->fields[1].value = 0xFFFFFF00 | v->fields[1].value;
492  }
493  v->fields[1].type = p->types[1];
494  } break;
495  case E_IA16U: {
496  v->n = 2;
497  v->fields[1].value = (data & 0x3E00000) >> 10;
498  v->fields[1].type = p->types[0];
499  v->fields[0].value = (data & 0x1F0000) >> 16;
500  v->fields[0].type = p->types[1];
501  v->fields[1].value |= (data & 0x7FF);
502  } break;
503  case E_IA16:
504  case E_I16A: {
505  v->n = 2;
506  v->fields[1].value = (data & 0x3E00000) >> 10;
507  v->fields[1].type = p->types[0];
508  v->fields[0].value = (data & 0x1F0000) >> 16;
509  v->fields[0].type = p->types[1];
510  v->fields[1].value |= (data & 0x7FF);
511  if (v->fields[1].value & 0x8000) {
512  v->fields[1].value = 0xFFFF0000 | v->fields[1].value;
513  }
514  } break;
515  case E_SCI8:
516  case E_SCI8CR: {
517  v->n = 3;
518  v->fields[0].value = (data & 0x3E00000) >> 21;
519  v->fields[0].type = p->types[0];
520  if (p->type == E_SCI8CR) {
521  v->fields[0].value &= 0x3;
522  }
523  v->fields[1].value = (data & 0x1F0000) >> 16;
524  v->fields[1].type = p->types[1];
525  ut32 ui8 = data & 0xFF;
526  ut32 scl = (data & 0x300) >> 8;
527  ut32 f = data & 0x400;
528  switch (scl) {
529  case 0:
530  v->fields[2].value = ui8 | (f ? 0xffffff00 : 0);
531  break;
532  case 1:
533  v->fields[2].value = (ui8 << 8) | (f ? 0xffff00ff : 0);
534  break;
535  case 2:
536  v->fields[2].value = (ui8 << 16) | (f ? 0xff00ffff : 0);
537  break;
538  default:
539  v->fields[2].value = (ui8 << 24) | (f ? 0x00ffffff : 0);
540  break;
541  }
542  v->fields[2].type = p->types[2];
543  } break;
544  case E_SCI8I: {
545  v->n = 3;
546  v->fields[1].value = (data & 0x3E00000) >> 21;
547  v->fields[1].type = p->types[0];
548  v->fields[0].value = (data & 0x1F0000) >> 16;
549  v->fields[0].type = p->types[1];
550  ut32 ui8 = data & 0xFF;
551  ut32 scl = (data & 0x300) >> 8;
552  ut32 f = data & 0x400;
553  switch (scl) {
554  case 0:
555  v->fields[2].value = ui8 | (f ? 0xffffff00 : 0);
556  break;
557  case 1:
558  v->fields[2].value = (ui8 << 8) | (f ? 0xffff00ff : 0);
559  break;
560  case 2:
561  v->fields[2].value = (ui8 << 16) | (f ? 0xff00ffff : 0);
562  break;
563  default:
564  v->fields[2].value = (ui8 << 24) | (f ? 0x00ffffff : 0);
565  break;
566  }
567  v->fields[2].type = p->types[2];
568  } break;
569  case E_I16L: {
570  v->n = 2;
571  v->fields[0].value = (data & 0x3E00000) >> 21;
572  v->fields[0].type = p->types[0];
573  v->fields[1].value = (data & 0x1F0000) >> 5;
574  v->fields[1].value |= (data & 0x7FF);
575  v->fields[1].type = p->types[1];
576  } break;
577  case E_I16LS: {
578  v->n = 2;
579  v->fields[0].value = (data & 0x3E00000) >> 21;
580  v->fields[0].type = p->types[0];
581  v->fields[1].value = (data & 0x1F0000) >> 5;
582  v->fields[1].value |= (data & 0x7FF);
583  v->fields[1].type = p->types[1];
584  } break;
585  case E_BD24: {
586  v->n = 1;
587  v->fields[0].value = data & 0x3FFFFFE;
588  if (v->fields[0].value & 0x1000000) {
589  v->fields[0].value |= 0xFE000000;
590  }
591  v->fields[0].type = p->types[0];
592  } break;
593  case E_BD15: {
594  v->n = 2;
595  v->fields[0].value = (data & 0xC0000) >> 18;
596  v->fields[0].type = p->types[0];
597  v->fields[1].value = data & 0xFFFE;
598  if (v->fields[1].value & 0x8000) {
599  v->fields[1].value |= 0xFFFF0000;
600  }
601  v->fields[1].type = p->types[1];
602  } break;
603  case E_BD15b: {
604  v->n = 3;
605  v->fields[0].value = (data & 0x300000) >> 20;
606  v->fields[0].type = p->types[0];
607  v->fields[1].value = (data & 0xF0000) >> 16;
608  v->fields[1].type = p->types[0];
609  v->fields[2].value = data & 0xFFFE;
610  if (v->fields[2].value & 0x8000) {
611  v->fields[2].value |= 0xFFFF0000;
612  }
613  v->fields[2].type = p->types[2];
614  } break;
615  case E_BD15c: {
616  v->n = 1;
617  v->fields[0].value = data & 0xFFFE;
618  if (v->fields[0].value & 0x8000) {
619  v->fields[0].value |= 0xFFFF0000;
620  }
621  v->fields[0].type = p->types[0];
622  } break;
623  case E_LI20: {
624  v->n = 2;
625  v->fields[0].value = (data & 0x03E00000) >> 21;
626  v->fields[0].type = p->types[0];
627  v->fields[1].value = ((data & 0x001F0000) >> 5);
628  v->fields[1].value |= ((data & 0x7800) << 5);
629  v->fields[1].value |= (data & 0x7FF);
630  v->fields[1].type = p->types[1];
631  if (v->fields[1].value & 0x80000) {
632  v->fields[1].value = 0xFFF00000 | v->fields[1].value;
633  }
634  } break;
635  case E_M: {
636  v->n = 5;
637  v->fields[1].value = (data & 0x3E00000) >> 21;
638  v->fields[1].type = p->types[1];
639  v->fields[0].value = (data & 0x1F0000) >> 16;
640  v->fields[0].type = p->types[0];
641  v->fields[2].value = (data & 0xF800) >> 11;
642  v->fields[2].type = p->types[2];
643  v->fields[3].value = (data & 0x7C0) >> 6;
644  v->fields[3].type = p->types[3];
645  v->fields[4].value = (data & 0x3E) >> 1;
646  v->fields[4].type = p->types[4];
647  } break;
648  case E_XCR: {
649  v->n = 3;
650  v->fields[0].value = (data & 0x3000000) >> 24;
651  v->fields[0].type = p->types[0];
652  v->fields[1].value = (data & 0x1F0000) >> 16;
653  v->fields[1].type = p->types[1];
654  v->fields[2].value = (data & 0xF800) >> 11;
655  v->fields[2].type = p->types[2];
656  } break;
657  case E_XLSP: {
658  v->n = 3;
659  v->fields[0].value = (data & 0x3800000) >> 23;
660  v->fields[0].type = p->types[0];
661  v->fields[1].value = (data & 0x1C0000) >> 18;
662  v->fields[1].type = p->types[1];
663  } break;
664  case E_NONE:
665  default:
666  v->n = 0;
667  break;
668  }
669 }
const char * v
Definition: dsignal.c:12
#define f(i)
Definition: sha256.c:46
#define E_X
Definition: vle.c:27
#define E_I16A
Definition: vle.c:17
#define E_IA16U
Definition: vle.c:21
#define E_D8_N
Definition: vle.c:16
#define E_BD24
Definition: vle.c:13
#define E_IA16
Definition: vle.c:20
#define E_XCR
Definition: vle.c:28
#define E_LI20
Definition: vle.c:22
#define E_BD15c
Definition: vle.c:12
#define E_NONE
Definition: vle.c:9
#define E_BD15
Definition: vle.c:10
#define E_BD15b
Definition: vle.c:11
#define E_XL
Definition: vle.c:29
#define E_D
Definition: vle.c:14
#define E_M
Definition: vle.c:23
#define E_SCI8I
Definition: vle.c:26
#define E_XRA
Definition: vle.c:31
#define E_SCI8
Definition: vle.c:24
#define E_XLSP
Definition: vle.c:30
#define E_I16LS
Definition: vle.c:19
#define E_SCI8CR
Definition: vle.c:25
#define E_I16L
Definition: vle.c:18
#define E_D8
Definition: vle.c:15

References E_BD15, E_BD15b, E_BD15c, E_BD24, E_D, E_D8, E_D8_N, E_I16A, E_I16L, E_I16LS, E_IA16, E_IA16U, E_LI20, E_M, E_NONE, E_SCI8, E_SCI8CR, E_SCI8I, E_X, E_XCR, E_XL, E_XLSP, E_XRA, f, p, and v.

Referenced by find_e().

◆ set_ppc_fields()

static void set_ppc_fields ( vle_t v,
const ppc_t p,
ut32  data 
)
static

Definition at line 671 of file vle.c.

671  {
672  if (!v) {
673  return;
674  }
675  switch (p->type) {
676  case F_X:
677  case F_XO:
678  case F_EVX: {
679  v->n = 0;
680  if (p->types[0] != TYPE_NONE) {
681  v->fields[0].value = (data & 0x3E00000) >> 21;
682  v->fields[0].type = p->types[0];
683  v->n++;
684  }
685  if (p->types[1] != TYPE_NONE) {
686  v->fields[1].value = (data & 0x1F0000) >> 16;
687  v->fields[1].type = p->types[1];
688  v->n++;
689  }
690  if (p->types[2] != TYPE_NONE) {
691  v->fields[2].value = (data & 0xF800) >> 11;
692  v->fields[2].type = p->types[2];
693  v->n++;
694  }
695  } break;
696  case F_X_EI: {
697  v->n = 1;
698  v->fields[0].value = (data & 0x8000) >> 15;
699  v->fields[0].type = p->types[0];
700  } break;
701  case F_XRA: {
702  v->n = 3;
703  v->fields[1].value = (data & 0x3E00000) >> 21;
704  v->fields[1].type = p->types[0];
705  v->fields[0].value = (data & 0x1F0000) >> 16;
706  v->fields[0].type = p->types[1];
707  v->fields[2].value = (data & 0xF800) >> 11;
708  v->fields[2].type = p->types[2];
709  } break;
710  case F_CMP: {
711  v->n = 3;
712  v->fields[0].value = (data & 0x3800000) >> 23;
713  v->fields[0].type = p->types[0];
714  v->fields[1].value = (data & 0x1F0000) >> 16;
715  v->fields[1].type = p->types[1];
716  v->fields[2].value = (data & 0xF800) >> 11;
717  v->fields[2].type = p->types[2];
718  } break;
719  case F_DCBF: {
720  v->n = 3;
721  v->fields[0].value = (data & 0x0E00000) >> 21;
722  v->fields[0].type = p->types[0];
723  v->fields[1].value = (data & 0x1F0000) >> 16;
724  v->fields[1].type = p->types[1];
725  v->fields[2].value = (data & 0xF800) >> 11;
726  v->fields[2].type = p->types[2];
727  } break;
728  case F_DCBL: {
729  v->n = 3;
730  v->fields[0].value = (data & 0x1E00000) >> 21;
731  v->fields[0].type = p->types[0];
732  v->fields[1].value = (data & 0x1F0000) >> 16;
733  v->fields[1].type = p->types[1];
734  v->fields[2].value = (data & 0xF800) >> 11;
735  v->fields[2].type = p->types[2];
736  } break;
737  case F_DCI: {
738  v->n = 1;
739  v->fields[0].value = (data & 0xE00000) >> 21;
740  v->fields[0].type = p->types[0];
741  } break;
742  case F_EXT: {
743  v->n = 2;
744  v->fields[0].value = (data & 0x3E00000) >> 21;
745  v->fields[0].type = p->types[0];
746  v->fields[1].value = (data & 0x1F0000) >> 16;
747  v->fields[1].type = p->types[1];
748  } break;
749  case F_A: {
750  v->n = 4;
751  v->fields[0].value = (data & 0x1E00000) >> 21;
752  v->fields[0].type = p->types[0];
753  v->fields[1].value = (data & 0x1F0000) >> 16;
754  v->fields[1].type = p->types[1];
755  v->fields[2].value = (data & 0xF800) >> 11;
756  v->fields[2].type = p->types[2];
757  v->fields[3].value = (data & 0x7C0) >> 6;
758  v->fields[3].type = p->types[3];
759  } break;
760  case F_XFX: {
761  v->n = 1;
762  v->fields[0].value = (data & 0x3E00000) >> 21;
763  v->fields[0].type = p->types[0];
764  } break;
765  case F_XER: {
766  v->n = 1;
767  v->fields[0].value = (data & 0x3800000) >> 23;
768  v->fields[0].type = p->types[0];
769  } break;
770  case F_MFPR: {
771  v->n = 2;
772  v->fields[0].value = (data & 0x1E00000) >> 21;
773  v->fields[0].type = p->types[0];
774  v->fields[1].value = (data & 0x1FF800) >> 11;
775  v->fields[1].type = p->types[1];
776  break;
777  }
778  case F_MTPR: {
779  v->n = 2;
780  // inverted
781  v->fields[1].value = (data & 0x1E00000) >> 21;
782  v->fields[1].type = p->types[1];
783  v->fields[0].value = (data & 0x1FF800) >> 11;
784  v->fields[0].type = p->types[0];
785  } break;
786  case E_NONE:
787  default:
788  v->n = 0;
789  break;
790  }
791 }
@ TYPE_NONE
Definition: marshal.h:30
#define F_XO
Definition: vle.c:48
#define F_CMP
Definition: vle.c:50
#define F_X_EI
Definition: vle.c:60
#define F_XRA
Definition: vle.c:61
#define F_DCI
Definition: vle.c:53
#define F_A
Definition: vle.c:55
#define F_XFX
Definition: vle.c:56
#define F_EVX
Definition: vle.c:49
#define F_EXT
Definition: vle.c:54
#define F_DCBL
Definition: vle.c:52
#define F_MFPR
Definition: vle.c:58
#define F_X
Definition: vle.c:47
#define F_XER
Definition: vle.c:57
#define F_MTPR
Definition: vle.c:59
#define F_DCBF
Definition: vle.c:51

References E_NONE, F_A, F_CMP, F_DCBF, F_DCBL, F_DCI, F_EVX, F_EXT, F_MFPR, F_MTPR, F_X, F_X_EI, F_XER, F_XFX, F_XO, F_XRA, p, TYPE_NONE, and v.

Referenced by find_ppc().

◆ vle_free()

void vle_free ( vle_t instr)

Definition at line 911 of file vle.c.

911  {
912  free(instr);
913 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130

References free().

Referenced by analop_vle(), and decompile_vle().

◆ vle_init()

int vle_init ( vle_handle handle,
const ut8 buffer,
const ut32  size 
)

Definition at line 870 of file vle.c.

870  {
871  if (!handle || !buffer || size < 2) {
872  return 1;
873  }
874  handle->pos = buffer;
875  handle->end = buffer + size;
876  handle->inc = 0;
877  handle->options = VLE_DEFAULTS;
878  return 0;
879 }
static mcore_handle handle
Definition: asm_mcore.c:8
struct buffer buffer
const ut8 * pos
Definition: mcore.h:31
ut16 inc
Definition: mcore.h:32
const ut8 * end
Definition: mcore.h:30
#define VLE_DEFAULTS
Definition: vle.h:8

References mcore_handle::end, handle, mcore_handle::inc, mcore_handle::pos, and VLE_DEFAULTS.

Referenced by analop_vle(), and decompile_vle().

◆ vle_next()

vle_t* vle_next ( vle_handle handle)

Definition at line 889 of file vle.c.

889  {
890  vle_t *op = NULL;
891  if (!handle || handle->pos + handle->inc >= handle->end) {
892  return NULL;
893  }
894  handle->pos += handle->inc;
895  // 'e-32' always before 'se-16'
896 
897  if (USE_INTERNAL_PPC(handle) && handle->pos + 4 <= handle->end) {
898  op = find_ppc(handle->pos);
899  }
900  if (!op && handle->pos + 4 <= handle->end) {
901  op = find_e(handle->pos);
902  }
903  if (!op && handle->pos + 2 <= handle->end) {
904  op = find_se(handle->pos);
905  }
906 
907  handle->inc = op ? op->size : 0;
908  return op;
909 }
ut8 op
Definition: 6502dis.c:13
Definition: dis.c:32
static vle_t * find_se(const ut8 *buffer)
Definition: vle.c:833
static vle_t * find_e(const ut8 *buffer)
Definition: vle.c:813
static vle_t * find_ppc(const ut8 *buffer)
Definition: vle.c:793
#define USE_INTERNAL_PPC(x)
Definition: vle.c:7

References mcore_handle::end, find_e(), find_ppc(), find_se(), handle, mcore_handle::inc, NULL, op, mcore_handle::pos, and USE_INTERNAL_PPC.

Referenced by analop_vle(), and decompile_vle().

◆ vle_option()

int vle_option ( vle_handle handle,
ut32  option 
)

Definition at line 881 of file vle.c.

881  {
882  if (!handle) {
883  return 1;
884  }
885  handle->options |= option;
886  return 0;
887 }
static int option
Definition: vmenus.c:2426

References handle, and option.

◆ vle_snprint()

void vle_snprint ( char *  str,
int  size,
ut32  addr,
vle_t instr 
)

Definition at line 915 of file vle.c.

915  {
916  ut32 i;
917  int bufsize = size, add = 0;
918  add = snprintf(str, bufsize, "%s", instr->name);
919  for (i = 0; add > 0 && i < instr->n && add < bufsize; i++) {
920  if (instr->fields[i].type == TYPE_REG) {
921  if (i < instr->n - 1 && instr->fields[i + 1].type == TYPE_MEM) {
922  add += snprintf(str + add, bufsize - add, " 0x%x(r%d)", instr->fields[i + 1].value, instr->fields[i].value);
923  i++;
924  } else {
925  add += snprintf(str + add, bufsize - add, " r%u", instr->fields[i].value);
926  }
927  } else if (instr->fields[i].type == TYPE_IMM) {
928  add += snprintf(str + add, bufsize - add, " 0x%x", instr->fields[i].value);
929  } else if (instr->fields[i].type == TYPE_JMP) {
930  add += snprintf(str + add, bufsize - add, " 0x%" PFMT32x, addr + instr->fields[i].value);
931  } else if (instr->fields[i].type == TYPE_CR) {
932  add += snprintf(str + add, bufsize - add, " cr%u", instr->fields[i].value);
933  }
934  }
935 }
#define PFMT32x
@ TYPE_IMM
Definition: armass.c:35
@ TYPE_MEM
Definition: armass.c:36
snprintf
Definition: kernel.h:364
#define TYPE_CR
int n
Definition: mipsasm.c:19
static int addr
Definition: z80asm.c:58
static int add(char *argv[])
Definition: ziptool.c:84

References add(), addr, vle_t::fields, i, n, vle_t::n, vle_t::name, PFMT32x, snprintf, cmd_descs_generate::str, vle_field_t::type, TYPE_CR, TYPE_IMM, TYPE_JMP, TYPE_MEM, TYPE_REG, and vle_field_t::value.

Referenced by decompile_vle().

Variable Documentation

◆ e_ops

const e_vle_t e_ops[]

Definition at line 240 of file vle.c.

Referenced by find_e().

◆ ppc_ops

const ppc_t ppc_ops[]

Definition at line 77 of file vle.c.

Referenced by find_ppc().

◆ se_ops

const se_vle_t se_ops[]

Definition at line 354 of file vle.c.

Referenced by find_se().