Fix semihosting::debug::exit() on riscv64 QEMU targets. #216
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 necessary extra parameter 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
.Note: tested for both rv32 and rv64 targets with https://github.com/kevin-vigor/test-riscv-semihosting-exit