chardev: split up qmp_chardev_open_socket connection code
[qemu/ar7.git] / target / s390x / misc_helper.c
blob52262f62df263475a1743815f89b1b5ae6feff4e
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"
34 #if !defined(CONFIG_USER_ONLY)
35 #include "sysemu/cpus.h"
36 #include "sysemu/sysemu.h"
37 #include "hw/s390x/ebcdic.h"
38 #include "hw/s390x/s390-virtio-hcall.h"
39 #include "hw/s390x/sclp.h"
40 #include "hw/s390x/s390_flic.h"
41 #include "hw/s390x/ioinst.h"
42 #include "hw/s390x/s390-pci-inst.h"
43 #include "hw/boards.h"
44 #include "hw/s390x/tod.h"
45 #endif
47 /* #define DEBUG_HELPER */
48 #ifdef DEBUG_HELPER
49 #define HELPER_LOG(x...) qemu_log(x)
50 #else
51 #define HELPER_LOG(x...)
52 #endif
54 /* Raise an exception statically from a TB. */
55 void HELPER(exception)(CPUS390XState *env, uint32_t excp)
57 CPUState *cs = CPU(s390_env_get_cpu(env));
59 HELPER_LOG("%s: exception %d\n", __func__, excp);
60 cs->exception_index = excp;
61 cpu_loop_exit(cs);
64 /* Store CPU Timer (also used for EXTRACT CPU TIME) */
65 uint64_t HELPER(stpt)(CPUS390XState *env)
67 #if defined(CONFIG_USER_ONLY)
69 * Fake a descending CPU timer. We could get negative values here,
70 * but we don't care as it is up to the OS when to process that
71 * interrupt and reset to > 0.
73 return UINT64_MAX - (uint64_t)cpu_get_host_ticks();
74 #else
75 return time2tod(env->cputm - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
76 #endif
79 #ifndef CONFIG_USER_ONLY
81 /* SCLP service call */
82 uint32_t HELPER(servc)(CPUS390XState *env, uint64_t r1, uint64_t r2)
84 qemu_mutex_lock_iothread();
85 int r = sclp_service_call(env, r1, r2);
86 qemu_mutex_unlock_iothread();
87 if (r < 0) {
88 s390_program_interrupt(env, -r, 4, GETPC());
90 return r;
93 void HELPER(diag)(CPUS390XState *env, uint32_t r1, uint32_t r3, uint32_t num)
95 uint64_t r;
97 switch (num) {
98 case 0x500:
99 /* KVM hypercall */
100 qemu_mutex_lock_iothread();
101 r = s390_virtio_hypercall(env);
102 qemu_mutex_unlock_iothread();
103 break;
104 case 0x44:
105 /* yield */
106 r = 0;
107 break;
108 case 0x308:
109 /* ipl */
110 qemu_mutex_lock_iothread();
111 handle_diag_308(env, r1, r3, GETPC());
112 qemu_mutex_unlock_iothread();
113 r = 0;
114 break;
115 case 0x288:
116 /* time bomb (watchdog) */
117 r = handle_diag_288(env, r1, r3);
118 break;
119 default:
120 r = -1;
121 break;
124 if (r) {
125 s390_program_interrupt(env, PGM_SPECIFICATION, ILEN_AUTO, GETPC());
129 /* Set Prefix */
130 void HELPER(spx)(CPUS390XState *env, uint64_t a1)
132 CPUState *cs = CPU(s390_env_get_cpu(env));
133 uint32_t prefix = a1 & 0x7fffe000;
135 env->psa = prefix;
136 HELPER_LOG("prefix: %#x\n", prefix);
137 tlb_flush_page(cs, 0);
138 tlb_flush_page(cs, TARGET_PAGE_SIZE);
141 /* Store Clock */
142 uint64_t HELPER(stck)(CPUS390XState *env)
144 S390TODState *td = s390_get_todstate();
145 S390TODClass *tdc = S390_TOD_GET_CLASS(td);
146 S390TOD tod;
148 tdc->get(td, &tod, &error_abort);
149 return tod.low;
152 static void update_ckc_timer(CPUS390XState *env)
154 S390TODState *td = s390_get_todstate();
155 uint64_t time;
157 /* stop the timer and remove pending CKC IRQs */
158 timer_del(env->tod_timer);
159 g_assert(qemu_mutex_iothread_locked());
160 env->pending_int &= ~INTERRUPT_EXT_CLOCK_COMPARATOR;
162 /* the tod has to exceed the ckc, this can never happen if ckc is all 1's */
163 if (env->ckc == -1ULL) {
164 return;
167 /* difference between origins */
168 time = env->ckc - td->base.low;
170 /* nanoseconds */
171 time = tod2time(time);
173 timer_mod(env->tod_timer, time);
176 /* Set Clock Comparator */
177 void HELPER(sckc)(CPUS390XState *env, uint64_t ckc)
179 env->ckc = ckc;
181 qemu_mutex_lock_iothread();
182 update_ckc_timer(env);
183 qemu_mutex_unlock_iothread();
186 void tcg_s390_tod_updated(CPUState *cs, run_on_cpu_data opaque)
188 S390CPU *cpu = S390_CPU(cs);
190 update_ckc_timer(&cpu->env);
193 /* Set Clock */
194 uint32_t HELPER(sck)(CPUS390XState *env, uint64_t tod_low)
196 S390TODState *td = s390_get_todstate();
197 S390TODClass *tdc = S390_TOD_GET_CLASS(td);
198 S390TOD tod = {
199 .high = 0,
200 .low = tod_low,
203 qemu_mutex_lock_iothread();
204 tdc->set(td, &tod, &error_abort);
205 qemu_mutex_unlock_iothread();
206 return 0;
209 /* Set Tod Programmable Field */
210 void HELPER(sckpf)(CPUS390XState *env, uint64_t r0)
212 uint32_t val = r0;
214 if (val & 0xffff0000) {
215 s390_program_interrupt(env, PGM_SPECIFICATION, 2, GETPC());
217 env->todpr = val;
220 /* Store Clock Comparator */
221 uint64_t HELPER(stckc)(CPUS390XState *env)
223 return env->ckc;
226 /* Set CPU Timer */
227 void HELPER(spt)(CPUS390XState *env, uint64_t time)
229 if (time == -1ULL) {
230 return;
233 /* nanoseconds */
234 time = tod2time(time);
236 env->cputm = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + time;
238 timer_mod(env->cpu_timer, env->cputm);
241 /* Store System Information */
242 uint32_t HELPER(stsi)(CPUS390XState *env, uint64_t a0, uint64_t r0, uint64_t r1)
244 const uintptr_t ra = GETPC();
245 const uint32_t sel1 = r0 & STSI_R0_SEL1_MASK;
246 const uint32_t sel2 = r1 & STSI_R1_SEL2_MASK;
247 const MachineState *ms = MACHINE(qdev_get_machine());
248 uint16_t total_cpus = 0, conf_cpus = 0, reserved_cpus = 0;
249 S390CPU *cpu = s390_env_get_cpu(env);
250 SysIB sysib = { };
251 int i, cc = 0;
253 if ((r0 & STSI_R0_FC_MASK) > STSI_R0_FC_LEVEL_3) {
254 /* invalid function code: no other checks are performed */
255 return 3;
258 if ((r0 & STSI_R0_RESERVED_MASK) || (r1 & STSI_R1_RESERVED_MASK)) {
259 s390_program_interrupt(env, PGM_SPECIFICATION, 4, ra);
262 if ((r0 & STSI_R0_FC_MASK) == STSI_R0_FC_CURRENT) {
263 /* query the current level: no further checks are performed */
264 env->regs[0] = STSI_R0_FC_LEVEL_3;
265 return 0;
268 if (a0 & ~TARGET_PAGE_MASK) {
269 s390_program_interrupt(env, PGM_SPECIFICATION, 4, ra);
272 /* count the cpus and split them into configured and reserved ones */
273 for (i = 0; i < ms->possible_cpus->len; i++) {
274 total_cpus++;
275 if (ms->possible_cpus->cpus[i].cpu) {
276 conf_cpus++;
277 } else {
278 reserved_cpus++;
283 * In theory, we could report Level 1 / Level 2 as current. However,
284 * the Linux kernel will detect this as running under LPAR and assume
285 * that we have a sclp linemode console (which is always present on
286 * LPAR, but not the default for QEMU), therefore not displaying boot
287 * messages and making booting a Linux kernel under TCG harder.
289 * For now we fake the same SMP configuration on all levels.
291 * TODO: We could later make the level configurable via the machine
292 * and change defaults (linemode console) based on machine type
293 * and accelerator.
295 switch (r0 & STSI_R0_FC_MASK) {
296 case STSI_R0_FC_LEVEL_1:
297 if ((sel1 == 1) && (sel2 == 1)) {
298 /* Basic Machine Configuration */
299 char type[5] = {};
301 ebcdic_put(sysib.sysib_111.manuf, "QEMU ", 16);
302 /* same as machine type number in STORE CPU ID, but in EBCDIC */
303 snprintf(type, ARRAY_SIZE(type), "%X", cpu->model->def->type);
304 ebcdic_put(sysib.sysib_111.type, type, 4);
305 /* model number (not stored in STORE CPU ID for z/Architecure) */
306 ebcdic_put(sysib.sysib_111.model, "QEMU ", 16);
307 ebcdic_put(sysib.sysib_111.sequence, "QEMU ", 16);
308 ebcdic_put(sysib.sysib_111.plant, "QEMU", 4);
309 } else if ((sel1 == 2) && (sel2 == 1)) {
310 /* Basic Machine CPU */
311 ebcdic_put(sysib.sysib_121.sequence, "QEMUQEMUQEMUQEMU", 16);
312 ebcdic_put(sysib.sysib_121.plant, "QEMU", 4);
313 sysib.sysib_121.cpu_addr = cpu_to_be16(env->core_id);
314 } else if ((sel1 == 2) && (sel2 == 2)) {
315 /* Basic Machine CPUs */
316 sysib.sysib_122.capability = cpu_to_be32(0x443afc29);
317 sysib.sysib_122.total_cpus = cpu_to_be16(total_cpus);
318 sysib.sysib_122.conf_cpus = cpu_to_be16(conf_cpus);
319 sysib.sysib_122.reserved_cpus = cpu_to_be16(reserved_cpus);
320 } else {
321 cc = 3;
323 break;
324 case STSI_R0_FC_LEVEL_2:
325 if ((sel1 == 2) && (sel2 == 1)) {
326 /* LPAR CPU */
327 ebcdic_put(sysib.sysib_221.sequence, "QEMUQEMUQEMUQEMU", 16);
328 ebcdic_put(sysib.sysib_221.plant, "QEMU", 4);
329 sysib.sysib_221.cpu_addr = cpu_to_be16(env->core_id);
330 } else if ((sel1 == 2) && (sel2 == 2)) {
331 /* LPAR CPUs */
332 sysib.sysib_222.lcpuc = 0x80; /* dedicated */
333 sysib.sysib_222.total_cpus = cpu_to_be16(total_cpus);
334 sysib.sysib_222.conf_cpus = cpu_to_be16(conf_cpus);
335 sysib.sysib_222.reserved_cpus = cpu_to_be16(reserved_cpus);
336 ebcdic_put(sysib.sysib_222.name, "QEMU ", 8);
337 sysib.sysib_222.caf = cpu_to_be32(1000);
338 sysib.sysib_222.dedicated_cpus = cpu_to_be16(conf_cpus);
339 } else {
340 cc = 3;
342 break;
343 case STSI_R0_FC_LEVEL_3:
344 if ((sel1 == 2) && (sel2 == 2)) {
345 /* VM CPUs */
346 sysib.sysib_322.count = 1;
347 sysib.sysib_322.vm[0].total_cpus = cpu_to_be16(total_cpus);
348 sysib.sysib_322.vm[0].conf_cpus = cpu_to_be16(conf_cpus);
349 sysib.sysib_322.vm[0].reserved_cpus = cpu_to_be16(reserved_cpus);
350 sysib.sysib_322.vm[0].caf = cpu_to_be32(1000);
351 /* Linux kernel uses this to distinguish us from z/VM */
352 ebcdic_put(sysib.sysib_322.vm[0].cpi, "KVM/Linux ", 16);
353 sysib.sysib_322.vm[0].ext_name_encoding = 2; /* UTF-8 */
355 /* If our VM has a name, use the real name */
356 if (qemu_name) {
357 memset(sysib.sysib_322.vm[0].name, 0x40,
358 sizeof(sysib.sysib_322.vm[0].name));
359 ebcdic_put(sysib.sysib_322.vm[0].name, qemu_name,
360 MIN(sizeof(sysib.sysib_322.vm[0].name),
361 strlen(qemu_name)));
362 strncpy((char *)sysib.sysib_322.ext_names[0], qemu_name,
363 sizeof(sysib.sysib_322.ext_names[0]));
364 } else {
365 ebcdic_put(sysib.sysib_322.vm[0].name, "TCGguest", 8);
366 strcpy((char *)sysib.sysib_322.ext_names[0], "TCGguest");
369 /* add the uuid */
370 memcpy(sysib.sysib_322.vm[0].uuid, &qemu_uuid,
371 sizeof(sysib.sysib_322.vm[0].uuid));
372 } else {
373 cc = 3;
375 break;
378 if (cc == 0) {
379 if (s390_cpu_virt_mem_write(cpu, a0, 0, &sysib, sizeof(sysib))) {
380 s390_cpu_virt_mem_handle_exc(cpu, ra);
384 return cc;
387 uint32_t HELPER(sigp)(CPUS390XState *env, uint64_t order_code, uint32_t r1,
388 uint32_t r3)
390 int cc;
392 /* TODO: needed to inject interrupts - push further down */
393 qemu_mutex_lock_iothread();
394 cc = handle_sigp(env, order_code & SIGP_ORDER_MASK, r1, r3);
395 qemu_mutex_unlock_iothread();
397 return cc;
399 #endif
401 #ifndef CONFIG_USER_ONLY
402 void HELPER(xsch)(CPUS390XState *env, uint64_t r1)
404 S390CPU *cpu = s390_env_get_cpu(env);
405 qemu_mutex_lock_iothread();
406 ioinst_handle_xsch(cpu, r1, GETPC());
407 qemu_mutex_unlock_iothread();
410 void HELPER(csch)(CPUS390XState *env, uint64_t r1)
412 S390CPU *cpu = s390_env_get_cpu(env);
413 qemu_mutex_lock_iothread();
414 ioinst_handle_csch(cpu, r1, GETPC());
415 qemu_mutex_unlock_iothread();
418 void HELPER(hsch)(CPUS390XState *env, uint64_t r1)
420 S390CPU *cpu = s390_env_get_cpu(env);
421 qemu_mutex_lock_iothread();
422 ioinst_handle_hsch(cpu, r1, GETPC());
423 qemu_mutex_unlock_iothread();
426 void HELPER(msch)(CPUS390XState *env, uint64_t r1, uint64_t inst)
428 S390CPU *cpu = s390_env_get_cpu(env);
429 qemu_mutex_lock_iothread();
430 ioinst_handle_msch(cpu, r1, inst >> 16, GETPC());
431 qemu_mutex_unlock_iothread();
434 void HELPER(rchp)(CPUS390XState *env, uint64_t r1)
436 S390CPU *cpu = s390_env_get_cpu(env);
437 qemu_mutex_lock_iothread();
438 ioinst_handle_rchp(cpu, r1, GETPC());
439 qemu_mutex_unlock_iothread();
442 void HELPER(rsch)(CPUS390XState *env, uint64_t r1)
444 S390CPU *cpu = s390_env_get_cpu(env);
445 qemu_mutex_lock_iothread();
446 ioinst_handle_rsch(cpu, r1, GETPC());
447 qemu_mutex_unlock_iothread();
450 void HELPER(sal)(CPUS390XState *env, uint64_t r1)
452 S390CPU *cpu = s390_env_get_cpu(env);
454 qemu_mutex_lock_iothread();
455 ioinst_handle_sal(cpu, r1, GETPC());
456 qemu_mutex_unlock_iothread();
459 void HELPER(schm)(CPUS390XState *env, uint64_t r1, uint64_t r2, uint64_t inst)
461 S390CPU *cpu = s390_env_get_cpu(env);
463 qemu_mutex_lock_iothread();
464 ioinst_handle_schm(cpu, r1, r2, inst >> 16, GETPC());
465 qemu_mutex_unlock_iothread();
468 void HELPER(ssch)(CPUS390XState *env, uint64_t r1, uint64_t inst)
470 S390CPU *cpu = s390_env_get_cpu(env);
471 qemu_mutex_lock_iothread();
472 ioinst_handle_ssch(cpu, r1, inst >> 16, GETPC());
473 qemu_mutex_unlock_iothread();
476 void HELPER(stcrw)(CPUS390XState *env, uint64_t inst)
478 S390CPU *cpu = s390_env_get_cpu(env);
480 qemu_mutex_lock_iothread();
481 ioinst_handle_stcrw(cpu, inst >> 16, GETPC());
482 qemu_mutex_unlock_iothread();
485 void HELPER(stsch)(CPUS390XState *env, uint64_t r1, uint64_t inst)
487 S390CPU *cpu = s390_env_get_cpu(env);
488 qemu_mutex_lock_iothread();
489 ioinst_handle_stsch(cpu, r1, inst >> 16, GETPC());
490 qemu_mutex_unlock_iothread();
493 uint32_t HELPER(tpi)(CPUS390XState *env, uint64_t addr)
495 const uintptr_t ra = GETPC();
496 S390CPU *cpu = s390_env_get_cpu(env);
497 QEMUS390FLICState *flic = s390_get_qemu_flic(s390_get_flic());
498 QEMUS390FlicIO *io = NULL;
499 LowCore *lowcore;
501 if (addr & 0x3) {
502 s390_program_interrupt(env, PGM_SPECIFICATION, 4, ra);
505 qemu_mutex_lock_iothread();
506 io = qemu_s390_flic_dequeue_io(flic, env->cregs[6]);
507 if (!io) {
508 qemu_mutex_unlock_iothread();
509 return 0;
512 if (addr) {
513 struct {
514 uint16_t id;
515 uint16_t nr;
516 uint32_t parm;
517 } intc = {
518 .id = cpu_to_be16(io->id),
519 .nr = cpu_to_be16(io->nr),
520 .parm = cpu_to_be32(io->parm),
523 if (s390_cpu_virt_mem_write(cpu, addr, 0, &intc, sizeof(intc))) {
524 /* writing failed, reinject and properly clean up */
525 s390_io_interrupt(io->id, io->nr, io->parm, io->word);
526 qemu_mutex_unlock_iothread();
527 g_free(io);
528 s390_cpu_virt_mem_handle_exc(cpu, ra);
529 return 0;
531 } else {
532 /* no protection applies */
533 lowcore = cpu_map_lowcore(env);
534 lowcore->subchannel_id = cpu_to_be16(io->id);
535 lowcore->subchannel_nr = cpu_to_be16(io->nr);
536 lowcore->io_int_parm = cpu_to_be32(io->parm);
537 lowcore->io_int_word = cpu_to_be32(io->word);
538 cpu_unmap_lowcore(lowcore);
541 g_free(io);
542 qemu_mutex_unlock_iothread();
543 return 1;
546 void HELPER(tsch)(CPUS390XState *env, uint64_t r1, uint64_t inst)
548 S390CPU *cpu = s390_env_get_cpu(env);
549 qemu_mutex_lock_iothread();
550 ioinst_handle_tsch(cpu, r1, inst >> 16, GETPC());
551 qemu_mutex_unlock_iothread();
554 void HELPER(chsc)(CPUS390XState *env, uint64_t inst)
556 S390CPU *cpu = s390_env_get_cpu(env);
557 qemu_mutex_lock_iothread();
558 ioinst_handle_chsc(cpu, inst >> 16, GETPC());
559 qemu_mutex_unlock_iothread();
561 #endif
563 #ifndef CONFIG_USER_ONLY
564 void HELPER(per_check_exception)(CPUS390XState *env)
566 uint32_t ilen;
568 if (env->per_perc_atmid) {
570 * FIXME: ILEN_AUTO is most probably the right thing to use. ilen
571 * always has to match the instruction referenced in the PSW. E.g.
572 * if a PER interrupt is triggered via EXECUTE, we have to use ilen
573 * of EXECUTE, while per_address contains the target of EXECUTE.
575 ilen = get_ilen(cpu_ldub_code(env, env->per_address));
576 s390_program_interrupt(env, PGM_PER, ilen, GETPC());
580 /* Check if an address is within the PER starting address and the PER
581 ending address. The address range might loop. */
582 static inline bool get_per_in_range(CPUS390XState *env, uint64_t addr)
584 if (env->cregs[10] <= env->cregs[11]) {
585 return env->cregs[10] <= addr && addr <= env->cregs[11];
586 } else {
587 return env->cregs[10] <= addr || addr <= env->cregs[11];
591 void HELPER(per_branch)(CPUS390XState *env, uint64_t from, uint64_t to)
593 if ((env->cregs[9] & PER_CR9_EVENT_BRANCH)) {
594 if (!(env->cregs[9] & PER_CR9_CONTROL_BRANCH_ADDRESS)
595 || get_per_in_range(env, to)) {
596 env->per_address = from;
597 env->per_perc_atmid = PER_CODE_EVENT_BRANCH | get_per_atmid(env);
602 void HELPER(per_ifetch)(CPUS390XState *env, uint64_t addr)
604 if ((env->cregs[9] & PER_CR9_EVENT_IFETCH) && get_per_in_range(env, addr)) {
605 env->per_address = addr;
606 env->per_perc_atmid = PER_CODE_EVENT_IFETCH | get_per_atmid(env);
608 /* If the instruction has to be nullified, trigger the
609 exception immediately. */
610 if (env->cregs[9] & PER_CR9_EVENT_NULLIFICATION) {
611 CPUState *cs = CPU(s390_env_get_cpu(env));
613 env->per_perc_atmid |= PER_CODE_EVENT_NULLIFICATION;
614 env->int_pgm_code = PGM_PER;
615 env->int_pgm_ilen = get_ilen(cpu_ldub_code(env, addr));
617 cs->exception_index = EXCP_PGM;
618 cpu_loop_exit(cs);
622 #endif
624 static uint8_t stfl_bytes[2048];
625 static unsigned int used_stfl_bytes;
627 static void prepare_stfl(void)
629 static bool initialized;
630 int i;
632 /* racy, but we don't care, the same values are always written */
633 if (initialized) {
634 return;
637 s390_get_feat_block(S390_FEAT_TYPE_STFL, stfl_bytes);
638 for (i = 0; i < sizeof(stfl_bytes); i++) {
639 if (stfl_bytes[i]) {
640 used_stfl_bytes = i + 1;
643 initialized = true;
646 #ifndef CONFIG_USER_ONLY
647 void HELPER(stfl)(CPUS390XState *env)
649 LowCore *lowcore;
651 lowcore = cpu_map_lowcore(env);
652 prepare_stfl();
653 memcpy(&lowcore->stfl_fac_list, stfl_bytes, sizeof(lowcore->stfl_fac_list));
654 cpu_unmap_lowcore(lowcore);
656 #endif
658 uint32_t HELPER(stfle)(CPUS390XState *env, uint64_t addr)
660 const uintptr_t ra = GETPC();
661 const int count_bytes = ((env->regs[0] & 0xff) + 1) * 8;
662 const int max_bytes = ROUND_UP(used_stfl_bytes, 8);
663 int i;
665 if (addr & 0x7) {
666 s390_program_interrupt(env, PGM_SPECIFICATION, 4, ra);
669 prepare_stfl();
670 for (i = 0; i < count_bytes; ++i) {
671 cpu_stb_data_ra(env, addr + i, stfl_bytes[i], ra);
674 env->regs[0] = deposit64(env->regs[0], 0, 8, (max_bytes / 8) - 1);
675 return count_bytes >= max_bytes ? 0 : 3;
678 #ifndef CONFIG_USER_ONLY
680 * Note: we ignore any return code of the functions called for the pci
681 * instructions, as the only time they return !0 is when the stub is
682 * called, and in that case we didn't even offer the zpci facility.
683 * The only exception is SIC, where program checks need to be handled
684 * by the caller.
686 void HELPER(clp)(CPUS390XState *env, uint32_t r2)
688 S390CPU *cpu = s390_env_get_cpu(env);
690 qemu_mutex_lock_iothread();
691 clp_service_call(cpu, r2, GETPC());
692 qemu_mutex_unlock_iothread();
695 void HELPER(pcilg)(CPUS390XState *env, uint32_t r1, uint32_t r2)
697 S390CPU *cpu = s390_env_get_cpu(env);
699 qemu_mutex_lock_iothread();
700 pcilg_service_call(cpu, r1, r2, GETPC());
701 qemu_mutex_unlock_iothread();
704 void HELPER(pcistg)(CPUS390XState *env, uint32_t r1, uint32_t r2)
706 S390CPU *cpu = s390_env_get_cpu(env);
708 qemu_mutex_lock_iothread();
709 pcistg_service_call(cpu, r1, r2, GETPC());
710 qemu_mutex_unlock_iothread();
713 void HELPER(stpcifc)(CPUS390XState *env, uint32_t r1, uint64_t fiba,
714 uint32_t ar)
716 S390CPU *cpu = s390_env_get_cpu(env);
718 qemu_mutex_lock_iothread();
719 stpcifc_service_call(cpu, r1, fiba, ar, GETPC());
720 qemu_mutex_unlock_iothread();
723 void HELPER(sic)(CPUS390XState *env, uint64_t r1, uint64_t r3)
725 int r;
727 qemu_mutex_lock_iothread();
728 r = css_do_sic(env, (r3 >> 27) & 0x7, r1 & 0xffff);
729 qemu_mutex_unlock_iothread();
730 /* css_do_sic() may actually return a PGM_xxx value to inject */
731 if (r) {
732 s390_program_interrupt(env, -r, 4, GETPC());
736 void HELPER(rpcit)(CPUS390XState *env, uint32_t r1, uint32_t r2)
738 S390CPU *cpu = s390_env_get_cpu(env);
740 qemu_mutex_lock_iothread();
741 rpcit_service_call(cpu, r1, r2, GETPC());
742 qemu_mutex_unlock_iothread();
745 void HELPER(pcistb)(CPUS390XState *env, uint32_t r1, uint32_t r3,
746 uint64_t gaddr, uint32_t ar)
748 S390CPU *cpu = s390_env_get_cpu(env);
750 qemu_mutex_lock_iothread();
751 pcistb_service_call(cpu, r1, r3, gaddr, ar, GETPC());
752 qemu_mutex_unlock_iothread();
755 void HELPER(mpcifc)(CPUS390XState *env, uint32_t r1, uint64_t fiba,
756 uint32_t ar)
758 S390CPU *cpu = s390_env_get_cpu(env);
760 qemu_mutex_lock_iothread();
761 mpcifc_service_call(cpu, r1, fiba, ar, GETPC());
762 qemu_mutex_unlock_iothread();
764 #endif