[PATCH 14 of 19] Move print_seg & Move kvm_show_regs to kvmctl-x86.c

Jerone Young
2007-11-02T18:25:03Z

# Date 1194027873 18000
# Node ID 68585a137682a876dd438782147445f4484146ce
# Parent 5bb5ef1b7faa8c11677b73fedbe089d0926ca4e9
Move print_seg & Move kvm_show_regs to kvmctl-x86.c

This patch moves functions print_seg, kvm_show_regs, & print_dt
to libkvm-x86.c. Since kvm_show_regs really has little
to no shared code (besides an ioctl call and variable
declarations), it is best that this be moved into
arch specific code.

Signed-off-by: Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>

diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c
--- a/libkvm/libkvm-x86.c
+++ b/libkvm/libkvm-x86.c
@@ -698,3 +698,63 @@ int kvm_set_msrs(kvm_context_t kvm, int
return r;
}

+static void print_seg(FILE *file, const char *name, struct kvm_segment *seg)
+{
+ fprintf(stderr,
+ "%s %04x (%08llx/%08x p %d dpl %d db %d s %d type %x l %d"
+ " g %d avl %d)\n",
+ name, seg->selector, seg->base, seg->limit, seg->present,
+ seg->dpl, seg->db, seg->s, seg->type, seg->l, seg->g,
+ seg->avl);
+}
+
+static void print_dt(FILE *file, const char *name, struct kvm_dtable *dt)
+{
+ fprintf(stderr, "%s %llx/%x\n", name, dt->base, dt->limit);
+}
+
+void kvm_show_regs(kvm_context_t kvm, int vcpu)
+{
+ int fd = kvm->vcpu_fd[vcpu];
+ struct kvm_regs regs;
+ struct kvm_sregs sregs;
+ int r;
+
+ r = ioctl(fd, KVM_GET_REGS, &regs);
+ if (r == -1) {
+ perror("KVM_GET_REGS");
+ return;
+ }
+ fprintf(stderr,
+ "rax %016llx rbx %016llx rcx %016llx rdx %016llx\n"
+ "rsi %016llx rdi %016llx rsp %016llx rbp %016llx\n"
+ "r8 %016llx r9 %016llx r10 %016llx r11 %016llx\n"
+ "r12 %016llx r13 %016llx r14 %016llx r15 %016llx\n"
+ "rip %016llx rflags %08llx\n",
+ regs.rax, regs.rbx, regs.rcx, regs.rdx,
+ regs.rsi, regs.rdi, regs.rsp, regs.rbp,
+ regs.r8, regs.r9, regs.r10, regs.r11,
+ regs.r12, regs.r13, regs.r14, regs.r15,
+ regs.rip, regs.rflags);
+ r = ioctl(fd, KVM_GET_SREGS, &sregs);
+ if (r == -1) {
+ perror("KVM_GET_SREGS");
+ return;
+ }
+ print_seg(stderr, "cs", &sregs.cs);
+ print_seg(stderr, "ds", &sregs.ds);
+ print_seg(stderr, "es", &sregs.es);
+ print_seg(stderr, "ss", &sregs.ss);
+ print_seg(stderr, "fs", &sregs.fs);
+ print_seg(stderr, "gs", &sregs.gs);
+ print_seg(stderr, "tr", &sregs.tr);
+ print_seg(stderr, "ldt", &sregs.ldt);
+ print_dt(stderr, "gdt", &sregs.gdt);
+ print_dt(stderr, "idt", &sregs.idt);
+ fprintf(stderr, "cr0 %llx cr2 %llx cr3 %llx cr4 %llx cr8 %llx"
+ " efer %llx\n",
+ sregs.cr0, sregs.cr2, sregs.cr3, sregs.cr4, sregs.cr8,
+ sregs.efer);
+}
+
+
diff --git a/libkvm/libkvm-x86.h b/libkvm/libkvm-x86.h
--- a/libkvm/libkvm-x86.h
+++ b/libkvm/libkvm-x86.h
@@ -55,4 +55,19 @@ int kvm_set_lapic(kvm_context_t kvm, int

#endif

+/*!
+ * \brief Dump VCPU registers
+ *
+ * This dumps some of the information that KVM has about a virtual CPU, namely:
+ * - GP Registers
+ *
+ * A much more verbose version of this is available as kvm_dump_vcpu()
+ *
+ * \param kvm Pointer to the current kvm_context
+ * \param vcpu Which virtual CPU should get dumped
+ * \return 0 on success
+ */
+void kvm_show_regs(kvm_context_t kvm, int vcpu);
+
+
#endif
diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
--- a/libkvm/libkvm.c
+++ b/libkvm/libkvm.c
@@ -635,65 +635,6 @@ int kvm_set_sregs(kvm_context_t kvm, int
return ioctl(kvm->vcpu_fd[vcpu], KVM_SET_SREGS, sregs);
}

-static void print_seg(FILE *file, const char *name, struct kvm_segment *seg)
-{
- fprintf(stderr,
- "%s %04x (%08llx/%08x p %d dpl %d db %d s %d type %x l %d"
- " g %d avl %d)\n",
- name, seg->selector, seg->base, seg->limit, seg->present,
- seg->dpl, seg->db, seg->s, seg->type, seg->l, seg->g,
- seg->avl);
-}
-
-static void print_dt(FILE *file, const char *name, struct kvm_dtable *dt)
-{
- fprintf(stderr, "%s %llx/%x\n", name, dt->base, dt->limit);
-}
-
-void kvm_show_regs(kvm_context_t kvm, int vcpu)
-{
- int fd = kvm->vcpu_fd[vcpu];
- struct kvm_regs regs;
- struct kvm_sregs sregs;
- int r;
-
- r = ioctl(fd, KVM_GET_REGS, &regs);
- if (r == -1) {
- perror("KVM_GET_REGS");
- return;
- }
- fprintf(stderr,
- "rax %016llx rbx %016llx rcx %016llx rdx %016llx\n"
- "rsi %016llx rdi %016llx rsp %016llx rbp %016llx\n"
- "r8 %016llx r9 %016llx r10 %016llx r11 %016llx\n"
- "r12 %016llx r13 %016llx r14 %016llx r15 %016llx\n"
- "rip %016llx rflags %08llx\n",
- regs.rax, regs.rbx, regs.rcx, regs.rdx,
- regs.rsi, regs.rdi, regs.rsp, regs.rbp,
- regs.r8, regs.r9, regs.r10, regs.r11,
- regs.r12, regs.r13, regs.r14, regs.r15,
- regs.rip, regs.rflags);
- r = ioctl(fd, KVM_GET_SREGS, &sregs);
- if (r == -1) {
- perror("KVM_GET_SREGS");
- return;
- }
- print_seg(stderr, "cs", &sregs.cs);
- print_seg(stderr, "ds", &sregs.ds);
- print_seg(stderr, "es", &sregs.es);
- print_seg(stderr, "ss", &sregs.ss);
- print_seg(stderr, "fs", &sregs.fs);
- print_seg(stderr, "gs", &sregs.gs);
- print_seg(stderr, "tr", &sregs.tr);
- print_seg(stderr, "ldt", &sregs.ldt);
- print_dt(stderr, "gdt", &sregs.gdt);
- print_dt(stderr, "idt", &sregs.idt);
- fprintf(stderr, "cr0 %llx cr2 %llx cr3 %llx cr4 %llx cr8 %llx"
- " efer %llx\n",
- sregs.cr0, sregs.cr2, sregs.cr3, sregs.cr4, sregs.cr8,
- sregs.efer);
-}
-
static int handle_mmio(kvm_context_t kvm, struct kvm_run *kvm_run)
{
unsigned long addr = kvm_run->mmio.phys_addr;
diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h
--- a/libkvm/libkvm.h
+++ b/libkvm/libkvm.h
@@ -399,20 +399,6 @@ int kvm_set_signal_mask(kvm_context_t kv
*/
int kvm_dump_vcpu(kvm_context_t kvm, int vcpu);

-/*!
- * \brief Dump VCPU registers
- *
- * This dumps some of the information that KVM has about a virtual CPU, namely:
- * - GP Registers
- *
- * A much more verbose version of this is available as kvm_dump_vcpu()
- *
- * \param kvm Pointer to the current kvm_context
- * \param vcpu Which virtual CPU should get dumped
- * \return 0 on success
- */
-void kvm_show_regs(kvm_context_t kvm, int vcpu);
-

void kvm_destroy_phys_mem(kvm_context_t, unsigned long phys_start,
unsigned long len);