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
[palacios.git] / palacios / include / palacios / vmm_instr_decoder.h
index 1c292a3..2e650e7 100644 (file)
@@ -140,11 +140,16 @@ static int get_addr_width(struct guest_info * info, struct x86_instr * instr) {
     switch (v3_get_vm_cpu_mode(info)) {
        case REAL:
            return (instr->prefixes.addr_size) ? 4 : 2;
+       case LONG:
+               return 8;
        case PROTECTED:
        case PROTECTED_PAE:
-           return (instr->prefixes.addr_size) ? 2 : 4;
        case LONG_32_COMPAT:
-       case LONG:
+               if (info->segments.cs.db) {
+                       return (instr->prefixes.addr_size) ? 2 : 4;
+               } else {
+                       return (instr->prefixes.addr_size) ? 4 : 2;
+               }                       
        default:
            PrintError("Unsupported CPU mode: %d\n", info->cpu_mode);
            return -1;
@@ -254,16 +259,24 @@ static int get_operand_width(struct guest_info * info, struct x86_instr * instr,
            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;
+                   }
                case PROTECTED:
                case PROTECTED_PAE:
-                   return (instr->prefixes.op_size) ? 2 : 4;
                case LONG_32_COMPAT:
-               case LONG:
+                   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:
@@ -271,9 +284,10 @@ static int get_operand_width(struct guest_info * info, struct x86_instr * instr,
                    return 0;
                case PROTECTED:
                case PROTECTED_PAE:
-                   return 4;
                case LONG_32_COMPAT:
+                       return 4;
                case LONG:
+                       return 8;
                default:
                    PrintError("Unsupported CPU mode: %d\n", info->cpu_mode);
                    return -1;
@@ -286,9 +300,10 @@ static int get_operand_width(struct guest_info * info, struct x86_instr * instr,
                    return 2;
                case PROTECTED:
                case PROTECTED_PAE:
-                   return 4;
                case LONG_32_COMPAT:
+                       return 4;
                case LONG:
+                       return 8;
                default:
                    PrintError("Unsupported CPU mode: %d\n", info->cpu_mode);
                    return -1;
@@ -302,9 +317,11 @@ static int get_operand_width(struct guest_info * info, struct x86_instr * instr,
                case REAL:
                case PROTECTED:
                case PROTECTED_PAE:
-                   return 4;
                case LONG_32_COMPAT:
+
+                       return 4;
                case LONG:
+                       return 8;
                default:
                    PrintError("Unsupported CPU mode: %d\n", info->cpu_mode);
                    return -1;
@@ -746,24 +763,41 @@ 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) {
+    
+    
+                                       
+    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)) {
-       return decode_rm_operand32(core, instr_ptr, instr, operand, reg_code);
-    } else {
-       PrintError("Invalid CPU_MODE (%d)\n", mode);
-       return -1;
+    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);
+           }
+       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;
     }
 }