Commit | Line | Data |
---|---|---|
bc8080cb HB |
1 | /* |
2 | * Copyright (C) 2008 Freescale Semiconductor, Inc. All rights reserved. | |
3 | * | |
4 | * Author: Yu Liu, <yu.liu@freescale.com> | |
5 | * | |
6 | * Description: | |
7 | * This file is derived from arch/powerpc/kvm/44x_emulate.c, | |
8 | * by Hollis Blanchard <hollisb@us.ibm.com>. | |
9 | * | |
10 | * This program is free software; you can redistribute it and/or modify | |
11 | * it under the terms of the GNU General Public License, version 2, as | |
12 | * published by the Free Software Foundation. | |
13 | */ | |
14 | ||
15 | #include <asm/kvm_ppc.h> | |
16 | #include <asm/disassemble.h> | |
17 | #include <asm/kvm_e500.h> | |
18 | ||
19 | #include "booke.h" | |
20 | #include "e500_tlb.h" | |
21 | ||
22 | #define XOP_TLBIVAX 786 | |
23 | #define XOP_TLBSX 914 | |
24 | #define XOP_TLBRE 946 | |
25 | #define XOP_TLBWE 978 | |
26 | ||
27 | int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu, | |
28 | unsigned int inst, int *advance) | |
29 | { | |
30 | int emulated = EMULATE_DONE; | |
31 | int ra; | |
32 | int rb; | |
33 | int rs; | |
34 | int rt; | |
35 | ||
36 | switch (get_op(inst)) { | |
37 | case 31: | |
38 | switch (get_xop(inst)) { | |
39 | ||
40 | case XOP_TLBRE: | |
41 | emulated = kvmppc_e500_emul_tlbre(vcpu); | |
42 | break; | |
43 | ||
44 | case XOP_TLBWE: | |
45 | emulated = kvmppc_e500_emul_tlbwe(vcpu); | |
46 | break; | |
47 | ||
48 | case XOP_TLBSX: | |
49 | rb = get_rb(inst); | |
50 | emulated = kvmppc_e500_emul_tlbsx(vcpu,rb); | |
51 | break; | |
52 | ||
53 | case XOP_TLBIVAX: | |
54 | ra = get_ra(inst); | |
55 | rb = get_rb(inst); | |
56 | emulated = kvmppc_e500_emul_tlbivax(vcpu, ra, rb); | |
57 | break; | |
58 | ||
59 | default: | |
60 | emulated = EMULATE_FAIL; | |
61 | } | |
62 | ||
63 | break; | |
64 | ||
65 | default: | |
66 | emulated = EMULATE_FAIL; | |
67 | } | |
68 | ||
69 | if (emulated == EMULATE_FAIL) | |
70 | emulated = kvmppc_booke_emulate_op(run, vcpu, inst, advance); | |
71 | ||
72 | return emulated; | |
73 | } | |
74 | ||
75 | int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs) | |
76 | { | |
77 | struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu); | |
78 | int emulated = EMULATE_DONE; | |
79 | ||
80 | switch (sprn) { | |
81 | case SPRN_PID: | |
82 | vcpu_e500->pid[0] = vcpu->arch.shadow_pid = | |
83 | vcpu->arch.pid = vcpu->arch.gpr[rs]; | |
84 | break; | |
85 | case SPRN_PID1: | |
86 | vcpu_e500->pid[1] = vcpu->arch.gpr[rs]; break; | |
87 | case SPRN_PID2: | |
88 | vcpu_e500->pid[2] = vcpu->arch.gpr[rs]; break; | |
89 | case SPRN_MAS0: | |
90 | vcpu_e500->mas0 = vcpu->arch.gpr[rs]; break; | |
91 | case SPRN_MAS1: | |
92 | vcpu_e500->mas1 = vcpu->arch.gpr[rs]; break; | |
93 | case SPRN_MAS2: | |
94 | vcpu_e500->mas2 = vcpu->arch.gpr[rs]; break; | |
95 | case SPRN_MAS3: | |
96 | vcpu_e500->mas3 = vcpu->arch.gpr[rs]; break; | |
97 | case SPRN_MAS4: | |
98 | vcpu_e500->mas4 = vcpu->arch.gpr[rs]; break; | |
99 | case SPRN_MAS6: | |
100 | vcpu_e500->mas6 = vcpu->arch.gpr[rs]; break; | |
101 | case SPRN_MAS7: | |
102 | vcpu_e500->mas7 = vcpu->arch.gpr[rs]; break; | |
103 | case SPRN_L1CSR1: | |
104 | vcpu_e500->l1csr1 = vcpu->arch.gpr[rs]; break; | |
105 | case SPRN_HID0: | |
106 | vcpu_e500->hid0 = vcpu->arch.gpr[rs]; break; | |
107 | case SPRN_HID1: | |
108 | vcpu_e500->hid1 = vcpu->arch.gpr[rs]; break; | |
109 | ||
110 | default: | |
111 | emulated = kvmppc_booke_emulate_mtspr(vcpu, sprn, rs); | |
112 | } | |
113 | ||
114 | return emulated; | |
115 | } | |
116 | ||
117 | int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt) | |
118 | { | |
119 | struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu); | |
120 | int emulated = EMULATE_DONE; | |
121 | ||
122 | switch (sprn) { | |
123 | case SPRN_PID: | |
124 | vcpu->arch.gpr[rt] = vcpu_e500->pid[0]; break; | |
125 | case SPRN_PID1: | |
126 | vcpu->arch.gpr[rt] = vcpu_e500->pid[1]; break; | |
127 | case SPRN_PID2: | |
128 | vcpu->arch.gpr[rt] = vcpu_e500->pid[2]; break; | |
129 | case SPRN_MAS0: | |
130 | vcpu->arch.gpr[rt] = vcpu_e500->mas0; break; | |
131 | case SPRN_MAS1: | |
132 | vcpu->arch.gpr[rt] = vcpu_e500->mas1; break; | |
133 | case SPRN_MAS2: | |
134 | vcpu->arch.gpr[rt] = vcpu_e500->mas2; break; | |
135 | case SPRN_MAS3: | |
136 | vcpu->arch.gpr[rt] = vcpu_e500->mas3; break; | |
137 | case SPRN_MAS4: | |
138 | vcpu->arch.gpr[rt] = vcpu_e500->mas4; break; | |
139 | case SPRN_MAS6: | |
140 | vcpu->arch.gpr[rt] = vcpu_e500->mas6; break; | |
141 | case SPRN_MAS7: | |
142 | vcpu->arch.gpr[rt] = vcpu_e500->mas7; break; | |
143 | ||
144 | case SPRN_TLB0CFG: | |
145 | vcpu->arch.gpr[rt] = mfspr(SPRN_TLB0CFG); | |
146 | vcpu->arch.gpr[rt] &= ~0xfffUL; | |
147 | vcpu->arch.gpr[rt] |= vcpu_e500->guest_tlb_size[0]; | |
148 | break; | |
149 | ||
150 | case SPRN_TLB1CFG: | |
151 | vcpu->arch.gpr[rt] = mfspr(SPRN_TLB1CFG); | |
152 | vcpu->arch.gpr[rt] &= ~0xfffUL; | |
153 | vcpu->arch.gpr[rt] |= vcpu_e500->guest_tlb_size[1]; | |
154 | break; | |
155 | ||
156 | case SPRN_L1CSR1: | |
157 | vcpu->arch.gpr[rt] = vcpu_e500->l1csr1; break; | |
158 | case SPRN_HID0: | |
159 | vcpu->arch.gpr[rt] = vcpu_e500->hid0; break; | |
160 | case SPRN_HID1: | |
161 | vcpu->arch.gpr[rt] = vcpu_e500->hid1; break; | |
162 | ||
163 | default: | |
164 | emulated = kvmppc_booke_emulate_mfspr(vcpu, sprn, rt); | |
165 | } | |
166 | ||
167 | return emulated; | |
168 | } | |
169 |