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