cr16-opc.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. /* cr16-opc.c -- Table of opcodes for the CR16 processor.
  2. Copyright (C) 2007-2022 Free Software Foundation, Inc.
  3. Contributed by M R Swami Reddy (MR.Swami.Reddy@nsc.com)
  4. This file is part of the GNU opcodes library.
  5. This library is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3, or (at your option)
  8. any later version.
  9. It is distributed in the hope that it will be useful, but WITHOUT
  10. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  12. License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software Foundation,
  15. Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
  16. #include <stdio.h>
  17. #include "libiberty.h"
  18. #include "symcat.h"
  19. #include "opcode/cr16.h"
  20. const inst cr16_instruction[] =
  21. {
  22. /* Create an arithmetic instruction - INST[bw]. */
  23. #define ARITH_BYTE_INST(NAME, OPC, OP1) \
  24. /* opc8 imm4 r */ \
  25. {NAME, 1, OPC, 24, ARITH_BYTE_INS, {{uimm4_1,20}, {regr,16}}}, \
  26. /* opc8 imm16 r */ \
  27. {NAME, 2, (OPC<<4)+0xB, 20, ARITH_BYTE_INS, {{OP1,0}, {regr,16}}}, \
  28. /* opc8 r r */ \
  29. {NAME, 1, OPC+0x1, 24, ARITH_BYTE_INS, {{regr,20}, {regr,16}}}
  30. /* For Logical operations, allow unsigned imm16 also. */
  31. #define ARITH1_BYTE_INST(NAME, OPC, OP1) \
  32. /* opc8 imm16 r */ \
  33. {NAME, 2, (OPC<<4)+0xB, 20, ARITH_BYTE_INS, {{OP1,0}, {regr,16}}}
  34. ARITH_BYTE_INST ("andb", 0x20, uimm16),
  35. ARITH1_BYTE_INST ("andb", 0x20, imm16),
  36. ARITH_BYTE_INST ("andw", 0x22, uimm16),
  37. ARITH1_BYTE_INST ("andw", 0x22, imm16),
  38. ARITH_BYTE_INST ("orb", 0x24, uimm16),
  39. ARITH1_BYTE_INST ("orb", 0x24, imm16),
  40. ARITH_BYTE_INST ("orw", 0x26, uimm16),
  41. ARITH1_BYTE_INST ("orw", 0x26, imm16),
  42. ARITH_BYTE_INST ("xorb", 0x28, uimm16),
  43. ARITH1_BYTE_INST ("xorb", 0x28, imm16),
  44. ARITH_BYTE_INST ("xorw", 0x2A, uimm16),
  45. ARITH1_BYTE_INST ("xorw", 0x2A, imm16),
  46. ARITH_BYTE_INST ("addub", 0x2C, imm16),
  47. ARITH_BYTE_INST ("adduw", 0x2E, imm16),
  48. ARITH_BYTE_INST ("addb", 0x30, imm16),
  49. ARITH_BYTE_INST ("addw", 0x32, imm16),
  50. ARITH_BYTE_INST ("addcb", 0x34, imm16),
  51. ARITH_BYTE_INST ("addcw", 0x36, imm16),
  52. ARITH_BYTE_INST ("subb", 0x38, imm16),
  53. ARITH_BYTE_INST ("subw", 0x3A, imm16),
  54. ARITH_BYTE_INST ("subcb", 0x3C, imm16),
  55. ARITH_BYTE_INST ("subcw", 0x3E, imm16),
  56. ARITH_BYTE_INST ("cmpb", 0x50, imm16),
  57. ARITH_BYTE_INST ("cmpw", 0x52, imm16),
  58. ARITH_BYTE_INST ("movb", 0x58, imm16),
  59. ARITH_BYTE_INST ("movw", 0x5A, imm16),
  60. ARITH_BYTE_INST ("mulb", 0x64, imm16),
  61. ARITH_BYTE_INST ("mulw", 0x66, imm16),
  62. #define ARITH_BYTE_INST1(NAME, OPC) \
  63. /* opc8 r r */ \
  64. {NAME, 1, OPC, 24, ARITH_BYTE_INS, {{regr,20}, {regr,16}}}
  65. ARITH_BYTE_INST1 ("movxb", 0x5C),
  66. ARITH_BYTE_INST1 ("movzb", 0x5D),
  67. ARITH_BYTE_INST1 ("mulsb", 0x0B),
  68. #define ARITH_BYTE_INST2(NAME, OPC) \
  69. /* opc8 r rp */ \
  70. {NAME, 1, OPC, 24, ARITH_BYTE_INS, {{regr,20}, {regp,16}}}
  71. ARITH_BYTE_INST2 ("movxw", 0x5E),
  72. ARITH_BYTE_INST2 ("movzw", 0x5F),
  73. ARITH_BYTE_INST2 ("mulsw", 0x62),
  74. ARITH_BYTE_INST2 ("muluw", 0x63),
  75. /* Create an arithmetic instruction - INST[d]- with 3 types. */
  76. #define ARITH_INST_D(NAME, OPC) \
  77. /* opc8 imm4 rp */ \
  78. {NAME, 1, OPC, 24, ARITH_INS, {{uimm4_1,20}, {regp,16}}}, \
  79. /* opc8 imm16 rp */ \
  80. {NAME, 2, (OPC<<4)+0xB, 20, ARITH_INS, {{imm16,0}, {regp,16}}}, \
  81. /* opc8 rp rp */ \
  82. {NAME, 1, OPC+1, 24, ARITH_INS, {{regp,20}, {regp,16}}}
  83. /* Create an arithmetic instruction - INST[d]-20 bit types. */
  84. #define ARITH_INST20(NAME, OPC) \
  85. /* opc8 uimm20 rp */ \
  86. {NAME, 2, OPC, 24, ARITH_INS, {{uimm20,0}, {regp,20}}}
  87. /* Create an arithmetic instruction - INST[d]-32 bit types. */
  88. #define ARITH_INST32(NAME, OPC, OP1) \
  89. /* opc12 imm32 rp */ \
  90. {NAME, 3, OPC, 20, ARITH_INS, {{OP1,0}, {regp,16}}}
  91. /* Create an arithmetic instruction - INST[d]-32bit types(reg pairs).*/
  92. #define ARITH_INST32RP(NAME, OPC) \
  93. /* opc24 rp rp */ \
  94. {NAME, 2, OPC, 12, ARITH_INS, {{regp,4}, {regp,0}}}
  95. ARITH_INST_D ("movd", 0x54),
  96. ARITH_INST20 ("movd", 0x05),
  97. ARITH_INST32 ("movd", 0x007, imm32),
  98. ARITH_INST_D ("addd", 0x60),
  99. ARITH_INST20 ("addd", 0x04),
  100. ARITH_INST32 ("addd", 0x002, imm32),
  101. ARITH_INST32 ("subd", 0x003, imm32),
  102. ARITH_INST32RP ("subd", 0x0014C),
  103. ARITH_INST_D ("cmpd", 0x56),
  104. ARITH_INST32 ("cmpd", 0x009, imm32),
  105. ARITH_INST32 ("andd", 0x004, uimm32),
  106. ARITH_INST32RP ("andd", 0x0014B),
  107. ARITH_INST32 ("ord", 0x005, uimm32),
  108. ARITH_INST32RP ("ord", 0x00149),
  109. ARITH_INST32 ("xord", 0x006, uimm32),
  110. ARITH_INST32RP ("xord", 0x0014A),
  111. /* Create a shift instruction. */
  112. #define SHIFT_INST_A(NAME, OPC1, OPC2, SHIFT, OP1, OP2) \
  113. /* opc imm r */ \
  114. {NAME, 1, OPC1, SHIFT, SHIFT_INS, {{OP1,20}, {OP2,16}}}, \
  115. /* opc imm r */ \
  116. {NAME, 1, OPC1+1, SHIFT, SHIFT_INS, {{OP1,20}, {OP2,16}}},\
  117. /* opc r r */ \
  118. {NAME, 1, OPC2, 24, SHIFT_INS, {{regr,20}, {OP2,16}}}
  119. SHIFT_INST_A("ashub", 0x80, 0x41, 23, imm4, regr),
  120. SHIFT_INST_A("ashud", 0x26, 0x48, 25, imm6, regp),
  121. SHIFT_INST_A("ashuw", 0x42, 0x45, 24, imm5, regr),
  122. #define SHIFT_INST_L(NAME, OPC1, OPC2, SHIFT, OP1, OP2) \
  123. /* opc imm r */ \
  124. {NAME, 1, OPC1, SHIFT, SHIFT_INS, {{OP1,20}, {OP2,16}}}, \
  125. /* opc r r */ \
  126. {NAME, 1, OPC2, 24, SHIFT_INS, {{regr,20}, {OP2,16}}}
  127. SHIFT_INST_L("lshb", 0x13, 0x44, 23, imm4, regr),
  128. SHIFT_INST_L("lshd", 0x25, 0x47, 25, imm6, regp),
  129. SHIFT_INST_L("lshw", 0x49, 0x46, 24, imm5, regr),
  130. /* Create a conditional branch instruction. */
  131. #define BRANCH_INST(NAME, OPC) \
  132. /* opc4 c4 dispe9 */ \
  133. {NAME, 1, OPC, 28, BRANCH_INS | RELAXABLE, {{cc,20}, {dispe9,16}}},\
  134. /* opc4 c4 disps17 */ \
  135. {NAME, 2, ((OPC<<4)+0x8), 24, BRANCH_INS | RELAXABLE, {{cc,20}, {disps17,0}}},\
  136. /* opc4 c4 disps25 */ \
  137. {NAME, 3, (OPC<<4), 16 , BRANCH_INS | RELAXABLE, {{cc,4}, {disps25,16}}}
  138. BRANCH_INST ("b", 0x1),
  139. /* Create a 'Branch if Equal to 0' instruction. */
  140. #define BRANCH_NEQ_INST(NAME, OPC) \
  141. /* opc8 disps5 r */ \
  142. {NAME, 1, OPC, 24, BRANCH_NEQ_INS, {{regr,16}, {disps5,20}}}
  143. BRANCH_NEQ_INST ("beq0b", 0x0C),
  144. BRANCH_NEQ_INST ("bne0b", 0x0D),
  145. BRANCH_NEQ_INST ("beq0w", 0x0E),
  146. BRANCH_NEQ_INST ("bne0w", 0x0F),
  147. /* Create an instruction using a single register operand. */
  148. #define REG1_INST(NAME, OPC) \
  149. /* opc8 c4 r */ \
  150. {NAME, 1, OPC, 20, NO_TYPE_INS, {{regr,16}}}
  151. #define REGP1_INST(NAME, OPC) \
  152. /* opc8 c4 r */ \
  153. {NAME, 1, OPC, 20, NO_TYPE_INS, {{regp,16}}}
  154. /* Same as REG1_INST, with additional FLAGS. */
  155. #define REG1_FLAG_INST(NAME, OPC, FLAGS) \
  156. /* opc8 c4 r */ \
  157. {NAME, 1, OPC, 20, NO_TYPE_INS | FLAGS, {{regp,16}}}
  158. /* JCond instructions */
  159. REGP1_INST ("jeq", 0x0A0),
  160. REGP1_INST ("jne", 0x0A1),
  161. REGP1_INST ("jcs", 0x0A2),
  162. REGP1_INST ("jcc", 0x0A3),
  163. REGP1_INST ("jhi", 0x0A4),
  164. REGP1_INST ("jls", 0x0A5),
  165. REGP1_INST ("jgt", 0x0A6),
  166. REGP1_INST ("jle", 0x0A7),
  167. REGP1_INST ("jfs", 0x0A8),
  168. REGP1_INST ("jfc", 0x0A9),
  169. REGP1_INST ("jlo", 0x0AA),
  170. REGP1_INST ("jhs", 0x0AB),
  171. REGP1_INST ("jlt", 0x0AC),
  172. REGP1_INST ("jge", 0x0AD),
  173. REGP1_INST ("jump", 0x0AE),
  174. REGP1_INST ("jusr", 0x0AF),
  175. /* SCond instructions */
  176. REG1_INST ("seq", 0x080),
  177. REG1_INST ("sne", 0x081),
  178. REG1_INST ("scs", 0x082),
  179. REG1_INST ("scc", 0x083),
  180. REG1_INST ("shi", 0x084),
  181. REG1_INST ("sls", 0x085),
  182. REG1_INST ("sgt", 0x086),
  183. REG1_INST ("sle", 0x087),
  184. REG1_INST ("sfs", 0x088),
  185. REG1_INST ("sfc", 0x089),
  186. REG1_INST ("slo", 0x08A),
  187. REG1_INST ("shs", 0x08B),
  188. REG1_INST ("slt", 0x08C),
  189. REG1_INST ("sge", 0x08D),
  190. /* Create an instruction using two register operands. */
  191. #define REG3_INST(NAME, OPC) \
  192. /* opc24 r r rp */ \
  193. {NAME, 2, OPC, 12, NO_TYPE_INS, {{regr,4}, {regr,0}, {regp,8}}}
  194. /* MULTIPLY INSTRUCTIONS */
  195. REG3_INST ("macqw", 0x0014d),
  196. REG3_INST ("macuw", 0x0014e),
  197. REG3_INST ("macsw", 0x0014f),
  198. /* Create a branch instruction. */
  199. #define BR_INST(NAME, OPC) \
  200. /* opc12 ra disps25 */ \
  201. {NAME, 2, OPC, 24, NO_TYPE_INS, {{rra,0}, {disps25,0}}}
  202. #define BR_INST_RP(NAME, OPC) \
  203. /* opc8 rp disps25 */ \
  204. {NAME, 3, OPC, 12, NO_TYPE_INS, {{regp,4}, {disps25,16}}}
  205. BR_INST ("bal", 0xC0),
  206. BR_INST_RP ("bal", 0x00102),
  207. #define REGPP2_INST(NAME, OPC) \
  208. /* opc16 rp rp */ \
  209. {NAME, 2, OPC, 12, NO_TYPE_INS, {{regp,0}, {regp,4}}}
  210. /* Jump and link instructions. */
  211. REGP1_INST ("jal",0x00D),
  212. REGPP2_INST ("jal",0x00148),
  213. /* Instructions including a register list (opcode is represented as a mask). */
  214. #define REGLIST_INST(NAME, OPC, TYPE) \
  215. /* opc7 r count3 RA */ \
  216. {NAME,1, (OPC<<1)+1, 23, TYPE, {{uimm3_1,20},{regr,16},{regr,0}}}, \
  217. /* opc8 r count3 */ \
  218. {NAME, 1, OPC, 24, TYPE, {{uimm3_1,20}, {regr,16}}}, \
  219. /* opc12 RA */ \
  220. {NAME, 1, (OPC<<8)+0x1E, 16, TYPE, {{regr,0}}}
  221. REGLIST_INST ("push", 0x01, (NO_TYPE_INS | REG_LIST)),
  222. REGLIST_INST ("pop", 0x02, (NO_TYPE_INS | REG_LIST)),
  223. REGLIST_INST ("popret", 0x03, (NO_TYPE_INS | REG_LIST)),
  224. {"loadm", 1, 0x14, 19, NO_TYPE_INS | REG_LIST, {{uimm3_1,16}}},
  225. {"loadmp", 1, 0x15, 19, NO_TYPE_INS | REG_LIST, {{uimm3_1,16}}},
  226. {"storm", 1, 0x16, 19, NO_TYPE_INS | REG_LIST, {{uimm3_1,16}}},
  227. {"stormp", 1, 0x17, 19, NO_TYPE_INS | REG_LIST, {{uimm3_1,16}}},
  228. /* Processor Register Manipulation instructions */
  229. /* opc16 reg, preg */
  230. {"lpr", 2, 0x00140, 12, NO_TYPE_INS, {{regr,0}, {pregr,4}}},
  231. /* opc16 regp, pregp */
  232. {"lprd", 2, 0x00141, 12, NO_TYPE_INS, {{regp,0}, {pregrp,4}}},
  233. /* opc16 preg, reg */
  234. {"spr", 2, 0x00142, 12, NO_TYPE_INS, {{pregr,4}, {regr,0}}},
  235. /* opc16 pregp, regp */
  236. {"sprd", 2, 0x00143, 12, NO_TYPE_INS, {{pregrp,4}, {regp,0}}},
  237. /* Miscellaneous. */
  238. /* opc12 ui4 */
  239. {"excp", 1, 0x00C, 20, NO_TYPE_INS, {{uimm4,16}}},
  240. /* Create a bit-b instruction. */
  241. #define CSTBIT_INST_B(NAME, OP, OPC1, OPC2, OPC3, OPC4) \
  242. /* opcNN iN abs20 */ \
  243. {NAME, 2, (OPC3+1), 23, CSTBIT_INS, {{OP,20},{abs20,0}}}, \
  244. /* opcNN iN abs24 */ \
  245. {NAME, 3, (OPC2+3), 12, CSTBIT_INS, {{OP,4},{abs24,16}}}, \
  246. /* opcNN iN (Rindex)abs20 */ \
  247. {NAME, 2, OPC1, 24, CSTBIT_INS, {{OP,20}, {rindex7_abs20,0}}}, \
  248. /* opcNN iN (prp) disps14(RPbase) */ \
  249. {NAME, 2, OPC4, 22, CSTBIT_INS, {{OP,4},{rpindex_disps14,0}}}, \
  250. /* opcNN iN disps20(Rbase) */ \
  251. {NAME, 3, OPC2, 12, CSTBIT_INS, {{OP,4}, {rbase_disps20,16}}}, \
  252. /* opcNN iN (rp) disps0(RPbase) */ \
  253. {NAME, 1, OPC3-2, 23, CSTBIT_INS, {{OP,20}, {rpbase_disps0,16}}}, \
  254. /* opcNN iN (rp) disps16(RPBase) */ \
  255. {NAME, 2, OPC3, 23, CSTBIT_INS, {{OP,20}, {rpbase_disps16,0}}}, \
  256. /* opcNN iN (rp) disps20(RPBase) */ \
  257. {NAME, 3, (OPC2+1), 12, CSTBIT_INS, {{OP,4}, {rpbase_disps20,16}}}, \
  258. /* opcNN iN rrp (Rindex)disps20(RPbase) */ \
  259. {NAME, 3, (OPC2+2), 12, CSTBIT_INS, {{OP,4}, {rpindex_disps20,16}}}
  260. CSTBIT_INST_B ("cbitb", uimm3, 0x68, 0x00104, 0xD6, 0x1AA),
  261. CSTBIT_INST_B ("sbitb", uimm3, 0x70, 0x00108, 0xE6, 0x1CA),
  262. CSTBIT_INST_B ("tbitb", uimm3, 0x78, 0x0010C, 0xF6, 0x1EA),
  263. /* Create a bit-w instruction. */
  264. #define CSTBIT_INST_W(NAME, OP, OPC1, OPC2, OPC3, OPC4) \
  265. /* opcNN iN abs20 */ \
  266. {NAME, 2, OPC1+6, 24, CSTBIT_INS, {{OP,20},{abs20,0}}}, \
  267. /* opcNN iN abs24 */ \
  268. {NAME, 3, OPC2+3, 12, CSTBIT_INS, {{OP,4},{abs24,16}}}, \
  269. /* opcNN iN (Rindex)abs20 */ \
  270. {NAME, 2, OPC3, 25, CSTBIT_INS, {{OP,20}, {rindex8_abs20,0}}}, \
  271. /* opcNN iN (prp) disps14(RPbase) */ \
  272. {NAME, 2, OPC4, 22, CSTBIT_INS, {{OP,4},{rpindex_disps14,0}}}, \
  273. /* opcNN iN disps20(Rbase) */ \
  274. {NAME, 3, OPC2, 12, CSTBIT_INS, {{OP,4}, {rbase_disps20,16}}}, \
  275. /* opcNN iN (rp) disps0(RPbase) */ \
  276. {NAME, 1, OPC1+5, 24, CSTBIT_INS, {{OP,20}, {rpbase_disps0,16}}}, \
  277. /* opcNN iN (rp) disps16(RPBase) */ \
  278. {NAME, 2, OPC1, 24, CSTBIT_INS, {{OP,20}, {rpbase_disps16,0}}}, \
  279. /* opcNN iN (rp) disps20(RPBase) */ \
  280. {NAME, 3, OPC2+1, 12, CSTBIT_INS, {{OP,4}, {rpbase_disps20,16}}}, \
  281. /* opcNN iN rrp (Rindex)disps20(RPbase) */ \
  282. {NAME, 3, OPC2+2, 12, CSTBIT_INS, {{OP,4}, {rpindex_disps20,16}}}
  283. CSTBIT_INST_W ("cbitw", uimm4, 0x69, 0x00114, 0x36, 0x1AB),
  284. CSTBIT_INST_W ("sbitw", uimm4, 0x71, 0x00118, 0x3A, 0x1CB),
  285. CSTBIT_INST_W ("tbitw", uimm4, 0x79, 0x0011C, 0x3E, 0x1EB),
  286. /* tbit cnt */
  287. {"tbit", 1, 0x06, 24, CSTBIT_INS, {{uimm4,20}, {regr,16}}},
  288. /* tbit reg reg */
  289. {"tbit", 1, 0x07, 24, CSTBIT_INS, {{regr,20}, {regr,16}}},
  290. /* Load instructions (from memory to register). */
  291. #define LD_REG_INST(NAME, OPC1, OPC2, OPC3, OPC4, OPC5, OP_S, OP_D) \
  292. /* opc8 reg abs20 */ \
  293. {NAME, 2, OPC3, 24, LD_STOR_INS, {{abs20,0}, {OP_D,20}}}, \
  294. /* opc20 reg abs24 */ \
  295. {NAME, 3, OPC1+3, 12, LD_STOR_INS, {{abs24,16}, {OP_D,4}}}, \
  296. /* opc7 reg rindex8_abs20 */ \
  297. {NAME, 2, OPC5, 25, LD_STOR_INS, {{rindex8_abs20,0}, {OP_D,20}}}, \
  298. /* opc4 reg disps4(RPbase) */ \
  299. {NAME, 1, (OPC2>>4), 28, LD_STOR_INS, {{OP_S,24}, {OP_D,20}}}, \
  300. /* opcNN reg disps0(RPbase) */ \
  301. {NAME, 1, OPC2, 24, LD_STOR_INS, {{rpindex_disps0,0}, {OP_D,20}}}, \
  302. /* opc reg disps14(RPbase) */ \
  303. {NAME, 2, OPC4, 22, LD_STOR_INS, {{rpindex_disps14,0}, {OP_D,20}}}, \
  304. /* opc reg -disps20(Rbase) */ \
  305. {NAME, 3, OPC1+0x60, 12, LD_STOR_INS, {{rbase_dispe20,16}, {OP_D,4}}}, \
  306. /* opc reg disps20(Rbase) */ \
  307. {NAME, 3, OPC1, 12, LD_STOR_INS, {{rbase_disps20,16}, {OP_D,4}}}, \
  308. /* opc reg (rp) disps16(RPbase) */ \
  309. {NAME, 2, OPC2+1, 24, LD_STOR_INS, {{rpbase_disps16,0}, {OP_D,20}}}, \
  310. /* opc16 reg (rp) disps20(RPbase) */ \
  311. {NAME, 3, OPC1+1, 12, LD_STOR_INS, {{rpbase_disps20,16}, {OP_D,4}}}, \
  312. /* op reg (rp) -disps20(RPbase) */ \
  313. {NAME, 3, OPC1+0x61, 12, LD_STOR_INS, {{rpbase_dispe20,16}, {OP_D,4}}}, \
  314. /* opc reg rrp (Rindex)disps20(RPbase) */ \
  315. {NAME, 3, (OPC1+2), 12, LD_STOR_INS, {{rpindex_disps20,16}, {OP_D,4}}}
  316. LD_REG_INST ("loadb", 0x00124, 0xBE, 0x88, 0x219, 0x45, rpbase_disps4, regr),
  317. LD_REG_INST ("loadd", 0x00128, 0xAE, 0x87, 0x21A, 0x46, rpbase_dispe4, regp),
  318. LD_REG_INST ("loadw", 0x0012C, 0x9E, 0x89, 0x21B, 0x47, rpbase_dispe4, regr),
  319. /* Store instructions (from reg to memory). */
  320. #define ST_REG_INST(NAME, OPC1, OPC2, OPC3, OPC4, OPC5, OP_D, OP_S) \
  321. /* opc8 reg abs20 */ \
  322. {NAME, 2, OPC3, 24, LD_STOR_INS, {{OP_S,20}, {abs20,0}}}, \
  323. /* opc20 reg abs24 */ \
  324. {NAME, 3, OPC1+3, 12, LD_STOR_INS, {{OP_S,4}, {abs24,16}}}, \
  325. /* opc7 reg rindex8_abs20 */ \
  326. {NAME, 2, OPC5, 25, LD_STOR_INS, {{OP_S,20}, {rindex8_abs20,0}}}, \
  327. /* opc4 reg disps4(RPbase) */ \
  328. {NAME, 1, (OPC2>>4), 28, LD_STOR_INS, {{OP_S,20}, {OP_D,24}}}, \
  329. /* opcNN reg disps0(RPbase) */ \
  330. {NAME, 1, OPC2, 24, LD_STOR_INS, {{OP_S,20}, {rpindex_disps0,0}}}, \
  331. /* opc reg disps14(RPbase) */ \
  332. {NAME, 2, OPC4, 22, LD_STOR_INS, {{OP_S,20}, {rpindex_disps14,0}}}, \
  333. /* opc reg -disps20(Rbase) */ \
  334. {NAME, 3, OPC1+0x60, 12, LD_STOR_INS, {{OP_S,4}, {rbase_dispe20,16}}}, \
  335. /* opc reg disps20(Rbase) */ \
  336. {NAME, 3, OPC1, 12, LD_STOR_INS, {{OP_S,4}, {rbase_disps20,16}}}, \
  337. /* opc reg disps16(RPbase) */ \
  338. {NAME, 2, OPC2+1, 24, LD_STOR_INS, {{OP_S,20}, {rpbase_disps16,0}}}, \
  339. /* opc16 reg disps20(RPbase) */ \
  340. {NAME, 3, OPC1+1, 12, LD_STOR_INS, {{OP_S,4}, {rpbase_disps20,16}}}, \
  341. /* op reg (rp) -disps20(RPbase) */ \
  342. {NAME, 3, OPC1+0x61, 12, LD_STOR_INS, {{OP_S,4}, {rpbase_dispe20,16}}}, \
  343. /* opc reg rrp (Rindex)disps20(RPbase) */ \
  344. {NAME, 3, OPC1+2, 12, LD_STOR_INS, {{OP_S,4}, {rpindex_disps20,16}}}
  345. /* Store instructions (from imm to memory). */
  346. #define ST_IMM_INST(NAME, OPC1, OPC2, OPC3, OPC4) \
  347. /* opcNN iN abs20 */ \
  348. {NAME, 2, OPC1, 24, LD_STOR_INS, {{uimm4,20},{abs20,0}}}, \
  349. /* opcNN iN abs24 */ \
  350. {NAME, 3, OPC2+3, 12, LD_STOR_INS, {{uimm4,4},{abs24,16}}}, \
  351. /* opcNN iN (Rindex)abs20 */ \
  352. {NAME, 2, OPC3, 25, LD_STOR_INS, {{uimm4,20}, {rindex8_abs20,0}}}, \
  353. /* opcNN iN (prp) disps14(RPbase) */ \
  354. {NAME, 2, OPC4, 22, LD_STOR_INS, {{uimm4,4},{rpindex_disps14,0}}}, \
  355. /* opcNN iN (rp) disps0(RPbase) */ \
  356. {NAME, 1, OPC1+1, 24, LD_STOR_INS, {{uimm4,20}, {rpbase_disps0,16}}}, \
  357. /* opcNN iN disps20(Rbase) */ \
  358. {NAME, 3, OPC2, 12, LD_STOR_INS, {{uimm4,4}, {rbase_disps20,16}}}, \
  359. /* opcNN iN (rp) disps16(RPBase) */ \
  360. {NAME, 2, OPC1+2, 24, LD_STOR_INS, {{uimm4,20}, {rpbase_disps16,0}}}, \
  361. /* opcNN iN (rp) disps20(RPBase) */ \
  362. {NAME, 3, OPC2+1, 12, LD_STOR_INS, {{uimm4,4}, {rpbase_disps20,16}}}, \
  363. /* opcNN iN rrp (Rindex)disps20(RPbase) */ \
  364. {NAME, 3, OPC2+2, 12, LD_STOR_INS, {{uimm4,4}, {rpindex_disps20,16}}}
  365. ST_REG_INST ("storb", 0x00134, 0xFE, 0xC8, 0x319, 0x65, rpbase_disps4, regr),
  366. ST_IMM_INST ("storb", 0x81, 0x00120, 0x42, 0x218),
  367. ST_REG_INST ("stord", 0x00138, 0xEE, 0xC7, 0x31A, 0x66, rpbase_dispe4, regp),
  368. ST_REG_INST ("storw", 0x0013C, 0xDE, 0xC9, 0x31B, 0x67, rpbase_dispe4, regr),
  369. ST_IMM_INST ("storw", 0xC1, 0x00130, 0x62, 0x318),
  370. /* Create instruction with no operands. */
  371. #define NO_OP_INST(NAME, OPC) \
  372. /* opc16 */ \
  373. {NAME, 1, OPC, 16, 0, {{0, 0}}}
  374. NO_OP_INST ("cinv[i]", 0x000A),
  375. NO_OP_INST ("cinv[i,u]", 0x000B),
  376. NO_OP_INST ("cinv[d]", 0x000C),
  377. NO_OP_INST ("cinv[d,u]", 0x000D),
  378. NO_OP_INST ("cinv[d,i]", 0x000E),
  379. NO_OP_INST ("cinv[d,i,u]", 0x000F),
  380. NO_OP_INST ("nop", 0x2C00),
  381. NO_OP_INST ("retx", 0x0003),
  382. NO_OP_INST ("di", 0x0004),
  383. NO_OP_INST ("ei", 0x0005),
  384. NO_OP_INST ("wait", 0x0006),
  385. NO_OP_INST ("eiwait", 0x0007),
  386. {NULL, 0, 0, 0, 0, {{0, 0}}}
  387. };
  388. const unsigned int cr16_num_opcodes = ARRAY_SIZE (cr16_instruction);
  389. /* Macro to build a reg_entry, which have an opcode image :
  390. For example :
  391. REG(u4, 0x84, CR16_U_REGTYPE)
  392. is interpreted as :
  393. {"u4", u4, 0x84, CR16_U_REGTYPE}
  394. The union initializer (second member) always refers to the first
  395. member of the union, so cast NAME to that type to avoid possible
  396. compiler warnings when used for CR16_P_REGTYPE cases. */
  397. #define REG(NAME, N, TYPE) {STRINGX(NAME), {(reg) NAME}, N, TYPE}
  398. #define REGP(NAME, BNAME, N, TYPE) {STRINGX(NAME), {BNAME}, N, TYPE}
  399. const reg_entry cr16_regtab[] =
  400. { /* Build a general purpose register r<N>. */
  401. #define REG_R(N) REG(CONCAT2(r,N), N, CR16_R_REGTYPE)
  402. REG_R(0), REG_R(1), REG_R(2), REG_R(3),
  403. REG_R(4), REG_R(5), REG_R(6), REG_R(7),
  404. REG_R(8), REG_R(9), REG_R(10), REG_R(11),
  405. REG_R(12), REG_R(13), REG_R(14), REG_R(15),
  406. REG(r12_L, 12, CR16_R_REGTYPE),
  407. REG(r13_L, 13, CR16_R_REGTYPE),
  408. REG(ra, 0xe, CR16_R_REGTYPE),
  409. REG(sp, 0xf, CR16_R_REGTYPE),
  410. REG(sp_L, 0xf, CR16_R_REGTYPE),
  411. REG(RA, 0xe, CR16_R_REGTYPE),
  412. };
  413. const reg_entry cr16_regptab[] =
  414. { /* Build a general purpose register r<N>. */
  415. #define REG_RP(M,N) REGP((CONCAT2(r,M),CONCAT2(r,N)), CONCAT2(r,N), N, CR16_RP_REGTYPE)
  416. REG_RP(1,0), REG_RP(2,1), REG_RP(3,2), REG_RP(4,3),
  417. REG_RP(5,4), REG_RP(6,5), REG_RP(7,6), REG_RP(8,7),
  418. REG_RP(9,8), REG_RP(10,9), REG_RP(11,10), REG_RP(12,11),
  419. REG((r12), 0xc, CR16_RP_REGTYPE),
  420. REG((r13), 0xd, CR16_RP_REGTYPE),
  421. /* REG((r14), 0xe, CR16_RP_REGTYPE), */
  422. REG((ra), 0xe, CR16_RP_REGTYPE),
  423. REG((sp), 0xf, CR16_RP_REGTYPE),
  424. };
  425. const unsigned int cr16_num_regs = ARRAY_SIZE (cr16_regtab) ;
  426. const unsigned int cr16_num_regps = ARRAY_SIZE (cr16_regptab) ;
  427. const reg_entry cr16_pregtab[] =
  428. {
  429. /* Build a processor register. */
  430. REG(dbs, 0x0, CR16_P_REGTYPE),
  431. REG(dsr, 0x1, CR16_P_REGTYPE),
  432. REG(dcrl, 0x2, CR16_P_REGTYPE),
  433. REG(dcrh, 0x3, CR16_P_REGTYPE),
  434. REG(car0l, 0x4, CR16_P_REGTYPE),
  435. REG(car0h, 0x5, CR16_P_REGTYPE),
  436. REG(car1l, 0x6, CR16_P_REGTYPE),
  437. REG(car1h, 0x7, CR16_P_REGTYPE),
  438. REG(cfg, 0x8, CR16_P_REGTYPE),
  439. REG(psr, 0x9, CR16_P_REGTYPE),
  440. REG(intbasel, 0xa, CR16_P_REGTYPE),
  441. REG(intbaseh, 0xb, CR16_P_REGTYPE),
  442. REG(ispl, 0xc, CR16_P_REGTYPE),
  443. REG(isph, 0xd, CR16_P_REGTYPE),
  444. REG(uspl, 0xe, CR16_P_REGTYPE),
  445. REG(usph, 0xf, CR16_P_REGTYPE),
  446. };
  447. const reg_entry cr16_pregptab[] =
  448. {
  449. REG(dbs, 0, CR16_P_REGTYPE),
  450. REG(dsr, 1, CR16_P_REGTYPE),
  451. REG(dcr, 2, CR16_P_REGTYPE),
  452. REG(car0, 4, CR16_P_REGTYPE),
  453. REG(car1, 6, CR16_P_REGTYPE),
  454. REG(cfg, 8, CR16_P_REGTYPE),
  455. REG(psr, 9, CR16_P_REGTYPE),
  456. REG(intbase, 10, CR16_P_REGTYPE),
  457. REG(isp, 12, CR16_P_REGTYPE),
  458. REG(usp, 14, CR16_P_REGTYPE),
  459. };
  460. const unsigned int cr16_num_pregs = ARRAY_SIZE (cr16_pregtab);
  461. const unsigned int cr16_num_pregps = ARRAY_SIZE (cr16_pregptab);
  462. const char *cr16_b_cond_tab[]=
  463. {
  464. "eq","ne","cs","cc","hi","ls","gt","le","fs","fc",
  465. "lo","hs","lt","ge","r", "???"
  466. };
  467. const unsigned int cr16_num_cc = ARRAY_SIZE (cr16_b_cond_tab);
  468. /* CR16 operands table. */
  469. const operand_entry cr16_optab[] =
  470. {
  471. /* Index 0 is dummy, so we can count the instruction's operands. */
  472. {0, nullargs, 0}, /* dummy */
  473. {3, arg_ic, OP_SIGNED}, /* imm3 */
  474. {4, arg_ic, OP_SIGNED}, /* imm4 */
  475. {5, arg_ic, OP_SIGNED}, /* imm5 */
  476. {6, arg_ic, OP_SIGNED}, /* imm6 */
  477. {16, arg_ic, OP_SIGNED}, /* imm16 */
  478. {20, arg_ic, OP_SIGNED}, /* imm20 */
  479. {32, arg_ic, OP_SIGNED}, /* imm32 */
  480. {3, arg_ic, OP_UNSIGNED}, /* uimm3 */
  481. {3, arg_ic, OP_UNSIGNED|OP_DEC}, /* uimm3_1 */
  482. {4, arg_ic, OP_UNSIGNED}, /* uimm4 */
  483. {4, arg_ic, OP_UNSIGNED|OP_ESC}, /* uimm4_1 */
  484. {5, arg_ic, OP_UNSIGNED}, /* uimm5 */
  485. {16, arg_ic, OP_UNSIGNED}, /* uimm16 */
  486. {20, arg_ic, OP_UNSIGNED}, /* uimm20 */
  487. {32, arg_ic, OP_UNSIGNED}, /* uimm32 */
  488. {5, arg_c, OP_EVEN|OP_SHIFT_DEC|OP_SIGNED}, /* disps5 */
  489. {16, arg_c, OP_EVEN|OP_UNSIGNED}, /* disps17 */
  490. {24, arg_c, OP_EVEN|OP_UNSIGNED}, /* disps25 */
  491. {8, arg_c, OP_EVEN|OP_UNSIGNED}, /* dispe9 */
  492. {20, arg_c, OP_UNSIGNED|OP_ABS20}, /* abs20 */
  493. {24, arg_c, OP_UNSIGNED|OP_ABS24}, /* abs24 */
  494. {4, arg_rp, 0}, /* rra */
  495. {4, arg_rbase, 0}, /* rbase */
  496. {20, arg_cr, OP_UNSIGNED}, /* rbase_disps20 */
  497. {21, arg_cr, OP_NEG}, /* rbase_dispe20 */
  498. {0, arg_crp, 0}, /* rpbase_disps0 */
  499. {4, arg_crp, OP_EVEN|OP_SHIFT|OP_UNSIGNED|OP_ESC1},/* rpbase_dispe4 */
  500. {4, arg_crp, OP_UNSIGNED|OP_ESC1}, /* rpbase_disps4 */
  501. {16, arg_crp, OP_UNSIGNED}, /* rpbase_disps16 */
  502. {20, arg_crp, OP_UNSIGNED}, /* rpbase_disps20 */
  503. {21, arg_crp, OP_NEG}, /* rpbase_dispe20 */
  504. {20, arg_idxr, OP_UNSIGNED}, /* rindex7_abs20 */
  505. {20, arg_idxr, OP_UNSIGNED}, /* rindex8_abs20 */
  506. {0, arg_idxrp, OP_UNSIGNED}, /* rpindex_disps0 */
  507. {14, arg_idxrp, OP_UNSIGNED}, /* rpindex_disps14 */
  508. {20, arg_idxrp, OP_UNSIGNED}, /* rpindex_disps20 */
  509. {4, arg_r, 0}, /* regr */
  510. {4, arg_rp, 0}, /* reg pair */
  511. {4, arg_pr, 0}, /* proc reg */
  512. {4, arg_prp, 0}, /* 32 bit proc reg */
  513. {4, arg_cc, OP_UNSIGNED} /* cc - code */
  514. };
  515. const unsigned int cr16_num_optab = ARRAY_SIZE (cr16_optab);
  516. /* CR16 traps/interrupts. */
  517. const trap_entry cr16_traps[] =
  518. {
  519. {"svc", 5}, {"dvz", 6}, {"flg", 7}, {"bpt", 8}, {"trc", 9},
  520. {"und", 10}, {"iad", 12}, {"dbg",14}, {"ise",15}
  521. };
  522. const unsigned int cr16_num_traps = ARRAY_SIZE (cr16_traps);
  523. /* CR16 instructions that don't have arguments. */
  524. const char * cr16_no_op_insn[] =
  525. {
  526. "cinv[i]", "cinv[i,u]", "cinv[d]", "cinv[d,u]", "cinv[d,i]", "cinv[d,i,u]",
  527. "di", "ei", "eiwait", "nop", "retx", "wait", NULL
  528. };