Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix semihosting::debug::exit() on riscv64 QEMU targets. #216

Merged
merged 1 commit into from
May 24, 2024

Conversation

kevin-vigor
Copy link
Contributor

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

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.
@kevin-vigor kevin-vigor requested a review from a team as a code owner May 24, 2024 18:21
Copy link
Contributor

@romancardenas romancardenas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@romancardenas romancardenas added this pull request to the merge queue May 24, 2024
Merged via the queue into rust-embedded:master with commit ee84d85 May 24, 2024
95 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants