Rizin
unix-like reverse engineering framework and cli tools
riscv.h File Reference
#include "riscv-opc.h"
#include <stdlib.h>
#include <stdint.h>

Go to the source code of this file.

Classes

struct  riscv_opcode
 

Macros

#define RVC_JUMP_BITS   11
 
#define RVC_JUMP_REACH   ((1ULL << RVC_JUMP_BITS) * RISCV_JUMP_ALIGN)
 
#define RVC_BRANCH_BITS   8
 
#define RVC_BRANCH_REACH   ((1ULL << RVC_BRANCH_BITS) * RISCV_BRANCH_ALIGN)
 
#define RV_X(x, s, n)   (((x) >> (s)) & ((1 << (n)) - 1))
 
#define RV_IMM_SIGN(x)   (-(((x) >> 31) & 1))
 
#define EXTRACT_ITYPE_IMM(x)    (RV_X(x, 20, 12) | (RV_IMM_SIGN(x) << 12))
 
#define EXTRACT_STYPE_IMM(x)    (RV_X(x, 7, 5) | (RV_X(x, 25, 7) << 5) | (RV_IMM_SIGN(x) << 12))
 
#define EXTRACT_SBTYPE_IMM(x)    ((RV_X(x, 8, 4) << 1) | (RV_X(x, 25, 6) << 5) | (RV_X(x, 7, 1) << 11) | (RV_IMM_SIGN(x) << 12))
 
#define EXTRACT_UTYPE_IMM(x)    ((RV_X(x, 12, 20) << 12) | (RV_IMM_SIGN(x) << 32))
 
#define EXTRACT_UJTYPE_IMM(x)    ((RV_X(x, 21, 10) << 1) | (RV_X(x, 20, 1) << 11) | (RV_X(x, 12, 8) << 12) | (RV_IMM_SIGN(x) << 20))
 
#define EXTRACT_RVC_IMM(x)    (RV_X(x, 2, 5) | (-RV_X(x, 12, 1) << 5))
 
#define EXTRACT_RVC_LUI_IMM(x)    (EXTRACT_RVC_IMM (x) << RISCV_IMM_BITS)
 
#define EXTRACT_RVC_SIMM3(x)    (RV_X(x, 10, 2) | (-RV_X(x, 12, 1) << 2))
 
#define EXTRACT_RVC_ADDI4SPN_IMM(x)    ((RV_X(x, 6, 1) << 2) | (RV_X(x, 5, 1) << 3) | (RV_X(x, 11, 2) << 4) | (RV_X(x, 7, 4) << 6))
 
#define EXTRACT_RVC_ADDI16SP_IMM(x)    ((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))
 
#define EXTRACT_RVC_LW_IMM(x)    ((RV_X(x, 6, 1) << 2) | (RV_X(x, 10, 3) << 3) | (RV_X(x, 5, 1) << 6))
 
#define EXTRACT_RVC_LD_IMM(x)    ((RV_X(x, 10, 3) << 3) | (RV_X(x, 5, 2) << 6))
 
#define EXTRACT_RVC_LWSP_IMM(x)    ((RV_X(x, 4, 3) << 2) | (RV_X(x, 12, 1) << 5) | (RV_X(x, 2, 2) << 6))
 
#define EXTRACT_RVC_LDSP_IMM(x)    ((RV_X(x, 5, 2) << 3) | (RV_X(x, 12, 1) << 5) | (RV_X(x, 2, 3) << 6))
 
#define EXTRACT_RVC_SWSP_IMM(x)    ((RV_X(x, 9, 4) << 2) | (RV_X(x, 7, 2) << 6))
 
#define EXTRACT_RVC_SDSP_IMM(x)    ((RV_X(x, 10, 3) << 3) | (RV_X(x, 7, 3) << 6))
 
#define EXTRACT_RVC_B_IMM(x)    ((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))
 
#define EXTRACT_RVC_J_IMM(x)    ((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))
 
#define ENCODE_ITYPE_IMM(x)    (RV_X(x, 0, 12) << 20)
 
#define ENCODE_STYPE_IMM(x)    ((RV_X(x, 0, 5) << 7) | (RV_X(x, 5, 7) << 25))
 
#define ENCODE_SBTYPE_IMM(x)    ((RV_X(x, 1, 4) << 8) | (RV_X(x, 5, 6) << 25) | (RV_X(x, 11, 1) << 7) | (RV_X(x, 12, 1) << 31))
 
#define ENCODE_UTYPE_IMM(x)    (RV_X(x, 12, 20) << 12)
 
#define ENCODE_UJTYPE_IMM(x)    ((RV_X(x, 1, 10) << 21) | (RV_X(x, 11, 1) << 20) | (RV_X(x, 12, 8) << 12) | (RV_X(x, 20, 1) << 31))
 
#define ENCODE_RVC_IMM(x)    ((RV_X(x, 0, 5) << 2) | (RV_X(x, 5, 1) << 12))
 
#define ENCODE_RVC_LUI_IMM(x)    ENCODE_RVC_IMM ((x) >> RISCV_IMM_BITS)
 
#define ENCODE_RVC_SIMM3(x)    (RV_X(x, 0, 3) << 10)
 
#define ENCODE_RVC_ADDI4SPN_IMM(x)    ((RV_X(x, 2, 1) << 6) | (RV_X(x, 3, 1) << 5) | (RV_X(x, 4, 2) << 11) | (RV_X(x, 6, 4) << 7))
 
#define ENCODE_RVC_ADDI16SP_IMM(x)    ((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))
 
#define ENCODE_RVC_LW_IMM(x)    ((RV_X(x, 2, 1) << 6) | (RV_X(x, 3, 3) << 10) | (RV_X(x, 6, 1) << 5))
 
#define ENCODE_RVC_LD_IMM(x)    ((RV_X(x, 3, 3) << 10) | (RV_X(x, 6, 2) << 5))
 
