book3s_interrupts.S 5.0 KB
Newer Older
A
Alexander Graf 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License, version 2, as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 * Copyright SUSE Linux Products GmbH 2009
 *
 * Authors: Alexander Graf <agraf@suse.de>
 */

#include <asm/ppc_asm.h>
#include <asm/kvm_asm.h>
#include <asm/reg.h>
#include <asm/page.h>
#include <asm/asm-offsets.h>
#include <asm/exception-64s.h>

27
#if defined(CONFIG_PPC_BOOK3S_64)
A
Alexander Graf 已提交
28

29 30
#define ULONG_SIZE 		8
#define FUNC(name) 		GLUE(.,name)
A
Alexander Graf 已提交
31

32 33 34 35 36 37 38 39 40
#elif defined(CONFIG_PPC_BOOK3S_32)

#define ULONG_SIZE              4
#define FUNC(name)		name

#endif /* CONFIG_PPC_BOOK3S_XX */


#define VCPU_GPR(n)		(VCPU_GPRS + (n * ULONG_SIZE))
41
#define VCPU_LOAD_NVGPRS(vcpu) \
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
	PPC_LL	r14, VCPU_GPR(r14)(vcpu); \
	PPC_LL	r15, VCPU_GPR(r15)(vcpu); \
	PPC_LL	r16, VCPU_GPR(r16)(vcpu); \
	PPC_LL	r17, VCPU_GPR(r17)(vcpu); \
	PPC_LL	r18, VCPU_GPR(r18)(vcpu); \
	PPC_LL	r19, VCPU_GPR(r19)(vcpu); \
	PPC_LL	r20, VCPU_GPR(r20)(vcpu); \
	PPC_LL	r21, VCPU_GPR(r21)(vcpu); \
	PPC_LL	r22, VCPU_GPR(r22)(vcpu); \
	PPC_LL	r23, VCPU_GPR(r23)(vcpu); \
	PPC_LL	r24, VCPU_GPR(r24)(vcpu); \
	PPC_LL	r25, VCPU_GPR(r25)(vcpu); \
	PPC_LL	r26, VCPU_GPR(r26)(vcpu); \
	PPC_LL	r27, VCPU_GPR(r27)(vcpu); \
	PPC_LL	r28, VCPU_GPR(r28)(vcpu); \
	PPC_LL	r29, VCPU_GPR(r29)(vcpu); \
	PPC_LL	r30, VCPU_GPR(r30)(vcpu); \
	PPC_LL	r31, VCPU_GPR(r31)(vcpu); \
60

A
Alexander Graf 已提交
61 62 63 64 65 66 67 68 69 70
/*****************************************************************************
 *                                                                           *
 *     Guest entry / exit code that is in kernel module memory (highmem)     *
 *                                                                           *
 ****************************************************************************/

/* Registers:
 *  r3: kvm_run pointer
 *  r4: vcpu pointer
 */
71
_GLOBAL(__kvmppc_vcpu_run)
A
Alexander Graf 已提交
72 73 74

kvm_start_entry:
	/* Write correct stack frame */
75 76
	mflr	r0
	PPC_STL	r0,PPC_LR_STKOFF(r1)
A
Alexander Graf 已提交
77 78

	/* Save host state to the stack */
79
	PPC_STLU r1, -SWITCH_FRAME_SIZE(r1)
A
Alexander Graf 已提交
80 81 82 83 84 85 86

	/* Save r3 (kvm_run) and r4 (vcpu) */
	SAVE_2GPRS(3, r1)

	/* Save non-volatile registers (r14 - r31) */
	SAVE_NVGPRS(r1)

87 88 89 90
	/* Save CR */
	mfcr	r14
	stw	r14, _CCR(r1)

A
Alexander Graf 已提交
91
	/* Save LR */
92
	PPC_STL	r0, _LINK(r1)
93 94 95

	/* Load non-volatile guest state from the vcpu */
	VCPU_LOAD_NVGPRS(r4)
A
Alexander Graf 已提交
96

97
kvm_start_lightweight:
98

99 100
#ifdef CONFIG_PPC_BOOK3S_64
	PPC_LL	r3, VCPU_HFLAGS(r4)
101 102
	rldicl	r3, r3, 0, 63		/* r3 &= 1 */
	stb	r3, HSTATE_RESTORE_HID5(r13)
103 104
#endif /* CONFIG_PPC_BOOK3S_64 */

105
	PPC_LL	r4, VCPU_SHADOW_MSR(r4)	/* get shadow_msr */
106

107
	/* Jump to segment patching handler and into our guest */
108 109
	bl	FUNC(kvmppc_entry_trampoline)
	nop
A
Alexander Graf 已提交
110 111 112 113 114 115 116 117 118 119 120 121 122

/*
 * This is the handler in module memory. It gets jumped at from the
 * lowmem trampoline code, so it's basically the guest exit code.
 *
 */

.global kvmppc_handler_highmem
kvmppc_handler_highmem:

	/*
	 * Register usage at this point:
	 *
123 124 125 126 127
	 * R1       = host R1
	 * R2       = host R2
	 * R12      = exit handler id
	 * R13      = PACA
	 * SVCPU.*  = guest *
A
Alexander Graf 已提交
128 129 130
	 *
	 */

131
	/* R7 = vcpu */
132
	PPC_LL	r7, GPR4(r1)
A
Alexander Graf 已提交
133

134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
	PPC_STL	r14, VCPU_GPR(r14)(r7)
	PPC_STL	r15, VCPU_GPR(r15)(r7)
	PPC_STL	r16, VCPU_GPR(r16)(r7)
	PPC_STL	r17, VCPU_GPR(r17)(r7)
	PPC_STL	r18, VCPU_GPR(r18)(r7)
	PPC_STL	r19, VCPU_GPR(r19)(r7)
	PPC_STL	r20, VCPU_GPR(r20)(r7)
	PPC_STL	r21, VCPU_GPR(r21)(r7)
	PPC_STL	r22, VCPU_GPR(r22)(r7)
	PPC_STL	r23, VCPU_GPR(r23)(r7)
	PPC_STL	r24, VCPU_GPR(r24)(r7)
	PPC_STL	r25, VCPU_GPR(r25)(r7)
	PPC_STL	r26, VCPU_GPR(r26)(r7)
	PPC_STL	r27, VCPU_GPR(r27)(r7)
	PPC_STL	r28, VCPU_GPR(r28)(r7)
	PPC_STL	r29, VCPU_GPR(r29)(r7)
	PPC_STL	r30, VCPU_GPR(r30)(r7)
	PPC_STL	r31, VCPU_GPR(r31)(r7)
A
Alexander Graf 已提交
152

153
	/* Pass the exit number as 3rd argument to kvmppc_handle_exit */
154
	mr	r5, r12
155

A
Alexander Graf 已提交
156 157
	/* Restore r3 (kvm_run) and r4 (vcpu) */
	REST_2GPRS(3, r1)
158
	bl	FUNC(kvmppc_handle_exit)
A
Alexander Graf 已提交
159

160
	/* If RESUME_GUEST, get back in the loop */
A
Alexander Graf 已提交
161
	cmpwi	r3, RESUME_GUEST
162
	beq	kvm_loop_lightweight
A
Alexander Graf 已提交
163

164 165
	cmpwi	r3, RESUME_GUEST_NV
	beq	kvm_loop_heavyweight
A
Alexander Graf 已提交
166

167
kvm_exit_loop:
A
Alexander Graf 已提交
168

169
	PPC_LL	r4, _LINK(r1)
A
Alexander Graf 已提交
170 171
	mtlr	r4

172 173 174
	lwz	r14, _CCR(r1)
	mtcr	r14

175 176 177 178 179 180 181
	/* Restore non-volatile host registers (r14 - r31) */
	REST_NVGPRS(r1)

	addi    r1, r1, SWITCH_FRAME_SIZE
	blr

kvm_loop_heavyweight:
A
Alexander Graf 已提交
182

183 184
	PPC_LL	r4, _LINK(r1)
	PPC_STL r4, (PPC_LR_STKOFF + SWITCH_FRAME_SIZE)(r1)
185 186

	/* Load vcpu and cpu_run */
A
Alexander Graf 已提交
187 188
	REST_2GPRS(3, r1)

189 190
	/* Load non-volatile guest state from the vcpu */
	VCPU_LOAD_NVGPRS(r4)
A
Alexander Graf 已提交
191

192 193
	/* Jump back into the beginning of this function */
	b	kvm_start_lightweight
A
Alexander Graf 已提交
194

195
kvm_loop_lightweight:
A
Alexander Graf 已提交
196

197 198 199 200 201
	/* We'll need the vcpu pointer */
	REST_GPR(4, r1)

	/* Jump back into the beginning of this function */
	b	kvm_start_lightweight