X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fvmm_emulator.c;h=f80aade45891286c1e2148669c3d1add953587c1;hb=c43fab2e53aa1a129a1020410c67de0240369ec0;hp=cc1c380e4a225f202564f40b34f8e548d1df34a4;hpb=a98de7d14ac0a9807303a39f5fcbfbd648665a32;p=palacios.git diff --git a/palacios/src/palacios/vmm_emulator.c b/palacios/src/palacios/vmm_emulator.c index cc1c380..f80aade 100644 --- a/palacios/src/palacios/vmm_emulator.c +++ b/palacios/src/palacios/vmm_emulator.c @@ -24,7 +24,7 @@ #include #include -#ifndef DEBUG_EMULATOR +#ifndef CONFIG_DEBUG_EMULATOR #undef PrintDebug #define PrintDebug(fmt, args...) #endif @@ -38,6 +38,7 @@ static int emulate_string_write_op(struct guest_info * info, struct x86_instr * int (*write_fn)(addr_t guest_addr, void * src, uint_t length, void * priv_data), void * priv_data) { uint_t emulation_length = 0; + uint_t emulation_iter_cnt = 0; addr_t tmp_rcx = 0; addr_t src_addr = 0; @@ -47,16 +48,17 @@ static int emulate_string_write_op(struct guest_info * info, struct x86_instr * return -1; } - emulation_length = ( (dec_instr->str_op_length < (0x1000 - PAGE_OFFSET_4KB(write_gva))) ? + /*emulation_length = ( (dec_instr->str_op_length < (0x1000 - PAGE_OFFSET_4KB(write_gva))) ? dec_instr->str_op_length : + (0x1000 - PAGE_OFFSET_4KB(write_gva)));*/ + emulation_length = ( (dec_instr->str_op_length * (dec_instr->dst_operand.size) < (0x1000 - PAGE_OFFSET_4KB(write_gva))) ? + dec_instr->str_op_length * dec_instr->dst_operand.size : (0x1000 - PAGE_OFFSET_4KB(write_gva))); /* ** Fix emulation length so that it doesn't overrun over the src page either ** */ - tmp_rcx = emulation_length; + emulation_iter_cnt = emulation_length / dec_instr->dst_operand.size; + tmp_rcx = emulation_iter_cnt; - - - if (dec_instr->op_type == V3_OP_MOVS) { // figure out addresses here.... @@ -92,7 +94,7 @@ static int emulate_string_write_op(struct guest_info * info, struct x86_instr * // RCX is only modified if the rep prefix is present if (dec_instr->prefixes.rep == 1) { - info->vm_regs.rcx -= emulation_length; + info->vm_regs.rcx -= emulation_iter_cnt; } } else if (dec_instr->op_type == V3_OP_STOS) { @@ -116,7 +118,7 @@ static int emulate_string_write_op(struct guest_info * info, struct x86_instr * // RCX is only modified if the rep prefix is present if (dec_instr->prefixes.rep == 1) { - info->vm_regs.rcx -= emulation_length; + info->vm_regs.rcx -= emulation_iter_cnt; } } else { @@ -294,7 +296,7 @@ int v3_emulate_write_op(struct guest_info * info, addr_t write_gva, addr_t write int dst_op_len = 0; PrintDebug("Emulating Write for instruction at %p\n", (void *)(addr_t)(info->rip)); - PrintDebug("GVA=%p\n", (void *)write_gva); + PrintDebug("GVA=%p Dst_Addr=%p\n", (void *)write_gva, (void *)dst_addr); if (info->mem_mode == PHYSICAL_MEM) { ret = read_guest_pa_memory(info, get_addr_linear(info, info->rip, &(info->segments.cs)), 15, instr); @@ -394,11 +396,13 @@ int v3_emulate_read_op(struct guest_info * info, addr_t read_gva, addr_t read_gp } else { ret = read_guest_va_memory(info, get_addr_linear(info, info->rip, &(info->segments.cs)), 15, instr); } - + if (ret == -1) { + PrintError("Could not read instruction for Emulated Read at %p\n", (void *)(addr_t)(info->rip)); return -1; } + if (v3_decode(info, (addr_t)instr, &dec_instr) == -1) { PrintError("Decoding Error\n"); // Kick off single step emulator @@ -415,8 +419,8 @@ int v3_emulate_read_op(struct guest_info * info, addr_t read_gva, addr_t read_gp if (info->shdw_pg_mode == SHADOW_PAGING) { if ((dec_instr.src_operand.type != MEM_OPERAND) || (dec_instr.src_operand.operand != read_gva)) { - PrintError("Inconsistency between Pagefault and Instruction Decode XED_ADDR=%p, PF_ADDR=%p\n", - (void *)dec_instr.src_operand.operand, (void *)read_gva); + PrintError("Inconsistency between Pagefault and Instruction Decode XED_ADDR=%p, PF_ADDR=%p operand_type=%d\n", + (void *)dec_instr.src_operand.operand, (void *)read_gva, dec_instr.src_operand.type); return -1; } } else {