RISC-V 开源模拟器环境构建
? ? RISC-V 提供的開源工程里面提供了一個模擬器,解除了學習者、移植者對專用硬件的依賴。本文是對搭建RISC-V開源模擬器環境的簡介。針對搭建過程中可能遇到的問題,提供解決建議。
? ?1. 工具鏈
? ?為了將源代碼生成能在RISC-V上運行的程序,我們首先要生成工具鏈。
? ? RISC-V? 工具鏈官方資源:?GitHub - riscv-collab/riscv-gnu-toolchain: GNU toolchain for RISC-V, including GCCGNU toolchain for RISC-V, including GCC. Contribute to riscv-collab/riscv-gnu-toolchain development by creating an account on GitHub.https://github.com/riscv-collab/riscv-gnu-toolchain
? ? RISC-V? 工具鏈國內鏡像:
mirrors / riscv / riscv-gnu-toolchain · GitCodehttps://gitcode.net/mirrors/riscv/riscv-gnu-toolchain
? 提示: 工具鏈工程源文件接近7G,clone過程中容易發生失敗。建議通過網盤下載,下載鏈接:https://pan.baidu.com/s/1KTckAhgQTcqStdgAK8yJ8g? 提取碼:p8my?
? 1.1 預先準備
? ? ? ? 構建工具鏈依賴若干基礎組件,在Ubuntu 上采用以下命令完成組件的安裝。
$ sudo apt-get install autoconf automake autotools-dev curl python3 libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat-dev? ? 提示: 安裝組件的過程可能會遇到依賴關系不滿足的問題。遇到這種情況,建議每次安裝一個組件的方式,找到依賴關系不滿足組件。然后利用aptitude進行的處理。
?針對上述 texinfo 安裝失敗的例子,aptitude的使用方法如下:
$ sudo apt-get install aptitude $ sudo aptitude install texinfo $ sudo apt-get install texinfo1.2 構建工具鏈
? ? ?在模擬器中,我們將使用到的 riscv64-unknown-elf-gcc 和?riscv64-unknown-linux-gnu-gcc. 各自對用的構建命令如下:
? ?riscv64-unknown-elf-gcc
./configure --prefix=/opt/riscv make? riscv64-unknown-linux-gnu-gcc
./configure --prefix=/opt/riscv --enable-multilib make linux提示: 工具鏈構建時間非常長,大約2小時。
1.3 配置工具鏈
? ? ? 將工具鏈的bin(我們這里是/opt/riscv/bin)加進$PATH,就可以正常使用了。
2. RISC-V 模擬器
? ? riscv-isa-sim 是 RISC-V 的模擬器,它的構建依賴于其他riscv-tools。riscv-tools中也包含了riscv-isa-sim, 所以通過對riscv-tools的構建來完成對模擬器的構建。
? ? ?RISC-V? tools 官方資源
https://github.com/riscv-software-src/riscv-toolshttps://github.com/riscv-software-src/riscv-tools
? ? ?RISC-V? tools 國內鏡像
mirrors / riscv / riscv-tools · GitCodehttps://gitcode.net/mirrors/riscv/riscv-tools
? 按照以下命令完成構建
# git submodule update --init --recursive # export RISCV=/opt/riscv/ # ./build.sh提示: /opt/riscv 是我們這個案例中的riscv-tools安裝地址。
提示: 構建需要使用管理員賬號。
3.測試
按照慣例,我們還是寫一個Hello world來跑第一個程序。
$echo -e '#include <stdio.h>\n int main(void) { printf("Helloworld!\\n"); return 0; }' > hello.cbuild后,在spike(riscv-isa-sim)中運行,恭喜!
?
總結
以上是生活随笔為你收集整理的RISC-V 开源模拟器环境构建的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 基础学编程之三个数顺序排序
- 下一篇: 栅格计算器函数之Con