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.


updates to enable functionality necessary for SEABIOS to run
[palacios.git] / palacios / include / palacios / vmm_instr_decoder.h
index 53831c4..a7c63fb 100644 (file)
@@ -151,7 +151,7 @@ static int get_addr_width(struct guest_info * info, struct x86_instr * instr) {
                        return (instr->prefixes.addr_size) ? 4 : 2;
                }                       
        default:
-           PrintError("Unsupported CPU mode: %d\n", info->cpu_mode);
+           PrintError(info->vm_info, info, "Unsupported CPU mode: %d\n", info->cpu_mode);
            return -1;
     }
 }
@@ -276,13 +276,13 @@ static int get_operand_width(struct guest_info * info, struct x86_instr * instr,
                        return (instr->prefixes.op_size) ? 4 : 2;
                    }
                default:
-                   PrintError("Unsupported CPU mode: %d\n", info->cpu_mode);
+                   PrintError(info->vm_info, info, "Unsupported CPU mode: %d\n", info->cpu_mode);
                    return -1;
            }
        case INVLPG:
            switch (v3_get_vm_cpu_mode(info)) {
                case REAL:
-                   PrintError("Invalid instruction given operating mode (%d)\n", form);
+                   PrintError(info->vm_info, info, "Invalid instruction given operating mode (%d)\n", form);
                    return 0;
                case PROTECTED:
                case PROTECTED_PAE:
@@ -291,7 +291,7 @@ static int get_operand_width(struct guest_info * info, struct x86_instr * instr,
                case LONG:
                        return 8;
                default:
-                   PrintError("Unsupported CPU mode: %d\n", info->cpu_mode);
+                   PrintError(info->vm_info, info, "Unsupported CPU mode: %d\n", info->cpu_mode);
                    return -1;
            }
 
@@ -307,7 +307,7 @@ static int get_operand_width(struct guest_info * info, struct x86_instr * instr,
                case LONG:
                        return 8;
                default:
-                   PrintError("Unsupported CPU mode: %d\n", info->cpu_mode);
+                   PrintError(info->vm_info, info, "Unsupported CPU mode: %d\n", info->cpu_mode);
                    return -1;
            }
 
@@ -326,14 +326,14 @@ static int get_operand_width(struct guest_info * info, struct x86_instr * instr,
                case LONG:
                        return 8;
                default:
-                   PrintError("Unsupported CPU mode: %d\n", info->cpu_mode);
+                   PrintError(info->vm_info, info, "Unsupported CPU mode: %d\n", info->cpu_mode);
                    return -1;
            }
 
        case MOV_SR2:
        case MOV_2SR:
        default:
-           PrintError("Unsupported instruction form %d\n", form);
+           PrintError(info->vm_info, info, "Unsupported instruction form %d\n", form);
            return -1;
        
     }
@@ -437,7 +437,7 @@ static inline int decode_gpr(struct guest_info * core,
            reg->operand = (addr_t)&(gprs->r15);
            break;
        default:
-           PrintError("Invalid Reg Code (%d)\n", reg_code);
+           PrintError(core->vm_info, core, "Invalid Reg Code (%d)\n", reg_code);
            reg->operand = 0;
            return -1;
     }
