Seregon/Hermes

Hermes/Dyforge is a program written in c++ allows you to inject a dll that can analyze all processes in a program, can be used for mod and reverse engeneering

C/3.8 KB/No license
DyMain/include/capstone/m680x.h
Hermes / DyMain / include / capstone / m680x.h
1#ifndef CAPSTONE_M680X_H
2#define CAPSTONE_M680X_H
3 
4/* Capstone Disassembly Engine */
5/* M680X Backend by Wolfgang Schwotzer <wolfgang.schwotzer@gmx.net> 2017 */
6 
7#ifdef __cplusplus
8extern "C" {
9#endif
10 
11#include "platform.h"
12#include "cs_operand.h"
13 
14#ifdef _MSC_VER
15#pragma warning(disable:4201)
16#endif
17 
18#define M680X_OPERAND_COUNT 9
19 
20/// M680X registers and special registers
21typedef enum m680x_reg {
22 M680X_REG_INVALID = 0,
23 
24 M680X_REG_A, ///< M6800/1/2/3/9, HD6301/9
25 M680X_REG_B, ///< M6800/1/2/3/9, HD6301/9
26 M680X_REG_E, ///< HD6309
27 M680X_REG_F, ///< HD6309
28 M680X_REG_0, ///< HD6309
29 
30 M680X_REG_D, ///< M6801/3/9, HD6301/9
31 M680X_REG_W, ///< HD6309
32 
33 M680X_REG_CC, ///< M6800/1/2/3/9, M6301/9
34 M680X_REG_DP, ///< M6809/M6309
35 M680X_REG_MD, ///< M6309
36 
37 M680X_REG_HX, ///< M6808
38 M680X_REG_H, ///< M6808
39 M680X_REG_X, ///< M6800/1/2/3/9, M6301/9
40 M680X_REG_Y, ///< M6809/M6309
41 M680X_REG_S, ///< M6809/M6309
42 M680X_REG_U, ///< M6809/M6309
43 M680X_REG_V, ///< M6309
44 
45 M680X_REG_Q, ///< M6309
46 
47 M680X_REG_PC, ///< M6800/1/2/3/9, M6301/9
48 
49 M680X_REG_TMP2, ///< CPU12
50 M680X_REG_TMP3, ///< CPU12
51 
52 M680X_REG_ENDING, ///< <-- mark the end of the list of registers
53} m680x_reg;
54 
55/// Operand type for instruction's operands
56typedef enum m680x_op_type {
57 M680X_OP_INVALID = CS_OP_INVALID, ///< = CS_OP_INVALID (Uninitialized).
58 M680X_OP_REGISTER = CS_OP_REG, ///< = Register operand.
59 M680X_OP_IMMEDIATE = CS_OP_IMM, ///< = Immediate operand.
60 M680X_OP_INDEXED = CS_OP_SPECIAL + 0, ///< = Indexed addressing operand.
61 M680X_OP_EXTENDED = CS_OP_SPECIAL + 1, ///< = Extended addressing operand.
62 M680X_OP_DIRECT = CS_OP_SPECIAL + 2, ///< = Direct addressing operand.
63 M680X_OP_RELATIVE = CS_OP_SPECIAL + 3, ///< = Relative addressing operand.
64 M680X_OP_CONSTANT = CS_OP_SPECIAL + 4, ///< = constant operand (Displayed as number only).
65 ///< Used e.g. for a bit index or page number.
66} m680x_op_type;
67 
68// Supported bit values for mem.idx.offset_bits
69#define M680X_OFFSET_NONE 0
70#define M680X_OFFSET_BITS_5 5
71#define M680X_OFFSET_BITS_8 8
72#define M680X_OFFSET_BITS_9 9
73#define M680X_OFFSET_BITS_16 16
74 
75// Supported bit flags for mem.idx.flags
76// These flags can be combined
77#define M680X_IDX_INDIRECT 1
78#define M680X_IDX_NO_COMMA 2
79#define M680X_IDX_POST_INC_DEC 4
80 
81/// Instruction's operand referring to indexed addressing
82typedef struct m680x_op_idx {
83 m680x_reg base_reg; ///< base register (or M680X_REG_INVALID if
84 ///< irrelevant)
85 m680x_reg offset_reg; ///< offset register (or M680X_REG_INVALID if
86 ///< irrelevant)
87 int16_t offset; ///< 5-,8- or 16-bit offset. See also offset_bits.
88 uint16_t offset_addr; ///< = offset addr. if base_reg == M680X_REG_PC.
89 ///< calculated as offset + PC
90 uint8_t offset_bits; ///< offset width in bits for indexed addressing
91 int8_t inc_dec; ///< inc. or dec. value:
92 ///< 0: no inc-/decrement
93 ///< 1 .. 8: increment by 1 .. 8
94 ///< -1 .. -8: decrement by 1 .. 8
95 ///< if flag M680X_IDX_POST_INC_DEC set it is post
96 ///< inc-/decrement otherwise pre inc-/decrement
97 uint8_t flags; ///< 8-bit flags (see above)
98} m680x_op_idx;
99 
100/// Instruction's memory operand referring to relative addressing (Bcc/LBcc)
101typedef struct m680x_op_rel {
102 uint16_t address; ///< The absolute address.
103 ///< calculated as PC + offset. PC is the first
104 ///< address after the instruction.
105 int16_t offset; ///< the offset/displacement value
106} m680x_op_rel;
107 
108/// Instruction's operand referring to extended addressing
109typedef struct m680x_op_ext {
110 uint16_t address; ///< The absolute address
111 bool indirect; ///< true if extended indirect addressing
112} m680x_op_ext;
113 
114/// Instruction operand
115typedef struct cs_m680x_op {
116 m680x_op_type type;
117 union {
118 int32_t imm; ///< immediate value for IMM operand
119 m680x_reg reg; ///< register value for REG operand
120 m680x_op_idx idx; ///< Indexed addressing operand
121 m680x_op_rel rel; ///< Relative address. operand (Bcc/LBcc)
122 m680x_op_ext ext; ///< Extended address
123 uint8_t direct_addr; ///<</ Direct address (lower 8-bit)
124 uint8_t const_val; ///< constant value (bit index, page nr.)
125 };
126 uint8_t size; ///< size of this operand (in bytes)
127 /// How is this operand accessed? (READ, WRITE or READ|WRITE)
128 /// This field is combined of cs_ac_type.
129 /// NOTE: this field is irrelevant if engine is compiled in DIET
130 uint8_t access;
131} cs_m680x_op;
132 
133/// Group of M680X instructions
134typedef enum m680x_group_type {
135 M680X_GRP_INVALID = 0, /// = CS_GRP_INVALID
136 // Generic groups
137 // all jump instructions (conditional+direct+indirect jumps)
138 M680X_GRP_JUMP, ///< = CS_GRP_JUMP
139 // all call instructions
140 M680X_GRP_CALL, ///< = CS_GRP_CALL
141 // all return instructions
142 M680X_GRP_RET, ///< = CS_GRP_RET
143 // all interrupt instructions (int+syscall)
144 M680X_GRP_INT, ///< = CS_GRP_INT
145 // all interrupt return instructions
146 M680X_GRP_IRET, ///< = CS_GRP_IRET
147 // all privileged instructions
148 M680X_GRP_PRIV, ///< = CS_GRP_PRIVILEDGE; not used
149 // all relative branching instructions
150 M680X_GRP_BRAREL, ///< = CS_GRP_BRANCH_RELATIVE
151 
152 // Architecture-specific groups
153 M680X_GRP_ENDING, // <-- mark the end of the list of groups
154} m680x_group_type;
155 
156// M680X instruction flags:
157 
158/// The first (register) operand is part of the
159/// instruction mnemonic
160#define M680X_FIRST_OP_IN_MNEM 1
161/// The second (register) operand is part of the
162/// instruction mnemonic
163#define M680X_SECOND_OP_IN_MNEM 2
164 
165/// The M680X instruction and its operands
166typedef struct cs_m680x {
167 uint8_t flags; ///< See: M680X instruction flags
168 uint8_t op_count; ///< number of operands for the instruction or 0
169 cs_m680x_op operands[M680X_OPERAND_COUNT]; ///< operands for this insn.
170} cs_m680x;
171 
172/// M680X instruction IDs
173typedef enum m680x_insn {
174 M680X_INS_INVLD = 0,
175 M680X_INS_ABA, ///< M6800/1/2/3
176 M680X_INS_ABX,
177 M680X_INS_ABY,
178 M680X_INS_ADC,
179 M680X_INS_ADCA,
180 M680X_INS_ADCB,
181 M680X_INS_ADCD,
182 M680X_INS_ADCR,
183 M680X_INS_ADD,
184 M680X_INS_ADDA,
185 M680X_INS_ADDB,
186 M680X_INS_ADDD,
187 M680X_INS_ADDE,
188 M680X_INS_ADDF,
189 M680X_INS_ADDR,
190 M680X_INS_ADDW,
191 M680X_INS_AIM,
192 M680X_INS_AIS,
193 M680X_INS_AIX,
194 M680X_INS_AND,
195 M680X_INS_ANDA,
196 M680X_INS_ANDB,
197 M680X_INS_ANDCC,
198 M680X_INS_ANDD,
199 M680X_INS_ANDR,
200 M680X_INS_ASL,
201 M680X_INS_ASLA,
202 M680X_INS_ASLB,
203 M680X_INS_ASLD, ///< or LSLD
204 M680X_INS_ASR,
205 M680X_INS_ASRA,
206 M680X_INS_ASRB,
207 M680X_INS_ASRD,
208 M680X_INS_ASRX,
209 M680X_INS_BAND,
210 M680X_INS_BCC, ///< or BHS
211 M680X_INS_BCLR,
212 M680X_INS_BCS, ///< or BLO
213 M680X_INS_BEOR,
214 M680X_INS_BEQ,
215 M680X_INS_BGE,
216 M680X_INS_BGND,
217 M680X_INS_BGT,
218 M680X_INS_BHCC,
219 M680X_INS_BHCS,
220 M680X_INS_BHI,
221 M680X_INS_BIAND,
222 M680X_INS_BIEOR,
223 M680X_INS_BIH,
224 M680X_INS_BIL,
225 M680X_INS_BIOR,
226 M680X_INS_BIT,
227 M680X_INS_BITA,
228 M680X_INS_BITB,
229 M680X_INS_BITD,
230 M680X_INS_BITMD,
231 M680X_INS_BLE,
232 M680X_INS_BLS,
233 M680X_INS_BLT,
234 M680X_INS_BMC,
235 M680X_INS_BMI,
236 M680X_INS_BMS,
237 M680X_INS_BNE,
238 M680X_INS_BOR,
239 M680X_INS_BPL,
240 M680X_INS_BRCLR,
241 M680X_INS_BRSET,
242 M680X_INS_BRA,
243 M680X_INS_BRN,
244 M680X_INS_BSET,
245 M680X_INS_BSR,
246 M680X_INS_BVC,
247 M680X_INS_BVS,
248 M680X_INS_CALL,
249 M680X_INS_CBA, ///< M6800/1/2/3
250 M680X_INS_CBEQ,
251 M680X_INS_CBEQA,
252 M680X_INS_CBEQX,
253 M680X_INS_CLC, ///< M6800/1/2/3
254 M680X_INS_CLI, ///< M6800/1/2/3
255 M680X_INS_CLR,
256 M680X_INS_CLRA,
257 M680X_INS_CLRB,
258 M680X_INS_CLRD,
259 M680X_INS_CLRE,
260 M680X_INS_CLRF,
261 M680X_INS_CLRH,
262 M680X_INS_CLRW,
263 M680X_INS_CLRX,
264 M680X_INS_CLV, ///< M6800/1/2/3
265 M680X_INS_CMP,
266 M680X_INS_CMPA,
267 M680X_INS_CMPB,
268 M680X_INS_CMPD,
269 M680X_INS_CMPE,
270 M680X_INS_CMPF,
271 M680X_INS_CMPR,
272 M680X_INS_CMPS,
273 M680X_INS_CMPU,
274 M680X_INS_CMPW,
275 M680X_INS_CMPX,
276 M680X_INS_CMPY,
277 M680X_INS_COM,
278 M680X_INS_COMA,
279 M680X_INS_COMB,
280 M680X_INS_COMD,
281 M680X_INS_COME,
282 M680X_INS_COMF,
283 M680X_INS_COMW,
284 M680X_INS_COMX,
285 M680X_INS_CPD,
286 M680X_INS_CPHX,
287 M680X_INS_CPS,
288 M680X_INS_CPX, ///< M6800/1/2/3
289 M680X_INS_CPY,
290 M680X_INS_CWAI,
291 M680X_INS_DAA,
292 M680X_INS_DBEQ,
293 M680X_INS_DBNE,
294 M680X_INS_DBNZ,
295 M680X_INS_DBNZA,
296 M680X_INS_DBNZX,
297 M680X_INS_DEC,
298 M680X_INS_DECA,
299 M680X_INS_DECB,
300 M680X_INS_DECD,
301 M680X_INS_DECE,
302 M680X_INS_DECF,
303 M680X_INS_DECW,
304 M680X_INS_DECX,
305 M680X_INS_DES, ///< M6800/1/2/3
306 M680X_INS_DEX, ///< M6800/1/2/3
307 M680X_INS_DEY,
308 M680X_INS_DIV,
309 M680X_INS_DIVD,
310 M680X_INS_DIVQ,
311 M680X_INS_EDIV,
312 M680X_INS_EDIVS,
313 M680X_INS_EIM,
314 M680X_INS_EMACS,
315 M680X_INS_EMAXD,
316 M680X_INS_EMAXM,
317 M680X_INS_EMIND,
318 M680X_INS_EMINM,
319 M680X_INS_EMUL,
320 M680X_INS_EMULS,
321 M680X_INS_EOR,
322 M680X_INS_EORA,
323 M680X_INS_EORB,
324 M680X_INS_EORD,
325 M680X_INS_EORR,
326 M680X_INS_ETBL,
327 M680X_INS_EXG,
328 M680X_INS_FDIV,
329 M680X_INS_IBEQ,
330 M680X_INS_IBNE,
331 M680X_INS_IDIV,
332 M680X_INS_IDIVS,
333 M680X_INS_ILLGL,
334 M680X_INS_INC,
335 M680X_INS_INCA,
336 M680X_INS_INCB,
337 M680X_INS_INCD,
338 M680X_INS_INCE,
339 M680X_INS_INCF,
340 M680X_INS_INCW,
341 M680X_INS_INCX,
342 M680X_INS_INS, ///< M6800/1/2/3
343 M680X_INS_INX, ///< M6800/1/2/3
344 M680X_INS_INY,
345 M680X_INS_JMP,
346 M680X_INS_JSR,
347 M680X_INS_LBCC, ///< or LBHS
348 M680X_INS_LBCS, ///< or LBLO
349 M680X_INS_LBEQ,
350 M680X_INS_LBGE,
351 M680X_INS_LBGT,
352 M680X_INS_LBHI,
353 M680X_INS_LBLE,
354 M680X_INS_LBLS,
355 M680X_INS_LBLT,
356 M680X_INS_LBMI,
357 M680X_INS_LBNE,
358 M680X_INS_LBPL,
359 M680X_INS_LBRA,
360 M680X_INS_LBRN,
361 M680X_INS_LBSR,
362 M680X_INS_LBVC,
363 M680X_INS_LBVS,
364 M680X_INS_LDA,
365 M680X_INS_LDAA, ///< M6800/1/2/3
366 M680X_INS_LDAB, ///< M6800/1/2/3
367 M680X_INS_LDB,
368 M680X_INS_LDBT,
369 M680X_INS_LDD,
370 M680X_INS_LDE,
371 M680X_INS_LDF,
372 M680X_INS_LDHX,
373 M680X_INS_LDMD,
374 M680X_INS_LDQ,
375 M680X_INS_LDS,
376 M680X_INS_LDU,
377 M680X_INS_LDW,
378 M680X_INS_LDX,
379 M680X_INS_LDY,
380 M680X_INS_LEAS,
381 M680X_INS_LEAU,
382 M680X_INS_LEAX,
383 M680X_INS_LEAY,
384 M680X_INS_LSL,
385 M680X_INS_LSLA,
386 M680X_INS_LSLB,
387 M680X_INS_LSLD,
388 M680X_INS_LSLX,
389 M680X_INS_LSR,
390 M680X_INS_LSRA,
391 M680X_INS_LSRB,
392 M680X_INS_LSRD, ///< or ASRD
393 M680X_INS_LSRW,
394 M680X_INS_LSRX,
395 M680X_INS_MAXA,
396 M680X_INS_MAXM,
397 M680X_INS_MEM,
398 M680X_INS_MINA,
399 M680X_INS_MINM,
400 M680X_INS_MOV,
401 M680X_INS_MOVB,
402 M680X_INS_MOVW,
403 M680X_INS_MUL,
404 M680X_INS_MULD,
405 M680X_INS_NEG,
406 M680X_INS_NEGA,
407 M680X_INS_NEGB,
408 M680X_INS_NEGD,
409 M680X_INS_NEGX,
410 M680X_INS_NOP,
411 M680X_INS_NSA,
412 M680X_INS_OIM,
413 M680X_INS_ORA,
414 M680X_INS_ORAA, ///< M6800/1/2/3
415 M680X_INS_ORAB, ///< M6800/1/2/3
416 M680X_INS_ORB,
417 M680X_INS_ORCC,
418 M680X_INS_ORD,
419 M680X_INS_ORR,
420 M680X_INS_PSHA, ///< M6800/1/2/3
421 M680X_INS_PSHB, ///< M6800/1/2/3
422 M680X_INS_PSHC,
423 M680X_INS_PSHD,
424 M680X_INS_PSHH,
425 M680X_INS_PSHS,
426 M680X_INS_PSHSW,
427 M680X_INS_PSHU,
428 M680X_INS_PSHUW,
429 M680X_INS_PSHX, ///< M6800/1/2/3
430 M680X_INS_PSHY,
431 M680X_INS_PULA, ///< M6800/1/2/3
432 M680X_INS_PULB, ///< M6800/1/2/3
433 M680X_INS_PULC,
434 M680X_INS_PULD,
435 M680X_INS_PULH,
436 M680X_INS_PULS,
437 M680X_INS_PULSW,
438 M680X_INS_PULU,
439 M680X_INS_PULUW,
440 M680X_INS_PULX, ///< M6800/1/2/3
441 M680X_INS_PULY,
442 M680X_INS_REV,
443 M680X_INS_REVW,
444 M680X_INS_ROL,
445 M680X_INS_ROLA,
446 M680X_INS_ROLB,
447 M680X_INS_ROLD,
448 M680X_INS_ROLW,
449 M680X_INS_ROLX,
450 M680X_INS_ROR,
451 M680X_INS_RORA,
452 M680X_INS_RORB,
453 M680X_INS_RORD,
454 M680X_INS_RORW,
455 M680X_INS_RORX,
456 M680X_INS_RSP,
457 M680X_INS_RTC,
458 M680X_INS_RTI,
459 M680X_INS_RTS,
460 M680X_INS_SBA, ///< M6800/1/2/3
461 M680X_INS_SBC,
462 M680X_INS_SBCA,
463 M680X_INS_SBCB,
464 M680X_INS_SBCD,
465 M680X_INS_SBCR,
466 M680X_INS_SEC,
467 M680X_INS_SEI,
468 M680X_INS_SEV,
469 M680X_INS_SEX,
470 M680X_INS_SEXW,
471 M680X_INS_SLP,
472 M680X_INS_STA,
473 M680X_INS_STAA, ///< M6800/1/2/3
474 M680X_INS_STAB, ///< M6800/1/2/3
475 M680X_INS_STB,
476 M680X_INS_STBT,
477 M680X_INS_STD,
478 M680X_INS_STE,
479 M680X_INS_STF,
480 M680X_INS_STOP,
481 M680X_INS_STHX,
482 M680X_INS_STQ,
483 M680X_INS_STS,
484 M680X_INS_STU,
485 M680X_INS_STW,
486 M680X_INS_STX,
487 M680X_INS_STY,
488 M680X_INS_SUB,
489 M680X_INS_SUBA,
490 M680X_INS_SUBB,
491 M680X_INS_SUBD,
492 M680X_INS_SUBE,
493 M680X_INS_SUBF,
494 M680X_INS_SUBR,
495 M680X_INS_SUBW,
496 M680X_INS_SWI,
497 M680X_INS_SWI2,
498 M680X_INS_SWI3,
499 M680X_INS_SYNC,
500 M680X_INS_TAB, ///< M6800/1/2/3
501 M680X_INS_TAP, ///< M6800/1/2/3
502 M680X_INS_TAX,
503 M680X_INS_TBA, ///< M6800/1/2/3
504 M680X_INS_TBEQ,
505 M680X_INS_TBL,
506 M680X_INS_TBNE,
507 M680X_INS_TEST,
508 M680X_INS_TFM,
509 M680X_INS_TFR,
510 M680X_INS_TIM,
511 M680X_INS_TPA, ///< M6800/1/2/3
512 M680X_INS_TST,
513 M680X_INS_TSTA,
514 M680X_INS_TSTB,
515 M680X_INS_TSTD,
516 M680X_INS_TSTE,
517 M680X_INS_TSTF,
518 M680X_INS_TSTW,
519 M680X_INS_TSTX,
520 M680X_INS_TSX, ///< M6800/1/2/3
521 M680X_INS_TSY,
522 M680X_INS_TXA,
523 M680X_INS_TXS, ///< M6800/1/2/3
524 M680X_INS_TYS,
525 M680X_INS_WAI, ///< M6800/1/2/3
526 M680X_INS_WAIT,
527 M680X_INS_WAV,
528 M680X_INS_WAVR,
529 M680X_INS_XGDX, ///< HD6301
530 M680X_INS_XGDY,
531 M680X_INS_ENDING, // <-- mark the end of the list of instructions
532} m680x_insn;
533 
534#ifdef __cplusplus
535}
536#endif
537 
538#endif
539