semihosting

crates.io docs.rs license rustc build status

Semihosting for AArch64, ARM, RISC-V (RV32 & RV64), MIPS, and MIPS64.

This library provides access to semihosting, a mechanism for programs running on the real or virtual (e.g., QEMU) target to communicate with I/O facilities on the host system. See the ARM documentation for more information on semihosting.

APIs are categorized into the following four types:

Additionally, this library provides a panic handler for semihosting and -C panic=unwind support, via optional features.

Platform Support

The following target architectures are supported:

| target_arch | Specification | semihosting::sys module | | ----------- | ------------- | ------------------------- | | arm/aarch64 | Semihosting for AArch32 and AArch64 | sys::arm_compat | | riscv32/riscv64 | RISC-V Semihosting | sys::arm_compat | | mips/mips64 | Unified Hosting Interface (MD01069) | sys::mips |

The host must be running an emulator or a debugger attached to the target.

The following targets have been tested on CI. (qemu-system has been tested on Linux, macOS, and Windows hosts, and qemu-user on Linux host.)

| target | exit | all-apis [1] (qemu-system) | all-apis [1] (qemu-user) | panic-unwind (qemu-system [2]) | | ------------------------------------ | ---- | --------------------------- | ------------------------- | ------------------------------- | | aarch64-unknown-none{,-softfloat} | ✓ | ✓ | ✓ | ✓ | | {arm,thumb}v4t-none-eabi | ✓ | | ✓ | | | {arm,thumb}v5te-none-eabi | ✓ | | ✓ | | | armv7a-none-eabi{,hf} | ✓ | ✓ | ✓ | | | armv7r-none-eabi{,hf} | ✓ | ✓ | ✓ | | | armebv7r-none-eabi{,hf} | ✓ | | ✓ | | | thumbv6m-none-eabi | ✓ | ✓ | N/A | | | thumbv7m-none-eabi | ✓ | ✓ | N/A | | | thumbv7em-none-eabi{,hf} | ✓ | ✓ | N/A | | | thumbv8m.base-none-eabi | ✓ | * [3] | N/A | | | thumbv8m.main-none-eabi{,hf} | ✓ | * [3] | N/A | | | riscv32*-unknown-none-elf | ✓ | ✓ | ✓ | ✓ [4] | | riscv64*-unknown-none-elf | ✓ | ✓ | ✓ | ✓ | | mips{,el}-unknown-none [5] | ✓ | ✓ | N/A | | | mips64{,el}-unknown-none [5] | ✓ | ✓ | N/A | |

[1] stdio, fs, time, and args.
[2] I'm not sure how to test panic-unwind on qemu-user.
[3] It works if the host OS is Linux, but not if the host OS is any other OS. It is not clear whether the actual problem is in the host OS or the QEMU version.
[4] RISC-V RV32 support for panic-unwind requires a patch that has not yet been upstream.)
[5] Requires nightly due to #![feature(asm_experimental_arch)].

Optional features

All features are disabled by default.

In general use cases, you probably only need the stdio feature that enables print-related macros and/or the panic-handler feature that exits with a non-zero error code on panic.

toml [dependencies] semihosting = { version = "0.1", features = ["stdio", "panic-handler"] }

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

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.