35 if ((insn & 0x3) != 0x3)
37 if ((insn & 0x1f) != 0x1f)
39 if ((insn & 0x3f) == 0x1f)
41 if ((insn & 0x7f) == 0x3f)
49 "rne",
"rtz",
"rdn",
"rup",
"rmm", 0, 0,
"dyn"
54 0,
"w",
"r",
"rw",
"o",
"ow",
"or",
"orw",
55 "i",
"iw",
"ir",
"irw",
"io",
"iow",
"ior",
"iorw"
58 #define RVC_JUMP_BITS 11
59 #define RVC_JUMP_REACH ((1ULL << RVC_JUMP_BITS) * RISCV_JUMP_ALIGN)
61 #define RVC_BRANCH_BITS 8
62 #define RVC_BRANCH_REACH ((1ULL << RVC_BRANCH_BITS) * RISCV_BRANCH_ALIGN)
64 #define RV_X(x, s, n) (((x) >> (s)) & ((1 << (n)) - 1))
65 #define RV_IMM_SIGN(x) (-(((x) >> 31) & 1))
67 #define EXTRACT_ITYPE_IMM(x) \
68 (RV_X(x, 20, 12) | (RV_IMM_SIGN(x) << 12))
69 #define EXTRACT_STYPE_IMM(x) \
70 (RV_X(x, 7, 5) | (RV_X(x, 25, 7) << 5) | (RV_IMM_SIGN(x) << 12))
71 #define EXTRACT_SBTYPE_IMM(x) \
72 ((RV_X(x, 8, 4) << 1) | (RV_X(x, 25, 6) << 5) | (RV_X(x, 7, 1) << 11) | (RV_IMM_SIGN(x) << 12))
73 #define EXTRACT_UTYPE_IMM(x) \
74 ((RV_X(x, 12, 20) << 12) | (RV_IMM_SIGN(x) << 32))
75 #define EXTRACT_UJTYPE_IMM(x) \
76 ((RV_X(x, 21, 10) << 1) | (RV_X(x, 20, 1) << 11) | (RV_X(x, 12, 8) << 12) | (RV_IMM_SIGN(x) << 20))
77 #define EXTRACT_RVC_IMM(x) \
78 (RV_X(x, 2, 5) | (-RV_X(x, 12, 1) << 5))
79 #define EXTRACT_RVC_LUI_IMM(x) \
80 (EXTRACT_RVC_IMM (x) << RISCV_IMM_BITS)
81 #define EXTRACT_RVC_SIMM3(x) \
82 (RV_X(x, 10, 2) | (-RV_X(x, 12, 1) << 2))
83 #define EXTRACT_RVC_ADDI4SPN_IMM(x) \
84 ((RV_X(x, 6, 1) << 2) | (RV_X(x, 5, 1) << 3) | (RV_X(x, 11, 2) << 4) | (RV_X(x, 7, 4) << 6))
85 #define EXTRACT_RVC_ADDI16SP_IMM(x) \
86 ((RV_X(x, 6, 1) << 4) | (RV_X(x, 2, 1) << 5) | (RV_X(x, 5, 1) << 6) | (RV_X(x, 3, 2) << 7) | (-RV_X(x, 12, 1) << 9))
87 #define EXTRACT_RVC_LW_IMM(x) \
88 ((RV_X(x, 6, 1) << 2) | (RV_X(x, 10, 3) << 3) | (RV_X(x, 5, 1) << 6))
89 #define EXTRACT_RVC_LD_IMM(x) \
90 ((RV_X(x, 10, 3) << 3) | (RV_X(x, 5, 2) << 6))
91 #define EXTRACT_RVC_LWSP_IMM(x) \
92 ((RV_X(x, 4, 3) << 2) | (RV_X(x, 12, 1) << 5) | (RV_X(x, 2, 2) << 6))
93 #define EXTRACT_RVC_LDSP_IMM(x) \
94 ((RV_X(x, 5, 2) << 3) | (RV_X(x, 12, 1) << 5) | (RV_X(x, 2, 3) << 6))
95 #define EXTRACT_RVC_SWSP_IMM(x) \
96 ((RV_X(x, 9, 4) << 2) | (RV_X(x, 7, 2) << 6))
97 #define EXTRACT_RVC_SDSP_IMM(x) \
98 ((RV_X(x, 10, 3) << 3) | (RV_X(x, 7, 3) << 6))
99 #define EXTRACT_RVC_B_IMM(x) \
100 ((RV_X(x, 3, 2) << 1) | (RV_X(x, 10, 2) << 3) | (RV_X(x, 2, 1) << 5) | (RV_X(x, 5, 2) << 6) | (-RV_X(x, 12, 1) << 8))
101 #define EXTRACT_RVC_J_IMM(x) \
102 ((RV_X(x, 3, 3) << 1) | (RV_X(x, 11, 1) << 4) | (RV_X(x, 2, 1) << 5) | (RV_X(x, 7, 1) << 6) | (RV_X(x, 6, 1) << 7) | (RV_X(x, 9, 2) << 8) | (RV_X(x, 8, 1) << 10) | (-RV_X(x, 12, 1) << 11))
104 #define ENCODE_ITYPE_IMM(x) \
105 (RV_X(x, 0, 12) << 20)
106 #define ENCODE_STYPE_IMM(x) \
107 ((RV_X(x, 0, 5) << 7) | (RV_X(x, 5, 7) << 25))
108 #define ENCODE_SBTYPE_IMM(x) \
109 ((RV_X(x, 1, 4) << 8) | (RV_X(x, 5, 6) << 25) | (RV_X(x, 11, 1) << 7) | (RV_X(x, 12, 1) << 31))
110 #define ENCODE_UTYPE_IMM(x) \
111 (RV_X(x, 12, 20) << 12)
112 #define ENCODE_UJTYPE_IMM(x) \
113 ((RV_X(x, 1, 10) << 21) | (RV_X(x, 11, 1) << 20) | (RV_X(x, 12, 8) << 12) | (RV_X(x, 20, 1) << 31))
114 #define ENCODE_RVC_IMM(x) \
115 ((RV_X(x, 0, 5) << 2) | (RV_X(x, 5, 1) << 12))
116 #define ENCODE_RVC_LUI_IMM(x) \
117 ENCODE_RVC_IMM ((x) >> RISCV_IMM_BITS)
118 #define ENCODE_RVC_SIMM3(x) \
119 (RV_X(x, 0, 3) << 10)
120 #define ENCODE_RVC_ADDI4SPN_IMM(x) \
121 ((RV_X(x, 2, 1) << 6) | (RV_X(x, 3, 1) << 5) | (RV_X(x, 4, 2) << 11) | (RV_X(x, 6, 4) << 7))
122 #define ENCODE_RVC_ADDI16SP_IMM(x) \
123 ((RV_X(x, 4, 1) << 6) | (RV_X(x, 5, 1) << 2) | (RV_X(x, 6, 1) << 5) | (RV_X(x, 7, 2) << 3) | (RV_X(x, 9, 1) << 12))
124 #define ENCODE_RVC_LW_IMM(x) \
125 ((RV_X(x, 2, 1) << 6) | (RV_X(x, 3, 3) << 10) | (RV_X(x, 6, 1) << 5))
126 #define ENCODE_RVC_LD_IMM(x) \
127 ((RV_X(x, 3, 3) << 10) | (RV_X(x, 6, 2) << 5))
128 #define ENCODE_RVC_LWSP_IMM(x) \
129 ((RV_X(x, 2, 3) << 4) | (RV_X(x, 5, 1) << 12) | (RV_X(x, 6, 2) << 2))
130 #define ENCODE_RVC_LDSP_IMM(x) \
131 ((RV_X(x, 3, 2) << 5) | (RV_X(x, 5, 1) << 12) | (RV_X(x, 6, 3) << 2))
132 #define ENCODE_RVC_SWSP_IMM(x) \
133 ((RV_X(x, 2, 4) << 9) | (RV_X(x, 6, 2) << 7))
134 #define ENCODE_RVC_SDSP_IMM(x) \
135 ((RV_X(x, 3, 3) << 10) | (RV_X(x, 6, 3) << 7))
136 #define ENCODE_RVC_B_IMM(x) \
137 ((RV_X(x, 1, 2) << 3) | (RV_X(x, 3, 2) << 10) | (RV_X(x, 5, 1) << 2) | (RV_X(x, 6, 2) << 5) | (RV_X(x, 8, 1) << 12))
138 #define ENCODE_RVC_J_IMM(x) \
139 ((RV_X(x, 1, 3) << 3) | (RV_X(x, 4, 1) << 11) | (RV_X(x, 5, 1) << 2) | (RV_X(x, 6, 1) << 7) | (RV_X(x, 7, 1) << 6) | (RV_X(x, 8, 2) << 9) | (RV_X(x, 10, 1) << 8) | (RV_X(x, 11, 1) << 12))
141 #define VALID_ITYPE_IMM(x) (EXTRACT_ITYPE_IMM(ENCODE_ITYPE_IMM(x)) == (x))
142 #define VALID_STYPE_IMM(x) (EXTRACT_STYPE_IMM(ENCODE_STYPE_IMM(x)) == (x))
143 #define VALID_SBTYPE_IMM(x) (EXTRACT_SBTYPE_IMM(ENCODE_SBTYPE_IMM(x)) == (x))
144 #define VALID_UTYPE_IMM(x) (EXTRACT_UTYPE_IMM(ENCODE_UTYPE_IMM(x)) == (x))
145 #define VALID_UJTYPE_IMM(x) (EXTRACT_UJTYPE_IMM(ENCODE_UJTYPE_IMM(x)) == (x))
146 #define VALID_RVC_IMM(x) (EXTRACT_RVC_IMM(ENCODE_RVC_IMM(x)) == (x))
147 #define VALID_RVC_LUI_IMM(x) (EXTRACT_RVC_LUI_IMM(ENCODE_RVC_LUI_IMM(x)) == (x))
148 #define VALID_RVC_SIMM3(x) (EXTRACT_RVC_SIMM3(ENCODE_RVC_SIMM3(x)) == (x))
149 #define VALID_RVC_ADDI4SPN_IMM(x) (EXTRACT_RVC_ADDI4SPN_IMM(ENCODE_RVC_ADDI4SPN_IMM(x)) == (x))
150 #define VALID_RVC_ADDI16SP_IMM(x) (EXTRACT_RVC_ADDI16SP_IMM(ENCODE_RVC_ADDI16SP_IMM(x)) == (x))
151 #define VALID_RVC_LW_IMM(x) (EXTRACT_RVC_LW_IMM(ENCODE_RVC_LW_IMM(x)) == (x))
152 #define VALID_RVC_LD_IMM(x) (EXTRACT_RVC_LD_IMM(ENCODE_RVC_LD_IMM(x)) == (x))
153 #define VALID_RVC_LWSP_IMM(x) (EXTRACT_RVC_LWSP_IMM(ENCODE_RVC_LWSP_IMM(x)) == (x))
154 #define VALID_RVC_LDSP_IMM(x) (EXTRACT_RVC_LDSP_IMM(ENCODE_RVC_LDSP_IMM(x)) == (x))
155 #define VALID_RVC_SWSP_IMM(x) (EXTRACT_RVC_SWSP_IMM(ENCODE_RVC_SWSP_IMM(x)) == (x))
156 #define VALID_RVC_SDSP_IMM(x) (EXTRACT_RVC_SDSP_IMM(ENCODE_RVC_SDSP_IMM(x)) == (x))
157 #define VALID_RVC_B_IMM(x) (EXTRACT_RVC_B_IMM(ENCODE_RVC_B_IMM(x)) == (x))
158 #define VALID_RVC_J_IMM(x) (EXTRACT_RVC_J_IMM(ENCODE_RVC_J_IMM(x)) == (x))
160 #define RISCV_RTYPE(insn, rd, rs1, rs2) \
161 ((MATCH_ ## insn) | ((rd) << OP_SH_RD) | ((rs1) << OP_SH_RS1) | ((rs2) << OP_SH_RS2))
162 #define RISCV_ITYPE(insn, rd, rs1, imm) \
163 ((MATCH_ ## insn) | ((rd) << OP_SH_RD) | ((rs1) << OP_SH_RS1) | ENCODE_ITYPE_IMM(imm))
164 #define RISCV_STYPE(insn, rs1, rs2, imm) \
165 ((MATCH_ ## insn) | ((rs1) << OP_SH_RS1) | ((rs2) << OP_SH_RS2) | ENCODE_STYPE_IMM(imm))
166 #define RISCV_SBTYPE(insn, rs1, rs2, target) \
167 ((MATCH_ ## insn) | ((rs1) << OP_SH_RS1) | ((rs2) << OP_SH_RS2) | ENCODE_SBTYPE_IMM(target))
168 #define RISCV_UTYPE(insn, rd, bigimm) \
169 ((MATCH_ ## insn) | ((rd) << OP_SH_RD) | ENCODE_UTYPE_IMM(bigimm))
170 #define RISCV_UJTYPE(insn, rd, target) \
171 ((MATCH_ ## insn) | ((rd) << OP_SH_RD) | ENCODE_UJTYPE_IMM(target))
173 #define RISCV_NOP RISCV_ITYPE(ADDI, 0, 0, 0)
174 #define RVC_NOP MATCH_C_ADDI
176 #define RISCV_CONST_HIGH_PART(VALUE) \
177 (((VALUE) + (RISCV_IMM_REACH/2)) & ~(RISCV_IMM_REACH-1))
178 #define RISCV_CONST_LOW_PART(VALUE) ((VALUE) - RISCV_CONST_HIGH_PART (VALUE))
179 #define RISCV_PCREL_HIGH_PART(VALUE, PC) RISCV_CONST_HIGH_PART((VALUE) - (PC))
180 #define RISCV_PCREL_LOW_PART(VALUE, PC) RISCV_CONST_LOW_PART((VALUE) - (PC))
182 #define RISCV_JUMP_BITS RISCV_BIGIMM_BITS
183 #define RISCV_JUMP_ALIGN_BITS 1
184 #define RISCV_JUMP_ALIGN (1 << RISCV_JUMP_ALIGN_BITS)
185 #define RISCV_JUMP_REACH ((1ULL << RISCV_JUMP_BITS) * RISCV_JUMP_ALIGN)
187 #define RISCV_IMM_BITS 12
188 #define RISCV_BIGIMM_BITS (32 - RISCV_IMM_BITS)
189 #define RISCV_IMM_REACH (1LL << RISCV_IMM_BITS)
190 #define RISCV_BIGIMM_REACH (1LL << RISCV_BIGIMM_BITS)
191 #define RISCV_RVC_IMM_REACH (1LL << 6)
192 #define RISCV_BRANCH_BITS RISCV_IMM_BITS
193 #define RISCV_BRANCH_ALIGN_BITS RISCV_JUMP_ALIGN_BITS
194 #define RISCV_BRANCH_ALIGN (1 << RISCV_BRANCH_ALIGN_BITS)
195 #define RISCV_BRANCH_REACH (RISCV_IMM_REACH * RISCV_BRANCH_ALIGN)
199 #define OP_MASK_OP 0x7f
201 #define OP_MASK_RS2 0x1f
203 #define OP_MASK_RS1 0x1f
205 #define OP_MASK_RS3 0x1f
207 #define OP_MASK_RD 0x1f
209 #define OP_MASK_SHAMT 0x3f
210 #define OP_SH_SHAMT 20
211 #define OP_MASK_SHAMTW 0x1f
212 #define OP_SH_SHAMTW 20
213 #define OP_MASK_RM 0x7
215 #define OP_MASK_PRED 0xf
216 #define OP_SH_PRED 24
217 #define OP_MASK_SUCC 0xf
218 #define OP_SH_SUCC 20
219 #define OP_MASK_AQ 0x1
221 #define OP_MASK_RL 0x1
224 #define OP_MASK_CUSTOM_IMM 0x7f
225 #define OP_SH_CUSTOM_IMM 25
226 #define OP_MASK_CSR 0xfff
231 #define OP_MASK_CRS2 0x1f
233 #define OP_MASK_CRS1S 0x7
234 #define OP_SH_CRS1S 7
235 #define OP_MASK_CRS2S 0x7
236 #define OP_SH_CRS2S 2
254 #define INSERT_BITS(STRUCT, VALUE, MASK, SHIFT) \
255 (STRUCT) = (((STRUCT) & ~((insn_t)(MASK) << (SHIFT))) \
256 | ((insn_t)((VALUE) & (MASK)) << (SHIFT)))
260 #define EXTRACT_BITS(STRUCT, MASK, SHIFT) \
261 (((STRUCT) >> (SHIFT)) & (MASK))
264 #define EXTRACT_OPERAND(FIELD, INSN) \
265 EXTRACT_BITS ((INSN), OP_MASK_##FIELD, OP_SH_##FIELD)
297 #define INSN_ALIAS 0x00000001
300 #define INSN_MACRO 0xffffffff
351 #define NUMOPCODES bfd_riscv_num_opcodes
static const char *const riscv_gpr_names_numeric[NGPR]
static const char *const riscv_gpr_names_abi[NGPR]
static int bfd_riscv_num_opcodes
static const char *const riscv_fpr_names_abi[NFPR]
static struct riscv_opcode * riscv_opcodes
static const char *const riscv_fpr_names_numeric[NFPR]
static const char *const riscv_rm[8]
static const char *const riscv_pred_succ[16]
static unsigned int riscv_insn_length(insn_t insn)
int(* match_func)(const struct riscv_opcode *op, insn_t word)