Skip to content

Commit

Permalink
Fix semihosting::debug::exit() on riscv64 QEMU targets.
Browse files Browse the repository at this point in the history
QEMU's handler for REPORT_EXCEPTION (a.k.a. TARGET_SYS_EXIT in QEMU sources)
expects two arguments for 64-bit systems, including riscv64. In the event
that a second argument is not provided, QEMU takes an error path which does
*not* exit the simulation.

The net result is that semihosting::debug::exit() hangs on riscv64 qemu
simulation.

Provide the necessry extra paramater to the syscall so that exit now
works properly.

Note that the second parameter only affects the simulator exit code if
the first parameter is ApplicationExit, and we use ApplicationExit only
for successful exit, so we can simply hardcode 0 as second parameter. On
the error path we set first parameter to RunTimeErrorUnknown and QEMU
properly returns exit code 1 regardless of second parameter.
  • Loading branch information
kevin-vigor authored and hegza committed May 29, 2024
1 parent 29edd7b commit afe3a98
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions riscv-semihosting/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Changed

- Made `cfg` variable selection more robust for custom targets
- Fixed debug::exit() on riscv64 QEMU simulation

## [v0.1.0] - 2023-01-18

Expand Down
4 changes: 4 additions & 0 deletions riscv-semihosting/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ pub fn exit(status: ExitStatus) {
pub fn report_exception(reason: Exception) {
let code = reason as usize;
unsafe {
#[cfg(target_arch = "riscv64")]
syscall!(REPORT_EXCEPTION, code, 0);

#[cfg(not(target_arch = "riscv64"))]
syscall1!(REPORT_EXCEPTION, code);
}
}

0 comments on commit afe3a98

Please sign in to comment.