sparc.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. #ifndef CAPSTONE_SPARC_H
  2. #define CAPSTONE_SPARC_H
  3. /* Capstone Disassembly Engine */
  4. /* By Nguyen Anh Quynh <aquynh@gmail.com>, 2014-2015 */
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. #include "platform.h"
  9. // GCC SPARC toolchain has a default macro called "sparc" which breaks
  10. // compilation
  11. #undef sparc
  12. #ifdef _MSC_VER
  13. #pragma warning(disable:4201)
  14. #endif
  15. /// Enums corresponding to Sparc condition codes, both icc's and fcc's.
  16. typedef enum sparc_cc {
  17. SPARC_CC_INVALID = 0, ///< invalid CC (default)
  18. // Integer condition codes
  19. SPARC_CC_ICC_A = 8+256, ///< Always
  20. SPARC_CC_ICC_N = 0+256, ///< Never
  21. SPARC_CC_ICC_NE = 9+256, ///< Not Equal
  22. SPARC_CC_ICC_E = 1+256, ///< Equal
  23. SPARC_CC_ICC_G = 10+256, ///< Greater
  24. SPARC_CC_ICC_LE = 2+256, ///< Less or Equal
  25. SPARC_CC_ICC_GE = 11+256, ///< Greater or Equal
  26. SPARC_CC_ICC_L = 3+256, ///< Less
  27. SPARC_CC_ICC_GU = 12+256, ///< Greater Unsigned
  28. SPARC_CC_ICC_LEU = 4+256, ///< Less or Equal Unsigned
  29. SPARC_CC_ICC_CC = 13+256, ///< Carry Clear/Great or Equal Unsigned
  30. SPARC_CC_ICC_CS = 5+256, ///< Carry Set/Less Unsigned
  31. SPARC_CC_ICC_POS = 14+256, ///< Positive
  32. SPARC_CC_ICC_NEG = 6+256, ///< Negative
  33. SPARC_CC_ICC_VC = 15+256, ///< Overflow Clear
  34. SPARC_CC_ICC_VS = 7+256, ///< Overflow Set
  35. // Floating condition codes
  36. SPARC_CC_FCC_A = 8+16+256, ///< Always
  37. SPARC_CC_FCC_N = 0+16+256, ///< Never
  38. SPARC_CC_FCC_U = 7+16+256, ///< Unordered
  39. SPARC_CC_FCC_G = 6+16+256, ///< Greater
  40. SPARC_CC_FCC_UG = 5+16+256, ///< Unordered or Greater
  41. SPARC_CC_FCC_L = 4+16+256, ///< Less
  42. SPARC_CC_FCC_UL = 3+16+256, ///< Unordered or Less
  43. SPARC_CC_FCC_LG = 2+16+256, ///< Less or Greater
  44. SPARC_CC_FCC_NE = 1+16+256, ///< Not Equal
  45. SPARC_CC_FCC_E = 9+16+256, ///< Equal
  46. SPARC_CC_FCC_UE = 10+16+256, ///< Unordered or Equal
  47. SPARC_CC_FCC_GE = 11+16+256, ///< Greater or Equal
  48. SPARC_CC_FCC_UGE = 12+16+256, ///< Unordered or Greater or Equal
  49. SPARC_CC_FCC_LE = 13+16+256, ///< Less or Equal
  50. SPARC_CC_FCC_ULE = 14+16+256, ///< Unordered or Less or Equal
  51. SPARC_CC_FCC_O = 15+16+256, ///< Ordered
  52. } sparc_cc;
  53. /// Branch hint
  54. typedef enum sparc_hint {
  55. SPARC_HINT_INVALID = 0, ///< no hint
  56. SPARC_HINT_A = 1 << 0, ///< annul delay slot instruction
  57. SPARC_HINT_PT = 1 << 1, ///< branch taken
  58. SPARC_HINT_PN = 1 << 2, ///< branch NOT taken
  59. } sparc_hint;
  60. /// Operand type for instruction's operands
  61. typedef enum sparc_op_type {
  62. SPARC_OP_INVALID = 0, ///< = CS_OP_INVALID (Uninitialized).
  63. SPARC_OP_REG, ///< = CS_OP_REG (Register operand).
  64. SPARC_OP_IMM, ///< = CS_OP_IMM (Immediate operand).
  65. SPARC_OP_MEM, ///< = CS_OP_MEM (Memory operand).
  66. } sparc_op_type;
  67. /// SPARC registers
  68. typedef enum sparc_reg {
  69. SPARC_REG_INVALID = 0,
  70. SPARC_REG_F0,
  71. SPARC_REG_F1,
  72. SPARC_REG_F2,
  73. SPARC_REG_F3,
  74. SPARC_REG_F4,
  75. SPARC_REG_F5,
  76. SPARC_REG_F6,
  77. SPARC_REG_F7,
  78. SPARC_REG_F8,
  79. SPARC_REG_F9,
  80. SPARC_REG_F10,
  81. SPARC_REG_F11,
  82. SPARC_REG_F12,
  83. SPARC_REG_F13,
  84. SPARC_REG_F14,
  85. SPARC_REG_F15,
  86. SPARC_REG_F16,
  87. SPARC_REG_F17,
  88. SPARC_REG_F18,
  89. SPARC_REG_F19,
  90. SPARC_REG_F20,
  91. SPARC_REG_F21,
  92. SPARC_REG_F22,
  93. SPARC_REG_F23,
  94. SPARC_REG_F24,
  95. SPARC_REG_F25,
  96. SPARC_REG_F26,
  97. SPARC_REG_F27,
  98. SPARC_REG_F28,
  99. SPARC_REG_F29,
  100. SPARC_REG_F30,
  101. SPARC_REG_F31,
  102. SPARC_REG_F32,
  103. SPARC_REG_F34,
  104. SPARC_REG_F36,
  105. SPARC_REG_F38,
  106. SPARC_REG_F40,
  107. SPARC_REG_F42,
  108. SPARC_REG_F44,
  109. SPARC_REG_F46,
  110. SPARC_REG_F48,
  111. SPARC_REG_F50,
  112. SPARC_REG_F52,
  113. SPARC_REG_F54,
  114. SPARC_REG_F56,
  115. SPARC_REG_F58,
  116. SPARC_REG_F60,
  117. SPARC_REG_F62,
  118. SPARC_REG_FCC0, // Floating condition codes
  119. SPARC_REG_FCC1,
  120. SPARC_REG_FCC2,
  121. SPARC_REG_FCC3,
  122. SPARC_REG_FP,
  123. SPARC_REG_G0,
  124. SPARC_REG_G1,
  125. SPARC_REG_G2,
  126. SPARC_REG_G3,
  127. SPARC_REG_G4,
  128. SPARC_REG_G5,
  129. SPARC_REG_G6,
  130. SPARC_REG_G7,
  131. SPARC_REG_I0,
  132. SPARC_REG_I1,
  133. SPARC_REG_I2,
  134. SPARC_REG_I3,
  135. SPARC_REG_I4,
  136. SPARC_REG_I5,
  137. SPARC_REG_I7,
  138. SPARC_REG_ICC, // Integer condition codes
  139. SPARC_REG_L0,
  140. SPARC_REG_L1,
  141. SPARC_REG_L2,
  142. SPARC_REG_L3,
  143. SPARC_REG_L4,
  144. SPARC_REG_L5,
  145. SPARC_REG_L6,
  146. SPARC_REG_L7,
  147. SPARC_REG_O0,
  148. SPARC_REG_O1,
  149. SPARC_REG_O2,
  150. SPARC_REG_O3,
  151. SPARC_REG_O4,
  152. SPARC_REG_O5,
  153. SPARC_REG_O7,
  154. SPARC_REG_SP,
  155. SPARC_REG_Y,
  156. // special register
  157. SPARC_REG_XCC,
  158. SPARC_REG_ENDING, // <-- mark the end of the list of registers
  159. // extras
  160. SPARC_REG_O6 = SPARC_REG_SP,
  161. SPARC_REG_I6 = SPARC_REG_FP,
  162. } sparc_reg;
  163. /// Instruction's operand referring to memory
  164. /// This is associated with SPARC_OP_MEM operand type above
  165. typedef struct sparc_op_mem {
  166. uint8_t base; ///< base register, can be safely interpreted as
  167. ///< a value of type `sparc_reg`, but it is only
  168. ///< one byte wide
  169. uint8_t index; ///< index register, same conditions apply here
  170. int32_t disp; ///< displacement/offset value
  171. } sparc_op_mem;
  172. /// Instruction operand
  173. typedef struct cs_sparc_op {
  174. sparc_op_type type; ///< operand type
  175. union {
  176. sparc_reg reg; ///< register value for REG operand
  177. int64_t imm; ///< immediate value for IMM operand
  178. sparc_op_mem mem; ///< base/disp value for MEM operand
  179. };
  180. } cs_sparc_op;
  181. /// Instruction structure
  182. typedef struct cs_sparc {
  183. sparc_cc cc; ///< code condition for this insn
  184. sparc_hint hint; ///< branch hint: encoding as bitwise OR of sparc_hint.
  185. /// Number of operands of this instruction,
  186. /// or 0 when instruction has no operand.
  187. uint8_t op_count;
  188. cs_sparc_op operands[4]; ///< operands for this instruction.
  189. } cs_sparc;
  190. /// SPARC instruction
  191. typedef enum sparc_insn {
  192. SPARC_INS_INVALID = 0,
  193. SPARC_INS_ADDCC,
  194. SPARC_INS_ADDX,
  195. SPARC_INS_ADDXCC,
  196. SPARC_INS_ADDXC,
  197. SPARC_INS_ADDXCCC,
  198. SPARC_INS_ADD,
  199. SPARC_INS_ALIGNADDR,
  200. SPARC_INS_ALIGNADDRL,
  201. SPARC_INS_ANDCC,
  202. SPARC_INS_ANDNCC,
  203. SPARC_INS_ANDN,
  204. SPARC_INS_AND,
  205. SPARC_INS_ARRAY16,
  206. SPARC_INS_ARRAY32,
  207. SPARC_INS_ARRAY8,
  208. SPARC_INS_B,
  209. SPARC_INS_JMP,
  210. SPARC_INS_BMASK,
  211. SPARC_INS_FB,
  212. SPARC_INS_BRGEZ,
  213. SPARC_INS_BRGZ,
  214. SPARC_INS_BRLEZ,
  215. SPARC_INS_BRLZ,
  216. SPARC_INS_BRNZ,
  217. SPARC_INS_BRZ,
  218. SPARC_INS_BSHUFFLE,
  219. SPARC_INS_CALL,
  220. SPARC_INS_CASX,
  221. SPARC_INS_CAS,
  222. SPARC_INS_CMASK16,
  223. SPARC_INS_CMASK32,
  224. SPARC_INS_CMASK8,
  225. SPARC_INS_CMP,
  226. SPARC_INS_EDGE16,
  227. SPARC_INS_EDGE16L,
  228. SPARC_INS_EDGE16LN,
  229. SPARC_INS_EDGE16N,
  230. SPARC_INS_EDGE32,
  231. SPARC_INS_EDGE32L,
  232. SPARC_INS_EDGE32LN,
  233. SPARC_INS_EDGE32N,
  234. SPARC_INS_EDGE8,
  235. SPARC_INS_EDGE8L,
  236. SPARC_INS_EDGE8LN,
  237. SPARC_INS_EDGE8N,
  238. SPARC_INS_FABSD,
  239. SPARC_INS_FABSQ,
  240. SPARC_INS_FABSS,
  241. SPARC_INS_FADDD,
  242. SPARC_INS_FADDQ,
  243. SPARC_INS_FADDS,
  244. SPARC_INS_FALIGNDATA,
  245. SPARC_INS_FAND,
  246. SPARC_INS_FANDNOT1,
  247. SPARC_INS_FANDNOT1S,
  248. SPARC_INS_FANDNOT2,
  249. SPARC_INS_FANDNOT2S,
  250. SPARC_INS_FANDS,
  251. SPARC_INS_FCHKSM16,
  252. SPARC_INS_FCMPD,
  253. SPARC_INS_FCMPEQ16,
  254. SPARC_INS_FCMPEQ32,
  255. SPARC_INS_FCMPGT16,
  256. SPARC_INS_FCMPGT32,
  257. SPARC_INS_FCMPLE16,
  258. SPARC_INS_FCMPLE32,
  259. SPARC_INS_FCMPNE16,
  260. SPARC_INS_FCMPNE32,
  261. SPARC_INS_FCMPQ,
  262. SPARC_INS_FCMPS,
  263. SPARC_INS_FDIVD,
  264. SPARC_INS_FDIVQ,
  265. SPARC_INS_FDIVS,
  266. SPARC_INS_FDMULQ,
  267. SPARC_INS_FDTOI,
  268. SPARC_INS_FDTOQ,
  269. SPARC_INS_FDTOS,
  270. SPARC_INS_FDTOX,
  271. SPARC_INS_FEXPAND,
  272. SPARC_INS_FHADDD,
  273. SPARC_INS_FHADDS,
  274. SPARC_INS_FHSUBD,
  275. SPARC_INS_FHSUBS,
  276. SPARC_INS_FITOD,
  277. SPARC_INS_FITOQ,
  278. SPARC_INS_FITOS,
  279. SPARC_INS_FLCMPD,
  280. SPARC_INS_FLCMPS,
  281. SPARC_INS_FLUSHW,
  282. SPARC_INS_FMEAN16,
  283. SPARC_INS_FMOVD,
  284. SPARC_INS_FMOVQ,
  285. SPARC_INS_FMOVRDGEZ,
  286. SPARC_INS_FMOVRQGEZ,
  287. SPARC_INS_FMOVRSGEZ,
  288. SPARC_INS_FMOVRDGZ,
  289. SPARC_INS_FMOVRQGZ,
  290. SPARC_INS_FMOVRSGZ,
  291. SPARC_INS_FMOVRDLEZ,
  292. SPARC_INS_FMOVRQLEZ,
  293. SPARC_INS_FMOVRSLEZ,
  294. SPARC_INS_FMOVRDLZ,
  295. SPARC_INS_FMOVRQLZ,
  296. SPARC_INS_FMOVRSLZ,
  297. SPARC_INS_FMOVRDNZ,
  298. SPARC_INS_FMOVRQNZ,
  299. SPARC_INS_FMOVRSNZ,
  300. SPARC_INS_FMOVRDZ,
  301. SPARC_INS_FMOVRQZ,
  302. SPARC_INS_FMOVRSZ,
  303. SPARC_INS_FMOVS,
  304. SPARC_INS_FMUL8SUX16,
  305. SPARC_INS_FMUL8ULX16,
  306. SPARC_INS_FMUL8X16,
  307. SPARC_INS_FMUL8X16AL,
  308. SPARC_INS_FMUL8X16AU,
  309. SPARC_INS_FMULD,
  310. SPARC_INS_FMULD8SUX16,
  311. SPARC_INS_FMULD8ULX16,
  312. SPARC_INS_FMULQ,
  313. SPARC_INS_FMULS,
  314. SPARC_INS_FNADDD,
  315. SPARC_INS_FNADDS,
  316. SPARC_INS_FNAND,
  317. SPARC_INS_FNANDS,
  318. SPARC_INS_FNEGD,
  319. SPARC_INS_FNEGQ,
  320. SPARC_INS_FNEGS,
  321. SPARC_INS_FNHADDD,
  322. SPARC_INS_FNHADDS,
  323. SPARC_INS_FNOR,
  324. SPARC_INS_FNORS,
  325. SPARC_INS_FNOT1,
  326. SPARC_INS_FNOT1S,
  327. SPARC_INS_FNOT2,
  328. SPARC_INS_FNOT2S,
  329. SPARC_INS_FONE,
  330. SPARC_INS_FONES,
  331. SPARC_INS_FOR,
  332. SPARC_INS_FORNOT1,
  333. SPARC_INS_FORNOT1S,
  334. SPARC_INS_FORNOT2,
  335. SPARC_INS_FORNOT2S,
  336. SPARC_INS_FORS,
  337. SPARC_INS_FPACK16,
  338. SPARC_INS_FPACK32,
  339. SPARC_INS_FPACKFIX,
  340. SPARC_INS_FPADD16,
  341. SPARC_INS_FPADD16S,
  342. SPARC_INS_FPADD32,
  343. SPARC_INS_FPADD32S,
  344. SPARC_INS_FPADD64,
  345. SPARC_INS_FPMERGE,
  346. SPARC_INS_FPSUB16,
  347. SPARC_INS_FPSUB16S,
  348. SPARC_INS_FPSUB32,
  349. SPARC_INS_FPSUB32S,
  350. SPARC_INS_FQTOD,
  351. SPARC_INS_FQTOI,
  352. SPARC_INS_FQTOS,
  353. SPARC_INS_FQTOX,
  354. SPARC_INS_FSLAS16,
  355. SPARC_INS_FSLAS32,
  356. SPARC_INS_FSLL16,
  357. SPARC_INS_FSLL32,
  358. SPARC_INS_FSMULD,
  359. SPARC_INS_FSQRTD,
  360. SPARC_INS_FSQRTQ,
  361. SPARC_INS_FSQRTS,
  362. SPARC_INS_FSRA16,
  363. SPARC_INS_FSRA32,
  364. SPARC_INS_FSRC1,
  365. SPARC_INS_FSRC1S,
  366. SPARC_INS_FSRC2,
  367. SPARC_INS_FSRC2S,
  368. SPARC_INS_FSRL16,
  369. SPARC_INS_FSRL32,
  370. SPARC_INS_FSTOD,
  371. SPARC_INS_FSTOI,
  372. SPARC_INS_FSTOQ,
  373. SPARC_INS_FSTOX,
  374. SPARC_INS_FSUBD,
  375. SPARC_INS_FSUBQ,
  376. SPARC_INS_FSUBS,
  377. SPARC_INS_FXNOR,
  378. SPARC_INS_FXNORS,
  379. SPARC_INS_FXOR,
  380. SPARC_INS_FXORS,
  381. SPARC_INS_FXTOD,
  382. SPARC_INS_FXTOQ,
  383. SPARC_INS_FXTOS,
  384. SPARC_INS_FZERO,
  385. SPARC_INS_FZEROS,
  386. SPARC_INS_JMPL,
  387. SPARC_INS_LDD,
  388. SPARC_INS_LD,
  389. SPARC_INS_LDQ,
  390. SPARC_INS_LDSB,
  391. SPARC_INS_LDSH,
  392. SPARC_INS_LDSW,
  393. SPARC_INS_LDUB,
  394. SPARC_INS_LDUH,
  395. SPARC_INS_LDX,
  396. SPARC_INS_LZCNT,
  397. SPARC_INS_MEMBAR,
  398. SPARC_INS_MOVDTOX,
  399. SPARC_INS_MOV,
  400. SPARC_INS_MOVRGEZ,
  401. SPARC_INS_MOVRGZ,
  402. SPARC_INS_MOVRLEZ,
  403. SPARC_INS_MOVRLZ,
  404. SPARC_INS_MOVRNZ,
  405. SPARC_INS_MOVRZ,
  406. SPARC_INS_MOVSTOSW,
  407. SPARC_INS_MOVSTOUW,
  408. SPARC_INS_MULX,
  409. SPARC_INS_NOP,
  410. SPARC_INS_ORCC,
  411. SPARC_INS_ORNCC,
  412. SPARC_INS_ORN,
  413. SPARC_INS_OR,
  414. SPARC_INS_PDIST,
  415. SPARC_INS_PDISTN,
  416. SPARC_INS_POPC,
  417. SPARC_INS_RD,
  418. SPARC_INS_RESTORE,
  419. SPARC_INS_RETT,
  420. SPARC_INS_SAVE,
  421. SPARC_INS_SDIVCC,
  422. SPARC_INS_SDIVX,
  423. SPARC_INS_SDIV,
  424. SPARC_INS_SETHI,
  425. SPARC_INS_SHUTDOWN,
  426. SPARC_INS_SIAM,
  427. SPARC_INS_SLLX,
  428. SPARC_INS_SLL,
  429. SPARC_INS_SMULCC,
  430. SPARC_INS_SMUL,
  431. SPARC_INS_SRAX,
  432. SPARC_INS_SRA,
  433. SPARC_INS_SRLX,
  434. SPARC_INS_SRL,
  435. SPARC_INS_STBAR,
  436. SPARC_INS_STB,
  437. SPARC_INS_STD,
  438. SPARC_INS_ST,
  439. SPARC_INS_STH,
  440. SPARC_INS_STQ,
  441. SPARC_INS_STX,
  442. SPARC_INS_SUBCC,
  443. SPARC_INS_SUBX,
  444. SPARC_INS_SUBXCC,
  445. SPARC_INS_SUB,
  446. SPARC_INS_SWAP,
  447. SPARC_INS_TADDCCTV,
  448. SPARC_INS_TADDCC,
  449. SPARC_INS_T,
  450. SPARC_INS_TSUBCCTV,
  451. SPARC_INS_TSUBCC,
  452. SPARC_INS_UDIVCC,
  453. SPARC_INS_UDIVX,
  454. SPARC_INS_UDIV,
  455. SPARC_INS_UMULCC,
  456. SPARC_INS_UMULXHI,
  457. SPARC_INS_UMUL,
  458. SPARC_INS_UNIMP,
  459. SPARC_INS_FCMPED,
  460. SPARC_INS_FCMPEQ,
  461. SPARC_INS_FCMPES,
  462. SPARC_INS_WR,
  463. SPARC_INS_XMULX,
  464. SPARC_INS_XMULXHI,
  465. SPARC_INS_XNORCC,
  466. SPARC_INS_XNOR,
  467. SPARC_INS_XORCC,
  468. SPARC_INS_XOR,
  469. // alias instructions
  470. SPARC_INS_RET,
  471. SPARC_INS_RETL,
  472. SPARC_INS_ENDING, // <-- mark the end of the list of instructions
  473. } sparc_insn;
  474. /// Group of SPARC instructions
  475. typedef enum sparc_insn_group {
  476. SPARC_GRP_INVALID = 0, ///< = CS_GRP_INVALID
  477. // Generic groups
  478. // all jump instructions (conditional+direct+indirect jumps)
  479. SPARC_GRP_JUMP, ///< = CS_GRP_JUMP
  480. // Architecture-specific groups
  481. SPARC_GRP_HARDQUAD = 128,
  482. SPARC_GRP_V9,
  483. SPARC_GRP_VIS,
  484. SPARC_GRP_VIS2,
  485. SPARC_GRP_VIS3,
  486. SPARC_GRP_32BIT,
  487. SPARC_GRP_64BIT,
  488. SPARC_GRP_ENDING, // <-- mark the end of the list of groups
  489. } sparc_insn_group;
  490. #ifdef __cplusplus
  491. }
  492. #endif
  493. #endif