riscv-softmmu target for full system RV64G emulation is currently supported.
It supports booting riscv-linux. Remote GDB debugging is also supported (see the
RISC-V Port Authors:
- Sagar Karandikar (email@example.com)
Upstream QEMU Version:
- The pre-rebase version of QEMU has been moved to a different repo. Going forward, only this repo will be updated and the old version will be removed. You can temporarily find the old version here.
$ sudo apt-get install gcc libc6-dev pkg-config bridge-utils uml-utilities zlib1g-dev libglib2.0-dev autoconf automake libtool libsdl1.2-dev
Method 1 (HTIF Devices):
####Step 1: Build QEMU
$ git clone https://github.com/riscv/riscv-qemu $ cd riscv-qemu $ git submodule update --init pixman $ ./configure --target-list=riscv-softmmu [--prefix=INSTALL_LOCATION] $ make $ [make install] # if you supplied prefix above
####Step 2: Obtain Images
####Step 3: Run QEMU
To boot Linux (assuming you are in the
$ ./riscv-softmmu/qemu-system-riscv -kernel bbl -append vmlinux -drive file=rootfs.ext2,format=raw -nographic
Notes about arguments:
-kernel bbl: This is the path to the bbl bootloader, included when riscv-tools is built.
-append vmlinux: The path to the linux kernel image.
-drive file=rootfs.ext2,format=raw: Your root filesystem. You can build one using Buildroot or download one above.
Useful optional arguments:
-m 128M: Set size of memory, in this example, 128 MB
IMPORTANT: To cleanly exit this system, you must enter
halt at the prompt
and then hit
ctrl-a x. Otherwise, the root filesystem will likely be corrupted.
- The current RISC-V board definition provides only HTIF devices (syscall
bbl, console, block device). These devices are experimental and will be replaced with standard devices. The console especially can fall behind under heavy use.
Method 2 (Standard Devices):
Running RISC-V Tests:
A script (
run-rv-tests.py) for running the RV64 tests from riscv-tests is
included in the
hacking_files directory. All RV64 tests are expected to pass,
however you will likely need to increase
Using QEMU to Debug RISC-V Code:
QEMU works with riscv-gdb to enable remote debugging. This currently requires
gdb from a special version of
To use this, start QEMU with the additional flags
$ ./riscv-softmmu/qemu-system-riscv -S -s -kernel bbl -append vmlinux -drive file=rootfs.ext2,format=raw -nographic
This will start QEMU, but immediately pause and wait for a gdb connection.
$ riscv64-unknown-elf-gdb [optional binary, e.g. vmlinux]
At the prompt, connect to QEMU:
(gdb) target remote localhost:1234
At this point, you can use regular gdb commands to singlestep, set breakpoints,
read/write registers, etc. If you type
continue in gdb, you can return to QEMU
and interact with the machine as if you were using it without GDB attached.
- Additional device support
- QEMU also supports a "linux-user" mode, however this is currently not implemented for RISC-V. For RISC-V, similar functionality can be obtained by using the proxy kernel instead of Linux.
- Files/directories of interest: