3 * Copyright (C) 2012 - Virtual Open Systems and Columbia University
4 * Author: Christoffer Dall <c.dall@virtualopensystems.com>
6 * Mostly rewritten in C by Marc Zyngier <marc.zyngier@arm.com>
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.
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.
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/>.
21 #include <asm/kvm_hyp.h>
23 __asm__(".arch_extension virt");
25 void __hyp_text
__banked_save_state(struct kvm_cpu_context
*ctxt
)
27 ctxt
->gp_regs
.usr_regs
.ARM_sp
= read_special(SP_usr
);
28 ctxt
->gp_regs
.usr_regs
.ARM_pc
= read_special(ELR_hyp
);
29 ctxt
->gp_regs
.usr_regs
.ARM_cpsr
= read_special(SPSR
);
30 ctxt
->gp_regs
.KVM_ARM_SVC_sp
= read_special(SP_svc
);
31 ctxt
->gp_regs
.KVM_ARM_SVC_lr
= read_special(LR_svc
);
32 ctxt
->gp_regs
.KVM_ARM_SVC_spsr
= read_special(SPSR_svc
);
33 ctxt
->gp_regs
.KVM_ARM_ABT_sp
= read_special(SP_abt
);
34 ctxt
->gp_regs
.KVM_ARM_ABT_lr
= read_special(LR_abt
);
35 ctxt
->gp_regs
.KVM_ARM_ABT_spsr
= read_special(SPSR_abt
);
36 ctxt
->gp_regs
.KVM_ARM_UND_sp
= read_special(SP_und
);
37 ctxt
->gp_regs
.KVM_ARM_UND_lr
= read_special(LR_und
);
38 ctxt
->gp_regs
.KVM_ARM_UND_spsr
= read_special(SPSR_und
);
39 ctxt
->gp_regs
.KVM_ARM_IRQ_sp
= read_special(SP_irq
);
40 ctxt
->gp_regs
.KVM_ARM_IRQ_lr
= read_special(LR_irq
);
41 ctxt
->gp_regs
.KVM_ARM_IRQ_spsr
= read_special(SPSR_irq
);
42 ctxt
->gp_regs
.KVM_ARM_FIQ_r8
= read_special(R8_fiq
);
43 ctxt
->gp_regs
.KVM_ARM_FIQ_r9
= read_special(R9_fiq
);
44 ctxt
->gp_regs
.KVM_ARM_FIQ_r10
= read_special(R10_fiq
);
45 ctxt
->gp_regs
.KVM_ARM_FIQ_fp
= read_special(R11_fiq
);
46 ctxt
->gp_regs
.KVM_ARM_FIQ_ip
= read_special(R12_fiq
);
47 ctxt
->gp_regs
.KVM_ARM_FIQ_sp
= read_special(SP_fiq
);
48 ctxt
->gp_regs
.KVM_ARM_FIQ_lr
= read_special(LR_fiq
);
49 ctxt
->gp_regs
.KVM_ARM_FIQ_spsr
= read_special(SPSR_fiq
);
52 void __hyp_text
__banked_restore_state(struct kvm_cpu_context
*ctxt
)
54 write_special(ctxt
->gp_regs
.usr_regs
.ARM_sp
, SP_usr
);
55 write_special(ctxt
->gp_regs
.usr_regs
.ARM_pc
, ELR_hyp
);
56 write_special(ctxt
->gp_regs
.usr_regs
.ARM_cpsr
, SPSR_cxsf
);
57 write_special(ctxt
->gp_regs
.KVM_ARM_SVC_sp
, SP_svc
);
58 write_special(ctxt
->gp_regs
.KVM_ARM_SVC_lr
, LR_svc
);
59 write_special(ctxt
->gp_regs
.KVM_ARM_SVC_spsr
, SPSR_svc
);
60 write_special(ctxt
->gp_regs
.KVM_ARM_ABT_sp
, SP_abt
);
61 write_special(ctxt
->gp_regs
.KVM_ARM_ABT_lr
, LR_abt
);
62 write_special(ctxt
->gp_regs
.KVM_ARM_ABT_spsr
, SPSR_abt
);
63 write_special(ctxt
->gp_regs
.KVM_ARM_UND_sp
, SP_und
);
64 write_special(ctxt
->gp_regs
.KVM_ARM_UND_lr
, LR_und
);
65 write_special(ctxt
->gp_regs
.KVM_ARM_UND_spsr
, SPSR_und
);
66 write_special(ctxt
->gp_regs
.KVM_ARM_IRQ_sp
, SP_irq
);
67 write_special(ctxt
->gp_regs
.KVM_ARM_IRQ_lr
, LR_irq
);
68 write_special(ctxt
->gp_regs
.KVM_ARM_IRQ_spsr
, SPSR_irq
);
69 write_special(ctxt
->gp_regs
.KVM_ARM_FIQ_r8
, R8_fiq
);
70 write_special(ctxt
->gp_regs
.KVM_ARM_FIQ_r9
, R9_fiq
);
71 write_special(ctxt
->gp_regs
.KVM_ARM_FIQ_r10
, R10_fiq
);
72 write_special(ctxt
->gp_regs
.KVM_ARM_FIQ_fp
, R11_fiq
);
73 write_special(ctxt
->gp_regs
.KVM_ARM_FIQ_ip
, R12_fiq
);
74 write_special(ctxt
->gp_regs
.KVM_ARM_FIQ_sp
, SP_fiq
);
75 write_special(ctxt
->gp_regs
.KVM_ARM_FIQ_lr
, LR_fiq
);
76 write_special(ctxt
->gp_regs
.KVM_ARM_FIQ_spsr
, SPSR_fiq
);