bfin-defs.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. /* bfin-defs.h ADI Blackfin gas header file
  2. Copyright (C) 2005-2015 Free Software Foundation, Inc.
  3. This file is part of GAS, the GNU Assembler.
  4. GAS is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3, or (at your option)
  7. any later version.
  8. GAS is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GAS; see the file COPYING. If not, write to the Free
  14. Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
  15. 02110-1301, USA. */
  16. #ifndef BFIN_PARSE_H
  17. #define BFIN_PARSE_H
  18. #include "opcode/bfin.h"
  19. #define PCREL 1
  20. #define CODE_FRAG_SIZE 4096 /* 1 page. */
  21. /* Definition for all status bits. */
  22. typedef enum
  23. {
  24. c_0,
  25. c_1,
  26. c_4,
  27. c_2,
  28. c_uimm2,
  29. c_uimm3,
  30. c_imm3,
  31. c_pcrel4,
  32. c_imm4,
  33. c_uimm4s4,
  34. c_uimm4,
  35. c_uimm4s2,
  36. c_negimm5s4,
  37. c_imm5,
  38. c_uimm5,
  39. c_imm6,
  40. c_imm7,
  41. c_imm8,
  42. c_uimm8,
  43. c_pcrel8,
  44. c_uimm8s4,
  45. c_pcrel8s4,
  46. c_lppcrel10,
  47. c_pcrel10,
  48. c_pcrel12,
  49. c_imm16s4,
  50. c_luimm16,
  51. c_imm16,
  52. c_huimm16,
  53. c_rimm16,
  54. c_imm16s2,
  55. c_uimm16s4,
  56. c_uimm16,
  57. c_pcrel24
  58. } const_forms_t;
  59. /* High-Nibble: group code, low nibble: register code. */
  60. #define T_REG_R 0x00
  61. #define T_REG_P 0x10
  62. #define T_REG_I 0x20
  63. #define T_REG_B 0x30
  64. #define T_REG_L 0x34
  65. #define T_REG_M 0x24
  66. #define T_REG_A 0x40
  67. /* All registers above this value don't
  68. belong to a usuable register group. */
  69. #define T_NOGROUP 0xa0
  70. /* Flags. */
  71. #define F_REG_NONE 0
  72. #define F_REG_HIGH 1
  73. #define F_REG_LOW 2
  74. enum machine_registers
  75. {
  76. REG_R0 = T_REG_R, REG_R1, REG_R2, REG_R3, REG_R4, REG_R5, REG_R6, REG_R7,
  77. REG_P0 = T_REG_P, REG_P1, REG_P2, REG_P3, REG_P4, REG_P5, REG_SP, REG_FP,
  78. REG_I0 = T_REG_I, REG_I1, REG_I2, REG_I3,
  79. REG_M0 = T_REG_M, REG_M1, REG_M2, REG_M3,
  80. REG_B0 = T_REG_B, REG_B1, REG_B2, REG_B3,
  81. REG_L0 = T_REG_L, REG_L1, REG_L2, REG_L3,
  82. REG_A0x = T_REG_A, REG_A0w, REG_A1x, REG_A1w,
  83. REG_ASTAT = 0x46,
  84. REG_RETS = 0x47,
  85. REG_LC0 = 0x60, REG_LT0, REG_LB0, REG_LC1, REG_LT1, REG_LB1,
  86. REG_CYCLES, REG_CYCLES2,
  87. REG_USP = 0x70, REG_SEQSTAT, REG_SYSCFG,
  88. REG_RETI, REG_RETX, REG_RETN, REG_RETE, REG_EMUDAT,
  89. /* These don't have groups. */
  90. REG_sftreset = T_NOGROUP, REG_omode, REG_excause, REG_emucause,
  91. REG_idle_req, REG_hwerrcause,
  92. REG_A0 = 0xc0, REG_A1, REG_CC,
  93. /* Pseudo registers, used only for distinction from symbols. */
  94. REG_RL0, REG_RL1, REG_RL2, REG_RL3,
  95. REG_RL4, REG_RL5, REG_RL6, REG_RL7,
  96. REG_RH0, REG_RH1, REG_RH2, REG_RH3,
  97. REG_RH4, REG_RH5, REG_RH6, REG_RH7,
  98. REG_LASTREG
  99. };
  100. /* Status register flags. */
  101. enum statusflags
  102. {
  103. S_AZ = 0,
  104. S_AN,
  105. S_AC0_COPY,
  106. S_V_COPY,
  107. S_AQ = 6,
  108. S_RND_MOD = 8,
  109. S_AC0 = 12,
  110. S_AC1,
  111. S_AV0 = 16,
  112. S_AV0S,
  113. S_AV1,
  114. S_AV1S,
  115. S_V = 24,
  116. S_VS = 25
  117. };
  118. enum reg_class
  119. {
  120. rc_dregs_lo,
  121. rc_dregs_hi,
  122. rc_dregs,
  123. rc_dregs_pair,
  124. rc_pregs,
  125. rc_spfp,
  126. rc_dregs_hilo,
  127. rc_accum_ext,
  128. rc_accum_word,
  129. rc_accum,
  130. rc_iregs,
  131. rc_mregs,
  132. rc_bregs,
  133. rc_lregs,
  134. rc_dpregs,
  135. rc_gregs,
  136. rc_regs,
  137. rc_statbits,
  138. rc_ignore_bits,
  139. rc_ccstat,
  140. rc_counters,
  141. rc_dregs2_sysregs1,
  142. rc_open,
  143. rc_sysregs2,
  144. rc_sysregs3,
  145. rc_allregs,
  146. LIM_REG_CLASSES
  147. };
  148. /* Register type checking macros. */
  149. #define CODE_MASK 0x07
  150. #define CLASS_MASK 0xf0
  151. #define REG_SAME(a, b) ((a).regno == (b).regno)
  152. #define REG_EQUAL(a, b) (((a).regno & CODE_MASK) == ((b).regno & CODE_MASK))
  153. #define REG_CLASS(a) ((a).regno & 0xf0)
  154. #define IS_A1(a) ((a).regno == REG_A1)
  155. #define IS_H(a) ((a).flags & F_REG_HIGH ? 1: 0)
  156. #define IS_EVEN(r) ((r).regno % 2 == 0)
  157. #define IS_HCOMPL(a, b) (REG_EQUAL(a, b) && \
  158. ((a).flags & F_REG_HIGH) != ((b).flags & F_REG_HIGH))
  159. /* register type checking. */
  160. #define _TYPECHECK(r, x) (((r).regno & CLASS_MASK) == T_REG_##x)
  161. #define IS_DREG(r) _TYPECHECK(r, R)
  162. #define IS_DREG_H(r) (_TYPECHECK(r, R) && IS_H(r))
  163. #define IS_DREG_L(r) (_TYPECHECK(r, R) && !IS_H(r))
  164. #define IS_PREG(r) _TYPECHECK(r, P)
  165. #define IS_IREG(r) (((r).regno & 0xf4) == T_REG_I)
  166. #define IS_MREG(r) (((r).regno & 0xf4) == T_REG_M)
  167. #define IS_BREG(r) (((r).regno & 0xf4) == T_REG_B)
  168. #define IS_LREG(r) (((r).regno & 0xf4) == T_REG_L)
  169. #define IS_CREG(r) ((r).regno == REG_LC0 || (r).regno == REG_LC1)
  170. #define IS_EMUDAT(r) ((r).regno == REG_EMUDAT)
  171. #define IS_ALLREG(r) ((r).regno < T_NOGROUP)
  172. #define IS_GENREG(r) \
  173. (IS_DREG (r) || IS_PREG (r) \
  174. || (r).regno == REG_A0x || (r).regno == REG_A0w \
  175. || (r).regno == REG_A1x || (r).regno == REG_A1w)
  176. #define IS_DAGREG(r) \
  177. (IS_IREG (r) || IS_MREG (r) || IS_BREG (r) || IS_LREG (r))
  178. #define IS_SYSREG(r) \
  179. ((r).regno == REG_ASTAT || (r).regno == REG_SEQSTAT \
  180. || (r).regno == REG_SYSCFG || (r).regno == REG_RETI \
  181. || (r).regno == REG_RETX || (r).regno == REG_RETN \
  182. || (r).regno == REG_RETE || (r).regno == REG_RETS \
  183. || (r).regno == REG_LC0 || (r).regno == REG_LC1 \
  184. || (r).regno == REG_LT0 || (r).regno == REG_LT1 \
  185. || (r).regno == REG_LB0 || (r).regno == REG_LB1 \
  186. || (r).regno == REG_CYCLES || (r).regno == REG_CYCLES2 \
  187. || (r).regno == REG_EMUDAT)
  188. /* Expression value macros. */
  189. typedef enum
  190. {
  191. ones_compl,
  192. twos_compl,
  193. mult,
  194. divide,
  195. mod,
  196. add,
  197. sub,
  198. lsh,
  199. rsh,
  200. logand,
  201. logior,
  202. logxor
  203. } expr_opcodes_t;
  204. struct expressionS;
  205. #define SYMBOL_T symbolS*
  206. struct expression_cell
  207. {
  208. int value;
  209. SYMBOL_T symbol;
  210. };
  211. /* User Type Definitions. */
  212. struct bfin_insn
  213. {
  214. unsigned long value;
  215. struct bfin_insn *next;
  216. struct expression_cell *exp;
  217. int pcrel;
  218. int reloc;
  219. };
  220. #define INSTR_T struct bfin_insn*
  221. #define EXPR_T struct expression_cell*
  222. typedef struct expr_node_struct Expr_Node;
  223. extern INSTR_T gencode (unsigned long x);
  224. extern INSTR_T conscode (INSTR_T head, INSTR_T tail);
  225. extern INSTR_T conctcode (INSTR_T head, INSTR_T tail);
  226. extern INSTR_T note_reloc
  227. (INSTR_T code, Expr_Node *, int reloc,int pcrel);
  228. extern INSTR_T note_reloc1
  229. (INSTR_T code, const char * sym, int reloc, int pcrel);
  230. extern INSTR_T note_reloc2
  231. (INSTR_T code, const char *symbol, int reloc, int value, int pcrel);
  232. /* Types of expressions. */
  233. typedef enum
  234. {
  235. Expr_Node_Binop, /* Binary operator. */
  236. Expr_Node_Unop, /* Unary operator. */
  237. Expr_Node_Reloc, /* Symbol to be relocated. */
  238. Expr_Node_GOT_Reloc, /* Symbol to be relocated using the GOT. */
  239. Expr_Node_Constant /* Constant. */
  240. } Expr_Node_Type;
  241. /* Types of operators. */
  242. typedef enum
  243. {
  244. Expr_Op_Type_Add,
  245. Expr_Op_Type_Sub,
  246. Expr_Op_Type_Mult,
  247. Expr_Op_Type_Div,
  248. Expr_Op_Type_Mod,
  249. Expr_Op_Type_Lshift,
  250. Expr_Op_Type_Rshift,
  251. Expr_Op_Type_BAND, /* Bitwise AND. */
  252. Expr_Op_Type_BOR, /* Bitwise OR. */
  253. Expr_Op_Type_BXOR, /* Bitwise exclusive OR. */
  254. Expr_Op_Type_LAND, /* Logical AND. */
  255. Expr_Op_Type_LOR, /* Logical OR. */
  256. Expr_Op_Type_NEG,
  257. Expr_Op_Type_COMP /* Complement. */
  258. } Expr_Op_Type;
  259. /* The value that can be stored ... depends on type. */
  260. typedef union
  261. {
  262. const char *s_value; /* if relocation symbol, the text. */
  263. long long i_value; /* if constant, the value. */
  264. Expr_Op_Type op_value; /* if operator, the value. */
  265. } Expr_Node_Value;
  266. /* The expression node. */
  267. struct expr_node_struct
  268. {
  269. Expr_Node_Type type;
  270. Expr_Node_Value value;
  271. Expr_Node *Left_Child;
  272. Expr_Node *Right_Child;
  273. };
  274. /* Operations on the expression node. */
  275. Expr_Node *Expr_Node_Create (Expr_Node_Type type,
  276. Expr_Node_Value value,
  277. Expr_Node *Left_Child,
  278. Expr_Node *Right_Child);
  279. /* Generate the reloc structure as a series of instructions. */
  280. INSTR_T Expr_Node_Gen_Reloc (Expr_Node *head, int parent_reloc);
  281. #define MKREF(x) mkexpr (0,x)
  282. #define ALLOCATE(x) malloc (x)
  283. #define NULL_CODE ((INSTR_T) 0)
  284. #ifndef EXPR_VALUE
  285. #define EXPR_VALUE(x) (((x)->type == Expr_Node_Constant) ? ((x)->value.i_value) : 0)
  286. #endif
  287. #ifndef EXPR_SYMBOL
  288. #define EXPR_SYMBOL(x) ((x)->symbol)
  289. #endif
  290. typedef long reg_t;
  291. typedef struct _register
  292. {
  293. reg_t regno; /* Register ID as defined in machine_registers. */
  294. int flags;
  295. } Register;
  296. typedef struct _macfunc
  297. {
  298. char n;
  299. char op;
  300. char w;
  301. char P;
  302. Register dst;
  303. Register s0;
  304. Register s1;
  305. } Macfunc;
  306. typedef struct _opt_mode
  307. {
  308. int MM;
  309. int mod;
  310. } Opt_mode;
  311. typedef enum
  312. {
  313. SEMANTIC_ERROR,
  314. NO_INSN_GENERATED,
  315. INSN_GENERATED
  316. } parse_state;
  317. #ifdef __cplusplus
  318. extern "C" {
  319. #endif
  320. extern int debug_codeselection;
  321. void error (char *format, ...);
  322. void warn (char *format, ...);
  323. int semantic_error (char *syntax);
  324. void semantic_error_2 (char *syntax);
  325. EXPR_T mkexpr (int, SYMBOL_T);
  326. /* Defined in bfin-lex.l. */
  327. void set_start_state (void);
  328. extern int insn_regmask (int, int);
  329. #ifdef __cplusplus
  330. }
  331. #endif
  332. #endif /* BFIN_PARSE_H */