X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fvmm_v3dec.c;h=c1df822c00b3ee39f8fd9ae1e6f2ccc8db2b2a4e;hb=9058423c8215f5abb3ad2fb789c5b16a250e7c65;hp=0a1aacbf935ad5e94842dd507d498a5518ddd339;hpb=1f1844528b1efc16001dff2fbdb2ab67bcf8c1ab;p=palacios.releases.git diff --git a/palacios/src/palacios/vmm_v3dec.c b/palacios/src/palacios/vmm_v3dec.c index 0a1aacb..c1df822 100644 --- a/palacios/src/palacios/vmm_v3dec.c +++ b/palacios/src/palacios/vmm_v3dec.c @@ -20,6 +20,11 @@ #include #include +#ifndef CONFIG_DEBUG_DECODER +#undef PrintDebug +#define PrintDebug(fmt, args...) +#endif + #define MASK(val, length) ({ \ ullong_t mask = 0x0LL; \ @@ -80,8 +85,16 @@ int v3_decode(struct guest_info * core, addr_t instr_ptr, struct x86_instr * ins // REX prefix if (v3_get_vm_cpu_mode(core) == LONG) { - if ((*(uint8_t *)(instr_ptr + length) & 0xf0) == 0x40) { - *(uint8_t *)&(instr->prefixes.rex) = *(uint8_t *)(instr_ptr + length); + uint8_t prefix = *(uint8_t *)(instr_ptr + length); + + if ((prefix & 0xf0) == 0x40) { + instr->prefixes.rex = 1; + + instr->prefixes.rex_rm = (prefix & 0x01); + instr->prefixes.rex_sib_idx = ((prefix & 0x02) >> 1); + instr->prefixes.rex_reg = ((prefix & 0x04) >> 2); + instr->prefixes.rex_op_size = ((prefix & 0x08) >> 3); + length += 1; } } @@ -145,9 +158,7 @@ static int parse_operands(struct guest_info * core, uint8_t * instr_ptr, case MOV_IMM2:{ uint8_t reg_code = 0; - instr->dst_operand.size = operand_width; - - ret = decode_rm_operand(core, instr_ptr, instr, &(instr->dst_operand), ®_code); + ret = decode_rm_operand(core, instr_ptr, form, instr, &(instr->dst_operand), ®_code); if (ret == -1) { PrintError("Error decoding operand\n"); @@ -159,6 +170,7 @@ static int parse_operands(struct guest_info * core, uint8_t * instr_ptr, instr->src_operand.type = IMM_OPERAND; instr->src_operand.size = operand_width; + if (operand_width == 1) { instr->src_operand.operand = *(uint8_t *)instr_ptr; } else if (operand_width == 2) { @@ -170,6 +182,9 @@ static int parse_operands(struct guest_info * core, uint8_t * instr_ptr, return -1; } + instr->src_operand.read = 1; + instr->dst_operand.write = 1; + instr_ptr += operand_width; instr->num_operands = 2; @@ -192,9 +207,7 @@ static int parse_operands(struct guest_info * core, uint8_t * instr_ptr, case MOV_2MEM: { uint8_t reg_code = 0; - instr->dst_operand.size = operand_width; - - ret = decode_rm_operand(core, instr_ptr, instr, &(instr->dst_operand), ®_code); + ret = decode_rm_operand(core, instr_ptr, form, instr, &(instr->dst_operand), ®_code); if (ret == -1) { PrintError("Error decoding operand\n"); @@ -206,6 +219,10 @@ static int parse_operands(struct guest_info * core, uint8_t * instr_ptr, instr->src_operand.type = REG_OPERAND; instr->src_operand.size = operand_width; + instr->src_operand.read = 1; + instr->dst_operand.write = 1; + + decode_gpr(core, reg_code, &(instr->src_operand)); instr->num_operands = 2; @@ -226,9 +243,8 @@ static int parse_operands(struct guest_info * core, uint8_t * instr_ptr, case XOR_MEM2: case MOV_MEM2: { uint8_t reg_code = 0; - instr->src_operand.size = operand_width; - ret = decode_rm_operand(core, instr_ptr, instr, &(instr->src_operand), ®_code); + ret = decode_rm_operand(core, instr_ptr, form, instr, &(instr->src_operand), ®_code); if (ret == -1) { PrintError("Error decoding operand\n"); @@ -241,6 +257,9 @@ static int parse_operands(struct guest_info * core, uint8_t * instr_ptr, instr->dst_operand.type = REG_OPERAND; decode_gpr(core, reg_code, &(instr->dst_operand)); + instr->src_operand.read = 1; + instr->dst_operand.write = 1; + instr->num_operands = 2; break; @@ -252,9 +271,9 @@ static int parse_operands(struct guest_info * core, uint8_t * instr_ptr, case SUB_IMM2SX_8: case XOR_IMM2SX_8: { uint8_t reg_code = 0; - instr->src_operand.size = operand_width; - ret = decode_rm_operand(core, instr_ptr, instr, &(instr->src_operand), ®_code); + ret = decode_rm_operand(core, instr_ptr, form, instr, &(instr->dst_operand), ®_code); + if (ret == -1) { PrintError("Error decoding operand\n"); @@ -267,6 +286,9 @@ static int parse_operands(struct guest_info * core, uint8_t * instr_ptr, instr->src_operand.size = operand_width; instr->src_operand.operand = *(sint8_t *)instr_ptr; // sign extend. + instr->src_operand.read = 1; + instr->dst_operand.write = 1; + instr_ptr += 1; instr->num_operands = 2; @@ -290,10 +312,15 @@ static int parse_operands(struct guest_info * core, uint8_t * instr_ptr, instr->src_operand.size = operand_width; instr->src_operand.operand = get_addr_linear(core, MASK(core->vm_regs.rsi, addr_width), &(core->segments.ds)); + instr->dst_operand.type = MEM_OPERAND; instr->dst_operand.size = operand_width; instr->dst_operand.operand = get_addr_linear(core, MASK(core->vm_regs.rdi, addr_width), &(core->segments.es)); + + instr->src_operand.read = 1; + instr->dst_operand.write = 1; + instr->num_operands = 2; break; @@ -301,9 +328,7 @@ static int parse_operands(struct guest_info * core, uint8_t * instr_ptr, case MOV_2CR: { uint8_t reg_code = 0; - instr->src_operand.size = operand_width; - - ret = decode_rm_operand(core, instr_ptr, instr, &(instr->src_operand), + ret = decode_rm_operand(core, instr_ptr, form, instr, &(instr->src_operand), ®_code); if (ret == -1) { @@ -317,17 +342,19 @@ static int parse_operands(struct guest_info * core, uint8_t * instr_ptr, instr->dst_operand.size = operand_width; decode_cr(core, reg_code, &(instr->dst_operand)); + instr->src_operand.read = 1; + instr->dst_operand.write = 1; + instr->num_operands = 2; break; } case MOV_CR2: { uint8_t reg_code = 0; - instr->dst_operand.size = operand_width; - - ret = decode_rm_operand(core, instr_ptr, instr, &(instr->dst_operand), + ret = decode_rm_operand(core, instr_ptr, form, instr, &(instr->dst_operand), ®_code); + if (ret == -1) { PrintError("Error decoding operand for (%s)\n", op_form_to_str(form)); return -1; @@ -339,6 +366,9 @@ static int parse_operands(struct guest_info * core, uint8_t * instr_ptr, instr->src_operand.size = operand_width; decode_cr(core, reg_code, &(instr->src_operand)); + instr->src_operand.read = 1; + instr->dst_operand.write = 1; + instr->num_operands = 2; break; } @@ -360,6 +390,9 @@ static int parse_operands(struct guest_info * core, uint8_t * instr_ptr, instr->dst_operand.size = operand_width; instr->dst_operand.operand = get_addr_linear(core, MASK(core->vm_regs.rdi, addr_width), &(core->segments.es)); + instr->src_operand.read = 1; + instr->dst_operand.write = 1; + instr->num_operands = 2; break; @@ -367,11 +400,7 @@ static int parse_operands(struct guest_info * core, uint8_t * instr_ptr, case INVLPG: { uint8_t reg_code = 0; - // We use the dst operand here to maintain bug-for-bug compatibility with XED - - instr->dst_operand.size = operand_width; - - ret = decode_rm_operand(core, instr_ptr, instr, &(instr->dst_operand), ®_code); + ret = decode_rm_operand(core, instr_ptr, form, instr, &(instr->dst_operand), ®_code); if (ret == -1) { PrintError("Error decoding operand for (%s)\n", op_form_to_str(form));