mirror of
https://github.com/clearlinux/kvmtool.git
synced 2026-10-17 22:22:45 +00:00
We start KVM in 16-bit mode so we should set cs:ip to point to the real-mode boot sector and setup code, not the protected mode kernel that starts at 1M. Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
62 lines
1.1 KiB
C
62 lines
1.1 KiB
C
#include "kvm/kvm.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include <inttypes.h>
|
|
#include <stdint.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
|
|
static void usage(char *argv[])
|
|
{
|
|
fprintf(stderr, " usage: %s <kernel-image>\n", argv[0]);
|
|
exit(1);
|
|
}
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
const char *kernel_filename;
|
|
struct kvm *kvm;
|
|
|
|
if (argc < 2)
|
|
usage(argv);
|
|
|
|
kernel_filename = argv[1];
|
|
|
|
kvm = kvm__init();
|
|
|
|
if (!kvm__load_kernel(kvm, kernel_filename))
|
|
die("unable to load kernel %s", kernel_filename);
|
|
|
|
kvm__reset_vcpu(kvm);
|
|
|
|
kvm__enable_singlestep(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, kvm_exit_reasons[kvm->kvm_run->exit_reason]);
|
|
|
|
kvm__show_registers(kvm);
|
|
kvm__show_code(kvm);
|
|
|
|
return 0;
|
|
}
|