Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


changed debug output to be more granular
Jack Lange [Mon, 21 Jul 2008 21:07:58 +0000 (21:07 +0000)]
palacios/build/Makefile
palacios/include/palacios/vmm.h
palacios/src/devices/nvram.c
palacios/src/geekos/vm.c
palacios/src/geekos/vmm_stubs.c
palacios/src/palacios/svm_handler.c
palacios/src/palacios/svm_io.c
palacios/src/palacios/vmm_ctrl_regs.c
palacios/src/palacios/vmm_intr.c
palacios/src/palacios/vmm_io.c
palacios/src/palacios/vmm_shadow_paging.c

index e8b2b78..3ced5a9 100644 (file)
@@ -1,6 +1,6 @@
 # Makefile for GeekOS kernel, userspace, and tools
 # Copyright (c) 2004,2005 David H. Hovemeyer <daveho@cs.umd.edu>
-# $Revision: 1.46 $
+# $Revision: 1.47 $
 
 # This is free software.  You are permitted to use,
 # redistribute, and modify it as specified in the file "COPYING".
@@ -57,7 +57,8 @@ DEBUG=1
 XED=0
 
 ifeq ($(DEBUG),1)
-  JRLDEBUG= -DSERIAL_PRINT_DEBUG=1 -DSERIAL_PRINT_DEBUG_LEVEL=10 -DSERIAL_PRINT=1 -DVMM_DEBUG=1 -DVMM_INFO=1 -DVMM_TRACE=1
+  JRLDEBUG= -DSERIAL_PRINT_DEBUG=1 -DSERIAL_PRINT_DEBUG_LEVEL=10 -DSERIAL_PRINT=1 -DVMM_DEBUG=1 -DVMM_INFO=1 -DVMM_TRACE=1 
+#-DDEBUG_SHADOW_PAGING -DDEBUG_CTRL_REGS -DDEBUG_INTERRUPTS -DDEBUG_IO
 else
   JRLDEBUG= -DSERIAL_PRINT_DEBUG=0 -DSERIAL_PRINT_DEBUG_LEVEL=999999 -DSERIAL_PRINT=0 -DVMM_DEBUG=0 -DVMM_INFO=0 -DVMM_TRACE=0
 endif
index b9e3fea..aebc8ad 100644 (file)
 #endif
 
 
+
+#define PrintError(fmt, args...)                       \
+  do {                                                 \
+    extern struct vmm_os_hooks * os_hooks;             \
+    if ((os_hooks) && (os_hooks)->print_debug) {       \
+      (os_hooks)->print_debug((fmt), ##args);          \
+    }                                                  \
+  } while (0)                                          
+
+
+
 #if VMM_INFO
 #define PrintInfo(fmt, args...)                        \
   do {                                                 \
index 5681983..624179f 100644 (file)
@@ -117,8 +117,8 @@ static int set_nvram_defaults(struct vm_device *dev)
   nvram_state->mem_state[NVRAM_REG_EXT_MEMORY_2ND_LOW]= 0x00;
 
   // Set the extended memory beyond 16 MB to 128-16 MB
-  nvram_state->mem_state[NVRAM_REG_AMI_BIG_MEMORY_HIGH]= 0x7;
-  nvram_state->mem_state[NVRAM_REG_AMI_BIG_MEMORY_LOW]= 0x00;
+  nvram_state->mem_state[NVRAM_REG_AMI_BIG_MEMORY_HIGH] = 0x7;
+  nvram_state->mem_state[NVRAM_REG_AMI_BIG_MEMORY_LOW] = 0x00;
 
   //nvram_state->mem_state[NVRAM_REG_AMI_BIG_MEMORY_HIGH]= 0x00;
   //nvram_state->mem_state[NVRAM_REG_AMI_BIG_MEMORY_LOW]= 0x00;
index 661f5d1..779e36e 100644 (file)
@@ -361,6 +361,8 @@ int RunVMM(struct Boot_Info * bootInfo) {
       //add_shadow_region_passthrough(&vm_info, 0x100000, 0x2000000, (addr_t)Allocate_VMM_Pages(8192));
       add_shadow_region_passthrough(&vm_info, 0x100000, 0x1000000, (addr_t)Allocate_VMM_Pages(4096));
 
+      add_shadow_region_passthrough(&vm_info, 0x1000000, 0x8000000, (addr_t)Allocate_VMM_Pages(32768));
+
       // test - give linux accesss to PCI space - PAD
       add_shadow_region_passthrough(&vm_info, 0xc0000000,0xffffffff,0xc0000000);
 
index 0dbe081..f419613 100644 (file)
@@ -112,7 +112,7 @@ static void translate_intr_handler(struct Interrupt_State *state)
   mystate.should_ack=0;
   mystate.opaque=my_opaque[mystate.irq];
 
-  PrintBoth("translate_intr_handler: opaque=0x%x\n",mystate.opaque);
+  //  PrintBoth("translate_intr_handler: opaque=0x%x\n",mystate.opaque);
 
   deliver_interrupt_to_vmm(&mystate);
 
index f14d94d..1545cad 100644 (file)
@@ -43,9 +43,9 @@ int handle_svm_exit(struct guest_info * info) {
   //if (!((exit_code == VMEXIT_IOIO) && ((ushort_t)(guest_ctrl->exit_info1 >> 16) == 0x402))) {
 
 
-  PrintDebug("SVM Returned: Exit Code: 0x%x \t\t(tsc=%ul)\n",exit_code, (uint_t)info->time_state.guest_tsc); 
+  //  PrintDebug("SVM Returned: Exit Code: 0x%x \t\t(tsc=%ul)\n",exit_code, (uint_t)info->time_state.guest_tsc); 
   
-  if (exit_code < 0x4f) {
+  if ((0) && (exit_code < 0x4f)) {
     char instr[32];
     int ret;
     // Dump out the instr stream
@@ -109,26 +109,30 @@ int handle_svm_exit(struct guest_info * info) {
       }
     }
   } else if (exit_code == VMEXIT_CR0_WRITE) {
+#ifdef DEBUG_CTRL_REGS
     PrintDebug("CR0 Write\n");
-
+#endif
     if (handle_cr0_write(info) == -1) {
       return -1;
     }
   } else if (exit_code == VMEXIT_CR0_READ) {
+#ifdef DEBUG_CTRL_REGS
     PrintDebug("CR0 Read\n");
-
+#endif
     if (handle_cr0_read(info) == -1) {
       return -1;
     }
   } else if (exit_code == VMEXIT_CR3_WRITE) {
+#ifdef DEBUG_CTRL_REGS
     PrintDebug("CR3 Write\n");
-
+#endif
     if (handle_cr3_write(info) == -1) {
       return -1;
     }    
   } else if (exit_code == VMEXIT_CR3_READ) {
+#ifdef DEBUG_CTRL_REGS
     PrintDebug("CR3 Read\n");
-
+#endif
     if (handle_cr3_read(info) == -1) {
       return -1;
     }
@@ -136,26 +140,28 @@ int handle_svm_exit(struct guest_info * info) {
   } else if (exit_code == VMEXIT_EXCP14) {
     addr_t fault_addr = guest_ctrl->exit_info2;
     pf_error_t * error_code = (pf_error_t *)&(guest_ctrl->exit_info1);
-    
+#ifdef DEBUG_SHADOW_PAGING
     PrintDebug("PageFault at %x (error=%d)\n", fault_addr, *error_code);
-
+#endif
     if (info->shdw_pg_mode == SHADOW_PAGING) {
       if (handle_shadow_pagefault(info, fault_addr, *error_code) == -1) {
        return -1;
       }
     } else {
 
-      PrintDebug("Page fault in un implemented paging mode\n");
+      PrintError("Page fault in un implemented paging mode\n");
      
       return -1;
     }
   } else if (exit_code == VMEXIT_NPF) {
-    PrintDebug("Currently unhandled Nested Page Fault\n");
+    PrintError("Currently unhandled Nested Page Fault\n");
     return -1;
 
   } else if (exit_code == VMEXIT_INVLPG) {
     if (info->shdw_pg_mode == SHADOW_PAGING) {
+#ifdef DEBUG_SHADOW_PAGING
       PrintDebug("Invlpg\n");
+#endif
       if (handle_shadow_invlpg(info) == -1) {
        return -1;
       }
@@ -193,40 +199,40 @@ int handle_svm_exit(struct guest_info * info) {
 
 
 
-    PrintDebug("SVM Returned:(VMCB=%x)\n", info->vmm_data); 
-    PrintDebug("RIP: %x\n", guest_state->rip);
-    PrintDebug("RIP Linear: %x\n", rip_addr);
+    PrintError("SVM Returned:(VMCB=%x)\n", info->vmm_data); 
+    PrintError("RIP: %x\n", guest_state->rip);
+    PrintError("RIP Linear: %x\n", rip_addr);
     
-    PrintDebug("SVM Returned: Exit Code: %x\n",exit_code); 
+    PrintError("SVM Returned: Exit Code: %x\n",exit_code); 
     
-    PrintDebug("io_info1 low = 0x%.8x\n", *(uint_t*)&(guest_ctrl->exit_info1));
-    PrintDebug("io_info1 high = 0x%.8x\n", *(uint_t *)(((uchar_t *)&(guest_ctrl->exit_info1)) + 4));
+    PrintError("io_info1 low = 0x%.8x\n", *(uint_t*)&(guest_ctrl->exit_info1));
+    PrintError("io_info1 high = 0x%.8x\n", *(uint_t *)(((uchar_t *)&(guest_ctrl->exit_info1)) + 4));
     
-    PrintDebug("io_info2 low = 0x%.8x\n", *(uint_t*)&(guest_ctrl->exit_info2));
-    PrintDebug("io_info2 high = 0x%.8x\n", *(uint_t *)(((uchar_t *)&(guest_ctrl->exit_info2)) + 4));
+    PrintError("io_info2 low = 0x%.8x\n", *(uint_t*)&(guest_ctrl->exit_info2));
+    PrintError("io_info2 high = 0x%.8x\n", *(uint_t *)(((uchar_t *)&(guest_ctrl->exit_info2)) + 4));
 
     
 
     if (info->mem_mode == PHYSICAL_MEM) {
       if (guest_pa_to_host_pa(info, guest_state->rip, &host_addr) == -1) {
-       PrintDebug("Could not translate guest_state->rip to host address\n");
+       PrintError("Could not translate guest_state->rip to host address\n");
        return -1;
       }
     } else if (info->mem_mode == VIRTUAL_MEM) {
       if (guest_va_to_host_pa(info, guest_state->rip, &host_addr) == -1) {
-       PrintDebug("Could not translate guest_state->rip to host address\n");
+       PrintError("Could not translate guest_state->rip to host address\n");
        return -1;
       }
     } else {
-      PrintDebug("Invalid memory mode\n");
+      PrintError("Invalid memory mode\n");
       return -1;
     }
 
-    PrintDebug("Host Address of rip = 0x%x\n", host_addr);
+    PrintError("Host Address of rip = 0x%x\n", host_addr);
 
     memset(buf, 0, 15);
     
-    PrintDebug("Reading from 0x%x in guest\n", rip_addr);
+    PrintError("Reading from 0x%x in guest\n", rip_addr);
     
     if (info->mem_mode == PHYSICAL_MEM) {
       read_guest_pa_memory(info, rip_addr, 15, buf);
@@ -262,9 +268,9 @@ int handle_svm_exit(struct guest_info * info) {
        guest_ctrl->guest_ctrl.V_INTR_VECTOR = irq;
        guest_ctrl->guest_ctrl.V_IGN_TPR = 1;
        guest_ctrl->guest_ctrl.V_INTR_PRIO = 0xf;
-
+#ifdef DEBUG_INTERRUPTS
        PrintDebug("Injecting Interrupt %d (EIP=%x)\n", guest_ctrl->guest_ctrl.V_INTR_VECTOR, info->rip);
-
+#endif
        injecting_intr(info, irq, EXTERNAL_IRQ);
        
        break;
@@ -281,13 +287,17 @@ int handle_svm_exit(struct guest_info * info) {
        if (info->intr_state.excp_error_code_valid) {  //PAD
          guest_ctrl->EVENTINJ.error_code = info->intr_state.excp_error_code;
          guest_ctrl->EVENTINJ.ev = 1;
+#ifdef DEBUG_INTERRUPTS
          PrintDebug("Injecting error code %x\n", guest_ctrl->EVENTINJ.error_code);
+#endif
        }
        
        guest_ctrl->EVENTINJ.vector = excp;
        
        guest_ctrl->EVENTINJ.valid = 1;
+#ifdef DEBUG_INTERRUPTS
        PrintDebug("Injecting Interrupt %d (EIP=%x)\n", guest_ctrl->EVENTINJ.vector, info->rip);
+#endif
        injecting_intr(info, excp, EXCEPTION);
        break;
       }
@@ -300,7 +310,7 @@ int handle_svm_exit(struct guest_info * info) {
 
     case INVALID_INTR: 
     default:
-      PrintDebug("Attempted to issue an invalid interrupt\n");
+      PrintError("Attempted to issue an invalid interrupt\n");
       return -1;
     }
 
index 33022f0..488b8a2 100644 (file)
@@ -4,6 +4,11 @@
 #include <palacios/vmm_decoder.h>
 #include <palacios/vm_guest_mem.h>
 
+#ifndef DEBUG_IO
+#undef PrintDebug
+#define PrintDebug(fmt, args...)
+#endif
+
 
 // This should package up an IO request and call vmm_handle_io
 int handle_svm_io_in(struct guest_info * info) {
@@ -15,7 +20,7 @@ int handle_svm_io_in(struct guest_info * info) {
   uint_t read_size = 0;
 
   if (hook == NULL) {
-    PrintDebug("Hook Not present for in on port %x\n", io_info->port);
+    PrintError("Hook Not present for in on port %x\n", io_info->port);
     // error, we should not have exited on this port
     return -1;
   }
@@ -33,7 +38,7 @@ int handle_svm_io_in(struct guest_info * info) {
 
   if (hook->read(io_info->port, &(info->vm_regs.rax), read_size, hook->priv_data) != read_size) {
     // not sure how we handle errors.....
-    PrintDebug("Read Failure for in on port %x\n", io_info->port);
+    PrintError("Read Failure for in on port %x\n", io_info->port);
     return -1;
   }
 
@@ -75,7 +80,7 @@ int handle_svm_io_ins(struct guest_info * info) {
 
 
   if (hook == NULL) {
-   PrintDebug("Hook Not present for ins on port %x\n", io_info->port);
+   PrintError("Hook Not present for ins on port %x\n", io_info->port);
     // error, we should not have exited on this port
     return -1;
   }
@@ -85,7 +90,7 @@ int handle_svm_io_ins(struct guest_info * info) {
   addr_t inst_ptr;
 
   if (guest_va_to_host_pa(info,get_addr_linear(info,info->rip,&(info->segments.cs)),&inst_ptr)==-1) {
-    PrintDebug("Can't access instruction\n");
+    PrintError("Can't access instruction\n");
     return -1;
   }
 
@@ -125,7 +130,7 @@ int handle_svm_io_ins(struct guest_info * info) {
   } else if (io_info->sz32) {
     read_size = 4;
   } else {
-    PrintDebug("io_info Invalid Size\n");
+    PrintError("io_info Invalid Size\n");
     return -1;
   }
 
@@ -161,13 +166,13 @@ int handle_svm_io_ins(struct guest_info * info) {
 
     if (guest_va_to_host_va(info, dst_addr, &host_addr) == -1) {
       // either page fault or gpf...
-      PrintDebug("Could not convert Guest VA to host VA\n");
+      PrintError("Could not convert Guest VA to host VA\n");
       return -1;
     }
 
     if (hook->read(io_info->port, (char*)host_addr, read_size, hook->priv_data) != read_size) {
       // not sure how we handle errors.....
-      PrintDebug("Read Failure for ins on port %x\n", io_info->port);
+      PrintError("Read Failure for ins on port %x\n", io_info->port);
       return -1;
     }
 
@@ -194,7 +199,7 @@ int handle_svm_io_out(struct guest_info * info) {
   uint_t write_size = 0;
 
   if (hook == NULL) {
-    PrintDebug("Hook Not present for out on port %x\n", io_info->port);
+    PrintError("Hook Not present for out on port %x\n", io_info->port);
     // error, we should not have exited on this port
     return -1;
   }
@@ -212,7 +217,7 @@ int handle_svm_io_out(struct guest_info * info) {
 
   if (hook->write(io_info->port, &(info->vm_regs.rax), write_size, hook->priv_data) != write_size) {
     // not sure how we handle errors.....
-    PrintDebug("Write Failure for out on port %x\n", io_info->port);
+    PrintError("Write Failure for out on port %x\n", io_info->port);
     return -1;
   }
 
@@ -253,7 +258,7 @@ int handle_svm_io_outs(struct guest_info * info) {
 
 
   if (hook == NULL) {
-    PrintDebug("Hook Not present for outs on port %x\n", io_info->port);
+    PrintError("Hook Not present for outs on port %x\n", io_info->port);
     // error, we should not have exited on this port
     return -1;
   }
@@ -296,7 +301,7 @@ int handle_svm_io_outs(struct guest_info * info) {
   addr_t inst_ptr;
 
   if (guest_va_to_host_pa(info,get_addr_linear(info,info->rip,&(info->segments.cs)),&inst_ptr)==-1) {
-    PrintDebug("Can't access instruction\n");
+    PrintError("Can't access instruction\n");
     return -1;
   }
 
@@ -341,7 +346,7 @@ int handle_svm_io_outs(struct guest_info * info) {
 
     if (hook->write(io_info->port, (char*)host_addr, write_size, hook->priv_data) != write_size) {
       // not sure how we handle errors.....
-      PrintDebug("Write Failure for outs on port %x\n", io_info->port);
+      PrintError("Write Failure for outs on port %x\n", io_info->port);
       return -1;
     }
 
index c02eb5c..3615671 100644 (file)
@@ -29,7 +29,7 @@ int handle_cr0_write(struct guest_info * info) {
       
       PrintDebug("Real Mode write to CR0 at linear guest pa 0x%x\n",get_addr_linear(info,info->rip,&(info->segments.cs)));
 
-      PrintV3Segments(info);
+      //PrintV3Segments(info);
 
       // The real rip address is actually a combination of the rip + CS base 
       ret = read_guest_pa_memory(info, get_addr_linear(info, info->rip, &(info->segments.cs)), 15, instr);
@@ -289,10 +289,11 @@ int handle_cr0_write(struct guest_info * info) {
 
        index += 2;
  
-       PrintDebug("MovToCR0 instr:\n");
-       PrintTraceMemDump(instr, 15);
-       PrintDebug("EAX=%x\n", *(uint_t*)&(info->vm_regs.rax));
-
+       /*
+         PrintDebug("MovToCR0 instr:\n");
+         PrintTraceMemDump(instr, 15);
+         PrintDebug("EAX=%x\n", *(uint_t*)&(info->vm_regs.rax));
+       */
        addr_type = decode_operands32(&(info->vm_regs), instr + index, &index, &first_operand, &second_operand, REG32);
 
        if (addr_type != REG_OPERAND) {
@@ -302,7 +303,7 @@ int handle_cr0_write(struct guest_info * info) {
 
        new_cr0 = (struct cr0_32 *)first_operand;
 
-       PrintDebug("first operand=%x\n", *(uint_t *)first_operand);
+       //PrintDebug("first operand=%x\n", *(uint_t *)first_operand);
 
        if (info->shdw_pg_mode == SHADOW_PAGING) {
          struct cr0_32 * shadow_cr0 = (struct cr0_32 *)&(info->shdw_pg_state.guest_cr0);
@@ -333,7 +334,7 @@ int handle_cr0_write(struct guest_info * info) {
            info->mem_mode = PHYSICAL_MEM;
            PrintDebug("Entering Real Mode\n");
 
-           PrintV3CtrlRegs(info);
+           //PrintV3CtrlRegs(info);
            // reinstate the identity mapped paged tables
            // But keep the shadow tables around to handle TLB issues.... UGH...
            //info->shdw_pg_state.shadow_cr3 &= 0x00000fff;
@@ -348,7 +349,7 @@ int handle_cr0_write(struct guest_info * info) {
            shadow_cr0->et = 1;
            real_cr0->et = 1;
 
-           PrintV3CtrlRegs(info);
+           //PrintV3CtrlRegs(info);
 
          }
 
@@ -495,7 +496,7 @@ int handle_cr0_read(struct guest_info * info) {
       int ret;
 
       PrintDebug("Real Mode read from CR0 at linear guest pa 0x%x\n",get_addr_linear(info,info->rip,&(info->segments.cs)));
-      PrintV3Segments(info);
+      //PrintV3Segments(info);
 
       // The real rip address is actually a combination of the rip + CS base 
       ret = read_guest_pa_memory(info, get_addr_linear(info, info->rip, &(info->segments.cs)), 15, instr);
@@ -635,8 +636,10 @@ int handle_cr0_read(struct guest_info * info) {
       }
 
 
-      PrintDebug("Instr (15 bytes) at %x:\n", instr);
-      PrintTraceMemDump((char*)instr, 15);
+      /*
+       PrintDebug("Instr (15 bytes) at %x:\n", instr);
+       PrintTraceMemDump((char*)instr, 15);
+      */
 
       if (ret != 15) {
        // I think we should inject a GPF into the guest
@@ -747,7 +750,7 @@ int handle_cr3_write(struct guest_info * info) {
     int ret;
     char instr[15];
 
-    PrintDebug("Real Mode Write to CR3??? What the fuck???\n");
+    PrintDebug("Real Mode Write to CR3.\n");
     // We need to read the instruction, which is at CS:IP, but that 
     // linear address is guest physical without PG and guest virtual with PG
 
@@ -871,10 +874,10 @@ int handle_cr3_write(struct guest_info * info) {
     // linear address is guest physical without PG and guest virtual with PG
     if (info->mem_mode == PHYSICAL_MEM) { 
       // The real rip address is actually a combination of the rip + CS base 
-      PrintDebug("Writing Guest CR3 Write (Physical Address)\n");
+      //PrintDebug("Writing Guest CR3 Write (Physical Address)\n");
       ret = read_guest_pa_memory(info, get_addr_linear(info, info->rip, &(info->segments.cs)), 15, instr);
     } else { 
-      PrintDebug("Writing Guest CR3 Write (Virtual Address)\n");
+      //PrintDebug("Writing Guest CR3 Write (Virtual Address)\n");
       // The real rip address is actually a combination of the rip + CS base 
       ret = read_guest_va_memory(info, get_addr_linear(info, info->rip, &(info->segments.cs)), 15, instr);
     }
@@ -1011,8 +1014,8 @@ int handle_cr3_read(struct guest_info * info) {
     linear_addr = get_addr_linear(info, info->rip, &(info->segments.cs));
 
     
-    PrintDebug("RIP Linear: %x\n", linear_addr);
-    PrintV3Segments(info);
+    //PrintDebug("RIP Linear: %x\n", linear_addr);
+    //PrintV3Segments(info);
     
     ret = read_guest_pa_memory(info, linear_addr, 15, instr);
 
index fea0959..8908507 100644 (file)
@@ -3,7 +3,10 @@
 
 #include <palacios/vm_guest.h>
 
-
+#ifndef DEBUG_INTERRUPTS
+#undef PrintDebug
+#define PrintDebug(fmt, args...)
+#endif
 
 void init_interrupt_state(struct guest_info * info) {
   info->intr_state.excp_pending = 0;
@@ -45,7 +48,7 @@ int hook_irq_new(uint_t irq,
   d->opaque = opaque;
   
   if (os_hooks->hook_interrupt_new(irq,d)) { 
-    PrintDebug("hook_irq_new: failed to hook irq 0x%x to decode 0x%x\n", irq,d);
+    PrintError("hook_irq_new: failed to hook irq 0x%x to decode 0x%x\n", irq,d);
     return -1;
   } else {
     PrintDebug("hook_irq_new: hooked irq 0x%x to decode 0x%x\n", irq,d);
@@ -89,7 +92,7 @@ int hook_irq_for_guest_injection(struct guest_info *info, int irq)
                        info);
 
   if (rc) { 
-    PrintDebug("guest_irq_injection: failed to hook irq 0x%x for guest 0x%x\n", irq,info);
+    PrintError("guest_irq_injection: failed to hook irq 0x%x for guest 0x%x\n", irq,info);
     return -1;
   } else {
     PrintDebug("guest_irq_injection: hooked irq 0x%x for guest 0x%x\n", irq,info);
@@ -116,7 +119,7 @@ int raise_exception_with_error(struct guest_info * info, uint_t excp, uint_t err
     intr_state->excp_error_code_valid = 1;
     PrintDebug("Raising exception with error code: %x\n", error_code);
   } else {
-    PrintDebug("exception already pending, currently not implemented\n");
+    PrintError("exception already pending, currently not implemented\n");
     return -1;
   }
 
@@ -132,7 +135,7 @@ int raise_exception(struct guest_info * info, uint_t excp) {
     intr_state->excp_error_code = 0;
     intr_state->excp_error_code_valid = 0;
   } else {
-    PrintDebug("exception already pending, currently not implemented\n");
+    PrintError("exception already pending, currently not implemented\n");
     return -1;
   }
 
index d6431b7..420085a 100644 (file)
@@ -5,7 +5,10 @@
 extern struct vmm_os_hooks * os_hooks;
 
 
-
+#ifndef DEBUG_IO
+#undef PrintDebug
+#define PrintDebug(fmt, args...)
+#endif
 
 
 void init_vmm_io_map(vmm_io_map_t * io_map) {
index 770bb14..9eeecc6 100644 (file)
@@ -5,6 +5,10 @@
 #include <palacios/vm_guest_mem.h>
 #include <palacios/vmm_decoder.h>
 
+#ifndef DEBUG_SHADOW_PAGING
+#undef PrintDebug
+#define PrintDebug(fmt, args...)
+#endif
 
 
 int init_shadow_page_state(struct shadow_page_state * state) {
@@ -31,11 +35,11 @@ int handle_shadow_pagefault(struct guest_info * info, addr_t fault_addr, pf_erro
     case PROTECTED_PAE:
     case LONG:
     default:
-      PrintDebug("Unhandled CPU Mode\n");
+      PrintError("Unhandled CPU Mode\n");
       return -1;
     }
   } else {
-    PrintDebug("Invalid Memory mode\n");
+    PrintError("Invalid Memory mode\n");
     return -1;
   }
 }
@@ -63,7 +67,7 @@ static int handle_pd32_nonaligned_4MB_page(struct guest_info * info, pte32_t * p
 
     if (host_page_type == HOST_REGION_INVALID) {
       // Currently we don't support this, but in theory we could
-      PrintDebug("Invalid Host Memory Type\n");
+      PrintError("Invalid Host Memory Type\n");
       return -1;
     } else if (host_page_type == HOST_REGION_PHYSICAL_MEMORY) {
       addr_t shadow_pa = get_shadow_addr(info, guest_pa);
@@ -78,7 +82,7 @@ static int handle_pd32_nonaligned_4MB_page(struct guest_info * info, pte32_t * p
       pte_cursor->global_page = 0;
 
     } else {
-      PrintDebug("Unsupported Host Memory Type\n");
+      PrintError("Unsupported Host Memory Type\n");
       return -1;
     }
   }
@@ -95,7 +99,7 @@ int handle_shadow_pagefault32(struct guest_info * info, addr_t fault_addr, pf_er
   pde32_t * shadow_pde = (pde32_t *)&(shadow_pd[PDE32_INDEX(fault_addr)]);
 
   if (guest_pa_to_host_va(info, guest_cr3, (addr_t*)&guest_pd) == -1) {
-    PrintDebug("Invalid Guest PDE Address: 0x%x\n", guest_cr3);
+    PrintError("Invalid Guest PDE Address: 0x%x\n", guest_cr3);
     return -1;
   }
 
@@ -135,13 +139,13 @@ int handle_shadow_pagefault32(struct guest_info * info, addr_t fault_addr, pf_er
     return 0;
 
  
-    /*  
+#ifdef DEBUG_SHADOW_PAGING
        PrintDebug("Guest CR3=%x\n", guest_cr3);
-       PrintDebug("Guest PD\n");
+       PrintDebug("Guest PD\n");
        PrintPD32(guest_pd);
        PrintDebug("Shadow PD\n");
        PrintPD32(shadow_pd);
-    */
+#endif
 
     return -1;
   }
@@ -192,7 +196,7 @@ int handle_shadow_pagefault32(struct guest_info * info, addr_t fault_addr, pf_er
       if (host_page_type == HOST_REGION_INVALID) {
 
        raise_exception(info, MC_EXCEPTION);
-       PrintDebug("Invalid guest address in large page (0x%x)\n", guest_start_addr);
+       PrintError("Invalid guest address in large page (0x%x)\n", guest_start_addr);
        return -1;
       } else if (host_page_type == HOST_REGION_PHYSICAL_MEMORY) {
        addr_t host_start_addr = 0;
@@ -238,16 +242,16 @@ int handle_shadow_pagefault32(struct guest_info * info, addr_t fault_addr, pf_er
          memset(shadow_pt, 0, PAGE_SIZE);
 
          if (handle_pd32_nonaligned_4MB_page(info, shadow_pt, guest_start_addr, large_shadow_pde) == -1) {
-           PrintDebug("Non Aligned Large Page Error\n");
+           PrintError("Non Aligned Large Page Error\n");
            V3_Free(shadow_pt);
            return -1;
          }
 
 
-         /*
+#ifdef DEBUG_SHADOW_PAGING
            PrintDebug("non-aligned Shadow PT\n");
            PrintPT32(PT32_PAGE_ADDR(fault_addr), shadow_pt);     
-         */
+#endif
          shadow_pde->pt_base_addr = PD32_BASE_ADDR(shadow_pt);
        }
 
@@ -255,7 +259,7 @@ int handle_shadow_pagefault32(struct guest_info * info, addr_t fault_addr, pf_er
       } else {
        // Handle hooked pages as well as other special pages
        if (handle_special_page_fault(info, fault_addr, error_code) == -1) {
-         PrintDebug("Special Page Fault handler returned error for address: %x\n", fault_addr);
+         PrintError("Special Page Fault handler returned error for address: %x\n", fault_addr);
          return -1;
        }
       }
@@ -301,7 +305,7 @@ int handle_shadow_pagefault32(struct guest_info * info, addr_t fault_addr, pf_er
 
 
     if (handle_shadow_pte32_fault(info, fault_addr, error_code, shadow_pt, guest_pt)  == -1) {
-      PrintDebug("Error handling Page fault caused by PTE\n");
+      PrintError("Error handling Page fault caused by PTE\n");
       return -1;
     }
 
@@ -348,11 +352,13 @@ int handle_shadow_pte32_fault(struct guest_info * info,
   // Check the shadow page permissions
   shadow_pte_access = can_access_pte32(shadow_pt, fault_addr, error_code);
   
-
+#ifdef DEBUG_SHADOW_PAGING
   PrintDebug("Guest PTE: (access=%d)\n\t", guest_pte_access);
   PrintPTE32(fault_addr, guest_pte);
   PrintDebug("Shadow PTE: (access=%d)\n\t", shadow_pte_access);
   PrintPTE32(fault_addr, shadow_pte);
+#endif
+  
   /* This should be redone, 
      but basically the reasoning is that there can be multiple reasons for a page fault:
      If there is a permissions failure for a page present in the guest _BUT_ 
@@ -399,12 +405,13 @@ int handle_shadow_pte32_fault(struct guest_info * info,
       // Inject a machine check in the guest
 
       raise_exception(info, MC_EXCEPTION);
-
+#ifdef DEBUG_SHADOW_PAGING
       PrintDebug("Invalid Guest Address in page table (0x%x)\n", guest_pa);
       PrintDebug("fault_addr=0x%x next are guest and shadow ptes \n",fault_addr);
       PrintPTE32(fault_addr,guest_pte);
       PrintPTE32(fault_addr,shadow_pte);
       PrintDebug("Done.\n");
+#endif
       return 0;
 
     } else if (host_page_type == HOST_REGION_PHYSICAL_MEMORY) {
@@ -435,7 +442,7 @@ int handle_shadow_pte32_fault(struct guest_info * info,
     } else {
       // Page fault handled by hook functions
       if (handle_special_page_fault(info, fault_addr, error_code) == -1) {
-       PrintDebug("Special Page fault handler returned error for address: %x\n", fault_addr);
+       PrintError("Special Page fault handler returned error for address: %x\n", fault_addr);
        return -1;
       }
     }
@@ -454,8 +461,8 @@ int handle_shadow_pte32_fault(struct guest_info * info,
     info->ctrl_regs.cr2 = fault_addr;
     raise_exception_with_error(info, PF_EXCEPTION, *(uint_t *)&error_code);
 
-    PrintDebug("PTE Page fault fell through... Not sure if this should ever happen\n");
-    PrintDebug("Manual Says to inject page fault into guest\n");
+    PrintError("PTE Page fault fell through... Not sure if this should ever happen\n");
+    PrintError("Manual Says to inject page fault into guest\n");
     return -1;
   }
 
@@ -473,7 +480,7 @@ int handle_shadow_invlpg(struct guest_info * info) {
   if (info->mem_mode != VIRTUAL_MEM) {
     // Paging must be turned on...
     // should handle with some sort of fault I think
-    PrintDebug("ERROR: INVLPG called in non paged mode\n");
+    PrintError("ERROR: INVLPG called in non paged mode\n");
     return -1;
   }
 
@@ -485,7 +492,7 @@ int handle_shadow_invlpg(struct guest_info * info) {
 
     ret = read_guest_va_memory(info, get_addr_linear(info, info->rip, &(info->segments.cs)), 15, instr);
     if (ret != 15) {
-      PrintDebug("Could not read instruction 0x%x (ret=%d)\n", info->rip, ret);
+      PrintError("Could not read instruction 0x%x (ret=%d)\n", info->rip, ret);
       return -1;
     }
 
@@ -507,7 +514,7 @@ int handle_shadow_invlpg(struct guest_info * info) {
       pde32_t * guest_pd = NULL;
 
       if (guest_pa_to_host_va(info, guest_cr3, (addr_t*)&guest_pd) == -1) {
-       PrintDebug("Invalid Guest PDE Address: 0x%x\n", guest_cr3);
+       PrintError("Invalid Guest PDE Address: 0x%x\n", guest_cr3);
        return -1;
       }
 
@@ -538,8 +545,12 @@ int handle_shadow_invlpg(struct guest_info * info) {
          if (shadow_pde->present == 1) {
            pte32_t * shadow_pt = (pte32_t *)PDE32_T_ADDR((*shadow_pde));
            pte32_t * shadow_pte = (pte32_t *)&shadow_pt[PTE32_INDEX(first_operand)];
+
+#ifdef DEBUG_SHADOW_PAGING
            PrintDebug("Setting not present\n");
            PrintPTE32(first_operand, shadow_pte);
+#endif
+
            shadow_pte->present = 0;
          }
        }
@@ -547,11 +558,11 @@ int handle_shadow_invlpg(struct guest_info * info) {
        info->rip += index;
 
       } else {
-       PrintDebug("Invalid Operand type\n");
+       PrintError("Invalid Operand type\n");
        return -1;
       }
     } else {
-      PrintDebug("invalid Instruction Opcode\n");
+      PrintError("invalid Instruction Opcode\n");
       PrintTraceMemDump(instr, 15);
       return -1;
     }