From fcc557da9d7a49ef6f367f9d5158d03f2fae443f Mon Sep 17 00:00:00 2001 From: Scott Beamer Date: Thu, 24 Jul 2014 17:05:53 -0700 Subject: [PATCH] added support for register convention names in debug mode --- README | 2 +- riscv/disasm.h | 14 ++++++++++++++ riscv/interactive.cc | 11 +++++++++-- spike/disasm.cc | 33 ++++++++++----------------------- 4 files changed, 34 insertions(+), 26 deletions(-) diff --git a/README b/README index 71827bc..093bf9f 100644 --- a/README +++ b/README @@ -65,7 +65,7 @@ To invoke interactive debug mode, launch spike with -d: To see the contents of a register (0 is for core 0): - : reg 0 14 + : reg 0 a0 To see the contents of a memory location (physical address in hex): diff --git a/riscv/disasm.h b/riscv/disasm.h index b5aa6de..58a518a 100644 --- a/riscv/disasm.h +++ b/riscv/disasm.h @@ -8,6 +8,20 @@ #include #include +static const char* xpr_name[] = { + "zero", "ra", "s0", "s1", "s2", "s3", "s4", "s5", + "s6", "s7", "s8", "s9", "s10", "s11", "sp", "tp", + "v0", "v1", "a0", "a1", "a2", "a3", "a4", "a5", + "a6", "a7", "t0", "t1", "t2", "t3", "t4", "gp" +}; + +static const char* fpr_name[] = { + "fs0", "fs1", "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", + "fs8", "fs9", "fs10", "fs11", "fs12", "fs13", "fs14", "fs15", + "fv0", "fv1", "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", + "fa6", "fa7", "ft0", "ft1", "ft2", "ft3", "ft4", "ft5" +}; + class arg_t { public: diff --git a/riscv/interactive.cc b/riscv/interactive.cc index 9014aa0..27e9ee0 100644 --- a/riscv/interactive.cc +++ b/riscv/interactive.cc @@ -1,5 +1,7 @@ // See LICENSE for license details. +#include "decode.h" +#include "disasm.h" #include "sim.h" #include "htif.h" #include @@ -14,6 +16,7 @@ #include #include #include +#include static std::string readline(int fd) { @@ -130,7 +133,9 @@ reg_t sim_t::get_reg(const std::vector& args) throw trap_illegal_instruction(); int p = atoi(args[0].c_str()); - int r = atoi(args[1].c_str()); + int r = std::find(xpr_name, xpr_name + NXPR, args[1]) - xpr_name; + if (r == NXPR) + r = atoi(args[1].c_str()); if(p >= (int)num_cores() || r >= NXPR) throw trap_illegal_instruction(); @@ -143,7 +148,9 @@ reg_t sim_t::get_freg(const std::vector& args) throw trap_illegal_instruction(); int p = atoi(args[0].c_str()); - int r = atoi(args[1].c_str()); + int r = std::find(fpr_name, fpr_name + NFPR, args[1]) - fpr_name; + if (r == NFPR) + r = atoi(args[1].c_str()); if(p >= (int)num_cores() || r >= NFPR) throw trap_illegal_instruction(); diff --git a/spike/disasm.cc b/spike/disasm.cc index f63dee1..8fb1db8 100644 --- a/spike/disasm.cc +++ b/spike/disasm.cc @@ -7,77 +7,64 @@ #include #include -static const char* xpr[] = { - "zero", "ra", "s0", "s1", "s2", "s3", "s4", "s5", - "s6", "s7", "s8", "s9", "s10", "s11", "sp", "tp", - "v0", "v1", "a0", "a1", "a2", "a3", "a4", "a5", - "a6", "a7", "t0", "t1", "t2", "t3", "t4", "gp" -}; - -static const char* fpr[] = { - "fs0", "fs1", "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", - "fs8", "fs9", "fs10", "fs11", "fs12", "fs13", "fs14", "fs15", - "fv0", "fv1", "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", - "fa6", "fa7", "ft0", "ft1", "ft2", "ft3", "ft4", "ft5" -}; struct : public arg_t { std::string to_string(insn_t insn) const { - return std::to_string((int)insn.i_imm()) + '(' + xpr[insn.rs1()] + ')'; + return std::to_string((int)insn.i_imm()) + '(' + xpr_name[insn.rs1()] + ')'; } } load_address; struct : public arg_t { std::string to_string(insn_t insn) const { - return std::to_string((int)insn.s_imm()) + '(' + xpr[insn.rs1()] + ')'; + return std::to_string((int)insn.s_imm()) + '(' + xpr_name[insn.rs1()] + ')'; } } store_address; struct : public arg_t { std::string to_string(insn_t insn) const { - return std::string("0(") + xpr[insn.rs1()] + ')'; + return std::string("0(") + xpr_name[insn.rs1()] + ')'; } } amo_address; struct : public arg_t { std::string to_string(insn_t insn) const { - return xpr[insn.rd()]; + return xpr_name[insn.rd()]; } } xrd; struct : public arg_t { std::string to_string(insn_t insn) const { - return xpr[insn.rs1()]; + return xpr_name[insn.rs1()]; } } xrs1; struct : public arg_t { std::string to_string(insn_t insn) const { - return xpr[insn.rs2()]; + return xpr_name[insn.rs2()]; } } xrs2; struct : public arg_t { std::string to_string(insn_t insn) const { - return fpr[insn.rd()]; + return fpr_name[insn.rd()]; } } frd; struct : public arg_t { std::string to_string(insn_t insn) const { - return fpr[insn.rs1()]; + return fpr_name[insn.rs1()]; } } frs1; struct : public arg_t { std::string to_string(insn_t insn) const { - return fpr[insn.rs2()]; + return fpr_name[insn.rs2()]; } } frs2; struct : public arg_t { std::string to_string(insn_t insn) const { - return fpr[insn.rs3()]; + return fpr_name[insn.rs3()]; } } frs3; -- 2.30.2