nios2.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /* Nios II opcode list for GAS, the GNU assembler.
  2. Copyright (C) 2012-2015 Free Software Foundation, Inc.
  3. Contributed by Nigel Gray (ngray@altera.com).
  4. Contributed by Mentor Graphics, Inc.
  5. This file is part of GAS, the GNU Assembler, and GDB, the GNU disassembler.
  6. GAS/GDB is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 3, or (at your option)
  9. any later version.
  10. GAS/GDB is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with GAS or GDB; see the file COPYING3. If not, write to
  16. the Free Software Foundation, 51 Franklin Street - Fifth Floor,
  17. Boston, MA 02110-1301, USA. */
  18. #ifndef _NIOS2_H_
  19. #define _NIOS2_H_
  20. #include "bfd.h"
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /****************************************************************************
  25. * This file contains structures, bit masks and shift counts used
  26. * by the GNU toolchain to define the Nios II instruction set and
  27. * access various opcode fields.
  28. ****************************************************************************/
  29. /* Instruction encoding formats. */
  30. enum iw_format_type {
  31. /* R1 formats. */
  32. iw_i_type,
  33. iw_r_type,
  34. iw_j_type,
  35. iw_custom_type,
  36. /* 32-bit R2 formats. */
  37. iw_L26_type,
  38. iw_F2I16_type,
  39. iw_F2X4I12_type,
  40. iw_F1X4I12_type,
  41. iw_F1X4L17_type,
  42. iw_F3X6L5_type,
  43. iw_F2X6L10_type,
  44. iw_F3X6_type,
  45. iw_F3X8_type,
  46. /* 16-bit R2 formats. */
  47. iw_I10_type,
  48. iw_T1I7_type,
  49. iw_T2I4_type,
  50. iw_T1X1I6_type,
  51. iw_X1I7_type,
  52. iw_L5I4X1_type,
  53. iw_T2X1L3_type,
  54. iw_T2X1I3_type,
  55. iw_T3X1_type,
  56. iw_T2X3_type,
  57. iw_F1X1_type,
  58. iw_X2L5_type,
  59. iw_F1I5_type,
  60. iw_F2_type
  61. };
  62. /* Identify different overflow situations for error messages. */
  63. enum overflow_type
  64. {
  65. call_target_overflow = 0,
  66. branch_target_overflow,
  67. address_offset_overflow,
  68. signed_immed16_overflow,
  69. unsigned_immed16_overflow,
  70. unsigned_immed5_overflow,
  71. signed_immed12_overflow,
  72. custom_opcode_overflow,
  73. enumeration_overflow,
  74. no_overflow
  75. };
  76. /* This structure holds information for a particular instruction.
  77. The args field is a string describing the operands. The following
  78. letters can appear in the args:
  79. c - a 5-bit control register index
  80. d - a 5-bit destination register index
  81. s - a 5-bit left source register index
  82. t - a 5-bit right source register index
  83. D - a 3-bit encoded destination register
  84. S - a 3-bit encoded left source register
  85. T - a 3-bit encoded right source register
  86. i - a 16-bit signed immediate
  87. j - a 5-bit unsigned immediate
  88. k - a (second) 5-bit unsigned immediate
  89. l - a 8-bit custom instruction constant
  90. m - a 26-bit unsigned immediate
  91. o - a 16-bit signed pc-relative offset
  92. u - a 16-bit unsigned immediate
  93. I - a 12-bit signed immediate
  94. M - a 6-bit unsigned immediate
  95. N - a 6-bit unsigned immediate with 2-bit shift
  96. O - a 10-bit signed pc-relative offset with 1-bit shift
  97. P - a 7-bit signed pc-relative offset with 1-bit shift
  98. U - a 7-bit unsigned immediate with 2-bit shift
  99. V - a 5-bit unsigned immediate with 2-bit shift
  100. W - a 4-bit unsigned immediate with 2-bit shift
  101. X - a 4-bit unsigned immediate with 1-bit shift
  102. Y - a 4-bit unsigned immediate
  103. e - an immediate coded as an enumeration for addi.n/subi.n
  104. f - an immediate coded as an enumeration for slli.n/srli.n
  105. g - an immediate coded as an enumeration for andi.n
  106. h - an immediate coded as an enumeration for movi.n
  107. R - a reglist for ldwm/stwm or push.n/pop.n
  108. B - a base register specifier and option list for ldwm/stwm
  109. Literal ',', '(', and ')' characters may also appear in the args as
  110. delimiters.
  111. Note that the args describe the semantics and assembly-language syntax
  112. of the operands, not their encoding into the instruction word.
  113. The pinfo field is INSN_MACRO for a macro. Otherwise, it is a collection
  114. of bits describing the instruction, notably any relevant hazard
  115. information.
  116. When assembling, the match field contains the opcode template, which
  117. is modified by the arguments to produce the actual opcode
  118. that is emitted. If pinfo is INSN_MACRO, then this is 0.
  119. If pinfo is INSN_MACRO, the mask field stores the macro identifier.
  120. Otherwise this is a bit mask for the relevant portions of the opcode
  121. when disassembling. If the actual opcode anded with the match field
  122. equals the opcode field, then we have found the correct instruction. */
  123. struct nios2_opcode
  124. {
  125. const char *name; /* The name of the instruction. */
  126. const char *args; /* A string describing the arguments for this
  127. instruction. */
  128. const char *args_test; /* Like args, but with an extra argument for
  129. the expected opcode. */
  130. unsigned long num_args; /* The number of arguments the instruction
  131. takes. */
  132. unsigned size; /* Size in bytes of the instruction. */
  133. enum iw_format_type format; /* Instruction format. */
  134. unsigned long match; /* The basic opcode for the instruction. */
  135. unsigned long mask; /* Mask for the opcode field of the
  136. instruction. */
  137. unsigned long pinfo; /* Is this a real instruction or instruction
  138. macro? */
  139. enum overflow_type overflow_msg; /* Used to generate informative
  140. message when fixup overflows. */
  141. };
  142. /* This value is used in the nios2_opcode.pinfo field to indicate that the
  143. instruction is a macro or pseudo-op. This requires special treatment by
  144. the assembler, and is used by the disassembler to determine whether to
  145. check for a nop. */
  146. #define NIOS2_INSN_MACRO 0x80000000
  147. #define NIOS2_INSN_MACRO_MOV 0x80000001
  148. #define NIOS2_INSN_MACRO_MOVI 0x80000002
  149. #define NIOS2_INSN_MACRO_MOVIA 0x80000004
  150. #define NIOS2_INSN_RELAXABLE 0x40000000
  151. #define NIOS2_INSN_UBRANCH 0x00000010
  152. #define NIOS2_INSN_CBRANCH 0x00000020
  153. #define NIOS2_INSN_CALL 0x00000040
  154. #define NIOS2_INSN_OPTARG 0x00000080
  155. /* Register attributes. */
  156. #define REG_NORMAL (1<<0) /* Normal registers. */
  157. #define REG_CONTROL (1<<1) /* Control registers. */
  158. #define REG_COPROCESSOR (1<<2) /* For custom instructions. */
  159. #define REG_3BIT (1<<3) /* For R2 CDX instructions. */
  160. #define REG_LDWM (1<<4) /* For R2 ldwm/stwm. */
  161. #define REG_POP (1<<5) /* For R2 pop.n/push.n. */
  162. struct nios2_reg
  163. {
  164. const char *name;
  165. const int index;
  166. unsigned long regtype;
  167. };
  168. /* Pull in the instruction field accessors, opcodes, and masks. */
  169. #include "nios2r1.h"
  170. #include "nios2r2.h"
  171. /* These are the data structures used to hold the instruction information. */
  172. extern const struct nios2_opcode nios2_r1_opcodes[];
  173. extern const int nios2_num_r1_opcodes;
  174. extern const struct nios2_opcode nios2_r2_opcodes[];
  175. extern const int nios2_num_r2_opcodes;
  176. extern struct nios2_opcode *nios2_opcodes;
  177. extern int nios2_num_opcodes;
  178. /* These are the data structures used to hold the register information. */
  179. extern const struct nios2_reg nios2_builtin_regs[];
  180. extern struct nios2_reg *nios2_regs;
  181. extern const int nios2_num_builtin_regs;
  182. extern int nios2_num_regs;
  183. /* Return the opcode descriptor for a single instruction. */
  184. extern const struct nios2_opcode *
  185. nios2_find_opcode_hash (unsigned long, unsigned long);
  186. /* Lookup tables for R2 immediate decodings. */
  187. extern unsigned int nios2_r2_asi_n_mappings[];
  188. extern const int nios2_num_r2_asi_n_mappings;
  189. extern unsigned int nios2_r2_shi_n_mappings[];
  190. extern const int nios2_num_r2_shi_n_mappings;
  191. extern unsigned int nios2_r2_andi_n_mappings[];
  192. extern const int nios2_num_r2_andi_n_mappings;
  193. /* Lookup table for 3-bit register decodings. */
  194. extern int nios2_r2_reg3_mappings[];
  195. extern const int nios2_num_r2_reg3_mappings;
  196. /* Lookup table for REG_RANGE value list decodings. */
  197. extern unsigned long nios2_r2_reg_range_mappings[];
  198. extern const int nios2_num_r2_reg_range_mappings;
  199. #ifdef __cplusplus
  200. }
  201. #endif
  202. #endif /* _NIOS2_H */