Provide out of box docker image for the RISCV emulator.
- Docker
- Public network access
docker run -ti plincar/riscv-qemu-emulator:latest
You may need to wait until RISCV ubuntu image boot, and login with ubuntu:ubuntu
.
Note: The ubuntu system may require you change the password for first login.
sudo apt update
sudo apt install gcc -y
sudo apt install golang-go -y
-
Compile below C code with
riscv64-linux-gnu-gcc main.c -o c.out
.#include <stdio.h> int main() { printf("Hello, world!\n"); return 0; }
-
If everything goes well, you may see similar output from your terminal.
riscv64-linux-gnu-gcc main.c -o c.out ./c.out Hello, world! file c.out c.out: 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]=b5d550645bc6fbb2045c8b07d710ac9d7df44aad, for GNU/Linux 4.15.0, not stripped
-
Compile below Golang code with
go build -o go.out main.go
.package main import "fmt" func main() { fmt.Println("Hello, world!") }
-
If everything goes well, you may see similar output from your terminal.
go build -o go.out main.go ./go.out Hello, world! file go.out go.out: ELF 64-bit LSB executable, UCB RISC-V, double-float ABI, version 1 (SYSV), statically linked, Go BuildID=XdPV_KgaapQAF-7BJps-/JfxOKsmko9eaB0VUSH5r/WPPni_yjw6hJogCIMxRZ/xx6PLTsSTbmjFPmeY9eq, not stripped
-
From
lscpu
.Architecture: riscv64 Byte Order: Little Endian CPU(s): 4 On-line CPU(s) list: 0-3 NUMA: NUMA node(s): 1 NUMA node0 CPU(s): 0-3
-
From
cpuinfo
.processor : 0 hart : 3 isa : rv64imafdcsu mmu : sv48 processor : 1 hart : 0 isa : rv64imafdcsu mmu : sv48 processor : 2 hart : 1 isa : rv64imafdcsu mmu : sv48 processor : 3 hart : 2 isa : rv64imafdcsu mmu : sv48
- The performance of this emulator is not as fast as hardware due to qemu emulation.
docker run -ti plincar/riscv-gnu-toolchain:latest
The RV64 only toolchain installed under /opt/riscv/gnu-toolchain/rv64
, while the multilib toolchain installed under /opt/riscv/gnu-toolchain/multilib
.
-
Compile below C code with
riscv64-unknown-gnu-gcc main.c -o c.out
.#include <stdio.h> int main() { printf("Hello, world!\n"); return 0; }
-
If everything goes well, you can execute the binary with spike as blow.
/opt/riscv/gnu-toolchain/rv64/bin/spike /opt/riscv/gnu-toolchain/riscv64-unknown-elf/bin/pk64 c.out bbl loader Hello, world! file c.out c.out: 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]=b5d550645bc6fbb2045c8b07d710ac9d7df44aad, for GNU/Linux 4.15.0, not stripped
docker run -ti plincar/riscv-llvm-toolchain:latest
- The llvm toolchain installed under
/opt/riscv/llvm-toolchain/
. - The gnu toolchain installed under
/opt/riscv/gnu-toolchain/
.- There are three versions of gnu toolchain.
- The multi-lib version installed under
/opt/riscv/gnu-toolchain/multilib
. - The rv64 with spike version installed under
/opt/riscv/gnu-toolchain/rv64
. - The rvv-next version installed under
/opt/riscv/gnu-toolchain/rvv-next
.
- The multi-lib version installed under
- There are three versions of gnu toolchain.
-
Compile below C code with
/opt/riscv/llvm-toolchain/bin/clang -fuse-ld=lld main.c -o c.out
.#include <stdio.h> int main() { printf("Hello, world!\n"); return 0; }
-
If everything goes well, you can compile the binary with llvm linker as below.
root@97b5a88258c5:/tmp# /opt/riscv/llvm-toolchain/bin/clang -fuse-ld=lld main.c -o c.out root@97b5a88258c5:/tmp# file c.out c.out: 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, for GNU/Linux 4.15.0, not stripped