1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2016 - ARM Ltd
4 * Author: Marc Zyngier <marc.zyngier@arm.com>
7 #include <linux/linkage.h>
8 #include <asm/asm-offsets.h>
9 #include <asm/kvm_arm.h>
10 #include <asm/kvm_asm.h>
15 .pushsection .hyp.text, "ax"
17 #define USR_REGS_OFFSET (CPU_CTXT_GP_REGS + GP_REGS_USR)
19 /* int __guest_enter(struct kvm_vcpu *vcpu, struct kvm_cpu_context *host) */
22 add r1, r1, #(USR_REGS_OFFSET + S_R4)
24 str lr, [r1, #4] @ Skip SP_usr (already saved)
26 @ Restore guest registers
27 add r0, r0, #(VCPU_GUEST_CTXT + USR_REGS_OFFSET + S_R0)
33 ENDPROC(__guest_enter)
38 * guest r0, r1, r2 saved on the stack
43 add r2, r0, #(VCPU_GUEST_CTXT + USR_REGS_OFFSET + S_R3)
46 add r2, r0, #(VCPU_GUEST_CTXT + USR_REGS_OFFSET + S_R0)
47 pop {r3, r4, r5} @ r0, r1, r2
50 ldr r0, [r0, #VCPU_HOST_CTXT]
51 add r0, r0, #(USR_REGS_OFFSET + S_R4)
58 mrc p15, 4, r3, c5, c2, 0 @ HSR
61 * Force loads and stores to complete before unmasking aborts
62 * and forcing the delivery of the exception. This gives us a
63 * single instruction window, which the handler will try to
69 .global abort_guest_exit_start
70 abort_guest_exit_start:
74 .global abort_guest_exit_end
78 * If we took an abort, r0[31] will be set, and cmp will set
79 * the N bit in PSTATE.
84 mcrmi p15, 4, r3, c5, c2, 0 @ HSR
90 * If VFPv3 support is not available, then we will not switch the VFP
91 * registers; however cp10 and cp11 accesses will still trap and fallback
92 * to the regular coprocessor emulation code, which currently will
93 * inject an undefined exception to the guest.
96 ENTRY(__vfp_guest_restore)
99 @ NEON/VFP used. Turn on VFP access.
100 mrc p15, 4, r1, c1, c1, 2 @ HCPTR
101 bic r1, r1, #(HCPTR_TCP(10) | HCPTR_TCP(11))
102 mcr p15, 4, r1, c1, c1, 2 @ HCPTR
105 @ Switch VFP/NEON hardware state to the guest's
107 ldr r0, [r0, #VCPU_HOST_CTXT]
108 add r0, r0, #CPU_CTXT_VFP
110 add r0, r4, #(VCPU_GUEST_CTXT + CPU_CTXT_VFP)
111 bl __vfp_restore_state
117 ENDPROC(__vfp_guest_restore)