diff options
author | Marc Zyngier <marc.zyngier@arm.com> | 2012-12-08 13:13:18 -0500 |
---|---|---|
committer | Christoffer Dall <cdall@cs.columbia.edu> | 2013-03-06 18:48:43 -0500 |
commit | c5997563298bc1b9da5212c15544962d4dbbe27d (patch) | |
tree | 28b83cf9fcf33f4b14ead94a618f0513810c47ed /arch/arm/kvm | |
parent | 52d1dba933f601d8d9e6373377377b12d6bcfac0 (diff) |
ARM: KVM: move kvm_condition_valid to emulate.c
This is really hardware emulation, and as such it better be with
its little friends.
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Diffstat (limited to 'arch/arm/kvm')
-rw-r--r-- | arch/arm/kvm/arm.c | 45 | ||||
-rw-r--r-- | arch/arm/kvm/emulate.c | 45 |
2 files changed, 45 insertions, 45 deletions
diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c index 269900174102..6b776183ff93 100644 --- a/arch/arm/kvm/arm.c +++ b/arch/arm/kvm/arm.c | |||
@@ -44,7 +44,6 @@ | |||
44 | #include <asm/kvm_emulate.h> | 44 | #include <asm/kvm_emulate.h> |
45 | #include <asm/kvm_coproc.h> | 45 | #include <asm/kvm_coproc.h> |
46 | #include <asm/kvm_psci.h> | 46 | #include <asm/kvm_psci.h> |
47 | #include <asm/opcodes.h> | ||
48 | 47 | ||
49 | #ifdef REQUIRES_VIRT | 48 | #ifdef REQUIRES_VIRT |
50 | __asm__(".arch_extension virt"); | 49 | __asm__(".arch_extension virt"); |
@@ -546,50 +545,6 @@ static exit_handle_fn arm_exit_handlers[] = { | |||
546 | }; | 545 | }; |
547 | 546 | ||
548 | /* | 547 | /* |
549 | * A conditional instruction is allowed to trap, even though it | ||
550 | * wouldn't be executed. So let's re-implement the hardware, in | ||
551 | * software! | ||
552 | */ | ||
553 | static bool kvm_condition_valid(struct kvm_vcpu *vcpu) | ||
554 | { | ||
555 | unsigned long cpsr, cond, insn; | ||
556 | |||
557 | /* | ||
558 | * Exception Code 0 can only happen if we set HCR.TGE to 1, to | ||
559 | * catch undefined instructions, and then we won't get past | ||
560 | * the arm_exit_handlers test anyway. | ||
561 | */ | ||
562 | BUG_ON(!kvm_vcpu_trap_get_class(vcpu)); | ||
563 | |||
564 | /* Top two bits non-zero? Unconditional. */ | ||
565 | if (kvm_vcpu_get_hsr(vcpu) >> 30) | ||
566 | return true; | ||
567 | |||
568 | cpsr = *vcpu_cpsr(vcpu); | ||
569 | |||
570 | /* Is condition field valid? */ | ||
571 | if ((kvm_vcpu_get_hsr(vcpu) & HSR_CV) >> HSR_CV_SHIFT) | ||
572 | cond = (kvm_vcpu_get_hsr(vcpu) & HSR_COND) >> HSR_COND_SHIFT; | ||
573 | else { | ||
574 | /* This can happen in Thumb mode: examine IT state. */ | ||
575 | unsigned long it; | ||
576 | |||
577 | it = ((cpsr >> 8) & 0xFC) | ((cpsr >> 25) & 0x3); | ||
578 | |||
579 | /* it == 0 => unconditional. */ | ||
580 | if (it == 0) | ||
581 | return true; | ||
582 | |||
583 | /* The cond for this insn works out as the top 4 bits. */ | ||
584 | cond = (it >> 4); | ||
585 | } | ||
586 | |||
587 | /* Shift makes it look like an ARM-mode instruction */ | ||
588 | insn = cond << 28; | ||
589 | return arm_check_condition(insn, cpsr) != ARM_OPCODE_CONDTEST_FAIL; | ||
590 | } | ||
591 | |||
592 | /* | ||
593 | * Return > 0 to return to guest, < 0 on error, 0 (and set exit_reason) on | 548 | * Return > 0 to return to guest, < 0 on error, 0 (and set exit_reason) on |
594 | * proper exit to QEMU. | 549 | * proper exit to QEMU. |
595 | */ | 550 | */ |
diff --git a/arch/arm/kvm/emulate.c b/arch/arm/kvm/emulate.c index d3094eb4ade6..04dbac6bdf4d 100644 --- a/arch/arm/kvm/emulate.c +++ b/arch/arm/kvm/emulate.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <linux/kvm_host.h> | 20 | #include <linux/kvm_host.h> |
21 | #include <asm/kvm_arm.h> | 21 | #include <asm/kvm_arm.h> |
22 | #include <asm/kvm_emulate.h> | 22 | #include <asm/kvm_emulate.h> |
23 | #include <asm/opcodes.h> | ||
23 | #include <trace/events/kvm.h> | 24 | #include <trace/events/kvm.h> |
24 | 25 | ||
25 | #include "trace.h" | 26 | #include "trace.h" |
@@ -176,6 +177,50 @@ int kvm_handle_wfi(struct kvm_vcpu *vcpu, struct kvm_run *run) | |||
176 | return 1; | 177 | return 1; |
177 | } | 178 | } |
178 | 179 | ||
180 | /* | ||
181 | * A conditional instruction is allowed to trap, even though it | ||
182 | * wouldn't be executed. So let's re-implement the hardware, in | ||
183 | * software! | ||
184 | */ | ||
185 | bool kvm_condition_valid(struct kvm_vcpu *vcpu) | ||
186 | { | ||
187 | unsigned long cpsr, cond, insn; | ||
188 | |||
189 | /* | ||
190 | * Exception Code 0 can only happen if we set HCR.TGE to 1, to | ||
191 | * catch undefined instructions, and then we won't get past | ||
192 | * the arm_exit_handlers test anyway. | ||
193 | */ | ||
194 | BUG_ON(!kvm_vcpu_trap_get_class(vcpu)); | ||
195 | |||
196 | /* Top two bits non-zero? Unconditional. */ | ||
197 | if (kvm_vcpu_get_hsr(vcpu) >> 30) | ||
198 | return true; | ||
199 | |||
200 | cpsr = *vcpu_cpsr(vcpu); | ||
201 | |||
202 | /* Is condition field valid? */ | ||
203 | if ((kvm_vcpu_get_hsr(vcpu) & HSR_CV) >> HSR_CV_SHIFT) | ||
204 | cond = (kvm_vcpu_get_hsr(vcpu) & HSR_COND) >> HSR_COND_SHIFT; | ||
205 | else { | ||
206 | /* This can happen in Thumb mode: examine IT state. */ | ||
207 | unsigned long it; | ||
208 | |||
209 | it = ((cpsr >> 8) & 0xFC) | ((cpsr >> 25) & 0x3); | ||
210 | |||
211 | /* it == 0 => unconditional. */ | ||
212 | if (it == 0) | ||
213 | return true; | ||
214 | |||
215 | /* The cond for this insn works out as the top 4 bits. */ | ||
216 | cond = (it >> 4); | ||
217 | } | ||
218 | |||
219 | /* Shift makes it look like an ARM-mode instruction */ | ||
220 | insn = cond << 28; | ||
221 | return arm_check_condition(insn, cpsr) != ARM_OPCODE_CONDTEST_FAIL; | ||
222 | } | ||
223 | |||
179 | /** | 224 | /** |
180 | * adjust_itstate - adjust ITSTATE when emulating instructions in IT-block | 225 | * adjust_itstate - adjust ITSTATE when emulating instructions in IT-block |
181 | * @vcpu: The VCPU pointer | 226 | * @vcpu: The VCPU pointer |