From: Rusty Russell <rusty.russell@xxxxxxxxxx> Now we put instr inside struct arm_insn, we don't need to hand it internally. Signed-off-by: Rusty Russell <rusty.russell@xxxxxxxxxx> --- arch/arm/kvm/emulate.c | 100 ++++++++++++++++++++++-------------------------- 1 file changed, 45 insertions(+), 55 deletions(-) diff --git a/arch/arm/kvm/emulate.c b/arch/arm/kvm/emulate.c index a6af2a5..d619ad8 100644 --- a/arch/arm/kvm/emulate.c +++ b/arch/arm/kvm/emulate.c @@ -318,8 +318,7 @@ struct arm_decode { u32 opc; u32 opc_mask; - bool (*decode)(struct kvm_vcpu *vcpu, - unsigned long instr, struct arm_insn *ai); + bool (*decode)(struct kvm_vcpu *vcpu, struct arm_insn *ai); struct arm_insn template; }; @@ -388,16 +387,15 @@ u32 shift(u32 value, u8 N, enum SRType type, u8 amount, bool carry_in) return value & mask; } -static bool decode_arm_wb(struct kvm_vcpu *vcpu, unsigned long instr, - struct arm_insn *ai) +static bool decode_arm_wb(struct kvm_vcpu *vcpu, struct arm_insn *ai) { u32 base_addr, offset; - ai->Rt = (instr >> 12) & 0xf; - ai->Rn = (instr >> 16) & 0xf; - ai->W = (instr >> 21) & 1; - ai->U = (instr >> 23) & 1; - ai->P = (instr >> 24) & 1; + ai->Rt = (ai->instr >> 12) & 0xf; + ai->Rn = (ai->instr >> 16) & 0xf; + ai->W = (ai->instr >> 21) & 1; + ai->U = (ai->instr >> 23) & 1; + ai->P = (ai->instr >> 24) & 1; base_addr = *vcpu_reg(vcpu, ai->Rn); @@ -428,30 +426,28 @@ static bool decode_arm_wb(struct kvm_vcpu *vcpu, unsigned long instr, return true; } -static bool decode_arm_ls(struct kvm_vcpu *vcpu, - unsigned long instr, struct arm_insn *ai) +static bool decode_arm_ls(struct kvm_vcpu *vcpu, struct arm_insn *ai) { - u8 A = (instr >> 25) & 1; + u8 A = (ai->instr >> 25) & 1; ai->register_form = A; - ai->imm = instr & 0xfff; - ai->Rm = instr & 0xf; - ai->type = (instr >> 5) & 0x3; - ai->shift_n = (instr >> 7) & 0x1f; + ai->imm = ai->instr & 0xfff; + ai->Rm = ai->instr & 0xf; + ai->type = (ai->instr >> 5) & 0x3; + ai->shift_n = (ai->instr >> 7) & 0x1f; - return decode_arm_wb(vcpu, instr, ai); + return decode_arm_wb(vcpu, ai); } -static bool decode_arm_extra(struct kvm_vcpu *vcpu, - unsigned long instr, struct arm_insn *ai) +static bool decode_arm_extra(struct kvm_vcpu *vcpu, struct arm_insn *ai) { - ai->register_form = !((instr >> 22) & 1); - ai->imm = ((instr >> 4) & 0xf0) | (instr & 0xf); - ai->Rm = instr & 0xf; + ai->register_form = !((ai->instr >> 22) & 1); + ai->imm = ((ai->instr >> 4) & 0xf0) | (ai->instr & 0xf); + ai->Rm = ai->instr & 0xf; ai->type = 0; /* SRType_LSL */ ai->shift_n = 0; - return decode_arm_wb(vcpu, instr, ai); + return decode_arm_wb(vcpu, ai); } /* @@ -531,18 +527,17 @@ static const struct arm_decode arm_decode[] = { .template = { .len = 2, .w = false, .sign_extend = true, }, }, }; -static bool kvm_decode_arm_ls(struct kvm_vcpu *vcpu, - unsigned long instr, struct arm_insn *ai) +static bool kvm_decode_arm_ls(struct kvm_vcpu *vcpu, struct arm_insn *ai) { int i; for (i = 0; i < ARRAY_SIZE(arm_decode); i++) { const struct arm_decode *d = &arm_decode[i]; - if ((instr & d->opc_mask) == d->opc) { + if ((ai->instr & d->opc_mask) == d->opc) { ai->len = d->template.len; ai->w = d->template.w; ai->sign_extend = d->template.sign_extend; - return d->decode(vcpu, instr, ai); + return d->decode(vcpu, ai); } } return false; @@ -564,20 +559,18 @@ struct thumb_decode { } t32; }; - bool (*decode)(struct kvm_vcpu *vcpu, - unsigned long instr, struct arm_insn *ti); + bool (*decode)(struct kvm_vcpu *vcpu, struct arm_insn *ti); }; -static bool decode_thumb_wb(struct kvm_vcpu *vcpu, - unsigned long instr, struct arm_insn *ti) +static bool decode_thumb_wb(struct kvm_vcpu *vcpu, struct arm_insn *ti) { - u8 imm8 = instr & 0xff; + u8 imm8 = ti->instr & 0xff; u32 offset_addr = vcpu->arch.hxfar; - ti->P = (instr >> 10) & 1; - ti->U = (instr >> 9) & 1; - ti->Rn = (instr >> 16) & 0xf; - ti->Rd = (instr >> 12) & 0xf; + ti->P = (ti->instr >> 10) & 1; + ti->U = (ti->instr >> 9) & 1; + ti->Rn = (ti->instr >> 16) & 0xf; + ti->Rd = (ti->instr >> 12) & 0xf; /* Handle Writeback */ if (!ti->P && ti->U) @@ -587,11 +580,10 @@ static bool decode_thumb_wb(struct kvm_vcpu *vcpu, return true; } -static bool decode_thumb_str(struct kvm_vcpu *vcpu, - unsigned long instr, struct arm_insn *ti) +static bool decode_thumb_str(struct kvm_vcpu *vcpu, struct arm_insn *ti) { - u8 op1 = (instr >> (16 + 5)) & 0x7; - u8 op2 = (instr >> 6) & 0x3f; + u8 op1 = (ti->instr >> (16 + 5)) & 0x7; + u8 op2 = (ti->instr >> 6) & 0x3f; ti->W = true; ti->sign_extend = false; @@ -606,17 +598,16 @@ static bool decode_thumb_str(struct kvm_vcpu *vcpu, if ((op2 & 0x24) == 0x24) { /* STRB (immediate, thumb, W=1) */ - return decode_thumb_wb(vcpu, instr, ti); + return decode_thumb_wb(vcpu, ti); } return false; } -static bool decode_thumb_ldr(struct kvm_vcpu *vcpu, - unsigned long instr, struct arm_insn *ti) +static bool decode_thumb_ldr(struct kvm_vcpu *vcpu, struct arm_insn *ti) { - u8 op1 = (instr >> (16 + 7)) & 0x3; - u8 op2 = (instr >> 6) & 0x3f; + u8 op1 = (ti->instr >> (16 + 7)) & 0x3; + u8 op2 = (ti->instr >> 6) & 0x3f; ti->W = false; @@ -635,7 +626,7 @@ static bool decode_thumb_ldr(struct kvm_vcpu *vcpu, if ((op2 & 0x24) == 0x24) { /* LDR{S}X (immediate, thumb, W=1) */ - return decode_thumb_wb(vcpu, instr, ti); + return decode_thumb_wb(vcpu, ti); } return false; @@ -666,21 +657,20 @@ static const struct thumb_decode thumb_decode[] = { }; -static bool kvm_decode_thumb_ls(struct kvm_vcpu *vcpu, - unsigned long instr, struct arm_insn *ti) +static bool kvm_decode_thumb_ls(struct kvm_vcpu *vcpu, struct arm_insn *ti) { bool is16; int i; ti->is_thumb = true; - ti->is_thumb32 = is_wide_instruction(instr); + ti->is_thumb32 = is_wide_instruction(ti->instr); is16 = !ti->is_thumb32; if (is16) { - ti->t16.opcode = (instr >> 10) & 0x3f; + ti->t16.opcode = (ti->instr >> 10) & 0x3f; } else { - ti->t32.op1 = (instr >> (16 + 11)) & 0x3; - ti->t32.op2 = (instr >> (16 + 4)) & 0x7f; + ti->t32.op1 = (ti->instr >> (16 + 11)) & 0x3; + ti->t32.op2 = (ti->instr >> (16 + 4)) & 0x7f; } for (i = 0; i < ARRAY_SIZE(thumb_decode); i++) { @@ -698,7 +688,7 @@ static bool kvm_decode_thumb_ls(struct kvm_vcpu *vcpu, continue; } - return td->decode(vcpu, instr, ti); + return td->decode(vcpu, ti); } return false; @@ -733,9 +723,9 @@ static int kvm_decode(struct kvm_vcpu *vcpu, unsigned long pc, u32 psr, return err; } - if (!is_thumb && !kvm_decode_arm_ls(vcpu, ai->instr, ai)) + if (!is_thumb && !kvm_decode_arm_ls(vcpu, ai)) return -ENOENT; - else if (is_thumb && !kvm_decode_thumb_ls(vcpu, ai->instr, ai)) + else if (is_thumb && !kvm_decode_thumb_ls(vcpu, ai)) return -ENOENT; return 0; -- 1.7.10.4 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html