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