xref: /openbmc/qemu/target/hppa/translate.c (revision 869051ea631ce1cb474e212b27d7c07d96daea0b)
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"
29*869051eaSRichard Henderson #include "exec/translator.h"
3061766fe9SRichard Henderson #include "trace-tcg.h"
3161766fe9SRichard Henderson #include "exec/log.h"
3261766fe9SRichard Henderson 
3361766fe9SRichard Henderson typedef struct DisasCond {
3461766fe9SRichard Henderson     TCGCond c;
3561766fe9SRichard Henderson     TCGv a0, a1;
3661766fe9SRichard Henderson     bool a0_is_n;
3761766fe9SRichard Henderson     bool a1_is_0;
3861766fe9SRichard Henderson } DisasCond;
3961766fe9SRichard Henderson 
4061766fe9SRichard Henderson typedef struct DisasContext {
4161766fe9SRichard Henderson     struct TranslationBlock *tb;
4261766fe9SRichard Henderson     CPUState *cs;
4361766fe9SRichard Henderson 
4461766fe9SRichard Henderson     target_ulong iaoq_f;
4561766fe9SRichard Henderson     target_ulong iaoq_b;
4661766fe9SRichard Henderson     target_ulong iaoq_n;
4761766fe9SRichard Henderson     TCGv iaoq_n_var;
4861766fe9SRichard Henderson 
4961766fe9SRichard Henderson     int ntemps;
5061766fe9SRichard Henderson     TCGv temps[8];
5161766fe9SRichard Henderson 
5261766fe9SRichard Henderson     DisasCond null_cond;
5361766fe9SRichard Henderson     TCGLabel *null_lab;
5461766fe9SRichard Henderson 
5561766fe9SRichard Henderson     bool singlestep_enabled;
5661766fe9SRichard Henderson     bool psw_n_nonzero;
5761766fe9SRichard Henderson } DisasContext;
5861766fe9SRichard Henderson 
59*869051eaSRichard Henderson /* Target-specific return values from translate_one, indicating the
60*869051eaSRichard Henderson    state of the TB.  Note that DISAS_NEXT indicates that we are not
61*869051eaSRichard Henderson    exiting the TB.  */
6261766fe9SRichard Henderson 
6361766fe9SRichard Henderson /* We are not using a goto_tb (for whatever reason), but have updated
6461766fe9SRichard Henderson    the iaq (for whatever reason), so don't do it again on exit.  */
65*869051eaSRichard Henderson #define DISAS_IAQ_N_UPDATED  DISAS_TARGET_0
6661766fe9SRichard Henderson 
6761766fe9SRichard Henderson /* We are exiting the TB, but have neither emitted a goto_tb, nor
6861766fe9SRichard Henderson    updated the iaq for the next instruction to be executed.  */
69*869051eaSRichard Henderson #define DISAS_IAQ_N_STALE    DISAS_TARGET_1
7061766fe9SRichard Henderson 
7161766fe9SRichard Henderson typedef struct DisasInsn {
7261766fe9SRichard Henderson     uint32_t insn, mask;
73*869051eaSRichard Henderson     DisasJumpType (*trans)(DisasContext *ctx, uint32_t insn,
7461766fe9SRichard Henderson                            const struct DisasInsn *f);
75b2167459SRichard Henderson     union {
76eff235ebSPaolo Bonzini         void (*ttt)(TCGv, TCGv, TCGv);
77eff235ebSPaolo Bonzini         void (*weww)(TCGv_i32, TCGv_env, TCGv_i32, TCGv_i32);
78eff235ebSPaolo Bonzini         void (*dedd)(TCGv_i64, TCGv_env, TCGv_i64, TCGv_i64);
79eff235ebSPaolo Bonzini         void (*wew)(TCGv_i32, TCGv_env, TCGv_i32);
80eff235ebSPaolo Bonzini         void (*ded)(TCGv_i64, TCGv_env, TCGv_i64);
81eff235ebSPaolo Bonzini         void (*wed)(TCGv_i32, TCGv_env, TCGv_i64);
82eff235ebSPaolo Bonzini         void (*dew)(TCGv_i64, TCGv_env, TCGv_i32);
83eff235ebSPaolo Bonzini     } f;
8461766fe9SRichard Henderson } DisasInsn;
8561766fe9SRichard Henderson 
8661766fe9SRichard Henderson /* global register indexes */
8761766fe9SRichard Henderson static TCGv_env cpu_env;
8861766fe9SRichard Henderson static TCGv cpu_gr[32];
8961766fe9SRichard Henderson static TCGv cpu_iaoq_f;
9061766fe9SRichard Henderson static TCGv cpu_iaoq_b;
9161766fe9SRichard Henderson static TCGv cpu_sar;
9261766fe9SRichard Henderson static TCGv cpu_psw_n;
9361766fe9SRichard Henderson static TCGv cpu_psw_v;
9461766fe9SRichard Henderson static TCGv cpu_psw_cb;
9561766fe9SRichard Henderson static TCGv cpu_psw_cb_msb;
9661766fe9SRichard Henderson static TCGv cpu_cr26;
9761766fe9SRichard Henderson static TCGv cpu_cr27;
9861766fe9SRichard Henderson 
9961766fe9SRichard Henderson #include "exec/gen-icount.h"
10061766fe9SRichard Henderson 
10161766fe9SRichard Henderson void hppa_translate_init(void)
10261766fe9SRichard Henderson {
10361766fe9SRichard Henderson #define DEF_VAR(V)  { &cpu_##V, #V, offsetof(CPUHPPAState, V) }
10461766fe9SRichard Henderson 
10561766fe9SRichard Henderson     typedef struct { TCGv *var; const char *name; int ofs; } GlobalVar;
10661766fe9SRichard Henderson     static const GlobalVar vars[] = {
10761766fe9SRichard Henderson         DEF_VAR(sar),
10861766fe9SRichard Henderson         DEF_VAR(cr26),
10961766fe9SRichard Henderson         DEF_VAR(cr27),
11061766fe9SRichard Henderson         DEF_VAR(psw_n),
11161766fe9SRichard Henderson         DEF_VAR(psw_v),
11261766fe9SRichard Henderson         DEF_VAR(psw_cb),
11361766fe9SRichard Henderson         DEF_VAR(psw_cb_msb),
11461766fe9SRichard Henderson         DEF_VAR(iaoq_f),
11561766fe9SRichard Henderson         DEF_VAR(iaoq_b),
11661766fe9SRichard Henderson     };
11761766fe9SRichard Henderson 
11861766fe9SRichard Henderson #undef DEF_VAR
11961766fe9SRichard Henderson 
12061766fe9SRichard Henderson     /* Use the symbolic register names that match the disassembler.  */
12161766fe9SRichard Henderson     static const char gr_names[32][4] = {
12261766fe9SRichard Henderson         "r0",  "r1",  "r2",  "r3",  "r4",  "r5",  "r6",  "r7",
12361766fe9SRichard Henderson         "r8",  "r9",  "r10", "r11", "r12", "r13", "r14", "r15",
12461766fe9SRichard Henderson         "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
12561766fe9SRichard Henderson         "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31"
12661766fe9SRichard Henderson     };
12761766fe9SRichard Henderson 
12861766fe9SRichard Henderson     static bool done_init = 0;
12961766fe9SRichard Henderson     int i;
13061766fe9SRichard Henderson 
13161766fe9SRichard Henderson     if (done_init) {
13261766fe9SRichard Henderson         return;
13361766fe9SRichard Henderson     }
13461766fe9SRichard Henderson     done_init = 1;
13561766fe9SRichard Henderson 
13661766fe9SRichard Henderson     cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
13761766fe9SRichard Henderson     tcg_ctx.tcg_env = cpu_env;
13861766fe9SRichard Henderson 
13961766fe9SRichard Henderson     TCGV_UNUSED(cpu_gr[0]);
14061766fe9SRichard Henderson     for (i = 1; i < 32; i++) {
14161766fe9SRichard Henderson         cpu_gr[i] = tcg_global_mem_new(cpu_env,
14261766fe9SRichard Henderson                                        offsetof(CPUHPPAState, gr[i]),
14361766fe9SRichard Henderson                                        gr_names[i]);
14461766fe9SRichard Henderson     }
14561766fe9SRichard Henderson 
14661766fe9SRichard Henderson     for (i = 0; i < ARRAY_SIZE(vars); ++i) {
14761766fe9SRichard Henderson         const GlobalVar *v = &vars[i];
14861766fe9SRichard Henderson         *v->var = tcg_global_mem_new(cpu_env, v->ofs, v->name);
14961766fe9SRichard Henderson     }
15061766fe9SRichard Henderson }
15161766fe9SRichard Henderson 
152129e9cc3SRichard Henderson static DisasCond cond_make_f(void)
153129e9cc3SRichard Henderson {
154129e9cc3SRichard Henderson     DisasCond r = { .c = TCG_COND_NEVER };
155129e9cc3SRichard Henderson     TCGV_UNUSED(r.a0);
156129e9cc3SRichard Henderson     TCGV_UNUSED(r.a1);
157129e9cc3SRichard Henderson     return r;
158129e9cc3SRichard Henderson }
159129e9cc3SRichard Henderson 
160129e9cc3SRichard Henderson static DisasCond cond_make_n(void)
161129e9cc3SRichard Henderson {
162129e9cc3SRichard Henderson     DisasCond r = { .c = TCG_COND_NE, .a0_is_n = true, .a1_is_0 = true };
163129e9cc3SRichard Henderson     r.a0 = cpu_psw_n;
164129e9cc3SRichard Henderson     TCGV_UNUSED(r.a1);
165129e9cc3SRichard Henderson     return r;
166129e9cc3SRichard Henderson }
167129e9cc3SRichard Henderson 
168129e9cc3SRichard Henderson static DisasCond cond_make_0(TCGCond c, TCGv a0)
169129e9cc3SRichard Henderson {
170129e9cc3SRichard Henderson     DisasCond r = { .c = c, .a1_is_0 = true };
171129e9cc3SRichard Henderson 
172129e9cc3SRichard Henderson     assert (c != TCG_COND_NEVER && c != TCG_COND_ALWAYS);
173129e9cc3SRichard Henderson     r.a0 = tcg_temp_new();
174129e9cc3SRichard Henderson     tcg_gen_mov_tl(r.a0, a0);
175129e9cc3SRichard Henderson     TCGV_UNUSED(r.a1);
176129e9cc3SRichard Henderson 
177129e9cc3SRichard Henderson     return r;
178129e9cc3SRichard Henderson }
179129e9cc3SRichard Henderson 
180129e9cc3SRichard Henderson static DisasCond cond_make(TCGCond c, TCGv a0, TCGv a1)
181129e9cc3SRichard Henderson {
182129e9cc3SRichard Henderson     DisasCond r = { .c = c };
183129e9cc3SRichard Henderson 
184129e9cc3SRichard Henderson     assert (c != TCG_COND_NEVER && c != TCG_COND_ALWAYS);
185129e9cc3SRichard Henderson     r.a0 = tcg_temp_new();
186129e9cc3SRichard Henderson     tcg_gen_mov_tl(r.a0, a0);
187129e9cc3SRichard Henderson     r.a1 = tcg_temp_new();
188129e9cc3SRichard Henderson     tcg_gen_mov_tl(r.a1, a1);
189129e9cc3SRichard Henderson 
190129e9cc3SRichard Henderson     return r;
191129e9cc3SRichard Henderson }
192129e9cc3SRichard Henderson 
193129e9cc3SRichard Henderson static void cond_prep(DisasCond *cond)
194129e9cc3SRichard Henderson {
195129e9cc3SRichard Henderson     if (cond->a1_is_0) {
196129e9cc3SRichard Henderson         cond->a1_is_0 = false;
197129e9cc3SRichard Henderson         cond->a1 = tcg_const_tl(0);
198129e9cc3SRichard Henderson     }
199129e9cc3SRichard Henderson }
200129e9cc3SRichard Henderson 
201129e9cc3SRichard Henderson static void cond_free(DisasCond *cond)
202129e9cc3SRichard Henderson {
203129e9cc3SRichard Henderson     switch (cond->c) {
204129e9cc3SRichard Henderson     default:
205129e9cc3SRichard Henderson         if (!cond->a0_is_n) {
206129e9cc3SRichard Henderson             tcg_temp_free(cond->a0);
207129e9cc3SRichard Henderson         }
208129e9cc3SRichard Henderson         if (!cond->a1_is_0) {
209129e9cc3SRichard Henderson             tcg_temp_free(cond->a1);
210129e9cc3SRichard Henderson         }
211129e9cc3SRichard Henderson         cond->a0_is_n = false;
212129e9cc3SRichard Henderson         cond->a1_is_0 = false;
213129e9cc3SRichard Henderson         TCGV_UNUSED(cond->a0);
214129e9cc3SRichard Henderson         TCGV_UNUSED(cond->a1);
215129e9cc3SRichard Henderson         /* fallthru */
216129e9cc3SRichard Henderson     case TCG_COND_ALWAYS:
217129e9cc3SRichard Henderson         cond->c = TCG_COND_NEVER;
218129e9cc3SRichard Henderson         break;
219129e9cc3SRichard Henderson     case TCG_COND_NEVER:
220129e9cc3SRichard Henderson         break;
221129e9cc3SRichard Henderson     }
222129e9cc3SRichard Henderson }
223129e9cc3SRichard Henderson 
22461766fe9SRichard Henderson static TCGv get_temp(DisasContext *ctx)
22561766fe9SRichard Henderson {
22661766fe9SRichard Henderson     unsigned i = ctx->ntemps++;
22761766fe9SRichard Henderson     g_assert(i < ARRAY_SIZE(ctx->temps));
22861766fe9SRichard Henderson     return ctx->temps[i] = tcg_temp_new();
22961766fe9SRichard Henderson }
23061766fe9SRichard Henderson 
23161766fe9SRichard Henderson static TCGv load_const(DisasContext *ctx, target_long v)
23261766fe9SRichard Henderson {
23361766fe9SRichard Henderson     TCGv t = get_temp(ctx);
23461766fe9SRichard Henderson     tcg_gen_movi_tl(t, v);
23561766fe9SRichard Henderson     return t;
23661766fe9SRichard Henderson }
23761766fe9SRichard Henderson 
23861766fe9SRichard Henderson static TCGv load_gpr(DisasContext *ctx, unsigned reg)
23961766fe9SRichard Henderson {
24061766fe9SRichard Henderson     if (reg == 0) {
24161766fe9SRichard Henderson         TCGv t = get_temp(ctx);
24261766fe9SRichard Henderson         tcg_gen_movi_tl(t, 0);
24361766fe9SRichard Henderson         return t;
24461766fe9SRichard Henderson     } else {
24561766fe9SRichard Henderson         return cpu_gr[reg];
24661766fe9SRichard Henderson     }
24761766fe9SRichard Henderson }
24861766fe9SRichard Henderson 
24961766fe9SRichard Henderson static TCGv dest_gpr(DisasContext *ctx, unsigned reg)
25061766fe9SRichard Henderson {
251129e9cc3SRichard Henderson     if (reg == 0 || ctx->null_cond.c != TCG_COND_NEVER) {
25261766fe9SRichard Henderson         return get_temp(ctx);
25361766fe9SRichard Henderson     } else {
25461766fe9SRichard Henderson         return cpu_gr[reg];
25561766fe9SRichard Henderson     }
25661766fe9SRichard Henderson }
25761766fe9SRichard Henderson 
258129e9cc3SRichard Henderson static void save_or_nullify(DisasContext *ctx, TCGv dest, TCGv t)
259129e9cc3SRichard Henderson {
260129e9cc3SRichard Henderson     if (ctx->null_cond.c != TCG_COND_NEVER) {
261129e9cc3SRichard Henderson         cond_prep(&ctx->null_cond);
262129e9cc3SRichard Henderson         tcg_gen_movcond_tl(ctx->null_cond.c, dest, ctx->null_cond.a0,
263129e9cc3SRichard Henderson                            ctx->null_cond.a1, dest, t);
264129e9cc3SRichard Henderson     } else {
265129e9cc3SRichard Henderson         tcg_gen_mov_tl(dest, t);
266129e9cc3SRichard Henderson     }
267129e9cc3SRichard Henderson }
268129e9cc3SRichard Henderson 
269129e9cc3SRichard Henderson static void save_gpr(DisasContext *ctx, unsigned reg, TCGv t)
270129e9cc3SRichard Henderson {
271129e9cc3SRichard Henderson     if (reg != 0) {
272129e9cc3SRichard Henderson         save_or_nullify(ctx, cpu_gr[reg], t);
273129e9cc3SRichard Henderson     }
274129e9cc3SRichard Henderson }
275129e9cc3SRichard Henderson 
27696d6407fSRichard Henderson #ifdef HOST_WORDS_BIGENDIAN
27796d6407fSRichard Henderson # define HI_OFS  0
27896d6407fSRichard Henderson # define LO_OFS  4
27996d6407fSRichard Henderson #else
28096d6407fSRichard Henderson # define HI_OFS  4
28196d6407fSRichard Henderson # define LO_OFS  0
28296d6407fSRichard Henderson #endif
28396d6407fSRichard Henderson 
28496d6407fSRichard Henderson static TCGv_i32 load_frw_i32(unsigned rt)
28596d6407fSRichard Henderson {
28696d6407fSRichard Henderson     TCGv_i32 ret = tcg_temp_new_i32();
28796d6407fSRichard Henderson     tcg_gen_ld_i32(ret, cpu_env,
28896d6407fSRichard Henderson                    offsetof(CPUHPPAState, fr[rt & 31])
28996d6407fSRichard Henderson                    + (rt & 32 ? LO_OFS : HI_OFS));
29096d6407fSRichard Henderson     return ret;
29196d6407fSRichard Henderson }
29296d6407fSRichard Henderson 
293ebe9383cSRichard Henderson static TCGv_i32 load_frw0_i32(unsigned rt)
294ebe9383cSRichard Henderson {
295ebe9383cSRichard Henderson     if (rt == 0) {
296ebe9383cSRichard Henderson         return tcg_const_i32(0);
297ebe9383cSRichard Henderson     } else {
298ebe9383cSRichard Henderson         return load_frw_i32(rt);
299ebe9383cSRichard Henderson     }
300ebe9383cSRichard Henderson }
301ebe9383cSRichard Henderson 
302ebe9383cSRichard Henderson static TCGv_i64 load_frw0_i64(unsigned rt)
303ebe9383cSRichard Henderson {
304ebe9383cSRichard Henderson     if (rt == 0) {
305ebe9383cSRichard Henderson         return tcg_const_i64(0);
306ebe9383cSRichard Henderson     } else {
307ebe9383cSRichard Henderson         TCGv_i64 ret = tcg_temp_new_i64();
308ebe9383cSRichard Henderson         tcg_gen_ld32u_i64(ret, cpu_env,
309ebe9383cSRichard Henderson                           offsetof(CPUHPPAState, fr[rt & 31])
310ebe9383cSRichard Henderson                           + (rt & 32 ? LO_OFS : HI_OFS));
311ebe9383cSRichard Henderson         return ret;
312ebe9383cSRichard Henderson     }
313ebe9383cSRichard Henderson }
314ebe9383cSRichard Henderson 
31596d6407fSRichard Henderson static void save_frw_i32(unsigned rt, TCGv_i32 val)
31696d6407fSRichard Henderson {
31796d6407fSRichard Henderson     tcg_gen_st_i32(val, cpu_env,
31896d6407fSRichard Henderson                    offsetof(CPUHPPAState, fr[rt & 31])
31996d6407fSRichard Henderson                    + (rt & 32 ? LO_OFS : HI_OFS));
32096d6407fSRichard Henderson }
32196d6407fSRichard Henderson 
32296d6407fSRichard Henderson #undef HI_OFS
32396d6407fSRichard Henderson #undef LO_OFS
32496d6407fSRichard Henderson 
32596d6407fSRichard Henderson static TCGv_i64 load_frd(unsigned rt)
32696d6407fSRichard Henderson {
32796d6407fSRichard Henderson     TCGv_i64 ret = tcg_temp_new_i64();
32896d6407fSRichard Henderson     tcg_gen_ld_i64(ret, cpu_env, offsetof(CPUHPPAState, fr[rt]));
32996d6407fSRichard Henderson     return ret;
33096d6407fSRichard Henderson }
33196d6407fSRichard Henderson 
332ebe9383cSRichard Henderson static TCGv_i64 load_frd0(unsigned rt)
333ebe9383cSRichard Henderson {
334ebe9383cSRichard Henderson     if (rt == 0) {
335ebe9383cSRichard Henderson         return tcg_const_i64(0);
336ebe9383cSRichard Henderson     } else {
337ebe9383cSRichard Henderson         return load_frd(rt);
338ebe9383cSRichard Henderson     }
339ebe9383cSRichard Henderson }
340ebe9383cSRichard Henderson 
34196d6407fSRichard Henderson static void save_frd(unsigned rt, TCGv_i64 val)
34296d6407fSRichard Henderson {
34396d6407fSRichard Henderson     tcg_gen_st_i64(val, cpu_env, offsetof(CPUHPPAState, fr[rt]));
34496d6407fSRichard Henderson }
34596d6407fSRichard Henderson 
346129e9cc3SRichard Henderson /* Skip over the implementation of an insn that has been nullified.
347129e9cc3SRichard Henderson    Use this when the insn is too complex for a conditional move.  */
348129e9cc3SRichard Henderson static void nullify_over(DisasContext *ctx)
349129e9cc3SRichard Henderson {
350129e9cc3SRichard Henderson     if (ctx->null_cond.c != TCG_COND_NEVER) {
351129e9cc3SRichard Henderson         /* The always condition should have been handled in the main loop.  */
352129e9cc3SRichard Henderson         assert(ctx->null_cond.c != TCG_COND_ALWAYS);
353129e9cc3SRichard Henderson 
354129e9cc3SRichard Henderson         ctx->null_lab = gen_new_label();
355129e9cc3SRichard Henderson         cond_prep(&ctx->null_cond);
356129e9cc3SRichard Henderson 
357129e9cc3SRichard Henderson         /* If we're using PSW[N], copy it to a temp because... */
358129e9cc3SRichard Henderson         if (ctx->null_cond.a0_is_n) {
359129e9cc3SRichard Henderson             ctx->null_cond.a0_is_n = false;
360129e9cc3SRichard Henderson             ctx->null_cond.a0 = tcg_temp_new();
361129e9cc3SRichard Henderson             tcg_gen_mov_tl(ctx->null_cond.a0, cpu_psw_n);
362129e9cc3SRichard Henderson         }
363129e9cc3SRichard Henderson         /* ... we clear it before branching over the implementation,
364129e9cc3SRichard Henderson            so that (1) it's clear after nullifying this insn and
365129e9cc3SRichard Henderson            (2) if this insn nullifies the next, PSW[N] is valid.  */
366129e9cc3SRichard Henderson         if (ctx->psw_n_nonzero) {
367129e9cc3SRichard Henderson             ctx->psw_n_nonzero = false;
368129e9cc3SRichard Henderson             tcg_gen_movi_tl(cpu_psw_n, 0);
369129e9cc3SRichard Henderson         }
370129e9cc3SRichard Henderson 
371129e9cc3SRichard Henderson         tcg_gen_brcond_tl(ctx->null_cond.c, ctx->null_cond.a0,
372129e9cc3SRichard Henderson                           ctx->null_cond.a1, ctx->null_lab);
373129e9cc3SRichard Henderson         cond_free(&ctx->null_cond);
374129e9cc3SRichard Henderson     }
375129e9cc3SRichard Henderson }
376129e9cc3SRichard Henderson 
377129e9cc3SRichard Henderson /* Save the current nullification state to PSW[N].  */
378129e9cc3SRichard Henderson static void nullify_save(DisasContext *ctx)
379129e9cc3SRichard Henderson {
380129e9cc3SRichard Henderson     if (ctx->null_cond.c == TCG_COND_NEVER) {
381129e9cc3SRichard Henderson         if (ctx->psw_n_nonzero) {
382129e9cc3SRichard Henderson             tcg_gen_movi_tl(cpu_psw_n, 0);
383129e9cc3SRichard Henderson         }
384129e9cc3SRichard Henderson         return;
385129e9cc3SRichard Henderson     }
386129e9cc3SRichard Henderson     if (!ctx->null_cond.a0_is_n) {
387129e9cc3SRichard Henderson         cond_prep(&ctx->null_cond);
388129e9cc3SRichard Henderson         tcg_gen_setcond_tl(ctx->null_cond.c, cpu_psw_n,
389129e9cc3SRichard Henderson                            ctx->null_cond.a0, ctx->null_cond.a1);
390129e9cc3SRichard Henderson         ctx->psw_n_nonzero = true;
391129e9cc3SRichard Henderson     }
392129e9cc3SRichard Henderson     cond_free(&ctx->null_cond);
393129e9cc3SRichard Henderson }
394129e9cc3SRichard Henderson 
395129e9cc3SRichard Henderson /* Set a PSW[N] to X.  The intention is that this is used immediately
396129e9cc3SRichard Henderson    before a goto_tb/exit_tb, so that there is no fallthru path to other
397129e9cc3SRichard Henderson    code within the TB.  Therefore we do not update psw_n_nonzero.  */
398129e9cc3SRichard Henderson static void nullify_set(DisasContext *ctx, bool x)
399129e9cc3SRichard Henderson {
400129e9cc3SRichard Henderson     if (ctx->psw_n_nonzero || x) {
401129e9cc3SRichard Henderson         tcg_gen_movi_tl(cpu_psw_n, x);
402129e9cc3SRichard Henderson     }
403129e9cc3SRichard Henderson }
404129e9cc3SRichard Henderson 
405129e9cc3SRichard Henderson /* Mark the end of an instruction that may have been nullified.
406129e9cc3SRichard Henderson    This is the pair to nullify_over.  */
407*869051eaSRichard Henderson static DisasJumpType nullify_end(DisasContext *ctx, DisasJumpType status)
408129e9cc3SRichard Henderson {
409129e9cc3SRichard Henderson     TCGLabel *null_lab = ctx->null_lab;
410129e9cc3SRichard Henderson 
411129e9cc3SRichard Henderson     if (likely(null_lab == NULL)) {
412129e9cc3SRichard Henderson         /* The current insn wasn't conditional or handled the condition
413129e9cc3SRichard Henderson            applied to it without a branch, so the (new) setting of
414129e9cc3SRichard Henderson            NULL_COND can be applied directly to the next insn.  */
415129e9cc3SRichard Henderson         return status;
416129e9cc3SRichard Henderson     }
417129e9cc3SRichard Henderson     ctx->null_lab = NULL;
418129e9cc3SRichard Henderson 
419129e9cc3SRichard Henderson     if (likely(ctx->null_cond.c == TCG_COND_NEVER)) {
420129e9cc3SRichard Henderson         /* The next instruction will be unconditional,
421129e9cc3SRichard Henderson            and NULL_COND already reflects that.  */
422129e9cc3SRichard Henderson         gen_set_label(null_lab);
423129e9cc3SRichard Henderson     } else {
424129e9cc3SRichard Henderson         /* The insn that we just executed is itself nullifying the next
425129e9cc3SRichard Henderson            instruction.  Store the condition in the PSW[N] global.
426129e9cc3SRichard Henderson            We asserted PSW[N] = 0 in nullify_over, so that after the
427129e9cc3SRichard Henderson            label we have the proper value in place.  */
428129e9cc3SRichard Henderson         nullify_save(ctx);
429129e9cc3SRichard Henderson         gen_set_label(null_lab);
430129e9cc3SRichard Henderson         ctx->null_cond = cond_make_n();
431129e9cc3SRichard Henderson     }
432129e9cc3SRichard Henderson 
433*869051eaSRichard Henderson     assert(status != DISAS_NORETURN && status != DISAS_IAQ_N_UPDATED);
434*869051eaSRichard Henderson     if (status == DISAS_NORETURN) {
435*869051eaSRichard Henderson         status = DISAS_NEXT;
436129e9cc3SRichard Henderson     }
437129e9cc3SRichard Henderson     return status;
438129e9cc3SRichard Henderson }
439129e9cc3SRichard Henderson 
44061766fe9SRichard Henderson static void copy_iaoq_entry(TCGv dest, target_ulong ival, TCGv vval)
44161766fe9SRichard Henderson {
44261766fe9SRichard Henderson     if (unlikely(ival == -1)) {
44361766fe9SRichard Henderson         tcg_gen_mov_tl(dest, vval);
44461766fe9SRichard Henderson     } else {
44561766fe9SRichard Henderson         tcg_gen_movi_tl(dest, ival);
44661766fe9SRichard Henderson     }
44761766fe9SRichard Henderson }
44861766fe9SRichard Henderson 
44961766fe9SRichard Henderson static inline target_ulong iaoq_dest(DisasContext *ctx, target_long disp)
45061766fe9SRichard Henderson {
45161766fe9SRichard Henderson     return ctx->iaoq_f + disp + 8;
45261766fe9SRichard Henderson }
45361766fe9SRichard Henderson 
45461766fe9SRichard Henderson static void gen_excp_1(int exception)
45561766fe9SRichard Henderson {
45661766fe9SRichard Henderson     TCGv_i32 t = tcg_const_i32(exception);
45761766fe9SRichard Henderson     gen_helper_excp(cpu_env, t);
45861766fe9SRichard Henderson     tcg_temp_free_i32(t);
45961766fe9SRichard Henderson }
46061766fe9SRichard Henderson 
461*869051eaSRichard Henderson static DisasJumpType gen_excp(DisasContext *ctx, int exception)
46261766fe9SRichard Henderson {
46361766fe9SRichard Henderson     copy_iaoq_entry(cpu_iaoq_f, ctx->iaoq_f, cpu_iaoq_f);
46461766fe9SRichard Henderson     copy_iaoq_entry(cpu_iaoq_b, ctx->iaoq_b, cpu_iaoq_b);
465129e9cc3SRichard Henderson     nullify_save(ctx);
46661766fe9SRichard Henderson     gen_excp_1(exception);
467*869051eaSRichard Henderson     return DISAS_NORETURN;
46861766fe9SRichard Henderson }
46961766fe9SRichard Henderson 
470*869051eaSRichard Henderson static DisasJumpType gen_illegal(DisasContext *ctx)
47161766fe9SRichard Henderson {
472129e9cc3SRichard Henderson     nullify_over(ctx);
473129e9cc3SRichard Henderson     return nullify_end(ctx, gen_excp(ctx, EXCP_SIGILL));
47461766fe9SRichard Henderson }
47561766fe9SRichard Henderson 
47661766fe9SRichard Henderson static bool use_goto_tb(DisasContext *ctx, target_ulong dest)
47761766fe9SRichard Henderson {
47861766fe9SRichard Henderson     /* Suppress goto_tb in the case of single-steping and IO.  */
47961766fe9SRichard Henderson     if ((ctx->tb->cflags & CF_LAST_IO) || ctx->singlestep_enabled) {
48061766fe9SRichard Henderson         return false;
48161766fe9SRichard Henderson     }
48261766fe9SRichard Henderson     return true;
48361766fe9SRichard Henderson }
48461766fe9SRichard Henderson 
485129e9cc3SRichard Henderson /* If the next insn is to be nullified, and it's on the same page,
486129e9cc3SRichard Henderson    and we're not attempting to set a breakpoint on it, then we can
487129e9cc3SRichard Henderson    totally skip the nullified insn.  This avoids creating and
488129e9cc3SRichard Henderson    executing a TB that merely branches to the next TB.  */
489129e9cc3SRichard Henderson static bool use_nullify_skip(DisasContext *ctx)
490129e9cc3SRichard Henderson {
491129e9cc3SRichard Henderson     return (((ctx->iaoq_b ^ ctx->iaoq_f) & TARGET_PAGE_MASK) == 0
492129e9cc3SRichard Henderson             && !cpu_breakpoint_test(ctx->cs, ctx->iaoq_b, BP_ANY));
493129e9cc3SRichard Henderson }
494129e9cc3SRichard Henderson 
49561766fe9SRichard Henderson static void gen_goto_tb(DisasContext *ctx, int which,
49661766fe9SRichard Henderson                         target_ulong f, target_ulong b)
49761766fe9SRichard Henderson {
49861766fe9SRichard Henderson     if (f != -1 && b != -1 && use_goto_tb(ctx, f)) {
49961766fe9SRichard Henderson         tcg_gen_goto_tb(which);
50061766fe9SRichard Henderson         tcg_gen_movi_tl(cpu_iaoq_f, f);
50161766fe9SRichard Henderson         tcg_gen_movi_tl(cpu_iaoq_b, b);
50261766fe9SRichard Henderson         tcg_gen_exit_tb((uintptr_t)ctx->tb + which);
50361766fe9SRichard Henderson     } else {
50461766fe9SRichard Henderson         copy_iaoq_entry(cpu_iaoq_f, f, cpu_iaoq_b);
50561766fe9SRichard Henderson         copy_iaoq_entry(cpu_iaoq_b, b, ctx->iaoq_n_var);
50661766fe9SRichard Henderson         if (ctx->singlestep_enabled) {
50761766fe9SRichard Henderson             gen_excp_1(EXCP_DEBUG);
50861766fe9SRichard Henderson         } else {
5094137cb83SRichard Henderson             tcg_gen_lookup_and_goto_ptr(cpu_iaoq_f);
51061766fe9SRichard Henderson         }
51161766fe9SRichard Henderson     }
51261766fe9SRichard Henderson }
51361766fe9SRichard Henderson 
514b2167459SRichard Henderson /* PA has a habit of taking the LSB of a field and using that as the sign,
515b2167459SRichard Henderson    with the rest of the field becoming the least significant bits.  */
516b2167459SRichard Henderson static target_long low_sextract(uint32_t val, int pos, int len)
517b2167459SRichard Henderson {
518b2167459SRichard Henderson     target_ulong x = -(target_ulong)extract32(val, pos, 1);
519b2167459SRichard Henderson     x = (x << (len - 1)) | extract32(val, pos + 1, len - 1);
520b2167459SRichard Henderson     return x;
521b2167459SRichard Henderson }
522b2167459SRichard Henderson 
523ebe9383cSRichard Henderson static unsigned assemble_rt64(uint32_t insn)
524ebe9383cSRichard Henderson {
525ebe9383cSRichard Henderson     unsigned r1 = extract32(insn, 6, 1);
526ebe9383cSRichard Henderson     unsigned r0 = extract32(insn, 0, 5);
527ebe9383cSRichard Henderson     return r1 * 32 + r0;
528ebe9383cSRichard Henderson }
529ebe9383cSRichard Henderson 
530ebe9383cSRichard Henderson static unsigned assemble_ra64(uint32_t insn)
531ebe9383cSRichard Henderson {
532ebe9383cSRichard Henderson     unsigned r1 = extract32(insn, 7, 1);
533ebe9383cSRichard Henderson     unsigned r0 = extract32(insn, 21, 5);
534ebe9383cSRichard Henderson     return r1 * 32 + r0;
535ebe9383cSRichard Henderson }
536ebe9383cSRichard Henderson 
537ebe9383cSRichard Henderson static unsigned assemble_rb64(uint32_t insn)
538ebe9383cSRichard Henderson {
539ebe9383cSRichard Henderson     unsigned r1 = extract32(insn, 12, 1);
540ebe9383cSRichard Henderson     unsigned r0 = extract32(insn, 16, 5);
541ebe9383cSRichard Henderson     return r1 * 32 + r0;
542ebe9383cSRichard Henderson }
543ebe9383cSRichard Henderson 
544ebe9383cSRichard Henderson static unsigned assemble_rc64(uint32_t insn)
545ebe9383cSRichard Henderson {
546ebe9383cSRichard Henderson     unsigned r2 = extract32(insn, 8, 1);
547ebe9383cSRichard Henderson     unsigned r1 = extract32(insn, 13, 3);
548ebe9383cSRichard Henderson     unsigned r0 = extract32(insn, 9, 2);
549ebe9383cSRichard Henderson     return r2 * 32 + r1 * 4 + r0;
550ebe9383cSRichard Henderson }
551ebe9383cSRichard Henderson 
55298cd9ca7SRichard Henderson static target_long assemble_12(uint32_t insn)
55398cd9ca7SRichard Henderson {
55498cd9ca7SRichard Henderson     target_ulong x = -(target_ulong)(insn & 1);
55598cd9ca7SRichard Henderson     x = (x <<  1) | extract32(insn, 2, 1);
55698cd9ca7SRichard Henderson     x = (x << 10) | extract32(insn, 3, 10);
55798cd9ca7SRichard Henderson     return x;
55898cd9ca7SRichard Henderson }
55998cd9ca7SRichard Henderson 
560b2167459SRichard Henderson static target_long assemble_16(uint32_t insn)
561b2167459SRichard Henderson {
562b2167459SRichard Henderson     /* Take the name from PA2.0, which produces a 16-bit number
563b2167459SRichard Henderson        only with wide mode; otherwise a 14-bit number.  Since we don't
564b2167459SRichard Henderson        implement wide mode, this is always the 14-bit number.  */
565b2167459SRichard Henderson     return low_sextract(insn, 0, 14);
566b2167459SRichard Henderson }
567b2167459SRichard Henderson 
56896d6407fSRichard Henderson static target_long assemble_16a(uint32_t insn)
56996d6407fSRichard Henderson {
57096d6407fSRichard Henderson     /* Take the name from PA2.0, which produces a 14-bit shifted number
57196d6407fSRichard Henderson        only with wide mode; otherwise a 12-bit shifted number.  Since we
57296d6407fSRichard Henderson        don't implement wide mode, this is always the 12-bit number.  */
57396d6407fSRichard Henderson     target_ulong x = -(target_ulong)(insn & 1);
57496d6407fSRichard Henderson     x = (x << 11) | extract32(insn, 2, 11);
57596d6407fSRichard Henderson     return x << 2;
57696d6407fSRichard Henderson }
57796d6407fSRichard Henderson 
57898cd9ca7SRichard Henderson static target_long assemble_17(uint32_t insn)
57998cd9ca7SRichard Henderson {
58098cd9ca7SRichard Henderson     target_ulong x = -(target_ulong)(insn & 1);
58198cd9ca7SRichard Henderson     x = (x <<  5) | extract32(insn, 16, 5);
58298cd9ca7SRichard Henderson     x = (x <<  1) | extract32(insn, 2, 1);
58398cd9ca7SRichard Henderson     x = (x << 10) | extract32(insn, 3, 10);
58498cd9ca7SRichard Henderson     return x << 2;
58598cd9ca7SRichard Henderson }
58698cd9ca7SRichard Henderson 
587b2167459SRichard Henderson static target_long assemble_21(uint32_t insn)
588b2167459SRichard Henderson {
589b2167459SRichard Henderson     target_ulong x = -(target_ulong)(insn & 1);
590b2167459SRichard Henderson     x = (x << 11) | extract32(insn, 1, 11);
591b2167459SRichard Henderson     x = (x <<  2) | extract32(insn, 14, 2);
592b2167459SRichard Henderson     x = (x <<  5) | extract32(insn, 16, 5);
593b2167459SRichard Henderson     x = (x <<  2) | extract32(insn, 12, 2);
594b2167459SRichard Henderson     return x << 11;
595b2167459SRichard Henderson }
596b2167459SRichard Henderson 
59798cd9ca7SRichard Henderson static target_long assemble_22(uint32_t insn)
59898cd9ca7SRichard Henderson {
59998cd9ca7SRichard Henderson     target_ulong x = -(target_ulong)(insn & 1);
60098cd9ca7SRichard Henderson     x = (x << 10) | extract32(insn, 16, 10);
60198cd9ca7SRichard Henderson     x = (x <<  1) | extract32(insn, 2, 1);
60298cd9ca7SRichard Henderson     x = (x << 10) | extract32(insn, 3, 10);
60398cd9ca7SRichard Henderson     return x << 2;
60498cd9ca7SRichard Henderson }
60598cd9ca7SRichard Henderson 
606b2167459SRichard Henderson /* The parisc documentation describes only the general interpretation of
607b2167459SRichard Henderson    the conditions, without describing their exact implementation.  The
608b2167459SRichard Henderson    interpretations do not stand up well when considering ADD,C and SUB,B.
609b2167459SRichard Henderson    However, considering the Addition, Subtraction and Logical conditions
610b2167459SRichard Henderson    as a whole it would appear that these relations are similar to what
611b2167459SRichard Henderson    a traditional NZCV set of flags would produce.  */
612b2167459SRichard Henderson 
613b2167459SRichard Henderson static DisasCond do_cond(unsigned cf, TCGv res, TCGv cb_msb, TCGv sv)
614b2167459SRichard Henderson {
615b2167459SRichard Henderson     DisasCond cond;
616b2167459SRichard Henderson     TCGv tmp;
617b2167459SRichard Henderson 
618b2167459SRichard Henderson     switch (cf >> 1) {
619b2167459SRichard Henderson     case 0: /* Never / TR */
620b2167459SRichard Henderson         cond = cond_make_f();
621b2167459SRichard Henderson         break;
622b2167459SRichard Henderson     case 1: /* = / <>        (Z / !Z) */
623b2167459SRichard Henderson         cond = cond_make_0(TCG_COND_EQ, res);
624b2167459SRichard Henderson         break;
625b2167459SRichard Henderson     case 2: /* < / >=        (N / !N) */
626b2167459SRichard Henderson         cond = cond_make_0(TCG_COND_LT, res);
627b2167459SRichard Henderson         break;
628b2167459SRichard Henderson     case 3: /* <= / >        (N | Z / !N & !Z) */
629b2167459SRichard Henderson         cond = cond_make_0(TCG_COND_LE, res);
630b2167459SRichard Henderson         break;
631b2167459SRichard Henderson     case 4: /* NUV / UV      (!C / C) */
632b2167459SRichard Henderson         cond = cond_make_0(TCG_COND_EQ, cb_msb);
633b2167459SRichard Henderson         break;
634b2167459SRichard Henderson     case 5: /* ZNV / VNZ     (!C | Z / C & !Z) */
635b2167459SRichard Henderson         tmp = tcg_temp_new();
636b2167459SRichard Henderson         tcg_gen_neg_tl(tmp, cb_msb);
637b2167459SRichard Henderson         tcg_gen_and_tl(tmp, tmp, res);
638b2167459SRichard Henderson         cond = cond_make_0(TCG_COND_EQ, tmp);
639b2167459SRichard Henderson         tcg_temp_free(tmp);
640b2167459SRichard Henderson         break;
641b2167459SRichard Henderson     case 6: /* SV / NSV      (V / !V) */
642b2167459SRichard Henderson         cond = cond_make_0(TCG_COND_LT, sv);
643b2167459SRichard Henderson         break;
644b2167459SRichard Henderson     case 7: /* OD / EV */
645b2167459SRichard Henderson         tmp = tcg_temp_new();
646b2167459SRichard Henderson         tcg_gen_andi_tl(tmp, res, 1);
647b2167459SRichard Henderson         cond = cond_make_0(TCG_COND_NE, tmp);
648b2167459SRichard Henderson         tcg_temp_free(tmp);
649b2167459SRichard Henderson         break;
650b2167459SRichard Henderson     default:
651b2167459SRichard Henderson         g_assert_not_reached();
652b2167459SRichard Henderson     }
653b2167459SRichard Henderson     if (cf & 1) {
654b2167459SRichard Henderson         cond.c = tcg_invert_cond(cond.c);
655b2167459SRichard Henderson     }
656b2167459SRichard Henderson 
657b2167459SRichard Henderson     return cond;
658b2167459SRichard Henderson }
659b2167459SRichard Henderson 
660b2167459SRichard Henderson /* Similar, but for the special case of subtraction without borrow, we
661b2167459SRichard Henderson    can use the inputs directly.  This can allow other computation to be
662b2167459SRichard Henderson    deleted as unused.  */
663b2167459SRichard Henderson 
664b2167459SRichard Henderson static DisasCond do_sub_cond(unsigned cf, TCGv res, TCGv in1, TCGv in2, TCGv sv)
665b2167459SRichard Henderson {
666b2167459SRichard Henderson     DisasCond cond;
667b2167459SRichard Henderson 
668b2167459SRichard Henderson     switch (cf >> 1) {
669b2167459SRichard Henderson     case 1: /* = / <> */
670b2167459SRichard Henderson         cond = cond_make(TCG_COND_EQ, in1, in2);
671b2167459SRichard Henderson         break;
672b2167459SRichard Henderson     case 2: /* < / >= */
673b2167459SRichard Henderson         cond = cond_make(TCG_COND_LT, in1, in2);
674b2167459SRichard Henderson         break;
675b2167459SRichard Henderson     case 3: /* <= / > */
676b2167459SRichard Henderson         cond = cond_make(TCG_COND_LE, in1, in2);
677b2167459SRichard Henderson         break;
678b2167459SRichard Henderson     case 4: /* << / >>= */
679b2167459SRichard Henderson         cond = cond_make(TCG_COND_LTU, in1, in2);
680b2167459SRichard Henderson         break;
681b2167459SRichard Henderson     case 5: /* <<= / >> */
682b2167459SRichard Henderson         cond = cond_make(TCG_COND_LEU, in1, in2);
683b2167459SRichard Henderson         break;
684b2167459SRichard Henderson     default:
685b2167459SRichard Henderson         return do_cond(cf, res, sv, sv);
686b2167459SRichard Henderson     }
687b2167459SRichard Henderson     if (cf & 1) {
688b2167459SRichard Henderson         cond.c = tcg_invert_cond(cond.c);
689b2167459SRichard Henderson     }
690b2167459SRichard Henderson 
691b2167459SRichard Henderson     return cond;
692b2167459SRichard Henderson }
693b2167459SRichard Henderson 
694b2167459SRichard Henderson /* Similar, but for logicals, where the carry and overflow bits are not
695b2167459SRichard Henderson    computed, and use of them is undefined.  */
696b2167459SRichard Henderson 
697b2167459SRichard Henderson static DisasCond do_log_cond(unsigned cf, TCGv res)
698b2167459SRichard Henderson {
699b2167459SRichard Henderson     switch (cf >> 1) {
700b2167459SRichard Henderson     case 4: case 5: case 6:
701b2167459SRichard Henderson         cf &= 1;
702b2167459SRichard Henderson         break;
703b2167459SRichard Henderson     }
704b2167459SRichard Henderson     return do_cond(cf, res, res, res);
705b2167459SRichard Henderson }
706b2167459SRichard Henderson 
70798cd9ca7SRichard Henderson /* Similar, but for shift/extract/deposit conditions.  */
70898cd9ca7SRichard Henderson 
70998cd9ca7SRichard Henderson static DisasCond do_sed_cond(unsigned orig, TCGv res)
71098cd9ca7SRichard Henderson {
71198cd9ca7SRichard Henderson     unsigned c, f;
71298cd9ca7SRichard Henderson 
71398cd9ca7SRichard Henderson     /* Convert the compressed condition codes to standard.
71498cd9ca7SRichard Henderson        0-2 are the same as logicals (nv,<,<=), while 3 is OD.
71598cd9ca7SRichard Henderson        4-7 are the reverse of 0-3.  */
71698cd9ca7SRichard Henderson     c = orig & 3;
71798cd9ca7SRichard Henderson     if (c == 3) {
71898cd9ca7SRichard Henderson         c = 7;
71998cd9ca7SRichard Henderson     }
72098cd9ca7SRichard Henderson     f = (orig & 4) / 4;
72198cd9ca7SRichard Henderson 
72298cd9ca7SRichard Henderson     return do_log_cond(c * 2 + f, res);
72398cd9ca7SRichard Henderson }
72498cd9ca7SRichard Henderson 
725b2167459SRichard Henderson /* Similar, but for unit conditions.  */
726b2167459SRichard Henderson 
727b2167459SRichard Henderson static DisasCond do_unit_cond(unsigned cf, TCGv res, TCGv in1, TCGv in2)
728b2167459SRichard Henderson {
729b2167459SRichard Henderson     DisasCond cond;
730b2167459SRichard Henderson     TCGv tmp, cb;
731b2167459SRichard Henderson 
732b2167459SRichard Henderson     TCGV_UNUSED(cb);
733b2167459SRichard Henderson     if (cf & 8) {
734b2167459SRichard Henderson         /* Since we want to test lots of carry-out bits all at once, do not
735b2167459SRichard Henderson          * do our normal thing and compute carry-in of bit B+1 since that
736b2167459SRichard Henderson          * leaves us with carry bits spread across two words.
737b2167459SRichard Henderson          */
738b2167459SRichard Henderson         cb = tcg_temp_new();
739b2167459SRichard Henderson         tmp = tcg_temp_new();
740b2167459SRichard Henderson         tcg_gen_or_tl(cb, in1, in2);
741b2167459SRichard Henderson         tcg_gen_and_tl(tmp, in1, in2);
742b2167459SRichard Henderson         tcg_gen_andc_tl(cb, cb, res);
743b2167459SRichard Henderson         tcg_gen_or_tl(cb, cb, tmp);
744b2167459SRichard Henderson         tcg_temp_free(tmp);
745b2167459SRichard Henderson     }
746b2167459SRichard Henderson 
747b2167459SRichard Henderson     switch (cf >> 1) {
748b2167459SRichard Henderson     case 0: /* never / TR */
749b2167459SRichard Henderson     case 1: /* undefined */
750b2167459SRichard Henderson     case 5: /* undefined */
751b2167459SRichard Henderson         cond = cond_make_f();
752b2167459SRichard Henderson         break;
753b2167459SRichard Henderson 
754b2167459SRichard Henderson     case 2: /* SBZ / NBZ */
755b2167459SRichard Henderson         /* See hasless(v,1) from
756b2167459SRichard Henderson          * https://graphics.stanford.edu/~seander/bithacks.html#ZeroInWord
757b2167459SRichard Henderson          */
758b2167459SRichard Henderson         tmp = tcg_temp_new();
759b2167459SRichard Henderson         tcg_gen_subi_tl(tmp, res, 0x01010101u);
760b2167459SRichard Henderson         tcg_gen_andc_tl(tmp, tmp, res);
761b2167459SRichard Henderson         tcg_gen_andi_tl(tmp, tmp, 0x80808080u);
762b2167459SRichard Henderson         cond = cond_make_0(TCG_COND_NE, tmp);
763b2167459SRichard Henderson         tcg_temp_free(tmp);
764b2167459SRichard Henderson         break;
765b2167459SRichard Henderson 
766b2167459SRichard Henderson     case 3: /* SHZ / NHZ */
767b2167459SRichard Henderson         tmp = tcg_temp_new();
768b2167459SRichard Henderson         tcg_gen_subi_tl(tmp, res, 0x00010001u);
769b2167459SRichard Henderson         tcg_gen_andc_tl(tmp, tmp, res);
770b2167459SRichard Henderson         tcg_gen_andi_tl(tmp, tmp, 0x80008000u);
771b2167459SRichard Henderson         cond = cond_make_0(TCG_COND_NE, tmp);
772b2167459SRichard Henderson         tcg_temp_free(tmp);
773b2167459SRichard Henderson         break;
774b2167459SRichard Henderson 
775b2167459SRichard Henderson     case 4: /* SDC / NDC */
776b2167459SRichard Henderson         tcg_gen_andi_tl(cb, cb, 0x88888888u);
777b2167459SRichard Henderson         cond = cond_make_0(TCG_COND_NE, cb);
778b2167459SRichard Henderson         break;
779b2167459SRichard Henderson 
780b2167459SRichard Henderson     case 6: /* SBC / NBC */
781b2167459SRichard Henderson         tcg_gen_andi_tl(cb, cb, 0x80808080u);
782b2167459SRichard Henderson         cond = cond_make_0(TCG_COND_NE, cb);
783b2167459SRichard Henderson         break;
784b2167459SRichard Henderson 
785b2167459SRichard Henderson     case 7: /* SHC / NHC */
786b2167459SRichard Henderson         tcg_gen_andi_tl(cb, cb, 0x80008000u);
787b2167459SRichard Henderson         cond = cond_make_0(TCG_COND_NE, cb);
788b2167459SRichard Henderson         break;
789b2167459SRichard Henderson 
790b2167459SRichard Henderson     default:
791b2167459SRichard Henderson         g_assert_not_reached();
792b2167459SRichard Henderson     }
793b2167459SRichard Henderson     if (cf & 8) {
794b2167459SRichard Henderson         tcg_temp_free(cb);
795b2167459SRichard Henderson     }
796b2167459SRichard Henderson     if (cf & 1) {
797b2167459SRichard Henderson         cond.c = tcg_invert_cond(cond.c);
798b2167459SRichard Henderson     }
799b2167459SRichard Henderson 
800b2167459SRichard Henderson     return cond;
801b2167459SRichard Henderson }
802b2167459SRichard Henderson 
803b2167459SRichard Henderson /* Compute signed overflow for addition.  */
804b2167459SRichard Henderson static TCGv do_add_sv(DisasContext *ctx, TCGv res, TCGv in1, TCGv in2)
805b2167459SRichard Henderson {
806b2167459SRichard Henderson     TCGv sv = get_temp(ctx);
807b2167459SRichard Henderson     TCGv tmp = tcg_temp_new();
808b2167459SRichard Henderson 
809b2167459SRichard Henderson     tcg_gen_xor_tl(sv, res, in1);
810b2167459SRichard Henderson     tcg_gen_xor_tl(tmp, in1, in2);
811b2167459SRichard Henderson     tcg_gen_andc_tl(sv, sv, tmp);
812b2167459SRichard Henderson     tcg_temp_free(tmp);
813b2167459SRichard Henderson 
814b2167459SRichard Henderson     return sv;
815b2167459SRichard Henderson }
816b2167459SRichard Henderson 
817b2167459SRichard Henderson /* Compute signed overflow for subtraction.  */
818b2167459SRichard Henderson static TCGv do_sub_sv(DisasContext *ctx, TCGv res, TCGv in1, TCGv in2)
819b2167459SRichard Henderson {
820b2167459SRichard Henderson     TCGv sv = get_temp(ctx);
821b2167459SRichard Henderson     TCGv tmp = tcg_temp_new();
822b2167459SRichard Henderson 
823b2167459SRichard Henderson     tcg_gen_xor_tl(sv, res, in1);
824b2167459SRichard Henderson     tcg_gen_xor_tl(tmp, in1, in2);
825b2167459SRichard Henderson     tcg_gen_and_tl(sv, sv, tmp);
826b2167459SRichard Henderson     tcg_temp_free(tmp);
827b2167459SRichard Henderson 
828b2167459SRichard Henderson     return sv;
829b2167459SRichard Henderson }
830b2167459SRichard Henderson 
831*869051eaSRichard Henderson static DisasJumpType do_add(DisasContext *ctx, unsigned rt, TCGv in1, TCGv in2,
832b2167459SRichard Henderson                             unsigned shift, bool is_l, bool is_tsv, bool is_tc,
833b2167459SRichard Henderson                             bool is_c, unsigned cf)
834b2167459SRichard Henderson {
835b2167459SRichard Henderson     TCGv dest, cb, cb_msb, sv, tmp;
836b2167459SRichard Henderson     unsigned c = cf >> 1;
837b2167459SRichard Henderson     DisasCond cond;
838b2167459SRichard Henderson 
839b2167459SRichard Henderson     dest = tcg_temp_new();
840b2167459SRichard Henderson     TCGV_UNUSED(cb);
841b2167459SRichard Henderson     TCGV_UNUSED(cb_msb);
842b2167459SRichard Henderson 
843b2167459SRichard Henderson     if (shift) {
844b2167459SRichard Henderson         tmp = get_temp(ctx);
845b2167459SRichard Henderson         tcg_gen_shli_tl(tmp, in1, shift);
846b2167459SRichard Henderson         in1 = tmp;
847b2167459SRichard Henderson     }
848b2167459SRichard Henderson 
849b2167459SRichard Henderson     if (!is_l || c == 4 || c == 5) {
850b2167459SRichard Henderson         TCGv zero = tcg_const_tl(0);
851b2167459SRichard Henderson         cb_msb = get_temp(ctx);
852b2167459SRichard Henderson         tcg_gen_add2_tl(dest, cb_msb, in1, zero, in2, zero);
853b2167459SRichard Henderson         if (is_c) {
854b2167459SRichard Henderson             tcg_gen_add2_tl(dest, cb_msb, dest, cb_msb, cpu_psw_cb_msb, zero);
855b2167459SRichard Henderson         }
856b2167459SRichard Henderson         tcg_temp_free(zero);
857b2167459SRichard Henderson         if (!is_l) {
858b2167459SRichard Henderson             cb = get_temp(ctx);
859b2167459SRichard Henderson             tcg_gen_xor_tl(cb, in1, in2);
860b2167459SRichard Henderson             tcg_gen_xor_tl(cb, cb, dest);
861b2167459SRichard Henderson         }
862b2167459SRichard Henderson     } else {
863b2167459SRichard Henderson         tcg_gen_add_tl(dest, in1, in2);
864b2167459SRichard Henderson         if (is_c) {
865b2167459SRichard Henderson             tcg_gen_add_tl(dest, dest, cpu_psw_cb_msb);
866b2167459SRichard Henderson         }
867b2167459SRichard Henderson     }
868b2167459SRichard Henderson 
869b2167459SRichard Henderson     /* Compute signed overflow if required.  */
870b2167459SRichard Henderson     TCGV_UNUSED(sv);
871b2167459SRichard Henderson     if (is_tsv || c == 6) {
872b2167459SRichard Henderson         sv = do_add_sv(ctx, dest, in1, in2);
873b2167459SRichard Henderson         if (is_tsv) {
874b2167459SRichard Henderson             /* ??? Need to include overflow from shift.  */
875b2167459SRichard Henderson             gen_helper_tsv(cpu_env, sv);
876b2167459SRichard Henderson         }
877b2167459SRichard Henderson     }
878b2167459SRichard Henderson 
879b2167459SRichard Henderson     /* Emit any conditional trap before any writeback.  */
880b2167459SRichard Henderson     cond = do_cond(cf, dest, cb_msb, sv);
881b2167459SRichard Henderson     if (is_tc) {
882b2167459SRichard Henderson         cond_prep(&cond);
883b2167459SRichard Henderson         tmp = tcg_temp_new();
884b2167459SRichard Henderson         tcg_gen_setcond_tl(cond.c, tmp, cond.a0, cond.a1);
885b2167459SRichard Henderson         gen_helper_tcond(cpu_env, tmp);
886b2167459SRichard Henderson         tcg_temp_free(tmp);
887b2167459SRichard Henderson     }
888b2167459SRichard Henderson 
889b2167459SRichard Henderson     /* Write back the result.  */
890b2167459SRichard Henderson     if (!is_l) {
891b2167459SRichard Henderson         save_or_nullify(ctx, cpu_psw_cb, cb);
892b2167459SRichard Henderson         save_or_nullify(ctx, cpu_psw_cb_msb, cb_msb);
893b2167459SRichard Henderson     }
894b2167459SRichard Henderson     save_gpr(ctx, rt, dest);
895b2167459SRichard Henderson     tcg_temp_free(dest);
896b2167459SRichard Henderson 
897b2167459SRichard Henderson     /* Install the new nullification.  */
898b2167459SRichard Henderson     cond_free(&ctx->null_cond);
899b2167459SRichard Henderson     ctx->null_cond = cond;
900*869051eaSRichard Henderson     return DISAS_NEXT;
901b2167459SRichard Henderson }
902b2167459SRichard Henderson 
903*869051eaSRichard Henderson static DisasJumpType do_sub(DisasContext *ctx, unsigned rt, TCGv in1, TCGv in2,
904b2167459SRichard Henderson                             bool is_tsv, bool is_b, bool is_tc, unsigned cf)
905b2167459SRichard Henderson {
906b2167459SRichard Henderson     TCGv dest, sv, cb, cb_msb, zero, tmp;
907b2167459SRichard Henderson     unsigned c = cf >> 1;
908b2167459SRichard Henderson     DisasCond cond;
909b2167459SRichard Henderson 
910b2167459SRichard Henderson     dest = tcg_temp_new();
911b2167459SRichard Henderson     cb = tcg_temp_new();
912b2167459SRichard Henderson     cb_msb = tcg_temp_new();
913b2167459SRichard Henderson 
914b2167459SRichard Henderson     zero = tcg_const_tl(0);
915b2167459SRichard Henderson     if (is_b) {
916b2167459SRichard Henderson         /* DEST,C = IN1 + ~IN2 + C.  */
917b2167459SRichard Henderson         tcg_gen_not_tl(cb, in2);
918b2167459SRichard Henderson         tcg_gen_add2_tl(dest, cb_msb, in1, zero, cpu_psw_cb_msb, zero);
919b2167459SRichard Henderson         tcg_gen_add2_tl(dest, cb_msb, dest, cb_msb, cb, zero);
920b2167459SRichard Henderson         tcg_gen_xor_tl(cb, cb, in1);
921b2167459SRichard Henderson         tcg_gen_xor_tl(cb, cb, dest);
922b2167459SRichard Henderson     } else {
923b2167459SRichard Henderson         /* DEST,C = IN1 + ~IN2 + 1.  We can produce the same result in fewer
924b2167459SRichard Henderson            operations by seeding the high word with 1 and subtracting.  */
925b2167459SRichard Henderson         tcg_gen_movi_tl(cb_msb, 1);
926b2167459SRichard Henderson         tcg_gen_sub2_tl(dest, cb_msb, in1, cb_msb, in2, zero);
927b2167459SRichard Henderson         tcg_gen_eqv_tl(cb, in1, in2);
928b2167459SRichard Henderson         tcg_gen_xor_tl(cb, cb, dest);
929b2167459SRichard Henderson     }
930b2167459SRichard Henderson     tcg_temp_free(zero);
931b2167459SRichard Henderson 
932b2167459SRichard Henderson     /* Compute signed overflow if required.  */
933b2167459SRichard Henderson     TCGV_UNUSED(sv);
934b2167459SRichard Henderson     if (is_tsv || c == 6) {
935b2167459SRichard Henderson         sv = do_sub_sv(ctx, dest, in1, in2);
936b2167459SRichard Henderson         if (is_tsv) {
937b2167459SRichard Henderson             gen_helper_tsv(cpu_env, sv);
938b2167459SRichard Henderson         }
939b2167459SRichard Henderson     }
940b2167459SRichard Henderson 
941b2167459SRichard Henderson     /* Compute the condition.  We cannot use the special case for borrow.  */
942b2167459SRichard Henderson     if (!is_b) {
943b2167459SRichard Henderson         cond = do_sub_cond(cf, dest, in1, in2, sv);
944b2167459SRichard Henderson     } else {
945b2167459SRichard Henderson         cond = do_cond(cf, dest, cb_msb, sv);
946b2167459SRichard Henderson     }
947b2167459SRichard Henderson 
948b2167459SRichard Henderson     /* Emit any conditional trap before any writeback.  */
949b2167459SRichard Henderson     if (is_tc) {
950b2167459SRichard Henderson         cond_prep(&cond);
951b2167459SRichard Henderson         tmp = tcg_temp_new();
952b2167459SRichard Henderson         tcg_gen_setcond_tl(cond.c, tmp, cond.a0, cond.a1);
953b2167459SRichard Henderson         gen_helper_tcond(cpu_env, tmp);
954b2167459SRichard Henderson         tcg_temp_free(tmp);
955b2167459SRichard Henderson     }
956b2167459SRichard Henderson 
957b2167459SRichard Henderson     /* Write back the result.  */
958b2167459SRichard Henderson     save_or_nullify(ctx, cpu_psw_cb, cb);
959b2167459SRichard Henderson     save_or_nullify(ctx, cpu_psw_cb_msb, cb_msb);
960b2167459SRichard Henderson     save_gpr(ctx, rt, dest);
961b2167459SRichard Henderson     tcg_temp_free(dest);
962b2167459SRichard Henderson 
963b2167459SRichard Henderson     /* Install the new nullification.  */
964b2167459SRichard Henderson     cond_free(&ctx->null_cond);
965b2167459SRichard Henderson     ctx->null_cond = cond;
966*869051eaSRichard Henderson     return DISAS_NEXT;
967b2167459SRichard Henderson }
968b2167459SRichard Henderson 
969*869051eaSRichard Henderson static DisasJumpType do_cmpclr(DisasContext *ctx, unsigned rt, TCGv in1,
970b2167459SRichard Henderson                                TCGv in2, unsigned cf)
971b2167459SRichard Henderson {
972b2167459SRichard Henderson     TCGv dest, sv;
973b2167459SRichard Henderson     DisasCond cond;
974b2167459SRichard Henderson 
975b2167459SRichard Henderson     dest = tcg_temp_new();
976b2167459SRichard Henderson     tcg_gen_sub_tl(dest, in1, in2);
977b2167459SRichard Henderson 
978b2167459SRichard Henderson     /* Compute signed overflow if required.  */
979b2167459SRichard Henderson     TCGV_UNUSED(sv);
980b2167459SRichard Henderson     if ((cf >> 1) == 6) {
981b2167459SRichard Henderson         sv = do_sub_sv(ctx, dest, in1, in2);
982b2167459SRichard Henderson     }
983b2167459SRichard Henderson 
984b2167459SRichard Henderson     /* Form the condition for the compare.  */
985b2167459SRichard Henderson     cond = do_sub_cond(cf, dest, in1, in2, sv);
986b2167459SRichard Henderson 
987b2167459SRichard Henderson     /* Clear.  */
988b2167459SRichard Henderson     tcg_gen_movi_tl(dest, 0);
989b2167459SRichard Henderson     save_gpr(ctx, rt, dest);
990b2167459SRichard Henderson     tcg_temp_free(dest);
991b2167459SRichard Henderson 
992b2167459SRichard Henderson     /* Install the new nullification.  */
993b2167459SRichard Henderson     cond_free(&ctx->null_cond);
994b2167459SRichard Henderson     ctx->null_cond = cond;
995*869051eaSRichard Henderson     return DISAS_NEXT;
996b2167459SRichard Henderson }
997b2167459SRichard Henderson 
998*869051eaSRichard Henderson static DisasJumpType do_log(DisasContext *ctx, unsigned rt, TCGv in1, TCGv in2,
999b2167459SRichard Henderson                             unsigned cf, void (*fn)(TCGv, TCGv, TCGv))
1000b2167459SRichard Henderson {
1001b2167459SRichard Henderson     TCGv dest = dest_gpr(ctx, rt);
1002b2167459SRichard Henderson 
1003b2167459SRichard Henderson     /* Perform the operation, and writeback.  */
1004b2167459SRichard Henderson     fn(dest, in1, in2);
1005b2167459SRichard Henderson     save_gpr(ctx, rt, dest);
1006b2167459SRichard Henderson 
1007b2167459SRichard Henderson     /* Install the new nullification.  */
1008b2167459SRichard Henderson     cond_free(&ctx->null_cond);
1009b2167459SRichard Henderson     if (cf) {
1010b2167459SRichard Henderson         ctx->null_cond = do_log_cond(cf, dest);
1011b2167459SRichard Henderson     }
1012*869051eaSRichard Henderson     return DISAS_NEXT;
1013b2167459SRichard Henderson }
1014b2167459SRichard Henderson 
1015*869051eaSRichard Henderson static DisasJumpType do_unit(DisasContext *ctx, unsigned rt, TCGv in1,
1016b2167459SRichard Henderson                              TCGv in2, unsigned cf, bool is_tc,
1017b2167459SRichard Henderson                              void (*fn)(TCGv, TCGv, TCGv))
1018b2167459SRichard Henderson {
1019b2167459SRichard Henderson     TCGv dest;
1020b2167459SRichard Henderson     DisasCond cond;
1021b2167459SRichard Henderson 
1022b2167459SRichard Henderson     if (cf == 0) {
1023b2167459SRichard Henderson         dest = dest_gpr(ctx, rt);
1024b2167459SRichard Henderson         fn(dest, in1, in2);
1025b2167459SRichard Henderson         save_gpr(ctx, rt, dest);
1026b2167459SRichard Henderson         cond_free(&ctx->null_cond);
1027b2167459SRichard Henderson     } else {
1028b2167459SRichard Henderson         dest = tcg_temp_new();
1029b2167459SRichard Henderson         fn(dest, in1, in2);
1030b2167459SRichard Henderson 
1031b2167459SRichard Henderson         cond = do_unit_cond(cf, dest, in1, in2);
1032b2167459SRichard Henderson 
1033b2167459SRichard Henderson         if (is_tc) {
1034b2167459SRichard Henderson             TCGv tmp = tcg_temp_new();
1035b2167459SRichard Henderson             cond_prep(&cond);
1036b2167459SRichard Henderson             tcg_gen_setcond_tl(cond.c, tmp, cond.a0, cond.a1);
1037b2167459SRichard Henderson             gen_helper_tcond(cpu_env, tmp);
1038b2167459SRichard Henderson             tcg_temp_free(tmp);
1039b2167459SRichard Henderson         }
1040b2167459SRichard Henderson         save_gpr(ctx, rt, dest);
1041b2167459SRichard Henderson 
1042b2167459SRichard Henderson         cond_free(&ctx->null_cond);
1043b2167459SRichard Henderson         ctx->null_cond = cond;
1044b2167459SRichard Henderson     }
1045*869051eaSRichard Henderson     return DISAS_NEXT;
1046b2167459SRichard Henderson }
1047b2167459SRichard Henderson 
104896d6407fSRichard Henderson /* Emit a memory load.  The modify parameter should be
104996d6407fSRichard Henderson  * < 0 for pre-modify,
105096d6407fSRichard Henderson  * > 0 for post-modify,
105196d6407fSRichard Henderson  * = 0 for no base register update.
105296d6407fSRichard Henderson  */
105396d6407fSRichard Henderson static void do_load_32(DisasContext *ctx, TCGv_i32 dest, unsigned rb,
105496d6407fSRichard Henderson                        unsigned rx, int scale, target_long disp,
105596d6407fSRichard Henderson                        int modify, TCGMemOp mop)
105696d6407fSRichard Henderson {
105796d6407fSRichard Henderson     TCGv addr, base;
105896d6407fSRichard Henderson 
105996d6407fSRichard Henderson     /* Caller uses nullify_over/nullify_end.  */
106096d6407fSRichard Henderson     assert(ctx->null_cond.c == TCG_COND_NEVER);
106196d6407fSRichard Henderson 
106296d6407fSRichard Henderson     addr = tcg_temp_new();
106396d6407fSRichard Henderson     base = load_gpr(ctx, rb);
106496d6407fSRichard Henderson 
106596d6407fSRichard Henderson     /* Note that RX is mutually exclusive with DISP.  */
106696d6407fSRichard Henderson     if (rx) {
106796d6407fSRichard Henderson         tcg_gen_shli_tl(addr, cpu_gr[rx], scale);
106896d6407fSRichard Henderson         tcg_gen_add_tl(addr, addr, base);
106996d6407fSRichard Henderson     } else {
107096d6407fSRichard Henderson         tcg_gen_addi_tl(addr, base, disp);
107196d6407fSRichard Henderson     }
107296d6407fSRichard Henderson 
107396d6407fSRichard Henderson     if (modify == 0) {
107496d6407fSRichard Henderson         tcg_gen_qemu_ld_i32(dest, addr, MMU_USER_IDX, mop);
107596d6407fSRichard Henderson     } else {
107696d6407fSRichard Henderson         tcg_gen_qemu_ld_i32(dest, (modify < 0 ? addr : base),
107796d6407fSRichard Henderson                             MMU_USER_IDX, mop);
107896d6407fSRichard Henderson         save_gpr(ctx, rb, addr);
107996d6407fSRichard Henderson     }
108096d6407fSRichard Henderson     tcg_temp_free(addr);
108196d6407fSRichard Henderson }
108296d6407fSRichard Henderson 
108396d6407fSRichard Henderson static void do_load_64(DisasContext *ctx, TCGv_i64 dest, unsigned rb,
108496d6407fSRichard Henderson                        unsigned rx, int scale, target_long disp,
108596d6407fSRichard Henderson                        int modify, TCGMemOp mop)
108696d6407fSRichard Henderson {
108796d6407fSRichard Henderson     TCGv addr, base;
108896d6407fSRichard Henderson 
108996d6407fSRichard Henderson     /* Caller uses nullify_over/nullify_end.  */
109096d6407fSRichard Henderson     assert(ctx->null_cond.c == TCG_COND_NEVER);
109196d6407fSRichard Henderson 
109296d6407fSRichard Henderson     addr = tcg_temp_new();
109396d6407fSRichard Henderson     base = load_gpr(ctx, rb);
109496d6407fSRichard Henderson 
109596d6407fSRichard Henderson     /* Note that RX is mutually exclusive with DISP.  */
109696d6407fSRichard Henderson     if (rx) {
109796d6407fSRichard Henderson         tcg_gen_shli_tl(addr, cpu_gr[rx], scale);
109896d6407fSRichard Henderson         tcg_gen_add_tl(addr, addr, base);
109996d6407fSRichard Henderson     } else {
110096d6407fSRichard Henderson         tcg_gen_addi_tl(addr, base, disp);
110196d6407fSRichard Henderson     }
110296d6407fSRichard Henderson 
110396d6407fSRichard Henderson     if (modify == 0) {
110496d6407fSRichard Henderson         tcg_gen_qemu_ld_i64(dest, addr, MMU_USER_IDX, mop);
110596d6407fSRichard Henderson     } else {
110696d6407fSRichard Henderson         tcg_gen_qemu_ld_i64(dest, (modify < 0 ? addr : base),
110796d6407fSRichard Henderson                             MMU_USER_IDX, mop);
110896d6407fSRichard Henderson         save_gpr(ctx, rb, addr);
110996d6407fSRichard Henderson     }
111096d6407fSRichard Henderson     tcg_temp_free(addr);
111196d6407fSRichard Henderson }
111296d6407fSRichard Henderson 
111396d6407fSRichard Henderson static void do_store_32(DisasContext *ctx, TCGv_i32 src, unsigned rb,
111496d6407fSRichard Henderson                         unsigned rx, int scale, target_long disp,
111596d6407fSRichard Henderson                         int modify, TCGMemOp mop)
111696d6407fSRichard Henderson {
111796d6407fSRichard Henderson     TCGv addr, base;
111896d6407fSRichard Henderson 
111996d6407fSRichard Henderson     /* Caller uses nullify_over/nullify_end.  */
112096d6407fSRichard Henderson     assert(ctx->null_cond.c == TCG_COND_NEVER);
112196d6407fSRichard Henderson 
112296d6407fSRichard Henderson     addr = tcg_temp_new();
112396d6407fSRichard Henderson     base = load_gpr(ctx, rb);
112496d6407fSRichard Henderson 
112596d6407fSRichard Henderson     /* Note that RX is mutually exclusive with DISP.  */
112696d6407fSRichard Henderson     if (rx) {
112796d6407fSRichard Henderson         tcg_gen_shli_tl(addr, cpu_gr[rx], scale);
112896d6407fSRichard Henderson         tcg_gen_add_tl(addr, addr, base);
112996d6407fSRichard Henderson     } else {
113096d6407fSRichard Henderson         tcg_gen_addi_tl(addr, base, disp);
113196d6407fSRichard Henderson     }
113296d6407fSRichard Henderson 
113396d6407fSRichard Henderson     tcg_gen_qemu_st_i32(src, (modify <= 0 ? addr : base), MMU_USER_IDX, mop);
113496d6407fSRichard Henderson 
113596d6407fSRichard Henderson     if (modify != 0) {
113696d6407fSRichard Henderson         save_gpr(ctx, rb, addr);
113796d6407fSRichard Henderson     }
113896d6407fSRichard Henderson     tcg_temp_free(addr);
113996d6407fSRichard Henderson }
114096d6407fSRichard Henderson 
114196d6407fSRichard Henderson static void do_store_64(DisasContext *ctx, TCGv_i64 src, unsigned rb,
114296d6407fSRichard Henderson                         unsigned rx, int scale, target_long disp,
114396d6407fSRichard Henderson                         int modify, TCGMemOp mop)
114496d6407fSRichard Henderson {
114596d6407fSRichard Henderson     TCGv addr, base;
114696d6407fSRichard Henderson 
114796d6407fSRichard Henderson     /* Caller uses nullify_over/nullify_end.  */
114896d6407fSRichard Henderson     assert(ctx->null_cond.c == TCG_COND_NEVER);
114996d6407fSRichard Henderson 
115096d6407fSRichard Henderson     addr = tcg_temp_new();
115196d6407fSRichard Henderson     base = load_gpr(ctx, rb);
115296d6407fSRichard Henderson 
115396d6407fSRichard Henderson     /* Note that RX is mutually exclusive with DISP.  */
115496d6407fSRichard Henderson     if (rx) {
115596d6407fSRichard Henderson         tcg_gen_shli_tl(addr, cpu_gr[rx], scale);
115696d6407fSRichard Henderson         tcg_gen_add_tl(addr, addr, base);
115796d6407fSRichard Henderson     } else {
115896d6407fSRichard Henderson         tcg_gen_addi_tl(addr, base, disp);
115996d6407fSRichard Henderson     }
116096d6407fSRichard Henderson 
116196d6407fSRichard Henderson     tcg_gen_qemu_st_i64(src, (modify <= 0 ? addr : base), MMU_USER_IDX, mop);
116296d6407fSRichard Henderson 
116396d6407fSRichard Henderson     if (modify != 0) {
116496d6407fSRichard Henderson         save_gpr(ctx, rb, addr);
116596d6407fSRichard Henderson     }
116696d6407fSRichard Henderson     tcg_temp_free(addr);
116796d6407fSRichard Henderson }
116896d6407fSRichard Henderson 
116996d6407fSRichard Henderson #if TARGET_LONG_BITS == 64
117096d6407fSRichard Henderson #define do_load_tl  do_load_64
117196d6407fSRichard Henderson #define do_store_tl do_store_64
117296d6407fSRichard Henderson #else
117396d6407fSRichard Henderson #define do_load_tl  do_load_32
117496d6407fSRichard Henderson #define do_store_tl do_store_32
117596d6407fSRichard Henderson #endif
117696d6407fSRichard Henderson 
1177*869051eaSRichard Henderson static DisasJumpType do_load(DisasContext *ctx, unsigned rt, unsigned rb,
117896d6407fSRichard Henderson                              unsigned rx, int scale, target_long disp,
117996d6407fSRichard Henderson                              int modify, TCGMemOp mop)
118096d6407fSRichard Henderson {
118196d6407fSRichard Henderson     TCGv dest;
118296d6407fSRichard Henderson 
118396d6407fSRichard Henderson     nullify_over(ctx);
118496d6407fSRichard Henderson 
118596d6407fSRichard Henderson     if (modify == 0) {
118696d6407fSRichard Henderson         /* No base register update.  */
118796d6407fSRichard Henderson         dest = dest_gpr(ctx, rt);
118896d6407fSRichard Henderson     } else {
118996d6407fSRichard Henderson         /* Make sure if RT == RB, we see the result of the load.  */
119096d6407fSRichard Henderson         dest = get_temp(ctx);
119196d6407fSRichard Henderson     }
119296d6407fSRichard Henderson     do_load_tl(ctx, dest, rb, rx, scale, disp, modify, mop);
119396d6407fSRichard Henderson     save_gpr(ctx, rt, dest);
119496d6407fSRichard Henderson 
1195*869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
119696d6407fSRichard Henderson }
119796d6407fSRichard Henderson 
1198*869051eaSRichard Henderson static DisasJumpType do_floadw(DisasContext *ctx, unsigned rt, unsigned rb,
119996d6407fSRichard Henderson                                unsigned rx, int scale, target_long disp,
120096d6407fSRichard Henderson                                int modify)
120196d6407fSRichard Henderson {
120296d6407fSRichard Henderson     TCGv_i32 tmp;
120396d6407fSRichard Henderson 
120496d6407fSRichard Henderson     nullify_over(ctx);
120596d6407fSRichard Henderson 
120696d6407fSRichard Henderson     tmp = tcg_temp_new_i32();
120796d6407fSRichard Henderson     do_load_32(ctx, tmp, rb, rx, scale, disp, modify, MO_TEUL);
120896d6407fSRichard Henderson     save_frw_i32(rt, tmp);
120996d6407fSRichard Henderson     tcg_temp_free_i32(tmp);
121096d6407fSRichard Henderson 
121196d6407fSRichard Henderson     if (rt == 0) {
121296d6407fSRichard Henderson         gen_helper_loaded_fr0(cpu_env);
121396d6407fSRichard Henderson     }
121496d6407fSRichard Henderson 
1215*869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
121696d6407fSRichard Henderson }
121796d6407fSRichard Henderson 
1218*869051eaSRichard Henderson static DisasJumpType do_floadd(DisasContext *ctx, unsigned rt, unsigned rb,
121996d6407fSRichard Henderson                                unsigned rx, int scale, target_long disp,
122096d6407fSRichard Henderson                                int modify)
122196d6407fSRichard Henderson {
122296d6407fSRichard Henderson     TCGv_i64 tmp;
122396d6407fSRichard Henderson 
122496d6407fSRichard Henderson     nullify_over(ctx);
122596d6407fSRichard Henderson 
122696d6407fSRichard Henderson     tmp = tcg_temp_new_i64();
122796d6407fSRichard Henderson     do_load_64(ctx, tmp, rb, rx, scale, disp, modify, MO_TEQ);
122896d6407fSRichard Henderson     save_frd(rt, tmp);
122996d6407fSRichard Henderson     tcg_temp_free_i64(tmp);
123096d6407fSRichard Henderson 
123196d6407fSRichard Henderson     if (rt == 0) {
123296d6407fSRichard Henderson         gen_helper_loaded_fr0(cpu_env);
123396d6407fSRichard Henderson     }
123496d6407fSRichard Henderson 
1235*869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
123696d6407fSRichard Henderson }
123796d6407fSRichard Henderson 
1238*869051eaSRichard Henderson static DisasJumpType do_store(DisasContext *ctx, unsigned rt, unsigned rb,
123996d6407fSRichard Henderson                               target_long disp, int modify, TCGMemOp mop)
124096d6407fSRichard Henderson {
124196d6407fSRichard Henderson     nullify_over(ctx);
124296d6407fSRichard Henderson     do_store_tl(ctx, load_gpr(ctx, rt), rb, 0, 0, disp, modify, mop);
1243*869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
124496d6407fSRichard Henderson }
124596d6407fSRichard Henderson 
1246*869051eaSRichard Henderson static DisasJumpType do_fstorew(DisasContext *ctx, unsigned rt, unsigned rb,
124796d6407fSRichard Henderson                                 unsigned rx, int scale, target_long disp,
124896d6407fSRichard Henderson                                 int modify)
124996d6407fSRichard Henderson {
125096d6407fSRichard Henderson     TCGv_i32 tmp;
125196d6407fSRichard Henderson 
125296d6407fSRichard Henderson     nullify_over(ctx);
125396d6407fSRichard Henderson 
125496d6407fSRichard Henderson     tmp = load_frw_i32(rt);
125596d6407fSRichard Henderson     do_store_32(ctx, tmp, rb, rx, scale, disp, modify, MO_TEUL);
125696d6407fSRichard Henderson     tcg_temp_free_i32(tmp);
125796d6407fSRichard Henderson 
1258*869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
125996d6407fSRichard Henderson }
126096d6407fSRichard Henderson 
1261*869051eaSRichard Henderson static DisasJumpType do_fstored(DisasContext *ctx, unsigned rt, unsigned rb,
126296d6407fSRichard Henderson                                 unsigned rx, int scale, target_long disp,
126396d6407fSRichard Henderson                                 int modify)
126496d6407fSRichard Henderson {
126596d6407fSRichard Henderson     TCGv_i64 tmp;
126696d6407fSRichard Henderson 
126796d6407fSRichard Henderson     nullify_over(ctx);
126896d6407fSRichard Henderson 
126996d6407fSRichard Henderson     tmp = load_frd(rt);
127096d6407fSRichard Henderson     do_store_64(ctx, tmp, rb, rx, scale, disp, modify, MO_TEQ);
127196d6407fSRichard Henderson     tcg_temp_free_i64(tmp);
127296d6407fSRichard Henderson 
1273*869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
127496d6407fSRichard Henderson }
127596d6407fSRichard Henderson 
1276*869051eaSRichard Henderson static DisasJumpType do_fop_wew(DisasContext *ctx, unsigned rt, unsigned ra,
1277ebe9383cSRichard Henderson                                 void (*func)(TCGv_i32, TCGv_env, TCGv_i32))
1278ebe9383cSRichard Henderson {
1279ebe9383cSRichard Henderson     TCGv_i32 tmp;
1280ebe9383cSRichard Henderson 
1281ebe9383cSRichard Henderson     nullify_over(ctx);
1282ebe9383cSRichard Henderson     tmp = load_frw0_i32(ra);
1283ebe9383cSRichard Henderson 
1284ebe9383cSRichard Henderson     func(tmp, cpu_env, tmp);
1285ebe9383cSRichard Henderson 
1286ebe9383cSRichard Henderson     save_frw_i32(rt, tmp);
1287ebe9383cSRichard Henderson     tcg_temp_free_i32(tmp);
1288*869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
1289ebe9383cSRichard Henderson }
1290ebe9383cSRichard Henderson 
1291*869051eaSRichard Henderson static DisasJumpType do_fop_wed(DisasContext *ctx, unsigned rt, unsigned ra,
1292ebe9383cSRichard Henderson                                 void (*func)(TCGv_i32, TCGv_env, TCGv_i64))
1293ebe9383cSRichard Henderson {
1294ebe9383cSRichard Henderson     TCGv_i32 dst;
1295ebe9383cSRichard Henderson     TCGv_i64 src;
1296ebe9383cSRichard Henderson 
1297ebe9383cSRichard Henderson     nullify_over(ctx);
1298ebe9383cSRichard Henderson     src = load_frd(ra);
1299ebe9383cSRichard Henderson     dst = tcg_temp_new_i32();
1300ebe9383cSRichard Henderson 
1301ebe9383cSRichard Henderson     func(dst, cpu_env, src);
1302ebe9383cSRichard Henderson 
1303ebe9383cSRichard Henderson     tcg_temp_free_i64(src);
1304ebe9383cSRichard Henderson     save_frw_i32(rt, dst);
1305ebe9383cSRichard Henderson     tcg_temp_free_i32(dst);
1306*869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
1307ebe9383cSRichard Henderson }
1308ebe9383cSRichard Henderson 
1309*869051eaSRichard Henderson static DisasJumpType do_fop_ded(DisasContext *ctx, unsigned rt, unsigned ra,
1310ebe9383cSRichard Henderson                                 void (*func)(TCGv_i64, TCGv_env, TCGv_i64))
1311ebe9383cSRichard Henderson {
1312ebe9383cSRichard Henderson     TCGv_i64 tmp;
1313ebe9383cSRichard Henderson 
1314ebe9383cSRichard Henderson     nullify_over(ctx);
1315ebe9383cSRichard Henderson     tmp = load_frd0(ra);
1316ebe9383cSRichard Henderson 
1317ebe9383cSRichard Henderson     func(tmp, cpu_env, tmp);
1318ebe9383cSRichard Henderson 
1319ebe9383cSRichard Henderson     save_frd(rt, tmp);
1320ebe9383cSRichard Henderson     tcg_temp_free_i64(tmp);
1321*869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
1322ebe9383cSRichard Henderson }
1323ebe9383cSRichard Henderson 
1324*869051eaSRichard Henderson static DisasJumpType do_fop_dew(DisasContext *ctx, unsigned rt, unsigned ra,
1325ebe9383cSRichard Henderson                                 void (*func)(TCGv_i64, TCGv_env, TCGv_i32))
1326ebe9383cSRichard Henderson {
1327ebe9383cSRichard Henderson     TCGv_i32 src;
1328ebe9383cSRichard Henderson     TCGv_i64 dst;
1329ebe9383cSRichard Henderson 
1330ebe9383cSRichard Henderson     nullify_over(ctx);
1331ebe9383cSRichard Henderson     src = load_frw0_i32(ra);
1332ebe9383cSRichard Henderson     dst = tcg_temp_new_i64();
1333ebe9383cSRichard Henderson 
1334ebe9383cSRichard Henderson     func(dst, cpu_env, src);
1335ebe9383cSRichard Henderson 
1336ebe9383cSRichard Henderson     tcg_temp_free_i32(src);
1337ebe9383cSRichard Henderson     save_frd(rt, dst);
1338ebe9383cSRichard Henderson     tcg_temp_free_i64(dst);
1339*869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
1340ebe9383cSRichard Henderson }
1341ebe9383cSRichard Henderson 
1342*869051eaSRichard Henderson static DisasJumpType do_fop_weww(DisasContext *ctx, unsigned rt,
1343ebe9383cSRichard Henderson                                  unsigned ra, unsigned rb,
1344ebe9383cSRichard Henderson                                  void (*func)(TCGv_i32, TCGv_env,
1345ebe9383cSRichard Henderson                                               TCGv_i32, TCGv_i32))
1346ebe9383cSRichard Henderson {
1347ebe9383cSRichard Henderson     TCGv_i32 a, b;
1348ebe9383cSRichard Henderson 
1349ebe9383cSRichard Henderson     nullify_over(ctx);
1350ebe9383cSRichard Henderson     a = load_frw0_i32(ra);
1351ebe9383cSRichard Henderson     b = load_frw0_i32(rb);
1352ebe9383cSRichard Henderson 
1353ebe9383cSRichard Henderson     func(a, cpu_env, a, b);
1354ebe9383cSRichard Henderson 
1355ebe9383cSRichard Henderson     tcg_temp_free_i32(b);
1356ebe9383cSRichard Henderson     save_frw_i32(rt, a);
1357ebe9383cSRichard Henderson     tcg_temp_free_i32(a);
1358*869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
1359ebe9383cSRichard Henderson }
1360ebe9383cSRichard Henderson 
1361*869051eaSRichard Henderson static DisasJumpType do_fop_dedd(DisasContext *ctx, unsigned rt,
1362ebe9383cSRichard Henderson                                  unsigned ra, unsigned rb,
1363ebe9383cSRichard Henderson                                  void (*func)(TCGv_i64, TCGv_env,
1364ebe9383cSRichard Henderson                                               TCGv_i64, TCGv_i64))
1365ebe9383cSRichard Henderson {
1366ebe9383cSRichard Henderson     TCGv_i64 a, b;
1367ebe9383cSRichard Henderson 
1368ebe9383cSRichard Henderson     nullify_over(ctx);
1369ebe9383cSRichard Henderson     a = load_frd0(ra);
1370ebe9383cSRichard Henderson     b = load_frd0(rb);
1371ebe9383cSRichard Henderson 
1372ebe9383cSRichard Henderson     func(a, cpu_env, a, b);
1373ebe9383cSRichard Henderson 
1374ebe9383cSRichard Henderson     tcg_temp_free_i64(b);
1375ebe9383cSRichard Henderson     save_frd(rt, a);
1376ebe9383cSRichard Henderson     tcg_temp_free_i64(a);
1377*869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
1378ebe9383cSRichard Henderson }
1379ebe9383cSRichard Henderson 
138098cd9ca7SRichard Henderson /* Emit an unconditional branch to a direct target, which may or may not
138198cd9ca7SRichard Henderson    have already had nullification handled.  */
1382*869051eaSRichard Henderson static DisasJumpType do_dbranch(DisasContext *ctx, target_ulong dest,
138398cd9ca7SRichard Henderson                                 unsigned link, bool is_n)
138498cd9ca7SRichard Henderson {
138598cd9ca7SRichard Henderson     if (ctx->null_cond.c == TCG_COND_NEVER && ctx->null_lab == NULL) {
138698cd9ca7SRichard Henderson         if (link != 0) {
138798cd9ca7SRichard Henderson             copy_iaoq_entry(cpu_gr[link], ctx->iaoq_n, ctx->iaoq_n_var);
138898cd9ca7SRichard Henderson         }
138998cd9ca7SRichard Henderson         ctx->iaoq_n = dest;
139098cd9ca7SRichard Henderson         if (is_n) {
139198cd9ca7SRichard Henderson             ctx->null_cond.c = TCG_COND_ALWAYS;
139298cd9ca7SRichard Henderson         }
1393*869051eaSRichard Henderson         return DISAS_NEXT;
139498cd9ca7SRichard Henderson     } else {
139598cd9ca7SRichard Henderson         nullify_over(ctx);
139698cd9ca7SRichard Henderson 
139798cd9ca7SRichard Henderson         if (link != 0) {
139898cd9ca7SRichard Henderson             copy_iaoq_entry(cpu_gr[link], ctx->iaoq_n, ctx->iaoq_n_var);
139998cd9ca7SRichard Henderson         }
140098cd9ca7SRichard Henderson 
140198cd9ca7SRichard Henderson         if (is_n && use_nullify_skip(ctx)) {
140298cd9ca7SRichard Henderson             nullify_set(ctx, 0);
140398cd9ca7SRichard Henderson             gen_goto_tb(ctx, 0, dest, dest + 4);
140498cd9ca7SRichard Henderson         } else {
140598cd9ca7SRichard Henderson             nullify_set(ctx, is_n);
140698cd9ca7SRichard Henderson             gen_goto_tb(ctx, 0, ctx->iaoq_b, dest);
140798cd9ca7SRichard Henderson         }
140898cd9ca7SRichard Henderson 
1409*869051eaSRichard Henderson         nullify_end(ctx, DISAS_NEXT);
141098cd9ca7SRichard Henderson 
141198cd9ca7SRichard Henderson         nullify_set(ctx, 0);
141298cd9ca7SRichard Henderson         gen_goto_tb(ctx, 1, ctx->iaoq_b, ctx->iaoq_n);
1413*869051eaSRichard Henderson         return DISAS_NORETURN;
141498cd9ca7SRichard Henderson     }
141598cd9ca7SRichard Henderson }
141698cd9ca7SRichard Henderson 
141798cd9ca7SRichard Henderson /* Emit a conditional branch to a direct target.  If the branch itself
141898cd9ca7SRichard Henderson    is nullified, we should have already used nullify_over.  */
1419*869051eaSRichard Henderson static DisasJumpType do_cbranch(DisasContext *ctx, target_long disp, bool is_n,
142098cd9ca7SRichard Henderson                                 DisasCond *cond)
142198cd9ca7SRichard Henderson {
142298cd9ca7SRichard Henderson     target_ulong dest = iaoq_dest(ctx, disp);
142398cd9ca7SRichard Henderson     TCGLabel *taken = NULL;
142498cd9ca7SRichard Henderson     TCGCond c = cond->c;
142598cd9ca7SRichard Henderson     bool n;
142698cd9ca7SRichard Henderson 
142798cd9ca7SRichard Henderson     assert(ctx->null_cond.c == TCG_COND_NEVER);
142898cd9ca7SRichard Henderson 
142998cd9ca7SRichard Henderson     /* Handle TRUE and NEVER as direct branches.  */
143098cd9ca7SRichard Henderson     if (c == TCG_COND_ALWAYS) {
143198cd9ca7SRichard Henderson         return do_dbranch(ctx, dest, 0, is_n && disp >= 0);
143298cd9ca7SRichard Henderson     }
143398cd9ca7SRichard Henderson     if (c == TCG_COND_NEVER) {
143498cd9ca7SRichard Henderson         return do_dbranch(ctx, ctx->iaoq_n, 0, is_n && disp < 0);
143598cd9ca7SRichard Henderson     }
143698cd9ca7SRichard Henderson 
143798cd9ca7SRichard Henderson     taken = gen_new_label();
143898cd9ca7SRichard Henderson     cond_prep(cond);
143998cd9ca7SRichard Henderson     tcg_gen_brcond_tl(c, cond->a0, cond->a1, taken);
144098cd9ca7SRichard Henderson     cond_free(cond);
144198cd9ca7SRichard Henderson 
144298cd9ca7SRichard Henderson     /* Not taken: Condition not satisfied; nullify on backward branches. */
144398cd9ca7SRichard Henderson     n = is_n && disp < 0;
144498cd9ca7SRichard Henderson     if (n && use_nullify_skip(ctx)) {
144598cd9ca7SRichard Henderson         nullify_set(ctx, 0);
1446a881c8e7SRichard Henderson         gen_goto_tb(ctx, 0, ctx->iaoq_n, ctx->iaoq_n + 4);
144798cd9ca7SRichard Henderson     } else {
144898cd9ca7SRichard Henderson         if (!n && ctx->null_lab) {
144998cd9ca7SRichard Henderson             gen_set_label(ctx->null_lab);
145098cd9ca7SRichard Henderson             ctx->null_lab = NULL;
145198cd9ca7SRichard Henderson         }
145298cd9ca7SRichard Henderson         nullify_set(ctx, n);
1453a881c8e7SRichard Henderson         gen_goto_tb(ctx, 0, ctx->iaoq_b, ctx->iaoq_n);
145498cd9ca7SRichard Henderson     }
145598cd9ca7SRichard Henderson 
145698cd9ca7SRichard Henderson     gen_set_label(taken);
145798cd9ca7SRichard Henderson 
145898cd9ca7SRichard Henderson     /* Taken: Condition satisfied; nullify on forward branches.  */
145998cd9ca7SRichard Henderson     n = is_n && disp >= 0;
146098cd9ca7SRichard Henderson     if (n && use_nullify_skip(ctx)) {
146198cd9ca7SRichard Henderson         nullify_set(ctx, 0);
1462a881c8e7SRichard Henderson         gen_goto_tb(ctx, 1, dest, dest + 4);
146398cd9ca7SRichard Henderson     } else {
146498cd9ca7SRichard Henderson         nullify_set(ctx, n);
1465a881c8e7SRichard Henderson         gen_goto_tb(ctx, 1, ctx->iaoq_b, dest);
146698cd9ca7SRichard Henderson     }
146798cd9ca7SRichard Henderson 
146898cd9ca7SRichard Henderson     /* Not taken: the branch itself was nullified.  */
146998cd9ca7SRichard Henderson     if (ctx->null_lab) {
147098cd9ca7SRichard Henderson         gen_set_label(ctx->null_lab);
147198cd9ca7SRichard Henderson         ctx->null_lab = NULL;
1472*869051eaSRichard Henderson         return DISAS_IAQ_N_STALE;
147398cd9ca7SRichard Henderson     } else {
1474*869051eaSRichard Henderson         return DISAS_NORETURN;
147598cd9ca7SRichard Henderson     }
147698cd9ca7SRichard Henderson }
147798cd9ca7SRichard Henderson 
147898cd9ca7SRichard Henderson /* Emit an unconditional branch to an indirect target.  This handles
147998cd9ca7SRichard Henderson    nullification of the branch itself.  */
1480*869051eaSRichard Henderson static DisasJumpType do_ibranch(DisasContext *ctx, TCGv dest,
148198cd9ca7SRichard Henderson                                 unsigned link, bool is_n)
148298cd9ca7SRichard Henderson {
148398cd9ca7SRichard Henderson     TCGv a0, a1, next, tmp;
148498cd9ca7SRichard Henderson     TCGCond c;
148598cd9ca7SRichard Henderson 
148698cd9ca7SRichard Henderson     assert(ctx->null_lab == NULL);
148798cd9ca7SRichard Henderson 
148898cd9ca7SRichard Henderson     if (ctx->null_cond.c == TCG_COND_NEVER) {
148998cd9ca7SRichard Henderson         if (link != 0) {
149098cd9ca7SRichard Henderson             copy_iaoq_entry(cpu_gr[link], ctx->iaoq_n, ctx->iaoq_n_var);
149198cd9ca7SRichard Henderson         }
149298cd9ca7SRichard Henderson         next = get_temp(ctx);
149398cd9ca7SRichard Henderson         tcg_gen_mov_tl(next, dest);
149498cd9ca7SRichard Henderson         ctx->iaoq_n = -1;
149598cd9ca7SRichard Henderson         ctx->iaoq_n_var = next;
149698cd9ca7SRichard Henderson         if (is_n) {
149798cd9ca7SRichard Henderson             ctx->null_cond.c = TCG_COND_ALWAYS;
149898cd9ca7SRichard Henderson         }
149998cd9ca7SRichard Henderson     } else if (is_n && use_nullify_skip(ctx)) {
150098cd9ca7SRichard Henderson         /* The (conditional) branch, B, nullifies the next insn, N,
150198cd9ca7SRichard Henderson            and we're allowed to skip execution N (no single-step or
15024137cb83SRichard Henderson            tracepoint in effect).  Since the goto_ptr that we must use
150398cd9ca7SRichard Henderson            for the indirect branch consumes no special resources, we
150498cd9ca7SRichard Henderson            can (conditionally) skip B and continue execution.  */
150598cd9ca7SRichard Henderson         /* The use_nullify_skip test implies we have a known control path.  */
150698cd9ca7SRichard Henderson         tcg_debug_assert(ctx->iaoq_b != -1);
150798cd9ca7SRichard Henderson         tcg_debug_assert(ctx->iaoq_n != -1);
150898cd9ca7SRichard Henderson 
150998cd9ca7SRichard Henderson         /* We do have to handle the non-local temporary, DEST, before
151098cd9ca7SRichard Henderson            branching.  Since IOAQ_F is not really live at this point, we
151198cd9ca7SRichard Henderson            can simply store DEST optimistically.  Similarly with IAOQ_B.  */
151298cd9ca7SRichard Henderson         tcg_gen_mov_tl(cpu_iaoq_f, dest);
151398cd9ca7SRichard Henderson         tcg_gen_addi_tl(cpu_iaoq_b, dest, 4);
151498cd9ca7SRichard Henderson 
151598cd9ca7SRichard Henderson         nullify_over(ctx);
151698cd9ca7SRichard Henderson         if (link != 0) {
151798cd9ca7SRichard Henderson             tcg_gen_movi_tl(cpu_gr[link], ctx->iaoq_n);
151898cd9ca7SRichard Henderson         }
15194137cb83SRichard Henderson         tcg_gen_lookup_and_goto_ptr(cpu_iaoq_f);
1520*869051eaSRichard Henderson         return nullify_end(ctx, DISAS_NEXT);
152198cd9ca7SRichard Henderson     } else {
152298cd9ca7SRichard Henderson         cond_prep(&ctx->null_cond);
152398cd9ca7SRichard Henderson         c = ctx->null_cond.c;
152498cd9ca7SRichard Henderson         a0 = ctx->null_cond.a0;
152598cd9ca7SRichard Henderson         a1 = ctx->null_cond.a1;
152698cd9ca7SRichard Henderson 
152798cd9ca7SRichard Henderson         tmp = tcg_temp_new();
152898cd9ca7SRichard Henderson         next = get_temp(ctx);
152998cd9ca7SRichard Henderson 
153098cd9ca7SRichard Henderson         copy_iaoq_entry(tmp, ctx->iaoq_n, ctx->iaoq_n_var);
153198cd9ca7SRichard Henderson         tcg_gen_movcond_tl(c, next, a0, a1, tmp, dest);
153298cd9ca7SRichard Henderson         ctx->iaoq_n = -1;
153398cd9ca7SRichard Henderson         ctx->iaoq_n_var = next;
153498cd9ca7SRichard Henderson 
153598cd9ca7SRichard Henderson         if (link != 0) {
153698cd9ca7SRichard Henderson             tcg_gen_movcond_tl(c, cpu_gr[link], a0, a1, cpu_gr[link], tmp);
153798cd9ca7SRichard Henderson         }
153898cd9ca7SRichard Henderson 
153998cd9ca7SRichard Henderson         if (is_n) {
154098cd9ca7SRichard Henderson             /* The branch nullifies the next insn, which means the state of N
154198cd9ca7SRichard Henderson                after the branch is the inverse of the state of N that applied
154298cd9ca7SRichard Henderson                to the branch.  */
154398cd9ca7SRichard Henderson             tcg_gen_setcond_tl(tcg_invert_cond(c), cpu_psw_n, a0, a1);
154498cd9ca7SRichard Henderson             cond_free(&ctx->null_cond);
154598cd9ca7SRichard Henderson             ctx->null_cond = cond_make_n();
154698cd9ca7SRichard Henderson             ctx->psw_n_nonzero = true;
154798cd9ca7SRichard Henderson         } else {
154898cd9ca7SRichard Henderson             cond_free(&ctx->null_cond);
154998cd9ca7SRichard Henderson         }
155098cd9ca7SRichard Henderson     }
155198cd9ca7SRichard Henderson 
1552*869051eaSRichard Henderson     return DISAS_NEXT;
155398cd9ca7SRichard Henderson }
155498cd9ca7SRichard Henderson 
15557ad439dfSRichard Henderson /* On Linux, page zero is normally marked execute only + gateway.
15567ad439dfSRichard Henderson    Therefore normal read or write is supposed to fail, but specific
15577ad439dfSRichard Henderson    offsets have kernel code mapped to raise permissions to implement
15587ad439dfSRichard Henderson    system calls.  Handling this via an explicit check here, rather
15597ad439dfSRichard Henderson    in than the "be disp(sr2,r0)" instruction that probably sent us
15607ad439dfSRichard Henderson    here, is the easiest way to handle the branch delay slot on the
15617ad439dfSRichard Henderson    aforementioned BE.  */
1562*869051eaSRichard Henderson static DisasJumpType do_page_zero(DisasContext *ctx)
15637ad439dfSRichard Henderson {
15647ad439dfSRichard Henderson     /* If by some means we get here with PSW[N]=1, that implies that
15657ad439dfSRichard Henderson        the B,GATE instruction would be skipped, and we'd fault on the
15667ad439dfSRichard Henderson        next insn within the privilaged page.  */
15677ad439dfSRichard Henderson     switch (ctx->null_cond.c) {
15687ad439dfSRichard Henderson     case TCG_COND_NEVER:
15697ad439dfSRichard Henderson         break;
15707ad439dfSRichard Henderson     case TCG_COND_ALWAYS:
15717ad439dfSRichard Henderson         tcg_gen_movi_tl(cpu_psw_n, 0);
15727ad439dfSRichard Henderson         goto do_sigill;
15737ad439dfSRichard Henderson     default:
15747ad439dfSRichard Henderson         /* Since this is always the first (and only) insn within the
15757ad439dfSRichard Henderson            TB, we should know the state of PSW[N] from TB->FLAGS.  */
15767ad439dfSRichard Henderson         g_assert_not_reached();
15777ad439dfSRichard Henderson     }
15787ad439dfSRichard Henderson 
15797ad439dfSRichard Henderson     /* Check that we didn't arrive here via some means that allowed
15807ad439dfSRichard Henderson        non-sequential instruction execution.  Normally the PSW[B] bit
15817ad439dfSRichard Henderson        detects this by disallowing the B,GATE instruction to execute
15827ad439dfSRichard Henderson        under such conditions.  */
15837ad439dfSRichard Henderson     if (ctx->iaoq_b != ctx->iaoq_f + 4) {
15847ad439dfSRichard Henderson         goto do_sigill;
15857ad439dfSRichard Henderson     }
15867ad439dfSRichard Henderson 
15877ad439dfSRichard Henderson     switch (ctx->iaoq_f) {
15887ad439dfSRichard Henderson     case 0x00: /* Null pointer call */
15897ad439dfSRichard Henderson         gen_excp_1(EXCP_SIGSEGV);
1590*869051eaSRichard Henderson         return DISAS_NORETURN;
15917ad439dfSRichard Henderson 
15927ad439dfSRichard Henderson     case 0xb0: /* LWS */
15937ad439dfSRichard Henderson         gen_excp_1(EXCP_SYSCALL_LWS);
1594*869051eaSRichard Henderson         return DISAS_NORETURN;
15957ad439dfSRichard Henderson 
15967ad439dfSRichard Henderson     case 0xe0: /* SET_THREAD_POINTER */
15977ad439dfSRichard Henderson         tcg_gen_mov_tl(cpu_cr27, cpu_gr[26]);
15987ad439dfSRichard Henderson         tcg_gen_mov_tl(cpu_iaoq_f, cpu_gr[31]);
15997ad439dfSRichard Henderson         tcg_gen_addi_tl(cpu_iaoq_b, cpu_iaoq_f, 4);
1600*869051eaSRichard Henderson         return DISAS_IAQ_N_UPDATED;
16017ad439dfSRichard Henderson 
16027ad439dfSRichard Henderson     case 0x100: /* SYSCALL */
16037ad439dfSRichard Henderson         gen_excp_1(EXCP_SYSCALL);
1604*869051eaSRichard Henderson         return DISAS_NORETURN;
16057ad439dfSRichard Henderson 
16067ad439dfSRichard Henderson     default:
16077ad439dfSRichard Henderson     do_sigill:
16087ad439dfSRichard Henderson         gen_excp_1(EXCP_SIGILL);
1609*869051eaSRichard Henderson         return DISAS_NORETURN;
16107ad439dfSRichard Henderson     }
16117ad439dfSRichard Henderson }
16127ad439dfSRichard Henderson 
1613*869051eaSRichard Henderson static DisasJumpType trans_nop(DisasContext *ctx, uint32_t insn,
1614b2167459SRichard Henderson                                const DisasInsn *di)
1615b2167459SRichard Henderson {
1616b2167459SRichard Henderson     cond_free(&ctx->null_cond);
1617*869051eaSRichard Henderson     return DISAS_NEXT;
1618b2167459SRichard Henderson }
1619b2167459SRichard Henderson 
1620*869051eaSRichard Henderson static DisasJumpType trans_break(DisasContext *ctx, uint32_t insn,
162198a9cb79SRichard Henderson                                  const DisasInsn *di)
162298a9cb79SRichard Henderson {
162398a9cb79SRichard Henderson     nullify_over(ctx);
162498a9cb79SRichard Henderson     return nullify_end(ctx, gen_excp(ctx, EXCP_DEBUG));
162598a9cb79SRichard Henderson }
162698a9cb79SRichard Henderson 
1627*869051eaSRichard Henderson static DisasJumpType trans_sync(DisasContext *ctx, uint32_t insn,
162898a9cb79SRichard Henderson                                 const DisasInsn *di)
162998a9cb79SRichard Henderson {
163098a9cb79SRichard Henderson     /* No point in nullifying the memory barrier.  */
163198a9cb79SRichard Henderson     tcg_gen_mb(TCG_BAR_SC | TCG_MO_ALL);
163298a9cb79SRichard Henderson 
163398a9cb79SRichard Henderson     cond_free(&ctx->null_cond);
1634*869051eaSRichard Henderson     return DISAS_NEXT;
163598a9cb79SRichard Henderson }
163698a9cb79SRichard Henderson 
1637*869051eaSRichard Henderson static DisasJumpType trans_mfia(DisasContext *ctx, uint32_t insn,
163898a9cb79SRichard Henderson                                 const DisasInsn *di)
163998a9cb79SRichard Henderson {
164098a9cb79SRichard Henderson     unsigned rt = extract32(insn, 0, 5);
164198a9cb79SRichard Henderson     TCGv tmp = dest_gpr(ctx, rt);
164298a9cb79SRichard Henderson     tcg_gen_movi_tl(tmp, ctx->iaoq_f);
164398a9cb79SRichard Henderson     save_gpr(ctx, rt, tmp);
164498a9cb79SRichard Henderson 
164598a9cb79SRichard Henderson     cond_free(&ctx->null_cond);
1646*869051eaSRichard Henderson     return DISAS_NEXT;
164798a9cb79SRichard Henderson }
164898a9cb79SRichard Henderson 
1649*869051eaSRichard Henderson static DisasJumpType trans_mfsp(DisasContext *ctx, uint32_t insn,
165098a9cb79SRichard Henderson                                 const DisasInsn *di)
165198a9cb79SRichard Henderson {
165298a9cb79SRichard Henderson     unsigned rt = extract32(insn, 0, 5);
165398a9cb79SRichard Henderson     TCGv tmp = dest_gpr(ctx, rt);
165498a9cb79SRichard Henderson 
165598a9cb79SRichard Henderson     /* ??? We don't implement space registers.  */
165698a9cb79SRichard Henderson     tcg_gen_movi_tl(tmp, 0);
165798a9cb79SRichard Henderson     save_gpr(ctx, rt, tmp);
165898a9cb79SRichard Henderson 
165998a9cb79SRichard Henderson     cond_free(&ctx->null_cond);
1660*869051eaSRichard Henderson     return DISAS_NEXT;
166198a9cb79SRichard Henderson }
166298a9cb79SRichard Henderson 
1663*869051eaSRichard Henderson static DisasJumpType trans_mfctl(DisasContext *ctx, uint32_t insn,
166498a9cb79SRichard Henderson                                  const DisasInsn *di)
166598a9cb79SRichard Henderson {
166698a9cb79SRichard Henderson     unsigned rt = extract32(insn, 0, 5);
166798a9cb79SRichard Henderson     unsigned ctl = extract32(insn, 21, 5);
166898a9cb79SRichard Henderson     TCGv tmp;
166998a9cb79SRichard Henderson 
167098a9cb79SRichard Henderson     switch (ctl) {
167198a9cb79SRichard Henderson     case 11: /* SAR */
167298a9cb79SRichard Henderson #ifdef TARGET_HPPA64
167398a9cb79SRichard Henderson         if (extract32(insn, 14, 1) == 0) {
167498a9cb79SRichard Henderson             /* MFSAR without ,W masks low 5 bits.  */
167598a9cb79SRichard Henderson             tmp = dest_gpr(ctx, rt);
167698a9cb79SRichard Henderson             tcg_gen_andi_tl(tmp, cpu_sar, 31);
167798a9cb79SRichard Henderson             save_gpr(ctx, rt, tmp);
167898a9cb79SRichard Henderson             break;
167998a9cb79SRichard Henderson         }
168098a9cb79SRichard Henderson #endif
168198a9cb79SRichard Henderson         save_gpr(ctx, rt, cpu_sar);
168298a9cb79SRichard Henderson         break;
168398a9cb79SRichard Henderson     case 16: /* Interval Timer */
168498a9cb79SRichard Henderson         tmp = dest_gpr(ctx, rt);
168598a9cb79SRichard Henderson         tcg_gen_movi_tl(tmp, 0); /* FIXME */
168698a9cb79SRichard Henderson         save_gpr(ctx, rt, tmp);
168798a9cb79SRichard Henderson         break;
168898a9cb79SRichard Henderson     case 26:
168998a9cb79SRichard Henderson         save_gpr(ctx, rt, cpu_cr26);
169098a9cb79SRichard Henderson         break;
169198a9cb79SRichard Henderson     case 27:
169298a9cb79SRichard Henderson         save_gpr(ctx, rt, cpu_cr27);
169398a9cb79SRichard Henderson         break;
169498a9cb79SRichard Henderson     default:
169598a9cb79SRichard Henderson         /* All other control registers are privileged.  */
169698a9cb79SRichard Henderson         return gen_illegal(ctx);
169798a9cb79SRichard Henderson     }
169898a9cb79SRichard Henderson 
169998a9cb79SRichard Henderson     cond_free(&ctx->null_cond);
1700*869051eaSRichard Henderson     return DISAS_NEXT;
170198a9cb79SRichard Henderson }
170298a9cb79SRichard Henderson 
1703*869051eaSRichard Henderson static DisasJumpType trans_mtctl(DisasContext *ctx, uint32_t insn,
170498a9cb79SRichard Henderson                                  const DisasInsn *di)
170598a9cb79SRichard Henderson {
170698a9cb79SRichard Henderson     unsigned rin = extract32(insn, 16, 5);
170798a9cb79SRichard Henderson     unsigned ctl = extract32(insn, 21, 5);
170898a9cb79SRichard Henderson     TCGv tmp;
170998a9cb79SRichard Henderson 
171098a9cb79SRichard Henderson     if (ctl == 11) { /* SAR */
171198a9cb79SRichard Henderson         tmp = tcg_temp_new();
171298a9cb79SRichard Henderson         tcg_gen_andi_tl(tmp, load_gpr(ctx, rin), TARGET_LONG_BITS - 1);
171398a9cb79SRichard Henderson         save_or_nullify(ctx, cpu_sar, tmp);
171498a9cb79SRichard Henderson         tcg_temp_free(tmp);
171598a9cb79SRichard Henderson     } else {
171698a9cb79SRichard Henderson         /* All other control registers are privileged or read-only.  */
171798a9cb79SRichard Henderson         return gen_illegal(ctx);
171898a9cb79SRichard Henderson     }
171998a9cb79SRichard Henderson 
172098a9cb79SRichard Henderson     cond_free(&ctx->null_cond);
1721*869051eaSRichard Henderson     return DISAS_NEXT;
172298a9cb79SRichard Henderson }
172398a9cb79SRichard Henderson 
1724*869051eaSRichard Henderson static DisasJumpType trans_mtsarcm(DisasContext *ctx, uint32_t insn,
172598a9cb79SRichard Henderson                                    const DisasInsn *di)
172698a9cb79SRichard Henderson {
172798a9cb79SRichard Henderson     unsigned rin = extract32(insn, 16, 5);
172898a9cb79SRichard Henderson     TCGv tmp = tcg_temp_new();
172998a9cb79SRichard Henderson 
173098a9cb79SRichard Henderson     tcg_gen_not_tl(tmp, load_gpr(ctx, rin));
173198a9cb79SRichard Henderson     tcg_gen_andi_tl(tmp, tmp, TARGET_LONG_BITS - 1);
173298a9cb79SRichard Henderson     save_or_nullify(ctx, cpu_sar, tmp);
173398a9cb79SRichard Henderson     tcg_temp_free(tmp);
173498a9cb79SRichard Henderson 
173598a9cb79SRichard Henderson     cond_free(&ctx->null_cond);
1736*869051eaSRichard Henderson     return DISAS_NEXT;
173798a9cb79SRichard Henderson }
173898a9cb79SRichard Henderson 
1739*869051eaSRichard Henderson static DisasJumpType trans_ldsid(DisasContext *ctx, uint32_t insn,
174098a9cb79SRichard Henderson                                  const DisasInsn *di)
174198a9cb79SRichard Henderson {
174298a9cb79SRichard Henderson     unsigned rt = extract32(insn, 0, 5);
174398a9cb79SRichard Henderson     TCGv dest = dest_gpr(ctx, rt);
174498a9cb79SRichard Henderson 
174598a9cb79SRichard Henderson     /* Since we don't implement space registers, this returns zero.  */
174698a9cb79SRichard Henderson     tcg_gen_movi_tl(dest, 0);
174798a9cb79SRichard Henderson     save_gpr(ctx, rt, dest);
174898a9cb79SRichard Henderson 
174998a9cb79SRichard Henderson     cond_free(&ctx->null_cond);
1750*869051eaSRichard Henderson     return DISAS_NEXT;
175198a9cb79SRichard Henderson }
175298a9cb79SRichard Henderson 
175398a9cb79SRichard Henderson static const DisasInsn table_system[] = {
175498a9cb79SRichard Henderson     { 0x00000000u, 0xfc001fe0u, trans_break },
175598a9cb79SRichard Henderson     /* We don't implement space register, so MTSP is a nop.  */
175698a9cb79SRichard Henderson     { 0x00001820u, 0xffe01fffu, trans_nop },
175798a9cb79SRichard Henderson     { 0x00001840u, 0xfc00ffffu, trans_mtctl },
175898a9cb79SRichard Henderson     { 0x016018c0u, 0xffe0ffffu, trans_mtsarcm },
175998a9cb79SRichard Henderson     { 0x000014a0u, 0xffffffe0u, trans_mfia },
176098a9cb79SRichard Henderson     { 0x000004a0u, 0xffff1fe0u, trans_mfsp },
176198a9cb79SRichard Henderson     { 0x000008a0u, 0xfc1fffe0u, trans_mfctl },
176298a9cb79SRichard Henderson     { 0x00000400u, 0xffffffffu, trans_sync },
176398a9cb79SRichard Henderson     { 0x000010a0u, 0xfc1f3fe0u, trans_ldsid },
176498a9cb79SRichard Henderson };
176598a9cb79SRichard Henderson 
1766*869051eaSRichard Henderson static DisasJumpType trans_base_idx_mod(DisasContext *ctx, uint32_t insn,
176798a9cb79SRichard Henderson                                         const DisasInsn *di)
176898a9cb79SRichard Henderson {
176998a9cb79SRichard Henderson     unsigned rb = extract32(insn, 21, 5);
177098a9cb79SRichard Henderson     unsigned rx = extract32(insn, 16, 5);
177198a9cb79SRichard Henderson     TCGv dest = dest_gpr(ctx, rb);
177298a9cb79SRichard Henderson     TCGv src1 = load_gpr(ctx, rb);
177398a9cb79SRichard Henderson     TCGv src2 = load_gpr(ctx, rx);
177498a9cb79SRichard Henderson 
177598a9cb79SRichard Henderson     /* The only thing we need to do is the base register modification.  */
177698a9cb79SRichard Henderson     tcg_gen_add_tl(dest, src1, src2);
177798a9cb79SRichard Henderson     save_gpr(ctx, rb, dest);
177898a9cb79SRichard Henderson 
177998a9cb79SRichard Henderson     cond_free(&ctx->null_cond);
1780*869051eaSRichard Henderson     return DISAS_NEXT;
178198a9cb79SRichard Henderson }
178298a9cb79SRichard Henderson 
1783*869051eaSRichard Henderson static DisasJumpType trans_probe(DisasContext *ctx, uint32_t insn,
178498a9cb79SRichard Henderson                                  const DisasInsn *di)
178598a9cb79SRichard Henderson {
178698a9cb79SRichard Henderson     unsigned rt = extract32(insn, 0, 5);
178798a9cb79SRichard Henderson     unsigned rb = extract32(insn, 21, 5);
178898a9cb79SRichard Henderson     unsigned is_write = extract32(insn, 6, 1);
178998a9cb79SRichard Henderson     TCGv dest;
179098a9cb79SRichard Henderson 
179198a9cb79SRichard Henderson     nullify_over(ctx);
179298a9cb79SRichard Henderson 
179398a9cb79SRichard Henderson     /* ??? Do something with priv level operand.  */
179498a9cb79SRichard Henderson     dest = dest_gpr(ctx, rt);
179598a9cb79SRichard Henderson     if (is_write) {
179698a9cb79SRichard Henderson         gen_helper_probe_w(dest, load_gpr(ctx, rb));
179798a9cb79SRichard Henderson     } else {
179898a9cb79SRichard Henderson         gen_helper_probe_r(dest, load_gpr(ctx, rb));
179998a9cb79SRichard Henderson     }
180098a9cb79SRichard Henderson     save_gpr(ctx, rt, dest);
1801*869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
180298a9cb79SRichard Henderson }
180398a9cb79SRichard Henderson 
180498a9cb79SRichard Henderson static const DisasInsn table_mem_mgmt[] = {
180598a9cb79SRichard Henderson     { 0x04003280u, 0xfc003fffu, trans_nop },          /* fdc, disp */
180698a9cb79SRichard Henderson     { 0x04001280u, 0xfc003fffu, trans_nop },          /* fdc, index */
180798a9cb79SRichard Henderson     { 0x040012a0u, 0xfc003fffu, trans_base_idx_mod }, /* fdc, index, base mod */
180898a9cb79SRichard Henderson     { 0x040012c0u, 0xfc003fffu, trans_nop },          /* fdce */
180998a9cb79SRichard Henderson     { 0x040012e0u, 0xfc003fffu, trans_base_idx_mod }, /* fdce, base mod */
181098a9cb79SRichard Henderson     { 0x04000280u, 0xfc001fffu, trans_nop },          /* fic 0a */
181198a9cb79SRichard Henderson     { 0x040002a0u, 0xfc001fffu, trans_base_idx_mod }, /* fic 0a, base mod */
181298a9cb79SRichard Henderson     { 0x040013c0u, 0xfc003fffu, trans_nop },          /* fic 4f */
181398a9cb79SRichard Henderson     { 0x040013e0u, 0xfc003fffu, trans_base_idx_mod }, /* fic 4f, base mod */
181498a9cb79SRichard Henderson     { 0x040002c0u, 0xfc001fffu, trans_nop },          /* fice */
181598a9cb79SRichard Henderson     { 0x040002e0u, 0xfc001fffu, trans_base_idx_mod }, /* fice, base mod */
181698a9cb79SRichard Henderson     { 0x04002700u, 0xfc003fffu, trans_nop },          /* pdc */
181798a9cb79SRichard Henderson     { 0x04002720u, 0xfc003fffu, trans_base_idx_mod }, /* pdc, base mod */
181898a9cb79SRichard Henderson     { 0x04001180u, 0xfc003fa0u, trans_probe },        /* probe */
181998a9cb79SRichard Henderson     { 0x04003180u, 0xfc003fa0u, trans_probe },        /* probei */
182098a9cb79SRichard Henderson };
182198a9cb79SRichard Henderson 
1822*869051eaSRichard Henderson static DisasJumpType trans_add(DisasContext *ctx, uint32_t insn,
1823b2167459SRichard Henderson                                const DisasInsn *di)
1824b2167459SRichard Henderson {
1825b2167459SRichard Henderson     unsigned r2 = extract32(insn, 21, 5);
1826b2167459SRichard Henderson     unsigned r1 = extract32(insn, 16, 5);
1827b2167459SRichard Henderson     unsigned cf = extract32(insn, 12, 4);
1828b2167459SRichard Henderson     unsigned ext = extract32(insn, 8, 4);
1829b2167459SRichard Henderson     unsigned shift = extract32(insn, 6, 2);
1830b2167459SRichard Henderson     unsigned rt = extract32(insn,  0, 5);
1831b2167459SRichard Henderson     TCGv tcg_r1, tcg_r2;
1832b2167459SRichard Henderson     bool is_c = false;
1833b2167459SRichard Henderson     bool is_l = false;
1834b2167459SRichard Henderson     bool is_tc = false;
1835b2167459SRichard Henderson     bool is_tsv = false;
1836*869051eaSRichard Henderson     DisasJumpType ret;
1837b2167459SRichard Henderson 
1838b2167459SRichard Henderson     switch (ext) {
1839b2167459SRichard Henderson     case 0x6: /* ADD, SHLADD */
1840b2167459SRichard Henderson         break;
1841b2167459SRichard Henderson     case 0xa: /* ADD,L, SHLADD,L */
1842b2167459SRichard Henderson         is_l = true;
1843b2167459SRichard Henderson         break;
1844b2167459SRichard Henderson     case 0xe: /* ADD,TSV, SHLADD,TSV (1) */
1845b2167459SRichard Henderson         is_tsv = true;
1846b2167459SRichard Henderson         break;
1847b2167459SRichard Henderson     case 0x7: /* ADD,C */
1848b2167459SRichard Henderson         is_c = true;
1849b2167459SRichard Henderson         break;
1850b2167459SRichard Henderson     case 0xf: /* ADD,C,TSV */
1851b2167459SRichard Henderson         is_c = is_tsv = true;
1852b2167459SRichard Henderson         break;
1853b2167459SRichard Henderson     default:
1854b2167459SRichard Henderson         return gen_illegal(ctx);
1855b2167459SRichard Henderson     }
1856b2167459SRichard Henderson 
1857b2167459SRichard Henderson     if (cf) {
1858b2167459SRichard Henderson         nullify_over(ctx);
1859b2167459SRichard Henderson     }
1860b2167459SRichard Henderson     tcg_r1 = load_gpr(ctx, r1);
1861b2167459SRichard Henderson     tcg_r2 = load_gpr(ctx, r2);
1862b2167459SRichard Henderson     ret = do_add(ctx, rt, tcg_r1, tcg_r2, shift, is_l, is_tsv, is_tc, is_c, cf);
1863b2167459SRichard Henderson     return nullify_end(ctx, ret);
1864b2167459SRichard Henderson }
1865b2167459SRichard Henderson 
1866*869051eaSRichard Henderson static DisasJumpType trans_sub(DisasContext *ctx, uint32_t insn,
1867b2167459SRichard Henderson                                const DisasInsn *di)
1868b2167459SRichard Henderson {
1869b2167459SRichard Henderson     unsigned r2 = extract32(insn, 21, 5);
1870b2167459SRichard Henderson     unsigned r1 = extract32(insn, 16, 5);
1871b2167459SRichard Henderson     unsigned cf = extract32(insn, 12, 4);
1872b2167459SRichard Henderson     unsigned ext = extract32(insn, 6, 6);
1873b2167459SRichard Henderson     unsigned rt = extract32(insn,  0, 5);
1874b2167459SRichard Henderson     TCGv tcg_r1, tcg_r2;
1875b2167459SRichard Henderson     bool is_b = false;
1876b2167459SRichard Henderson     bool is_tc = false;
1877b2167459SRichard Henderson     bool is_tsv = false;
1878*869051eaSRichard Henderson     DisasJumpType ret;
1879b2167459SRichard Henderson 
1880b2167459SRichard Henderson     switch (ext) {
1881b2167459SRichard Henderson     case 0x10: /* SUB */
1882b2167459SRichard Henderson         break;
1883b2167459SRichard Henderson     case 0x30: /* SUB,TSV */
1884b2167459SRichard Henderson         is_tsv = true;
1885b2167459SRichard Henderson         break;
1886b2167459SRichard Henderson     case 0x14: /* SUB,B */
1887b2167459SRichard Henderson         is_b = true;
1888b2167459SRichard Henderson         break;
1889b2167459SRichard Henderson     case 0x34: /* SUB,B,TSV */
1890b2167459SRichard Henderson         is_b = is_tsv = true;
1891b2167459SRichard Henderson         break;
1892b2167459SRichard Henderson     case 0x13: /* SUB,TC */
1893b2167459SRichard Henderson         is_tc = true;
1894b2167459SRichard Henderson         break;
1895b2167459SRichard Henderson     case 0x33: /* SUB,TSV,TC */
1896b2167459SRichard Henderson         is_tc = is_tsv = true;
1897b2167459SRichard Henderson         break;
1898b2167459SRichard Henderson     default:
1899b2167459SRichard Henderson         return gen_illegal(ctx);
1900b2167459SRichard Henderson     }
1901b2167459SRichard Henderson 
1902b2167459SRichard Henderson     if (cf) {
1903b2167459SRichard Henderson         nullify_over(ctx);
1904b2167459SRichard Henderson     }
1905b2167459SRichard Henderson     tcg_r1 = load_gpr(ctx, r1);
1906b2167459SRichard Henderson     tcg_r2 = load_gpr(ctx, r2);
1907b2167459SRichard Henderson     ret = do_sub(ctx, rt, tcg_r1, tcg_r2, is_tsv, is_b, is_tc, cf);
1908b2167459SRichard Henderson     return nullify_end(ctx, ret);
1909b2167459SRichard Henderson }
1910b2167459SRichard Henderson 
1911*869051eaSRichard Henderson static DisasJumpType trans_log(DisasContext *ctx, uint32_t insn,
1912b2167459SRichard Henderson                                const DisasInsn *di)
1913b2167459SRichard Henderson {
1914b2167459SRichard Henderson     unsigned r2 = extract32(insn, 21, 5);
1915b2167459SRichard Henderson     unsigned r1 = extract32(insn, 16, 5);
1916b2167459SRichard Henderson     unsigned cf = extract32(insn, 12, 4);
1917b2167459SRichard Henderson     unsigned rt = extract32(insn,  0, 5);
1918b2167459SRichard Henderson     TCGv tcg_r1, tcg_r2;
1919*869051eaSRichard Henderson     DisasJumpType ret;
1920b2167459SRichard Henderson 
1921b2167459SRichard Henderson     if (cf) {
1922b2167459SRichard Henderson         nullify_over(ctx);
1923b2167459SRichard Henderson     }
1924b2167459SRichard Henderson     tcg_r1 = load_gpr(ctx, r1);
1925b2167459SRichard Henderson     tcg_r2 = load_gpr(ctx, r2);
1926eff235ebSPaolo Bonzini     ret = do_log(ctx, rt, tcg_r1, tcg_r2, cf, di->f.ttt);
1927b2167459SRichard Henderson     return nullify_end(ctx, ret);
1928b2167459SRichard Henderson }
1929b2167459SRichard Henderson 
1930b2167459SRichard Henderson /* OR r,0,t -> COPY (according to gas) */
1931*869051eaSRichard Henderson static DisasJumpType trans_copy(DisasContext *ctx, uint32_t insn,
1932b2167459SRichard Henderson                                 const DisasInsn *di)
1933b2167459SRichard Henderson {
1934b2167459SRichard Henderson     unsigned r1 = extract32(insn, 16, 5);
1935b2167459SRichard Henderson     unsigned rt = extract32(insn,  0, 5);
1936b2167459SRichard Henderson 
1937b2167459SRichard Henderson     if (r1 == 0) {
1938b2167459SRichard Henderson         TCGv dest = dest_gpr(ctx, rt);
1939b2167459SRichard Henderson         tcg_gen_movi_tl(dest, 0);
1940b2167459SRichard Henderson         save_gpr(ctx, rt, dest);
1941b2167459SRichard Henderson     } else {
1942b2167459SRichard Henderson         save_gpr(ctx, rt, cpu_gr[r1]);
1943b2167459SRichard Henderson     }
1944b2167459SRichard Henderson     cond_free(&ctx->null_cond);
1945*869051eaSRichard Henderson     return DISAS_NEXT;
1946b2167459SRichard Henderson }
1947b2167459SRichard Henderson 
1948*869051eaSRichard Henderson static DisasJumpType trans_cmpclr(DisasContext *ctx, uint32_t insn,
1949b2167459SRichard Henderson                                   const DisasInsn *di)
1950b2167459SRichard Henderson {
1951b2167459SRichard Henderson     unsigned r2 = extract32(insn, 21, 5);
1952b2167459SRichard Henderson     unsigned r1 = extract32(insn, 16, 5);
1953b2167459SRichard Henderson     unsigned cf = extract32(insn, 12, 4);
1954b2167459SRichard Henderson     unsigned rt = extract32(insn,  0, 5);
1955b2167459SRichard Henderson     TCGv tcg_r1, tcg_r2;
1956*869051eaSRichard Henderson     DisasJumpType ret;
1957b2167459SRichard Henderson 
1958b2167459SRichard Henderson     if (cf) {
1959b2167459SRichard Henderson         nullify_over(ctx);
1960b2167459SRichard Henderson     }
1961b2167459SRichard Henderson     tcg_r1 = load_gpr(ctx, r1);
1962b2167459SRichard Henderson     tcg_r2 = load_gpr(ctx, r2);
1963b2167459SRichard Henderson     ret = do_cmpclr(ctx, rt, tcg_r1, tcg_r2, cf);
1964b2167459SRichard Henderson     return nullify_end(ctx, ret);
1965b2167459SRichard Henderson }
1966b2167459SRichard Henderson 
1967*869051eaSRichard Henderson static DisasJumpType trans_uxor(DisasContext *ctx, uint32_t insn,
1968b2167459SRichard Henderson                                 const DisasInsn *di)
1969b2167459SRichard Henderson {
1970b2167459SRichard Henderson     unsigned r2 = extract32(insn, 21, 5);
1971b2167459SRichard Henderson     unsigned r1 = extract32(insn, 16, 5);
1972b2167459SRichard Henderson     unsigned cf = extract32(insn, 12, 4);
1973b2167459SRichard Henderson     unsigned rt = extract32(insn,  0, 5);
1974b2167459SRichard Henderson     TCGv tcg_r1, tcg_r2;
1975*869051eaSRichard Henderson     DisasJumpType ret;
1976b2167459SRichard Henderson 
1977b2167459SRichard Henderson     if (cf) {
1978b2167459SRichard Henderson         nullify_over(ctx);
1979b2167459SRichard Henderson     }
1980b2167459SRichard Henderson     tcg_r1 = load_gpr(ctx, r1);
1981b2167459SRichard Henderson     tcg_r2 = load_gpr(ctx, r2);
1982b2167459SRichard Henderson     ret = do_unit(ctx, rt, tcg_r1, tcg_r2, cf, false, tcg_gen_xor_tl);
1983b2167459SRichard Henderson     return nullify_end(ctx, ret);
1984b2167459SRichard Henderson }
1985b2167459SRichard Henderson 
1986*869051eaSRichard Henderson static DisasJumpType trans_uaddcm(DisasContext *ctx, uint32_t insn,
1987b2167459SRichard Henderson                                   const DisasInsn *di)
1988b2167459SRichard Henderson {
1989b2167459SRichard Henderson     unsigned r2 = extract32(insn, 21, 5);
1990b2167459SRichard Henderson     unsigned r1 = extract32(insn, 16, 5);
1991b2167459SRichard Henderson     unsigned cf = extract32(insn, 12, 4);
1992b2167459SRichard Henderson     unsigned is_tc = extract32(insn, 6, 1);
1993b2167459SRichard Henderson     unsigned rt = extract32(insn,  0, 5);
1994b2167459SRichard Henderson     TCGv tcg_r1, tcg_r2, tmp;
1995*869051eaSRichard Henderson     DisasJumpType ret;
1996b2167459SRichard Henderson 
1997b2167459SRichard Henderson     if (cf) {
1998b2167459SRichard Henderson         nullify_over(ctx);
1999b2167459SRichard Henderson     }
2000b2167459SRichard Henderson     tcg_r1 = load_gpr(ctx, r1);
2001b2167459SRichard Henderson     tcg_r2 = load_gpr(ctx, r2);
2002b2167459SRichard Henderson     tmp = get_temp(ctx);
2003b2167459SRichard Henderson     tcg_gen_not_tl(tmp, tcg_r2);
2004b2167459SRichard Henderson     ret = do_unit(ctx, rt, tcg_r1, tmp, cf, is_tc, tcg_gen_add_tl);
2005b2167459SRichard Henderson     return nullify_end(ctx, ret);
2006b2167459SRichard Henderson }
2007b2167459SRichard Henderson 
2008*869051eaSRichard Henderson static DisasJumpType trans_dcor(DisasContext *ctx, uint32_t insn,
2009b2167459SRichard Henderson                                 const DisasInsn *di)
2010b2167459SRichard Henderson {
2011b2167459SRichard Henderson     unsigned r2 = extract32(insn, 21, 5);
2012b2167459SRichard Henderson     unsigned cf = extract32(insn, 12, 4);
2013b2167459SRichard Henderson     unsigned is_i = extract32(insn, 6, 1);
2014b2167459SRichard Henderson     unsigned rt = extract32(insn,  0, 5);
2015b2167459SRichard Henderson     TCGv tmp;
2016*869051eaSRichard Henderson     DisasJumpType ret;
2017b2167459SRichard Henderson 
2018b2167459SRichard Henderson     nullify_over(ctx);
2019b2167459SRichard Henderson 
2020b2167459SRichard Henderson     tmp = get_temp(ctx);
2021b2167459SRichard Henderson     tcg_gen_shri_tl(tmp, cpu_psw_cb, 3);
2022b2167459SRichard Henderson     if (!is_i) {
2023b2167459SRichard Henderson         tcg_gen_not_tl(tmp, tmp);
2024b2167459SRichard Henderson     }
2025b2167459SRichard Henderson     tcg_gen_andi_tl(tmp, tmp, 0x11111111);
2026b2167459SRichard Henderson     tcg_gen_muli_tl(tmp, tmp, 6);
2027b2167459SRichard Henderson     ret = do_unit(ctx, rt, tmp, load_gpr(ctx, r2), cf, false,
2028b2167459SRichard Henderson                   is_i ? tcg_gen_add_tl : tcg_gen_sub_tl);
2029b2167459SRichard Henderson 
2030b2167459SRichard Henderson     return nullify_end(ctx, ret);
2031b2167459SRichard Henderson }
2032b2167459SRichard Henderson 
2033*869051eaSRichard Henderson static DisasJumpType trans_ds(DisasContext *ctx, uint32_t insn,
2034b2167459SRichard Henderson                               const DisasInsn *di)
2035b2167459SRichard Henderson {
2036b2167459SRichard Henderson     unsigned r2 = extract32(insn, 21, 5);
2037b2167459SRichard Henderson     unsigned r1 = extract32(insn, 16, 5);
2038b2167459SRichard Henderson     unsigned cf = extract32(insn, 12, 4);
2039b2167459SRichard Henderson     unsigned rt = extract32(insn,  0, 5);
2040b2167459SRichard Henderson     TCGv dest, add1, add2, addc, zero, in1, in2;
2041b2167459SRichard Henderson 
2042b2167459SRichard Henderson     nullify_over(ctx);
2043b2167459SRichard Henderson 
2044b2167459SRichard Henderson     in1 = load_gpr(ctx, r1);
2045b2167459SRichard Henderson     in2 = load_gpr(ctx, r2);
2046b2167459SRichard Henderson 
2047b2167459SRichard Henderson     add1 = tcg_temp_new();
2048b2167459SRichard Henderson     add2 = tcg_temp_new();
2049b2167459SRichard Henderson     addc = tcg_temp_new();
2050b2167459SRichard Henderson     dest = tcg_temp_new();
2051b2167459SRichard Henderson     zero = tcg_const_tl(0);
2052b2167459SRichard Henderson 
2053b2167459SRichard Henderson     /* Form R1 << 1 | PSW[CB]{8}.  */
2054b2167459SRichard Henderson     tcg_gen_add_tl(add1, in1, in1);
2055b2167459SRichard Henderson     tcg_gen_add_tl(add1, add1, cpu_psw_cb_msb);
2056b2167459SRichard Henderson 
2057b2167459SRichard Henderson     /* Add or subtract R2, depending on PSW[V].  Proper computation of
2058b2167459SRichard Henderson        carry{8} requires that we subtract via + ~R2 + 1, as described in
2059b2167459SRichard Henderson        the manual.  By extracting and masking V, we can produce the
2060b2167459SRichard Henderson        proper inputs to the addition without movcond.  */
2061b2167459SRichard Henderson     tcg_gen_sari_tl(addc, cpu_psw_v, TARGET_LONG_BITS - 1);
2062b2167459SRichard Henderson     tcg_gen_xor_tl(add2, in2, addc);
2063b2167459SRichard Henderson     tcg_gen_andi_tl(addc, addc, 1);
2064b2167459SRichard Henderson     /* ??? This is only correct for 32-bit.  */
2065b2167459SRichard Henderson     tcg_gen_add2_i32(dest, cpu_psw_cb_msb, add1, zero, add2, zero);
2066b2167459SRichard Henderson     tcg_gen_add2_i32(dest, cpu_psw_cb_msb, dest, cpu_psw_cb_msb, addc, zero);
2067b2167459SRichard Henderson 
2068b2167459SRichard Henderson     tcg_temp_free(addc);
2069b2167459SRichard Henderson     tcg_temp_free(zero);
2070b2167459SRichard Henderson 
2071b2167459SRichard Henderson     /* Write back the result register.  */
2072b2167459SRichard Henderson     save_gpr(ctx, rt, dest);
2073b2167459SRichard Henderson 
2074b2167459SRichard Henderson     /* Write back PSW[CB].  */
2075b2167459SRichard Henderson     tcg_gen_xor_tl(cpu_psw_cb, add1, add2);
2076b2167459SRichard Henderson     tcg_gen_xor_tl(cpu_psw_cb, cpu_psw_cb, dest);
2077b2167459SRichard Henderson 
2078b2167459SRichard Henderson     /* Write back PSW[V] for the division step.  */
2079b2167459SRichard Henderson     tcg_gen_neg_tl(cpu_psw_v, cpu_psw_cb_msb);
2080b2167459SRichard Henderson     tcg_gen_xor_tl(cpu_psw_v, cpu_psw_v, in2);
2081b2167459SRichard Henderson 
2082b2167459SRichard Henderson     /* Install the new nullification.  */
2083b2167459SRichard Henderson     if (cf) {
2084b2167459SRichard Henderson         TCGv sv;
2085b2167459SRichard Henderson         TCGV_UNUSED(sv);
2086b2167459SRichard Henderson         if (cf >> 1 == 6) {
2087b2167459SRichard Henderson             /* ??? The lshift is supposed to contribute to overflow.  */
2088b2167459SRichard Henderson             sv = do_add_sv(ctx, dest, add1, add2);
2089b2167459SRichard Henderson         }
2090b2167459SRichard Henderson         ctx->null_cond = do_cond(cf, dest, cpu_psw_cb_msb, sv);
2091b2167459SRichard Henderson     }
2092b2167459SRichard Henderson 
2093b2167459SRichard Henderson     tcg_temp_free(add1);
2094b2167459SRichard Henderson     tcg_temp_free(add2);
2095b2167459SRichard Henderson     tcg_temp_free(dest);
2096b2167459SRichard Henderson 
2097*869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
2098b2167459SRichard Henderson }
2099b2167459SRichard Henderson 
2100b2167459SRichard Henderson static const DisasInsn table_arith_log[] = {
2101b2167459SRichard Henderson     { 0x08000240u, 0xfc00ffffu, trans_nop },  /* or x,y,0 */
2102b2167459SRichard Henderson     { 0x08000240u, 0xffe0ffe0u, trans_copy }, /* or x,0,t */
2103eff235ebSPaolo Bonzini     { 0x08000000u, 0xfc000fe0u, trans_log, .f.ttt = tcg_gen_andc_tl },
2104eff235ebSPaolo Bonzini     { 0x08000200u, 0xfc000fe0u, trans_log, .f.ttt = tcg_gen_and_tl },
2105eff235ebSPaolo Bonzini     { 0x08000240u, 0xfc000fe0u, trans_log, .f.ttt = tcg_gen_or_tl },
2106eff235ebSPaolo Bonzini     { 0x08000280u, 0xfc000fe0u, trans_log, .f.ttt = tcg_gen_xor_tl },
2107b2167459SRichard Henderson     { 0x08000880u, 0xfc000fe0u, trans_cmpclr },
2108b2167459SRichard Henderson     { 0x08000380u, 0xfc000fe0u, trans_uxor },
2109b2167459SRichard Henderson     { 0x08000980u, 0xfc000fa0u, trans_uaddcm },
2110b2167459SRichard Henderson     { 0x08000b80u, 0xfc1f0fa0u, trans_dcor },
2111b2167459SRichard Henderson     { 0x08000440u, 0xfc000fe0u, trans_ds },
2112b2167459SRichard Henderson     { 0x08000700u, 0xfc0007e0u, trans_add }, /* add */
2113b2167459SRichard Henderson     { 0x08000400u, 0xfc0006e0u, trans_sub }, /* sub; sub,b; sub,tsv */
2114b2167459SRichard Henderson     { 0x080004c0u, 0xfc0007e0u, trans_sub }, /* sub,tc; sub,tsv,tc */
2115b2167459SRichard Henderson     { 0x08000200u, 0xfc000320u, trans_add }, /* shladd */
2116b2167459SRichard Henderson };
2117b2167459SRichard Henderson 
2118*869051eaSRichard Henderson static DisasJumpType trans_addi(DisasContext *ctx, uint32_t insn)
2119b2167459SRichard Henderson {
2120b2167459SRichard Henderson     target_long im = low_sextract(insn, 0, 11);
2121b2167459SRichard Henderson     unsigned e1 = extract32(insn, 11, 1);
2122b2167459SRichard Henderson     unsigned cf = extract32(insn, 12, 4);
2123b2167459SRichard Henderson     unsigned rt = extract32(insn, 16, 5);
2124b2167459SRichard Henderson     unsigned r2 = extract32(insn, 21, 5);
2125b2167459SRichard Henderson     unsigned o1 = extract32(insn, 26, 1);
2126b2167459SRichard Henderson     TCGv tcg_im, tcg_r2;
2127*869051eaSRichard Henderson     DisasJumpType ret;
2128b2167459SRichard Henderson 
2129b2167459SRichard Henderson     if (cf) {
2130b2167459SRichard Henderson         nullify_over(ctx);
2131b2167459SRichard Henderson     }
2132b2167459SRichard Henderson 
2133b2167459SRichard Henderson     tcg_im = load_const(ctx, im);
2134b2167459SRichard Henderson     tcg_r2 = load_gpr(ctx, r2);
2135b2167459SRichard Henderson     ret = do_add(ctx, rt, tcg_im, tcg_r2, 0, false, e1, !o1, false, cf);
2136b2167459SRichard Henderson 
2137b2167459SRichard Henderson     return nullify_end(ctx, ret);
2138b2167459SRichard Henderson }
2139b2167459SRichard Henderson 
2140*869051eaSRichard Henderson static DisasJumpType trans_subi(DisasContext *ctx, uint32_t insn)
2141b2167459SRichard Henderson {
2142b2167459SRichard Henderson     target_long im = low_sextract(insn, 0, 11);
2143b2167459SRichard Henderson     unsigned e1 = extract32(insn, 11, 1);
2144b2167459SRichard Henderson     unsigned cf = extract32(insn, 12, 4);
2145b2167459SRichard Henderson     unsigned rt = extract32(insn, 16, 5);
2146b2167459SRichard Henderson     unsigned r2 = extract32(insn, 21, 5);
2147b2167459SRichard Henderson     TCGv tcg_im, tcg_r2;
2148*869051eaSRichard Henderson     DisasJumpType ret;
2149b2167459SRichard Henderson 
2150b2167459SRichard Henderson     if (cf) {
2151b2167459SRichard Henderson         nullify_over(ctx);
2152b2167459SRichard Henderson     }
2153b2167459SRichard Henderson 
2154b2167459SRichard Henderson     tcg_im = load_const(ctx, im);
2155b2167459SRichard Henderson     tcg_r2 = load_gpr(ctx, r2);
2156b2167459SRichard Henderson     ret = do_sub(ctx, rt, tcg_im, tcg_r2, e1, false, false, cf);
2157b2167459SRichard Henderson 
2158b2167459SRichard Henderson     return nullify_end(ctx, ret);
2159b2167459SRichard Henderson }
2160b2167459SRichard Henderson 
2161*869051eaSRichard Henderson static DisasJumpType trans_cmpiclr(DisasContext *ctx, uint32_t insn)
2162b2167459SRichard Henderson {
2163b2167459SRichard Henderson     target_long im = low_sextract(insn, 0, 11);
2164b2167459SRichard Henderson     unsigned cf = extract32(insn, 12, 4);
2165b2167459SRichard Henderson     unsigned rt = extract32(insn, 16, 5);
2166b2167459SRichard Henderson     unsigned r2 = extract32(insn, 21, 5);
2167b2167459SRichard Henderson     TCGv tcg_im, tcg_r2;
2168*869051eaSRichard Henderson     DisasJumpType ret;
2169b2167459SRichard Henderson 
2170b2167459SRichard Henderson     if (cf) {
2171b2167459SRichard Henderson         nullify_over(ctx);
2172b2167459SRichard Henderson     }
2173b2167459SRichard Henderson 
2174b2167459SRichard Henderson     tcg_im = load_const(ctx, im);
2175b2167459SRichard Henderson     tcg_r2 = load_gpr(ctx, r2);
2176b2167459SRichard Henderson     ret = do_cmpclr(ctx, rt, tcg_im, tcg_r2, cf);
2177b2167459SRichard Henderson 
2178b2167459SRichard Henderson     return nullify_end(ctx, ret);
2179b2167459SRichard Henderson }
2180b2167459SRichard Henderson 
2181*869051eaSRichard Henderson static DisasJumpType trans_ld_idx_i(DisasContext *ctx, uint32_t insn,
218296d6407fSRichard Henderson                                     const DisasInsn *di)
218396d6407fSRichard Henderson {
218496d6407fSRichard Henderson     unsigned rt = extract32(insn, 0, 5);
218596d6407fSRichard Henderson     unsigned m = extract32(insn, 5, 1);
218696d6407fSRichard Henderson     unsigned sz = extract32(insn, 6, 2);
218796d6407fSRichard Henderson     unsigned a = extract32(insn, 13, 1);
218896d6407fSRichard Henderson     int disp = low_sextract(insn, 16, 5);
218996d6407fSRichard Henderson     unsigned rb = extract32(insn, 21, 5);
219096d6407fSRichard Henderson     int modify = (m ? (a ? -1 : 1) : 0);
219196d6407fSRichard Henderson     TCGMemOp mop = MO_TE | sz;
219296d6407fSRichard Henderson 
219396d6407fSRichard Henderson     return do_load(ctx, rt, rb, 0, 0, disp, modify, mop);
219496d6407fSRichard Henderson }
219596d6407fSRichard Henderson 
2196*869051eaSRichard Henderson static DisasJumpType trans_ld_idx_x(DisasContext *ctx, uint32_t insn,
219796d6407fSRichard Henderson                                     const DisasInsn *di)
219896d6407fSRichard Henderson {
219996d6407fSRichard Henderson     unsigned rt = extract32(insn, 0, 5);
220096d6407fSRichard Henderson     unsigned m = extract32(insn, 5, 1);
220196d6407fSRichard Henderson     unsigned sz = extract32(insn, 6, 2);
220296d6407fSRichard Henderson     unsigned u = extract32(insn, 13, 1);
220396d6407fSRichard Henderson     unsigned rx = extract32(insn, 16, 5);
220496d6407fSRichard Henderson     unsigned rb = extract32(insn, 21, 5);
220596d6407fSRichard Henderson     TCGMemOp mop = MO_TE | sz;
220696d6407fSRichard Henderson 
220796d6407fSRichard Henderson     return do_load(ctx, rt, rb, rx, u ? sz : 0, 0, m, mop);
220896d6407fSRichard Henderson }
220996d6407fSRichard Henderson 
2210*869051eaSRichard Henderson static DisasJumpType trans_st_idx_i(DisasContext *ctx, uint32_t insn,
221196d6407fSRichard Henderson                                     const DisasInsn *di)
221296d6407fSRichard Henderson {
221396d6407fSRichard Henderson     int disp = low_sextract(insn, 0, 5);
221496d6407fSRichard Henderson     unsigned m = extract32(insn, 5, 1);
221596d6407fSRichard Henderson     unsigned sz = extract32(insn, 6, 2);
221696d6407fSRichard Henderson     unsigned a = extract32(insn, 13, 1);
221796d6407fSRichard Henderson     unsigned rr = extract32(insn, 16, 5);
221896d6407fSRichard Henderson     unsigned rb = extract32(insn, 21, 5);
221996d6407fSRichard Henderson     int modify = (m ? (a ? -1 : 1) : 0);
222096d6407fSRichard Henderson     TCGMemOp mop = MO_TE | sz;
222196d6407fSRichard Henderson 
222296d6407fSRichard Henderson     return do_store(ctx, rr, rb, disp, modify, mop);
222396d6407fSRichard Henderson }
222496d6407fSRichard Henderson 
2225*869051eaSRichard Henderson static DisasJumpType trans_ldcw(DisasContext *ctx, uint32_t insn,
222696d6407fSRichard Henderson                                 const DisasInsn *di)
222796d6407fSRichard Henderson {
222896d6407fSRichard Henderson     unsigned rt = extract32(insn, 0, 5);
222996d6407fSRichard Henderson     unsigned m = extract32(insn, 5, 1);
223096d6407fSRichard Henderson     unsigned i = extract32(insn, 12, 1);
223196d6407fSRichard Henderson     unsigned au = extract32(insn, 13, 1);
223296d6407fSRichard Henderson     unsigned rx = extract32(insn, 16, 5);
223396d6407fSRichard Henderson     unsigned rb = extract32(insn, 21, 5);
223496d6407fSRichard Henderson     TCGMemOp mop = MO_TEUL | MO_ALIGN_16;
223596d6407fSRichard Henderson     TCGv zero, addr, base, dest;
223696d6407fSRichard Henderson     int modify, disp = 0, scale = 0;
223796d6407fSRichard Henderson 
223896d6407fSRichard Henderson     nullify_over(ctx);
223996d6407fSRichard Henderson 
224096d6407fSRichard Henderson     /* ??? Share more code with do_load and do_load_{32,64}.  */
224196d6407fSRichard Henderson 
224296d6407fSRichard Henderson     if (i) {
224396d6407fSRichard Henderson         modify = (m ? (au ? -1 : 1) : 0);
224496d6407fSRichard Henderson         disp = low_sextract(rx, 0, 5);
224596d6407fSRichard Henderson         rx = 0;
224696d6407fSRichard Henderson     } else {
224796d6407fSRichard Henderson         modify = m;
224896d6407fSRichard Henderson         if (au) {
224996d6407fSRichard Henderson             scale = mop & MO_SIZE;
225096d6407fSRichard Henderson         }
225196d6407fSRichard Henderson     }
225296d6407fSRichard Henderson     if (modify) {
225396d6407fSRichard Henderson         /* Base register modification.  Make sure if RT == RB, we see
225496d6407fSRichard Henderson            the result of the load.  */
225596d6407fSRichard Henderson         dest = get_temp(ctx);
225696d6407fSRichard Henderson     } else {
225796d6407fSRichard Henderson         dest = dest_gpr(ctx, rt);
225896d6407fSRichard Henderson     }
225996d6407fSRichard Henderson 
226096d6407fSRichard Henderson     addr = tcg_temp_new();
226196d6407fSRichard Henderson     base = load_gpr(ctx, rb);
226296d6407fSRichard Henderson     if (rx) {
226396d6407fSRichard Henderson         tcg_gen_shli_tl(addr, cpu_gr[rx], scale);
226496d6407fSRichard Henderson         tcg_gen_add_tl(addr, addr, base);
226596d6407fSRichard Henderson     } else {
226696d6407fSRichard Henderson         tcg_gen_addi_tl(addr, base, disp);
226796d6407fSRichard Henderson     }
226896d6407fSRichard Henderson 
226996d6407fSRichard Henderson     zero = tcg_const_tl(0);
227096d6407fSRichard Henderson     tcg_gen_atomic_xchg_tl(dest, (modify <= 0 ? addr : base),
227196d6407fSRichard Henderson                            zero, MMU_USER_IDX, mop);
227296d6407fSRichard Henderson     if (modify) {
227396d6407fSRichard Henderson         save_gpr(ctx, rb, addr);
227496d6407fSRichard Henderson     }
227596d6407fSRichard Henderson     save_gpr(ctx, rt, dest);
227696d6407fSRichard Henderson 
2277*869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
227896d6407fSRichard Henderson }
227996d6407fSRichard Henderson 
2280*869051eaSRichard Henderson static DisasJumpType trans_stby(DisasContext *ctx, uint32_t insn,
228196d6407fSRichard Henderson                                 const DisasInsn *di)
228296d6407fSRichard Henderson {
228396d6407fSRichard Henderson     target_long disp = low_sextract(insn, 0, 5);
228496d6407fSRichard Henderson     unsigned m = extract32(insn, 5, 1);
228596d6407fSRichard Henderson     unsigned a = extract32(insn, 13, 1);
228696d6407fSRichard Henderson     unsigned rt = extract32(insn, 16, 5);
228796d6407fSRichard Henderson     unsigned rb = extract32(insn, 21, 5);
228896d6407fSRichard Henderson     TCGv addr, val;
228996d6407fSRichard Henderson 
229096d6407fSRichard Henderson     nullify_over(ctx);
229196d6407fSRichard Henderson 
229296d6407fSRichard Henderson     addr = tcg_temp_new();
229396d6407fSRichard Henderson     if (m || disp == 0) {
229496d6407fSRichard Henderson         tcg_gen_mov_tl(addr, load_gpr(ctx, rb));
229596d6407fSRichard Henderson     } else {
229696d6407fSRichard Henderson         tcg_gen_addi_tl(addr, load_gpr(ctx, rb), disp);
229796d6407fSRichard Henderson     }
229896d6407fSRichard Henderson     val = load_gpr(ctx, rt);
229996d6407fSRichard Henderson 
230096d6407fSRichard Henderson     if (a) {
230196d6407fSRichard Henderson         gen_helper_stby_e(cpu_env, addr, val);
230296d6407fSRichard Henderson     } else {
230396d6407fSRichard Henderson         gen_helper_stby_b(cpu_env, addr, val);
230496d6407fSRichard Henderson     }
230596d6407fSRichard Henderson 
230696d6407fSRichard Henderson     if (m) {
230796d6407fSRichard Henderson         tcg_gen_addi_tl(addr, addr, disp);
230896d6407fSRichard Henderson         tcg_gen_andi_tl(addr, addr, ~3);
230996d6407fSRichard Henderson         save_gpr(ctx, rb, addr);
231096d6407fSRichard Henderson     }
231196d6407fSRichard Henderson     tcg_temp_free(addr);
231296d6407fSRichard Henderson 
2313*869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
231496d6407fSRichard Henderson }
231596d6407fSRichard Henderson 
231696d6407fSRichard Henderson static const DisasInsn table_index_mem[] = {
231796d6407fSRichard Henderson     { 0x0c001000u, 0xfc001300, trans_ld_idx_i }, /* LD[BHWD], im */
231896d6407fSRichard Henderson     { 0x0c000000u, 0xfc001300, trans_ld_idx_x }, /* LD[BHWD], rx */
231996d6407fSRichard Henderson     { 0x0c001200u, 0xfc001300, trans_st_idx_i }, /* ST[BHWD] */
232096d6407fSRichard Henderson     { 0x0c0001c0u, 0xfc0003c0, trans_ldcw },
232196d6407fSRichard Henderson     { 0x0c001300u, 0xfc0013c0, trans_stby },
232296d6407fSRichard Henderson };
232396d6407fSRichard Henderson 
2324*869051eaSRichard Henderson static DisasJumpType trans_ldil(DisasContext *ctx, uint32_t insn)
2325b2167459SRichard Henderson {
2326b2167459SRichard Henderson     unsigned rt = extract32(insn, 21, 5);
2327b2167459SRichard Henderson     target_long i = assemble_21(insn);
2328b2167459SRichard Henderson     TCGv tcg_rt = dest_gpr(ctx, rt);
2329b2167459SRichard Henderson 
2330b2167459SRichard Henderson     tcg_gen_movi_tl(tcg_rt, i);
2331b2167459SRichard Henderson     save_gpr(ctx, rt, tcg_rt);
2332b2167459SRichard Henderson     cond_free(&ctx->null_cond);
2333b2167459SRichard Henderson 
2334*869051eaSRichard Henderson     return DISAS_NEXT;
2335b2167459SRichard Henderson }
2336b2167459SRichard Henderson 
2337*869051eaSRichard Henderson static DisasJumpType trans_addil(DisasContext *ctx, uint32_t insn)
2338b2167459SRichard Henderson {
2339b2167459SRichard Henderson     unsigned rt = extract32(insn, 21, 5);
2340b2167459SRichard Henderson     target_long i = assemble_21(insn);
2341b2167459SRichard Henderson     TCGv tcg_rt = load_gpr(ctx, rt);
2342b2167459SRichard Henderson     TCGv tcg_r1 = dest_gpr(ctx, 1);
2343b2167459SRichard Henderson 
2344b2167459SRichard Henderson     tcg_gen_addi_tl(tcg_r1, tcg_rt, i);
2345b2167459SRichard Henderson     save_gpr(ctx, 1, tcg_r1);
2346b2167459SRichard Henderson     cond_free(&ctx->null_cond);
2347b2167459SRichard Henderson 
2348*869051eaSRichard Henderson     return DISAS_NEXT;
2349b2167459SRichard Henderson }
2350b2167459SRichard Henderson 
2351*869051eaSRichard Henderson static DisasJumpType trans_ldo(DisasContext *ctx, uint32_t insn)
2352b2167459SRichard Henderson {
2353b2167459SRichard Henderson     unsigned rb = extract32(insn, 21, 5);
2354b2167459SRichard Henderson     unsigned rt = extract32(insn, 16, 5);
2355b2167459SRichard Henderson     target_long i = assemble_16(insn);
2356b2167459SRichard Henderson     TCGv tcg_rt = dest_gpr(ctx, rt);
2357b2167459SRichard Henderson 
2358b2167459SRichard Henderson     /* Special case rb == 0, for the LDI pseudo-op.
2359b2167459SRichard Henderson        The COPY pseudo-op is handled for free within tcg_gen_addi_tl.  */
2360b2167459SRichard Henderson     if (rb == 0) {
2361b2167459SRichard Henderson         tcg_gen_movi_tl(tcg_rt, i);
2362b2167459SRichard Henderson     } else {
2363b2167459SRichard Henderson         tcg_gen_addi_tl(tcg_rt, cpu_gr[rb], i);
2364b2167459SRichard Henderson     }
2365b2167459SRichard Henderson     save_gpr(ctx, rt, tcg_rt);
2366b2167459SRichard Henderson     cond_free(&ctx->null_cond);
2367b2167459SRichard Henderson 
2368*869051eaSRichard Henderson     return DISAS_NEXT;
2369b2167459SRichard Henderson }
2370b2167459SRichard Henderson 
2371*869051eaSRichard Henderson static DisasJumpType trans_load(DisasContext *ctx, uint32_t insn,
237296d6407fSRichard Henderson                                 bool is_mod, TCGMemOp mop)
237396d6407fSRichard Henderson {
237496d6407fSRichard Henderson     unsigned rb = extract32(insn, 21, 5);
237596d6407fSRichard Henderson     unsigned rt = extract32(insn, 16, 5);
237696d6407fSRichard Henderson     target_long i = assemble_16(insn);
237796d6407fSRichard Henderson 
237896d6407fSRichard Henderson     return do_load(ctx, rt, rb, 0, 0, i, is_mod ? (i < 0 ? -1 : 1) : 0, mop);
237996d6407fSRichard Henderson }
238096d6407fSRichard Henderson 
2381*869051eaSRichard Henderson static DisasJumpType trans_load_w(DisasContext *ctx, uint32_t insn)
238296d6407fSRichard Henderson {
238396d6407fSRichard Henderson     unsigned rb = extract32(insn, 21, 5);
238496d6407fSRichard Henderson     unsigned rt = extract32(insn, 16, 5);
238596d6407fSRichard Henderson     target_long i = assemble_16a(insn);
238696d6407fSRichard Henderson     unsigned ext2 = extract32(insn, 1, 2);
238796d6407fSRichard Henderson 
238896d6407fSRichard Henderson     switch (ext2) {
238996d6407fSRichard Henderson     case 0:
239096d6407fSRichard Henderson     case 1:
239196d6407fSRichard Henderson         /* FLDW without modification.  */
239296d6407fSRichard Henderson         return do_floadw(ctx, ext2 * 32 + rt, rb, 0, 0, i, 0);
239396d6407fSRichard Henderson     case 2:
239496d6407fSRichard Henderson         /* LDW with modification.  Note that the sign of I selects
239596d6407fSRichard Henderson            post-dec vs pre-inc.  */
239696d6407fSRichard Henderson         return do_load(ctx, rt, rb, 0, 0, i, (i < 0 ? 1 : -1), MO_TEUL);
239796d6407fSRichard Henderson     default:
239896d6407fSRichard Henderson         return gen_illegal(ctx);
239996d6407fSRichard Henderson     }
240096d6407fSRichard Henderson }
240196d6407fSRichard Henderson 
2402*869051eaSRichard Henderson static DisasJumpType trans_fload_mod(DisasContext *ctx, uint32_t insn)
240396d6407fSRichard Henderson {
240496d6407fSRichard Henderson     target_long i = assemble_16a(insn);
240596d6407fSRichard Henderson     unsigned t1 = extract32(insn, 1, 1);
240696d6407fSRichard Henderson     unsigned a = extract32(insn, 2, 1);
240796d6407fSRichard Henderson     unsigned t0 = extract32(insn, 16, 5);
240896d6407fSRichard Henderson     unsigned rb = extract32(insn, 21, 5);
240996d6407fSRichard Henderson 
241096d6407fSRichard Henderson     /* FLDW with modification.  */
241196d6407fSRichard Henderson     return do_floadw(ctx, t1 * 32 + t0, rb, 0, 0, i, (a ? -1 : 1));
241296d6407fSRichard Henderson }
241396d6407fSRichard Henderson 
2414*869051eaSRichard Henderson static DisasJumpType trans_store(DisasContext *ctx, uint32_t insn,
241596d6407fSRichard Henderson                                  bool is_mod, TCGMemOp mop)
241696d6407fSRichard Henderson {
241796d6407fSRichard Henderson     unsigned rb = extract32(insn, 21, 5);
241896d6407fSRichard Henderson     unsigned rt = extract32(insn, 16, 5);
241996d6407fSRichard Henderson     target_long i = assemble_16(insn);
242096d6407fSRichard Henderson 
242196d6407fSRichard Henderson     return do_store(ctx, rt, rb, i, is_mod ? (i < 0 ? -1 : 1) : 0, mop);
242296d6407fSRichard Henderson }
242396d6407fSRichard Henderson 
2424*869051eaSRichard Henderson static DisasJumpType trans_store_w(DisasContext *ctx, uint32_t insn)
242596d6407fSRichard Henderson {
242696d6407fSRichard Henderson     unsigned rb = extract32(insn, 21, 5);
242796d6407fSRichard Henderson     unsigned rt = extract32(insn, 16, 5);
242896d6407fSRichard Henderson     target_long i = assemble_16a(insn);
242996d6407fSRichard Henderson     unsigned ext2 = extract32(insn, 1, 2);
243096d6407fSRichard Henderson 
243196d6407fSRichard Henderson     switch (ext2) {
243296d6407fSRichard Henderson     case 0:
243396d6407fSRichard Henderson     case 1:
243496d6407fSRichard Henderson         /* FSTW without modification.  */
243596d6407fSRichard Henderson         return do_fstorew(ctx, ext2 * 32 + rt, rb, 0, 0, i, 0);
243696d6407fSRichard Henderson     case 2:
243796d6407fSRichard Henderson         /* LDW with modification.  */
243896d6407fSRichard Henderson         return do_store(ctx, rt, rb, i, (i < 0 ? 1 : -1), MO_TEUL);
243996d6407fSRichard Henderson     default:
244096d6407fSRichard Henderson         return gen_illegal(ctx);
244196d6407fSRichard Henderson     }
244296d6407fSRichard Henderson }
244396d6407fSRichard Henderson 
2444*869051eaSRichard Henderson static DisasJumpType trans_fstore_mod(DisasContext *ctx, uint32_t insn)
244596d6407fSRichard Henderson {
244696d6407fSRichard Henderson     target_long i = assemble_16a(insn);
244796d6407fSRichard Henderson     unsigned t1 = extract32(insn, 1, 1);
244896d6407fSRichard Henderson     unsigned a = extract32(insn, 2, 1);
244996d6407fSRichard Henderson     unsigned t0 = extract32(insn, 16, 5);
245096d6407fSRichard Henderson     unsigned rb = extract32(insn, 21, 5);
245196d6407fSRichard Henderson 
245296d6407fSRichard Henderson     /* FSTW with modification.  */
245396d6407fSRichard Henderson     return do_fstorew(ctx, t1 * 32 + t0, rb, 0, 0, i, (a ? -1 : 1));
245496d6407fSRichard Henderson }
245596d6407fSRichard Henderson 
2456*869051eaSRichard Henderson static DisasJumpType trans_copr_w(DisasContext *ctx, uint32_t insn)
245796d6407fSRichard Henderson {
245896d6407fSRichard Henderson     unsigned t0 = extract32(insn, 0, 5);
245996d6407fSRichard Henderson     unsigned m = extract32(insn, 5, 1);
246096d6407fSRichard Henderson     unsigned t1 = extract32(insn, 6, 1);
246196d6407fSRichard Henderson     unsigned ext3 = extract32(insn, 7, 3);
246296d6407fSRichard Henderson     /* unsigned cc = extract32(insn, 10, 2); */
246396d6407fSRichard Henderson     unsigned i = extract32(insn, 12, 1);
246496d6407fSRichard Henderson     unsigned ua = extract32(insn, 13, 1);
246596d6407fSRichard Henderson     unsigned rx = extract32(insn, 16, 5);
246696d6407fSRichard Henderson     unsigned rb = extract32(insn, 21, 5);
246796d6407fSRichard Henderson     unsigned rt = t1 * 32 + t0;
246896d6407fSRichard Henderson     int modify = (m ? (ua ? -1 : 1) : 0);
246996d6407fSRichard Henderson     int disp, scale;
247096d6407fSRichard Henderson 
247196d6407fSRichard Henderson     if (i == 0) {
247296d6407fSRichard Henderson         scale = (ua ? 2 : 0);
247396d6407fSRichard Henderson         disp = 0;
247496d6407fSRichard Henderson         modify = m;
247596d6407fSRichard Henderson     } else {
247696d6407fSRichard Henderson         disp = low_sextract(rx, 0, 5);
247796d6407fSRichard Henderson         scale = 0;
247896d6407fSRichard Henderson         rx = 0;
247996d6407fSRichard Henderson         modify = (m ? (ua ? -1 : 1) : 0);
248096d6407fSRichard Henderson     }
248196d6407fSRichard Henderson 
248296d6407fSRichard Henderson     switch (ext3) {
248396d6407fSRichard Henderson     case 0: /* FLDW */
248496d6407fSRichard Henderson         return do_floadw(ctx, rt, rb, rx, scale, disp, modify);
248596d6407fSRichard Henderson     case 4: /* FSTW */
248696d6407fSRichard Henderson         return do_fstorew(ctx, rt, rb, rx, scale, disp, modify);
248796d6407fSRichard Henderson     }
248896d6407fSRichard Henderson     return gen_illegal(ctx);
248996d6407fSRichard Henderson }
249096d6407fSRichard Henderson 
2491*869051eaSRichard Henderson static DisasJumpType trans_copr_dw(DisasContext *ctx, uint32_t insn)
249296d6407fSRichard Henderson {
249396d6407fSRichard Henderson     unsigned rt = extract32(insn, 0, 5);
249496d6407fSRichard Henderson     unsigned m = extract32(insn, 5, 1);
249596d6407fSRichard Henderson     unsigned ext4 = extract32(insn, 6, 4);
249696d6407fSRichard Henderson     /* unsigned cc = extract32(insn, 10, 2); */
249796d6407fSRichard Henderson     unsigned i = extract32(insn, 12, 1);
249896d6407fSRichard Henderson     unsigned ua = extract32(insn, 13, 1);
249996d6407fSRichard Henderson     unsigned rx = extract32(insn, 16, 5);
250096d6407fSRichard Henderson     unsigned rb = extract32(insn, 21, 5);
250196d6407fSRichard Henderson     int modify = (m ? (ua ? -1 : 1) : 0);
250296d6407fSRichard Henderson     int disp, scale;
250396d6407fSRichard Henderson 
250496d6407fSRichard Henderson     if (i == 0) {
250596d6407fSRichard Henderson         scale = (ua ? 3 : 0);
250696d6407fSRichard Henderson         disp = 0;
250796d6407fSRichard Henderson         modify = m;
250896d6407fSRichard Henderson     } else {
250996d6407fSRichard Henderson         disp = low_sextract(rx, 0, 5);
251096d6407fSRichard Henderson         scale = 0;
251196d6407fSRichard Henderson         rx = 0;
251296d6407fSRichard Henderson         modify = (m ? (ua ? -1 : 1) : 0);
251396d6407fSRichard Henderson     }
251496d6407fSRichard Henderson 
251596d6407fSRichard Henderson     switch (ext4) {
251696d6407fSRichard Henderson     case 0: /* FLDD */
251796d6407fSRichard Henderson         return do_floadd(ctx, rt, rb, rx, scale, disp, modify);
251896d6407fSRichard Henderson     case 8: /* FSTD */
251996d6407fSRichard Henderson         return do_fstored(ctx, rt, rb, rx, scale, disp, modify);
252096d6407fSRichard Henderson     default:
252196d6407fSRichard Henderson         return gen_illegal(ctx);
252296d6407fSRichard Henderson     }
252396d6407fSRichard Henderson }
252496d6407fSRichard Henderson 
2525*869051eaSRichard Henderson static DisasJumpType trans_cmpb(DisasContext *ctx, uint32_t insn,
252698cd9ca7SRichard Henderson                                 bool is_true, bool is_imm, bool is_dw)
252798cd9ca7SRichard Henderson {
252898cd9ca7SRichard Henderson     target_long disp = assemble_12(insn) * 4;
252998cd9ca7SRichard Henderson     unsigned n = extract32(insn, 1, 1);
253098cd9ca7SRichard Henderson     unsigned c = extract32(insn, 13, 3);
253198cd9ca7SRichard Henderson     unsigned r = extract32(insn, 21, 5);
253298cd9ca7SRichard Henderson     unsigned cf = c * 2 + !is_true;
253398cd9ca7SRichard Henderson     TCGv dest, in1, in2, sv;
253498cd9ca7SRichard Henderson     DisasCond cond;
253598cd9ca7SRichard Henderson 
253698cd9ca7SRichard Henderson     nullify_over(ctx);
253798cd9ca7SRichard Henderson 
253898cd9ca7SRichard Henderson     if (is_imm) {
253998cd9ca7SRichard Henderson         in1 = load_const(ctx, low_sextract(insn, 16, 5));
254098cd9ca7SRichard Henderson     } else {
254198cd9ca7SRichard Henderson         in1 = load_gpr(ctx, extract32(insn, 16, 5));
254298cd9ca7SRichard Henderson     }
254398cd9ca7SRichard Henderson     in2 = load_gpr(ctx, r);
254498cd9ca7SRichard Henderson     dest = get_temp(ctx);
254598cd9ca7SRichard Henderson 
254698cd9ca7SRichard Henderson     tcg_gen_sub_tl(dest, in1, in2);
254798cd9ca7SRichard Henderson 
254898cd9ca7SRichard Henderson     TCGV_UNUSED(sv);
254998cd9ca7SRichard Henderson     if (c == 6) {
255098cd9ca7SRichard Henderson         sv = do_sub_sv(ctx, dest, in1, in2);
255198cd9ca7SRichard Henderson     }
255298cd9ca7SRichard Henderson 
255398cd9ca7SRichard Henderson     cond = do_sub_cond(cf, dest, in1, in2, sv);
255498cd9ca7SRichard Henderson     return do_cbranch(ctx, disp, n, &cond);
255598cd9ca7SRichard Henderson }
255698cd9ca7SRichard Henderson 
2557*869051eaSRichard Henderson static DisasJumpType trans_addb(DisasContext *ctx, uint32_t insn,
255898cd9ca7SRichard Henderson                                 bool is_true, bool is_imm)
255998cd9ca7SRichard Henderson {
256098cd9ca7SRichard Henderson     target_long disp = assemble_12(insn) * 4;
256198cd9ca7SRichard Henderson     unsigned n = extract32(insn, 1, 1);
256298cd9ca7SRichard Henderson     unsigned c = extract32(insn, 13, 3);
256398cd9ca7SRichard Henderson     unsigned r = extract32(insn, 21, 5);
256498cd9ca7SRichard Henderson     unsigned cf = c * 2 + !is_true;
256598cd9ca7SRichard Henderson     TCGv dest, in1, in2, sv, cb_msb;
256698cd9ca7SRichard Henderson     DisasCond cond;
256798cd9ca7SRichard Henderson 
256898cd9ca7SRichard Henderson     nullify_over(ctx);
256998cd9ca7SRichard Henderson 
257098cd9ca7SRichard Henderson     if (is_imm) {
257198cd9ca7SRichard Henderson         in1 = load_const(ctx, low_sextract(insn, 16, 5));
257298cd9ca7SRichard Henderson     } else {
257398cd9ca7SRichard Henderson         in1 = load_gpr(ctx, extract32(insn, 16, 5));
257498cd9ca7SRichard Henderson     }
257598cd9ca7SRichard Henderson     in2 = load_gpr(ctx, r);
257698cd9ca7SRichard Henderson     dest = dest_gpr(ctx, r);
257798cd9ca7SRichard Henderson     TCGV_UNUSED(sv);
257898cd9ca7SRichard Henderson     TCGV_UNUSED(cb_msb);
257998cd9ca7SRichard Henderson 
258098cd9ca7SRichard Henderson     switch (c) {
258198cd9ca7SRichard Henderson     default:
258298cd9ca7SRichard Henderson         tcg_gen_add_tl(dest, in1, in2);
258398cd9ca7SRichard Henderson         break;
258498cd9ca7SRichard Henderson     case 4: case 5:
258598cd9ca7SRichard Henderson         cb_msb = get_temp(ctx);
258698cd9ca7SRichard Henderson         tcg_gen_movi_tl(cb_msb, 0);
258798cd9ca7SRichard Henderson         tcg_gen_add2_tl(dest, cb_msb, in1, cb_msb, in2, cb_msb);
258898cd9ca7SRichard Henderson         break;
258998cd9ca7SRichard Henderson     case 6:
259098cd9ca7SRichard Henderson         tcg_gen_add_tl(dest, in1, in2);
259198cd9ca7SRichard Henderson         sv = do_add_sv(ctx, dest, in1, in2);
259298cd9ca7SRichard Henderson         break;
259398cd9ca7SRichard Henderson     }
259498cd9ca7SRichard Henderson 
259598cd9ca7SRichard Henderson     cond = do_cond(cf, dest, cb_msb, sv);
259698cd9ca7SRichard Henderson     return do_cbranch(ctx, disp, n, &cond);
259798cd9ca7SRichard Henderson }
259898cd9ca7SRichard Henderson 
2599*869051eaSRichard Henderson static DisasJumpType trans_bb(DisasContext *ctx, uint32_t insn)
260098cd9ca7SRichard Henderson {
260198cd9ca7SRichard Henderson     target_long disp = assemble_12(insn) * 4;
260298cd9ca7SRichard Henderson     unsigned n = extract32(insn, 1, 1);
260398cd9ca7SRichard Henderson     unsigned c = extract32(insn, 15, 1);
260498cd9ca7SRichard Henderson     unsigned r = extract32(insn, 16, 5);
260598cd9ca7SRichard Henderson     unsigned p = extract32(insn, 21, 5);
260698cd9ca7SRichard Henderson     unsigned i = extract32(insn, 26, 1);
260798cd9ca7SRichard Henderson     TCGv tmp, tcg_r;
260898cd9ca7SRichard Henderson     DisasCond cond;
260998cd9ca7SRichard Henderson 
261098cd9ca7SRichard Henderson     nullify_over(ctx);
261198cd9ca7SRichard Henderson 
261298cd9ca7SRichard Henderson     tmp = tcg_temp_new();
261398cd9ca7SRichard Henderson     tcg_r = load_gpr(ctx, r);
261498cd9ca7SRichard Henderson     if (i) {
261598cd9ca7SRichard Henderson         tcg_gen_shli_tl(tmp, tcg_r, p);
261698cd9ca7SRichard Henderson     } else {
261798cd9ca7SRichard Henderson         tcg_gen_shl_tl(tmp, tcg_r, cpu_sar);
261898cd9ca7SRichard Henderson     }
261998cd9ca7SRichard Henderson 
262098cd9ca7SRichard Henderson     cond = cond_make_0(c ? TCG_COND_GE : TCG_COND_LT, tmp);
262198cd9ca7SRichard Henderson     tcg_temp_free(tmp);
262298cd9ca7SRichard Henderson     return do_cbranch(ctx, disp, n, &cond);
262398cd9ca7SRichard Henderson }
262498cd9ca7SRichard Henderson 
2625*869051eaSRichard Henderson static DisasJumpType trans_movb(DisasContext *ctx, uint32_t insn, bool is_imm)
262698cd9ca7SRichard Henderson {
262798cd9ca7SRichard Henderson     target_long disp = assemble_12(insn) * 4;
262898cd9ca7SRichard Henderson     unsigned n = extract32(insn, 1, 1);
262998cd9ca7SRichard Henderson     unsigned c = extract32(insn, 13, 3);
263098cd9ca7SRichard Henderson     unsigned t = extract32(insn, 16, 5);
263198cd9ca7SRichard Henderson     unsigned r = extract32(insn, 21, 5);
263298cd9ca7SRichard Henderson     TCGv dest;
263398cd9ca7SRichard Henderson     DisasCond cond;
263498cd9ca7SRichard Henderson 
263598cd9ca7SRichard Henderson     nullify_over(ctx);
263698cd9ca7SRichard Henderson 
263798cd9ca7SRichard Henderson     dest = dest_gpr(ctx, r);
263898cd9ca7SRichard Henderson     if (is_imm) {
263998cd9ca7SRichard Henderson         tcg_gen_movi_tl(dest, low_sextract(t, 0, 5));
264098cd9ca7SRichard Henderson     } else if (t == 0) {
264198cd9ca7SRichard Henderson         tcg_gen_movi_tl(dest, 0);
264298cd9ca7SRichard Henderson     } else {
264398cd9ca7SRichard Henderson         tcg_gen_mov_tl(dest, cpu_gr[t]);
264498cd9ca7SRichard Henderson     }
264598cd9ca7SRichard Henderson 
264698cd9ca7SRichard Henderson     cond = do_sed_cond(c, dest);
264798cd9ca7SRichard Henderson     return do_cbranch(ctx, disp, n, &cond);
264898cd9ca7SRichard Henderson }
264998cd9ca7SRichard Henderson 
2650*869051eaSRichard Henderson static DisasJumpType trans_shrpw_sar(DisasContext *ctx, uint32_t insn,
26510b1347d2SRichard Henderson                                     const DisasInsn *di)
26520b1347d2SRichard Henderson {
26530b1347d2SRichard Henderson     unsigned rt = extract32(insn, 0, 5);
26540b1347d2SRichard Henderson     unsigned c = extract32(insn, 13, 3);
26550b1347d2SRichard Henderson     unsigned r1 = extract32(insn, 16, 5);
26560b1347d2SRichard Henderson     unsigned r2 = extract32(insn, 21, 5);
26570b1347d2SRichard Henderson     TCGv dest;
26580b1347d2SRichard Henderson 
26590b1347d2SRichard Henderson     if (c) {
26600b1347d2SRichard Henderson         nullify_over(ctx);
26610b1347d2SRichard Henderson     }
26620b1347d2SRichard Henderson 
26630b1347d2SRichard Henderson     dest = dest_gpr(ctx, rt);
26640b1347d2SRichard Henderson     if (r1 == 0) {
26650b1347d2SRichard Henderson         tcg_gen_ext32u_tl(dest, load_gpr(ctx, r2));
26660b1347d2SRichard Henderson         tcg_gen_shr_tl(dest, dest, cpu_sar);
26670b1347d2SRichard Henderson     } else if (r1 == r2) {
26680b1347d2SRichard Henderson         TCGv_i32 t32 = tcg_temp_new_i32();
26690b1347d2SRichard Henderson         tcg_gen_trunc_tl_i32(t32, load_gpr(ctx, r2));
26700b1347d2SRichard Henderson         tcg_gen_rotr_i32(t32, t32, cpu_sar);
26710b1347d2SRichard Henderson         tcg_gen_extu_i32_tl(dest, t32);
26720b1347d2SRichard Henderson         tcg_temp_free_i32(t32);
26730b1347d2SRichard Henderson     } else {
26740b1347d2SRichard Henderson         TCGv_i64 t = tcg_temp_new_i64();
26750b1347d2SRichard Henderson         TCGv_i64 s = tcg_temp_new_i64();
26760b1347d2SRichard Henderson 
26770b1347d2SRichard Henderson         tcg_gen_concat_tl_i64(t, load_gpr(ctx, r2), load_gpr(ctx, r1));
26780b1347d2SRichard Henderson         tcg_gen_extu_tl_i64(s, cpu_sar);
26790b1347d2SRichard Henderson         tcg_gen_shr_i64(t, t, s);
26800b1347d2SRichard Henderson         tcg_gen_trunc_i64_tl(dest, t);
26810b1347d2SRichard Henderson 
26820b1347d2SRichard Henderson         tcg_temp_free_i64(t);
26830b1347d2SRichard Henderson         tcg_temp_free_i64(s);
26840b1347d2SRichard Henderson     }
26850b1347d2SRichard Henderson     save_gpr(ctx, rt, dest);
26860b1347d2SRichard Henderson 
26870b1347d2SRichard Henderson     /* Install the new nullification.  */
26880b1347d2SRichard Henderson     cond_free(&ctx->null_cond);
26890b1347d2SRichard Henderson     if (c) {
26900b1347d2SRichard Henderson         ctx->null_cond = do_sed_cond(c, dest);
26910b1347d2SRichard Henderson     }
2692*869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
26930b1347d2SRichard Henderson }
26940b1347d2SRichard Henderson 
2695*869051eaSRichard Henderson static DisasJumpType trans_shrpw_imm(DisasContext *ctx, uint32_t insn,
26960b1347d2SRichard Henderson                                      const DisasInsn *di)
26970b1347d2SRichard Henderson {
26980b1347d2SRichard Henderson     unsigned rt = extract32(insn, 0, 5);
26990b1347d2SRichard Henderson     unsigned cpos = extract32(insn, 5, 5);
27000b1347d2SRichard Henderson     unsigned c = extract32(insn, 13, 3);
27010b1347d2SRichard Henderson     unsigned r1 = extract32(insn, 16, 5);
27020b1347d2SRichard Henderson     unsigned r2 = extract32(insn, 21, 5);
27030b1347d2SRichard Henderson     unsigned sa = 31 - cpos;
27040b1347d2SRichard Henderson     TCGv dest, t2;
27050b1347d2SRichard Henderson 
27060b1347d2SRichard Henderson     if (c) {
27070b1347d2SRichard Henderson         nullify_over(ctx);
27080b1347d2SRichard Henderson     }
27090b1347d2SRichard Henderson 
27100b1347d2SRichard Henderson     dest = dest_gpr(ctx, rt);
27110b1347d2SRichard Henderson     t2 = load_gpr(ctx, r2);
27120b1347d2SRichard Henderson     if (r1 == r2) {
27130b1347d2SRichard Henderson         TCGv_i32 t32 = tcg_temp_new_i32();
27140b1347d2SRichard Henderson         tcg_gen_trunc_tl_i32(t32, t2);
27150b1347d2SRichard Henderson         tcg_gen_rotri_i32(t32, t32, sa);
27160b1347d2SRichard Henderson         tcg_gen_extu_i32_tl(dest, t32);
27170b1347d2SRichard Henderson         tcg_temp_free_i32(t32);
27180b1347d2SRichard Henderson     } else if (r1 == 0) {
27190b1347d2SRichard Henderson         tcg_gen_extract_tl(dest, t2, sa, 32 - sa);
27200b1347d2SRichard Henderson     } else {
27210b1347d2SRichard Henderson         TCGv t0 = tcg_temp_new();
27220b1347d2SRichard Henderson         tcg_gen_extract_tl(t0, t2, sa, 32 - sa);
27230b1347d2SRichard Henderson         tcg_gen_deposit_tl(dest, t0, cpu_gr[r1], 32 - sa, sa);
27240b1347d2SRichard Henderson         tcg_temp_free(t0);
27250b1347d2SRichard Henderson     }
27260b1347d2SRichard Henderson     save_gpr(ctx, rt, dest);
27270b1347d2SRichard Henderson 
27280b1347d2SRichard Henderson     /* Install the new nullification.  */
27290b1347d2SRichard Henderson     cond_free(&ctx->null_cond);
27300b1347d2SRichard Henderson     if (c) {
27310b1347d2SRichard Henderson         ctx->null_cond = do_sed_cond(c, dest);
27320b1347d2SRichard Henderson     }
2733*869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
27340b1347d2SRichard Henderson }
27350b1347d2SRichard Henderson 
2736*869051eaSRichard Henderson static DisasJumpType trans_extrw_sar(DisasContext *ctx, uint32_t insn,
27370b1347d2SRichard Henderson                                      const DisasInsn *di)
27380b1347d2SRichard Henderson {
27390b1347d2SRichard Henderson     unsigned clen = extract32(insn, 0, 5);
27400b1347d2SRichard Henderson     unsigned is_se = extract32(insn, 10, 1);
27410b1347d2SRichard Henderson     unsigned c = extract32(insn, 13, 3);
27420b1347d2SRichard Henderson     unsigned rt = extract32(insn, 16, 5);
27430b1347d2SRichard Henderson     unsigned rr = extract32(insn, 21, 5);
27440b1347d2SRichard Henderson     unsigned len = 32 - clen;
27450b1347d2SRichard Henderson     TCGv dest, src, tmp;
27460b1347d2SRichard Henderson 
27470b1347d2SRichard Henderson     if (c) {
27480b1347d2SRichard Henderson         nullify_over(ctx);
27490b1347d2SRichard Henderson     }
27500b1347d2SRichard Henderson 
27510b1347d2SRichard Henderson     dest = dest_gpr(ctx, rt);
27520b1347d2SRichard Henderson     src = load_gpr(ctx, rr);
27530b1347d2SRichard Henderson     tmp = tcg_temp_new();
27540b1347d2SRichard Henderson 
27550b1347d2SRichard Henderson     /* Recall that SAR is using big-endian bit numbering.  */
27560b1347d2SRichard Henderson     tcg_gen_xori_tl(tmp, cpu_sar, TARGET_LONG_BITS - 1);
27570b1347d2SRichard Henderson     if (is_se) {
27580b1347d2SRichard Henderson         tcg_gen_sar_tl(dest, src, tmp);
27590b1347d2SRichard Henderson         tcg_gen_sextract_tl(dest, dest, 0, len);
27600b1347d2SRichard Henderson     } else {
27610b1347d2SRichard Henderson         tcg_gen_shr_tl(dest, src, tmp);
27620b1347d2SRichard Henderson         tcg_gen_extract_tl(dest, dest, 0, len);
27630b1347d2SRichard Henderson     }
27640b1347d2SRichard Henderson     tcg_temp_free(tmp);
27650b1347d2SRichard Henderson     save_gpr(ctx, rt, dest);
27660b1347d2SRichard Henderson 
27670b1347d2SRichard Henderson     /* Install the new nullification.  */
27680b1347d2SRichard Henderson     cond_free(&ctx->null_cond);
27690b1347d2SRichard Henderson     if (c) {
27700b1347d2SRichard Henderson         ctx->null_cond = do_sed_cond(c, dest);
27710b1347d2SRichard Henderson     }
2772*869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
27730b1347d2SRichard Henderson }
27740b1347d2SRichard Henderson 
2775*869051eaSRichard Henderson static DisasJumpType trans_extrw_imm(DisasContext *ctx, uint32_t insn,
27760b1347d2SRichard Henderson                                      const DisasInsn *di)
27770b1347d2SRichard Henderson {
27780b1347d2SRichard Henderson     unsigned clen = extract32(insn, 0, 5);
27790b1347d2SRichard Henderson     unsigned pos = extract32(insn, 5, 5);
27800b1347d2SRichard Henderson     unsigned is_se = extract32(insn, 10, 1);
27810b1347d2SRichard Henderson     unsigned c = extract32(insn, 13, 3);
27820b1347d2SRichard Henderson     unsigned rt = extract32(insn, 16, 5);
27830b1347d2SRichard Henderson     unsigned rr = extract32(insn, 21, 5);
27840b1347d2SRichard Henderson     unsigned len = 32 - clen;
27850b1347d2SRichard Henderson     unsigned cpos = 31 - pos;
27860b1347d2SRichard Henderson     TCGv dest, src;
27870b1347d2SRichard Henderson 
27880b1347d2SRichard Henderson     if (c) {
27890b1347d2SRichard Henderson         nullify_over(ctx);
27900b1347d2SRichard Henderson     }
27910b1347d2SRichard Henderson 
27920b1347d2SRichard Henderson     dest = dest_gpr(ctx, rt);
27930b1347d2SRichard Henderson     src = load_gpr(ctx, rr);
27940b1347d2SRichard Henderson     if (is_se) {
27950b1347d2SRichard Henderson         tcg_gen_sextract_tl(dest, src, cpos, len);
27960b1347d2SRichard Henderson     } else {
27970b1347d2SRichard Henderson         tcg_gen_extract_tl(dest, src, cpos, len);
27980b1347d2SRichard Henderson     }
27990b1347d2SRichard Henderson     save_gpr(ctx, rt, dest);
28000b1347d2SRichard Henderson 
28010b1347d2SRichard Henderson     /* Install the new nullification.  */
28020b1347d2SRichard Henderson     cond_free(&ctx->null_cond);
28030b1347d2SRichard Henderson     if (c) {
28040b1347d2SRichard Henderson         ctx->null_cond = do_sed_cond(c, dest);
28050b1347d2SRichard Henderson     }
2806*869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
28070b1347d2SRichard Henderson }
28080b1347d2SRichard Henderson 
28090b1347d2SRichard Henderson static const DisasInsn table_sh_ex[] = {
28100b1347d2SRichard Henderson     { 0xd0000000u, 0xfc001fe0u, trans_shrpw_sar },
28110b1347d2SRichard Henderson     { 0xd0000800u, 0xfc001c00u, trans_shrpw_imm },
28120b1347d2SRichard Henderson     { 0xd0001000u, 0xfc001be0u, trans_extrw_sar },
28130b1347d2SRichard Henderson     { 0xd0001800u, 0xfc001800u, trans_extrw_imm },
28140b1347d2SRichard Henderson };
28150b1347d2SRichard Henderson 
2816*869051eaSRichard Henderson static DisasJumpType trans_depw_imm_c(DisasContext *ctx, uint32_t insn,
28170b1347d2SRichard Henderson                                       const DisasInsn *di)
28180b1347d2SRichard Henderson {
28190b1347d2SRichard Henderson     unsigned clen = extract32(insn, 0, 5);
28200b1347d2SRichard Henderson     unsigned cpos = extract32(insn, 5, 5);
28210b1347d2SRichard Henderson     unsigned nz = extract32(insn, 10, 1);
28220b1347d2SRichard Henderson     unsigned c = extract32(insn, 13, 3);
28230b1347d2SRichard Henderson     target_long val = low_sextract(insn, 16, 5);
28240b1347d2SRichard Henderson     unsigned rt = extract32(insn, 21, 5);
28250b1347d2SRichard Henderson     unsigned len = 32 - clen;
28260b1347d2SRichard Henderson     target_long mask0, mask1;
28270b1347d2SRichard Henderson     TCGv dest;
28280b1347d2SRichard Henderson 
28290b1347d2SRichard Henderson     if (c) {
28300b1347d2SRichard Henderson         nullify_over(ctx);
28310b1347d2SRichard Henderson     }
28320b1347d2SRichard Henderson     if (cpos + len > 32) {
28330b1347d2SRichard Henderson         len = 32 - cpos;
28340b1347d2SRichard Henderson     }
28350b1347d2SRichard Henderson 
28360b1347d2SRichard Henderson     dest = dest_gpr(ctx, rt);
28370b1347d2SRichard Henderson     mask0 = deposit64(0, cpos, len, val);
28380b1347d2SRichard Henderson     mask1 = deposit64(-1, cpos, len, val);
28390b1347d2SRichard Henderson 
28400b1347d2SRichard Henderson     if (nz) {
28410b1347d2SRichard Henderson         TCGv src = load_gpr(ctx, rt);
28420b1347d2SRichard Henderson         if (mask1 != -1) {
28430b1347d2SRichard Henderson             tcg_gen_andi_tl(dest, src, mask1);
28440b1347d2SRichard Henderson             src = dest;
28450b1347d2SRichard Henderson         }
28460b1347d2SRichard Henderson         tcg_gen_ori_tl(dest, src, mask0);
28470b1347d2SRichard Henderson     } else {
28480b1347d2SRichard Henderson         tcg_gen_movi_tl(dest, mask0);
28490b1347d2SRichard Henderson     }
28500b1347d2SRichard Henderson     save_gpr(ctx, rt, dest);
28510b1347d2SRichard Henderson 
28520b1347d2SRichard Henderson     /* Install the new nullification.  */
28530b1347d2SRichard Henderson     cond_free(&ctx->null_cond);
28540b1347d2SRichard Henderson     if (c) {
28550b1347d2SRichard Henderson         ctx->null_cond = do_sed_cond(c, dest);
28560b1347d2SRichard Henderson     }
2857*869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
28580b1347d2SRichard Henderson }
28590b1347d2SRichard Henderson 
2860*869051eaSRichard Henderson static DisasJumpType trans_depw_imm(DisasContext *ctx, uint32_t insn,
28610b1347d2SRichard Henderson                                     const DisasInsn *di)
28620b1347d2SRichard Henderson {
28630b1347d2SRichard Henderson     unsigned clen = extract32(insn, 0, 5);
28640b1347d2SRichard Henderson     unsigned cpos = extract32(insn, 5, 5);
28650b1347d2SRichard Henderson     unsigned nz = extract32(insn, 10, 1);
28660b1347d2SRichard Henderson     unsigned c = extract32(insn, 13, 3);
28670b1347d2SRichard Henderson     unsigned rr = extract32(insn, 16, 5);
28680b1347d2SRichard Henderson     unsigned rt = extract32(insn, 21, 5);
28690b1347d2SRichard Henderson     unsigned rs = nz ? rt : 0;
28700b1347d2SRichard Henderson     unsigned len = 32 - clen;
28710b1347d2SRichard Henderson     TCGv dest, val;
28720b1347d2SRichard Henderson 
28730b1347d2SRichard Henderson     if (c) {
28740b1347d2SRichard Henderson         nullify_over(ctx);
28750b1347d2SRichard Henderson     }
28760b1347d2SRichard Henderson     if (cpos + len > 32) {
28770b1347d2SRichard Henderson         len = 32 - cpos;
28780b1347d2SRichard Henderson     }
28790b1347d2SRichard Henderson 
28800b1347d2SRichard Henderson     dest = dest_gpr(ctx, rt);
28810b1347d2SRichard Henderson     val = load_gpr(ctx, rr);
28820b1347d2SRichard Henderson     if (rs == 0) {
28830b1347d2SRichard Henderson         tcg_gen_deposit_z_tl(dest, val, cpos, len);
28840b1347d2SRichard Henderson     } else {
28850b1347d2SRichard Henderson         tcg_gen_deposit_tl(dest, cpu_gr[rs], val, cpos, len);
28860b1347d2SRichard Henderson     }
28870b1347d2SRichard Henderson     save_gpr(ctx, rt, dest);
28880b1347d2SRichard Henderson 
28890b1347d2SRichard Henderson     /* Install the new nullification.  */
28900b1347d2SRichard Henderson     cond_free(&ctx->null_cond);
28910b1347d2SRichard Henderson     if (c) {
28920b1347d2SRichard Henderson         ctx->null_cond = do_sed_cond(c, dest);
28930b1347d2SRichard Henderson     }
2894*869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
28950b1347d2SRichard Henderson }
28960b1347d2SRichard Henderson 
2897*869051eaSRichard Henderson static DisasJumpType trans_depw_sar(DisasContext *ctx, uint32_t insn,
28980b1347d2SRichard Henderson                                     const DisasInsn *di)
28990b1347d2SRichard Henderson {
29000b1347d2SRichard Henderson     unsigned clen = extract32(insn, 0, 5);
29010b1347d2SRichard Henderson     unsigned nz = extract32(insn, 10, 1);
29020b1347d2SRichard Henderson     unsigned i = extract32(insn, 12, 1);
29030b1347d2SRichard Henderson     unsigned c = extract32(insn, 13, 3);
29040b1347d2SRichard Henderson     unsigned rt = extract32(insn, 21, 5);
29050b1347d2SRichard Henderson     unsigned rs = nz ? rt : 0;
29060b1347d2SRichard Henderson     unsigned len = 32 - clen;
29070b1347d2SRichard Henderson     TCGv val, mask, tmp, shift, dest;
29080b1347d2SRichard Henderson     unsigned msb = 1U << (len - 1);
29090b1347d2SRichard Henderson 
29100b1347d2SRichard Henderson     if (c) {
29110b1347d2SRichard Henderson         nullify_over(ctx);
29120b1347d2SRichard Henderson     }
29130b1347d2SRichard Henderson 
29140b1347d2SRichard Henderson     if (i) {
29150b1347d2SRichard Henderson         val = load_const(ctx, low_sextract(insn, 16, 5));
29160b1347d2SRichard Henderson     } else {
29170b1347d2SRichard Henderson         val = load_gpr(ctx, extract32(insn, 16, 5));
29180b1347d2SRichard Henderson     }
29190b1347d2SRichard Henderson     dest = dest_gpr(ctx, rt);
29200b1347d2SRichard Henderson     shift = tcg_temp_new();
29210b1347d2SRichard Henderson     tmp = tcg_temp_new();
29220b1347d2SRichard Henderson 
29230b1347d2SRichard Henderson     /* Convert big-endian bit numbering in SAR to left-shift.  */
29240b1347d2SRichard Henderson     tcg_gen_xori_tl(shift, cpu_sar, TARGET_LONG_BITS - 1);
29250b1347d2SRichard Henderson 
29260b1347d2SRichard Henderson     mask = tcg_const_tl(msb + (msb - 1));
29270b1347d2SRichard Henderson     tcg_gen_and_tl(tmp, val, mask);
29280b1347d2SRichard Henderson     if (rs) {
29290b1347d2SRichard Henderson         tcg_gen_shl_tl(mask, mask, shift);
29300b1347d2SRichard Henderson         tcg_gen_shl_tl(tmp, tmp, shift);
29310b1347d2SRichard Henderson         tcg_gen_andc_tl(dest, cpu_gr[rs], mask);
29320b1347d2SRichard Henderson         tcg_gen_or_tl(dest, dest, tmp);
29330b1347d2SRichard Henderson     } else {
29340b1347d2SRichard Henderson         tcg_gen_shl_tl(dest, tmp, shift);
29350b1347d2SRichard Henderson     }
29360b1347d2SRichard Henderson     tcg_temp_free(shift);
29370b1347d2SRichard Henderson     tcg_temp_free(mask);
29380b1347d2SRichard Henderson     tcg_temp_free(tmp);
29390b1347d2SRichard Henderson     save_gpr(ctx, rt, dest);
29400b1347d2SRichard Henderson 
29410b1347d2SRichard Henderson     /* Install the new nullification.  */
29420b1347d2SRichard Henderson     cond_free(&ctx->null_cond);
29430b1347d2SRichard Henderson     if (c) {
29440b1347d2SRichard Henderson         ctx->null_cond = do_sed_cond(c, dest);
29450b1347d2SRichard Henderson     }
2946*869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
29470b1347d2SRichard Henderson }
29480b1347d2SRichard Henderson 
29490b1347d2SRichard Henderson static const DisasInsn table_depw[] = {
29500b1347d2SRichard Henderson     { 0xd4000000u, 0xfc000be0u, trans_depw_sar },
29510b1347d2SRichard Henderson     { 0xd4000800u, 0xfc001800u, trans_depw_imm },
29520b1347d2SRichard Henderson     { 0xd4001800u, 0xfc001800u, trans_depw_imm_c },
29530b1347d2SRichard Henderson };
29540b1347d2SRichard Henderson 
2955*869051eaSRichard Henderson static DisasJumpType trans_be(DisasContext *ctx, uint32_t insn, bool is_l)
295698cd9ca7SRichard Henderson {
295798cd9ca7SRichard Henderson     unsigned n = extract32(insn, 1, 1);
295898cd9ca7SRichard Henderson     unsigned b = extract32(insn, 21, 5);
295998cd9ca7SRichard Henderson     target_long disp = assemble_17(insn);
296098cd9ca7SRichard Henderson 
296198cd9ca7SRichard Henderson     /* unsigned s = low_uextract(insn, 13, 3); */
296298cd9ca7SRichard Henderson     /* ??? It seems like there should be a good way of using
296398cd9ca7SRichard Henderson        "be disp(sr2, r0)", the canonical gateway entry mechanism
296498cd9ca7SRichard Henderson        to our advantage.  But that appears to be inconvenient to
296598cd9ca7SRichard Henderson        manage along side branch delay slots.  Therefore we handle
296698cd9ca7SRichard Henderson        entry into the gateway page via absolute address.  */
296798cd9ca7SRichard Henderson 
296898cd9ca7SRichard Henderson     /* Since we don't implement spaces, just branch.  Do notice the special
296998cd9ca7SRichard Henderson        case of "be disp(*,r0)" using a direct branch to disp, so that we can
297098cd9ca7SRichard Henderson        goto_tb to the TB containing the syscall.  */
297198cd9ca7SRichard Henderson     if (b == 0) {
297298cd9ca7SRichard Henderson         return do_dbranch(ctx, disp, is_l ? 31 : 0, n);
297398cd9ca7SRichard Henderson     } else {
297498cd9ca7SRichard Henderson         TCGv tmp = get_temp(ctx);
297598cd9ca7SRichard Henderson         tcg_gen_addi_tl(tmp, load_gpr(ctx, b), disp);
297698cd9ca7SRichard Henderson         return do_ibranch(ctx, tmp, is_l ? 31 : 0, n);
297798cd9ca7SRichard Henderson     }
297898cd9ca7SRichard Henderson }
297998cd9ca7SRichard Henderson 
2980*869051eaSRichard Henderson static DisasJumpType trans_bl(DisasContext *ctx, uint32_t insn,
298198cd9ca7SRichard Henderson                               const DisasInsn *di)
298298cd9ca7SRichard Henderson {
298398cd9ca7SRichard Henderson     unsigned n = extract32(insn, 1, 1);
298498cd9ca7SRichard Henderson     unsigned link = extract32(insn, 21, 5);
298598cd9ca7SRichard Henderson     target_long disp = assemble_17(insn);
298698cd9ca7SRichard Henderson 
298798cd9ca7SRichard Henderson     return do_dbranch(ctx, iaoq_dest(ctx, disp), link, n);
298898cd9ca7SRichard Henderson }
298998cd9ca7SRichard Henderson 
2990*869051eaSRichard Henderson static DisasJumpType trans_bl_long(DisasContext *ctx, uint32_t insn,
299198cd9ca7SRichard Henderson                                    const DisasInsn *di)
299298cd9ca7SRichard Henderson {
299398cd9ca7SRichard Henderson     unsigned n = extract32(insn, 1, 1);
299498cd9ca7SRichard Henderson     target_long disp = assemble_22(insn);
299598cd9ca7SRichard Henderson 
299698cd9ca7SRichard Henderson     return do_dbranch(ctx, iaoq_dest(ctx, disp), 2, n);
299798cd9ca7SRichard Henderson }
299898cd9ca7SRichard Henderson 
2999*869051eaSRichard Henderson static DisasJumpType trans_blr(DisasContext *ctx, uint32_t insn,
300098cd9ca7SRichard Henderson                                const DisasInsn *di)
300198cd9ca7SRichard Henderson {
300298cd9ca7SRichard Henderson     unsigned n = extract32(insn, 1, 1);
300398cd9ca7SRichard Henderson     unsigned rx = extract32(insn, 16, 5);
300498cd9ca7SRichard Henderson     unsigned link = extract32(insn, 21, 5);
300598cd9ca7SRichard Henderson     TCGv tmp = get_temp(ctx);
300698cd9ca7SRichard Henderson 
300798cd9ca7SRichard Henderson     tcg_gen_shli_tl(tmp, load_gpr(ctx, rx), 3);
300898cd9ca7SRichard Henderson     tcg_gen_addi_tl(tmp, tmp, ctx->iaoq_f + 8);
300998cd9ca7SRichard Henderson     return do_ibranch(ctx, tmp, link, n);
301098cd9ca7SRichard Henderson }
301198cd9ca7SRichard Henderson 
3012*869051eaSRichard Henderson static DisasJumpType trans_bv(DisasContext *ctx, uint32_t insn,
301398cd9ca7SRichard Henderson                               const DisasInsn *di)
301498cd9ca7SRichard Henderson {
301598cd9ca7SRichard Henderson     unsigned n = extract32(insn, 1, 1);
301698cd9ca7SRichard Henderson     unsigned rx = extract32(insn, 16, 5);
301798cd9ca7SRichard Henderson     unsigned rb = extract32(insn, 21, 5);
301898cd9ca7SRichard Henderson     TCGv dest;
301998cd9ca7SRichard Henderson 
302098cd9ca7SRichard Henderson     if (rx == 0) {
302198cd9ca7SRichard Henderson         dest = load_gpr(ctx, rb);
302298cd9ca7SRichard Henderson     } else {
302398cd9ca7SRichard Henderson         dest = get_temp(ctx);
302498cd9ca7SRichard Henderson         tcg_gen_shli_tl(dest, load_gpr(ctx, rx), 3);
302598cd9ca7SRichard Henderson         tcg_gen_add_tl(dest, dest, load_gpr(ctx, rb));
302698cd9ca7SRichard Henderson     }
302798cd9ca7SRichard Henderson     return do_ibranch(ctx, dest, 0, n);
302898cd9ca7SRichard Henderson }
302998cd9ca7SRichard Henderson 
3030*869051eaSRichard Henderson static DisasJumpType trans_bve(DisasContext *ctx, uint32_t insn,
303198cd9ca7SRichard Henderson                                const DisasInsn *di)
303298cd9ca7SRichard Henderson {
303398cd9ca7SRichard Henderson     unsigned n = extract32(insn, 1, 1);
303498cd9ca7SRichard Henderson     unsigned rb = extract32(insn, 21, 5);
303598cd9ca7SRichard Henderson     unsigned link = extract32(insn, 13, 1) ? 2 : 0;
303698cd9ca7SRichard Henderson 
303798cd9ca7SRichard Henderson     return do_ibranch(ctx, load_gpr(ctx, rb), link, n);
303898cd9ca7SRichard Henderson }
303998cd9ca7SRichard Henderson 
304098cd9ca7SRichard Henderson static const DisasInsn table_branch[] = {
304198cd9ca7SRichard Henderson     { 0xe8000000u, 0xfc006000u, trans_bl }, /* B,L and B,L,PUSH */
304298cd9ca7SRichard Henderson     { 0xe800a000u, 0xfc00e000u, trans_bl_long },
304398cd9ca7SRichard Henderson     { 0xe8004000u, 0xfc00fffdu, trans_blr },
304498cd9ca7SRichard Henderson     { 0xe800c000u, 0xfc00fffdu, trans_bv },
304598cd9ca7SRichard Henderson     { 0xe800d000u, 0xfc00dffcu, trans_bve },
304698cd9ca7SRichard Henderson };
304798cd9ca7SRichard Henderson 
3048*869051eaSRichard Henderson static DisasJumpType trans_fop_wew_0c(DisasContext *ctx, uint32_t insn,
3049ebe9383cSRichard Henderson                                       const DisasInsn *di)
3050ebe9383cSRichard Henderson {
3051ebe9383cSRichard Henderson     unsigned rt = extract32(insn, 0, 5);
3052ebe9383cSRichard Henderson     unsigned ra = extract32(insn, 21, 5);
3053eff235ebSPaolo Bonzini     return do_fop_wew(ctx, rt, ra, di->f.wew);
3054ebe9383cSRichard Henderson }
3055ebe9383cSRichard Henderson 
3056*869051eaSRichard Henderson static DisasJumpType trans_fop_wew_0e(DisasContext *ctx, uint32_t insn,
3057ebe9383cSRichard Henderson                                       const DisasInsn *di)
3058ebe9383cSRichard Henderson {
3059ebe9383cSRichard Henderson     unsigned rt = assemble_rt64(insn);
3060ebe9383cSRichard Henderson     unsigned ra = assemble_ra64(insn);
3061eff235ebSPaolo Bonzini     return do_fop_wew(ctx, rt, ra, di->f.wew);
3062ebe9383cSRichard Henderson }
3063ebe9383cSRichard Henderson 
3064*869051eaSRichard Henderson static DisasJumpType trans_fop_ded(DisasContext *ctx, uint32_t insn,
3065ebe9383cSRichard Henderson                                    const DisasInsn *di)
3066ebe9383cSRichard Henderson {
3067ebe9383cSRichard Henderson     unsigned rt = extract32(insn, 0, 5);
3068ebe9383cSRichard Henderson     unsigned ra = extract32(insn, 21, 5);
3069eff235ebSPaolo Bonzini     return do_fop_ded(ctx, rt, ra, di->f.ded);
3070ebe9383cSRichard Henderson }
3071ebe9383cSRichard Henderson 
3072*869051eaSRichard Henderson static DisasJumpType trans_fop_wed_0c(DisasContext *ctx, uint32_t insn,
3073ebe9383cSRichard Henderson                                       const DisasInsn *di)
3074ebe9383cSRichard Henderson {
3075ebe9383cSRichard Henderson     unsigned rt = extract32(insn, 0, 5);
3076ebe9383cSRichard Henderson     unsigned ra = extract32(insn, 21, 5);
3077eff235ebSPaolo Bonzini     return do_fop_wed(ctx, rt, ra, di->f.wed);
3078ebe9383cSRichard Henderson }
3079ebe9383cSRichard Henderson 
3080*869051eaSRichard Henderson static DisasJumpType trans_fop_wed_0e(DisasContext *ctx, uint32_t insn,
3081ebe9383cSRichard Henderson                                       const DisasInsn *di)
3082ebe9383cSRichard Henderson {
3083ebe9383cSRichard Henderson     unsigned rt = assemble_rt64(insn);
3084ebe9383cSRichard Henderson     unsigned ra = extract32(insn, 21, 5);
3085eff235ebSPaolo Bonzini     return do_fop_wed(ctx, rt, ra, di->f.wed);
3086ebe9383cSRichard Henderson }
3087ebe9383cSRichard Henderson 
3088*869051eaSRichard Henderson static DisasJumpType trans_fop_dew_0c(DisasContext *ctx, uint32_t insn,
3089ebe9383cSRichard Henderson                                       const DisasInsn *di)
3090ebe9383cSRichard Henderson {
3091ebe9383cSRichard Henderson     unsigned rt = extract32(insn, 0, 5);
3092ebe9383cSRichard Henderson     unsigned ra = extract32(insn, 21, 5);
3093eff235ebSPaolo Bonzini     return do_fop_dew(ctx, rt, ra, di->f.dew);
3094ebe9383cSRichard Henderson }
3095ebe9383cSRichard Henderson 
3096*869051eaSRichard Henderson static DisasJumpType trans_fop_dew_0e(DisasContext *ctx, uint32_t insn,
3097ebe9383cSRichard Henderson                                       const DisasInsn *di)
3098ebe9383cSRichard Henderson {
3099ebe9383cSRichard Henderson     unsigned rt = extract32(insn, 0, 5);
3100ebe9383cSRichard Henderson     unsigned ra = assemble_ra64(insn);
3101eff235ebSPaolo Bonzini     return do_fop_dew(ctx, rt, ra, di->f.dew);
3102ebe9383cSRichard Henderson }
3103ebe9383cSRichard Henderson 
3104*869051eaSRichard Henderson static DisasJumpType trans_fop_weww_0c(DisasContext *ctx, uint32_t insn,
3105ebe9383cSRichard Henderson                                        const DisasInsn *di)
3106ebe9383cSRichard Henderson {
3107ebe9383cSRichard Henderson     unsigned rt = extract32(insn, 0, 5);
3108ebe9383cSRichard Henderson     unsigned rb = extract32(insn, 16, 5);
3109ebe9383cSRichard Henderson     unsigned ra = extract32(insn, 21, 5);
3110eff235ebSPaolo Bonzini     return do_fop_weww(ctx, rt, ra, rb, di->f.weww);
3111ebe9383cSRichard Henderson }
3112ebe9383cSRichard Henderson 
3113*869051eaSRichard Henderson static DisasJumpType trans_fop_weww_0e(DisasContext *ctx, uint32_t insn,
3114ebe9383cSRichard Henderson                                        const DisasInsn *di)
3115ebe9383cSRichard Henderson {
3116ebe9383cSRichard Henderson     unsigned rt = assemble_rt64(insn);
3117ebe9383cSRichard Henderson     unsigned rb = assemble_rb64(insn);
3118ebe9383cSRichard Henderson     unsigned ra = assemble_ra64(insn);
3119eff235ebSPaolo Bonzini     return do_fop_weww(ctx, rt, ra, rb, di->f.weww);
3120ebe9383cSRichard Henderson }
3121ebe9383cSRichard Henderson 
3122*869051eaSRichard Henderson static DisasJumpType trans_fop_dedd(DisasContext *ctx, uint32_t insn,
3123ebe9383cSRichard Henderson                                     const DisasInsn *di)
3124ebe9383cSRichard Henderson {
3125ebe9383cSRichard Henderson     unsigned rt = extract32(insn, 0, 5);
3126ebe9383cSRichard Henderson     unsigned rb = extract32(insn, 16, 5);
3127ebe9383cSRichard Henderson     unsigned ra = extract32(insn, 21, 5);
3128eff235ebSPaolo Bonzini     return do_fop_dedd(ctx, rt, ra, rb, di->f.dedd);
3129ebe9383cSRichard Henderson }
3130ebe9383cSRichard Henderson 
3131ebe9383cSRichard Henderson static void gen_fcpy_s(TCGv_i32 dst, TCGv_env unused, TCGv_i32 src)
3132ebe9383cSRichard Henderson {
3133ebe9383cSRichard Henderson     tcg_gen_mov_i32(dst, src);
3134ebe9383cSRichard Henderson }
3135ebe9383cSRichard Henderson 
3136ebe9383cSRichard Henderson static void gen_fcpy_d(TCGv_i64 dst, TCGv_env unused, TCGv_i64 src)
3137ebe9383cSRichard Henderson {
3138ebe9383cSRichard Henderson     tcg_gen_mov_i64(dst, src);
3139ebe9383cSRichard Henderson }
3140ebe9383cSRichard Henderson 
3141ebe9383cSRichard Henderson static void gen_fabs_s(TCGv_i32 dst, TCGv_env unused, TCGv_i32 src)
3142ebe9383cSRichard Henderson {
3143ebe9383cSRichard Henderson     tcg_gen_andi_i32(dst, src, INT32_MAX);
3144ebe9383cSRichard Henderson }
3145ebe9383cSRichard Henderson 
3146ebe9383cSRichard Henderson static void gen_fabs_d(TCGv_i64 dst, TCGv_env unused, TCGv_i64 src)
3147ebe9383cSRichard Henderson {
3148ebe9383cSRichard Henderson     tcg_gen_andi_i64(dst, src, INT64_MAX);
3149ebe9383cSRichard Henderson }
3150ebe9383cSRichard Henderson 
3151ebe9383cSRichard Henderson static void gen_fneg_s(TCGv_i32 dst, TCGv_env unused, TCGv_i32 src)
3152ebe9383cSRichard Henderson {
3153ebe9383cSRichard Henderson     tcg_gen_xori_i32(dst, src, INT32_MIN);
3154ebe9383cSRichard Henderson }
3155ebe9383cSRichard Henderson 
3156ebe9383cSRichard Henderson static void gen_fneg_d(TCGv_i64 dst, TCGv_env unused, TCGv_i64 src)
3157ebe9383cSRichard Henderson {
3158ebe9383cSRichard Henderson     tcg_gen_xori_i64(dst, src, INT64_MIN);
3159ebe9383cSRichard Henderson }
3160ebe9383cSRichard Henderson 
3161ebe9383cSRichard Henderson static void gen_fnegabs_s(TCGv_i32 dst, TCGv_env unused, TCGv_i32 src)
3162ebe9383cSRichard Henderson {
3163ebe9383cSRichard Henderson     tcg_gen_ori_i32(dst, src, INT32_MIN);
3164ebe9383cSRichard Henderson }
3165ebe9383cSRichard Henderson 
3166ebe9383cSRichard Henderson static void gen_fnegabs_d(TCGv_i64 dst, TCGv_env unused, TCGv_i64 src)
3167ebe9383cSRichard Henderson {
3168ebe9383cSRichard Henderson     tcg_gen_ori_i64(dst, src, INT64_MIN);
3169ebe9383cSRichard Henderson }
3170ebe9383cSRichard Henderson 
3171*869051eaSRichard Henderson static DisasJumpType do_fcmp_s(DisasContext *ctx, unsigned ra, unsigned rb,
3172ebe9383cSRichard Henderson                                unsigned y, unsigned c)
3173ebe9383cSRichard Henderson {
3174ebe9383cSRichard Henderson     TCGv_i32 ta, tb, tc, ty;
3175ebe9383cSRichard Henderson 
3176ebe9383cSRichard Henderson     nullify_over(ctx);
3177ebe9383cSRichard Henderson 
3178ebe9383cSRichard Henderson     ta = load_frw0_i32(ra);
3179ebe9383cSRichard Henderson     tb = load_frw0_i32(rb);
3180ebe9383cSRichard Henderson     ty = tcg_const_i32(y);
3181ebe9383cSRichard Henderson     tc = tcg_const_i32(c);
3182ebe9383cSRichard Henderson 
3183ebe9383cSRichard Henderson     gen_helper_fcmp_s(cpu_env, ta, tb, ty, tc);
3184ebe9383cSRichard Henderson 
3185ebe9383cSRichard Henderson     tcg_temp_free_i32(ta);
3186ebe9383cSRichard Henderson     tcg_temp_free_i32(tb);
3187ebe9383cSRichard Henderson     tcg_temp_free_i32(ty);
3188ebe9383cSRichard Henderson     tcg_temp_free_i32(tc);
3189ebe9383cSRichard Henderson 
3190*869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
3191ebe9383cSRichard Henderson }
3192ebe9383cSRichard Henderson 
3193*869051eaSRichard Henderson static DisasJumpType trans_fcmp_s_0c(DisasContext *ctx, uint32_t insn,
3194ebe9383cSRichard Henderson                                      const DisasInsn *di)
3195ebe9383cSRichard Henderson {
3196ebe9383cSRichard Henderson     unsigned c = extract32(insn, 0, 5);
3197ebe9383cSRichard Henderson     unsigned y = extract32(insn, 13, 3);
3198ebe9383cSRichard Henderson     unsigned rb = extract32(insn, 16, 5);
3199ebe9383cSRichard Henderson     unsigned ra = extract32(insn, 21, 5);
3200ebe9383cSRichard Henderson     return do_fcmp_s(ctx, ra, rb, y, c);
3201ebe9383cSRichard Henderson }
3202ebe9383cSRichard Henderson 
3203*869051eaSRichard Henderson static DisasJumpType trans_fcmp_s_0e(DisasContext *ctx, uint32_t insn,
3204ebe9383cSRichard Henderson                                      const DisasInsn *di)
3205ebe9383cSRichard Henderson {
3206ebe9383cSRichard Henderson     unsigned c = extract32(insn, 0, 5);
3207ebe9383cSRichard Henderson     unsigned y = extract32(insn, 13, 3);
3208ebe9383cSRichard Henderson     unsigned rb = assemble_rb64(insn);
3209ebe9383cSRichard Henderson     unsigned ra = assemble_ra64(insn);
3210ebe9383cSRichard Henderson     return do_fcmp_s(ctx, ra, rb, y, c);
3211ebe9383cSRichard Henderson }
3212ebe9383cSRichard Henderson 
3213*869051eaSRichard Henderson static DisasJumpType trans_fcmp_d(DisasContext *ctx, uint32_t insn,
3214ebe9383cSRichard Henderson                                   const DisasInsn *di)
3215ebe9383cSRichard Henderson {
3216ebe9383cSRichard Henderson     unsigned c = extract32(insn, 0, 5);
3217ebe9383cSRichard Henderson     unsigned y = extract32(insn, 13, 3);
3218ebe9383cSRichard Henderson     unsigned rb = extract32(insn, 16, 5);
3219ebe9383cSRichard Henderson     unsigned ra = extract32(insn, 21, 5);
3220ebe9383cSRichard Henderson     TCGv_i64 ta, tb;
3221ebe9383cSRichard Henderson     TCGv_i32 tc, ty;
3222ebe9383cSRichard Henderson 
3223ebe9383cSRichard Henderson     nullify_over(ctx);
3224ebe9383cSRichard Henderson 
3225ebe9383cSRichard Henderson     ta = load_frd0(ra);
3226ebe9383cSRichard Henderson     tb = load_frd0(rb);
3227ebe9383cSRichard Henderson     ty = tcg_const_i32(y);
3228ebe9383cSRichard Henderson     tc = tcg_const_i32(c);
3229ebe9383cSRichard Henderson 
3230ebe9383cSRichard Henderson     gen_helper_fcmp_d(cpu_env, ta, tb, ty, tc);
3231ebe9383cSRichard Henderson 
3232ebe9383cSRichard Henderson     tcg_temp_free_i64(ta);
3233ebe9383cSRichard Henderson     tcg_temp_free_i64(tb);
3234ebe9383cSRichard Henderson     tcg_temp_free_i32(ty);
3235ebe9383cSRichard Henderson     tcg_temp_free_i32(tc);
3236ebe9383cSRichard Henderson 
3237*869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
3238ebe9383cSRichard Henderson }
3239ebe9383cSRichard Henderson 
3240*869051eaSRichard Henderson static DisasJumpType trans_ftest_t(DisasContext *ctx, uint32_t insn,
3241ebe9383cSRichard Henderson                                    const DisasInsn *di)
3242ebe9383cSRichard Henderson {
3243ebe9383cSRichard Henderson     unsigned y = extract32(insn, 13, 3);
3244ebe9383cSRichard Henderson     unsigned cbit = (y ^ 1) - 1;
3245ebe9383cSRichard Henderson     TCGv t;
3246ebe9383cSRichard Henderson 
3247ebe9383cSRichard Henderson     nullify_over(ctx);
3248ebe9383cSRichard Henderson 
3249ebe9383cSRichard Henderson     t = tcg_temp_new();
3250ebe9383cSRichard Henderson     tcg_gen_ld32u_tl(t, cpu_env, offsetof(CPUHPPAState, fr0_shadow));
3251ebe9383cSRichard Henderson     tcg_gen_extract_tl(t, t, 21 - cbit, 1);
3252ebe9383cSRichard Henderson     ctx->null_cond = cond_make_0(TCG_COND_NE, t);
3253ebe9383cSRichard Henderson     tcg_temp_free(t);
3254ebe9383cSRichard Henderson 
3255*869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
3256ebe9383cSRichard Henderson }
3257ebe9383cSRichard Henderson 
3258*869051eaSRichard Henderson static DisasJumpType trans_ftest_q(DisasContext *ctx, uint32_t insn,
3259ebe9383cSRichard Henderson                                    const DisasInsn *di)
3260ebe9383cSRichard Henderson {
3261ebe9383cSRichard Henderson     unsigned c = extract32(insn, 0, 5);
3262ebe9383cSRichard Henderson     int mask;
3263ebe9383cSRichard Henderson     bool inv = false;
3264ebe9383cSRichard Henderson     TCGv t;
3265ebe9383cSRichard Henderson 
3266ebe9383cSRichard Henderson     nullify_over(ctx);
3267ebe9383cSRichard Henderson 
3268ebe9383cSRichard Henderson     t = tcg_temp_new();
3269ebe9383cSRichard Henderson     tcg_gen_ld32u_tl(t, cpu_env, offsetof(CPUHPPAState, fr0_shadow));
3270ebe9383cSRichard Henderson 
3271ebe9383cSRichard Henderson     switch (c) {
3272ebe9383cSRichard Henderson     case 0: /* simple */
3273ebe9383cSRichard Henderson         tcg_gen_andi_tl(t, t, 0x4000000);
3274ebe9383cSRichard Henderson         ctx->null_cond = cond_make_0(TCG_COND_NE, t);
3275ebe9383cSRichard Henderson         goto done;
3276ebe9383cSRichard Henderson     case 2: /* rej */
3277ebe9383cSRichard Henderson         inv = true;
3278ebe9383cSRichard Henderson         /* fallthru */
3279ebe9383cSRichard Henderson     case 1: /* acc */
3280ebe9383cSRichard Henderson         mask = 0x43ff800;
3281ebe9383cSRichard Henderson         break;
3282ebe9383cSRichard Henderson     case 6: /* rej8 */
3283ebe9383cSRichard Henderson         inv = true;
3284ebe9383cSRichard Henderson         /* fallthru */
3285ebe9383cSRichard Henderson     case 5: /* acc8 */
3286ebe9383cSRichard Henderson         mask = 0x43f8000;
3287ebe9383cSRichard Henderson         break;
3288ebe9383cSRichard Henderson     case 9: /* acc6 */
3289ebe9383cSRichard Henderson         mask = 0x43e0000;
3290ebe9383cSRichard Henderson         break;
3291ebe9383cSRichard Henderson     case 13: /* acc4 */
3292ebe9383cSRichard Henderson         mask = 0x4380000;
3293ebe9383cSRichard Henderson         break;
3294ebe9383cSRichard Henderson     case 17: /* acc2 */
3295ebe9383cSRichard Henderson         mask = 0x4200000;
3296ebe9383cSRichard Henderson         break;
3297ebe9383cSRichard Henderson     default:
3298ebe9383cSRichard Henderson         return gen_illegal(ctx);
3299ebe9383cSRichard Henderson     }
3300ebe9383cSRichard Henderson     if (inv) {
3301ebe9383cSRichard Henderson         TCGv c = load_const(ctx, mask);
3302ebe9383cSRichard Henderson         tcg_gen_or_tl(t, t, c);
3303ebe9383cSRichard Henderson         ctx->null_cond = cond_make(TCG_COND_EQ, t, c);
3304ebe9383cSRichard Henderson     } else {
3305ebe9383cSRichard Henderson         tcg_gen_andi_tl(t, t, mask);
3306ebe9383cSRichard Henderson         ctx->null_cond = cond_make_0(TCG_COND_EQ, t);
3307ebe9383cSRichard Henderson     }
3308ebe9383cSRichard Henderson  done:
3309*869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
3310ebe9383cSRichard Henderson }
3311ebe9383cSRichard Henderson 
3312*869051eaSRichard Henderson static DisasJumpType trans_xmpyu(DisasContext *ctx, uint32_t insn,
3313ebe9383cSRichard Henderson                                  const DisasInsn *di)
3314ebe9383cSRichard Henderson {
3315ebe9383cSRichard Henderson     unsigned rt = extract32(insn, 0, 5);
3316ebe9383cSRichard Henderson     unsigned rb = assemble_rb64(insn);
3317ebe9383cSRichard Henderson     unsigned ra = assemble_ra64(insn);
3318ebe9383cSRichard Henderson     TCGv_i64 a, b;
3319ebe9383cSRichard Henderson 
3320ebe9383cSRichard Henderson     nullify_over(ctx);
3321ebe9383cSRichard Henderson 
3322ebe9383cSRichard Henderson     a = load_frw0_i64(ra);
3323ebe9383cSRichard Henderson     b = load_frw0_i64(rb);
3324ebe9383cSRichard Henderson     tcg_gen_mul_i64(a, a, b);
3325ebe9383cSRichard Henderson     save_frd(rt, a);
3326ebe9383cSRichard Henderson     tcg_temp_free_i64(a);
3327ebe9383cSRichard Henderson     tcg_temp_free_i64(b);
3328ebe9383cSRichard Henderson 
3329*869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
3330ebe9383cSRichard Henderson }
3331ebe9383cSRichard Henderson 
3332eff235ebSPaolo Bonzini #define FOP_DED  trans_fop_ded, .f.ded
3333eff235ebSPaolo Bonzini #define FOP_DEDD trans_fop_dedd, .f.dedd
3334ebe9383cSRichard Henderson 
3335eff235ebSPaolo Bonzini #define FOP_WEW  trans_fop_wew_0c, .f.wew
3336eff235ebSPaolo Bonzini #define FOP_DEW  trans_fop_dew_0c, .f.dew
3337eff235ebSPaolo Bonzini #define FOP_WED  trans_fop_wed_0c, .f.wed
3338eff235ebSPaolo Bonzini #define FOP_WEWW trans_fop_weww_0c, .f.weww
3339ebe9383cSRichard Henderson 
3340ebe9383cSRichard Henderson static const DisasInsn table_float_0c[] = {
3341ebe9383cSRichard Henderson     /* floating point class zero */
3342ebe9383cSRichard Henderson     { 0x30004000, 0xfc1fffe0, FOP_WEW = gen_fcpy_s },
3343ebe9383cSRichard Henderson     { 0x30006000, 0xfc1fffe0, FOP_WEW = gen_fabs_s },
3344ebe9383cSRichard Henderson     { 0x30008000, 0xfc1fffe0, FOP_WEW = gen_helper_fsqrt_s },
3345ebe9383cSRichard Henderson     { 0x3000a000, 0xfc1fffe0, FOP_WEW = gen_helper_frnd_s },
3346ebe9383cSRichard Henderson     { 0x3000c000, 0xfc1fffe0, FOP_WEW = gen_fneg_s },
3347ebe9383cSRichard Henderson     { 0x3000e000, 0xfc1fffe0, FOP_WEW = gen_fnegabs_s },
3348ebe9383cSRichard Henderson 
3349ebe9383cSRichard Henderson     { 0x30004800, 0xfc1fffe0, FOP_DED = gen_fcpy_d },
3350ebe9383cSRichard Henderson     { 0x30006800, 0xfc1fffe0, FOP_DED = gen_fabs_d },
3351ebe9383cSRichard Henderson     { 0x30008800, 0xfc1fffe0, FOP_DED = gen_helper_fsqrt_d },
3352ebe9383cSRichard Henderson     { 0x3000a800, 0xfc1fffe0, FOP_DED = gen_helper_frnd_d },
3353ebe9383cSRichard Henderson     { 0x3000c800, 0xfc1fffe0, FOP_DED = gen_fneg_d },
3354ebe9383cSRichard Henderson     { 0x3000e800, 0xfc1fffe0, FOP_DED = gen_fnegabs_d },
3355ebe9383cSRichard Henderson 
3356ebe9383cSRichard Henderson     /* floating point class three */
3357ebe9383cSRichard Henderson     { 0x30000600, 0xfc00ffe0, FOP_WEWW = gen_helper_fadd_s },
3358ebe9383cSRichard Henderson     { 0x30002600, 0xfc00ffe0, FOP_WEWW = gen_helper_fsub_s },
3359ebe9383cSRichard Henderson     { 0x30004600, 0xfc00ffe0, FOP_WEWW = gen_helper_fmpy_s },
3360ebe9383cSRichard Henderson     { 0x30006600, 0xfc00ffe0, FOP_WEWW = gen_helper_fdiv_s },
3361ebe9383cSRichard Henderson 
3362ebe9383cSRichard Henderson     { 0x30000e00, 0xfc00ffe0, FOP_DEDD = gen_helper_fadd_d },
3363ebe9383cSRichard Henderson     { 0x30002e00, 0xfc00ffe0, FOP_DEDD = gen_helper_fsub_d },
3364ebe9383cSRichard Henderson     { 0x30004e00, 0xfc00ffe0, FOP_DEDD = gen_helper_fmpy_d },
3365ebe9383cSRichard Henderson     { 0x30006e00, 0xfc00ffe0, FOP_DEDD = gen_helper_fdiv_d },
3366ebe9383cSRichard Henderson 
3367ebe9383cSRichard Henderson     /* floating point class one */
3368ebe9383cSRichard Henderson     /* float/float */
3369ebe9383cSRichard Henderson     { 0x30000a00, 0xfc1fffe0, FOP_WED = gen_helper_fcnv_d_s },
3370ebe9383cSRichard Henderson     { 0x30002200, 0xfc1fffe0, FOP_DEW = gen_helper_fcnv_s_d },
3371ebe9383cSRichard Henderson     /* int/float */
3372ebe9383cSRichard Henderson     { 0x30008200, 0xfc1fffe0, FOP_WEW = gen_helper_fcnv_w_s },
3373ebe9383cSRichard Henderson     { 0x30008a00, 0xfc1fffe0, FOP_WED = gen_helper_fcnv_dw_s },
3374ebe9383cSRichard Henderson     { 0x3000a200, 0xfc1fffe0, FOP_DEW = gen_helper_fcnv_w_d },
3375ebe9383cSRichard Henderson     { 0x3000aa00, 0xfc1fffe0, FOP_DED = gen_helper_fcnv_dw_d },
3376ebe9383cSRichard Henderson     /* float/int */
3377ebe9383cSRichard Henderson     { 0x30010200, 0xfc1fffe0, FOP_WEW = gen_helper_fcnv_s_w },
3378ebe9383cSRichard Henderson     { 0x30010a00, 0xfc1fffe0, FOP_WED = gen_helper_fcnv_d_w },
3379ebe9383cSRichard Henderson     { 0x30012200, 0xfc1fffe0, FOP_DEW = gen_helper_fcnv_s_dw },
3380ebe9383cSRichard Henderson     { 0x30012a00, 0xfc1fffe0, FOP_DED = gen_helper_fcnv_d_dw },
3381ebe9383cSRichard Henderson     /* float/int truncate */
3382ebe9383cSRichard Henderson     { 0x30018200, 0xfc1fffe0, FOP_WEW = gen_helper_fcnv_t_s_w },
3383ebe9383cSRichard Henderson     { 0x30018a00, 0xfc1fffe0, FOP_WED = gen_helper_fcnv_t_d_w },
3384ebe9383cSRichard Henderson     { 0x3001a200, 0xfc1fffe0, FOP_DEW = gen_helper_fcnv_t_s_dw },
3385ebe9383cSRichard Henderson     { 0x3001aa00, 0xfc1fffe0, FOP_DED = gen_helper_fcnv_t_d_dw },
3386ebe9383cSRichard Henderson     /* uint/float */
3387ebe9383cSRichard Henderson     { 0x30028200, 0xfc1fffe0, FOP_WEW = gen_helper_fcnv_uw_s },
3388ebe9383cSRichard Henderson     { 0x30028a00, 0xfc1fffe0, FOP_WED = gen_helper_fcnv_udw_s },
3389ebe9383cSRichard Henderson     { 0x3002a200, 0xfc1fffe0, FOP_DEW = gen_helper_fcnv_uw_d },
3390ebe9383cSRichard Henderson     { 0x3002aa00, 0xfc1fffe0, FOP_DED = gen_helper_fcnv_udw_d },
3391ebe9383cSRichard Henderson     /* float/uint */
3392ebe9383cSRichard Henderson     { 0x30030200, 0xfc1fffe0, FOP_WEW = gen_helper_fcnv_s_uw },
3393ebe9383cSRichard Henderson     { 0x30030a00, 0xfc1fffe0, FOP_WED = gen_helper_fcnv_d_uw },
3394ebe9383cSRichard Henderson     { 0x30032200, 0xfc1fffe0, FOP_DEW = gen_helper_fcnv_s_udw },
3395ebe9383cSRichard Henderson     { 0x30032a00, 0xfc1fffe0, FOP_DED = gen_helper_fcnv_d_udw },
3396ebe9383cSRichard Henderson     /* float/uint truncate */
3397ebe9383cSRichard Henderson     { 0x30038200, 0xfc1fffe0, FOP_WEW = gen_helper_fcnv_t_s_uw },
3398ebe9383cSRichard Henderson     { 0x30038a00, 0xfc1fffe0, FOP_WED = gen_helper_fcnv_t_d_uw },
3399ebe9383cSRichard Henderson     { 0x3003a200, 0xfc1fffe0, FOP_DEW = gen_helper_fcnv_t_s_udw },
3400ebe9383cSRichard Henderson     { 0x3003aa00, 0xfc1fffe0, FOP_DED = gen_helper_fcnv_t_d_udw },
3401ebe9383cSRichard Henderson 
3402ebe9383cSRichard Henderson     /* floating point class two */
3403ebe9383cSRichard Henderson     { 0x30000400, 0xfc001fe0, trans_fcmp_s_0c },
3404ebe9383cSRichard Henderson     { 0x30000c00, 0xfc001fe0, trans_fcmp_d },
3405ebe9383cSRichard Henderson     { 0x30002420, 0xffffffe0, trans_ftest_q },
3406ebe9383cSRichard Henderson     { 0x30000420, 0xffff1fff, trans_ftest_t },
3407ebe9383cSRichard Henderson 
3408ebe9383cSRichard Henderson     /* FID.  Note that ra == rt == 0, which via fcpy puts 0 into fr0.
3409ebe9383cSRichard Henderson        This is machine/revision == 0, which is reserved for simulator.  */
3410ebe9383cSRichard Henderson     { 0x30000000, 0xffffffff, FOP_WEW = gen_fcpy_s },
3411ebe9383cSRichard Henderson };
3412ebe9383cSRichard Henderson 
3413ebe9383cSRichard Henderson #undef FOP_WEW
3414ebe9383cSRichard Henderson #undef FOP_DEW
3415ebe9383cSRichard Henderson #undef FOP_WED
3416ebe9383cSRichard Henderson #undef FOP_WEWW
3417eff235ebSPaolo Bonzini #define FOP_WEW  trans_fop_wew_0e, .f.wew
3418eff235ebSPaolo Bonzini #define FOP_DEW  trans_fop_dew_0e, .f.dew
3419eff235ebSPaolo Bonzini #define FOP_WED  trans_fop_wed_0e, .f.wed
3420eff235ebSPaolo Bonzini #define FOP_WEWW trans_fop_weww_0e, .f.weww
3421ebe9383cSRichard Henderson 
3422ebe9383cSRichard Henderson static const DisasInsn table_float_0e[] = {
3423ebe9383cSRichard Henderson     /* floating point class zero */
3424ebe9383cSRichard Henderson     { 0x38004000, 0xfc1fff20, FOP_WEW = gen_fcpy_s },
3425ebe9383cSRichard Henderson     { 0x38006000, 0xfc1fff20, FOP_WEW = gen_fabs_s },
3426ebe9383cSRichard Henderson     { 0x38008000, 0xfc1fff20, FOP_WEW = gen_helper_fsqrt_s },
3427ebe9383cSRichard Henderson     { 0x3800a000, 0xfc1fff20, FOP_WEW = gen_helper_frnd_s },
3428ebe9383cSRichard Henderson     { 0x3800c000, 0xfc1fff20, FOP_WEW = gen_fneg_s },
3429ebe9383cSRichard Henderson     { 0x3800e000, 0xfc1fff20, FOP_WEW = gen_fnegabs_s },
3430ebe9383cSRichard Henderson 
3431ebe9383cSRichard Henderson     { 0x38004800, 0xfc1fffe0, FOP_DED = gen_fcpy_d },
3432ebe9383cSRichard Henderson     { 0x38006800, 0xfc1fffe0, FOP_DED = gen_fabs_d },
3433ebe9383cSRichard Henderson     { 0x38008800, 0xfc1fffe0, FOP_DED = gen_helper_fsqrt_d },
3434ebe9383cSRichard Henderson     { 0x3800a800, 0xfc1fffe0, FOP_DED = gen_helper_frnd_d },
3435ebe9383cSRichard Henderson     { 0x3800c800, 0xfc1fffe0, FOP_DED = gen_fneg_d },
3436ebe9383cSRichard Henderson     { 0x3800e800, 0xfc1fffe0, FOP_DED = gen_fnegabs_d },
3437ebe9383cSRichard Henderson 
3438ebe9383cSRichard Henderson     /* floating point class three */
3439ebe9383cSRichard Henderson     { 0x38000600, 0xfc00ef20, FOP_WEWW = gen_helper_fadd_s },
3440ebe9383cSRichard Henderson     { 0x38002600, 0xfc00ef20, FOP_WEWW = gen_helper_fsub_s },
3441ebe9383cSRichard Henderson     { 0x38004600, 0xfc00ef20, FOP_WEWW = gen_helper_fmpy_s },
3442ebe9383cSRichard Henderson     { 0x38006600, 0xfc00ef20, FOP_WEWW = gen_helper_fdiv_s },
3443ebe9383cSRichard Henderson 
3444ebe9383cSRichard Henderson     { 0x38000e00, 0xfc00ffe0, FOP_DEDD = gen_helper_fadd_d },
3445ebe9383cSRichard Henderson     { 0x38002e00, 0xfc00ffe0, FOP_DEDD = gen_helper_fsub_d },
3446ebe9383cSRichard Henderson     { 0x38004e00, 0xfc00ffe0, FOP_DEDD = gen_helper_fmpy_d },
3447ebe9383cSRichard Henderson     { 0x38006e00, 0xfc00ffe0, FOP_DEDD = gen_helper_fdiv_d },
3448ebe9383cSRichard Henderson 
3449ebe9383cSRichard Henderson     { 0x38004700, 0xfc00ef60, trans_xmpyu },
3450ebe9383cSRichard Henderson 
3451ebe9383cSRichard Henderson     /* floating point class one */
3452ebe9383cSRichard Henderson     /* float/float */
3453ebe9383cSRichard Henderson     { 0x38000a00, 0xfc1fffa0, FOP_WED = gen_helper_fcnv_d_s },
3454ebe9383cSRichard Henderson     { 0x38002200, 0xfc1fffc0, FOP_DEW = gen_helper_fcnv_s_d },
3455ebe9383cSRichard Henderson     /* int/float */
3456ebe9383cSRichard Henderson     { 0x38008200, 0xfc1ffe60, FOP_WEW = gen_helper_fcnv_w_s },
3457ebe9383cSRichard Henderson     { 0x38008a00, 0xfc1fffa0, FOP_WED = gen_helper_fcnv_dw_s },
3458ebe9383cSRichard Henderson     { 0x3800a200, 0xfc1fff60, FOP_DEW = gen_helper_fcnv_w_d },
3459ebe9383cSRichard Henderson     { 0x3800aa00, 0xfc1fffe0, FOP_DED = gen_helper_fcnv_dw_d },
3460ebe9383cSRichard Henderson     /* float/int */
3461ebe9383cSRichard Henderson     { 0x38010200, 0xfc1ffe60, FOP_WEW = gen_helper_fcnv_s_w },
3462ebe9383cSRichard Henderson     { 0x38010a00, 0xfc1fffa0, FOP_WED = gen_helper_fcnv_d_w },
3463ebe9383cSRichard Henderson     { 0x38012200, 0xfc1fff60, FOP_DEW = gen_helper_fcnv_s_dw },
3464ebe9383cSRichard Henderson     { 0x38012a00, 0xfc1fffe0, FOP_DED = gen_helper_fcnv_d_dw },
3465ebe9383cSRichard Henderson     /* float/int truncate */
3466ebe9383cSRichard Henderson     { 0x38018200, 0xfc1ffe60, FOP_WEW = gen_helper_fcnv_t_s_w },
3467ebe9383cSRichard Henderson     { 0x38018a00, 0xfc1fffa0, FOP_WED = gen_helper_fcnv_t_d_w },
3468ebe9383cSRichard Henderson     { 0x3801a200, 0xfc1fff60, FOP_DEW = gen_helper_fcnv_t_s_dw },
3469ebe9383cSRichard Henderson     { 0x3801aa00, 0xfc1fffe0, FOP_DED = gen_helper_fcnv_t_d_dw },
3470ebe9383cSRichard Henderson     /* uint/float */
3471ebe9383cSRichard Henderson     { 0x38028200, 0xfc1ffe60, FOP_WEW = gen_helper_fcnv_uw_s },
3472ebe9383cSRichard Henderson     { 0x38028a00, 0xfc1fffa0, FOP_WED = gen_helper_fcnv_udw_s },
3473ebe9383cSRichard Henderson     { 0x3802a200, 0xfc1fff60, FOP_DEW = gen_helper_fcnv_uw_d },
3474ebe9383cSRichard Henderson     { 0x3802aa00, 0xfc1fffe0, FOP_DED = gen_helper_fcnv_udw_d },
3475ebe9383cSRichard Henderson     /* float/uint */
3476ebe9383cSRichard Henderson     { 0x38030200, 0xfc1ffe60, FOP_WEW = gen_helper_fcnv_s_uw },
3477ebe9383cSRichard Henderson     { 0x38030a00, 0xfc1fffa0, FOP_WED = gen_helper_fcnv_d_uw },
3478ebe9383cSRichard Henderson     { 0x38032200, 0xfc1fff60, FOP_DEW = gen_helper_fcnv_s_udw },
3479ebe9383cSRichard Henderson     { 0x38032a00, 0xfc1fffe0, FOP_DED = gen_helper_fcnv_d_udw },
3480ebe9383cSRichard Henderson     /* float/uint truncate */
3481ebe9383cSRichard Henderson     { 0x38038200, 0xfc1ffe60, FOP_WEW = gen_helper_fcnv_t_s_uw },
3482ebe9383cSRichard Henderson     { 0x38038a00, 0xfc1fffa0, FOP_WED = gen_helper_fcnv_t_d_uw },
3483ebe9383cSRichard Henderson     { 0x3803a200, 0xfc1fff60, FOP_DEW = gen_helper_fcnv_t_s_udw },
3484ebe9383cSRichard Henderson     { 0x3803aa00, 0xfc1fffe0, FOP_DED = gen_helper_fcnv_t_d_udw },
3485ebe9383cSRichard Henderson 
3486ebe9383cSRichard Henderson     /* floating point class two */
3487ebe9383cSRichard Henderson     { 0x38000400, 0xfc000f60, trans_fcmp_s_0e },
3488ebe9383cSRichard Henderson     { 0x38000c00, 0xfc001fe0, trans_fcmp_d },
3489ebe9383cSRichard Henderson };
3490ebe9383cSRichard Henderson 
3491ebe9383cSRichard Henderson #undef FOP_WEW
3492ebe9383cSRichard Henderson #undef FOP_DEW
3493ebe9383cSRichard Henderson #undef FOP_WED
3494ebe9383cSRichard Henderson #undef FOP_WEWW
3495ebe9383cSRichard Henderson #undef FOP_DED
3496ebe9383cSRichard Henderson #undef FOP_DEDD
3497ebe9383cSRichard Henderson 
3498ebe9383cSRichard Henderson /* Convert the fmpyadd single-precision register encodings to standard.  */
3499ebe9383cSRichard Henderson static inline int fmpyadd_s_reg(unsigned r)
3500ebe9383cSRichard Henderson {
3501ebe9383cSRichard Henderson     return (r & 16) * 2 + 16 + (r & 15);
3502ebe9383cSRichard Henderson }
3503ebe9383cSRichard Henderson 
3504*869051eaSRichard Henderson static DisasJumpType trans_fmpyadd(DisasContext *ctx,
3505*869051eaSRichard Henderson                                    uint32_t insn, bool is_sub)
3506ebe9383cSRichard Henderson {
3507ebe9383cSRichard Henderson     unsigned tm = extract32(insn, 0, 5);
3508ebe9383cSRichard Henderson     unsigned f = extract32(insn, 5, 1);
3509ebe9383cSRichard Henderson     unsigned ra = extract32(insn, 6, 5);
3510ebe9383cSRichard Henderson     unsigned ta = extract32(insn, 11, 5);
3511ebe9383cSRichard Henderson     unsigned rm2 = extract32(insn, 16, 5);
3512ebe9383cSRichard Henderson     unsigned rm1 = extract32(insn, 21, 5);
3513ebe9383cSRichard Henderson 
3514ebe9383cSRichard Henderson     nullify_over(ctx);
3515ebe9383cSRichard Henderson 
3516ebe9383cSRichard Henderson     /* Independent multiply & add/sub, with undefined behaviour
3517ebe9383cSRichard Henderson        if outputs overlap inputs.  */
3518ebe9383cSRichard Henderson     if (f == 0) {
3519ebe9383cSRichard Henderson         tm = fmpyadd_s_reg(tm);
3520ebe9383cSRichard Henderson         ra = fmpyadd_s_reg(ra);
3521ebe9383cSRichard Henderson         ta = fmpyadd_s_reg(ta);
3522ebe9383cSRichard Henderson         rm2 = fmpyadd_s_reg(rm2);
3523ebe9383cSRichard Henderson         rm1 = fmpyadd_s_reg(rm1);
3524ebe9383cSRichard Henderson         do_fop_weww(ctx, tm, rm1, rm2, gen_helper_fmpy_s);
3525ebe9383cSRichard Henderson         do_fop_weww(ctx, ta, ta, ra,
3526ebe9383cSRichard Henderson                     is_sub ? gen_helper_fsub_s : gen_helper_fadd_s);
3527ebe9383cSRichard Henderson     } else {
3528ebe9383cSRichard Henderson         do_fop_dedd(ctx, tm, rm1, rm2, gen_helper_fmpy_d);
3529ebe9383cSRichard Henderson         do_fop_dedd(ctx, ta, ta, ra,
3530ebe9383cSRichard Henderson                     is_sub ? gen_helper_fsub_d : gen_helper_fadd_d);
3531ebe9383cSRichard Henderson     }
3532ebe9383cSRichard Henderson 
3533*869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
3534ebe9383cSRichard Henderson }
3535ebe9383cSRichard Henderson 
3536*869051eaSRichard Henderson static DisasJumpType trans_fmpyfadd_s(DisasContext *ctx, uint32_t insn,
3537ebe9383cSRichard Henderson                                       const DisasInsn *di)
3538ebe9383cSRichard Henderson {
3539ebe9383cSRichard Henderson     unsigned rt = assemble_rt64(insn);
3540ebe9383cSRichard Henderson     unsigned neg = extract32(insn, 5, 1);
3541ebe9383cSRichard Henderson     unsigned rm1 = assemble_ra64(insn);
3542ebe9383cSRichard Henderson     unsigned rm2 = assemble_rb64(insn);
3543ebe9383cSRichard Henderson     unsigned ra3 = assemble_rc64(insn);
3544ebe9383cSRichard Henderson     TCGv_i32 a, b, c;
3545ebe9383cSRichard Henderson 
3546ebe9383cSRichard Henderson     nullify_over(ctx);
3547ebe9383cSRichard Henderson     a = load_frw0_i32(rm1);
3548ebe9383cSRichard Henderson     b = load_frw0_i32(rm2);
3549ebe9383cSRichard Henderson     c = load_frw0_i32(ra3);
3550ebe9383cSRichard Henderson 
3551ebe9383cSRichard Henderson     if (neg) {
3552ebe9383cSRichard Henderson         gen_helper_fmpynfadd_s(a, cpu_env, a, b, c);
3553ebe9383cSRichard Henderson     } else {
3554ebe9383cSRichard Henderson         gen_helper_fmpyfadd_s(a, cpu_env, a, b, c);
3555ebe9383cSRichard Henderson     }
3556ebe9383cSRichard Henderson 
3557ebe9383cSRichard Henderson     tcg_temp_free_i32(b);
3558ebe9383cSRichard Henderson     tcg_temp_free_i32(c);
3559ebe9383cSRichard Henderson     save_frw_i32(rt, a);
3560ebe9383cSRichard Henderson     tcg_temp_free_i32(a);
3561*869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
3562ebe9383cSRichard Henderson }
3563ebe9383cSRichard Henderson 
3564*869051eaSRichard Henderson static DisasJumpType trans_fmpyfadd_d(DisasContext *ctx, uint32_t insn,
3565ebe9383cSRichard Henderson                                       const DisasInsn *di)
3566ebe9383cSRichard Henderson {
3567ebe9383cSRichard Henderson     unsigned rt = extract32(insn, 0, 5);
3568ebe9383cSRichard Henderson     unsigned neg = extract32(insn, 5, 1);
3569ebe9383cSRichard Henderson     unsigned rm1 = extract32(insn, 21, 5);
3570ebe9383cSRichard Henderson     unsigned rm2 = extract32(insn, 16, 5);
3571ebe9383cSRichard Henderson     unsigned ra3 = assemble_rc64(insn);
3572ebe9383cSRichard Henderson     TCGv_i64 a, b, c;
3573ebe9383cSRichard Henderson 
3574ebe9383cSRichard Henderson     nullify_over(ctx);
3575ebe9383cSRichard Henderson     a = load_frd0(rm1);
3576ebe9383cSRichard Henderson     b = load_frd0(rm2);
3577ebe9383cSRichard Henderson     c = load_frd0(ra3);
3578ebe9383cSRichard Henderson 
3579ebe9383cSRichard Henderson     if (neg) {
3580ebe9383cSRichard Henderson         gen_helper_fmpynfadd_d(a, cpu_env, a, b, c);
3581ebe9383cSRichard Henderson     } else {
3582ebe9383cSRichard Henderson         gen_helper_fmpyfadd_d(a, cpu_env, a, b, c);
3583ebe9383cSRichard Henderson     }
3584ebe9383cSRichard Henderson 
3585ebe9383cSRichard Henderson     tcg_temp_free_i64(b);
3586ebe9383cSRichard Henderson     tcg_temp_free_i64(c);
3587ebe9383cSRichard Henderson     save_frd(rt, a);
3588ebe9383cSRichard Henderson     tcg_temp_free_i64(a);
3589*869051eaSRichard Henderson     return nullify_end(ctx, DISAS_NEXT);
3590ebe9383cSRichard Henderson }
3591ebe9383cSRichard Henderson 
3592ebe9383cSRichard Henderson static const DisasInsn table_fp_fused[] = {
3593ebe9383cSRichard Henderson     { 0xb8000000u, 0xfc000800u, trans_fmpyfadd_s },
3594ebe9383cSRichard Henderson     { 0xb8000800u, 0xfc0019c0u, trans_fmpyfadd_d }
3595ebe9383cSRichard Henderson };
3596ebe9383cSRichard Henderson 
3597*869051eaSRichard Henderson static DisasJumpType translate_table_int(DisasContext *ctx, uint32_t insn,
359861766fe9SRichard Henderson                                          const DisasInsn table[], size_t n)
359961766fe9SRichard Henderson {
360061766fe9SRichard Henderson     size_t i;
360161766fe9SRichard Henderson     for (i = 0; i < n; ++i) {
360261766fe9SRichard Henderson         if ((insn & table[i].mask) == table[i].insn) {
360361766fe9SRichard Henderson             return table[i].trans(ctx, insn, &table[i]);
360461766fe9SRichard Henderson         }
360561766fe9SRichard Henderson     }
360661766fe9SRichard Henderson     return gen_illegal(ctx);
360761766fe9SRichard Henderson }
360861766fe9SRichard Henderson 
360961766fe9SRichard Henderson #define translate_table(ctx, insn, table) \
361061766fe9SRichard Henderson     translate_table_int(ctx, insn, table, ARRAY_SIZE(table))
361161766fe9SRichard Henderson 
3612*869051eaSRichard Henderson static DisasJumpType translate_one(DisasContext *ctx, uint32_t insn)
361361766fe9SRichard Henderson {
361461766fe9SRichard Henderson     uint32_t opc = extract32(insn, 26, 6);
361561766fe9SRichard Henderson 
361661766fe9SRichard Henderson     switch (opc) {
361798a9cb79SRichard Henderson     case 0x00: /* system op */
361898a9cb79SRichard Henderson         return translate_table(ctx, insn, table_system);
361998a9cb79SRichard Henderson     case 0x01:
362098a9cb79SRichard Henderson         return translate_table(ctx, insn, table_mem_mgmt);
3621b2167459SRichard Henderson     case 0x02:
3622b2167459SRichard Henderson         return translate_table(ctx, insn, table_arith_log);
362396d6407fSRichard Henderson     case 0x03:
362496d6407fSRichard Henderson         return translate_table(ctx, insn, table_index_mem);
3625ebe9383cSRichard Henderson     case 0x06:
3626ebe9383cSRichard Henderson         return trans_fmpyadd(ctx, insn, false);
3627b2167459SRichard Henderson     case 0x08:
3628b2167459SRichard Henderson         return trans_ldil(ctx, insn);
362996d6407fSRichard Henderson     case 0x09:
363096d6407fSRichard Henderson         return trans_copr_w(ctx, insn);
3631b2167459SRichard Henderson     case 0x0A:
3632b2167459SRichard Henderson         return trans_addil(ctx, insn);
363396d6407fSRichard Henderson     case 0x0B:
363496d6407fSRichard Henderson         return trans_copr_dw(ctx, insn);
3635ebe9383cSRichard Henderson     case 0x0C:
3636ebe9383cSRichard Henderson         return translate_table(ctx, insn, table_float_0c);
3637b2167459SRichard Henderson     case 0x0D:
3638b2167459SRichard Henderson         return trans_ldo(ctx, insn);
3639ebe9383cSRichard Henderson     case 0x0E:
3640ebe9383cSRichard Henderson         return translate_table(ctx, insn, table_float_0e);
364196d6407fSRichard Henderson 
364296d6407fSRichard Henderson     case 0x10:
364396d6407fSRichard Henderson         return trans_load(ctx, insn, false, MO_UB);
364496d6407fSRichard Henderson     case 0x11:
364596d6407fSRichard Henderson         return trans_load(ctx, insn, false, MO_TEUW);
364696d6407fSRichard Henderson     case 0x12:
364796d6407fSRichard Henderson         return trans_load(ctx, insn, false, MO_TEUL);
364896d6407fSRichard Henderson     case 0x13:
364996d6407fSRichard Henderson         return trans_load(ctx, insn, true, MO_TEUL);
365096d6407fSRichard Henderson     case 0x16:
365196d6407fSRichard Henderson         return trans_fload_mod(ctx, insn);
365296d6407fSRichard Henderson     case 0x17:
365396d6407fSRichard Henderson         return trans_load_w(ctx, insn);
365496d6407fSRichard Henderson     case 0x18:
365596d6407fSRichard Henderson         return trans_store(ctx, insn, false, MO_UB);
365696d6407fSRichard Henderson     case 0x19:
365796d6407fSRichard Henderson         return trans_store(ctx, insn, false, MO_TEUW);
365896d6407fSRichard Henderson     case 0x1A:
365996d6407fSRichard Henderson         return trans_store(ctx, insn, false, MO_TEUL);
366096d6407fSRichard Henderson     case 0x1B:
366196d6407fSRichard Henderson         return trans_store(ctx, insn, true, MO_TEUL);
366296d6407fSRichard Henderson     case 0x1E:
366396d6407fSRichard Henderson         return trans_fstore_mod(ctx, insn);
366496d6407fSRichard Henderson     case 0x1F:
366596d6407fSRichard Henderson         return trans_store_w(ctx, insn);
366696d6407fSRichard Henderson 
366798cd9ca7SRichard Henderson     case 0x20:
366898cd9ca7SRichard Henderson         return trans_cmpb(ctx, insn, true, false, false);
366998cd9ca7SRichard Henderson     case 0x21:
367098cd9ca7SRichard Henderson         return trans_cmpb(ctx, insn, true, true, false);
367198cd9ca7SRichard Henderson     case 0x22:
367298cd9ca7SRichard Henderson         return trans_cmpb(ctx, insn, false, false, false);
367398cd9ca7SRichard Henderson     case 0x23:
367498cd9ca7SRichard Henderson         return trans_cmpb(ctx, insn, false, true, false);
3675b2167459SRichard Henderson     case 0x24:
3676b2167459SRichard Henderson         return trans_cmpiclr(ctx, insn);
3677b2167459SRichard Henderson     case 0x25:
3678b2167459SRichard Henderson         return trans_subi(ctx, insn);
3679ebe9383cSRichard Henderson     case 0x26:
3680ebe9383cSRichard Henderson         return trans_fmpyadd(ctx, insn, true);
368198cd9ca7SRichard Henderson     case 0x27:
368298cd9ca7SRichard Henderson         return trans_cmpb(ctx, insn, true, false, true);
368398cd9ca7SRichard Henderson     case 0x28:
368498cd9ca7SRichard Henderson         return trans_addb(ctx, insn, true, false);
368598cd9ca7SRichard Henderson     case 0x29:
368698cd9ca7SRichard Henderson         return trans_addb(ctx, insn, true, true);
368798cd9ca7SRichard Henderson     case 0x2A:
368898cd9ca7SRichard Henderson         return trans_addb(ctx, insn, false, false);
368998cd9ca7SRichard Henderson     case 0x2B:
369098cd9ca7SRichard Henderson         return trans_addb(ctx, insn, false, true);
3691b2167459SRichard Henderson     case 0x2C:
3692b2167459SRichard Henderson     case 0x2D:
3693b2167459SRichard Henderson         return trans_addi(ctx, insn);
3694ebe9383cSRichard Henderson     case 0x2E:
3695ebe9383cSRichard Henderson         return translate_table(ctx, insn, table_fp_fused);
369698cd9ca7SRichard Henderson     case 0x2F:
369798cd9ca7SRichard Henderson         return trans_cmpb(ctx, insn, false, false, true);
369896d6407fSRichard Henderson 
369998cd9ca7SRichard Henderson     case 0x30:
370098cd9ca7SRichard Henderson     case 0x31:
370198cd9ca7SRichard Henderson         return trans_bb(ctx, insn);
370298cd9ca7SRichard Henderson     case 0x32:
370398cd9ca7SRichard Henderson         return trans_movb(ctx, insn, false);
370498cd9ca7SRichard Henderson     case 0x33:
370598cd9ca7SRichard Henderson         return trans_movb(ctx, insn, true);
37060b1347d2SRichard Henderson     case 0x34:
37070b1347d2SRichard Henderson         return translate_table(ctx, insn, table_sh_ex);
37080b1347d2SRichard Henderson     case 0x35:
37090b1347d2SRichard Henderson         return translate_table(ctx, insn, table_depw);
371098cd9ca7SRichard Henderson     case 0x38:
371198cd9ca7SRichard Henderson         return trans_be(ctx, insn, false);
371298cd9ca7SRichard Henderson     case 0x39:
371398cd9ca7SRichard Henderson         return trans_be(ctx, insn, true);
371498cd9ca7SRichard Henderson     case 0x3A:
371598cd9ca7SRichard Henderson         return translate_table(ctx, insn, table_branch);
371696d6407fSRichard Henderson 
371796d6407fSRichard Henderson     case 0x04: /* spopn */
371896d6407fSRichard Henderson     case 0x05: /* diag */
371996d6407fSRichard Henderson     case 0x0F: /* product specific */
372096d6407fSRichard Henderson         break;
372196d6407fSRichard Henderson 
372296d6407fSRichard Henderson     case 0x07: /* unassigned */
372396d6407fSRichard Henderson     case 0x15: /* unassigned */
372496d6407fSRichard Henderson     case 0x1D: /* unassigned */
372596d6407fSRichard Henderson     case 0x37: /* unassigned */
372696d6407fSRichard Henderson     case 0x3F: /* unassigned */
372761766fe9SRichard Henderson     default:
372861766fe9SRichard Henderson         break;
372961766fe9SRichard Henderson     }
373061766fe9SRichard Henderson     return gen_illegal(ctx);
373161766fe9SRichard Henderson }
373261766fe9SRichard Henderson 
37339c489ea6SLluís Vilanova void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb)
373461766fe9SRichard Henderson {
37359c489ea6SLluís Vilanova     CPUHPPAState *env = cs->env_ptr;
373661766fe9SRichard Henderson     DisasContext ctx;
3737*869051eaSRichard Henderson     DisasJumpType ret;
373861766fe9SRichard Henderson     int num_insns, max_insns, i;
373961766fe9SRichard Henderson 
374061766fe9SRichard Henderson     ctx.tb = tb;
374161766fe9SRichard Henderson     ctx.cs = cs;
374261766fe9SRichard Henderson     ctx.iaoq_f = tb->pc;
374361766fe9SRichard Henderson     ctx.iaoq_b = tb->cs_base;
374461766fe9SRichard Henderson     ctx.singlestep_enabled = cs->singlestep_enabled;
374561766fe9SRichard Henderson 
374661766fe9SRichard Henderson     ctx.ntemps = 0;
374761766fe9SRichard Henderson     for (i = 0; i < ARRAY_SIZE(ctx.temps); ++i) {
374861766fe9SRichard Henderson         TCGV_UNUSED(ctx.temps[i]);
374961766fe9SRichard Henderson     }
375061766fe9SRichard Henderson 
375161766fe9SRichard Henderson     /* Compute the maximum number of insns to execute, as bounded by
375261766fe9SRichard Henderson        (1) icount, (2) single-stepping, (3) branch delay slots, or
375361766fe9SRichard Henderson        (4) the number of insns remaining on the current page.  */
375461766fe9SRichard Henderson     max_insns = tb->cflags & CF_COUNT_MASK;
375561766fe9SRichard Henderson     if (max_insns == 0) {
375661766fe9SRichard Henderson         max_insns = CF_COUNT_MASK;
375761766fe9SRichard Henderson     }
375861766fe9SRichard Henderson     if (ctx.singlestep_enabled || singlestep) {
375961766fe9SRichard Henderson         max_insns = 1;
376061766fe9SRichard Henderson     } else if (max_insns > TCG_MAX_INSNS) {
376161766fe9SRichard Henderson         max_insns = TCG_MAX_INSNS;
376261766fe9SRichard Henderson     }
376361766fe9SRichard Henderson 
376461766fe9SRichard Henderson     num_insns = 0;
376561766fe9SRichard Henderson     gen_tb_start(tb);
376661766fe9SRichard Henderson 
3767129e9cc3SRichard Henderson     /* Seed the nullification status from PSW[N], as shown in TB->FLAGS.  */
3768129e9cc3SRichard Henderson     ctx.null_cond = cond_make_f();
3769129e9cc3SRichard Henderson     ctx.psw_n_nonzero = false;
3770129e9cc3SRichard Henderson     if (tb->flags & 1) {
3771129e9cc3SRichard Henderson         ctx.null_cond.c = TCG_COND_ALWAYS;
3772129e9cc3SRichard Henderson         ctx.psw_n_nonzero = true;
3773129e9cc3SRichard Henderson     }
3774129e9cc3SRichard Henderson     ctx.null_lab = NULL;
3775129e9cc3SRichard Henderson 
377661766fe9SRichard Henderson     do {
377761766fe9SRichard Henderson         tcg_gen_insn_start(ctx.iaoq_f, ctx.iaoq_b);
377861766fe9SRichard Henderson         num_insns++;
377961766fe9SRichard Henderson 
378061766fe9SRichard Henderson         if (unlikely(cpu_breakpoint_test(cs, ctx.iaoq_f, BP_ANY))) {
378161766fe9SRichard Henderson             ret = gen_excp(&ctx, EXCP_DEBUG);
378261766fe9SRichard Henderson             break;
378361766fe9SRichard Henderson         }
378461766fe9SRichard Henderson         if (num_insns == max_insns && (tb->cflags & CF_LAST_IO)) {
378561766fe9SRichard Henderson             gen_io_start();
378661766fe9SRichard Henderson         }
378761766fe9SRichard Henderson 
37887ad439dfSRichard Henderson         if (ctx.iaoq_f < TARGET_PAGE_SIZE) {
37897ad439dfSRichard Henderson             ret = do_page_zero(&ctx);
3790*869051eaSRichard Henderson             assert(ret != DISAS_NEXT);
37917ad439dfSRichard Henderson         } else {
379261766fe9SRichard Henderson             /* Always fetch the insn, even if nullified, so that we check
379361766fe9SRichard Henderson                the page permissions for execute.  */
379461766fe9SRichard Henderson             uint32_t insn = cpu_ldl_code(env, ctx.iaoq_f);
379561766fe9SRichard Henderson 
379661766fe9SRichard Henderson             /* Set up the IA queue for the next insn.
379761766fe9SRichard Henderson                This will be overwritten by a branch.  */
379861766fe9SRichard Henderson             if (ctx.iaoq_b == -1) {
379961766fe9SRichard Henderson                 ctx.iaoq_n = -1;
380061766fe9SRichard Henderson                 ctx.iaoq_n_var = get_temp(&ctx);
380161766fe9SRichard Henderson                 tcg_gen_addi_tl(ctx.iaoq_n_var, cpu_iaoq_b, 4);
380261766fe9SRichard Henderson             } else {
380361766fe9SRichard Henderson                 ctx.iaoq_n = ctx.iaoq_b + 4;
380461766fe9SRichard Henderson                 TCGV_UNUSED(ctx.iaoq_n_var);
380561766fe9SRichard Henderson             }
380661766fe9SRichard Henderson 
3807129e9cc3SRichard Henderson             if (unlikely(ctx.null_cond.c == TCG_COND_ALWAYS)) {
3808129e9cc3SRichard Henderson                 ctx.null_cond.c = TCG_COND_NEVER;
3809*869051eaSRichard Henderson                 ret = DISAS_NEXT;
3810129e9cc3SRichard Henderson             } else {
381161766fe9SRichard Henderson                 ret = translate_one(&ctx, insn);
3812129e9cc3SRichard Henderson                 assert(ctx.null_lab == NULL);
3813129e9cc3SRichard Henderson             }
381461766fe9SRichard Henderson         }
381561766fe9SRichard Henderson 
381661766fe9SRichard Henderson         for (i = 0; i < ctx.ntemps; ++i) {
381761766fe9SRichard Henderson             tcg_temp_free(ctx.temps[i]);
381861766fe9SRichard Henderson             TCGV_UNUSED(ctx.temps[i]);
381961766fe9SRichard Henderson         }
382061766fe9SRichard Henderson         ctx.ntemps = 0;
382161766fe9SRichard Henderson 
382261766fe9SRichard Henderson         /* If we see non-linear instructions, exhaust instruction count,
382361766fe9SRichard Henderson            or run out of buffer space, stop generation.  */
382461766fe9SRichard Henderson         /* ??? The non-linear instruction restriction is purely due to
382561766fe9SRichard Henderson            the debugging dump.  Otherwise we *could* follow unconditional
382661766fe9SRichard Henderson            branches within the same page.  */
3827*869051eaSRichard Henderson         if (ret == DISAS_NEXT
382861766fe9SRichard Henderson             && (ctx.iaoq_b != ctx.iaoq_f + 4
382961766fe9SRichard Henderson                 || num_insns >= max_insns
383061766fe9SRichard Henderson                 || tcg_op_buf_full())) {
3831129e9cc3SRichard Henderson             if (ctx.null_cond.c == TCG_COND_NEVER
3832129e9cc3SRichard Henderson                 || ctx.null_cond.c == TCG_COND_ALWAYS) {
3833129e9cc3SRichard Henderson                 nullify_set(&ctx, ctx.null_cond.c == TCG_COND_ALWAYS);
3834129e9cc3SRichard Henderson                 gen_goto_tb(&ctx, 0, ctx.iaoq_b, ctx.iaoq_n);
3835*869051eaSRichard Henderson                 ret = DISAS_NORETURN;
3836129e9cc3SRichard Henderson             } else {
3837*869051eaSRichard Henderson                 ret = DISAS_IAQ_N_STALE;
383861766fe9SRichard Henderson             }
3839129e9cc3SRichard Henderson         }
384061766fe9SRichard Henderson 
384161766fe9SRichard Henderson         ctx.iaoq_f = ctx.iaoq_b;
384261766fe9SRichard Henderson         ctx.iaoq_b = ctx.iaoq_n;
3843*869051eaSRichard Henderson         if (ret == DISAS_NORETURN || ret == DISAS_IAQ_N_UPDATED) {
384461766fe9SRichard Henderson             break;
384561766fe9SRichard Henderson         }
384661766fe9SRichard Henderson         if (ctx.iaoq_f == -1) {
384761766fe9SRichard Henderson             tcg_gen_mov_tl(cpu_iaoq_f, cpu_iaoq_b);
384861766fe9SRichard Henderson             copy_iaoq_entry(cpu_iaoq_b, ctx.iaoq_n, ctx.iaoq_n_var);
3849129e9cc3SRichard Henderson             nullify_save(&ctx);
3850*869051eaSRichard Henderson             ret = DISAS_IAQ_N_UPDATED;
385161766fe9SRichard Henderson             break;
385261766fe9SRichard Henderson         }
385361766fe9SRichard Henderson         if (ctx.iaoq_b == -1) {
385461766fe9SRichard Henderson             tcg_gen_mov_tl(cpu_iaoq_b, ctx.iaoq_n_var);
385561766fe9SRichard Henderson         }
3856*869051eaSRichard Henderson     } while (ret == DISAS_NEXT);
385761766fe9SRichard Henderson 
385861766fe9SRichard Henderson     if (tb->cflags & CF_LAST_IO) {
385961766fe9SRichard Henderson         gen_io_end();
386061766fe9SRichard Henderson     }
386161766fe9SRichard Henderson 
386261766fe9SRichard Henderson     switch (ret) {
3863*869051eaSRichard Henderson     case DISAS_NORETURN:
386461766fe9SRichard Henderson         break;
3865*869051eaSRichard Henderson     case DISAS_IAQ_N_STALE:
386661766fe9SRichard Henderson         copy_iaoq_entry(cpu_iaoq_f, ctx.iaoq_f, cpu_iaoq_f);
386761766fe9SRichard Henderson         copy_iaoq_entry(cpu_iaoq_b, ctx.iaoq_b, cpu_iaoq_b);
3868129e9cc3SRichard Henderson         nullify_save(&ctx);
386961766fe9SRichard Henderson         /* FALLTHRU */
3870*869051eaSRichard Henderson     case DISAS_IAQ_N_UPDATED:
387161766fe9SRichard Henderson         if (ctx.singlestep_enabled) {
387261766fe9SRichard Henderson             gen_excp_1(EXCP_DEBUG);
387361766fe9SRichard Henderson         } else {
38744137cb83SRichard Henderson             tcg_gen_lookup_and_goto_ptr(cpu_iaoq_f);
387561766fe9SRichard Henderson         }
387661766fe9SRichard Henderson         break;
387761766fe9SRichard Henderson     default:
387861766fe9SRichard Henderson         abort();
387961766fe9SRichard Henderson     }
388061766fe9SRichard Henderson 
388161766fe9SRichard Henderson     gen_tb_end(tb, num_insns);
388261766fe9SRichard Henderson 
388361766fe9SRichard Henderson     tb->size = num_insns * 4;
388461766fe9SRichard Henderson     tb->icount = num_insns;
388561766fe9SRichard Henderson 
388661766fe9SRichard Henderson #ifdef DEBUG_DISAS
388761766fe9SRichard Henderson     if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)
388861766fe9SRichard Henderson         && qemu_log_in_addr_range(tb->pc)) {
388961766fe9SRichard Henderson         qemu_log_lock();
38907ad439dfSRichard Henderson         switch (tb->pc) {
38917ad439dfSRichard Henderson         case 0x00:
38927ad439dfSRichard Henderson             qemu_log("IN:\n0x00000000:  (null)\n\n");
38937ad439dfSRichard Henderson             break;
38947ad439dfSRichard Henderson         case 0xb0:
38957ad439dfSRichard Henderson             qemu_log("IN:\n0x000000b0:  light-weight-syscall\n\n");
38967ad439dfSRichard Henderson             break;
38977ad439dfSRichard Henderson         case 0xe0:
38987ad439dfSRichard Henderson             qemu_log("IN:\n0x000000e0:  set-thread-pointer-syscall\n\n");
38997ad439dfSRichard Henderson             break;
39007ad439dfSRichard Henderson         case 0x100:
39017ad439dfSRichard Henderson             qemu_log("IN:\n0x00000100:  syscall\n\n");
39027ad439dfSRichard Henderson             break;
39037ad439dfSRichard Henderson         default:
390461766fe9SRichard Henderson             qemu_log("IN: %s\n", lookup_symbol(tb->pc));
390561766fe9SRichard Henderson             log_target_disas(cs, tb->pc, tb->size, 1);
390661766fe9SRichard Henderson             qemu_log("\n");
39077ad439dfSRichard Henderson             break;
39087ad439dfSRichard Henderson         }
390961766fe9SRichard Henderson         qemu_log_unlock();
391061766fe9SRichard Henderson     }
391161766fe9SRichard Henderson #endif
391261766fe9SRichard Henderson }
391361766fe9SRichard Henderson 
391461766fe9SRichard Henderson void restore_state_to_opc(CPUHPPAState *env, TranslationBlock *tb,
391561766fe9SRichard Henderson                           target_ulong *data)
391661766fe9SRichard Henderson {
391761766fe9SRichard Henderson     env->iaoq_f = data[0];
391861766fe9SRichard Henderson     if (data[1] != -1) {
391961766fe9SRichard Henderson         env->iaoq_b = data[1];
392061766fe9SRichard Henderson     }
392161766fe9SRichard Henderson     /* Since we were executing the instruction at IAOQ_F, and took some
392261766fe9SRichard Henderson        sort of action that provoked the cpu_restore_state, we can infer
392361766fe9SRichard Henderson        that the instruction was not nullified.  */
392461766fe9SRichard Henderson     env->psw_n = 0;
392561766fe9SRichard Henderson }
3926