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

Go to the source code of this file.

Macros

#define MASK_RS1   (OP_MASK_RS1 << OP_SH_RS1)
 
#define MASK_RS2   (OP_MASK_RS2 << OP_SH_RS2)
 
#define MASK_RD   (OP_MASK_RD << OP_SH_RD)
 
#define MASK_CRS2   (OP_MASK_CRS2 << OP_SH_CRS2)
 
#define MASK_IMM   ENCODE_ITYPE_IMM (-1U)
 
#define MASK_RVC_IMM   ENCODE_RVC_IMM (-1U)
 
#define MASK_UIMM   ENCODE_UTYPE_IMM (-1U)
 
#define MASK_RM   (OP_MASK_RM << OP_SH_RM)
 
#define MASK_PRED   (OP_MASK_PRED << OP_SH_PRED)
 
#define MASK_SUCC   (OP_MASK_SUCC << OP_SH_SUCC)
 
#define MASK_AQ   (OP_MASK_AQ << OP_SH_AQ)
 
#define MASK_RL   (OP_MASK_RL << OP_SH_RL)
 
#define MASK_AQRL   (MASK_AQ | MASK_RL)
 
#define RISCV_NUM_OPCODES    ((sizeof riscv_builtin_opcodes) / (sizeof (riscv_builtin_opcodes[0])))
 

Functions

static int match_opcode (const struct riscv_opcode *op, insn_t insn)
 
static int match_never (const struct riscv_opcode *op, insn_t insn)
 
static int match_rs1_eq_rs2 (const struct riscv_opcode *op, insn_t insn)
 
static int match_rd_nonzero (const struct riscv_opcode *op, insn_t insn)
 
static int match_c_add (const struct riscv_opcode *op, insn_t insn)
 
static int match_c_lui (const struct riscv_opcode *op, insn_t insn)
 

Variables

static const char *const riscv_gpr_names_numeric [NGPR]
 
static const char *const riscv_gpr_names_abi [NGPR]
 
static const char *const riscv_fpr_names_numeric [NFPR]
 
static const char *const riscv_fpr_names_abi [NFPR]
 
static const struct riscv_opcode riscv_builtin_opcodes []
 
static struct riscv_opcoderiscv_opcodes
 
static int bfd_riscv_num_opcodes = RISCV_NUM_OPCODES
 

Macro Definition Documentation

◆ MASK_AQ

#define MASK_AQ   (OP_MASK_AQ << OP_SH_AQ)

Definition at line 81 of file riscv-opc.c.

◆ MASK_AQRL

#define MASK_AQRL   (MASK_AQ | MASK_RL)

Definition at line 83 of file riscv-opc.c.

◆ MASK_CRS2

#define MASK_CRS2   (OP_MASK_CRS2 << OP_SH_CRS2)

Definition at line 74 of file riscv-opc.c.

◆ MASK_IMM

#define MASK_IMM   ENCODE_ITYPE_IMM (-1U)

Definition at line 75 of file riscv-opc.c.

◆ MASK_PRED

#define MASK_PRED   (OP_MASK_PRED << OP_SH_PRED)

Definition at line 79 of file riscv-opc.c.

◆ MASK_RD

#define MASK_RD   (OP_MASK_RD << OP_SH_RD)

Definition at line 73 of file riscv-opc.c.

◆ MASK_RL

#define MASK_RL   (OP_MASK_RL << OP_SH_RL)

Definition at line 82 of file riscv-opc.c.

◆ MASK_RM

#define MASK_RM   (OP_MASK_RM << OP_SH_RM)

Definition at line 78 of file riscv-opc.c.

◆ MASK_RS1

#define MASK_RS1   (OP_MASK_RS1 << OP_SH_RS1)

Definition at line 71 of file riscv-opc.c.

◆ MASK_RS2

#define MASK_RS2   (OP_MASK_RS2 << OP_SH_RS2)

Definition at line 72 of file riscv-opc.c.

◆ MASK_RVC_IMM

#define MASK_RVC_IMM   ENCODE_RVC_IMM (-1U)

Definition at line 76 of file riscv-opc.c.

◆ MASK_SUCC

#define MASK_SUCC   (OP_MASK_SUCC << OP_SH_SUCC)

Definition at line 80 of file riscv-opc.c.

◆ MASK_UIMM

#define MASK_UIMM   ENCODE_UTYPE_IMM (-1U)

Definition at line 77 of file riscv-opc.c.

◆ RISCV_NUM_OPCODES

#define RISCV_NUM_OPCODES    ((sizeof riscv_builtin_opcodes) / (sizeof (riscv_builtin_opcodes[0])))

Definition at line 679 of file riscv-opc.c.

Function Documentation

◆ match_c_add()

