m680x.h 12 KB

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