QEMU with RISC-V Emulation Support
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 19 commits ahead, 20338 commits behind riscv:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
audio
backends
block
bsd-user
contrib
crypto
default-configs
disas
docs
dtc @ 65cc4d2
fpu
fsdev
gdb-xml
hacking_files
hw
include
libdecnumber
linux-headers
linux-user
migration
net
pc-bios
pixman @ 87eea99
po
qapi
qga
qobject
qom
replay
roms
scripts
slirp
stubs
target-alpha
target-arm
target-cris
target-i386
target-lm32
target-m68k
target-microblaze
target-mips
target-moxie
target-openrisc
target-ppc
target-riscv
target-s390x
target-sh4
target-sparc
target-tilegx
target-tricore
target-unicore32
target-xtensa
tcg
tests
trace
ui
util
.dir-locals.el
.exrc
.gitignore
.gitmodules
.mailmap
.travis.yml
CODING_STYLE
COPYING
COPYING.LIB
Changelog
HACKING
LICENSE
MAINTAINERS
Makefile
Makefile.objs
Makefile.target
README
README.md
VERSION
accel.c
aio-posix.c
aio-win32.c
arch_init.c
async.c
balloon.c
block.c
blockdev-nbd.c
blockdev.c
blockjob.c
bootdevice.c
bt-host.c
bt-vhci.c
configure
cpu-exec-common.c
cpu-exec.c
cpus.c
cputlb.c
device-hotplug.c
device_tree.c
disas.c
dma-helpers.c
dump.c
exec.c
gdbstub.c
hmp-commands-info.hx
hmp-commands.hx
hmp.c
hmp.h
iohandler.c
ioport.c
iothread.c
kvm-all.c
kvm-stub.c
main-loop.c
memory.c
memory_mapping.c
module-common.c
monitor.c
nbd.c
numa.c
os-posix.c
os-win32.c
page_cache.c
qapi-schema.json
qdev-monitor.c
qdict-test-data.txt
qemu-bridge-helper.c
qemu-char.c
qemu-doc.texi
qemu-ga.texi
qemu-img-cmds.hx
qemu-img.c
qemu-img.texi
qemu-io-cmds.c
qemu-io.c
qemu-log.c
qemu-nbd.c
qemu-nbd.texi
qemu-options-wrapper.h
qemu-options.h
qemu-options.hx
qemu-seccomp.c
qemu-tech.texi
qemu-timer.c
qemu.nsi
qemu.sasl
qjson.c
qmp-commands.hx
qmp.c
qtest.c
rules.mak
softmmu_template.h
spice-qemu-char.c
tcg-runtime.c
tci.c
thread-pool.c
thunk.c
tpm.c
trace-events
translate-all.c
translate-all.h
translate-common.c
user-exec.c
version.rc
vl.c
xen-common-stub.c
xen-common.c
xen-hvm-stub.c
xen-hvm.c
xen-mapcache.c

README.md

riscv-qemu Build Status

About:

The riscv-softmmu target for full system RV64G emulation is currently supported. It supports booting riscv-linux. Remote GDB debugging is also supported (see the section below).

RISC-V Port Authors:

Upstream QEMU Version:

  • v2.5.0

Notes:

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

Installation

Prerequisites:

$ 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

You can build vmlinux from the riscv-linux repo and a root filesystem using Buildroot or download the prebuilt copies below. You'll also need a copy of bbl.

a) vmlinux

b) rootfs.ext2

c) bbl

####Step 3: Run QEMU

To boot Linux (assuming you are in the riscv-qemu directory):

$ ./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.

####Current limitations:

  • The current RISC-V board definition provides only HTIF devices (syscall proxy for 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):

Coming soon!

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 TIMER_INTERVAL in riscv-tests/env/pt/riscv_test.h.

Using QEMU to Debug RISC-V Code:

QEMU works with riscv-gdb to enable remote debugging. This currently requires building gdb from a special version of riscv-gnu-toolchain, available here.

To use this, start QEMU with the additional flags -S -s:

$ ./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.

Separately, start riscv64-unknown-elf-gdb:

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

TODOs:

  • Additional device support

Notes

  • 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:
    • target-riscv/
    • hw/riscv/