[PATCH 30/33] KVM: PPC: Add rlwimi instruction emulation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch adds emulation support for the rlwimi instruction.

Signed-off-by: Alexander Graf <agraf@xxxxxxx>
---
 arch/powerpc/include/asm/ppc-opcode.h |  1 +
 arch/powerpc/kvm/emulate.c            | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/arch/powerpc/include/asm/ppc-opcode.h b/arch/powerpc/include/asm/ppc-opcode.h
index 1e80fd2..569b518 100644
--- a/arch/powerpc/include/asm/ppc-opcode.h
+++ b/arch/powerpc/include/asm/ppc-opcode.h
@@ -119,6 +119,7 @@
 #define OP_CMPI 11
 #define OP_ADDIS 15
 #define OP_BC   16
+#define OP_RLWIMI 20
 #define OP_ORI  24
 #define OP_ORIS 25
 #define OP_ANDI 28
diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c
index 47b1de8..c40f255 100644
--- a/arch/powerpc/kvm/emulate.c
+++ b/arch/powerpc/kvm/emulate.c
@@ -601,6 +601,37 @@ int kvmppc_emulate_rld(struct kvm_vcpu *vcpu, u32 inst)
 	return EMULATE_DONE;
 }
 
+int kvmppc_emulate_rlwimi(struct kvm_vcpu *vcpu, u32 inst)
+{
+	int sh = (inst >> 11) & 0x1f;
+	int mb = (inst >> 6) & 0x1f;
+	int me = (inst >> 1) & 0x1f;
+	u32 source = kvmppc_get_gpr(vcpu, get_rs(inst));
+	u32 dest = source;
+	u32 mask;
+
+	if (sh)
+		dest = (source << sh) | (source >> (32 - sh));
+
+	if (!mb)
+		mask = (u32)-1 << (31 - me);
+	else if (me == 31)
+		mask = (u32)-1 >> mb;
+	else {
+		mask = ((u32)-1 >> mb) ^ (((u32)-1 >> me) >> 1);
+		if (mb > me)
+			mask = ~mask;
+	}
+	dest &= mask;
+	dest |= kvmppc_get_gpr(vcpu, get_ra(inst)) & ~mask;
+
+	kvmppc_set_gpr(vcpu, get_ra(inst), dest);
+	if (get_rc(inst))
+		kvmppc_emulate_cmp(vcpu, dest, 0, true, 0, true);
+
+	return EMULATE_DONE;
+}
+
 /* Emulates privileged and non-privileged instructions */
 int kvmppc_emulate_any_instruction(struct kvm_vcpu *vcpu)
 {
@@ -675,6 +706,9 @@ int kvmppc_emulate_any_instruction(struct kvm_vcpu *vcpu)
 	case OP_RLD:
 		emulated = kvmppc_emulate_rld(vcpu, inst);
 		break;
+	case OP_RLWIMI:
+		emulated = kvmppc_emulate_rlwimi(vcpu, inst);
+		break;
 	case 31:
 		switch (get_xop(inst)) {
 		case OP_31_XOP_MFCR:
-- 
1.8.1.4

--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [KVM Development]     [KVM ARM]     [KVM ia64]     [Linux Virtualization]     [Linux USB Devel]     [Linux Video]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux