Use fprintf() for printing user TFs
authorBarret Rhoden <brho@cs.berkeley.edu>
Fri, 13 Jan 2017 21:15:54 +0000 (16:15 -0500)
committerBarret Rhoden <brho@cs.berkeley.edu>
Wed, 18 Jan 2017 15:00:02 +0000 (10:00 -0500)
This allows us to consolidate similar TF-printing code, and in the case of
the VM, see more info.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
user/parlib/include/parlib/vcore.h
user/parlib/x86/vcore.c
user/vmm/vmx.c

index feffd83..c0be1de 100644 (file)
@@ -6,6 +6,7 @@
 #include <string.h>
 #include <parlib/timing.h>
 #include <parlib/common.h>
 #include <string.h>
 #include <parlib/timing.h>
 #include <parlib/common.h>
+#include <stdio.h>
 
 __BEGIN_DECLS
 
 
 __BEGIN_DECLS
 
@@ -65,8 +66,9 @@ void cpu_relax_vc(uint32_t vcoreid);
 uint32_t get_vcoreid(void);
 bool check_vcoreid(const char *str, uint32_t vcoreid);
 void __attribute__((noreturn)) vcore_yield_or_restart(void);
 uint32_t get_vcoreid(void);
 bool check_vcoreid(const char *str, uint32_t vcoreid);
 void __attribute__((noreturn)) vcore_yield_or_restart(void);
-void print_hw_tf(struct hw_trapframe *tf);
-void print_sw_tf(struct sw_trapframe *sw_tf);
+void fprintf_hw_tf(FILE *f, struct hw_trapframe *hw_tf);
+void fprintf_sw_tf(FILE *f, struct sw_trapframe *sw_tf);
+void fprintf_vm_tf(FILE *f, struct vm_trapframe *vm_tf);
 void print_user_context(struct user_context *ctx);
 
 /* This works so long as we don't dlopen parlib (which we never do) */
 void print_user_context(struct user_context *ctx);
 
 /* This works so long as we don't dlopen parlib (which we never do) */
index 5a4e8ab..a56e79e 100644 (file)
@@ -301,98 +301,98 @@ void pop_user_ctx_raw(struct user_context *ctx, uint32_t vcoreid)
                      : "memory");
 }
 
                      : "memory");
 }
 
-void print_hw_tf(struct hw_trapframe *hw_tf)
+void fprintf_hw_tf(FILE *f, struct hw_trapframe *hw_tf)
 {
 {
-       printf("[user] HW TRAP frame 0x%016x\n", hw_tf);
-       printf("  rax  0x%016lx\n",           hw_tf->tf_rax);
-       printf("  rbx  0x%016lx\n",           hw_tf->tf_rbx);
-       printf("  rcx  0x%016lx\n",           hw_tf->tf_rcx);
-       printf("  rdx  0x%016lx\n",           hw_tf->tf_rdx);
-       printf("  rbp  0x%016lx\n",           hw_tf->tf_rbp);
-       printf("  rsi  0x%016lx\n",           hw_tf->tf_rsi);
-       printf("  rdi  0x%016lx\n",           hw_tf->tf_rdi);
-       printf("  r8   0x%016lx\n",           hw_tf->tf_r8);
-       printf("  r9   0x%016lx\n",           hw_tf->tf_r9);
-       printf("  r10  0x%016lx\n",           hw_tf->tf_r10);
-       printf("  r11  0x%016lx\n",           hw_tf->tf_r11);
-       printf("  r12  0x%016lx\n",           hw_tf->tf_r12);
-       printf("  r13  0x%016lx\n",           hw_tf->tf_r13);
-       printf("  r14  0x%016lx\n",           hw_tf->tf_r14);
-       printf("  r15  0x%016lx\n",           hw_tf->tf_r15);
-       printf("  trap 0x%08x\n",             hw_tf->tf_trapno);
-       printf("  gsbs 0x%016lx\n",           hw_tf->tf_gsbase);
-       printf("  fsbs 0x%016lx\n",           hw_tf->tf_fsbase);
-       printf("  err  0x--------%08x\n",     hw_tf->tf_err);
-       printf("  rip  0x%016lx\n",           hw_tf->tf_rip);
-       printf("  cs   0x------------%04x\n", hw_tf->tf_cs);
-       printf("  flag 0x%016lx\n",           hw_tf->tf_rflags);
-       printf("  rsp  0x%016lx\n",           hw_tf->tf_rsp);
-       printf("  ss   0x------------%04x\n", hw_tf->tf_ss);
+       fprintf(f, "[user] HW TRAP frame 0x%016x\n", hw_tf);
+       fprintf(f, "  rax  0x%016lx\n",           hw_tf->tf_rax);
+       fprintf(f, "  rbx  0x%016lx\n",           hw_tf->tf_rbx);
+       fprintf(f, "  rcx  0x%016lx\n",           hw_tf->tf_rcx);
+       fprintf(f, "  rdx  0x%016lx\n",           hw_tf->tf_rdx);
+       fprintf(f, "  rbp  0x%016lx\n",           hw_tf->tf_rbp);
+       fprintf(f, "  rsi  0x%016lx\n",           hw_tf->tf_rsi);
+       fprintf(f, "  rdi  0x%016lx\n",           hw_tf->tf_rdi);
+       fprintf(f, "  r8   0x%016lx\n",           hw_tf->tf_r8);
+       fprintf(f, "  r9   0x%016lx\n",           hw_tf->tf_r9);
+       fprintf(f, "  r10  0x%016lx\n",           hw_tf->tf_r10);
+       fprintf(f, "  r11  0x%016lx\n",           hw_tf->tf_r11);
+       fprintf(f, "  r12  0x%016lx\n",           hw_tf->tf_r12);
+       fprintf(f, "  r13  0x%016lx\n",           hw_tf->tf_r13);
+       fprintf(f, "  r14  0x%016lx\n",           hw_tf->tf_r14);
+       fprintf(f, "  r15  0x%016lx\n",           hw_tf->tf_r15);
+       fprintf(f, "  trap 0x%08x\n",             hw_tf->tf_trapno);
+       fprintf(f, "  gsbs 0x%016lx\n",           hw_tf->tf_gsbase);
+       fprintf(f, "  fsbs 0x%016lx\n",           hw_tf->tf_fsbase);
+       fprintf(f, "  err  0x--------%08x\n",     hw_tf->tf_err);
+       fprintf(f, "  rip  0x%016lx\n",           hw_tf->tf_rip);
+       fprintf(f, "  cs   0x------------%04x\n", hw_tf->tf_cs);
+       fprintf(f, "  flag 0x%016lx\n",           hw_tf->tf_rflags);
+       fprintf(f, "  rsp  0x%016lx\n",           hw_tf->tf_rsp);
+       fprintf(f, "  ss   0x------------%04x\n", hw_tf->tf_ss);
 }
 
 }
 
