]>
Commit | Line | Data |
---|---|---|
10ec5117 | 1 | /* |
aea1e885 | 2 | * S/390 misc helper routines |
10ec5117 | 3 | * |
defb0e31 | 4 | * Copyright (c) 2009 Ulrich Hecht |
10ec5117 AG |
5 | * Copyright (c) 2009 Alexander Graf |
6 | * | |
7 | * This library is free software; you can redistribute it and/or | |
8 | * modify it under the terms of the GNU Lesser General Public | |
9 | * License as published by the Free Software Foundation; either | |
10 | * version 2 of the License, or (at your option) any later version. | |
11 | * | |
12 | * This library is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * Lesser General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU Lesser General Public | |
70539e18 | 18 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. |
10ec5117 AG |
19 | */ |
20 | ||
9615495a | 21 | #include "qemu/osdep.h" |
278f5e98 | 22 | #include "qemu/main-loop.h" |
3e457172 | 23 | #include "cpu.h" |
4e58b838 | 24 | #include "internal.h" |
022c62cb | 25 | #include "exec/memory.h" |
1de7afc9 | 26 | #include "qemu/host-utils.h" |
2ef6175a | 27 | #include "exec/helper-proto.h" |
1de7afc9 | 28 | #include "qemu/timer.h" |
df75a4e2 | 29 | #include "exec/address-spaces.h" |
63c91552 | 30 | #include "exec/exec-all.h" |
f08b6170 | 31 | #include "exec/cpu_ldst.h" |
10ec5117 | 32 | |
71e47088 | 33 | #if !defined(CONFIG_USER_ONLY) |
f0778475 | 34 | #include "sysemu/cpus.h" |
9c17d615 | 35 | #include "sysemu/sysemu.h" |
40fa5264 | 36 | #include "hw/s390x/ebcdic.h" |
2c98a6c1 | 37 | #include "hw/s390x/s390-virtio-hcall.h" |
53d8e91d | 38 | #include "hw/s390x/sclp.h" |
6a253de3 | 39 | #include "hw/s390x/s390_flic.h" |
79947862 | 40 | #include "hw/s390x/ioinst.h" |
f6c232ce | 41 | #include "hw/s390x/s390-pci-inst.h" |
79947862 | 42 | #include "hw/boards.h" |
10ec5117 | 43 | #endif |
d5a43964 | 44 | |
defb0e31 AG |
45 | /* #define DEBUG_HELPER */ |
46 | #ifdef DEBUG_HELPER | |
47 | #define HELPER_LOG(x...) qemu_log(x) | |
48 | #else | |
49 | #define HELPER_LOG(x...) | |
50 | #endif | |
51 | ||
d5a103cd | 52 | /* Raise an exception statically from a TB. */ |
089f5c06 | 53 | void HELPER(exception)(CPUS390XState *env, uint32_t excp) |
defb0e31 | 54 | { |
27103424 AF |
55 | CPUState *cs = CPU(s390_env_get_cpu(env)); |
56 | ||
71e47088 | 57 | HELPER_LOG("%s: exception %d\n", __func__, excp); |
27103424 | 58 | cs->exception_index = excp; |
5638d180 | 59 | cpu_loop_exit(cs); |
defb0e31 AG |
60 | } |
61 | ||
4bac52f5 DH |
62 | /* Store CPU Timer (also used for EXTRACT CPU TIME) */ |
63 | uint64_t HELPER(stpt)(CPUS390XState *env) | |
64 | { | |
65 | #if defined(CONFIG_USER_ONLY) | |
66 | /* | |
67 | * Fake a descending CPU timer. We could get negative values here, | |
68 | * but we don't care as it is up to the OS when to process that | |
69 | * interrupt and reset to > 0. | |
70 | */ | |
71 | return UINT64_MAX - (uint64_t)cpu_get_host_ticks(); | |
72 | #else | |
73 | return time2tod(env->cputm - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)); | |
74 | #endif | |
75 | } | |
76 | ||
31006af3 AJ |
77 | #ifndef CONFIG_USER_ONLY |
78 | ||
defb0e31 | 79 | /* SCLP service call */ |
dc458df9 | 80 | uint32_t HELPER(servc)(CPUS390XState *env, uint64_t r1, uint64_t r2) |
defb0e31 | 81 | { |
8d04fb55 | 82 | qemu_mutex_lock_iothread(); |
6e252802 | 83 | int r = sclp_service_call(env, r1, r2); |
1a38921a | 84 | qemu_mutex_unlock_iothread(); |
9abf567d | 85 | if (r < 0) { |
1a38921a | 86 | s390_program_interrupt(env, -r, 4, GETPC()); |
9abf567d CB |
87 | } |
88 | return r; | |
defb0e31 AG |
89 | } |
90 | ||
8df7eef3 | 91 | void HELPER(diag)(CPUS390XState *env, uint32_t r1, uint32_t r3, uint32_t num) |
defb0e31 AG |
92 | { |
93 | uint64_t r; | |
94 | ||
95 | switch (num) { | |
96 | case 0x500: | |
97 | /* KVM hypercall */ | |
2cf9953b | 98 | qemu_mutex_lock_iothread(); |
28e942f8 | 99 | r = s390_virtio_hypercall(env); |
2cf9953b | 100 | qemu_mutex_unlock_iothread(); |
defb0e31 AG |
101 | break; |
102 | case 0x44: | |
103 | /* yield */ | |
104 | r = 0; | |
105 | break; | |
106 | case 0x308: | |
107 | /* ipl */ | |
7337c6eb | 108 | qemu_mutex_lock_iothread(); |
968db419 | 109 | handle_diag_308(env, r1, r3, GETPC()); |
7337c6eb | 110 | qemu_mutex_unlock_iothread(); |
defb0e31 AG |
111 | r = 0; |
112 | break; | |
eb569af8 CH |
113 | case 0x288: |
114 | /* time bomb (watchdog) */ | |
115 | r = handle_diag_288(env, r1, r3); | |
116 | break; | |
defb0e31 AG |
117 | default: |
118 | r = -1; | |
119 | break; | |
120 | } | |
121 | ||
122 | if (r) { | |
277b156d | 123 | s390_program_interrupt(env, PGM_SPECIFICATION, ILEN_AUTO, GETPC()); |
defb0e31 | 124 | } |
defb0e31 AG |
125 | } |
126 | ||
defb0e31 | 127 | /* Set Prefix */ |
089f5c06 | 128 | void HELPER(spx)(CPUS390XState *env, uint64_t a1) |
defb0e31 | 129 | { |
31b030d4 | 130 | CPUState *cs = CPU(s390_env_get_cpu(env)); |
e805a0d3 | 131 | uint32_t prefix = a1 & 0x7fffe000; |
31b030d4 | 132 | |
e805a0d3 | 133 | env->psa = prefix; |
aafcf80e | 134 | HELPER_LOG("prefix: %#x\n", prefix); |
31b030d4 AF |
135 | tlb_flush_page(cs, 0); |
136 | tlb_flush_page(cs, TARGET_PAGE_SIZE); | |
defb0e31 AG |
137 | } |
138 | ||
d9d55f11 AJ |
139 | /* Store Clock */ |
140 | uint64_t HELPER(stck)(CPUS390XState *env) | |
defb0e31 AG |
141 | { |
142 | uint64_t time; | |
143 | ||
144 | time = env->tod_offset + | |
bc72ad67 | 145 | time2tod(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) - env->tod_basetime); |
defb0e31 AG |
146 | |
147 | return time; | |
148 | } | |
149 | ||
defb0e31 | 150 | /* Set Clock Comparator */ |
dd3eb7b5 | 151 | void HELPER(sckc)(CPUS390XState *env, uint64_t time) |
defb0e31 | 152 | { |
defb0e31 AG |
153 | if (time == -1ULL) { |
154 | return; | |
155 | } | |
156 | ||
aa9e14e6 AJ |
157 | env->ckc = time; |
158 | ||
c941f074 AJ |
159 | /* difference between origins */ |
160 | time -= env->tod_offset; | |
161 | ||
defb0e31 | 162 | /* nanoseconds */ |
9cb32c44 | 163 | time = tod2time(time); |
defb0e31 | 164 | |
c941f074 | 165 | timer_mod(env->tod_timer, env->tod_basetime + time); |
defb0e31 AG |
166 | } |
167 | ||
257a119e DH |
168 | /* Set Tod Programmable Field */ |
169 | void HELPER(sckpf)(CPUS390XState *env, uint64_t r0) | |
170 | { | |
171 | uint32_t val = r0; | |
172 | ||
173 | if (val & 0xffff0000) { | |
174 | s390_program_interrupt(env, PGM_SPECIFICATION, 2, GETPC()); | |
175 | } | |
176 | env->todpr = val; | |
177 | } | |
178 | ||
defb0e31 | 179 | /* Store Clock Comparator */ |
dd3eb7b5 | 180 | uint64_t HELPER(stckc)(CPUS390XState *env) |
defb0e31 | 181 | { |
aa9e14e6 | 182 | return env->ckc; |
defb0e31 AG |
183 | } |
184 | ||
185 | /* Set CPU Timer */ | |
c4f0a863 | 186 | void HELPER(spt)(CPUS390XState *env, uint64_t time) |
defb0e31 | 187 | { |
defb0e31 AG |
188 | if (time == -1ULL) { |
189 | return; | |
190 | } | |
191 | ||
192 | /* nanoseconds */ | |
9cb32c44 | 193 | time = tod2time(time); |
defb0e31 | 194 | |
b8ae94bd AJ |
195 | env->cputm = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + time; |
196 | ||
197 | timer_mod(env->cpu_timer, env->cputm); | |
defb0e31 AG |
198 | } |
199 | ||
defb0e31 | 200 | /* Store System Information */ |
79947862 | 201 | uint32_t HELPER(stsi)(CPUS390XState *env, uint64_t a0, uint64_t r0, uint64_t r1) |
defb0e31 | 202 | { |
79947862 DH |
203 | const uintptr_t ra = GETPC(); |
204 | const uint32_t sel1 = r0 & STSI_R0_SEL1_MASK; | |
205 | const uint32_t sel2 = r1 & STSI_R1_SEL2_MASK; | |
206 | const MachineState *ms = MACHINE(qdev_get_machine()); | |
207 | uint16_t total_cpus = 0, conf_cpus = 0, reserved_cpus = 0; | |
076d4d39 | 208 | S390CPU *cpu = s390_env_get_cpu(env); |
79947862 DH |
209 | SysIB sysib = { 0 }; |
210 | int i, cc = 0; | |
defb0e31 | 211 | |
79947862 DH |
212 | if ((r0 & STSI_R0_FC_MASK) > STSI_R0_FC_LEVEL_3) { |
213 | /* invalid function code: no other checks are performed */ | |
214 | return 3; | |
defb0e31 AG |
215 | } |
216 | ||
79947862 DH |
217 | if ((r0 & STSI_R0_RESERVED_MASK) || (r1 & STSI_R1_RESERVED_MASK)) { |
218 | s390_program_interrupt(env, PGM_SPECIFICATION, 4, ra); | |
219 | } | |
220 | ||
221 | if ((r0 & STSI_R0_FC_MASK) == STSI_R0_FC_CURRENT) { | |
222 | /* query the current level: no further checks are performed */ | |
223 | env->regs[0] = STSI_R0_FC_LEVEL_3; | |
224 | return 0; | |
225 | } | |
defb0e31 | 226 | |
79947862 DH |
227 | if (a0 & ~TARGET_PAGE_MASK) { |
228 | s390_program_interrupt(env, PGM_SPECIFICATION, 4, ra); | |
229 | } | |
230 | ||
231 | /* count the cpus and split them into configured and reserved ones */ | |
232 | for (i = 0; i < ms->possible_cpus->len; i++) { | |
233 | total_cpus++; | |
234 | if (ms->possible_cpus->cpus[i].cpu) { | |
235 | conf_cpus++; | |
236 | } else { | |
237 | reserved_cpus++; | |
238 | } | |
239 | } | |
defb0e31 | 240 | |
79947862 DH |
241 | /* |
242 | * In theory, we could report Level 1 / Level 2 as current. However, | |
243 | * the Linux kernel will detect this as running under LPAR and assume | |
244 | * that we have a sclp linemode console (which is always present on | |
245 | * LPAR, but not the default for QEMU), therefore not displaying boot | |
246 | * messages and making booting a Linux kernel under TCG harder. | |
247 | * | |
248 | * For now we fake the same SMP configuration on all levels. | |
249 | * | |
250 | * TODO: We could later make the level configurable via the machine | |
251 | * and change defaults (linemode console) based on machine type | |
252 | * and accelerator. | |
253 | */ | |
254 | switch (r0 & STSI_R0_FC_MASK) { | |
255 | case STSI_R0_FC_LEVEL_1: | |
defb0e31 AG |
256 | if ((sel1 == 1) && (sel2 == 1)) { |
257 | /* Basic Machine Configuration */ | |
076d4d39 | 258 | char type[5] = {}; |
defb0e31 | 259 | |
79947862 | 260 | ebcdic_put(sysib.sysib_111.manuf, "QEMU ", 16); |
076d4d39 DH |
261 | /* same as machine type number in STORE CPU ID, but in EBCDIC */ |
262 | snprintf(type, ARRAY_SIZE(type), "%X", cpu->model->def->type); | |
79947862 | 263 | ebcdic_put(sysib.sysib_111.type, type, 4); |
076d4d39 | 264 | /* model number (not stored in STORE CPU ID for z/Architecure) */ |
79947862 DH |
265 | ebcdic_put(sysib.sysib_111.model, "QEMU ", 16); |
266 | ebcdic_put(sysib.sysib_111.sequence, "QEMU ", 16); | |
267 | ebcdic_put(sysib.sysib_111.plant, "QEMU", 4); | |
defb0e31 AG |
268 | } else if ((sel1 == 2) && (sel2 == 1)) { |
269 | /* Basic Machine CPU */ | |
79947862 DH |
270 | ebcdic_put(sysib.sysib_121.sequence, "QEMUQEMUQEMUQEMU", 16); |
271 | ebcdic_put(sysib.sysib_121.plant, "QEMU", 4); | |
272 | sysib.sysib_121.cpu_addr = cpu_to_be16(env->core_id); | |
defb0e31 AG |
273 | } else if ((sel1 == 2) && (sel2 == 2)) { |
274 | /* Basic Machine CPUs */ | |
79947862 DH |
275 | sysib.sysib_122.capability = cpu_to_be32(0x443afc29); |
276 | sysib.sysib_122.total_cpus = cpu_to_be16(total_cpus); | |
277 | sysib.sysib_122.conf_cpus = cpu_to_be16(conf_cpus); | |
278 | sysib.sysib_122.reserved_cpus = cpu_to_be16(reserved_cpus); | |
defb0e31 AG |
279 | } else { |
280 | cc = 3; | |
281 | } | |
282 | break; | |
79947862 DH |
283 | case STSI_R0_FC_LEVEL_2: |
284 | if ((sel1 == 2) && (sel2 == 1)) { | |
285 | /* LPAR CPU */ | |
286 | ebcdic_put(sysib.sysib_221.sequence, "QEMUQEMUQEMUQEMU", 16); | |
287 | ebcdic_put(sysib.sysib_221.plant, "QEMU", 4); | |
288 | sysib.sysib_221.cpu_addr = cpu_to_be16(env->core_id); | |
289 | } else if ((sel1 == 2) && (sel2 == 2)) { | |
290 | /* LPAR CPUs */ | |
291 | sysib.sysib_222.lcpuc = 0x80; /* dedicated */ | |
292 | sysib.sysib_222.total_cpus = cpu_to_be16(total_cpus); | |
293 | sysib.sysib_222.conf_cpus = cpu_to_be16(conf_cpus); | |
294 | sysib.sysib_222.reserved_cpus = cpu_to_be16(reserved_cpus); | |
295 | ebcdic_put(sysib.sysib_222.name, "QEMU ", 8); | |
296 | sysib.sysib_222.caf = cpu_to_be32(1000); | |
297 | sysib.sysib_222.dedicated_cpus = cpu_to_be16(conf_cpus); | |
298 | } else { | |
299 | cc = 3; | |
defb0e31 | 300 | } |
79947862 DH |
301 | break; |
302 | case STSI_R0_FC_LEVEL_3: | |
303 | if ((sel1 == 2) && (sel2 == 2)) { | |
304 | /* VM CPUs */ | |
305 | sysib.sysib_322.count = 1; | |
306 | sysib.sysib_322.vm[0].total_cpus = cpu_to_be16(total_cpus); | |
307 | sysib.sysib_322.vm[0].conf_cpus = cpu_to_be16(conf_cpus); | |
308 | sysib.sysib_322.vm[0].reserved_cpus = cpu_to_be16(reserved_cpus); | |
309 | sysib.sysib_322.vm[0].caf = cpu_to_be32(1000); | |
310 | /* Linux kernel uses this to distinguish us from z/VM */ | |
311 | ebcdic_put(sysib.sysib_322.vm[0].cpi, "KVM/Linux ", 16); | |
312 | sysib.sysib_322.vm[0].ext_name_encoding = 2; /* UTF-8 */ | |
313 | ||
314 | /* If our VM has a name, use the real name */ | |
315 | if (qemu_name) { | |
316 | memset(sysib.sysib_322.vm[0].name, 0x40, | |
317 | sizeof(sysib.sysib_322.vm[0].name)); | |
318 | ebcdic_put(sysib.sysib_322.vm[0].name, qemu_name, | |
319 | MIN(sizeof(sysib.sysib_322.vm[0].name), | |
320 | strlen(qemu_name))); | |
321 | strncpy((char *)sysib.sysib_322.ext_names[0], qemu_name, | |
322 | sizeof(sysib.sysib_322.ext_names[0])); | |
71e47088 | 323 | } else { |
79947862 DH |
324 | ebcdic_put(sysib.sysib_322.vm[0].name, "TCGguest", 8); |
325 | strcpy((char *)sysib.sysib_322.ext_names[0], "TCGguest"); | |
71e47088 | 326 | } |
79947862 DH |
327 | |
328 | /* add the uuid */ | |
329 | memcpy(sysib.sysib_322.vm[0].uuid, &qemu_uuid, | |
330 | sizeof(sysib.sysib_322.vm[0].uuid)); | |
331 | } else { | |
332 | cc = 3; | |
defb0e31 | 333 | } |
defb0e31 AG |
334 | break; |
335 | } | |
336 | ||
79947862 DH |
337 | if (cc == 0) { |
338 | if (s390_cpu_virt_mem_write(cpu, a0, 0, &sysib, sizeof(sysib))) { | |
339 | s390_cpu_virt_mem_handle_exc(cpu, ra); | |
340 | } | |
341 | } | |
342 | ||
defb0e31 AG |
343 | return cc; |
344 | } | |
345 | ||
089f5c06 | 346 | uint32_t HELPER(sigp)(CPUS390XState *env, uint64_t order_code, uint32_t r1, |
11b0079c | 347 | uint32_t r3) |
defb0e31 | 348 | { |
11b0079c | 349 | int cc; |
defb0e31 | 350 | |
11b0079c DH |
351 | /* TODO: needed to inject interrupts - push further down */ |
352 | qemu_mutex_lock_iothread(); | |
353 | cc = handle_sigp(env, order_code & SIGP_ORDER_MASK, r1, r3); | |
354 | qemu_mutex_unlock_iothread(); | |
defb0e31 AG |
355 | |
356 | return cc; | |
357 | } | |
defb0e31 | 358 | #endif |
ad8a4570 AG |
359 | |
360 | #ifndef CONFIG_USER_ONLY | |
361 | void HELPER(xsch)(CPUS390XState *env, uint64_t r1) | |
362 | { | |
363 | S390CPU *cpu = s390_env_get_cpu(env); | |
278f5e98 | 364 | qemu_mutex_lock_iothread(); |
1b98fb99 | 365 | ioinst_handle_xsch(cpu, r1, GETPC()); |
278f5e98 | 366 | qemu_mutex_unlock_iothread(); |
ad8a4570 AG |
367 | } |
368 | ||
369 | void HELPER(csch)(CPUS390XState *env, uint64_t r1) | |
370 | { | |
371 | S390CPU *cpu = s390_env_get_cpu(env); | |
278f5e98 | 372 | qemu_mutex_lock_iothread(); |
1b98fb99 | 373 | ioinst_handle_csch(cpu, r1, GETPC()); |
278f5e98 | 374 | qemu_mutex_unlock_iothread(); |
ad8a4570 AG |
375 | } |
376 | ||
377 | void HELPER(hsch)(CPUS390XState *env, uint64_t r1) | |
378 | { | |
379 | S390CPU *cpu = s390_env_get_cpu(env); | |
278f5e98 | 380 | qemu_mutex_lock_iothread(); |
1b98fb99 | 381 | ioinst_handle_hsch(cpu, r1, GETPC()); |
278f5e98 | 382 | qemu_mutex_unlock_iothread(); |
ad8a4570 AG |
383 | } |
384 | ||
385 | void HELPER(msch)(CPUS390XState *env, uint64_t r1, uint64_t inst) | |
386 | { | |
387 | S390CPU *cpu = s390_env_get_cpu(env); | |
278f5e98 | 388 | qemu_mutex_lock_iothread(); |
1b98fb99 | 389 | ioinst_handle_msch(cpu, r1, inst >> 16, GETPC()); |
278f5e98 | 390 | qemu_mutex_unlock_iothread(); |
ad8a4570 AG |
391 | } |
392 | ||
393 | void HELPER(rchp)(CPUS390XState *env, uint64_t r1) | |
394 | { | |
395 | S390CPU *cpu = s390_env_get_cpu(env); | |
278f5e98 | 396 | qemu_mutex_lock_iothread(); |
1b98fb99 | 397 | ioinst_handle_rchp(cpu, r1, GETPC()); |
278f5e98 | 398 | qemu_mutex_unlock_iothread(); |
ad8a4570 AG |
399 | } |
400 | ||
401 | void HELPER(rsch)(CPUS390XState *env, uint64_t r1) | |
402 | { | |
403 | S390CPU *cpu = s390_env_get_cpu(env); | |
278f5e98 | 404 | qemu_mutex_lock_iothread(); |
1b98fb99 | 405 | ioinst_handle_rsch(cpu, r1, GETPC()); |
278f5e98 | 406 | qemu_mutex_unlock_iothread(); |
ad8a4570 AG |
407 | } |
408 | ||
86c34633 DH |
409 | void HELPER(sal)(CPUS390XState *env, uint64_t r1) |
410 | { | |
411 | S390CPU *cpu = s390_env_get_cpu(env); | |
412 | ||
413 | qemu_mutex_lock_iothread(); | |
414 | ioinst_handle_sal(cpu, r1, GETPC()); | |
415 | qemu_mutex_unlock_iothread(); | |
416 | } | |
417 | ||
a9de75a0 DH |
418 | void HELPER(schm)(CPUS390XState *env, uint64_t r1, uint64_t r2, uint64_t inst) |
419 | { | |
420 | S390CPU *cpu = s390_env_get_cpu(env); | |
421 | ||
422 | qemu_mutex_lock_iothread(); | |
423 | ioinst_handle_schm(cpu, r1, r2, inst >> 16, GETPC()); | |
424 | qemu_mutex_unlock_iothread(); | |
425 | } | |
426 | ||
ad8a4570 AG |
427 | void HELPER(ssch)(CPUS390XState *env, uint64_t r1, uint64_t inst) |
428 | { | |
429 | S390CPU *cpu = s390_env_get_cpu(env); | |
278f5e98 | 430 | qemu_mutex_lock_iothread(); |
1b98fb99 | 431 | ioinst_handle_ssch(cpu, r1, inst >> 16, GETPC()); |
278f5e98 | 432 | qemu_mutex_unlock_iothread(); |
5a59bc1d DH |
433 | } |
434 | ||
435 | void HELPER(stcrw)(CPUS390XState *env, uint64_t inst) | |
436 | { | |
437 | S390CPU *cpu = s390_env_get_cpu(env); | |
438 | ||
439 | qemu_mutex_lock_iothread(); | |
440 | ioinst_handle_stcrw(cpu, inst >> 16, GETPC()); | |
441 | qemu_mutex_unlock_iothread(); | |
ad8a4570 AG |
442 | } |
443 | ||
444 | void HELPER(stsch)(CPUS390XState *env, uint64_t r1, uint64_t inst) | |
445 | { | |
446 | S390CPU *cpu = s390_env_get_cpu(env); | |
278f5e98 | 447 | qemu_mutex_lock_iothread(); |
1b98fb99 | 448 | ioinst_handle_stsch(cpu, r1, inst >> 16, GETPC()); |
278f5e98 | 449 | qemu_mutex_unlock_iothread(); |
ad8a4570 AG |
450 | } |
451 | ||
6a253de3 DH |
452 | uint32_t HELPER(tpi)(CPUS390XState *env, uint64_t addr) |
453 | { | |
454 | const uintptr_t ra = GETPC(); | |
455 | S390CPU *cpu = s390_env_get_cpu(env); | |
f68ecdd4 | 456 | QEMUS390FLICState *flic = s390_get_qemu_flic(s390_get_flic()); |
6a253de3 DH |
457 | QEMUS390FlicIO *io = NULL; |
458 | LowCore *lowcore; | |
459 | ||
460 | if (addr & 0x3) { | |
461 | s390_program_interrupt(env, PGM_SPECIFICATION, 4, ra); | |
462 | } | |
463 | ||
464 | qemu_mutex_lock_iothread(); | |
465 | io = qemu_s390_flic_dequeue_io(flic, env->cregs[6]); | |
466 | if (!io) { | |
467 | qemu_mutex_unlock_iothread(); | |
468 | return 0; | |
469 | } | |
470 | ||
471 | if (addr) { | |
472 | struct { | |
473 | uint16_t id; | |
474 | uint16_t nr; | |
475 | uint32_t parm; | |
476 | } intc = { | |
477 | .id = cpu_to_be16(io->id), | |
478 | .nr = cpu_to_be16(io->nr), | |
479 | .parm = cpu_to_be32(io->parm), | |
480 | }; | |
481 | ||
482 | if (s390_cpu_virt_mem_write(cpu, addr, 0, &intc, sizeof(intc))) { | |
483 | /* writing failed, reinject and properly clean up */ | |
484 | s390_io_interrupt(io->id, io->nr, io->parm, io->word); | |
485 | qemu_mutex_unlock_iothread(); | |
486 | g_free(io); | |
487 | s390_cpu_virt_mem_handle_exc(cpu, ra); | |
488 | return 0; | |
489 | } | |
490 | } else { | |
491 | /* no protection applies */ | |
492 | lowcore = cpu_map_lowcore(env); | |
493 | lowcore->subchannel_id = cpu_to_be16(io->id); | |
494 | lowcore->subchannel_nr = cpu_to_be16(io->nr); | |
495 | lowcore->io_int_parm = cpu_to_be32(io->parm); | |
496 | lowcore->io_int_word = cpu_to_be32(io->word); | |
497 | cpu_unmap_lowcore(lowcore); | |
498 | } | |
499 | ||
500 | g_free(io); | |
501 | qemu_mutex_unlock_iothread(); | |
502 | return 1; | |
503 | } | |
504 | ||
ad8a4570 AG |
505 | void HELPER(tsch)(CPUS390XState *env, uint64_t r1, uint64_t inst) |
506 | { | |
507 | S390CPU *cpu = s390_env_get_cpu(env); | |
278f5e98 | 508 | qemu_mutex_lock_iothread(); |
1b98fb99 | 509 | ioinst_handle_tsch(cpu, r1, inst >> 16, GETPC()); |
278f5e98 | 510 | qemu_mutex_unlock_iothread(); |
ad8a4570 AG |
511 | } |
512 | ||
513 | void HELPER(chsc)(CPUS390XState *env, uint64_t inst) | |
514 | { | |
515 | S390CPU *cpu = s390_env_get_cpu(env); | |
278f5e98 | 516 | qemu_mutex_lock_iothread(); |
1b98fb99 | 517 | ioinst_handle_chsc(cpu, inst >> 16, GETPC()); |
278f5e98 | 518 | qemu_mutex_unlock_iothread(); |
ad8a4570 AG |
519 | } |
520 | #endif | |
777c98c3 AJ |
521 | |
522 | #ifndef CONFIG_USER_ONLY | |
523 | void HELPER(per_check_exception)(CPUS390XState *env) | |
524 | { | |
e0b1a8a1 | 525 | uint32_t ilen; |
777c98c3 AJ |
526 | |
527 | if (env->per_perc_atmid) { | |
e0b1a8a1 DH |
528 | /* |
529 | * FIXME: ILEN_AUTO is most probably the right thing to use. ilen | |
530 | * always has to match the instruction referenced in the PSW. E.g. | |
531 | * if a PER interrupt is triggered via EXECUTE, we have to use ilen | |
532 | * of EXECUTE, while per_address contains the target of EXECUTE. | |
533 | */ | |
534 | ilen = get_ilen(cpu_ldub_code(env, env->per_address)); | |
88083382 | 535 | s390_program_interrupt(env, PGM_PER, ilen, GETPC()); |
777c98c3 AJ |
536 | } |
537 | } | |
2c2275eb | 538 | |
d9b8daf9 DH |
539 | /* Check if an address is within the PER starting address and the PER |
540 | ending address. The address range might loop. */ | |
541 | static inline bool get_per_in_range(CPUS390XState *env, uint64_t addr) | |
542 | { | |
543 | if (env->cregs[10] <= env->cregs[11]) { | |
544 | return env->cregs[10] <= addr && addr <= env->cregs[11]; | |
545 | } else { | |
546 | return env->cregs[10] <= addr || addr <= env->cregs[11]; | |
547 | } | |
548 | } | |
549 | ||
2c2275eb AJ |
550 | void HELPER(per_branch)(CPUS390XState *env, uint64_t from, uint64_t to) |
551 | { | |
552 | if ((env->cregs[9] & PER_CR9_EVENT_BRANCH)) { | |
553 | if (!(env->cregs[9] & PER_CR9_CONTROL_BRANCH_ADDRESS) | |
554 | || get_per_in_range(env, to)) { | |
555 | env->per_address = from; | |
556 | env->per_perc_atmid = PER_CODE_EVENT_BRANCH | get_per_atmid(env); | |
557 | } | |
558 | } | |
559 | } | |
f0e0d817 AJ |
560 | |
561 | void HELPER(per_ifetch)(CPUS390XState *env, uint64_t addr) | |
562 | { | |
563 | if ((env->cregs[9] & PER_CR9_EVENT_IFETCH) && get_per_in_range(env, addr)) { | |
564 | env->per_address = addr; | |
565 | env->per_perc_atmid = PER_CODE_EVENT_IFETCH | get_per_atmid(env); | |
83bb1612 AJ |
566 | |
567 | /* If the instruction has to be nullified, trigger the | |
568 | exception immediately. */ | |
569 | if (env->cregs[9] & PER_CR9_EVENT_NULLIFICATION) { | |
570 | CPUState *cs = CPU(s390_env_get_cpu(env)); | |
571 | ||
465aec46 | 572 | env->per_perc_atmid |= PER_CODE_EVENT_NULLIFICATION; |
83bb1612 AJ |
573 | env->int_pgm_code = PGM_PER; |
574 | env->int_pgm_ilen = get_ilen(cpu_ldub_code(env, addr)); | |
575 | ||
576 | cs->exception_index = EXCP_PGM; | |
577 | cpu_loop_exit(cs); | |
578 | } | |
f0e0d817 AJ |
579 | } |
580 | } | |
777c98c3 | 581 | #endif |
5bf83628 | 582 | |
f74990a5 DH |
583 | static uint8_t stfl_bytes[2048]; |
584 | static unsigned int used_stfl_bytes; | |
5bf83628 | 585 | |
f74990a5 | 586 | static void prepare_stfl(void) |
5bf83628 | 587 | { |
f74990a5 DH |
588 | static bool initialized; |
589 | int i; | |
5bf83628 | 590 | |
f74990a5 DH |
591 | /* racy, but we don't care, the same values are always written */ |
592 | if (initialized) { | |
593 | return; | |
5bf83628 RH |
594 | } |
595 | ||
f74990a5 DH |
596 | s390_get_feat_block(S390_FEAT_TYPE_STFL, stfl_bytes); |
597 | for (i = 0; i < sizeof(stfl_bytes); i++) { | |
598 | if (stfl_bytes[i]) { | |
599 | used_stfl_bytes = i + 1; | |
5bf83628 RH |
600 | } |
601 | } | |
f74990a5 | 602 | initialized = true; |
5bf83628 RH |
603 | } |
604 | ||
86b5ab39 | 605 | #ifndef CONFIG_USER_ONLY |
5bf83628 RH |
606 | void HELPER(stfl)(CPUS390XState *env) |
607 | { | |
86b5ab39 | 608 | LowCore *lowcore; |
5bf83628 | 609 | |
86b5ab39 | 610 | lowcore = cpu_map_lowcore(env); |
f74990a5 DH |
611 | prepare_stfl(); |
612 | memcpy(&lowcore->stfl_fac_list, stfl_bytes, sizeof(lowcore->stfl_fac_list)); | |
86b5ab39 | 613 | cpu_unmap_lowcore(lowcore); |
5bf83628 | 614 | } |
86b5ab39 | 615 | #endif |
5bf83628 RH |
616 | |
617 | uint32_t HELPER(stfle)(CPUS390XState *env, uint64_t addr) | |
618 | { | |
f74990a5 DH |
619 | const uintptr_t ra = GETPC(); |
620 | const int count_bytes = ((env->regs[0] & 0xff) + 1) * 8; | |
621 | const int max_bytes = ROUND_UP(used_stfl_bytes, 8); | |
622 | int i; | |
623 | ||
624 | if (addr & 0x7) { | |
8d2f850a | 625 | s390_program_interrupt(env, PGM_SPECIFICATION, 4, ra); |
f74990a5 | 626 | } |
5bf83628 | 627 | |
f74990a5 DH |
628 | prepare_stfl(); |
629 | for (i = 0; i < count_bytes; ++i) { | |
630 | cpu_stb_data_ra(env, addr + i, stfl_bytes[i], ra); | |
5bf83628 RH |
631 | } |
632 | ||
f74990a5 DH |
633 | env->regs[0] = deposit64(env->regs[0], 0, 8, (max_bytes / 8) - 1); |
634 | return count_bytes >= max_bytes ? 0 : 3; | |
5bf83628 | 635 | } |
f6c232ce CH |
636 | |
637 | #ifndef CONFIG_USER_ONLY | |
638 | /* | |
639 | * Note: we ignore any return code of the functions called for the pci | |
640 | * instructions, as the only time they return !0 is when the stub is | |
641 | * called, and in that case we didn't even offer the zpci facility. | |
642 | * The only exception is SIC, where program checks need to be handled | |
643 | * by the caller. | |
644 | */ | |
645 | void HELPER(clp)(CPUS390XState *env, uint32_t r2) | |
646 | { | |
647 | S390CPU *cpu = s390_env_get_cpu(env); | |
648 | ||
649 | qemu_mutex_lock_iothread(); | |
650 | clp_service_call(cpu, r2, GETPC()); | |
651 | qemu_mutex_unlock_iothread(); | |
652 | } | |
653 | ||
654 | void HELPER(pcilg)(CPUS390XState *env, uint32_t r1, uint32_t r2) | |
655 | { | |
656 | S390CPU *cpu = s390_env_get_cpu(env); | |
657 | ||
658 | qemu_mutex_lock_iothread(); | |
659 | pcilg_service_call(cpu, r1, r2, GETPC()); | |
660 | qemu_mutex_unlock_iothread(); | |
661 | } | |
662 | ||
663 | void HELPER(pcistg)(CPUS390XState *env, uint32_t r1, uint32_t r2) | |
664 | { | |
665 | S390CPU *cpu = s390_env_get_cpu(env); | |
666 | ||
667 | qemu_mutex_lock_iothread(); | |
668 | pcistg_service_call(cpu, r1, r2, GETPC()); | |
669 | qemu_mutex_unlock_iothread(); | |
670 | } | |
671 | ||
672 | void HELPER(stpcifc)(CPUS390XState *env, uint32_t r1, uint64_t fiba, | |
673 | uint32_t ar) | |
674 | { | |
675 | S390CPU *cpu = s390_env_get_cpu(env); | |
676 | ||
677 | qemu_mutex_lock_iothread(); | |
678 | stpcifc_service_call(cpu, r1, fiba, ar, GETPC()); | |
679 | qemu_mutex_unlock_iothread(); | |
680 | } | |
681 | ||
682 | void HELPER(sic)(CPUS390XState *env, uint64_t r1, uint64_t r3) | |
683 | { | |
684 | int r; | |
685 | ||
686 | qemu_mutex_lock_iothread(); | |
687 | r = css_do_sic(env, (r3 >> 27) & 0x7, r1 & 0xffff); | |
688 | qemu_mutex_unlock_iothread(); | |
689 | /* css_do_sic() may actually return a PGM_xxx value to inject */ | |
690 | if (r) { | |
691 | s390_program_interrupt(env, -r, 4, GETPC()); | |
692 | } | |
693 | } | |
694 | ||
695 | void HELPER(rpcit)(CPUS390XState *env, uint32_t r1, uint32_t r2) | |
696 | { | |
697 | S390CPU *cpu = s390_env_get_cpu(env); | |
698 | ||
699 | qemu_mutex_lock_iothread(); | |
700 | rpcit_service_call(cpu, r1, r2, GETPC()); | |
701 | qemu_mutex_unlock_iothread(); | |
702 | } | |
703 | ||
704 | void HELPER(pcistb)(CPUS390XState *env, uint32_t r1, uint32_t r3, | |
705 | uint64_t gaddr, uint32_t ar) | |
706 | { | |
707 | S390CPU *cpu = s390_env_get_cpu(env); | |
708 | ||
709 | qemu_mutex_lock_iothread(); | |
710 | pcistb_service_call(cpu, r1, r3, gaddr, ar, GETPC()); | |
711 | qemu_mutex_unlock_iothread(); | |
712 | } | |
713 | ||
714 | void HELPER(mpcifc)(CPUS390XState *env, uint32_t r1, uint64_t fiba, | |
715 | uint32_t ar) | |
716 | { | |
717 | S390CPU *cpu = s390_env_get_cpu(env); | |
718 | ||
719 | qemu_mutex_lock_iothread(); | |
720 | mpcifc_service_call(cpu, r1, fiba, ar, GETPC()); | |
721 | qemu_mutex_unlock_iothread(); | |
722 | } | |
723 | #endif |