xref: /netbsd-src/external/gpl3/gdb/dist/include/opcode/riscv.h (revision aab831cebf6361fb2b518a47c70732e608d9abd2)
1796c32c9Schristos /* riscv.h.  RISC-V opcode list for GDB, the GNU debugger.
2*aab831ceSchristos    Copyright (C) 2011-2024 Free Software Foundation, Inc.
3796c32c9Schristos    Contributed by Andrew Waterman
4796c32c9Schristos 
5796c32c9Schristos    This file is part of GDB, GAS, and the GNU binutils.
6796c32c9Schristos 
7796c32c9Schristos    GDB, GAS, and the GNU binutils are free software; you can redistribute
8796c32c9Schristos    them and/or modify them under the terms of the GNU General Public
9796c32c9Schristos    License as published by the Free Software Foundation; either version
10796c32c9Schristos    3, or (at your option) any later version.
11796c32c9Schristos 
12796c32c9Schristos    GDB, GAS, and the GNU binutils are distributed in the hope that they
13796c32c9Schristos    will be useful, but WITHOUT ANY WARRANTY; without even the implied
14796c32c9Schristos    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
15796c32c9Schristos    the GNU General Public License for more details.
16796c32c9Schristos 
17796c32c9Schristos    You should have received a copy of the GNU General Public License
18796c32c9Schristos    along with this program; see the file COPYING3. If not,
19796c32c9Schristos    see <http://www.gnu.org/licenses/>.  */
20796c32c9Schristos 
21796c32c9Schristos #ifndef _RISCV_H_
22796c32c9Schristos #define _RISCV_H_
23796c32c9Schristos 
24796c32c9Schristos #include "riscv-opc.h"
25796c32c9Schristos #include <stdlib.h>
26796c32c9Schristos #include <stdint.h>
27796c32c9Schristos 
28796c32c9Schristos typedef uint64_t insn_t;
29796c32c9Schristos 
30796c32c9Schristos static inline unsigned int riscv_insn_length (insn_t insn)
31796c32c9Schristos {
324b169a6bSchristos   if ((insn & 0x3) != 0x3) /* RVC instructions.  */
33796c32c9Schristos     return 2;
344b169a6bSchristos   if ((insn & 0x1f) != 0x1f) /* 32-bit instructions.  */
35796c32c9Schristos     return 4;
364b169a6bSchristos   if ((insn & 0x3f) == 0x1f) /* 48-bit instructions.  */
37796c32c9Schristos     return 6;
384b169a6bSchristos   if ((insn & 0x7f) == 0x3f) /* 64-bit instructions.  */
39796c32c9Schristos     return 8;
404b169a6bSchristos   /* 80- ... 176-bit instructions.  */
414b169a6bSchristos   if ((insn & 0x7f) == 0x7f && (insn & 0x7000) != 0x7000)
424b169a6bSchristos     return 10 + ((insn >> 11) & 0xe);
434b169a6bSchristos   /* Maximum value returned by this function.  */
444b169a6bSchristos #define RISCV_MAX_INSN_LEN 22
45796c32c9Schristos   /* Longer instructions not supported at the moment.  */
46796c32c9Schristos   return 2;
47796c32c9Schristos }
48796c32c9Schristos 
49796c32c9Schristos #define RVC_JUMP_BITS 11
50796c32c9Schristos #define RVC_JUMP_REACH ((1ULL << RVC_JUMP_BITS) * RISCV_JUMP_ALIGN)
51796c32c9Schristos 
52796c32c9Schristos #define RVC_BRANCH_BITS 8
53796c32c9Schristos #define RVC_BRANCH_REACH ((1ULL << RVC_BRANCH_BITS) * RISCV_BRANCH_ALIGN)
54796c32c9Schristos 
55796c32c9Schristos #define RV_X(x, s, n)  (((x) >> (s)) & ((1 << (n)) - 1))
56796c32c9Schristos #define RV_IMM_SIGN(x) (-(((x) >> 31) & 1))
574b169a6bSchristos #define RV_X_SIGNED(x, s, n) (RV_X(x, s, n) | ((-(RV_X(x, (s + n - 1), 1))) << (n)))
58796c32c9Schristos 
59796c32c9Schristos #define EXTRACT_ITYPE_IMM(x) \
60796c32c9Schristos   (RV_X(x, 20, 12) | (RV_IMM_SIGN(x) << 12))
61796c32c9Schristos #define EXTRACT_STYPE_IMM(x) \
62796c32c9Schristos   (RV_X(x, 7, 5) | (RV_X(x, 25, 7) << 5) | (RV_IMM_SIGN(x) << 12))
634b169a6bSchristos #define EXTRACT_BTYPE_IMM(x) \
64796c32c9Schristos   ((RV_X(x, 8, 4) << 1) | (RV_X(x, 25, 6) << 5) | (RV_X(x, 7, 1) << 11) | (RV_IMM_SIGN(x) << 12))
65796c32c9Schristos #define EXTRACT_UTYPE_IMM(x) \
66796c32c9Schristos   ((RV_X(x, 12, 20) << 12) | (RV_IMM_SIGN(x) << 32))
674b169a6bSchristos #define EXTRACT_JTYPE_IMM(x) \
68796c32c9Schristos   ((RV_X(x, 21, 10) << 1) | (RV_X(x, 20, 1) << 11) | (RV_X(x, 12, 8) << 12) | (RV_IMM_SIGN(x) << 20))
694b169a6bSchristos #define EXTRACT_CITYPE_IMM(x) \
70796c32c9Schristos   (RV_X(x, 2, 5) | (-RV_X(x, 12, 1) << 5))
714b169a6bSchristos #define EXTRACT_CITYPE_LUI_IMM(x) \
724b169a6bSchristos   (EXTRACT_CITYPE_IMM (x) << RISCV_IMM_BITS)
734b169a6bSchristos #define EXTRACT_CITYPE_ADDI16SP_IMM(x) \
74796c32c9Schristos   ((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))
754b169a6bSchristos #define EXTRACT_CITYPE_LWSP_IMM(x) \
76796c32c9Schristos   ((RV_X(x, 4, 3) << 2) | (RV_X(x, 12, 1) << 5) | (RV_X(x, 2, 2) << 6))
774b169a6bSchristos #define EXTRACT_CITYPE_LDSP_IMM(x) \
78796c32c9Schristos   ((RV_X(x, 5, 2) << 3) | (RV_X(x, 12, 1) << 5) | (RV_X(x, 2, 3) << 6))
794b169a6bSchristos #define EXTRACT_CSSTYPE_IMM(x) \
804b169a6bSchristos   (RV_X(x, 7, 6) << 0)
814b169a6bSchristos #define EXTRACT_CSSTYPE_SWSP_IMM(x) \
82796c32c9Schristos   ((RV_X(x, 9, 4) << 2) | (RV_X(x, 7, 2) << 6))
834b169a6bSchristos #define EXTRACT_CSSTYPE_SDSP_IMM(x) \
84796c32c9Schristos   ((RV_X(x, 10, 3) << 3) | (RV_X(x, 7, 3) << 6))
854b169a6bSchristos #define EXTRACT_CIWTYPE_IMM(x) \
864b169a6bSchristos   (RV_X(x, 5, 8))
874b169a6bSchristos #define EXTRACT_CIWTYPE_ADDI4SPN_IMM(x) \
884b169a6bSchristos   ((RV_X(x, 6, 1) << 2) | (RV_X(x, 5, 1) << 3) | (RV_X(x, 11, 2) << 4) | (RV_X(x, 7, 4) << 6))
894b169a6bSchristos #define EXTRACT_CLTYPE_IMM(x) \
904b169a6bSchristos   ((RV_X(x, 5, 2) << 0) | (RV_X(x, 10, 3) << 2))
914b169a6bSchristos #define EXTRACT_CLTYPE_LW_IMM(x) \
924b169a6bSchristos   ((RV_X(x, 6, 1) << 2) | (RV_X(x, 10, 3) << 3) | (RV_X(x, 5, 1) << 6))
934b169a6bSchristos #define EXTRACT_CLTYPE_LD_IMM(x) \
944b169a6bSchristos   ((RV_X(x, 10, 3) << 3) | (RV_X(x, 5, 2) << 6))
954b169a6bSchristos #define EXTRACT_CBTYPE_IMM(x) \
96796c32c9Schristos   ((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))
974b169a6bSchristos #define EXTRACT_CJTYPE_IMM(x) \
98796c32c9Schristos   ((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))
994b169a6bSchristos #define EXTRACT_RVV_VI_IMM(x) \
1004b169a6bSchristos   (RV_X(x, 15, 5) | (-RV_X(x, 19, 1) << 5))
1014b169a6bSchristos #define EXTRACT_RVV_VI_UIMM(x) \
1024b169a6bSchristos   (RV_X(x, 15, 5))
103*aab831ceSchristos #define EXTRACT_RVV_VI_UIMM6(x) \
104*aab831ceSchristos   (RV_X(x, 15, 5) | (RV_X(x, 26, 1) << 5))
1054b169a6bSchristos #define EXTRACT_RVV_OFFSET(x) \
1064b169a6bSchristos   (RV_X(x, 29, 3))
1074b169a6bSchristos #define EXTRACT_RVV_VB_IMM(x) \
1084b169a6bSchristos   (RV_X(x, 20, 10))
1094b169a6bSchristos #define EXTRACT_RVV_VC_IMM(x) \
1104b169a6bSchristos   (RV_X(x, 20, 11))
111*aab831ceSchristos #define EXTRACT_ZCB_BYTE_UIMM(x) \
112*aab831ceSchristos   (RV_X(x, 6, 1) | (RV_X(x, 5, 1) << 1))
113*aab831ceSchristos #define EXTRACT_ZCB_HALFWORD_UIMM(x) \
114*aab831ceSchristos   (RV_X(x, 5, 1) << 1)
115*aab831ceSchristos #define EXTRACT_ZCMP_SPIMM(x) \
116*aab831ceSchristos   (RV_X(x, 2, 2) << 4)
117*aab831ceSchristos /* Vendor-specific (CORE-V) extract macros.  */
118*aab831ceSchristos #define EXTRACT_CV_IS2_UIMM5(x) \
119*aab831ceSchristos   (RV_X(x, 20, 5))
120*aab831ceSchristos #define EXTRACT_CV_IS3_UIMM5(x) \
121*aab831ceSchristos   (RV_X(x, 25, 5))
122796c32c9Schristos 
123796c32c9Schristos #define ENCODE_ITYPE_IMM(x) \
124796c32c9Schristos   (RV_X(x, 0, 12) << 20)
125796c32c9Schristos #define ENCODE_STYPE_IMM(x) \
126796c32c9Schristos   ((RV_X(x, 0, 5) << 7) | (RV_X(x, 5, 7) << 25))
1274b169a6bSchristos #define ENCODE_BTYPE_IMM(x) \
128796c32c9Schristos   ((RV_X(x, 1, 4) << 8) | (RV_X(x, 5, 6) << 25) | (RV_X(x, 11, 1) << 7) | (RV_X(x, 12, 1) << 31))
129796c32c9Schristos #define ENCODE_UTYPE_IMM(x) \
130796c32c9Schristos   (RV_X(x, 12, 20) << 12)
1314b169a6bSchristos #define ENCODE_JTYPE_IMM(x) \
132796c32c9Schristos   ((RV_X(x, 1, 10) << 21) | (RV_X(x, 11, 1) << 20) | (RV_X(x, 12, 8) << 12) | (RV_X(x, 20, 1) << 31))
1334b169a6bSchristos #define ENCODE_CITYPE_IMM(x) \
134796c32c9Schristos   ((RV_X(x, 0, 5) << 2) | (RV_X(x, 5, 1) << 12))
1354b169a6bSchristos #define ENCODE_CITYPE_LUI_IMM(x) \
1364b169a6bSchristos   ENCODE_CITYPE_IMM ((x) >> RISCV_IMM_BITS)
1374b169a6bSchristos #define ENCODE_CITYPE_ADDI16SP_IMM(x) \
138796c32c9Schristos   ((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))
1394b169a6bSchristos #define ENCODE_CITYPE_LWSP_IMM(x) \
140796c32c9Schristos   ((RV_X(x, 2, 3) << 4) | (RV_X(x, 5, 1) << 12) | (RV_X(x, 6, 2) << 2))
1414b169a6bSchristos #define ENCODE_CITYPE_LDSP_IMM(x) \
142796c32c9Schristos   ((RV_X(x, 3, 2) << 5) | (RV_X(x, 5, 1) << 12) | (RV_X(x, 6, 3) << 2))
1434b169a6bSchristos #define ENCODE_CSSTYPE_IMM(x) \
1444b169a6bSchristos   (RV_X(x, 0, 6) << 7)
1454b169a6bSchristos #define ENCODE_CSSTYPE_SWSP_IMM(x) \
146796c32c9Schristos   ((RV_X(x, 2, 4) << 9) | (RV_X(x, 6, 2) << 7))
1474b169a6bSchristos #define ENCODE_CSSTYPE_SDSP_IMM(x) \
148796c32c9Schristos   ((RV_X(x, 3, 3) << 10) | (RV_X(x, 6, 3) << 7))
1494b169a6bSchristos #define ENCODE_CIWTYPE_IMM(x) \
1504b169a6bSchristos   (RV_X(x, 0, 8) << 5)
1514b169a6bSchristos #define ENCODE_CIWTYPE_ADDI4SPN_IMM(x) \
1524b169a6bSchristos   ((RV_X(x, 2, 1) << 6) | (RV_X(x, 3, 1) << 5) | (RV_X(x, 4, 2) << 11) | (RV_X(x, 6, 4) << 7))
1534b169a6bSchristos #define ENCODE_CLTYPE_IMM(x) \
1544b169a6bSchristos   ((RV_X(x, 0, 2) << 5) | (RV_X(x, 2, 3) << 10))
1554b169a6bSchristos #define ENCODE_CLTYPE_LW_IMM(x) \
1564b169a6bSchristos   ((RV_X(x, 2, 1) << 6) | (RV_X(x, 3, 3) << 10) | (RV_X(x, 6, 1) << 5))
1574b169a6bSchristos #define ENCODE_CLTYPE_LD_IMM(x) \
1584b169a6bSchristos   ((RV_X(x, 3, 3) << 10) | (RV_X(x, 6, 2) << 5))
1594b169a6bSchristos #define ENCODE_CBTYPE_IMM(x) \
160796c32c9Schristos   ((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))
1614b169a6bSchristos #define ENCODE_CJTYPE_IMM(x) \
162796c32c9Schristos   ((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))
1634b169a6bSchristos #define ENCODE_RVV_VB_IMM(x) \
1644b169a6bSchristos   (RV_X(x, 0, 10) << 20)
1654b169a6bSchristos #define ENCODE_RVV_VC_IMM(x) \
1664b169a6bSchristos   (RV_X(x, 0, 11) << 20)
167*aab831ceSchristos #define ENCODE_RVV_VI_UIMM6(x) \
168*aab831ceSchristos   (RV_X(x, 0, 5) << 15 | RV_X(x, 5, 1) << 26)
169*aab831ceSchristos #define ENCODE_ZCB_BYTE_UIMM(x) \
170*aab831ceSchristos   ((RV_X(x, 0, 1) << 6) | (RV_X(x, 1, 1) << 5))
171*aab831ceSchristos #define ENCODE_ZCB_HALFWORD_UIMM(x) \
172*aab831ceSchristos   (RV_X(x, 1, 1) << 5)
173*aab831ceSchristos #define ENCODE_ZCMP_SPIMM(x) \
174*aab831ceSchristos   (RV_X(x, 4, 2) << 2)
175*aab831ceSchristos /* Vendor-specific (CORE-V) encode macros.  */
176*aab831ceSchristos #define ENCODE_CV_IS2_UIMM5(x) \
177*aab831ceSchristos   (RV_X(x, 0, 5) << 20)
178*aab831ceSchristos #define ENCODE_CV_IS3_UIMM5(x) \
179*aab831ceSchristos   (RV_X(x, 0, 5) << 25)
180796c32c9Schristos 
181796c32c9Schristos #define VALID_ITYPE_IMM(x) (EXTRACT_ITYPE_IMM(ENCODE_ITYPE_IMM(x)) == (x))
182796c32c9Schristos #define VALID_STYPE_IMM(x) (EXTRACT_STYPE_IMM(ENCODE_STYPE_IMM(x)) == (x))
1834b169a6bSchristos #define VALID_BTYPE_IMM(x) (EXTRACT_BTYPE_IMM(ENCODE_BTYPE_IMM(x)) == (x))
184796c32c9Schristos #define VALID_UTYPE_IMM(x) (EXTRACT_UTYPE_IMM(ENCODE_UTYPE_IMM(x)) == (x))
1854b169a6bSchristos #define VALID_JTYPE_IMM(x) (EXTRACT_JTYPE_IMM(ENCODE_JTYPE_IMM(x)) == (x))
1864b169a6bSchristos #define VALID_CITYPE_IMM(x) (EXTRACT_CITYPE_IMM(ENCODE_CITYPE_IMM(x)) == (x))
1874b169a6bSchristos #define VALID_CITYPE_LUI_IMM(x) (ENCODE_CITYPE_LUI_IMM(x) != 0 \
1884b169a6bSchristos 				 && EXTRACT_CITYPE_LUI_IMM(ENCODE_CITYPE_LUI_IMM(x)) == (x))
1894b169a6bSchristos #define VALID_CITYPE_ADDI16SP_IMM(x) (ENCODE_CITYPE_ADDI16SP_IMM(x) != 0 \
1904b169a6bSchristos 				      && EXTRACT_CITYPE_ADDI16SP_IMM(ENCODE_CITYPE_ADDI16SP_IMM(x)) == (x))
1914b169a6bSchristos #define VALID_CITYPE_LWSP_IMM(x) (EXTRACT_CITYPE_LWSP_IMM(ENCODE_CITYPE_LWSP_IMM(x)) == (x))
1924b169a6bSchristos #define VALID_CITYPE_LDSP_IMM(x) (EXTRACT_CITYPE_LDSP_IMM(ENCODE_CITYPE_LDSP_IMM(x)) == (x))
1934b169a6bSchristos #define VALID_CSSTYPE_IMM(x) (EXTRACT_CSSTYPE_IMM(ENCODE_CSSTYPE_IMM(x)) == (x))
1944b169a6bSchristos #define VALID_CSSTYPE_SWSP_IMM(x) (EXTRACT_CSSTYPE_SWSP_IMM(ENCODE_CSSTYPE_SWSP_IMM(x)) == (x))
1954b169a6bSchristos #define VALID_CSSTYPE_SDSP_IMM(x) (EXTRACT_CSSTYPE_SDSP_IMM(ENCODE_CSSTYPE_SDSP_IMM(x)) == (x))
1964b169a6bSchristos #define VALID_CIWTYPE_IMM(x) (EXTRACT_CIWTYPE_IMM(ENCODE_CIWTYPE_IMM(x)) == (x))
1974b169a6bSchristos #define VALID_CIWTYPE_ADDI4SPN_IMM(x) (EXTRACT_CIWTYPE_ADDI4SPN_IMM(ENCODE_CIWTYPE_ADDI4SPN_IMM(x)) == (x))
1984b169a6bSchristos #define VALID_CLTYPE_IMM(x) (EXTRACT_CLTYPE_IMM(ENCODE_CLTYPE_IMM(x)) == (x))
1994b169a6bSchristos #define VALID_CLTYPE_LW_IMM(x) (EXTRACT_CLTYPE_LW_IMM(ENCODE_CLTYPE_LW_IMM(x)) == (x))
2004b169a6bSchristos #define VALID_CLTYPE_LD_IMM(x) (EXTRACT_CLTYPE_LD_IMM(ENCODE_CLTYPE_LD_IMM(x)) == (x))
2014b169a6bSchristos #define VALID_CBTYPE_IMM(x) (EXTRACT_CBTYPE_IMM(ENCODE_CBTYPE_IMM(x)) == (x))
2024b169a6bSchristos #define VALID_CJTYPE_IMM(x) (EXTRACT_CJTYPE_IMM(ENCODE_CJTYPE_IMM(x)) == (x))
2034b169a6bSchristos #define VALID_RVV_VB_IMM(x) (EXTRACT_RVV_VB_IMM(ENCODE_RVV_VB_IMM(x)) == (x))
2044b169a6bSchristos #define VALID_RVV_VC_IMM(x) (EXTRACT_RVV_VC_IMM(ENCODE_RVV_VC_IMM(x)) == (x))
205*aab831ceSchristos #define VALID_ZCB_BYTE_UIMM(x) (EXTRACT_ZCB_BYTE_UIMM(ENCODE_ZCB_BYTE_UIMM(x)) == (x))
206*aab831ceSchristos #define VALID_ZCB_HALFWORD_UIMM(x) (EXTRACT_ZCB_HALFWORD_UIMM(ENCODE_ZCB_HALFWORD_UIMM(x)) == (x))
207*aab831ceSchristos #define VALID_ZCMP_SPIMM(x) (EXTRACT_ZCMP_SPIMM(ENCODE_ZCMP_SPIMM(x)) == (x))
208796c32c9Schristos 
209796c32c9Schristos #define RISCV_RTYPE(insn, rd, rs1, rs2) \
210796c32c9Schristos   ((MATCH_ ## insn) | ((rd) << OP_SH_RD) | ((rs1) << OP_SH_RS1) | ((rs2) << OP_SH_RS2))
211796c32c9Schristos #define RISCV_ITYPE(insn, rd, rs1, imm) \
212796c32c9Schristos   ((MATCH_ ## insn) | ((rd) << OP_SH_RD) | ((rs1) << OP_SH_RS1) | ENCODE_ITYPE_IMM(imm))
213796c32c9Schristos #define RISCV_STYPE(insn, rs1, rs2, imm) \
214796c32c9Schristos   ((MATCH_ ## insn) | ((rs1) << OP_SH_RS1) | ((rs2) << OP_SH_RS2) | ENCODE_STYPE_IMM(imm))
2154b169a6bSchristos #define RISCV_BTYPE(insn, rs1, rs2, target) \
2164b169a6bSchristos   ((MATCH_ ## insn) | ((rs1) << OP_SH_RS1) | ((rs2) << OP_SH_RS2) | ENCODE_BTYPE_IMM(target))
217796c32c9Schristos #define RISCV_UTYPE(insn, rd, bigimm) \
218796c32c9Schristos   ((MATCH_ ## insn) | ((rd) << OP_SH_RD) | ENCODE_UTYPE_IMM(bigimm))
2194b169a6bSchristos #define RISCV_JTYPE(insn, rd, target) \
2204b169a6bSchristos   ((MATCH_ ## insn) | ((rd) << OP_SH_RD) | ENCODE_JTYPE_IMM(target))
221796c32c9Schristos 
222796c32c9Schristos #define RISCV_NOP RISCV_ITYPE(ADDI, 0, 0, 0)
223796c32c9Schristos #define RVC_NOP MATCH_C_ADDI
224796c32c9Schristos 
225796c32c9Schristos #define RISCV_CONST_HIGH_PART(VALUE) \
226796c32c9Schristos   (((VALUE) + (RISCV_IMM_REACH/2)) & ~(RISCV_IMM_REACH-1))
227796c32c9Schristos #define RISCV_CONST_LOW_PART(VALUE) ((VALUE) - RISCV_CONST_HIGH_PART (VALUE))
228796c32c9Schristos #define RISCV_PCREL_HIGH_PART(VALUE, PC) RISCV_CONST_HIGH_PART((VALUE) - (PC))
229796c32c9Schristos #define RISCV_PCREL_LOW_PART(VALUE, PC) RISCV_CONST_LOW_PART((VALUE) - (PC))
230796c32c9Schristos 
231796c32c9Schristos #define RISCV_JUMP_BITS RISCV_BIGIMM_BITS
232796c32c9Schristos #define RISCV_JUMP_ALIGN_BITS 1
233796c32c9Schristos #define RISCV_JUMP_ALIGN (1 << RISCV_JUMP_ALIGN_BITS)
234796c32c9Schristos #define RISCV_JUMP_REACH ((1ULL << RISCV_JUMP_BITS) * RISCV_JUMP_ALIGN)
235796c32c9Schristos 
236796c32c9Schristos #define RISCV_IMM_BITS 12
237796c32c9Schristos #define RISCV_BIGIMM_BITS (32 - RISCV_IMM_BITS)
238796c32c9Schristos #define RISCV_IMM_REACH (1LL << RISCV_IMM_BITS)
239796c32c9Schristos #define RISCV_BIGIMM_REACH (1LL << RISCV_BIGIMM_BITS)
240796c32c9Schristos #define RISCV_RVC_IMM_REACH (1LL << 6)
241796c32c9Schristos #define RISCV_BRANCH_BITS RISCV_IMM_BITS
242796c32c9Schristos #define RISCV_BRANCH_ALIGN_BITS RISCV_JUMP_ALIGN_BITS
243796c32c9Schristos #define RISCV_BRANCH_ALIGN (1 << RISCV_BRANCH_ALIGN_BITS)
244796c32c9Schristos #define RISCV_BRANCH_REACH (RISCV_IMM_REACH * RISCV_BRANCH_ALIGN)
245796c32c9Schristos 
246796c32c9Schristos /* RV fields.  */
247796c32c9Schristos 
248796c32c9Schristos #define OP_MASK_OP		0x7f
249796c32c9Schristos #define OP_SH_OP		0
250796c32c9Schristos #define OP_MASK_RS2		0x1f
251796c32c9Schristos #define OP_SH_RS2		20
252796c32c9Schristos #define OP_MASK_RS1		0x1f
253796c32c9Schristos #define OP_SH_RS1		15
2548dffb485Schristos #define OP_MASK_RS3		0x1fU
255796c32c9Schristos #define OP_SH_RS3		27
256796c32c9Schristos #define OP_MASK_RD		0x1f
257796c32c9Schristos #define OP_SH_RD		7
258796c32c9Schristos #define OP_MASK_SHAMT		0x3f
259796c32c9Schristos #define OP_SH_SHAMT		20
260796c32c9Schristos #define OP_MASK_SHAMTW		0x1f
261796c32c9Schristos #define OP_SH_SHAMTW		20
262796c32c9Schristos #define OP_MASK_RM		0x7
263796c32c9Schristos #define OP_SH_RM		12
264796c32c9Schristos #define OP_MASK_PRED		0xf
265796c32c9Schristos #define OP_SH_PRED		24
266796c32c9Schristos #define OP_MASK_SUCC		0xf
267796c32c9Schristos #define OP_SH_SUCC		20
268796c32c9Schristos #define OP_MASK_AQ		0x1
269796c32c9Schristos #define OP_SH_AQ		26
270796c32c9Schristos #define OP_MASK_RL		0x1
271796c32c9Schristos #define OP_SH_RL		25
272796c32c9Schristos 
2738dffb485Schristos #define OP_MASK_CSR		0xfffU
274796c32c9Schristos #define OP_SH_CSR		20
275796c32c9Schristos 
2764559860eSchristos #define OP_MASK_FUNCT3		0x7
2774559860eSchristos #define OP_SH_FUNCT3		12
2788dffb485Schristos #define OP_MASK_FUNCT7		0x7fU
2794559860eSchristos #define OP_SH_FUNCT7		25
2804559860eSchristos #define OP_MASK_FUNCT2		0x3
2814559860eSchristos #define OP_SH_FUNCT2		25
2824559860eSchristos 
283796c32c9Schristos /* RVC fields.  */
284796c32c9Schristos 
2854559860eSchristos #define OP_MASK_OP2		0x3
2864559860eSchristos #define OP_SH_OP2		0
2874559860eSchristos 
288796c32c9Schristos #define OP_MASK_CRS2		0x1f
289796c32c9Schristos #define OP_SH_CRS2		2
290796c32c9Schristos #define OP_MASK_CRS1S		0x7
291796c32c9Schristos #define OP_SH_CRS1S		7
292796c32c9Schristos #define OP_MASK_CRS2S		0x7
293796c32c9Schristos #define OP_SH_CRS2S		2
294796c32c9Schristos 
2954559860eSchristos #define OP_MASK_CFUNCT6		0x3f
2964559860eSchristos #define OP_SH_CFUNCT6		10
2974559860eSchristos #define OP_MASK_CFUNCT4		0xf
2984559860eSchristos #define OP_SH_CFUNCT4		12
2994559860eSchristos #define OP_MASK_CFUNCT3		0x7
3004559860eSchristos #define OP_SH_CFUNCT3		13
3014559860eSchristos #define OP_MASK_CFUNCT2		0x3
3024559860eSchristos #define OP_SH_CFUNCT2		5
3034559860eSchristos 
3044b169a6bSchristos /* Scalar crypto fields. */
3054b169a6bSchristos 
3064b169a6bSchristos #define OP_SH_BS        30
3074b169a6bSchristos #define OP_MASK_BS      3
3084b169a6bSchristos #define OP_SH_RNUM      20
3094b169a6bSchristos #define OP_MASK_RNUM    0xf
3104b169a6bSchristos 
3114b169a6bSchristos /* RVV fields.  */
3124b169a6bSchristos 
3134b169a6bSchristos #define OP_MASK_VD		0x1f
3144b169a6bSchristos #define OP_SH_VD		7
3154b169a6bSchristos #define OP_MASK_VS1		0x1f
3164b169a6bSchristos #define OP_SH_VS1		15
3174b169a6bSchristos #define OP_MASK_VS2		0x1f
3184b169a6bSchristos #define OP_SH_VS2		20
3194b169a6bSchristos #define OP_MASK_VIMM		0x1f
3204b169a6bSchristos #define OP_SH_VIMM		15
3214b169a6bSchristos #define OP_MASK_VMASK		0x1
3224b169a6bSchristos #define OP_SH_VMASK		25
3234b169a6bSchristos #define OP_MASK_VFUNCT6		0x3f
3244b169a6bSchristos #define OP_SH_VFUNCT6		26
3254b169a6bSchristos #define OP_MASK_VLMUL		0x7
3264b169a6bSchristos #define OP_SH_VLMUL		0
3274b169a6bSchristos #define OP_MASK_VSEW		0x7
3284b169a6bSchristos #define OP_SH_VSEW		3
3294b169a6bSchristos #define OP_MASK_VTA		0x1
3304b169a6bSchristos #define OP_SH_VTA		6
3314b169a6bSchristos #define OP_MASK_VMA		0x1
3324b169a6bSchristos #define OP_SH_VMA		7
3334b169a6bSchristos #define OP_MASK_VWD		0x1
3344b169a6bSchristos #define OP_SH_VWD		26
3354b169a6bSchristos 
336*aab831ceSchristos #define OP_MASK_XTHEADVLMUL	0x3
337*aab831ceSchristos #define OP_SH_XTHEADVLMUL	0
338*aab831ceSchristos #define OP_MASK_XTHEADVSEW	0x7
339*aab831ceSchristos #define OP_SH_XTHEADVSEW	2
340*aab831ceSchristos #define OP_MASK_XTHEADVEDIV	0x3
341*aab831ceSchristos #define OP_SH_XTHEADVEDIV	5
342*aab831ceSchristos #define OP_MASK_XTHEADVTYPE_RES	0xf
343*aab831ceSchristos #define OP_SH_XTHEADVTYPE_RES	7
344*aab831ceSchristos 
345*aab831ceSchristos /* Zc fields.  */
346*aab831ceSchristos #define OP_MASK_REG_LIST	0xf
347*aab831ceSchristos #define OP_SH_REG_LIST		4
348*aab831ceSchristos #define ZCMP_SP_ALIGNMENT	16
349*aab831ceSchristos 
3504b169a6bSchristos #define NVECR 32
3514b169a6bSchristos #define NVECM 1
3524b169a6bSchristos 
353*aab831ceSchristos /* SiFive fields.  */
354*aab831ceSchristos #define OP_MASK_XSO2            0x3
355*aab831ceSchristos #define OP_SH_XSO2              26
356*aab831ceSchristos #define OP_MASK_XSO1            0x1
357*aab831ceSchristos #define OP_SH_XSO1              26
358*aab831ceSchristos 
359796c32c9Schristos /* ABI names for selected x-registers.  */
360796c32c9Schristos 
361796c32c9Schristos #define X_RA 1
362796c32c9Schristos #define X_SP 2
363796c32c9Schristos #define X_GP 3
364796c32c9Schristos #define X_TP 4
365796c32c9Schristos #define X_T0 5
366796c32c9Schristos #define X_T1 6
367796c32c9Schristos #define X_T2 7
368*aab831ceSchristos #define X_S0 8
369*aab831ceSchristos #define X_S1 9
370*aab831ceSchristos #define X_S2 18
371*aab831ceSchristos #define X_S10 26
372*aab831ceSchristos #define X_S11 27
373796c32c9Schristos #define X_T3 28
374796c32c9Schristos 
375796c32c9Schristos #define NGPR 32
376796c32c9Schristos #define NFPR 32
377796c32c9Schristos 
3784559860eSchristos /* These fake label defines are use by both the assembler, and
3794559860eSchristos    libopcodes.  The assembler uses this when it needs to generate a fake
3804559860eSchristos    label, and libopcodes uses it to hide the fake labels in its output.  */
3814559860eSchristos #define RISCV_FAKE_LABEL_NAME ".L0 "
3824559860eSchristos #define RISCV_FAKE_LABEL_CHAR ' '
3834559860eSchristos 
384796c32c9Schristos /* Replace bits MASK << SHIFT of STRUCT with the equivalent bits in
385796c32c9Schristos    VALUE << SHIFT.  VALUE is evaluated exactly once.  */
386796c32c9Schristos #define INSERT_BITS(STRUCT, VALUE, MASK, SHIFT) \
387796c32c9Schristos   (STRUCT) = (((STRUCT) & ~((insn_t)(MASK) << (SHIFT))) \
388796c32c9Schristos 	      | ((insn_t)((VALUE) & (MASK)) << (SHIFT)))
389796c32c9Schristos 
390796c32c9Schristos /* Extract bits MASK << SHIFT from STRUCT and shift them right
391796c32c9Schristos    SHIFT places.  */
392796c32c9Schristos #define EXTRACT_BITS(STRUCT, MASK, SHIFT) \
393796c32c9Schristos   (((STRUCT) >> (SHIFT)) & (MASK))
394796c32c9Schristos 
395796c32c9Schristos /* Extract the operand given by FIELD from integer INSN.  */
396796c32c9Schristos #define EXTRACT_OPERAND(FIELD, INSN) \
397*aab831ceSchristos   ((unsigned int) EXTRACT_BITS ((INSN), OP_MASK_##FIELD, OP_SH_##FIELD))
398796c32c9Schristos 
3994b169a6bSchristos /* Extract an unsigned immediate operand on position s with n bits.  */
4004b169a6bSchristos #define EXTRACT_U_IMM(n, s, l) \
4014b169a6bSchristos   RV_X (l, s, n)
4024b169a6bSchristos 
4034b169a6bSchristos /* Extract an signed immediate operand on position s with n bits.  */
4044b169a6bSchristos #define EXTRACT_S_IMM(n, s, l) \
4054b169a6bSchristos   RV_X_SIGNED (l, s, n)
4064b169a6bSchristos 
4074b169a6bSchristos /* Validate that unsigned n-bit immediate is within bounds.  */
4084b169a6bSchristos #define VALIDATE_U_IMM(v, n) \
4094b169a6bSchristos   ((unsigned long) v < (1UL << n))
4104b169a6bSchristos 
4114b169a6bSchristos /* Validate that signed n-bit immediate is within bounds.  */
4124b169a6bSchristos #define VALIDATE_S_IMM(v, n) \
4134b169a6bSchristos   (v < (long) (1UL << (n-1)) && v >= -(offsetT) (1UL << (n-1)))
4144b169a6bSchristos 
4154559860eSchristos /* The maximal number of subset can be required.  */
4164559860eSchristos #define MAX_SUBSET_NUM 4
4174559860eSchristos 
4188dffb485Schristos /* All RISC-V instructions belong to at least one of these classes.  */
4198dffb485Schristos enum riscv_insn_class
4208dffb485Schristos {
4218dffb485Schristos   INSN_CLASS_NONE,
4228dffb485Schristos 
4238dffb485Schristos   INSN_CLASS_I,
4248dffb485Schristos   INSN_CLASS_C,
4258dffb485Schristos   INSN_CLASS_M,
4268dffb485Schristos   INSN_CLASS_F,
4278dffb485Schristos   INSN_CLASS_D,
4288dffb485Schristos   INSN_CLASS_Q,
4294b169a6bSchristos   INSN_CLASS_F_AND_C,
4304b169a6bSchristos   INSN_CLASS_D_AND_C,
431*aab831ceSchristos   INSN_CLASS_ZICOND,
4324b169a6bSchristos   INSN_CLASS_ZICSR,
4334b169a6bSchristos   INSN_CLASS_ZIFENCEI,
434*aab831ceSchristos   INSN_CLASS_ZIHINTNTL,
435*aab831ceSchristos   INSN_CLASS_ZIHINTNTL_AND_C,
4364b169a6bSchristos   INSN_CLASS_ZIHINTPAUSE,
4374b169a6bSchristos   INSN_CLASS_ZMMUL,
438*aab831ceSchristos   INSN_CLASS_ZAAMO,
439*aab831ceSchristos   INSN_CLASS_ZALRSC,
4404b169a6bSchristos   INSN_CLASS_ZAWRS,
4414b169a6bSchristos   INSN_CLASS_F_INX,
4424b169a6bSchristos   INSN_CLASS_D_INX,
4434b169a6bSchristos   INSN_CLASS_Q_INX,
4444b169a6bSchristos   INSN_CLASS_ZFH_INX,
4454b169a6bSchristos   INSN_CLASS_ZFHMIN,
4464b169a6bSchristos   INSN_CLASS_ZFHMIN_INX,
4474b169a6bSchristos   INSN_CLASS_ZFHMIN_AND_D_INX,
4484b169a6bSchristos   INSN_CLASS_ZFHMIN_AND_Q_INX,
449*aab831ceSchristos   INSN_CLASS_ZFA,
450*aab831ceSchristos   INSN_CLASS_D_AND_ZFA,
451*aab831ceSchristos   INSN_CLASS_Q_AND_ZFA,
452*aab831ceSchristos   INSN_CLASS_ZFH_AND_ZFA,
453*aab831ceSchristos   INSN_CLASS_ZFH_OR_ZVFH_AND_ZFA,
4544b169a6bSchristos   INSN_CLASS_ZBA,
4554b169a6bSchristos   INSN_CLASS_ZBB,
4564b169a6bSchristos   INSN_CLASS_ZBC,
4574b169a6bSchristos   INSN_CLASS_ZBS,
4584b169a6bSchristos   INSN_CLASS_ZBKB,
4594b169a6bSchristos   INSN_CLASS_ZBKC,
4604b169a6bSchristos   INSN_CLASS_ZBKX,
4614b169a6bSchristos   INSN_CLASS_ZKND,
4624b169a6bSchristos   INSN_CLASS_ZKNE,
4634b169a6bSchristos   INSN_CLASS_ZKNH,
4644b169a6bSchristos   INSN_CLASS_ZKSED,
4654b169a6bSchristos   INSN_CLASS_ZKSH,
4664b169a6bSchristos   INSN_CLASS_ZBB_OR_ZBKB,
4674b169a6bSchristos   INSN_CLASS_ZBC_OR_ZBKC,
4684b169a6bSchristos   INSN_CLASS_ZKND_OR_ZKNE,
4694b169a6bSchristos   INSN_CLASS_V,
4704b169a6bSchristos   INSN_CLASS_ZVEF,
471*aab831ceSchristos   INSN_CLASS_ZVBB,
472*aab831ceSchristos   INSN_CLASS_ZVBC,
473*aab831ceSchristos   INSN_CLASS_ZVKB,
474*aab831ceSchristos   INSN_CLASS_ZVKG,
475*aab831ceSchristos   INSN_CLASS_ZVKNED,
476*aab831ceSchristos   INSN_CLASS_ZVKNHA_OR_ZVKNHB,
477*aab831ceSchristos   INSN_CLASS_ZVKSED,
478*aab831ceSchristos   INSN_CLASS_ZVKSH,
479*aab831ceSchristos   INSN_CLASS_ZCB,
480*aab831ceSchristos   INSN_CLASS_ZCB_AND_ZBA,
481*aab831ceSchristos   INSN_CLASS_ZCB_AND_ZBB,
482*aab831ceSchristos   INSN_CLASS_ZCB_AND_ZMMUL,
483*aab831ceSchristos   INSN_CLASS_ZCMP,
4844b169a6bSchristos   INSN_CLASS_SVINVAL,
4854b169a6bSchristos   INSN_CLASS_ZICBOM,
4864b169a6bSchristos   INSN_CLASS_ZICBOP,
4874b169a6bSchristos   INSN_CLASS_ZICBOZ,
488*aab831ceSchristos   INSN_CLASS_ZABHA,
4894b169a6bSchristos   INSN_CLASS_H,
490*aab831ceSchristos   INSN_CLASS_XCVMAC,
491*aab831ceSchristos   INSN_CLASS_XCVALU,
4924b169a6bSchristos   INSN_CLASS_XTHEADBA,
4934b169a6bSchristos   INSN_CLASS_XTHEADBB,
4944b169a6bSchristos   INSN_CLASS_XTHEADBS,
4954b169a6bSchristos   INSN_CLASS_XTHEADCMO,
4964b169a6bSchristos   INSN_CLASS_XTHEADCONDMOV,
4974b169a6bSchristos   INSN_CLASS_XTHEADFMEMIDX,
4984b169a6bSchristos   INSN_CLASS_XTHEADFMV,
4994b169a6bSchristos   INSN_CLASS_XTHEADINT,
5004b169a6bSchristos   INSN_CLASS_XTHEADMAC,
5014b169a6bSchristos   INSN_CLASS_XTHEADMEMIDX,
5024b169a6bSchristos   INSN_CLASS_XTHEADMEMPAIR,
5034b169a6bSchristos   INSN_CLASS_XTHEADSYNC,
504*aab831ceSchristos   INSN_CLASS_XTHEADVECTOR,
505*aab831ceSchristos   INSN_CLASS_XTHEADZVAMO,
506*aab831ceSchristos   INSN_CLASS_XVENTANACONDOPS,
507*aab831ceSchristos   INSN_CLASS_XSFVCP,
5088dffb485Schristos };
5098dffb485Schristos 
510796c32c9Schristos /* This structure holds information for a particular instruction.  */
511796c32c9Schristos struct riscv_opcode
512796c32c9Schristos {
513796c32c9Schristos   /* The name of the instruction.  */
514796c32c9Schristos   const char *name;
5154b169a6bSchristos 
5164559860eSchristos   /* The requirement of xlen for the instruction, 0 if no requirement.  */
5174559860eSchristos   unsigned xlen_requirement;
5184b169a6bSchristos 
5198dffb485Schristos   /* Class to which this instruction belongs.  Used to decide whether or
5208dffb485Schristos      not this instruction is legal in the current -march context.  */
5218dffb485Schristos   enum riscv_insn_class insn_class;
5224b169a6bSchristos 
523796c32c9Schristos   /* A string describing the arguments for this instruction.  */
524796c32c9Schristos   const char *args;
5254b169a6bSchristos 
526796c32c9Schristos   /* The basic opcode for the instruction.  When assembling, this
527796c32c9Schristos      opcode is modified by the arguments to produce the actual opcode
528796c32c9Schristos      that is used.  If pinfo is INSN_MACRO, then this is 0.  */
529796c32c9Schristos   insn_t match;
5304b169a6bSchristos 
531796c32c9Schristos   /* If pinfo is not INSN_MACRO, then this is a bit mask for the
532796c32c9Schristos      relevant portions of the opcode when disassembling.  If the
533796c32c9Schristos      actual opcode anded with the match field equals the opcode field,
534796c32c9Schristos      then we have found the correct instruction.  If pinfo is
535796c32c9Schristos      INSN_MACRO, then this field is the macro identifier.  */
536796c32c9Schristos   insn_t mask;
5374b169a6bSchristos 
538796c32c9Schristos   /* A function to determine if a word corresponds to this instruction.
539796c32c9Schristos      Usually, this computes ((word & mask) == match).  */
540796c32c9Schristos   int (*match_func) (const struct riscv_opcode *op, insn_t word);
5414b169a6bSchristos 
542796c32c9Schristos   /* For a macro, this is INSN_MACRO.  Otherwise, it is a collection
543796c32c9Schristos      of bits describing the instruction, notably any relevant hazard
544796c32c9Schristos      information.  */
545796c32c9Schristos   unsigned long pinfo;
546796c32c9Schristos };
547796c32c9Schristos 
548796c32c9Schristos /* Instruction is a simple alias (e.g. "mv" for "addi").  */
549796c32c9Schristos #define	INSN_ALIAS		0x00000001
5504559860eSchristos 
5514559860eSchristos /* These are for setting insn_info fields.
5524559860eSchristos 
5534559860eSchristos    Nonbranch is the default.  Noninsn is used only if there is no match.
5544559860eSchristos    There are no condjsr or dref2 instructions.  So that leaves condbranch,
5554559860eSchristos    branch, jsr, and dref that we need to handle here, encoded in 3 bits.  */
5564559860eSchristos #define INSN_TYPE		0x0000000e
5574559860eSchristos 
5584559860eSchristos /* Instruction is an unconditional branch.  */
5594559860eSchristos #define INSN_BRANCH		0x00000002
5604559860eSchristos /* Instruction is a conditional branch.  */
5614559860eSchristos #define INSN_CONDBRANCH		0x00000004
5624559860eSchristos /* Instruction is a jump to subroutine.  */
5634559860eSchristos #define INSN_JSR		0x00000006
5644559860eSchristos /* Instruction is a data reference.  */
5654559860eSchristos #define INSN_DREF		0x00000008
5664b169a6bSchristos /* Instruction is allowed when eew >= 64.  */
5674b169a6bSchristos #define INSN_V_EEW64		0x10000000
5684559860eSchristos 
5694559860eSchristos /* We have 5 data reference sizes, which we can encode in 3 bits.  */
5704559860eSchristos #define INSN_DATA_SIZE		0x00000070
5714559860eSchristos #define INSN_DATA_SIZE_SHIFT	4
5724559860eSchristos #define INSN_1_BYTE		0x00000010
5734559860eSchristos #define INSN_2_BYTE		0x00000020
5744559860eSchristos #define INSN_4_BYTE		0x00000030
5754559860eSchristos #define INSN_8_BYTE		0x00000040
5764559860eSchristos #define INSN_16_BYTE		0x00000050
5774559860eSchristos 
578796c32c9Schristos /* Instruction is actually a macro.  It should be ignored by the
579796c32c9Schristos    disassembler, and requires special treatment by the assembler.  */
580796c32c9Schristos #define INSN_MACRO		0xffffffff
581796c32c9Schristos 
5824b169a6bSchristos /* This is a list of macro expanded instructions.  */
583796c32c9Schristos enum
584796c32c9Schristos {
585796c32c9Schristos   M_LA,
586796c32c9Schristos   M_LLA,
587*aab831ceSchristos   M_LGA,
588796c32c9Schristos   M_LA_TLS_GD,
589796c32c9Schristos   M_LA_TLS_IE,
590*aab831ceSchristos   M_Lx,
591*aab831ceSchristos   M_FLx,
592*aab831ceSchristos   M_Sx_FSx,
593796c32c9Schristos   M_CALL,
594796c32c9Schristos   M_J,
595796c32c9Schristos   M_LI,
596*aab831ceSchristos   M_EXTH,
5974b169a6bSchristos   M_ZEXTW,
5984b169a6bSchristos   M_SEXTB,
5994b169a6bSchristos   M_VMSGE,
600796c32c9Schristos   M_NUM_MACROS
601796c32c9Schristos };
602796c32c9Schristos 
6034b169a6bSchristos /* The mapping symbol states.  */
6044b169a6bSchristos enum riscv_seg_mstate
6054b169a6bSchristos {
6064b169a6bSchristos   MAP_NONE = 0,		/* Must be zero, for seginfo in new sections.  */
6074b169a6bSchristos   MAP_DATA,		/* Data.  */
6084b169a6bSchristos   MAP_INSN,		/* Instructions.  */
6094b169a6bSchristos };
610796c32c9Schristos 
611*aab831ceSchristos #define NRC (4 + 1)     /* Max characters in register names, incl nul.  */
612*aab831ceSchristos 
613*aab831ceSchristos extern const char riscv_gpr_names_numeric[NGPR][NRC];
614*aab831ceSchristos extern const char riscv_gpr_names_abi[NGPR][NRC];
615*aab831ceSchristos extern const char riscv_fpr_names_numeric[NFPR][NRC];
616*aab831ceSchristos extern const char riscv_fpr_names_abi[NFPR][NRC];
6174b169a6bSchristos extern const char * const riscv_rm[8];
6184b169a6bSchristos extern const char * const riscv_pred_succ[16];
619*aab831ceSchristos extern const char riscv_vecr_names_numeric[NVECR][NRC];
620*aab831ceSchristos extern const char riscv_vecm_names_numeric[NVECM][NRC];
6214b169a6bSchristos extern const char * const riscv_vsew[8];
6224b169a6bSchristos extern const char * const riscv_vlmul[8];
6234b169a6bSchristos extern const char * const riscv_vta[2];
6244b169a6bSchristos extern const char * const riscv_vma[2];
625*aab831ceSchristos extern const char * const riscv_th_vlen[4];
626*aab831ceSchristos extern const char * const riscv_th_vediv[4];
627*aab831ceSchristos extern const char * const riscv_fli_symval[32];
628*aab831ceSchristos extern const float riscv_fli_numval[32];
629796c32c9Schristos 
630796c32c9Schristos extern const struct riscv_opcode riscv_opcodes[];
6314559860eSchristos extern const struct riscv_opcode riscv_insn_types[];
632796c32c9Schristos 
633*aab831ceSchristos extern unsigned int riscv_get_sp_base (insn_t, unsigned int);
634*aab831ceSchristos 
635796c32c9Schristos #endif /* _RISCV_H_ */
636