GitHub - riscv-software-src/riscv-isa-sim: Spike, a RISC-V ISA Simulator

GitHub - riscv-software-src/riscv-isa-sim: Spike, a RISC-V ISA Simulator

操作手册

$ apt-get install device-tree-compiler libboost-regex-dev libboost-system-dev

$ mkdir build

$ cd build

$ ../configure --prefix=$RISCV

$ make

$ [sudo] make install

具体安装

安装依赖

sudo apt-get install device-tree-compiler libboost-regex-dev libboost-system-dev

安装gcc编译器

sudo apt install gcc-riscv64-unknown-elf

git clone下载源码

git clone https://githubfast.com/riscv-software-src/riscv-isa-sim

编译

cd riscv-isa-sim
mkdir build
cd build
../configure --prefix=$RISCV
make -j 12
sudo make install

安装完成:

mkdir /include/softfloat
../scripts/mk-install-dirs.sh /include
for dir in fesvr       ; \
  do \
        ../scripts/mk-install-dirs.sh /include/$dir; \
    /usr/bin/install -c -m 644 config.h /include/$dir; \
  done
make: Circular libriscv.so <- libriscv.so dependency dropped.
make: Circular libcustomext.so <- libcustomext.so dependency dropped.
make: Circular libsoftfloat.so <- libsoftfloat.so dependency dropped.
../scripts/mk-install-dirs.sh /lib
for file in libfesvr.a libriscv.so libdisasm.a libcustomext.so libsoftfloat.so; \
  do \
    /usr/bin/install -c -m 644 $file /lib; \
  done
../scripts/mk-install-dirs.sh /bin
for file in elf2hex spike spike-log-parser xspike termios-xspike spike-dasm; \
  do \
    /usr/bin/install -c -m 755 $file /bin; \
  done
../scripts/mk-install-dirs.sh /lib/pkgconfig/
mkdir /lib/pkgconfig
for file in riscv-fesvr.pc riscv-riscv.pc riscv-disasm.pc; \
  do \
    /usr/bin/install -c -m 644 $file /lib/pkgconfig/; \
  done

Compiling and Running a Simple C Program

Install spike (see Build Steps), riscv-gnu-toolchain, and riscv-pk.

Write a short C program and name it hello.c. Then, compile it into a RISC-V ELF binary named hello:

$ riscv64-unknown-elf-gcc -o hello hello.c

Now you can simulate the program atop the proxy kernel:

$ spike pk hello

Simulating a New Instruction

Adding an instruction to the simulator requires two steps:

  1. Describe the instruction's functional behavior in the file riscv/insns/<new_instruction_name>.h. Examine other instructions in that directory as a starting point.

  2. Add the opcode and opcode mask to riscv/opcodes.h. Alternatively, add it to the riscv-opcodes package, and it will do so for you:

     $ cd ../riscv-opcodes
     $ vi opcodes       // add a line for the new instruction
     $ make install
    
  3. Add the instruction to riscv/riscv.mk.in. Otherwise, the instruction will not be included in the build and will be treated as an illegal instruction.

  4. Rebuild the simulator.

调试

编译报错fatal error: stdio.h: No such file or directory

riscv64-unknown-elf-gcc -o hello hello.c

hello.c:1:10: fatal error: stdio.h: No such file or directory

1 | #include <stdio.h>

| ^~~~~~~~~

compilation terminated.

没有解决

安装gcc-riscv64-linux-gnu试试

sudo apt install gcc-riscv64-linux-gnu

然后用这条命令:

riscv64-linux-gnu-gcc -o hello hello.c
skywalk@DESKTOP-9C5AU01:~/work$ file hello
hello: ELF 64-bit LSB pie executable, UCB RISC-V, RVC, double-float ABI, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-riscv64-lp64d.so.1, BuildID[sha1]=2fbc3940bdd6f61378b1a8629c6bac6f89b9aa41, for GNU/Linux 4.15.0, not stripped

编译成功!

运行spike pk hello报错could not open pk; searched paths:

spike pk hello

terminate called after throwing an instance of 'std::runtime_error'

what(): could not open pk; searched paths:

. (current directory)

/riscv64-unknown-elf/bin/ (based on configured --prefix and --with-target)

相关推荐
2401_858286111 分钟前
123.【C语言】数据结构之快速排序挖坑法和前后指针法
c语言·开发语言·数据结构·算法·排序算法
一水鉴天6 分钟前
为AI聊天工具添加一个知识系统 之27 支持边缘计算设备的资源存储库及管理器
数据库·人工智能·前端框架
_WndProc10 分钟前
【C++/控制台】2048小游戏
开发语言·c++·游戏·游戏程序
白白白白纸呀12 分钟前
ADO.NET知识总结6---SqlDataAdapter桥接器
开发语言·c#·.net
C++小厨神20 分钟前
SQL语言的函数实现
开发语言·后端·golang
闲人编程32 分钟前
CAPL概述与环境搭建
开发语言·自动化测试·数据分析·capl·canoe·故障注入·canalyzer
网硕互联的小客服1 小时前
云服务器加了安全组端口还是无法访问
开发语言·php
倔强的石头1061 小时前
【C++经典例题】求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句
开发语言·c++
九离十1 小时前
C语言教程——指针进阶(1)
c语言·开发语言
DevOpsDojo1 小时前
Julia语言的软件工程
开发语言·后端·golang