不用開發板也能學習RISC-V

前言:

因工作需求開始接觸RISC-V OS,在手邊未有開發板的狀況下,先使用模擬器的方式來了解RISC-V的底下撰寫的程式碼及編譯方式,網路上找了許多資料以下方式比較容易搭建環境,本篇博文使用Ubuntu 18.04安裝 Spike RISC-V 32位元。

 

依賴項目安裝:

$ sudo apt-get install -y 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 \
gcc-riscv64-linux-gnu device-tree-compiler​

 

Clone相關Tools

$ mkdir RISCV
$ cd RISCV
$ git clone --recursive https://github.com/riscv-collab/riscv-gnu-toolchain
$ git clone https://github.com/riscv-software-src/riscv-pk
$ git clone https://github.com/riscv-software-src/riscv-isa-sim

 

設定環境變數.bashrc

$ gedit ~/.bashrc

底下新增

export RISCV=/home/ubuntu/RISC-V/riscv-gnu-toolchain_install (Your own RISCV path)
export PATH=$PATH:$RISCV/bin

 

編譯RISC-V GNU Toolchain

$ cd riscv-gnu-toolchain
$ mkdir build
$ cd build
$ ../configure --prefix=$RISCV --with-arch=rv32i
$ make

 

編譯Proxy Kernel

$ cd ../../riscv-pk
$ mkdir build
$ cd build
$ ../configure --prefix=$RISCV --host=riscv32-unknown-elf
$ make
$ make install

 

編譯Spike

$ cd ../../riscv-isa-sim

$ mkdir build
$ cd build
$ ../configure --prefix=$RISCV --enable-histogram
$ make
$ make install

 

測試:

建立Hello.c程式碼如下:

#include <stdio.h>

int main() {
printf("Hello world!\n");
}

 

編譯Hello.c程式碼:

$ riscv32-unknown-elf-gcc Hello.c

 

執行:

$ spike --isa=RV32IMAC /home/ubuntu/RISC-V/riscv-pk/build/pk a.out

$ spike --dump-dts a.out

  

小結:

透過Spike模擬器即可操作RISC-V指令,無需硬體開發板,但如果需要操作周邊IO,則需要開發版支持,不然無法看到實際顯示結果,感謝觀看本博文。

 

參考:

深入理解基于RISC-V ISS Spike的仿真系统:探索Spike,pk和fesrv

RISC-V GNU Compiler Toolchain

RISC-V Proxy Kernel and Boot Loader

Spike RISC-V ISA Simulator

★博文內容均由個人提供,與平台無關,如有違法或侵權,請與網站管理員聯繫。

★文明上網,請理性發言。內容一周內被舉報5次,發文人進小黑屋喔~

評論