]>
Commit | Line | Data |
---|---|---|
0e60a699 AG |
1 | /* |
2 | * QEMU S390x KVM implementation | |
3 | * | |
4 | * Copyright (c) 2009 Alexander Graf <[email protected]> | |
5 | * | |
6 | * This library is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU Lesser General Public | |
8 | * License as published by the Free Software Foundation; either | |
9 | * version 2 of the License, or (at your option) any later version. | |
10 | * | |
11 | * This library is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * Lesser General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU Lesser General Public | |
17 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. | |
18 | */ | |
19 | ||
20 | #include <sys/types.h> | |
21 | #include <sys/ioctl.h> | |
22 | #include <sys/mman.h> | |
23 | ||
24 | #include <linux/kvm.h> | |
25 | #include <asm/ptrace.h> | |
26 | ||
27 | #include "qemu-common.h" | |
1de7afc9 | 28 | #include "qemu/timer.h" |
9c17d615 PB |
29 | #include "sysemu/sysemu.h" |
30 | #include "sysemu/kvm.h" | |
0e60a699 | 31 | #include "cpu.h" |
9c17d615 | 32 | #include "sysemu/device_tree.h" |
0e60a699 AG |
33 | |
34 | /* #define DEBUG_KVM */ | |
35 | ||
36 | #ifdef DEBUG_KVM | |
37 | #define dprintf(fmt, ...) \ | |
38 | do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0) | |
39 | #else | |
40 | #define dprintf(fmt, ...) \ | |
41 | do { } while (0) | |
42 | #endif | |
43 | ||
44 | #define IPA0_DIAG 0x8300 | |
45 | #define IPA0_SIGP 0xae00 | |
46 | #define IPA0_PRIV 0xb200 | |
47 | ||
48 | #define PRIV_SCLP_CALL 0x20 | |
49 | #define DIAG_KVM_HYPERCALL 0x500 | |
50 | #define DIAG_KVM_BREAKPOINT 0x501 | |
51 | ||
0e60a699 AG |
52 | #define ICPT_INSTRUCTION 0x04 |
53 | #define ICPT_WAITPSW 0x1c | |
54 | #define ICPT_SOFT_INTERCEPT 0x24 | |
55 | #define ICPT_CPU_STOP 0x28 | |
56 | #define ICPT_IO 0x40 | |
57 | ||
58 | #define SIGP_RESTART 0x06 | |
59 | #define SIGP_INITIAL_CPU_RESET 0x0b | |
60 | #define SIGP_STORE_STATUS_ADDR 0x0e | |
61 | #define SIGP_SET_ARCH 0x12 | |
62 | ||
94a8d39a JK |
63 | const KVMCapabilityInfo kvm_arch_required_capabilities[] = { |
64 | KVM_CAP_LAST_INFO | |
65 | }; | |
66 | ||
5b08b344 CB |
67 | static int cap_sync_regs; |
68 | ||
cad1e282 | 69 | int kvm_arch_init(KVMState *s) |
0e60a699 | 70 | { |
5b08b344 | 71 | cap_sync_regs = kvm_check_extension(s, KVM_CAP_SYNC_REGS); |
0e60a699 AG |
72 | return 0; |
73 | } | |
74 | ||
20d695a9 | 75 | int kvm_arch_init_vcpu(CPUState *cpu) |
0e60a699 AG |
76 | { |
77 | int ret = 0; | |
78 | ||
1bc22652 | 79 | if (kvm_vcpu_ioctl(cpu, KVM_S390_INITIAL_RESET, NULL) < 0) { |
0e60a699 AG |
80 | perror("cannot init reset vcpu"); |
81 | } | |
82 | ||
83 | return ret; | |
84 | } | |
85 | ||
20d695a9 | 86 | void kvm_arch_reset_vcpu(CPUState *cpu) |
0e60a699 AG |
87 | { |
88 | /* FIXME: add code to reset vcpu. */ | |
89 | } | |
90 | ||
20d695a9 | 91 | int kvm_arch_put_registers(CPUState *cs, int level) |
0e60a699 | 92 | { |
20d695a9 AF |
93 | S390CPU *cpu = S390_CPU(cs); |
94 | CPUS390XState *env = &cpu->env; | |
5b08b344 | 95 | struct kvm_sregs sregs; |
0e60a699 AG |
96 | struct kvm_regs regs; |
97 | int ret; | |
98 | int i; | |
99 | ||
5b08b344 | 100 | /* always save the PSW and the GPRS*/ |
f7575c96 AF |
101 | cs->kvm_run->psw_addr = env->psw.addr; |
102 | cs->kvm_run->psw_mask = env->psw.mask; | |
0e60a699 | 103 | |
f7575c96 | 104 | if (cap_sync_regs && cs->kvm_run->kvm_valid_regs & KVM_SYNC_GPRS) { |
5b08b344 | 105 | for (i = 0; i < 16; i++) { |
f7575c96 AF |
106 | cs->kvm_run->s.regs.gprs[i] = env->regs[i]; |
107 | cs->kvm_run->kvm_dirty_regs |= KVM_SYNC_GPRS; | |
5b08b344 CB |
108 | } |
109 | } else { | |
110 | for (i = 0; i < 16; i++) { | |
111 | regs.gprs[i] = env->regs[i]; | |
112 | } | |
1bc22652 | 113 | ret = kvm_vcpu_ioctl(cs, KVM_SET_REGS, ®s); |
5b08b344 CB |
114 | if (ret < 0) { |
115 | return ret; | |
116 | } | |
0e60a699 AG |
117 | } |
118 | ||
5b08b344 CB |
119 | /* Do we need to save more than that? */ |
120 | if (level == KVM_PUT_RUNTIME_STATE) { | |
121 | return 0; | |
0e60a699 AG |
122 | } |
123 | ||
5b08b344 | 124 | if (cap_sync_regs && |
f7575c96 AF |
125 | cs->kvm_run->kvm_valid_regs & KVM_SYNC_ACRS && |
126 | cs->kvm_run->kvm_valid_regs & KVM_SYNC_CRS) { | |
5b08b344 | 127 | for (i = 0; i < 16; i++) { |
f7575c96 AF |
128 | cs->kvm_run->s.regs.acrs[i] = env->aregs[i]; |
129 | cs->kvm_run->s.regs.crs[i] = env->cregs[i]; | |
5b08b344 | 130 | } |
f7575c96 AF |
131 | cs->kvm_run->kvm_dirty_regs |= KVM_SYNC_ACRS; |
132 | cs->kvm_run->kvm_dirty_regs |= KVM_SYNC_CRS; | |
5b08b344 CB |
133 | } else { |
134 | for (i = 0; i < 16; i++) { | |
135 | sregs.acrs[i] = env->aregs[i]; | |
136 | sregs.crs[i] = env->cregs[i]; | |
137 | } | |
1bc22652 | 138 | ret = kvm_vcpu_ioctl(cs, KVM_SET_SREGS, &sregs); |
5b08b344 CB |
139 | if (ret < 0) { |
140 | return ret; | |
141 | } | |
142 | } | |
0e60a699 | 143 | |
5b08b344 | 144 | /* Finally the prefix */ |
f7575c96 AF |
145 | if (cap_sync_regs && cs->kvm_run->kvm_valid_regs & KVM_SYNC_PREFIX) { |
146 | cs->kvm_run->s.regs.prefix = env->psa; | |
147 | cs->kvm_run->kvm_dirty_regs |= KVM_SYNC_PREFIX; | |
5b08b344 CB |
148 | } else { |
149 | /* prefix is only supported via sync regs */ | |
150 | } | |
151 | return 0; | |
0e60a699 AG |
152 | } |
153 | ||
20d695a9 | 154 | int kvm_arch_get_registers(CPUState *cs) |
0e60a699 | 155 | { |
20d695a9 AF |
156 | S390CPU *cpu = S390_CPU(cs); |
157 | CPUS390XState *env = &cpu->env; | |
5b08b344 | 158 | struct kvm_sregs sregs; |
0e60a699 | 159 | struct kvm_regs regs; |
5b08b344 | 160 | int ret; |
0e60a699 AG |
161 | int i; |
162 | ||
5b08b344 | 163 | /* get the PSW */ |
f7575c96 AF |
164 | env->psw.addr = cs->kvm_run->psw_addr; |
165 | env->psw.mask = cs->kvm_run->psw_mask; | |
5b08b344 CB |
166 | |
167 | /* the GPRS */ | |
f7575c96 | 168 | if (cap_sync_regs && cs->kvm_run->kvm_valid_regs & KVM_SYNC_GPRS) { |
5b08b344 | 169 | for (i = 0; i < 16; i++) { |
f7575c96 | 170 | env->regs[i] = cs->kvm_run->s.regs.gprs[i]; |
5b08b344 CB |
171 | } |
172 | } else { | |
1bc22652 | 173 | ret = kvm_vcpu_ioctl(cs, KVM_GET_REGS, ®s); |
5b08b344 CB |
174 | if (ret < 0) { |
175 | return ret; | |
176 | } | |
177 | for (i = 0; i < 16; i++) { | |
178 | env->regs[i] = regs.gprs[i]; | |
179 | } | |
0e60a699 AG |
180 | } |
181 | ||
5b08b344 CB |
182 | /* The ACRS and CRS */ |
183 | if (cap_sync_regs && | |
f7575c96 AF |
184 | cs->kvm_run->kvm_valid_regs & KVM_SYNC_ACRS && |
185 | cs->kvm_run->kvm_valid_regs & KVM_SYNC_CRS) { | |
5b08b344 | 186 | for (i = 0; i < 16; i++) { |
f7575c96 AF |
187 | env->aregs[i] = cs->kvm_run->s.regs.acrs[i]; |
188 | env->cregs[i] = cs->kvm_run->s.regs.crs[i]; | |
5b08b344 CB |
189 | } |
190 | } else { | |
1bc22652 | 191 | ret = kvm_vcpu_ioctl(cs, KVM_GET_SREGS, &sregs); |
5b08b344 CB |
192 | if (ret < 0) { |
193 | return ret; | |
194 | } | |
195 | for (i = 0; i < 16; i++) { | |
196 | env->aregs[i] = sregs.acrs[i]; | |
197 | env->cregs[i] = sregs.crs[i]; | |
198 | } | |
0e60a699 AG |
199 | } |
200 | ||
5b08b344 | 201 | /* Finally the prefix */ |
f7575c96 AF |
202 | if (cap_sync_regs && cs->kvm_run->kvm_valid_regs & KVM_SYNC_PREFIX) { |
203 | env->psa = cs->kvm_run->s.regs.prefix; | |
5b08b344 CB |
204 | } else { |
205 | /* no prefix without sync regs */ | |
206 | } | |
0e60a699 AG |
207 | |
208 | return 0; | |
209 | } | |
210 | ||
fdec9918 CB |
211 | /* |
212 | * Legacy layout for s390: | |
213 | * Older S390 KVM requires the topmost vma of the RAM to be | |
214 | * smaller than an system defined value, which is at least 256GB. | |
215 | * Larger systems have larger values. We put the guest between | |
216 | * the end of data segment (system break) and this value. We | |
217 | * use 32GB as a base to have enough room for the system break | |
218 | * to grow. We also have to use MAP parameters that avoid | |
219 | * read-only mapping of guest pages. | |
220 | */ | |
221 | static void *legacy_s390_alloc(ram_addr_t size) | |
222 | { | |
223 | void *mem; | |
224 | ||
225 | mem = mmap((void *) 0x800000000ULL, size, | |
226 | PROT_EXEC|PROT_READ|PROT_WRITE, | |
227 | MAP_SHARED | MAP_ANONYMOUS | MAP_FIXED, -1, 0); | |
228 | if (mem == MAP_FAILED) { | |
229 | fprintf(stderr, "Allocating RAM failed\n"); | |
230 | abort(); | |
231 | } | |
232 | return mem; | |
233 | } | |
234 | ||
235 | void *kvm_arch_vmalloc(ram_addr_t size) | |
236 | { | |
237 | /* Can we use the standard allocation ? */ | |
238 | if (kvm_check_extension(kvm_state, KVM_CAP_S390_GMAP) && | |
239 | kvm_check_extension(kvm_state, KVM_CAP_S390_COW)) { | |
240 | return NULL; | |
241 | } else { | |
242 | return legacy_s390_alloc(size); | |
243 | } | |
244 | } | |
245 | ||
20d695a9 | 246 | int kvm_arch_insert_sw_breakpoint(CPUState *cs, struct kvm_sw_breakpoint *bp) |
0e60a699 | 247 | { |
20d695a9 AF |
248 | S390CPU *cpu = S390_CPU(cs); |
249 | CPUS390XState *env = &cpu->env; | |
0e60a699 AG |
250 | static const uint8_t diag_501[] = {0x83, 0x24, 0x05, 0x01}; |
251 | ||
252 | if (cpu_memory_rw_debug(env, bp->pc, (uint8_t *)&bp->saved_insn, 4, 0) || | |
253 | cpu_memory_rw_debug(env, bp->pc, (uint8_t *)diag_501, 4, 1)) { | |
254 | return -EINVAL; | |
255 | } | |
256 | return 0; | |
257 | } | |
258 | ||
20d695a9 | 259 | int kvm_arch_remove_sw_breakpoint(CPUState *cs, struct kvm_sw_breakpoint *bp) |
0e60a699 | 260 | { |
20d695a9 AF |
261 | S390CPU *cpu = S390_CPU(cs); |
262 | CPUS390XState *env = &cpu->env; | |
0e60a699 AG |
263 | uint8_t t[4]; |
264 | static const uint8_t diag_501[] = {0x83, 0x24, 0x05, 0x01}; | |
265 | ||
266 | if (cpu_memory_rw_debug(env, bp->pc, t, 4, 0)) { | |
267 | return -EINVAL; | |
268 | } else if (memcmp(t, diag_501, 4)) { | |
269 | return -EINVAL; | |
270 | } else if (cpu_memory_rw_debug(env, bp->pc, (uint8_t *)&bp->saved_insn, 1, 1)) { | |
271 | return -EINVAL; | |
272 | } | |
273 | ||
274 | return 0; | |
275 | } | |
276 | ||
20d695a9 | 277 | void kvm_arch_pre_run(CPUState *cpu, struct kvm_run *run) |
0e60a699 | 278 | { |
0e60a699 AG |
279 | } |
280 | ||
20d695a9 | 281 | void kvm_arch_post_run(CPUState *cpu, struct kvm_run *run) |
0e60a699 | 282 | { |
0e60a699 AG |
283 | } |
284 | ||
20d695a9 | 285 | int kvm_arch_process_async_events(CPUState *cs) |
0af691d7 | 286 | { |
20d695a9 AF |
287 | S390CPU *cpu = S390_CPU(cs); |
288 | return cpu->env.halted; | |
0af691d7 MT |
289 | } |
290 | ||
1bc22652 | 291 | void kvm_s390_interrupt_internal(S390CPU *cpu, int type, uint32_t parm, |
bcec36ea | 292 | uint64_t parm64, int vm) |
0e60a699 | 293 | { |
1bc22652 | 294 | CPUState *cs = CPU(cpu); |
0e60a699 AG |
295 | struct kvm_s390_interrupt kvmint; |
296 | int r; | |
297 | ||
a60f24b5 | 298 | if (!cs->kvm_state) { |
0e60a699 AG |
299 | return; |
300 | } | |
301 | ||
0e60a699 AG |
302 | kvmint.type = type; |
303 | kvmint.parm = parm; | |
304 | kvmint.parm64 = parm64; | |
305 | ||
306 | if (vm) { | |
a60f24b5 | 307 | r = kvm_vm_ioctl(cs->kvm_state, KVM_S390_INTERRUPT, &kvmint); |
0e60a699 | 308 | } else { |
1bc22652 | 309 | r = kvm_vcpu_ioctl(cs, KVM_S390_INTERRUPT, &kvmint); |
0e60a699 AG |
310 | } |
311 | ||
312 | if (r < 0) { | |
313 | fprintf(stderr, "KVM failed to inject interrupt\n"); | |
314 | exit(1); | |
315 | } | |
316 | } | |
317 | ||
1bc22652 | 318 | void kvm_s390_virtio_irq(S390CPU *cpu, int config_change, uint64_t token) |
0e60a699 | 319 | { |
1bc22652 | 320 | kvm_s390_interrupt_internal(cpu, KVM_S390_INT_VIRTIO, config_change, |
0e60a699 AG |
321 | token, 1); |
322 | } | |
323 | ||
1bc22652 | 324 | void kvm_s390_interrupt(S390CPU *cpu, int type, uint32_t code) |
0e60a699 | 325 | { |
1bc22652 | 326 | kvm_s390_interrupt_internal(cpu, type, code, 0, 0); |
0e60a699 AG |
327 | } |
328 | ||
1bc22652 | 329 | static void enter_pgmcheck(S390CPU *cpu, uint16_t code) |
0e60a699 | 330 | { |
1bc22652 | 331 | kvm_s390_interrupt(cpu, KVM_S390_PROGRAM_INT, code); |
0e60a699 AG |
332 | } |
333 | ||
f7575c96 | 334 | static inline void setcc(S390CPU *cpu, uint64_t cc) |
0e60a699 | 335 | { |
f7575c96 AF |
336 | CPUS390XState *env = &cpu->env; |
337 | CPUState *cs = CPU(cpu); | |
338 | ||
339 | cs->kvm_run->psw_mask &= ~(3ull << 44); | |
340 | cs->kvm_run->psw_mask |= (cc & 3) << 44; | |
0e60a699 AG |
341 | |
342 | env->psw.mask &= ~(3ul << 44); | |
343 | env->psw.mask |= (cc & 3) << 44; | |
344 | } | |
345 | ||
1bc22652 | 346 | static int kvm_sclp_service_call(S390CPU *cpu, struct kvm_run *run, |
bcec36ea | 347 | uint16_t ipbh0) |
0e60a699 | 348 | { |
1bc22652 | 349 | CPUS390XState *env = &cpu->env; |
0e60a699 AG |
350 | uint32_t sccb; |
351 | uint64_t code; | |
352 | int r = 0; | |
353 | ||
354 | cpu_synchronize_state(env); | |
355 | sccb = env->regs[ipbh0 & 0xf]; | |
356 | code = env->regs[(ipbh0 & 0xf0) >> 4]; | |
357 | ||
f6c98f92 | 358 | r = sclp_service_call(sccb, code); |
9abf567d | 359 | if (r < 0) { |
1bc22652 | 360 | enter_pgmcheck(cpu, -r); |
0e60a699 | 361 | } |
f7575c96 | 362 | setcc(cpu, r); |
81f7c56c | 363 | |
0e60a699 AG |
364 | return 0; |
365 | } | |
366 | ||
1bc22652 | 367 | static int handle_priv(S390CPU *cpu, struct kvm_run *run, uint8_t ipa1) |
0e60a699 AG |
368 | { |
369 | int r = 0; | |
370 | uint16_t ipbh0 = (run->s390_sieic.ipb & 0xffff0000) >> 16; | |
371 | ||
372 | dprintf("KVM: PRIV: %d\n", ipa1); | |
373 | switch (ipa1) { | |
374 | case PRIV_SCLP_CALL: | |
1bc22652 | 375 | r = kvm_sclp_service_call(cpu, run, ipbh0); |
0e60a699 AG |
376 | break; |
377 | default: | |
378 | dprintf("KVM: unknown PRIV: 0x%x\n", ipa1); | |
379 | r = -1; | |
380 | break; | |
381 | } | |
382 | ||
383 | return r; | |
384 | } | |
385 | ||
a4e3ad19 | 386 | static int handle_hypercall(CPUS390XState *env, struct kvm_run *run) |
0e60a699 | 387 | { |
0e60a699 | 388 | cpu_synchronize_state(env); |
bcec36ea | 389 | env->regs[2] = s390_virtio_hypercall(env, env->regs[2], env->regs[1]); |
0e60a699 | 390 | |
bcec36ea | 391 | return 0; |
0e60a699 AG |
392 | } |
393 | ||
a4e3ad19 | 394 | static int handle_diag(CPUS390XState *env, struct kvm_run *run, int ipb_code) |
0e60a699 AG |
395 | { |
396 | int r = 0; | |
397 | ||
398 | switch (ipb_code) { | |
399 | case DIAG_KVM_HYPERCALL: | |
400 | r = handle_hypercall(env, run); | |
401 | break; | |
402 | case DIAG_KVM_BREAKPOINT: | |
403 | sleep(10); | |
404 | break; | |
405 | default: | |
406 | dprintf("KVM: unknown DIAG: 0x%x\n", ipb_code); | |
407 | r = -1; | |
408 | break; | |
409 | } | |
410 | ||
411 | return r; | |
412 | } | |
413 | ||
3edb8f92 | 414 | static int s390_cpu_restart(S390CPU *cpu) |
0e60a699 | 415 | { |
3edb8f92 AF |
416 | CPUS390XState *env = &cpu->env; |
417 | ||
1bc22652 | 418 | kvm_s390_interrupt(cpu, KVM_S390_RESTART, 0); |
854e42f3 | 419 | s390_add_running_cpu(env); |
c08d7424 | 420 | qemu_cpu_kick(CPU(cpu)); |
0e60a699 AG |
421 | dprintf("DONE: SIGP cpu restart: %p\n", env); |
422 | return 0; | |
423 | } | |
424 | ||
a4e3ad19 | 425 | static int s390_store_status(CPUS390XState *env, uint32_t parameter) |
0e60a699 AG |
426 | { |
427 | /* XXX */ | |
428 | fprintf(stderr, "XXX SIGP store status\n"); | |
429 | return -1; | |
430 | } | |
431 | ||
1bc22652 | 432 | static int s390_cpu_initial_reset(S390CPU *cpu) |
0e60a699 | 433 | { |
1bc22652 | 434 | CPUS390XState *env = &cpu->env; |
d5900813 AG |
435 | int i; |
436 | ||
2fb70f6f | 437 | s390_del_running_cpu(env); |
1bc22652 | 438 | if (kvm_vcpu_ioctl(CPU(cpu), KVM_S390_INITIAL_RESET, NULL) < 0) { |
d5900813 AG |
439 | perror("cannot init reset vcpu"); |
440 | } | |
441 | ||
442 | /* Manually zero out all registers */ | |
443 | cpu_synchronize_state(env); | |
444 | for (i = 0; i < 16; i++) { | |
445 | env->regs[i] = 0; | |
446 | } | |
447 | ||
448 | dprintf("DONE: SIGP initial reset: %p\n", env); | |
449 | return 0; | |
0e60a699 AG |
450 | } |
451 | ||
f7575c96 | 452 | static int handle_sigp(S390CPU *cpu, struct kvm_run *run, uint8_t ipa1) |
0e60a699 | 453 | { |
f7575c96 | 454 | CPUS390XState *env = &cpu->env; |
0e60a699 AG |
455 | uint8_t order_code; |
456 | uint32_t parameter; | |
457 | uint16_t cpu_addr; | |
458 | uint8_t t; | |
459 | int r = -1; | |
45fa769b | 460 | S390CPU *target_cpu; |
a4e3ad19 | 461 | CPUS390XState *target_env; |
0e60a699 AG |
462 | |
463 | cpu_synchronize_state(env); | |
464 | ||
465 | /* get order code */ | |
466 | order_code = run->s390_sieic.ipb >> 28; | |
467 | if (order_code > 0) { | |
468 | order_code = env->regs[order_code]; | |
469 | } | |
470 | order_code += (run->s390_sieic.ipb & 0x0fff0000) >> 16; | |
471 | ||
472 | /* get parameters */ | |
473 | t = (ipa1 & 0xf0) >> 4; | |
474 | if (!(t % 2)) { | |
475 | t++; | |
476 | } | |
477 | ||
478 | parameter = env->regs[t] & 0x7ffffe00; | |
479 | cpu_addr = env->regs[ipa1 & 0x0f]; | |
480 | ||
45fa769b AF |
481 | target_cpu = s390_cpu_addr2state(cpu_addr); |
482 | if (target_cpu == NULL) { | |
0e60a699 AG |
483 | goto out; |
484 | } | |
45fa769b | 485 | target_env = &target_cpu->env; |
0e60a699 AG |
486 | |
487 | switch (order_code) { | |
488 | case SIGP_RESTART: | |
3edb8f92 | 489 | r = s390_cpu_restart(target_cpu); |
0e60a699 AG |
490 | break; |
491 | case SIGP_STORE_STATUS_ADDR: | |
492 | r = s390_store_status(target_env, parameter); | |
493 | break; | |
494 | case SIGP_SET_ARCH: | |
495 | /* make the caller panic */ | |
496 | return -1; | |
497 | case SIGP_INITIAL_CPU_RESET: | |
1bc22652 | 498 | r = s390_cpu_initial_reset(target_cpu); |
0e60a699 AG |
499 | break; |
500 | default: | |
a74cdab4 | 501 | fprintf(stderr, "KVM: unknown SIGP: 0x%x\n", order_code); |
0e60a699 AG |
502 | break; |
503 | } | |
504 | ||
505 | out: | |
f7575c96 | 506 | setcc(cpu, r ? 3 : 0); |
0e60a699 AG |
507 | return 0; |
508 | } | |
509 | ||
1bc22652 | 510 | static int handle_instruction(S390CPU *cpu, struct kvm_run *run) |
0e60a699 | 511 | { |
1bc22652 | 512 | CPUS390XState *env = &cpu->env; |
0e60a699 AG |
513 | unsigned int ipa0 = (run->s390_sieic.ipa & 0xff00); |
514 | uint8_t ipa1 = run->s390_sieic.ipa & 0x00ff; | |
515 | int ipb_code = (run->s390_sieic.ipb & 0x0fff0000) >> 16; | |
d7963c43 | 516 | int r = -1; |
0e60a699 AG |
517 | |
518 | dprintf("handle_instruction 0x%x 0x%x\n", run->s390_sieic.ipa, run->s390_sieic.ipb); | |
519 | switch (ipa0) { | |
520 | case IPA0_PRIV: | |
1bc22652 | 521 | r = handle_priv(cpu, run, ipa1); |
0e60a699 AG |
522 | break; |
523 | case IPA0_DIAG: | |
524 | r = handle_diag(env, run, ipb_code); | |
525 | break; | |
526 | case IPA0_SIGP: | |
f7575c96 | 527 | r = handle_sigp(cpu, run, ipa1); |
0e60a699 AG |
528 | break; |
529 | } | |
530 | ||
531 | if (r < 0) { | |
1bc22652 | 532 | enter_pgmcheck(cpu, 0x0001); |
0e60a699 | 533 | } |
359507ee | 534 | return 0; |
0e60a699 AG |
535 | } |
536 | ||
f7575c96 | 537 | static bool is_special_wait_psw(CPUState *cs) |
eca3ed03 CB |
538 | { |
539 | /* signal quiesce */ | |
f7575c96 | 540 | return cs->kvm_run->psw_addr == 0xfffUL; |
eca3ed03 CB |
541 | } |
542 | ||
1bc22652 | 543 | static int handle_intercept(S390CPU *cpu) |
0e60a699 | 544 | { |
1bc22652 | 545 | CPUS390XState *env = &cpu->env; |
f7575c96 AF |
546 | CPUState *cs = CPU(cpu); |
547 | struct kvm_run *run = cs->kvm_run; | |
0e60a699 AG |
548 | int icpt_code = run->s390_sieic.icptcode; |
549 | int r = 0; | |
550 | ||
81f7c56c | 551 | dprintf("intercept: 0x%x (at 0x%lx)\n", icpt_code, |
f7575c96 | 552 | (long)cs->kvm_run->psw_addr); |
0e60a699 AG |
553 | switch (icpt_code) { |
554 | case ICPT_INSTRUCTION: | |
1bc22652 | 555 | r = handle_instruction(cpu, run); |
0e60a699 AG |
556 | break; |
557 | case ICPT_WAITPSW: | |
eca3ed03 | 558 | if (s390_del_running_cpu(env) == 0 && |
f7575c96 | 559 | is_special_wait_psw(cs)) { |
eca3ed03 CB |
560 | qemu_system_shutdown_request(); |
561 | } | |
562 | r = EXCP_HALTED; | |
563 | break; | |
854e42f3 CB |
564 | case ICPT_CPU_STOP: |
565 | if (s390_del_running_cpu(env) == 0) { | |
566 | qemu_system_shutdown_request(); | |
567 | } | |
568 | r = EXCP_HALTED; | |
0e60a699 AG |
569 | break; |
570 | case ICPT_SOFT_INTERCEPT: | |
571 | fprintf(stderr, "KVM unimplemented icpt SOFT\n"); | |
572 | exit(1); | |
573 | break; | |
0e60a699 AG |
574 | case ICPT_IO: |
575 | fprintf(stderr, "KVM unimplemented icpt IO\n"); | |
576 | exit(1); | |
577 | break; | |
578 | default: | |
579 | fprintf(stderr, "Unknown intercept code: %d\n", icpt_code); | |
580 | exit(1); | |
581 | break; | |
582 | } | |
583 | ||
584 | return r; | |
585 | } | |
586 | ||
20d695a9 | 587 | int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) |
0e60a699 | 588 | { |
20d695a9 | 589 | S390CPU *cpu = S390_CPU(cs); |
0e60a699 AG |
590 | int ret = 0; |
591 | ||
592 | switch (run->exit_reason) { | |
593 | case KVM_EXIT_S390_SIEIC: | |
1bc22652 | 594 | ret = handle_intercept(cpu); |
0e60a699 AG |
595 | break; |
596 | case KVM_EXIT_S390_RESET: | |
add142e0 | 597 | qemu_system_reset_request(); |
0e60a699 AG |
598 | break; |
599 | default: | |
600 | fprintf(stderr, "Unknown KVM exit: %d\n", run->exit_reason); | |
601 | break; | |
602 | } | |
603 | ||
bb4ea393 JK |
604 | if (ret == 0) { |
605 | ret = EXCP_INTERRUPT; | |
bb4ea393 | 606 | } |
0e60a699 AG |
607 | return ret; |
608 | } | |
4513d923 | 609 | |
20d695a9 | 610 | bool kvm_arch_stop_on_emulation_error(CPUState *cpu) |
4513d923 GN |
611 | { |
612 | return true; | |
613 | } | |
a1b87fe0 | 614 | |
20d695a9 | 615 | int kvm_arch_on_sigbus_vcpu(CPUState *cpu, int code, void *addr) |
a1b87fe0 JK |
616 | { |
617 | return 1; | |
618 | } | |
619 | ||
620 | int kvm_arch_on_sigbus(int code, void *addr) | |
621 | { | |
622 | return 1; | |
623 | } |