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