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"
36 #include "exec/cpu_ldst.h"
38 /* global register indexes */
39 static TCGv_ptr cpu_env
;
41 #include "exec/gen-icount.h"
42 #include "exec/helper-proto.h"
43 #include "exec/helper-gen.h"
45 #include "trace-tcg.h"
48 /* Information that (most) every instruction needs to manipulate. */
49 typedef struct DisasContext DisasContext
;
50 typedef struct DisasInsn DisasInsn
;
51 typedef struct DisasFields DisasFields
;
54 struct TranslationBlock
*tb
;
55 const DisasInsn
*insn
;
59 bool singlestep_enabled
;
62 /* Information carried about a condition to be evaluated. */
69 struct { TCGv_i64 a
, b
; } s64
;
70 struct { TCGv_i32 a
, b
; } s32
;
76 #ifdef DEBUG_INLINE_BRANCHES
77 static uint64_t inline_branch_hit
[CC_OP_MAX
];
78 static uint64_t inline_branch_miss
[CC_OP_MAX
];
81 static uint64_t pc_to_link_info(DisasContext
*s
, uint64_t pc
)
83 if (!(s
->tb
->flags
& FLAG_MASK_64
)) {
84 if (s
->tb
->flags
& FLAG_MASK_32
) {
85 return pc
| 0x80000000;
91 void s390_cpu_dump_state(CPUState
*cs
, FILE *f
, fprintf_function cpu_fprintf
,
94 S390CPU
*cpu
= S390_CPU(cs
);
95 CPUS390XState
*env
= &cpu
->env
;
99 cpu_fprintf(f
, "PSW=mask %016" PRIx64
" addr %016" PRIx64
" cc %15s\n",
100 env
->psw
.mask
, env
->psw
.addr
, cc_name(env
->cc_op
));
102 cpu_fprintf(f
, "PSW=mask %016" PRIx64
" addr %016" PRIx64
" cc %02x\n",
103 env
->psw
.mask
, env
->psw
.addr
, env
->cc_op
);
106 for (i
= 0; i
< 16; i
++) {
107 cpu_fprintf(f
, "R%02d=%016" PRIx64
, i
, env
->regs
[i
]);
109 cpu_fprintf(f
, "\n");
115 for (i
= 0; i
< 16; i
++) {
116 cpu_fprintf(f
, "F%02d=%016" PRIx64
, i
, get_freg(env
, i
)->ll
);
118 cpu_fprintf(f
, "\n");
124 for (i
= 0; i
< 32; i
++) {
125 cpu_fprintf(f
, "V%02d=%016" PRIx64
"%016" PRIx64
, i
,
126 env
->vregs
[i
][0].ll
, env
->vregs
[i
][1].ll
);
127 cpu_fprintf(f
, (i
% 2) ? " " : "\n");
130 #ifndef CONFIG_USER_ONLY
131 for (i
= 0; i
< 16; i
++) {
132 cpu_fprintf(f
, "C%02d=%016" PRIx64
, i
, env
->cregs
[i
]);
134 cpu_fprintf(f
, "\n");
141 #ifdef DEBUG_INLINE_BRANCHES
142 for (i
= 0; i
< CC_OP_MAX
; i
++) {
143 cpu_fprintf(f
, " %15s = %10ld\t%10ld\n", cc_name(i
),
144 inline_branch_miss
[i
], inline_branch_hit
[i
]);
148 cpu_fprintf(f
, "\n");
151 static TCGv_i64 psw_addr
;
152 static TCGv_i64 psw_mask
;
154 static TCGv_i32 cc_op
;
155 static TCGv_i64 cc_src
;
156 static TCGv_i64 cc_dst
;
157 static TCGv_i64 cc_vr
;
159 static char cpu_reg_names
[32][4];
160 static TCGv_i64 regs
[16];
161 static TCGv_i64 fregs
[16];
163 static uint8_t gen_opc_cc_op
[OPC_BUF_SIZE
];
165 void s390x_translate_init(void)
169 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
170 psw_addr
= tcg_global_mem_new_i64(TCG_AREG0
,
171 offsetof(CPUS390XState
, psw
.addr
),
173 psw_mask
= tcg_global_mem_new_i64(TCG_AREG0
,
174 offsetof(CPUS390XState
, psw
.mask
),
177 cc_op
= tcg_global_mem_new_i32(TCG_AREG0
, offsetof(CPUS390XState
, cc_op
),
179 cc_src
= tcg_global_mem_new_i64(TCG_AREG0
, offsetof(CPUS390XState
, cc_src
),
181 cc_dst
= tcg_global_mem_new_i64(TCG_AREG0
, offsetof(CPUS390XState
, cc_dst
),
183 cc_vr
= tcg_global_mem_new_i64(TCG_AREG0
, offsetof(CPUS390XState
, cc_vr
),
186 for (i
= 0; i
< 16; i
++) {
187 snprintf(cpu_reg_names
[i
], sizeof(cpu_reg_names
[0]), "r%d", i
);
188 regs
[i
] = tcg_global_mem_new(TCG_AREG0
,
189 offsetof(CPUS390XState
, regs
[i
]),
193 for (i
= 0; i
< 16; i
++) {
194 snprintf(cpu_reg_names
[i
+ 16], sizeof(cpu_reg_names
[0]), "f%d", i
);
195 fregs
[i
] = tcg_global_mem_new(TCG_AREG0
,
196 offsetof(CPUS390XState
, vregs
[i
][0].d
),
197 cpu_reg_names
[i
+ 16]);
201 static TCGv_i64
load_reg(int reg
)
203 TCGv_i64 r
= tcg_temp_new_i64();
204 tcg_gen_mov_i64(r
, regs
[reg
]);
208 static TCGv_i64
load_freg32_i64(int reg
)
210 TCGv_i64 r
= tcg_temp_new_i64();
211 tcg_gen_shri_i64(r
, fregs
[reg
], 32);
215 static void store_reg(int reg
, TCGv_i64 v
)
217 tcg_gen_mov_i64(regs
[reg
], v
);
220 static void store_freg(int reg
, TCGv_i64 v
)
222 tcg_gen_mov_i64(fregs
[reg
], v
);
225 static void store_reg32_i64(int reg
, TCGv_i64 v
)
227 /* 32 bit register writes keep the upper half */
228 tcg_gen_deposit_i64(regs
[reg
], regs
[reg
], v
, 0, 32);
231 static void store_reg32h_i64(int reg
, TCGv_i64 v
)
233 tcg_gen_deposit_i64(regs
[reg
], regs
[reg
], v
, 32, 32);
236 static void store_freg32_i64(int reg
, TCGv_i64 v
)
238 tcg_gen_deposit_i64(fregs
[reg
], fregs
[reg
], v
, 32, 32);
241 static void return_low128(TCGv_i64 dest
)
243 tcg_gen_ld_i64(dest
, cpu_env
, offsetof(CPUS390XState
, retxl
));
246 static void update_psw_addr(DisasContext
*s
)
249 tcg_gen_movi_i64(psw_addr
, s
->pc
);
252 static void update_cc_op(DisasContext
*s
)
254 if (s
->cc_op
!= CC_OP_DYNAMIC
&& s
->cc_op
!= CC_OP_STATIC
) {
255 tcg_gen_movi_i32(cc_op
, s
->cc_op
);
259 static void potential_page_fault(DisasContext
*s
)
265 static inline uint64_t ld_code2(CPUS390XState
*env
, uint64_t pc
)
267 return (uint64_t)cpu_lduw_code(env
, pc
);
270 static inline uint64_t ld_code4(CPUS390XState
*env
, uint64_t pc
)
272 return (uint64_t)(uint32_t)cpu_ldl_code(env
, pc
);
275 static int get_mem_index(DisasContext
*s
)
277 switch (s
->tb
->flags
& FLAG_MASK_ASC
) {
278 case PSW_ASC_PRIMARY
>> 32:
280 case PSW_ASC_SECONDARY
>> 32:
282 case PSW_ASC_HOME
>> 32:
290 static void gen_exception(int excp
)
292 TCGv_i32 tmp
= tcg_const_i32(excp
);
293 gen_helper_exception(cpu_env
, tmp
);
294 tcg_temp_free_i32(tmp
);
297 static void gen_program_exception(DisasContext
*s
, int code
)
301 /* Remember what pgm exeption this was. */
302 tmp
= tcg_const_i32(code
);
303 tcg_gen_st_i32(tmp
, cpu_env
, offsetof(CPUS390XState
, int_pgm_code
));
304 tcg_temp_free_i32(tmp
);
306 tmp
= tcg_const_i32(s
->next_pc
- s
->pc
);
307 tcg_gen_st_i32(tmp
, cpu_env
, offsetof(CPUS390XState
, int_pgm_ilen
));
308 tcg_temp_free_i32(tmp
);
310 /* Advance past instruction. */
317 /* Trigger exception. */
318 gen_exception(EXCP_PGM
);
321 static inline void gen_illegal_opcode(DisasContext
*s
)
323 gen_program_exception(s
, PGM_SPECIFICATION
);
326 #ifndef CONFIG_USER_ONLY
327 static void check_privileged(DisasContext
*s
)
329 if (s
->tb
->flags
& (PSW_MASK_PSTATE
>> 32)) {
330 gen_program_exception(s
, PGM_PRIVILEGED
);
335 static TCGv_i64
get_address(DisasContext
*s
, int x2
, int b2
, int d2
)
337 TCGv_i64 tmp
= tcg_temp_new_i64();
338 bool need_31
= !(s
->tb
->flags
& FLAG_MASK_64
);
340 /* Note that d2 is limited to 20 bits, signed. If we crop negative
341 displacements early we create larger immedate addends. */
343 /* Note that addi optimizes the imm==0 case. */
345 tcg_gen_add_i64(tmp
, regs
[b2
], regs
[x2
]);
346 tcg_gen_addi_i64(tmp
, tmp
, d2
);
348 tcg_gen_addi_i64(tmp
, regs
[b2
], d2
);
350 tcg_gen_addi_i64(tmp
, regs
[x2
], d2
);
356 tcg_gen_movi_i64(tmp
, d2
);
359 tcg_gen_andi_i64(tmp
, tmp
, 0x7fffffff);
365 static inline bool live_cc_data(DisasContext
*s
)
367 return (s
->cc_op
!= CC_OP_DYNAMIC
368 && s
->cc_op
!= CC_OP_STATIC
372 static inline void gen_op_movi_cc(DisasContext
*s
, uint32_t val
)
374 if (live_cc_data(s
)) {
375 tcg_gen_discard_i64(cc_src
);
376 tcg_gen_discard_i64(cc_dst
);
377 tcg_gen_discard_i64(cc_vr
);
379 s
->cc_op
= CC_OP_CONST0
+ val
;
382 static void gen_op_update1_cc_i64(DisasContext
*s
, enum cc_op op
, TCGv_i64 dst
)
384 if (live_cc_data(s
)) {
385 tcg_gen_discard_i64(cc_src
);
386 tcg_gen_discard_i64(cc_vr
);
388 tcg_gen_mov_i64(cc_dst
, dst
);
392 static void gen_op_update2_cc_i64(DisasContext
*s
, enum cc_op op
, TCGv_i64 src
,
395 if (live_cc_data(s
)) {
396 tcg_gen_discard_i64(cc_vr
);
398 tcg_gen_mov_i64(cc_src
, src
);
399 tcg_gen_mov_i64(cc_dst
, dst
);
403 static void gen_op_update3_cc_i64(DisasContext
*s
, enum cc_op op
, TCGv_i64 src
,
404 TCGv_i64 dst
, TCGv_i64 vr
)
406 tcg_gen_mov_i64(cc_src
, src
);
407 tcg_gen_mov_i64(cc_dst
, dst
);
408 tcg_gen_mov_i64(cc_vr
, vr
);
412 static void set_cc_nz_u64(DisasContext
*s
, TCGv_i64 val
)
414 gen_op_update1_cc_i64(s
, CC_OP_NZ
, val
);
417 static void gen_set_cc_nz_f32(DisasContext
*s
, TCGv_i64 val
)
419 gen_op_update1_cc_i64(s
, CC_OP_NZ_F32
, val
);
422 static void gen_set_cc_nz_f64(DisasContext
*s
, TCGv_i64 val
)
424 gen_op_update1_cc_i64(s
, CC_OP_NZ_F64
, val
);
427 static void gen_set_cc_nz_f128(DisasContext
*s
, TCGv_i64 vh
, TCGv_i64 vl
)
429 gen_op_update2_cc_i64(s
, CC_OP_NZ_F128
, vh
, vl
);
432 /* CC value is in env->cc_op */
433 static void set_cc_static(DisasContext
*s
)
435 if (live_cc_data(s
)) {
436 tcg_gen_discard_i64(cc_src
);
437 tcg_gen_discard_i64(cc_dst
);
438 tcg_gen_discard_i64(cc_vr
);
440 s
->cc_op
= CC_OP_STATIC
;
443 /* calculates cc into cc_op */
444 static void gen_op_calc_cc(DisasContext
*s
)
446 TCGv_i32 local_cc_op
;
449 TCGV_UNUSED_I32(local_cc_op
);
450 TCGV_UNUSED_I64(dummy
);
453 dummy
= tcg_const_i64(0);
467 local_cc_op
= tcg_const_i32(s
->cc_op
);
483 /* s->cc_op is the cc value */
484 tcg_gen_movi_i32(cc_op
, s
->cc_op
- CC_OP_CONST0
);
487 /* env->cc_op already is the cc value */
502 gen_helper_calc_cc(cc_op
, cpu_env
, local_cc_op
, dummy
, cc_dst
, dummy
);
507 case CC_OP_LTUGTU_32
:
508 case CC_OP_LTUGTU_64
:
515 gen_helper_calc_cc(cc_op
, cpu_env
, local_cc_op
, cc_src
, cc_dst
, dummy
);
530 gen_helper_calc_cc(cc_op
, cpu_env
, local_cc_op
, cc_src
, cc_dst
, cc_vr
);
533 /* unknown operation - assume 3 arguments and cc_op in env */
534 gen_helper_calc_cc(cc_op
, cpu_env
, cc_op
, cc_src
, cc_dst
, cc_vr
);
540 if (!TCGV_IS_UNUSED_I32(local_cc_op
)) {
541 tcg_temp_free_i32(local_cc_op
);
543 if (!TCGV_IS_UNUSED_I64(dummy
)) {
544 tcg_temp_free_i64(dummy
);
547 /* We now have cc in cc_op as constant */
551 static int use_goto_tb(DisasContext
*s
, uint64_t dest
)
553 /* NOTE: we handle the case where the TB spans two pages here */
554 return (((dest
& TARGET_PAGE_MASK
) == (s
->tb
->pc
& TARGET_PAGE_MASK
)
555 || (dest
& TARGET_PAGE_MASK
) == ((s
->pc
- 1) & TARGET_PAGE_MASK
))
556 && !s
->singlestep_enabled
557 && !(s
->tb
->cflags
& CF_LAST_IO
));
560 static void account_noninline_branch(DisasContext
*s
, int cc_op
)
562 #ifdef DEBUG_INLINE_BRANCHES
563 inline_branch_miss
[cc_op
]++;
567 static void account_inline_branch(DisasContext
*s
, int cc_op
)
569 #ifdef DEBUG_INLINE_BRANCHES
570 inline_branch_hit
[cc_op
]++;
574 /* Table of mask values to comparison codes, given a comparison as input.
575 For such, CC=3 should not be possible. */
576 static const TCGCond ltgt_cond
[16] = {
577 TCG_COND_NEVER
, TCG_COND_NEVER
, /* | | | x */
578 TCG_COND_GT
, TCG_COND_GT
, /* | | GT | x */
579 TCG_COND_LT
, TCG_COND_LT
, /* | LT | | x */
580 TCG_COND_NE
, TCG_COND_NE
, /* | LT | GT | x */
581 TCG_COND_EQ
, TCG_COND_EQ
, /* EQ | | | x */
582 TCG_COND_GE
, TCG_COND_GE
, /* EQ | | GT | x */
583 TCG_COND_LE
, TCG_COND_LE
, /* EQ | LT | | x */
584 TCG_COND_ALWAYS
, TCG_COND_ALWAYS
, /* EQ | LT | GT | x */
587 /* Table of mask values to comparison codes, given a logic op as input.
588 For such, only CC=0 and CC=1 should be possible. */
589 static const TCGCond nz_cond
[16] = {
590 TCG_COND_NEVER
, TCG_COND_NEVER
, /* | | x | x */
591 TCG_COND_NEVER
, TCG_COND_NEVER
,
592 TCG_COND_NE
, TCG_COND_NE
, /* | NE | x | x */
593 TCG_COND_NE
, TCG_COND_NE
,
594 TCG_COND_EQ
, TCG_COND_EQ
, /* EQ | | x | x */
595 TCG_COND_EQ
, TCG_COND_EQ
,
596 TCG_COND_ALWAYS
, TCG_COND_ALWAYS
, /* EQ | NE | x | x */
597 TCG_COND_ALWAYS
, TCG_COND_ALWAYS
,
600 /* Interpret MASK in terms of S->CC_OP, and fill in C with all the
601 details required to generate a TCG comparison. */
602 static void disas_jcc(DisasContext
*s
, DisasCompare
*c
, uint32_t mask
)
605 enum cc_op old_cc_op
= s
->cc_op
;
607 if (mask
== 15 || mask
== 0) {
608 c
->cond
= (mask
? TCG_COND_ALWAYS
: TCG_COND_NEVER
);
611 c
->g1
= c
->g2
= true;
616 /* Find the TCG condition for the mask + cc op. */
622 cond
= ltgt_cond
[mask
];
623 if (cond
== TCG_COND_NEVER
) {
626 account_inline_branch(s
, old_cc_op
);
629 case CC_OP_LTUGTU_32
:
630 case CC_OP_LTUGTU_64
:
631 cond
= tcg_unsigned_cond(ltgt_cond
[mask
]);
632 if (cond
== TCG_COND_NEVER
) {
635 account_inline_branch(s
, old_cc_op
);
639 cond
= nz_cond
[mask
];
640 if (cond
== TCG_COND_NEVER
) {
643 account_inline_branch(s
, old_cc_op
);
658 account_inline_branch(s
, old_cc_op
);
673 account_inline_branch(s
, old_cc_op
);
677 switch (mask
& 0xa) {
678 case 8: /* src == 0 -> no one bit found */
681 case 2: /* src != 0 -> one bit found */
687 account_inline_branch(s
, old_cc_op
);
693 case 8 | 2: /* vr == 0 */
696 case 4 | 1: /* vr != 0 */
699 case 8 | 4: /* no carry -> vr >= src */
702 case 2 | 1: /* carry -> vr < src */
708 account_inline_branch(s
, old_cc_op
);
713 /* Note that CC=0 is impossible; treat it as dont-care. */
715 case 2: /* zero -> op1 == op2 */
718 case 4 | 1: /* !zero -> op1 != op2 */
721 case 4: /* borrow (!carry) -> op1 < op2 */
724 case 2 | 1: /* !borrow (carry) -> op1 >= op2 */
730 account_inline_branch(s
, old_cc_op
);
735 /* Calculate cc value. */
740 /* Jump based on CC. We'll load up the real cond below;
741 the assignment here merely avoids a compiler warning. */
742 account_noninline_branch(s
, old_cc_op
);
743 old_cc_op
= CC_OP_STATIC
;
744 cond
= TCG_COND_NEVER
;
748 /* Load up the arguments of the comparison. */
750 c
->g1
= c
->g2
= false;
754 c
->u
.s32
.a
= tcg_temp_new_i32();
755 tcg_gen_trunc_i64_i32(c
->u
.s32
.a
, cc_dst
);
756 c
->u
.s32
.b
= tcg_const_i32(0);
759 case CC_OP_LTUGTU_32
:
762 c
->u
.s32
.a
= tcg_temp_new_i32();
763 tcg_gen_trunc_i64_i32(c
->u
.s32
.a
, cc_src
);
764 c
->u
.s32
.b
= tcg_temp_new_i32();
765 tcg_gen_trunc_i64_i32(c
->u
.s32
.b
, cc_dst
);
772 c
->u
.s64
.b
= tcg_const_i64(0);
776 case CC_OP_LTUGTU_64
:
780 c
->g1
= c
->g2
= true;
786 c
->u
.s64
.a
= tcg_temp_new_i64();
787 c
->u
.s64
.b
= tcg_const_i64(0);
788 tcg_gen_and_i64(c
->u
.s64
.a
, cc_src
, cc_dst
);
793 c
->u
.s32
.a
= tcg_temp_new_i32();
794 c
->u
.s32
.b
= tcg_temp_new_i32();
795 tcg_gen_trunc_i64_i32(c
->u
.s32
.a
, cc_vr
);
796 if (cond
== TCG_COND_EQ
|| cond
== TCG_COND_NE
) {
797 tcg_gen_movi_i32(c
->u
.s32
.b
, 0);
799 tcg_gen_trunc_i64_i32(c
->u
.s32
.b
, cc_src
);
806 if (cond
== TCG_COND_EQ
|| cond
== TCG_COND_NE
) {
807 c
->u
.s64
.b
= tcg_const_i64(0);
819 case 0x8 | 0x4 | 0x2: /* cc != 3 */
821 c
->u
.s32
.b
= tcg_const_i32(3);
823 case 0x8 | 0x4 | 0x1: /* cc != 2 */
825 c
->u
.s32
.b
= tcg_const_i32(2);
827 case 0x8 | 0x2 | 0x1: /* cc != 1 */
829 c
->u
.s32
.b
= tcg_const_i32(1);
831 case 0x8 | 0x2: /* cc == 0 ||Â cc == 2 => (cc & 1) == 0 */
834 c
->u
.s32
.a
= tcg_temp_new_i32();
835 c
->u
.s32
.b
= tcg_const_i32(0);
836 tcg_gen_andi_i32(c
->u
.s32
.a
, cc_op
, 1);
838 case 0x8 | 0x4: /* cc < 2 */
840 c
->u
.s32
.b
= tcg_const_i32(2);
842 case 0x8: /* cc == 0 */
844 c
->u
.s32
.b
= tcg_const_i32(0);
846 case 0x4 | 0x2 | 0x1: /* cc != 0 */
848 c
->u
.s32
.b
= tcg_const_i32(0);
850 case 0x4 | 0x1: /* cc == 1 ||Â cc == 3 => (cc & 1) != 0 */
853 c
->u
.s32
.a
= tcg_temp_new_i32();
854 c
->u
.s32
.b
= tcg_const_i32(0);
855 tcg_gen_andi_i32(c
->u
.s32
.a
, cc_op
, 1);
857 case 0x4: /* cc == 1 */
859 c
->u
.s32
.b
= tcg_const_i32(1);
861 case 0x2 | 0x1: /* cc > 1 */
863 c
->u
.s32
.b
= tcg_const_i32(1);
865 case 0x2: /* cc == 2 */
867 c
->u
.s32
.b
= tcg_const_i32(2);
869 case 0x1: /* cc == 3 */
871 c
->u
.s32
.b
= tcg_const_i32(3);
874 /* CC is masked by something else: (8 >> cc) & mask. */
877 c
->u
.s32
.a
= tcg_const_i32(8);
878 c
->u
.s32
.b
= tcg_const_i32(0);
879 tcg_gen_shr_i32(c
->u
.s32
.a
, c
->u
.s32
.a
, cc_op
);
880 tcg_gen_andi_i32(c
->u
.s32
.a
, c
->u
.s32
.a
, mask
);
891 static void free_compare(DisasCompare
*c
)
895 tcg_temp_free_i64(c
->u
.s64
.a
);
897 tcg_temp_free_i32(c
->u
.s32
.a
);
902 tcg_temp_free_i64(c
->u
.s64
.b
);
904 tcg_temp_free_i32(c
->u
.s32
.b
);
909 /* ====================================================================== */
910 /* Define the insn format enumeration. */
911 #define F0(N) FMT_##N,
912 #define F1(N, X1) F0(N)
913 #define F2(N, X1, X2) F0(N)
914 #define F3(N, X1, X2, X3) F0(N)
915 #define F4(N, X1, X2, X3, X4) F0(N)
916 #define F5(N, X1, X2, X3, X4, X5) F0(N)
919 #include "insn-format.def"
929 /* Define a structure to hold the decoded fields. We'll store each inside
930 an array indexed by an enum. In order to conserve memory, we'll arrange
931 for fields that do not exist at the same time to overlap, thus the "C"
932 for compact. For checking purposes there is an "O" for original index
933 as well that will be applied to availability bitmaps. */
935 enum DisasFieldIndexO
{
958 enum DisasFieldIndexC
{
992 unsigned presentC
:16;
993 unsigned int presentO
;
997 /* This is the way fields are to be accessed out of DisasFields. */
998 #define have_field(S, F) have_field1((S), FLD_O_##F)
999 #define get_field(S, F) get_field1((S), FLD_O_##F, FLD_C_##F)
1001 static bool have_field1(const DisasFields
*f
, enum DisasFieldIndexO c
)
1003 return (f
->presentO
>> c
) & 1;
1006 static int get_field1(const DisasFields
*f
, enum DisasFieldIndexO o
,
1007 enum DisasFieldIndexC c
)
1009 assert(have_field1(f
, o
));
1013 /* Describe the layout of each field in each format. */
1014 typedef struct DisasField
{
1016 unsigned int size
:8;
1017 unsigned int type
:2;
1018 unsigned int indexC
:6;
1019 enum DisasFieldIndexO indexO
:8;
1022 typedef struct DisasFormatInfo
{
1023 DisasField op
[NUM_C_FIELD
];
1026 #define R(N, B) { B, 4, 0, FLD_C_r##N, FLD_O_r##N }
1027 #define M(N, B) { B, 4, 0, FLD_C_m##N, FLD_O_m##N }
1028 #define BD(N, BB, BD) { BB, 4, 0, FLD_C_b##N, FLD_O_b##N }, \
1029 { BD, 12, 0, FLD_C_d##N, FLD_O_d##N }
1030 #define BXD(N) { 16, 4, 0, FLD_C_b##N, FLD_O_b##N }, \
1031 { 12, 4, 0, FLD_C_x##N, FLD_O_x##N }, \
1032 { 20, 12, 0, FLD_C_d##N, FLD_O_d##N }
1033 #define BDL(N) { 16, 4, 0, FLD_C_b##N, FLD_O_b##N }, \
1034 { 20, 20, 2, FLD_C_d##N, FLD_O_d##N }
1035 #define BXDL(N) { 16, 4, 0, FLD_C_b##N, FLD_O_b##N }, \
1036 { 12, 4, 0, FLD_C_x##N, FLD_O_x##N }, \
1037 { 20, 20, 2, FLD_C_d##N, FLD_O_d##N }
1038 #define I(N, B, S) { B, S, 1, FLD_C_i##N, FLD_O_i##N }
1039 #define L(N, B, S) { B, S, 0, FLD_C_l##N, FLD_O_l##N }
1041 #define F0(N) { { } },
1042 #define F1(N, X1) { { X1 } },
1043 #define F2(N, X1, X2) { { X1, X2 } },
1044 #define F3(N, X1, X2, X3) { { X1, X2, X3 } },
1045 #define F4(N, X1, X2, X3, X4) { { X1, X2, X3, X4 } },
1046 #define F5(N, X1, X2, X3, X4, X5) { { X1, X2, X3, X4, X5 } },
1048 static const DisasFormatInfo format_info
[] = {
1049 #include "insn-format.def"
1067 /* Generally, we'll extract operands into this structures, operate upon
1068 them, and store them back. See the "in1", "in2", "prep", "wout" sets
1069 of routines below for more details. */
1071 bool g_out
, g_out2
, g_in1
, g_in2
;
1072 TCGv_i64 out
, out2
, in1
, in2
;
1076 /* Instructions can place constraints on their operands, raising specification
1077 exceptions if they are violated. To make this easy to automate, each "in1",
1078 "in2", "prep", "wout" helper will have a SPEC_<name> define that equals one
1079 of the following, or 0. To make this easy to document, we'll put the
1080 SPEC_<name> defines next to <name>. */
1082 #define SPEC_r1_even 1
1083 #define SPEC_r2_even 2
1084 #define SPEC_r3_even 4
1085 #define SPEC_r1_f128 8
1086 #define SPEC_r2_f128 16
1088 /* Return values from translate_one, indicating the state of the TB. */
1090 /* Continue the TB. */
1092 /* We have emitted one or more goto_tb. No fixup required. */
1094 /* We are not using a goto_tb (for whatever reason), but have updated
1095 the PC (for whatever reason), so there's no need to do it again on
1098 /* We are exiting the TB, but have neither emitted a goto_tb, nor
1099 updated the PC for the next instruction to be executed. */
1101 /* We are ending the TB with a noreturn function call, e.g. longjmp.
1102 No following code will be executed. */
1106 typedef enum DisasFacility
{
1107 FAC_Z
, /* zarch (default) */
1108 FAC_CASS
, /* compare and swap and store */
1109 FAC_CASS2
, /* compare and swap and store 2*/
1110 FAC_DFP
, /* decimal floating point */
1111 FAC_DFPR
, /* decimal floating point rounding */
1112 FAC_DO
, /* distinct operands */
1113 FAC_EE
, /* execute extensions */
1114 FAC_EI
, /* extended immediate */
1115 FAC_FPE
, /* floating point extension */
1116 FAC_FPSSH
, /* floating point support sign handling */
1117 FAC_FPRGR
, /* FPR-GR transfer */
1118 FAC_GIE
, /* general instructions extension */
1119 FAC_HFP_MA
, /* HFP multiply-and-add/subtract */
1120 FAC_HW
, /* high-word */
1121 FAC_IEEEE_SIM
, /* IEEE exception sumilation */
1122 FAC_LOC
, /* load/store on condition */
1123 FAC_LD
, /* long displacement */
1124 FAC_PC
, /* population count */
1125 FAC_SCF
, /* store clock fast */
1126 FAC_SFLE
, /* store facility list extended */
1127 FAC_ILA
, /* interlocked access facility 1 */
1133 DisasFacility fac
:8;
1138 void (*help_in1
)(DisasContext
*, DisasFields
*, DisasOps
*);
1139 void (*help_in2
)(DisasContext
*, DisasFields
*, DisasOps
*);
1140 void (*help_prep
)(DisasContext
*, DisasFields
*, DisasOps
*);
1141 void (*help_wout
)(DisasContext
*, DisasFields
*, DisasOps
*);
1142 void (*help_cout
)(DisasContext
*, DisasOps
*);
1143 ExitStatus (*help_op
)(DisasContext
*, DisasOps
*);
1148 /* ====================================================================== */
1149 /* Miscellaneous helpers, used by several operations. */
1151 static void help_l2_shift(DisasContext
*s
, DisasFields
*f
,
1152 DisasOps
*o
, int mask
)
1154 int b2
= get_field(f
, b2
);
1155 int d2
= get_field(f
, d2
);
1158 o
->in2
= tcg_const_i64(d2
& mask
);
1160 o
->in2
= get_address(s
, 0, b2
, d2
);
1161 tcg_gen_andi_i64(o
->in2
, o
->in2
, mask
);
1165 static ExitStatus
help_goto_direct(DisasContext
*s
, uint64_t dest
)
1167 if (dest
== s
->next_pc
) {
1170 if (use_goto_tb(s
, dest
)) {
1173 tcg_gen_movi_i64(psw_addr
, dest
);
1174 tcg_gen_exit_tb((uintptr_t)s
->tb
);
1175 return EXIT_GOTO_TB
;
1177 tcg_gen_movi_i64(psw_addr
, dest
);
1178 return EXIT_PC_UPDATED
;
1182 static ExitStatus
help_branch(DisasContext
*s
, DisasCompare
*c
,
1183 bool is_imm
, int imm
, TCGv_i64 cdest
)
1186 uint64_t dest
= s
->pc
+ 2 * imm
;
1189 /* Take care of the special cases first. */
1190 if (c
->cond
== TCG_COND_NEVER
) {
1195 if (dest
== s
->next_pc
) {
1196 /* Branch to next. */
1200 if (c
->cond
== TCG_COND_ALWAYS
) {
1201 ret
= help_goto_direct(s
, dest
);
1205 if (TCGV_IS_UNUSED_I64(cdest
)) {
1206 /* E.g. bcr %r0 -> no branch. */
1210 if (c
->cond
== TCG_COND_ALWAYS
) {
1211 tcg_gen_mov_i64(psw_addr
, cdest
);
1212 ret
= EXIT_PC_UPDATED
;
1217 if (use_goto_tb(s
, s
->next_pc
)) {
1218 if (is_imm
&& use_goto_tb(s
, dest
)) {
1219 /* Both exits can use goto_tb. */
1222 lab
= gen_new_label();
1224 tcg_gen_brcond_i64(c
->cond
, c
->u
.s64
.a
, c
->u
.s64
.b
, lab
);
1226 tcg_gen_brcond_i32(c
->cond
, c
->u
.s32
.a
, c
->u
.s32
.b
, lab
);
1229 /* Branch not taken. */
1231 tcg_gen_movi_i64(psw_addr
, s
->next_pc
);
1232 tcg_gen_exit_tb((uintptr_t)s
->tb
+ 0);
1237 tcg_gen_movi_i64(psw_addr
, dest
);
1238 tcg_gen_exit_tb((uintptr_t)s
->tb
+ 1);
1242 /* Fallthru can use goto_tb, but taken branch cannot. */
1243 /* Store taken branch destination before the brcond. This
1244 avoids having to allocate a new local temp to hold it.
1245 We'll overwrite this in the not taken case anyway. */
1247 tcg_gen_mov_i64(psw_addr
, cdest
);
1250 lab
= gen_new_label();
1252 tcg_gen_brcond_i64(c
->cond
, c
->u
.s64
.a
, c
->u
.s64
.b
, lab
);
1254 tcg_gen_brcond_i32(c
->cond
, c
->u
.s32
.a
, c
->u
.s32
.b
, lab
);
1257 /* Branch not taken. */
1260 tcg_gen_movi_i64(psw_addr
, s
->next_pc
);
1261 tcg_gen_exit_tb((uintptr_t)s
->tb
+ 0);
1265 tcg_gen_movi_i64(psw_addr
, dest
);
1267 ret
= EXIT_PC_UPDATED
;
1270 /* Fallthru cannot use goto_tb. This by itself is vanishingly rare.
1271 Most commonly we're single-stepping or some other condition that
1272 disables all use of goto_tb. Just update the PC and exit. */
1274 TCGv_i64 next
= tcg_const_i64(s
->next_pc
);
1276 cdest
= tcg_const_i64(dest
);
1280 tcg_gen_movcond_i64(c
->cond
, psw_addr
, c
->u
.s64
.a
, c
->u
.s64
.b
,
1283 TCGv_i32 t0
= tcg_temp_new_i32();
1284 TCGv_i64 t1
= tcg_temp_new_i64();
1285 TCGv_i64 z
= tcg_const_i64(0);
1286 tcg_gen_setcond_i32(c
->cond
, t0
, c
->u
.s32
.a
, c
->u
.s32
.b
);
1287 tcg_gen_extu_i32_i64(t1
, t0
);
1288 tcg_temp_free_i32(t0
);
1289 tcg_gen_movcond_i64(TCG_COND_NE
, psw_addr
, t1
, z
, cdest
, next
);
1290 tcg_temp_free_i64(t1
);
1291 tcg_temp_free_i64(z
);
1295 tcg_temp_free_i64(cdest
);
1297 tcg_temp_free_i64(next
);
1299 ret
= EXIT_PC_UPDATED
;
1307 /* ====================================================================== */
1308 /* The operations. These perform the bulk of the work for any insn,
1309 usually after the operands have been loaded and output initialized. */
1311 static ExitStatus
op_abs(DisasContext
*s
, DisasOps
*o
)
1313 gen_helper_abs_i64(o
->out
, o
->in2
);
1317 static ExitStatus
op_absf32(DisasContext
*s
, DisasOps
*o
)
1319 tcg_gen_andi_i64(o
->out
, o
->in2
, 0x7fffffffull
);
1323 static ExitStatus
op_absf64(DisasContext
*s
, DisasOps
*o
)
1325 tcg_gen_andi_i64(o
->out
, o
->in2
, 0x7fffffffffffffffull
);
1329 static ExitStatus
op_absf128(DisasContext
*s
, DisasOps
*o
)
1331 tcg_gen_andi_i64(o
->out
, o
->in1
, 0x7fffffffffffffffull
);
1332 tcg_gen_mov_i64(o
->out2
, o
->in2
);
1336 static ExitStatus
op_add(DisasContext
*s
, DisasOps
*o
)
1338 tcg_gen_add_i64(o
->out
, o
->in1
, o
->in2
);
1342 static ExitStatus
op_addc(DisasContext
*s
, DisasOps
*o
)
1347 tcg_gen_add_i64(o
->out
, o
->in1
, o
->in2
);
1349 /* The carry flag is the msb of CC, therefore the branch mask that would
1350 create that comparison is 3. Feeding the generated comparison to
1351 setcond produces the carry flag that we desire. */
1352 disas_jcc(s
, &cmp
, 3);
1353 carry
= tcg_temp_new_i64();
1355 tcg_gen_setcond_i64(cmp
.cond
, carry
, cmp
.u
.s64
.a
, cmp
.u
.s64
.b
);
1357 TCGv_i32 t
= tcg_temp_new_i32();
1358 tcg_gen_setcond_i32(cmp
.cond
, t
, cmp
.u
.s32
.a
, cmp
.u
.s32
.b
);
1359 tcg_gen_extu_i32_i64(carry
, t
);
1360 tcg_temp_free_i32(t
);
1364 tcg_gen_add_i64(o
->out
, o
->out
, carry
);
1365 tcg_temp_free_i64(carry
);
1369 static ExitStatus
op_aeb(DisasContext
*s
, DisasOps
*o
)
1371 gen_helper_aeb(o
->out
, cpu_env
, o
->in1
, o
->in2
);
1375 static ExitStatus
op_adb(DisasContext
*s
, DisasOps
*o
)
1377 gen_helper_adb(o
->out
, cpu_env
, o
->in1
, o
->in2
);
1381 static ExitStatus
op_axb(DisasContext
*s
, DisasOps
*o
)
1383 gen_helper_axb(o
->out
, cpu_env
, o
->out
, o
->out2
, o
->in1
, o
->in2
);
1384 return_low128(o
->out2
);
1388 static ExitStatus
op_and(DisasContext
*s
, DisasOps
*o
)
1390 tcg_gen_and_i64(o
->out
, o
->in1
, o
->in2
);
1394 static ExitStatus
op_andi(DisasContext
*s
, DisasOps
*o
)
1396 int shift
= s
->insn
->data
& 0xff;
1397 int size
= s
->insn
->data
>> 8;
1398 uint64_t mask
= ((1ull << size
) - 1) << shift
;
1401 tcg_gen_shli_i64(o
->in2
, o
->in2
, shift
);
1402 tcg_gen_ori_i64(o
->in2
, o
->in2
, ~mask
);
1403 tcg_gen_and_i64(o
->out
, o
->in1
, o
->in2
);
1405 /* Produce the CC from only the bits manipulated. */
1406 tcg_gen_andi_i64(cc_dst
, o
->out
, mask
);
1407 set_cc_nz_u64(s
, cc_dst
);
1411 static ExitStatus
op_bas(DisasContext
*s
, DisasOps
*o
)
1413 tcg_gen_movi_i64(o
->out
, pc_to_link_info(s
, s
->next_pc
));
1414 if (!TCGV_IS_UNUSED_I64(o
->in2
)) {
1415 tcg_gen_mov_i64(psw_addr
, o
->in2
);
1416 return EXIT_PC_UPDATED
;
1422 static ExitStatus
op_basi(DisasContext
*s
, DisasOps
*o
)
1424 tcg_gen_movi_i64(o
->out
, pc_to_link_info(s
, s
->next_pc
));
1425 return help_goto_direct(s
, s
->pc
+ 2 * get_field(s
->fields
, i2
));
1428 static ExitStatus
op_bc(DisasContext
*s
, DisasOps
*o
)
1430 int m1
= get_field(s
->fields
, m1
);
1431 bool is_imm
= have_field(s
->fields
, i2
);
1432 int imm
= is_imm
? get_field(s
->fields
, i2
) : 0;
1435 disas_jcc(s
, &c
, m1
);
1436 return help_branch(s
, &c
, is_imm
, imm
, o
->in2
);
1439 static ExitStatus
op_bct32(DisasContext
*s
, DisasOps
*o
)
1441 int r1
= get_field(s
->fields
, r1
);
1442 bool is_imm
= have_field(s
->fields
, i2
);
1443 int imm
= is_imm
? get_field(s
->fields
, i2
) : 0;
1447 c
.cond
= TCG_COND_NE
;
1452 t
= tcg_temp_new_i64();
1453 tcg_gen_subi_i64(t
, regs
[r1
], 1);
1454 store_reg32_i64(r1
, t
);
1455 c
.u
.s32
.a
= tcg_temp_new_i32();
1456 c
.u
.s32
.b
= tcg_const_i32(0);
1457 tcg_gen_trunc_i64_i32(c
.u
.s32
.a
, t
);
1458 tcg_temp_free_i64(t
);
1460 return help_branch(s
, &c
, is_imm
, imm
, o
->in2
);
1463 static ExitStatus
op_bct64(DisasContext
*s
, DisasOps
*o
)
1465 int r1
= get_field(s
->fields
, r1
);
1466 bool is_imm
= have_field(s
->fields
, i2
);
1467 int imm
= is_imm
? get_field(s
->fields
, i2
) : 0;
1470 c
.cond
= TCG_COND_NE
;
1475 tcg_gen_subi_i64(regs
[r1
], regs
[r1
], 1);
1476 c
.u
.s64
.a
= regs
[r1
];
1477 c
.u
.s64
.b
= tcg_const_i64(0);
1479 return help_branch(s
, &c
, is_imm
, imm
, o
->in2
);
1482 static ExitStatus
op_bx32(DisasContext
*s
, DisasOps
*o
)
1484 int r1
= get_field(s
->fields
, r1
);
1485 int r3
= get_field(s
->fields
, r3
);
1486 bool is_imm
= have_field(s
->fields
, i2
);
1487 int imm
= is_imm
? get_field(s
->fields
, i2
) : 0;
1491 c
.cond
= (s
->insn
->data
? TCG_COND_LE
: TCG_COND_GT
);
1496 t
= tcg_temp_new_i64();
1497 tcg_gen_add_i64(t
, regs
[r1
], regs
[r3
]);
1498 c
.u
.s32
.a
= tcg_temp_new_i32();
1499 c
.u
.s32
.b
= tcg_temp_new_i32();
1500 tcg_gen_trunc_i64_i32(c
.u
.s32
.a
, t
);
1501 tcg_gen_trunc_i64_i32(c
.u
.s32
.b
, regs
[r3
| 1]);
1502 store_reg32_i64(r1
, t
);
1503 tcg_temp_free_i64(t
);
1505 return help_branch(s
, &c
, is_imm
, imm
, o
->in2
);
1508 static ExitStatus
op_bx64(DisasContext
*s
, DisasOps
*o
)
1510 int r1
= get_field(s
->fields
, r1
);
1511 int r3
= get_field(s
->fields
, r3
);
1512 bool is_imm
= have_field(s
->fields
, i2
);
1513 int imm
= is_imm
? get_field(s
->fields
, i2
) : 0;
1516 c
.cond
= (s
->insn
->data
? TCG_COND_LE
: TCG_COND_GT
);
1519 if (r1
== (r3
| 1)) {
1520 c
.u
.s64
.b
= load_reg(r3
| 1);
1523 c
.u
.s64
.b
= regs
[r3
| 1];
1527 tcg_gen_add_i64(regs
[r1
], regs
[r1
], regs
[r3
]);
1528 c
.u
.s64
.a
= regs
[r1
];
1531 return help_branch(s
, &c
, is_imm
, imm
, o
->in2
);
1534 static ExitStatus
op_cj(DisasContext
*s
, DisasOps
*o
)
1536 int imm
, m3
= get_field(s
->fields
, m3
);
1540 c
.cond
= ltgt_cond
[m3
];
1541 if (s
->insn
->data
) {
1542 c
.cond
= tcg_unsigned_cond(c
.cond
);
1544 c
.is_64
= c
.g1
= c
.g2
= true;
1548 is_imm
= have_field(s
->fields
, i4
);
1550 imm
= get_field(s
->fields
, i4
);
1553 o
->out
= get_address(s
, 0, get_field(s
->fields
, b4
),
1554 get_field(s
->fields
, d4
));
1557 return help_branch(s
, &c
, is_imm
, imm
, o
->out
);
1560 static ExitStatus
op_ceb(DisasContext
*s
, DisasOps
*o
)
1562 gen_helper_ceb(cc_op
, cpu_env
, o
->in1
, o
->in2
);
1567 static ExitStatus
op_cdb(DisasContext
*s
, DisasOps
*o
)
1569 gen_helper_cdb(cc_op
, cpu_env
, o
->in1
, o
->in2
);
1574 static ExitStatus
op_cxb(DisasContext
*s
, DisasOps
*o
)
1576 gen_helper_cxb(cc_op
, cpu_env
, o
->out
, o
->out2
, o
->in1
, o
->in2
);
1581 static ExitStatus
op_cfeb(DisasContext
*s
, DisasOps
*o
)
1583 TCGv_i32 m3
= tcg_const_i32(get_field(s
->fields
, m3
));
1584 gen_helper_cfeb(o
->out
, cpu_env
, o
->in2
, m3
);
1585 tcg_temp_free_i32(m3
);
1586 gen_set_cc_nz_f32(s
, o
->in2
);
1590 static ExitStatus
op_cfdb(DisasContext
*s
, DisasOps
*o
)
1592 TCGv_i32 m3
= tcg_const_i32(get_field(s
->fields
, m3
));
1593 gen_helper_cfdb(o
->out
, cpu_env
, o
->in2
, m3
);
1594 tcg_temp_free_i32(m3
);
1595 gen_set_cc_nz_f64(s
, o
->in2
);
1599 static ExitStatus
op_cfxb(DisasContext
*s
, DisasOps
*o
)
1601 TCGv_i32 m3
= tcg_const_i32(get_field(s
->fields
, m3
));
1602 gen_helper_cfxb(o
->out
, cpu_env
, o
->in1
, o
->in2
, m3
);
1603 tcg_temp_free_i32(m3
);
1604 gen_set_cc_nz_f128(s
, o
->in1
, o
->in2
);
1608 static ExitStatus
op_cgeb(DisasContext
*s
, DisasOps
*o
)
1610 TCGv_i32 m3
= tcg_const_i32(get_field(s
->fields
, m3
));
1611 gen_helper_cgeb(o
->out
, cpu_env
, o
->in2
, m3
);
1612 tcg_temp_free_i32(m3
);
1613 gen_set_cc_nz_f32(s
, o
->in2
);
1617 static ExitStatus
op_cgdb(DisasContext
*s
, DisasOps
*o
)
1619 TCGv_i32 m3
= tcg_const_i32(get_field(s
->fields
, m3
));
1620 gen_helper_cgdb(o
->out
, cpu_env
, o
->in2
, m3
);
1621 tcg_temp_free_i32(m3
);
1622 gen_set_cc_nz_f64(s
, o
->in2
);
1626 static ExitStatus
op_cgxb(DisasContext
*s
, DisasOps
*o
)
1628 TCGv_i32 m3
= tcg_const_i32(get_field(s
->fields
, m3
));
1629 gen_helper_cgxb(o
->out
, cpu_env
, o
->in1
, o
->in2
, m3
);
1630 tcg_temp_free_i32(m3
);
1631 gen_set_cc_nz_f128(s
, o
->in1
, o
->in2
);
1635 static ExitStatus
op_clfeb(DisasContext
*s
, DisasOps
*o
)
1637 TCGv_i32 m3
= tcg_const_i32(get_field(s
->fields
, m3
));
1638 gen_helper_clfeb(o
->out
, cpu_env
, o
->in2
, m3
);
1639 tcg_temp_free_i32(m3
);
1640 gen_set_cc_nz_f32(s
, o
->in2
);
1644 static ExitStatus
op_clfdb(DisasContext
*s
, DisasOps
*o
)
1646 TCGv_i32 m3
= tcg_const_i32(get_field(s
->fields
, m3
));
1647 gen_helper_clfdb(o
->out
, cpu_env
, o
->in2
, m3
);
1648 tcg_temp_free_i32(m3
);
1649 gen_set_cc_nz_f64(s
, o
->in2
);
1653 static ExitStatus
op_clfxb(DisasContext
*s
, DisasOps
*o
)
1655 TCGv_i32 m3
= tcg_const_i32(get_field(s
->fields
, m3
));
1656 gen_helper_clfxb(o
->out
, cpu_env
, o
->in1
, o
->in2
, m3
);
1657 tcg_temp_free_i32(m3
);
1658 gen_set_cc_nz_f128(s
, o
->in1
, o
->in2
);
1662 static ExitStatus
op_clgeb(DisasContext
*s
, DisasOps
*o
)
1664 TCGv_i32 m3
= tcg_const_i32(get_field(s
->fields
, m3
));
1665 gen_helper_clgeb(o
->out
, cpu_env
, o
->in2
, m3
);
1666 tcg_temp_free_i32(m3
);
1667 gen_set_cc_nz_f32(s
, o
->in2
);
1671 static ExitStatus
op_clgdb(DisasContext
*s
, DisasOps
*o
)
1673 TCGv_i32 m3
= tcg_const_i32(get_field(s
->fields
, m3
));
1674 gen_helper_clgdb(o
->out
, cpu_env
, o
->in2
, m3
);
1675 tcg_temp_free_i32(m3
);
1676 gen_set_cc_nz_f64(s
, o
->in2
);
1680 static ExitStatus
op_clgxb(DisasContext
*s
, DisasOps
*o
)
1682 TCGv_i32 m3
= tcg_const_i32(get_field(s
->fields
, m3
));
1683 gen_helper_clgxb(o
->out
, cpu_env
, o
->in1
, o
->in2
, m3
);
1684 tcg_temp_free_i32(m3
);
1685 gen_set_cc_nz_f128(s
, o
->in1
, o
->in2
);
1689 static ExitStatus
op_cegb(DisasContext
*s
, DisasOps
*o
)
1691 TCGv_i32 m3
= tcg_const_i32(get_field(s
->fields
, m3
));
1692 gen_helper_cegb(o
->out
, cpu_env
, o
->in2
, m3
);
1693 tcg_temp_free_i32(m3
);
1697 static ExitStatus
op_cdgb(DisasContext
*s
, DisasOps
*o
)
1699 TCGv_i32 m3
= tcg_const_i32(get_field(s
->fields
, m3
));
1700 gen_helper_cdgb(o
->out
, cpu_env
, o
->in2
, m3
);
1701 tcg_temp_free_i32(m3
);
1705 static ExitStatus
op_cxgb(DisasContext
*s
, DisasOps
*o
)
1707 TCGv_i32 m3
= tcg_const_i32(get_field(s
->fields
, m3
));
1708 gen_helper_cxgb(o
->out
, cpu_env
, o
->in2
, m3
);
1709 tcg_temp_free_i32(m3
);
1710 return_low128(o
->out2
);
1714 static ExitStatus
op_celgb(DisasContext
*s
, DisasOps
*o
)
1716 TCGv_i32 m3
= tcg_const_i32(get_field(s
->fields
, m3
));
1717 gen_helper_celgb(o
->out
, cpu_env
, o
->in2
, m3
);
1718 tcg_temp_free_i32(m3
);
1722 static ExitStatus
op_cdlgb(DisasContext
*s
, DisasOps
*o
)
1724 TCGv_i32 m3
= tcg_const_i32(get_field(s
->fields
, m3
));
1725 gen_helper_cdlgb(o
->out
, cpu_env
, o
->in2
, m3
);
1726 tcg_temp_free_i32(m3
);
1730 static ExitStatus
op_cxlgb(DisasContext
*s
, DisasOps
*o
)
1732 TCGv_i32 m3
= tcg_const_i32(get_field(s
->fields
, m3
));
1733 gen_helper_cxlgb(o
->out
, cpu_env
, o
->in2
, m3
);
1734 tcg_temp_free_i32(m3
);
1735 return_low128(o
->out2
);
1739 static ExitStatus
op_cksm(DisasContext
*s
, DisasOps
*o
)
1741 int r2
= get_field(s
->fields
, r2
);
1742 TCGv_i64 len
= tcg_temp_new_i64();
1744 potential_page_fault(s
);
1745 gen_helper_cksm(len
, cpu_env
, o
->in1
, o
->in2
, regs
[r2
+ 1]);
1747 return_low128(o
->out
);
1749 tcg_gen_add_i64(regs
[r2
], regs
[r2
], len
);
1750 tcg_gen_sub_i64(regs
[r2
+ 1], regs
[r2
+ 1], len
);
1751 tcg_temp_free_i64(len
);
1756 static ExitStatus
op_clc(DisasContext
*s
, DisasOps
*o
)
1758 int l
= get_field(s
->fields
, l1
);
1763 tcg_gen_qemu_ld8u(cc_src
, o
->addr1
, get_mem_index(s
));
1764 tcg_gen_qemu_ld8u(cc_dst
, o
->in2
, get_mem_index(s
));
1767 tcg_gen_qemu_ld16u(cc_src
, o
->addr1
, get_mem_index(s
));
1768 tcg_gen_qemu_ld16u(cc_dst
, o
->in2
, get_mem_index(s
));
1771 tcg_gen_qemu_ld32u(cc_src
, o
->addr1
, get_mem_index(s
));
1772 tcg_gen_qemu_ld32u(cc_dst
, o
->in2
, get_mem_index(s
));
1775 tcg_gen_qemu_ld64(cc_src
, o
->addr1
, get_mem_index(s
));
1776 tcg_gen_qemu_ld64(cc_dst
, o
->in2
, get_mem_index(s
));
1779 potential_page_fault(s
);
1780 vl
= tcg_const_i32(l
);
1781 gen_helper_clc(cc_op
, cpu_env
, vl
, o
->addr1
, o
->in2
);
1782 tcg_temp_free_i32(vl
);
1786 gen_op_update2_cc_i64(s
, CC_OP_LTUGTU_64
, cc_src
, cc_dst
);
1790 static ExitStatus
op_clcle(DisasContext
*s
, DisasOps
*o
)
1792 TCGv_i32 r1
= tcg_const_i32(get_field(s
->fields
, r1
));
1793 TCGv_i32 r3
= tcg_const_i32(get_field(s
->fields
, r3
));
1794 potential_page_fault(s
);
1795 gen_helper_clcle(cc_op
, cpu_env
, r1
, o
->in2
, r3
);
1796 tcg_temp_free_i32(r1
);
1797 tcg_temp_free_i32(r3
);
1802 static ExitStatus
op_clm(DisasContext
*s
, DisasOps
*o
)
1804 TCGv_i32 m3
= tcg_const_i32(get_field(s
->fields
, m3
));
1805 TCGv_i32 t1
= tcg_temp_new_i32();
1806 tcg_gen_trunc_i64_i32(t1
, o
->in1
);
1807 potential_page_fault(s
);
1808 gen_helper_clm(cc_op
, cpu_env
, t1
, m3
, o
->in2
);
1810 tcg_temp_free_i32(t1
);
1811 tcg_temp_free_i32(m3
);
1815 static ExitStatus
op_clst(DisasContext
*s
, DisasOps
*o
)
1817 potential_page_fault(s
);
1818 gen_helper_clst(o
->in1
, cpu_env
, regs
[0], o
->in1
, o
->in2
);
1820 return_low128(o
->in2
);
1824 static ExitStatus
op_cps(DisasContext
*s
, DisasOps
*o
)
1826 TCGv_i64 t
= tcg_temp_new_i64();
1827 tcg_gen_andi_i64(t
, o
->in1
, 0x8000000000000000ull
);
1828 tcg_gen_andi_i64(o
->out
, o
->in2
, 0x7fffffffffffffffull
);
1829 tcg_gen_or_i64(o
->out
, o
->out
, t
);
1830 tcg_temp_free_i64(t
);
1834 static ExitStatus
op_cs(DisasContext
*s
, DisasOps
*o
)
1836 /* FIXME: needs an atomic solution for CONFIG_USER_ONLY. */
1837 int d2
= get_field(s
->fields
, d2
);
1838 int b2
= get_field(s
->fields
, b2
);
1839 int is_64
= s
->insn
->data
;
1840 TCGv_i64 addr
, mem
, cc
, z
;
1842 /* Note that in1 = R3 (new value) and
1843 in2 = (zero-extended) R1 (expected value). */
1845 /* Load the memory into the (temporary) output. While the PoO only talks
1846 about moving the memory to R1 on inequality, if we include equality it
1847 means that R1 is equal to the memory in all conditions. */
1848 addr
= get_address(s
, 0, b2
, d2
);
1850 tcg_gen_qemu_ld64(o
->out
, addr
, get_mem_index(s
));
1852 tcg_gen_qemu_ld32u(o
->out
, addr
, get_mem_index(s
));
1855 /* Are the memory and expected values (un)equal? Note that this setcond
1856 produces the output CC value, thus the NE sense of the test. */
1857 cc
= tcg_temp_new_i64();
1858 tcg_gen_setcond_i64(TCG_COND_NE
, cc
, o
->in2
, o
->out
);
1860 /* If the memory and expected values are equal (CC==0), copy R3 to MEM.
1861 Recall that we are allowed to unconditionally issue the store (and
1862 thus any possible write trap), so (re-)store the original contents
1863 of MEM in case of inequality. */
1864 z
= tcg_const_i64(0);
1865 mem
= tcg_temp_new_i64();
1866 tcg_gen_movcond_i64(TCG_COND_EQ
, mem
, cc
, z
, o
->in1
, o
->out
);
1868 tcg_gen_qemu_st64(mem
, addr
, get_mem_index(s
));
1870 tcg_gen_qemu_st32(mem
, addr
, get_mem_index(s
));
1872 tcg_temp_free_i64(z
);
1873 tcg_temp_free_i64(mem
);
1874 tcg_temp_free_i64(addr
);
1876 /* Store CC back to cc_op. Wait until after the store so that any
1877 exception gets the old cc_op value. */
1878 tcg_gen_trunc_i64_i32(cc_op
, cc
);
1879 tcg_temp_free_i64(cc
);
1884 static ExitStatus
op_cdsg(DisasContext
*s
, DisasOps
*o
)
1886 /* FIXME: needs an atomic solution for CONFIG_USER_ONLY. */
1887 int r1
= get_field(s
->fields
, r1
);
1888 int r3
= get_field(s
->fields
, r3
);
1889 int d2
= get_field(s
->fields
, d2
);
1890 int b2
= get_field(s
->fields
, b2
);
1891 TCGv_i64 addrh
, addrl
, memh
, meml
, outh
, outl
, cc
, z
;
1893 /* Note that R1:R1+1 = expected value and R3:R3+1 = new value. */
1895 addrh
= get_address(s
, 0, b2
, d2
);
1896 addrl
= get_address(s
, 0, b2
, d2
+ 8);
1897 outh
= tcg_temp_new_i64();
1898 outl
= tcg_temp_new_i64();
1900 tcg_gen_qemu_ld64(outh
, addrh
, get_mem_index(s
));
1901 tcg_gen_qemu_ld64(outl
, addrl
, get_mem_index(s
));
1903 /* Fold the double-word compare with arithmetic. */
1904 cc
= tcg_temp_new_i64();
1905 z
= tcg_temp_new_i64();
1906 tcg_gen_xor_i64(cc
, outh
, regs
[r1
]);
1907 tcg_gen_xor_i64(z
, outl
, regs
[r1
+ 1]);
1908 tcg_gen_or_i64(cc
, cc
, z
);
1909 tcg_gen_movi_i64(z
, 0);
1910 tcg_gen_setcond_i64(TCG_COND_NE
, cc
, cc
, z
);
1912 memh
= tcg_temp_new_i64();
1913 meml
= tcg_temp_new_i64();
1914 tcg_gen_movcond_i64(TCG_COND_EQ
, memh
, cc
, z
, regs
[r3
], outh
);
1915 tcg_gen_movcond_i64(TCG_COND_EQ
, meml
, cc
, z
, regs
[r3
+ 1], outl
);
1916 tcg_temp_free_i64(z
);
1918 tcg_gen_qemu_st64(memh
, addrh
, get_mem_index(s
));
1919 tcg_gen_qemu_st64(meml
, addrl
, get_mem_index(s
));
1920 tcg_temp_free_i64(memh
);
1921 tcg_temp_free_i64(meml
);
1922 tcg_temp_free_i64(addrh
);
1923 tcg_temp_free_i64(addrl
);
1925 /* Save back state now that we've passed all exceptions. */
1926 tcg_gen_mov_i64(regs
[r1
], outh
);
1927 tcg_gen_mov_i64(regs
[r1
+ 1], outl
);
1928 tcg_gen_trunc_i64_i32(cc_op
, cc
);
1929 tcg_temp_free_i64(outh
);
1930 tcg_temp_free_i64(outl
);
1931 tcg_temp_free_i64(cc
);
1936 #ifndef CONFIG_USER_ONLY
1937 static ExitStatus
op_csp(DisasContext
*s
, DisasOps
*o
)
1939 TCGv_i32 r1
= tcg_const_i32(get_field(s
->fields
, r1
));
1940 check_privileged(s
);
1941 gen_helper_csp(cc_op
, cpu_env
, r1
, o
->in2
);
1942 tcg_temp_free_i32(r1
);
1948 static ExitStatus
op_cvd(DisasContext
*s
, DisasOps
*o
)
1950 TCGv_i64 t1
= tcg_temp_new_i64();
1951 TCGv_i32 t2
= tcg_temp_new_i32();
1952 tcg_gen_trunc_i64_i32(t2
, o
->in1
);
1953 gen_helper_cvd(t1
, t2
);
1954 tcg_temp_free_i32(t2
);
1955 tcg_gen_qemu_st64(t1
, o
->in2
, get_mem_index(s
));
1956 tcg_temp_free_i64(t1
);
1960 static ExitStatus
op_ct(DisasContext
*s
, DisasOps
*o
)
1962 int m3
= get_field(s
->fields
, m3
);
1963 TCGLabel
*lab
= gen_new_label();
1967 c
= tcg_invert_cond(ltgt_cond
[m3
]);
1968 if (s
->insn
->data
) {
1969 c
= tcg_unsigned_cond(c
);
1971 tcg_gen_brcond_i64(c
, o
->in1
, o
->in2
, lab
);
1973 /* Set DXC to 0xff. */
1974 t
= tcg_temp_new_i32();
1975 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUS390XState
, fpc
));
1976 tcg_gen_ori_i32(t
, t
, 0xff00);
1977 tcg_gen_st_i32(t
, cpu_env
, offsetof(CPUS390XState
, fpc
));
1978 tcg_temp_free_i32(t
);
1981 gen_program_exception(s
, PGM_DATA
);
1987 #ifndef CONFIG_USER_ONLY
1988 static ExitStatus
op_diag(DisasContext
*s
, DisasOps
*o
)
1992 check_privileged(s
);
1993 potential_page_fault(s
);
1995 /* We pretend the format is RX_a so that D2 is the field we want. */
1996 tmp
= tcg_const_i32(get_field(s
->fields
, d2
) & 0xfff);
1997 gen_helper_diag(regs
[2], cpu_env
, tmp
, regs
[2], regs
[1]);
1998 tcg_temp_free_i32(tmp
);
2003 static ExitStatus
op_divs32(DisasContext
*s
, DisasOps
*o
)
2005 gen_helper_divs32(o
->out2
, cpu_env
, o
->in1
, o
->in2
);
2006 return_low128(o
->out
);
2010 static ExitStatus
op_divu32(DisasContext
*s
, DisasOps
*o
)
2012 gen_helper_divu32(o
->out2
, cpu_env
, o
->in1
, o
->in2
);
2013 return_low128(o
->out
);
2017 static ExitStatus
op_divs64(DisasContext
*s
, DisasOps
*o
)
2019 gen_helper_divs64(o
->out2
, cpu_env
, o
->in1
, o
->in2
);
2020 return_low128(o
->out
);
2024 static ExitStatus
op_divu64(DisasContext
*s
, DisasOps
*o
)
2026 gen_helper_divu64(o
->out2
, cpu_env
, o
->out
, o
->out2
, o
->in2
);
2027 return_low128(o
->out
);
2031 static ExitStatus
op_deb(DisasContext
*s
, DisasOps
*o
)
2033 gen_helper_deb(o
->out
, cpu_env
, o
->in1
, o
->in2
);
2037 static ExitStatus
op_ddb(DisasContext
*s
, DisasOps
*o
)
2039 gen_helper_ddb(o
->out
, cpu_env
, o
->in1
, o
->in2
);
2043 static ExitStatus
op_dxb(DisasContext
*s
, DisasOps
*o
)
2045 gen_helper_dxb(o
->out
, cpu_env
, o
->out
, o
->out2
, o
->in1
, o
->in2
);
2046 return_low128(o
->out2
);
2050 static ExitStatus
op_ear(DisasContext
*s
, DisasOps
*o
)
2052 int r2
= get_field(s
->fields
, r2
);
2053 tcg_gen_ld32u_i64(o
->out
, cpu_env
, offsetof(CPUS390XState
, aregs
[r2
]));
2057 static ExitStatus
op_ecag(DisasContext
*s
, DisasOps
*o
)
2059 /* No cache information provided. */
2060 tcg_gen_movi_i64(o
->out
, -1);
2064 static ExitStatus
op_efpc(DisasContext
*s
, DisasOps
*o
)
2066 tcg_gen_ld32u_i64(o
->out
, cpu_env
, offsetof(CPUS390XState
, fpc
));
2070 static ExitStatus
op_epsw(DisasContext
*s
, DisasOps
*o
)
2072 int r1
= get_field(s
->fields
, r1
);
2073 int r2
= get_field(s
->fields
, r2
);
2074 TCGv_i64 t
= tcg_temp_new_i64();
2076 /* Note the "subsequently" in the PoO, which implies a defined result
2077 if r1 == r2. Thus we cannot defer these writes to an output hook. */
2078 tcg_gen_shri_i64(t
, psw_mask
, 32);
2079 store_reg32_i64(r1
, t
);
2081 store_reg32_i64(r2
, psw_mask
);
2084 tcg_temp_free_i64(t
);
2088 static ExitStatus
op_ex(DisasContext
*s
, DisasOps
*o
)
2090 /* ??? Perhaps a better way to implement EXECUTE is to set a bit in
2091 tb->flags, (ab)use the tb->cs_base field as the address of
2092 the template in memory, and grab 8 bits of tb->flags/cflags for
2093 the contents of the register. We would then recognize all this
2094 in gen_intermediate_code_internal, generating code for exactly
2095 one instruction. This new TB then gets executed normally.
2097 On the other hand, this seems to be mostly used for modifying
2098 MVC inside of memcpy, which needs a helper call anyway. So
2099 perhaps this doesn't bear thinking about any further. */
2106 tmp
= tcg_const_i64(s
->next_pc
);
2107 gen_helper_ex(cc_op
, cpu_env
, cc_op
, o
->in1
, o
->in2
, tmp
);
2108 tcg_temp_free_i64(tmp
);
2114 static ExitStatus
op_flogr(DisasContext
*s
, DisasOps
*o
)
2116 /* We'll use the original input for cc computation, since we get to
2117 compare that against 0, which ought to be better than comparing
2118 the real output against 64. It also lets cc_dst be a convenient
2119 temporary during our computation. */
2120 gen_op_update1_cc_i64(s
, CC_OP_FLOGR
, o
->in2
);
2122 /* R1 = IN ? CLZ(IN) : 64. */
2123 gen_helper_clz(o
->out
, o
->in2
);
2125 /* R1+1 = IN & ~(found bit). Note that we may attempt to shift this
2126 value by 64, which is undefined. But since the shift is 64 iff the
2127 input is zero, we still get the correct result after and'ing. */
2128 tcg_gen_movi_i64(o
->out2
, 0x8000000000000000ull
);
2129 tcg_gen_shr_i64(o
->out2
, o
->out2
, o
->out
);
2130 tcg_gen_andc_i64(o
->out2
, cc_dst
, o
->out2
);
2134 static ExitStatus
op_icm(DisasContext
*s
, DisasOps
*o
)
2136 int m3
= get_field(s
->fields
, m3
);
2137 int pos
, len
, base
= s
->insn
->data
;
2138 TCGv_i64 tmp
= tcg_temp_new_i64();
2143 /* Effectively a 32-bit load. */
2144 tcg_gen_qemu_ld32u(tmp
, o
->in2
, get_mem_index(s
));
2151 /* Effectively a 16-bit load. */
2152 tcg_gen_qemu_ld16u(tmp
, o
->in2
, get_mem_index(s
));
2160 /* Effectively an 8-bit load. */
2161 tcg_gen_qemu_ld8u(tmp
, o
->in2
, get_mem_index(s
));
2166 pos
= base
+ ctz32(m3
) * 8;
2167 tcg_gen_deposit_i64(o
->out
, o
->out
, tmp
, pos
, len
);
2168 ccm
= ((1ull << len
) - 1) << pos
;
2172 /* This is going to be a sequence of loads and inserts. */
2173 pos
= base
+ 32 - 8;
2177 tcg_gen_qemu_ld8u(tmp
, o
->in2
, get_mem_index(s
));
2178 tcg_gen_addi_i64(o
->in2
, o
->in2
, 1);
2179 tcg_gen_deposit_i64(o
->out
, o
->out
, tmp
, pos
, 8);
2182 m3
= (m3
<< 1) & 0xf;
2188 tcg_gen_movi_i64(tmp
, ccm
);
2189 gen_op_update2_cc_i64(s
, CC_OP_ICM
, tmp
, o
->out
);
2190 tcg_temp_free_i64(tmp
);
2194 static ExitStatus
op_insi(DisasContext
*s
, DisasOps
*o
)
2196 int shift
= s
->insn
->data
& 0xff;
2197 int size
= s
->insn
->data
>> 8;
2198 tcg_gen_deposit_i64(o
->out
, o
->in1
, o
->in2
, shift
, size
);
2202 static ExitStatus
op_ipm(DisasContext
*s
, DisasOps
*o
)
2207 tcg_gen_andi_i64(o
->out
, o
->out
, ~0xff000000ull
);
2209 t1
= tcg_temp_new_i64();
2210 tcg_gen_shli_i64(t1
, psw_mask
, 20);
2211 tcg_gen_shri_i64(t1
, t1
, 36);
2212 tcg_gen_or_i64(o
->out
, o
->out
, t1
);
2214 tcg_gen_extu_i32_i64(t1
, cc_op
);
2215 tcg_gen_shli_i64(t1
, t1
, 28);
2216 tcg_gen_or_i64(o
->out
, o
->out
, t1
);
2217 tcg_temp_free_i64(t1
);
2221 #ifndef CONFIG_USER_ONLY
2222 static ExitStatus
op_ipte(DisasContext
*s
, DisasOps
*o
)
2224 check_privileged(s
);
2225 gen_helper_ipte(cpu_env
, o
->in1
, o
->in2
);
2229 static ExitStatus
op_iske(DisasContext
*s
, DisasOps
*o
)
2231 check_privileged(s
);
2232 gen_helper_iske(o
->out
, cpu_env
, o
->in2
);
2237 static ExitStatus
op_ldeb(DisasContext
*s
, DisasOps
*o
)
2239 gen_helper_ldeb(o
->out
, cpu_env
, o
->in2
);
2243 static ExitStatus
op_ledb(DisasContext
*s
, DisasOps
*o
)
2245 gen_helper_ledb(o
->out
, cpu_env
, o
->in2
);
2249 static ExitStatus
op_ldxb(DisasContext
*s
, DisasOps
*o
)
2251 gen_helper_ldxb(o
->out
, cpu_env
, o
->in1
, o
->in2
);
2255 static ExitStatus
op_lexb(DisasContext
*s
, DisasOps
*o
)
2257 gen_helper_lexb(o
->out
, cpu_env
, o
->in1
, o
->in2
);
2261 static ExitStatus
op_lxdb(DisasContext
*s
, DisasOps
*o
)
2263 gen_helper_lxdb(o
->out
, cpu_env
, o
->in2
);
2264 return_low128(o
->out2
);
2268 static ExitStatus
op_lxeb(DisasContext
*s
, DisasOps
*o
)
2270 gen_helper_lxeb(o
->out
, cpu_env
, o
->in2
);
2271 return_low128(o
->out2
);
2275 static ExitStatus
op_llgt(DisasContext
*s
, DisasOps
*o
)
2277 tcg_gen_andi_i64(o
->out
, o
->in2
, 0x7fffffff);
2281 static ExitStatus
op_ld8s(DisasContext
*s
, DisasOps
*o
)
2283 tcg_gen_qemu_ld8s(o
->out
, o
->in2
, get_mem_index(s
));
2287 static ExitStatus
op_ld8u(DisasContext
*s
, DisasOps
*o
)
2289 tcg_gen_qemu_ld8u(o
->out
, o
->in2
, get_mem_index(s
));
2293 static ExitStatus
op_ld16s(DisasContext
*s
, DisasOps
*o
)
2295 tcg_gen_qemu_ld16s(o
->out
, o
->in2
, get_mem_index(s
));
2299 static ExitStatus
op_ld16u(DisasContext
*s
, DisasOps
*o
)
2301 tcg_gen_qemu_ld16u(o
->out
, o
->in2
, get_mem_index(s
));
2305 static ExitStatus
op_ld32s(DisasContext
*s
, DisasOps
*o
)
2307 tcg_gen_qemu_ld32s(o
->out
, o
->in2
, get_mem_index(s
));
2311 static ExitStatus
op_ld32u(DisasContext
*s
, DisasOps
*o
)
2313 tcg_gen_qemu_ld32u(o
->out
, o
->in2
, get_mem_index(s
));
2317 static ExitStatus
op_ld64(DisasContext
*s
, DisasOps
*o
)
2319 tcg_gen_qemu_ld64(o
->out
, o
->in2
, get_mem_index(s
));
2323 static ExitStatus
op_loc(DisasContext
*s
, DisasOps
*o
)
2327 disas_jcc(s
, &c
, get_field(s
->fields
, m3
));
2330 tcg_gen_movcond_i64(c
.cond
, o
->out
, c
.u
.s64
.a
, c
.u
.s64
.b
,
2334 TCGv_i32 t32
= tcg_temp_new_i32();
2337 tcg_gen_setcond_i32(c
.cond
, t32
, c
.u
.s32
.a
, c
.u
.s32
.b
);
2340 t
= tcg_temp_new_i64();
2341 tcg_gen_extu_i32_i64(t
, t32
);
2342 tcg_temp_free_i32(t32
);
2344 z
= tcg_const_i64(0);
2345 tcg_gen_movcond_i64(TCG_COND_NE
, o
->out
, t
, z
, o
->in2
, o
->in1
);
2346 tcg_temp_free_i64(t
);
2347 tcg_temp_free_i64(z
);
2353 #ifndef CONFIG_USER_ONLY
2354 static ExitStatus
op_lctl(DisasContext
*s
, DisasOps
*o
)
2356 TCGv_i32 r1
= tcg_const_i32(get_field(s
->fields
, r1
));
2357 TCGv_i32 r3
= tcg_const_i32(get_field(s
->fields
, r3
));
2358 check_privileged(s
);
2359 potential_page_fault(s
);
2360 gen_helper_lctl(cpu_env
, r1
, o
->in2
, r3
);
2361 tcg_temp_free_i32(r1
);
2362 tcg_temp_free_i32(r3
);
2366 static ExitStatus
op_lctlg(DisasContext
*s
, DisasOps
*o
)
2368 TCGv_i32 r1
= tcg_const_i32(get_field(s
->fields
, r1
));
2369 TCGv_i32 r3
= tcg_const_i32(get_field(s
->fields
, r3
));
2370 check_privileged(s
);
2371 potential_page_fault(s
);
2372 gen_helper_lctlg(cpu_env
, r1
, o
->in2
, r3
);
2373 tcg_temp_free_i32(r1
);
2374 tcg_temp_free_i32(r3
);
2377 static ExitStatus
op_lra(DisasContext
*s
, DisasOps
*o
)
2379 check_privileged(s
);
2380 potential_page_fault(s
);
2381 gen_helper_lra(o
->out
, cpu_env
, o
->in2
);
2386 static ExitStatus
op_lpsw(DisasContext
*s
, DisasOps
*o
)
2390 check_privileged(s
);
2392 t1
= tcg_temp_new_i64();
2393 t2
= tcg_temp_new_i64();
2394 tcg_gen_qemu_ld32u(t1
, o
->in2
, get_mem_index(s
));
2395 tcg_gen_addi_i64(o
->in2
, o
->in2
, 4);
2396 tcg_gen_qemu_ld32u(t2
, o
->in2
, get_mem_index(s
));
2397 /* Convert the 32-bit PSW_MASK into the 64-bit PSW_MASK. */
2398 tcg_gen_shli_i64(t1
, t1
, 32);
2399 gen_helper_load_psw(cpu_env
, t1
, t2
);
2400 tcg_temp_free_i64(t1
);
2401 tcg_temp_free_i64(t2
);
2402 return EXIT_NORETURN
;
2405 static ExitStatus
op_lpswe(DisasContext
*s
, DisasOps
*o
)
2409 check_privileged(s
);
2411 t1
= tcg_temp_new_i64();
2412 t2
= tcg_temp_new_i64();
2413 tcg_gen_qemu_ld64(t1
, o
->in2
, get_mem_index(s
));
2414 tcg_gen_addi_i64(o
->in2
, o
->in2
, 8);
2415 tcg_gen_qemu_ld64(t2
, o
->in2
, get_mem_index(s
));
2416 gen_helper_load_psw(cpu_env
, t1
, t2
);
2417 tcg_temp_free_i64(t1
);
2418 tcg_temp_free_i64(t2
);
2419 return EXIT_NORETURN
;
2423 static ExitStatus
op_lam(DisasContext
*s
, DisasOps
*o
)
2425 TCGv_i32 r1
= tcg_const_i32(get_field(s
->fields
, r1
));
2426 TCGv_i32 r3
= tcg_const_i32(get_field(s
->fields
, r3
));
2427 potential_page_fault(s
);
2428 gen_helper_lam(cpu_env
, r1
, o
->in2
, r3
);
2429 tcg_temp_free_i32(r1
);
2430 tcg_temp_free_i32(r3
);
2434 static ExitStatus
op_lm32(DisasContext
*s
, DisasOps
*o
)
2436 int r1
= get_field(s
->fields
, r1
);
2437 int r3
= get_field(s
->fields
, r3
);
2438 TCGv_i64 t
= tcg_temp_new_i64();
2439 TCGv_i64 t4
= tcg_const_i64(4);
2442 tcg_gen_qemu_ld32u(t
, o
->in2
, get_mem_index(s
));
2443 store_reg32_i64(r1
, t
);
2447 tcg_gen_add_i64(o
->in2
, o
->in2
, t4
);
2451 tcg_temp_free_i64(t
);
2452 tcg_temp_free_i64(t4
);
2456 static ExitStatus
op_lmh(DisasContext
*s
, DisasOps
*o
)
2458 int r1
= get_field(s
->fields
, r1
);
2459 int r3
= get_field(s
->fields
, r3
);
2460 TCGv_i64 t
= tcg_temp_new_i64();
2461 TCGv_i64 t4
= tcg_const_i64(4);
2464 tcg_gen_qemu_ld32u(t
, o
->in2
, get_mem_index(s
));
2465 store_reg32h_i64(r1
, t
);
2469 tcg_gen_add_i64(o
->in2
, o
->in2
, t4
);
2473 tcg_temp_free_i64(t
);
2474 tcg_temp_free_i64(t4
);
2478 static ExitStatus
op_lm64(DisasContext
*s
, DisasOps
*o
)
2480 int r1
= get_field(s
->fields
, r1
);
2481 int r3
= get_field(s
->fields
, r3
);
2482 TCGv_i64 t8
= tcg_const_i64(8);
2485 tcg_gen_qemu_ld64(regs
[r1
], o
->in2
, get_mem_index(s
));
2489 tcg_gen_add_i64(o
->in2
, o
->in2
, t8
);
2493 tcg_temp_free_i64(t8
);
2497 #ifndef CONFIG_USER_ONLY
2498 static ExitStatus
op_lura(DisasContext
*s
, DisasOps
*o
)
2500 check_privileged(s
);
2501 potential_page_fault(s
);
2502 gen_helper_lura(o
->out
, cpu_env
, o
->in2
);
2506 static ExitStatus
op_lurag(DisasContext
*s
, DisasOps
*o
)
2508 check_privileged(s
);
2509 potential_page_fault(s
);
2510 gen_helper_lurag(o
->out
, cpu_env
, o
->in2
);
2515 static ExitStatus
op_mov2(DisasContext
*s
, DisasOps
*o
)
2518 o
->g_out
= o
->g_in2
;
2519 TCGV_UNUSED_I64(o
->in2
);
2524 static ExitStatus
op_movx(DisasContext
*s
, DisasOps
*o
)
2528 o
->g_out
= o
->g_in1
;
2529 o
->g_out2
= o
->g_in2
;
2530 TCGV_UNUSED_I64(o
->in1
);
2531 TCGV_UNUSED_I64(o
->in2
);
2532 o
->g_in1
= o
->g_in2
= false;
2536 static ExitStatus
op_mvc(DisasContext
*s
, DisasOps
*o
)
2538 TCGv_i32 l
= tcg_const_i32(get_field(s
->fields
, l1
));
2539 potential_page_fault(s
);
2540 gen_helper_mvc(cpu_env
, l
, o
->addr1
, o
->in2
);
2541 tcg_temp_free_i32(l
);
2545 static ExitStatus
op_mvcl(DisasContext
*s
, DisasOps
*o
)
2547 TCGv_i32 r1
= tcg_const_i32(get_field(s
->fields
, r1
));
2548 TCGv_i32 r2
= tcg_const_i32(get_field(s
->fields
, r2
));
2549 potential_page_fault(s
);
2550 gen_helper_mvcl(cc_op
, cpu_env
, r1
, r2
);
2551 tcg_temp_free_i32(r1
);
2552 tcg_temp_free_i32(r2
);
2557 static ExitStatus
op_mvcle(DisasContext
*s
, DisasOps
*o
)
2559 TCGv_i32 r1
= tcg_const_i32(get_field(s
->fields
, r1
));
2560 TCGv_i32 r3
= tcg_const_i32(get_field(s
->fields
, r3
));
2561 potential_page_fault(s
);
2562 gen_helper_mvcle(cc_op
, cpu_env
, r1
, o
->in2
, r3
);
2563 tcg_temp_free_i32(r1
);
2564 tcg_temp_free_i32(r3
);
2569 #ifndef CONFIG_USER_ONLY
2570 static ExitStatus
op_mvcp(DisasContext
*s
, DisasOps
*o
)
2572 int r1
= get_field(s
->fields
, l1
);
2573 check_privileged(s
);
2574 potential_page_fault(s
);
2575 gen_helper_mvcp(cc_op
, cpu_env
, regs
[r1
], o
->addr1
, o
->in2
);
2580 static ExitStatus
op_mvcs(DisasContext
*s
, DisasOps
*o
)
2582 int r1
= get_field(s
->fields
, l1
);
2583 check_privileged(s
);
2584 potential_page_fault(s
);
2585 gen_helper_mvcs(cc_op
, cpu_env
, regs
[r1
], o
->addr1
, o
->in2
);
2591 static ExitStatus
op_mvpg(DisasContext
*s
, DisasOps
*o
)
2593 potential_page_fault(s
);
2594 gen_helper_mvpg(cpu_env
, regs
[0], o
->in1
, o
->in2
);
2599 static ExitStatus
op_mvst(DisasContext
*s
, DisasOps
*o
)
2601 potential_page_fault(s
);
2602 gen_helper_mvst(o
->in1
, cpu_env
, regs
[0], o
->in1
, o
->in2
);
2604 return_low128(o
->in2
);
2608 static ExitStatus
op_mul(DisasContext
*s
, DisasOps
*o
)
2610 tcg_gen_mul_i64(o
->out
, o
->in1
, o
->in2
);
2614 static ExitStatus
op_mul128(DisasContext
*s
, DisasOps
*o
)
2616 tcg_gen_mulu2_i64(o
->out2
, o
->out
, o
->in1
, o
->in2
);
2620 static ExitStatus
op_meeb(DisasContext
*s
, DisasOps
*o
)
2622 gen_helper_meeb(o
->out
, cpu_env
, o
->in1
, o
->in2
);
2626 static ExitStatus
op_mdeb(DisasContext
*s
, DisasOps
*o
)
2628 gen_helper_mdeb(o
->out
, cpu_env
, o
->in1
, o
->in2
);
2632 static ExitStatus
op_mdb(DisasContext
*s
, DisasOps
*o
)
2634 gen_helper_mdb(o
->out
, cpu_env
, o
->in1
, o
->in2
);
2638 static ExitStatus
op_mxb(DisasContext
*s
, DisasOps
*o
)
2640 gen_helper_mxb(o
->out
, cpu_env
, o
->out
, o
->out2
, o
->in1
, o
->in2
);
2641 return_low128(o
->out2
);
2645 static ExitStatus
op_mxdb(DisasContext
*s
, DisasOps
*o
)
2647 gen_helper_mxdb(o
->out
, cpu_env
, o
->out
, o
->out2
, o
->in2
);
2648 return_low128(o
->out2
);
2652 static ExitStatus
op_maeb(DisasContext
*s
, DisasOps
*o
)
2654 TCGv_i64 r3
= load_freg32_i64(get_field(s
->fields
, r3
));
2655 gen_helper_maeb(o
->out
, cpu_env
, o
->in1
, o
->in2
, r3
);
2656 tcg_temp_free_i64(r3
);
2660 static ExitStatus
op_madb(DisasContext
*s
, DisasOps
*o
)
2662 int r3
= get_field(s
->fields
, r3
);
2663 gen_helper_madb(o
->out
, cpu_env
, o
->in1
, o
->in2
, fregs
[r3
]);
2667 static ExitStatus
op_mseb(DisasContext
*s
, DisasOps
*o
)
2669 TCGv_i64 r3
= load_freg32_i64(get_field(s
->fields
, r3
));
2670 gen_helper_mseb(o
->out
, cpu_env
, o
->in1
, o
->in2
, r3
);
2671 tcg_temp_free_i64(r3
);
2675 static ExitStatus
op_msdb(DisasContext
*s
, DisasOps
*o
)
2677 int r3
= get_field(s
->fields
, r3
);
2678 gen_helper_msdb(o
->out
, cpu_env
, o
->in1
, o
->in2
, fregs
[r3
]);
2682 static ExitStatus
op_nabs(DisasContext
*s
, DisasOps
*o
)
2684 gen_helper_nabs_i64(o
->out
, o
->in2
);
2688 static ExitStatus
op_nabsf32(DisasContext
*s
, DisasOps
*o
)
2690 tcg_gen_ori_i64(o
->out
, o
->in2
, 0x80000000ull
);
2694 static ExitStatus
op_nabsf64(DisasContext
*s
, DisasOps
*o
)
2696 tcg_gen_ori_i64(o
->out
, o
->in2
, 0x8000000000000000ull
);
2700 static ExitStatus
op_nabsf128(DisasContext
*s
, DisasOps
*o
)
2702 tcg_gen_ori_i64(o
->out
, o
->in1
, 0x8000000000000000ull
);
2703 tcg_gen_mov_i64(o
->out2
, o
->in2
);
2707 static ExitStatus
op_nc(DisasContext
*s
, DisasOps
*o
)
2709 TCGv_i32 l
= tcg_const_i32(get_field(s
->fields
, l1
));
2710 potential_page_fault(s
);
2711 gen_helper_nc(cc_op
, cpu_env
, l
, o
->addr1
, o
->in2
);
2712 tcg_temp_free_i32(l
);
2717 static ExitStatus
op_neg(DisasContext
*s
, DisasOps
*o
)
2719 tcg_gen_neg_i64(o
->out
, o
->in2
);
2723 static ExitStatus
op_negf32(DisasContext
*s
, DisasOps
*o
)
2725 tcg_gen_xori_i64(o
->out
, o
->in2
, 0x80000000ull
);
2729 static ExitStatus
op_negf64(DisasContext
*s
, DisasOps
*o
)
2731 tcg_gen_xori_i64(o
->out
, o
->in2
, 0x8000000000000000ull
);
2735 static ExitStatus
op_negf128(DisasContext
*s
, DisasOps
*o
)
2737 tcg_gen_xori_i64(o
->out
, o
->in1
, 0x8000000000000000ull
);
2738 tcg_gen_mov_i64(o
->out2
, o
->in2
);
2742 static ExitStatus
op_oc(DisasContext
*s
, DisasOps
*o
)
2744 TCGv_i32 l
= tcg_const_i32(get_field(s
->fields
, l1
));
2745 potential_page_fault(s
);
2746 gen_helper_oc(cc_op
, cpu_env
, l
, o
->addr1
, o
->in2
);
2747 tcg_temp_free_i32(l
);
2752 static ExitStatus
op_or(DisasContext
*s
, DisasOps
*o
)
2754 tcg_gen_or_i64(o
->out
, o
->in1
, o
->in2
);
2758 static ExitStatus
op_ori(DisasContext
*s
, DisasOps
*o
)
2760 int shift
= s
->insn
->data
& 0xff;
2761 int size
= s
->insn
->data
>> 8;
2762 uint64_t mask
= ((1ull << size
) - 1) << shift
;
2765 tcg_gen_shli_i64(o
->in2
, o
->in2
, shift
);
2766 tcg_gen_or_i64(o
->out
, o
->in1
, o
->in2
);
2768 /* Produce the CC from only the bits manipulated. */
2769 tcg_gen_andi_i64(cc_dst
, o
->out
, mask
);
2770 set_cc_nz_u64(s
, cc_dst
);
2774 static ExitStatus
op_popcnt(DisasContext
*s
, DisasOps
*o
)
2776 gen_helper_popcnt(o
->out
, o
->in2
);
2780 #ifndef CONFIG_USER_ONLY
2781 static ExitStatus
op_ptlb(DisasContext
*s
, DisasOps
*o
)
2783 check_privileged(s
);
2784 gen_helper_ptlb(cpu_env
);
2789 static ExitStatus
op_risbg(DisasContext
*s
, DisasOps
*o
)
2791 int i3
= get_field(s
->fields
, i3
);
2792 int i4
= get_field(s
->fields
, i4
);
2793 int i5
= get_field(s
->fields
, i5
);
2794 int do_zero
= i4
& 0x80;
2795 uint64_t mask
, imask
, pmask
;
2798 /* Adjust the arguments for the specific insn. */
2799 switch (s
->fields
->op2
) {
2800 case 0x55: /* risbg */
2805 case 0x5d: /* risbhg */
2808 pmask
= 0xffffffff00000000ull
;
2810 case 0x51: /* risblg */
2813 pmask
= 0x00000000ffffffffull
;
2819 /* MASK is the set of bits to be inserted from R2.
2820 Take care for I3/I4 wraparound. */
2823 mask
^= pmask
>> i4
>> 1;
2825 mask
|= ~(pmask
>> i4
>> 1);
2829 /* IMASK is the set of bits to be kept from R1. In the case of the high/low
2830 insns, we need to keep the other half of the register. */
2831 imask
= ~mask
| ~pmask
;
2833 if (s
->fields
->op2
== 0x55) {
2840 /* In some cases we can implement this with deposit, which can be more
2841 efficient on some hosts. */
2842 if (~mask
== imask
&& i3
<= i4
) {
2843 if (s
->fields
->op2
== 0x5d) {
2846 /* Note that we rotate the bits to be inserted to the lsb, not to
2847 the position as described in the PoO. */
2850 rot
= (i5
- pos
) & 63;
2856 /* Rotate the input as necessary. */
2857 tcg_gen_rotli_i64(o
->in2
, o
->in2
, rot
);
2859 /* Insert the selected bits into the output. */
2861 tcg_gen_deposit_i64(o
->out
, o
->out
, o
->in2
, pos
, len
);
2862 } else if (imask
== 0) {
2863 tcg_gen_andi_i64(o
->out
, o
->in2
, mask
);
2865 tcg_gen_andi_i64(o
->in2
, o
->in2
, mask
);
2866 tcg_gen_andi_i64(o
->out
, o
->out
, imask
);
2867 tcg_gen_or_i64(o
->out
, o
->out
, o
->in2
);
2872 static ExitStatus
op_rosbg(DisasContext
*s
, DisasOps
*o
)
2874 int i3
= get_field(s
->fields
, i3
);
2875 int i4
= get_field(s
->fields
, i4
);
2876 int i5
= get_field(s
->fields
, i5
);
2879 /* If this is a test-only form, arrange to discard the result. */
2881 o
->out
= tcg_temp_new_i64();
2889 /* MASK is the set of bits to be operated on from R2.
2890 Take care for I3/I4 wraparound. */
2893 mask
^= ~0ull >> i4
>> 1;
2895 mask
|= ~(~0ull >> i4
>> 1);
2898 /* Rotate the input as necessary. */
2899 tcg_gen_rotli_i64(o
->in2
, o
->in2
, i5
);
2902 switch (s
->fields
->op2
) {
2903 case 0x55: /* AND */
2904 tcg_gen_ori_i64(o
->in2
, o
->in2
, ~mask
);
2905 tcg_gen_and_i64(o
->out
, o
->out
, o
->in2
);
2908 tcg_gen_andi_i64(o
->in2
, o
->in2
, mask
);
2909 tcg_gen_or_i64(o
->out
, o
->out
, o
->in2
);
2911 case 0x57: /* XOR */
2912 tcg_gen_andi_i64(o
->in2
, o
->in2
, mask
);
2913 tcg_gen_xor_i64(o
->out
, o
->out
, o
->in2
);
2920 tcg_gen_andi_i64(cc_dst
, o
->out
, mask
);
2921 set_cc_nz_u64(s
, cc_dst
);
2925 static ExitStatus
op_rev16(DisasContext
*s
, DisasOps
*o
)
2927 tcg_gen_bswap16_i64(o
->out
, o
->in2
);
2931 static ExitStatus
op_rev32(DisasContext
*s
, DisasOps
*o
)
2933 tcg_gen_bswap32_i64(o
->out
, o
->in2
);
2937 static ExitStatus
op_rev64(DisasContext
*s
, DisasOps
*o
)
2939 tcg_gen_bswap64_i64(o
->out
, o
->in2
);
2943 static ExitStatus
op_rll32(DisasContext
*s
, DisasOps
*o
)
2945 TCGv_i32 t1
= tcg_temp_new_i32();
2946 TCGv_i32 t2
= tcg_temp_new_i32();
2947 TCGv_i32 to
= tcg_temp_new_i32();
2948 tcg_gen_trunc_i64_i32(t1
, o
->in1
);
2949 tcg_gen_trunc_i64_i32(t2
, o
->in2
);
2950 tcg_gen_rotl_i32(to
, t1
, t2
);
2951 tcg_gen_extu_i32_i64(o
->out
, to
);
2952 tcg_temp_free_i32(t1
);
2953 tcg_temp_free_i32(t2
);
2954 tcg_temp_free_i32(to
);
2958 static ExitStatus
op_rll64(DisasContext
*s
, DisasOps
*o
)
2960 tcg_gen_rotl_i64(o
->out
, o
->in1
, o
->in2
);
2964 #ifndef CONFIG_USER_ONLY
2965 static ExitStatus
op_rrbe(DisasContext
*s
, DisasOps
*o
)
2967 check_privileged(s
);
2968 gen_helper_rrbe(cc_op
, cpu_env
, o
->in2
);
2973 static ExitStatus
op_sacf(DisasContext
*s
, DisasOps
*o
)
2975 check_privileged(s
);
2976 gen_helper_sacf(cpu_env
, o
->in2
);
2977 /* Addressing mode has changed, so end the block. */
2978 return EXIT_PC_STALE
;
2982 static ExitStatus
op_sam(DisasContext
*s
, DisasOps
*o
)
2984 int sam
= s
->insn
->data
;
3000 /* Bizarre but true, we check the address of the current insn for the
3001 specification exception, not the next to be executed. Thus the PoO
3002 documents that Bad Things Happen two bytes before the end. */
3003 if (s
->pc
& ~mask
) {
3004 gen_program_exception(s
, PGM_SPECIFICATION
);
3005 return EXIT_NORETURN
;
3009 tsam
= tcg_const_i64(sam
);
3010 tcg_gen_deposit_i64(psw_mask
, psw_mask
, tsam
, 31, 2);
3011 tcg_temp_free_i64(tsam
);
3013 /* Always exit the TB, since we (may have) changed execution mode. */
3014 return EXIT_PC_STALE
;
3017 static ExitStatus
op_sar(DisasContext
*s
, DisasOps
*o
)
3019 int r1
= get_field(s
->fields
, r1
);
3020 tcg_gen_st32_i64(o
->in2
, cpu_env
, offsetof(CPUS390XState
, aregs
[r1
]));
3024 static ExitStatus
op_seb(DisasContext
*s
, DisasOps
*o
)
3026 gen_helper_seb(o
->out
, cpu_env
, o
->in1
, o
->in2
);
3030 static ExitStatus
op_sdb(DisasContext
*s
, DisasOps
*o
)
3032 gen_helper_sdb(o
->out
, cpu_env
, o
->in1
, o
->in2
);
3036 static ExitStatus
op_sxb(DisasContext
*s
, DisasOps
*o
)
3038 gen_helper_sxb(o
->out
, cpu_env
, o
->out
, o
->out2
, o
->in1
, o
->in2
);
3039 return_low128(o
->out2
);
3043 static ExitStatus
op_sqeb(DisasContext
*s
, DisasOps
*o
)
3045 gen_helper_sqeb(o
->out
, cpu_env
, o
->in2
);
3049 static ExitStatus
op_sqdb(DisasContext
*s
, DisasOps
*o
)
3051 gen_helper_sqdb(o
->out
, cpu_env
, o
->in2
);
3055 static ExitStatus
op_sqxb(DisasContext
*s
, DisasOps
*o
)
3057 gen_helper_sqxb(o
->out
, cpu_env
, o
->in1
, o
->in2
);
3058 return_low128(o
->out2
);
3062 #ifndef CONFIG_USER_ONLY
3063 static ExitStatus
op_servc(DisasContext
*s
, DisasOps
*o
)
3065 check_privileged(s
);
3066 potential_page_fault(s
);
3067 gen_helper_servc(cc_op
, cpu_env
, o
->in2
, o
->in1
);
3072 static ExitStatus
op_sigp(DisasContext
*s
, DisasOps
*o
)
3074 TCGv_i32 r1
= tcg_const_i32(get_field(s
->fields
, r1
));
3075 check_privileged(s
);
3076 potential_page_fault(s
);
3077 gen_helper_sigp(cc_op
, cpu_env
, o
->in2
, r1
, o
->in1
);
3078 tcg_temp_free_i32(r1
);
3083 static ExitStatus
op_soc(DisasContext
*s
, DisasOps
*o
)
3090 disas_jcc(s
, &c
, get_field(s
->fields
, m3
));
3092 /* We want to store when the condition is fulfilled, so branch
3093 out when it's not */
3094 c
.cond
= tcg_invert_cond(c
.cond
);
3096 lab
= gen_new_label();
3098 tcg_gen_brcond_i64(c
.cond
, c
.u
.s64
.a
, c
.u
.s64
.b
, lab
);
3100 tcg_gen_brcond_i32(c
.cond
, c
.u
.s32
.a
, c
.u
.s32
.b
, lab
);
3104 r1
= get_field(s
->fields
, r1
);
3105 a
= get_address(s
, 0, get_field(s
->fields
, b2
), get_field(s
->fields
, d2
));
3106 if (s
->insn
->data
) {
3107 tcg_gen_qemu_st64(regs
[r1
], a
, get_mem_index(s
));
3109 tcg_gen_qemu_st32(regs
[r1
], a
, get_mem_index(s
));
3111 tcg_temp_free_i64(a
);
3117 static ExitStatus
op_sla(DisasContext
*s
, DisasOps
*o
)
3119 uint64_t sign
= 1ull << s
->insn
->data
;
3120 enum cc_op cco
= s
->insn
->data
== 31 ? CC_OP_SLA_32
: CC_OP_SLA_64
;
3121 gen_op_update2_cc_i64(s
, cco
, o
->in1
, o
->in2
);
3122 tcg_gen_shl_i64(o
->out
, o
->in1
, o
->in2
);
3123 /* The arithmetic left shift is curious in that it does not affect
3124 the sign bit. Copy that over from the source unchanged. */
3125 tcg_gen_andi_i64(o
->out
, o
->out
, ~sign
);
3126 tcg_gen_andi_i64(o
->in1
, o
->in1
, sign
);
3127 tcg_gen_or_i64(o
->out
, o
->out
, o
->in1
);
3131 static ExitStatus
op_sll(DisasContext
*s
, DisasOps
*o
)
3133 tcg_gen_shl_i64(o
->out
, o
->in1
, o
->in2
);
3137 static ExitStatus
op_sra(DisasContext
*s
, DisasOps
*o
)
3139 tcg_gen_sar_i64(o
->out
, o
->in1
, o
->in2
);
3143 static ExitStatus
op_srl(DisasContext
*s
, DisasOps
*o
)
3145 tcg_gen_shr_i64(o
->out
, o
->in1
, o
->in2
);
3149 static ExitStatus
op_sfpc(DisasContext
*s
, DisasOps
*o
)
3151 gen_helper_sfpc(cpu_env
, o
->in2
);
3155 static ExitStatus
op_sfas(DisasContext
*s
, DisasOps
*o
)
3157 gen_helper_sfas(cpu_env
, o
->in2
);
3161 static ExitStatus
op_srnm(DisasContext
*s
, DisasOps
*o
)
3163 int b2
= get_field(s
->fields
, b2
);
3164 int d2
= get_field(s
->fields
, d2
);
3165 TCGv_i64 t1
= tcg_temp_new_i64();
3166 TCGv_i64 t2
= tcg_temp_new_i64();
3169 switch (s
->fields
->op2
) {
3170 case 0x99: /* SRNM */
3173 case 0xb8: /* SRNMB */
3176 case 0xb9: /* SRNMT */
3182 mask
= (1 << len
) - 1;
3184 /* Insert the value into the appropriate field of the FPC. */
3186 tcg_gen_movi_i64(t1
, d2
& mask
);
3188 tcg_gen_addi_i64(t1
, regs
[b2
], d2
);
3189 tcg_gen_andi_i64(t1
, t1
, mask
);
3191 tcg_gen_ld32u_i64(t2
, cpu_env
, offsetof(CPUS390XState
, fpc
));
3192 tcg_gen_deposit_i64(t2
, t2
, t1
, pos
, len
);
3193 tcg_temp_free_i64(t1
);
3195 /* Then install the new FPC to set the rounding mode in fpu_status. */
3196 gen_helper_sfpc(cpu_env
, t2
);
3197 tcg_temp_free_i64(t2
);
3201 #ifndef CONFIG_USER_ONLY
3202 static ExitStatus
op_spka(DisasContext
*s
, DisasOps
*o
)
3204 check_privileged(s
);
3205 tcg_gen_shri_i64(o
->in2
, o
->in2
, 4);
3206 tcg_gen_deposit_i64(psw_mask
, psw_mask
, o
->in2
, PSW_SHIFT_KEY
- 4, 4);
3210 static ExitStatus
op_sske(DisasContext
*s
, DisasOps
*o
)
3212 check_privileged(s
);
3213 gen_helper_sske(cpu_env
, o
->in1
, o
->in2
);
3217 static ExitStatus
op_ssm(DisasContext
*s
, DisasOps
*o
)
3219 check_privileged(s
);
3220 tcg_gen_deposit_i64(psw_mask
, psw_mask
, o
->in2
, 56, 8);
3224 static ExitStatus
op_stap(DisasContext
*s
, DisasOps
*o
)
3226 check_privileged(s
);
3227 /* ??? Surely cpu address != cpu number. In any case the previous
3228 version of this stored more than the required half-word, so it
3229 is unlikely this has ever been tested. */
3230 tcg_gen_ld32u_i64(o
->out
, cpu_env
, offsetof(CPUS390XState
, cpu_num
));
3234 static ExitStatus
op_stck(DisasContext
*s
, DisasOps
*o
)
3236 gen_helper_stck(o
->out
, cpu_env
);
3237 /* ??? We don't implement clock states. */
3238 gen_op_movi_cc(s
, 0);
3242 static ExitStatus
op_stcke(DisasContext
*s
, DisasOps
*o
)
3244 TCGv_i64 c1
= tcg_temp_new_i64();
3245 TCGv_i64 c2
= tcg_temp_new_i64();
3246 gen_helper_stck(c1
, cpu_env
);
3247 /* Shift the 64-bit value into its place as a zero-extended
3248 104-bit value. Note that "bit positions 64-103 are always
3249 non-zero so that they compare differently to STCK"; we set
3250 the least significant bit to 1. */
3251 tcg_gen_shli_i64(c2
, c1
, 56);
3252 tcg_gen_shri_i64(c1
, c1
, 8);
3253 tcg_gen_ori_i64(c2
, c2
, 0x10000);
3254 tcg_gen_qemu_st64(c1
, o
->in2
, get_mem_index(s
));
3255 tcg_gen_addi_i64(o
->in2
, o
->in2
, 8);
3256 tcg_gen_qemu_st64(c2
, o
->in2
, get_mem_index(s
));
3257 tcg_temp_free_i64(c1
);
3258 tcg_temp_free_i64(c2
);
3259 /* ??? We don't implement clock states. */
3260 gen_op_movi_cc(s
, 0);
3264 static ExitStatus
op_sckc(DisasContext
*s
, DisasOps
*o
)
3266 check_privileged(s
);
3267 gen_helper_sckc(cpu_env
, o
->in2
);
3271 static ExitStatus
op_stckc(DisasContext
*s
, DisasOps
*o
)
3273 check_privileged(s
);
3274 gen_helper_stckc(o
->out
, cpu_env
);
3278 static ExitStatus
op_stctg(DisasContext
*s
, DisasOps
*o
)
3280 TCGv_i32 r1
= tcg_const_i32(get_field(s
->fields
, r1
));
3281 TCGv_i32 r3
= tcg_const_i32(get_field(s
->fields
, r3
));
3282 check_privileged(s
);
3283 potential_page_fault(s
);
3284 gen_helper_stctg(cpu_env
, r1
, o
->in2
, r3
);
3285 tcg_temp_free_i32(r1
);
3286 tcg_temp_free_i32(r3
);
3290 static ExitStatus
op_stctl(DisasContext
*s
, DisasOps
*o
)
3292 TCGv_i32 r1
= tcg_const_i32(get_field(s
->fields
, r1
));
3293 TCGv_i32 r3
= tcg_const_i32(get_field(s
->fields
, r3
));
3294 check_privileged(s
);
3295 potential_page_fault(s
);
3296 gen_helper_stctl(cpu_env
, r1
, o
->in2
, r3
);
3297 tcg_temp_free_i32(r1
);
3298 tcg_temp_free_i32(r3
);
3302 static ExitStatus
op_stidp(DisasContext
*s
, DisasOps
*o
)
3304 TCGv_i64 t1
= tcg_temp_new_i64();
3306 check_privileged(s
);
3307 tcg_gen_ld32u_i64(o
->out
, cpu_env
, offsetof(CPUS390XState
, cpu_num
));
3308 tcg_gen_ld32u_i64(t1
, cpu_env
, offsetof(CPUS390XState
, machine_type
));
3309 tcg_gen_deposit_i64(o
->out
, o
->out
, t1
, 32, 32);
3310 tcg_temp_free_i64(t1
);
3315 static ExitStatus
op_spt(DisasContext
*s
, DisasOps
*o
)
3317 check_privileged(s
);
3318 gen_helper_spt(cpu_env
, o
->in2
);
3322 static ExitStatus
op_stfl(DisasContext
*s
, DisasOps
*o
)
3325 /* We really ought to have more complete indication of facilities
3326 that we implement. Address this when STFLE is implemented. */
3327 check_privileged(s
);
3328 f
= tcg_const_i64(0xc0000000);
3329 a
= tcg_const_i64(200);
3330 tcg_gen_qemu_st32(f
, a
, get_mem_index(s
));
3331 tcg_temp_free_i64(f
);
3332 tcg_temp_free_i64(a
);
3336 static ExitStatus
op_stpt(DisasContext
*s
, DisasOps
*o
)
3338 check_privileged(s
);
3339 gen_helper_stpt(o
->out
, cpu_env
);
3343 static ExitStatus
op_stsi(DisasContext
*s
, DisasOps
*o
)
3345 check_privileged(s
);
3346 potential_page_fault(s
);
3347 gen_helper_stsi(cc_op
, cpu_env
, o
->in2
, regs
[0], regs
[1]);
3352 static ExitStatus
op_spx(DisasContext
*s
, DisasOps
*o
)
3354 check_privileged(s
);
3355 gen_helper_spx(cpu_env
, o
->in2
);
3359 static ExitStatus
op_subchannel(DisasContext
*s
, DisasOps
*o
)
3361 check_privileged(s
);
3362 /* Not operational. */
3363 gen_op_movi_cc(s
, 3);
3367 static ExitStatus
op_stpx(DisasContext
*s
, DisasOps
*o
)
3369 check_privileged(s
);
3370 tcg_gen_ld_i64(o
->out
, cpu_env
, offsetof(CPUS390XState
, psa
));
3371 tcg_gen_andi_i64(o
->out
, o
->out
, 0x7fffe000);
3375 static ExitStatus
op_stnosm(DisasContext
*s
, DisasOps
*o
)
3377 uint64_t i2
= get_field(s
->fields
, i2
);
3380 check_privileged(s
);
3382 /* It is important to do what the instruction name says: STORE THEN.
3383 If we let the output hook perform the store then if we fault and
3384 restart, we'll have the wrong SYSTEM MASK in place. */
3385 t
= tcg_temp_new_i64();
3386 tcg_gen_shri_i64(t
, psw_mask
, 56);
3387 tcg_gen_qemu_st8(t
, o
->addr1
, get_mem_index(s
));
3388 tcg_temp_free_i64(t
);
3390 if (s
->fields
->op
== 0xac) {
3391 tcg_gen_andi_i64(psw_mask
, psw_mask
,
3392 (i2
<< 56) | 0x00ffffffffffffffull
);
3394 tcg_gen_ori_i64(psw_mask
, psw_mask
, i2
<< 56);
3399 static ExitStatus
op_stura(DisasContext
*s
, DisasOps
*o
)
3401 check_privileged(s
);
3402 potential_page_fault(s
);
3403 gen_helper_stura(cpu_env
, o
->in2
, o
->in1
);
3407 static ExitStatus
op_sturg(DisasContext
*s
, DisasOps
*o
)
3409 check_privileged(s
);
3410 potential_page_fault(s
);
3411 gen_helper_sturg(cpu_env
, o
->in2
, o
->in1
);
3416 static ExitStatus
op_st8(DisasContext
*s
, DisasOps
*o
)
3418 tcg_gen_qemu_st8(o
->in1
, o
->in2
, get_mem_index(s
));
3422 static ExitStatus
op_st16(DisasContext
*s
, DisasOps
*o
)
3424 tcg_gen_qemu_st16(o
->in1
, o
->in2
, get_mem_index(s
));
3428 static ExitStatus
op_st32(DisasContext
*s
, DisasOps
*o
)
3430 tcg_gen_qemu_st32(o
->in1
, o
->in2
, get_mem_index(s
));
3434 static ExitStatus
op_st64(DisasContext
*s
, DisasOps
*o
)
3436 tcg_gen_qemu_st64(o
->in1
, o
->in2
, get_mem_index(s
));
3440 static ExitStatus
op_stam(DisasContext
*s
, DisasOps
*o
)
3442 TCGv_i32 r1
= tcg_const_i32(get_field(s
->fields
, r1
));
3443 TCGv_i32 r3
= tcg_const_i32(get_field(s
->fields
, r3
));
3444 potential_page_fault(s
);
3445 gen_helper_stam(cpu_env
, r1
, o
->in2
, r3
);
3446 tcg_temp_free_i32(r1
);
3447 tcg_temp_free_i32(r3
);
3451 static ExitStatus
op_stcm(DisasContext
*s
, DisasOps
*o
)
3453 int m3
= get_field(s
->fields
, m3
);
3454 int pos
, base
= s
->insn
->data
;
3455 TCGv_i64 tmp
= tcg_temp_new_i64();
3457 pos
= base
+ ctz32(m3
) * 8;
3460 /* Effectively a 32-bit store. */
3461 tcg_gen_shri_i64(tmp
, o
->in1
, pos
);
3462 tcg_gen_qemu_st32(tmp
, o
->in2
, get_mem_index(s
));
3468 /* Effectively a 16-bit store. */
3469 tcg_gen_shri_i64(tmp
, o
->in1
, pos
);
3470 tcg_gen_qemu_st16(tmp
, o
->in2
, get_mem_index(s
));
3477 /* Effectively an 8-bit store. */
3478 tcg_gen_shri_i64(tmp
, o
->in1
, pos
);
3479 tcg_gen_qemu_st8(tmp
, o
->in2
, get_mem_index(s
));
3483 /* This is going to be a sequence of shifts and stores. */
3484 pos
= base
+ 32 - 8;
3487 tcg_gen_shri_i64(tmp
, o
->in1
, pos
);
3488 tcg_gen_qemu_st8(tmp
, o
->in2
, get_mem_index(s
));
3489 tcg_gen_addi_i64(o
->in2
, o
->in2
, 1);
3491 m3
= (m3
<< 1) & 0xf;
3496 tcg_temp_free_i64(tmp
);
3500 static ExitStatus
op_stm(DisasContext
*s
, DisasOps
*o
)
3502 int r1
= get_field(s
->fields
, r1
);
3503 int r3
= get_field(s
->fields
, r3
);
3504 int size
= s
->insn
->data
;
3505 TCGv_i64 tsize
= tcg_const_i64(size
);
3509 tcg_gen_qemu_st64(regs
[r1
], o
->in2
, get_mem_index(s
));
3511 tcg_gen_qemu_st32(regs
[r1
], o
->in2
, get_mem_index(s
));
3516 tcg_gen_add_i64(o
->in2
, o
->in2
, tsize
);
3520 tcg_temp_free_i64(tsize
);
3524 static ExitStatus
op_stmh(DisasContext
*s
, DisasOps
*o
)
3526 int r1
= get_field(s
->fields
, r1
);
3527 int r3
= get_field(s
->fields
, r3
);
3528 TCGv_i64 t
= tcg_temp_new_i64();
3529 TCGv_i64 t4
= tcg_const_i64(4);
3530 TCGv_i64 t32
= tcg_const_i64(32);
3533 tcg_gen_shl_i64(t
, regs
[r1
], t32
);
3534 tcg_gen_qemu_st32(t
, o
->in2
, get_mem_index(s
));
3538 tcg_gen_add_i64(o
->in2
, o
->in2
, t4
);
3542 tcg_temp_free_i64(t
);
3543 tcg_temp_free_i64(t4
);
3544 tcg_temp_free_i64(t32
);
3548 static ExitStatus
op_srst(DisasContext
*s
, DisasOps
*o
)
3550 potential_page_fault(s
);
3551 gen_helper_srst(o
->in1
, cpu_env
, regs
[0], o
->in1
, o
->in2
);
3553 return_low128(o
->in2
);
3557 static ExitStatus
op_sub(DisasContext
*s
, DisasOps
*o
)
3559 tcg_gen_sub_i64(o
->out
, o
->in1
, o
->in2
);
3563 static ExitStatus
op_subb(DisasContext
*s
, DisasOps
*o
)
3568 tcg_gen_sub_i64(o
->out
, o
->in1
, o
->in2
);
3570 /* The !borrow flag is the msb of CC. Since we want the inverse of
3571 that, we ask for a comparison of CC=0 | CC=1 -> mask of 8 | 4. */
3572 disas_jcc(s
, &cmp
, 8 | 4);
3573 borrow
= tcg_temp_new_i64();
3575 tcg_gen_setcond_i64(cmp
.cond
, borrow
, cmp
.u
.s64
.a
, cmp
.u
.s64
.b
);
3577 TCGv_i32 t
= tcg_temp_new_i32();
3578 tcg_gen_setcond_i32(cmp
.cond
, t
, cmp
.u
.s32
.a
, cmp
.u
.s32
.b
);
3579 tcg_gen_extu_i32_i64(borrow
, t
);
3580 tcg_temp_free_i32(t
);
3584 tcg_gen_sub_i64(o
->out
, o
->out
, borrow
);
3585 tcg_temp_free_i64(borrow
);
3589 static ExitStatus
op_svc(DisasContext
*s
, DisasOps
*o
)
3596 t
= tcg_const_i32(get_field(s
->fields
, i1
) & 0xff);
3597 tcg_gen_st_i32(t
, cpu_env
, offsetof(CPUS390XState
, int_svc_code
));
3598 tcg_temp_free_i32(t
);
3600 t
= tcg_const_i32(s
->next_pc
- s
->pc
);
3601 tcg_gen_st_i32(t
, cpu_env
, offsetof(CPUS390XState
, int_svc_ilen
));
3602 tcg_temp_free_i32(t
);
3604 gen_exception(EXCP_SVC
);
3605 return EXIT_NORETURN
;
3608 static ExitStatus
op_tceb(DisasContext
*s
, DisasOps
*o
)
3610 gen_helper_tceb(cc_op
, o
->in1
, o
->in2
);
3615 static ExitStatus
op_tcdb(DisasContext
*s
, DisasOps
*o
)
3617 gen_helper_tcdb(cc_op
, o
->in1
, o
->in2
);
3622 static ExitStatus
op_tcxb(DisasContext
*s
, DisasOps
*o
)
3624 gen_helper_tcxb(cc_op
, o
->out
, o
->out2
, o
->in2
);
3629 #ifndef CONFIG_USER_ONLY
3630 static ExitStatus
op_tprot(DisasContext
*s
, DisasOps
*o
)
3632 potential_page_fault(s
);
3633 gen_helper_tprot(cc_op
, o
->addr1
, o
->in2
);
3639 static ExitStatus
op_tr(DisasContext
*s
, DisasOps
*o
)
3641 TCGv_i32 l
= tcg_const_i32(get_field(s
->fields
, l1
));
3642 potential_page_fault(s
);
3643 gen_helper_tr(cpu_env
, l
, o
->addr1
, o
->in2
);
3644 tcg_temp_free_i32(l
);
3649 static ExitStatus
op_unpk(DisasContext
*s
, DisasOps
*o
)
3651 TCGv_i32 l
= tcg_const_i32(get_field(s
->fields
, l1
));
3652 potential_page_fault(s
);
3653 gen_helper_unpk(cpu_env
, l
, o
->addr1
, o
->in2
);
3654 tcg_temp_free_i32(l
);
3658 static ExitStatus
op_xc(DisasContext
*s
, DisasOps
*o
)
3660 int d1
= get_field(s
->fields
, d1
);
3661 int d2
= get_field(s
->fields
, d2
);
3662 int b1
= get_field(s
->fields
, b1
);
3663 int b2
= get_field(s
->fields
, b2
);
3664 int l
= get_field(s
->fields
, l1
);
3667 o
->addr1
= get_address(s
, 0, b1
, d1
);
3669 /* If the addresses are identical, this is a store/memset of zero. */
3670 if (b1
== b2
&& d1
== d2
&& (l
+ 1) <= 32) {
3671 o
->in2
= tcg_const_i64(0);
3675 tcg_gen_qemu_st64(o
->in2
, o
->addr1
, get_mem_index(s
));
3678 tcg_gen_addi_i64(o
->addr1
, o
->addr1
, 8);
3682 tcg_gen_qemu_st32(o
->in2
, o
->addr1
, get_mem_index(s
));
3685 tcg_gen_addi_i64(o
->addr1
, o
->addr1
, 4);
3689 tcg_gen_qemu_st16(o
->in2
, o
->addr1
, get_mem_index(s
));
3692 tcg_gen_addi_i64(o
->addr1
, o
->addr1
, 2);
3696 tcg_gen_qemu_st8(o
->in2
, o
->addr1
, get_mem_index(s
));
3698 gen_op_movi_cc(s
, 0);
3702 /* But in general we'll defer to a helper. */
3703 o
->in2
= get_address(s
, 0, b2
, d2
);
3704 t32
= tcg_const_i32(l
);
3705 potential_page_fault(s
);
3706 gen_helper_xc(cc_op
, cpu_env
, t32
, o
->addr1
, o
->in2
);
3707 tcg_temp_free_i32(t32
);
3712 static ExitStatus
op_xor(DisasContext
*s
, DisasOps
*o
)
3714 tcg_gen_xor_i64(o
->out
, o
->in1
, o
->in2
);
3718 static ExitStatus
op_xori(DisasContext
*s
, DisasOps
*o
)
3720 int shift
= s
->insn
->data
& 0xff;
3721 int size
= s
->insn
->data
>> 8;
3722 uint64_t mask
= ((1ull << size
) - 1) << shift
;
3725 tcg_gen_shli_i64(o
->in2
, o
->in2
, shift
);
3726 tcg_gen_xor_i64(o
->out
, o
->in1
, o
->in2
);
3728 /* Produce the CC from only the bits manipulated. */
3729 tcg_gen_andi_i64(cc_dst
, o
->out
, mask
);
3730 set_cc_nz_u64(s
, cc_dst
);
3734 static ExitStatus
op_zero(DisasContext
*s
, DisasOps
*o
)
3736 o
->out
= tcg_const_i64(0);
3740 static ExitStatus
op_zero2(DisasContext
*s
, DisasOps
*o
)
3742 o
->out
= tcg_const_i64(0);
3748 /* ====================================================================== */
3749 /* The "Cc OUTput" generators. Given the generated output (and in some cases
3750 the original inputs), update the various cc data structures in order to
3751 be able to compute the new condition code. */
3753 static void cout_abs32(DisasContext
*s
, DisasOps
*o
)
3755 gen_op_update1_cc_i64(s
, CC_OP_ABS_32
, o
->out
);
3758 static void cout_abs64(DisasContext
*s
, DisasOps
*o
)
3760 gen_op_update1_cc_i64(s
, CC_OP_ABS_64
, o
->out
);
3763 static void cout_adds32(DisasContext
*s
, DisasOps
*o
)
3765 gen_op_update3_cc_i64(s
, CC_OP_ADD_32
, o
->in1
, o
->in2
, o
->out
);
3768 static void cout_adds64(DisasContext
*s
, DisasOps
*o
)
3770 gen_op_update3_cc_i64(s
, CC_OP_ADD_64
, o
->in1
, o
->in2
, o
->out
);
3773 static void cout_addu32(DisasContext
*s
, DisasOps
*o
)
3775 gen_op_update3_cc_i64(s
, CC_OP_ADDU_32
, o
->in1
, o
->in2
, o
->out
);
3778 static void cout_addu64(DisasContext
*s
, DisasOps
*o
)
3780 gen_op_update3_cc_i64(s
, CC_OP_ADDU_64
, o
->in1
, o
->in2
, o
->out
);
3783 static void cout_addc32(DisasContext
*s
, DisasOps
*o
)
3785 gen_op_update3_cc_i64(s
, CC_OP_ADDC_32
, o
->in1
, o
->in2
, o
->out
);
3788 static void cout_addc64(DisasContext
*s
, DisasOps
*o
)
3790 gen_op_update3_cc_i64(s
, CC_OP_ADDC_64
, o
->in1
, o
->in2
, o
->out
);
3793 static void cout_cmps32(DisasContext
*s
, DisasOps
*o
)
3795 gen_op_update2_cc_i64(s
, CC_OP_LTGT_32
, o
->in1
, o
->in2
);
3798 static void cout_cmps64(DisasContext
*s
, DisasOps
*o
)
3800 gen_op_update2_cc_i64(s
, CC_OP_LTGT_64
, o
->in1
, o
->in2
);
3803 static void cout_cmpu32(DisasContext
*s
, DisasOps
*o
)
3805 gen_op_update2_cc_i64(s
, CC_OP_LTUGTU_32
, o
->in1
, o
->in2
);
3808 static void cout_cmpu64(DisasContext
*s
, DisasOps
*o
)
3810 gen_op_update2_cc_i64(s
, CC_OP_LTUGTU_64
, o
->in1
, o
->in2
);
3813 static void cout_f32(DisasContext
*s
, DisasOps
*o
)
3815 gen_op_update1_cc_i64(s
, CC_OP_NZ_F32
, o
->out
);
3818 static void cout_f64(DisasContext
*s
, DisasOps
*o
)
3820 gen_op_update1_cc_i64(s
, CC_OP_NZ_F64
, o
->out
);
3823 static void cout_f128(DisasContext
*s
, DisasOps
*o
)
3825 gen_op_update2_cc_i64(s
, CC_OP_NZ_F128
, o
->out
, o
->out2
);
3828 static void cout_nabs32(DisasContext
*s
, DisasOps
*o
)
3830 gen_op_update1_cc_i64(s
, CC_OP_NABS_32
, o
->out
);
3833 static void cout_nabs64(DisasContext
*s
, DisasOps
*o
)
3835 gen_op_update1_cc_i64(s
, CC_OP_NABS_64
, o
->out
);
3838 static void cout_neg32(DisasContext
*s
, DisasOps
*o
)
3840 gen_op_update1_cc_i64(s
, CC_OP_COMP_32
, o
->out
);
3843 static void cout_neg64(DisasContext
*s
, DisasOps
*o
)
3845 gen_op_update1_cc_i64(s
, CC_OP_COMP_64
, o
->out
);
3848 static void cout_nz32(DisasContext
*s
, DisasOps
*o
)
3850 tcg_gen_ext32u_i64(cc_dst
, o
->out
);
3851 gen_op_update1_cc_i64(s
, CC_OP_NZ
, cc_dst
);
3854 static void cout_nz64(DisasContext
*s
, DisasOps
*o
)
3856 gen_op_update1_cc_i64(s
, CC_OP_NZ
, o
->out
);
3859 static void cout_s32(DisasContext
*s
, DisasOps
*o
)
3861 gen_op_update1_cc_i64(s
, CC_OP_LTGT0_32
, o
->out
);
3864 static void cout_s64(DisasContext
*s
, DisasOps
*o
)
3866 gen_op_update1_cc_i64(s
, CC_OP_LTGT0_64
, o
->out
);
3869 static void cout_subs32(DisasContext
*s
, DisasOps
*o
)
3871 gen_op_update3_cc_i64(s
, CC_OP_SUB_32
, o
->in1
, o
->in2
, o
->out
);
3874 static void cout_subs64(DisasContext
*s
, DisasOps
*o
)
3876 gen_op_update3_cc_i64(s
, CC_OP_SUB_64
, o
->in1
, o
->in2
, o
->out
);
3879 static void cout_subu32(DisasContext
*s
, DisasOps
*o
)
3881 gen_op_update3_cc_i64(s
, CC_OP_SUBU_32
, o
->in1
, o
->in2
, o
->out
);
3884 static void cout_subu64(DisasContext
*s
, DisasOps
*o
)
3886 gen_op_update3_cc_i64(s
, CC_OP_SUBU_64
, o
->in1
, o
->in2
, o
->out
);
3889 static void cout_subb32(DisasContext
*s
, DisasOps
*o
)
3891 gen_op_update3_cc_i64(s
, CC_OP_SUBB_32
, o
->in1
, o
->in2
, o
->out
);
3894 static void cout_subb64(DisasContext
*s
, DisasOps
*o
)
3896 gen_op_update3_cc_i64(s
, CC_OP_SUBB_64
, o
->in1
, o
->in2
, o
->out
);
3899 static void cout_tm32(DisasContext
*s
, DisasOps
*o
)
3901 gen_op_update2_cc_i64(s
, CC_OP_TM_32
, o
->in1
, o
->in2
);
3904 static void cout_tm64(DisasContext
*s
, DisasOps
*o
)
3906 gen_op_update2_cc_i64(s
, CC_OP_TM_64
, o
->in1
, o
->in2
);
3909 /* ====================================================================== */
3910 /* The "PREParation" generators. These initialize the DisasOps.OUT fields
3911 with the TCG register to which we will write. Used in combination with
3912 the "wout" generators, in some cases we need a new temporary, and in
3913 some cases we can write to a TCG global. */
3915 static void prep_new(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3917 o
->out
= tcg_temp_new_i64();
3919 #define SPEC_prep_new 0
3921 static void prep_new_P(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3923 o
->out
= tcg_temp_new_i64();
3924 o
->out2
= tcg_temp_new_i64();
3926 #define SPEC_prep_new_P 0
3928 static void prep_r1(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3930 o
->out
= regs
[get_field(f
, r1
)];
3933 #define SPEC_prep_r1 0
3935 static void prep_r1_P(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3937 int r1
= get_field(f
, r1
);
3939 o
->out2
= regs
[r1
+ 1];
3940 o
->g_out
= o
->g_out2
= true;
3942 #define SPEC_prep_r1_P SPEC_r1_even
3944 static void prep_f1(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3946 o
->out
= fregs
[get_field(f
, r1
)];
3949 #define SPEC_prep_f1 0
3951 static void prep_x1(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3953 int r1
= get_field(f
, r1
);
3955 o
->out2
= fregs
[r1
+ 2];
3956 o
->g_out
= o
->g_out2
= true;
3958 #define SPEC_prep_x1 SPEC_r1_f128
3960 /* ====================================================================== */
3961 /* The "Write OUTput" generators. These generally perform some non-trivial
3962 copy of data to TCG globals, or to main memory. The trivial cases are
3963 generally handled by having a "prep" generator install the TCG global
3964 as the destination of the operation. */
3966 static void wout_r1(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3968 store_reg(get_field(f
, r1
), o
->out
);
3970 #define SPEC_wout_r1 0
3972 static void wout_r1_8(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3974 int r1
= get_field(f
, r1
);
3975 tcg_gen_deposit_i64(regs
[r1
], regs
[r1
], o
->out
, 0, 8);
3977 #define SPEC_wout_r1_8 0
3979 static void wout_r1_16(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3981 int r1
= get_field(f
, r1
);
3982 tcg_gen_deposit_i64(regs
[r1
], regs
[r1
], o
->out
, 0, 16);
3984 #define SPEC_wout_r1_16 0
3986 static void wout_r1_32(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3988 store_reg32_i64(get_field(f
, r1
), o
->out
);
3990 #define SPEC_wout_r1_32 0
3992 static void wout_r1_P32(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3994 int r1
= get_field(f
, r1
);
3995 store_reg32_i64(r1
, o
->out
);
3996 store_reg32_i64(r1
+ 1, o
->out2
);
3998 #define SPEC_wout_r1_P32 SPEC_r1_even
4000 static void wout_r1_D32(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4002 int r1
= get_field(f
, r1
);
4003 store_reg32_i64(r1
+ 1, o
->out
);
4004 tcg_gen_shri_i64(o
->out
, o
->out
, 32);
4005 store_reg32_i64(r1
, o
->out
);
4007 #define SPEC_wout_r1_D32 SPEC_r1_even
4009 static void wout_e1(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4011 store_freg32_i64(get_field(f
, r1
), o
->out
);
4013 #define SPEC_wout_e1 0
4015 static void wout_f1(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4017 store_freg(get_field(f
, r1
), o
->out
);
4019 #define SPEC_wout_f1 0
4021 static void wout_x1(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4023 int f1
= get_field(s
->fields
, r1
);
4024 store_freg(f1
, o
->out
);
4025 store_freg(f1
+ 2, o
->out2
);
4027 #define SPEC_wout_x1 SPEC_r1_f128
4029 static void wout_cond_r1r2_32(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4031 if (get_field(f
, r1
) != get_field(f
, r2
)) {
4032 store_reg32_i64(get_field(f
, r1
), o
->out
);
4035 #define SPEC_wout_cond_r1r2_32 0
4037 static void wout_cond_e1e2(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4039 if (get_field(f
, r1
) != get_field(f
, r2
)) {
4040 store_freg32_i64(get_field(f
, r1
), o
->out
);
4043 #define SPEC_wout_cond_e1e2 0
4045 static void wout_m1_8(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4047 tcg_gen_qemu_st8(o
->out
, o
->addr1
, get_mem_index(s
));
4049 #define SPEC_wout_m1_8 0
4051 static void wout_m1_16(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4053 tcg_gen_qemu_st16(o
->out
, o
->addr1
, get_mem_index(s
));
4055 #define SPEC_wout_m1_16 0
4057 static void wout_m1_32(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4059 tcg_gen_qemu_st32(o
->out
, o
->addr1
, get_mem_index(s
));
4061 #define SPEC_wout_m1_32 0
4063 static void wout_m1_64(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4065 tcg_gen_qemu_st64(o
->out
, o
->addr1
, get_mem_index(s
));
4067 #define SPEC_wout_m1_64 0
4069 static void wout_m2_32(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4071 tcg_gen_qemu_st32(o
->out
, o
->in2
, get_mem_index(s
));
4073 #define SPEC_wout_m2_32 0
4075 static void wout_m2_32_r1_atomic(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4077 /* XXX release reservation */
4078 tcg_gen_qemu_st32(o
->out
, o
->addr1
, get_mem_index(s
));
4079 store_reg32_i64(get_field(f
, r1
), o
->in2
);
4081 #define SPEC_wout_m2_32_r1_atomic 0
4083 static void wout_m2_64_r1_atomic(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4085 /* XXX release reservation */
4086 tcg_gen_qemu_st64(o
->out
, o
->addr1
, get_mem_index(s
));
4087 store_reg(get_field(f
, r1
), o
->in2
);
4089 #define SPEC_wout_m2_64_r1_atomic 0
4091 /* ====================================================================== */
4092 /* The "INput 1" generators. These load the first operand to an insn. */
4094 static void in1_r1(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4096 o
->in1
= load_reg(get_field(f
, r1
));
4098 #define SPEC_in1_r1 0
4100 static void in1_r1_o(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4102 o
->in1
= regs
[get_field(f
, r1
)];
4105 #define SPEC_in1_r1_o 0
4107 static void in1_r1_32s(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4109 o
->in1
= tcg_temp_new_i64();
4110 tcg_gen_ext32s_i64(o
->in1
, regs
[get_field(f
, r1
)]);
4112 #define SPEC_in1_r1_32s 0
4114 static void in1_r1_32u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4116 o
->in1
= tcg_temp_new_i64();
4117 tcg_gen_ext32u_i64(o
->in1
, regs
[get_field(f
, r1
)]);
4119 #define SPEC_in1_r1_32u 0
4121 static void in1_r1_sr32(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4123 o
->in1
= tcg_temp_new_i64();
4124 tcg_gen_shri_i64(o
->in1
, regs
[get_field(f
, r1
)], 32);
4126 #define SPEC_in1_r1_sr32 0
4128 static void in1_r1p1(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4130 o
->in1
= load_reg(get_field(f
, r1
) + 1);
4132 #define SPEC_in1_r1p1 SPEC_r1_even
4134 static void in1_r1p1_32s(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4136 o
->in1
= tcg_temp_new_i64();
4137 tcg_gen_ext32s_i64(o
->in1
, regs
[get_field(f
, r1
) + 1]);
4139 #define SPEC_in1_r1p1_32s SPEC_r1_even
4141 static void in1_r1p1_32u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4143 o
->in1
= tcg_temp_new_i64();
4144 tcg_gen_ext32u_i64(o
->in1
, regs
[get_field(f
, r1
) + 1]);
4146 #define SPEC_in1_r1p1_32u SPEC_r1_even
4148 static void in1_r1_D32(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4150 int r1
= get_field(f
, r1
);
4151 o
->in1
= tcg_temp_new_i64();
4152 tcg_gen_concat32_i64(o
->in1
, regs
[r1
+ 1], regs
[r1
]);
4154 #define SPEC_in1_r1_D32 SPEC_r1_even
4156 static void in1_r2(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4158 o
->in1
= load_reg(get_field(f
, r2
));
4160 #define SPEC_in1_r2 0
4162 static void in1_r3(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4164 o
->in1
= load_reg(get_field(f
, r3
));
4166 #define SPEC_in1_r3 0
4168 static void in1_r3_o(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4170 o
->in1
= regs
[get_field(f
, r3
)];
4173 #define SPEC_in1_r3_o 0
4175 static void in1_r3_32s(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4177 o
->in1
= tcg_temp_new_i64();
4178 tcg_gen_ext32s_i64(o
->in1
, regs
[get_field(f
, r3
)]);
4180 #define SPEC_in1_r3_32s 0
4182 static void in1_r3_32u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4184 o
->in1
= tcg_temp_new_i64();
4185 tcg_gen_ext32u_i64(o
->in1
, regs
[get_field(f
, r3
)]);
4187 #define SPEC_in1_r3_32u 0
4189 static void in1_r3_D32(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4191 int r3
= get_field(f
, r3
);
4192 o
->in1
= tcg_temp_new_i64();
4193 tcg_gen_concat32_i64(o
->in1
, regs
[r3
+ 1], regs
[r3
]);
4195 #define SPEC_in1_r3_D32 SPEC_r3_even
4197 static void in1_e1(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4199 o
->in1
= load_freg32_i64(get_field(f
, r1
));
4201 #define SPEC_in1_e1 0
4203 static void in1_f1_o(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4205 o
->in1
= fregs
[get_field(f
, r1
)];
4208 #define SPEC_in1_f1_o 0
4210 static void in1_x1_o(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4212 int r1
= get_field(f
, r1
);
4214 o
->out2
= fregs
[r1
+ 2];
4215 o
->g_out
= o
->g_out2
= true;
4217 #define SPEC_in1_x1_o SPEC_r1_f128
4219 static void in1_f3_o(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4221 o
->in1
= fregs
[get_field(f
, r3
)];
4224 #define SPEC_in1_f3_o 0
4226 static void in1_la1(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4228 o
->addr1
= get_address(s
, 0, get_field(f
, b1
), get_field(f
, d1
));
4230 #define SPEC_in1_la1 0
4232 static void in1_la2(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4234 int x2
= have_field(f
, x2
) ? get_field(f
, x2
) : 0;
4235 o
->addr1
= get_address(s
, x2
, get_field(f
, b2
), get_field(f
, d2
));
4237 #define SPEC_in1_la2 0
4239 static void in1_m1_8u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4242 o
->in1
= tcg_temp_new_i64();
4243 tcg_gen_qemu_ld8u(o
->in1
, o
->addr1
, get_mem_index(s
));
4245 #define SPEC_in1_m1_8u 0
4247 static void in1_m1_16s(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4250 o
->in1
= tcg_temp_new_i64();
4251 tcg_gen_qemu_ld16s(o
->in1
, o
->addr1
, get_mem_index(s
));
4253 #define SPEC_in1_m1_16s 0
4255 static void in1_m1_16u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4258 o
->in1
= tcg_temp_new_i64();
4259 tcg_gen_qemu_ld16u(o
->in1
, o
->addr1
, get_mem_index(s
));
4261 #define SPEC_in1_m1_16u 0
4263 static void in1_m1_32s(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4266 o
->in1
= tcg_temp_new_i64();
4267 tcg_gen_qemu_ld32s(o
->in1
, o
->addr1
, get_mem_index(s
));
4269 #define SPEC_in1_m1_32s 0
4271 static void in1_m1_32u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4274 o
->in1
= tcg_temp_new_i64();
4275 tcg_gen_qemu_ld32u(o
->in1
, o
->addr1
, get_mem_index(s
));
4277 #define SPEC_in1_m1_32u 0
4279 static void in1_m1_64(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4282 o
->in1
= tcg_temp_new_i64();
4283 tcg_gen_qemu_ld64(o
->in1
, o
->addr1
, get_mem_index(s
));
4285 #define SPEC_in1_m1_64 0
4287 /* ====================================================================== */
4288 /* The "INput 2" generators. These load the second operand to an insn. */
4290 static void in2_r1_o(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4292 o
->in2
= regs
[get_field(f
, r1
)];
4295 #define SPEC_in2_r1_o 0
4297 static void in2_r1_16u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4299 o
->in2
= tcg_temp_new_i64();
4300 tcg_gen_ext16u_i64(o
->in2
, regs
[get_field(f
, r1
)]);
4302 #define SPEC_in2_r1_16u 0
4304 static void in2_r1_32u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4306 o
->in2
= tcg_temp_new_i64();
4307 tcg_gen_ext32u_i64(o
->in2
, regs
[get_field(f
, r1
)]);
4309 #define SPEC_in2_r1_32u 0
4311 static void in2_r1_D32(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4313 int r1
= get_field(f
, r1
);
4314 o
->in2
= tcg_temp_new_i64();
4315 tcg_gen_concat32_i64(o
->in2
, regs
[r1
+ 1], regs
[r1
]);
4317 #define SPEC_in2_r1_D32 SPEC_r1_even
4319 static void in2_r2(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4321 o
->in2
= load_reg(get_field(f
, r2
));
4323 #define SPEC_in2_r2 0
4325 static void in2_r2_o(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4327 o
->in2
= regs
[get_field(f
, r2
)];
4330 #define SPEC_in2_r2_o 0
4332 static void in2_r2_nz(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4334 int r2
= get_field(f
, r2
);
4336 o
->in2
= load_reg(r2
);
4339 #define SPEC_in2_r2_nz 0
4341 static void in2_r2_8s(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4343 o
->in2
= tcg_temp_new_i64();
4344 tcg_gen_ext8s_i64(o
->in2
, regs
[get_field(f
, r2
)]);
4346 #define SPEC_in2_r2_8s 0
4348 static void in2_r2_8u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4350 o
->in2
= tcg_temp_new_i64();
4351 tcg_gen_ext8u_i64(o
->in2
, regs
[get_field(f
, r2
)]);
4353 #define SPEC_in2_r2_8u 0
4355 static void in2_r2_16s(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4357 o
->in2
= tcg_temp_new_i64();
4358 tcg_gen_ext16s_i64(o
->in2
, regs
[get_field(f
, r2
)]);
4360 #define SPEC_in2_r2_16s 0
4362 static void in2_r2_16u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4364 o
->in2
= tcg_temp_new_i64();
4365 tcg_gen_ext16u_i64(o
->in2
, regs
[get_field(f
, r2
)]);
4367 #define SPEC_in2_r2_16u 0
4369 static void in2_r3(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4371 o
->in2
= load_reg(get_field(f
, r3
));
4373 #define SPEC_in2_r3 0
4375 static void in2_r2_32s(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4377 o
->in2
= tcg_temp_new_i64();
4378 tcg_gen_ext32s_i64(o
->in2
, regs
[get_field(f
, r2
)]);
4380 #define SPEC_in2_r2_32s 0
4382 static void in2_r2_32u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4384 o
->in2
= tcg_temp_new_i64();
4385 tcg_gen_ext32u_i64(o
->in2
, regs
[get_field(f
, r2
)]);
4387 #define SPEC_in2_r2_32u 0
4389 static void in2_e2(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4391 o
->in2
= load_freg32_i64(get_field(f
, r2
));
4393 #define SPEC_in2_e2 0
4395 static void in2_f2_o(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4397 o
->in2
= fregs
[get_field(f
, r2
)];
4400 #define SPEC_in2_f2_o 0
4402 static void in2_x2_o(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4404 int r2
= get_field(f
, r2
);
4406 o
->in2
= fregs
[r2
+ 2];
4407 o
->g_in1
= o
->g_in2
= true;
4409 #define SPEC_in2_x2_o SPEC_r2_f128
4411 static void in2_ra2(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4413 o
->in2
= get_address(s
, 0, get_field(f
, r2
), 0);
4415 #define SPEC_in2_ra2 0
4417 static void in2_a2(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4419 int x2
= have_field(f
, x2
) ? get_field(f
, x2
) : 0;
4420 o
->in2
= get_address(s
, x2
, get_field(f
, b2
), get_field(f
, d2
));
4422 #define SPEC_in2_a2 0
4424 static void in2_ri2(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4426 o
->in2
= tcg_const_i64(s
->pc
+ (int64_t)get_field(f
, i2
) * 2);
4428 #define SPEC_in2_ri2 0
4430 static void in2_sh32(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4432 help_l2_shift(s
, f
, o
, 31);
4434 #define SPEC_in2_sh32 0
4436 static void in2_sh64(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4438 help_l2_shift(s
, f
, o
, 63);
4440 #define SPEC_in2_sh64 0
4442 static void in2_m2_8u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4445 tcg_gen_qemu_ld8u(o
->in2
, o
->in2
, get_mem_index(s
));
4447 #define SPEC_in2_m2_8u 0
4449 static void in2_m2_16s(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4452 tcg_gen_qemu_ld16s(o
->in2
, o
->in2
, get_mem_index(s
));
4454 #define SPEC_in2_m2_16s 0
4456 static void in2_m2_16u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4459 tcg_gen_qemu_ld16u(o
->in2
, o
->in2
, get_mem_index(s
));
4461 #define SPEC_in2_m2_16u 0
4463 static void in2_m2_32s(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4466 tcg_gen_qemu_ld32s(o
->in2
, o
->in2
, get_mem_index(s
));
4468 #define SPEC_in2_m2_32s 0
4470 static void in2_m2_32u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4473 tcg_gen_qemu_ld32u(o
->in2
, o
->in2
, get_mem_index(s
));
4475 #define SPEC_in2_m2_32u 0
4477 static void in2_m2_64(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4480 tcg_gen_qemu_ld64(o
->in2
, o
->in2
, get_mem_index(s
));
4482 #define SPEC_in2_m2_64 0
4484 static void in2_mri2_16u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4487 tcg_gen_qemu_ld16u(o
->in2
, o
->in2
, get_mem_index(s
));
4489 #define SPEC_in2_mri2_16u 0
4491 static void in2_mri2_32s(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4494 tcg_gen_qemu_ld32s(o
->in2
, o
->in2
, get_mem_index(s
));
4496 #define SPEC_in2_mri2_32s 0
4498 static void in2_mri2_32u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4501 tcg_gen_qemu_ld32u(o
->in2
, o
->in2
, get_mem_index(s
));
4503 #define SPEC_in2_mri2_32u 0
4505 static void in2_mri2_64(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4508 tcg_gen_qemu_ld64(o
->in2
, o
->in2
, get_mem_index(s
));
4510 #define SPEC_in2_mri2_64 0
4512 static void in2_m2_32s_atomic(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4514 /* XXX should reserve the address */
4516 o
->in2
= tcg_temp_new_i64();
4517 tcg_gen_qemu_ld32s(o
->in2
, o
->addr1
, get_mem_index(s
));
4519 #define SPEC_in2_m2_32s_atomic 0
4521 static void in2_m2_64_atomic(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4523 /* XXX should reserve the address */
4525 o
->in2
= tcg_temp_new_i64();
4526 tcg_gen_qemu_ld64(o
->in2
, o
->addr1
, get_mem_index(s
));
4528 #define SPEC_in2_m2_64_atomic 0
4530 static void in2_i2(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4532 o
->in2
= tcg_const_i64(get_field(f
, i2
));
4534 #define SPEC_in2_i2 0
4536 static void in2_i2_8u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4538 o
->in2
= tcg_const_i64((uint8_t)get_field(f
, i2
));
4540 #define SPEC_in2_i2_8u 0
4542 static void in2_i2_16u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4544 o
->in2
= tcg_const_i64((uint16_t)get_field(f
, i2
));
4546 #define SPEC_in2_i2_16u 0
4548 static void in2_i2_32u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4550 o
->in2
= tcg_const_i64((uint32_t)get_field(f
, i2
));
4552 #define SPEC_in2_i2_32u 0
4554 static void in2_i2_16u_shl(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4556 uint64_t i2
= (uint16_t)get_field(f
, i2
);
4557 o
->in2
= tcg_const_i64(i2
<< s
->insn
->data
);
4559 #define SPEC_in2_i2_16u_shl 0
4561 static void in2_i2_32u_shl(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
4563 uint64_t i2
= (uint32_t)get_field(f
, i2
);
4564 o
->in2
= tcg_const_i64(i2
<< s
->insn
->data
);
4566 #define SPEC_in2_i2_32u_shl 0
4568 /* ====================================================================== */
4570 /* Find opc within the table of insns. This is formulated as a switch
4571 statement so that (1) we get compile-time notice of cut-paste errors
4572 for duplicated opcodes, and (2) the compiler generates the binary
4573 search tree, rather than us having to post-process the table. */
4575 #define C(OPC, NM, FT, FC, I1, I2, P, W, OP, CC) \
4576 D(OPC, NM, FT, FC, I1, I2, P, W, OP, CC, 0)
4578 #define D(OPC, NM, FT, FC, I1, I2, P, W, OP, CC, D) insn_ ## NM,
4580 enum DisasInsnEnum
{
4581 #include "insn-data.def"
4585 #define D(OPC, NM, FT, FC, I1, I2, P, W, OP, CC, D) { \
4589 .spec = SPEC_in1_##I1 | SPEC_in2_##I2 | SPEC_prep_##P | SPEC_wout_##W, \
4591 .help_in1 = in1_##I1, \
4592 .help_in2 = in2_##I2, \
4593 .help_prep = prep_##P, \
4594 .help_wout = wout_##W, \
4595 .help_cout = cout_##CC, \
4596 .help_op = op_##OP, \
4600 /* Allow 0 to be used for NULL in the table below. */
4608 #define SPEC_in1_0 0
4609 #define SPEC_in2_0 0
4610 #define SPEC_prep_0 0
4611 #define SPEC_wout_0 0
4613 static const DisasInsn insn_info
[] = {
4614 #include "insn-data.def"
4618 #define D(OPC, NM, FT, FC, I1, I2, P, W, OP, CC, D) \
4619 case OPC: return &insn_info[insn_ ## NM];
4621 static const DisasInsn
*lookup_opc(uint16_t opc
)
4624 #include "insn-data.def"
4633 /* Extract a field from the insn. The INSN should be left-aligned in
4634 the uint64_t so that we can more easily utilize the big-bit-endian
4635 definitions we extract from the Principals of Operation. */
4637 static void extract_field(DisasFields
*o
, const DisasField
*f
, uint64_t insn
)
4645 /* Zero extract the field from the insn. */
4646 r
= (insn
<< f
->beg
) >> (64 - f
->size
);
4648 /* Sign-extend, or un-swap the field as necessary. */
4650 case 0: /* unsigned */
4652 case 1: /* signed */
4653 assert(f
->size
<= 32);
4654 m
= 1u << (f
->size
- 1);
4657 case 2: /* dl+dh split, signed 20 bit. */
4658 r
= ((int8_t)r
<< 12) | (r
>> 8);
4664 /* Validate that the "compressed" encoding we selected above is valid.
4665 I.e. we havn't make two different original fields overlap. */
4666 assert(((o
->presentC
>> f
->indexC
) & 1) == 0);
4667 o
->presentC
|= 1 << f
->indexC
;
4668 o
->presentO
|= 1 << f
->indexO
;
4670 o
->c
[f
->indexC
] = r
;
4673 /* Lookup the insn at the current PC, extracting the operands into O and
4674 returning the info struct for the insn. Returns NULL for invalid insn. */
4676 static const DisasInsn
*extract_insn(CPUS390XState
*env
, DisasContext
*s
,
4679 uint64_t insn
, pc
= s
->pc
;
4681 const DisasInsn
*info
;
4683 insn
= ld_code2(env
, pc
);
4684 op
= (insn
>> 8) & 0xff;
4685 ilen
= get_ilen(op
);
4686 s
->next_pc
= s
->pc
+ ilen
;
4693 insn
= ld_code4(env
, pc
) << 32;
4696 insn
= (insn
<< 48) | (ld_code4(env
, pc
+ 2) << 16);
4702 /* We can't actually determine the insn format until we've looked up
4703 the full insn opcode. Which we can't do without locating the
4704 secondary opcode. Assume by default that OP2 is at bit 40; for
4705 those smaller insns that don't actually have a secondary opcode
4706 this will correctly result in OP2 = 0. */
4712 case 0xb2: /* S, RRF, RRE */
4713 case 0xb3: /* RRE, RRD, RRF */
4714 case 0xb9: /* RRE, RRF */
4715 case 0xe5: /* SSE, SIL */
4716 op2
= (insn
<< 8) >> 56;
4720 case 0xc0: /* RIL */
4721 case 0xc2: /* RIL */
4722 case 0xc4: /* RIL */
4723 case 0xc6: /* RIL */
4724 case 0xc8: /* SSF */
4725 case 0xcc: /* RIL */
4726 op2
= (insn
<< 12) >> 60;
4728 case 0xd0 ... 0xdf: /* SS */
4734 case 0xee ... 0xf3: /* SS */
4735 case 0xf8 ... 0xfd: /* SS */
4739 op2
= (insn
<< 40) >> 56;
4743 memset(f
, 0, sizeof(*f
));
4747 /* Lookup the instruction. */
4748 info
= lookup_opc(op
<< 8 | op2
);
4750 /* If we found it, extract the operands. */
4752 DisasFormat fmt
= info
->fmt
;
4755 for (i
= 0; i
< NUM_C_FIELD
; ++i
) {
4756 extract_field(f
, &format_info
[fmt
].op
[i
], insn
);
4762 static ExitStatus
translate_one(CPUS390XState
*env
, DisasContext
*s
)
4764 const DisasInsn
*insn
;
4765 ExitStatus ret
= NO_EXIT
;
4769 /* Search for the insn in the table. */
4770 insn
= extract_insn(env
, s
, &f
);
4772 /* Not found means unimplemented/illegal opcode. */
4774 qemu_log_mask(LOG_UNIMP
, "unimplemented opcode 0x%02x%02x\n",
4776 gen_illegal_opcode(s
);
4777 return EXIT_NORETURN
;
4780 /* Check for insn specification exceptions. */
4782 int spec
= insn
->spec
, excp
= 0, r
;
4784 if (spec
& SPEC_r1_even
) {
4785 r
= get_field(&f
, r1
);
4787 excp
= PGM_SPECIFICATION
;
4790 if (spec
& SPEC_r2_even
) {
4791 r
= get_field(&f
, r2
);
4793 excp
= PGM_SPECIFICATION
;
4796 if (spec
& SPEC_r3_even
) {
4797 r
= get_field(&f
, r3
);
4799 excp
= PGM_SPECIFICATION
;
4802 if (spec
& SPEC_r1_f128
) {
4803 r
= get_field(&f
, r1
);
4805 excp
= PGM_SPECIFICATION
;
4808 if (spec
& SPEC_r2_f128
) {
4809 r
= get_field(&f
, r2
);
4811 excp
= PGM_SPECIFICATION
;
4815 gen_program_exception(s
, excp
);
4816 return EXIT_NORETURN
;
4820 /* Set up the strutures we use to communicate with the helpers. */
4823 o
.g_out
= o
.g_out2
= o
.g_in1
= o
.g_in2
= false;
4824 TCGV_UNUSED_I64(o
.out
);
4825 TCGV_UNUSED_I64(o
.out2
);
4826 TCGV_UNUSED_I64(o
.in1
);
4827 TCGV_UNUSED_I64(o
.in2
);
4828 TCGV_UNUSED_I64(o
.addr1
);
4830 /* Implement the instruction. */
4831 if (insn
->help_in1
) {
4832 insn
->help_in1(s
, &f
, &o
);
4834 if (insn
->help_in2
) {
4835 insn
->help_in2(s
, &f
, &o
);
4837 if (insn
->help_prep
) {
4838 insn
->help_prep(s
, &f
, &o
);
4840 if (insn
->help_op
) {
4841 ret
= insn
->help_op(s
, &o
);
4843 if (insn
->help_wout
) {
4844 insn
->help_wout(s
, &f
, &o
);
4846 if (insn
->help_cout
) {
4847 insn
->help_cout(s
, &o
);
4850 /* Free any temporaries created by the helpers. */
4851 if (!TCGV_IS_UNUSED_I64(o
.out
) && !o
.g_out
) {
4852 tcg_temp_free_i64(o
.out
);
4854 if (!TCGV_IS_UNUSED_I64(o
.out2
) && !o
.g_out2
) {
4855 tcg_temp_free_i64(o
.out2
);
4857 if (!TCGV_IS_UNUSED_I64(o
.in1
) && !o
.g_in1
) {
4858 tcg_temp_free_i64(o
.in1
);
4860 if (!TCGV_IS_UNUSED_I64(o
.in2
) && !o
.g_in2
) {
4861 tcg_temp_free_i64(o
.in2
);
4863 if (!TCGV_IS_UNUSED_I64(o
.addr1
)) {
4864 tcg_temp_free_i64(o
.addr1
);
4867 /* Advance to the next instruction. */
4872 static inline void gen_intermediate_code_internal(S390CPU
*cpu
,
4873 TranslationBlock
*tb
,
4876 CPUState
*cs
= CPU(cpu
);
4877 CPUS390XState
*env
= &cpu
->env
;
4879 target_ulong pc_start
;
4880 uint64_t next_page_start
;
4882 int num_insns
, max_insns
;
4890 if (!(tb
->flags
& FLAG_MASK_64
)) {
4891 pc_start
&= 0x7fffffff;
4896 dc
.cc_op
= CC_OP_DYNAMIC
;
4897 do_debug
= dc
.singlestep_enabled
= cs
->singlestep_enabled
;
4899 next_page_start
= (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
4902 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
4903 if (max_insns
== 0) {
4904 max_insns
= CF_COUNT_MASK
;
4911 j
= tcg_op_buf_count();
4915 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
4918 tcg_ctx
.gen_opc_pc
[lj
] = dc
.pc
;
4919 gen_opc_cc_op
[lj
] = dc
.cc_op
;
4920 tcg_ctx
.gen_opc_instr_start
[lj
] = 1;
4921 tcg_ctx
.gen_opc_icount
[lj
] = num_insns
;
4923 if (++num_insns
== max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
4927 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
4928 tcg_gen_debug_insn_start(dc
.pc
);
4932 if (unlikely(!QTAILQ_EMPTY(&cs
->breakpoints
))) {
4933 QTAILQ_FOREACH(bp
, &cs
->breakpoints
, entry
) {
4934 if (bp
->pc
== dc
.pc
) {
4935 status
= EXIT_PC_STALE
;
4941 if (status
== NO_EXIT
) {
4942 status
= translate_one(env
, &dc
);
4945 /* If we reach a page boundary, are single stepping,
4946 or exhaust instruction count, stop generation. */
4947 if (status
== NO_EXIT
4948 && (dc
.pc
>= next_page_start
4949 || tcg_op_buf_full()
4950 || num_insns
>= max_insns
4952 || cs
->singlestep_enabled
)) {
4953 status
= EXIT_PC_STALE
;
4955 } while (status
== NO_EXIT
);
4957 if (tb
->cflags
& CF_LAST_IO
) {
4966 update_psw_addr(&dc
);
4968 case EXIT_PC_UPDATED
:
4969 /* Next TB starts off with CC_OP_DYNAMIC, so make sure the
4970 cc op type is in env */
4972 /* Exit the TB, either by raising a debug exception or by return. */
4974 gen_exception(EXCP_DEBUG
);
4983 gen_tb_end(tb
, num_insns
);
4986 j
= tcg_op_buf_count();
4989 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
4992 tb
->size
= dc
.pc
- pc_start
;
4993 tb
->icount
= num_insns
;
4996 #if defined(S390X_DEBUG_DISAS)
4997 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
4998 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
4999 log_target_disas(env
, pc_start
, dc
.pc
- pc_start
, 1);
5005 void gen_intermediate_code (CPUS390XState
*env
, struct TranslationBlock
*tb
)
5007 gen_intermediate_code_internal(s390_env_get_cpu(env
), tb
, false);
5010 void gen_intermediate_code_pc (CPUS390XState
*env
, struct TranslationBlock
*tb
)
5012 gen_intermediate_code_internal(s390_env_get_cpu(env
), tb
, true);
5015 void restore_state_to_opc(CPUS390XState
*env
, TranslationBlock
*tb
, int pc_pos
)
5018 env
->psw
.addr
= tcg_ctx
.gen_opc_pc
[pc_pos
];
5019 cc_op
= gen_opc_cc_op
[pc_pos
];
5020 if ((cc_op
!= CC_OP_DYNAMIC
) && (cc_op
!= CC_OP_STATIC
)) {