xref: /openbmc/qemu/target/hppa/translate.c (revision 3bdf20819e6824b75a498332961abe7fd25ed671)
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
9d6ea4236SChetan Pant  * version 2.1 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"
25dcb32f1dSPhilippe Mathieu-Daudé #include "tcg/tcg-op.h"
260843563fSRichard Henderson #include "tcg/tcg-op-gvec.h"
2761766fe9SRichard Henderson #include "exec/helper-proto.h"
2861766fe9SRichard Henderson #include "exec/helper-gen.h"
29869051eaSRichard Henderson #include "exec/translator.h"
3061766fe9SRichard Henderson #include "exec/log.h"
3161766fe9SRichard Henderson 
32d53106c9SRichard Henderson #define HELPER_H "helper.h"
33d53106c9SRichard Henderson #include "exec/helper-info.c.inc"
34d53106c9SRichard Henderson #undef  HELPER_H
35d53106c9SRichard Henderson 
36aac0f603SRichard Henderson /* Choose to use explicit sizes within this file. */
37aac0f603SRichard Henderson #undef tcg_temp_new
38d53106c9SRichard Henderson 
3961766fe9SRichard Henderson typedef struct DisasCond {
4061766fe9SRichard Henderson     TCGCond c;
416fd0c7bcSRichard Henderson     TCGv_i64 a0, a1;
4261766fe9SRichard Henderson } DisasCond;
4361766fe9SRichard Henderson 
4461766fe9SRichard Henderson typedef struct DisasContext {
45d01a3625SRichard Henderson     DisasContextBase base;
4661766fe9SRichard Henderson     CPUState *cs;
47f5b5c857SRichard Henderson     TCGOp *insn_start;
4861766fe9SRichard Henderson 
49c53e401eSRichard Henderson     uint64_t iaoq_f;
50c53e401eSRichard Henderson     uint64_t iaoq_b;
51c53e401eSRichard Henderson     uint64_t iaoq_n;
526fd0c7bcSRichard Henderson     TCGv_i64 iaoq_n_var;
5361766fe9SRichard Henderson 
5461766fe9SRichard Henderson     DisasCond null_cond;
5561766fe9SRichard Henderson     TCGLabel *null_lab;
5661766fe9SRichard Henderson 
57a4db4a78SRichard Henderson     TCGv_i64 zero;
58a4db4a78SRichard Henderson 
591a19da0dSRichard Henderson     uint32_t insn;
60494737b7SRichard Henderson     uint32_t tb_flags;
613d68ee7bSRichard Henderson     int mmu_idx;
623d68ee7bSRichard Henderson     int privilege;
6361766fe9SRichard Henderson     bool psw_n_nonzero;
64bd6243a3SRichard Henderson     bool is_pa20;
65217d1a5eSRichard Henderson 
66217d1a5eSRichard Henderson #ifdef CONFIG_USER_ONLY
67217d1a5eSRichard Henderson     MemOp unalign;
68217d1a5eSRichard Henderson #endif
6961766fe9SRichard Henderson } DisasContext;
7061766fe9SRichard Henderson 
71217d1a5eSRichard Henderson #ifdef CONFIG_USER_ONLY
72217d1a5eSRichard Henderson #define UNALIGN(C)       (C)->unalign
7317fe594cSRichard Henderson #define MMU_DISABLED(C)  false
74217d1a5eSRichard Henderson #else
752d4afb03SRichard Henderson #define UNALIGN(C)       MO_ALIGN
7617fe594cSRichard Henderson #define MMU_DISABLED(C)  MMU_IDX_MMU_DISABLED((C)->mmu_idx)
77217d1a5eSRichard Henderson #endif
78217d1a5eSRichard Henderson 
79e36f27efSRichard Henderson /* Note that ssm/rsm instructions number PSW_W and PSW_E differently.  */
80451e4ffdSRichard Henderson static int expand_sm_imm(DisasContext *ctx, int val)
81e36f27efSRichard Henderson {
82881d1073SHelge Deller     /* Keep unimplemented bits disabled -- see cpu_hppa_put_psw. */
83881d1073SHelge Deller     if (ctx->is_pa20) {
84e36f27efSRichard Henderson         if (val & PSW_SM_W) {
85881d1073SHelge Deller             val |= PSW_W;
86881d1073SHelge Deller         }
87881d1073SHelge Deller         val &= ~(PSW_SM_W | PSW_SM_E | PSW_G);
88881d1073SHelge Deller     } else {
89881d1073SHelge Deller         val &= ~(PSW_SM_W | PSW_SM_E | PSW_O);
90e36f27efSRichard Henderson     }
91e36f27efSRichard Henderson     return val;
92e36f27efSRichard Henderson }
93e36f27efSRichard Henderson 
94deee69a1SRichard Henderson /* Inverted space register indicates 0 means sr0 not inferred from base.  */
95451e4ffdSRichard Henderson static int expand_sr3x(DisasContext *ctx, int val)
96deee69a1SRichard Henderson {
97deee69a1SRichard Henderson     return ~val;
98deee69a1SRichard Henderson }
99deee69a1SRichard Henderson 
1001cd012a5SRichard Henderson /* Convert the M:A bits within a memory insn to the tri-state value
1011cd012a5SRichard Henderson    we use for the final M.  */
102451e4ffdSRichard Henderson static int ma_to_m(DisasContext *ctx, int val)
1031cd012a5SRichard Henderson {
1041cd012a5SRichard Henderson     return val & 2 ? (val & 1 ? -1 : 1) : 0;
1051cd012a5SRichard Henderson }
1061cd012a5SRichard Henderson 
107740038d7SRichard Henderson /* Convert the sign of the displacement to a pre or post-modify.  */
108451e4ffdSRichard Henderson static int pos_to_m(DisasContext *ctx, int val)
109740038d7SRichard Henderson {
110740038d7SRichard Henderson     return val ? 1 : -1;
111740038d7SRichard Henderson }
112740038d7SRichard Henderson 
113451e4ffdSRichard Henderson static int neg_to_m(DisasContext *ctx, int val)
114740038d7SRichard Henderson {
115740038d7SRichard Henderson     return val ? -1 : 1;
116740038d7SRichard Henderson }
117740038d7SRichard Henderson 
118740038d7SRichard Henderson /* Used for branch targets and fp memory ops.  */
119451e4ffdSRichard Henderson static int expand_shl2(DisasContext *ctx, int val)
12001afb7beSRichard Henderson {
12101afb7beSRichard Henderson     return val << 2;
12201afb7beSRichard Henderson }
12301afb7beSRichard Henderson 
1240588e061SRichard Henderson /* Used for assemble_21.  */
125451e4ffdSRichard Henderson static int expand_shl11(DisasContext *ctx, int val)
1260588e061SRichard Henderson {
1270588e061SRichard Henderson     return val << 11;
1280588e061SRichard Henderson }
1290588e061SRichard Henderson 
13072ae4f2bSRichard Henderson static int assemble_6(DisasContext *ctx, int val)
13172ae4f2bSRichard Henderson {
13272ae4f2bSRichard Henderson     /*
13372ae4f2bSRichard Henderson      * Officially, 32 * x + 32 - y.
13472ae4f2bSRichard Henderson      * Here, x is already in bit 5, and y is [4:0].
13572ae4f2bSRichard Henderson      * Since -y = ~y + 1, in 5 bits 32 - y => y ^ 31 + 1,
13672ae4f2bSRichard Henderson      * with the overflow from bit 4 summing with x.
13772ae4f2bSRichard Henderson      */
13872ae4f2bSRichard Henderson     return (val ^ 31) + 1;
13972ae4f2bSRichard Henderson }
14072ae4f2bSRichard Henderson 
1414768c28eSRichard Henderson /* Expander for assemble_16a(s,cat(im10a,0),i). */
1424768c28eSRichard Henderson static int expand_11a(DisasContext *ctx, int val)
1434768c28eSRichard Henderson {
1444768c28eSRichard Henderson     /*
1454768c28eSRichard Henderson      * @val is bit 0 and bits [4:15].
1464768c28eSRichard Henderson      * Swizzle thing around depending on PSW.W.
1474768c28eSRichard Henderson      */
1484768c28eSRichard Henderson     int im10a = extract32(val, 1, 10);
1494768c28eSRichard Henderson     int s = extract32(val, 11, 2);
1504768c28eSRichard Henderson     int i = (-(val & 1) << 13) | (im10a << 3);
1514768c28eSRichard Henderson 
1524768c28eSRichard Henderson     if (ctx->tb_flags & PSW_W) {
1534768c28eSRichard Henderson         i ^= s << 13;
1544768c28eSRichard Henderson     }
1554768c28eSRichard Henderson     return i;
1564768c28eSRichard Henderson }
1574768c28eSRichard Henderson 
15846174e14SRichard Henderson /* Expander for assemble_16a(s,im11a,i). */
15946174e14SRichard Henderson static int expand_12a(DisasContext *ctx, int val)
16046174e14SRichard Henderson {
16146174e14SRichard Henderson     /*
16246174e14SRichard Henderson      * @val is bit 0 and bits [3:15].
16346174e14SRichard Henderson      * Swizzle thing around depending on PSW.W.
16446174e14SRichard Henderson      */
16546174e14SRichard Henderson     int im11a = extract32(val, 1, 11);
16646174e14SRichard Henderson     int s = extract32(val, 12, 2);
16746174e14SRichard Henderson     int i = (-(val & 1) << 13) | (im11a << 2);
16846174e14SRichard Henderson 
16946174e14SRichard Henderson     if (ctx->tb_flags & PSW_W) {
17046174e14SRichard Henderson         i ^= s << 13;
17146174e14SRichard Henderson     }
17246174e14SRichard Henderson     return i;
17346174e14SRichard Henderson }
17446174e14SRichard Henderson 
17572bace2dSRichard Henderson /* Expander for assemble_16(s,im14). */
17672bace2dSRichard Henderson static int expand_16(DisasContext *ctx, int val)
17772bace2dSRichard Henderson {
17872bace2dSRichard Henderson     /*
17972bace2dSRichard Henderson      * @val is bits [0:15], containing both im14 and s.
18072bace2dSRichard Henderson      * Swizzle thing around depending on PSW.W.
18172bace2dSRichard Henderson      */
18272bace2dSRichard Henderson     int s = extract32(val, 14, 2);
18372bace2dSRichard Henderson     int i = (-(val & 1) << 13) | extract32(val, 1, 13);
18472bace2dSRichard Henderson 
18572bace2dSRichard Henderson     if (ctx->tb_flags & PSW_W) {
18672bace2dSRichard Henderson         i ^= s << 13;
18772bace2dSRichard Henderson     }
18872bace2dSRichard Henderson     return i;
18972bace2dSRichard Henderson }
19072bace2dSRichard Henderson 
19172bace2dSRichard Henderson /* The sp field is only present with !PSW_W. */
19272bace2dSRichard Henderson static int sp0_if_wide(DisasContext *ctx, int sp)
19372bace2dSRichard Henderson {
19472bace2dSRichard Henderson     return ctx->tb_flags & PSW_W ? 0 : sp;
19572bace2dSRichard Henderson }
19672bace2dSRichard Henderson 
197c65c3ee1SRichard Henderson /* Translate CMPI doubleword conditions to standard. */
198c65c3ee1SRichard Henderson static int cmpbid_c(DisasContext *ctx, int val)
199c65c3ee1SRichard Henderson {
200c65c3ee1SRichard Henderson     return val ? val : 4; /* 0 == "*<<" */
201c65c3ee1SRichard Henderson }
202c65c3ee1SRichard Henderson 
20382d0c831SRichard Henderson /*
20482d0c831SRichard Henderson  * In many places pa1.x did not decode the bit that later became
20582d0c831SRichard Henderson  * the pa2.0 D bit.  Suppress D unless the cpu is pa2.0.
20682d0c831SRichard Henderson  */
20782d0c831SRichard Henderson static int pa20_d(DisasContext *ctx, int val)
20882d0c831SRichard Henderson {
20982d0c831SRichard Henderson     return ctx->is_pa20 & val;
21082d0c831SRichard Henderson }
21101afb7beSRichard Henderson 
21240f9f908SRichard Henderson /* Include the auto-generated decoder.  */
213abff1abfSPaolo Bonzini #include "decode-insns.c.inc"
21440f9f908SRichard Henderson 
21561766fe9SRichard Henderson /* We are not using a goto_tb (for whatever reason), but have updated
21661766fe9SRichard Henderson    the iaq (for whatever reason), so don't do it again on exit.  */
217869051eaSRichard Henderson #define DISAS_IAQ_N_UPDATED  DISAS_TARGET_0
21861766fe9SRichard Henderson 
21961766fe9SRichard Henderson /* We are exiting the TB, but have neither emitted a goto_tb, nor
22061766fe9SRichard Henderson    updated the iaq for the next instruction to be executed.  */
221869051eaSRichard Henderson #define DISAS_IAQ_N_STALE    DISAS_TARGET_1
22261766fe9SRichard Henderson 
223e1b5a5edSRichard Henderson /* Similarly, but we want to return to the main loop immediately
224e1b5a5edSRichard Henderson    to recognize unmasked interrupts.  */
225e1b5a5edSRichard Henderson #define DISAS_IAQ_N_STALE_EXIT      DISAS_TARGET_2
226c5d0aec2SRichard Henderson #define DISAS_EXIT                  DISAS_TARGET_3
227e1b5a5edSRichard Henderson 
22861766fe9SRichard Henderson /* global register indexes */
2296fd0c7bcSRichard Henderson static TCGv_i64 cpu_gr[32];
23033423472SRichard Henderson static TCGv_i64 cpu_sr[4];
231494737b7SRichard Henderson static TCGv_i64 cpu_srH;
2326fd0c7bcSRichard Henderson static TCGv_i64 cpu_iaoq_f;
2336fd0c7bcSRichard Henderson static TCGv_i64 cpu_iaoq_b;
234c301f34eSRichard Henderson static TCGv_i64 cpu_iasq_f;
235c301f34eSRichard Henderson static TCGv_i64 cpu_iasq_b;
2366fd0c7bcSRichard Henderson static TCGv_i64 cpu_sar;
2376fd0c7bcSRichard Henderson static TCGv_i64 cpu_psw_n;
2386fd0c7bcSRichard Henderson static TCGv_i64 cpu_psw_v;
2396fd0c7bcSRichard Henderson static TCGv_i64 cpu_psw_cb;
2406fd0c7bcSRichard Henderson static TCGv_i64 cpu_psw_cb_msb;
24161766fe9SRichard Henderson 
24261766fe9SRichard Henderson void hppa_translate_init(void)
24361766fe9SRichard Henderson {
24461766fe9SRichard Henderson #define DEF_VAR(V)  { &cpu_##V, #V, offsetof(CPUHPPAState, V) }
24561766fe9SRichard Henderson 
2466fd0c7bcSRichard Henderson     typedef struct { TCGv_i64 *var; const char *name; int ofs; } GlobalVar;
24761766fe9SRichard Henderson     static const GlobalVar vars[] = {
24835136a77SRichard Henderson         { &cpu_sar, "sar", offsetof(CPUHPPAState, cr[CR_SAR]) },
24961766fe9SRichard Henderson         DEF_VAR(psw_n),
25061766fe9SRichard Henderson         DEF_VAR(psw_v),
25161766fe9SRichard Henderson         DEF_VAR(psw_cb),
25261766fe9SRichard Henderson         DEF_VAR(psw_cb_msb),
25361766fe9SRichard Henderson         DEF_VAR(iaoq_f),
25461766fe9SRichard Henderson         DEF_VAR(iaoq_b),
25561766fe9SRichard Henderson     };
25661766fe9SRichard Henderson 
25761766fe9SRichard Henderson #undef DEF_VAR
25861766fe9SRichard Henderson 
25961766fe9SRichard Henderson     /* Use the symbolic register names that match the disassembler.  */
26061766fe9SRichard Henderson     static const char gr_names[32][4] = {
26161766fe9SRichard Henderson         "r0",  "r1",  "r2",  "r3",  "r4",  "r5",  "r6",  "r7",
26261766fe9SRichard Henderson         "r8",  "r9",  "r10", "r11", "r12", "r13", "r14", "r15",
26361766fe9SRichard Henderson         "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
26461766fe9SRichard Henderson         "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31"
26561766fe9SRichard Henderson     };
26633423472SRichard Henderson     /* SR[4-7] are not global registers so that we can index them.  */
267494737b7SRichard Henderson     static const char sr_names[5][4] = {
268494737b7SRichard Henderson         "sr0", "sr1", "sr2", "sr3", "srH"
26933423472SRichard Henderson     };
27061766fe9SRichard Henderson 
27161766fe9SRichard Henderson     int i;
27261766fe9SRichard Henderson 
273f764718dSRichard Henderson     cpu_gr[0] = NULL;
27461766fe9SRichard Henderson     for (i = 1; i < 32; i++) {
275ad75a51eSRichard Henderson         cpu_gr[i] = tcg_global_mem_new(tcg_env,
27661766fe9SRichard Henderson                                        offsetof(CPUHPPAState, gr[i]),
27761766fe9SRichard Henderson                                        gr_names[i]);
27861766fe9SRichard Henderson     }
27933423472SRichard Henderson     for (i = 0; i < 4; i++) {
280ad75a51eSRichard Henderson         cpu_sr[i] = tcg_global_mem_new_i64(tcg_env,
28133423472SRichard Henderson                                            offsetof(CPUHPPAState, sr[i]),
28233423472SRichard Henderson                                            sr_names[i]);
28333423472SRichard Henderson     }
284ad75a51eSRichard Henderson     cpu_srH = tcg_global_mem_new_i64(tcg_env,
285494737b7SRichard Henderson                                      offsetof(CPUHPPAState, sr[4]),
286494737b7SRichard Henderson                                      sr_names[4]);
28761766fe9SRichard Henderson 
28861766fe9SRichard Henderson     for (i = 0; i < ARRAY_SIZE(vars); ++i) {
28961766fe9SRichard Henderson         const GlobalVar *v = &vars[i];
290ad75a51eSRichard Henderson         *v->var = tcg_global_mem_new(tcg_env, v->ofs, v->name);
29161766fe9SRichard Henderson     }
292c301f34eSRichard Henderson 
293ad75a51eSRichard Henderson     cpu_iasq_f = tcg_global_mem_new_i64(tcg_env,
294c301f34eSRichard Henderson                                         offsetof(CPUHPPAState, iasq_f),
295c301f34eSRichard Henderson                                         "iasq_f");
296ad75a51eSRichard Henderson     cpu_iasq_b = tcg_global_mem_new_i64(tcg_env,
297c301f34eSRichard Henderson                                         offsetof(CPUHPPAState, iasq_b),
298c301f34eSRichard Henderson                                         "iasq_b");
29961766fe9SRichard Henderson }
30061766fe9SRichard Henderson 
301f5b5c857SRichard Henderson static void set_insn_breg(DisasContext *ctx, int breg)
302f5b5c857SRichard Henderson {
303f5b5c857SRichard Henderson     assert(ctx->insn_start != NULL);
304f5b5c857SRichard Henderson     tcg_set_insn_start_param(ctx->insn_start, 2, breg);
305f5b5c857SRichard Henderson     ctx->insn_start = NULL;
306f5b5c857SRichard Henderson }
307f5b5c857SRichard Henderson 
308129e9cc3SRichard Henderson static DisasCond cond_make_f(void)
309129e9cc3SRichard Henderson {
310f764718dSRichard Henderson     return (DisasCond){
311f764718dSRichard Henderson         .c = TCG_COND_NEVER,
312f764718dSRichard Henderson         .a0 = NULL,
313f764718dSRichard Henderson         .a1 = NULL,
314f764718dSRichard Henderson     };
315129e9cc3SRichard Henderson }
316129e9cc3SRichard Henderson 
317df0232feSRichard Henderson static DisasCond cond_make_t(void)
318df0232feSRichard Henderson {
319df0232feSRichard Henderson     return (DisasCond){
320df0232feSRichard Henderson         .c = TCG_COND_ALWAYS,
321df0232feSRichard Henderson         .a0 = NULL,
322df0232feSRichard Henderson         .a1 = NULL,
323df0232feSRichard Henderson     };
324df0232feSRichard Henderson }
325df0232feSRichard Henderson 
326129e9cc3SRichard Henderson static DisasCond cond_make_n(void)
327129e9cc3SRichard Henderson {
328f764718dSRichard Henderson     return (DisasCond){
329f764718dSRichard Henderson         .c = TCG_COND_NE,
330f764718dSRichard Henderson         .a0 = cpu_psw_n,
3316fd0c7bcSRichard Henderson         .a1 = tcg_constant_i64(0)
332f764718dSRichard Henderson     };
333129e9cc3SRichard Henderson }
334129e9cc3SRichard Henderson 
3356fd0c7bcSRichard Henderson static DisasCond cond_make_tmp(TCGCond c, TCGv_i64 a0, TCGv_i64 a1)
336b47a4a02SSven Schnelle {
337b47a4a02SSven Schnelle     assert (c != TCG_COND_NEVER && c != TCG_COND_ALWAYS);
3384fe9533aSRichard Henderson     return (DisasCond){ .c = c, .a0 = a0, .a1 = a1 };
3394fe9533aSRichard Henderson }
3404fe9533aSRichard Henderson 
3416fd0c7bcSRichard Henderson static DisasCond cond_make_0_tmp(TCGCond c, TCGv_i64 a0)
3424fe9533aSRichard Henderson {
3436fd0c7bcSRichard Henderson     return cond_make_tmp(c, a0, tcg_constant_i64(0));
344b47a4a02SSven Schnelle }
345b47a4a02SSven Schnelle 
3466fd0c7bcSRichard Henderson static DisasCond cond_make_0(TCGCond c, TCGv_i64 a0)
347129e9cc3SRichard Henderson {
348aac0f603SRichard Henderson     TCGv_i64 tmp = tcg_temp_new_i64();
3496fd0c7bcSRichard Henderson     tcg_gen_mov_i64(tmp, a0);
350b47a4a02SSven Schnelle     return cond_make_0_tmp(c, tmp);
351129e9cc3SRichard Henderson }
352129e9cc3SRichard Henderson 
3536fd0c7bcSRichard Henderson static DisasCond cond_make(TCGCond c, TCGv_i64 a0, TCGv_i64 a1)
354129e9cc3SRichard Henderson {
355aac0f603SRichard Henderson     TCGv_i64 t0 = tcg_temp_new_i64();
356aac0f603SRichard Henderson     TCGv_i64 t1 = tcg_temp_new_i64();
357129e9cc3SRichard Henderson 
3586fd0c7bcSRichard Henderson     tcg_gen_mov_i64(t0, a0);
3596fd0c7bcSRichard Henderson     tcg_gen_mov_i64(t1, a1);
3604fe9533aSRichard Henderson     return cond_make_tmp(c, t0, t1);
361129e9cc3SRichard Henderson }
362129e9cc3SRichard Henderson 
363129e9cc3SRichard Henderson static void cond_free(DisasCond *cond)
364129e9cc3SRichard Henderson {
365129e9cc3SRichard Henderson     switch (cond->c) {
366129e9cc3SRichard Henderson     default:
367f764718dSRichard Henderson         cond->a0 = NULL;
368f764718dSRichard Henderson         cond->a1 = NULL;
369129e9cc3SRichard Henderson         /* fallthru */
370129e9cc3SRichard Henderson     case TCG_COND_ALWAYS:
371129e9cc3SRichard Henderson         cond->c = TCG_COND_NEVER;
372129e9cc3SRichard Henderson         break;
373129e9cc3SRichard Henderson     case TCG_COND_NEVER:
374129e9cc3SRichard Henderson         break;
375129e9cc3SRichard Henderson     }
376129e9cc3SRichard Henderson }
377129e9cc3SRichard Henderson 
3786fd0c7bcSRichard Henderson static TCGv_i64 load_gpr(DisasContext *ctx, unsigned reg)
37961766fe9SRichard Henderson {
38061766fe9SRichard Henderson     if (reg == 0) {
381bc3da3cfSRichard Henderson         return ctx->zero;
38261766fe9SRichard Henderson     } else {
38361766fe9SRichard Henderson         return cpu_gr[reg];
38461766fe9SRichard Henderson     }
38561766fe9SRichard Henderson }
38661766fe9SRichard Henderson 
3876fd0c7bcSRichard Henderson static TCGv_i64 dest_gpr(DisasContext *ctx, unsigned reg)
38861766fe9SRichard Henderson {
389129e9cc3SRichard Henderson     if (reg == 0 || ctx->null_cond.c != TCG_COND_NEVER) {
390aac0f603SRichard Henderson         return tcg_temp_new_i64();
39161766fe9SRichard Henderson     } else {
39261766fe9SRichard Henderson         return cpu_gr[reg];
39361766fe9SRichard Henderson     }
39461766fe9SRichard Henderson }
39561766fe9SRichard Henderson 
3966fd0c7bcSRichard Henderson static void save_or_nullify(DisasContext *ctx, TCGv_i64 dest, TCGv_i64 t)
397129e9cc3SRichard Henderson {
398129e9cc3SRichard Henderson     if (ctx->null_cond.c != TCG_COND_NEVER) {
3996fd0c7bcSRichard Henderson         tcg_gen_movcond_i64(ctx->null_cond.c, dest, ctx->null_cond.a0,
400129e9cc3SRichard Henderson                             ctx->null_cond.a1, dest, t);
401129e9cc3SRichard Henderson     } else {
4026fd0c7bcSRichard Henderson         tcg_gen_mov_i64(dest, t);
403129e9cc3SRichard Henderson     }
404129e9cc3SRichard Henderson }
405129e9cc3SRichard Henderson 
4066fd0c7bcSRichard Henderson static void save_gpr(DisasContext *ctx, unsigned reg, TCGv_i64 t)
407129e9cc3SRichard Henderson {
408129e9cc3SRichard Henderson     if (reg != 0) {
409129e9cc3SRichard Henderson         save_or_nullify(ctx, cpu_gr[reg], t);
410129e9cc3SRichard Henderson     }
411129e9cc3SRichard Henderson }
412129e9cc3SRichard Henderson 
413e03b5686SMarc-André Lureau #if HOST_BIG_ENDIAN
41496d6407fSRichard Henderson # define HI_OFS  0
41596d6407fSRichard Henderson # define LO_OFS  4
41696d6407fSRichard Henderson #else
41796d6407fSRichard Henderson # define HI_OFS  4
41896d6407fSRichard Henderson # define LO_OFS  0
41996d6407fSRichard Henderson #endif
42096d6407fSRichard Henderson 
42196d6407fSRichard Henderson static TCGv_i32 load_frw_i32(unsigned rt)
42296d6407fSRichard Henderson {
42396d6407fSRichard Henderson     TCGv_i32 ret = tcg_temp_new_i32();
424ad75a51eSRichard Henderson     tcg_gen_ld_i32(ret, tcg_env,
42596d6407fSRichard Henderson                    offsetof(CPUHPPAState, fr[rt & 31])
42696d6407fSRichard Henderson                    + (rt & 32 ? LO_OFS : HI_OFS));
42796d6407fSRichard Henderson     return ret;
42896d6407fSRichard Henderson }
42996d6407fSRichard Henderson 
430ebe9383cSRichard Henderson static TCGv_i32 load_frw0_i32(unsigned rt)
431ebe9383cSRichard Henderson {
432ebe9383cSRichard Henderson     if (rt == 0) {
4330992a930SRichard Henderson         TCGv_i32 ret = tcg_temp_new_i32();
4340992a930SRichard Henderson         tcg_gen_movi_i32(ret, 0);
4350992a930SRichard Henderson         return ret;
436ebe9383cSRichard Henderson     } else {
437ebe9383cSRichard Henderson         return load_frw_i32(rt);
438ebe9383cSRichard Henderson     }
439ebe9383cSRichard Henderson }
440ebe9383cSRichard Henderson 
441ebe9383cSRichard Henderson static TCGv_i64 load_frw0_i64(unsigned rt)
442ebe9383cSRichard Henderson {
443ebe9383cSRichard Henderson     TCGv_i64 ret = tcg_temp_new_i64();
4440992a930SRichard Henderson     if (rt == 0) {
4450992a930SRichard Henderson         tcg_gen_movi_i64(ret, 0);
4460992a930SRichard Henderson     } else {
447ad75a51eSRichard Henderson         tcg_gen_ld32u_i64(ret, tcg_env,
448ebe9383cSRichard Henderson                           offsetof(CPUHPPAState, fr[rt & 31])
449ebe9383cSRichard Henderson                           + (rt & 32 ? LO_OFS : HI_OFS));
450ebe9383cSRichard Henderson     }
4510992a930SRichard Henderson     return ret;
452ebe9383cSRichard Henderson }
453ebe9383cSRichard Henderson 
45496d6407fSRichard Henderson static void save_frw_i32(unsigned rt, TCGv_i32 val)
45596d6407fSRichard Henderson {
456ad75a51eSRichard Henderson     tcg_gen_st_i32(val, tcg_env,
45796d6407fSRichard Henderson                    offsetof(CPUHPPAState, fr[rt & 31])
45896d6407fSRichard Henderson                    + (rt & 32 ? LO_OFS : HI_OFS));
45996d6407fSRichard Henderson }
46096d6407fSRichard Henderson 
46196d6407fSRichard Henderson #undef HI_OFS
46296d6407fSRichard Henderson #undef LO_OFS
46396d6407fSRichard Henderson 
46496d6407fSRichard Henderson static TCGv_i64 load_frd(unsigned rt)
46596d6407fSRichard Henderson {
46696d6407fSRichard Henderson     TCGv_i64 ret = tcg_temp_new_i64();
467ad75a51eSRichard Henderson     tcg_gen_ld_i64(ret, tcg_env, offsetof(CPUHPPAState, fr[rt]));
46896d6407fSRichard Henderson     return ret;
46996d6407fSRichard Henderson }
47096d6407fSRichard Henderson 
471ebe9383cSRichard Henderson static TCGv_i64 load_frd0(unsigned rt)
472ebe9383cSRichard Henderson {
473ebe9383cSRichard Henderson     if (rt == 0) {
4740992a930SRichard Henderson         TCGv_i64 ret = tcg_temp_new_i64();
4750992a930SRichard Henderson         tcg_gen_movi_i64(ret, 0);
4760992a930SRichard Henderson         return ret;
477ebe9383cSRichard Henderson     } else {
478ebe9383cSRichard Henderson         return load_frd(rt);
479ebe9383cSRichard Henderson     }
480ebe9383cSRichard Henderson }
481ebe9383cSRichard Henderson 
48296d6407fSRichard Henderson static void save_frd(unsigned rt, TCGv_i64 val)
48396d6407fSRichard Henderson {
484ad75a51eSRichard Henderson     tcg_gen_st_i64(val, tcg_env, offsetof(CPUHPPAState, fr[rt]));
48596d6407fSRichard Henderson }
48696d6407fSRichard Henderson 
48733423472SRichard Henderson static void load_spr(DisasContext *ctx, TCGv_i64 dest, unsigned reg)
48833423472SRichard Henderson {
48933423472SRichard Henderson #ifdef CONFIG_USER_ONLY
49033423472SRichard Henderson     tcg_gen_movi_i64(dest, 0);
49133423472SRichard Henderson #else
49233423472SRichard Henderson     if (reg < 4) {
49333423472SRichard Henderson         tcg_gen_mov_i64(dest, cpu_sr[reg]);
494494737b7SRichard Henderson     } else if (ctx->tb_flags & TB_FLAG_SR_SAME) {
495494737b7SRichard Henderson         tcg_gen_mov_i64(dest, cpu_srH);
49633423472SRichard Henderson     } else {
497ad75a51eSRichard Henderson         tcg_gen_ld_i64(dest, tcg_env, offsetof(CPUHPPAState, sr[reg]));
49833423472SRichard Henderson     }
49933423472SRichard Henderson #endif
50033423472SRichard Henderson }
50133423472SRichard Henderson 
502129e9cc3SRichard Henderson /* Skip over the implementation of an insn that has been nullified.
503129e9cc3SRichard Henderson    Use this when the insn is too complex for a conditional move.  */
504129e9cc3SRichard Henderson static void nullify_over(DisasContext *ctx)
505129e9cc3SRichard Henderson {
506129e9cc3SRichard Henderson     if (ctx->null_cond.c != TCG_COND_NEVER) {
507129e9cc3SRichard Henderson         /* The always condition should have been handled in the main loop.  */
508129e9cc3SRichard Henderson         assert(ctx->null_cond.c != TCG_COND_ALWAYS);
509129e9cc3SRichard Henderson 
510129e9cc3SRichard Henderson         ctx->null_lab = gen_new_label();
511129e9cc3SRichard Henderson 
512129e9cc3SRichard Henderson         /* If we're using PSW[N], copy it to a temp because... */
5136e94937aSRichard Henderson         if (ctx->null_cond.a0 == cpu_psw_n) {
514aac0f603SRichard Henderson             ctx->null_cond.a0 = tcg_temp_new_i64();
5156fd0c7bcSRichard Henderson             tcg_gen_mov_i64(ctx->null_cond.a0, cpu_psw_n);
516129e9cc3SRichard Henderson         }
517129e9cc3SRichard Henderson         /* ... we clear it before branching over the implementation,
518129e9cc3SRichard Henderson            so that (1) it's clear after nullifying this insn and
519129e9cc3SRichard Henderson            (2) if this insn nullifies the next, PSW[N] is valid.  */
520129e9cc3SRichard Henderson         if (ctx->psw_n_nonzero) {
521129e9cc3SRichard Henderson             ctx->psw_n_nonzero = false;
5226fd0c7bcSRichard Henderson             tcg_gen_movi_i64(cpu_psw_n, 0);
523129e9cc3SRichard Henderson         }
524129e9cc3SRichard Henderson 
5256fd0c7bcSRichard Henderson         tcg_gen_brcond_i64(ctx->null_cond.c, ctx->null_cond.a0,
526129e9cc3SRichard Henderson                            ctx->null_cond.a1, ctx->null_lab);
527129e9cc3SRichard Henderson         cond_free(&ctx->null_cond);
528129e9cc3SRichard Henderson     }
529129e9cc3SRichard Henderson }
530129e9cc3SRichard Henderson 
531129e9cc3SRichard Henderson /* Save the current nullification state to PSW[N].  */
532129e9cc3SRichard Henderson static void nullify_save(DisasContext *ctx)
533129e9cc3SRichard Henderson {
534129e9cc3SRichard Henderson     if (ctx->null_cond.c == TCG_COND_NEVER) {
535129e9cc3SRichard Henderson         if (ctx->psw_n_nonzero) {
5366fd0c7bcSRichard Henderson             tcg_gen_movi_i64(cpu_psw_n, 0);
537129e9cc3SRichard Henderson         }
538129e9cc3SRichard Henderson         return;
539129e9cc3SRichard Henderson     }
5406e94937aSRichard Henderson     if (ctx->null_cond.a0 != cpu_psw_n) {
5416fd0c7bcSRichard Henderson         tcg_gen_setcond_i64(ctx->null_cond.c, cpu_psw_n,
542129e9cc3SRichard Henderson                             ctx->null_cond.a0, ctx->null_cond.a1);
543129e9cc3SRichard Henderson         ctx->psw_n_nonzero = true;
544129e9cc3SRichard Henderson     }
545129e9cc3SRichard Henderson     cond_free(&ctx->null_cond);
546129e9cc3SRichard Henderson }
547129e9cc3SRichard Henderson 
548129e9cc3SRichard Henderson /* Set a PSW[N] to X.  The intention is that this is used immediately
549129e9cc3SRichard Henderson    before a goto_tb/exit_tb, so that there is no fallthru path to other
550129e9cc3SRichard Henderson    code within the TB.  Therefore we do not update psw_n_nonzero.  */
551129e9cc3SRichard Henderson static void nullify_set(DisasContext *ctx, bool x)
552129e9cc3SRichard Henderson {
553129e9cc3SRichard Henderson     if (ctx->psw_n_nonzero || x) {
5546fd0c7bcSRichard Henderson         tcg_gen_movi_i64(cpu_psw_n, x);
555129e9cc3SRichard Henderson     }
556129e9cc3SRichard Henderson }
557129e9cc3SRichard Henderson 
558129e9cc3SRichard Henderson /* Mark the end of an instruction that may have been nullified.
55940f9f908SRichard Henderson    This is the pair to nullify_over.  Always returns true so that
56040f9f908SRichard Henderson    it may be tail-called from a translate function.  */
56131234768SRichard Henderson static bool nullify_end(DisasContext *ctx)
562129e9cc3SRichard Henderson {
563129e9cc3SRichard Henderson     TCGLabel *null_lab = ctx->null_lab;
56431234768SRichard Henderson     DisasJumpType status = ctx->base.is_jmp;
565129e9cc3SRichard Henderson 
566f49b3537SRichard Henderson     /* For NEXT, NORETURN, STALE, we can easily continue (or exit).
567f49b3537SRichard Henderson        For UPDATED, we cannot update on the nullified path.  */
568f49b3537SRichard Henderson     assert(status != DISAS_IAQ_N_UPDATED);
569f49b3537SRichard Henderson 
570129e9cc3SRichard Henderson     if (likely(null_lab == NULL)) {
571129e9cc3SRichard Henderson         /* The current insn wasn't conditional or handled the condition
572129e9cc3SRichard Henderson            applied to it without a branch, so the (new) setting of
573129e9cc3SRichard Henderson            NULL_COND can be applied directly to the next insn.  */
57431234768SRichard Henderson         return true;
575129e9cc3SRichard Henderson     }
576129e9cc3SRichard Henderson     ctx->null_lab = NULL;
577129e9cc3SRichard Henderson 
578129e9cc3SRichard Henderson     if (likely(ctx->null_cond.c == TCG_COND_NEVER)) {
579129e9cc3SRichard Henderson         /* The next instruction will be unconditional,
580129e9cc3SRichard Henderson            and NULL_COND already reflects that.  */
581129e9cc3SRichard Henderson         gen_set_label(null_lab);
582129e9cc3SRichard Henderson     } else {
583129e9cc3SRichard Henderson         /* The insn that we just executed is itself nullifying the next
584129e9cc3SRichard Henderson            instruction.  Store the condition in the PSW[N] global.
585129e9cc3SRichard Henderson            We asserted PSW[N] = 0 in nullify_over, so that after the
586129e9cc3SRichard Henderson            label we have the proper value in place.  */
587129e9cc3SRichard Henderson         nullify_save(ctx);
588129e9cc3SRichard Henderson         gen_set_label(null_lab);
589129e9cc3SRichard Henderson         ctx->null_cond = cond_make_n();
590129e9cc3SRichard Henderson     }
591869051eaSRichard Henderson     if (status == DISAS_NORETURN) {
59231234768SRichard Henderson         ctx->base.is_jmp = DISAS_NEXT;
593129e9cc3SRichard Henderson     }
59431234768SRichard Henderson     return true;
595129e9cc3SRichard Henderson }
596129e9cc3SRichard Henderson 
5976fd0c7bcSRichard Henderson static void copy_iaoq_entry(DisasContext *ctx, TCGv_i64 dest,
5986fd0c7bcSRichard Henderson                             uint64_t ival, TCGv_i64 vval)
59961766fe9SRichard Henderson {
6007d50b696SSven Schnelle     uint64_t mask = gva_offset_mask(ctx->tb_flags);
601f13bf343SRichard Henderson 
602f13bf343SRichard Henderson     if (ival != -1) {
6036fd0c7bcSRichard Henderson         tcg_gen_movi_i64(dest, ival & mask);
604f13bf343SRichard Henderson         return;
605f13bf343SRichard Henderson     }
606f13bf343SRichard Henderson     tcg_debug_assert(vval != NULL);
607f13bf343SRichard Henderson 
608f13bf343SRichard Henderson     /*
609f13bf343SRichard Henderson      * We know that the IAOQ is already properly masked.
610f13bf343SRichard Henderson      * This optimization is primarily for "iaoq_f = iaoq_b".
611f13bf343SRichard Henderson      */
612f13bf343SRichard Henderson     if (vval == cpu_iaoq_f || vval == cpu_iaoq_b) {
6136fd0c7bcSRichard Henderson         tcg_gen_mov_i64(dest, vval);
61461766fe9SRichard Henderson     } else {
6156fd0c7bcSRichard Henderson         tcg_gen_andi_i64(dest, vval, mask);
61661766fe9SRichard Henderson     }
61761766fe9SRichard Henderson }
61861766fe9SRichard Henderson 
619c53e401eSRichard Henderson static inline uint64_t iaoq_dest(DisasContext *ctx, int64_t disp)
62061766fe9SRichard Henderson {
62161766fe9SRichard Henderson     return ctx->iaoq_f + disp + 8;
62261766fe9SRichard Henderson }
62361766fe9SRichard Henderson 
62461766fe9SRichard Henderson static void gen_excp_1(int exception)
62561766fe9SRichard Henderson {
626ad75a51eSRichard Henderson     gen_helper_excp(tcg_env, tcg_constant_i32(exception));
62761766fe9SRichard Henderson }
62861766fe9SRichard Henderson 
62931234768SRichard Henderson static void gen_excp(DisasContext *ctx, int exception)
63061766fe9SRichard Henderson {
631741322f4SRichard Henderson     copy_iaoq_entry(ctx, cpu_iaoq_f, ctx->iaoq_f, cpu_iaoq_f);
632741322f4SRichard Henderson     copy_iaoq_entry(ctx, cpu_iaoq_b, ctx->iaoq_b, cpu_iaoq_b);
633129e9cc3SRichard Henderson     nullify_save(ctx);
63461766fe9SRichard Henderson     gen_excp_1(exception);
63531234768SRichard Henderson     ctx->base.is_jmp = DISAS_NORETURN;
63661766fe9SRichard Henderson }
63761766fe9SRichard Henderson 
63831234768SRichard Henderson static bool gen_excp_iir(DisasContext *ctx, int exc)
6391a19da0dSRichard Henderson {
64031234768SRichard Henderson     nullify_over(ctx);
6416fd0c7bcSRichard Henderson     tcg_gen_st_i64(tcg_constant_i64(ctx->insn),
642ad75a51eSRichard Henderson                    tcg_env, offsetof(CPUHPPAState, cr[CR_IIR]));
64331234768SRichard Henderson     gen_excp(ctx, exc);
64431234768SRichard Henderson     return nullify_end(ctx);
6451a19da0dSRichard Henderson }
6461a19da0dSRichard Henderson 
64731234768SRichard Henderson static bool gen_illegal(DisasContext *ctx)
64861766fe9SRichard Henderson {
64931234768SRichard Henderson     return gen_excp_iir(ctx, EXCP_ILL);
65061766fe9SRichard Henderson }
65161766fe9SRichard Henderson 
65240f9f908SRichard Henderson #ifdef CONFIG_USER_ONLY
65340f9f908SRichard Henderson #define CHECK_MOST_PRIVILEGED(EXCP) \
65440f9f908SRichard Henderson     return gen_excp_iir(ctx, EXCP)
65540f9f908SRichard Henderson #else
656e1b5a5edSRichard Henderson #define CHECK_MOST_PRIVILEGED(EXCP) \
657e1b5a5edSRichard Henderson     do {                                     \
658e1b5a5edSRichard Henderson         if (ctx->privilege != 0) {           \
65931234768SRichard Henderson             return gen_excp_iir(ctx, EXCP);  \
660e1b5a5edSRichard Henderson         }                                    \
661e1b5a5edSRichard Henderson     } while (0)
66240f9f908SRichard Henderson #endif
663e1b5a5edSRichard Henderson 
664c53e401eSRichard Henderson static bool use_goto_tb(DisasContext *ctx, uint64_t dest)
66561766fe9SRichard Henderson {
66657f91498SRichard Henderson     return translator_use_goto_tb(&ctx->base, dest);
66761766fe9SRichard Henderson }
66861766fe9SRichard Henderson 
669129e9cc3SRichard Henderson /* If the next insn is to be nullified, and it's on the same page,
670129e9cc3SRichard Henderson    and we're not attempting to set a breakpoint on it, then we can
671129e9cc3SRichard Henderson    totally skip the nullified insn.  This avoids creating and
672129e9cc3SRichard Henderson    executing a TB that merely branches to the next TB.  */
673129e9cc3SRichard Henderson static bool use_nullify_skip(DisasContext *ctx)
674129e9cc3SRichard Henderson {
675129e9cc3SRichard Henderson     return (((ctx->iaoq_b ^ ctx->iaoq_f) & TARGET_PAGE_MASK) == 0
676129e9cc3SRichard Henderson             && !cpu_breakpoint_test(ctx->cs, ctx->iaoq_b, BP_ANY));
677129e9cc3SRichard Henderson }
678129e9cc3SRichard Henderson 
67961766fe9SRichard Henderson static void gen_goto_tb(DisasContext *ctx, int which,
680c53e401eSRichard Henderson                         uint64_t f, uint64_t b)
68161766fe9SRichard Henderson {
68261766fe9SRichard Henderson     if (f != -1 && b != -1 && use_goto_tb(ctx, f)) {
68361766fe9SRichard Henderson         tcg_gen_goto_tb(which);
684a0180973SRichard Henderson         copy_iaoq_entry(ctx, cpu_iaoq_f, f, NULL);
685a0180973SRichard Henderson         copy_iaoq_entry(ctx, cpu_iaoq_b, b, NULL);
68607ea28b4SRichard Henderson         tcg_gen_exit_tb(ctx->base.tb, which);
68761766fe9SRichard Henderson     } else {
688741322f4SRichard Henderson         copy_iaoq_entry(ctx, cpu_iaoq_f, f, cpu_iaoq_b);
689741322f4SRichard Henderson         copy_iaoq_entry(ctx, cpu_iaoq_b, b, ctx->iaoq_n_var);
6907f11636dSEmilio G. Cota         tcg_gen_lookup_and_goto_ptr();
69161766fe9SRichard Henderson     }
69261766fe9SRichard Henderson }
69361766fe9SRichard Henderson 
694b47a4a02SSven Schnelle static bool cond_need_sv(int c)
695b47a4a02SSven Schnelle {
696b47a4a02SSven Schnelle     return c == 2 || c == 3 || c == 6;
697b47a4a02SSven Schnelle }
698b47a4a02SSven Schnelle 
699b47a4a02SSven Schnelle static bool cond_need_cb(int c)
700b47a4a02SSven Schnelle {
701b47a4a02SSven Schnelle     return c == 4 || c == 5;
702b47a4a02SSven Schnelle }
703b47a4a02SSven Schnelle 
704b47a4a02SSven Schnelle /*
705b47a4a02SSven Schnelle  * Compute conditional for arithmetic.  See Page 5-3, Table 5-1, of
706b47a4a02SSven Schnelle  * the Parisc 1.1 Architecture Reference Manual for details.
707b47a4a02SSven Schnelle  */
708b2167459SRichard Henderson 
709a751eb31SRichard Henderson static DisasCond do_cond(DisasContext *ctx, unsigned cf, bool d,
710fe2d066aSRichard Henderson                          TCGv_i64 res, TCGv_i64 uv, TCGv_i64 sv)
711b2167459SRichard Henderson {
712b2167459SRichard Henderson     DisasCond cond;
7136fd0c7bcSRichard Henderson     TCGv_i64 tmp;
714b2167459SRichard Henderson 
715b2167459SRichard Henderson     switch (cf >> 1) {
716b47a4a02SSven Schnelle     case 0: /* Never / TR    (0 / 1) */
717b2167459SRichard Henderson         cond = cond_make_f();
718b2167459SRichard Henderson         break;
719b2167459SRichard Henderson     case 1: /* = / <>        (Z / !Z) */
72082d0c831SRichard Henderson         if (!d) {
721aac0f603SRichard Henderson             tmp = tcg_temp_new_i64();
7226fd0c7bcSRichard Henderson             tcg_gen_ext32u_i64(tmp, res);
723a751eb31SRichard Henderson             res = tmp;
724a751eb31SRichard Henderson         }
725b2167459SRichard Henderson         cond = cond_make_0(TCG_COND_EQ, res);
726b2167459SRichard Henderson         break;
727b47a4a02SSven Schnelle     case 2: /* < / >=        (N ^ V / !(N ^ V) */
728aac0f603SRichard Henderson         tmp = tcg_temp_new_i64();
7296fd0c7bcSRichard Henderson         tcg_gen_xor_i64(tmp, res, sv);
73082d0c831SRichard Henderson         if (!d) {
7316fd0c7bcSRichard Henderson             tcg_gen_ext32s_i64(tmp, tmp);
732a751eb31SRichard Henderson         }
733b47a4a02SSven Schnelle         cond = cond_make_0_tmp(TCG_COND_LT, tmp);
734b2167459SRichard Henderson         break;
735b47a4a02SSven Schnelle     case 3: /* <= / >        (N ^ V) | Z / !((N ^ V) | Z) */
736b47a4a02SSven Schnelle         /*
737b47a4a02SSven Schnelle          * Simplify:
738b47a4a02SSven Schnelle          *   (N ^ V) | Z
739b47a4a02SSven Schnelle          *   ((res < 0) ^ (sv < 0)) | !res
740b47a4a02SSven Schnelle          *   ((res ^ sv) < 0) | !res
741b47a4a02SSven Schnelle          *   (~(res ^ sv) >= 0) | !res
742b47a4a02SSven Schnelle          *   !(~(res ^ sv) >> 31) | !res
743b47a4a02SSven Schnelle          *   !(~(res ^ sv) >> 31 & res)
744b47a4a02SSven Schnelle          */
745aac0f603SRichard Henderson         tmp = tcg_temp_new_i64();
7466fd0c7bcSRichard Henderson         tcg_gen_eqv_i64(tmp, res, sv);
74782d0c831SRichard Henderson         if (!d) {
7486fd0c7bcSRichard Henderson             tcg_gen_sextract_i64(tmp, tmp, 31, 1);
7496fd0c7bcSRichard Henderson             tcg_gen_and_i64(tmp, tmp, res);
7506fd0c7bcSRichard Henderson             tcg_gen_ext32u_i64(tmp, tmp);
751a751eb31SRichard Henderson         } else {
7526fd0c7bcSRichard Henderson             tcg_gen_sari_i64(tmp, tmp, 63);
7536fd0c7bcSRichard Henderson             tcg_gen_and_i64(tmp, tmp, res);
754a751eb31SRichard Henderson         }
755b47a4a02SSven Schnelle         cond = cond_make_0_tmp(TCG_COND_EQ, tmp);
756b2167459SRichard Henderson         break;
757fe2d066aSRichard Henderson     case 4: /* NUV / UV      (!UV / UV) */
758fe2d066aSRichard Henderson         cond = cond_make_0(TCG_COND_EQ, uv);
759b2167459SRichard Henderson         break;
760fe2d066aSRichard Henderson     case 5: /* ZNV / VNZ     (!UV | Z / UV & !Z) */
761aac0f603SRichard Henderson         tmp = tcg_temp_new_i64();
762fe2d066aSRichard Henderson         tcg_gen_movcond_i64(TCG_COND_EQ, tmp, uv, ctx->zero, ctx->zero, res);
76382d0c831SRichard Henderson         if (!d) {
7646fd0c7bcSRichard Henderson             tcg_gen_ext32u_i64(tmp, tmp);
765a751eb31SRichard Henderson         }
766b47a4a02SSven Schnelle         cond = cond_make_0_tmp(TCG_COND_EQ, tmp);
767b2167459SRichard Henderson         break;
768b2167459SRichard Henderson     case 6: /* SV / NSV      (V / !V) */
76982d0c831SRichard Henderson         if (!d) {
770aac0f603SRichard Henderson             tmp = tcg_temp_new_i64();
7716fd0c7bcSRichard Henderson             tcg_gen_ext32s_i64(tmp, sv);
772a751eb31SRichard Henderson             sv = tmp;
773a751eb31SRichard Henderson         }
774b2167459SRichard Henderson         cond = cond_make_0(TCG_COND_LT, sv);
775b2167459SRichard Henderson         break;
776b2167459SRichard Henderson     case 7: /* OD / EV */
777aac0f603SRichard Henderson         tmp = tcg_temp_new_i64();
7786fd0c7bcSRichard Henderson         tcg_gen_andi_i64(tmp, res, 1);
779b47a4a02SSven Schnelle         cond = cond_make_0_tmp(TCG_COND_NE, tmp);
780b2167459SRichard Henderson         break;
781b2167459SRichard Henderson     default:
782b2167459SRichard Henderson         g_assert_not_reached();
783b2167459SRichard Henderson     }
784b2167459SRichard Henderson     if (cf & 1) {
785b2167459SRichard Henderson         cond.c = tcg_invert_cond(cond.c);
786b2167459SRichard Henderson     }
787b2167459SRichard Henderson 
788b2167459SRichard Henderson     return cond;
789b2167459SRichard Henderson }
790b2167459SRichard Henderson 
791b2167459SRichard Henderson /* Similar, but for the special case of subtraction without borrow, we
792b2167459SRichard Henderson    can use the inputs directly.  This can allow other computation to be
793b2167459SRichard Henderson    deleted as unused.  */
794b2167459SRichard Henderson 
7954fe9533aSRichard Henderson static DisasCond do_sub_cond(DisasContext *ctx, unsigned cf, bool d,
7966fd0c7bcSRichard Henderson                              TCGv_i64 res, TCGv_i64 in1,
7976fd0c7bcSRichard Henderson                              TCGv_i64 in2, TCGv_i64 sv)
798b2167459SRichard Henderson {
7994fe9533aSRichard Henderson     TCGCond tc;
8004fe9533aSRichard Henderson     bool ext_uns;
801b2167459SRichard Henderson 
802b2167459SRichard Henderson     switch (cf >> 1) {
803b2167459SRichard Henderson     case 1: /* = / <> */
8044fe9533aSRichard Henderson         tc = TCG_COND_EQ;
8054fe9533aSRichard Henderson         ext_uns = true;
806b2167459SRichard Henderson         break;
807b2167459SRichard Henderson     case 2: /* < / >= */
8084fe9533aSRichard Henderson         tc = TCG_COND_LT;
8094fe9533aSRichard Henderson         ext_uns = false;
810b2167459SRichard Henderson         break;
811b2167459SRichard Henderson     case 3: /* <= / > */
8124fe9533aSRichard Henderson         tc = TCG_COND_LE;
8134fe9533aSRichard Henderson         ext_uns = false;
814b2167459SRichard Henderson         break;
815b2167459SRichard Henderson     case 4: /* << / >>= */
8164fe9533aSRichard Henderson         tc = TCG_COND_LTU;
8174fe9533aSRichard Henderson         ext_uns = true;
818b2167459SRichard Henderson         break;
819b2167459SRichard Henderson     case 5: /* <<= / >> */
8204fe9533aSRichard Henderson         tc = TCG_COND_LEU;
8214fe9533aSRichard Henderson         ext_uns = true;
822b2167459SRichard Henderson         break;
823b2167459SRichard Henderson     default:
824a751eb31SRichard Henderson         return do_cond(ctx, cf, d, res, NULL, sv);
825b2167459SRichard Henderson     }
826b2167459SRichard Henderson 
8274fe9533aSRichard Henderson     if (cf & 1) {
8284fe9533aSRichard Henderson         tc = tcg_invert_cond(tc);
8294fe9533aSRichard Henderson     }
83082d0c831SRichard Henderson     if (!d) {
831aac0f603SRichard Henderson         TCGv_i64 t1 = tcg_temp_new_i64();
832aac0f603SRichard Henderson         TCGv_i64 t2 = tcg_temp_new_i64();
8334fe9533aSRichard Henderson 
8344fe9533aSRichard Henderson         if (ext_uns) {
8356fd0c7bcSRichard Henderson             tcg_gen_ext32u_i64(t1, in1);
8366fd0c7bcSRichard Henderson             tcg_gen_ext32u_i64(t2, in2);
8374fe9533aSRichard Henderson         } else {
8386fd0c7bcSRichard Henderson             tcg_gen_ext32s_i64(t1, in1);
8396fd0c7bcSRichard Henderson             tcg_gen_ext32s_i64(t2, in2);
8404fe9533aSRichard Henderson         }
8414fe9533aSRichard Henderson         return cond_make_tmp(tc, t1, t2);
8424fe9533aSRichard Henderson     }
8434fe9533aSRichard Henderson     return cond_make(tc, in1, in2);
844b2167459SRichard Henderson }
845b2167459SRichard Henderson 
846df0232feSRichard Henderson /*
847df0232feSRichard Henderson  * Similar, but for logicals, where the carry and overflow bits are not
848df0232feSRichard Henderson  * computed, and use of them is undefined.
849df0232feSRichard Henderson  *
850df0232feSRichard Henderson  * Undefined or not, hardware does not trap.  It seems reasonable to
851df0232feSRichard Henderson  * assume hardware treats cases c={4,5,6} as if C=0 & V=0, since that's
852df0232feSRichard Henderson  * how cases c={2,3} are treated.
853df0232feSRichard Henderson  */
854b2167459SRichard Henderson 
855b5af8423SRichard Henderson static DisasCond do_log_cond(DisasContext *ctx, unsigned cf, bool d,
8566fd0c7bcSRichard Henderson                              TCGv_i64 res)
857b2167459SRichard Henderson {
858b5af8423SRichard Henderson     TCGCond tc;
859b5af8423SRichard Henderson     bool ext_uns;
860a751eb31SRichard Henderson 
861df0232feSRichard Henderson     switch (cf) {
862df0232feSRichard Henderson     case 0:  /* never */
863df0232feSRichard Henderson     case 9:  /* undef, C */
864df0232feSRichard Henderson     case 11: /* undef, C & !Z */
865df0232feSRichard Henderson     case 12: /* undef, V */
866df0232feSRichard Henderson         return cond_make_f();
867df0232feSRichard Henderson 
868df0232feSRichard Henderson     case 1:  /* true */
869df0232feSRichard Henderson     case 8:  /* undef, !C */
870df0232feSRichard Henderson     case 10: /* undef, !C | Z */
871df0232feSRichard Henderson     case 13: /* undef, !V */
872df0232feSRichard Henderson         return cond_make_t();
873df0232feSRichard Henderson 
874df0232feSRichard Henderson     case 2:  /* == */
875b5af8423SRichard Henderson         tc = TCG_COND_EQ;
876b5af8423SRichard Henderson         ext_uns = true;
877b5af8423SRichard Henderson         break;
878df0232feSRichard Henderson     case 3:  /* <> */
879b5af8423SRichard Henderson         tc = TCG_COND_NE;
880b5af8423SRichard Henderson         ext_uns = true;
881b5af8423SRichard Henderson         break;
882df0232feSRichard Henderson     case 4:  /* < */
883b5af8423SRichard Henderson         tc = TCG_COND_LT;
884b5af8423SRichard Henderson         ext_uns = false;
885b5af8423SRichard Henderson         break;
886df0232feSRichard Henderson     case 5:  /* >= */
887b5af8423SRichard Henderson         tc = TCG_COND_GE;
888b5af8423SRichard Henderson         ext_uns = false;
889b5af8423SRichard Henderson         break;
890df0232feSRichard Henderson     case 6:  /* <= */
891b5af8423SRichard Henderson         tc = TCG_COND_LE;
892b5af8423SRichard Henderson         ext_uns = false;
893b5af8423SRichard Henderson         break;
894df0232feSRichard Henderson     case 7:  /* > */
895b5af8423SRichard Henderson         tc = TCG_COND_GT;
896b5af8423SRichard Henderson         ext_uns = false;
897b5af8423SRichard Henderson         break;
898df0232feSRichard Henderson 
899df0232feSRichard Henderson     case 14: /* OD */
900df0232feSRichard Henderson     case 15: /* EV */
901a751eb31SRichard Henderson         return do_cond(ctx, cf, d, res, NULL, NULL);
902df0232feSRichard Henderson 
903df0232feSRichard Henderson     default:
904df0232feSRichard Henderson         g_assert_not_reached();
905b2167459SRichard Henderson     }
906b5af8423SRichard Henderson 
90782d0c831SRichard Henderson     if (!d) {
908aac0f603SRichard Henderson         TCGv_i64 tmp = tcg_temp_new_i64();
909b5af8423SRichard Henderson 
910b5af8423SRichard Henderson         if (ext_uns) {
9116fd0c7bcSRichard Henderson             tcg_gen_ext32u_i64(tmp, res);
912b5af8423SRichard Henderson         } else {
9136fd0c7bcSRichard Henderson             tcg_gen_ext32s_i64(tmp, res);
914b5af8423SRichard Henderson         }
915b5af8423SRichard Henderson         return cond_make_0_tmp(tc, tmp);
916b5af8423SRichard Henderson     }
917b5af8423SRichard Henderson     return cond_make_0(tc, res);
918b2167459SRichard Henderson }
919b2167459SRichard Henderson 
92098cd9ca7SRichard Henderson /* Similar, but for shift/extract/deposit conditions.  */
92198cd9ca7SRichard Henderson 
9224fa52edfSRichard Henderson static DisasCond do_sed_cond(DisasContext *ctx, unsigned orig, bool d,
9236fd0c7bcSRichard Henderson                              TCGv_i64 res)
92498cd9ca7SRichard Henderson {
92598cd9ca7SRichard Henderson     unsigned c, f;
92698cd9ca7SRichard Henderson 
92798cd9ca7SRichard Henderson     /* Convert the compressed condition codes to standard.
92898cd9ca7SRichard Henderson        0-2 are the same as logicals (nv,<,<=), while 3 is OD.
92998cd9ca7SRichard Henderson        4-7 are the reverse of 0-3.  */
93098cd9ca7SRichard Henderson     c = orig & 3;
93198cd9ca7SRichard Henderson     if (c == 3) {
93298cd9ca7SRichard Henderson         c = 7;
93398cd9ca7SRichard Henderson     }
93498cd9ca7SRichard Henderson     f = (orig & 4) / 4;
93598cd9ca7SRichard Henderson 
936b5af8423SRichard Henderson     return do_log_cond(ctx, c * 2 + f, d, res);
93798cd9ca7SRichard Henderson }
93898cd9ca7SRichard Henderson 
93946bb3d46SRichard Henderson /* Similar, but for unit zero conditions.  */
94046bb3d46SRichard Henderson static DisasCond do_unit_zero_cond(unsigned cf, bool d, TCGv_i64 res)
941b2167459SRichard Henderson {
94246bb3d46SRichard Henderson     TCGv_i64 tmp;
943c53e401eSRichard Henderson     uint64_t d_repl = d ? 0x0000000100000001ull : 1;
94446bb3d46SRichard Henderson     uint64_t ones = 0, sgns = 0;
945b2167459SRichard Henderson 
946b2167459SRichard Henderson     switch (cf >> 1) {
947578b8132SSven Schnelle     case 1: /* SBW / NBW */
948578b8132SSven Schnelle         if (d) {
94946bb3d46SRichard Henderson             ones = d_repl;
95046bb3d46SRichard Henderson             sgns = d_repl << 31;
951578b8132SSven Schnelle         }
952578b8132SSven Schnelle         break;
953b2167459SRichard Henderson     case 2: /* SBZ / NBZ */
95446bb3d46SRichard Henderson         ones = d_repl * 0x01010101u;
95546bb3d46SRichard Henderson         sgns = ones << 7;
95646bb3d46SRichard Henderson         break;
95746bb3d46SRichard Henderson     case 3: /* SHZ / NHZ */
95846bb3d46SRichard Henderson         ones = d_repl * 0x00010001u;
95946bb3d46SRichard Henderson         sgns = ones << 15;
96046bb3d46SRichard Henderson         break;
96146bb3d46SRichard Henderson     }
96246bb3d46SRichard Henderson     if (ones == 0) {
96346bb3d46SRichard Henderson         /* Undefined, or 0/1 (never/always). */
96446bb3d46SRichard Henderson         return cf & 1 ? cond_make_t() : cond_make_f();
96546bb3d46SRichard Henderson     }
96646bb3d46SRichard Henderson 
96746bb3d46SRichard Henderson     /*
96846bb3d46SRichard Henderson      * See hasless(v,1) from
969b2167459SRichard Henderson      * https://graphics.stanford.edu/~seander/bithacks.html#ZeroInWord
970b2167459SRichard Henderson      */
971aac0f603SRichard Henderson     tmp = tcg_temp_new_i64();
97246bb3d46SRichard Henderson     tcg_gen_subi_i64(tmp, res, ones);
9736fd0c7bcSRichard Henderson     tcg_gen_andc_i64(tmp, tmp, res);
97446bb3d46SRichard Henderson     tcg_gen_andi_i64(tmp, tmp, sgns);
975b2167459SRichard Henderson 
97646bb3d46SRichard Henderson     return cond_make_0_tmp(cf & 1 ? TCG_COND_EQ : TCG_COND_NE, tmp);
977b2167459SRichard Henderson }
978b2167459SRichard Henderson 
9796fd0c7bcSRichard Henderson static TCGv_i64 get_carry(DisasContext *ctx, bool d,
9806fd0c7bcSRichard Henderson                           TCGv_i64 cb, TCGv_i64 cb_msb)
98172ca8753SRichard Henderson {
98282d0c831SRichard Henderson     if (!d) {
983aac0f603SRichard Henderson         TCGv_i64 t = tcg_temp_new_i64();
9846fd0c7bcSRichard Henderson         tcg_gen_extract_i64(t, cb, 32, 1);
98572ca8753SRichard Henderson         return t;
98672ca8753SRichard Henderson     }
98772ca8753SRichard Henderson     return cb_msb;
98872ca8753SRichard Henderson }
98972ca8753SRichard Henderson 
9906fd0c7bcSRichard Henderson static TCGv_i64 get_psw_carry(DisasContext *ctx, bool d)
99172ca8753SRichard Henderson {
99272ca8753SRichard Henderson     return get_carry(ctx, d, cpu_psw_cb, cpu_psw_cb_msb);
99372ca8753SRichard Henderson }
99472ca8753SRichard Henderson 
995b2167459SRichard Henderson /* Compute signed overflow for addition.  */
9966fd0c7bcSRichard Henderson static TCGv_i64 do_add_sv(DisasContext *ctx, TCGv_i64 res,
997f8f5986eSRichard Henderson                           TCGv_i64 in1, TCGv_i64 in2,
998f8f5986eSRichard Henderson                           TCGv_i64 orig_in1, int shift, bool d)
999b2167459SRichard Henderson {
1000aac0f603SRichard Henderson     TCGv_i64 sv = tcg_temp_new_i64();
1001aac0f603SRichard Henderson     TCGv_i64 tmp = tcg_temp_new_i64();
1002b2167459SRichard Henderson 
10036fd0c7bcSRichard Henderson     tcg_gen_xor_i64(sv, res, in1);
10046fd0c7bcSRichard Henderson     tcg_gen_xor_i64(tmp, in1, in2);
10056fd0c7bcSRichard Henderson     tcg_gen_andc_i64(sv, sv, tmp);
1006b2167459SRichard Henderson 
1007f8f5986eSRichard Henderson     switch (shift) {
1008f8f5986eSRichard Henderson     case 0:
1009f8f5986eSRichard Henderson         break;
1010f8f5986eSRichard Henderson     case 1:
1011f8f5986eSRichard Henderson         /* Shift left by one and compare the sign. */
1012f8f5986eSRichard Henderson         tcg_gen_add_i64(tmp, orig_in1, orig_in1);
1013f8f5986eSRichard Henderson         tcg_gen_xor_i64(tmp, tmp, orig_in1);
1014f8f5986eSRichard Henderson         /* Incorporate into the overflow. */
1015f8f5986eSRichard Henderson         tcg_gen_or_i64(sv, sv, tmp);
1016f8f5986eSRichard Henderson         break;
1017f8f5986eSRichard Henderson     default:
1018f8f5986eSRichard Henderson         {
1019f8f5986eSRichard Henderson             int sign_bit = d ? 63 : 31;
1020f8f5986eSRichard Henderson 
1021f8f5986eSRichard Henderson             /* Compare the sign against all lower bits. */
1022f8f5986eSRichard Henderson             tcg_gen_sextract_i64(tmp, orig_in1, sign_bit, 1);
1023f8f5986eSRichard Henderson             tcg_gen_xor_i64(tmp, tmp, orig_in1);
1024f8f5986eSRichard Henderson             /*
1025f8f5986eSRichard Henderson              * If one of the bits shifting into or through the sign
1026f8f5986eSRichard Henderson              * differs, then we have overflow.
1027f8f5986eSRichard Henderson              */
1028f8f5986eSRichard Henderson             tcg_gen_extract_i64(tmp, tmp, sign_bit - shift, shift);
1029f8f5986eSRichard Henderson             tcg_gen_movcond_i64(TCG_COND_NE, sv, tmp, ctx->zero,
1030f8f5986eSRichard Henderson                                 tcg_constant_i64(-1), sv);
1031f8f5986eSRichard Henderson         }
1032f8f5986eSRichard Henderson     }
1033b2167459SRichard Henderson     return sv;
1034b2167459SRichard Henderson }
1035b2167459SRichard Henderson 
1036f8f5986eSRichard Henderson /* Compute unsigned overflow for addition.  */
1037f8f5986eSRichard Henderson static TCGv_i64 do_add_uv(DisasContext *ctx, TCGv_i64 cb, TCGv_i64 cb_msb,
1038f8f5986eSRichard Henderson                           TCGv_i64 in1, int shift, bool d)
1039f8f5986eSRichard Henderson {
1040f8f5986eSRichard Henderson     if (shift == 0) {
1041f8f5986eSRichard Henderson         return get_carry(ctx, d, cb, cb_msb);
1042f8f5986eSRichard Henderson     } else {
1043f8f5986eSRichard Henderson         TCGv_i64 tmp = tcg_temp_new_i64();
1044f8f5986eSRichard Henderson         tcg_gen_extract_i64(tmp, in1, (d ? 63 : 31) - shift, shift);
1045f8f5986eSRichard Henderson         tcg_gen_or_i64(tmp, tmp, get_carry(ctx, d, cb, cb_msb));
1046f8f5986eSRichard Henderson         return tmp;
1047f8f5986eSRichard Henderson     }
1048f8f5986eSRichard Henderson }
1049f8f5986eSRichard Henderson 
1050b2167459SRichard Henderson /* Compute signed overflow for subtraction.  */
10516fd0c7bcSRichard Henderson static TCGv_i64 do_sub_sv(DisasContext *ctx, TCGv_i64 res,
10526fd0c7bcSRichard Henderson                           TCGv_i64 in1, TCGv_i64 in2)
1053b2167459SRichard Henderson {
1054aac0f603SRichard Henderson     TCGv_i64 sv = tcg_temp_new_i64();
1055aac0f603SRichard Henderson     TCGv_i64 tmp = tcg_temp_new_i64();
1056b2167459SRichard Henderson 
10576fd0c7bcSRichard Henderson     tcg_gen_xor_i64(sv, res, in1);
10586fd0c7bcSRichard Henderson     tcg_gen_xor_i64(tmp, in1, in2);
10596fd0c7bcSRichard Henderson     tcg_gen_and_i64(sv, sv, tmp);
1060b2167459SRichard Henderson 
1061b2167459SRichard Henderson     return sv;
1062b2167459SRichard Henderson }
1063b2167459SRichard Henderson 
1064f8f5986eSRichard Henderson static void do_add(DisasContext *ctx, unsigned rt, TCGv_i64 orig_in1,
10656fd0c7bcSRichard Henderson                    TCGv_i64 in2, unsigned shift, bool is_l,
1066faf97ba1SRichard Henderson                    bool is_tsv, bool is_tc, bool is_c, unsigned cf, bool d)
1067b2167459SRichard Henderson {
1068f8f5986eSRichard Henderson     TCGv_i64 dest, cb, cb_msb, in1, uv, sv, tmp;
1069b2167459SRichard Henderson     unsigned c = cf >> 1;
1070b2167459SRichard Henderson     DisasCond cond;
1071b2167459SRichard Henderson 
1072aac0f603SRichard Henderson     dest = tcg_temp_new_i64();
1073f764718dSRichard Henderson     cb = NULL;
1074f764718dSRichard Henderson     cb_msb = NULL;
1075b2167459SRichard Henderson 
1076f8f5986eSRichard Henderson     in1 = orig_in1;
1077b2167459SRichard Henderson     if (shift) {
1078aac0f603SRichard Henderson         tmp = tcg_temp_new_i64();
10796fd0c7bcSRichard Henderson         tcg_gen_shli_i64(tmp, in1, shift);
1080b2167459SRichard Henderson         in1 = tmp;
1081b2167459SRichard Henderson     }
1082b2167459SRichard Henderson 
1083b47a4a02SSven Schnelle     if (!is_l || cond_need_cb(c)) {
1084aac0f603SRichard Henderson         cb_msb = tcg_temp_new_i64();
1085aac0f603SRichard Henderson         cb = tcg_temp_new_i64();
1086bdcccc17SRichard Henderson 
1087a4db4a78SRichard Henderson         tcg_gen_add2_i64(dest, cb_msb, in1, ctx->zero, in2, ctx->zero);
1088b2167459SRichard Henderson         if (is_c) {
10896fd0c7bcSRichard Henderson             tcg_gen_add2_i64(dest, cb_msb, dest, cb_msb,
1090a4db4a78SRichard Henderson                              get_psw_carry(ctx, d), ctx->zero);
1091b2167459SRichard Henderson         }
10926fd0c7bcSRichard Henderson         tcg_gen_xor_i64(cb, in1, in2);
10936fd0c7bcSRichard Henderson         tcg_gen_xor_i64(cb, cb, dest);
1094b2167459SRichard Henderson     } else {
10956fd0c7bcSRichard Henderson         tcg_gen_add_i64(dest, in1, in2);
1096b2167459SRichard Henderson         if (is_c) {
10976fd0c7bcSRichard Henderson             tcg_gen_add_i64(dest, dest, get_psw_carry(ctx, d));
1098b2167459SRichard Henderson         }
1099b2167459SRichard Henderson     }
1100b2167459SRichard Henderson 
1101b2167459SRichard Henderson     /* Compute signed overflow if required.  */
1102f764718dSRichard Henderson     sv = NULL;
1103b47a4a02SSven Schnelle     if (is_tsv || cond_need_sv(c)) {
1104f8f5986eSRichard Henderson         sv = do_add_sv(ctx, dest, in1, in2, orig_in1, shift, d);
1105b2167459SRichard Henderson         if (is_tsv) {
1106bd1ad92cSSven Schnelle             if (!d) {
1107bd1ad92cSSven Schnelle                 tcg_gen_ext32s_i64(sv, sv);
1108bd1ad92cSSven Schnelle             }
1109ad75a51eSRichard Henderson             gen_helper_tsv(tcg_env, sv);
1110b2167459SRichard Henderson         }
1111b2167459SRichard Henderson     }
1112b2167459SRichard Henderson 
1113f8f5986eSRichard Henderson     /* Compute unsigned overflow if required.  */
1114f8f5986eSRichard Henderson     uv = NULL;
1115f8f5986eSRichard Henderson     if (cond_need_cb(c)) {
1116f8f5986eSRichard Henderson         uv = do_add_uv(ctx, cb, cb_msb, orig_in1, shift, d);
1117f8f5986eSRichard Henderson     }
1118f8f5986eSRichard Henderson 
1119b2167459SRichard Henderson     /* Emit any conditional trap before any writeback.  */
1120f8f5986eSRichard Henderson     cond = do_cond(ctx, cf, d, dest, uv, sv);
1121b2167459SRichard Henderson     if (is_tc) {
1122aac0f603SRichard Henderson         tmp = tcg_temp_new_i64();
11236fd0c7bcSRichard Henderson         tcg_gen_setcond_i64(cond.c, tmp, cond.a0, cond.a1);
1124ad75a51eSRichard Henderson         gen_helper_tcond(tcg_env, tmp);
1125b2167459SRichard Henderson     }
1126b2167459SRichard Henderson 
1127b2167459SRichard Henderson     /* Write back the result.  */
1128b2167459SRichard Henderson     if (!is_l) {
1129b2167459SRichard Henderson         save_or_nullify(ctx, cpu_psw_cb, cb);
1130b2167459SRichard Henderson         save_or_nullify(ctx, cpu_psw_cb_msb, cb_msb);
1131b2167459SRichard Henderson     }
1132b2167459SRichard Henderson     save_gpr(ctx, rt, dest);
1133b2167459SRichard Henderson 
1134b2167459SRichard Henderson     /* Install the new nullification.  */
1135b2167459SRichard Henderson     cond_free(&ctx->null_cond);
1136b2167459SRichard Henderson     ctx->null_cond = cond;
1137b2167459SRichard Henderson }
1138b2167459SRichard Henderson 
1139faf97ba1SRichard Henderson static bool do_add_reg(DisasContext *ctx, arg_rrr_cf_d_sh *a,
11400c982a28SRichard Henderson                        bool is_l, bool is_tsv, bool is_tc, bool is_c)
11410c982a28SRichard Henderson {
11426fd0c7bcSRichard Henderson     TCGv_i64 tcg_r1, tcg_r2;
11430c982a28SRichard Henderson 
11440c982a28SRichard Henderson     if (a->cf) {
11450c982a28SRichard Henderson         nullify_over(ctx);
11460c982a28SRichard Henderson     }
11470c982a28SRichard Henderson     tcg_r1 = load_gpr(ctx, a->r1);
11480c982a28SRichard Henderson     tcg_r2 = load_gpr(ctx, a->r2);
1149faf97ba1SRichard Henderson     do_add(ctx, a->t, tcg_r1, tcg_r2, a->sh, is_l,
1150faf97ba1SRichard Henderson            is_tsv, is_tc, is_c, a->cf, a->d);
11510c982a28SRichard Henderson     return nullify_end(ctx);
11520c982a28SRichard Henderson }
11530c982a28SRichard Henderson 
11540588e061SRichard Henderson static bool do_add_imm(DisasContext *ctx, arg_rri_cf *a,
11550588e061SRichard Henderson                        bool is_tsv, bool is_tc)
11560588e061SRichard Henderson {
11576fd0c7bcSRichard Henderson     TCGv_i64 tcg_im, tcg_r2;
11580588e061SRichard Henderson 
11590588e061SRichard Henderson     if (a->cf) {
11600588e061SRichard Henderson         nullify_over(ctx);
11610588e061SRichard Henderson     }
11626fd0c7bcSRichard Henderson     tcg_im = tcg_constant_i64(a->i);
11630588e061SRichard Henderson     tcg_r2 = load_gpr(ctx, a->r);
1164faf97ba1SRichard Henderson     /* All ADDI conditions are 32-bit. */
1165faf97ba1SRichard Henderson     do_add(ctx, a->t, tcg_im, tcg_r2, 0, 0, is_tsv, is_tc, 0, a->cf, false);
11660588e061SRichard Henderson     return nullify_end(ctx);
11670588e061SRichard Henderson }
11680588e061SRichard Henderson 
11696fd0c7bcSRichard Henderson static void do_sub(DisasContext *ctx, unsigned rt, TCGv_i64 in1,
11706fd0c7bcSRichard Henderson                    TCGv_i64 in2, bool is_tsv, bool is_b,
117163c427c6SRichard Henderson                    bool is_tc, unsigned cf, bool d)
1172b2167459SRichard Henderson {
1173a4db4a78SRichard Henderson     TCGv_i64 dest, sv, cb, cb_msb, tmp;
1174b2167459SRichard Henderson     unsigned c = cf >> 1;
1175b2167459SRichard Henderson     DisasCond cond;
1176b2167459SRichard Henderson 
1177aac0f603SRichard Henderson     dest = tcg_temp_new_i64();
1178aac0f603SRichard Henderson     cb = tcg_temp_new_i64();
1179aac0f603SRichard Henderson     cb_msb = tcg_temp_new_i64();
1180b2167459SRichard Henderson 
1181b2167459SRichard Henderson     if (is_b) {
1182b2167459SRichard Henderson         /* DEST,C = IN1 + ~IN2 + C.  */
11836fd0c7bcSRichard Henderson         tcg_gen_not_i64(cb, in2);
1184a4db4a78SRichard Henderson         tcg_gen_add2_i64(dest, cb_msb, in1, ctx->zero,
1185a4db4a78SRichard Henderson                          get_psw_carry(ctx, d), ctx->zero);
1186a4db4a78SRichard Henderson         tcg_gen_add2_i64(dest, cb_msb, dest, cb_msb, cb, ctx->zero);
11876fd0c7bcSRichard Henderson         tcg_gen_xor_i64(cb, cb, in1);
11886fd0c7bcSRichard Henderson         tcg_gen_xor_i64(cb, cb, dest);
1189b2167459SRichard Henderson     } else {
1190bdcccc17SRichard Henderson         /*
1191bdcccc17SRichard Henderson          * DEST,C = IN1 + ~IN2 + 1.  We can produce the same result in fewer
1192bdcccc17SRichard Henderson          * operations by seeding the high word with 1 and subtracting.
1193bdcccc17SRichard Henderson          */
11946fd0c7bcSRichard Henderson         TCGv_i64 one = tcg_constant_i64(1);
1195a4db4a78SRichard Henderson         tcg_gen_sub2_i64(dest, cb_msb, in1, one, in2, ctx->zero);
11966fd0c7bcSRichard Henderson         tcg_gen_eqv_i64(cb, in1, in2);
11976fd0c7bcSRichard Henderson         tcg_gen_xor_i64(cb, cb, dest);
1198b2167459SRichard Henderson     }
1199b2167459SRichard Henderson 
1200b2167459SRichard Henderson     /* Compute signed overflow if required.  */
1201f764718dSRichard Henderson     sv = NULL;
1202b47a4a02SSven Schnelle     if (is_tsv || cond_need_sv(c)) {
1203b2167459SRichard Henderson         sv = do_sub_sv(ctx, dest, in1, in2);
1204b2167459SRichard Henderson         if (is_tsv) {
1205bd1ad92cSSven Schnelle             if (!d) {
1206bd1ad92cSSven Schnelle                 tcg_gen_ext32s_i64(sv, sv);
1207bd1ad92cSSven Schnelle             }
1208ad75a51eSRichard Henderson             gen_helper_tsv(tcg_env, sv);
1209b2167459SRichard Henderson         }
1210b2167459SRichard Henderson     }
1211b2167459SRichard Henderson 
1212b2167459SRichard Henderson     /* Compute the condition.  We cannot use the special case for borrow.  */
1213b2167459SRichard Henderson     if (!is_b) {
12144fe9533aSRichard Henderson         cond = do_sub_cond(ctx, cf, d, dest, in1, in2, sv);
1215b2167459SRichard Henderson     } else {
1216a751eb31SRichard Henderson         cond = do_cond(ctx, cf, d, dest, get_carry(ctx, d, cb, cb_msb), sv);
1217b2167459SRichard Henderson     }
1218b2167459SRichard Henderson 
1219b2167459SRichard Henderson     /* Emit any conditional trap before any writeback.  */
1220b2167459SRichard Henderson     if (is_tc) {
1221aac0f603SRichard Henderson         tmp = tcg_temp_new_i64();
12226fd0c7bcSRichard Henderson         tcg_gen_setcond_i64(cond.c, tmp, cond.a0, cond.a1);
1223ad75a51eSRichard Henderson         gen_helper_tcond(tcg_env, tmp);
1224b2167459SRichard Henderson     }
1225b2167459SRichard Henderson 
1226b2167459SRichard Henderson     /* Write back the result.  */
1227b2167459SRichard Henderson     save_or_nullify(ctx, cpu_psw_cb, cb);
1228b2167459SRichard Henderson     save_or_nullify(ctx, cpu_psw_cb_msb, cb_msb);
1229b2167459SRichard Henderson     save_gpr(ctx, rt, dest);
1230b2167459SRichard Henderson 
1231b2167459SRichard Henderson     /* Install the new nullification.  */
1232b2167459SRichard Henderson     cond_free(&ctx->null_cond);
1233b2167459SRichard Henderson     ctx->null_cond = cond;
1234b2167459SRichard Henderson }
1235b2167459SRichard Henderson 
123663c427c6SRichard Henderson static bool do_sub_reg(DisasContext *ctx, arg_rrr_cf_d *a,
12370c982a28SRichard Henderson                        bool is_tsv, bool is_b, bool is_tc)
12380c982a28SRichard Henderson {
12396fd0c7bcSRichard Henderson     TCGv_i64 tcg_r1, tcg_r2;
12400c982a28SRichard Henderson 
12410c982a28SRichard Henderson     if (a->cf) {
12420c982a28SRichard Henderson         nullify_over(ctx);
12430c982a28SRichard Henderson     }
12440c982a28SRichard Henderson     tcg_r1 = load_gpr(ctx, a->r1);
12450c982a28SRichard Henderson     tcg_r2 = load_gpr(ctx, a->r2);
124663c427c6SRichard Henderson     do_sub(ctx, a->t, tcg_r1, tcg_r2, is_tsv, is_b, is_tc, a->cf, a->d);
12470c982a28SRichard Henderson     return nullify_end(ctx);
12480c982a28SRichard Henderson }
12490c982a28SRichard Henderson 
12500588e061SRichard Henderson static bool do_sub_imm(DisasContext *ctx, arg_rri_cf *a, bool is_tsv)
12510588e061SRichard Henderson {
12526fd0c7bcSRichard Henderson     TCGv_i64 tcg_im, tcg_r2;
12530588e061SRichard Henderson 
12540588e061SRichard Henderson     if (a->cf) {
12550588e061SRichard Henderson         nullify_over(ctx);
12560588e061SRichard Henderson     }
12576fd0c7bcSRichard Henderson     tcg_im = tcg_constant_i64(a->i);
12580588e061SRichard Henderson     tcg_r2 = load_gpr(ctx, a->r);
125963c427c6SRichard Henderson     /* All SUBI conditions are 32-bit. */
126063c427c6SRichard Henderson     do_sub(ctx, a->t, tcg_im, tcg_r2, is_tsv, 0, 0, a->cf, false);
12610588e061SRichard Henderson     return nullify_end(ctx);
12620588e061SRichard Henderson }
12630588e061SRichard Henderson 
12646fd0c7bcSRichard Henderson static void do_cmpclr(DisasContext *ctx, unsigned rt, TCGv_i64 in1,
12656fd0c7bcSRichard Henderson                       TCGv_i64 in2, unsigned cf, bool d)
1266b2167459SRichard Henderson {
12676fd0c7bcSRichard Henderson     TCGv_i64 dest, sv;
1268b2167459SRichard Henderson     DisasCond cond;
1269b2167459SRichard Henderson 
1270aac0f603SRichard Henderson     dest = tcg_temp_new_i64();
12716fd0c7bcSRichard Henderson     tcg_gen_sub_i64(dest, in1, in2);
1272b2167459SRichard Henderson 
1273b2167459SRichard Henderson     /* Compute signed overflow if required.  */
1274f764718dSRichard Henderson     sv = NULL;
1275b47a4a02SSven Schnelle     if (cond_need_sv(cf >> 1)) {
1276b2167459SRichard Henderson         sv = do_sub_sv(ctx, dest, in1, in2);
1277b2167459SRichard Henderson     }
1278b2167459SRichard Henderson 
1279b2167459SRichard Henderson     /* Form the condition for the compare.  */
12804fe9533aSRichard Henderson     cond = do_sub_cond(ctx, cf, d, dest, in1, in2, sv);
1281b2167459SRichard Henderson 
1282b2167459SRichard Henderson     /* Clear.  */
12836fd0c7bcSRichard Henderson     tcg_gen_movi_i64(dest, 0);
1284b2167459SRichard Henderson     save_gpr(ctx, rt, dest);
1285b2167459SRichard Henderson 
1286b2167459SRichard Henderson     /* Install the new nullification.  */
1287b2167459SRichard Henderson     cond_free(&ctx->null_cond);
1288b2167459SRichard Henderson     ctx->null_cond = cond;
1289b2167459SRichard Henderson }
1290b2167459SRichard Henderson 
12916fd0c7bcSRichard Henderson static void do_log(DisasContext *ctx, unsigned rt, TCGv_i64 in1,
12926fd0c7bcSRichard Henderson                    TCGv_i64 in2, unsigned cf, bool d,
12936fd0c7bcSRichard Henderson                    void (*fn)(TCGv_i64, TCGv_i64, TCGv_i64))
1294b2167459SRichard Henderson {
12956fd0c7bcSRichard Henderson     TCGv_i64 dest = dest_gpr(ctx, rt);
1296b2167459SRichard Henderson 
1297b2167459SRichard Henderson     /* Perform the operation, and writeback.  */
1298b2167459SRichard Henderson     fn(dest, in1, in2);
1299b2167459SRichard Henderson     save_gpr(ctx, rt, dest);
1300b2167459SRichard Henderson 
1301b2167459SRichard Henderson     /* Install the new nullification.  */
1302b2167459SRichard Henderson     cond_free(&ctx->null_cond);
1303b2167459SRichard Henderson     if (cf) {
1304b5af8423SRichard Henderson         ctx->null_cond = do_log_cond(ctx, cf, d, dest);
1305b2167459SRichard Henderson     }
1306b2167459SRichard Henderson }
1307b2167459SRichard Henderson 
1308fa8e3bedSRichard Henderson static bool do_log_reg(DisasContext *ctx, arg_rrr_cf_d *a,
13096fd0c7bcSRichard Henderson                        void (*fn)(TCGv_i64, TCGv_i64, TCGv_i64))
13100c982a28SRichard Henderson {
13116fd0c7bcSRichard Henderson     TCGv_i64 tcg_r1, tcg_r2;
13120c982a28SRichard Henderson 
13130c982a28SRichard Henderson     if (a->cf) {
13140c982a28SRichard Henderson         nullify_over(ctx);
13150c982a28SRichard Henderson     }
13160c982a28SRichard Henderson     tcg_r1 = load_gpr(ctx, a->r1);
13170c982a28SRichard Henderson     tcg_r2 = load_gpr(ctx, a->r2);
1318fa8e3bedSRichard Henderson     do_log(ctx, a->t, tcg_r1, tcg_r2, a->cf, a->d, fn);
13190c982a28SRichard Henderson     return nullify_end(ctx);
13200c982a28SRichard Henderson }
13210c982a28SRichard Henderson 
132246bb3d46SRichard Henderson static void do_unit_addsub(DisasContext *ctx, unsigned rt, TCGv_i64 in1,
132346bb3d46SRichard Henderson                            TCGv_i64 in2, unsigned cf, bool d,
132446bb3d46SRichard Henderson                            bool is_tc, bool is_add)
1325b2167459SRichard Henderson {
132646bb3d46SRichard Henderson     TCGv_i64 dest = tcg_temp_new_i64();
132746bb3d46SRichard Henderson     uint64_t test_cb = 0;
1328b2167459SRichard Henderson     DisasCond cond;
1329b2167459SRichard Henderson 
133046bb3d46SRichard Henderson     /* Select which carry-out bits to test. */
133146bb3d46SRichard Henderson     switch (cf >> 1) {
133246bb3d46SRichard Henderson     case 4: /* NDC / SDC -- 4-bit carries */
133346bb3d46SRichard Henderson         test_cb = dup_const(MO_8, 0x88);
133446bb3d46SRichard Henderson         break;
133546bb3d46SRichard Henderson     case 5: /* NWC / SWC -- 32-bit carries */
133646bb3d46SRichard Henderson         if (d) {
133746bb3d46SRichard Henderson             test_cb = dup_const(MO_32, INT32_MIN);
1338b2167459SRichard Henderson         } else {
133946bb3d46SRichard Henderson             cf &= 1; /* undefined -- map to never/always */
134046bb3d46SRichard Henderson         }
134146bb3d46SRichard Henderson         break;
134246bb3d46SRichard Henderson     case 6: /* NBC / SBC -- 8-bit carries */
134346bb3d46SRichard Henderson         test_cb = dup_const(MO_8, INT8_MIN);
134446bb3d46SRichard Henderson         break;
134546bb3d46SRichard Henderson     case 7: /* NHC / SHC -- 16-bit carries */
134646bb3d46SRichard Henderson         test_cb = dup_const(MO_16, INT16_MIN);
134746bb3d46SRichard Henderson         break;
134846bb3d46SRichard Henderson     }
134946bb3d46SRichard Henderson     if (!d) {
135046bb3d46SRichard Henderson         test_cb = (uint32_t)test_cb;
135146bb3d46SRichard Henderson     }
1352b2167459SRichard Henderson 
135346bb3d46SRichard Henderson     if (!test_cb) {
135446bb3d46SRichard Henderson         /* No need to compute carries if we don't need to test them. */
135546bb3d46SRichard Henderson         if (is_add) {
135646bb3d46SRichard Henderson             tcg_gen_add_i64(dest, in1, in2);
135746bb3d46SRichard Henderson         } else {
135846bb3d46SRichard Henderson             tcg_gen_sub_i64(dest, in1, in2);
135946bb3d46SRichard Henderson         }
136046bb3d46SRichard Henderson         cond = do_unit_zero_cond(cf, d, dest);
136146bb3d46SRichard Henderson     } else {
136246bb3d46SRichard Henderson         TCGv_i64 cb = tcg_temp_new_i64();
136346bb3d46SRichard Henderson 
136446bb3d46SRichard Henderson         if (d) {
136546bb3d46SRichard Henderson             TCGv_i64 cb_msb = tcg_temp_new_i64();
136646bb3d46SRichard Henderson             if (is_add) {
136746bb3d46SRichard Henderson                 tcg_gen_add2_i64(dest, cb_msb, in1, ctx->zero, in2, ctx->zero);
136846bb3d46SRichard Henderson                 tcg_gen_xor_i64(cb, in1, in2);
136946bb3d46SRichard Henderson             } else {
137046bb3d46SRichard Henderson                 /* See do_sub, !is_b. */
137146bb3d46SRichard Henderson                 TCGv_i64 one = tcg_constant_i64(1);
137246bb3d46SRichard Henderson                 tcg_gen_sub2_i64(dest, cb_msb, in1, one, in2, ctx->zero);
137346bb3d46SRichard Henderson                 tcg_gen_eqv_i64(cb, in1, in2);
137446bb3d46SRichard Henderson             }
137546bb3d46SRichard Henderson             tcg_gen_xor_i64(cb, cb, dest);
137646bb3d46SRichard Henderson             tcg_gen_extract2_i64(cb, cb, cb_msb, 1);
137746bb3d46SRichard Henderson         } else {
137846bb3d46SRichard Henderson             if (is_add) {
137946bb3d46SRichard Henderson                 tcg_gen_add_i64(dest, in1, in2);
138046bb3d46SRichard Henderson                 tcg_gen_xor_i64(cb, in1, in2);
138146bb3d46SRichard Henderson             } else {
138246bb3d46SRichard Henderson                 tcg_gen_sub_i64(dest, in1, in2);
138346bb3d46SRichard Henderson                 tcg_gen_eqv_i64(cb, in1, in2);
138446bb3d46SRichard Henderson             }
138546bb3d46SRichard Henderson             tcg_gen_xor_i64(cb, cb, dest);
138646bb3d46SRichard Henderson             tcg_gen_shri_i64(cb, cb, 1);
138746bb3d46SRichard Henderson         }
138846bb3d46SRichard Henderson 
138946bb3d46SRichard Henderson         tcg_gen_andi_i64(cb, cb, test_cb);
139046bb3d46SRichard Henderson         cond = cond_make_0_tmp(cf & 1 ? TCG_COND_EQ : TCG_COND_NE, cb);
139146bb3d46SRichard Henderson     }
1392b2167459SRichard Henderson 
1393b2167459SRichard Henderson     if (is_tc) {
1394aac0f603SRichard Henderson         TCGv_i64 tmp = tcg_temp_new_i64();
13956fd0c7bcSRichard Henderson         tcg_gen_setcond_i64(cond.c, tmp, cond.a0, cond.a1);
1396ad75a51eSRichard Henderson         gen_helper_tcond(tcg_env, tmp);
1397b2167459SRichard Henderson     }
1398b2167459SRichard Henderson     save_gpr(ctx, rt, dest);
1399b2167459SRichard Henderson 
1400b2167459SRichard Henderson     cond_free(&ctx->null_cond);
1401b2167459SRichard Henderson     ctx->null_cond = cond;
1402b2167459SRichard Henderson }
1403b2167459SRichard Henderson 
140486f8d05fSRichard Henderson #ifndef CONFIG_USER_ONLY
14058d6ae7fbSRichard Henderson /* The "normal" usage is SP >= 0, wherein SP == 0 selects the space
14068d6ae7fbSRichard Henderson    from the top 2 bits of the base register.  There are a few system
14078d6ae7fbSRichard Henderson    instructions that have a 3-bit space specifier, for which SR0 is
14088d6ae7fbSRichard Henderson    not special.  To handle this, pass ~SP.  */
14096fd0c7bcSRichard Henderson static TCGv_i64 space_select(DisasContext *ctx, int sp, TCGv_i64 base)
141086f8d05fSRichard Henderson {
141186f8d05fSRichard Henderson     TCGv_ptr ptr;
14126fd0c7bcSRichard Henderson     TCGv_i64 tmp;
141386f8d05fSRichard Henderson     TCGv_i64 spc;
141486f8d05fSRichard Henderson 
141586f8d05fSRichard Henderson     if (sp != 0) {
14168d6ae7fbSRichard Henderson         if (sp < 0) {
14178d6ae7fbSRichard Henderson             sp = ~sp;
14188d6ae7fbSRichard Henderson         }
14196fd0c7bcSRichard Henderson         spc = tcg_temp_new_i64();
14208d6ae7fbSRichard Henderson         load_spr(ctx, spc, sp);
14218d6ae7fbSRichard Henderson         return spc;
142286f8d05fSRichard Henderson     }
1423494737b7SRichard Henderson     if (ctx->tb_flags & TB_FLAG_SR_SAME) {
1424494737b7SRichard Henderson         return cpu_srH;
1425494737b7SRichard Henderson     }
142686f8d05fSRichard Henderson 
142786f8d05fSRichard Henderson     ptr = tcg_temp_new_ptr();
1428aac0f603SRichard Henderson     tmp = tcg_temp_new_i64();
14296fd0c7bcSRichard Henderson     spc = tcg_temp_new_i64();
143086f8d05fSRichard Henderson 
1431698240d1SRichard Henderson     /* Extract top 2 bits of the address, shift left 3 for uint64_t index. */
14326fd0c7bcSRichard Henderson     tcg_gen_shri_i64(tmp, base, (ctx->tb_flags & PSW_W ? 64 : 32) - 5);
14336fd0c7bcSRichard Henderson     tcg_gen_andi_i64(tmp, tmp, 030);
14346fd0c7bcSRichard Henderson     tcg_gen_trunc_i64_ptr(ptr, tmp);
143586f8d05fSRichard Henderson 
1436ad75a51eSRichard Henderson     tcg_gen_add_ptr(ptr, ptr, tcg_env);
143786f8d05fSRichard Henderson     tcg_gen_ld_i64(spc, ptr, offsetof(CPUHPPAState, sr[4]));
143886f8d05fSRichard Henderson 
143986f8d05fSRichard Henderson     return spc;
144086f8d05fSRichard Henderson }
144186f8d05fSRichard Henderson #endif
144286f8d05fSRichard Henderson 
14436fd0c7bcSRichard Henderson static void form_gva(DisasContext *ctx, TCGv_i64 *pgva, TCGv_i64 *pofs,
1444c53e401eSRichard Henderson                      unsigned rb, unsigned rx, int scale, int64_t disp,
144586f8d05fSRichard Henderson                      unsigned sp, int modify, bool is_phys)
144686f8d05fSRichard Henderson {
14476fd0c7bcSRichard Henderson     TCGv_i64 base = load_gpr(ctx, rb);
14486fd0c7bcSRichard Henderson     TCGv_i64 ofs;
14496fd0c7bcSRichard Henderson     TCGv_i64 addr;
145086f8d05fSRichard Henderson 
1451f5b5c857SRichard Henderson     set_insn_breg(ctx, rb);
1452f5b5c857SRichard Henderson 
145386f8d05fSRichard Henderson     /* Note that RX is mutually exclusive with DISP.  */
145486f8d05fSRichard Henderson     if (rx) {
1455aac0f603SRichard Henderson         ofs = tcg_temp_new_i64();
14566fd0c7bcSRichard Henderson         tcg_gen_shli_i64(ofs, cpu_gr[rx], scale);
14576fd0c7bcSRichard Henderson         tcg_gen_add_i64(ofs, ofs, base);
145886f8d05fSRichard Henderson     } else if (disp || modify) {
1459aac0f603SRichard Henderson         ofs = tcg_temp_new_i64();
14606fd0c7bcSRichard Henderson         tcg_gen_addi_i64(ofs, base, disp);
146186f8d05fSRichard Henderson     } else {
146286f8d05fSRichard Henderson         ofs = base;
146386f8d05fSRichard Henderson     }
146486f8d05fSRichard Henderson 
146586f8d05fSRichard Henderson     *pofs = ofs;
14666fd0c7bcSRichard Henderson     *pgva = addr = tcg_temp_new_i64();
14677d50b696SSven Schnelle     tcg_gen_andi_i64(addr, modify <= 0 ? ofs : base,
14687d50b696SSven Schnelle                      gva_offset_mask(ctx->tb_flags));
1469698240d1SRichard Henderson #ifndef CONFIG_USER_ONLY
147086f8d05fSRichard Henderson     if (!is_phys) {
1471d265360fSRichard Henderson         tcg_gen_or_i64(addr, addr, space_select(ctx, sp, base));
147286f8d05fSRichard Henderson     }
147386f8d05fSRichard Henderson #endif
147486f8d05fSRichard Henderson }
147586f8d05fSRichard Henderson 
147696d6407fSRichard Henderson /* Emit a memory load.  The modify parameter should be
147796d6407fSRichard Henderson  * < 0 for pre-modify,
147896d6407fSRichard Henderson  * > 0 for post-modify,
147996d6407fSRichard Henderson  * = 0 for no base register update.
148096d6407fSRichard Henderson  */
148196d6407fSRichard Henderson static void do_load_32(DisasContext *ctx, TCGv_i32 dest, unsigned rb,
1482c53e401eSRichard Henderson                        unsigned rx, int scale, int64_t disp,
148314776ab5STony Nguyen                        unsigned sp, int modify, MemOp mop)
148496d6407fSRichard Henderson {
14856fd0c7bcSRichard Henderson     TCGv_i64 ofs;
14866fd0c7bcSRichard Henderson     TCGv_i64 addr;
148796d6407fSRichard Henderson 
148896d6407fSRichard Henderson     /* Caller uses nullify_over/nullify_end.  */
148996d6407fSRichard Henderson     assert(ctx->null_cond.c == TCG_COND_NEVER);
149096d6407fSRichard Henderson 
149186f8d05fSRichard Henderson     form_gva(ctx, &addr, &ofs, rb, rx, scale, disp, sp, modify,
149217fe594cSRichard Henderson              MMU_DISABLED(ctx));
1493c1f55d97SRichard Henderson     tcg_gen_qemu_ld_i32(dest, addr, ctx->mmu_idx, mop | UNALIGN(ctx));
149486f8d05fSRichard Henderson     if (modify) {
149586f8d05fSRichard Henderson         save_gpr(ctx, rb, ofs);
149696d6407fSRichard Henderson     }
149796d6407fSRichard Henderson }
149896d6407fSRichard Henderson 
149996d6407fSRichard Henderson static void do_load_64(DisasContext *ctx, TCGv_i64 dest, unsigned rb,
1500c53e401eSRichard Henderson                        unsigned rx, int scale, int64_t disp,
150114776ab5STony Nguyen                        unsigned sp, int modify, MemOp mop)
150296d6407fSRichard Henderson {
15036fd0c7bcSRichard Henderson     TCGv_i64 ofs;
15046fd0c7bcSRichard Henderson     TCGv_i64 addr;
150596d6407fSRichard Henderson 
150696d6407fSRichard Henderson     /* Caller uses nullify_over/nullify_end.  */
150796d6407fSRichard Henderson     assert(ctx->null_cond.c == TCG_COND_NEVER);
150896d6407fSRichard Henderson 
150986f8d05fSRichard Henderson     form_gva(ctx, &addr, &ofs, rb, rx, scale, disp, sp, modify,
151017fe594cSRichard Henderson              MMU_DISABLED(ctx));
1511217d1a5eSRichard Henderson     tcg_gen_qemu_ld_i64(dest, addr, ctx->mmu_idx, mop | UNALIGN(ctx));
151286f8d05fSRichard Henderson     if (modify) {
151386f8d05fSRichard Henderson         save_gpr(ctx, rb, ofs);
151496d6407fSRichard Henderson     }
151596d6407fSRichard Henderson }
151696d6407fSRichard Henderson 
151796d6407fSRichard Henderson static void do_store_32(DisasContext *ctx, TCGv_i32 src, unsigned rb,
1518c53e401eSRichard Henderson                         unsigned rx, int scale, int64_t disp,
151914776ab5STony Nguyen                         unsigned sp, int modify, MemOp mop)
152096d6407fSRichard Henderson {
15216fd0c7bcSRichard Henderson     TCGv_i64 ofs;
15226fd0c7bcSRichard Henderson     TCGv_i64 addr;
152396d6407fSRichard Henderson 
152496d6407fSRichard Henderson     /* Caller uses nullify_over/nullify_end.  */
152596d6407fSRichard Henderson     assert(ctx->null_cond.c == TCG_COND_NEVER);
152696d6407fSRichard Henderson 
152786f8d05fSRichard Henderson     form_gva(ctx, &addr, &ofs, rb, rx, scale, disp, sp, modify,
152817fe594cSRichard Henderson              MMU_DISABLED(ctx));
1529217d1a5eSRichard Henderson     tcg_gen_qemu_st_i32(src, addr, ctx->mmu_idx, mop | UNALIGN(ctx));
153086f8d05fSRichard Henderson     if (modify) {
153186f8d05fSRichard Henderson         save_gpr(ctx, rb, ofs);
153296d6407fSRichard Henderson     }
153396d6407fSRichard Henderson }
153496d6407fSRichard Henderson 
153596d6407fSRichard Henderson static void do_store_64(DisasContext *ctx, TCGv_i64 src, unsigned rb,
1536c53e401eSRichard Henderson                         unsigned rx, int scale, int64_t disp,
153714776ab5STony Nguyen                         unsigned sp, int modify, MemOp mop)
153896d6407fSRichard Henderson {
15396fd0c7bcSRichard Henderson     TCGv_i64 ofs;
15406fd0c7bcSRichard Henderson     TCGv_i64 addr;
154196d6407fSRichard Henderson 
154296d6407fSRichard Henderson     /* Caller uses nullify_over/nullify_end.  */
154396d6407fSRichard Henderson     assert(ctx->null_cond.c == TCG_COND_NEVER);
154496d6407fSRichard Henderson 
154586f8d05fSRichard Henderson     form_gva(ctx, &addr, &ofs, rb, rx, scale, disp, sp, modify,
154617fe594cSRichard Henderson              MMU_DISABLED(ctx));
1547217d1a5eSRichard Henderson     tcg_gen_qemu_st_i64(src, addr, ctx->mmu_idx, mop | UNALIGN(ctx));
154886f8d05fSRichard Henderson     if (modify) {
154986f8d05fSRichard Henderson         save_gpr(ctx, rb, ofs);
155096d6407fSRichard Henderson     }
155196d6407fSRichard Henderson }
155296d6407fSRichard Henderson 
15531cd012a5SRichard Henderson static bool do_load(DisasContext *ctx, unsigned rt, unsigned rb,
1554c53e401eSRichard Henderson                     unsigned rx, int scale, int64_t disp,
155514776ab5STony Nguyen                     unsigned sp, int modify, MemOp mop)
155696d6407fSRichard Henderson {
15576fd0c7bcSRichard Henderson     TCGv_i64 dest;
155896d6407fSRichard Henderson 
155996d6407fSRichard Henderson     nullify_over(ctx);
156096d6407fSRichard Henderson 
156196d6407fSRichard Henderson     if (modify == 0) {
156296d6407fSRichard Henderson         /* No base register update.  */
156396d6407fSRichard Henderson         dest = dest_gpr(ctx, rt);
156496d6407fSRichard Henderson     } else {
156596d6407fSRichard Henderson         /* Make sure if RT == RB, we see the result of the load.  */
1566aac0f603SRichard Henderson         dest = tcg_temp_new_i64();
156796d6407fSRichard Henderson     }
15686fd0c7bcSRichard Henderson     do_load_64(ctx, dest, rb, rx, scale, disp, sp, modify, mop);
156996d6407fSRichard Henderson     save_gpr(ctx, rt, dest);
157096d6407fSRichard Henderson 
15711cd012a5SRichard Henderson     return nullify_end(ctx);
157296d6407fSRichard Henderson }
157396d6407fSRichard Henderson 
1574740038d7SRichard Henderson static bool do_floadw(DisasContext *ctx, unsigned rt, unsigned rb,
1575c53e401eSRichard Henderson                       unsigned rx, int scale, int64_t disp,
157686f8d05fSRichard Henderson                       unsigned sp, int modify)
157796d6407fSRichard Henderson {
157896d6407fSRichard Henderson     TCGv_i32 tmp;
157996d6407fSRichard Henderson 
158096d6407fSRichard Henderson     nullify_over(ctx);
158196d6407fSRichard Henderson 
158296d6407fSRichard Henderson     tmp = tcg_temp_new_i32();
158386f8d05fSRichard Henderson     do_load_32(ctx, tmp, rb, rx, scale, disp, sp, modify, MO_TEUL);
158496d6407fSRichard Henderson     save_frw_i32(rt, tmp);
158596d6407fSRichard Henderson 
158696d6407fSRichard Henderson     if (rt == 0) {
1587ad75a51eSRichard Henderson         gen_helper_loaded_fr0(tcg_env);
158896d6407fSRichard Henderson     }
158996d6407fSRichard Henderson 
1590740038d7SRichard Henderson     return nullify_end(ctx);
159196d6407fSRichard Henderson }
159296d6407fSRichard Henderson 
1593740038d7SRichard Henderson static bool trans_fldw(DisasContext *ctx, arg_ldst *a)
1594740038d7SRichard Henderson {
1595740038d7SRichard Henderson     return do_floadw(ctx, a->t, a->b, a->x, a->scale ? 2 : 0,
1596740038d7SRichard Henderson                      a->disp, a->sp, a->m);
1597740038d7SRichard Henderson }
1598740038d7SRichard Henderson 
1599740038d7SRichard Henderson static bool do_floadd(DisasContext *ctx, unsigned rt, unsigned rb,
1600c53e401eSRichard Henderson                       unsigned rx, int scale, int64_t disp,
160186f8d05fSRichard Henderson                       unsigned sp, int modify)
160296d6407fSRichard Henderson {
160396d6407fSRichard Henderson     TCGv_i64 tmp;
160496d6407fSRichard Henderson 
160596d6407fSRichard Henderson     nullify_over(ctx);
160696d6407fSRichard Henderson 
160796d6407fSRichard Henderson     tmp = tcg_temp_new_i64();
1608fc313c64SFrédéric Pétrot     do_load_64(ctx, tmp, rb, rx, scale, disp, sp, modify, MO_TEUQ);
160996d6407fSRichard Henderson     save_frd(rt, tmp);
161096d6407fSRichard Henderson 
161196d6407fSRichard Henderson     if (rt == 0) {
1612ad75a51eSRichard Henderson         gen_helper_loaded_fr0(tcg_env);
161396d6407fSRichard Henderson     }
161496d6407fSRichard Henderson 
1615740038d7SRichard Henderson     return nullify_end(ctx);
1616740038d7SRichard Henderson }
1617740038d7SRichard Henderson 
1618740038d7SRichard Henderson static bool trans_fldd(DisasContext *ctx, arg_ldst *a)
1619740038d7SRichard Henderson {
1620740038d7SRichard Henderson     return do_floadd(ctx, a->t, a->b, a->x, a->scale ? 3 : 0,
1621740038d7SRichard Henderson                      a->disp, a->sp, a->m);
162296d6407fSRichard Henderson }
162396d6407fSRichard Henderson 
16241cd012a5SRichard Henderson static bool do_store(DisasContext *ctx, unsigned rt, unsigned rb,
1625c53e401eSRichard Henderson                      int64_t disp, unsigned sp,
162614776ab5STony Nguyen                      int modify, MemOp mop)
162796d6407fSRichard Henderson {
162896d6407fSRichard Henderson     nullify_over(ctx);
16296fd0c7bcSRichard Henderson     do_store_64(ctx, load_gpr(ctx, rt), rb, 0, 0, disp, sp, modify, mop);
16301cd012a5SRichard Henderson     return nullify_end(ctx);
163196d6407fSRichard Henderson }
163296d6407fSRichard Henderson 
1633740038d7SRichard Henderson static bool do_fstorew(DisasContext *ctx, unsigned rt, unsigned rb,
1634c53e401eSRichard Henderson                        unsigned rx, int scale, int64_t disp,
163586f8d05fSRichard Henderson                        unsigned sp, int modify)
163696d6407fSRichard Henderson {
163796d6407fSRichard Henderson     TCGv_i32 tmp;
163896d6407fSRichard Henderson 
163996d6407fSRichard Henderson     nullify_over(ctx);
164096d6407fSRichard Henderson 
164196d6407fSRichard Henderson     tmp = load_frw_i32(rt);
164286f8d05fSRichard Henderson     do_store_32(ctx, tmp, rb, rx, scale, disp, sp, modify, MO_TEUL);
164396d6407fSRichard Henderson 
1644740038d7SRichard Henderson     return nullify_end(ctx);
164596d6407fSRichard Henderson }
164696d6407fSRichard Henderson 
1647740038d7SRichard Henderson static bool trans_fstw(DisasContext *ctx, arg_ldst *a)
1648740038d7SRichard Henderson {
1649740038d7SRichard Henderson     return do_fstorew(ctx, a->t, a->b, a->x, a->scale ? 2 : 0,
1650740038d7SRichard Henderson                       a->disp, a->sp, a->m);
1651740038d7SRichard Henderson }
1652740038d7SRichard Henderson 
1653740038d7SRichard Henderson static bool do_fstored(DisasContext *ctx, unsigned rt, unsigned rb,
1654c53e401eSRichard Henderson                        unsigned rx, int scale, int64_t disp,
165586f8d05fSRichard Henderson                        unsigned sp, int modify)
165696d6407fSRichard Henderson {
165796d6407fSRichard Henderson     TCGv_i64 tmp;
165896d6407fSRichard Henderson 
165996d6407fSRichard Henderson     nullify_over(ctx);
166096d6407fSRichard Henderson 
166196d6407fSRichard Henderson     tmp = load_frd(rt);
1662fc313c64SFrédéric Pétrot     do_store_64(ctx, tmp, rb, rx, scale, disp, sp, modify, MO_TEUQ);
166396d6407fSRichard Henderson 
1664740038d7SRichard Henderson     return nullify_end(ctx);
1665740038d7SRichard Henderson }
1666740038d7SRichard Henderson 
1667740038d7SRichard Henderson static bool trans_fstd(DisasContext *ctx, arg_ldst *a)
1668740038d7SRichard Henderson {
1669740038d7SRichard Henderson     return do_fstored(ctx, a->t, a->b, a->x, a->scale ? 3 : 0,
1670740038d7SRichard Henderson                       a->disp, a->sp, a->m);
167196d6407fSRichard Henderson }
167296d6407fSRichard Henderson 
16731ca74648SRichard Henderson static bool do_fop_wew(DisasContext *ctx, unsigned rt, unsigned ra,
1674ebe9383cSRichard Henderson                        void (*func)(TCGv_i32, TCGv_env, TCGv_i32))
1675ebe9383cSRichard Henderson {
1676ebe9383cSRichard Henderson     TCGv_i32 tmp;
1677ebe9383cSRichard Henderson 
1678ebe9383cSRichard Henderson     nullify_over(ctx);
1679ebe9383cSRichard Henderson     tmp = load_frw0_i32(ra);
1680ebe9383cSRichard Henderson 
1681ad75a51eSRichard Henderson     func(tmp, tcg_env, tmp);
1682ebe9383cSRichard Henderson 
1683ebe9383cSRichard Henderson     save_frw_i32(rt, tmp);
16841ca74648SRichard Henderson     return nullify_end(ctx);
1685ebe9383cSRichard Henderson }
1686ebe9383cSRichard Henderson 
16871ca74648SRichard Henderson static bool do_fop_wed(DisasContext *ctx, unsigned rt, unsigned ra,
1688ebe9383cSRichard Henderson                        void (*func)(TCGv_i32, TCGv_env, TCGv_i64))
1689ebe9383cSRichard Henderson {
1690ebe9383cSRichard Henderson     TCGv_i32 dst;
1691ebe9383cSRichard Henderson     TCGv_i64 src;
1692ebe9383cSRichard Henderson 
1693ebe9383cSRichard Henderson     nullify_over(ctx);
1694ebe9383cSRichard Henderson     src = load_frd(ra);
1695ebe9383cSRichard Henderson     dst = tcg_temp_new_i32();
1696ebe9383cSRichard Henderson 
1697ad75a51eSRichard Henderson     func(dst, tcg_env, src);
1698ebe9383cSRichard Henderson 
1699ebe9383cSRichard Henderson     save_frw_i32(rt, dst);
17001ca74648SRichard Henderson     return nullify_end(ctx);
1701ebe9383cSRichard Henderson }
1702ebe9383cSRichard Henderson 
17031ca74648SRichard Henderson static bool do_fop_ded(DisasContext *ctx, unsigned rt, unsigned ra,
1704ebe9383cSRichard Henderson                        void (*func)(TCGv_i64, TCGv_env, TCGv_i64))
1705ebe9383cSRichard Henderson {
1706ebe9383cSRichard Henderson     TCGv_i64 tmp;
1707ebe9383cSRichard Henderson 
1708ebe9383cSRichard Henderson     nullify_over(ctx);
1709ebe9383cSRichard Henderson     tmp = load_frd0(ra);
1710ebe9383cSRichard Henderson 
1711ad75a51eSRichard Henderson     func(tmp, tcg_env, tmp);
1712ebe9383cSRichard Henderson 
1713ebe9383cSRichard Henderson     save_frd(rt, tmp);
17141ca74648SRichard Henderson     return nullify_end(ctx);
1715ebe9383cSRichard Henderson }
1716ebe9383cSRichard Henderson 
17171ca74648SRichard Henderson static bool do_fop_dew(DisasContext *ctx, unsigned rt, unsigned ra,
1718ebe9383cSRichard Henderson                        void (*func)(TCGv_i64, TCGv_env, TCGv_i32))
1719ebe9383cSRichard Henderson {
1720ebe9383cSRichard Henderson     TCGv_i32 src;
1721ebe9383cSRichard Henderson     TCGv_i64 dst;
1722ebe9383cSRichard Henderson 
1723ebe9383cSRichard Henderson     nullify_over(ctx);
1724ebe9383cSRichard Henderson     src = load_frw0_i32(ra);
1725ebe9383cSRichard Henderson     dst = tcg_temp_new_i64();
1726ebe9383cSRichard Henderson 
1727ad75a51eSRichard Henderson     func(dst, tcg_env, src);
1728ebe9383cSRichard Henderson 
1729ebe9383cSRichard Henderson     save_frd(rt, dst);
17301ca74648SRichard Henderson     return nullify_end(ctx);
1731ebe9383cSRichard Henderson }
1732ebe9383cSRichard Henderson 
17331ca74648SRichard Henderson static bool do_fop_weww(DisasContext *ctx, unsigned rt,
1734ebe9383cSRichard Henderson                         unsigned ra, unsigned rb,
173531234768SRichard Henderson                         void (*func)(TCGv_i32, TCGv_env, TCGv_i32, TCGv_i32))
1736ebe9383cSRichard Henderson {
1737ebe9383cSRichard Henderson     TCGv_i32 a, b;
1738ebe9383cSRichard Henderson 
1739ebe9383cSRichard Henderson     nullify_over(ctx);
1740ebe9383cSRichard Henderson     a = load_frw0_i32(ra);
1741ebe9383cSRichard Henderson     b = load_frw0_i32(rb);
1742ebe9383cSRichard Henderson 
1743ad75a51eSRichard Henderson     func(a, tcg_env, a, b);
1744ebe9383cSRichard Henderson 
1745ebe9383cSRichard Henderson     save_frw_i32(rt, a);
17461ca74648SRichard Henderson     return nullify_end(ctx);
1747ebe9383cSRichard Henderson }
1748ebe9383cSRichard Henderson 
17491ca74648SRichard Henderson static bool do_fop_dedd(DisasContext *ctx, unsigned rt,
1750ebe9383cSRichard Henderson                         unsigned ra, unsigned rb,
175131234768SRichard Henderson                         void (*func)(TCGv_i64, TCGv_env, TCGv_i64, TCGv_i64))
1752ebe9383cSRichard Henderson {
1753ebe9383cSRichard Henderson     TCGv_i64 a, b;
1754ebe9383cSRichard Henderson 
1755ebe9383cSRichard Henderson     nullify_over(ctx);
1756ebe9383cSRichard Henderson     a = load_frd0(ra);
1757ebe9383cSRichard Henderson     b = load_frd0(rb);
1758ebe9383cSRichard Henderson 
1759ad75a51eSRichard Henderson     func(a, tcg_env, a, b);
1760ebe9383cSRichard Henderson 
1761ebe9383cSRichard Henderson     save_frd(rt, a);
17621ca74648SRichard Henderson     return nullify_end(ctx);
1763ebe9383cSRichard Henderson }
1764ebe9383cSRichard Henderson 
176598cd9ca7SRichard Henderson /* Emit an unconditional branch to a direct target, which may or may not
176698cd9ca7SRichard Henderson    have already had nullification handled.  */
1767c53e401eSRichard Henderson static bool do_dbranch(DisasContext *ctx, uint64_t dest,
176898cd9ca7SRichard Henderson                        unsigned link, bool is_n)
176998cd9ca7SRichard Henderson {
177098cd9ca7SRichard Henderson     if (ctx->null_cond.c == TCG_COND_NEVER && ctx->null_lab == NULL) {
177198cd9ca7SRichard Henderson         if (link != 0) {
1772741322f4SRichard Henderson             copy_iaoq_entry(ctx, cpu_gr[link], ctx->iaoq_n, ctx->iaoq_n_var);
177398cd9ca7SRichard Henderson         }
177498cd9ca7SRichard Henderson         ctx->iaoq_n = dest;
177598cd9ca7SRichard Henderson         if (is_n) {
177698cd9ca7SRichard Henderson             ctx->null_cond.c = TCG_COND_ALWAYS;
177798cd9ca7SRichard Henderson         }
177898cd9ca7SRichard Henderson     } else {
177998cd9ca7SRichard Henderson         nullify_over(ctx);
178098cd9ca7SRichard Henderson 
178198cd9ca7SRichard Henderson         if (link != 0) {
1782741322f4SRichard Henderson             copy_iaoq_entry(ctx, cpu_gr[link], ctx->iaoq_n, ctx->iaoq_n_var);
178398cd9ca7SRichard Henderson         }
178498cd9ca7SRichard Henderson 
178598cd9ca7SRichard Henderson         if (is_n && use_nullify_skip(ctx)) {
178698cd9ca7SRichard Henderson             nullify_set(ctx, 0);
178798cd9ca7SRichard Henderson             gen_goto_tb(ctx, 0, dest, dest + 4);
178898cd9ca7SRichard Henderson         } else {
178998cd9ca7SRichard Henderson             nullify_set(ctx, is_n);
179098cd9ca7SRichard Henderson             gen_goto_tb(ctx, 0, ctx->iaoq_b, dest);
179198cd9ca7SRichard Henderson         }
179298cd9ca7SRichard Henderson 
179331234768SRichard Henderson         nullify_end(ctx);
179498cd9ca7SRichard Henderson 
179598cd9ca7SRichard Henderson         nullify_set(ctx, 0);
179698cd9ca7SRichard Henderson         gen_goto_tb(ctx, 1, ctx->iaoq_b, ctx->iaoq_n);
179731234768SRichard Henderson         ctx->base.is_jmp = DISAS_NORETURN;
179898cd9ca7SRichard Henderson     }
179901afb7beSRichard Henderson     return true;
180098cd9ca7SRichard Henderson }
180198cd9ca7SRichard Henderson 
180298cd9ca7SRichard Henderson /* Emit a conditional branch to a direct target.  If the branch itself
180398cd9ca7SRichard Henderson    is nullified, we should have already used nullify_over.  */
1804c53e401eSRichard Henderson static bool do_cbranch(DisasContext *ctx, int64_t disp, bool is_n,
180598cd9ca7SRichard Henderson                        DisasCond *cond)
180698cd9ca7SRichard Henderson {
1807c53e401eSRichard Henderson     uint64_t dest = iaoq_dest(ctx, disp);
180898cd9ca7SRichard Henderson     TCGLabel *taken = NULL;
180998cd9ca7SRichard Henderson     TCGCond c = cond->c;
181098cd9ca7SRichard Henderson     bool n;
181198cd9ca7SRichard Henderson 
181298cd9ca7SRichard Henderson     assert(ctx->null_cond.c == TCG_COND_NEVER);
181398cd9ca7SRichard Henderson 
181498cd9ca7SRichard Henderson     /* Handle TRUE and NEVER as direct branches.  */
181598cd9ca7SRichard Henderson     if (c == TCG_COND_ALWAYS) {
181601afb7beSRichard Henderson         return do_dbranch(ctx, dest, 0, is_n && disp >= 0);
181798cd9ca7SRichard Henderson     }
181898cd9ca7SRichard Henderson     if (c == TCG_COND_NEVER) {
181901afb7beSRichard Henderson         return do_dbranch(ctx, ctx->iaoq_n, 0, is_n && disp < 0);
182098cd9ca7SRichard Henderson     }
182198cd9ca7SRichard Henderson 
182298cd9ca7SRichard Henderson     taken = gen_new_label();
18236fd0c7bcSRichard Henderson     tcg_gen_brcond_i64(c, cond->a0, cond->a1, taken);
182498cd9ca7SRichard Henderson     cond_free(cond);
182598cd9ca7SRichard Henderson 
182698cd9ca7SRichard Henderson     /* Not taken: Condition not satisfied; nullify on backward branches. */
182798cd9ca7SRichard Henderson     n = is_n && disp < 0;
182898cd9ca7SRichard Henderson     if (n && use_nullify_skip(ctx)) {
182998cd9ca7SRichard Henderson         nullify_set(ctx, 0);
1830a881c8e7SRichard Henderson         gen_goto_tb(ctx, 0, ctx->iaoq_n, ctx->iaoq_n + 4);
183198cd9ca7SRichard Henderson     } else {
183298cd9ca7SRichard Henderson         if (!n && ctx->null_lab) {
183398cd9ca7SRichard Henderson             gen_set_label(ctx->null_lab);
183498cd9ca7SRichard Henderson             ctx->null_lab = NULL;
183598cd9ca7SRichard Henderson         }
183698cd9ca7SRichard Henderson         nullify_set(ctx, n);
1837c301f34eSRichard Henderson         if (ctx->iaoq_n == -1) {
1838c301f34eSRichard Henderson             /* The temporary iaoq_n_var died at the branch above.
1839c301f34eSRichard Henderson                Regenerate it here instead of saving it.  */
18406fd0c7bcSRichard Henderson             tcg_gen_addi_i64(ctx->iaoq_n_var, cpu_iaoq_b, 4);
1841c301f34eSRichard Henderson         }
1842a881c8e7SRichard Henderson         gen_goto_tb(ctx, 0, ctx->iaoq_b, ctx->iaoq_n);
184398cd9ca7SRichard Henderson     }
184498cd9ca7SRichard Henderson 
184598cd9ca7SRichard Henderson     gen_set_label(taken);
184698cd9ca7SRichard Henderson 
184798cd9ca7SRichard Henderson     /* Taken: Condition satisfied; nullify on forward branches.  */
184898cd9ca7SRichard Henderson     n = is_n && disp >= 0;
184998cd9ca7SRichard Henderson     if (n && use_nullify_skip(ctx)) {
185098cd9ca7SRichard Henderson         nullify_set(ctx, 0);
1851a881c8e7SRichard Henderson         gen_goto_tb(ctx, 1, dest, dest + 4);
185298cd9ca7SRichard Henderson     } else {
185398cd9ca7SRichard Henderson         nullify_set(ctx, n);
1854a881c8e7SRichard Henderson         gen_goto_tb(ctx, 1, ctx->iaoq_b, dest);
185598cd9ca7SRichard Henderson     }
185698cd9ca7SRichard Henderson 
185798cd9ca7SRichard Henderson     /* Not taken: the branch itself was nullified.  */
185898cd9ca7SRichard Henderson     if (ctx->null_lab) {
185998cd9ca7SRichard Henderson         gen_set_label(ctx->null_lab);
186098cd9ca7SRichard Henderson         ctx->null_lab = NULL;
186131234768SRichard Henderson         ctx->base.is_jmp = DISAS_IAQ_N_STALE;
186298cd9ca7SRichard Henderson     } else {
186331234768SRichard Henderson         ctx->base.is_jmp = DISAS_NORETURN;
186498cd9ca7SRichard Henderson     }
186501afb7beSRichard Henderson     return true;
186698cd9ca7SRichard Henderson }
186798cd9ca7SRichard Henderson 
186898cd9ca7SRichard Henderson /* Emit an unconditional branch to an indirect target.  This handles
186998cd9ca7SRichard Henderson    nullification of the branch itself.  */
18706fd0c7bcSRichard Henderson static bool do_ibranch(DisasContext *ctx, TCGv_i64 dest,
187198cd9ca7SRichard Henderson                        unsigned link, bool is_n)
187298cd9ca7SRichard Henderson {
18736fd0c7bcSRichard Henderson     TCGv_i64 a0, a1, next, tmp;
187498cd9ca7SRichard Henderson     TCGCond c;
187598cd9ca7SRichard Henderson 
187698cd9ca7SRichard Henderson     assert(ctx->null_lab == NULL);
187798cd9ca7SRichard Henderson 
187898cd9ca7SRichard Henderson     if (ctx->null_cond.c == TCG_COND_NEVER) {
187998cd9ca7SRichard Henderson         if (link != 0) {
1880741322f4SRichard Henderson             copy_iaoq_entry(ctx, cpu_gr[link], ctx->iaoq_n, ctx->iaoq_n_var);
188198cd9ca7SRichard Henderson         }
1882aac0f603SRichard Henderson         next = tcg_temp_new_i64();
18836fd0c7bcSRichard Henderson         tcg_gen_mov_i64(next, dest);
188498cd9ca7SRichard Henderson         if (is_n) {
1885c301f34eSRichard Henderson             if (use_nullify_skip(ctx)) {
1886a0180973SRichard Henderson                 copy_iaoq_entry(ctx, cpu_iaoq_f, -1, next);
18876fd0c7bcSRichard Henderson                 tcg_gen_addi_i64(next, next, 4);
1888a0180973SRichard Henderson                 copy_iaoq_entry(ctx, cpu_iaoq_b, -1, next);
1889c301f34eSRichard Henderson                 nullify_set(ctx, 0);
189031234768SRichard Henderson                 ctx->base.is_jmp = DISAS_IAQ_N_UPDATED;
189101afb7beSRichard Henderson                 return true;
1892c301f34eSRichard Henderson             }
189398cd9ca7SRichard Henderson             ctx->null_cond.c = TCG_COND_ALWAYS;
189498cd9ca7SRichard Henderson         }
1895c301f34eSRichard Henderson         ctx->iaoq_n = -1;
1896c301f34eSRichard Henderson         ctx->iaoq_n_var = next;
189798cd9ca7SRichard Henderson     } else if (is_n && use_nullify_skip(ctx)) {
189898cd9ca7SRichard Henderson         /* The (conditional) branch, B, nullifies the next insn, N,
189998cd9ca7SRichard Henderson            and we're allowed to skip execution N (no single-step or
19004137cb83SRichard Henderson            tracepoint in effect).  Since the goto_ptr that we must use
190198cd9ca7SRichard Henderson            for the indirect branch consumes no special resources, we
190298cd9ca7SRichard Henderson            can (conditionally) skip B and continue execution.  */
190398cd9ca7SRichard Henderson         /* The use_nullify_skip test implies we have a known control path.  */
190498cd9ca7SRichard Henderson         tcg_debug_assert(ctx->iaoq_b != -1);
190598cd9ca7SRichard Henderson         tcg_debug_assert(ctx->iaoq_n != -1);
190698cd9ca7SRichard Henderson 
190798cd9ca7SRichard Henderson         /* We do have to handle the non-local temporary, DEST, before
190898cd9ca7SRichard Henderson            branching.  Since IOAQ_F is not really live at this point, we
190998cd9ca7SRichard Henderson            can simply store DEST optimistically.  Similarly with IAOQ_B.  */
1910a0180973SRichard Henderson         copy_iaoq_entry(ctx, cpu_iaoq_f, -1, dest);
1911aac0f603SRichard Henderson         next = tcg_temp_new_i64();
19126fd0c7bcSRichard Henderson         tcg_gen_addi_i64(next, dest, 4);
1913a0180973SRichard Henderson         copy_iaoq_entry(ctx, cpu_iaoq_b, -1, next);
191498cd9ca7SRichard Henderson 
191598cd9ca7SRichard Henderson         nullify_over(ctx);
191698cd9ca7SRichard Henderson         if (link != 0) {
19179a91dd84SRichard Henderson             copy_iaoq_entry(ctx, cpu_gr[link], ctx->iaoq_n, ctx->iaoq_n_var);
191898cd9ca7SRichard Henderson         }
19197f11636dSEmilio G. Cota         tcg_gen_lookup_and_goto_ptr();
192001afb7beSRichard Henderson         return nullify_end(ctx);
192198cd9ca7SRichard Henderson     } else {
192298cd9ca7SRichard Henderson         c = ctx->null_cond.c;
192398cd9ca7SRichard Henderson         a0 = ctx->null_cond.a0;
192498cd9ca7SRichard Henderson         a1 = ctx->null_cond.a1;
192598cd9ca7SRichard Henderson 
1926aac0f603SRichard Henderson         tmp = tcg_temp_new_i64();
1927aac0f603SRichard Henderson         next = tcg_temp_new_i64();
192898cd9ca7SRichard Henderson 
1929741322f4SRichard Henderson         copy_iaoq_entry(ctx, tmp, ctx->iaoq_n, ctx->iaoq_n_var);
19306fd0c7bcSRichard Henderson         tcg_gen_movcond_i64(c, next, a0, a1, tmp, dest);
193198cd9ca7SRichard Henderson         ctx->iaoq_n = -1;
193298cd9ca7SRichard Henderson         ctx->iaoq_n_var = next;
193398cd9ca7SRichard Henderson 
193498cd9ca7SRichard Henderson         if (link != 0) {
19356fd0c7bcSRichard Henderson             tcg_gen_movcond_i64(c, cpu_gr[link], a0, a1, cpu_gr[link], tmp);
193698cd9ca7SRichard Henderson         }
193798cd9ca7SRichard Henderson 
193898cd9ca7SRichard Henderson         if (is_n) {
193998cd9ca7SRichard Henderson             /* The branch nullifies the next insn, which means the state of N
194098cd9ca7SRichard Henderson                after the branch is the inverse of the state of N that applied
194198cd9ca7SRichard Henderson                to the branch.  */
19426fd0c7bcSRichard Henderson             tcg_gen_setcond_i64(tcg_invert_cond(c), cpu_psw_n, a0, a1);
194398cd9ca7SRichard Henderson             cond_free(&ctx->null_cond);
194498cd9ca7SRichard Henderson             ctx->null_cond = cond_make_n();
194598cd9ca7SRichard Henderson             ctx->psw_n_nonzero = true;
194698cd9ca7SRichard Henderson         } else {
194798cd9ca7SRichard Henderson             cond_free(&ctx->null_cond);
194898cd9ca7SRichard Henderson         }
194998cd9ca7SRichard Henderson     }
195001afb7beSRichard Henderson     return true;
195198cd9ca7SRichard Henderson }
195298cd9ca7SRichard Henderson 
1953660eefe1SRichard Henderson /* Implement
1954660eefe1SRichard Henderson  *    if (IAOQ_Front{30..31} < GR[b]{30..31})
1955660eefe1SRichard Henderson  *      IAOQ_Next{30..31} ← GR[b]{30..31};
1956660eefe1SRichard Henderson  *    else
1957660eefe1SRichard Henderson  *      IAOQ_Next{30..31} ← IAOQ_Front{30..31};
1958660eefe1SRichard Henderson  * which keeps the privilege level from being increased.
1959660eefe1SRichard Henderson  */
19606fd0c7bcSRichard Henderson static TCGv_i64 do_ibranch_priv(DisasContext *ctx, TCGv_i64 offset)
1961660eefe1SRichard Henderson {
19626fd0c7bcSRichard Henderson     TCGv_i64 dest;
1963660eefe1SRichard Henderson     switch (ctx->privilege) {
1964660eefe1SRichard Henderson     case 0:
1965660eefe1SRichard Henderson         /* Privilege 0 is maximum and is allowed to decrease.  */
1966660eefe1SRichard Henderson         return offset;
1967660eefe1SRichard Henderson     case 3:
1968993119feSRichard Henderson         /* Privilege 3 is minimum and is never allowed to increase.  */
1969aac0f603SRichard Henderson         dest = tcg_temp_new_i64();
19706fd0c7bcSRichard Henderson         tcg_gen_ori_i64(dest, offset, 3);
1971660eefe1SRichard Henderson         break;
1972660eefe1SRichard Henderson     default:
1973aac0f603SRichard Henderson         dest = tcg_temp_new_i64();
19746fd0c7bcSRichard Henderson         tcg_gen_andi_i64(dest, offset, -4);
19756fd0c7bcSRichard Henderson         tcg_gen_ori_i64(dest, dest, ctx->privilege);
19766fd0c7bcSRichard Henderson         tcg_gen_movcond_i64(TCG_COND_GTU, dest, dest, offset, dest, offset);
1977660eefe1SRichard Henderson         break;
1978660eefe1SRichard Henderson     }
1979660eefe1SRichard Henderson     return dest;
1980660eefe1SRichard Henderson }
1981660eefe1SRichard Henderson 
1982ba1d0b44SRichard Henderson #ifdef CONFIG_USER_ONLY
19837ad439dfSRichard Henderson /* On Linux, page zero is normally marked execute only + gateway.
19847ad439dfSRichard Henderson    Therefore normal read or write is supposed to fail, but specific
19857ad439dfSRichard Henderson    offsets have kernel code mapped to raise permissions to implement
19867ad439dfSRichard Henderson    system calls.  Handling this via an explicit check here, rather
19877ad439dfSRichard Henderson    in than the "be disp(sr2,r0)" instruction that probably sent us
19887ad439dfSRichard Henderson    here, is the easiest way to handle the branch delay slot on the
19897ad439dfSRichard Henderson    aforementioned BE.  */
199031234768SRichard Henderson static void do_page_zero(DisasContext *ctx)
19917ad439dfSRichard Henderson {
19926fd0c7bcSRichard Henderson     TCGv_i64 tmp;
1993a0180973SRichard Henderson 
19947ad439dfSRichard Henderson     /* If by some means we get here with PSW[N]=1, that implies that
19957ad439dfSRichard Henderson        the B,GATE instruction would be skipped, and we'd fault on the
19968b81968cSMichael Tokarev        next insn within the privileged page.  */
19977ad439dfSRichard Henderson     switch (ctx->null_cond.c) {
19987ad439dfSRichard Henderson     case TCG_COND_NEVER:
19997ad439dfSRichard Henderson         break;
20007ad439dfSRichard Henderson     case TCG_COND_ALWAYS:
20016fd0c7bcSRichard Henderson         tcg_gen_movi_i64(cpu_psw_n, 0);
20027ad439dfSRichard Henderson         goto do_sigill;
20037ad439dfSRichard Henderson     default:
20047ad439dfSRichard Henderson         /* Since this is always the first (and only) insn within the
20057ad439dfSRichard Henderson            TB, we should know the state of PSW[N] from TB->FLAGS.  */
20067ad439dfSRichard Henderson         g_assert_not_reached();
20077ad439dfSRichard Henderson     }
20087ad439dfSRichard Henderson 
20097ad439dfSRichard Henderson     /* Check that we didn't arrive here via some means that allowed
20107ad439dfSRichard Henderson        non-sequential instruction execution.  Normally the PSW[B] bit
20117ad439dfSRichard Henderson        detects this by disallowing the B,GATE instruction to execute
20127ad439dfSRichard Henderson        under such conditions.  */
20137ad439dfSRichard Henderson     if (ctx->iaoq_b != ctx->iaoq_f + 4) {
20147ad439dfSRichard Henderson         goto do_sigill;
20157ad439dfSRichard Henderson     }
20167ad439dfSRichard Henderson 
2017ebd0e151SRichard Henderson     switch (ctx->iaoq_f & -4) {
20187ad439dfSRichard Henderson     case 0x00: /* Null pointer call */
20192986721dSRichard Henderson         gen_excp_1(EXCP_IMP);
202031234768SRichard Henderson         ctx->base.is_jmp = DISAS_NORETURN;
202131234768SRichard Henderson         break;
20227ad439dfSRichard Henderson 
20237ad439dfSRichard Henderson     case 0xb0: /* LWS */
20247ad439dfSRichard Henderson         gen_excp_1(EXCP_SYSCALL_LWS);
202531234768SRichard Henderson         ctx->base.is_jmp = DISAS_NORETURN;
202631234768SRichard Henderson         break;
20277ad439dfSRichard Henderson 
20287ad439dfSRichard Henderson     case 0xe0: /* SET_THREAD_POINTER */
20296fd0c7bcSRichard Henderson         tcg_gen_st_i64(cpu_gr[26], tcg_env, offsetof(CPUHPPAState, cr[27]));
2030aac0f603SRichard Henderson         tmp = tcg_temp_new_i64();
20316fd0c7bcSRichard Henderson         tcg_gen_ori_i64(tmp, cpu_gr[31], 3);
2032a0180973SRichard Henderson         copy_iaoq_entry(ctx, cpu_iaoq_f, -1, tmp);
20336fd0c7bcSRichard Henderson         tcg_gen_addi_i64(tmp, tmp, 4);
2034a0180973SRichard Henderson         copy_iaoq_entry(ctx, cpu_iaoq_b, -1, tmp);
203531234768SRichard Henderson         ctx->base.is_jmp = DISAS_IAQ_N_UPDATED;
203631234768SRichard Henderson         break;
20377ad439dfSRichard Henderson 
20387ad439dfSRichard Henderson     case 0x100: /* SYSCALL */
20397ad439dfSRichard Henderson         gen_excp_1(EXCP_SYSCALL);
204031234768SRichard Henderson         ctx->base.is_jmp = DISAS_NORETURN;
204131234768SRichard Henderson         break;
20427ad439dfSRichard Henderson 
20437ad439dfSRichard Henderson     default:
20447ad439dfSRichard Henderson     do_sigill:
20452986721dSRichard Henderson         gen_excp_1(EXCP_ILL);
204631234768SRichard Henderson         ctx->base.is_jmp = DISAS_NORETURN;
204731234768SRichard Henderson         break;
20487ad439dfSRichard Henderson     }
20497ad439dfSRichard Henderson }
2050ba1d0b44SRichard Henderson #endif
20517ad439dfSRichard Henderson 
2052deee69a1SRichard Henderson static bool trans_nop(DisasContext *ctx, arg_nop *a)
2053b2167459SRichard Henderson {
2054b2167459SRichard Henderson     cond_free(&ctx->null_cond);
205531234768SRichard Henderson     return true;
2056b2167459SRichard Henderson }
2057b2167459SRichard Henderson 
205840f9f908SRichard Henderson static bool trans_break(DisasContext *ctx, arg_break *a)
205998a9cb79SRichard Henderson {
206031234768SRichard Henderson     return gen_excp_iir(ctx, EXCP_BREAK);
206198a9cb79SRichard Henderson }
206298a9cb79SRichard Henderson 
2063e36f27efSRichard Henderson static bool trans_sync(DisasContext *ctx, arg_sync *a)
206498a9cb79SRichard Henderson {
206598a9cb79SRichard Henderson     /* No point in nullifying the memory barrier.  */
206698a9cb79SRichard Henderson     tcg_gen_mb(TCG_BAR_SC | TCG_MO_ALL);
206798a9cb79SRichard Henderson 
206898a9cb79SRichard Henderson     cond_free(&ctx->null_cond);
206931234768SRichard Henderson     return true;
207098a9cb79SRichard Henderson }
207198a9cb79SRichard Henderson 
2072c603e14aSRichard Henderson static bool trans_mfia(DisasContext *ctx, arg_mfia *a)
207398a9cb79SRichard Henderson {
2074c603e14aSRichard Henderson     unsigned rt = a->t;
20756fd0c7bcSRichard Henderson     TCGv_i64 tmp = dest_gpr(ctx, rt);
2076b5e0b3a5SSven Schnelle     tcg_gen_movi_i64(tmp, ctx->iaoq_f & ~3ULL);
207798a9cb79SRichard Henderson     save_gpr(ctx, rt, tmp);
207898a9cb79SRichard Henderson 
207998a9cb79SRichard Henderson     cond_free(&ctx->null_cond);
208031234768SRichard Henderson     return true;
208198a9cb79SRichard Henderson }
208298a9cb79SRichard Henderson 
2083c603e14aSRichard Henderson static bool trans_mfsp(DisasContext *ctx, arg_mfsp *a)
208498a9cb79SRichard Henderson {
2085c603e14aSRichard Henderson     unsigned rt = a->t;
2086c603e14aSRichard Henderson     unsigned rs = a->sp;
208733423472SRichard Henderson     TCGv_i64 t0 = tcg_temp_new_i64();
208898a9cb79SRichard Henderson 
208933423472SRichard Henderson     load_spr(ctx, t0, rs);
209033423472SRichard Henderson     tcg_gen_shri_i64(t0, t0, 32);
209133423472SRichard Henderson 
2092967662cdSRichard Henderson     save_gpr(ctx, rt, t0);
209398a9cb79SRichard Henderson 
209498a9cb79SRichard Henderson     cond_free(&ctx->null_cond);
209531234768SRichard Henderson     return true;
209698a9cb79SRichard Henderson }
209798a9cb79SRichard Henderson 
2098c603e14aSRichard Henderson static bool trans_mfctl(DisasContext *ctx, arg_mfctl *a)
209998a9cb79SRichard Henderson {
2100c603e14aSRichard Henderson     unsigned rt = a->t;
2101c603e14aSRichard Henderson     unsigned ctl = a->r;
21026fd0c7bcSRichard Henderson     TCGv_i64 tmp;
210398a9cb79SRichard Henderson 
210498a9cb79SRichard Henderson     switch (ctl) {
210535136a77SRichard Henderson     case CR_SAR:
2106c603e14aSRichard Henderson         if (a->e == 0) {
210798a9cb79SRichard Henderson             /* MFSAR without ,W masks low 5 bits.  */
210898a9cb79SRichard Henderson             tmp = dest_gpr(ctx, rt);
21096fd0c7bcSRichard Henderson             tcg_gen_andi_i64(tmp, cpu_sar, 31);
211098a9cb79SRichard Henderson             save_gpr(ctx, rt, tmp);
211135136a77SRichard Henderson             goto done;
211298a9cb79SRichard Henderson         }
211398a9cb79SRichard Henderson         save_gpr(ctx, rt, cpu_sar);
211435136a77SRichard Henderson         goto done;
211535136a77SRichard Henderson     case CR_IT: /* Interval Timer */
211635136a77SRichard Henderson         /* FIXME: Respect PSW_S bit.  */
211735136a77SRichard Henderson         nullify_over(ctx);
211898a9cb79SRichard Henderson         tmp = dest_gpr(ctx, rt);
2119dfd1b812SRichard Henderson         if (translator_io_start(&ctx->base)) {
212031234768SRichard Henderson             ctx->base.is_jmp = DISAS_IAQ_N_STALE;
212149c29d6cSRichard Henderson         }
21220c58c1bcSRichard Henderson         gen_helper_read_interval_timer(tmp);
212398a9cb79SRichard Henderson         save_gpr(ctx, rt, tmp);
212431234768SRichard Henderson         return nullify_end(ctx);
212598a9cb79SRichard Henderson     case 26:
212698a9cb79SRichard Henderson     case 27:
212798a9cb79SRichard Henderson         break;
212898a9cb79SRichard Henderson     default:
212998a9cb79SRichard Henderson         /* All other control registers are privileged.  */
213035136a77SRichard Henderson         CHECK_MOST_PRIVILEGED(EXCP_PRIV_REG);
213135136a77SRichard Henderson         break;
213298a9cb79SRichard Henderson     }
213398a9cb79SRichard Henderson 
2134aac0f603SRichard Henderson     tmp = tcg_temp_new_i64();
21356fd0c7bcSRichard Henderson     tcg_gen_ld_i64(tmp, tcg_env, offsetof(CPUHPPAState, cr[ctl]));
213635136a77SRichard Henderson     save_gpr(ctx, rt, tmp);
213735136a77SRichard Henderson 
213835136a77SRichard Henderson  done:
213998a9cb79SRichard Henderson     cond_free(&ctx->null_cond);
214031234768SRichard Henderson     return true;
214198a9cb79SRichard Henderson }
214298a9cb79SRichard Henderson 
2143c603e14aSRichard Henderson static bool trans_mtsp(DisasContext *ctx, arg_mtsp *a)
214433423472SRichard Henderson {
2145c603e14aSRichard Henderson     unsigned rr = a->r;
2146c603e14aSRichard Henderson     unsigned rs = a->sp;
2147967662cdSRichard Henderson     TCGv_i64 tmp;
214833423472SRichard Henderson 
214933423472SRichard Henderson     if (rs >= 5) {
215033423472SRichard Henderson         CHECK_MOST_PRIVILEGED(EXCP_PRIV_REG);
215133423472SRichard Henderson     }
215233423472SRichard Henderson     nullify_over(ctx);
215333423472SRichard Henderson 
2154967662cdSRichard Henderson     tmp = tcg_temp_new_i64();
2155967662cdSRichard Henderson     tcg_gen_shli_i64(tmp, load_gpr(ctx, rr), 32);
215633423472SRichard Henderson 
215733423472SRichard Henderson     if (rs >= 4) {
2158967662cdSRichard Henderson         tcg_gen_st_i64(tmp, tcg_env, offsetof(CPUHPPAState, sr[rs]));
2159494737b7SRichard Henderson         ctx->tb_flags &= ~TB_FLAG_SR_SAME;
216033423472SRichard Henderson     } else {
2161967662cdSRichard Henderson         tcg_gen_mov_i64(cpu_sr[rs], tmp);
216233423472SRichard Henderson     }
216333423472SRichard Henderson 
216431234768SRichard Henderson     return nullify_end(ctx);
216533423472SRichard Henderson }
216633423472SRichard Henderson 
2167c603e14aSRichard Henderson static bool trans_mtctl(DisasContext *ctx, arg_mtctl *a)
216898a9cb79SRichard Henderson {
2169c603e14aSRichard Henderson     unsigned ctl = a->t;
21706fd0c7bcSRichard Henderson     TCGv_i64 reg;
21716fd0c7bcSRichard Henderson     TCGv_i64 tmp;
217298a9cb79SRichard Henderson 
217335136a77SRichard Henderson     if (ctl == CR_SAR) {
21744845f015SSven Schnelle         reg = load_gpr(ctx, a->r);
2175aac0f603SRichard Henderson         tmp = tcg_temp_new_i64();
21766fd0c7bcSRichard Henderson         tcg_gen_andi_i64(tmp, reg, ctx->is_pa20 ? 63 : 31);
217798a9cb79SRichard Henderson         save_or_nullify(ctx, cpu_sar, tmp);
217898a9cb79SRichard Henderson 
217998a9cb79SRichard Henderson         cond_free(&ctx->null_cond);
218031234768SRichard Henderson         return true;
218198a9cb79SRichard Henderson     }
218298a9cb79SRichard Henderson 
218335136a77SRichard Henderson     /* All other control registers are privileged or read-only.  */
218435136a77SRichard Henderson     CHECK_MOST_PRIVILEGED(EXCP_PRIV_REG);
218535136a77SRichard Henderson 
2186c603e14aSRichard Henderson #ifndef CONFIG_USER_ONLY
218735136a77SRichard Henderson     nullify_over(ctx);
21884c34bab0SHelge Deller 
21894c34bab0SHelge Deller     if (ctx->is_pa20) {
21904845f015SSven Schnelle         reg = load_gpr(ctx, a->r);
21914c34bab0SHelge Deller     } else {
21924c34bab0SHelge Deller         reg = tcg_temp_new_i64();
21934c34bab0SHelge Deller         tcg_gen_ext32u_i64(reg, load_gpr(ctx, a->r));
21944c34bab0SHelge Deller     }
21954845f015SSven Schnelle 
219635136a77SRichard Henderson     switch (ctl) {
219735136a77SRichard Henderson     case CR_IT:
2198104281c1SRichard Henderson         if (translator_io_start(&ctx->base)) {
2199104281c1SRichard Henderson             ctx->base.is_jmp = DISAS_IAQ_N_STALE;
2200104281c1SRichard Henderson         }
2201ad75a51eSRichard Henderson         gen_helper_write_interval_timer(tcg_env, reg);
220235136a77SRichard Henderson         break;
22034f5f2548SRichard Henderson     case CR_EIRR:
22046ebebea7SRichard Henderson         /* Helper modifies interrupt lines and is therefore IO. */
22056ebebea7SRichard Henderson         translator_io_start(&ctx->base);
2206ad75a51eSRichard Henderson         gen_helper_write_eirr(tcg_env, reg);
22076ebebea7SRichard Henderson         /* Exit to re-evaluate interrupts in the main loop. */
220831234768SRichard Henderson         ctx->base.is_jmp = DISAS_IAQ_N_STALE_EXIT;
22094f5f2548SRichard Henderson         break;
22104f5f2548SRichard Henderson 
221135136a77SRichard Henderson     case CR_IIASQ:
221235136a77SRichard Henderson     case CR_IIAOQ:
221335136a77SRichard Henderson         /* FIXME: Respect PSW_Q bit */
221435136a77SRichard Henderson         /* The write advances the queue and stores to the back element.  */
2215aac0f603SRichard Henderson         tmp = tcg_temp_new_i64();
22166fd0c7bcSRichard Henderson         tcg_gen_ld_i64(tmp, tcg_env,
221735136a77SRichard Henderson                        offsetof(CPUHPPAState, cr_back[ctl - CR_IIASQ]));
22186fd0c7bcSRichard Henderson         tcg_gen_st_i64(tmp, tcg_env, offsetof(CPUHPPAState, cr[ctl]));
22196fd0c7bcSRichard Henderson         tcg_gen_st_i64(reg, tcg_env,
222035136a77SRichard Henderson                        offsetof(CPUHPPAState, cr_back[ctl - CR_IIASQ]));
222135136a77SRichard Henderson         break;
222235136a77SRichard Henderson 
2223d5de20bdSSven Schnelle     case CR_PID1:
2224d5de20bdSSven Schnelle     case CR_PID2:
2225d5de20bdSSven Schnelle     case CR_PID3:
2226d5de20bdSSven Schnelle     case CR_PID4:
22276fd0c7bcSRichard Henderson         tcg_gen_st_i64(reg, tcg_env, offsetof(CPUHPPAState, cr[ctl]));
2228d5de20bdSSven Schnelle #ifndef CONFIG_USER_ONLY
2229ad75a51eSRichard Henderson         gen_helper_change_prot_id(tcg_env);
2230d5de20bdSSven Schnelle #endif
2231d5de20bdSSven Schnelle         break;
2232d5de20bdSSven Schnelle 
22336ebebea7SRichard Henderson     case CR_EIEM:
22346ebebea7SRichard Henderson         /* Exit to re-evaluate interrupts in the main loop. */
22356ebebea7SRichard Henderson         ctx->base.is_jmp = DISAS_IAQ_N_STALE_EXIT;
22366ebebea7SRichard Henderson         /* FALLTHRU */
223735136a77SRichard Henderson     default:
22386fd0c7bcSRichard Henderson         tcg_gen_st_i64(reg, tcg_env, offsetof(CPUHPPAState, cr[ctl]));
223935136a77SRichard Henderson         break;
224035136a77SRichard Henderson     }
224131234768SRichard Henderson     return nullify_end(ctx);
22424f5f2548SRichard Henderson #endif
224335136a77SRichard Henderson }
224435136a77SRichard Henderson 
2245c603e14aSRichard Henderson static bool trans_mtsarcm(DisasContext *ctx, arg_mtsarcm *a)
224698a9cb79SRichard Henderson {
2247aac0f603SRichard Henderson     TCGv_i64 tmp = tcg_temp_new_i64();
224898a9cb79SRichard Henderson 
22496fd0c7bcSRichard Henderson     tcg_gen_not_i64(tmp, load_gpr(ctx, a->r));
22506fd0c7bcSRichard Henderson     tcg_gen_andi_i64(tmp, tmp, ctx->is_pa20 ? 63 : 31);
225198a9cb79SRichard Henderson     save_or_nullify(ctx, cpu_sar, tmp);
225298a9cb79SRichard Henderson 
225398a9cb79SRichard Henderson     cond_free(&ctx->null_cond);
225431234768SRichard Henderson     return true;
225598a9cb79SRichard Henderson }
225698a9cb79SRichard Henderson 
2257e36f27efSRichard Henderson static bool trans_ldsid(DisasContext *ctx, arg_ldsid *a)
225898a9cb79SRichard Henderson {
22596fd0c7bcSRichard Henderson     TCGv_i64 dest = dest_gpr(ctx, a->t);
226098a9cb79SRichard Henderson 
22612330504cSHelge Deller #ifdef CONFIG_USER_ONLY
22622330504cSHelge Deller     /* We don't implement space registers in user mode. */
22636fd0c7bcSRichard Henderson     tcg_gen_movi_i64(dest, 0);
22642330504cSHelge Deller #else
2265967662cdSRichard Henderson     tcg_gen_mov_i64(dest, space_select(ctx, a->sp, load_gpr(ctx, a->b)));
2266967662cdSRichard Henderson     tcg_gen_shri_i64(dest, dest, 32);
22672330504cSHelge Deller #endif
2268e36f27efSRichard Henderson     save_gpr(ctx, a->t, dest);
226998a9cb79SRichard Henderson 
227098a9cb79SRichard Henderson     cond_free(&ctx->null_cond);
227131234768SRichard Henderson     return true;
227298a9cb79SRichard Henderson }
227398a9cb79SRichard Henderson 
2274e36f27efSRichard Henderson static bool trans_rsm(DisasContext *ctx, arg_rsm *a)
2275e36f27efSRichard Henderson {
22767b2d70a1SHelge Deller #ifdef CONFIG_USER_ONLY
2277e36f27efSRichard Henderson     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
22787b2d70a1SHelge Deller #else
22796fd0c7bcSRichard Henderson     TCGv_i64 tmp;
2280e1b5a5edSRichard Henderson 
22817b2d70a1SHelge Deller     /* HP-UX 11i and HP ODE use rsm for read-access to PSW */
22827b2d70a1SHelge Deller     if (a->i) {
22837b2d70a1SHelge Deller         CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
22847b2d70a1SHelge Deller     }
22857b2d70a1SHelge Deller 
2286e1b5a5edSRichard Henderson     nullify_over(ctx);
2287e1b5a5edSRichard Henderson 
2288aac0f603SRichard Henderson     tmp = tcg_temp_new_i64();
22896fd0c7bcSRichard Henderson     tcg_gen_ld_i64(tmp, tcg_env, offsetof(CPUHPPAState, psw));
22906fd0c7bcSRichard Henderson     tcg_gen_andi_i64(tmp, tmp, ~a->i);
2291ad75a51eSRichard Henderson     gen_helper_swap_system_mask(tmp, tcg_env, tmp);
2292e36f27efSRichard Henderson     save_gpr(ctx, a->t, tmp);
2293e1b5a5edSRichard Henderson 
2294e1b5a5edSRichard Henderson     /* Exit the TB to recognize new interrupts, e.g. PSW_M.  */
229531234768SRichard Henderson     ctx->base.is_jmp = DISAS_IAQ_N_STALE_EXIT;
229631234768SRichard Henderson     return nullify_end(ctx);
2297e36f27efSRichard Henderson #endif
2298e1b5a5edSRichard Henderson }
2299e1b5a5edSRichard Henderson 
2300e36f27efSRichard Henderson static bool trans_ssm(DisasContext *ctx, arg_ssm *a)
2301e1b5a5edSRichard Henderson {
2302e36f27efSRichard Henderson     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
2303e36f27efSRichard Henderson #ifndef CONFIG_USER_ONLY
23046fd0c7bcSRichard Henderson     TCGv_i64 tmp;
2305e1b5a5edSRichard Henderson 
2306e1b5a5edSRichard Henderson     nullify_over(ctx);
2307e1b5a5edSRichard Henderson 
2308aac0f603SRichard Henderson     tmp = tcg_temp_new_i64();
23096fd0c7bcSRichard Henderson     tcg_gen_ld_i64(tmp, tcg_env, offsetof(CPUHPPAState, psw));
23106fd0c7bcSRichard Henderson     tcg_gen_ori_i64(tmp, tmp, a->i);
2311ad75a51eSRichard Henderson     gen_helper_swap_system_mask(tmp, tcg_env, tmp);
2312e36f27efSRichard Henderson     save_gpr(ctx, a->t, tmp);
2313e1b5a5edSRichard Henderson 
2314e1b5a5edSRichard Henderson     /* Exit the TB to recognize new interrupts, e.g. PSW_I.  */
231531234768SRichard Henderson     ctx->base.is_jmp = DISAS_IAQ_N_STALE_EXIT;
231631234768SRichard Henderson     return nullify_end(ctx);
2317e36f27efSRichard Henderson #endif
2318e1b5a5edSRichard Henderson }
2319e1b5a5edSRichard Henderson 
2320c603e14aSRichard Henderson static bool trans_mtsm(DisasContext *ctx, arg_mtsm *a)
2321e1b5a5edSRichard Henderson {
2322e1b5a5edSRichard Henderson     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
2323c603e14aSRichard Henderson #ifndef CONFIG_USER_ONLY
23246fd0c7bcSRichard Henderson     TCGv_i64 tmp, reg;
2325e1b5a5edSRichard Henderson     nullify_over(ctx);
2326e1b5a5edSRichard Henderson 
2327c603e14aSRichard Henderson     reg = load_gpr(ctx, a->r);
2328aac0f603SRichard Henderson     tmp = tcg_temp_new_i64();
2329ad75a51eSRichard Henderson     gen_helper_swap_system_mask(tmp, tcg_env, reg);
2330e1b5a5edSRichard Henderson 
2331e1b5a5edSRichard Henderson     /* Exit the TB to recognize new interrupts.  */
233231234768SRichard Henderson     ctx->base.is_jmp = DISAS_IAQ_N_STALE_EXIT;
233331234768SRichard Henderson     return nullify_end(ctx);
2334c603e14aSRichard Henderson #endif
2335e1b5a5edSRichard Henderson }
2336f49b3537SRichard Henderson 
2337e36f27efSRichard Henderson static bool do_rfi(DisasContext *ctx, bool rfi_r)
2338f49b3537SRichard Henderson {
2339f49b3537SRichard Henderson     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
2340e36f27efSRichard Henderson #ifndef CONFIG_USER_ONLY
2341f49b3537SRichard Henderson     nullify_over(ctx);
2342f49b3537SRichard Henderson 
2343e36f27efSRichard Henderson     if (rfi_r) {
2344ad75a51eSRichard Henderson         gen_helper_rfi_r(tcg_env);
2345f49b3537SRichard Henderson     } else {
2346ad75a51eSRichard Henderson         gen_helper_rfi(tcg_env);
2347f49b3537SRichard Henderson     }
234831234768SRichard Henderson     /* Exit the TB to recognize new interrupts.  */
234907ea28b4SRichard Henderson     tcg_gen_exit_tb(NULL, 0);
235031234768SRichard Henderson     ctx->base.is_jmp = DISAS_NORETURN;
2351f49b3537SRichard Henderson 
235231234768SRichard Henderson     return nullify_end(ctx);
2353e36f27efSRichard Henderson #endif
2354f49b3537SRichard Henderson }
23556210db05SHelge Deller 
2356e36f27efSRichard Henderson static bool trans_rfi(DisasContext *ctx, arg_rfi *a)
2357e36f27efSRichard Henderson {
2358e36f27efSRichard Henderson     return do_rfi(ctx, false);
2359e36f27efSRichard Henderson }
2360e36f27efSRichard Henderson 
2361e36f27efSRichard Henderson static bool trans_rfi_r(DisasContext *ctx, arg_rfi_r *a)
2362e36f27efSRichard Henderson {
2363e36f27efSRichard Henderson     return do_rfi(ctx, true);
2364e36f27efSRichard Henderson }
2365e36f27efSRichard Henderson 
236696927adbSRichard Henderson static bool trans_halt(DisasContext *ctx, arg_halt *a)
23676210db05SHelge Deller {
23686210db05SHelge Deller     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
236996927adbSRichard Henderson #ifndef CONFIG_USER_ONLY
23706210db05SHelge Deller     nullify_over(ctx);
2371ad75a51eSRichard Henderson     gen_helper_halt(tcg_env);
237231234768SRichard Henderson     ctx->base.is_jmp = DISAS_NORETURN;
237331234768SRichard Henderson     return nullify_end(ctx);
237496927adbSRichard Henderson #endif
23756210db05SHelge Deller }
237696927adbSRichard Henderson 
237796927adbSRichard Henderson static bool trans_reset(DisasContext *ctx, arg_reset *a)
237896927adbSRichard Henderson {
237996927adbSRichard Henderson     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
238096927adbSRichard Henderson #ifndef CONFIG_USER_ONLY
238196927adbSRichard Henderson     nullify_over(ctx);
2382ad75a51eSRichard Henderson     gen_helper_reset(tcg_env);
238396927adbSRichard Henderson     ctx->base.is_jmp = DISAS_NORETURN;
238496927adbSRichard Henderson     return nullify_end(ctx);
238596927adbSRichard Henderson #endif
238696927adbSRichard Henderson }
2387e1b5a5edSRichard Henderson 
2388558c09beSRichard Henderson static bool do_getshadowregs(DisasContext *ctx)
23894a4554c6SHelge Deller {
23904a4554c6SHelge Deller     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
23914a4554c6SHelge Deller     nullify_over(ctx);
2392558c09beSRichard Henderson     tcg_gen_ld_i64(cpu_gr[1], tcg_env, offsetof(CPUHPPAState, shadow[0]));
2393558c09beSRichard Henderson     tcg_gen_ld_i64(cpu_gr[8], tcg_env, offsetof(CPUHPPAState, shadow[1]));
2394558c09beSRichard Henderson     tcg_gen_ld_i64(cpu_gr[9], tcg_env, offsetof(CPUHPPAState, shadow[2]));
2395558c09beSRichard Henderson     tcg_gen_ld_i64(cpu_gr[16], tcg_env, offsetof(CPUHPPAState, shadow[3]));
2396558c09beSRichard Henderson     tcg_gen_ld_i64(cpu_gr[17], tcg_env, offsetof(CPUHPPAState, shadow[4]));
2397558c09beSRichard Henderson     tcg_gen_ld_i64(cpu_gr[24], tcg_env, offsetof(CPUHPPAState, shadow[5]));
2398558c09beSRichard Henderson     tcg_gen_ld_i64(cpu_gr[25], tcg_env, offsetof(CPUHPPAState, shadow[6]));
23994a4554c6SHelge Deller     return nullify_end(ctx);
2400558c09beSRichard Henderson }
2401558c09beSRichard Henderson 
2402*3bdf2081SHelge Deller static bool do_putshadowregs(DisasContext *ctx)
2403*3bdf2081SHelge Deller {
2404*3bdf2081SHelge Deller     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
2405*3bdf2081SHelge Deller     nullify_over(ctx);
2406*3bdf2081SHelge Deller     tcg_gen_st_i64(cpu_gr[1], tcg_env, offsetof(CPUHPPAState, shadow[0]));
2407*3bdf2081SHelge Deller     tcg_gen_st_i64(cpu_gr[8], tcg_env, offsetof(CPUHPPAState, shadow[1]));
2408*3bdf2081SHelge Deller     tcg_gen_st_i64(cpu_gr[9], tcg_env, offsetof(CPUHPPAState, shadow[2]));
2409*3bdf2081SHelge Deller     tcg_gen_st_i64(cpu_gr[16], tcg_env, offsetof(CPUHPPAState, shadow[3]));
2410*3bdf2081SHelge Deller     tcg_gen_st_i64(cpu_gr[17], tcg_env, offsetof(CPUHPPAState, shadow[4]));
2411*3bdf2081SHelge Deller     tcg_gen_st_i64(cpu_gr[24], tcg_env, offsetof(CPUHPPAState, shadow[5]));
2412*3bdf2081SHelge Deller     tcg_gen_st_i64(cpu_gr[25], tcg_env, offsetof(CPUHPPAState, shadow[6]));
2413*3bdf2081SHelge Deller     return nullify_end(ctx);
2414*3bdf2081SHelge Deller }
2415*3bdf2081SHelge Deller 
2416558c09beSRichard Henderson static bool trans_getshadowregs(DisasContext *ctx, arg_getshadowregs *a)
2417558c09beSRichard Henderson {
2418558c09beSRichard Henderson     return do_getshadowregs(ctx);
24194a4554c6SHelge Deller }
24204a4554c6SHelge Deller 
2421deee69a1SRichard Henderson static bool trans_nop_addrx(DisasContext *ctx, arg_ldst *a)
242298a9cb79SRichard Henderson {
2423deee69a1SRichard Henderson     if (a->m) {
24246fd0c7bcSRichard Henderson         TCGv_i64 dest = dest_gpr(ctx, a->b);
24256fd0c7bcSRichard Henderson         TCGv_i64 src1 = load_gpr(ctx, a->b);
24266fd0c7bcSRichard Henderson         TCGv_i64 src2 = load_gpr(ctx, a->x);
242798a9cb79SRichard Henderson 
242898a9cb79SRichard Henderson         /* The only thing we need to do is the base register modification.  */
24296fd0c7bcSRichard Henderson         tcg_gen_add_i64(dest, src1, src2);
2430deee69a1SRichard Henderson         save_gpr(ctx, a->b, dest);
2431deee69a1SRichard Henderson     }
243298a9cb79SRichard Henderson     cond_free(&ctx->null_cond);
243331234768SRichard Henderson     return true;
243498a9cb79SRichard Henderson }
243598a9cb79SRichard Henderson 
2436ad1fdacdSSven Schnelle static bool trans_fic(DisasContext *ctx, arg_ldst *a)
2437ad1fdacdSSven Schnelle {
2438ad1fdacdSSven Schnelle     /* End TB for flush instruction cache, so we pick up new insns. */
2439ad1fdacdSSven Schnelle     ctx->base.is_jmp = DISAS_IAQ_N_STALE;
2440ad1fdacdSSven Schnelle     return trans_nop_addrx(ctx, a);
2441ad1fdacdSSven Schnelle }
2442ad1fdacdSSven Schnelle 
2443deee69a1SRichard Henderson static bool trans_probe(DisasContext *ctx, arg_probe *a)
244498a9cb79SRichard Henderson {
24456fd0c7bcSRichard Henderson     TCGv_i64 dest, ofs;
2446eed14219SRichard Henderson     TCGv_i32 level, want;
24476fd0c7bcSRichard Henderson     TCGv_i64 addr;
244898a9cb79SRichard Henderson 
244998a9cb79SRichard Henderson     nullify_over(ctx);
245098a9cb79SRichard Henderson 
2451deee69a1SRichard Henderson     dest = dest_gpr(ctx, a->t);
2452deee69a1SRichard Henderson     form_gva(ctx, &addr, &ofs, a->b, 0, 0, 0, a->sp, 0, false);
2453eed14219SRichard Henderson 
2454deee69a1SRichard Henderson     if (a->imm) {
2455e5d487c9SRichard Henderson         level = tcg_constant_i32(a->ri & 3);
245698a9cb79SRichard Henderson     } else {
2457eed14219SRichard Henderson         level = tcg_temp_new_i32();
24586fd0c7bcSRichard Henderson         tcg_gen_extrl_i64_i32(level, load_gpr(ctx, a->ri));
2459eed14219SRichard Henderson         tcg_gen_andi_i32(level, level, 3);
246098a9cb79SRichard Henderson     }
246129dd6f64SRichard Henderson     want = tcg_constant_i32(a->write ? PAGE_WRITE : PAGE_READ);
2462eed14219SRichard Henderson 
2463ad75a51eSRichard Henderson     gen_helper_probe(dest, tcg_env, addr, level, want);
2464eed14219SRichard Henderson 
2465deee69a1SRichard Henderson     save_gpr(ctx, a->t, dest);
246631234768SRichard Henderson     return nullify_end(ctx);
246798a9cb79SRichard Henderson }
246898a9cb79SRichard Henderson 
2469deee69a1SRichard Henderson static bool trans_ixtlbx(DisasContext *ctx, arg_ixtlbx *a)
24708d6ae7fbSRichard Henderson {
24718577f354SRichard Henderson     if (ctx->is_pa20) {
24728577f354SRichard Henderson         return false;
24738577f354SRichard Henderson     }
2474deee69a1SRichard Henderson     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
2475deee69a1SRichard Henderson #ifndef CONFIG_USER_ONLY
24766fd0c7bcSRichard Henderson     TCGv_i64 addr;
24776fd0c7bcSRichard Henderson     TCGv_i64 ofs, reg;
24788d6ae7fbSRichard Henderson 
24798d6ae7fbSRichard Henderson     nullify_over(ctx);
24808d6ae7fbSRichard Henderson 
2481deee69a1SRichard Henderson     form_gva(ctx, &addr, &ofs, a->b, 0, 0, 0, a->sp, 0, false);
2482deee69a1SRichard Henderson     reg = load_gpr(ctx, a->r);
2483deee69a1SRichard Henderson     if (a->addr) {
24848577f354SRichard Henderson         gen_helper_itlba_pa11(tcg_env, addr, reg);
24858d6ae7fbSRichard Henderson     } else {
24868577f354SRichard Henderson         gen_helper_itlbp_pa11(tcg_env, addr, reg);
24878d6ae7fbSRichard Henderson     }
24888d6ae7fbSRichard Henderson 
248932dc7569SSven Schnelle     /* Exit TB for TLB change if mmu is enabled.  */
249032dc7569SSven Schnelle     if (ctx->tb_flags & PSW_C) {
249131234768SRichard Henderson         ctx->base.is_jmp = DISAS_IAQ_N_STALE;
249231234768SRichard Henderson     }
249331234768SRichard Henderson     return nullify_end(ctx);
2494deee69a1SRichard Henderson #endif
24958d6ae7fbSRichard Henderson }
249663300a00SRichard Henderson 
2497eb25d10fSHelge Deller static bool do_pxtlb(DisasContext *ctx, arg_ldst *a, bool local)
249863300a00SRichard Henderson {
2499deee69a1SRichard Henderson     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
2500deee69a1SRichard Henderson #ifndef CONFIG_USER_ONLY
25016fd0c7bcSRichard Henderson     TCGv_i64 addr;
25026fd0c7bcSRichard Henderson     TCGv_i64 ofs;
250363300a00SRichard Henderson 
250463300a00SRichard Henderson     nullify_over(ctx);
250563300a00SRichard Henderson 
2506deee69a1SRichard Henderson     form_gva(ctx, &addr, &ofs, a->b, a->x, 0, 0, a->sp, a->m, false);
2507eb25d10fSHelge Deller 
2508eb25d10fSHelge Deller     /*
2509eb25d10fSHelge Deller      * Page align now, rather than later, so that we can add in the
2510eb25d10fSHelge Deller      * page_size field from pa2.0 from the low 4 bits of GR[b].
2511eb25d10fSHelge Deller      */
2512eb25d10fSHelge Deller     tcg_gen_andi_i64(addr, addr, TARGET_PAGE_MASK);
2513eb25d10fSHelge Deller     if (ctx->is_pa20) {
2514eb25d10fSHelge Deller         tcg_gen_deposit_i64(addr, addr, load_gpr(ctx, a->b), 0, 4);
251563300a00SRichard Henderson     }
2516eb25d10fSHelge Deller 
2517eb25d10fSHelge Deller     if (local) {
2518eb25d10fSHelge Deller         gen_helper_ptlb_l(tcg_env, addr);
251963300a00SRichard Henderson     } else {
2520ad75a51eSRichard Henderson         gen_helper_ptlb(tcg_env, addr);
252163300a00SRichard Henderson     }
252263300a00SRichard Henderson 
2523eb25d10fSHelge Deller     if (a->m) {
2524eb25d10fSHelge Deller         save_gpr(ctx, a->b, ofs);
2525eb25d10fSHelge Deller     }
2526eb25d10fSHelge Deller 
2527eb25d10fSHelge Deller     /* Exit TB for TLB change if mmu is enabled.  */
2528eb25d10fSHelge Deller     if (ctx->tb_flags & PSW_C) {
2529eb25d10fSHelge Deller         ctx->base.is_jmp = DISAS_IAQ_N_STALE;
2530eb25d10fSHelge Deller     }
2531eb25d10fSHelge Deller     return nullify_end(ctx);
2532eb25d10fSHelge Deller #endif
2533eb25d10fSHelge Deller }
2534eb25d10fSHelge Deller 
2535eb25d10fSHelge Deller static bool trans_pxtlb(DisasContext *ctx, arg_ldst *a)
2536eb25d10fSHelge Deller {
2537eb25d10fSHelge Deller     return do_pxtlb(ctx, a, false);
2538eb25d10fSHelge Deller }
2539eb25d10fSHelge Deller 
2540eb25d10fSHelge Deller static bool trans_pxtlb_l(DisasContext *ctx, arg_ldst *a)
2541eb25d10fSHelge Deller {
2542eb25d10fSHelge Deller     return ctx->is_pa20 && do_pxtlb(ctx, a, true);
2543eb25d10fSHelge Deller }
2544eb25d10fSHelge Deller 
2545eb25d10fSHelge Deller static bool trans_pxtlbe(DisasContext *ctx, arg_ldst *a)
2546eb25d10fSHelge Deller {
2547eb25d10fSHelge Deller     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
2548eb25d10fSHelge Deller #ifndef CONFIG_USER_ONLY
2549eb25d10fSHelge Deller     nullify_over(ctx);
2550eb25d10fSHelge Deller 
2551eb25d10fSHelge Deller     trans_nop_addrx(ctx, a);
2552eb25d10fSHelge Deller     gen_helper_ptlbe(tcg_env);
2553eb25d10fSHelge Deller 
255463300a00SRichard Henderson     /* Exit TB for TLB change if mmu is enabled.  */
255532dc7569SSven Schnelle     if (ctx->tb_flags & PSW_C) {
255631234768SRichard Henderson         ctx->base.is_jmp = DISAS_IAQ_N_STALE;
255731234768SRichard Henderson     }
255831234768SRichard Henderson     return nullify_end(ctx);
2559deee69a1SRichard Henderson #endif
256063300a00SRichard Henderson }
25612dfcca9fSRichard Henderson 
25626797c315SNick Hudson /*
25636797c315SNick Hudson  * Implement the pcxl and pcxl2 Fast TLB Insert instructions.
25646797c315SNick Hudson  * See
25656797c315SNick Hudson  *     https://parisc.wiki.kernel.org/images-parisc/a/a9/Pcxl2_ers.pdf
25666797c315SNick Hudson  *     page 13-9 (195/206)
25676797c315SNick Hudson  */
25686797c315SNick Hudson static bool trans_ixtlbxf(DisasContext *ctx, arg_ixtlbxf *a)
25696797c315SNick Hudson {
25708577f354SRichard Henderson     if (ctx->is_pa20) {
25718577f354SRichard Henderson         return false;
25728577f354SRichard Henderson     }
25736797c315SNick Hudson     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
25746797c315SNick Hudson #ifndef CONFIG_USER_ONLY
25756fd0c7bcSRichard Henderson     TCGv_i64 addr, atl, stl;
25766fd0c7bcSRichard Henderson     TCGv_i64 reg;
25776797c315SNick Hudson 
25786797c315SNick Hudson     nullify_over(ctx);
25796797c315SNick Hudson 
25806797c315SNick Hudson     /*
25816797c315SNick Hudson      * FIXME:
25826797c315SNick Hudson      *  if (not (pcxl or pcxl2))
25836797c315SNick Hudson      *    return gen_illegal(ctx);
25846797c315SNick Hudson      */
25856797c315SNick Hudson 
25866fd0c7bcSRichard Henderson     atl = tcg_temp_new_i64();
25876fd0c7bcSRichard Henderson     stl = tcg_temp_new_i64();
25886fd0c7bcSRichard Henderson     addr = tcg_temp_new_i64();
25896797c315SNick Hudson 
2590ad75a51eSRichard Henderson     tcg_gen_ld32u_i64(stl, tcg_env,
25916797c315SNick Hudson                       a->data ? offsetof(CPUHPPAState, cr[CR_ISR])
25926797c315SNick Hudson                       : offsetof(CPUHPPAState, cr[CR_IIASQ]));
2593ad75a51eSRichard Henderson     tcg_gen_ld32u_i64(atl, tcg_env,
25946797c315SNick Hudson                       a->data ? offsetof(CPUHPPAState, cr[CR_IOR])
25956797c315SNick Hudson                       : offsetof(CPUHPPAState, cr[CR_IIAOQ]));
25966797c315SNick Hudson     tcg_gen_shli_i64(stl, stl, 32);
2597d265360fSRichard Henderson     tcg_gen_or_i64(addr, atl, stl);
25986797c315SNick Hudson 
25996797c315SNick Hudson     reg = load_gpr(ctx, a->r);
26006797c315SNick Hudson     if (a->addr) {
26018577f354SRichard Henderson         gen_helper_itlba_pa11(tcg_env, addr, reg);
26026797c315SNick Hudson     } else {
26038577f354SRichard Henderson         gen_helper_itlbp_pa11(tcg_env, addr, reg);
26046797c315SNick Hudson     }
26056797c315SNick Hudson 
26066797c315SNick Hudson     /* Exit TB for TLB change if mmu is enabled.  */
26076797c315SNick Hudson     if (ctx->tb_flags & PSW_C) {
26086797c315SNick Hudson         ctx->base.is_jmp = DISAS_IAQ_N_STALE;
26096797c315SNick Hudson     }
26106797c315SNick Hudson     return nullify_end(ctx);
26116797c315SNick Hudson #endif
26126797c315SNick Hudson }
26136797c315SNick Hudson 
26148577f354SRichard Henderson static bool trans_ixtlbt(DisasContext *ctx, arg_ixtlbt *a)
26158577f354SRichard Henderson {
26168577f354SRichard Henderson     if (!ctx->is_pa20) {
26178577f354SRichard Henderson         return false;
26188577f354SRichard Henderson     }
26198577f354SRichard Henderson     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
26208577f354SRichard Henderson #ifndef CONFIG_USER_ONLY
26218577f354SRichard Henderson     nullify_over(ctx);
26228577f354SRichard Henderson     {
26238577f354SRichard Henderson         TCGv_i64 src1 = load_gpr(ctx, a->r1);
26248577f354SRichard Henderson         TCGv_i64 src2 = load_gpr(ctx, a->r2);
26258577f354SRichard Henderson 
26268577f354SRichard Henderson         if (a->data) {
26278577f354SRichard Henderson             gen_helper_idtlbt_pa20(tcg_env, src1, src2);
26288577f354SRichard Henderson         } else {
26298577f354SRichard Henderson             gen_helper_iitlbt_pa20(tcg_env, src1, src2);
26308577f354SRichard Henderson         }
26318577f354SRichard Henderson     }
26328577f354SRichard Henderson     /* Exit TB for TLB change if mmu is enabled.  */
26338577f354SRichard Henderson     if (ctx->tb_flags & PSW_C) {
26348577f354SRichard Henderson         ctx->base.is_jmp = DISAS_IAQ_N_STALE;
26358577f354SRichard Henderson     }
26368577f354SRichard Henderson     return nullify_end(ctx);
26378577f354SRichard Henderson #endif
26388577f354SRichard Henderson }
26398577f354SRichard Henderson 
2640deee69a1SRichard Henderson static bool trans_lpa(DisasContext *ctx, arg_ldst *a)
26412dfcca9fSRichard Henderson {
2642deee69a1SRichard Henderson     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
2643deee69a1SRichard Henderson #ifndef CONFIG_USER_ONLY
26446fd0c7bcSRichard Henderson     TCGv_i64 vaddr;
26456fd0c7bcSRichard Henderson     TCGv_i64 ofs, paddr;
26462dfcca9fSRichard Henderson 
26472dfcca9fSRichard Henderson     nullify_over(ctx);
26482dfcca9fSRichard Henderson 
2649deee69a1SRichard Henderson     form_gva(ctx, &vaddr, &ofs, a->b, a->x, 0, 0, a->sp, a->m, false);
26502dfcca9fSRichard Henderson 
2651aac0f603SRichard Henderson     paddr = tcg_temp_new_i64();
2652ad75a51eSRichard Henderson     gen_helper_lpa(paddr, tcg_env, vaddr);
26532dfcca9fSRichard Henderson 
26542dfcca9fSRichard Henderson     /* Note that physical address result overrides base modification.  */
2655deee69a1SRichard Henderson     if (a->m) {
2656deee69a1SRichard Henderson         save_gpr(ctx, a->b, ofs);
26572dfcca9fSRichard Henderson     }
2658deee69a1SRichard Henderson     save_gpr(ctx, a->t, paddr);
26592dfcca9fSRichard Henderson 
266031234768SRichard Henderson     return nullify_end(ctx);
2661deee69a1SRichard Henderson #endif
26622dfcca9fSRichard Henderson }
266343a97b81SRichard Henderson 
2664deee69a1SRichard Henderson static bool trans_lci(DisasContext *ctx, arg_lci *a)
266543a97b81SRichard Henderson {
266643a97b81SRichard Henderson     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
266743a97b81SRichard Henderson 
266843a97b81SRichard Henderson     /* The Coherence Index is an implementation-defined function of the
266943a97b81SRichard Henderson        physical address.  Two addresses with the same CI have a coherent
267043a97b81SRichard Henderson        view of the cache.  Our implementation is to return 0 for all,
267143a97b81SRichard Henderson        since the entire address space is coherent.  */
2672a4db4a78SRichard Henderson     save_gpr(ctx, a->t, ctx->zero);
267343a97b81SRichard Henderson 
267431234768SRichard Henderson     cond_free(&ctx->null_cond);
267531234768SRichard Henderson     return true;
267643a97b81SRichard Henderson }
267798a9cb79SRichard Henderson 
2678faf97ba1SRichard Henderson static bool trans_add(DisasContext *ctx, arg_rrr_cf_d_sh *a)
2679b2167459SRichard Henderson {
26800c982a28SRichard Henderson     return do_add_reg(ctx, a, false, false, false, false);
2681b2167459SRichard Henderson }
2682b2167459SRichard Henderson 
2683faf97ba1SRichard Henderson static bool trans_add_l(DisasContext *ctx, arg_rrr_cf_d_sh *a)
2684b2167459SRichard Henderson {
26850c982a28SRichard Henderson     return do_add_reg(ctx, a, true, false, false, false);
2686b2167459SRichard Henderson }
2687b2167459SRichard Henderson 
2688faf97ba1SRichard Henderson static bool trans_add_tsv(DisasContext *ctx, arg_rrr_cf_d_sh *a)
2689b2167459SRichard Henderson {
26900c982a28SRichard Henderson     return do_add_reg(ctx, a, false, true, false, false);
2691b2167459SRichard Henderson }
2692b2167459SRichard Henderson 
2693faf97ba1SRichard Henderson static bool trans_add_c(DisasContext *ctx, arg_rrr_cf_d_sh *a)
2694b2167459SRichard Henderson {
26950c982a28SRichard Henderson     return do_add_reg(ctx, a, false, false, false, true);
26960c982a28SRichard Henderson }
2697b2167459SRichard Henderson 
2698faf97ba1SRichard Henderson static bool trans_add_c_tsv(DisasContext *ctx, arg_rrr_cf_d_sh *a)
26990c982a28SRichard Henderson {
27000c982a28SRichard Henderson     return do_add_reg(ctx, a, false, true, false, true);
27010c982a28SRichard Henderson }
27020c982a28SRichard Henderson 
270363c427c6SRichard Henderson static bool trans_sub(DisasContext *ctx, arg_rrr_cf_d *a)
27040c982a28SRichard Henderson {
27050c982a28SRichard Henderson     return do_sub_reg(ctx, a, false, false, false);
27060c982a28SRichard Henderson }
27070c982a28SRichard Henderson 
270863c427c6SRichard Henderson static bool trans_sub_tsv(DisasContext *ctx, arg_rrr_cf_d *a)
27090c982a28SRichard Henderson {
27100c982a28SRichard Henderson     return do_sub_reg(ctx, a, true, false, false);
27110c982a28SRichard Henderson }
27120c982a28SRichard Henderson 
271363c427c6SRichard Henderson static bool trans_sub_tc(DisasContext *ctx, arg_rrr_cf_d *a)
27140c982a28SRichard Henderson {
27150c982a28SRichard Henderson     return do_sub_reg(ctx, a, false, false, true);
27160c982a28SRichard Henderson }
27170c982a28SRichard Henderson 
271863c427c6SRichard Henderson static bool trans_sub_tsv_tc(DisasContext *ctx, arg_rrr_cf_d *a)
27190c982a28SRichard Henderson {
27200c982a28SRichard Henderson     return do_sub_reg(ctx, a, true, false, true);
27210c982a28SRichard Henderson }
27220c982a28SRichard Henderson 
272363c427c6SRichard Henderson static bool trans_sub_b(DisasContext *ctx, arg_rrr_cf_d *a)
27240c982a28SRichard Henderson {
27250c982a28SRichard Henderson     return do_sub_reg(ctx, a, false, true, false);
27260c982a28SRichard Henderson }
27270c982a28SRichard Henderson 
272863c427c6SRichard Henderson static bool trans_sub_b_tsv(DisasContext *ctx, arg_rrr_cf_d *a)
27290c982a28SRichard Henderson {
27300c982a28SRichard Henderson     return do_sub_reg(ctx, a, true, true, false);
27310c982a28SRichard Henderson }
27320c982a28SRichard Henderson 
2733fa8e3bedSRichard Henderson static bool trans_andcm(DisasContext *ctx, arg_rrr_cf_d *a)
27340c982a28SRichard Henderson {
27356fd0c7bcSRichard Henderson     return do_log_reg(ctx, a, tcg_gen_andc_i64);
27360c982a28SRichard Henderson }
27370c982a28SRichard Henderson 
2738fa8e3bedSRichard Henderson static bool trans_and(DisasContext *ctx, arg_rrr_cf_d *a)
27390c982a28SRichard Henderson {
27406fd0c7bcSRichard Henderson     return do_log_reg(ctx, a, tcg_gen_and_i64);
27410c982a28SRichard Henderson }
27420c982a28SRichard Henderson 
2743fa8e3bedSRichard Henderson static bool trans_or(DisasContext *ctx, arg_rrr_cf_d *a)
27440c982a28SRichard Henderson {
27450c982a28SRichard Henderson     if (a->cf == 0) {
27460c982a28SRichard Henderson         unsigned r2 = a->r2;
27470c982a28SRichard Henderson         unsigned r1 = a->r1;
27480c982a28SRichard Henderson         unsigned rt = a->t;
27490c982a28SRichard Henderson 
27507aee8189SRichard Henderson         if (rt == 0) { /* NOP */
27517aee8189SRichard Henderson             cond_free(&ctx->null_cond);
27527aee8189SRichard Henderson             return true;
27537aee8189SRichard Henderson         }
27547aee8189SRichard Henderson         if (r2 == 0) { /* COPY */
2755b2167459SRichard Henderson             if (r1 == 0) {
27566fd0c7bcSRichard Henderson                 TCGv_i64 dest = dest_gpr(ctx, rt);
27576fd0c7bcSRichard Henderson                 tcg_gen_movi_i64(dest, 0);
2758b2167459SRichard Henderson                 save_gpr(ctx, rt, dest);
2759b2167459SRichard Henderson             } else {
2760b2167459SRichard Henderson                 save_gpr(ctx, rt, cpu_gr[r1]);
2761b2167459SRichard Henderson             }
2762b2167459SRichard Henderson             cond_free(&ctx->null_cond);
276331234768SRichard Henderson             return true;
2764b2167459SRichard Henderson         }
27657aee8189SRichard Henderson #ifndef CONFIG_USER_ONLY
27667aee8189SRichard Henderson         /* These are QEMU extensions and are nops in the real architecture:
27677aee8189SRichard Henderson          *
27687aee8189SRichard Henderson          * or %r10,%r10,%r10 -- idle loop; wait for interrupt
27697aee8189SRichard Henderson          * or %r31,%r31,%r31 -- death loop; offline cpu
27707aee8189SRichard Henderson          *                      currently implemented as idle.
27717aee8189SRichard Henderson          */
27727aee8189SRichard Henderson         if ((rt == 10 || rt == 31) && r1 == rt && r2 == rt) { /* PAUSE */
27737aee8189SRichard Henderson             /* No need to check for supervisor, as userland can only pause
27747aee8189SRichard Henderson                until the next timer interrupt.  */
27757aee8189SRichard Henderson             nullify_over(ctx);
27767aee8189SRichard Henderson 
27777aee8189SRichard Henderson             /* Advance the instruction queue.  */
2778741322f4SRichard Henderson             copy_iaoq_entry(ctx, cpu_iaoq_f, ctx->iaoq_b, cpu_iaoq_b);
2779741322f4SRichard Henderson             copy_iaoq_entry(ctx, cpu_iaoq_b, ctx->iaoq_n, ctx->iaoq_n_var);
27807aee8189SRichard Henderson             nullify_set(ctx, 0);
27817aee8189SRichard Henderson 
27827aee8189SRichard Henderson             /* Tell the qemu main loop to halt until this cpu has work.  */
2783ad75a51eSRichard Henderson             tcg_gen_st_i32(tcg_constant_i32(1), tcg_env,
278429dd6f64SRichard Henderson                            offsetof(CPUState, halted) - offsetof(HPPACPU, env));
27857aee8189SRichard Henderson             gen_excp_1(EXCP_HALTED);
27867aee8189SRichard Henderson             ctx->base.is_jmp = DISAS_NORETURN;
27877aee8189SRichard Henderson 
27887aee8189SRichard Henderson             return nullify_end(ctx);
27897aee8189SRichard Henderson         }
27907aee8189SRichard Henderson #endif
27917aee8189SRichard Henderson     }
27926fd0c7bcSRichard Henderson     return do_log_reg(ctx, a, tcg_gen_or_i64);
27937aee8189SRichard Henderson }
2794b2167459SRichard Henderson 
2795fa8e3bedSRichard Henderson static bool trans_xor(DisasContext *ctx, arg_rrr_cf_d *a)
2796b2167459SRichard Henderson {
27976fd0c7bcSRichard Henderson     return do_log_reg(ctx, a, tcg_gen_xor_i64);
27980c982a28SRichard Henderson }
27990c982a28SRichard Henderson 
2800345aa35fSRichard Henderson static bool trans_cmpclr(DisasContext *ctx, arg_rrr_cf_d *a)
28010c982a28SRichard Henderson {
28026fd0c7bcSRichard Henderson     TCGv_i64 tcg_r1, tcg_r2;
2803b2167459SRichard Henderson 
28040c982a28SRichard Henderson     if (a->cf) {
2805b2167459SRichard Henderson         nullify_over(ctx);
2806b2167459SRichard Henderson     }
28070c982a28SRichard Henderson     tcg_r1 = load_gpr(ctx, a->r1);
28080c982a28SRichard Henderson     tcg_r2 = load_gpr(ctx, a->r2);
2809345aa35fSRichard Henderson     do_cmpclr(ctx, a->t, tcg_r1, tcg_r2, a->cf, a->d);
281031234768SRichard Henderson     return nullify_end(ctx);
2811b2167459SRichard Henderson }
2812b2167459SRichard Henderson 
2813af240753SRichard Henderson static bool trans_uxor(DisasContext *ctx, arg_rrr_cf_d *a)
2814b2167459SRichard Henderson {
281546bb3d46SRichard Henderson     TCGv_i64 tcg_r1, tcg_r2, dest;
2816b2167459SRichard Henderson 
28170c982a28SRichard Henderson     if (a->cf) {
2818b2167459SRichard Henderson         nullify_over(ctx);
2819b2167459SRichard Henderson     }
282046bb3d46SRichard Henderson 
28210c982a28SRichard Henderson     tcg_r1 = load_gpr(ctx, a->r1);
28220c982a28SRichard Henderson     tcg_r2 = load_gpr(ctx, a->r2);
282346bb3d46SRichard Henderson     dest = dest_gpr(ctx, a->t);
282446bb3d46SRichard Henderson 
282546bb3d46SRichard Henderson     tcg_gen_xor_i64(dest, tcg_r1, tcg_r2);
282646bb3d46SRichard Henderson     save_gpr(ctx, a->t, dest);
282746bb3d46SRichard Henderson 
282846bb3d46SRichard Henderson     cond_free(&ctx->null_cond);
282946bb3d46SRichard Henderson     if (a->cf) {
283046bb3d46SRichard Henderson         ctx->null_cond = do_unit_zero_cond(a->cf, a->d, dest);
283146bb3d46SRichard Henderson     }
283246bb3d46SRichard Henderson 
283331234768SRichard Henderson     return nullify_end(ctx);
2834b2167459SRichard Henderson }
2835b2167459SRichard Henderson 
2836af240753SRichard Henderson static bool do_uaddcm(DisasContext *ctx, arg_rrr_cf_d *a, bool is_tc)
2837b2167459SRichard Henderson {
28386fd0c7bcSRichard Henderson     TCGv_i64 tcg_r1, tcg_r2, tmp;
2839b2167459SRichard Henderson 
2840ababac16SRichard Henderson     if (a->cf == 0) {
2841ababac16SRichard Henderson         tcg_r2 = load_gpr(ctx, a->r2);
2842ababac16SRichard Henderson         tmp = dest_gpr(ctx, a->t);
2843ababac16SRichard Henderson 
2844ababac16SRichard Henderson         if (a->r1 == 0) {
2845ababac16SRichard Henderson             /* UADDCM r0,src,dst is the common idiom for dst = ~src. */
2846ababac16SRichard Henderson             tcg_gen_not_i64(tmp, tcg_r2);
2847ababac16SRichard Henderson         } else {
2848ababac16SRichard Henderson             /*
2849ababac16SRichard Henderson              * Recall that r1 - r2 == r1 + ~r2 + 1.
2850ababac16SRichard Henderson              * Thus r1 + ~r2 == r1 - r2 - 1,
2851ababac16SRichard Henderson              * which does not require an extra temporary.
2852ababac16SRichard Henderson              */
2853ababac16SRichard Henderson             tcg_r1 = load_gpr(ctx, a->r1);
2854ababac16SRichard Henderson             tcg_gen_sub_i64(tmp, tcg_r1, tcg_r2);
2855ababac16SRichard Henderson             tcg_gen_subi_i64(tmp, tmp, 1);
2856b2167459SRichard Henderson         }
2857ababac16SRichard Henderson         save_gpr(ctx, a->t, tmp);
2858ababac16SRichard Henderson         cond_free(&ctx->null_cond);
2859ababac16SRichard Henderson         return true;
2860ababac16SRichard Henderson     }
2861ababac16SRichard Henderson 
2862ababac16SRichard Henderson     nullify_over(ctx);
28630c982a28SRichard Henderson     tcg_r1 = load_gpr(ctx, a->r1);
28640c982a28SRichard Henderson     tcg_r2 = load_gpr(ctx, a->r2);
2865aac0f603SRichard Henderson     tmp = tcg_temp_new_i64();
28666fd0c7bcSRichard Henderson     tcg_gen_not_i64(tmp, tcg_r2);
286746bb3d46SRichard Henderson     do_unit_addsub(ctx, a->t, tcg_r1, tmp, a->cf, a->d, is_tc, true);
286831234768SRichard Henderson     return nullify_end(ctx);
2869b2167459SRichard Henderson }
2870b2167459SRichard Henderson 
2871af240753SRichard Henderson static bool trans_uaddcm(DisasContext *ctx, arg_rrr_cf_d *a)
2872b2167459SRichard Henderson {
28730c982a28SRichard Henderson     return do_uaddcm(ctx, a, false);
28740c982a28SRichard Henderson }
28750c982a28SRichard Henderson 
2876af240753SRichard Henderson static bool trans_uaddcm_tc(DisasContext *ctx, arg_rrr_cf_d *a)
28770c982a28SRichard Henderson {
28780c982a28SRichard Henderson     return do_uaddcm(ctx, a, true);
28790c982a28SRichard Henderson }
28800c982a28SRichard Henderson 
2881af240753SRichard Henderson static bool do_dcor(DisasContext *ctx, arg_rr_cf_d *a, bool is_i)
28820c982a28SRichard Henderson {
28836fd0c7bcSRichard Henderson     TCGv_i64 tmp;
2884b2167459SRichard Henderson 
2885b2167459SRichard Henderson     nullify_over(ctx);
2886b2167459SRichard Henderson 
2887aac0f603SRichard Henderson     tmp = tcg_temp_new_i64();
2888d0ae87a2SRichard Henderson     tcg_gen_extract2_i64(tmp, cpu_psw_cb, cpu_psw_cb_msb, 4);
2889b2167459SRichard Henderson     if (!is_i) {
28906fd0c7bcSRichard Henderson         tcg_gen_not_i64(tmp, tmp);
2891b2167459SRichard Henderson     }
28926fd0c7bcSRichard Henderson     tcg_gen_andi_i64(tmp, tmp, (uint64_t)0x1111111111111111ull);
28936fd0c7bcSRichard Henderson     tcg_gen_muli_i64(tmp, tmp, 6);
289446bb3d46SRichard Henderson     do_unit_addsub(ctx, a->t, load_gpr(ctx, a->r), tmp,
289546bb3d46SRichard Henderson                    a->cf, a->d, false, is_i);
289631234768SRichard Henderson     return nullify_end(ctx);
2897b2167459SRichard Henderson }
2898b2167459SRichard Henderson 
2899af240753SRichard Henderson static bool trans_dcor(DisasContext *ctx, arg_rr_cf_d *a)
2900b2167459SRichard Henderson {
29010c982a28SRichard Henderson     return do_dcor(ctx, a, false);
29020c982a28SRichard Henderson }
29030c982a28SRichard Henderson 
2904af240753SRichard Henderson static bool trans_dcor_i(DisasContext *ctx, arg_rr_cf_d *a)
29050c982a28SRichard Henderson {
29060c982a28SRichard Henderson     return do_dcor(ctx, a, true);
29070c982a28SRichard Henderson }
29080c982a28SRichard Henderson 
29090c982a28SRichard Henderson static bool trans_ds(DisasContext *ctx, arg_rrr_cf *a)
29100c982a28SRichard Henderson {
2911a4db4a78SRichard Henderson     TCGv_i64 dest, add1, add2, addc, in1, in2;
2912b2167459SRichard Henderson 
2913b2167459SRichard Henderson     nullify_over(ctx);
2914b2167459SRichard Henderson 
29150c982a28SRichard Henderson     in1 = load_gpr(ctx, a->r1);
29160c982a28SRichard Henderson     in2 = load_gpr(ctx, a->r2);
2917b2167459SRichard Henderson 
2918aac0f603SRichard Henderson     add1 = tcg_temp_new_i64();
2919aac0f603SRichard Henderson     add2 = tcg_temp_new_i64();
2920aac0f603SRichard Henderson     addc = tcg_temp_new_i64();
2921aac0f603SRichard Henderson     dest = tcg_temp_new_i64();
2922b2167459SRichard Henderson 
2923b2167459SRichard Henderson     /* Form R1 << 1 | PSW[CB]{8}.  */
29246fd0c7bcSRichard Henderson     tcg_gen_add_i64(add1, in1, in1);
29256fd0c7bcSRichard Henderson     tcg_gen_add_i64(add1, add1, get_psw_carry(ctx, false));
2926b2167459SRichard Henderson 
292772ca8753SRichard Henderson     /*
292872ca8753SRichard Henderson      * Add or subtract R2, depending on PSW[V].  Proper computation of
292972ca8753SRichard Henderson      * carry requires that we subtract via + ~R2 + 1, as described in
293072ca8753SRichard Henderson      * the manual.  By extracting and masking V, we can produce the
293172ca8753SRichard Henderson      * proper inputs to the addition without movcond.
293272ca8753SRichard Henderson      */
29336fd0c7bcSRichard Henderson     tcg_gen_sextract_i64(addc, cpu_psw_v, 31, 1);
29346fd0c7bcSRichard Henderson     tcg_gen_xor_i64(add2, in2, addc);
29356fd0c7bcSRichard Henderson     tcg_gen_andi_i64(addc, addc, 1);
293672ca8753SRichard Henderson 
2937a4db4a78SRichard Henderson     tcg_gen_add2_i64(dest, cpu_psw_cb_msb, add1, ctx->zero, add2, ctx->zero);
2938a4db4a78SRichard Henderson     tcg_gen_add2_i64(dest, cpu_psw_cb_msb, dest, cpu_psw_cb_msb,
2939a4db4a78SRichard Henderson                      addc, ctx->zero);
2940b2167459SRichard Henderson 
2941b2167459SRichard Henderson     /* Write back the result register.  */
29420c982a28SRichard Henderson     save_gpr(ctx, a->t, dest);
2943b2167459SRichard Henderson 
2944b2167459SRichard Henderson     /* Write back PSW[CB].  */
29456fd0c7bcSRichard Henderson     tcg_gen_xor_i64(cpu_psw_cb, add1, add2);
29466fd0c7bcSRichard Henderson     tcg_gen_xor_i64(cpu_psw_cb, cpu_psw_cb, dest);
2947b2167459SRichard Henderson 
2948f8f5986eSRichard Henderson     /*
2949f8f5986eSRichard Henderson      * Write back PSW[V] for the division step.
2950f8f5986eSRichard Henderson      * Shift cb{8} from where it lives in bit 32 to bit 31,
2951f8f5986eSRichard Henderson      * so that it overlaps r2{32} in bit 31.
2952f8f5986eSRichard Henderson      */
2953f8f5986eSRichard Henderson     tcg_gen_shri_i64(cpu_psw_v, cpu_psw_cb, 1);
29546fd0c7bcSRichard Henderson     tcg_gen_xor_i64(cpu_psw_v, cpu_psw_v, in2);
2955b2167459SRichard Henderson 
2956b2167459SRichard Henderson     /* Install the new nullification.  */
29570c982a28SRichard Henderson     if (a->cf) {
2958f8f5986eSRichard Henderson         TCGv_i64 sv = NULL, uv = NULL;
2959b47a4a02SSven Schnelle         if (cond_need_sv(a->cf >> 1)) {
2960f8f5986eSRichard Henderson             sv = do_add_sv(ctx, dest, add1, add2, in1, 1, false);
2961f8f5986eSRichard Henderson         } else if (cond_need_cb(a->cf >> 1)) {
2962f8f5986eSRichard Henderson             uv = do_add_uv(ctx, cpu_psw_cb, NULL, in1, 1, false);
2963b2167459SRichard Henderson         }
2964f8f5986eSRichard Henderson         ctx->null_cond = do_cond(ctx, a->cf, false, dest, uv, sv);
2965b2167459SRichard Henderson     }
2966b2167459SRichard Henderson 
296731234768SRichard Henderson     return nullify_end(ctx);
2968b2167459SRichard Henderson }
2969b2167459SRichard Henderson 
29700588e061SRichard Henderson static bool trans_addi(DisasContext *ctx, arg_rri_cf *a)
2971b2167459SRichard Henderson {
29720588e061SRichard Henderson     return do_add_imm(ctx, a, false, false);
29730588e061SRichard Henderson }
29740588e061SRichard Henderson 
29750588e061SRichard Henderson static bool trans_addi_tsv(DisasContext *ctx, arg_rri_cf *a)
29760588e061SRichard Henderson {
29770588e061SRichard Henderson     return do_add_imm(ctx, a, true, false);
29780588e061SRichard Henderson }
29790588e061SRichard Henderson 
29800588e061SRichard Henderson static bool trans_addi_tc(DisasContext *ctx, arg_rri_cf *a)
29810588e061SRichard Henderson {
29820588e061SRichard Henderson     return do_add_imm(ctx, a, false, true);
29830588e061SRichard Henderson }
29840588e061SRichard Henderson 
29850588e061SRichard Henderson static bool trans_addi_tc_tsv(DisasContext *ctx, arg_rri_cf *a)
29860588e061SRichard Henderson {
29870588e061SRichard Henderson     return do_add_imm(ctx, a, true, true);
29880588e061SRichard Henderson }
29890588e061SRichard Henderson 
29900588e061SRichard Henderson static bool trans_subi(DisasContext *ctx, arg_rri_cf *a)
29910588e061SRichard Henderson {
29920588e061SRichard Henderson     return do_sub_imm(ctx, a, false);
29930588e061SRichard Henderson }
29940588e061SRichard Henderson 
29950588e061SRichard Henderson static bool trans_subi_tsv(DisasContext *ctx, arg_rri_cf *a)
29960588e061SRichard Henderson {
29970588e061SRichard Henderson     return do_sub_imm(ctx, a, true);
29980588e061SRichard Henderson }
29990588e061SRichard Henderson 
3000345aa35fSRichard Henderson static bool trans_cmpiclr(DisasContext *ctx, arg_rri_cf_d *a)
30010588e061SRichard Henderson {
30026fd0c7bcSRichard Henderson     TCGv_i64 tcg_im, tcg_r2;
3003b2167459SRichard Henderson 
30040588e061SRichard Henderson     if (a->cf) {
3005b2167459SRichard Henderson         nullify_over(ctx);
3006b2167459SRichard Henderson     }
3007b2167459SRichard Henderson 
30086fd0c7bcSRichard Henderson     tcg_im = tcg_constant_i64(a->i);
30090588e061SRichard Henderson     tcg_r2 = load_gpr(ctx, a->r);
3010345aa35fSRichard Henderson     do_cmpclr(ctx, a->t, tcg_im, tcg_r2, a->cf, a->d);
3011b2167459SRichard Henderson 
301231234768SRichard Henderson     return nullify_end(ctx);
3013b2167459SRichard Henderson }
3014b2167459SRichard Henderson 
30150843563fSRichard Henderson static bool do_multimedia(DisasContext *ctx, arg_rrr *a,
30160843563fSRichard Henderson                           void (*fn)(TCGv_i64, TCGv_i64, TCGv_i64))
30170843563fSRichard Henderson {
30180843563fSRichard Henderson     TCGv_i64 r1, r2, dest;
30190843563fSRichard Henderson 
30200843563fSRichard Henderson     if (!ctx->is_pa20) {
30210843563fSRichard Henderson         return false;
30220843563fSRichard Henderson     }
30230843563fSRichard Henderson 
30240843563fSRichard Henderson     nullify_over(ctx);
30250843563fSRichard Henderson 
30260843563fSRichard Henderson     r1 = load_gpr(ctx, a->r1);
30270843563fSRichard Henderson     r2 = load_gpr(ctx, a->r2);
30280843563fSRichard Henderson     dest = dest_gpr(ctx, a->t);
30290843563fSRichard Henderson 
30300843563fSRichard Henderson     fn(dest, r1, r2);
30310843563fSRichard Henderson     save_gpr(ctx, a->t, dest);
30320843563fSRichard Henderson 
30330843563fSRichard Henderson     return nullify_end(ctx);
30340843563fSRichard Henderson }
30350843563fSRichard Henderson 
3036151f309bSRichard Henderson static bool do_multimedia_sh(DisasContext *ctx, arg_rri *a,
3037151f309bSRichard Henderson                              void (*fn)(TCGv_i64, TCGv_i64, int64_t))
3038151f309bSRichard Henderson {
3039151f309bSRichard Henderson     TCGv_i64 r, dest;
3040151f309bSRichard Henderson 
3041151f309bSRichard Henderson     if (!ctx->is_pa20) {
3042151f309bSRichard Henderson         return false;
3043151f309bSRichard Henderson     }
3044151f309bSRichard Henderson 
3045151f309bSRichard Henderson     nullify_over(ctx);
3046151f309bSRichard Henderson 
3047151f309bSRichard Henderson     r = load_gpr(ctx, a->r);
3048151f309bSRichard Henderson     dest = dest_gpr(ctx, a->t);
3049151f309bSRichard Henderson 
3050151f309bSRichard Henderson     fn(dest, r, a->i);
3051151f309bSRichard Henderson     save_gpr(ctx, a->t, dest);
3052151f309bSRichard Henderson 
3053151f309bSRichard Henderson     return nullify_end(ctx);
3054151f309bSRichard Henderson }
3055151f309bSRichard Henderson 
30563bbb8e48SRichard Henderson static bool do_multimedia_shadd(DisasContext *ctx, arg_rrr_sh *a,
30573bbb8e48SRichard Henderson                                 void (*fn)(TCGv_i64, TCGv_i64,
30583bbb8e48SRichard Henderson                                            TCGv_i64, TCGv_i32))
30593bbb8e48SRichard Henderson {
30603bbb8e48SRichard Henderson     TCGv_i64 r1, r2, dest;
30613bbb8e48SRichard Henderson 
30623bbb8e48SRichard Henderson     if (!ctx->is_pa20) {
30633bbb8e48SRichard Henderson         return false;
30643bbb8e48SRichard Henderson     }
30653bbb8e48SRichard Henderson 
30663bbb8e48SRichard Henderson     nullify_over(ctx);
30673bbb8e48SRichard Henderson 
30683bbb8e48SRichard Henderson     r1 = load_gpr(ctx, a->r1);
30693bbb8e48SRichard Henderson     r2 = load_gpr(ctx, a->r2);
30703bbb8e48SRichard Henderson     dest = dest_gpr(ctx, a->t);
30713bbb8e48SRichard Henderson 
30723bbb8e48SRichard Henderson     fn(dest, r1, r2, tcg_constant_i32(a->sh));
30733bbb8e48SRichard Henderson     save_gpr(ctx, a->t, dest);
30743bbb8e48SRichard Henderson 
30753bbb8e48SRichard Henderson     return nullify_end(ctx);
30763bbb8e48SRichard Henderson }
30773bbb8e48SRichard Henderson 
30780843563fSRichard Henderson static bool trans_hadd(DisasContext *ctx, arg_rrr *a)
30790843563fSRichard Henderson {
30800843563fSRichard Henderson     return do_multimedia(ctx, a, tcg_gen_vec_add16_i64);
30810843563fSRichard Henderson }
30820843563fSRichard Henderson 
30830843563fSRichard Henderson static bool trans_hadd_ss(DisasContext *ctx, arg_rrr *a)
30840843563fSRichard Henderson {
30850843563fSRichard Henderson     return do_multimedia(ctx, a, gen_helper_hadd_ss);
30860843563fSRichard Henderson }
30870843563fSRichard Henderson 
30880843563fSRichard Henderson static bool trans_hadd_us(DisasContext *ctx, arg_rrr *a)
30890843563fSRichard Henderson {
30900843563fSRichard Henderson     return do_multimedia(ctx, a, gen_helper_hadd_us);
30910843563fSRichard Henderson }
30920843563fSRichard Henderson 
30931b3cb7c8SRichard Henderson static bool trans_havg(DisasContext *ctx, arg_rrr *a)
30941b3cb7c8SRichard Henderson {
30951b3cb7c8SRichard Henderson     return do_multimedia(ctx, a, gen_helper_havg);
30961b3cb7c8SRichard Henderson }
30971b3cb7c8SRichard Henderson 
3098151f309bSRichard Henderson static bool trans_hshl(DisasContext *ctx, arg_rri *a)
3099151f309bSRichard Henderson {
3100151f309bSRichard Henderson     return do_multimedia_sh(ctx, a, tcg_gen_vec_shl16i_i64);
3101151f309bSRichard Henderson }
3102151f309bSRichard Henderson 
3103151f309bSRichard Henderson static bool trans_hshr_s(DisasContext *ctx, arg_rri *a)
3104151f309bSRichard Henderson {
3105151f309bSRichard Henderson     return do_multimedia_sh(ctx, a, tcg_gen_vec_sar16i_i64);
3106151f309bSRichard Henderson }
3107151f309bSRichard Henderson 
3108151f309bSRichard Henderson static bool trans_hshr_u(DisasContext *ctx, arg_rri *a)
3109151f309bSRichard Henderson {
3110151f309bSRichard Henderson     return do_multimedia_sh(ctx, a, tcg_gen_vec_shr16i_i64);
3111151f309bSRichard Henderson }
3112151f309bSRichard Henderson 
31133bbb8e48SRichard Henderson static bool trans_hshladd(DisasContext *ctx, arg_rrr_sh *a)
31143bbb8e48SRichard Henderson {
31153bbb8e48SRichard Henderson     return do_multimedia_shadd(ctx, a, gen_helper_hshladd);
31163bbb8e48SRichard Henderson }
31173bbb8e48SRichard Henderson 
31183bbb8e48SRichard Henderson static bool trans_hshradd(DisasContext *ctx, arg_rrr_sh *a)
31193bbb8e48SRichard Henderson {
31203bbb8e48SRichard Henderson     return do_multimedia_shadd(ctx, a, gen_helper_hshradd);
31213bbb8e48SRichard Henderson }
31223bbb8e48SRichard Henderson 
312310c9e58dSRichard Henderson static bool trans_hsub(DisasContext *ctx, arg_rrr *a)
312410c9e58dSRichard Henderson {
312510c9e58dSRichard Henderson     return do_multimedia(ctx, a, tcg_gen_vec_sub16_i64);
312610c9e58dSRichard Henderson }
312710c9e58dSRichard Henderson 
312810c9e58dSRichard Henderson static bool trans_hsub_ss(DisasContext *ctx, arg_rrr *a)
312910c9e58dSRichard Henderson {
313010c9e58dSRichard Henderson     return do_multimedia(ctx, a, gen_helper_hsub_ss);
313110c9e58dSRichard Henderson }
313210c9e58dSRichard Henderson 
313310c9e58dSRichard Henderson static bool trans_hsub_us(DisasContext *ctx, arg_rrr *a)
313410c9e58dSRichard Henderson {
313510c9e58dSRichard Henderson     return do_multimedia(ctx, a, gen_helper_hsub_us);
313610c9e58dSRichard Henderson }
313710c9e58dSRichard Henderson 
3138c2a7ee3fSRichard Henderson static void gen_mixh_l(TCGv_i64 dst, TCGv_i64 r1, TCGv_i64 r2)
3139c2a7ee3fSRichard Henderson {
3140c2a7ee3fSRichard Henderson     uint64_t mask = 0xffff0000ffff0000ull;
3141c2a7ee3fSRichard Henderson     TCGv_i64 tmp = tcg_temp_new_i64();
3142c2a7ee3fSRichard Henderson 
3143c2a7ee3fSRichard Henderson     tcg_gen_andi_i64(tmp, r2, mask);
3144c2a7ee3fSRichard Henderson     tcg_gen_andi_i64(dst, r1, mask);
3145c2a7ee3fSRichard Henderson     tcg_gen_shri_i64(tmp, tmp, 16);
3146c2a7ee3fSRichard Henderson     tcg_gen_or_i64(dst, dst, tmp);
3147c2a7ee3fSRichard Henderson }
3148c2a7ee3fSRichard Henderson 
3149c2a7ee3fSRichard Henderson static bool trans_mixh_l(DisasContext *ctx, arg_rrr *a)
3150c2a7ee3fSRichard Henderson {
3151c2a7ee3fSRichard Henderson     return do_multimedia(ctx, a, gen_mixh_l);
3152c2a7ee3fSRichard Henderson }
3153c2a7ee3fSRichard Henderson 
3154c2a7ee3fSRichard Henderson static void gen_mixh_r(TCGv_i64 dst, TCGv_i64 r1, TCGv_i64 r2)
3155c2a7ee3fSRichard Henderson {
3156c2a7ee3fSRichard Henderson     uint64_t mask = 0x0000ffff0000ffffull;
3157c2a7ee3fSRichard Henderson     TCGv_i64 tmp = tcg_temp_new_i64();
3158c2a7ee3fSRichard Henderson 
3159c2a7ee3fSRichard Henderson     tcg_gen_andi_i64(tmp, r1, mask);
3160c2a7ee3fSRichard Henderson     tcg_gen_andi_i64(dst, r2, mask);
3161c2a7ee3fSRichard Henderson     tcg_gen_shli_i64(tmp, tmp, 16);
3162c2a7ee3fSRichard Henderson     tcg_gen_or_i64(dst, dst, tmp);
3163c2a7ee3fSRichard Henderson }
3164c2a7ee3fSRichard Henderson 
3165c2a7ee3fSRichard Henderson static bool trans_mixh_r(DisasContext *ctx, arg_rrr *a)
3166c2a7ee3fSRichard Henderson {
3167c2a7ee3fSRichard Henderson     return do_multimedia(ctx, a, gen_mixh_r);
3168c2a7ee3fSRichard Henderson }
3169c2a7ee3fSRichard Henderson 
3170c2a7ee3fSRichard Henderson static void gen_mixw_l(TCGv_i64 dst, TCGv_i64 r1, TCGv_i64 r2)
3171c2a7ee3fSRichard Henderson {
3172c2a7ee3fSRichard Henderson     TCGv_i64 tmp = tcg_temp_new_i64();
3173c2a7ee3fSRichard Henderson 
3174c2a7ee3fSRichard Henderson     tcg_gen_shri_i64(tmp, r2, 32);
3175c2a7ee3fSRichard Henderson     tcg_gen_deposit_i64(dst, r1, tmp, 0, 32);
3176c2a7ee3fSRichard Henderson }
3177c2a7ee3fSRichard Henderson 
3178c2a7ee3fSRichard Henderson static bool trans_mixw_l(DisasContext *ctx, arg_rrr *a)
3179c2a7ee3fSRichard Henderson {
3180c2a7ee3fSRichard Henderson     return do_multimedia(ctx, a, gen_mixw_l);
3181c2a7ee3fSRichard Henderson }
3182c2a7ee3fSRichard Henderson 
3183c2a7ee3fSRichard Henderson static void gen_mixw_r(TCGv_i64 dst, TCGv_i64 r1, TCGv_i64 r2)
3184c2a7ee3fSRichard Henderson {
3185c2a7ee3fSRichard Henderson     tcg_gen_deposit_i64(dst, r2, r1, 32, 32);
3186c2a7ee3fSRichard Henderson }
3187c2a7ee3fSRichard Henderson 
3188c2a7ee3fSRichard Henderson static bool trans_mixw_r(DisasContext *ctx, arg_rrr *a)
3189c2a7ee3fSRichard Henderson {
3190c2a7ee3fSRichard Henderson     return do_multimedia(ctx, a, gen_mixw_r);
3191c2a7ee3fSRichard Henderson }
3192c2a7ee3fSRichard Henderson 
31934e7abdb1SRichard Henderson static bool trans_permh(DisasContext *ctx, arg_permh *a)
31944e7abdb1SRichard Henderson {
31954e7abdb1SRichard Henderson     TCGv_i64 r, t0, t1, t2, t3;
31964e7abdb1SRichard Henderson 
31974e7abdb1SRichard Henderson     if (!ctx->is_pa20) {
31984e7abdb1SRichard Henderson         return false;
31994e7abdb1SRichard Henderson     }
32004e7abdb1SRichard Henderson 
32014e7abdb1SRichard Henderson     nullify_over(ctx);
32024e7abdb1SRichard Henderson 
32034e7abdb1SRichard Henderson     r = load_gpr(ctx, a->r1);
32044e7abdb1SRichard Henderson     t0 = tcg_temp_new_i64();
32054e7abdb1SRichard Henderson     t1 = tcg_temp_new_i64();
32064e7abdb1SRichard Henderson     t2 = tcg_temp_new_i64();
32074e7abdb1SRichard Henderson     t3 = tcg_temp_new_i64();
32084e7abdb1SRichard Henderson 
32094e7abdb1SRichard Henderson     tcg_gen_extract_i64(t0, r, (3 - a->c0) * 16, 16);
32104e7abdb1SRichard Henderson     tcg_gen_extract_i64(t1, r, (3 - a->c1) * 16, 16);
32114e7abdb1SRichard Henderson     tcg_gen_extract_i64(t2, r, (3 - a->c2) * 16, 16);
32124e7abdb1SRichard Henderson     tcg_gen_extract_i64(t3, r, (3 - a->c3) * 16, 16);
32134e7abdb1SRichard Henderson 
32144e7abdb1SRichard Henderson     tcg_gen_deposit_i64(t0, t1, t0, 16, 48);
32154e7abdb1SRichard Henderson     tcg_gen_deposit_i64(t2, t3, t2, 16, 48);
32164e7abdb1SRichard Henderson     tcg_gen_deposit_i64(t0, t2, t0, 32, 32);
32174e7abdb1SRichard Henderson 
32184e7abdb1SRichard Henderson     save_gpr(ctx, a->t, t0);
32194e7abdb1SRichard Henderson     return nullify_end(ctx);
32204e7abdb1SRichard Henderson }
32214e7abdb1SRichard Henderson 
32221cd012a5SRichard Henderson static bool trans_ld(DisasContext *ctx, arg_ldst *a)
322396d6407fSRichard Henderson {
3224b5caa17cSRichard Henderson     if (ctx->is_pa20) {
3225b5caa17cSRichard Henderson        /*
3226b5caa17cSRichard Henderson         * With pa20, LDB, LDH, LDW, LDD to %g0 are prefetches.
3227b5caa17cSRichard Henderson         * Any base modification still occurs.
3228b5caa17cSRichard Henderson         */
3229b5caa17cSRichard Henderson         if (a->t == 0) {
3230b5caa17cSRichard Henderson             return trans_nop_addrx(ctx, a);
3231b5caa17cSRichard Henderson         }
3232b5caa17cSRichard Henderson     } else if (a->size > MO_32) {
32330786a3b6SHelge Deller         return gen_illegal(ctx);
3234c53e401eSRichard Henderson     }
32351cd012a5SRichard Henderson     return do_load(ctx, a->t, a->b, a->x, a->scale ? a->size : 0,
32361cd012a5SRichard Henderson                    a->disp, a->sp, a->m, a->size | MO_TE);
323796d6407fSRichard Henderson }
323896d6407fSRichard Henderson 
32391cd012a5SRichard Henderson static bool trans_st(DisasContext *ctx, arg_ldst *a)
324096d6407fSRichard Henderson {
32411cd012a5SRichard Henderson     assert(a->x == 0 && a->scale == 0);
3242c53e401eSRichard Henderson     if (!ctx->is_pa20 && a->size > MO_32) {
32430786a3b6SHelge Deller         return gen_illegal(ctx);
324496d6407fSRichard Henderson     }
3245c53e401eSRichard Henderson     return do_store(ctx, a->t, a->b, a->disp, a->sp, a->m, a->size | MO_TE);
32460786a3b6SHelge Deller }
324796d6407fSRichard Henderson 
32481cd012a5SRichard Henderson static bool trans_ldc(DisasContext *ctx, arg_ldst *a)
324996d6407fSRichard Henderson {
3250b1af755cSRichard Henderson     MemOp mop = MO_TE | MO_ALIGN | a->size;
3251a4db4a78SRichard Henderson     TCGv_i64 dest, ofs;
32526fd0c7bcSRichard Henderson     TCGv_i64 addr;
325396d6407fSRichard Henderson 
3254c53e401eSRichard Henderson     if (!ctx->is_pa20 && a->size > MO_32) {
325551416c4eSRichard Henderson         return gen_illegal(ctx);
325651416c4eSRichard Henderson     }
325751416c4eSRichard Henderson 
325896d6407fSRichard Henderson     nullify_over(ctx);
325996d6407fSRichard Henderson 
32601cd012a5SRichard Henderson     if (a->m) {
326186f8d05fSRichard Henderson         /* Base register modification.  Make sure if RT == RB,
326286f8d05fSRichard Henderson            we see the result of the load.  */
3263aac0f603SRichard Henderson         dest = tcg_temp_new_i64();
326496d6407fSRichard Henderson     } else {
32651cd012a5SRichard Henderson         dest = dest_gpr(ctx, a->t);
326696d6407fSRichard Henderson     }
326796d6407fSRichard Henderson 
3268c3ea1996SSven Schnelle     form_gva(ctx, &addr, &ofs, a->b, a->x, a->scale ? 3 : 0,
326917fe594cSRichard Henderson              a->disp, a->sp, a->m, MMU_DISABLED(ctx));
3270b1af755cSRichard Henderson 
3271b1af755cSRichard Henderson     /*
3272b1af755cSRichard Henderson      * For hppa1.1, LDCW is undefined unless aligned mod 16.
3273b1af755cSRichard Henderson      * However actual hardware succeeds with aligned mod 4.
3274b1af755cSRichard Henderson      * Detect this case and log a GUEST_ERROR.
3275b1af755cSRichard Henderson      *
3276b1af755cSRichard Henderson      * TODO: HPPA64 relaxes the over-alignment requirement
3277b1af755cSRichard Henderson      * with the ,co completer.
3278b1af755cSRichard Henderson      */
3279b1af755cSRichard Henderson     gen_helper_ldc_check(addr);
3280b1af755cSRichard Henderson 
3281a4db4a78SRichard Henderson     tcg_gen_atomic_xchg_i64(dest, addr, ctx->zero, ctx->mmu_idx, mop);
3282b1af755cSRichard Henderson 
32831cd012a5SRichard Henderson     if (a->m) {
32841cd012a5SRichard Henderson         save_gpr(ctx, a->b, ofs);
328596d6407fSRichard Henderson     }
32861cd012a5SRichard Henderson     save_gpr(ctx, a->t, dest);
328796d6407fSRichard Henderson 
328831234768SRichard Henderson     return nullify_end(ctx);
328996d6407fSRichard Henderson }
329096d6407fSRichard Henderson 
32911cd012a5SRichard Henderson static bool trans_stby(DisasContext *ctx, arg_stby *a)
329296d6407fSRichard Henderson {
32936fd0c7bcSRichard Henderson     TCGv_i64 ofs, val;
32946fd0c7bcSRichard Henderson     TCGv_i64 addr;
329596d6407fSRichard Henderson 
329696d6407fSRichard Henderson     nullify_over(ctx);
329796d6407fSRichard Henderson 
32981cd012a5SRichard Henderson     form_gva(ctx, &addr, &ofs, a->b, 0, 0, a->disp, a->sp, a->m,
329917fe594cSRichard Henderson              MMU_DISABLED(ctx));
33001cd012a5SRichard Henderson     val = load_gpr(ctx, a->r);
33011cd012a5SRichard Henderson     if (a->a) {
3302f9f46db4SEmilio G. Cota         if (tb_cflags(ctx->base.tb) & CF_PARALLEL) {
3303ad75a51eSRichard Henderson             gen_helper_stby_e_parallel(tcg_env, addr, val);
3304f9f46db4SEmilio G. Cota         } else {
3305ad75a51eSRichard Henderson             gen_helper_stby_e(tcg_env, addr, val);
3306f9f46db4SEmilio G. Cota         }
3307f9f46db4SEmilio G. Cota     } else {
3308f9f46db4SEmilio G. Cota         if (tb_cflags(ctx->base.tb) & CF_PARALLEL) {
3309ad75a51eSRichard Henderson             gen_helper_stby_b_parallel(tcg_env, addr, val);
331096d6407fSRichard Henderson         } else {
3311ad75a51eSRichard Henderson             gen_helper_stby_b(tcg_env, addr, val);
331296d6407fSRichard Henderson         }
3313f9f46db4SEmilio G. Cota     }
33141cd012a5SRichard Henderson     if (a->m) {
33156fd0c7bcSRichard Henderson         tcg_gen_andi_i64(ofs, ofs, ~3);
33161cd012a5SRichard Henderson         save_gpr(ctx, a->b, ofs);
331796d6407fSRichard Henderson     }
331896d6407fSRichard Henderson 
331931234768SRichard Henderson     return nullify_end(ctx);
332096d6407fSRichard Henderson }
332196d6407fSRichard Henderson 
332225460fc5SRichard Henderson static bool trans_stdby(DisasContext *ctx, arg_stby *a)
332325460fc5SRichard Henderson {
33246fd0c7bcSRichard Henderson     TCGv_i64 ofs, val;
33256fd0c7bcSRichard Henderson     TCGv_i64 addr;
332625460fc5SRichard Henderson 
332725460fc5SRichard Henderson     if (!ctx->is_pa20) {
332825460fc5SRichard Henderson         return false;
332925460fc5SRichard Henderson     }
333025460fc5SRichard Henderson     nullify_over(ctx);
333125460fc5SRichard Henderson 
333225460fc5SRichard Henderson     form_gva(ctx, &addr, &ofs, a->b, 0, 0, a->disp, a->sp, a->m,
333317fe594cSRichard Henderson              MMU_DISABLED(ctx));
333425460fc5SRichard Henderson     val = load_gpr(ctx, a->r);
333525460fc5SRichard Henderson     if (a->a) {
333625460fc5SRichard Henderson         if (tb_cflags(ctx->base.tb) & CF_PARALLEL) {
333725460fc5SRichard Henderson             gen_helper_stdby_e_parallel(tcg_env, addr, val);
333825460fc5SRichard Henderson         } else {
333925460fc5SRichard Henderson             gen_helper_stdby_e(tcg_env, addr, val);
334025460fc5SRichard Henderson         }
334125460fc5SRichard Henderson     } else {
334225460fc5SRichard Henderson         if (tb_cflags(ctx->base.tb) & CF_PARALLEL) {
334325460fc5SRichard Henderson             gen_helper_stdby_b_parallel(tcg_env, addr, val);
334425460fc5SRichard Henderson         } else {
334525460fc5SRichard Henderson             gen_helper_stdby_b(tcg_env, addr, val);
334625460fc5SRichard Henderson         }
334725460fc5SRichard Henderson     }
334825460fc5SRichard Henderson     if (a->m) {
33496fd0c7bcSRichard Henderson         tcg_gen_andi_i64(ofs, ofs, ~7);
335025460fc5SRichard Henderson         save_gpr(ctx, a->b, ofs);
335125460fc5SRichard Henderson     }
335225460fc5SRichard Henderson 
335325460fc5SRichard Henderson     return nullify_end(ctx);
335425460fc5SRichard Henderson }
335525460fc5SRichard Henderson 
33561cd012a5SRichard Henderson static bool trans_lda(DisasContext *ctx, arg_ldst *a)
3357d0a851ccSRichard Henderson {
3358d0a851ccSRichard Henderson     int hold_mmu_idx = ctx->mmu_idx;
3359d0a851ccSRichard Henderson 
3360d0a851ccSRichard Henderson     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
3361451d993dSRichard Henderson     ctx->mmu_idx = ctx->tb_flags & PSW_W ? MMU_ABS_W_IDX : MMU_ABS_IDX;
33621cd012a5SRichard Henderson     trans_ld(ctx, a);
3363d0a851ccSRichard Henderson     ctx->mmu_idx = hold_mmu_idx;
336431234768SRichard Henderson     return true;
3365d0a851ccSRichard Henderson }
3366d0a851ccSRichard Henderson 
33671cd012a5SRichard Henderson static bool trans_sta(DisasContext *ctx, arg_ldst *a)
3368d0a851ccSRichard Henderson {
3369d0a851ccSRichard Henderson     int hold_mmu_idx = ctx->mmu_idx;
3370d0a851ccSRichard Henderson 
3371d0a851ccSRichard Henderson     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
3372451d993dSRichard Henderson     ctx->mmu_idx = ctx->tb_flags & PSW_W ? MMU_ABS_W_IDX : MMU_ABS_IDX;
33731cd012a5SRichard Henderson     trans_st(ctx, a);
3374d0a851ccSRichard Henderson     ctx->mmu_idx = hold_mmu_idx;
337531234768SRichard Henderson     return true;
3376d0a851ccSRichard Henderson }
337795412a61SRichard Henderson 
33780588e061SRichard Henderson static bool trans_ldil(DisasContext *ctx, arg_ldil *a)
3379b2167459SRichard Henderson {
33806fd0c7bcSRichard Henderson     TCGv_i64 tcg_rt = dest_gpr(ctx, a->t);
3381b2167459SRichard Henderson 
33826fd0c7bcSRichard Henderson     tcg_gen_movi_i64(tcg_rt, a->i);
33830588e061SRichard Henderson     save_gpr(ctx, a->t, tcg_rt);
3384b2167459SRichard Henderson     cond_free(&ctx->null_cond);
338531234768SRichard Henderson     return true;
3386b2167459SRichard Henderson }
3387b2167459SRichard Henderson 
33880588e061SRichard Henderson static bool trans_addil(DisasContext *ctx, arg_addil *a)
3389b2167459SRichard Henderson {
33906fd0c7bcSRichard Henderson     TCGv_i64 tcg_rt = load_gpr(ctx, a->r);
33916fd0c7bcSRichard Henderson     TCGv_i64 tcg_r1 = dest_gpr(ctx, 1);
3392b2167459SRichard Henderson 
33936fd0c7bcSRichard Henderson     tcg_gen_addi_i64(tcg_r1, tcg_rt, a->i);
3394b2167459SRichard Henderson     save_gpr(ctx, 1, tcg_r1);
3395b2167459SRichard Henderson     cond_free(&ctx->null_cond);
339631234768SRichard Henderson     return true;
3397b2167459SRichard Henderson }
3398b2167459SRichard Henderson 
33990588e061SRichard Henderson static bool trans_ldo(DisasContext *ctx, arg_ldo *a)
3400b2167459SRichard Henderson {
34016fd0c7bcSRichard Henderson     TCGv_i64 tcg_rt = dest_gpr(ctx, a->t);
3402b2167459SRichard Henderson 
3403b2167459SRichard Henderson     /* Special case rb == 0, for the LDI pseudo-op.
3404d265360fSRichard Henderson        The COPY pseudo-op is handled for free within tcg_gen_addi_i64.  */
34050588e061SRichard Henderson     if (a->b == 0) {
34066fd0c7bcSRichard Henderson         tcg_gen_movi_i64(tcg_rt, a->i);
3407b2167459SRichard Henderson     } else {
34086fd0c7bcSRichard Henderson         tcg_gen_addi_i64(tcg_rt, cpu_gr[a->b], a->i);
3409b2167459SRichard Henderson     }
34100588e061SRichard Henderson     save_gpr(ctx, a->t, tcg_rt);
3411b2167459SRichard Henderson     cond_free(&ctx->null_cond);
341231234768SRichard Henderson     return true;
3413b2167459SRichard Henderson }
3414b2167459SRichard Henderson 
34156fd0c7bcSRichard Henderson static bool do_cmpb(DisasContext *ctx, unsigned r, TCGv_i64 in1,
3416e9efd4bcSRichard Henderson                     unsigned c, unsigned f, bool d, unsigned n, int disp)
341798cd9ca7SRichard Henderson {
34186fd0c7bcSRichard Henderson     TCGv_i64 dest, in2, sv;
341998cd9ca7SRichard Henderson     DisasCond cond;
342098cd9ca7SRichard Henderson 
342198cd9ca7SRichard Henderson     in2 = load_gpr(ctx, r);
3422aac0f603SRichard Henderson     dest = tcg_temp_new_i64();
342398cd9ca7SRichard Henderson 
34246fd0c7bcSRichard Henderson     tcg_gen_sub_i64(dest, in1, in2);
342598cd9ca7SRichard Henderson 
3426f764718dSRichard Henderson     sv = NULL;
3427b47a4a02SSven Schnelle     if (cond_need_sv(c)) {
342898cd9ca7SRichard Henderson         sv = do_sub_sv(ctx, dest, in1, in2);
342998cd9ca7SRichard Henderson     }
343098cd9ca7SRichard Henderson 
34314fe9533aSRichard Henderson     cond = do_sub_cond(ctx, c * 2 + f, d, dest, in1, in2, sv);
343201afb7beSRichard Henderson     return do_cbranch(ctx, disp, n, &cond);
343398cd9ca7SRichard Henderson }
343498cd9ca7SRichard Henderson 
343501afb7beSRichard Henderson static bool trans_cmpb(DisasContext *ctx, arg_cmpb *a)
343698cd9ca7SRichard Henderson {
3437e9efd4bcSRichard Henderson     if (!ctx->is_pa20 && a->d) {
3438e9efd4bcSRichard Henderson         return false;
3439e9efd4bcSRichard Henderson     }
344001afb7beSRichard Henderson     nullify_over(ctx);
3441e9efd4bcSRichard Henderson     return do_cmpb(ctx, a->r2, load_gpr(ctx, a->r1),
3442e9efd4bcSRichard Henderson                    a->c, a->f, a->d, a->n, a->disp);
344301afb7beSRichard Henderson }
344401afb7beSRichard Henderson 
344501afb7beSRichard Henderson static bool trans_cmpbi(DisasContext *ctx, arg_cmpbi *a)
344601afb7beSRichard Henderson {
3447c65c3ee1SRichard Henderson     if (!ctx->is_pa20 && a->d) {
3448c65c3ee1SRichard Henderson         return false;
3449c65c3ee1SRichard Henderson     }
345001afb7beSRichard Henderson     nullify_over(ctx);
34516fd0c7bcSRichard Henderson     return do_cmpb(ctx, a->r, tcg_constant_i64(a->i),
3452c65c3ee1SRichard Henderson                    a->c, a->f, a->d, a->n, a->disp);
345301afb7beSRichard Henderson }
345401afb7beSRichard Henderson 
34556fd0c7bcSRichard Henderson static bool do_addb(DisasContext *ctx, unsigned r, TCGv_i64 in1,
345601afb7beSRichard Henderson                     unsigned c, unsigned f, unsigned n, int disp)
345701afb7beSRichard Henderson {
34586fd0c7bcSRichard Henderson     TCGv_i64 dest, in2, sv, cb_cond;
345998cd9ca7SRichard Henderson     DisasCond cond;
3460bdcccc17SRichard Henderson     bool d = false;
346198cd9ca7SRichard Henderson 
3462f25d3160SRichard Henderson     /*
3463f25d3160SRichard Henderson      * For hppa64, the ADDB conditions change with PSW.W,
3464f25d3160SRichard Henderson      * dropping ZNV, SV, OD in favor of double-word EQ, LT, LE.
3465f25d3160SRichard Henderson      */
3466f25d3160SRichard Henderson     if (ctx->tb_flags & PSW_W) {
3467f25d3160SRichard Henderson         d = c >= 5;
3468f25d3160SRichard Henderson         if (d) {
3469f25d3160SRichard Henderson             c &= 3;
3470f25d3160SRichard Henderson         }
3471f25d3160SRichard Henderson     }
3472f25d3160SRichard Henderson 
347398cd9ca7SRichard Henderson     in2 = load_gpr(ctx, r);
3474aac0f603SRichard Henderson     dest = tcg_temp_new_i64();
3475f764718dSRichard Henderson     sv = NULL;
3476bdcccc17SRichard Henderson     cb_cond = NULL;
347798cd9ca7SRichard Henderson 
3478b47a4a02SSven Schnelle     if (cond_need_cb(c)) {
3479aac0f603SRichard Henderson         TCGv_i64 cb = tcg_temp_new_i64();
3480aac0f603SRichard Henderson         TCGv_i64 cb_msb = tcg_temp_new_i64();
3481bdcccc17SRichard Henderson 
34826fd0c7bcSRichard Henderson         tcg_gen_movi_i64(cb_msb, 0);
34836fd0c7bcSRichard Henderson         tcg_gen_add2_i64(dest, cb_msb, in1, cb_msb, in2, cb_msb);
34846fd0c7bcSRichard Henderson         tcg_gen_xor_i64(cb, in1, in2);
34856fd0c7bcSRichard Henderson         tcg_gen_xor_i64(cb, cb, dest);
3486bdcccc17SRichard Henderson         cb_cond = get_carry(ctx, d, cb, cb_msb);
3487b47a4a02SSven Schnelle     } else {
34886fd0c7bcSRichard Henderson         tcg_gen_add_i64(dest, in1, in2);
3489b47a4a02SSven Schnelle     }
3490b47a4a02SSven Schnelle     if (cond_need_sv(c)) {
3491f8f5986eSRichard Henderson         sv = do_add_sv(ctx, dest, in1, in2, in1, 0, d);
349298cd9ca7SRichard Henderson     }
349398cd9ca7SRichard Henderson 
3494a751eb31SRichard Henderson     cond = do_cond(ctx, c * 2 + f, d, dest, cb_cond, sv);
349543675d20SSven Schnelle     save_gpr(ctx, r, dest);
349601afb7beSRichard Henderson     return do_cbranch(ctx, disp, n, &cond);
349798cd9ca7SRichard Henderson }
349898cd9ca7SRichard Henderson 
349901afb7beSRichard Henderson static bool trans_addb(DisasContext *ctx, arg_addb *a)
350098cd9ca7SRichard Henderson {
350101afb7beSRichard Henderson     nullify_over(ctx);
350201afb7beSRichard Henderson     return do_addb(ctx, a->r2, load_gpr(ctx, a->r1), a->c, a->f, a->n, a->disp);
350301afb7beSRichard Henderson }
350401afb7beSRichard Henderson 
350501afb7beSRichard Henderson static bool trans_addbi(DisasContext *ctx, arg_addbi *a)
350601afb7beSRichard Henderson {
350701afb7beSRichard Henderson     nullify_over(ctx);
35086fd0c7bcSRichard Henderson     return do_addb(ctx, a->r, tcg_constant_i64(a->i), a->c, a->f, a->n, a->disp);
350901afb7beSRichard Henderson }
351001afb7beSRichard Henderson 
351101afb7beSRichard Henderson static bool trans_bb_sar(DisasContext *ctx, arg_bb_sar *a)
351201afb7beSRichard Henderson {
35136fd0c7bcSRichard Henderson     TCGv_i64 tmp, tcg_r;
351498cd9ca7SRichard Henderson     DisasCond cond;
351598cd9ca7SRichard Henderson 
351698cd9ca7SRichard Henderson     nullify_over(ctx);
351798cd9ca7SRichard Henderson 
3518aac0f603SRichard Henderson     tmp = tcg_temp_new_i64();
351901afb7beSRichard Henderson     tcg_r = load_gpr(ctx, a->r);
352082d0c831SRichard Henderson     if (a->d) {
352182d0c831SRichard Henderson         tcg_gen_shl_i64(tmp, tcg_r, cpu_sar);
352282d0c831SRichard Henderson     } else {
35231e9ab9fbSRichard Henderson         /* Force shift into [32,63] */
35246fd0c7bcSRichard Henderson         tcg_gen_ori_i64(tmp, cpu_sar, 32);
35256fd0c7bcSRichard Henderson         tcg_gen_shl_i64(tmp, tcg_r, tmp);
35261e9ab9fbSRichard Henderson     }
352798cd9ca7SRichard Henderson 
35281e9ab9fbSRichard Henderson     cond = cond_make_0_tmp(a->c ? TCG_COND_GE : TCG_COND_LT, tmp);
352901afb7beSRichard Henderson     return do_cbranch(ctx, a->disp, a->n, &cond);
353098cd9ca7SRichard Henderson }
353198cd9ca7SRichard Henderson 
353201afb7beSRichard Henderson static bool trans_bb_imm(DisasContext *ctx, arg_bb_imm *a)
353398cd9ca7SRichard Henderson {
35346fd0c7bcSRichard Henderson     TCGv_i64 tmp, tcg_r;
353501afb7beSRichard Henderson     DisasCond cond;
35361e9ab9fbSRichard Henderson     int p;
353701afb7beSRichard Henderson 
353801afb7beSRichard Henderson     nullify_over(ctx);
353901afb7beSRichard Henderson 
3540aac0f603SRichard Henderson     tmp = tcg_temp_new_i64();
354101afb7beSRichard Henderson     tcg_r = load_gpr(ctx, a->r);
354282d0c831SRichard Henderson     p = a->p | (a->d ? 0 : 32);
35436fd0c7bcSRichard Henderson     tcg_gen_shli_i64(tmp, tcg_r, p);
354401afb7beSRichard Henderson 
354501afb7beSRichard Henderson     cond = cond_make_0(a->c ? TCG_COND_GE : TCG_COND_LT, tmp);
354601afb7beSRichard Henderson     return do_cbranch(ctx, a->disp, a->n, &cond);
354701afb7beSRichard Henderson }
354801afb7beSRichard Henderson 
354901afb7beSRichard Henderson static bool trans_movb(DisasContext *ctx, arg_movb *a)
355001afb7beSRichard Henderson {
35516fd0c7bcSRichard Henderson     TCGv_i64 dest;
355298cd9ca7SRichard Henderson     DisasCond cond;
355398cd9ca7SRichard Henderson 
355498cd9ca7SRichard Henderson     nullify_over(ctx);
355598cd9ca7SRichard Henderson 
355601afb7beSRichard Henderson     dest = dest_gpr(ctx, a->r2);
355701afb7beSRichard Henderson     if (a->r1 == 0) {
35586fd0c7bcSRichard Henderson         tcg_gen_movi_i64(dest, 0);
355998cd9ca7SRichard Henderson     } else {
35606fd0c7bcSRichard Henderson         tcg_gen_mov_i64(dest, cpu_gr[a->r1]);
356198cd9ca7SRichard Henderson     }
356298cd9ca7SRichard Henderson 
35634fa52edfSRichard Henderson     /* All MOVB conditions are 32-bit. */
35644fa52edfSRichard Henderson     cond = do_sed_cond(ctx, a->c, false, dest);
356501afb7beSRichard Henderson     return do_cbranch(ctx, a->disp, a->n, &cond);
356601afb7beSRichard Henderson }
356701afb7beSRichard Henderson 
356801afb7beSRichard Henderson static bool trans_movbi(DisasContext *ctx, arg_movbi *a)
356901afb7beSRichard Henderson {
35706fd0c7bcSRichard Henderson     TCGv_i64 dest;
357101afb7beSRichard Henderson     DisasCond cond;
357201afb7beSRichard Henderson 
357301afb7beSRichard Henderson     nullify_over(ctx);
357401afb7beSRichard Henderson 
357501afb7beSRichard Henderson     dest = dest_gpr(ctx, a->r);
35766fd0c7bcSRichard Henderson     tcg_gen_movi_i64(dest, a->i);
357701afb7beSRichard Henderson 
35784fa52edfSRichard Henderson     /* All MOVBI conditions are 32-bit. */
35794fa52edfSRichard Henderson     cond = do_sed_cond(ctx, a->c, false, dest);
358001afb7beSRichard Henderson     return do_cbranch(ctx, a->disp, a->n, &cond);
358198cd9ca7SRichard Henderson }
358298cd9ca7SRichard Henderson 
3583f7b775a9SRichard Henderson static bool trans_shrp_sar(DisasContext *ctx, arg_shrp_sar *a)
35840b1347d2SRichard Henderson {
35856fd0c7bcSRichard Henderson     TCGv_i64 dest, src2;
35860b1347d2SRichard Henderson 
3587f7b775a9SRichard Henderson     if (!ctx->is_pa20 && a->d) {
3588f7b775a9SRichard Henderson         return false;
3589f7b775a9SRichard Henderson     }
359030878590SRichard Henderson     if (a->c) {
35910b1347d2SRichard Henderson         nullify_over(ctx);
35920b1347d2SRichard Henderson     }
35930b1347d2SRichard Henderson 
359430878590SRichard Henderson     dest = dest_gpr(ctx, a->t);
3595f7b775a9SRichard Henderson     src2 = load_gpr(ctx, a->r2);
359630878590SRichard Henderson     if (a->r1 == 0) {
3597f7b775a9SRichard Henderson         if (a->d) {
35986fd0c7bcSRichard Henderson             tcg_gen_shr_i64(dest, src2, cpu_sar);
3599f7b775a9SRichard Henderson         } else {
3600aac0f603SRichard Henderson             TCGv_i64 tmp = tcg_temp_new_i64();
3601f7b775a9SRichard Henderson 
36026fd0c7bcSRichard Henderson             tcg_gen_ext32u_i64(dest, src2);
36036fd0c7bcSRichard Henderson             tcg_gen_andi_i64(tmp, cpu_sar, 31);
36046fd0c7bcSRichard Henderson             tcg_gen_shr_i64(dest, dest, tmp);
3605f7b775a9SRichard Henderson         }
360630878590SRichard Henderson     } else if (a->r1 == a->r2) {
3607f7b775a9SRichard Henderson         if (a->d) {
36086fd0c7bcSRichard Henderson             tcg_gen_rotr_i64(dest, src2, cpu_sar);
3609f7b775a9SRichard Henderson         } else {
36100b1347d2SRichard Henderson             TCGv_i32 t32 = tcg_temp_new_i32();
3611e1d635e8SRichard Henderson             TCGv_i32 s32 = tcg_temp_new_i32();
3612e1d635e8SRichard Henderson 
36136fd0c7bcSRichard Henderson             tcg_gen_extrl_i64_i32(t32, src2);
36146fd0c7bcSRichard Henderson             tcg_gen_extrl_i64_i32(s32, cpu_sar);
3615f7b775a9SRichard Henderson             tcg_gen_andi_i32(s32, s32, 31);
3616e1d635e8SRichard Henderson             tcg_gen_rotr_i32(t32, t32, s32);
36176fd0c7bcSRichard Henderson             tcg_gen_extu_i32_i64(dest, t32);
3618f7b775a9SRichard Henderson         }
3619f7b775a9SRichard Henderson     } else {
36206fd0c7bcSRichard Henderson         TCGv_i64 src1 = load_gpr(ctx, a->r1);
3621f7b775a9SRichard Henderson 
3622f7b775a9SRichard Henderson         if (a->d) {
3623aac0f603SRichard Henderson             TCGv_i64 t = tcg_temp_new_i64();
3624aac0f603SRichard Henderson             TCGv_i64 n = tcg_temp_new_i64();
3625f7b775a9SRichard Henderson 
36266fd0c7bcSRichard Henderson             tcg_gen_xori_i64(n, cpu_sar, 63);
3627a01491a2SHelge Deller             tcg_gen_shl_i64(t, src1, n);
36286fd0c7bcSRichard Henderson             tcg_gen_shli_i64(t, t, 1);
3629a01491a2SHelge Deller             tcg_gen_shr_i64(dest, src2, cpu_sar);
36306fd0c7bcSRichard Henderson             tcg_gen_or_i64(dest, dest, t);
36310b1347d2SRichard Henderson         } else {
36320b1347d2SRichard Henderson             TCGv_i64 t = tcg_temp_new_i64();
36330b1347d2SRichard Henderson             TCGv_i64 s = tcg_temp_new_i64();
36340b1347d2SRichard Henderson 
36356fd0c7bcSRichard Henderson             tcg_gen_concat32_i64(t, src2, src1);
3636967662cdSRichard Henderson             tcg_gen_andi_i64(s, cpu_sar, 31);
3637967662cdSRichard Henderson             tcg_gen_shr_i64(dest, t, s);
36380b1347d2SRichard Henderson         }
3639f7b775a9SRichard Henderson     }
364030878590SRichard Henderson     save_gpr(ctx, a->t, dest);
36410b1347d2SRichard Henderson 
36420b1347d2SRichard Henderson     /* Install the new nullification.  */
36430b1347d2SRichard Henderson     cond_free(&ctx->null_cond);
364430878590SRichard Henderson     if (a->c) {
3645d37fad0aSSven Schnelle         ctx->null_cond = do_sed_cond(ctx, a->c, a->d, dest);
36460b1347d2SRichard Henderson     }
364731234768SRichard Henderson     return nullify_end(ctx);
36480b1347d2SRichard Henderson }
36490b1347d2SRichard Henderson 
3650f7b775a9SRichard Henderson static bool trans_shrp_imm(DisasContext *ctx, arg_shrp_imm *a)
36510b1347d2SRichard Henderson {
3652f7b775a9SRichard Henderson     unsigned width, sa;
36536fd0c7bcSRichard Henderson     TCGv_i64 dest, t2;
36540b1347d2SRichard Henderson 
3655f7b775a9SRichard Henderson     if (!ctx->is_pa20 && a->d) {
3656f7b775a9SRichard Henderson         return false;
3657f7b775a9SRichard Henderson     }
365830878590SRichard Henderson     if (a->c) {
36590b1347d2SRichard Henderson         nullify_over(ctx);
36600b1347d2SRichard Henderson     }
36610b1347d2SRichard Henderson 
3662f7b775a9SRichard Henderson     width = a->d ? 64 : 32;
3663f7b775a9SRichard Henderson     sa = width - 1 - a->cpos;
3664f7b775a9SRichard Henderson 
366530878590SRichard Henderson     dest = dest_gpr(ctx, a->t);
366630878590SRichard Henderson     t2 = load_gpr(ctx, a->r2);
366705bfd4dbSRichard Henderson     if (a->r1 == 0) {
36686fd0c7bcSRichard Henderson         tcg_gen_extract_i64(dest, t2, sa, width - sa);
3669c53e401eSRichard Henderson     } else if (width == TARGET_LONG_BITS) {
36706fd0c7bcSRichard Henderson         tcg_gen_extract2_i64(dest, t2, cpu_gr[a->r1], sa);
3671f7b775a9SRichard Henderson     } else {
3672f7b775a9SRichard Henderson         assert(!a->d);
3673f7b775a9SRichard Henderson         if (a->r1 == a->r2) {
36740b1347d2SRichard Henderson             TCGv_i32 t32 = tcg_temp_new_i32();
36756fd0c7bcSRichard Henderson             tcg_gen_extrl_i64_i32(t32, t2);
36760b1347d2SRichard Henderson             tcg_gen_rotri_i32(t32, t32, sa);
36776fd0c7bcSRichard Henderson             tcg_gen_extu_i32_i64(dest, t32);
36780b1347d2SRichard Henderson         } else {
3679967662cdSRichard Henderson             tcg_gen_concat32_i64(dest, t2, cpu_gr[a->r1]);
3680967662cdSRichard Henderson             tcg_gen_extract_i64(dest, dest, sa, 32);
36810b1347d2SRichard Henderson         }
3682f7b775a9SRichard Henderson     }
368330878590SRichard Henderson     save_gpr(ctx, a->t, dest);
36840b1347d2SRichard Henderson 
36850b1347d2SRichard Henderson     /* Install the new nullification.  */
36860b1347d2SRichard Henderson     cond_free(&ctx->null_cond);
368730878590SRichard Henderson     if (a->c) {
3688d37fad0aSSven Schnelle         ctx->null_cond = do_sed_cond(ctx, a->c, a->d, dest);
36890b1347d2SRichard Henderson     }
369031234768SRichard Henderson     return nullify_end(ctx);
36910b1347d2SRichard Henderson }
36920b1347d2SRichard Henderson 
3693bd792da3SRichard Henderson static bool trans_extr_sar(DisasContext *ctx, arg_extr_sar *a)
36940b1347d2SRichard Henderson {
3695bd792da3SRichard Henderson     unsigned widthm1 = a->d ? 63 : 31;
36966fd0c7bcSRichard Henderson     TCGv_i64 dest, src, tmp;
36970b1347d2SRichard Henderson 
3698bd792da3SRichard Henderson     if (!ctx->is_pa20 && a->d) {
3699bd792da3SRichard Henderson         return false;
3700bd792da3SRichard Henderson     }
370130878590SRichard Henderson     if (a->c) {
37020b1347d2SRichard Henderson         nullify_over(ctx);
37030b1347d2SRichard Henderson     }
37040b1347d2SRichard Henderson 
370530878590SRichard Henderson     dest = dest_gpr(ctx, a->t);
370630878590SRichard Henderson     src = load_gpr(ctx, a->r);
3707aac0f603SRichard Henderson     tmp = tcg_temp_new_i64();
37080b1347d2SRichard Henderson 
37090b1347d2SRichard Henderson     /* Recall that SAR is using big-endian bit numbering.  */
37106fd0c7bcSRichard Henderson     tcg_gen_andi_i64(tmp, cpu_sar, widthm1);
37116fd0c7bcSRichard Henderson     tcg_gen_xori_i64(tmp, tmp, widthm1);
3712d781cb77SRichard Henderson 
371330878590SRichard Henderson     if (a->se) {
3714bd792da3SRichard Henderson         if (!a->d) {
37156fd0c7bcSRichard Henderson             tcg_gen_ext32s_i64(dest, src);
3716bd792da3SRichard Henderson             src = dest;
3717bd792da3SRichard Henderson         }
37186fd0c7bcSRichard Henderson         tcg_gen_sar_i64(dest, src, tmp);
37196fd0c7bcSRichard Henderson         tcg_gen_sextract_i64(dest, dest, 0, a->len);
37200b1347d2SRichard Henderson     } else {
3721bd792da3SRichard Henderson         if (!a->d) {
37226fd0c7bcSRichard Henderson             tcg_gen_ext32u_i64(dest, src);
3723bd792da3SRichard Henderson             src = dest;
3724bd792da3SRichard Henderson         }
37256fd0c7bcSRichard Henderson         tcg_gen_shr_i64(dest, src, tmp);
37266fd0c7bcSRichard Henderson         tcg_gen_extract_i64(dest, dest, 0, a->len);
37270b1347d2SRichard Henderson     }
372830878590SRichard Henderson     save_gpr(ctx, a->t, dest);
37290b1347d2SRichard Henderson 
37300b1347d2SRichard Henderson     /* Install the new nullification.  */
37310b1347d2SRichard Henderson     cond_free(&ctx->null_cond);
373230878590SRichard Henderson     if (a->c) {
3733bd792da3SRichard Henderson         ctx->null_cond = do_sed_cond(ctx, a->c, a->d, dest);
37340b1347d2SRichard Henderson     }
373531234768SRichard Henderson     return nullify_end(ctx);
37360b1347d2SRichard Henderson }
37370b1347d2SRichard Henderson 
3738bd792da3SRichard Henderson static bool trans_extr_imm(DisasContext *ctx, arg_extr_imm *a)
37390b1347d2SRichard Henderson {
3740bd792da3SRichard Henderson     unsigned len, cpos, width;
37416fd0c7bcSRichard Henderson     TCGv_i64 dest, src;
37420b1347d2SRichard Henderson 
3743bd792da3SRichard Henderson     if (!ctx->is_pa20 && a->d) {
3744bd792da3SRichard Henderson         return false;
3745bd792da3SRichard Henderson     }
374630878590SRichard Henderson     if (a->c) {
37470b1347d2SRichard Henderson         nullify_over(ctx);
37480b1347d2SRichard Henderson     }
37490b1347d2SRichard Henderson 
3750bd792da3SRichard Henderson     len = a->len;
3751bd792da3SRichard Henderson     width = a->d ? 64 : 32;
3752bd792da3SRichard Henderson     cpos = width - 1 - a->pos;
3753bd792da3SRichard Henderson     if (cpos + len > width) {
3754bd792da3SRichard Henderson         len = width - cpos;
3755bd792da3SRichard Henderson     }
3756bd792da3SRichard Henderson 
375730878590SRichard Henderson     dest = dest_gpr(ctx, a->t);
375830878590SRichard Henderson     src = load_gpr(ctx, a->r);
375930878590SRichard Henderson     if (a->se) {
37606fd0c7bcSRichard Henderson         tcg_gen_sextract_i64(dest, src, cpos, len);
37610b1347d2SRichard Henderson     } else {
37626fd0c7bcSRichard Henderson         tcg_gen_extract_i64(dest, src, cpos, len);
37630b1347d2SRichard Henderson     }
376430878590SRichard Henderson     save_gpr(ctx, a->t, dest);
37650b1347d2SRichard Henderson 
37660b1347d2SRichard Henderson     /* Install the new nullification.  */
37670b1347d2SRichard Henderson     cond_free(&ctx->null_cond);
376830878590SRichard Henderson     if (a->c) {
3769bd792da3SRichard Henderson         ctx->null_cond = do_sed_cond(ctx, a->c, a->d, dest);
37700b1347d2SRichard Henderson     }
377131234768SRichard Henderson     return nullify_end(ctx);
37720b1347d2SRichard Henderson }
37730b1347d2SRichard Henderson 
377472ae4f2bSRichard Henderson static bool trans_depi_imm(DisasContext *ctx, arg_depi_imm *a)
37750b1347d2SRichard Henderson {
377672ae4f2bSRichard Henderson     unsigned len, width;
3777c53e401eSRichard Henderson     uint64_t mask0, mask1;
37786fd0c7bcSRichard Henderson     TCGv_i64 dest;
37790b1347d2SRichard Henderson 
378072ae4f2bSRichard Henderson     if (!ctx->is_pa20 && a->d) {
378172ae4f2bSRichard Henderson         return false;
378272ae4f2bSRichard Henderson     }
378330878590SRichard Henderson     if (a->c) {
37840b1347d2SRichard Henderson         nullify_over(ctx);
37850b1347d2SRichard Henderson     }
378672ae4f2bSRichard Henderson 
378772ae4f2bSRichard Henderson     len = a->len;
378872ae4f2bSRichard Henderson     width = a->d ? 64 : 32;
378972ae4f2bSRichard Henderson     if (a->cpos + len > width) {
379072ae4f2bSRichard Henderson         len = width - a->cpos;
37910b1347d2SRichard Henderson     }
37920b1347d2SRichard Henderson 
379330878590SRichard Henderson     dest = dest_gpr(ctx, a->t);
379430878590SRichard Henderson     mask0 = deposit64(0, a->cpos, len, a->i);
379530878590SRichard Henderson     mask1 = deposit64(-1, a->cpos, len, a->i);
37960b1347d2SRichard Henderson 
379730878590SRichard Henderson     if (a->nz) {
37986fd0c7bcSRichard Henderson         TCGv_i64 src = load_gpr(ctx, a->t);
37996fd0c7bcSRichard Henderson         tcg_gen_andi_i64(dest, src, mask1);
38006fd0c7bcSRichard Henderson         tcg_gen_ori_i64(dest, dest, mask0);
38010b1347d2SRichard Henderson     } else {
38026fd0c7bcSRichard Henderson         tcg_gen_movi_i64(dest, mask0);
38030b1347d2SRichard Henderson     }
380430878590SRichard Henderson     save_gpr(ctx, a->t, dest);
38050b1347d2SRichard Henderson 
38060b1347d2SRichard Henderson     /* Install the new nullification.  */
38070b1347d2SRichard Henderson     cond_free(&ctx->null_cond);
380830878590SRichard Henderson     if (a->c) {
380972ae4f2bSRichard Henderson         ctx->null_cond = do_sed_cond(ctx, a->c, a->d, dest);
38100b1347d2SRichard Henderson     }
381131234768SRichard Henderson     return nullify_end(ctx);
38120b1347d2SRichard Henderson }
38130b1347d2SRichard Henderson 
381472ae4f2bSRichard Henderson static bool trans_dep_imm(DisasContext *ctx, arg_dep_imm *a)
38150b1347d2SRichard Henderson {
381630878590SRichard Henderson     unsigned rs = a->nz ? a->t : 0;
381772ae4f2bSRichard Henderson     unsigned len, width;
38186fd0c7bcSRichard Henderson     TCGv_i64 dest, val;
38190b1347d2SRichard Henderson 
382072ae4f2bSRichard Henderson     if (!ctx->is_pa20 && a->d) {
382172ae4f2bSRichard Henderson         return false;
382272ae4f2bSRichard Henderson     }
382330878590SRichard Henderson     if (a->c) {
38240b1347d2SRichard Henderson         nullify_over(ctx);
38250b1347d2SRichard Henderson     }
382672ae4f2bSRichard Henderson 
382772ae4f2bSRichard Henderson     len = a->len;
382872ae4f2bSRichard Henderson     width = a->d ? 64 : 32;
382972ae4f2bSRichard Henderson     if (a->cpos + len > width) {
383072ae4f2bSRichard Henderson         len = width - a->cpos;
38310b1347d2SRichard Henderson     }
38320b1347d2SRichard Henderson 
383330878590SRichard Henderson     dest = dest_gpr(ctx, a->t);
383430878590SRichard Henderson     val = load_gpr(ctx, a->r);
38350b1347d2SRichard Henderson     if (rs == 0) {
38366fd0c7bcSRichard Henderson         tcg_gen_deposit_z_i64(dest, val, a->cpos, len);
38370b1347d2SRichard Henderson     } else {
38386fd0c7bcSRichard Henderson         tcg_gen_deposit_i64(dest, cpu_gr[rs], val, a->cpos, len);
38390b1347d2SRichard Henderson     }
384030878590SRichard Henderson     save_gpr(ctx, a->t, dest);
38410b1347d2SRichard Henderson 
38420b1347d2SRichard Henderson     /* Install the new nullification.  */
38430b1347d2SRichard Henderson     cond_free(&ctx->null_cond);
384430878590SRichard Henderson     if (a->c) {
384572ae4f2bSRichard Henderson         ctx->null_cond = do_sed_cond(ctx, a->c, a->d, dest);
38460b1347d2SRichard Henderson     }
384731234768SRichard Henderson     return nullify_end(ctx);
38480b1347d2SRichard Henderson }
38490b1347d2SRichard Henderson 
385072ae4f2bSRichard Henderson static bool do_dep_sar(DisasContext *ctx, unsigned rt, unsigned c,
38516fd0c7bcSRichard Henderson                        bool d, bool nz, unsigned len, TCGv_i64 val)
38520b1347d2SRichard Henderson {
38530b1347d2SRichard Henderson     unsigned rs = nz ? rt : 0;
385472ae4f2bSRichard Henderson     unsigned widthm1 = d ? 63 : 31;
38556fd0c7bcSRichard Henderson     TCGv_i64 mask, tmp, shift, dest;
3856c53e401eSRichard Henderson     uint64_t msb = 1ULL << (len - 1);
38570b1347d2SRichard Henderson 
38580b1347d2SRichard Henderson     dest = dest_gpr(ctx, rt);
3859aac0f603SRichard Henderson     shift = tcg_temp_new_i64();
3860aac0f603SRichard Henderson     tmp = tcg_temp_new_i64();
38610b1347d2SRichard Henderson 
38620b1347d2SRichard Henderson     /* Convert big-endian bit numbering in SAR to left-shift.  */
38636fd0c7bcSRichard Henderson     tcg_gen_andi_i64(shift, cpu_sar, widthm1);
38646fd0c7bcSRichard Henderson     tcg_gen_xori_i64(shift, shift, widthm1);
38650b1347d2SRichard Henderson 
3866aac0f603SRichard Henderson     mask = tcg_temp_new_i64();
38676fd0c7bcSRichard Henderson     tcg_gen_movi_i64(mask, msb + (msb - 1));
38686fd0c7bcSRichard Henderson     tcg_gen_and_i64(tmp, val, mask);
38690b1347d2SRichard Henderson     if (rs) {
38706fd0c7bcSRichard Henderson         tcg_gen_shl_i64(mask, mask, shift);
38716fd0c7bcSRichard Henderson         tcg_gen_shl_i64(tmp, tmp, shift);
38726fd0c7bcSRichard Henderson         tcg_gen_andc_i64(dest, cpu_gr[rs], mask);
38736fd0c7bcSRichard Henderson         tcg_gen_or_i64(dest, dest, tmp);
38740b1347d2SRichard Henderson     } else {
38756fd0c7bcSRichard Henderson         tcg_gen_shl_i64(dest, tmp, shift);
38760b1347d2SRichard Henderson     }
38770b1347d2SRichard Henderson     save_gpr(ctx, rt, dest);
38780b1347d2SRichard Henderson 
38790b1347d2SRichard Henderson     /* Install the new nullification.  */
38800b1347d2SRichard Henderson     cond_free(&ctx->null_cond);
38810b1347d2SRichard Henderson     if (c) {
388272ae4f2bSRichard Henderson         ctx->null_cond = do_sed_cond(ctx, c, d, dest);
38830b1347d2SRichard Henderson     }
388431234768SRichard Henderson     return nullify_end(ctx);
38850b1347d2SRichard Henderson }
38860b1347d2SRichard Henderson 
388772ae4f2bSRichard Henderson static bool trans_dep_sar(DisasContext *ctx, arg_dep_sar *a)
388830878590SRichard Henderson {
388972ae4f2bSRichard Henderson     if (!ctx->is_pa20 && a->d) {
389072ae4f2bSRichard Henderson         return false;
389172ae4f2bSRichard Henderson     }
3892a6deecceSSven Schnelle     if (a->c) {
3893a6deecceSSven Schnelle         nullify_over(ctx);
3894a6deecceSSven Schnelle     }
389572ae4f2bSRichard Henderson     return do_dep_sar(ctx, a->t, a->c, a->d, a->nz, a->len,
389672ae4f2bSRichard Henderson                       load_gpr(ctx, a->r));
389730878590SRichard Henderson }
389830878590SRichard Henderson 
389972ae4f2bSRichard Henderson static bool trans_depi_sar(DisasContext *ctx, arg_depi_sar *a)
390030878590SRichard Henderson {
390172ae4f2bSRichard Henderson     if (!ctx->is_pa20 && a->d) {
390272ae4f2bSRichard Henderson         return false;
390372ae4f2bSRichard Henderson     }
3904a6deecceSSven Schnelle     if (a->c) {
3905a6deecceSSven Schnelle         nullify_over(ctx);
3906a6deecceSSven Schnelle     }
390772ae4f2bSRichard Henderson     return do_dep_sar(ctx, a->t, a->c, a->d, a->nz, a->len,
39086fd0c7bcSRichard Henderson                       tcg_constant_i64(a->i));
390930878590SRichard Henderson }
39100b1347d2SRichard Henderson 
39118340f534SRichard Henderson static bool trans_be(DisasContext *ctx, arg_be *a)
391298cd9ca7SRichard Henderson {
39136fd0c7bcSRichard Henderson     TCGv_i64 tmp;
391498cd9ca7SRichard Henderson 
3915c301f34eSRichard Henderson #ifdef CONFIG_USER_ONLY
391698cd9ca7SRichard Henderson     /* ??? It seems like there should be a good way of using
391798cd9ca7SRichard Henderson        "be disp(sr2, r0)", the canonical gateway entry mechanism
391898cd9ca7SRichard Henderson        to our advantage.  But that appears to be inconvenient to
391998cd9ca7SRichard Henderson        manage along side branch delay slots.  Therefore we handle
392098cd9ca7SRichard Henderson        entry into the gateway page via absolute address.  */
392198cd9ca7SRichard Henderson     /* Since we don't implement spaces, just branch.  Do notice the special
392298cd9ca7SRichard Henderson        case of "be disp(*,r0)" using a direct branch to disp, so that we can
392398cd9ca7SRichard Henderson        goto_tb to the TB containing the syscall.  */
39248340f534SRichard Henderson     if (a->b == 0) {
39258340f534SRichard Henderson         return do_dbranch(ctx, a->disp, a->l, a->n);
392698cd9ca7SRichard Henderson     }
3927c301f34eSRichard Henderson #else
3928c301f34eSRichard Henderson     nullify_over(ctx);
3929660eefe1SRichard Henderson #endif
3930660eefe1SRichard Henderson 
3931aac0f603SRichard Henderson     tmp = tcg_temp_new_i64();
39326fd0c7bcSRichard Henderson     tcg_gen_addi_i64(tmp, load_gpr(ctx, a->b), a->disp);
3933660eefe1SRichard Henderson     tmp = do_ibranch_priv(ctx, tmp);
3934c301f34eSRichard Henderson 
3935c301f34eSRichard Henderson #ifdef CONFIG_USER_ONLY
39368340f534SRichard Henderson     return do_ibranch(ctx, tmp, a->l, a->n);
3937c301f34eSRichard Henderson #else
3938c301f34eSRichard Henderson     TCGv_i64 new_spc = tcg_temp_new_i64();
3939c301f34eSRichard Henderson 
39408340f534SRichard Henderson     load_spr(ctx, new_spc, a->sp);
39418340f534SRichard Henderson     if (a->l) {
3942741322f4SRichard Henderson         copy_iaoq_entry(ctx, cpu_gr[31], ctx->iaoq_n, ctx->iaoq_n_var);
39437fb7c9daSRichard Henderson         tcg_gen_mov_i64(cpu_sr[0], cpu_iasq_b);
3944c301f34eSRichard Henderson     }
39458340f534SRichard Henderson     if (a->n && use_nullify_skip(ctx)) {
3946a0180973SRichard Henderson         copy_iaoq_entry(ctx, cpu_iaoq_f, -1, tmp);
39476fd0c7bcSRichard Henderson         tcg_gen_addi_i64(tmp, tmp, 4);
3948a0180973SRichard Henderson         copy_iaoq_entry(ctx, cpu_iaoq_b, -1, tmp);
3949c301f34eSRichard Henderson         tcg_gen_mov_i64(cpu_iasq_f, new_spc);
3950c301f34eSRichard Henderson         tcg_gen_mov_i64(cpu_iasq_b, cpu_iasq_f);
3951c301f34eSRichard Henderson     } else {
3952741322f4SRichard Henderson         copy_iaoq_entry(ctx, cpu_iaoq_f, ctx->iaoq_b, cpu_iaoq_b);
3953c301f34eSRichard Henderson         if (ctx->iaoq_b == -1) {
3954c301f34eSRichard Henderson             tcg_gen_mov_i64(cpu_iasq_f, cpu_iasq_b);
3955c301f34eSRichard Henderson         }
3956a0180973SRichard Henderson         copy_iaoq_entry(ctx, cpu_iaoq_b, -1, tmp);
3957c301f34eSRichard Henderson         tcg_gen_mov_i64(cpu_iasq_b, new_spc);
39588340f534SRichard Henderson         nullify_set(ctx, a->n);
3959c301f34eSRichard Henderson     }
3960c301f34eSRichard Henderson     tcg_gen_lookup_and_goto_ptr();
396131234768SRichard Henderson     ctx->base.is_jmp = DISAS_NORETURN;
396231234768SRichard Henderson     return nullify_end(ctx);
3963c301f34eSRichard Henderson #endif
396498cd9ca7SRichard Henderson }
396598cd9ca7SRichard Henderson 
39668340f534SRichard Henderson static bool trans_bl(DisasContext *ctx, arg_bl *a)
396798cd9ca7SRichard Henderson {
39688340f534SRichard Henderson     return do_dbranch(ctx, iaoq_dest(ctx, a->disp), a->l, a->n);
396998cd9ca7SRichard Henderson }
397098cd9ca7SRichard Henderson 
39718340f534SRichard Henderson static bool trans_b_gate(DisasContext *ctx, arg_b_gate *a)
397243e05652SRichard Henderson {
3973c53e401eSRichard Henderson     uint64_t dest = iaoq_dest(ctx, a->disp);
397443e05652SRichard Henderson 
39756e5f5300SSven Schnelle     nullify_over(ctx);
39766e5f5300SSven Schnelle 
397743e05652SRichard Henderson     /* Make sure the caller hasn't done something weird with the queue.
397843e05652SRichard Henderson      * ??? This is not quite the same as the PSW[B] bit, which would be
397943e05652SRichard Henderson      * expensive to track.  Real hardware will trap for
398043e05652SRichard Henderson      *    b  gateway
398143e05652SRichard Henderson      *    b  gateway+4  (in delay slot of first branch)
398243e05652SRichard Henderson      * However, checking for a non-sequential instruction queue *will*
398343e05652SRichard Henderson      * diagnose the security hole
398443e05652SRichard Henderson      *    b  gateway
398543e05652SRichard Henderson      *    b  evil
398643e05652SRichard Henderson      * in which instructions at evil would run with increased privs.
398743e05652SRichard Henderson      */
398843e05652SRichard Henderson     if (ctx->iaoq_b == -1 || ctx->iaoq_b != ctx->iaoq_f + 4) {
398943e05652SRichard Henderson         return gen_illegal(ctx);
399043e05652SRichard Henderson     }
399143e05652SRichard Henderson 
399243e05652SRichard Henderson #ifndef CONFIG_USER_ONLY
399343e05652SRichard Henderson     if (ctx->tb_flags & PSW_C) {
399494956d7bSPhilippe Mathieu-Daudé         int type = hppa_artype_for_page(cpu_env(ctx->cs), ctx->base.pc_next);
399543e05652SRichard Henderson         /* If we could not find a TLB entry, then we need to generate an
399643e05652SRichard Henderson            ITLB miss exception so the kernel will provide it.
399743e05652SRichard Henderson            The resulting TLB fill operation will invalidate this TB and
399843e05652SRichard Henderson            we will re-translate, at which point we *will* be able to find
399943e05652SRichard Henderson            the TLB entry and determine if this is in fact a gateway page.  */
400043e05652SRichard Henderson         if (type < 0) {
400131234768SRichard Henderson             gen_excp(ctx, EXCP_ITLB_MISS);
400231234768SRichard Henderson             return true;
400343e05652SRichard Henderson         }
400443e05652SRichard Henderson         /* No change for non-gateway pages or for priv decrease.  */
400543e05652SRichard Henderson         if (type >= 4 && type - 4 < ctx->privilege) {
40062f48ba7bSRichard Henderson             dest = deposit64(dest, 0, 2, type - 4);
400743e05652SRichard Henderson         }
400843e05652SRichard Henderson     } else {
400943e05652SRichard Henderson         dest &= -4;  /* priv = 0 */
401043e05652SRichard Henderson     }
401143e05652SRichard Henderson #endif
401243e05652SRichard Henderson 
40136e5f5300SSven Schnelle     if (a->l) {
40146fd0c7bcSRichard Henderson         TCGv_i64 tmp = dest_gpr(ctx, a->l);
40156e5f5300SSven Schnelle         if (ctx->privilege < 3) {
40166fd0c7bcSRichard Henderson             tcg_gen_andi_i64(tmp, tmp, -4);
40176e5f5300SSven Schnelle         }
40186fd0c7bcSRichard Henderson         tcg_gen_ori_i64(tmp, tmp, ctx->privilege);
40196e5f5300SSven Schnelle         save_gpr(ctx, a->l, tmp);
40206e5f5300SSven Schnelle     }
40216e5f5300SSven Schnelle 
40226e5f5300SSven Schnelle     return do_dbranch(ctx, dest, 0, a->n);
402343e05652SRichard Henderson }
402443e05652SRichard Henderson 
40258340f534SRichard Henderson static bool trans_blr(DisasContext *ctx, arg_blr *a)
402698cd9ca7SRichard Henderson {
4027b35aec85SRichard Henderson     if (a->x) {
4028aac0f603SRichard Henderson         TCGv_i64 tmp = tcg_temp_new_i64();
40296fd0c7bcSRichard Henderson         tcg_gen_shli_i64(tmp, load_gpr(ctx, a->x), 3);
40306fd0c7bcSRichard Henderson         tcg_gen_addi_i64(tmp, tmp, ctx->iaoq_f + 8);
4031660eefe1SRichard Henderson         /* The computation here never changes privilege level.  */
40328340f534SRichard Henderson         return do_ibranch(ctx, tmp, a->l, a->n);
4033b35aec85SRichard Henderson     } else {
4034b35aec85SRichard Henderson         /* BLR R0,RX is a good way to load PC+8 into RX.  */
4035b35aec85SRichard Henderson         return do_dbranch(ctx, ctx->iaoq_f + 8, a->l, a->n);
4036b35aec85SRichard Henderson     }
403798cd9ca7SRichard Henderson }
403898cd9ca7SRichard Henderson 
40398340f534SRichard Henderson static bool trans_bv(DisasContext *ctx, arg_bv *a)
404098cd9ca7SRichard Henderson {
40416fd0c7bcSRichard Henderson     TCGv_i64 dest;
404298cd9ca7SRichard Henderson 
40438340f534SRichard Henderson     if (a->x == 0) {
40448340f534SRichard Henderson         dest = load_gpr(ctx, a->b);
404598cd9ca7SRichard Henderson     } else {
4046aac0f603SRichard Henderson         dest = tcg_temp_new_i64();
40476fd0c7bcSRichard Henderson         tcg_gen_shli_i64(dest, load_gpr(ctx, a->x), 3);
40486fd0c7bcSRichard Henderson         tcg_gen_add_i64(dest, dest, load_gpr(ctx, a->b));
404998cd9ca7SRichard Henderson     }
4050660eefe1SRichard Henderson     dest = do_ibranch_priv(ctx, dest);
40518340f534SRichard Henderson     return do_ibranch(ctx, dest, 0, a->n);
405298cd9ca7SRichard Henderson }
405398cd9ca7SRichard Henderson 
40548340f534SRichard Henderson static bool trans_bve(DisasContext *ctx, arg_bve *a)
405598cd9ca7SRichard Henderson {
40566fd0c7bcSRichard Henderson     TCGv_i64 dest;
405798cd9ca7SRichard Henderson 
4058c301f34eSRichard Henderson #ifdef CONFIG_USER_ONLY
40598340f534SRichard Henderson     dest = do_ibranch_priv(ctx, load_gpr(ctx, a->b));
40608340f534SRichard Henderson     return do_ibranch(ctx, dest, a->l, a->n);
4061c301f34eSRichard Henderson #else
4062c301f34eSRichard Henderson     nullify_over(ctx);
40638340f534SRichard Henderson     dest = do_ibranch_priv(ctx, load_gpr(ctx, a->b));
4064c301f34eSRichard Henderson 
4065741322f4SRichard Henderson     copy_iaoq_entry(ctx, cpu_iaoq_f, ctx->iaoq_b, cpu_iaoq_b);
4066c301f34eSRichard Henderson     if (ctx->iaoq_b == -1) {
4067c301f34eSRichard Henderson         tcg_gen_mov_i64(cpu_iasq_f, cpu_iasq_b);
4068c301f34eSRichard Henderson     }
4069741322f4SRichard Henderson     copy_iaoq_entry(ctx, cpu_iaoq_b, -1, dest);
4070c301f34eSRichard Henderson     tcg_gen_mov_i64(cpu_iasq_b, space_select(ctx, 0, dest));
40718340f534SRichard Henderson     if (a->l) {
4072741322f4SRichard Henderson         copy_iaoq_entry(ctx, cpu_gr[a->l], ctx->iaoq_n, ctx->iaoq_n_var);
4073c301f34eSRichard Henderson     }
40748340f534SRichard Henderson     nullify_set(ctx, a->n);
4075c301f34eSRichard Henderson     tcg_gen_lookup_and_goto_ptr();
407631234768SRichard Henderson     ctx->base.is_jmp = DISAS_NORETURN;
407731234768SRichard Henderson     return nullify_end(ctx);
4078c301f34eSRichard Henderson #endif
407998cd9ca7SRichard Henderson }
408098cd9ca7SRichard Henderson 
4081a8966ba7SRichard Henderson static bool trans_nopbts(DisasContext *ctx, arg_nopbts *a)
4082a8966ba7SRichard Henderson {
4083a8966ba7SRichard Henderson     /* All branch target stack instructions implement as nop. */
4084a8966ba7SRichard Henderson     return ctx->is_pa20;
4085a8966ba7SRichard Henderson }
4086a8966ba7SRichard Henderson 
40871ca74648SRichard Henderson /*
40881ca74648SRichard Henderson  * Float class 0
40891ca74648SRichard Henderson  */
4090ebe9383cSRichard Henderson 
40911ca74648SRichard Henderson static void gen_fcpy_f(TCGv_i32 dst, TCGv_env unused, TCGv_i32 src)
4092ebe9383cSRichard Henderson {
4093ebe9383cSRichard Henderson     tcg_gen_mov_i32(dst, src);
4094ebe9383cSRichard Henderson }
4095ebe9383cSRichard Henderson 
409659f8c04bSHelge Deller static bool trans_fid_f(DisasContext *ctx, arg_fid_f *a)
409759f8c04bSHelge Deller {
4098a300dad3SRichard Henderson     uint64_t ret;
4099a300dad3SRichard Henderson 
4100c53e401eSRichard Henderson     if (ctx->is_pa20) {
4101a300dad3SRichard Henderson         ret = 0x13080000000000ULL; /* PA8700 (PCX-W2) */
4102a300dad3SRichard Henderson     } else {
4103a300dad3SRichard Henderson         ret = 0x0f080000000000ULL; /* PA7300LC (PCX-L2) */
4104a300dad3SRichard Henderson     }
4105a300dad3SRichard Henderson 
410659f8c04bSHelge Deller     nullify_over(ctx);
4107a300dad3SRichard Henderson     save_frd(0, tcg_constant_i64(ret));
410859f8c04bSHelge Deller     return nullify_end(ctx);
410959f8c04bSHelge Deller }
411059f8c04bSHelge Deller 
41111ca74648SRichard Henderson static bool trans_fcpy_f(DisasContext *ctx, arg_fclass01 *a)
41121ca74648SRichard Henderson {
41131ca74648SRichard Henderson     return do_fop_wew(ctx, a->t, a->r, gen_fcpy_f);
41141ca74648SRichard Henderson }
41151ca74648SRichard Henderson 
4116ebe9383cSRichard Henderson static void gen_fcpy_d(TCGv_i64 dst, TCGv_env unused, TCGv_i64 src)
4117ebe9383cSRichard Henderson {
4118ebe9383cSRichard Henderson     tcg_gen_mov_i64(dst, src);
4119ebe9383cSRichard Henderson }
4120ebe9383cSRichard Henderson 
41211ca74648SRichard Henderson static bool trans_fcpy_d(DisasContext *ctx, arg_fclass01 *a)
41221ca74648SRichard Henderson {
41231ca74648SRichard Henderson     return do_fop_ded(ctx, a->t, a->r, gen_fcpy_d);
41241ca74648SRichard Henderson }
41251ca74648SRichard Henderson 
41261ca74648SRichard Henderson static void gen_fabs_f(TCGv_i32 dst, TCGv_env unused, TCGv_i32 src)
4127ebe9383cSRichard Henderson {
4128ebe9383cSRichard Henderson     tcg_gen_andi_i32(dst, src, INT32_MAX);
4129ebe9383cSRichard Henderson }
4130ebe9383cSRichard Henderson 
41311ca74648SRichard Henderson static bool trans_fabs_f(DisasContext *ctx, arg_fclass01 *a)
41321ca74648SRichard Henderson {
41331ca74648SRichard Henderson     return do_fop_wew(ctx, a->t, a->r, gen_fabs_f);
41341ca74648SRichard Henderson }
41351ca74648SRichard Henderson 
4136ebe9383cSRichard Henderson static void gen_fabs_d(TCGv_i64 dst, TCGv_env unused, TCGv_i64 src)
4137ebe9383cSRichard Henderson {
4138ebe9383cSRichard Henderson     tcg_gen_andi_i64(dst, src, INT64_MAX);
4139ebe9383cSRichard Henderson }
4140ebe9383cSRichard Henderson 
41411ca74648SRichard Henderson static bool trans_fabs_d(DisasContext *ctx, arg_fclass01 *a)
41421ca74648SRichard Henderson {
41431ca74648SRichard Henderson     return do_fop_ded(ctx, a->t, a->r, gen_fabs_d);
41441ca74648SRichard Henderson }
41451ca74648SRichard Henderson 
41461ca74648SRichard Henderson static bool trans_fsqrt_f(DisasContext *ctx, arg_fclass01 *a)
41471ca74648SRichard Henderson {
41481ca74648SRichard Henderson     return do_fop_wew(ctx, a->t, a->r, gen_helper_fsqrt_s);
41491ca74648SRichard Henderson }
41501ca74648SRichard Henderson 
41511ca74648SRichard Henderson static bool trans_fsqrt_d(DisasContext *ctx, arg_fclass01 *a)
41521ca74648SRichard Henderson {
41531ca74648SRichard Henderson     return do_fop_ded(ctx, a->t, a->r, gen_helper_fsqrt_d);
41541ca74648SRichard Henderson }
41551ca74648SRichard Henderson 
41561ca74648SRichard Henderson static bool trans_frnd_f(DisasContext *ctx, arg_fclass01 *a)
41571ca74648SRichard Henderson {
41581ca74648SRichard Henderson     return do_fop_wew(ctx, a->t, a->r, gen_helper_frnd_s);
41591ca74648SRichard Henderson }
41601ca74648SRichard Henderson 
41611ca74648SRichard Henderson static bool trans_frnd_d(DisasContext *ctx, arg_fclass01 *a)
41621ca74648SRichard Henderson {
41631ca74648SRichard Henderson     return do_fop_ded(ctx, a->t, a->r, gen_helper_frnd_d);
41641ca74648SRichard Henderson }
41651ca74648SRichard Henderson 
41661ca74648SRichard Henderson static void gen_fneg_f(TCGv_i32 dst, TCGv_env unused, TCGv_i32 src)
4167ebe9383cSRichard Henderson {
4168ebe9383cSRichard Henderson     tcg_gen_xori_i32(dst, src, INT32_MIN);
4169ebe9383cSRichard Henderson }
4170ebe9383cSRichard Henderson 
41711ca74648SRichard Henderson static bool trans_fneg_f(DisasContext *ctx, arg_fclass01 *a)
41721ca74648SRichard Henderson {
41731ca74648SRichard Henderson     return do_fop_wew(ctx, a->t, a->r, gen_fneg_f);
41741ca74648SRichard Henderson }
41751ca74648SRichard Henderson 
4176ebe9383cSRichard Henderson static void gen_fneg_d(TCGv_i64 dst, TCGv_env unused, TCGv_i64 src)
4177ebe9383cSRichard Henderson {
4178ebe9383cSRichard Henderson     tcg_gen_xori_i64(dst, src, INT64_MIN);
4179ebe9383cSRichard Henderson }
4180ebe9383cSRichard Henderson 
41811ca74648SRichard Henderson static bool trans_fneg_d(DisasContext *ctx, arg_fclass01 *a)
41821ca74648SRichard Henderson {
41831ca74648SRichard Henderson     return do_fop_ded(ctx, a->t, a->r, gen_fneg_d);
41841ca74648SRichard Henderson }
41851ca74648SRichard Henderson 
41861ca74648SRichard Henderson static void gen_fnegabs_f(TCGv_i32 dst, TCGv_env unused, TCGv_i32 src)
4187ebe9383cSRichard Henderson {
4188ebe9383cSRichard Henderson     tcg_gen_ori_i32(dst, src, INT32_MIN);
4189ebe9383cSRichard Henderson }
4190ebe9383cSRichard Henderson 
41911ca74648SRichard Henderson static bool trans_fnegabs_f(DisasContext *ctx, arg_fclass01 *a)
41921ca74648SRichard Henderson {
41931ca74648SRichard Henderson     return do_fop_wew(ctx, a->t, a->r, gen_fnegabs_f);
41941ca74648SRichard Henderson }
41951ca74648SRichard Henderson 
4196ebe9383cSRichard Henderson static void gen_fnegabs_d(TCGv_i64 dst, TCGv_env unused, TCGv_i64 src)
4197ebe9383cSRichard Henderson {
4198ebe9383cSRichard Henderson     tcg_gen_ori_i64(dst, src, INT64_MIN);
4199ebe9383cSRichard Henderson }
4200ebe9383cSRichard Henderson 
42011ca74648SRichard Henderson static bool trans_fnegabs_d(DisasContext *ctx, arg_fclass01 *a)
42021ca74648SRichard Henderson {
42031ca74648SRichard Henderson     return do_fop_ded(ctx, a->t, a->r, gen_fnegabs_d);
42041ca74648SRichard Henderson }
42051ca74648SRichard Henderson 
42061ca74648SRichard Henderson /*
42071ca74648SRichard Henderson  * Float class 1
42081ca74648SRichard Henderson  */
42091ca74648SRichard Henderson 
42101ca74648SRichard Henderson static bool trans_fcnv_d_f(DisasContext *ctx, arg_fclass01 *a)
42111ca74648SRichard Henderson {
42121ca74648SRichard Henderson     return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_d_s);
42131ca74648SRichard Henderson }
42141ca74648SRichard Henderson 
42151ca74648SRichard Henderson static bool trans_fcnv_f_d(DisasContext *ctx, arg_fclass01 *a)
42161ca74648SRichard Henderson {
42171ca74648SRichard Henderson     return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_s_d);
42181ca74648SRichard Henderson }
42191ca74648SRichard Henderson 
42201ca74648SRichard Henderson static bool trans_fcnv_w_f(DisasContext *ctx, arg_fclass01 *a)
42211ca74648SRichard Henderson {
42221ca74648SRichard Henderson     return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_w_s);
42231ca74648SRichard Henderson }
42241ca74648SRichard Henderson 
42251ca74648SRichard Henderson static bool trans_fcnv_q_f(DisasContext *ctx, arg_fclass01 *a)
42261ca74648SRichard Henderson {
42271ca74648SRichard Henderson     return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_dw_s);
42281ca74648SRichard Henderson }
42291ca74648SRichard Henderson 
42301ca74648SRichard Henderson static bool trans_fcnv_w_d(DisasContext *ctx, arg_fclass01 *a)
42311ca74648SRichard Henderson {
42321ca74648SRichard Henderson     return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_w_d);
42331ca74648SRichard Henderson }
42341ca74648SRichard Henderson 
42351ca74648SRichard Henderson static bool trans_fcnv_q_d(DisasContext *ctx, arg_fclass01 *a)
42361ca74648SRichard Henderson {
42371ca74648SRichard Henderson     return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_dw_d);
42381ca74648SRichard Henderson }
42391ca74648SRichard Henderson 
42401ca74648SRichard Henderson static bool trans_fcnv_f_w(DisasContext *ctx, arg_fclass01 *a)
42411ca74648SRichard Henderson {
42421ca74648SRichard Henderson     return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_s_w);
42431ca74648SRichard Henderson }
42441ca74648SRichard Henderson 
42451ca74648SRichard Henderson static bool trans_fcnv_d_w(DisasContext *ctx, arg_fclass01 *a)
42461ca74648SRichard Henderson {
42471ca74648SRichard Henderson     return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_d_w);
42481ca74648SRichard Henderson }
42491ca74648SRichard Henderson 
42501ca74648SRichard Henderson static bool trans_fcnv_f_q(DisasContext *ctx, arg_fclass01 *a)
42511ca74648SRichard Henderson {
42521ca74648SRichard Henderson     return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_s_dw);
42531ca74648SRichard Henderson }
42541ca74648SRichard Henderson 
42551ca74648SRichard Henderson static bool trans_fcnv_d_q(DisasContext *ctx, arg_fclass01 *a)
42561ca74648SRichard Henderson {
42571ca74648SRichard Henderson     return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_d_dw);
42581ca74648SRichard Henderson }
42591ca74648SRichard Henderson 
42601ca74648SRichard Henderson static bool trans_fcnv_t_f_w(DisasContext *ctx, arg_fclass01 *a)
42611ca74648SRichard Henderson {
42621ca74648SRichard Henderson     return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_t_s_w);
42631ca74648SRichard Henderson }
42641ca74648SRichard Henderson 
42651ca74648SRichard Henderson static bool trans_fcnv_t_d_w(DisasContext *ctx, arg_fclass01 *a)
42661ca74648SRichard Henderson {
42671ca74648SRichard Henderson     return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_t_d_w);
42681ca74648SRichard Henderson }
42691ca74648SRichard Henderson 
42701ca74648SRichard Henderson static bool trans_fcnv_t_f_q(DisasContext *ctx, arg_fclass01 *a)
42711ca74648SRichard Henderson {
42721ca74648SRichard Henderson     return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_t_s_dw);
42731ca74648SRichard Henderson }
42741ca74648SRichard Henderson 
42751ca74648SRichard Henderson static bool trans_fcnv_t_d_q(DisasContext *ctx, arg_fclass01 *a)
42761ca74648SRichard Henderson {
42771ca74648SRichard Henderson     return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_t_d_dw);
42781ca74648SRichard Henderson }
42791ca74648SRichard Henderson 
42801ca74648SRichard Henderson static bool trans_fcnv_uw_f(DisasContext *ctx, arg_fclass01 *a)
42811ca74648SRichard Henderson {
42821ca74648SRichard Henderson     return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_uw_s);
42831ca74648SRichard Henderson }
42841ca74648SRichard Henderson 
42851ca74648SRichard Henderson static bool trans_fcnv_uq_f(DisasContext *ctx, arg_fclass01 *a)
42861ca74648SRichard Henderson {
42871ca74648SRichard Henderson     return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_udw_s);
42881ca74648SRichard Henderson }
42891ca74648SRichard Henderson 
42901ca74648SRichard Henderson static bool trans_fcnv_uw_d(DisasContext *ctx, arg_fclass01 *a)
42911ca74648SRichard Henderson {
42921ca74648SRichard Henderson     return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_uw_d);
42931ca74648SRichard Henderson }
42941ca74648SRichard Henderson 
42951ca74648SRichard Henderson static bool trans_fcnv_uq_d(DisasContext *ctx, arg_fclass01 *a)
42961ca74648SRichard Henderson {
42971ca74648SRichard Henderson     return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_udw_d);
42981ca74648SRichard Henderson }
42991ca74648SRichard Henderson 
43001ca74648SRichard Henderson static bool trans_fcnv_f_uw(DisasContext *ctx, arg_fclass01 *a)
43011ca74648SRichard Henderson {
43021ca74648SRichard Henderson     return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_s_uw);
43031ca74648SRichard Henderson }
43041ca74648SRichard Henderson 
43051ca74648SRichard Henderson static bool trans_fcnv_d_uw(DisasContext *ctx, arg_fclass01 *a)
43061ca74648SRichard Henderson {
43071ca74648SRichard Henderson     return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_d_uw);
43081ca74648SRichard Henderson }
43091ca74648SRichard Henderson 
43101ca74648SRichard Henderson static bool trans_fcnv_f_uq(DisasContext *ctx, arg_fclass01 *a)
43111ca74648SRichard Henderson {
43121ca74648SRichard Henderson     return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_s_udw);
43131ca74648SRichard Henderson }
43141ca74648SRichard Henderson 
43151ca74648SRichard Henderson static bool trans_fcnv_d_uq(DisasContext *ctx, arg_fclass01 *a)
43161ca74648SRichard Henderson {
43171ca74648SRichard Henderson     return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_d_udw);
43181ca74648SRichard Henderson }
43191ca74648SRichard Henderson 
43201ca74648SRichard Henderson static bool trans_fcnv_t_f_uw(DisasContext *ctx, arg_fclass01 *a)
43211ca74648SRichard Henderson {
43221ca74648SRichard Henderson     return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_t_s_uw);
43231ca74648SRichard Henderson }
43241ca74648SRichard Henderson 
43251ca74648SRichard Henderson static bool trans_fcnv_t_d_uw(DisasContext *ctx, arg_fclass01 *a)
43261ca74648SRichard Henderson {
43271ca74648SRichard Henderson     return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_t_d_uw);
43281ca74648SRichard Henderson }
43291ca74648SRichard Henderson 
43301ca74648SRichard Henderson static bool trans_fcnv_t_f_uq(DisasContext *ctx, arg_fclass01 *a)
43311ca74648SRichard Henderson {
43321ca74648SRichard Henderson     return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_t_s_udw);
43331ca74648SRichard Henderson }
43341ca74648SRichard Henderson 
43351ca74648SRichard Henderson static bool trans_fcnv_t_d_uq(DisasContext *ctx, arg_fclass01 *a)
43361ca74648SRichard Henderson {
43371ca74648SRichard Henderson     return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_t_d_udw);
43381ca74648SRichard Henderson }
43391ca74648SRichard Henderson 
43401ca74648SRichard Henderson /*
43411ca74648SRichard Henderson  * Float class 2
43421ca74648SRichard Henderson  */
43431ca74648SRichard Henderson 
43441ca74648SRichard Henderson static bool trans_fcmp_f(DisasContext *ctx, arg_fclass2 *a)
4345ebe9383cSRichard Henderson {
4346ebe9383cSRichard Henderson     TCGv_i32 ta, tb, tc, ty;
4347ebe9383cSRichard Henderson 
4348ebe9383cSRichard Henderson     nullify_over(ctx);
4349ebe9383cSRichard Henderson 
43501ca74648SRichard Henderson     ta = load_frw0_i32(a->r1);
43511ca74648SRichard Henderson     tb = load_frw0_i32(a->r2);
435229dd6f64SRichard Henderson     ty = tcg_constant_i32(a->y);
435329dd6f64SRichard Henderson     tc = tcg_constant_i32(a->c);
4354ebe9383cSRichard Henderson 
4355ad75a51eSRichard Henderson     gen_helper_fcmp_s(tcg_env, ta, tb, ty, tc);
4356ebe9383cSRichard Henderson 
43571ca74648SRichard Henderson     return nullify_end(ctx);
4358ebe9383cSRichard Henderson }
4359ebe9383cSRichard Henderson 
43601ca74648SRichard Henderson static bool trans_fcmp_d(DisasContext *ctx, arg_fclass2 *a)
4361ebe9383cSRichard Henderson {
4362ebe9383cSRichard Henderson     TCGv_i64 ta, tb;
4363ebe9383cSRichard Henderson     TCGv_i32 tc, ty;
4364ebe9383cSRichard Henderson 
4365ebe9383cSRichard Henderson     nullify_over(ctx);
4366ebe9383cSRichard Henderson 
43671ca74648SRichard Henderson     ta = load_frd0(a->r1);
43681ca74648SRichard Henderson     tb = load_frd0(a->r2);
436929dd6f64SRichard Henderson     ty = tcg_constant_i32(a->y);
437029dd6f64SRichard Henderson     tc = tcg_constant_i32(a->c);
4371ebe9383cSRichard Henderson 
4372ad75a51eSRichard Henderson     gen_helper_fcmp_d(tcg_env, ta, tb, ty, tc);
4373ebe9383cSRichard Henderson 
437431234768SRichard Henderson     return nullify_end(ctx);
4375ebe9383cSRichard Henderson }
4376ebe9383cSRichard Henderson 
43771ca74648SRichard Henderson static bool trans_ftest(DisasContext *ctx, arg_ftest *a)
4378ebe9383cSRichard Henderson {
43796fd0c7bcSRichard Henderson     TCGv_i64 t;
4380ebe9383cSRichard Henderson 
4381ebe9383cSRichard Henderson     nullify_over(ctx);
4382ebe9383cSRichard Henderson 
4383aac0f603SRichard Henderson     t = tcg_temp_new_i64();
43846fd0c7bcSRichard Henderson     tcg_gen_ld32u_i64(t, tcg_env, offsetof(CPUHPPAState, fr0_shadow));
4385ebe9383cSRichard Henderson 
43861ca74648SRichard Henderson     if (a->y == 1) {
4387ebe9383cSRichard Henderson         int mask;
4388ebe9383cSRichard Henderson         bool inv = false;
4389ebe9383cSRichard Henderson 
43901ca74648SRichard Henderson         switch (a->c) {
4391ebe9383cSRichard Henderson         case 0: /* simple */
43926fd0c7bcSRichard Henderson             tcg_gen_andi_i64(t, t, 0x4000000);
4393ebe9383cSRichard Henderson             ctx->null_cond = cond_make_0(TCG_COND_NE, t);
4394ebe9383cSRichard Henderson             goto done;
4395ebe9383cSRichard Henderson         case 2: /* rej */
4396ebe9383cSRichard Henderson             inv = true;
4397ebe9383cSRichard Henderson             /* fallthru */
4398ebe9383cSRichard Henderson         case 1: /* acc */
4399ebe9383cSRichard Henderson             mask = 0x43ff800;
4400ebe9383cSRichard Henderson             break;
4401ebe9383cSRichard Henderson         case 6: /* rej8 */
4402ebe9383cSRichard Henderson             inv = true;
4403ebe9383cSRichard Henderson             /* fallthru */
4404ebe9383cSRichard Henderson         case 5: /* acc8 */
4405ebe9383cSRichard Henderson             mask = 0x43f8000;
4406ebe9383cSRichard Henderson             break;
4407ebe9383cSRichard Henderson         case 9: /* acc6 */
4408ebe9383cSRichard Henderson             mask = 0x43e0000;
4409ebe9383cSRichard Henderson             break;
4410ebe9383cSRichard Henderson         case 13: /* acc4 */
4411ebe9383cSRichard Henderson             mask = 0x4380000;
4412ebe9383cSRichard Henderson             break;
4413ebe9383cSRichard Henderson         case 17: /* acc2 */
4414ebe9383cSRichard Henderson             mask = 0x4200000;
4415ebe9383cSRichard Henderson             break;
4416ebe9383cSRichard Henderson         default:
44171ca74648SRichard Henderson             gen_illegal(ctx);
44181ca74648SRichard Henderson             return true;
4419ebe9383cSRichard Henderson         }
4420ebe9383cSRichard Henderson         if (inv) {
44216fd0c7bcSRichard Henderson             TCGv_i64 c = tcg_constant_i64(mask);
44226fd0c7bcSRichard Henderson             tcg_gen_or_i64(t, t, c);
4423ebe9383cSRichard Henderson             ctx->null_cond = cond_make(TCG_COND_EQ, t, c);
4424ebe9383cSRichard Henderson         } else {
44256fd0c7bcSRichard Henderson             tcg_gen_andi_i64(t, t, mask);
4426ebe9383cSRichard Henderson             ctx->null_cond = cond_make_0(TCG_COND_EQ, t);
4427ebe9383cSRichard Henderson         }
44281ca74648SRichard Henderson     } else {
44291ca74648SRichard Henderson         unsigned cbit = (a->y ^ 1) - 1;
44301ca74648SRichard Henderson 
44316fd0c7bcSRichard Henderson         tcg_gen_extract_i64(t, t, 21 - cbit, 1);
44321ca74648SRichard Henderson         ctx->null_cond = cond_make_0(TCG_COND_NE, t);
44331ca74648SRichard Henderson     }
44341ca74648SRichard Henderson 
4435ebe9383cSRichard Henderson  done:
443631234768SRichard Henderson     return nullify_end(ctx);
4437ebe9383cSRichard Henderson }
4438ebe9383cSRichard Henderson 
44391ca74648SRichard Henderson /*
44401ca74648SRichard Henderson  * Float class 2
44411ca74648SRichard Henderson  */
44421ca74648SRichard Henderson 
44431ca74648SRichard Henderson static bool trans_fadd_f(DisasContext *ctx, arg_fclass3 *a)
4444ebe9383cSRichard Henderson {
44451ca74648SRichard Henderson     return do_fop_weww(ctx, a->t, a->r1, a->r2, gen_helper_fadd_s);
44461ca74648SRichard Henderson }
44471ca74648SRichard Henderson 
44481ca74648SRichard Henderson static bool trans_fadd_d(DisasContext *ctx, arg_fclass3 *a)
44491ca74648SRichard Henderson {
44501ca74648SRichard Henderson     return do_fop_dedd(ctx, a->t, a->r1, a->r2, gen_helper_fadd_d);
44511ca74648SRichard Henderson }
44521ca74648SRichard Henderson 
44531ca74648SRichard Henderson static bool trans_fsub_f(DisasContext *ctx, arg_fclass3 *a)
44541ca74648SRichard Henderson {
44551ca74648SRichard Henderson     return do_fop_weww(ctx, a->t, a->r1, a->r2, gen_helper_fsub_s);
44561ca74648SRichard Henderson }
44571ca74648SRichard Henderson 
44581ca74648SRichard Henderson static bool trans_fsub_d(DisasContext *ctx, arg_fclass3 *a)
44591ca74648SRichard Henderson {
44601ca74648SRichard Henderson     return do_fop_dedd(ctx, a->t, a->r1, a->r2, gen_helper_fsub_d);
44611ca74648SRichard Henderson }
44621ca74648SRichard Henderson 
44631ca74648SRichard Henderson static bool trans_fmpy_f(DisasContext *ctx, arg_fclass3 *a)
44641ca74648SRichard Henderson {
44651ca74648SRichard Henderson     return do_fop_weww(ctx, a->t, a->r1, a->r2, gen_helper_fmpy_s);
44661ca74648SRichard Henderson }
44671ca74648SRichard Henderson 
44681ca74648SRichard Henderson static bool trans_fmpy_d(DisasContext *ctx, arg_fclass3 *a)
44691ca74648SRichard Henderson {
44701ca74648SRichard Henderson     return do_fop_dedd(ctx, a->t, a->r1, a->r2, gen_helper_fmpy_d);
44711ca74648SRichard Henderson }
44721ca74648SRichard Henderson 
44731ca74648SRichard Henderson static bool trans_fdiv_f(DisasContext *ctx, arg_fclass3 *a)
44741ca74648SRichard Henderson {
44751ca74648SRichard Henderson     return do_fop_weww(ctx, a->t, a->r1, a->r2, gen_helper_fdiv_s);
44761ca74648SRichard Henderson }
44771ca74648SRichard Henderson 
44781ca74648SRichard Henderson static bool trans_fdiv_d(DisasContext *ctx, arg_fclass3 *a)
44791ca74648SRichard Henderson {
44801ca74648SRichard Henderson     return do_fop_dedd(ctx, a->t, a->r1, a->r2, gen_helper_fdiv_d);
44811ca74648SRichard Henderson }
44821ca74648SRichard Henderson 
44831ca74648SRichard Henderson static bool trans_xmpyu(DisasContext *ctx, arg_xmpyu *a)
44841ca74648SRichard Henderson {
44851ca74648SRichard Henderson     TCGv_i64 x, y;
4486ebe9383cSRichard Henderson 
4487ebe9383cSRichard Henderson     nullify_over(ctx);
4488ebe9383cSRichard Henderson 
44891ca74648SRichard Henderson     x = load_frw0_i64(a->r1);
44901ca74648SRichard Henderson     y = load_frw0_i64(a->r2);
44911ca74648SRichard Henderson     tcg_gen_mul_i64(x, x, y);
44921ca74648SRichard Henderson     save_frd(a->t, x);
4493ebe9383cSRichard Henderson 
449431234768SRichard Henderson     return nullify_end(ctx);
4495ebe9383cSRichard Henderson }
4496ebe9383cSRichard Henderson 
4497ebe9383cSRichard Henderson /* Convert the fmpyadd single-precision register encodings to standard.  */
4498ebe9383cSRichard Henderson static inline int fmpyadd_s_reg(unsigned r)
4499ebe9383cSRichard Henderson {
4500ebe9383cSRichard Henderson     return (r & 16) * 2 + 16 + (r & 15);
4501ebe9383cSRichard Henderson }
4502ebe9383cSRichard Henderson 
4503b1e2af57SRichard Henderson static bool do_fmpyadd_s(DisasContext *ctx, arg_mpyadd *a, bool is_sub)
4504ebe9383cSRichard Henderson {
4505b1e2af57SRichard Henderson     int tm = fmpyadd_s_reg(a->tm);
4506b1e2af57SRichard Henderson     int ra = fmpyadd_s_reg(a->ra);
4507b1e2af57SRichard Henderson     int ta = fmpyadd_s_reg(a->ta);
4508b1e2af57SRichard Henderson     int rm2 = fmpyadd_s_reg(a->rm2);
4509b1e2af57SRichard Henderson     int rm1 = fmpyadd_s_reg(a->rm1);
4510ebe9383cSRichard Henderson 
4511ebe9383cSRichard Henderson     nullify_over(ctx);
4512ebe9383cSRichard Henderson 
4513ebe9383cSRichard Henderson     do_fop_weww(ctx, tm, rm1, rm2, gen_helper_fmpy_s);
4514ebe9383cSRichard Henderson     do_fop_weww(ctx, ta, ta, ra,
4515ebe9383cSRichard Henderson                 is_sub ? gen_helper_fsub_s : gen_helper_fadd_s);
4516ebe9383cSRichard Henderson 
451731234768SRichard Henderson     return nullify_end(ctx);
4518ebe9383cSRichard Henderson }
4519ebe9383cSRichard Henderson 
4520b1e2af57SRichard Henderson static bool trans_fmpyadd_f(DisasContext *ctx, arg_mpyadd *a)
4521b1e2af57SRichard Henderson {
4522b1e2af57SRichard Henderson     return do_fmpyadd_s(ctx, a, false);
4523b1e2af57SRichard Henderson }
4524b1e2af57SRichard Henderson 
4525b1e2af57SRichard Henderson static bool trans_fmpysub_f(DisasContext *ctx, arg_mpyadd *a)
4526b1e2af57SRichard Henderson {
4527b1e2af57SRichard Henderson     return do_fmpyadd_s(ctx, a, true);
4528b1e2af57SRichard Henderson }
4529b1e2af57SRichard Henderson 
4530b1e2af57SRichard Henderson static bool do_fmpyadd_d(DisasContext *ctx, arg_mpyadd *a, bool is_sub)
4531b1e2af57SRichard Henderson {
4532b1e2af57SRichard Henderson     nullify_over(ctx);
4533b1e2af57SRichard Henderson 
4534b1e2af57SRichard Henderson     do_fop_dedd(ctx, a->tm, a->rm1, a->rm2, gen_helper_fmpy_d);
4535b1e2af57SRichard Henderson     do_fop_dedd(ctx, a->ta, a->ta, a->ra,
4536b1e2af57SRichard Henderson                 is_sub ? gen_helper_fsub_d : gen_helper_fadd_d);
4537b1e2af57SRichard Henderson 
4538b1e2af57SRichard Henderson     return nullify_end(ctx);
4539b1e2af57SRichard Henderson }
4540b1e2af57SRichard Henderson 
4541b1e2af57SRichard Henderson static bool trans_fmpyadd_d(DisasContext *ctx, arg_mpyadd *a)
4542b1e2af57SRichard Henderson {
4543b1e2af57SRichard Henderson     return do_fmpyadd_d(ctx, a, false);
4544b1e2af57SRichard Henderson }
4545b1e2af57SRichard Henderson 
4546b1e2af57SRichard Henderson static bool trans_fmpysub_d(DisasContext *ctx, arg_mpyadd *a)
4547b1e2af57SRichard Henderson {
4548b1e2af57SRichard Henderson     return do_fmpyadd_d(ctx, a, true);
4549b1e2af57SRichard Henderson }
4550b1e2af57SRichard Henderson 
4551c3bad4f8SRichard Henderson static bool trans_fmpyfadd_f(DisasContext *ctx, arg_fmpyfadd_f *a)
4552ebe9383cSRichard Henderson {
4553c3bad4f8SRichard Henderson     TCGv_i32 x, y, z;
4554ebe9383cSRichard Henderson 
4555ebe9383cSRichard Henderson     nullify_over(ctx);
4556c3bad4f8SRichard Henderson     x = load_frw0_i32(a->rm1);
4557c3bad4f8SRichard Henderson     y = load_frw0_i32(a->rm2);
4558c3bad4f8SRichard Henderson     z = load_frw0_i32(a->ra3);
4559ebe9383cSRichard Henderson 
4560c3bad4f8SRichard Henderson     if (a->neg) {
4561ad75a51eSRichard Henderson         gen_helper_fmpynfadd_s(x, tcg_env, x, y, z);
4562ebe9383cSRichard Henderson     } else {
4563ad75a51eSRichard Henderson         gen_helper_fmpyfadd_s(x, tcg_env, x, y, z);
4564ebe9383cSRichard Henderson     }
4565ebe9383cSRichard Henderson 
4566c3bad4f8SRichard Henderson     save_frw_i32(a->t, x);
456731234768SRichard Henderson     return nullify_end(ctx);
4568ebe9383cSRichard Henderson }
4569ebe9383cSRichard Henderson 
4570c3bad4f8SRichard Henderson static bool trans_fmpyfadd_d(DisasContext *ctx, arg_fmpyfadd_d *a)
4571ebe9383cSRichard Henderson {
4572c3bad4f8SRichard Henderson     TCGv_i64 x, y, z;
4573ebe9383cSRichard Henderson 
4574ebe9383cSRichard Henderson     nullify_over(ctx);
4575c3bad4f8SRichard Henderson     x = load_frd0(a->rm1);
4576c3bad4f8SRichard Henderson     y = load_frd0(a->rm2);
4577c3bad4f8SRichard Henderson     z = load_frd0(a->ra3);
4578ebe9383cSRichard Henderson 
4579c3bad4f8SRichard Henderson     if (a->neg) {
4580ad75a51eSRichard Henderson         gen_helper_fmpynfadd_d(x, tcg_env, x, y, z);
4581ebe9383cSRichard Henderson     } else {
4582ad75a51eSRichard Henderson         gen_helper_fmpyfadd_d(x, tcg_env, x, y, z);
4583ebe9383cSRichard Henderson     }
4584ebe9383cSRichard Henderson 
4585c3bad4f8SRichard Henderson     save_frd(a->t, x);
458631234768SRichard Henderson     return nullify_end(ctx);
4587ebe9383cSRichard Henderson }
4588ebe9383cSRichard Henderson 
458938193127SRichard Henderson /* Emulate PDC BTLB, called by SeaBIOS-hppa */
459038193127SRichard Henderson static bool trans_diag_btlb(DisasContext *ctx, arg_diag_btlb *a)
459115da177bSSven Schnelle {
4592cf6b28d4SHelge Deller     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
4593cf6b28d4SHelge Deller #ifndef CONFIG_USER_ONLY
4594ad75a51eSRichard Henderson     nullify_over(ctx);
4595ad75a51eSRichard Henderson     gen_helper_diag_btlb(tcg_env);
4596cf6b28d4SHelge Deller     return nullify_end(ctx);
459738193127SRichard Henderson #endif
459815da177bSSven Schnelle }
459938193127SRichard Henderson 
460038193127SRichard Henderson /* Print char in %r26 to first serial console, used by SeaBIOS-hppa */
460138193127SRichard Henderson static bool trans_diag_cout(DisasContext *ctx, arg_diag_cout *a)
460238193127SRichard Henderson {
460338193127SRichard Henderson     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
460438193127SRichard Henderson #ifndef CONFIG_USER_ONLY
4605dbca0835SHelge Deller     nullify_over(ctx);
4606dbca0835SHelge Deller     gen_helper_diag_console_output(tcg_env);
4607dbca0835SHelge Deller     return nullify_end(ctx);
4608ad75a51eSRichard Henderson #endif
460938193127SRichard Henderson }
461038193127SRichard Henderson 
4611*3bdf2081SHelge Deller static bool trans_diag_getshadowregs_pa1(DisasContext *ctx, arg_empty *a)
4612*3bdf2081SHelge Deller {
4613*3bdf2081SHelge Deller     return !ctx->is_pa20 && do_getshadowregs(ctx);
4614*3bdf2081SHelge Deller }
4615*3bdf2081SHelge Deller 
4616*3bdf2081SHelge Deller static bool trans_diag_getshadowregs_pa2(DisasContext *ctx, arg_empty *a)
4617*3bdf2081SHelge Deller {
4618*3bdf2081SHelge Deller     return ctx->is_pa20 && do_getshadowregs(ctx);
4619*3bdf2081SHelge Deller }
4620*3bdf2081SHelge Deller 
4621*3bdf2081SHelge Deller static bool trans_diag_putshadowregs_pa1(DisasContext *ctx, arg_empty *a)
4622*3bdf2081SHelge Deller {
4623*3bdf2081SHelge Deller     return !ctx->is_pa20 && do_putshadowregs(ctx);
4624*3bdf2081SHelge Deller }
4625*3bdf2081SHelge Deller 
4626*3bdf2081SHelge Deller static bool trans_diag_putshadowregs_pa2(DisasContext *ctx, arg_empty *a)
4627*3bdf2081SHelge Deller {
4628*3bdf2081SHelge Deller     return ctx->is_pa20 && do_putshadowregs(ctx);
4629*3bdf2081SHelge Deller }
4630*3bdf2081SHelge Deller 
463138193127SRichard Henderson static bool trans_diag_unimp(DisasContext *ctx, arg_diag_unimp *a)
463238193127SRichard Henderson {
463338193127SRichard Henderson     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
4634ad75a51eSRichard Henderson     qemu_log_mask(LOG_UNIMP, "DIAG opcode 0x%04x ignored\n", a->i);
4635ad75a51eSRichard Henderson     return true;
4636ad75a51eSRichard Henderson }
463715da177bSSven Schnelle 
4638b542683dSEmilio G. Cota static void hppa_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
463961766fe9SRichard Henderson {
464051b061fbSRichard Henderson     DisasContext *ctx = container_of(dcbase, DisasContext, base);
4641f764718dSRichard Henderson     int bound;
464261766fe9SRichard Henderson 
464351b061fbSRichard Henderson     ctx->cs = cs;
4644494737b7SRichard Henderson     ctx->tb_flags = ctx->base.tb->flags;
4645bd6243a3SRichard Henderson     ctx->is_pa20 = hppa_is_pa20(cpu_env(cs));
46463d68ee7bSRichard Henderson 
46473d68ee7bSRichard Henderson #ifdef CONFIG_USER_ONLY
4648c01e5dfbSHelge Deller     ctx->privilege = MMU_IDX_TO_PRIV(MMU_USER_IDX);
46493d68ee7bSRichard Henderson     ctx->mmu_idx = MMU_USER_IDX;
4650c01e5dfbSHelge Deller     ctx->iaoq_f = ctx->base.pc_first | ctx->privilege;
4651c01e5dfbSHelge Deller     ctx->iaoq_b = ctx->base.tb->cs_base | ctx->privilege;
4652217d1a5eSRichard Henderson     ctx->unalign = (ctx->tb_flags & TB_FLAG_UNALIGN ? MO_UNALN : MO_ALIGN);
4653c301f34eSRichard Henderson #else
4654494737b7SRichard Henderson     ctx->privilege = (ctx->tb_flags >> TB_FLAG_PRIV_SHIFT) & 3;
4655bb67ec32SRichard Henderson     ctx->mmu_idx = (ctx->tb_flags & PSW_D
4656bb67ec32SRichard Henderson                     ? PRIV_P_TO_MMU_IDX(ctx->privilege, ctx->tb_flags & PSW_P)
4657451d993dSRichard Henderson                     : ctx->tb_flags & PSW_W ? MMU_ABS_W_IDX : MMU_ABS_IDX);
46583d68ee7bSRichard Henderson 
4659c301f34eSRichard Henderson     /* Recover the IAOQ values from the GVA + PRIV.  */
4660c301f34eSRichard Henderson     uint64_t cs_base = ctx->base.tb->cs_base;
4661c301f34eSRichard Henderson     uint64_t iasq_f = cs_base & ~0xffffffffull;
4662c301f34eSRichard Henderson     int32_t diff = cs_base;
4663c301f34eSRichard Henderson 
4664c301f34eSRichard Henderson     ctx->iaoq_f = (ctx->base.pc_first & ~iasq_f) + ctx->privilege;
4665c301f34eSRichard Henderson     ctx->iaoq_b = (diff ? ctx->iaoq_f + diff : -1);
4666c301f34eSRichard Henderson #endif
466751b061fbSRichard Henderson     ctx->iaoq_n = -1;
4668f764718dSRichard Henderson     ctx->iaoq_n_var = NULL;
466961766fe9SRichard Henderson 
4670a4db4a78SRichard Henderson     ctx->zero = tcg_constant_i64(0);
4671a4db4a78SRichard Henderson 
46723d68ee7bSRichard Henderson     /* Bound the number of instructions by those left on the page.  */
46733d68ee7bSRichard Henderson     bound = -(ctx->base.pc_first | TARGET_PAGE_MASK) / 4;
4674b542683dSEmilio G. Cota     ctx->base.max_insns = MIN(ctx->base.max_insns, bound);
467561766fe9SRichard Henderson }
467661766fe9SRichard Henderson 
467751b061fbSRichard Henderson static void hppa_tr_tb_start(DisasContextBase *dcbase, CPUState *cs)
467851b061fbSRichard Henderson {
467951b061fbSRichard Henderson     DisasContext *ctx = container_of(dcbase, DisasContext, base);
468061766fe9SRichard Henderson 
46813d68ee7bSRichard Henderson     /* Seed the nullification status from PSW[N], as saved in TB->FLAGS.  */
468251b061fbSRichard Henderson     ctx->null_cond = cond_make_f();
468351b061fbSRichard Henderson     ctx->psw_n_nonzero = false;
4684494737b7SRichard Henderson     if (ctx->tb_flags & PSW_N) {
468551b061fbSRichard Henderson         ctx->null_cond.c = TCG_COND_ALWAYS;
468651b061fbSRichard Henderson         ctx->psw_n_nonzero = true;
4687129e9cc3SRichard Henderson     }
468851b061fbSRichard Henderson     ctx->null_lab = NULL;
468961766fe9SRichard Henderson }
469061766fe9SRichard Henderson 
469151b061fbSRichard Henderson static void hppa_tr_insn_start(DisasContextBase *dcbase, CPUState *cs)
469251b061fbSRichard Henderson {
469351b061fbSRichard Henderson     DisasContext *ctx = container_of(dcbase, DisasContext, base);
469451b061fbSRichard Henderson 
4695f5b5c857SRichard Henderson     tcg_gen_insn_start(ctx->iaoq_f, ctx->iaoq_b, 0);
4696f5b5c857SRichard Henderson     ctx->insn_start = tcg_last_op();
469751b061fbSRichard Henderson }
469851b061fbSRichard Henderson 
469951b061fbSRichard Henderson static void hppa_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs)
470051b061fbSRichard Henderson {
470151b061fbSRichard Henderson     DisasContext *ctx = container_of(dcbase, DisasContext, base);
4702b77af26eSRichard Henderson     CPUHPPAState *env = cpu_env(cs);
470351b061fbSRichard Henderson     DisasJumpType ret;
470451b061fbSRichard Henderson 
470551b061fbSRichard Henderson     /* Execute one insn.  */
4706ba1d0b44SRichard Henderson #ifdef CONFIG_USER_ONLY
4707c301f34eSRichard Henderson     if (ctx->base.pc_next < TARGET_PAGE_SIZE) {
470831234768SRichard Henderson         do_page_zero(ctx);
470931234768SRichard Henderson         ret = ctx->base.is_jmp;
4710869051eaSRichard Henderson         assert(ret != DISAS_NEXT);
4711ba1d0b44SRichard Henderson     } else
4712ba1d0b44SRichard Henderson #endif
4713ba1d0b44SRichard Henderson     {
471461766fe9SRichard Henderson         /* Always fetch the insn, even if nullified, so that we check
471561766fe9SRichard Henderson            the page permissions for execute.  */
47164e116893SIlya Leoshkevich         uint32_t insn = translator_ldl(env, &ctx->base, ctx->base.pc_next);
471761766fe9SRichard Henderson 
471861766fe9SRichard Henderson         /* Set up the IA queue for the next insn.
471961766fe9SRichard Henderson            This will be overwritten by a branch.  */
472051b061fbSRichard Henderson         if (ctx->iaoq_b == -1) {
472151b061fbSRichard Henderson             ctx->iaoq_n = -1;
4722aac0f603SRichard Henderson             ctx->iaoq_n_var = tcg_temp_new_i64();
47236fd0c7bcSRichard Henderson             tcg_gen_addi_i64(ctx->iaoq_n_var, cpu_iaoq_b, 4);
472461766fe9SRichard Henderson         } else {
472551b061fbSRichard Henderson             ctx->iaoq_n = ctx->iaoq_b + 4;
4726f764718dSRichard Henderson             ctx->iaoq_n_var = NULL;
472761766fe9SRichard Henderson         }
472861766fe9SRichard Henderson 
472951b061fbSRichard Henderson         if (unlikely(ctx->null_cond.c == TCG_COND_ALWAYS)) {
473051b061fbSRichard Henderson             ctx->null_cond.c = TCG_COND_NEVER;
4731869051eaSRichard Henderson             ret = DISAS_NEXT;
4732129e9cc3SRichard Henderson         } else {
47331a19da0dSRichard Henderson             ctx->insn = insn;
473431274b46SRichard Henderson             if (!decode(ctx, insn)) {
473531274b46SRichard Henderson                 gen_illegal(ctx);
473631274b46SRichard Henderson             }
473731234768SRichard Henderson             ret = ctx->base.is_jmp;
473851b061fbSRichard Henderson             assert(ctx->null_lab == NULL);
4739129e9cc3SRichard Henderson         }
474061766fe9SRichard Henderson     }
474161766fe9SRichard Henderson 
47423d68ee7bSRichard Henderson     /* Advance the insn queue.  Note that this check also detects
47433d68ee7bSRichard Henderson        a priority change within the instruction queue.  */
474451b061fbSRichard Henderson     if (ret == DISAS_NEXT && ctx->iaoq_b != ctx->iaoq_f + 4) {
4745c301f34eSRichard Henderson         if (ctx->iaoq_b != -1 && ctx->iaoq_n != -1
4746c301f34eSRichard Henderson             && use_goto_tb(ctx, ctx->iaoq_b)
4747c301f34eSRichard Henderson             && (ctx->null_cond.c == TCG_COND_NEVER
4748c301f34eSRichard Henderson                 || ctx->null_cond.c == TCG_COND_ALWAYS)) {
474951b061fbSRichard Henderson             nullify_set(ctx, ctx->null_cond.c == TCG_COND_ALWAYS);
475051b061fbSRichard Henderson             gen_goto_tb(ctx, 0, ctx->iaoq_b, ctx->iaoq_n);
475131234768SRichard Henderson             ctx->base.is_jmp = ret = DISAS_NORETURN;
4752129e9cc3SRichard Henderson         } else {
475331234768SRichard Henderson             ctx->base.is_jmp = ret = DISAS_IAQ_N_STALE;
475461766fe9SRichard Henderson         }
4755129e9cc3SRichard Henderson     }
475651b061fbSRichard Henderson     ctx->iaoq_f = ctx->iaoq_b;
475751b061fbSRichard Henderson     ctx->iaoq_b = ctx->iaoq_n;
4758c301f34eSRichard Henderson     ctx->base.pc_next += 4;
475961766fe9SRichard Henderson 
4760c5d0aec2SRichard Henderson     switch (ret) {
4761c5d0aec2SRichard Henderson     case DISAS_NORETURN:
4762c5d0aec2SRichard Henderson     case DISAS_IAQ_N_UPDATED:
4763c5d0aec2SRichard Henderson         break;
4764c5d0aec2SRichard Henderson 
4765c5d0aec2SRichard Henderson     case DISAS_NEXT:
4766c5d0aec2SRichard Henderson     case DISAS_IAQ_N_STALE:
4767c5d0aec2SRichard Henderson     case DISAS_IAQ_N_STALE_EXIT:
476851b061fbSRichard Henderson         if (ctx->iaoq_f == -1) {
4769a0180973SRichard Henderson             copy_iaoq_entry(ctx, cpu_iaoq_f, -1, cpu_iaoq_b);
4770741322f4SRichard Henderson             copy_iaoq_entry(ctx, cpu_iaoq_b, ctx->iaoq_n, ctx->iaoq_n_var);
4771c301f34eSRichard Henderson #ifndef CONFIG_USER_ONLY
4772c301f34eSRichard Henderson             tcg_gen_mov_i64(cpu_iasq_f, cpu_iasq_b);
4773c301f34eSRichard Henderson #endif
477451b061fbSRichard Henderson             nullify_save(ctx);
4775c5d0aec2SRichard Henderson             ctx->base.is_jmp = (ret == DISAS_IAQ_N_STALE_EXIT
4776c5d0aec2SRichard Henderson                                 ? DISAS_EXIT
4777c5d0aec2SRichard Henderson                                 : DISAS_IAQ_N_UPDATED);
477851b061fbSRichard Henderson         } else if (ctx->iaoq_b == -1) {
4779a0180973SRichard Henderson             copy_iaoq_entry(ctx, cpu_iaoq_b, -1, ctx->iaoq_n_var);
478061766fe9SRichard Henderson         }
4781c5d0aec2SRichard Henderson         break;
4782c5d0aec2SRichard Henderson 
4783c5d0aec2SRichard Henderson     default:
4784c5d0aec2SRichard Henderson         g_assert_not_reached();
4785c5d0aec2SRichard Henderson     }
478661766fe9SRichard Henderson }
478761766fe9SRichard Henderson 
478851b061fbSRichard Henderson static void hppa_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)
478951b061fbSRichard Henderson {
479051b061fbSRichard Henderson     DisasContext *ctx = container_of(dcbase, DisasContext, base);
4791e1b5a5edSRichard Henderson     DisasJumpType is_jmp = ctx->base.is_jmp;
479251b061fbSRichard Henderson 
4793e1b5a5edSRichard Henderson     switch (is_jmp) {
4794869051eaSRichard Henderson     case DISAS_NORETURN:
479561766fe9SRichard Henderson         break;
479651b061fbSRichard Henderson     case DISAS_TOO_MANY:
4797869051eaSRichard Henderson     case DISAS_IAQ_N_STALE:
4798e1b5a5edSRichard Henderson     case DISAS_IAQ_N_STALE_EXIT:
4799741322f4SRichard Henderson         copy_iaoq_entry(ctx, cpu_iaoq_f, ctx->iaoq_f, cpu_iaoq_f);
4800741322f4SRichard Henderson         copy_iaoq_entry(ctx, cpu_iaoq_b, ctx->iaoq_b, cpu_iaoq_b);
480151b061fbSRichard Henderson         nullify_save(ctx);
480261766fe9SRichard Henderson         /* FALLTHRU */
4803869051eaSRichard Henderson     case DISAS_IAQ_N_UPDATED:
48048532a14eSRichard Henderson         if (is_jmp != DISAS_IAQ_N_STALE_EXIT) {
48057f11636dSEmilio G. Cota             tcg_gen_lookup_and_goto_ptr();
48068532a14eSRichard Henderson             break;
480761766fe9SRichard Henderson         }
4808c5d0aec2SRichard Henderson         /* FALLTHRU */
4809c5d0aec2SRichard Henderson     case DISAS_EXIT:
4810c5d0aec2SRichard Henderson         tcg_gen_exit_tb(NULL, 0);
481161766fe9SRichard Henderson         break;
481261766fe9SRichard Henderson     default:
481351b061fbSRichard Henderson         g_assert_not_reached();
481461766fe9SRichard Henderson     }
481551b061fbSRichard Henderson }
481661766fe9SRichard Henderson 
48178eb806a7SRichard Henderson static void hppa_tr_disas_log(const DisasContextBase *dcbase,
48188eb806a7SRichard Henderson                               CPUState *cs, FILE *logfile)
481951b061fbSRichard Henderson {
4820c301f34eSRichard Henderson     target_ulong pc = dcbase->pc_first;
482161766fe9SRichard Henderson 
4822ba1d0b44SRichard Henderson #ifdef CONFIG_USER_ONLY
4823ba1d0b44SRichard Henderson     switch (pc) {
48247ad439dfSRichard Henderson     case 0x00:
48258eb806a7SRichard Henderson         fprintf(logfile, "IN:\n0x00000000:  (null)\n");
4826ba1d0b44SRichard Henderson         return;
48277ad439dfSRichard Henderson     case 0xb0:
48288eb806a7SRichard Henderson         fprintf(logfile, "IN:\n0x000000b0:  light-weight-syscall\n");
4829ba1d0b44SRichard Henderson         return;
48307ad439dfSRichard Henderson     case 0xe0:
48318eb806a7SRichard Henderson         fprintf(logfile, "IN:\n0x000000e0:  set-thread-pointer-syscall\n");
4832ba1d0b44SRichard Henderson         return;
48337ad439dfSRichard Henderson     case 0x100:
48348eb806a7SRichard Henderson         fprintf(logfile, "IN:\n0x00000100:  syscall\n");
4835ba1d0b44SRichard Henderson         return;
48367ad439dfSRichard Henderson     }
4837ba1d0b44SRichard Henderson #endif
4838ba1d0b44SRichard Henderson 
48398eb806a7SRichard Henderson     fprintf(logfile, "IN: %s\n", lookup_symbol(pc));
48408eb806a7SRichard Henderson     target_disas(logfile, cs, pc, dcbase->tb->size);
484161766fe9SRichard Henderson }
484251b061fbSRichard Henderson 
484351b061fbSRichard Henderson static const TranslatorOps hppa_tr_ops = {
484451b061fbSRichard Henderson     .init_disas_context = hppa_tr_init_disas_context,
484551b061fbSRichard Henderson     .tb_start           = hppa_tr_tb_start,
484651b061fbSRichard Henderson     .insn_start         = hppa_tr_insn_start,
484751b061fbSRichard Henderson     .translate_insn     = hppa_tr_translate_insn,
484851b061fbSRichard Henderson     .tb_stop            = hppa_tr_tb_stop,
484951b061fbSRichard Henderson     .disas_log          = hppa_tr_disas_log,
485051b061fbSRichard Henderson };
485151b061fbSRichard Henderson 
4852597f9b2dSRichard Henderson void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int *max_insns,
485332f0c394SAnton Johansson                            vaddr pc, void *host_pc)
485451b061fbSRichard Henderson {
485551b061fbSRichard Henderson     DisasContext ctx;
4856306c8721SRichard Henderson     translator_loop(cs, tb, max_insns, pc, host_pc, &hppa_tr_ops, &ctx.base);
485761766fe9SRichard Henderson }
4858