static int match_c_add ( const struct riscv_opcode op,
insn_t  insn 
)
static

Definition at line 107 of file riscv-opc.c.

108 {
109  return match_rd_nonzero (op, insn) && ((insn & MASK_CRS2) != 0);
110 }
static int match_rd_nonzero(const struct riscv_opcode *op, insn_t insn)
Definition: riscv-opc.c:102
#define MASK_CRS2
Definition: riscv-opc.c:74
Definition: dis.c:32

References MASK_CRS2, and match_rd_nonzero().

◆ match_c_lui()

static int match_c_lui ( const struct riscv_opcode op,
insn_t  insn 
)
static

Definition at line 112 of file riscv-opc.c.

113 {
114  return match_rd_nonzero (op, insn) && (((insn & MASK_RD) >> OP_SH_RD) != 2);
115 }
#define OP_SH_RD
Definition: mips.h:85
#define MASK_RD
Definition: riscv-opc.c:73

References MASK_RD, match_rd_nonzero(), and OP_SH_RD.

◆ match_never()

static int match_never ( const struct riscv_opcode op,
insn_t  insn 
)
static

Definition at line 90 of file riscv-opc.c.

91 {
92  return 0;
93 }

◆ match_opcode()

static int match_opcode ( const struct riscv_opcode op,
insn_t  insn 
)
static

Definition at line 85 of file riscv-opc.c.

86 {
87  return ((insn ^ op->match) & op->mask) == 0;
88 }

Referenced by match_rd_nonzero(), and match_rs1_eq_rs2().

◆ match_rd_nonzero()

static int match_rd_nonzero ( const struct riscv_opcode op,
insn_t  insn 
)
static

Definition at line 102 of file riscv-opc.c.

103 {
104  return match_opcode (op, insn) && ((insn & MASK_RD) != 0);
105 }
static int match_opcode(const struct riscv_opcode *op, insn_t insn)
Definition: riscv-opc.c:85

References MASK_RD, and match_opcode().

Referenced by match_c_add(), and match_c_lui().

◆ match_rs1_eq_rs2()

static int match_rs1_eq_rs2 ( const struct riscv_opcode op,
insn_t  insn 
)
static

Definition at line 95 of file riscv-opc.c.

96 {
97  int rs1 = (insn & MASK_RS1) >> OP_SH_RS1;
98  int rs2 = (insn & MASK_RS2) >> OP_SH_RS2;
99  return match_opcode (op, insn) && rs1 == rs2;
100 }
#define MASK_RS2
Definition: riscv-opc.c:72
#define MASK_RS1
Definition: riscv-opc.c:71
#define OP_SH_RS2
Definition: riscv.h:202
#define OP_SH_RS1
Definition: riscv.h:204

References MASK_RS1, MASK_RS2, match_opcode(), OP_SH_RS1, and OP_SH_RS2.

Variable Documentation

◆ bfd_riscv_num_opcodes

int bfd_riscv_num_opcodes = RISCV_NUM_OPCODES
static

Definition at line 687 of file riscv-opc.c.

◆ riscv_builtin_opcodes

const struct riscv_opcode riscv_builtin_opcodes[]
static

Definition at line 112 of file riscv-opc.c.

◆ riscv_fpr_names_abi

const char* const riscv_fpr_names_abi[NFPR]
static
Initial value:
= {
"ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7",
"fs0", "fs1", "fa0", "fa1", "fa2", "fa3", "fa4", "fa5",
"fa6", "fa7", "fs2", "fs3", "fs4", "fs5", "fs6", "fs7",
"fs8", "fs9", "fs10", "fs11", "ft8", "ft9", "ft10", "ft11"
}

Definition at line 54 of file riscv-opc.c.

◆ riscv_fpr_names_numeric

const char* const riscv_fpr_names_numeric[NFPR]
static
Initial value:
=
{
"f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
"f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
"f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
"f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31"
}

Definition at line 46 of file riscv-opc.c.

◆ riscv_gpr_names_abi

const char* const riscv_gpr_names_abi[NGPR]
static
Initial value:
= {
"zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2",
"s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5",
"a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7",
"s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6"
}

Definition at line 39 of file riscv-opc.c.

◆ riscv_gpr_names_numeric

const char* const riscv_gpr_names_numeric[NGPR]
static
Initial value:
=
{
"x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
"x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
"x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
"x24", "x25", "x26", "x27", "x28", "x29", "x30", "x31"
}

Definition at line 31 of file riscv-opc.c.

◆ riscv_opcodes

struct riscv_opcode* riscv_opcodes
static
Initial value:
=
static const struct riscv_opcode riscv_builtin_opcodes[]
Definition: riscv-opc.c:117

Definition at line 685 of file riscv-opc.c.

Referenced by get_opcode(), riscv_disassemble(), and riscv_op().