Move print_user_context out of a header
authorBarret Rhoden <brho@cs.berkeley.edu>
Mon, 14 Dec 2015 19:39:28 +0000 (14:39 -0500)
committerBarret Rhoden <brho@cs.berkeley.edu>
Wed, 16 Dec 2015 23:23:10 +0000 (18:23 -0500)
The printf's are problematic in a header.  Specifically when we include and
use those functions from within parts of glibc, we can trigger the dreaded
'multiple libc' problem when building glibc.

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

index 16655da..a965591 100644 (file)
@@ -63,6 +63,9 @@ void ensure_vcore_runs(uint32_t vcoreid);
 void cpu_relax_vc(uint32_t vcoreid);
 uint32_t get_vcoreid(void);
 bool check_vcoreid(const char *str, uint32_t vcoreid);
+void print_hw_tf(struct hw_trapframe *tf);
+void print_sw_tf(struct sw_trapframe *sw_tf);
+void print_user_context(struct user_context *ctx);
 
 /* This works so long as we don't dlopen parlib (which we never do) */
 #define get_tlsvar_linaddr(_vcoreid, _var)                                     \
index 88f4de1..483c97a 100644 (file)
@@ -329,55 +329,6 @@ static inline uintptr_t get_user_ctx_stack(struct user_context *ctx)
        temp; \
 })
 
-/* For debugging. */
-#include <stdio.h>
-static void print_hw_tf(struct hw_trapframe *tf)
-{
-       printf("[user] HW TRAP frame %08p\n", tf);
-       printf("  edi  0x%08x\n", tf->tf_regs.reg_edi);
-       printf("  esi  0x%08x\n", tf->tf_regs.reg_esi);
-       printf("  ebp  0x%08x\n", tf->tf_regs.reg_ebp);
-       printf("  oesp 0x%08x\n", tf->tf_regs.reg_oesp);
-       printf("  ebx  0x%08x\n", tf->tf_regs.reg_ebx);
-       printf("  edx  0x%08x\n", tf->tf_regs.reg_edx);
-       printf("  ecx  0x%08x\n", tf->tf_regs.reg_ecx);
-       printf("  eax  0x%08x\n", tf->tf_regs.reg_eax);
-       printf("  gs   0x----%04x\n", tf->tf_gs);
-       printf("  fs   0x----%04x\n", tf->tf_fs);
-       printf("  es   0x----%04x\n", tf->tf_es);
-       printf("  ds   0x----%04x\n", tf->tf_ds);
-       printf("  trap 0x%08x\n", tf->tf_trapno);
-       printf("  err  0x%08x\n", tf->tf_err);
-       printf("  eip  0x%08x\n", tf->tf_eip);
-       printf("  cs   0x----%04x\n", tf->tf_cs);
-       printf("  flag 0x%08x\n", tf->tf_eflags);
-       printf("  esp  0x%08x\n", tf->tf_esp);
-       printf("  ss   0x----%04x\n", tf->tf_ss);
-}
-
-static void print_sw_tf(struct sw_trapframe *sw_tf)
-{
-       printf("[user] SW TRAP frame %08p\n", sw_tf);
-       printf("  ebp  0x%08x\n", sw_tf->tf_ebp);
-       printf("  ebx  0x%08x\n", sw_tf->tf_ebx);
-       printf("  esi  0x%08x\n", sw_tf->tf_esi);
-       printf("  edi  0x%08x\n", sw_tf->tf_edi);
-       printf("  esp  0x%08x\n", sw_tf->tf_esp);
-       printf("  eip  0x%08x\n", sw_tf->tf_eip);
-       printf(" mxcsr 0x%08x\n", sw_tf->tf_mxcsr);
-       printf(" fpucw 0x----%04x\n", sw_tf->tf_fpucw);
-}
-
-static void print_user_context(struct user_context *ctx)
-{
-       if (ctx->type == ROS_HW_CTX)
-               print_hw_tf(&ctx->tf.hw_tf);
-       else if (ctx->type == ROS_SW_CTX)
-               print_sw_tf(&ctx->tf.sw_tf);
-       else
-               printf("Unknown context type %d\n", ctx->type);
-}
-
 static bool has_refl_fault(struct user_context *ctx)
 {
        return ctx->tf.hw_tf.tf_padding3 == ROS_ARCH_REFL_ID;
index 77efbb3..bf3815b 100644 (file)
@@ -368,64 +368,6 @@ static inline uintptr_t get_user_ctx_stack(struct user_context *ctx)
        temp; \
 })
 
-/* For debugging. */
-#include <stdio.h>
-static void print_hw_tf(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);
-}
-
-static void print_sw_tf(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);
-}
-
-static void print_user_context(struct user_context *ctx)
-{
-       if (ctx->type == ROS_HW_CTX)
-               print_hw_tf(&ctx->tf.hw_tf);
-       else if (ctx->type == ROS_SW_CTX)
-               print_sw_tf(&ctx->tf.sw_tf);
-       else
-               printf("Unknown context type %d\n", ctx->type);
-}
-
 static bool has_refl_fault(struct user_context *ctx)
 {
        return ctx->tf.hw_tf.tf_padding3 == ROS_ARCH_REFL_ID;
index df1cb49..b3c6182 100644 (file)
@@ -1,5 +1,6 @@
 #include <ros/syscall.h>
 #include <parlib/arch/vcore.h>
+#include <parlib/stdio.h>
 
 struct syscall vc_entry = {
        .num = SYS_vc_entry,
@@ -15,3 +16,59 @@ struct syscall vc_entry = {
        .arg4 = 0,
        .arg5 = 0,
 };
+
+void print_hw_tf(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);
+}
+
+void print_sw_tf(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);
+}
+
+void print_user_context(struct user_context *ctx)
+{
+       if (ctx->type == ROS_HW_CTX)
+               print_hw_tf(&ctx->tf.hw_tf);
+       else if (ctx->type == ROS_SW_CTX)
+               print_sw_tf(&ctx->tf.sw_tf);
+       else
+               printf("Unknown context type %d\n", ctx->type);
+}