LoginSignup
7
6

RISC-V向けの実行ファイルをmacOSとUbuntu22.04それぞれでエミュレーション実行する方法

Last updated at Posted at 2023-03-01

riscv-isa-simriscv-pkを使います.

macOS

brew tap riscv-software-src/riscv
brew install riscv-isa-sim riscv-pk

Ubuntu 22.04

spikeのインストール

下記をインストールします.

/usr/local/riscv にインストールします.

sudo apt update
sudo apt install device-tree-compiler
git clone https://github.com/riscv-software-src/riscv-isa-sim.git
cd riscv-isa-sim
mkdir build
cd build
../configure --prefix=/usr/local/riscv
make -j$(nproc)
sudo make install

pkのインストール

あらかじめ下記にしたがって,riscv-gnu-toolchainをインストールして,インストール先(/usr/local/riscv/binなど)にPATHを通しておいてください.

下記をインストールします.

/usr/local/riscv にインストールします.

git clone https://github.com/riscv-software-src/riscv-pk.git
cd riscv-pk
git checkout 8ce2dc4 # 2023年5月15日現在,このcommit hashをcheckoutしないとpkが正常に動作しません
mkdir build
cd build
../configure --prefix=/usr/local/riscv --host=riscv64-unknown-elf --with-arch=rv64gc_zifencei
make -j$(nproc)
sudo make install

参考記事は下記の通りです.

使い方

次のように使います.

macOSの場合

spike pk (実行ファイル)

Ubuntu 22.04の場合

/usr/local/riscv/bin/spike /usr/local/riscv/riscv64-unknown-elf/bin/pk (実行ファイル)

ベクタ拡張を含む実行ファイルを実行するには次のようにします.

masOSの場合

spike --isa=RV64IMAFDCV pk (実行ファイル)

Ubuntu 22.04の場合

/usr/local/riscv/bin/spike --isa=RV64IMAFDCV /usr/local/riscv/riscv64-unknown-elf/bin/pk (実行ファイル)

--isa=RV64GVでは動作しませんでした.

32ビットアーキテクチャで動かすためには,riscv-pkを32ビットアーキテクチャでコンパイルする必要があります.

あらかじめ,下記の記事にしたがって,riscv-gnu-toolchainをインストールしておきます.

pkのインストール先をたとえば次のように設定します.

export RISCV=~/rv32

その後,次のようにしてビルド・インストールします.

macOSの場合

git clone https://github.com/riscv/riscv-pk.git
cd riscv-pk
mkdir build
cd build
../configure --prefix=$RISCV --host=riscv64-unknown-elf --with-arch=rv32i
make
make install

Ubuntuの場合

git clone https://github.com/riscv-software-src/riscv-pk.git
cd riscv-pk
git checkout 8ce2dc4 # 2023年5月15日現在,このcommit hashをcheckoutしないとpkが正常に動作しません
mkdir build
cd build
../configure --prefix=$RISCV --host=riscv64-unknown-elf --with-arch=rv32i_zifencei
make -j$(nproc)
sudo make install

使用方法としては,例えば次のようにします.

spike --isa=RV32I ~/rv32/riscv32-unknown-elf/bin/pk (実行ファイル)
7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6