m680x_detail.c
Go to the documentation of this file.
1 /* Capstone testing regression */
2 /* By Do Minh Tuan <tuanit96@gmail.com>, 02-2019 */
3 
4 
5 #include "factory.h"
6 
7 static const char *s_access[] = {
8  "UNCHANGED", "READ", "WRITE", "READ ; WRITE",
9 };
10 
11 static void print_read_write_regs(char *result, csh *handle, cs_detail *detail)
12 {
13  int i;
14 
15  if (detail->regs_read_count > 0) {
16  add_str(&result, "\treading from regs: ");
17 
18  for (i = 0; i < detail->regs_read_count; ++i) {
19  if (i > 0)
20  add_str(&result, ", ");
21 
22  add_str(&result, "%s", cs_reg_name(*handle, detail->regs_read[i]));
23  }
24  }
25 
26  if (detail->regs_write_count > 0) {
27  add_str(&result, "\twriting to regs: ");
28 
29  for (i = 0; i < detail->regs_write_count; ++i) {
30  if (i > 0)
31  add_str(&result, ", ");
32 
33  add_str(&result, "%s", cs_reg_name(*handle, detail->regs_write[i]));
34  }
35  }
36 }
37 
38 char *get_detail_m680x(csh *handle, cs_mode mode, cs_insn *insn)
39 {
40  cs_detail *detail = insn->detail;
41  cs_m680x *m680x = NULL;
42  int i;
43  char *result;
44 
45  result = (char *)malloc(sizeof(char));
46  result[0] = '\0';
47 
48  if (detail == NULL)
49  return result;
50 
51  m680x = &detail->m680x;
52 
53  if (m680x->op_count)
54  add_str(&result, " ; op_count: %u", m680x->op_count);
55 
56  for (i = 0; i < m680x->op_count; i++) {
57  cs_m680x_op *op = &(m680x->operands[i]);
58  const char *comment;
59 
60  switch ((int)op->type) {
61  default:
62  break;
63 
64  case M680X_OP_REGISTER:
65  comment = "";
66 
67  if ((i == 0 && m680x->flags & M680X_FIRST_OP_IN_MNEM) ||
68  (i == 1 && m680x->flags &
70  comment = " (in mnemonic)";
71 
72  add_str(&result, " ; operands[%u].type: REGISTER = %s%s", i, cs_reg_name(*handle, op->reg), comment);
73  break;
74 
75  case M680X_OP_CONSTANT:
76  add_str(&result, " ; operands[%u].type: CONSTANT = %u", i, op->const_val);
77  break;
78 
79  case M680X_OP_IMMEDIATE:
80  add_str(&result, " ; operands[%u].type: IMMEDIATE = #%d", i, op->imm);
81  break;
82 
83  case M680X_OP_DIRECT:
84  add_str(&result, " ; operands[%u].type: DIRECT = 0x%02X", i, op->direct_addr);
85  break;
86 
87  case M680X_OP_EXTENDED:
88  add_str(&result, " ; operands[%u].type: EXTENDED %s = 0x%04X", i, op->ext.indirect ? "INDIRECT" : "", op->ext.address);
89  break;
90 
91  case M680X_OP_RELATIVE:
92  add_str(&result, " ; operands[%u].type: RELATIVE = 0x%04X", i, op->rel.address);
93  break;
94 
95  case M680X_OP_INDEXED:
96  add_str(&result, " ; operands[%u].type: INDEXED%s", i, (op->idx.flags & M680X_IDX_INDIRECT) ? " INDIRECT" : "");
97 
98  if (op->idx.base_reg != M680X_REG_INVALID)
99  add_str(&result, " ; base register: %s", cs_reg_name(*handle, op->idx.base_reg));
100 
101  if (op->idx.offset_reg != M680X_REG_INVALID)
102  add_str(&result, " ; offset register: %s", cs_reg_name(*handle, op->idx.offset_reg));
103 
104  if ((op->idx.offset_bits != 0) &&
105  (op->idx.offset_reg == M680X_REG_INVALID) &&
106  !op->idx.inc_dec) {
107  add_str(&result, " ; offset: %d", op->idx.offset);
108 
109  if (op->idx.base_reg == M680X_REG_PC)
110  add_str(&result, " ; offset address: 0x%X", op->idx.offset_addr);
111 
112  add_str(&result, " ; offset bits: %u", op->idx.offset_bits);
113  }
114 
115  if (op->idx.inc_dec) {
116  const char *post_pre = op->idx.flags &
117  M680X_IDX_POST_INC_DEC ? "post" : "pre";
118  const char *inc_dec = (op->idx.inc_dec > 0) ?
119  "increment" : "decrement";
120 
121  add_str(&result, " ; %s %s: %d", post_pre, inc_dec, abs(op->idx.inc_dec));
122  }
123 
124  break;
125  }
126 
127  if (op->size != 0)
128  add_str(&result, " ; size: %u", op->size);
129 
130  if (op->access != CS_AC_INVALID)
131  add_str(&result, " ; access: %s", s_access[op->access]);
132  }
133 
135 
136  return result;
137 }
_gevent_test_main.result
result
Definition: _gevent_test_main.py:96
grpc_op::flags
uint32_t flags
Definition: grpc_types.h:644
M680X_OP_CONSTANT
@ M680X_OP_CONSTANT
Used e.g. for a bit index or page number.
Definition: m680x.h:63
M680X_OP_EXTENDED
@ M680X_OP_EXTENDED
= Extended addressing operand.
Definition: m680x.h:60
factory.h
M680X_OP_DIRECT
@ M680X_OP_DIRECT
= Direct addressing operand.
Definition: m680x.h:61
print_read_write_regs
static void print_read_write_regs(char *result, csh *handle, cs_detail *detail)
Definition: m680x_detail.c:11
M680X_OP_IMMEDIATE
@ M680X_OP_IMMEDIATE
= Immediate operand.
Definition: m680x.h:58
mode
const char int mode
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:135
get_detail_m680x
char * get_detail_m680x(csh *handle, cs_mode mode, cs_insn *insn)
Definition: m680x_detail.c:38
M680X_FIRST_OP_IN_MNEM
#define M680X_FIRST_OP_IN_MNEM
Definition: m680x.h:159
detail
Definition: test_winkernel.cpp:39
s_access
static const char * s_access[]
Definition: m680x_detail.c:7
cs_m680x::op_count
uint8_t op_count
number of operands for the instruction or 0
Definition: m680x.h:167
cs_mode
cs_mode
Mode type.
Definition: capstone.h:103
M680X_IDX_POST_INC_DEC
#define M680X_IDX_POST_INC_DEC
Definition: m680x.h:78
cs_reg_name
const CAPSTONE_EXPORT char *CAPSTONE_API cs_reg_name(csh ud, unsigned int reg)
Definition: cs.c:1176
M680X_REG_PC
@ M680X_REG_PC
M6800/1/2/3/9, M6301/9.
Definition: m680x.h:46
add_str
void add_str(char **src, const char *format,...)
Definition: helper.c:89
cs_m680x::flags
uint8_t flags
See: M680X instruction flags.
Definition: m680x.h:166
cs_m680x
The M680X instruction and it's operands.
Definition: m680x.h:165
M680X_IDX_INDIRECT
#define M680X_IDX_INDIRECT
Definition: m680x.h:76
CS_AC_INVALID
@ CS_AC_INVALID
Uninitialized/invalid access type.
Definition: capstone.h:204
cs_m680x::operands
cs_m680x_op operands[M680X_OPERAND_COUNT]
operands for this insn.
Definition: m680x.h:168
csh
size_t csh
Definition: capstone.h:71
M680X_SECOND_OP_IN_MNEM
#define M680X_SECOND_OP_IN_MNEM
Definition: m680x.h:162
M680X_OP_RELATIVE
@ M680X_OP_RELATIVE
= Relative addressing operand.
Definition: m680x.h:62
M680X_OP_INDEXED
@ M680X_OP_INDEXED
= Indexed addressing operand.
Definition: m680x.h:59
handle
static csh handle
Definition: test_arm_regression.c:16
M680X_OP_REGISTER
@ M680X_OP_REGISTER
= Register operand.
Definition: m680x.h:57
cs_m680x_op
Instruction operand.
Definition: m680x.h:114
M680X_REG_INVALID
@ M680X_REG_INVALID
Definition: m680x.h:21
op
static grpc_op * op
Definition: test/core/fling/client.cc:47
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:17