RISCV模拟器安装过程

在Ubuntu 20.04上安装了一个RISCV模拟器,记录一下安装的全过程:

  1. 从GitHub克隆riscv-toolchain:      

git clone https://github.com/riscv/riscv-gnu-toolchain 

  1. 安装相关依赖库:     

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

  1. 进入riscv-gnu-toolchain目录,编译(需要2个多小时)

    ./configure --prefix=/opt/riscv --enable-multilib
    sudo make
    sudo make linux

如果后续步骤有问题,分别编译下面

riscv64-unknown-elf-gcc 

    ./configure --prefix=/opt/riscv
    sudo make

riscv64-unknown-linux-gnu-gcc 

    ./configure --prefix=/opt/riscv --enable-multilib
    sudo make linux

  1. 下载riscv-tools

git clone https://github.com/riscv-software-src/riscv-tools
cd ./riscv-tools

  1. 安装依赖包

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

  1. 运行

git submodule update --init --recursive
export RISCV=/opt/riscv
./build.sh

如果报错:Please set the RISCV environment variable to your preferred install path

su    #切换到root
export RISCV=/opt/riscv 
./build-spike-pk.sh

5分钟左右安装成功,提示:

RISC-V Toolchain installation completed!

  1. 创建一个代码hello.c

#include <stdio.h>
int main(){
    printf("hello world!\n");
    return 0;
}

  1. 编译

/opt/riscv/bin/riscv64-unknown-elf-gcc -o hello hello.c

9、执行

/opt/riscv/bin/spike pk ./hello

注意: 这里可能会产生一个错误:

bad syscall #90463429510455458

解决方法: 修改riscv-tools/riscv-pk/util/string.c,在memset函数前后添加三行#pragma:

#pragma GCC push_options
#pragma GCC optimize ("no-tree-loop-distribute-patterns")
void* memset(void* dest, int byte, size_t len)
{
  if ((((uintptr_t)dest | len) & (sizeof(uintptr_t)-1)) == 0) {
    uintptr_t word = byte & 0xFF;
    word |= word << 8;
    word |= word << 16;
    word |= word << 16 << 16;
    uintptr_t *d = dest;
    while (d < (uintptr_t*)(dest + len))
      *d++ = word;
  } else {
    char *d = dest;
    while (d < (char*)(dest + len))
      *d++ = byte;
  }
  return dest;
}
#pragma GCC pop_options

然后进入riscv-tools目录,重新编译./build-spike-pk.sh后,运行/opt/riscv/bin/spike pk ./hello。

参考:

https://www.cnblogs.com/zhaogaojian/p/16536003.html

https://blog.csdn.net/m0_69754566/article/details/125941663

https://blog.csdn.net/nijino/article/details/119273504

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值