From 59ec157568d2a52feeec568ac042362db1c5ddbc Mon Sep 17 00:00:00 2001 From: Rupert Swarbrick Date: Fri, 11 Mar 2022 21:44:54 +0000 Subject: [PATCH] Incorporate supported privilege levels into isa_parser_t (#940) These affect the "max_isa" value (now exposed as get_max_isa()) and feel like they're similar to the other computations done in isa_parser_t. --- disasm/disasm.cc | 2 +- riscv/processor.cc | 52 +++++++++++++++++++--------------------- riscv/processor.h | 3 ++- spike_dasm/spike-dasm.cc | 2 +- 4 files changed, 28 insertions(+), 31 deletions(-) diff --git a/disasm/disasm.cc b/disasm/disasm.cc index beb18c28..52dede67 100644 --- a/disasm/disasm.cc +++ b/disasm/disasm.cc @@ -2032,7 +2032,7 @@ disassembler_t::disassembler_t(const isa_parser_t *isa) // next-highest priority: other instructions in same base ISA std::string fallback_isa_string = std::string("rv") + std::to_string(isa->get_max_xlen()) + "gcv_zfh_zba_zbb_zbc_zbs_zkn_zkr_zks_xbitmanip"; - isa_parser_t fallback_isa(fallback_isa_string.c_str()); + isa_parser_t fallback_isa(fallback_isa_string.c_str(), DEFAULT_PRIV); add_instructions(&fallback_isa); // finally: instructions with known opcodes but unknown arguments diff --git a/riscv/processor.cc b/riscv/processor.cc index f20ac6ac..438c989e 100644 --- a/riscv/processor.cc +++ b/riscv/processor.cc @@ -26,7 +26,7 @@ processor_t::processor_t(const char* isa, const char* priv, const char* varch, simif_t* sim, uint32_t id, bool halt_on_reset, FILE* log_file, std::ostream& sout_) - : isa_parser_t(isa), debug(false), halt_request(HR_NONE), sim(sim), id(id), xlen(0), + : isa_parser_t(isa, priv), debug(false), halt_request(HR_NONE), sim(sim), id(id), xlen(0), histogram_enabled(false), log_commits_enabled(false), log_file(log_file), sout_(sout_.rdbuf()), halt_on_reset(halt_on_reset), impl_table(256, false), last_pc(1), executions(1) @@ -40,7 +40,6 @@ processor_t::processor_t(const char* isa, const char* priv, const char* varch, } #endif - parse_priv_string(priv); parse_varch_string(varch); register_base_instructions(); @@ -175,32 +174,7 @@ void processor_t::parse_varch_string(const char* s) VU.vstart_alu = vstart_alu; } -void processor_t::parse_priv_string(const char* str) -{ - std::string lowercase = strtolower(str); - bool user = false, supervisor = false; - - if (lowercase == "m") - ; - else if (lowercase == "mu") - user = true; - else if (lowercase == "msu") - user = supervisor = true; - else - bad_priv_string(str); - - if (user) { - max_isa |= reg_t(user) << ('u' - 'a'); - extension_table['U'] = true; - } - - if (supervisor) { - max_isa |= reg_t(supervisor) << ('s' - 'a'); - extension_table['S'] = true; - } -} - -isa_parser_t::isa_parser_t(const char* str) +isa_parser_t::isa_parser_t(const char* str, const char *priv) : extension_table(256, false) { isa_string = strtolower(str); @@ -394,6 +368,28 @@ isa_parser_t::isa_parser_t(const char* str) if (*p) { bad_isa_string(str, ("can't parse: " + std::string(p)).c_str()); } + + std::string lowercase = strtolower(priv); + bool user = false, supervisor = false; + + if (lowercase == "m") + ; + else if (lowercase == "mu") + user = true; + else if (lowercase == "msu") + user = supervisor = true; + else + bad_priv_string(priv); + + if (user) { + max_isa |= reg_t(user) << ('u' - 'a'); + extension_table['U'] = true; + } + + if (supervisor) { + max_isa |= reg_t(supervisor) << ('s' - 'a'); + extension_table['S'] = true; + } } static int xlen_to_uxl(int xlen) diff --git a/riscv/processor.h b/riscv/processor.h index 05c55cec..2fe5ede7 100644 --- a/riscv/processor.h +++ b/riscv/processor.h @@ -311,9 +311,10 @@ static int cto(reg_t val) class isa_parser_t { public: - isa_parser_t(const char* str); + isa_parser_t(const char* str, const char *priv); ~isa_parser_t(){}; unsigned get_max_xlen() const { return max_xlen; } + reg_t get_max_isa() const { return max_isa; } std::string get_isa_string() const { return isa_string; } bool extension_enabled(unsigned char ext) const { if (ext >= 'A' && ext <= 'Z') diff --git a/spike_dasm/spike-dasm.cc b/spike_dasm/spike-dasm.cc index afe46e09..c4fc840f 100644 --- a/spike_dasm/spike-dasm.cc +++ b/spike_dasm/spike-dasm.cc @@ -27,7 +27,7 @@ int main(int argc, char** argv) parser.option(0, "isa", 1, [&](const char* s){isa = s;}); parser.parse(argv); - isa_parser_t isa_parser(isa); + isa_parser_t isa_parser(isa, DEFAULT_PRIV); disassembler_t* disassembler = new disassembler_t(&isa_parser); if (extension) { for (auto disasm_insn : extension()->get_disasms()) {