blob: 532afaf19841918e8b4efbb83b860d7b482adc6f [file] [log] [blame]
Paul Mackerrasde56a942011-06-29 00:21:34 +00001/*
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 2011 Paul Mackerras, IBM Corp. <paulus@au1.ibm.com>
16 *
17 * Derived from book3s_interrupts.S, which is:
18 * Copyright SUSE Linux Products GmbH 2009
19 *
20 * Authors: Alexander Graf <agraf@suse.de>
21 */
22
23#include <asm/ppc_asm.h>
24#include <asm/kvm_asm.h>
25#include <asm/reg.h>
26#include <asm/page.h>
27#include <asm/asm-offsets.h>
28#include <asm/exception-64s.h>
29#include <asm/ppc-opcode.h>
30
31/*****************************************************************************
32 * *
33 * Guest entry / exit code that is in kernel module memory (vmalloc) *
34 * *
35 ****************************************************************************/
36
37/* Registers:
38 * r4: vcpu pointer
39 */
40_GLOBAL(__kvmppc_vcore_entry)
41
42 /* Write correct stack frame */
43 mflr r0
44 std r0,PPC_LR_STKOFF(r1)
45
46 /* Save host state to the stack */
47 stdu r1, -SWITCH_FRAME_SIZE(r1)
48
49 /* Save non-volatile registers (r14 - r31) */
50 SAVE_NVGPRS(r1)
51
52 /* Save host DSCR */
53 mfspr r3, SPRN_DSCR
54 std r3, HSTATE_DSCR(r13)
55
56 /* Save host DABR */
57 mfspr r3, SPRN_DABR
58 std r3, HSTATE_DABR(r13)
59
60 /* Hard-disable interrupts */
61 mfmsr r10
62 std r10, HSTATE_HOST_MSR(r13)
63 rldicl r10,r10,48,1
64 rotldi r10,r10,16
65 mtmsrd r10,1
66
67 /* Save host PMU registers and load guest PMU registers */
68 /* R4 is live here (vcpu pointer) but not r3 or r5 */
69 li r3, 1
70 sldi r3, r3, 31 /* MMCR0_FC (freeze counters) bit */
71 mfspr r7, SPRN_MMCR0 /* save MMCR0 */
72 mtspr SPRN_MMCR0, r3 /* freeze all counters, disable interrupts */
73 isync
74 ld r3, PACALPPACAPTR(r13) /* is the host using the PMU? */
75 lbz r5, LPPACA_PMCINUSE(r3)
76 cmpwi r5, 0
77 beq 31f /* skip if not */
78 mfspr r5, SPRN_MMCR1
79 mfspr r6, SPRN_MMCRA
80 std r7, HSTATE_MMCR(r13)
81 std r5, HSTATE_MMCR + 8(r13)
82 std r6, HSTATE_MMCR + 16(r13)
83 mfspr r3, SPRN_PMC1
84 mfspr r5, SPRN_PMC2
85 mfspr r6, SPRN_PMC3
86 mfspr r7, SPRN_PMC4
87 mfspr r8, SPRN_PMC5
88 mfspr r9, SPRN_PMC6
89 stw r3, HSTATE_PMC(r13)
90 stw r5, HSTATE_PMC + 4(r13)
91 stw r6, HSTATE_PMC + 8(r13)
92 stw r7, HSTATE_PMC + 12(r13)
93 stw r8, HSTATE_PMC + 16(r13)
94 stw r9, HSTATE_PMC + 20(r13)
9531:
96
97 /*
98 * Put whatever is in the decrementer into the
99 * hypervisor decrementer.
100 */
101 mfspr r8,SPRN_DEC
102 mftb r7
103 mtspr SPRN_HDEC,r8
104 extsw r8,r8
105 add r8,r8,r7
106 std r8,HSTATE_DECEXP(r13)
107
108 /* Jump to partition switch code */
109 bl .kvmppc_hv_entry_trampoline
110 nop
111
112/*
113 * We return here in virtual mode after the guest exits
114 * with something that we can't handle in real mode.
115 * Interrupts are enabled again at this point.
116 */
117
118.global kvmppc_handler_highmem
119kvmppc_handler_highmem:
120
121 /*
122 * Register usage at this point:
123 *
124 * R1 = host R1
125 * R2 = host R2
126 * R12 = exit handler id
127 * R13 = PACA
128 */
129
130 /* Restore non-volatile host registers (r14 - r31) */
131 REST_NVGPRS(r1)
132
133 addi r1, r1, SWITCH_FRAME_SIZE
134 ld r0, PPC_LR_STKOFF(r1)
135 mtlr r0
136 blr