Skip to content

Incarnation-p-lee/riscv-docker-emulator

Repository files navigation

RISCV Docker Emulator

Provide out of box docker image for the RISCV emulator.

Precondition

  • Docker
  • Public network access

Qemu

How to Steps

Start the Docker Image

docker run -ti plincar/riscv-qemu-emulator:latest

Login the Docker Container

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.

Update Package and Install Toolchain.

sudo apt update
sudo apt install gcc -y
sudo apt install golang-go -y

Validate the C Programming Language

  1. 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;
    }
  2. 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
    

Validate the Golang Programming Language

  1. Compile below Golang code with go build -o go.out main.go.

    package main
    
    import "fmt"
    
    func main() {
    	fmt.Println("Hello, world!")
    }
  2. 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

Emulated RISCV CPU

  1. 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
  2. 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
    

Open Issues

  1. The performance of this emulator is not as fast as hardware due to qemu emulation.

GNU Toolchain

How to Steps

Start the Docker Image

docker run -ti plincar/riscv-gnu-toolchain:latest

Check the Toolchain Install Dir

The RV64 only toolchain installed under /opt/riscv/gnu-toolchain/rv64, while the multilib toolchain installed under /opt/riscv/gnu-toolchain/multilib.

Validate the C Programming Language

  1. 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;
    }
  2. 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
    

Open Issue

  • RV32 spike support, see this issue.
  • SSH url sub module, see this question.

LLVM Clang Tool Chain

How to Steps

Start the Docker Image

docker run -ti plincar/riscv-llvm-toolchain:latest

Check the Toolchain Install Dir

  • 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.

Validate the C Programming Language

  1. 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;
    }
  2. 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

Reference Link

About

Provide docker image for the RISCV emulator

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published