Skip to content

Commit

Permalink
RISC-V: Fix CSR hashtable initialization
Browse files Browse the repository at this point in the history
This commit fixes the issue which repeatedly initializing CSR hashtable
everytime we parse an CSR and makes sure that CSR hashtable initialization
occurs when either architecture or option is changed (e.g. setting a
disassembler option `priv-spec' on GDB may change the privileged spec
version, changing canonical CSR names dynamically).

opcodes/ChangeLog:

	* riscv-dis.c (init_dis_per_arch_and_options): Reset the CSR
	init flag for privileged spec version change.
	(print_insn_args): Don't repeatedly initialize CSR hashtable.
	Use a file scope flag to initialize CSR hashtable to enable
	resetting the flag.
  • Loading branch information
a4lg committed Jul 11, 2022
1 parent 561ca1d commit c5bed3a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions opcodes/riscv-dis.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ static bool no_aliases = false;
/* If set, disassemble with numeric registers. */
static bool is_numeric = false;

/* Reset when either arch or option is changed. */
static bool is_init_csr = false;


static void
set_default_riscv_dis_options (void)
{
Expand Down Expand Up @@ -178,6 +182,8 @@ init_dis_per_arch_and_options (void)
/* If arch has Zfinx extension, use GPR to disassemble. */
if (riscv_subset_supports (&riscv_rps_dis, "zfinx"))
riscv_fpr_names = riscv_gpr_names;
/* Reset CSR hashtable because `priv-spec' option may change the names. */
is_init_csr = false;
}

/* Print one argument from an array. */
Expand Down Expand Up @@ -534,10 +540,9 @@ print_insn_args (const char *oparg, insn_t l, bfd_vma pc, disassemble_info *info
case 'E':
{
static const char *riscv_csr_hash[4096]; /* Total 2^12 CSRs. */
static bool init_csr = false;
unsigned int csr = EXTRACT_OPERAND (CSR, l);

if (!init_csr)
if (!is_init_csr)
{
unsigned int i;
for (i = 0; i < 4096; i++)
Expand All @@ -558,6 +563,7 @@ print_insn_args (const char *oparg, insn_t l, bfd_vma pc, disassemble_info *info
DECLARE_CSR (name, num, class, define_version, abort_version)
#include "opcode/riscv-opc.h"
#undef DECLARE_CSR
is_init_csr = true;
}

if (riscv_csr_hash[csr] != NULL)
Expand Down

0 comments on commit c5bed3a

Please sign in to comment.