VMM: Add custom exit reasons (XCC)
[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
23 /* nowhere on my linux system. */
24 #define ARRAY_SIZE(x) (sizeof((x))/sizeof((x)[0]))
25
26 char *vmxexit[] = {
27         VMX_EXIT_REASONS
28 };
29
30 void showstatus(FILE *f, struct vmctl *v)
31 {
32         int shutdown = v->ret_code;
33         char *when = shutdown & VMX_EXIT_REASONS_FAILED_VMENTRY ? "entry" : "exit";
34         shutdown &= ~VMX_EXIT_REASONS_FAILED_VMENTRY;
35         char *reason = "UNKNOWN";
36         if (shutdown < ARRAY_SIZE(vmxexit) && vmxexit[shutdown])
37                 reason = vmxexit[shutdown];
38         fprintf(f, "Shutdown: core %d, %s due to %s(0x%x); ret code 0x%x\n", v->core, when, reason, shutdown, v->ret_code);
39         fprintf(f, "  gva %p gpa %p cr3 %p\n", (void *)v->gva, (void *)v->gpa, (void *)v->cr3);
40
41         fprintf(f, "  rax  0x%016lx\n",           v->regs.tf_rax);
42         fprintf(f, "  rbx  0x%016lx\n",           v->regs.tf_rbx);
43         fprintf(f, "  rcx  0x%016lx\n",           v->regs.tf_rcx);
44         fprintf(f, "  rdx  0x%016lx\n",           v->regs.tf_rdx);
45         fprintf(f, "  rbp  0x%016lx\n",           v->regs.tf_rbp);
46         fprintf(f, "  rsi  0x%016lx\n",           v->regs.tf_rsi);
47         fprintf(f, "  rdi  0x%016lx\n",           v->regs.tf_rdi);
48         fprintf(f, "  r8   0x%016lx\n",           v->regs.tf_r8);
49         fprintf(f, "  r9   0x%016lx\n",           v->regs.tf_r9);
50         fprintf(f, "  r10  0x%016lx\n",           v->regs.tf_r10);
51         fprintf(f, "  r11  0x%016lx\n",           v->regs.tf_r11);
52         fprintf(f, "  r12  0x%016lx\n",           v->regs.tf_r12);
53         fprintf(f, "  r13  0x%016lx\n",           v->regs.tf_r13);
54         fprintf(f, "  r14  0x%016lx\n",           v->regs.tf_r14);
55         fprintf(f, "  r15  0x%016lx\n",           v->regs.tf_r15);
56 }