Removed debug prints. Fixed virtio decode function to handle full set of 16 registers.
authorGanShun <ganshun@gmail.com>
Sat, 26 Sep 2015 22:20:20 +0000 (15:20 -0700)
committerBarret Rhoden <brho@cs.berkeley.edu>
Tue, 3 Nov 2015 15:53:13 +0000 (10:53 -0500)
Removed all debug prints after vm has fully started.

Fixed decode function to find the correct register from the instruction and handle full set of 16 registers.

Signed-off-by: GanShun <ganshun@gmail.com>
Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/arch/x86/trap.c
kern/arch/x86/vmm/intel/vmx.c
kern/drivers/dev/cons.c
tests/vmm/vmrunkernel.c
user/vmm/decode.c
user/vmm/virtio-mmio.c

index 8972863..8cb1b9c 100644 (file)
@@ -646,7 +646,6 @@ void sysenter_callwrapper(struct syscall *sysc, unsigned long count,
 void send_ipi(uint32_t os_coreid, uint8_t vector)
 {
        int hw_coreid = get_hw_coreid(os_coreid);
-       printk("Sending IPI with core: %d, interrupt: %d", os_coreid, vector);
        if (hw_coreid == -1) {
                panic("Unmapped OS coreid (OS %d)!\n", os_coreid);
                return;
index 104ff26..440cf53 100644 (file)
 
 /* debug stuff == remove later. It's not even multivm safe. */
 uint64_t idtr;
+int debug =0;
 
 // END debug
 static unsigned long *msr_bitmap;
@@ -1772,6 +1773,7 @@ static void vmx_set_posted_interrupt(int vector)
 int vmx_interrupt_notify(struct vmctl *v) {
        int vm_core = v->core;
        send_ipi(vm_core, I_VMMCP_POSTED);
+       if(debug) printk("Posting Interrupt\n");
        return 0;
 }
 
@@ -1868,7 +1870,7 @@ int vmx_launch(struct vmctl *v) {
                 * I don't see how: it will mainly just break your guest vm AFAICT.
                 */
                if (v->interrupt) {
-                       printk("Set VM_ENTRY_INFTR_INFO_FIELD to 0x%x\n", v->interrupt);
+                       if(debug) printk("Set VM_ENTRY_INFTR_INFO_FIELD to 0x%x\n", v->interrupt);
                        //vmcs_writel(VM_ENTRY_INTR_INFO_FIELD, v->interrupt);
                        //vapic_status_dump_kernel((void *)v->vapic);
                        
@@ -1887,8 +1889,8 @@ int vmx_launch(struct vmctl *v) {
        vcpu->shutdown = 0;
        vmx_put_cpu(vcpu);
        if (interrupting) {
-               printk("BEFORE INTERRUPT: ");
-               vmx_dump_cpu(vcpu);
+               if(debug) printk("BEFORE INTERRUPT: ");
+               if(debug) vmx_dump_cpu(vcpu);
        }
        vcpu->ret_code = -1;
 
@@ -1910,14 +1912,14 @@ int vmx_launch(struct vmctl *v) {
                vmx_put_cpu(vcpu);
 
                if (interrupting) {
-                       printk("POST INTERRUPT: \n");
+                       if(debug) printk("POST INTERRUPT: \n");
                        unsigned long cr8val;
                        asm volatile("mov %%cr8,%0" : "=r" (cr8val));
-                       printk("CR8 Value: 0x%08x", cr8val);
+                       if(debug) printk("CR8 Value: 0x%08x", cr8val);
                        
-                       printk("%s: Status is %04x\n", __func__,
+                       if(debug) printk("%s: Status is %04x\n", __func__,
                                        vmcs_read16(GUEST_INTR_STATUS));
-                       vmx_dump_cpu(vcpu);
+                       if(debug) vmx_dump_cpu(vcpu);
                }
 
                if (ret == EXIT_REASON_VMCALL) {
index dd25aa5..ff93ca4 100644 (file)
@@ -1044,7 +1044,7 @@ static long conswrite(struct chan *c, void *va, long n, int64_t offset)
                        if ((offset >> 12) ==1) {
                                ret = vm_post_interrupt(&vmctl);
                                n = ret;
-                               printk("vm_interrupt_notify returns %d\n", ret);
+                               //printk("vm_interrupt_notify returns %d\n", ret);
                        }
                        else {
                                ret = vm_run(&vmctl);
index 9262d86..2412f1f 100644 (file)
@@ -153,7 +153,7 @@ int resumeprompt = 0;
 /* unlike Linux, this shared struct is for both host and guest. */
 //     struct virtqueue *constoguest = 
 //             vring_new_virtqueue(0, 512, 8192, 0, inpages, NULL, NULL, "test");
-uint64_t virtio_mmio_base = 0x100000000;
+uint64_t virtio_mmio_base = 0x100000000ULL;
 
 void vapic_status_dump(FILE *f, void *vapic);
 static void set_posted_interrupt(int vector);
@@ -248,7 +248,7 @@ void *consin(void *arg)
        if (debug) fprintf(stderr, "Spin on console being read, print num queues, halt\n");
 
        for(num = 0;! quit;num++) {
-               int debug = 1;
+               //int debug = 1;
                /* host: use any buffers we should have been sent. */
                head = wait_for_vq_desc(v, iov, &outlen, &inlen);
                if (debug)
@@ -361,10 +361,10 @@ static void set_posted_interrupt(int vector)
        // Move to the correct location to set our bit.
        bit_vec = pir + vector/(sizeof(unsigned long)*8);
        bit_offset = vector%(sizeof(unsigned long)*8);
-       fprintf(stderr, "%s: Pre set PIR dump", __func__);
-       pir_dump();
-       vapic_status_dump(stderr, (void *)vmctl.vapic);
-       fprintf(stderr, "%s: Setting pir bit offset %d at 0x%p", __func__,
+       if(debug) fprintf(stderr, "%s: Pre set PIR dump\n", __func__);
+       if(debug) pir_dump();
+       if(debug) vapic_status_dump(stderr, (void *)vmctl.vapic);
+       if(debug) fprintf(stderr, "%s: Setting pir bit offset %d at 0x%p\n", __func__,
                        bit_offset, bit_vec);
        test_and_set_bit(bit_offset, bit_vec);
 
@@ -374,7 +374,7 @@ static void set_posted_interrupt(int vector)
                        bit_vec);
        test_and_set_bit(0, bit_vec);*/
 
-       pir_dump();
+       if(debug) pir_dump();
 }
 
 int main(int argc, char **argv)
@@ -656,11 +656,11 @@ fprintf(stderr, "%p %p %p %p\n", PGSIZE, PGSHIFT, PML1_SHIFT, PML1_PTE_REACH);
        fprintf(stderr, "threads started\n");
        fprintf(stderr, "Writing command :%s:\n", cmd);
        
-       vapic_status_dump(stderr, (void *)vmctl.vapic);
+       if(debug) vapic_status_dump(stderr, (void *)vmctl.vapic);
 
        ret = pwrite(fd, &vmctl, sizeof(vmctl), 0);
 
-       vapic_status_dump(stderr, (void *)vmctl.vapic);
+       if(debug) vapic_status_dump(stderr, (void *)vmctl.vapic);
 
        if (ret != sizeof(vmctl)) {
                perror(cmd);
@@ -735,12 +735,12 @@ fprintf(stderr, "%p %p %p %p\n", PGSIZE, PGSHIFT, PML1_SHIFT, PML1_PTE_REACH);
                        case  EXIT_REASON_VMCALL:
                                byte = vmctl.regs.tf_rdi;
                                printf("%c", byte);
-                               if (byte == '\n') printf("%c", 'V');
+                               if (byte == '\n') printf("%c", '%');
                                vmctl.regs.tf_rip += 3;
                                break;
                        case EXIT_REASON_EXTERNAL_INTERRUPT:
                                //debug = 1;
-                               fprintf(stderr, "XINT 0x%x 0x%x\n", vmctl.intrinfo1, vmctl.intrinfo2);
+                               if (debug) fprintf(stderr, "XINT 0x%x 0x%x\n", vmctl.intrinfo1, vmctl.intrinfo2);
                                pir_dump();
                                vmctl.command = RESUME;
                                break;
@@ -776,7 +776,7 @@ fprintf(stderr, "%p %p %p %p\n", PGSIZE, PGSHIFT, PML1_SHIFT, PML1_PTE_REACH);
                                while (!consdata)
                                        ;
                                //debug = 1;
-                               vapic_status_dump(stderr, (void *)vmctl.vapic);
+                               if(debug) vapic_status_dump(stderr, (void *)vmctl.vapic);
                                if (debug)fprintf(stderr, "Resume with consdata ...\n");
                                vmctl.regs.tf_rip += 3;
                                ret = pwrite(fd, &vmctl, sizeof(vmctl), 0);
@@ -840,7 +840,7 @@ fprintf(stderr, "%p %p %p %p\n", PGSIZE, PGSHIFT, PML1_SHIFT, PML1_PTE_REACH);
                        break;
                if (consdata) {
                        if (debug) fprintf(stderr, "inject an interrupt\n");
-                       fprintf(stderr, "XINT 0x%x 0x%x\n", vmctl.intrinfo1, vmctl.intrinfo2);
+                       if (debug) fprintf(stderr, "XINT 0x%x 0x%x\n", vmctl.intrinfo1, vmctl.intrinfo2);
                        vmctl.interrupt = 0x80000000 | virtioirq;
                        virtio_mmio_set_vring_irq();
                        consdata = 0;
index f1575dc..afcefb6 100644 (file)
@@ -209,10 +209,11 @@ int decode(struct vmctl *v, uint64_t *gpa, uint8_t *destreg, uint64_t **regp, in
 
        *advance = insize(kva);
 
-       uint16_t ins = *(uint16_t *)(kva + 8*(kva[0] == 0x44));
+       uint16_t ins = *(uint16_t *)(kva + (kva[0] == 0x44));
        DPRINTF("ins is %04x\n", ins);
                
        *destreg = (ins>>11) & 7;
+       *destreg += 8*(kva[0] == 0x44);
        // Our primitive approach wins big here.
        // We don't have to decode the register or the offset used
        // in the computation; that was done by the CPU and is the gpa.
@@ -242,6 +243,30 @@ int decode(struct vmctl *v, uint64_t *gpa, uint8_t *destreg, uint64_t **regp, in
        case 7:
                *regp = &v->regs.tf_rdi;
                break;
+       case 8:
+               *regp = &v->regs.tf_r8;
+               break;
+       case 9:
+               *regp = &v->regs.tf_r9;
+               break;
+       case 10:
+               *regp = &v->regs.tf_r10;
+               break;
+       case 11:
+               *regp = &v->regs.tf_r11;
+               break;
+       case 12:
+               *regp = &v->regs.tf_r12;
+               break;
+       case 13:
+               *regp = &v->regs.tf_r13;
+               break;
+       case 14:
+               *regp = &v->regs.tf_r14;
+               break;
+       case 15:
+               *regp = &v->regs.tf_r15;
+               break;
        }
        return 0;
 }
index 96abfe4..473928a 100644 (file)
@@ -183,6 +183,9 @@ static uint32_t virtio_mmio_read(uint64_t gpa)
            return mmio.vqdev->vqs[mmio.qsel].pfn;
     case VIRTIO_MMIO_INTERRUPT_STATUS:
                // pretty sure this is per-mmio, not per-q. 
+       //fprintf(stderr, "MMIO ISR 0x%08x\n", mmio.isr);
+       //fprintf(stderr, "GPA IS 0x%016x\n", gpa);
+       //fprintf(stderr, "mmio.bar IS 0x%016x\n", mmio.bar);
                return mmio.isr;
            //return mmio.vqdev->vqs[mmio.qsel].isr;
     case VIRTIO_MMIO_STATUS: