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
)
334 TCGv_i64 tmp
= tcg_temp_new_i64();
335 bool need_31
= !(s
->tb
->flags
& FLAG_MASK_64
);
337 /* Note that d2 is limited to 20 bits, signed. If we crop negative
338 displacements early we create larger immedate addends. */
340 /* Note that addi optimizes the imm==0 case. */
342 tcg_gen_add_i64(tmp
, regs
[b2
], regs
[x2
]);
343 tcg_gen_addi_i64(tmp
, tmp
, d2
);
345 tcg_gen_addi_i64(tmp
, regs
[b2
], d2
);
347 tcg_gen_addi_i64(tmp
, regs
[x2
], d2
);
353 tcg_gen_movi_i64(tmp
, d2
);
356 tcg_gen_andi_i64(tmp
, tmp
, 0x7fffffff);
362 static inline bool live_cc_data(DisasContext
*s
)
364 return (s
->cc_op
!= CC_OP_DYNAMIC
365 && s
->cc_op
!= CC_OP_STATIC
369 static inline void gen_op_movi_cc(DisasContext
*s
, uint32_t val
)
371 if (live_cc_data(s
)) {
372 tcg_gen_discard_i64(cc_src
);
373 tcg_gen_discard_i64(cc_dst
);
374 tcg_gen_discard_i64(cc_vr
);
376 s
->cc_op
= CC_OP_CONST0
+ val
;
379 static void gen_op_update1_cc_i64(DisasContext
*s
, enum cc_op op
, TCGv_i64 dst
)
381 if (live_cc_data(s
)) {
382 tcg_gen_discard_i64(cc_src
);
383 tcg_gen_discard_i64(cc_vr
);
385 tcg_gen_mov_i64(cc_dst
, dst
);
389 static void gen_op_update2_cc_i64(DisasContext
*s
, enum cc_op op
, TCGv_i64 src
,
392 if (live_cc_data(s
)) {
393 tcg_gen_discard_i64(cc_vr
);
395 tcg_gen_mov_i64(cc_src
, src
);
396 tcg_gen_mov_i64(cc_dst
, dst
);
400 static void gen_op_update3_cc_i64(DisasContext
*s
, enum cc_op op
, TCGv_i64 src
,
401 TCGv_i64 dst
, TCGv_i64 vr
)
403 tcg_gen_mov_i64(cc_src
, src
);
404 tcg_gen_mov_i64(cc_dst
, dst
);
405 tcg_gen_mov_i64(cc_vr
, vr
);
409 static void set_cc_nz_u64(DisasContext
*s
, TCGv_i64 val
)
411 gen_op_update1_cc_i64(s
, CC_OP_NZ
, val
);
414 static void gen_set_cc_nz_f32(DisasContext
*s
, TCGv_i64 val
)
416 gen_op_update1_cc_i64(s
, CC_OP_NZ_F32
, val
);
419 static void gen_set_cc_nz_f64(DisasContext
*s
, TCGv_i64 val
)
421 gen_op_update1_cc_i64(s
, CC_OP_NZ_F64
, val
);
424 static void gen_set_cc_nz_f128(DisasContext
*s
, TCGv_i64 vh
, TCGv_i64 vl
)
426 gen_op_update2_cc_i64(s
, CC_OP_NZ_F128
, vh
, vl
);
429 /* CC value is in env->cc_op */
430 static void set_cc_static(DisasContext
*s
)
432 if (live_cc_data(s
)) {
433 tcg_gen_discard_i64(cc_src
);
434 tcg_gen_discard_i64(cc_dst
);
435 tcg_gen_discard_i64(cc_vr
);
437 s
->cc_op
= CC_OP_STATIC
;
440 /* calculates cc into cc_op */
441 static void gen_op_calc_cc(DisasContext
*s
)
443 TCGv_i32 local_cc_op
;
446 TCGV_UNUSED_I32(local_cc_op
);
447 TCGV_UNUSED_I64(dummy
);
450 dummy
= tcg_const_i64(0);
464 local_cc_op
= tcg_const_i32(s
->cc_op
);
480 /* s->cc_op is the cc value */
481 tcg_gen_movi_i32(cc_op
, s
->cc_op
- CC_OP_CONST0
);
484 /* env->cc_op already is the cc value */
499 gen_helper_calc_cc(cc_op
, cpu_env
, local_cc_op
, dummy
, cc_dst
, dummy
);
504 case CC_OP_LTUGTU_32
:
505 case CC_OP_LTUGTU_64
:
512 gen_helper_calc_cc(cc_op
, cpu_env
, local_cc_op
, cc_src
, cc_dst
, dummy
);
527 gen_helper_calc_cc(cc_op
, cpu_env
, local_cc_op
, cc_src
, cc_dst
, cc_vr
);
530 /* unknown operation - assume 3 arguments and cc_op in env */
531 gen_helper_calc_cc(cc_op
, cpu_env
, cc_op
, cc_src
, cc_dst
, cc_vr
);
537 if (!TCGV_IS_UNUSED_I32(local_cc_op
)) {
538 tcg_temp_free_i32(local_cc_op
);
540 if (!TCGV_IS_UNUSED_I64(dummy
)) {
541 tcg_temp_free_i64(dummy
);
544 /* We now have cc in cc_op as constant */
548 static int use_goto_tb(DisasContext
*s
, uint64_t dest
)
550 /* NOTE: we handle the case where the TB spans two pages here */
551 return (((dest
& TARGET_PAGE_MASK
) == (s
->tb
->pc
& TARGET_PAGE_MASK
)
552 || (dest
& TARGET_PAGE_MASK
) == ((s
->pc
- 1) & TARGET_PAGE_MASK
))
553 && !s
->singlestep_enabled
554 && !(s
->tb
->cflags
& CF_LAST_IO
));
557 static void account_noninline_branch(DisasContext
*s
, int cc_op
)
559 #ifdef DEBUG_INLINE_BRANCHES
560 inline_branch_miss
[cc_op
]++;
564 static void account_inline_branch(DisasContext
*s
, int cc_op
)
566 #ifdef DEBUG_INLINE_BRANCHES
567 inline_branch_hit
[cc_op
]++;
571 /* Table of mask values to comparison codes, given a comparison as input.
572 For such, CC=3 should not be possible. */
573 static const TCGCond ltgt_cond
[16] = {
574 TCG_COND_NEVER
, TCG_COND_NEVER
, /* | | | x */
575 TCG_COND_GT
, TCG_COND_GT
, /* | | GT | x */
576 TCG_COND_LT
, TCG_COND_LT
, /* | LT | | x */
577 TCG_COND_NE
, TCG_COND_NE
, /* | LT | GT | x */
578 TCG_COND_EQ
, TCG_COND_EQ
, /* EQ | | | x */
579 TCG_COND_GE
, TCG_COND_GE
, /* EQ | | GT | x */
580 TCG_COND_LE
, TCG_COND_LE
, /* EQ | LT | | x */
581 TCG_COND_ALWAYS
, TCG_COND_ALWAYS
, /* EQ | LT | GT | x */
584 /* Table of mask values to comparison codes, given a logic op as input.
585 For such, only CC=0 and CC=1 should be possible. */
586 static const TCGCond nz_cond
[16] = {
587 TCG_COND_NEVER
, TCG_COND_NEVER
, /* | | x | x */
588 TCG_COND_NEVER
, TCG_COND_NEVER
,
589 TCG_COND_NE
, TCG_COND_NE
, /* | NE | x | x */
590 TCG_COND_NE
, TCG_COND_NE
,
591 TCG_COND_EQ
, TCG_COND_EQ
, /* EQ | | x | x */
592 TCG_COND_EQ
, TCG_COND_EQ
,
593 TCG_COND_ALWAYS
, TCG_COND_ALWAYS
, /* EQ | NE | x | x */
594 TCG_COND_ALWAYS
, TCG_COND_ALWAYS
,
597 /* Interpret MASK in terms of S->CC_OP, and fill in C with all the
598 details required to generate a TCG comparison. */
599 static void disas_jcc(DisasContext
*s
, DisasCompare
*c
, uint32_t mask
)
602 enum cc_op old_cc_op
= s
->cc_op
;
604 if (mask
== 15 || mask
== 0) {
605 c
->cond
= (mask
? TCG_COND_ALWAYS
: TCG_COND_NEVER
);
608 c
->g1
= c
->g2
= true;
613 /* Find the TCG condition for the mask + cc op. */
619 cond
= ltgt_cond
[mask
];
620 if (cond
== TCG_COND_NEVER
) {
623 account_inline_branch(s
, old_cc_op
);
626 case CC_OP_LTUGTU_32
:
627 case CC_OP_LTUGTU_64
:
628 cond
= tcg_unsigned_cond(ltgt_cond
[mask
]);
629 if (cond
== TCG_COND_NEVER
) {
632 account_inline_branch(s
, old_cc_op
);
636 cond
= nz_cond
[mask
];
637 if (cond
== TCG_COND_NEVER
) {
640 account_inline_branch(s
, old_cc_op
);
655 account_inline_branch(s
, old_cc_op
);
670 account_inline_branch(s
, old_cc_op
);
674 switch (mask
& 0xa) {
675 case 8: /* src == 0 -> no one bit found */
678 case 2: /* src != 0 -> one bit found */
684 account_inline_branch(s
, old_cc_op
);
690 case 8 | 2: /* vr == 0 */
693 case 4 | 1: /* vr != 0 */
696 case 8 | 4: /* no carry -> vr >= src */
699 case 2 | 1: /* carry -> vr < src */
705 account_inline_branch(s
, old_cc_op
);
710 /* Note that CC=0 is impossible; treat it as dont-care. */
712 case 2: /* zero -> op1 == op2 */
715 case 4 | 1: /* !zero -> op1 != op2 */
718 case 4: /* borrow (!carry) -> op1 < op2 */
721 case 2 | 1: /* !borrow (carry) -> op1 >= op2 */
727 account_inline_branch(s
, old_cc_op
);
732 /* Calculate cc value. */
737 /* Jump based on CC. We'll load up the real cond below;
738 the assignment here merely avoids a compiler warning. */
739 account_noninline_branch(s
, old_cc_op
);
740 old_cc_op
= CC_OP_STATIC
;
741 cond
= TCG_COND_NEVER
;
745 /* Load up the arguments of the comparison. */
747 c
->g1
= c
->g2
= false;
751 c
->u
.s32
.a
= tcg_temp_new_i32();
752 tcg_gen_trunc_i64_i32(c
->u
.s32
.a
, cc_dst
);
753 c
->u
.s32
.b
= tcg_const_i32(0);
756 case CC_OP_LTUGTU_32
:
759 c
->u
.s32
.a
= tcg_temp_new_i32();
760 tcg_gen_trunc_i64_i32(c
->u
.s32
.a
, cc_src
);
761 c
->u
.s32
.b
= tcg_temp_new_i32();
762 tcg_gen_trunc_i64_i32(c
->u
.s32
.b
, cc_dst
);
769 c
->u
.s64
.b
= tcg_const_i64(0);
773 case CC_OP_LTUGTU_64
:
777 c
->g1
= c
->g2
= true;
783 c
->u
.s64
.a
= tcg_temp_new_i64();
784 c
->u
.s64
.b
= tcg_const_i64(0);
785 tcg_gen_and_i64(c
->u
.s64
.a
, cc_src
, cc_dst
);
790 c
->u
.s32
.a
= tcg_temp_new_i32();
791 c
->u
.s32
.b
= tcg_temp_new_i32();
792 tcg_gen_trunc_i64_i32(c
->u
.s32
.a
, cc_vr
);
793 if (cond
== TCG_COND_EQ
|| cond
== TCG_COND_NE
) {
794 tcg_gen_movi_i32(c
->u
.s32
.b
, 0);
796 tcg_gen_trunc_i64_i32(c
->u
.s32
.b
, cc_src
);
803 if (cond
== TCG_COND_EQ
|| cond
== TCG_COND_NE
) {
804 c
->u
.s64
.b
= tcg_const_i64(0);
816 case 0x8 | 0x4 | 0x2: /* cc != 3 */
818 c
->u
.s32
.b
= tcg_const_i32(3);
820 case 0x8 | 0x4 | 0x1: /* cc != 2 */
822 c
->u
.s32
.b
= tcg_const_i32(2);
824 case 0x8 | 0x2 | 0x1: /* cc != 1 */
826 c
->u
.s32
.b
= tcg_const_i32(1);
828 case 0x8 | 0x2: /* cc == 0 ||Â cc == 2 => (cc & 1) == 0 */
831 c
->u
.s32
.a
= tcg_temp_new_i32();
832 c
->u
.s32
.b
= tcg_const_i32(0);
833 tcg_gen_andi_i32(c
->u
.s32
.a
, cc_op
, 1);
835 case 0x8 | 0x4: /* cc < 2 */
837 c
->u
.s32
.b
= tcg_const_i32(2);
839 case 0x8: /* cc == 0 */
841 c
->u
.s32
.b
= tcg_const_i32(0);
843 case 0x4 | 0x2 | 0x1: /* cc != 0 */
845 c
->u
.s32
.b
= tcg_const_i32(0);
847 case 0x4 | 0x1: /* cc == 1 ||Â cc == 3 => (cc & 1) != 0 */
850 c
->u
.s32
.a
= tcg_temp_new_i32();
851 c
->u
.s32
.b
= tcg_const_i32(0);
852 tcg_gen_andi_i32(c
->u
.s32
.a
, cc_op
, 1);
854 case 0x4: /* cc == 1 */
856 c
->u
.s32
.b
= tcg_const_i32(1);
858 case 0x2 | 0x1: /* cc > 1 */
860 c
->u
.s32
.b
= tcg_const_i32(1);
862 case 0x2: /* cc == 2 */
864 c
->u
.s32
.b
= tcg_const_i32(2);
866 case 0x1: /* cc == 3 */
868 c
->u
.s32
.b
= tcg_const_i32(3);
871 /* CC is masked by something else: (8 >> cc) & mask. */
874 c
->u
.s32
.a
= tcg_const_i32(8);
875 c
->u
.s32
.b
= tcg_const_i32(0);
876 tcg_gen_shr_i32(c
->u
.s32
.a
, c
->u
.s32
.a
, cc_op
);
877 tcg_gen_andi_i32(c
->u
.s32
.a
, c
->u
.s32
.a
, mask
);
888 static void free_compare(DisasCompare
*c
)
892 tcg_temp_free_i64(c
->u
.s64
.a
);
894 tcg_temp_free_i32(c
->u
.s32
.a
);
899 tcg_temp_free_i64(c
->u
.s64
.b
);
901 tcg_temp_free_i32(c
->u
.s32
.b
);
906 /* ====================================================================== */
907 /* Define the insn format enumeration. */
908 #define F0(N) FMT_##N,
909 #define F1(N, X1) F0(N)
910 #define F2(N, X1, X2) F0(N)
911 #define F3(N, X1, X2, X3) F0(N)
912 #define F4(N, X1, X2, X3, X4) F0(N)
913 #define F5(N, X1, X2, X3, X4, X5) F0(N)
916 #include "insn-format.def"
926 /* Define a structure to hold the decoded fields. We'll store each inside
927 an array indexed by an enum. In order to conserve memory, we'll arrange
928 for fields that do not exist at the same time to overlap, thus the "C"
929 for compact. For checking purposes there is an "O" for original index
930 as well that will be applied to availability bitmaps. */
932 enum DisasFieldIndexO
{
955 enum DisasFieldIndexC
{
989 unsigned presentC
:16;
990 unsigned int presentO
;
994 /* This is the way fields are to be accessed out of DisasFields. */
995 #define have_field(S, F) have_field1((S), FLD_O_##F)
996 #define get_field(S, F) get_field1((S), FLD_O_##F, FLD_C_##F)
998 static bool have_field1(const DisasFields
*f
, enum DisasFieldIndexO c
)
1000 return (f
->presentO
>> c
) & 1;
1003 static int get_field1(const DisasFields
*f
, enum DisasFieldIndexO o
,
1004 enum DisasFieldIndexC c
)
1006 assert(have_field1(f
, o
));
1010 /* Describe the layout of each field in each format. */
1011 typedef struct DisasField
{
1013 unsigned int size
:8;
1014 unsigned int type
:2;
1015 unsigned int indexC
:6;
1016 enum DisasFieldIndexO indexO
:8;
1019 typedef struct DisasFormatInfo
{
1020 DisasField op
[NUM_C_FIELD
];
1023 #define R(N, B) { B, 4, 0, FLD_C_r##N, FLD_O_r##N }
1024 #define M(N, B) { B, 4, 0, FLD_C_m##N, FLD_O_m##N }
1025 #define BD(N, BB, BD) { BB, 4, 0, FLD_C_b##N, FLD_O_b##N }, \
1026 { BD, 12, 0, FLD_C_d##N, FLD_O_d##N }
1027 #define BXD(N) { 16, 4, 0, FLD_C_b##N, FLD_O_b##N }, \
1028 { 12, 4, 0, FLD_C_x##N, FLD_O_x##N }, \
1029 { 20, 12, 0, FLD_C_d##N, FLD_O_d##N }
1030 #define BDL(N) { 16, 4, 0, FLD_C_b##N, FLD_O_b##N }, \
1031 { 20, 20, 2, FLD_C_d##N, FLD_O_d##N }
1032 #define BXDL(N) { 16, 4, 0, FLD_C_b##N, FLD_O_b##N }, \
1033 { 12, 4, 0, FLD_C_x##N, FLD_O_x##N }, \
1034 { 20, 20, 2, FLD_C_d##N, FLD_O_d##N }
1035 #define I(N, B, S) { B, S, 1, FLD_C_i##N, FLD_O_i##N }
1036 #define L(N, B, S) { B, S, 0, FLD_C_l##N, FLD_O_l##N }
1038 #define F0(N) { { } },
1039 #define F1(N, X1) { { X1 } },
1040 #define F2(N, X1, X2) { { X1, X2 } },
1041 #define F3(N, X1, X2, X3) { { X1, X2, X3 } },
1042 #define F4(N, X1, X2, X3, X4) { { X1, X2, X3, X4 } },
1043 #define F5(N, X1, X2, X3, X4, X5) { { X1, X2, X3, X4, X5 } },
1045 static const DisasFormatInfo format_info
[] = {
1046 #include "insn-format.def"
1064 /* Generally, we'll extract operands into this structures, operate upon
1065 them, and store them back. See the "in1", "in2", "prep", "wout" sets
1066 of routines below for more details. */
1068 bool g_out
, g_out2
, g_in1
, g_in2
;
1069 TCGv_i64 out
, out2
, in1
, in2
;
1073 /* Instructions can place constraints on their operands, raising specification
1074 exceptions if they are violated. To make this easy to automate, each "in1",
1075 "in2", "prep", "wout" helper will have a SPEC_<name> define that equals one
1076 of the following, or 0. To make this easy to document, we'll put the
1077 SPEC_<name> defines next to <name>. */
1079 #define SPEC_r1_even 1
1080 #define SPEC_r2_even 2
1081 #define SPEC_r3_even 4
1082 #define SPEC_r1_f128 8
1083 #define SPEC_r2_f128 16
1085 /* Return values from translate_one, indicating the state of the TB. */
1087 /* Continue the TB. */
1089 /* We have emitted one or more goto_tb. No fixup required. */
1091 /* We are not using a goto_tb (for whatever reason), but have updated
1092 the PC (for whatever reason), so there's no need to do it again on
1095 /* We are exiting the TB, but have neither emitted a goto_tb, nor
1096 updated the PC for the next instruction to be executed. */
1098 /* We are ending the TB with a noreturn function call, e.g. longjmp.
1099 No following code will be executed. */
1103 typedef enum DisasFacility
{
1104 FAC_Z
, /* zarch (default) */
1105 FAC_CASS
, /* compare and swap and store */
1106 FAC_CASS2
, /* compare and swap and store 2*/
1107 FAC_DFP
, /* decimal floating point */
1108 FAC_DFPR
, /* decimal floating point rounding */
1109 FAC_DO
, /* distinct operands */
1110 FAC_EE
, /* execute extensions */
1111 FAC_EI
, /* extended immediate */
1112 FAC_FPE
, /* floating point extension */
1113 FAC_FPSSH
, /* floating point support sign handling */
1114 FAC_FPRGR
, /* FPR-GR transfer */
1115 FAC_GIE
, /* general instructions extension */
1116 FAC_HFP_MA
, /* HFP multiply-and-add/subtract */
1117 FAC_HW
, /* high-word */
1118 FAC_IEEEE_SIM
, /* IEEE exception sumilation */
1119 FAC_LOC
, /* load/store on condition */
1120 FAC_LD
, /* long displacement */
1121 FAC_PC
, /* population count */
1122 FAC_SCF
, /* store clock fast */
1123 FAC_SFLE
, /* store facility list extended */
1129 DisasFacility fac
:8;
1134 void (*help_in1
)(DisasContext
*, DisasFields
*, DisasOps
*);
1135 void (*help_in2
)(DisasContext
*, DisasFields
*, DisasOps
*);
1136 void (*help_prep
)(DisasContext
*, DisasFields
*, DisasOps
*);
1137 void (*help_wout
)(DisasContext
*, DisasFields
*, DisasOps
*);
1138 void (*help_cout
)(DisasContext
*, DisasOps
*);
1139 ExitStatus (*help_op
)(DisasContext
*, DisasOps
*);
1144 /* ====================================================================== */
1145 /* Miscelaneous helpers, used by several operations. */
1147 static void help_l2_shift(DisasContext
*s
, DisasFields
*f
,
1148 DisasOps
*o
, int mask
)
1150 int b2
= get_field(f
, b2
);
1151 int d2
= get_field(f
, d2
);
1154 o
->in2
= tcg_const_i64(d2
& mask
);
1156 o
->in2
= get_address(s
, 0, b2
, d2
);
1157 tcg_gen_andi_i64(o
->in2
, o
->in2
, mask
);
1161 static ExitStatus
help_goto_direct(DisasContext
*s
, uint64_t dest
)
1163 if (dest
== s
->next_pc
) {
1166 if (use_goto_tb(s
, dest
)) {
1169 tcg_gen_movi_i64(psw_addr
, dest
);
1170 tcg_gen_exit_tb((tcg_target_long
)s
->tb
);
1171 return EXIT_GOTO_TB
;
1173 tcg_gen_movi_i64(psw_addr
, dest
);
1174 return EXIT_PC_UPDATED
;
1178 static ExitStatus
help_branch(DisasContext
*s
, DisasCompare
*c
,
1179 bool is_imm
, int imm
, TCGv_i64 cdest
)
1182 uint64_t dest
= s
->pc
+ 2 * imm
;
1185 /* Take care of the special cases first. */
1186 if (c
->cond
== TCG_COND_NEVER
) {
1191 if (dest
== s
->next_pc
) {
1192 /* Branch to next. */
1196 if (c
->cond
== TCG_COND_ALWAYS
) {
1197 ret
= help_goto_direct(s
, dest
);
1201 if (TCGV_IS_UNUSED_I64(cdest
)) {
1202 /* E.g. bcr %r0 -> no branch. */
1206 if (c
->cond
== TCG_COND_ALWAYS
) {
1207 tcg_gen_mov_i64(psw_addr
, cdest
);
1208 ret
= EXIT_PC_UPDATED
;
1213 if (use_goto_tb(s
, s
->next_pc
)) {
1214 if (is_imm
&& use_goto_tb(s
, dest
)) {
1215 /* Both exits can use goto_tb. */
1218 lab
= gen_new_label();
1220 tcg_gen_brcond_i64(c
->cond
, c
->u
.s64
.a
, c
->u
.s64
.b
, lab
);
1222 tcg_gen_brcond_i32(c
->cond
, c
->u
.s32
.a
, c
->u
.s32
.b
, lab
);
1225 /* Branch not taken. */
1227 tcg_gen_movi_i64(psw_addr
, s
->next_pc
);
1228 tcg_gen_exit_tb((tcg_target_long
)s
->tb
+ 0);
1233 tcg_gen_movi_i64(psw_addr
, dest
);
1234 tcg_gen_exit_tb((tcg_target_long
)s
->tb
+ 1);
1238 /* Fallthru can use goto_tb, but taken branch cannot. */
1239 /* Store taken branch destination before the brcond. This
1240 avoids having to allocate a new local temp to hold it.
1241 We'll overwrite this in the not taken case anyway. */
1243 tcg_gen_mov_i64(psw_addr
, cdest
);
1246 lab
= gen_new_label();
1248 tcg_gen_brcond_i64(c
->cond
, c
->u
.s64
.a
, c
->u
.s64
.b
, lab
);
1250 tcg_gen_brcond_i32(c
->cond
, c
->u
.s32
.a
, c
->u
.s32
.b
, lab
);
1253 /* Branch not taken. */
1256 tcg_gen_movi_i64(psw_addr
, s
->next_pc
);
1257 tcg_gen_exit_tb((tcg_target_long
)s
->tb
+ 0);
1261 tcg_gen_movi_i64(psw_addr
, dest
);
1263 ret
= EXIT_PC_UPDATED
;
1266 /* Fallthru cannot use goto_tb. This by itself is vanishingly rare.
1267 Most commonly we're single-stepping or some other condition that
1268 disables all use of goto_tb. Just update the PC and exit. */
1270 TCGv_i64 next
= tcg_const_i64(s
->next_pc
);
1272 cdest
= tcg_const_i64(dest
);
1276 tcg_gen_movcond_i64(c
->cond
, psw_addr
, c
->u
.s64
.a
, c
->u
.s64
.b
,
1279 TCGv_i32 t0
= tcg_temp_new_i32();
1280 TCGv_i64 t1
= tcg_temp_new_i64();
1281 TCGv_i64 z
= tcg_const_i64(0);
1282 tcg_gen_setcond_i32(c
->cond
, t0
, c
->u
.s32
.a
, c
->u
.s32
.b
);
1283 tcg_gen_extu_i32_i64(t1
, t0
);
1284 tcg_temp_free_i32(t0
);
1285 tcg_gen_movcond_i64(TCG_COND_NE
, psw_addr
, t1
, z
, cdest
, next
);
1286 tcg_temp_free_i64(t1
);
1287 tcg_temp_free_i64(z
);
1291 tcg_temp_free_i64(cdest
);
1293 tcg_temp_free_i64(next
);
1295 ret
= EXIT_PC_UPDATED
;
1303 /* ====================================================================== */
1304 /* The operations. These perform the bulk of the work for any insn,
1305 usually after the operands have been loaded and output initialized. */
1307 static ExitStatus
op_abs(DisasContext
*s
, DisasOps
*o
)
1309 gen_helper_abs_i64(o
->out
, o
->in2
);
1313 static ExitStatus
op_absf32(DisasContext
*s
, DisasOps
*o
)
1315 tcg_gen_andi_i64(o
->out
, o
->in2
, 0x7fffffffull
);
1319 static ExitStatus
op_absf64(DisasContext
*s
, DisasOps
*o
)
1321 tcg_gen_andi_i64(o
->out
, o
->in2
, 0x7fffffffffffffffull
);
1325 static ExitStatus
op_absf128(DisasContext
*s
, DisasOps
*o
)
1327 tcg_gen_andi_i64(o
->out
, o
->in1
, 0x7fffffffffffffffull
);
1328 tcg_gen_mov_i64(o
->out2
, o
->in2
);
1332 static ExitStatus
op_add(DisasContext
*s
, DisasOps
*o
)
1334 tcg_gen_add_i64(o
->out
, o
->in1
, o
->in2
);
1338 static ExitStatus
op_addc(DisasContext
*s
, DisasOps
*o
)
1343 tcg_gen_add_i64(o
->out
, o
->in1
, o
->in2
);
1345 /* The carry flag is the msb of CC, therefore the branch mask that would
1346 create that comparison is 3. Feeding the generated comparison to
1347 setcond produces the carry flag that we desire. */
1348 disas_jcc(s
, &cmp
, 3);
1349 carry
= tcg_temp_new_i64();
1351 tcg_gen_setcond_i64(cmp
.cond
, carry
, cmp
.u
.s64
.a
, cmp
.u
.s64
.b
);
1353 TCGv_i32 t
= tcg_temp_new_i32();
1354 tcg_gen_setcond_i32(cmp
.cond
, t
, cmp
.u
.s32
.a
, cmp
.u
.s32
.b
);
1355 tcg_gen_extu_i32_i64(carry
, t
);
1356 tcg_temp_free_i32(t
);
1360 tcg_gen_add_i64(o
->out
, o
->out
, carry
);
1361 tcg_temp_free_i64(carry
);
1365 static ExitStatus
op_aeb(DisasContext
*s
, DisasOps
*o
)
1367 gen_helper_aeb(o
->out
, cpu_env
, o
->in1
, o
->in2
);
1371 static ExitStatus
op_adb(DisasContext
*s
, DisasOps
*o
)
1373 gen_helper_adb(o
->out
, cpu_env
, o
->in1
, o
->in2
);
1377 static ExitStatus
op_axb(DisasContext
*s
, DisasOps
*o
)
1379 gen_helper_axb(o
->out
, cpu_env
, o
->out
, o
->out2
, o
->in1
, o
->in2
);
1380 return_low128(o
->out2
);
1384 static ExitStatus
op_and(DisasContext
*s
, DisasOps
*o
)
1386 tcg_gen_and_i64(o
->out
, o
->in1
, o
->in2
);
1390 static ExitStatus
op_andi(DisasContext
*s
, DisasOps
*o
)
1392 int shift
= s
->insn
->data
& 0xff;
1393 int size
= s
->insn
->data
>> 8;
1394 uint64_t mask
= ((1ull << size
) - 1) << shift
;
1397 tcg_gen_shli_i64(o
->in2
, o
->in2
, shift
);
1398 tcg_gen_ori_i64(o
->in2
, o
->in2
, ~mask
);
1399 tcg_gen_and_i64(o
->out
, o
->in1
, o
->in2
);
1401 /* Produce the CC from only the bits manipulated. */
1402 tcg_gen_andi_i64(cc_dst
, o
->out
, mask
);
1403 set_cc_nz_u64(s
, cc_dst
);
1407 static ExitStatus
op_bas(DisasContext
*s
, DisasOps
*o
)
1409 tcg_gen_movi_i64(o
->out
, pc_to_link_info(s
, s
->next_pc
));
1410 if (!TCGV_IS_UNUSED_I64(o
->in2
)) {
1411 tcg_gen_mov_i64(psw_addr
, o
->in2
);
1412 return EXIT_PC_UPDATED
;
1418 static ExitStatus
op_basi(DisasContext
*s
, DisasOps
*o
)
1420 tcg_gen_movi_i64(o
->out
, pc_to_link_info(s
, s
->next_pc
));
1421 return help_goto_direct(s
, s
->pc
+ 2 * get_field(s
->fields
, i2
));
1424 static ExitStatus
op_bc(DisasContext
*s
, DisasOps
*o
)
1426 int m1
= get_field(s
->fields
, m1
);
1427 bool is_imm
= have_field(s
->fields
, i2
);
1428 int imm
= is_imm
? get_field(s
->fields
, i2
) : 0;
1431 disas_jcc(s
, &c
, m1
);
1432 return help_branch(s
, &c
, is_imm
, imm
, o
->in2
);
1435 static ExitStatus
op_bct32(DisasContext
*s
, DisasOps
*o
)
1437 int r1
= get_field(s
->fields
, r1
);
1438 bool is_imm
= have_field(s
->fields
, i2
);
1439 int imm
= is_imm
? get_field(s
->fields
, i2
) : 0;
1443 c
.cond
= TCG_COND_NE
;
1448 t
= tcg_temp_new_i64();
1449 tcg_gen_subi_i64(t
, regs
[r1
], 1);
1450 store_reg32_i64(r1
, t
);
1451 c
.u
.s32
.a
= tcg_temp_new_i32();
1452 c
.u
.s32
.b
= tcg_const_i32(0);
1453 tcg_gen_trunc_i64_i32(c
.u
.s32
.a
, t
);
1454 tcg_temp_free_i64(t
);
1456 return help_branch(s
, &c
, is_imm
, imm
, o
->in2
);
1459 static ExitStatus
op_bct64(DisasContext
*s
, DisasOps
*o
)
1461 int r1
= get_field(s
->fields
, r1
);
1462 bool is_imm
= have_field(s
->fields
, i2
);
1463 int imm
= is_imm
? get_field(s
->fields
, i2
) : 0;
1466 c
.cond
= TCG_COND_NE
;
1471 tcg_gen_subi_i64(regs
[r1
], regs
[r1
], 1);
1472 c
.u
.s64
.a
= regs
[r1
];
1473 c
.u
.s64
.b
= tcg_const_i64(0);
1475 return help_branch(s
, &c
, is_imm
, imm
, o
->in2
);
1478 static ExitStatus
op_bx32(DisasContext
*s
, DisasOps
*o
)
1480 int r1
= get_field(s
->fields
, r1
);
1481 int r3
= get_field(s
->fields
, r3
);
1482 bool is_imm
= have_field(s
->fields
, i2
);
1483 int imm
= is_imm
? get_field(s
->fields
, i2
) : 0;
1487 c
.cond
= (s
->insn
->data
? TCG_COND_LE
: TCG_COND_GT
);
1492 t
= tcg_temp_new_i64();
1493 tcg_gen_add_i64(t
, regs
[r1
], regs
[r3
]);
1494 c
.u
.s32
.a
= tcg_temp_new_i32();
1495 c
.u
.s32
.b
= tcg_temp_new_i32();
1496 tcg_gen_trunc_i64_i32(c
.u
.s32
.a
, t
);
1497 tcg_gen_trunc_i64_i32(c
.u
.s32
.b
, regs
[r3
| 1]);
1498 store_reg32_i64(r1
, t
);
1499 tcg_temp_free_i64(t
);
1501 return help_branch(s
, &c
, is_imm
, imm
, o
->in2
);
1504 static ExitStatus
op_bx64(DisasContext
*s
, DisasOps
*o
)
1506 int r1
= get_field(s
->fields
, r1
);
1507 int r3
= get_field(s
->fields
, r3
);
1508 bool is_imm
= have_field(s
->fields
, i2
);
1509 int imm
= is_imm
? get_field(s
->fields
, i2
) : 0;
1512 c
.cond
= (s
->insn
->data
? TCG_COND_LE
: TCG_COND_GT
);
1515 if (r1
== (r3
| 1)) {
1516 c
.u
.s64
.b
= load_reg(r3
| 1);
1519 c
.u
.s64
.b
= regs
[r3
| 1];
1523 tcg_gen_add_i64(regs
[r1
], regs
[r1
], regs
[r3
]);
1524 c
.u
.s64
.a
= regs
[r1
];
1527 return help_branch(s
, &c
, is_imm
, imm
, o
->in2
);
1530 static ExitStatus
op_cj(DisasContext
*s
, DisasOps
*o
)
1532 int imm
, m3
= get_field(s
->fields
, m3
);
1536 c
.cond
= ltgt_cond
[m3
];
1537 if (s
->insn
->data
) {
1538 c
.cond
= tcg_unsigned_cond(c
.cond
);
1540 c
.is_64
= c
.g1
= c
.g2
= true;
1544 is_imm
= have_field(s
->fields
, i4
);
1546 imm
= get_field(s
->fields
, i4
);
1549 o
->out
= get_address(s
, 0, get_field(s
->fields
, b4
),
1550 get_field(s
->fields
, d4
));
1553 return help_branch(s
, &c
, is_imm
, imm
, o
->out
);
1556 static ExitStatus
op_ceb(DisasContext
*s
, DisasOps
*o
)
1558 gen_helper_ceb(cc_op
, cpu_env
, o
->in1
, o
->in2
);
1563 static ExitStatus
op_cdb(DisasContext
*s
, DisasOps
*o
)
1565 gen_helper_cdb(cc_op
, cpu_env
, o
->in1
, o
->in2
);
1570 static ExitStatus
op_cxb(DisasContext
*s
, DisasOps
*o
)
1572 gen_helper_cxb(cc_op
, cpu_env
, o
->out
, o
->out2
, o
->in1
, o
->in2
);
1577 static ExitStatus
op_cfeb(DisasContext
*s
, DisasOps
*o
)
1579 TCGv_i32 m3
= tcg_const_i32(get_field(s
->fields
, m3
));
1580 gen_helper_cfeb(o
->out
, cpu_env
, o
->in2
, m3
);
1581 tcg_temp_free_i32(m3
);
1582 gen_set_cc_nz_f32(s
, o
->in2
);
1586 static ExitStatus
op_cfdb(DisasContext
*s
, DisasOps
*o
)
1588 TCGv_i32 m3
= tcg_const_i32(get_field(s
->fields
, m3
));
1589 gen_helper_cfdb(o
->out
, cpu_env
, o
->in2
, m3
);
1590 tcg_temp_free_i32(m3
);
1591 gen_set_cc_nz_f64(s
, o
->in2
);
1595 static ExitStatus
op_cfxb(DisasContext
*s
, DisasOps
*o
)
1597 TCGv_i32 m3
= tcg_const_i32(get_field(s
->fields
, m3
));
1598 gen_helper_cfxb(o
->out
, cpu_env
, o
->in1
, o
->in2
, m3
);
1599 tcg_temp_free_i32(m3
);
1600 gen_set_cc_nz_f128(s
, o
->in1
, o
->in2
);
1604 static ExitStatus
op_cgeb(DisasContext
*s
, DisasOps
*o
)
1606 TCGv_i32 m3
= tcg_const_i32(get_field(s
->fields
, m3
));
1607 gen_helper_cgeb(o
->out
, cpu_env
, o
->in2
, m3
);
1608 tcg_temp_free_i32(m3
);
1609 gen_set_cc_nz_f32(s
, o
->in2
);
1613 static ExitStatus
op_cgdb(DisasContext
*s
, DisasOps
*o
)
1615 TCGv_i32 m3
= tcg_const_i32(get_field(s
->fields
, m3
));
1616 gen_helper_cgdb(o
->out
, cpu_env
, o
->in2
, m3
);
1617 tcg_temp_free_i32(m3
);
1618 gen_set_cc_nz_f64(s
, o
->in2
);
1622 static ExitStatus
op_cgxb(DisasContext
*s
, DisasOps
*o
)
1624 TCGv_i32 m3
= tcg_const_i32(get_field(s
->fields
, m3
));
1625 gen_helper_cgxb(o
->out
, cpu_env
, o
->in1
, o
->in2
, m3
);
1626 tcg_temp_free_i32(m3
);
1627 gen_set_cc_nz_f128(s
, o
->in1
, o
->in2
);
1631 static ExitStatus
op_clfeb(DisasContext
*s
, DisasOps
*o
)
1633 TCGv_i32 m3
= tcg_const_i32(get_field(s
->fields
, m3
));
1634 gen_helper_clfeb(o
->out
, cpu_env
, o
->in2
, m3
);
1635 tcg_temp_free_i32(m3
);
1636 gen_set_cc_nz_f32(s
, o
->in2
);
1640 static ExitStatus
op_clfdb(DisasContext
*s
, DisasOps
*o
)
1642 TCGv_i32 m3
= tcg_const_i32(get_field(s
->fields
, m3
));
1643 gen_helper_clfdb(o
->out
, cpu_env
, o
->in2
, m3
);
1644 tcg_temp_free_i32(m3
);
1645 gen_set_cc_nz_f64(s
, o
->in2
);
1649 static ExitStatus
op_clfxb(DisasContext
*s
, DisasOps
*o
)
1651 TCGv_i32 m3
= tcg_const_i32(get_field(s
->fields
, m3
));
1652 gen_helper_clfxb(o
->out
, cpu_env
, o
->in1
, o
->in2
, m3
);
1653 tcg_temp_free_i32(m3
);
1654 gen_set_cc_nz_f128(s
, o
->in1
, o
->in2
);
1658 static ExitStatus
op_clgeb(DisasContext
*s
, DisasOps
*o
)
1660 TCGv_i32 m3
= tcg_const_i32(get_field(s
->fields
, m3
));
1661 gen_helper_clgeb(o
->out
, cpu_env
, o
->in2
, m3
);
1662 tcg_temp_free_i32(m3
);
1663 gen_set_cc_nz_f32(s
, o
->in2
);
1667 static ExitStatus
op_clgdb(DisasContext
*s
, DisasOps
*o
)
1669 TCGv_i32 m3
= tcg_const_i32(get_field(s
->fields
, m3
));
1670 gen_helper_clgdb(o
->out
, cpu_env
, o
->in2
, m3
);
1671 tcg_temp_free_i32(m3
);
1672 gen_set_cc_nz_f64(s
, o
->in2
);
1676 static ExitStatus
op_clgxb(DisasContext
*s
, DisasOps
*o
)
1678 TCGv_i32 m3
= tcg_const_i32(get_field(s
->fields
, m3
));
1679 gen_helper_clgxb(o
->out
, cpu_env
, o
->in1
, o
->in2
, m3
);
1680 tcg_temp_free_i32(m3
);
1681 gen_set_cc_nz_f128(s
, o
->in1
, o
->in2
);
1685 static ExitStatus
op_cegb(DisasContext
*s
, DisasOps
*o
)
1687 TCGv_i32 m3
= tcg_const_i32(get_field(s
->fields
, m3
));
1688 gen_helper_cegb(o
->out
, cpu_env
, o
->in2
, m3
);
1689 tcg_temp_free_i32(m3
);
1693 static ExitStatus
op_cdgb(DisasContext
*s
, DisasOps
*o
)
1695 TCGv_i32 m3
= tcg_const_i32(get_field(s
->fields
, m3
));
1696 gen_helper_cdgb(o
->out
, cpu_env
, o
->in2
, m3
);
1697 tcg_temp_free_i32(m3
);
1701 static ExitStatus
op_cxgb(DisasContext
*s
, DisasOps
*o
)
1703 TCGv_i32 m3
= tcg_const_i32(get_field(s
->fields
, m3
));
1704 gen_helper_cxgb(o
->out
, cpu_env
, o
->in2
, m3
);
1705 tcg_temp_free_i32(m3
);
1706 return_low128(o
->out2
);
1710 static ExitStatus
op_celgb(DisasContext
*s
, DisasOps
*o
)
1712 TCGv_i32 m3
= tcg_const_i32(get_field(s
->fields
, m3
));
1713 gen_helper_celgb(o
->out
, cpu_env
, o
->in2
, m3
);
1714 tcg_temp_free_i32(m3
);
1718 static ExitStatus
op_cdlgb(DisasContext
*s
, DisasOps
*o
)
1720 TCGv_i32 m3
= tcg_const_i32(get_field(s
->fields
, m3
));
1721 gen_helper_cdlgb(o
->out
, cpu_env
, o
->in2
, m3
);
1722 tcg_temp_free_i32(m3
);
1726 static ExitStatus
op_cxlgb(DisasContext
*s
, DisasOps
*o
)
1728 TCGv_i32 m3
= tcg_const_i32(get_field(s
->fields
, m3
));
1729 gen_helper_cxlgb(o
->out
, cpu_env
, o
->in2
, m3
);
1730 tcg_temp_free_i32(m3
);
1731 return_low128(o
->out2
);
1735 static ExitStatus
op_cksm(DisasContext
*s
, DisasOps
*o
)
1737 int r2
= get_field(s
->fields
, r2
);
1738 TCGv_i64 len
= tcg_temp_new_i64();
1740 potential_page_fault(s
);
1741 gen_helper_cksm(len
, cpu_env
, o
->in1
, o
->in2
, regs
[r2
+ 1]);
1743 return_low128(o
->out
);
1745 tcg_gen_add_i64(regs
[r2
], regs
[r2
], len
);
1746 tcg_gen_sub_i64(regs
[r2
+ 1], regs
[r2
+ 1], len
);
1747 tcg_temp_free_i64(len
);
1752 static ExitStatus
op_clc(DisasContext
*s
, DisasOps
*o
)
1754 int l
= get_field(s
->fields
, l1
);
1759 tcg_gen_qemu_ld8u(cc_src
, o
->addr1
, get_mem_index(s
));
1760 tcg_gen_qemu_ld8u(cc_dst
, o
->in2
, get_mem_index(s
));
1763 tcg_gen_qemu_ld16u(cc_src
, o
->addr1
, get_mem_index(s
));
1764 tcg_gen_qemu_ld16u(cc_dst
, o
->in2
, get_mem_index(s
));
1767 tcg_gen_qemu_ld32u(cc_src
, o
->addr1
, get_mem_index(s
));
1768 tcg_gen_qemu_ld32u(cc_dst
, o
->in2
, get_mem_index(s
));
1771 tcg_gen_qemu_ld64(cc_src
, o
->addr1
, get_mem_index(s
));
1772 tcg_gen_qemu_ld64(cc_dst
, o
->in2
, get_mem_index(s
));
1775 potential_page_fault(s
);
1776 vl
= tcg_const_i32(l
);
1777 gen_helper_clc(cc_op
, cpu_env
, vl
, o
->addr1
, o
->in2
);
1778 tcg_temp_free_i32(vl
);
1782 gen_op_update2_cc_i64(s
, CC_OP_LTUGTU_64
, cc_src
, cc_dst
);
1786 static ExitStatus
op_clcle(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 gen_helper_clcle(cc_op
, cpu_env
, r1
, o
->in2
, r3
);
1792 tcg_temp_free_i32(r1
);
1793 tcg_temp_free_i32(r3
);
1798 static ExitStatus
op_clm(DisasContext
*s
, DisasOps
*o
)
1800 TCGv_i32 m3
= tcg_const_i32(get_field(s
->fields
, m3
));
1801 TCGv_i32 t1
= tcg_temp_new_i32();
1802 tcg_gen_trunc_i64_i32(t1
, o
->in1
);
1803 potential_page_fault(s
);
1804 gen_helper_clm(cc_op
, cpu_env
, t1
, m3
, o
->in2
);
1806 tcg_temp_free_i32(t1
);
1807 tcg_temp_free_i32(m3
);
1811 static ExitStatus
op_clst(DisasContext
*s
, DisasOps
*o
)
1813 potential_page_fault(s
);
1814 gen_helper_clst(o
->in1
, cpu_env
, regs
[0], o
->in1
, o
->in2
);
1816 return_low128(o
->in2
);
1820 static ExitStatus
op_cps(DisasContext
*s
, DisasOps
*o
)
1822 TCGv_i64 t
= tcg_temp_new_i64();
1823 tcg_gen_andi_i64(t
, o
->in1
, 0x8000000000000000ull
);
1824 tcg_gen_andi_i64(o
->out
, o
->in2
, 0x7fffffffffffffffull
);
1825 tcg_gen_or_i64(o
->out
, o
->out
, t
);
1826 tcg_temp_free_i64(t
);
1830 static ExitStatus
op_cs(DisasContext
*s
, DisasOps
*o
)
1832 /* FIXME: needs an atomic solution for CONFIG_USER_ONLY. */
1833 int d2
= get_field(s
->fields
, d2
);
1834 int b2
= get_field(s
->fields
, b2
);
1835 int is_64
= s
->insn
->data
;
1836 TCGv_i64 addr
, mem
, cc
, z
;
1838 /* Note that in1 = R3 (new value) and
1839 in2 = (zero-extended) R1 (expected value). */
1841 /* Load the memory into the (temporary) output. While the PoO only talks
1842 about moving the memory to R1 on inequality, if we include equality it
1843 means that R1 is equal to the memory in all conditions. */
1844 addr
= get_address(s
, 0, b2
, d2
);
1846 tcg_gen_qemu_ld64(o
->out
, addr
, get_mem_index(s
));
1848 tcg_gen_qemu_ld32u(o
->out
, addr
, get_mem_index(s
));
1851 /* Are the memory and expected values (un)equal? Note that this setcond
1852 produces the output CC value, thus the NE sense of the test. */
1853 cc
= tcg_temp_new_i64();
1854 tcg_gen_setcond_i64(TCG_COND_NE
, cc
, o
->in2
, o
->out
);
1856 /* If the memory and expected values are equal (CC==0), copy R3 to MEM.
1857 Recall that we are allowed to unconditionally issue the store (and
1858 thus any possible write trap), so (re-)store the original contents
1859 of MEM in case of inequality. */
1860 z
= tcg_const_i64(0);
1861 mem
= tcg_temp_new_i64();
1862 tcg_gen_movcond_i64(TCG_COND_EQ
, mem
, cc
, z
, o
->in1
, o
->out
);
1864 tcg_gen_qemu_st64(mem
, addr
, get_mem_index(s
));
1866 tcg_gen_qemu_st32(mem
, addr
, get_mem_index(s
));
1868 tcg_temp_free_i64(z
);
1869 tcg_temp_free_i64(mem
);
1870 tcg_temp_free_i64(addr
);
1872 /* Store CC back to cc_op. Wait until after the store so that any
1873 exception gets the old cc_op value. */
1874 tcg_gen_trunc_i64_i32(cc_op
, cc
);
1875 tcg_temp_free_i64(cc
);
1880 static ExitStatus
op_cdsg(DisasContext
*s
, DisasOps
*o
)
1882 /* FIXME: needs an atomic solution for CONFIG_USER_ONLY. */
1883 int r1
= get_field(s
->fields
, r1
);
1884 int r3
= get_field(s
->fields
, r3
);
1885 int d2
= get_field(s
->fields
, d2
);
1886 int b2
= get_field(s
->fields
, b2
);
1887 TCGv_i64 addrh
, addrl
, memh
, meml
, outh
, outl
, cc
, z
;
1889 /* Note that R1:R1+1 = expected value and R3:R3+1 = new value. */
1891 addrh
= get_address(s
, 0, b2
, d2
);
1892 addrl
= get_address(s
, 0, b2
, d2
+ 8);
1893 outh
= tcg_temp_new_i64();
1894 outl
= tcg_temp_new_i64();
1896 tcg_gen_qemu_ld64(outh
, addrh
, get_mem_index(s
));
1897 tcg_gen_qemu_ld64(outl
, addrl
, get_mem_index(s
));
1899 /* Fold the double-word compare with arithmetic. */
1900 cc
= tcg_temp_new_i64();
1901 z
= tcg_temp_new_i64();
1902 tcg_gen_xor_i64(cc
, outh
, regs
[r1
]);
1903 tcg_gen_xor_i64(z
, outl
, regs
[r1
+ 1]);
1904 tcg_gen_or_i64(cc
, cc
, z
);
1905 tcg_gen_movi_i64(z
, 0);
1906 tcg_gen_setcond_i64(TCG_COND_NE
, cc
, cc
, z
);
1908 memh
= tcg_temp_new_i64();
1909 meml
= tcg_temp_new_i64();
1910 tcg_gen_movcond_i64(TCG_COND_EQ
, memh
, cc
, z
, regs
[r3
], outh
);
1911 tcg_gen_movcond_i64(TCG_COND_EQ
, meml
, cc
, z
, regs
[r3
+ 1], outl
);
1912 tcg_temp_free_i64(z
);
1914 tcg_gen_qemu_st64(memh
, addrh
, get_mem_index(s
));
1915 tcg_gen_qemu_st64(meml
, addrl
, get_mem_index(s
));
1916 tcg_temp_free_i64(memh
);
1917 tcg_temp_free_i64(meml
);
1918 tcg_temp_free_i64(addrh
);
1919 tcg_temp_free_i64(addrl
);
1921 /* Save back state now that we've passed all exceptions. */
1922 tcg_gen_mov_i64(regs
[r1
], outh
);
1923 tcg_gen_mov_i64(regs
[r1
+ 1], outl
);
1924 tcg_gen_trunc_i64_i32(cc_op
, cc
);
1925 tcg_temp_free_i64(outh
);
1926 tcg_temp_free_i64(outl
);
1927 tcg_temp_free_i64(cc
);
1932 #ifndef CONFIG_USER_ONLY
1933 static ExitStatus
op_csp(DisasContext
*s
, DisasOps
*o
)
1935 TCGv_i32 r1
= tcg_const_i32(get_field(s
->fields
, r1
));
1936 check_privileged(s
);
1937 gen_helper_csp(cc_op
, cpu_env
, r1
, o
->in2
);
1938 tcg_temp_free_i32(r1
);
1944 static ExitStatus
op_cvd(DisasContext
*s
, DisasOps
*o
)
1946 TCGv_i64 t1
= tcg_temp_new_i64();
1947 TCGv_i32 t2
= tcg_temp_new_i32();
1948 tcg_gen_trunc_i64_i32(t2
, o
->in1
);
1949 gen_helper_cvd(t1
, t2
);
1950 tcg_temp_free_i32(t2
);
1951 tcg_gen_qemu_st64(t1
, o
->in2
, get_mem_index(s
));
1952 tcg_temp_free_i64(t1
);
1956 static ExitStatus
op_ct(DisasContext
*s
, DisasOps
*o
)
1958 int m3
= get_field(s
->fields
, m3
);
1959 int lab
= gen_new_label();
1963 c
= tcg_invert_cond(ltgt_cond
[m3
]);
1964 if (s
->insn
->data
) {
1965 c
= tcg_unsigned_cond(c
);
1967 tcg_gen_brcond_i64(c
, o
->in1
, o
->in2
, lab
);
1969 /* Set DXC to 0xff. */
1970 t
= tcg_temp_new_i32();
1971 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUS390XState
, fpc
));
1972 tcg_gen_ori_i32(t
, t
, 0xff00);
1973 tcg_gen_st_i32(t
, cpu_env
, offsetof(CPUS390XState
, fpc
));
1974 tcg_temp_free_i32(t
);
1977 gen_program_exception(s
, PGM_DATA
);
1983 #ifndef CONFIG_USER_ONLY
1984 static ExitStatus
op_diag(DisasContext
*s
, DisasOps
*o
)
1988 check_privileged(s
);
1989 potential_page_fault(s
);
1991 /* We pretend the format is RX_a so that D2 is the field we want. */
1992 tmp
= tcg_const_i32(get_field(s
->fields
, d2
) & 0xfff);
1993 gen_helper_diag(regs
[2], cpu_env
, tmp
, regs
[2], regs
[1]);
1994 tcg_temp_free_i32(tmp
);
1999 static ExitStatus
op_divs32(DisasContext
*s
, DisasOps
*o
)
2001 gen_helper_divs32(o
->out2
, cpu_env
, o
->in1
, o
->in2
);
2002 return_low128(o
->out
);
2006 static ExitStatus
op_divu32(DisasContext
*s
, DisasOps
*o
)
2008 gen_helper_divu32(o
->out2
, cpu_env
, o
->in1
, o
->in2
);
2009 return_low128(o
->out
);
2013 static ExitStatus
op_divs64(DisasContext
*s
, DisasOps
*o
)
2015 gen_helper_divs64(o
->out2
, cpu_env
, o
->in1
, o
->in2
);
2016 return_low128(o
->out
);
2020 static ExitStatus
op_divu64(DisasContext
*s
, DisasOps
*o
)
2022 gen_helper_divu64(o
->out2
, cpu_env
, o
->out
, o
->out2
, o
->in2
);
2023 return_low128(o
->out
);
2027 static ExitStatus
op_deb(DisasContext
*s
, DisasOps
*o
)
2029 gen_helper_deb(o
->out
, cpu_env
, o
->in1
, o
->in2
);
2033 static ExitStatus
op_ddb(DisasContext
*s
, DisasOps
*o
)
2035 gen_helper_ddb(o
->out
, cpu_env
, o
->in1
, o
->in2
);
2039 static ExitStatus
op_dxb(DisasContext
*s
, DisasOps
*o
)
2041 gen_helper_dxb(o
->out
, cpu_env
, o
->out
, o
->out2
, o
->in1
, o
->in2
);
2042 return_low128(o
->out2
);
2046 static ExitStatus
op_ear(DisasContext
*s
, DisasOps
*o
)
2048 int r2
= get_field(s
->fields
, r2
);
2049 tcg_gen_ld32u_i64(o
->out
, cpu_env
, offsetof(CPUS390XState
, aregs
[r2
]));
2053 static ExitStatus
op_efpc(DisasContext
*s
, DisasOps
*o
)
2055 tcg_gen_ld32u_i64(o
->out
, cpu_env
, offsetof(CPUS390XState
, fpc
));
2059 static ExitStatus
op_ex(DisasContext
*s
, DisasOps
*o
)
2061 /* ??? Perhaps a better way to implement EXECUTE is to set a bit in
2062 tb->flags, (ab)use the tb->cs_base field as the address of
2063 the template in memory, and grab 8 bits of tb->flags/cflags for
2064 the contents of the register. We would then recognize all this
2065 in gen_intermediate_code_internal, generating code for exactly
2066 one instruction. This new TB then gets executed normally.
2068 On the other hand, this seems to be mostly used for modifying
2069 MVC inside of memcpy, which needs a helper call anyway. So
2070 perhaps this doesn't bear thinking about any further. */
2077 tmp
= tcg_const_i64(s
->next_pc
);
2078 gen_helper_ex(cc_op
, cpu_env
, cc_op
, o
->in1
, o
->in2
, tmp
);
2079 tcg_temp_free_i64(tmp
);
2085 static ExitStatus
op_flogr(DisasContext
*s
, DisasOps
*o
)
2087 /* We'll use the original input for cc computation, since we get to
2088 compare that against 0, which ought to be better than comparing
2089 the real output against 64. It also lets cc_dst be a convenient
2090 temporary during our computation. */
2091 gen_op_update1_cc_i64(s
, CC_OP_FLOGR
, o
->in2
);
2093 /* R1 = IN ? CLZ(IN) : 64. */
2094 gen_helper_clz(o
->out
, o
->in2
);
2096 /* R1+1 = IN & ~(found bit). Note that we may attempt to shift this
2097 value by 64, which is undefined. But since the shift is 64 iff the
2098 input is zero, we still get the correct result after and'ing. */
2099 tcg_gen_movi_i64(o
->out2
, 0x8000000000000000ull
);
2100 tcg_gen_shr_i64(o
->out2
, o
->out2
, o
->out
);
2101 tcg_gen_andc_i64(o
->out2
, cc_dst
, o
->out2
);
2105 static ExitStatus
op_icm(DisasContext
*s
, DisasOps
*o
)
2107 int m3
= get_field(s
->fields
, m3
);
2108 int pos
, len
, base
= s
->insn
->data
;
2109 TCGv_i64 tmp
= tcg_temp_new_i64();
2114 /* Effectively a 32-bit load. */
2115 tcg_gen_qemu_ld32u(tmp
, o
->in2
, get_mem_index(s
));
2122 /* Effectively a 16-bit load. */
2123 tcg_gen_qemu_ld16u(tmp
, o
->in2
, get_mem_index(s
));
2131 /* Effectively an 8-bit load. */
2132 tcg_gen_qemu_ld8u(tmp
, o
->in2
, get_mem_index(s
));
2137 pos
= base
+ ctz32(m3
) * 8;
2138 tcg_gen_deposit_i64(o
->out
, o
->out
, tmp
, pos
, len
);
2139 ccm
= ((1ull << len
) - 1) << pos
;
2143 /* This is going to be a sequence of loads and inserts. */
2144 pos
= base
+ 32 - 8;
2148 tcg_gen_qemu_ld8u(tmp
, o
->in2
, get_mem_index(s
));
2149 tcg_gen_addi_i64(o
->in2
, o
->in2
, 1);
2150 tcg_gen_deposit_i64(o
->out
, o
->out
, tmp
, pos
, 8);
2153 m3
= (m3
<< 1) & 0xf;
2159 tcg_gen_movi_i64(tmp
, ccm
);
2160 gen_op_update2_cc_i64(s
, CC_OP_ICM
, tmp
, o
->out
);
2161 tcg_temp_free_i64(tmp
);
2165 static ExitStatus
op_insi(DisasContext
*s
, DisasOps
*o
)
2167 int shift
= s
->insn
->data
& 0xff;
2168 int size
= s
->insn
->data
>> 8;
2169 tcg_gen_deposit_i64(o
->out
, o
->in1
, o
->in2
, shift
, size
);
2173 static ExitStatus
op_ipm(DisasContext
*s
, DisasOps
*o
)
2178 tcg_gen_andi_i64(o
->out
, o
->out
, ~0xff000000ull
);
2180 t1
= tcg_temp_new_i64();
2181 tcg_gen_shli_i64(t1
, psw_mask
, 20);
2182 tcg_gen_shri_i64(t1
, t1
, 36);
2183 tcg_gen_or_i64(o
->out
, o
->out
, t1
);
2185 tcg_gen_extu_i32_i64(t1
, cc_op
);
2186 tcg_gen_shli_i64(t1
, t1
, 28);
2187 tcg_gen_or_i64(o
->out
, o
->out
, t1
);
2188 tcg_temp_free_i64(t1
);
2192 #ifndef CONFIG_USER_ONLY
2193 static ExitStatus
op_ipte(DisasContext
*s
, DisasOps
*o
)
2195 check_privileged(s
);
2196 gen_helper_ipte(cpu_env
, o
->in1
, o
->in2
);
2200 static ExitStatus
op_iske(DisasContext
*s
, DisasOps
*o
)
2202 check_privileged(s
);
2203 gen_helper_iske(o
->out
, cpu_env
, o
->in2
);
2208 static ExitStatus
op_ldeb(DisasContext
*s
, DisasOps
*o
)
2210 gen_helper_ldeb(o
->out
, cpu_env
, o
->in2
);
2214 static ExitStatus
op_ledb(DisasContext
*s
, DisasOps
*o
)
2216 gen_helper_ledb(o
->out
, cpu_env
, o
->in2
);
2220 static ExitStatus
op_ldxb(DisasContext
*s
, DisasOps
*o
)
2222 gen_helper_ldxb(o
->out
, cpu_env
, o
->in1
, o
->in2
);
2226 static ExitStatus
op_lexb(DisasContext
*s
, DisasOps
*o
)
2228 gen_helper_lexb(o
->out
, cpu_env
, o
->in1
, o
->in2
);
2232 static ExitStatus
op_lxdb(DisasContext
*s
, DisasOps
*o
)
2234 gen_helper_lxdb(o
->out
, cpu_env
, o
->in2
);
2235 return_low128(o
->out2
);
2239 static ExitStatus
op_lxeb(DisasContext
*s
, DisasOps
*o
)
2241 gen_helper_lxeb(o
->out
, cpu_env
, o
->in2
);
2242 return_low128(o
->out2
);
2246 static ExitStatus
op_llgt(DisasContext
*s
, DisasOps
*o
)
2248 tcg_gen_andi_i64(o
->out
, o
->in2
, 0x7fffffff);
2252 static ExitStatus
op_ld8s(DisasContext
*s
, DisasOps
*o
)
2254 tcg_gen_qemu_ld8s(o
->out
, o
->in2
, get_mem_index(s
));
2258 static ExitStatus
op_ld8u(DisasContext
*s
, DisasOps
*o
)
2260 tcg_gen_qemu_ld8u(o
->out
, o
->in2
, get_mem_index(s
));
2264 static ExitStatus
op_ld16s(DisasContext
*s
, DisasOps
*o
)
2266 tcg_gen_qemu_ld16s(o
->out
, o
->in2
, get_mem_index(s
));
2270 static ExitStatus
op_ld16u(DisasContext
*s
, DisasOps
*o
)
2272 tcg_gen_qemu_ld16u(o
->out
, o
->in2
, get_mem_index(s
));
2276 static ExitStatus
op_ld32s(DisasContext
*s
, DisasOps
*o
)
2278 tcg_gen_qemu_ld32s(o
->out
, o
->in2
, get_mem_index(s
));
2282 static ExitStatus
op_ld32u(DisasContext
*s
, DisasOps
*o
)
2284 tcg_gen_qemu_ld32u(o
->out
, o
->in2
, get_mem_index(s
));
2288 static ExitStatus
op_ld64(DisasContext
*s
, DisasOps
*o
)
2290 tcg_gen_qemu_ld64(o
->out
, o
->in2
, get_mem_index(s
));
2294 static ExitStatus
op_loc(DisasContext
*s
, DisasOps
*o
)
2298 disas_jcc(s
, &c
, get_field(s
->fields
, m3
));
2301 tcg_gen_movcond_i64(c
.cond
, o
->out
, c
.u
.s64
.a
, c
.u
.s64
.b
,
2305 TCGv_i32 t32
= tcg_temp_new_i32();
2308 tcg_gen_setcond_i32(c
.cond
, t32
, c
.u
.s32
.a
, c
.u
.s32
.b
);
2311 t
= tcg_temp_new_i64();
2312 tcg_gen_extu_i32_i64(t
, t32
);
2313 tcg_temp_free_i32(t32
);
2315 z
= tcg_const_i64(0);
2316 tcg_gen_movcond_i64(TCG_COND_NE
, o
->out
, t
, z
, o
->in2
, o
->in1
);
2317 tcg_temp_free_i64(t
);
2318 tcg_temp_free_i64(z
);
2324 #ifndef CONFIG_USER_ONLY
2325 static ExitStatus
op_lctl(DisasContext
*s
, DisasOps
*o
)
2327 TCGv_i32 r1
= tcg_const_i32(get_field(s
->fields
, r1
));
2328 TCGv_i32 r3
= tcg_const_i32(get_field(s
->fields
, r3
));
2329 check_privileged(s
);
2330 potential_page_fault(s
);
2331 gen_helper_lctl(cpu_env
, r1
, o
->in2
, r3
);
2332 tcg_temp_free_i32(r1
);
2333 tcg_temp_free_i32(r3
);
2337 static ExitStatus
op_lctlg(DisasContext
*s
, DisasOps
*o
)
2339 TCGv_i32 r1
= tcg_const_i32(get_field(s
->fields
, r1
));
2340 TCGv_i32 r3
= tcg_const_i32(get_field(s
->fields
, r3
));
2341 check_privileged(s
);
2342 potential_page_fault(s
);
2343 gen_helper_lctlg(cpu_env
, r1
, o
->in2
, r3
);
2344 tcg_temp_free_i32(r1
);
2345 tcg_temp_free_i32(r3
);
2348 static ExitStatus
op_lra(DisasContext
*s
, DisasOps
*o
)
2350 check_privileged(s
);
2351 potential_page_fault(s
);
2352 gen_helper_lra(o
->out
, cpu_env
, o
->in2
);
2357 static ExitStatus
op_lpsw(DisasContext
*s
, DisasOps
*o
)
2361 check_privileged(s
);
2363 t1
= tcg_temp_new_i64();
2364 t2
= tcg_temp_new_i64();
2365 tcg_gen_qemu_ld32u(t1
, o
->in2
, get_mem_index(s
));
2366 tcg_gen_addi_i64(o
->in2
, o
->in2
, 4);
2367 tcg_gen_qemu_ld32u(t2
, o
->in2
, get_mem_index(s
));
2368 /* Convert the 32-bit PSW_MASK into the 64-bit PSW_MASK. */
2369 tcg_gen_shli_i64(t1
, t1
, 32);
2370 gen_helper_load_psw(cpu_env
, t1
, t2
);
2371 tcg_temp_free_i64(t1
);
2372 tcg_temp_free_i64(t2
);
2373 return EXIT_NORETURN
;
2376 static ExitStatus
op_lpswe(DisasContext
*s
, DisasOps
*o
)
2380 check_privileged(s
);
2382 t1
= tcg_temp_new_i64();
2383 t2
= tcg_temp_new_i64();
2384 tcg_gen_qemu_ld64(t1
, o
->in2
, get_mem_index(s
));
2385 tcg_gen_addi_i64(o
->in2
, o
->in2
, 8);
2386 tcg_gen_qemu_ld64(t2
, o
->in2
, get_mem_index(s
));
2387 gen_helper_load_psw(cpu_env
, t1
, t2
);
2388 tcg_temp_free_i64(t1
);
2389 tcg_temp_free_i64(t2
);
2390 return EXIT_NORETURN
;
2394 static ExitStatus
op_lam(DisasContext
*s
, DisasOps
*o
)
2396 TCGv_i32 r1
= tcg_const_i32(get_field(s
->fields
, r1
));
2397 TCGv_i32 r3
= tcg_const_i32(get_field(s
->fields
, r3
));
2398 potential_page_fault(s
);
2399 gen_helper_lam(cpu_env
, r1
, o
->in2
, r3
);
2400 tcg_temp_free_i32(r1
);
2401 tcg_temp_free_i32(r3
);
2405 static ExitStatus
op_lm32(DisasContext
*s
, DisasOps
*o
)
2407 int r1
= get_field(s
->fields
, r1
);
2408 int r3
= get_field(s
->fields
, r3
);
2409 TCGv_i64 t
= tcg_temp_new_i64();
2410 TCGv_i64 t4
= tcg_const_i64(4);
2413 tcg_gen_qemu_ld32u(t
, o
->in2
, get_mem_index(s
));
2414 store_reg32_i64(r1
, t
);
2418 tcg_gen_add_i64(o
->in2
, o
->in2
, t4
);
2422 tcg_temp_free_i64(t
);
2423 tcg_temp_free_i64(t4
);
2427 static ExitStatus
op_lmh(DisasContext
*s
, DisasOps
*o
)
2429 int r1
= get_field(s
->fields
, r1
);
2430 int r3
= get_field(s
->fields
, r3
);
2431 TCGv_i64 t
= tcg_temp_new_i64();
2432 TCGv_i64 t4
= tcg_const_i64(4);
2435 tcg_gen_qemu_ld32u(t
, o
->in2
, get_mem_index(s
));
2436 store_reg32h_i64(r1
, t
);
2440 tcg_gen_add_i64(o
->in2
, o
->in2
, t4
);
2444 tcg_temp_free_i64(t
);
2445 tcg_temp_free_i64(t4
);
2449 static ExitStatus
op_lm64(DisasContext
*s
, DisasOps
*o
)
2451 int r1
= get_field(s
->fields
, r1
);
2452 int r3
= get_field(s
->fields
, r3
);
2453 TCGv_i64 t8
= tcg_const_i64(8);
2456 tcg_gen_qemu_ld64(regs
[r1
], o
->in2
, get_mem_index(s
));
2460 tcg_gen_add_i64(o
->in2
, o
->in2
, t8
);
2464 tcg_temp_free_i64(t8
);
2468 static ExitStatus
op_mov2(DisasContext
*s
, DisasOps
*o
)
2471 o
->g_out
= o
->g_in2
;
2472 TCGV_UNUSED_I64(o
->in2
);
2477 static ExitStatus
op_movx(DisasContext
*s
, DisasOps
*o
)
2481 o
->g_out
= o
->g_in1
;
2482 o
->g_out2
= o
->g_in2
;
2483 TCGV_UNUSED_I64(o
->in1
);
2484 TCGV_UNUSED_I64(o
->in2
);
2485 o
->g_in1
= o
->g_in2
= false;
2489 static ExitStatus
op_mvc(DisasContext
*s
, DisasOps
*o
)
2491 TCGv_i32 l
= tcg_const_i32(get_field(s
->fields
, l1
));
2492 potential_page_fault(s
);
2493 gen_helper_mvc(cpu_env
, l
, o
->addr1
, o
->in2
);
2494 tcg_temp_free_i32(l
);
2498 static ExitStatus
op_mvcl(DisasContext
*s
, DisasOps
*o
)
2500 TCGv_i32 r1
= tcg_const_i32(get_field(s
->fields
, r1
));
2501 TCGv_i32 r2
= tcg_const_i32(get_field(s
->fields
, r2
));
2502 potential_page_fault(s
);
2503 gen_helper_mvcl(cc_op
, cpu_env
, r1
, r2
);
2504 tcg_temp_free_i32(r1
);
2505 tcg_temp_free_i32(r2
);
2510 static ExitStatus
op_mvcle(DisasContext
*s
, DisasOps
*o
)
2512 TCGv_i32 r1
= tcg_const_i32(get_field(s
->fields
, r1
));
2513 TCGv_i32 r3
= tcg_const_i32(get_field(s
->fields
, r3
));
2514 potential_page_fault(s
);
2515 gen_helper_mvcle(cc_op
, cpu_env
, r1
, o
->in2
, r3
);
2516 tcg_temp_free_i32(r1
);
2517 tcg_temp_free_i32(r3
);
2522 #ifndef CONFIG_USER_ONLY
2523 static ExitStatus
op_mvcp(DisasContext
*s
, DisasOps
*o
)
2525 int r1
= get_field(s
->fields
, l1
);
2526 check_privileged(s
);
2527 potential_page_fault(s
);
2528 gen_helper_mvcp(cc_op
, cpu_env
, regs
[r1
], o
->addr1
, o
->in2
);
2533 static ExitStatus
op_mvcs(DisasContext
*s
, DisasOps
*o
)
2535 int r1
= get_field(s
->fields
, l1
);
2536 check_privileged(s
);
2537 potential_page_fault(s
);
2538 gen_helper_mvcs(cc_op
, cpu_env
, regs
[r1
], o
->addr1
, o
->in2
);
2544 static ExitStatus
op_mvpg(DisasContext
*s
, DisasOps
*o
)
2546 potential_page_fault(s
);
2547 gen_helper_mvpg(cpu_env
, regs
[0], o
->in1
, o
->in2
);
2552 static ExitStatus
op_mvst(DisasContext
*s
, DisasOps
*o
)
2554 potential_page_fault(s
);
2555 gen_helper_mvst(o
->in1
, cpu_env
, regs
[0], o
->in1
, o
->in2
);
2557 return_low128(o
->in2
);
2561 static ExitStatus
op_mul(DisasContext
*s
, DisasOps
*o
)
2563 tcg_gen_mul_i64(o
->out
, o
->in1
, o
->in2
);
2567 static ExitStatus
op_mul128(DisasContext
*s
, DisasOps
*o
)
2569 tcg_gen_mulu2_i64(o
->out2
, o
->out
, o
->in1
, o
->in2
);
2573 static ExitStatus
op_meeb(DisasContext
*s
, DisasOps
*o
)
2575 gen_helper_meeb(o
->out
, cpu_env
, o
->in1
, o
->in2
);
2579 static ExitStatus
op_mdeb(DisasContext
*s
, DisasOps
*o
)
2581 gen_helper_mdeb(o
->out
, cpu_env
, o
->in1
, o
->in2
);
2585 static ExitStatus
op_mdb(DisasContext
*s
, DisasOps
*o
)
2587 gen_helper_mdb(o
->out
, cpu_env
, o
->in1
, o
->in2
);
2591 static ExitStatus
op_mxb(DisasContext
*s
, DisasOps
*o
)
2593 gen_helper_mxb(o
->out
, cpu_env
, o
->out
, o
->out2
, o
->in1
, o
->in2
);
2594 return_low128(o
->out2
);
2598 static ExitStatus
op_mxdb(DisasContext
*s
, DisasOps
*o
)
2600 gen_helper_mxdb(o
->out
, cpu_env
, o
->out
, o
->out2
, o
->in2
);
2601 return_low128(o
->out2
);
2605 static ExitStatus
op_maeb(DisasContext
*s
, DisasOps
*o
)
2607 TCGv_i64 r3
= load_freg32_i64(get_field(s
->fields
, r3
));
2608 gen_helper_maeb(o
->out
, cpu_env
, o
->in1
, o
->in2
, r3
);
2609 tcg_temp_free_i64(r3
);
2613 static ExitStatus
op_madb(DisasContext
*s
, DisasOps
*o
)
2615 int r3
= get_field(s
->fields
, r3
);
2616 gen_helper_madb(o
->out
, cpu_env
, o
->in1
, o
->in2
, fregs
[r3
]);
2620 static ExitStatus
op_mseb(DisasContext
*s
, DisasOps
*o
)
2622 TCGv_i64 r3
= load_freg32_i64(get_field(s
->fields
, r3
));
2623 gen_helper_mseb(o
->out
, cpu_env
, o
->in1
, o
->in2
, r3
);
2624 tcg_temp_free_i64(r3
);
2628 static ExitStatus
op_msdb(DisasContext
*s
, DisasOps
*o
)
2630 int r3
= get_field(s
->fields
, r3
);
2631 gen_helper_msdb(o
->out
, cpu_env
, o
->in1
, o
->in2
, fregs
[r3
]);
2635 static ExitStatus
op_nabs(DisasContext
*s
, DisasOps
*o
)
2637 gen_helper_nabs_i64(o
->out
, o
->in2
);
2641 static ExitStatus
op_nabsf32(DisasContext
*s
, DisasOps
*o
)
2643 tcg_gen_ori_i64(o
->out
, o
->in2
, 0x80000000ull
);
2647 static ExitStatus
op_nabsf64(DisasContext
*s
, DisasOps
*o
)
2649 tcg_gen_ori_i64(o
->out
, o
->in2
, 0x8000000000000000ull
);
2653 static ExitStatus
op_nabsf128(DisasContext
*s
, DisasOps
*o
)
2655 tcg_gen_ori_i64(o
->out
, o
->in1
, 0x8000000000000000ull
);
2656 tcg_gen_mov_i64(o
->out2
, o
->in2
);
2660 static ExitStatus
op_nc(DisasContext
*s
, DisasOps
*o
)
2662 TCGv_i32 l
= tcg_const_i32(get_field(s
->fields
, l1
));
2663 potential_page_fault(s
);
2664 gen_helper_nc(cc_op
, cpu_env
, l
, o
->addr1
, o
->in2
);
2665 tcg_temp_free_i32(l
);
2670 static ExitStatus
op_neg(DisasContext
*s
, DisasOps
*o
)
2672 tcg_gen_neg_i64(o
->out
, o
->in2
);
2676 static ExitStatus
op_negf32(DisasContext
*s
, DisasOps
*o
)
2678 tcg_gen_xori_i64(o
->out
, o
->in2
, 0x80000000ull
);
2682 static ExitStatus
op_negf64(DisasContext
*s
, DisasOps
*o
)
2684 tcg_gen_xori_i64(o
->out
, o
->in2
, 0x8000000000000000ull
);
2688 static ExitStatus
op_negf128(DisasContext
*s
, DisasOps
*o
)
2690 tcg_gen_xori_i64(o
->out
, o
->in1
, 0x8000000000000000ull
);
2691 tcg_gen_mov_i64(o
->out2
, o
->in2
);
2695 static ExitStatus
op_oc(DisasContext
*s
, DisasOps
*o
)
2697 TCGv_i32 l
= tcg_const_i32(get_field(s
->fields
, l1
));
2698 potential_page_fault(s
);
2699 gen_helper_oc(cc_op
, cpu_env
, l
, o
->addr1
, o
->in2
);
2700 tcg_temp_free_i32(l
);
2705 static ExitStatus
op_or(DisasContext
*s
, DisasOps
*o
)
2707 tcg_gen_or_i64(o
->out
, o
->in1
, o
->in2
);
2711 static ExitStatus
op_ori(DisasContext
*s
, DisasOps
*o
)
2713 int shift
= s
->insn
->data
& 0xff;
2714 int size
= s
->insn
->data
>> 8;
2715 uint64_t mask
= ((1ull << size
) - 1) << shift
;
2718 tcg_gen_shli_i64(o
->in2
, o
->in2
, shift
);
2719 tcg_gen_or_i64(o
->out
, o
->in1
, o
->in2
);
2721 /* Produce the CC from only the bits manipulated. */
2722 tcg_gen_andi_i64(cc_dst
, o
->out
, mask
);
2723 set_cc_nz_u64(s
, cc_dst
);
2727 static ExitStatus
op_popcnt(DisasContext
*s
, DisasOps
*o
)
2729 gen_helper_popcnt(o
->out
, o
->in2
);
2733 #ifndef CONFIG_USER_ONLY
2734 static ExitStatus
op_ptlb(DisasContext
*s
, DisasOps
*o
)
2736 check_privileged(s
);
2737 gen_helper_ptlb(cpu_env
);
2742 static ExitStatus
op_risbg(DisasContext
*s
, DisasOps
*o
)
2744 int i3
= get_field(s
->fields
, i3
);
2745 int i4
= get_field(s
->fields
, i4
);
2746 int i5
= get_field(s
->fields
, i5
);
2747 int do_zero
= i4
& 0x80;
2748 uint64_t mask
, imask
, pmask
;
2751 /* Adjust the arguments for the specific insn. */
2752 switch (s
->fields
->op2
) {
2753 case 0x55: /* risbg */
2758 case 0x5d: /* risbhg */
2761 pmask
= 0xffffffff00000000ull
;
2763 case 0x51: /* risblg */
2766 pmask
= 0x00000000ffffffffull
;
2772 /* MASK is the set of bits to be inserted from R2.
2773 Take care for I3/I4 wraparound. */
2776 mask
^= pmask
>> i4
>> 1;
2778 mask
|= ~(pmask
>> i4
>> 1);
2782 /* IMASK is the set of bits to be kept from R1. In the case of the high/low
2783 insns, we need to keep the other half of the register. */
2784 imask
= ~mask
| ~pmask
;
2786 if (s
->fields
->op2
== 0x55) {
2793 /* In some cases we can implement this with deposit, which can be more
2794 efficient on some hosts. */
2795 if (~mask
== imask
&& i3
<= i4
) {
2796 if (s
->fields
->op2
== 0x5d) {
2799 /* Note that we rotate the bits to be inserted to the lsb, not to
2800 the position as described in the PoO. */
2803 rot
= (i5
- pos
) & 63;
2809 /* Rotate the input as necessary. */
2810 tcg_gen_rotli_i64(o
->in2
, o
->in2
, rot
);
2812 /* Insert the selected bits into the output. */
2814 tcg_gen_deposit_i64(o
->out
, o
->out
, o
->in2
, pos
, len
);
2815 } else if (imask
== 0) {
2816 tcg_gen_andi_i64(o
->out
, o
->in2
, mask
);
2818 tcg_gen_andi_i64(o
->in2
, o
->in2
, mask
);
2819 tcg_gen_andi_i64(o
->out
, o
->out
, imask
);
2820 tcg_gen_or_i64(o
->out
, o
->out
, o
->in2
);
2825 static ExitStatus
op_rosbg(DisasContext
*s
, DisasOps
*o
)
2827 int i3
= get_field(s
->fields
, i3
);
2828 int i4
= get_field(s
->fields
, i4
);
2829 int i5
= get_field(s
->fields
, i5
);
2832 /* If this is a test-only form, arrange to discard the result. */
2834 o
->out
= tcg_temp_new_i64();
2842 /* MASK is the set of bits to be operated on from R2.
2843 Take care for I3/I4 wraparound. */
2846 mask
^= ~0ull >> i4
>> 1;
2848 mask
|= ~(~0ull >> i4
>> 1);
2851 /* Rotate the input as necessary. */
2852 tcg_gen_rotli_i64(o
->in2
, o
->in2
, i5
);
2855 switch (s
->fields
->op2
) {
2856 case 0x55: /* AND */
2857 tcg_gen_ori_i64(o
->in2
, o
->in2
, ~mask
);
2858 tcg_gen_and_i64(o
->out
, o
->out
, o
->in2
);
2861 tcg_gen_andi_i64(o
->in2
, o
->in2
, mask
);
2862 tcg_gen_or_i64(o
->out
, o
->out
, o
->in2
);
2864 case 0x57: /* XOR */
2865 tcg_gen_andi_i64(o
->in2
, o
->in2
, mask
);
2866 tcg_gen_xor_i64(o
->out
, o
->out
, o
->in2
);
2873 tcg_gen_andi_i64(cc_dst
, o
->out
, mask
);
2874 set_cc_nz_u64(s
, cc_dst
);
2878 static ExitStatus
op_rev16(DisasContext
*s
, DisasOps
*o
)
2880 tcg_gen_bswap16_i64(o
->out
, o
->in2
);
2884 static ExitStatus
op_rev32(DisasContext
*s
, DisasOps
*o
)
2886 tcg_gen_bswap32_i64(o
->out
, o
->in2
);
2890 static ExitStatus
op_rev64(DisasContext
*s
, DisasOps
*o
)
2892 tcg_gen_bswap64_i64(o
->out
, o
->in2
);
2896 static ExitStatus
op_rll32(DisasContext
*s
, DisasOps
*o
)
2898 TCGv_i32 t1
= tcg_temp_new_i32();
2899 TCGv_i32 t2
= tcg_temp_new_i32();
2900 TCGv_i32 to
= tcg_temp_new_i32();
2901 tcg_gen_trunc_i64_i32(t1
, o
->in1
);
2902 tcg_gen_trunc_i64_i32(t2
, o
->in2
);
2903 tcg_gen_rotl_i32(to
, t1
, t2
);
2904 tcg_gen_extu_i32_i64(o
->out
, to
);
2905 tcg_temp_free_i32(t1
);
2906 tcg_temp_free_i32(t2
);
2907 tcg_temp_free_i32(to
);
2911 static ExitStatus
op_rll64(DisasContext
*s
, DisasOps
*o
)
2913 tcg_gen_rotl_i64(o
->out
, o
->in1
, o
->in2
);
2917 #ifndef CONFIG_USER_ONLY
2918 static ExitStatus
op_rrbe(DisasContext
*s
, DisasOps
*o
)
2920 check_privileged(s
);
2921 gen_helper_rrbe(cc_op
, cpu_env
, o
->in2
);
2926 static ExitStatus
op_sacf(DisasContext
*s
, DisasOps
*o
)
2928 check_privileged(s
);
2929 gen_helper_sacf(cpu_env
, o
->in2
);
2930 /* Addressing mode has changed, so end the block. */
2931 return EXIT_PC_STALE
;
2935 static ExitStatus
op_sar(DisasContext
*s
, DisasOps
*o
)
2937 int r1
= get_field(s
->fields
, r1
);
2938 tcg_gen_st32_i64(o
->in2
, cpu_env
, offsetof(CPUS390XState
, aregs
[r1
]));
2942 static ExitStatus
op_seb(DisasContext
*s
, DisasOps
*o
)
2944 gen_helper_seb(o
->out
, cpu_env
, o
->in1
, o
->in2
);
2948 static ExitStatus
op_sdb(DisasContext
*s
, DisasOps
*o
)
2950 gen_helper_sdb(o
->out
, cpu_env
, o
->in1
, o
->in2
);
2954 static ExitStatus
op_sxb(DisasContext
*s
, DisasOps
*o
)
2956 gen_helper_sxb(o
->out
, cpu_env
, o
->out
, o
->out2
, o
->in1
, o
->in2
);
2957 return_low128(o
->out2
);
2961 static ExitStatus
op_sqeb(DisasContext
*s
, DisasOps
*o
)
2963 gen_helper_sqeb(o
->out
, cpu_env
, o
->in2
);
2967 static ExitStatus
op_sqdb(DisasContext
*s
, DisasOps
*o
)
2969 gen_helper_sqdb(o
->out
, cpu_env
, o
->in2
);
2973 static ExitStatus
op_sqxb(DisasContext
*s
, DisasOps
*o
)
2975 gen_helper_sqxb(o
->out
, cpu_env
, o
->in1
, o
->in2
);
2976 return_low128(o
->out2
);
2980 #ifndef CONFIG_USER_ONLY
2981 static ExitStatus
op_servc(DisasContext
*s
, DisasOps
*o
)
2983 check_privileged(s
);
2984 potential_page_fault(s
);
2985 gen_helper_servc(cc_op
, cpu_env
, o
->in2
, o
->in1
);
2990 static ExitStatus
op_sigp(DisasContext
*s
, DisasOps
*o
)
2992 TCGv_i32 r1
= tcg_const_i32(get_field(s
->fields
, r1
));
2993 check_privileged(s
);
2994 potential_page_fault(s
);
2995 gen_helper_sigp(cc_op
, cpu_env
, o
->in2
, r1
, o
->in1
);
2996 tcg_temp_free_i32(r1
);
3001 static ExitStatus
op_soc(DisasContext
*s
, DisasOps
*o
)
3007 disas_jcc(s
, &c
, get_field(s
->fields
, m3
));
3009 lab
= gen_new_label();
3011 tcg_gen_brcond_i64(c
.cond
, c
.u
.s64
.a
, c
.u
.s64
.b
, lab
);
3013 tcg_gen_brcond_i32(c
.cond
, c
.u
.s32
.a
, c
.u
.s32
.b
, lab
);
3017 r1
= get_field(s
->fields
, r1
);
3018 a
= get_address(s
, 0, get_field(s
->fields
, b2
), get_field(s
->fields
, d2
));
3019 if (s
->insn
->data
) {
3020 tcg_gen_qemu_st64(regs
[r1
], a
, get_mem_index(s
));
3022 tcg_gen_qemu_st32(regs
[r1
], a
, get_mem_index(s
));
3024 tcg_temp_free_i64(a
);
3030 static ExitStatus
op_sla(DisasContext
*s
, DisasOps
*o
)
3032 uint64_t sign
= 1ull << s
->insn
->data
;
3033 enum cc_op cco
= s
->insn
->data
== 31 ? CC_OP_SLA_32
: CC_OP_SLA_64
;
3034 gen_op_update2_cc_i64(s
, cco
, o
->in1
, o
->in2
);
3035 tcg_gen_shl_i64(o
->out
, o
->in1
, o
->in2
);
3036 /* The arithmetic left shift is curious in that it does not affect
3037 the sign bit. Copy that over from the source unchanged. */
3038 tcg_gen_andi_i64(o
->out
, o
->out
, ~sign
);
3039 tcg_gen_andi_i64(o
->in1
, o
->in1
, sign
);
3040 tcg_gen_or_i64(o
->out
, o
->out
, o
->in1
);
3044 static ExitStatus
op_sll(DisasContext
*s
, DisasOps
*o
)
3046 tcg_gen_shl_i64(o
->out
, o
->in1
, o
->in2
);
3050 static ExitStatus
op_sra(DisasContext
*s
, DisasOps
*o
)
3052 tcg_gen_sar_i64(o
->out
, o
->in1
, o
->in2
);
3056 static ExitStatus
op_srl(DisasContext
*s
, DisasOps
*o
)
3058 tcg_gen_shr_i64(o
->out
, o
->in1
, o
->in2
);
3062 static ExitStatus
op_sfpc(DisasContext
*s
, DisasOps
*o
)
3064 gen_helper_sfpc(cpu_env
, o
->in2
);
3068 static ExitStatus
op_sfas(DisasContext
*s
, DisasOps
*o
)
3070 gen_helper_sfas(cpu_env
, o
->in2
);
3074 static ExitStatus
op_srnm(DisasContext
*s
, DisasOps
*o
)
3076 int b2
= get_field(s
->fields
, b2
);
3077 int d2
= get_field(s
->fields
, d2
);
3078 TCGv_i64 t1
= tcg_temp_new_i64();
3079 TCGv_i64 t2
= tcg_temp_new_i64();
3082 switch (s
->fields
->op2
) {
3083 case 0x99: /* SRNM */
3086 case 0xb8: /* SRNMB */
3089 case 0xb9: /* SRNMT */
3094 mask
= (1 << len
) - 1;
3096 /* Insert the value into the appropriate field of the FPC. */
3098 tcg_gen_movi_i64(t1
, d2
& mask
);
3100 tcg_gen_addi_i64(t1
, regs
[b2
], d2
);
3101 tcg_gen_andi_i64(t1
, t1
, mask
);
3103 tcg_gen_ld32u_i64(t2
, cpu_env
, offsetof(CPUS390XState
, fpc
));
3104 tcg_gen_deposit_i64(t2
, t2
, t1
, pos
, len
);
3105 tcg_temp_free_i64(t1
);
3107 /* Then install the new FPC to set the rounding mode in fpu_status. */
3108 gen_helper_sfpc(cpu_env
, t2
);
3109 tcg_temp_free_i64(t2
);
3113 #ifndef CONFIG_USER_ONLY
3114 static ExitStatus
op_spka(DisasContext
*s
, DisasOps
*o
)
3116 check_privileged(s
);
3117 tcg_gen_shri_i64(o
->in2
, o
->in2
, 4);
3118 tcg_gen_deposit_i64(psw_mask
, psw_mask
, o
->in2
, PSW_SHIFT_KEY
- 4, 4);
3122 static ExitStatus
op_sske(DisasContext
*s
, DisasOps
*o
)
3124 check_privileged(s
);
3125 gen_helper_sske(cpu_env
, o
->in1
, o
->in2
);
3129 static ExitStatus
op_ssm(DisasContext
*s
, DisasOps
*o
)
3131 check_privileged(s
);
3132 tcg_gen_deposit_i64(psw_mask
, psw_mask
, o
->in2
, 56, 8);
3136 static ExitStatus
op_stap(DisasContext
*s
, DisasOps
*o
)
3138 check_privileged(s
);
3139 /* ??? Surely cpu address != cpu number. In any case the previous
3140 version of this stored more than the required half-word, so it
3141 is unlikely this has ever been tested. */
3142 tcg_gen_ld32u_i64(o
->out
, cpu_env
, offsetof(CPUS390XState
, cpu_num
));
3146 static ExitStatus
op_stck(DisasContext
*s
, DisasOps
*o
)
3148 gen_helper_stck(o
->out
, cpu_env
);
3149 /* ??? We don't implement clock states. */
3150 gen_op_movi_cc(s
, 0);
3154 static ExitStatus
op_stcke(DisasContext
*s
, DisasOps
*o
)
3156 TCGv_i64 c1
= tcg_temp_new_i64();
3157 TCGv_i64 c2
= tcg_temp_new_i64();
3158 gen_helper_stck(c1
, cpu_env
);
3159 /* Shift the 64-bit value into its place as a zero-extended
3160 104-bit value. Note that "bit positions 64-103 are always
3161 non-zero so that they compare differently to STCK"; we set
3162 the least significant bit to 1. */
3163 tcg_gen_shli_i64(c2
, c1
, 56);
3164 tcg_gen_shri_i64(c1
, c1
, 8);
3165 tcg_gen_ori_i64(c2
, c2
, 0x10000);
3166 tcg_gen_qemu_st64(c1
, o
->in2
, get_mem_index(s
));
3167 tcg_gen_addi_i64(o
->in2
, o
->in2
, 8);
3168 tcg_gen_qemu_st64(c2
, o
->in2
, get_mem_index(s
));
3169 tcg_temp_free_i64(c1
);
3170 tcg_temp_free_i64(c2
);
3171 /* ??? We don't implement clock states. */
3172 gen_op_movi_cc(s
, 0);
3176 static ExitStatus
op_sckc(DisasContext
*s
, DisasOps
*o
)
3178 check_privileged(s
);
3179 gen_helper_sckc(cpu_env
, o
->in2
);
3183 static ExitStatus
op_stckc(DisasContext
*s
, DisasOps
*o
)
3185 check_privileged(s
);
3186 gen_helper_stckc(o
->out
, cpu_env
);
3190 static ExitStatus
op_stctg(DisasContext
*s
, DisasOps
*o
)
3192 TCGv_i32 r1
= tcg_const_i32(get_field(s
->fields
, r1
));
3193 TCGv_i32 r3
= tcg_const_i32(get_field(s
->fields
, r3
));
3194 check_privileged(s
);
3195 potential_page_fault(s
);
3196 gen_helper_stctg(cpu_env
, r1
, o
->in2
, r3
);
3197 tcg_temp_free_i32(r1
);
3198 tcg_temp_free_i32(r3
);
3202 static ExitStatus
op_stctl(DisasContext
*s
, DisasOps
*o
)
3204 TCGv_i32 r1
= tcg_const_i32(get_field(s
->fields
, r1
));
3205 TCGv_i32 r3
= tcg_const_i32(get_field(s
->fields
, r3
));
3206 check_privileged(s
);
3207 potential_page_fault(s
);
3208 gen_helper_stctl(cpu_env
, r1
, o
->in2
, r3
);
3209 tcg_temp_free_i32(r1
);
3210 tcg_temp_free_i32(r3
);
3214 static ExitStatus
op_stidp(DisasContext
*s
, DisasOps
*o
)
3216 check_privileged(s
);
3217 tcg_gen_ld32u_i64(o
->out
, cpu_env
, offsetof(CPUS390XState
, cpu_num
));
3221 static ExitStatus
op_spt(DisasContext
*s
, DisasOps
*o
)
3223 check_privileged(s
);
3224 gen_helper_spt(cpu_env
, o
->in2
);
3228 static ExitStatus
op_stfl(DisasContext
*s
, DisasOps
*o
)
3231 /* We really ought to have more complete indication of facilities
3232 that we implement. Address this when STFLE is implemented. */
3233 check_privileged(s
);
3234 f
= tcg_const_i64(0xc0000000);
3235 a
= tcg_const_i64(200);
3236 tcg_gen_qemu_st32(f
, a
, get_mem_index(s
));
3237 tcg_temp_free_i64(f
);
3238 tcg_temp_free_i64(a
);
3242 static ExitStatus
op_stpt(DisasContext
*s
, DisasOps
*o
)
3244 check_privileged(s
);
3245 gen_helper_stpt(o
->out
, cpu_env
);
3249 static ExitStatus
op_stsi(DisasContext
*s
, DisasOps
*o
)
3251 check_privileged(s
);
3252 potential_page_fault(s
);
3253 gen_helper_stsi(cc_op
, cpu_env
, o
->in2
, regs
[0], regs
[1]);
3258 static ExitStatus
op_spx(DisasContext
*s
, DisasOps
*o
)
3260 check_privileged(s
);
3261 gen_helper_spx(cpu_env
, o
->in2
);
3265 static ExitStatus
op_subchannel(DisasContext
*s
, DisasOps
*o
)
3267 check_privileged(s
);
3268 /* Not operational. */
3269 gen_op_movi_cc(s
, 3);
3273 static ExitStatus
op_stpx(DisasContext
*s
, DisasOps
*o
)
3275 check_privileged(s
);
3276 tcg_gen_ld_i64(o
->out
, cpu_env
, offsetof(CPUS390XState
, psa
));
3277 tcg_gen_andi_i64(o
->out
, o
->out
, 0x7fffe000);
3281 static ExitStatus
op_stnosm(DisasContext
*s
, DisasOps
*o
)
3283 uint64_t i2
= get_field(s
->fields
, i2
);
3286 check_privileged(s
);
3288 /* It is important to do what the instruction name says: STORE THEN.
3289 If we let the output hook perform the store then if we fault and
3290 restart, we'll have the wrong SYSTEM MASK in place. */
3291 t
= tcg_temp_new_i64();
3292 tcg_gen_shri_i64(t
, psw_mask
, 56);
3293 tcg_gen_qemu_st8(t
, o
->addr1
, get_mem_index(s
));
3294 tcg_temp_free_i64(t
);
3296 if (s
->fields
->op
== 0xac) {
3297 tcg_gen_andi_i64(psw_mask
, psw_mask
,
3298 (i2
<< 56) | 0x00ffffffffffffffull
);
3300 tcg_gen_ori_i64(psw_mask
, psw_mask
, i2
<< 56);
3305 static ExitStatus
op_stura(DisasContext
*s
, DisasOps
*o
)
3307 check_privileged(s
);
3308 potential_page_fault(s
);
3309 gen_helper_stura(cpu_env
, o
->in2
, o
->in1
);
3314 static ExitStatus
op_st8(DisasContext
*s
, DisasOps
*o
)
3316 tcg_gen_qemu_st8(o
->in1
, o
->in2
, get_mem_index(s
));
3320 static ExitStatus
op_st16(DisasContext
*s
, DisasOps
*o
)
3322 tcg_gen_qemu_st16(o
->in1
, o
->in2
, get_mem_index(s
));
3326 static ExitStatus
op_st32(DisasContext
*s
, DisasOps
*o
)
3328 tcg_gen_qemu_st32(o
->in1
, o
->in2
, get_mem_index(s
));
3332 static ExitStatus
op_st64(DisasContext
*s
, DisasOps
*o
)
3334 tcg_gen_qemu_st64(o
->in1
, o
->in2
, get_mem_index(s
));
3338 static ExitStatus
op_stam(DisasContext
*s
, DisasOps
*o
)
3340 TCGv_i32 r1
= tcg_const_i32(get_field(s
->fields
, r1
));
3341 TCGv_i32 r3
= tcg_const_i32(get_field(s
->fields
, r3
));
3342 potential_page_fault(s
);
3343 gen_helper_stam(cpu_env
, r1
, o
->in2
, r3
);
3344 tcg_temp_free_i32(r1
);
3345 tcg_temp_free_i32(r3
);
3349 static ExitStatus
op_stcm(DisasContext
*s
, DisasOps
*o
)
3351 int m3
= get_field(s
->fields
, m3
);
3352 int pos
, base
= s
->insn
->data
;
3353 TCGv_i64 tmp
= tcg_temp_new_i64();
3355 pos
= base
+ ctz32(m3
) * 8;
3358 /* Effectively a 32-bit store. */
3359 tcg_gen_shri_i64(tmp
, o
->in1
, pos
);
3360 tcg_gen_qemu_st32(tmp
, o
->in2
, get_mem_index(s
));
3366 /* Effectively a 16-bit store. */
3367 tcg_gen_shri_i64(tmp
, o
->in1
, pos
);
3368 tcg_gen_qemu_st16(tmp
, o
->in2
, get_mem_index(s
));
3375 /* Effectively an 8-bit store. */
3376 tcg_gen_shri_i64(tmp
, o
->in1
, pos
);
3377 tcg_gen_qemu_st8(tmp
, o
->in2
, get_mem_index(s
));
3381 /* This is going to be a sequence of shifts and stores. */
3382 pos
= base
+ 32 - 8;
3385 tcg_gen_shri_i64(tmp
, o
->in1
, pos
);
3386 tcg_gen_qemu_st8(tmp
, o
->in2
, get_mem_index(s
));
3387 tcg_gen_addi_i64(o
->in2
, o
->in2
, 1);
3389 m3
= (m3
<< 1) & 0xf;
3394 tcg_temp_free_i64(tmp
);
3398 static ExitStatus
op_stm(DisasContext
*s
, DisasOps
*o
)
3400 int r1
= get_field(s
->fields
, r1
);
3401 int r3
= get_field(s
->fields
, r3
);
3402 int size
= s
->insn
->data
;
3403 TCGv_i64 tsize
= tcg_const_i64(size
);
3407 tcg_gen_qemu_st64(regs
[r1
], o
->in2
, get_mem_index(s
));
3409 tcg_gen_qemu_st32(regs
[r1
], o
->in2
, get_mem_index(s
));
3414 tcg_gen_add_i64(o
->in2
, o
->in2
, tsize
);
3418 tcg_temp_free_i64(tsize
);
3422 static ExitStatus
op_stmh(DisasContext
*s
, DisasOps
*o
)
3424 int r1
= get_field(s
->fields
, r1
);
3425 int r3
= get_field(s
->fields
, r3
);
3426 TCGv_i64 t
= tcg_temp_new_i64();
3427 TCGv_i64 t4
= tcg_const_i64(4);
3428 TCGv_i64 t32
= tcg_const_i64(32);
3431 tcg_gen_shl_i64(t
, regs
[r1
], t32
);
3432 tcg_gen_qemu_st32(t
, o
->in2
, get_mem_index(s
));
3436 tcg_gen_add_i64(o
->in2
, o
->in2
, t4
);
3440 tcg_temp_free_i64(t
);
3441 tcg_temp_free_i64(t4
);
3442 tcg_temp_free_i64(t32
);
3446 static ExitStatus
op_srst(DisasContext
*s
, DisasOps
*o
)
3448 potential_page_fault(s
);
3449 gen_helper_srst(o
->in1
, cpu_env
, regs
[0], o
->in1
, o
->in2
);
3451 return_low128(o
->in2
);
3455 static ExitStatus
op_sub(DisasContext
*s
, DisasOps
*o
)
3457 tcg_gen_sub_i64(o
->out
, o
->in1
, o
->in2
);
3461 static ExitStatus
op_subb(DisasContext
*s
, DisasOps
*o
)
3466 tcg_gen_sub_i64(o
->out
, o
->in1
, o
->in2
);
3468 /* The !borrow flag is the msb of CC. Since we want the inverse of
3469 that, we ask for a comparison of CC=0 | CC=1 -> mask of 8 | 4. */
3470 disas_jcc(s
, &cmp
, 8 | 4);
3471 borrow
= tcg_temp_new_i64();
3473 tcg_gen_setcond_i64(cmp
.cond
, borrow
, cmp
.u
.s64
.a
, cmp
.u
.s64
.b
);
3475 TCGv_i32 t
= tcg_temp_new_i32();
3476 tcg_gen_setcond_i32(cmp
.cond
, t
, cmp
.u
.s32
.a
, cmp
.u
.s32
.b
);
3477 tcg_gen_extu_i32_i64(borrow
, t
);
3478 tcg_temp_free_i32(t
);
3482 tcg_gen_sub_i64(o
->out
, o
->out
, borrow
);
3483 tcg_temp_free_i64(borrow
);
3487 static ExitStatus
op_svc(DisasContext
*s
, DisasOps
*o
)
3494 t
= tcg_const_i32(get_field(s
->fields
, i1
) & 0xff);
3495 tcg_gen_st_i32(t
, cpu_env
, offsetof(CPUS390XState
, int_svc_code
));
3496 tcg_temp_free_i32(t
);
3498 t
= tcg_const_i32(s
->next_pc
- s
->pc
);
3499 tcg_gen_st_i32(t
, cpu_env
, offsetof(CPUS390XState
, int_svc_ilen
));
3500 tcg_temp_free_i32(t
);
3502 gen_exception(EXCP_SVC
);
3503 return EXIT_NORETURN
;
3506 static ExitStatus
op_tceb(DisasContext
*s
, DisasOps
*o
)
3508 gen_helper_tceb(cc_op
, o
->in1
, o
->in2
);
3513 static ExitStatus
op_tcdb(DisasContext
*s
, DisasOps
*o
)
3515 gen_helper_tcdb(cc_op
, o
->in1
, o
->in2
);
3520 static ExitStatus
op_tcxb(DisasContext
*s
, DisasOps
*o
)
3522 gen_helper_tcxb(cc_op
, o
->out
, o
->out2
, o
->in2
);
3527 #ifndef CONFIG_USER_ONLY
3528 static ExitStatus
op_tprot(DisasContext
*s
, DisasOps
*o
)
3530 potential_page_fault(s
);
3531 gen_helper_tprot(cc_op
, o
->addr1
, o
->in2
);
3537 static ExitStatus
op_tr(DisasContext
*s
, DisasOps
*o
)
3539 TCGv_i32 l
= tcg_const_i32(get_field(s
->fields
, l1
));
3540 potential_page_fault(s
);
3541 gen_helper_tr(cpu_env
, l
, o
->addr1
, o
->in2
);
3542 tcg_temp_free_i32(l
);
3547 static ExitStatus
op_unpk(DisasContext
*s
, DisasOps
*o
)
3549 TCGv_i32 l
= tcg_const_i32(get_field(s
->fields
, l1
));
3550 potential_page_fault(s
);
3551 gen_helper_unpk(cpu_env
, l
, o
->addr1
, o
->in2
);
3552 tcg_temp_free_i32(l
);
3556 static ExitStatus
op_xc(DisasContext
*s
, DisasOps
*o
)
3558 int d1
= get_field(s
->fields
, d1
);
3559 int d2
= get_field(s
->fields
, d2
);
3560 int b1
= get_field(s
->fields
, b1
);
3561 int b2
= get_field(s
->fields
, b2
);
3562 int l
= get_field(s
->fields
, l1
);
3565 o
->addr1
= get_address(s
, 0, b1
, d1
);
3567 /* If the addresses are identical, this is a store/memset of zero. */
3568 if (b1
== b2
&& d1
== d2
&& (l
+ 1) <= 32) {
3569 o
->in2
= tcg_const_i64(0);
3573 tcg_gen_qemu_st64(o
->in2
, o
->addr1
, get_mem_index(s
));
3576 tcg_gen_addi_i64(o
->addr1
, o
->addr1
, 8);
3580 tcg_gen_qemu_st32(o
->in2
, o
->addr1
, get_mem_index(s
));
3583 tcg_gen_addi_i64(o
->addr1
, o
->addr1
, 4);
3587 tcg_gen_qemu_st16(o
->in2
, o
->addr1
, get_mem_index(s
));
3590 tcg_gen_addi_i64(o
->addr1
, o
->addr1
, 2);
3594 tcg_gen_qemu_st8(o
->in2
, o
->addr1
, get_mem_index(s
));
3596 gen_op_movi_cc(s
, 0);
3600 /* But in general we'll defer to a helper. */
3601 o
->in2
= get_address(s
, 0, b2
, d2
);
3602 t32
= tcg_const_i32(l
);
3603 potential_page_fault(s
);
3604 gen_helper_xc(cc_op
, cpu_env
, t32
, o
->addr1
, o
->in2
);
3605 tcg_temp_free_i32(t32
);
3610 static ExitStatus
op_xor(DisasContext
*s
, DisasOps
*o
)
3612 tcg_gen_xor_i64(o
->out
, o
->in1
, o
->in2
);
3616 static ExitStatus
op_xori(DisasContext
*s
, DisasOps
*o
)
3618 int shift
= s
->insn
->data
& 0xff;
3619 int size
= s
->insn
->data
>> 8;
3620 uint64_t mask
= ((1ull << size
) - 1) << shift
;
3623 tcg_gen_shli_i64(o
->in2
, o
->in2
, shift
);
3624 tcg_gen_xor_i64(o
->out
, o
->in1
, o
->in2
);
3626 /* Produce the CC from only the bits manipulated. */
3627 tcg_gen_andi_i64(cc_dst
, o
->out
, mask
);
3628 set_cc_nz_u64(s
, cc_dst
);
3632 static ExitStatus
op_zero(DisasContext
*s
, DisasOps
*o
)
3634 o
->out
= tcg_const_i64(0);
3638 static ExitStatus
op_zero2(DisasContext
*s
, DisasOps
*o
)
3640 o
->out
= tcg_const_i64(0);
3646 /* ====================================================================== */
3647 /* The "Cc OUTput" generators. Given the generated output (and in some cases
3648 the original inputs), update the various cc data structures in order to
3649 be able to compute the new condition code. */
3651 static void cout_abs32(DisasContext
*s
, DisasOps
*o
)
3653 gen_op_update1_cc_i64(s
, CC_OP_ABS_32
, o
->out
);
3656 static void cout_abs64(DisasContext
*s
, DisasOps
*o
)
3658 gen_op_update1_cc_i64(s
, CC_OP_ABS_64
, o
->out
);
3661 static void cout_adds32(DisasContext
*s
, DisasOps
*o
)
3663 gen_op_update3_cc_i64(s
, CC_OP_ADD_32
, o
->in1
, o
->in2
, o
->out
);
3666 static void cout_adds64(DisasContext
*s
, DisasOps
*o
)
3668 gen_op_update3_cc_i64(s
, CC_OP_ADD_64
, o
->in1
, o
->in2
, o
->out
);
3671 static void cout_addu32(DisasContext
*s
, DisasOps
*o
)
3673 gen_op_update3_cc_i64(s
, CC_OP_ADDU_32
, o
->in1
, o
->in2
, o
->out
);
3676 static void cout_addu64(DisasContext
*s
, DisasOps
*o
)
3678 gen_op_update3_cc_i64(s
, CC_OP_ADDU_64
, o
->in1
, o
->in2
, o
->out
);
3681 static void cout_addc32(DisasContext
*s
, DisasOps
*o
)
3683 gen_op_update3_cc_i64(s
, CC_OP_ADDC_32
, o
->in1
, o
->in2
, o
->out
);
3686 static void cout_addc64(DisasContext
*s
, DisasOps
*o
)
3688 gen_op_update3_cc_i64(s
, CC_OP_ADDC_64
, o
->in1
, o
->in2
, o
->out
);
3691 static void cout_cmps32(DisasContext
*s
, DisasOps
*o
)
3693 gen_op_update2_cc_i64(s
, CC_OP_LTGT_32
, o
->in1
, o
->in2
);
3696 static void cout_cmps64(DisasContext
*s
, DisasOps
*o
)
3698 gen_op_update2_cc_i64(s
, CC_OP_LTGT_64
, o
->in1
, o
->in2
);
3701 static void cout_cmpu32(DisasContext
*s
, DisasOps
*o
)
3703 gen_op_update2_cc_i64(s
, CC_OP_LTUGTU_32
, o
->in1
, o
->in2
);
3706 static void cout_cmpu64(DisasContext
*s
, DisasOps
*o
)
3708 gen_op_update2_cc_i64(s
, CC_OP_LTUGTU_64
, o
->in1
, o
->in2
);
3711 static void cout_f32(DisasContext
*s
, DisasOps
*o
)
3713 gen_op_update1_cc_i64(s
, CC_OP_NZ_F32
, o
->out
);
3716 static void cout_f64(DisasContext
*s
, DisasOps
*o
)
3718 gen_op_update1_cc_i64(s
, CC_OP_NZ_F64
, o
->out
);
3721 static void cout_f128(DisasContext
*s
, DisasOps
*o
)
3723 gen_op_update2_cc_i64(s
, CC_OP_NZ_F128
, o
->out
, o
->out2
);
3726 static void cout_nabs32(DisasContext
*s
, DisasOps
*o
)
3728 gen_op_update1_cc_i64(s
, CC_OP_NABS_32
, o
->out
);
3731 static void cout_nabs64(DisasContext
*s
, DisasOps
*o
)
3733 gen_op_update1_cc_i64(s
, CC_OP_NABS_64
, o
->out
);
3736 static void cout_neg32(DisasContext
*s
, DisasOps
*o
)
3738 gen_op_update1_cc_i64(s
, CC_OP_COMP_32
, o
->out
);
3741 static void cout_neg64(DisasContext
*s
, DisasOps
*o
)
3743 gen_op_update1_cc_i64(s
, CC_OP_COMP_64
, o
->out
);
3746 static void cout_nz32(DisasContext
*s
, DisasOps
*o
)
3748 tcg_gen_ext32u_i64(cc_dst
, o
->out
);
3749 gen_op_update1_cc_i64(s
, CC_OP_NZ
, cc_dst
);
3752 static void cout_nz64(DisasContext
*s
, DisasOps
*o
)
3754 gen_op_update1_cc_i64(s
, CC_OP_NZ
, o
->out
);
3757 static void cout_s32(DisasContext
*s
, DisasOps
*o
)
3759 gen_op_update1_cc_i64(s
, CC_OP_LTGT0_32
, o
->out
);
3762 static void cout_s64(DisasContext
*s
, DisasOps
*o
)
3764 gen_op_update1_cc_i64(s
, CC_OP_LTGT0_64
, o
->out
);
3767 static void cout_subs32(DisasContext
*s
, DisasOps
*o
)
3769 gen_op_update3_cc_i64(s
, CC_OP_SUB_32
, o
->in1
, o
->in2
, o
->out
);
3772 static void cout_subs64(DisasContext
*s
, DisasOps
*o
)
3774 gen_op_update3_cc_i64(s
, CC_OP_SUB_64
, o
->in1
, o
->in2
, o
->out
);
3777 static void cout_subu32(DisasContext
*s
, DisasOps
*o
)
3779 gen_op_update3_cc_i64(s
, CC_OP_SUBU_32
, o
->in1
, o
->in2
, o
->out
);
3782 static void cout_subu64(DisasContext
*s
, DisasOps
*o
)
3784 gen_op_update3_cc_i64(s
, CC_OP_SUBU_64
, o
->in1
, o
->in2
, o
->out
);
3787 static void cout_subb32(DisasContext
*s
, DisasOps
*o
)
3789 gen_op_update3_cc_i64(s
, CC_OP_SUBB_32
, o
->in1
, o
->in2
, o
->out
);
3792 static void cout_subb64(DisasContext
*s
, DisasOps
*o
)
3794 gen_op_update3_cc_i64(s
, CC_OP_SUBB_64
, o
->in1
, o
->in2
, o
->out
);
3797 static void cout_tm32(DisasContext
*s
, DisasOps
*o
)
3799 gen_op_update2_cc_i64(s
, CC_OP_TM_32
, o
->in1
, o
->in2
);
3802 static void cout_tm64(DisasContext
*s
, DisasOps
*o
)
3804 gen_op_update2_cc_i64(s
, CC_OP_TM_64
, o
->in1
, o
->in2
);
3807 /* ====================================================================== */
3808 /* The "PREPeration" generators. These initialize the DisasOps.OUT fields
3809 with the TCG register to which we will write. Used in combination with
3810 the "wout" generators, in some cases we need a new temporary, and in
3811 some cases we can write to a TCG global. */
3813 static void prep_new(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3815 o
->out
= tcg_temp_new_i64();
3817 #define SPEC_prep_new 0
3819 static void prep_new_P(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3821 o
->out
= tcg_temp_new_i64();
3822 o
->out2
= tcg_temp_new_i64();
3824 #define SPEC_prep_new_P 0
3826 static void prep_r1(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3828 o
->out
= regs
[get_field(f
, r1
)];
3831 #define SPEC_prep_r1 0
3833 static void prep_r1_P(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3835 int r1
= get_field(f
, r1
);
3837 o
->out2
= regs
[r1
+ 1];
3838 o
->g_out
= o
->g_out2
= true;
3840 #define SPEC_prep_r1_P SPEC_r1_even
3842 static void prep_f1(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3844 o
->out
= fregs
[get_field(f
, r1
)];
3847 #define SPEC_prep_f1 0
3849 static void prep_x1(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3851 int r1
= get_field(f
, r1
);
3853 o
->out2
= fregs
[r1
+ 2];
3854 o
->g_out
= o
->g_out2
= true;
3856 #define SPEC_prep_x1 SPEC_r1_f128
3858 /* ====================================================================== */
3859 /* The "Write OUTput" generators. These generally perform some non-trivial
3860 copy of data to TCG globals, or to main memory. The trivial cases are
3861 generally handled by having a "prep" generator install the TCG global
3862 as the destination of the operation. */
3864 static void wout_r1(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3866 store_reg(get_field(f
, r1
), o
->out
);
3868 #define SPEC_wout_r1 0
3870 static void wout_r1_8(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3872 int r1
= get_field(f
, r1
);
3873 tcg_gen_deposit_i64(regs
[r1
], regs
[r1
], o
->out
, 0, 8);
3875 #define SPEC_wout_r1_8 0
3877 static void wout_r1_16(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3879 int r1
= get_field(f
, r1
);
3880 tcg_gen_deposit_i64(regs
[r1
], regs
[r1
], o
->out
, 0, 16);
3882 #define SPEC_wout_r1_16 0
3884 static void wout_r1_32(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3886 store_reg32_i64(get_field(f
, r1
), o
->out
);
3888 #define SPEC_wout_r1_32 0
3890 static void wout_r1_P32(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3892 int r1
= get_field(f
, r1
);
3893 store_reg32_i64(r1
, o
->out
);
3894 store_reg32_i64(r1
+ 1, o
->out2
);
3896 #define SPEC_wout_r1_P32 SPEC_r1_even
3898 static void wout_r1_D32(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3900 int r1
= get_field(f
, r1
);
3901 store_reg32_i64(r1
+ 1, o
->out
);
3902 tcg_gen_shri_i64(o
->out
, o
->out
, 32);
3903 store_reg32_i64(r1
, o
->out
);
3905 #define SPEC_wout_r1_D32 SPEC_r1_even
3907 static void wout_e1(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3909 store_freg32_i64(get_field(f
, r1
), o
->out
);
3911 #define SPEC_wout_e1 0
3913 static void wout_f1(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3915 store_freg(get_field(f
, r1
), o
->out
);
3917 #define SPEC_wout_f1 0
3919 static void wout_x1(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3921 int f1
= get_field(s
->fields
, r1
);
3922 store_freg(f1
, o
->out
);
3923 store_freg(f1
+ 2, o
->out2
);
3925 #define SPEC_wout_x1 SPEC_r1_f128
3927 static void wout_cond_r1r2_32(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3929 if (get_field(f
, r1
) != get_field(f
, r2
)) {
3930 store_reg32_i64(get_field(f
, r1
), o
->out
);
3933 #define SPEC_wout_cond_r1r2_32 0
3935 static void wout_cond_e1e2(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3937 if (get_field(f
, r1
) != get_field(f
, r2
)) {
3938 store_freg32_i64(get_field(f
, r1
), o
->out
);
3941 #define SPEC_wout_cond_e1e2 0
3943 static void wout_m1_8(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3945 tcg_gen_qemu_st8(o
->out
, o
->addr1
, get_mem_index(s
));
3947 #define SPEC_wout_m1_8 0
3949 static void wout_m1_16(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3951 tcg_gen_qemu_st16(o
->out
, o
->addr1
, get_mem_index(s
));
3953 #define SPEC_wout_m1_16 0
3955 static void wout_m1_32(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3957 tcg_gen_qemu_st32(o
->out
, o
->addr1
, get_mem_index(s
));
3959 #define SPEC_wout_m1_32 0
3961 static void wout_m1_64(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3963 tcg_gen_qemu_st64(o
->out
, o
->addr1
, get_mem_index(s
));
3965 #define SPEC_wout_m1_64 0
3967 static void wout_m2_32(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3969 tcg_gen_qemu_st32(o
->out
, o
->in2
, get_mem_index(s
));
3971 #define SPEC_wout_m2_32 0
3973 /* ====================================================================== */
3974 /* The "INput 1" generators. These load the first operand to an insn. */
3976 static void in1_r1(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3978 o
->in1
= load_reg(get_field(f
, r1
));
3980 #define SPEC_in1_r1 0
3982 static void in1_r1_o(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3984 o
->in1
= regs
[get_field(f
, r1
)];
3987 #define SPEC_in1_r1_o 0
3989 static void in1_r1_32s(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3991 o
->in1
= tcg_temp_new_i64();
3992 tcg_gen_ext32s_i64(o
->in1
, regs
[get_field(f
, r1
)]);
3994 #define SPEC_in1_r1_32s 0
3996 static void in1_r1_32u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3998 o
->in1
= tcg_temp_new_i64();
3999 tcg_gen_ext32u_i64(o
->in1
, regs
[get_field(f
, r1
)]);
4001 #define SPEC_in1_r1_32u 0
4003 static void in1_r1_sr32(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4005 o
->in1
= tcg_temp_new_i64();
4006 tcg_gen_shri_i64(o
->in1
, regs
[get_field(f
, r1
)], 32);
4008 #define SPEC_in1_r1_sr32 0
4010 static void in1_r1p1(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4012 o
->in1
= load_reg(get_field(f
, r1
) + 1);
4014 #define SPEC_in1_r1p1 SPEC_r1_even
4016 static void in1_r1p1_32s(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4018 o
->in1
= tcg_temp_new_i64();
4019 tcg_gen_ext32s_i64(o
->in1
, regs
[get_field(f
, r1
) + 1]);
4021 #define SPEC_in1_r1p1_32s SPEC_r1_even
4023 static void in1_r1p1_32u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4025 o
->in1
= tcg_temp_new_i64();
4026 tcg_gen_ext32u_i64(o
->in1
, regs
[get_field(f
, r1
) + 1]);
4028 #define SPEC_in1_r1p1_32u SPEC_r1_even
4030 static void in1_r1_D32(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4032 int r1
= get_field(f
, r1
);
4033 o
->in1
= tcg_temp_new_i64();
4034 tcg_gen_concat32_i64(o
->in1
, regs
[r1
+ 1], regs
[r1
]);
4036 #define SPEC_in1_r1_D32 SPEC_r1_even
4038 static void in1_r2(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4040 o
->in1
= load_reg(get_field(f
, r2
));
4042 #define SPEC_in1_r2 0
4044 static void in1_r3(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4046 o
->in1
= load_reg(get_field(f
, r3
));
4048 #define SPEC_in1_r3 0
4050 static void in1_r3_o(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4052 o
->in1
= regs
[get_field(f
, r3
)];
4055 #define SPEC_in1_r3_o 0
4057 static void in1_r3_32s(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4059 o
->in1
= tcg_temp_new_i64();
4060 tcg_gen_ext32s_i64(o
->in1
, regs
[get_field(f
, r3
)]);
4062 #define SPEC_in1_r3_32s 0
4064 static void in1_r3_32u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4066 o
->in1
= tcg_temp_new_i64();
4067 tcg_gen_ext32u_i64(o
->in1
, regs
[get_field(f
, r3
)]);
4069 #define SPEC_in1_r3_32u 0
4071 static void in1_r3_D32(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4073 int r3
= get_field(f
, r3
);
4074 o
->in1
= tcg_temp_new_i64();
4075 tcg_gen_concat32_i64(o
->in1
, regs
[r3
+ 1], regs
[r3
]);
4077 #define SPEC_in1_r3_D32 SPEC_r3_even
4079 static void in1_e1(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4081 o
->in1
= load_freg32_i64(get_field(f
, r1
));
4083 #define SPEC_in1_e1 0
4085 static void in1_f1_o(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4087 o
->in1
= fregs
[get_field(f
, r1
)];
4090 #define SPEC_in1_f1_o 0
4092 static void in1_x1_o(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4094 int r1
= get_field(f
, r1
);
4096 o
->out2
= fregs
[r1
+ 2];
4097 o
->g_out
= o
->g_out2
= true;
4099 #define SPEC_in1_x1_o SPEC_r1_f128
4101 static void in1_f3_o(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4103 o
->in1
= fregs
[get_field(f
, r3
)];
4106 #define SPEC_in1_f3_o 0
4108 static void in1_la1(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4110 o
->addr1
= get_address(s
, 0, get_field(f
, b1
), get_field(f
, d1
));
4112 #define SPEC_in1_la1 0
4114 static void in1_la2(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4116 int x2
= have_field(f
, x2
) ? get_field(f
, x2
) : 0;
4117 o
->addr1
= get_address(s
, x2
, get_field(f
, b2
), get_field(f
, d2
));
4119 #define SPEC_in1_la2 0
4121 static void in1_m1_8u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4124 o
->in1
= tcg_temp_new_i64();
4125 tcg_gen_qemu_ld8u(o
->in1
, o
->addr1
, get_mem_index(s
));
4127 #define SPEC_in1_m1_8u 0
4129 static void in1_m1_16s(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4132 o
->in1
= tcg_temp_new_i64();
4133 tcg_gen_qemu_ld16s(o
->in1
, o
->addr1
, get_mem_index(s
));
4135 #define SPEC_in1_m1_16s 0
4137 static void in1_m1_16u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4140 o
->in1
= tcg_temp_new_i64();
4141 tcg_gen_qemu_ld16u(o
->in1
, o
->addr1
, get_mem_index(s
));
4143 #define SPEC_in1_m1_16u 0
4145 static void in1_m1_32s(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4148 o
->in1
= tcg_temp_new_i64();
4149 tcg_gen_qemu_ld32s(o
->in1
, o
->addr1
, get_mem_index(s
));
4151 #define SPEC_in1_m1_32s 0
4153 static void in1_m1_32u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4156 o
->in1
= tcg_temp_new_i64();
4157 tcg_gen_qemu_ld32u(o
->in1
, o
->addr1
, get_mem_index(s
));
4159 #define SPEC_in1_m1_32u 0
4161 static void in1_m1_64(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4164 o
->in1
= tcg_temp_new_i64();
4165 tcg_gen_qemu_ld64(o
->in1
, o
->addr1
, get_mem_index(s
));
4167 #define SPEC_in1_m1_64 0
4169 /* ====================================================================== */
4170 /* The "INput 2" generators. These load the second operand to an insn. */
4172 static void in2_r1_o(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4174 o
->in2
= regs
[get_field(f
, r1
)];
4177 #define SPEC_in2_r1_o 0
4179 static void in2_r1_16u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4181 o
->in2
= tcg_temp_new_i64();
4182 tcg_gen_ext16u_i64(o
->in2
, regs
[get_field(f
, r1
)]);
4184 #define SPEC_in2_r1_16u 0
4186 static void in2_r1_32u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4188 o
->in2
= tcg_temp_new_i64();
4189 tcg_gen_ext32u_i64(o
->in2
, regs
[get_field(f
, r1
)]);
4191 #define SPEC_in2_r1_32u 0
4193 static void in2_r1_D32(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4195 int r1
= get_field(f
, r1
);
4196 o
->in2
= tcg_temp_new_i64();
4197 tcg_gen_concat32_i64(o
->in2
, regs
[r1
+ 1], regs
[r1
]);
4199 #define SPEC_in2_r1_D32 SPEC_r1_even
4201 static void in2_r2(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4203 o
->in2
= load_reg(get_field(f
, r2
));
4205 #define SPEC_in2_r2 0
4207 static void in2_r2_o(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4209 o
->in2
= regs
[get_field(f
, r2
)];
4212 #define SPEC_in2_r2_o 0
4214 static void in2_r2_nz(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4216 int r2
= get_field(f
, r2
);
4218 o
->in2
= load_reg(r2
);
4221 #define SPEC_in2_r2_nz 0
4223 static void in2_r2_8s(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4225 o
->in2
= tcg_temp_new_i64();
4226 tcg_gen_ext8s_i64(o
->in2
, regs
[get_field(f
, r2
)]);
4228 #define SPEC_in2_r2_8s 0
4230 static void in2_r2_8u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4232 o
->in2
= tcg_temp_new_i64();
4233 tcg_gen_ext8u_i64(o
->in2
, regs
[get_field(f
, r2
)]);
4235 #define SPEC_in2_r2_8u 0
4237 static void in2_r2_16s(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4239 o
->in2
= tcg_temp_new_i64();
4240 tcg_gen_ext16s_i64(o
->in2
, regs
[get_field(f
, r2
)]);
4242 #define SPEC_in2_r2_16s 0
4244 static void in2_r2_16u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4246 o
->in2
= tcg_temp_new_i64();
4247 tcg_gen_ext16u_i64(o
->in2
, regs
[get_field(f
, r2
)]);
4249 #define SPEC_in2_r2_16u 0
4251 static void in2_r3(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4253 o
->in2
= load_reg(get_field(f
, r3
));
4255 #define SPEC_in2_r3 0
4257 static void in2_r2_32s(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4259 o
->in2
= tcg_temp_new_i64();
4260 tcg_gen_ext32s_i64(o
->in2
, regs
[get_field(f
, r2
)]);
4262 #define SPEC_in2_r2_32s 0
4264 static void in2_r2_32u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4266 o
->in2
= tcg_temp_new_i64();
4267 tcg_gen_ext32u_i64(o
->in2
, regs
[get_field(f
, r2
)]);
4269 #define SPEC_in2_r2_32u 0
4271 static void in2_e2(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4273 o
->in2
= load_freg32_i64(get_field(f
, r2
));
4275 #define SPEC_in2_e2 0
4277 static void in2_f2_o(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4279 o
->in2
= fregs
[get_field(f
, r2
)];
4282 #define SPEC_in2_f2_o 0
4284 static void in2_x2_o(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4286 int r2
= get_field(f
, r2
);
4288 o
->in2
= fregs
[r2
+ 2];
4289 o
->g_in1
= o
->g_in2
= true;
4291 #define SPEC_in2_x2_o SPEC_r2_f128
4293 static void in2_ra2(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4295 o
->in2
= get_address(s
, 0, get_field(f
, r2
), 0);
4297 #define SPEC_in2_ra2 0
4299 static void in2_a2(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4301 int x2
= have_field(f
, x2
) ? get_field(f
, x2
) : 0;
4302 o
->in2
= get_address(s
, x2
, get_field(f
, b2
), get_field(f
, d2
));
4304 #define SPEC_in2_a2 0
4306 static void in2_ri2(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4308 o
->in2
= tcg_const_i64(s
->pc
+ (int64_t)get_field(f
, i2
) * 2);
4310 #define SPEC_in2_ri2 0
4312 static void in2_sh32(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4314 help_l2_shift(s
, f
, o
, 31);
4316 #define SPEC_in2_sh32 0
4318 static void in2_sh64(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4320 help_l2_shift(s
, f
, o
, 63);
4322 #define SPEC_in2_sh64 0
4324 static void in2_m2_8u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4327 tcg_gen_qemu_ld8u(o
->in2
, o
->in2
, get_mem_index(s
));
4329 #define SPEC_in2_m2_8u 0
4331 static void in2_m2_16s(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4334 tcg_gen_qemu_ld16s(o
->in2
, o
->in2
, get_mem_index(s
));
4336 #define SPEC_in2_m2_16s 0
4338 static void in2_m2_16u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4341 tcg_gen_qemu_ld16u(o
->in2
, o
->in2
, get_mem_index(s
));
4343 #define SPEC_in2_m2_16u 0
4345 static void in2_m2_32s(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4348 tcg_gen_qemu_ld32s(o
->in2
, o
->in2
, get_mem_index(s
));
4350 #define SPEC_in2_m2_32s 0
4352 static void in2_m2_32u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4355 tcg_gen_qemu_ld32u(o
->in2
, o
->in2
, get_mem_index(s
));
4357 #define SPEC_in2_m2_32u 0
4359 static void in2_m2_64(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4362 tcg_gen_qemu_ld64(o
->in2
, o
->in2
, get_mem_index(s
));
4364 #define SPEC_in2_m2_64 0
4366 static void in2_mri2_16u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4369 tcg_gen_qemu_ld16u(o
->in2
, o
->in2
, get_mem_index(s
));
4371 #define SPEC_in2_mri2_16u 0
4373 static void in2_mri2_32s(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4376 tcg_gen_qemu_ld32s(o
->in2
, o
->in2
, get_mem_index(s
));
4378 #define SPEC_in2_mri2_32s 0
4380 static void in2_mri2_32u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4383 tcg_gen_qemu_ld32u(o
->in2
, o
->in2
, get_mem_index(s
));
4385 #define SPEC_in2_mri2_32u 0
4387 static void in2_mri2_64(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4390 tcg_gen_qemu_ld64(o
->in2
, o
->in2
, get_mem_index(s
));
4392 #define SPEC_in2_mri2_64 0
4394 static void in2_i2(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4396 o
->in2
= tcg_const_i64(get_field(f
, i2
));
4398 #define SPEC_in2_i2 0
4400 static void in2_i2_8u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4402 o
->in2
= tcg_const_i64((uint8_t)get_field(f
, i2
));
4404 #define SPEC_in2_i2_8u 0
4406 static void in2_i2_16u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4408 o
->in2
= tcg_const_i64((uint16_t)get_field(f
, i2
));
4410 #define SPEC_in2_i2_16u 0
4412 static void in2_i2_32u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4414 o
->in2
= tcg_const_i64((uint32_t)get_field(f
, i2
));
4416 #define SPEC_in2_i2_32u 0
4418 static void in2_i2_16u_shl(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4420 uint64_t i2
= (uint16_t)get_field(f
, i2
);
4421 o
->in2
= tcg_const_i64(i2
<< s
->insn
->data
);
4423 #define SPEC_in2_i2_16u_shl 0
4425 static void in2_i2_32u_shl(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4427 uint64_t i2
= (uint32_t)get_field(f
, i2
);
4428 o
->in2
= tcg_const_i64(i2
<< s
->insn
->data
);
4430 #define SPEC_in2_i2_32u_shl 0
4432 /* ====================================================================== */
4434 /* Find opc within the table of insns. This is formulated as a switch
4435 statement so that (1) we get compile-time notice of cut-paste errors
4436 for duplicated opcodes, and (2) the compiler generates the binary
4437 search tree, rather than us having to post-process the table. */
4439 #define C(OPC, NM, FT, FC, I1, I2, P, W, OP, CC) \
4440 D(OPC, NM, FT, FC, I1, I2, P, W, OP, CC, 0)
4442 #define D(OPC, NM, FT, FC, I1, I2, P, W, OP, CC, D) insn_ ## NM,
4444 enum DisasInsnEnum
{
4445 #include "insn-data.def"
4449 #define D(OPC, NM, FT, FC, I1, I2, P, W, OP, CC, D) { \
4453 .spec = SPEC_in1_##I1 | SPEC_in2_##I2 | SPEC_prep_##P | SPEC_wout_##W, \
4455 .help_in1 = in1_##I1, \
4456 .help_in2 = in2_##I2, \
4457 .help_prep = prep_##P, \
4458 .help_wout = wout_##W, \
4459 .help_cout = cout_##CC, \
4460 .help_op = op_##OP, \
4464 /* Allow 0 to be used for NULL in the table below. */
4472 #define SPEC_in1_0 0
4473 #define SPEC_in2_0 0
4474 #define SPEC_prep_0 0
4475 #define SPEC_wout_0 0
4477 static const DisasInsn insn_info
[] = {
4478 #include "insn-data.def"
4482 #define D(OPC, NM, FT, FC, I1, I2, P, W, OP, CC, D) \
4483 case OPC: return &insn_info[insn_ ## NM];
4485 static const DisasInsn
*lookup_opc(uint16_t opc
)
4488 #include "insn-data.def"
4497 /* Extract a field from the insn. The INSN should be left-aligned in
4498 the uint64_t so that we can more easily utilize the big-bit-endian
4499 definitions we extract from the Principals of Operation. */
4501 static void extract_field(DisasFields
*o
, const DisasField
*f
, uint64_t insn
)
4509 /* Zero extract the field from the insn. */
4510 r
= (insn
<< f
->beg
) >> (64 - f
->size
);
4512 /* Sign-extend, or un-swap the field as necessary. */
4514 case 0: /* unsigned */
4516 case 1: /* signed */
4517 assert(f
->size
<= 32);
4518 m
= 1u << (f
->size
- 1);
4521 case 2: /* dl+dh split, signed 20 bit. */
4522 r
= ((int8_t)r
<< 12) | (r
>> 8);
4528 /* Validate that the "compressed" encoding we selected above is valid.
4529 I.e. we havn't make two different original fields overlap. */
4530 assert(((o
->presentC
>> f
->indexC
) & 1) == 0);
4531 o
->presentC
|= 1 << f
->indexC
;
4532 o
->presentO
|= 1 << f
->indexO
;
4534 o
->c
[f
->indexC
] = r
;
4537 /* Lookup the insn at the current PC, extracting the operands into O and
4538 returning the info struct for the insn. Returns NULL for invalid insn. */
4540 static const DisasInsn
*extract_insn(CPUS390XState
*env
, DisasContext
*s
,
4543 uint64_t insn
, pc
= s
->pc
;
4545 const DisasInsn
*info
;
4547 insn
= ld_code2(env
, pc
);
4548 op
= (insn
>> 8) & 0xff;
4549 ilen
= get_ilen(op
);
4550 s
->next_pc
= s
->pc
+ ilen
;
4557 insn
= ld_code4(env
, pc
) << 32;
4560 insn
= (insn
<< 48) | (ld_code4(env
, pc
+ 2) << 16);
4566 /* We can't actually determine the insn format until we've looked up
4567 the full insn opcode. Which we can't do without locating the
4568 secondary opcode. Assume by default that OP2 is at bit 40; for
4569 those smaller insns that don't actually have a secondary opcode
4570 this will correctly result in OP2 = 0. */
4576 case 0xb2: /* S, RRF, RRE */
4577 case 0xb3: /* RRE, RRD, RRF */
4578 case 0xb9: /* RRE, RRF */
4579 case 0xe5: /* SSE, SIL */
4580 op2
= (insn
<< 8) >> 56;
4584 case 0xc0: /* RIL */
4585 case 0xc2: /* RIL */
4586 case 0xc4: /* RIL */
4587 case 0xc6: /* RIL */
4588 case 0xc8: /* SSF */
4589 case 0xcc: /* RIL */
4590 op2
= (insn
<< 12) >> 60;
4592 case 0xd0 ... 0xdf: /* SS */
4598 case 0xee ... 0xf3: /* SS */
4599 case 0xf8 ... 0xfd: /* SS */
4603 op2
= (insn
<< 40) >> 56;
4607 memset(f
, 0, sizeof(*f
));
4611 /* Lookup the instruction. */
4612 info
= lookup_opc(op
<< 8 | op2
);
4614 /* If we found it, extract the operands. */
4616 DisasFormat fmt
= info
->fmt
;
4619 for (i
= 0; i
< NUM_C_FIELD
; ++i
) {
4620 extract_field(f
, &format_info
[fmt
].op
[i
], insn
);
4626 static ExitStatus
translate_one(CPUS390XState
*env
, DisasContext
*s
)
4628 const DisasInsn
*insn
;
4629 ExitStatus ret
= NO_EXIT
;
4633 /* Search for the insn in the table. */
4634 insn
= extract_insn(env
, s
, &f
);
4636 /* Not found means unimplemented/illegal opcode. */
4638 qemu_log_mask(LOG_UNIMP
, "unimplemented opcode 0x%02x%02x\n",
4640 gen_illegal_opcode(s
);
4641 return EXIT_NORETURN
;
4644 /* Check for insn specification exceptions. */
4646 int spec
= insn
->spec
, excp
= 0, r
;
4648 if (spec
& SPEC_r1_even
) {
4649 r
= get_field(&f
, r1
);
4651 excp
= PGM_SPECIFICATION
;
4654 if (spec
& SPEC_r2_even
) {
4655 r
= get_field(&f
, r2
);
4657 excp
= PGM_SPECIFICATION
;
4660 if (spec
& SPEC_r3_even
) {
4661 r
= get_field(&f
, r3
);
4663 excp
= PGM_SPECIFICATION
;
4666 if (spec
& SPEC_r1_f128
) {
4667 r
= get_field(&f
, r1
);
4669 excp
= PGM_SPECIFICATION
;
4672 if (spec
& SPEC_r2_f128
) {
4673 r
= get_field(&f
, r2
);
4675 excp
= PGM_SPECIFICATION
;
4679 gen_program_exception(s
, excp
);
4680 return EXIT_NORETURN
;
4684 /* Set up the strutures we use to communicate with the helpers. */
4687 o
.g_out
= o
.g_out2
= o
.g_in1
= o
.g_in2
= false;
4688 TCGV_UNUSED_I64(o
.out
);
4689 TCGV_UNUSED_I64(o
.out2
);
4690 TCGV_UNUSED_I64(o
.in1
);
4691 TCGV_UNUSED_I64(o
.in2
);
4692 TCGV_UNUSED_I64(o
.addr1
);
4694 /* Implement the instruction. */
4695 if (insn
->help_in1
) {
4696 insn
->help_in1(s
, &f
, &o
);
4698 if (insn
->help_in2
) {
4699 insn
->help_in2(s
, &f
, &o
);
4701 if (insn
->help_prep
) {
4702 insn
->help_prep(s
, &f
, &o
);
4704 if (insn
->help_op
) {
4705 ret
= insn
->help_op(s
, &o
);
4707 if (insn
->help_wout
) {
4708 insn
->help_wout(s
, &f
, &o
);
4710 if (insn
->help_cout
) {
4711 insn
->help_cout(s
, &o
);
4714 /* Free any temporaries created by the helpers. */
4715 if (!TCGV_IS_UNUSED_I64(o
.out
) && !o
.g_out
) {
4716 tcg_temp_free_i64(o
.out
);
4718 if (!TCGV_IS_UNUSED_I64(o
.out2
) && !o
.g_out2
) {
4719 tcg_temp_free_i64(o
.out2
);
4721 if (!TCGV_IS_UNUSED_I64(o
.in1
) && !o
.g_in1
) {
4722 tcg_temp_free_i64(o
.in1
);
4724 if (!TCGV_IS_UNUSED_I64(o
.in2
) && !o
.g_in2
) {
4725 tcg_temp_free_i64(o
.in2
);
4727 if (!TCGV_IS_UNUSED_I64(o
.addr1
)) {
4728 tcg_temp_free_i64(o
.addr1
);
4731 /* Advance to the next instruction. */
4736 static inline void gen_intermediate_code_internal(CPUS390XState
*env
,
4737 TranslationBlock
*tb
,
4741 target_ulong pc_start
;
4742 uint64_t next_page_start
;
4743 uint16_t *gen_opc_end
;
4745 int num_insns
, max_insns
;
4753 if (!(tb
->flags
& FLAG_MASK_64
)) {
4754 pc_start
&= 0x7fffffff;
4759 dc
.cc_op
= CC_OP_DYNAMIC
;
4760 do_debug
= dc
.singlestep_enabled
= env
->singlestep_enabled
;
4762 gen_opc_end
= tcg_ctx
.gen_opc_buf
+ OPC_MAX_SIZE
;
4764 next_page_start
= (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
4767 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
4768 if (max_insns
== 0) {
4769 max_insns
= CF_COUNT_MASK
;
4776 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
4780 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
4783 tcg_ctx
.gen_opc_pc
[lj
] = dc
.pc
;
4784 gen_opc_cc_op
[lj
] = dc
.cc_op
;
4785 tcg_ctx
.gen_opc_instr_start
[lj
] = 1;
4786 tcg_ctx
.gen_opc_icount
[lj
] = num_insns
;
4788 if (++num_insns
== max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
4792 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
4793 tcg_gen_debug_insn_start(dc
.pc
);
4797 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
4798 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
4799 if (bp
->pc
== dc
.pc
) {
4800 status
= EXIT_PC_STALE
;
4806 if (status
== NO_EXIT
) {
4807 status
= translate_one(env
, &dc
);
4810 /* If we reach a page boundary, are single stepping,
4811 or exhaust instruction count, stop generation. */
4812 if (status
== NO_EXIT
4813 && (dc
.pc
>= next_page_start
4814 || tcg_ctx
.gen_opc_ptr
>= gen_opc_end
4815 || num_insns
>= max_insns
4817 || env
->singlestep_enabled
)) {
4818 status
= EXIT_PC_STALE
;
4820 } while (status
== NO_EXIT
);
4822 if (tb
->cflags
& CF_LAST_IO
) {
4831 update_psw_addr(&dc
);
4833 case EXIT_PC_UPDATED
:
4834 /* Next TB starts off with CC_OP_DYNAMIC, so make sure the
4835 cc op type is in env */
4837 /* Exit the TB, either by raising a debug exception or by return. */
4839 gen_exception(EXCP_DEBUG
);
4848 gen_tb_end(tb
, num_insns
);
4849 *tcg_ctx
.gen_opc_ptr
= INDEX_op_end
;
4851 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
4854 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
4857 tb
->size
= dc
.pc
- pc_start
;
4858 tb
->icount
= num_insns
;
4861 #if defined(S390X_DEBUG_DISAS)
4862 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
4863 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
4864 log_target_disas(env
, pc_start
, dc
.pc
- pc_start
, 1);
4870 void gen_intermediate_code (CPUS390XState
*env
, struct TranslationBlock
*tb
)
4872 gen_intermediate_code_internal(env
, tb
, 0);
4875 void gen_intermediate_code_pc (CPUS390XState
*env
, struct TranslationBlock
*tb
)
4877 gen_intermediate_code_internal(env
, tb
, 1);
4880 void restore_state_to_opc(CPUS390XState
*env
, TranslationBlock
*tb
, int pc_pos
)
4883 env
->psw
.addr
= tcg_ctx
.gen_opc_pc
[pc_pos
];
4884 cc_op
= gen_opc_cc_op
[pc_pos
];
4885 if ((cc_op
!= CC_OP_DYNAMIC
) && (cc_op
!= CC_OP_STATIC
)) {