parlib: have 2LS libraries #include parlib/stdio.h
[akaros.git] / user / vmm / vmx.c
index 8528958..7be527d 100644 (file)
@@ -1,4 +1,4 @@
-#include <stdio.h>
+#include <parlib/stdio.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -31,9 +31,11 @@ void showstatus(FILE *f, struct guest_thread *vm_thread)
 {
        struct vm_trapframe *vm_tf = gth_to_vmtf(vm_thread);
        int shutdown = vm_tf->tf_exit_reason;
-       char *when = shutdown & VMX_EXIT_REASONS_FAILED_VMENTRY ? "entry" : "exit";
-       shutdown &= ~VMX_EXIT_REASONS_FAILED_VMENTRY;
+       char *when = shutdown & VMX_EXIT_REASONS_FAILED_VMENTRY ? "entry"
+                                                               : "exit";
        char *reason = "UNKNOWN";
+
+       shutdown &= ~VMX_EXIT_REASONS_FAILED_VMENTRY;
        if (shutdown < COUNT_OF(vmxexit) && vmxexit[shutdown])
                reason = vmxexit[shutdown];
        fprintf(f, "Shutdown: core %d, %s due to %s(0x%x); ret code 0x%x\n",
@@ -43,19 +45,17 @@ void showstatus(FILE *f, struct guest_thread *vm_thread)
        backtrace_guest_thread(f, vm_thread);
 }
 
-/* Convert a kernel guest virtual address to physical address.
- * Assumes that the guest VA is in the high negative address space.
- * TODO: Takes the vm_thread argument so that we can walk the page tables
- * instead of just coercing the pointer. Therefore, this is not in vmm.h
- * since it may get complex. */
-int gvatogpa(struct guest_thread *vm_thread, uint64_t va, uint64_t *pa)
+/* Convert a guest virtual address to physical address. */
+int gva2gpa(struct guest_thread *vm_thread, uint64_t va, uint64_t *pa)
 {
        assert(vm_thread != NULL);
        struct vm_trapframe *vm_tf = gth_to_vmtf(vm_thread);
        uint64_t *ptptr = (uint64_t *)vm_tf->tf_cr3;
        uint64_t entry;
 
-       for (int shift = PML4_SHIFT; shift >= PML1_SHIFT; shift -= BITS_PER_PML) {
+       for (int shift = PML4_SHIFT;
+            shift >= PML1_SHIFT;
+            shift -= BITS_PER_PML) {
                entry = ptptr[PMLx(va, shift)];
                /* bit 63 can be NX.  Bits 62:52 are ignored (for PML4) */
                entry &= 0x000fffffffffffff;
@@ -78,5 +78,5 @@ int gvatogpa(struct guest_thread *vm_thread, uint64_t va, uint64_t *pa)
 int rippa(struct guest_thread *vm_thread, uint64_t *pa)
 {
        assert(vm_thread != NULL);
-       return gvatogpa(vm_thread, gth_to_vmtf(vm_thread)->tf_rip, pa);
+       return gva2gpa(vm_thread, gth_to_vmtf(vm_thread)->tf_rip, pa);
 }