From 608c1a56e30bc9fdfd2defa9d6b72c10148b97d5 Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Wed, 24 Mar 2010 21:33:45 +0200 Subject: [PATCH] Dump KVM_EXIT_IO details When KVM_RUN returns with KVM_EXIT_IO, dump the I/O details and exit. Signed-off-by: Pekka Enberg --- tools/kvm/kvm.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c index fac42f250d64..c245dfd2f982 100644 --- a/tools/kvm/kvm.c +++ b/tools/kvm/kvm.c @@ -282,6 +282,24 @@ static void kvm__reset_vcpu(struct kvm *self, uint64_t rip) self->regs.rflags = 0x0000000000000002ULL; } +static void kvm__emulate_io_out(struct kvm *self, uint16_t port, void *data, int size, uint32_t count) +{ + fprintf(stderr, "%s port=%x, size=%d, count=%" PRIu32 "\n", __func__, port, size, count); +} + +static void kvm__emulate_io_in(struct kvm *self, uint16_t port, void *data, int size, uint32_t count) +{ + fprintf(stderr, "%s port=%x, size=%d, count=%" PRIu32 "\n", __func__, port, size, count); +} + +static void kvm__emulate_io(struct kvm *self, uint16_t port, void *data, int direction, int size, uint32_t count) +{ + if (direction == KVM_EXIT_IO_IN) + kvm__emulate_io_in(self, port, data, size, count); + else + kvm__emulate_io_out(self, port, data, size, count); +} + int main(int argc, char *argv[]) { const char *kernel_filename; @@ -300,8 +318,25 @@ int main(int argc, char *argv[]) kvm__reset_vcpu(kvm, kernel_start); - kvm__run(kvm); + for (;;) { + kvm__run(kvm); + + switch (kvm->kvm_run->exit_reason) { + case KVM_EXIT_IO: + kvm__emulate_io(kvm, + kvm->kvm_run->io.port, + (uint8_t *)kvm->kvm_run + kvm->kvm_run->io.data_offset, + kvm->kvm_run->io.direction, + kvm->kvm_run->io.size, + kvm->kvm_run->io.count); + goto exit_kvm; + break; + default: + goto exit_kvm; + } + } +exit_kvm: fprintf(stderr, "KVM exit reason: %" PRIu32 " (\"%s\")\n", kvm->kvm_run->exit_reason, exit_reasons[kvm->kvm_run->exit_reason]); -- 2.39.5