#define EXIT_REASON_EXTERNAL_INTERRUPT 6
 #define EXIT_REASON_IPI                        7
 #define EXIT_REASON_PTC_G              8
+#define EXIT_REASON_DEBUG              20
 
 /*Define vmm address space and vm data space.*/
 #define KVM_VMM_SIZE (__IA64_UL_CONST(16)<<20)
                        KVM_MEM_DIRTY_LOG_SIZE) / sizeof(struct kvm_vcpu_data)
 #define KVM_MAX_MEM_SIZE (KVM_P2M_SIZE >> 3 << PAGE_SHIFT)
 
+#define VMM_LOG_LEN 256
+
 #include <linux/types.h>
 #include <linux/mm.h>
 #include <linux/kvm.h>
 
        unsigned long opcode;
        unsigned long cause;
+       char log_buf[VMM_LOG_LEN];
        union context host;
        union context guest;
 };
 
 
 CFLAGS_vcpu.o += -mfixed-range=f2-f5,f12-f127
 kvm-intel-objs = vmm.o vmm_ivt.o trampoline.o vcpu.o optvfault.o mmio.o \
-       vtlb.o process.o
+       vtlb.o process.o kvm_lib.o
 #Add link memcpy and memset to avoid possible structure assignment error
 kvm-intel-objs += memcpy.o memset.o
 obj-$(CONFIG_KVM_INTEL) += kvm-intel.o
 
        return 1;
 }
 
+static int handle_vcpu_debug(struct kvm_vcpu *vcpu,
+                               struct kvm_run *kvm_run)
+{
+       printk("VMM: %s", vcpu->arch.log_buf);
+       return 1;
+}
+
 static int (*kvm_vti_exit_handlers[])(struct kvm_vcpu *vcpu,
                struct kvm_run *kvm_run) = {
        [EXIT_REASON_VM_PANIC]              = handle_vm_error,
        [EXIT_REASON_EXTERNAL_INTERRUPT]    = handle_external_interrupt,
        [EXIT_REASON_IPI]                   = handle_ipi,
        [EXIT_REASON_PTC_G]                 = handle_global_purge,
+       [EXIT_REASON_DEBUG]                 = handle_vcpu_debug,
 
 };
 
 
--- /dev/null
+/*
+ * kvm_lib.c: Compile some libraries for kvm-intel module.
+ *
+ *     Just include kernel's library, and disable symbols export.
+ *     Copyright (C) 2008, Intel Corporation.
+ *     Xiantao Zhang  (xiantao.zhang@intel.com)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+#undef CONFIG_MODULES
+#include "../../../lib/vsprintf.c"
+#include "../../../lib/ctype.c"
 
 {
        _vmm_raw_spin_unlock(lock);
 }
+
+static void vcpu_debug_exit(struct kvm_vcpu *vcpu)
+{
+       struct exit_ctl_data *p = &vcpu->arch.exit_data;
+       long psr;
+
+       local_irq_save(psr);
+       p->exit_reason = EXIT_REASON_DEBUG;
+       vmm_transition(vcpu);
+       local_irq_restore(psr);
+}
+
+asmlinkage int printk(const char *fmt, ...)
+{
+       struct kvm_vcpu *vcpu = current_vcpu;
+       va_list args;
+       int r;
+
+       memset(vcpu->arch.log_buf, 0, VMM_LOG_LEN);
+       va_start(args, fmt);
+       r = vsnprintf(vcpu->arch.log_buf, VMM_LOG_LEN, fmt, args);
+       va_end(args);
+       vcpu_debug_exit(vcpu);
+       return r;
+}
+
 module_init(kvm_vmm_init)
 module_exit(kvm_vmm_exit)