Rizin
unix-like reverse engineering framework and cli tools
cstool_m68k.c File Reference
#include <stdio.h>
#include <capstone/capstone.h>

Go to the source code of this file.

Functions

void print_string_hex (char *comment, unsigned char *str, size_t len)
 
static void print_read_write_regs (cs_detail *detail, csh handle)
 
void print_insn_detail_m68k (csh handle, cs_insn *ins)
 

Variables

static const char * s_addressing_modes []
 

Function Documentation

◆ print_insn_detail_m68k()

void print_insn_detail_m68k ( csh  handle,
cs_insn *  ins 
)

Definition at line 61 of file cstool_m68k.c.

62 {
63  cs_m68k* m68k;
64  cs_detail* detail;
65  int i;
66 
67  // detail can be NULL on "data" instruction if SKIPDATA option is turned ON
68  if (ins->detail == NULL)
69  return;
70 
71  detail = ins->detail;
72  m68k = &detail->m68k;
73  if (m68k->op_count)
74  printf("\top_count: %u\n", m68k->op_count);
75 
77 
78  printf("\tgroups_count: %u\n", detail->groups_count);
79 
80  for (i = 0; i < m68k->op_count; i++) {
81  cs_m68k_op* op = &(m68k->operands[i]);
82 
83  switch((int)op->type) {
84  default:
85  break;
86  case M68K_OP_REG:
87  printf("\t\toperands[%u].type: REG = %s\n", i, cs_reg_name(handle, op->reg));
88  break;
89  case M68K_OP_IMM:
90  printf("\t\toperands[%u].type: IMM = 0x%x\n", i, (int)op->imm);
91  break;
92  case M68K_OP_MEM:
93  printf("\t\toperands[%u].type: MEM\n", i);
94  if (op->mem.base_reg != M68K_REG_INVALID)
95  printf("\t\t\toperands[%u].mem.base: REG = %s\n",
96  i, cs_reg_name(handle, op->mem.base_reg));
97  if (op->mem.index_reg != M68K_REG_INVALID) {
98  printf("\t\t\toperands[%u].mem.index: REG = %s\n",
99  i, cs_reg_name(handle, op->mem.index_reg));
100  printf("\t\t\toperands[%u].mem.index: size = %c\n",
101  i, op->mem.index_size ? 'l' : 'w');
102  }
103  if (op->mem.disp != 0)
104  printf("\t\t\toperands[%u].mem.disp: 0x%x\n", i, op->mem.disp);
105  if (op->mem.scale != 0)
106  printf("\t\t\toperands[%u].mem.scale: %d\n", i, op->mem.scale);
107 
108  printf("\t\taddress mode: %s\n", s_addressing_modes[op->address_mode]);
109  break;
110  case M68K_OP_FP_SINGLE:
111  printf("\t\toperands[%u].type: FP_SINGLE\n", i);
112  printf("\t\t\toperands[%u].simm: %f\n", i, op->simm);
113  break;
114  case M68K_OP_FP_DOUBLE:
115  printf("\t\toperands[%u].type: FP_DOUBLE\n", i);
116  printf("\t\t\toperands[%u].dimm: %lf\n", i, op->dimm);
117  break;
118  }
119  }
120 }
lzma_index ** i
Definition: index.h:629
static mcore_handle handle
Definition: asm_mcore.c:8
#define NULL
Definition: cris-opc.c:27
CAPSTONE_EXPORT const char *CAPSTONE_API cs_reg_name(csh ud, unsigned int reg)
Definition: cs.c:1154
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93
static const char * s_addressing_modes[]
Definition: cstool_m68k.c:14
static void print_read_write_regs(cs_detail *detail, csh handle)
Definition: cstool_m68k.c:44
@ M68K_OP_IMM
= CS_OP_IMM (Immediate operand).
Definition: m68k.h:115
@ M68K_OP_FP_SINGLE
single precision Floating-Point operand
Definition: m68k.h:117
@ M68K_OP_FP_DOUBLE
double precision Floating-Point operand
Definition: m68k.h:118
@ M68K_OP_REG
= CS_OP_REG (Register operand).
Definition: m68k.h:114
@ M68K_OP_MEM
= CS_OP_MEM (Memory operand).
Definition: m68k.h:116
@ M68K_REG_INVALID
Definition: m68k.h:21
Instruction operand.
Definition: m68k.h:160
The M68K instruction and it's operands.
Definition: m68k.h:210
Definition: dis.c:32

References cs_reg_name(), test_evm::detail, handle, i, M68K_OP_FP_DOUBLE, M68K_OP_FP_SINGLE, M68K_OP_IMM, M68K_OP_MEM, M68K_OP_REG, M68K_REG_INVALID, NULL, print_read_write_regs(), printf(), and s_addressing_modes.

Referenced by print_details().

◆ print_read_write_regs()

static void print_read_write_regs ( cs_detail *  detail,
csh  handle 
)
static

Definition at line 44 of file cstool_m68k.c.

45 {
46  int i;
47 
48  for (i = 0; i < detail->regs_read_count; ++i) {
49  uint16_t reg_id = detail->regs_read[i];
50  const char* reg_name = cs_reg_name(handle, reg_id);
51  printf("\treading from reg: %s\n", reg_name);
52  }
53 
54  for (i = 0; i < detail->regs_write_count; ++i) {
55  uint16_t reg_id = detail->regs_write[i];
56  const char* reg_name = cs_reg_name(handle, reg_id);
57  printf("\twriting to reg: %s\n", reg_name);
58  }
59 }
unsigned short uint16_t
Definition: sftypes.h:30

References cs_reg_name(), handle, i, and printf().

Referenced by print_insn_detail_m68k().

◆ print_string_hex()

void print_string_hex ( char *  comment,
unsigned char *  str,
size_t  len 
)

Variable Documentation

◆ s_addressing_modes

const char* s_addressing_modes[]
static
Initial value:
= {
"<invalid mode>",
"Register Direct - Data",
"Register Direct - Address",
"Register Indirect - Address",
"Register Indirect - Address with Postincrement",
"Register Indirect - Address with Predecrement",
"Register Indirect - Address with Displacement",
"Address Register Indirect With Index - 8-bit displacement",
"Address Register Indirect With Index - Base displacement",
"Memory indirect - Postindex",
"Memory indirect - Preindex",
"Program Counter Indirect - with Displacement",
"Program Counter Indirect with Index - with 8-Bit Displacement",
"Program Counter Indirect with Index - with Base Displacement",
"Program Counter Memory Indirect - Postindexed",
"Program Counter Memory Indirect - Preindexed",
"Absolute Data Addressing - Short",
"Absolute Data Addressing - Long",
"Immediate value",
}

Definition at line 14 of file cstool_m68k.c.

Referenced by print_insn_detail_m68k().