#define ENCODE_RVC_LWSP_IMM(x)    ((RV_X(x, 2, 3) << 4) | (RV_X(x, 5, 1) << 12) | (RV_X(x, 6, 2) << 2))
 
#define ENCODE_RVC_LDSP_IMM(x)    ((RV_X(x, 3, 2) << 5) | (RV_X(x, 5, 1) << 12) | (RV_X(x, 6, 3) << 2))
 
#define ENCODE_RVC_SWSP_IMM(x)    ((RV_X(x, 2, 4) << 9) | (RV_X(x, 6, 2) << 7))
 
#define ENCODE_RVC_SDSP_IMM(x)    ((RV_X(x, 3, 3) << 10) | (RV_X(x, 6, 3) << 7))
 
#define ENCODE_RVC_B_IMM(x)    ((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))
 
#define ENCODE_RVC_J_IMM(x)    ((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))
 
#define VALID_ITYPE_IMM(x)   (EXTRACT_ITYPE_IMM(ENCODE_ITYPE_IMM(x)) == (x))
 
#define VALID_STYPE_IMM(x)   (EXTRACT_STYPE_IMM(ENCODE_STYPE_IMM(x)) == (x))
 
#define VALID_SBTYPE_IMM(x)   (EXTRACT_SBTYPE_IMM(ENCODE_SBTYPE_IMM(x)) == (x))
 
#define VALID_UTYPE_IMM(x)   (EXTRACT_UTYPE_IMM(ENCODE_UTYPE_IMM(x)) == (x))
 
#define VALID_UJTYPE_IMM(x)   (EXTRACT_UJTYPE_IMM(ENCODE_UJTYPE_IMM(x)) == (x))
 
#define VALID_RVC_IMM(x)   (EXTRACT_RVC_IMM(ENCODE_RVC_IMM(x)) == (x))
 
#define VALID_RVC_LUI_IMM(x)   (EXTRACT_RVC_LUI_IMM(ENCODE_RVC_LUI_IMM(x)) == (x))
 
#define VALID_RVC_SIMM3(x)   (EXTRACT_RVC_SIMM3(ENCODE_RVC_SIMM3(x)) == (x))
 
#define VALID_RVC_ADDI4SPN_IMM(x)   (EXTRACT_RVC_ADDI4SPN_IMM(ENCODE_RVC_ADDI4SPN_IMM(x)) == (x))
 
#define VALID_RVC_ADDI16SP_IMM(x)   (EXTRACT_RVC_ADDI16SP_IMM(ENCODE_RVC_ADDI16SP_IMM(x)) == (x))
 
#define VALID_RVC_LW_IMM(x)   (EXTRACT_RVC_LW_IMM(ENCODE_RVC_LW_IMM(x)) == (x))
 
#define VALID_RVC_LD_IMM(x)   (EXTRACT_RVC_LD_IMM(ENCODE_RVC_LD_IMM(x)) == (x))
 
#define VALID_RVC_LWSP_IMM(x)   (EXTRACT_RVC_LWSP_IMM(ENCODE_RVC_LWSP_IMM(x)) == (x))
 
#define VALID_RVC_LDSP_IMM(x)   (EXTRACT_RVC_LDSP_IMM(ENCODE_RVC_LDSP_IMM(x)) == (x))
 
#define VALID_RVC_SWSP_IMM(x)   (EXTRACT_RVC_SWSP_IMM(ENCODE_RVC_SWSP_IMM(x)) == (x))
 
#define VALID_RVC_SDSP_IMM(x)   (EXTRACT_RVC_SDSP_IMM(ENCODE_RVC_SDSP_IMM(x)) == (x))
 
#define VALID_RVC_B_IMM(x)   (EXTRACT_RVC_B_IMM(ENCODE_RVC_B_IMM(x)) == (x))
 
#define VALID_RVC_J_IMM(x)   (EXTRACT_RVC_J_IMM(ENCODE_RVC_J_IMM(x)) == (x))
 
#define RISCV_RTYPE(insn, rd, rs1, rs2)    ((MATCH_ ## insn) | ((rd) << OP_SH_RD) | ((rs1) << OP_SH_RS1) | ((rs2) << OP_SH_RS2))
 
#define RISCV_ITYPE(insn, rd, rs1, imm)    ((MATCH_ ## insn) | ((rd) << OP_SH_RD) | ((rs1) << OP_SH_RS1) | ENCODE_ITYPE_IMM(imm))
 
#define RISCV_STYPE(insn, rs1, rs2, imm)    ((MATCH_ ## insn) | ((rs1) << OP_SH_RS1) | ((rs2) << OP_SH_RS2) | ENCODE_STYPE_IMM(imm))
 
#define RISCV_SBTYPE(insn, rs1, rs2, target)    ((MATCH_ ## insn) | ((rs1) << OP_SH_RS1) | ((rs2) << OP_SH_RS2) | ENCODE_SBTYPE_IMM(target))
 
#define RISCV_UTYPE(insn, rd, bigimm)    ((MATCH_ ## insn) | ((rd) << OP_SH_RD) | ENCODE_UTYPE_IMM(bigimm))
 
#define RISCV_UJTYPE(insn, rd, target)    ((MATCH_ ## insn) | ((rd) << OP_SH_RD) | ENCODE_UJTYPE_IMM(target))
 
#define RISCV_NOP   RISCV_ITYPE(ADDI, 0, 0, 0)
 
#define RVC_NOP   MATCH_C_ADDI
 
#define RISCV_CONST_HIGH_PART(VALUE)    (((VALUE) + (RISCV_IMM_REACH/2)) & ~(RISCV_IMM_REACH-1))
 
#define RISCV_CONST_LOW_PART(VALUE)   ((VALUE) - RISCV_CONST_HIGH_PART (VALUE))
 
#define RISCV_PCREL_HIGH_PART(VALUE, PC)   RISCV_CONST_HIGH_PART((VALUE) - (PC))
 
