xref: /openbmc/qemu/target/hppa/translate.c (revision 1a19da0da44430581bf48b595d75ad6e9fc7e428)
161766fe9SRichard Henderson /*
261766fe9SRichard Henderson  * HPPA emulation cpu translation for qemu.
361766fe9SRichard Henderson  *
461766fe9SRichard Henderson  * Copyright (c) 2016 Richard Henderson <rth@twiddle.net>
561766fe9SRichard Henderson  *
661766fe9SRichard Henderson  * This library is free software; you can redistribute it and/or
761766fe9SRichard Henderson  * modify it under the terms of the GNU Lesser General Public
861766fe9SRichard Henderson  * License as published by the Free Software Foundation; either
961766fe9SRichard Henderson  * version 2 of the License, or (at your option) any later version.
1061766fe9SRichard Henderson  *
1161766fe9SRichard Henderson  * This library is distributed in the hope that it will be useful,
1261766fe9SRichard Henderson  * but WITHOUT ANY WARRANTY; without even the implied warranty of
1361766fe9SRichard Henderson  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1461766fe9SRichard Henderson  * Lesser General Public License for more details.
1561766fe9SRichard Henderson  *
1661766fe9SRichard Henderson  * You should have received a copy of the GNU Lesser General Public
1761766fe9SRichard Henderson  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
1861766fe9SRichard Henderson  */
1961766fe9SRichard Henderson 
2061766fe9SRichard Henderson #include "qemu/osdep.h"
2161766fe9SRichard Henderson #include "cpu.h"
2261766fe9SRichard Henderson #include "disas/disas.h"
2361766fe9SRichard Henderson #include "qemu/host-utils.h"
2461766fe9SRichard Henderson #include "exec/exec-all.h"
2561766fe9SRichard Henderson #include "tcg-op.h"
2661766fe9SRichard Henderson #include "exec/cpu_ldst.h"
2761766fe9SRichard Henderson #include "exec/helper-proto.h"
2861766fe9SRichard Henderson #include "exec/helper-gen.h"
29869051eaSRichard Henderson #include "exec/translator.h"
3061766fe9SRichard Henderson #include "trace-tcg.h"
3161766fe9SRichard Henderson #include "exec/log.h"
3261766fe9SRichard Henderson 
33eaa3783bSRichard Henderson /* Since we have a distinction between register size and address size,
34eaa3783bSRichard Henderson    we need to redefine all of these.  */
35eaa3783bSRichard Henderson 
36eaa3783bSRichard Henderson #undef TCGv
37eaa3783bSRichard Henderson #undef tcg_temp_new
38eaa3783bSRichard Henderson #undef tcg_global_reg_new
39eaa3783bSRichard Henderson #undef tcg_global_mem_new
40eaa3783bSRichard Henderson #undef tcg_temp_local_new
41eaa3783bSRichard Henderson #undef tcg_temp_free
42eaa3783bSRichard Henderson 
43eaa3783bSRichard Henderson #if TARGET_LONG_BITS == 64
44eaa3783bSRichard Henderson #define TCGv_tl              TCGv_i64
45eaa3783bSRichard Henderson #define tcg_temp_new_tl      tcg_temp_new_i64
46eaa3783bSRichard Henderson #define tcg_temp_free_tl     tcg_temp_free_i64
47eaa3783bSRichard Henderson #if TARGET_REGISTER_BITS == 64
48eaa3783bSRichard Henderson #define tcg_gen_extu_reg_tl  tcg_gen_mov_i64
49eaa3783bSRichard Henderson #else
50eaa3783bSRichard Henderson #define tcg_gen_extu_reg_tl  tcg_gen_extu_i32_i64
51eaa3783bSRichard Henderson #endif
52eaa3783bSRichard Henderson #else
53eaa3783bSRichard Henderson #define TCGv_tl              TCGv_i32
54eaa3783bSRichard Henderson #define tcg_temp_new_tl      tcg_temp_new_i32
55eaa3783bSRichard Henderson #define tcg_temp_free_tl     tcg_temp_free_i32
56eaa3783bSRichard Henderson #define tcg_gen_extu_reg_tl  tcg_gen_mov_i32
57eaa3783bSRichard Henderson #endif
58eaa3783bSRichard Henderson 
59eaa3783bSRichard Henderson #if TARGET_REGISTER_BITS == 64
60eaa3783bSRichard Henderson #define TCGv_reg             TCGv_i64
61eaa3783bSRichard Henderson 
62eaa3783bSRichard Henderson #define tcg_temp_new         tcg_temp_new_i64
63eaa3783bSRichard Henderson #define tcg_global_reg_new   tcg_global_reg_new_i64
64eaa3783bSRichard Henderson #define tcg_global_mem_new   tcg_global_mem_new_i64
65eaa3783bSRichard Henderson #define tcg_temp_local_new   tcg_temp_local_new_i64
66eaa3783bSRichard Henderson #define tcg_temp_free        tcg_temp_free_i64
67eaa3783bSRichard Henderson 
68eaa3783bSRichard Henderson #define tcg_gen_movi_reg     tcg_gen_movi_i64
69eaa3783bSRichard Henderson #define tcg_gen_mov_reg      tcg_gen_mov_i64
70eaa3783bSRichard Henderson #define tcg_gen_ld8u_reg     tcg_gen_ld8u_i64
71eaa3783bSRichard Henderson #define tcg_gen_ld8s_reg     tcg_gen_ld8s_i64
72eaa3783bSRichard Henderson #define tcg_gen_ld16u_reg    tcg_gen_ld16u_i64
73eaa3783bSRichard Henderson #define tcg_gen_ld16s_reg    tcg_gen_ld16s_i64
74eaa3783bSRichard Henderson #define tcg_gen_ld32u_reg    tcg_gen_ld32u_i64
75eaa3783bSRichard Henderson #define tcg_gen_ld32s_reg    tcg_gen_ld32s_i64
76eaa3783bSRichard Henderson #define tcg_gen_ld_reg       tcg_gen_ld_i64
77eaa3783bSRichard Henderson #define tcg_gen_st8_reg      tcg_gen_st8_i64
78eaa3783bSRichard Henderson #define tcg_gen_st16_reg     tcg_gen_st16_i64
79eaa3783bSRichard Henderson #define tcg_gen_st32_reg     tcg_gen_st32_i64
80eaa3783bSRichard Henderson #define tcg_gen_st_reg       tcg_gen_st_i64
81eaa3783bSRichard Henderson #define tcg_gen_add_reg      tcg_gen_add_i64
82eaa3783bSRichard Henderson #define tcg_gen_addi_reg     tcg_gen_addi_i64
83eaa3783bSRichard Henderson #define tcg_gen_sub_reg      tcg_gen_sub_i64
84eaa3783bSRichard Henderson #define tcg_gen_neg_reg      tcg_gen_neg_i64
85eaa3783bSRichard Henderson #define tcg_gen_subfi_reg    tcg_gen_subfi_i64
86eaa3783bSRichard Henderson #define tcg_gen_subi_reg     tcg_gen_subi_i64
87eaa3783bSRichard Henderson #define tcg_gen_and_reg      tcg_gen_and_i64
88eaa3783bSRichard Henderson #define tcg_gen_andi_reg     tcg_gen_andi_i64
89eaa3783bSRichard Henderson #define tcg_gen_or_reg       tcg_gen_or_i64
90eaa3783bSRichard Henderson #define tcg_gen_ori_reg      tcg_gen_ori_i64
91eaa3783bSRichard Henderson #define tcg_gen_xor_reg      tcg_gen_xor_i64
92eaa3783bSRichard Henderson #define tcg_gen_xori_reg     tcg_gen_xori_i64
93eaa3783bSRichard Henderson #define tcg_gen_not_reg      tcg_gen_not_i64
94eaa3783bSRichard Henderson #define tcg_gen_shl_reg      tcg_gen_shl_i64
95eaa3783bSRichard Henderson #define tcg_gen_shli_reg     tcg_gen_shli_i64
96eaa3783bSRichard Henderson #define tcg_gen_shr_reg      tcg_gen_shr_i64
97eaa3783bSRichard Henderson #define tcg_gen_shri_reg     tcg_gen_shri_i64
98eaa3783bSRichard Henderson #define tcg_gen_sar_reg      tcg_gen_sar_i64
99eaa3783bSRichard Henderson #define tcg_gen_sari_reg     tcg_gen_sari_i64
100eaa3783bSRichard Henderson #define tcg_gen_brcond_reg   tcg_gen_brcond_i64
101eaa3783bSRichard Henderson #define tcg_gen_brcondi_reg  tcg_gen_brcondi_i64
102eaa3783bSRichard Henderson #define tcg_gen_setcond_reg  tcg_gen_setcond_i64
103eaa3783bSRichard Henderson #define tcg_gen_setcondi_reg tcg_gen_setcondi_i64
104eaa3783bSRichard Henderson #define tcg_gen_mul_reg      tcg_gen_mul_i64
105eaa3783bSRichard Henderson #define tcg_gen_muli_reg     tcg_gen_muli_i64
106eaa3783bSRichard Henderson #define tcg_gen_div_reg      tcg_gen_div_i64
107eaa3783bSRichard Henderson #define tcg_gen_rem_reg      tcg_gen_rem_i64
108eaa3783bSRichard Henderson #define tcg_gen_divu_reg     tcg_gen_divu_i64
109eaa3783bSRichard Henderson #define tcg_gen_remu_reg     tcg_gen_remu_i64
110eaa3783bSRichard Henderson #define tcg_gen_discard_reg  tcg_gen_discard_i64
111eaa3783bSRichard Henderson #define tcg_gen_trunc_reg_i32 tcg_gen_extrl_i64_i32
112eaa3783bSRichard Henderson #define tcg_gen_trunc_i64_reg tcg_gen_mov_i64
113eaa3783bSRichard Henderson #define tcg_gen_extu_i32_reg tcg_gen_extu_i32_i64
114eaa3783bSRichard Henderson #define tcg_gen_ext_i32_reg  tcg_gen_ext_i32_i64
115eaa3783bSRichard Henderson #define tcg_gen_extu_reg_i64 tcg_gen_mov_i64
116eaa3783bSRichard Henderson #define tcg_gen_ext_reg_i64  tcg_gen_mov_i64
117eaa3783bSRichard Henderson #define tcg_gen_ext8u_reg    tcg_gen_ext8u_i64
118eaa3783bSRichard Henderson #define tcg_gen_ext8s_reg    tcg_gen_ext8s_i64
119eaa3783bSRichard Henderson #define tcg_gen_ext16u_reg   tcg_gen_ext16u_i64
120eaa3783bSRichard Henderson #define tcg_gen_ext16s_reg   tcg_gen_ext16s_i64
121eaa3783bSRichard Henderson #define tcg_gen_ext32u_reg   tcg_gen_ext32u_i64
122eaa3783bSRichard Henderson #define tcg_gen_ext32s_reg   tcg_gen_ext32s_i64
123eaa3783bSRichard Henderson #define tcg_gen_bswap16_reg  tcg_gen_bswap16_i64
124eaa3783bSRichard Henderson #define tcg_gen_bswap32_reg  tcg_gen_bswap32_i64
125eaa3783bSRichard Henderson #define tcg_gen_bswap64_reg  tcg_gen_bswap64_i64
126eaa3783bSRichard Henderson #define tcg_gen_concat_reg_i64 tcg_gen_concat32_i64
127eaa3783bSRichard Henderson #define tcg_gen_andc_reg     tcg_gen_andc_i64
128eaa3783bSRichard Henderson #define tcg_gen_eqv_reg      tcg_gen_eqv_i64
129eaa3783bSRichard Henderson #define tcg_gen_nand_reg     tcg_gen_nand_i64
130eaa3783bSRichard Henderson #define tcg_gen_nor_reg      tcg_gen_nor_i64
131eaa3783bSRichard Henderson #define tcg_gen_orc_reg      tcg_gen_orc_i64
132eaa3783bSRichard Henderson #define tcg_gen_clz_reg      tcg_gen_clz_i64
133eaa3783bSRichard Henderson #define tcg_gen_ctz_reg      tcg_gen_ctz_i64
134eaa3783bSRichard Henderson #define tcg_gen_clzi_reg     tcg_gen_clzi_i64
135eaa3783bSRichard Henderson #define tcg_gen_ctzi_reg     tcg_gen_ctzi_i64
136eaa3783bSRichard Henderson #define tcg_gen_clrsb_reg    tcg_gen_clrsb_i64
137eaa3783bSRichard Henderson #define tcg_gen_ctpop_reg    tcg_gen_ctpop_i64
138eaa3783bSRichard Henderson #define tcg_gen_rotl_reg     tcg_gen_rotl_i64
139eaa3783bSRichard Henderson #define tcg_gen_rotli_reg    tcg_gen_rotli_i64
140eaa3783bSRichard Henderson #define tcg_gen_rotr_reg     tcg_gen_rotr_i64
141eaa3783bSRichard Henderson #define tcg_gen_rotri_reg    tcg_gen_rotri_i64
142eaa3783bSRichard Henderson #define tcg_gen_deposit_reg  tcg_gen_deposit_i64
143eaa3783bSRichard Henderson #define tcg_gen_deposit_z_reg tcg_gen_deposit_z_i64
144eaa3783bSRichard Henderson #define tcg_gen_extract_reg  tcg_gen_extract_i64
145eaa3783bSRichard Henderson #define tcg_gen_sextract_reg tcg_gen_sextract_i64
146eaa3783bSRichard Henderson #define tcg_const_reg        tcg_const_i64
147eaa3783bSRichard Henderson #define tcg_const_local_reg  tcg_const_local_i64
148eaa3783bSRichard Henderson #define tcg_gen_movcond_reg  tcg_gen_movcond_i64
149eaa3783bSRichard Henderson #define tcg_gen_add2_reg     tcg_gen_add2_i64
150eaa3783bSRichard Henderson #define tcg_gen_sub2_reg     tcg_gen_sub2_i64
151eaa3783bSRichard Henderson #define tcg_gen_qemu_ld_reg  tcg_gen_qemu_ld_i64
152eaa3783bSRichard Henderson #define tcg_gen_qemu_st_reg  tcg_gen_qemu_st_i64
153eaa3783bSRichard Henderson #define tcg_gen_atomic_xchg_reg tcg_gen_atomic_xchg_i64
154eaa3783bSRichard Henderson #if UINTPTR_MAX == UINT32_MAX
155eaa3783bSRichard Henderson # define tcg_gen_trunc_reg_ptr(p, r) \
156eaa3783bSRichard Henderson     tcg_gen_trunc_i64_i32(TCGV_PTR_TO_NAT(p), r)
157eaa3783bSRichard Henderson #else
158eaa3783bSRichard Henderson # define tcg_gen_trunc_reg_ptr(p, r) \
159eaa3783bSRichard Henderson     tcg_gen_mov_i64(TCGV_PTR_TO_NAT(p), r)
160eaa3783bSRichard Henderson #endif
161eaa3783bSRichard Henderson #else
162eaa3783bSRichard Henderson #define TCGv_reg             TCGv_i32
163eaa3783bSRichard Henderson #define tcg_temp_new         tcg_temp_new_i32
164eaa3783bSRichard Henderson #define tcg_global_reg_new   tcg_global_reg_new_i32
165eaa3783bSRichard Henderson #define tcg_global_mem_new   tcg_global_mem_new_i32
166eaa3783bSRichard Henderson #define tcg_temp_local_new   tcg_temp_local_new_i32
167eaa3783bSRichard Henderson #define tcg_temp_free        tcg_temp_free_i32
168eaa3783bSRichard Henderson 
169eaa3783bSRichard Henderson #define tcg_gen_movi_reg     tcg_gen_movi_i32
170eaa3783bSRichard Henderson #define tcg_gen_mov_reg      tcg_gen_mov_i32
171eaa3783bSRichard Henderson #define tcg_gen_ld8u_reg     tcg_gen_ld8u_i32
172eaa3783bSRichard Henderson #define tcg_gen_ld8s_reg     tcg_gen_ld8s_i32
173eaa3783bSRichard Henderson #define tcg_gen_ld16u_reg    tcg_gen_ld16u_i32
174eaa3783bSRichard Henderson #define tcg_gen_ld16s_reg    tcg_gen_ld16s_i32
175eaa3783bSRichard Henderson #define tcg_gen_ld32u_reg    tcg_gen_ld_i32
176eaa3783bSRichard Henderson #define tcg_gen_ld32s_reg    tcg_gen_ld_i32
177eaa3783bSRichard Henderson #define tcg_gen_ld_reg       tcg_gen_ld_i32
178eaa3783bSRichard Henderson #define tcg_gen_st8_reg      tcg_gen_st8_i32
179eaa3783bSRichard Henderson #define tcg_gen_st16_reg     tcg_gen_st16_i32
180eaa3783bSRichard Henderson #define tcg_gen_st32_reg     tcg_gen_st32_i32
181eaa3783bSRichard Henderson #define tcg_gen_st_reg       tcg_gen_st_i32
182eaa3783bSRichard Henderson #define tcg_gen_add_reg      tcg_gen_add_i32
183eaa3783bSRichard Henderson #define tcg_gen_addi_reg     tcg_gen_addi_i32
184eaa3783bSRichard Henderson #define tcg_gen_sub_reg      tcg_gen_sub_i32
185eaa3783bSRichard Henderson #define tcg_gen_neg_reg      tcg_gen_neg_i32
186eaa3783bSRichard Henderson #define tcg_gen_subfi_reg    tcg_gen_subfi_i32
187eaa3783bSRichard Henderson #define tcg_gen_subi_reg     tcg_gen_subi_i32
188eaa3783bSRichard Henderson #define tcg_gen_and_reg      tcg_gen_and_i32
189eaa3783bSRichard Henderson #define tcg_gen_andi_reg     tcg_gen_andi_i32
190eaa3783bSRichard Henderson #define tcg_gen_or_reg       tcg_gen_or_i32
191eaa3783bSRichard Henderson #define tcg_gen_ori_reg      tcg_gen_ori_i32
192eaa3783bSRichard Henderson #define tcg_gen_xor_reg      tcg_gen_xor_i32
193eaa3783bSRichard Henderson #define tcg_gen_xori_reg     tcg_gen_xori_i32
194eaa3783bSRichard Henderson #define tcg_gen_not_reg      tcg_gen_not_i32
195eaa3783bSRichard Henderson #define tcg_gen_shl_reg      tcg_gen_shl_i32
196eaa3783bSRichard Henderson #define tcg_gen_shli_reg     tcg_gen_shli_i32
197eaa3783bSRichard Henderson #define tcg_gen_shr_reg      tcg_gen_shr_i32
198eaa3783bSRichard Henderson #define tcg_gen_shri_reg     tcg_gen_shri_i32
199eaa3783bSRichard Henderson #define tcg_gen_sar_reg      tcg_gen_sar_i32
200eaa3783bSRichard Henderson #define tcg_gen_sari_reg     tcg_gen_sari_i32
201eaa3783bSRichard Henderson #define tcg_gen_brcond_reg   tcg_gen_brcond_i32
202eaa3783bSRichard Henderson #define tcg_gen_brcondi_reg  tcg_gen_brcondi_i32
203eaa3783bSRichard Henderson #define tcg_gen_setcond_reg  tcg_gen_setcond_i32
204eaa3783bSRichard Henderson #define tcg_gen_setcondi_reg tcg_gen_setcondi_i32
205eaa3783bSRichard Henderson #define tcg_gen_mul_reg      tcg_gen_mul_i32
206eaa3783bSRichard Henderson #define tcg_gen_muli_reg     tcg_gen_muli_i32
207eaa3783bSRichard Henderson #define tcg_gen_div_reg      tcg_gen_div_i32
208eaa3783bSRichard Henderson #define tcg_gen_rem_reg      tcg_gen_rem_i32
209eaa3783bSRichard Henderson #define tcg_gen_divu_reg     tcg_gen_divu_i32
210eaa3783bSRichard Henderson #define tcg_gen_remu_reg     tcg_gen_remu_i32
211eaa3783bSRichard Henderson #define tcg_gen_discard_reg  tcg_gen_discard_i32
212eaa3783bSRichard Henderson #define tcg_gen_trunc_reg_i32 tcg_gen_mov_i32
213eaa3783bSRichard Henderson #define tcg_gen_trunc_i64_reg tcg_gen_extrl_i64_i32
214eaa3783bSRichard Henderson #define tcg_gen_extu_i32_reg tcg_gen_mov_i32
215eaa3783bSRichard Henderson #define tcg_gen_ext_i32_reg  tcg_gen_mov_i32
216eaa3783bSRichard Henderson #define tcg_gen_extu_reg_i64 tcg_gen_extu_i32_i64
217eaa3783bSRichard Henderson #define tcg_gen_ext_reg_i64  tcg_gen_ext_i32_i64
218eaa3783bSRichard Henderson #define tcg_gen_ext8u_reg    tcg_gen_ext8u_i32
219eaa3783bSRichard Henderson #define tcg_gen_ext8s_reg    tcg_gen_ext8s_i32
220eaa3783bSRichard Henderson #define tcg_gen_ext16u_reg   tcg_gen_ext16u_i32
221eaa3783bSRichard Henderson #define tcg_gen_ext16s_reg   tcg_gen_ext16s_i32
222eaa3783bSRichard Henderson #define tcg_gen_ext32u_reg   tcg_gen_mov_i32
223eaa3783bSRichard Henderson #define tcg_gen_ext32s_reg   tcg_gen_mov_i32
224eaa3783bSRichard Henderson #define tcg_gen_bswap16_reg  tcg_gen_bswap16_i32
225eaa3783bSRichard Henderson #define tcg_gen_bswap32_reg  tcg_gen_bswap32_i32
226eaa3783bSRichard Henderson #define tcg_gen_concat_reg_i64 tcg_gen_concat_i32_i64
227eaa3783bSRichard Henderson #define tcg_gen_andc_reg     tcg_gen_andc_i32
228eaa3783bSRichard Henderson #define tcg_gen_eqv_reg      tcg_gen_eqv_i32
229eaa3783bSRichard Henderson #define tcg_gen_nand_reg     tcg_gen_nand_i32
230eaa3783bSRichard Henderson #define tcg_gen_nor_reg      tcg_gen_nor_i32
231eaa3783bSRichard Henderson #define tcg_gen_orc_reg      tcg_gen_orc_i32
232eaa3783bSRichard Henderson #define tcg_gen_clz_reg      tcg_gen_clz_i32
233eaa3783bSRichard Henderson #define tcg_gen_ctz_reg      tcg_gen_ctz_i32
234eaa3783bSRichard Henderson #define tcg_gen_clzi_reg     tcg_gen_clzi_i32
235eaa3783bSRichard Henderson #define tcg_gen_ctzi_reg     tcg_gen_ctzi_i32
236eaa3783bSRichard Henderson #define tcg_gen_clrsb_reg    tcg_gen_clrsb_i32
237eaa3783bSRichard Henderson #define tcg_gen_ctpop_reg    tcg_gen_ctpop_i32
238eaa3783bSRichard Henderson #define tcg_gen_rotl_reg     tcg_gen_rotl_i32
239eaa3783bSRichard Henderson #define tcg_gen_rotli_reg    tcg_gen_rotli_i32
240eaa3783bSRichard Henderson #define tcg_gen_rotr_reg     tcg_gen_rotr_i32
241eaa3783bSRichard Henderson #define tcg_gen_rotri_reg    tcg_gen_rotri_i32
242eaa3783bSRichard Henderson #define tcg_gen_deposit_reg  tcg_gen_deposit_i32
243eaa3783bSRichard Henderson #define tcg_gen_deposit_z_reg tcg_gen_deposit_z_i32
244eaa3783bSRichard Henderson #define tcg_gen_extract_reg  tcg_gen_extract_i32
245eaa3783bSRichard Henderson #define tcg_gen_sextract_reg tcg_gen_sextract_i32
246eaa3783bSRichard Henderson #define tcg_const_reg        tcg_const_i32
247eaa3783bSRichard Henderson #define tcg_const_local_reg  tcg_const_local_i32
248eaa3783bSRichard Henderson #define tcg_gen_movcond_reg  tcg_gen_movcond_i32
249eaa3783bSRichard Henderson #define tcg_gen_add2_reg     tcg_gen_add2_i32
250eaa3783bSRichard Henderson #define tcg_gen_sub2_reg     tcg_gen_sub2_i32
251eaa3783bSRichard Henderson #define tcg_gen_qemu_ld_reg  tcg_gen_qemu_ld_i32
252eaa3783bSRichard Henderson #define tcg_gen_qemu_st_reg  tcg_gen_qemu_st_i32
253eaa3783bSRichard Henderson #define tcg_gen_atomic_xchg_reg tcg_gen_atomic_xchg_i32
254eaa3783bSRichard Henderson #if UINTPTR_MAX == UINT32_MAX
255eaa3783bSRichard Henderson # define tcg_gen_trunc_reg_ptr(p, r) \
256eaa3783bSRichard Henderson     tcg_gen_mov_i32(TCGV_PTR_TO_NAT(p), r)
257eaa3783bSRichard Henderson #else
258eaa3783bSRichard Henderson # define tcg_gen_trunc_reg_ptr(p, r) \
259eaa3783bSRichard Henderson     tcg_gen_extu_i32_i64(TCGV_PTR_TO_NAT(p), r)
260eaa3783bSRichard Henderson #endif
261eaa3783bSRichard Henderson #endif /* TARGET_REGISTER_BITS */
262eaa3783bSRichard Henderson 
26361766fe9SRichard Henderson typedef struct DisasCond {
26461766fe9SRichard Henderson     TCGCond c;
265eaa3783bSRichard Henderson     TCGv_reg a0, a1;
26661766fe9SRichard Henderson     bool a0_is_n;
26761766fe9SRichard Henderson     bool a1_is_0;
26861766fe9SRichard Henderson } DisasCond;
26961766fe9SRichard Henderson 
27061766fe9SRichard Henderson typedef struct DisasContext {
271d01a3625SRichard Henderson     DisasContextBase base;
27261766fe9SRichard Henderson     CPUState *cs;
27361766fe9SRichard Henderson 
274eaa3783bSRichard Henderson     target_ureg iaoq_f;
275eaa3783bSRichard Henderson     target_ureg iaoq_b;
276eaa3783bSRichard Henderson     target_ureg iaoq_n;
277eaa3783bSRichard Henderson     TCGv_reg iaoq_n_var;
27861766fe9SRichard Henderson 
27961766fe9SRichard Henderson     int ntemps;
280eaa3783bSRichard Henderson     TCGv_reg temps[8];
28161766fe9SRichard Henderson 
28261766fe9SRichard Henderson     DisasCond null_cond;
28361766fe9SRichard Henderson     TCGLabel *null_lab;
28461766fe9SRichard Henderson 
285*1a19da0dSRichard Henderson     uint32_t insn;
2863d68ee7bSRichard Henderson     int mmu_idx;
2873d68ee7bSRichard Henderson     int privilege;
28861766fe9SRichard Henderson     bool psw_n_nonzero;
28961766fe9SRichard Henderson } DisasContext;
29061766fe9SRichard Henderson 
291869051eaSRichard Henderson /* Target-specific return values from translate_one, indicating the
292869051eaSRichard Henderson    state of the TB.  Note that DISAS_NEXT indicates that we are not
293869051eaSRichard Henderson    exiting the TB.  */
29461766fe9SRichard Henderson 
29561766fe9SRichard Henderson /* We are not using a goto_tb (for whatever reason), but have updated
29661766fe9SRichard Henderson    the iaq (for whatever reason), so don't do it again on exit.  */
297869051eaSRichard Henderson #define DISAS_IAQ_N_UPDATED  DISAS_TARGET_0
29861766fe9SRichard Henderson 
29961766fe9SRichard Henderson /* We are exiting the TB, but have neither emitted a goto_tb, nor
30061766fe9SRichard Henderson    updated the iaq for the next instruction to be executed.  */
301869051eaSRichard Henderson #define DISAS_IAQ_N_STALE    DISAS_TARGET_1
30261766fe9SRichard Henderson 
303e1b5a5edSRichard Henderson /* Similarly, but we want to return to the main loop immediately
304e1b5a5edSRichard Henderson    to recognize unmasked interrupts.  */
305e1b5a5edSRichard Henderson #define DISAS_IAQ_N_STALE_EXIT      DISAS_TARGET_2
306e1b5a5edSRichard Henderson 
30761766fe9SRichard Henderson typedef struct DisasInsn {
30861766fe9SRichard Henderson     uint32_t insn, mask;
309869051eaSRichard Henderson     DisasJumpType (*trans)(DisasContext *ctx, uint32_t insn,
31061766fe9SRichard Henderson                            const struct DisasInsn *f);
311b2167459SRichard Henderson     union {
312eaa3783bSRichard Henderson         void (*ttt)(TCGv_reg, TCGv_reg, TCGv_reg);
313eff235ebSPaolo Bonzini         void (*weww)(TCGv_i32, TCGv_env, TCGv_i32, TCGv_i32);
314eff235ebSPaolo Bonzini         void (*dedd)(TCGv_i64, TCGv_env, TCGv_i64, TCGv_i64);
315eff235ebSPaolo Bonzini         void (*wew)(TCGv_i32, TCGv_env, TCGv_i32);
316eff235ebSPaolo Bonzini         void (*ded)(TCGv_i64, TCGv_env, TCGv_i64);
317eff235ebSPaolo Bonzini         void (*wed)(TCGv_i32, TCGv_env, TCGv_i64);
318eff235ebSPaolo Bonzini         void (*dew)(TCGv_i64, TCGv_env, TCGv_i32);
319eff235ebSPaolo Bonzini     } f;
32061766fe9SRichard Henderson } DisasInsn;
32161766fe9SRichard Henderson 
32261766fe9SRichard Henderson /* global register indexes */
323eaa3783bSRichard Henderson static TCGv_reg cpu_gr[32];
32433423472SRichard Henderson static TCGv_i64 cpu_sr[4];
325eaa3783bSRichard Henderson static TCGv_reg cpu_iaoq_f;
326eaa3783bSRichard Henderson static TCGv_reg cpu_iaoq_b;
327eaa3783bSRichard Henderson static TCGv_reg cpu_sar;
328eaa3783bSRichard Henderson static TCGv_reg cpu_psw_n;
329eaa3783bSRichard Henderson static TCGv_reg cpu_psw_v;
330eaa3783bSRichard Henderson static TCGv_reg cpu_psw_cb;
331eaa3783bSRichard Henderson static TCGv_reg cpu_psw_cb_msb;
33261766fe9SRichard Henderson 
33361766fe9SRichard Henderson #include "exec/gen-icount.h"
33461766fe9SRichard Henderson 
33561766fe9SRichard Henderson void hppa_translate_init(void)
33661766fe9SRichard Henderson {
33761766fe9SRichard Henderson #define DEF_VAR(V)  { &cpu_##V, #V, offsetof(CPUHPPAState, V) }
33861766fe9SRichard Henderson 
339eaa3783bSRichard Henderson     typedef struct { TCGv_reg *var; const char *name; int ofs; } GlobalVar;
34061766fe9SRichard Henderson     static const GlobalVar vars[] = {
34135136a77SRichard Henderson         { &cpu_sar, "sar", offsetof(CPUHPPAState, cr[CR_SAR]) },
34261766fe9SRichard Henderson         DEF_VAR(psw_n),
34361766fe9SRichard Henderson         DEF_VAR(psw_v),
34461766fe9SRichard Henderson         DEF_VAR(psw_cb),
34561766fe9SRichard Henderson         DEF_VAR(psw_cb_msb),
34661766fe9SRichard Henderson         DEF_VAR(iaoq_f),
34761766fe9SRichard Henderson         DEF_VAR(iaoq_b),
34861766fe9SRichard Henderson     };
34961766fe9SRichard Henderson 
35061766fe9SRichard Henderson #undef DEF_VAR
35161766fe9SRichard Henderson 
35261766fe9SRichard Henderson     /* Use the symbolic register names that match the disassembler.  */
35361766fe9SRichard Henderson     static const char gr_names[32][4] = {
35461766fe9SRichard Henderson         "r0",  "r1",  "r2",  "r3",  "r4",  "r5",  "r6",  "r7",
35561766fe9SRichard Henderson         "r8",  "r9",  "r10", "r11", "r12", "r13", "r14", "r15",
35661766fe9SRichard Henderson         "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
35761766fe9SRichard Henderson         "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31"
35861766fe9SRichard Henderson     };
35933423472SRichard Henderson     /* SR[4-7] are not global registers so that we can index them.  */
36033423472SRichard Henderson     static const char sr_names[4][4] = {
36133423472SRichard Henderson         "sr0", "sr1", "sr2", "sr3"
36233423472SRichard Henderson     };
36361766fe9SRichard Henderson 
36461766fe9SRichard Henderson     int i;
36561766fe9SRichard Henderson 
366f764718dSRichard Henderson     cpu_gr[0] = NULL;
36761766fe9SRichard Henderson     for (i = 1; i < 32; i++) {
36861766fe9SRichard Henderson         cpu_gr[i] = tcg_global_mem_new(cpu_env,
36961766fe9SRichard Henderson                                        offsetof(CPUHPPAState, gr[i]),
37061766fe9SRichard Henderson                                        gr_names[i]);
37161766fe9SRichard Henderson     }
37233423472SRichard Henderson     for (i = 0; i < 4; i++) {
37333423472SRichard Henderson         cpu_sr[i] = tcg_global_mem_new_i64(cpu_env,
37433423472SRichard Henderson                                            offsetof(CPUHPPAState, sr[i]),
37533423472SRichard Henderson                                            sr_names[i]);
37633423472SRichard Henderson     }
37761766fe9SRichard Henderson 
37861766fe9SRichard Henderson     for (i = 0; i < ARRAY_SIZE(vars); ++i) {
37961766fe9SRichard Henderson         const GlobalVar *v = &vars[i];
38061766fe9SRichard Henderson         *v->var = tcg_global_mem_new(cpu_env, v->ofs, v->name);
38161766fe9SRichard Henderson     }
38261766fe9SRichard Henderson }
38361766fe9SRichard Henderson 
384129e9cc3SRichard Henderson static DisasCond cond_make_f(void)
385129e9cc3SRichard Henderson {
386f764718dSRichard Henderson     return (DisasCond){
387f764718dSRichard Henderson         .c = TCG_COND_NEVER,
388f764718dSRichard Henderson         .a0 = NULL,
389f764718dSRichard Henderson         .a1 = NULL,
390f764718dSRichard Henderson     };
391129e9cc3SRichard Henderson }
392129e9cc3SRichard Henderson 
393129e9cc3SRichard Henderson static DisasCond cond_make_n(void)
394129e9cc3SRichard Henderson {
395f764718dSRichard Henderson     return (DisasCond){
396f764718dSRichard Henderson         .c = TCG_COND_NE,
397f764718dSRichard Henderson         .a0 = cpu_psw_n,
398f764718dSRichard Henderson         .a0_is_n = true,
399f764718dSRichard Henderson         .a1 = NULL,
400f764718dSRichard Henderson         .a1_is_0 = true
401f764718dSRichard Henderson     };
402129e9cc3SRichard Henderson }
403129e9cc3SRichard Henderson 
404eaa3783bSRichard Henderson static DisasCond cond_make_0(TCGCond c, TCGv_reg a0)
405129e9cc3SRichard Henderson {
406f764718dSRichard Henderson     DisasCond r = { .c = c, .a1 = NULL, .a1_is_0 = true };
407129e9cc3SRichard Henderson 
408129e9cc3SRichard Henderson     assert (c != TCG_COND_NEVER && c != TCG_COND_ALWAYS);
409129e9cc3SRichard Henderson     r.a0 = tcg_temp_new();
410eaa3783bSRichard Henderson     tcg_gen_mov_reg(r.a0, a0);
411129e9cc3SRichard Henderson 
412129e9cc3SRichard Henderson     return r;
413129e9cc3SRichard Henderson }
414129e9cc3SRichard Henderson 
415eaa3783bSRichard Henderson static DisasCond cond_make(TCGCond c, TCGv_reg a0, TCGv_reg a1)
416129e9cc3SRichard Henderson {
417129e9cc3SRichard Henderson     DisasCond r = { .c = c };
418129e9cc3SRichard Henderson 
419129e9cc3SRichard Henderson     assert (c != TCG_COND_NEVER && c != TCG_COND_ALWAYS);
420129e9cc3SRichard Henderson     r.a0 = tcg_temp_new();
421eaa3783bSRichard Henderson     tcg_gen_mov_reg(r.a0, a0);
422129e9cc3SRichard Henderson     r.a1 = tcg_temp_new();
423eaa3783bSRichard Henderson     tcg_gen_mov_reg(r.a1, a1);
424129e9cc3SRichard Henderson 
425129e9cc3SRichard Henderson     return r;
426129e9cc3SRichard Henderson }
427129e9cc3SRichard Henderson 
428129e9cc3SRichard Henderson static void cond_prep(DisasCond *cond)
429129e9cc3SRichard Henderson {
430129e9cc3SRichard Henderson     if (cond->a1_is_0) {
431129e9cc3SRichard Henderson         cond->a1_is_0 = false;
432eaa3783bSRichard Henderson         cond->a1 = tcg_const_reg(0);
433129e9cc3SRichard Henderson     }
434129e9cc3SRichard Henderson }
435129e9cc3SRichard Henderson 
436129e9cc3SRichard Henderson static void cond_free(DisasCond *cond)
437129e9cc3SRichard Henderson {
438129e9cc3SRichard Henderson     switch (cond->c) {
439129e9cc3SRichard Henderson     default:
440129e9cc3SRichard Henderson         if (!cond->a0_is_n) {
441129e9cc3SRichard Henderson             tcg_temp_free(cond->a0);
442129e9cc3SRichard Henderson         }
443129e9cc3SRichard Henderson         if (!cond->a1_is_0) {
444129e9cc3SRichard Henderson             tcg_temp_free(cond->a1);
445129e9cc3SRichard Henderson         }
446129e9cc3SRichard Henderson         cond->a0_is_n = false;
447129e9cc3SRichard Henderson         cond->a1_is_0 = false;
448f764718dSRichard Henderson         cond->a0 = NULL;
449f764718dSRichard Henderson         cond->a1 = NULL;
450129e9cc3SRichard Henderson         /* fallthru */
451129e9cc3SRichard Henderson     case TCG_COND_ALWAYS:
452129e9cc3SRichard Henderson         cond->c = TCG_COND_NEVER;
453129e9cc3SRichard Henderson         break;
454129e9cc3SRichard Henderson     case TCG_COND_NEVER:
455129e9cc3SRichard Henderson         break;
456129e9cc3SRichard Henderson     }
457129e9cc3SRichard Henderson }
458129e9cc3SRichard Henderson 
459eaa3783bSRichard Henderson static TCGv_reg get_temp(DisasContext *ctx)
46061766fe9SRichard Henderson {
46161766fe9SRichard Henderson     unsigned i = ctx->ntemps++;
46261766fe9SRichard Henderson     g_assert(i < ARRAY_SIZE(ctx->temps));
46361766fe9SRichard Henderson     return ctx->temps[i] = tcg_temp_new();
46461766fe9SRichard Henderson }
46561766fe9SRichard Henderson 
466eaa3783bSRichard Henderson static TCGv_reg load_const(DisasContext *ctx, target_sreg v)
46761766fe9SRichard Henderson {
468eaa3783bSRichard Henderson     TCGv_reg t = get_temp(ctx);
469eaa3783bSRichard Henderson     tcg_gen_movi_reg(t, v);
47061766fe9SRichard Henderson     return t;
47161766fe9SRichard Henderson }
47261766fe9SRichard Henderson 
473eaa3783bSRichard Henderson static TCGv_reg load_gpr(DisasContext *ctx, unsigned reg)
47461766fe9SRichard Henderson {
47561766fe9SRichard Henderson     if (reg == 0) {
476eaa3783bSRichard Henderson         TCGv_reg t = get_temp(ctx);
477eaa3783bSRichard Henderson         tcg_gen_movi_reg(t, 0);
47861766fe9SRichard Henderson         return t;
47961766fe9SRichard Henderson     } else {
48061766fe9SRichard Henderson         return cpu_gr[reg];
48161766fe9SRichard Henderson     }
48261766fe9SRichard Henderson }
48361766fe9SRichard Henderson 
484eaa3783bSRichard Henderson static TCGv_reg dest_gpr(DisasContext *ctx, unsigned reg)
48561766fe9SRichard Henderson {
486129e9cc3SRichard Henderson     if (reg == 0 || ctx->null_cond.c != TCG_COND_NEVER) {
48761766fe9SRichard Henderson         return get_temp(ctx);
48861766fe9SRichard Henderson     } else {
48961766fe9SRichard Henderson         return cpu_gr[reg];
49061766fe9SRichard Henderson     }
49161766fe9SRichard Henderson }
49261766fe9SRichard Henderson 
493eaa3783bSRichard Henderson static void save_or_nullify(DisasContext *ctx, TCGv_reg dest, TCGv_reg t)
494129e9cc3SRichard Henderson {
495129e9cc3SRichard Henderson     if (ctx->null_cond.c != TCG_COND_NEVER) {
496129e9cc3SRichard Henderson         cond_prep(&ctx->null_cond);
497eaa3783bSRichard Henderson         tcg_gen_movcond_reg(ctx->null_cond.c, dest, ctx->null_cond.a0,
498129e9cc3SRichard Henderson                            ctx->null_cond.a1, dest, t);
499129e9cc3SRichard Henderson     } else {
500eaa3783bSRichard Henderson         tcg_gen_mov_reg(dest, t);
501129e9cc3SRichard Henderson     }
502129e9cc3SRichard Henderson }
503129e9cc3SRichard Henderson 
504eaa3783bSRichard Henderson static void save_gpr(DisasContext *ctx, unsigned reg, TCGv_reg t)
505129e9cc3SRichard Henderson {
506129e9cc3SRichard Henderson     if (reg != 0) {
507129e9cc3SRichard Henderson         save_or_nullify(ctx, cpu_gr[reg], t);
508129e9cc3SRichard Henderson     }
509129e9cc3SRichard Henderson }
510129e9cc3SRichard Henderson 
51196d6407fSRichard Henderson #ifdef HOST_WORDS_BIGENDIAN
51296d6407fSRichard Henderson # define HI_OFS  0
51396d6407fSRichard Henderson # define LO_OFS  4
51496d6407fSRichard Henderson #else
51596d6407fSRichard Henderson # define HI_OFS  4
51696d6407fSRichard Henderson # define LO_OFS  0
51796d6407fSRichard Henderson #endif
51896d6407fSRichard Henderson 
51996d6407fSRichard Henderson static TCGv_i32 load_frw_i32(unsigned rt)
52096d6407fSRichard Henderson {
52196d6407fSRichard Henderson     TCGv_i32 ret = tcg_temp_new_i32();
52296d6407fSRichard Henderson     tcg_gen_ld_i32(ret, cpu_env,
52396d6407fSRichard Henderson                    offsetof(CPUHPPAState, fr[rt & 31])
52496d6407fSRichard Henderson                    + (rt & 32 ? LO_OFS : HI_OFS));
52596d6407fSRichard Henderson     return ret;
52696d6407fSRichard Henderson }
52796d6407fSRichard Henderson 
528ebe9383cSRichard Henderson static TCGv_i32 load_frw0_i32(unsigned rt)
529ebe9383cSRichard Henderson {
530ebe9383cSRichard Henderson     if (rt == 0) {
531ebe9383cSRichard Henderson         return tcg_const_i32(0);
532ebe9383cSRichard Henderson     } else {
533ebe9383cSRichard Henderson         return load_frw_i32(rt);
534ebe9383cSRichard Henderson     }
535ebe9383cSRichard Henderson }
536ebe9383cSRichard Henderson 
537ebe9383cSRichard Henderson static TCGv_i64 load_frw0_i64(unsigned rt)
538ebe9383cSRichard Henderson {
539ebe9383cSRichard Henderson     if (rt == 0) {
540ebe9383cSRichard Henderson         return tcg_const_i64(0);
541ebe9383cSRichard Henderson     } else {
542ebe9383cSRichard Henderson         TCGv_i64 ret = tcg_temp_new_i64();
543ebe9383cSRichard Henderson         tcg_gen_ld32u_i64(ret, cpu_env,
544ebe9383cSRichard Henderson                           offsetof(CPUHPPAState, fr[rt & 31])
545ebe9383cSRichard Henderson                           + (rt & 32 ? LO_OFS : HI_OFS));
546ebe9383cSRichard Henderson         return ret;
547ebe9383cSRichard Henderson     }
548ebe9383cSRichard Henderson }
549ebe9383cSRichard Henderson 
55096d6407fSRichard Henderson static void save_frw_i32(unsigned rt, TCGv_i32 val)
55196d6407fSRichard Henderson {
55296d6407fSRichard Henderson     tcg_gen_st_i32(val, cpu_env,
55396d6407fSRichard Henderson                    offsetof(CPUHPPAState, fr[rt & 31])
55496d6407fSRichard Henderson                    + (rt & 32 ? LO_OFS : HI_OFS));
55596d6407fSRichard Henderson }
55696d6407fSRichard Henderson 
55796d6407fSRichard Henderson #undef HI_OFS
55896d6407fSRichard Henderson #undef LO_OFS
55996d6407fSRichard Henderson 
56096d6407fSRichard Henderson static TCGv_i64 load_frd(unsigned rt)
56196d6407fSRichard Henderson {
56296d6407fSRichard Henderson     TCGv_i64 ret = tcg_temp_new_i64();
56396d6407fSRichard Henderson     tcg_gen_ld_i64(ret, cpu_env, offsetof(CPUHPPAState, fr[rt]));
56496d6407fSRichard Henderson     return ret;
56596d6407fSRichard Henderson }
56696d6407fSRichard Henderson 
567ebe9383cSRichard Henderson static TCGv_i64 load_frd0(unsigned rt)
568ebe9383cSRichard Henderson {
569ebe9383cSRichard Henderson     if (rt == 0) {
570ebe9383cSRichard Henderson         return tcg_const_i64(0);
571ebe9383cSRichard Henderson     } else {
572ebe9383cSRichard Henderson         return load_frd(rt);
573ebe9383cSRichard Henderson     }
574ebe9383cSRichard Henderson }
575ebe9383cSRichard Henderson 
57696d6407fSRichard Henderson static void save_frd(unsigned rt, TCGv_i64 val)
57796d6407fSRichard Henderson {
57896d6407fSRichard Henderson     tcg_gen_st_i64(val, cpu_env, offsetof(CPUHPPAState, fr[rt]));
57996d6407fSRichard Henderson }
58096d6407fSRichard Henderson 
58133423472SRichard Henderson static void load_spr(DisasContext *ctx, TCGv_i64 dest, unsigned reg)
58233423472SRichard Henderson {
58333423472SRichard Henderson #ifdef CONFIG_USER_ONLY
58433423472SRichard Henderson     tcg_gen_movi_i64(dest, 0);
58533423472SRichard Henderson #else
58633423472SRichard Henderson     if (reg < 4) {
58733423472SRichard Henderson         tcg_gen_mov_i64(dest, cpu_sr[reg]);
58833423472SRichard Henderson     } else {
58933423472SRichard Henderson         tcg_gen_ld_i64(dest, cpu_env, offsetof(CPUHPPAState, sr[reg]));
59033423472SRichard Henderson     }
59133423472SRichard Henderson #endif
59233423472SRichard Henderson }
59333423472SRichard Henderson 
594129e9cc3SRichard Henderson /* Skip over the implementation of an insn that has been nullified.
595129e9cc3SRichard Henderson    Use this when the insn is too complex for a conditional move.  */
596129e9cc3SRichard Henderson static void nullify_over(DisasContext *ctx)
597129e9cc3SRichard Henderson {
598129e9cc3SRichard Henderson     if (ctx->null_cond.c != TCG_COND_NEVER) {
599129e9cc3SRichard Henderson         /* The always condition should have been handled in the main loop.  */
600129e9cc3SRichard Henderson         assert(ctx->null_cond.c != TCG_COND_ALWAYS);
601129e9cc3SRichard Henderson 
602129e9cc3SRichard Henderson         ctx->null_lab = gen_new_label();
603129e9cc3SRichard Henderson         cond_prep(&ctx->null_cond);
604129e9cc3SRichard Henderson 
605129e9cc3SRichard Henderson         /* If we're using PSW[N], copy it to a temp because... */
606129e9cc3SRichard Henderson         if (ctx->null_cond.a0_is_n) {
607129e9cc3SRichard Henderson             ctx->null_cond.a0_is_n = false;
608129e9cc3SRichard Henderson             ctx->null_cond.a0 = tcg_temp_new();
609eaa3783bSRichard Henderson             tcg_gen_mov_reg(ctx->null_cond.a0, cpu_psw_n);
610129e9cc3SRichard Henderson         }
611129e9cc3SRichard Henderson         /* ... we clear it before branching over the implementation,
612129e9cc3SRichard Henderson            so that (1) it's clear after nullifying this insn and
613129e9cc3SRichard Henderson            (2) if this insn nullifies the next, PSW[N] is valid.  */
614129e9cc3SRichard Henderson         if (ctx->psw_n_nonzero) {
615129e9cc3SRichard Henderson             ctx->psw_n_nonzero = false;
616eaa3783bSRichard Henderson             tcg_gen_movi_reg(cpu_psw_n, 0);
617129e9cc3SRichard Henderson         }
618129e9cc3SRichard Henderson 
619eaa3783bSRichard Henderson         tcg_gen_brcond_reg(ctx->null_cond.c, ctx->null_cond.a0,
620129e9cc3SRichard Henderson                           ctx->null_cond.a1, ctx->null_lab);
621129e9cc3SRichard Henderson         cond_free(&ctx->null_cond);
622129e9cc3SRichard Henderson     }
623129e9cc3SRichard Henderson }
624129e9cc3SRichard Henderson 
625129e9cc3SRichard Henderson /* Save the current nullification state to PSW[N].  */
626129e9cc3SRichard Henderson static void nullify_save(DisasContext *ctx)
627129e9cc3SRichard Henderson {
628129e9cc3SRichard Henderson     if (ctx->null_cond.c == TCG_COND_NEVER) {
629129e9cc3SRichard Henderson         if (ctx->psw_n_nonzero) {
630eaa3783bSRichard Henderson             tcg_gen_movi_reg(cpu_psw_n, 0);
631129e9cc3SRichard Henderson         }
632129e9cc3SRichard Henderson         return;
633129e9cc3SRichard Henderson     }
634129e9cc3SRichard Henderson     if (!ctx->null_cond.a0_is_n) {
635129e9cc3SRichard Henderson         cond_prep(&ctx->null_cond);
636eaa3783bSRichard Henderson         tcg_gen_setcond_reg(ctx->null_cond.c, cpu_psw_n,
637129e9cc3SRichard Henderson                            ctx->null_cond.a0, ctx->null_cond.a1);
638129e9cc3SRichard Henderson         ctx->psw_n_nonzero = true;
639129e9cc3SRichard Henderson     }
640129e9cc3SRichard Henderson     cond_free(&ctx->null_cond);
641129e9cc3SRichard Henderson }
642129e9cc3SRichard Henderson 
643129e9cc3SRichard Henderson /* Set a PSW[N] to X.  The intention is that this is used immediately
644129e9cc3SRichard Henderson    before a goto_tb/exit_tb, so that there is no fallthru path to other
645129e9cc3SRichard Henderson    code within the TB.  Therefore we do not update psw_n_nonzero.  */
646129e9cc3SRichard Henderson static void nullify_set(DisasContext *ctx, bool x)
647129e9cc3SRichard Henderson {
648129e9cc3SRichard Henderson     if (ctx->psw_n_nonzero || x) {
649eaa3783bSRichard Henderson         tcg_gen_movi_reg(cpu_psw_n, x);
650129e9cc3SRichard Henderson     }
651129e9cc3SRichard Henderson }
652129e9cc3SRichard Henderson 
653129e9cc3SRichard Henderson /* Mark the end of an instruction that may have been nullified.
654129e9cc3SRichard Henderson    This is the pair to nullify_over.  */
655869051eaSRichard Henderson static DisasJumpType nullify_end(DisasContext *ctx, DisasJumpType status)
656129e9cc3SRichard Henderson {
657129e9cc3SRichard Henderson     TCGLabel *null_lab = ctx->null_lab;
658129e9cc3SRichard Henderson 
659f49b3537SRichard Henderson     /* For NEXT, NORETURN, STALE, we can easily continue (or exit).
660f49b3537SRichard Henderson        For UPDATED, we cannot update on the nullified path.  */
661f49b3537SRichard Henderson     assert(status != DISAS_IAQ_N_UPDATED);
662f49b3537SRichard Henderson 
663129e9cc3SRichard Henderson     if (likely(null_lab == NULL)) {
664129e9cc3SRichard Henderson         /* The current insn wasn't conditional or handled the condition
665129e9cc3SRichard Henderson            applied to it without a branch, so the (new) setting of
666129e9cc3SRichard Henderson            NULL_COND can be applied directly to the next insn.  */
667129e9cc3SRichard Henderson         return status;
668129e9cc3SRichard Henderson     }
669129e9cc3SRichard Henderson     ctx->null_lab = NULL;
670129e9cc3SRichard Henderson 
671129e9cc3SRichard Henderson     if (likely(ctx->null_cond.c == TCG_COND_NEVER)) {
672129e9cc3SRichard Henderson         /* The next instruction will be unconditional,
673129e9cc3SRichard Henderson            and NULL_COND already reflects that.  */
674129e9cc3SRichard Henderson         gen_set_label(null_lab);
675129e9cc3SRichard Henderson     } else {
676129e9cc3SRichard Henderson         /* The insn that we just executed is itself nullifying the next
677129e9cc3SRichard Henderson            instruction.  Store the condition in the PSW[N] global.
678129e9cc3SRichard Henderson            We asserted PSW[N] = 0 in nullify_over, so that after the
679129e9cc3SRichard Henderson            label we have the proper value in place.  */
680129e9cc3SRichard Henderson         nullify_save(ctx);
681129e9cc3SRichard Henderson         gen_set_label(null_lab);
682129e9cc3SRichard Henderson         ctx->null_cond = cond_make_n();
683129e9cc3SRichard Henderson     }
684869051eaSRichard Henderson     if (status == DISAS_NORETURN) {
685869051eaSRichard Henderson         status = DISAS_NEXT;
686129e9cc3SRichard Henderson     }
687129e9cc3SRichard Henderson     return status;
688129e9cc3SRichard Henderson }
689129e9cc3SRichard Henderson 
690eaa3783bSRichard Henderson static void copy_iaoq_entry(TCGv_reg dest, target_ureg ival, TCGv_reg vval)
69161766fe9SRichard Henderson {
69261766fe9SRichard Henderson     if (unlikely(ival == -1)) {
693eaa3783bSRichard Henderson         tcg_gen_mov_reg(dest, vval);
69461766fe9SRichard Henderson     } else {
695eaa3783bSRichard Henderson         tcg_gen_movi_reg(dest, ival);
69661766fe9SRichard Henderson     }
69761766fe9SRichard Henderson }
69861766fe9SRichard Henderson 
699eaa3783bSRichard Henderson static inline target_ureg iaoq_dest(DisasContext *ctx, target_sreg disp)
70061766fe9SRichard Henderson {
70161766fe9SRichard Henderson     return ctx->iaoq_f + disp + 8;
70261766fe9SRichard Henderson }
70361766fe9SRichard Henderson 
70461766fe9SRichard Henderson static void gen_excp_1(int exception)
70561766fe9SRichard Henderson {
70661766fe9SRichard Henderson     TCGv_i32 t = tcg_const_i32(exception);
70761766fe9SRichard Henderson     gen_helper_excp(cpu_env, t);
70861766fe9SRichard Henderson     tcg_temp_free_i32(t);
70961766fe9SRichard Henderson }
71061766fe9SRichard Henderson 
711869051eaSRichard Henderson static DisasJumpType gen_excp(DisasContext *ctx, int exception)
71261766fe9SRichard Henderson {
71361766fe9SRichard Henderson     copy_iaoq_entry(cpu_iaoq_f, ctx->iaoq_f, cpu_iaoq_f);
71461766fe9SRichard Henderson     copy_iaoq_entry(cpu_iaoq_b, ctx->iaoq_b, cpu_iaoq_b);
715129e9cc3SRichard Henderson     nullify_save(ctx);
71661766fe9SRichard Henderson     gen_excp_1(exception);
717869051eaSRichard Henderson     return DISAS_NORETURN;
71861766fe9SRichard Henderson }
71961766fe9SRichard Henderson 
720*1a19da0dSRichard Henderson static DisasJumpType gen_excp_iir(DisasContext *ctx, int exc)
721*1a19da0dSRichard Henderson {
722*1a19da0dSRichard Henderson     TCGv_reg tmp = tcg_const_reg(ctx->insn);
723*1a19da0dSRichard Henderson     tcg_gen_st_reg(tmp, cpu_env, offsetof(CPUHPPAState, cr[CR_IIR]));
724*1a19da0dSRichard Henderson     tcg_temp_free(tmp);
725*1a19da0dSRichard Henderson     return gen_excp(ctx, exc);
726*1a19da0dSRichard Henderson }
727*1a19da0dSRichard Henderson 
728869051eaSRichard Henderson static DisasJumpType gen_illegal(DisasContext *ctx)
72961766fe9SRichard Henderson {
730129e9cc3SRichard Henderson     nullify_over(ctx);
731*1a19da0dSRichard Henderson     return nullify_end(ctx, gen_excp_iir(ctx, EXCP_ILL));
73261766fe9SRichard Henderson }
73361766fe9SRichard Henderson 
734e1b5a5edSRichard Henderson #define CHECK_MOST_PRIVILEGED(EXCP)                               \
735e1b5a5edSRichard Henderson     do {                                                          \
736e1b5a5edSRichard Henderson         if (ctx->privilege != 0) {                                \
737e1b5a5edSRichard Henderson             nullify_over(ctx);                                    \
738*1a19da0dSRichard Henderson             return nullify_end(ctx, gen_excp_iir(ctx, EXCP));     \
739e1b5a5edSRichard Henderson         }                                                         \
740e1b5a5edSRichard Henderson     } while (0)
741e1b5a5edSRichard Henderson 
742eaa3783bSRichard Henderson static bool use_goto_tb(DisasContext *ctx, target_ureg dest)
74361766fe9SRichard Henderson {
74461766fe9SRichard Henderson     /* Suppress goto_tb in the case of single-steping and IO.  */
745c5a49c63SEmilio G. Cota     if ((tb_cflags(ctx->base.tb) & CF_LAST_IO) || ctx->base.singlestep_enabled) {
74661766fe9SRichard Henderson         return false;
74761766fe9SRichard Henderson     }
74861766fe9SRichard Henderson     return true;
74961766fe9SRichard Henderson }
75061766fe9SRichard Henderson 
751129e9cc3SRichard Henderson /* If the next insn is to be nullified, and it's on the same page,
752129e9cc3SRichard Henderson    and we're not attempting to set a breakpoint on it, then we can
753129e9cc3SRichard Henderson    totally skip the nullified insn.  This avoids creating and
754129e9cc3SRichard Henderson    executing a TB that merely branches to the next TB.  */
755129e9cc3SRichard Henderson static bool use_nullify_skip(DisasContext *ctx)
756129e9cc3SRichard Henderson {
757129e9cc3SRichard Henderson     return (((ctx->iaoq_b ^ ctx->iaoq_f) & TARGET_PAGE_MASK) == 0
758129e9cc3SRichard Henderson             && !cpu_breakpoint_test(ctx->cs, ctx->iaoq_b, BP_ANY));
759129e9cc3SRichard Henderson }
760129e9cc3SRichard Henderson 
76161766fe9SRichard Henderson static void gen_goto_tb(DisasContext *ctx, int which,
762eaa3783bSRichard Henderson                         target_ureg f, target_ureg b)
76361766fe9SRichard Henderson {
76461766fe9SRichard Henderson     if (f != -1 && b != -1 && use_goto_tb(ctx, f)) {
76561766fe9SRichard Henderson         tcg_gen_goto_tb(which);
766eaa3783bSRichard Henderson         tcg_gen_movi_reg(cpu_iaoq_f, f);
767eaa3783bSRichard Henderson         tcg_gen_movi_reg(cpu_iaoq_b, b);
768d01a3625SRichard Henderson         tcg_gen_exit_tb((uintptr_t)ctx->base.tb + which);
76961766fe9SRichard Henderson     } else {
77061766fe9SRichard Henderson         copy_iaoq_entry(cpu_iaoq_f, f, cpu_iaoq_b);
77161766fe9SRichard Henderson         copy_iaoq_entry(cpu_iaoq_b, b, ctx->iaoq_n_var);
772d01a3625SRichard Henderson         if (ctx->base.singlestep_enabled) {
77361766fe9SRichard Henderson             gen_excp_1(EXCP_DEBUG);
77461766fe9SRichard Henderson         } else {
7757f11636dSEmilio G. Cota             tcg_gen_lookup_and_goto_ptr();
77661766fe9SRichard Henderson         }
77761766fe9SRichard Henderson     }
77861766fe9SRichard Henderson }
77961766fe9SRichard Henderson 
780b2167459SRichard Henderson /* PA has a habit of taking the LSB of a field and using that as the sign,
781b2167459SRichard Henderson    with the rest of the field becoming the least significant bits.  */
782eaa3783bSRichard Henderson static target_sreg low_sextract(uint32_t val, int pos, int len)
783b2167459SRichard Henderson {
784eaa3783bSRichard Henderson     target_ureg x = -(target_ureg)extract32(val, pos, 1);
785b2167459SRichard Henderson     x = (x << (len - 1)) | extract32(val, pos + 1, len - 1);
786b2167459SRichard Henderson     return x;
787b2167459SRichard Henderson }
788b2167459SRichard Henderson 
789ebe9383cSRichard Henderson static unsigned assemble_rt64(uint32_t insn)
790ebe9383cSRichard Henderson {
791ebe9383cSRichard Henderson     unsigned r1 = extract32(insn, 6, 1);
792ebe9383cSRichard Henderson     unsigned r0 = extract32(insn, 0, 5);
793ebe9383cSRichard Henderson     return r1 * 32 + r0;
794ebe9383cSRichard Henderson }
795ebe9383cSRichard Henderson 
796ebe9383cSRichard Henderson static unsigned assemble_ra64(uint32_t insn)
797ebe9383cSRichard Henderson {
798ebe9383cSRichard Henderson     unsigned r1 = extract32(insn, 7, 1);
799ebe9383cSRichard Henderson     unsigned r0 = extract32(insn, 21, 5);
800ebe9383cSRichard Henderson     return r1 * 32 + r0;
801ebe9383cSRichard Henderson }
802ebe9383cSRichard Henderson 
803ebe9383cSRichard Henderson static unsigned assemble_rb64(uint32_t insn)
804ebe9383cSRichard Henderson {
805ebe9383cSRichard Henderson     unsigned r1 = extract32(insn, 12, 1);
806ebe9383cSRichard Henderson     unsigned r0 = extract32(insn, 16, 5);
807ebe9383cSRichard Henderson     return r1 * 32 + r0;
808ebe9383cSRichard Henderson }
809ebe9383cSRichard Henderson 
810ebe9383cSRichard Henderson static unsigned assemble_rc64(uint32_t insn)
811ebe9383cSRichard Henderson {
812ebe9383cSRichard Henderson     unsigned r2 = extract32(insn, 8, 1);
813ebe9383cSRichard Henderson     unsigned r1 = extract32(insn, 13, 3);
814ebe9383cSRichard Henderson     unsigned r0 = extract32(insn, 9, 2);
815ebe9383cSRichard Henderson     return r2 * 32 + r1 * 4 + r0;
816ebe9383cSRichard Henderson }
817ebe9383cSRichard Henderson 
81833423472SRichard Henderson static unsigned assemble_sr3(uint32_t insn)
81933423472SRichard Henderson {
82033423472SRichard Henderson     unsigned s2 = extract32(insn, 13, 1);
82133423472SRichard Henderson     unsigned s0 = extract32(insn, 14, 2);
82233423472SRichard Henderson     return s2 * 4 + s0;
82333423472SRichard Henderson }
82433423472SRichard Henderson 
825eaa3783bSRichard Henderson static target_sreg assemble_12(uint32_t insn)
82698cd9ca7SRichard Henderson {
827eaa3783bSRichard Henderson     target_ureg x = -(target_ureg)(insn & 1);
82898cd9ca7SRichard Henderson     x = (x <<  1) | extract32(insn, 2, 1);
82998cd9ca7SRichard Henderson     x = (x << 10) | extract32(insn, 3, 10);
83098cd9ca7SRichard Henderson     return x;
83198cd9ca7SRichard Henderson }
83298cd9ca7SRichard Henderson 
833eaa3783bSRichard Henderson static target_sreg assemble_16(uint32_t insn)
834b2167459SRichard Henderson {
835b2167459SRichard Henderson     /* Take the name from PA2.0, which produces a 16-bit number
836b2167459SRichard Henderson        only with wide mode; otherwise a 14-bit number.  Since we don't
837b2167459SRichard Henderson        implement wide mode, this is always the 14-bit number.  */
838b2167459SRichard Henderson     return low_sextract(insn, 0, 14);
839b2167459SRichard Henderson }
840b2167459SRichard Henderson 
841eaa3783bSRichard Henderson static target_sreg assemble_16a(uint32_t insn)
84296d6407fSRichard Henderson {
84396d6407fSRichard Henderson     /* Take the name from PA2.0, which produces a 14-bit shifted number
84496d6407fSRichard Henderson        only with wide mode; otherwise a 12-bit shifted number.  Since we
84596d6407fSRichard Henderson        don't implement wide mode, this is always the 12-bit number.  */
846eaa3783bSRichard Henderson     target_ureg x = -(target_ureg)(insn & 1);
84796d6407fSRichard Henderson     x = (x << 11) | extract32(insn, 2, 11);
84896d6407fSRichard Henderson     return x << 2;
84996d6407fSRichard Henderson }
85096d6407fSRichard Henderson 
851eaa3783bSRichard Henderson static target_sreg assemble_17(uint32_t insn)
85298cd9ca7SRichard Henderson {
853eaa3783bSRichard Henderson     target_ureg x = -(target_ureg)(insn & 1);
85498cd9ca7SRichard Henderson     x = (x <<  5) | extract32(insn, 16, 5);
85598cd9ca7SRichard Henderson     x = (x <<  1) | extract32(insn, 2, 1);
85698cd9ca7SRichard Henderson     x = (x << 10) | extract32(insn, 3, 10);
85798cd9ca7SRichard Henderson     return x << 2;
85898cd9ca7SRichard Henderson }
85998cd9ca7SRichard Henderson 
860eaa3783bSRichard Henderson static target_sreg assemble_21(uint32_t insn)
861b2167459SRichard Henderson {
862eaa3783bSRichard Henderson     target_ureg x = -(target_ureg)(insn & 1);
863b2167459SRichard Henderson     x = (x << 11) | extract32(insn, 1, 11);
864b2167459SRichard Henderson     x = (x <<  2) | extract32(insn, 14, 2);
865b2167459SRichard Henderson     x = (x <<  5) | extract32(insn, 16, 5);
866b2167459SRichard Henderson     x = (x <<  2) | extract32(insn, 12, 2);
867b2167459SRichard Henderson     return x << 11;
868b2167459SRichard Henderson }
869b2167459SRichard Henderson 
870eaa3783bSRichard Henderson static target_sreg assemble_22(uint32_t insn)
87198cd9ca7SRichard Henderson {
872eaa3783bSRichard Henderson     target_ureg x = -(target_ureg)(insn & 1);
87398cd9ca7SRichard Henderson     x = (x << 10) | extract32(insn, 16, 10);
87498cd9ca7SRichard Henderson     x = (x <<  1) | extract32(insn, 2, 1);
87598cd9ca7SRichard Henderson     x = (x << 10) | extract32(insn, 3, 10);
87698cd9ca7SRichard Henderson     return x << 2;
87798cd9ca7SRichard Henderson }
87898cd9ca7SRichard Henderson 
879b2167459SRichard Henderson /* The parisc documentation describes only the general interpretation of
880b2167459SRichard Henderson    the conditions, without describing their exact implementation.  The
881b2167459SRichard Henderson    interpretations do not stand up well when considering ADD,C and SUB,B.
882b2167459SRichard Henderson    However, considering the Addition, Subtraction and Logical conditions
883b2167459SRichard Henderson    as a whole it would appear that these relations are similar to what
884b2167459SRichard Henderson    a traditional NZCV set of flags would produce.  */
885b2167459SRichard Henderson 
886eaa3783bSRichard Henderson static DisasCond do_cond(unsigned cf, TCGv_reg res,
887eaa3783bSRichard Henderson                          TCGv_reg cb_msb, TCGv_reg sv)
888b2167459SRichard Henderson {
889b2167459SRichard Henderson     DisasCond cond;
890eaa3783bSRichard Henderson     TCGv_reg tmp;
891b2167459SRichard Henderson 
892b2167459SRichard Henderson     switch (cf >> 1) {
893b2167459SRichard Henderson     case 0: /* Never / TR */
894b2167459SRichard Henderson         cond = cond_make_f();
895b2167459SRichard Henderson         break;
896b2167459SRichard Henderson     case 1: /* = / <>        (Z / !Z) */
897b2167459SRichard Henderson         cond = cond_make_0(TCG_COND_EQ, res);
898b2167459SRichard Henderson         break;
899b2167459SRichard Henderson     case 2: /* < / >=        (N / !N) */
900b2167459SRichard Henderson         cond = cond_make_0(TCG_COND_LT, res);
901b2167459SRichard Henderson         break;
902b2167459SRichard Henderson     case 3: /* <= / >        (N | Z / !N & !Z) */
903b2167459SRichard Henderson         cond = cond_make_0(TCG_COND_LE, res);
904b2167459SRichard Henderson         break;
905b2167459SRichard Henderson     case 4: /* NUV / UV      (!C / C) */
906b2167459SRichard Henderson         cond = cond_make_0(TCG_COND_EQ, cb_msb);
907b2167459SRichard Henderson         break;
908b2167459SRichard Henderson     case 5: /* ZNV / VNZ     (!C | Z / C & !Z) */
909b2167459SRichard Henderson         tmp = tcg_temp_new();
910eaa3783bSRichard Henderson         tcg_gen_neg_reg(tmp, cb_msb);
911eaa3783bSRichard Henderson         tcg_gen_and_reg(tmp, tmp, res);
912b2167459SRichard Henderson         cond = cond_make_0(TCG_COND_EQ, tmp);
913b2167459SRichard Henderson         tcg_temp_free(tmp);
914b2167459SRichard Henderson         break;
915b2167459SRichard Henderson     case 6: /* SV / NSV      (V / !V) */
916b2167459SRichard Henderson         cond = cond_make_0(TCG_COND_LT, sv);
917b2167459SRichard Henderson         break;
918b2167459SRichard Henderson     case 7: /* OD / EV */
919b2167459SRichard Henderson         tmp = tcg_temp_new();
920eaa3783bSRichard Henderson         tcg_gen_andi_reg(tmp, res, 1);
921b2167459SRichard Henderson         cond = cond_make_0(TCG_COND_NE, tmp);
922b2167459SRichard Henderson         tcg_temp_free(tmp);
923b2167459SRichard Henderson         break;
924b2167459SRichard Henderson     default:
925b2167459SRichard Henderson         g_assert_not_reached();
926b2167459SRichard Henderson     }
927b2167459SRichard Henderson     if (cf & 1) {
928b2167459SRichard Henderson         cond.c = tcg_invert_cond(cond.c);
929b2167459SRichard Henderson     }
930b2167459SRichard Henderson 
931b2167459SRichard Henderson     return cond;
932b2167459SRichard Henderson }
933b2167459SRichard Henderson 
934b2167459SRichard Henderson /* Similar, but for the special case of subtraction without borrow, we
935b2167459SRichard Henderson    can use the inputs directly.  This can allow other computation to be
936b2167459SRichard Henderson    deleted as unused.  */
937b2167459SRichard Henderson 
938eaa3783bSRichard Henderson static DisasCond do_sub_cond(unsigned cf, TCGv_reg res,
939eaa3783bSRichard Henderson                              TCGv_reg in1, TCGv_reg in2, TCGv_reg sv)
940b2167459SRichard Henderson {
941b2167459SRichard Henderson     DisasCond cond;
942b2167459SRichard Henderson 
943b2167459SRichard Henderson     switch (cf >> 1) {
944b2167459SRichard Henderson     case 1: /* = / <> */
945b2167459SRichard Henderson         cond = cond_make(TCG_COND_EQ, in1, in2);
946b2167459SRichard Henderson         break;
947b2167459SRichard Henderson     case 2: /* < / >= */
948b2167459SRichard Henderson         cond = cond_make(TCG_COND_LT, in1, in2);
949b2167459SRichard Henderson         break;
950b2167459SRichard Henderson     case 3: /* <= / > */
951b2167459SRichard Henderson         cond = cond_make(TCG_COND_LE, in1, in2);
952b2167459SRichard Henderson         break;
953b2167459SRichard Henderson     case 4: /* << / >>= */
954b2167459SRichard Henderson         cond = cond_make(TCG_COND_LTU, in1, in2);
955b2167459SRichard Henderson         break;
956b2167459SRichard Henderson     case 5: /* <<= / >> */
957b2167459SRichard Henderson         cond = cond_make(TCG_COND_LEU, in1, in2);
958b2167459SRichard Henderson         break;
959b2167459SRichard Henderson     default:
960b2167459SRichard Henderson         return do_cond(cf, res, sv, sv);
961b2167459SRichard Henderson     }
962b2167459SRichard Henderson     if (cf & 1) {
963b2167459SRichard Henderson         cond.c = tcg_invert_cond(cond.c);
964b2167459SRichard Henderson     }
965b2167459SRichard Henderson 
966b2167459SRichard Henderson     return cond;
967b2167459SRichard Henderson }
968b2167459SRichard Henderson 
969b2167459SRichard Henderson /* Similar, but for logicals, where the carry and overflow bits are not
970b2167459SRichard Henderson    computed, and use of them is undefined.  */
971b2167459SRichard Henderson 
972eaa3783bSRichard Henderson static DisasCond do_log_cond(unsigned cf, TCGv_reg res)
973b2167459SRichard Henderson {
974b2167459SRichard Henderson     switch (cf >> 1) {
975b2167459SRichard Henderson     case 4: case 5: case 6:
976b2167459SRichard Henderson         cf &= 1;
977b2167459SRichard Henderson         break;
978b2167459SRichard Henderson     }
979b2167459SRichard Henderson     return do_cond(cf, res, res, res);
980b2167459SRichard Henderson }
981b2167459SRichard Henderson 
98298cd9ca7SRichard Henderson /* Similar, but for shift/extract/deposit conditions.  */
98398cd9ca7SRichard Henderson 
984eaa3783bSRichard Henderson static DisasCond do_sed_cond(unsigned orig, TCGv_reg res)
98598cd9ca7SRichard Henderson {
98698cd9ca7SRichard Henderson     unsigned c, f;
98798cd9ca7SRichard Henderson 
98898cd9ca7SRichard Henderson     /* Convert the compressed condition codes to standard.
98998cd9ca7SRichard Henderson        0-2 are the same as logicals (nv,<,<=), while 3 is OD.
99098cd9ca7SRichard Henderson        4-7 are the reverse of 0-3.  */
99198cd9ca7SRichard Henderson     c = orig & 3;
99298cd9ca7SRichard Henderson     if (c == 3) {
99398cd9ca7SRichard Henderson         c = 7;
99498cd9ca7SRichard Henderson     }
99598cd9ca7SRichard Henderson     f = (orig & 4) / 4;
99698cd9ca7SRichard Henderson 
99798cd9ca7SRichard Henderson     return do_log_cond(c * 2 + f, res);
99898cd9ca7SRichard Henderson }
99998cd9ca7SRichard Henderson 
1000b2167459SRichard Henderson /* Similar, but for unit conditions.  */
1001b2167459SRichard Henderson 
1002eaa3783bSRichard Henderson static DisasCond do_unit_cond(unsigned cf, TCGv_reg res,
1003eaa3783bSRichard Henderson                               TCGv_reg in1, TCGv_reg in2)
1004b2167459SRichard Henderson {
1005b2167459SRichard Henderson     DisasCond cond;
1006eaa3783bSRichard Henderson     TCGv_reg tmp, cb = NULL;
1007b2167459SRichard Henderson 
1008b2167459SRichard Henderson     if (cf & 8) {
1009b2167459SRichard Henderson         /* Since we want to test lots of carry-out bits all at once, do not
1010b2167459SRichard Henderson          * do our normal thing and compute carry-in of bit B+1 since that
1011b2167459SRichard Henderson          * leaves us with carry bits spread across two words.
1012b2167459SRichard Henderson          */
1013b2167459SRichard Henderson         cb = tcg_temp_new();
1014b2167459SRichard Henderson         tmp = tcg_temp_new();
1015eaa3783bSRichard Henderson         tcg_gen_or_reg(cb, in1, in2);
1016eaa3783bSRichard Henderson         tcg_gen_and_reg(tmp, in1, in2);
1017eaa3783bSRichard Henderson         tcg_gen_andc_reg(cb, cb, res);
1018eaa3783bSRichard Henderson         tcg_gen_or_reg(cb, cb, tmp);
1019b2167459SRichard Henderson         tcg_temp_free(tmp);
1020b2167459SRichard Henderson     }
1021b2167459SRichard Henderson 
1022b2167459SRichard Henderson     switch (cf >> 1) {
1023b2167459SRichard Henderson     case 0: /* never / TR */
1024b2167459SRichard Henderson     case 1: /* undefined */
1025b2167459SRichard Henderson     case 5: /* undefined */
1026b2167459SRichard Henderson         cond = cond_make_f();
1027b2167459SRichard Henderson         break;
1028b2167459SRichard Henderson 
1029b2167459SRichard Henderson     case 2: /* SBZ / NBZ */
1030b2167459SRichard Henderson         /* See hasless(v,1) from
1031b2167459SRichard Henderson          * https://graphics.stanford.edu/~seander/bithacks.html#ZeroInWord
1032b2167459SRichard Henderson          */
1033b2167459SRichard Henderson         tmp = tcg_temp_new();
1034eaa3783bSRichard Henderson         tcg_gen_subi_reg(tmp, res, 0x01010101u);
1035eaa3783bSRichard Henderson         tcg_gen_andc_reg(tmp, tmp, res);
1036eaa3783bSRichard Henderson         tcg_gen_andi_reg(tmp, tmp, 0x80808080u);
1037b2167459SRichard Henderson         cond = cond_make_0(TCG_COND_NE, tmp);
1038b2167459SRichard Henderson         tcg_temp_free(tmp);
1039b2167459SRichard Henderson         break;
1040b2167459SRichard Henderson 
1041b2167459SRichard Henderson     case 3: /* SHZ / NHZ */
1042b2167459SRichard Henderson         tmp = tcg_temp_new();
1043eaa3783bSRichard Henderson         tcg_gen_subi_reg(tmp, res, 0x00010001u);
1044eaa3783bSRichard Henderson         tcg_gen_andc_reg(tmp, tmp, res);
1045eaa3783bSRichard Henderson         tcg_gen_andi_reg(tmp, tmp, 0x80008000u);
1046b2167459SRichard Henderson         cond = cond_make_0(TCG_COND_NE, tmp);
1047b2167459SRichard Henderson         tcg_temp_free(tmp);
1048b2167459SRichard Henderson         break;
1049b2167459SRichard Henderson 
1050b2167459SRichard Henderson     case 4: /* SDC / NDC */
1051eaa3783bSRichard Henderson         tcg_gen_andi_reg(cb, cb, 0x88888888u);
1052b2167459SRichard Henderson         cond = cond_make_0(TCG_COND_NE, cb);
1053b2167459SRichard Henderson         break;
1054b2167459SRichard Henderson 
1055b2167459SRichard Henderson     case 6: /* SBC / NBC */
1056eaa3783bSRichard Henderson         tcg_gen_andi_reg(cb, cb, 0x80808080u);
1057b2167459SRichard Henderson         cond = cond_make_0(TCG_COND_NE, cb);
1058b2167459SRichard Henderson         break;
1059b2167459SRichard Henderson 
1060b2167459SRichard Henderson     case 7: /* SHC / NHC */
1061eaa3783bSRichard Henderson         tcg_gen_andi_reg(cb, cb, 0x80008000u);
1062b2167459SRichard Henderson         cond = cond_make_0(TCG_COND_NE, cb);
1063b2167459SRichard Henderson         break;
1064b2167459SRichard Henderson 
1065b2167459SRichard Henderson     default:
1066b2167459SRichard Henderson         g_assert_not_reached();
1067b2167459SRichard Henderson     }
1068b2167459SRichard Henderson     if (cf & 8) {
1069b2167459SRichard Henderson         tcg_temp_free(cb);
1070b2167459SRichard Henderson     }
1071b2167459SRichard Henderson     if (cf & 1) {
1072b2167459SRichard Henderson         cond.c = tcg_invert_cond(cond.c);
1073b2167459SRichard Henderson     }
1074b2167459SRichard Henderson 
1075b2167459SRichard Henderson     return cond;
1076b2167459SRichard Henderson }
1077b2167459SRichard Henderson 
1078b2167459SRichard Henderson /* Compute signed overflow for addition.  */
1079eaa3783bSRichard Henderson static TCGv_reg do_add_sv(DisasContext *ctx, TCGv_reg res,
1080eaa3783bSRichard Henderson                           TCGv_reg in1, TCGv_reg in2)
1081b2167459SRichard Henderson {
1082eaa3783bSRichard Henderson     TCGv_reg sv = get_temp(ctx);
1083eaa3783bSRichard Henderson     TCGv_reg tmp = tcg_temp_new();
1084b2167459SRichard Henderson 
1085eaa3783bSRichard Henderson     tcg_gen_xor_reg(sv, res, in1);
1086eaa3783bSRichard Henderson     tcg_gen_xor_reg(tmp, in1, in2);
1087eaa3783bSRichard Henderson     tcg_gen_andc_reg(sv, sv, tmp);
1088b2167459SRichard Henderson     tcg_temp_free(tmp);
1089b2167459SRichard Henderson 
1090b2167459SRichard Henderson     return sv;
1091b2167459SRichard Henderson }
1092b2167459SRichard Henderson 
1093b2167459SRichard Henderson /* Compute signed overflow for subtraction.  */
1094eaa3783bSRichard Henderson static TCGv_reg do_sub_sv(DisasContext *ctx, TCGv_reg res,
1095eaa3783bSRichard Henderson                           TCGv_reg in1, TCGv_reg in2)
1096b2167459SRichard Henderson {
1097eaa3783bSRichard Henderson     TCGv_reg sv = get_temp(ctx);
1098eaa3783bSRichard Henderson     TCGv_reg tmp = tcg_temp_new();
1099b2167459SRichard Henderson 
1100eaa3783bSRichard Henderson     tcg_gen_xor_reg(sv, res, in1);
1101eaa3783bSRichard Henderson     tcg_gen_xor_reg(tmp, in1, in2);
1102eaa3783bSRichard Henderson     tcg_gen_and_reg(sv, sv, tmp);
1103b2167459SRichard Henderson     tcg_temp_free(tmp);
1104b2167459SRichard Henderson 
1105b2167459SRichard Henderson     return sv;
1106b2167459SRichard Henderson }
1107b2167459SRichard Henderson 
1108eaa3783bSRichard Henderson static DisasJumpType do_add(DisasContext *ctx, unsigned rt, TCGv_reg in1,
1109eaa3783bSRichard Henderson                             TCGv_reg in2, unsigned shift, bool is_l,
1110eaa3783bSRichard Henderson                             bool is_tsv, bool is_tc, bool is_c, unsigned cf)
1111b2167459SRichard Henderson {
1112eaa3783bSRichard Henderson     TCGv_reg dest, cb, cb_msb, sv, tmp;
1113b2167459SRichard Henderson     unsigned c = cf >> 1;
1114b2167459SRichard Henderson     DisasCond cond;
1115b2167459SRichard Henderson 
1116b2167459SRichard Henderson     dest = tcg_temp_new();
1117f764718dSRichard Henderson     cb = NULL;
1118f764718dSRichard Henderson     cb_msb = NULL;
1119b2167459SRichard Henderson 
1120b2167459SRichard Henderson     if (shift) {
1121b2167459SRichard Henderson         tmp = get_temp(ctx);
1122eaa3783bSRichard Henderson         tcg_gen_shli_reg(tmp, in1, shift);
1123b2167459SRichard Henderson         in1 = tmp;
1124b2167459SRichard Henderson     }
1125b2167459SRichard Henderson 
1126b2167459SRichard Henderson     if (!is_l || c == 4 || c == 5) {
1127eaa3783bSRichard Henderson         TCGv_reg zero = tcg_const_reg(0);
1128b2167459SRichard Henderson         cb_msb = get_temp(ctx);
1129eaa3783bSRichard Henderson         tcg_gen_add2_reg(dest, cb_msb, in1, zero, in2, zero);
1130b2167459SRichard Henderson         if (is_c) {
1131eaa3783bSRichard Henderson             tcg_gen_add2_reg(dest, cb_msb, dest, cb_msb, cpu_psw_cb_msb, zero);
1132b2167459SRichard Henderson         }
1133b2167459SRichard Henderson         tcg_temp_free(zero);
1134b2167459SRichard Henderson         if (!is_l) {
1135b2167459SRichard Henderson             cb = get_temp(ctx);
1136eaa3783bSRichard Henderson             tcg_gen_xor_reg(cb, in1, in2);
1137eaa3783bSRichard Henderson             tcg_gen_xor_reg(cb, cb, dest);
1138b2167459SRichard Henderson         }
1139b2167459SRichard Henderson     } else {
1140eaa3783bSRichard Henderson         tcg_gen_add_reg(dest, in1, in2);
1141b2167459SRichard Henderson         if (is_c) {
1142eaa3783bSRichard Henderson             tcg_gen_add_reg(dest, dest, cpu_psw_cb_msb);
1143b2167459SRichard Henderson         }
1144b2167459SRichard Henderson     }
1145b2167459SRichard Henderson 
1146b2167459SRichard Henderson     /* Compute signed overflow if required.  */
1147f764718dSRichard Henderson     sv = NULL;
1148b2167459SRichard Henderson     if (is_tsv || c == 6) {
1149b2167459SRichard Henderson         sv = do_add_sv(ctx, dest, in1, in2);
1150b2167459SRichard Henderson         if (is_tsv) {
1151b2167459SRichard Henderson             /* ??? Need to include overflow from shift.  */
1152b2167459SRichard Henderson             gen_helper_tsv(cpu_env, sv);
1153b2167459SRichard Henderson         }
1154b2167459SRichard Henderson     }
1155b2167459SRichard Henderson 
1156b2167459SRichard Henderson     /* Emit any conditional trap before any writeback.  */
1157b2167459SRichard Henderson     cond = do_cond(cf, dest, cb_msb, sv);
1158b2167459SRichard Henderson     if (is_tc) {
1159b2167459SRichard Henderson         cond_prep(&cond);
1160b2167459SRichard Henderson         tmp = tcg_temp_new();
1161eaa3783bSRichard Henderson         tcg_gen_setcond_reg(cond.c, tmp, cond.a0, cond.a1);
1162b2167459SRichard Henderson         gen_helper_tcond(cpu_env, tmp);
1163b2167459SRichard Henderson         tcg_temp_free(tmp);
1164b2167459SRichard Henderson     }
1165b2167459SRichard Henderson 
1166b2167459SRichard Henderson     /* Write back the result.  */
1167b2167459SRichard Henderson     if (!is_l) {
1168b2167459SRichard Henderson         save_or_nullify(ctx, cpu_psw_cb, cb);
1169b2167459SRichard Henderson         save_or_nullify(ctx, cpu_psw_cb_msb, cb_msb);
1170b2167459SRichard Henderson     }
1171b2167459SRichard Henderson     save_gpr(ctx, rt, dest);
1172b2167459SRichard Henderson     tcg_temp_free(dest);
1173b2167459SRichard Henderson 
1174b2167459SRichard Henderson     /* Install the new nullification.  */
1175b2167459SRichard Henderson     cond_free(&ctx->null_cond);
1176b2167459SRichard Henderson     ctx->null_cond = cond;
1177869051eaSRichard Henderson     return DISAS_NEXT;
1178b2167459SRichard Henderson }
1179b2167459SRichard Henderson 
1180eaa3783bSRichard Henderson static DisasJumpType do_sub(DisasContext *ctx, unsigned rt, TCGv_reg in1,
1181eaa3783bSRichard Henderson                             TCGv_reg in2, bool is_tsv, bool is_b,
1182eaa3783bSRichard Henderson                             bool is_tc, unsigned cf)
1183b2167459SRichard Henderson {
1184eaa3783bSRichard Henderson     TCGv_reg dest, sv, cb, cb_msb, zero, tmp;
1185b2167459SRichard Henderson     unsigned c = cf >> 1;
1186b2167459SRichard Henderson     DisasCond cond;
1187b2167459SRichard Henderson 
1188b2167459SRichard Henderson     dest = tcg_temp_new();
1189b2167459SRichard Henderson     cb = tcg_temp_new();
1190b2167459SRichard Henderson     cb_msb = tcg_temp_new();
1191b2167459SRichard Henderson 
1192eaa3783bSRichard Henderson     zero = tcg_const_reg(0);
1193b2167459SRichard Henderson     if (is_b) {
1194b2167459SRichard Henderson         /* DEST,C = IN1 + ~IN2 + C.  */
1195eaa3783bSRichard Henderson         tcg_gen_not_reg(cb, in2);
1196eaa3783bSRichard Henderson         tcg_gen_add2_reg(dest, cb_msb, in1, zero, cpu_psw_cb_msb, zero);
1197eaa3783bSRichard Henderson         tcg_gen_add2_reg(dest, cb_msb, dest, cb_msb, cb, zero);
1198eaa3783bSRichard Henderson         tcg_gen_xor_reg(cb, cb, in1);
1199eaa3783bSRichard Henderson         tcg_gen_xor_reg(cb, cb, dest);
1200b2167459SRichard Henderson     } else {
1201b2167459SRichard Henderson         /* DEST,C = IN1 + ~IN2 + 1.  We can produce the same result in fewer
1202b2167459SRichard Henderson            operations by seeding the high word with 1 and subtracting.  */
1203eaa3783bSRichard Henderson         tcg_gen_movi_reg(cb_msb, 1);
1204eaa3783bSRichard Henderson         tcg_gen_sub2_reg(dest, cb_msb, in1, cb_msb, in2, zero);
1205eaa3783bSRichard Henderson         tcg_gen_eqv_reg(cb, in1, in2);
1206eaa3783bSRichard Henderson         tcg_gen_xor_reg(cb, cb, dest);
1207b2167459SRichard Henderson     }
1208b2167459SRichard Henderson     tcg_temp_free(zero);
1209b2167459SRichard Henderson 
1210b2167459SRichard Henderson     /* Compute signed overflow if required.  */
1211f764718dSRichard Henderson     sv = NULL;
1212b2167459SRichard Henderson     if (is_tsv || c == 6) {
1213b2167459SRichard Henderson         sv = do_sub_sv(ctx, dest, in1, in2);
1214b2167459SRichard Henderson         if (is_tsv) {
1215b2167459SRichard Henderson             gen_helper_tsv(cpu_env, sv);
1216b2167459SRichard Henderson         }
1217b2167459SRichard Henderson     }
1218b2167459SRichard Henderson 
1219b2167459SRichard Henderson     /* Compute the condition.  We cannot use the special case for borrow.  */
1220b2167459SRichard Henderson     if (!is_b) {
1221b2167459SRichard Henderson         cond = do_sub_cond(cf, dest, in1, in2, sv);
1222b2167459SRichard Henderson     } else {
1223b2167459SRichard Henderson         cond = do_cond(cf, dest, cb_msb, sv);
1224b2167459SRichard Henderson     }
1225b2167459SRichard Henderson 
1226b2167459SRichard Henderson     /* Emit any conditional trap before any writeback.  */
1227b2167459SRichard Henderson     if (is_tc) {
1228b2167459SRichard Henderson         cond_prep(&cond);
1229b2167459SRichard Henderson         tmp = tcg_temp_new();
1230eaa3783bSRichard Henderson         tcg_gen_setcond_reg(cond.c, tmp, cond.a0, cond.a1);
1231b2167459SRichard Henderson         gen_helper_tcond(cpu_env, tmp);
1232b2167459SRichard Henderson         tcg_temp_free(tmp);
1233b2167459SRichard Henderson     }
1234b2167459SRichard Henderson 
1235b2167459SRichard Henderson     /* Write back the result.  */
1236b2167459SRichard Henderson     save_or_nullify(ctx, cpu_psw_cb, cb);
1237b2167459SRichard Henderson     save_or_nullify(ctx, cpu_psw_cb_msb, cb_msb);
1238b2167459SRichard Henderson     save_gpr(ctx, rt, dest);
1239b2167459SRichard Henderson     tcg_temp_free(dest);
1240b2167459SRichard Henderson 
1241b2167459SRichard Henderson     /* Install the new nullification.  */
1242b2167459SRichard Henderson     cond_free(&ctx->null_cond);
1243b2167459SRichard Henderson     ctx->null_cond = cond;
1244869051eaSRichard Henderson     return DISAS_NEXT;
1245b2167459SRichard Henderson }
1246b2167459SRichard Henderson 
1247eaa3783bSRichard Henderson static DisasJumpType do_cmpclr(DisasContext *ctx, unsigned rt, TCGv_reg in1,
1248eaa3783bSRichard Henderson                                TCGv_reg in2, unsigned cf)
1249b2167459SRichard Henderson {
1250eaa3783bSRichard Henderson     TCGv_reg dest, sv;
1251b2167459SRichard Henderson     DisasCond cond;
1252b2167459SRichard Henderson 
1253b2167459SRichard Henderson     dest = tcg_temp_new();
1254eaa3783bSRichard Henderson     tcg_gen_sub_reg(dest, in1, in2);
1255b2167459SRichard Henderson 
1256b2167459SRichard Henderson     /* Compute signed overflow if required.  */
1257f764718dSRichard Henderson     sv = NULL;
1258b2167459SRichard Henderson     if ((cf >> 1) == 6) {
1259b2167459SRichard Henderson         sv = do_sub_sv(ctx, dest, in1, in2);
1260b2167459SRichard Henderson     }
1261b2167459SRichard Henderson 
1262b2167459SRichard Henderson     /* Form the condition for the compare.  */
1263b2167459SRichard Henderson     cond = do_sub_cond(cf, dest, in1, in2, sv);
1264b2167459SRichard Henderson 
1265b2167459SRichard Henderson     /* Clear.  */
1266eaa3783bSRichard Henderson     tcg_gen_movi_reg(dest, 0);
1267b2167459SRichard Henderson     save_gpr(ctx, rt, dest);
1268b2167459SRichard Henderson     tcg_temp_free(dest);
1269b2167459SRichard Henderson 
1270b2167459SRichard Henderson     /* Install the new nullification.  */
1271b2167459SRichard Henderson     cond_free(&ctx->null_cond);
1272b2167459SRichard Henderson     ctx->null_cond = cond;
1273869051eaSRichard Henderson     return DISAS_NEXT;
1274b2167459SRichard Henderson }
1275b2167459SRichard Henderson 
1276eaa3783bSRichard Henderson static DisasJumpType do_log(DisasContext *ctx, unsigned rt, TCGv_reg in1,
1277eaa3783bSRichard Henderson                             TCGv_reg in2, unsigned cf,
1278eaa3783bSRichard Henderson                             void (*fn)(TCGv_reg, TCGv_reg, TCGv_reg))
1279b2167459SRichard Henderson {
1280eaa3783bSRichard Henderson     TCGv_reg dest = dest_gpr(ctx, rt);
1281b2167459SRichard Henderson 
1282b2167459SRichard Henderson     /* Perform the operation, and writeback.  */
1283b2167459SRichard Henderson     fn(dest, in1, in2);
1284b2167459SRichard Henderson     save_gpr(ctx, rt, dest);
1285b2167459SRichard Henderson 
1286b2167459SRichard Henderson     /* Install the new nullification.  */
1287b2167459SRichard Henderson     cond_free(&ctx->null_cond);
1288b2167459SRichard Henderson     if (cf) {
1289b2167459SRichard Henderson         ctx->null_cond = do_log_cond(cf, dest);
1290b2167459SRichard Henderson     }
1291869051eaSRichard Henderson     return DISAS_NEXT;
1292b2167459SRichard Henderson }
1293b2167459SRichard Henderson 
1294eaa3783bSRichard Henderson static DisasJumpType do_unit(DisasContext *ctx, unsigned rt, TCGv_reg in1,
1295eaa3783bSRichard Henderson                              TCGv_reg in2, unsigned cf, bool is_tc,
1296eaa3783bSRichard Henderson                              void (*fn)(TCGv_reg, TCGv_reg, TCGv_reg))
1297b2167459SRichard Henderson {
1298eaa3783bSRichard Henderson     TCGv_reg dest;
1299b2167459SRichard Henderson     DisasCond cond;
1300b2167459SRichard Henderson 
1301b2167459SRichard Henderson     if (cf == 0) {
1302b2167459SRichard Henderson         dest = dest_gpr(ctx, rt);
1303b2167459SRichard Henderson         fn(dest, in1, in2);
1304b2167459SRichard Henderson         save_gpr(ctx, rt, dest);
1305b2167459SRichard Henderson         cond_free(&ctx->null_cond);
1306b2167459SRichard Henderson     } else {
1307b2167459SRichard Henderson         dest = tcg_temp_new();
1308b2167459SRichard Henderson         fn(dest, in1, in2);
1309b2167459SRichard Henderson 
1310b2167459SRichard Henderson         cond = do_unit_cond(cf, dest, in1, in2);
1311b2167459SRichard Henderson 
1312b2167459SRichard Henderson         if (is_tc) {
1313eaa3783bSRichard Henderson             TCGv_reg tmp = tcg_temp_new();
1314b2167459SRichard Henderson             cond_prep(&cond);
1315eaa3783bSRichard Henderson             tcg_gen_setcond_reg(cond.c, tmp, cond.a0, cond.a1);
1316b2167459SRichard Henderson             gen_helper_tcond(cpu_env, tmp);
1317b2167459SRichard Henderson             tcg_temp_free(tmp);
1318b2167459SRichard Henderson         }
1319b2167459SRichard Henderson         save_gpr(ctx, rt, dest);
1320b2167459SRichard Henderson 
1321b2167459SRichard Henderson         cond_free(&ctx->null_cond);
1322b2167459SRichard Henderson         ctx->null_cond = cond;
1323b2167459SRichard Henderson     }
1324869051eaSRichard Henderson     return DISAS_NEXT;
1325b2167459SRichard Henderson }
1326b2167459SRichard Henderson 
132796d6407fSRichard Henderson /* Emit a memory load.  The modify parameter should be
132896d6407fSRichard Henderson  * < 0 for pre-modify,
132996d6407fSRichard Henderson  * > 0 for post-modify,
133096d6407fSRichard Henderson  * = 0 for no base register update.
133196d6407fSRichard Henderson  */
133296d6407fSRichard Henderson static void do_load_32(DisasContext *ctx, TCGv_i32 dest, unsigned rb,
1333eaa3783bSRichard Henderson                        unsigned rx, int scale, target_sreg disp,
133496d6407fSRichard Henderson                        int modify, TCGMemOp mop)
133596d6407fSRichard Henderson {
1336eaa3783bSRichard Henderson     TCGv_reg addr, base;
133796d6407fSRichard Henderson 
133896d6407fSRichard Henderson     /* Caller uses nullify_over/nullify_end.  */
133996d6407fSRichard Henderson     assert(ctx->null_cond.c == TCG_COND_NEVER);
134096d6407fSRichard Henderson 
134196d6407fSRichard Henderson     addr = tcg_temp_new();
134296d6407fSRichard Henderson     base = load_gpr(ctx, rb);
134396d6407fSRichard Henderson 
134496d6407fSRichard Henderson     /* Note that RX is mutually exclusive with DISP.  */
134596d6407fSRichard Henderson     if (rx) {
1346eaa3783bSRichard Henderson         tcg_gen_shli_reg(addr, cpu_gr[rx], scale);
1347eaa3783bSRichard Henderson         tcg_gen_add_reg(addr, addr, base);
134896d6407fSRichard Henderson     } else {
1349eaa3783bSRichard Henderson         tcg_gen_addi_reg(addr, base, disp);
135096d6407fSRichard Henderson     }
135196d6407fSRichard Henderson 
135296d6407fSRichard Henderson     if (modify == 0) {
13533d68ee7bSRichard Henderson         tcg_gen_qemu_ld_i32(dest, addr, ctx->mmu_idx, mop);
135496d6407fSRichard Henderson     } else {
135596d6407fSRichard Henderson         tcg_gen_qemu_ld_i32(dest, (modify < 0 ? addr : base),
13563d68ee7bSRichard Henderson                             ctx->mmu_idx, mop);
135796d6407fSRichard Henderson         save_gpr(ctx, rb, addr);
135896d6407fSRichard Henderson     }
135996d6407fSRichard Henderson     tcg_temp_free(addr);
136096d6407fSRichard Henderson }
136196d6407fSRichard Henderson 
136296d6407fSRichard Henderson static void do_load_64(DisasContext *ctx, TCGv_i64 dest, unsigned rb,
1363eaa3783bSRichard Henderson                        unsigned rx, int scale, target_sreg disp,
136496d6407fSRichard Henderson                        int modify, TCGMemOp mop)
136596d6407fSRichard Henderson {
1366eaa3783bSRichard Henderson     TCGv_reg addr, base;
136796d6407fSRichard Henderson 
136896d6407fSRichard Henderson     /* Caller uses nullify_over/nullify_end.  */
136996d6407fSRichard Henderson     assert(ctx->null_cond.c == TCG_COND_NEVER);
137096d6407fSRichard Henderson 
137196d6407fSRichard Henderson     addr = tcg_temp_new();
137296d6407fSRichard Henderson     base = load_gpr(ctx, rb);
137396d6407fSRichard Henderson 
137496d6407fSRichard Henderson     /* Note that RX is mutually exclusive with DISP.  */
137596d6407fSRichard Henderson     if (rx) {
1376eaa3783bSRichard Henderson         tcg_gen_shli_reg(addr, cpu_gr[rx], scale);
1377eaa3783bSRichard Henderson         tcg_gen_add_reg(addr, addr, base);
137896d6407fSRichard Henderson     } else {
1379eaa3783bSRichard Henderson         tcg_gen_addi_reg(addr, base, disp);
138096d6407fSRichard Henderson     }
138196d6407fSRichard Henderson 
138296d6407fSRichard Henderson     if (modify == 0) {
13833d68ee7bSRichard Henderson         tcg_gen_qemu_ld_i64(dest, addr, ctx->mmu_idx, mop);
138496d6407fSRichard Henderson     } else {
138596d6407fSRichard Henderson         tcg_gen_qemu_ld_i64(dest, (modify < 0 ? addr : base),
13863d68ee7bSRichard Henderson                             ctx->mmu_idx, mop);
138796d6407fSRichard Henderson         save_gpr(ctx, rb, addr);
138896d6407fSRichard Henderson     }
138996d6407fSRichard Henderson     tcg_temp_free(addr);
139096d6407fSRichard Henderson }
139196d6407fSRichard Henderson 
139296d6407fSRichard Henderson static void do_store_32(DisasContext *ctx, TCGv_i32 src, unsigned rb,
1393eaa3783bSRichard Henderson                         unsigned rx, int scale, target_sreg disp,
139496d6407fSRichard Henderson                         int modify, TCGMemOp mop)
139596d6407fSRichard Henderson {
1396eaa3783bSRichard Henderson     TCGv_reg addr, base;
139796d6407fSRichard Henderson 
139896d6407fSRichard Henderson     /* Caller uses nullify_over/nullify_end.  */
139996d6407fSRichard Henderson     assert(ctx->null_cond.c == TCG_COND_NEVER);
140096d6407fSRichard Henderson 
140196d6407fSRichard Henderson     addr = tcg_temp_new();
140296d6407fSRichard Henderson     base = load_gpr(ctx, rb);
140396d6407fSRichard Henderson 
140496d6407fSRichard Henderson     /* Note that RX is mutually exclusive with DISP.  */
140596d6407fSRichard Henderson     if (rx) {
1406eaa3783bSRichard Henderson         tcg_gen_shli_reg(addr, cpu_gr[rx], scale);
1407eaa3783bSRichard Henderson         tcg_gen_add_reg(addr, addr, base);
140896d6407fSRichard Henderson     } else {
1409eaa3783bSRichard Henderson         tcg_gen_addi_reg(addr, base, disp);
141096d6407fSRichard Henderson     }
141196d6407fSRichard Henderson 
14123d68ee7bSRichard Henderson     tcg_gen_qemu_st_i32(src, (modify <= 0 ? addr : base), ctx->mmu_idx, mop);
141396d6407fSRichard Henderson 
141496d6407fSRichard Henderson     if (modify != 0) {
141596d6407fSRichard Henderson         save_gpr(ctx, rb, addr);
141696d6407fSRichard Henderson     }
141796d6407fSRichard Henderson     tcg_temp_free(addr);
141896d6407fSRichard Henderson }
141996d6407fSRichard Henderson 
142096d6407fSRichard Henderson static void do_store_64(DisasContext *ctx, TCGv_i64 src, unsigned rb,
1421eaa3783bSRichard Henderson                         unsigned rx, int scale, target_sreg disp,
142296d6407fSRichard Henderson                         int modify, TCGMemOp mop)
142396d6407fSRichard Henderson {
1424eaa3783bSRichard Henderson     TCGv_reg addr, base;
142596d6407fSRichard Henderson 
142696d6407fSRichard Henderson     /* Caller uses nullify_over/nullify_end.  */
142796d6407fSRichard Henderson     assert(ctx->null_cond.c == TCG_COND_NEVER);
142896d6407fSRichard Henderson 
142996d6407fSRichard Henderson     addr = tcg_temp_new();
143096d6407fSRichard Henderson     base = load_gpr(ctx, rb);
143196d6407fSRichard Henderson 
143296d6407fSRichard Henderson     /* Note that RX is mutually exclusive with DISP.  */
143396d6407fSRichard Henderson     if (rx) {
1434eaa3783bSRichard Henderson         tcg_gen_shli_reg(addr, cpu_gr[rx], scale);
1435eaa3783bSRichard Henderson         tcg_gen_add_reg(addr, addr, base);
143696d6407fSRichard Henderson     } else {
1437eaa3783bSRichard Henderson         tcg_gen_addi_reg(addr, base, disp);
143896d6407fSRichard Henderson     }
143996d6407fSRichard Henderson 
14403d68ee7bSRichard Henderson     tcg_gen_qemu_st_i64(src, (modify <= 0 ? addr : base), ctx->mmu_idx, mop);
144196d6407fSRichard Henderson 
144296d6407fSRichard Henderson     if (modify != 0) {
144396d6407fSRichard Henderson         save_gpr(ctx, rb, addr);
144496d6407fSRichard Henderson     }
144596d6407fSRichard Henderson     tcg_temp_free(addr);
144696d6407fSRichard Henderson }
144796d6407fSRichard Henderson 
1448eaa3783bSRichard Henderson #if TARGET_REGISTER_BITS == 64
1449eaa3783bSRichard Henderson #define do_load_reg   do_load_64
1450eaa3783bSRichard Henderson #define do_store_reg  do_store_64
145196d6407fSRichard Henderson #else
1452eaa3783bSRichard Henderson #define do_load_reg   do_load_32
1453eaa3783bSRichard Henderson #define do_store_reg  do_store_32
145496d6407fSRichard Henderson #endif
145596d6407fSRichard Henderson 
1456869051eaSRichard Henderson static DisasJumpType do_load(DisasContext *ctx, unsigned rt, unsigned rb,
1457eaa3783bSRichard Henderson                              unsigned rx, int scale, target_sreg disp,
145896d6407fSRichard Henderson                              int modify, TCGMemOp mop)
145996d6407fSRichard Henderson {
1460eaa3783bSRichard Henderson     TCGv_reg dest;
146196d6407fSRichard Henderson 
146296d6407fSRichard Henderson     nullify_over(ctx);
146396d6407fSRichard Henderson 
146496d6407fSRichard Henderson     if (modify == 0) {
146596d6407fSRichard Henderson         /* No base register update.  */
146696d6407fSRichard Henderson         dest = dest_gpr(ctx, rt);
146796d6407fSRichard Henderson     } else {
146896d6407fSRichard Henderson         /* Make sure if RT == RB, we see the result of the load.  */
146996d6407fSRichard Henderson         dest = get_temp(ctx);
147096d6407fSRichard Henderson     }
1471eaa3783bSRichard Henderson     do_load_reg(ctx, dest, rb, rx, scale, disp, modify, mop);
147296d6407fSRichard Henderson     save_gpr(ctx, rt, dest);
147396d6407fSRichard Henderson 
1474869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
147596d6407fSRichard Henderson }
147696d6407fSRichard Henderson 
1477869051eaSRichard Henderson static DisasJumpType do_floadw(DisasContext *ctx, unsigned rt, unsigned rb,
1478eaa3783bSRichard Henderson                                unsigned rx, int scale, target_sreg disp,
147996d6407fSRichard Henderson                                int modify)
148096d6407fSRichard Henderson {
148196d6407fSRichard Henderson     TCGv_i32 tmp;
148296d6407fSRichard Henderson 
148396d6407fSRichard Henderson     nullify_over(ctx);
148496d6407fSRichard Henderson 
148596d6407fSRichard Henderson     tmp = tcg_temp_new_i32();
148696d6407fSRichard Henderson     do_load_32(ctx, tmp, rb, rx, scale, disp, modify, MO_TEUL);
148796d6407fSRichard Henderson     save_frw_i32(rt, tmp);
148896d6407fSRichard Henderson     tcg_temp_free_i32(tmp);
148996d6407fSRichard Henderson 
149096d6407fSRichard Henderson     if (rt == 0) {
149196d6407fSRichard Henderson         gen_helper_loaded_fr0(cpu_env);
149296d6407fSRichard Henderson     }
149396d6407fSRichard Henderson 
1494869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
149596d6407fSRichard Henderson }
149696d6407fSRichard Henderson 
1497869051eaSRichard Henderson static DisasJumpType do_floadd(DisasContext *ctx, unsigned rt, unsigned rb,
1498eaa3783bSRichard Henderson                                unsigned rx, int scale, target_sreg disp,
149996d6407fSRichard Henderson                                int modify)
150096d6407fSRichard Henderson {
150196d6407fSRichard Henderson     TCGv_i64 tmp;
150296d6407fSRichard Henderson 
150396d6407fSRichard Henderson     nullify_over(ctx);
150496d6407fSRichard Henderson 
150596d6407fSRichard Henderson     tmp = tcg_temp_new_i64();
150696d6407fSRichard Henderson     do_load_64(ctx, tmp, rb, rx, scale, disp, modify, MO_TEQ);
150796d6407fSRichard Henderson     save_frd(rt, tmp);
150896d6407fSRichard Henderson     tcg_temp_free_i64(tmp);
150996d6407fSRichard Henderson 
151096d6407fSRichard Henderson     if (rt == 0) {
151196d6407fSRichard Henderson         gen_helper_loaded_fr0(cpu_env);
151296d6407fSRichard Henderson     }
151396d6407fSRichard Henderson 
1514869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
151596d6407fSRichard Henderson }
151696d6407fSRichard Henderson 
1517869051eaSRichard Henderson static DisasJumpType do_store(DisasContext *ctx, unsigned rt, unsigned rb,
1518eaa3783bSRichard Henderson                               target_sreg disp, int modify, TCGMemOp mop)
151996d6407fSRichard Henderson {
152096d6407fSRichard Henderson     nullify_over(ctx);
1521eaa3783bSRichard Henderson     do_store_reg(ctx, load_gpr(ctx, rt), rb, 0, 0, disp, modify, mop);
1522869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
152396d6407fSRichard Henderson }
152496d6407fSRichard Henderson 
1525869051eaSRichard Henderson static DisasJumpType do_fstorew(DisasContext *ctx, unsigned rt, unsigned rb,
1526eaa3783bSRichard Henderson                                 unsigned rx, int scale, target_sreg disp,
152796d6407fSRichard Henderson                                 int modify)
152896d6407fSRichard Henderson {
152996d6407fSRichard Henderson     TCGv_i32 tmp;
153096d6407fSRichard Henderson 
153196d6407fSRichard Henderson     nullify_over(ctx);
153296d6407fSRichard Henderson 
153396d6407fSRichard Henderson     tmp = load_frw_i32(rt);
153496d6407fSRichard Henderson     do_store_32(ctx, tmp, rb, rx, scale, disp, modify, MO_TEUL);
153596d6407fSRichard Henderson     tcg_temp_free_i32(tmp);
153696d6407fSRichard Henderson 
1537869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
153896d6407fSRichard Henderson }
153996d6407fSRichard Henderson 
1540869051eaSRichard Henderson static DisasJumpType do_fstored(DisasContext *ctx, unsigned rt, unsigned rb,
1541eaa3783bSRichard Henderson                                 unsigned rx, int scale, target_sreg disp,
154296d6407fSRichard Henderson                                 int modify)
154396d6407fSRichard Henderson {
154496d6407fSRichard Henderson     TCGv_i64 tmp;
154596d6407fSRichard Henderson 
154696d6407fSRichard Henderson     nullify_over(ctx);
154796d6407fSRichard Henderson 
154896d6407fSRichard Henderson     tmp = load_frd(rt);
154996d6407fSRichard Henderson     do_store_64(ctx, tmp, rb, rx, scale, disp, modify, MO_TEQ);
155096d6407fSRichard Henderson     tcg_temp_free_i64(tmp);
155196d6407fSRichard Henderson 
1552869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
155396d6407fSRichard Henderson }
155496d6407fSRichard Henderson 
1555869051eaSRichard Henderson static DisasJumpType do_fop_wew(DisasContext *ctx, unsigned rt, unsigned ra,
1556ebe9383cSRichard Henderson                                 void (*func)(TCGv_i32, TCGv_env, TCGv_i32))
1557ebe9383cSRichard Henderson {
1558ebe9383cSRichard Henderson     TCGv_i32 tmp;
1559ebe9383cSRichard Henderson 
1560ebe9383cSRichard Henderson     nullify_over(ctx);
1561ebe9383cSRichard Henderson     tmp = load_frw0_i32(ra);
1562ebe9383cSRichard Henderson 
1563ebe9383cSRichard Henderson     func(tmp, cpu_env, tmp);
1564ebe9383cSRichard Henderson 
1565ebe9383cSRichard Henderson     save_frw_i32(rt, tmp);
1566ebe9383cSRichard Henderson     tcg_temp_free_i32(tmp);
1567869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
1568ebe9383cSRichard Henderson }
1569ebe9383cSRichard Henderson 
1570869051eaSRichard Henderson static DisasJumpType do_fop_wed(DisasContext *ctx, unsigned rt, unsigned ra,
1571ebe9383cSRichard Henderson                                 void (*func)(TCGv_i32, TCGv_env, TCGv_i64))
1572ebe9383cSRichard Henderson {
1573ebe9383cSRichard Henderson     TCGv_i32 dst;
1574ebe9383cSRichard Henderson     TCGv_i64 src;
1575ebe9383cSRichard Henderson 
1576ebe9383cSRichard Henderson     nullify_over(ctx);
1577ebe9383cSRichard Henderson     src = load_frd(ra);
1578ebe9383cSRichard Henderson     dst = tcg_temp_new_i32();
1579ebe9383cSRichard Henderson 
1580ebe9383cSRichard Henderson     func(dst, cpu_env, src);
1581ebe9383cSRichard Henderson 
1582ebe9383cSRichard Henderson     tcg_temp_free_i64(src);
1583ebe9383cSRichard Henderson     save_frw_i32(rt, dst);
1584ebe9383cSRichard Henderson     tcg_temp_free_i32(dst);
1585869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
1586ebe9383cSRichard Henderson }
1587ebe9383cSRichard Henderson 
1588869051eaSRichard Henderson static DisasJumpType do_fop_ded(DisasContext *ctx, unsigned rt, unsigned ra,
1589ebe9383cSRichard Henderson                                 void (*func)(TCGv_i64, TCGv_env, TCGv_i64))
1590ebe9383cSRichard Henderson {
1591ebe9383cSRichard Henderson     TCGv_i64 tmp;
1592ebe9383cSRichard Henderson 
1593ebe9383cSRichard Henderson     nullify_over(ctx);
1594ebe9383cSRichard Henderson     tmp = load_frd0(ra);
1595ebe9383cSRichard Henderson 
1596ebe9383cSRichard Henderson     func(tmp, cpu_env, tmp);
1597ebe9383cSRichard Henderson 
1598ebe9383cSRichard Henderson     save_frd(rt, tmp);
1599ebe9383cSRichard Henderson     tcg_temp_free_i64(tmp);
1600869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
1601ebe9383cSRichard Henderson }
1602ebe9383cSRichard Henderson 
1603869051eaSRichard Henderson static DisasJumpType do_fop_dew(DisasContext *ctx, unsigned rt, unsigned ra,
1604ebe9383cSRichard Henderson                                 void (*func)(TCGv_i64, TCGv_env, TCGv_i32))
1605ebe9383cSRichard Henderson {
1606ebe9383cSRichard Henderson     TCGv_i32 src;
1607ebe9383cSRichard Henderson     TCGv_i64 dst;
1608ebe9383cSRichard Henderson 
1609ebe9383cSRichard Henderson     nullify_over(ctx);
1610ebe9383cSRichard Henderson     src = load_frw0_i32(ra);
1611ebe9383cSRichard Henderson     dst = tcg_temp_new_i64();
1612ebe9383cSRichard Henderson 
1613ebe9383cSRichard Henderson     func(dst, cpu_env, src);
1614ebe9383cSRichard Henderson 
1615ebe9383cSRichard Henderson     tcg_temp_free_i32(src);
1616ebe9383cSRichard Henderson     save_frd(rt, dst);
1617ebe9383cSRichard Henderson     tcg_temp_free_i64(dst);
1618869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
1619ebe9383cSRichard Henderson }
1620ebe9383cSRichard Henderson 
1621869051eaSRichard Henderson static DisasJumpType do_fop_weww(DisasContext *ctx, unsigned rt,
1622ebe9383cSRichard Henderson                                  unsigned ra, unsigned rb,
1623ebe9383cSRichard Henderson                                  void (*func)(TCGv_i32, TCGv_env,
1624ebe9383cSRichard Henderson                                               TCGv_i32, TCGv_i32))
1625ebe9383cSRichard Henderson {
1626ebe9383cSRichard Henderson     TCGv_i32 a, b;
1627ebe9383cSRichard Henderson 
1628ebe9383cSRichard Henderson     nullify_over(ctx);
1629ebe9383cSRichard Henderson     a = load_frw0_i32(ra);
1630ebe9383cSRichard Henderson     b = load_frw0_i32(rb);
1631ebe9383cSRichard Henderson 
1632ebe9383cSRichard Henderson     func(a, cpu_env, a, b);
1633ebe9383cSRichard Henderson 
1634ebe9383cSRichard Henderson     tcg_temp_free_i32(b);
1635ebe9383cSRichard Henderson     save_frw_i32(rt, a);
1636ebe9383cSRichard Henderson     tcg_temp_free_i32(a);
1637869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
1638ebe9383cSRichard Henderson }
1639ebe9383cSRichard Henderson 
1640869051eaSRichard Henderson static DisasJumpType do_fop_dedd(DisasContext *ctx, unsigned rt,
1641ebe9383cSRichard Henderson                                  unsigned ra, unsigned rb,
1642ebe9383cSRichard Henderson                                  void (*func)(TCGv_i64, TCGv_env,
1643ebe9383cSRichard Henderson                                               TCGv_i64, TCGv_i64))
1644ebe9383cSRichard Henderson {
1645ebe9383cSRichard Henderson     TCGv_i64 a, b;
1646ebe9383cSRichard Henderson 
1647ebe9383cSRichard Henderson     nullify_over(ctx);
1648ebe9383cSRichard Henderson     a = load_frd0(ra);
1649ebe9383cSRichard Henderson     b = load_frd0(rb);
1650ebe9383cSRichard Henderson 
1651ebe9383cSRichard Henderson     func(a, cpu_env, a, b);
1652ebe9383cSRichard Henderson 
1653ebe9383cSRichard Henderson     tcg_temp_free_i64(b);
1654ebe9383cSRichard Henderson     save_frd(rt, a);
1655ebe9383cSRichard Henderson     tcg_temp_free_i64(a);
1656869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
1657ebe9383cSRichard Henderson }
1658ebe9383cSRichard Henderson 
165998cd9ca7SRichard Henderson /* Emit an unconditional branch to a direct target, which may or may not
166098cd9ca7SRichard Henderson    have already had nullification handled.  */
1661eaa3783bSRichard Henderson static DisasJumpType do_dbranch(DisasContext *ctx, target_ureg dest,
166298cd9ca7SRichard Henderson                                 unsigned link, bool is_n)
166398cd9ca7SRichard Henderson {
166498cd9ca7SRichard Henderson     if (ctx->null_cond.c == TCG_COND_NEVER && ctx->null_lab == NULL) {
166598cd9ca7SRichard Henderson         if (link != 0) {
166698cd9ca7SRichard Henderson             copy_iaoq_entry(cpu_gr[link], ctx->iaoq_n, ctx->iaoq_n_var);
166798cd9ca7SRichard Henderson         }
166898cd9ca7SRichard Henderson         ctx->iaoq_n = dest;
166998cd9ca7SRichard Henderson         if (is_n) {
167098cd9ca7SRichard Henderson             ctx->null_cond.c = TCG_COND_ALWAYS;
167198cd9ca7SRichard Henderson         }
1672869051eaSRichard Henderson         return DISAS_NEXT;
167398cd9ca7SRichard Henderson     } else {
167498cd9ca7SRichard Henderson         nullify_over(ctx);
167598cd9ca7SRichard Henderson 
167698cd9ca7SRichard Henderson         if (link != 0) {
167798cd9ca7SRichard Henderson             copy_iaoq_entry(cpu_gr[link], ctx->iaoq_n, ctx->iaoq_n_var);
167898cd9ca7SRichard Henderson         }
167998cd9ca7SRichard Henderson 
168098cd9ca7SRichard Henderson         if (is_n && use_nullify_skip(ctx)) {
168198cd9ca7SRichard Henderson             nullify_set(ctx, 0);
168298cd9ca7SRichard Henderson             gen_goto_tb(ctx, 0, dest, dest + 4);
168398cd9ca7SRichard Henderson         } else {
168498cd9ca7SRichard Henderson             nullify_set(ctx, is_n);
168598cd9ca7SRichard Henderson             gen_goto_tb(ctx, 0, ctx->iaoq_b, dest);
168698cd9ca7SRichard Henderson         }
168798cd9ca7SRichard Henderson 
1688869051eaSRichard Henderson         nullify_end(ctx, DISAS_NEXT);
168998cd9ca7SRichard Henderson 
169098cd9ca7SRichard Henderson         nullify_set(ctx, 0);
169198cd9ca7SRichard Henderson         gen_goto_tb(ctx, 1, ctx->iaoq_b, ctx->iaoq_n);
1692869051eaSRichard Henderson         return DISAS_NORETURN;
169398cd9ca7SRichard Henderson     }
169498cd9ca7SRichard Henderson }
169598cd9ca7SRichard Henderson 
169698cd9ca7SRichard Henderson /* Emit a conditional branch to a direct target.  If the branch itself
169798cd9ca7SRichard Henderson    is nullified, we should have already used nullify_over.  */
1698eaa3783bSRichard Henderson static DisasJumpType do_cbranch(DisasContext *ctx, target_sreg disp, bool is_n,
169998cd9ca7SRichard Henderson                                 DisasCond *cond)
170098cd9ca7SRichard Henderson {
1701eaa3783bSRichard Henderson     target_ureg dest = iaoq_dest(ctx, disp);
170298cd9ca7SRichard Henderson     TCGLabel *taken = NULL;
170398cd9ca7SRichard Henderson     TCGCond c = cond->c;
170498cd9ca7SRichard Henderson     bool n;
170598cd9ca7SRichard Henderson 
170698cd9ca7SRichard Henderson     assert(ctx->null_cond.c == TCG_COND_NEVER);
170798cd9ca7SRichard Henderson 
170898cd9ca7SRichard Henderson     /* Handle TRUE and NEVER as direct branches.  */
170998cd9ca7SRichard Henderson     if (c == TCG_COND_ALWAYS) {
171098cd9ca7SRichard Henderson         return do_dbranch(ctx, dest, 0, is_n && disp >= 0);
171198cd9ca7SRichard Henderson     }
171298cd9ca7SRichard Henderson     if (c == TCG_COND_NEVER) {
171398cd9ca7SRichard Henderson         return do_dbranch(ctx, ctx->iaoq_n, 0, is_n && disp < 0);
171498cd9ca7SRichard Henderson     }
171598cd9ca7SRichard Henderson 
171698cd9ca7SRichard Henderson     taken = gen_new_label();
171798cd9ca7SRichard Henderson     cond_prep(cond);
1718eaa3783bSRichard Henderson     tcg_gen_brcond_reg(c, cond->a0, cond->a1, taken);
171998cd9ca7SRichard Henderson     cond_free(cond);
172098cd9ca7SRichard Henderson 
172198cd9ca7SRichard Henderson     /* Not taken: Condition not satisfied; nullify on backward branches. */
172298cd9ca7SRichard Henderson     n = is_n && disp < 0;
172398cd9ca7SRichard Henderson     if (n && use_nullify_skip(ctx)) {
172498cd9ca7SRichard Henderson         nullify_set(ctx, 0);
1725a881c8e7SRichard Henderson         gen_goto_tb(ctx, 0, ctx->iaoq_n, ctx->iaoq_n + 4);
172698cd9ca7SRichard Henderson     } else {
172798cd9ca7SRichard Henderson         if (!n && ctx->null_lab) {
172898cd9ca7SRichard Henderson             gen_set_label(ctx->null_lab);
172998cd9ca7SRichard Henderson             ctx->null_lab = NULL;
173098cd9ca7SRichard Henderson         }
173198cd9ca7SRichard Henderson         nullify_set(ctx, n);
1732a881c8e7SRichard Henderson         gen_goto_tb(ctx, 0, ctx->iaoq_b, ctx->iaoq_n);
173398cd9ca7SRichard Henderson     }
173498cd9ca7SRichard Henderson 
173598cd9ca7SRichard Henderson     gen_set_label(taken);
173698cd9ca7SRichard Henderson 
173798cd9ca7SRichard Henderson     /* Taken: Condition satisfied; nullify on forward branches.  */
173898cd9ca7SRichard Henderson     n = is_n && disp >= 0;
173998cd9ca7SRichard Henderson     if (n && use_nullify_skip(ctx)) {
174098cd9ca7SRichard Henderson         nullify_set(ctx, 0);
1741a881c8e7SRichard Henderson         gen_goto_tb(ctx, 1, dest, dest + 4);
174298cd9ca7SRichard Henderson     } else {
174398cd9ca7SRichard Henderson         nullify_set(ctx, n);
1744a881c8e7SRichard Henderson         gen_goto_tb(ctx, 1, ctx->iaoq_b, dest);
174598cd9ca7SRichard Henderson     }
174698cd9ca7SRichard Henderson 
174798cd9ca7SRichard Henderson     /* Not taken: the branch itself was nullified.  */
174898cd9ca7SRichard Henderson     if (ctx->null_lab) {
174998cd9ca7SRichard Henderson         gen_set_label(ctx->null_lab);
175098cd9ca7SRichard Henderson         ctx->null_lab = NULL;
1751869051eaSRichard Henderson         return DISAS_IAQ_N_STALE;
175298cd9ca7SRichard Henderson     } else {
1753869051eaSRichard Henderson         return DISAS_NORETURN;
175498cd9ca7SRichard Henderson     }
175598cd9ca7SRichard Henderson }
175698cd9ca7SRichard Henderson 
175798cd9ca7SRichard Henderson /* Emit an unconditional branch to an indirect target.  This handles
175898cd9ca7SRichard Henderson    nullification of the branch itself.  */
1759eaa3783bSRichard Henderson static DisasJumpType do_ibranch(DisasContext *ctx, TCGv_reg dest,
176098cd9ca7SRichard Henderson                                 unsigned link, bool is_n)
176198cd9ca7SRichard Henderson {
1762eaa3783bSRichard Henderson     TCGv_reg a0, a1, next, tmp;
176398cd9ca7SRichard Henderson     TCGCond c;
176498cd9ca7SRichard Henderson 
176598cd9ca7SRichard Henderson     assert(ctx->null_lab == NULL);
176698cd9ca7SRichard Henderson 
176798cd9ca7SRichard Henderson     if (ctx->null_cond.c == TCG_COND_NEVER) {
176898cd9ca7SRichard Henderson         if (link != 0) {
176998cd9ca7SRichard Henderson             copy_iaoq_entry(cpu_gr[link], ctx->iaoq_n, ctx->iaoq_n_var);
177098cd9ca7SRichard Henderson         }
177198cd9ca7SRichard Henderson         next = get_temp(ctx);
1772eaa3783bSRichard Henderson         tcg_gen_mov_reg(next, dest);
177398cd9ca7SRichard Henderson         ctx->iaoq_n = -1;
177498cd9ca7SRichard Henderson         ctx->iaoq_n_var = next;
177598cd9ca7SRichard Henderson         if (is_n) {
177698cd9ca7SRichard Henderson             ctx->null_cond.c = TCG_COND_ALWAYS;
177798cd9ca7SRichard Henderson         }
177898cd9ca7SRichard Henderson     } else if (is_n && use_nullify_skip(ctx)) {
177998cd9ca7SRichard Henderson         /* The (conditional) branch, B, nullifies the next insn, N,
178098cd9ca7SRichard Henderson            and we're allowed to skip execution N (no single-step or
17814137cb83SRichard Henderson            tracepoint in effect).  Since the goto_ptr that we must use
178298cd9ca7SRichard Henderson            for the indirect branch consumes no special resources, we
178398cd9ca7SRichard Henderson            can (conditionally) skip B and continue execution.  */
178498cd9ca7SRichard Henderson         /* The use_nullify_skip test implies we have a known control path.  */
178598cd9ca7SRichard Henderson         tcg_debug_assert(ctx->iaoq_b != -1);
178698cd9ca7SRichard Henderson         tcg_debug_assert(ctx->iaoq_n != -1);
178798cd9ca7SRichard Henderson 
178898cd9ca7SRichard Henderson         /* We do have to handle the non-local temporary, DEST, before
178998cd9ca7SRichard Henderson            branching.  Since IOAQ_F is not really live at this point, we
179098cd9ca7SRichard Henderson            can simply store DEST optimistically.  Similarly with IAOQ_B.  */
1791eaa3783bSRichard Henderson         tcg_gen_mov_reg(cpu_iaoq_f, dest);
1792eaa3783bSRichard Henderson         tcg_gen_addi_reg(cpu_iaoq_b, dest, 4);
179398cd9ca7SRichard Henderson 
179498cd9ca7SRichard Henderson         nullify_over(ctx);
179598cd9ca7SRichard Henderson         if (link != 0) {
1796eaa3783bSRichard Henderson             tcg_gen_movi_reg(cpu_gr[link], ctx->iaoq_n);
179798cd9ca7SRichard Henderson         }
17987f11636dSEmilio G. Cota         tcg_gen_lookup_and_goto_ptr();
1799869051eaSRichard Henderson         return nullify_end(ctx, DISAS_NEXT);
180098cd9ca7SRichard Henderson     } else {
180198cd9ca7SRichard Henderson         cond_prep(&ctx->null_cond);
180298cd9ca7SRichard Henderson         c = ctx->null_cond.c;
180398cd9ca7SRichard Henderson         a0 = ctx->null_cond.a0;
180498cd9ca7SRichard Henderson         a1 = ctx->null_cond.a1;
180598cd9ca7SRichard Henderson 
180698cd9ca7SRichard Henderson         tmp = tcg_temp_new();
180798cd9ca7SRichard Henderson         next = get_temp(ctx);
180898cd9ca7SRichard Henderson 
180998cd9ca7SRichard Henderson         copy_iaoq_entry(tmp, ctx->iaoq_n, ctx->iaoq_n_var);
1810eaa3783bSRichard Henderson         tcg_gen_movcond_reg(c, next, a0, a1, tmp, dest);
181198cd9ca7SRichard Henderson         ctx->iaoq_n = -1;
181298cd9ca7SRichard Henderson         ctx->iaoq_n_var = next;
181398cd9ca7SRichard Henderson 
181498cd9ca7SRichard Henderson         if (link != 0) {
1815eaa3783bSRichard Henderson             tcg_gen_movcond_reg(c, cpu_gr[link], a0, a1, cpu_gr[link], tmp);
181698cd9ca7SRichard Henderson         }
181798cd9ca7SRichard Henderson 
181898cd9ca7SRichard Henderson         if (is_n) {
181998cd9ca7SRichard Henderson             /* The branch nullifies the next insn, which means the state of N
182098cd9ca7SRichard Henderson                after the branch is the inverse of the state of N that applied
182198cd9ca7SRichard Henderson                to the branch.  */
1822eaa3783bSRichard Henderson             tcg_gen_setcond_reg(tcg_invert_cond(c), cpu_psw_n, a0, a1);
182398cd9ca7SRichard Henderson             cond_free(&ctx->null_cond);
182498cd9ca7SRichard Henderson             ctx->null_cond = cond_make_n();
182598cd9ca7SRichard Henderson             ctx->psw_n_nonzero = true;
182698cd9ca7SRichard Henderson         } else {
182798cd9ca7SRichard Henderson             cond_free(&ctx->null_cond);
182898cd9ca7SRichard Henderson         }
182998cd9ca7SRichard Henderson     }
183098cd9ca7SRichard Henderson 
1831869051eaSRichard Henderson     return DISAS_NEXT;
183298cd9ca7SRichard Henderson }
183398cd9ca7SRichard Henderson 
1834ba1d0b44SRichard Henderson #ifdef CONFIG_USER_ONLY
18357ad439dfSRichard Henderson /* On Linux, page zero is normally marked execute only + gateway.
18367ad439dfSRichard Henderson    Therefore normal read or write is supposed to fail, but specific
18377ad439dfSRichard Henderson    offsets have kernel code mapped to raise permissions to implement
18387ad439dfSRichard Henderson    system calls.  Handling this via an explicit check here, rather
18397ad439dfSRichard Henderson    in than the "be disp(sr2,r0)" instruction that probably sent us
18407ad439dfSRichard Henderson    here, is the easiest way to handle the branch delay slot on the
18417ad439dfSRichard Henderson    aforementioned BE.  */
1842869051eaSRichard Henderson static DisasJumpType do_page_zero(DisasContext *ctx)
18437ad439dfSRichard Henderson {
18447ad439dfSRichard Henderson     /* If by some means we get here with PSW[N]=1, that implies that
18457ad439dfSRichard Henderson        the B,GATE instruction would be skipped, and we'd fault on the
18467ad439dfSRichard Henderson        next insn within the privilaged page.  */
18477ad439dfSRichard Henderson     switch (ctx->null_cond.c) {
18487ad439dfSRichard Henderson     case TCG_COND_NEVER:
18497ad439dfSRichard Henderson         break;
18507ad439dfSRichard Henderson     case TCG_COND_ALWAYS:
1851eaa3783bSRichard Henderson         tcg_gen_movi_reg(cpu_psw_n, 0);
18527ad439dfSRichard Henderson         goto do_sigill;
18537ad439dfSRichard Henderson     default:
18547ad439dfSRichard Henderson         /* Since this is always the first (and only) insn within the
18557ad439dfSRichard Henderson            TB, we should know the state of PSW[N] from TB->FLAGS.  */
18567ad439dfSRichard Henderson         g_assert_not_reached();
18577ad439dfSRichard Henderson     }
18587ad439dfSRichard Henderson 
18597ad439dfSRichard Henderson     /* Check that we didn't arrive here via some means that allowed
18607ad439dfSRichard Henderson        non-sequential instruction execution.  Normally the PSW[B] bit
18617ad439dfSRichard Henderson        detects this by disallowing the B,GATE instruction to execute
18627ad439dfSRichard Henderson        under such conditions.  */
18637ad439dfSRichard Henderson     if (ctx->iaoq_b != ctx->iaoq_f + 4) {
18647ad439dfSRichard Henderson         goto do_sigill;
18657ad439dfSRichard Henderson     }
18667ad439dfSRichard Henderson 
18677ad439dfSRichard Henderson     switch (ctx->iaoq_f) {
18687ad439dfSRichard Henderson     case 0x00: /* Null pointer call */
18692986721dSRichard Henderson         gen_excp_1(EXCP_IMP);
1870869051eaSRichard Henderson         return DISAS_NORETURN;
18717ad439dfSRichard Henderson 
18727ad439dfSRichard Henderson     case 0xb0: /* LWS */
18737ad439dfSRichard Henderson         gen_excp_1(EXCP_SYSCALL_LWS);
1874869051eaSRichard Henderson         return DISAS_NORETURN;
18757ad439dfSRichard Henderson 
18767ad439dfSRichard Henderson     case 0xe0: /* SET_THREAD_POINTER */
187735136a77SRichard Henderson         tcg_gen_st_reg(cpu_gr[26], cpu_env, offsetof(CPUHPPAState, cr[27]));
1878eaa3783bSRichard Henderson         tcg_gen_mov_reg(cpu_iaoq_f, cpu_gr[31]);
1879eaa3783bSRichard Henderson         tcg_gen_addi_reg(cpu_iaoq_b, cpu_iaoq_f, 4);
1880869051eaSRichard Henderson         return DISAS_IAQ_N_UPDATED;
18817ad439dfSRichard Henderson 
18827ad439dfSRichard Henderson     case 0x100: /* SYSCALL */
18837ad439dfSRichard Henderson         gen_excp_1(EXCP_SYSCALL);
1884869051eaSRichard Henderson         return DISAS_NORETURN;
18857ad439dfSRichard Henderson 
18867ad439dfSRichard Henderson     default:
18877ad439dfSRichard Henderson     do_sigill:
18882986721dSRichard Henderson         gen_excp_1(EXCP_ILL);
1889869051eaSRichard Henderson         return DISAS_NORETURN;
18907ad439dfSRichard Henderson     }
18917ad439dfSRichard Henderson }
1892ba1d0b44SRichard Henderson #endif
18937ad439dfSRichard Henderson 
1894869051eaSRichard Henderson static DisasJumpType trans_nop(DisasContext *ctx, uint32_t insn,
1895b2167459SRichard Henderson                                const DisasInsn *di)
1896b2167459SRichard Henderson {
1897b2167459SRichard Henderson     cond_free(&ctx->null_cond);
1898869051eaSRichard Henderson     return DISAS_NEXT;
1899b2167459SRichard Henderson }
1900b2167459SRichard Henderson 
1901869051eaSRichard Henderson static DisasJumpType trans_break(DisasContext *ctx, uint32_t insn,
190298a9cb79SRichard Henderson                                  const DisasInsn *di)
190398a9cb79SRichard Henderson {
190498a9cb79SRichard Henderson     nullify_over(ctx);
1905*1a19da0dSRichard Henderson     return nullify_end(ctx, gen_excp_iir(ctx, EXCP_BREAK));
190698a9cb79SRichard Henderson }
190798a9cb79SRichard Henderson 
1908869051eaSRichard Henderson static DisasJumpType trans_sync(DisasContext *ctx, uint32_t insn,
190998a9cb79SRichard Henderson                                 const DisasInsn *di)
191098a9cb79SRichard Henderson {
191198a9cb79SRichard Henderson     /* No point in nullifying the memory barrier.  */
191298a9cb79SRichard Henderson     tcg_gen_mb(TCG_BAR_SC | TCG_MO_ALL);
191398a9cb79SRichard Henderson 
191498a9cb79SRichard Henderson     cond_free(&ctx->null_cond);
1915869051eaSRichard Henderson     return DISAS_NEXT;
191698a9cb79SRichard Henderson }
191798a9cb79SRichard Henderson 
1918869051eaSRichard Henderson static DisasJumpType trans_mfia(DisasContext *ctx, uint32_t insn,
191998a9cb79SRichard Henderson                                 const DisasInsn *di)
192098a9cb79SRichard Henderson {
192198a9cb79SRichard Henderson     unsigned rt = extract32(insn, 0, 5);
1922eaa3783bSRichard Henderson     TCGv_reg tmp = dest_gpr(ctx, rt);
1923eaa3783bSRichard Henderson     tcg_gen_movi_reg(tmp, ctx->iaoq_f);
192498a9cb79SRichard Henderson     save_gpr(ctx, rt, tmp);
192598a9cb79SRichard Henderson 
192698a9cb79SRichard Henderson     cond_free(&ctx->null_cond);
1927869051eaSRichard Henderson     return DISAS_NEXT;
192898a9cb79SRichard Henderson }
192998a9cb79SRichard Henderson 
1930869051eaSRichard Henderson static DisasJumpType trans_mfsp(DisasContext *ctx, uint32_t insn,
193198a9cb79SRichard Henderson                                 const DisasInsn *di)
193298a9cb79SRichard Henderson {
193398a9cb79SRichard Henderson     unsigned rt = extract32(insn, 0, 5);
193433423472SRichard Henderson     unsigned rs = assemble_sr3(insn);
193533423472SRichard Henderson     TCGv_i64 t0 = tcg_temp_new_i64();
193633423472SRichard Henderson     TCGv_reg t1 = tcg_temp_new();
193798a9cb79SRichard Henderson 
193833423472SRichard Henderson     load_spr(ctx, t0, rs);
193933423472SRichard Henderson     tcg_gen_shri_i64(t0, t0, 32);
194033423472SRichard Henderson     tcg_gen_trunc_i64_reg(t1, t0);
194133423472SRichard Henderson 
194233423472SRichard Henderson     save_gpr(ctx, rt, t1);
194333423472SRichard Henderson     tcg_temp_free(t1);
194433423472SRichard Henderson     tcg_temp_free_i64(t0);
194598a9cb79SRichard Henderson 
194698a9cb79SRichard Henderson     cond_free(&ctx->null_cond);
1947869051eaSRichard Henderson     return DISAS_NEXT;
194898a9cb79SRichard Henderson }
194998a9cb79SRichard Henderson 
1950869051eaSRichard Henderson static DisasJumpType trans_mfctl(DisasContext *ctx, uint32_t insn,
195198a9cb79SRichard Henderson                                  const DisasInsn *di)
195298a9cb79SRichard Henderson {
195398a9cb79SRichard Henderson     unsigned rt = extract32(insn, 0, 5);
195498a9cb79SRichard Henderson     unsigned ctl = extract32(insn, 21, 5);
1955eaa3783bSRichard Henderson     TCGv_reg tmp;
195698a9cb79SRichard Henderson 
195798a9cb79SRichard Henderson     switch (ctl) {
195835136a77SRichard Henderson     case CR_SAR:
195998a9cb79SRichard Henderson #ifdef TARGET_HPPA64
196098a9cb79SRichard Henderson         if (extract32(insn, 14, 1) == 0) {
196198a9cb79SRichard Henderson             /* MFSAR without ,W masks low 5 bits.  */
196298a9cb79SRichard Henderson             tmp = dest_gpr(ctx, rt);
1963eaa3783bSRichard Henderson             tcg_gen_andi_reg(tmp, cpu_sar, 31);
196498a9cb79SRichard Henderson             save_gpr(ctx, rt, tmp);
196535136a77SRichard Henderson             goto done;
196698a9cb79SRichard Henderson         }
196798a9cb79SRichard Henderson #endif
196898a9cb79SRichard Henderson         save_gpr(ctx, rt, cpu_sar);
196935136a77SRichard Henderson         goto done;
197035136a77SRichard Henderson     case CR_IT: /* Interval Timer */
197135136a77SRichard Henderson         /* FIXME: Respect PSW_S bit.  */
197235136a77SRichard Henderson         nullify_over(ctx);
197398a9cb79SRichard Henderson         tmp = dest_gpr(ctx, rt);
197435136a77SRichard Henderson         tcg_gen_movi_reg(tmp, 0); /* FIXME */
197598a9cb79SRichard Henderson         save_gpr(ctx, rt, tmp);
197698a9cb79SRichard Henderson         break;
197798a9cb79SRichard Henderson     case 26:
197898a9cb79SRichard Henderson     case 27:
197998a9cb79SRichard Henderson         break;
198098a9cb79SRichard Henderson     default:
198198a9cb79SRichard Henderson         /* All other control registers are privileged.  */
198235136a77SRichard Henderson         CHECK_MOST_PRIVILEGED(EXCP_PRIV_REG);
198335136a77SRichard Henderson         break;
198498a9cb79SRichard Henderson     }
198598a9cb79SRichard Henderson 
198635136a77SRichard Henderson     tmp = get_temp(ctx);
198735136a77SRichard Henderson     tcg_gen_ld_reg(tmp, cpu_env, offsetof(CPUHPPAState, cr[ctl]));
198835136a77SRichard Henderson     save_gpr(ctx, rt, tmp);
198935136a77SRichard Henderson 
199035136a77SRichard Henderson  done:
199198a9cb79SRichard Henderson     cond_free(&ctx->null_cond);
1992869051eaSRichard Henderson     return DISAS_NEXT;
199398a9cb79SRichard Henderson }
199498a9cb79SRichard Henderson 
199533423472SRichard Henderson static DisasJumpType trans_mtsp(DisasContext *ctx, uint32_t insn,
199633423472SRichard Henderson                                 const DisasInsn *di)
199733423472SRichard Henderson {
199833423472SRichard Henderson     unsigned rr = extract32(insn, 16, 5);
199933423472SRichard Henderson     unsigned rs = assemble_sr3(insn);
200033423472SRichard Henderson     TCGv_i64 t64;
200133423472SRichard Henderson 
200233423472SRichard Henderson     if (rs >= 5) {
200333423472SRichard Henderson         CHECK_MOST_PRIVILEGED(EXCP_PRIV_REG);
200433423472SRichard Henderson     }
200533423472SRichard Henderson     nullify_over(ctx);
200633423472SRichard Henderson 
200733423472SRichard Henderson     t64 = tcg_temp_new_i64();
200833423472SRichard Henderson     tcg_gen_extu_reg_i64(t64, load_gpr(ctx, rr));
200933423472SRichard Henderson     tcg_gen_shli_i64(t64, t64, 32);
201033423472SRichard Henderson 
201133423472SRichard Henderson     if (rs >= 4) {
201233423472SRichard Henderson         tcg_gen_st_i64(t64, cpu_env, offsetof(CPUHPPAState, sr[rs]));
201333423472SRichard Henderson     } else {
201433423472SRichard Henderson         tcg_gen_mov_i64(cpu_sr[rs], t64);
201533423472SRichard Henderson     }
201633423472SRichard Henderson     tcg_temp_free_i64(t64);
201733423472SRichard Henderson 
201833423472SRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
201933423472SRichard Henderson }
202033423472SRichard Henderson 
2021869051eaSRichard Henderson static DisasJumpType trans_mtctl(DisasContext *ctx, uint32_t insn,
202298a9cb79SRichard Henderson                                  const DisasInsn *di)
202398a9cb79SRichard Henderson {
202498a9cb79SRichard Henderson     unsigned rin = extract32(insn, 16, 5);
202598a9cb79SRichard Henderson     unsigned ctl = extract32(insn, 21, 5);
202635136a77SRichard Henderson     TCGv_reg reg = load_gpr(ctx, rin);
2027eaa3783bSRichard Henderson     TCGv_reg tmp;
202898a9cb79SRichard Henderson 
202935136a77SRichard Henderson     if (ctl == CR_SAR) {
203098a9cb79SRichard Henderson         tmp = tcg_temp_new();
203135136a77SRichard Henderson         tcg_gen_andi_reg(tmp, reg, TARGET_REGISTER_BITS - 1);
203298a9cb79SRichard Henderson         save_or_nullify(ctx, cpu_sar, tmp);
203398a9cb79SRichard Henderson         tcg_temp_free(tmp);
203498a9cb79SRichard Henderson 
203598a9cb79SRichard Henderson         cond_free(&ctx->null_cond);
2036869051eaSRichard Henderson         return DISAS_NEXT;
203798a9cb79SRichard Henderson     }
203898a9cb79SRichard Henderson 
203935136a77SRichard Henderson     /* All other control registers are privileged or read-only.  */
204035136a77SRichard Henderson     CHECK_MOST_PRIVILEGED(EXCP_PRIV_REG);
204135136a77SRichard Henderson 
204235136a77SRichard Henderson     nullify_over(ctx);
204335136a77SRichard Henderson     switch (ctl) {
204435136a77SRichard Henderson     case CR_IT:
204535136a77SRichard Henderson         /* ??? modify interval timer offset */
204635136a77SRichard Henderson         break;
204735136a77SRichard Henderson 
204835136a77SRichard Henderson     case CR_IIASQ:
204935136a77SRichard Henderson     case CR_IIAOQ:
205035136a77SRichard Henderson         /* FIXME: Respect PSW_Q bit */
205135136a77SRichard Henderson         /* The write advances the queue and stores to the back element.  */
205235136a77SRichard Henderson         tmp = get_temp(ctx);
205335136a77SRichard Henderson         tcg_gen_ld_reg(tmp, cpu_env,
205435136a77SRichard Henderson                        offsetof(CPUHPPAState, cr_back[ctl - CR_IIASQ]));
205535136a77SRichard Henderson         tcg_gen_st_reg(tmp, cpu_env, offsetof(CPUHPPAState, cr[ctl]));
205635136a77SRichard Henderson         tcg_gen_st_reg(reg, cpu_env,
205735136a77SRichard Henderson                        offsetof(CPUHPPAState, cr_back[ctl - CR_IIASQ]));
205835136a77SRichard Henderson         break;
205935136a77SRichard Henderson 
206035136a77SRichard Henderson     default:
206135136a77SRichard Henderson         tcg_gen_st_reg(reg, cpu_env, offsetof(CPUHPPAState, cr[ctl]));
206235136a77SRichard Henderson         break;
206335136a77SRichard Henderson     }
206435136a77SRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
206535136a77SRichard Henderson }
206635136a77SRichard Henderson 
2067869051eaSRichard Henderson static DisasJumpType trans_mtsarcm(DisasContext *ctx, uint32_t insn,
206898a9cb79SRichard Henderson                                    const DisasInsn *di)
206998a9cb79SRichard Henderson {
207098a9cb79SRichard Henderson     unsigned rin = extract32(insn, 16, 5);
2071eaa3783bSRichard Henderson     TCGv_reg tmp = tcg_temp_new();
207298a9cb79SRichard Henderson 
2073eaa3783bSRichard Henderson     tcg_gen_not_reg(tmp, load_gpr(ctx, rin));
2074eaa3783bSRichard Henderson     tcg_gen_andi_reg(tmp, tmp, TARGET_REGISTER_BITS - 1);
207598a9cb79SRichard Henderson     save_or_nullify(ctx, cpu_sar, tmp);
207698a9cb79SRichard Henderson     tcg_temp_free(tmp);
207798a9cb79SRichard Henderson 
207898a9cb79SRichard Henderson     cond_free(&ctx->null_cond);
2079869051eaSRichard Henderson     return DISAS_NEXT;
208098a9cb79SRichard Henderson }
208198a9cb79SRichard Henderson 
2082869051eaSRichard Henderson static DisasJumpType trans_ldsid(DisasContext *ctx, uint32_t insn,
208398a9cb79SRichard Henderson                                  const DisasInsn *di)
208498a9cb79SRichard Henderson {
208598a9cb79SRichard Henderson     unsigned rt = extract32(insn, 0, 5);
2086eaa3783bSRichard Henderson     TCGv_reg dest = dest_gpr(ctx, rt);
208798a9cb79SRichard Henderson 
208898a9cb79SRichard Henderson     /* Since we don't implement space registers, this returns zero.  */
2089eaa3783bSRichard Henderson     tcg_gen_movi_reg(dest, 0);
209098a9cb79SRichard Henderson     save_gpr(ctx, rt, dest);
209198a9cb79SRichard Henderson 
209298a9cb79SRichard Henderson     cond_free(&ctx->null_cond);
2093869051eaSRichard Henderson     return DISAS_NEXT;
209498a9cb79SRichard Henderson }
209598a9cb79SRichard Henderson 
2096e1b5a5edSRichard Henderson #ifndef CONFIG_USER_ONLY
2097e1b5a5edSRichard Henderson /* Note that ssm/rsm instructions number PSW_W and PSW_E differently.  */
2098e1b5a5edSRichard Henderson static target_ureg extract_sm_imm(uint32_t insn)
2099e1b5a5edSRichard Henderson {
2100e1b5a5edSRichard Henderson     target_ureg val = extract32(insn, 16, 10);
2101e1b5a5edSRichard Henderson 
2102e1b5a5edSRichard Henderson     if (val & PSW_SM_E) {
2103e1b5a5edSRichard Henderson         val = (val & ~PSW_SM_E) | PSW_E;
2104e1b5a5edSRichard Henderson     }
2105e1b5a5edSRichard Henderson     if (val & PSW_SM_W) {
2106e1b5a5edSRichard Henderson         val = (val & ~PSW_SM_W) | PSW_W;
2107e1b5a5edSRichard Henderson     }
2108e1b5a5edSRichard Henderson     return val;
2109e1b5a5edSRichard Henderson }
2110e1b5a5edSRichard Henderson 
2111e1b5a5edSRichard Henderson static DisasJumpType trans_rsm(DisasContext *ctx, uint32_t insn,
2112e1b5a5edSRichard Henderson                                const DisasInsn *di)
2113e1b5a5edSRichard Henderson {
2114e1b5a5edSRichard Henderson     unsigned rt = extract32(insn, 0, 5);
2115e1b5a5edSRichard Henderson     target_ureg sm = extract_sm_imm(insn);
2116e1b5a5edSRichard Henderson     TCGv_reg tmp;
2117e1b5a5edSRichard Henderson 
2118e1b5a5edSRichard Henderson     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
2119e1b5a5edSRichard Henderson     nullify_over(ctx);
2120e1b5a5edSRichard Henderson 
2121e1b5a5edSRichard Henderson     tmp = get_temp(ctx);
2122e1b5a5edSRichard Henderson     tcg_gen_ld_reg(tmp, cpu_env, offsetof(CPUHPPAState, psw));
2123e1b5a5edSRichard Henderson     tcg_gen_andi_reg(tmp, tmp, ~sm);
2124e1b5a5edSRichard Henderson     gen_helper_swap_system_mask(tmp, cpu_env, tmp);
2125e1b5a5edSRichard Henderson     save_gpr(ctx, rt, tmp);
2126e1b5a5edSRichard Henderson 
2127e1b5a5edSRichard Henderson     /* Exit the TB to recognize new interrupts, e.g. PSW_M.  */
2128e1b5a5edSRichard Henderson     return nullify_end(ctx, DISAS_IAQ_N_STALE_EXIT);
2129e1b5a5edSRichard Henderson }
2130e1b5a5edSRichard Henderson 
2131e1b5a5edSRichard Henderson static DisasJumpType trans_ssm(DisasContext *ctx, uint32_t insn,
2132e1b5a5edSRichard Henderson                                const DisasInsn *di)
2133e1b5a5edSRichard Henderson {
2134e1b5a5edSRichard Henderson     unsigned rt = extract32(insn, 0, 5);
2135e1b5a5edSRichard Henderson     target_ureg sm = extract_sm_imm(insn);
2136e1b5a5edSRichard Henderson     TCGv_reg tmp;
2137e1b5a5edSRichard Henderson 
2138e1b5a5edSRichard Henderson     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
2139e1b5a5edSRichard Henderson     nullify_over(ctx);
2140e1b5a5edSRichard Henderson 
2141e1b5a5edSRichard Henderson     tmp = get_temp(ctx);
2142e1b5a5edSRichard Henderson     tcg_gen_ld_reg(tmp, cpu_env, offsetof(CPUHPPAState, psw));
2143e1b5a5edSRichard Henderson     tcg_gen_ori_reg(tmp, tmp, sm);
2144e1b5a5edSRichard Henderson     gen_helper_swap_system_mask(tmp, cpu_env, tmp);
2145e1b5a5edSRichard Henderson     save_gpr(ctx, rt, tmp);
2146e1b5a5edSRichard Henderson 
2147e1b5a5edSRichard Henderson     /* Exit the TB to recognize new interrupts, e.g. PSW_I.  */
2148e1b5a5edSRichard Henderson     return nullify_end(ctx, DISAS_IAQ_N_STALE_EXIT);
2149e1b5a5edSRichard Henderson }
2150e1b5a5edSRichard Henderson 
2151e1b5a5edSRichard Henderson static DisasJumpType trans_mtsm(DisasContext *ctx, uint32_t insn,
2152e1b5a5edSRichard Henderson                                 const DisasInsn *di)
2153e1b5a5edSRichard Henderson {
2154e1b5a5edSRichard Henderson     unsigned rr = extract32(insn, 16, 5);
2155e1b5a5edSRichard Henderson     TCGv_reg tmp, reg;
2156e1b5a5edSRichard Henderson 
2157e1b5a5edSRichard Henderson     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
2158e1b5a5edSRichard Henderson     nullify_over(ctx);
2159e1b5a5edSRichard Henderson 
2160e1b5a5edSRichard Henderson     reg = load_gpr(ctx, rr);
2161e1b5a5edSRichard Henderson     tmp = get_temp(ctx);
2162e1b5a5edSRichard Henderson     gen_helper_swap_system_mask(tmp, cpu_env, reg);
2163e1b5a5edSRichard Henderson 
2164e1b5a5edSRichard Henderson     /* Exit the TB to recognize new interrupts.  */
2165e1b5a5edSRichard Henderson     return nullify_end(ctx, DISAS_IAQ_N_STALE_EXIT);
2166e1b5a5edSRichard Henderson }
2167f49b3537SRichard Henderson 
2168f49b3537SRichard Henderson static DisasJumpType trans_rfi(DisasContext *ctx, uint32_t insn,
2169f49b3537SRichard Henderson                                const DisasInsn *di)
2170f49b3537SRichard Henderson {
2171f49b3537SRichard Henderson     unsigned comp = extract32(insn, 5, 4);
2172f49b3537SRichard Henderson 
2173f49b3537SRichard Henderson     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
2174f49b3537SRichard Henderson     nullify_over(ctx);
2175f49b3537SRichard Henderson 
2176f49b3537SRichard Henderson     if (comp == 5) {
2177f49b3537SRichard Henderson         gen_helper_rfi_r(cpu_env);
2178f49b3537SRichard Henderson     } else {
2179f49b3537SRichard Henderson         gen_helper_rfi(cpu_env);
2180f49b3537SRichard Henderson     }
2181f49b3537SRichard Henderson     if (ctx->base.singlestep_enabled) {
2182f49b3537SRichard Henderson         gen_excp_1(EXCP_DEBUG);
2183f49b3537SRichard Henderson     } else {
2184f49b3537SRichard Henderson         tcg_gen_exit_tb(0);
2185f49b3537SRichard Henderson     }
2186f49b3537SRichard Henderson 
2187f49b3537SRichard Henderson     /* Exit the TB to recognize new interrupts.  */
2188f49b3537SRichard Henderson     return nullify_end(ctx, DISAS_NORETURN);
2189f49b3537SRichard Henderson }
2190e1b5a5edSRichard Henderson #endif /* !CONFIG_USER_ONLY */
2191e1b5a5edSRichard Henderson 
219298a9cb79SRichard Henderson static const DisasInsn table_system[] = {
219398a9cb79SRichard Henderson     { 0x00000000u, 0xfc001fe0u, trans_break },
219433423472SRichard Henderson     { 0x00001820u, 0xffe01fffu, trans_mtsp },
219598a9cb79SRichard Henderson     { 0x00001840u, 0xfc00ffffu, trans_mtctl },
219698a9cb79SRichard Henderson     { 0x016018c0u, 0xffe0ffffu, trans_mtsarcm },
219798a9cb79SRichard Henderson     { 0x000014a0u, 0xffffffe0u, trans_mfia },
219898a9cb79SRichard Henderson     { 0x000004a0u, 0xffff1fe0u, trans_mfsp },
21997f221b07SRichard Henderson     { 0x000008a0u, 0xfc1fbfe0u, trans_mfctl },
220098a9cb79SRichard Henderson     { 0x00000400u, 0xffffffffu, trans_sync },
220198a9cb79SRichard Henderson     { 0x000010a0u, 0xfc1f3fe0u, trans_ldsid },
2202e1b5a5edSRichard Henderson #ifndef CONFIG_USER_ONLY
2203e1b5a5edSRichard Henderson     { 0x00000e60u, 0xfc00ffe0u, trans_rsm },
2204e1b5a5edSRichard Henderson     { 0x00000d60u, 0xfc00ffe0u, trans_ssm },
2205e1b5a5edSRichard Henderson     { 0x00001860u, 0xffe0ffffu, trans_mtsm },
2206f49b3537SRichard Henderson     { 0x00000c00u, 0xfffffe1fu, trans_rfi },
2207e1b5a5edSRichard Henderson #endif
220898a9cb79SRichard Henderson };
220998a9cb79SRichard Henderson 
2210869051eaSRichard Henderson static DisasJumpType trans_base_idx_mod(DisasContext *ctx, uint32_t insn,
221198a9cb79SRichard Henderson                                         const DisasInsn *di)
221298a9cb79SRichard Henderson {
221398a9cb79SRichard Henderson     unsigned rb = extract32(insn, 21, 5);
221498a9cb79SRichard Henderson     unsigned rx = extract32(insn, 16, 5);
2215eaa3783bSRichard Henderson     TCGv_reg dest = dest_gpr(ctx, rb);
2216eaa3783bSRichard Henderson     TCGv_reg src1 = load_gpr(ctx, rb);
2217eaa3783bSRichard Henderson     TCGv_reg src2 = load_gpr(ctx, rx);
221898a9cb79SRichard Henderson 
221998a9cb79SRichard Henderson     /* The only thing we need to do is the base register modification.  */
2220eaa3783bSRichard Henderson     tcg_gen_add_reg(dest, src1, src2);
222198a9cb79SRichard Henderson     save_gpr(ctx, rb, dest);
222298a9cb79SRichard Henderson 
222398a9cb79SRichard Henderson     cond_free(&ctx->null_cond);
2224869051eaSRichard Henderson     return DISAS_NEXT;
222598a9cb79SRichard Henderson }
222698a9cb79SRichard Henderson 
2227869051eaSRichard Henderson static DisasJumpType trans_probe(DisasContext *ctx, uint32_t insn,
222898a9cb79SRichard Henderson                                  const DisasInsn *di)
222998a9cb79SRichard Henderson {
223098a9cb79SRichard Henderson     unsigned rt = extract32(insn, 0, 5);
223198a9cb79SRichard Henderson     unsigned rb = extract32(insn, 21, 5);
223298a9cb79SRichard Henderson     unsigned is_write = extract32(insn, 6, 1);
2233eaa3783bSRichard Henderson     TCGv_reg dest;
223498a9cb79SRichard Henderson 
223598a9cb79SRichard Henderson     nullify_over(ctx);
223698a9cb79SRichard Henderson 
223798a9cb79SRichard Henderson     /* ??? Do something with priv level operand.  */
223898a9cb79SRichard Henderson     dest = dest_gpr(ctx, rt);
223998a9cb79SRichard Henderson     if (is_write) {
224098a9cb79SRichard Henderson         gen_helper_probe_w(dest, load_gpr(ctx, rb));
224198a9cb79SRichard Henderson     } else {
224298a9cb79SRichard Henderson         gen_helper_probe_r(dest, load_gpr(ctx, rb));
224398a9cb79SRichard Henderson     }
224498a9cb79SRichard Henderson     save_gpr(ctx, rt, dest);
2245869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
224698a9cb79SRichard Henderson }
224798a9cb79SRichard Henderson 
224898a9cb79SRichard Henderson static const DisasInsn table_mem_mgmt[] = {
224998a9cb79SRichard Henderson     { 0x04003280u, 0xfc003fffu, trans_nop },          /* fdc, disp */
225098a9cb79SRichard Henderson     { 0x04001280u, 0xfc003fffu, trans_nop },          /* fdc, index */
225198a9cb79SRichard Henderson     { 0x040012a0u, 0xfc003fffu, trans_base_idx_mod }, /* fdc, index, base mod */
225298a9cb79SRichard Henderson     { 0x040012c0u, 0xfc003fffu, trans_nop },          /* fdce */
225398a9cb79SRichard Henderson     { 0x040012e0u, 0xfc003fffu, trans_base_idx_mod }, /* fdce, base mod */
225498a9cb79SRichard Henderson     { 0x04000280u, 0xfc001fffu, trans_nop },          /* fic 0a */
225598a9cb79SRichard Henderson     { 0x040002a0u, 0xfc001fffu, trans_base_idx_mod }, /* fic 0a, base mod */
225698a9cb79SRichard Henderson     { 0x040013c0u, 0xfc003fffu, trans_nop },          /* fic 4f */
225798a9cb79SRichard Henderson     { 0x040013e0u, 0xfc003fffu, trans_base_idx_mod }, /* fic 4f, base mod */
225898a9cb79SRichard Henderson     { 0x040002c0u, 0xfc001fffu, trans_nop },          /* fice */
225998a9cb79SRichard Henderson     { 0x040002e0u, 0xfc001fffu, trans_base_idx_mod }, /* fice, base mod */
226098a9cb79SRichard Henderson     { 0x04002700u, 0xfc003fffu, trans_nop },          /* pdc */
226198a9cb79SRichard Henderson     { 0x04002720u, 0xfc003fffu, trans_base_idx_mod }, /* pdc, base mod */
226298a9cb79SRichard Henderson     { 0x04001180u, 0xfc003fa0u, trans_probe },        /* probe */
226398a9cb79SRichard Henderson     { 0x04003180u, 0xfc003fa0u, trans_probe },        /* probei */
226498a9cb79SRichard Henderson };
226598a9cb79SRichard Henderson 
2266869051eaSRichard Henderson static DisasJumpType trans_add(DisasContext *ctx, uint32_t insn,
2267b2167459SRichard Henderson                                const DisasInsn *di)
2268b2167459SRichard Henderson {
2269b2167459SRichard Henderson     unsigned r2 = extract32(insn, 21, 5);
2270b2167459SRichard Henderson     unsigned r1 = extract32(insn, 16, 5);
2271b2167459SRichard Henderson     unsigned cf = extract32(insn, 12, 4);
2272b2167459SRichard Henderson     unsigned ext = extract32(insn, 8, 4);
2273b2167459SRichard Henderson     unsigned shift = extract32(insn, 6, 2);
2274b2167459SRichard Henderson     unsigned rt = extract32(insn,  0, 5);
2275eaa3783bSRichard Henderson     TCGv_reg tcg_r1, tcg_r2;
2276b2167459SRichard Henderson     bool is_c = false;
2277b2167459SRichard Henderson     bool is_l = false;
2278b2167459SRichard Henderson     bool is_tc = false;
2279b2167459SRichard Henderson     bool is_tsv = false;
2280869051eaSRichard Henderson     DisasJumpType ret;
2281b2167459SRichard Henderson 
2282b2167459SRichard Henderson     switch (ext) {
2283b2167459SRichard Henderson     case 0x6: /* ADD, SHLADD */
2284b2167459SRichard Henderson         break;
2285b2167459SRichard Henderson     case 0xa: /* ADD,L, SHLADD,L */
2286b2167459SRichard Henderson         is_l = true;
2287b2167459SRichard Henderson         break;
2288b2167459SRichard Henderson     case 0xe: /* ADD,TSV, SHLADD,TSV (1) */
2289b2167459SRichard Henderson         is_tsv = true;
2290b2167459SRichard Henderson         break;
2291b2167459SRichard Henderson     case 0x7: /* ADD,C */
2292b2167459SRichard Henderson         is_c = true;
2293b2167459SRichard Henderson         break;
2294b2167459SRichard Henderson     case 0xf: /* ADD,C,TSV */
2295b2167459SRichard Henderson         is_c = is_tsv = true;
2296b2167459SRichard Henderson         break;
2297b2167459SRichard Henderson     default:
2298b2167459SRichard Henderson         return gen_illegal(ctx);
2299b2167459SRichard Henderson     }
2300b2167459SRichard Henderson 
2301b2167459SRichard Henderson     if (cf) {
2302b2167459SRichard Henderson         nullify_over(ctx);
2303b2167459SRichard Henderson     }
2304b2167459SRichard Henderson     tcg_r1 = load_gpr(ctx, r1);
2305b2167459SRichard Henderson     tcg_r2 = load_gpr(ctx, r2);
2306b2167459SRichard Henderson     ret = do_add(ctx, rt, tcg_r1, tcg_r2, shift, is_l, is_tsv, is_tc, is_c, cf);
2307b2167459SRichard Henderson     return nullify_end(ctx, ret);
2308b2167459SRichard Henderson }
2309b2167459SRichard Henderson 
2310869051eaSRichard Henderson static DisasJumpType trans_sub(DisasContext *ctx, uint32_t insn,
2311b2167459SRichard Henderson                                const DisasInsn *di)
2312b2167459SRichard Henderson {
2313b2167459SRichard Henderson     unsigned r2 = extract32(insn, 21, 5);
2314b2167459SRichard Henderson     unsigned r1 = extract32(insn, 16, 5);
2315b2167459SRichard Henderson     unsigned cf = extract32(insn, 12, 4);
2316b2167459SRichard Henderson     unsigned ext = extract32(insn, 6, 6);
2317b2167459SRichard Henderson     unsigned rt = extract32(insn,  0, 5);
2318eaa3783bSRichard Henderson     TCGv_reg tcg_r1, tcg_r2;
2319b2167459SRichard Henderson     bool is_b = false;
2320b2167459SRichard Henderson     bool is_tc = false;
2321b2167459SRichard Henderson     bool is_tsv = false;
2322869051eaSRichard Henderson     DisasJumpType ret;
2323b2167459SRichard Henderson 
2324b2167459SRichard Henderson     switch (ext) {
2325b2167459SRichard Henderson     case 0x10: /* SUB */
2326b2167459SRichard Henderson         break;
2327b2167459SRichard Henderson     case 0x30: /* SUB,TSV */
2328b2167459SRichard Henderson         is_tsv = true;
2329b2167459SRichard Henderson         break;
2330b2167459SRichard Henderson     case 0x14: /* SUB,B */
2331b2167459SRichard Henderson         is_b = true;
2332b2167459SRichard Henderson         break;
2333b2167459SRichard Henderson     case 0x34: /* SUB,B,TSV */
2334b2167459SRichard Henderson         is_b = is_tsv = true;
2335b2167459SRichard Henderson         break;
2336b2167459SRichard Henderson     case 0x13: /* SUB,TC */
2337b2167459SRichard Henderson         is_tc = true;
2338b2167459SRichard Henderson         break;
2339b2167459SRichard Henderson     case 0x33: /* SUB,TSV,TC */
2340b2167459SRichard Henderson         is_tc = is_tsv = true;
2341b2167459SRichard Henderson         break;
2342b2167459SRichard Henderson     default:
2343b2167459SRichard Henderson         return gen_illegal(ctx);
2344b2167459SRichard Henderson     }
2345b2167459SRichard Henderson 
2346b2167459SRichard Henderson     if (cf) {
2347b2167459SRichard Henderson         nullify_over(ctx);
2348b2167459SRichard Henderson     }
2349b2167459SRichard Henderson     tcg_r1 = load_gpr(ctx, r1);
2350b2167459SRichard Henderson     tcg_r2 = load_gpr(ctx, r2);
2351b2167459SRichard Henderson     ret = do_sub(ctx, rt, tcg_r1, tcg_r2, is_tsv, is_b, is_tc, cf);
2352b2167459SRichard Henderson     return nullify_end(ctx, ret);
2353b2167459SRichard Henderson }
2354b2167459SRichard Henderson 
2355869051eaSRichard Henderson static DisasJumpType trans_log(DisasContext *ctx, uint32_t insn,
2356b2167459SRichard Henderson                                const DisasInsn *di)
2357b2167459SRichard Henderson {
2358b2167459SRichard Henderson     unsigned r2 = extract32(insn, 21, 5);
2359b2167459SRichard Henderson     unsigned r1 = extract32(insn, 16, 5);
2360b2167459SRichard Henderson     unsigned cf = extract32(insn, 12, 4);
2361b2167459SRichard Henderson     unsigned rt = extract32(insn,  0, 5);
2362eaa3783bSRichard Henderson     TCGv_reg tcg_r1, tcg_r2;
2363869051eaSRichard Henderson     DisasJumpType ret;
2364b2167459SRichard Henderson 
2365b2167459SRichard Henderson     if (cf) {
2366b2167459SRichard Henderson         nullify_over(ctx);
2367b2167459SRichard Henderson     }
2368b2167459SRichard Henderson     tcg_r1 = load_gpr(ctx, r1);
2369b2167459SRichard Henderson     tcg_r2 = load_gpr(ctx, r2);
2370eff235ebSPaolo Bonzini     ret = do_log(ctx, rt, tcg_r1, tcg_r2, cf, di->f.ttt);
2371b2167459SRichard Henderson     return nullify_end(ctx, ret);
2372b2167459SRichard Henderson }
2373b2167459SRichard Henderson 
2374b2167459SRichard Henderson /* OR r,0,t -> COPY (according to gas) */
2375869051eaSRichard Henderson static DisasJumpType trans_copy(DisasContext *ctx, uint32_t insn,
2376b2167459SRichard Henderson                                 const DisasInsn *di)
2377b2167459SRichard Henderson {
2378b2167459SRichard Henderson     unsigned r1 = extract32(insn, 16, 5);
2379b2167459SRichard Henderson     unsigned rt = extract32(insn,  0, 5);
2380b2167459SRichard Henderson 
2381b2167459SRichard Henderson     if (r1 == 0) {
2382eaa3783bSRichard Henderson         TCGv_reg dest = dest_gpr(ctx, rt);
2383eaa3783bSRichard Henderson         tcg_gen_movi_reg(dest, 0);
2384b2167459SRichard Henderson         save_gpr(ctx, rt, dest);
2385b2167459SRichard Henderson     } else {
2386b2167459SRichard Henderson         save_gpr(ctx, rt, cpu_gr[r1]);
2387b2167459SRichard Henderson     }
2388b2167459SRichard Henderson     cond_free(&ctx->null_cond);
2389869051eaSRichard Henderson     return DISAS_NEXT;
2390b2167459SRichard Henderson }
2391b2167459SRichard Henderson 
2392869051eaSRichard Henderson static DisasJumpType trans_cmpclr(DisasContext *ctx, uint32_t insn,
2393b2167459SRichard Henderson                                   const DisasInsn *di)
2394b2167459SRichard Henderson {
2395b2167459SRichard Henderson     unsigned r2 = extract32(insn, 21, 5);
2396b2167459SRichard Henderson     unsigned r1 = extract32(insn, 16, 5);
2397b2167459SRichard Henderson     unsigned cf = extract32(insn, 12, 4);
2398b2167459SRichard Henderson     unsigned rt = extract32(insn,  0, 5);
2399eaa3783bSRichard Henderson     TCGv_reg tcg_r1, tcg_r2;
2400869051eaSRichard Henderson     DisasJumpType ret;
2401b2167459SRichard Henderson 
2402b2167459SRichard Henderson     if (cf) {
2403b2167459SRichard Henderson         nullify_over(ctx);
2404b2167459SRichard Henderson     }
2405b2167459SRichard Henderson     tcg_r1 = load_gpr(ctx, r1);
2406b2167459SRichard Henderson     tcg_r2 = load_gpr(ctx, r2);
2407b2167459SRichard Henderson     ret = do_cmpclr(ctx, rt, tcg_r1, tcg_r2, cf);
2408b2167459SRichard Henderson     return nullify_end(ctx, ret);
2409b2167459SRichard Henderson }
2410b2167459SRichard Henderson 
2411869051eaSRichard Henderson static DisasJumpType trans_uxor(DisasContext *ctx, uint32_t insn,
2412b2167459SRichard Henderson                                 const DisasInsn *di)
2413b2167459SRichard Henderson {
2414b2167459SRichard Henderson     unsigned r2 = extract32(insn, 21, 5);
2415b2167459SRichard Henderson     unsigned r1 = extract32(insn, 16, 5);
2416b2167459SRichard Henderson     unsigned cf = extract32(insn, 12, 4);
2417b2167459SRichard Henderson     unsigned rt = extract32(insn,  0, 5);
2418eaa3783bSRichard Henderson     TCGv_reg tcg_r1, tcg_r2;
2419869051eaSRichard Henderson     DisasJumpType ret;
2420b2167459SRichard Henderson 
2421b2167459SRichard Henderson     if (cf) {
2422b2167459SRichard Henderson         nullify_over(ctx);
2423b2167459SRichard Henderson     }
2424b2167459SRichard Henderson     tcg_r1 = load_gpr(ctx, r1);
2425b2167459SRichard Henderson     tcg_r2 = load_gpr(ctx, r2);
2426eaa3783bSRichard Henderson     ret = do_unit(ctx, rt, tcg_r1, tcg_r2, cf, false, tcg_gen_xor_reg);
2427b2167459SRichard Henderson     return nullify_end(ctx, ret);
2428b2167459SRichard Henderson }
2429b2167459SRichard Henderson 
2430869051eaSRichard Henderson static DisasJumpType trans_uaddcm(DisasContext *ctx, uint32_t insn,
2431b2167459SRichard Henderson                                   const DisasInsn *di)
2432b2167459SRichard Henderson {
2433b2167459SRichard Henderson     unsigned r2 = extract32(insn, 21, 5);
2434b2167459SRichard Henderson     unsigned r1 = extract32(insn, 16, 5);
2435b2167459SRichard Henderson     unsigned cf = extract32(insn, 12, 4);
2436b2167459SRichard Henderson     unsigned is_tc = extract32(insn, 6, 1);
2437b2167459SRichard Henderson     unsigned rt = extract32(insn,  0, 5);
2438eaa3783bSRichard Henderson     TCGv_reg tcg_r1, tcg_r2, tmp;
2439869051eaSRichard Henderson     DisasJumpType ret;
2440b2167459SRichard Henderson 
2441b2167459SRichard Henderson     if (cf) {
2442b2167459SRichard Henderson         nullify_over(ctx);
2443b2167459SRichard Henderson     }
2444b2167459SRichard Henderson     tcg_r1 = load_gpr(ctx, r1);
2445b2167459SRichard Henderson     tcg_r2 = load_gpr(ctx, r2);
2446b2167459SRichard Henderson     tmp = get_temp(ctx);
2447eaa3783bSRichard Henderson     tcg_gen_not_reg(tmp, tcg_r2);
2448eaa3783bSRichard Henderson     ret = do_unit(ctx, rt, tcg_r1, tmp, cf, is_tc, tcg_gen_add_reg);
2449b2167459SRichard Henderson     return nullify_end(ctx, ret);
2450b2167459SRichard Henderson }
2451b2167459SRichard Henderson 
2452869051eaSRichard Henderson static DisasJumpType trans_dcor(DisasContext *ctx, uint32_t insn,
2453b2167459SRichard Henderson                                 const DisasInsn *di)
2454b2167459SRichard Henderson {
2455b2167459SRichard Henderson     unsigned r2 = extract32(insn, 21, 5);
2456b2167459SRichard Henderson     unsigned cf = extract32(insn, 12, 4);
2457b2167459SRichard Henderson     unsigned is_i = extract32(insn, 6, 1);
2458b2167459SRichard Henderson     unsigned rt = extract32(insn,  0, 5);
2459eaa3783bSRichard Henderson     TCGv_reg tmp;
2460869051eaSRichard Henderson     DisasJumpType ret;
2461b2167459SRichard Henderson 
2462b2167459SRichard Henderson     nullify_over(ctx);
2463b2167459SRichard Henderson 
2464b2167459SRichard Henderson     tmp = get_temp(ctx);
2465eaa3783bSRichard Henderson     tcg_gen_shri_reg(tmp, cpu_psw_cb, 3);
2466b2167459SRichard Henderson     if (!is_i) {
2467eaa3783bSRichard Henderson         tcg_gen_not_reg(tmp, tmp);
2468b2167459SRichard Henderson     }
2469eaa3783bSRichard Henderson     tcg_gen_andi_reg(tmp, tmp, 0x11111111);
2470eaa3783bSRichard Henderson     tcg_gen_muli_reg(tmp, tmp, 6);
2471b2167459SRichard Henderson     ret = do_unit(ctx, rt, tmp, load_gpr(ctx, r2), cf, false,
2472eaa3783bSRichard Henderson                   is_i ? tcg_gen_add_reg : tcg_gen_sub_reg);
2473b2167459SRichard Henderson 
2474b2167459SRichard Henderson     return nullify_end(ctx, ret);
2475b2167459SRichard Henderson }
2476b2167459SRichard Henderson 
2477869051eaSRichard Henderson static DisasJumpType trans_ds(DisasContext *ctx, uint32_t insn,
2478b2167459SRichard Henderson                               const DisasInsn *di)
2479b2167459SRichard Henderson {
2480b2167459SRichard Henderson     unsigned r2 = extract32(insn, 21, 5);
2481b2167459SRichard Henderson     unsigned r1 = extract32(insn, 16, 5);
2482b2167459SRichard Henderson     unsigned cf = extract32(insn, 12, 4);
2483b2167459SRichard Henderson     unsigned rt = extract32(insn,  0, 5);
2484eaa3783bSRichard Henderson     TCGv_reg dest, add1, add2, addc, zero, in1, in2;
2485b2167459SRichard Henderson 
2486b2167459SRichard Henderson     nullify_over(ctx);
2487b2167459SRichard Henderson 
2488b2167459SRichard Henderson     in1 = load_gpr(ctx, r1);
2489b2167459SRichard Henderson     in2 = load_gpr(ctx, r2);
2490b2167459SRichard Henderson 
2491b2167459SRichard Henderson     add1 = tcg_temp_new();
2492b2167459SRichard Henderson     add2 = tcg_temp_new();
2493b2167459SRichard Henderson     addc = tcg_temp_new();
2494b2167459SRichard Henderson     dest = tcg_temp_new();
2495eaa3783bSRichard Henderson     zero = tcg_const_reg(0);
2496b2167459SRichard Henderson 
2497b2167459SRichard Henderson     /* Form R1 << 1 | PSW[CB]{8}.  */
2498eaa3783bSRichard Henderson     tcg_gen_add_reg(add1, in1, in1);
2499eaa3783bSRichard Henderson     tcg_gen_add_reg(add1, add1, cpu_psw_cb_msb);
2500b2167459SRichard Henderson 
2501b2167459SRichard Henderson     /* Add or subtract R2, depending on PSW[V].  Proper computation of
2502b2167459SRichard Henderson        carry{8} requires that we subtract via + ~R2 + 1, as described in
2503b2167459SRichard Henderson        the manual.  By extracting and masking V, we can produce the
2504b2167459SRichard Henderson        proper inputs to the addition without movcond.  */
2505eaa3783bSRichard Henderson     tcg_gen_sari_reg(addc, cpu_psw_v, TARGET_REGISTER_BITS - 1);
2506eaa3783bSRichard Henderson     tcg_gen_xor_reg(add2, in2, addc);
2507eaa3783bSRichard Henderson     tcg_gen_andi_reg(addc, addc, 1);
2508b2167459SRichard Henderson     /* ??? This is only correct for 32-bit.  */
2509b2167459SRichard Henderson     tcg_gen_add2_i32(dest, cpu_psw_cb_msb, add1, zero, add2, zero);
2510b2167459SRichard Henderson     tcg_gen_add2_i32(dest, cpu_psw_cb_msb, dest, cpu_psw_cb_msb, addc, zero);
2511b2167459SRichard Henderson 
2512b2167459SRichard Henderson     tcg_temp_free(addc);
2513b2167459SRichard Henderson     tcg_temp_free(zero);
2514b2167459SRichard Henderson 
2515b2167459SRichard Henderson     /* Write back the result register.  */
2516b2167459SRichard Henderson     save_gpr(ctx, rt, dest);
2517b2167459SRichard Henderson 
2518b2167459SRichard Henderson     /* Write back PSW[CB].  */
2519eaa3783bSRichard Henderson     tcg_gen_xor_reg(cpu_psw_cb, add1, add2);
2520eaa3783bSRichard Henderson     tcg_gen_xor_reg(cpu_psw_cb, cpu_psw_cb, dest);
2521b2167459SRichard Henderson 
2522b2167459SRichard Henderson     /* Write back PSW[V] for the division step.  */
2523eaa3783bSRichard Henderson     tcg_gen_neg_reg(cpu_psw_v, cpu_psw_cb_msb);
2524eaa3783bSRichard Henderson     tcg_gen_xor_reg(cpu_psw_v, cpu_psw_v, in2);
2525b2167459SRichard Henderson 
2526b2167459SRichard Henderson     /* Install the new nullification.  */
2527b2167459SRichard Henderson     if (cf) {
2528eaa3783bSRichard Henderson         TCGv_reg sv = NULL;
2529b2167459SRichard Henderson         if (cf >> 1 == 6) {
2530b2167459SRichard Henderson             /* ??? The lshift is supposed to contribute to overflow.  */
2531b2167459SRichard Henderson             sv = do_add_sv(ctx, dest, add1, add2);
2532b2167459SRichard Henderson         }
2533b2167459SRichard Henderson         ctx->null_cond = do_cond(cf, dest, cpu_psw_cb_msb, sv);
2534b2167459SRichard Henderson     }
2535b2167459SRichard Henderson 
2536b2167459SRichard Henderson     tcg_temp_free(add1);
2537b2167459SRichard Henderson     tcg_temp_free(add2);
2538b2167459SRichard Henderson     tcg_temp_free(dest);
2539b2167459SRichard Henderson 
2540869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
2541b2167459SRichard Henderson }
2542b2167459SRichard Henderson 
2543b2167459SRichard Henderson static const DisasInsn table_arith_log[] = {
2544b2167459SRichard Henderson     { 0x08000240u, 0xfc00ffffu, trans_nop },  /* or x,y,0 */
2545b2167459SRichard Henderson     { 0x08000240u, 0xffe0ffe0u, trans_copy }, /* or x,0,t */
2546eaa3783bSRichard Henderson     { 0x08000000u, 0xfc000fe0u, trans_log, .f.ttt = tcg_gen_andc_reg },
2547eaa3783bSRichard Henderson     { 0x08000200u, 0xfc000fe0u, trans_log, .f.ttt = tcg_gen_and_reg },
2548eaa3783bSRichard Henderson     { 0x08000240u, 0xfc000fe0u, trans_log, .f.ttt = tcg_gen_or_reg },
2549eaa3783bSRichard Henderson     { 0x08000280u, 0xfc000fe0u, trans_log, .f.ttt = tcg_gen_xor_reg },
2550b2167459SRichard Henderson     { 0x08000880u, 0xfc000fe0u, trans_cmpclr },
2551b2167459SRichard Henderson     { 0x08000380u, 0xfc000fe0u, trans_uxor },
2552b2167459SRichard Henderson     { 0x08000980u, 0xfc000fa0u, trans_uaddcm },
2553b2167459SRichard Henderson     { 0x08000b80u, 0xfc1f0fa0u, trans_dcor },
2554b2167459SRichard Henderson     { 0x08000440u, 0xfc000fe0u, trans_ds },
2555b2167459SRichard Henderson     { 0x08000700u, 0xfc0007e0u, trans_add }, /* add */
2556b2167459SRichard Henderson     { 0x08000400u, 0xfc0006e0u, trans_sub }, /* sub; sub,b; sub,tsv */
2557b2167459SRichard Henderson     { 0x080004c0u, 0xfc0007e0u, trans_sub }, /* sub,tc; sub,tsv,tc */
2558b2167459SRichard Henderson     { 0x08000200u, 0xfc000320u, trans_add }, /* shladd */
2559b2167459SRichard Henderson };
2560b2167459SRichard Henderson 
2561869051eaSRichard Henderson static DisasJumpType trans_addi(DisasContext *ctx, uint32_t insn)
2562b2167459SRichard Henderson {
2563eaa3783bSRichard Henderson     target_sreg im = low_sextract(insn, 0, 11);
2564b2167459SRichard Henderson     unsigned e1 = extract32(insn, 11, 1);
2565b2167459SRichard Henderson     unsigned cf = extract32(insn, 12, 4);
2566b2167459SRichard Henderson     unsigned rt = extract32(insn, 16, 5);
2567b2167459SRichard Henderson     unsigned r2 = extract32(insn, 21, 5);
2568b2167459SRichard Henderson     unsigned o1 = extract32(insn, 26, 1);
2569eaa3783bSRichard Henderson     TCGv_reg tcg_im, tcg_r2;
2570869051eaSRichard Henderson     DisasJumpType ret;
2571b2167459SRichard Henderson 
2572b2167459SRichard Henderson     if (cf) {
2573b2167459SRichard Henderson         nullify_over(ctx);
2574b2167459SRichard Henderson     }
2575b2167459SRichard Henderson 
2576b2167459SRichard Henderson     tcg_im = load_const(ctx, im);
2577b2167459SRichard Henderson     tcg_r2 = load_gpr(ctx, r2);
2578b2167459SRichard Henderson     ret = do_add(ctx, rt, tcg_im, tcg_r2, 0, false, e1, !o1, false, cf);
2579b2167459SRichard Henderson 
2580b2167459SRichard Henderson     return nullify_end(ctx, ret);
2581b2167459SRichard Henderson }
2582b2167459SRichard Henderson 
2583869051eaSRichard Henderson static DisasJumpType trans_subi(DisasContext *ctx, uint32_t insn)
2584b2167459SRichard Henderson {
2585eaa3783bSRichard Henderson     target_sreg im = low_sextract(insn, 0, 11);
2586b2167459SRichard Henderson     unsigned e1 = extract32(insn, 11, 1);
2587b2167459SRichard Henderson     unsigned cf = extract32(insn, 12, 4);
2588b2167459SRichard Henderson     unsigned rt = extract32(insn, 16, 5);
2589b2167459SRichard Henderson     unsigned r2 = extract32(insn, 21, 5);
2590eaa3783bSRichard Henderson     TCGv_reg tcg_im, tcg_r2;
2591869051eaSRichard Henderson     DisasJumpType ret;
2592b2167459SRichard Henderson 
2593b2167459SRichard Henderson     if (cf) {
2594b2167459SRichard Henderson         nullify_over(ctx);
2595b2167459SRichard Henderson     }
2596b2167459SRichard Henderson 
2597b2167459SRichard Henderson     tcg_im = load_const(ctx, im);
2598b2167459SRichard Henderson     tcg_r2 = load_gpr(ctx, r2);
2599b2167459SRichard Henderson     ret = do_sub(ctx, rt, tcg_im, tcg_r2, e1, false, false, cf);
2600b2167459SRichard Henderson 
2601b2167459SRichard Henderson     return nullify_end(ctx, ret);
2602b2167459SRichard Henderson }
2603b2167459SRichard Henderson 
2604869051eaSRichard Henderson static DisasJumpType trans_cmpiclr(DisasContext *ctx, uint32_t insn)
2605b2167459SRichard Henderson {
2606eaa3783bSRichard Henderson     target_sreg im = low_sextract(insn, 0, 11);
2607b2167459SRichard Henderson     unsigned cf = extract32(insn, 12, 4);
2608b2167459SRichard Henderson     unsigned rt = extract32(insn, 16, 5);
2609b2167459SRichard Henderson     unsigned r2 = extract32(insn, 21, 5);
2610eaa3783bSRichard Henderson     TCGv_reg tcg_im, tcg_r2;
2611869051eaSRichard Henderson     DisasJumpType ret;
2612b2167459SRichard Henderson 
2613b2167459SRichard Henderson     if (cf) {
2614b2167459SRichard Henderson         nullify_over(ctx);
2615b2167459SRichard Henderson     }
2616b2167459SRichard Henderson 
2617b2167459SRichard Henderson     tcg_im = load_const(ctx, im);
2618b2167459SRichard Henderson     tcg_r2 = load_gpr(ctx, r2);
2619b2167459SRichard Henderson     ret = do_cmpclr(ctx, rt, tcg_im, tcg_r2, cf);
2620b2167459SRichard Henderson 
2621b2167459SRichard Henderson     return nullify_end(ctx, ret);
2622b2167459SRichard Henderson }
2623b2167459SRichard Henderson 
2624869051eaSRichard Henderson static DisasJumpType trans_ld_idx_i(DisasContext *ctx, uint32_t insn,
262596d6407fSRichard Henderson                                     const DisasInsn *di)
262696d6407fSRichard Henderson {
262796d6407fSRichard Henderson     unsigned rt = extract32(insn, 0, 5);
262896d6407fSRichard Henderson     unsigned m = extract32(insn, 5, 1);
262996d6407fSRichard Henderson     unsigned sz = extract32(insn, 6, 2);
263096d6407fSRichard Henderson     unsigned a = extract32(insn, 13, 1);
263196d6407fSRichard Henderson     int disp = low_sextract(insn, 16, 5);
263296d6407fSRichard Henderson     unsigned rb = extract32(insn, 21, 5);
263396d6407fSRichard Henderson     int modify = (m ? (a ? -1 : 1) : 0);
263496d6407fSRichard Henderson     TCGMemOp mop = MO_TE | sz;
263596d6407fSRichard Henderson 
263696d6407fSRichard Henderson     return do_load(ctx, rt, rb, 0, 0, disp, modify, mop);
263796d6407fSRichard Henderson }
263896d6407fSRichard Henderson 
2639869051eaSRichard Henderson static DisasJumpType trans_ld_idx_x(DisasContext *ctx, uint32_t insn,
264096d6407fSRichard Henderson                                     const DisasInsn *di)
264196d6407fSRichard Henderson {
264296d6407fSRichard Henderson     unsigned rt = extract32(insn, 0, 5);
264396d6407fSRichard Henderson     unsigned m = extract32(insn, 5, 1);
264496d6407fSRichard Henderson     unsigned sz = extract32(insn, 6, 2);
264596d6407fSRichard Henderson     unsigned u = extract32(insn, 13, 1);
264696d6407fSRichard Henderson     unsigned rx = extract32(insn, 16, 5);
264796d6407fSRichard Henderson     unsigned rb = extract32(insn, 21, 5);
264896d6407fSRichard Henderson     TCGMemOp mop = MO_TE | sz;
264996d6407fSRichard Henderson 
265096d6407fSRichard Henderson     return do_load(ctx, rt, rb, rx, u ? sz : 0, 0, m, mop);
265196d6407fSRichard Henderson }
265296d6407fSRichard Henderson 
2653869051eaSRichard Henderson static DisasJumpType trans_st_idx_i(DisasContext *ctx, uint32_t insn,
265496d6407fSRichard Henderson                                     const DisasInsn *di)
265596d6407fSRichard Henderson {
265696d6407fSRichard Henderson     int disp = low_sextract(insn, 0, 5);
265796d6407fSRichard Henderson     unsigned m = extract32(insn, 5, 1);
265896d6407fSRichard Henderson     unsigned sz = extract32(insn, 6, 2);
265996d6407fSRichard Henderson     unsigned a = extract32(insn, 13, 1);
266096d6407fSRichard Henderson     unsigned rr = extract32(insn, 16, 5);
266196d6407fSRichard Henderson     unsigned rb = extract32(insn, 21, 5);
266296d6407fSRichard Henderson     int modify = (m ? (a ? -1 : 1) : 0);
266396d6407fSRichard Henderson     TCGMemOp mop = MO_TE | sz;
266496d6407fSRichard Henderson 
266596d6407fSRichard Henderson     return do_store(ctx, rr, rb, disp, modify, mop);
266696d6407fSRichard Henderson }
266796d6407fSRichard Henderson 
2668869051eaSRichard Henderson static DisasJumpType trans_ldcw(DisasContext *ctx, uint32_t insn,
266996d6407fSRichard Henderson                                 const DisasInsn *di)
267096d6407fSRichard Henderson {
267196d6407fSRichard Henderson     unsigned rt = extract32(insn, 0, 5);
267296d6407fSRichard Henderson     unsigned m = extract32(insn, 5, 1);
267396d6407fSRichard Henderson     unsigned i = extract32(insn, 12, 1);
267496d6407fSRichard Henderson     unsigned au = extract32(insn, 13, 1);
267596d6407fSRichard Henderson     unsigned rx = extract32(insn, 16, 5);
267696d6407fSRichard Henderson     unsigned rb = extract32(insn, 21, 5);
267796d6407fSRichard Henderson     TCGMemOp mop = MO_TEUL | MO_ALIGN_16;
2678eaa3783bSRichard Henderson     TCGv_reg zero, addr, base, dest;
267996d6407fSRichard Henderson     int modify, disp = 0, scale = 0;
268096d6407fSRichard Henderson 
268196d6407fSRichard Henderson     nullify_over(ctx);
268296d6407fSRichard Henderson 
268396d6407fSRichard Henderson     /* ??? Share more code with do_load and do_load_{32,64}.  */
268496d6407fSRichard Henderson 
268596d6407fSRichard Henderson     if (i) {
268696d6407fSRichard Henderson         modify = (m ? (au ? -1 : 1) : 0);
268796d6407fSRichard Henderson         disp = low_sextract(rx, 0, 5);
268896d6407fSRichard Henderson         rx = 0;
268996d6407fSRichard Henderson     } else {
269096d6407fSRichard Henderson         modify = m;
269196d6407fSRichard Henderson         if (au) {
269296d6407fSRichard Henderson             scale = mop & MO_SIZE;
269396d6407fSRichard Henderson         }
269496d6407fSRichard Henderson     }
269596d6407fSRichard Henderson     if (modify) {
269696d6407fSRichard Henderson         /* Base register modification.  Make sure if RT == RB, we see
269796d6407fSRichard Henderson            the result of the load.  */
269896d6407fSRichard Henderson         dest = get_temp(ctx);
269996d6407fSRichard Henderson     } else {
270096d6407fSRichard Henderson         dest = dest_gpr(ctx, rt);
270196d6407fSRichard Henderson     }
270296d6407fSRichard Henderson 
270396d6407fSRichard Henderson     addr = tcg_temp_new();
270496d6407fSRichard Henderson     base = load_gpr(ctx, rb);
270596d6407fSRichard Henderson     if (rx) {
2706eaa3783bSRichard Henderson         tcg_gen_shli_reg(addr, cpu_gr[rx], scale);
2707eaa3783bSRichard Henderson         tcg_gen_add_reg(addr, addr, base);
270896d6407fSRichard Henderson     } else {
2709eaa3783bSRichard Henderson         tcg_gen_addi_reg(addr, base, disp);
271096d6407fSRichard Henderson     }
271196d6407fSRichard Henderson 
2712eaa3783bSRichard Henderson     zero = tcg_const_reg(0);
2713eaa3783bSRichard Henderson     tcg_gen_atomic_xchg_reg(dest, (modify <= 0 ? addr : base),
27143d68ee7bSRichard Henderson                             zero, ctx->mmu_idx, mop);
271596d6407fSRichard Henderson     if (modify) {
271696d6407fSRichard Henderson         save_gpr(ctx, rb, addr);
271796d6407fSRichard Henderson     }
271896d6407fSRichard Henderson     save_gpr(ctx, rt, dest);
271996d6407fSRichard Henderson 
2720869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
272196d6407fSRichard Henderson }
272296d6407fSRichard Henderson 
2723869051eaSRichard Henderson static DisasJumpType trans_stby(DisasContext *ctx, uint32_t insn,
272496d6407fSRichard Henderson                                 const DisasInsn *di)
272596d6407fSRichard Henderson {
2726eaa3783bSRichard Henderson     target_sreg disp = low_sextract(insn, 0, 5);
272796d6407fSRichard Henderson     unsigned m = extract32(insn, 5, 1);
272896d6407fSRichard Henderson     unsigned a = extract32(insn, 13, 1);
272996d6407fSRichard Henderson     unsigned rt = extract32(insn, 16, 5);
273096d6407fSRichard Henderson     unsigned rb = extract32(insn, 21, 5);
2731eaa3783bSRichard Henderson     TCGv_reg addr, val;
273296d6407fSRichard Henderson 
273396d6407fSRichard Henderson     nullify_over(ctx);
273496d6407fSRichard Henderson 
273596d6407fSRichard Henderson     addr = tcg_temp_new();
273696d6407fSRichard Henderson     if (m || disp == 0) {
2737eaa3783bSRichard Henderson         tcg_gen_mov_reg(addr, load_gpr(ctx, rb));
273896d6407fSRichard Henderson     } else {
2739eaa3783bSRichard Henderson         tcg_gen_addi_reg(addr, load_gpr(ctx, rb), disp);
274096d6407fSRichard Henderson     }
274196d6407fSRichard Henderson     val = load_gpr(ctx, rt);
274296d6407fSRichard Henderson 
274396d6407fSRichard Henderson     if (a) {
2744f9f46db4SEmilio G. Cota         if (tb_cflags(ctx->base.tb) & CF_PARALLEL) {
2745f9f46db4SEmilio G. Cota             gen_helper_stby_e_parallel(cpu_env, addr, val);
2746f9f46db4SEmilio G. Cota         } else {
274796d6407fSRichard Henderson             gen_helper_stby_e(cpu_env, addr, val);
2748f9f46db4SEmilio G. Cota         }
2749f9f46db4SEmilio G. Cota     } else {
2750f9f46db4SEmilio G. Cota         if (tb_cflags(ctx->base.tb) & CF_PARALLEL) {
2751f9f46db4SEmilio G. Cota             gen_helper_stby_b_parallel(cpu_env, addr, val);
275296d6407fSRichard Henderson         } else {
275396d6407fSRichard Henderson             gen_helper_stby_b(cpu_env, addr, val);
275496d6407fSRichard Henderson         }
2755f9f46db4SEmilio G. Cota     }
275696d6407fSRichard Henderson 
275796d6407fSRichard Henderson     if (m) {
2758eaa3783bSRichard Henderson         tcg_gen_addi_reg(addr, addr, disp);
2759eaa3783bSRichard Henderson         tcg_gen_andi_reg(addr, addr, ~3);
276096d6407fSRichard Henderson         save_gpr(ctx, rb, addr);
276196d6407fSRichard Henderson     }
276296d6407fSRichard Henderson     tcg_temp_free(addr);
276396d6407fSRichard Henderson 
2764869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
276596d6407fSRichard Henderson }
276696d6407fSRichard Henderson 
276796d6407fSRichard Henderson static const DisasInsn table_index_mem[] = {
276896d6407fSRichard Henderson     { 0x0c001000u, 0xfc001300, trans_ld_idx_i }, /* LD[BHWD], im */
276996d6407fSRichard Henderson     { 0x0c000000u, 0xfc001300, trans_ld_idx_x }, /* LD[BHWD], rx */
277096d6407fSRichard Henderson     { 0x0c001200u, 0xfc001300, trans_st_idx_i }, /* ST[BHWD] */
277196d6407fSRichard Henderson     { 0x0c0001c0u, 0xfc0003c0, trans_ldcw },
277296d6407fSRichard Henderson     { 0x0c001300u, 0xfc0013c0, trans_stby },
277396d6407fSRichard Henderson };
277496d6407fSRichard Henderson 
2775869051eaSRichard Henderson static DisasJumpType trans_ldil(DisasContext *ctx, uint32_t insn)
2776b2167459SRichard Henderson {
2777b2167459SRichard Henderson     unsigned rt = extract32(insn, 21, 5);
2778eaa3783bSRichard Henderson     target_sreg i = assemble_21(insn);
2779eaa3783bSRichard Henderson     TCGv_reg tcg_rt = dest_gpr(ctx, rt);
2780b2167459SRichard Henderson 
2781eaa3783bSRichard Henderson     tcg_gen_movi_reg(tcg_rt, i);
2782b2167459SRichard Henderson     save_gpr(ctx, rt, tcg_rt);
2783b2167459SRichard Henderson     cond_free(&ctx->null_cond);
2784b2167459SRichard Henderson 
2785869051eaSRichard Henderson     return DISAS_NEXT;
2786b2167459SRichard Henderson }
2787b2167459SRichard Henderson 
2788869051eaSRichard Henderson static DisasJumpType trans_addil(DisasContext *ctx, uint32_t insn)
2789b2167459SRichard Henderson {
2790b2167459SRichard Henderson     unsigned rt = extract32(insn, 21, 5);
2791eaa3783bSRichard Henderson     target_sreg i = assemble_21(insn);
2792eaa3783bSRichard Henderson     TCGv_reg tcg_rt = load_gpr(ctx, rt);
2793eaa3783bSRichard Henderson     TCGv_reg tcg_r1 = dest_gpr(ctx, 1);
2794b2167459SRichard Henderson 
2795eaa3783bSRichard Henderson     tcg_gen_addi_reg(tcg_r1, tcg_rt, i);
2796b2167459SRichard Henderson     save_gpr(ctx, 1, tcg_r1);
2797b2167459SRichard Henderson     cond_free(&ctx->null_cond);
2798b2167459SRichard Henderson 
2799869051eaSRichard Henderson     return DISAS_NEXT;
2800b2167459SRichard Henderson }
2801b2167459SRichard Henderson 
2802869051eaSRichard Henderson static DisasJumpType trans_ldo(DisasContext *ctx, uint32_t insn)
2803b2167459SRichard Henderson {
2804b2167459SRichard Henderson     unsigned rb = extract32(insn, 21, 5);
2805b2167459SRichard Henderson     unsigned rt = extract32(insn, 16, 5);
2806eaa3783bSRichard Henderson     target_sreg i = assemble_16(insn);
2807eaa3783bSRichard Henderson     TCGv_reg tcg_rt = dest_gpr(ctx, rt);
2808b2167459SRichard Henderson 
2809b2167459SRichard Henderson     /* Special case rb == 0, for the LDI pseudo-op.
2810b2167459SRichard Henderson        The COPY pseudo-op is handled for free within tcg_gen_addi_tl.  */
2811b2167459SRichard Henderson     if (rb == 0) {
2812eaa3783bSRichard Henderson         tcg_gen_movi_reg(tcg_rt, i);
2813b2167459SRichard Henderson     } else {
2814eaa3783bSRichard Henderson         tcg_gen_addi_reg(tcg_rt, cpu_gr[rb], i);
2815b2167459SRichard Henderson     }
2816b2167459SRichard Henderson     save_gpr(ctx, rt, tcg_rt);
2817b2167459SRichard Henderson     cond_free(&ctx->null_cond);
2818b2167459SRichard Henderson 
2819869051eaSRichard Henderson     return DISAS_NEXT;
2820b2167459SRichard Henderson }
2821b2167459SRichard Henderson 
2822869051eaSRichard Henderson static DisasJumpType trans_load(DisasContext *ctx, uint32_t insn,
282396d6407fSRichard Henderson                                 bool is_mod, TCGMemOp mop)
282496d6407fSRichard Henderson {
282596d6407fSRichard Henderson     unsigned rb = extract32(insn, 21, 5);
282696d6407fSRichard Henderson     unsigned rt = extract32(insn, 16, 5);
2827eaa3783bSRichard Henderson     target_sreg i = assemble_16(insn);
282896d6407fSRichard Henderson 
282996d6407fSRichard Henderson     return do_load(ctx, rt, rb, 0, 0, i, is_mod ? (i < 0 ? -1 : 1) : 0, mop);
283096d6407fSRichard Henderson }
283196d6407fSRichard Henderson 
2832869051eaSRichard Henderson static DisasJumpType trans_load_w(DisasContext *ctx, uint32_t insn)
283396d6407fSRichard Henderson {
283496d6407fSRichard Henderson     unsigned rb = extract32(insn, 21, 5);
283596d6407fSRichard Henderson     unsigned rt = extract32(insn, 16, 5);
2836eaa3783bSRichard Henderson     target_sreg i = assemble_16a(insn);
283796d6407fSRichard Henderson     unsigned ext2 = extract32(insn, 1, 2);
283896d6407fSRichard Henderson 
283996d6407fSRichard Henderson     switch (ext2) {
284096d6407fSRichard Henderson     case 0:
284196d6407fSRichard Henderson     case 1:
284296d6407fSRichard Henderson         /* FLDW without modification.  */
284396d6407fSRichard Henderson         return do_floadw(ctx, ext2 * 32 + rt, rb, 0, 0, i, 0);
284496d6407fSRichard Henderson     case 2:
284596d6407fSRichard Henderson         /* LDW with modification.  Note that the sign of I selects
284696d6407fSRichard Henderson            post-dec vs pre-inc.  */
284796d6407fSRichard Henderson         return do_load(ctx, rt, rb, 0, 0, i, (i < 0 ? 1 : -1), MO_TEUL);
284896d6407fSRichard Henderson     default:
284996d6407fSRichard Henderson         return gen_illegal(ctx);
285096d6407fSRichard Henderson     }
285196d6407fSRichard Henderson }
285296d6407fSRichard Henderson 
2853869051eaSRichard Henderson static DisasJumpType trans_fload_mod(DisasContext *ctx, uint32_t insn)
285496d6407fSRichard Henderson {
2855eaa3783bSRichard Henderson     target_sreg i = assemble_16a(insn);
285696d6407fSRichard Henderson     unsigned t1 = extract32(insn, 1, 1);
285796d6407fSRichard Henderson     unsigned a = extract32(insn, 2, 1);
285896d6407fSRichard Henderson     unsigned t0 = extract32(insn, 16, 5);
285996d6407fSRichard Henderson     unsigned rb = extract32(insn, 21, 5);
286096d6407fSRichard Henderson 
286196d6407fSRichard Henderson     /* FLDW with modification.  */
286296d6407fSRichard Henderson     return do_floadw(ctx, t1 * 32 + t0, rb, 0, 0, i, (a ? -1 : 1));
286396d6407fSRichard Henderson }
286496d6407fSRichard Henderson 
2865869051eaSRichard Henderson static DisasJumpType trans_store(DisasContext *ctx, uint32_t insn,
286696d6407fSRichard Henderson                                  bool is_mod, TCGMemOp mop)
286796d6407fSRichard Henderson {
286896d6407fSRichard Henderson     unsigned rb = extract32(insn, 21, 5);
286996d6407fSRichard Henderson     unsigned rt = extract32(insn, 16, 5);
2870eaa3783bSRichard Henderson     target_sreg i = assemble_16(insn);
287196d6407fSRichard Henderson 
287296d6407fSRichard Henderson     return do_store(ctx, rt, rb, i, is_mod ? (i < 0 ? -1 : 1) : 0, mop);
287396d6407fSRichard Henderson }
287496d6407fSRichard Henderson 
2875869051eaSRichard Henderson static DisasJumpType trans_store_w(DisasContext *ctx, uint32_t insn)
287696d6407fSRichard Henderson {
287796d6407fSRichard Henderson     unsigned rb = extract32(insn, 21, 5);
287896d6407fSRichard Henderson     unsigned rt = extract32(insn, 16, 5);
2879eaa3783bSRichard Henderson     target_sreg i = assemble_16a(insn);
288096d6407fSRichard Henderson     unsigned ext2 = extract32(insn, 1, 2);
288196d6407fSRichard Henderson 
288296d6407fSRichard Henderson     switch (ext2) {
288396d6407fSRichard Henderson     case 0:
288496d6407fSRichard Henderson     case 1:
288596d6407fSRichard Henderson         /* FSTW without modification.  */
288696d6407fSRichard Henderson         return do_fstorew(ctx, ext2 * 32 + rt, rb, 0, 0, i, 0);
288796d6407fSRichard Henderson     case 2:
288896d6407fSRichard Henderson         /* LDW with modification.  */
288996d6407fSRichard Henderson         return do_store(ctx, rt, rb, i, (i < 0 ? 1 : -1), MO_TEUL);
289096d6407fSRichard Henderson     default:
289196d6407fSRichard Henderson         return gen_illegal(ctx);
289296d6407fSRichard Henderson     }
289396d6407fSRichard Henderson }
289496d6407fSRichard Henderson 
2895869051eaSRichard Henderson static DisasJumpType trans_fstore_mod(DisasContext *ctx, uint32_t insn)
289696d6407fSRichard Henderson {
2897eaa3783bSRichard Henderson     target_sreg i = assemble_16a(insn);
289896d6407fSRichard Henderson     unsigned t1 = extract32(insn, 1, 1);
289996d6407fSRichard Henderson     unsigned a = extract32(insn, 2, 1);
290096d6407fSRichard Henderson     unsigned t0 = extract32(insn, 16, 5);
290196d6407fSRichard Henderson     unsigned rb = extract32(insn, 21, 5);
290296d6407fSRichard Henderson 
290396d6407fSRichard Henderson     /* FSTW with modification.  */
290496d6407fSRichard Henderson     return do_fstorew(ctx, t1 * 32 + t0, rb, 0, 0, i, (a ? -1 : 1));
290596d6407fSRichard Henderson }
290696d6407fSRichard Henderson 
2907869051eaSRichard Henderson static DisasJumpType trans_copr_w(DisasContext *ctx, uint32_t insn)
290896d6407fSRichard Henderson {
290996d6407fSRichard Henderson     unsigned t0 = extract32(insn, 0, 5);
291096d6407fSRichard Henderson     unsigned m = extract32(insn, 5, 1);
291196d6407fSRichard Henderson     unsigned t1 = extract32(insn, 6, 1);
291296d6407fSRichard Henderson     unsigned ext3 = extract32(insn, 7, 3);
291396d6407fSRichard Henderson     /* unsigned cc = extract32(insn, 10, 2); */
291496d6407fSRichard Henderson     unsigned i = extract32(insn, 12, 1);
291596d6407fSRichard Henderson     unsigned ua = extract32(insn, 13, 1);
291696d6407fSRichard Henderson     unsigned rx = extract32(insn, 16, 5);
291796d6407fSRichard Henderson     unsigned rb = extract32(insn, 21, 5);
291896d6407fSRichard Henderson     unsigned rt = t1 * 32 + t0;
291996d6407fSRichard Henderson     int modify = (m ? (ua ? -1 : 1) : 0);
292096d6407fSRichard Henderson     int disp, scale;
292196d6407fSRichard Henderson 
292296d6407fSRichard Henderson     if (i == 0) {
292396d6407fSRichard Henderson         scale = (ua ? 2 : 0);
292496d6407fSRichard Henderson         disp = 0;
292596d6407fSRichard Henderson         modify = m;
292696d6407fSRichard Henderson     } else {
292796d6407fSRichard Henderson         disp = low_sextract(rx, 0, 5);
292896d6407fSRichard Henderson         scale = 0;
292996d6407fSRichard Henderson         rx = 0;
293096d6407fSRichard Henderson         modify = (m ? (ua ? -1 : 1) : 0);
293196d6407fSRichard Henderson     }
293296d6407fSRichard Henderson 
293396d6407fSRichard Henderson     switch (ext3) {
293496d6407fSRichard Henderson     case 0: /* FLDW */
293596d6407fSRichard Henderson         return do_floadw(ctx, rt, rb, rx, scale, disp, modify);
293696d6407fSRichard Henderson     case 4: /* FSTW */
293796d6407fSRichard Henderson         return do_fstorew(ctx, rt, rb, rx, scale, disp, modify);
293896d6407fSRichard Henderson     }
293996d6407fSRichard Henderson     return gen_illegal(ctx);
294096d6407fSRichard Henderson }
294196d6407fSRichard Henderson 
2942869051eaSRichard Henderson static DisasJumpType trans_copr_dw(DisasContext *ctx, uint32_t insn)
294396d6407fSRichard Henderson {
294496d6407fSRichard Henderson     unsigned rt = extract32(insn, 0, 5);
294596d6407fSRichard Henderson     unsigned m = extract32(insn, 5, 1);
294696d6407fSRichard Henderson     unsigned ext4 = extract32(insn, 6, 4);
294796d6407fSRichard Henderson     /* unsigned cc = extract32(insn, 10, 2); */
294896d6407fSRichard Henderson     unsigned i = extract32(insn, 12, 1);
294996d6407fSRichard Henderson     unsigned ua = extract32(insn, 13, 1);
295096d6407fSRichard Henderson     unsigned rx = extract32(insn, 16, 5);
295196d6407fSRichard Henderson     unsigned rb = extract32(insn, 21, 5);
295296d6407fSRichard Henderson     int modify = (m ? (ua ? -1 : 1) : 0);
295396d6407fSRichard Henderson     int disp, scale;
295496d6407fSRichard Henderson 
295596d6407fSRichard Henderson     if (i == 0) {
295696d6407fSRichard Henderson         scale = (ua ? 3 : 0);
295796d6407fSRichard Henderson         disp = 0;
295896d6407fSRichard Henderson         modify = m;
295996d6407fSRichard Henderson     } else {
296096d6407fSRichard Henderson         disp = low_sextract(rx, 0, 5);
296196d6407fSRichard Henderson         scale = 0;
296296d6407fSRichard Henderson         rx = 0;
296396d6407fSRichard Henderson         modify = (m ? (ua ? -1 : 1) : 0);
296496d6407fSRichard Henderson     }
296596d6407fSRichard Henderson 
296696d6407fSRichard Henderson     switch (ext4) {
296796d6407fSRichard Henderson     case 0: /* FLDD */
296896d6407fSRichard Henderson         return do_floadd(ctx, rt, rb, rx, scale, disp, modify);
296996d6407fSRichard Henderson     case 8: /* FSTD */
297096d6407fSRichard Henderson         return do_fstored(ctx, rt, rb, rx, scale, disp, modify);
297196d6407fSRichard Henderson     default:
297296d6407fSRichard Henderson         return gen_illegal(ctx);
297396d6407fSRichard Henderson     }
297496d6407fSRichard Henderson }
297596d6407fSRichard Henderson 
2976869051eaSRichard Henderson static DisasJumpType trans_cmpb(DisasContext *ctx, uint32_t insn,
297798cd9ca7SRichard Henderson                                 bool is_true, bool is_imm, bool is_dw)
297898cd9ca7SRichard Henderson {
2979eaa3783bSRichard Henderson     target_sreg disp = assemble_12(insn) * 4;
298098cd9ca7SRichard Henderson     unsigned n = extract32(insn, 1, 1);
298198cd9ca7SRichard Henderson     unsigned c = extract32(insn, 13, 3);
298298cd9ca7SRichard Henderson     unsigned r = extract32(insn, 21, 5);
298398cd9ca7SRichard Henderson     unsigned cf = c * 2 + !is_true;
2984eaa3783bSRichard Henderson     TCGv_reg dest, in1, in2, sv;
298598cd9ca7SRichard Henderson     DisasCond cond;
298698cd9ca7SRichard Henderson 
298798cd9ca7SRichard Henderson     nullify_over(ctx);
298898cd9ca7SRichard Henderson 
298998cd9ca7SRichard Henderson     if (is_imm) {
299098cd9ca7SRichard Henderson         in1 = load_const(ctx, low_sextract(insn, 16, 5));
299198cd9ca7SRichard Henderson     } else {
299298cd9ca7SRichard Henderson         in1 = load_gpr(ctx, extract32(insn, 16, 5));
299398cd9ca7SRichard Henderson     }
299498cd9ca7SRichard Henderson     in2 = load_gpr(ctx, r);
299598cd9ca7SRichard Henderson     dest = get_temp(ctx);
299698cd9ca7SRichard Henderson 
2997eaa3783bSRichard Henderson     tcg_gen_sub_reg(dest, in1, in2);
299898cd9ca7SRichard Henderson 
2999f764718dSRichard Henderson     sv = NULL;
300098cd9ca7SRichard Henderson     if (c == 6) {
300198cd9ca7SRichard Henderson         sv = do_sub_sv(ctx, dest, in1, in2);
300298cd9ca7SRichard Henderson     }
300398cd9ca7SRichard Henderson 
300498cd9ca7SRichard Henderson     cond = do_sub_cond(cf, dest, in1, in2, sv);
300598cd9ca7SRichard Henderson     return do_cbranch(ctx, disp, n, &cond);
300698cd9ca7SRichard Henderson }
300798cd9ca7SRichard Henderson 
3008869051eaSRichard Henderson static DisasJumpType trans_addb(DisasContext *ctx, uint32_t insn,
300998cd9ca7SRichard Henderson                                 bool is_true, bool is_imm)
301098cd9ca7SRichard Henderson {
3011eaa3783bSRichard Henderson     target_sreg disp = assemble_12(insn) * 4;
301298cd9ca7SRichard Henderson     unsigned n = extract32(insn, 1, 1);
301398cd9ca7SRichard Henderson     unsigned c = extract32(insn, 13, 3);
301498cd9ca7SRichard Henderson     unsigned r = extract32(insn, 21, 5);
301598cd9ca7SRichard Henderson     unsigned cf = c * 2 + !is_true;
3016eaa3783bSRichard Henderson     TCGv_reg dest, in1, in2, sv, cb_msb;
301798cd9ca7SRichard Henderson     DisasCond cond;
301898cd9ca7SRichard Henderson 
301998cd9ca7SRichard Henderson     nullify_over(ctx);
302098cd9ca7SRichard Henderson 
302198cd9ca7SRichard Henderson     if (is_imm) {
302298cd9ca7SRichard Henderson         in1 = load_const(ctx, low_sextract(insn, 16, 5));
302398cd9ca7SRichard Henderson     } else {
302498cd9ca7SRichard Henderson         in1 = load_gpr(ctx, extract32(insn, 16, 5));
302598cd9ca7SRichard Henderson     }
302698cd9ca7SRichard Henderson     in2 = load_gpr(ctx, r);
302798cd9ca7SRichard Henderson     dest = dest_gpr(ctx, r);
3028f764718dSRichard Henderson     sv = NULL;
3029f764718dSRichard Henderson     cb_msb = NULL;
303098cd9ca7SRichard Henderson 
303198cd9ca7SRichard Henderson     switch (c) {
303298cd9ca7SRichard Henderson     default:
3033eaa3783bSRichard Henderson         tcg_gen_add_reg(dest, in1, in2);
303498cd9ca7SRichard Henderson         break;
303598cd9ca7SRichard Henderson     case 4: case 5:
303698cd9ca7SRichard Henderson         cb_msb = get_temp(ctx);
3037eaa3783bSRichard Henderson         tcg_gen_movi_reg(cb_msb, 0);
3038eaa3783bSRichard Henderson         tcg_gen_add2_reg(dest, cb_msb, in1, cb_msb, in2, cb_msb);
303998cd9ca7SRichard Henderson         break;
304098cd9ca7SRichard Henderson     case 6:
3041eaa3783bSRichard Henderson         tcg_gen_add_reg(dest, in1, in2);
304298cd9ca7SRichard Henderson         sv = do_add_sv(ctx, dest, in1, in2);
304398cd9ca7SRichard Henderson         break;
304498cd9ca7SRichard Henderson     }
304598cd9ca7SRichard Henderson 
304698cd9ca7SRichard Henderson     cond = do_cond(cf, dest, cb_msb, sv);
304798cd9ca7SRichard Henderson     return do_cbranch(ctx, disp, n, &cond);
304898cd9ca7SRichard Henderson }
304998cd9ca7SRichard Henderson 
3050869051eaSRichard Henderson static DisasJumpType trans_bb(DisasContext *ctx, uint32_t insn)
305198cd9ca7SRichard Henderson {
3052eaa3783bSRichard Henderson     target_sreg disp = assemble_12(insn) * 4;
305398cd9ca7SRichard Henderson     unsigned n = extract32(insn, 1, 1);
305498cd9ca7SRichard Henderson     unsigned c = extract32(insn, 15, 1);
305598cd9ca7SRichard Henderson     unsigned r = extract32(insn, 16, 5);
305698cd9ca7SRichard Henderson     unsigned p = extract32(insn, 21, 5);
305798cd9ca7SRichard Henderson     unsigned i = extract32(insn, 26, 1);
3058eaa3783bSRichard Henderson     TCGv_reg tmp, tcg_r;
305998cd9ca7SRichard Henderson     DisasCond cond;
306098cd9ca7SRichard Henderson 
306198cd9ca7SRichard Henderson     nullify_over(ctx);
306298cd9ca7SRichard Henderson 
306398cd9ca7SRichard Henderson     tmp = tcg_temp_new();
306498cd9ca7SRichard Henderson     tcg_r = load_gpr(ctx, r);
306598cd9ca7SRichard Henderson     if (i) {
3066eaa3783bSRichard Henderson         tcg_gen_shli_reg(tmp, tcg_r, p);
306798cd9ca7SRichard Henderson     } else {
3068eaa3783bSRichard Henderson         tcg_gen_shl_reg(tmp, tcg_r, cpu_sar);
306998cd9ca7SRichard Henderson     }
307098cd9ca7SRichard Henderson 
307198cd9ca7SRichard Henderson     cond = cond_make_0(c ? TCG_COND_GE : TCG_COND_LT, tmp);
307298cd9ca7SRichard Henderson     tcg_temp_free(tmp);
307398cd9ca7SRichard Henderson     return do_cbranch(ctx, disp, n, &cond);
307498cd9ca7SRichard Henderson }
307598cd9ca7SRichard Henderson 
3076869051eaSRichard Henderson static DisasJumpType trans_movb(DisasContext *ctx, uint32_t insn, bool is_imm)
307798cd9ca7SRichard Henderson {
3078eaa3783bSRichard Henderson     target_sreg disp = assemble_12(insn) * 4;
307998cd9ca7SRichard Henderson     unsigned n = extract32(insn, 1, 1);
308098cd9ca7SRichard Henderson     unsigned c = extract32(insn, 13, 3);
308198cd9ca7SRichard Henderson     unsigned t = extract32(insn, 16, 5);
308298cd9ca7SRichard Henderson     unsigned r = extract32(insn, 21, 5);
3083eaa3783bSRichard Henderson     TCGv_reg dest;
308498cd9ca7SRichard Henderson     DisasCond cond;
308598cd9ca7SRichard Henderson 
308698cd9ca7SRichard Henderson     nullify_over(ctx);
308798cd9ca7SRichard Henderson 
308898cd9ca7SRichard Henderson     dest = dest_gpr(ctx, r);
308998cd9ca7SRichard Henderson     if (is_imm) {
3090eaa3783bSRichard Henderson         tcg_gen_movi_reg(dest, low_sextract(t, 0, 5));
309198cd9ca7SRichard Henderson     } else if (t == 0) {
3092eaa3783bSRichard Henderson         tcg_gen_movi_reg(dest, 0);
309398cd9ca7SRichard Henderson     } else {
3094eaa3783bSRichard Henderson         tcg_gen_mov_reg(dest, cpu_gr[t]);
309598cd9ca7SRichard Henderson     }
309698cd9ca7SRichard Henderson 
309798cd9ca7SRichard Henderson     cond = do_sed_cond(c, dest);
309898cd9ca7SRichard Henderson     return do_cbranch(ctx, disp, n, &cond);
309998cd9ca7SRichard Henderson }
310098cd9ca7SRichard Henderson 
3101869051eaSRichard Henderson static DisasJumpType trans_shrpw_sar(DisasContext *ctx, uint32_t insn,
31020b1347d2SRichard Henderson                                     const DisasInsn *di)
31030b1347d2SRichard Henderson {
31040b1347d2SRichard Henderson     unsigned rt = extract32(insn, 0, 5);
31050b1347d2SRichard Henderson     unsigned c = extract32(insn, 13, 3);
31060b1347d2SRichard Henderson     unsigned r1 = extract32(insn, 16, 5);
31070b1347d2SRichard Henderson     unsigned r2 = extract32(insn, 21, 5);
3108eaa3783bSRichard Henderson     TCGv_reg dest;
31090b1347d2SRichard Henderson 
31100b1347d2SRichard Henderson     if (c) {
31110b1347d2SRichard Henderson         nullify_over(ctx);
31120b1347d2SRichard Henderson     }
31130b1347d2SRichard Henderson 
31140b1347d2SRichard Henderson     dest = dest_gpr(ctx, rt);
31150b1347d2SRichard Henderson     if (r1 == 0) {
3116eaa3783bSRichard Henderson         tcg_gen_ext32u_reg(dest, load_gpr(ctx, r2));
3117eaa3783bSRichard Henderson         tcg_gen_shr_reg(dest, dest, cpu_sar);
31180b1347d2SRichard Henderson     } else if (r1 == r2) {
31190b1347d2SRichard Henderson         TCGv_i32 t32 = tcg_temp_new_i32();
3120eaa3783bSRichard Henderson         tcg_gen_trunc_reg_i32(t32, load_gpr(ctx, r2));
31210b1347d2SRichard Henderson         tcg_gen_rotr_i32(t32, t32, cpu_sar);
3122eaa3783bSRichard Henderson         tcg_gen_extu_i32_reg(dest, t32);
31230b1347d2SRichard Henderson         tcg_temp_free_i32(t32);
31240b1347d2SRichard Henderson     } else {
31250b1347d2SRichard Henderson         TCGv_i64 t = tcg_temp_new_i64();
31260b1347d2SRichard Henderson         TCGv_i64 s = tcg_temp_new_i64();
31270b1347d2SRichard Henderson 
3128eaa3783bSRichard Henderson         tcg_gen_concat_reg_i64(t, load_gpr(ctx, r2), load_gpr(ctx, r1));
3129eaa3783bSRichard Henderson         tcg_gen_extu_reg_i64(s, cpu_sar);
31300b1347d2SRichard Henderson         tcg_gen_shr_i64(t, t, s);
3131eaa3783bSRichard Henderson         tcg_gen_trunc_i64_reg(dest, t);
31320b1347d2SRichard Henderson 
31330b1347d2SRichard Henderson         tcg_temp_free_i64(t);
31340b1347d2SRichard Henderson         tcg_temp_free_i64(s);
31350b1347d2SRichard Henderson     }
31360b1347d2SRichard Henderson     save_gpr(ctx, rt, dest);
31370b1347d2SRichard Henderson 
31380b1347d2SRichard Henderson     /* Install the new nullification.  */
31390b1347d2SRichard Henderson     cond_free(&ctx->null_cond);
31400b1347d2SRichard Henderson     if (c) {
31410b1347d2SRichard Henderson         ctx->null_cond = do_sed_cond(c, dest);
31420b1347d2SRichard Henderson     }
3143869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
31440b1347d2SRichard Henderson }
31450b1347d2SRichard Henderson 
3146869051eaSRichard Henderson static DisasJumpType trans_shrpw_imm(DisasContext *ctx, uint32_t insn,
31470b1347d2SRichard Henderson                                      const DisasInsn *di)
31480b1347d2SRichard Henderson {
31490b1347d2SRichard Henderson     unsigned rt = extract32(insn, 0, 5);
31500b1347d2SRichard Henderson     unsigned cpos = extract32(insn, 5, 5);
31510b1347d2SRichard Henderson     unsigned c = extract32(insn, 13, 3);
31520b1347d2SRichard Henderson     unsigned r1 = extract32(insn, 16, 5);
31530b1347d2SRichard Henderson     unsigned r2 = extract32(insn, 21, 5);
31540b1347d2SRichard Henderson     unsigned sa = 31 - cpos;
3155eaa3783bSRichard Henderson     TCGv_reg dest, t2;
31560b1347d2SRichard Henderson 
31570b1347d2SRichard Henderson     if (c) {
31580b1347d2SRichard Henderson         nullify_over(ctx);
31590b1347d2SRichard Henderson     }
31600b1347d2SRichard Henderson 
31610b1347d2SRichard Henderson     dest = dest_gpr(ctx, rt);
31620b1347d2SRichard Henderson     t2 = load_gpr(ctx, r2);
31630b1347d2SRichard Henderson     if (r1 == r2) {
31640b1347d2SRichard Henderson         TCGv_i32 t32 = tcg_temp_new_i32();
3165eaa3783bSRichard Henderson         tcg_gen_trunc_reg_i32(t32, t2);
31660b1347d2SRichard Henderson         tcg_gen_rotri_i32(t32, t32, sa);
3167eaa3783bSRichard Henderson         tcg_gen_extu_i32_reg(dest, t32);
31680b1347d2SRichard Henderson         tcg_temp_free_i32(t32);
31690b1347d2SRichard Henderson     } else if (r1 == 0) {
3170eaa3783bSRichard Henderson         tcg_gen_extract_reg(dest, t2, sa, 32 - sa);
31710b1347d2SRichard Henderson     } else {
3172eaa3783bSRichard Henderson         TCGv_reg t0 = tcg_temp_new();
3173eaa3783bSRichard Henderson         tcg_gen_extract_reg(t0, t2, sa, 32 - sa);
3174eaa3783bSRichard Henderson         tcg_gen_deposit_reg(dest, t0, cpu_gr[r1], 32 - sa, sa);
31750b1347d2SRichard Henderson         tcg_temp_free(t0);
31760b1347d2SRichard Henderson     }
31770b1347d2SRichard Henderson     save_gpr(ctx, rt, dest);
31780b1347d2SRichard Henderson 
31790b1347d2SRichard Henderson     /* Install the new nullification.  */
31800b1347d2SRichard Henderson     cond_free(&ctx->null_cond);
31810b1347d2SRichard Henderson     if (c) {
31820b1347d2SRichard Henderson         ctx->null_cond = do_sed_cond(c, dest);
31830b1347d2SRichard Henderson     }
3184869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
31850b1347d2SRichard Henderson }
31860b1347d2SRichard Henderson 
3187869051eaSRichard Henderson static DisasJumpType trans_extrw_sar(DisasContext *ctx, uint32_t insn,
31880b1347d2SRichard Henderson                                      const DisasInsn *di)
31890b1347d2SRichard Henderson {
31900b1347d2SRichard Henderson     unsigned clen = extract32(insn, 0, 5);
31910b1347d2SRichard Henderson     unsigned is_se = extract32(insn, 10, 1);
31920b1347d2SRichard Henderson     unsigned c = extract32(insn, 13, 3);
31930b1347d2SRichard Henderson     unsigned rt = extract32(insn, 16, 5);
31940b1347d2SRichard Henderson     unsigned rr = extract32(insn, 21, 5);
31950b1347d2SRichard Henderson     unsigned len = 32 - clen;
3196eaa3783bSRichard Henderson     TCGv_reg dest, src, tmp;
31970b1347d2SRichard Henderson 
31980b1347d2SRichard Henderson     if (c) {
31990b1347d2SRichard Henderson         nullify_over(ctx);
32000b1347d2SRichard Henderson     }
32010b1347d2SRichard Henderson 
32020b1347d2SRichard Henderson     dest = dest_gpr(ctx, rt);
32030b1347d2SRichard Henderson     src = load_gpr(ctx, rr);
32040b1347d2SRichard Henderson     tmp = tcg_temp_new();
32050b1347d2SRichard Henderson 
32060b1347d2SRichard Henderson     /* Recall that SAR is using big-endian bit numbering.  */
3207eaa3783bSRichard Henderson     tcg_gen_xori_reg(tmp, cpu_sar, TARGET_REGISTER_BITS - 1);
32080b1347d2SRichard Henderson     if (is_se) {
3209eaa3783bSRichard Henderson         tcg_gen_sar_reg(dest, src, tmp);
3210eaa3783bSRichard Henderson         tcg_gen_sextract_reg(dest, dest, 0, len);
32110b1347d2SRichard Henderson     } else {
3212eaa3783bSRichard Henderson         tcg_gen_shr_reg(dest, src, tmp);
3213eaa3783bSRichard Henderson         tcg_gen_extract_reg(dest, dest, 0, len);
32140b1347d2SRichard Henderson     }
32150b1347d2SRichard Henderson     tcg_temp_free(tmp);
32160b1347d2SRichard Henderson     save_gpr(ctx, rt, dest);
32170b1347d2SRichard Henderson 
32180b1347d2SRichard Henderson     /* Install the new nullification.  */
32190b1347d2SRichard Henderson     cond_free(&ctx->null_cond);
32200b1347d2SRichard Henderson     if (c) {
32210b1347d2SRichard Henderson         ctx->null_cond = do_sed_cond(c, dest);
32220b1347d2SRichard Henderson     }
3223869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
32240b1347d2SRichard Henderson }
32250b1347d2SRichard Henderson 
3226869051eaSRichard Henderson static DisasJumpType trans_extrw_imm(DisasContext *ctx, uint32_t insn,
32270b1347d2SRichard Henderson                                      const DisasInsn *di)
32280b1347d2SRichard Henderson {
32290b1347d2SRichard Henderson     unsigned clen = extract32(insn, 0, 5);
32300b1347d2SRichard Henderson     unsigned pos = extract32(insn, 5, 5);
32310b1347d2SRichard Henderson     unsigned is_se = extract32(insn, 10, 1);
32320b1347d2SRichard Henderson     unsigned c = extract32(insn, 13, 3);
32330b1347d2SRichard Henderson     unsigned rt = extract32(insn, 16, 5);
32340b1347d2SRichard Henderson     unsigned rr = extract32(insn, 21, 5);
32350b1347d2SRichard Henderson     unsigned len = 32 - clen;
32360b1347d2SRichard Henderson     unsigned cpos = 31 - pos;
3237eaa3783bSRichard Henderson     TCGv_reg dest, src;
32380b1347d2SRichard Henderson 
32390b1347d2SRichard Henderson     if (c) {
32400b1347d2SRichard Henderson         nullify_over(ctx);
32410b1347d2SRichard Henderson     }
32420b1347d2SRichard Henderson 
32430b1347d2SRichard Henderson     dest = dest_gpr(ctx, rt);
32440b1347d2SRichard Henderson     src = load_gpr(ctx, rr);
32450b1347d2SRichard Henderson     if (is_se) {
3246eaa3783bSRichard Henderson         tcg_gen_sextract_reg(dest, src, cpos, len);
32470b1347d2SRichard Henderson     } else {
3248eaa3783bSRichard Henderson         tcg_gen_extract_reg(dest, src, cpos, len);
32490b1347d2SRichard Henderson     }
32500b1347d2SRichard Henderson     save_gpr(ctx, rt, dest);
32510b1347d2SRichard Henderson 
32520b1347d2SRichard Henderson     /* Install the new nullification.  */
32530b1347d2SRichard Henderson     cond_free(&ctx->null_cond);
32540b1347d2SRichard Henderson     if (c) {
32550b1347d2SRichard Henderson         ctx->null_cond = do_sed_cond(c, dest);
32560b1347d2SRichard Henderson     }
3257869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
32580b1347d2SRichard Henderson }
32590b1347d2SRichard Henderson 
32600b1347d2SRichard Henderson static const DisasInsn table_sh_ex[] = {
32610b1347d2SRichard Henderson     { 0xd0000000u, 0xfc001fe0u, trans_shrpw_sar },
32620b1347d2SRichard Henderson     { 0xd0000800u, 0xfc001c00u, trans_shrpw_imm },
32630b1347d2SRichard Henderson     { 0xd0001000u, 0xfc001be0u, trans_extrw_sar },
32640b1347d2SRichard Henderson     { 0xd0001800u, 0xfc001800u, trans_extrw_imm },
32650b1347d2SRichard Henderson };
32660b1347d2SRichard Henderson 
3267869051eaSRichard Henderson static DisasJumpType trans_depw_imm_c(DisasContext *ctx, uint32_t insn,
32680b1347d2SRichard Henderson                                       const DisasInsn *di)
32690b1347d2SRichard Henderson {
32700b1347d2SRichard Henderson     unsigned clen = extract32(insn, 0, 5);
32710b1347d2SRichard Henderson     unsigned cpos = extract32(insn, 5, 5);
32720b1347d2SRichard Henderson     unsigned nz = extract32(insn, 10, 1);
32730b1347d2SRichard Henderson     unsigned c = extract32(insn, 13, 3);
3274eaa3783bSRichard Henderson     target_sreg val = low_sextract(insn, 16, 5);
32750b1347d2SRichard Henderson     unsigned rt = extract32(insn, 21, 5);
32760b1347d2SRichard Henderson     unsigned len = 32 - clen;
3277eaa3783bSRichard Henderson     target_sreg mask0, mask1;
3278eaa3783bSRichard Henderson     TCGv_reg dest;
32790b1347d2SRichard Henderson 
32800b1347d2SRichard Henderson     if (c) {
32810b1347d2SRichard Henderson         nullify_over(ctx);
32820b1347d2SRichard Henderson     }
32830b1347d2SRichard Henderson     if (cpos + len > 32) {
32840b1347d2SRichard Henderson         len = 32 - cpos;
32850b1347d2SRichard Henderson     }
32860b1347d2SRichard Henderson 
32870b1347d2SRichard Henderson     dest = dest_gpr(ctx, rt);
32880b1347d2SRichard Henderson     mask0 = deposit64(0, cpos, len, val);
32890b1347d2SRichard Henderson     mask1 = deposit64(-1, cpos, len, val);
32900b1347d2SRichard Henderson 
32910b1347d2SRichard Henderson     if (nz) {
3292eaa3783bSRichard Henderson         TCGv_reg src = load_gpr(ctx, rt);
32930b1347d2SRichard Henderson         if (mask1 != -1) {
3294eaa3783bSRichard Henderson             tcg_gen_andi_reg(dest, src, mask1);
32950b1347d2SRichard Henderson             src = dest;
32960b1347d2SRichard Henderson         }
3297eaa3783bSRichard Henderson         tcg_gen_ori_reg(dest, src, mask0);
32980b1347d2SRichard Henderson     } else {
3299eaa3783bSRichard Henderson         tcg_gen_movi_reg(dest, mask0);
33000b1347d2SRichard Henderson     }
33010b1347d2SRichard Henderson     save_gpr(ctx, rt, dest);
33020b1347d2SRichard Henderson 
33030b1347d2SRichard Henderson     /* Install the new nullification.  */
33040b1347d2SRichard Henderson     cond_free(&ctx->null_cond);
33050b1347d2SRichard Henderson     if (c) {
33060b1347d2SRichard Henderson         ctx->null_cond = do_sed_cond(c, dest);
33070b1347d2SRichard Henderson     }
3308869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
33090b1347d2SRichard Henderson }
33100b1347d2SRichard Henderson 
3311869051eaSRichard Henderson static DisasJumpType trans_depw_imm(DisasContext *ctx, uint32_t insn,
33120b1347d2SRichard Henderson                                     const DisasInsn *di)
33130b1347d2SRichard Henderson {
33140b1347d2SRichard Henderson     unsigned clen = extract32(insn, 0, 5);
33150b1347d2SRichard Henderson     unsigned cpos = extract32(insn, 5, 5);
33160b1347d2SRichard Henderson     unsigned nz = extract32(insn, 10, 1);
33170b1347d2SRichard Henderson     unsigned c = extract32(insn, 13, 3);
33180b1347d2SRichard Henderson     unsigned rr = extract32(insn, 16, 5);
33190b1347d2SRichard Henderson     unsigned rt = extract32(insn, 21, 5);
33200b1347d2SRichard Henderson     unsigned rs = nz ? rt : 0;
33210b1347d2SRichard Henderson     unsigned len = 32 - clen;
3322eaa3783bSRichard Henderson     TCGv_reg dest, val;
33230b1347d2SRichard Henderson 
33240b1347d2SRichard Henderson     if (c) {
33250b1347d2SRichard Henderson         nullify_over(ctx);
33260b1347d2SRichard Henderson     }
33270b1347d2SRichard Henderson     if (cpos + len > 32) {
33280b1347d2SRichard Henderson         len = 32 - cpos;
33290b1347d2SRichard Henderson     }
33300b1347d2SRichard Henderson 
33310b1347d2SRichard Henderson     dest = dest_gpr(ctx, rt);
33320b1347d2SRichard Henderson     val = load_gpr(ctx, rr);
33330b1347d2SRichard Henderson     if (rs == 0) {
3334eaa3783bSRichard Henderson         tcg_gen_deposit_z_reg(dest, val, cpos, len);
33350b1347d2SRichard Henderson     } else {
3336eaa3783bSRichard Henderson         tcg_gen_deposit_reg(dest, cpu_gr[rs], val, cpos, len);
33370b1347d2SRichard Henderson     }
33380b1347d2SRichard Henderson     save_gpr(ctx, rt, dest);
33390b1347d2SRichard Henderson 
33400b1347d2SRichard Henderson     /* Install the new nullification.  */
33410b1347d2SRichard Henderson     cond_free(&ctx->null_cond);
33420b1347d2SRichard Henderson     if (c) {
33430b1347d2SRichard Henderson         ctx->null_cond = do_sed_cond(c, dest);
33440b1347d2SRichard Henderson     }
3345869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
33460b1347d2SRichard Henderson }
33470b1347d2SRichard Henderson 
3348869051eaSRichard Henderson static DisasJumpType trans_depw_sar(DisasContext *ctx, uint32_t insn,
33490b1347d2SRichard Henderson                                     const DisasInsn *di)
33500b1347d2SRichard Henderson {
33510b1347d2SRichard Henderson     unsigned clen = extract32(insn, 0, 5);
33520b1347d2SRichard Henderson     unsigned nz = extract32(insn, 10, 1);
33530b1347d2SRichard Henderson     unsigned i = extract32(insn, 12, 1);
33540b1347d2SRichard Henderson     unsigned c = extract32(insn, 13, 3);
33550b1347d2SRichard Henderson     unsigned rt = extract32(insn, 21, 5);
33560b1347d2SRichard Henderson     unsigned rs = nz ? rt : 0;
33570b1347d2SRichard Henderson     unsigned len = 32 - clen;
3358eaa3783bSRichard Henderson     TCGv_reg val, mask, tmp, shift, dest;
33590b1347d2SRichard Henderson     unsigned msb = 1U << (len - 1);
33600b1347d2SRichard Henderson 
33610b1347d2SRichard Henderson     if (c) {
33620b1347d2SRichard Henderson         nullify_over(ctx);
33630b1347d2SRichard Henderson     }
33640b1347d2SRichard Henderson 
33650b1347d2SRichard Henderson     if (i) {
33660b1347d2SRichard Henderson         val = load_const(ctx, low_sextract(insn, 16, 5));
33670b1347d2SRichard Henderson     } else {
33680b1347d2SRichard Henderson         val = load_gpr(ctx, extract32(insn, 16, 5));
33690b1347d2SRichard Henderson     }
33700b1347d2SRichard Henderson     dest = dest_gpr(ctx, rt);
33710b1347d2SRichard Henderson     shift = tcg_temp_new();
33720b1347d2SRichard Henderson     tmp = tcg_temp_new();
33730b1347d2SRichard Henderson 
33740b1347d2SRichard Henderson     /* Convert big-endian bit numbering in SAR to left-shift.  */
3375eaa3783bSRichard Henderson     tcg_gen_xori_reg(shift, cpu_sar, TARGET_REGISTER_BITS - 1);
33760b1347d2SRichard Henderson 
3377eaa3783bSRichard Henderson     mask = tcg_const_reg(msb + (msb - 1));
3378eaa3783bSRichard Henderson     tcg_gen_and_reg(tmp, val, mask);
33790b1347d2SRichard Henderson     if (rs) {
3380eaa3783bSRichard Henderson         tcg_gen_shl_reg(mask, mask, shift);
3381eaa3783bSRichard Henderson         tcg_gen_shl_reg(tmp, tmp, shift);
3382eaa3783bSRichard Henderson         tcg_gen_andc_reg(dest, cpu_gr[rs], mask);
3383eaa3783bSRichard Henderson         tcg_gen_or_reg(dest, dest, tmp);
33840b1347d2SRichard Henderson     } else {
3385eaa3783bSRichard Henderson         tcg_gen_shl_reg(dest, tmp, shift);
33860b1347d2SRichard Henderson     }
33870b1347d2SRichard Henderson     tcg_temp_free(shift);
33880b1347d2SRichard Henderson     tcg_temp_free(mask);
33890b1347d2SRichard Henderson     tcg_temp_free(tmp);
33900b1347d2SRichard Henderson     save_gpr(ctx, rt, dest);
33910b1347d2SRichard Henderson 
33920b1347d2SRichard Henderson     /* Install the new nullification.  */
33930b1347d2SRichard Henderson     cond_free(&ctx->null_cond);
33940b1347d2SRichard Henderson     if (c) {
33950b1347d2SRichard Henderson         ctx->null_cond = do_sed_cond(c, dest);
33960b1347d2SRichard Henderson     }
3397869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
33980b1347d2SRichard Henderson }
33990b1347d2SRichard Henderson 
34000b1347d2SRichard Henderson static const DisasInsn table_depw[] = {
34010b1347d2SRichard Henderson     { 0xd4000000u, 0xfc000be0u, trans_depw_sar },
34020b1347d2SRichard Henderson     { 0xd4000800u, 0xfc001800u, trans_depw_imm },
34030b1347d2SRichard Henderson     { 0xd4001800u, 0xfc001800u, trans_depw_imm_c },
34040b1347d2SRichard Henderson };
34050b1347d2SRichard Henderson 
3406869051eaSRichard Henderson static DisasJumpType trans_be(DisasContext *ctx, uint32_t insn, bool is_l)
340798cd9ca7SRichard Henderson {
340898cd9ca7SRichard Henderson     unsigned n = extract32(insn, 1, 1);
340998cd9ca7SRichard Henderson     unsigned b = extract32(insn, 21, 5);
3410eaa3783bSRichard Henderson     target_sreg disp = assemble_17(insn);
341198cd9ca7SRichard Henderson 
341298cd9ca7SRichard Henderson     /* unsigned s = low_uextract(insn, 13, 3); */
341398cd9ca7SRichard Henderson     /* ??? It seems like there should be a good way of using
341498cd9ca7SRichard Henderson        "be disp(sr2, r0)", the canonical gateway entry mechanism
341598cd9ca7SRichard Henderson        to our advantage.  But that appears to be inconvenient to
341698cd9ca7SRichard Henderson        manage along side branch delay slots.  Therefore we handle
341798cd9ca7SRichard Henderson        entry into the gateway page via absolute address.  */
341898cd9ca7SRichard Henderson 
341998cd9ca7SRichard Henderson     /* Since we don't implement spaces, just branch.  Do notice the special
342098cd9ca7SRichard Henderson        case of "be disp(*,r0)" using a direct branch to disp, so that we can
342198cd9ca7SRichard Henderson        goto_tb to the TB containing the syscall.  */
342298cd9ca7SRichard Henderson     if (b == 0) {
342398cd9ca7SRichard Henderson         return do_dbranch(ctx, disp, is_l ? 31 : 0, n);
342498cd9ca7SRichard Henderson     } else {
3425eaa3783bSRichard Henderson         TCGv_reg tmp = get_temp(ctx);
3426eaa3783bSRichard Henderson         tcg_gen_addi_reg(tmp, load_gpr(ctx, b), disp);
342798cd9ca7SRichard Henderson         return do_ibranch(ctx, tmp, is_l ? 31 : 0, n);
342898cd9ca7SRichard Henderson     }
342998cd9ca7SRichard Henderson }
343098cd9ca7SRichard Henderson 
3431869051eaSRichard Henderson static DisasJumpType trans_bl(DisasContext *ctx, uint32_t insn,
343298cd9ca7SRichard Henderson                               const DisasInsn *di)
343398cd9ca7SRichard Henderson {
343498cd9ca7SRichard Henderson     unsigned n = extract32(insn, 1, 1);
343598cd9ca7SRichard Henderson     unsigned link = extract32(insn, 21, 5);
3436eaa3783bSRichard Henderson     target_sreg disp = assemble_17(insn);
343798cd9ca7SRichard Henderson 
343898cd9ca7SRichard Henderson     return do_dbranch(ctx, iaoq_dest(ctx, disp), link, n);
343998cd9ca7SRichard Henderson }
344098cd9ca7SRichard Henderson 
3441869051eaSRichard Henderson static DisasJumpType trans_bl_long(DisasContext *ctx, uint32_t insn,
344298cd9ca7SRichard Henderson                                    const DisasInsn *di)
344398cd9ca7SRichard Henderson {
344498cd9ca7SRichard Henderson     unsigned n = extract32(insn, 1, 1);
3445eaa3783bSRichard Henderson     target_sreg disp = assemble_22(insn);
344698cd9ca7SRichard Henderson 
344798cd9ca7SRichard Henderson     return do_dbranch(ctx, iaoq_dest(ctx, disp), 2, n);
344898cd9ca7SRichard Henderson }
344998cd9ca7SRichard Henderson 
3450869051eaSRichard Henderson static DisasJumpType trans_blr(DisasContext *ctx, uint32_t insn,
345198cd9ca7SRichard Henderson                                const DisasInsn *di)
345298cd9ca7SRichard Henderson {
345398cd9ca7SRichard Henderson     unsigned n = extract32(insn, 1, 1);
345498cd9ca7SRichard Henderson     unsigned rx = extract32(insn, 16, 5);
345598cd9ca7SRichard Henderson     unsigned link = extract32(insn, 21, 5);
3456eaa3783bSRichard Henderson     TCGv_reg tmp = get_temp(ctx);
345798cd9ca7SRichard Henderson 
3458eaa3783bSRichard Henderson     tcg_gen_shli_reg(tmp, load_gpr(ctx, rx), 3);
3459eaa3783bSRichard Henderson     tcg_gen_addi_reg(tmp, tmp, ctx->iaoq_f + 8);
346098cd9ca7SRichard Henderson     return do_ibranch(ctx, tmp, link, n);
346198cd9ca7SRichard Henderson }
346298cd9ca7SRichard Henderson 
3463869051eaSRichard Henderson static DisasJumpType trans_bv(DisasContext *ctx, uint32_t insn,
346498cd9ca7SRichard Henderson                               const DisasInsn *di)
346598cd9ca7SRichard Henderson {
346698cd9ca7SRichard Henderson     unsigned n = extract32(insn, 1, 1);
346798cd9ca7SRichard Henderson     unsigned rx = extract32(insn, 16, 5);
346898cd9ca7SRichard Henderson     unsigned rb = extract32(insn, 21, 5);
3469eaa3783bSRichard Henderson     TCGv_reg dest;
347098cd9ca7SRichard Henderson 
347198cd9ca7SRichard Henderson     if (rx == 0) {
347298cd9ca7SRichard Henderson         dest = load_gpr(ctx, rb);
347398cd9ca7SRichard Henderson     } else {
347498cd9ca7SRichard Henderson         dest = get_temp(ctx);
3475eaa3783bSRichard Henderson         tcg_gen_shli_reg(dest, load_gpr(ctx, rx), 3);
3476eaa3783bSRichard Henderson         tcg_gen_add_reg(dest, dest, load_gpr(ctx, rb));
347798cd9ca7SRichard Henderson     }
347898cd9ca7SRichard Henderson     return do_ibranch(ctx, dest, 0, n);
347998cd9ca7SRichard Henderson }
348098cd9ca7SRichard Henderson 
3481869051eaSRichard Henderson static DisasJumpType trans_bve(DisasContext *ctx, uint32_t insn,
348298cd9ca7SRichard Henderson                                const DisasInsn *di)
348398cd9ca7SRichard Henderson {
348498cd9ca7SRichard Henderson     unsigned n = extract32(insn, 1, 1);
348598cd9ca7SRichard Henderson     unsigned rb = extract32(insn, 21, 5);
348698cd9ca7SRichard Henderson     unsigned link = extract32(insn, 13, 1) ? 2 : 0;
348798cd9ca7SRichard Henderson 
348898cd9ca7SRichard Henderson     return do_ibranch(ctx, load_gpr(ctx, rb), link, n);
348998cd9ca7SRichard Henderson }
349098cd9ca7SRichard Henderson 
349198cd9ca7SRichard Henderson static const DisasInsn table_branch[] = {
349298cd9ca7SRichard Henderson     { 0xe8000000u, 0xfc006000u, trans_bl }, /* B,L and B,L,PUSH */
349398cd9ca7SRichard Henderson     { 0xe800a000u, 0xfc00e000u, trans_bl_long },
349498cd9ca7SRichard Henderson     { 0xe8004000u, 0xfc00fffdu, trans_blr },
349598cd9ca7SRichard Henderson     { 0xe800c000u, 0xfc00fffdu, trans_bv },
349698cd9ca7SRichard Henderson     { 0xe800d000u, 0xfc00dffcu, trans_bve },
349798cd9ca7SRichard Henderson };
349898cd9ca7SRichard Henderson 
3499869051eaSRichard Henderson static DisasJumpType trans_fop_wew_0c(DisasContext *ctx, uint32_t insn,
3500ebe9383cSRichard Henderson                                       const DisasInsn *di)
3501ebe9383cSRichard Henderson {
3502ebe9383cSRichard Henderson     unsigned rt = extract32(insn, 0, 5);
3503ebe9383cSRichard Henderson     unsigned ra = extract32(insn, 21, 5);
3504eff235ebSPaolo Bonzini     return do_fop_wew(ctx, rt, ra, di->f.wew);
3505ebe9383cSRichard Henderson }
3506ebe9383cSRichard Henderson 
3507869051eaSRichard Henderson static DisasJumpType trans_fop_wew_0e(DisasContext *ctx, uint32_t insn,
3508ebe9383cSRichard Henderson                                       const DisasInsn *di)
3509ebe9383cSRichard Henderson {
3510ebe9383cSRichard Henderson     unsigned rt = assemble_rt64(insn);
3511ebe9383cSRichard Henderson     unsigned ra = assemble_ra64(insn);
3512eff235ebSPaolo Bonzini     return do_fop_wew(ctx, rt, ra, di->f.wew);
3513ebe9383cSRichard Henderson }
3514ebe9383cSRichard Henderson 
3515869051eaSRichard Henderson static DisasJumpType trans_fop_ded(DisasContext *ctx, uint32_t insn,
3516ebe9383cSRichard Henderson                                    const DisasInsn *di)
3517ebe9383cSRichard Henderson {
3518ebe9383cSRichard Henderson     unsigned rt = extract32(insn, 0, 5);
3519ebe9383cSRichard Henderson     unsigned ra = extract32(insn, 21, 5);
3520eff235ebSPaolo Bonzini     return do_fop_ded(ctx, rt, ra, di->f.ded);
3521ebe9383cSRichard Henderson }
3522ebe9383cSRichard Henderson 
3523869051eaSRichard Henderson static DisasJumpType trans_fop_wed_0c(DisasContext *ctx, uint32_t insn,
3524ebe9383cSRichard Henderson                                       const DisasInsn *di)
3525ebe9383cSRichard Henderson {
3526ebe9383cSRichard Henderson     unsigned rt = extract32(insn, 0, 5);
3527ebe9383cSRichard Henderson     unsigned ra = extract32(insn, 21, 5);
3528eff235ebSPaolo Bonzini     return do_fop_wed(ctx, rt, ra, di->f.wed);
3529ebe9383cSRichard Henderson }
3530ebe9383cSRichard Henderson 
3531869051eaSRichard Henderson static DisasJumpType trans_fop_wed_0e(DisasContext *ctx, uint32_t insn,
3532ebe9383cSRichard Henderson                                       const DisasInsn *di)
3533ebe9383cSRichard Henderson {
3534ebe9383cSRichard Henderson     unsigned rt = assemble_rt64(insn);
3535ebe9383cSRichard Henderson     unsigned ra = extract32(insn, 21, 5);
3536eff235ebSPaolo Bonzini     return do_fop_wed(ctx, rt, ra, di->f.wed);
3537ebe9383cSRichard Henderson }
3538ebe9383cSRichard Henderson 
3539869051eaSRichard Henderson static DisasJumpType trans_fop_dew_0c(DisasContext *ctx, uint32_t insn,
3540ebe9383cSRichard Henderson                                       const DisasInsn *di)
3541ebe9383cSRichard Henderson {
3542ebe9383cSRichard Henderson     unsigned rt = extract32(insn, 0, 5);
3543ebe9383cSRichard Henderson     unsigned ra = extract32(insn, 21, 5);
3544eff235ebSPaolo Bonzini     return do_fop_dew(ctx, rt, ra, di->f.dew);
3545ebe9383cSRichard Henderson }
3546ebe9383cSRichard Henderson 
3547869051eaSRichard Henderson static DisasJumpType trans_fop_dew_0e(DisasContext *ctx, uint32_t insn,
3548ebe9383cSRichard Henderson                                       const DisasInsn *di)
3549ebe9383cSRichard Henderson {
3550ebe9383cSRichard Henderson     unsigned rt = extract32(insn, 0, 5);
3551ebe9383cSRichard Henderson     unsigned ra = assemble_ra64(insn);
3552eff235ebSPaolo Bonzini     return do_fop_dew(ctx, rt, ra, di->f.dew);
3553ebe9383cSRichard Henderson }
3554ebe9383cSRichard Henderson 
3555869051eaSRichard Henderson static DisasJumpType trans_fop_weww_0c(DisasContext *ctx, uint32_t insn,
3556ebe9383cSRichard Henderson                                        const DisasInsn *di)
3557ebe9383cSRichard Henderson {
3558ebe9383cSRichard Henderson     unsigned rt = extract32(insn, 0, 5);
3559ebe9383cSRichard Henderson     unsigned rb = extract32(insn, 16, 5);
3560ebe9383cSRichard Henderson     unsigned ra = extract32(insn, 21, 5);
3561eff235ebSPaolo Bonzini     return do_fop_weww(ctx, rt, ra, rb, di->f.weww);
3562ebe9383cSRichard Henderson }
3563ebe9383cSRichard Henderson 
3564869051eaSRichard Henderson static DisasJumpType trans_fop_weww_0e(DisasContext *ctx, uint32_t insn,
3565ebe9383cSRichard Henderson                                        const DisasInsn *di)
3566ebe9383cSRichard Henderson {
3567ebe9383cSRichard Henderson     unsigned rt = assemble_rt64(insn);
3568ebe9383cSRichard Henderson     unsigned rb = assemble_rb64(insn);
3569ebe9383cSRichard Henderson     unsigned ra = assemble_ra64(insn);
3570eff235ebSPaolo Bonzini     return do_fop_weww(ctx, rt, ra, rb, di->f.weww);
3571ebe9383cSRichard Henderson }
3572ebe9383cSRichard Henderson 
3573869051eaSRichard Henderson static DisasJumpType trans_fop_dedd(DisasContext *ctx, uint32_t insn,
3574ebe9383cSRichard Henderson                                     const DisasInsn *di)
3575ebe9383cSRichard Henderson {
3576ebe9383cSRichard Henderson     unsigned rt = extract32(insn, 0, 5);
3577ebe9383cSRichard Henderson     unsigned rb = extract32(insn, 16, 5);
3578ebe9383cSRichard Henderson     unsigned ra = extract32(insn, 21, 5);
3579eff235ebSPaolo Bonzini     return do_fop_dedd(ctx, rt, ra, rb, di->f.dedd);
3580ebe9383cSRichard Henderson }
3581ebe9383cSRichard Henderson 
3582ebe9383cSRichard Henderson static void gen_fcpy_s(TCGv_i32 dst, TCGv_env unused, TCGv_i32 src)
3583ebe9383cSRichard Henderson {
3584ebe9383cSRichard Henderson     tcg_gen_mov_i32(dst, src);
3585ebe9383cSRichard Henderson }
3586ebe9383cSRichard Henderson 
3587ebe9383cSRichard Henderson static void gen_fcpy_d(TCGv_i64 dst, TCGv_env unused, TCGv_i64 src)
3588ebe9383cSRichard Henderson {
3589ebe9383cSRichard Henderson     tcg_gen_mov_i64(dst, src);
3590ebe9383cSRichard Henderson }
3591ebe9383cSRichard Henderson 
3592ebe9383cSRichard Henderson static void gen_fabs_s(TCGv_i32 dst, TCGv_env unused, TCGv_i32 src)
3593ebe9383cSRichard Henderson {
3594ebe9383cSRichard Henderson     tcg_gen_andi_i32(dst, src, INT32_MAX);
3595ebe9383cSRichard Henderson }
3596ebe9383cSRichard Henderson 
3597ebe9383cSRichard Henderson static void gen_fabs_d(TCGv_i64 dst, TCGv_env unused, TCGv_i64 src)
3598ebe9383cSRichard Henderson {
3599ebe9383cSRichard Henderson     tcg_gen_andi_i64(dst, src, INT64_MAX);
3600ebe9383cSRichard Henderson }
3601ebe9383cSRichard Henderson 
3602ebe9383cSRichard Henderson static void gen_fneg_s(TCGv_i32 dst, TCGv_env unused, TCGv_i32 src)
3603ebe9383cSRichard Henderson {
3604ebe9383cSRichard Henderson     tcg_gen_xori_i32(dst, src, INT32_MIN);
3605ebe9383cSRichard Henderson }
3606ebe9383cSRichard Henderson 
3607ebe9383cSRichard Henderson static void gen_fneg_d(TCGv_i64 dst, TCGv_env unused, TCGv_i64 src)
3608ebe9383cSRichard Henderson {
3609ebe9383cSRichard Henderson     tcg_gen_xori_i64(dst, src, INT64_MIN);
3610ebe9383cSRichard Henderson }
3611ebe9383cSRichard Henderson 
3612ebe9383cSRichard Henderson static void gen_fnegabs_s(TCGv_i32 dst, TCGv_env unused, TCGv_i32 src)
3613ebe9383cSRichard Henderson {
3614ebe9383cSRichard Henderson     tcg_gen_ori_i32(dst, src, INT32_MIN);
3615ebe9383cSRichard Henderson }
3616ebe9383cSRichard Henderson 
3617ebe9383cSRichard Henderson static void gen_fnegabs_d(TCGv_i64 dst, TCGv_env unused, TCGv_i64 src)
3618ebe9383cSRichard Henderson {
3619ebe9383cSRichard Henderson     tcg_gen_ori_i64(dst, src, INT64_MIN);
3620ebe9383cSRichard Henderson }
3621ebe9383cSRichard Henderson 
3622869051eaSRichard Henderson static DisasJumpType do_fcmp_s(DisasContext *ctx, unsigned ra, unsigned rb,
3623ebe9383cSRichard Henderson                                unsigned y, unsigned c)
3624ebe9383cSRichard Henderson {
3625ebe9383cSRichard Henderson     TCGv_i32 ta, tb, tc, ty;
3626ebe9383cSRichard Henderson 
3627ebe9383cSRichard Henderson     nullify_over(ctx);
3628ebe9383cSRichard Henderson 
3629ebe9383cSRichard Henderson     ta = load_frw0_i32(ra);
3630ebe9383cSRichard Henderson     tb = load_frw0_i32(rb);
3631ebe9383cSRichard Henderson     ty = tcg_const_i32(y);
3632ebe9383cSRichard Henderson     tc = tcg_const_i32(c);
3633ebe9383cSRichard Henderson 
3634ebe9383cSRichard Henderson     gen_helper_fcmp_s(cpu_env, ta, tb, ty, tc);
3635ebe9383cSRichard Henderson 
3636ebe9383cSRichard Henderson     tcg_temp_free_i32(ta);
3637ebe9383cSRichard Henderson     tcg_temp_free_i32(tb);
3638ebe9383cSRichard Henderson     tcg_temp_free_i32(ty);
3639ebe9383cSRichard Henderson     tcg_temp_free_i32(tc);
3640ebe9383cSRichard Henderson 
3641869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
3642ebe9383cSRichard Henderson }
3643ebe9383cSRichard Henderson 
3644869051eaSRichard Henderson static DisasJumpType trans_fcmp_s_0c(DisasContext *ctx, uint32_t insn,
3645ebe9383cSRichard Henderson                                      const DisasInsn *di)
3646ebe9383cSRichard Henderson {
3647ebe9383cSRichard Henderson     unsigned c = extract32(insn, 0, 5);
3648ebe9383cSRichard Henderson     unsigned y = extract32(insn, 13, 3);
3649ebe9383cSRichard Henderson     unsigned rb = extract32(insn, 16, 5);
3650ebe9383cSRichard Henderson     unsigned ra = extract32(insn, 21, 5);
3651ebe9383cSRichard Henderson     return do_fcmp_s(ctx, ra, rb, y, c);
3652ebe9383cSRichard Henderson }
3653ebe9383cSRichard Henderson 
3654869051eaSRichard Henderson static DisasJumpType trans_fcmp_s_0e(DisasContext *ctx, uint32_t insn,
3655ebe9383cSRichard Henderson                                      const DisasInsn *di)
3656ebe9383cSRichard Henderson {
3657ebe9383cSRichard Henderson     unsigned c = extract32(insn, 0, 5);
3658ebe9383cSRichard Henderson     unsigned y = extract32(insn, 13, 3);
3659ebe9383cSRichard Henderson     unsigned rb = assemble_rb64(insn);
3660ebe9383cSRichard Henderson     unsigned ra = assemble_ra64(insn);
3661ebe9383cSRichard Henderson     return do_fcmp_s(ctx, ra, rb, y, c);
3662ebe9383cSRichard Henderson }
3663ebe9383cSRichard Henderson 
3664869051eaSRichard Henderson static DisasJumpType trans_fcmp_d(DisasContext *ctx, uint32_t insn,
3665ebe9383cSRichard Henderson                                   const DisasInsn *di)
3666ebe9383cSRichard Henderson {
3667ebe9383cSRichard Henderson     unsigned c = extract32(insn, 0, 5);
3668ebe9383cSRichard Henderson     unsigned y = extract32(insn, 13, 3);
3669ebe9383cSRichard Henderson     unsigned rb = extract32(insn, 16, 5);
3670ebe9383cSRichard Henderson     unsigned ra = extract32(insn, 21, 5);
3671ebe9383cSRichard Henderson     TCGv_i64 ta, tb;
3672ebe9383cSRichard Henderson     TCGv_i32 tc, ty;
3673ebe9383cSRichard Henderson 
3674ebe9383cSRichard Henderson     nullify_over(ctx);
3675ebe9383cSRichard Henderson 
3676ebe9383cSRichard Henderson     ta = load_frd0(ra);
3677ebe9383cSRichard Henderson     tb = load_frd0(rb);
3678ebe9383cSRichard Henderson     ty = tcg_const_i32(y);
3679ebe9383cSRichard Henderson     tc = tcg_const_i32(c);
3680ebe9383cSRichard Henderson 
3681ebe9383cSRichard Henderson     gen_helper_fcmp_d(cpu_env, ta, tb, ty, tc);
3682ebe9383cSRichard Henderson 
3683ebe9383cSRichard Henderson     tcg_temp_free_i64(ta);
3684ebe9383cSRichard Henderson     tcg_temp_free_i64(tb);
3685ebe9383cSRichard Henderson     tcg_temp_free_i32(ty);
3686ebe9383cSRichard Henderson     tcg_temp_free_i32(tc);
3687ebe9383cSRichard Henderson 
3688869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
3689ebe9383cSRichard Henderson }
3690ebe9383cSRichard Henderson 
3691869051eaSRichard Henderson static DisasJumpType trans_ftest_t(DisasContext *ctx, uint32_t insn,
3692ebe9383cSRichard Henderson                                    const DisasInsn *di)
3693ebe9383cSRichard Henderson {
3694ebe9383cSRichard Henderson     unsigned y = extract32(insn, 13, 3);
3695ebe9383cSRichard Henderson     unsigned cbit = (y ^ 1) - 1;
3696eaa3783bSRichard Henderson     TCGv_reg t;
3697ebe9383cSRichard Henderson 
3698ebe9383cSRichard Henderson     nullify_over(ctx);
3699ebe9383cSRichard Henderson 
3700ebe9383cSRichard Henderson     t = tcg_temp_new();
3701eaa3783bSRichard Henderson     tcg_gen_ld32u_reg(t, cpu_env, offsetof(CPUHPPAState, fr0_shadow));
3702eaa3783bSRichard Henderson     tcg_gen_extract_reg(t, t, 21 - cbit, 1);
3703ebe9383cSRichard Henderson     ctx->null_cond = cond_make_0(TCG_COND_NE, t);
3704ebe9383cSRichard Henderson     tcg_temp_free(t);
3705ebe9383cSRichard Henderson 
3706869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
3707ebe9383cSRichard Henderson }
3708ebe9383cSRichard Henderson 
3709869051eaSRichard Henderson static DisasJumpType trans_ftest_q(DisasContext *ctx, uint32_t insn,
3710ebe9383cSRichard Henderson                                    const DisasInsn *di)
3711ebe9383cSRichard Henderson {
3712ebe9383cSRichard Henderson     unsigned c = extract32(insn, 0, 5);
3713ebe9383cSRichard Henderson     int mask;
3714ebe9383cSRichard Henderson     bool inv = false;
3715eaa3783bSRichard Henderson     TCGv_reg t;
3716ebe9383cSRichard Henderson 
3717ebe9383cSRichard Henderson     nullify_over(ctx);
3718ebe9383cSRichard Henderson 
3719ebe9383cSRichard Henderson     t = tcg_temp_new();
3720eaa3783bSRichard Henderson     tcg_gen_ld32u_reg(t, cpu_env, offsetof(CPUHPPAState, fr0_shadow));
3721ebe9383cSRichard Henderson 
3722ebe9383cSRichard Henderson     switch (c) {
3723ebe9383cSRichard Henderson     case 0: /* simple */
3724eaa3783bSRichard Henderson         tcg_gen_andi_reg(t, t, 0x4000000);
3725ebe9383cSRichard Henderson         ctx->null_cond = cond_make_0(TCG_COND_NE, t);
3726ebe9383cSRichard Henderson         goto done;
3727ebe9383cSRichard Henderson     case 2: /* rej */
3728ebe9383cSRichard Henderson         inv = true;
3729ebe9383cSRichard Henderson         /* fallthru */
3730ebe9383cSRichard Henderson     case 1: /* acc */
3731ebe9383cSRichard Henderson         mask = 0x43ff800;
3732ebe9383cSRichard Henderson         break;
3733ebe9383cSRichard Henderson     case 6: /* rej8 */
3734ebe9383cSRichard Henderson         inv = true;
3735ebe9383cSRichard Henderson         /* fallthru */
3736ebe9383cSRichard Henderson     case 5: /* acc8 */
3737ebe9383cSRichard Henderson         mask = 0x43f8000;
3738ebe9383cSRichard Henderson         break;
3739ebe9383cSRichard Henderson     case 9: /* acc6 */
3740ebe9383cSRichard Henderson         mask = 0x43e0000;
3741ebe9383cSRichard Henderson         break;
3742ebe9383cSRichard Henderson     case 13: /* acc4 */
3743ebe9383cSRichard Henderson         mask = 0x4380000;
3744ebe9383cSRichard Henderson         break;
3745ebe9383cSRichard Henderson     case 17: /* acc2 */
3746ebe9383cSRichard Henderson         mask = 0x4200000;
3747ebe9383cSRichard Henderson         break;
3748ebe9383cSRichard Henderson     default:
3749ebe9383cSRichard Henderson         return gen_illegal(ctx);
3750ebe9383cSRichard Henderson     }
3751ebe9383cSRichard Henderson     if (inv) {
3752eaa3783bSRichard Henderson         TCGv_reg c = load_const(ctx, mask);
3753eaa3783bSRichard Henderson         tcg_gen_or_reg(t, t, c);
3754ebe9383cSRichard Henderson         ctx->null_cond = cond_make(TCG_COND_EQ, t, c);
3755ebe9383cSRichard Henderson     } else {
3756eaa3783bSRichard Henderson         tcg_gen_andi_reg(t, t, mask);
3757ebe9383cSRichard Henderson         ctx->null_cond = cond_make_0(TCG_COND_EQ, t);
3758ebe9383cSRichard Henderson     }
3759ebe9383cSRichard Henderson  done:
3760869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
3761ebe9383cSRichard Henderson }
3762ebe9383cSRichard Henderson 
3763869051eaSRichard Henderson static DisasJumpType trans_xmpyu(DisasContext *ctx, uint32_t insn,
3764ebe9383cSRichard Henderson                                  const DisasInsn *di)
3765ebe9383cSRichard Henderson {
3766ebe9383cSRichard Henderson     unsigned rt = extract32(insn, 0, 5);
3767ebe9383cSRichard Henderson     unsigned rb = assemble_rb64(insn);
3768ebe9383cSRichard Henderson     unsigned ra = assemble_ra64(insn);
3769ebe9383cSRichard Henderson     TCGv_i64 a, b;
3770ebe9383cSRichard Henderson 
3771ebe9383cSRichard Henderson     nullify_over(ctx);
3772ebe9383cSRichard Henderson 
3773ebe9383cSRichard Henderson     a = load_frw0_i64(ra);
3774ebe9383cSRichard Henderson     b = load_frw0_i64(rb);
3775ebe9383cSRichard Henderson     tcg_gen_mul_i64(a, a, b);
3776ebe9383cSRichard Henderson     save_frd(rt, a);
3777ebe9383cSRichard Henderson     tcg_temp_free_i64(a);
3778ebe9383cSRichard Henderson     tcg_temp_free_i64(b);
3779ebe9383cSRichard Henderson 
3780869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
3781ebe9383cSRichard Henderson }
3782ebe9383cSRichard Henderson 
3783eff235ebSPaolo Bonzini #define FOP_DED  trans_fop_ded, .f.ded
3784eff235ebSPaolo Bonzini #define FOP_DEDD trans_fop_dedd, .f.dedd
3785ebe9383cSRichard Henderson 
3786eff235ebSPaolo Bonzini #define FOP_WEW  trans_fop_wew_0c, .f.wew
3787eff235ebSPaolo Bonzini #define FOP_DEW  trans_fop_dew_0c, .f.dew
3788eff235ebSPaolo Bonzini #define FOP_WED  trans_fop_wed_0c, .f.wed
3789eff235ebSPaolo Bonzini #define FOP_WEWW trans_fop_weww_0c, .f.weww
3790ebe9383cSRichard Henderson 
3791ebe9383cSRichard Henderson static const DisasInsn table_float_0c[] = {
3792ebe9383cSRichard Henderson     /* floating point class zero */
3793ebe9383cSRichard Henderson     { 0x30004000, 0xfc1fffe0, FOP_WEW = gen_fcpy_s },
3794ebe9383cSRichard Henderson     { 0x30006000, 0xfc1fffe0, FOP_WEW = gen_fabs_s },
3795ebe9383cSRichard Henderson     { 0x30008000, 0xfc1fffe0, FOP_WEW = gen_helper_fsqrt_s },
3796ebe9383cSRichard Henderson     { 0x3000a000, 0xfc1fffe0, FOP_WEW = gen_helper_frnd_s },
3797ebe9383cSRichard Henderson     { 0x3000c000, 0xfc1fffe0, FOP_WEW = gen_fneg_s },
3798ebe9383cSRichard Henderson     { 0x3000e000, 0xfc1fffe0, FOP_WEW = gen_fnegabs_s },
3799ebe9383cSRichard Henderson 
3800ebe9383cSRichard Henderson     { 0x30004800, 0xfc1fffe0, FOP_DED = gen_fcpy_d },
3801ebe9383cSRichard Henderson     { 0x30006800, 0xfc1fffe0, FOP_DED = gen_fabs_d },
3802ebe9383cSRichard Henderson     { 0x30008800, 0xfc1fffe0, FOP_DED = gen_helper_fsqrt_d },
3803ebe9383cSRichard Henderson     { 0x3000a800, 0xfc1fffe0, FOP_DED = gen_helper_frnd_d },
3804ebe9383cSRichard Henderson     { 0x3000c800, 0xfc1fffe0, FOP_DED = gen_fneg_d },
3805ebe9383cSRichard Henderson     { 0x3000e800, 0xfc1fffe0, FOP_DED = gen_fnegabs_d },
3806ebe9383cSRichard Henderson 
3807ebe9383cSRichard Henderson     /* floating point class three */
3808ebe9383cSRichard Henderson     { 0x30000600, 0xfc00ffe0, FOP_WEWW = gen_helper_fadd_s },
3809ebe9383cSRichard Henderson     { 0x30002600, 0xfc00ffe0, FOP_WEWW = gen_helper_fsub_s },
3810ebe9383cSRichard Henderson     { 0x30004600, 0xfc00ffe0, FOP_WEWW = gen_helper_fmpy_s },
3811ebe9383cSRichard Henderson     { 0x30006600, 0xfc00ffe0, FOP_WEWW = gen_helper_fdiv_s },
3812ebe9383cSRichard Henderson 
3813ebe9383cSRichard Henderson     { 0x30000e00, 0xfc00ffe0, FOP_DEDD = gen_helper_fadd_d },
3814ebe9383cSRichard Henderson     { 0x30002e00, 0xfc00ffe0, FOP_DEDD = gen_helper_fsub_d },
3815ebe9383cSRichard Henderson     { 0x30004e00, 0xfc00ffe0, FOP_DEDD = gen_helper_fmpy_d },
3816ebe9383cSRichard Henderson     { 0x30006e00, 0xfc00ffe0, FOP_DEDD = gen_helper_fdiv_d },
3817ebe9383cSRichard Henderson 
3818ebe9383cSRichard Henderson     /* floating point class one */
3819ebe9383cSRichard Henderson     /* float/float */
3820ebe9383cSRichard Henderson     { 0x30000a00, 0xfc1fffe0, FOP_WED = gen_helper_fcnv_d_s },
3821ebe9383cSRichard Henderson     { 0x30002200, 0xfc1fffe0, FOP_DEW = gen_helper_fcnv_s_d },
3822ebe9383cSRichard Henderson     /* int/float */
3823ebe9383cSRichard Henderson     { 0x30008200, 0xfc1fffe0, FOP_WEW = gen_helper_fcnv_w_s },
3824ebe9383cSRichard Henderson     { 0x30008a00, 0xfc1fffe0, FOP_WED = gen_helper_fcnv_dw_s },
3825ebe9383cSRichard Henderson     { 0x3000a200, 0xfc1fffe0, FOP_DEW = gen_helper_fcnv_w_d },
3826ebe9383cSRichard Henderson     { 0x3000aa00, 0xfc1fffe0, FOP_DED = gen_helper_fcnv_dw_d },
3827ebe9383cSRichard Henderson     /* float/int */
3828ebe9383cSRichard Henderson     { 0x30010200, 0xfc1fffe0, FOP_WEW = gen_helper_fcnv_s_w },
3829ebe9383cSRichard Henderson     { 0x30010a00, 0xfc1fffe0, FOP_WED = gen_helper_fcnv_d_w },
3830ebe9383cSRichard Henderson     { 0x30012200, 0xfc1fffe0, FOP_DEW = gen_helper_fcnv_s_dw },
3831ebe9383cSRichard Henderson     { 0x30012a00, 0xfc1fffe0, FOP_DED = gen_helper_fcnv_d_dw },
3832ebe9383cSRichard Henderson     /* float/int truncate */
3833ebe9383cSRichard Henderson     { 0x30018200, 0xfc1fffe0, FOP_WEW = gen_helper_fcnv_t_s_w },
3834ebe9383cSRichard Henderson     { 0x30018a00, 0xfc1fffe0, FOP_WED = gen_helper_fcnv_t_d_w },
3835ebe9383cSRichard Henderson     { 0x3001a200, 0xfc1fffe0, FOP_DEW = gen_helper_fcnv_t_s_dw },
3836ebe9383cSRichard Henderson     { 0x3001aa00, 0xfc1fffe0, FOP_DED = gen_helper_fcnv_t_d_dw },
3837ebe9383cSRichard Henderson     /* uint/float */
3838ebe9383cSRichard Henderson     { 0x30028200, 0xfc1fffe0, FOP_WEW = gen_helper_fcnv_uw_s },
3839ebe9383cSRichard Henderson     { 0x30028a00, 0xfc1fffe0, FOP_WED = gen_helper_fcnv_udw_s },
3840ebe9383cSRichard Henderson     { 0x3002a200, 0xfc1fffe0, FOP_DEW = gen_helper_fcnv_uw_d },
3841ebe9383cSRichard Henderson     { 0x3002aa00, 0xfc1fffe0, FOP_DED = gen_helper_fcnv_udw_d },
3842ebe9383cSRichard Henderson     /* float/uint */
3843ebe9383cSRichard Henderson     { 0x30030200, 0xfc1fffe0, FOP_WEW = gen_helper_fcnv_s_uw },
3844ebe9383cSRichard Henderson     { 0x30030a00, 0xfc1fffe0, FOP_WED = gen_helper_fcnv_d_uw },
3845ebe9383cSRichard Henderson     { 0x30032200, 0xfc1fffe0, FOP_DEW = gen_helper_fcnv_s_udw },
3846ebe9383cSRichard Henderson     { 0x30032a00, 0xfc1fffe0, FOP_DED = gen_helper_fcnv_d_udw },
3847ebe9383cSRichard Henderson     /* float/uint truncate */
3848ebe9383cSRichard Henderson     { 0x30038200, 0xfc1fffe0, FOP_WEW = gen_helper_fcnv_t_s_uw },
3849ebe9383cSRichard Henderson     { 0x30038a00, 0xfc1fffe0, FOP_WED = gen_helper_fcnv_t_d_uw },
3850ebe9383cSRichard Henderson     { 0x3003a200, 0xfc1fffe0, FOP_DEW = gen_helper_fcnv_t_s_udw },
3851ebe9383cSRichard Henderson     { 0x3003aa00, 0xfc1fffe0, FOP_DED = gen_helper_fcnv_t_d_udw },
3852ebe9383cSRichard Henderson 
3853ebe9383cSRichard Henderson     /* floating point class two */
3854ebe9383cSRichard Henderson     { 0x30000400, 0xfc001fe0, trans_fcmp_s_0c },
3855ebe9383cSRichard Henderson     { 0x30000c00, 0xfc001fe0, trans_fcmp_d },
3856ebe9383cSRichard Henderson     { 0x30002420, 0xffffffe0, trans_ftest_q },
3857ebe9383cSRichard Henderson     { 0x30000420, 0xffff1fff, trans_ftest_t },
3858ebe9383cSRichard Henderson 
3859ebe9383cSRichard Henderson     /* FID.  Note that ra == rt == 0, which via fcpy puts 0 into fr0.
3860ebe9383cSRichard Henderson        This is machine/revision == 0, which is reserved for simulator.  */
3861ebe9383cSRichard Henderson     { 0x30000000, 0xffffffff, FOP_WEW = gen_fcpy_s },
3862ebe9383cSRichard Henderson };
3863ebe9383cSRichard Henderson 
3864ebe9383cSRichard Henderson #undef FOP_WEW
3865ebe9383cSRichard Henderson #undef FOP_DEW
3866ebe9383cSRichard Henderson #undef FOP_WED
3867ebe9383cSRichard Henderson #undef FOP_WEWW
3868eff235ebSPaolo Bonzini #define FOP_WEW  trans_fop_wew_0e, .f.wew
3869eff235ebSPaolo Bonzini #define FOP_DEW  trans_fop_dew_0e, .f.dew
3870eff235ebSPaolo Bonzini #define FOP_WED  trans_fop_wed_0e, .f.wed
3871eff235ebSPaolo Bonzini #define FOP_WEWW trans_fop_weww_0e, .f.weww
3872ebe9383cSRichard Henderson 
3873ebe9383cSRichard Henderson static const DisasInsn table_float_0e[] = {
3874ebe9383cSRichard Henderson     /* floating point class zero */
3875ebe9383cSRichard Henderson     { 0x38004000, 0xfc1fff20, FOP_WEW = gen_fcpy_s },
3876ebe9383cSRichard Henderson     { 0x38006000, 0xfc1fff20, FOP_WEW = gen_fabs_s },
3877ebe9383cSRichard Henderson     { 0x38008000, 0xfc1fff20, FOP_WEW = gen_helper_fsqrt_s },
3878ebe9383cSRichard Henderson     { 0x3800a000, 0xfc1fff20, FOP_WEW = gen_helper_frnd_s },
3879ebe9383cSRichard Henderson     { 0x3800c000, 0xfc1fff20, FOP_WEW = gen_fneg_s },
3880ebe9383cSRichard Henderson     { 0x3800e000, 0xfc1fff20, FOP_WEW = gen_fnegabs_s },
3881ebe9383cSRichard Henderson 
3882ebe9383cSRichard Henderson     { 0x38004800, 0xfc1fffe0, FOP_DED = gen_fcpy_d },
3883ebe9383cSRichard Henderson     { 0x38006800, 0xfc1fffe0, FOP_DED = gen_fabs_d },
3884ebe9383cSRichard Henderson     { 0x38008800, 0xfc1fffe0, FOP_DED = gen_helper_fsqrt_d },
3885ebe9383cSRichard Henderson     { 0x3800a800, 0xfc1fffe0, FOP_DED = gen_helper_frnd_d },
3886ebe9383cSRichard Henderson     { 0x3800c800, 0xfc1fffe0, FOP_DED = gen_fneg_d },
3887ebe9383cSRichard Henderson     { 0x3800e800, 0xfc1fffe0, FOP_DED = gen_fnegabs_d },
3888ebe9383cSRichard Henderson 
3889ebe9383cSRichard Henderson     /* floating point class three */
3890ebe9383cSRichard Henderson     { 0x38000600, 0xfc00ef20, FOP_WEWW = gen_helper_fadd_s },
3891ebe9383cSRichard Henderson     { 0x38002600, 0xfc00ef20, FOP_WEWW = gen_helper_fsub_s },
3892ebe9383cSRichard Henderson     { 0x38004600, 0xfc00ef20, FOP_WEWW = gen_helper_fmpy_s },
3893ebe9383cSRichard Henderson     { 0x38006600, 0xfc00ef20, FOP_WEWW = gen_helper_fdiv_s },
3894ebe9383cSRichard Henderson 
3895ebe9383cSRichard Henderson     { 0x38000e00, 0xfc00ffe0, FOP_DEDD = gen_helper_fadd_d },
3896ebe9383cSRichard Henderson     { 0x38002e00, 0xfc00ffe0, FOP_DEDD = gen_helper_fsub_d },
3897ebe9383cSRichard Henderson     { 0x38004e00, 0xfc00ffe0, FOP_DEDD = gen_helper_fmpy_d },
3898ebe9383cSRichard Henderson     { 0x38006e00, 0xfc00ffe0, FOP_DEDD = gen_helper_fdiv_d },
3899ebe9383cSRichard Henderson 
3900ebe9383cSRichard Henderson     { 0x38004700, 0xfc00ef60, trans_xmpyu },
3901ebe9383cSRichard Henderson 
3902ebe9383cSRichard Henderson     /* floating point class one */
3903ebe9383cSRichard Henderson     /* float/float */
3904ebe9383cSRichard Henderson     { 0x38000a00, 0xfc1fffa0, FOP_WED = gen_helper_fcnv_d_s },
3905ebe9383cSRichard Henderson     { 0x38002200, 0xfc1fffc0, FOP_DEW = gen_helper_fcnv_s_d },
3906ebe9383cSRichard Henderson     /* int/float */
3907ebe9383cSRichard Henderson     { 0x38008200, 0xfc1ffe60, FOP_WEW = gen_helper_fcnv_w_s },
3908ebe9383cSRichard Henderson     { 0x38008a00, 0xfc1fffa0, FOP_WED = gen_helper_fcnv_dw_s },
3909ebe9383cSRichard Henderson     { 0x3800a200, 0xfc1fff60, FOP_DEW = gen_helper_fcnv_w_d },
3910ebe9383cSRichard Henderson     { 0x3800aa00, 0xfc1fffe0, FOP_DED = gen_helper_fcnv_dw_d },
3911ebe9383cSRichard Henderson     /* float/int */
3912ebe9383cSRichard Henderson     { 0x38010200, 0xfc1ffe60, FOP_WEW = gen_helper_fcnv_s_w },
3913ebe9383cSRichard Henderson     { 0x38010a00, 0xfc1fffa0, FOP_WED = gen_helper_fcnv_d_w },
3914ebe9383cSRichard Henderson     { 0x38012200, 0xfc1fff60, FOP_DEW = gen_helper_fcnv_s_dw },
3915ebe9383cSRichard Henderson     { 0x38012a00, 0xfc1fffe0, FOP_DED = gen_helper_fcnv_d_dw },
3916ebe9383cSRichard Henderson     /* float/int truncate */
3917ebe9383cSRichard Henderson     { 0x38018200, 0xfc1ffe60, FOP_WEW = gen_helper_fcnv_t_s_w },
3918ebe9383cSRichard Henderson     { 0x38018a00, 0xfc1fffa0, FOP_WED = gen_helper_fcnv_t_d_w },
3919ebe9383cSRichard Henderson     { 0x3801a200, 0xfc1fff60, FOP_DEW = gen_helper_fcnv_t_s_dw },
3920ebe9383cSRichard Henderson     { 0x3801aa00, 0xfc1fffe0, FOP_DED = gen_helper_fcnv_t_d_dw },
3921ebe9383cSRichard Henderson     /* uint/float */
3922ebe9383cSRichard Henderson     { 0x38028200, 0xfc1ffe60, FOP_WEW = gen_helper_fcnv_uw_s },
3923ebe9383cSRichard Henderson     { 0x38028a00, 0xfc1fffa0, FOP_WED = gen_helper_fcnv_udw_s },
3924ebe9383cSRichard Henderson     { 0x3802a200, 0xfc1fff60, FOP_DEW = gen_helper_fcnv_uw_d },
3925ebe9383cSRichard Henderson     { 0x3802aa00, 0xfc1fffe0, FOP_DED = gen_helper_fcnv_udw_d },
3926ebe9383cSRichard Henderson     /* float/uint */
3927ebe9383cSRichard Henderson     { 0x38030200, 0xfc1ffe60, FOP_WEW = gen_helper_fcnv_s_uw },
3928ebe9383cSRichard Henderson     { 0x38030a00, 0xfc1fffa0, FOP_WED = gen_helper_fcnv_d_uw },
3929ebe9383cSRichard Henderson     { 0x38032200, 0xfc1fff60, FOP_DEW = gen_helper_fcnv_s_udw },
3930ebe9383cSRichard Henderson     { 0x38032a00, 0xfc1fffe0, FOP_DED = gen_helper_fcnv_d_udw },
3931ebe9383cSRichard Henderson     /* float/uint truncate */
3932ebe9383cSRichard Henderson     { 0x38038200, 0xfc1ffe60, FOP_WEW = gen_helper_fcnv_t_s_uw },
3933ebe9383cSRichard Henderson     { 0x38038a00, 0xfc1fffa0, FOP_WED = gen_helper_fcnv_t_d_uw },
3934ebe9383cSRichard Henderson     { 0x3803a200, 0xfc1fff60, FOP_DEW = gen_helper_fcnv_t_s_udw },
3935ebe9383cSRichard Henderson     { 0x3803aa00, 0xfc1fffe0, FOP_DED = gen_helper_fcnv_t_d_udw },
3936ebe9383cSRichard Henderson 
3937ebe9383cSRichard Henderson     /* floating point class two */
3938ebe9383cSRichard Henderson     { 0x38000400, 0xfc000f60, trans_fcmp_s_0e },
3939ebe9383cSRichard Henderson     { 0x38000c00, 0xfc001fe0, trans_fcmp_d },
3940ebe9383cSRichard Henderson };
3941ebe9383cSRichard Henderson 
3942ebe9383cSRichard Henderson #undef FOP_WEW
3943ebe9383cSRichard Henderson #undef FOP_DEW
3944ebe9383cSRichard Henderson #undef FOP_WED
3945ebe9383cSRichard Henderson #undef FOP_WEWW
3946ebe9383cSRichard Henderson #undef FOP_DED
3947ebe9383cSRichard Henderson #undef FOP_DEDD
3948ebe9383cSRichard Henderson 
3949ebe9383cSRichard Henderson /* Convert the fmpyadd single-precision register encodings to standard.  */
3950ebe9383cSRichard Henderson static inline int fmpyadd_s_reg(unsigned r)
3951ebe9383cSRichard Henderson {
3952ebe9383cSRichard Henderson     return (r & 16) * 2 + 16 + (r & 15);
3953ebe9383cSRichard Henderson }
3954ebe9383cSRichard Henderson 
3955869051eaSRichard Henderson static DisasJumpType trans_fmpyadd(DisasContext *ctx,
3956869051eaSRichard Henderson                                    uint32_t insn, bool is_sub)
3957ebe9383cSRichard Henderson {
3958ebe9383cSRichard Henderson     unsigned tm = extract32(insn, 0, 5);
3959ebe9383cSRichard Henderson     unsigned f = extract32(insn, 5, 1);
3960ebe9383cSRichard Henderson     unsigned ra = extract32(insn, 6, 5);
3961ebe9383cSRichard Henderson     unsigned ta = extract32(insn, 11, 5);
3962ebe9383cSRichard Henderson     unsigned rm2 = extract32(insn, 16, 5);
3963ebe9383cSRichard Henderson     unsigned rm1 = extract32(insn, 21, 5);
3964ebe9383cSRichard Henderson 
3965ebe9383cSRichard Henderson     nullify_over(ctx);
3966ebe9383cSRichard Henderson 
3967ebe9383cSRichard Henderson     /* Independent multiply & add/sub, with undefined behaviour
3968ebe9383cSRichard Henderson        if outputs overlap inputs.  */
3969ebe9383cSRichard Henderson     if (f == 0) {
3970ebe9383cSRichard Henderson         tm = fmpyadd_s_reg(tm);
3971ebe9383cSRichard Henderson         ra = fmpyadd_s_reg(ra);
3972ebe9383cSRichard Henderson         ta = fmpyadd_s_reg(ta);
3973ebe9383cSRichard Henderson         rm2 = fmpyadd_s_reg(rm2);
3974ebe9383cSRichard Henderson         rm1 = fmpyadd_s_reg(rm1);
3975ebe9383cSRichard Henderson         do_fop_weww(ctx, tm, rm1, rm2, gen_helper_fmpy_s);
3976ebe9383cSRichard Henderson         do_fop_weww(ctx, ta, ta, ra,
3977ebe9383cSRichard Henderson                     is_sub ? gen_helper_fsub_s : gen_helper_fadd_s);
3978ebe9383cSRichard Henderson     } else {
3979ebe9383cSRichard Henderson         do_fop_dedd(ctx, tm, rm1, rm2, gen_helper_fmpy_d);
3980ebe9383cSRichard Henderson         do_fop_dedd(ctx, ta, ta, ra,
3981ebe9383cSRichard Henderson                     is_sub ? gen_helper_fsub_d : gen_helper_fadd_d);
3982ebe9383cSRichard Henderson     }
3983ebe9383cSRichard Henderson 
3984869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
3985ebe9383cSRichard Henderson }
3986ebe9383cSRichard Henderson 
3987869051eaSRichard Henderson static DisasJumpType trans_fmpyfadd_s(DisasContext *ctx, uint32_t insn,
3988ebe9383cSRichard Henderson                                       const DisasInsn *di)
3989ebe9383cSRichard Henderson {
3990ebe9383cSRichard Henderson     unsigned rt = assemble_rt64(insn);
3991ebe9383cSRichard Henderson     unsigned neg = extract32(insn, 5, 1);
3992ebe9383cSRichard Henderson     unsigned rm1 = assemble_ra64(insn);
3993ebe9383cSRichard Henderson     unsigned rm2 = assemble_rb64(insn);
3994ebe9383cSRichard Henderson     unsigned ra3 = assemble_rc64(insn);
3995ebe9383cSRichard Henderson     TCGv_i32 a, b, c;
3996ebe9383cSRichard Henderson 
3997ebe9383cSRichard Henderson     nullify_over(ctx);
3998ebe9383cSRichard Henderson     a = load_frw0_i32(rm1);
3999ebe9383cSRichard Henderson     b = load_frw0_i32(rm2);
4000ebe9383cSRichard Henderson     c = load_frw0_i32(ra3);
4001ebe9383cSRichard Henderson 
4002ebe9383cSRichard Henderson     if (neg) {
4003ebe9383cSRichard Henderson         gen_helper_fmpynfadd_s(a, cpu_env, a, b, c);
4004ebe9383cSRichard Henderson     } else {
4005ebe9383cSRichard Henderson         gen_helper_fmpyfadd_s(a, cpu_env, a, b, c);
4006ebe9383cSRichard Henderson     }
4007ebe9383cSRichard Henderson 
4008ebe9383cSRichard Henderson     tcg_temp_free_i32(b);
4009ebe9383cSRichard Henderson     tcg_temp_free_i32(c);
4010ebe9383cSRichard Henderson     save_frw_i32(rt, a);
4011ebe9383cSRichard Henderson     tcg_temp_free_i32(a);
4012869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
4013ebe9383cSRichard Henderson }
4014ebe9383cSRichard Henderson 
4015869051eaSRichard Henderson static DisasJumpType trans_fmpyfadd_d(DisasContext *ctx, uint32_t insn,
4016ebe9383cSRichard Henderson                                       const DisasInsn *di)
4017ebe9383cSRichard Henderson {
4018ebe9383cSRichard Henderson     unsigned rt = extract32(insn, 0, 5);
4019ebe9383cSRichard Henderson     unsigned neg = extract32(insn, 5, 1);
4020ebe9383cSRichard Henderson     unsigned rm1 = extract32(insn, 21, 5);
4021ebe9383cSRichard Henderson     unsigned rm2 = extract32(insn, 16, 5);
4022ebe9383cSRichard Henderson     unsigned ra3 = assemble_rc64(insn);
4023ebe9383cSRichard Henderson     TCGv_i64 a, b, c;
4024ebe9383cSRichard Henderson 
4025ebe9383cSRichard Henderson     nullify_over(ctx);
4026ebe9383cSRichard Henderson     a = load_frd0(rm1);
4027ebe9383cSRichard Henderson     b = load_frd0(rm2);
4028ebe9383cSRichard Henderson     c = load_frd0(ra3);
4029ebe9383cSRichard Henderson 
4030ebe9383cSRichard Henderson     if (neg) {
4031ebe9383cSRichard Henderson         gen_helper_fmpynfadd_d(a, cpu_env, a, b, c);
4032ebe9383cSRichard Henderson     } else {
4033ebe9383cSRichard Henderson         gen_helper_fmpyfadd_d(a, cpu_env, a, b, c);
4034ebe9383cSRichard Henderson     }
4035ebe9383cSRichard Henderson 
4036ebe9383cSRichard Henderson     tcg_temp_free_i64(b);
4037ebe9383cSRichard Henderson     tcg_temp_free_i64(c);
4038ebe9383cSRichard Henderson     save_frd(rt, a);
4039ebe9383cSRichard Henderson     tcg_temp_free_i64(a);
4040869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
4041ebe9383cSRichard Henderson }
4042ebe9383cSRichard Henderson 
4043ebe9383cSRichard Henderson static const DisasInsn table_fp_fused[] = {
4044ebe9383cSRichard Henderson     { 0xb8000000u, 0xfc000800u, trans_fmpyfadd_s },
4045ebe9383cSRichard Henderson     { 0xb8000800u, 0xfc0019c0u, trans_fmpyfadd_d }
4046ebe9383cSRichard Henderson };
4047ebe9383cSRichard Henderson 
4048869051eaSRichard Henderson static DisasJumpType translate_table_int(DisasContext *ctx, uint32_t insn,
404961766fe9SRichard Henderson                                          const DisasInsn table[], size_t n)
405061766fe9SRichard Henderson {
405161766fe9SRichard Henderson     size_t i;
405261766fe9SRichard Henderson     for (i = 0; i < n; ++i) {
405361766fe9SRichard Henderson         if ((insn & table[i].mask) == table[i].insn) {
405461766fe9SRichard Henderson             return table[i].trans(ctx, insn, &table[i]);
405561766fe9SRichard Henderson         }
405661766fe9SRichard Henderson     }
405761766fe9SRichard Henderson     return gen_illegal(ctx);
405861766fe9SRichard Henderson }
405961766fe9SRichard Henderson 
406061766fe9SRichard Henderson #define translate_table(ctx, insn, table) \
406161766fe9SRichard Henderson     translate_table_int(ctx, insn, table, ARRAY_SIZE(table))
406261766fe9SRichard Henderson 
4063869051eaSRichard Henderson static DisasJumpType translate_one(DisasContext *ctx, uint32_t insn)
406461766fe9SRichard Henderson {
406561766fe9SRichard Henderson     uint32_t opc = extract32(insn, 26, 6);
406661766fe9SRichard Henderson 
406761766fe9SRichard Henderson     switch (opc) {
406898a9cb79SRichard Henderson     case 0x00: /* system op */
406998a9cb79SRichard Henderson         return translate_table(ctx, insn, table_system);
407098a9cb79SRichard Henderson     case 0x01:
407198a9cb79SRichard Henderson         return translate_table(ctx, insn, table_mem_mgmt);
4072b2167459SRichard Henderson     case 0x02:
4073b2167459SRichard Henderson         return translate_table(ctx, insn, table_arith_log);
407496d6407fSRichard Henderson     case 0x03:
407596d6407fSRichard Henderson         return translate_table(ctx, insn, table_index_mem);
4076ebe9383cSRichard Henderson     case 0x06:
4077ebe9383cSRichard Henderson         return trans_fmpyadd(ctx, insn, false);
4078b2167459SRichard Henderson     case 0x08:
4079b2167459SRichard Henderson         return trans_ldil(ctx, insn);
408096d6407fSRichard Henderson     case 0x09:
408196d6407fSRichard Henderson         return trans_copr_w(ctx, insn);
4082b2167459SRichard Henderson     case 0x0A:
4083b2167459SRichard Henderson         return trans_addil(ctx, insn);
408496d6407fSRichard Henderson     case 0x0B:
408596d6407fSRichard Henderson         return trans_copr_dw(ctx, insn);
4086ebe9383cSRichard Henderson     case 0x0C:
4087ebe9383cSRichard Henderson         return translate_table(ctx, insn, table_float_0c);
4088b2167459SRichard Henderson     case 0x0D:
4089b2167459SRichard Henderson         return trans_ldo(ctx, insn);
4090ebe9383cSRichard Henderson     case 0x0E:
4091ebe9383cSRichard Henderson         return translate_table(ctx, insn, table_float_0e);
409296d6407fSRichard Henderson 
409396d6407fSRichard Henderson     case 0x10:
409496d6407fSRichard Henderson         return trans_load(ctx, insn, false, MO_UB);
409596d6407fSRichard Henderson     case 0x11:
409696d6407fSRichard Henderson         return trans_load(ctx, insn, false, MO_TEUW);
409796d6407fSRichard Henderson     case 0x12:
409896d6407fSRichard Henderson         return trans_load(ctx, insn, false, MO_TEUL);
409996d6407fSRichard Henderson     case 0x13:
410096d6407fSRichard Henderson         return trans_load(ctx, insn, true, MO_TEUL);
410196d6407fSRichard Henderson     case 0x16:
410296d6407fSRichard Henderson         return trans_fload_mod(ctx, insn);
410396d6407fSRichard Henderson     case 0x17:
410496d6407fSRichard Henderson         return trans_load_w(ctx, insn);
410596d6407fSRichard Henderson     case 0x18:
410696d6407fSRichard Henderson         return trans_store(ctx, insn, false, MO_UB);
410796d6407fSRichard Henderson     case 0x19:
410896d6407fSRichard Henderson         return trans_store(ctx, insn, false, MO_TEUW);
410996d6407fSRichard Henderson     case 0x1A:
411096d6407fSRichard Henderson         return trans_store(ctx, insn, false, MO_TEUL);
411196d6407fSRichard Henderson     case 0x1B:
411296d6407fSRichard Henderson         return trans_store(ctx, insn, true, MO_TEUL);
411396d6407fSRichard Henderson     case 0x1E:
411496d6407fSRichard Henderson         return trans_fstore_mod(ctx, insn);
411596d6407fSRichard Henderson     case 0x1F:
411696d6407fSRichard Henderson         return trans_store_w(ctx, insn);
411796d6407fSRichard Henderson 
411898cd9ca7SRichard Henderson     case 0x20:
411998cd9ca7SRichard Henderson         return trans_cmpb(ctx, insn, true, false, false);
412098cd9ca7SRichard Henderson     case 0x21:
412198cd9ca7SRichard Henderson         return trans_cmpb(ctx, insn, true, true, false);
412298cd9ca7SRichard Henderson     case 0x22:
412398cd9ca7SRichard Henderson         return trans_cmpb(ctx, insn, false, false, false);
412498cd9ca7SRichard Henderson     case 0x23:
412598cd9ca7SRichard Henderson         return trans_cmpb(ctx, insn, false, true, false);
4126b2167459SRichard Henderson     case 0x24:
4127b2167459SRichard Henderson         return trans_cmpiclr(ctx, insn);
4128b2167459SRichard Henderson     case 0x25:
4129b2167459SRichard Henderson         return trans_subi(ctx, insn);
4130ebe9383cSRichard Henderson     case 0x26:
4131ebe9383cSRichard Henderson         return trans_fmpyadd(ctx, insn, true);
413298cd9ca7SRichard Henderson     case 0x27:
413398cd9ca7SRichard Henderson         return trans_cmpb(ctx, insn, true, false, true);
413498cd9ca7SRichard Henderson     case 0x28:
413598cd9ca7SRichard Henderson         return trans_addb(ctx, insn, true, false);
413698cd9ca7SRichard Henderson     case 0x29:
413798cd9ca7SRichard Henderson         return trans_addb(ctx, insn, true, true);
413898cd9ca7SRichard Henderson     case 0x2A:
413998cd9ca7SRichard Henderson         return trans_addb(ctx, insn, false, false);
414098cd9ca7SRichard Henderson     case 0x2B:
414198cd9ca7SRichard Henderson         return trans_addb(ctx, insn, false, true);
4142b2167459SRichard Henderson     case 0x2C:
4143b2167459SRichard Henderson     case 0x2D:
4144b2167459SRichard Henderson         return trans_addi(ctx, insn);
4145ebe9383cSRichard Henderson     case 0x2E:
4146ebe9383cSRichard Henderson         return translate_table(ctx, insn, table_fp_fused);
414798cd9ca7SRichard Henderson     case 0x2F:
414898cd9ca7SRichard Henderson         return trans_cmpb(ctx, insn, false, false, true);
414996d6407fSRichard Henderson 
415098cd9ca7SRichard Henderson     case 0x30:
415198cd9ca7SRichard Henderson     case 0x31:
415298cd9ca7SRichard Henderson         return trans_bb(ctx, insn);
415398cd9ca7SRichard Henderson     case 0x32:
415498cd9ca7SRichard Henderson         return trans_movb(ctx, insn, false);
415598cd9ca7SRichard Henderson     case 0x33:
415698cd9ca7SRichard Henderson         return trans_movb(ctx, insn, true);
41570b1347d2SRichard Henderson     case 0x34:
41580b1347d2SRichard Henderson         return translate_table(ctx, insn, table_sh_ex);
41590b1347d2SRichard Henderson     case 0x35:
41600b1347d2SRichard Henderson         return translate_table(ctx, insn, table_depw);
416198cd9ca7SRichard Henderson     case 0x38:
416298cd9ca7SRichard Henderson         return trans_be(ctx, insn, false);
416398cd9ca7SRichard Henderson     case 0x39:
416498cd9ca7SRichard Henderson         return trans_be(ctx, insn, true);
416598cd9ca7SRichard Henderson     case 0x3A:
416698cd9ca7SRichard Henderson         return translate_table(ctx, insn, table_branch);
416796d6407fSRichard Henderson 
416896d6407fSRichard Henderson     case 0x04: /* spopn */
416996d6407fSRichard Henderson     case 0x05: /* diag */
417096d6407fSRichard Henderson     case 0x0F: /* product specific */
417196d6407fSRichard Henderson         break;
417296d6407fSRichard Henderson 
417396d6407fSRichard Henderson     case 0x07: /* unassigned */
417496d6407fSRichard Henderson     case 0x15: /* unassigned */
417596d6407fSRichard Henderson     case 0x1D: /* unassigned */
417696d6407fSRichard Henderson     case 0x37: /* unassigned */
417796d6407fSRichard Henderson     case 0x3F: /* unassigned */
417861766fe9SRichard Henderson     default:
417961766fe9SRichard Henderson         break;
418061766fe9SRichard Henderson     }
418161766fe9SRichard Henderson     return gen_illegal(ctx);
418261766fe9SRichard Henderson }
418361766fe9SRichard Henderson 
418451b061fbSRichard Henderson static int hppa_tr_init_disas_context(DisasContextBase *dcbase,
418551b061fbSRichard Henderson                                       CPUState *cs, int max_insns)
418661766fe9SRichard Henderson {
418751b061fbSRichard Henderson     DisasContext *ctx = container_of(dcbase, DisasContext, base);
4188f764718dSRichard Henderson     int bound;
418961766fe9SRichard Henderson 
419051b061fbSRichard Henderson     ctx->cs = cs;
41913d68ee7bSRichard Henderson 
41923d68ee7bSRichard Henderson #ifdef CONFIG_USER_ONLY
41933d68ee7bSRichard Henderson     ctx->privilege = MMU_USER_IDX;
41943d68ee7bSRichard Henderson     ctx->mmu_idx = MMU_USER_IDX;
41953d68ee7bSRichard Henderson #else
41963d68ee7bSRichard Henderson     ctx->privilege = ctx->base.pc_first & 3;
41973d68ee7bSRichard Henderson     ctx->mmu_idx = (ctx->base.tb->flags & PSW_D
41983d68ee7bSRichard Henderson                     ? ctx->privilege : MMU_PHYS_IDX);
41993d68ee7bSRichard Henderson #endif
42003d68ee7bSRichard Henderson     ctx->iaoq_f = ctx->base.pc_first;
42013d68ee7bSRichard Henderson     ctx->iaoq_b = ctx->base.tb->cs_base;
42023d68ee7bSRichard Henderson     ctx->base.pc_first &= -4;
42033d68ee7bSRichard Henderson 
420451b061fbSRichard Henderson     ctx->iaoq_n = -1;
4205f764718dSRichard Henderson     ctx->iaoq_n_var = NULL;
420661766fe9SRichard Henderson 
42073d68ee7bSRichard Henderson     /* Bound the number of instructions by those left on the page.  */
42083d68ee7bSRichard Henderson     bound = -(ctx->base.pc_first | TARGET_PAGE_MASK) / 4;
42093d68ee7bSRichard Henderson     bound = MIN(max_insns, bound);
42103d68ee7bSRichard Henderson 
421151b061fbSRichard Henderson     ctx->ntemps = 0;
4212f764718dSRichard Henderson     memset(ctx->temps, 0, sizeof(ctx->temps));
421361766fe9SRichard Henderson 
42143d68ee7bSRichard Henderson     return bound;
421561766fe9SRichard Henderson }
421661766fe9SRichard Henderson 
421751b061fbSRichard Henderson static void hppa_tr_tb_start(DisasContextBase *dcbase, CPUState *cs)
421851b061fbSRichard Henderson {
421951b061fbSRichard Henderson     DisasContext *ctx = container_of(dcbase, DisasContext, base);
422061766fe9SRichard Henderson 
42213d68ee7bSRichard Henderson     /* Seed the nullification status from PSW[N], as saved in TB->FLAGS.  */
422251b061fbSRichard Henderson     ctx->null_cond = cond_make_f();
422351b061fbSRichard Henderson     ctx->psw_n_nonzero = false;
42243d68ee7bSRichard Henderson     if (ctx->base.tb->flags & PSW_N) {
422551b061fbSRichard Henderson         ctx->null_cond.c = TCG_COND_ALWAYS;
422651b061fbSRichard Henderson         ctx->psw_n_nonzero = true;
4227129e9cc3SRichard Henderson     }
422851b061fbSRichard Henderson     ctx->null_lab = NULL;
422961766fe9SRichard Henderson }
423061766fe9SRichard Henderson 
423151b061fbSRichard Henderson static void hppa_tr_insn_start(DisasContextBase *dcbase, CPUState *cs)
423251b061fbSRichard Henderson {
423351b061fbSRichard Henderson     DisasContext *ctx = container_of(dcbase, DisasContext, base);
423451b061fbSRichard Henderson 
423551b061fbSRichard Henderson     tcg_gen_insn_start(ctx->iaoq_f, ctx->iaoq_b);
423651b061fbSRichard Henderson }
423751b061fbSRichard Henderson 
423851b061fbSRichard Henderson static bool hppa_tr_breakpoint_check(DisasContextBase *dcbase, CPUState *cs,
423951b061fbSRichard Henderson                                       const CPUBreakpoint *bp)
424051b061fbSRichard Henderson {
424151b061fbSRichard Henderson     DisasContext *ctx = container_of(dcbase, DisasContext, base);
424251b061fbSRichard Henderson 
424351b061fbSRichard Henderson     ctx->base.is_jmp = gen_excp(ctx, EXCP_DEBUG);
42443d68ee7bSRichard Henderson     ctx->base.pc_next = (ctx->iaoq_f & -4) + 4;
424551b061fbSRichard Henderson     return true;
424651b061fbSRichard Henderson }
424751b061fbSRichard Henderson 
424851b061fbSRichard Henderson static void hppa_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs)
424951b061fbSRichard Henderson {
425051b061fbSRichard Henderson     DisasContext *ctx = container_of(dcbase, DisasContext, base);
425151b061fbSRichard Henderson     CPUHPPAState *env = cs->env_ptr;
425251b061fbSRichard Henderson     DisasJumpType ret;
425351b061fbSRichard Henderson     int i, n;
425451b061fbSRichard Henderson 
425551b061fbSRichard Henderson     /* Execute one insn.  */
4256ba1d0b44SRichard Henderson #ifdef CONFIG_USER_ONLY
425751b061fbSRichard Henderson     if (ctx->iaoq_f < TARGET_PAGE_SIZE) {
425851b061fbSRichard Henderson         ret = do_page_zero(ctx);
4259869051eaSRichard Henderson         assert(ret != DISAS_NEXT);
4260ba1d0b44SRichard Henderson     } else
4261ba1d0b44SRichard Henderson #endif
4262ba1d0b44SRichard Henderson     {
426361766fe9SRichard Henderson         /* Always fetch the insn, even if nullified, so that we check
426461766fe9SRichard Henderson            the page permissions for execute.  */
42653d68ee7bSRichard Henderson         uint32_t insn = cpu_ldl_code(env, ctx->iaoq_f & -4);
426661766fe9SRichard Henderson 
426761766fe9SRichard Henderson         /* Set up the IA queue for the next insn.
426861766fe9SRichard Henderson            This will be overwritten by a branch.  */
426951b061fbSRichard Henderson         if (ctx->iaoq_b == -1) {
427051b061fbSRichard Henderson             ctx->iaoq_n = -1;
427151b061fbSRichard Henderson             ctx->iaoq_n_var = get_temp(ctx);
4272eaa3783bSRichard Henderson             tcg_gen_addi_reg(ctx->iaoq_n_var, cpu_iaoq_b, 4);
427361766fe9SRichard Henderson         } else {
427451b061fbSRichard Henderson             ctx->iaoq_n = ctx->iaoq_b + 4;
4275f764718dSRichard Henderson             ctx->iaoq_n_var = NULL;
427661766fe9SRichard Henderson         }
427761766fe9SRichard Henderson 
427851b061fbSRichard Henderson         if (unlikely(ctx->null_cond.c == TCG_COND_ALWAYS)) {
427951b061fbSRichard Henderson             ctx->null_cond.c = TCG_COND_NEVER;
4280869051eaSRichard Henderson             ret = DISAS_NEXT;
4281129e9cc3SRichard Henderson         } else {
4282*1a19da0dSRichard Henderson             ctx->insn = insn;
428351b061fbSRichard Henderson             ret = translate_one(ctx, insn);
428451b061fbSRichard Henderson             assert(ctx->null_lab == NULL);
4285129e9cc3SRichard Henderson         }
428661766fe9SRichard Henderson     }
428761766fe9SRichard Henderson 
428851b061fbSRichard Henderson     /* Free any temporaries allocated.  */
428951b061fbSRichard Henderson     for (i = 0, n = ctx->ntemps; i < n; ++i) {
429051b061fbSRichard Henderson         tcg_temp_free(ctx->temps[i]);
4291f764718dSRichard Henderson         ctx->temps[i] = NULL;
429261766fe9SRichard Henderson     }
429351b061fbSRichard Henderson     ctx->ntemps = 0;
429461766fe9SRichard Henderson 
42953d68ee7bSRichard Henderson     /* Advance the insn queue.  Note that this check also detects
42963d68ee7bSRichard Henderson        a priority change within the instruction queue.  */
429751b061fbSRichard Henderson     if (ret == DISAS_NEXT && ctx->iaoq_b != ctx->iaoq_f + 4) {
429851b061fbSRichard Henderson         if (ctx->null_cond.c == TCG_COND_NEVER
429951b061fbSRichard Henderson             || ctx->null_cond.c == TCG_COND_ALWAYS) {
430051b061fbSRichard Henderson             nullify_set(ctx, ctx->null_cond.c == TCG_COND_ALWAYS);
430151b061fbSRichard Henderson             gen_goto_tb(ctx, 0, ctx->iaoq_b, ctx->iaoq_n);
4302869051eaSRichard Henderson             ret = DISAS_NORETURN;
4303129e9cc3SRichard Henderson         } else {
4304869051eaSRichard Henderson             ret = DISAS_IAQ_N_STALE;
430561766fe9SRichard Henderson        }
4306129e9cc3SRichard Henderson     }
430751b061fbSRichard Henderson     ctx->iaoq_f = ctx->iaoq_b;
430851b061fbSRichard Henderson     ctx->iaoq_b = ctx->iaoq_n;
430951b061fbSRichard Henderson     ctx->base.is_jmp = ret;
431061766fe9SRichard Henderson 
4311869051eaSRichard Henderson     if (ret == DISAS_NORETURN || ret == DISAS_IAQ_N_UPDATED) {
431251b061fbSRichard Henderson         return;
431361766fe9SRichard Henderson     }
431451b061fbSRichard Henderson     if (ctx->iaoq_f == -1) {
4315eaa3783bSRichard Henderson         tcg_gen_mov_reg(cpu_iaoq_f, cpu_iaoq_b);
431651b061fbSRichard Henderson         copy_iaoq_entry(cpu_iaoq_b, ctx->iaoq_n, ctx->iaoq_n_var);
431751b061fbSRichard Henderson         nullify_save(ctx);
431851b061fbSRichard Henderson         ctx->base.is_jmp = DISAS_IAQ_N_UPDATED;
431951b061fbSRichard Henderson     } else if (ctx->iaoq_b == -1) {
4320eaa3783bSRichard Henderson         tcg_gen_mov_reg(cpu_iaoq_b, ctx->iaoq_n_var);
432161766fe9SRichard Henderson     }
432261766fe9SRichard Henderson }
432361766fe9SRichard Henderson 
432451b061fbSRichard Henderson static void hppa_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)
432551b061fbSRichard Henderson {
432651b061fbSRichard Henderson     DisasContext *ctx = container_of(dcbase, DisasContext, base);
4327e1b5a5edSRichard Henderson     DisasJumpType is_jmp = ctx->base.is_jmp;
432851b061fbSRichard Henderson 
4329e1b5a5edSRichard Henderson     switch (is_jmp) {
4330869051eaSRichard Henderson     case DISAS_NORETURN:
433161766fe9SRichard Henderson         break;
433251b061fbSRichard Henderson     case DISAS_TOO_MANY:
4333869051eaSRichard Henderson     case DISAS_IAQ_N_STALE:
4334e1b5a5edSRichard Henderson     case DISAS_IAQ_N_STALE_EXIT:
433551b061fbSRichard Henderson         copy_iaoq_entry(cpu_iaoq_f, ctx->iaoq_f, cpu_iaoq_f);
433651b061fbSRichard Henderson         copy_iaoq_entry(cpu_iaoq_b, ctx->iaoq_b, cpu_iaoq_b);
433751b061fbSRichard Henderson         nullify_save(ctx);
433861766fe9SRichard Henderson         /* FALLTHRU */
4339869051eaSRichard Henderson     case DISAS_IAQ_N_UPDATED:
434051b061fbSRichard Henderson         if (ctx->base.singlestep_enabled) {
434161766fe9SRichard Henderson             gen_excp_1(EXCP_DEBUG);
4342e1b5a5edSRichard Henderson         } else if (is_jmp == DISAS_IAQ_N_STALE_EXIT) {
4343e1b5a5edSRichard Henderson             tcg_gen_exit_tb(0);
434461766fe9SRichard Henderson         } else {
43457f11636dSEmilio G. Cota             tcg_gen_lookup_and_goto_ptr();
434661766fe9SRichard Henderson         }
434761766fe9SRichard Henderson         break;
434861766fe9SRichard Henderson     default:
434951b061fbSRichard Henderson         g_assert_not_reached();
435061766fe9SRichard Henderson     }
435161766fe9SRichard Henderson 
435251b061fbSRichard Henderson     /* We don't actually use this during normal translation,
435351b061fbSRichard Henderson        but we should interact with the generic main loop.  */
43543d68ee7bSRichard Henderson     ctx->base.pc_next = ctx->base.pc_first + 4 * ctx->base.num_insns;
435551b061fbSRichard Henderson }
435661766fe9SRichard Henderson 
435751b061fbSRichard Henderson static void hppa_tr_disas_log(const DisasContextBase *dcbase, CPUState *cs)
435851b061fbSRichard Henderson {
4359eaa3783bSRichard Henderson     target_ureg pc = dcbase->pc_first;
436061766fe9SRichard Henderson 
4361ba1d0b44SRichard Henderson #ifdef CONFIG_USER_ONLY
4362ba1d0b44SRichard Henderson     switch (pc) {
43637ad439dfSRichard Henderson     case 0x00:
436451b061fbSRichard Henderson         qemu_log("IN:\n0x00000000:  (null)\n");
4365ba1d0b44SRichard Henderson         return;
43667ad439dfSRichard Henderson     case 0xb0:
436751b061fbSRichard Henderson         qemu_log("IN:\n0x000000b0:  light-weight-syscall\n");
4368ba1d0b44SRichard Henderson         return;
43697ad439dfSRichard Henderson     case 0xe0:
437051b061fbSRichard Henderson         qemu_log("IN:\n0x000000e0:  set-thread-pointer-syscall\n");
4371ba1d0b44SRichard Henderson         return;
43727ad439dfSRichard Henderson     case 0x100:
437351b061fbSRichard Henderson         qemu_log("IN:\n0x00000100:  syscall\n");
4374ba1d0b44SRichard Henderson         return;
43757ad439dfSRichard Henderson     }
4376ba1d0b44SRichard Henderson #endif
4377ba1d0b44SRichard Henderson 
4378ba1d0b44SRichard Henderson     qemu_log("IN: %s\n", lookup_symbol(pc));
4379eaa3783bSRichard Henderson     log_target_disas(cs, pc, dcbase->tb->size);
438061766fe9SRichard Henderson }
438151b061fbSRichard Henderson 
438251b061fbSRichard Henderson static const TranslatorOps hppa_tr_ops = {
438351b061fbSRichard Henderson     .init_disas_context = hppa_tr_init_disas_context,
438451b061fbSRichard Henderson     .tb_start           = hppa_tr_tb_start,
438551b061fbSRichard Henderson     .insn_start         = hppa_tr_insn_start,
438651b061fbSRichard Henderson     .breakpoint_check   = hppa_tr_breakpoint_check,
438751b061fbSRichard Henderson     .translate_insn     = hppa_tr_translate_insn,
438851b061fbSRichard Henderson     .tb_stop            = hppa_tr_tb_stop,
438951b061fbSRichard Henderson     .disas_log          = hppa_tr_disas_log,
439051b061fbSRichard Henderson };
439151b061fbSRichard Henderson 
439251b061fbSRichard Henderson void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb)
439351b061fbSRichard Henderson 
439451b061fbSRichard Henderson {
439551b061fbSRichard Henderson     DisasContext ctx;
439651b061fbSRichard Henderson     translator_loop(&hppa_tr_ops, &ctx.base, cs, tb);
439761766fe9SRichard Henderson }
439861766fe9SRichard Henderson 
439961766fe9SRichard Henderson void restore_state_to_opc(CPUHPPAState *env, TranslationBlock *tb,
440061766fe9SRichard Henderson                           target_ulong *data)
440161766fe9SRichard Henderson {
440261766fe9SRichard Henderson     env->iaoq_f = data[0];
440361766fe9SRichard Henderson     if (data[1] != -1) {
440461766fe9SRichard Henderson         env->iaoq_b = data[1];
440561766fe9SRichard Henderson     }
440661766fe9SRichard Henderson     /* Since we were executing the instruction at IAOQ_F, and took some
440761766fe9SRichard Henderson        sort of action that provoked the cpu_restore_state, we can infer
440861766fe9SRichard Henderson        that the instruction was not nullified.  */
440961766fe9SRichard Henderson     env->psw_n = 0;
441061766fe9SRichard Henderson }
4411