Thomas Gleixner | d94d71c | 2019-05-29 07:12:40 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 2 | /* |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 3 | * |
| 4 | * Copyright IBM Corp. 2007 |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 5 | * Copyright 2011 Freescale Semiconductor, Inc. |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 6 | * |
| 7 | * Authors: Hollis Blanchard <hollisb@us.ibm.com> |
| 8 | */ |
| 9 | |
| 10 | #include <linux/jiffies.h> |
Alexander Graf | 544c676 | 2009-11-02 12:02:31 +0000 | [diff] [blame] | 11 | #include <linux/hrtimer.h> |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 12 | #include <linux/types.h> |
| 13 | #include <linux/string.h> |
| 14 | #include <linux/kvm_host.h> |
Bharat Bhushan | 6e35994 | 2012-04-18 06:01:19 +0000 | [diff] [blame] | 15 | #include <linux/clockchips.h> |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 16 | |
Hollis Blanchard | 75f74f0 | 2008-11-05 09:36:16 -0600 | [diff] [blame] | 17 | #include <asm/reg.h> |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 18 | #include <asm/time.h> |
| 19 | #include <asm/byteorder.h> |
| 20 | #include <asm/kvm_ppc.h> |
Hollis Blanchard | c381a04 | 2008-11-05 09:36:15 -0600 | [diff] [blame] | 21 | #include <asm/disassemble.h> |
Hongtao Jia | 9123c5e | 2013-04-28 13:20:07 +0800 | [diff] [blame] | 22 | #include <asm/ppc-opcode.h> |
Hollis Blanchard | 73e75b4 | 2008-12-02 15:51:57 -0600 | [diff] [blame] | 23 | #include "timing.h" |
Marcelo Tosatti | 46f43c6 | 2009-06-18 11:47:27 -0300 | [diff] [blame] | 24 | #include "trace.h" |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 25 | |
Hollis Blanchard | 75f74f0 | 2008-11-05 09:36:16 -0600 | [diff] [blame] | 26 | void kvmppc_emulate_dec(struct kvm_vcpu *vcpu) |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 27 | { |
Alexander Graf | 544c676 | 2009-11-02 12:02:31 +0000 | [diff] [blame] | 28 | unsigned long dec_nsec; |
Bharat Bhushan | dc2babfe | 2011-10-19 09:46:06 +0530 | [diff] [blame] | 29 | unsigned long long dec_time; |
Alexander Graf | 9a7a9b0 | 2009-10-30 05:47:15 +0000 | [diff] [blame] | 30 | |
Paul Mackerras | 1bc3fe8 | 2017-05-22 16:55:16 +1000 | [diff] [blame] | 31 | pr_debug("mtDEC: %lx\n", vcpu->arch.dec); |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 32 | hrtimer_try_to_cancel(&vcpu->arch.dec_timer); |
| 33 | |
Alexander Graf | 00c3a37 | 2010-04-16 00:11:42 +0200 | [diff] [blame] | 34 | #ifdef CONFIG_PPC_BOOK3S |
Alexander Graf | 7706664d | 2009-12-21 20:21:24 +0100 | [diff] [blame] | 35 | /* mtdec lowers the interrupt line when positive. */ |
| 36 | kvmppc_core_dequeue_dec(vcpu); |
Alexander Graf | 513579e | 2009-10-30 05:47:16 +0000 | [diff] [blame] | 37 | #endif |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 38 | |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 39 | #ifdef CONFIG_BOOKE |
| 40 | /* On BOOKE, DEC = 0 is as good as decrementer not enabled */ |
| 41 | if (vcpu->arch.dec == 0) |
| 42 | return; |
| 43 | #endif |
| 44 | |
| 45 | /* |
| 46 | * The decrementer ticks at the same rate as the timebase, so |
| 47 | * that's how we convert the guest DEC value to the number of |
| 48 | * host ticks. |
| 49 | */ |
| 50 | |
| 51 | dec_time = vcpu->arch.dec; |
Bharat Bhushan | 6e35994 | 2012-04-18 06:01:19 +0000 | [diff] [blame] | 52 | /* |
Paul Mackerras | c43befc | 2018-10-20 20:54:55 +1100 | [diff] [blame] | 53 | * Guest timebase ticks at the same frequency as host timebase. |
| 54 | * So use the host timebase calculations for decrementer emulation. |
Bharat Bhushan | 6e35994 | 2012-04-18 06:01:19 +0000 | [diff] [blame] | 55 | */ |
Paul Mackerras | c43befc | 2018-10-20 20:54:55 +1100 | [diff] [blame] | 56 | dec_time = tb_to_ns(dec_time); |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 57 | dec_nsec = do_div(dec_time, NSEC_PER_SEC); |
| 58 | hrtimer_start(&vcpu->arch.dec_timer, |
| 59 | ktime_set(dec_time, dec_nsec), HRTIMER_MODE_REL); |
| 60 | vcpu->arch.dec_jiffies = get_tb(); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 61 | } |
| 62 | |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 63 | u32 kvmppc_get_dec(struct kvm_vcpu *vcpu, u64 tb) |
| 64 | { |
| 65 | u64 jd = tb - vcpu->arch.dec_jiffies; |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 66 | |
| 67 | #ifdef CONFIG_BOOKE |
| 68 | if (vcpu->arch.dec < jd) |
| 69 | return 0; |
| 70 | #endif |
| 71 | |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 72 | return vcpu->arch.dec - jd; |
| 73 | } |
| 74 | |
Alexander Graf | 388cf9e | 2012-10-06 23:19:01 +0200 | [diff] [blame] | 75 | static int kvmppc_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs) |
| 76 | { |
| 77 | enum emulation_result emulated = EMULATE_DONE; |
| 78 | ulong spr_val = kvmppc_get_gpr(vcpu, rs); |
| 79 | |
| 80 | switch (sprn) { |
| 81 | case SPRN_SRR0: |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 82 | kvmppc_set_srr0(vcpu, spr_val); |
Alexander Graf | 388cf9e | 2012-10-06 23:19:01 +0200 | [diff] [blame] | 83 | break; |
| 84 | case SPRN_SRR1: |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 85 | kvmppc_set_srr1(vcpu, spr_val); |
Alexander Graf | 388cf9e | 2012-10-06 23:19:01 +0200 | [diff] [blame] | 86 | break; |
| 87 | |
| 88 | /* XXX We need to context-switch the timebase for |
| 89 | * watchdog and FIT. */ |
| 90 | case SPRN_TBWL: break; |
| 91 | case SPRN_TBWU: break; |
| 92 | |
Alexander Graf | 388cf9e | 2012-10-06 23:19:01 +0200 | [diff] [blame] | 93 | case SPRN_DEC: |
Paul Mackerras | 1bc3fe8 | 2017-05-22 16:55:16 +1000 | [diff] [blame] | 94 | vcpu->arch.dec = (u32) spr_val; |
Alexander Graf | 388cf9e | 2012-10-06 23:19:01 +0200 | [diff] [blame] | 95 | kvmppc_emulate_dec(vcpu); |
| 96 | break; |
| 97 | |
| 98 | case SPRN_SPRG0: |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 99 | kvmppc_set_sprg0(vcpu, spr_val); |
Alexander Graf | 388cf9e | 2012-10-06 23:19:01 +0200 | [diff] [blame] | 100 | break; |
| 101 | case SPRN_SPRG1: |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 102 | kvmppc_set_sprg1(vcpu, spr_val); |
Alexander Graf | 388cf9e | 2012-10-06 23:19:01 +0200 | [diff] [blame] | 103 | break; |
| 104 | case SPRN_SPRG2: |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 105 | kvmppc_set_sprg2(vcpu, spr_val); |
Alexander Graf | 388cf9e | 2012-10-06 23:19:01 +0200 | [diff] [blame] | 106 | break; |
| 107 | case SPRN_SPRG3: |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 108 | kvmppc_set_sprg3(vcpu, spr_val); |
Alexander Graf | 388cf9e | 2012-10-06 23:19:01 +0200 | [diff] [blame] | 109 | break; |
| 110 | |
Alexander Graf | a3ff5fb | 2013-06-27 01:07:15 +0200 | [diff] [blame] | 111 | /* PIR can legally be written, but we ignore it */ |
| 112 | case SPRN_PIR: break; |
| 113 | |
Alexander Graf | 388cf9e | 2012-10-06 23:19:01 +0200 | [diff] [blame] | 114 | default: |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 115 | emulated = vcpu->kvm->arch.kvm_ops->emulate_mtspr(vcpu, sprn, |
| 116 | spr_val); |
Alexander Graf | 388cf9e | 2012-10-06 23:19:01 +0200 | [diff] [blame] | 117 | if (emulated == EMULATE_FAIL) |
| 118 | printk(KERN_INFO "mtspr: unknown spr " |
| 119 | "0x%x\n", sprn); |
| 120 | break; |
| 121 | } |
| 122 | |
| 123 | kvmppc_set_exit_type(vcpu, EMULATED_MTSPR_EXITS); |
| 124 | |
| 125 | return emulated; |
| 126 | } |
| 127 | |
| 128 | static int kvmppc_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt) |
| 129 | { |
| 130 | enum emulation_result emulated = EMULATE_DONE; |
| 131 | ulong spr_val = 0; |
| 132 | |
| 133 | switch (sprn) { |
| 134 | case SPRN_SRR0: |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 135 | spr_val = kvmppc_get_srr0(vcpu); |
Alexander Graf | 388cf9e | 2012-10-06 23:19:01 +0200 | [diff] [blame] | 136 | break; |
| 137 | case SPRN_SRR1: |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 138 | spr_val = kvmppc_get_srr1(vcpu); |
Alexander Graf | 388cf9e | 2012-10-06 23:19:01 +0200 | [diff] [blame] | 139 | break; |
| 140 | case SPRN_PVR: |
| 141 | spr_val = vcpu->arch.pvr; |
| 142 | break; |
| 143 | case SPRN_PIR: |
| 144 | spr_val = vcpu->vcpu_id; |
| 145 | break; |
Alexander Graf | 388cf9e | 2012-10-06 23:19:01 +0200 | [diff] [blame] | 146 | |
| 147 | /* Note: mftb and TBRL/TBWL are user-accessible, so |
| 148 | * the guest can always access the real TB anyways. |
| 149 | * In fact, we probably will never see these traps. */ |
| 150 | case SPRN_TBWL: |
| 151 | spr_val = get_tb() >> 32; |
| 152 | break; |
| 153 | case SPRN_TBWU: |
| 154 | spr_val = get_tb(); |
| 155 | break; |
| 156 | |
| 157 | case SPRN_SPRG0: |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 158 | spr_val = kvmppc_get_sprg0(vcpu); |
Alexander Graf | 388cf9e | 2012-10-06 23:19:01 +0200 | [diff] [blame] | 159 | break; |
| 160 | case SPRN_SPRG1: |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 161 | spr_val = kvmppc_get_sprg1(vcpu); |
Alexander Graf | 388cf9e | 2012-10-06 23:19:01 +0200 | [diff] [blame] | 162 | break; |
| 163 | case SPRN_SPRG2: |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 164 | spr_val = kvmppc_get_sprg2(vcpu); |
Alexander Graf | 388cf9e | 2012-10-06 23:19:01 +0200 | [diff] [blame] | 165 | break; |
| 166 | case SPRN_SPRG3: |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 167 | spr_val = kvmppc_get_sprg3(vcpu); |
Alexander Graf | 388cf9e | 2012-10-06 23:19:01 +0200 | [diff] [blame] | 168 | break; |
| 169 | /* Note: SPRG4-7 are user-readable, so we don't get |
| 170 | * a trap. */ |
| 171 | |
| 172 | case SPRN_DEC: |
| 173 | spr_val = kvmppc_get_dec(vcpu, get_tb()); |
| 174 | break; |
| 175 | default: |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 176 | emulated = vcpu->kvm->arch.kvm_ops->emulate_mfspr(vcpu, sprn, |
| 177 | &spr_val); |
Alexander Graf | 388cf9e | 2012-10-06 23:19:01 +0200 | [diff] [blame] | 178 | if (unlikely(emulated == EMULATE_FAIL)) { |
| 179 | printk(KERN_INFO "mfspr: unknown spr " |
| 180 | "0x%x\n", sprn); |
| 181 | } |
| 182 | break; |
| 183 | } |
| 184 | |
| 185 | if (emulated == EMULATE_DONE) |
| 186 | kvmppc_set_gpr(vcpu, rt, spr_val); |
| 187 | kvmppc_set_exit_type(vcpu, EMULATED_MFSPR_EXITS); |
| 188 | |
| 189 | return emulated; |
| 190 | } |
| 191 | |
Hollis Blanchard | 75f74f0 | 2008-11-05 09:36:16 -0600 | [diff] [blame] | 192 | /* XXX Should probably auto-generate instruction decoding for a particular core |
| 193 | * from opcode tables in the future. */ |
Tianjia Zhang | 8c99d34 | 2020-04-27 12:35:11 +0800 | [diff] [blame] | 194 | int kvmppc_emulate_instruction(struct kvm_vcpu *vcpu) |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 195 | { |
Mihai Caraman | 51f0472 | 2014-07-23 19:06:21 +0300 | [diff] [blame] | 196 | u32 inst; |
Alexander Graf | d69614a | 2014-06-18 14:53:49 +0200 | [diff] [blame] | 197 | int rs, rt, sprn; |
Mihai Caraman | 51f0472 | 2014-07-23 19:06:21 +0300 | [diff] [blame] | 198 | enum emulation_result emulated; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 199 | int advance = 1; |
| 200 | |
Hollis Blanchard | 73e75b4 | 2008-12-02 15:51:57 -0600 | [diff] [blame] | 201 | /* this default type might be overwritten by subcategories */ |
| 202 | kvmppc_set_exit_type(vcpu, EMULATED_INST_EXITS); |
| 203 | |
Alexander Graf | 8d0eff6 | 2014-09-10 14:37:29 +0200 | [diff] [blame] | 204 | emulated = kvmppc_get_last_inst(vcpu, INST_GENERIC, &inst); |
Mihai Caraman | 51f0472 | 2014-07-23 19:06:21 +0300 | [diff] [blame] | 205 | if (emulated != EMULATE_DONE) |
| 206 | return emulated; |
| 207 | |
Joe Perches | 689fd14 | 2010-09-11 19:10:53 +0000 | [diff] [blame] | 208 | pr_debug("Emulating opcode %d / %d\n", get_op(inst), get_xop(inst)); |
Alexander Graf | 513579e | 2009-10-30 05:47:16 +0000 | [diff] [blame] | 209 | |
Mihai Caraman | 51f0472 | 2014-07-23 19:06:21 +0300 | [diff] [blame] | 210 | rs = get_rs(inst); |
| 211 | rt = get_rt(inst); |
| 212 | sprn = get_sprn(inst); |
| 213 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 214 | switch (get_op(inst)) { |
Hollis Blanchard | cea5d8c | 2009-01-03 16:23:05 -0600 | [diff] [blame] | 215 | case OP_TRAP: |
Alexander Graf | 00c3a37 | 2010-04-16 00:11:42 +0200 | [diff] [blame] | 216 | #ifdef CONFIG_PPC_BOOK3S |
Alexander Graf | 513579e | 2009-10-30 05:47:16 +0000 | [diff] [blame] | 217 | case OP_TRAP_64: |
Alexander Graf | 25a8a02d | 2010-01-08 02:58:07 +0100 | [diff] [blame] | 218 | kvmppc_core_queue_program(vcpu, SRR1_PROGTRAP); |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 219 | #else |
Scott Wood | b590497 | 2011-11-08 18:23:30 -0600 | [diff] [blame] | 220 | kvmppc_core_queue_program(vcpu, |
| 221 | vcpu->arch.shared->esr | ESR_PTR); |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 222 | #endif |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 223 | advance = 0; |
| 224 | break; |
| 225 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 226 | case 31: |
| 227 | switch (get_xop(inst)) { |
| 228 | |
Alexander Graf | 6df79df | 2012-03-13 22:15:45 +0100 | [diff] [blame] | 229 | case OP_31_XOP_TRAP: |
| 230 | #ifdef CONFIG_64BIT |
| 231 | case OP_31_XOP_TRAP_64: |
| 232 | #endif |
| 233 | #ifdef CONFIG_PPC_BOOK3S |
| 234 | kvmppc_core_queue_program(vcpu, SRR1_PROGTRAP); |
| 235 | #else |
| 236 | kvmppc_core_queue_program(vcpu, |
| 237 | vcpu->arch.shared->esr | ESR_PTR); |
| 238 | #endif |
| 239 | advance = 0; |
| 240 | break; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 241 | |
Hollis Blanchard | cea5d8c | 2009-01-03 16:23:05 -0600 | [diff] [blame] | 242 | case OP_31_XOP_MFSPR: |
Alexander Graf | 388cf9e | 2012-10-06 23:19:01 +0200 | [diff] [blame] | 243 | emulated = kvmppc_emulate_mfspr(vcpu, sprn, rt); |
Thomas Huth | feafd13 | 2017-04-05 15:58:51 +0200 | [diff] [blame] | 244 | if (emulated == EMULATE_AGAIN) { |
| 245 | emulated = EMULATE_DONE; |
| 246 | advance = 0; |
| 247 | } |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 248 | break; |
| 249 | |
Hollis Blanchard | cea5d8c | 2009-01-03 16:23:05 -0600 | [diff] [blame] | 250 | case OP_31_XOP_MTSPR: |
Alexander Graf | 388cf9e | 2012-10-06 23:19:01 +0200 | [diff] [blame] | 251 | emulated = kvmppc_emulate_mtspr(vcpu, sprn, rs); |
Thomas Huth | feafd13 | 2017-04-05 15:58:51 +0200 | [diff] [blame] | 252 | if (emulated == EMULATE_AGAIN) { |
| 253 | emulated = EMULATE_DONE; |
| 254 | advance = 0; |
| 255 | } |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 256 | break; |
| 257 | |
Hollis Blanchard | cea5d8c | 2009-01-03 16:23:05 -0600 | [diff] [blame] | 258 | case OP_31_XOP_TLBSYNC: |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 259 | break; |
| 260 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 261 | default: |
Hollis Blanchard | 75f74f0 | 2008-11-05 09:36:16 -0600 | [diff] [blame] | 262 | /* Attempt core-specific emulation below. */ |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 263 | emulated = EMULATE_FAIL; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 264 | } |
| 265 | break; |
| 266 | |
Madhavan Srinivasan | a59c1d9 | 2014-09-09 22:37:35 +0530 | [diff] [blame] | 267 | case 0: |
| 268 | /* |
| 269 | * Instruction with primary opcode 0. Based on PowerISA |
| 270 | * these are illegal instructions. |
| 271 | */ |
| 272 | if (inst == KVMPPC_INST_SW_BREAKPOINT) { |
Tianjia Zhang | 8c99d34 | 2020-04-27 12:35:11 +0800 | [diff] [blame] | 273 | vcpu->run->exit_reason = KVM_EXIT_DEBUG; |
| 274 | vcpu->run->debug.arch.status = 0; |
| 275 | vcpu->run->debug.arch.address = kvmppc_get_pc(vcpu); |
Madhavan Srinivasan | a59c1d9 | 2014-09-09 22:37:35 +0530 | [diff] [blame] | 276 | emulated = EMULATE_EXIT_USER; |
| 277 | advance = 0; |
| 278 | } else |
| 279 | emulated = EMULATE_FAIL; |
| 280 | |
| 281 | break; |
| 282 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 283 | default: |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 284 | emulated = EMULATE_FAIL; |
Hollis Blanchard | 75f74f0 | 2008-11-05 09:36:16 -0600 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | if (emulated == EMULATE_FAIL) { |
Tianjia Zhang | 8c99d34 | 2020-04-27 12:35:11 +0800 | [diff] [blame] | 288 | emulated = vcpu->kvm->arch.kvm_ops->emulate_op(vcpu, inst, |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 289 | &advance); |
Alexander Graf | 37f5bca | 2010-02-19 11:00:31 +0100 | [diff] [blame] | 290 | if (emulated == EMULATE_AGAIN) { |
| 291 | advance = 0; |
| 292 | } else if (emulated == EMULATE_FAIL) { |
Hollis Blanchard | 75f74f0 | 2008-11-05 09:36:16 -0600 | [diff] [blame] | 293 | advance = 0; |
| 294 | printk(KERN_ERR "Couldn't emulate instruction 0x%08x " |
| 295 | "(op %d xop %d)\n", inst, get_op(inst), get_xop(inst)); |
| 296 | } |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 297 | } |
| 298 | |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 299 | trace_kvm_ppc_instr(inst, kvmppc_get_pc(vcpu), emulated); |
Christian Ehrhardt | 3b4bd79 | 2008-07-14 14:00:04 +0200 | [diff] [blame] | 300 | |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 301 | /* Advance past emulated instruction. */ |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 302 | if (advance) |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 303 | kvmppc_set_pc(vcpu, kvmppc_get_pc(vcpu) + 4); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 304 | |
| 305 | return emulated; |
| 306 | } |
Aneesh Kumar K.V | 2ba9f0d | 2013-10-07 22:17:59 +0530 | [diff] [blame] | 307 | EXPORT_SYMBOL_GPL(kvmppc_emulate_instruction); |