root / target-s390x / kvm.c @ a88790a1
History | View | Annotate | Download (12 kB)
1 | 0e60a699 | Alexander Graf | /*
|
---|---|---|---|
2 | 0e60a699 | Alexander Graf | * QEMU S390x KVM implementation
|
3 | 0e60a699 | Alexander Graf | *
|
4 | 0e60a699 | Alexander Graf | * Copyright (c) 2009 Alexander Graf <agraf@suse.de>
|
5 | 0e60a699 | Alexander Graf | *
|
6 | 0e60a699 | Alexander Graf | * This library is free software; you can redistribute it and/or
|
7 | 0e60a699 | Alexander Graf | * modify it under the terms of the GNU Lesser General Public
|
8 | 0e60a699 | Alexander Graf | * License as published by the Free Software Foundation; either
|
9 | 0e60a699 | Alexander Graf | * version 2 of the License, or (at your option) any later version.
|
10 | 0e60a699 | Alexander Graf | *
|
11 | 0e60a699 | Alexander Graf | * This library is distributed in the hope that it will be useful,
|
12 | 0e60a699 | Alexander Graf | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 0e60a699 | Alexander Graf | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | 0e60a699 | Alexander Graf | * Lesser General Public License for more details.
|
15 | 0e60a699 | Alexander Graf | *
|
16 | 0e60a699 | Alexander Graf | * You should have received a copy of the GNU Lesser General Public
|
17 | 0e60a699 | Alexander Graf | * License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
18 | 0e60a699 | Alexander Graf | */
|
19 | 0e60a699 | Alexander Graf | |
20 | 0e60a699 | Alexander Graf | #include <sys/types.h> |
21 | 0e60a699 | Alexander Graf | #include <sys/ioctl.h> |
22 | 0e60a699 | Alexander Graf | #include <sys/mman.h> |
23 | 0e60a699 | Alexander Graf | |
24 | 0e60a699 | Alexander Graf | #include <linux/kvm.h> |
25 | 0e60a699 | Alexander Graf | #include <asm/ptrace.h> |
26 | 0e60a699 | Alexander Graf | |
27 | 0e60a699 | Alexander Graf | #include "qemu-common.h" |
28 | 0e60a699 | Alexander Graf | #include "qemu-timer.h" |
29 | 0e60a699 | Alexander Graf | #include "sysemu.h" |
30 | 0e60a699 | Alexander Graf | #include "kvm.h" |
31 | 0e60a699 | Alexander Graf | #include "cpu.h" |
32 | 0e60a699 | Alexander Graf | #include "device_tree.h" |
33 | 0e60a699 | Alexander Graf | |
34 | 0e60a699 | Alexander Graf | /* #define DEBUG_KVM */
|
35 | 0e60a699 | Alexander Graf | |
36 | 0e60a699 | Alexander Graf | #ifdef DEBUG_KVM
|
37 | 0e60a699 | Alexander Graf | #define dprintf(fmt, ...) \
|
38 | 0e60a699 | Alexander Graf | do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0) |
39 | 0e60a699 | Alexander Graf | #else
|
40 | 0e60a699 | Alexander Graf | #define dprintf(fmt, ...) \
|
41 | 0e60a699 | Alexander Graf | do { } while (0) |
42 | 0e60a699 | Alexander Graf | #endif
|
43 | 0e60a699 | Alexander Graf | |
44 | 0e60a699 | Alexander Graf | #define IPA0_DIAG 0x8300 |
45 | 0e60a699 | Alexander Graf | #define IPA0_SIGP 0xae00 |
46 | 0e60a699 | Alexander Graf | #define IPA0_PRIV 0xb200 |
47 | 0e60a699 | Alexander Graf | |
48 | 0e60a699 | Alexander Graf | #define PRIV_SCLP_CALL 0x20 |
49 | 0e60a699 | Alexander Graf | #define DIAG_KVM_HYPERCALL 0x500 |
50 | 0e60a699 | Alexander Graf | #define DIAG_KVM_BREAKPOINT 0x501 |
51 | 0e60a699 | Alexander Graf | |
52 | 0e60a699 | Alexander Graf | #define SCP_LENGTH 0x00 |
53 | 0e60a699 | Alexander Graf | #define SCP_FUNCTION_CODE 0x02 |
54 | 0e60a699 | Alexander Graf | #define SCP_CONTROL_MASK 0x03 |
55 | 0e60a699 | Alexander Graf | #define SCP_RESPONSE_CODE 0x06 |
56 | 0e60a699 | Alexander Graf | #define SCP_MEM_CODE 0x08 |
57 | 0e60a699 | Alexander Graf | #define SCP_INCREMENT 0x0a |
58 | 0e60a699 | Alexander Graf | |
59 | 0e60a699 | Alexander Graf | #define ICPT_INSTRUCTION 0x04 |
60 | 0e60a699 | Alexander Graf | #define ICPT_WAITPSW 0x1c |
61 | 0e60a699 | Alexander Graf | #define ICPT_SOFT_INTERCEPT 0x24 |
62 | 0e60a699 | Alexander Graf | #define ICPT_CPU_STOP 0x28 |
63 | 0e60a699 | Alexander Graf | #define ICPT_IO 0x40 |
64 | 0e60a699 | Alexander Graf | |
65 | 0e60a699 | Alexander Graf | #define SIGP_RESTART 0x06 |
66 | 0e60a699 | Alexander Graf | #define SIGP_INITIAL_CPU_RESET 0x0b |
67 | 0e60a699 | Alexander Graf | #define SIGP_STORE_STATUS_ADDR 0x0e |
68 | 0e60a699 | Alexander Graf | #define SIGP_SET_ARCH 0x12 |
69 | 0e60a699 | Alexander Graf | |
70 | 0e60a699 | Alexander Graf | #define SCLP_CMDW_READ_SCP_INFO 0x00020001 |
71 | 0e60a699 | Alexander Graf | #define SCLP_CMDW_READ_SCP_INFO_FORCED 0x00120001 |
72 | 0e60a699 | Alexander Graf | |
73 | 0e60a699 | Alexander Graf | int kvm_arch_init(KVMState *s, int smp_cpus) |
74 | 0e60a699 | Alexander Graf | { |
75 | 0e60a699 | Alexander Graf | return 0; |
76 | 0e60a699 | Alexander Graf | } |
77 | 0e60a699 | Alexander Graf | |
78 | 0e60a699 | Alexander Graf | int kvm_arch_init_vcpu(CPUState *env)
|
79 | 0e60a699 | Alexander Graf | { |
80 | 0e60a699 | Alexander Graf | int ret = 0; |
81 | 0e60a699 | Alexander Graf | |
82 | 0e60a699 | Alexander Graf | if (kvm_vcpu_ioctl(env, KVM_S390_INITIAL_RESET, NULL) < 0) { |
83 | 0e60a699 | Alexander Graf | perror("cannot init reset vcpu");
|
84 | 0e60a699 | Alexander Graf | } |
85 | 0e60a699 | Alexander Graf | |
86 | 0e60a699 | Alexander Graf | return ret;
|
87 | 0e60a699 | Alexander Graf | } |
88 | 0e60a699 | Alexander Graf | |
89 | 0e60a699 | Alexander Graf | void kvm_arch_reset_vcpu(CPUState *env)
|
90 | 0e60a699 | Alexander Graf | { |
91 | 0e60a699 | Alexander Graf | /* FIXME: add code to reset vcpu. */
|
92 | 0e60a699 | Alexander Graf | } |
93 | 0e60a699 | Alexander Graf | |
94 | ea375f9a | Jan Kiszka | int kvm_arch_put_registers(CPUState *env, int level) |
95 | 0e60a699 | Alexander Graf | { |
96 | 0e60a699 | Alexander Graf | struct kvm_regs regs;
|
97 | 0e60a699 | Alexander Graf | int ret;
|
98 | 0e60a699 | Alexander Graf | int i;
|
99 | 0e60a699 | Alexander Graf | |
100 | 0e60a699 | Alexander Graf | ret = kvm_vcpu_ioctl(env, KVM_GET_REGS, ®s); |
101 | 0e60a699 | Alexander Graf | if (ret < 0) { |
102 | 0e60a699 | Alexander Graf | return ret;
|
103 | 0e60a699 | Alexander Graf | } |
104 | 0e60a699 | Alexander Graf | |
105 | 0e60a699 | Alexander Graf | for (i = 0; i < 16; i++) { |
106 | 0e60a699 | Alexander Graf | regs.gprs[i] = env->regs[i]; |
107 | 0e60a699 | Alexander Graf | } |
108 | 0e60a699 | Alexander Graf | |
109 | 0e60a699 | Alexander Graf | ret = kvm_vcpu_ioctl(env, KVM_SET_REGS, ®s); |
110 | 0e60a699 | Alexander Graf | if (ret < 0) { |
111 | 0e60a699 | Alexander Graf | return ret;
|
112 | 0e60a699 | Alexander Graf | } |
113 | 0e60a699 | Alexander Graf | |
114 | 0e60a699 | Alexander Graf | env->kvm_run->psw_addr = env->psw.addr; |
115 | 0e60a699 | Alexander Graf | env->kvm_run->psw_mask = env->psw.mask; |
116 | 0e60a699 | Alexander Graf | |
117 | 0e60a699 | Alexander Graf | return ret;
|
118 | 0e60a699 | Alexander Graf | } |
119 | 0e60a699 | Alexander Graf | |
120 | 0e60a699 | Alexander Graf | int kvm_arch_get_registers(CPUState *env)
|
121 | 0e60a699 | Alexander Graf | { |
122 | 0e60a699 | Alexander Graf | uint32_t ret; |
123 | 0e60a699 | Alexander Graf | struct kvm_regs regs;
|
124 | 0e60a699 | Alexander Graf | int i;
|
125 | 0e60a699 | Alexander Graf | |
126 | 0e60a699 | Alexander Graf | ret = kvm_vcpu_ioctl(env, KVM_GET_REGS, ®s); |
127 | 0e60a699 | Alexander Graf | if (ret < 0) { |
128 | 0e60a699 | Alexander Graf | return ret;
|
129 | 0e60a699 | Alexander Graf | } |
130 | 0e60a699 | Alexander Graf | |
131 | 0e60a699 | Alexander Graf | for (i = 0; i < 16; i++) { |
132 | 0e60a699 | Alexander Graf | env->regs[i] = regs.gprs[i]; |
133 | 0e60a699 | Alexander Graf | } |
134 | 0e60a699 | Alexander Graf | |
135 | 0e60a699 | Alexander Graf | env->psw.addr = env->kvm_run->psw_addr; |
136 | 0e60a699 | Alexander Graf | env->psw.mask = env->kvm_run->psw_mask; |
137 | 0e60a699 | Alexander Graf | |
138 | 0e60a699 | Alexander Graf | return 0; |
139 | 0e60a699 | Alexander Graf | } |
140 | 0e60a699 | Alexander Graf | |
141 | 0e60a699 | Alexander Graf | int kvm_arch_insert_sw_breakpoint(CPUState *env, struct kvm_sw_breakpoint *bp) |
142 | 0e60a699 | Alexander Graf | { |
143 | 0e60a699 | Alexander Graf | static const uint8_t diag_501[] = {0x83, 0x24, 0x05, 0x01}; |
144 | 0e60a699 | Alexander Graf | |
145 | 0e60a699 | Alexander Graf | if (cpu_memory_rw_debug(env, bp->pc, (uint8_t *)&bp->saved_insn, 4, 0) || |
146 | 0e60a699 | Alexander Graf | cpu_memory_rw_debug(env, bp->pc, (uint8_t *)diag_501, 4, 1)) { |
147 | 0e60a699 | Alexander Graf | return -EINVAL;
|
148 | 0e60a699 | Alexander Graf | } |
149 | 0e60a699 | Alexander Graf | return 0; |
150 | 0e60a699 | Alexander Graf | } |
151 | 0e60a699 | Alexander Graf | |
152 | 0e60a699 | Alexander Graf | int kvm_arch_remove_sw_breakpoint(CPUState *env, struct kvm_sw_breakpoint *bp) |
153 | 0e60a699 | Alexander Graf | { |
154 | 0e60a699 | Alexander Graf | uint8_t t[4];
|
155 | 0e60a699 | Alexander Graf | static const uint8_t diag_501[] = {0x83, 0x24, 0x05, 0x01}; |
156 | 0e60a699 | Alexander Graf | |
157 | 0e60a699 | Alexander Graf | if (cpu_memory_rw_debug(env, bp->pc, t, 4, 0)) { |
158 | 0e60a699 | Alexander Graf | return -EINVAL;
|
159 | 0e60a699 | Alexander Graf | } else if (memcmp(t, diag_501, 4)) { |
160 | 0e60a699 | Alexander Graf | return -EINVAL;
|
161 | 0e60a699 | Alexander Graf | } else if (cpu_memory_rw_debug(env, bp->pc, (uint8_t *)&bp->saved_insn, 1, 1)) { |
162 | 0e60a699 | Alexander Graf | return -EINVAL;
|
163 | 0e60a699 | Alexander Graf | } |
164 | 0e60a699 | Alexander Graf | |
165 | 0e60a699 | Alexander Graf | return 0; |
166 | 0e60a699 | Alexander Graf | } |
167 | 0e60a699 | Alexander Graf | |
168 | 0e60a699 | Alexander Graf | int kvm_arch_pre_run(CPUState *env, struct kvm_run *run) |
169 | 0e60a699 | Alexander Graf | { |
170 | 0e60a699 | Alexander Graf | return 0; |
171 | 0e60a699 | Alexander Graf | } |
172 | 0e60a699 | Alexander Graf | |
173 | 0e60a699 | Alexander Graf | int kvm_arch_post_run(CPUState *env, struct kvm_run *run) |
174 | 0e60a699 | Alexander Graf | { |
175 | 0e60a699 | Alexander Graf | return 0; |
176 | 0e60a699 | Alexander Graf | } |
177 | 0e60a699 | Alexander Graf | |
178 | 0af691d7 | Marcelo Tosatti | int kvm_arch_process_irqchip_events(CPUState *env)
|
179 | 0af691d7 | Marcelo Tosatti | { |
180 | 0af691d7 | Marcelo Tosatti | return 0; |
181 | 0af691d7 | Marcelo Tosatti | } |
182 | 0af691d7 | Marcelo Tosatti | |
183 | 0e60a699 | Alexander Graf | static void kvm_s390_interrupt_internal(CPUState *env, int type, uint32_t parm, |
184 | 0e60a699 | Alexander Graf | uint64_t parm64, int vm)
|
185 | 0e60a699 | Alexander Graf | { |
186 | 0e60a699 | Alexander Graf | struct kvm_s390_interrupt kvmint;
|
187 | 0e60a699 | Alexander Graf | int r;
|
188 | 0e60a699 | Alexander Graf | |
189 | 0e60a699 | Alexander Graf | if (!env->kvm_state) {
|
190 | 0e60a699 | Alexander Graf | return;
|
191 | 0e60a699 | Alexander Graf | } |
192 | 0e60a699 | Alexander Graf | |
193 | 0e60a699 | Alexander Graf | env->halted = 0;
|
194 | ee0dc6d3 | Blue Swirl | env->exception_index = -1;
|
195 | 0e60a699 | Alexander Graf | |
196 | 0e60a699 | Alexander Graf | kvmint.type = type; |
197 | 0e60a699 | Alexander Graf | kvmint.parm = parm; |
198 | 0e60a699 | Alexander Graf | kvmint.parm64 = parm64; |
199 | 0e60a699 | Alexander Graf | |
200 | 0e60a699 | Alexander Graf | if (vm) {
|
201 | 0e60a699 | Alexander Graf | r = kvm_vm_ioctl(env->kvm_state, KVM_S390_INTERRUPT, &kvmint); |
202 | 0e60a699 | Alexander Graf | } else {
|
203 | 0e60a699 | Alexander Graf | r = kvm_vcpu_ioctl(env, KVM_S390_INTERRUPT, &kvmint); |
204 | 0e60a699 | Alexander Graf | } |
205 | 0e60a699 | Alexander Graf | |
206 | 0e60a699 | Alexander Graf | if (r < 0) { |
207 | 0e60a699 | Alexander Graf | fprintf(stderr, "KVM failed to inject interrupt\n");
|
208 | 0e60a699 | Alexander Graf | exit(1);
|
209 | 0e60a699 | Alexander Graf | } |
210 | 0e60a699 | Alexander Graf | } |
211 | 0e60a699 | Alexander Graf | |
212 | 0e60a699 | Alexander Graf | void kvm_s390_virtio_irq(CPUState *env, int config_change, uint64_t token) |
213 | 0e60a699 | Alexander Graf | { |
214 | 0e60a699 | Alexander Graf | kvm_s390_interrupt_internal(env, KVM_S390_INT_VIRTIO, config_change, |
215 | 0e60a699 | Alexander Graf | token, 1);
|
216 | 0e60a699 | Alexander Graf | } |
217 | 0e60a699 | Alexander Graf | |
218 | 0e60a699 | Alexander Graf | static void kvm_s390_interrupt(CPUState *env, int type, uint32_t code) |
219 | 0e60a699 | Alexander Graf | { |
220 | 0e60a699 | Alexander Graf | kvm_s390_interrupt_internal(env, type, code, 0, 0); |
221 | 0e60a699 | Alexander Graf | } |
222 | 0e60a699 | Alexander Graf | |
223 | 0e60a699 | Alexander Graf | static void enter_pgmcheck(CPUState *env, uint16_t code) |
224 | 0e60a699 | Alexander Graf | { |
225 | 0e60a699 | Alexander Graf | kvm_s390_interrupt(env, KVM_S390_PROGRAM_INT, code); |
226 | 0e60a699 | Alexander Graf | } |
227 | 0e60a699 | Alexander Graf | |
228 | 0e60a699 | Alexander Graf | static void setcc(CPUState *env, uint64_t cc) |
229 | 0e60a699 | Alexander Graf | { |
230 | 0e60a699 | Alexander Graf | env->kvm_run->psw_mask &= ~(3ul << 44); |
231 | 0e60a699 | Alexander Graf | env->kvm_run->psw_mask |= (cc & 3) << 44; |
232 | 0e60a699 | Alexander Graf | |
233 | 0e60a699 | Alexander Graf | env->psw.mask &= ~(3ul << 44); |
234 | 0e60a699 | Alexander Graf | env->psw.mask |= (cc & 3) << 44; |
235 | 0e60a699 | Alexander Graf | } |
236 | 0e60a699 | Alexander Graf | |
237 | 0e60a699 | Alexander Graf | static int sclp_service_call(CPUState *env, struct kvm_run *run, uint16_t ipbh0) |
238 | 0e60a699 | Alexander Graf | { |
239 | 0e60a699 | Alexander Graf | uint32_t sccb; |
240 | 0e60a699 | Alexander Graf | uint64_t code; |
241 | 0e60a699 | Alexander Graf | int r = 0; |
242 | 0e60a699 | Alexander Graf | |
243 | 0e60a699 | Alexander Graf | cpu_synchronize_state(env); |
244 | 0e60a699 | Alexander Graf | sccb = env->regs[ipbh0 & 0xf];
|
245 | 0e60a699 | Alexander Graf | code = env->regs[(ipbh0 & 0xf0) >> 4]; |
246 | 0e60a699 | Alexander Graf | |
247 | 0e60a699 | Alexander Graf | dprintf("sclp(0x%x, 0x%lx)\n", sccb, code);
|
248 | 0e60a699 | Alexander Graf | |
249 | 0e60a699 | Alexander Graf | if (sccb & ~0x7ffffff8ul) { |
250 | 0e60a699 | Alexander Graf | fprintf(stderr, "KVM: invalid sccb address 0x%x\n", sccb);
|
251 | 0e60a699 | Alexander Graf | r = -1;
|
252 | 0e60a699 | Alexander Graf | goto out;
|
253 | 0e60a699 | Alexander Graf | } |
254 | 0e60a699 | Alexander Graf | |
255 | 0e60a699 | Alexander Graf | switch(code) {
|
256 | 0e60a699 | Alexander Graf | case SCLP_CMDW_READ_SCP_INFO:
|
257 | 0e60a699 | Alexander Graf | case SCLP_CMDW_READ_SCP_INFO_FORCED:
|
258 | 0e60a699 | Alexander Graf | stw_phys(sccb + SCP_MEM_CODE, ram_size >> 20);
|
259 | 0e60a699 | Alexander Graf | stb_phys(sccb + SCP_INCREMENT, 1);
|
260 | 0e60a699 | Alexander Graf | stw_phys(sccb + SCP_RESPONSE_CODE, 0x10);
|
261 | 0e60a699 | Alexander Graf | setcc(env, 0);
|
262 | 0e60a699 | Alexander Graf | |
263 | 0e60a699 | Alexander Graf | kvm_s390_interrupt_internal(env, KVM_S390_INT_SERVICE, |
264 | 0e60a699 | Alexander Graf | sccb & ~3, 0, 1); |
265 | 0e60a699 | Alexander Graf | break;
|
266 | 0e60a699 | Alexander Graf | default:
|
267 | 0e60a699 | Alexander Graf | dprintf("KVM: invalid sclp call 0x%x / 0x%lx\n", sccb, code);
|
268 | 0e60a699 | Alexander Graf | r = -1;
|
269 | 0e60a699 | Alexander Graf | break;
|
270 | 0e60a699 | Alexander Graf | } |
271 | 0e60a699 | Alexander Graf | |
272 | 0e60a699 | Alexander Graf | out:
|
273 | 0e60a699 | Alexander Graf | if (r < 0) { |
274 | 0e60a699 | Alexander Graf | setcc(env, 3);
|
275 | 0e60a699 | Alexander Graf | } |
276 | 0e60a699 | Alexander Graf | return 0; |
277 | 0e60a699 | Alexander Graf | } |
278 | 0e60a699 | Alexander Graf | |
279 | 0e60a699 | Alexander Graf | static int handle_priv(CPUState *env, struct kvm_run *run, uint8_t ipa1) |
280 | 0e60a699 | Alexander Graf | { |
281 | 0e60a699 | Alexander Graf | int r = 0; |
282 | 0e60a699 | Alexander Graf | uint16_t ipbh0 = (run->s390_sieic.ipb & 0xffff0000) >> 16; |
283 | 0e60a699 | Alexander Graf | |
284 | 0e60a699 | Alexander Graf | dprintf("KVM: PRIV: %d\n", ipa1);
|
285 | 0e60a699 | Alexander Graf | switch (ipa1) {
|
286 | 0e60a699 | Alexander Graf | case PRIV_SCLP_CALL:
|
287 | 0e60a699 | Alexander Graf | r = sclp_service_call(env, run, ipbh0); |
288 | 0e60a699 | Alexander Graf | break;
|
289 | 0e60a699 | Alexander Graf | default:
|
290 | 0e60a699 | Alexander Graf | dprintf("KVM: unknown PRIV: 0x%x\n", ipa1);
|
291 | 0e60a699 | Alexander Graf | r = -1;
|
292 | 0e60a699 | Alexander Graf | break;
|
293 | 0e60a699 | Alexander Graf | } |
294 | 0e60a699 | Alexander Graf | |
295 | 0e60a699 | Alexander Graf | return r;
|
296 | 0e60a699 | Alexander Graf | } |
297 | 0e60a699 | Alexander Graf | |
298 | 0e60a699 | Alexander Graf | static int handle_hypercall(CPUState *env, struct kvm_run *run) |
299 | 0e60a699 | Alexander Graf | { |
300 | 0e60a699 | Alexander Graf | int r;
|
301 | 0e60a699 | Alexander Graf | |
302 | 0e60a699 | Alexander Graf | cpu_synchronize_state(env); |
303 | 0e60a699 | Alexander Graf | r = s390_virtio_hypercall(env); |
304 | 0e60a699 | Alexander Graf | |
305 | 0e60a699 | Alexander Graf | return r;
|
306 | 0e60a699 | Alexander Graf | } |
307 | 0e60a699 | Alexander Graf | |
308 | 0e60a699 | Alexander Graf | static int handle_diag(CPUState *env, struct kvm_run *run, int ipb_code) |
309 | 0e60a699 | Alexander Graf | { |
310 | 0e60a699 | Alexander Graf | int r = 0; |
311 | 0e60a699 | Alexander Graf | |
312 | 0e60a699 | Alexander Graf | switch (ipb_code) {
|
313 | 0e60a699 | Alexander Graf | case DIAG_KVM_HYPERCALL:
|
314 | 0e60a699 | Alexander Graf | r = handle_hypercall(env, run); |
315 | 0e60a699 | Alexander Graf | break;
|
316 | 0e60a699 | Alexander Graf | case DIAG_KVM_BREAKPOINT:
|
317 | 0e60a699 | Alexander Graf | sleep(10);
|
318 | 0e60a699 | Alexander Graf | break;
|
319 | 0e60a699 | Alexander Graf | default:
|
320 | 0e60a699 | Alexander Graf | dprintf("KVM: unknown DIAG: 0x%x\n", ipb_code);
|
321 | 0e60a699 | Alexander Graf | r = -1;
|
322 | 0e60a699 | Alexander Graf | break;
|
323 | 0e60a699 | Alexander Graf | } |
324 | 0e60a699 | Alexander Graf | |
325 | 0e60a699 | Alexander Graf | return r;
|
326 | 0e60a699 | Alexander Graf | } |
327 | 0e60a699 | Alexander Graf | |
328 | 0e60a699 | Alexander Graf | static int s390_cpu_restart(CPUState *env) |
329 | 0e60a699 | Alexander Graf | { |
330 | 0e60a699 | Alexander Graf | kvm_s390_interrupt(env, KVM_S390_RESTART, 0);
|
331 | 0e60a699 | Alexander Graf | env->halted = 0;
|
332 | ee0dc6d3 | Blue Swirl | env->exception_index = -1;
|
333 | 0e60a699 | Alexander Graf | qemu_cpu_kick(env); |
334 | 0e60a699 | Alexander Graf | dprintf("DONE: SIGP cpu restart: %p\n", env);
|
335 | 0e60a699 | Alexander Graf | return 0; |
336 | 0e60a699 | Alexander Graf | } |
337 | 0e60a699 | Alexander Graf | |
338 | 0e60a699 | Alexander Graf | static int s390_store_status(CPUState *env, uint32_t parameter) |
339 | 0e60a699 | Alexander Graf | { |
340 | 0e60a699 | Alexander Graf | /* XXX */
|
341 | 0e60a699 | Alexander Graf | fprintf(stderr, "XXX SIGP store status\n");
|
342 | 0e60a699 | Alexander Graf | return -1; |
343 | 0e60a699 | Alexander Graf | } |
344 | 0e60a699 | Alexander Graf | |
345 | 0e60a699 | Alexander Graf | static int s390_cpu_initial_reset(CPUState *env) |
346 | 0e60a699 | Alexander Graf | { |
347 | d5900813 | Alexander Graf | int i;
|
348 | d5900813 | Alexander Graf | |
349 | d5900813 | Alexander Graf | if (kvm_vcpu_ioctl(env, KVM_S390_INITIAL_RESET, NULL) < 0) { |
350 | d5900813 | Alexander Graf | perror("cannot init reset vcpu");
|
351 | d5900813 | Alexander Graf | } |
352 | d5900813 | Alexander Graf | |
353 | d5900813 | Alexander Graf | /* Manually zero out all registers */
|
354 | d5900813 | Alexander Graf | cpu_synchronize_state(env); |
355 | d5900813 | Alexander Graf | for (i = 0; i < 16; i++) { |
356 | d5900813 | Alexander Graf | env->regs[i] = 0;
|
357 | d5900813 | Alexander Graf | } |
358 | d5900813 | Alexander Graf | |
359 | d5900813 | Alexander Graf | dprintf("DONE: SIGP initial reset: %p\n", env);
|
360 | d5900813 | Alexander Graf | return 0; |
361 | 0e60a699 | Alexander Graf | } |
362 | 0e60a699 | Alexander Graf | |
363 | 0e60a699 | Alexander Graf | static int handle_sigp(CPUState *env, struct kvm_run *run, uint8_t ipa1) |
364 | 0e60a699 | Alexander Graf | { |
365 | 0e60a699 | Alexander Graf | uint8_t order_code; |
366 | 0e60a699 | Alexander Graf | uint32_t parameter; |
367 | 0e60a699 | Alexander Graf | uint16_t cpu_addr; |
368 | 0e60a699 | Alexander Graf | uint8_t t; |
369 | 0e60a699 | Alexander Graf | int r = -1; |
370 | 0e60a699 | Alexander Graf | CPUState *target_env; |
371 | 0e60a699 | Alexander Graf | |
372 | 0e60a699 | Alexander Graf | cpu_synchronize_state(env); |
373 | 0e60a699 | Alexander Graf | |
374 | 0e60a699 | Alexander Graf | /* get order code */
|
375 | 0e60a699 | Alexander Graf | order_code = run->s390_sieic.ipb >> 28;
|
376 | 0e60a699 | Alexander Graf | if (order_code > 0) { |
377 | 0e60a699 | Alexander Graf | order_code = env->regs[order_code]; |
378 | 0e60a699 | Alexander Graf | } |
379 | 0e60a699 | Alexander Graf | order_code += (run->s390_sieic.ipb & 0x0fff0000) >> 16; |
380 | 0e60a699 | Alexander Graf | |
381 | 0e60a699 | Alexander Graf | /* get parameters */
|
382 | 0e60a699 | Alexander Graf | t = (ipa1 & 0xf0) >> 4; |
383 | 0e60a699 | Alexander Graf | if (!(t % 2)) { |
384 | 0e60a699 | Alexander Graf | t++; |
385 | 0e60a699 | Alexander Graf | } |
386 | 0e60a699 | Alexander Graf | |
387 | 0e60a699 | Alexander Graf | parameter = env->regs[t] & 0x7ffffe00;
|
388 | 0e60a699 | Alexander Graf | cpu_addr = env->regs[ipa1 & 0x0f];
|
389 | 0e60a699 | Alexander Graf | |
390 | 0e60a699 | Alexander Graf | target_env = s390_cpu_addr2state(cpu_addr); |
391 | 0e60a699 | Alexander Graf | if (!target_env) {
|
392 | 0e60a699 | Alexander Graf | goto out;
|
393 | 0e60a699 | Alexander Graf | } |
394 | 0e60a699 | Alexander Graf | |
395 | 0e60a699 | Alexander Graf | switch (order_code) {
|
396 | 0e60a699 | Alexander Graf | case SIGP_RESTART:
|
397 | 0e60a699 | Alexander Graf | r = s390_cpu_restart(target_env); |
398 | 0e60a699 | Alexander Graf | break;
|
399 | 0e60a699 | Alexander Graf | case SIGP_STORE_STATUS_ADDR:
|
400 | 0e60a699 | Alexander Graf | r = s390_store_status(target_env, parameter); |
401 | 0e60a699 | Alexander Graf | break;
|
402 | 0e60a699 | Alexander Graf | case SIGP_SET_ARCH:
|
403 | 0e60a699 | Alexander Graf | /* make the caller panic */
|
404 | 0e60a699 | Alexander Graf | return -1; |
405 | 0e60a699 | Alexander Graf | case SIGP_INITIAL_CPU_RESET:
|
406 | 0e60a699 | Alexander Graf | r = s390_cpu_initial_reset(target_env); |
407 | 0e60a699 | Alexander Graf | break;
|
408 | 0e60a699 | Alexander Graf | default:
|
409 | 0e60a699 | Alexander Graf | fprintf(stderr, "KVM: unknown SIGP: 0x%x\n", ipa1);
|
410 | 0e60a699 | Alexander Graf | break;
|
411 | 0e60a699 | Alexander Graf | } |
412 | 0e60a699 | Alexander Graf | |
413 | 0e60a699 | Alexander Graf | out:
|
414 | 0e60a699 | Alexander Graf | setcc(env, r ? 3 : 0); |
415 | 0e60a699 | Alexander Graf | return 0; |
416 | 0e60a699 | Alexander Graf | } |
417 | 0e60a699 | Alexander Graf | |
418 | 0e60a699 | Alexander Graf | static int handle_instruction(CPUState *env, struct kvm_run *run) |
419 | 0e60a699 | Alexander Graf | { |
420 | 0e60a699 | Alexander Graf | unsigned int ipa0 = (run->s390_sieic.ipa & 0xff00); |
421 | 0e60a699 | Alexander Graf | uint8_t ipa1 = run->s390_sieic.ipa & 0x00ff;
|
422 | 0e60a699 | Alexander Graf | int ipb_code = (run->s390_sieic.ipb & 0x0fff0000) >> 16; |
423 | d7963c43 | Alexander Graf | int r = -1; |
424 | 0e60a699 | Alexander Graf | |
425 | 0e60a699 | Alexander Graf | dprintf("handle_instruction 0x%x 0x%x\n", run->s390_sieic.ipa, run->s390_sieic.ipb);
|
426 | 0e60a699 | Alexander Graf | switch (ipa0) {
|
427 | 0e60a699 | Alexander Graf | case IPA0_PRIV:
|
428 | 0e60a699 | Alexander Graf | r = handle_priv(env, run, ipa1); |
429 | 0e60a699 | Alexander Graf | break;
|
430 | 0e60a699 | Alexander Graf | case IPA0_DIAG:
|
431 | 0e60a699 | Alexander Graf | r = handle_diag(env, run, ipb_code); |
432 | 0e60a699 | Alexander Graf | break;
|
433 | 0e60a699 | Alexander Graf | case IPA0_SIGP:
|
434 | 0e60a699 | Alexander Graf | r = handle_sigp(env, run, ipa1); |
435 | 0e60a699 | Alexander Graf | break;
|
436 | 0e60a699 | Alexander Graf | } |
437 | 0e60a699 | Alexander Graf | |
438 | 0e60a699 | Alexander Graf | if (r < 0) { |
439 | 0e60a699 | Alexander Graf | enter_pgmcheck(env, 0x0001);
|
440 | 0e60a699 | Alexander Graf | } |
441 | 0e60a699 | Alexander Graf | return r;
|
442 | 0e60a699 | Alexander Graf | } |
443 | 0e60a699 | Alexander Graf | |
444 | 0e60a699 | Alexander Graf | static int handle_intercept(CPUState *env) |
445 | 0e60a699 | Alexander Graf | { |
446 | 0e60a699 | Alexander Graf | struct kvm_run *run = env->kvm_run;
|
447 | 0e60a699 | Alexander Graf | int icpt_code = run->s390_sieic.icptcode;
|
448 | 0e60a699 | Alexander Graf | int r = 0; |
449 | 0e60a699 | Alexander Graf | |
450 | 0e60a699 | Alexander Graf | dprintf("intercept: 0x%x (at 0x%lx)\n", icpt_code, env->kvm_run->psw_addr);
|
451 | 0e60a699 | Alexander Graf | switch (icpt_code) {
|
452 | 0e60a699 | Alexander Graf | case ICPT_INSTRUCTION:
|
453 | 0e60a699 | Alexander Graf | r = handle_instruction(env, run); |
454 | 0e60a699 | Alexander Graf | break;
|
455 | 0e60a699 | Alexander Graf | case ICPT_WAITPSW:
|
456 | 0e60a699 | Alexander Graf | /* XXX What to do on system shutdown? */
|
457 | 0e60a699 | Alexander Graf | env->halted = 1;
|
458 | 0e60a699 | Alexander Graf | env->exception_index = EXCP_HLT; |
459 | 0e60a699 | Alexander Graf | break;
|
460 | 0e60a699 | Alexander Graf | case ICPT_SOFT_INTERCEPT:
|
461 | 0e60a699 | Alexander Graf | fprintf(stderr, "KVM unimplemented icpt SOFT\n");
|
462 | 0e60a699 | Alexander Graf | exit(1);
|
463 | 0e60a699 | Alexander Graf | break;
|
464 | 0e60a699 | Alexander Graf | case ICPT_CPU_STOP:
|
465 | 0e60a699 | Alexander Graf | qemu_system_shutdown_request(); |
466 | 0e60a699 | Alexander Graf | break;
|
467 | 0e60a699 | Alexander Graf | case ICPT_IO:
|
468 | 0e60a699 | Alexander Graf | fprintf(stderr, "KVM unimplemented icpt IO\n");
|
469 | 0e60a699 | Alexander Graf | exit(1);
|
470 | 0e60a699 | Alexander Graf | break;
|
471 | 0e60a699 | Alexander Graf | default:
|
472 | 0e60a699 | Alexander Graf | fprintf(stderr, "Unknown intercept code: %d\n", icpt_code);
|
473 | 0e60a699 | Alexander Graf | exit(1);
|
474 | 0e60a699 | Alexander Graf | break;
|
475 | 0e60a699 | Alexander Graf | } |
476 | 0e60a699 | Alexander Graf | |
477 | 0e60a699 | Alexander Graf | return r;
|
478 | 0e60a699 | Alexander Graf | } |
479 | 0e60a699 | Alexander Graf | |
480 | 0e60a699 | Alexander Graf | int kvm_arch_handle_exit(CPUState *env, struct kvm_run *run) |
481 | 0e60a699 | Alexander Graf | { |
482 | 0e60a699 | Alexander Graf | int ret = 0; |
483 | 0e60a699 | Alexander Graf | |
484 | 0e60a699 | Alexander Graf | switch (run->exit_reason) {
|
485 | 0e60a699 | Alexander Graf | case KVM_EXIT_S390_SIEIC:
|
486 | 0e60a699 | Alexander Graf | ret = handle_intercept(env); |
487 | 0e60a699 | Alexander Graf | break;
|
488 | 0e60a699 | Alexander Graf | case KVM_EXIT_S390_RESET:
|
489 | 0e60a699 | Alexander Graf | fprintf(stderr, "RESET not implemented\n");
|
490 | 0e60a699 | Alexander Graf | exit(1);
|
491 | 0e60a699 | Alexander Graf | break;
|
492 | 0e60a699 | Alexander Graf | default:
|
493 | 0e60a699 | Alexander Graf | fprintf(stderr, "Unknown KVM exit: %d\n", run->exit_reason);
|
494 | 0e60a699 | Alexander Graf | break;
|
495 | 0e60a699 | Alexander Graf | } |
496 | 0e60a699 | Alexander Graf | |
497 | 0e60a699 | Alexander Graf | return ret;
|
498 | 0e60a699 | Alexander Graf | } |
499 | 4513d923 | Gleb Natapov | |
500 | 4513d923 | Gleb Natapov | bool kvm_arch_stop_on_emulation_error(CPUState *env)
|
501 | 4513d923 | Gleb Natapov | { |
502 | 4513d923 | Gleb Natapov | return true; |
503 | 4513d923 | Gleb Natapov | } |