cstool_m68k.c
Go to the documentation of this file.
1 //
2 // cstool_m68k.c
3 //
4 //
5 // Created by YUHANG TANG on 26/10/16.
6 //
7 //
8 
9 #include <stdio.h>
10 #include <capstone/capstone.h>
11 
12 void print_string_hex(char *comment, unsigned char *str, size_t len);
13 
14 static const char* s_addressing_modes[] = {
15  "<invalid mode>",
16 
17  "Register Direct - Data",
18  "Register Direct - Address",
19 
20  "Register Indirect - Address",
21  "Register Indirect - Address with Postincrement",
22  "Register Indirect - Address with Predecrement",
23  "Register Indirect - Address with Displacement",
24 
25  "Address Register Indirect With Index - 8-bit displacement",
26  "Address Register Indirect With Index - Base displacement",
27 
28  "Memory indirect - Postindex",
29  "Memory indirect - Preindex",
30 
31  "Program Counter Indirect - with Displacement",
32 
33  "Program Counter Indirect with Index - with 8-Bit Displacement",
34  "Program Counter Indirect with Index - with Base Displacement",
35 
36  "Program Counter Memory Indirect - Postindexed",
37  "Program Counter Memory Indirect - Preindexed",
38 
39  "Absolute Data Addressing - Short",
40  "Absolute Data Addressing - Long",
41  "Immediate value",
42 };
43 
44 static void print_read_write_regs(cs_detail* detail, csh handle)
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 }
60 
61 void print_insn_detail_m68k(csh handle, cs_insn *ins)
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 }
121 
xds_interop_client.str
str
Definition: xds_interop_client.py:487
uint16_t
unsigned short uint16_t
Definition: stdint-msvc2008.h:79
printf
_Use_decl_annotations_ int __cdecl printf(const char *_Format,...)
Definition: cs_driver.c:91
M68K_OP_FP_DOUBLE
@ M68K_OP_FP_DOUBLE
double precision Floating-Point operand
Definition: m68k.h:118
M68K_OP_FP_SINGLE
@ M68K_OP_FP_SINGLE
single precision Floating-Point operand
Definition: m68k.h:117
detail
Definition: test_winkernel.cpp:39
capstone.h
cs_m68k
The M68K instruction and it's operands.
Definition: m68k.h:207
cs_reg_name
const CAPSTONE_EXPORT char *CAPSTONE_API cs_reg_name(csh ud, unsigned int reg)
Definition: cs.c:1176
m68k
Definition: test_winkernel.cpp:67
M68K_OP_IMM
@ M68K_OP_IMM
= CS_OP_IMM (Immediate operand).
Definition: m68k.h:115
csh
size_t csh
Definition: capstone.h:71
s_addressing_modes
static const char * s_addressing_modes[]
Definition: cstool_m68k.c:14
M68K_REG_INVALID
@ M68K_REG_INVALID
Definition: m68k.h:21
M68K_OP_REG
@ M68K_OP_REG
= CS_OP_REG (Register operand).
Definition: m68k.h:114
handle
static csh handle
Definition: test_arm_regression.c:16
print_read_write_regs
static void print_read_write_regs(cs_detail *detail, csh handle)
Definition: cstool_m68k.c:44
len
int len
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:46
cs_m68k_op
Instruction operand.
Definition: m68k.h:154
M68K_OP_MEM
@ M68K_OP_MEM
= CS_OP_MEM (Memory operand).
Definition: m68k.h:116
op
static grpc_op * op
Definition: test/core/fling/client.cc:47
print_string_hex
void print_string_hex(char *comment, unsigned char *str, size_t len)
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
print_insn_detail_m68k
void print_insn_detail_m68k(csh handle, cs_insn *ins)
Definition: cstool_m68k.c:61
test_evm.detail
detail
Definition: test_evm.py:9


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:59:02