Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Merge branch 'devel' of palacios@newskysaw.cs.northwestern.edu:/home/palacios/palacio...
[palacios-OLD.git] / palacios / src / palacios / vmm_v3dec.c
index dd0abd9..c1df822 100644 (file)
 #include <palacios/vmm_decoder.h>
 #include <palacios/vmm_instr_decoder.h>
 
+#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;
        }
     }
@@ -157,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) {
@@ -168,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;
@@ -202,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;
@@ -236,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;
@@ -248,7 +272,8 @@ static int parse_operands(struct guest_info * core, uint8_t * instr_ptr,
        case XOR_IMM2SX_8: {
            uint8_t reg_code = 0;
 
-           ret = decode_rm_operand(core, instr_ptr, form, instr, &(instr->src_operand), &reg_code);
+           ret = decode_rm_operand(core, instr_ptr, form, instr, &(instr->dst_operand), &reg_code);
+
 
            if (ret == -1) {
                PrintError("Error decoding operand\n");
@@ -261,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;
@@ -284,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;
@@ -309,6 +342,9 @@ 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;
            }
@@ -318,6 +354,7 @@ static int parse_operands(struct guest_info * core, uint8_t * instr_ptr,
                ret = decode_rm_operand(core, instr_ptr, form, instr, &(instr->dst_operand),
                                        &reg_code);
 
+
                if (ret == -1) {
                    PrintError("Error decoding operand for (%s)\n", op_form_to_str(form));
                    return -1;
@@ -329,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;
            }
@@ -350,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;
@@ -357,8 +400,6 @@ 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
-
                ret = decode_rm_operand(core, instr_ptr, form, instr, &(instr->dst_operand), &reg_code);
 
                if (ret == -1) {