Skip to content

Commit

Permalink
RISC-V: Support disassembling RV32E
Browse files Browse the repository at this point in the history
This commit adds support for RV32E disassembling which turns x16-x31
into invalid16-invalid31 while disassembling.

gas/ChangeLog:

	* testsuite/gas/riscv/e-ext-dis.s: New RV32E disassembler test.
	* testsuite/gas/riscv/e-ext-dis-rv32e.d: Likewise.
	* testsuite/gas/riscv/e-ext-dis-rv32i.d: Likewise.

include/ChangeLog:

	* opcode/riscv.h: Add RVE register name definitions.

opcodes/ChangeLog:

	* riscv-dis.c (init_riscv_dis_state_for_arch_and_options): Apply
	RVE register names when the E extension is enabled.
	* riscv-opc.c (riscv_gpr_names_rve_numeric): New.
	(riscv_gpr_names_rve_abi): New.
  • Loading branch information
a4lg committed Jul 13, 2022
1 parent c306598 commit afb7c60
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 4 deletions.
11 changes: 11 additions & 0 deletions gas/testsuite/gas/riscv/e-ext-dis-rv32e.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#as: -march=rv32e
#source: e-ext-dis.s
#objdump: -dr -M numeric

.*:[ ]+file format .*

Disassembly of section .text:

0+000 <target>:
[ ]+[0-9a-f]+:[ ]+00f78793[ ]+addi[ ]+x15,x15,15
[ ]+[0-9a-f]+:[ ]+01ff8f93[ ]+addi[ ]+invalid31,invalid31,31
11 changes: 11 additions & 0 deletions gas/testsuite/gas/riscv/e-ext-dis-rv32i.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#as: -march=rv32i
#source: e-ext-dis.s
#objdump: -dr -M numeric

.*:[ ]+file format .*

Disassembly of section .text:

0+000 <target>:
[ ]+[0-9a-f]+:[ ]+00f78793[ ]+addi[ ]+x15,x15,15
[ ]+[0-9a-f]+:[ ]+01ff8f93[ ]+addi[ ]+x31,x31,31
4 changes: 4 additions & 0 deletions gas/testsuite/gas/riscv/e-ext-dis.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
target:
addi x15, x15, 15
# addi x31, x31, 31 (invalid on RV32E)
.insn 0x01ff8f93
2 changes: 2 additions & 0 deletions include/opcode/riscv.h
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,8 @@ enum riscv_seg_mstate

extern const char * const riscv_gpr_names_numeric[NGPR];
extern const char * const riscv_gpr_names_abi[NGPR];
extern const char * const riscv_gpr_names_rve_numeric[NGPR];
extern const char * const riscv_gpr_names_rve_abi[NGPR];
extern const char * const riscv_fpr_names_numeric[NFPR];
extern const char * const riscv_fpr_names_abi[NFPR];
extern const char * const riscv_vecr_names_numeric[NVECR];
Expand Down
3 changes: 3 additions & 0 deletions opcodes/riscv-dis.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ init_riscv_dis_state_for_arch_and_options (void)
{
riscv_gpr_names = is_numeric ? riscv_gpr_names_numeric : riscv_gpr_names_abi;
riscv_fpr_names = is_numeric ? riscv_fpr_names_numeric : riscv_fpr_names_abi;
if (riscv_subset_supports (&riscv_rps_dis, "e"))
riscv_gpr_names
= is_numeric ? riscv_gpr_names_rve_numeric : riscv_gpr_names_rve_abi;
/* If arch has Zfinx extension, use GPR to disassemble. */
if (riscv_subset_supports (&riscv_rps_dis, "zfinx"))
riscv_fpr_names = riscv_gpr_names;
Expand Down
28 changes: 24 additions & 4 deletions opcodes/riscv-opc.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,40 @@

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

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

#define RISCV_GPR_NAMES_RVE_UPPER \
"invalid16", "invalid17", "invalid18", "invalid19", \
"invalid20", "invalid21", "invalid22", "invalid23", \
"invalid24", "invalid25", "invalid26", "invalid27", \
"invalid28", "invalid29", "invalid30", "invalid31"
const char * const riscv_gpr_names_rve_numeric[NGPR] =
{
RISCV_GPR_NAMES_NUMERIC_LOWER,
RISCV_GPR_NAMES_RVE_UPPER
};
const char * const riscv_gpr_names_rve_abi[NGPR] =
{
RISCV_GPR_NAMES_ABI_LOWER,
RISCV_GPR_NAMES_RVE_UPPER
};

const char * const riscv_fpr_names_numeric[NFPR] =
{
"f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
Expand Down

0 comments on commit afb7c60

Please sign in to comment.