Rizin
unix-like reverse engineering framework and cli tools
MCInst.c
Go to the documentation of this file.
1 /* Capstone Disassembly Engine */
2 /* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2015 */
3 
4 #if defined(CAPSTONE_HAS_OSXKERNEL)
5 #include <Availability.h>
6 #include <libkern/libkern.h>
7 #else
8 #include <stdio.h>
9 #include <stdlib.h>
10 #endif
11 #include <string.h>
12 
13 #include "MCInst.h"
14 #include "utils.h"
15 
16 #define MCINST_CACHE (ARR_SIZE(mcInst->Operands) - 1)
17 
18 void MCInst_Init(MCInst *inst)
19 {
20  unsigned int i;
21 
22  for (i = 0; i < 48; i++) {
23  inst->Operands[i].Kind = kInvalid;
24  inst->Operands[i].ImmVal = 0;
25  }
26 
27  memset(inst, 0, sizeof(MCInst));
28  inst->Opcode = 0;
29  inst->OpcodePub = 0;
30  inst->size = 0;
31  inst->has_imm = false;
32  inst->op1_size = 0;
33  inst->writeback = false;
34  inst->ac_idx = 0;
35  inst->popcode_adjust = 0;
36  inst->assembly[0] = '\0';
37  inst->xAcquireRelease = 0;
38 }
39 
40 void MCInst_clear(MCInst *inst)
41 {
42  inst->size = 0;
43 }
44 
45 // do not free @Op
46 void MCInst_insert0(MCInst *inst, int index, MCOperand *Op)
47 {
48  int i;
49 
50  for(i = inst->size; i > index; i--)
51  //memcpy(&(inst->Operands[i]), &(inst->Operands[i-1]), sizeof(MCOperand));
52  inst->Operands[i] = inst->Operands[i-1];
53 
54  inst->Operands[index] = *Op;
55  inst->size++;
56 }
57 
58 void MCInst_setOpcode(MCInst *inst, unsigned Op)
59 {
60  inst->Opcode = Op;
61 }
62 
63 void MCInst_setOpcodePub(MCInst *inst, unsigned Op)
64 {
65  inst->OpcodePub = Op;
66 }
67 
68 unsigned MCInst_getOpcode(const MCInst *inst)
69 {
70  return inst->Opcode;
71 }
72 
73 unsigned MCInst_getOpcodePub(const MCInst *inst)
74 {
75  return inst->OpcodePub;
76 }
77 
79 {
80  return &inst->Operands[i];
81 }
82 
83 unsigned MCInst_getNumOperands(const MCInst *inst)
84 {
85  return inst->size;
86 }
87 
88 // This addOperand2 function doesnt free Op
90 {
91  inst->Operands[inst->size] = *Op;
92 
93  inst->size++;
94 }
95 
97 {
98  return op->Kind != kInvalid;
99 }
100 
102 {
103  return op->Kind == kRegister;
104 }
105 
107 {
108  return op->Kind == kImmediate;
109 }
110 
112 {
113  return op->Kind == kFPImmediate;
114 }
115 
117 unsigned MCOperand_getReg(const MCOperand *op)
118 {
119  return op->RegVal;
120 }
121 
124 {
125  op->RegVal = Reg;
126 }
127 
129 {
130  return op->ImmVal;
131 }
132 
134 {
135  op->ImmVal = Val;
136 }
137 
139 {
140  return op->FPImmVal;
141 }
142 
143 void MCOperand_setFPImm(MCOperand *op, double Val)
144 {
145  op->FPImmVal = Val;
146 }
147 
149 {
150  MCOperand *op = &(mcInst->Operands[MCINST_CACHE]);
151 
152  op->Kind = kRegister;
153  op->RegVal = Reg;
154 
155  return op;
156 }
157 
158 void MCOperand_CreateReg0(MCInst *mcInst, unsigned Reg)
159 {
160  MCOperand *op = &(mcInst->Operands[mcInst->size]);
161  mcInst->size++;
162 
163  op->Kind = kRegister;
164  op->RegVal = Reg;
165 }
166 
168 {
169  MCOperand *op = &(mcInst->Operands[MCINST_CACHE]);
170 
171  op->Kind = kImmediate;
172  op->ImmVal = Val;
173 
174  return op;
175 }
176 
178 {
179  MCOperand *op = &(mcInst->Operands[mcInst->size]);
180  mcInst->size++;
181 
182  op->Kind = kImmediate;
183  op->ImmVal = Val;
184 }
ut8 op
Definition: 6502dis.c:13
double MCOperand_getFPImm(const MCOperand *op)
Definition: MCInst.c:138
unsigned MCInst_getOpcodePub(const MCInst *inst)
Definition: MCInst.c:73
MCOperand * MCOperand_CreateReg1(MCInst *mcInst, unsigned Reg)
Definition: MCInst.c:148
unsigned MCInst_getOpcode(const MCInst *inst)
Definition: MCInst.c:68
void MCInst_clear(MCInst *inst)
Definition: MCInst.c:40
void MCOperand_setReg(MCOperand *op, unsigned Reg)
setReg - Set the register number.
Definition: MCInst.c:123
unsigned MCInst_getNumOperands(const MCInst *inst)
Definition: MCInst.c:83
MCOperand * MCInst_getOperand(MCInst *inst, unsigned i)
Definition: MCInst.c:78
void MCOperand_setImm(MCOperand *op, int64_t Val)
Definition: MCInst.c:133
void MCOperand_setFPImm(MCOperand *op, double Val)
Definition: MCInst.c:143
bool MCOperand_isReg(const MCOperand *op)
Definition: MCInst.c:101
void MCInst_Init(MCInst *inst)
Definition: MCInst.c:18
void MCInst_insert0(MCInst *inst, int index, MCOperand *Op)
Definition: MCInst.c:46
void MCOperand_CreateReg0(MCInst *mcInst, unsigned Reg)
Definition: MCInst.c:158
void MCInst_setOpcodePub(MCInst *inst, unsigned Op)
Definition: MCInst.c:63
bool MCOperand_isValid(const MCOperand *op)
Definition: MCInst.c:96
int64_t MCOperand_getImm(MCOperand *op)
Definition: MCInst.c:128
unsigned MCOperand_getReg(const MCOperand *op)
getReg - Returns the register number.
Definition: MCInst.c:117
#define MCINST_CACHE
Definition: MCInst.c:16
void MCInst_addOperand2(MCInst *inst, MCOperand *Op)
Definition: MCInst.c:89
void MCInst_setOpcode(MCInst *inst, unsigned Op)
Definition: MCInst.c:58
bool MCOperand_isFPImm(const MCOperand *op)
Definition: MCInst.c:111
MCOperand * MCOperand_CreateImm1(MCInst *mcInst, int64_t Val)
Definition: MCInst.c:167
bool MCOperand_isImm(const MCOperand *op)
Definition: MCInst.c:106
void MCOperand_CreateImm0(MCInst *mcInst, int64_t Val)
Definition: MCInst.c:177
lzma_index ** i
Definition: index.h:629
return memset(p, 0, total)
long int64_t
Definition: sftypes.h:32
Definition: MCInst.h:88
uint8_t size
Definition: MCInst.h:90
uint8_t ac_idx
Definition: MCInst.h:107
uint8_t op1_size
Definition: MCInst.h:92
bool has_imm
Definition: MCInst.h:91
char assembly[8]
Definition: MCInst.h:109
uint8_t xAcquireRelease
Definition: MCInst.h:111
MCOperand Operands[48]
Definition: MCInst.h:94
unsigned OpcodePub
Definition: MCInst.h:89
unsigned Opcode
Definition: MCInst.h:93
bool writeback
Definition: MCInst.h:105
uint8_t popcode_adjust
Definition: MCInst.h:108
unsigned char Kind
Definition: MCInst.h:37
int64_t ImmVal
Definition: MCInst.h:41
Definition: dis.c:32