Skip to content

Commit aa73a86

Browse files
wtarreaupaulmckrcu
authored andcommitted
selftests/nolibc: on x86, support exiting with isa-debug-exit
QEMU, when started with "-device isa-debug-exit -no-reboot" will exit with status code 2N+1 when N is written to 0x501. This is particularly convenient for automated tests but this is not portable. As such we only enable this on x86_64 when pid==1. In addition, this requires an ioperm() call but in order not to have to define arch-specific syscalls we just perform the syscall by hand there. Signed-off-by: Willy Tarreau <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
1 parent f49896d commit aa73a86

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

tools/testing/selftests/nolibc/nolibc-test.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,15 @@ int main(int argc, char **argv, char **envp)
638638
printf("Leaving init with final status: %d\n", !!ret);
639639
if (ret == 0)
640640
reboot(LINUX_REBOOT_CMD_POWER_OFF);
641+
#if defined(__x86_64__)
642+
/* QEMU started with "-device isa-debug-exit -no-reboot" will
643+
* exit with status code 2N+1 when N is written to 0x501. We
644+
* hard-code the syscall here as it's arch-dependent.
645+
*/
646+
else if (my_syscall3(__NR_ioperm, 0x501, 1, 1) == 0)
647+
asm volatile ("outb %%al, %%dx" :: "d"(0x501), "a"(0));
648+
/* if it does nothing, fall back to the regular panic */
649+
#endif
641650
}
642651

643652
printf("Exiting with status %d\n", !!ret);

0 commit comments

Comments
 (0)