結局まとめると、修正点は以下のようになる:
riscv/build-riscv.sh の修正
問題なのは riscv-tools リポジトリでダウンロードする riscv-gnu-toolchain が古すぎるのと、そもそも riscv-gnu-toolchain はサブモジュールを全部クローンする必要はなくて、ビルド時に必要なものを自動的にダウンロードすることになっているので余計な操作は不要なはず。
これに伴って、スクリプトをいくつか修正する。
- まず
riscv-toolsを単純に clone するスクリプトを取り除く。
-URL=https://github.com/nus-comparch/riscv-tools.git -BRANCH=sift -FOLDER=riscv-tools -updateGitRepo "$URL" "$BRANCH" "$FOLDER"
riscv-toolsのクローンは、まずはそのリポジトリそのものをクローンするだけで、 riscv-gnu-toolchain 以外のサブモジュールはsubmodule updateでクローンする。
+if [ ! -d riscv-tools ]; then + # Clone riscv-tools + git clone -b sift https://github.com/nus-comparch/riscv-tools.git riscv-tools + cd riscv-tools + + # Initialize all submodules EXCEPT riscv-gnu-toolchain to avoid old version issues + git submodule update --init riscv-fesvr riscv-isa-sim riscv-opcodes riscv-openocd riscv-pk riscv-tests +else + cd riscv-tools + git pull + # Update other submodules (not riscv-gnu-toolchain yet) + git submodule update --init riscv-fesvr riscv-isa-sim riscv-opcodes riscv-openocd riscv-pk riscv-tests +fi
- riscv-gnu-toolchain については、まずはリポジトリ自体をクローンしたうえで、tagの最新版を引っ張ってくるようにする。
+# Now handle riscv-gnu-toolchain separately with latest tag (both new and existing cases) +echo "Setting up riscv-gnu-toolchain with latest tag..." +cd $LOCAL_ROOT/riscv-tools +git submodule update --init riscv-gnu-toolchain +cd riscv-gnu-toolchain + +# Configure git to use https:// instead of git:// protocol (local config for this repo) +git config --local url."https://github.com/".insteadOf git://github.com/ + +git fetch --tags +LATEST_TAG=$(git tag --list | grep -E '^[0-9]{4}\.' | sort -V | tail -1) +if [ -n "$LATEST_TAG" ]; then + echo "Checking out riscv-gnu-toolchain tag: $LATEST_TAG" + git checkout $LATEST_TAG + # NOTE: Do NOT recursively init submodules here + # riscv-gnu-toolchain will download required components during build time +fi + +cd $LOCAL_ROOT
decoder_lib/riscv_decoder.* の修正
riscv_decoder.cc に足りない部分を実装する。
std::string RISCVDecodedInst::disassembly_to_str() constに修正する。
/// Get a string with the disassembled instruction -void RISCVDecodedInst::disassembly_to_str(char *str, int len) const +std::string RISCVDecodedInst::disassembly_to_str() const { riscv::decode dec = this->rv8_dec; std::string args; @@ -606,8 +655,7 @@ void RISCVDecodedInst::disassembly_to_str(char *str, int len) const fmt++; } - strncpy(str, args.c_str(), len-1); - str[len-1] = '\0'; + return args; }
それ以外の関数を実装する。
diff --git a/decoder_lib/riscv_decoder.cc b/decoder_lib/riscv_decoder.cc index 08f5bea..b55303f 100644 --- a/decoder_lib/riscv_decoder.cc +++ b/decoder_lib/riscv_decoder.cc @@ -494,6 +494,55 @@ Decoder::decoder_reg RISCVDecoder::last_reg() return dl::last_reg; // enum reg_num defined in riscv_decoder.h } +/// Get the input register mapped +uint32_t RISCVDecoder::map_register(decoder_reg reg) +{ + // RISC-V doesn't have register aliasing like x86 + return static_cast<uint32_t>(reg); +} + +/// Get the number of implicit registers that are read by the instruction +unsigned int RISCVDecoder::num_read_implicit_registers(const DecodedInst* inst) +{ + // RISC-V has explicit operands; no implicit reads except for special cases + return 0; +} + +/// Get the idx implicit source register +Decoder::decoder_reg RISCVDecoder::get_read_implicit_reg(const DecodedInst* inst, unsigned int idx) +{ + // No implicit source registers in RISC-V + return Decoder::DL_REG_INVALID; +} + +/// Get the number of implicit registers that are written by the instruction +unsigned int RISCVDecoder::num_write_implicit_registers(const DecodedInst* inst) +{ + // RISC-V has explicit operands; no implicit writes + return 0; +} + +/// Get the idx implicit destiny register +Decoder::decoder_reg RISCVDecoder::get_write_implicit_reg(const DecodedInst* inst, unsigned int idx) +{ + // No implicit destination registers in RISC-V + return Decoder::DL_REG_INVALID; +} + +/// Check if the base register of the memory operand pointed by mem_idx is also updated +bool RISCVDecoder::mem_base_upate(const DecodedInst* inst, unsigned int mem_idx) +{ + // RISC-V doesn't have auto-increment/decrement addressing modes like ARM + return false; +} + +/// Check if the memory operand pointed by mem_idx has an index register +bool RISCVDecoder::has_index_reg(const DecodedInst* inst, unsigned int mem_idx) +{ + // RISC-V uses base+offset addressing, no index register + return false; +} + RISCVDecodedInst::RISCVDecodedInst(Decoder* d, const uint8_t * code, size_t size, uint64_t address) {
一応、これでビルドが進んでいる。