1a2e2270fSchristos /* Nios II opcode list for GAS, the GNU assembler. 2*aab831ceSchristos Copyright (C) 2012-2024 Free Software Foundation, Inc. 3a2e2270fSchristos Contributed by Nigel Gray (ngray@altera.com). 4a2e2270fSchristos Contributed by Mentor Graphics, Inc. 5a2e2270fSchristos 6796c32c9Schristos This file is part of the GNU opcodes library. 7a2e2270fSchristos 8a2e2270fSchristos GAS/GDB is free software; you can redistribute it and/or modify 9a2e2270fSchristos it under the terms of the GNU General Public License as published by 10a2e2270fSchristos the Free Software Foundation; either version 3, or (at your option) 11a2e2270fSchristos any later version. 12a2e2270fSchristos 13a2e2270fSchristos GAS/GDB is distributed in the hope that it will be useful, 14a2e2270fSchristos but WITHOUT ANY WARRANTY; without even the implied warranty of 15a2e2270fSchristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16a2e2270fSchristos GNU General Public License for more details. 17a2e2270fSchristos 18a2e2270fSchristos You should have received a copy of the GNU General Public License 19a2e2270fSchristos along with GAS or GDB; see the file COPYING3. If not, write to 20a2e2270fSchristos the Free Software Foundation, 51 Franklin Street - Fifth Floor, 21a2e2270fSchristos Boston, MA 02110-1301, USA. */ 22a2e2270fSchristos 23a2e2270fSchristos #ifndef _NIOS2_H_ 24a2e2270fSchristos #define _NIOS2_H_ 25a2e2270fSchristos 26a2e2270fSchristos #include "bfd.h" 27a2e2270fSchristos 28212397c6Schristos #ifdef __cplusplus 29212397c6Schristos extern "C" { 30212397c6Schristos #endif 31212397c6Schristos 32a2e2270fSchristos /**************************************************************************** 33a2e2270fSchristos * This file contains structures, bit masks and shift counts used 34a2e2270fSchristos * by the GNU toolchain to define the Nios II instruction set and 35a2e2270fSchristos * access various opcode fields. 36a2e2270fSchristos ****************************************************************************/ 37a2e2270fSchristos 38968cf8f2Schristos /* Instruction encoding formats. */ 39968cf8f2Schristos enum iw_format_type { 40212397c6Schristos /* R1 formats. */ 41968cf8f2Schristos iw_i_type, 42968cf8f2Schristos iw_r_type, 43968cf8f2Schristos iw_j_type, 44212397c6Schristos iw_custom_type, 45212397c6Schristos 46212397c6Schristos /* 32-bit R2 formats. */ 47212397c6Schristos iw_L26_type, 48212397c6Schristos iw_F2I16_type, 49212397c6Schristos iw_F2X4I12_type, 50212397c6Schristos iw_F1X4I12_type, 51212397c6Schristos iw_F1X4L17_type, 52212397c6Schristos iw_F3X6L5_type, 53212397c6Schristos iw_F2X6L10_type, 54212397c6Schristos iw_F3X6_type, 55212397c6Schristos iw_F3X8_type, 56212397c6Schristos 57212397c6Schristos /* 16-bit R2 formats. */ 58212397c6Schristos iw_I10_type, 59212397c6Schristos iw_T1I7_type, 60212397c6Schristos iw_T2I4_type, 61212397c6Schristos iw_T1X1I6_type, 62212397c6Schristos iw_X1I7_type, 63212397c6Schristos iw_L5I4X1_type, 64212397c6Schristos iw_T2X1L3_type, 65212397c6Schristos iw_T2X1I3_type, 66212397c6Schristos iw_T3X1_type, 67212397c6Schristos iw_T2X3_type, 68212397c6Schristos iw_F1X1_type, 69212397c6Schristos iw_X2L5_type, 70212397c6Schristos iw_F1I5_type, 71212397c6Schristos iw_F2_type 72968cf8f2Schristos }; 73968cf8f2Schristos 74a2e2270fSchristos /* Identify different overflow situations for error messages. */ 75a2e2270fSchristos enum overflow_type 76a2e2270fSchristos { 77a2e2270fSchristos call_target_overflow = 0, 78a2e2270fSchristos branch_target_overflow, 79a2e2270fSchristos address_offset_overflow, 80a2e2270fSchristos signed_immed16_overflow, 81a2e2270fSchristos unsigned_immed16_overflow, 82a2e2270fSchristos unsigned_immed5_overflow, 83212397c6Schristos signed_immed12_overflow, 84a2e2270fSchristos custom_opcode_overflow, 85212397c6Schristos enumeration_overflow, 86a2e2270fSchristos no_overflow 87a2e2270fSchristos }; 88a2e2270fSchristos 89a2e2270fSchristos /* This structure holds information for a particular instruction. 90a2e2270fSchristos 91a2e2270fSchristos The args field is a string describing the operands. The following 92a2e2270fSchristos letters can appear in the args: 93a2e2270fSchristos c - a 5-bit control register index 94a2e2270fSchristos d - a 5-bit destination register index 95a2e2270fSchristos s - a 5-bit left source register index 96a2e2270fSchristos t - a 5-bit right source register index 97212397c6Schristos D - a 3-bit encoded destination register 98212397c6Schristos S - a 3-bit encoded left source register 99212397c6Schristos T - a 3-bit encoded right source register 100a2e2270fSchristos i - a 16-bit signed immediate 101a2e2270fSchristos j - a 5-bit unsigned immediate 102212397c6Schristos k - a (second) 5-bit unsigned immediate 103a2e2270fSchristos l - a 8-bit custom instruction constant 104a2e2270fSchristos m - a 26-bit unsigned immediate 105212397c6Schristos o - a 16-bit signed pc-relative offset 106212397c6Schristos u - a 16-bit unsigned immediate 107212397c6Schristos I - a 12-bit signed immediate 108212397c6Schristos M - a 6-bit unsigned immediate 109212397c6Schristos N - a 6-bit unsigned immediate with 2-bit shift 110212397c6Schristos O - a 10-bit signed pc-relative offset with 1-bit shift 111212397c6Schristos P - a 7-bit signed pc-relative offset with 1-bit shift 112212397c6Schristos U - a 7-bit unsigned immediate with 2-bit shift 113212397c6Schristos V - a 5-bit unsigned immediate with 2-bit shift 114212397c6Schristos W - a 4-bit unsigned immediate with 2-bit shift 115212397c6Schristos X - a 4-bit unsigned immediate with 1-bit shift 116212397c6Schristos Y - a 4-bit unsigned immediate 117212397c6Schristos e - an immediate coded as an enumeration for addi.n/subi.n 118212397c6Schristos f - an immediate coded as an enumeration for slli.n/srli.n 119212397c6Schristos g - an immediate coded as an enumeration for andi.n 120212397c6Schristos h - an immediate coded as an enumeration for movi.n 121212397c6Schristos R - a reglist for ldwm/stwm or push.n/pop.n 122212397c6Schristos B - a base register specifier and option list for ldwm/stwm 123a2e2270fSchristos Literal ',', '(', and ')' characters may also appear in the args as 124a2e2270fSchristos delimiters. 125a2e2270fSchristos 126968cf8f2Schristos Note that the args describe the semantics and assembly-language syntax 127968cf8f2Schristos of the operands, not their encoding into the instruction word. 128968cf8f2Schristos 129a2e2270fSchristos The pinfo field is INSN_MACRO for a macro. Otherwise, it is a collection 130a2e2270fSchristos of bits describing the instruction, notably any relevant hazard 131a2e2270fSchristos information. 132a2e2270fSchristos 133a2e2270fSchristos When assembling, the match field contains the opcode template, which 134a2e2270fSchristos is modified by the arguments to produce the actual opcode 135a2e2270fSchristos that is emitted. If pinfo is INSN_MACRO, then this is 0. 136a2e2270fSchristos 137a2e2270fSchristos If pinfo is INSN_MACRO, the mask field stores the macro identifier. 138a2e2270fSchristos Otherwise this is a bit mask for the relevant portions of the opcode 139a2e2270fSchristos when disassembling. If the actual opcode anded with the match field 140a2e2270fSchristos equals the opcode field, then we have found the correct instruction. */ 141a2e2270fSchristos 142a2e2270fSchristos struct nios2_opcode 143a2e2270fSchristos { 144a2e2270fSchristos const char *name; /* The name of the instruction. */ 145a2e2270fSchristos const char *args; /* A string describing the arguments for this 146a2e2270fSchristos instruction. */ 147a2e2270fSchristos const char *args_test; /* Like args, but with an extra argument for 148a2e2270fSchristos the expected opcode. */ 149a2e2270fSchristos unsigned long num_args; /* The number of arguments the instruction 150a2e2270fSchristos takes. */ 151968cf8f2Schristos unsigned size; /* Size in bytes of the instruction. */ 152968cf8f2Schristos enum iw_format_type format; /* Instruction format. */ 153a2e2270fSchristos unsigned long match; /* The basic opcode for the instruction. */ 154a2e2270fSchristos unsigned long mask; /* Mask for the opcode field of the 155a2e2270fSchristos instruction. */ 156a2e2270fSchristos unsigned long pinfo; /* Is this a real instruction or instruction 157a2e2270fSchristos macro? */ 158a2e2270fSchristos enum overflow_type overflow_msg; /* Used to generate informative 159a2e2270fSchristos message when fixup overflows. */ 160a2e2270fSchristos }; 161a2e2270fSchristos 162a2e2270fSchristos /* This value is used in the nios2_opcode.pinfo field to indicate that the 163a2e2270fSchristos instruction is a macro or pseudo-op. This requires special treatment by 164a2e2270fSchristos the assembler, and is used by the disassembler to determine whether to 165a2e2270fSchristos check for a nop. */ 166a2e2270fSchristos #define NIOS2_INSN_MACRO 0x80000000 167a2e2270fSchristos #define NIOS2_INSN_MACRO_MOV 0x80000001 168a2e2270fSchristos #define NIOS2_INSN_MACRO_MOVI 0x80000002 169a2e2270fSchristos #define NIOS2_INSN_MACRO_MOVIA 0x80000004 170a2e2270fSchristos 171a2e2270fSchristos #define NIOS2_INSN_RELAXABLE 0x40000000 172a2e2270fSchristos #define NIOS2_INSN_UBRANCH 0x00000010 173a2e2270fSchristos #define NIOS2_INSN_CBRANCH 0x00000020 174a2e2270fSchristos #define NIOS2_INSN_CALL 0x00000040 175a2e2270fSchristos 176968cf8f2Schristos #define NIOS2_INSN_OPTARG 0x00000080 177a2e2270fSchristos 178968cf8f2Schristos /* Register attributes. */ 179968cf8f2Schristos #define REG_NORMAL (1<<0) /* Normal registers. */ 180968cf8f2Schristos #define REG_CONTROL (1<<1) /* Control registers. */ 181968cf8f2Schristos #define REG_COPROCESSOR (1<<2) /* For custom instructions. */ 182212397c6Schristos #define REG_3BIT (1<<3) /* For R2 CDX instructions. */ 183212397c6Schristos #define REG_LDWM (1<<4) /* For R2 ldwm/stwm. */ 184212397c6Schristos #define REG_POP (1<<5) /* For R2 pop.n/push.n. */ 185a2e2270fSchristos 186a2e2270fSchristos struct nios2_reg 187a2e2270fSchristos { 188a2e2270fSchristos const char *name; 189a2e2270fSchristos const int index; 190968cf8f2Schristos unsigned long regtype; 191a2e2270fSchristos }; 192a2e2270fSchristos 193968cf8f2Schristos /* Pull in the instruction field accessors, opcodes, and masks. */ 194968cf8f2Schristos #include "nios2r1.h" 195212397c6Schristos #include "nios2r2.h" 196a2e2270fSchristos 197968cf8f2Schristos /* These are the data structures used to hold the instruction information. */ 198968cf8f2Schristos extern const struct nios2_opcode nios2_r1_opcodes[]; 199968cf8f2Schristos extern const int nios2_num_r1_opcodes; 200212397c6Schristos extern const struct nios2_opcode nios2_r2_opcodes[]; 201212397c6Schristos extern const int nios2_num_r2_opcodes; 202a2e2270fSchristos extern struct nios2_opcode *nios2_opcodes; 203968cf8f2Schristos extern int nios2_num_opcodes; 204a2e2270fSchristos 205a2e2270fSchristos /* These are the data structures used to hold the register information. */ 206a2e2270fSchristos extern const struct nios2_reg nios2_builtin_regs[]; 207a2e2270fSchristos extern struct nios2_reg *nios2_regs; 208a2e2270fSchristos extern const int nios2_num_builtin_regs; 209a2e2270fSchristos extern int nios2_num_regs; 210a2e2270fSchristos 211968cf8f2Schristos /* Return the opcode descriptor for a single instruction. */ 212968cf8f2Schristos extern const struct nios2_opcode * 213968cf8f2Schristos nios2_find_opcode_hash (unsigned long, unsigned long); 214a2e2270fSchristos 215212397c6Schristos /* Lookup tables for R2 immediate decodings. */ 216212397c6Schristos extern unsigned int nios2_r2_asi_n_mappings[]; 217212397c6Schristos extern const int nios2_num_r2_asi_n_mappings; 218212397c6Schristos extern unsigned int nios2_r2_shi_n_mappings[]; 219212397c6Schristos extern const int nios2_num_r2_shi_n_mappings; 220212397c6Schristos extern unsigned int nios2_r2_andi_n_mappings[]; 221212397c6Schristos extern const int nios2_num_r2_andi_n_mappings; 222212397c6Schristos 223212397c6Schristos /* Lookup table for 3-bit register decodings. */ 224212397c6Schristos extern int nios2_r2_reg3_mappings[]; 225212397c6Schristos extern const int nios2_num_r2_reg3_mappings; 226212397c6Schristos 227212397c6Schristos /* Lookup table for REG_RANGE value list decodings. */ 228212397c6Schristos extern unsigned long nios2_r2_reg_range_mappings[]; 229212397c6Schristos extern const int nios2_num_r2_reg_range_mappings; 230212397c6Schristos 231212397c6Schristos #ifdef __cplusplus 232212397c6Schristos } 233212397c6Schristos #endif 234212397c6Schristos 235a2e2270fSchristos #endif /* _NIOS2_H */ 236