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