2 * Copyright (C) 2016 - ARM Ltd
3 * Author: Marc Zyngier <marc.zyngier@arm.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include <linux/linkage.h>
19 #include <asm/asm-offsets.h>
20 #include <asm/kvm_arm.h>
25 .pushsection .hyp.text, "ax"
27 #define USR_REGS_OFFSET (CPU_CTXT_GP_REGS + GP_REGS_USR)
29 /* int __guest_enter(struct kvm_vcpu *vcpu, struct kvm_cpu_context *host) */
32 add r1, r1, #(USR_REGS_OFFSET + S_R4)
34 str lr, [r1, #4] @ Skip SP_usr (already saved)
36 @ Restore guest registers
37 add r0, r0, #(VCPU_GUEST_CTXT + USR_REGS_OFFSET + S_R0)
43 ENDPROC(__guest_enter)
48 * guest r0, r1, r2 saved on the stack
53 add r2, r0, #(VCPU_GUEST_CTXT + USR_REGS_OFFSET + S_R3)
56 add r2, r0, #(VCPU_GUEST_CTXT + USR_REGS_OFFSET + S_R0)
57 pop {r3, r4, r5} @ r0, r1, r2
60 ldr r0, [r0, #VCPU_HOST_CTXT]
61 add r0, r0, #(USR_REGS_OFFSET + S_R4)
70 * If VFPv3 support is not available, then we will not switch the VFP
71 * registers; however cp10 and cp11 accesses will still trap and fallback
72 * to the regular coprocessor emulation code, which currently will
73 * inject an undefined exception to the guest.
76 ENTRY(__vfp_guest_restore)
79 @ NEON/VFP used. Turn on VFP access.
80 mrc p15, 4, r1, c1, c1, 2 @ HCPTR
81 bic r1, r1, #(HCPTR_TCP(10) | HCPTR_TCP(11))
82 mcr p15, 4, r1, c1, c1, 2 @ HCPTR
85 @ Switch VFP/NEON hardware state to the guest's
87 ldr r0, [r0, #VCPU_HOST_CTXT]
88 add r0, r0, #CPU_CTXT_VFP
90 add r0, r4, #(VCPU_GUEST_CTXT + CPU_CTXT_VFP)
91 bl __vfp_restore_state
97 ENDPROC(__vfp_guest_restore)