Skip to contentSkip to conversation

Extract instruction emulate codes for

PATCH In review Zhang Wei 1 participant 1 message Jan 25, 2008

Subsystems (2)
lore
Share & tools
lore

Zhang Wei

author
#0 lore raw

PATCH 5/5 Extract instruction emulate codes for

Some instruction emulation need implemented for individual processor. I extract general code from emulate.c to header file inst.h. A new header 44x_inst.h is created for special 44x emulation functions.

---
 arch/powerpc/kvm/44x_inst.h |  192 +++++++++++++++++++++++++++++++++
 arch/powerpc/kvm/emulate.c  |  245 +------------------------------------------
 arch/powerpc/kvm/inst.h     |  132 +++++++++++++++++++++++
 3 files changed, 329 insertions(+), 240 deletions(-)
 create mode 100644 arch/powerpc/kvm/44x_inst.h
 create mode 100644 arch/powerpc/kvm/inst.h
arch/powerpc/kvm/44x_inst.h new file +192 -0
new file mode 100644
index 0000000..7529618
@@ -0,0 +1,192 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Copyright IBM Corp. 2007
+ *
+ * Authors: Hollis Blanchard <[email protected]>
+ *
+ * Functions of the file are extrcated from emulate.c.
+ * The file only includes special implementation for PowerPC 44x.
+ *
+ * Copyright (C) 2008 Freescale Semiconductor.
+ *
+ * Zhang Wei <[email protected]>
+ */
+
+#ifndef __ARCH_POWERPC_KVM_44X_INST_H__
+#define __ARCH_POWERPC_KVM_44X_INST_H__
+
+#define DCRN_CPR0_CFGADDR	0xc
+#define DCRN_CPR0_CFGDATA	0xd
+
+static int emul_tlbwe(struct kvm_vcpu *vcpu, u32 inst)
+{
+	u64 eaddr;
+	u64 raddr;
+	u64 asid;
+	u32 flags;
+	struct tlbe *tlbe;
+	unsigned int ra;
+	unsigned int rs;
+	unsigned int ws;
+	unsigned int index;
+
+	ra = get_ra(inst);
+	rs = get_rs(inst);
+	ws = get_ws(inst);
+
+	index = vcpu->arch.gpr[ra];
+	if (index > PPC44x_TLB_SIZE) {
+		printk("%s: index %d\n", __func__, index);
+		kvmppc_dump_vcpu(vcpu);
+		return EMULATE_FAIL;
+	}
+
+	tlbe = &vcpu->arch.guest_tlb[index];
+
+	/* Invalidate shadow mappings for the about-to-be-clobbered TLBE. */
+	if (tlbe->word0 & PPC44x_TLB_VALID) {
+		eaddr = get_tlb_eaddr(tlbe);
+		asid = (tlbe->word0 & PPC44x_TLB_TS) | tlbe->tid;
+		kvmppc_mmu_invalidate(vcpu, eaddr, asid);
+	}
+
+	switch (ws) {
+	case PPC44x_TLB_PAGEID:
+		tlbe->tid = vcpu->arch.mmucr & 0xff;
+		tlbe->word0 = vcpu->arch.gpr[rs];
+		break;
+
+	case PPC44x_TLB_XLAT:
+		tlbe->word1 = vcpu->arch.gpr[rs];
+		break;
+
+	case PPC44x_TLB_ATTRIB:
+		tlbe->word2 = vcpu->arch.gpr[rs];
+		break;
+
+	default:
+		return EMULATE_FAIL;
+	}
+
+#if 0
+	printk("gtlbe %02d: %08x %08x %08x %08x\n", index,
+	       tlbe->tid, tlbe->word0, tlbe->word1, tlbe->word2);
+#endif
+
+	if (tlbe_is_host_safe(vcpu, tlbe)) {
+		eaddr = get_tlb_eaddr(tlbe);
+		raddr = get_tlb_raddr(tlbe);
+		asid = (tlbe->word0 & PPC44x_TLB_TS) | tlbe->tid;
+		flags = tlbe->word2 & 0xffff;
+
+		/* Create a 4KB mapping on the host. If the guest wanted a
+		 * large page, only the first 4KB is mapped here and the rest
+		 * are mapped on the fly. */
+		kvmppc_mmu_map(vcpu, eaddr, raddr >> PAGE_SHIFT, asid, flags);
+	}
+
+	return EMULATE_DONE;
+}
+
+static int emul_mtdcr(struct kvm_vcpu *vcpu, u32 inst)
+{
+	struct kvm_run *run = vcpu->run;
+	int dcrn;
+	int rs;
+
+	dcrn = get_dcrn(inst);
+	rs = get_rs(inst);
+
+	/* emulate some access in kernel */
+	switch (dcrn) {
+	case DCRN_CPR0_CFGADDR:
+		vcpu->arch.cpr0_cfgaddr = vcpu->arch.gpr[rs];
+		break;
+	default:
+		run->dcr.dcrn = dcrn;
+		run->dcr.data = vcpu->arch.gpr[rs];
+		run->dcr.is_write = 1;
+		vcpu->arch.dcr_needed = 1;
+		return EMULATE_DO_DCR;
+	}
+
+	return EMULATE_DONE;
+}
+
+static int emul_mfdcr(struct kvm_vcpu *vcpu, u32 inst)
+{
+	struct kvm_run *run = vcpu->run;
+	int dcrn;
+	int rt;
+
+	dcrn = get_dcrn(inst);
+	rt = get_rt(inst);
+
+	/* emulate some access in kernel */
+	switch (dcrn) {
+	case DCRN_CPR0_CFGADDR:
+		vcpu->arch.gpr[rt] = vcpu->arch.cpr0_cfgaddr;
+		break;
+	case DCRN_CPR0_CFGDATA:
+		local_irq_disable();
+		mtdcr(DCRN_CPR0_CFGADDR,
+		      vcpu->arch.cpr0_cfgaddr);
+		vcpu->arch.gpr[rt] = mfdcr(DCRN_CPR0_CFGDATA);
+		local_irq_enable();
+		break;
+	default:
+		run->dcr.dcrn = dcrn;
+		run->dcr.data =  0;
+		run->dcr.is_write = 0;
+		vcpu->arch.io_gpr = rt;
+		vcpu->arch.dcr_needed = 1;
+		return EMULATE_DO_DCR;
+	}
+
+	return EMULATE_DONE;
+}
+
+static int emul_tlbsx(struct kvm_vcpu *vcpu, u32 inst)
+{
+	int index;
+	unsigned int as = get_mmucr_sts(vcpu);
+	unsigned int pid = get_mmucr_stid(vcpu);
+	unsigned int ra;
+	unsigned int rb;
+	unsigned int rc;
+	unsigned int rt;
+	unsigned int ea;
+
+	rt = get_rt(inst);
+	ra = get_ra(inst);
+	rb = get_rb(inst);
+	rc = get_rc(inst);
+
+	ea = vcpu->arch.gpr[rb];
+	if (ra)
+		ea += vcpu->arch.gpr[ra];
+
+	index = kvmppc_tlb_index(vcpu, ea, pid, as);
+	if (rc) {
+		if (index < 0)
+			vcpu->arch.cr &= ~0x20000000;
+		else
+			vcpu->arch.cr |= 0x20000000;
+	}
+	vcpu->arch.gpr[rt] = index;
+
+	return EMULATE_DONE;
+}
+#endif /* __ARCH_POWERPC_KVM_44X_INST_H__ */
arch/powerpc/kvm/emulate.c +5 -240

281 lines not on this page · raw message

arch/powerpc/kvm/inst.h new file +132 -0

132 lines not on this page · raw message

Signature · 11 lines
1.5.2


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
kvm-ppc-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-ppc-devel