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.


added checks for 64 bit operand decoding
Jack Lange [Tue, 15 Mar 2011 22:11:47 +0000 (17:11 -0500)]
palacios/include/palacios/vmm_instr_decoder.h
palacios/src/palacios/vmm_v3dec.c

index aa106b6..2e650e7 100644 (file)
@@ -256,27 +256,27 @@ static int get_operand_width(struct guest_info * info, struct x86_instr * instr,
        case OR_IMM2SX_8:
        case SUB_IMM2SX_8:
        case XOR_IMM2SX_8:
-       switch (v3_get_vm_cpu_mode(info)) {
+           switch (v3_get_vm_cpu_mode(info)) {
                case REAL:
                    return (instr->prefixes.op_size) ? 4 : 2;
                case LONG:
-                       if (instr->prefixes.rex.op_size) {
-                               return 8;
-                       }
+                   if (instr->prefixes.rex.op_size) {
+                       return 8;
+                   }
                case PROTECTED:
                case PROTECTED_PAE:
                case LONG_32_COMPAT:
-                       if (info->segments.cs.db) {
-                               // default is 32
-                               return (instr->prefixes.op_size) ? 2 : 4;
-                       } else {
-                               return (instr->prefixes.op_size) ? 4 : 2;
-                       }
+                   if (info->segments.cs.db) {
+                       // default is 32
+                       return (instr->prefixes.op_size) ? 2 : 4;
+                   } else {
+                       return (instr->prefixes.op_size) ? 4 : 2;
+                   }
                default:
                    PrintError("Unsupported CPU mode: %d\n", info->cpu_mode);
                    return -1;
            }
-
+           
        case INVLPG:
            switch (v3_get_vm_cpu_mode(info)) {
                case REAL:
@@ -285,7 +285,6 @@ static int get_operand_width(struct guest_info * info, struct x86_instr * instr,
                case PROTECTED:
                case PROTECTED_PAE:
                case LONG_32_COMPAT:
-
                        return 4;
                case LONG:
                        return 8;
@@ -765,31 +764,40 @@ static int decode_rm_operand32(struct guest_info * core,
 
 
 int decode_rm_operand64(struct guest_info * core, uint8_t * instr_ptr, 
-                                       struct x86_instr * instr, struct x86_operand * operand, 
-                                       uint8_t * reg_code) {
-                                       
+                       struct x86_instr * instr, struct x86_operand * operand, 
+                       uint8_t * reg_code) {
+    
+    
                                        
-       return 0;
+    return 0;
 }
 
 
 static int decode_rm_operand(struct guest_info * core, 
                             uint8_t * instr_ptr,        // input
+                            op_form_t form, 
                             struct x86_instr * instr,
                             struct x86_operand * operand, 
                             uint8_t * reg_code) {
     
     v3_cpu_mode_t mode = v3_get_vm_cpu_mode(core);
 
-    if (mode == REAL) {
-       return decode_rm_operand16(core, instr_ptr, instr, operand, reg_code);
-    } else if ((mode == PROTECTED) || (mode == PROTECTED_PAE) || (mode == LONG_32_COMPAT)) {
-       return decode_rm_operand32(core, instr_ptr, instr, operand, reg_code);
-       } else if (mode == LONG) {
+    operand->size = get_operand_width(core, instr, form);
+
+    switch (mode) {
+       case REAL:
+           return decode_rm_operand16(core, instr_ptr, instr, operand, reg_code);
+       case LONG:
+           if (instr->prefixes.rex.op_size) {
                return decode_rm_operand64(core, instr_ptr, instr, operand, reg_code);
-    } else {
-       PrintError("Invalid CPU_MODE (%d)\n", mode);
-       return -1;
+           }
+       case PROTECTED:
+       case PROTECTED_PAE:
+       case LONG_32_COMPAT:
+           return decode_rm_operand32(core, instr_ptr, instr, operand, reg_code);
+       default:
+           PrintError("Invalid CPU_MODE (%d)\n", mode);
+           return -1;
     }
 }
                             
index 0a1aacb..dd0abd9 100644 (file)
@@ -145,9 +145,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), &reg_code);
+           ret = decode_rm_operand(core, instr_ptr, form, instr, &(instr->dst_operand), &reg_code);
 
            if (ret == -1) {
                PrintError("Error decoding operand\n");
@@ -192,9 +190,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), &reg_code);
+           ret = decode_rm_operand(core, instr_ptr, form, instr, &(instr->dst_operand), &reg_code);
 
            if (ret == -1) {
                PrintError("Error decoding operand\n");
@@ -226,9 +222,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), &reg_code);
+           ret = decode_rm_operand(core, instr_ptr, form, instr, &(instr->src_operand), &reg_code);
 
            if (ret == -1) {
                PrintError("Error decoding operand\n");
@@ -252,9 +247,8 @@ 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), &reg_code);
+           ret = decode_rm_operand(core, instr_ptr, form, instr, &(instr->src_operand), &reg_code);
 
            if (ret == -1) {
                PrintError("Error decoding operand\n");
@@ -301,9 +295,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),
                                        &reg_code);
 
                if (ret == -1) {
@@ -323,9 +315,7 @@ static int parse_operands(struct guest_info * core, uint8_t * instr_ptr,
            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),
                                        &reg_code);
 
                if (ret == -1) {
@@ -369,9 +359,7 @@ static int parse_operands(struct guest_info * core, uint8_t * instr_ptr,
 
                // 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), &reg_code);
+               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));