VMM: Added header for virtio_lguest_console functions
[akaros.git] / user / vmm / vmx.c
1 #include <stdio.h> 
2 #include <pthread.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6 #include <parlib/arch/arch.h>
7 #include <parlib/ros_debug.h>
8 #include <unistd.h>
9 #include <errno.h>
10 #include <dirent.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <ros/syscall.h>
14 #include <sys/mman.h>
15 #include <vmm/coreboot_tables.h>
16 #include <ros/common.h>
17 #include <vmm/vmm.h>
18 #include <vmm/virtio.h>
19 #include <vmm/virtio_mmio.h>
20 #include <vmm/virtio_ids.h>
21 #include <ros/arch/vmx.h>
22 #include <vmm/sched.h>
23 #include <ros/arch/trapframe.h>
24
25 /* nowhere on my linux system. */
26 #define ARRAY_SIZE(x) (sizeof((x))/sizeof((x)[0]))
27
28 char *vmxexit[] = {
29         VMX_EXIT_REASONS
30 };
31
32 void showstatus(FILE *f, struct guest_thread *vm_thread)
33 {
34         struct vm_trapframe *vm_tf = &(vm_thread->uthread.u_ctx.tf.vm_tf);
35         int shutdown = vm_tf->tf_exit_reason;
36         char *when = shutdown & VMX_EXIT_REASONS_FAILED_VMENTRY ? "entry" : "exit";
37         shutdown &= ~VMX_EXIT_REASONS_FAILED_VMENTRY;
38         char *reason = "UNKNOWN";
39         if (shutdown < ARRAY_SIZE(vmxexit) && vmxexit[shutdown])
40                 reason = vmxexit[shutdown];
41         fprintf(f, "Shutdown: core %d, %s due to %s(0x%x); ret code 0x%x\n",
42                 vm_tf->tf_guest_pcoreid, when, reason, shutdown,
43                         vm_tf->tf_exit_reason);
44         fprintf(f, "  gva %p gpa %p cr3 %p\n", (void *)vm_tf->tf_guest_va,
45                 (void *)vm_tf->tf_guest_pa, (void *)vm_tf->tf_cr3);
46
47         fprintf(f, "  rax  0x%016lx\n",           vm_tf->tf_rax);
48         fprintf(f, "  rbx  0x%016lx\n",           vm_tf->tf_rbx);
49         fprintf(f, "  rcx  0x%016lx\n",           vm_tf->tf_rcx);
50         fprintf(f, "  rdx  0x%016lx\n",           vm_tf->tf_rdx);
51         fprintf(f, "  rbp  0x%016lx\n",           vm_tf->tf_rbp);
52         fprintf(f, "  rsi  0x%016lx\n",           vm_tf->tf_rsi);
53         fprintf(f, "  rdi  0x%016lx\n",           vm_tf->tf_rdi);
54         fprintf(f, "  r8   0x%016lx\n",           vm_tf->tf_r8);
55         fprintf(f, "  r9   0x%016lx\n",           vm_tf->tf_r9);
56         fprintf(f, "  r10  0x%016lx\n",           vm_tf->tf_r10);
57         fprintf(f, "  r11  0x%016lx\n",           vm_tf->tf_r11);
58         fprintf(f, "  r12  0x%016lx\n",           vm_tf->tf_r12);
59         fprintf(f, "  r13  0x%016lx\n",           vm_tf->tf_r13);
60         fprintf(f, "  r14  0x%016lx\n",           vm_tf->tf_r14);
61         fprintf(f, "  r15  0x%016lx\n",           vm_tf->tf_r15);
62 }