configure / meson: Move check for sys/kcov.h to meson.build
[qemu/ar7.git] / target / s390x / misc_helper.c
blob58dbc023eb5495ec5da0321651ad2af2aa6b7e16
1 /*
2 * S/390 misc helper routines
4 * Copyright (c) 2009 Ulrich Hecht
5 * Copyright (c) 2009 Alexander Graf
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.1 of the License, or (at your option) any later version.
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.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
21 #include "qemu/osdep.h"
22 #include "qemu/main-loop.h"
23 #include "cpu.h"
24 #include "internal.h"
25 #include "exec/memory.h"
26 #include "qemu/host-utils.h"
27 #include "exec/helper-proto.h"
28 #include "qemu/timer.h"
29 #include "exec/exec-all.h"
30 #include "exec/cpu_ldst.h"
31 #include "qapi/error.h"
32 #include "tcg_s390x.h"
33 #include "s390-tod.h"
35 #if !defined(CONFIG_USER_ONLY)
36 #include "sysemu/cpus.h"
37 #include "sysemu/sysemu.h"
38 #include "hw/s390x/ebcdic.h"
39 #include "hw/s390x/s390-virtio-hcall.h"
40 #include "hw/s390x/sclp.h"
41 #include "hw/s390x/s390_flic.h"
42 #include "hw/s390x/ioinst.h"
43 #include "hw/s390x/s390-pci-inst.h"
44 #include "hw/boards.h"
45 #include "hw/s390x/tod.h"
46 #endif
48 /* #define DEBUG_HELPER */
49 #ifdef DEBUG_HELPER
50 #define HELPER_LOG(x...) qemu_log(x)
51 #else
52 #define HELPER_LOG(x...)
53 #endif
55 /* Raise an exception statically from a TB. */
56 void HELPER(exception)(CPUS390XState *env, uint32_t excp)
58 CPUState *cs = env_cpu(env);
60 HELPER_LOG("%s: exception %d\n", __func__, excp);
61 cs->exception_index = excp;
62 cpu_loop_exit(cs);
65 /* Store CPU Timer (also used for EXTRACT CPU TIME) */
66 uint64_t HELPER(stpt)(CPUS390XState *env)
68 #if defined(CONFIG_USER_ONLY)
70 * Fake a descending CPU timer. We could get negative values here,
71 * but we don't care as it is up to the OS when to process that
72 * interrupt and reset to > 0.
74 return UINT64_MAX - (uint64_t)cpu_get_host_ticks();
75 #else
76 return time2tod(env->cputm - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
77 #endif
80 /* Store Clock */
81 uint64_t HELPER(stck)(CPUS390XState *env)
83 #ifdef CONFIG_USER_ONLY
84 struct timespec ts;
85 uint64_t ns;
87 clock_gettime(CLOCK_REALTIME, &ts);
88 ns = ts.tv_sec * NANOSECONDS_PER_SECOND + ts.tv_nsec;
90 return TOD_UNIX_EPOCH + time2tod(ns);
91 #else
92 S390TODState *td = s390_get_todstate();
93 S390TODClass *tdc = S390_TOD_GET_CLASS(td);
94 S390TOD tod;
96 tdc->get(td, &tod, &error_abort);
97 return tod.low;
98 #endif
101 #ifndef CONFIG_USER_ONLY
102 /* SCLP service call */
103 uint32_t HELPER(servc)(CPUS390XState *env, uint64_t r1, uint64_t r2)
105 qemu_mutex_lock_iothread();
106 int r = sclp_service_call(env, r1, r2);
107 qemu_mutex_unlock_iothread();
108 if (r < 0) {
109 tcg_s390_program_interrupt(env, -r, GETPC());
111 return r;
114 void HELPER(diag)(CPUS390XState *env, uint32_t r1, uint32_t r3, uint32_t num)
116 uint64_t r;
118 switch (num) {
119 case 0x500:
120 /* KVM hypercall */
121 qemu_mutex_lock_iothread();
122 r = s390_virtio_hypercall(env);
123 qemu_mutex_unlock_iothread();
124 break;
125 case 0x44:
126 /* yield */
127 r = 0;
128 break;
129 case 0x308:
130 /* ipl */
131 qemu_mutex_lock_iothread();
132 handle_diag_308(env, r1, r3, GETPC());
133 qemu_mutex_unlock_iothread();
134 r = 0;
135 break;
136 case 0x288:
137 /* time bomb (watchdog) */
138 r = handle_diag_288(env, r1, r3);
139 break;
140 default:
141 r = -1;
142 break;
145 if (r) {
146 tcg_s390_program_interrupt(env, PGM_SPECIFICATION, GETPC());
150 /* Set Prefix */
151 void HELPER(spx)(CPUS390XState *env, uint64_t a1)
153 CPUState *cs = env_cpu(env);
154 uint32_t prefix = a1 & 0x7fffe000;
156 env->psa = prefix;
157 HELPER_LOG("prefix: %#x\n", prefix);
158 tlb_flush_page(cs, 0);
159 tlb_flush_page(cs, TARGET_PAGE_SIZE);
162 static void update_ckc_timer(CPUS390XState *env)
164 S390TODState *td = s390_get_todstate();
165 uint64_t time;
167 /* stop the timer and remove pending CKC IRQs */
168 timer_del(env->tod_timer);
169 g_assert(qemu_mutex_iothread_locked());
170 env->pending_int &= ~INTERRUPT_EXT_CLOCK_COMPARATOR;
172 /* the tod has to exceed the ckc, this can never happen if ckc is all 1's */
173 if (env->ckc == -1ULL) {
174 return;
177 /* difference between origins */
178 time = env->ckc - td->base.low;
180 /* nanoseconds */
181 time = tod2time(time);
183 timer_mod(env->tod_timer, time);
186 /* Set Clock Comparator */
187 void HELPER(sckc)(CPUS390XState *env, uint64_t ckc)
189 env->ckc = ckc;
191 qemu_mutex_lock_iothread();
192 update_ckc_timer(env);
193 qemu_mutex_unlock_iothread();
196 void tcg_s390_tod_updated(CPUState *cs, run_on_cpu_data opaque)
198 S390CPU *cpu = S390_CPU(cs);
200 update_ckc_timer(&cpu->env);
203 /* Set Clock */
204 uint32_t HELPER(sck)(CPUS390XState *env, uint64_t tod_low)
206 S390TODState *td = s390_get_todstate();
207 S390TODClass *tdc = S390_TOD_GET_CLASS(td);
208 S390TOD tod = {
209 .high = 0,
210 .low = tod_low,
213 qemu_mutex_lock_iothread();
214 tdc->set(td, &tod, &error_abort);
215 qemu_mutex_unlock_iothread();
216 return 0;
219 /* Set Tod Programmable Field */
220 void HELPER(sckpf)(CPUS390XState *env, uint64_t r0)
222 uint32_t val = r0;
224 if (val & 0xffff0000) {
225 tcg_s390_program_interrupt(env, PGM_SPECIFICATION, GETPC());
227 env->todpr = val;
230 /* Store Clock Comparator */
231 uint64_t HELPER(stckc)(CPUS390XState *env)
233 return env->ckc;
236 /* Set CPU Timer */
237 void HELPER(spt)(CPUS390XState *env, uint64_t time)
239 if (time == -1ULL) {
240 return;
243 /* nanoseconds */
244 time = tod2time(time);
246 env->cputm = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + time;
248 timer_mod(env->cpu_timer, env->cputm);
251 /* Store System Information */
252 uint32_t HELPER(stsi)(CPUS390XState *env, uint64_t a0, uint64_t r0, uint64_t r1)
254 const uintptr_t ra = GETPC();
255 const uint32_t sel1 = r0 & STSI_R0_SEL1_MASK;
256 const uint32_t sel2 = r1 & STSI_R1_SEL2_MASK;
257 const MachineState *ms = MACHINE(qdev_get_machine());
258 uint16_t total_cpus = 0, conf_cpus = 0, reserved_cpus = 0;
259 S390CPU *cpu = env_archcpu(env);
260 SysIB sysib = { };
261 int i, cc = 0;
263 if ((r0 & STSI_R0_FC_MASK) > STSI_R0_FC_LEVEL_3) {
264 /* invalid function code: no other checks are performed */
265 return 3;
268 if ((r0 & STSI_R0_RESERVED_MASK) || (r1 & STSI_R1_RESERVED_MASK)) {
269 tcg_s390_program_interrupt(env, PGM_SPECIFICATION, ra);
272 if ((r0 & STSI_R0_FC_MASK) == STSI_R0_FC_CURRENT) {
273 /* query the current level: no further checks are performed */
274 env->regs[0] = STSI_R0_FC_LEVEL_3;
275 return 0;
278 if (a0 & ~TARGET_PAGE_MASK) {
279 tcg_s390_program_interrupt(env, PGM_SPECIFICATION, ra);
282 /* count the cpus and split them into configured and reserved ones */
283 for (i = 0; i < ms->possible_cpus->len; i++) {
284 total_cpus++;
285 if (ms->possible_cpus->cpus[i].cpu) {
286 conf_cpus++;
287 } else {
288 reserved_cpus++;
293 * In theory, we could report Level 1 / Level 2 as current. However,
294 * the Linux kernel will detect this as running under LPAR and assume
295 * that we have a sclp linemode console (which is always present on
296 * LPAR, but not the default for QEMU), therefore not displaying boot
297 * messages and making booting a Linux kernel under TCG harder.
299 * For now we fake the same SMP configuration on all levels.
301 * TODO: We could later make the level configurable via the machine
302 * and change defaults (linemode console) based on machine type
303 * and accelerator.
305 switch (r0 & STSI_R0_FC_MASK) {
306 case STSI_R0_FC_LEVEL_1:
307 if ((sel1 == 1) && (sel2 == 1)) {
308 /* Basic Machine Configuration */
309 char type[5] = {};
311 ebcdic_put(sysib.sysib_111.manuf, "QEMU ", 16);
312 /* same as machine type number in STORE CPU ID, but in EBCDIC */
313 snprintf(type, ARRAY_SIZE(type), "%X", cpu->model->def->type);
314 ebcdic_put(sysib.sysib_111.type, type, 4);
315 /* model number (not stored in STORE CPU ID for z/Architecure) */
316 ebcdic_put(sysib.sysib_111.model, "QEMU ", 16);
317 ebcdic_put(sysib.sysib_111.sequence, "QEMU ", 16);
318 ebcdic_put(sysib.sysib_111.plant, "QEMU", 4);
319 } else if ((sel1 == 2) && (sel2 == 1)) {
320 /* Basic Machine CPU */
321 ebcdic_put(sysib.sysib_121.sequence, "QEMUQEMUQEMUQEMU", 16);
322 ebcdic_put(sysib.sysib_121.plant, "QEMU", 4);
323 sysib.sysib_121.cpu_addr = cpu_to_be16(env->core_id);
324 } else if ((sel1 == 2) && (sel2 == 2)) {
325 /* Basic Machine CPUs */
326 sysib.sysib_122.capability = cpu_to_be32(0x443afc29);
327 sysib.sysib_122.total_cpus = cpu_to_be16(total_cpus);
328 sysib.sysib_122.conf_cpus = cpu_to_be16(conf_cpus);
329 sysib.sysib_122.reserved_cpus = cpu_to_be16(reserved_cpus);
330 } else {
331 cc = 3;
333 break;
334 case STSI_R0_FC_LEVEL_2:
335 if ((sel1 == 2) && (sel2 == 1)) {
336 /* LPAR CPU */
337 ebcdic_put(sysib.sysib_221.sequence, "QEMUQEMUQEMUQEMU", 16);
338 ebcdic_put(sysib.sysib_221.plant, "QEMU", 4);
339 sysib.sysib_221.cpu_addr = cpu_to_be16(env->core_id);
340 } else if ((sel1 == 2) && (sel2 == 2)) {
341 /* LPAR CPUs */
342 sysib.sysib_222.lcpuc = 0x80; /* dedicated */
343 sysib.sysib_222.total_cpus = cpu_to_be16(total_cpus);
344 sysib.sysib_222.conf_cpus = cpu_to_be16(conf_cpus);
345 sysib.sysib_222.reserved_cpus = cpu_to_be16(reserved_cpus);
346 ebcdic_put(sysib.sysib_222.name, "QEMU ", 8);
347 sysib.sysib_222.caf = cpu_to_be32(1000);
348 sysib.sysib_222.dedicated_cpus = cpu_to_be16(conf_cpus);
349 } else {
350 cc = 3;
352 break;
353 case STSI_R0_FC_LEVEL_3:
354 if ((sel1 == 2) && (sel2 == 2)) {
355 /* VM CPUs */
356 sysib.sysib_322.count = 1;
357 sysib.sysib_322.vm[0].total_cpus = cpu_to_be16(total_cpus);
358 sysib.sysib_322.vm[0].conf_cpus = cpu_to_be16(conf_cpus);
359 sysib.sysib_322.vm[0].reserved_cpus = cpu_to_be16(reserved_cpus);
360 sysib.sysib_322.vm[0].caf = cpu_to_be32(1000);
361 /* Linux kernel uses this to distinguish us from z/VM */
362 ebcdic_put(sysib.sysib_322.vm[0].cpi, "KVM/Linux ", 16);
363 sysib.sysib_322.vm[0].ext_name_encoding = 2; /* UTF-8 */
365 /* If our VM has a name, use the real name */
366 if (qemu_name) {
367 memset(sysib.sysib_322.vm[0].name, 0x40,
368 sizeof(sysib.sysib_322.vm[0].name));
369 ebcdic_put(sysib.sysib_322.vm[0].name, qemu_name,
370 MIN(sizeof(sysib.sysib_322.vm[0].name),
371 strlen(qemu_name)));
372 strncpy((char *)sysib.sysib_322.ext_names[0], qemu_name,
373 sizeof(sysib.sysib_322.ext_names[0]));
374 } else {
375 ebcdic_put(sysib.sysib_322.vm[0].name, "TCGguest", 8);
376 strcpy((char *)sysib.sysib_322.ext_names[0], "TCGguest");
379 /* add the uuid */
380 memcpy(sysib.sysib_322.vm[0].uuid, &qemu_uuid,
381 sizeof(sysib.sysib_322.vm[0].uuid));
382 } else {
383 cc = 3;
385 break;
388 if (cc == 0) {
389 if (s390_cpu_virt_mem_write(cpu, a0, 0, &sysib, sizeof(sysib))) {
390 s390_cpu_virt_mem_handle_exc(cpu, ra);
394 return cc;
397 uint32_t HELPER(sigp)(CPUS390XState *env, uint64_t order_code, uint32_t r1,
398 uint32_t r3)
400 int cc;
402 /* TODO: needed to inject interrupts - push further down */
403 qemu_mutex_lock_iothread();
404 cc = handle_sigp(env, order_code & SIGP_ORDER_MASK, r1, r3);
405 qemu_mutex_unlock_iothread();
407 return cc;
409 #endif
411 #ifndef CONFIG_USER_ONLY
412 void HELPER(xsch)(CPUS390XState *env, uint64_t r1)
414 S390CPU *cpu = env_archcpu(env);
415 qemu_mutex_lock_iothread();
416 ioinst_handle_xsch(cpu, r1, GETPC());
417 qemu_mutex_unlock_iothread();
420 void HELPER(csch)(CPUS390XState *env, uint64_t r1)
422 S390CPU *cpu = env_archcpu(env);
423 qemu_mutex_lock_iothread();
424 ioinst_handle_csch(cpu, r1, GETPC());
425 qemu_mutex_unlock_iothread();
428 void HELPER(hsch)(CPUS390XState *env, uint64_t r1)
430 S390CPU *cpu = env_archcpu(env);
431 qemu_mutex_lock_iothread();
432 ioinst_handle_hsch(cpu, r1, GETPC());
433 qemu_mutex_unlock_iothread();
436 void HELPER(msch)(CPUS390XState *env, uint64_t r1, uint64_t inst)
438 S390CPU *cpu = env_archcpu(env);
439 qemu_mutex_lock_iothread();
440 ioinst_handle_msch(cpu, r1, inst >> 16, GETPC());
441 qemu_mutex_unlock_iothread();
444 void HELPER(rchp)(CPUS390XState *env, uint64_t r1)
446 S390CPU *cpu = env_archcpu(env);
447 qemu_mutex_lock_iothread();
448 ioinst_handle_rchp(cpu, r1, GETPC());
449 qemu_mutex_unlock_iothread();
452 void HELPER(rsch)(CPUS390XState *env, uint64_t r1)
454 S390CPU *cpu = env_archcpu(env);
455 qemu_mutex_lock_iothread();
456 ioinst_handle_rsch(cpu, r1, GETPC());
457 qemu_mutex_unlock_iothread();
460 void HELPER(sal)(CPUS390XState *env, uint64_t r1)
462 S390CPU *cpu = env_archcpu(env);
464 qemu_mutex_lock_iothread();
465 ioinst_handle_sal(cpu, r1, GETPC());
466 qemu_mutex_unlock_iothread();
469 void HELPER(schm)(CPUS390XState *env, uint64_t r1, uint64_t r2, uint64_t inst)
471 S390CPU *cpu = env_archcpu(env);
473 qemu_mutex_lock_iothread();
474 ioinst_handle_schm(cpu, r1, r2, inst >> 16, GETPC());
475 qemu_mutex_unlock_iothread();
478 void HELPER(ssch)(CPUS390XState *env, uint64_t r1, uint64_t inst)
480 S390CPU *cpu = env_archcpu(env);
481 qemu_mutex_lock_iothread();
482 ioinst_handle_ssch(cpu, r1, inst >> 16, GETPC());
483 qemu_mutex_unlock_iothread();
486 void HELPER(stcrw)(CPUS390XState *env, uint64_t inst)
488 S390CPU *cpu = env_archcpu(env);
490 qemu_mutex_lock_iothread();
491 ioinst_handle_stcrw(cpu, inst >> 16, GETPC());
492 qemu_mutex_unlock_iothread();
495 void HELPER(stsch)(CPUS390XState *env, uint64_t r1, uint64_t inst)
497 S390CPU *cpu = env_archcpu(env);
498 qemu_mutex_lock_iothread();
499 ioinst_handle_stsch(cpu, r1, inst >> 16, GETPC());
500 qemu_mutex_unlock_iothread();
503 uint32_t HELPER(tpi)(CPUS390XState *env, uint64_t addr)
505 const uintptr_t ra = GETPC();
506 S390CPU *cpu = env_archcpu(env);
507 QEMUS390FLICState *flic = s390_get_qemu_flic(s390_get_flic());
508 QEMUS390FlicIO *io = NULL;
509 LowCore *lowcore;
511 if (addr & 0x3) {
512 tcg_s390_program_interrupt(env, PGM_SPECIFICATION, ra);
515 qemu_mutex_lock_iothread();
516 io = qemu_s390_flic_dequeue_io(flic, env->cregs[6]);
517 if (!io) {
518 qemu_mutex_unlock_iothread();
519 return 0;
522 if (addr) {
523 struct {
524 uint16_t id;
525 uint16_t nr;
526 uint32_t parm;
527 } intc = {
528 .id = cpu_to_be16(io->id),
529 .nr = cpu_to_be16(io->nr),
530 .parm = cpu_to_be32(io->parm),
533 if (s390_cpu_virt_mem_write(cpu, addr, 0, &intc, sizeof(intc))) {
534 /* writing failed, reinject and properly clean up */
535 s390_io_interrupt(io->id, io->nr, io->parm, io->word);
536 qemu_mutex_unlock_iothread();
537 g_free(io);
538 s390_cpu_virt_mem_handle_exc(cpu, ra);
539 return 0;
541 } else {
542 /* no protection applies */
543 lowcore = cpu_map_lowcore(env);
544 lowcore->subchannel_id = cpu_to_be16(io->id);
545 lowcore->subchannel_nr = cpu_to_be16(io->nr);
546 lowcore->io_int_parm = cpu_to_be32(io->parm);
547 lowcore->io_int_word = cpu_to_be32(io->word);
548 cpu_unmap_lowcore(lowcore);
551 g_free(io);
552 qemu_mutex_unlock_iothread();
553 return 1;
556 void HELPER(tsch)(CPUS390XState *env, uint64_t r1, uint64_t inst)
558 S390CPU *cpu = env_archcpu(env);
559 qemu_mutex_lock_iothread();
560 ioinst_handle_tsch(cpu, r1, inst >> 16, GETPC());
561 qemu_mutex_unlock_iothread();
564 void HELPER(chsc)(CPUS390XState *env, uint64_t inst)
566 S390CPU *cpu = env_archcpu(env);
567 qemu_mutex_lock_iothread();
568 ioinst_handle_chsc(cpu, inst >> 16, GETPC());
569 qemu_mutex_unlock_iothread();
571 #endif
573 #ifndef CONFIG_USER_ONLY
574 void HELPER(per_check_exception)(CPUS390XState *env)
576 if (env->per_perc_atmid) {
577 tcg_s390_program_interrupt(env, PGM_PER, GETPC());
581 /* Check if an address is within the PER starting address and the PER
582 ending address. The address range might loop. */
583 static inline bool get_per_in_range(CPUS390XState *env, uint64_t addr)
585 if (env->cregs[10] <= env->cregs[11]) {
586 return env->cregs[10] <= addr && addr <= env->cregs[11];
587 } else {
588 return env->cregs[10] <= addr || addr <= env->cregs[11];
592 void HELPER(per_branch)(CPUS390XState *env, uint64_t from, uint64_t to)
594 if ((env->cregs[9] & PER_CR9_EVENT_BRANCH)) {
595 if (!(env->cregs[9] & PER_CR9_CONTROL_BRANCH_ADDRESS)
596 || get_per_in_range(env, to)) {
597 env->per_address = from;
598 env->per_perc_atmid = PER_CODE_EVENT_BRANCH | get_per_atmid(env);
603 void HELPER(per_ifetch)(CPUS390XState *env, uint64_t addr)
605 if ((env->cregs[9] & PER_CR9_EVENT_IFETCH) && get_per_in_range(env, addr)) {
606 env->per_address = addr;
607 env->per_perc_atmid = PER_CODE_EVENT_IFETCH | get_per_atmid(env);
609 /* If the instruction has to be nullified, trigger the
610 exception immediately. */
611 if (env->cregs[9] & PER_CR9_EVENT_NULLIFICATION) {
612 CPUState *cs = env_cpu(env);
614 env->per_perc_atmid |= PER_CODE_EVENT_NULLIFICATION;
615 env->int_pgm_code = PGM_PER;
616 env->int_pgm_ilen = get_ilen(cpu_ldub_code(env, addr));
618 cs->exception_index = EXCP_PGM;
619 cpu_loop_exit(cs);
624 void HELPER(per_store_real)(CPUS390XState *env)
626 if ((env->cregs[9] & PER_CR9_EVENT_STORE) &&
627 (env->cregs[9] & PER_CR9_EVENT_STORE_REAL)) {
628 /* PSW is saved just before calling the helper. */
629 env->per_address = env->psw.addr;
630 env->per_perc_atmid = PER_CODE_EVENT_STORE_REAL | get_per_atmid(env);
633 #endif
635 static uint8_t stfl_bytes[2048];
636 static unsigned int used_stfl_bytes;
638 static void prepare_stfl(void)
640 static bool initialized;
641 int i;
643 /* racy, but we don't care, the same values are always written */
644 if (initialized) {
645 return;
648 s390_get_feat_block(S390_FEAT_TYPE_STFL, stfl_bytes);
649 for (i = 0; i < sizeof(stfl_bytes); i++) {
650 if (stfl_bytes[i]) {
651 used_stfl_bytes = i + 1;
654 initialized = true;
657 #ifndef CONFIG_USER_ONLY
658 void HELPER(stfl)(CPUS390XState *env)
660 LowCore *lowcore;
662 lowcore = cpu_map_lowcore(env);
663 prepare_stfl();
664 memcpy(&lowcore->stfl_fac_list, stfl_bytes, sizeof(lowcore->stfl_fac_list));
665 cpu_unmap_lowcore(lowcore);
667 #endif
669 uint32_t HELPER(stfle)(CPUS390XState *env, uint64_t addr)
671 const uintptr_t ra = GETPC();
672 const int count_bytes = ((env->regs[0] & 0xff) + 1) * 8;
673 int max_bytes;
674 int i;
676 if (addr & 0x7) {
677 tcg_s390_program_interrupt(env, PGM_SPECIFICATION, ra);
680 prepare_stfl();
681 max_bytes = ROUND_UP(used_stfl_bytes, 8);
684 * The PoP says that doublewords beyond the highest-numbered facility
685 * bit may or may not be stored. However, existing hardware appears to
686 * not store the words, and existing software depend on that.
688 for (i = 0; i < MIN(count_bytes, max_bytes); ++i) {
689 cpu_stb_data_ra(env, addr + i, stfl_bytes[i], ra);
692 env->regs[0] = deposit64(env->regs[0], 0, 8, (max_bytes / 8) - 1);
693 return count_bytes >= max_bytes ? 0 : 3;
696 #ifndef CONFIG_USER_ONLY
698 * Note: we ignore any return code of the functions called for the pci
699 * instructions, as the only time they return !0 is when the stub is
700 * called, and in that case we didn't even offer the zpci facility.
701 * The only exception is SIC, where program checks need to be handled
702 * by the caller.
704 void HELPER(clp)(CPUS390XState *env, uint32_t r2)
706 S390CPU *cpu = env_archcpu(env);
708 qemu_mutex_lock_iothread();
709 clp_service_call(cpu, r2, GETPC());
710 qemu_mutex_unlock_iothread();
713 void HELPER(pcilg)(CPUS390XState *env, uint32_t r1, uint32_t r2)
715 S390CPU *cpu = env_archcpu(env);
717 qemu_mutex_lock_iothread();
718 pcilg_service_call(cpu, r1, r2, GETPC());
719 qemu_mutex_unlock_iothread();
722 void HELPER(pcistg)(CPUS390XState *env, uint32_t r1, uint32_t r2)
724 S390CPU *cpu = env_archcpu(env);
726 qemu_mutex_lock_iothread();
727 pcistg_service_call(cpu, r1, r2, GETPC());
728 qemu_mutex_unlock_iothread();
731 void HELPER(stpcifc)(CPUS390XState *env, uint32_t r1, uint64_t fiba,
732 uint32_t ar)
734 S390CPU *cpu = env_archcpu(env);
736 qemu_mutex_lock_iothread();
737 stpcifc_service_call(cpu, r1, fiba, ar, GETPC());
738 qemu_mutex_unlock_iothread();
741 void HELPER(sic)(CPUS390XState *env, uint64_t r1, uint64_t r3)
743 int r;
745 qemu_mutex_lock_iothread();
746 r = css_do_sic(env, (r3 >> 27) & 0x7, r1 & 0xffff);
747 qemu_mutex_unlock_iothread();
748 /* css_do_sic() may actually return a PGM_xxx value to inject */
749 if (r) {
750 tcg_s390_program_interrupt(env, -r, GETPC());
754 void HELPER(rpcit)(CPUS390XState *env, uint32_t r1, uint32_t r2)
756 S390CPU *cpu = env_archcpu(env);
758 qemu_mutex_lock_iothread();
759 rpcit_service_call(cpu, r1, r2, GETPC());
760 qemu_mutex_unlock_iothread();
763 void HELPER(pcistb)(CPUS390XState *env, uint32_t r1, uint32_t r3,
764 uint64_t gaddr, uint32_t ar)
766 S390CPU *cpu = env_archcpu(env);
768 qemu_mutex_lock_iothread();
769 pcistb_service_call(cpu, r1, r3, gaddr, ar, GETPC());
770 qemu_mutex_unlock_iothread();
773 void HELPER(mpcifc)(CPUS390XState *env, uint32_t r1, uint64_t fiba,
774 uint32_t ar)
776 S390CPU *cpu = env_archcpu(env);
778 qemu_mutex_lock_iothread();
779 mpcifc_service_call(cpu, r1, fiba, ar, GETPC());
780 qemu_mutex_unlock_iothread();
782 #endif