RISCV学习-1 RISCV模拟器
作者:互联网
最近有个项目需要用到RISCV开发板,没拿到开发板之前,先尝试配置一个虚拟机环境
1、配置riscv-toolchain
git clone https://github.com/riscv/riscv-gnu-toolchain
Cloning into 'riscv-gnu-toolchain'...
remote: Enumerating objects: 8045, done.
remote: Counting objects: 100% (504/504), done.
remote: Compressing objects: 100% (377/377), done.
remote: Total 8045 (delta 137), reused 448 (delta 124), pack-reused 7541
Receiving objects: 100% (8045/8045), 5.56 MiB | 55.00 KiB/s, done.
Resolving deltas: 100% (3859/3859), done.
2、保依赖库都已经安装
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
3、进入riscv-gnu-toolchain目录
./configure --prefix=/opt/riscv --enable-multilib
./make
./make linux
如果后续步骤有问题,分别编译下面
riscv64-unknown-elf-gcc
./configure --prefix=/opt/riscv
make
riscv64-unknown-linux-gnu-gcc
./configure --prefix=/opt/riscv --enable-multilib
make linux
5、下载riscv-tools
git clone https://github.com/riscv-software-src/riscv-tools
cd ./riscv-tools
6、安装依赖包
sudo apt-get install autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev libusb-1.0-0-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev device-tree-compiler pkg-config libexpat-dev
7、运行
git submodule update --init --recursive
export RISCV=/opt/riscv
./build.sh
5分钟左右,安装成功提示
RISC-V Toolchain installation completed!
8、创建一个代码hello.c
#include <stdio.h>
int main(){
printf("hello world!\n");
return 0;
}
9、编译
/opt/riscv/bin/riscv64-unknown-elf-gcc -o hello hello.c
10、执行
/opt/riscv/bin/spike pk ./hello
增加-m128参数,执行成功
/opt/riscv/bin/spike -m128 pk ./hello
参考:
https://blog.csdn.net/popebl/article/details/123829110
https://blog.csdn.net/nijino/article/details/119273504
标签:opt,riscv,RISCV,dev,学习,--,done,hello,模拟器 来源: https://www.cnblogs.com/zhaogaojian/p/16536003.html