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::exit() on riscv64 QEMU targets. #215

Closed
wants to merge 1 commit into from

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 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 17:20
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
Copy link
Contributor Author

Hold off, I just tested this on riscv32 target and return error codes are broken by this change. Will resubmit.

@taiki-e
Copy link
Contributor

taiki-e commented May 24, 2024

SYS_EXIT has the different API on 32-bit and 64-bit:

32-bit

On entry, the PARAMETER register is set to a reason code describing the cause of the trap.

64-bit

On entry, the PARAMETER REGISTER contains a pointer to a two-field argument block:

The master branch is correct for 32-bit and this PR is correct for 64-bit.

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