#define RISCV_PCREL_LOW_PART(VALUE, PC)   RISCV_CONST_LOW_PART((VALUE) - (PC))
 
#define RISCV_JUMP_BITS   RISCV_BIGIMM_BITS
 
#define RISCV_JUMP_ALIGN_BITS   1
 
#define RISCV_JUMP_ALIGN   (1 << RISCV_JUMP_ALIGN_BITS)
 
#define RISCV_JUMP_REACH   ((1ULL << RISCV_JUMP_BITS) * RISCV_JUMP_ALIGN)
 
#define RISCV_IMM_BITS   12
 
#define RISCV_BIGIMM_BITS   (32 - RISCV_IMM_BITS)
 
#define RISCV_IMM_REACH   (1LL << RISCV_IMM_BITS)
 
#define RISCV_BIGIMM_REACH   (1LL << RISCV_BIGIMM_BITS)
 
#define RISCV_RVC_IMM_REACH   (1LL << 6)
 
#define RISCV_BRANCH_BITS   RISCV_IMM_BITS
 
#define RISCV_BRANCH_ALIGN_BITS   RISCV_JUMP_ALIGN_BITS
 
#define RISCV_BRANCH_ALIGN   (1 << RISCV_BRANCH_ALIGN_BITS)
 
#define RISCV_BRANCH_REACH   (RISCV_IMM_REACH * RISCV_BRANCH_ALIGN)
 
#define OP_MASK_OP   0x7f
 
#define OP_SH_OP   0
 
#define OP_MASK_RS2   0x1f
 
#define OP_SH_RS2   20
 
#define OP_MASK_RS1   0x1f
 
#define OP_SH_RS1   15
 
#define OP_MASK_RS3   0x1f
 
#define OP_SH_RS3   27
 
#define OP_MASK_RD   0x1f
 
#define OP_SH_RD   7
 
#define OP_MASK_SHAMT   0x3f
 
#define OP_SH_SHAMT   20
 
#define OP_MASK_SHAMTW   0x1f
 
#define OP_SH_SHAMTW   20
 
#define OP_MASK_RM   0x7
 
#define OP_SH_RM   12
 
#define OP_MASK_PRED   0xf
 
#define OP_SH_PRED   24
 
#define OP_MASK_SUCC   0xf
 
#define OP_SH_SUCC   20
 
#define OP_MASK_AQ   0x1
 
#define OP_SH_AQ   26
 
#define OP_MASK_RL   0x1
 
#define OP_SH_RL   25
 
#define OP_MASK_CUSTOM_IMM   0x7f
 
#define OP_SH_CUSTOM_IMM   25
 
#define OP_MASK_CSR   0xfff
 
#define OP_SH_CSR   20
 
#define OP_MASK_CRS2   0x1f
 
#define OP_SH_CRS2   2
 
#define OP_MASK_CRS1S   0x7
 
#define OP_SH_CRS1S   7
 
#define OP_MASK_CRS2S   0x7
 
#define OP_SH_CRS2S   2
 
#define X_RA   1
 
#define X_SP   2
 
#define X_GP   3
 
#define X_TP   4
 
#define X_T0   5
 
#define X_T1   6
 
#define X_T2   7
 
#define X_T3   28
 
#define NGPR   32
 
#define NFPR   32
 
#define INSERT_BITS(STRUCT, VALUE, MASK, SHIFT)
 
#define EXTRACT_BITS(STRUCT, MASK, SHIFT)    (((STRUCT) >> (SHIFT)) & (MASK))
 
#define EXTRACT_OPERAND(FIELD, INSN)    EXTRACT_BITS ((INSN), OP_MASK_##FIELD, OP_SH_##FIELD)
 
#define INSN_ALIAS   0x00000001
 
#define INSN_MACRO   0xffffffff
 
#define NUMOPCODES   bfd_riscv_num_opcodes
 

Typedefs

typedef uint64_t insn_t
 

Enumerations

enum  {
  M_LA , M_LLA , M_LA_TLS_GD , M_LA_TLS_IE ,
  M_LB , M_LBU , M_LH , M_LHU ,
  M_LW , M_LWU , M_LD , M_SB ,
  M_SH , M_SW , M_SD , M_FLW ,
  M_FLD , M_FLQ , M_FSW , M_FSD ,
  M_FSQ , M_CALL , M_J , M_LI ,
  M_NUM_MACROS
}
 

Functions

static unsigned int riscv_insn_length (insn_t insn)
 

Variables

static const char *const riscv_rm [8]
 
static const char *const riscv_pred_succ [16]
 

Macro Definition Documentation

◆ ENCODE_ITYPE_IMM

#define ENCODE_ITYPE_IMM (   x)     (RV_X(x, 0, 12) << 20)

Definition at line 104 of file riscv.h.

◆ ENCODE_RVC_ADDI16SP_IMM

#define ENCODE_RVC_ADDI16SP_IMM (   x)     ((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))

Definition at line 122 of file riscv.h.

◆ ENCODE_RVC_ADDI4SPN_IMM

#define ENCODE_RVC_ADDI4SPN_IMM (   x)     ((RV_X(x, 2, 1) << 6) | (RV_X(x, 3, 1) << 5) | (RV_X(x, 4, 2) << 11) | (RV_X(x, 6, 4) << 7))

Definition at line 120 of file riscv.h.

◆ ENCODE_RVC_B_IMM

#define ENCODE_RVC_B_IMM (   x)     ((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))

Definition at line 136 of file riscv.h.

◆ ENCODE_RVC_IMM

#define ENCODE_RVC_IMM (   x)     ((RV_X(x, 0, 5) << 2) | (RV_X(x, 5, 1) << 12))

Definition at line 114 of file riscv.h.

◆ ENCODE_RVC_J_IMM

#define ENCODE_RVC_J_IMM (   x)     ((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))

