Add user support for VM contexts
[akaros.git] / user / parlib / x86 / vcore.c
1 #include <ros/syscall.h>
2 #include <parlib/arch/vcore.h>
3 #include <parlib/stdio.h>
4
5 struct syscall vc_entry = {
6         .num = SYS_vc_entry,
7         .err = 0,
8         .retval = 0,
9         .flags = 0,
10         .ev_q = 0,
11         .u_data = 0,
12         .arg0 = 0,
13         .arg1 = 0,
14         .arg2 = 0,
15         .arg3 = 0,
16         .arg4 = 0,
17         .arg5 = 0,
18 };
19
20 void print_hw_tf(struct hw_trapframe *hw_tf)
21 {
22         printf("[user] HW TRAP frame 0x%016x\n", hw_tf);
23         printf("  rax  0x%016lx\n",           hw_tf->tf_rax);
24         printf("  rbx  0x%016lx\n",           hw_tf->tf_rbx);
25         printf("  rcx  0x%016lx\n",           hw_tf->tf_rcx);
26         printf("  rdx  0x%016lx\n",           hw_tf->tf_rdx);
27         printf("  rbp  0x%016lx\n",           hw_tf->tf_rbp);
28         printf("  rsi  0x%016lx\n",           hw_tf->tf_rsi);
29         printf("  rdi  0x%016lx\n",           hw_tf->tf_rdi);
30         printf("  r8   0x%016lx\n",           hw_tf->tf_r8);
31         printf("  r9   0x%016lx\n",           hw_tf->tf_r9);
32         printf("  r10  0x%016lx\n",           hw_tf->tf_r10);
33         printf("  r11  0x%016lx\n",           hw_tf->tf_r11);
34         printf("  r12  0x%016lx\n",           hw_tf->tf_r12);
35         printf("  r13  0x%016lx\n",           hw_tf->tf_r13);
36         printf("  r14  0x%016lx\n",           hw_tf->tf_r14);
37         printf("  r15  0x%016lx\n",           hw_tf->tf_r15);
38         printf("  trap 0x%08x\n",             hw_tf->tf_trapno);
39         printf("  gsbs 0x%016lx\n",           hw_tf->tf_gsbase);
40         printf("  fsbs 0x%016lx\n",           hw_tf->tf_fsbase);
41         printf("  err  0x--------%08x\n",     hw_tf->tf_err);
42         printf("  rip  0x%016lx\n",           hw_tf->tf_rip);
43         printf("  cs   0x------------%04x\n", hw_tf->tf_cs);
44         printf("  flag 0x%016lx\n",           hw_tf->tf_rflags);
45         printf("  rsp  0x%016lx\n",           hw_tf->tf_rsp);
46         printf("  ss   0x------------%04x\n", hw_tf->tf_ss);
47 }
48
49 void print_sw_tf(struct sw_trapframe *sw_tf)
50 {
51         printf("[user] SW TRAP frame 0x%016p\n", sw_tf);
52         printf("  rbx  0x%016lx\n",           sw_tf->tf_rbx);
53         printf("  rbp  0x%016lx\n",           sw_tf->tf_rbp);
54         printf("  r12  0x%016lx\n",           sw_tf->tf_r12);
55         printf("  r13  0x%016lx\n",           sw_tf->tf_r13);
56         printf("  r14  0x%016lx\n",           sw_tf->tf_r14);
57         printf("  r15  0x%016lx\n",           sw_tf->tf_r15);
58         printf("  gsbs 0x%016lx\n",           sw_tf->tf_gsbase);
59         printf("  fsbs 0x%016lx\n",           sw_tf->tf_fsbase);
60         printf("  rip  0x%016lx\n",           sw_tf->tf_rip);
61         printf("  rsp  0x%016lx\n",           sw_tf->tf_rsp);
62         printf(" mxcsr 0x%08x\n",             sw_tf->tf_mxcsr);
63         printf(" fpucw 0x%04x\n",             sw_tf->tf_fpucw);
64 }
65
66 void print_vm_tf(struct vm_trapframe *vm_tf)
67 {
68         printf("[user] VM Trapframe 0x%016x\n", vm_tf);
69         printf("  rax  0x%016lx\n",           vm_tf->tf_rax);
70         printf("  rbx  0x%016lx\n",           vm_tf->tf_rbx);
71         printf("  rcx  0x%016lx\n",           vm_tf->tf_rcx);
72         printf("  rdx  0x%016lx\n",           vm_tf->tf_rdx);
73         printf("  rbp  0x%016lx\n",           vm_tf->tf_rbp);
74         printf("  rsi  0x%016lx\n",           vm_tf->tf_rsi);
75         printf("  rdi  0x%016lx\n",           vm_tf->tf_rdi);
76         printf("  r8   0x%016lx\n",           vm_tf->tf_r8);
77         printf("  r9   0x%016lx\n",           vm_tf->tf_r9);
78         printf("  r10  0x%016lx\n",           vm_tf->tf_r10);
79         printf("  r11  0x%016lx\n",           vm_tf->tf_r11);
80         printf("  r12  0x%016lx\n",           vm_tf->tf_r12);
81         printf("  r13  0x%016lx\n",           vm_tf->tf_r13);
82         printf("  r14  0x%016lx\n",           vm_tf->tf_r14);
83         printf("  r15  0x%016lx\n",           vm_tf->tf_r15);
84         printf("  rip  0x%016lx\n",           vm_tf->tf_rip);
85         printf("  rflg 0x%016lx\n",           vm_tf->tf_rflags);
86         printf("  rsp  0x%016lx\n",           vm_tf->tf_rsp);
87         printf("  cr2  0x%016lx\n",           vm_tf->tf_cr2);
88         printf("  cr3  0x%016lx\n",           vm_tf->tf_cr3);
89         printf("Gpcore 0x%08x\n",             vm_tf->tf_guest_pcoreid);
90         printf("Flags  0x%08x\n",             vm_tf->tf_flags);
91         printf("Inject 0x%08x\n",             vm_tf->tf_trap_inject);
92         printf("ExitRs 0x%08x\n",             vm_tf->tf_exit_reason);
93         printf("ExitQl 0x%08x\n",             vm_tf->tf_exit_qual);
94         printf("Intr1  0x%016lx\n",           vm_tf->tf_intrinfo1);
95         printf("Intr2  0x%016lx\n",           vm_tf->tf_intrinfo2);
96         printf("GVA    0x%016lx\n",           vm_tf->tf_guest_va);
97         printf("GPA    0x%016lx\n",           vm_tf->tf_guest_pa);
98 }
99
100 void print_user_context(struct user_context *ctx)
101 {
102         switch (ctx->type) {
103         case ROS_HW_CTX:
104                 print_hw_tf(&ctx->tf.hw_tf);
105                 break;
106         case ROS_SW_CTX:
107                 print_sw_tf(&ctx->tf.sw_tf);
108                 break;
109         case ROS_VM_CTX:
110                 print_vm_tf(&ctx->tf.vm_tf);
111                 break;
112         default:
113                 printf("Unknown context type %d\n", ctx->type);
114         }
115 }