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