Skip to content

Commit ff4dc30

Browse files
committed
Fix semihosting::debug::exit() on riscv64 QEMU targets.
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.
1 parent 2fc23fe commit ff4dc30

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

riscv-semihosting/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
88
### Changed
99

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

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

riscv-semihosting/src/debug.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ pub fn exit(status: ExitStatus) {
8989
pub fn report_exception(reason: Exception) {
9090
let code = reason as usize;
9191
unsafe {
92+
#[cfg(target_arch = "riscv64")]
93+
syscall!(REPORT_EXCEPTION, code, 0);
94+
95+
#[cfg(not(target_arch = "riscv64"))]
9296
syscall1!(REPORT_EXCEPTION, code);
9397
}
9498
}

0 commit comments

Comments
 (0)