Definition at line 138 of file riscv.h.

◆ ENCODE_RVC_LD_IMM

#define ENCODE_RVC_LD_IMM (   x)     ((RV_X(x, 3, 3) << 10) | (RV_X(x, 6, 2) << 5))

Definition at line 126 of file riscv.h.

◆ ENCODE_RVC_LDSP_IMM

#define ENCODE_RVC_LDSP_IMM (   x)     ((RV_X(x, 3, 2) << 5) | (RV_X(x, 5, 1) << 12) | (RV_X(x, 6, 3) << 2))

Definition at line 130 of file riscv.h.

◆ ENCODE_RVC_LUI_IMM

#define ENCODE_RVC_LUI_IMM (   x)     ENCODE_RVC_IMM ((x) >> RISCV_IMM_BITS)

Definition at line 116 of file riscv.h.

◆ ENCODE_RVC_LW_IMM

#define ENCODE_RVC_LW_IMM (   x)     ((RV_X(x, 2, 1) << 6) | (RV_X(x, 3, 3) << 10) | (RV_X(x, 6, 1) << 5))

Definition at line 124 of file riscv.h.

◆ ENCODE_RVC_LWSP_IMM

#define ENCODE_RVC_LWSP_IMM (   x)     ((RV_X(x, 2, 3) << 4) | (RV_X(x, 5, 1) << 12) | (RV_X(x, 6, 2) << 2))

Definition at line 128 of file riscv.h.

◆ ENCODE_RVC_SDSP_IMM

#define ENCODE_RVC_SDSP_IMM (   x)     ((RV_X(x, 3, 3) << 10) | (RV_X(x, 6, 3) << 7))

Definition at line 134 of file riscv.h.

◆ ENCODE_RVC_SIMM3

#define ENCODE_RVC_SIMM3 (   x)     (RV_X(x, 0, 3) << 10)

Definition at line 118 of file riscv.h.

◆ ENCODE_RVC_SWSP_IMM

#define ENCODE_RVC_SWSP_IMM (   x)     ((RV_X(x, 2, 4) << 9) | (RV_X(x, 6, 2) << 7))

Definition at line 132 of file riscv.h.

◆ ENCODE_SBTYPE_IMM

#define ENCODE_SBTYPE_IMM (   x)     ((RV_X(x, 1, 4) << 8) | (RV_X(x, 5, 6) << 25) | (RV_X(x, 11, 1) << 7) | (RV_X(x, 12, 1) << 31))

Definition at line 108 of file riscv.h.

◆ ENCODE_STYPE_IMM

#define ENCODE_STYPE_IMM (   x)     ((RV_X(x, 0, 5) << 7) | (RV_X(x, 5, 7) << 25))

Definition at line 106 of file riscv.h.

◆ ENCODE_UJTYPE_IMM

#define ENCODE_UJTYPE_IMM (   x)     ((RV_X(x, 1, 10) << 21) | (RV_X(x, 11, 1) << 20) | (RV_X(x, 12, 8) << 12) | (RV_X(x, 20, 1) << 31))

Definition at line 112 of file riscv.h.

◆ ENCODE_UTYPE_IMM

#define ENCODE_UTYPE_IMM (   x)     (RV_X(x, 12, 20) << 12)

Definition at line 110 of file riscv.h.

◆ EXTRACT_BITS

#define EXTRACT_BITS (   STRUCT,
  MASK,
  SHIFT 
)     (((STRUCT) >> (SHIFT)) & (MASK))

Definition at line 260 of file riscv.h.

◆ EXTRACT_ITYPE_IMM

#define EXTRACT_ITYPE_IMM (   x)     (RV_X(x, 20, 12) | (RV_IMM_SIGN(x) << 12))

Definition at line 67 of file riscv.h.

◆ EXTRACT_OPERAND

