root / target-s390x / kvm.c @ 94ad5b00
History | View | Annotate | Download (12.2 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 | 94a8d39a | Jan Kiszka | const KVMCapabilityInfo kvm_arch_required_capabilities[] = {
|
74 | 94a8d39a | Jan Kiszka | KVM_CAP_LAST_INFO |
75 | 94a8d39a | Jan Kiszka | }; |
76 | 94a8d39a | Jan Kiszka | |
77 | cad1e282 | Jan Kiszka | int kvm_arch_init(KVMState *s)
|
78 | 0e60a699 | Alexander Graf | { |
79 | 0e60a699 | Alexander Graf | return 0; |
80 | 0e60a699 | Alexander Graf | } |
81 | 0e60a699 | Alexander Graf | |
82 | 0e60a699 | Alexander Graf | int kvm_arch_init_vcpu(CPUState *env)
|
83 | 0e60a699 | Alexander Graf | { |
84 | 0e60a699 | Alexander Graf | int ret = 0; |
85 | 0e60a699 | Alexander Graf | |
86 | 0e60a699 | Alexander Graf | if (kvm_vcpu_ioctl(env, KVM_S390_INITIAL_RESET, NULL) < 0) { |
87 | 0e60a699 | Alexander Graf | perror("cannot init reset vcpu");
|
88 | 0e60a699 | Alexander Graf | } |
89 | 0e60a699 | Alexander Graf | |
90 | 0e60a699 | Alexander Graf | return ret;
|
91 | 0e60a699 | Alexander Graf | } |
92 | 0e60a699 | Alexander Graf | |
93 | 0e60a699 | Alexander Graf | void kvm_arch_reset_vcpu(CPUState *env)
|
94 | 0e60a699 | Alexander Graf | { |
95 | 0e60a699 | Alexander Graf | /* FIXME: add code to reset vcpu. */
|
96 | 0e60a699 | Alexander Graf | } |
97 | 0e60a699 | Alexander Graf | |
98 | ea375f9a | Jan Kiszka | int kvm_arch_put_registers(CPUState *env, int level) |
99 | 0e60a699 | Alexander Graf | { |
100 | 0e60a699 | Alexander Graf | struct kvm_regs regs;
|
101 | 0e60a699 | Alexander Graf | int ret;
|
102 | 0e60a699 | Alexander Graf | int i;
|
103 | 0e60a699 | Alexander Graf | |
104 | 0e60a699 | Alexander Graf | ret = kvm_vcpu_ioctl(env, KVM_GET_REGS, ®s); |
105 | 0e60a699 | Alexander Graf | if (ret < 0) { |
106 | 0e60a699 | Alexander Graf | return ret;
|
107 | 0e60a699 | Alexander Graf | } |
108 | 0e60a699 | Alexander Graf | |
109 | 0e60a699 | Alexander Graf | for (i = 0; i < 16; i++) { |
110 | 0e60a699 | Alexander Graf | regs.gprs[i] = env->regs[i]; |
111 | 0e60a699 | Alexander Graf | } |
112 | 0e60a699 | Alexander Graf | |
113 | 0e60a699 | Alexander Graf | ret = kvm_vcpu_ioctl(env, KVM_SET_REGS, ®s); |
114 | 0e60a699 | Alexander Graf | if (ret < 0) { |
115 | 0e60a699 | Alexander Graf | return ret;
|
116 | 0e60a699 | Alexander Graf | } |
117 | 0e60a699 | Alexander Graf | |
118 | 0e60a699 | Alexander Graf | env->kvm_run->psw_addr = env->psw.addr; |
119 | 0e60a699 | Alexander Graf | env->kvm_run->psw_mask = env->psw.mask; |
120 | 0e60a699 | Alexander Graf | |
121 | 0e60a699 | Alexander Graf | return ret;
|
122 | 0e60a699 | Alexander Graf | } |
123 | 0e60a699 | Alexander Graf | |
124 | 0e60a699 | Alexander Graf | int kvm_arch_get_registers(CPUState *env)
|
125 | 0e60a699 | Alexander Graf | { |
126 | 6c33286a | Alexander Graf | int ret;
|
127 | 0e60a699 | Alexander Graf | struct kvm_regs regs;
|
128 | 0e60a699 | Alexander Graf | int i;
|
129 | 0e60a699 | Alexander Graf | |
130 | 0e60a699 | Alexander Graf | ret = kvm_vcpu_ioctl(env, KVM_GET_REGS, ®s); |
131 | 0e60a699 | Alexander Graf | if (ret < 0) { |
132 | 0e60a699 | Alexander Graf | return ret;
|
133 | 0e60a699 | Alexander Graf | } |
134 | 0e60a699 | Alexander Graf | |
135 | 0e60a699 | Alexander Graf | for (i = 0; i < 16; i++) { |
136 | 0e60a699 | Alexander Graf | env->regs[i] = regs.gprs[i]; |
137 | 0e60a699 | Alexander Graf | } |
138 | 0e60a699 | Alexander Graf | |
139 | 0e60a699 | Alexander Graf | env->psw.addr = env->kvm_run->psw_addr; |
140 | 0e60a699 | Alexander Graf | env->psw.mask = env->kvm_run->psw_mask; |
141 | 0e60a699 | Alexander Graf | |
142 | 0e60a699 | Alexander Graf | return 0; |
143 | 0e60a699 | Alexander Graf | } |
144 | 0e60a699 | Alexander Graf | |
145 | 0e60a699 | Alexander Graf | int kvm_arch_insert_sw_breakpoint(CPUState *env, struct kvm_sw_breakpoint *bp) |
146 | 0e60a699 | Alexander Graf | { |
147 | 0e60a699 | Alexander Graf | static const uint8_t diag_501[] = {0x83, 0x24, 0x05, 0x01}; |
148 | 0e60a699 | Alexander Graf | |
149 | 0e60a699 | Alexander Graf | if (cpu_memory_rw_debug(env, bp->pc, (uint8_t *)&bp->saved_insn, 4, 0) || |
150 | 0e60a699 | Alexander Graf | cpu_memory_rw_debug(env, bp->pc, (uint8_t *)diag_501, 4, 1)) { |
151 | 0e60a699 | Alexander Graf | return -EINVAL;
|
152 | 0e60a699 | Alexander Graf | } |
153 | 0e60a699 | Alexander Graf | return 0; |
154 | 0e60a699 | Alexander Graf | } |
155 | 0e60a699 | Alexander Graf | |
156 | 0e60a699 | Alexander Graf | int kvm_arch_remove_sw_breakpoint(CPUState *env, struct kvm_sw_breakpoint *bp) |
157 | 0e60a699 | Alexander Graf | { |
158 | 0e60a699 | Alexander Graf | uint8_t t[4];
|
159 | 0e60a699 | Alexander Graf | static const uint8_t diag_501[] = {0x83, 0x24, 0x05, 0x01}; |
160 | 0e60a699 | Alexander Graf | |
161 | 0e60a699 | Alexander Graf | if (cpu_memory_rw_debug(env, bp->pc, t, 4, 0)) { |
162 | 0e60a699 | Alexander Graf | return -EINVAL;
|
163 | 0e60a699 | Alexander Graf | } else if (memcmp(t, diag_501, 4)) { |
164 | 0e60a699 | Alexander Graf | return -EINVAL;
|
165 | 0e60a699 | Alexander Graf | } else if (cpu_memory_rw_debug(env, bp->pc, (uint8_t *)&bp->saved_insn, 1, 1)) { |
166 | 0e60a699 | Alexander Graf | return -EINVAL;
|
167 | 0e60a699 | Alexander Graf | } |
168 | 0e60a699 | Alexander Graf | |
169 | 0e60a699 | Alexander Graf | return 0; |
170 | 0e60a699 | Alexander Graf | } |
171 | 0e60a699 | Alexander Graf | |
172 | 7a39fe58 | Jan Kiszka | void kvm_arch_pre_run(CPUState *env, struct kvm_run *run) |
173 | 0e60a699 | Alexander Graf | { |
174 | 0e60a699 | Alexander Graf | } |
175 | 0e60a699 | Alexander Graf | |
176 | 7a39fe58 | Jan Kiszka | void kvm_arch_post_run(CPUState *env, struct kvm_run *run) |
177 | 0e60a699 | Alexander Graf | { |
178 | 0e60a699 | Alexander Graf | } |
179 | 0e60a699 | Alexander Graf | |
180 | 0af691d7 | Marcelo Tosatti | int kvm_arch_process_irqchip_events(CPUState *env)
|
181 | 0af691d7 | Marcelo Tosatti | { |
182 | 0af691d7 | Marcelo Tosatti | return 0; |
183 | 0af691d7 | Marcelo Tosatti | } |
184 | 0af691d7 | Marcelo Tosatti | |
185 | 0e60a699 | Alexander Graf | static void kvm_s390_interrupt_internal(CPUState *env, int type, uint32_t parm, |
186 | 0e60a699 | Alexander Graf | uint64_t parm64, int vm)
|
187 | 0e60a699 | Alexander Graf | { |
188 | 0e60a699 | Alexander Graf | struct kvm_s390_interrupt kvmint;
|
189 | 0e60a699 | Alexander Graf | int r;
|
190 | 0e60a699 | Alexander Graf | |
191 | 0e60a699 | Alexander Graf | if (!env->kvm_state) {
|
192 | 0e60a699 | Alexander Graf | return;
|
193 | 0e60a699 | Alexander Graf | } |
194 | 0e60a699 | Alexander Graf | |
195 | 0e60a699 | Alexander Graf | env->halted = 0;
|
196 | ee0dc6d3 | Blue Swirl | env->exception_index = -1;
|
197 | 94ad5b00 | Paolo Bonzini | qemu_cpu_kick(env); |
198 | 0e60a699 | Alexander Graf | |
199 | 0e60a699 | Alexander Graf | kvmint.type = type; |
200 | 0e60a699 | Alexander Graf | kvmint.parm = parm; |
201 | 0e60a699 | Alexander Graf | kvmint.parm64 = parm64; |
202 | 0e60a699 | Alexander Graf | |
203 | 0e60a699 | Alexander Graf | if (vm) {
|
204 | 0e60a699 | Alexander Graf | r = kvm_vm_ioctl(env->kvm_state, KVM_S390_INTERRUPT, &kvmint); |
205 | 0e60a699 | Alexander Graf | } else {
|
206 | 0e60a699 | Alexander Graf | r = kvm_vcpu_ioctl(env, KVM_S390_INTERRUPT, &kvmint); |
207 | 0e60a699 | Alexander Graf | } |
208 | 0e60a699 | Alexander Graf | |
209 | 0e60a699 | Alexander Graf | if (r < 0) { |
210 | 0e60a699 | Alexander Graf | fprintf(stderr, "KVM failed to inject interrupt\n");
|
211 | 0e60a699 | Alexander Graf | exit(1);
|
212 | 0e60a699 | Alexander Graf | } |
213 | 0e60a699 | Alexander Graf | } |
214 | 0e60a699 | Alexander Graf | |
215 | 0e60a699 | Alexander Graf | void kvm_s390_virtio_irq(CPUState *env, int config_change, uint64_t token) |
216 | 0e60a699 | Alexander Graf | { |
217 | 0e60a699 | Alexander Graf | kvm_s390_interrupt_internal(env, KVM_S390_INT_VIRTIO, config_change, |
218 | 0e60a699 | Alexander Graf | token, 1);
|
219 | 0e60a699 | Alexander Graf | } |
220 | 0e60a699 | Alexander Graf | |
221 | 0e60a699 | Alexander Graf | static void kvm_s390_interrupt(CPUState *env, int type, uint32_t code) |
222 | 0e60a699 | Alexander Graf | { |
223 | 0e60a699 | Alexander Graf | kvm_s390_interrupt_internal(env, type, code, 0, 0); |
224 | 0e60a699 | Alexander Graf | } |
225 | 0e60a699 | Alexander Graf | |
226 | 0e60a699 | Alexander Graf | static void enter_pgmcheck(CPUState *env, uint16_t code) |
227 | 0e60a699 | Alexander Graf | { |
228 | 0e60a699 | Alexander Graf | kvm_s390_interrupt(env, KVM_S390_PROGRAM_INT, code); |
229 | 0e60a699 | Alexander Graf | } |
230 | 0e60a699 | Alexander Graf | |
231 | 0e60a699 | Alexander Graf | static void setcc(CPUState *env, uint64_t cc) |
232 | 0e60a699 | Alexander Graf | { |
233 | 0e60a699 | Alexander Graf | env->kvm_run->psw_mask &= ~(3ul << 44); |
234 | 0e60a699 | Alexander Graf | env->kvm_run->psw_mask |= (cc & 3) << 44; |
235 | 0e60a699 | Alexander Graf | |
236 | 0e60a699 | Alexander Graf | env->psw.mask &= ~(3ul << 44); |
237 | 0e60a699 | Alexander Graf | env->psw.mask |= (cc & 3) << 44; |
238 | 0e60a699 | Alexander Graf | } |
239 | 0e60a699 | Alexander Graf | |
240 | 0e60a699 | Alexander Graf | static int sclp_service_call(CPUState *env, struct kvm_run *run, uint16_t ipbh0) |
241 | 0e60a699 | Alexander Graf | { |
242 | 0e60a699 | Alexander Graf | uint32_t sccb; |
243 | 0e60a699 | Alexander Graf | uint64_t code; |
244 | 0e60a699 | Alexander Graf | int r = 0; |
245 | 0e60a699 | Alexander Graf | |
246 | 0e60a699 | Alexander Graf | cpu_synchronize_state(env); |
247 | 0e60a699 | Alexander Graf | sccb = env->regs[ipbh0 & 0xf];
|
248 | 0e60a699 | Alexander Graf | code = env->regs[(ipbh0 & 0xf0) >> 4]; |
249 | 0e60a699 | Alexander Graf | |
250 | 0e60a699 | Alexander Graf | dprintf("sclp(0x%x, 0x%lx)\n", sccb, code);
|
251 | 0e60a699 | Alexander Graf | |
252 | 0e60a699 | Alexander Graf | if (sccb & ~0x7ffffff8ul) { |
253 | 0e60a699 | Alexander Graf | fprintf(stderr, "KVM: invalid sccb address 0x%x\n", sccb);
|
254 | 0e60a699 | Alexander Graf | r = -1;
|
255 | 0e60a699 | Alexander Graf | goto out;
|
256 | 0e60a699 | Alexander Graf | } |
257 | 0e60a699 | Alexander Graf | |
258 | 0e60a699 | Alexander Graf | switch(code) {
|
259 | 0e60a699 | Alexander Graf | case SCLP_CMDW_READ_SCP_INFO:
|
260 | 0e60a699 | Alexander Graf | case SCLP_CMDW_READ_SCP_INFO_FORCED:
|
261 | 0e60a699 | Alexander Graf | stw_phys(sccb + SCP_MEM_CODE, ram_size >> 20);
|
262 | 0e60a699 | Alexander Graf | stb_phys(sccb + SCP_INCREMENT, 1);
|
263 | 0e60a699 | Alexander Graf | stw_phys(sccb + SCP_RESPONSE_CODE, 0x10);
|
264 | 0e60a699 | Alexander Graf | setcc(env, 0);
|
265 | 0e60a699 | Alexander Graf | |
266 | 0e60a699 | Alexander Graf | kvm_s390_interrupt_internal(env, KVM_S390_INT_SERVICE, |
267 | 0e60a699 | Alexander Graf | sccb & ~3, 0, 1); |
268 | 0e60a699 | Alexander Graf | break;
|
269 | 0e60a699 | Alexander Graf | default:
|
270 | 0e60a699 | Alexander Graf | dprintf("KVM: invalid sclp call 0x%x / 0x%lx\n", sccb, code);
|
271 | 0e60a699 | Alexander Graf | r = -1;
|
272 | 0e60a699 | Alexander Graf | break;
|
273 | 0e60a699 | Alexander Graf | } |
274 | 0e60a699 | Alexander Graf | |
275 | 0e60a699 | Alexander Graf | out:
|
276 | 0e60a699 | Alexander Graf | if (r < 0) { |
277 | 0e60a699 | Alexander Graf | setcc(env, 3);
|
278 | 0e60a699 | Alexander Graf | } |
279 | 0e60a699 | Alexander Graf | return 0; |
280 | 0e60a699 | Alexander Graf | } |
281 | 0e60a699 | Alexander Graf | |
282 | 0e60a699 | Alexander Graf | static int handle_priv(CPUState *env, struct kvm_run *run, uint8_t ipa1) |
283 | 0e60a699 | Alexander Graf | { |
284 | 0e60a699 | Alexander Graf | int r = 0; |
285 | 0e60a699 | Alexander Graf | uint16_t ipbh0 = (run->s390_sieic.ipb & 0xffff0000) >> 16; |
286 | 0e60a699 | Alexander Graf | |
287 | 0e60a699 | Alexander Graf | dprintf("KVM: PRIV: %d\n", ipa1);
|
288 | 0e60a699 | Alexander Graf | switch (ipa1) {
|
289 | 0e60a699 | Alexander Graf | case PRIV_SCLP_CALL:
|
290 | 0e60a699 | Alexander Graf | r = sclp_service_call(env, run, ipbh0); |
291 | 0e60a699 | Alexander Graf | break;
|
292 | 0e60a699 | Alexander Graf | default:
|
293 | 0e60a699 | Alexander Graf | dprintf("KVM: unknown PRIV: 0x%x\n", ipa1);
|
294 | 0e60a699 | Alexander Graf | r = -1;
|
295 | 0e60a699 | Alexander Graf | break;
|
296 | 0e60a699 | Alexander Graf | } |
297 | 0e60a699 | Alexander Graf | |
298 | 0e60a699 | Alexander Graf | return r;
|
299 | 0e60a699 | Alexander Graf | } |
300 | 0e60a699 | Alexander Graf | |
301 | 0e60a699 | Alexander Graf | static int handle_hypercall(CPUState *env, struct kvm_run *run) |
302 | 0e60a699 | Alexander Graf | { |
303 | 0e60a699 | Alexander Graf | int r;
|
304 | 0e60a699 | Alexander Graf | |
305 | 0e60a699 | Alexander Graf | cpu_synchronize_state(env); |
306 | 0e60a699 | Alexander Graf | r = s390_virtio_hypercall(env); |
307 | 0e60a699 | Alexander Graf | |
308 | 0e60a699 | Alexander Graf | return r;
|
309 | 0e60a699 | Alexander Graf | } |
310 | 0e60a699 | Alexander Graf | |
311 | 0e60a699 | Alexander Graf | static int handle_diag(CPUState *env, struct kvm_run *run, int ipb_code) |
312 | 0e60a699 | Alexander Graf | { |
313 | 0e60a699 | Alexander Graf | int r = 0; |
314 | 0e60a699 | Alexander Graf | |
315 | 0e60a699 | Alexander Graf | switch (ipb_code) {
|
316 | 0e60a699 | Alexander Graf | case DIAG_KVM_HYPERCALL:
|
317 | 0e60a699 | Alexander Graf | r = handle_hypercall(env, run); |
318 | 0e60a699 | Alexander Graf | break;
|
319 | 0e60a699 | Alexander Graf | case DIAG_KVM_BREAKPOINT:
|
320 | 0e60a699 | Alexander Graf | sleep(10);
|
321 | 0e60a699 | Alexander Graf | break;
|
322 | 0e60a699 | Alexander Graf | default:
|
323 | 0e60a699 | Alexander Graf | dprintf("KVM: unknown DIAG: 0x%x\n", ipb_code);
|
324 | 0e60a699 | Alexander Graf | r = -1;
|
325 | 0e60a699 | Alexander Graf | break;
|
326 | 0e60a699 | Alexander Graf | } |
327 | 0e60a699 | Alexander Graf | |
328 | 0e60a699 | Alexander Graf | return r;
|
329 | 0e60a699 | Alexander Graf | } |
330 | 0e60a699 | Alexander Graf | |
331 | 0e60a699 | Alexander Graf | static int s390_cpu_restart(CPUState *env) |
332 | 0e60a699 | Alexander Graf | { |
333 | 0e60a699 | Alexander Graf | kvm_s390_interrupt(env, KVM_S390_RESTART, 0);
|
334 | 0e60a699 | Alexander Graf | env->halted = 0;
|
335 | ee0dc6d3 | Blue Swirl | env->exception_index = -1;
|
336 | 0e60a699 | Alexander Graf | qemu_cpu_kick(env); |
337 | 0e60a699 | Alexander Graf | dprintf("DONE: SIGP cpu restart: %p\n", env);
|
338 | 0e60a699 | Alexander Graf | return 0; |
339 | 0e60a699 | Alexander Graf | } |
340 | 0e60a699 | Alexander Graf | |
341 | 0e60a699 | Alexander Graf | static int s390_store_status(CPUState *env, uint32_t parameter) |
342 | 0e60a699 | Alexander Graf | { |
343 | 0e60a699 | Alexander Graf | /* XXX */
|
344 | 0e60a699 | Alexander Graf | fprintf(stderr, "XXX SIGP store status\n");
|
345 | 0e60a699 | Alexander Graf | return -1; |
346 | 0e60a699 | Alexander Graf | } |
347 | 0e60a699 | Alexander Graf | |
348 | 0e60a699 | Alexander Graf | static int s390_cpu_initial_reset(CPUState *env) |
349 | 0e60a699 | Alexander Graf | { |
350 | d5900813 | Alexander Graf | int i;
|
351 | d5900813 | Alexander Graf | |
352 | d5900813 | Alexander Graf | if (kvm_vcpu_ioctl(env, KVM_S390_INITIAL_RESET, NULL) < 0) { |
353 | d5900813 | Alexander Graf | perror("cannot init reset vcpu");
|
354 | d5900813 | Alexander Graf | } |
355 | d5900813 | Alexander Graf | |
356 | d5900813 | Alexander Graf | /* Manually zero out all registers */
|
357 | d5900813 | Alexander Graf | cpu_synchronize_state(env); |
358 | d5900813 | Alexander Graf | for (i = 0; i < 16; i++) { |
359 | d5900813 | Alexander Graf | env->regs[i] = 0;
|
360 | d5900813 | Alexander Graf | } |
361 | d5900813 | Alexander Graf | |
362 | d5900813 | Alexander Graf | dprintf("DONE: SIGP initial reset: %p\n", env);
|
363 | d5900813 | Alexander Graf | return 0; |
364 | 0e60a699 | Alexander Graf | } |
365 | 0e60a699 | Alexander Graf | |
366 | 0e60a699 | Alexander Graf | static int handle_sigp(CPUState *env, struct kvm_run *run, uint8_t ipa1) |
367 | 0e60a699 | Alexander Graf | { |
368 | 0e60a699 | Alexander Graf | uint8_t order_code; |
369 | 0e60a699 | Alexander Graf | uint32_t parameter; |
370 | 0e60a699 | Alexander Graf | uint16_t cpu_addr; |
371 | 0e60a699 | Alexander Graf | uint8_t t; |
372 | 0e60a699 | Alexander Graf | int r = -1; |
373 | 0e60a699 | Alexander Graf | CPUState *target_env; |
374 | 0e60a699 | Alexander Graf | |
375 | 0e60a699 | Alexander Graf | cpu_synchronize_state(env); |
376 | 0e60a699 | Alexander Graf | |
377 | 0e60a699 | Alexander Graf | /* get order code */
|
378 | 0e60a699 | Alexander Graf | order_code = run->s390_sieic.ipb >> 28;
|
379 | 0e60a699 | Alexander Graf | if (order_code > 0) { |
380 | 0e60a699 | Alexander Graf | order_code = env->regs[order_code]; |
381 | 0e60a699 | Alexander Graf | } |
382 | 0e60a699 | Alexander Graf | order_code += (run->s390_sieic.ipb & 0x0fff0000) >> 16; |
383 | 0e60a699 | Alexander Graf | |
384 | 0e60a699 | Alexander Graf | /* get parameters */
|
385 | 0e60a699 | Alexander Graf | t = (ipa1 & 0xf0) >> 4; |
386 | 0e60a699 | Alexander Graf | if (!(t % 2)) { |
387 | 0e60a699 | Alexander Graf | t++; |
388 | 0e60a699 | Alexander Graf | } |
389 | 0e60a699 | Alexander Graf | |
390 | 0e60a699 | Alexander Graf | parameter = env->regs[t] & 0x7ffffe00;
|
391 | 0e60a699 | Alexander Graf | cpu_addr = env->regs[ipa1 & 0x0f];
|
392 | 0e60a699 | Alexander Graf | |
393 | 0e60a699 | Alexander Graf | target_env = s390_cpu_addr2state(cpu_addr); |
394 | 0e60a699 | Alexander Graf | if (!target_env) {
|
395 | 0e60a699 | Alexander Graf | goto out;
|
396 | 0e60a699 | Alexander Graf | } |
397 | 0e60a699 | Alexander Graf | |
398 | 0e60a699 | Alexander Graf | switch (order_code) {
|
399 | 0e60a699 | Alexander Graf | case SIGP_RESTART:
|
400 | 0e60a699 | Alexander Graf | r = s390_cpu_restart(target_env); |
401 | 0e60a699 | Alexander Graf | break;
|
402 | 0e60a699 | Alexander Graf | case SIGP_STORE_STATUS_ADDR:
|
403 | 0e60a699 | Alexander Graf | r = s390_store_status(target_env, parameter); |
404 | 0e60a699 | Alexander Graf | break;
|
405 | 0e60a699 | Alexander Graf | case SIGP_SET_ARCH:
|
406 | 0e60a699 | Alexander Graf | /* make the caller panic */
|
407 | 0e60a699 | Alexander Graf | return -1; |
408 | 0e60a699 | Alexander Graf | case SIGP_INITIAL_CPU_RESET:
|
409 | 0e60a699 | Alexander Graf | r = s390_cpu_initial_reset(target_env); |
410 | 0e60a699 | Alexander Graf | break;
|
411 | 0e60a699 | Alexander Graf | default:
|
412 | 0e60a699 | Alexander Graf | fprintf(stderr, "KVM: unknown SIGP: 0x%x\n", ipa1);
|
413 | 0e60a699 | Alexander Graf | break;
|
414 | 0e60a699 | Alexander Graf | } |
415 | 0e60a699 | Alexander Graf | |
416 | 0e60a699 | Alexander Graf | out:
|
417 | 0e60a699 | Alexander Graf | setcc(env, r ? 3 : 0); |
418 | 0e60a699 | Alexander Graf | return 0; |
419 | 0e60a699 | Alexander Graf | } |
420 | 0e60a699 | Alexander Graf | |
421 | 0e60a699 | Alexander Graf | static int handle_instruction(CPUState *env, struct kvm_run *run) |
422 | 0e60a699 | Alexander Graf | { |
423 | 0e60a699 | Alexander Graf | unsigned int ipa0 = (run->s390_sieic.ipa & 0xff00); |
424 | 0e60a699 | Alexander Graf | uint8_t ipa1 = run->s390_sieic.ipa & 0x00ff;
|
425 | 0e60a699 | Alexander Graf | int ipb_code = (run->s390_sieic.ipb & 0x0fff0000) >> 16; |
426 | d7963c43 | Alexander Graf | int r = -1; |
427 | 0e60a699 | Alexander Graf | |
428 | 0e60a699 | Alexander Graf | dprintf("handle_instruction 0x%x 0x%x\n", run->s390_sieic.ipa, run->s390_sieic.ipb);
|
429 | 0e60a699 | Alexander Graf | switch (ipa0) {
|
430 | 0e60a699 | Alexander Graf | case IPA0_PRIV:
|
431 | 0e60a699 | Alexander Graf | r = handle_priv(env, run, ipa1); |
432 | 0e60a699 | Alexander Graf | break;
|
433 | 0e60a699 | Alexander Graf | case IPA0_DIAG:
|
434 | 0e60a699 | Alexander Graf | r = handle_diag(env, run, ipb_code); |
435 | 0e60a699 | Alexander Graf | break;
|
436 | 0e60a699 | Alexander Graf | case IPA0_SIGP:
|
437 | 0e60a699 | Alexander Graf | r = handle_sigp(env, run, ipa1); |
438 | 0e60a699 | Alexander Graf | break;
|
439 | 0e60a699 | Alexander Graf | } |
440 | 0e60a699 | Alexander Graf | |
441 | 0e60a699 | Alexander Graf | if (r < 0) { |
442 | 0e60a699 | Alexander Graf | enter_pgmcheck(env, 0x0001);
|
443 | 0e60a699 | Alexander Graf | } |
444 | 0e60a699 | Alexander Graf | return r;
|
445 | 0e60a699 | Alexander Graf | } |
446 | 0e60a699 | Alexander Graf | |
447 | 0e60a699 | Alexander Graf | static int handle_intercept(CPUState *env) |
448 | 0e60a699 | Alexander Graf | { |
449 | 0e60a699 | Alexander Graf | struct kvm_run *run = env->kvm_run;
|
450 | 0e60a699 | Alexander Graf | int icpt_code = run->s390_sieic.icptcode;
|
451 | 0e60a699 | Alexander Graf | int r = 0; |
452 | 0e60a699 | Alexander Graf | |
453 | 0e60a699 | Alexander Graf | dprintf("intercept: 0x%x (at 0x%lx)\n", icpt_code, env->kvm_run->psw_addr);
|
454 | 0e60a699 | Alexander Graf | switch (icpt_code) {
|
455 | 0e60a699 | Alexander Graf | case ICPT_INSTRUCTION:
|
456 | 0e60a699 | Alexander Graf | r = handle_instruction(env, run); |
457 | 0e60a699 | Alexander Graf | break;
|
458 | 0e60a699 | Alexander Graf | case ICPT_WAITPSW:
|
459 | 0e60a699 | Alexander Graf | /* XXX What to do on system shutdown? */
|
460 | 0e60a699 | Alexander Graf | env->halted = 1;
|
461 | 0e60a699 | Alexander Graf | env->exception_index = EXCP_HLT; |
462 | 0e60a699 | Alexander Graf | break;
|
463 | 0e60a699 | Alexander Graf | case ICPT_SOFT_INTERCEPT:
|
464 | 0e60a699 | Alexander Graf | fprintf(stderr, "KVM unimplemented icpt SOFT\n");
|
465 | 0e60a699 | Alexander Graf | exit(1);
|
466 | 0e60a699 | Alexander Graf | break;
|
467 | 0e60a699 | Alexander Graf | case ICPT_CPU_STOP:
|
468 | 0e60a699 | Alexander Graf | qemu_system_shutdown_request(); |
469 | 0e60a699 | Alexander Graf | break;
|
470 | 0e60a699 | Alexander Graf | case ICPT_IO:
|
471 | 0e60a699 | Alexander Graf | fprintf(stderr, "KVM unimplemented icpt IO\n");
|
472 | 0e60a699 | Alexander Graf | exit(1);
|
473 | 0e60a699 | Alexander Graf | break;
|
474 | 0e60a699 | Alexander Graf | default:
|
475 | 0e60a699 | Alexander Graf | fprintf(stderr, "Unknown intercept code: %d\n", icpt_code);
|
476 | 0e60a699 | Alexander Graf | exit(1);
|
477 | 0e60a699 | Alexander Graf | break;
|
478 | 0e60a699 | Alexander Graf | } |
479 | 0e60a699 | Alexander Graf | |
480 | 0e60a699 | Alexander Graf | return r;
|
481 | 0e60a699 | Alexander Graf | } |
482 | 0e60a699 | Alexander Graf | |
483 | 0e60a699 | Alexander Graf | int kvm_arch_handle_exit(CPUState *env, struct kvm_run *run) |
484 | 0e60a699 | Alexander Graf | { |
485 | 0e60a699 | Alexander Graf | int ret = 0; |
486 | 0e60a699 | Alexander Graf | |
487 | 0e60a699 | Alexander Graf | switch (run->exit_reason) {
|
488 | 0e60a699 | Alexander Graf | case KVM_EXIT_S390_SIEIC:
|
489 | 0e60a699 | Alexander Graf | ret = handle_intercept(env); |
490 | 0e60a699 | Alexander Graf | break;
|
491 | 0e60a699 | Alexander Graf | case KVM_EXIT_S390_RESET:
|
492 | 0e60a699 | Alexander Graf | fprintf(stderr, "RESET not implemented\n");
|
493 | 0e60a699 | Alexander Graf | exit(1);
|
494 | 0e60a699 | Alexander Graf | break;
|
495 | 0e60a699 | Alexander Graf | default:
|
496 | 0e60a699 | Alexander Graf | fprintf(stderr, "Unknown KVM exit: %d\n", run->exit_reason);
|
497 | 0e60a699 | Alexander Graf | break;
|
498 | 0e60a699 | Alexander Graf | } |
499 | 0e60a699 | Alexander Graf | |
500 | 0e60a699 | Alexander Graf | return ret;
|
501 | 0e60a699 | Alexander Graf | } |
502 | 4513d923 | Gleb Natapov | |
503 | 4513d923 | Gleb Natapov | bool kvm_arch_stop_on_emulation_error(CPUState *env)
|
504 | 4513d923 | Gleb Natapov | { |
505 | 4513d923 | Gleb Natapov | return true; |
506 | 4513d923 | Gleb Natapov | } |
507 | a1b87fe0 | Jan Kiszka | |
508 | a1b87fe0 | Jan Kiszka | int kvm_arch_on_sigbus_vcpu(CPUState *env, int code, void *addr) |
509 | a1b87fe0 | Jan Kiszka | { |
510 | a1b87fe0 | Jan Kiszka | return 1; |
511 | a1b87fe0 | Jan Kiszka | } |
512 | a1b87fe0 | Jan Kiszka | |
513 | a1b87fe0 | Jan Kiszka | int kvm_arch_on_sigbus(int code, void *addr) |
514 | a1b87fe0 | Jan Kiszka | { |
515 | a1b87fe0 | Jan Kiszka | return 1; |
516 | a1b87fe0 | Jan Kiszka | } |