@@ -454,7 +454,7 @@ static inline int decode_cr(struct guest_info * core,
 
     struct v3_ctrl_regs * crs = &(core->ctrl_regs);
 
-//    PrintDebug("\t Ctrl regs %d\n", reg_code);
+//    PrintDebug(core->vm_info, core, "\t Ctrl regs %d\n", reg_code);
 
     switch (reg_code) {
        case 0:
@@ -471,13 +471,31 @@ static inline int decode_cr(struct guest_info * core,
            break;
        default:
            reg->operand = 0;
-           PrintError("Invalid Reg Code (%d)\n", reg_code);
+           PrintError(core->vm_info, core, "Invalid Reg Code (%d)\n", reg_code);
            return -1;
     }
 
     return 0;
 }
 
+static struct v3_segment * get_instr_segment(struct guest_info * core, struct x86_instr * instr) {
+    struct v3_segment * seg = &(core->segments.ds);
+
+    if (instr->prefixes.cs_override) {
+       seg = &(core->segments.cs);
+    } else if (instr->prefixes.es_override) {
+       seg = &(core->segments.es);
+    } else if (instr->prefixes.ss_override) {
+       seg = &(core->segments.ss);
+    } else if (instr->prefixes.fs_override) {
+       seg = &(core->segments.fs);
+    } else if (instr->prefixes.gs_override) {
+       seg = &(core->segments.gs);
+    } 
+
+    return seg;
+}
+
 
 
 #define ADDR_MASK(val, length) ({                            \
@@ -510,14 +528,14 @@ static  int decode_rm_operand16(struct guest_info * core,
     modrm_mode_t mod_mode = 0;
     uint8_t * instr_cursor = modrm_instr;
 
-    //  PrintDebug("ModRM mod=%d\n", modrm->mod);
+    //  PrintDebug(core->vm_info, core, "ModRM mod=%d\n", modrm->mod);
     
     *reg_code = modrm->reg;
 
     instr_cursor += 1;
 
     if (modrm->mod == 3) {
-       //PrintDebug("first operand = Register (RM=%d)\n",modrm->rm);
+       //PrintDebug(core->vm_info, core, "first operand = Register (RM=%d)\n",modrm->rm);
        operand->type = REG_OPERAND;
 
        decode_gpr(core, modrm->rm, operand);
@@ -534,7 +552,7 @@ static  int decode_rm_operand16(struct guest_info * core,
        } else if (modrm->mod == 2) {
            mod_mode = DISP16;
        } else {
-           PrintError("Instruction format error: Invalid mod_rm mode (%d)\n", modrm->mod);
+           PrintError(core->vm_info, core, "Instruction format error: Invalid mod_rm mode (%d)\n", modrm->mod);
            v3_print_instr(instr);
            return -1;
        }
@@ -627,7 +645,7 @@ static int decode_rm_operand32(struct guest_info * core,
 
     if (modrm->mod == 3) {
        operand->type = REG_OPERAND;
-       //    PrintDebug("first operand = Register (RM=%d)\n",modrm->rm);
+       //    PrintDebug(core->vm_info, core, "first operand = Register (RM=%d)\n",modrm->rm);
 
        decode_gpr(core, modrm->rm, operand);
 
@@ -643,7 +661,7 @@ static int decode_rm_operand32(struct guest_info * core,
        } else if (modrm->mod == 2) {
            mod_mode = DISP32;
        } else {
-           PrintError("Instruction format error: Invalid mod_rm mode (%d)\n", modrm->mod);
+           PrintError(core->vm_info, core, "Instruction format error: Invalid mod_rm mode (%d)\n", modrm->mod);
            v3_print_instr(instr);
            return -1;
        }
@@ -681,7 +699,6 @@ static int decode_rm_operand32(struct guest_info * core,
        }
 
        if (has_sib_byte) {
-           instr_cursor += 1;
            struct sib_byte * sib = (struct sib_byte *)(instr_cursor);
            int scale = 0x1 << sib->scale;
 
@@ -736,6 +753,9 @@ static int decode_rm_operand32(struct guest_info * core,
                case 5:
                    if (modrm->mod != 0) {
                        base_addr += ADDR_MASK(gprs->rbp, 4);
+                   } else {
+                       mod_mode = DISP32;
+                       base_addr = 0;
                    }
                    break;
                case 6:
@@ -804,7 +824,7 @@ int decode_rm_operand64(struct guest_info * core, uint8_t * modrm_instr,
        rm_val |= (instr->prefixes.rex_rm << 3);
        
        operand->type = REG_OPERAND;
-       //    PrintDebug("first operand = Register (RM=%d)\n",modrm->rm);
+       //    PrintDebug(core->vm_info, core, "first operand = Register (RM=%d)\n",modrm->rm);
        
        decode_gpr(core, rm_val, operand);
     } else {
@@ -821,7 +841,7 @@ int decode_rm_operand64(struct guest_info * core, uint8_t * modrm_instr,
        } else if (modrm->mod == 2) {
            mod_mode = DISP32;
        } else {
-           PrintError("Instruction format error: Invalid mod_rm mode (%d)\n", modrm->mod);
+           PrintError(core->vm_info, core, "Instruction format error: Invalid mod_rm mode (%d)\n", modrm->mod);
            v3_print_instr(instr);
            return -1;
        }
@@ -888,7 +908,6 @@ int decode_rm_operand64(struct guest_info * core, uint8_t * modrm_instr,
        }
 
        if (has_sib_byte) {
-           instr_cursor += 1;
            struct sib_byte * sib = (struct sib_byte *)(instr_cursor);
            int scale = 0x1 << sib->scale;
            uint8_t index_val = sib->index;
@@ -972,6 +991,9 @@ int decode_rm_operand64(struct guest_info * core, uint8_t * modrm_instr,
                case 5:
                    if (modrm->mod != 0) {
                        base_addr += gprs->rbp;
+                   } else {
+                       mod_mode = DISP32;
+                       base_addr = 0;
                    }
                    break;
                case 6:
@@ -1071,7 +1093,7 @@ static int decode_rm_operand(struct guest_info * core,
        case LONG_32_COMPAT:
            return decode_rm_operand32(core, instr_ptr, instr, operand, reg_code);
        default:
-           PrintError("Invalid CPU_MODE (%d)\n", mode);
+           PrintError(core->vm_info, core, "Invalid CPU_MODE (%d)\n", mode);
            return -1;
     }
 }