4 * Copyright (c) 2009 Ulrich Hecht
5 * Copyright (c) 2010 Alexander Graf
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
21 /* #define DEBUG_INLINE_BRANCHES */
22 #define S390X_DEBUG_DISAS
23 /* #define S390X_DEBUG_DISAS_VERBOSE */
25 #ifdef S390X_DEBUG_DISAS_VERBOSE
26 # define LOG_DISAS(...) qemu_log(__VA_ARGS__)
28 # define LOG_DISAS(...) do { } while (0)
32 #include "disas/disas.h"
35 #include "qemu/host-utils.h"
37 /* global register indexes */
38 static TCGv_ptr cpu_env
;
40 #include "exec/gen-icount.h"
46 /* Information that (most) every instruction needs to manipulate. */
47 typedef struct DisasContext DisasContext
;
48 typedef struct DisasInsn DisasInsn
;
49 typedef struct DisasFields DisasFields
;
52 struct TranslationBlock
*tb
;
53 const DisasInsn
*insn
;
57 bool singlestep_enabled
;
61 /* Information carried about a condition to be evaluated. */
68 struct { TCGv_i64 a
, b
; } s64
;
69 struct { TCGv_i32 a
, b
; } s32
;
75 static void gen_op_calc_cc(DisasContext
*s
);
77 #ifdef DEBUG_INLINE_BRANCHES
78 static uint64_t inline_branch_hit
[CC_OP_MAX
];
79 static uint64_t inline_branch_miss
[CC_OP_MAX
];
82 static inline void debug_insn(uint64_t insn
)
84 LOG_DISAS("insn: 0x%" PRIx64
"\n", insn
);
87 static inline uint64_t pc_to_link_info(DisasContext
*s
, uint64_t pc
)
89 if (!(s
->tb
->flags
& FLAG_MASK_64
)) {
90 if (s
->tb
->flags
& FLAG_MASK_32
) {
91 return pc
| 0x80000000;
97 void cpu_dump_state(CPUS390XState
*env
, FILE *f
, fprintf_function cpu_fprintf
,
102 if (env
->cc_op
> 3) {
103 cpu_fprintf(f
, "PSW=mask %016" PRIx64
" addr %016" PRIx64
" cc %15s\n",
104 env
->psw
.mask
, env
->psw
.addr
, cc_name(env
->cc_op
));
106 cpu_fprintf(f
, "PSW=mask %016" PRIx64
" addr %016" PRIx64
" cc %02x\n",
107 env
->psw
.mask
, env
->psw
.addr
, env
->cc_op
);
110 for (i
= 0; i
< 16; i
++) {
111 cpu_fprintf(f
, "R%02d=%016" PRIx64
, i
, env
->regs
[i
]);
113 cpu_fprintf(f
, "\n");
119 for (i
= 0; i
< 16; i
++) {
120 cpu_fprintf(f
, "F%02d=%016" PRIx64
, i
, env
->fregs
[i
].ll
);
122 cpu_fprintf(f
, "\n");
128 #ifndef CONFIG_USER_ONLY
129 for (i
= 0; i
< 16; i
++) {
130 cpu_fprintf(f
, "C%02d=%016" PRIx64
, i
, env
->cregs
[i
]);
132 cpu_fprintf(f
, "\n");
139 #ifdef DEBUG_INLINE_BRANCHES
140 for (i
= 0; i
< CC_OP_MAX
; i
++) {
141 cpu_fprintf(f
, " %15s = %10ld\t%10ld\n", cc_name(i
),
142 inline_branch_miss
[i
], inline_branch_hit
[i
]);
146 cpu_fprintf(f
, "\n");
149 static TCGv_i64 psw_addr
;
150 static TCGv_i64 psw_mask
;
152 static TCGv_i32 cc_op
;
153 static TCGv_i64 cc_src
;
154 static TCGv_i64 cc_dst
;
155 static TCGv_i64 cc_vr
;
157 static char cpu_reg_names
[32][4];
158 static TCGv_i64 regs
[16];
159 static TCGv_i64 fregs
[16];
161 static uint8_t gen_opc_cc_op
[OPC_BUF_SIZE
];
163 void s390x_translate_init(void)
167 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
168 psw_addr
= tcg_global_mem_new_i64(TCG_AREG0
,
169 offsetof(CPUS390XState
, psw
.addr
),
171 psw_mask
= tcg_global_mem_new_i64(TCG_AREG0
,
172 offsetof(CPUS390XState
, psw
.mask
),
175 cc_op
= tcg_global_mem_new_i32(TCG_AREG0
, offsetof(CPUS390XState
, cc_op
),
177 cc_src
= tcg_global_mem_new_i64(TCG_AREG0
, offsetof(CPUS390XState
, cc_src
),
179 cc_dst
= tcg_global_mem_new_i64(TCG_AREG0
, offsetof(CPUS390XState
, cc_dst
),
181 cc_vr
= tcg_global_mem_new_i64(TCG_AREG0
, offsetof(CPUS390XState
, cc_vr
),
184 for (i
= 0; i
< 16; i
++) {
185 snprintf(cpu_reg_names
[i
], sizeof(cpu_reg_names
[0]), "r%d", i
);
186 regs
[i
] = tcg_global_mem_new(TCG_AREG0
,
187 offsetof(CPUS390XState
, regs
[i
]),
191 for (i
= 0; i
< 16; i
++) {
192 snprintf(cpu_reg_names
[i
+ 16], sizeof(cpu_reg_names
[0]), "f%d", i
);
193 fregs
[i
] = tcg_global_mem_new(TCG_AREG0
,
194 offsetof(CPUS390XState
, fregs
[i
].d
),
195 cpu_reg_names
[i
+ 16]);
198 /* register helpers */
203 static inline TCGv_i64
load_reg(int reg
)
205 TCGv_i64 r
= tcg_temp_new_i64();
206 tcg_gen_mov_i64(r
, regs
[reg
]);
210 static inline TCGv_i64
load_freg(int reg
)
212 TCGv_i64 r
= tcg_temp_new_i64();
213 tcg_gen_mov_i64(r
, fregs
[reg
]);
217 static inline TCGv_i32
load_freg32(int reg
)
219 TCGv_i32 r
= tcg_temp_new_i32();
220 #if HOST_LONG_BITS == 32
221 tcg_gen_mov_i32(r
, TCGV_HIGH(fregs
[reg
]));
223 tcg_gen_shri_i64(MAKE_TCGV_I64(GET_TCGV_I32(r
)), fregs
[reg
], 32);
228 static inline TCGv_i64
load_freg32_i64(int reg
)
230 TCGv_i64 r
= tcg_temp_new_i64();
231 tcg_gen_shri_i64(r
, fregs
[reg
], 32);
235 static inline TCGv_i32
load_reg32(int reg
)
237 TCGv_i32 r
= tcg_temp_new_i32();
238 tcg_gen_trunc_i64_i32(r
, regs
[reg
]);
242 static inline TCGv_i64
load_reg32_i64(int reg
)
244 TCGv_i64 r
= tcg_temp_new_i64();
245 tcg_gen_ext32s_i64(r
, regs
[reg
]);
249 static inline void store_reg(int reg
, TCGv_i64 v
)
251 tcg_gen_mov_i64(regs
[reg
], v
);
254 static inline void store_freg(int reg
, TCGv_i64 v
)
256 tcg_gen_mov_i64(fregs
[reg
], v
);
259 static inline void store_reg32(int reg
, TCGv_i32 v
)
261 /* 32 bit register writes keep the upper half */
262 #if HOST_LONG_BITS == 32
263 tcg_gen_mov_i32(TCGV_LOW(regs
[reg
]), v
);
265 tcg_gen_deposit_i64(regs
[reg
], regs
[reg
],
266 MAKE_TCGV_I64(GET_TCGV_I32(v
)), 0, 32);
270 static inline void store_reg32_i64(int reg
, TCGv_i64 v
)
272 /* 32 bit register writes keep the upper half */
273 tcg_gen_deposit_i64(regs
[reg
], regs
[reg
], v
, 0, 32);
276 static inline void store_reg32h_i64(int reg
, TCGv_i64 v
)
278 tcg_gen_deposit_i64(regs
[reg
], regs
[reg
], v
, 32, 32);
281 static inline void store_freg32(int reg
, TCGv_i32 v
)
283 /* 32 bit register writes keep the lower half */
284 #if HOST_LONG_BITS == 32
285 tcg_gen_mov_i32(TCGV_HIGH(fregs
[reg
]), v
);
287 tcg_gen_deposit_i64(fregs
[reg
], fregs
[reg
],
288 MAKE_TCGV_I64(GET_TCGV_I32(v
)), 32, 32);
292 static inline void store_freg32_i64(int reg
, TCGv_i64 v
)
294 tcg_gen_deposit_i64(fregs
[reg
], fregs
[reg
], v
, 32, 32);
297 static inline void return_low128(TCGv_i64 dest
)
299 tcg_gen_ld_i64(dest
, cpu_env
, offsetof(CPUS390XState
, retxl
));
302 static inline void update_psw_addr(DisasContext
*s
)
305 tcg_gen_movi_i64(psw_addr
, s
->pc
);
308 static inline void potential_page_fault(DisasContext
*s
)
310 #ifndef CONFIG_USER_ONLY
316 static inline uint64_t ld_code2(CPUS390XState
*env
, uint64_t pc
)
318 return (uint64_t)cpu_lduw_code(env
, pc
);
321 static inline uint64_t ld_code4(CPUS390XState
*env
, uint64_t pc
)
323 return (uint64_t)(uint32_t)cpu_ldl_code(env
, pc
);
326 static inline uint64_t ld_code6(CPUS390XState
*env
, uint64_t pc
)
328 return (ld_code2(env
, pc
) << 32) | ld_code4(env
, pc
+ 2);
331 static inline int get_mem_index(DisasContext
*s
)
333 switch (s
->tb
->flags
& FLAG_MASK_ASC
) {
334 case PSW_ASC_PRIMARY
>> 32:
336 case PSW_ASC_SECONDARY
>> 32:
338 case PSW_ASC_HOME
>> 32:
346 static void gen_exception(int excp
)
348 TCGv_i32 tmp
= tcg_const_i32(excp
);
349 gen_helper_exception(cpu_env
, tmp
);
350 tcg_temp_free_i32(tmp
);
353 static void gen_program_exception(DisasContext
*s
, int code
)
357 /* Remember what pgm exeption this was. */
358 tmp
= tcg_const_i32(code
);
359 tcg_gen_st_i32(tmp
, cpu_env
, offsetof(CPUS390XState
, int_pgm_code
));
360 tcg_temp_free_i32(tmp
);
362 tmp
= tcg_const_i32(s
->next_pc
- s
->pc
);
363 tcg_gen_st_i32(tmp
, cpu_env
, offsetof(CPUS390XState
, int_pgm_ilen
));
364 tcg_temp_free_i32(tmp
);
366 /* Advance past instruction. */
373 /* Trigger exception. */
374 gen_exception(EXCP_PGM
);
377 s
->is_jmp
= DISAS_EXCP
;
380 static inline void gen_illegal_opcode(DisasContext
*s
)
382 gen_program_exception(s
, PGM_SPECIFICATION
);
385 static inline void check_privileged(DisasContext
*s
)
387 if (s
->tb
->flags
& (PSW_MASK_PSTATE
>> 32)) {
388 gen_program_exception(s
, PGM_PRIVILEGED
);
392 static TCGv_i64
get_address(DisasContext
*s
, int x2
, int b2
, int d2
)
396 /* 31-bitify the immediate part; register contents are dealt with below */
397 if (!(s
->tb
->flags
& FLAG_MASK_64
)) {
403 tmp
= tcg_const_i64(d2
);
404 tcg_gen_add_i64(tmp
, tmp
, regs
[x2
]);
409 tcg_gen_add_i64(tmp
, tmp
, regs
[b2
]);
413 tmp
= tcg_const_i64(d2
);
414 tcg_gen_add_i64(tmp
, tmp
, regs
[b2
]);
419 tmp
= tcg_const_i64(d2
);
422 /* 31-bit mode mask if there are values loaded from registers */
423 if (!(s
->tb
->flags
& FLAG_MASK_64
) && (x2
|| b2
)) {
424 tcg_gen_andi_i64(tmp
, tmp
, 0x7fffffffUL
);
430 static void gen_op_movi_cc(DisasContext
*s
, uint32_t val
)
432 s
->cc_op
= CC_OP_CONST0
+ val
;
435 static void gen_op_update1_cc_i64(DisasContext
*s
, enum cc_op op
, TCGv_i64 dst
)
437 tcg_gen_discard_i64(cc_src
);
438 tcg_gen_mov_i64(cc_dst
, dst
);
439 tcg_gen_discard_i64(cc_vr
);
443 static void gen_op_update1_cc_i32(DisasContext
*s
, enum cc_op op
, TCGv_i32 dst
)
445 tcg_gen_discard_i64(cc_src
);
446 tcg_gen_extu_i32_i64(cc_dst
, dst
);
447 tcg_gen_discard_i64(cc_vr
);
451 static void gen_op_update2_cc_i64(DisasContext
*s
, enum cc_op op
, TCGv_i64 src
,
454 tcg_gen_mov_i64(cc_src
, src
);
455 tcg_gen_mov_i64(cc_dst
, dst
);
456 tcg_gen_discard_i64(cc_vr
);
460 static void gen_op_update2_cc_i32(DisasContext
*s
, enum cc_op op
, TCGv_i32 src
,
463 tcg_gen_extu_i32_i64(cc_src
, src
);
464 tcg_gen_extu_i32_i64(cc_dst
, dst
);
465 tcg_gen_discard_i64(cc_vr
);
469 static void gen_op_update3_cc_i64(DisasContext
*s
, enum cc_op op
, TCGv_i64 src
,
470 TCGv_i64 dst
, TCGv_i64 vr
)
472 tcg_gen_mov_i64(cc_src
, src
);
473 tcg_gen_mov_i64(cc_dst
, dst
);
474 tcg_gen_mov_i64(cc_vr
, vr
);
478 static inline void set_cc_nz_u32(DisasContext
*s
, TCGv_i32 val
)
480 gen_op_update1_cc_i32(s
, CC_OP_NZ
, val
);
483 static inline void set_cc_nz_u64(DisasContext
*s
, TCGv_i64 val
)
485 gen_op_update1_cc_i64(s
, CC_OP_NZ
, val
);
488 static inline void cmp_32(DisasContext
*s
, TCGv_i32 v1
, TCGv_i32 v2
,
491 gen_op_update2_cc_i32(s
, cond
, v1
, v2
);
494 static inline void cmp_64(DisasContext
*s
, TCGv_i64 v1
, TCGv_i64 v2
,
497 gen_op_update2_cc_i64(s
, cond
, v1
, v2
);
500 static inline void cmp_s32(DisasContext
*s
, TCGv_i32 v1
, TCGv_i32 v2
)
502 cmp_32(s
, v1
, v2
, CC_OP_LTGT_32
);
505 static inline void cmp_u32(DisasContext
*s
, TCGv_i32 v1
, TCGv_i32 v2
)
507 cmp_32(s
, v1
, v2
, CC_OP_LTUGTU_32
);
510 static inline void cmp_s32c(DisasContext
*s
, TCGv_i32 v1
, int32_t v2
)
512 /* XXX optimize for the constant? put it in s? */
513 TCGv_i32 tmp
= tcg_const_i32(v2
);
514 cmp_32(s
, v1
, tmp
, CC_OP_LTGT_32
);
515 tcg_temp_free_i32(tmp
);
518 static inline void cmp_u32c(DisasContext
*s
, TCGv_i32 v1
, uint32_t v2
)
520 TCGv_i32 tmp
= tcg_const_i32(v2
);
521 cmp_32(s
, v1
, tmp
, CC_OP_LTUGTU_32
);
522 tcg_temp_free_i32(tmp
);
525 static inline void cmp_s64(DisasContext
*s
, TCGv_i64 v1
, TCGv_i64 v2
)
527 cmp_64(s
, v1
, v2
, CC_OP_LTGT_64
);
530 static inline void cmp_u64(DisasContext
*s
, TCGv_i64 v1
, TCGv_i64 v2
)
532 cmp_64(s
, v1
, v2
, CC_OP_LTUGTU_64
);
535 static inline void cmp_s64c(DisasContext
*s
, TCGv_i64 v1
, int64_t v2
)
537 TCGv_i64 tmp
= tcg_const_i64(v2
);
539 tcg_temp_free_i64(tmp
);
542 static inline void cmp_u64c(DisasContext
*s
, TCGv_i64 v1
, uint64_t v2
)
544 TCGv_i64 tmp
= tcg_const_i64(v2
);
546 tcg_temp_free_i64(tmp
);
549 static inline void set_cc_s32(DisasContext
*s
, TCGv_i32 val
)
551 gen_op_update1_cc_i32(s
, CC_OP_LTGT0_32
, val
);
554 static inline void set_cc_s64(DisasContext
*s
, TCGv_i64 val
)
556 gen_op_update1_cc_i64(s
, CC_OP_LTGT0_64
, val
);
559 /* CC value is in env->cc_op */
560 static inline void set_cc_static(DisasContext
*s
)
562 tcg_gen_discard_i64(cc_src
);
563 tcg_gen_discard_i64(cc_dst
);
564 tcg_gen_discard_i64(cc_vr
);
565 s
->cc_op
= CC_OP_STATIC
;
568 static inline void gen_op_set_cc_op(DisasContext
*s
)
570 if (s
->cc_op
!= CC_OP_DYNAMIC
&& s
->cc_op
!= CC_OP_STATIC
) {
571 tcg_gen_movi_i32(cc_op
, s
->cc_op
);
575 static inline void gen_update_cc_op(DisasContext
*s
)
580 /* calculates cc into cc_op */
581 static void gen_op_calc_cc(DisasContext
*s
)
583 TCGv_i32 local_cc_op
= tcg_const_i32(s
->cc_op
);
584 TCGv_i64 dummy
= tcg_const_i64(0);
591 /* s->cc_op is the cc value */
592 tcg_gen_movi_i32(cc_op
, s
->cc_op
- CC_OP_CONST0
);
595 /* env->cc_op already is the cc value */
609 gen_helper_calc_cc(cc_op
, cpu_env
, local_cc_op
, dummy
, cc_dst
, dummy
);
614 case CC_OP_LTUGTU_32
:
615 case CC_OP_LTUGTU_64
:
622 gen_helper_calc_cc(cc_op
, cpu_env
, local_cc_op
, cc_src
, cc_dst
, dummy
);
637 gen_helper_calc_cc(cc_op
, cpu_env
, local_cc_op
, cc_src
, cc_dst
, cc_vr
);
640 /* unknown operation - assume 3 arguments and cc_op in env */
641 gen_helper_calc_cc(cc_op
, cpu_env
, cc_op
, cc_src
, cc_dst
, cc_vr
);
647 tcg_temp_free_i32(local_cc_op
);
648 tcg_temp_free_i64(dummy
);
650 /* We now have cc in cc_op as constant */
654 static inline void decode_rr(DisasContext
*s
, uint64_t insn
, int *r1
, int *r2
)
658 *r1
= (insn
>> 4) & 0xf;
662 static inline TCGv_i64
decode_rx(DisasContext
*s
, uint64_t insn
, int *r1
,
663 int *x2
, int *b2
, int *d2
)
667 *r1
= (insn
>> 20) & 0xf;
668 *x2
= (insn
>> 16) & 0xf;
669 *b2
= (insn
>> 12) & 0xf;
672 return get_address(s
, *x2
, *b2
, *d2
);
675 static inline void decode_rs(DisasContext
*s
, uint64_t insn
, int *r1
, int *r3
,
680 *r1
= (insn
>> 20) & 0xf;
682 *r3
= (insn
>> 16) & 0xf;
683 *b2
= (insn
>> 12) & 0xf;
687 static inline TCGv_i64
decode_si(DisasContext
*s
, uint64_t insn
, int *i2
,
692 *i2
= (insn
>> 16) & 0xff;
693 *b1
= (insn
>> 12) & 0xf;
696 return get_address(s
, 0, *b1
, *d1
);
699 static int use_goto_tb(DisasContext
*s
, uint64_t dest
)
701 /* NOTE: we handle the case where the TB spans two pages here */
702 return (((dest
& TARGET_PAGE_MASK
) == (s
->tb
->pc
& TARGET_PAGE_MASK
)
703 || (dest
& TARGET_PAGE_MASK
) == ((s
->pc
- 1) & TARGET_PAGE_MASK
))
704 && !s
->singlestep_enabled
705 && !(s
->tb
->cflags
& CF_LAST_IO
));
708 static inline void gen_goto_tb(DisasContext
*s
, int tb_num
, target_ulong pc
)
712 if (use_goto_tb(s
, pc
)) {
713 tcg_gen_goto_tb(tb_num
);
714 tcg_gen_movi_i64(psw_addr
, pc
);
715 tcg_gen_exit_tb((tcg_target_long
)s
->tb
+ tb_num
);
717 /* jump to another page: currently not optimized */
718 tcg_gen_movi_i64(psw_addr
, pc
);
723 static inline void account_noninline_branch(DisasContext
*s
, int cc_op
)
725 #ifdef DEBUG_INLINE_BRANCHES
726 inline_branch_miss
[cc_op
]++;
730 static inline void account_inline_branch(DisasContext
*s
, int cc_op
)
732 #ifdef DEBUG_INLINE_BRANCHES
733 inline_branch_hit
[cc_op
]++;
737 /* Table of mask values to comparison codes, given a comparison as input.
738 For a true comparison CC=3 will never be set, but we treat this
739 conservatively for possible use when CC=3 indicates overflow. */
740 static const TCGCond ltgt_cond
[16] = {
741 TCG_COND_NEVER
, TCG_COND_NEVER
, /* | | | x */
742 TCG_COND_GT
, TCG_COND_NEVER
, /* | | GT | x */
743 TCG_COND_LT
, TCG_COND_NEVER
, /* | LT | | x */
744 TCG_COND_NE
, TCG_COND_NEVER
, /* | LT | GT | x */
745 TCG_COND_EQ
, TCG_COND_NEVER
, /* EQ | | | x */
746 TCG_COND_GE
, TCG_COND_NEVER
, /* EQ | | GT | x */
747 TCG_COND_LE
, TCG_COND_NEVER
, /* EQ | LT | | x */
748 TCG_COND_ALWAYS
, TCG_COND_ALWAYS
, /* EQ | LT | GT | x */
751 /* Table of mask values to comparison codes, given a logic op as input.
752 For such, only CC=0 and CC=1 should be possible. */
753 static const TCGCond nz_cond
[16] = {
755 TCG_COND_NEVER
, TCG_COND_NEVER
, TCG_COND_NEVER
, TCG_COND_NEVER
,
757 TCG_COND_NE
, TCG_COND_NE
, TCG_COND_NE
, TCG_COND_NE
,
759 TCG_COND_EQ
, TCG_COND_EQ
, TCG_COND_EQ
, TCG_COND_EQ
,
760 /* EQ | NE | x | x */
761 TCG_COND_ALWAYS
, TCG_COND_ALWAYS
, TCG_COND_ALWAYS
, TCG_COND_ALWAYS
,
764 /* Interpret MASK in terms of S->CC_OP, and fill in C with all the
765 details required to generate a TCG comparison. */
766 static void disas_jcc(DisasContext
*s
, DisasCompare
*c
, uint32_t mask
)
769 enum cc_op old_cc_op
= s
->cc_op
;
771 if (mask
== 15 || mask
== 0) {
772 c
->cond
= (mask
? TCG_COND_ALWAYS
: TCG_COND_NEVER
);
775 c
->g1
= c
->g2
= true;
780 /* Find the TCG condition for the mask + cc op. */
786 cond
= ltgt_cond
[mask
];
787 if (cond
== TCG_COND_NEVER
) {
790 account_inline_branch(s
, old_cc_op
);
793 case CC_OP_LTUGTU_32
:
794 case CC_OP_LTUGTU_64
:
795 cond
= tcg_unsigned_cond(ltgt_cond
[mask
]);
796 if (cond
== TCG_COND_NEVER
) {
799 account_inline_branch(s
, old_cc_op
);
803 cond
= nz_cond
[mask
];
804 if (cond
== TCG_COND_NEVER
) {
807 account_inline_branch(s
, old_cc_op
);
822 account_inline_branch(s
, old_cc_op
);
837 account_inline_branch(s
, old_cc_op
);
842 /* Calculate cc value. */
847 /* Jump based on CC. We'll load up the real cond below;
848 the assignment here merely avoids a compiler warning. */
849 account_noninline_branch(s
, old_cc_op
);
850 old_cc_op
= CC_OP_STATIC
;
851 cond
= TCG_COND_NEVER
;
855 /* Load up the arguments of the comparison. */
857 c
->g1
= c
->g2
= false;
861 c
->u
.s32
.a
= tcg_temp_new_i32();
862 tcg_gen_trunc_i64_i32(c
->u
.s32
.a
, cc_dst
);
863 c
->u
.s32
.b
= tcg_const_i32(0);
866 case CC_OP_LTUGTU_32
:
868 c
->u
.s32
.a
= tcg_temp_new_i32();
869 tcg_gen_trunc_i64_i32(c
->u
.s32
.a
, cc_src
);
870 c
->u
.s32
.b
= tcg_temp_new_i32();
871 tcg_gen_trunc_i64_i32(c
->u
.s32
.b
, cc_dst
);
877 c
->u
.s64
.b
= tcg_const_i64(0);
881 case CC_OP_LTUGTU_64
:
884 c
->g1
= c
->g2
= true;
890 c
->u
.s64
.a
= tcg_temp_new_i64();
891 c
->u
.s64
.b
= tcg_const_i64(0);
892 tcg_gen_and_i64(c
->u
.s64
.a
, cc_src
, cc_dst
);
900 case 0x8 | 0x4 | 0x2: /* cc != 3 */
902 c
->u
.s32
.b
= tcg_const_i32(3);
904 case 0x8 | 0x4 | 0x1: /* cc != 2 */
906 c
->u
.s32
.b
= tcg_const_i32(2);
908 case 0x8 | 0x2 | 0x1: /* cc != 1 */
910 c
->u
.s32
.b
= tcg_const_i32(1);
912 case 0x8 | 0x2: /* cc == 0 ||Â cc == 2 => (cc & 1) == 0 */
915 c
->u
.s32
.a
= tcg_temp_new_i32();
916 c
->u
.s32
.b
= tcg_const_i32(0);
917 tcg_gen_andi_i32(c
->u
.s32
.a
, cc_op
, 1);
919 case 0x8 | 0x4: /* cc < 2 */
921 c
->u
.s32
.b
= tcg_const_i32(2);
923 case 0x8: /* cc == 0 */
925 c
->u
.s32
.b
= tcg_const_i32(0);
927 case 0x4 | 0x2 | 0x1: /* cc != 0 */
929 c
->u
.s32
.b
= tcg_const_i32(0);
931 case 0x4 | 0x1: /* cc == 1 ||Â cc == 3 => (cc & 1) != 0 */
934 c
->u
.s32
.a
= tcg_temp_new_i32();
935 c
->u
.s32
.b
= tcg_const_i32(0);
936 tcg_gen_andi_i32(c
->u
.s32
.a
, cc_op
, 1);
938 case 0x4: /* cc == 1 */
940 c
->u
.s32
.b
= tcg_const_i32(1);
942 case 0x2 | 0x1: /* cc > 1 */
944 c
->u
.s32
.b
= tcg_const_i32(1);
946 case 0x2: /* cc == 2 */
948 c
->u
.s32
.b
= tcg_const_i32(2);
950 case 0x1: /* cc == 3 */
952 c
->u
.s32
.b
= tcg_const_i32(3);
955 /* CC is masked by something else: (8 >> cc) & mask. */
958 c
->u
.s32
.a
= tcg_const_i32(8);
959 c
->u
.s32
.b
= tcg_const_i32(0);
960 tcg_gen_shr_i32(c
->u
.s32
.a
, c
->u
.s32
.a
, cc_op
);
961 tcg_gen_andi_i32(c
->u
.s32
.a
, c
->u
.s32
.a
, mask
);
972 static void free_compare(DisasCompare
*c
)
976 tcg_temp_free_i64(c
->u
.s64
.a
);
978 tcg_temp_free_i32(c
->u
.s32
.a
);
983 tcg_temp_free_i64(c
->u
.s64
.b
);
985 tcg_temp_free_i32(c
->u
.s32
.b
);
990 static void disas_ed(CPUS390XState
*env
, DisasContext
*s
, int op
, int r1
,
991 int x2
, int b2
, int d2
, int r1b
)
993 TCGv_i32 tmp_r1
, tmp32
;
995 addr
= get_address(s
, x2
, b2
, d2
);
996 tmp_r1
= tcg_const_i32(r1
);
998 case 0xd: /* DEB R1,D2(X2,B2) [RXE] */
999 tmp
= tcg_temp_new_i64();
1000 tmp32
= tcg_temp_new_i32();
1001 tcg_gen_qemu_ld32u(tmp
, addr
, get_mem_index(s
));
1002 tcg_gen_trunc_i64_i32(tmp32
, tmp
);
1003 gen_helper_deb(cpu_env
, tmp_r1
, tmp32
);
1004 tcg_temp_free_i64(tmp
);
1005 tcg_temp_free_i32(tmp32
);
1007 case 0x10: /* TCEB R1,D2(X2,B2) [RXE] */
1008 potential_page_fault(s
);
1009 gen_helper_tceb(cc_op
, cpu_env
, tmp_r1
, addr
);
1012 case 0x11: /* TCDB R1,D2(X2,B2) [RXE] */
1013 potential_page_fault(s
);
1014 gen_helper_tcdb(cc_op
, cpu_env
, tmp_r1
, addr
);
1017 case 0x12: /* TCXB R1,D2(X2,B2) [RXE] */
1018 potential_page_fault(s
);
1019 gen_helper_tcxb(cc_op
, cpu_env
, tmp_r1
, addr
);
1022 case 0x17: /* MEEB R1,D2(X2,B2) [RXE] */
1023 tmp
= tcg_temp_new_i64();
1024 tmp32
= tcg_temp_new_i32();
1025 tcg_gen_qemu_ld32u(tmp
, addr
, get_mem_index(s
));
1026 tcg_gen_trunc_i64_i32(tmp32
, tmp
);
1027 gen_helper_meeb(cpu_env
, tmp_r1
, tmp32
);
1028 tcg_temp_free_i64(tmp
);
1029 tcg_temp_free_i32(tmp32
);
1031 case 0x1c: /* MDB R1,D2(X2,B2) [RXE] */
1032 potential_page_fault(s
);
1033 gen_helper_mdb(cpu_env
, tmp_r1
, addr
);
1035 case 0x1d: /* DDB R1,D2(X2,B2) [RXE] */
1036 potential_page_fault(s
);
1037 gen_helper_ddb(cpu_env
, tmp_r1
, addr
);
1039 case 0x1e: /* MADB R1,R3,D2(X2,B2) [RXF] */
1040 /* for RXF insns, r1 is R3 and r1b is R1 */
1041 tmp32
= tcg_const_i32(r1b
);
1042 potential_page_fault(s
);
1043 gen_helper_madb(cpu_env
, tmp32
, addr
, tmp_r1
);
1044 tcg_temp_free_i32(tmp32
);
1047 LOG_DISAS("illegal ed operation 0x%x\n", op
);
1048 gen_illegal_opcode(s
);
1051 tcg_temp_free_i32(tmp_r1
);
1052 tcg_temp_free_i64(addr
);
1055 static void disas_b2(CPUS390XState
*env
, DisasContext
*s
, int op
,
1058 TCGv_i64 tmp
, tmp2
, tmp3
;
1059 TCGv_i32 tmp32_1
, tmp32_2
, tmp32_3
;
1061 #ifndef CONFIG_USER_ONLY
1065 r1
= (insn
>> 4) & 0xf;
1068 LOG_DISAS("disas_b2: op 0x%x r1 %d r2 %d\n", op
, r1
, r2
);
1071 case 0x22: /* IPM R1 [RRE] */
1072 tmp32_1
= tcg_const_i32(r1
);
1074 gen_helper_ipm(cpu_env
, cc_op
, tmp32_1
);
1075 tcg_temp_free_i32(tmp32_1
);
1077 case 0x41: /* CKSM R1,R2 [RRE] */
1078 tmp32_1
= tcg_const_i32(r1
);
1079 tmp32_2
= tcg_const_i32(r2
);
1080 potential_page_fault(s
);
1081 gen_helper_cksm(cpu_env
, tmp32_1
, tmp32_2
);
1082 tcg_temp_free_i32(tmp32_1
);
1083 tcg_temp_free_i32(tmp32_2
);
1084 gen_op_movi_cc(s
, 0);
1086 case 0x4e: /* SAR R1,R2 [RRE] */
1087 tmp32_1
= load_reg32(r2
);
1088 tcg_gen_st_i32(tmp32_1
, cpu_env
, offsetof(CPUS390XState
, aregs
[r1
]));
1089 tcg_temp_free_i32(tmp32_1
);
1091 case 0x4f: /* EAR R1,R2 [RRE] */
1092 tmp32_1
= tcg_temp_new_i32();
1093 tcg_gen_ld_i32(tmp32_1
, cpu_env
, offsetof(CPUS390XState
, aregs
[r2
]));
1094 store_reg32(r1
, tmp32_1
);
1095 tcg_temp_free_i32(tmp32_1
);
1097 case 0x54: /* MVPG R1,R2 [RRE] */
1099 tmp2
= load_reg(r1
);
1100 tmp3
= load_reg(r2
);
1101 potential_page_fault(s
);
1102 gen_helper_mvpg(cpu_env
, tmp
, tmp2
, tmp3
);
1103 tcg_temp_free_i64(tmp
);
1104 tcg_temp_free_i64(tmp2
);
1105 tcg_temp_free_i64(tmp3
);
1106 /* XXX check CCO bit and set CC accordingly */
1107 gen_op_movi_cc(s
, 0);
1109 case 0x55: /* MVST R1,R2 [RRE] */
1110 tmp32_1
= load_reg32(0);
1111 tmp32_2
= tcg_const_i32(r1
);
1112 tmp32_3
= tcg_const_i32(r2
);
1113 potential_page_fault(s
);
1114 gen_helper_mvst(cpu_env
, tmp32_1
, tmp32_2
, tmp32_3
);
1115 tcg_temp_free_i32(tmp32_1
);
1116 tcg_temp_free_i32(tmp32_2
);
1117 tcg_temp_free_i32(tmp32_3
);
1118 gen_op_movi_cc(s
, 1);
1120 case 0x5d: /* CLST R1,R2 [RRE] */
1121 tmp32_1
= load_reg32(0);
1122 tmp32_2
= tcg_const_i32(r1
);
1123 tmp32_3
= tcg_const_i32(r2
);
1124 potential_page_fault(s
);
1125 gen_helper_clst(cc_op
, cpu_env
, tmp32_1
, tmp32_2
, tmp32_3
);
1127 tcg_temp_free_i32(tmp32_1
);
1128 tcg_temp_free_i32(tmp32_2
);
1129 tcg_temp_free_i32(tmp32_3
);
1131 case 0x5e: /* SRST R1,R2 [RRE] */
1132 tmp32_1
= load_reg32(0);
1133 tmp32_2
= tcg_const_i32(r1
);
1134 tmp32_3
= tcg_const_i32(r2
);
1135 potential_page_fault(s
);
1136 gen_helper_srst(cc_op
, cpu_env
, tmp32_1
, tmp32_2
, tmp32_3
);
1138 tcg_temp_free_i32(tmp32_1
);
1139 tcg_temp_free_i32(tmp32_2
);
1140 tcg_temp_free_i32(tmp32_3
);
1143 #ifndef CONFIG_USER_ONLY
1144 case 0x02: /* STIDP D2(B2) [S] */
1146 check_privileged(s
);
1147 decode_rs(s
, insn
, &r1
, &r3
, &b2
, &d2
);
1148 tmp
= get_address(s
, 0, b2
, d2
);
1149 potential_page_fault(s
);
1150 gen_helper_stidp(cpu_env
, tmp
);
1151 tcg_temp_free_i64(tmp
);
1153 case 0x04: /* SCK D2(B2) [S] */
1155 check_privileged(s
);
1156 decode_rs(s
, insn
, &r1
, &r3
, &b2
, &d2
);
1157 tmp
= get_address(s
, 0, b2
, d2
);
1158 potential_page_fault(s
);
1159 gen_helper_sck(cc_op
, tmp
);
1161 tcg_temp_free_i64(tmp
);
1163 case 0x05: /* STCK D2(B2) [S] */
1165 decode_rs(s
, insn
, &r1
, &r3
, &b2
, &d2
);
1166 tmp
= get_address(s
, 0, b2
, d2
);
1167 potential_page_fault(s
);
1168 gen_helper_stck(cc_op
, cpu_env
, tmp
);
1170 tcg_temp_free_i64(tmp
);
1172 case 0x06: /* SCKC D2(B2) [S] */
1173 /* Set Clock Comparator */
1174 check_privileged(s
);
1175 decode_rs(s
, insn
, &r1
, &r3
, &b2
, &d2
);
1176 tmp
= get_address(s
, 0, b2
, d2
);
1177 potential_page_fault(s
);
1178 gen_helper_sckc(cpu_env
, tmp
);
1179 tcg_temp_free_i64(tmp
);
1181 case 0x07: /* STCKC D2(B2) [S] */
1182 /* Store Clock Comparator */
1183 check_privileged(s
);
1184 decode_rs(s
, insn
, &r1
, &r3
, &b2
, &d2
);
1185 tmp
= get_address(s
, 0, b2
, d2
);
1186 potential_page_fault(s
);
1187 gen_helper_stckc(cpu_env
, tmp
);
1188 tcg_temp_free_i64(tmp
);
1190 case 0x08: /* SPT D2(B2) [S] */
1192 check_privileged(s
);
1193 decode_rs(s
, insn
, &r1
, &r3
, &b2
, &d2
);
1194 tmp
= get_address(s
, 0, b2
, d2
);
1195 potential_page_fault(s
);
1196 gen_helper_spt(cpu_env
, tmp
);
1197 tcg_temp_free_i64(tmp
);
1199 case 0x09: /* STPT D2(B2) [S] */
1200 /* Store CPU Timer */
1201 check_privileged(s
);
1202 decode_rs(s
, insn
, &r1
, &r3
, &b2
, &d2
);
1203 tmp
= get_address(s
, 0, b2
, d2
);
1204 potential_page_fault(s
);
1205 gen_helper_stpt(cpu_env
, tmp
);
1206 tcg_temp_free_i64(tmp
);
1208 case 0x0a: /* SPKA D2(B2) [S] */
1209 /* Set PSW Key from Address */
1210 check_privileged(s
);
1211 decode_rs(s
, insn
, &r1
, &r3
, &b2
, &d2
);
1212 tmp
= get_address(s
, 0, b2
, d2
);
1213 tmp2
= tcg_temp_new_i64();
1214 tcg_gen_andi_i64(tmp2
, psw_mask
, ~PSW_MASK_KEY
);
1215 tcg_gen_shli_i64(tmp
, tmp
, PSW_SHIFT_KEY
- 4);
1216 tcg_gen_or_i64(psw_mask
, tmp2
, tmp
);
1217 tcg_temp_free_i64(tmp2
);
1218 tcg_temp_free_i64(tmp
);
1220 case 0x0d: /* PTLB [S] */
1222 check_privileged(s
);
1223 gen_helper_ptlb(cpu_env
);
1225 case 0x10: /* SPX D2(B2) [S] */
1226 /* Set Prefix Register */
1227 check_privileged(s
);
1228 decode_rs(s
, insn
, &r1
, &r3
, &b2
, &d2
);
1229 tmp
= get_address(s
, 0, b2
, d2
);
1230 potential_page_fault(s
);
1231 gen_helper_spx(cpu_env
, tmp
);
1232 tcg_temp_free_i64(tmp
);
1234 case 0x11: /* STPX D2(B2) [S] */
1236 check_privileged(s
);
1237 decode_rs(s
, insn
, &r1
, &r3
, &b2
, &d2
);
1238 tmp
= get_address(s
, 0, b2
, d2
);
1239 tmp2
= tcg_temp_new_i64();
1240 tcg_gen_ld_i64(tmp2
, cpu_env
, offsetof(CPUS390XState
, psa
));
1241 tcg_gen_qemu_st32(tmp2
, tmp
, get_mem_index(s
));
1242 tcg_temp_free_i64(tmp
);
1243 tcg_temp_free_i64(tmp2
);
1245 case 0x12: /* STAP D2(B2) [S] */
1246 /* Store CPU Address */
1247 check_privileged(s
);
1248 decode_rs(s
, insn
, &r1
, &r3
, &b2
, &d2
);
1249 tmp
= get_address(s
, 0, b2
, d2
);
1250 tmp2
= tcg_temp_new_i64();
1251 tmp32_1
= tcg_temp_new_i32();
1252 tcg_gen_ld_i32(tmp32_1
, cpu_env
, offsetof(CPUS390XState
, cpu_num
));
1253 tcg_gen_extu_i32_i64(tmp2
, tmp32_1
);
1254 tcg_gen_qemu_st32(tmp2
, tmp
, get_mem_index(s
));
1255 tcg_temp_free_i64(tmp
);
1256 tcg_temp_free_i64(tmp2
);
1257 tcg_temp_free_i32(tmp32_1
);
1259 case 0x21: /* IPTE R1,R2 [RRE] */
1260 /* Invalidate PTE */
1261 check_privileged(s
);
1262 r1
= (insn
>> 4) & 0xf;
1265 tmp2
= load_reg(r2
);
1266 gen_helper_ipte(cpu_env
, tmp
, tmp2
);
1267 tcg_temp_free_i64(tmp
);
1268 tcg_temp_free_i64(tmp2
);
1270 case 0x29: /* ISKE R1,R2 [RRE] */
1271 /* Insert Storage Key Extended */
1272 check_privileged(s
);
1273 r1
= (insn
>> 4) & 0xf;
1276 tmp2
= tcg_temp_new_i64();
1277 gen_helper_iske(tmp2
, cpu_env
, tmp
);
1278 store_reg(r1
, tmp2
);
1279 tcg_temp_free_i64(tmp
);
1280 tcg_temp_free_i64(tmp2
);
1282 case 0x2a: /* RRBE R1,R2 [RRE] */
1283 /* Set Storage Key Extended */
1284 check_privileged(s
);
1285 r1
= (insn
>> 4) & 0xf;
1287 tmp32_1
= load_reg32(r1
);
1289 gen_helper_rrbe(cc_op
, cpu_env
, tmp32_1
, tmp
);
1291 tcg_temp_free_i32(tmp32_1
);
1292 tcg_temp_free_i64(tmp
);
1294 case 0x2b: /* SSKE R1,R2 [RRE] */
1295 /* Set Storage Key Extended */
1296 check_privileged(s
);
1297 r1
= (insn
>> 4) & 0xf;
1299 tmp32_1
= load_reg32(r1
);
1301 gen_helper_sske(cpu_env
, tmp32_1
, tmp
);
1302 tcg_temp_free_i32(tmp32_1
);
1303 tcg_temp_free_i64(tmp
);
1305 case 0x34: /* STCH ? */
1306 /* Store Subchannel */
1307 check_privileged(s
);
1308 gen_op_movi_cc(s
, 3);
1310 case 0x46: /* STURA R1,R2 [RRE] */
1311 /* Store Using Real Address */
1312 check_privileged(s
);
1313 r1
= (insn
>> 4) & 0xf;
1315 tmp32_1
= load_reg32(r1
);
1317 potential_page_fault(s
);
1318 gen_helper_stura(cpu_env
, tmp
, tmp32_1
);
1319 tcg_temp_free_i32(tmp32_1
);
1320 tcg_temp_free_i64(tmp
);
1322 case 0x50: /* CSP R1,R2 [RRE] */
1323 /* Compare And Swap And Purge */
1324 check_privileged(s
);
1325 r1
= (insn
>> 4) & 0xf;
1327 tmp32_1
= tcg_const_i32(r1
);
1328 tmp32_2
= tcg_const_i32(r2
);
1329 gen_helper_csp(cc_op
, cpu_env
, tmp32_1
, tmp32_2
);
1331 tcg_temp_free_i32(tmp32_1
);
1332 tcg_temp_free_i32(tmp32_2
);
1334 case 0x5f: /* CHSC ? */
1335 /* Channel Subsystem Call */
1336 check_privileged(s
);
1337 gen_op_movi_cc(s
, 3);
1339 case 0x78: /* STCKE D2(B2) [S] */
1340 /* Store Clock Extended */
1341 decode_rs(s
, insn
, &r1
, &r3
, &b2
, &d2
);
1342 tmp
= get_address(s
, 0, b2
, d2
);
1343 potential_page_fault(s
);
1344 gen_helper_stcke(cc_op
, cpu_env
, tmp
);
1346 tcg_temp_free_i64(tmp
);
1348 case 0x79: /* SACF D2(B2) [S] */
1349 /* Set Address Space Control Fast */
1350 check_privileged(s
);
1351 decode_rs(s
, insn
, &r1
, &r3
, &b2
, &d2
);
1352 tmp
= get_address(s
, 0, b2
, d2
);
1353 potential_page_fault(s
);
1354 gen_helper_sacf(cpu_env
, tmp
);
1355 tcg_temp_free_i64(tmp
);
1356 /* addressing mode has changed, so end the block */
1359 s
->is_jmp
= DISAS_JUMP
;
1361 case 0x7d: /* STSI D2,(B2) [S] */
1362 check_privileged(s
);
1363 decode_rs(s
, insn
, &r1
, &r3
, &b2
, &d2
);
1364 tmp
= get_address(s
, 0, b2
, d2
);
1365 tmp32_1
= load_reg32(0);
1366 tmp32_2
= load_reg32(1);
1367 potential_page_fault(s
);
1368 gen_helper_stsi(cc_op
, cpu_env
, tmp
, tmp32_1
, tmp32_2
);
1370 tcg_temp_free_i64(tmp
);
1371 tcg_temp_free_i32(tmp32_1
);
1372 tcg_temp_free_i32(tmp32_2
);
1374 case 0x9d: /* LFPC D2(B2) [S] */
1375 decode_rs(s
, insn
, &r1
, &r3
, &b2
, &d2
);
1376 tmp
= get_address(s
, 0, b2
, d2
);
1377 tmp2
= tcg_temp_new_i64();
1378 tmp32_1
= tcg_temp_new_i32();
1379 tcg_gen_qemu_ld32u(tmp2
, tmp
, get_mem_index(s
));
1380 tcg_gen_trunc_i64_i32(tmp32_1
, tmp2
);
1381 tcg_gen_st_i32(tmp32_1
, cpu_env
, offsetof(CPUS390XState
, fpc
));
1382 tcg_temp_free_i64(tmp
);
1383 tcg_temp_free_i64(tmp2
);
1384 tcg_temp_free_i32(tmp32_1
);
1386 case 0xb1: /* STFL D2(B2) [S] */
1387 /* Store Facility List (CPU features) at 200 */
1388 check_privileged(s
);
1389 tmp2
= tcg_const_i64(0xc0000000);
1390 tmp
= tcg_const_i64(200);
1391 tcg_gen_qemu_st32(tmp2
, tmp
, get_mem_index(s
));
1392 tcg_temp_free_i64(tmp2
);
1393 tcg_temp_free_i64(tmp
);
1395 case 0xb2: /* LPSWE D2(B2) [S] */
1396 /* Load PSW Extended */
1397 check_privileged(s
);
1398 decode_rs(s
, insn
, &r1
, &r3
, &b2
, &d2
);
1399 tmp
= get_address(s
, 0, b2
, d2
);
1400 tmp2
= tcg_temp_new_i64();
1401 tmp3
= tcg_temp_new_i64();
1402 tcg_gen_qemu_ld64(tmp2
, tmp
, get_mem_index(s
));
1403 tcg_gen_addi_i64(tmp
, tmp
, 8);
1404 tcg_gen_qemu_ld64(tmp3
, tmp
, get_mem_index(s
));
1405 gen_helper_load_psw(cpu_env
, tmp2
, tmp3
);
1406 /* we need to keep cc_op intact */
1407 s
->is_jmp
= DISAS_JUMP
;
1408 tcg_temp_free_i64(tmp
);
1409 tcg_temp_free_i64(tmp2
);
1410 tcg_temp_free_i64(tmp3
);
1412 case 0x20: /* SERVC R1,R2 [RRE] */
1413 /* SCLP Service call (PV hypercall) */
1414 check_privileged(s
);
1415 potential_page_fault(s
);
1416 tmp32_1
= load_reg32(r2
);
1418 gen_helper_servc(cc_op
, cpu_env
, tmp32_1
, tmp
);
1420 tcg_temp_free_i32(tmp32_1
);
1421 tcg_temp_free_i64(tmp
);
1425 LOG_DISAS("illegal b2 operation 0x%x\n", op
);
1426 gen_illegal_opcode(s
);
1431 static void disas_b3(CPUS390XState
*env
, DisasContext
*s
, int op
, int m3
,
1435 TCGv_i32 tmp32_1
, tmp32_2
, tmp32_3
;
1436 LOG_DISAS("disas_b3: op 0x%x m3 0x%x r1 %d r2 %d\n", op
, m3
, r1
, r2
);
1437 #define FP_HELPER(i) \
1438 tmp32_1 = tcg_const_i32(r1); \
1439 tmp32_2 = tcg_const_i32(r2); \
1440 gen_helper_ ## i(cpu_env, tmp32_1, tmp32_2); \
1441 tcg_temp_free_i32(tmp32_1); \
1442 tcg_temp_free_i32(tmp32_2);
1444 #define FP_HELPER_CC(i) \
1445 tmp32_1 = tcg_const_i32(r1); \
1446 tmp32_2 = tcg_const_i32(r2); \
1447 gen_helper_ ## i(cc_op, cpu_env, tmp32_1, tmp32_2); \
1449 tcg_temp_free_i32(tmp32_1); \
1450 tcg_temp_free_i32(tmp32_2);
1453 case 0x0: /* LPEBR R1,R2 [RRE] */
1454 FP_HELPER_CC(lpebr
);
1456 case 0x3: /* LCEBR R1,R2 [RRE] */
1457 FP_HELPER_CC(lcebr
);
1459 case 0xd: /* DEBR R1,R2 [RRE] */
1462 case 0x10: /* LPDBR R1,R2 [RRE] */
1463 FP_HELPER_CC(lpdbr
);
1465 case 0x13: /* LCDBR R1,R2 [RRE] */
1466 FP_HELPER_CC(lcdbr
);
1468 case 0x15: /* SQBDR R1,R2 [RRE] */
1471 case 0x17: /* MEEBR R1,R2 [RRE] */
1474 case 0x1c: /* MDBR R1,R2 [RRE] */
1477 case 0x1d: /* DDBR R1,R2 [RRE] */
1480 case 0xe: /* MAEBR R1,R3,R2 [RRF] */
1481 case 0x1e: /* MADBR R1,R3,R2 [RRF] */
1482 case 0x1f: /* MSDBR R1,R3,R2 [RRF] */
1483 /* for RRF insns, m3 is R1, r1 is R3, and r2 is R2 */
1484 tmp32_1
= tcg_const_i32(m3
);
1485 tmp32_2
= tcg_const_i32(r2
);
1486 tmp32_3
= tcg_const_i32(r1
);
1489 gen_helper_maebr(cpu_env
, tmp32_1
, tmp32_3
, tmp32_2
);
1492 gen_helper_madbr(cpu_env
, tmp32_1
, tmp32_3
, tmp32_2
);
1495 gen_helper_msdbr(cpu_env
, tmp32_1
, tmp32_3
, tmp32_2
);
1500 tcg_temp_free_i32(tmp32_1
);
1501 tcg_temp_free_i32(tmp32_2
);
1502 tcg_temp_free_i32(tmp32_3
);
1504 case 0x40: /* LPXBR R1,R2 [RRE] */
1505 FP_HELPER_CC(lpxbr
);
1507 case 0x43: /* LCXBR R1,R2 [RRE] */
1508 FP_HELPER_CC(lcxbr
);
1510 case 0x4c: /* MXBR R1,R2 [RRE] */
1513 case 0x4d: /* DXBR R1,R2 [RRE] */
1516 case 0x65: /* LXR R1,R2 [RRE] */
1517 tmp
= load_freg(r2
);
1518 store_freg(r1
, tmp
);
1519 tcg_temp_free_i64(tmp
);
1520 tmp
= load_freg(r2
+ 2);
1521 store_freg(r1
+ 2, tmp
);
1522 tcg_temp_free_i64(tmp
);
1524 case 0x74: /* LZER R1 [RRE] */
1525 tmp32_1
= tcg_const_i32(r1
);
1526 gen_helper_lzer(cpu_env
, tmp32_1
);
1527 tcg_temp_free_i32(tmp32_1
);
1529 case 0x75: /* LZDR R1 [RRE] */
1530 tmp32_1
= tcg_const_i32(r1
);
1531 gen_helper_lzdr(cpu_env
, tmp32_1
);
1532 tcg_temp_free_i32(tmp32_1
);
1534 case 0x76: /* LZXR R1 [RRE] */
1535 tmp32_1
= tcg_const_i32(r1
);
1536 gen_helper_lzxr(cpu_env
, tmp32_1
);
1537 tcg_temp_free_i32(tmp32_1
);
1539 case 0x84: /* SFPC R1 [RRE] */
1540 tmp32_1
= load_reg32(r1
);
1541 tcg_gen_st_i32(tmp32_1
, cpu_env
, offsetof(CPUS390XState
, fpc
));
1542 tcg_temp_free_i32(tmp32_1
);
1544 case 0x94: /* CEFBR R1,R2 [RRE] */
1545 case 0x95: /* CDFBR R1,R2 [RRE] */
1546 case 0x96: /* CXFBR R1,R2 [RRE] */
1547 tmp32_1
= tcg_const_i32(r1
);
1548 tmp32_2
= load_reg32(r2
);
1551 gen_helper_cefbr(cpu_env
, tmp32_1
, tmp32_2
);
1554 gen_helper_cdfbr(cpu_env
, tmp32_1
, tmp32_2
);
1557 gen_helper_cxfbr(cpu_env
, tmp32_1
, tmp32_2
);
1562 tcg_temp_free_i32(tmp32_1
);
1563 tcg_temp_free_i32(tmp32_2
);
1565 case 0x98: /* CFEBR R1,R2 [RRE] */
1566 case 0x99: /* CFDBR R1,R2 [RRE] */
1567 case 0x9a: /* CFXBR R1,R2 [RRE] */
1568 tmp32_1
= tcg_const_i32(r1
);
1569 tmp32_2
= tcg_const_i32(r2
);
1570 tmp32_3
= tcg_const_i32(m3
);
1573 gen_helper_cfebr(cc_op
, cpu_env
, tmp32_1
, tmp32_2
, tmp32_3
);
1576 gen_helper_cfdbr(cc_op
, cpu_env
, tmp32_1
, tmp32_2
, tmp32_3
);
1579 gen_helper_cfxbr(cc_op
, cpu_env
, tmp32_1
, tmp32_2
, tmp32_3
);
1585 tcg_temp_free_i32(tmp32_1
);
1586 tcg_temp_free_i32(tmp32_2
);
1587 tcg_temp_free_i32(tmp32_3
);
1589 case 0xa4: /* CEGBR R1,R2 [RRE] */
1590 case 0xa5: /* CDGBR R1,R2 [RRE] */
1591 tmp32_1
= tcg_const_i32(r1
);
1595 gen_helper_cegbr(cpu_env
, tmp32_1
, tmp
);
1598 gen_helper_cdgbr(cpu_env
, tmp32_1
, tmp
);
1603 tcg_temp_free_i32(tmp32_1
);
1604 tcg_temp_free_i64(tmp
);
1606 case 0xa6: /* CXGBR R1,R2 [RRE] */
1607 tmp32_1
= tcg_const_i32(r1
);
1609 gen_helper_cxgbr(cpu_env
, tmp32_1
, tmp
);
1610 tcg_temp_free_i32(tmp32_1
);
1611 tcg_temp_free_i64(tmp
);
1613 case 0xa8: /* CGEBR R1,R2 [RRE] */
1614 tmp32_1
= tcg_const_i32(r1
);
1615 tmp32_2
= tcg_const_i32(r2
);
1616 tmp32_3
= tcg_const_i32(m3
);
1617 gen_helper_cgebr(cc_op
, cpu_env
, tmp32_1
, tmp32_2
, tmp32_3
);
1619 tcg_temp_free_i32(tmp32_1
);
1620 tcg_temp_free_i32(tmp32_2
);
1621 tcg_temp_free_i32(tmp32_3
);
1623 case 0xa9: /* CGDBR R1,R2 [RRE] */
1624 tmp32_1
= tcg_const_i32(r1
);
1625 tmp32_2
= tcg_const_i32(r2
);
1626 tmp32_3
= tcg_const_i32(m3
);
1627 gen_helper_cgdbr(cc_op
, cpu_env
, tmp32_1
, tmp32_2
, tmp32_3
);
1629 tcg_temp_free_i32(tmp32_1
);
1630 tcg_temp_free_i32(tmp32_2
);
1631 tcg_temp_free_i32(tmp32_3
);
1633 case 0xaa: /* CGXBR R1,R2 [RRE] */
1634 tmp32_1
= tcg_const_i32(r1
);
1635 tmp32_2
= tcg_const_i32(r2
);
1636 tmp32_3
= tcg_const_i32(m3
);
1637 gen_helper_cgxbr(cc_op
, cpu_env
, tmp32_1
, tmp32_2
, tmp32_3
);
1639 tcg_temp_free_i32(tmp32_1
);
1640 tcg_temp_free_i32(tmp32_2
);
1641 tcg_temp_free_i32(tmp32_3
);
1644 LOG_DISAS("illegal b3 operation 0x%x\n", op
);
1645 gen_illegal_opcode(s
);
1653 static void disas_b9(CPUS390XState
*env
, DisasContext
*s
, int op
, int r1
,
1659 LOG_DISAS("disas_b9: op 0x%x r1 %d r2 %d\n", op
, r1
, r2
);
1661 case 0x83: /* FLOGR R1,R2 [RRE] */
1663 tmp32_1
= tcg_const_i32(r1
);
1664 gen_helper_flogr(cc_op
, cpu_env
, tmp32_1
, tmp
);
1666 tcg_temp_free_i64(tmp
);
1667 tcg_temp_free_i32(tmp32_1
);
1670 LOG_DISAS("illegal b9 operation 0x%x\n", op
);
1671 gen_illegal_opcode(s
);
1676 static void disas_s390_insn(CPUS390XState
*env
, DisasContext
*s
)
1680 int op
, r1
, r2
, r3
, d2
, x2
, b2
, r1b
;
1682 opc
= cpu_ldub_code(env
, s
->pc
);
1683 LOG_DISAS("opc 0x%x\n", opc
);
1687 insn
= ld_code4(env
, s
->pc
);
1688 op
= (insn
>> 16) & 0xff;
1689 disas_b2(env
, s
, op
, insn
);
1692 insn
= ld_code4(env
, s
->pc
);
1693 op
= (insn
>> 16) & 0xff;
1694 r3
= (insn
>> 12) & 0xf; /* aka m3 */
1695 r1
= (insn
>> 4) & 0xf;
1697 disas_b3(env
, s
, op
, r3
, r1
, r2
);
1700 insn
= ld_code4(env
, s
->pc
);
1701 r1
= (insn
>> 4) & 0xf;
1703 op
= (insn
>> 16) & 0xff;
1704 disas_b9(env
, s
, op
, r1
, r2
);
1707 insn
= ld_code6(env
, s
->pc
);
1710 r1
= (insn
>> 36) & 0xf;
1711 x2
= (insn
>> 32) & 0xf;
1712 b2
= (insn
>> 28) & 0xf;
1713 d2
= (short)((insn
>> 16) & 0xfff);
1714 r1b
= (insn
>> 12) & 0xf;
1715 disas_ed(env
, s
, op
, r1
, x2
, b2
, d2
, r1b
);
1718 qemu_log_mask(LOG_UNIMP
, "unimplemented opcode 0x%x\n", opc
);
1719 gen_illegal_opcode(s
);
1724 /* ====================================================================== */
1725 /* Define the insn format enumeration. */
1726 #define F0(N) FMT_##N,
1727 #define F1(N, X1) F0(N)
1728 #define F2(N, X1, X2) F0(N)
1729 #define F3(N, X1, X2, X3) F0(N)
1730 #define F4(N, X1, X2, X3, X4) F0(N)
1731 #define F5(N, X1, X2, X3, X4, X5) F0(N)
1734 #include "insn-format.def"
1744 /* Define a structure to hold the decoded fields. We'll store each inside
1745 an array indexed by an enum. In order to conserve memory, we'll arrange
1746 for fields that do not exist at the same time to overlap, thus the "C"
1747 for compact. For checking purposes there is an "O" for original index
1748 as well that will be applied to availability bitmaps. */
1750 enum DisasFieldIndexO
{
1773 enum DisasFieldIndexC
{
1804 struct DisasFields
{
1807 unsigned presentC
:16;
1808 unsigned int presentO
;
1812 /* This is the way fields are to be accessed out of DisasFields. */
1813 #define have_field(S, F) have_field1((S), FLD_O_##F)
1814 #define get_field(S, F) get_field1((S), FLD_O_##F, FLD_C_##F)
1816 static bool have_field1(const DisasFields
*f
, enum DisasFieldIndexO c
)
1818 return (f
->presentO
>> c
) & 1;
1821 static int get_field1(const DisasFields
*f
, enum DisasFieldIndexO o
,
1822 enum DisasFieldIndexC c
)
1824 assert(have_field1(f
, o
));
1828 /* Describe the layout of each field in each format. */
1829 typedef struct DisasField
{
1831 unsigned int size
:8;
1832 unsigned int type
:2;
1833 unsigned int indexC
:6;
1834 enum DisasFieldIndexO indexO
:8;
1837 typedef struct DisasFormatInfo
{
1838 DisasField op
[NUM_C_FIELD
];
1841 #define R(N, B) { B, 4, 0, FLD_C_r##N, FLD_O_r##N }
1842 #define M(N, B) { B, 4, 0, FLD_C_m##N, FLD_O_m##N }
1843 #define BD(N, BB, BD) { BB, 4, 0, FLD_C_b##N, FLD_O_b##N }, \
1844 { BD, 12, 0, FLD_C_d##N, FLD_O_d##N }
1845 #define BXD(N) { 16, 4, 0, FLD_C_b##N, FLD_O_b##N }, \
1846 { 12, 4, 0, FLD_C_x##N, FLD_O_x##N }, \
1847 { 20, 12, 0, FLD_C_d##N, FLD_O_d##N }
1848 #define BDL(N) { 16, 4, 0, FLD_C_b##N, FLD_O_b##N }, \
1849 { 20, 20, 2, FLD_C_d##N, FLD_O_d##N }
1850 #define BXDL(N) { 16, 4, 0, FLD_C_b##N, FLD_O_b##N }, \
1851 { 12, 4, 0, FLD_C_x##N, FLD_O_x##N }, \
1852 { 20, 20, 2, FLD_C_d##N, FLD_O_d##N }
1853 #define I(N, B, S) { B, S, 1, FLD_C_i##N, FLD_O_i##N }
1854 #define L(N, B, S) { B, S, 0, FLD_C_l##N, FLD_O_l##N }
1856 #define F0(N) { { } },
1857 #define F1(N, X1) { { X1 } },
1858 #define F2(N, X1, X2) { { X1, X2 } },
1859 #define F3(N, X1, X2, X3) { { X1, X2, X3 } },
1860 #define F4(N, X1, X2, X3, X4) { { X1, X2, X3, X4 } },
1861 #define F5(N, X1, X2, X3, X4, X5) { { X1, X2, X3, X4, X5 } },
1863 static const DisasFormatInfo format_info
[] = {
1864 #include "insn-format.def"
1882 /* Generally, we'll extract operands into this structures, operate upon
1883 them, and store them back. See the "in1", "in2", "prep", "wout" sets
1884 of routines below for more details. */
1886 bool g_out
, g_out2
, g_in1
, g_in2
;
1887 TCGv_i64 out
, out2
, in1
, in2
;
1891 /* Return values from translate_one, indicating the state of the TB. */
1893 /* Continue the TB. */
1895 /* We have emitted one or more goto_tb. No fixup required. */
1897 /* We are not using a goto_tb (for whatever reason), but have updated
1898 the PC (for whatever reason), so there's no need to do it again on
1901 /* We are exiting the TB, but have neither emitted a goto_tb, nor
1902 updated the PC for the next instruction to be executed. */
1904 /* We are ending the TB with a noreturn function call, e.g. longjmp.
1905 No following code will be executed. */
1909 typedef enum DisasFacility
{
1910 FAC_Z
, /* zarch (default) */
1911 FAC_CASS
, /* compare and swap and store */
1912 FAC_CASS2
, /* compare and swap and store 2*/
1913 FAC_DFP
, /* decimal floating point */
1914 FAC_DFPR
, /* decimal floating point rounding */
1915 FAC_DO
, /* distinct operands */
1916 FAC_EE
, /* execute extensions */
1917 FAC_EI
, /* extended immediate */
1918 FAC_FPE
, /* floating point extension */
1919 FAC_FPSSH
, /* floating point support sign handling */
1920 FAC_FPRGR
, /* FPR-GR transfer */
1921 FAC_GIE
, /* general instructions extension */
1922 FAC_HFP_MA
, /* HFP multiply-and-add/subtract */
1923 FAC_HW
, /* high-word */
1924 FAC_IEEEE_SIM
, /* IEEE exception sumilation */
1925 FAC_LOC
, /* load/store on condition */
1926 FAC_LD
, /* long displacement */
1927 FAC_PC
, /* population count */
1928 FAC_SCF
, /* store clock fast */
1929 FAC_SFLE
, /* store facility list extended */
1935 DisasFacility fac
:6;
1939 void (*help_in1
)(DisasContext
*, DisasFields
*, DisasOps
*);
1940 void (*help_in2
)(DisasContext
*, DisasFields
*, DisasOps
*);
1941 void (*help_prep
)(DisasContext
*, DisasFields
*, DisasOps
*);
1942 void (*help_wout
)(DisasContext
*, DisasFields
*, DisasOps
*);
1943 void (*help_cout
)(DisasContext
*, DisasOps
*);
1944 ExitStatus (*help_op
)(DisasContext
*, DisasOps
*);
1949 /* ====================================================================== */
1950 /* Miscelaneous helpers, used by several operations. */
1952 static void help_l2_shift(DisasContext
*s
, DisasFields
*f
,
1953 DisasOps
*o
, int mask
)
1955 int b2
= get_field(f
, b2
);
1956 int d2
= get_field(f
, d2
);
1959 o
->in2
= tcg_const_i64(d2
& mask
);
1961 o
->in2
= get_address(s
, 0, b2
, d2
);
1962 tcg_gen_andi_i64(o
->in2
, o
->in2
, mask
);
1966 static ExitStatus
help_goto_direct(DisasContext
*s
, uint64_t dest
)
1968 if (dest
== s
->next_pc
) {
1971 if (use_goto_tb(s
, dest
)) {
1972 gen_update_cc_op(s
);
1974 tcg_gen_movi_i64(psw_addr
, dest
);
1975 tcg_gen_exit_tb((tcg_target_long
)s
->tb
);
1976 return EXIT_GOTO_TB
;
1978 tcg_gen_movi_i64(psw_addr
, dest
);
1979 return EXIT_PC_UPDATED
;
1983 static ExitStatus
help_branch(DisasContext
*s
, DisasCompare
*c
,
1984 bool is_imm
, int imm
, TCGv_i64 cdest
)
1987 uint64_t dest
= s
->pc
+ 2 * imm
;
1990 /* Take care of the special cases first. */
1991 if (c
->cond
== TCG_COND_NEVER
) {
1996 if (dest
== s
->next_pc
) {
1997 /* Branch to next. */
2001 if (c
->cond
== TCG_COND_ALWAYS
) {
2002 ret
= help_goto_direct(s
, dest
);
2006 if (TCGV_IS_UNUSED_I64(cdest
)) {
2007 /* E.g. bcr %r0 -> no branch. */
2011 if (c
->cond
== TCG_COND_ALWAYS
) {
2012 tcg_gen_mov_i64(psw_addr
, cdest
);
2013 ret
= EXIT_PC_UPDATED
;
2018 if (use_goto_tb(s
, s
->next_pc
)) {
2019 if (is_imm
&& use_goto_tb(s
, dest
)) {
2020 /* Both exits can use goto_tb. */
2021 gen_update_cc_op(s
);
2023 lab
= gen_new_label();
2025 tcg_gen_brcond_i64(c
->cond
, c
->u
.s64
.a
, c
->u
.s64
.b
, lab
);
2027 tcg_gen_brcond_i32(c
->cond
, c
->u
.s32
.a
, c
->u
.s32
.b
, lab
);
2030 /* Branch not taken. */
2032 tcg_gen_movi_i64(psw_addr
, s
->next_pc
);
2033 tcg_gen_exit_tb((tcg_target_long
)s
->tb
+ 0);
2038 tcg_gen_movi_i64(psw_addr
, dest
);
2039 tcg_gen_exit_tb((tcg_target_long
)s
->tb
+ 1);
2043 /* Fallthru can use goto_tb, but taken branch cannot. */
2044 /* Store taken branch destination before the brcond. This
2045 avoids having to allocate a new local temp to hold it.
2046 We'll overwrite this in the not taken case anyway. */
2048 tcg_gen_mov_i64(psw_addr
, cdest
);
2051 lab
= gen_new_label();
2053 tcg_gen_brcond_i64(c
->cond
, c
->u
.s64
.a
, c
->u
.s64
.b
, lab
);
2055 tcg_gen_brcond_i32(c
->cond
, c
->u
.s32
.a
, c
->u
.s32
.b
, lab
);
2058 /* Branch not taken. */
2059 gen_update_cc_op(s
);
2061 tcg_gen_movi_i64(psw_addr
, s
->next_pc
);
2062 tcg_gen_exit_tb((tcg_target_long
)s
->tb
+ 0);
2066 tcg_gen_movi_i64(psw_addr
, dest
);
2068 ret
= EXIT_PC_UPDATED
;
2071 /* Fallthru cannot use goto_tb. This by itself is vanishingly rare.
2072 Most commonly we're single-stepping or some other condition that
2073 disables all use of goto_tb. Just update the PC and exit. */
2075 TCGv_i64 next
= tcg_const_i64(s
->next_pc
);
2077 cdest
= tcg_const_i64(dest
);
2081 tcg_gen_movcond_i64(c
->cond
, psw_addr
, c
->u
.s64
.a
, c
->u
.s64
.b
,
2084 TCGv_i32 t0
= tcg_temp_new_i32();
2085 TCGv_i64 t1
= tcg_temp_new_i64();
2086 TCGv_i64 z
= tcg_const_i64(0);
2087 tcg_gen_setcond_i32(c
->cond
, t0
, c
->u
.s32
.a
, c
->u
.s32
.b
);
2088 tcg_gen_extu_i32_i64(t1
, t0
);
2089 tcg_temp_free_i32(t0
);
2090 tcg_gen_movcond_i64(TCG_COND_NE
, psw_addr
, t1
, z
, cdest
, next
);
2091 tcg_temp_free_i64(t1
);
2092 tcg_temp_free_i64(z
);
2096 tcg_temp_free_i64(cdest
);
2098 tcg_temp_free_i64(next
);
2100 ret
= EXIT_PC_UPDATED
;
2108 /* ====================================================================== */
2109 /* The operations. These perform the bulk of the work for any insn,
2110 usually after the operands have been loaded and output initialized. */
2112 static ExitStatus
op_abs(DisasContext
*s
, DisasOps
*o
)
2114 gen_helper_abs_i64(o
->out
, o
->in2
);
2118 static ExitStatus
op_add(DisasContext
*s
, DisasOps
*o
)
2120 tcg_gen_add_i64(o
->out
, o
->in1
, o
->in2
);
2124 static ExitStatus
op_addc(DisasContext
*s
, DisasOps
*o
)
2128 tcg_gen_add_i64(o
->out
, o
->in1
, o
->in2
);
2130 /* XXX possible optimization point */
2132 cc
= tcg_temp_new_i64();
2133 tcg_gen_extu_i32_i64(cc
, cc_op
);
2134 tcg_gen_shri_i64(cc
, cc
, 1);
2136 tcg_gen_add_i64(o
->out
, o
->out
, cc
);
2137 tcg_temp_free_i64(cc
);
2141 static ExitStatus
op_aeb(DisasContext
*s
, DisasOps
*o
)
2143 gen_helper_aeb(o
->out
, cpu_env
, o
->in1
, o
->in2
);
2147 static ExitStatus
op_adb(DisasContext
*s
, DisasOps
*o
)
2149 gen_helper_adb(o
->out
, cpu_env
, o
->in1
, o
->in2
);
2153 static ExitStatus
op_axb(DisasContext
*s
, DisasOps
*o
)
2155 gen_helper_axb(o
->out
, cpu_env
, o
->out
, o
->out2
, o
->in1
, o
->in2
);
2156 return_low128(o
->out2
);
2160 static ExitStatus
op_and(DisasContext
*s
, DisasOps
*o
)
2162 tcg_gen_and_i64(o
->out
, o
->in1
, o
->in2
);
2166 static ExitStatus
op_andi(DisasContext
*s
, DisasOps
*o
)
2168 int shift
= s
->insn
->data
& 0xff;
2169 int size
= s
->insn
->data
>> 8;
2170 uint64_t mask
= ((1ull << size
) - 1) << shift
;
2173 tcg_gen_shli_i64(o
->in2
, o
->in2
, shift
);
2174 tcg_gen_ori_i64(o
->in2
, o
->in2
, ~mask
);
2175 tcg_gen_and_i64(o
->out
, o
->in1
, o
->in2
);
2177 /* Produce the CC from only the bits manipulated. */
2178 tcg_gen_andi_i64(cc_dst
, o
->out
, mask
);
2179 set_cc_nz_u64(s
, cc_dst
);
2183 static ExitStatus
op_bas(DisasContext
*s
, DisasOps
*o
)
2185 tcg_gen_movi_i64(o
->out
, pc_to_link_info(s
, s
->next_pc
));
2186 if (!TCGV_IS_UNUSED_I64(o
->in2
)) {
2187 tcg_gen_mov_i64(psw_addr
, o
->in2
);
2188 return EXIT_PC_UPDATED
;
2194 static ExitStatus
op_basi(DisasContext
*s
, DisasOps
*o
)
2196 tcg_gen_movi_i64(o
->out
, pc_to_link_info(s
, s
->next_pc
));
2197 return help_goto_direct(s
, s
->pc
+ 2 * get_field(s
->fields
, i2
));
2200 static ExitStatus
op_bc(DisasContext
*s
, DisasOps
*o
)
2202 int m1
= get_field(s
->fields
, m1
);
2203 bool is_imm
= have_field(s
->fields
, i2
);
2204 int imm
= is_imm
? get_field(s
->fields
, i2
) : 0;
2207 disas_jcc(s
, &c
, m1
);
2208 return help_branch(s
, &c
, is_imm
, imm
, o
->in2
);
2211 static ExitStatus
op_bct32(DisasContext
*s
, DisasOps
*o
)
2213 int r1
= get_field(s
->fields
, r1
);
2214 bool is_imm
= have_field(s
->fields
, i2
);
2215 int imm
= is_imm
? get_field(s
->fields
, i2
) : 0;
2219 c
.cond
= TCG_COND_NE
;
2224 t
= tcg_temp_new_i64();
2225 tcg_gen_subi_i64(t
, regs
[r1
], 1);
2226 store_reg32_i64(r1
, t
);
2227 c
.u
.s32
.a
= tcg_temp_new_i32();
2228 c
.u
.s32
.b
= tcg_const_i32(0);
2229 tcg_gen_trunc_i64_i32(c
.u
.s32
.a
, t
);
2230 tcg_temp_free_i64(t
);
2232 return help_branch(s
, &c
, is_imm
, imm
, o
->in2
);
2235 static ExitStatus
op_bct64(DisasContext
*s
, DisasOps
*o
)
2237 int r1
= get_field(s
->fields
, r1
);
2238 bool is_imm
= have_field(s
->fields
, i2
);
2239 int imm
= is_imm
? get_field(s
->fields
, i2
) : 0;
2242 c
.cond
= TCG_COND_NE
;
2247 tcg_gen_subi_i64(regs
[r1
], regs
[r1
], 1);
2248 c
.u
.s64
.a
= regs
[r1
];
2249 c
.u
.s64
.b
= tcg_const_i64(0);
2251 return help_branch(s
, &c
, is_imm
, imm
, o
->in2
);
2254 static ExitStatus
op_ceb(DisasContext
*s
, DisasOps
*o
)
2256 gen_helper_ceb(cc_op
, cpu_env
, o
->in1
, o
->in2
);
2261 static ExitStatus
op_cdb(DisasContext
*s
, DisasOps
*o
)
2263 gen_helper_cdb(cc_op
, cpu_env
, o
->in1
, o
->in2
);
2268 static ExitStatus
op_cxb(DisasContext
*s
, DisasOps
*o
)
2270 gen_helper_cxb(cc_op
, cpu_env
, o
->out
, o
->out2
, o
->in1
, o
->in2
);
2275 static ExitStatus
op_clc(DisasContext
*s
, DisasOps
*o
)
2277 int l
= get_field(s
->fields
, l1
);
2282 tcg_gen_qemu_ld8u(cc_src
, o
->addr1
, get_mem_index(s
));
2283 tcg_gen_qemu_ld8u(cc_dst
, o
->in2
, get_mem_index(s
));
2286 tcg_gen_qemu_ld16u(cc_src
, o
->addr1
, get_mem_index(s
));
2287 tcg_gen_qemu_ld16u(cc_dst
, o
->in2
, get_mem_index(s
));
2290 tcg_gen_qemu_ld32u(cc_src
, o
->addr1
, get_mem_index(s
));
2291 tcg_gen_qemu_ld32u(cc_dst
, o
->in2
, get_mem_index(s
));
2294 tcg_gen_qemu_ld64(cc_src
, o
->addr1
, get_mem_index(s
));
2295 tcg_gen_qemu_ld64(cc_dst
, o
->in2
, get_mem_index(s
));
2298 potential_page_fault(s
);
2299 vl
= tcg_const_i32(l
);
2300 gen_helper_clc(cc_op
, cpu_env
, vl
, o
->addr1
, o
->in2
);
2301 tcg_temp_free_i32(vl
);
2305 gen_op_update2_cc_i64(s
, CC_OP_LTUGTU_64
, cc_src
, cc_dst
);
2309 static ExitStatus
op_clcle(DisasContext
*s
, DisasOps
*o
)
2311 TCGv_i32 r1
= tcg_const_i32(get_field(s
->fields
, r1
));
2312 TCGv_i32 r3
= tcg_const_i32(get_field(s
->fields
, r3
));
2313 potential_page_fault(s
);
2314 gen_helper_clcle(cc_op
, cpu_env
, r1
, o
->in2
, r3
);
2315 tcg_temp_free_i32(r1
);
2316 tcg_temp_free_i32(r3
);
2321 static ExitStatus
op_clm(DisasContext
*s
, DisasOps
*o
)
2323 TCGv_i32 m3
= tcg_const_i32(get_field(s
->fields
, m3
));
2324 TCGv_i32 t1
= tcg_temp_new_i32();
2325 tcg_gen_trunc_i64_i32(t1
, o
->in1
);
2326 potential_page_fault(s
);
2327 gen_helper_clm(cc_op
, cpu_env
, t1
, m3
, o
->in2
);
2329 tcg_temp_free_i32(t1
);
2330 tcg_temp_free_i32(m3
);
2334 static ExitStatus
op_cs(DisasContext
*s
, DisasOps
*o
)
2336 int r3
= get_field(s
->fields
, r3
);
2337 potential_page_fault(s
);
2338 gen_helper_cs(o
->out
, cpu_env
, o
->in1
, o
->in2
, regs
[r3
]);
2343 static ExitStatus
op_csg(DisasContext
*s
, DisasOps
*o
)
2345 int r3
= get_field(s
->fields
, r3
);
2346 potential_page_fault(s
);
2347 gen_helper_csg(o
->out
, cpu_env
, o
->in1
, o
->in2
, regs
[r3
]);
2352 static ExitStatus
op_cds(DisasContext
*s
, DisasOps
*o
)
2354 int r3
= get_field(s
->fields
, r3
);
2355 TCGv_i64 in3
= tcg_temp_new_i64();
2356 tcg_gen_deposit_i64(in3
, regs
[r3
+ 1], regs
[r3
], 32, 32);
2357 potential_page_fault(s
);
2358 gen_helper_csg(o
->out
, cpu_env
, o
->in1
, o
->in2
, in3
);
2359 tcg_temp_free_i64(in3
);
2364 static ExitStatus
op_cdsg(DisasContext
*s
, DisasOps
*o
)
2366 TCGv_i32 r1
= tcg_const_i32(get_field(s
->fields
, r1
));
2367 TCGv_i32 r3
= tcg_const_i32(get_field(s
->fields
, r3
));
2368 potential_page_fault(s
);
2369 /* XXX rewrite in tcg */
2370 gen_helper_cdsg(cc_op
, cpu_env
, r1
, o
->in2
, r3
);
2375 static ExitStatus
op_cvd(DisasContext
*s
, DisasOps
*o
)
2377 TCGv_i64 t1
= tcg_temp_new_i64();
2378 TCGv_i32 t2
= tcg_temp_new_i32();
2379 tcg_gen_trunc_i64_i32(t2
, o
->in1
);
2380 gen_helper_cvd(t1
, t2
);
2381 tcg_temp_free_i32(t2
);
2382 tcg_gen_qemu_st64(t1
, o
->in2
, get_mem_index(s
));
2383 tcg_temp_free_i64(t1
);
2387 #ifndef CONFIG_USER_ONLY
2388 static ExitStatus
op_diag(DisasContext
*s
, DisasOps
*o
)
2392 check_privileged(s
);
2393 potential_page_fault(s
);
2395 /* We pretend the format is RX_a so that D2 is the field we want. */
2396 tmp
= tcg_const_i32(get_field(s
->fields
, d2
) & 0xfff);
2397 gen_helper_diag(regs
[2], cpu_env
, tmp
, regs
[2], regs
[1]);
2398 tcg_temp_free_i32(tmp
);
2403 static ExitStatus
op_divs32(DisasContext
*s
, DisasOps
*o
)
2405 gen_helper_divs32(o
->out2
, cpu_env
, o
->in1
, o
->in2
);
2406 return_low128(o
->out
);
2410 static ExitStatus
op_divu32(DisasContext
*s
, DisasOps
*o
)
2412 gen_helper_divu32(o
->out2
, cpu_env
, o
->in1
, o
->in2
);
2413 return_low128(o
->out
);
2417 static ExitStatus
op_divs64(DisasContext
*s
, DisasOps
*o
)
2419 gen_helper_divs64(o
->out2
, cpu_env
, o
->in1
, o
->in2
);
2420 return_low128(o
->out
);
2424 static ExitStatus
op_divu64(DisasContext
*s
, DisasOps
*o
)
2426 gen_helper_divu64(o
->out2
, cpu_env
, o
->out
, o
->out2
, o
->in2
);
2427 return_low128(o
->out
);
2431 static ExitStatus
op_efpc(DisasContext
*s
, DisasOps
*o
)
2433 tcg_gen_ld32u_i64(o
->out
, cpu_env
, offsetof(CPUS390XState
, fpc
));
2437 static ExitStatus
op_ex(DisasContext
*s
, DisasOps
*o
)
2439 /* ??? Perhaps a better way to implement EXECUTE is to set a bit in
2440 tb->flags, (ab)use the tb->cs_base field as the address of
2441 the template in memory, and grab 8 bits of tb->flags/cflags for
2442 the contents of the register. We would then recognize all this
2443 in gen_intermediate_code_internal, generating code for exactly
2444 one instruction. This new TB then gets executed normally.
2446 On the other hand, this seems to be mostly used for modifying
2447 MVC inside of memcpy, which needs a helper call anyway. So
2448 perhaps this doesn't bear thinking about any further. */
2455 tmp
= tcg_const_i64(s
->next_pc
);
2456 gen_helper_ex(cc_op
, cpu_env
, cc_op
, o
->in1
, o
->in2
, tmp
);
2457 tcg_temp_free_i64(tmp
);
2463 static ExitStatus
op_icm(DisasContext
*s
, DisasOps
*o
)
2465 int m3
= get_field(s
->fields
, m3
);
2466 int pos
, len
, base
= s
->insn
->data
;
2467 TCGv_i64 tmp
= tcg_temp_new_i64();
2472 /* Effectively a 32-bit load. */
2473 tcg_gen_qemu_ld32u(tmp
, o
->in2
, get_mem_index(s
));
2480 /* Effectively a 16-bit load. */
2481 tcg_gen_qemu_ld16u(tmp
, o
->in2
, get_mem_index(s
));
2489 /* Effectively an 8-bit load. */
2490 tcg_gen_qemu_ld8u(tmp
, o
->in2
, get_mem_index(s
));
2495 pos
= base
+ ctz32(m3
) * 8;
2496 tcg_gen_deposit_i64(o
->out
, o
->out
, tmp
, pos
, len
);
2497 ccm
= ((1ull << len
) - 1) << pos
;
2501 /* This is going to be a sequence of loads and inserts. */
2502 pos
= base
+ 32 - 8;
2506 tcg_gen_qemu_ld8u(tmp
, o
->in2
, get_mem_index(s
));
2507 tcg_gen_addi_i64(o
->in2
, o
->in2
, 1);
2508 tcg_gen_deposit_i64(o
->out
, o
->out
, tmp
, pos
, 8);
2511 m3
= (m3
<< 1) & 0xf;
2517 tcg_gen_movi_i64(tmp
, ccm
);
2518 gen_op_update2_cc_i64(s
, CC_OP_ICM
, tmp
, o
->out
);
2519 tcg_temp_free_i64(tmp
);
2523 static ExitStatus
op_insi(DisasContext
*s
, DisasOps
*o
)
2525 int shift
= s
->insn
->data
& 0xff;
2526 int size
= s
->insn
->data
>> 8;
2527 tcg_gen_deposit_i64(o
->out
, o
->in1
, o
->in2
, shift
, size
);
2531 static ExitStatus
op_ldeb(DisasContext
*s
, DisasOps
*o
)
2533 gen_helper_ldeb(o
->out
, cpu_env
, o
->in2
);
2537 static ExitStatus
op_ledb(DisasContext
*s
, DisasOps
*o
)
2539 gen_helper_ledb(o
->out
, cpu_env
, o
->in2
);
2543 static ExitStatus
op_ldxb(DisasContext
*s
, DisasOps
*o
)
2545 gen_helper_ldxb(o
->out
, cpu_env
, o
->in1
, o
->in2
);
2549 static ExitStatus
op_lexb(DisasContext
*s
, DisasOps
*o
)
2551 gen_helper_lexb(o
->out
, cpu_env
, o
->in1
, o
->in2
);
2555 static ExitStatus
op_lxdb(DisasContext
*s
, DisasOps
*o
)
2557 gen_helper_lxdb(o
->out
, cpu_env
, o
->in2
);
2558 return_low128(o
->out2
);
2562 static ExitStatus
op_lxeb(DisasContext
*s
, DisasOps
*o
)
2564 gen_helper_lxeb(o
->out
, cpu_env
, o
->in2
);
2565 return_low128(o
->out2
);
2569 static ExitStatus
op_llgt(DisasContext
*s
, DisasOps
*o
)
2571 tcg_gen_andi_i64(o
->out
, o
->in2
, 0x7fffffff);
2575 static ExitStatus
op_ld8s(DisasContext
*s
, DisasOps
*o
)
2577 tcg_gen_qemu_ld8s(o
->out
, o
->in2
, get_mem_index(s
));
2581 static ExitStatus
op_ld8u(DisasContext
*s
, DisasOps
*o
)
2583 tcg_gen_qemu_ld8u(o
->out
, o
->in2
, get_mem_index(s
));
2587 static ExitStatus
op_ld16s(DisasContext
*s
, DisasOps
*o
)
2589 tcg_gen_qemu_ld16s(o
->out
, o
->in2
, get_mem_index(s
));
2593 static ExitStatus
op_ld16u(DisasContext
*s
, DisasOps
*o
)
2595 tcg_gen_qemu_ld16u(o
->out
, o
->in2
, get_mem_index(s
));
2599 static ExitStatus
op_ld32s(DisasContext
*s
, DisasOps
*o
)
2601 tcg_gen_qemu_ld32s(o
->out
, o
->in2
, get_mem_index(s
));
2605 static ExitStatus
op_ld32u(DisasContext
*s
, DisasOps
*o
)
2607 tcg_gen_qemu_ld32u(o
->out
, o
->in2
, get_mem_index(s
));
2611 static ExitStatus
op_ld64(DisasContext
*s
, DisasOps
*o
)
2613 tcg_gen_qemu_ld64(o
->out
, o
->in2
, get_mem_index(s
));
2617 #ifndef CONFIG_USER_ONLY
2618 static ExitStatus
op_lctl(DisasContext
*s
, DisasOps
*o
)
2620 TCGv_i32 r1
= tcg_const_i32(get_field(s
->fields
, r1
));
2621 TCGv_i32 r3
= tcg_const_i32(get_field(s
->fields
, r3
));
2622 check_privileged(s
);
2623 potential_page_fault(s
);
2624 gen_helper_lctl(cpu_env
, r1
, o
->in2
, r3
);
2625 tcg_temp_free_i32(r1
);
2626 tcg_temp_free_i32(r3
);
2630 static ExitStatus
op_lctlg(DisasContext
*s
, DisasOps
*o
)
2632 TCGv_i32 r1
= tcg_const_i32(get_field(s
->fields
, r1
));
2633 TCGv_i32 r3
= tcg_const_i32(get_field(s
->fields
, r3
));
2634 check_privileged(s
);
2635 potential_page_fault(s
);
2636 gen_helper_lctlg(cpu_env
, r1
, o
->in2
, r3
);
2637 tcg_temp_free_i32(r1
);
2638 tcg_temp_free_i32(r3
);
2641 static ExitStatus
op_lra(DisasContext
*s
, DisasOps
*o
)
2643 check_privileged(s
);
2644 potential_page_fault(s
);
2645 gen_helper_lra(o
->out
, cpu_env
, o
->in2
);
2650 static ExitStatus
op_lpsw(DisasContext
*s
, DisasOps
*o
)
2654 check_privileged(s
);
2656 t1
= tcg_temp_new_i64();
2657 t2
= tcg_temp_new_i64();
2658 tcg_gen_qemu_ld32u(t1
, o
->in2
, get_mem_index(s
));
2659 tcg_gen_addi_i64(o
->in2
, o
->in2
, 4);
2660 tcg_gen_qemu_ld32u(t2
, o
->in2
, get_mem_index(s
));
2661 /* Convert the 32-bit PSW_MASK into the 64-bit PSW_MASK. */
2662 tcg_gen_shli_i64(t1
, t1
, 32);
2663 gen_helper_load_psw(cpu_env
, t1
, t2
);
2664 tcg_temp_free_i64(t1
);
2665 tcg_temp_free_i64(t2
);
2666 return EXIT_NORETURN
;
2670 static ExitStatus
op_lam(DisasContext
*s
, DisasOps
*o
)
2672 TCGv_i32 r1
= tcg_const_i32(get_field(s
->fields
, r1
));
2673 TCGv_i32 r3
= tcg_const_i32(get_field(s
->fields
, r3
));
2674 potential_page_fault(s
);
2675 gen_helper_lam(cpu_env
, r1
, o
->in2
, r3
);
2676 tcg_temp_free_i32(r1
);
2677 tcg_temp_free_i32(r3
);
2681 static ExitStatus
op_lm32(DisasContext
*s
, DisasOps
*o
)
2683 int r1
= get_field(s
->fields
, r1
);
2684 int r3
= get_field(s
->fields
, r3
);
2685 TCGv_i64 t
= tcg_temp_new_i64();
2686 TCGv_i64 t4
= tcg_const_i64(4);
2689 tcg_gen_qemu_ld32u(t
, o
->in2
, get_mem_index(s
));
2690 store_reg32_i64(r1
, t
);
2694 tcg_gen_add_i64(o
->in2
, o
->in2
, t4
);
2698 tcg_temp_free_i64(t
);
2699 tcg_temp_free_i64(t4
);
2703 static ExitStatus
op_lmh(DisasContext
*s
, DisasOps
*o
)
2705 int r1
= get_field(s
->fields
, r1
);
2706 int r3
= get_field(s
->fields
, r3
);
2707 TCGv_i64 t
= tcg_temp_new_i64();
2708 TCGv_i64 t4
= tcg_const_i64(4);
2711 tcg_gen_qemu_ld32u(t
, o
->in2
, get_mem_index(s
));
2712 store_reg32h_i64(r1
, t
);
2716 tcg_gen_add_i64(o
->in2
, o
->in2
, t4
);
2720 tcg_temp_free_i64(t
);
2721 tcg_temp_free_i64(t4
);
2725 static ExitStatus
op_lm64(DisasContext
*s
, DisasOps
*o
)
2727 int r1
= get_field(s
->fields
, r1
);
2728 int r3
= get_field(s
->fields
, r3
);
2729 TCGv_i64 t8
= tcg_const_i64(8);
2732 tcg_gen_qemu_ld64(regs
[r1
], o
->in2
, get_mem_index(s
));
2736 tcg_gen_add_i64(o
->in2
, o
->in2
, t8
);
2740 tcg_temp_free_i64(t8
);
2744 static ExitStatus
op_mov2(DisasContext
*s
, DisasOps
*o
)
2747 o
->g_out
= o
->g_in2
;
2748 TCGV_UNUSED_I64(o
->in2
);
2753 static ExitStatus
op_movx(DisasContext
*s
, DisasOps
*o
)
2757 o
->g_out
= o
->g_in1
;
2758 o
->g_out2
= o
->g_in2
;
2759 TCGV_UNUSED_I64(o
->in1
);
2760 TCGV_UNUSED_I64(o
->in2
);
2761 o
->g_in1
= o
->g_in2
= false;
2765 static ExitStatus
op_mvc(DisasContext
*s
, DisasOps
*o
)
2767 TCGv_i32 l
= tcg_const_i32(get_field(s
->fields
, l1
));
2768 potential_page_fault(s
);
2769 gen_helper_mvc(cpu_env
, l
, o
->addr1
, o
->in2
);
2770 tcg_temp_free_i32(l
);
2774 static ExitStatus
op_mvcl(DisasContext
*s
, DisasOps
*o
)
2776 TCGv_i32 r1
= tcg_const_i32(get_field(s
->fields
, r1
));
2777 TCGv_i32 r2
= tcg_const_i32(get_field(s
->fields
, r2
));
2778 potential_page_fault(s
);
2779 gen_helper_mvcl(cc_op
, cpu_env
, r1
, r2
);
2780 tcg_temp_free_i32(r1
);
2781 tcg_temp_free_i32(r2
);
2786 static ExitStatus
op_mvcle(DisasContext
*s
, DisasOps
*o
)
2788 TCGv_i32 r1
= tcg_const_i32(get_field(s
->fields
, r1
));
2789 TCGv_i32 r3
= tcg_const_i32(get_field(s
->fields
, r3
));
2790 potential_page_fault(s
);
2791 gen_helper_mvcle(cc_op
, cpu_env
, r1
, o
->in2
, r3
);
2792 tcg_temp_free_i32(r1
);
2793 tcg_temp_free_i32(r3
);
2798 #ifndef CONFIG_USER_ONLY
2799 static ExitStatus
op_mvcp(DisasContext
*s
, DisasOps
*o
)
2801 int r1
= get_field(s
->fields
, l1
);
2802 check_privileged(s
);
2803 potential_page_fault(s
);
2804 gen_helper_mvcp(cc_op
, cpu_env
, regs
[r1
], o
->addr1
, o
->in2
);
2809 static ExitStatus
op_mvcs(DisasContext
*s
, DisasOps
*o
)
2811 int r1
= get_field(s
->fields
, l1
);
2812 check_privileged(s
);
2813 potential_page_fault(s
);
2814 gen_helper_mvcs(cc_op
, cpu_env
, regs
[r1
], o
->addr1
, o
->in2
);
2820 static ExitStatus
op_mul(DisasContext
*s
, DisasOps
*o
)
2822 tcg_gen_mul_i64(o
->out
, o
->in1
, o
->in2
);
2826 static ExitStatus
op_mul128(DisasContext
*s
, DisasOps
*o
)
2828 gen_helper_mul128(o
->out
, cpu_env
, o
->in1
, o
->in2
);
2829 return_low128(o
->out2
);
2833 static ExitStatus
op_nabs(DisasContext
*s
, DisasOps
*o
)
2835 gen_helper_nabs_i64(o
->out
, o
->in2
);
2839 static ExitStatus
op_nc(DisasContext
*s
, DisasOps
*o
)
2841 TCGv_i32 l
= tcg_const_i32(get_field(s
->fields
, l1
));
2842 potential_page_fault(s
);
2843 gen_helper_nc(cc_op
, cpu_env
, l
, o
->addr1
, o
->in2
);
2844 tcg_temp_free_i32(l
);
2849 static ExitStatus
op_neg(DisasContext
*s
, DisasOps
*o
)
2851 tcg_gen_neg_i64(o
->out
, o
->in2
);
2855 static ExitStatus
op_oc(DisasContext
*s
, DisasOps
*o
)
2857 TCGv_i32 l
= tcg_const_i32(get_field(s
->fields
, l1
));
2858 potential_page_fault(s
);
2859 gen_helper_oc(cc_op
, cpu_env
, l
, o
->addr1
, o
->in2
);
2860 tcg_temp_free_i32(l
);
2865 static ExitStatus
op_or(DisasContext
*s
, DisasOps
*o
)
2867 tcg_gen_or_i64(o
->out
, o
->in1
, o
->in2
);
2871 static ExitStatus
op_ori(DisasContext
*s
, DisasOps
*o
)
2873 int shift
= s
->insn
->data
& 0xff;
2874 int size
= s
->insn
->data
>> 8;
2875 uint64_t mask
= ((1ull << size
) - 1) << shift
;
2878 tcg_gen_shli_i64(o
->in2
, o
->in2
, shift
);
2879 tcg_gen_or_i64(o
->out
, o
->in1
, o
->in2
);
2881 /* Produce the CC from only the bits manipulated. */
2882 tcg_gen_andi_i64(cc_dst
, o
->out
, mask
);
2883 set_cc_nz_u64(s
, cc_dst
);
2887 static ExitStatus
op_rev16(DisasContext
*s
, DisasOps
*o
)
2889 tcg_gen_bswap16_i64(o
->out
, o
->in2
);
2893 static ExitStatus
op_rev32(DisasContext
*s
, DisasOps
*o
)
2895 tcg_gen_bswap32_i64(o
->out
, o
->in2
);
2899 static ExitStatus
op_rev64(DisasContext
*s
, DisasOps
*o
)
2901 tcg_gen_bswap64_i64(o
->out
, o
->in2
);
2905 static ExitStatus
op_rll32(DisasContext
*s
, DisasOps
*o
)
2907 TCGv_i32 t1
= tcg_temp_new_i32();
2908 TCGv_i32 t2
= tcg_temp_new_i32();
2909 TCGv_i32 to
= tcg_temp_new_i32();
2910 tcg_gen_trunc_i64_i32(t1
, o
->in1
);
2911 tcg_gen_trunc_i64_i32(t2
, o
->in2
);
2912 tcg_gen_rotl_i32(to
, t1
, t2
);
2913 tcg_gen_extu_i32_i64(o
->out
, to
);
2914 tcg_temp_free_i32(t1
);
2915 tcg_temp_free_i32(t2
);
2916 tcg_temp_free_i32(to
);
2920 static ExitStatus
op_rll64(DisasContext
*s
, DisasOps
*o
)
2922 tcg_gen_rotl_i64(o
->out
, o
->in1
, o
->in2
);
2926 static ExitStatus
op_seb(DisasContext
*s
, DisasOps
*o
)
2928 gen_helper_seb(o
->out
, cpu_env
, o
->in1
, o
->in2
);
2932 static ExitStatus
op_sdb(DisasContext
*s
, DisasOps
*o
)
2934 gen_helper_sdb(o
->out
, cpu_env
, o
->in1
, o
->in2
);
2938 static ExitStatus
op_sxb(DisasContext
*s
, DisasOps
*o
)
2940 gen_helper_sxb(o
->out
, cpu_env
, o
->out
, o
->out2
, o
->in1
, o
->in2
);
2941 return_low128(o
->out2
);
2945 #ifndef CONFIG_USER_ONLY
2946 static ExitStatus
op_sigp(DisasContext
*s
, DisasOps
*o
)
2948 TCGv_i32 r1
= tcg_const_i32(get_field(s
->fields
, r1
));
2949 check_privileged(s
);
2950 potential_page_fault(s
);
2951 gen_helper_sigp(cc_op
, cpu_env
, o
->in2
, r1
, o
->in1
);
2952 tcg_temp_free_i32(r1
);
2957 static ExitStatus
op_sla(DisasContext
*s
, DisasOps
*o
)
2959 uint64_t sign
= 1ull << s
->insn
->data
;
2960 enum cc_op cco
= s
->insn
->data
== 31 ? CC_OP_SLA_32
: CC_OP_SLA_64
;
2961 gen_op_update2_cc_i64(s
, cco
, o
->in1
, o
->in2
);
2962 tcg_gen_shl_i64(o
->out
, o
->in1
, o
->in2
);
2963 /* The arithmetic left shift is curious in that it does not affect
2964 the sign bit. Copy that over from the source unchanged. */
2965 tcg_gen_andi_i64(o
->out
, o
->out
, ~sign
);
2966 tcg_gen_andi_i64(o
->in1
, o
->in1
, sign
);
2967 tcg_gen_or_i64(o
->out
, o
->out
, o
->in1
);
2971 static ExitStatus
op_sll(DisasContext
*s
, DisasOps
*o
)
2973 tcg_gen_shl_i64(o
->out
, o
->in1
, o
->in2
);
2977 static ExitStatus
op_sra(DisasContext
*s
, DisasOps
*o
)
2979 tcg_gen_sar_i64(o
->out
, o
->in1
, o
->in2
);
2983 static ExitStatus
op_srl(DisasContext
*s
, DisasOps
*o
)
2985 tcg_gen_shr_i64(o
->out
, o
->in1
, o
->in2
);
2989 #ifndef CONFIG_USER_ONLY
2990 static ExitStatus
op_ssm(DisasContext
*s
, DisasOps
*o
)
2992 check_privileged(s
);
2993 tcg_gen_deposit_i64(psw_mask
, psw_mask
, o
->in2
, 56, 8);
2997 static ExitStatus
op_stctg(DisasContext
*s
, DisasOps
*o
)
2999 TCGv_i32 r1
= tcg_const_i32(get_field(s
->fields
, r1
));
3000 TCGv_i32 r3
= tcg_const_i32(get_field(s
->fields
, r3
));
3001 check_privileged(s
);
3002 potential_page_fault(s
);
3003 gen_helper_stctg(cpu_env
, r1
, o
->in2
, r3
);
3004 tcg_temp_free_i32(r1
);
3005 tcg_temp_free_i32(r3
);
3009 static ExitStatus
op_stctl(DisasContext
*s
, DisasOps
*o
)
3011 TCGv_i32 r1
= tcg_const_i32(get_field(s
->fields
, r1
));
3012 TCGv_i32 r3
= tcg_const_i32(get_field(s
->fields
, r3
));
3013 check_privileged(s
);
3014 potential_page_fault(s
);
3015 gen_helper_stctl(cpu_env
, r1
, o
->in2
, r3
);
3016 tcg_temp_free_i32(r1
);
3017 tcg_temp_free_i32(r3
);
3021 static ExitStatus
op_stnosm(DisasContext
*s
, DisasOps
*o
)
3023 uint64_t i2
= get_field(s
->fields
, i2
);
3026 check_privileged(s
);
3028 /* It is important to do what the instruction name says: STORE THEN.
3029 If we let the output hook perform the store then if we fault and
3030 restart, we'll have the wrong SYSTEM MASK in place. */
3031 t
= tcg_temp_new_i64();
3032 tcg_gen_shri_i64(t
, psw_mask
, 56);
3033 tcg_gen_qemu_st8(t
, o
->addr1
, get_mem_index(s
));
3034 tcg_temp_free_i64(t
);
3036 if (s
->fields
->op
== 0xac) {
3037 tcg_gen_andi_i64(psw_mask
, psw_mask
,
3038 (i2
<< 56) | 0x00ffffffffffffffull
);
3040 tcg_gen_ori_i64(psw_mask
, psw_mask
, i2
<< 56);
3046 static ExitStatus
op_st8(DisasContext
*s
, DisasOps
*o
)
3048 tcg_gen_qemu_st8(o
->in1
, o
->in2
, get_mem_index(s
));
3052 static ExitStatus
op_st16(DisasContext
*s
, DisasOps
*o
)
3054 tcg_gen_qemu_st16(o
->in1
, o
->in2
, get_mem_index(s
));
3058 static ExitStatus
op_st32(DisasContext
*s
, DisasOps
*o
)
3060 tcg_gen_qemu_st32(o
->in1
, o
->in2
, get_mem_index(s
));
3064 static ExitStatus
op_st64(DisasContext
*s
, DisasOps
*o
)
3066 tcg_gen_qemu_st64(o
->in1
, o
->in2
, get_mem_index(s
));
3070 static ExitStatus
op_stam(DisasContext
*s
, DisasOps
*o
)
3072 TCGv_i32 r1
= tcg_const_i32(get_field(s
->fields
, r1
));
3073 TCGv_i32 r3
= tcg_const_i32(get_field(s
->fields
, r3
));
3074 potential_page_fault(s
);
3075 gen_helper_stam(cpu_env
, r1
, o
->in2
, r3
);
3076 tcg_temp_free_i32(r1
);
3077 tcg_temp_free_i32(r3
);
3081 static ExitStatus
op_stcm(DisasContext
*s
, DisasOps
*o
)
3083 int m3
= get_field(s
->fields
, m3
);
3084 int pos
, base
= s
->insn
->data
;
3085 TCGv_i64 tmp
= tcg_temp_new_i64();
3087 pos
= base
+ ctz32(m3
) * 8;
3090 /* Effectively a 32-bit store. */
3091 tcg_gen_shri_i64(tmp
, o
->in1
, pos
);
3092 tcg_gen_qemu_st32(tmp
, o
->in2
, get_mem_index(s
));
3098 /* Effectively a 16-bit store. */
3099 tcg_gen_shri_i64(tmp
, o
->in1
, pos
);
3100 tcg_gen_qemu_st16(tmp
, o
->in2
, get_mem_index(s
));
3107 /* Effectively an 8-bit store. */
3108 tcg_gen_shri_i64(tmp
, o
->in1
, pos
);
3109 tcg_gen_qemu_st8(tmp
, o
->in2
, get_mem_index(s
));
3113 /* This is going to be a sequence of shifts and stores. */
3114 pos
= base
+ 32 - 8;
3117 tcg_gen_shri_i64(tmp
, o
->in1
, pos
);
3118 tcg_gen_qemu_st8(tmp
, o
->in2
, get_mem_index(s
));
3119 tcg_gen_addi_i64(o
->in2
, o
->in2
, 1);
3121 m3
= (m3
<< 1) & 0xf;
3126 tcg_temp_free_i64(tmp
);
3130 static ExitStatus
op_stm(DisasContext
*s
, DisasOps
*o
)
3132 int r1
= get_field(s
->fields
, r1
);
3133 int r3
= get_field(s
->fields
, r3
);
3134 int size
= s
->insn
->data
;
3135 TCGv_i64 tsize
= tcg_const_i64(size
);
3139 tcg_gen_qemu_st64(regs
[r1
], o
->in2
, get_mem_index(s
));
3141 tcg_gen_qemu_st32(regs
[r1
], o
->in2
, get_mem_index(s
));
3146 tcg_gen_add_i64(o
->in2
, o
->in2
, tsize
);
3150 tcg_temp_free_i64(tsize
);
3154 static ExitStatus
op_stmh(DisasContext
*s
, DisasOps
*o
)
3156 int r1
= get_field(s
->fields
, r1
);
3157 int r3
= get_field(s
->fields
, r3
);
3158 TCGv_i64 t
= tcg_temp_new_i64();
3159 TCGv_i64 t4
= tcg_const_i64(4);
3160 TCGv_i64 t32
= tcg_const_i64(32);
3163 tcg_gen_shl_i64(t
, regs
[r1
], t32
);
3164 tcg_gen_qemu_st32(t
, o
->in2
, get_mem_index(s
));
3168 tcg_gen_add_i64(o
->in2
, o
->in2
, t4
);
3172 tcg_temp_free_i64(t
);
3173 tcg_temp_free_i64(t4
);
3174 tcg_temp_free_i64(t32
);
3178 static ExitStatus
op_sub(DisasContext
*s
, DisasOps
*o
)
3180 tcg_gen_sub_i64(o
->out
, o
->in1
, o
->in2
);
3184 static ExitStatus
op_subb(DisasContext
*s
, DisasOps
*o
)
3189 tcg_gen_not_i64(o
->in2
, o
->in2
);
3190 tcg_gen_add_i64(o
->out
, o
->in1
, o
->in2
);
3192 /* XXX possible optimization point */
3194 cc
= tcg_temp_new_i64();
3195 tcg_gen_extu_i32_i64(cc
, cc_op
);
3196 tcg_gen_shri_i64(cc
, cc
, 1);
3197 tcg_gen_add_i64(o
->out
, o
->out
, cc
);
3198 tcg_temp_free_i64(cc
);
3202 static ExitStatus
op_svc(DisasContext
*s
, DisasOps
*o
)
3209 t
= tcg_const_i32(get_field(s
->fields
, i1
) & 0xff);
3210 tcg_gen_st_i32(t
, cpu_env
, offsetof(CPUS390XState
, int_svc_code
));
3211 tcg_temp_free_i32(t
);
3213 t
= tcg_const_i32(s
->next_pc
- s
->pc
);
3214 tcg_gen_st_i32(t
, cpu_env
, offsetof(CPUS390XState
, int_svc_ilen
));
3215 tcg_temp_free_i32(t
);
3217 gen_exception(EXCP_SVC
);
3218 return EXIT_NORETURN
;
3221 #ifndef CONFIG_USER_ONLY
3222 static ExitStatus
op_tprot(DisasContext
*s
, DisasOps
*o
)
3224 potential_page_fault(s
);
3225 gen_helper_tprot(cc_op
, o
->addr1
, o
->in2
);
3231 static ExitStatus
op_tr(DisasContext
*s
, DisasOps
*o
)
3233 TCGv_i32 l
= tcg_const_i32(get_field(s
->fields
, l1
));
3234 potential_page_fault(s
);
3235 gen_helper_tr(cpu_env
, l
, o
->addr1
, o
->in2
);
3236 tcg_temp_free_i32(l
);
3241 static ExitStatus
op_unpk(DisasContext
*s
, DisasOps
*o
)
3243 TCGv_i32 l
= tcg_const_i32(get_field(s
->fields
, l1
));
3244 potential_page_fault(s
);
3245 gen_helper_unpk(cpu_env
, l
, o
->addr1
, o
->in2
);
3246 tcg_temp_free_i32(l
);
3250 static ExitStatus
op_xc(DisasContext
*s
, DisasOps
*o
)
3252 TCGv_i32 l
= tcg_const_i32(get_field(s
->fields
, l1
));
3253 potential_page_fault(s
);
3254 gen_helper_xc(cc_op
, cpu_env
, l
, o
->addr1
, o
->in2
);
3255 tcg_temp_free_i32(l
);
3260 static ExitStatus
op_xor(DisasContext
*s
, DisasOps
*o
)
3262 tcg_gen_xor_i64(o
->out
, o
->in1
, o
->in2
);
3266 static ExitStatus
op_xori(DisasContext
*s
, DisasOps
*o
)
3268 int shift
= s
->insn
->data
& 0xff;
3269 int size
= s
->insn
->data
>> 8;
3270 uint64_t mask
= ((1ull << size
) - 1) << shift
;
3273 tcg_gen_shli_i64(o
->in2
, o
->in2
, shift
);
3274 tcg_gen_xor_i64(o
->out
, o
->in1
, o
->in2
);
3276 /* Produce the CC from only the bits manipulated. */
3277 tcg_gen_andi_i64(cc_dst
, o
->out
, mask
);
3278 set_cc_nz_u64(s
, cc_dst
);
3282 /* ====================================================================== */
3283 /* The "Cc OUTput" generators. Given the generated output (and in some cases
3284 the original inputs), update the various cc data structures in order to
3285 be able to compute the new condition code. */
3287 static void cout_abs32(DisasContext
*s
, DisasOps
*o
)
3289 gen_op_update1_cc_i64(s
, CC_OP_ABS_32
, o
->out
);
3292 static void cout_abs64(DisasContext
*s
, DisasOps
*o
)
3294 gen_op_update1_cc_i64(s
, CC_OP_ABS_64
, o
->out
);
3297 static void cout_adds32(DisasContext
*s
, DisasOps
*o
)
3299 gen_op_update3_cc_i64(s
, CC_OP_ADD_32
, o
->in1
, o
->in2
, o
->out
);
3302 static void cout_adds64(DisasContext
*s
, DisasOps
*o
)
3304 gen_op_update3_cc_i64(s
, CC_OP_ADD_64
, o
->in1
, o
->in2
, o
->out
);
3307 static void cout_addu32(DisasContext
*s
, DisasOps
*o
)
3309 gen_op_update3_cc_i64(s
, CC_OP_ADDU_32
, o
->in1
, o
->in2
, o
->out
);
3312 static void cout_addu64(DisasContext
*s
, DisasOps
*o
)
3314 gen_op_update3_cc_i64(s
, CC_OP_ADDU_64
, o
->in1
, o
->in2
, o
->out
);
3317 static void cout_addc32(DisasContext
*s
, DisasOps
*o
)
3319 gen_op_update3_cc_i64(s
, CC_OP_ADDC_32
, o
->in1
, o
->in2
, o
->out
);
3322 static void cout_addc64(DisasContext
*s
, DisasOps
*o
)
3324 gen_op_update3_cc_i64(s
, CC_OP_ADDC_64
, o
->in1
, o
->in2
, o
->out
);
3327 static void cout_cmps32(DisasContext
*s
, DisasOps
*o
)
3329 gen_op_update2_cc_i64(s
, CC_OP_LTGT_32
, o
->in1
, o
->in2
);
3332 static void cout_cmps64(DisasContext
*s
, DisasOps
*o
)
3334 gen_op_update2_cc_i64(s
, CC_OP_LTGT_64
, o
->in1
, o
->in2
);
3337 static void cout_cmpu32(DisasContext
*s
, DisasOps
*o
)
3339 gen_op_update2_cc_i64(s
, CC_OP_LTUGTU_32
, o
->in1
, o
->in2
);
3342 static void cout_cmpu64(DisasContext
*s
, DisasOps
*o
)
3344 gen_op_update2_cc_i64(s
, CC_OP_LTUGTU_64
, o
->in1
, o
->in2
);
3347 static void cout_f32(DisasContext
*s
, DisasOps
*o
)
3349 gen_op_update1_cc_i64(s
, CC_OP_NZ_F32
, o
->out
);
3352 static void cout_f64(DisasContext
*s
, DisasOps
*o
)
3354 gen_op_update1_cc_i64(s
, CC_OP_NZ_F64
, o
->out
);
3357 static void cout_f128(DisasContext
*s
, DisasOps
*o
)
3359 gen_op_update2_cc_i64(s
, CC_OP_NZ_F128
, o
->out
, o
->out2
);
3362 static void cout_nabs32(DisasContext
*s
, DisasOps
*o
)
3364 gen_op_update1_cc_i64(s
, CC_OP_NABS_32
, o
->out
);
3367 static void cout_nabs64(DisasContext
*s
, DisasOps
*o
)
3369 gen_op_update1_cc_i64(s
, CC_OP_NABS_64
, o
->out
);
3372 static void cout_neg32(DisasContext
*s
, DisasOps
*o
)
3374 gen_op_update1_cc_i64(s
, CC_OP_COMP_32
, o
->out
);
3377 static void cout_neg64(DisasContext
*s
, DisasOps
*o
)
3379 gen_op_update1_cc_i64(s
, CC_OP_COMP_64
, o
->out
);
3382 static void cout_nz32(DisasContext
*s
, DisasOps
*o
)
3384 tcg_gen_ext32u_i64(cc_dst
, o
->out
);
3385 gen_op_update1_cc_i64(s
, CC_OP_NZ
, cc_dst
);
3388 static void cout_nz64(DisasContext
*s
, DisasOps
*o
)
3390 gen_op_update1_cc_i64(s
, CC_OP_NZ
, o
->out
);
3393 static void cout_s32(DisasContext
*s
, DisasOps
*o
)
3395 gen_op_update1_cc_i64(s
, CC_OP_LTGT0_32
, o
->out
);
3398 static void cout_s64(DisasContext
*s
, DisasOps
*o
)
3400 gen_op_update1_cc_i64(s
, CC_OP_LTGT0_64
, o
->out
);
3403 static void cout_subs32(DisasContext
*s
, DisasOps
*o
)
3405 gen_op_update3_cc_i64(s
, CC_OP_SUB_32
, o
->in1
, o
->in2
, o
->out
);
3408 static void cout_subs64(DisasContext
*s
, DisasOps
*o
)
3410 gen_op_update3_cc_i64(s
, CC_OP_SUB_64
, o
->in1
, o
->in2
, o
->out
);
3413 static void cout_subu32(DisasContext
*s
, DisasOps
*o
)
3415 gen_op_update3_cc_i64(s
, CC_OP_SUBU_32
, o
->in1
, o
->in2
, o
->out
);
3418 static void cout_subu64(DisasContext
*s
, DisasOps
*o
)
3420 gen_op_update3_cc_i64(s
, CC_OP_SUBU_64
, o
->in1
, o
->in2
, o
->out
);
3423 static void cout_subb32(DisasContext
*s
, DisasOps
*o
)
3425 gen_op_update3_cc_i64(s
, CC_OP_SUBB_32
, o
->in1
, o
->in2
, o
->out
);
3428 static void cout_subb64(DisasContext
*s
, DisasOps
*o
)
3430 gen_op_update3_cc_i64(s
, CC_OP_SUBB_64
, o
->in1
, o
->in2
, o
->out
);
3433 static void cout_tm32(DisasContext
*s
, DisasOps
*o
)
3435 gen_op_update2_cc_i64(s
, CC_OP_TM_32
, o
->in1
, o
->in2
);
3438 static void cout_tm64(DisasContext
*s
, DisasOps
*o
)
3440 gen_op_update2_cc_i64(s
, CC_OP_TM_64
, o
->in1
, o
->in2
);
3443 /* ====================================================================== */
3444 /* The "PREPeration" generators. These initialize the DisasOps.OUT fields
3445 with the TCG register to which we will write. Used in combination with
3446 the "wout" generators, in some cases we need a new temporary, and in
3447 some cases we can write to a TCG global. */
3449 static void prep_new(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3451 o
->out
= tcg_temp_new_i64();
3454 static void prep_new_P(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3456 o
->out
= tcg_temp_new_i64();
3457 o
->out2
= tcg_temp_new_i64();
3460 static void prep_r1(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3462 o
->out
= regs
[get_field(f
, r1
)];
3466 static void prep_r1_P(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3468 /* ??? Specification exception: r1 must be even. */
3469 int r1
= get_field(f
, r1
);
3471 o
->out2
= regs
[(r1
+ 1) & 15];
3472 o
->g_out
= o
->g_out2
= true;
3475 static void prep_f1(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3477 o
->out
= fregs
[get_field(f
, r1
)];
3481 static void prep_x1(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3483 /* ??? Specification exception: r1 must be < 14. */
3484 int r1
= get_field(f
, r1
);
3486 o
->out2
= fregs
[(r1
+ 2) & 15];
3487 o
->g_out
= o
->g_out2
= true;
3490 /* ====================================================================== */
3491 /* The "Write OUTput" generators. These generally perform some non-trivial
3492 copy of data to TCG globals, or to main memory. The trivial cases are
3493 generally handled by having a "prep" generator install the TCG global
3494 as the destination of the operation. */
3496 static void wout_r1(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3498 store_reg(get_field(f
, r1
), o
->out
);
3501 static void wout_r1_8(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3503 int r1
= get_field(f
, r1
);
3504 tcg_gen_deposit_i64(regs
[r1
], regs
[r1
], o
->out
, 0, 8);
3507 static void wout_r1_16(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3509 int r1
= get_field(f
, r1
);
3510 tcg_gen_deposit_i64(regs
[r1
], regs
[r1
], o
->out
, 0, 16);
3513 static void wout_r1_32(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3515 store_reg32_i64(get_field(f
, r1
), o
->out
);
3518 static void wout_r1_P32(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3520 /* ??? Specification exception: r1 must be even. */
3521 int r1
= get_field(f
, r1
);
3522 store_reg32_i64(r1
, o
->out
);
3523 store_reg32_i64((r1
+ 1) & 15, o
->out2
);
3526 static void wout_r1_D32(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3528 /* ??? Specification exception: r1 must be even. */
3529 int r1
= get_field(f
, r1
);
3530 store_reg32_i64((r1
+ 1) & 15, o
->out
);
3531 tcg_gen_shri_i64(o
->out
, o
->out
, 32);
3532 store_reg32_i64(r1
, o
->out
);
3535 static void wout_e1(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3537 store_freg32_i64(get_field(f
, r1
), o
->out
);
3540 static void wout_f1(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3542 store_freg(get_field(f
, r1
), o
->out
);
3545 static void wout_x1(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3547 /* ??? Specification exception: r1 must be < 14. */
3548 int f1
= get_field(s
->fields
, r1
);
3549 store_freg(f1
, o
->out
);
3550 store_freg((f1
+ 2) & 15, o
->out2
);
3553 static void wout_cond_r1r2_32(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3555 if (get_field(f
, r1
) != get_field(f
, r2
)) {
3556 store_reg32_i64(get_field(f
, r1
), o
->out
);
3560 static void wout_cond_e1e2(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3562 if (get_field(f
, r1
) != get_field(f
, r2
)) {
3563 store_freg32_i64(get_field(f
, r1
), o
->out
);
3567 static void wout_m1_8(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3569 tcg_gen_qemu_st8(o
->out
, o
->addr1
, get_mem_index(s
));
3572 static void wout_m1_16(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3574 tcg_gen_qemu_st16(o
->out
, o
->addr1
, get_mem_index(s
));
3577 static void wout_m1_32(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3579 tcg_gen_qemu_st32(o
->out
, o
->addr1
, get_mem_index(s
));
3582 static void wout_m1_64(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3584 tcg_gen_qemu_st64(o
->out
, o
->addr1
, get_mem_index(s
));
3587 static void wout_m2_32(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3589 tcg_gen_qemu_st32(o
->out
, o
->in2
, get_mem_index(s
));
3592 /* ====================================================================== */
3593 /* The "INput 1" generators. These load the first operand to an insn. */
3595 static void in1_r1(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3597 o
->in1
= load_reg(get_field(f
, r1
));
3600 static void in1_r1_o(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3602 o
->in1
= regs
[get_field(f
, r1
)];
3606 static void in1_r1_32s(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3608 o
->in1
= tcg_temp_new_i64();
3609 tcg_gen_ext32s_i64(o
->in1
, regs
[get_field(f
, r1
)]);
3612 static void in1_r1_32u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3614 o
->in1
= tcg_temp_new_i64();
3615 tcg_gen_ext32u_i64(o
->in1
, regs
[get_field(f
, r1
)]);
3618 static void in1_r1_sr32(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3620 o
->in1
= tcg_temp_new_i64();
3621 tcg_gen_shri_i64(o
->in1
, regs
[get_field(f
, r1
)], 32);
3624 static void in1_r1p1(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3626 /* ??? Specification exception: r1 must be even. */
3627 int r1
= get_field(f
, r1
);
3628 o
->in1
= load_reg((r1
+ 1) & 15);
3631 static void in1_r1p1_32s(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3633 /* ??? Specification exception: r1 must be even. */
3634 int r1
= get_field(f
, r1
);
3635 o
->in1
= tcg_temp_new_i64();
3636 tcg_gen_ext32s_i64(o
->in1
, regs
[(r1
+ 1) & 15]);
3639 static void in1_r1p1_32u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3641 /* ??? Specification exception: r1 must be even. */
3642 int r1
= get_field(f
, r1
);
3643 o
->in1
= tcg_temp_new_i64();
3644 tcg_gen_ext32u_i64(o
->in1
, regs
[(r1
+ 1) & 15]);
3647 static void in1_r1_D32(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3649 /* ??? Specification exception: r1 must be even. */
3650 int r1
= get_field(f
, r1
);
3651 o
->in1
= tcg_temp_new_i64();
3652 tcg_gen_concat32_i64(o
->in1
, regs
[r1
+ 1], regs
[r1
]);
3655 static void in1_r2(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3657 o
->in1
= load_reg(get_field(f
, r2
));
3660 static void in1_r3(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3662 o
->in1
= load_reg(get_field(f
, r3
));
3665 static void in1_r3_o(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3667 o
->in1
= regs
[get_field(f
, r3
)];
3671 static void in1_r3_32s(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3673 o
->in1
= tcg_temp_new_i64();
3674 tcg_gen_ext32s_i64(o
->in1
, regs
[get_field(f
, r3
)]);
3677 static void in1_r3_32u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3679 o
->in1
= tcg_temp_new_i64();
3680 tcg_gen_ext32u_i64(o
->in1
, regs
[get_field(f
, r3
)]);
3683 static void in1_e1(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3685 o
->in1
= load_freg32_i64(get_field(f
, r1
));
3688 static void in1_f1_o(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3690 o
->in1
= fregs
[get_field(f
, r1
)];
3694 static void in1_x1_o(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3696 /* ??? Specification exception: r1 must be < 14. */
3697 int r1
= get_field(f
, r1
);
3699 o
->out2
= fregs
[(r1
+ 2) & 15];
3700 o
->g_out
= o
->g_out2
= true;
3703 static void in1_la1(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3705 o
->addr1
= get_address(s
, 0, get_field(f
, b1
), get_field(f
, d1
));
3708 static void in1_la2(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3710 int x2
= have_field(f
, x2
) ? get_field(f
, x2
) : 0;
3711 o
->addr1
= get_address(s
, x2
, get_field(f
, b2
), get_field(f
, d2
));
3714 static void in1_m1_8u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3717 o
->in1
= tcg_temp_new_i64();
3718 tcg_gen_qemu_ld8u(o
->in1
, o
->addr1
, get_mem_index(s
));
3721 static void in1_m1_16s(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3724 o
->in1
= tcg_temp_new_i64();
3725 tcg_gen_qemu_ld16s(o
->in1
, o
->addr1
, get_mem_index(s
));
3728 static void in1_m1_16u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3731 o
->in1
= tcg_temp_new_i64();
3732 tcg_gen_qemu_ld16u(o
->in1
, o
->addr1
, get_mem_index(s
));
3735 static void in1_m1_32s(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3738 o
->in1
= tcg_temp_new_i64();
3739 tcg_gen_qemu_ld32s(o
->in1
, o
->addr1
, get_mem_index(s
));
3742 static void in1_m1_32u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3745 o
->in1
= tcg_temp_new_i64();
3746 tcg_gen_qemu_ld32u(o
->in1
, o
->addr1
, get_mem_index(s
));
3749 static void in1_m1_64(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3752 o
->in1
= tcg_temp_new_i64();
3753 tcg_gen_qemu_ld64(o
->in1
, o
->addr1
, get_mem_index(s
));
3756 /* ====================================================================== */
3757 /* The "INput 2" generators. These load the second operand to an insn. */
3759 static void in2_r1_o(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3761 o
->in2
= regs
[get_field(f
, r1
)];
3765 static void in2_r1_16u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3767 o
->in2
= tcg_temp_new_i64();
3768 tcg_gen_ext16u_i64(o
->in2
, regs
[get_field(f
, r1
)]);
3771 static void in2_r1_32u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3773 o
->in2
= tcg_temp_new_i64();
3774 tcg_gen_ext32u_i64(o
->in2
, regs
[get_field(f
, r1
)]);
3777 static void in2_r2(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3779 o
->in2
= load_reg(get_field(f
, r2
));
3782 static void in2_r2_o(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3784 o
->in2
= regs
[get_field(f
, r2
)];
3788 static void in2_r2_nz(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3790 int r2
= get_field(f
, r2
);
3792 o
->in2
= load_reg(r2
);
3796 static void in2_r2_8s(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3798 o
->in2
= tcg_temp_new_i64();
3799 tcg_gen_ext8s_i64(o
->in2
, regs
[get_field(f
, r2
)]);
3802 static void in2_r2_8u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3804 o
->in2
= tcg_temp_new_i64();
3805 tcg_gen_ext8u_i64(o
->in2
, regs
[get_field(f
, r2
)]);
3808 static void in2_r2_16s(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3810 o
->in2
= tcg_temp_new_i64();
3811 tcg_gen_ext16s_i64(o
->in2
, regs
[get_field(f
, r2
)]);
3814 static void in2_r2_16u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3816 o
->in2
= tcg_temp_new_i64();
3817 tcg_gen_ext16u_i64(o
->in2
, regs
[get_field(f
, r2
)]);
3820 static void in2_r3(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3822 o
->in2
= load_reg(get_field(f
, r3
));
3825 static void in2_r2_32s(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3827 o
->in2
= tcg_temp_new_i64();
3828 tcg_gen_ext32s_i64(o
->in2
, regs
[get_field(f
, r2
)]);
3831 static void in2_r2_32u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3833 o
->in2
= tcg_temp_new_i64();
3834 tcg_gen_ext32u_i64(o
->in2
, regs
[get_field(f
, r2
)]);
3837 static void in2_e2(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3839 o
->in2
= load_freg32_i64(get_field(f
, r2
));
3842 static void in2_f2_o(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3844 o
->in2
= fregs
[get_field(f
, r2
)];
3848 static void in2_x2_o(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3850 /* ??? Specification exception: r1 must be < 14. */
3851 int r2
= get_field(f
, r2
);
3853 o
->in2
= fregs
[(r2
+ 2) & 15];
3854 o
->g_in1
= o
->g_in2
= true;
3857 static void in2_a2(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3859 int x2
= have_field(f
, x2
) ? get_field(f
, x2
) : 0;
3860 o
->in2
= get_address(s
, x2
, get_field(f
, b2
), get_field(f
, d2
));
3863 static void in2_ri2(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3865 o
->in2
= tcg_const_i64(s
->pc
+ (int64_t)get_field(f
, i2
) * 2);
3868 static void in2_sh32(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3870 help_l2_shift(s
, f
, o
, 31);
3873 static void in2_sh64(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3875 help_l2_shift(s
, f
, o
, 63);
3878 static void in2_m2_8u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3881 tcg_gen_qemu_ld8u(o
->in2
, o
->in2
, get_mem_index(s
));
3884 static void in2_m2_16s(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3887 tcg_gen_qemu_ld16s(o
->in2
, o
->in2
, get_mem_index(s
));
3890 static void in2_m2_16u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3893 tcg_gen_qemu_ld16u(o
->in2
, o
->in2
, get_mem_index(s
));
3896 static void in2_m2_32s(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3899 tcg_gen_qemu_ld32s(o
->in2
, o
->in2
, get_mem_index(s
));
3902 static void in2_m2_32u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3905 tcg_gen_qemu_ld32u(o
->in2
, o
->in2
, get_mem_index(s
));
3908 static void in2_m2_64(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3911 tcg_gen_qemu_ld64(o
->in2
, o
->in2
, get_mem_index(s
));
3914 static void in2_mri2_16u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3917 tcg_gen_qemu_ld16u(o
->in2
, o
->in2
, get_mem_index(s
));
3920 static void in2_mri2_32s(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3923 tcg_gen_qemu_ld32s(o
->in2
, o
->in2
, get_mem_index(s
));
3926 static void in2_mri2_32u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3929 tcg_gen_qemu_ld32u(o
->in2
, o
->in2
, get_mem_index(s
));
3932 static void in2_mri2_64(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3935 tcg_gen_qemu_ld64(o
->in2
, o
->in2
, get_mem_index(s
));
3938 static void in2_i2(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3940 o
->in2
= tcg_const_i64(get_field(f
, i2
));
3943 static void in2_i2_8u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3945 o
->in2
= tcg_const_i64((uint8_t)get_field(f
, i2
));
3948 static void in2_i2_16u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3950 o
->in2
= tcg_const_i64((uint16_t)get_field(f
, i2
));
3953 static void in2_i2_32u(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3955 o
->in2
= tcg_const_i64((uint32_t)get_field(f
, i2
));
3958 static void in2_i2_16u_shl(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3960 uint64_t i2
= (uint16_t)get_field(f
, i2
);
3961 o
->in2
= tcg_const_i64(i2
<< s
->insn
->data
);
3964 static void in2_i2_32u_shl(DisasContext
*s
, DisasFields
*f
, DisasOps
*o
)
3966 uint64_t i2
= (uint32_t)get_field(f
, i2
);
3967 o
->in2
= tcg_const_i64(i2
<< s
->insn
->data
);
3970 /* ====================================================================== */
3972 /* Find opc within the table of insns. This is formulated as a switch
3973 statement so that (1) we get compile-time notice of cut-paste errors
3974 for duplicated opcodes, and (2) the compiler generates the binary
3975 search tree, rather than us having to post-process the table. */
3977 #define C(OPC, NM, FT, FC, I1, I2, P, W, OP, CC) \
3978 D(OPC, NM, FT, FC, I1, I2, P, W, OP, CC, 0)
3980 #define D(OPC, NM, FT, FC, I1, I2, P, W, OP, CC, D) insn_ ## NM,
3982 enum DisasInsnEnum
{
3983 #include "insn-data.def"
3987 #define D(OPC, NM, FT, FC, I1, I2, P, W, OP, CC, D) { \
3992 .help_in1 = in1_##I1, \
3993 .help_in2 = in2_##I2, \
3994 .help_prep = prep_##P, \
3995 .help_wout = wout_##W, \
3996 .help_cout = cout_##CC, \
3997 .help_op = op_##OP, \
4001 /* Allow 0 to be used for NULL in the table below. */
4009 static const DisasInsn insn_info
[] = {
4010 #include "insn-data.def"
4014 #define D(OPC, NM, FT, FC, I1, I2, P, W, OP, CC, D) \
4015 case OPC: return &insn_info[insn_ ## NM];
4017 static const DisasInsn
*lookup_opc(uint16_t opc
)
4020 #include "insn-data.def"
4029 /* Extract a field from the insn. The INSN should be left-aligned in
4030 the uint64_t so that we can more easily utilize the big-bit-endian
4031 definitions we extract from the Principals of Operation. */
4033 static void extract_field(DisasFields
*o
, const DisasField
*f
, uint64_t insn
)
4041 /* Zero extract the field from the insn. */
4042 r
= (insn
<< f
->beg
) >> (64 - f
->size
);
4044 /* Sign-extend, or un-swap the field as necessary. */
4046 case 0: /* unsigned */
4048 case 1: /* signed */
4049 assert(f
->size
<= 32);
4050 m
= 1u << (f
->size
- 1);
4053 case 2: /* dl+dh split, signed 20 bit. */
4054 r
= ((int8_t)r
<< 12) | (r
>> 8);
4060 /* Validate that the "compressed" encoding we selected above is valid.
4061 I.e. we havn't make two different original fields overlap. */
4062 assert(((o
->presentC
>> f
->indexC
) & 1) == 0);
4063 o
->presentC
|= 1 << f
->indexC
;
4064 o
->presentO
|= 1 << f
->indexO
;
4066 o
->c
[f
->indexC
] = r
;
4069 /* Lookup the insn at the current PC, extracting the operands into O and
4070 returning the info struct for the insn. Returns NULL for invalid insn. */
4072 static const DisasInsn
*extract_insn(CPUS390XState
*env
, DisasContext
*s
,
4075 uint64_t insn
, pc
= s
->pc
;
4077 const DisasInsn
*info
;
4079 insn
= ld_code2(env
, pc
);
4080 op
= (insn
>> 8) & 0xff;
4081 ilen
= get_ilen(op
);
4082 s
->next_pc
= s
->pc
+ ilen
;
4089 insn
= ld_code4(env
, pc
) << 32;
4092 insn
= (insn
<< 48) | (ld_code4(env
, pc
+ 2) << 16);
4098 /* We can't actually determine the insn format until we've looked up
4099 the full insn opcode. Which we can't do without locating the
4100 secondary opcode. Assume by default that OP2 is at bit 40; for
4101 those smaller insns that don't actually have a secondary opcode
4102 this will correctly result in OP2 = 0. */
4108 case 0xb2: /* S, RRF, RRE */
4109 case 0xb3: /* RRE, RRD, RRF */
4110 case 0xb9: /* RRE, RRF */
4111 case 0xe5: /* SSE, SIL */
4112 op2
= (insn
<< 8) >> 56;
4116 case 0xc0: /* RIL */
4117 case 0xc2: /* RIL */
4118 case 0xc4: /* RIL */
4119 case 0xc6: /* RIL */
4120 case 0xc8: /* SSF */
4121 case 0xcc: /* RIL */
4122 op2
= (insn
<< 12) >> 60;
4124 case 0xd0 ... 0xdf: /* SS */
4130 case 0xee ... 0xf3: /* SS */
4131 case 0xf8 ... 0xfd: /* SS */
4135 op2
= (insn
<< 40) >> 56;
4139 memset(f
, 0, sizeof(*f
));
4143 /* Lookup the instruction. */
4144 info
= lookup_opc(op
<< 8 | op2
);
4146 /* If we found it, extract the operands. */
4148 DisasFormat fmt
= info
->fmt
;
4151 for (i
= 0; i
< NUM_C_FIELD
; ++i
) {
4152 extract_field(f
, &format_info
[fmt
].op
[i
], insn
);
4158 static ExitStatus
translate_one(CPUS390XState
*env
, DisasContext
*s
)
4160 const DisasInsn
*insn
;
4161 ExitStatus ret
= NO_EXIT
;
4165 insn
= extract_insn(env
, s
, &f
);
4167 /* If not found, try the old interpreter. This includes ILLOPC. */
4169 disas_s390_insn(env
, s
);
4170 switch (s
->is_jmp
) {
4178 ret
= EXIT_PC_UPDATED
;
4181 ret
= EXIT_NORETURN
;
4191 /* Set up the strutures we use to communicate with the helpers. */
4194 o
.g_out
= o
.g_out2
= o
.g_in1
= o
.g_in2
= false;
4195 TCGV_UNUSED_I64(o
.out
);
4196 TCGV_UNUSED_I64(o
.out2
);
4197 TCGV_UNUSED_I64(o
.in1
);
4198 TCGV_UNUSED_I64(o
.in2
);
4199 TCGV_UNUSED_I64(o
.addr1
);
4201 /* Implement the instruction. */
4202 if (insn
->help_in1
) {
4203 insn
->help_in1(s
, &f
, &o
);
4205 if (insn
->help_in2
) {
4206 insn
->help_in2(s
, &f
, &o
);
4208 if (insn
->help_prep
) {
4209 insn
->help_prep(s
, &f
, &o
);
4211 if (insn
->help_op
) {
4212 ret
= insn
->help_op(s
, &o
);
4214 if (insn
->help_wout
) {
4215 insn
->help_wout(s
, &f
, &o
);
4217 if (insn
->help_cout
) {
4218 insn
->help_cout(s
, &o
);
4221 /* Free any temporaries created by the helpers. */
4222 if (!TCGV_IS_UNUSED_I64(o
.out
) && !o
.g_out
) {
4223 tcg_temp_free_i64(o
.out
);
4225 if (!TCGV_IS_UNUSED_I64(o
.out2
) && !o
.g_out2
) {
4226 tcg_temp_free_i64(o
.out2
);
4228 if (!TCGV_IS_UNUSED_I64(o
.in1
) && !o
.g_in1
) {
4229 tcg_temp_free_i64(o
.in1
);
4231 if (!TCGV_IS_UNUSED_I64(o
.in2
) && !o
.g_in2
) {
4232 tcg_temp_free_i64(o
.in2
);
4234 if (!TCGV_IS_UNUSED_I64(o
.addr1
)) {
4235 tcg_temp_free_i64(o
.addr1
);
4238 /* Advance to the next instruction. */
4243 static inline void gen_intermediate_code_internal(CPUS390XState
*env
,
4244 TranslationBlock
*tb
,
4248 target_ulong pc_start
;
4249 uint64_t next_page_start
;
4250 uint16_t *gen_opc_end
;
4252 int num_insns
, max_insns
;
4260 if (!(tb
->flags
& FLAG_MASK_64
)) {
4261 pc_start
&= 0x7fffffff;
4266 dc
.cc_op
= CC_OP_DYNAMIC
;
4267 do_debug
= dc
.singlestep_enabled
= env
->singlestep_enabled
;
4268 dc
.is_jmp
= DISAS_NEXT
;
4270 gen_opc_end
= tcg_ctx
.gen_opc_buf
+ OPC_MAX_SIZE
;
4272 next_page_start
= (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
4275 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
4276 if (max_insns
== 0) {
4277 max_insns
= CF_COUNT_MASK
;
4284 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
4288 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
4291 tcg_ctx
.gen_opc_pc
[lj
] = dc
.pc
;
4292 gen_opc_cc_op
[lj
] = dc
.cc_op
;
4293 tcg_ctx
.gen_opc_instr_start
[lj
] = 1;
4294 tcg_ctx
.gen_opc_icount
[lj
] = num_insns
;
4296 if (++num_insns
== max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
4300 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
4301 tcg_gen_debug_insn_start(dc
.pc
);
4305 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
4306 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
4307 if (bp
->pc
== dc
.pc
) {
4308 status
= EXIT_PC_STALE
;
4314 if (status
== NO_EXIT
) {
4315 status
= translate_one(env
, &dc
);
4318 /* If we reach a page boundary, are single stepping,
4319 or exhaust instruction count, stop generation. */
4320 if (status
== NO_EXIT
4321 && (dc
.pc
>= next_page_start
4322 || tcg_ctx
.gen_opc_ptr
>= gen_opc_end
4323 || num_insns
>= max_insns
4325 || env
->singlestep_enabled
)) {
4326 status
= EXIT_PC_STALE
;
4328 } while (status
== NO_EXIT
);
4330 if (tb
->cflags
& CF_LAST_IO
) {
4339 update_psw_addr(&dc
);
4341 case EXIT_PC_UPDATED
:
4342 if (singlestep
&& dc
.cc_op
!= CC_OP_DYNAMIC
) {
4343 gen_op_calc_cc(&dc
);
4345 /* Next TB starts off with CC_OP_DYNAMIC,
4346 so make sure the cc op type is in env */
4347 gen_op_set_cc_op(&dc
);
4350 gen_exception(EXCP_DEBUG
);
4352 /* Generate the return instruction */
4360 gen_icount_end(tb
, num_insns
);
4361 *tcg_ctx
.gen_opc_ptr
= INDEX_op_end
;
4363 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
4366 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
4369 tb
->size
= dc
.pc
- pc_start
;
4370 tb
->icount
= num_insns
;
4373 #if defined(S390X_DEBUG_DISAS)
4374 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
4375 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
4376 log_target_disas(env
, pc_start
, dc
.pc
- pc_start
, 1);
4382 void gen_intermediate_code (CPUS390XState
*env
, struct TranslationBlock
*tb
)
4384 gen_intermediate_code_internal(env
, tb
, 0);
4387 void gen_intermediate_code_pc (CPUS390XState
*env
, struct TranslationBlock
*tb
)
4389 gen_intermediate_code_internal(env
, tb
, 1);
4392 void restore_state_to_opc(CPUS390XState
*env
, TranslationBlock
*tb
, int pc_pos
)
4395 env
->psw
.addr
= tcg_ctx
.gen_opc_pc
[pc_pos
];
4396 cc_op
= gen_opc_cc_op
[pc_pos
];
4397 if ((cc_op
!= CC_OP_DYNAMIC
) && (cc_op
!= CC_OP_STATIC
)) {