aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/kvm/book3s_rmhandlers.S
diff options
context:
space:
mode:
authorAlexander Graf <agraf@suse.de>2010-04-15 18:11:32 -0400
committerAvi Kivity <avi@redhat.com>2010-05-17 05:18:14 -0400
commit2191d657c9eaa4c444c33e014199ed9de1ac339d (patch)
tree091ac64b7ed2962ad9482660a58efa3532d4dcb7 /arch/powerpc/kvm/book3s_rmhandlers.S
parent77a1a715707d0f60ce0cfbe44070527a0a561f01 (diff)
KVM: PPC: Name generic 64-bit code generic
We have quite some code that can be used by Book3S_32 and Book3S_64 alike, so let's call it "Book3S" instead of "Book3S_64", so we can later on use it from the 32 bit port too. Signed-off-by: Alexander Graf <agraf@suse.de> Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch/powerpc/kvm/book3s_rmhandlers.S')
-rw-r--r--arch/powerpc/kvm/book3s_rmhandlers.S194
1 files changed, 194 insertions, 0 deletions
diff --git a/arch/powerpc/kvm/book3s_rmhandlers.S b/arch/powerpc/kvm/book3s_rmhandlers.S
new file mode 100644
index 000000000000..d89e315615bc
--- /dev/null
+++ b/arch/powerpc/kvm/book3s_rmhandlers.S
@@ -0,0 +1,194 @@
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License, version 2, as
4 * published by the Free Software Foundation.
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * You should have received a copy of the GNU General Public License
12 * along with this program; if not, write to the Free Software
13 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
14 *
15 * Copyright SUSE Linux Products GmbH 2009
16 *
17 * Authors: Alexander Graf <agraf@suse.de>
18 */
19
20#include <asm/ppc_asm.h>
21#include <asm/kvm_asm.h>
22#include <asm/reg.h>
23#include <asm/page.h>
24#include <asm/asm-offsets.h>
25#include <asm/exception-64s.h>
26
27/*****************************************************************************
28 * *
29 * Real Mode handlers that need to be in low physical memory *
30 * *
31 ****************************************************************************/
32
33
34.macro INTERRUPT_TRAMPOLINE intno
35
36.global kvmppc_trampoline_\intno
37kvmppc_trampoline_\intno:
38
39 mtspr SPRN_SPRG_SCRATCH0, r13 /* Save r13 */
40
41 /*
42 * First thing to do is to find out if we're coming
43 * from a KVM guest or a Linux process.
44 *
45 * To distinguish, we check a magic byte in the PACA
46 */
47 mfspr r13, SPRN_SPRG_PACA /* r13 = PACA */
48 std r12, PACA_KVM_SCRATCH0(r13)
49 mfcr r12
50 stw r12, PACA_KVM_SCRATCH1(r13)
51 lbz r12, PACA_KVM_IN_GUEST(r13)
52 cmpwi r12, KVM_GUEST_MODE_NONE
53 bne ..kvmppc_handler_hasmagic_\intno
54 /* No KVM guest? Then jump back to the Linux handler! */
55 lwz r12, PACA_KVM_SCRATCH1(r13)
56 mtcr r12
57 ld r12, PACA_KVM_SCRATCH0(r13)
58 mfspr r13, SPRN_SPRG_SCRATCH0 /* r13 = original r13 */
59 b kvmppc_resume_\intno /* Get back original handler */
60
61 /* Now we know we're handling a KVM guest */
62..kvmppc_handler_hasmagic_\intno:
63
64 /* Should we just skip the faulting instruction? */
65 cmpwi r12, KVM_GUEST_MODE_SKIP
66 beq kvmppc_handler_skip_ins
67
68 /* Let's store which interrupt we're handling */
69 li r12, \intno
70
71 /* Jump into the SLB exit code that goes to the highmem handler */
72 b kvmppc_handler_trampoline_exit
73
74.endm
75
76INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_SYSTEM_RESET
77INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_MACHINE_CHECK
78INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DATA_STORAGE
79INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DATA_SEGMENT
80INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_INST_STORAGE
81INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_INST_SEGMENT
82INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_EXTERNAL
83INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_ALIGNMENT
84INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_PROGRAM
85INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_FP_UNAVAIL
86INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DECREMENTER
87INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_SYSCALL
88INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_TRACE
89INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_PERFMON
90INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_ALTIVEC
91INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_VSX
92
93/*
94 * Bring us back to the faulting code, but skip the
95 * faulting instruction.
96 *
97 * This is a generic exit path from the interrupt
98 * trampolines above.
99 *
100 * Input Registers:
101 *
102 * R12 = free
103 * R13 = PACA
104 * PACA.KVM.SCRATCH0 = guest R12
105 * PACA.KVM.SCRATCH1 = guest CR
106 * SPRG_SCRATCH0 = guest R13
107 *
108 */
109kvmppc_handler_skip_ins:
110
111 /* Patch the IP to the next instruction */
112 mfsrr0 r12
113 addi r12, r12, 4
114 mtsrr0 r12
115
116 /* Clean up all state */
117 lwz r12, PACA_KVM_SCRATCH1(r13)
118 mtcr r12
119 ld r12, PACA_KVM_SCRATCH0(r13)
120 mfspr r13, SPRN_SPRG_SCRATCH0
121
122 /* And get back into the code */
123 RFI
124
125/*
126 * This trampoline brings us back to a real mode handler
127 *
128 * Input Registers:
129 *
130 * R5 = SRR0
131 * R6 = SRR1
132 * LR = real-mode IP
133 *
134 */
135.global kvmppc_handler_lowmem_trampoline
136kvmppc_handler_lowmem_trampoline:
137
138 mtsrr0 r5
139 mtsrr1 r6
140 blr
141kvmppc_handler_lowmem_trampoline_end:
142
143/*
144 * Call a function in real mode
145 *
146 * Input Registers:
147 *
148 * R3 = function
149 * R4 = MSR
150 * R5 = CTR
151 *
152 */
153_GLOBAL(kvmppc_rmcall)
154 mtmsr r4 /* Disable relocation, so mtsrr
155 doesn't get interrupted */
156 mtctr r5
157 mtsrr0 r3
158 mtsrr1 r4
159 RFI
160
161/*
162 * Activate current's external feature (FPU/Altivec/VSX)
163 */
164#define define_load_up(what) \
165 \
166_GLOBAL(kvmppc_load_up_ ## what); \
167 stdu r1, -INT_FRAME_SIZE(r1); \
168 mflr r3; \
169 std r3, _LINK(r1); \
170 \
171 bl .load_up_ ## what; \
172 \
173 ld r3, _LINK(r1); \
174 mtlr r3; \
175 addi r1, r1, INT_FRAME_SIZE; \
176 blr
177
178define_load_up(fpu)
179#ifdef CONFIG_ALTIVEC
180define_load_up(altivec)
181#endif
182#ifdef CONFIG_VSX
183define_load_up(vsx)
184#endif
185
186.global kvmppc_trampoline_lowmem
187kvmppc_trampoline_lowmem:
188 .long kvmppc_handler_lowmem_trampoline - _stext
189
190.global kvmppc_trampoline_enter
191kvmppc_trampoline_enter:
192 .long kvmppc_handler_trampoline_enter - _stext
193
194#include "book3s_64_slb.S"