Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1 | /* |
| 2 | * This program is free software; you can redistribute it and/or modify |
| 3 | * it under the terms of the GNU General Public License, version 2, as |
| 4 | * published by the Free Software Foundation. |
| 5 | * |
| 6 | * This program is distributed in the hope that it will be useful, |
| 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 8 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 9 | * GNU General Public License for more details. |
| 10 | * |
| 11 | * You should have received a copy of the GNU General Public License |
| 12 | * along with this program; if not, write to the Free Software |
| 13 | * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 14 | * |
| 15 | * Copyright IBM Corp. 2007 |
| 16 | * |
| 17 | * Authors: Hollis Blanchard <hollisb@us.ibm.com> |
| 18 | */ |
| 19 | |
| 20 | #include <linux/jiffies.h> |
| 21 | #include <linux/timer.h> |
| 22 | #include <linux/types.h> |
| 23 | #include <linux/string.h> |
| 24 | #include <linux/kvm_host.h> |
| 25 | |
Hollis Blanchard | 75f74f0 | 2008-11-05 09:36:16 -0600 | [diff] [blame] | 26 | #include <asm/reg.h> |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 27 | #include <asm/time.h> |
| 28 | #include <asm/byteorder.h> |
| 29 | #include <asm/kvm_ppc.h> |
Hollis Blanchard | c381a04 | 2008-11-05 09:36:15 -0600 | [diff] [blame] | 30 | #include <asm/disassemble.h> |
Hollis Blanchard | 73e75b4 | 2008-12-02 15:51:57 -0600 | [diff] [blame] | 31 | #include "timing.h" |
Marcelo Tosatti | 46f43c6 | 2009-06-18 11:47:27 -0300 | [diff] [blame] | 32 | #include "trace.h" |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 33 | |
Hollis Blanchard | cea5d8c | 2009-01-03 16:23:05 -0600 | [diff] [blame] | 34 | #define OP_TRAP 3 |
| 35 | |
| 36 | #define OP_31_XOP_LWZX 23 |
| 37 | #define OP_31_XOP_LBZX 87 |
| 38 | #define OP_31_XOP_STWX 151 |
| 39 | #define OP_31_XOP_STBX 215 |
| 40 | #define OP_31_XOP_STBUX 247 |
| 41 | #define OP_31_XOP_LHZX 279 |
| 42 | #define OP_31_XOP_LHZUX 311 |
| 43 | #define OP_31_XOP_MFSPR 339 |
| 44 | #define OP_31_XOP_STHX 407 |
| 45 | #define OP_31_XOP_STHUX 439 |
| 46 | #define OP_31_XOP_MTSPR 467 |
| 47 | #define OP_31_XOP_DCBI 470 |
| 48 | #define OP_31_XOP_LWBRX 534 |
| 49 | #define OP_31_XOP_TLBSYNC 566 |
| 50 | #define OP_31_XOP_STWBRX 662 |
| 51 | #define OP_31_XOP_LHBRX 790 |
| 52 | #define OP_31_XOP_STHBRX 918 |
| 53 | |
| 54 | #define OP_LWZ 32 |
| 55 | #define OP_LWZU 33 |
| 56 | #define OP_LBZ 34 |
| 57 | #define OP_LBZU 35 |
| 58 | #define OP_STW 36 |
| 59 | #define OP_STWU 37 |
| 60 | #define OP_STB 38 |
| 61 | #define OP_STBU 39 |
| 62 | #define OP_LHZ 40 |
| 63 | #define OP_LHZU 41 |
| 64 | #define OP_STH 44 |
| 65 | #define OP_STHU 45 |
| 66 | |
Hollis Blanchard | 75f74f0 | 2008-11-05 09:36:16 -0600 | [diff] [blame] | 67 | void kvmppc_emulate_dec(struct kvm_vcpu *vcpu) |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 68 | { |
Alexander Graf | 9a7a9b0 | 2009-10-30 05:47:15 +0000 | [diff] [blame^] | 69 | unsigned long nr_jiffies; |
| 70 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 71 | if (vcpu->arch.tcr & TCR_DIE) { |
| 72 | /* The decrementer ticks at the same rate as the timebase, so |
| 73 | * that's how we convert the guest DEC value to the number of |
| 74 | * host ticks. */ |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 75 | |
Alexander Graf | 9a7a9b0 | 2009-10-30 05:47:15 +0000 | [diff] [blame^] | 76 | vcpu->arch.dec_jiffies = mftb(); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 77 | nr_jiffies = vcpu->arch.dec / tb_ticks_per_jiffy; |
| 78 | mod_timer(&vcpu->arch.dec_timer, |
| 79 | get_jiffies_64() + nr_jiffies); |
| 80 | } else { |
| 81 | del_timer(&vcpu->arch.dec_timer); |
| 82 | } |
| 83 | } |
| 84 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 85 | /* XXX to do: |
| 86 | * lhax |
| 87 | * lhaux |
| 88 | * lswx |
| 89 | * lswi |
| 90 | * stswx |
| 91 | * stswi |
| 92 | * lha |
| 93 | * lhau |
| 94 | * lmw |
| 95 | * stmw |
| 96 | * |
| 97 | * XXX is_bigendian should depend on MMU mapping or MSR[LE] |
| 98 | */ |
Hollis Blanchard | 75f74f0 | 2008-11-05 09:36:16 -0600 | [diff] [blame] | 99 | /* XXX Should probably auto-generate instruction decoding for a particular core |
| 100 | * from opcode tables in the future. */ |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 101 | int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu) |
| 102 | { |
| 103 | u32 inst = vcpu->arch.last_inst; |
| 104 | u32 ea; |
| 105 | int ra; |
| 106 | int rb; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 107 | int rs; |
| 108 | int rt; |
| 109 | int sprn; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 110 | enum emulation_result emulated = EMULATE_DONE; |
| 111 | int advance = 1; |
| 112 | |
Hollis Blanchard | 73e75b4 | 2008-12-02 15:51:57 -0600 | [diff] [blame] | 113 | /* this default type might be overwritten by subcategories */ |
| 114 | kvmppc_set_exit_type(vcpu, EMULATED_INST_EXITS); |
| 115 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 116 | switch (get_op(inst)) { |
Hollis Blanchard | cea5d8c | 2009-01-03 16:23:05 -0600 | [diff] [blame] | 117 | case OP_TRAP: |
Hollis Blanchard | fcfdbd2 | 2008-11-05 09:36:24 -0600 | [diff] [blame] | 118 | vcpu->arch.esr |= ESR_PTR; |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 119 | kvmppc_core_queue_program(vcpu); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 120 | advance = 0; |
| 121 | break; |
| 122 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 123 | case 31: |
| 124 | switch (get_xop(inst)) { |
| 125 | |
Hollis Blanchard | cea5d8c | 2009-01-03 16:23:05 -0600 | [diff] [blame] | 126 | case OP_31_XOP_LWZX: |
Hollis Blanchard | ac3cd34 | 2008-05-21 18:22:52 -0500 | [diff] [blame] | 127 | rt = get_rt(inst); |
| 128 | emulated = kvmppc_handle_load(run, vcpu, rt, 4, 1); |
| 129 | break; |
| 130 | |
Hollis Blanchard | cea5d8c | 2009-01-03 16:23:05 -0600 | [diff] [blame] | 131 | case OP_31_XOP_LBZX: |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 132 | rt = get_rt(inst); |
| 133 | emulated = kvmppc_handle_load(run, vcpu, rt, 1, 1); |
| 134 | break; |
| 135 | |
Hollis Blanchard | cea5d8c | 2009-01-03 16:23:05 -0600 | [diff] [blame] | 136 | case OP_31_XOP_STWX: |
Hollis Blanchard | ac3cd34 | 2008-05-21 18:22:52 -0500 | [diff] [blame] | 137 | rs = get_rs(inst); |
| 138 | emulated = kvmppc_handle_store(run, vcpu, |
| 139 | vcpu->arch.gpr[rs], |
| 140 | 4, 1); |
| 141 | break; |
| 142 | |
Hollis Blanchard | cea5d8c | 2009-01-03 16:23:05 -0600 | [diff] [blame] | 143 | case OP_31_XOP_STBX: |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 144 | rs = get_rs(inst); |
| 145 | emulated = kvmppc_handle_store(run, vcpu, |
| 146 | vcpu->arch.gpr[rs], |
| 147 | 1, 1); |
| 148 | break; |
| 149 | |
Hollis Blanchard | cea5d8c | 2009-01-03 16:23:05 -0600 | [diff] [blame] | 150 | case OP_31_XOP_STBUX: |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 151 | rs = get_rs(inst); |
| 152 | ra = get_ra(inst); |
| 153 | rb = get_rb(inst); |
| 154 | |
| 155 | ea = vcpu->arch.gpr[rb]; |
| 156 | if (ra) |
| 157 | ea += vcpu->arch.gpr[ra]; |
| 158 | |
| 159 | emulated = kvmppc_handle_store(run, vcpu, |
| 160 | vcpu->arch.gpr[rs], |
| 161 | 1, 1); |
| 162 | vcpu->arch.gpr[rs] = ea; |
| 163 | break; |
| 164 | |
Hollis Blanchard | cea5d8c | 2009-01-03 16:23:05 -0600 | [diff] [blame] | 165 | case OP_31_XOP_LHZX: |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 166 | rt = get_rt(inst); |
| 167 | emulated = kvmppc_handle_load(run, vcpu, rt, 2, 1); |
| 168 | break; |
| 169 | |
Hollis Blanchard | cea5d8c | 2009-01-03 16:23:05 -0600 | [diff] [blame] | 170 | case OP_31_XOP_LHZUX: |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 171 | rt = get_rt(inst); |
| 172 | ra = get_ra(inst); |
| 173 | rb = get_rb(inst); |
| 174 | |
| 175 | ea = vcpu->arch.gpr[rb]; |
| 176 | if (ra) |
| 177 | ea += vcpu->arch.gpr[ra]; |
| 178 | |
| 179 | emulated = kvmppc_handle_load(run, vcpu, rt, 2, 1); |
| 180 | vcpu->arch.gpr[ra] = ea; |
| 181 | break; |
| 182 | |
Hollis Blanchard | cea5d8c | 2009-01-03 16:23:05 -0600 | [diff] [blame] | 183 | case OP_31_XOP_MFSPR: |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 184 | sprn = get_sprn(inst); |
| 185 | rt = get_rt(inst); |
| 186 | |
| 187 | switch (sprn) { |
| 188 | case SPRN_SRR0: |
| 189 | vcpu->arch.gpr[rt] = vcpu->arch.srr0; break; |
| 190 | case SPRN_SRR1: |
| 191 | vcpu->arch.gpr[rt] = vcpu->arch.srr1; break; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 192 | case SPRN_PVR: |
Liu Yu | 5b7c1a2 | 2009-06-05 14:54:30 +0800 | [diff] [blame] | 193 | vcpu->arch.gpr[rt] = mfspr(SPRN_PVR); break; |
Liu Yu | 06579dd | 2009-06-05 14:54:31 +0800 | [diff] [blame] | 194 | case SPRN_PIR: |
| 195 | vcpu->arch.gpr[rt] = mfspr(SPRN_PIR); break; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 196 | |
| 197 | /* Note: mftb and TBRL/TBWL are user-accessible, so |
| 198 | * the guest can always access the real TB anyways. |
| 199 | * In fact, we probably will never see these traps. */ |
| 200 | case SPRN_TBWL: |
| 201 | vcpu->arch.gpr[rt] = mftbl(); break; |
| 202 | case SPRN_TBWU: |
| 203 | vcpu->arch.gpr[rt] = mftbu(); break; |
| 204 | |
| 205 | case SPRN_SPRG0: |
| 206 | vcpu->arch.gpr[rt] = vcpu->arch.sprg0; break; |
| 207 | case SPRN_SPRG1: |
| 208 | vcpu->arch.gpr[rt] = vcpu->arch.sprg1; break; |
| 209 | case SPRN_SPRG2: |
| 210 | vcpu->arch.gpr[rt] = vcpu->arch.sprg2; break; |
| 211 | case SPRN_SPRG3: |
| 212 | vcpu->arch.gpr[rt] = vcpu->arch.sprg3; break; |
| 213 | /* Note: SPRG4-7 are user-readable, so we don't get |
| 214 | * a trap. */ |
| 215 | |
Alexander Graf | 9a7a9b0 | 2009-10-30 05:47:15 +0000 | [diff] [blame^] | 216 | case SPRN_DEC: |
| 217 | { |
| 218 | u64 jd = mftb() - vcpu->arch.dec_jiffies; |
| 219 | vcpu->arch.gpr[rt] = vcpu->arch.dec - jd; |
| 220 | #ifdef DEBUG_EMUL |
| 221 | printk(KERN_INFO "mfDEC: %x - %llx = %lx\n", vcpu->arch.dec, jd, vcpu->arch.gpr[rt]); |
| 222 | #endif |
| 223 | break; |
| 224 | } |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 225 | default: |
Hollis Blanchard | 75f74f0 | 2008-11-05 09:36:16 -0600 | [diff] [blame] | 226 | emulated = kvmppc_core_emulate_mfspr(vcpu, sprn, rt); |
| 227 | if (emulated == EMULATE_FAIL) { |
| 228 | printk("mfspr: unknown spr %x\n", sprn); |
| 229 | vcpu->arch.gpr[rt] = 0; |
| 230 | } |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 231 | break; |
| 232 | } |
| 233 | break; |
| 234 | |
Hollis Blanchard | cea5d8c | 2009-01-03 16:23:05 -0600 | [diff] [blame] | 235 | case OP_31_XOP_STHX: |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 236 | rs = get_rs(inst); |
| 237 | ra = get_ra(inst); |
| 238 | rb = get_rb(inst); |
| 239 | |
| 240 | emulated = kvmppc_handle_store(run, vcpu, |
| 241 | vcpu->arch.gpr[rs], |
| 242 | 2, 1); |
| 243 | break; |
| 244 | |
Hollis Blanchard | cea5d8c | 2009-01-03 16:23:05 -0600 | [diff] [blame] | 245 | case OP_31_XOP_STHUX: |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 246 | rs = get_rs(inst); |
| 247 | ra = get_ra(inst); |
| 248 | rb = get_rb(inst); |
| 249 | |
| 250 | ea = vcpu->arch.gpr[rb]; |
| 251 | if (ra) |
| 252 | ea += vcpu->arch.gpr[ra]; |
| 253 | |
| 254 | emulated = kvmppc_handle_store(run, vcpu, |
| 255 | vcpu->arch.gpr[rs], |
| 256 | 2, 1); |
| 257 | vcpu->arch.gpr[ra] = ea; |
| 258 | break; |
| 259 | |
Hollis Blanchard | cea5d8c | 2009-01-03 16:23:05 -0600 | [diff] [blame] | 260 | case OP_31_XOP_MTSPR: |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 261 | sprn = get_sprn(inst); |
| 262 | rs = get_rs(inst); |
| 263 | switch (sprn) { |
| 264 | case SPRN_SRR0: |
| 265 | vcpu->arch.srr0 = vcpu->arch.gpr[rs]; break; |
| 266 | case SPRN_SRR1: |
| 267 | vcpu->arch.srr1 = vcpu->arch.gpr[rs]; break; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 268 | |
| 269 | /* XXX We need to context-switch the timebase for |
| 270 | * watchdog and FIT. */ |
| 271 | case SPRN_TBWL: break; |
| 272 | case SPRN_TBWU: break; |
| 273 | |
| 274 | case SPRN_DEC: |
| 275 | vcpu->arch.dec = vcpu->arch.gpr[rs]; |
| 276 | kvmppc_emulate_dec(vcpu); |
| 277 | break; |
| 278 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 279 | case SPRN_SPRG0: |
| 280 | vcpu->arch.sprg0 = vcpu->arch.gpr[rs]; break; |
| 281 | case SPRN_SPRG1: |
| 282 | vcpu->arch.sprg1 = vcpu->arch.gpr[rs]; break; |
| 283 | case SPRN_SPRG2: |
| 284 | vcpu->arch.sprg2 = vcpu->arch.gpr[rs]; break; |
| 285 | case SPRN_SPRG3: |
| 286 | vcpu->arch.sprg3 = vcpu->arch.gpr[rs]; break; |
| 287 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 288 | default: |
Hollis Blanchard | 75f74f0 | 2008-11-05 09:36:16 -0600 | [diff] [blame] | 289 | emulated = kvmppc_core_emulate_mtspr(vcpu, sprn, rs); |
| 290 | if (emulated == EMULATE_FAIL) |
| 291 | printk("mtspr: unknown spr %x\n", sprn); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 292 | break; |
| 293 | } |
| 294 | break; |
| 295 | |
Hollis Blanchard | cea5d8c | 2009-01-03 16:23:05 -0600 | [diff] [blame] | 296 | case OP_31_XOP_DCBI: |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 297 | /* Do nothing. The guest is performing dcbi because |
| 298 | * hardware DMA is not snooped by the dcache, but |
| 299 | * emulated DMA either goes through the dcache as |
| 300 | * normal writes, or the host kernel has handled dcache |
| 301 | * coherence. */ |
| 302 | break; |
| 303 | |
Hollis Blanchard | cea5d8c | 2009-01-03 16:23:05 -0600 | [diff] [blame] | 304 | case OP_31_XOP_LWBRX: |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 305 | rt = get_rt(inst); |
| 306 | emulated = kvmppc_handle_load(run, vcpu, rt, 4, 0); |
| 307 | break; |
| 308 | |
Hollis Blanchard | cea5d8c | 2009-01-03 16:23:05 -0600 | [diff] [blame] | 309 | case OP_31_XOP_TLBSYNC: |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 310 | break; |
| 311 | |
Hollis Blanchard | cea5d8c | 2009-01-03 16:23:05 -0600 | [diff] [blame] | 312 | case OP_31_XOP_STWBRX: |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 313 | rs = get_rs(inst); |
| 314 | ra = get_ra(inst); |
| 315 | rb = get_rb(inst); |
| 316 | |
| 317 | emulated = kvmppc_handle_store(run, vcpu, |
| 318 | vcpu->arch.gpr[rs], |
| 319 | 4, 0); |
| 320 | break; |
| 321 | |
Hollis Blanchard | cea5d8c | 2009-01-03 16:23:05 -0600 | [diff] [blame] | 322 | case OP_31_XOP_LHBRX: |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 323 | rt = get_rt(inst); |
| 324 | emulated = kvmppc_handle_load(run, vcpu, rt, 2, 0); |
| 325 | break; |
| 326 | |
Hollis Blanchard | cea5d8c | 2009-01-03 16:23:05 -0600 | [diff] [blame] | 327 | case OP_31_XOP_STHBRX: |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 328 | rs = get_rs(inst); |
| 329 | ra = get_ra(inst); |
| 330 | rb = get_rb(inst); |
| 331 | |
| 332 | emulated = kvmppc_handle_store(run, vcpu, |
| 333 | vcpu->arch.gpr[rs], |
| 334 | 2, 0); |
| 335 | break; |
| 336 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 337 | default: |
Hollis Blanchard | 75f74f0 | 2008-11-05 09:36:16 -0600 | [diff] [blame] | 338 | /* Attempt core-specific emulation below. */ |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 339 | emulated = EMULATE_FAIL; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 340 | } |
| 341 | break; |
| 342 | |
Hollis Blanchard | cea5d8c | 2009-01-03 16:23:05 -0600 | [diff] [blame] | 343 | case OP_LWZ: |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 344 | rt = get_rt(inst); |
| 345 | emulated = kvmppc_handle_load(run, vcpu, rt, 4, 1); |
| 346 | break; |
| 347 | |
Hollis Blanchard | cea5d8c | 2009-01-03 16:23:05 -0600 | [diff] [blame] | 348 | case OP_LWZU: |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 349 | ra = get_ra(inst); |
| 350 | rt = get_rt(inst); |
| 351 | emulated = kvmppc_handle_load(run, vcpu, rt, 4, 1); |
| 352 | vcpu->arch.gpr[ra] = vcpu->arch.paddr_accessed; |
| 353 | break; |
| 354 | |
Hollis Blanchard | cea5d8c | 2009-01-03 16:23:05 -0600 | [diff] [blame] | 355 | case OP_LBZ: |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 356 | rt = get_rt(inst); |
| 357 | emulated = kvmppc_handle_load(run, vcpu, rt, 1, 1); |
| 358 | break; |
| 359 | |
Hollis Blanchard | cea5d8c | 2009-01-03 16:23:05 -0600 | [diff] [blame] | 360 | case OP_LBZU: |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 361 | ra = get_ra(inst); |
| 362 | rt = get_rt(inst); |
| 363 | emulated = kvmppc_handle_load(run, vcpu, rt, 1, 1); |
| 364 | vcpu->arch.gpr[ra] = vcpu->arch.paddr_accessed; |
| 365 | break; |
| 366 | |
Hollis Blanchard | cea5d8c | 2009-01-03 16:23:05 -0600 | [diff] [blame] | 367 | case OP_STW: |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 368 | rs = get_rs(inst); |
| 369 | emulated = kvmppc_handle_store(run, vcpu, vcpu->arch.gpr[rs], |
| 370 | 4, 1); |
| 371 | break; |
| 372 | |
Hollis Blanchard | cea5d8c | 2009-01-03 16:23:05 -0600 | [diff] [blame] | 373 | case OP_STWU: |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 374 | ra = get_ra(inst); |
| 375 | rs = get_rs(inst); |
| 376 | emulated = kvmppc_handle_store(run, vcpu, vcpu->arch.gpr[rs], |
| 377 | 4, 1); |
| 378 | vcpu->arch.gpr[ra] = vcpu->arch.paddr_accessed; |
| 379 | break; |
| 380 | |
Hollis Blanchard | cea5d8c | 2009-01-03 16:23:05 -0600 | [diff] [blame] | 381 | case OP_STB: |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 382 | rs = get_rs(inst); |
| 383 | emulated = kvmppc_handle_store(run, vcpu, vcpu->arch.gpr[rs], |
| 384 | 1, 1); |
| 385 | break; |
| 386 | |
Hollis Blanchard | cea5d8c | 2009-01-03 16:23:05 -0600 | [diff] [blame] | 387 | case OP_STBU: |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 388 | ra = get_ra(inst); |
| 389 | rs = get_rs(inst); |
| 390 | emulated = kvmppc_handle_store(run, vcpu, vcpu->arch.gpr[rs], |
| 391 | 1, 1); |
| 392 | vcpu->arch.gpr[ra] = vcpu->arch.paddr_accessed; |
| 393 | break; |
| 394 | |
Hollis Blanchard | cea5d8c | 2009-01-03 16:23:05 -0600 | [diff] [blame] | 395 | case OP_LHZ: |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 396 | rt = get_rt(inst); |
| 397 | emulated = kvmppc_handle_load(run, vcpu, rt, 2, 1); |
| 398 | break; |
| 399 | |
Hollis Blanchard | cea5d8c | 2009-01-03 16:23:05 -0600 | [diff] [blame] | 400 | case OP_LHZU: |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 401 | ra = get_ra(inst); |
| 402 | rt = get_rt(inst); |
| 403 | emulated = kvmppc_handle_load(run, vcpu, rt, 2, 1); |
| 404 | vcpu->arch.gpr[ra] = vcpu->arch.paddr_accessed; |
| 405 | break; |
| 406 | |
Hollis Blanchard | cea5d8c | 2009-01-03 16:23:05 -0600 | [diff] [blame] | 407 | case OP_STH: |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 408 | rs = get_rs(inst); |
| 409 | emulated = kvmppc_handle_store(run, vcpu, vcpu->arch.gpr[rs], |
| 410 | 2, 1); |
| 411 | break; |
| 412 | |
Hollis Blanchard | cea5d8c | 2009-01-03 16:23:05 -0600 | [diff] [blame] | 413 | case OP_STHU: |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 414 | ra = get_ra(inst); |
| 415 | rs = get_rs(inst); |
| 416 | emulated = kvmppc_handle_store(run, vcpu, vcpu->arch.gpr[rs], |
| 417 | 2, 1); |
| 418 | vcpu->arch.gpr[ra] = vcpu->arch.paddr_accessed; |
| 419 | break; |
| 420 | |
| 421 | default: |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 422 | emulated = EMULATE_FAIL; |
Hollis Blanchard | 75f74f0 | 2008-11-05 09:36:16 -0600 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | if (emulated == EMULATE_FAIL) { |
| 426 | emulated = kvmppc_core_emulate_op(run, vcpu, inst, &advance); |
| 427 | if (emulated == EMULATE_FAIL) { |
| 428 | advance = 0; |
| 429 | printk(KERN_ERR "Couldn't emulate instruction 0x%08x " |
| 430 | "(op %d xop %d)\n", inst, get_op(inst), get_xop(inst)); |
| 431 | } |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 432 | } |
| 433 | |
Marcelo Tosatti | 46f43c6 | 2009-06-18 11:47:27 -0300 | [diff] [blame] | 434 | trace_kvm_ppc_instr(inst, vcpu->arch.pc, emulated); |
Christian Ehrhardt | 3b4bd79 | 2008-07-14 14:00:04 +0200 | [diff] [blame] | 435 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 436 | if (advance) |
| 437 | vcpu->arch.pc += 4; /* Advance past emulated instruction. */ |
| 438 | |
| 439 | return emulated; |
| 440 | } |