Debian Codegraph @

kdebug/exit.c

raw
1 /*
2 * See https://stackoverflow.com/questions/42208228/how-to-automatically-close-the-execution-of-the-qemu-after-end-of-process
3 */
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <sys/io.h>
7 #include <unistd.h>
8
9 #define SHUTDOWN_PORT 0x604
10 #define EXIT_PORT 0x501
11
12 static void clean_exit(void) {
13 ioperm(SHUTDOWN_PORT, 16, 1);
14 outw(0x2000, SHUTDOWN_PORT);
15 }
16
17 int main(int argc, char **argv) {
18 int status;
19 if (argc != 2) {
20 clean_exit();
21 }
22 status = atoi(argv[1]);
23 printf("exiting with status %d (in three seconds)\n", status);
24 sleep(3);
25 if (!status) {
26 clean_exit();
27 }
28 ioperm(EXIT_PORT, 8, 1);
29 /*
30 * status returned is 1+(2*orig_status)
31 */
32 outb(status-1, EXIT_PORT);
33 printf("didn't exit.. did you include '-device isa-debug-exit'"
34 " in qemu command?\n");
35 exit(1);
36 }