4 * Copyright (c) 2009 Ulrich Hecht
5 * Copyright (c) 2010 Alexander Graf
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
21 /* #define DEBUG_INLINE_BRANCHES */
22 #define S390X_DEBUG_DISAS
23 /* #define S390X_DEBUG_DISAS_VERBOSE */
25 #ifdef S390X_DEBUG_DISAS_VERBOSE
26 # define LOG_DISAS(...) qemu_log(__VA_ARGS__)
28 # define LOG_DISAS(...) do { } while (0)
32 #include "disas/disas.h"
35 #include "qemu/host-utils.h"
37 /* global register indexes */
38 static TCGv_ptr cpu_env;
40 #include "exec/gen-icount.h"
46 /* Information that (most) every instruction needs to manipulate. */
47 typedef struct DisasContext DisasContext;
48 typedef struct DisasInsn DisasInsn;
49 typedef struct DisasFields DisasFields;
52 struct TranslationBlock *tb;
53 const DisasInsn *insn;
57 bool singlestep_enabled;
60 /* Information carried about a condition to be evaluated. */
67 struct { TCGv_i64 a, b; } s64;
68 struct { TCGv_i32 a, b; } s32;
74 #ifdef DEBUG_INLINE_BRANCHES
75 static uint64_t inline_branch_hit[CC_OP_MAX];
76 static uint64_t inline_branch_miss[CC_OP_MAX];
79 static uint64_t pc_to_link_info(DisasContext *s, uint64_t pc)
81 if (!(s->tb->flags & FLAG_MASK_64)) {
82 if (s->tb->flags & FLAG_MASK_32) {
83 return pc | 0x80000000;
89 void cpu_dump_state(CPUS390XState *env, FILE *f, fprintf_function cpu_fprintf,
95 cpu_fprintf(f, "PSW=mask %016" PRIx64 " addr %016" PRIx64 " cc %15s\n",
96 env->psw.mask, env->psw.addr, cc_name(env->cc_op));
98 cpu_fprintf(f, "PSW=mask %016" PRIx64 " addr %016" PRIx64 " cc %02x\n",
99 env->psw.mask, env->psw.addr, env->cc_op);
102 for (i = 0; i < 16; i++) {
103 cpu_fprintf(f, "R%02d=%016" PRIx64, i, env->regs[i]);
105 cpu_fprintf(f, "\n");
111 for (i = 0; i < 16; i++) {
112 cpu_fprintf(f, "F%02d=%016" PRIx64, i, env->fregs[i].ll);
114 cpu_fprintf(f, "\n");
120 #ifndef CONFIG_USER_ONLY
121 for (i = 0; i < 16; i++) {
122 cpu_fprintf(f, "C%02d=%016" PRIx64, i, env->cregs[i]);
124 cpu_fprintf(f, "\n");
131 #ifdef DEBUG_INLINE_BRANCHES
132 for (i = 0; i < CC_OP_MAX; i++) {
133 cpu_fprintf(f, " %15s = %10ld\t%10ld\n", cc_name(i),
134 inline_branch_miss[i], inline_branch_hit[i]);
138 cpu_fprintf(f, "\n");
141 static TCGv_i64 psw_addr;
142 static TCGv_i64 psw_mask;
144 static TCGv_i32 cc_op;
145 static TCGv_i64 cc_src;
146 static TCGv_i64 cc_dst;
147 static TCGv_i64 cc_vr;
149 static char cpu_reg_names[32][4];
150 static TCGv_i64 regs[16];
151 static TCGv_i64 fregs[16];
153 static uint8_t gen_opc_cc_op[OPC_BUF_SIZE];
155 void s390x_translate_init(void)
159 cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
160 psw_addr = tcg_global_mem_new_i64(TCG_AREG0,
161 offsetof(CPUS390XState, psw.addr),
163 psw_mask = tcg_global_mem_new_i64(TCG_AREG0,
164 offsetof(CPUS390XState, psw.mask),
167 cc_op = tcg_global_mem_new_i32(TCG_AREG0, offsetof(CPUS390XState, cc_op),
169 cc_src = tcg_global_mem_new_i64(TCG_AREG0, offsetof(CPUS390XState, cc_src),
171 cc_dst = tcg_global_mem_new_i64(TCG_AREG0, offsetof(CPUS390XState, cc_dst),
173 cc_vr = tcg_global_mem_new_i64(TCG_AREG0, offsetof(CPUS390XState, cc_vr),
176 for (i = 0; i < 16; i++) {
177 snprintf(cpu_reg_names[i], sizeof(cpu_reg_names[0]), "r%d", i);
178 regs[i] = tcg_global_mem_new(TCG_AREG0,
179 offsetof(CPUS390XState, regs[i]),
183 for (i = 0; i < 16; i++) {
184 snprintf(cpu_reg_names[i + 16], sizeof(cpu_reg_names[0]), "f%d", i);
185 fregs[i] = tcg_global_mem_new(TCG_AREG0,
186 offsetof(CPUS390XState, fregs[i].d),
187 cpu_reg_names[i + 16]);
190 /* register helpers */
195 static TCGv_i64 load_reg(int reg)
197 TCGv_i64 r = tcg_temp_new_i64();
198 tcg_gen_mov_i64(r, regs[reg]);
202 static TCGv_i64 load_freg32_i64(int reg)
204 TCGv_i64 r = tcg_temp_new_i64();
205 tcg_gen_shri_i64(r, fregs[reg], 32);
209 static void store_reg(int reg, TCGv_i64 v)
211 tcg_gen_mov_i64(regs[reg], v);
214 static void store_freg(int reg, TCGv_i64 v)
216 tcg_gen_mov_i64(fregs[reg], v);
219 static void store_reg32_i64(int reg, TCGv_i64 v)
221 /* 32 bit register writes keep the upper half */
222 tcg_gen_deposit_i64(regs[reg], regs[reg], v, 0, 32);
225 static void store_reg32h_i64(int reg, TCGv_i64 v)
227 tcg_gen_deposit_i64(regs[reg], regs[reg], v, 32, 32);
230 static void store_freg32_i64(int reg, TCGv_i64 v)
232 tcg_gen_deposit_i64(fregs[reg], fregs[reg], v, 32, 32);
235 static void return_low128(TCGv_i64 dest)
237 tcg_gen_ld_i64(dest, cpu_env, offsetof(CPUS390XState, retxl));
240 static void update_psw_addr(DisasContext *s)
243 tcg_gen_movi_i64(psw_addr, s->pc);
246 static void update_cc_op(DisasContext *s)
248 if (s->cc_op != CC_OP_DYNAMIC && s->cc_op != CC_OP_STATIC) {
249 tcg_gen_movi_i32(cc_op, s->cc_op);
253 static void potential_page_fault(DisasContext *s)
259 static inline uint64_t ld_code2(CPUS390XState *env, uint64_t pc)
261 return (uint64_t)cpu_lduw_code(env, pc);
264 static inline uint64_t ld_code4(CPUS390XState *env, uint64_t pc)
266 return (uint64_t)(uint32_t)cpu_ldl_code(env, pc);
269 static inline uint64_t ld_code6(CPUS390XState *env, uint64_t pc)
271 return (ld_code2(env, pc) << 32) | ld_code4(env, pc + 2);
274 static int get_mem_index(DisasContext *s)
276 switch (s->tb->flags & FLAG_MASK_ASC) {
277 case PSW_ASC_PRIMARY >> 32:
279 case PSW_ASC_SECONDARY >> 32:
281 case PSW_ASC_HOME >> 32:
289 static void gen_exception(int excp)
291 TCGv_i32 tmp = tcg_const_i32(excp);
292 gen_helper_exception(cpu_env, tmp);
293 tcg_temp_free_i32(tmp);
296 static void gen_program_exception(DisasContext *s, int code)
300 /* Remember what pgm exeption this was. */
301 tmp = tcg_const_i32(code);
302 tcg_gen_st_i32(tmp, cpu_env, offsetof(CPUS390XState, int_pgm_code));
303 tcg_temp_free_i32(tmp);
305 tmp = tcg_const_i32(s->next_pc - s->pc);
306 tcg_gen_st_i32(tmp, cpu_env, offsetof(CPUS390XState, int_pgm_ilen));
307 tcg_temp_free_i32(tmp);
309 /* Advance past instruction. */
316 /* Trigger exception. */
317 gen_exception(EXCP_PGM);
320 static inline void gen_illegal_opcode(DisasContext *s)
322 gen_program_exception(s, PGM_SPECIFICATION);
325 static inline void check_privileged(DisasContext *s)
327 if (s->tb->flags & (PSW_MASK_PSTATE >> 32)) {
328 gen_program_exception(s, PGM_PRIVILEGED);
332 static TCGv_i64 get_address(DisasContext *s, int x2, int b2, int d2)
336 /* 31-bitify the immediate part; register contents are dealt with below */
337 if (!(s->tb->flags & FLAG_MASK_64)) {
343 tmp = tcg_const_i64(d2);
344 tcg_gen_add_i64(tmp, tmp, regs[x2]);
349 tcg_gen_add_i64(tmp, tmp, regs[b2]);
353 tmp = tcg_const_i64(d2);
354 tcg_gen_add_i64(tmp, tmp, regs[b2]);
359 tmp = tcg_const_i64(d2);
362 /* 31-bit mode mask if there are values loaded from registers */
363 if (!(s->tb->flags & FLAG_MASK_64) && (x2 || b2)) {
364 tcg_gen_andi_i64(tmp, tmp, 0x7fffffffUL);
370 static inline void gen_op_movi_cc(DisasContext *s, uint32_t val)
372 s->cc_op = CC_OP_CONST0 + val;
375 static void gen_op_update1_cc_i64(DisasContext *s, enum cc_op op, TCGv_i64 dst)
377 tcg_gen_discard_i64(cc_src);
378 tcg_gen_mov_i64(cc_dst, dst);
379 tcg_gen_discard_i64(cc_vr);
383 static void gen_op_update2_cc_i64(DisasContext *s, enum cc_op op, TCGv_i64 src,
386 tcg_gen_mov_i64(cc_src, src);
387 tcg_gen_mov_i64(cc_dst, dst);
388 tcg_gen_discard_i64(cc_vr);
392 static void gen_op_update3_cc_i64(DisasContext *s, enum cc_op op, TCGv_i64 src,
393 TCGv_i64 dst, TCGv_i64 vr)
395 tcg_gen_mov_i64(cc_src, src);
396 tcg_gen_mov_i64(cc_dst, dst);
397 tcg_gen_mov_i64(cc_vr, vr);
401 static void set_cc_nz_u64(DisasContext *s, TCGv_i64 val)
403 gen_op_update1_cc_i64(s, CC_OP_NZ, val);
406 static void gen_set_cc_nz_f32(DisasContext *s, TCGv_i64 val)
408 gen_op_update1_cc_i64(s, CC_OP_NZ_F32, val);
411 static void gen_set_cc_nz_f64(DisasContext *s, TCGv_i64 val)
413 gen_op_update1_cc_i64(s, CC_OP_NZ_F64, val);
416 static void gen_set_cc_nz_f128(DisasContext *s, TCGv_i64 vh, TCGv_i64 vl)
418 gen_op_update2_cc_i64(s, CC_OP_NZ_F128, vh, vl);
421 /* CC value is in env->cc_op */
422 static void set_cc_static(DisasContext *s)
424 tcg_gen_discard_i64(cc_src);
425 tcg_gen_discard_i64(cc_dst);
426 tcg_gen_discard_i64(cc_vr);
427 s->cc_op = CC_OP_STATIC;
430 /* calculates cc into cc_op */
431 static void gen_op_calc_cc(DisasContext *s)
433 TCGv_i32 local_cc_op;
436 TCGV_UNUSED_I32(local_cc_op);
437 TCGV_UNUSED_I64(dummy);
440 dummy = tcg_const_i64(0);
454 local_cc_op = tcg_const_i32(s->cc_op);
470 /* s->cc_op is the cc value */
471 tcg_gen_movi_i32(cc_op, s->cc_op - CC_OP_CONST0);
474 /* env->cc_op already is the cc value */
489 gen_helper_calc_cc(cc_op, cpu_env, local_cc_op, dummy, cc_dst, dummy);
494 case CC_OP_LTUGTU_32:
495 case CC_OP_LTUGTU_64:
502 gen_helper_calc_cc(cc_op, cpu_env, local_cc_op, cc_src, cc_dst, dummy);
517 gen_helper_calc_cc(cc_op, cpu_env, local_cc_op, cc_src, cc_dst, cc_vr);
520 /* unknown operation - assume 3 arguments and cc_op in env */
521 gen_helper_calc_cc(cc_op, cpu_env, cc_op, cc_src, cc_dst, cc_vr);
527 if (!TCGV_IS_UNUSED_I32(local_cc_op)) {
528 tcg_temp_free_i32(local_cc_op);
530 if (!TCGV_IS_UNUSED_I64(dummy)) {
531 tcg_temp_free_i64(dummy);
534 /* We now have cc in cc_op as constant */
538 static int use_goto_tb(DisasContext *s, uint64_t dest)
540 /* NOTE: we handle the case where the TB spans two pages here */
541 return (((dest & TARGET_PAGE_MASK) == (s->tb->pc & TARGET_PAGE_MASK)
542 || (dest & TARGET_PAGE_MASK) == ((s->pc - 1) & TARGET_PAGE_MASK))
543 && !s->singlestep_enabled
544 && !(s->tb->cflags & CF_LAST_IO));
547 static void account_noninline_branch(DisasContext *s, int cc_op)
549 #ifdef DEBUG_INLINE_BRANCHES
550 inline_branch_miss[cc_op]++;
554 static void account_inline_branch(DisasContext *s, int cc_op)
556 #ifdef DEBUG_INLINE_BRANCHES
557 inline_branch_hit[cc_op]++;
561 /* Table of mask values to comparison codes, given a comparison as input.
562 For a true comparison CC=3 will never be set, but we treat this
563 conservatively for possible use when CC=3 indicates overflow. */
564 static const TCGCond ltgt_cond[16] = {
565 TCG_COND_NEVER, TCG_COND_NEVER, /* | | | x */
566 TCG_COND_GT, TCG_COND_NEVER, /* | | GT | x */
567 TCG_COND_LT, TCG_COND_NEVER, /* | LT | | x */
568 TCG_COND_NE, TCG_COND_NEVER, /* | LT | GT | x */
569 TCG_COND_EQ, TCG_COND_NEVER, /* EQ | | | x */
570 TCG_COND_GE, TCG_COND_NEVER, /* EQ | | GT | x */
571 TCG_COND_LE, TCG_COND_NEVER, /* EQ | LT | | x */
572 TCG_COND_ALWAYS, TCG_COND_ALWAYS, /* EQ | LT | GT | x */
575 /* Table of mask values to comparison codes, given a logic op as input.
576 For such, only CC=0 and CC=1 should be possible. */
577 static const TCGCond nz_cond[16] = {
579 TCG_COND_NEVER, TCG_COND_NEVER, TCG_COND_NEVER, TCG_COND_NEVER,
581 TCG_COND_NE, TCG_COND_NE, TCG_COND_NE, TCG_COND_NE,
583 TCG_COND_EQ, TCG_COND_EQ, TCG_COND_EQ, TCG_COND_EQ,
584 /* EQ | NE | x | x */
585 TCG_COND_ALWAYS, TCG_COND_ALWAYS, TCG_COND_ALWAYS, TCG_COND_ALWAYS,
588 /* Interpret MASK in terms of S->CC_OP, and fill in C with all the
589 details required to generate a TCG comparison. */
590 static void disas_jcc(DisasContext *s, DisasCompare *c, uint32_t mask)
593 enum cc_op old_cc_op = s->cc_op;
595 if (mask == 15 || mask == 0) {
596 c->cond = (mask ? TCG_COND_ALWAYS : TCG_COND_NEVER);
599 c->g1 = c->g2 = true;
604 /* Find the TCG condition for the mask + cc op. */
610 cond = ltgt_cond[mask];
611 if (cond == TCG_COND_NEVER) {
614 account_inline_branch(s, old_cc_op);
617 case CC_OP_LTUGTU_32:
618 case CC_OP_LTUGTU_64:
619 cond = tcg_unsigned_cond(ltgt_cond[mask]);
620 if (cond == TCG_COND_NEVER) {
623 account_inline_branch(s, old_cc_op);
627 cond = nz_cond[mask];
628 if (cond == TCG_COND_NEVER) {
631 account_inline_branch(s, old_cc_op);
646 account_inline_branch(s, old_cc_op);
661 account_inline_branch(s, old_cc_op);
665 switch (mask & 0xa) {
666 case 8: /* src == 0 -> no one bit found */
669 case 2: /* src != 0 -> one bit found */
675 account_inline_branch(s, old_cc_op);
680 /* Calculate cc value. */
685 /* Jump based on CC. We'll load up the real cond below;
686 the assignment here merely avoids a compiler warning. */
687 account_noninline_branch(s, old_cc_op);
688 old_cc_op = CC_OP_STATIC;
689 cond = TCG_COND_NEVER;
693 /* Load up the arguments of the comparison. */
695 c->g1 = c->g2 = false;
699 c->u.s32.a = tcg_temp_new_i32();
700 tcg_gen_trunc_i64_i32(c->u.s32.a, cc_dst);
701 c->u.s32.b = tcg_const_i32(0);
704 case CC_OP_LTUGTU_32:
706 c->u.s32.a = tcg_temp_new_i32();
707 tcg_gen_trunc_i64_i32(c->u.s32.a, cc_src);
708 c->u.s32.b = tcg_temp_new_i32();
709 tcg_gen_trunc_i64_i32(c->u.s32.b, cc_dst);
716 c->u.s64.b = tcg_const_i64(0);
720 case CC_OP_LTUGTU_64:
723 c->g1 = c->g2 = true;
729 c->u.s64.a = tcg_temp_new_i64();
730 c->u.s64.b = tcg_const_i64(0);
731 tcg_gen_and_i64(c->u.s64.a, cc_src, cc_dst);
739 case 0x8 | 0x4 | 0x2: /* cc != 3 */
741 c->u.s32.b = tcg_const_i32(3);
743 case 0x8 | 0x4 | 0x1: /* cc != 2 */
745 c->u.s32.b = tcg_const_i32(2);
747 case 0x8 | 0x2 | 0x1: /* cc != 1 */
749 c->u.s32.b = tcg_const_i32(1);
751 case 0x8 | 0x2: /* cc == 0 ||Â cc == 2 => (cc & 1) == 0 */
754 c->u.s32.a = tcg_temp_new_i32();
755 c->u.s32.b = tcg_const_i32(0);
756 tcg_gen_andi_i32(c->u.s32.a, cc_op, 1);
758 case 0x8 | 0x4: /* cc < 2 */
760 c->u.s32.b = tcg_const_i32(2);
762 case 0x8: /* cc == 0 */
764 c->u.s32.b = tcg_const_i32(0);
766 case 0x4 | 0x2 | 0x1: /* cc != 0 */
768 c->u.s32.b = tcg_const_i32(0);
770 case 0x4 | 0x1: /* cc == 1 ||Â cc == 3 => (cc & 1) != 0 */
773 c->u.s32.a = tcg_temp_new_i32();
774 c->u.s32.b = tcg_const_i32(0);
775 tcg_gen_andi_i32(c->u.s32.a, cc_op, 1);
777 case 0x4: /* cc == 1 */
779 c->u.s32.b = tcg_const_i32(1);
781 case 0x2 | 0x1: /* cc > 1 */
783 c->u.s32.b = tcg_const_i32(1);
785 case 0x2: /* cc == 2 */
787 c->u.s32.b = tcg_const_i32(2);
789 case 0x1: /* cc == 3 */
791 c->u.s32.b = tcg_const_i32(3);
794 /* CC is masked by something else: (8 >> cc) & mask. */
797 c->u.s32.a = tcg_const_i32(8);
798 c->u.s32.b = tcg_const_i32(0);
799 tcg_gen_shr_i32(c->u.s32.a, c->u.s32.a, cc_op);
800 tcg_gen_andi_i32(c->u.s32.a, c->u.s32.a, mask);
811 static void free_compare(DisasCompare *c)
815 tcg_temp_free_i64(c->u.s64.a);
817 tcg_temp_free_i32(c->u.s32.a);
822 tcg_temp_free_i64(c->u.s64.b);
824 tcg_temp_free_i32(c->u.s32.b);
829 /* ====================================================================== */
830 /* Define the insn format enumeration. */
831 #define F0(N) FMT_##N,
832 #define F1(N, X1) F0(N)
833 #define F2(N, X1, X2) F0(N)
834 #define F3(N, X1, X2, X3) F0(N)
835 #define F4(N, X1, X2, X3, X4) F0(N)
836 #define F5(N, X1, X2, X3, X4, X5) F0(N)
839 #include "insn-format.def"
849 /* Define a structure to hold the decoded fields. We'll store each inside
850 an array indexed by an enum. In order to conserve memory, we'll arrange
851 for fields that do not exist at the same time to overlap, thus the "C"
852 for compact. For checking purposes there is an "O" for original index
853 as well that will be applied to availability bitmaps. */
855 enum DisasFieldIndexO {
878 enum DisasFieldIndexC {
912 unsigned presentC:16;
913 unsigned int presentO;
917 /* This is the way fields are to be accessed out of DisasFields. */
918 #define have_field(S, F) have_field1((S), FLD_O_##F)
919 #define get_field(S, F) get_field1((S), FLD_O_##F, FLD_C_##F)
921 static bool have_field1(const DisasFields *f, enum DisasFieldIndexO c)
923 return (f->presentO >> c) & 1;
926 static int get_field1(const DisasFields *f, enum DisasFieldIndexO o,
927 enum DisasFieldIndexC c)
929 assert(have_field1(f, o));
933 /* Describe the layout of each field in each format. */
934 typedef struct DisasField {
938 unsigned int indexC:6;
939 enum DisasFieldIndexO indexO:8;
942 typedef struct DisasFormatInfo {
943 DisasField op[NUM_C_FIELD];
946 #define R(N, B) { B, 4, 0, FLD_C_r##N, FLD_O_r##N }
947 #define M(N, B) { B, 4, 0, FLD_C_m##N, FLD_O_m##N }
948 #define BD(N, BB, BD) { BB, 4, 0, FLD_C_b##N, FLD_O_b##N }, \
949 { BD, 12, 0, FLD_C_d##N, FLD_O_d##N }
950 #define BXD(N) { 16, 4, 0, FLD_C_b##N, FLD_O_b##N }, \
951 { 12, 4, 0, FLD_C_x##N, FLD_O_x##N }, \
952 { 20, 12, 0, FLD_C_d##N, FLD_O_d##N }
953 #define BDL(N) { 16, 4, 0, FLD_C_b##N, FLD_O_b##N }, \
954 { 20, 20, 2, FLD_C_d##N, FLD_O_d##N }
955 #define BXDL(N) { 16, 4, 0, FLD_C_b##N, FLD_O_b##N }, \
956 { 12, 4, 0, FLD_C_x##N, FLD_O_x##N }, \
957 { 20, 20, 2, FLD_C_d##N, FLD_O_d##N }
958 #define I(N, B, S) { B, S, 1, FLD_C_i##N, FLD_O_i##N }
959 #define L(N, B, S) { B, S, 0, FLD_C_l##N, FLD_O_l##N }
961 #define F0(N) { { } },
962 #define F1(N, X1) { { X1 } },
963 #define F2(N, X1, X2) { { X1, X2 } },
964 #define F3(N, X1, X2, X3) { { X1, X2, X3 } },
965 #define F4(N, X1, X2, X3, X4) { { X1, X2, X3, X4 } },
966 #define F5(N, X1, X2, X3, X4, X5) { { X1, X2, X3, X4, X5 } },
968 static const DisasFormatInfo format_info[] = {
969 #include "insn-format.def"
987 /* Generally, we'll extract operands into this structures, operate upon
988 them, and store them back. See the "in1", "in2", "prep", "wout" sets
989 of routines below for more details. */
991 bool g_out, g_out2, g_in1, g_in2;
992 TCGv_i64 out, out2, in1, in2;
996 /* Instructions can place constraints on their operands, raising specification
997 exceptions if they are violated. To make this easy to automate, each "in1",
998 "in2", "prep", "wout" helper will have a SPEC_<name> define that equals one
999 of the following, or 0. To make this easy to document, we'll put the
1000 SPEC_<name> defines next to <name>. */
1002 #define SPEC_r1_even 1
1003 #define SPEC_r2_even 2
1004 #define SPEC_r1_f128 4
1005 #define SPEC_r2_f128 8
1007 /* Return values from translate_one, indicating the state of the TB. */
1009 /* Continue the TB. */
1011 /* We have emitted one or more goto_tb. No fixup required. */
1013 /* We are not using a goto_tb (for whatever reason), but have updated
1014 the PC (for whatever reason), so there's no need to do it again on
1017 /* We are exiting the TB, but have neither emitted a goto_tb, nor
1018 updated the PC for the next instruction to be executed. */
1020 /* We are ending the TB with a noreturn function call, e.g. longjmp.
1021 No following code will be executed. */
1025 typedef enum DisasFacility {
1026 FAC_Z, /* zarch (default) */
1027 FAC_CASS, /* compare and swap and store */
1028 FAC_CASS2, /* compare and swap and store 2*/
1029 FAC_DFP, /* decimal floating point */
1030 FAC_DFPR, /* decimal floating point rounding */
1031 FAC_DO, /* distinct operands */
1032 FAC_EE, /* execute extensions */
1033 FAC_EI, /* extended immediate */
1034 FAC_FPE, /* floating point extension */
1035 FAC_FPSSH, /* floating point support sign handling */
1036 FAC_FPRGR, /* FPR-GR transfer */
1037 FAC_GIE, /* general instructions extension */
1038 FAC_HFP_MA, /* HFP multiply-and-add/subtract */
1039 FAC_HW, /* high-word */
1040 FAC_IEEEE_SIM, /* IEEE exception sumilation */
1041 FAC_LOC, /* load/store on condition */
1042 FAC_LD, /* long displacement */
1043 FAC_PC, /* population count */
1044 FAC_SCF, /* store clock fast */
1045 FAC_SFLE, /* store facility list extended */
1051 DisasFacility fac:6;
1056 void (*help_in1)(DisasContext *, DisasFields *, DisasOps *);
1057 void (*help_in2)(DisasContext *, DisasFields *, DisasOps *);
1058 void (*help_prep)(DisasContext *, DisasFields *, DisasOps *);
1059 void (*help_wout)(DisasContext *, DisasFields *, DisasOps *);
1060 void (*help_cout)(DisasContext *, DisasOps *);
1061 ExitStatus (*help_op)(DisasContext *, DisasOps *);
1066 /* ====================================================================== */
1067 /* Miscelaneous helpers, used by several operations. */
1069 static void help_l2_shift(DisasContext *s, DisasFields *f,
1070 DisasOps *o, int mask)
1072 int b2 = get_field(f, b2);
1073 int d2 = get_field(f, d2);
1076 o->in2 = tcg_const_i64(d2 & mask);
1078 o->in2 = get_address(s, 0, b2, d2);
1079 tcg_gen_andi_i64(o->in2, o->in2, mask);
1083 static ExitStatus help_goto_direct(DisasContext *s, uint64_t dest)
1085 if (dest == s->next_pc) {
1088 if (use_goto_tb(s, dest)) {
1091 tcg_gen_movi_i64(psw_addr, dest);
1092 tcg_gen_exit_tb((tcg_target_long)s->tb);
1093 return EXIT_GOTO_TB;
1095 tcg_gen_movi_i64(psw_addr, dest);
1096 return EXIT_PC_UPDATED;
1100 static ExitStatus help_branch(DisasContext *s, DisasCompare *c,
1101 bool is_imm, int imm, TCGv_i64 cdest)
1104 uint64_t dest = s->pc + 2 * imm;
1107 /* Take care of the special cases first. */
1108 if (c->cond == TCG_COND_NEVER) {
1113 if (dest == s->next_pc) {
1114 /* Branch to next. */
1118 if (c->cond == TCG_COND_ALWAYS) {
1119 ret = help_goto_direct(s, dest);
1123 if (TCGV_IS_UNUSED_I64(cdest)) {
1124 /* E.g. bcr %r0 -> no branch. */
1128 if (c->cond == TCG_COND_ALWAYS) {
1129 tcg_gen_mov_i64(psw_addr, cdest);
1130 ret = EXIT_PC_UPDATED;
1135 if (use_goto_tb(s, s->next_pc)) {
1136 if (is_imm && use_goto_tb(s, dest)) {
1137 /* Both exits can use goto_tb. */
1140 lab = gen_new_label();
1142 tcg_gen_brcond_i64(c->cond, c->u.s64.a, c->u.s64.b, lab);
1144 tcg_gen_brcond_i32(c->cond, c->u.s32.a, c->u.s32.b, lab);
1147 /* Branch not taken. */
1149 tcg_gen_movi_i64(psw_addr, s->next_pc);
1150 tcg_gen_exit_tb((tcg_target_long)s->tb + 0);
1155 tcg_gen_movi_i64(psw_addr, dest);
1156 tcg_gen_exit_tb((tcg_target_long)s->tb + 1);
1160 /* Fallthru can use goto_tb, but taken branch cannot. */
1161 /* Store taken branch destination before the brcond. This
1162 avoids having to allocate a new local temp to hold it.
1163 We'll overwrite this in the not taken case anyway. */
1165 tcg_gen_mov_i64(psw_addr, cdest);
1168 lab = gen_new_label();
1170 tcg_gen_brcond_i64(c->cond, c->u.s64.a, c->u.s64.b, lab);
1172 tcg_gen_brcond_i32(c->cond, c->u.s32.a, c->u.s32.b, lab);
1175 /* Branch not taken. */
1178 tcg_gen_movi_i64(psw_addr, s->next_pc);
1179 tcg_gen_exit_tb((tcg_target_long)s->tb + 0);
1183 tcg_gen_movi_i64(psw_addr, dest);
1185 ret = EXIT_PC_UPDATED;
1188 /* Fallthru cannot use goto_tb. This by itself is vanishingly rare.
1189 Most commonly we're single-stepping or some other condition that
1190 disables all use of goto_tb. Just update the PC and exit. */
1192 TCGv_i64 next = tcg_const_i64(s->next_pc);
1194 cdest = tcg_const_i64(dest);
1198 tcg_gen_movcond_i64(c->cond, psw_addr, c->u.s64.a, c->u.s64.b,
1201 TCGv_i32 t0 = tcg_temp_new_i32();
1202 TCGv_i64 t1 = tcg_temp_new_i64();
1203 TCGv_i64 z = tcg_const_i64(0);
1204 tcg_gen_setcond_i32(c->cond, t0, c->u.s32.a, c->u.s32.b);
1205 tcg_gen_extu_i32_i64(t1, t0);
1206 tcg_temp_free_i32(t0);
1207 tcg_gen_movcond_i64(TCG_COND_NE, psw_addr, t1, z, cdest, next);
1208 tcg_temp_free_i64(t1);
1209 tcg_temp_free_i64(z);
1213 tcg_temp_free_i64(cdest);
1215 tcg_temp_free_i64(next);
1217 ret = EXIT_PC_UPDATED;
1225 /* ====================================================================== */
1226 /* The operations. These perform the bulk of the work for any insn,
1227 usually after the operands have been loaded and output initialized. */
1229 static ExitStatus op_abs(DisasContext *s, DisasOps *o)
1231 gen_helper_abs_i64(o->out, o->in2);
1235 static ExitStatus op_absf32(DisasContext *s, DisasOps *o)
1237 tcg_gen_andi_i64(o->out, o->in2, 0x7fffffffull);
1241 static ExitStatus op_absf64(DisasContext *s, DisasOps *o)
1243 tcg_gen_andi_i64(o->out, o->in2, 0x7fffffffffffffffull);
1247 static ExitStatus op_absf128(DisasContext *s, DisasOps *o)
1249 tcg_gen_andi_i64(o->out, o->in1, 0x7fffffffffffffffull);
1250 tcg_gen_mov_i64(o->out2, o->in2);
1254 static ExitStatus op_add(DisasContext *s, DisasOps *o)
1256 tcg_gen_add_i64(o->out, o->in1, o->in2);
1260 static ExitStatus op_addc(DisasContext *s, DisasOps *o)
1264 tcg_gen_add_i64(o->out, o->in1, o->in2);
1266 /* XXX possible optimization point */
1268 cc = tcg_temp_new_i64();
1269 tcg_gen_extu_i32_i64(cc, cc_op);
1270 tcg_gen_shri_i64(cc, cc, 1);
1272 tcg_gen_add_i64(o->out, o->out, cc);
1273 tcg_temp_free_i64(cc);
1277 static ExitStatus op_aeb(DisasContext *s, DisasOps *o)
1279 gen_helper_aeb(o->out, cpu_env, o->in1, o->in2);
1283 static ExitStatus op_adb(DisasContext *s, DisasOps *o)
1285 gen_helper_adb(o->out, cpu_env, o->in1, o->in2);
1289 static ExitStatus op_axb(DisasContext *s, DisasOps *o)
1291 gen_helper_axb(o->out, cpu_env, o->out, o->out2, o->in1, o->in2);
1292 return_low128(o->out2);
1296 static ExitStatus op_and(DisasContext *s, DisasOps *o)
1298 tcg_gen_and_i64(o->out, o->in1, o->in2);
1302 static ExitStatus op_andi(DisasContext *s, DisasOps *o)
1304 int shift = s->insn->data & 0xff;
1305 int size = s->insn->data >> 8;
1306 uint64_t mask = ((1ull << size) - 1) << shift;
1309 tcg_gen_shli_i64(o->in2, o->in2, shift);
1310 tcg_gen_ori_i64(o->in2, o->in2, ~mask);
1311 tcg_gen_and_i64(o->out, o->in1, o->in2);
1313 /* Produce the CC from only the bits manipulated. */
1314 tcg_gen_andi_i64(cc_dst, o->out, mask);
1315 set_cc_nz_u64(s, cc_dst);
1319 static ExitStatus op_bas(DisasContext *s, DisasOps *o)
1321 tcg_gen_movi_i64(o->out, pc_to_link_info(s, s->next_pc));
1322 if (!TCGV_IS_UNUSED_I64(o->in2)) {
1323 tcg_gen_mov_i64(psw_addr, o->in2);
1324 return EXIT_PC_UPDATED;
1330 static ExitStatus op_basi(DisasContext *s, DisasOps *o)
1332 tcg_gen_movi_i64(o->out, pc_to_link_info(s, s->next_pc));
1333 return help_goto_direct(s, s->pc + 2 * get_field(s->fields, i2));
1336 static ExitStatus op_bc(DisasContext *s, DisasOps *o)
1338 int m1 = get_field(s->fields, m1);
1339 bool is_imm = have_field(s->fields, i2);
1340 int imm = is_imm ? get_field(s->fields, i2) : 0;
1343 disas_jcc(s, &c, m1);
1344 return help_branch(s, &c, is_imm, imm, o->in2);
1347 static ExitStatus op_bct32(DisasContext *s, DisasOps *o)
1349 int r1 = get_field(s->fields, r1);
1350 bool is_imm = have_field(s->fields, i2);
1351 int imm = is_imm ? get_field(s->fields, i2) : 0;
1355 c.cond = TCG_COND_NE;
1360 t = tcg_temp_new_i64();
1361 tcg_gen_subi_i64(t, regs[r1], 1);
1362 store_reg32_i64(r1, t);
1363 c.u.s32.a = tcg_temp_new_i32();
1364 c.u.s32.b = tcg_const_i32(0);
1365 tcg_gen_trunc_i64_i32(c.u.s32.a, t);
1366 tcg_temp_free_i64(t);
1368 return help_branch(s, &c, is_imm, imm, o->in2);
1371 static ExitStatus op_bct64(DisasContext *s, DisasOps *o)
1373 int r1 = get_field(s->fields, r1);
1374 bool is_imm = have_field(s->fields, i2);
1375 int imm = is_imm ? get_field(s->fields, i2) : 0;
1378 c.cond = TCG_COND_NE;
1383 tcg_gen_subi_i64(regs[r1], regs[r1], 1);
1384 c.u.s64.a = regs[r1];
1385 c.u.s64.b = tcg_const_i64(0);
1387 return help_branch(s, &c, is_imm, imm, o->in2);
1390 static ExitStatus op_bx32(DisasContext *s, DisasOps *o)
1392 int r1 = get_field(s->fields, r1);
1393 int r3 = get_field(s->fields, r3);
1394 bool is_imm = have_field(s->fields, i2);
1395 int imm = is_imm ? get_field(s->fields, i2) : 0;
1399 c.cond = (s->insn->data ? TCG_COND_LE : TCG_COND_GT);
1404 t = tcg_temp_new_i64();
1405 tcg_gen_add_i64(t, regs[r1], regs[r3]);
1406 c.u.s32.a = tcg_temp_new_i32();
1407 c.u.s32.b = tcg_temp_new_i32();
1408 tcg_gen_trunc_i64_i32(c.u.s32.a, t);
1409 tcg_gen_trunc_i64_i32(c.u.s32.b, regs[r3 | 1]);
1410 store_reg32_i64(r1, t);
1411 tcg_temp_free_i64(t);
1413 return help_branch(s, &c, is_imm, imm, o->in2);
1416 static ExitStatus op_bx64(DisasContext *s, DisasOps *o)
1418 int r1 = get_field(s->fields, r1);
1419 int r3 = get_field(s->fields, r3);
1420 bool is_imm = have_field(s->fields, i2);
1421 int imm = is_imm ? get_field(s->fields, i2) : 0;
1424 c.cond = (s->insn->data ? TCG_COND_LE : TCG_COND_GT);
1427 if (r1 == (r3 | 1)) {
1428 c.u.s64.b = load_reg(r3 | 1);
1431 c.u.s64.b = regs[r3 | 1];
1435 tcg_gen_add_i64(regs[r1], regs[r1], regs[r3]);
1436 c.u.s64.a = regs[r1];
1439 return help_branch(s, &c, is_imm, imm, o->in2);
1442 static ExitStatus op_cj(DisasContext *s, DisasOps *o)
1444 int imm, m3 = get_field(s->fields, m3);
1448 /* Bit 3 of the m3 field is reserved and should be zero.
1449 Choose to ignore it wrt the ltgt_cond table above. */
1450 c.cond = ltgt_cond[m3 & 14];
1451 if (s->insn->data) {
1452 c.cond = tcg_unsigned_cond(c.cond);
1454 c.is_64 = c.g1 = c.g2 = true;
1458 is_imm = have_field(s->fields, i4);
1460 imm = get_field(s->fields, i4);
1463 o->out = get_address(s, 0, get_field(s->fields, b4),
1464 get_field(s->fields, d4));
1467 return help_branch(s, &c, is_imm, imm, o->out);
1470 static ExitStatus op_ceb(DisasContext *s, DisasOps *o)
1472 gen_helper_ceb(cc_op, cpu_env, o->in1, o->in2);
1477 static ExitStatus op_cdb(DisasContext *s, DisasOps *o)
1479 gen_helper_cdb(cc_op, cpu_env, o->in1, o->in2);
1484 static ExitStatus op_cxb(DisasContext *s, DisasOps *o)
1486 gen_helper_cxb(cc_op, cpu_env, o->out, o->out2, o->in1, o->in2);
1491 static ExitStatus op_cfeb(DisasContext *s, DisasOps *o)
1493 TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
1494 gen_helper_cfeb(o->out, cpu_env, o->in2, m3);
1495 tcg_temp_free_i32(m3);
1496 gen_set_cc_nz_f32(s, o->in2);
1500 static ExitStatus op_cfdb(DisasContext *s, DisasOps *o)
1502 TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
1503 gen_helper_cfdb(o->out, cpu_env, o->in2, m3);
1504 tcg_temp_free_i32(m3);
1505 gen_set_cc_nz_f64(s, o->in2);
1509 static ExitStatus op_cfxb(DisasContext *s, DisasOps *o)
1511 TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
1512 gen_helper_cfxb(o->out, cpu_env, o->in1, o->in2, m3);
1513 tcg_temp_free_i32(m3);
1514 gen_set_cc_nz_f128(s, o->in1, o->in2);
1518 static ExitStatus op_cgeb(DisasContext *s, DisasOps *o)
1520 TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
1521 gen_helper_cgeb(o->out, cpu_env, o->in2, m3);
1522 tcg_temp_free_i32(m3);
1523 gen_set_cc_nz_f32(s, o->in2);
1527 static ExitStatus op_cgdb(DisasContext *s, DisasOps *o)
1529 TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
1530 gen_helper_cgdb(o->out, cpu_env, o->in2, m3);
1531 tcg_temp_free_i32(m3);
1532 gen_set_cc_nz_f64(s, o->in2);
1536 static ExitStatus op_cgxb(DisasContext *s, DisasOps *o)
1538 TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
1539 gen_helper_cgxb(o->out, cpu_env, o->in1, o->in2, m3);
1540 tcg_temp_free_i32(m3);
1541 gen_set_cc_nz_f128(s, o->in1, o->in2);
1545 static ExitStatus op_clfeb(DisasContext *s, DisasOps *o)
1547 TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
1548 gen_helper_clfeb(o->out, cpu_env, o->in2, m3);
1549 tcg_temp_free_i32(m3);
1550 gen_set_cc_nz_f32(s, o->in2);
1554 static ExitStatus op_clfdb(DisasContext *s, DisasOps *o)
1556 TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
1557 gen_helper_clfdb(o->out, cpu_env, o->in2, m3);
1558 tcg_temp_free_i32(m3);
1559 gen_set_cc_nz_f64(s, o->in2);
1563 static ExitStatus op_clfxb(DisasContext *s, DisasOps *o)
1565 TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
1566 gen_helper_clfxb(o->out, cpu_env, o->in1, o->in2, m3);
1567 tcg_temp_free_i32(m3);
1568 gen_set_cc_nz_f128(s, o->in1, o->in2);
1572 static ExitStatus op_clgeb(DisasContext *s, DisasOps *o)
1574 TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
1575 gen_helper_clgeb(o->out, cpu_env, o->in2, m3);
1576 tcg_temp_free_i32(m3);
1577 gen_set_cc_nz_f32(s, o->in2);
1581 static ExitStatus op_clgdb(DisasContext *s, DisasOps *o)
1583 TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
1584 gen_helper_clgdb(o->out, cpu_env, o->in2, m3);
1585 tcg_temp_free_i32(m3);
1586 gen_set_cc_nz_f64(s, o->in2);
1590 static ExitStatus op_clgxb(DisasContext *s, DisasOps *o)
1592 TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
1593 gen_helper_clgxb(o->out, cpu_env, o->in1, o->in2, m3);
1594 tcg_temp_free_i32(m3);
1595 gen_set_cc_nz_f128(s, o->in1, o->in2);
1599 static ExitStatus op_cegb(DisasContext *s, DisasOps *o)
1601 TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
1602 gen_helper_cegb(o->out, cpu_env, o->in2, m3);
1603 tcg_temp_free_i32(m3);
1607 static ExitStatus op_cdgb(DisasContext *s, DisasOps *o)
1609 TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
1610 gen_helper_cdgb(o->out, cpu_env, o->in2, m3);
1611 tcg_temp_free_i32(m3);
1615 static ExitStatus op_cxgb(DisasContext *s, DisasOps *o)
1617 TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
1618 gen_helper_cxgb(o->out, cpu_env, o->in2, m3);
1619 tcg_temp_free_i32(m3);
1620 return_low128(o->out2);
1624 static ExitStatus op_celgb(DisasContext *s, DisasOps *o)
1626 TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
1627 gen_helper_celgb(o->out, cpu_env, o->in2, m3);
1628 tcg_temp_free_i32(m3);
1632 static ExitStatus op_cdlgb(DisasContext *s, DisasOps *o)
1634 TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
1635 gen_helper_cdlgb(o->out, cpu_env, o->in2, m3);
1636 tcg_temp_free_i32(m3);
1640 static ExitStatus op_cxlgb(DisasContext *s, DisasOps *o)
1642 TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
1643 gen_helper_cxlgb(o->out, cpu_env, o->in2, m3);
1644 tcg_temp_free_i32(m3);
1645 return_low128(o->out2);
1649 static ExitStatus op_cksm(DisasContext *s, DisasOps *o)
1651 int r2 = get_field(s->fields, r2);
1652 TCGv_i64 len = tcg_temp_new_i64();
1654 potential_page_fault(s);
1655 gen_helper_cksm(len, cpu_env, o->in1, o->in2, regs[r2 + 1]);
1657 return_low128(o->out);
1659 tcg_gen_add_i64(regs[r2], regs[r2], len);
1660 tcg_gen_sub_i64(regs[r2 + 1], regs[r2 + 1], len);
1661 tcg_temp_free_i64(len);
1666 static ExitStatus op_clc(DisasContext *s, DisasOps *o)
1668 int l = get_field(s->fields, l1);
1673 tcg_gen_qemu_ld8u(cc_src, o->addr1, get_mem_index(s));
1674 tcg_gen_qemu_ld8u(cc_dst, o->in2, get_mem_index(s));
1677 tcg_gen_qemu_ld16u(cc_src, o->addr1, get_mem_index(s));
1678 tcg_gen_qemu_ld16u(cc_dst, o->in2, get_mem_index(s));
1681 tcg_gen_qemu_ld32u(cc_src, o->addr1, get_mem_index(s));
1682 tcg_gen_qemu_ld32u(cc_dst, o->in2, get_mem_index(s));
1685 tcg_gen_qemu_ld64(cc_src, o->addr1, get_mem_index(s));
1686 tcg_gen_qemu_ld64(cc_dst, o->in2, get_mem_index(s));
1689 potential_page_fault(s);
1690 vl = tcg_const_i32(l);
1691 gen_helper_clc(cc_op, cpu_env, vl, o->addr1, o->in2);
1692 tcg_temp_free_i32(vl);
1696 gen_op_update2_cc_i64(s, CC_OP_LTUGTU_64, cc_src, cc_dst);
1700 static ExitStatus op_clcle(DisasContext *s, DisasOps *o)
1702 TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
1703 TCGv_i32 r3 = tcg_const_i32(get_field(s->fields, r3));
1704 potential_page_fault(s);
1705 gen_helper_clcle(cc_op, cpu_env, r1, o->in2, r3);
1706 tcg_temp_free_i32(r1);
1707 tcg_temp_free_i32(r3);
1712 static ExitStatus op_clm(DisasContext *s, DisasOps *o)
1714 TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
1715 TCGv_i32 t1 = tcg_temp_new_i32();
1716 tcg_gen_trunc_i64_i32(t1, o->in1);
1717 potential_page_fault(s);
1718 gen_helper_clm(cc_op, cpu_env, t1, m3, o->in2);
1720 tcg_temp_free_i32(t1);
1721 tcg_temp_free_i32(m3);
1725 static ExitStatus op_clst(DisasContext *s, DisasOps *o)
1727 potential_page_fault(s);
1728 gen_helper_clst(o->in1, cpu_env, regs[0], o->in1, o->in2);
1730 return_low128(o->in2);
1734 static ExitStatus op_cps(DisasContext *s, DisasOps *o)
1736 TCGv_i64 t = tcg_temp_new_i64();
1737 tcg_gen_andi_i64(t, o->in1, 0x8000000000000000ull);
1738 tcg_gen_andi_i64(o->out, o->in2, 0x7fffffffffffffffull);
1739 tcg_gen_or_i64(o->out, o->out, t);
1740 tcg_temp_free_i64(t);
1744 static ExitStatus op_cs(DisasContext *s, DisasOps *o)
1746 int r3 = get_field(s->fields, r3);
1747 potential_page_fault(s);
1748 gen_helper_cs(o->out, cpu_env, o->in1, o->in2, regs[r3]);
1753 static ExitStatus op_csg(DisasContext *s, DisasOps *o)
1755 int r3 = get_field(s->fields, r3);
1756 potential_page_fault(s);
1757 gen_helper_csg(o->out, cpu_env, o->in1, o->in2, regs[r3]);
1762 #ifndef CONFIG_USER_ONLY
1763 static ExitStatus op_csp(DisasContext *s, DisasOps *o)
1765 TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
1766 check_privileged(s);
1767 gen_helper_csp(cc_op, cpu_env, r1, o->in2);
1768 tcg_temp_free_i32(r1);
1774 static ExitStatus op_cds(DisasContext *s, DisasOps *o)
1776 int r3 = get_field(s->fields, r3);
1777 TCGv_i64 in3 = tcg_temp_new_i64();
1778 tcg_gen_deposit_i64(in3, regs[r3 + 1], regs[r3], 32, 32);
1779 potential_page_fault(s);
1780 gen_helper_csg(o->out, cpu_env, o->in1, o->in2, in3);
1781 tcg_temp_free_i64(in3);
1786 static ExitStatus op_cdsg(DisasContext *s, DisasOps *o)
1788 TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
1789 TCGv_i32 r3 = tcg_const_i32(get_field(s->fields, r3));
1790 potential_page_fault(s);
1791 /* XXX rewrite in tcg */
1792 gen_helper_cdsg(cc_op, cpu_env, r1, o->in2, r3);
1797 static ExitStatus op_cvd(DisasContext *s, DisasOps *o)
1799 TCGv_i64 t1 = tcg_temp_new_i64();
1800 TCGv_i32 t2 = tcg_temp_new_i32();
1801 tcg_gen_trunc_i64_i32(t2, o->in1);
1802 gen_helper_cvd(t1, t2);
1803 tcg_temp_free_i32(t2);
1804 tcg_gen_qemu_st64(t1, o->in2, get_mem_index(s));
1805 tcg_temp_free_i64(t1);
1809 static ExitStatus op_ct(DisasContext *s, DisasOps *o)
1811 int m3 = get_field(s->fields, m3);
1812 int lab = gen_new_label();
1816 /* Bit 3 of the m3 field is reserved and should be zero.
1817 Choose to ignore it wrt the ltgt_cond table above. */
1818 c = tcg_invert_cond(ltgt_cond[m3 & 14]);
1819 if (s->insn->data) {
1820 c = tcg_unsigned_cond(c);
1822 tcg_gen_brcond_i64(c, o->in1, o->in2, lab);
1824 /* Set DXC to 0xff. */
1825 t = tcg_temp_new_i32();
1826 tcg_gen_ld_i32(t, cpu_env, offsetof(CPUS390XState, fpc));
1827 tcg_gen_ori_i32(t, t, 0xff00);
1828 tcg_gen_st_i32(t, cpu_env, offsetof(CPUS390XState, fpc));
1829 tcg_temp_free_i32(t);
1832 gen_program_exception(s, PGM_DATA);
1838 #ifndef CONFIG_USER_ONLY
1839 static ExitStatus op_diag(DisasContext *s, DisasOps *o)
1843 check_privileged(s);
1844 potential_page_fault(s);
1846 /* We pretend the format is RX_a so that D2 is the field we want. */
1847 tmp = tcg_const_i32(get_field(s->fields, d2) & 0xfff);
1848 gen_helper_diag(regs[2], cpu_env, tmp, regs[2], regs[1]);
1849 tcg_temp_free_i32(tmp);
1854 static ExitStatus op_divs32(DisasContext *s, DisasOps *o)
1856 gen_helper_divs32(o->out2, cpu_env, o->in1, o->in2);
1857 return_low128(o->out);
1861 static ExitStatus op_divu32(DisasContext *s, DisasOps *o)
1863 gen_helper_divu32(o->out2, cpu_env, o->in1, o->in2);
1864 return_low128(o->out);
1868 static ExitStatus op_divs64(DisasContext *s, DisasOps *o)
1870 gen_helper_divs64(o->out2, cpu_env, o->in1, o->in2);
1871 return_low128(o->out);
1875 static ExitStatus op_divu64(DisasContext *s, DisasOps *o)
1877 gen_helper_divu64(o->out2, cpu_env, o->out, o->out2, o->in2);
1878 return_low128(o->out);
1882 static ExitStatus op_deb(DisasContext *s, DisasOps *o)
1884 gen_helper_deb(o->out, cpu_env, o->in1, o->in2);
1888 static ExitStatus op_ddb(DisasContext *s, DisasOps *o)
1890 gen_helper_ddb(o->out, cpu_env, o->in1, o->in2);
1894 static ExitStatus op_dxb(DisasContext *s, DisasOps *o)
1896 gen_helper_dxb(o->out, cpu_env, o->out, o->out2, o->in1, o->in2);
1897 return_low128(o->out2);
1901 static ExitStatus op_ear(DisasContext *s, DisasOps *o)
1903 int r2 = get_field(s->fields, r2);
1904 tcg_gen_ld32u_i64(o->out, cpu_env, offsetof(CPUS390XState, aregs[r2]));
1908 static ExitStatus op_efpc(DisasContext *s, DisasOps *o)
1910 tcg_gen_ld32u_i64(o->out, cpu_env, offsetof(CPUS390XState, fpc));
1914 static ExitStatus op_ex(DisasContext *s, DisasOps *o)
1916 /* ??? Perhaps a better way to implement EXECUTE is to set a bit in
1917 tb->flags, (ab)use the tb->cs_base field as the address of
1918 the template in memory, and grab 8 bits of tb->flags/cflags for
1919 the contents of the register. We would then recognize all this
1920 in gen_intermediate_code_internal, generating code for exactly
1921 one instruction. This new TB then gets executed normally.
1923 On the other hand, this seems to be mostly used for modifying
1924 MVC inside of memcpy, which needs a helper call anyway. So
1925 perhaps this doesn't bear thinking about any further. */
1932 tmp = tcg_const_i64(s->next_pc);
1933 gen_helper_ex(cc_op, cpu_env, cc_op, o->in1, o->in2, tmp);
1934 tcg_temp_free_i64(tmp);
1940 static ExitStatus op_flogr(DisasContext *s, DisasOps *o)
1942 /* We'll use the original input for cc computation, since we get to
1943 compare that against 0, which ought to be better than comparing
1944 the real output against 64. It also lets cc_dst be a convenient
1945 temporary during our computation. */
1946 gen_op_update1_cc_i64(s, CC_OP_FLOGR, o->in2);
1948 /* R1 = IN ? CLZ(IN) : 64. */
1949 gen_helper_clz(o->out, o->in2);
1951 /* R1+1 = IN & ~(found bit). Note that we may attempt to shift this
1952 value by 64, which is undefined. But since the shift is 64 iff the
1953 input is zero, we still get the correct result after and'ing. */
1954 tcg_gen_movi_i64(o->out2, 0x8000000000000000ull);
1955 tcg_gen_shr_i64(o->out2, o->out2, o->out);
1956 tcg_gen_andc_i64(o->out2, cc_dst, o->out2);
1960 static ExitStatus op_icm(DisasContext *s, DisasOps *o)
1962 int m3 = get_field(s->fields, m3);
1963 int pos, len, base = s->insn->data;
1964 TCGv_i64 tmp = tcg_temp_new_i64();
1969 /* Effectively a 32-bit load. */
1970 tcg_gen_qemu_ld32u(tmp, o->in2, get_mem_index(s));
1977 /* Effectively a 16-bit load. */
1978 tcg_gen_qemu_ld16u(tmp, o->in2, get_mem_index(s));
1986 /* Effectively an 8-bit load. */
1987 tcg_gen_qemu_ld8u(tmp, o->in2, get_mem_index(s));
1992 pos = base + ctz32(m3) * 8;
1993 tcg_gen_deposit_i64(o->out, o->out, tmp, pos, len);
1994 ccm = ((1ull << len) - 1) << pos;
1998 /* This is going to be a sequence of loads and inserts. */
1999 pos = base + 32 - 8;
2003 tcg_gen_qemu_ld8u(tmp, o->in2, get_mem_index(s));
2004 tcg_gen_addi_i64(o->in2, o->in2, 1);
2005 tcg_gen_deposit_i64(o->out, o->out, tmp, pos, 8);
2008 m3 = (m3 << 1) & 0xf;
2014 tcg_gen_movi_i64(tmp, ccm);
2015 gen_op_update2_cc_i64(s, CC_OP_ICM, tmp, o->out);
2016 tcg_temp_free_i64(tmp);
2020 static ExitStatus op_insi(DisasContext *s, DisasOps *o)
2022 int shift = s->insn->data & 0xff;
2023 int size = s->insn->data >> 8;
2024 tcg_gen_deposit_i64(o->out, o->in1, o->in2, shift, size);
2028 static ExitStatus op_ipm(DisasContext *s, DisasOps *o)
2033 tcg_gen_andi_i64(o->out, o->out, ~0xff000000ull);
2035 t1 = tcg_temp_new_i64();
2036 tcg_gen_shli_i64(t1, psw_mask, 20);
2037 tcg_gen_shri_i64(t1, t1, 36);
2038 tcg_gen_or_i64(o->out, o->out, t1);
2040 tcg_gen_extu_i32_i64(t1, cc_op);
2041 tcg_gen_shli_i64(t1, t1, 28);
2042 tcg_gen_or_i64(o->out, o->out, t1);
2043 tcg_temp_free_i64(t1);
2047 #ifndef CONFIG_USER_ONLY
2048 static ExitStatus op_ipte(DisasContext *s, DisasOps *o)
2050 check_privileged(s);
2051 gen_helper_ipte(cpu_env, o->in1, o->in2);
2055 static ExitStatus op_iske(DisasContext *s, DisasOps *o)
2057 check_privileged(s);
2058 gen_helper_iske(o->out, cpu_env, o->in2);
2063 static ExitStatus op_ldeb(DisasContext *s, DisasOps *o)
2065 gen_helper_ldeb(o->out, cpu_env, o->in2);
2069 static ExitStatus op_ledb(DisasContext *s, DisasOps *o)
2071 gen_helper_ledb(o->out, cpu_env, o->in2);
2075 static ExitStatus op_ldxb(DisasContext *s, DisasOps *o)
2077 gen_helper_ldxb(o->out, cpu_env, o->in1, o->in2);
2081 static ExitStatus op_lexb(DisasContext *s, DisasOps *o)
2083 gen_helper_lexb(o->out, cpu_env, o->in1, o->in2);
2087 static ExitStatus op_lxdb(DisasContext *s, DisasOps *o)
2089 gen_helper_lxdb(o->out, cpu_env, o->in2);
2090 return_low128(o->out2);
2094 static ExitStatus op_lxeb(DisasContext *s, DisasOps *o)
2096 gen_helper_lxeb(o->out, cpu_env, o->in2);
2097 return_low128(o->out2);
2101 static ExitStatus op_llgt(DisasContext *s, DisasOps *o)
2103 tcg_gen_andi_i64(o->out, o->in2, 0x7fffffff);
2107 static ExitStatus op_ld8s(DisasContext *s, DisasOps *o)
2109 tcg_gen_qemu_ld8s(o->out, o->in2, get_mem_index(s));
2113 static ExitStatus op_ld8u(DisasContext *s, DisasOps *o)
2115 tcg_gen_qemu_ld8u(o->out, o->in2, get_mem_index(s));
2119 static ExitStatus op_ld16s(DisasContext *s, DisasOps *o)
2121 tcg_gen_qemu_ld16s(o->out, o->in2, get_mem_index(s));
2125 static ExitStatus op_ld16u(DisasContext *s, DisasOps *o)
2127 tcg_gen_qemu_ld16u(o->out, o->in2, get_mem_index(s));
2131 static ExitStatus op_ld32s(DisasContext *s, DisasOps *o)
2133 tcg_gen_qemu_ld32s(o->out, o->in2, get_mem_index(s));
2137 static ExitStatus op_ld32u(DisasContext *s, DisasOps *o)
2139 tcg_gen_qemu_ld32u(o->out, o->in2, get_mem_index(s));
2143 static ExitStatus op_ld64(DisasContext *s, DisasOps *o)
2145 tcg_gen_qemu_ld64(o->out, o->in2, get_mem_index(s));
2149 static ExitStatus op_loc(DisasContext *s, DisasOps *o)
2153 disas_jcc(s, &c, get_field(s->fields, m3));
2156 tcg_gen_movcond_i64(c.cond, o->out, c.u.s64.a, c.u.s64.b,
2160 TCGv_i32 t32 = tcg_temp_new_i32();
2163 tcg_gen_setcond_i32(c.cond, t32, c.u.s32.a, c.u.s32.b);
2166 t = tcg_temp_new_i64();
2167 tcg_gen_extu_i32_i64(t, t32);
2168 tcg_temp_free_i32(t32);
2170 z = tcg_const_i64(0);
2171 tcg_gen_movcond_i64(TCG_COND_NE, o->out, t, z, o->in2, o->in1);
2172 tcg_temp_free_i64(t);
2173 tcg_temp_free_i64(z);
2179 #ifndef CONFIG_USER_ONLY
2180 static ExitStatus op_lctl(DisasContext *s, DisasOps *o)
2182 TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
2183 TCGv_i32 r3 = tcg_const_i32(get_field(s->fields, r3));
2184 check_privileged(s);
2185 potential_page_fault(s);
2186 gen_helper_lctl(cpu_env, r1, o->in2, r3);
2187 tcg_temp_free_i32(r1);
2188 tcg_temp_free_i32(r3);
2192 static ExitStatus op_lctlg(DisasContext *s, DisasOps *o)
2194 TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
2195 TCGv_i32 r3 = tcg_const_i32(get_field(s->fields, r3));
2196 check_privileged(s);
2197 potential_page_fault(s);
2198 gen_helper_lctlg(cpu_env, r1, o->in2, r3);
2199 tcg_temp_free_i32(r1);
2200 tcg_temp_free_i32(r3);
2203 static ExitStatus op_lra(DisasContext *s, DisasOps *o)
2205 check_privileged(s);
2206 potential_page_fault(s);
2207 gen_helper_lra(o->out, cpu_env, o->in2);
2212 static ExitStatus op_lpsw(DisasContext *s, DisasOps *o)
2216 check_privileged(s);
2218 t1 = tcg_temp_new_i64();
2219 t2 = tcg_temp_new_i64();
2220 tcg_gen_qemu_ld32u(t1, o->in2, get_mem_index(s));
2221 tcg_gen_addi_i64(o->in2, o->in2, 4);
2222 tcg_gen_qemu_ld32u(t2, o->in2, get_mem_index(s));
2223 /* Convert the 32-bit PSW_MASK into the 64-bit PSW_MASK. */
2224 tcg_gen_shli_i64(t1, t1, 32);
2225 gen_helper_load_psw(cpu_env, t1, t2);
2226 tcg_temp_free_i64(t1);
2227 tcg_temp_free_i64(t2);
2228 return EXIT_NORETURN;
2231 static ExitStatus op_lpswe(DisasContext *s, DisasOps *o)
2235 check_privileged(s);
2237 t1 = tcg_temp_new_i64();
2238 t2 = tcg_temp_new_i64();
2239 tcg_gen_qemu_ld64(t1, o->in2, get_mem_index(s));
2240 tcg_gen_addi_i64(o->in2, o->in2, 8);
2241 tcg_gen_qemu_ld64(t2, o->in2, get_mem_index(s));
2242 gen_helper_load_psw(cpu_env, t1, t2);
2243 tcg_temp_free_i64(t1);
2244 tcg_temp_free_i64(t2);
2245 return EXIT_NORETURN;
2249 static ExitStatus op_lam(DisasContext *s, DisasOps *o)
2251 TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
2252 TCGv_i32 r3 = tcg_const_i32(get_field(s->fields, r3));
2253 potential_page_fault(s);
2254 gen_helper_lam(cpu_env, r1, o->in2, r3);
2255 tcg_temp_free_i32(r1);
2256 tcg_temp_free_i32(r3);
2260 static ExitStatus op_lm32(DisasContext *s, DisasOps *o)
2262 int r1 = get_field(s->fields, r1);
2263 int r3 = get_field(s->fields, r3);
2264 TCGv_i64 t = tcg_temp_new_i64();
2265 TCGv_i64 t4 = tcg_const_i64(4);
2268 tcg_gen_qemu_ld32u(t, o->in2, get_mem_index(s));
2269 store_reg32_i64(r1, t);
2273 tcg_gen_add_i64(o->in2, o->in2, t4);
2277 tcg_temp_free_i64(t);
2278 tcg_temp_free_i64(t4);
2282 static ExitStatus op_lmh(DisasContext *s, DisasOps *o)
2284 int r1 = get_field(s->fields, r1);
2285 int r3 = get_field(s->fields, r3);
2286 TCGv_i64 t = tcg_temp_new_i64();
2287 TCGv_i64 t4 = tcg_const_i64(4);
2290 tcg_gen_qemu_ld32u(t, o->in2, get_mem_index(s));
2291 store_reg32h_i64(r1, t);
2295 tcg_gen_add_i64(o->in2, o->in2, t4);
2299 tcg_temp_free_i64(t);
2300 tcg_temp_free_i64(t4);
2304 static ExitStatus op_lm64(DisasContext *s, DisasOps *o)
2306 int r1 = get_field(s->fields, r1);
2307 int r3 = get_field(s->fields, r3);
2308 TCGv_i64 t8 = tcg_const_i64(8);
2311 tcg_gen_qemu_ld64(regs[r1], o->in2, get_mem_index(s));
2315 tcg_gen_add_i64(o->in2, o->in2, t8);
2319 tcg_temp_free_i64(t8);
2323 static ExitStatus op_mov2(DisasContext *s, DisasOps *o)
2326 o->g_out = o->g_in2;
2327 TCGV_UNUSED_I64(o->in2);
2332 static ExitStatus op_movx(DisasContext *s, DisasOps *o)
2336 o->g_out = o->g_in1;
2337 o->g_out2 = o->g_in2;
2338 TCGV_UNUSED_I64(o->in1);
2339 TCGV_UNUSED_I64(o->in2);
2340 o->g_in1 = o->g_in2 = false;
2344 static ExitStatus op_mvc(DisasContext *s, DisasOps *o)
2346 TCGv_i32 l = tcg_const_i32(get_field(s->fields, l1));
2347 potential_page_fault(s);
2348 gen_helper_mvc(cpu_env, l, o->addr1, o->in2);
2349 tcg_temp_free_i32(l);
2353 static ExitStatus op_mvcl(DisasContext *s, DisasOps *o)
2355 TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
2356 TCGv_i32 r2 = tcg_const_i32(get_field(s->fields, r2));
2357 potential_page_fault(s);
2358 gen_helper_mvcl(cc_op, cpu_env, r1, r2);
2359 tcg_temp_free_i32(r1);
2360 tcg_temp_free_i32(r2);
2365 static ExitStatus op_mvcle(DisasContext *s, DisasOps *o)
2367 TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
2368 TCGv_i32 r3 = tcg_const_i32(get_field(s->fields, r3));
2369 potential_page_fault(s);
2370 gen_helper_mvcle(cc_op, cpu_env, r1, o->in2, r3);
2371 tcg_temp_free_i32(r1);
2372 tcg_temp_free_i32(r3);
2377 #ifndef CONFIG_USER_ONLY
2378 static ExitStatus op_mvcp(DisasContext *s, DisasOps *o)
2380 int r1 = get_field(s->fields, l1);
2381 check_privileged(s);
2382 potential_page_fault(s);
2383 gen_helper_mvcp(cc_op, cpu_env, regs[r1], o->addr1, o->in2);
2388 static ExitStatus op_mvcs(DisasContext *s, DisasOps *o)
2390 int r1 = get_field(s->fields, l1);
2391 check_privileged(s);
2392 potential_page_fault(s);
2393 gen_helper_mvcs(cc_op, cpu_env, regs[r1], o->addr1, o->in2);
2399 static ExitStatus op_mvpg(DisasContext *s, DisasOps *o)
2401 potential_page_fault(s);
2402 gen_helper_mvpg(cpu_env, regs[0], o->in1, o->in2);
2407 static ExitStatus op_mvst(DisasContext *s, DisasOps *o)
2409 potential_page_fault(s);
2410 gen_helper_mvst(o->in1, cpu_env, regs[0], o->in1, o->in2);
2412 return_low128(o->in2);
2416 static ExitStatus op_mul(DisasContext *s, DisasOps *o)
2418 tcg_gen_mul_i64(o->out, o->in1, o->in2);
2422 static ExitStatus op_mul128(DisasContext *s, DisasOps *o)
2424 gen_helper_mul128(o->out, cpu_env, o->in1, o->in2);
2425 return_low128(o->out2);
2429 static ExitStatus op_meeb(DisasContext *s, DisasOps *o)
2431 gen_helper_meeb(o->out, cpu_env, o->in1, o->in2);
2435 static ExitStatus op_mdeb(DisasContext *s, DisasOps *o)
2437 gen_helper_mdeb(o->out, cpu_env, o->in1, o->in2);
2441 static ExitStatus op_mdb(DisasContext *s, DisasOps *o)
2443 gen_helper_mdb(o->out, cpu_env, o->in1, o->in2);
2447 static ExitStatus op_mxb(DisasContext *s, DisasOps *o)
2449 gen_helper_mxb(o->out, cpu_env, o->out, o->out2, o->in1, o->in2);
2450 return_low128(o->out2);
2454 static ExitStatus op_mxdb(DisasContext *s, DisasOps *o)
2456 gen_helper_mxdb(o->out, cpu_env, o->out, o->out2, o->in2);
2457 return_low128(o->out2);
2461 static ExitStatus op_maeb(DisasContext *s, DisasOps *o)
2463 TCGv_i64 r3 = load_freg32_i64(get_field(s->fields, r3));
2464 gen_helper_maeb(o->out, cpu_env, o->in1, o->in2, r3);
2465 tcg_temp_free_i64(r3);
2469 static ExitStatus op_madb(DisasContext *s, DisasOps *o)
2471 int r3 = get_field(s->fields, r3);
2472 gen_helper_madb(o->out, cpu_env, o->in1, o->in2, fregs[r3]);
2476 static ExitStatus op_mseb(DisasContext *s, DisasOps *o)
2478 TCGv_i64 r3 = load_freg32_i64(get_field(s->fields, r3));
2479 gen_helper_mseb(o->out, cpu_env, o->in1, o->in2, r3);
2480 tcg_temp_free_i64(r3);
2484 static ExitStatus op_msdb(DisasContext *s, DisasOps *o)
2486 int r3 = get_field(s->fields, r3);
2487 gen_helper_msdb(o->out, cpu_env, o->in1, o->in2, fregs[r3]);
2491 static ExitStatus op_nabs(DisasContext *s, DisasOps *o)
2493 gen_helper_nabs_i64(o->out, o->in2);
2497 static ExitStatus op_nabsf32(DisasContext *s, DisasOps *o)
2499 tcg_gen_ori_i64(o->out, o->in2, 0x80000000ull);
2503 static ExitStatus op_nabsf64(DisasContext *s, DisasOps *o)
2505 tcg_gen_ori_i64(o->out, o->in2, 0x8000000000000000ull);
2509 static ExitStatus op_nabsf128(DisasContext *s, DisasOps *o)
2511 tcg_gen_ori_i64(o->out, o->in1, 0x8000000000000000ull);
2512 tcg_gen_mov_i64(o->out2, o->in2);
2516 static ExitStatus op_nc(DisasContext *s, DisasOps *o)
2518 TCGv_i32 l = tcg_const_i32(get_field(s->fields, l1));
2519 potential_page_fault(s);
2520 gen_helper_nc(cc_op, cpu_env, l, o->addr1, o->in2);
2521 tcg_temp_free_i32(l);
2526 static ExitStatus op_neg(DisasContext *s, DisasOps *o)
2528 tcg_gen_neg_i64(o->out, o->in2);
2532 static ExitStatus op_negf32(DisasContext *s, DisasOps *o)
2534 tcg_gen_xori_i64(o->out, o->in2, 0x80000000ull);
2538 static ExitStatus op_negf64(DisasContext *s, DisasOps *o)
2540 tcg_gen_xori_i64(o->out, o->in2, 0x8000000000000000ull);
2544 static ExitStatus op_negf128(DisasContext *s, DisasOps *o)
2546 tcg_gen_xori_i64(o->out, o->in1, 0x8000000000000000ull);
2547 tcg_gen_mov_i64(o->out2, o->in2);
2551 static ExitStatus op_oc(DisasContext *s, DisasOps *o)
2553 TCGv_i32 l = tcg_const_i32(get_field(s->fields, l1));
2554 potential_page_fault(s);
2555 gen_helper_oc(cc_op, cpu_env, l, o->addr1, o->in2);
2556 tcg_temp_free_i32(l);
2561 static ExitStatus op_or(DisasContext *s, DisasOps *o)
2563 tcg_gen_or_i64(o->out, o->in1, o->in2);
2567 static ExitStatus op_ori(DisasContext *s, DisasOps *o)
2569 int shift = s->insn->data & 0xff;
2570 int size = s->insn->data >> 8;
2571 uint64_t mask = ((1ull << size) - 1) << shift;
2574 tcg_gen_shli_i64(o->in2, o->in2, shift);
2575 tcg_gen_or_i64(o->out, o->in1, o->in2);
2577 /* Produce the CC from only the bits manipulated. */
2578 tcg_gen_andi_i64(cc_dst, o->out, mask);
2579 set_cc_nz_u64(s, cc_dst);
2583 static ExitStatus op_popcnt(DisasContext *s, DisasOps *o)
2585 gen_helper_popcnt(o->out, o->in2);
2589 #ifndef CONFIG_USER_ONLY
2590 static ExitStatus op_ptlb(DisasContext *s, DisasOps *o)
2592 check_privileged(s);
2593 gen_helper_ptlb(cpu_env);
2598 static ExitStatus op_risbg(DisasContext *s, DisasOps *o)
2600 int i3 = get_field(s->fields, i3);
2601 int i4 = get_field(s->fields, i4);
2602 int i5 = get_field(s->fields, i5);
2603 int do_zero = i4 & 0x80;
2604 uint64_t mask, imask, pmask;
2607 /* Adjust the arguments for the specific insn. */
2608 switch (s->fields->op2) {
2609 case 0x55: /* risbg */
2614 case 0x5d: /* risbhg */
2617 pmask = 0xffffffff00000000ull;
2619 case 0x51: /* risblg */
2622 pmask = 0x00000000ffffffffull;
2628 /* MASK is the set of bits to be inserted from R2.
2629 Take care for I3/I4 wraparound. */
2632 mask ^= pmask >> i4 >> 1;
2634 mask |= ~(pmask >> i4 >> 1);
2638 /* IMASK is the set of bits to be kept from R1. In the case of the high/low
2639 insns, we need to keep the other half of the register. */
2640 imask = ~mask | ~pmask;
2642 if (s->fields->op2 == 0x55) {
2649 /* In some cases we can implement this with deposit, which can be more
2650 efficient on some hosts. */
2651 if (~mask == imask && i3 <= i4) {
2652 if (s->fields->op2 == 0x5d) {
2655 /* Note that we rotate the bits to be inserted to the lsb, not to
2656 the position as described in the PoO. */
2659 rot = (i5 - pos) & 63;
2665 /* Rotate the input as necessary. */
2666 tcg_gen_rotli_i64(o->in2, o->in2, rot);
2668 /* Insert the selected bits into the output. */
2670 tcg_gen_deposit_i64(o->out, o->out, o->in2, pos, len);
2671 } else if (imask == 0) {
2672 tcg_gen_andi_i64(o->out, o->in2, mask);
2674 tcg_gen_andi_i64(o->in2, o->in2, mask);
2675 tcg_gen_andi_i64(o->out, o->out, imask);
2676 tcg_gen_or_i64(o->out, o->out, o->in2);
2681 static ExitStatus op_rosbg(DisasContext *s, DisasOps *o)
2683 int i3 = get_field(s->fields, i3);
2684 int i4 = get_field(s->fields, i4);
2685 int i5 = get_field(s->fields, i5);
2688 /* If this is a test-only form, arrange to discard the result. */
2690 o->out = tcg_temp_new_i64();
2698 /* MASK is the set of bits to be operated on from R2.
2699 Take care for I3/I4 wraparound. */
2702 mask ^= ~0ull >> i4 >> 1;
2704 mask |= ~(~0ull >> i4 >> 1);
2707 /* Rotate the input as necessary. */
2708 tcg_gen_rotli_i64(o->in2, o->in2, i5);
2711 switch (s->fields->op2) {
2712 case 0x55: /* AND */
2713 tcg_gen_ori_i64(o->in2, o->in2, ~mask);
2714 tcg_gen_and_i64(o->out, o->out, o->in2);
2717 tcg_gen_andi_i64(o->in2, o->in2, mask);
2718 tcg_gen_or_i64(o->out, o->out, o->in2);
2720 case 0x57: /* XOR */
2721 tcg_gen_andi_i64(o->in2, o->in2, mask);
2722 tcg_gen_xor_i64(o->out, o->out, o->in2);
2729 tcg_gen_andi_i64(cc_dst, o->out, mask);
2730 set_cc_nz_u64(s, cc_dst);
2734 static ExitStatus op_rev16(DisasContext *s, DisasOps *o)
2736 tcg_gen_bswap16_i64(o->out, o->in2);
2740 static ExitStatus op_rev32(DisasContext *s, DisasOps *o)
2742 tcg_gen_bswap32_i64(o->out, o->in2);
2746 static ExitStatus op_rev64(DisasContext *s, DisasOps *o)
2748 tcg_gen_bswap64_i64(o->out, o->in2);
2752 static ExitStatus op_rll32(DisasContext *s, DisasOps *o)
2754 TCGv_i32 t1 = tcg_temp_new_i32();
2755 TCGv_i32 t2 = tcg_temp_new_i32();
2756 TCGv_i32 to = tcg_temp_new_i32();
2757 tcg_gen_trunc_i64_i32(t1, o->in1);
2758 tcg_gen_trunc_i64_i32(t2, o->in2);
2759 tcg_gen_rotl_i32(to, t1, t2);
2760 tcg_gen_extu_i32_i64(o->out, to);
2761 tcg_temp_free_i32(t1);
2762 tcg_temp_free_i32(t2);
2763 tcg_temp_free_i32(to);
2767 static ExitStatus op_rll64(DisasContext *s, DisasOps *o)
2769 tcg_gen_rotl_i64(o->out, o->in1, o->in2);
2773 #ifndef CONFIG_USER_ONLY
2774 static ExitStatus op_rrbe(DisasContext *s, DisasOps *o)
2776 check_privileged(s);
2777 gen_helper_rrbe(cc_op, cpu_env, o->in2);
2782 static ExitStatus op_sacf(DisasContext *s, DisasOps *o)
2784 check_privileged(s);
2785 gen_helper_sacf(cpu_env, o->in2);
2786 /* Addressing mode has changed, so end the block. */
2787 return EXIT_PC_STALE;
2791 static ExitStatus op_sar(DisasContext *s, DisasOps *o)
2793 int r1 = get_field(s->fields, r1);
2794 tcg_gen_st32_i64(o->in2, cpu_env, offsetof(CPUS390XState, aregs[r1]));
2798 static ExitStatus op_seb(DisasContext *s, DisasOps *o)
2800 gen_helper_seb(o->out, cpu_env, o->in1, o->in2);
2804 static ExitStatus op_sdb(DisasContext *s, DisasOps *o)
2806 gen_helper_sdb(o->out, cpu_env, o->in1, o->in2);
2810 static ExitStatus op_sxb(DisasContext *s, DisasOps *o)
2812 gen_helper_sxb(o->out, cpu_env, o->out, o->out2, o->in1, o->in2);
2813 return_low128(o->out2);
2817 static ExitStatus op_sqeb(DisasContext *s, DisasOps *o)
2819 gen_helper_sqeb(o->out, cpu_env, o->in2);
2823 static ExitStatus op_sqdb(DisasContext *s, DisasOps *o)
2825 gen_helper_sqdb(o->out, cpu_env, o->in2);
2829 static ExitStatus op_sqxb(DisasContext *s, DisasOps *o)
2831 gen_helper_sqxb(o->out, cpu_env, o->in1, o->in2);
2832 return_low128(o->out2);
2836 #ifndef CONFIG_USER_ONLY
2837 static ExitStatus op_servc(DisasContext *s, DisasOps *o)
2839 check_privileged(s);
2840 potential_page_fault(s);
2841 gen_helper_servc(cc_op, cpu_env, o->in2, o->in1);
2846 static ExitStatus op_sigp(DisasContext *s, DisasOps *o)
2848 TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
2849 check_privileged(s);
2850 potential_page_fault(s);
2851 gen_helper_sigp(cc_op, cpu_env, o->in2, r1, o->in1);
2852 tcg_temp_free_i32(r1);
2857 static ExitStatus op_soc(DisasContext *s, DisasOps *o)
2863 disas_jcc(s, &c, get_field(s->fields, m3));
2865 lab = gen_new_label();
2867 tcg_gen_brcond_i64(c.cond, c.u.s64.a, c.u.s64.b, lab);
2869 tcg_gen_brcond_i32(c.cond, c.u.s32.a, c.u.s32.b, lab);
2873 r1 = get_field(s->fields, r1);
2874 a = get_address(s, 0, get_field(s->fields, b2), get_field(s->fields, d2));
2875 if (s->insn->data) {
2876 tcg_gen_qemu_st64(regs[r1], a, get_mem_index(s));
2878 tcg_gen_qemu_st32(regs[r1], a, get_mem_index(s));
2880 tcg_temp_free_i64(a);
2886 static ExitStatus op_sla(DisasContext *s, DisasOps *o)
2888 uint64_t sign = 1ull << s->insn->data;
2889 enum cc_op cco = s->insn->data == 31 ? CC_OP_SLA_32 : CC_OP_SLA_64;
2890 gen_op_update2_cc_i64(s, cco, o->in1, o->in2);
2891 tcg_gen_shl_i64(o->out, o->in1, o->in2);
2892 /* The arithmetic left shift is curious in that it does not affect
2893 the sign bit. Copy that over from the source unchanged. */
2894 tcg_gen_andi_i64(o->out, o->out, ~sign);
2895 tcg_gen_andi_i64(o->in1, o->in1, sign);
2896 tcg_gen_or_i64(o->out, o->out, o->in1);
2900 static ExitStatus op_sll(DisasContext *s, DisasOps *o)
2902 tcg_gen_shl_i64(o->out, o->in1, o->in2);
2906 static ExitStatus op_sra(DisasContext *s, DisasOps *o)
2908 tcg_gen_sar_i64(o->out, o->in1, o->in2);
2912 static ExitStatus op_srl(DisasContext *s, DisasOps *o)
2914 tcg_gen_shr_i64(o->out, o->in1, o->in2);
2918 static ExitStatus op_sfpc(DisasContext *s, DisasOps *o)
2920 gen_helper_sfpc(cpu_env, o->in2);
2924 #ifndef CONFIG_USER_ONLY
2925 static ExitStatus op_spka(DisasContext *s, DisasOps *o)
2927 check_privileged(s);
2928 tcg_gen_shri_i64(o->in2, o->in2, 4);
2929 tcg_gen_deposit_i64(psw_mask, psw_mask, o->in2, PSW_SHIFT_KEY - 4, 4);
2933 static ExitStatus op_sske(DisasContext *s, DisasOps *o)
2935 check_privileged(s);
2936 gen_helper_sske(cpu_env, o->in1, o->in2);
2940 static ExitStatus op_ssm(DisasContext *s, DisasOps *o)
2942 check_privileged(s);
2943 tcg_gen_deposit_i64(psw_mask, psw_mask, o->in2, 56, 8);
2947 static ExitStatus op_stap(DisasContext *s, DisasOps *o)
2949 check_privileged(s);
2950 /* ??? Surely cpu address != cpu number. In any case the previous
2951 version of this stored more than the required half-word, so it
2952 is unlikely this has ever been tested. */
2953 tcg_gen_ld32u_i64(o->out, cpu_env, offsetof(CPUS390XState, cpu_num));
2957 static ExitStatus op_stck(DisasContext *s, DisasOps *o)
2959 gen_helper_stck(o->out, cpu_env);
2960 /* ??? We don't implement clock states. */
2961 gen_op_movi_cc(s, 0);
2965 static ExitStatus op_stcke(DisasContext *s, DisasOps *o)
2967 TCGv_i64 c1 = tcg_temp_new_i64();
2968 TCGv_i64 c2 = tcg_temp_new_i64();
2969 gen_helper_stck(c1, cpu_env);
2970 /* Shift the 64-bit value into its place as a zero-extended
2971 104-bit value. Note that "bit positions 64-103 are always
2972 non-zero so that they compare differently to STCK"; we set
2973 the least significant bit to 1. */
2974 tcg_gen_shli_i64(c2, c1, 56);
2975 tcg_gen_shri_i64(c1, c1, 8);
2976 tcg_gen_ori_i64(c2, c2, 0x10000);
2977 tcg_gen_qemu_st64(c1, o->in2, get_mem_index(s));
2978 tcg_gen_addi_i64(o->in2, o->in2, 8);
2979 tcg_gen_qemu_st64(c2, o->in2, get_mem_index(s));
2980 tcg_temp_free_i64(c1);
2981 tcg_temp_free_i64(c2);
2982 /* ??? We don't implement clock states. */
2983 gen_op_movi_cc(s, 0);
2987 static ExitStatus op_sckc(DisasContext *s, DisasOps *o)
2989 check_privileged(s);
2990 gen_helper_sckc(cpu_env, o->in2);
2994 static ExitStatus op_stckc(DisasContext *s, DisasOps *o)
2996 check_privileged(s);
2997 gen_helper_stckc(o->out, cpu_env);
3001 static ExitStatus op_stctg(DisasContext *s, DisasOps *o)
3003 TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
3004 TCGv_i32 r3 = tcg_const_i32(get_field(s->fields, r3));
3005 check_privileged(s);
3006 potential_page_fault(s);
3007 gen_helper_stctg(cpu_env, r1, o->in2, r3);
3008 tcg_temp_free_i32(r1);
3009 tcg_temp_free_i32(r3);
3013 static ExitStatus op_stctl(DisasContext *s, DisasOps *o)
3015 TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
3016 TCGv_i32 r3 = tcg_const_i32(get_field(s->fields, r3));
3017 check_privileged(s);
3018 potential_page_fault(s);
3019 gen_helper_stctl(cpu_env, r1, o->in2, r3);
3020 tcg_temp_free_i32(r1);
3021 tcg_temp_free_i32(r3);
3025 static ExitStatus op_stidp(DisasContext *s, DisasOps *o)
3027 check_privileged(s);
3028 tcg_gen_ld32u_i64(o->out, cpu_env, offsetof(CPUS390XState, cpu_num));
3032 static ExitStatus op_spt(DisasContext *s, DisasOps *o)
3034 check_privileged(s);
3035 gen_helper_spt(cpu_env, o->in2);
3039 static ExitStatus op_stfl(DisasContext *s, DisasOps *o)
3042 /* We really ought to have more complete indication of facilities
3043 that we implement. Address this when STFLE is implemented. */
3044 check_privileged(s);
3045 f = tcg_const_i64(0xc0000000);
3046 a = tcg_const_i64(200);
3047 tcg_gen_qemu_st32(f, a, get_mem_index(s));
3048 tcg_temp_free_i64(f);
3049 tcg_temp_free_i64(a);
3053 static ExitStatus op_stpt(DisasContext *s, DisasOps *o)
3055 check_privileged(s);
3056 gen_helper_stpt(o->out, cpu_env);
3060 static ExitStatus op_stsi(DisasContext *s, DisasOps *o)
3062 check_privileged(s);
3063 potential_page_fault(s);
3064 gen_helper_stsi(cc_op, cpu_env, o->in2, regs[0], regs[1]);
3069 static ExitStatus op_spx(DisasContext *s, DisasOps *o)
3071 check_privileged(s);
3072 gen_helper_spx(cpu_env, o->in2);
3076 static ExitStatus op_subchannel(DisasContext *s, DisasOps *o)
3078 check_privileged(s);
3079 /* Not operational. */
3080 gen_op_movi_cc(s, 3);
3084 static ExitStatus op_stpx(DisasContext *s, DisasOps *o)
3086 check_privileged(s);
3087 tcg_gen_ld_i64(o->out, cpu_env, offsetof(CPUS390XState, psa));
3088 tcg_gen_andi_i64(o->out, o->out, 0x7fffe000);
3092 static ExitStatus op_stnosm(DisasContext *s, DisasOps *o)
3094 uint64_t i2 = get_field(s->fields, i2);
3097 check_privileged(s);
3099 /* It is important to do what the instruction name says: STORE THEN.
3100 If we let the output hook perform the store then if we fault and
3101 restart, we'll have the wrong SYSTEM MASK in place. */
3102 t = tcg_temp_new_i64();
3103 tcg_gen_shri_i64(t, psw_mask, 56);
3104 tcg_gen_qemu_st8(t, o->addr1, get_mem_index(s));
3105 tcg_temp_free_i64(t);
3107 if (s->fields->op == 0xac) {
3108 tcg_gen_andi_i64(psw_mask, psw_mask,
3109 (i2 << 56) | 0x00ffffffffffffffull);
3111 tcg_gen_ori_i64(psw_mask, psw_mask, i2 << 56);
3116 static ExitStatus op_stura(DisasContext *s, DisasOps *o)
3118 check_privileged(s);
3119 potential_page_fault(s);
3120 gen_helper_stura(cpu_env, o->in2, o->in1);
3125 static ExitStatus op_st8(DisasContext *s, DisasOps *o)
3127 tcg_gen_qemu_st8(o->in1, o->in2, get_mem_index(s));
3131 static ExitStatus op_st16(DisasContext *s, DisasOps *o)
3133 tcg_gen_qemu_st16(o->in1, o->in2, get_mem_index(s));
3137 static ExitStatus op_st32(DisasContext *s, DisasOps *o)
3139 tcg_gen_qemu_st32(o->in1, o->in2, get_mem_index(s));
3143 static ExitStatus op_st64(DisasContext *s, DisasOps *o)
3145 tcg_gen_qemu_st64(o->in1, o->in2, get_mem_index(s));
3149 static ExitStatus op_stam(DisasContext *s, DisasOps *o)
3151 TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
3152 TCGv_i32 r3 = tcg_const_i32(get_field(s->fields, r3));
3153 potential_page_fault(s);
3154 gen_helper_stam(cpu_env, r1, o->in2, r3);
3155 tcg_temp_free_i32(r1);
3156 tcg_temp_free_i32(r3);
3160 static ExitStatus op_stcm(DisasContext *s, DisasOps *o)
3162 int m3 = get_field(s->fields, m3);
3163 int pos, base = s->insn->data;
3164 TCGv_i64 tmp = tcg_temp_new_i64();
3166 pos = base + ctz32(m3) * 8;
3169 /* Effectively a 32-bit store. */
3170 tcg_gen_shri_i64(tmp, o->in1, pos);
3171 tcg_gen_qemu_st32(tmp, o->in2, get_mem_index(s));
3177 /* Effectively a 16-bit store. */
3178 tcg_gen_shri_i64(tmp, o->in1, pos);
3179 tcg_gen_qemu_st16(tmp, o->in2, get_mem_index(s));
3186 /* Effectively an 8-bit store. */
3187 tcg_gen_shri_i64(tmp, o->in1, pos);
3188 tcg_gen_qemu_st8(tmp, o->in2, get_mem_index(s));
3192 /* This is going to be a sequence of shifts and stores. */
3193 pos = base + 32 - 8;
3196 tcg_gen_shri_i64(tmp, o->in1, pos);
3197 tcg_gen_qemu_st8(tmp, o->in2, get_mem_index(s));
3198 tcg_gen_addi_i64(o->in2, o->in2, 1);
3200 m3 = (m3 << 1) & 0xf;
3205 tcg_temp_free_i64(tmp);
3209 static ExitStatus op_stm(DisasContext *s, DisasOps *o)
3211 int r1 = get_field(s->fields, r1);
3212 int r3 = get_field(s->fields, r3);
3213 int size = s->insn->data;
3214 TCGv_i64 tsize = tcg_const_i64(size);
3218 tcg_gen_qemu_st64(regs[r1], o->in2, get_mem_index(s));
3220 tcg_gen_qemu_st32(regs[r1], o->in2, get_mem_index(s));
3225 tcg_gen_add_i64(o->in2, o->in2, tsize);
3229 tcg_temp_free_i64(tsize);
3233 static ExitStatus op_stmh(DisasContext *s, DisasOps *o)
3235 int r1 = get_field(s->fields, r1);
3236 int r3 = get_field(s->fields, r3);
3237 TCGv_i64 t = tcg_temp_new_i64();
3238 TCGv_i64 t4 = tcg_const_i64(4);
3239 TCGv_i64 t32 = tcg_const_i64(32);
3242 tcg_gen_shl_i64(t, regs[r1], t32);
3243 tcg_gen_qemu_st32(t, o->in2, get_mem_index(s));
3247 tcg_gen_add_i64(o->in2, o->in2, t4);
3251 tcg_temp_free_i64(t);
3252 tcg_temp_free_i64(t4);
3253 tcg_temp_free_i64(t32);
3257 static ExitStatus op_srst(DisasContext *s, DisasOps *o)
3259 potential_page_fault(s);
3260 gen_helper_srst(o->in1, cpu_env, regs[0], o->in1, o->in2);
3262 return_low128(o->in2);
3266 static ExitStatus op_sub(DisasContext *s, DisasOps *o)
3268 tcg_gen_sub_i64(o->out, o->in1, o->in2);
3272 static ExitStatus op_subb(DisasContext *s, DisasOps *o)
3277 tcg_gen_not_i64(o->in2, o->in2);
3278 tcg_gen_add_i64(o->out, o->in1, o->in2);
3280 /* XXX possible optimization point */
3282 cc = tcg_temp_new_i64();
3283 tcg_gen_extu_i32_i64(cc, cc_op);
3284 tcg_gen_shri_i64(cc, cc, 1);
3285 tcg_gen_add_i64(o->out, o->out, cc);
3286 tcg_temp_free_i64(cc);
3290 static ExitStatus op_svc(DisasContext *s, DisasOps *o)
3297 t = tcg_const_i32(get_field(s->fields, i1) & 0xff);
3298 tcg_gen_st_i32(t, cpu_env, offsetof(CPUS390XState, int_svc_code));
3299 tcg_temp_free_i32(t);
3301 t = tcg_const_i32(s->next_pc - s->pc);
3302 tcg_gen_st_i32(t, cpu_env, offsetof(CPUS390XState, int_svc_ilen));
3303 tcg_temp_free_i32(t);
3305 gen_exception(EXCP_SVC);
3306 return EXIT_NORETURN;
3309 static ExitStatus op_tceb(DisasContext *s, DisasOps *o)
3311 gen_helper_tceb(cc_op, o->in1, o->in2);
3316 static ExitStatus op_tcdb(DisasContext *s, DisasOps *o)
3318 gen_helper_tcdb(cc_op, o->in1, o->in2);
3323 static ExitStatus op_tcxb(DisasContext *s, DisasOps *o)
3325 gen_helper_tcxb(cc_op, o->out, o->out2, o->in2);
3330 #ifndef CONFIG_USER_ONLY
3331 static ExitStatus op_tprot(DisasContext *s, DisasOps *o)
3333 potential_page_fault(s);
3334 gen_helper_tprot(cc_op, o->addr1, o->in2);
3340 static ExitStatus op_tr(DisasContext *s, DisasOps *o)
3342 TCGv_i32 l = tcg_const_i32(get_field(s->fields, l1));
3343 potential_page_fault(s);
3344 gen_helper_tr(cpu_env, l, o->addr1, o->in2);
3345 tcg_temp_free_i32(l);
3350 static ExitStatus op_unpk(DisasContext *s, DisasOps *o)
3352 TCGv_i32 l = tcg_const_i32(get_field(s->fields, l1));
3353 potential_page_fault(s);
3354 gen_helper_unpk(cpu_env, l, o->addr1, o->in2);
3355 tcg_temp_free_i32(l);
3359 static ExitStatus op_xc(DisasContext *s, DisasOps *o)
3361 TCGv_i32 l = tcg_const_i32(get_field(s->fields, l1));
3362 potential_page_fault(s);
3363 gen_helper_xc(cc_op, cpu_env, l, o->addr1, o->in2);
3364 tcg_temp_free_i32(l);
3369 static ExitStatus op_xor(DisasContext *s, DisasOps *o)
3371 tcg_gen_xor_i64(o->out, o->in1, o->in2);
3375 static ExitStatus op_xori(DisasContext *s, DisasOps *o)
3377 int shift = s->insn->data & 0xff;
3378 int size = s->insn->data >> 8;
3379 uint64_t mask = ((1ull << size) - 1) << shift;
3382 tcg_gen_shli_i64(o->in2, o->in2, shift);
3383 tcg_gen_xor_i64(o->out, o->in1, o->in2);
3385 /* Produce the CC from only the bits manipulated. */
3386 tcg_gen_andi_i64(cc_dst, o->out, mask);
3387 set_cc_nz_u64(s, cc_dst);
3391 static ExitStatus op_zero(DisasContext *s, DisasOps *o)
3393 o->out = tcg_const_i64(0);
3397 static ExitStatus op_zero2(DisasContext *s, DisasOps *o)
3399 o->out = tcg_const_i64(0);
3405 /* ====================================================================== */
3406 /* The "Cc OUTput" generators. Given the generated output (and in some cases
3407 the original inputs), update the various cc data structures in order to
3408 be able to compute the new condition code. */
3410 static void cout_abs32(DisasContext *s, DisasOps *o)
3412 gen_op_update1_cc_i64(s, CC_OP_ABS_32, o->out);
3415 static void cout_abs64(DisasContext *s, DisasOps *o)
3417 gen_op_update1_cc_i64(s, CC_OP_ABS_64, o->out);
3420 static void cout_adds32(DisasContext *s, DisasOps *o)
3422 gen_op_update3_cc_i64(s, CC_OP_ADD_32, o->in1, o->in2, o->out);
3425 static void cout_adds64(DisasContext *s, DisasOps *o)
3427 gen_op_update3_cc_i64(s, CC_OP_ADD_64, o->in1, o->in2, o->out);
3430 static void cout_addu32(DisasContext *s, DisasOps *o)
3432 gen_op_update3_cc_i64(s, CC_OP_ADDU_32, o->in1, o->in2, o->out);
3435 static void cout_addu64(DisasContext *s, DisasOps *o)
3437 gen_op_update3_cc_i64(s, CC_OP_ADDU_64, o->in1, o->in2, o->out);
3440 static void cout_addc32(DisasContext *s, DisasOps *o)
3442 gen_op_update3_cc_i64(s, CC_OP_ADDC_32, o->in1, o->in2, o->out);
3445 static void cout_addc64(DisasContext *s, DisasOps *o)
3447 gen_op_update3_cc_i64(s, CC_OP_ADDC_64, o->in1, o->in2, o->out);
3450 static void cout_cmps32(DisasContext *s, DisasOps *o)
3452 gen_op_update2_cc_i64(s, CC_OP_LTGT_32, o->in1, o->in2);
3455 static void cout_cmps64(DisasContext *s, DisasOps *o)
3457 gen_op_update2_cc_i64(s, CC_OP_LTGT_64, o->in1, o->in2);
3460 static void cout_cmpu32(DisasContext *s, DisasOps *o)
3462 gen_op_update2_cc_i64(s, CC_OP_LTUGTU_32, o->in1, o->in2);
3465 static void cout_cmpu64(DisasContext *s, DisasOps *o)
3467 gen_op_update2_cc_i64(s, CC_OP_LTUGTU_64, o->in1, o->in2);
3470 static void cout_f32(DisasContext *s, DisasOps *o)
3472 gen_op_update1_cc_i64(s, CC_OP_NZ_F32, o->out);
3475 static void cout_f64(DisasContext *s, DisasOps *o)
3477 gen_op_update1_cc_i64(s, CC_OP_NZ_F64, o->out);
3480 static void cout_f128(DisasContext *s, DisasOps *o)
3482 gen_op_update2_cc_i64(s, CC_OP_NZ_F128, o->out, o->out2);
3485 static void cout_nabs32(DisasContext *s, DisasOps *o)
3487 gen_op_update1_cc_i64(s, CC_OP_NABS_32, o->out);
3490 static void cout_nabs64(DisasContext *s, DisasOps *o)
3492 gen_op_update1_cc_i64(s, CC_OP_NABS_64, o->out);
3495 static void cout_neg32(DisasContext *s, DisasOps *o)
3497 gen_op_update1_cc_i64(s, CC_OP_COMP_32, o->out);
3500 static void cout_neg64(DisasContext *s, DisasOps *o)
3502 gen_op_update1_cc_i64(s, CC_OP_COMP_64, o->out);
3505 static void cout_nz32(DisasContext *s, DisasOps *o)
3507 tcg_gen_ext32u_i64(cc_dst, o->out);
3508 gen_op_update1_cc_i64(s, CC_OP_NZ, cc_dst);
3511 static void cout_nz64(DisasContext *s, DisasOps *o)
3513 gen_op_update1_cc_i64(s, CC_OP_NZ, o->out);
3516 static void cout_s32(DisasContext *s, DisasOps *o)
3518 gen_op_update1_cc_i64(s, CC_OP_LTGT0_32, o->out);
3521 static void cout_s64(DisasContext *s, DisasOps *o)
3523 gen_op_update1_cc_i64(s, CC_OP_LTGT0_64, o->out);
3526 static void cout_subs32(DisasContext *s, DisasOps *o)
3528 gen_op_update3_cc_i64(s, CC_OP_SUB_32, o->in1, o->in2, o->out);
3531 static void cout_subs64(DisasContext *s, DisasOps *o)
3533 gen_op_update3_cc_i64(s, CC_OP_SUB_64, o->in1, o->in2, o->out);
3536 static void cout_subu32(DisasContext *s, DisasOps *o)
3538 gen_op_update3_cc_i64(s, CC_OP_SUBU_32, o->in1, o->in2, o->out);
3541 static void cout_subu64(DisasContext *s, DisasOps *o)
3543 gen_op_update3_cc_i64(s, CC_OP_SUBU_64, o->in1, o->in2, o->out);
3546 static void cout_subb32(DisasContext *s, DisasOps *o)
3548 gen_op_update3_cc_i64(s, CC_OP_SUBB_32, o->in1, o->in2, o->out);
3551 static void cout_subb64(DisasContext *s, DisasOps *o)
3553 gen_op_update3_cc_i64(s, CC_OP_SUBB_64, o->in1, o->in2, o->out);
3556 static void cout_tm32(DisasContext *s, DisasOps *o)
3558 gen_op_update2_cc_i64(s, CC_OP_TM_32, o->in1, o->in2);
3561 static void cout_tm64(DisasContext *s, DisasOps *o)
3563 gen_op_update2_cc_i64(s, CC_OP_TM_64, o->in1, o->in2);
3566 /* ====================================================================== */
3567 /* The "PREPeration" generators. These initialize the DisasOps.OUT fields
3568 with the TCG register to which we will write. Used in combination with
3569 the "wout" generators, in some cases we need a new temporary, and in
3570 some cases we can write to a TCG global. */
3572 static void prep_new(DisasContext *s, DisasFields *f, DisasOps *o)
3574 o->out = tcg_temp_new_i64();
3576 #define SPEC_prep_new 0
3578 static void prep_new_P(DisasContext *s, DisasFields *f, DisasOps *o)
3580 o->out = tcg_temp_new_i64();
3581 o->out2 = tcg_temp_new_i64();
3583 #define SPEC_prep_new_P 0
3585 static void prep_r1(DisasContext *s, DisasFields *f, DisasOps *o)
3587 o->out = regs[get_field(f, r1)];
3590 #define SPEC_prep_r1 0
3592 static void prep_r1_P(DisasContext *s, DisasFields *f, DisasOps *o)
3594 int r1 = get_field(f, r1);
3596 o->out2 = regs[r1 + 1];
3597 o->g_out = o->g_out2 = true;
3599 #define SPEC_prep_r1_P SPEC_r1_even
3601 static void prep_f1(DisasContext *s, DisasFields *f, DisasOps *o)
3603 o->out = fregs[get_field(f, r1)];
3606 #define SPEC_prep_f1 0
3608 static void prep_x1(DisasContext *s, DisasFields *f, DisasOps *o)
3610 int r1 = get_field(f, r1);
3612 o->out2 = fregs[r1 + 2];
3613 o->g_out = o->g_out2 = true;
3615 #define SPEC_prep_x1 SPEC_r1_f128
3617 /* ====================================================================== */
3618 /* The "Write OUTput" generators. These generally perform some non-trivial
3619 copy of data to TCG globals, or to main memory. The trivial cases are
3620 generally handled by having a "prep" generator install the TCG global
3621 as the destination of the operation. */
3623 static void wout_r1(DisasContext *s, DisasFields *f, DisasOps *o)
3625 store_reg(get_field(f, r1), o->out);
3627 #define SPEC_wout_r1 0
3629 static void wout_r1_8(DisasContext *s, DisasFields *f, DisasOps *o)
3631 int r1 = get_field(f, r1);
3632 tcg_gen_deposit_i64(regs[r1], regs[r1], o->out, 0, 8);
3634 #define SPEC_wout_r1_8 0
3636 static void wout_r1_16(DisasContext *s, DisasFields *f, DisasOps *o)
3638 int r1 = get_field(f, r1);
3639 tcg_gen_deposit_i64(regs[r1], regs[r1], o->out, 0, 16);
3641 #define SPEC_wout_r1_16 0
3643 static void wout_r1_32(DisasContext *s, DisasFields *f, DisasOps *o)
3645 store_reg32_i64(get_field(f, r1), o->out);
3647 #define SPEC_wout_r1_32 0
3649 static void wout_r1_P32(DisasContext *s, DisasFields *f, DisasOps *o)
3651 int r1 = get_field(f, r1);
3652 store_reg32_i64(r1, o->out);
3653 store_reg32_i64(r1 + 1, o->out2);
3655 #define SPEC_wout_r1_P32 SPEC_r1_even
3657 static void wout_r1_D32(DisasContext *s, DisasFields *f, DisasOps *o)
3659 int r1 = get_field(f, r1);
3660 store_reg32_i64(r1 + 1, o->out);
3661 tcg_gen_shri_i64(o->out, o->out, 32);
3662 store_reg32_i64(r1, o->out);
3664 #define SPEC_wout_r1_D32 SPEC_r1_even
3666 static void wout_e1(DisasContext *s, DisasFields *f, DisasOps *o)
3668 store_freg32_i64(get_field(f, r1), o->out);
3670 #define SPEC_wout_e1 0
3672 static void wout_f1(DisasContext *s, DisasFields *f, DisasOps *o)
3674 store_freg(get_field(f, r1), o->out);
3676 #define SPEC_wout_f1 0
3678 static void wout_x1(DisasContext *s, DisasFields *f, DisasOps *o)
3680 int f1 = get_field(s->fields, r1);
3681 store_freg(f1, o->out);
3682 store_freg(f1 + 2, o->out2);
3684 #define SPEC_wout_x1 SPEC_r1_f128
3686 static void wout_cond_r1r2_32(DisasContext *s, DisasFields *f, DisasOps *o)
3688 if (get_field(f, r1) != get_field(f, r2)) {
3689 store_reg32_i64(get_field(f, r1), o->out);
3692 #define SPEC_wout_cond_r1r2_32 0
3694 static void wout_cond_e1e2(DisasContext *s, DisasFields *f, DisasOps *o)
3696 if (get_field(f, r1) != get_field(f, r2)) {
3697 store_freg32_i64(get_field(f, r1), o->out);
3700 #define SPEC_wout_cond_e1e2 0
3702 static void wout_m1_8(DisasContext *s, DisasFields *f, DisasOps *o)
3704 tcg_gen_qemu_st8(o->out, o->addr1, get_mem_index(s));
3706 #define SPEC_wout_m1_8 0
3708 static void wout_m1_16(DisasContext *s, DisasFields *f, DisasOps *o)
3710 tcg_gen_qemu_st16(o->out, o->addr1, get_mem_index(s));
3712 #define SPEC_wout_m1_16 0
3714 static void wout_m1_32(DisasContext *s, DisasFields *f, DisasOps *o)
3716 tcg_gen_qemu_st32(o->out, o->addr1, get_mem_index(s));
3718 #define SPEC_wout_m1_32 0
3720 static void wout_m1_64(DisasContext *s, DisasFields *f, DisasOps *o)
3722 tcg_gen_qemu_st64(o->out, o->addr1, get_mem_index(s));
3724 #define SPEC_wout_m1_64 0
3726 static void wout_m2_32(DisasContext *s, DisasFields *f, DisasOps *o)
3728 tcg_gen_qemu_st32(o->out, o->in2, get_mem_index(s));
3730 #define SPEC_wout_m2_32 0
3732 /* ====================================================================== */
3733 /* The "INput 1" generators. These load the first operand to an insn. */
3735 static void in1_r1(DisasContext *s, DisasFields *f, DisasOps *o)
3737 o->in1 = load_reg(get_field(f, r1));
3739 #define SPEC_in1_r1 0
3741 static void in1_r1_o(DisasContext *s, DisasFields *f, DisasOps *o)
3743 o->in1 = regs[get_field(f, r1)];
3746 #define SPEC_in1_r1_o 0
3748 static void in1_r1_32s(DisasContext *s, DisasFields *f, DisasOps *o)
3750 o->in1 = tcg_temp_new_i64();
3751 tcg_gen_ext32s_i64(o->in1, regs[get_field(f, r1)]);
3753 #define SPEC_in1_r1_32s 0
3755 static void in1_r1_32u(DisasContext *s, DisasFields *f, DisasOps *o)
3757 o->in1 = tcg_temp_new_i64();
3758 tcg_gen_ext32u_i64(o->in1, regs[get_field(f, r1)]);
3760 #define SPEC_in1_r1_32u 0
3762 static void in1_r1_sr32(DisasContext *s, DisasFields *f, DisasOps *o)
3764 o->in1 = tcg_temp_new_i64();
3765 tcg_gen_shri_i64(o->in1, regs[get_field(f, r1)], 32);
3767 #define SPEC_in1_r1_sr32 0
3769 static void in1_r1p1(DisasContext *s, DisasFields *f, DisasOps *o)
3771 o->in1 = load_reg(get_field(f, r1) + 1);
3773 #define SPEC_in1_r1p1 SPEC_r1_even
3775 static void in1_r1p1_32s(DisasContext *s, DisasFields *f, DisasOps *o)
3777 o->in1 = tcg_temp_new_i64();
3778 tcg_gen_ext32s_i64(o->in1, regs[get_field(f, r1) + 1]);
3780 #define SPEC_in1_r1p1_32s SPEC_r1_even
3782 static void in1_r1p1_32u(DisasContext *s, DisasFields *f, DisasOps *o)
3784 o->in1 = tcg_temp_new_i64();
3785 tcg_gen_ext32u_i64(o->in1, regs[get_field(f, r1) + 1]);
3787 #define SPEC_in1_r1p1_32u SPEC_r1_even
3789 static void in1_r1_D32(DisasContext *s, DisasFields *f, DisasOps *o)
3791 int r1 = get_field(f, r1);
3792 o->in1 = tcg_temp_new_i64();
3793 tcg_gen_concat32_i64(o->in1, regs[r1 + 1], regs[r1]);
3795 #define SPEC_in1_r1_D32 SPEC_r1_even
3797 static void in1_r2(DisasContext *s, DisasFields *f, DisasOps *o)
3799 o->in1 = load_reg(get_field(f, r2));
3801 #define SPEC_in1_r2 0
3803 static void in1_r3(DisasContext *s, DisasFields *f, DisasOps *o)
3805 o->in1 = load_reg(get_field(f, r3));
3807 #define SPEC_in1_r3 0
3809 static void in1_r3_o(DisasContext *s, DisasFields *f, DisasOps *o)
3811 o->in1 = regs[get_field(f, r3)];
3814 #define SPEC_in1_r3_o 0
3816 static void in1_r3_32s(DisasContext *s, DisasFields *f, DisasOps *o)
3818 o->in1 = tcg_temp_new_i64();
3819 tcg_gen_ext32s_i64(o->in1, regs[get_field(f, r3)]);
3821 #define SPEC_in1_r3_32s 0
3823 static void in1_r3_32u(DisasContext *s, DisasFields *f, DisasOps *o)
3825 o->in1 = tcg_temp_new_i64();
3826 tcg_gen_ext32u_i64(o->in1, regs[get_field(f, r3)]);
3828 #define SPEC_in1_r3_32u 0
3830 static void in1_e1(DisasContext *s, DisasFields *f, DisasOps *o)
3832 o->in1 = load_freg32_i64(get_field(f, r1));
3834 #define SPEC_in1_e1 0
3836 static void in1_f1_o(DisasContext *s, DisasFields *f, DisasOps *o)
3838 o->in1 = fregs[get_field(f, r1)];
3841 #define SPEC_in1_f1_o 0
3843 static void in1_x1_o(DisasContext *s, DisasFields *f, DisasOps *o)
3845 int r1 = get_field(f, r1);
3847 o->out2 = fregs[r1 + 2];
3848 o->g_out = o->g_out2 = true;
3850 #define SPEC_in1_x1_o SPEC_r1_f128
3852 static void in1_f3_o(DisasContext *s, DisasFields *f, DisasOps *o)
3854 o->in1 = fregs[get_field(f, r3)];
3857 #define SPEC_in1_f3_o 0
3859 static void in1_la1(DisasContext *s, DisasFields *f, DisasOps *o)
3861 o->addr1 = get_address(s, 0, get_field(f, b1), get_field(f, d1));
3863 #define SPEC_in1_la1 0
3865 static void in1_la2(DisasContext *s, DisasFields *f, DisasOps *o)
3867 int x2 = have_field(f, x2) ? get_field(f, x2) : 0;
3868 o->addr1 = get_address(s, x2, get_field(f, b2), get_field(f, d2));
3870 #define SPEC_in1_la2 0
3872 static void in1_m1_8u(DisasContext *s, DisasFields *f, DisasOps *o)
3875 o->in1 = tcg_temp_new_i64();
3876 tcg_gen_qemu_ld8u(o->in1, o->addr1, get_mem_index(s));
3878 #define SPEC_in1_m1_8u 0
3880 static void in1_m1_16s(DisasContext *s, DisasFields *f, DisasOps *o)
3883 o->in1 = tcg_temp_new_i64();
3884 tcg_gen_qemu_ld16s(o->in1, o->addr1, get_mem_index(s));
3886 #define SPEC_in1_m1_16s 0
3888 static void in1_m1_16u(DisasContext *s, DisasFields *f, DisasOps *o)
3891 o->in1 = tcg_temp_new_i64();
3892 tcg_gen_qemu_ld16u(o->in1, o->addr1, get_mem_index(s));
3894 #define SPEC_in1_m1_16u 0
3896 static void in1_m1_32s(DisasContext *s, DisasFields *f, DisasOps *o)
3899 o->in1 = tcg_temp_new_i64();
3900 tcg_gen_qemu_ld32s(o->in1, o->addr1, get_mem_index(s));
3902 #define SPEC_in1_m1_32s 0
3904 static void in1_m1_32u(DisasContext *s, DisasFields *f, DisasOps *o)
3907 o->in1 = tcg_temp_new_i64();
3908 tcg_gen_qemu_ld32u(o->in1, o->addr1, get_mem_index(s));
3910 #define SPEC_in1_m1_32u 0
3912 static void in1_m1_64(DisasContext *s, DisasFields *f, DisasOps *o)
3915 o->in1 = tcg_temp_new_i64();
3916 tcg_gen_qemu_ld64(o->in1, o->addr1, get_mem_index(s));
3918 #define SPEC_in1_m1_64 0
3920 /* ====================================================================== */
3921 /* The "INput 2" generators. These load the second operand to an insn. */
3923 static void in2_r1_o(DisasContext *s, DisasFields *f, DisasOps *o)
3925 o->in2 = regs[get_field(f, r1)];
3928 #define SPEC_in2_r1_o 0
3930 static void in2_r1_16u(DisasContext *s, DisasFields *f, DisasOps *o)
3932 o->in2 = tcg_temp_new_i64();
3933 tcg_gen_ext16u_i64(o->in2, regs[get_field(f, r1)]);
3935 #define SPEC_in2_r1_16u 0
3937 static void in2_r1_32u(DisasContext *s, DisasFields *f, DisasOps *o)
3939 o->in2 = tcg_temp_new_i64();
3940 tcg_gen_ext32u_i64(o->in2, regs[get_field(f, r1)]);
3942 #define SPEC_in2_r1_32u 0
3944 static void in2_r2(DisasContext *s, DisasFields *f, DisasOps *o)
3946 o->in2 = load_reg(get_field(f, r2));
3948 #define SPEC_in2_r2 0
3950 static void in2_r2_o(DisasContext *s, DisasFields *f, DisasOps *o)
3952 o->in2 = regs[get_field(f, r2)];
3955 #define SPEC_in2_r2_o 0
3957 static void in2_r2_nz(DisasContext *s, DisasFields *f, DisasOps *o)
3959 int r2 = get_field(f, r2);
3961 o->in2 = load_reg(r2);
3964 #define SPEC_in2_r2_nz 0
3966 static void in2_r2_8s(DisasContext *s, DisasFields *f, DisasOps *o)
3968 o->in2 = tcg_temp_new_i64();
3969 tcg_gen_ext8s_i64(o->in2, regs[get_field(f, r2)]);
3971 #define SPEC_in2_r2_8s 0
3973 static void in2_r2_8u(DisasContext *s, DisasFields *f, DisasOps *o)
3975 o->in2 = tcg_temp_new_i64();
3976 tcg_gen_ext8u_i64(o->in2, regs[get_field(f, r2)]);
3978 #define SPEC_in2_r2_8u 0
3980 static void in2_r2_16s(DisasContext *s, DisasFields *f, DisasOps *o)
3982 o->in2 = tcg_temp_new_i64();
3983 tcg_gen_ext16s_i64(o->in2, regs[get_field(f, r2)]);
3985 #define SPEC_in2_r2_16s 0
3987 static void in2_r2_16u(DisasContext *s, DisasFields *f, DisasOps *o)
3989 o->in2 = tcg_temp_new_i64();
3990 tcg_gen_ext16u_i64(o->in2, regs[get_field(f, r2)]);
3992 #define SPEC_in2_r2_16u 0
3994 static void in2_r3(DisasContext *s, DisasFields *f, DisasOps *o)
3996 o->in2 = load_reg(get_field(f, r3));
3998 #define SPEC_in2_r3 0
4000 static void in2_r2_32s(DisasContext *s, DisasFields *f, DisasOps *o)
4002 o->in2 = tcg_temp_new_i64();
4003 tcg_gen_ext32s_i64(o->in2, regs[get_field(f, r2)]);
4005 #define SPEC_in2_r2_32s 0
4007 static void in2_r2_32u(DisasContext *s, DisasFields *f, DisasOps *o)
4009 o->in2 = tcg_temp_new_i64();
4010 tcg_gen_ext32u_i64(o->in2, regs[get_field(f, r2)]);
4012 #define SPEC_in2_r2_32u 0
4014 static void in2_e2(DisasContext *s, DisasFields *f, DisasOps *o)
4016 o->in2 = load_freg32_i64(get_field(f, r2));
4018 #define SPEC_in2_e2 0
4020 static void in2_f2_o(DisasContext *s, DisasFields *f, DisasOps *o)
4022 o->in2 = fregs[get_field(f, r2)];
4025 #define SPEC_in2_f2_o 0
4027 static void in2_x2_o(DisasContext *s, DisasFields *f, DisasOps *o)
4029 int r2 = get_field(f, r2);
4031 o->in2 = fregs[r2 + 2];
4032 o->g_in1 = o->g_in2 = true;
4034 #define SPEC_in2_x2_o SPEC_r2_f128
4036 static void in2_ra2(DisasContext *s, DisasFields *f, DisasOps *o)
4038 o->in2 = get_address(s, 0, get_field(f, r2), 0);
4040 #define SPEC_in2_ra2 0
4042 static void in2_a2(DisasContext *s, DisasFields *f, DisasOps *o)
4044 int x2 = have_field(f, x2) ? get_field(f, x2) : 0;
4045 o->in2 = get_address(s, x2, get_field(f, b2), get_field(f, d2));
4047 #define SPEC_in2_a2 0
4049 static void in2_ri2(DisasContext *s, DisasFields *f, DisasOps *o)
4051 o->in2 = tcg_const_i64(s->pc + (int64_t)get_field(f, i2) * 2);
4053 #define SPEC_in2_ri2 0
4055 static void in2_sh32(DisasContext *s, DisasFields *f, DisasOps *o)
4057 help_l2_shift(s, f, o, 31);
4059 #define SPEC_in2_sh32 0
4061 static void in2_sh64(DisasContext *s, DisasFields *f, DisasOps *o)
4063 help_l2_shift(s, f, o, 63);
4065 #define SPEC_in2_sh64 0
4067 static void in2_m2_8u(DisasContext *s, DisasFields *f, DisasOps *o)
4070 tcg_gen_qemu_ld8u(o->in2, o->in2, get_mem_index(s));
4072 #define SPEC_in2_m2_8u 0
4074 static void in2_m2_16s(DisasContext *s, DisasFields *f, DisasOps *o)
4077 tcg_gen_qemu_ld16s(o->in2, o->in2, get_mem_index(s));
4079 #define SPEC_in2_m2_16s 0
4081 static void in2_m2_16u(DisasContext *s, DisasFields *f, DisasOps *o)
4084 tcg_gen_qemu_ld16u(o->in2, o->in2, get_mem_index(s));
4086 #define SPEC_in2_m2_16u 0
4088 static void in2_m2_32s(DisasContext *s, DisasFields *f, DisasOps *o)
4091 tcg_gen_qemu_ld32s(o->in2, o->in2, get_mem_index(s));
4093 #define SPEC_in2_m2_32s 0
4095 static void in2_m2_32u(DisasContext *s, DisasFields *f, DisasOps *o)
4098 tcg_gen_qemu_ld32u(o->in2, o->in2, get_mem_index(s));
4100 #define SPEC_in2_m2_32u 0
4102 static void in2_m2_64(DisasContext *s, DisasFields *f, DisasOps *o)
4105 tcg_gen_qemu_ld64(o->in2, o->in2, get_mem_index(s));
4107 #define SPEC_in2_m2_64 0
4109 static void in2_mri2_16u(DisasContext *s, DisasFields *f, DisasOps *o)
4112 tcg_gen_qemu_ld16u(o->in2, o->in2, get_mem_index(s));
4114 #define SPEC_in2_mri2_16u 0
4116 static void in2_mri2_32s(DisasContext *s, DisasFields *f, DisasOps *o)
4119 tcg_gen_qemu_ld32s(o->in2, o->in2, get_mem_index(s));
4121 #define SPEC_in2_mri2_32s 0
4123 static void in2_mri2_32u(DisasContext *s, DisasFields *f, DisasOps *o)
4126 tcg_gen_qemu_ld32u(o->in2, o->in2, get_mem_index(s));
4128 #define SPEC_in2_mri2_32u 0
4130 static void in2_mri2_64(DisasContext *s, DisasFields *f, DisasOps *o)
4133 tcg_gen_qemu_ld64(o->in2, o->in2, get_mem_index(s));
4135 #define SPEC_in2_mri2_64 0
4137 static void in2_i2(DisasContext *s, DisasFields *f, DisasOps *o)
4139 o->in2 = tcg_const_i64(get_field(f, i2));
4141 #define SPEC_in2_i2 0
4143 static void in2_i2_8u(DisasContext *s, DisasFields *f, DisasOps *o)
4145 o->in2 = tcg_const_i64((uint8_t)get_field(f, i2));
4147 #define SPEC_in2_i2_8u 0
4149 static void in2_i2_16u(DisasContext *s, DisasFields *f, DisasOps *o)
4151 o->in2 = tcg_const_i64((uint16_t)get_field(f, i2));
4153 #define SPEC_in2_i2_16u 0
4155 static void in2_i2_32u(DisasContext *s, DisasFields *f, DisasOps *o)
4157 o->in2 = tcg_const_i64((uint32_t)get_field(f, i2));
4159 #define SPEC_in2_i2_32u 0
4161 static void in2_i2_16u_shl(DisasContext *s, DisasFields *f, DisasOps *o)
4163 uint64_t i2 = (uint16_t)get_field(f, i2);
4164 o->in2 = tcg_const_i64(i2 << s->insn->data);
4166 #define SPEC_in2_i2_16u_shl 0
4168 static void in2_i2_32u_shl(DisasContext *s, DisasFields *f, DisasOps *o)
4170 uint64_t i2 = (uint32_t)get_field(f, i2);
4171 o->in2 = tcg_const_i64(i2 << s->insn->data);
4173 #define SPEC_in2_i2_32u_shl 0
4175 /* ====================================================================== */
4177 /* Find opc within the table of insns. This is formulated as a switch
4178 statement so that (1) we get compile-time notice of cut-paste errors
4179 for duplicated opcodes, and (2) the compiler generates the binary
4180 search tree, rather than us having to post-process the table. */
4182 #define C(OPC, NM, FT, FC, I1, I2, P, W, OP, CC) \
4183 D(OPC, NM, FT, FC, I1, I2, P, W, OP, CC, 0)
4185 #define D(OPC, NM, FT, FC, I1, I2, P, W, OP, CC, D) insn_ ## NM,
4187 enum DisasInsnEnum {
4188 #include "insn-data.def"
4192 #define D(OPC, NM, FT, FC, I1, I2, P, W, OP, CC, D) { \
4196 .spec = SPEC_in1_##I1 | SPEC_in2_##I2 | SPEC_prep_##P | SPEC_wout_##W, \
4198 .help_in1 = in1_##I1, \
4199 .help_in2 = in2_##I2, \
4200 .help_prep = prep_##P, \
4201 .help_wout = wout_##W, \
4202 .help_cout = cout_##CC, \
4203 .help_op = op_##OP, \
4207 /* Allow 0 to be used for NULL in the table below. */
4215 #define SPEC_in1_0 0
4216 #define SPEC_in2_0 0
4217 #define SPEC_prep_0 0
4218 #define SPEC_wout_0 0
4220 static const DisasInsn insn_info[] = {
4221 #include "insn-data.def"
4225 #define D(OPC, NM, FT, FC, I1, I2, P, W, OP, CC, D) \
4226 case OPC: return &insn_info[insn_ ## NM];
4228 static const DisasInsn *lookup_opc(uint16_t opc)
4231 #include "insn-data.def"
4240 /* Extract a field from the insn. The INSN should be left-aligned in
4241 the uint64_t so that we can more easily utilize the big-bit-endian
4242 definitions we extract from the Principals of Operation. */
4244 static void extract_field(DisasFields *o, const DisasField *f, uint64_t insn)
4252 /* Zero extract the field from the insn. */
4253 r = (insn << f->beg) >> (64 - f->size);
4255 /* Sign-extend, or un-swap the field as necessary. */
4257 case 0: /* unsigned */
4259 case 1: /* signed */
4260 assert(f->size <= 32);
4261 m = 1u << (f->size - 1);
4264 case 2: /* dl+dh split, signed 20 bit. */
4265 r = ((int8_t)r << 12) | (r >> 8);
4271 /* Validate that the "compressed" encoding we selected above is valid.
4272 I.e. we havn't make two different original fields overlap. */
4273 assert(((o->presentC >> f->indexC) & 1) == 0);
4274 o->presentC |= 1 << f->indexC;
4275 o->presentO |= 1 << f->indexO;
4277 o->c[f->indexC] = r;
4280 /* Lookup the insn at the current PC, extracting the operands into O and
4281 returning the info struct for the insn. Returns NULL for invalid insn. */
4283 static const DisasInsn *extract_insn(CPUS390XState *env, DisasContext *s,
4286 uint64_t insn, pc = s->pc;
4288 const DisasInsn *info;
4290 insn = ld_code2(env, pc);
4291 op = (insn >> 8) & 0xff;
4292 ilen = get_ilen(op);
4293 s->next_pc = s->pc + ilen;
4300 insn = ld_code4(env, pc) << 32;
4303 insn = (insn << 48) | (ld_code4(env, pc + 2) << 16);
4309 /* We can't actually determine the insn format until we've looked up
4310 the full insn opcode. Which we can't do without locating the
4311 secondary opcode. Assume by default that OP2 is at bit 40; for
4312 those smaller insns that don't actually have a secondary opcode
4313 this will correctly result in OP2 = 0. */
4319 case 0xb2: /* S, RRF, RRE */
4320 case 0xb3: /* RRE, RRD, RRF */
4321 case 0xb9: /* RRE, RRF */
4322 case 0xe5: /* SSE, SIL */
4323 op2 = (insn << 8) >> 56;
4327 case 0xc0: /* RIL */
4328 case 0xc2: /* RIL */
4329 case 0xc4: /* RIL */
4330 case 0xc6: /* RIL */
4331 case 0xc8: /* SSF */
4332 case 0xcc: /* RIL */
4333 op2 = (insn << 12) >> 60;
4335 case 0xd0 ... 0xdf: /* SS */
4341 case 0xee ... 0xf3: /* SS */
4342 case 0xf8 ... 0xfd: /* SS */
4346 op2 = (insn << 40) >> 56;
4350 memset(f, 0, sizeof(*f));
4354 /* Lookup the instruction. */
4355 info = lookup_opc(op << 8 | op2);
4357 /* If we found it, extract the operands. */
4359 DisasFormat fmt = info->fmt;
4362 for (i = 0; i < NUM_C_FIELD; ++i) {
4363 extract_field(f, &format_info[fmt].op[i], insn);
4369 static ExitStatus translate_one(CPUS390XState *env, DisasContext *s)
4371 const DisasInsn *insn;
4372 ExitStatus ret = NO_EXIT;
4376 /* Search for the insn in the table. */
4377 insn = extract_insn(env, s, &f);
4379 /* Not found means unimplemented/illegal opcode. */
4381 qemu_log_mask(LOG_UNIMP, "unimplemented opcode 0x%02x%02x\n",
4383 gen_illegal_opcode(s);
4384 return EXIT_NORETURN;
4387 /* Check for insn specification exceptions. */
4389 int spec = insn->spec, excp = 0, r;
4391 if (spec & SPEC_r1_even) {
4392 r = get_field(&f, r1);
4394 excp = PGM_SPECIFICATION;
4397 if (spec & SPEC_r2_even) {
4398 r = get_field(&f, r2);
4400 excp = PGM_SPECIFICATION;
4403 if (spec & SPEC_r1_f128) {
4404 r = get_field(&f, r1);
4406 excp = PGM_SPECIFICATION;
4409 if (spec & SPEC_r2_f128) {
4410 r = get_field(&f, r2);
4412 excp = PGM_SPECIFICATION;
4416 gen_program_exception(s, excp);
4417 return EXIT_NORETURN;
4421 /* Set up the strutures we use to communicate with the helpers. */
4424 o.g_out = o.g_out2 = o.g_in1 = o.g_in2 = false;
4425 TCGV_UNUSED_I64(o.out);
4426 TCGV_UNUSED_I64(o.out2);
4427 TCGV_UNUSED_I64(o.in1);
4428 TCGV_UNUSED_I64(o.in2);
4429 TCGV_UNUSED_I64(o.addr1);
4431 /* Implement the instruction. */
4432 if (insn->help_in1) {
4433 insn->help_in1(s, &f, &o);
4435 if (insn->help_in2) {
4436 insn->help_in2(s, &f, &o);
4438 if (insn->help_prep) {
4439 insn->help_prep(s, &f, &o);
4441 if (insn->help_op) {
4442 ret = insn->help_op(s, &o);
4444 if (insn->help_wout) {
4445 insn->help_wout(s, &f, &o);
4447 if (insn->help_cout) {
4448 insn->help_cout(s, &o);
4451 /* Free any temporaries created by the helpers. */
4452 if (!TCGV_IS_UNUSED_I64(o.out) && !o.g_out) {
4453 tcg_temp_free_i64(o.out);
4455 if (!TCGV_IS_UNUSED_I64(o.out2) && !o.g_out2) {
4456 tcg_temp_free_i64(o.out2);
4458 if (!TCGV_IS_UNUSED_I64(o.in1) && !o.g_in1) {
4459 tcg_temp_free_i64(o.in1);
4461 if (!TCGV_IS_UNUSED_I64(o.in2) && !o.g_in2) {
4462 tcg_temp_free_i64(o.in2);
4464 if (!TCGV_IS_UNUSED_I64(o.addr1)) {
4465 tcg_temp_free_i64(o.addr1);
4468 /* Advance to the next instruction. */
4473 static inline void gen_intermediate_code_internal(CPUS390XState *env,
4474 TranslationBlock *tb,
4478 target_ulong pc_start;
4479 uint64_t next_page_start;
4480 uint16_t *gen_opc_end;
4482 int num_insns, max_insns;
4490 if (!(tb->flags & FLAG_MASK_64)) {
4491 pc_start &= 0x7fffffff;
4496 dc.cc_op = CC_OP_DYNAMIC;
4497 do_debug = dc.singlestep_enabled = env->singlestep_enabled;
4499 gen_opc_end = tcg_ctx.gen_opc_buf + OPC_MAX_SIZE;
4501 next_page_start = (pc_start & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE;
4504 max_insns = tb->cflags & CF_COUNT_MASK;
4505 if (max_insns == 0) {
4506 max_insns = CF_COUNT_MASK;
4513 j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf;
4517 tcg_ctx.gen_opc_instr_start[lj++] = 0;
4520 tcg_ctx.gen_opc_pc[lj] = dc.pc;
4521 gen_opc_cc_op[lj] = dc.cc_op;
4522 tcg_ctx.gen_opc_instr_start[lj] = 1;
4523 tcg_ctx.gen_opc_icount[lj] = num_insns;
4525 if (++num_insns == max_insns && (tb->cflags & CF_LAST_IO)) {
4529 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP | CPU_LOG_TB_OP_OPT))) {
4530 tcg_gen_debug_insn_start(dc.pc);
4534 if (unlikely(!QTAILQ_EMPTY(&env->breakpoints))) {
4535 QTAILQ_FOREACH(bp, &env->breakpoints, entry) {
4536 if (bp->pc == dc.pc) {
4537 status = EXIT_PC_STALE;
4543 if (status == NO_EXIT) {
4544 status = translate_one(env, &dc);
4547 /* If we reach a page boundary, are single stepping,
4548 or exhaust instruction count, stop generation. */
4549 if (status == NO_EXIT
4550 && (dc.pc >= next_page_start
4551 || tcg_ctx.gen_opc_ptr >= gen_opc_end
4552 || num_insns >= max_insns
4554 || env->singlestep_enabled)) {
4555 status = EXIT_PC_STALE;
4557 } while (status == NO_EXIT);
4559 if (tb->cflags & CF_LAST_IO) {
4568 update_psw_addr(&dc);
4570 case EXIT_PC_UPDATED:
4571 /* Next TB starts off with CC_OP_DYNAMIC, so make sure the
4572 cc op type is in env */
4574 /* Exit the TB, either by raising a debug exception or by return. */
4576 gen_exception(EXCP_DEBUG);
4585 gen_icount_end(tb, num_insns);
4586 *tcg_ctx.gen_opc_ptr = INDEX_op_end;
4588 j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf;
4591 tcg_ctx.gen_opc_instr_start[lj++] = 0;
4594 tb->size = dc.pc - pc_start;
4595 tb->icount = num_insns;
4598 #if defined(S390X_DEBUG_DISAS)
4599 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
4600 qemu_log("IN: %s\n", lookup_symbol(pc_start));
4601 log_target_disas(env, pc_start, dc.pc - pc_start, 1);
4607 void gen_intermediate_code (CPUS390XState *env, struct TranslationBlock *tb)
4609 gen_intermediate_code_internal(env, tb, 0);
4612 void gen_intermediate_code_pc (CPUS390XState *env, struct TranslationBlock *tb)
4614 gen_intermediate_code_internal(env, tb, 1);
4617 void restore_state_to_opc(CPUS390XState *env, TranslationBlock *tb, int pc_pos)
4620 env->psw.addr = tcg_ctx.gen_opc_pc[pc_pos];
4621 cc_op = gen_opc_cc_op[pc_pos];
4622 if ((cc_op != CC_OP_DYNAMIC) && (cc_op != CC_OP_STATIC)) {