13 releases (8 stable)

3.0.2 Jul 12, 2023
3.0.1 Jan 15, 2022
3.0.0 Dec 17, 2021
2.0.1 Jul 6, 2021
0.1.0 Dec 3, 2019

#55 in Embedded development

Download history 759/week @ 2023-06-06 805/week @ 2023-06-13 990/week @ 2023-06-20 727/week @ 2023-06-27 788/week @ 2023-07-04 663/week @ 2023-07-11 972/week @ 2023-07-18 788/week @ 2023-07-25 1019/week @ 2023-08-01 1265/week @ 2023-08-08 1015/week @ 2023-08-15 1464/week @ 2023-08-22 840/week @ 2023-08-29 788/week @ 2023-09-05 745/week @ 2023-09-12 771/week @ 2023-09-19

3,340 downloads per month
Used in 3 crates


146 lines

Contains (ELF exe/lib, 640KB) tests/riscv64_virt/fw_jump.elf

crates.io crates.io Build Test


Exit QEMU with user-defined code.

Quit a running QEMU session with user-defined exit code. Useful for unit or integration tests using QEMU.


use qemu_exit::QEMUExit;

#[cfg(target_arch = "aarch64")]
let qemu_exit_handle = qemu_exit::AArch64::new();

// addr: The address of sifive_test.
#[cfg(target_arch = "riscv64")]
let qemu_exit_handle = qemu_exit::RISCV64::new(addr);

// io_base:             I/O-base of isa-debug-exit.
// custom_exit_success: A custom success code; Must be an odd number.
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
let qemu_exit_handle = qemu_exit::X86::new(io_base, custom_exit_success);


Architecture Specific Configuration


Pass the -semihosting argument to the QEMU invocation, e.g.:

qemu-system-aarch64 -M raspi3 -serial stdio -semihosting -kernel kernel8.img


You need to chose a machine with the sifive_test device, for exemple -M virt:

qemu-system-riscv64 -M virt -nographic -monitor none -serial stdio -kernel kernel.elf


Add the special ISA debug exit device by passing the flags:

-device isa-debug-exit,iobase=0xf4,iosize=0x04

When instantiating the handle, iobase must be given as the first parameter.

The second parameter must be an EXIT_SUCCESS code of your choice that is an odd number, aka bit number zero must be 1. This is needed because in QEMU, the provided code is internally binary-OR'ed with 0x1. This is hardcoded and therefore, with isa-debug-exit, it is not possible to let QEMU invoke exit(0).

let qemu_exit_handle = qemu_exit::X86::new(io_base, custom_exit_success);




Licensed under either of

at your option.

See the THIRD_PARTY_NOTICES.md for more information about utilized third party projects and their respective licenses.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps