Marc Zyngier | 33280b4 | 2016-01-05 18:38:09 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Original code: |
| 3 | * Copyright (C) 2012 - Virtual Open Systems and Columbia University |
| 4 | * Author: Christoffer Dall <c.dall@virtualopensystems.com> |
| 5 | * |
| 6 | * Mostly rewritten in C by Marc Zyngier <marc.zyngier@arm.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | */ |
| 20 | |
Marc Zyngier | f1c9cad | 2016-01-28 14:31:37 +0000 | [diff] [blame] | 21 | #include <asm/kvm_hyp.h> |
Marc Zyngier | 33280b4 | 2016-01-05 18:38:09 +0000 | [diff] [blame] | 22 | |
Arnd Bergmann | 67870eb | 2018-02-02 16:07:34 +0100 | [diff] [blame] | 23 | /* |
| 24 | * gcc before 4.9 doesn't understand -march=armv7ve, so we have to |
| 25 | * trick the assembler. |
| 26 | */ |
Marc Zyngier | 33280b4 | 2016-01-05 18:38:09 +0000 | [diff] [blame] | 27 | __asm__(".arch_extension virt"); |
| 28 | |
| 29 | void __hyp_text __banked_save_state(struct kvm_cpu_context *ctxt) |
| 30 | { |
| 31 | ctxt->gp_regs.usr_regs.ARM_sp = read_special(SP_usr); |
| 32 | ctxt->gp_regs.usr_regs.ARM_pc = read_special(ELR_hyp); |
| 33 | ctxt->gp_regs.usr_regs.ARM_cpsr = read_special(SPSR); |
| 34 | ctxt->gp_regs.KVM_ARM_SVC_sp = read_special(SP_svc); |
| 35 | ctxt->gp_regs.KVM_ARM_SVC_lr = read_special(LR_svc); |
| 36 | ctxt->gp_regs.KVM_ARM_SVC_spsr = read_special(SPSR_svc); |
| 37 | ctxt->gp_regs.KVM_ARM_ABT_sp = read_special(SP_abt); |
| 38 | ctxt->gp_regs.KVM_ARM_ABT_lr = read_special(LR_abt); |
| 39 | ctxt->gp_regs.KVM_ARM_ABT_spsr = read_special(SPSR_abt); |
| 40 | ctxt->gp_regs.KVM_ARM_UND_sp = read_special(SP_und); |
| 41 | ctxt->gp_regs.KVM_ARM_UND_lr = read_special(LR_und); |
| 42 | ctxt->gp_regs.KVM_ARM_UND_spsr = read_special(SPSR_und); |
| 43 | ctxt->gp_regs.KVM_ARM_IRQ_sp = read_special(SP_irq); |
| 44 | ctxt->gp_regs.KVM_ARM_IRQ_lr = read_special(LR_irq); |
| 45 | ctxt->gp_regs.KVM_ARM_IRQ_spsr = read_special(SPSR_irq); |
| 46 | ctxt->gp_regs.KVM_ARM_FIQ_r8 = read_special(R8_fiq); |
| 47 | ctxt->gp_regs.KVM_ARM_FIQ_r9 = read_special(R9_fiq); |
| 48 | ctxt->gp_regs.KVM_ARM_FIQ_r10 = read_special(R10_fiq); |
| 49 | ctxt->gp_regs.KVM_ARM_FIQ_fp = read_special(R11_fiq); |
| 50 | ctxt->gp_regs.KVM_ARM_FIQ_ip = read_special(R12_fiq); |
| 51 | ctxt->gp_regs.KVM_ARM_FIQ_sp = read_special(SP_fiq); |
| 52 | ctxt->gp_regs.KVM_ARM_FIQ_lr = read_special(LR_fiq); |
| 53 | ctxt->gp_regs.KVM_ARM_FIQ_spsr = read_special(SPSR_fiq); |
| 54 | } |
| 55 | |
| 56 | void __hyp_text __banked_restore_state(struct kvm_cpu_context *ctxt) |
| 57 | { |
| 58 | write_special(ctxt->gp_regs.usr_regs.ARM_sp, SP_usr); |
| 59 | write_special(ctxt->gp_regs.usr_regs.ARM_pc, ELR_hyp); |
| 60 | write_special(ctxt->gp_regs.usr_regs.ARM_cpsr, SPSR_cxsf); |
| 61 | write_special(ctxt->gp_regs.KVM_ARM_SVC_sp, SP_svc); |
| 62 | write_special(ctxt->gp_regs.KVM_ARM_SVC_lr, LR_svc); |
| 63 | write_special(ctxt->gp_regs.KVM_ARM_SVC_spsr, SPSR_svc); |
| 64 | write_special(ctxt->gp_regs.KVM_ARM_ABT_sp, SP_abt); |
| 65 | write_special(ctxt->gp_regs.KVM_ARM_ABT_lr, LR_abt); |
| 66 | write_special(ctxt->gp_regs.KVM_ARM_ABT_spsr, SPSR_abt); |
| 67 | write_special(ctxt->gp_regs.KVM_ARM_UND_sp, SP_und); |
| 68 | write_special(ctxt->gp_regs.KVM_ARM_UND_lr, LR_und); |
| 69 | write_special(ctxt->gp_regs.KVM_ARM_UND_spsr, SPSR_und); |
| 70 | write_special(ctxt->gp_regs.KVM_ARM_IRQ_sp, SP_irq); |
| 71 | write_special(ctxt->gp_regs.KVM_ARM_IRQ_lr, LR_irq); |
| 72 | write_special(ctxt->gp_regs.KVM_ARM_IRQ_spsr, SPSR_irq); |
| 73 | write_special(ctxt->gp_regs.KVM_ARM_FIQ_r8, R8_fiq); |
| 74 | write_special(ctxt->gp_regs.KVM_ARM_FIQ_r9, R9_fiq); |
| 75 | write_special(ctxt->gp_regs.KVM_ARM_FIQ_r10, R10_fiq); |
| 76 | write_special(ctxt->gp_regs.KVM_ARM_FIQ_fp, R11_fiq); |
| 77 | write_special(ctxt->gp_regs.KVM_ARM_FIQ_ip, R12_fiq); |
| 78 | write_special(ctxt->gp_regs.KVM_ARM_FIQ_sp, SP_fiq); |
| 79 | write_special(ctxt->gp_regs.KVM_ARM_FIQ_lr, LR_fiq); |
| 80 | write_special(ctxt->gp_regs.KVM_ARM_FIQ_spsr, SPSR_fiq); |
| 81 | } |