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.
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.
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.
15 * Copyright SUSE Linux Products GmbH 2009
17 * Authors: Alexander Graf <agraf@suse.de>
20 #define SHADOW_SLB_ESID(num) (SLBSHADOW_SAVEAREA + (num * 0x10))
21 #define SHADOW_SLB_VSID(num) (SLBSHADOW_SAVEAREA + (num * 0x10) + 0x8)
22 #define UNBOLT_SLB_ENTRY(num) \
23 ld r9, SHADOW_SLB_ESID(num)(r12); \
24 /* Invalid? Skip. */; \
25 rldicl. r0, r9, 37, 63; \
26 beq slb_entry_skip_ ## num; \
27 xoris r9, r9, SLB_ESID_V@h; \
28 std r9, SHADOW_SLB_ESID(num)(r12); \
29 slb_entry_skip_ ## num:
31 #define REBOLT_SLB_ENTRY(num) \
32 ld r10, SHADOW_SLB_ESID(num)(r11); \
34 beq slb_exit_skip_ ## num; \
35 oris r10, r10, SLB_ESID_V@h; \
36 ld r9, SHADOW_SLB_VSID(num)(r11); \
38 std r10, SHADOW_SLB_ESID(num)(r11); \
39 slb_exit_skip_ ## num:
41 /******************************************************************************
45 *****************************************************************************/
47 .global kvmppc_handler_trampoline_enter
48 kvmppc_handler_trampoline_enter:
58 * all other GPRS = free
59 * PACA[KVM_CR] = guest CR
60 * PACA[KVM_XER] = guest XER
66 /* Remove LPAR shadow entries */
68 #if SLB_NUM_BOLTED == 3
70 ld r12, PACA_SLBSHADOWPTR(r13)
72 /* Save off the first entry so we can slbie it later */
73 ld r10, SHADOW_SLB_ESID(0)(r12)
74 ld r11, SHADOW_SLB_VSID(0)(r12)
76 /* Remove bolted entries */
82 #error unknown number of bolted entries
89 /* r0 = esid & ESID_MASK */
90 rldicr r10, r10, 0, 35
91 /* r0 |= CLASS_BIT(VSID) */
92 rldic r12, r11, 56 - 36, 36
98 /* Fill SLB with our shadow */
100 lbz r12, PACA_KVM_SLB_MAX(r13)
102 addi r12, r12, PACA_KVM_SLB
105 /* for (r11 = kvm_slb; r11 < kvm_slb + kvm_slb_size; r11+=slb_entry) */
113 rldicl. r0, r10, 37, 63
114 beq slb_loop_enter_skip
128 ld r0, (PACA_KVM_R0)(r13)
129 ld r1, (PACA_KVM_R1)(r13)
130 ld r2, (PACA_KVM_R2)(r13)
131 ld r3, (PACA_KVM_R3)(r13)
132 ld r4, (PACA_KVM_R4)(r13)
133 ld r5, (PACA_KVM_R5)(r13)
134 ld r6, (PACA_KVM_R6)(r13)
135 ld r7, (PACA_KVM_R7)(r13)
136 ld r8, (PACA_KVM_R8)(r13)
137 ld r9, (PACA_KVM_R9)(r13)
138 ld r10, (PACA_KVM_R10)(r13)
139 ld r12, (PACA_KVM_R12)(r13)
141 lwz r11, (PACA_KVM_CR)(r13)
144 ld r11, (PACA_KVM_XER)(r13)
147 ld r11, (PACA_KVM_R11)(r13)
148 ld r13, (PACA_KVM_R13)(r13)
151 kvmppc_handler_trampoline_enter_end:
155 /******************************************************************************
159 *****************************************************************************/
161 .global kvmppc_handler_trampoline_exit
162 kvmppc_handler_trampoline_exit:
164 /* Register usage at this point:
166 * SPRG_SCRATCH0 = guest R13
167 * R12 = exit handler id
169 * PACA.KVM.SCRATCH0 = guest R12
170 * PACA.KVM.SCRATCH1 = guest CR
176 std r0, PACA_KVM_R0(r13)
177 std r1, PACA_KVM_R1(r13)
178 std r2, PACA_KVM_R2(r13)
179 std r3, PACA_KVM_R3(r13)
180 std r4, PACA_KVM_R4(r13)
181 std r5, PACA_KVM_R5(r13)
182 std r6, PACA_KVM_R6(r13)
183 std r7, PACA_KVM_R7(r13)
184 std r8, PACA_KVM_R8(r13)
185 std r9, PACA_KVM_R9(r13)
186 std r10, PACA_KVM_R10(r13)
187 std r11, PACA_KVM_R11(r13)
189 /* Restore R1/R2 so we can handle faults */
190 ld r1, PACA_KVM_HOST_R1(r13)
191 ld r2, PACA_KVM_HOST_R2(r13)
193 /* Save guest PC and MSR in GPRs */
197 /* Get scratch'ed off registers */
198 mfspr r9, SPRN_SPRG_SCRATCH0
199 std r9, PACA_KVM_R13(r13)
201 ld r8, PACA_KVM_SCRATCH0(r13)
202 std r8, PACA_KVM_R12(r13)
204 lwz r7, PACA_KVM_SCRATCH1(r13)
205 stw r7, PACA_KVM_CR(r13)
207 /* Save more register state */
210 stw r6, PACA_KVM_XER(r13)
215 /* Unset guest state */
217 stb r9, PACA_KVM_IN_GUEST(r13)
220 * In order for us to easily get the last instruction,
221 * we got the #vmexit at, we exploit the fact that the
222 * virtual layout is still the same here, so we can just
223 * ld from the guest's PC address
226 /* We only load the last instruction when it's safe */
227 cmpwi r12, BOOK3S_INTERRUPT_DATA_STORAGE
229 cmpwi r12, BOOK3S_INTERRUPT_PROGRAM
235 /* Save off the guest instruction we're at */
236 /* 1) enable paging for data */
238 ori r11, r9, MSR_DR /* Enable paging for data */
240 /* 2) fetch the instruction */
241 /* XXX implement PACA_KVM_IN_GUEST=2 path to safely jump over this */
243 /* 3) disable paging again */
248 /* Restore bolted entries from the shadow and fix it along the way */
250 /* We don't store anything in entry 0, so we don't need to take care of it */
254 #if SLB_NUM_BOLTED == 3
256 ld r11, PACA_SLBSHADOWPTR(r13)
263 #error unknown number of bolted entries
268 /* Register usage at this point:
270 * R0 = guest last inst
277 * R12 = exit handler id
279 * PACA.KVM.* = guest *
283 /* RFI into the highmem handler */
285 ori r7, r7, MSR_IR|MSR_DR|MSR_RI /* Enable paging */
287 ld r8, PACA_KVM_VMHANDLER(r13) /* Highmem handler address */
291 kvmppc_handler_trampoline_exit_end: