Path: blob/master/arch/powerpc/kvm/booke_emulate.c
10820 views
/*1* This program is free software; you can redistribute it and/or modify2* it under the terms of the GNU General Public License, version 2, as3* published by the Free Software Foundation.4*5* This program is distributed in the hope that it will be useful,6* but WITHOUT ANY WARRANTY; without even the implied warranty of7* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the8* GNU General Public License for more details.9*10* You should have received a copy of the GNU General Public License11* along with this program; if not, write to the Free Software12* Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.13*14* Copyright IBM Corp. 200815*16* Authors: Hollis Blanchard <[email protected]>17*/1819#include <linux/kvm_host.h>20#include <asm/disassemble.h>2122#include "booke.h"2324#define OP_19_XOP_RFI 502526#define OP_31_XOP_MFMSR 8327#define OP_31_XOP_WRTEE 13128#define OP_31_XOP_MTMSR 14629#define OP_31_XOP_WRTEEI 1633031static void kvmppc_emul_rfi(struct kvm_vcpu *vcpu)32{33vcpu->arch.pc = vcpu->arch.shared->srr0;34kvmppc_set_msr(vcpu, vcpu->arch.shared->srr1);35}3637int kvmppc_booke_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,38unsigned int inst, int *advance)39{40int emulated = EMULATE_DONE;41int rs;42int rt;4344switch (get_op(inst)) {45case 19:46switch (get_xop(inst)) {47case OP_19_XOP_RFI:48kvmppc_emul_rfi(vcpu);49kvmppc_set_exit_type(vcpu, EMULATED_RFI_EXITS);50*advance = 0;51break;5253default:54emulated = EMULATE_FAIL;55break;56}57break;5859case 31:60switch (get_xop(inst)) {6162case OP_31_XOP_MFMSR:63rt = get_rt(inst);64kvmppc_set_gpr(vcpu, rt, vcpu->arch.shared->msr);65kvmppc_set_exit_type(vcpu, EMULATED_MFMSR_EXITS);66break;6768case OP_31_XOP_MTMSR:69rs = get_rs(inst);70kvmppc_set_exit_type(vcpu, EMULATED_MTMSR_EXITS);71kvmppc_set_msr(vcpu, kvmppc_get_gpr(vcpu, rs));72break;7374case OP_31_XOP_WRTEE:75rs = get_rs(inst);76vcpu->arch.shared->msr = (vcpu->arch.shared->msr & ~MSR_EE)77| (kvmppc_get_gpr(vcpu, rs) & MSR_EE);78kvmppc_set_exit_type(vcpu, EMULATED_WRTEE_EXITS);79break;8081case OP_31_XOP_WRTEEI:82vcpu->arch.shared->msr = (vcpu->arch.shared->msr & ~MSR_EE)83| (inst & MSR_EE);84kvmppc_set_exit_type(vcpu, EMULATED_WRTEE_EXITS);85break;8687default:88emulated = EMULATE_FAIL;89}9091break;9293default:94emulated = EMULATE_FAIL;95}9697return emulated;98}99100int kvmppc_booke_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs)101{102int emulated = EMULATE_DONE;103ulong spr_val = kvmppc_get_gpr(vcpu, rs);104105switch (sprn) {106case SPRN_DEAR:107vcpu->arch.shared->dar = spr_val; break;108case SPRN_ESR:109vcpu->arch.esr = spr_val; break;110case SPRN_DBCR0:111vcpu->arch.dbcr0 = spr_val; break;112case SPRN_DBCR1:113vcpu->arch.dbcr1 = spr_val; break;114case SPRN_DBSR:115vcpu->arch.dbsr &= ~spr_val; break;116case SPRN_TSR:117vcpu->arch.tsr &= ~spr_val; break;118case SPRN_TCR:119vcpu->arch.tcr = spr_val;120kvmppc_emulate_dec(vcpu);121break;122123/* Note: SPRG4-7 are user-readable. These values are124* loaded into the real SPRGs when resuming the125* guest. */126case SPRN_SPRG4:127vcpu->arch.sprg4 = spr_val; break;128case SPRN_SPRG5:129vcpu->arch.sprg5 = spr_val; break;130case SPRN_SPRG6:131vcpu->arch.sprg6 = spr_val; break;132case SPRN_SPRG7:133vcpu->arch.sprg7 = spr_val; break;134135case SPRN_IVPR:136vcpu->arch.ivpr = spr_val;137break;138case SPRN_IVOR0:139vcpu->arch.ivor[BOOKE_IRQPRIO_CRITICAL] = spr_val;140break;141case SPRN_IVOR1:142vcpu->arch.ivor[BOOKE_IRQPRIO_MACHINE_CHECK] = spr_val;143break;144case SPRN_IVOR2:145vcpu->arch.ivor[BOOKE_IRQPRIO_DATA_STORAGE] = spr_val;146break;147case SPRN_IVOR3:148vcpu->arch.ivor[BOOKE_IRQPRIO_INST_STORAGE] = spr_val;149break;150case SPRN_IVOR4:151vcpu->arch.ivor[BOOKE_IRQPRIO_EXTERNAL] = spr_val;152break;153case SPRN_IVOR5:154vcpu->arch.ivor[BOOKE_IRQPRIO_ALIGNMENT] = spr_val;155break;156case SPRN_IVOR6:157vcpu->arch.ivor[BOOKE_IRQPRIO_PROGRAM] = spr_val;158break;159case SPRN_IVOR7:160vcpu->arch.ivor[BOOKE_IRQPRIO_FP_UNAVAIL] = spr_val;161break;162case SPRN_IVOR8:163vcpu->arch.ivor[BOOKE_IRQPRIO_SYSCALL] = spr_val;164break;165case SPRN_IVOR9:166vcpu->arch.ivor[BOOKE_IRQPRIO_AP_UNAVAIL] = spr_val;167break;168case SPRN_IVOR10:169vcpu->arch.ivor[BOOKE_IRQPRIO_DECREMENTER] = spr_val;170break;171case SPRN_IVOR11:172vcpu->arch.ivor[BOOKE_IRQPRIO_FIT] = spr_val;173break;174case SPRN_IVOR12:175vcpu->arch.ivor[BOOKE_IRQPRIO_WATCHDOG] = spr_val;176break;177case SPRN_IVOR13:178vcpu->arch.ivor[BOOKE_IRQPRIO_DTLB_MISS] = spr_val;179break;180case SPRN_IVOR14:181vcpu->arch.ivor[BOOKE_IRQPRIO_ITLB_MISS] = spr_val;182break;183case SPRN_IVOR15:184vcpu->arch.ivor[BOOKE_IRQPRIO_DEBUG] = spr_val;185break;186187default:188emulated = EMULATE_FAIL;189}190191return emulated;192}193194int kvmppc_booke_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt)195{196int emulated = EMULATE_DONE;197198switch (sprn) {199case SPRN_IVPR:200kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivpr); break;201case SPRN_DEAR:202kvmppc_set_gpr(vcpu, rt, vcpu->arch.shared->dar); break;203case SPRN_ESR:204kvmppc_set_gpr(vcpu, rt, vcpu->arch.esr); break;205case SPRN_DBCR0:206kvmppc_set_gpr(vcpu, rt, vcpu->arch.dbcr0); break;207case SPRN_DBCR1:208kvmppc_set_gpr(vcpu, rt, vcpu->arch.dbcr1); break;209case SPRN_DBSR:210kvmppc_set_gpr(vcpu, rt, vcpu->arch.dbsr); break;211212case SPRN_IVOR0:213kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_CRITICAL]);214break;215case SPRN_IVOR1:216kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_MACHINE_CHECK]);217break;218case SPRN_IVOR2:219kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_DATA_STORAGE]);220break;221case SPRN_IVOR3:222kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_INST_STORAGE]);223break;224case SPRN_IVOR4:225kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_EXTERNAL]);226break;227case SPRN_IVOR5:228kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_ALIGNMENT]);229break;230case SPRN_IVOR6:231kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_PROGRAM]);232break;233case SPRN_IVOR7:234kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_FP_UNAVAIL]);235break;236case SPRN_IVOR8:237kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_SYSCALL]);238break;239case SPRN_IVOR9:240kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_AP_UNAVAIL]);241break;242case SPRN_IVOR10:243kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_DECREMENTER]);244break;245case SPRN_IVOR11:246kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_FIT]);247break;248case SPRN_IVOR12:249kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_WATCHDOG]);250break;251case SPRN_IVOR13:252kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_DTLB_MISS]);253break;254case SPRN_IVOR14:255kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_ITLB_MISS]);256break;257case SPRN_IVOR15:258kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_DEBUG]);259break;260261default:262emulated = EMULATE_FAIL;263}264265return emulated;266}267268269