-void print_sw_tf(struct sw_trapframe *sw_tf)
+void fprintf_sw_tf(FILE *f, struct sw_trapframe *sw_tf)
 {
 {
-       printf("[user] SW TRAP frame 0x%016p\n", sw_tf);
-       printf("  rbx  0x%016lx\n",           sw_tf->tf_rbx);
-       printf("  rbp  0x%016lx\n",           sw_tf->tf_rbp);
-       printf("  r12  0x%016lx\n",           sw_tf->tf_r12);
-       printf("  r13  0x%016lx\n",           sw_tf->tf_r13);
-       printf("  r14  0x%016lx\n",           sw_tf->tf_r14);
-       printf("  r15  0x%016lx\n",           sw_tf->tf_r15);
-       printf("  gsbs 0x%016lx\n",           sw_tf->tf_gsbase);
-       printf("  fsbs 0x%016lx\n",           sw_tf->tf_fsbase);
-       printf("  rip  0x%016lx\n",           sw_tf->tf_rip);
-       printf("  rsp  0x%016lx\n",           sw_tf->tf_rsp);
-       printf(" mxcsr 0x%08x\n",             sw_tf->tf_mxcsr);
-       printf(" fpucw 0x%04x\n",             sw_tf->tf_fpucw);
+       fprintf(f, "[user] SW TRAP frame 0x%016p\n", sw_tf);
+       fprintf(f, "  rbx  0x%016lx\n",           sw_tf->tf_rbx);
+       fprintf(f, "  rbp  0x%016lx\n",           sw_tf->tf_rbp);
+       fprintf(f, "  r12  0x%016lx\n",           sw_tf->tf_r12);
+       fprintf(f, "  r13  0x%016lx\n",           sw_tf->tf_r13);
+       fprintf(f, "  r14  0x%016lx\n",           sw_tf->tf_r14);
+       fprintf(f, "  r15  0x%016lx\n",           sw_tf->tf_r15);
+       fprintf(f, "  gsbs 0x%016lx\n",           sw_tf->tf_gsbase);
+       fprintf(f, "  fsbs 0x%016lx\n",           sw_tf->tf_fsbase);
+       fprintf(f, "  rip  0x%016lx\n",           sw_tf->tf_rip);
+       fprintf(f, "  rsp  0x%016lx\n",           sw_tf->tf_rsp);
+       fprintf(f, " mxcsr 0x%08x\n",             sw_tf->tf_mxcsr);
+       fprintf(f, " fpucw 0x%04x\n",             sw_tf->tf_fpucw);
 }
 
 }
 
-void print_vm_tf(struct vm_trapframe *vm_tf)
+void fprintf_vm_tf(FILE *f, struct vm_trapframe *vm_tf)
 {
 {
-       printf("[user] VM Trapframe 0x%016x\n", vm_tf);
-       printf("  rax  0x%016lx\n",           vm_tf->tf_rax);
-       printf("  rbx  0x%016lx\n",           vm_tf->tf_rbx);
-       printf("  rcx  0x%016lx\n",           vm_tf->tf_rcx);
-       printf("  rdx  0x%016lx\n",           vm_tf->tf_rdx);
-       printf("  rbp  0x%016lx\n",           vm_tf->tf_rbp);
-       printf("  rsi  0x%016lx\n",           vm_tf->tf_rsi);
-       printf("  rdi  0x%016lx\n",           vm_tf->tf_rdi);
-       printf("  r8   0x%016lx\n",           vm_tf->tf_r8);
-       printf("  r9   0x%016lx\n",           vm_tf->tf_r9);
-       printf("  r10  0x%016lx\n",           vm_tf->tf_r10);
-       printf("  r11  0x%016lx\n",           vm_tf->tf_r11);
-       printf("  r12  0x%016lx\n",           vm_tf->tf_r12);
-       printf("  r13  0x%016lx\n",           vm_tf->tf_r13);
-       printf("  r14  0x%016lx\n",           vm_tf->tf_r14);
-       printf("  r15  0x%016lx\n",           vm_tf->tf_r15);
-       printf("  rip  0x%016lx\n",           vm_tf->tf_rip);
-       printf("  rflg 0x%016lx\n",           vm_tf->tf_rflags);
-       printf("  rsp  0x%016lx\n",           vm_tf->tf_rsp);
-       printf("  cr2  0x%016lx\n",           vm_tf->tf_cr2);
-       printf("  cr3  0x%016lx\n",           vm_tf->tf_cr3);
-       printf("Gpcore 0x%08x\n",             vm_tf->tf_guest_pcoreid);
-       printf("Flags  0x%08x\n",             vm_tf->tf_flags);
-       printf("Inject 0x%08x\n",             vm_tf->tf_trap_inject);
-       printf("ExitRs 0x%08x\n",             vm_tf->tf_exit_reason);
-       printf("ExitQl 0x%08x\n",             vm_tf->tf_exit_qual);
-       printf("Intr1  0x%016lx\n",           vm_tf->tf_intrinfo1);
-       printf("Intr2  0x%016lx\n",           vm_tf->tf_intrinfo2);
-       printf("GIntr  0x----%04x\n",         vm_tf->tf_guest_intr_status);
-       printf("GVA    0x%016lx\n",           vm_tf->tf_guest_va);
-       printf("GPA    0x%016lx\n",           vm_tf->tf_guest_pa);
+       fprintf(f, "[user] VM Trapframe 0x%016x\n", vm_tf);
+       fprintf(f, "  rax  0x%016lx\n",           vm_tf->tf_rax);
+       fprintf(f, "  rbx  0x%016lx\n",           vm_tf->tf_rbx);
+       fprintf(f, "  rcx  0x%016lx\n",           vm_tf->tf_rcx);
+       fprintf(f, "  rdx  0x%016lx\n",           vm_tf->tf_rdx);
+       fprintf(f, "  rbp  0x%016lx\n",           vm_tf->tf_rbp);
+       fprintf(f, "  rsi  0x%016lx\n",           vm_tf->tf_rsi);
+       fprintf(f, "  rdi  0x%016lx\n",           vm_tf->tf_rdi);
+       fprintf(f, "  r8   0x%016lx\n",           vm_tf->tf_r8);
+       fprintf(f, "  r9   0x%016lx\n",           vm_tf->tf_r9);
+       fprintf(f, "  r10  0x%016lx\n",           vm_tf->tf_r10);
+       fprintf(f, "  r11  0x%016lx\n",           vm_tf->tf_r11);
+       fprintf(f, "  r12  0x%016lx\n",           vm_tf->tf_r12);
+       fprintf(f, "  r13  0x%016lx\n",           vm_tf->tf_r13);
+       fprintf(f, "  r14  0x%016lx\n",           vm_tf->tf_r14);
+       fprintf(f, "  r15  0x%016lx\n",           vm_tf->tf_r15);
+       fprintf(f, "  rip  0x%016lx\n",           vm_tf->tf_rip);
+       fprintf(f, "  rflg 0x%016lx\n",           vm_tf->tf_rflags);
+       fprintf(f, "  rsp  0x%016lx\n",           vm_tf->tf_rsp);
+       fprintf(f, "  cr2  0x%016lx\n",           vm_tf->tf_cr2);
+       fprintf(f, "  cr3  0x%016lx\n",           vm_tf->tf_cr3);
+       fprintf(f, "Gpcore 0x%08x\n",             vm_tf->tf_guest_pcoreid);
+       fprintf(f, "Flags  0x%08x\n",             vm_tf->tf_flags);
+       fprintf(f, "Inject 0x%08x\n",             vm_tf->tf_trap_inject);
+       fprintf(f, "ExitRs 0x%08x\n",             vm_tf->tf_exit_reason);
+       fprintf(f, "ExitQl 0x%08x\n",             vm_tf->tf_exit_qual);
+       fprintf(f, "Intr1  0x%016lx\n",           vm_tf->tf_intrinfo1);
+       fprintf(f, "Intr2  0x%016lx\n",           vm_tf->tf_intrinfo2);
+       fprintf(f, "GIntr  0x----%04x\n",         vm_tf->tf_guest_intr_status);
+       fprintf(f, "GVA    0x%016lx\n",           vm_tf->tf_guest_va);
+       fprintf(f, "GPA    0x%016lx\n",           vm_tf->tf_guest_pa);
 }
 
 void print_user_context(struct user_context *ctx)
 {
        switch (ctx->type) {
        case ROS_HW_CTX:
 }
 
 void print_user_context(struct user_context *ctx)
 {
        switch (ctx->type) {
        case ROS_HW_CTX:
-               print_hw_tf(&ctx->tf.hw_tf);
+               fprintf_hw_tf(stdout, &ctx->tf.hw_tf);
                break;
        case ROS_SW_CTX:
                break;
        case ROS_SW_CTX:
-               print_sw_tf(&ctx->tf.sw_tf);
+               fprintf_sw_tf(stdout, &ctx->tf.sw_tf);
                break;
        case ROS_VM_CTX:
                break;
        case ROS_VM_CTX:
-               print_vm_tf(&ctx->tf.vm_tf);
+               fprintf_vm_tf(stdout, &ctx->tf.vm_tf);
                break;
        default:
                printf("Unknown context type %d\n", ctx->type);
                break;
        default:
                printf("Unknown context type %d\n", ctx->type);
index 221f8cb..421c742 100644 (file)
@@ -39,24 +39,7 @@ void showstatus(FILE *f, struct guest_thread *vm_thread)
        fprintf(f, "Shutdown: core %d, %s due to %s(0x%x); ret code 0x%x\n",
                vm_tf->tf_guest_pcoreid, when, reason, shutdown,
                        vm_tf->tf_exit_reason);
        fprintf(f, "Shutdown: core %d, %s due to %s(0x%x); ret code 0x%x\n",
                vm_tf->tf_guest_pcoreid, when, reason, shutdown,
                        vm_tf->tf_exit_reason);
-       fprintf(f, "  gva %p gpa %p cr3 %p\n", (void *)vm_tf->tf_guest_va,
-               (void *)vm_tf->tf_guest_pa, (void *)vm_tf->tf_cr3);
-
-       fprintf(f, "  rax  0x%016lx\n",           vm_tf->tf_rax);
-       fprintf(f, "  rbx  0x%016lx\n",           vm_tf->tf_rbx);
-       fprintf(f, "  rcx  0x%016lx\n",           vm_tf->tf_rcx);
-       fprintf(f, "  rdx  0x%016lx\n",           vm_tf->tf_rdx);
-       fprintf(f, "  rbp  0x%016lx\n",           vm_tf->tf_rbp);
-       fprintf(f, "  rsi  0x%016lx\n",           vm_tf->tf_rsi);
-       fprintf(f, "  rdi  0x%016lx\n",           vm_tf->tf_rdi);
-       fprintf(f, "  r8   0x%016lx\n",           vm_tf->tf_r8);
-       fprintf(f, "  r9   0x%016lx\n",           vm_tf->tf_r9);
-       fprintf(f, "  r10  0x%016lx\n",           vm_tf->tf_r10);
-       fprintf(f, "  r11  0x%016lx\n",           vm_tf->tf_r11);
-       fprintf(f, "  r12  0x%016lx\n",           vm_tf->tf_r12);
-       fprintf(f, "  r13  0x%016lx\n",           vm_tf->tf_r13);
-       fprintf(f, "  r14  0x%016lx\n",           vm_tf->tf_r14);
-       fprintf(f, "  r15  0x%016lx\n",           vm_tf->tf_r15);
+       fprintf_vm_tf(f, vm_tf);
 }
 
 /* Convert a kernel guest virtual address to physical address.
 }
 
 /* Convert a kernel guest virtual address to physical address.