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_1; \
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 * PACA[PACA_EXMC + EX_R9] = guest R9
59 * PACA[PACA_EXMC + EX_R10] = guest R10
60 * PACA[PACA_EXMC + EX_R11] = guest R11
61 * PACA[PACA_EXMC + EX_R12] = guest R12
62 * PACA[PACA_EXMC + EX_R13] = guest R13
63 * PACA[PACA_EXMC + EX_CCR] = guest CR
64 * PACA[PACA_EXMC + EX_R3] = guest XER
70 mtspr SPRN_SPRG_SCRATCH0, r0
72 /* Remove LPAR shadow entries */
74 #if SLB_NUM_BOLTED == 3
76 ld r12, PACA_SLBSHADOWPTR(r13)
78 /* Save off the first entry so we can slbie it later */
79 ld r10, SHADOW_SLB_ESID(0)(r12)
80 ld r11, SHADOW_SLB_VSID(0)(r12)
82 /* Remove bolted entries */
88 #error unknown number of bolted entries
95 /* r0 = esid & ESID_MASK */
96 rldicr r10, r10, 0, 35
97 /* r0 |= CLASS_BIT(VSID) */
98 rldic r12, r11, 56 - 36, 36
104 /* Fill SLB with our shadow */
106 lbz r12, PACA_KVM_SLB_MAX(r13)
108 addi r12, r12, PACA_KVM_SLB
111 /* for (r11 = kvm_slb; r11 < kvm_slb + kvm_slb_size; r11+=slb_entry) */
119 rldicl. r0, r10, 37, 63
120 beq slb_loop_enter_skip
134 mfspr r0, SPRN_SPRG_SCRATCH0
136 ld r9, (PACA_EXMC+EX_R9)(r13)
137 ld r10, (PACA_EXMC+EX_R10)(r13)
138 ld r12, (PACA_EXMC+EX_R12)(r13)
140 lwz r11, (PACA_EXMC+EX_CCR)(r13)
143 ld r11, (PACA_EXMC+EX_R3)(r13)
146 ld r11, (PACA_EXMC+EX_R11)(r13)
147 ld r13, (PACA_EXMC+EX_R13)(r13)
150 kvmppc_handler_trampoline_enter_end:
154 /******************************************************************************
158 *****************************************************************************/
160 .global kvmppc_handler_trampoline_exit
161 kvmppc_handler_trampoline_exit:
163 /* Register usage at this point:
165 * SPRG_SCRATCH0 = guest R13
170 * R12 = exit handler id
172 * PACA.exmc.CCR = guest CR
173 * PACA.exmc.R9 = guest R1
174 * PACA.exmc.R10 = guest R10
175 * PACA.exmc.R11 = guest R11
176 * PACA.exmc.R12 = guest R12
177 * PACA.exmc.R13 = guest R2
183 std r0, (PACA_EXMC+EX_SRR0)(r13)
184 std r9, (PACA_EXMC+EX_R3)(r13)
185 std r10, (PACA_EXMC+EX_LR)(r13)
186 std r11, (PACA_EXMC+EX_DAR)(r13)
189 * In order for us to easily get the last instruction,
190 * we got the #vmexit at, we exploit the fact that the
191 * virtual layout is still the same here, so we can just
192 * ld from the guest's PC address
195 /* We only load the last instruction when it's safe */
196 cmpwi r12, BOOK3S_INTERRUPT_DATA_STORAGE
198 cmpwi r12, BOOK3S_INTERRUPT_PROGRAM
204 /* Save off the guest instruction we're at */
205 /* 1) enable paging for data */
207 ori r11, r9, MSR_DR /* Enable paging for data */
209 /* 2) fetch the instruction */
211 /* 3) disable paging again */
216 /* Restore bolted entries from the shadow and fix it along the way */
218 /* We don't store anything in entry 0, so we don't need to take care of it */
222 #if SLB_NUM_BOLTED == 3
224 ld r11, PACA_SLBSHADOWPTR(r13)
231 #error unknown number of bolted entries
236 /* Restore registers */
238 ld r11, (PACA_EXMC+EX_DAR)(r13)
239 ld r10, (PACA_EXMC+EX_LR)(r13)
240 ld r9, (PACA_EXMC+EX_R3)(r13)
243 stw r0, (PACA_EXMC+EX_LR)(r13)
245 /* Save DAR and DSISR before going to paged mode */
247 std r0, (PACA_EXMC+EX_DAR)(r13)
249 stw r0, (PACA_EXMC+EX_DSISR)(r13)
251 /* RFI into the highmem handler */
253 ori r0, r0, MSR_IR|MSR_DR|MSR_RI /* Enable paging */
255 ld r0, PACASAVEDMSR(r13) /* Highmem handler address */
258 mfspr r0, SPRN_SPRG_SCRATCH0
261 kvmppc_handler_trampoline_exit_end: