#include "kvm/pci.h"
#include <inttypes.h>
+#include <termios.h>
+#include <unistd.h>
#include <signal.h>
#include <stdint.h>
#include <stdlib.h>
static struct kvm *kvm;
+static void tty_set_canon_flag(int fd, int on)
+{
+ struct termios tty;
+ int mask = ISTRIP | INLCR | ICRNL | IGNCR | IXON | IXOFF | ICANON | ECHO;
+
+ tcgetattr(fd, &tty);
+ if (on)
+ tty.c_lflag |= mask;
+ else
+ tty.c_lflag &= ~mask;
+ tcsetattr(fd, TCSAFLUSH, &tty);
+}
+
+static void shutdown(void)
+{
+ tty_set_canon_flag(fileno(stdin), 0);
+}
+
+static void handle_sigint(int sig)
+{
+ shutdown();
+ exit(1);
+}
+
static void handle_sigquit(int sig)
{
kvm__show_registers(kvm);
die("timer_settime()");
}
-
int main(int argc, char *argv[])
{
const char *kernel_filename = NULL;
bool single_step = false;
int i;
+ atexit(shutdown);
+
signal(SIGQUIT, handle_sigquit);
+ signal(SIGINT, handle_sigint);
for (i = 1; i < argc; i++) {
if (option_matches(argv[i], "--kernel=")) {
setup_timer();
+ tty_set_canon_flag(fileno(stdin), 1);
+
for (;;) {
kvm__run(kvm);