crx.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. /* crx.h -- Header file for CRX opcode and register tables.
  2. Copyright (C) 2004-2022 Free Software Foundation, Inc.
  3. Contributed by Tomer Levi, NSC, Israel.
  4. Originally written for GAS 2.12 by Tomer Levi, NSC, Israel.
  5. Updates, BFDizing, GNUifying and ELF support by Tomer Levi.
  6. This file is part of GAS, GDB and the GNU binutils.
  7. GAS, GDB, and GNU binutils is free software; you can redistribute it
  8. and/or modify it under the terms of the GNU General Public License as
  9. published by the Free Software Foundation; either version 3, or (at your
  10. option) any later version.
  11. GAS, GDB, and GNU binutils are distributed in the hope that they will be
  12. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  18. MA 02110-1301, USA. */
  19. #ifndef _CRX_H_
  20. #define _CRX_H_
  21. /* CRX core/debug Registers :
  22. The enums are used as indices to CRX registers table (crx_regtab).
  23. Therefore, order MUST be preserved. */
  24. typedef enum
  25. {
  26. /* 32-bit general purpose registers. */
  27. r0, r1, r2, r3, r4, r5, r6, r7, r8, r9,
  28. r10, r11, r12, r13, r14, r15, ra, sp,
  29. /* 32-bit user registers. */
  30. u0, u1, u2, u3, u4, u5, u6, u7, u8, u9,
  31. u10, u11, u12, u13, u14, u15, ura, usp,
  32. /* hi and lo registers. */
  33. hi, lo,
  34. /* hi and lo user registers. */
  35. uhi, ulo,
  36. /* Processor Status Register. */
  37. psr,
  38. /* Interrupt Base Register. */
  39. intbase,
  40. /* Interrupt Stack Pointer Register. */
  41. isp,
  42. /* Configuration Register. */
  43. cfg,
  44. /* Coprocessor Configuration Register. */
  45. cpcfg,
  46. /* Coprocessor Enable Register. */
  47. cen,
  48. /* Not a register. */
  49. nullregister,
  50. MAX_REG
  51. }
  52. reg;
  53. /* CRX Coprocessor registers and special registers :
  54. The enums are used as indices to CRX coprocessor registers table
  55. (crx_copregtab). Therefore, order MUST be preserved. */
  56. typedef enum
  57. {
  58. /* Coprocessor registers. */
  59. c0 = MAX_REG, c1, c2, c3, c4, c5, c6, c7, c8,
  60. c9, c10, c11, c12, c13, c14, c15,
  61. /* Coprocessor special registers. */
  62. cs0, cs1 ,cs2, cs3, cs4, cs5, cs6, cs7, cs8,
  63. cs9, cs10, cs11, cs12, cs13, cs14, cs15,
  64. /* Not a Coprocessor register. */
  65. nullcopregister,
  66. MAX_COPREG
  67. }
  68. copreg;
  69. /* CRX Register types. */
  70. typedef enum
  71. {
  72. CRX_R_REGTYPE, /* r<N> */
  73. CRX_U_REGTYPE, /* u<N> */
  74. CRX_C_REGTYPE, /* c<N> */
  75. CRX_CS_REGTYPE, /* cs<N> */
  76. CRX_CFG_REGTYPE /* configuration register */
  77. }
  78. reg_type;
  79. /* CRX argument types :
  80. The argument types correspond to instructions operands
  81. Argument types :
  82. r - register
  83. c - constant
  84. i - immediate
  85. idxr - index register
  86. rbase - register base
  87. s - star ('*')
  88. copr - coprocessor register
  89. copsr - coprocessor special register. */
  90. typedef enum
  91. {
  92. arg_r, arg_c, arg_cr, arg_ic, arg_icr, arg_sc,
  93. arg_idxr, arg_rbase, arg_copr, arg_copsr,
  94. /* Not an argument. */
  95. nullargs
  96. }
  97. argtype;
  98. /* CRX operand types :
  99. The operand types correspond to instructions operands. */
  100. typedef enum
  101. {
  102. dummy,
  103. /* 4-bit encoded constant. */
  104. cst4,
  105. /* N-bit immediate. */
  106. i16, i32,
  107. /* N-bit unsigned immediate. */
  108. ui3, ui4, ui5, ui16,
  109. /* N-bit signed displacement. */
  110. disps9, disps17, disps25, disps32,
  111. /* N-bit unsigned displacement. */
  112. dispu5,
  113. /* N-bit escaped displacement. */
  114. dispe9,
  115. /* N-bit absolute address. */
  116. abs16, abs32,
  117. /* Register relative. */
  118. rbase, rbase_dispu4,
  119. rbase_disps12, rbase_disps16, rbase_disps28, rbase_disps32,
  120. /* Register index. */
  121. rindex_disps6, rindex_disps22,
  122. /* 4-bit genaral-purpose register specifier. */
  123. regr,
  124. /* 8-bit register address space. */
  125. regr8,
  126. /* coprocessor register. */
  127. copregr,
  128. /* coprocessor special register. */
  129. copsregr,
  130. /* Not an operand. */
  131. nulloperand,
  132. /* Maximum supported operand. */
  133. MAX_OPRD
  134. }
  135. operand_type;
  136. /* CRX instruction types. */
  137. #define NO_TYPE_INS 0
  138. #define ARITH_INS 1
  139. #define LD_STOR_INS 2
  140. #define BRANCH_INS 3
  141. #define ARITH_BYTE_INS 4
  142. #define CMPBR_INS 5
  143. #define SHIFT_INS 6
  144. #define BRANCH_NEQ_INS 7
  145. #define LD_STOR_INS_INC 8
  146. #define STOR_IMM_INS 9
  147. #define CSTBIT_INS 10
  148. #define COP_BRANCH_INS 11
  149. #define COP_REG_INS 12
  150. #define COPS_REG_INS 13
  151. #define DCR_BRANCH_INS 14
  152. /* Maximum value supported for instruction types. */
  153. #define CRX_INS_MAX (1 << 4)
  154. /* Mask to record an instruction type. */
  155. #define CRX_INS_MASK (CRX_INS_MAX - 1)
  156. /* Return instruction type, given instruction's attributes. */
  157. #define CRX_INS_TYPE(attr) ((attr) & CRX_INS_MASK)
  158. /* Indicates whether this instruction has a register list as parameter. */
  159. #define REG_LIST CRX_INS_MAX
  160. /* The operands in binary and assembly are placed in reverse order.
  161. load - (REVERSE_MATCH)/store - (! REVERSE_MATCH). */
  162. #define REVERSE_MATCH (1 << 5)
  163. /* Kind of displacement map used DISPU[BWD]4. */
  164. #define DISPUB4 (1 << 6)
  165. #define DISPUW4 (1 << 7)
  166. #define DISPUD4 (1 << 8)
  167. #define DISPU4MAP (DISPUB4 | DISPUW4 | DISPUD4)
  168. /* Printing formats, where the instruction prefix isn't consecutive. */
  169. #define FMT_1 (1 << 9) /* 0xF0F00000 */
  170. #define FMT_2 (1 << 10) /* 0xFFF0FF00 */
  171. #define FMT_3 (1 << 11) /* 0xFFF00F00 */
  172. #define FMT_4 (1 << 12) /* 0xFFF0F000 */
  173. #define FMT_5 (1 << 13) /* 0xFFF0FFF0 */
  174. #define FMT_CRX (FMT_1 | FMT_2 | FMT_3 | FMT_4 | FMT_5)
  175. /* Indicates whether this instruction can be relaxed. */
  176. #define RELAXABLE (1 << 14)
  177. /* Indicates that instruction uses user registers (and not
  178. general-purpose registers) as operands. */
  179. #define USER_REG (1 << 15)
  180. /* Indicates that instruction can perfom a cst4 mapping. */
  181. #define CST4MAP (1 << 16)
  182. /* Instruction shouldn't allow 'sp' usage. */
  183. #define NO_SP (1 << 17)
  184. /* Instruction shouldn't allow to push a register which is used as a rptr. */
  185. #define NO_RPTR (1 << 18)
  186. /* Maximum operands per instruction. */
  187. #define MAX_OPERANDS 5
  188. /* Maximum register name length. */
  189. #define MAX_REGNAME_LEN 10
  190. /* Maximum instruction length. */
  191. #define MAX_INST_LEN 256
  192. /* Values defined for the flags field of a struct operand_entry. */
  193. /* Operand must be an unsigned number. */
  194. #define OP_UNSIGNED (1 << 0)
  195. /* Operand must be a signed number. */
  196. #define OP_SIGNED (1 << 1)
  197. /* A special arithmetic 4-bit constant operand. */
  198. #define OP_CST4 (1 << 2)
  199. /* A special load/stor 4-bit unsigned displacement operand. */
  200. #define OP_DISPU4 (1 << 3)
  201. /* Operand must be an even number. */
  202. #define OP_EVEN (1 << 4)
  203. /* Operand is shifted right. */
  204. #define OP_SHIFT (1 << 5)
  205. /* Operand is shifted right and decremented. */
  206. #define OP_SHIFT_DEC (1 << 6)
  207. /* Operand has reserved escape sequences. */
  208. #define OP_ESC (1 << 7)
  209. /* Operand is used only for the upper 64 KB (FFFF0000 to FFFFFFFF). */
  210. #define OP_UPPER_64KB (1 << 8)
  211. /* Single operand description. */
  212. typedef struct
  213. {
  214. /* Operand type. */
  215. operand_type op_type;
  216. /* Operand location within the opcode. */
  217. unsigned int shift;
  218. }
  219. operand_desc;
  220. /* Instruction data structure used in instruction table. */
  221. typedef struct
  222. {
  223. /* Name. */
  224. const char *mnemonic;
  225. /* Size (in words). */
  226. unsigned int size;
  227. /* Constant prefix (matched by the disassembler). */
  228. unsigned int match;
  229. /* Match size (in bits). */
  230. int match_bits;
  231. /* Attributes. */
  232. unsigned int flags;
  233. /* Operands (always last, so unreferenced operands are initialized). */
  234. operand_desc operands[MAX_OPERANDS];
  235. }
  236. inst;
  237. /* Data structure for a single instruction's arguments (Operands). */
  238. typedef struct
  239. {
  240. /* Register or base register. */
  241. reg r;
  242. /* Index register. */
  243. reg i_r;
  244. /* Coprocessor register. */
  245. copreg cr;
  246. /* Constant/immediate/absolute value. */
  247. long constant;
  248. /* Scaled index mode. */
  249. unsigned int scale;
  250. /* Argument type. */
  251. argtype type;
  252. /* Size of the argument (in bits) required to represent. */
  253. int size;
  254. /* The type of the expression. */
  255. unsigned char X_op;
  256. }
  257. argument;
  258. /* Internal structure to hold the various entities
  259. corresponding to the current assembling instruction. */
  260. typedef struct
  261. {
  262. /* Number of arguments. */
  263. int nargs;
  264. /* The argument data structure for storing args (operands). */
  265. argument arg[MAX_OPERANDS];
  266. /* The following fields are required only by CRX-assembler. */
  267. #ifdef TC_CRX
  268. /* Expression used for setting the fixups (if any). */
  269. expressionS exp;
  270. bfd_reloc_code_real_type rtype;
  271. #endif /* TC_CRX */
  272. /* Instruction size (in bytes). */
  273. int size;
  274. }
  275. ins;
  276. /* Structure to hold information about predefined operands. */
  277. typedef struct
  278. {
  279. /* Size (in bits). */
  280. unsigned int bit_size;
  281. /* Argument type. */
  282. argtype arg_type;
  283. /* One bit syntax flags. */
  284. int flags;
  285. }
  286. operand_entry;
  287. /* Structure to hold trap handler information. */
  288. typedef struct
  289. {
  290. /* Trap name. */
  291. char *name;
  292. /* Index in dispatch table. */
  293. unsigned int entry;
  294. }
  295. trap_entry;
  296. /* Structure to hold information about predefined registers. */
  297. typedef struct
  298. {
  299. /* Name (string representation). */
  300. char *name;
  301. /* Value (enum representation). */
  302. union
  303. {
  304. /* Register. */
  305. reg reg_val;
  306. /* Coprocessor register. */
  307. copreg copreg_val;
  308. } value;
  309. /* Register image. */
  310. int image;
  311. /* Register type. */
  312. reg_type type;
  313. }
  314. reg_entry;
  315. /* Structure to hold a cst4 operand mapping. */
  316. /* CRX opcode table. */
  317. extern const inst crx_instruction[];
  318. extern const int crx_num_opcodes;
  319. #define NUMOPCODES crx_num_opcodes
  320. /* CRX operands table. */
  321. extern const operand_entry crx_optab[];
  322. /* CRX registers table. */
  323. extern const reg_entry crx_regtab[];
  324. extern const int crx_num_regs;
  325. #define NUMREGS crx_num_regs
  326. /* CRX coprocessor registers table. */
  327. extern const reg_entry crx_copregtab[];
  328. extern const int crx_num_copregs;
  329. #define NUMCOPREGS crx_num_copregs
  330. /* CRX trap/interrupt table. */
  331. extern const trap_entry crx_traps[];
  332. extern const int crx_num_traps;
  333. #define NUMTRAPS crx_num_traps
  334. /* cst4 operand mapping. */
  335. extern const int crx_cst4_map[];
  336. extern const int crx_cst4_maps;
  337. /* Table of instructions with no operands. */
  338. extern const char* crx_no_op_insn[];
  339. /* A macro for representing the instruction "constant" opcode, that is,
  340. the FIXED part of the instruction. The "constant" opcode is represented
  341. as a 32-bit unsigned long, where OPC is expanded (by a left SHIFT)
  342. over that range. */
  343. #define BIN(OPC,SHIFT) (OPC << SHIFT)
  344. /* Is the current instruction type is TYPE ? */
  345. #define IS_INSN_TYPE(TYPE) \
  346. (CRX_INS_TYPE(instruction->flags) == TYPE)
  347. /* Is the current instruction mnemonic is MNEMONIC ? */
  348. #define IS_INSN_MNEMONIC(MNEMONIC) \
  349. (strcmp(instruction->mnemonic,MNEMONIC) == 0)
  350. /* Does the current instruction has register list ? */
  351. #define INST_HAS_REG_LIST \
  352. (instruction->flags & REG_LIST)
  353. /* Long long type handling. */
  354. /* Replace all appearances of 'long long int' with LONGLONG. */
  355. typedef long long int LONGLONG;
  356. typedef unsigned long long ULONGLONG;
  357. #endif /* _CRX_H_ */