X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fsvm_handler.c;h=5c85a5673a9597a1209e97c6521e4ef5616d3504;hb=debabd511ff9dc2d0e6cd608045ac44295fe7319;hp=893f49c0bd6caef1ea141f795f0f16afef86e7fc;hpb=2bfd0e9c8aa5d520e4207fd6cf50a5f50993e3ca;p=palacios-OLD.git diff --git a/palacios/src/palacios/svm_handler.c b/palacios/src/palacios/svm_handler.c index 893f49c..5c85a56 100644 --- a/palacios/src/palacios/svm_handler.c +++ b/palacios/src/palacios/svm_handler.c @@ -31,6 +31,7 @@ #include #include #include +#include @@ -79,13 +80,17 @@ int v3_handle_svm_exit(struct guest_info * info) { // PrintDebug("SVM Returned: Exit Code: 0x%x \t\t(tsc=%ul)\n",exit_code, (uint_t)info->time_state.guest_tsc); - if ((0) && (exit_code < 0x4f)) { + if ((0) && (exit_code <= VMEXIT_EXCP14)) { uchar_t instr[32]; int ret; // Dump out the instr stream //PrintDebug("RIP: %x\n", guest_state->rip); - PrintDebug("RIP Linear: %p\n", (void *)get_addr_linear(info, info->rip, &(info->segments.cs))); + PrintDebug("\n\n\nRIP Linear: %p\n", (void *)get_addr_linear(info, info->rip, &(info->segments.cs))); + + v3_print_GPRs(info); + v3_print_ctrl_regs(info); + // OK, now we will read the instruction // The only difference between PROTECTED and PROTECTED_PG is whether we read @@ -97,6 +102,8 @@ int v3_handle_svm_exit(struct guest_info * info) { ret = read_guest_va_memory(info, get_addr_linear(info, info->rip, &(info->segments.cs)), 32, instr); } + + if (ret != 32) { // I think we should inject a GPF into the guest PrintDebug("Could not read instruction (ret=%d)\n", ret); @@ -265,6 +272,25 @@ int v3_handle_svm_exit(struct guest_info * info) { */ break; } + + + + case VMEXIT_VMMCALL: + { + /* + * Hypercall + */ + + if (v3_handle_hypercall(info) == -1) { + return -1; + } + + // VMMCALL is a 3 byte op + info->rip += 3; + break; + } + + case VMEXIT_INTR: { // handled by interrupt dispatch earlier @@ -294,56 +320,6 @@ int v3_handle_svm_exit(struct guest_info * info) { break; -#if 0 - // Emulation handlers currently not used - case VMEXIT_EXCP1: - { -#ifdef DEBUG_EMULATOR - PrintDebug("DEBUG EXCEPTION\n"); -#endif - if (info->run_state == VM_EMULATING) { - if (v3_emulation_exit_handler(info) == -1) { - return -1; - } - } else { - PrintError("VMMCALL with not emulator...\n"); - return -1; - } - break; - } - - - case VMEXIT_VMMCALL: - { -#ifdef DEBUG_EMULATOR - PrintDebug("VMMCALL\n"); -#endif - if (info->run_state == VM_EMULATING) { - if (v3_emulation_exit_handler(info) == -1) { - return -1; - } - } else { - /* - ulong_t tsc_spread = 0; - ullong_t exit_tsc = 0; - - ulong_t rax = (ulong_t)info->vm_regs.rbx; - ulong_t rdx = (ulong_t)info->vm_regs.rcx; - - *(ulong_t *)(&exit_tsc) = rax; - *(((ulong_t *)(&exit_tsc)) + 1) = rdx; - - tsc_spread = info->exit_tsc - exit_tsc; - - PrintError("VMMCALL tsc diff = %lu\n",tsc_spread); - info->rip += 3; - */ - PrintError("VMMCALL with not emulator...\n"); - return -1; - } - break; - } -#endif case VMEXIT_WBINVD: @@ -351,7 +327,7 @@ int v3_handle_svm_exit(struct guest_info * info) { #ifdef DEBUG_EMULATOR PrintDebug("WBINVD\n"); #endif - if (!v3_handle_svm_wbinvd(info)) { + if (v3_handle_svm_wbinvd(info) == -1) { return -1; } break; @@ -363,68 +339,39 @@ int v3_handle_svm_exit(struct guest_info * info) { /* Exits Following this line are NOT HANDLED */ /*=======================================================================*/ - default: { - - addr_t rip_addr; - uchar_t buf[15]; - addr_t host_addr; - - PrintDebug("Unhandled SVM Exit: %s\n", vmexit_code_to_str(exit_code)); - - rip_addr = get_addr_linear(info, guest_state->rip, &(info->segments.cs)); - - - PrintError("SVM Returned:(VMCB=%p)\n", (void *)(info->vmm_data)); - PrintError("RIP: %p\n", (void *)(addr_t)(guest_state->rip)); - PrintError("RIP Linear: %p\n", (void *)(addr_t)(rip_addr)); - - PrintError("SVM Returned: Exit Code: %p\n", (void *)(addr_t)exit_code); - - 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)); - - 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)); - - + default: + { - if (info->mem_mode == PHYSICAL_MEM) { - if (guest_pa_to_host_va(info, guest_state->rip, &host_addr) == -1) { - 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_va(info, guest_state->rip, &host_addr) == -1) { - PrintError("Could not translate guest_state->rip to host address\n"); - return -1; + addr_t rip_addr; + + PrintDebug("Unhandled SVM Exit: %s\n", vmexit_code_to_str(exit_code)); + + rip_addr = get_addr_linear(info, guest_state->rip, &(info->segments.cs)); + + + PrintError("SVM Returned:(VMCB=%p)\n", (void *)(info->vmm_data)); + PrintError("RIP: %p\n", (void *)(addr_t)(guest_state->rip)); + PrintError("RIP Linear: %p\n", (void *)(addr_t)(rip_addr)); + + PrintError("SVM Returned: Exit Code: %p\n", (void *)(addr_t)exit_code); + + 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)); + + 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->shdw_pg_mode == SHADOW_PAGING) { + PrintHostPageTables(info, info->ctrl_regs.cr3); + //PrintGuestPageTables(info, info->shdw_pg_state.guest_cr3); } - } else { - PrintError("Invalid memory mode\n"); + return -1; + } - - PrintError("Host Address of rip = 0x%p\n", (void *)host_addr); - - memset(buf, 0, 32); - - PrintError("Reading instruction stream in guest (addr=%p)\n", (void *)rip_addr); - - if (info->mem_mode == PHYSICAL_MEM) { - read_guest_pa_memory(info, rip_addr - 16, 32, buf); - } else { - read_guest_va_memory(info, rip_addr - 16, 32, buf); - } - - PrintDebug("16 bytes before Rip\n"); - PrintTraceMemDump(buf, 16); - PrintDebug("Rip onward\n"); - PrintTraceMemDump(buf+16, 16); - - return -1; - - } break; - + } // END OF SWITCH (EXIT_CODE)