#define EXTRACT_OPERAND (   FIELD,
  INSN 
)     EXTRACT_BITS ((INSN), OP_MASK_##FIELD, OP_SH_##FIELD)

Definition at line 264 of file riscv.h.

◆ EXTRACT_RVC_ADDI16SP_IMM

#define EXTRACT_RVC_ADDI16SP_IMM (   x)     ((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))

Definition at line 85 of file riscv.h.

◆ EXTRACT_RVC_ADDI4SPN_IMM

#define EXTRACT_RVC_ADDI4SPN_IMM (   x)     ((RV_X(x, 6, 1) << 2) | (RV_X(x, 5, 1) << 3) | (RV_X(x, 11, 2) << 4) | (RV_X(x, 7, 4) << 6))

Definition at line 83 of file riscv.h.

◆ EXTRACT_RVC_B_IMM

#define EXTRACT_RVC_B_IMM (   x)     ((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))

Definition at line 99 of file riscv.h.

◆ EXTRACT_RVC_IMM

#define EXTRACT_RVC_IMM (   x)     (RV_X(x, 2, 5) | (-RV_X(x, 12, 1) << 5))

Definition at line 77 of file riscv.h.

◆ EXTRACT_RVC_J_IMM

#define EXTRACT_RVC_J_IMM (   x)     ((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))

Definition at line 101 of file riscv.h.

◆ EXTRACT_RVC_LD_IMM

#define EXTRACT_RVC_LD_IMM (   x)     ((RV_X(x, 10, 3) << 3) | (RV_X(x, 5, 2) << 6))

Definition at line 89 of file riscv.h.

◆ EXTRACT_RVC_LDSP_IMM

#define EXTRACT_RVC_LDSP_IMM (   x)     ((RV_X(x, 5, 2) << 3) | (RV_X(x, 12, 1) << 5) | (RV_X(x, 2, 3) << 6))

Definition at line 93 of file riscv.h.

◆ EXTRACT_RVC_LUI_IMM

#define EXTRACT_RVC_LUI_IMM (   x)     (EXTRACT_RVC_IMM (x) << RISCV_IMM_BITS)

Definition at line 79 of file riscv.h.

◆ EXTRACT_RVC_LW_IMM

#define EXTRACT_RVC_LW_IMM (   x)     ((RV_X(x, 6, 1) << 2) | (RV_X(x, 10, 3) << 3) | (RV_X(x, 5, 1) << 6))

Definition at line 87 of file riscv.h.

◆ EXTRACT_RVC_LWSP_IMM

#define EXTRACT_RVC_LWSP_IMM (   x)     ((RV_X(x, 4, 3) << 2) | (RV_X(x, 12, 1) << 5) | (RV_X(x, 2, 2) << 6))

Definition at line 91 of file riscv.h.

◆ EXTRACT_RVC_SDSP_IMM

#define EXTRACT_RVC_SDSP_IMM (   x)     ((RV_X(x, 10, 3) << 3) | (RV_X(x, 7, 3) << 6))

Definition at line 97 of file riscv.h.

◆ EXTRACT_RVC_SIMM3

#define EXTRACT_RVC_SIMM3 (   x)     (RV_X(x, 10, 2) | (-RV_X(x, 12, 1) << 2))

Definition at line 81 of file riscv.h.

◆ EXTRACT_RVC_SWSP_IMM

#define EXTRACT_RVC_SWSP_IMM (   x)     ((RV_X(x, 9, 4) << 2) | (RV_X(x, 7, 2) << 6))

Definition at line 95 of file riscv.h.

◆ EXTRACT_SBTYPE_IMM

#define EXTRACT_SBTYPE_IMM (   x)     ((RV_X(x, 8, 4) << 1) | (RV_X(x, 25, 6) << 5) | (RV_X(x, 7, 1) << 11) | (RV_IMM_SIGN(x) << 12))

Definition at line 71 of file riscv.h.

◆ EXTRACT_STYPE_IMM

#define EXTRACT_STYPE_IMM (   x)     (RV_X(x, 7, 5) | (RV_X(x, 25, 7) << 5) | (RV_IMM_SIGN(x) << 12))

Definition at line 69 of file riscv.h.

◆ EXTRACT_UJTYPE_IMM

#define EXTRACT_UJTYPE_IMM (   x)     ((RV_X(x, 21, 10) << 1) | (RV_X(x, 20, 1) << 11) | (RV_X(x, 12, 8) << 12) | (RV_IMM_SIGN(x) << 20))

Definition at line 75 of file riscv.h.

◆ EXTRACT_UTYPE_IMM

#define EXTRACT_UTYPE_IMM (   x)     ((RV_X(x, 12, 20) << 12) | (RV_IMM_SIGN(x) << 32))

Definition at line 73 of file riscv.h.

◆ INSERT_BITS

#define INSERT_BITS (   STRUCT,
  VALUE,
  MASK,
  SHIFT 
)
Value:
(STRUCT) = (((STRUCT) & ~((insn_t)(MASK) << (SHIFT))) \
| ((insn_t)((VALUE) & (MASK)) << (SHIFT)))
#define MASK(bits)
Definition: avr_esil.c:58
uint64_t insn_t
Definition: riscv.h:31
#define SHIFT(state_value)
Definition: parser.h:175

Definition at line 254 of file riscv.h.

◆ INSN_ALIAS

#define INSN_ALIAS   0x00000001

Definition at line 297 of file riscv.h.

◆ INSN_MACRO

#define INSN_MACRO   0xffffffff

Definition at line 300 of file riscv.h.

◆ NFPR

#define NFPR   32

Definition at line 250 of file riscv.h.

◆ NGPR

#define NGPR   32

Definition at line 249 of file riscv.h.

◆ NUMOPCODES

#define NUMOPCODES   bfd_riscv_num_opcodes

Definition at line 351 of file riscv.h.

◆ OP_MASK_AQ

#define OP_MASK_AQ   0x1

Definition at line 219 of file riscv.h.

◆ OP_MASK_CRS1S

#define OP_MASK_CRS1S   0x7

Definition at line 233 of file riscv.h.

◆ OP_MASK_CRS2

#define OP_MASK_CRS2   0x1f

Definition at line 231 of file riscv.h.

◆ OP_MASK_CRS2S

#define OP_MASK_CRS2S   0x7

Definition at line 235 of file riscv.h.

◆ OP_MASK_CSR

#define OP_MASK_CSR   0xfff

Definition at line 226 of file riscv.h.

◆ OP_MASK_CUSTOM_IMM

#define OP_MASK_CUSTOM_IMM   0x7f

Definition at line 224 of file riscv.h.

◆ OP_MASK_OP

#define OP_MASK_OP   0x7f

Definition at line 199 of file riscv.h.

◆ OP_MASK_PRED

#define OP_MASK_PRED   0xf

Definition at line 215 of file riscv.h.

◆ OP_MASK_RD

#define OP_MASK_RD   0x1f

Definition at line 207 of file riscv.h.

◆ OP_MASK_RL

#define OP_MASK_RL   0x1

Definition at line 221 of file riscv.h.

◆ OP_MASK_RM

#define OP_MASK_RM   0x7

Definition at line 213 of file riscv.h.

◆ OP_MASK_RS1

#define OP_MASK_RS1   0x1f

Definition at line 203 of file riscv.h.

◆ OP_MASK_RS2

#define OP_MASK_RS2   0x1f

Definition at line 201 of file riscv.h.

◆ OP_MASK_RS3

#define OP_MASK_RS3   0x1f

Definition at line 205 of file riscv.h.

◆ OP_MASK_SHAMT

#define OP_MASK_SHAMT   0x3f

Definition at line 209 of file riscv.h.

◆ OP_MASK_SHAMTW

#define OP_MASK_SHAMTW   0x1f

Definition at line 211 of file riscv.h.

◆ OP_MASK_SUCC

#define OP_MASK_SUCC   0xf

Definition at line 217 of file riscv.h.

