]> git.proxmox.com Git - qemu.git/blame - target-s390x/translate.c
target-s390: Convert SPT, STPT
[qemu.git] / target-s390x / translate.c
CommitLineData
10ec5117
AG
1/*
2 * S/390 translation
3 *
4 * Copyright (c) 2009 Ulrich Hecht
e023e832 5 * Copyright (c) 2010 Alexander Graf
10ec5117
AG
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 19 */
e023e832 20
e023e832
AG
21/* #define DEBUG_INLINE_BRANCHES */
22#define S390X_DEBUG_DISAS
23/* #define S390X_DEBUG_DISAS_VERBOSE */
24
25#ifdef S390X_DEBUG_DISAS_VERBOSE
26# define LOG_DISAS(...) qemu_log(__VA_ARGS__)
27#else
28# define LOG_DISAS(...) do { } while (0)
29#endif
10ec5117
AG
30
31#include "cpu.h"
76cad711 32#include "disas/disas.h"
10ec5117 33#include "tcg-op.h"
1de7afc9 34#include "qemu/log.h"
58a9e35b 35#include "qemu/host-utils.h"
10ec5117 36
e023e832
AG
37/* global register indexes */
38static TCGv_ptr cpu_env;
39
022c62cb 40#include "exec/gen-icount.h"
3208afbe 41#include "helper.h"
e023e832 42#define GEN_HELPER 1
3208afbe 43#include "helper.h"
e023e832 44
ad044d09
RH
45
46/* Information that (most) every instruction needs to manipulate. */
e023e832 47typedef struct DisasContext DisasContext;
ad044d09
RH
48typedef struct DisasInsn DisasInsn;
49typedef struct DisasFields DisasFields;
50
e023e832 51struct DisasContext {
e023e832 52 struct TranslationBlock *tb;
ad044d09
RH
53 const DisasInsn *insn;
54 DisasFields *fields;
55 uint64_t pc, next_pc;
56 enum cc_op cc_op;
57 bool singlestep_enabled;
58 int is_jmp;
e023e832
AG
59};
60
3fde06f5
RH
61/* Information carried about a condition to be evaluated. */
62typedef struct {
63 TCGCond cond:8;
64 bool is_64;
65 bool g1;
66 bool g2;
67 union {
68 struct { TCGv_i64 a, b; } s64;
69 struct { TCGv_i32 a, b; } s32;
70 } u;
71} DisasCompare;
72
e023e832
AG
73#define DISAS_EXCP 4
74
75static void gen_op_calc_cc(DisasContext *s);
76
77#ifdef DEBUG_INLINE_BRANCHES
78static uint64_t inline_branch_hit[CC_OP_MAX];
79static uint64_t inline_branch_miss[CC_OP_MAX];
80#endif
81
82static inline void debug_insn(uint64_t insn)
83{
84 LOG_DISAS("insn: 0x%" PRIx64 "\n", insn);
85}
86
87static inline uint64_t pc_to_link_info(DisasContext *s, uint64_t pc)
88{
89 if (!(s->tb->flags & FLAG_MASK_64)) {
90 if (s->tb->flags & FLAG_MASK_32) {
91 return pc | 0x80000000;
92 }
93 }
94 return pc;
95}
96
a4e3ad19 97void cpu_dump_state(CPUS390XState *env, FILE *f, fprintf_function cpu_fprintf,
10ec5117
AG
98 int flags)
99{
100 int i;
e023e832 101
d885bdd4
RH
102 if (env->cc_op > 3) {
103 cpu_fprintf(f, "PSW=mask %016" PRIx64 " addr %016" PRIx64 " cc %15s\n",
104 env->psw.mask, env->psw.addr, cc_name(env->cc_op));
105 } else {
106 cpu_fprintf(f, "PSW=mask %016" PRIx64 " addr %016" PRIx64 " cc %02x\n",
107 env->psw.mask, env->psw.addr, env->cc_op);
108 }
109
10ec5117 110 for (i = 0; i < 16; i++) {
e023e832 111 cpu_fprintf(f, "R%02d=%016" PRIx64, i, env->regs[i]);
10ec5117
AG
112 if ((i % 4) == 3) {
113 cpu_fprintf(f, "\n");
114 } else {
115 cpu_fprintf(f, " ");
116 }
117 }
e023e832 118
10ec5117 119 for (i = 0; i < 16; i++) {
431253c2 120 cpu_fprintf(f, "F%02d=%016" PRIx64, i, env->fregs[i].ll);
10ec5117
AG
121 if ((i % 4) == 3) {
122 cpu_fprintf(f, "\n");
123 } else {
124 cpu_fprintf(f, " ");
125 }
126 }
e023e832 127
e023e832
AG
128#ifndef CONFIG_USER_ONLY
129 for (i = 0; i < 16; i++) {
130 cpu_fprintf(f, "C%02d=%016" PRIx64, i, env->cregs[i]);
131 if ((i % 4) == 3) {
132 cpu_fprintf(f, "\n");
133 } else {
134 cpu_fprintf(f, " ");
135 }
136 }
137#endif
138
e023e832
AG
139#ifdef DEBUG_INLINE_BRANCHES
140 for (i = 0; i < CC_OP_MAX; i++) {
141 cpu_fprintf(f, " %15s = %10ld\t%10ld\n", cc_name(i),
142 inline_branch_miss[i], inline_branch_hit[i]);
143 }
144#endif
d885bdd4
RH
145
146 cpu_fprintf(f, "\n");
10ec5117
AG
147}
148
e023e832
AG
149static TCGv_i64 psw_addr;
150static TCGv_i64 psw_mask;
151
152static TCGv_i32 cc_op;
153static TCGv_i64 cc_src;
154static TCGv_i64 cc_dst;
155static TCGv_i64 cc_vr;
156
431253c2 157static char cpu_reg_names[32][4];
e023e832 158static TCGv_i64 regs[16];
431253c2 159static TCGv_i64 fregs[16];
e023e832
AG
160
161static uint8_t gen_opc_cc_op[OPC_BUF_SIZE];
162
d5a43964
AG
163void s390x_translate_init(void)
164{
e023e832 165 int i;
e023e832
AG
166
167 cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
431253c2
RH
168 psw_addr = tcg_global_mem_new_i64(TCG_AREG0,
169 offsetof(CPUS390XState, psw.addr),
e023e832 170 "psw_addr");
431253c2
RH
171 psw_mask = tcg_global_mem_new_i64(TCG_AREG0,
172 offsetof(CPUS390XState, psw.mask),
e023e832
AG
173 "psw_mask");
174
a4e3ad19 175 cc_op = tcg_global_mem_new_i32(TCG_AREG0, offsetof(CPUS390XState, cc_op),
e023e832 176 "cc_op");
a4e3ad19 177 cc_src = tcg_global_mem_new_i64(TCG_AREG0, offsetof(CPUS390XState, cc_src),
e023e832 178 "cc_src");
a4e3ad19 179 cc_dst = tcg_global_mem_new_i64(TCG_AREG0, offsetof(CPUS390XState, cc_dst),
e023e832 180 "cc_dst");
a4e3ad19 181 cc_vr = tcg_global_mem_new_i64(TCG_AREG0, offsetof(CPUS390XState, cc_vr),
e023e832
AG
182 "cc_vr");
183
e023e832 184 for (i = 0; i < 16; i++) {
431253c2 185 snprintf(cpu_reg_names[i], sizeof(cpu_reg_names[0]), "r%d", i);
e023e832 186 regs[i] = tcg_global_mem_new(TCG_AREG0,
431253c2
RH
187 offsetof(CPUS390XState, regs[i]),
188 cpu_reg_names[i]);
189 }
190
191 for (i = 0; i < 16; i++) {
192 snprintf(cpu_reg_names[i + 16], sizeof(cpu_reg_names[0]), "f%d", i);
193 fregs[i] = tcg_global_mem_new(TCG_AREG0,
194 offsetof(CPUS390XState, fregs[i].d),
195 cpu_reg_names[i + 16]);
e023e832 196 }
7e68da2a
RH
197
198 /* register helpers */
199#define GEN_HELPER 2
200#include "helper.h"
d5a43964
AG
201}
202
e023e832 203static inline TCGv_i64 load_reg(int reg)
10ec5117 204{
e023e832
AG
205 TCGv_i64 r = tcg_temp_new_i64();
206 tcg_gen_mov_i64(r, regs[reg]);
207 return r;
10ec5117
AG
208}
209
e023e832 210static inline TCGv_i64 load_freg(int reg)
10ec5117 211{
e023e832 212 TCGv_i64 r = tcg_temp_new_i64();
431253c2 213 tcg_gen_mov_i64(r, fregs[reg]);
e023e832 214 return r;
10ec5117
AG
215}
216
e023e832 217static inline TCGv_i32 load_freg32(int reg)
10ec5117 218{
e023e832 219 TCGv_i32 r = tcg_temp_new_i32();
431253c2
RH
220#if HOST_LONG_BITS == 32
221 tcg_gen_mov_i32(r, TCGV_HIGH(fregs[reg]));
222#else
223 tcg_gen_shri_i64(MAKE_TCGV_I64(GET_TCGV_I32(r)), fregs[reg], 32);
224#endif
e023e832
AG
225 return r;
226}
227
d764a8d1
RH
228static inline TCGv_i64 load_freg32_i64(int reg)
229{
230 TCGv_i64 r = tcg_temp_new_i64();
231 tcg_gen_shri_i64(r, fregs[reg], 32);
232 return r;
233}
234
e023e832
AG
235static inline TCGv_i32 load_reg32(int reg)
236{
237 TCGv_i32 r = tcg_temp_new_i32();
238 tcg_gen_trunc_i64_i32(r, regs[reg]);
239 return r;
240}
241
242static inline TCGv_i64 load_reg32_i64(int reg)
243{
244 TCGv_i64 r = tcg_temp_new_i64();
245 tcg_gen_ext32s_i64(r, regs[reg]);
246 return r;
247}
248
249static inline void store_reg(int reg, TCGv_i64 v)
250{
251 tcg_gen_mov_i64(regs[reg], v);
252}
253
254static inline void store_freg(int reg, TCGv_i64 v)
255{
431253c2 256 tcg_gen_mov_i64(fregs[reg], v);
e023e832
AG
257}
258
259static inline void store_reg32(int reg, TCGv_i32 v)
260{
431253c2 261 /* 32 bit register writes keep the upper half */
e023e832
AG
262#if HOST_LONG_BITS == 32
263 tcg_gen_mov_i32(TCGV_LOW(regs[reg]), v);
264#else
431253c2
RH
265 tcg_gen_deposit_i64(regs[reg], regs[reg],
266 MAKE_TCGV_I64(GET_TCGV_I32(v)), 0, 32);
e023e832
AG
267#endif
268}
269
270static inline void store_reg32_i64(int reg, TCGv_i64 v)
271{
272 /* 32 bit register writes keep the upper half */
e023e832 273 tcg_gen_deposit_i64(regs[reg], regs[reg], v, 0, 32);
e023e832
AG
274}
275
77f8d6c3
RH
276static inline void store_reg32h_i64(int reg, TCGv_i64 v)
277{
278 tcg_gen_deposit_i64(regs[reg], regs[reg], v, 32, 32);
279}
280
e023e832
AG
281static inline void store_freg32(int reg, TCGv_i32 v)
282{
431253c2
RH
283 /* 32 bit register writes keep the lower half */
284#if HOST_LONG_BITS == 32
285 tcg_gen_mov_i32(TCGV_HIGH(fregs[reg]), v);
286#else
287 tcg_gen_deposit_i64(fregs[reg], fregs[reg],
288 MAKE_TCGV_I64(GET_TCGV_I32(v)), 32, 32);
289#endif
e023e832
AG
290}
291
d764a8d1
RH
292static inline void store_freg32_i64(int reg, TCGv_i64 v)
293{
294 tcg_gen_deposit_i64(fregs[reg], fregs[reg], v, 32, 32);
295}
296
1ac5889f
RH
297static inline void return_low128(TCGv_i64 dest)
298{
299 tcg_gen_ld_i64(dest, cpu_env, offsetof(CPUS390XState, retxl));
300}
301
e023e832
AG
302static inline void update_psw_addr(DisasContext *s)
303{
304 /* psw.addr */
305 tcg_gen_movi_i64(psw_addr, s->pc);
306}
307
308static inline void potential_page_fault(DisasContext *s)
309{
310#ifndef CONFIG_USER_ONLY
311 update_psw_addr(s);
312 gen_op_calc_cc(s);
313#endif
314}
315
46ee3d84 316static inline uint64_t ld_code2(CPUS390XState *env, uint64_t pc)
e023e832 317{
46ee3d84 318 return (uint64_t)cpu_lduw_code(env, pc);
e023e832
AG
319}
320
46ee3d84 321static inline uint64_t ld_code4(CPUS390XState *env, uint64_t pc)
e023e832 322{
ad044d09 323 return (uint64_t)(uint32_t)cpu_ldl_code(env, pc);
e023e832
AG
324}
325
46ee3d84 326static inline uint64_t ld_code6(CPUS390XState *env, uint64_t pc)
e023e832 327{
ad044d09 328 return (ld_code2(env, pc) << 32) | ld_code4(env, pc + 2);
e023e832
AG
329}
330
331static inline int get_mem_index(DisasContext *s)
332{
333 switch (s->tb->flags & FLAG_MASK_ASC) {
334 case PSW_ASC_PRIMARY >> 32:
335 return 0;
336 case PSW_ASC_SECONDARY >> 32:
337 return 1;
338 case PSW_ASC_HOME >> 32:
339 return 2;
340 default:
341 tcg_abort();
342 break;
343 }
344}
345
d5a103cd 346static void gen_exception(int excp)
e023e832 347{
d5a103cd 348 TCGv_i32 tmp = tcg_const_i32(excp);
089f5c06 349 gen_helper_exception(cpu_env, tmp);
e023e832 350 tcg_temp_free_i32(tmp);
e023e832
AG
351}
352
d5a103cd 353static void gen_program_exception(DisasContext *s, int code)
e023e832
AG
354{
355 TCGv_i32 tmp;
356
d5a103cd 357 /* Remember what pgm exeption this was. */
e023e832 358 tmp = tcg_const_i32(code);
a4e3ad19 359 tcg_gen_st_i32(tmp, cpu_env, offsetof(CPUS390XState, int_pgm_code));
e023e832
AG
360 tcg_temp_free_i32(tmp);
361
d5a103cd
RH
362 tmp = tcg_const_i32(s->next_pc - s->pc);
363 tcg_gen_st_i32(tmp, cpu_env, offsetof(CPUS390XState, int_pgm_ilen));
e023e832
AG
364 tcg_temp_free_i32(tmp);
365
d5a103cd
RH
366 /* Advance past instruction. */
367 s->pc = s->next_pc;
e023e832
AG
368 update_psw_addr(s);
369
d5a103cd 370 /* Save off cc. */
e023e832
AG
371 gen_op_calc_cc(s);
372
d5a103cd
RH
373 /* Trigger exception. */
374 gen_exception(EXCP_PGM);
e023e832 375
d5a103cd 376 /* End TB here. */
e023e832
AG
377 s->is_jmp = DISAS_EXCP;
378}
379
d5a103cd 380static inline void gen_illegal_opcode(DisasContext *s)
e023e832 381{
d5a103cd 382 gen_program_exception(s, PGM_SPECIFICATION);
e023e832
AG
383}
384
d5a103cd 385static inline void check_privileged(DisasContext *s)
e023e832
AG
386{
387 if (s->tb->flags & (PSW_MASK_PSTATE >> 32)) {
d5a103cd 388 gen_program_exception(s, PGM_PRIVILEGED);
e023e832
AG
389 }
390}
391
e023e832
AG
392static TCGv_i64 get_address(DisasContext *s, int x2, int b2, int d2)
393{
394 TCGv_i64 tmp;
395
396 /* 31-bitify the immediate part; register contents are dealt with below */
397 if (!(s->tb->flags & FLAG_MASK_64)) {
398 d2 &= 0x7fffffffUL;
399 }
400
401 if (x2) {
402 if (d2) {
403 tmp = tcg_const_i64(d2);
404 tcg_gen_add_i64(tmp, tmp, regs[x2]);
405 } else {
406 tmp = load_reg(x2);
407 }
408 if (b2) {
409 tcg_gen_add_i64(tmp, tmp, regs[b2]);
410 }
411 } else if (b2) {
412 if (d2) {
413 tmp = tcg_const_i64(d2);
414 tcg_gen_add_i64(tmp, tmp, regs[b2]);
415 } else {
416 tmp = load_reg(b2);
417 }
418 } else {
419 tmp = tcg_const_i64(d2);
420 }
421
422 /* 31-bit mode mask if there are values loaded from registers */
423 if (!(s->tb->flags & FLAG_MASK_64) && (x2 || b2)) {
424 tcg_gen_andi_i64(tmp, tmp, 0x7fffffffUL);
425 }
426
427 return tmp;
428}
429
aa31bf60 430static inline void gen_op_movi_cc(DisasContext *s, uint32_t val)
e023e832
AG
431{
432 s->cc_op = CC_OP_CONST0 + val;
433}
434
435static void gen_op_update1_cc_i64(DisasContext *s, enum cc_op op, TCGv_i64 dst)
436{
437 tcg_gen_discard_i64(cc_src);
438 tcg_gen_mov_i64(cc_dst, dst);
439 tcg_gen_discard_i64(cc_vr);
440 s->cc_op = op;
441}
442
443static void gen_op_update1_cc_i32(DisasContext *s, enum cc_op op, TCGv_i32 dst)
444{
445 tcg_gen_discard_i64(cc_src);
446 tcg_gen_extu_i32_i64(cc_dst, dst);
447 tcg_gen_discard_i64(cc_vr);
448 s->cc_op = op;
449}
450
451static void gen_op_update2_cc_i64(DisasContext *s, enum cc_op op, TCGv_i64 src,
452 TCGv_i64 dst)
453{
454 tcg_gen_mov_i64(cc_src, src);
455 tcg_gen_mov_i64(cc_dst, dst);
456 tcg_gen_discard_i64(cc_vr);
457 s->cc_op = op;
458}
459
460static void gen_op_update2_cc_i32(DisasContext *s, enum cc_op op, TCGv_i32 src,
461 TCGv_i32 dst)
462{
463 tcg_gen_extu_i32_i64(cc_src, src);
464 tcg_gen_extu_i32_i64(cc_dst, dst);
465 tcg_gen_discard_i64(cc_vr);
466 s->cc_op = op;
467}
468
469static void gen_op_update3_cc_i64(DisasContext *s, enum cc_op op, TCGv_i64 src,
470 TCGv_i64 dst, TCGv_i64 vr)
471{
472 tcg_gen_mov_i64(cc_src, src);
473 tcg_gen_mov_i64(cc_dst, dst);
474 tcg_gen_mov_i64(cc_vr, vr);
475 s->cc_op = op;
476}
477
e023e832
AG
478static inline void set_cc_nz_u32(DisasContext *s, TCGv_i32 val)
479{
480 gen_op_update1_cc_i32(s, CC_OP_NZ, val);
481}
482
483static inline void set_cc_nz_u64(DisasContext *s, TCGv_i64 val)
484{
485 gen_op_update1_cc_i64(s, CC_OP_NZ, val);
486}
487
68c8bd93
RH
488static inline void gen_set_cc_nz_f32(DisasContext *s, TCGv_i64 val)
489{
490 gen_op_update1_cc_i64(s, CC_OP_NZ_F32, val);
491}
492
493static inline void gen_set_cc_nz_f64(DisasContext *s, TCGv_i64 val)
494{
495 gen_op_update1_cc_i64(s, CC_OP_NZ_F64, val);
496}
497
498static inline void gen_set_cc_nz_f128(DisasContext *s, TCGv_i64 vh, TCGv_i64 vl)
499{
500 gen_op_update2_cc_i64(s, CC_OP_NZ_F128, vh, vl);
501}
502
e023e832
AG
503static inline void cmp_32(DisasContext *s, TCGv_i32 v1, TCGv_i32 v2,
504 enum cc_op cond)
505{
506 gen_op_update2_cc_i32(s, cond, v1, v2);
507}
508
509static inline void cmp_64(DisasContext *s, TCGv_i64 v1, TCGv_i64 v2,
510 enum cc_op cond)
511{
512 gen_op_update2_cc_i64(s, cond, v1, v2);
513}
514
515static inline void cmp_s32(DisasContext *s, TCGv_i32 v1, TCGv_i32 v2)
516{
517 cmp_32(s, v1, v2, CC_OP_LTGT_32);
518}
519
520static inline void cmp_u32(DisasContext *s, TCGv_i32 v1, TCGv_i32 v2)
521{
522 cmp_32(s, v1, v2, CC_OP_LTUGTU_32);
523}
524
525static inline void cmp_s32c(DisasContext *s, TCGv_i32 v1, int32_t v2)
526{
527 /* XXX optimize for the constant? put it in s? */
528 TCGv_i32 tmp = tcg_const_i32(v2);
529 cmp_32(s, v1, tmp, CC_OP_LTGT_32);
530 tcg_temp_free_i32(tmp);
531}
532
533static inline void cmp_u32c(DisasContext *s, TCGv_i32 v1, uint32_t v2)
534{
535 TCGv_i32 tmp = tcg_const_i32(v2);
536 cmp_32(s, v1, tmp, CC_OP_LTUGTU_32);
537 tcg_temp_free_i32(tmp);
538}
539
540static inline void cmp_s64(DisasContext *s, TCGv_i64 v1, TCGv_i64 v2)
541{
542 cmp_64(s, v1, v2, CC_OP_LTGT_64);
543}
544
545static inline void cmp_u64(DisasContext *s, TCGv_i64 v1, TCGv_i64 v2)
546{
547 cmp_64(s, v1, v2, CC_OP_LTUGTU_64);
548}
549
550static inline void cmp_s64c(DisasContext *s, TCGv_i64 v1, int64_t v2)
551{
552 TCGv_i64 tmp = tcg_const_i64(v2);
553 cmp_s64(s, v1, tmp);
554 tcg_temp_free_i64(tmp);
555}
556
557static inline void cmp_u64c(DisasContext *s, TCGv_i64 v1, uint64_t v2)
558{
559 TCGv_i64 tmp = tcg_const_i64(v2);
560 cmp_u64(s, v1, tmp);
561 tcg_temp_free_i64(tmp);
562}
563
564static inline void set_cc_s32(DisasContext *s, TCGv_i32 val)
565{
566 gen_op_update1_cc_i32(s, CC_OP_LTGT0_32, val);
567}
568
569static inline void set_cc_s64(DisasContext *s, TCGv_i64 val)
570{
571 gen_op_update1_cc_i64(s, CC_OP_LTGT0_64, val);
572}
573
e023e832
AG
574/* CC value is in env->cc_op */
575static inline void set_cc_static(DisasContext *s)
576{
577 tcg_gen_discard_i64(cc_src);
578 tcg_gen_discard_i64(cc_dst);
579 tcg_gen_discard_i64(cc_vr);
580 s->cc_op = CC_OP_STATIC;
581}
582
583static inline void gen_op_set_cc_op(DisasContext *s)
584{
585 if (s->cc_op != CC_OP_DYNAMIC && s->cc_op != CC_OP_STATIC) {
586 tcg_gen_movi_i32(cc_op, s->cc_op);
587 }
588}
589
590static inline void gen_update_cc_op(DisasContext *s)
591{
592 gen_op_set_cc_op(s);
593}
594
595/* calculates cc into cc_op */
596static void gen_op_calc_cc(DisasContext *s)
597{
598 TCGv_i32 local_cc_op = tcg_const_i32(s->cc_op);
599 TCGv_i64 dummy = tcg_const_i64(0);
600
601 switch (s->cc_op) {
602 case CC_OP_CONST0:
603 case CC_OP_CONST1:
604 case CC_OP_CONST2:
605 case CC_OP_CONST3:
606 /* s->cc_op is the cc value */
607 tcg_gen_movi_i32(cc_op, s->cc_op - CC_OP_CONST0);
608 break;
609 case CC_OP_STATIC:
610 /* env->cc_op already is the cc value */
611 break;
612 case CC_OP_NZ:
613 case CC_OP_ABS_64:
614 case CC_OP_NABS_64:
615 case CC_OP_ABS_32:
616 case CC_OP_NABS_32:
617 case CC_OP_LTGT0_32:
618 case CC_OP_LTGT0_64:
619 case CC_OP_COMP_32:
620 case CC_OP_COMP_64:
621 case CC_OP_NZ_F32:
622 case CC_OP_NZ_F64:
102bf2c6 623 case CC_OP_FLOGR:
e023e832 624 /* 1 argument */
932385a3 625 gen_helper_calc_cc(cc_op, cpu_env, local_cc_op, dummy, cc_dst, dummy);
e023e832
AG
626 break;
627 case CC_OP_ICM:
628 case CC_OP_LTGT_32:
629 case CC_OP_LTGT_64:
630 case CC_OP_LTUGTU_32:
631 case CC_OP_LTUGTU_64:
632 case CC_OP_TM_32:
633 case CC_OP_TM_64:
cbe24bfa
RH
634 case CC_OP_SLA_32:
635 case CC_OP_SLA_64:
587626f8 636 case CC_OP_NZ_F128:
e023e832 637 /* 2 arguments */
932385a3 638 gen_helper_calc_cc(cc_op, cpu_env, local_cc_op, cc_src, cc_dst, dummy);
e023e832
AG
639 break;
640 case CC_OP_ADD_64:
641 case CC_OP_ADDU_64:
4e4bb438 642 case CC_OP_ADDC_64:
e023e832
AG
643 case CC_OP_SUB_64:
644 case CC_OP_SUBU_64:
4e4bb438 645 case CC_OP_SUBB_64:
e023e832
AG
646 case CC_OP_ADD_32:
647 case CC_OP_ADDU_32:
4e4bb438 648 case CC_OP_ADDC_32:
e023e832
AG
649 case CC_OP_SUB_32:
650 case CC_OP_SUBU_32:
4e4bb438 651 case CC_OP_SUBB_32:
e023e832 652 /* 3 arguments */
932385a3 653 gen_helper_calc_cc(cc_op, cpu_env, local_cc_op, cc_src, cc_dst, cc_vr);
e023e832
AG
654 break;
655 case CC_OP_DYNAMIC:
656 /* unknown operation - assume 3 arguments and cc_op in env */
932385a3 657 gen_helper_calc_cc(cc_op, cpu_env, cc_op, cc_src, cc_dst, cc_vr);
e023e832
AG
658 break;
659 default:
660 tcg_abort();
661 }
662
663 tcg_temp_free_i32(local_cc_op);
063eb0f3 664 tcg_temp_free_i64(dummy);
e023e832
AG
665
666 /* We now have cc in cc_op as constant */
667 set_cc_static(s);
668}
669
670static inline void decode_rr(DisasContext *s, uint64_t insn, int *r1, int *r2)
671{
672 debug_insn(insn);
673
674 *r1 = (insn >> 4) & 0xf;
675 *r2 = insn & 0xf;
676}
677
678static inline TCGv_i64 decode_rx(DisasContext *s, uint64_t insn, int *r1,
679 int *x2, int *b2, int *d2)
680{
681 debug_insn(insn);
682
683 *r1 = (insn >> 20) & 0xf;
684 *x2 = (insn >> 16) & 0xf;
685 *b2 = (insn >> 12) & 0xf;
686 *d2 = insn & 0xfff;
687
688 return get_address(s, *x2, *b2, *d2);
689}
690
691static inline void decode_rs(DisasContext *s, uint64_t insn, int *r1, int *r3,
692 int *b2, int *d2)
693{
694 debug_insn(insn);
695
696 *r1 = (insn >> 20) & 0xf;
697 /* aka m3 */
698 *r3 = (insn >> 16) & 0xf;
699 *b2 = (insn >> 12) & 0xf;
700 *d2 = insn & 0xfff;
701}
702
703static inline TCGv_i64 decode_si(DisasContext *s, uint64_t insn, int *i2,
704 int *b1, int *d1)
705{
706 debug_insn(insn);
707
708 *i2 = (insn >> 16) & 0xff;
709 *b1 = (insn >> 12) & 0xf;
710 *d1 = insn & 0xfff;
711
712 return get_address(s, 0, *b1, *d1);
713}
714
8ac33cdb 715static int use_goto_tb(DisasContext *s, uint64_t dest)
e023e832 716{
8ac33cdb
RH
717 /* NOTE: we handle the case where the TB spans two pages here */
718 return (((dest & TARGET_PAGE_MASK) == (s->tb->pc & TARGET_PAGE_MASK)
719 || (dest & TARGET_PAGE_MASK) == ((s->pc - 1) & TARGET_PAGE_MASK))
720 && !s->singlestep_enabled
721 && !(s->tb->cflags & CF_LAST_IO));
722}
e023e832 723
8ac33cdb
RH
724static inline void gen_goto_tb(DisasContext *s, int tb_num, target_ulong pc)
725{
e023e832
AG
726 gen_update_cc_op(s);
727
8ac33cdb 728 if (use_goto_tb(s, pc)) {
e023e832
AG
729 tcg_gen_goto_tb(tb_num);
730 tcg_gen_movi_i64(psw_addr, pc);
8ac33cdb 731 tcg_gen_exit_tb((tcg_target_long)s->tb + tb_num);
e023e832
AG
732 } else {
733 /* jump to another page: currently not optimized */
734 tcg_gen_movi_i64(psw_addr, pc);
735 tcg_gen_exit_tb(0);
736 }
737}
738
739static inline void account_noninline_branch(DisasContext *s, int cc_op)
740{
741#ifdef DEBUG_INLINE_BRANCHES
742 inline_branch_miss[cc_op]++;
743#endif
744}
745
3fde06f5 746static inline void account_inline_branch(DisasContext *s, int cc_op)
e023e832
AG
747{
748#ifdef DEBUG_INLINE_BRANCHES
3fde06f5 749 inline_branch_hit[cc_op]++;
e023e832
AG
750#endif
751}
752
3fde06f5
RH
753/* Table of mask values to comparison codes, given a comparison as input.
754 For a true comparison CC=3 will never be set, but we treat this
755 conservatively for possible use when CC=3 indicates overflow. */
756static const TCGCond ltgt_cond[16] = {
757 TCG_COND_NEVER, TCG_COND_NEVER, /* | | | x */
758 TCG_COND_GT, TCG_COND_NEVER, /* | | GT | x */
759 TCG_COND_LT, TCG_COND_NEVER, /* | LT | | x */
760 TCG_COND_NE, TCG_COND_NEVER, /* | LT | GT | x */
761 TCG_COND_EQ, TCG_COND_NEVER, /* EQ | | | x */
762 TCG_COND_GE, TCG_COND_NEVER, /* EQ | | GT | x */
763 TCG_COND_LE, TCG_COND_NEVER, /* EQ | LT | | x */
764 TCG_COND_ALWAYS, TCG_COND_ALWAYS, /* EQ | LT | GT | x */
765};
766
767/* Table of mask values to comparison codes, given a logic op as input.
768 For such, only CC=0 and CC=1 should be possible. */
769static const TCGCond nz_cond[16] = {
770 /* | | x | x */
771 TCG_COND_NEVER, TCG_COND_NEVER, TCG_COND_NEVER, TCG_COND_NEVER,
772 /* | NE | x | x */
773 TCG_COND_NE, TCG_COND_NE, TCG_COND_NE, TCG_COND_NE,
774 /* EQ | | x | x */
775 TCG_COND_EQ, TCG_COND_EQ, TCG_COND_EQ, TCG_COND_EQ,
776 /* EQ | NE | x | x */
777 TCG_COND_ALWAYS, TCG_COND_ALWAYS, TCG_COND_ALWAYS, TCG_COND_ALWAYS,
778};
779
780/* Interpret MASK in terms of S->CC_OP, and fill in C with all the
781 details required to generate a TCG comparison. */
782static void disas_jcc(DisasContext *s, DisasCompare *c, uint32_t mask)
e023e832 783{
3fde06f5
RH
784 TCGCond cond;
785 enum cc_op old_cc_op = s->cc_op;
e023e832 786
3fde06f5
RH
787 if (mask == 15 || mask == 0) {
788 c->cond = (mask ? TCG_COND_ALWAYS : TCG_COND_NEVER);
789 c->u.s32.a = cc_op;
790 c->u.s32.b = cc_op;
791 c->g1 = c->g2 = true;
792 c->is_64 = false;
793 return;
794 }
795
796 /* Find the TCG condition for the mask + cc op. */
797 switch (old_cc_op) {
e023e832 798 case CC_OP_LTGT0_32:
e023e832 799 case CC_OP_LTGT0_64:
e023e832 800 case CC_OP_LTGT_32:
e023e832 801 case CC_OP_LTGT_64:
3fde06f5
RH
802 cond = ltgt_cond[mask];
803 if (cond == TCG_COND_NEVER) {
e023e832
AG
804 goto do_dynamic;
805 }
3fde06f5 806 account_inline_branch(s, old_cc_op);
e023e832 807 break;
3fde06f5 808
e023e832 809 case CC_OP_LTUGTU_32:
e023e832 810 case CC_OP_LTUGTU_64:
3fde06f5
RH
811 cond = tcg_unsigned_cond(ltgt_cond[mask]);
812 if (cond == TCG_COND_NEVER) {
e023e832
AG
813 goto do_dynamic;
814 }
3fde06f5 815 account_inline_branch(s, old_cc_op);
e023e832 816 break;
3fde06f5 817
e023e832 818 case CC_OP_NZ:
3fde06f5
RH
819 cond = nz_cond[mask];
820 if (cond == TCG_COND_NEVER) {
e023e832
AG
821 goto do_dynamic;
822 }
3fde06f5 823 account_inline_branch(s, old_cc_op);
e023e832 824 break;
e023e832 825
3fde06f5 826 case CC_OP_TM_32:
e023e832 827 case CC_OP_TM_64:
e023e832 828 switch (mask) {
3fde06f5
RH
829 case 8:
830 cond = TCG_COND_EQ;
e023e832 831 break;
3fde06f5
RH
832 case 4 | 2 | 1:
833 cond = TCG_COND_NE;
e023e832
AG
834 break;
835 default:
836 goto do_dynamic;
837 }
3fde06f5 838 account_inline_branch(s, old_cc_op);
e023e832 839 break;
3fde06f5 840
e023e832
AG
841 case CC_OP_ICM:
842 switch (mask) {
3fde06f5
RH
843 case 8:
844 cond = TCG_COND_EQ;
e023e832 845 break;
3fde06f5
RH
846 case 4 | 2 | 1:
847 case 4 | 2:
848 cond = TCG_COND_NE;
e023e832
AG
849 break;
850 default:
851 goto do_dynamic;
852 }
3fde06f5 853 account_inline_branch(s, old_cc_op);
e023e832 854 break;
3fde06f5 855
102bf2c6
RH
856 case CC_OP_FLOGR:
857 switch (mask & 0xa) {
858 case 8: /* src == 0 -> no one bit found */
859 cond = TCG_COND_EQ;
860 break;
861 case 2: /* src != 0 -> one bit found */
862 cond = TCG_COND_NE;
863 break;
864 default:
865 goto do_dynamic;
866 }
867 account_inline_branch(s, old_cc_op);
868 break;
869
e023e832 870 default:
3fde06f5
RH
871 do_dynamic:
872 /* Calculate cc value. */
e023e832 873 gen_op_calc_cc(s);
3fde06f5 874 /* FALLTHRU */
e023e832 875
3fde06f5
RH
876 case CC_OP_STATIC:
877 /* Jump based on CC. We'll load up the real cond below;
878 the assignment here merely avoids a compiler warning. */
e023e832 879 account_noninline_branch(s, old_cc_op);
3fde06f5
RH
880 old_cc_op = CC_OP_STATIC;
881 cond = TCG_COND_NEVER;
882 break;
883 }
e023e832 884
3fde06f5
RH
885 /* Load up the arguments of the comparison. */
886 c->is_64 = true;
887 c->g1 = c->g2 = false;
888 switch (old_cc_op) {
889 case CC_OP_LTGT0_32:
890 c->is_64 = false;
891 c->u.s32.a = tcg_temp_new_i32();
892 tcg_gen_trunc_i64_i32(c->u.s32.a, cc_dst);
893 c->u.s32.b = tcg_const_i32(0);
894 break;
895 case CC_OP_LTGT_32:
896 case CC_OP_LTUGTU_32:
897 c->is_64 = false;
898 c->u.s32.a = tcg_temp_new_i32();
899 tcg_gen_trunc_i64_i32(c->u.s32.a, cc_src);
900 c->u.s32.b = tcg_temp_new_i32();
901 tcg_gen_trunc_i64_i32(c->u.s32.b, cc_dst);
902 break;
903
904 case CC_OP_LTGT0_64:
905 case CC_OP_NZ:
102bf2c6 906 case CC_OP_FLOGR:
3fde06f5
RH
907 c->u.s64.a = cc_dst;
908 c->u.s64.b = tcg_const_i64(0);
909 c->g1 = true;
910 break;
911 case CC_OP_LTGT_64:
912 case CC_OP_LTUGTU_64:
913 c->u.s64.a = cc_src;
914 c->u.s64.b = cc_dst;
915 c->g1 = c->g2 = true;
916 break;
917
918 case CC_OP_TM_32:
919 case CC_OP_TM_64:
58a9e35b 920 case CC_OP_ICM:
3fde06f5
RH
921 c->u.s64.a = tcg_temp_new_i64();
922 c->u.s64.b = tcg_const_i64(0);
923 tcg_gen_and_i64(c->u.s64.a, cc_src, cc_dst);
924 break;
925
926 case CC_OP_STATIC:
927 c->is_64 = false;
928 c->u.s32.a = cc_op;
929 c->g1 = true;
e023e832 930 switch (mask) {
e023e832 931 case 0x8 | 0x4 | 0x2: /* cc != 3 */
3fde06f5
RH
932 cond = TCG_COND_NE;
933 c->u.s32.b = tcg_const_i32(3);
e023e832
AG
934 break;
935 case 0x8 | 0x4 | 0x1: /* cc != 2 */
3fde06f5
RH
936 cond = TCG_COND_NE;
937 c->u.s32.b = tcg_const_i32(2);
e023e832
AG
938 break;
939 case 0x8 | 0x2 | 0x1: /* cc != 1 */
3fde06f5
RH
940 cond = TCG_COND_NE;
941 c->u.s32.b = tcg_const_i32(1);
e023e832 942 break;
3fde06f5
RH
943 case 0x8 | 0x2: /* cc == 0 || cc == 2 => (cc & 1) == 0 */
944 cond = TCG_COND_EQ;
945 c->g1 = false;
946 c->u.s32.a = tcg_temp_new_i32();
947 c->u.s32.b = tcg_const_i32(0);
948 tcg_gen_andi_i32(c->u.s32.a, cc_op, 1);
e023e832
AG
949 break;
950 case 0x8 | 0x4: /* cc < 2 */
3fde06f5
RH
951 cond = TCG_COND_LTU;
952 c->u.s32.b = tcg_const_i32(2);
e023e832
AG
953 break;
954 case 0x8: /* cc == 0 */
3fde06f5
RH
955 cond = TCG_COND_EQ;
956 c->u.s32.b = tcg_const_i32(0);
e023e832
AG
957 break;
958 case 0x4 | 0x2 | 0x1: /* cc != 0 */
3fde06f5
RH
959 cond = TCG_COND_NE;
960 c->u.s32.b = tcg_const_i32(0);
e023e832 961 break;
3fde06f5
RH
962 case 0x4 | 0x1: /* cc == 1 || cc == 3 => (cc & 1) != 0 */
963 cond = TCG_COND_NE;
964 c->g1 = false;
965 c->u.s32.a = tcg_temp_new_i32();
966 c->u.s32.b = tcg_const_i32(0);
967 tcg_gen_andi_i32(c->u.s32.a, cc_op, 1);
e023e832
AG
968 break;
969 case 0x4: /* cc == 1 */
3fde06f5
RH
970 cond = TCG_COND_EQ;
971 c->u.s32.b = tcg_const_i32(1);
e023e832
AG
972 break;
973 case 0x2 | 0x1: /* cc > 1 */
3fde06f5
RH
974 cond = TCG_COND_GTU;
975 c->u.s32.b = tcg_const_i32(1);
e023e832
AG
976 break;
977 case 0x2: /* cc == 2 */
3fde06f5
RH
978 cond = TCG_COND_EQ;
979 c->u.s32.b = tcg_const_i32(2);
e023e832
AG
980 break;
981 case 0x1: /* cc == 3 */
3fde06f5
RH
982 cond = TCG_COND_EQ;
983 c->u.s32.b = tcg_const_i32(3);
e023e832 984 break;
3fde06f5
RH
985 default:
986 /* CC is masked by something else: (8 >> cc) & mask. */
987 cond = TCG_COND_NE;
988 c->g1 = false;
989 c->u.s32.a = tcg_const_i32(8);
990 c->u.s32.b = tcg_const_i32(0);
991 tcg_gen_shr_i32(c->u.s32.a, c->u.s32.a, cc_op);
992 tcg_gen_andi_i32(c->u.s32.a, c->u.s32.a, mask);
e023e832
AG
993 break;
994 }
995 break;
3fde06f5
RH
996
997 default:
998 abort();
e023e832 999 }
3fde06f5
RH
1000 c->cond = cond;
1001}
1002
1003static void free_compare(DisasCompare *c)
1004{
1005 if (!c->g1) {
1006 if (c->is_64) {
1007 tcg_temp_free_i64(c->u.s64.a);
1008 } else {
1009 tcg_temp_free_i32(c->u.s32.a);
1010 }
1011 }
1012 if (!c->g2) {
1013 if (c->is_64) {
1014 tcg_temp_free_i64(c->u.s64.b);
1015 } else {
1016 tcg_temp_free_i32(c->u.s32.b);
1017 }
1018 }
1019}
1020
46ee3d84
BS
1021static void disas_b2(CPUS390XState *env, DisasContext *s, int op,
1022 uint32_t insn)
e023e832 1023{
4600c994 1024#ifndef CONFIG_USER_ONLY
e023e832 1025 TCGv_i64 tmp, tmp2, tmp3;
4600c994 1026 TCGv_i32 tmp32_1, tmp32_2;
e023e832 1027 int r1, r2;
e023e832 1028 int r3, d2, b2;
e023e832
AG
1029
1030 r1 = (insn >> 4) & 0xf;
1031 r2 = insn & 0xf;
1032
1033 LOG_DISAS("disas_b2: op 0x%x r1 %d r2 %d\n", op, r1, r2);
1034
1035 switch (op) {
e023e832
AG
1036 case 0x0a: /* SPKA D2(B2) [S] */
1037 /* Set PSW Key from Address */
d5a103cd 1038 check_privileged(s);
e023e832
AG
1039 decode_rs(s, insn, &r1, &r3, &b2, &d2);
1040 tmp = get_address(s, 0, b2, d2);
1041 tmp2 = tcg_temp_new_i64();
1042 tcg_gen_andi_i64(tmp2, psw_mask, ~PSW_MASK_KEY);
1043 tcg_gen_shli_i64(tmp, tmp, PSW_SHIFT_KEY - 4);
1044 tcg_gen_or_i64(psw_mask, tmp2, tmp);
1045 tcg_temp_free_i64(tmp2);
1046 tcg_temp_free_i64(tmp);
1047 break;
1048 case 0x0d: /* PTLB [S] */
1049 /* Purge TLB */
d5a103cd 1050 check_privileged(s);
19b0516f 1051 gen_helper_ptlb(cpu_env);
e023e832
AG
1052 break;
1053 case 0x10: /* SPX D2(B2) [S] */
1054 /* Set Prefix Register */
d5a103cd 1055 check_privileged(s);
e023e832
AG
1056 decode_rs(s, insn, &r1, &r3, &b2, &d2);
1057 tmp = get_address(s, 0, b2, d2);
1058 potential_page_fault(s);
089f5c06 1059 gen_helper_spx(cpu_env, tmp);
e023e832
AG
1060 tcg_temp_free_i64(tmp);
1061 break;
1062 case 0x11: /* STPX D2(B2) [S] */
1063 /* Store Prefix */
d5a103cd 1064 check_privileged(s);
e023e832
AG
1065 decode_rs(s, insn, &r1, &r3, &b2, &d2);
1066 tmp = get_address(s, 0, b2, d2);
1067 tmp2 = tcg_temp_new_i64();
a4e3ad19 1068 tcg_gen_ld_i64(tmp2, cpu_env, offsetof(CPUS390XState, psa));
e023e832
AG
1069 tcg_gen_qemu_st32(tmp2, tmp, get_mem_index(s));
1070 tcg_temp_free_i64(tmp);
1071 tcg_temp_free_i64(tmp2);
1072 break;
1073 case 0x12: /* STAP D2(B2) [S] */
1074 /* Store CPU Address */
d5a103cd 1075 check_privileged(s);
e023e832
AG
1076 decode_rs(s, insn, &r1, &r3, &b2, &d2);
1077 tmp = get_address(s, 0, b2, d2);
1078 tmp2 = tcg_temp_new_i64();
1079 tmp32_1 = tcg_temp_new_i32();
a4e3ad19 1080 tcg_gen_ld_i32(tmp32_1, cpu_env, offsetof(CPUS390XState, cpu_num));
e023e832
AG
1081 tcg_gen_extu_i32_i64(tmp2, tmp32_1);
1082 tcg_gen_qemu_st32(tmp2, tmp, get_mem_index(s));
1083 tcg_temp_free_i64(tmp);
1084 tcg_temp_free_i64(tmp2);
1085 tcg_temp_free_i32(tmp32_1);
1086 break;
1087 case 0x21: /* IPTE R1,R2 [RRE] */
1088 /* Invalidate PTE */
d5a103cd 1089 check_privileged(s);
e023e832
AG
1090 r1 = (insn >> 4) & 0xf;
1091 r2 = insn & 0xf;
1092 tmp = load_reg(r1);
1093 tmp2 = load_reg(r2);
19b0516f 1094 gen_helper_ipte(cpu_env, tmp, tmp2);
e023e832
AG
1095 tcg_temp_free_i64(tmp);
1096 tcg_temp_free_i64(tmp2);
1097 break;
1098 case 0x29: /* ISKE R1,R2 [RRE] */
1099 /* Insert Storage Key Extended */
d5a103cd 1100 check_privileged(s);
e023e832
AG
1101 r1 = (insn >> 4) & 0xf;
1102 r2 = insn & 0xf;
1103 tmp = load_reg(r2);
1104 tmp2 = tcg_temp_new_i64();
19b0516f 1105 gen_helper_iske(tmp2, cpu_env, tmp);
e023e832
AG
1106 store_reg(r1, tmp2);
1107 tcg_temp_free_i64(tmp);
1108 tcg_temp_free_i64(tmp2);
1109 break;
1110 case 0x2a: /* RRBE R1,R2 [RRE] */
1111 /* Set Storage Key Extended */
d5a103cd 1112 check_privileged(s);
e023e832
AG
1113 r1 = (insn >> 4) & 0xf;
1114 r2 = insn & 0xf;
1115 tmp32_1 = load_reg32(r1);
1116 tmp = load_reg(r2);
19b0516f 1117 gen_helper_rrbe(cc_op, cpu_env, tmp32_1, tmp);
e023e832
AG
1118 set_cc_static(s);
1119 tcg_temp_free_i32(tmp32_1);
1120 tcg_temp_free_i64(tmp);
1121 break;
1122 case 0x2b: /* SSKE R1,R2 [RRE] */
1123 /* Set Storage Key Extended */
d5a103cd 1124 check_privileged(s);
e023e832
AG
1125 r1 = (insn >> 4) & 0xf;
1126 r2 = insn & 0xf;
1127 tmp32_1 = load_reg32(r1);
1128 tmp = load_reg(r2);
19b0516f 1129 gen_helper_sske(cpu_env, tmp32_1, tmp);
e023e832
AG
1130 tcg_temp_free_i32(tmp32_1);
1131 tcg_temp_free_i64(tmp);
1132 break;
1133 case 0x34: /* STCH ? */
1134 /* Store Subchannel */
d5a103cd 1135 check_privileged(s);
e023e832
AG
1136 gen_op_movi_cc(s, 3);
1137 break;
1138 case 0x46: /* STURA R1,R2 [RRE] */
1139 /* Store Using Real Address */
d5a103cd 1140 check_privileged(s);
e023e832
AG
1141 r1 = (insn >> 4) & 0xf;
1142 r2 = insn & 0xf;
1143 tmp32_1 = load_reg32(r1);
1144 tmp = load_reg(r2);
1145 potential_page_fault(s);
19b0516f 1146 gen_helper_stura(cpu_env, tmp, tmp32_1);
e023e832
AG
1147 tcg_temp_free_i32(tmp32_1);
1148 tcg_temp_free_i64(tmp);
1149 break;
1150 case 0x50: /* CSP R1,R2 [RRE] */
1151 /* Compare And Swap And Purge */
d5a103cd 1152 check_privileged(s);
e023e832
AG
1153 r1 = (insn >> 4) & 0xf;
1154 r2 = insn & 0xf;
1155 tmp32_1 = tcg_const_i32(r1);
1156 tmp32_2 = tcg_const_i32(r2);
19b0516f 1157 gen_helper_csp(cc_op, cpu_env, tmp32_1, tmp32_2);
e023e832
AG
1158 set_cc_static(s);
1159 tcg_temp_free_i32(tmp32_1);
1160 tcg_temp_free_i32(tmp32_2);
1161 break;
1162 case 0x5f: /* CHSC ? */
1163 /* Channel Subsystem Call */
d5a103cd 1164 check_privileged(s);
e023e832
AG
1165 gen_op_movi_cc(s, 3);
1166 break;
1167 case 0x78: /* STCKE D2(B2) [S] */
1168 /* Store Clock Extended */
1169 decode_rs(s, insn, &r1, &r3, &b2, &d2);
1170 tmp = get_address(s, 0, b2, d2);
1171 potential_page_fault(s);
089f5c06 1172 gen_helper_stcke(cc_op, cpu_env, tmp);
e023e832
AG
1173 set_cc_static(s);
1174 tcg_temp_free_i64(tmp);
1175 break;
1176 case 0x79: /* SACF D2(B2) [S] */
afd43fec 1177 /* Set Address Space Control Fast */
d5a103cd 1178 check_privileged(s);
e023e832
AG
1179 decode_rs(s, insn, &r1, &r3, &b2, &d2);
1180 tmp = get_address(s, 0, b2, d2);
1181 potential_page_fault(s);
932385a3 1182 gen_helper_sacf(cpu_env, tmp);
e023e832
AG
1183 tcg_temp_free_i64(tmp);
1184 /* addressing mode has changed, so end the block */
d5a103cd 1185 s->pc = s->next_pc;
e023e832 1186 update_psw_addr(s);
afd43fec 1187 s->is_jmp = DISAS_JUMP;
e023e832
AG
1188 break;
1189 case 0x7d: /* STSI D2,(B2) [S] */
d5a103cd 1190 check_privileged(s);
e023e832
AG
1191 decode_rs(s, insn, &r1, &r3, &b2, &d2);
1192 tmp = get_address(s, 0, b2, d2);
1193 tmp32_1 = load_reg32(0);
1194 tmp32_2 = load_reg32(1);
1195 potential_page_fault(s);
089f5c06 1196 gen_helper_stsi(cc_op, cpu_env, tmp, tmp32_1, tmp32_2);
e023e832
AG
1197 set_cc_static(s);
1198 tcg_temp_free_i64(tmp);
1199 tcg_temp_free_i32(tmp32_1);
1200 tcg_temp_free_i32(tmp32_2);
1201 break;
e023e832
AG
1202 case 0xb1: /* STFL D2(B2) [S] */
1203 /* Store Facility List (CPU features) at 200 */
d5a103cd 1204 check_privileged(s);
e023e832
AG
1205 tmp2 = tcg_const_i64(0xc0000000);
1206 tmp = tcg_const_i64(200);
1207 tcg_gen_qemu_st32(tmp2, tmp, get_mem_index(s));
1208 tcg_temp_free_i64(tmp2);
1209 tcg_temp_free_i64(tmp);
1210 break;
1211 case 0xb2: /* LPSWE D2(B2) [S] */
1212 /* Load PSW Extended */
d5a103cd 1213 check_privileged(s);
e023e832
AG
1214 decode_rs(s, insn, &r1, &r3, &b2, &d2);
1215 tmp = get_address(s, 0, b2, d2);
1216 tmp2 = tcg_temp_new_i64();
1217 tmp3 = tcg_temp_new_i64();
1218 tcg_gen_qemu_ld64(tmp2, tmp, get_mem_index(s));
1219 tcg_gen_addi_i64(tmp, tmp, 8);
1220 tcg_gen_qemu_ld64(tmp3, tmp, get_mem_index(s));
932385a3 1221 gen_helper_load_psw(cpu_env, tmp2, tmp3);
e023e832
AG
1222 /* we need to keep cc_op intact */
1223 s->is_jmp = DISAS_JUMP;
1224 tcg_temp_free_i64(tmp);
e32a1832
SW
1225 tcg_temp_free_i64(tmp2);
1226 tcg_temp_free_i64(tmp3);
e023e832
AG
1227 break;
1228 case 0x20: /* SERVC R1,R2 [RRE] */
1229 /* SCLP Service call (PV hypercall) */
d5a103cd 1230 check_privileged(s);
e023e832
AG
1231 potential_page_fault(s);
1232 tmp32_1 = load_reg32(r2);
1233 tmp = load_reg(r1);
089f5c06 1234 gen_helper_servc(cc_op, cpu_env, tmp32_1, tmp);
e023e832
AG
1235 set_cc_static(s);
1236 tcg_temp_free_i32(tmp32_1);
1237 tcg_temp_free_i64(tmp);
1238 break;
e023e832 1239 default:
4600c994 1240#endif
e023e832 1241 LOG_DISAS("illegal b2 operation 0x%x\n", op);
d5a103cd 1242 gen_illegal_opcode(s);
4600c994 1243#ifndef CONFIG_USER_ONLY
e023e832
AG
1244 break;
1245 }
4600c994 1246#endif
e023e832
AG
1247}
1248
46ee3d84 1249static void disas_s390_insn(CPUS390XState *env, DisasContext *s)
e023e832 1250{
e023e832
AG
1251 unsigned char opc;
1252 uint64_t insn;
8379bfdb 1253 int op;
e023e832 1254
46ee3d84 1255 opc = cpu_ldub_code(env, s->pc);
e023e832
AG
1256 LOG_DISAS("opc 0x%x\n", opc);
1257
e023e832 1258 switch (opc) {
e023e832 1259 case 0xb2:
46ee3d84 1260 insn = ld_code4(env, s->pc);
e023e832 1261 op = (insn >> 16) & 0xff;
ea20490f 1262 disas_b2(env, s, op, insn);
e023e832 1263 break;
e023e832 1264 default:
71547a3b 1265 qemu_log_mask(LOG_UNIMP, "unimplemented opcode 0x%x\n", opc);
d5a103cd 1266 gen_illegal_opcode(s);
e023e832
AG
1267 break;
1268 }
ad044d09
RH
1269}
1270
1271/* ====================================================================== */
1272/* Define the insn format enumeration. */
1273#define F0(N) FMT_##N,
1274#define F1(N, X1) F0(N)
1275#define F2(N, X1, X2) F0(N)
1276#define F3(N, X1, X2, X3) F0(N)
1277#define F4(N, X1, X2, X3, X4) F0(N)
1278#define F5(N, X1, X2, X3, X4, X5) F0(N)
1279
1280typedef enum {
1281#include "insn-format.def"
1282} DisasFormat;
1283
1284#undef F0
1285#undef F1
1286#undef F2
1287#undef F3
1288#undef F4
1289#undef F5
1290
1291/* Define a structure to hold the decoded fields. We'll store each inside
1292 an array indexed by an enum. In order to conserve memory, we'll arrange
1293 for fields that do not exist at the same time to overlap, thus the "C"
1294 for compact. For checking purposes there is an "O" for original index
1295 as well that will be applied to availability bitmaps. */
1296
1297enum DisasFieldIndexO {
1298 FLD_O_r1,
1299 FLD_O_r2,
1300 FLD_O_r3,
1301 FLD_O_m1,
1302 FLD_O_m3,
1303 FLD_O_m4,
1304 FLD_O_b1,
1305 FLD_O_b2,
1306 FLD_O_b4,
1307 FLD_O_d1,
1308 FLD_O_d2,
1309 FLD_O_d4,
1310 FLD_O_x2,
1311 FLD_O_l1,
1312 FLD_O_l2,
1313 FLD_O_i1,
1314 FLD_O_i2,
1315 FLD_O_i3,
1316 FLD_O_i4,
1317 FLD_O_i5
1318};
1319
1320enum DisasFieldIndexC {
1321 FLD_C_r1 = 0,
1322 FLD_C_m1 = 0,
1323 FLD_C_b1 = 0,
1324 FLD_C_i1 = 0,
1325
1326 FLD_C_r2 = 1,
1327 FLD_C_b2 = 1,
1328 FLD_C_i2 = 1,
1329
1330 FLD_C_r3 = 2,
1331 FLD_C_m3 = 2,
1332 FLD_C_i3 = 2,
1333
1334 FLD_C_m4 = 3,
1335 FLD_C_b4 = 3,
1336 FLD_C_i4 = 3,
1337 FLD_C_l1 = 3,
1338
1339 FLD_C_i5 = 4,
1340 FLD_C_d1 = 4,
1341
1342 FLD_C_d2 = 5,
1343
1344 FLD_C_d4 = 6,
1345 FLD_C_x2 = 6,
1346 FLD_C_l2 = 6,
1347
1348 NUM_C_FIELD = 7
1349};
1350
1351struct DisasFields {
1352 unsigned op:8;
1353 unsigned op2:8;
1354 unsigned presentC:16;
1355 unsigned int presentO;
1356 int c[NUM_C_FIELD];
1357};
1358
1359/* This is the way fields are to be accessed out of DisasFields. */
1360#define have_field(S, F) have_field1((S), FLD_O_##F)
1361#define get_field(S, F) get_field1((S), FLD_O_##F, FLD_C_##F)
1362
1363static bool have_field1(const DisasFields *f, enum DisasFieldIndexO c)
1364{
1365 return (f->presentO >> c) & 1;
1366}
1367
1368static int get_field1(const DisasFields *f, enum DisasFieldIndexO o,
1369 enum DisasFieldIndexC c)
1370{
1371 assert(have_field1(f, o));
1372 return f->c[c];
1373}
1374
1375/* Describe the layout of each field in each format. */
1376typedef struct DisasField {
1377 unsigned int beg:8;
1378 unsigned int size:8;
1379 unsigned int type:2;
1380 unsigned int indexC:6;
1381 enum DisasFieldIndexO indexO:8;
1382} DisasField;
1383
1384typedef struct DisasFormatInfo {
1385 DisasField op[NUM_C_FIELD];
1386} DisasFormatInfo;
1387
1388#define R(N, B) { B, 4, 0, FLD_C_r##N, FLD_O_r##N }
1389#define M(N, B) { B, 4, 0, FLD_C_m##N, FLD_O_m##N }
1390#define BD(N, BB, BD) { BB, 4, 0, FLD_C_b##N, FLD_O_b##N }, \
1391 { BD, 12, 0, FLD_C_d##N, FLD_O_d##N }
1392#define BXD(N) { 16, 4, 0, FLD_C_b##N, FLD_O_b##N }, \
1393 { 12, 4, 0, FLD_C_x##N, FLD_O_x##N }, \
1394 { 20, 12, 0, FLD_C_d##N, FLD_O_d##N }
1395#define BDL(N) { 16, 4, 0, FLD_C_b##N, FLD_O_b##N }, \
1396 { 20, 20, 2, FLD_C_d##N, FLD_O_d##N }
1397#define BXDL(N) { 16, 4, 0, FLD_C_b##N, FLD_O_b##N }, \
1398 { 12, 4, 0, FLD_C_x##N, FLD_O_x##N }, \
1399 { 20, 20, 2, FLD_C_d##N, FLD_O_d##N }
1400#define I(N, B, S) { B, S, 1, FLD_C_i##N, FLD_O_i##N }
1401#define L(N, B, S) { B, S, 0, FLD_C_l##N, FLD_O_l##N }
1402
1403#define F0(N) { { } },
1404#define F1(N, X1) { { X1 } },
1405#define F2(N, X1, X2) { { X1, X2 } },
1406#define F3(N, X1, X2, X3) { { X1, X2, X3 } },
1407#define F4(N, X1, X2, X3, X4) { { X1, X2, X3, X4 } },
1408#define F5(N, X1, X2, X3, X4, X5) { { X1, X2, X3, X4, X5 } },
1409
1410static const DisasFormatInfo format_info[] = {
1411#include "insn-format.def"
1412};
1413
1414#undef F0
1415#undef F1
1416#undef F2
1417#undef F3
1418#undef F4
1419#undef F5
1420#undef R
1421#undef M
1422#undef BD
1423#undef BXD
1424#undef BDL
1425#undef BXDL
1426#undef I
1427#undef L
1428
1429/* Generally, we'll extract operands into this structures, operate upon
1430 them, and store them back. See the "in1", "in2", "prep", "wout" sets
1431 of routines below for more details. */
1432typedef struct {
1433 bool g_out, g_out2, g_in1, g_in2;
1434 TCGv_i64 out, out2, in1, in2;
1435 TCGv_i64 addr1;
1436} DisasOps;
1437
1438/* Return values from translate_one, indicating the state of the TB. */
1439typedef enum {
1440 /* Continue the TB. */
1441 NO_EXIT,
1442 /* We have emitted one or more goto_tb. No fixup required. */
1443 EXIT_GOTO_TB,
1444 /* We are not using a goto_tb (for whatever reason), but have updated
1445 the PC (for whatever reason), so there's no need to do it again on
1446 exiting the TB. */
1447 EXIT_PC_UPDATED,
1448 /* We are exiting the TB, but have neither emitted a goto_tb, nor
1449 updated the PC for the next instruction to be executed. */
1450 EXIT_PC_STALE,
1451 /* We are ending the TB with a noreturn function call, e.g. longjmp.
1452 No following code will be executed. */
1453 EXIT_NORETURN,
1454} ExitStatus;
1455
1456typedef enum DisasFacility {
1457 FAC_Z, /* zarch (default) */
1458 FAC_CASS, /* compare and swap and store */
1459 FAC_CASS2, /* compare and swap and store 2*/
1460 FAC_DFP, /* decimal floating point */
1461 FAC_DFPR, /* decimal floating point rounding */
1462 FAC_DO, /* distinct operands */
1463 FAC_EE, /* execute extensions */
1464 FAC_EI, /* extended immediate */
1465 FAC_FPE, /* floating point extension */
1466 FAC_FPSSH, /* floating point support sign handling */
1467 FAC_FPRGR, /* FPR-GR transfer */
1468 FAC_GIE, /* general instructions extension */
1469 FAC_HFP_MA, /* HFP multiply-and-add/subtract */
1470 FAC_HW, /* high-word */
1471 FAC_IEEEE_SIM, /* IEEE exception sumilation */
1472 FAC_LOC, /* load/store on condition */
1473 FAC_LD, /* long displacement */
1474 FAC_PC, /* population count */
1475 FAC_SCF, /* store clock fast */
1476 FAC_SFLE, /* store facility list extended */
1477} DisasFacility;
1478
1479struct DisasInsn {
1480 unsigned opc:16;
1481 DisasFormat fmt:6;
1482 DisasFacility fac:6;
1483
1484 const char *name;
1485
1486 void (*help_in1)(DisasContext *, DisasFields *, DisasOps *);
1487 void (*help_in2)(DisasContext *, DisasFields *, DisasOps *);
1488 void (*help_prep)(DisasContext *, DisasFields *, DisasOps *);
1489 void (*help_wout)(DisasContext *, DisasFields *, DisasOps *);
1490 void (*help_cout)(DisasContext *, DisasOps *);
1491 ExitStatus (*help_op)(DisasContext *, DisasOps *);
1492
1493 uint64_t data;
1494};
1495
8ac33cdb
RH
1496/* ====================================================================== */
1497/* Miscelaneous helpers, used by several operations. */
1498
cbe24bfa
RH
1499static void help_l2_shift(DisasContext *s, DisasFields *f,
1500 DisasOps *o, int mask)
1501{
1502 int b2 = get_field(f, b2);
1503 int d2 = get_field(f, d2);
1504
1505 if (b2 == 0) {
1506 o->in2 = tcg_const_i64(d2 & mask);
1507 } else {
1508 o->in2 = get_address(s, 0, b2, d2);
1509 tcg_gen_andi_i64(o->in2, o->in2, mask);
1510 }
1511}
1512
8ac33cdb
RH
1513static ExitStatus help_goto_direct(DisasContext *s, uint64_t dest)
1514{
1515 if (dest == s->next_pc) {
1516 return NO_EXIT;
1517 }
1518 if (use_goto_tb(s, dest)) {
1519 gen_update_cc_op(s);
1520 tcg_gen_goto_tb(0);
1521 tcg_gen_movi_i64(psw_addr, dest);
1522 tcg_gen_exit_tb((tcg_target_long)s->tb);
1523 return EXIT_GOTO_TB;
1524 } else {
1525 tcg_gen_movi_i64(psw_addr, dest);
1526 return EXIT_PC_UPDATED;
1527 }
1528}
1529
7233f2ed
RH
1530static ExitStatus help_branch(DisasContext *s, DisasCompare *c,
1531 bool is_imm, int imm, TCGv_i64 cdest)
1532{
1533 ExitStatus ret;
1534 uint64_t dest = s->pc + 2 * imm;
1535 int lab;
1536
1537 /* Take care of the special cases first. */
1538 if (c->cond == TCG_COND_NEVER) {
1539 ret = NO_EXIT;
1540 goto egress;
1541 }
1542 if (is_imm) {
1543 if (dest == s->next_pc) {
1544 /* Branch to next. */
1545 ret = NO_EXIT;
1546 goto egress;
1547 }
1548 if (c->cond == TCG_COND_ALWAYS) {
1549 ret = help_goto_direct(s, dest);
1550 goto egress;
1551 }
1552 } else {
1553 if (TCGV_IS_UNUSED_I64(cdest)) {
1554 /* E.g. bcr %r0 -> no branch. */
1555 ret = NO_EXIT;
1556 goto egress;
1557 }
1558 if (c->cond == TCG_COND_ALWAYS) {
1559 tcg_gen_mov_i64(psw_addr, cdest);
1560 ret = EXIT_PC_UPDATED;
1561 goto egress;
1562 }
1563 }
1564
1565 if (use_goto_tb(s, s->next_pc)) {
1566 if (is_imm && use_goto_tb(s, dest)) {
1567 /* Both exits can use goto_tb. */
1568 gen_update_cc_op(s);
1569
1570 lab = gen_new_label();
1571 if (c->is_64) {
1572 tcg_gen_brcond_i64(c->cond, c->u.s64.a, c->u.s64.b, lab);
1573 } else {
1574 tcg_gen_brcond_i32(c->cond, c->u.s32.a, c->u.s32.b, lab);
1575 }
1576
1577 /* Branch not taken. */
1578 tcg_gen_goto_tb(0);
1579 tcg_gen_movi_i64(psw_addr, s->next_pc);
1580 tcg_gen_exit_tb((tcg_target_long)s->tb + 0);
1581
1582 /* Branch taken. */
1583 gen_set_label(lab);
1584 tcg_gen_goto_tb(1);
1585 tcg_gen_movi_i64(psw_addr, dest);
1586 tcg_gen_exit_tb((tcg_target_long)s->tb + 1);
1587
1588 ret = EXIT_GOTO_TB;
1589 } else {
1590 /* Fallthru can use goto_tb, but taken branch cannot. */
1591 /* Store taken branch destination before the brcond. This
1592 avoids having to allocate a new local temp to hold it.
1593 We'll overwrite this in the not taken case anyway. */
1594 if (!is_imm) {
1595 tcg_gen_mov_i64(psw_addr, cdest);
1596 }
1597
1598 lab = gen_new_label();
1599 if (c->is_64) {
1600 tcg_gen_brcond_i64(c->cond, c->u.s64.a, c->u.s64.b, lab);
1601 } else {
1602 tcg_gen_brcond_i32(c->cond, c->u.s32.a, c->u.s32.b, lab);
1603 }
1604
1605 /* Branch not taken. */
1606 gen_update_cc_op(s);
1607 tcg_gen_goto_tb(0);
1608 tcg_gen_movi_i64(psw_addr, s->next_pc);
1609 tcg_gen_exit_tb((tcg_target_long)s->tb + 0);
1610
1611 gen_set_label(lab);
1612 if (is_imm) {
1613 tcg_gen_movi_i64(psw_addr, dest);
1614 }
1615 ret = EXIT_PC_UPDATED;
1616 }
1617 } else {
1618 /* Fallthru cannot use goto_tb. This by itself is vanishingly rare.
1619 Most commonly we're single-stepping or some other condition that
1620 disables all use of goto_tb. Just update the PC and exit. */
1621
1622 TCGv_i64 next = tcg_const_i64(s->next_pc);
1623 if (is_imm) {
1624 cdest = tcg_const_i64(dest);
1625 }
1626
1627 if (c->is_64) {
1628 tcg_gen_movcond_i64(c->cond, psw_addr, c->u.s64.a, c->u.s64.b,
1629 cdest, next);
1630 } else {
1631 TCGv_i32 t0 = tcg_temp_new_i32();
1632 TCGv_i64 t1 = tcg_temp_new_i64();
1633 TCGv_i64 z = tcg_const_i64(0);
1634 tcg_gen_setcond_i32(c->cond, t0, c->u.s32.a, c->u.s32.b);
1635 tcg_gen_extu_i32_i64(t1, t0);
1636 tcg_temp_free_i32(t0);
1637 tcg_gen_movcond_i64(TCG_COND_NE, psw_addr, t1, z, cdest, next);
1638 tcg_temp_free_i64(t1);
1639 tcg_temp_free_i64(z);
1640 }
1641
1642 if (is_imm) {
1643 tcg_temp_free_i64(cdest);
1644 }
1645 tcg_temp_free_i64(next);
1646
1647 ret = EXIT_PC_UPDATED;
1648 }
1649
1650 egress:
1651 free_compare(c);
1652 return ret;
1653}
1654
ad044d09
RH
1655/* ====================================================================== */
1656/* The operations. These perform the bulk of the work for any insn,
1657 usually after the operands have been loaded and output initialized. */
1658
b9bca3e5
RH
1659static ExitStatus op_abs(DisasContext *s, DisasOps *o)
1660{
1661 gen_helper_abs_i64(o->out, o->in2);
1662 return NO_EXIT;
1663}
1664
5d7fd045
RH
1665static ExitStatus op_absf32(DisasContext *s, DisasOps *o)
1666{
1667 tcg_gen_andi_i64(o->out, o->in2, 0x7fffffffull);
1668 return NO_EXIT;
1669}
1670
1671static ExitStatus op_absf64(DisasContext *s, DisasOps *o)
1672{
1673 tcg_gen_andi_i64(o->out, o->in2, 0x7fffffffffffffffull);
1674 return NO_EXIT;
1675}
1676
1677static ExitStatus op_absf128(DisasContext *s, DisasOps *o)
1678{
1679 tcg_gen_andi_i64(o->out, o->in1, 0x7fffffffffffffffull);
1680 tcg_gen_mov_i64(o->out2, o->in2);
1681 return NO_EXIT;
1682}
1683
ad044d09
RH
1684static ExitStatus op_add(DisasContext *s, DisasOps *o)
1685{
1686 tcg_gen_add_i64(o->out, o->in1, o->in2);
1687 return NO_EXIT;
1688}
1689
4e4bb438
RH
1690static ExitStatus op_addc(DisasContext *s, DisasOps *o)
1691{
1692 TCGv_i64 cc;
1693
1694 tcg_gen_add_i64(o->out, o->in1, o->in2);
1695
1696 /* XXX possible optimization point */
1697 gen_op_calc_cc(s);
1698 cc = tcg_temp_new_i64();
1699 tcg_gen_extu_i32_i64(cc, cc_op);
1700 tcg_gen_shri_i64(cc, cc, 1);
1701
1702 tcg_gen_add_i64(o->out, o->out, cc);
1703 tcg_temp_free_i64(cc);
1704 return NO_EXIT;
1705}
1706
587626f8
RH
1707static ExitStatus op_aeb(DisasContext *s, DisasOps *o)
1708{
1709 gen_helper_aeb(o->out, cpu_env, o->in1, o->in2);
1710 return NO_EXIT;
1711}
1712
1713static ExitStatus op_adb(DisasContext *s, DisasOps *o)
1714{
1715 gen_helper_adb(o->out, cpu_env, o->in1, o->in2);
1716 return NO_EXIT;
1717}
1718
1719static ExitStatus op_axb(DisasContext *s, DisasOps *o)
1720{
1721 gen_helper_axb(o->out, cpu_env, o->out, o->out2, o->in1, o->in2);
1722 return_low128(o->out2);
1723 return NO_EXIT;
1724}
1725
3bbfbd1f
RH
1726static ExitStatus op_and(DisasContext *s, DisasOps *o)
1727{
1728 tcg_gen_and_i64(o->out, o->in1, o->in2);
1729 return NO_EXIT;
1730}
1731
facfc864
RH
1732static ExitStatus op_andi(DisasContext *s, DisasOps *o)
1733{
1734 int shift = s->insn->data & 0xff;
1735 int size = s->insn->data >> 8;
1736 uint64_t mask = ((1ull << size) - 1) << shift;
1737
1738 assert(!o->g_in2);
1739 tcg_gen_shli_i64(o->in2, o->in2, shift);
1740 tcg_gen_ori_i64(o->in2, o->in2, ~mask);
1741 tcg_gen_and_i64(o->out, o->in1, o->in2);
1742
1743 /* Produce the CC from only the bits manipulated. */
1744 tcg_gen_andi_i64(cc_dst, o->out, mask);
1745 set_cc_nz_u64(s, cc_dst);
1746 return NO_EXIT;
1747}
1748
8ac33cdb
RH
1749static ExitStatus op_bas(DisasContext *s, DisasOps *o)
1750{
1751 tcg_gen_movi_i64(o->out, pc_to_link_info(s, s->next_pc));
1752 if (!TCGV_IS_UNUSED_I64(o->in2)) {
1753 tcg_gen_mov_i64(psw_addr, o->in2);
1754 return EXIT_PC_UPDATED;
1755 } else {
1756 return NO_EXIT;
1757 }
1758}
1759
1760static ExitStatus op_basi(DisasContext *s, DisasOps *o)
1761{
1762 tcg_gen_movi_i64(o->out, pc_to_link_info(s, s->next_pc));
1763 return help_goto_direct(s, s->pc + 2 * get_field(s->fields, i2));
1764}
1765
7233f2ed
RH
1766static ExitStatus op_bc(DisasContext *s, DisasOps *o)
1767{
1768 int m1 = get_field(s->fields, m1);
1769 bool is_imm = have_field(s->fields, i2);
1770 int imm = is_imm ? get_field(s->fields, i2) : 0;
1771 DisasCompare c;
1772
1773 disas_jcc(s, &c, m1);
1774 return help_branch(s, &c, is_imm, imm, o->in2);
1775}
1776
c61aad69
RH
1777static ExitStatus op_bct32(DisasContext *s, DisasOps *o)
1778{
1779 int r1 = get_field(s->fields, r1);
1780 bool is_imm = have_field(s->fields, i2);
1781 int imm = is_imm ? get_field(s->fields, i2) : 0;
1782 DisasCompare c;
1783 TCGv_i64 t;
1784
1785 c.cond = TCG_COND_NE;
1786 c.is_64 = false;
1787 c.g1 = false;
1788 c.g2 = false;
1789
1790 t = tcg_temp_new_i64();
1791 tcg_gen_subi_i64(t, regs[r1], 1);
1792 store_reg32_i64(r1, t);
1793 c.u.s32.a = tcg_temp_new_i32();
1794 c.u.s32.b = tcg_const_i32(0);
1795 tcg_gen_trunc_i64_i32(c.u.s32.a, t);
1796 tcg_temp_free_i64(t);
1797
1798 return help_branch(s, &c, is_imm, imm, o->in2);
1799}
1800
1801static ExitStatus op_bct64(DisasContext *s, DisasOps *o)
1802{
1803 int r1 = get_field(s->fields, r1);
1804 bool is_imm = have_field(s->fields, i2);
1805 int imm = is_imm ? get_field(s->fields, i2) : 0;
1806 DisasCompare c;
1807
1808 c.cond = TCG_COND_NE;
1809 c.is_64 = true;
1810 c.g1 = true;
1811 c.g2 = false;
1812
1813 tcg_gen_subi_i64(regs[r1], regs[r1], 1);
1814 c.u.s64.a = regs[r1];
1815 c.u.s64.b = tcg_const_i64(0);
1816
1817 return help_branch(s, &c, is_imm, imm, o->in2);
1818}
1819
587626f8
RH
1820static ExitStatus op_ceb(DisasContext *s, DisasOps *o)
1821{
1822 gen_helper_ceb(cc_op, cpu_env, o->in1, o->in2);
1823 set_cc_static(s);
1824 return NO_EXIT;
1825}
1826
1827static ExitStatus op_cdb(DisasContext *s, DisasOps *o)
1828{
1829 gen_helper_cdb(cc_op, cpu_env, o->in1, o->in2);
1830 set_cc_static(s);
1831 return NO_EXIT;
1832}
1833
1834static ExitStatus op_cxb(DisasContext *s, DisasOps *o)
1835{
1836 gen_helper_cxb(cc_op, cpu_env, o->out, o->out2, o->in1, o->in2);
1837 set_cc_static(s);
1838 return NO_EXIT;
1839}
1840
68c8bd93
RH
1841static ExitStatus op_cfeb(DisasContext *s, DisasOps *o)
1842{
1843 TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
1844 gen_helper_cfeb(o->out, cpu_env, o->in2, m3);
1845 tcg_temp_free_i32(m3);
1846 gen_set_cc_nz_f32(s, o->in2);
1847 return NO_EXIT;
1848}
1849
1850static ExitStatus op_cfdb(DisasContext *s, DisasOps *o)
1851{
1852 TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
1853 gen_helper_cfdb(o->out, cpu_env, o->in2, m3);
1854 tcg_temp_free_i32(m3);
1855 gen_set_cc_nz_f64(s, o->in2);
1856 return NO_EXIT;
1857}
1858
1859static ExitStatus op_cfxb(DisasContext *s, DisasOps *o)
1860{
1861 TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
1862 gen_helper_cfxb(o->out, cpu_env, o->in1, o->in2, m3);
1863 tcg_temp_free_i32(m3);
1864 gen_set_cc_nz_f128(s, o->in1, o->in2);
1865 return NO_EXIT;
1866}
1867
1868static ExitStatus op_cgeb(DisasContext *s, DisasOps *o)
1869{
1870 TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
1871 gen_helper_cgeb(o->out, cpu_env, o->in2, m3);
1872 tcg_temp_free_i32(m3);
1873 gen_set_cc_nz_f32(s, o->in2);
1874 return NO_EXIT;
1875}
1876
1877static ExitStatus op_cgdb(DisasContext *s, DisasOps *o)
1878{
1879 TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
1880 gen_helper_cgdb(o->out, cpu_env, o->in2, m3);
1881 tcg_temp_free_i32(m3);
1882 gen_set_cc_nz_f64(s, o->in2);
1883 return NO_EXIT;
1884}
1885
1886static ExitStatus op_cgxb(DisasContext *s, DisasOps *o)
1887{
1888 TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
1889 gen_helper_cgxb(o->out, cpu_env, o->in1, o->in2, m3);
1890 tcg_temp_free_i32(m3);
1891 gen_set_cc_nz_f128(s, o->in1, o->in2);
1892 return NO_EXIT;
1893}
1894
683bb9a8
RH
1895static ExitStatus op_cegb(DisasContext *s, DisasOps *o)
1896{
1897 TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
1898 gen_helper_cegb(o->out, cpu_env, o->in2, m3);
1899 tcg_temp_free_i32(m3);
1900 return NO_EXIT;
1901}
1902
1903static ExitStatus op_cdgb(DisasContext *s, DisasOps *o)
1904{
1905 TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
1906 gen_helper_cdgb(o->out, cpu_env, o->in2, m3);
1907 tcg_temp_free_i32(m3);
1908 return NO_EXIT;
1909}
1910
1911static ExitStatus op_cxgb(DisasContext *s, DisasOps *o)
1912{
1913 TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
1914 gen_helper_cxgb(o->out, cpu_env, o->in2, m3);
1915 tcg_temp_free_i32(m3);
1916 return_low128(o->out2);
1917 return NO_EXIT;
1918}
1919
374724f9
RH
1920static ExitStatus op_cksm(DisasContext *s, DisasOps *o)
1921{
1922 int r2 = get_field(s->fields, r2);
1923 TCGv_i64 len = tcg_temp_new_i64();
1924
1925 potential_page_fault(s);
1926 gen_helper_cksm(len, cpu_env, o->in1, o->in2, regs[r2 + 1]);
1927 set_cc_static(s);
1928 return_low128(o->out);
1929
1930 tcg_gen_add_i64(regs[r2], regs[r2], len);
1931 tcg_gen_sub_i64(regs[r2 + 1], regs[r2 + 1], len);
1932 tcg_temp_free_i64(len);
1933
1934 return NO_EXIT;
1935}
1936
4f7403d5
RH
1937static ExitStatus op_clc(DisasContext *s, DisasOps *o)
1938{
1939 int l = get_field(s->fields, l1);
1940 TCGv_i32 vl;
1941
1942 switch (l + 1) {
1943 case 1:
1944 tcg_gen_qemu_ld8u(cc_src, o->addr1, get_mem_index(s));
1945 tcg_gen_qemu_ld8u(cc_dst, o->in2, get_mem_index(s));
1946 break;
1947 case 2:
1948 tcg_gen_qemu_ld16u(cc_src, o->addr1, get_mem_index(s));
1949 tcg_gen_qemu_ld16u(cc_dst, o->in2, get_mem_index(s));
1950 break;
1951 case 4:
1952 tcg_gen_qemu_ld32u(cc_src, o->addr1, get_mem_index(s));
1953 tcg_gen_qemu_ld32u(cc_dst, o->in2, get_mem_index(s));
1954 break;
1955 case 8:
1956 tcg_gen_qemu_ld64(cc_src, o->addr1, get_mem_index(s));
1957 tcg_gen_qemu_ld64(cc_dst, o->in2, get_mem_index(s));
1958 break;
1959 default:
1960 potential_page_fault(s);
1961 vl = tcg_const_i32(l);
1962 gen_helper_clc(cc_op, cpu_env, vl, o->addr1, o->in2);
1963 tcg_temp_free_i32(vl);
1964 set_cc_static(s);
1965 return NO_EXIT;
1966 }
1967 gen_op_update2_cc_i64(s, CC_OP_LTUGTU_64, cc_src, cc_dst);
1968 return NO_EXIT;
1969}
1970
eb66e6a9
RH
1971static ExitStatus op_clcle(DisasContext *s, DisasOps *o)
1972{
1973 TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
1974 TCGv_i32 r3 = tcg_const_i32(get_field(s->fields, r3));
1975 potential_page_fault(s);
1976 gen_helper_clcle(cc_op, cpu_env, r1, o->in2, r3);
1977 tcg_temp_free_i32(r1);
1978 tcg_temp_free_i32(r3);
1979 set_cc_static(s);
1980 return NO_EXIT;
1981}
1982
32a44d58
RH
1983static ExitStatus op_clm(DisasContext *s, DisasOps *o)
1984{
1985 TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
1986 TCGv_i32 t1 = tcg_temp_new_i32();
1987 tcg_gen_trunc_i64_i32(t1, o->in1);
1988 potential_page_fault(s);
1989 gen_helper_clm(cc_op, cpu_env, t1, m3, o->in2);
1990 set_cc_static(s);
1991 tcg_temp_free_i32(t1);
1992 tcg_temp_free_i32(m3);
1993 return NO_EXIT;
1994}
1995
aa31bf60
RH
1996static ExitStatus op_clst(DisasContext *s, DisasOps *o)
1997{
1998 potential_page_fault(s);
1999 gen_helper_clst(o->in1, cpu_env, regs[0], o->in1, o->in2);
2000 set_cc_static(s);
2001 return_low128(o->in2);
2002 return NO_EXIT;
2003}
2004
f3de39c4
RH
2005static ExitStatus op_cs(DisasContext *s, DisasOps *o)
2006{
2007 int r3 = get_field(s->fields, r3);
2008 potential_page_fault(s);
2009 gen_helper_cs(o->out, cpu_env, o->in1, o->in2, regs[r3]);
2010 set_cc_static(s);
2011 return NO_EXIT;
2012}
2013
2014static ExitStatus op_csg(DisasContext *s, DisasOps *o)
2015{
2016 int r3 = get_field(s->fields, r3);
2017 potential_page_fault(s);
2018 gen_helper_csg(o->out, cpu_env, o->in1, o->in2, regs[r3]);
2019 set_cc_static(s);
2020 return NO_EXIT;
2021}
2022
2023static ExitStatus op_cds(DisasContext *s, DisasOps *o)
2024{
2025 int r3 = get_field(s->fields, r3);
2026 TCGv_i64 in3 = tcg_temp_new_i64();
2027 tcg_gen_deposit_i64(in3, regs[r3 + 1], regs[r3], 32, 32);
2028 potential_page_fault(s);
2029 gen_helper_csg(o->out, cpu_env, o->in1, o->in2, in3);
2030 tcg_temp_free_i64(in3);
2031 set_cc_static(s);
2032 return NO_EXIT;
2033}
2034
2035static ExitStatus op_cdsg(DisasContext *s, DisasOps *o)
2036{
2037 TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
2038 TCGv_i32 r3 = tcg_const_i32(get_field(s->fields, r3));
2039 potential_page_fault(s);
2040 /* XXX rewrite in tcg */
2041 gen_helper_cdsg(cc_op, cpu_env, r1, o->in2, r3);
2042 set_cc_static(s);
2043 return NO_EXIT;
2044}
2045
c49daa51
RH
2046static ExitStatus op_cvd(DisasContext *s, DisasOps *o)
2047{
2048 TCGv_i64 t1 = tcg_temp_new_i64();
2049 TCGv_i32 t2 = tcg_temp_new_i32();
2050 tcg_gen_trunc_i64_i32(t2, o->in1);
2051 gen_helper_cvd(t1, t2);
2052 tcg_temp_free_i32(t2);
2053 tcg_gen_qemu_st64(t1, o->in2, get_mem_index(s));
2054 tcg_temp_free_i64(t1);
2055 return NO_EXIT;
2056}
2057
972e35b9
RH
2058#ifndef CONFIG_USER_ONLY
2059static ExitStatus op_diag(DisasContext *s, DisasOps *o)
2060{
2061 TCGv_i32 tmp;
2062
2063 check_privileged(s);
2064 potential_page_fault(s);
2065
2066 /* We pretend the format is RX_a so that D2 is the field we want. */
2067 tmp = tcg_const_i32(get_field(s->fields, d2) & 0xfff);
2068 gen_helper_diag(regs[2], cpu_env, tmp, regs[2], regs[1]);
2069 tcg_temp_free_i32(tmp);
2070 return NO_EXIT;
2071}
2072#endif
2073
891452e5
RH
2074static ExitStatus op_divs32(DisasContext *s, DisasOps *o)
2075{
2076 gen_helper_divs32(o->out2, cpu_env, o->in1, o->in2);
2077 return_low128(o->out);
2078 return NO_EXIT;
2079}
2080
2081static ExitStatus op_divu32(DisasContext *s, DisasOps *o)
2082{
2083 gen_helper_divu32(o->out2, cpu_env, o->in1, o->in2);
2084 return_low128(o->out);
2085 return NO_EXIT;
2086}
2087
2088static ExitStatus op_divs64(DisasContext *s, DisasOps *o)
2089{
2090 gen_helper_divs64(o->out2, cpu_env, o->in1, o->in2);
2091 return_low128(o->out);
2092 return NO_EXIT;
2093}
2094
2095static ExitStatus op_divu64(DisasContext *s, DisasOps *o)
2096{
2097 gen_helper_divu64(o->out2, cpu_env, o->out, o->out2, o->in2);
2098 return_low128(o->out);
2099 return NO_EXIT;
2100}
2101
f08a5c31
RH
2102static ExitStatus op_deb(DisasContext *s, DisasOps *o)
2103{
2104 gen_helper_deb(o->out, cpu_env, o->in1, o->in2);
2105 return NO_EXIT;
2106}
2107
2108static ExitStatus op_ddb(DisasContext *s, DisasOps *o)
2109{
2110 gen_helper_ddb(o->out, cpu_env, o->in1, o->in2);
2111 return NO_EXIT;
2112}
2113
2114static ExitStatus op_dxb(DisasContext *s, DisasOps *o)
2115{
2116 gen_helper_dxb(o->out, cpu_env, o->out, o->out2, o->in1, o->in2);
2117 return_low128(o->out2);
2118 return NO_EXIT;
2119}
2120
d62a4c97
RH
2121static ExitStatus op_ear(DisasContext *s, DisasOps *o)
2122{
2123 int r2 = get_field(s->fields, r2);
2124 tcg_gen_ld32u_i64(o->out, cpu_env, offsetof(CPUS390XState, aregs[r2]));
2125 return NO_EXIT;
2126}
2127
ea20490f
RH
2128static ExitStatus op_efpc(DisasContext *s, DisasOps *o)
2129{
2130 tcg_gen_ld32u_i64(o->out, cpu_env, offsetof(CPUS390XState, fpc));
2131 return NO_EXIT;
2132}
2133
6e764e97
RH
2134static ExitStatus op_ex(DisasContext *s, DisasOps *o)
2135{
2136 /* ??? Perhaps a better way to implement EXECUTE is to set a bit in
2137 tb->flags, (ab)use the tb->cs_base field as the address of
2138 the template in memory, and grab 8 bits of tb->flags/cflags for
2139 the contents of the register. We would then recognize all this
2140 in gen_intermediate_code_internal, generating code for exactly
2141 one instruction. This new TB then gets executed normally.
2142
2143 On the other hand, this seems to be mostly used for modifying
2144 MVC inside of memcpy, which needs a helper call anyway. So
2145 perhaps this doesn't bear thinking about any further. */
2146
2147 TCGv_i64 tmp;
2148
2149 update_psw_addr(s);
2150 gen_op_calc_cc(s);
2151
2152 tmp = tcg_const_i64(s->next_pc);
2153 gen_helper_ex(cc_op, cpu_env, cc_op, o->in1, o->in2, tmp);
2154 tcg_temp_free_i64(tmp);
2155
2156 set_cc_static(s);
2157 return NO_EXIT;
2158}
2159
102bf2c6
RH
2160static ExitStatus op_flogr(DisasContext *s, DisasOps *o)
2161{
2162 /* We'll use the original input for cc computation, since we get to
2163 compare that against 0, which ought to be better than comparing
2164 the real output against 64. It also lets cc_dst be a convenient
2165 temporary during our computation. */
2166 gen_op_update1_cc_i64(s, CC_OP_FLOGR, o->in2);
2167
2168 /* R1 = IN ? CLZ(IN) : 64. */
2169 gen_helper_clz(o->out, o->in2);
2170
2171 /* R1+1 = IN & ~(found bit). Note that we may attempt to shift this
2172 value by 64, which is undefined. But since the shift is 64 iff the
2173 input is zero, we still get the correct result after and'ing. */
2174 tcg_gen_movi_i64(o->out2, 0x8000000000000000ull);
2175 tcg_gen_shr_i64(o->out2, o->out2, o->out);
2176 tcg_gen_andc_i64(o->out2, cc_dst, o->out2);
2177 return NO_EXIT;
2178}
2179
58a9e35b
RH
2180static ExitStatus op_icm(DisasContext *s, DisasOps *o)
2181{
2182 int m3 = get_field(s->fields, m3);
2183 int pos, len, base = s->insn->data;
2184 TCGv_i64 tmp = tcg_temp_new_i64();
2185 uint64_t ccm;
2186
2187 switch (m3) {
2188 case 0xf:
2189 /* Effectively a 32-bit load. */
2190 tcg_gen_qemu_ld32u(tmp, o->in2, get_mem_index(s));
2191 len = 32;
2192 goto one_insert;
2193
2194 case 0xc:
2195 case 0x6:
2196 case 0x3:
2197 /* Effectively a 16-bit load. */
2198 tcg_gen_qemu_ld16u(tmp, o->in2, get_mem_index(s));
2199 len = 16;
2200 goto one_insert;
2201
2202 case 0x8:
2203 case 0x4:
2204 case 0x2:
2205 case 0x1:
2206 /* Effectively an 8-bit load. */
2207 tcg_gen_qemu_ld8u(tmp, o->in2, get_mem_index(s));
2208 len = 8;
2209 goto one_insert;
2210
2211 one_insert:
2212 pos = base + ctz32(m3) * 8;
2213 tcg_gen_deposit_i64(o->out, o->out, tmp, pos, len);
2214 ccm = ((1ull << len) - 1) << pos;
2215 break;
2216
2217 default:
2218 /* This is going to be a sequence of loads and inserts. */
2219 pos = base + 32 - 8;
2220 ccm = 0;
2221 while (m3) {
2222 if (m3 & 0x8) {
2223 tcg_gen_qemu_ld8u(tmp, o->in2, get_mem_index(s));
2224 tcg_gen_addi_i64(o->in2, o->in2, 1);
2225 tcg_gen_deposit_i64(o->out, o->out, tmp, pos, 8);
2226 ccm |= 0xff << pos;
2227 }
2228 m3 = (m3 << 1) & 0xf;
2229 pos -= 8;
2230 }
2231 break;
2232 }
2233
2234 tcg_gen_movi_i64(tmp, ccm);
2235 gen_op_update2_cc_i64(s, CC_OP_ICM, tmp, o->out);
2236 tcg_temp_free_i64(tmp);
2237 return NO_EXIT;
2238}
2239
facfc864
RH
2240static ExitStatus op_insi(DisasContext *s, DisasOps *o)
2241{
2242 int shift = s->insn->data & 0xff;
2243 int size = s->insn->data >> 8;
2244 tcg_gen_deposit_i64(o->out, o->in1, o->in2, shift, size);
2245 return NO_EXIT;
2246}
2247
6e2704e7
RH
2248static ExitStatus op_ipm(DisasContext *s, DisasOps *o)
2249{
2250 TCGv_i64 t1;
2251
2252 gen_op_calc_cc(s);
2253 tcg_gen_andi_i64(o->out, o->out, ~0xff000000ull);
2254
2255 t1 = tcg_temp_new_i64();
2256 tcg_gen_shli_i64(t1, psw_mask, 20);
2257 tcg_gen_shri_i64(t1, t1, 36);
2258 tcg_gen_or_i64(o->out, o->out, t1);
2259
2260 tcg_gen_extu_i32_i64(t1, cc_op);
2261 tcg_gen_shli_i64(t1, t1, 28);
2262 tcg_gen_or_i64(o->out, o->out, t1);
2263 tcg_temp_free_i64(t1);
2264 return NO_EXIT;
2265}
2266
587626f8
RH
2267static ExitStatus op_ldeb(DisasContext *s, DisasOps *o)
2268{
2269 gen_helper_ldeb(o->out, cpu_env, o->in2);
2270 return NO_EXIT;
2271}
2272
2273static ExitStatus op_ledb(DisasContext *s, DisasOps *o)
2274{
2275 gen_helper_ledb(o->out, cpu_env, o->in2);
2276 return NO_EXIT;
2277}
2278
2279static ExitStatus op_ldxb(DisasContext *s, DisasOps *o)
2280{
2281 gen_helper_ldxb(o->out, cpu_env, o->in1, o->in2);
2282 return NO_EXIT;
2283}
2284
2285static ExitStatus op_lexb(DisasContext *s, DisasOps *o)
2286{
2287 gen_helper_lexb(o->out, cpu_env, o->in1, o->in2);
2288 return NO_EXIT;
2289}
2290
2291static ExitStatus op_lxdb(DisasContext *s, DisasOps *o)
2292{
2293 gen_helper_lxdb(o->out, cpu_env, o->in2);
2294 return_low128(o->out2);
2295 return NO_EXIT;
2296}
2297
2298static ExitStatus op_lxeb(DisasContext *s, DisasOps *o)
2299{
2300 gen_helper_lxeb(o->out, cpu_env, o->in2);
2301 return_low128(o->out2);
2302 return NO_EXIT;
2303}
2304
7691c23b
RH
2305static ExitStatus op_llgt(DisasContext *s, DisasOps *o)
2306{
2307 tcg_gen_andi_i64(o->out, o->in2, 0x7fffffff);
2308 return NO_EXIT;
2309}
2310
c698d876
RH
2311static ExitStatus op_ld8s(DisasContext *s, DisasOps *o)
2312{
2313 tcg_gen_qemu_ld8s(o->out, o->in2, get_mem_index(s));
2314 return NO_EXIT;
2315}
2316
2317static ExitStatus op_ld8u(DisasContext *s, DisasOps *o)
2318{
2319 tcg_gen_qemu_ld8u(o->out, o->in2, get_mem_index(s));
2320 return NO_EXIT;
2321}
2322
2323static ExitStatus op_ld16s(DisasContext *s, DisasOps *o)
2324{
2325 tcg_gen_qemu_ld16s(o->out, o->in2, get_mem_index(s));
2326 return NO_EXIT;
2327}
2328
2329static ExitStatus op_ld16u(DisasContext *s, DisasOps *o)
2330{
2331 tcg_gen_qemu_ld16u(o->out, o->in2, get_mem_index(s));
2332 return NO_EXIT;
2333}
2334
22c37a08
RH
2335static ExitStatus op_ld32s(DisasContext *s, DisasOps *o)
2336{
2337 tcg_gen_qemu_ld32s(o->out, o->in2, get_mem_index(s));
2338 return NO_EXIT;
2339}
2340
2341static ExitStatus op_ld32u(DisasContext *s, DisasOps *o)
2342{
2343 tcg_gen_qemu_ld32u(o->out, o->in2, get_mem_index(s));
2344 return NO_EXIT;
2345}
2346
2347static ExitStatus op_ld64(DisasContext *s, DisasOps *o)
2348{
2349 tcg_gen_qemu_ld64(o->out, o->in2, get_mem_index(s));
2350 return NO_EXIT;
2351}
2352
8b5ff571 2353#ifndef CONFIG_USER_ONLY
504488b8
RH
2354static ExitStatus op_lctl(DisasContext *s, DisasOps *o)
2355{
2356 TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
2357 TCGv_i32 r3 = tcg_const_i32(get_field(s->fields, r3));
2358 check_privileged(s);
2359 potential_page_fault(s);
2360 gen_helper_lctl(cpu_env, r1, o->in2, r3);
2361 tcg_temp_free_i32(r1);
2362 tcg_temp_free_i32(r3);
2363 return NO_EXIT;
2364}
2365
3e398cf9
RH
2366static ExitStatus op_lctlg(DisasContext *s, DisasOps *o)
2367{
2368 TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
2369 TCGv_i32 r3 = tcg_const_i32(get_field(s->fields, r3));
2370 check_privileged(s);
2371 potential_page_fault(s);
2372 gen_helper_lctlg(cpu_env, r1, o->in2, r3);
2373 tcg_temp_free_i32(r1);
2374 tcg_temp_free_i32(r3);
2375 return NO_EXIT;
2376}
d8fe4a9c
RH
2377static ExitStatus op_lra(DisasContext *s, DisasOps *o)
2378{
2379 check_privileged(s);
2380 potential_page_fault(s);
2381 gen_helper_lra(o->out, cpu_env, o->in2);
2382 set_cc_static(s);
2383 return NO_EXIT;
2384}
2385
8b5ff571
RH
2386static ExitStatus op_lpsw(DisasContext *s, DisasOps *o)
2387{
2388 TCGv_i64 t1, t2;
2389
2390 check_privileged(s);
2391
2392 t1 = tcg_temp_new_i64();
2393 t2 = tcg_temp_new_i64();
2394 tcg_gen_qemu_ld32u(t1, o->in2, get_mem_index(s));
2395 tcg_gen_addi_i64(o->in2, o->in2, 4);
2396 tcg_gen_qemu_ld32u(t2, o->in2, get_mem_index(s));
2397 /* Convert the 32-bit PSW_MASK into the 64-bit PSW_MASK. */
2398 tcg_gen_shli_i64(t1, t1, 32);
2399 gen_helper_load_psw(cpu_env, t1, t2);
2400 tcg_temp_free_i64(t1);
2401 tcg_temp_free_i64(t2);
2402 return EXIT_NORETURN;
2403}
2404#endif
2405
7df3e93a
RH
2406static ExitStatus op_lam(DisasContext *s, DisasOps *o)
2407{
2408 TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
2409 TCGv_i32 r3 = tcg_const_i32(get_field(s->fields, r3));
2410 potential_page_fault(s);
2411 gen_helper_lam(cpu_env, r1, o->in2, r3);
2412 tcg_temp_free_i32(r1);
2413 tcg_temp_free_i32(r3);
2414 return NO_EXIT;
2415}
2416
77f8d6c3
RH
2417static ExitStatus op_lm32(DisasContext *s, DisasOps *o)
2418{
2419 int r1 = get_field(s->fields, r1);
2420 int r3 = get_field(s->fields, r3);
2421 TCGv_i64 t = tcg_temp_new_i64();
2422 TCGv_i64 t4 = tcg_const_i64(4);
2423
2424 while (1) {
2425 tcg_gen_qemu_ld32u(t, o->in2, get_mem_index(s));
2426 store_reg32_i64(r1, t);
2427 if (r1 == r3) {
2428 break;
2429 }
2430 tcg_gen_add_i64(o->in2, o->in2, t4);
2431 r1 = (r1 + 1) & 15;
2432 }
2433
2434 tcg_temp_free_i64(t);
2435 tcg_temp_free_i64(t4);
2436 return NO_EXIT;
2437}
2438
2439static ExitStatus op_lmh(DisasContext *s, DisasOps *o)
2440{
2441 int r1 = get_field(s->fields, r1);
2442 int r3 = get_field(s->fields, r3);
2443 TCGv_i64 t = tcg_temp_new_i64();
2444 TCGv_i64 t4 = tcg_const_i64(4);
2445
2446 while (1) {
2447 tcg_gen_qemu_ld32u(t, o->in2, get_mem_index(s));
2448 store_reg32h_i64(r1, t);
2449 if (r1 == r3) {
2450 break;
2451 }
2452 tcg_gen_add_i64(o->in2, o->in2, t4);
2453 r1 = (r1 + 1) & 15;
2454 }
2455
2456 tcg_temp_free_i64(t);
2457 tcg_temp_free_i64(t4);
2458 return NO_EXIT;
2459}
2460
2461static ExitStatus op_lm64(DisasContext *s, DisasOps *o)
2462{
2463 int r1 = get_field(s->fields, r1);
2464 int r3 = get_field(s->fields, r3);
2465 TCGv_i64 t8 = tcg_const_i64(8);
2466
2467 while (1) {
2468 tcg_gen_qemu_ld64(regs[r1], o->in2, get_mem_index(s));
2469 if (r1 == r3) {
2470 break;
2471 }
2472 tcg_gen_add_i64(o->in2, o->in2, t8);
2473 r1 = (r1 + 1) & 15;
2474 }
2475
2476 tcg_temp_free_i64(t8);
2477 return NO_EXIT;
2478}
2479
22c37a08
RH
2480static ExitStatus op_mov2(DisasContext *s, DisasOps *o)
2481{
2482 o->out = o->in2;
2483 o->g_out = o->g_in2;
2484 TCGV_UNUSED_I64(o->in2);
2485 o->g_in2 = false;
2486 return NO_EXIT;
2487}
2488
d764a8d1
RH
2489static ExitStatus op_movx(DisasContext *s, DisasOps *o)
2490{
2491 o->out = o->in1;
2492 o->out2 = o->in2;
2493 o->g_out = o->g_in1;
2494 o->g_out2 = o->g_in2;
2495 TCGV_UNUSED_I64(o->in1);
2496 TCGV_UNUSED_I64(o->in2);
2497 o->g_in1 = o->g_in2 = false;
2498 return NO_EXIT;
2499}
2500
af9e5a04
RH
2501static ExitStatus op_mvc(DisasContext *s, DisasOps *o)
2502{
2503 TCGv_i32 l = tcg_const_i32(get_field(s->fields, l1));
2504 potential_page_fault(s);
2505 gen_helper_mvc(cpu_env, l, o->addr1, o->in2);
2506 tcg_temp_free_i32(l);
2507 return NO_EXIT;
2508}
2509
e1eaada9
RH
2510static ExitStatus op_mvcl(DisasContext *s, DisasOps *o)
2511{
2512 TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
2513 TCGv_i32 r2 = tcg_const_i32(get_field(s->fields, r2));
2514 potential_page_fault(s);
2515 gen_helper_mvcl(cc_op, cpu_env, r1, r2);
2516 tcg_temp_free_i32(r1);
2517 tcg_temp_free_i32(r2);
2518 set_cc_static(s);
2519 return NO_EXIT;
2520}
2521
eb66e6a9
RH
2522static ExitStatus op_mvcle(DisasContext *s, DisasOps *o)
2523{
2524 TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
2525 TCGv_i32 r3 = tcg_const_i32(get_field(s->fields, r3));
2526 potential_page_fault(s);
2527 gen_helper_mvcle(cc_op, cpu_env, r1, o->in2, r3);
2528 tcg_temp_free_i32(r1);
2529 tcg_temp_free_i32(r3);
2530 set_cc_static(s);
2531 return NO_EXIT;
2532}
2533
97c3ab61
RH
2534#ifndef CONFIG_USER_ONLY
2535static ExitStatus op_mvcp(DisasContext *s, DisasOps *o)
2536{
2537 int r1 = get_field(s->fields, l1);
2538 check_privileged(s);
2539 potential_page_fault(s);
2540 gen_helper_mvcp(cc_op, cpu_env, regs[r1], o->addr1, o->in2);
2541 set_cc_static(s);
2542 return NO_EXIT;
2543}
2544
2545static ExitStatus op_mvcs(DisasContext *s, DisasOps *o)
2546{
2547 int r1 = get_field(s->fields, l1);
2548 check_privileged(s);
2549 potential_page_fault(s);
2550 gen_helper_mvcs(cc_op, cpu_env, regs[r1], o->addr1, o->in2);
2551 set_cc_static(s);
2552 return NO_EXIT;
2553}
2554#endif
2555
ee6c38d5
RH
2556static ExitStatus op_mvpg(DisasContext *s, DisasOps *o)
2557{
2558 potential_page_fault(s);
2559 gen_helper_mvpg(cpu_env, regs[0], o->in1, o->in2);
2560 set_cc_static(s);
2561 return NO_EXIT;
2562}
2563
aa31bf60
RH
2564static ExitStatus op_mvst(DisasContext *s, DisasOps *o)
2565{
2566 potential_page_fault(s);
2567 gen_helper_mvst(o->in1, cpu_env, regs[0], o->in1, o->in2);
2568 set_cc_static(s);
2569 return_low128(o->in2);
2570 return NO_EXIT;
2571}
2572
d1c04a2b
RH
2573static ExitStatus op_mul(DisasContext *s, DisasOps *o)
2574{
2575 tcg_gen_mul_i64(o->out, o->in1, o->in2);
2576 return NO_EXIT;
2577}
2578
1ac5889f
RH
2579static ExitStatus op_mul128(DisasContext *s, DisasOps *o)
2580{
2581 gen_helper_mul128(o->out, cpu_env, o->in1, o->in2);
2582 return_low128(o->out2);
2583 return NO_EXIT;
2584}
2585
83b00736
RH
2586static ExitStatus op_meeb(DisasContext *s, DisasOps *o)
2587{
2588 gen_helper_meeb(o->out, cpu_env, o->in1, o->in2);
2589 return NO_EXIT;
2590}
2591
2592static ExitStatus op_mdeb(DisasContext *s, DisasOps *o)
2593{
2594 gen_helper_mdeb(o->out, cpu_env, o->in1, o->in2);
2595 return NO_EXIT;
2596}
2597
2598static ExitStatus op_mdb(DisasContext *s, DisasOps *o)
2599{
2600 gen_helper_mdb(o->out, cpu_env, o->in1, o->in2);
2601 return NO_EXIT;
2602}
2603
2604static ExitStatus op_mxb(DisasContext *s, DisasOps *o)
2605{
2606 gen_helper_mxb(o->out, cpu_env, o->out, o->out2, o->in1, o->in2);
2607 return_low128(o->out2);
2608 return NO_EXIT;
2609}
2610
2611static ExitStatus op_mxdb(DisasContext *s, DisasOps *o)
2612{
2613 gen_helper_mxdb(o->out, cpu_env, o->out, o->out2, o->in2);
2614 return_low128(o->out2);
2615 return NO_EXIT;
2616}
2617
722bfec3
RH
2618static ExitStatus op_maeb(DisasContext *s, DisasOps *o)
2619{
2620 TCGv_i64 r3 = load_freg32_i64(get_field(s->fields, r3));
2621 gen_helper_maeb(o->out, cpu_env, o->in1, o->in2, r3);
2622 tcg_temp_free_i64(r3);
2623 return NO_EXIT;
2624}
2625
2626static ExitStatus op_madb(DisasContext *s, DisasOps *o)
2627{
2628 int r3 = get_field(s->fields, r3);
2629 gen_helper_madb(o->out, cpu_env, o->in1, o->in2, fregs[r3]);
2630 return NO_EXIT;
2631}
2632
2633static ExitStatus op_mseb(DisasContext *s, DisasOps *o)
2634{
2635 TCGv_i64 r3 = load_freg32_i64(get_field(s->fields, r3));
2636 gen_helper_mseb(o->out, cpu_env, o->in1, o->in2, r3);
2637 tcg_temp_free_i64(r3);
2638 return NO_EXIT;
2639}
2640
2641static ExitStatus op_msdb(DisasContext *s, DisasOps *o)
2642{
2643 int r3 = get_field(s->fields, r3);
2644 gen_helper_msdb(o->out, cpu_env, o->in1, o->in2, fregs[r3]);
2645 return NO_EXIT;
2646}
2647
b9bca3e5
RH
2648static ExitStatus op_nabs(DisasContext *s, DisasOps *o)
2649{
2650 gen_helper_nabs_i64(o->out, o->in2);
2651 return NO_EXIT;
2652}
2653
5d7fd045
RH
2654static ExitStatus op_nabsf32(DisasContext *s, DisasOps *o)
2655{
2656 tcg_gen_ori_i64(o->out, o->in2, 0x80000000ull);
2657 return NO_EXIT;
2658}
2659
2660static ExitStatus op_nabsf64(DisasContext *s, DisasOps *o)
2661{
2662 tcg_gen_ori_i64(o->out, o->in2, 0x8000000000000000ull);
2663 return NO_EXIT;
2664}
2665
2666static ExitStatus op_nabsf128(DisasContext *s, DisasOps *o)
2667{
2668 tcg_gen_ori_i64(o->out, o->in1, 0x8000000000000000ull);
2669 tcg_gen_mov_i64(o->out2, o->in2);
2670 return NO_EXIT;
2671}
2672
0a949039
RH
2673static ExitStatus op_nc(DisasContext *s, DisasOps *o)
2674{
2675 TCGv_i32 l = tcg_const_i32(get_field(s->fields, l1));
2676 potential_page_fault(s);
2677 gen_helper_nc(cc_op, cpu_env, l, o->addr1, o->in2);
2678 tcg_temp_free_i32(l);
2679 set_cc_static(s);
2680 return NO_EXIT;
2681}
2682
b9bca3e5
RH
2683static ExitStatus op_neg(DisasContext *s, DisasOps *o)
2684{
2685 tcg_gen_neg_i64(o->out, o->in2);
2686 return NO_EXIT;
2687}
2688
5d7fd045
RH
2689static ExitStatus op_negf32(DisasContext *s, DisasOps *o)
2690{
2691 tcg_gen_xori_i64(o->out, o->in2, 0x80000000ull);
2692 return NO_EXIT;
2693}
2694
2695static ExitStatus op_negf64(DisasContext *s, DisasOps *o)
2696{
2697 tcg_gen_xori_i64(o->out, o->in2, 0x8000000000000000ull);
2698 return NO_EXIT;
2699}
2700
2701static ExitStatus op_negf128(DisasContext *s, DisasOps *o)
2702{
2703 tcg_gen_xori_i64(o->out, o->in1, 0x8000000000000000ull);
2704 tcg_gen_mov_i64(o->out2, o->in2);
2705 return NO_EXIT;
2706}
2707
0a949039
RH
2708static ExitStatus op_oc(DisasContext *s, DisasOps *o)
2709{
2710 TCGv_i32 l = tcg_const_i32(get_field(s->fields, l1));
2711 potential_page_fault(s);
2712 gen_helper_oc(cc_op, cpu_env, l, o->addr1, o->in2);
2713 tcg_temp_free_i32(l);
2714 set_cc_static(s);
2715 return NO_EXIT;
2716}
2717
3bbfbd1f
RH
2718static ExitStatus op_or(DisasContext *s, DisasOps *o)
2719{
2720 tcg_gen_or_i64(o->out, o->in1, o->in2);
2721 return NO_EXIT;
2722}
2723
facfc864
RH
2724static ExitStatus op_ori(DisasContext *s, DisasOps *o)
2725{
2726 int shift = s->insn->data & 0xff;
2727 int size = s->insn->data >> 8;
2728 uint64_t mask = ((1ull << size) - 1) << shift;
2729
2730 assert(!o->g_in2);
2731 tcg_gen_shli_i64(o->in2, o->in2, shift);
2732 tcg_gen_or_i64(o->out, o->in1, o->in2);
2733
2734 /* Produce the CC from only the bits manipulated. */
2735 tcg_gen_andi_i64(cc_dst, o->out, mask);
2736 set_cc_nz_u64(s, cc_dst);
2737 return NO_EXIT;
2738}
2739
d54f5865
RH
2740static ExitStatus op_rev16(DisasContext *s, DisasOps *o)
2741{
2742 tcg_gen_bswap16_i64(o->out, o->in2);
2743 return NO_EXIT;
2744}
2745
2746static ExitStatus op_rev32(DisasContext *s, DisasOps *o)
2747{
2748 tcg_gen_bswap32_i64(o->out, o->in2);
2749 return NO_EXIT;
2750}
2751
2752static ExitStatus op_rev64(DisasContext *s, DisasOps *o)
2753{
2754 tcg_gen_bswap64_i64(o->out, o->in2);
2755 return NO_EXIT;
2756}
2757
cbe24bfa
RH
2758static ExitStatus op_rll32(DisasContext *s, DisasOps *o)
2759{
2760 TCGv_i32 t1 = tcg_temp_new_i32();
2761 TCGv_i32 t2 = tcg_temp_new_i32();
2762 TCGv_i32 to = tcg_temp_new_i32();
2763 tcg_gen_trunc_i64_i32(t1, o->in1);
2764 tcg_gen_trunc_i64_i32(t2, o->in2);
2765 tcg_gen_rotl_i32(to, t1, t2);
2766 tcg_gen_extu_i32_i64(o->out, to);
2767 tcg_temp_free_i32(t1);
2768 tcg_temp_free_i32(t2);
2769 tcg_temp_free_i32(to);
2770 return NO_EXIT;
2771}
2772
2773static ExitStatus op_rll64(DisasContext *s, DisasOps *o)
2774{
2775 tcg_gen_rotl_i64(o->out, o->in1, o->in2);
2776 return NO_EXIT;
2777}
2778
d62a4c97
RH
2779static ExitStatus op_sar(DisasContext *s, DisasOps *o)
2780{
2781 int r1 = get_field(s->fields, r1);
2782 tcg_gen_st32_i64(o->in2, cpu_env, offsetof(CPUS390XState, aregs[r1]));
2783 return NO_EXIT;
2784}
2785
1a800a2d
RH
2786static ExitStatus op_seb(DisasContext *s, DisasOps *o)
2787{
2788 gen_helper_seb(o->out, cpu_env, o->in1, o->in2);
2789 return NO_EXIT;
2790}
2791
2792static ExitStatus op_sdb(DisasContext *s, DisasOps *o)
2793{
2794 gen_helper_sdb(o->out, cpu_env, o->in1, o->in2);
2795 return NO_EXIT;
2796}
2797
2798static ExitStatus op_sxb(DisasContext *s, DisasOps *o)
2799{
2800 gen_helper_sxb(o->out, cpu_env, o->out, o->out2, o->in1, o->in2);
2801 return_low128(o->out2);
2802 return NO_EXIT;
2803}
2804
16d7b2a4
RH
2805static ExitStatus op_sqeb(DisasContext *s, DisasOps *o)
2806{
2807 gen_helper_sqeb(o->out, cpu_env, o->in2);
2808 return NO_EXIT;
2809}
2810
2811static ExitStatus op_sqdb(DisasContext *s, DisasOps *o)
2812{
2813 gen_helper_sqdb(o->out, cpu_env, o->in2);
2814 return NO_EXIT;
2815}
2816
2817static ExitStatus op_sqxb(DisasContext *s, DisasOps *o)
2818{
2819 gen_helper_sqxb(o->out, cpu_env, o->in1, o->in2);
2820 return_low128(o->out2);
2821 return NO_EXIT;
2822}
2823
0c240015
RH
2824#ifndef CONFIG_USER_ONLY
2825static ExitStatus op_sigp(DisasContext *s, DisasOps *o)
2826{
2827 TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
2828 check_privileged(s);
2829 potential_page_fault(s);
2830 gen_helper_sigp(cc_op, cpu_env, o->in2, r1, o->in1);
2831 tcg_temp_free_i32(r1);
2832 return NO_EXIT;
2833}
2834#endif
2835
cbe24bfa
RH
2836static ExitStatus op_sla(DisasContext *s, DisasOps *o)
2837{
2838 uint64_t sign = 1ull << s->insn->data;
2839 enum cc_op cco = s->insn->data == 31 ? CC_OP_SLA_32 : CC_OP_SLA_64;
2840 gen_op_update2_cc_i64(s, cco, o->in1, o->in2);
2841 tcg_gen_shl_i64(o->out, o->in1, o->in2);
2842 /* The arithmetic left shift is curious in that it does not affect
2843 the sign bit. Copy that over from the source unchanged. */
2844 tcg_gen_andi_i64(o->out, o->out, ~sign);
2845 tcg_gen_andi_i64(o->in1, o->in1, sign);
2846 tcg_gen_or_i64(o->out, o->out, o->in1);
2847 return NO_EXIT;
2848}
2849
2850static ExitStatus op_sll(DisasContext *s, DisasOps *o)
2851{
2852 tcg_gen_shl_i64(o->out, o->in1, o->in2);
2853 return NO_EXIT;
2854}
2855
2856static ExitStatus op_sra(DisasContext *s, DisasOps *o)
2857{
2858 tcg_gen_sar_i64(o->out, o->in1, o->in2);
2859 return NO_EXIT;
2860}
2861
2862static ExitStatus op_srl(DisasContext *s, DisasOps *o)
2863{
2864 tcg_gen_shr_i64(o->out, o->in1, o->in2);
2865 return NO_EXIT;
2866}
2867
8379bfdb
RH
2868static ExitStatus op_sfpc(DisasContext *s, DisasOps *o)
2869{
2870 gen_helper_sfpc(cpu_env, o->in2);
2871 return NO_EXIT;
2872}
2873
7d30bb73
RH
2874#ifndef CONFIG_USER_ONLY
2875static ExitStatus op_ssm(DisasContext *s, DisasOps *o)
2876{
2877 check_privileged(s);
2878 tcg_gen_deposit_i64(psw_mask, psw_mask, o->in2, 56, 8);
2879 return NO_EXIT;
2880}
145cdb40 2881
434c91a5
RH
2882static ExitStatus op_stck(DisasContext *s, DisasOps *o)
2883{
2884 gen_helper_stck(o->out, cpu_env);
2885 /* ??? We don't implement clock states. */
2886 gen_op_movi_cc(s, 0);
2887 return NO_EXIT;
2888}
2889
dd3eb7b5
RH
2890static ExitStatus op_sckc(DisasContext *s, DisasOps *o)
2891{
2892 check_privileged(s);
2893 gen_helper_sckc(cpu_env, o->in2);
2894 return NO_EXIT;
2895}
2896
2897static ExitStatus op_stckc(DisasContext *s, DisasOps *o)
2898{
2899 check_privileged(s);
2900 gen_helper_stckc(o->out, cpu_env);
2901 return NO_EXIT;
2902}
2903
3e398cf9
RH
2904static ExitStatus op_stctg(DisasContext *s, DisasOps *o)
2905{
2906 TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
2907 TCGv_i32 r3 = tcg_const_i32(get_field(s->fields, r3));
2908 check_privileged(s);
2909 potential_page_fault(s);
2910 gen_helper_stctg(cpu_env, r1, o->in2, r3);
2911 tcg_temp_free_i32(r1);
2912 tcg_temp_free_i32(r3);
2913 return NO_EXIT;
2914}
2915
504488b8
RH
2916static ExitStatus op_stctl(DisasContext *s, DisasOps *o)
2917{
2918 TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
2919 TCGv_i32 r3 = tcg_const_i32(get_field(s->fields, r3));
2920 check_privileged(s);
2921 potential_page_fault(s);
2922 gen_helper_stctl(cpu_env, r1, o->in2, r3);
2923 tcg_temp_free_i32(r1);
2924 tcg_temp_free_i32(r3);
2925 return NO_EXIT;
2926}
2927
71bd6669
RH
2928static ExitStatus op_stidp(DisasContext *s, DisasOps *o)
2929{
2930 check_privileged(s);
2931 tcg_gen_ld32u_i64(o->out, cpu_env, offsetof(CPUS390XState, cpu_num));
2932 return NO_EXIT;
2933}
2934
c4f0a863
RH
2935static ExitStatus op_spt(DisasContext *s, DisasOps *o)
2936{
2937 check_privileged(s);
2938 gen_helper_spt(cpu_env, o->in2);
2939 return NO_EXIT;
2940}
2941
2942static ExitStatus op_stpt(DisasContext *s, DisasOps *o)
2943{
2944 check_privileged(s);
2945 gen_helper_stpt(o->out, cpu_env);
2946 return NO_EXIT;
2947}
2948
145cdb40
RH
2949static ExitStatus op_stnosm(DisasContext *s, DisasOps *o)
2950{
2951 uint64_t i2 = get_field(s->fields, i2);
2952 TCGv_i64 t;
2953
2954 check_privileged(s);
2955
2956 /* It is important to do what the instruction name says: STORE THEN.
2957 If we let the output hook perform the store then if we fault and
2958 restart, we'll have the wrong SYSTEM MASK in place. */
2959 t = tcg_temp_new_i64();
2960 tcg_gen_shri_i64(t, psw_mask, 56);
2961 tcg_gen_qemu_st8(t, o->addr1, get_mem_index(s));
2962 tcg_temp_free_i64(t);
2963
2964 if (s->fields->op == 0xac) {
2965 tcg_gen_andi_i64(psw_mask, psw_mask,
2966 (i2 << 56) | 0x00ffffffffffffffull);
2967 } else {
2968 tcg_gen_ori_i64(psw_mask, psw_mask, i2 << 56);
2969 }
2970 return NO_EXIT;
2971}
7d30bb73
RH
2972#endif
2973
2b280b97
RH
2974static ExitStatus op_st8(DisasContext *s, DisasOps *o)
2975{
2976 tcg_gen_qemu_st8(o->in1, o->in2, get_mem_index(s));
2977 return NO_EXIT;
2978}
2979
2980static ExitStatus op_st16(DisasContext *s, DisasOps *o)
2981{
2982 tcg_gen_qemu_st16(o->in1, o->in2, get_mem_index(s));
2983 return NO_EXIT;
2984}
2985
2986static ExitStatus op_st32(DisasContext *s, DisasOps *o)
2987{
2988 tcg_gen_qemu_st32(o->in1, o->in2, get_mem_index(s));
2989 return NO_EXIT;
2990}
2991
2992static ExitStatus op_st64(DisasContext *s, DisasOps *o)
2993{
2994 tcg_gen_qemu_st64(o->in1, o->in2, get_mem_index(s));
2995 return NO_EXIT;
2996}
2997
7df3e93a
RH
2998static ExitStatus op_stam(DisasContext *s, DisasOps *o)
2999{
3000 TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
3001 TCGv_i32 r3 = tcg_const_i32(get_field(s->fields, r3));
3002 potential_page_fault(s);
3003 gen_helper_stam(cpu_env, r1, o->in2, r3);
3004 tcg_temp_free_i32(r1);
3005 tcg_temp_free_i32(r3);
3006 return NO_EXIT;
3007}
3008
2ae68059
RH
3009static ExitStatus op_stcm(DisasContext *s, DisasOps *o)
3010{
3011 int m3 = get_field(s->fields, m3);
3012 int pos, base = s->insn->data;
3013 TCGv_i64 tmp = tcg_temp_new_i64();
3014
3015 pos = base + ctz32(m3) * 8;
3016 switch (m3) {
3017 case 0xf:
3018 /* Effectively a 32-bit store. */
3019 tcg_gen_shri_i64(tmp, o->in1, pos);
3020 tcg_gen_qemu_st32(tmp, o->in2, get_mem_index(s));
3021 break;
3022
3023 case 0xc:
3024 case 0x6:
3025 case 0x3:
3026 /* Effectively a 16-bit store. */
3027 tcg_gen_shri_i64(tmp, o->in1, pos);
3028 tcg_gen_qemu_st16(tmp, o->in2, get_mem_index(s));
3029 break;
3030
3031 case 0x8:
3032 case 0x4:
3033 case 0x2:
3034 case 0x1:
3035 /* Effectively an 8-bit store. */
3036 tcg_gen_shri_i64(tmp, o->in1, pos);
3037 tcg_gen_qemu_st8(tmp, o->in2, get_mem_index(s));
3038 break;
3039
3040 default:
3041 /* This is going to be a sequence of shifts and stores. */
3042 pos = base + 32 - 8;
3043 while (m3) {
3044 if (m3 & 0x8) {
3045 tcg_gen_shri_i64(tmp, o->in1, pos);
3046 tcg_gen_qemu_st8(tmp, o->in2, get_mem_index(s));
3047 tcg_gen_addi_i64(o->in2, o->in2, 1);
3048 }
3049 m3 = (m3 << 1) & 0xf;
3050 pos -= 8;
3051 }
3052 break;
3053 }
3054 tcg_temp_free_i64(tmp);
3055 return NO_EXIT;
3056}
3057
77f8d6c3
RH
3058static ExitStatus op_stm(DisasContext *s, DisasOps *o)
3059{
3060 int r1 = get_field(s->fields, r1);
3061 int r3 = get_field(s->fields, r3);
3062 int size = s->insn->data;
3063 TCGv_i64 tsize = tcg_const_i64(size);
3064
3065 while (1) {
3066 if (size == 8) {
3067 tcg_gen_qemu_st64(regs[r1], o->in2, get_mem_index(s));
3068 } else {
3069 tcg_gen_qemu_st32(regs[r1], o->in2, get_mem_index(s));
3070 }
3071 if (r1 == r3) {
3072 break;
3073 }
3074 tcg_gen_add_i64(o->in2, o->in2, tsize);
3075 r1 = (r1 + 1) & 15;
3076 }
3077
3078 tcg_temp_free_i64(tsize);
3079 return NO_EXIT;
3080}
3081
3082static ExitStatus op_stmh(DisasContext *s, DisasOps *o)
3083{
3084 int r1 = get_field(s->fields, r1);
3085 int r3 = get_field(s->fields, r3);
3086 TCGv_i64 t = tcg_temp_new_i64();
3087 TCGv_i64 t4 = tcg_const_i64(4);
3088 TCGv_i64 t32 = tcg_const_i64(32);
3089
3090 while (1) {
3091 tcg_gen_shl_i64(t, regs[r1], t32);
3092 tcg_gen_qemu_st32(t, o->in2, get_mem_index(s));
3093 if (r1 == r3) {
3094 break;
3095 }
3096 tcg_gen_add_i64(o->in2, o->in2, t4);
3097 r1 = (r1 + 1) & 15;
3098 }
3099
3100 tcg_temp_free_i64(t);
3101 tcg_temp_free_i64(t4);
3102 tcg_temp_free_i64(t32);
3103 return NO_EXIT;
3104}
3105
4600c994
RH
3106static ExitStatus op_srst(DisasContext *s, DisasOps *o)
3107{
3108 potential_page_fault(s);
3109 gen_helper_srst(o->in1, cpu_env, regs[0], o->in1, o->in2);
3110 set_cc_static(s);
3111 return_low128(o->in2);
3112 return NO_EXIT;
3113}
3114
ad044d09
RH
3115static ExitStatus op_sub(DisasContext *s, DisasOps *o)
3116{
3117 tcg_gen_sub_i64(o->out, o->in1, o->in2);
3118 return NO_EXIT;
3119}
3120
4e4bb438
RH
3121static ExitStatus op_subb(DisasContext *s, DisasOps *o)
3122{
3123 TCGv_i64 cc;
3124
3125 assert(!o->g_in2);
3126 tcg_gen_not_i64(o->in2, o->in2);
3127 tcg_gen_add_i64(o->out, o->in1, o->in2);
3128
3129 /* XXX possible optimization point */
3130 gen_op_calc_cc(s);
3131 cc = tcg_temp_new_i64();
3132 tcg_gen_extu_i32_i64(cc, cc_op);
3133 tcg_gen_shri_i64(cc, cc, 1);
3134 tcg_gen_add_i64(o->out, o->out, cc);
3135 tcg_temp_free_i64(cc);
3136 return NO_EXIT;
3137}
3138
b9836c1a
RH
3139static ExitStatus op_svc(DisasContext *s, DisasOps *o)
3140{
3141 TCGv_i32 t;
3142
3143 update_psw_addr(s);
3144 gen_op_calc_cc(s);
3145
3146 t = tcg_const_i32(get_field(s->fields, i1) & 0xff);
3147 tcg_gen_st_i32(t, cpu_env, offsetof(CPUS390XState, int_svc_code));
3148 tcg_temp_free_i32(t);
3149
3150 t = tcg_const_i32(s->next_pc - s->pc);
3151 tcg_gen_st_i32(t, cpu_env, offsetof(CPUS390XState, int_svc_ilen));
3152 tcg_temp_free_i32(t);
3153
3154 gen_exception(EXCP_SVC);
3155 return EXIT_NORETURN;
3156}
3157
31aa97d1
RH
3158static ExitStatus op_tceb(DisasContext *s, DisasOps *o)
3159{
3160 gen_helper_tceb(cc_op, o->in1, o->in2);
3161 set_cc_static(s);
3162 return NO_EXIT;
3163}
3164
3165static ExitStatus op_tcdb(DisasContext *s, DisasOps *o)
3166{
3167 gen_helper_tcdb(cc_op, o->in1, o->in2);
3168 set_cc_static(s);
3169 return NO_EXIT;
3170}
3171
3172static ExitStatus op_tcxb(DisasContext *s, DisasOps *o)
3173{
3174 gen_helper_tcxb(cc_op, o->out, o->out2, o->in2);
3175 set_cc_static(s);
3176 return NO_EXIT;
3177}
3178
112bf079
RH
3179#ifndef CONFIG_USER_ONLY
3180static ExitStatus op_tprot(DisasContext *s, DisasOps *o)
3181{
3182 potential_page_fault(s);
3183 gen_helper_tprot(cc_op, o->addr1, o->in2);
3184 set_cc_static(s);
3185 return NO_EXIT;
3186}
3187#endif
3188
0a949039
RH
3189static ExitStatus op_tr(DisasContext *s, DisasOps *o)
3190{
3191 TCGv_i32 l = tcg_const_i32(get_field(s->fields, l1));
3192 potential_page_fault(s);
3193 gen_helper_tr(cpu_env, l, o->addr1, o->in2);
3194 tcg_temp_free_i32(l);
3195 set_cc_static(s);
3196 return NO_EXIT;
3197}
3198
3199static ExitStatus op_unpk(DisasContext *s, DisasOps *o)
3200{
3201 TCGv_i32 l = tcg_const_i32(get_field(s->fields, l1));
3202 potential_page_fault(s);
3203 gen_helper_unpk(cpu_env, l, o->addr1, o->in2);
3204 tcg_temp_free_i32(l);
3205 return NO_EXIT;
3206}
3207
3208static ExitStatus op_xc(DisasContext *s, DisasOps *o)
3209{
3210 TCGv_i32 l = tcg_const_i32(get_field(s->fields, l1));
3211 potential_page_fault(s);
3212 gen_helper_xc(cc_op, cpu_env, l, o->addr1, o->in2);
3213 tcg_temp_free_i32(l);
3214 set_cc_static(s);
3215 return NO_EXIT;
3216}
3217
3bbfbd1f
RH
3218static ExitStatus op_xor(DisasContext *s, DisasOps *o)
3219{
3220 tcg_gen_xor_i64(o->out, o->in1, o->in2);
3221 return NO_EXIT;
3222}
3223
facfc864
RH
3224static ExitStatus op_xori(DisasContext *s, DisasOps *o)
3225{
3226 int shift = s->insn->data & 0xff;
3227 int size = s->insn->data >> 8;
3228 uint64_t mask = ((1ull << size) - 1) << shift;
3229
3230 assert(!o->g_in2);
3231 tcg_gen_shli_i64(o->in2, o->in2, shift);
3232 tcg_gen_xor_i64(o->out, o->in1, o->in2);
3233
3234 /* Produce the CC from only the bits manipulated. */
3235 tcg_gen_andi_i64(cc_dst, o->out, mask);
3236 set_cc_nz_u64(s, cc_dst);
3237 return NO_EXIT;
3238}
3239
24db8412
RH
3240static ExitStatus op_zero(DisasContext *s, DisasOps *o)
3241{
3242 o->out = tcg_const_i64(0);
3243 return NO_EXIT;
3244}
3245
3246static ExitStatus op_zero2(DisasContext *s, DisasOps *o)
3247{
3248 o->out = tcg_const_i64(0);
3249 o->out2 = o->out;
3250 o->g_out2 = true;
3251 return NO_EXIT;
3252}
3253
ad044d09
RH
3254/* ====================================================================== */
3255/* The "Cc OUTput" generators. Given the generated output (and in some cases
3256 the original inputs), update the various cc data structures in order to
3257 be able to compute the new condition code. */
3258
b9bca3e5
RH
3259static void cout_abs32(DisasContext *s, DisasOps *o)
3260{
3261 gen_op_update1_cc_i64(s, CC_OP_ABS_32, o->out);
3262}
3263
3264static void cout_abs64(DisasContext *s, DisasOps *o)
3265{
3266 gen_op_update1_cc_i64(s, CC_OP_ABS_64, o->out);
3267}
3268
ad044d09
RH
3269static void cout_adds32(DisasContext *s, DisasOps *o)
3270{
3271 gen_op_update3_cc_i64(s, CC_OP_ADD_32, o->in1, o->in2, o->out);
3272}
3273
3274static void cout_adds64(DisasContext *s, DisasOps *o)
3275{
3276 gen_op_update3_cc_i64(s, CC_OP_ADD_64, o->in1, o->in2, o->out);
3277}
3278
3279static void cout_addu32(DisasContext *s, DisasOps *o)
3280{
3281 gen_op_update3_cc_i64(s, CC_OP_ADDU_32, o->in1, o->in2, o->out);
3282}
3283
3284static void cout_addu64(DisasContext *s, DisasOps *o)
3285{
3286 gen_op_update3_cc_i64(s, CC_OP_ADDU_64, o->in1, o->in2, o->out);
3287}
3288
4e4bb438
RH
3289static void cout_addc32(DisasContext *s, DisasOps *o)
3290{
3291 gen_op_update3_cc_i64(s, CC_OP_ADDC_32, o->in1, o->in2, o->out);
3292}
3293
3294static void cout_addc64(DisasContext *s, DisasOps *o)
3295{
3296 gen_op_update3_cc_i64(s, CC_OP_ADDC_64, o->in1, o->in2, o->out);
3297}
3298
a7e836d5
RH
3299static void cout_cmps32(DisasContext *s, DisasOps *o)
3300{
3301 gen_op_update2_cc_i64(s, CC_OP_LTGT_32, o->in1, o->in2);
3302}
3303
3304static void cout_cmps64(DisasContext *s, DisasOps *o)
3305{
3306 gen_op_update2_cc_i64(s, CC_OP_LTGT_64, o->in1, o->in2);
3307}
3308
3309static void cout_cmpu32(DisasContext *s, DisasOps *o)
3310{
3311 gen_op_update2_cc_i64(s, CC_OP_LTUGTU_32, o->in1, o->in2);
3312}
3313
3314static void cout_cmpu64(DisasContext *s, DisasOps *o)
3315{
3316 gen_op_update2_cc_i64(s, CC_OP_LTUGTU_64, o->in1, o->in2);
3317}
3318
587626f8
RH
3319static void cout_f32(DisasContext *s, DisasOps *o)
3320{
3321 gen_op_update1_cc_i64(s, CC_OP_NZ_F32, o->out);
3322}
3323
3324static void cout_f64(DisasContext *s, DisasOps *o)
3325{
3326 gen_op_update1_cc_i64(s, CC_OP_NZ_F64, o->out);
3327}
3328
3329static void cout_f128(DisasContext *s, DisasOps *o)
3330{
3331 gen_op_update2_cc_i64(s, CC_OP_NZ_F128, o->out, o->out2);
3332}
3333
b9bca3e5
RH
3334static void cout_nabs32(DisasContext *s, DisasOps *o)
3335{
3336 gen_op_update1_cc_i64(s, CC_OP_NABS_32, o->out);
3337}
3338
3339static void cout_nabs64(DisasContext *s, DisasOps *o)
3340{
3341 gen_op_update1_cc_i64(s, CC_OP_NABS_64, o->out);
3342}
3343
3344static void cout_neg32(DisasContext *s, DisasOps *o)
3345{
3346 gen_op_update1_cc_i64(s, CC_OP_COMP_32, o->out);
3347}
3348
3349static void cout_neg64(DisasContext *s, DisasOps *o)
3350{
3351 gen_op_update1_cc_i64(s, CC_OP_COMP_64, o->out);
3352}
3353
3bbfbd1f
RH
3354static void cout_nz32(DisasContext *s, DisasOps *o)
3355{
3356 tcg_gen_ext32u_i64(cc_dst, o->out);
3357 gen_op_update1_cc_i64(s, CC_OP_NZ, cc_dst);
3358}
3359
3360static void cout_nz64(DisasContext *s, DisasOps *o)
3361{
3362 gen_op_update1_cc_i64(s, CC_OP_NZ, o->out);
3363}
3364
11bf2d73
RH
3365static void cout_s32(DisasContext *s, DisasOps *o)
3366{
3367 gen_op_update1_cc_i64(s, CC_OP_LTGT0_32, o->out);
3368}
3369
3370static void cout_s64(DisasContext *s, DisasOps *o)
3371{
3372 gen_op_update1_cc_i64(s, CC_OP_LTGT0_64, o->out);
3373}
3374
ad044d09
RH
3375static void cout_subs32(DisasContext *s, DisasOps *o)
3376{
3377 gen_op_update3_cc_i64(s, CC_OP_SUB_32, o->in1, o->in2, o->out);
3378}
3379
3380static void cout_subs64(DisasContext *s, DisasOps *o)
3381{
3382 gen_op_update3_cc_i64(s, CC_OP_SUB_64, o->in1, o->in2, o->out);
3383}
3384
3385static void cout_subu32(DisasContext *s, DisasOps *o)
3386{
3387 gen_op_update3_cc_i64(s, CC_OP_SUBU_32, o->in1, o->in2, o->out);
3388}
3389
3390static void cout_subu64(DisasContext *s, DisasOps *o)
3391{
3392 gen_op_update3_cc_i64(s, CC_OP_SUBU_64, o->in1, o->in2, o->out);
3393}
3394
4e4bb438
RH
3395static void cout_subb32(DisasContext *s, DisasOps *o)
3396{
3397 gen_op_update3_cc_i64(s, CC_OP_SUBB_32, o->in1, o->in2, o->out);
3398}
3399
3400static void cout_subb64(DisasContext *s, DisasOps *o)
3401{
3402 gen_op_update3_cc_i64(s, CC_OP_SUBB_64, o->in1, o->in2, o->out);
3403}
3404
00d2dc19
RH
3405static void cout_tm32(DisasContext *s, DisasOps *o)
3406{
3407 gen_op_update2_cc_i64(s, CC_OP_TM_32, o->in1, o->in2);
3408}
3409
3410static void cout_tm64(DisasContext *s, DisasOps *o)
3411{
3412 gen_op_update2_cc_i64(s, CC_OP_TM_64, o->in1, o->in2);
3413}
3414
ad044d09
RH
3415/* ====================================================================== */
3416/* The "PREPeration" generators. These initialize the DisasOps.OUT fields
3417 with the TCG register to which we will write. Used in combination with
3418 the "wout" generators, in some cases we need a new temporary, and in
3419 some cases we can write to a TCG global. */
3420
3421static void prep_new(DisasContext *s, DisasFields *f, DisasOps *o)
3422{
3423 o->out = tcg_temp_new_i64();
3424}
3425
891452e5
RH
3426static void prep_new_P(DisasContext *s, DisasFields *f, DisasOps *o)
3427{
3428 o->out = tcg_temp_new_i64();
3429 o->out2 = tcg_temp_new_i64();
3430}
3431
ad044d09
RH
3432static void prep_r1(DisasContext *s, DisasFields *f, DisasOps *o)
3433{
3434 o->out = regs[get_field(f, r1)];
3435 o->g_out = true;
3436}
3437
1ac5889f
RH
3438static void prep_r1_P(DisasContext *s, DisasFields *f, DisasOps *o)
3439{
3440 /* ??? Specification exception: r1 must be even. */
3441 int r1 = get_field(f, r1);
3442 o->out = regs[r1];
3443 o->out2 = regs[(r1 + 1) & 15];
3444 o->g_out = o->g_out2 = true;
3445}
3446
587626f8
RH
3447static void prep_f1(DisasContext *s, DisasFields *f, DisasOps *o)
3448{
3449 o->out = fregs[get_field(f, r1)];
3450 o->g_out = true;
3451}
3452
3453static void prep_x1(DisasContext *s, DisasFields *f, DisasOps *o)
3454{
3455 /* ??? Specification exception: r1 must be < 14. */
3456 int r1 = get_field(f, r1);
3457 o->out = fregs[r1];
3458 o->out2 = fregs[(r1 + 2) & 15];
3459 o->g_out = o->g_out2 = true;
3460}
3461
ad044d09
RH
3462/* ====================================================================== */
3463/* The "Write OUTput" generators. These generally perform some non-trivial
3464 copy of data to TCG globals, or to main memory. The trivial cases are
3465 generally handled by having a "prep" generator install the TCG global
3466 as the destination of the operation. */
3467
22c37a08
RH
3468static void wout_r1(DisasContext *s, DisasFields *f, DisasOps *o)
3469{
3470 store_reg(get_field(f, r1), o->out);
3471}
3472
afdc70be
RH
3473static void wout_r1_8(DisasContext *s, DisasFields *f, DisasOps *o)
3474{
3475 int r1 = get_field(f, r1);
3476 tcg_gen_deposit_i64(regs[r1], regs[r1], o->out, 0, 8);
3477}
3478
d54f5865
RH
3479static void wout_r1_16(DisasContext *s, DisasFields *f, DisasOps *o)
3480{
3481 int r1 = get_field(f, r1);
3482 tcg_gen_deposit_i64(regs[r1], regs[r1], o->out, 0, 16);
3483}
3484
ad044d09
RH
3485static void wout_r1_32(DisasContext *s, DisasFields *f, DisasOps *o)
3486{
3487 store_reg32_i64(get_field(f, r1), o->out);
3488}
3489
891452e5
RH
3490static void wout_r1_P32(DisasContext *s, DisasFields *f, DisasOps *o)
3491{
3492 /* ??? Specification exception: r1 must be even. */
3493 int r1 = get_field(f, r1);
3494 store_reg32_i64(r1, o->out);
3495 store_reg32_i64((r1 + 1) & 15, o->out2);
3496}
3497
d87aaf93
RH
3498static void wout_r1_D32(DisasContext *s, DisasFields *f, DisasOps *o)
3499{
3500 /* ??? Specification exception: r1 must be even. */
3501 int r1 = get_field(f, r1);
3502 store_reg32_i64((r1 + 1) & 15, o->out);
3503 tcg_gen_shri_i64(o->out, o->out, 32);
3504 store_reg32_i64(r1, o->out);
3505}
22c37a08 3506
d764a8d1
RH
3507static void wout_e1(DisasContext *s, DisasFields *f, DisasOps *o)
3508{
3509 store_freg32_i64(get_field(f, r1), o->out);
3510}
3511
3512static void wout_f1(DisasContext *s, DisasFields *f, DisasOps *o)
3513{
3514 store_freg(get_field(f, r1), o->out);
3515}
3516
3517static void wout_x1(DisasContext *s, DisasFields *f, DisasOps *o)
3518{
587626f8 3519 /* ??? Specification exception: r1 must be < 14. */
d764a8d1
RH
3520 int f1 = get_field(s->fields, r1);
3521 store_freg(f1, o->out);
3522 store_freg((f1 + 2) & 15, o->out2);
3523}
3524
22c37a08
RH
3525static void wout_cond_r1r2_32(DisasContext *s, DisasFields *f, DisasOps *o)
3526{
3527 if (get_field(f, r1) != get_field(f, r2)) {
3528 store_reg32_i64(get_field(f, r1), o->out);
3529 }
3530}
d87aaf93 3531
d764a8d1
RH
3532static void wout_cond_e1e2(DisasContext *s, DisasFields *f, DisasOps *o)
3533{
3534 if (get_field(f, r1) != get_field(f, r2)) {
3535 store_freg32_i64(get_field(f, r1), o->out);
3536 }
3537}
3538
6a04d76a
RH
3539static void wout_m1_8(DisasContext *s, DisasFields *f, DisasOps *o)
3540{
3541 tcg_gen_qemu_st8(o->out, o->addr1, get_mem_index(s));
3542}
3543
3544static void wout_m1_16(DisasContext *s, DisasFields *f, DisasOps *o)
3545{
3546 tcg_gen_qemu_st16(o->out, o->addr1, get_mem_index(s));
3547}
3548
ad044d09
RH
3549static void wout_m1_32(DisasContext *s, DisasFields *f, DisasOps *o)
3550{
3551 tcg_gen_qemu_st32(o->out, o->addr1, get_mem_index(s));
3552}
3553
3554static void wout_m1_64(DisasContext *s, DisasFields *f, DisasOps *o)
3555{
3556 tcg_gen_qemu_st64(o->out, o->addr1, get_mem_index(s));
3557}
3558
ea20490f
RH
3559static void wout_m2_32(DisasContext *s, DisasFields *f, DisasOps *o)
3560{
3561 tcg_gen_qemu_st32(o->out, o->in2, get_mem_index(s));
3562}
3563
ad044d09
RH
3564/* ====================================================================== */
3565/* The "INput 1" generators. These load the first operand to an insn. */
3566
3567static void in1_r1(DisasContext *s, DisasFields *f, DisasOps *o)
3568{
3569 o->in1 = load_reg(get_field(f, r1));
3570}
3571
d1c04a2b
RH
3572static void in1_r1_o(DisasContext *s, DisasFields *f, DisasOps *o)
3573{
3574 o->in1 = regs[get_field(f, r1)];
3575 o->g_in1 = true;
3576}
3577
cbe24bfa
RH
3578static void in1_r1_32s(DisasContext *s, DisasFields *f, DisasOps *o)
3579{
3580 o->in1 = tcg_temp_new_i64();
3581 tcg_gen_ext32s_i64(o->in1, regs[get_field(f, r1)]);
3582}
3583
3584static void in1_r1_32u(DisasContext *s, DisasFields *f, DisasOps *o)
3585{
3586 o->in1 = tcg_temp_new_i64();
3587 tcg_gen_ext32u_i64(o->in1, regs[get_field(f, r1)]);
3588}
3589
32a44d58
RH
3590static void in1_r1_sr32(DisasContext *s, DisasFields *f, DisasOps *o)
3591{
3592 o->in1 = tcg_temp_new_i64();
3593 tcg_gen_shri_i64(o->in1, regs[get_field(f, r1)], 32);
3594}
3595
1ac5889f
RH
3596static void in1_r1p1(DisasContext *s, DisasFields *f, DisasOps *o)
3597{
3598 /* ??? Specification exception: r1 must be even. */
3599 int r1 = get_field(f, r1);
3600 o->in1 = load_reg((r1 + 1) & 15);
3601}
3602
d87aaf93
RH
3603static void in1_r1p1_32s(DisasContext *s, DisasFields *f, DisasOps *o)
3604{
3605 /* ??? Specification exception: r1 must be even. */
3606 int r1 = get_field(f, r1);
3607 o->in1 = tcg_temp_new_i64();
3608 tcg_gen_ext32s_i64(o->in1, regs[(r1 + 1) & 15]);
3609}
3610
3611static void in1_r1p1_32u(DisasContext *s, DisasFields *f, DisasOps *o)
3612{
3613 /* ??? Specification exception: r1 must be even. */
3614 int r1 = get_field(f, r1);
3615 o->in1 = tcg_temp_new_i64();
3616 tcg_gen_ext32u_i64(o->in1, regs[(r1 + 1) & 15]);
3617}
3618
891452e5
RH
3619static void in1_r1_D32(DisasContext *s, DisasFields *f, DisasOps *o)
3620{
3621 /* ??? Specification exception: r1 must be even. */
3622 int r1 = get_field(f, r1);
3623 o->in1 = tcg_temp_new_i64();
3624 tcg_gen_concat32_i64(o->in1, regs[r1 + 1], regs[r1]);
3625}
3626
ad044d09
RH
3627static void in1_r2(DisasContext *s, DisasFields *f, DisasOps *o)
3628{
3629 o->in1 = load_reg(get_field(f, r2));
3630}
3631
3632static void in1_r3(DisasContext *s, DisasFields *f, DisasOps *o)
3633{
3634 o->in1 = load_reg(get_field(f, r3));
3635}
3636
cbe24bfa
RH
3637static void in1_r3_o(DisasContext *s, DisasFields *f, DisasOps *o)
3638{
3639 o->in1 = regs[get_field(f, r3)];
3640 o->g_in1 = true;
3641}
3642
3643static void in1_r3_32s(DisasContext *s, DisasFields *f, DisasOps *o)
3644{
3645 o->in1 = tcg_temp_new_i64();
3646 tcg_gen_ext32s_i64(o->in1, regs[get_field(f, r3)]);
3647}
3648
3649static void in1_r3_32u(DisasContext *s, DisasFields *f, DisasOps *o)
3650{
3651 o->in1 = tcg_temp_new_i64();
3652 tcg_gen_ext32u_i64(o->in1, regs[get_field(f, r3)]);
3653}
3654
00574261
RH
3655static void in1_e1(DisasContext *s, DisasFields *f, DisasOps *o)
3656{
3657 o->in1 = load_freg32_i64(get_field(f, r1));
3658}
3659
3660static void in1_f1_o(DisasContext *s, DisasFields *f, DisasOps *o)
3661{
3662 o->in1 = fregs[get_field(f, r1)];
3663 o->g_in1 = true;
3664}
3665
587626f8
RH
3666static void in1_x1_o(DisasContext *s, DisasFields *f, DisasOps *o)
3667{
3668 /* ??? Specification exception: r1 must be < 14. */
3669 int r1 = get_field(f, r1);
3670 o->out = fregs[r1];
3671 o->out2 = fregs[(r1 + 2) & 15];
3672 o->g_out = o->g_out2 = true;
3673}
3674
ad044d09
RH
3675static void in1_la1(DisasContext *s, DisasFields *f, DisasOps *o)
3676{
3677 o->addr1 = get_address(s, 0, get_field(f, b1), get_field(f, d1));
3678}
3679
e025e52a
RH
3680static void in1_la2(DisasContext *s, DisasFields *f, DisasOps *o)
3681{
3682 int x2 = have_field(f, x2) ? get_field(f, x2) : 0;
3683 o->addr1 = get_address(s, x2, get_field(f, b2), get_field(f, d2));
3684}
3685
a7e836d5
RH
3686static void in1_m1_8u(DisasContext *s, DisasFields *f, DisasOps *o)
3687{
3688 in1_la1(s, f, o);
3689 o->in1 = tcg_temp_new_i64();
3690 tcg_gen_qemu_ld8u(o->in1, o->addr1, get_mem_index(s));
3691}
3692
3693static void in1_m1_16s(DisasContext *s, DisasFields *f, DisasOps *o)
3694{
3695 in1_la1(s, f, o);
3696 o->in1 = tcg_temp_new_i64();
3697 tcg_gen_qemu_ld16s(o->in1, o->addr1, get_mem_index(s));
3698}
3699
3700static void in1_m1_16u(DisasContext *s, DisasFields *f, DisasOps *o)
3701{
3702 in1_la1(s, f, o);
3703 o->in1 = tcg_temp_new_i64();
3704 tcg_gen_qemu_ld16u(o->in1, o->addr1, get_mem_index(s));
3705}
3706
ad044d09
RH
3707static void in1_m1_32s(DisasContext *s, DisasFields *f, DisasOps *o)
3708{
3709 in1_la1(s, f, o);
3710 o->in1 = tcg_temp_new_i64();
3711 tcg_gen_qemu_ld32s(o->in1, o->addr1, get_mem_index(s));
3712}
3713
e272b3ac
RH
3714static void in1_m1_32u(DisasContext *s, DisasFields *f, DisasOps *o)
3715{
3716 in1_la1(s, f, o);
3717 o->in1 = tcg_temp_new_i64();
3718 tcg_gen_qemu_ld32u(o->in1, o->addr1, get_mem_index(s));
3719}
3720
ad044d09
RH
3721static void in1_m1_64(DisasContext *s, DisasFields *f, DisasOps *o)
3722{
3723 in1_la1(s, f, o);
3724 o->in1 = tcg_temp_new_i64();
3725 tcg_gen_qemu_ld64(o->in1, o->addr1, get_mem_index(s));
3726}
3727
3728/* ====================================================================== */
3729/* The "INput 2" generators. These load the second operand to an insn. */
3730
e025e52a
RH
3731static void in2_r1_o(DisasContext *s, DisasFields *f, DisasOps *o)
3732{
3733 o->in2 = regs[get_field(f, r1)];
3734 o->g_in2 = true;
3735}
3736
3737static void in2_r1_16u(DisasContext *s, DisasFields *f, DisasOps *o)
3738{
3739 o->in2 = tcg_temp_new_i64();
3740 tcg_gen_ext16u_i64(o->in2, regs[get_field(f, r1)]);
3741}
3742
3743static void in2_r1_32u(DisasContext *s, DisasFields *f, DisasOps *o)
3744{
3745 o->in2 = tcg_temp_new_i64();
3746 tcg_gen_ext32u_i64(o->in2, regs[get_field(f, r1)]);
3747}
3748
ad044d09
RH
3749static void in2_r2(DisasContext *s, DisasFields *f, DisasOps *o)
3750{
3751 o->in2 = load_reg(get_field(f, r2));
3752}
3753
d1c04a2b
RH
3754static void in2_r2_o(DisasContext *s, DisasFields *f, DisasOps *o)
3755{
3756 o->in2 = regs[get_field(f, r2)];
3757 o->g_in2 = true;
3758}
3759
8ac33cdb
RH
3760static void in2_r2_nz(DisasContext *s, DisasFields *f, DisasOps *o)
3761{
3762 int r2 = get_field(f, r2);
3763 if (r2 != 0) {
3764 o->in2 = load_reg(r2);
3765 }
3766}
3767
c698d876
RH
3768static void in2_r2_8s(DisasContext *s, DisasFields *f, DisasOps *o)
3769{
3770 o->in2 = tcg_temp_new_i64();
3771 tcg_gen_ext8s_i64(o->in2, regs[get_field(f, r2)]);
3772}
3773
3774static void in2_r2_8u(DisasContext *s, DisasFields *f, DisasOps *o)
3775{
3776 o->in2 = tcg_temp_new_i64();
3777 tcg_gen_ext8u_i64(o->in2, regs[get_field(f, r2)]);
3778}
3779
3780static void in2_r2_16s(DisasContext *s, DisasFields *f, DisasOps *o)
3781{
3782 o->in2 = tcg_temp_new_i64();
3783 tcg_gen_ext16s_i64(o->in2, regs[get_field(f, r2)]);
3784}
3785
3786static void in2_r2_16u(DisasContext *s, DisasFields *f, DisasOps *o)
3787{
3788 o->in2 = tcg_temp_new_i64();
3789 tcg_gen_ext16u_i64(o->in2, regs[get_field(f, r2)]);
3790}
3791
ad044d09
RH
3792static void in2_r3(DisasContext *s, DisasFields *f, DisasOps *o)
3793{
3794 o->in2 = load_reg(get_field(f, r3));
3795}
3796
3797static void in2_r2_32s(DisasContext *s, DisasFields *f, DisasOps *o)
3798{
3799 o->in2 = tcg_temp_new_i64();
3800 tcg_gen_ext32s_i64(o->in2, regs[get_field(f, r2)]);
3801}
3802
3803static void in2_r2_32u(DisasContext *s, DisasFields *f, DisasOps *o)
3804{
3805 o->in2 = tcg_temp_new_i64();
3806 tcg_gen_ext32u_i64(o->in2, regs[get_field(f, r2)]);
3807}
3808
d764a8d1
RH
3809static void in2_e2(DisasContext *s, DisasFields *f, DisasOps *o)
3810{
3811 o->in2 = load_freg32_i64(get_field(f, r2));
3812}
3813
3814static void in2_f2_o(DisasContext *s, DisasFields *f, DisasOps *o)
3815{
3816 o->in2 = fregs[get_field(f, r2)];
3817 o->g_in2 = true;
3818}
3819
3820static void in2_x2_o(DisasContext *s, DisasFields *f, DisasOps *o)
3821{
587626f8
RH
3822 /* ??? Specification exception: r1 must be < 14. */
3823 int r2 = get_field(f, r2);
3824 o->in1 = fregs[r2];
3825 o->in2 = fregs[(r2 + 2) & 15];
d764a8d1
RH
3826 o->g_in1 = o->g_in2 = true;
3827}
3828
374724f9
RH
3829static void in2_ra2(DisasContext *s, DisasFields *f, DisasOps *o)
3830{
3831 o->in2 = get_address(s, 0, get_field(f, r2), 0);
3832}
3833
ad044d09
RH
3834static void in2_a2(DisasContext *s, DisasFields *f, DisasOps *o)
3835{
3836 int x2 = have_field(f, x2) ? get_field(f, x2) : 0;
3837 o->in2 = get_address(s, x2, get_field(f, b2), get_field(f, d2));
3838}
3839
a7e836d5
RH
3840static void in2_ri2(DisasContext *s, DisasFields *f, DisasOps *o)
3841{
3842 o->in2 = tcg_const_i64(s->pc + (int64_t)get_field(f, i2) * 2);
3843}
3844
cbe24bfa
RH
3845static void in2_sh32(DisasContext *s, DisasFields *f, DisasOps *o)
3846{
3847 help_l2_shift(s, f, o, 31);
3848}
3849
3850static void in2_sh64(DisasContext *s, DisasFields *f, DisasOps *o)
3851{
3852 help_l2_shift(s, f, o, 63);
3853}
3854
afdc70be
RH
3855static void in2_m2_8u(DisasContext *s, DisasFields *f, DisasOps *o)
3856{
3857 in2_a2(s, f, o);
3858 tcg_gen_qemu_ld8u(o->in2, o->in2, get_mem_index(s));
3859}
3860
d82287de
RH
3861static void in2_m2_16s(DisasContext *s, DisasFields *f, DisasOps *o)
3862{
3863 in2_a2(s, f, o);
3864 tcg_gen_qemu_ld16s(o->in2, o->in2, get_mem_index(s));
3865}
3866
d54f5865
RH
3867static void in2_m2_16u(DisasContext *s, DisasFields *f, DisasOps *o)
3868{
3869 in2_a2(s, f, o);
3870 tcg_gen_qemu_ld16u(o->in2, o->in2, get_mem_index(s));
3871}
3872
ad044d09
RH
3873static void in2_m2_32s(DisasContext *s, DisasFields *f, DisasOps *o)
3874{
3875 in2_a2(s, f, o);
3876 tcg_gen_qemu_ld32s(o->in2, o->in2, get_mem_index(s));
3877}
3878
3879static void in2_m2_32u(DisasContext *s, DisasFields *f, DisasOps *o)
3880{
3881 in2_a2(s, f, o);
3882 tcg_gen_qemu_ld32u(o->in2, o->in2, get_mem_index(s));
3883}
3884
3885static void in2_m2_64(DisasContext *s, DisasFields *f, DisasOps *o)
3886{
3887 in2_a2(s, f, o);
3888 tcg_gen_qemu_ld64(o->in2, o->in2, get_mem_index(s));
3889}
3890
a7e836d5
RH
3891static void in2_mri2_16u(DisasContext *s, DisasFields *f, DisasOps *o)
3892{
3893 in2_ri2(s, f, o);
3894 tcg_gen_qemu_ld16u(o->in2, o->in2, get_mem_index(s));
3895}
3896
3897static void in2_mri2_32s(DisasContext *s, DisasFields *f, DisasOps *o)
3898{
3899 in2_ri2(s, f, o);
3900 tcg_gen_qemu_ld32s(o->in2, o->in2, get_mem_index(s));
3901}
3902
3903static void in2_mri2_32u(DisasContext *s, DisasFields *f, DisasOps *o)
3904{
3905 in2_ri2(s, f, o);
3906 tcg_gen_qemu_ld32u(o->in2, o->in2, get_mem_index(s));
3907}
3908
3909static void in2_mri2_64(DisasContext *s, DisasFields *f, DisasOps *o)
3910{
3911 in2_ri2(s, f, o);
3912 tcg_gen_qemu_ld64(o->in2, o->in2, get_mem_index(s));
3913}
3914
ad044d09
RH
3915static void in2_i2(DisasContext *s, DisasFields *f, DisasOps *o)
3916{
3917 o->in2 = tcg_const_i64(get_field(f, i2));
3918}
3919
a7e836d5
RH
3920static void in2_i2_8u(DisasContext *s, DisasFields *f, DisasOps *o)
3921{
3922 o->in2 = tcg_const_i64((uint8_t)get_field(f, i2));
3923}
3924
3925static void in2_i2_16u(DisasContext *s, DisasFields *f, DisasOps *o)
3926{
3927 o->in2 = tcg_const_i64((uint16_t)get_field(f, i2));
3928}
3929
ad044d09
RH
3930static void in2_i2_32u(DisasContext *s, DisasFields *f, DisasOps *o)
3931{
3932 o->in2 = tcg_const_i64((uint32_t)get_field(f, i2));
3933}
3934
ade9dea4
RH
3935static void in2_i2_16u_shl(DisasContext *s, DisasFields *f, DisasOps *o)
3936{
3937 uint64_t i2 = (uint16_t)get_field(f, i2);
3938 o->in2 = tcg_const_i64(i2 << s->insn->data);
3939}
3940
3941static void in2_i2_32u_shl(DisasContext *s, DisasFields *f, DisasOps *o)
3942{
3943 uint64_t i2 = (uint32_t)get_field(f, i2);
3944 o->in2 = tcg_const_i64(i2 << s->insn->data);
3945}
3946
ad044d09
RH
3947/* ====================================================================== */
3948
3949/* Find opc within the table of insns. This is formulated as a switch
3950 statement so that (1) we get compile-time notice of cut-paste errors
3951 for duplicated opcodes, and (2) the compiler generates the binary
3952 search tree, rather than us having to post-process the table. */
3953
3954#define C(OPC, NM, FT, FC, I1, I2, P, W, OP, CC) \
3955 D(OPC, NM, FT, FC, I1, I2, P, W, OP, CC, 0)
3956
3957#define D(OPC, NM, FT, FC, I1, I2, P, W, OP, CC, D) insn_ ## NM,
3958
3959enum DisasInsnEnum {
3960#include "insn-data.def"
3961};
3962
3963#undef D
3964#define D(OPC, NM, FT, FC, I1, I2, P, W, OP, CC, D) { \
3965 .opc = OPC, \
3966 .fmt = FMT_##FT, \
3967 .fac = FAC_##FC, \
3968 .name = #NM, \
3969 .help_in1 = in1_##I1, \
3970 .help_in2 = in2_##I2, \
3971 .help_prep = prep_##P, \
3972 .help_wout = wout_##W, \
3973 .help_cout = cout_##CC, \
3974 .help_op = op_##OP, \
3975 .data = D \
3976 },
3977
3978/* Allow 0 to be used for NULL in the table below. */
3979#define in1_0 NULL
3980#define in2_0 NULL
3981#define prep_0 NULL
3982#define wout_0 NULL
3983#define cout_0 NULL
3984#define op_0 NULL
3985
3986static const DisasInsn insn_info[] = {
3987#include "insn-data.def"
3988};
3989
3990#undef D
3991#define D(OPC, NM, FT, FC, I1, I2, P, W, OP, CC, D) \
3992 case OPC: return &insn_info[insn_ ## NM];
3993
3994static const DisasInsn *lookup_opc(uint16_t opc)
3995{
3996 switch (opc) {
3997#include "insn-data.def"
3998 default:
3999 return NULL;
4000 }
4001}
4002
4003#undef D
4004#undef C
4005
4006/* Extract a field from the insn. The INSN should be left-aligned in
4007 the uint64_t so that we can more easily utilize the big-bit-endian
4008 definitions we extract from the Principals of Operation. */
4009
4010static void extract_field(DisasFields *o, const DisasField *f, uint64_t insn)
4011{
4012 uint32_t r, m;
4013
4014 if (f->size == 0) {
4015 return;
4016 }
4017
4018 /* Zero extract the field from the insn. */
4019 r = (insn << f->beg) >> (64 - f->size);
4020
4021 /* Sign-extend, or un-swap the field as necessary. */
4022 switch (f->type) {
4023 case 0: /* unsigned */
4024 break;
4025 case 1: /* signed */
4026 assert(f->size <= 32);
4027 m = 1u << (f->size - 1);
4028 r = (r ^ m) - m;
4029 break;
4030 case 2: /* dl+dh split, signed 20 bit. */
4031 r = ((int8_t)r << 12) | (r >> 8);
4032 break;
4033 default:
4034 abort();
4035 }
4036
4037 /* Validate that the "compressed" encoding we selected above is valid.
4038 I.e. we havn't make two different original fields overlap. */
4039 assert(((o->presentC >> f->indexC) & 1) == 0);
4040 o->presentC |= 1 << f->indexC;
4041 o->presentO |= 1 << f->indexO;
4042
4043 o->c[f->indexC] = r;
4044}
4045
4046/* Lookup the insn at the current PC, extracting the operands into O and
4047 returning the info struct for the insn. Returns NULL for invalid insn. */
4048
4049static const DisasInsn *extract_insn(CPUS390XState *env, DisasContext *s,
4050 DisasFields *f)
4051{
4052 uint64_t insn, pc = s->pc;
d5a103cd 4053 int op, op2, ilen;
ad044d09
RH
4054 const DisasInsn *info;
4055
4056 insn = ld_code2(env, pc);
4057 op = (insn >> 8) & 0xff;
d5a103cd
RH
4058 ilen = get_ilen(op);
4059 s->next_pc = s->pc + ilen;
4060
4061 switch (ilen) {
4062 case 2:
ad044d09
RH
4063 insn = insn << 48;
4064 break;
d5a103cd 4065 case 4:
ad044d09
RH
4066 insn = ld_code4(env, pc) << 32;
4067 break;
d5a103cd 4068 case 6:
ad044d09
RH
4069 insn = (insn << 48) | (ld_code4(env, pc + 2) << 16);
4070 break;
4071 default:
4072 abort();
4073 }
4074
4075 /* We can't actually determine the insn format until we've looked up
4076 the full insn opcode. Which we can't do without locating the
4077 secondary opcode. Assume by default that OP2 is at bit 40; for
4078 those smaller insns that don't actually have a secondary opcode
4079 this will correctly result in OP2 = 0. */
4080 switch (op) {
4081 case 0x01: /* E */
4082 case 0x80: /* S */
4083 case 0x82: /* S */
4084 case 0x93: /* S */
4085 case 0xb2: /* S, RRF, RRE */
4086 case 0xb3: /* RRE, RRD, RRF */
4087 case 0xb9: /* RRE, RRF */
4088 case 0xe5: /* SSE, SIL */
4089 op2 = (insn << 8) >> 56;
4090 break;
4091 case 0xa5: /* RI */
4092 case 0xa7: /* RI */
4093 case 0xc0: /* RIL */
4094 case 0xc2: /* RIL */
4095 case 0xc4: /* RIL */
4096 case 0xc6: /* RIL */
4097 case 0xc8: /* SSF */
4098 case 0xcc: /* RIL */
4099 op2 = (insn << 12) >> 60;
4100 break;
4101 case 0xd0 ... 0xdf: /* SS */
4102 case 0xe1: /* SS */
4103 case 0xe2: /* SS */
4104 case 0xe8: /* SS */
4105 case 0xe9: /* SS */
4106 case 0xea: /* SS */
4107 case 0xee ... 0xf3: /* SS */
4108 case 0xf8 ... 0xfd: /* SS */
4109 op2 = 0;
4110 break;
4111 default:
4112 op2 = (insn << 40) >> 56;
4113 break;
4114 }
4115
4116 memset(f, 0, sizeof(*f));
4117 f->op = op;
4118 f->op2 = op2;
4119
4120 /* Lookup the instruction. */
4121 info = lookup_opc(op << 8 | op2);
4122
4123 /* If we found it, extract the operands. */
4124 if (info != NULL) {
4125 DisasFormat fmt = info->fmt;
4126 int i;
4127
4128 for (i = 0; i < NUM_C_FIELD; ++i) {
4129 extract_field(f, &format_info[fmt].op[i], insn);
4130 }
4131 }
4132 return info;
4133}
4134
4135static ExitStatus translate_one(CPUS390XState *env, DisasContext *s)
4136{
4137 const DisasInsn *insn;
4138 ExitStatus ret = NO_EXIT;
4139 DisasFields f;
4140 DisasOps o;
4141
4142 insn = extract_insn(env, s, &f);
e023e832 4143
ad044d09
RH
4144 /* If not found, try the old interpreter. This includes ILLOPC. */
4145 if (insn == NULL) {
4146 disas_s390_insn(env, s);
4147 switch (s->is_jmp) {
4148 case DISAS_NEXT:
4149 ret = NO_EXIT;
4150 break;
4151 case DISAS_TB_JUMP:
4152 ret = EXIT_GOTO_TB;
4153 break;
4154 case DISAS_JUMP:
4155 ret = EXIT_PC_UPDATED;
4156 break;
4157 case DISAS_EXCP:
4158 ret = EXIT_NORETURN;
4159 break;
4160 default:
4161 abort();
4162 }
4163
4164 s->pc = s->next_pc;
4165 return ret;
4166 }
4167
4168 /* Set up the strutures we use to communicate with the helpers. */
4169 s->insn = insn;
4170 s->fields = &f;
4171 o.g_out = o.g_out2 = o.g_in1 = o.g_in2 = false;
4172 TCGV_UNUSED_I64(o.out);
4173 TCGV_UNUSED_I64(o.out2);
4174 TCGV_UNUSED_I64(o.in1);
4175 TCGV_UNUSED_I64(o.in2);
4176 TCGV_UNUSED_I64(o.addr1);
4177
4178 /* Implement the instruction. */
4179 if (insn->help_in1) {
4180 insn->help_in1(s, &f, &o);
4181 }
4182 if (insn->help_in2) {
4183 insn->help_in2(s, &f, &o);
4184 }
4185 if (insn->help_prep) {
4186 insn->help_prep(s, &f, &o);
4187 }
4188 if (insn->help_op) {
4189 ret = insn->help_op(s, &o);
4190 }
4191 if (insn->help_wout) {
4192 insn->help_wout(s, &f, &o);
4193 }
4194 if (insn->help_cout) {
4195 insn->help_cout(s, &o);
4196 }
4197
4198 /* Free any temporaries created by the helpers. */
4199 if (!TCGV_IS_UNUSED_I64(o.out) && !o.g_out) {
4200 tcg_temp_free_i64(o.out);
4201 }
4202 if (!TCGV_IS_UNUSED_I64(o.out2) && !o.g_out2) {
4203 tcg_temp_free_i64(o.out2);
4204 }
4205 if (!TCGV_IS_UNUSED_I64(o.in1) && !o.g_in1) {
4206 tcg_temp_free_i64(o.in1);
4207 }
4208 if (!TCGV_IS_UNUSED_I64(o.in2) && !o.g_in2) {
4209 tcg_temp_free_i64(o.in2);
4210 }
4211 if (!TCGV_IS_UNUSED_I64(o.addr1)) {
4212 tcg_temp_free_i64(o.addr1);
4213 }
4214
4215 /* Advance to the next instruction. */
4216 s->pc = s->next_pc;
4217 return ret;
e023e832
AG
4218}
4219
a4e3ad19 4220static inline void gen_intermediate_code_internal(CPUS390XState *env,
e023e832
AG
4221 TranslationBlock *tb,
4222 int search_pc)
4223{
4224 DisasContext dc;
4225 target_ulong pc_start;
4226 uint64_t next_page_start;
4227 uint16_t *gen_opc_end;
4228 int j, lj = -1;
4229 int num_insns, max_insns;
4230 CPUBreakpoint *bp;
ad044d09 4231 ExitStatus status;
d5a103cd 4232 bool do_debug;
e023e832
AG
4233
4234 pc_start = tb->pc;
4235
4236 /* 31-bit mode */
4237 if (!(tb->flags & FLAG_MASK_64)) {
4238 pc_start &= 0x7fffffff;
4239 }
4240
e023e832 4241 dc.tb = tb;
ad044d09 4242 dc.pc = pc_start;
e023e832 4243 dc.cc_op = CC_OP_DYNAMIC;
d5a103cd 4244 do_debug = dc.singlestep_enabled = env->singlestep_enabled;
ad044d09 4245 dc.is_jmp = DISAS_NEXT;
e023e832 4246
92414b31 4247 gen_opc_end = tcg_ctx.gen_opc_buf + OPC_MAX_SIZE;
e023e832
AG
4248
4249 next_page_start = (pc_start & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE;
4250
4251 num_insns = 0;
4252 max_insns = tb->cflags & CF_COUNT_MASK;
4253 if (max_insns == 0) {
4254 max_insns = CF_COUNT_MASK;
4255 }
4256
4257 gen_icount_start();
4258
4259 do {
e023e832 4260 if (search_pc) {
92414b31 4261 j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf;
e023e832
AG
4262 if (lj < j) {
4263 lj++;
4264 while (lj < j) {
ab1103de 4265 tcg_ctx.gen_opc_instr_start[lj++] = 0;
e023e832
AG
4266 }
4267 }
25983cad 4268 tcg_ctx.gen_opc_pc[lj] = dc.pc;
e023e832 4269 gen_opc_cc_op[lj] = dc.cc_op;
ab1103de 4270 tcg_ctx.gen_opc_instr_start[lj] = 1;
c9c99c22 4271 tcg_ctx.gen_opc_icount[lj] = num_insns;
e023e832 4272 }
ad044d09 4273 if (++num_insns == max_insns && (tb->cflags & CF_LAST_IO)) {
e023e832
AG
4274 gen_io_start();
4275 }
7193b5f6
RH
4276
4277 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP | CPU_LOG_TB_OP_OPT))) {
4278 tcg_gen_debug_insn_start(dc.pc);
4279 }
4280
d5a103cd
RH
4281 status = NO_EXIT;
4282 if (unlikely(!QTAILQ_EMPTY(&env->breakpoints))) {
4283 QTAILQ_FOREACH(bp, &env->breakpoints, entry) {
4284 if (bp->pc == dc.pc) {
4285 status = EXIT_PC_STALE;
4286 do_debug = true;
4287 break;
4288 }
4289 }
4290 }
4291 if (status == NO_EXIT) {
4292 status = translate_one(env, &dc);
4293 }
ad044d09
RH
4294
4295 /* If we reach a page boundary, are single stepping,
4296 or exhaust instruction count, stop generation. */
4297 if (status == NO_EXIT
4298 && (dc.pc >= next_page_start
4299 || tcg_ctx.gen_opc_ptr >= gen_opc_end
4300 || num_insns >= max_insns
4301 || singlestep
4302 || env->singlestep_enabled)) {
4303 status = EXIT_PC_STALE;
e023e832 4304 }
ad044d09 4305 } while (status == NO_EXIT);
e023e832
AG
4306
4307 if (tb->cflags & CF_LAST_IO) {
4308 gen_io_end();
4309 }
ad044d09
RH
4310
4311 switch (status) {
4312 case EXIT_GOTO_TB:
4313 case EXIT_NORETURN:
4314 break;
4315 case EXIT_PC_STALE:
4316 update_psw_addr(&dc);
4317 /* FALLTHRU */
4318 case EXIT_PC_UPDATED:
4319 if (singlestep && dc.cc_op != CC_OP_DYNAMIC) {
4320 gen_op_calc_cc(&dc);
4321 } else {
4322 /* Next TB starts off with CC_OP_DYNAMIC,
4323 so make sure the cc op type is in env */
4324 gen_op_set_cc_op(&dc);
4325 }
d5a103cd
RH
4326 if (do_debug) {
4327 gen_exception(EXCP_DEBUG);
ad044d09
RH
4328 } else {
4329 /* Generate the return instruction */
4330 tcg_gen_exit_tb(0);
4331 }
4332 break;
4333 default:
4334 abort();
e023e832 4335 }
ad044d09 4336
e023e832 4337 gen_icount_end(tb, num_insns);
efd7f486 4338 *tcg_ctx.gen_opc_ptr = INDEX_op_end;
e023e832 4339 if (search_pc) {
92414b31 4340 j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf;
e023e832
AG
4341 lj++;
4342 while (lj <= j) {
ab1103de 4343 tcg_ctx.gen_opc_instr_start[lj++] = 0;
e023e832
AG
4344 }
4345 } else {
4346 tb->size = dc.pc - pc_start;
4347 tb->icount = num_insns;
4348 }
ad044d09 4349
e023e832 4350#if defined(S390X_DEBUG_DISAS)
e023e832
AG
4351 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
4352 qemu_log("IN: %s\n", lookup_symbol(pc_start));
f4359b9f 4353 log_target_disas(env, pc_start, dc.pc - pc_start, 1);
e023e832
AG
4354 qemu_log("\n");
4355 }
4356#endif
4357}
4358
a4e3ad19 4359void gen_intermediate_code (CPUS390XState *env, struct TranslationBlock *tb)
e023e832
AG
4360{
4361 gen_intermediate_code_internal(env, tb, 0);
4362}
4363
a4e3ad19 4364void gen_intermediate_code_pc (CPUS390XState *env, struct TranslationBlock *tb)
e023e832
AG
4365{
4366 gen_intermediate_code_internal(env, tb, 1);
4367}
4368
a4e3ad19 4369void restore_state_to_opc(CPUS390XState *env, TranslationBlock *tb, int pc_pos)
e023e832
AG
4370{
4371 int cc_op;
25983cad 4372 env->psw.addr = tcg_ctx.gen_opc_pc[pc_pos];
e023e832
AG
4373 cc_op = gen_opc_cc_op[pc_pos];
4374 if ((cc_op != CC_OP_DYNAMIC) && (cc_op != CC_OP_STATIC)) {
4375 env->cc_op = cc_op;
4376 }
10ec5117 4377}