target/s390x: correctly indicate PER nullification
[qemu/ar7.git] / target / s390x / misc_helper.c
blobd6eda832eb9db7ad90453d318a26aa384c732029
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 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 "exec/memory.h"
25 #include "qemu/host-utils.h"
26 #include "exec/helper-proto.h"
27 #include "sysemu/kvm.h"
28 #include "qemu/timer.h"
29 #include "qemu/main-loop.h"
30 #include "exec/address-spaces.h"
31 #ifdef CONFIG_KVM
32 #include <linux/kvm.h>
33 #endif
34 #include "exec/exec-all.h"
35 #include "exec/cpu_ldst.h"
37 #if !defined(CONFIG_USER_ONLY)
38 #include "hw/watchdog/wdt_diag288.h"
39 #include "sysemu/cpus.h"
40 #include "sysemu/sysemu.h"
41 #include "hw/s390x/ebcdic.h"
42 #include "hw/s390x/ipl.h"
43 #endif
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
52 /* Raise an exception dynamically from a helper function. */
53 void QEMU_NORETURN runtime_exception(CPUS390XState *env, int excp,
54 uintptr_t retaddr)
56 CPUState *cs = CPU(s390_env_get_cpu(env));
57 int t;
59 cs->exception_index = EXCP_PGM;
60 env->int_pgm_code = excp;
62 /* Use the (ultimate) callers address to find the insn that trapped. */
63 cpu_restore_state(cs, retaddr);
65 /* Advance past the insn. */
66 t = cpu_ldub_code(env, env->psw.addr);
67 env->int_pgm_ilen = t = get_ilen(t);
68 env->psw.addr += t;
70 cpu_loop_exit(cs);
73 /* Raise an exception statically from a TB. */
74 void HELPER(exception)(CPUS390XState *env, uint32_t excp)
76 CPUState *cs = CPU(s390_env_get_cpu(env));
78 HELPER_LOG("%s: exception %d\n", __func__, excp);
79 cs->exception_index = excp;
80 cpu_loop_exit(cs);
83 void program_interrupt(CPUS390XState *env, uint32_t code, int ilen)
85 S390CPU *cpu = s390_env_get_cpu(env);
87 qemu_log_mask(CPU_LOG_INT, "program interrupt at %#" PRIx64 "\n",
88 env->psw.addr);
90 if (kvm_enabled()) {
91 #ifdef CONFIG_KVM
92 struct kvm_s390_irq irq = {
93 .type = KVM_S390_PROGRAM_INT,
94 .u.pgm.code = code,
97 kvm_s390_vcpu_interrupt(cpu, &irq);
98 #endif
99 } else {
100 CPUState *cs = CPU(cpu);
102 env->int_pgm_code = code;
103 env->int_pgm_ilen = ilen;
104 cs->exception_index = EXCP_PGM;
105 cpu_loop_exit(cs);
109 #ifndef CONFIG_USER_ONLY
111 /* SCLP service call */
112 uint32_t HELPER(servc)(CPUS390XState *env, uint64_t r1, uint64_t r2)
114 qemu_mutex_lock_iothread();
115 int r = sclp_service_call(env, r1, r2);
116 if (r < 0) {
117 program_interrupt(env, -r, 4);
118 r = 0;
120 qemu_mutex_unlock_iothread();
121 return r;
124 #ifndef CONFIG_USER_ONLY
125 static int modified_clear_reset(S390CPU *cpu)
127 S390CPUClass *scc = S390_CPU_GET_CLASS(cpu);
128 CPUState *t;
130 pause_all_vcpus();
131 cpu_synchronize_all_states();
132 CPU_FOREACH(t) {
133 run_on_cpu(t, s390_do_cpu_full_reset, RUN_ON_CPU_NULL);
135 s390_cmma_reset();
136 subsystem_reset();
137 s390_crypto_reset();
138 scc->load_normal(CPU(cpu));
139 cpu_synchronize_all_post_reset();
140 resume_all_vcpus();
141 return 0;
144 static int load_normal_reset(S390CPU *cpu)
146 S390CPUClass *scc = S390_CPU_GET_CLASS(cpu);
147 CPUState *t;
149 pause_all_vcpus();
150 cpu_synchronize_all_states();
151 CPU_FOREACH(t) {
152 run_on_cpu(t, s390_do_cpu_reset, RUN_ON_CPU_NULL);
154 s390_cmma_reset();
155 subsystem_reset();
156 scc->initial_cpu_reset(CPU(cpu));
157 scc->load_normal(CPU(cpu));
158 cpu_synchronize_all_post_reset();
159 resume_all_vcpus();
160 return 0;
163 int handle_diag_288(CPUS390XState *env, uint64_t r1, uint64_t r3)
165 uint64_t func = env->regs[r1];
166 uint64_t timeout = env->regs[r1 + 1];
167 uint64_t action = env->regs[r3];
168 Object *obj;
169 DIAG288State *diag288;
170 DIAG288Class *diag288_class;
172 if (r1 % 2 || action != 0) {
173 return -1;
176 /* Timeout must be more than 15 seconds except for timer deletion */
177 if (func != WDT_DIAG288_CANCEL && timeout < 15) {
178 return -1;
181 obj = object_resolve_path_type("", TYPE_WDT_DIAG288, NULL);
182 if (!obj) {
183 return -1;
186 diag288 = DIAG288(obj);
187 diag288_class = DIAG288_GET_CLASS(diag288);
188 return diag288_class->handle_timer(diag288, func, timeout);
191 #define DIAG_308_RC_OK 0x0001
192 #define DIAG_308_RC_NO_CONF 0x0102
193 #define DIAG_308_RC_INVALID 0x0402
195 void handle_diag_308(CPUS390XState *env, uint64_t r1, uint64_t r3)
197 uint64_t addr = env->regs[r1];
198 uint64_t subcode = env->regs[r3];
199 IplParameterBlock *iplb;
201 if (env->psw.mask & PSW_MASK_PSTATE) {
202 program_interrupt(env, PGM_PRIVILEGED, ILEN_LATER_INC);
203 return;
206 if ((subcode & ~0x0ffffULL) || (subcode > 6)) {
207 program_interrupt(env, PGM_SPECIFICATION, ILEN_LATER_INC);
208 return;
211 switch (subcode) {
212 case 0:
213 modified_clear_reset(s390_env_get_cpu(env));
214 if (tcg_enabled()) {
215 cpu_loop_exit(CPU(s390_env_get_cpu(env)));
217 break;
218 case 1:
219 load_normal_reset(s390_env_get_cpu(env));
220 if (tcg_enabled()) {
221 cpu_loop_exit(CPU(s390_env_get_cpu(env)));
223 break;
224 case 3:
225 s390_reipl_request();
226 if (tcg_enabled()) {
227 cpu_loop_exit(CPU(s390_env_get_cpu(env)));
229 break;
230 case 5:
231 if ((r1 & 1) || (addr & 0x0fffULL)) {
232 program_interrupt(env, PGM_SPECIFICATION, ILEN_LATER_INC);
233 return;
235 if (!address_space_access_valid(&address_space_memory, addr,
236 sizeof(IplParameterBlock), false)) {
237 program_interrupt(env, PGM_ADDRESSING, ILEN_LATER_INC);
238 return;
240 iplb = g_malloc0(sizeof(IplParameterBlock));
241 cpu_physical_memory_read(addr, iplb, sizeof(iplb->len));
242 if (!iplb_valid_len(iplb)) {
243 env->regs[r1 + 1] = DIAG_308_RC_INVALID;
244 goto out;
247 cpu_physical_memory_read(addr, iplb, be32_to_cpu(iplb->len));
249 if (!iplb_valid_ccw(iplb) && !iplb_valid_fcp(iplb)) {
250 env->regs[r1 + 1] = DIAG_308_RC_INVALID;
251 goto out;
254 s390_ipl_update_diag308(iplb);
255 env->regs[r1 + 1] = DIAG_308_RC_OK;
256 out:
257 g_free(iplb);
258 return;
259 case 6:
260 if ((r1 & 1) || (addr & 0x0fffULL)) {
261 program_interrupt(env, PGM_SPECIFICATION, ILEN_LATER_INC);
262 return;
264 if (!address_space_access_valid(&address_space_memory, addr,
265 sizeof(IplParameterBlock), true)) {
266 program_interrupt(env, PGM_ADDRESSING, ILEN_LATER_INC);
267 return;
269 iplb = s390_ipl_get_iplb();
270 if (iplb) {
271 cpu_physical_memory_write(addr, iplb, be32_to_cpu(iplb->len));
272 env->regs[r1 + 1] = DIAG_308_RC_OK;
273 } else {
274 env->regs[r1 + 1] = DIAG_308_RC_NO_CONF;
276 return;
277 default:
278 hw_error("Unhandled diag308 subcode %" PRIx64, subcode);
279 break;
282 #endif
284 void HELPER(diag)(CPUS390XState *env, uint32_t r1, uint32_t r3, uint32_t num)
286 uint64_t r;
288 switch (num) {
289 case 0x500:
290 /* KVM hypercall */
291 qemu_mutex_lock_iothread();
292 r = s390_virtio_hypercall(env);
293 qemu_mutex_unlock_iothread();
294 break;
295 case 0x44:
296 /* yield */
297 r = 0;
298 break;
299 case 0x308:
300 /* ipl */
301 handle_diag_308(env, r1, r3);
302 r = 0;
303 break;
304 default:
305 r = -1;
306 break;
309 if (r) {
310 program_interrupt(env, PGM_OPERATION, ILEN_LATER_INC);
314 /* Set Prefix */
315 void HELPER(spx)(CPUS390XState *env, uint64_t a1)
317 CPUState *cs = CPU(s390_env_get_cpu(env));
318 uint32_t prefix = a1 & 0x7fffe000;
320 env->psa = prefix;
321 HELPER_LOG("prefix: %#x\n", prefix);
322 tlb_flush_page(cs, 0);
323 tlb_flush_page(cs, TARGET_PAGE_SIZE);
326 /* Store Clock */
327 uint64_t HELPER(stck)(CPUS390XState *env)
329 uint64_t time;
331 time = env->tod_offset +
332 time2tod(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) - env->tod_basetime);
334 return time;
337 /* Set Clock Comparator */
338 void HELPER(sckc)(CPUS390XState *env, uint64_t time)
340 if (time == -1ULL) {
341 return;
344 env->ckc = time;
346 /* difference between origins */
347 time -= env->tod_offset;
349 /* nanoseconds */
350 time = tod2time(time);
352 timer_mod(env->tod_timer, env->tod_basetime + time);
355 /* Store Clock Comparator */
356 uint64_t HELPER(stckc)(CPUS390XState *env)
358 return env->ckc;
361 /* Set CPU Timer */
362 void HELPER(spt)(CPUS390XState *env, uint64_t time)
364 if (time == -1ULL) {
365 return;
368 /* nanoseconds */
369 time = tod2time(time);
371 env->cputm = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + time;
373 timer_mod(env->cpu_timer, env->cputm);
376 /* Store CPU Timer */
377 uint64_t HELPER(stpt)(CPUS390XState *env)
379 return time2tod(env->cputm - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
382 /* Store System Information */
383 uint32_t HELPER(stsi)(CPUS390XState *env, uint64_t a0,
384 uint64_t r0, uint64_t r1)
386 int cc = 0;
387 int sel1, sel2;
389 if ((r0 & STSI_LEVEL_MASK) <= STSI_LEVEL_3 &&
390 ((r0 & STSI_R0_RESERVED_MASK) || (r1 & STSI_R1_RESERVED_MASK))) {
391 /* valid function code, invalid reserved bits */
392 program_interrupt(env, PGM_SPECIFICATION, 2);
395 sel1 = r0 & STSI_R0_SEL1_MASK;
396 sel2 = r1 & STSI_R1_SEL2_MASK;
398 /* XXX: spec exception if sysib is not 4k-aligned */
400 switch (r0 & STSI_LEVEL_MASK) {
401 case STSI_LEVEL_1:
402 if ((sel1 == 1) && (sel2 == 1)) {
403 /* Basic Machine Configuration */
404 struct sysib_111 sysib;
406 memset(&sysib, 0, sizeof(sysib));
407 ebcdic_put(sysib.manuf, "QEMU ", 16);
408 /* same as machine type number in STORE CPU ID */
409 ebcdic_put(sysib.type, "QEMU", 4);
410 /* same as model number in STORE CPU ID */
411 ebcdic_put(sysib.model, "QEMU ", 16);
412 ebcdic_put(sysib.sequence, "QEMU ", 16);
413 ebcdic_put(sysib.plant, "QEMU", 4);
414 cpu_physical_memory_write(a0, &sysib, sizeof(sysib));
415 } else if ((sel1 == 2) && (sel2 == 1)) {
416 /* Basic Machine CPU */
417 struct sysib_121 sysib;
419 memset(&sysib, 0, sizeof(sysib));
420 /* XXX make different for different CPUs? */
421 ebcdic_put(sysib.sequence, "QEMUQEMUQEMUQEMU", 16);
422 ebcdic_put(sysib.plant, "QEMU", 4);
423 stw_p(&sysib.cpu_addr, env->cpu_num);
424 cpu_physical_memory_write(a0, &sysib, sizeof(sysib));
425 } else if ((sel1 == 2) && (sel2 == 2)) {
426 /* Basic Machine CPUs */
427 struct sysib_122 sysib;
429 memset(&sysib, 0, sizeof(sysib));
430 stl_p(&sysib.capability, 0x443afc29);
431 /* XXX change when SMP comes */
432 stw_p(&sysib.total_cpus, 1);
433 stw_p(&sysib.active_cpus, 1);
434 stw_p(&sysib.standby_cpus, 0);
435 stw_p(&sysib.reserved_cpus, 0);
436 cpu_physical_memory_write(a0, &sysib, sizeof(sysib));
437 } else {
438 cc = 3;
440 break;
441 case STSI_LEVEL_2:
443 if ((sel1 == 2) && (sel2 == 1)) {
444 /* LPAR CPU */
445 struct sysib_221 sysib;
447 memset(&sysib, 0, sizeof(sysib));
448 /* XXX make different for different CPUs? */
449 ebcdic_put(sysib.sequence, "QEMUQEMUQEMUQEMU", 16);
450 ebcdic_put(sysib.plant, "QEMU", 4);
451 stw_p(&sysib.cpu_addr, env->cpu_num);
452 stw_p(&sysib.cpu_id, 0);
453 cpu_physical_memory_write(a0, &sysib, sizeof(sysib));
454 } else if ((sel1 == 2) && (sel2 == 2)) {
455 /* LPAR CPUs */
456 struct sysib_222 sysib;
458 memset(&sysib, 0, sizeof(sysib));
459 stw_p(&sysib.lpar_num, 0);
460 sysib.lcpuc = 0;
461 /* XXX change when SMP comes */
462 stw_p(&sysib.total_cpus, 1);
463 stw_p(&sysib.conf_cpus, 1);
464 stw_p(&sysib.standby_cpus, 0);
465 stw_p(&sysib.reserved_cpus, 0);
466 ebcdic_put(sysib.name, "QEMU ", 8);
467 stl_p(&sysib.caf, 1000);
468 stw_p(&sysib.dedicated_cpus, 0);
469 stw_p(&sysib.shared_cpus, 0);
470 cpu_physical_memory_write(a0, &sysib, sizeof(sysib));
471 } else {
472 cc = 3;
474 break;
476 case STSI_LEVEL_3:
478 if ((sel1 == 2) && (sel2 == 2)) {
479 /* VM CPUs */
480 struct sysib_322 sysib;
482 memset(&sysib, 0, sizeof(sysib));
483 sysib.count = 1;
484 /* XXX change when SMP comes */
485 stw_p(&sysib.vm[0].total_cpus, 1);
486 stw_p(&sysib.vm[0].conf_cpus, 1);
487 stw_p(&sysib.vm[0].standby_cpus, 0);
488 stw_p(&sysib.vm[0].reserved_cpus, 0);
489 ebcdic_put(sysib.vm[0].name, "KVMguest", 8);
490 stl_p(&sysib.vm[0].caf, 1000);
491 ebcdic_put(sysib.vm[0].cpi, "KVM/Linux ", 16);
492 cpu_physical_memory_write(a0, &sysib, sizeof(sysib));
493 } else {
494 cc = 3;
496 break;
498 case STSI_LEVEL_CURRENT:
499 env->regs[0] = STSI_LEVEL_3;
500 break;
501 default:
502 cc = 3;
503 break;
506 return cc;
509 uint32_t HELPER(sigp)(CPUS390XState *env, uint64_t order_code, uint32_t r1,
510 uint64_t cpu_addr)
512 int cc = SIGP_CC_ORDER_CODE_ACCEPTED;
514 HELPER_LOG("%s: %016" PRIx64 " %08x %016" PRIx64 "\n",
515 __func__, order_code, r1, cpu_addr);
517 /* Remember: Use "R1 or R1 + 1, whichever is the odd-numbered register"
518 as parameter (input). Status (output) is always R1. */
520 switch (order_code & SIGP_ORDER_MASK) {
521 case SIGP_SET_ARCH:
522 /* switch arch */
523 break;
524 case SIGP_SENSE:
525 /* enumerate CPU status */
526 if (cpu_addr) {
527 /* XXX implement when SMP comes */
528 return 3;
530 env->regs[r1] &= 0xffffffff00000000ULL;
531 cc = 1;
532 break;
533 #if !defined(CONFIG_USER_ONLY)
534 case SIGP_RESTART:
535 qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
536 cpu_loop_exit(CPU(s390_env_get_cpu(env)));
537 break;
538 case SIGP_STOP:
539 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
540 cpu_loop_exit(CPU(s390_env_get_cpu(env)));
541 break;
542 #endif
543 default:
544 /* unknown sigp */
545 fprintf(stderr, "XXX unknown sigp: 0x%" PRIx64 "\n", order_code);
546 cc = SIGP_CC_NOT_OPERATIONAL;
549 return cc;
551 #endif
553 #ifndef CONFIG_USER_ONLY
554 void HELPER(xsch)(CPUS390XState *env, uint64_t r1)
556 S390CPU *cpu = s390_env_get_cpu(env);
557 qemu_mutex_lock_iothread();
558 ioinst_handle_xsch(cpu, r1);
559 qemu_mutex_unlock_iothread();
562 void HELPER(csch)(CPUS390XState *env, uint64_t r1)
564 S390CPU *cpu = s390_env_get_cpu(env);
565 qemu_mutex_lock_iothread();
566 ioinst_handle_csch(cpu, r1);
567 qemu_mutex_unlock_iothread();
570 void HELPER(hsch)(CPUS390XState *env, uint64_t r1)
572 S390CPU *cpu = s390_env_get_cpu(env);
573 qemu_mutex_lock_iothread();
574 ioinst_handle_hsch(cpu, r1);
575 qemu_mutex_unlock_iothread();
578 void HELPER(msch)(CPUS390XState *env, uint64_t r1, uint64_t inst)
580 S390CPU *cpu = s390_env_get_cpu(env);
581 qemu_mutex_lock_iothread();
582 ioinst_handle_msch(cpu, r1, inst >> 16);
583 qemu_mutex_unlock_iothread();
586 void HELPER(rchp)(CPUS390XState *env, uint64_t r1)
588 S390CPU *cpu = s390_env_get_cpu(env);
589 qemu_mutex_lock_iothread();
590 ioinst_handle_rchp(cpu, r1);
591 qemu_mutex_unlock_iothread();
594 void HELPER(rsch)(CPUS390XState *env, uint64_t r1)
596 S390CPU *cpu = s390_env_get_cpu(env);
597 qemu_mutex_lock_iothread();
598 ioinst_handle_rsch(cpu, r1);
599 qemu_mutex_unlock_iothread();
602 void HELPER(ssch)(CPUS390XState *env, uint64_t r1, uint64_t inst)
604 S390CPU *cpu = s390_env_get_cpu(env);
605 qemu_mutex_lock_iothread();
606 ioinst_handle_ssch(cpu, r1, inst >> 16);
607 qemu_mutex_unlock_iothread();
610 void HELPER(stsch)(CPUS390XState *env, uint64_t r1, uint64_t inst)
612 S390CPU *cpu = s390_env_get_cpu(env);
613 qemu_mutex_lock_iothread();
614 ioinst_handle_stsch(cpu, r1, inst >> 16);
615 qemu_mutex_unlock_iothread();
618 void HELPER(tsch)(CPUS390XState *env, uint64_t r1, uint64_t inst)
620 S390CPU *cpu = s390_env_get_cpu(env);
621 qemu_mutex_lock_iothread();
622 ioinst_handle_tsch(cpu, r1, inst >> 16);
623 qemu_mutex_unlock_iothread();
626 void HELPER(chsc)(CPUS390XState *env, uint64_t inst)
628 S390CPU *cpu = s390_env_get_cpu(env);
629 qemu_mutex_lock_iothread();
630 ioinst_handle_chsc(cpu, inst >> 16);
631 qemu_mutex_unlock_iothread();
633 #endif
635 #ifndef CONFIG_USER_ONLY
636 void HELPER(per_check_exception)(CPUS390XState *env)
638 CPUState *cs = CPU(s390_env_get_cpu(env));
640 if (env->per_perc_atmid) {
641 env->int_pgm_code = PGM_PER;
642 env->int_pgm_ilen = get_ilen(cpu_ldub_code(env, env->per_address));
644 cs->exception_index = EXCP_PGM;
645 cpu_loop_exit(cs);
649 void HELPER(per_branch)(CPUS390XState *env, uint64_t from, uint64_t to)
651 if ((env->cregs[9] & PER_CR9_EVENT_BRANCH)) {
652 if (!(env->cregs[9] & PER_CR9_CONTROL_BRANCH_ADDRESS)
653 || get_per_in_range(env, to)) {
654 env->per_address = from;
655 env->per_perc_atmid = PER_CODE_EVENT_BRANCH | get_per_atmid(env);
660 void HELPER(per_ifetch)(CPUS390XState *env, uint64_t addr)
662 if ((env->cregs[9] & PER_CR9_EVENT_IFETCH) && get_per_in_range(env, addr)) {
663 env->per_address = addr;
664 env->per_perc_atmid = PER_CODE_EVENT_IFETCH | get_per_atmid(env);
666 /* If the instruction has to be nullified, trigger the
667 exception immediately. */
668 if (env->cregs[9] & PER_CR9_EVENT_NULLIFICATION) {
669 CPUState *cs = CPU(s390_env_get_cpu(env));
671 env->per_perc_atmid |= PER_CODE_EVENT_NULLIFICATION;
672 env->int_pgm_code = PGM_PER;
673 env->int_pgm_ilen = get_ilen(cpu_ldub_code(env, addr));
675 cs->exception_index = EXCP_PGM;
676 cpu_loop_exit(cs);
680 #endif
682 /* The maximum bit defined at the moment is 129. */
683 #define MAX_STFL_WORDS 3
685 /* Canonicalize the current cpu's features into the 64-bit words required
686 by STFLE. Return the index-1 of the max word that is non-zero. */
687 static unsigned do_stfle(CPUS390XState *env, uint64_t words[MAX_STFL_WORDS])
689 S390CPU *cpu = s390_env_get_cpu(env);
690 const unsigned long *features = cpu->model->features;
691 unsigned max_bit = 0;
692 S390Feat feat;
694 memset(words, 0, sizeof(uint64_t) * MAX_STFL_WORDS);
696 if (test_bit(S390_FEAT_ZARCH, features)) {
697 /* z/Architecture is always active if around */
698 words[0] = 1ull << (63 - 2);
701 for (feat = find_first_bit(features, S390_FEAT_MAX);
702 feat < S390_FEAT_MAX;
703 feat = find_next_bit(features, S390_FEAT_MAX, feat + 1)) {
704 const S390FeatDef *def = s390_feat_def(feat);
705 if (def->type == S390_FEAT_TYPE_STFL) {
706 unsigned bit = def->bit;
707 if (bit > max_bit) {
708 max_bit = bit;
710 assert(bit / 64 < MAX_STFL_WORDS);
711 words[bit / 64] |= 1ULL << (63 - bit % 64);
715 return max_bit / 64;
718 void HELPER(stfl)(CPUS390XState *env)
720 uint64_t words[MAX_STFL_WORDS];
722 do_stfle(env, words);
723 cpu_stl_data(env, 200, words[0] >> 32);
726 uint32_t HELPER(stfle)(CPUS390XState *env, uint64_t addr)
728 uint64_t words[MAX_STFL_WORDS];
729 unsigned count_m1 = env->regs[0] & 0xff;
730 unsigned max_m1 = do_stfle(env, words);
731 unsigned i;
733 for (i = 0; i <= count_m1; ++i) {
734 cpu_stq_data(env, addr + 8 * i, words[i]);
737 env->regs[0] = deposit64(env->regs[0], 0, 8, max_m1);
738 return (count_m1 >= max_m1 ? 0 : 3);