◆ OP_SH_AQ

#define OP_SH_AQ   26

Definition at line 220 of file riscv.h.

◆ OP_SH_CRS1S

#define OP_SH_CRS1S   7

Definition at line 234 of file riscv.h.

◆ OP_SH_CRS2

#define OP_SH_CRS2   2

Definition at line 232 of file riscv.h.

◆ OP_SH_CRS2S

#define OP_SH_CRS2S   2

Definition at line 236 of file riscv.h.

◆ OP_SH_CSR

#define OP_SH_CSR   20

Definition at line 227 of file riscv.h.

◆ OP_SH_CUSTOM_IMM

#define OP_SH_CUSTOM_IMM   25

Definition at line 225 of file riscv.h.

◆ OP_SH_OP

#define OP_SH_OP   0

Definition at line 200 of file riscv.h.

◆ OP_SH_PRED

#define OP_SH_PRED   24

Definition at line 216 of file riscv.h.

◆ OP_SH_RD

#define OP_SH_RD   7

Definition at line 208 of file riscv.h.

◆ OP_SH_RL

#define OP_SH_RL   25

Definition at line 222 of file riscv.h.

◆ OP_SH_RM

#define OP_SH_RM   12

Definition at line 214 of file riscv.h.

◆ OP_SH_RS1

#define OP_SH_RS1   15

Definition at line 204 of file riscv.h.

◆ OP_SH_RS2

#define OP_SH_RS2   20

Definition at line 202 of file riscv.h.

◆ OP_SH_RS3

#define OP_SH_RS3   27

Definition at line 206 of file riscv.h.

◆ OP_SH_SHAMT

#define OP_SH_SHAMT   20

Definition at line 210 of file riscv.h.

◆ OP_SH_SHAMTW

#define OP_SH_SHAMTW   20

Definition at line 212 of file riscv.h.

◆ OP_SH_SUCC

#define OP_SH_SUCC   20

Definition at line 218 of file riscv.h.

◆ RISCV_BIGIMM_BITS

#define RISCV_BIGIMM_BITS   (32 - RISCV_IMM_BITS)

Definition at line 188 of file riscv.h.

◆ RISCV_BIGIMM_REACH

#define RISCV_BIGIMM_REACH   (1LL << RISCV_BIGIMM_BITS)

Definition at line 190 of file riscv.h.

◆ RISCV_BRANCH_ALIGN

#define RISCV_BRANCH_ALIGN   (1 << RISCV_BRANCH_ALIGN_BITS)

Definition at line 194 of file riscv.h.

◆ RISCV_BRANCH_ALIGN_BITS

#define RISCV_BRANCH_ALIGN_BITS   RISCV_JUMP_ALIGN_BITS

Definition at line 193 of file riscv.h.

◆ RISCV_BRANCH_BITS

#define RISCV_BRANCH_BITS   RISCV_IMM_BITS

Definition at line 192 of file riscv.h.

◆ RISCV_BRANCH_REACH

#define RISCV_BRANCH_REACH   (RISCV_IMM_REACH * RISCV_BRANCH_ALIGN)

Definition at line 195 of file riscv.h.

◆ RISCV_CONST_HIGH_PART

#define RISCV_CONST_HIGH_PART (   VALUE)     (((VALUE) + (RISCV_IMM_REACH/2)) & ~(RISCV_IMM_REACH-1))

Definition at line 176 of file riscv.h.

◆ RISCV_CONST_LOW_PART

#define RISCV_CONST_LOW_PART (   VALUE)    ((VALUE) - RISCV_CONST_HIGH_PART (VALUE))

Definition at line 178 of file riscv.h.

◆ RISCV_IMM_BITS

#define RISCV_IMM_BITS   12

Definition at line 187 of file riscv.h.

◆ RISCV_IMM_REACH

#define RISCV_IMM_REACH   (1LL << RISCV_IMM_BITS)

Definition at line 189 of file riscv.h.

◆ RISCV_ITYPE

#define RISCV_ITYPE (   insn,
  rd,
  rs1,
  imm 
)     ((MATCH_ ## insn) | ((rd) << OP_SH_RD) | ((rs1) << OP_SH_RS1) | ENCODE_ITYPE_IMM(imm))

Definition at line 162 of file riscv.h.

◆ RISCV_JUMP_ALIGN

#define RISCV_JUMP_ALIGN   (1 << RISCV_JUMP_ALIGN_BITS)

Definition at line 184 of file riscv.h.

◆ RISCV_JUMP_ALIGN_BITS

#define RISCV_JUMP_ALIGN_BITS   1

Definition at line 183 of file riscv.h.

◆ RISCV_JUMP_BITS

#define RISCV_JUMP_BITS   RISCV_BIGIMM_BITS

Definition at line 182 of file riscv.h.

◆ RISCV_JUMP_REACH

#define RISCV_JUMP_REACH   ((1ULL << RISCV_JUMP_BITS) * RISCV_JUMP_ALIGN)

Definition at line 185 of file riscv.h.

◆ RISCV_NOP

#define RISCV_NOP   RISCV_ITYPE(ADDI, 0, 0, 0)

Definition at line 173 of file riscv.h.

◆ RISCV_PCREL_HIGH_PART

#define RISCV_PCREL_HIGH_PART (   VALUE,
  PC 
)    RISCV_CONST_HIGH_PART((VALUE) - (PC))

Definition at line 179 of file riscv.h.

◆ RISCV_PCREL_LOW_PART

#define RISCV_PCREL_LOW_PART (   VALUE,
  PC 
)    RISCV_CONST_LOW_PART((VALUE) - (PC))

Definition at line 180 of file riscv.h.

◆ RISCV_RTYPE

#define RISCV_RTYPE (   insn,
  rd,
  rs1,
  rs2 
)     ((MATCH_ ## insn) | ((rd) << OP_SH_RD) | ((rs1) << OP_SH_RS1) | ((rs2) << OP_SH_RS2))

Definition at line 160 of file riscv.h.

◆ RISCV_RVC_IMM_REACH

#define RISCV_RVC_IMM_REACH   (1LL << 6)

Definition at line 191 of file riscv.h.

◆ RISCV_SBTYPE

#define RISCV_SBTYPE (   insn,
  rs1,
  rs2,
  target 
)     ((MATCH_ ## insn) | ((rs1) << OP_SH_RS1) | ((rs2) << OP_SH_RS2) | ENCODE_SBTYPE_IMM(target))

Definition at line 166 of file riscv.h.

◆ RISCV_STYPE

#define RISCV_STYPE (   insn,
  rs1,
  rs2,
  imm 
)     ((MATCH_ ## insn) | ((rs1) << OP_SH_RS1) | ((rs2) << OP_SH_RS2) | ENCODE_STYPE_IMM(imm))

Definition at line 164 of file riscv.h.

◆ RISCV_UJTYPE

#define RISCV_UJTYPE (   insn,
  rd,
  target 
)     ((MATCH_ ## insn) | ((rd) << OP_SH_RD) | ENCODE_UJTYPE_IMM(target))

Definition at line 170 of file riscv.h.

◆ RISCV_UTYPE

#define RISCV_UTYPE (   insn,
  rd,
  bigimm 
)     ((MATCH_ ## insn) | ((rd) << OP_SH_RD) | ENCODE_UTYPE_IMM(bigimm))

Definition at line 168 of file riscv.h.

◆ RV_IMM_SIGN

#define RV_IMM_SIGN (   x)    (-(((x) >> 31) & 1))

Definition at line 65 of file riscv.h.

◆ RV_X

#define RV_X (   x,
  s,
  n 
)    (((x) >> (s)) & ((1 << (n)) - 1))

Definition at line 64 of file riscv.h.

◆ RVC_BRANCH_BITS

#define RVC_BRANCH_BITS   8

Definition at line 61 of file riscv.h.

◆ RVC_BRANCH_REACH

#define RVC_BRANCH_REACH   ((1ULL << RVC_BRANCH_BITS) * RISCV_BRANCH_ALIGN)

Definition at line 62 of file riscv.h.

◆ RVC_JUMP_BITS

#define RVC_JUMP_BITS   11

Definition at line 58 of file riscv.h.

◆ RVC_JUMP_REACH

#define RVC_JUMP_REACH   ((1ULL << RVC_JUMP_BITS) * RISCV_JUMP_ALIGN)

Definition at line 59 of file riscv.h.

◆ RVC_NOP

#define RVC_NOP   MATCH_C_ADDI

Definition at line 174 of file riscv.h.

◆ VALID_ITYPE_IMM

#define VALID_ITYPE_IMM (   x)    (EXTRACT_ITYPE_IMM(ENCODE_ITYPE_IMM(x)) == (x))

Definition at line 141 of file riscv.h.

◆ VALID_RVC_ADDI16SP_IMM

#define VALID_RVC_ADDI16SP_IMM (   x)    (EXTRACT_RVC_ADDI16SP_IMM(ENCODE_RVC_ADDI16SP_IMM(x)) == (x))

Definition at line 150 of file riscv.h.

◆ VALID_RVC_ADDI4SPN_IMM

#define VALID_RVC_ADDI4SPN_IMM (   x)    (EXTRACT_RVC_ADDI4SPN_IMM(ENCODE_RVC_ADDI4SPN_IMM(x)) == (x))

Definition at line 149 of file riscv.h.

◆ VALID_RVC_B_IMM

#define VALID_RVC_B_IMM (   x)    (EXTRACT_RVC_B_IMM(ENCODE_RVC_B_IMM(x)) == (x))

Definition at line 157 of file riscv.h.

◆ VALID_RVC_IMM

#define VALID_RVC_IMM (   x)    (EXTRACT_RVC_IMM(ENCODE_RVC_IMM(x)) == (x))

Definition at line 146 of file riscv.h.

◆ VALID_RVC_J_IMM

#define VALID_RVC_J_IMM (   x)    (EXTRACT_RVC_J_IMM(ENCODE_RVC_J_IMM(x)) == (x))

Definition at line 158 of file riscv.h.

◆ VALID_RVC_LD_IMM

#define VALID_RVC_LD_IMM (   x)    (EXTRACT_RVC_LD_IMM(ENCODE_RVC_LD_IMM(x)) == (x))

Definition at line 152 of file riscv.h.

◆ VALID_RVC_LDSP_IMM

#define VALID_RVC_LDSP_IMM (   x)    (EXTRACT_RVC_LDSP_IMM(ENCODE_RVC_LDSP_IMM(x)) == (x))

Definition at line 154 of file riscv.h.

◆ VALID_RVC_LUI_IMM

#define VALID_RVC_LUI_IMM (   x)    (EXTRACT_RVC_LUI_IMM(ENCODE_RVC_LUI_IMM(x)) == (x))

Definition at line 147 of file riscv.h.

◆ VALID_RVC_LW_IMM

#define VALID_RVC_LW_IMM (   x)    (EXTRACT_RVC_LW_IMM(ENCODE_RVC_LW_IMM(x)) == (x))

Definition at line 151 of file riscv.h.

◆ VALID_RVC_LWSP_IMM

#define VALID_RVC_LWSP_IMM (   x)    (EXTRACT_RVC_LWSP_IMM(ENCODE_RVC_LWSP_IMM(x)) == (x))

Definition at line 153 of file riscv.h.

◆ VALID_RVC_SDSP_IMM

#define VALID_RVC_SDSP_IMM (   x)    (EXTRACT_RVC_SDSP_IMM(ENCODE_RVC_SDSP_IMM(x)) == (x))

Definition at line 156 of file riscv.h.

◆ VALID_RVC_SIMM3

#define VALID_RVC_SIMM3 (   x)    (EXTRACT_RVC_SIMM3(ENCODE_RVC_SIMM3(x)) == (x))

Definition at line 148 of file riscv.h.

◆ VALID_RVC_SWSP_IMM

#define VALID_RVC_SWSP_IMM (   x)    (EXTRACT_RVC_SWSP_IMM(ENCODE_RVC_SWSP_IMM(x)) == (x))

Definition at line 155 of file riscv.h.

◆ VALID_SBTYPE_IMM

#define VALID_SBTYPE_IMM (   x)    (EXTRACT_SBTYPE_IMM(ENCODE_SBTYPE_IMM(x)) == (x))

Definition at line 143 of file riscv.h.

◆ VALID_STYPE_IMM

#define VALID_STYPE_IMM (   x)    (EXTRACT_STYPE_IMM(ENCODE_STYPE_IMM(x)) == (x))

Definition at line 142 of file riscv.h.

◆ VALID_UJTYPE_IMM

#define VALID_UJTYPE_IMM (   x)    (EXTRACT_UJTYPE_IMM(ENCODE_UJTYPE_IMM(x)) == (x))

Definition at line 145 of file riscv.h.

◆ VALID_UTYPE_IMM

#define VALID_UTYPE_IMM (   x)    (EXTRACT_UTYPE_IMM(ENCODE_UTYPE_IMM(x)) == (x))

Definition at line 144 of file riscv.h.

◆ X_GP

#define X_GP   3

Definition at line 242 of file riscv.h.

◆ X_RA

#define X_RA   1

Definition at line 240 of file riscv.h.

◆ X_SP

#define X_SP   2

Definition at line 241 of file riscv.h.

◆ X_T0

#define X_T0   5

Definition at line 244 of file riscv.h.

◆ X_T1

#define X_T1   6

Definition at line 245 of file riscv.h.

◆ X_T2

#define X_T2   7

Definition at line 246 of file riscv.h.

◆ X_T3

#define X_T3   28

Definition at line 247 of file riscv.h.

◆ X_TP

#define X_TP   4

Definition at line 243 of file riscv.h.

Typedef Documentation

◆ insn_t

typedef uint64_t insn_t

Definition at line 31 of file riscv.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
M_LA 
M_LLA 
M_LA_TLS_GD 
M_LA_TLS_IE 
M_LB 
M_LBU 
M_LH 
M_LHU 
M_LW 
M_LWU 
M_LD 
M_SB 
M_SH 
M_SW 
M_SD 
M_FLW 
M_FLD 
M_FLQ 
M_FSW 
M_FSD 
M_FSQ 
M_CALL 
M_J 
M_LI 
M_NUM_MACROS 

Definition at line 310 of file riscv.h.

311 {
312  M_LA,
313  M_LLA,
314  M_LA_TLS_GD,
315  M_LA_TLS_IE,
316  M_LB,
317  M_LBU,
318  M_LH,
319  M_LHU,
320  M_LW,
321  M_LWU,
322  M_LD,
323  M_SB,
324  M_SH,
325  M_SW,
326  M_SD,
327  M_FLW,
328  M_FLD,
329  M_FLQ,
330  M_FSW,
331  M_FSD,
332  M_FSQ,
333  M_CALL,
334  M_J,
335  M_LI,
337 };
@ M_LWU
Definition: riscv.h:321
@ M_SD
Definition: riscv.h:326
@ M_LLA
Definition: riscv.h:313
@ M_FLQ
Definition: riscv.h:329
@ M_FSQ
Definition: riscv.h:332
@ M_CALL
Definition: riscv.h:333
@ M_LHU
Definition: riscv.h:319
@ M_SW
Definition: riscv.h:325
@ M_LW
Definition: riscv.h:320
@ M_FSD
Definition: riscv.h:331
@ M_FLD
Definition: riscv.h:328
@ M_LA
Definition: riscv.h:312
@ M_LD
Definition: riscv.h:322
@ M_LH
Definition: riscv.h:318
@ M_FLW
Definition: riscv.h:327
@ M_SH
Definition: riscv.h:324
@ M_LBU
Definition: riscv.h:317
@ M_J
Definition: riscv.h:334
@ M_LB
Definition: riscv.h:316
@ M_FSW
Definition: riscv.h:330
@ M_LA_TLS_IE
Definition: riscv.h:315
@ M_NUM_MACROS
Definition: riscv.h:336
@ M_LA_TLS_GD
Definition: riscv.h:314
@ M_SB
Definition: riscv.h:323
@ M_LI
Definition: riscv.h:335

Function Documentation

◆ riscv_insn_length()

static unsigned int riscv_insn_length ( insn_t  insn)
inlinestatic

Definition at line 33 of file riscv.h.

34 {
35  if ((insn & 0x3) != 0x3) /* RVC. */
36  return 2;
37  if ((insn & 0x1f) != 0x1f) /* Base ISA and extensions in 32-bit space. */
38  return 4;
39  if ((insn & 0x3f) == 0x1f) /* 48-bit extensions. */
40  return 6;
41  if ((insn & 0x7f) == 0x3f) /* 64-bit extensions. */
42  return 8;
43  /* Longer instructions not supported at the moment. */
44  return 2;
45 }

Referenced by riscv_dis().

Variable Documentation

◆ riscv_pred_succ

const char* const riscv_pred_succ[16]
static
Initial value:
=
{
0, "w", "r", "rw", "o", "ow", "or", "orw",
"i", "iw", "ir", "irw", "io", "iow", "ior", "iorw"
}

Definition at line 52 of file riscv.h.

Referenced by get_insn_args().

◆ riscv_rm

const char* const riscv_rm[8]
static
Initial value:
=
{
"rne", "rtz", "rdn", "rup", "rmm", 0, 0, "dyn"
}

Definition at line 47 of file riscv.h.

Referenced by get_insn_args().