xref: /openbmc/qemu/target/hppa/translate.c (revision 922582ace2df59572a671f5c0c5c6c5c706995e5)
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 "qemu/host-utils.h"
2361766fe9SRichard Henderson #include "exec/exec-all.h"
2474781c08SPhilippe Mathieu-Daudé #include "exec/page-protection.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 
44bc921866SRichard Henderson typedef struct DisasIAQE {
45bc921866SRichard Henderson     /* IASQ; may be null for no change from TB. */
46bc921866SRichard Henderson     TCGv_i64 space;
470d89cb7cSRichard Henderson     /* IAOQ base; may be null for relative address. */
48bc921866SRichard Henderson     TCGv_i64 base;
49*6dd9b145SRichard Henderson     /* IAOQ addend; if base is null, relative to cpu_iaoq_f. */
50bc921866SRichard Henderson     int64_t disp;
51bc921866SRichard Henderson } DisasIAQE;
52bc921866SRichard Henderson 
5380603007SRichard Henderson typedef struct DisasDelayException {
5480603007SRichard Henderson     struct DisasDelayException *next;
5580603007SRichard Henderson     TCGLabel *lab;
5680603007SRichard Henderson     uint32_t insn;
5780603007SRichard Henderson     bool set_iir;
5880603007SRichard Henderson     int8_t set_n;
5980603007SRichard Henderson     uint8_t excp;
6080603007SRichard Henderson     /* Saved state at parent insn. */
6180603007SRichard Henderson     DisasIAQE iaq_f, iaq_b;
6280603007SRichard Henderson } DisasDelayException;
6380603007SRichard Henderson 
6461766fe9SRichard Henderson typedef struct DisasContext {
65d01a3625SRichard Henderson     DisasContextBase base;
6661766fe9SRichard Henderson     CPUState *cs;
6761766fe9SRichard Henderson 
68bc921866SRichard Henderson     /* IAQ_Front, IAQ_Back. */
69bc921866SRichard Henderson     DisasIAQE iaq_f, iaq_b;
70bc921866SRichard Henderson     /* IAQ_Next, for jumps, otherwise null for simple advance. */
71bc921866SRichard Henderson     DisasIAQE iaq_j, *iaq_n;
7261766fe9SRichard Henderson 
730d89cb7cSRichard Henderson     /* IAOQ_Front at entry to TB. */
740d89cb7cSRichard Henderson     uint64_t iaoq_first;
7561766fe9SRichard Henderson 
7661766fe9SRichard Henderson     DisasCond null_cond;
7761766fe9SRichard Henderson     TCGLabel *null_lab;
7861766fe9SRichard Henderson 
7980603007SRichard Henderson     DisasDelayException *delay_excp_list;
80a4db4a78SRichard Henderson     TCGv_i64 zero;
81a4db4a78SRichard Henderson 
821a19da0dSRichard Henderson     uint32_t insn;
83494737b7SRichard Henderson     uint32_t tb_flags;
843d68ee7bSRichard Henderson     int mmu_idx;
853d68ee7bSRichard Henderson     int privilege;
86d27fe7c3SRichard Henderson     uint32_t psw_xb;
8761766fe9SRichard Henderson     bool psw_n_nonzero;
88d27fe7c3SRichard Henderson     bool psw_b_next;
89bd6243a3SRichard Henderson     bool is_pa20;
9024638bd1SRichard Henderson     bool insn_start_updated;
91217d1a5eSRichard Henderson 
92217d1a5eSRichard Henderson #ifdef CONFIG_USER_ONLY
93217d1a5eSRichard Henderson     MemOp unalign;
94217d1a5eSRichard Henderson #endif
9561766fe9SRichard Henderson } DisasContext;
9661766fe9SRichard Henderson 
97217d1a5eSRichard Henderson #ifdef CONFIG_USER_ONLY
98217d1a5eSRichard Henderson #define UNALIGN(C)       (C)->unalign
9917fe594cSRichard Henderson #define MMU_DISABLED(C)  false
100217d1a5eSRichard Henderson #else
1012d4afb03SRichard Henderson #define UNALIGN(C)       MO_ALIGN
10217fe594cSRichard Henderson #define MMU_DISABLED(C)  MMU_IDX_MMU_DISABLED((C)->mmu_idx)
103217d1a5eSRichard Henderson #endif
104217d1a5eSRichard Henderson 
105e36f27efSRichard Henderson /* Note that ssm/rsm instructions number PSW_W and PSW_E differently.  */
expand_sm_imm(DisasContext * ctx,int val)106451e4ffdSRichard Henderson static int expand_sm_imm(DisasContext *ctx, int val)
107e36f27efSRichard Henderson {
108881d1073SHelge Deller     /* Keep unimplemented bits disabled -- see cpu_hppa_put_psw. */
109881d1073SHelge Deller     if (ctx->is_pa20) {
110e36f27efSRichard Henderson         if (val & PSW_SM_W) {
111881d1073SHelge Deller             val |= PSW_W;
112881d1073SHelge Deller         }
113881d1073SHelge Deller         val &= ~(PSW_SM_W | PSW_SM_E | PSW_G);
114881d1073SHelge Deller     } else {
115881d1073SHelge Deller         val &= ~(PSW_SM_W | PSW_SM_E | PSW_O);
116e36f27efSRichard Henderson     }
117e36f27efSRichard Henderson     return val;
118e36f27efSRichard Henderson }
119e36f27efSRichard Henderson 
120deee69a1SRichard Henderson /* Inverted space register indicates 0 means sr0 not inferred from base.  */
expand_sr3x(DisasContext * ctx,int val)121451e4ffdSRichard Henderson static int expand_sr3x(DisasContext *ctx, int val)
122deee69a1SRichard Henderson {
123deee69a1SRichard Henderson     return ~val;
124deee69a1SRichard Henderson }
125deee69a1SRichard Henderson 
1261cd012a5SRichard Henderson /* Convert the M:A bits within a memory insn to the tri-state value
1271cd012a5SRichard Henderson    we use for the final M.  */
ma_to_m(DisasContext * ctx,int val)128451e4ffdSRichard Henderson static int ma_to_m(DisasContext *ctx, int val)
1291cd012a5SRichard Henderson {
1301cd012a5SRichard Henderson     return val & 2 ? (val & 1 ? -1 : 1) : 0;
1311cd012a5SRichard Henderson }
1321cd012a5SRichard Henderson 
133740038d7SRichard Henderson /* Convert the sign of the displacement to a pre or post-modify.  */
pos_to_m(DisasContext * ctx,int val)134451e4ffdSRichard Henderson static int pos_to_m(DisasContext *ctx, int val)
135740038d7SRichard Henderson {
136740038d7SRichard Henderson     return val ? 1 : -1;
137740038d7SRichard Henderson }
138740038d7SRichard Henderson 
neg_to_m(DisasContext * ctx,int val)139451e4ffdSRichard Henderson static int neg_to_m(DisasContext *ctx, int val)
140740038d7SRichard Henderson {
141740038d7SRichard Henderson     return val ? -1 : 1;
142740038d7SRichard Henderson }
143740038d7SRichard Henderson 
144740038d7SRichard Henderson /* Used for branch targets and fp memory ops.  */
expand_shl2(DisasContext * ctx,int val)145451e4ffdSRichard Henderson static int expand_shl2(DisasContext *ctx, int val)
14601afb7beSRichard Henderson {
14701afb7beSRichard Henderson     return val << 2;
14801afb7beSRichard Henderson }
14901afb7beSRichard Henderson 
1500588e061SRichard Henderson /* Used for assemble_21.  */
expand_shl11(DisasContext * ctx,int val)151451e4ffdSRichard Henderson static int expand_shl11(DisasContext *ctx, int val)
1520588e061SRichard Henderson {
1530588e061SRichard Henderson     return val << 11;
1540588e061SRichard Henderson }
1550588e061SRichard Henderson 
assemble_6(DisasContext * ctx,int val)15672ae4f2bSRichard Henderson static int assemble_6(DisasContext *ctx, int val)
15772ae4f2bSRichard Henderson {
15872ae4f2bSRichard Henderson     /*
15972ae4f2bSRichard Henderson      * Officially, 32 * x + 32 - y.
16072ae4f2bSRichard Henderson      * Here, x is already in bit 5, and y is [4:0].
16172ae4f2bSRichard Henderson      * Since -y = ~y + 1, in 5 bits 32 - y => y ^ 31 + 1,
16272ae4f2bSRichard Henderson      * with the overflow from bit 4 summing with x.
16372ae4f2bSRichard Henderson      */
16472ae4f2bSRichard Henderson     return (val ^ 31) + 1;
16572ae4f2bSRichard Henderson }
16672ae4f2bSRichard Henderson 
1674768c28eSRichard Henderson /* Expander for assemble_16a(s,cat(im10a,0),i). */
expand_11a(DisasContext * ctx,int val)1684768c28eSRichard Henderson static int expand_11a(DisasContext *ctx, int val)
1694768c28eSRichard Henderson {
1704768c28eSRichard Henderson     /*
1714768c28eSRichard Henderson      * @val is bit 0 and bits [4:15].
1724768c28eSRichard Henderson      * Swizzle thing around depending on PSW.W.
1734768c28eSRichard Henderson      */
1744768c28eSRichard Henderson     int im10a = extract32(val, 1, 10);
1754768c28eSRichard Henderson     int s = extract32(val, 11, 2);
1764768c28eSRichard Henderson     int i = (-(val & 1) << 13) | (im10a << 3);
1774768c28eSRichard Henderson 
1784768c28eSRichard Henderson     if (ctx->tb_flags & PSW_W) {
1794768c28eSRichard Henderson         i ^= s << 13;
1804768c28eSRichard Henderson     }
1814768c28eSRichard Henderson     return i;
1824768c28eSRichard Henderson }
1834768c28eSRichard Henderson 
18446174e14SRichard Henderson /* Expander for assemble_16a(s,im11a,i). */
expand_12a(DisasContext * ctx,int val)18546174e14SRichard Henderson static int expand_12a(DisasContext *ctx, int val)
18646174e14SRichard Henderson {
18746174e14SRichard Henderson     /*
18846174e14SRichard Henderson      * @val is bit 0 and bits [3:15].
18946174e14SRichard Henderson      * Swizzle thing around depending on PSW.W.
19046174e14SRichard Henderson      */
19146174e14SRichard Henderson     int im11a = extract32(val, 1, 11);
19246174e14SRichard Henderson     int s = extract32(val, 12, 2);
19346174e14SRichard Henderson     int i = (-(val & 1) << 13) | (im11a << 2);
19446174e14SRichard Henderson 
19546174e14SRichard Henderson     if (ctx->tb_flags & PSW_W) {
19646174e14SRichard Henderson         i ^= s << 13;
19746174e14SRichard Henderson     }
19846174e14SRichard Henderson     return i;
19946174e14SRichard Henderson }
20046174e14SRichard Henderson 
20172bace2dSRichard Henderson /* Expander for assemble_16(s,im14). */
expand_16(DisasContext * ctx,int val)20272bace2dSRichard Henderson static int expand_16(DisasContext *ctx, int val)
20372bace2dSRichard Henderson {
20472bace2dSRichard Henderson     /*
20572bace2dSRichard Henderson      * @val is bits [0:15], containing both im14 and s.
20672bace2dSRichard Henderson      * Swizzle thing around depending on PSW.W.
20772bace2dSRichard Henderson      */
20872bace2dSRichard Henderson     int s = extract32(val, 14, 2);
20972bace2dSRichard Henderson     int i = (-(val & 1) << 13) | extract32(val, 1, 13);
21072bace2dSRichard Henderson 
21172bace2dSRichard Henderson     if (ctx->tb_flags & PSW_W) {
21272bace2dSRichard Henderson         i ^= s << 13;
21372bace2dSRichard Henderson     }
21472bace2dSRichard Henderson     return i;
21572bace2dSRichard Henderson }
21672bace2dSRichard Henderson 
21772bace2dSRichard Henderson /* The sp field is only present with !PSW_W. */
sp0_if_wide(DisasContext * ctx,int sp)21872bace2dSRichard Henderson static int sp0_if_wide(DisasContext *ctx, int sp)
21972bace2dSRichard Henderson {
22072bace2dSRichard Henderson     return ctx->tb_flags & PSW_W ? 0 : sp;
22172bace2dSRichard Henderson }
22272bace2dSRichard Henderson 
223c65c3ee1SRichard Henderson /* Translate CMPI doubleword conditions to standard. */
cmpbid_c(DisasContext * ctx,int val)224c65c3ee1SRichard Henderson static int cmpbid_c(DisasContext *ctx, int val)
225c65c3ee1SRichard Henderson {
226c65c3ee1SRichard Henderson     return val ? val : 4; /* 0 == "*<<" */
227c65c3ee1SRichard Henderson }
228c65c3ee1SRichard Henderson 
22982d0c831SRichard Henderson /*
23082d0c831SRichard Henderson  * In many places pa1.x did not decode the bit that later became
23182d0c831SRichard Henderson  * the pa2.0 D bit.  Suppress D unless the cpu is pa2.0.
23282d0c831SRichard Henderson  */
pa20_d(DisasContext * ctx,int val)23382d0c831SRichard Henderson static int pa20_d(DisasContext *ctx, int val)
23482d0c831SRichard Henderson {
23582d0c831SRichard Henderson     return ctx->is_pa20 & val;
23682d0c831SRichard Henderson }
23701afb7beSRichard Henderson 
23840f9f908SRichard Henderson /* Include the auto-generated decoder.  */
239abff1abfSPaolo Bonzini #include "decode-insns.c.inc"
24040f9f908SRichard Henderson 
24161766fe9SRichard Henderson /* We are not using a goto_tb (for whatever reason), but have updated
24261766fe9SRichard Henderson    the iaq (for whatever reason), so don't do it again on exit.  */
243869051eaSRichard Henderson #define DISAS_IAQ_N_UPDATED  DISAS_TARGET_0
24461766fe9SRichard Henderson 
24561766fe9SRichard Henderson /* We are exiting the TB, but have neither emitted a goto_tb, nor
24661766fe9SRichard Henderson    updated the iaq for the next instruction to be executed.  */
247869051eaSRichard Henderson #define DISAS_IAQ_N_STALE    DISAS_TARGET_1
24861766fe9SRichard Henderson 
249e1b5a5edSRichard Henderson /* Similarly, but we want to return to the main loop immediately
250e1b5a5edSRichard Henderson    to recognize unmasked interrupts.  */
251e1b5a5edSRichard Henderson #define DISAS_IAQ_N_STALE_EXIT      DISAS_TARGET_2
252c5d0aec2SRichard Henderson #define DISAS_EXIT                  DISAS_TARGET_3
253e1b5a5edSRichard Henderson 
25461766fe9SRichard Henderson /* global register indexes */
2556fd0c7bcSRichard Henderson static TCGv_i64 cpu_gr[32];
25633423472SRichard Henderson static TCGv_i64 cpu_sr[4];
257494737b7SRichard Henderson static TCGv_i64 cpu_srH;
2586fd0c7bcSRichard Henderson static TCGv_i64 cpu_iaoq_f;
2596fd0c7bcSRichard Henderson static TCGv_i64 cpu_iaoq_b;
260c301f34eSRichard Henderson static TCGv_i64 cpu_iasq_f;
261c301f34eSRichard Henderson static TCGv_i64 cpu_iasq_b;
2626fd0c7bcSRichard Henderson static TCGv_i64 cpu_sar;
2636fd0c7bcSRichard Henderson static TCGv_i64 cpu_psw_n;
2646fd0c7bcSRichard Henderson static TCGv_i64 cpu_psw_v;
2656fd0c7bcSRichard Henderson static TCGv_i64 cpu_psw_cb;
2666fd0c7bcSRichard Henderson static TCGv_i64 cpu_psw_cb_msb;
267d27fe7c3SRichard Henderson static TCGv_i32 cpu_psw_xb;
26861766fe9SRichard Henderson 
hppa_translate_init(void)26961766fe9SRichard Henderson void hppa_translate_init(void)
27061766fe9SRichard Henderson {
27161766fe9SRichard Henderson #define DEF_VAR(V)  { &cpu_##V, #V, offsetof(CPUHPPAState, V) }
27261766fe9SRichard Henderson 
2736fd0c7bcSRichard Henderson     typedef struct { TCGv_i64 *var; const char *name; int ofs; } GlobalVar;
27461766fe9SRichard Henderson     static const GlobalVar vars[] = {
27535136a77SRichard Henderson         { &cpu_sar, "sar", offsetof(CPUHPPAState, cr[CR_SAR]) },
27661766fe9SRichard Henderson         DEF_VAR(psw_n),
27761766fe9SRichard Henderson         DEF_VAR(psw_v),
27861766fe9SRichard Henderson         DEF_VAR(psw_cb),
27961766fe9SRichard Henderson         DEF_VAR(psw_cb_msb),
28061766fe9SRichard Henderson         DEF_VAR(iaoq_f),
28161766fe9SRichard Henderson         DEF_VAR(iaoq_b),
28261766fe9SRichard Henderson     };
28361766fe9SRichard Henderson 
28461766fe9SRichard Henderson #undef DEF_VAR
28561766fe9SRichard Henderson 
28661766fe9SRichard Henderson     /* Use the symbolic register names that match the disassembler.  */
28761766fe9SRichard Henderson     static const char gr_names[32][4] = {
28861766fe9SRichard Henderson         "r0",  "r1",  "r2",  "r3",  "r4",  "r5",  "r6",  "r7",
28961766fe9SRichard Henderson         "r8",  "r9",  "r10", "r11", "r12", "r13", "r14", "r15",
29061766fe9SRichard Henderson         "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
29161766fe9SRichard Henderson         "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31"
29261766fe9SRichard Henderson     };
29333423472SRichard Henderson     /* SR[4-7] are not global registers so that we can index them.  */
294494737b7SRichard Henderson     static const char sr_names[5][4] = {
295494737b7SRichard Henderson         "sr0", "sr1", "sr2", "sr3", "srH"
29633423472SRichard Henderson     };
29761766fe9SRichard Henderson 
29861766fe9SRichard Henderson     int i;
29961766fe9SRichard Henderson 
300f764718dSRichard Henderson     cpu_gr[0] = NULL;
30161766fe9SRichard Henderson     for (i = 1; i < 32; i++) {
302ad75a51eSRichard Henderson         cpu_gr[i] = tcg_global_mem_new(tcg_env,
30361766fe9SRichard Henderson                                        offsetof(CPUHPPAState, gr[i]),
30461766fe9SRichard Henderson                                        gr_names[i]);
30561766fe9SRichard Henderson     }
30633423472SRichard Henderson     for (i = 0; i < 4; i++) {
307ad75a51eSRichard Henderson         cpu_sr[i] = tcg_global_mem_new_i64(tcg_env,
30833423472SRichard Henderson                                            offsetof(CPUHPPAState, sr[i]),
30933423472SRichard Henderson                                            sr_names[i]);
31033423472SRichard Henderson     }
311ad75a51eSRichard Henderson     cpu_srH = tcg_global_mem_new_i64(tcg_env,
312494737b7SRichard Henderson                                      offsetof(CPUHPPAState, sr[4]),
313494737b7SRichard Henderson                                      sr_names[4]);
31461766fe9SRichard Henderson 
31561766fe9SRichard Henderson     for (i = 0; i < ARRAY_SIZE(vars); ++i) {
31661766fe9SRichard Henderson         const GlobalVar *v = &vars[i];
317ad75a51eSRichard Henderson         *v->var = tcg_global_mem_new(tcg_env, v->ofs, v->name);
31861766fe9SRichard Henderson     }
319c301f34eSRichard Henderson 
320d27fe7c3SRichard Henderson     cpu_psw_xb = tcg_global_mem_new_i32(tcg_env,
321d27fe7c3SRichard Henderson                                         offsetof(CPUHPPAState, psw_xb),
322d27fe7c3SRichard Henderson                                         "psw_xb");
323ad75a51eSRichard Henderson     cpu_iasq_f = tcg_global_mem_new_i64(tcg_env,
324c301f34eSRichard Henderson                                         offsetof(CPUHPPAState, iasq_f),
325c301f34eSRichard Henderson                                         "iasq_f");
326ad75a51eSRichard Henderson     cpu_iasq_b = tcg_global_mem_new_i64(tcg_env,
327c301f34eSRichard Henderson                                         offsetof(CPUHPPAState, iasq_b),
328c301f34eSRichard Henderson                                         "iasq_b");
32961766fe9SRichard Henderson }
33061766fe9SRichard Henderson 
set_insn_breg(DisasContext * ctx,int breg)331f5b5c857SRichard Henderson static void set_insn_breg(DisasContext *ctx, int breg)
332f5b5c857SRichard Henderson {
33324638bd1SRichard Henderson     assert(!ctx->insn_start_updated);
33424638bd1SRichard Henderson     ctx->insn_start_updated = true;
33524638bd1SRichard Henderson     tcg_set_insn_start_param(ctx->base.insn_start, 2, breg);
336f5b5c857SRichard Henderson }
337f5b5c857SRichard Henderson 
cond_make_f(void)338129e9cc3SRichard Henderson static DisasCond cond_make_f(void)
339129e9cc3SRichard Henderson {
340f764718dSRichard Henderson     return (DisasCond){
341f764718dSRichard Henderson         .c = TCG_COND_NEVER,
342f764718dSRichard Henderson         .a0 = NULL,
343f764718dSRichard Henderson         .a1 = NULL,
344f764718dSRichard Henderson     };
345129e9cc3SRichard Henderson }
346129e9cc3SRichard Henderson 
cond_make_t(void)347df0232feSRichard Henderson static DisasCond cond_make_t(void)
348df0232feSRichard Henderson {
349df0232feSRichard Henderson     return (DisasCond){
350df0232feSRichard Henderson         .c = TCG_COND_ALWAYS,
351df0232feSRichard Henderson         .a0 = NULL,
352df0232feSRichard Henderson         .a1 = NULL,
353df0232feSRichard Henderson     };
354df0232feSRichard Henderson }
355df0232feSRichard Henderson 
cond_make_n(void)356129e9cc3SRichard Henderson static DisasCond cond_make_n(void)
357129e9cc3SRichard Henderson {
358f764718dSRichard Henderson     return (DisasCond){
359f764718dSRichard Henderson         .c = TCG_COND_NE,
360f764718dSRichard Henderson         .a0 = cpu_psw_n,
3616fd0c7bcSRichard Henderson         .a1 = tcg_constant_i64(0)
362f764718dSRichard Henderson     };
363129e9cc3SRichard Henderson }
364129e9cc3SRichard Henderson 
cond_make_tt(TCGCond c,TCGv_i64 a0,TCGv_i64 a1)3654c42fd0dSRichard Henderson static DisasCond cond_make_tt(TCGCond c, TCGv_i64 a0, TCGv_i64 a1)
366b47a4a02SSven Schnelle {
367b47a4a02SSven Schnelle     assert (c != TCG_COND_NEVER && c != TCG_COND_ALWAYS);
3684fe9533aSRichard Henderson     return (DisasCond){ .c = c, .a0 = a0, .a1 = a1 };
3694fe9533aSRichard Henderson }
3704fe9533aSRichard Henderson 
cond_make_ti(TCGCond c,TCGv_i64 a0,uint64_t imm)3714c42fd0dSRichard Henderson static DisasCond cond_make_ti(TCGCond c, TCGv_i64 a0, uint64_t imm)
3724fe9533aSRichard Henderson {
3734c42fd0dSRichard Henderson     return cond_make_tt(c, a0, tcg_constant_i64(imm));
374b47a4a02SSven Schnelle }
375b47a4a02SSven Schnelle 
cond_make_vi(TCGCond c,TCGv_i64 a0,uint64_t imm)3764c42fd0dSRichard Henderson static DisasCond cond_make_vi(TCGCond c, TCGv_i64 a0, uint64_t imm)
377129e9cc3SRichard Henderson {
378aac0f603SRichard Henderson     TCGv_i64 tmp = tcg_temp_new_i64();
3796fd0c7bcSRichard Henderson     tcg_gen_mov_i64(tmp, a0);
3804c42fd0dSRichard Henderson     return cond_make_ti(c, tmp, imm);
381129e9cc3SRichard Henderson }
382129e9cc3SRichard Henderson 
cond_make_vv(TCGCond c,TCGv_i64 a0,TCGv_i64 a1)3834c42fd0dSRichard Henderson static DisasCond cond_make_vv(TCGCond c, TCGv_i64 a0, TCGv_i64 a1)
384129e9cc3SRichard Henderson {
385aac0f603SRichard Henderson     TCGv_i64 t0 = tcg_temp_new_i64();
386aac0f603SRichard Henderson     TCGv_i64 t1 = tcg_temp_new_i64();
387129e9cc3SRichard Henderson 
3886fd0c7bcSRichard Henderson     tcg_gen_mov_i64(t0, a0);
3896fd0c7bcSRichard Henderson     tcg_gen_mov_i64(t1, a1);
3904c42fd0dSRichard Henderson     return cond_make_tt(c, t0, t1);
391129e9cc3SRichard Henderson }
392129e9cc3SRichard Henderson 
load_gpr(DisasContext * ctx,unsigned reg)3936fd0c7bcSRichard Henderson static TCGv_i64 load_gpr(DisasContext *ctx, unsigned reg)
39461766fe9SRichard Henderson {
39561766fe9SRichard Henderson     if (reg == 0) {
396bc3da3cfSRichard Henderson         return ctx->zero;
39761766fe9SRichard Henderson     } else {
39861766fe9SRichard Henderson         return cpu_gr[reg];
39961766fe9SRichard Henderson     }
40061766fe9SRichard Henderson }
40161766fe9SRichard Henderson 
dest_gpr(DisasContext * ctx,unsigned reg)4026fd0c7bcSRichard Henderson static TCGv_i64 dest_gpr(DisasContext *ctx, unsigned reg)
40361766fe9SRichard Henderson {
404129e9cc3SRichard Henderson     if (reg == 0 || ctx->null_cond.c != TCG_COND_NEVER) {
405aac0f603SRichard Henderson         return tcg_temp_new_i64();
40661766fe9SRichard Henderson     } else {
40761766fe9SRichard Henderson         return cpu_gr[reg];
40861766fe9SRichard Henderson     }
40961766fe9SRichard Henderson }
41061766fe9SRichard Henderson 
save_or_nullify(DisasContext * ctx,TCGv_i64 dest,TCGv_i64 t)4116fd0c7bcSRichard Henderson static void save_or_nullify(DisasContext *ctx, TCGv_i64 dest, TCGv_i64 t)
412129e9cc3SRichard Henderson {
413129e9cc3SRichard Henderson     if (ctx->null_cond.c != TCG_COND_NEVER) {
4146fd0c7bcSRichard Henderson         tcg_gen_movcond_i64(ctx->null_cond.c, dest, ctx->null_cond.a0,
415129e9cc3SRichard Henderson                             ctx->null_cond.a1, dest, t);
416129e9cc3SRichard Henderson     } else {
4176fd0c7bcSRichard Henderson         tcg_gen_mov_i64(dest, t);
418129e9cc3SRichard Henderson     }
419129e9cc3SRichard Henderson }
420129e9cc3SRichard Henderson 
save_gpr(DisasContext * ctx,unsigned reg,TCGv_i64 t)4216fd0c7bcSRichard Henderson static void save_gpr(DisasContext *ctx, unsigned reg, TCGv_i64 t)
422129e9cc3SRichard Henderson {
423129e9cc3SRichard Henderson     if (reg != 0) {
424129e9cc3SRichard Henderson         save_or_nullify(ctx, cpu_gr[reg], t);
425129e9cc3SRichard Henderson     }
426129e9cc3SRichard Henderson }
427129e9cc3SRichard Henderson 
428e03b5686SMarc-André Lureau #if HOST_BIG_ENDIAN
42996d6407fSRichard Henderson # define HI_OFS  0
43096d6407fSRichard Henderson # define LO_OFS  4
43196d6407fSRichard Henderson #else
43296d6407fSRichard Henderson # define HI_OFS  4
43396d6407fSRichard Henderson # define LO_OFS  0
43496d6407fSRichard Henderson #endif
43596d6407fSRichard Henderson 
load_frw_i32(unsigned rt)43696d6407fSRichard Henderson static TCGv_i32 load_frw_i32(unsigned rt)
43796d6407fSRichard Henderson {
43896d6407fSRichard Henderson     TCGv_i32 ret = tcg_temp_new_i32();
439ad75a51eSRichard Henderson     tcg_gen_ld_i32(ret, tcg_env,
44096d6407fSRichard Henderson                    offsetof(CPUHPPAState, fr[rt & 31])
44196d6407fSRichard Henderson                    + (rt & 32 ? LO_OFS : HI_OFS));
44296d6407fSRichard Henderson     return ret;
44396d6407fSRichard Henderson }
44496d6407fSRichard Henderson 
load_frw0_i32(unsigned rt)445ebe9383cSRichard Henderson static TCGv_i32 load_frw0_i32(unsigned rt)
446ebe9383cSRichard Henderson {
447ebe9383cSRichard Henderson     if (rt == 0) {
4480992a930SRichard Henderson         TCGv_i32 ret = tcg_temp_new_i32();
4490992a930SRichard Henderson         tcg_gen_movi_i32(ret, 0);
4500992a930SRichard Henderson         return ret;
451ebe9383cSRichard Henderson     } else {
452ebe9383cSRichard Henderson         return load_frw_i32(rt);
453ebe9383cSRichard Henderson     }
454ebe9383cSRichard Henderson }
455ebe9383cSRichard Henderson 
load_frw0_i64(unsigned rt)456ebe9383cSRichard Henderson static TCGv_i64 load_frw0_i64(unsigned rt)
457ebe9383cSRichard Henderson {
458ebe9383cSRichard Henderson     TCGv_i64 ret = tcg_temp_new_i64();
4590992a930SRichard Henderson     if (rt == 0) {
4600992a930SRichard Henderson         tcg_gen_movi_i64(ret, 0);
4610992a930SRichard Henderson     } else {
462ad75a51eSRichard Henderson         tcg_gen_ld32u_i64(ret, tcg_env,
463ebe9383cSRichard Henderson                           offsetof(CPUHPPAState, fr[rt & 31])
464ebe9383cSRichard Henderson                           + (rt & 32 ? LO_OFS : HI_OFS));
465ebe9383cSRichard Henderson     }
4660992a930SRichard Henderson     return ret;
467ebe9383cSRichard Henderson }
468ebe9383cSRichard Henderson 
save_frw_i32(unsigned rt,TCGv_i32 val)46996d6407fSRichard Henderson static void save_frw_i32(unsigned rt, TCGv_i32 val)
47096d6407fSRichard Henderson {
471ad75a51eSRichard Henderson     tcg_gen_st_i32(val, tcg_env,
47296d6407fSRichard Henderson                    offsetof(CPUHPPAState, fr[rt & 31])
47396d6407fSRichard Henderson                    + (rt & 32 ? LO_OFS : HI_OFS));
47496d6407fSRichard Henderson }
47596d6407fSRichard Henderson 
47696d6407fSRichard Henderson #undef HI_OFS
47796d6407fSRichard Henderson #undef LO_OFS
47896d6407fSRichard Henderson 
load_frd(unsigned rt)47996d6407fSRichard Henderson static TCGv_i64 load_frd(unsigned rt)
48096d6407fSRichard Henderson {
48196d6407fSRichard Henderson     TCGv_i64 ret = tcg_temp_new_i64();
482ad75a51eSRichard Henderson     tcg_gen_ld_i64(ret, tcg_env, offsetof(CPUHPPAState, fr[rt]));
48396d6407fSRichard Henderson     return ret;
48496d6407fSRichard Henderson }
48596d6407fSRichard Henderson 
load_frd0(unsigned rt)486ebe9383cSRichard Henderson static TCGv_i64 load_frd0(unsigned rt)
487ebe9383cSRichard Henderson {
488ebe9383cSRichard Henderson     if (rt == 0) {
4890992a930SRichard Henderson         TCGv_i64 ret = tcg_temp_new_i64();
4900992a930SRichard Henderson         tcg_gen_movi_i64(ret, 0);
4910992a930SRichard Henderson         return ret;
492ebe9383cSRichard Henderson     } else {
493ebe9383cSRichard Henderson         return load_frd(rt);
494ebe9383cSRichard Henderson     }
495ebe9383cSRichard Henderson }
496ebe9383cSRichard Henderson 
save_frd(unsigned rt,TCGv_i64 val)49796d6407fSRichard Henderson static void save_frd(unsigned rt, TCGv_i64 val)
49896d6407fSRichard Henderson {
499ad75a51eSRichard Henderson     tcg_gen_st_i64(val, tcg_env, offsetof(CPUHPPAState, fr[rt]));
50096d6407fSRichard Henderson }
50196d6407fSRichard Henderson 
load_spr(DisasContext * ctx,TCGv_i64 dest,unsigned reg)50233423472SRichard Henderson static void load_spr(DisasContext *ctx, TCGv_i64 dest, unsigned reg)
50333423472SRichard Henderson {
50433423472SRichard Henderson #ifdef CONFIG_USER_ONLY
50533423472SRichard Henderson     tcg_gen_movi_i64(dest, 0);
50633423472SRichard Henderson #else
50733423472SRichard Henderson     if (reg < 4) {
50833423472SRichard Henderson         tcg_gen_mov_i64(dest, cpu_sr[reg]);
509494737b7SRichard Henderson     } else if (ctx->tb_flags & TB_FLAG_SR_SAME) {
510494737b7SRichard Henderson         tcg_gen_mov_i64(dest, cpu_srH);
51133423472SRichard Henderson     } else {
512ad75a51eSRichard Henderson         tcg_gen_ld_i64(dest, tcg_env, offsetof(CPUHPPAState, sr[reg]));
51333423472SRichard Henderson     }
51433423472SRichard Henderson #endif
51533423472SRichard Henderson }
51633423472SRichard Henderson 
517d27fe7c3SRichard Henderson /*
518d27fe7c3SRichard Henderson  * Write a value to psw_xb, bearing in mind the known value.
519d27fe7c3SRichard Henderson  * To be used just before exiting the TB, so do not update the known value.
520d27fe7c3SRichard Henderson  */
store_psw_xb(DisasContext * ctx,uint32_t xb)521d27fe7c3SRichard Henderson static void store_psw_xb(DisasContext *ctx, uint32_t xb)
522d27fe7c3SRichard Henderson {
523d27fe7c3SRichard Henderson     tcg_debug_assert(xb == 0 || xb == PSW_B);
524d27fe7c3SRichard Henderson     if (ctx->psw_xb != xb) {
525d27fe7c3SRichard Henderson         tcg_gen_movi_i32(cpu_psw_xb, xb);
526d27fe7c3SRichard Henderson     }
527d27fe7c3SRichard Henderson }
528d27fe7c3SRichard Henderson 
529d27fe7c3SRichard Henderson /* Write a value to psw_xb, and update the known value. */
set_psw_xb(DisasContext * ctx,uint32_t xb)530d27fe7c3SRichard Henderson static void set_psw_xb(DisasContext *ctx, uint32_t xb)
531d27fe7c3SRichard Henderson {
532d27fe7c3SRichard Henderson     store_psw_xb(ctx, xb);
533d27fe7c3SRichard Henderson     ctx->psw_xb = xb;
534d27fe7c3SRichard Henderson }
535d27fe7c3SRichard Henderson 
536129e9cc3SRichard Henderson /* Skip over the implementation of an insn that has been nullified.
537129e9cc3SRichard Henderson    Use this when the insn is too complex for a conditional move.  */
nullify_over(DisasContext * ctx)538129e9cc3SRichard Henderson static void nullify_over(DisasContext *ctx)
539129e9cc3SRichard Henderson {
540129e9cc3SRichard Henderson     if (ctx->null_cond.c != TCG_COND_NEVER) {
541129e9cc3SRichard Henderson         /* The always condition should have been handled in the main loop.  */
542129e9cc3SRichard Henderson         assert(ctx->null_cond.c != TCG_COND_ALWAYS);
543129e9cc3SRichard Henderson 
544129e9cc3SRichard Henderson         ctx->null_lab = gen_new_label();
545129e9cc3SRichard Henderson 
546129e9cc3SRichard Henderson         /* If we're using PSW[N], copy it to a temp because... */
5476e94937aSRichard Henderson         if (ctx->null_cond.a0 == cpu_psw_n) {
548aac0f603SRichard Henderson             ctx->null_cond.a0 = tcg_temp_new_i64();
5496fd0c7bcSRichard Henderson             tcg_gen_mov_i64(ctx->null_cond.a0, cpu_psw_n);
550129e9cc3SRichard Henderson         }
551129e9cc3SRichard Henderson         /* ... we clear it before branching over the implementation,
552129e9cc3SRichard Henderson            so that (1) it's clear after nullifying this insn and
553129e9cc3SRichard Henderson            (2) if this insn nullifies the next, PSW[N] is valid.  */
554129e9cc3SRichard Henderson         if (ctx->psw_n_nonzero) {
555129e9cc3SRichard Henderson             ctx->psw_n_nonzero = false;
5566fd0c7bcSRichard Henderson             tcg_gen_movi_i64(cpu_psw_n, 0);
557129e9cc3SRichard Henderson         }
558129e9cc3SRichard Henderson 
5596fd0c7bcSRichard Henderson         tcg_gen_brcond_i64(ctx->null_cond.c, ctx->null_cond.a0,
560129e9cc3SRichard Henderson                            ctx->null_cond.a1, ctx->null_lab);
561e0137378SRichard Henderson         ctx->null_cond = cond_make_f();
562129e9cc3SRichard Henderson     }
563129e9cc3SRichard Henderson }
564129e9cc3SRichard Henderson 
565129e9cc3SRichard Henderson /* Save the current nullification state to PSW[N].  */
nullify_save(DisasContext * ctx)566129e9cc3SRichard Henderson static void nullify_save(DisasContext *ctx)
567129e9cc3SRichard Henderson {
568129e9cc3SRichard Henderson     if (ctx->null_cond.c == TCG_COND_NEVER) {
569129e9cc3SRichard Henderson         if (ctx->psw_n_nonzero) {
5706fd0c7bcSRichard Henderson             tcg_gen_movi_i64(cpu_psw_n, 0);
571129e9cc3SRichard Henderson         }
572129e9cc3SRichard Henderson         return;
573129e9cc3SRichard Henderson     }
5746e94937aSRichard Henderson     if (ctx->null_cond.a0 != cpu_psw_n) {
5756fd0c7bcSRichard Henderson         tcg_gen_setcond_i64(ctx->null_cond.c, cpu_psw_n,
576129e9cc3SRichard Henderson                             ctx->null_cond.a0, ctx->null_cond.a1);
577129e9cc3SRichard Henderson         ctx->psw_n_nonzero = true;
578129e9cc3SRichard Henderson     }
579e0137378SRichard Henderson     ctx->null_cond = cond_make_f();
580129e9cc3SRichard Henderson }
581129e9cc3SRichard Henderson 
582129e9cc3SRichard Henderson /* Set a PSW[N] to X.  The intention is that this is used immediately
583129e9cc3SRichard Henderson    before a goto_tb/exit_tb, so that there is no fallthru path to other
584129e9cc3SRichard Henderson    code within the TB.  Therefore we do not update psw_n_nonzero.  */
nullify_set(DisasContext * ctx,bool x)585129e9cc3SRichard Henderson static void nullify_set(DisasContext *ctx, bool x)
586129e9cc3SRichard Henderson {
587129e9cc3SRichard Henderson     if (ctx->psw_n_nonzero || x) {
5886fd0c7bcSRichard Henderson         tcg_gen_movi_i64(cpu_psw_n, x);
589129e9cc3SRichard Henderson     }
590129e9cc3SRichard Henderson }
591129e9cc3SRichard Henderson 
592129e9cc3SRichard Henderson /* Mark the end of an instruction that may have been nullified.
59340f9f908SRichard Henderson    This is the pair to nullify_over.  Always returns true so that
59440f9f908SRichard Henderson    it may be tail-called from a translate function.  */
nullify_end(DisasContext * ctx)59531234768SRichard Henderson static bool nullify_end(DisasContext *ctx)
596129e9cc3SRichard Henderson {
597129e9cc3SRichard Henderson     TCGLabel *null_lab = ctx->null_lab;
59831234768SRichard Henderson     DisasJumpType status = ctx->base.is_jmp;
599129e9cc3SRichard Henderson 
600f49b3537SRichard Henderson     /* For NEXT, NORETURN, STALE, we can easily continue (or exit).
601f49b3537SRichard Henderson        For UPDATED, we cannot update on the nullified path.  */
602f49b3537SRichard Henderson     assert(status != DISAS_IAQ_N_UPDATED);
603d27fe7c3SRichard Henderson     /* Taken branches are handled manually. */
604d27fe7c3SRichard Henderson     assert(!ctx->psw_b_next);
605f49b3537SRichard Henderson 
606129e9cc3SRichard Henderson     if (likely(null_lab == NULL)) {
607129e9cc3SRichard Henderson         /* The current insn wasn't conditional or handled the condition
608129e9cc3SRichard Henderson            applied to it without a branch, so the (new) setting of
609129e9cc3SRichard Henderson            NULL_COND can be applied directly to the next insn.  */
61031234768SRichard Henderson         return true;
611129e9cc3SRichard Henderson     }
612129e9cc3SRichard Henderson     ctx->null_lab = NULL;
613129e9cc3SRichard Henderson 
614129e9cc3SRichard Henderson     if (likely(ctx->null_cond.c == TCG_COND_NEVER)) {
615129e9cc3SRichard Henderson         /* The next instruction will be unconditional,
616129e9cc3SRichard Henderson            and NULL_COND already reflects that.  */
617129e9cc3SRichard Henderson         gen_set_label(null_lab);
618129e9cc3SRichard Henderson     } else {
619129e9cc3SRichard Henderson         /* The insn that we just executed is itself nullifying the next
620129e9cc3SRichard Henderson            instruction.  Store the condition in the PSW[N] global.
621129e9cc3SRichard Henderson            We asserted PSW[N] = 0 in nullify_over, so that after the
622129e9cc3SRichard Henderson            label we have the proper value in place.  */
623129e9cc3SRichard Henderson         nullify_save(ctx);
624129e9cc3SRichard Henderson         gen_set_label(null_lab);
625129e9cc3SRichard Henderson         ctx->null_cond = cond_make_n();
626129e9cc3SRichard Henderson     }
627869051eaSRichard Henderson     if (status == DISAS_NORETURN) {
62831234768SRichard Henderson         ctx->base.is_jmp = DISAS_NEXT;
629129e9cc3SRichard Henderson     }
63031234768SRichard Henderson     return true;
631129e9cc3SRichard Henderson }
632129e9cc3SRichard Henderson 
iaqe_variable(const DisasIAQE * e)633bc921866SRichard Henderson static bool iaqe_variable(const DisasIAQE *e)
63461766fe9SRichard Henderson {
635bc921866SRichard Henderson     return e->base || e->space;
636f13bf343SRichard Henderson }
637bc921866SRichard Henderson 
iaqe_incr(const DisasIAQE * e,int64_t disp)638bc921866SRichard Henderson static DisasIAQE iaqe_incr(const DisasIAQE *e, int64_t disp)
639bc921866SRichard Henderson {
640bc921866SRichard Henderson     return (DisasIAQE){
641bc921866SRichard Henderson         .space = e->space,
642bc921866SRichard Henderson         .base = e->base,
643bc921866SRichard Henderson         .disp = e->disp + disp,
644bc921866SRichard Henderson     };
645bc921866SRichard Henderson }
646bc921866SRichard Henderson 
iaqe_branchi(DisasContext * ctx,int64_t disp)647bc921866SRichard Henderson static DisasIAQE iaqe_branchi(DisasContext *ctx, int64_t disp)
648bc921866SRichard Henderson {
649bc921866SRichard Henderson     return (DisasIAQE){
650bc921866SRichard Henderson         .space = ctx->iaq_b.space,
651bc921866SRichard Henderson         .disp = ctx->iaq_f.disp + 8 + disp,
652bc921866SRichard Henderson     };
653bc921866SRichard Henderson }
654bc921866SRichard Henderson 
iaqe_next_absv(DisasContext * ctx,TCGv_i64 var)655bc921866SRichard Henderson static DisasIAQE iaqe_next_absv(DisasContext *ctx, TCGv_i64 var)
656bc921866SRichard Henderson {
657bc921866SRichard Henderson     return (DisasIAQE){
658bc921866SRichard Henderson         .space = ctx->iaq_b.space,
659bc921866SRichard Henderson         .base = var,
660bc921866SRichard Henderson     };
661bc921866SRichard Henderson }
662bc921866SRichard Henderson 
copy_iaoq_entry(DisasContext * ctx,TCGv_i64 dest,const DisasIAQE * src)66361766fe9SRichard Henderson static void copy_iaoq_entry(DisasContext *ctx, TCGv_i64 dest,
664bc921866SRichard Henderson                             const DisasIAQE *src)
66561766fe9SRichard Henderson {
666*6dd9b145SRichard Henderson     tcg_gen_addi_i64(dest, src->base ? : cpu_iaoq_f, src->disp);
66761766fe9SRichard Henderson }
66861766fe9SRichard Henderson 
install_iaq_entries(DisasContext * ctx,const DisasIAQE * f,const DisasIAQE * b)669bc921866SRichard Henderson static void install_iaq_entries(DisasContext *ctx, const DisasIAQE *f,
670bc921866SRichard Henderson                                 const DisasIAQE *b)
67185e6cda0SRichard Henderson {
672bc921866SRichard Henderson     DisasIAQE b_next;
67385e6cda0SRichard Henderson 
674bc921866SRichard Henderson     if (b == NULL) {
675bc921866SRichard Henderson         b_next = iaqe_incr(f, 4);
676bc921866SRichard Henderson         b = &b_next;
67785e6cda0SRichard Henderson     }
678eaa3783bSRichard Henderson 
67961766fe9SRichard Henderson     /*
680*6dd9b145SRichard Henderson      * There is an edge case
681*6dd9b145SRichard Henderson      *    bv   r0(rN)
682*6dd9b145SRichard Henderson      *    b,l  disp,r0
683*6dd9b145SRichard Henderson      * for which F will use cpu_iaoq_b (from the indirect branch),
684*6dd9b145SRichard Henderson      * and B will use cpu_iaoq_f (from the direct branch).
685*6dd9b145SRichard Henderson      * In this case we need an extra temporary.
68661766fe9SRichard Henderson      */
687*6dd9b145SRichard Henderson     if (f->base != cpu_iaoq_b) {
688bc921866SRichard Henderson         copy_iaoq_entry(ctx, cpu_iaoq_b, b);
689*6dd9b145SRichard Henderson         copy_iaoq_entry(ctx, cpu_iaoq_f, f);
690*6dd9b145SRichard Henderson     } else if (f->base == b->base) {
691*6dd9b145SRichard Henderson         copy_iaoq_entry(ctx, cpu_iaoq_f, f);
692*6dd9b145SRichard Henderson         tcg_gen_addi_i64(cpu_iaoq_b, cpu_iaoq_f, b->disp - f->disp);
693ad75a51eSRichard Henderson     } else {
694*6dd9b145SRichard Henderson         TCGv_i64 tmp = tcg_temp_new_i64();
695*6dd9b145SRichard Henderson         copy_iaoq_entry(ctx, tmp, b);
696*6dd9b145SRichard Henderson         copy_iaoq_entry(ctx, cpu_iaoq_f, f);
697*6dd9b145SRichard Henderson         tcg_gen_mov_i64(cpu_iaoq_b, tmp);
698*6dd9b145SRichard Henderson     }
699*6dd9b145SRichard Henderson 
700bc921866SRichard Henderson     if (f->space) {
701bc921866SRichard Henderson         tcg_gen_mov_i64(cpu_iasq_f, f->space);
702588deedaSRichard Henderson     }
703bc921866SRichard Henderson     if (b->space || f->space) {
704bc921866SRichard Henderson         tcg_gen_mov_i64(cpu_iasq_b, b->space ? : f->space);
70561766fe9SRichard Henderson     }
70661766fe9SRichard Henderson }
70761766fe9SRichard Henderson 
install_link(DisasContext * ctx,unsigned link,bool with_sr0)70843541db0SRichard Henderson static void install_link(DisasContext *ctx, unsigned link, bool with_sr0)
70961766fe9SRichard Henderson {
71043541db0SRichard Henderson     tcg_debug_assert(ctx->null_cond.c == TCG_COND_NEVER);
71143541db0SRichard Henderson     if (!link) {
71243541db0SRichard Henderson         return;
71343541db0SRichard Henderson     }
7140d89cb7cSRichard Henderson     DisasIAQE next = iaqe_incr(&ctx->iaq_b, 4);
7150d89cb7cSRichard Henderson     copy_iaoq_entry(ctx, cpu_gr[link], &next);
71643541db0SRichard Henderson #ifndef CONFIG_USER_ONLY
71743541db0SRichard Henderson     if (with_sr0) {
71843541db0SRichard Henderson         tcg_gen_mov_i64(cpu_sr[0], cpu_iasq_b);
71943541db0SRichard Henderson     }
72043541db0SRichard Henderson #endif
72161766fe9SRichard Henderson }
72261766fe9SRichard Henderson 
gen_excp_1(int exception)72361766fe9SRichard Henderson static void gen_excp_1(int exception)
72461766fe9SRichard Henderson {
72529dd6f64SRichard Henderson     gen_helper_excp(tcg_env, tcg_constant_i32(exception));
72661766fe9SRichard Henderson }
72761766fe9SRichard Henderson 
gen_excp(DisasContext * ctx,int exception)72831234768SRichard Henderson static void gen_excp(DisasContext *ctx, int exception)
72961766fe9SRichard Henderson {
730bc921866SRichard Henderson     install_iaq_entries(ctx, &ctx->iaq_f, &ctx->iaq_b);
731129e9cc3SRichard Henderson     nullify_save(ctx);
73261766fe9SRichard Henderson     gen_excp_1(exception);
73331234768SRichard Henderson     ctx->base.is_jmp = DISAS_NORETURN;
73461766fe9SRichard Henderson }
73561766fe9SRichard Henderson 
delay_excp(DisasContext * ctx,uint8_t excp)73680603007SRichard Henderson static DisasDelayException *delay_excp(DisasContext *ctx, uint8_t excp)
73780603007SRichard Henderson {
73880603007SRichard Henderson     DisasDelayException *e = tcg_malloc(sizeof(DisasDelayException));
73980603007SRichard Henderson 
74080603007SRichard Henderson     memset(e, 0, sizeof(*e));
74180603007SRichard Henderson     e->next = ctx->delay_excp_list;
74280603007SRichard Henderson     ctx->delay_excp_list = e;
74380603007SRichard Henderson 
74480603007SRichard Henderson     e->lab = gen_new_label();
74580603007SRichard Henderson     e->insn = ctx->insn;
74680603007SRichard Henderson     e->set_iir = true;
74780603007SRichard Henderson     e->set_n = ctx->psw_n_nonzero ? 0 : -1;
74880603007SRichard Henderson     e->excp = excp;
74980603007SRichard Henderson     e->iaq_f = ctx->iaq_f;
75080603007SRichard Henderson     e->iaq_b = ctx->iaq_b;
75180603007SRichard Henderson 
75280603007SRichard Henderson     return e;
75380603007SRichard Henderson }
75480603007SRichard Henderson 
gen_excp_iir(DisasContext * ctx,int exc)75531234768SRichard Henderson static bool gen_excp_iir(DisasContext *ctx, int exc)
7561a19da0dSRichard Henderson {
75780603007SRichard Henderson     if (ctx->null_cond.c == TCG_COND_NEVER) {
7586fd0c7bcSRichard Henderson         tcg_gen_st_i64(tcg_constant_i64(ctx->insn),
759ad75a51eSRichard Henderson                        tcg_env, offsetof(CPUHPPAState, cr[CR_IIR]));
76031234768SRichard Henderson         gen_excp(ctx, exc);
76180603007SRichard Henderson     } else {
76280603007SRichard Henderson         DisasDelayException *e = delay_excp(ctx, exc);
76380603007SRichard Henderson         tcg_gen_brcond_i64(tcg_invert_cond(ctx->null_cond.c),
76480603007SRichard Henderson                            ctx->null_cond.a0, ctx->null_cond.a1, e->lab);
76580603007SRichard Henderson         ctx->null_cond = cond_make_f();
76680603007SRichard Henderson     }
76780603007SRichard Henderson     return true;
7681a19da0dSRichard Henderson }
7691a19da0dSRichard Henderson 
gen_illegal(DisasContext * ctx)77031234768SRichard Henderson static bool gen_illegal(DisasContext *ctx)
77161766fe9SRichard Henderson {
77231234768SRichard Henderson     return gen_excp_iir(ctx, EXCP_ILL);
77361766fe9SRichard Henderson }
77461766fe9SRichard Henderson 
77540f9f908SRichard Henderson #ifdef CONFIG_USER_ONLY
77640f9f908SRichard Henderson #define CHECK_MOST_PRIVILEGED(EXCP) \
77740f9f908SRichard Henderson     return gen_excp_iir(ctx, EXCP)
77840f9f908SRichard Henderson #else
779e1b5a5edSRichard Henderson #define CHECK_MOST_PRIVILEGED(EXCP) \
780e1b5a5edSRichard Henderson     do {                                     \
781e1b5a5edSRichard Henderson         if (ctx->privilege != 0) {           \
78231234768SRichard Henderson             return gen_excp_iir(ctx, EXCP);  \
783e1b5a5edSRichard Henderson         }                                    \
784e1b5a5edSRichard Henderson     } while (0)
78540f9f908SRichard Henderson #endif
786e1b5a5edSRichard Henderson 
use_goto_tb(DisasContext * ctx,const DisasIAQE * f,const DisasIAQE * b)787bc921866SRichard Henderson static bool use_goto_tb(DisasContext *ctx, const DisasIAQE *f,
788bc921866SRichard Henderson                         const DisasIAQE *b)
78961766fe9SRichard Henderson {
790bc921866SRichard Henderson     return (!iaqe_variable(f) &&
791bc921866SRichard Henderson             (b == NULL || !iaqe_variable(b)) &&
7920d89cb7cSRichard Henderson             translator_use_goto_tb(&ctx->base, ctx->iaoq_first + f->disp));
79361766fe9SRichard Henderson }
79461766fe9SRichard Henderson 
795129e9cc3SRichard Henderson /* If the next insn is to be nullified, and it's on the same page,
796129e9cc3SRichard Henderson    and we're not attempting to set a breakpoint on it, then we can
797129e9cc3SRichard Henderson    totally skip the nullified insn.  This avoids creating and
798129e9cc3SRichard Henderson    executing a TB that merely branches to the next TB.  */
use_nullify_skip(DisasContext * ctx)799129e9cc3SRichard Henderson static bool use_nullify_skip(DisasContext *ctx)
800129e9cc3SRichard Henderson {
801f9b11bc2SRichard Henderson     return (!(tb_cflags(ctx->base.tb) & CF_BP_PAGE)
802bc921866SRichard Henderson             && !iaqe_variable(&ctx->iaq_b)
8030d89cb7cSRichard Henderson             && (((ctx->iaoq_first + ctx->iaq_b.disp) ^ ctx->iaoq_first)
8040d89cb7cSRichard Henderson                 & TARGET_PAGE_MASK) == 0);
805129e9cc3SRichard Henderson }
806129e9cc3SRichard Henderson 
gen_goto_tb(DisasContext * ctx,int which,const DisasIAQE * f,const DisasIAQE * b)80761766fe9SRichard Henderson static void gen_goto_tb(DisasContext *ctx, int which,
808bc921866SRichard Henderson                         const DisasIAQE *f, const DisasIAQE *b)
80961766fe9SRichard Henderson {
8109dfcd243SRichard Henderson     install_iaq_entries(ctx, f, b);
811bc921866SRichard Henderson     if (use_goto_tb(ctx, f, b)) {
81261766fe9SRichard Henderson         tcg_gen_goto_tb(which);
81307ea28b4SRichard Henderson         tcg_gen_exit_tb(ctx->base.tb, which);
81461766fe9SRichard Henderson     } else {
8157f11636dSEmilio G. Cota         tcg_gen_lookup_and_goto_ptr();
81661766fe9SRichard Henderson     }
81761766fe9SRichard Henderson }
81861766fe9SRichard Henderson 
cond_need_sv(int c)819b47a4a02SSven Schnelle static bool cond_need_sv(int c)
820b47a4a02SSven Schnelle {
821b47a4a02SSven Schnelle     return c == 2 || c == 3 || c == 6;
822b47a4a02SSven Schnelle }
823b47a4a02SSven Schnelle 
cond_need_cb(int c)824b47a4a02SSven Schnelle static bool cond_need_cb(int c)
825b47a4a02SSven Schnelle {
826b47a4a02SSven Schnelle     return c == 4 || c == 5;
827b47a4a02SSven Schnelle }
828b47a4a02SSven Schnelle 
829b47a4a02SSven Schnelle /*
830b47a4a02SSven Schnelle  * Compute conditional for arithmetic.  See Page 5-3, Table 5-1, of
831b47a4a02SSven Schnelle  * the Parisc 1.1 Architecture Reference Manual for details.
832b47a4a02SSven Schnelle  */
833b2167459SRichard Henderson 
do_cond(DisasContext * ctx,unsigned cf,bool d,TCGv_i64 res,TCGv_i64 uv,TCGv_i64 sv)834a751eb31SRichard Henderson static DisasCond do_cond(DisasContext *ctx, unsigned cf, bool d,
835fe2d066aSRichard Henderson                          TCGv_i64 res, TCGv_i64 uv, TCGv_i64 sv)
836b2167459SRichard Henderson {
837d6d46be1SRichard Henderson     TCGCond sign_cond, zero_cond;
838d6d46be1SRichard Henderson     uint64_t sign_imm, zero_imm;
839b2167459SRichard Henderson     DisasCond cond;
8406fd0c7bcSRichard Henderson     TCGv_i64 tmp;
841b2167459SRichard Henderson 
842d6d46be1SRichard Henderson     if (d) {
843d6d46be1SRichard Henderson         /* 64-bit condition. */
844d6d46be1SRichard Henderson         sign_imm = 0;
845d6d46be1SRichard Henderson         sign_cond = TCG_COND_LT;
846d6d46be1SRichard Henderson         zero_imm = 0;
847d6d46be1SRichard Henderson         zero_cond = TCG_COND_EQ;
848d6d46be1SRichard Henderson     } else {
849d6d46be1SRichard Henderson         /* 32-bit condition. */
850d6d46be1SRichard Henderson         sign_imm = 1ull << 31;
851d6d46be1SRichard Henderson         sign_cond = TCG_COND_TSTNE;
852d6d46be1SRichard Henderson         zero_imm = UINT32_MAX;
853d6d46be1SRichard Henderson         zero_cond = TCG_COND_TSTEQ;
854d6d46be1SRichard Henderson     }
855d6d46be1SRichard Henderson 
856b2167459SRichard Henderson     switch (cf >> 1) {
857b47a4a02SSven Schnelle     case 0: /* Never / TR    (0 / 1) */
858b2167459SRichard Henderson         cond = cond_make_f();
859b2167459SRichard Henderson         break;
860b2167459SRichard Henderson     case 1: /* = / <>        (Z / !Z) */
861d6d46be1SRichard Henderson         cond = cond_make_vi(zero_cond, res, zero_imm);
862b2167459SRichard Henderson         break;
863b47a4a02SSven Schnelle     case 2: /* < / >=        (N ^ V / !(N ^ V) */
864aac0f603SRichard Henderson         tmp = tcg_temp_new_i64();
8656fd0c7bcSRichard Henderson         tcg_gen_xor_i64(tmp, res, sv);
866d6d46be1SRichard Henderson         cond = cond_make_ti(sign_cond, tmp, sign_imm);
867b2167459SRichard Henderson         break;
868b47a4a02SSven Schnelle     case 3: /* <= / >        (N ^ V) | Z / !((N ^ V) | Z) */
869b47a4a02SSven Schnelle         /*
870b47a4a02SSven Schnelle          * Simplify:
871b47a4a02SSven Schnelle          *   (N ^ V) | Z
872b47a4a02SSven Schnelle          *   ((res < 0) ^ (sv < 0)) | !res
873b47a4a02SSven Schnelle          *   ((res ^ sv) < 0) | !res
874d6d46be1SRichard Henderson          *   ((res ^ sv) < 0 ? 1 : !res)
875d6d46be1SRichard Henderson          *   !((res ^ sv) < 0 ? 0 : res)
876b47a4a02SSven Schnelle          */
877aac0f603SRichard Henderson         tmp = tcg_temp_new_i64();
878d6d46be1SRichard Henderson         tcg_gen_xor_i64(tmp, res, sv);
879d6d46be1SRichard Henderson         tcg_gen_movcond_i64(sign_cond, tmp,
880d6d46be1SRichard Henderson                             tmp, tcg_constant_i64(sign_imm),
881d6d46be1SRichard Henderson                             ctx->zero, res);
882d6d46be1SRichard Henderson         cond = cond_make_ti(zero_cond, tmp, zero_imm);
883b2167459SRichard Henderson         break;
884fe2d066aSRichard Henderson     case 4: /* NUV / UV      (!UV / UV) */
8854c42fd0dSRichard Henderson         cond = cond_make_vi(TCG_COND_EQ, uv, 0);
886b2167459SRichard Henderson         break;
887fe2d066aSRichard Henderson     case 5: /* ZNV / VNZ     (!UV | Z / UV & !Z) */
888aac0f603SRichard Henderson         tmp = tcg_temp_new_i64();
889fe2d066aSRichard Henderson         tcg_gen_movcond_i64(TCG_COND_EQ, tmp, uv, ctx->zero, ctx->zero, res);
890d6d46be1SRichard Henderson         cond = cond_make_ti(zero_cond, tmp, zero_imm);
891b2167459SRichard Henderson         break;
892b2167459SRichard Henderson     case 6: /* SV / NSV      (V / !V) */
893d6d46be1SRichard Henderson         cond = cond_make_vi(sign_cond, sv, sign_imm);
894b2167459SRichard Henderson         break;
895b2167459SRichard Henderson     case 7: /* OD / EV */
896d6d46be1SRichard Henderson         cond = cond_make_vi(TCG_COND_TSTNE, res, 1);
897b2167459SRichard Henderson         break;
898b2167459SRichard Henderson     default:
899b2167459SRichard Henderson         g_assert_not_reached();
900b2167459SRichard Henderson     }
901b2167459SRichard Henderson     if (cf & 1) {
902b2167459SRichard Henderson         cond.c = tcg_invert_cond(cond.c);
903b2167459SRichard Henderson     }
904b2167459SRichard Henderson 
905b2167459SRichard Henderson     return cond;
906b2167459SRichard Henderson }
907b2167459SRichard Henderson 
908b2167459SRichard Henderson /* Similar, but for the special case of subtraction without borrow, we
909b2167459SRichard Henderson    can use the inputs directly.  This can allow other computation to be
910b2167459SRichard Henderson    deleted as unused.  */
911b2167459SRichard Henderson 
do_sub_cond(DisasContext * ctx,unsigned cf,bool d,TCGv_i64 res,TCGv_i64 in1,TCGv_i64 in2,TCGv_i64 sv)9124fe9533aSRichard Henderson static DisasCond do_sub_cond(DisasContext *ctx, unsigned cf, bool d,
9136fd0c7bcSRichard Henderson                              TCGv_i64 res, TCGv_i64 in1,
9146fd0c7bcSRichard Henderson                              TCGv_i64 in2, TCGv_i64 sv)
915b2167459SRichard Henderson {
9164fe9533aSRichard Henderson     TCGCond tc;
9174fe9533aSRichard Henderson     bool ext_uns;
918b2167459SRichard Henderson 
919b2167459SRichard Henderson     switch (cf >> 1) {
920b2167459SRichard Henderson     case 1: /* = / <> */
9214fe9533aSRichard Henderson         tc = TCG_COND_EQ;
9224fe9533aSRichard Henderson         ext_uns = true;
923b2167459SRichard Henderson         break;
924b2167459SRichard Henderson     case 2: /* < / >= */
9254fe9533aSRichard Henderson         tc = TCG_COND_LT;
9264fe9533aSRichard Henderson         ext_uns = false;
927b2167459SRichard Henderson         break;
928b2167459SRichard Henderson     case 3: /* <= / > */
9294fe9533aSRichard Henderson         tc = TCG_COND_LE;
9304fe9533aSRichard Henderson         ext_uns = false;
931b2167459SRichard Henderson         break;
932b2167459SRichard Henderson     case 4: /* << / >>= */
9334fe9533aSRichard Henderson         tc = TCG_COND_LTU;
9344fe9533aSRichard Henderson         ext_uns = true;
935b2167459SRichard Henderson         break;
936b2167459SRichard Henderson     case 5: /* <<= / >> */
9374fe9533aSRichard Henderson         tc = TCG_COND_LEU;
9384fe9533aSRichard Henderson         ext_uns = true;
939b2167459SRichard Henderson         break;
940b2167459SRichard Henderson     default:
941a751eb31SRichard Henderson         return do_cond(ctx, cf, d, res, NULL, sv);
942b2167459SRichard Henderson     }
943b2167459SRichard Henderson 
9444fe9533aSRichard Henderson     if (cf & 1) {
9454fe9533aSRichard Henderson         tc = tcg_invert_cond(tc);
9464fe9533aSRichard Henderson     }
94782d0c831SRichard Henderson     if (!d) {
948aac0f603SRichard Henderson         TCGv_i64 t1 = tcg_temp_new_i64();
949aac0f603SRichard Henderson         TCGv_i64 t2 = tcg_temp_new_i64();
9504fe9533aSRichard Henderson 
9514fe9533aSRichard Henderson         if (ext_uns) {
9526fd0c7bcSRichard Henderson             tcg_gen_ext32u_i64(t1, in1);
9536fd0c7bcSRichard Henderson             tcg_gen_ext32u_i64(t2, in2);
9544fe9533aSRichard Henderson         } else {
9556fd0c7bcSRichard Henderson             tcg_gen_ext32s_i64(t1, in1);
9566fd0c7bcSRichard Henderson             tcg_gen_ext32s_i64(t2, in2);
9574fe9533aSRichard Henderson         }
9584c42fd0dSRichard Henderson         return cond_make_tt(tc, t1, t2);
9594fe9533aSRichard Henderson     }
9604c42fd0dSRichard Henderson     return cond_make_vv(tc, in1, in2);
961b2167459SRichard Henderson }
962b2167459SRichard Henderson 
963df0232feSRichard Henderson /*
964df0232feSRichard Henderson  * Similar, but for logicals, where the carry and overflow bits are not
965df0232feSRichard Henderson  * computed, and use of them is undefined.
966df0232feSRichard Henderson  *
967df0232feSRichard Henderson  * Undefined or not, hardware does not trap.  It seems reasonable to
968df0232feSRichard Henderson  * assume hardware treats cases c={4,5,6} as if C=0 & V=0, since that's
969df0232feSRichard Henderson  * how cases c={2,3} are treated.
970df0232feSRichard Henderson  */
971b2167459SRichard Henderson 
do_log_cond(DisasContext * ctx,unsigned cf,bool d,TCGv_i64 res)972b5af8423SRichard Henderson static DisasCond do_log_cond(DisasContext *ctx, unsigned cf, bool d,
9736fd0c7bcSRichard Henderson                              TCGv_i64 res)
974b2167459SRichard Henderson {
975b5af8423SRichard Henderson     TCGCond tc;
976fbe65c64SRichard Henderson     uint64_t imm;
977a751eb31SRichard Henderson 
978fbe65c64SRichard Henderson     switch (cf >> 1) {
979fbe65c64SRichard Henderson     case 0:  /* never / always */
980fbe65c64SRichard Henderson     case 4:  /* undef, C */
981fbe65c64SRichard Henderson     case 5:  /* undef, C & !Z */
982fbe65c64SRichard Henderson     case 6:  /* undef, V */
983fbe65c64SRichard Henderson         return cf & 1 ? cond_make_t() : cond_make_f();
984fbe65c64SRichard Henderson     case 1:  /* == / <> */
985fbe65c64SRichard Henderson         tc = d ? TCG_COND_EQ : TCG_COND_TSTEQ;
986fbe65c64SRichard Henderson         imm = d ? 0 : UINT32_MAX;
987b5af8423SRichard Henderson         break;
988fbe65c64SRichard Henderson     case 2:  /* < / >= */
989fbe65c64SRichard Henderson         tc = d ? TCG_COND_LT : TCG_COND_TSTNE;
990fbe65c64SRichard Henderson         imm = d ? 0 : 1ull << 31;
991b5af8423SRichard Henderson         break;
992fbe65c64SRichard Henderson     case 3:  /* <= / > */
993fbe65c64SRichard Henderson         tc = cf & 1 ? TCG_COND_GT : TCG_COND_LE;
99482d0c831SRichard Henderson         if (!d) {
995aac0f603SRichard Henderson             TCGv_i64 tmp = tcg_temp_new_i64();
9966fd0c7bcSRichard Henderson             tcg_gen_ext32s_i64(tmp, res);
9974c42fd0dSRichard Henderson             return cond_make_ti(tc, tmp, 0);
998b5af8423SRichard Henderson         }
9994c42fd0dSRichard Henderson         return cond_make_vi(tc, res, 0);
1000fbe65c64SRichard Henderson     case 7: /* OD / EV */
1001fbe65c64SRichard Henderson         tc = TCG_COND_TSTNE;
1002fbe65c64SRichard Henderson         imm = 1;
1003df0232feSRichard Henderson         break;
1004df0232feSRichard Henderson     default:
1005df0232feSRichard Henderson         g_assert_not_reached();
1006b2167459SRichard Henderson     }
1007fbe65c64SRichard Henderson     if (cf & 1) {
1008fbe65c64SRichard Henderson         tc = tcg_invert_cond(tc);
1009b5af8423SRichard Henderson     }
1010fbe65c64SRichard Henderson     return cond_make_vi(tc, res, imm);
1011b2167459SRichard Henderson }
1012b2167459SRichard Henderson 
101398cd9ca7SRichard Henderson /* Similar, but for shift/extract/deposit conditions.  */
101498cd9ca7SRichard Henderson 
do_sed_cond(DisasContext * ctx,unsigned orig,bool d,TCGv_i64 res)10154fa52edfSRichard Henderson static DisasCond do_sed_cond(DisasContext *ctx, unsigned orig, bool d,
10166fd0c7bcSRichard Henderson                              TCGv_i64 res)
101798cd9ca7SRichard Henderson {
101898cd9ca7SRichard Henderson     unsigned c, f;
101998cd9ca7SRichard Henderson 
102098cd9ca7SRichard Henderson     /* Convert the compressed condition codes to standard.
102198cd9ca7SRichard Henderson        0-2 are the same as logicals (nv,<,<=), while 3 is OD.
102298cd9ca7SRichard Henderson        4-7 are the reverse of 0-3.  */
102398cd9ca7SRichard Henderson     c = orig & 3;
102498cd9ca7SRichard Henderson     if (c == 3) {
102598cd9ca7SRichard Henderson         c = 7;
102698cd9ca7SRichard Henderson     }
102798cd9ca7SRichard Henderson     f = (orig & 4) / 4;
102898cd9ca7SRichard Henderson 
1029b5af8423SRichard Henderson     return do_log_cond(ctx, c * 2 + f, d, res);
103098cd9ca7SRichard Henderson }
103198cd9ca7SRichard Henderson 
103246bb3d46SRichard Henderson /* Similar, but for unit zero conditions.  */
do_unit_zero_cond(unsigned cf,bool d,TCGv_i64 res)103346bb3d46SRichard Henderson static DisasCond do_unit_zero_cond(unsigned cf, bool d, TCGv_i64 res)
1034b2167459SRichard Henderson {
103546bb3d46SRichard Henderson     TCGv_i64 tmp;
1036c53e401eSRichard Henderson     uint64_t d_repl = d ? 0x0000000100000001ull : 1;
103746bb3d46SRichard Henderson     uint64_t ones = 0, sgns = 0;
1038b2167459SRichard Henderson 
1039b2167459SRichard Henderson     switch (cf >> 1) {
1040578b8132SSven Schnelle     case 1: /* SBW / NBW */
1041578b8132SSven Schnelle         if (d) {
104246bb3d46SRichard Henderson             ones = d_repl;
104346bb3d46SRichard Henderson             sgns = d_repl << 31;
1044578b8132SSven Schnelle         }
1045578b8132SSven Schnelle         break;
1046b2167459SRichard Henderson     case 2: /* SBZ / NBZ */
104746bb3d46SRichard Henderson         ones = d_repl * 0x01010101u;
104846bb3d46SRichard Henderson         sgns = ones << 7;
104946bb3d46SRichard Henderson         break;
105046bb3d46SRichard Henderson     case 3: /* SHZ / NHZ */
105146bb3d46SRichard Henderson         ones = d_repl * 0x00010001u;
105246bb3d46SRichard Henderson         sgns = ones << 15;
105346bb3d46SRichard Henderson         break;
105446bb3d46SRichard Henderson     }
105546bb3d46SRichard Henderson     if (ones == 0) {
105646bb3d46SRichard Henderson         /* Undefined, or 0/1 (never/always). */
105746bb3d46SRichard Henderson         return cf & 1 ? cond_make_t() : cond_make_f();
105846bb3d46SRichard Henderson     }
105946bb3d46SRichard Henderson 
106046bb3d46SRichard Henderson     /*
106146bb3d46SRichard Henderson      * See hasless(v,1) from
1062b2167459SRichard Henderson      * https://graphics.stanford.edu/~seander/bithacks.html#ZeroInWord
1063b2167459SRichard Henderson      */
1064aac0f603SRichard Henderson     tmp = tcg_temp_new_i64();
106546bb3d46SRichard Henderson     tcg_gen_subi_i64(tmp, res, ones);
10666fd0c7bcSRichard Henderson     tcg_gen_andc_i64(tmp, tmp, res);
1067b2167459SRichard Henderson 
106825f97be7SRichard Henderson     return cond_make_ti(cf & 1 ? TCG_COND_TSTEQ : TCG_COND_TSTNE, tmp, sgns);
1069b2167459SRichard Henderson }
1070b2167459SRichard Henderson 
get_carry(DisasContext * ctx,bool d,TCGv_i64 cb,TCGv_i64 cb_msb)10716fd0c7bcSRichard Henderson static TCGv_i64 get_carry(DisasContext *ctx, bool d,
10726fd0c7bcSRichard Henderson                           TCGv_i64 cb, TCGv_i64 cb_msb)
107372ca8753SRichard Henderson {
107482d0c831SRichard Henderson     if (!d) {
1075aac0f603SRichard Henderson         TCGv_i64 t = tcg_temp_new_i64();
10766fd0c7bcSRichard Henderson         tcg_gen_extract_i64(t, cb, 32, 1);
107772ca8753SRichard Henderson         return t;
107872ca8753SRichard Henderson     }
107972ca8753SRichard Henderson     return cb_msb;
108072ca8753SRichard Henderson }
108172ca8753SRichard Henderson 
get_psw_carry(DisasContext * ctx,bool d)10826fd0c7bcSRichard Henderson static TCGv_i64 get_psw_carry(DisasContext *ctx, bool d)
108372ca8753SRichard Henderson {
108472ca8753SRichard Henderson     return get_carry(ctx, d, cpu_psw_cb, cpu_psw_cb_msb);
108572ca8753SRichard Henderson }
108672ca8753SRichard Henderson 
1087b2167459SRichard Henderson /* Compute signed overflow for addition.  */
do_add_sv(DisasContext * ctx,TCGv_i64 res,TCGv_i64 in1,TCGv_i64 in2,TCGv_i64 orig_in1,int shift,bool d)10886fd0c7bcSRichard Henderson static TCGv_i64 do_add_sv(DisasContext *ctx, TCGv_i64 res,
1089f8f5986eSRichard Henderson                           TCGv_i64 in1, TCGv_i64 in2,
1090f8f5986eSRichard Henderson                           TCGv_i64 orig_in1, int shift, bool d)
1091b2167459SRichard Henderson {
1092aac0f603SRichard Henderson     TCGv_i64 sv = tcg_temp_new_i64();
1093aac0f603SRichard Henderson     TCGv_i64 tmp = tcg_temp_new_i64();
1094b2167459SRichard Henderson 
10956fd0c7bcSRichard Henderson     tcg_gen_xor_i64(sv, res, in1);
10966fd0c7bcSRichard Henderson     tcg_gen_xor_i64(tmp, in1, in2);
10976fd0c7bcSRichard Henderson     tcg_gen_andc_i64(sv, sv, tmp);
1098b2167459SRichard Henderson 
1099f8f5986eSRichard Henderson     switch (shift) {
1100f8f5986eSRichard Henderson     case 0:
1101f8f5986eSRichard Henderson         break;
1102f8f5986eSRichard Henderson     case 1:
1103f8f5986eSRichard Henderson         /* Shift left by one and compare the sign. */
1104f8f5986eSRichard Henderson         tcg_gen_add_i64(tmp, orig_in1, orig_in1);
1105f8f5986eSRichard Henderson         tcg_gen_xor_i64(tmp, tmp, orig_in1);
1106f8f5986eSRichard Henderson         /* Incorporate into the overflow. */
1107f8f5986eSRichard Henderson         tcg_gen_or_i64(sv, sv, tmp);
1108f8f5986eSRichard Henderson         break;
1109f8f5986eSRichard Henderson     default:
1110f8f5986eSRichard Henderson         {
1111f8f5986eSRichard Henderson             int sign_bit = d ? 63 : 31;
1112f8f5986eSRichard Henderson 
1113f8f5986eSRichard Henderson             /* Compare the sign against all lower bits. */
1114f8f5986eSRichard Henderson             tcg_gen_sextract_i64(tmp, orig_in1, sign_bit, 1);
1115f8f5986eSRichard Henderson             tcg_gen_xor_i64(tmp, tmp, orig_in1);
1116f8f5986eSRichard Henderson             /*
1117f8f5986eSRichard Henderson              * If one of the bits shifting into or through the sign
1118f8f5986eSRichard Henderson              * differs, then we have overflow.
1119f8f5986eSRichard Henderson              */
1120f8f5986eSRichard Henderson             tcg_gen_extract_i64(tmp, tmp, sign_bit - shift, shift);
1121f8f5986eSRichard Henderson             tcg_gen_movcond_i64(TCG_COND_NE, sv, tmp, ctx->zero,
1122f8f5986eSRichard Henderson                                 tcg_constant_i64(-1), sv);
1123f8f5986eSRichard Henderson         }
1124f8f5986eSRichard Henderson     }
1125b2167459SRichard Henderson     return sv;
1126b2167459SRichard Henderson }
1127b2167459SRichard Henderson 
1128f8f5986eSRichard Henderson /* Compute unsigned overflow for addition.  */
do_add_uv(DisasContext * ctx,TCGv_i64 cb,TCGv_i64 cb_msb,TCGv_i64 in1,int shift,bool d)1129f8f5986eSRichard Henderson static TCGv_i64 do_add_uv(DisasContext *ctx, TCGv_i64 cb, TCGv_i64 cb_msb,
1130f8f5986eSRichard Henderson                           TCGv_i64 in1, int shift, bool d)
1131f8f5986eSRichard Henderson {
1132f8f5986eSRichard Henderson     if (shift == 0) {
1133f8f5986eSRichard Henderson         return get_carry(ctx, d, cb, cb_msb);
1134f8f5986eSRichard Henderson     } else {
1135f8f5986eSRichard Henderson         TCGv_i64 tmp = tcg_temp_new_i64();
1136f8f5986eSRichard Henderson         tcg_gen_extract_i64(tmp, in1, (d ? 63 : 31) - shift, shift);
1137f8f5986eSRichard Henderson         tcg_gen_or_i64(tmp, tmp, get_carry(ctx, d, cb, cb_msb));
1138f8f5986eSRichard Henderson         return tmp;
1139f8f5986eSRichard Henderson     }
1140f8f5986eSRichard Henderson }
1141f8f5986eSRichard Henderson 
1142b2167459SRichard Henderson /* Compute signed overflow for subtraction.  */
do_sub_sv(DisasContext * ctx,TCGv_i64 res,TCGv_i64 in1,TCGv_i64 in2)11436fd0c7bcSRichard Henderson static TCGv_i64 do_sub_sv(DisasContext *ctx, TCGv_i64 res,
11446fd0c7bcSRichard Henderson                           TCGv_i64 in1, TCGv_i64 in2)
1145b2167459SRichard Henderson {
1146aac0f603SRichard Henderson     TCGv_i64 sv = tcg_temp_new_i64();
1147aac0f603SRichard Henderson     TCGv_i64 tmp = tcg_temp_new_i64();
1148b2167459SRichard Henderson 
11496fd0c7bcSRichard Henderson     tcg_gen_xor_i64(sv, res, in1);
11506fd0c7bcSRichard Henderson     tcg_gen_xor_i64(tmp, in1, in2);
11516fd0c7bcSRichard Henderson     tcg_gen_and_i64(sv, sv, tmp);
1152b2167459SRichard Henderson 
1153b2167459SRichard Henderson     return sv;
1154b2167459SRichard Henderson }
1155b2167459SRichard Henderson 
gen_tc(DisasContext * ctx,DisasCond * cond)1156269ca0a9SRichard Henderson static void gen_tc(DisasContext *ctx, DisasCond *cond)
1157269ca0a9SRichard Henderson {
1158269ca0a9SRichard Henderson     DisasDelayException *e;
1159269ca0a9SRichard Henderson 
1160269ca0a9SRichard Henderson     switch (cond->c) {
1161269ca0a9SRichard Henderson     case TCG_COND_NEVER:
1162269ca0a9SRichard Henderson         break;
1163269ca0a9SRichard Henderson     case TCG_COND_ALWAYS:
1164269ca0a9SRichard Henderson         gen_excp_iir(ctx, EXCP_COND);
1165269ca0a9SRichard Henderson         break;
1166269ca0a9SRichard Henderson     default:
1167269ca0a9SRichard Henderson         e = delay_excp(ctx, EXCP_COND);
1168269ca0a9SRichard Henderson         tcg_gen_brcond_i64(cond->c, cond->a0, cond->a1, e->lab);
1169269ca0a9SRichard Henderson         /* In the non-trap path, the condition is known false. */
1170269ca0a9SRichard Henderson         *cond = cond_make_f();
1171269ca0a9SRichard Henderson         break;
1172269ca0a9SRichard Henderson     }
1173269ca0a9SRichard Henderson }
1174269ca0a9SRichard Henderson 
gen_tsv(DisasContext * ctx,TCGv_i64 * sv,bool d)1175a0ea4becSRichard Henderson static void gen_tsv(DisasContext *ctx, TCGv_i64 *sv, bool d)
1176a0ea4becSRichard Henderson {
1177a0ea4becSRichard Henderson     DisasCond cond = do_cond(ctx, /* SV */ 12, d, NULL, NULL, *sv);
1178a0ea4becSRichard Henderson     DisasDelayException *e = delay_excp(ctx, EXCP_OVERFLOW);
1179a0ea4becSRichard Henderson 
1180a0ea4becSRichard Henderson     tcg_gen_brcond_i64(cond.c, cond.a0, cond.a1, e->lab);
1181a0ea4becSRichard Henderson 
1182a0ea4becSRichard Henderson     /* In the non-trap path, V is known zero. */
1183a0ea4becSRichard Henderson     *sv = tcg_constant_i64(0);
1184a0ea4becSRichard Henderson }
1185a0ea4becSRichard Henderson 
do_add(DisasContext * ctx,unsigned rt,TCGv_i64 orig_in1,TCGv_i64 in2,unsigned shift,bool is_l,bool is_tsv,bool is_tc,bool is_c,unsigned cf,bool d)1186f8f5986eSRichard Henderson static void do_add(DisasContext *ctx, unsigned rt, TCGv_i64 orig_in1,
11876fd0c7bcSRichard Henderson                    TCGv_i64 in2, unsigned shift, bool is_l,
1188faf97ba1SRichard Henderson                    bool is_tsv, bool is_tc, bool is_c, unsigned cf, bool d)
1189b2167459SRichard Henderson {
1190f8f5986eSRichard Henderson     TCGv_i64 dest, cb, cb_msb, in1, uv, sv, tmp;
1191b2167459SRichard Henderson     unsigned c = cf >> 1;
1192b2167459SRichard Henderson     DisasCond cond;
1193b2167459SRichard Henderson 
1194aac0f603SRichard Henderson     dest = tcg_temp_new_i64();
1195f764718dSRichard Henderson     cb = NULL;
1196f764718dSRichard Henderson     cb_msb = NULL;
1197b2167459SRichard Henderson 
1198f8f5986eSRichard Henderson     in1 = orig_in1;
1199b2167459SRichard Henderson     if (shift) {
1200aac0f603SRichard Henderson         tmp = tcg_temp_new_i64();
12016fd0c7bcSRichard Henderson         tcg_gen_shli_i64(tmp, in1, shift);
1202b2167459SRichard Henderson         in1 = tmp;
1203b2167459SRichard Henderson     }
1204b2167459SRichard Henderson 
1205b47a4a02SSven Schnelle     if (!is_l || cond_need_cb(c)) {
1206aac0f603SRichard Henderson         cb_msb = tcg_temp_new_i64();
1207aac0f603SRichard Henderson         cb = tcg_temp_new_i64();
1208bdcccc17SRichard Henderson 
1209a4db4a78SRichard Henderson         tcg_gen_add2_i64(dest, cb_msb, in1, ctx->zero, in2, ctx->zero);
1210b2167459SRichard Henderson         if (is_c) {
12116fd0c7bcSRichard Henderson             tcg_gen_add2_i64(dest, cb_msb, dest, cb_msb,
1212a4db4a78SRichard Henderson                              get_psw_carry(ctx, d), ctx->zero);
1213b2167459SRichard Henderson         }
12146fd0c7bcSRichard Henderson         tcg_gen_xor_i64(cb, in1, in2);
12156fd0c7bcSRichard Henderson         tcg_gen_xor_i64(cb, cb, dest);
1216b2167459SRichard Henderson     } else {
12176fd0c7bcSRichard Henderson         tcg_gen_add_i64(dest, in1, in2);
1218b2167459SRichard Henderson         if (is_c) {
12196fd0c7bcSRichard Henderson             tcg_gen_add_i64(dest, dest, get_psw_carry(ctx, d));
1220b2167459SRichard Henderson         }
1221b2167459SRichard Henderson     }
1222b2167459SRichard Henderson 
1223b2167459SRichard Henderson     /* Compute signed overflow if required.  */
1224f764718dSRichard Henderson     sv = NULL;
1225b47a4a02SSven Schnelle     if (is_tsv || cond_need_sv(c)) {
1226f8f5986eSRichard Henderson         sv = do_add_sv(ctx, dest, in1, in2, orig_in1, shift, d);
1227b2167459SRichard Henderson         if (is_tsv) {
1228a0ea4becSRichard Henderson             gen_tsv(ctx, &sv, d);
1229b2167459SRichard Henderson         }
1230b2167459SRichard Henderson     }
1231b2167459SRichard Henderson 
1232f8f5986eSRichard Henderson     /* Compute unsigned overflow if required.  */
1233f8f5986eSRichard Henderson     uv = NULL;
1234f8f5986eSRichard Henderson     if (cond_need_cb(c)) {
1235f8f5986eSRichard Henderson         uv = do_add_uv(ctx, cb, cb_msb, orig_in1, shift, d);
1236f8f5986eSRichard Henderson     }
1237f8f5986eSRichard Henderson 
1238b2167459SRichard Henderson     /* Emit any conditional trap before any writeback.  */
1239f8f5986eSRichard Henderson     cond = do_cond(ctx, cf, d, dest, uv, sv);
1240b2167459SRichard Henderson     if (is_tc) {
1241269ca0a9SRichard Henderson         gen_tc(ctx, &cond);
1242b2167459SRichard Henderson     }
1243b2167459SRichard Henderson 
1244b2167459SRichard Henderson     /* Write back the result.  */
1245b2167459SRichard Henderson     if (!is_l) {
1246b2167459SRichard Henderson         save_or_nullify(ctx, cpu_psw_cb, cb);
1247b2167459SRichard Henderson         save_or_nullify(ctx, cpu_psw_cb_msb, cb_msb);
1248b2167459SRichard Henderson     }
1249b2167459SRichard Henderson     save_gpr(ctx, rt, dest);
1250b2167459SRichard Henderson 
1251b2167459SRichard Henderson     /* Install the new nullification.  */
1252b2167459SRichard Henderson     ctx->null_cond = cond;
1253b2167459SRichard Henderson }
1254b2167459SRichard Henderson 
do_add_reg(DisasContext * ctx,arg_rrr_cf_d_sh * a,bool is_l,bool is_tsv,bool is_tc,bool is_c)1255faf97ba1SRichard Henderson static bool do_add_reg(DisasContext *ctx, arg_rrr_cf_d_sh *a,
12560c982a28SRichard Henderson                        bool is_l, bool is_tsv, bool is_tc, bool is_c)
12570c982a28SRichard Henderson {
12586fd0c7bcSRichard Henderson     TCGv_i64 tcg_r1, tcg_r2;
12590c982a28SRichard Henderson 
1260269ca0a9SRichard Henderson     if (unlikely(is_tc && a->cf == 1)) {
1261269ca0a9SRichard Henderson         /* Unconditional trap on condition. */
1262269ca0a9SRichard Henderson         return gen_excp_iir(ctx, EXCP_COND);
1263269ca0a9SRichard Henderson     }
12640c982a28SRichard Henderson     if (a->cf) {
12650c982a28SRichard Henderson         nullify_over(ctx);
12660c982a28SRichard Henderson     }
12670c982a28SRichard Henderson     tcg_r1 = load_gpr(ctx, a->r1);
12680c982a28SRichard Henderson     tcg_r2 = load_gpr(ctx, a->r2);
1269faf97ba1SRichard Henderson     do_add(ctx, a->t, tcg_r1, tcg_r2, a->sh, is_l,
1270faf97ba1SRichard Henderson            is_tsv, is_tc, is_c, a->cf, a->d);
12710c982a28SRichard Henderson     return nullify_end(ctx);
12720c982a28SRichard Henderson }
12730c982a28SRichard Henderson 
do_add_imm(DisasContext * ctx,arg_rri_cf * a,bool is_tsv,bool is_tc)12740588e061SRichard Henderson static bool do_add_imm(DisasContext *ctx, arg_rri_cf *a,
12750588e061SRichard Henderson                        bool is_tsv, bool is_tc)
12760588e061SRichard Henderson {
12776fd0c7bcSRichard Henderson     TCGv_i64 tcg_im, tcg_r2;
12780588e061SRichard Henderson 
1279269ca0a9SRichard Henderson     if (unlikely(is_tc && a->cf == 1)) {
1280269ca0a9SRichard Henderson         /* Unconditional trap on condition. */
1281269ca0a9SRichard Henderson         return gen_excp_iir(ctx, EXCP_COND);
1282269ca0a9SRichard Henderson     }
12830588e061SRichard Henderson     if (a->cf) {
12840588e061SRichard Henderson         nullify_over(ctx);
12850588e061SRichard Henderson     }
12866fd0c7bcSRichard Henderson     tcg_im = tcg_constant_i64(a->i);
12870588e061SRichard Henderson     tcg_r2 = load_gpr(ctx, a->r);
1288faf97ba1SRichard Henderson     /* All ADDI conditions are 32-bit. */
1289faf97ba1SRichard Henderson     do_add(ctx, a->t, tcg_im, tcg_r2, 0, 0, is_tsv, is_tc, 0, a->cf, false);
12900588e061SRichard Henderson     return nullify_end(ctx);
12910588e061SRichard Henderson }
12920588e061SRichard Henderson 
do_sub(DisasContext * ctx,unsigned rt,TCGv_i64 in1,TCGv_i64 in2,bool is_tsv,bool is_b,bool is_tc,unsigned cf,bool d)12936fd0c7bcSRichard Henderson static void do_sub(DisasContext *ctx, unsigned rt, TCGv_i64 in1,
12946fd0c7bcSRichard Henderson                    TCGv_i64 in2, bool is_tsv, bool is_b,
129563c427c6SRichard Henderson                    bool is_tc, unsigned cf, bool d)
1296b2167459SRichard Henderson {
1297269ca0a9SRichard Henderson     TCGv_i64 dest, sv, cb, cb_msb;
1298b2167459SRichard Henderson     unsigned c = cf >> 1;
1299b2167459SRichard Henderson     DisasCond cond;
1300b2167459SRichard Henderson 
1301aac0f603SRichard Henderson     dest = tcg_temp_new_i64();
1302aac0f603SRichard Henderson     cb = tcg_temp_new_i64();
1303aac0f603SRichard Henderson     cb_msb = tcg_temp_new_i64();
1304b2167459SRichard Henderson 
1305b2167459SRichard Henderson     if (is_b) {
1306b2167459SRichard Henderson         /* DEST,C = IN1 + ~IN2 + C.  */
13076fd0c7bcSRichard Henderson         tcg_gen_not_i64(cb, in2);
1308a4db4a78SRichard Henderson         tcg_gen_add2_i64(dest, cb_msb, in1, ctx->zero,
1309a4db4a78SRichard Henderson                          get_psw_carry(ctx, d), ctx->zero);
1310a4db4a78SRichard Henderson         tcg_gen_add2_i64(dest, cb_msb, dest, cb_msb, cb, ctx->zero);
13116fd0c7bcSRichard Henderson         tcg_gen_xor_i64(cb, cb, in1);
13126fd0c7bcSRichard Henderson         tcg_gen_xor_i64(cb, cb, dest);
1313b2167459SRichard Henderson     } else {
1314bdcccc17SRichard Henderson         /*
1315bdcccc17SRichard Henderson          * DEST,C = IN1 + ~IN2 + 1.  We can produce the same result in fewer
1316bdcccc17SRichard Henderson          * operations by seeding the high word with 1 and subtracting.
1317bdcccc17SRichard Henderson          */
13186fd0c7bcSRichard Henderson         TCGv_i64 one = tcg_constant_i64(1);
1319a4db4a78SRichard Henderson         tcg_gen_sub2_i64(dest, cb_msb, in1, one, in2, ctx->zero);
13206fd0c7bcSRichard Henderson         tcg_gen_eqv_i64(cb, in1, in2);
13216fd0c7bcSRichard Henderson         tcg_gen_xor_i64(cb, cb, dest);
1322b2167459SRichard Henderson     }
1323b2167459SRichard Henderson 
1324b2167459SRichard Henderson     /* Compute signed overflow if required.  */
1325f764718dSRichard Henderson     sv = NULL;
1326b47a4a02SSven Schnelle     if (is_tsv || cond_need_sv(c)) {
1327b2167459SRichard Henderson         sv = do_sub_sv(ctx, dest, in1, in2);
1328b2167459SRichard Henderson         if (is_tsv) {
1329a0ea4becSRichard Henderson             gen_tsv(ctx, &sv, d);
1330b2167459SRichard Henderson         }
1331b2167459SRichard Henderson     }
1332b2167459SRichard Henderson 
1333b2167459SRichard Henderson     /* Compute the condition.  We cannot use the special case for borrow.  */
1334b2167459SRichard Henderson     if (!is_b) {
13354fe9533aSRichard Henderson         cond = do_sub_cond(ctx, cf, d, dest, in1, in2, sv);
1336b2167459SRichard Henderson     } else {
1337a751eb31SRichard Henderson         cond = do_cond(ctx, cf, d, dest, get_carry(ctx, d, cb, cb_msb), sv);
1338b2167459SRichard Henderson     }
1339b2167459SRichard Henderson 
1340b2167459SRichard Henderson     /* Emit any conditional trap before any writeback.  */
1341b2167459SRichard Henderson     if (is_tc) {
1342269ca0a9SRichard Henderson         gen_tc(ctx, &cond);
1343b2167459SRichard Henderson     }
1344b2167459SRichard Henderson 
1345b2167459SRichard Henderson     /* Write back the result.  */
1346b2167459SRichard Henderson     save_or_nullify(ctx, cpu_psw_cb, cb);
1347b2167459SRichard Henderson     save_or_nullify(ctx, cpu_psw_cb_msb, cb_msb);
1348b2167459SRichard Henderson     save_gpr(ctx, rt, dest);
1349b2167459SRichard Henderson 
1350b2167459SRichard Henderson     /* Install the new nullification.  */
1351b2167459SRichard Henderson     ctx->null_cond = cond;
1352b2167459SRichard Henderson }
1353b2167459SRichard Henderson 
do_sub_reg(DisasContext * ctx,arg_rrr_cf_d * a,bool is_tsv,bool is_b,bool is_tc)135463c427c6SRichard Henderson static bool do_sub_reg(DisasContext *ctx, arg_rrr_cf_d *a,
13550c982a28SRichard Henderson                        bool is_tsv, bool is_b, bool is_tc)
13560c982a28SRichard Henderson {
13576fd0c7bcSRichard Henderson     TCGv_i64 tcg_r1, tcg_r2;
13580c982a28SRichard Henderson 
13590c982a28SRichard Henderson     if (a->cf) {
13600c982a28SRichard Henderson         nullify_over(ctx);
13610c982a28SRichard Henderson     }
13620c982a28SRichard Henderson     tcg_r1 = load_gpr(ctx, a->r1);
13630c982a28SRichard Henderson     tcg_r2 = load_gpr(ctx, a->r2);
136463c427c6SRichard Henderson     do_sub(ctx, a->t, tcg_r1, tcg_r2, is_tsv, is_b, is_tc, a->cf, a->d);
13650c982a28SRichard Henderson     return nullify_end(ctx);
13660c982a28SRichard Henderson }
13670c982a28SRichard Henderson 
do_sub_imm(DisasContext * ctx,arg_rri_cf * a,bool is_tsv)13680588e061SRichard Henderson static bool do_sub_imm(DisasContext *ctx, arg_rri_cf *a, bool is_tsv)
13690588e061SRichard Henderson {
13706fd0c7bcSRichard Henderson     TCGv_i64 tcg_im, tcg_r2;
13710588e061SRichard Henderson 
13720588e061SRichard Henderson     if (a->cf) {
13730588e061SRichard Henderson         nullify_over(ctx);
13740588e061SRichard Henderson     }
13756fd0c7bcSRichard Henderson     tcg_im = tcg_constant_i64(a->i);
13760588e061SRichard Henderson     tcg_r2 = load_gpr(ctx, a->r);
137763c427c6SRichard Henderson     /* All SUBI conditions are 32-bit. */
137863c427c6SRichard Henderson     do_sub(ctx, a->t, tcg_im, tcg_r2, is_tsv, 0, 0, a->cf, false);
13790588e061SRichard Henderson     return nullify_end(ctx);
13800588e061SRichard Henderson }
13810588e061SRichard Henderson 
do_cmpclr(DisasContext * ctx,unsigned rt,TCGv_i64 in1,TCGv_i64 in2,unsigned cf,bool d)13826fd0c7bcSRichard Henderson static void do_cmpclr(DisasContext *ctx, unsigned rt, TCGv_i64 in1,
13836fd0c7bcSRichard Henderson                       TCGv_i64 in2, unsigned cf, bool d)
1384b2167459SRichard Henderson {
13856fd0c7bcSRichard Henderson     TCGv_i64 dest, sv;
1386b2167459SRichard Henderson     DisasCond cond;
1387b2167459SRichard Henderson 
1388aac0f603SRichard Henderson     dest = tcg_temp_new_i64();
13896fd0c7bcSRichard Henderson     tcg_gen_sub_i64(dest, in1, in2);
1390b2167459SRichard Henderson 
1391b2167459SRichard Henderson     /* Compute signed overflow if required.  */
1392f764718dSRichard Henderson     sv = NULL;
1393b47a4a02SSven Schnelle     if (cond_need_sv(cf >> 1)) {
1394b2167459SRichard Henderson         sv = do_sub_sv(ctx, dest, in1, in2);
1395b2167459SRichard Henderson     }
1396b2167459SRichard Henderson 
1397b2167459SRichard Henderson     /* Form the condition for the compare.  */
13984fe9533aSRichard Henderson     cond = do_sub_cond(ctx, cf, d, dest, in1, in2, sv);
1399b2167459SRichard Henderson 
1400b2167459SRichard Henderson     /* Clear.  */
14016fd0c7bcSRichard Henderson     tcg_gen_movi_i64(dest, 0);
1402b2167459SRichard Henderson     save_gpr(ctx, rt, dest);
1403b2167459SRichard Henderson 
1404b2167459SRichard Henderson     /* Install the new nullification.  */
1405b2167459SRichard Henderson     ctx->null_cond = cond;
1406b2167459SRichard Henderson }
1407b2167459SRichard Henderson 
do_log(DisasContext * ctx,unsigned rt,TCGv_i64 in1,TCGv_i64 in2,unsigned cf,bool d,void (* fn)(TCGv_i64,TCGv_i64,TCGv_i64))14086fd0c7bcSRichard Henderson static void do_log(DisasContext *ctx, unsigned rt, TCGv_i64 in1,
14096fd0c7bcSRichard Henderson                    TCGv_i64 in2, unsigned cf, bool d,
14106fd0c7bcSRichard Henderson                    void (*fn)(TCGv_i64, TCGv_i64, TCGv_i64))
1411b2167459SRichard Henderson {
14126fd0c7bcSRichard Henderson     TCGv_i64 dest = dest_gpr(ctx, rt);
1413b2167459SRichard Henderson 
1414b2167459SRichard Henderson     /* Perform the operation, and writeback.  */
1415b2167459SRichard Henderson     fn(dest, in1, in2);
1416b2167459SRichard Henderson     save_gpr(ctx, rt, dest);
1417b2167459SRichard Henderson 
1418b2167459SRichard Henderson     /* Install the new nullification.  */
1419b5af8423SRichard Henderson     ctx->null_cond = do_log_cond(ctx, cf, d, dest);
1420b2167459SRichard Henderson }
1421b2167459SRichard Henderson 
do_log_reg(DisasContext * ctx,arg_rrr_cf_d * a,void (* fn)(TCGv_i64,TCGv_i64,TCGv_i64))1422fa8e3bedSRichard Henderson static bool do_log_reg(DisasContext *ctx, arg_rrr_cf_d *a,
14236fd0c7bcSRichard Henderson                        void (*fn)(TCGv_i64, TCGv_i64, TCGv_i64))
14240c982a28SRichard Henderson {
14256fd0c7bcSRichard Henderson     TCGv_i64 tcg_r1, tcg_r2;
14260c982a28SRichard Henderson 
14270c982a28SRichard Henderson     if (a->cf) {
14280c982a28SRichard Henderson         nullify_over(ctx);
14290c982a28SRichard Henderson     }
14300c982a28SRichard Henderson     tcg_r1 = load_gpr(ctx, a->r1);
14310c982a28SRichard Henderson     tcg_r2 = load_gpr(ctx, a->r2);
1432fa8e3bedSRichard Henderson     do_log(ctx, a->t, tcg_r1, tcg_r2, a->cf, a->d, fn);
14330c982a28SRichard Henderson     return nullify_end(ctx);
14340c982a28SRichard Henderson }
14350c982a28SRichard Henderson 
do_unit_addsub(DisasContext * ctx,unsigned rt,TCGv_i64 in1,TCGv_i64 in2,unsigned cf,bool d,bool is_tc,bool is_add)143646bb3d46SRichard Henderson static void do_unit_addsub(DisasContext *ctx, unsigned rt, TCGv_i64 in1,
143746bb3d46SRichard Henderson                            TCGv_i64 in2, unsigned cf, bool d,
143846bb3d46SRichard Henderson                            bool is_tc, bool is_add)
1439b2167459SRichard Henderson {
144046bb3d46SRichard Henderson     TCGv_i64 dest = tcg_temp_new_i64();
144146bb3d46SRichard Henderson     uint64_t test_cb = 0;
1442b2167459SRichard Henderson     DisasCond cond;
1443b2167459SRichard Henderson 
144446bb3d46SRichard Henderson     /* Select which carry-out bits to test. */
144546bb3d46SRichard Henderson     switch (cf >> 1) {
144646bb3d46SRichard Henderson     case 4: /* NDC / SDC -- 4-bit carries */
144746bb3d46SRichard Henderson         test_cb = dup_const(MO_8, 0x88);
144846bb3d46SRichard Henderson         break;
144946bb3d46SRichard Henderson     case 5: /* NWC / SWC -- 32-bit carries */
145046bb3d46SRichard Henderson         if (d) {
145146bb3d46SRichard Henderson             test_cb = dup_const(MO_32, INT32_MIN);
1452b2167459SRichard Henderson         } else {
145346bb3d46SRichard Henderson             cf &= 1; /* undefined -- map to never/always */
145446bb3d46SRichard Henderson         }
145546bb3d46SRichard Henderson         break;
145646bb3d46SRichard Henderson     case 6: /* NBC / SBC -- 8-bit carries */
145746bb3d46SRichard Henderson         test_cb = dup_const(MO_8, INT8_MIN);
145846bb3d46SRichard Henderson         break;
145946bb3d46SRichard Henderson     case 7: /* NHC / SHC -- 16-bit carries */
146046bb3d46SRichard Henderson         test_cb = dup_const(MO_16, INT16_MIN);
146146bb3d46SRichard Henderson         break;
146246bb3d46SRichard Henderson     }
146346bb3d46SRichard Henderson     if (!d) {
146446bb3d46SRichard Henderson         test_cb = (uint32_t)test_cb;
146546bb3d46SRichard Henderson     }
1466b2167459SRichard Henderson 
146746bb3d46SRichard Henderson     if (!test_cb) {
146846bb3d46SRichard Henderson         /* No need to compute carries if we don't need to test them. */
146946bb3d46SRichard Henderson         if (is_add) {
147046bb3d46SRichard Henderson             tcg_gen_add_i64(dest, in1, in2);
147146bb3d46SRichard Henderson         } else {
147246bb3d46SRichard Henderson             tcg_gen_sub_i64(dest, in1, in2);
147346bb3d46SRichard Henderson         }
147446bb3d46SRichard Henderson         cond = do_unit_zero_cond(cf, d, dest);
147546bb3d46SRichard Henderson     } else {
147646bb3d46SRichard Henderson         TCGv_i64 cb = tcg_temp_new_i64();
147746bb3d46SRichard Henderson 
147846bb3d46SRichard Henderson         if (d) {
147946bb3d46SRichard Henderson             TCGv_i64 cb_msb = tcg_temp_new_i64();
148046bb3d46SRichard Henderson             if (is_add) {
148146bb3d46SRichard Henderson                 tcg_gen_add2_i64(dest, cb_msb, in1, ctx->zero, in2, ctx->zero);
148246bb3d46SRichard Henderson                 tcg_gen_xor_i64(cb, in1, in2);
148346bb3d46SRichard Henderson             } else {
148446bb3d46SRichard Henderson                 /* See do_sub, !is_b. */
148546bb3d46SRichard Henderson                 TCGv_i64 one = tcg_constant_i64(1);
148646bb3d46SRichard Henderson                 tcg_gen_sub2_i64(dest, cb_msb, in1, one, in2, ctx->zero);
148746bb3d46SRichard Henderson                 tcg_gen_eqv_i64(cb, in1, in2);
148846bb3d46SRichard Henderson             }
148946bb3d46SRichard Henderson             tcg_gen_xor_i64(cb, cb, dest);
149046bb3d46SRichard Henderson             tcg_gen_extract2_i64(cb, cb, cb_msb, 1);
149146bb3d46SRichard Henderson         } else {
149246bb3d46SRichard Henderson             if (is_add) {
149346bb3d46SRichard Henderson                 tcg_gen_add_i64(dest, in1, in2);
149446bb3d46SRichard Henderson                 tcg_gen_xor_i64(cb, in1, in2);
149546bb3d46SRichard Henderson             } else {
149646bb3d46SRichard Henderson                 tcg_gen_sub_i64(dest, in1, in2);
149746bb3d46SRichard Henderson                 tcg_gen_eqv_i64(cb, in1, in2);
149846bb3d46SRichard Henderson             }
149946bb3d46SRichard Henderson             tcg_gen_xor_i64(cb, cb, dest);
150046bb3d46SRichard Henderson             tcg_gen_shri_i64(cb, cb, 1);
150146bb3d46SRichard Henderson         }
150246bb3d46SRichard Henderson 
15033289ea0eSRichard Henderson         cond = cond_make_ti(cf & 1 ? TCG_COND_TSTEQ : TCG_COND_TSTNE,
15043289ea0eSRichard Henderson                             cb, test_cb);
150546bb3d46SRichard Henderson     }
1506b2167459SRichard Henderson 
1507b2167459SRichard Henderson     if (is_tc) {
1508269ca0a9SRichard Henderson         gen_tc(ctx, &cond);
1509b2167459SRichard Henderson     }
1510b2167459SRichard Henderson     save_gpr(ctx, rt, dest);
1511b2167459SRichard Henderson 
1512b2167459SRichard Henderson     ctx->null_cond = cond;
1513b2167459SRichard Henderson }
1514b2167459SRichard Henderson 
151586f8d05fSRichard Henderson #ifndef CONFIG_USER_ONLY
15168d6ae7fbSRichard Henderson /* The "normal" usage is SP >= 0, wherein SP == 0 selects the space
15178d6ae7fbSRichard Henderson    from the top 2 bits of the base register.  There are a few system
15188d6ae7fbSRichard Henderson    instructions that have a 3-bit space specifier, for which SR0 is
15198d6ae7fbSRichard Henderson    not special.  To handle this, pass ~SP.  */
space_select(DisasContext * ctx,int sp,TCGv_i64 base)15206fd0c7bcSRichard Henderson static TCGv_i64 space_select(DisasContext *ctx, int sp, TCGv_i64 base)
152186f8d05fSRichard Henderson {
152286f8d05fSRichard Henderson     TCGv_ptr ptr;
15236fd0c7bcSRichard Henderson     TCGv_i64 tmp;
152486f8d05fSRichard Henderson     TCGv_i64 spc;
152586f8d05fSRichard Henderson 
152686f8d05fSRichard Henderson     if (sp != 0) {
15278d6ae7fbSRichard Henderson         if (sp < 0) {
15288d6ae7fbSRichard Henderson             sp = ~sp;
15298d6ae7fbSRichard Henderson         }
15306fd0c7bcSRichard Henderson         spc = tcg_temp_new_i64();
15318d6ae7fbSRichard Henderson         load_spr(ctx, spc, sp);
15328d6ae7fbSRichard Henderson         return spc;
153386f8d05fSRichard Henderson     }
1534494737b7SRichard Henderson     if (ctx->tb_flags & TB_FLAG_SR_SAME) {
1535494737b7SRichard Henderson         return cpu_srH;
1536494737b7SRichard Henderson     }
153786f8d05fSRichard Henderson 
153886f8d05fSRichard Henderson     ptr = tcg_temp_new_ptr();
1539aac0f603SRichard Henderson     tmp = tcg_temp_new_i64();
15406fd0c7bcSRichard Henderson     spc = tcg_temp_new_i64();
154186f8d05fSRichard Henderson 
1542698240d1SRichard Henderson     /* Extract top 2 bits of the address, shift left 3 for uint64_t index. */
15436fd0c7bcSRichard Henderson     tcg_gen_shri_i64(tmp, base, (ctx->tb_flags & PSW_W ? 64 : 32) - 5);
15446fd0c7bcSRichard Henderson     tcg_gen_andi_i64(tmp, tmp, 030);
15456fd0c7bcSRichard Henderson     tcg_gen_trunc_i64_ptr(ptr, tmp);
154686f8d05fSRichard Henderson 
1547ad75a51eSRichard Henderson     tcg_gen_add_ptr(ptr, ptr, tcg_env);
154886f8d05fSRichard Henderson     tcg_gen_ld_i64(spc, ptr, offsetof(CPUHPPAState, sr[4]));
154986f8d05fSRichard Henderson 
155086f8d05fSRichard Henderson     return spc;
155186f8d05fSRichard Henderson }
155286f8d05fSRichard Henderson #endif
155386f8d05fSRichard Henderson 
form_gva(DisasContext * ctx,TCGv_i64 * pgva,TCGv_i64 * pofs,unsigned rb,unsigned rx,int scale,int64_t disp,unsigned sp,int modify,bool is_phys)15546fd0c7bcSRichard Henderson static void form_gva(DisasContext *ctx, TCGv_i64 *pgva, TCGv_i64 *pofs,
1555c53e401eSRichard Henderson                      unsigned rb, unsigned rx, int scale, int64_t disp,
155686f8d05fSRichard Henderson                      unsigned sp, int modify, bool is_phys)
155786f8d05fSRichard Henderson {
15586fd0c7bcSRichard Henderson     TCGv_i64 base = load_gpr(ctx, rb);
15596fd0c7bcSRichard Henderson     TCGv_i64 ofs;
15606fd0c7bcSRichard Henderson     TCGv_i64 addr;
156186f8d05fSRichard Henderson 
1562f5b5c857SRichard Henderson     set_insn_breg(ctx, rb);
1563f5b5c857SRichard Henderson 
156486f8d05fSRichard Henderson     /* Note that RX is mutually exclusive with DISP.  */
156586f8d05fSRichard Henderson     if (rx) {
1566aac0f603SRichard Henderson         ofs = tcg_temp_new_i64();
15676fd0c7bcSRichard Henderson         tcg_gen_shli_i64(ofs, cpu_gr[rx], scale);
15686fd0c7bcSRichard Henderson         tcg_gen_add_i64(ofs, ofs, base);
156986f8d05fSRichard Henderson     } else if (disp || modify) {
1570aac0f603SRichard Henderson         ofs = tcg_temp_new_i64();
15716fd0c7bcSRichard Henderson         tcg_gen_addi_i64(ofs, base, disp);
157286f8d05fSRichard Henderson     } else {
157386f8d05fSRichard Henderson         ofs = base;
157486f8d05fSRichard Henderson     }
157586f8d05fSRichard Henderson 
157686f8d05fSRichard Henderson     *pofs = ofs;
15776fd0c7bcSRichard Henderson     *pgva = addr = tcg_temp_new_i64();
15787d50b696SSven Schnelle     tcg_gen_andi_i64(addr, modify <= 0 ? ofs : base,
15797d50b696SSven Schnelle                      gva_offset_mask(ctx->tb_flags));
1580698240d1SRichard Henderson #ifndef CONFIG_USER_ONLY
158186f8d05fSRichard Henderson     if (!is_phys) {
1582d265360fSRichard Henderson         tcg_gen_or_i64(addr, addr, space_select(ctx, sp, base));
158386f8d05fSRichard Henderson     }
158486f8d05fSRichard Henderson #endif
158586f8d05fSRichard Henderson }
158686f8d05fSRichard Henderson 
158796d6407fSRichard Henderson /* Emit a memory load.  The modify parameter should be
158896d6407fSRichard Henderson  * < 0 for pre-modify,
158996d6407fSRichard Henderson  * > 0 for post-modify,
159096d6407fSRichard Henderson  * = 0 for no base register update.
159196d6407fSRichard Henderson  */
do_load_32(DisasContext * ctx,TCGv_i32 dest,unsigned rb,unsigned rx,int scale,int64_t disp,unsigned sp,int modify,MemOp mop)159296d6407fSRichard Henderson static void do_load_32(DisasContext *ctx, TCGv_i32 dest, unsigned rb,
1593c53e401eSRichard Henderson                        unsigned rx, int scale, int64_t disp,
159414776ab5STony Nguyen                        unsigned sp, int modify, MemOp mop)
159596d6407fSRichard Henderson {
15966fd0c7bcSRichard Henderson     TCGv_i64 ofs;
15976fd0c7bcSRichard Henderson     TCGv_i64 addr;
159896d6407fSRichard Henderson 
159996d6407fSRichard Henderson     /* Caller uses nullify_over/nullify_end.  */
160096d6407fSRichard Henderson     assert(ctx->null_cond.c == TCG_COND_NEVER);
160196d6407fSRichard Henderson 
160286f8d05fSRichard Henderson     form_gva(ctx, &addr, &ofs, rb, rx, scale, disp, sp, modify,
160317fe594cSRichard Henderson              MMU_DISABLED(ctx));
1604c1f55d97SRichard Henderson     tcg_gen_qemu_ld_i32(dest, addr, ctx->mmu_idx, mop | UNALIGN(ctx));
160586f8d05fSRichard Henderson     if (modify) {
160686f8d05fSRichard Henderson         save_gpr(ctx, rb, ofs);
160796d6407fSRichard Henderson     }
160896d6407fSRichard Henderson }
160996d6407fSRichard Henderson 
do_load_64(DisasContext * ctx,TCGv_i64 dest,unsigned rb,unsigned rx,int scale,int64_t disp,unsigned sp,int modify,MemOp mop)161096d6407fSRichard Henderson static void do_load_64(DisasContext *ctx, TCGv_i64 dest, unsigned rb,
1611c53e401eSRichard Henderson                        unsigned rx, int scale, int64_t disp,
161214776ab5STony Nguyen                        unsigned sp, int modify, MemOp mop)
161396d6407fSRichard Henderson {
16146fd0c7bcSRichard Henderson     TCGv_i64 ofs;
16156fd0c7bcSRichard Henderson     TCGv_i64 addr;
161696d6407fSRichard Henderson 
161796d6407fSRichard Henderson     /* Caller uses nullify_over/nullify_end.  */
161896d6407fSRichard Henderson     assert(ctx->null_cond.c == TCG_COND_NEVER);
161996d6407fSRichard Henderson 
162086f8d05fSRichard Henderson     form_gva(ctx, &addr, &ofs, rb, rx, scale, disp, sp, modify,
162117fe594cSRichard Henderson              MMU_DISABLED(ctx));
1622217d1a5eSRichard Henderson     tcg_gen_qemu_ld_i64(dest, addr, ctx->mmu_idx, mop | UNALIGN(ctx));
162386f8d05fSRichard Henderson     if (modify) {
162486f8d05fSRichard Henderson         save_gpr(ctx, rb, ofs);
162596d6407fSRichard Henderson     }
162696d6407fSRichard Henderson }
162796d6407fSRichard Henderson 
do_store_32(DisasContext * ctx,TCGv_i32 src,unsigned rb,unsigned rx,int scale,int64_t disp,unsigned sp,int modify,MemOp mop)162896d6407fSRichard Henderson static void do_store_32(DisasContext *ctx, TCGv_i32 src, unsigned rb,
1629c53e401eSRichard Henderson                         unsigned rx, int scale, int64_t disp,
163014776ab5STony Nguyen                         unsigned sp, int modify, MemOp mop)
163196d6407fSRichard Henderson {
16326fd0c7bcSRichard Henderson     TCGv_i64 ofs;
16336fd0c7bcSRichard Henderson     TCGv_i64 addr;
163496d6407fSRichard Henderson 
163596d6407fSRichard Henderson     /* Caller uses nullify_over/nullify_end.  */
163696d6407fSRichard Henderson     assert(ctx->null_cond.c == TCG_COND_NEVER);
163796d6407fSRichard Henderson 
163886f8d05fSRichard Henderson     form_gva(ctx, &addr, &ofs, rb, rx, scale, disp, sp, modify,
163917fe594cSRichard Henderson              MMU_DISABLED(ctx));
1640217d1a5eSRichard Henderson     tcg_gen_qemu_st_i32(src, addr, ctx->mmu_idx, mop | UNALIGN(ctx));
164186f8d05fSRichard Henderson     if (modify) {
164286f8d05fSRichard Henderson         save_gpr(ctx, rb, ofs);
164396d6407fSRichard Henderson     }
164496d6407fSRichard Henderson }
164596d6407fSRichard Henderson 
do_store_64(DisasContext * ctx,TCGv_i64 src,unsigned rb,unsigned rx,int scale,int64_t disp,unsigned sp,int modify,MemOp mop)164696d6407fSRichard Henderson static void do_store_64(DisasContext *ctx, TCGv_i64 src, unsigned rb,
1647c53e401eSRichard Henderson                         unsigned rx, int scale, int64_t disp,
164814776ab5STony Nguyen                         unsigned sp, int modify, MemOp mop)
164996d6407fSRichard Henderson {
16506fd0c7bcSRichard Henderson     TCGv_i64 ofs;
16516fd0c7bcSRichard Henderson     TCGv_i64 addr;
165296d6407fSRichard Henderson 
165396d6407fSRichard Henderson     /* Caller uses nullify_over/nullify_end.  */
165496d6407fSRichard Henderson     assert(ctx->null_cond.c == TCG_COND_NEVER);
165596d6407fSRichard Henderson 
165686f8d05fSRichard Henderson     form_gva(ctx, &addr, &ofs, rb, rx, scale, disp, sp, modify,
165717fe594cSRichard Henderson              MMU_DISABLED(ctx));
1658217d1a5eSRichard Henderson     tcg_gen_qemu_st_i64(src, addr, ctx->mmu_idx, mop | UNALIGN(ctx));
165986f8d05fSRichard Henderson     if (modify) {
166086f8d05fSRichard Henderson         save_gpr(ctx, rb, ofs);
166196d6407fSRichard Henderson     }
166296d6407fSRichard Henderson }
166396d6407fSRichard Henderson 
do_load(DisasContext * ctx,unsigned rt,unsigned rb,unsigned rx,int scale,int64_t disp,unsigned sp,int modify,MemOp mop)16641cd012a5SRichard Henderson static bool do_load(DisasContext *ctx, unsigned rt, unsigned rb,
1665c53e401eSRichard Henderson                     unsigned rx, int scale, int64_t disp,
166614776ab5STony Nguyen                     unsigned sp, int modify, MemOp mop)
166796d6407fSRichard Henderson {
16686fd0c7bcSRichard Henderson     TCGv_i64 dest;
166996d6407fSRichard Henderson 
167096d6407fSRichard Henderson     nullify_over(ctx);
167196d6407fSRichard Henderson 
167296d6407fSRichard Henderson     if (modify == 0) {
167396d6407fSRichard Henderson         /* No base register update.  */
167496d6407fSRichard Henderson         dest = dest_gpr(ctx, rt);
167596d6407fSRichard Henderson     } else {
167696d6407fSRichard Henderson         /* Make sure if RT == RB, we see the result of the load.  */
1677aac0f603SRichard Henderson         dest = tcg_temp_new_i64();
167896d6407fSRichard Henderson     }
16796fd0c7bcSRichard Henderson     do_load_64(ctx, dest, rb, rx, scale, disp, sp, modify, mop);
168096d6407fSRichard Henderson     save_gpr(ctx, rt, dest);
168196d6407fSRichard Henderson 
16821cd012a5SRichard Henderson     return nullify_end(ctx);
168396d6407fSRichard Henderson }
168496d6407fSRichard Henderson 
do_floadw(DisasContext * ctx,unsigned rt,unsigned rb,unsigned rx,int scale,int64_t disp,unsigned sp,int modify)1685740038d7SRichard Henderson static bool do_floadw(DisasContext *ctx, unsigned rt, unsigned rb,
1686c53e401eSRichard Henderson                       unsigned rx, int scale, int64_t disp,
168786f8d05fSRichard Henderson                       unsigned sp, int modify)
168896d6407fSRichard Henderson {
168996d6407fSRichard Henderson     TCGv_i32 tmp;
169096d6407fSRichard Henderson 
169196d6407fSRichard Henderson     nullify_over(ctx);
169296d6407fSRichard Henderson 
169396d6407fSRichard Henderson     tmp = tcg_temp_new_i32();
169486f8d05fSRichard Henderson     do_load_32(ctx, tmp, rb, rx, scale, disp, sp, modify, MO_TEUL);
169596d6407fSRichard Henderson     save_frw_i32(rt, tmp);
169696d6407fSRichard Henderson 
169796d6407fSRichard Henderson     if (rt == 0) {
1698ad75a51eSRichard Henderson         gen_helper_loaded_fr0(tcg_env);
169996d6407fSRichard Henderson     }
170096d6407fSRichard Henderson 
1701740038d7SRichard Henderson     return nullify_end(ctx);
170296d6407fSRichard Henderson }
170396d6407fSRichard Henderson 
trans_fldw(DisasContext * ctx,arg_ldst * a)1704740038d7SRichard Henderson static bool trans_fldw(DisasContext *ctx, arg_ldst *a)
1705740038d7SRichard Henderson {
1706740038d7SRichard Henderson     return do_floadw(ctx, a->t, a->b, a->x, a->scale ? 2 : 0,
1707740038d7SRichard Henderson                      a->disp, a->sp, a->m);
1708740038d7SRichard Henderson }
1709740038d7SRichard Henderson 
do_floadd(DisasContext * ctx,unsigned rt,unsigned rb,unsigned rx,int scale,int64_t disp,unsigned sp,int modify)1710740038d7SRichard Henderson static bool do_floadd(DisasContext *ctx, unsigned rt, unsigned rb,
1711c53e401eSRichard Henderson                       unsigned rx, int scale, int64_t disp,
171286f8d05fSRichard Henderson                       unsigned sp, int modify)
171396d6407fSRichard Henderson {
171496d6407fSRichard Henderson     TCGv_i64 tmp;
171596d6407fSRichard Henderson 
171696d6407fSRichard Henderson     nullify_over(ctx);
171796d6407fSRichard Henderson 
171896d6407fSRichard Henderson     tmp = tcg_temp_new_i64();
1719fc313c64SFrédéric Pétrot     do_load_64(ctx, tmp, rb, rx, scale, disp, sp, modify, MO_TEUQ);
172096d6407fSRichard Henderson     save_frd(rt, tmp);
172196d6407fSRichard Henderson 
172296d6407fSRichard Henderson     if (rt == 0) {
1723ad75a51eSRichard Henderson         gen_helper_loaded_fr0(tcg_env);
172496d6407fSRichard Henderson     }
172596d6407fSRichard Henderson 
1726740038d7SRichard Henderson     return nullify_end(ctx);
1727740038d7SRichard Henderson }
1728740038d7SRichard Henderson 
trans_fldd(DisasContext * ctx,arg_ldst * a)1729740038d7SRichard Henderson static bool trans_fldd(DisasContext *ctx, arg_ldst *a)
1730740038d7SRichard Henderson {
1731740038d7SRichard Henderson     return do_floadd(ctx, a->t, a->b, a->x, a->scale ? 3 : 0,
1732740038d7SRichard Henderson                      a->disp, a->sp, a->m);
173396d6407fSRichard Henderson }
173496d6407fSRichard Henderson 
do_store(DisasContext * ctx,unsigned rt,unsigned rb,int64_t disp,unsigned sp,int modify,MemOp mop)17351cd012a5SRichard Henderson static bool do_store(DisasContext *ctx, unsigned rt, unsigned rb,
1736c53e401eSRichard Henderson                      int64_t disp, unsigned sp,
173714776ab5STony Nguyen                      int modify, MemOp mop)
173896d6407fSRichard Henderson {
173996d6407fSRichard Henderson     nullify_over(ctx);
17406fd0c7bcSRichard Henderson     do_store_64(ctx, load_gpr(ctx, rt), rb, 0, 0, disp, sp, modify, mop);
17411cd012a5SRichard Henderson     return nullify_end(ctx);
174296d6407fSRichard Henderson }
174396d6407fSRichard Henderson 
do_fstorew(DisasContext * ctx,unsigned rt,unsigned rb,unsigned rx,int scale,int64_t disp,unsigned sp,int modify)1744740038d7SRichard Henderson static bool do_fstorew(DisasContext *ctx, unsigned rt, unsigned rb,
1745c53e401eSRichard Henderson                        unsigned rx, int scale, int64_t disp,
174686f8d05fSRichard Henderson                        unsigned sp, int modify)
174796d6407fSRichard Henderson {
174896d6407fSRichard Henderson     TCGv_i32 tmp;
174996d6407fSRichard Henderson 
175096d6407fSRichard Henderson     nullify_over(ctx);
175196d6407fSRichard Henderson 
175296d6407fSRichard Henderson     tmp = load_frw_i32(rt);
175386f8d05fSRichard Henderson     do_store_32(ctx, tmp, rb, rx, scale, disp, sp, modify, MO_TEUL);
175496d6407fSRichard Henderson 
1755740038d7SRichard Henderson     return nullify_end(ctx);
175696d6407fSRichard Henderson }
175796d6407fSRichard Henderson 
trans_fstw(DisasContext * ctx,arg_ldst * a)1758740038d7SRichard Henderson static bool trans_fstw(DisasContext *ctx, arg_ldst *a)
1759740038d7SRichard Henderson {
1760740038d7SRichard Henderson     return do_fstorew(ctx, a->t, a->b, a->x, a->scale ? 2 : 0,
1761740038d7SRichard Henderson                       a->disp, a->sp, a->m);
1762740038d7SRichard Henderson }
1763740038d7SRichard Henderson 
do_fstored(DisasContext * ctx,unsigned rt,unsigned rb,unsigned rx,int scale,int64_t disp,unsigned sp,int modify)1764740038d7SRichard Henderson static bool do_fstored(DisasContext *ctx, unsigned rt, unsigned rb,
1765c53e401eSRichard Henderson                        unsigned rx, int scale, int64_t disp,
176686f8d05fSRichard Henderson                        unsigned sp, int modify)
176796d6407fSRichard Henderson {
176896d6407fSRichard Henderson     TCGv_i64 tmp;
176996d6407fSRichard Henderson 
177096d6407fSRichard Henderson     nullify_over(ctx);
177196d6407fSRichard Henderson 
177296d6407fSRichard Henderson     tmp = load_frd(rt);
1773fc313c64SFrédéric Pétrot     do_store_64(ctx, tmp, rb, rx, scale, disp, sp, modify, MO_TEUQ);
177496d6407fSRichard Henderson 
1775740038d7SRichard Henderson     return nullify_end(ctx);
1776740038d7SRichard Henderson }
1777740038d7SRichard Henderson 
trans_fstd(DisasContext * ctx,arg_ldst * a)1778740038d7SRichard Henderson static bool trans_fstd(DisasContext *ctx, arg_ldst *a)
1779740038d7SRichard Henderson {
1780740038d7SRichard Henderson     return do_fstored(ctx, a->t, a->b, a->x, a->scale ? 3 : 0,
1781740038d7SRichard Henderson                       a->disp, a->sp, a->m);
178296d6407fSRichard Henderson }
178396d6407fSRichard Henderson 
do_fop_wew(DisasContext * ctx,unsigned rt,unsigned ra,void (* func)(TCGv_i32,TCGv_env,TCGv_i32))17841ca74648SRichard Henderson static bool do_fop_wew(DisasContext *ctx, unsigned rt, unsigned ra,
1785ebe9383cSRichard Henderson                        void (*func)(TCGv_i32, TCGv_env, TCGv_i32))
1786ebe9383cSRichard Henderson {
1787ebe9383cSRichard Henderson     TCGv_i32 tmp;
1788ebe9383cSRichard Henderson 
1789ebe9383cSRichard Henderson     nullify_over(ctx);
1790ebe9383cSRichard Henderson     tmp = load_frw0_i32(ra);
1791ebe9383cSRichard Henderson 
1792ad75a51eSRichard Henderson     func(tmp, tcg_env, tmp);
1793ebe9383cSRichard Henderson 
1794ebe9383cSRichard Henderson     save_frw_i32(rt, tmp);
17951ca74648SRichard Henderson     return nullify_end(ctx);
1796ebe9383cSRichard Henderson }
1797ebe9383cSRichard Henderson 
do_fop_wed(DisasContext * ctx,unsigned rt,unsigned ra,void (* func)(TCGv_i32,TCGv_env,TCGv_i64))17981ca74648SRichard Henderson static bool do_fop_wed(DisasContext *ctx, unsigned rt, unsigned ra,
1799ebe9383cSRichard Henderson                        void (*func)(TCGv_i32, TCGv_env, TCGv_i64))
1800ebe9383cSRichard Henderson {
1801ebe9383cSRichard Henderson     TCGv_i32 dst;
1802ebe9383cSRichard Henderson     TCGv_i64 src;
1803ebe9383cSRichard Henderson 
1804ebe9383cSRichard Henderson     nullify_over(ctx);
1805ebe9383cSRichard Henderson     src = load_frd(ra);
1806ebe9383cSRichard Henderson     dst = tcg_temp_new_i32();
1807ebe9383cSRichard Henderson 
1808ad75a51eSRichard Henderson     func(dst, tcg_env, src);
1809ebe9383cSRichard Henderson 
1810ebe9383cSRichard Henderson     save_frw_i32(rt, dst);
18111ca74648SRichard Henderson     return nullify_end(ctx);
1812ebe9383cSRichard Henderson }
1813ebe9383cSRichard Henderson 
do_fop_ded(DisasContext * ctx,unsigned rt,unsigned ra,void (* func)(TCGv_i64,TCGv_env,TCGv_i64))18141ca74648SRichard Henderson static bool do_fop_ded(DisasContext *ctx, unsigned rt, unsigned ra,
1815ebe9383cSRichard Henderson                        void (*func)(TCGv_i64, TCGv_env, TCGv_i64))
1816ebe9383cSRichard Henderson {
1817ebe9383cSRichard Henderson     TCGv_i64 tmp;
1818ebe9383cSRichard Henderson 
1819ebe9383cSRichard Henderson     nullify_over(ctx);
1820ebe9383cSRichard Henderson     tmp = load_frd0(ra);
1821ebe9383cSRichard Henderson 
1822ad75a51eSRichard Henderson     func(tmp, tcg_env, tmp);
1823ebe9383cSRichard Henderson 
1824ebe9383cSRichard Henderson     save_frd(rt, tmp);
18251ca74648SRichard Henderson     return nullify_end(ctx);
1826ebe9383cSRichard Henderson }
1827ebe9383cSRichard Henderson 
do_fop_dew(DisasContext * ctx,unsigned rt,unsigned ra,void (* func)(TCGv_i64,TCGv_env,TCGv_i32))18281ca74648SRichard Henderson static bool do_fop_dew(DisasContext *ctx, unsigned rt, unsigned ra,
1829ebe9383cSRichard Henderson                        void (*func)(TCGv_i64, TCGv_env, TCGv_i32))
1830ebe9383cSRichard Henderson {
1831ebe9383cSRichard Henderson     TCGv_i32 src;
1832ebe9383cSRichard Henderson     TCGv_i64 dst;
1833ebe9383cSRichard Henderson 
1834ebe9383cSRichard Henderson     nullify_over(ctx);
1835ebe9383cSRichard Henderson     src = load_frw0_i32(ra);
1836ebe9383cSRichard Henderson     dst = tcg_temp_new_i64();
1837ebe9383cSRichard Henderson 
1838ad75a51eSRichard Henderson     func(dst, tcg_env, src);
1839ebe9383cSRichard Henderson 
1840ebe9383cSRichard Henderson     save_frd(rt, dst);
18411ca74648SRichard Henderson     return nullify_end(ctx);
1842ebe9383cSRichard Henderson }
1843ebe9383cSRichard Henderson 
do_fop_weww(DisasContext * ctx,unsigned rt,unsigned ra,unsigned rb,void (* func)(TCGv_i32,TCGv_env,TCGv_i32,TCGv_i32))18441ca74648SRichard Henderson static bool do_fop_weww(DisasContext *ctx, unsigned rt,
1845ebe9383cSRichard Henderson                         unsigned ra, unsigned rb,
184631234768SRichard Henderson                         void (*func)(TCGv_i32, TCGv_env, TCGv_i32, TCGv_i32))
1847ebe9383cSRichard Henderson {
1848ebe9383cSRichard Henderson     TCGv_i32 a, b;
1849ebe9383cSRichard Henderson 
1850ebe9383cSRichard Henderson     nullify_over(ctx);
1851ebe9383cSRichard Henderson     a = load_frw0_i32(ra);
1852ebe9383cSRichard Henderson     b = load_frw0_i32(rb);
1853ebe9383cSRichard Henderson 
1854ad75a51eSRichard Henderson     func(a, tcg_env, a, b);
1855ebe9383cSRichard Henderson 
1856ebe9383cSRichard Henderson     save_frw_i32(rt, a);
18571ca74648SRichard Henderson     return nullify_end(ctx);
1858ebe9383cSRichard Henderson }
1859ebe9383cSRichard Henderson 
do_fop_dedd(DisasContext * ctx,unsigned rt,unsigned ra,unsigned rb,void (* func)(TCGv_i64,TCGv_env,TCGv_i64,TCGv_i64))18601ca74648SRichard Henderson static bool do_fop_dedd(DisasContext *ctx, unsigned rt,
1861ebe9383cSRichard Henderson                         unsigned ra, unsigned rb,
186231234768SRichard Henderson                         void (*func)(TCGv_i64, TCGv_env, TCGv_i64, TCGv_i64))
1863ebe9383cSRichard Henderson {
1864ebe9383cSRichard Henderson     TCGv_i64 a, b;
1865ebe9383cSRichard Henderson 
1866ebe9383cSRichard Henderson     nullify_over(ctx);
1867ebe9383cSRichard Henderson     a = load_frd0(ra);
1868ebe9383cSRichard Henderson     b = load_frd0(rb);
1869ebe9383cSRichard Henderson 
1870ad75a51eSRichard Henderson     func(a, tcg_env, a, b);
1871ebe9383cSRichard Henderson 
1872ebe9383cSRichard Henderson     save_frd(rt, a);
18731ca74648SRichard Henderson     return nullify_end(ctx);
1874ebe9383cSRichard Henderson }
1875ebe9383cSRichard Henderson 
187698cd9ca7SRichard Henderson /* Emit an unconditional branch to a direct target, which may or may not
187798cd9ca7SRichard Henderson    have already had nullification handled.  */
do_dbranch(DisasContext * ctx,int64_t disp,unsigned link,bool is_n)18782644f80bSRichard Henderson static bool do_dbranch(DisasContext *ctx, int64_t disp,
187998cd9ca7SRichard Henderson                        unsigned link, bool is_n)
188098cd9ca7SRichard Henderson {
1881bc921866SRichard Henderson     ctx->iaq_j = iaqe_branchi(ctx, disp);
18822644f80bSRichard Henderson 
188398cd9ca7SRichard Henderson     if (ctx->null_cond.c == TCG_COND_NEVER && ctx->null_lab == NULL) {
188443541db0SRichard Henderson         install_link(ctx, link, false);
188598cd9ca7SRichard Henderson         if (is_n) {
1886d08ad0e0SRichard Henderson             if (use_nullify_skip(ctx)) {
1887d08ad0e0SRichard Henderson                 nullify_set(ctx, 0);
1888d27fe7c3SRichard Henderson                 store_psw_xb(ctx, 0);
1889bc921866SRichard Henderson                 gen_goto_tb(ctx, 0, &ctx->iaq_j, NULL);
1890d08ad0e0SRichard Henderson                 ctx->base.is_jmp = DISAS_NORETURN;
1891d08ad0e0SRichard Henderson                 return true;
1892d08ad0e0SRichard Henderson             }
189398cd9ca7SRichard Henderson             ctx->null_cond.c = TCG_COND_ALWAYS;
189498cd9ca7SRichard Henderson         }
1895bc921866SRichard Henderson         ctx->iaq_n = &ctx->iaq_j;
1896d27fe7c3SRichard Henderson         ctx->psw_b_next = true;
189798cd9ca7SRichard Henderson     } else {
189898cd9ca7SRichard Henderson         nullify_over(ctx);
189998cd9ca7SRichard Henderson 
190043541db0SRichard Henderson         install_link(ctx, link, false);
190198cd9ca7SRichard Henderson         if (is_n && use_nullify_skip(ctx)) {
190298cd9ca7SRichard Henderson             nullify_set(ctx, 0);
1903d27fe7c3SRichard Henderson             store_psw_xb(ctx, 0);
1904bc921866SRichard Henderson             gen_goto_tb(ctx, 0, &ctx->iaq_j, NULL);
190598cd9ca7SRichard Henderson         } else {
190698cd9ca7SRichard Henderson             nullify_set(ctx, is_n);
1907d27fe7c3SRichard Henderson             store_psw_xb(ctx, PSW_B);
1908bc921866SRichard Henderson             gen_goto_tb(ctx, 0, &ctx->iaq_b, &ctx->iaq_j);
190998cd9ca7SRichard Henderson         }
191031234768SRichard Henderson         nullify_end(ctx);
191198cd9ca7SRichard Henderson 
191298cd9ca7SRichard Henderson         nullify_set(ctx, 0);
1913d27fe7c3SRichard Henderson         store_psw_xb(ctx, 0);
1914bc921866SRichard Henderson         gen_goto_tb(ctx, 1, &ctx->iaq_b, NULL);
191531234768SRichard Henderson         ctx->base.is_jmp = DISAS_NORETURN;
191698cd9ca7SRichard Henderson     }
191701afb7beSRichard Henderson     return true;
191898cd9ca7SRichard Henderson }
191998cd9ca7SRichard Henderson 
192098cd9ca7SRichard Henderson /* Emit a conditional branch to a direct target.  If the branch itself
192198cd9ca7SRichard Henderson    is nullified, we should have already used nullify_over.  */
do_cbranch(DisasContext * ctx,int64_t disp,bool is_n,DisasCond * cond)1922c53e401eSRichard Henderson static bool do_cbranch(DisasContext *ctx, int64_t disp, bool is_n,
192398cd9ca7SRichard Henderson                        DisasCond *cond)
192498cd9ca7SRichard Henderson {
1925bc921866SRichard Henderson     DisasIAQE next;
192698cd9ca7SRichard Henderson     TCGLabel *taken = NULL;
192798cd9ca7SRichard Henderson     TCGCond c = cond->c;
192898cd9ca7SRichard Henderson     bool n;
192998cd9ca7SRichard Henderson 
193098cd9ca7SRichard Henderson     assert(ctx->null_cond.c == TCG_COND_NEVER);
193198cd9ca7SRichard Henderson 
193298cd9ca7SRichard Henderson     /* Handle TRUE and NEVER as direct branches.  */
193398cd9ca7SRichard Henderson     if (c == TCG_COND_ALWAYS) {
19342644f80bSRichard Henderson         return do_dbranch(ctx, disp, 0, is_n && disp >= 0);
193598cd9ca7SRichard Henderson     }
193698cd9ca7SRichard Henderson 
193798cd9ca7SRichard Henderson     taken = gen_new_label();
19386fd0c7bcSRichard Henderson     tcg_gen_brcond_i64(c, cond->a0, cond->a1, taken);
193998cd9ca7SRichard Henderson 
194098cd9ca7SRichard Henderson     /* Not taken: Condition not satisfied; nullify on backward branches. */
194198cd9ca7SRichard Henderson     n = is_n && disp < 0;
194298cd9ca7SRichard Henderson     if (n && use_nullify_skip(ctx)) {
194398cd9ca7SRichard Henderson         nullify_set(ctx, 0);
1944d27fe7c3SRichard Henderson         store_psw_xb(ctx, 0);
1945bc921866SRichard Henderson         next = iaqe_incr(&ctx->iaq_b, 4);
1946bc921866SRichard Henderson         gen_goto_tb(ctx, 0, &next, NULL);
194798cd9ca7SRichard Henderson     } else {
194898cd9ca7SRichard Henderson         if (!n && ctx->null_lab) {
194998cd9ca7SRichard Henderson             gen_set_label(ctx->null_lab);
195098cd9ca7SRichard Henderson             ctx->null_lab = NULL;
195198cd9ca7SRichard Henderson         }
195298cd9ca7SRichard Henderson         nullify_set(ctx, n);
1953d27fe7c3SRichard Henderson         store_psw_xb(ctx, 0);
1954bc921866SRichard Henderson         gen_goto_tb(ctx, 0, &ctx->iaq_b, NULL);
195598cd9ca7SRichard Henderson     }
195698cd9ca7SRichard Henderson 
195798cd9ca7SRichard Henderson     gen_set_label(taken);
195898cd9ca7SRichard Henderson 
195998cd9ca7SRichard Henderson     /* Taken: Condition satisfied; nullify on forward branches.  */
196098cd9ca7SRichard Henderson     n = is_n && disp >= 0;
1961bc921866SRichard Henderson 
1962bc921866SRichard Henderson     next = iaqe_branchi(ctx, disp);
196398cd9ca7SRichard Henderson     if (n && use_nullify_skip(ctx)) {
196498cd9ca7SRichard Henderson         nullify_set(ctx, 0);
1965d27fe7c3SRichard Henderson         store_psw_xb(ctx, 0);
1966bc921866SRichard Henderson         gen_goto_tb(ctx, 1, &next, NULL);
196798cd9ca7SRichard Henderson     } else {
196898cd9ca7SRichard Henderson         nullify_set(ctx, n);
1969d27fe7c3SRichard Henderson         store_psw_xb(ctx, PSW_B);
1970bc921866SRichard Henderson         gen_goto_tb(ctx, 1, &ctx->iaq_b, &next);
197198cd9ca7SRichard Henderson     }
197298cd9ca7SRichard Henderson 
197398cd9ca7SRichard Henderson     /* Not taken: the branch itself was nullified.  */
197498cd9ca7SRichard Henderson     if (ctx->null_lab) {
197598cd9ca7SRichard Henderson         gen_set_label(ctx->null_lab);
197698cd9ca7SRichard Henderson         ctx->null_lab = NULL;
197731234768SRichard Henderson         ctx->base.is_jmp = DISAS_IAQ_N_STALE;
197898cd9ca7SRichard Henderson     } else {
197931234768SRichard Henderson         ctx->base.is_jmp = DISAS_NORETURN;
198098cd9ca7SRichard Henderson     }
198101afb7beSRichard Henderson     return true;
198298cd9ca7SRichard Henderson }
198398cd9ca7SRichard Henderson 
1984bc921866SRichard Henderson /*
1985bc921866SRichard Henderson  * Emit an unconditional branch to an indirect target, in ctx->iaq_j.
1986bc921866SRichard Henderson  * This handles nullification of the branch itself.
1987bc921866SRichard Henderson  */
do_ibranch(DisasContext * ctx,unsigned link,bool with_sr0,bool is_n)1988bc921866SRichard Henderson static bool do_ibranch(DisasContext *ctx, unsigned link,
1989bc921866SRichard Henderson                        bool with_sr0, bool is_n)
199098cd9ca7SRichard Henderson {
1991d582c1faSRichard Henderson     if (ctx->null_cond.c == TCG_COND_NEVER && ctx->null_lab == NULL) {
1992019f4159SRichard Henderson         install_link(ctx, link, with_sr0);
199398cd9ca7SRichard Henderson         if (is_n) {
1994c301f34eSRichard Henderson             if (use_nullify_skip(ctx)) {
1995bc921866SRichard Henderson                 install_iaq_entries(ctx, &ctx->iaq_j, NULL);
1996c301f34eSRichard Henderson                 nullify_set(ctx, 0);
199731234768SRichard Henderson                 ctx->base.is_jmp = DISAS_IAQ_N_UPDATED;
199801afb7beSRichard Henderson                 return true;
1999c301f34eSRichard Henderson             }
200098cd9ca7SRichard Henderson             ctx->null_cond.c = TCG_COND_ALWAYS;
200198cd9ca7SRichard Henderson         }
2002bc921866SRichard Henderson         ctx->iaq_n = &ctx->iaq_j;
2003d27fe7c3SRichard Henderson         ctx->psw_b_next = true;
2004d582c1faSRichard Henderson         return true;
2005d582c1faSRichard Henderson     }
200698cd9ca7SRichard Henderson 
200798cd9ca7SRichard Henderson     nullify_over(ctx);
2008d582c1faSRichard Henderson 
2009019f4159SRichard Henderson     install_link(ctx, link, with_sr0);
2010d582c1faSRichard Henderson     if (is_n && use_nullify_skip(ctx)) {
2011bc921866SRichard Henderson         install_iaq_entries(ctx, &ctx->iaq_j, NULL);
2012d582c1faSRichard Henderson         nullify_set(ctx, 0);
2013d27fe7c3SRichard Henderson         store_psw_xb(ctx, 0);
2014d582c1faSRichard Henderson     } else {
2015bc921866SRichard Henderson         install_iaq_entries(ctx, &ctx->iaq_b, &ctx->iaq_j);
2016d582c1faSRichard Henderson         nullify_set(ctx, is_n);
2017d27fe7c3SRichard Henderson         store_psw_xb(ctx, PSW_B);
201898cd9ca7SRichard Henderson     }
2019d582c1faSRichard Henderson 
20207f11636dSEmilio G. Cota     tcg_gen_lookup_and_goto_ptr();
2021d582c1faSRichard Henderson     ctx->base.is_jmp = DISAS_NORETURN;
202201afb7beSRichard Henderson     return nullify_end(ctx);
202398cd9ca7SRichard Henderson }
202498cd9ca7SRichard Henderson 
2025660eefe1SRichard Henderson /* Implement
2026660eefe1SRichard Henderson  *    if (IAOQ_Front{30..31} < GR[b]{30..31})
2027660eefe1SRichard Henderson  *      IAOQ_Next{30..31} ← GR[b]{30..31};
2028660eefe1SRichard Henderson  *    else
2029660eefe1SRichard Henderson  *      IAOQ_Next{30..31} ← IAOQ_Front{30..31};
2030660eefe1SRichard Henderson  * which keeps the privilege level from being increased.
2031660eefe1SRichard Henderson  */
do_ibranch_priv(DisasContext * ctx,TCGv_i64 offset)20326fd0c7bcSRichard Henderson static TCGv_i64 do_ibranch_priv(DisasContext *ctx, TCGv_i64 offset)
2033660eefe1SRichard Henderson {
20341874e6c2SRichard Henderson     TCGv_i64 dest = tcg_temp_new_i64();
2035660eefe1SRichard Henderson     switch (ctx->privilege) {
2036660eefe1SRichard Henderson     case 0:
2037660eefe1SRichard Henderson         /* Privilege 0 is maximum and is allowed to decrease.  */
20381874e6c2SRichard Henderson         tcg_gen_mov_i64(dest, offset);
20391874e6c2SRichard Henderson         break;
2040660eefe1SRichard Henderson     case 3:
2041993119feSRichard Henderson         /* Privilege 3 is minimum and is never allowed to increase.  */
20426fd0c7bcSRichard Henderson         tcg_gen_ori_i64(dest, offset, 3);
2043660eefe1SRichard Henderson         break;
2044660eefe1SRichard Henderson     default:
20456fd0c7bcSRichard Henderson         tcg_gen_andi_i64(dest, offset, -4);
20466fd0c7bcSRichard Henderson         tcg_gen_ori_i64(dest, dest, ctx->privilege);
20470bb02029SRichard Henderson         tcg_gen_umax_i64(dest, dest, offset);
2048660eefe1SRichard Henderson         break;
2049660eefe1SRichard Henderson     }
2050660eefe1SRichard Henderson     return dest;
2051660eefe1SRichard Henderson }
2052660eefe1SRichard Henderson 
2053ba1d0b44SRichard Henderson #ifdef CONFIG_USER_ONLY
20547ad439dfSRichard Henderson /* On Linux, page zero is normally marked execute only + gateway.
20557ad439dfSRichard Henderson    Therefore normal read or write is supposed to fail, but specific
20567ad439dfSRichard Henderson    offsets have kernel code mapped to raise permissions to implement
20577ad439dfSRichard Henderson    system calls.  Handling this via an explicit check here, rather
20587ad439dfSRichard Henderson    in than the "be disp(sr2,r0)" instruction that probably sent us
20597ad439dfSRichard Henderson    here, is the easiest way to handle the branch delay slot on the
20607ad439dfSRichard Henderson    aforementioned BE.  */
do_page_zero(DisasContext * ctx)206131234768SRichard Henderson static void do_page_zero(DisasContext *ctx)
20627ad439dfSRichard Henderson {
20630d89cb7cSRichard Henderson     assert(ctx->iaq_f.disp == 0);
2064a0180973SRichard Henderson 
20657ad439dfSRichard Henderson     /* If by some means we get here with PSW[N]=1, that implies that
20667ad439dfSRichard Henderson        the B,GATE instruction would be skipped, and we'd fault on the
20678b81968cSMichael Tokarev        next insn within the privileged page.  */
20687ad439dfSRichard Henderson     switch (ctx->null_cond.c) {
20697ad439dfSRichard Henderson     case TCG_COND_NEVER:
20707ad439dfSRichard Henderson         break;
20717ad439dfSRichard Henderson     case TCG_COND_ALWAYS:
20726fd0c7bcSRichard Henderson         tcg_gen_movi_i64(cpu_psw_n, 0);
20737ad439dfSRichard Henderson         goto do_sigill;
20747ad439dfSRichard Henderson     default:
20757ad439dfSRichard Henderson         /* Since this is always the first (and only) insn within the
20767ad439dfSRichard Henderson            TB, we should know the state of PSW[N] from TB->FLAGS.  */
20777ad439dfSRichard Henderson         g_assert_not_reached();
20787ad439dfSRichard Henderson     }
20797ad439dfSRichard Henderson 
20805ae8adbbSRichard Henderson     /* If PSW[B] is set, the B,GATE insn would trap. */
20815ae8adbbSRichard Henderson     if (ctx->psw_xb & PSW_B) {
20827ad439dfSRichard Henderson         goto do_sigill;
20837ad439dfSRichard Henderson     }
20847ad439dfSRichard Henderson 
20850d89cb7cSRichard Henderson     switch (ctx->base.pc_first) {
20867ad439dfSRichard Henderson     case 0x00: /* Null pointer call */
20872986721dSRichard Henderson         gen_excp_1(EXCP_IMP);
208831234768SRichard Henderson         ctx->base.is_jmp = DISAS_NORETURN;
208931234768SRichard Henderson         break;
20907ad439dfSRichard Henderson 
20917ad439dfSRichard Henderson     case 0xb0: /* LWS */
20927ad439dfSRichard Henderson         gen_excp_1(EXCP_SYSCALL_LWS);
209331234768SRichard Henderson         ctx->base.is_jmp = DISAS_NORETURN;
209431234768SRichard Henderson         break;
20957ad439dfSRichard Henderson 
20967ad439dfSRichard Henderson     case 0xe0: /* SET_THREAD_POINTER */
2097bc921866SRichard Henderson         {
2098bc921866SRichard Henderson             DisasIAQE next = { .base = tcg_temp_new_i64() };
2099bc921866SRichard Henderson 
2100bc921866SRichard Henderson             tcg_gen_st_i64(cpu_gr[26], tcg_env,
2101bc921866SRichard Henderson                            offsetof(CPUHPPAState, cr[27]));
21023c13b0ffSRichard Henderson             tcg_gen_ori_i64(next.base, cpu_gr[31], PRIV_USER);
2103bc921866SRichard Henderson             install_iaq_entries(ctx, &next, NULL);
210431234768SRichard Henderson             ctx->base.is_jmp = DISAS_IAQ_N_UPDATED;
2105bc921866SRichard Henderson         }
210631234768SRichard Henderson         break;
21077ad439dfSRichard Henderson 
21087ad439dfSRichard Henderson     case 0x100: /* SYSCALL */
21097ad439dfSRichard Henderson         gen_excp_1(EXCP_SYSCALL);
211031234768SRichard Henderson         ctx->base.is_jmp = DISAS_NORETURN;
211131234768SRichard Henderson         break;
21127ad439dfSRichard Henderson 
21137ad439dfSRichard Henderson     default:
21147ad439dfSRichard Henderson     do_sigill:
21152986721dSRichard Henderson         gen_excp_1(EXCP_ILL);
211631234768SRichard Henderson         ctx->base.is_jmp = DISAS_NORETURN;
211731234768SRichard Henderson         break;
21187ad439dfSRichard Henderson     }
21197ad439dfSRichard Henderson }
2120ba1d0b44SRichard Henderson #endif
21217ad439dfSRichard Henderson 
trans_nop(DisasContext * ctx,arg_nop * a)2122deee69a1SRichard Henderson static bool trans_nop(DisasContext *ctx, arg_nop *a)
2123b2167459SRichard Henderson {
2124e0137378SRichard Henderson     ctx->null_cond = cond_make_f();
212531234768SRichard Henderson     return true;
2126b2167459SRichard Henderson }
2127b2167459SRichard Henderson 
trans_break(DisasContext * ctx,arg_break * a)212840f9f908SRichard Henderson static bool trans_break(DisasContext *ctx, arg_break *a)
212998a9cb79SRichard Henderson {
213031234768SRichard Henderson     return gen_excp_iir(ctx, EXCP_BREAK);
213198a9cb79SRichard Henderson }
213298a9cb79SRichard Henderson 
trans_sync(DisasContext * ctx,arg_sync * a)2133e36f27efSRichard Henderson static bool trans_sync(DisasContext *ctx, arg_sync *a)
213498a9cb79SRichard Henderson {
213598a9cb79SRichard Henderson     /* No point in nullifying the memory barrier.  */
213698a9cb79SRichard Henderson     tcg_gen_mb(TCG_BAR_SC | TCG_MO_ALL);
213798a9cb79SRichard Henderson 
2138e0137378SRichard Henderson     ctx->null_cond = cond_make_f();
213931234768SRichard Henderson     return true;
214098a9cb79SRichard Henderson }
214198a9cb79SRichard Henderson 
trans_mfia(DisasContext * ctx,arg_mfia * a)2142c603e14aSRichard Henderson static bool trans_mfia(DisasContext *ctx, arg_mfia *a)
214398a9cb79SRichard Henderson {
2144bc921866SRichard Henderson     TCGv_i64 dest = dest_gpr(ctx, a->t);
214598a9cb79SRichard Henderson 
2146bc921866SRichard Henderson     copy_iaoq_entry(ctx, dest, &ctx->iaq_f);
2147bc921866SRichard Henderson     tcg_gen_andi_i64(dest, dest, -4);
2148bc921866SRichard Henderson 
2149bc921866SRichard Henderson     save_gpr(ctx, a->t, dest);
2150e0137378SRichard Henderson     ctx->null_cond = cond_make_f();
215131234768SRichard Henderson     return true;
215298a9cb79SRichard Henderson }
215398a9cb79SRichard Henderson 
trans_mfsp(DisasContext * ctx,arg_mfsp * a)2154c603e14aSRichard Henderson static bool trans_mfsp(DisasContext *ctx, arg_mfsp *a)
215598a9cb79SRichard Henderson {
2156c603e14aSRichard Henderson     unsigned rt = a->t;
2157c603e14aSRichard Henderson     unsigned rs = a->sp;
215833423472SRichard Henderson     TCGv_i64 t0 = tcg_temp_new_i64();
215998a9cb79SRichard Henderson 
216033423472SRichard Henderson     load_spr(ctx, t0, rs);
216133423472SRichard Henderson     tcg_gen_shri_i64(t0, t0, 32);
216233423472SRichard Henderson 
2163967662cdSRichard Henderson     save_gpr(ctx, rt, t0);
216498a9cb79SRichard Henderson 
2165e0137378SRichard Henderson     ctx->null_cond = cond_make_f();
216631234768SRichard Henderson     return true;
216798a9cb79SRichard Henderson }
216898a9cb79SRichard Henderson 
trans_mfctl(DisasContext * ctx,arg_mfctl * a)2169c603e14aSRichard Henderson static bool trans_mfctl(DisasContext *ctx, arg_mfctl *a)
217098a9cb79SRichard Henderson {
2171c603e14aSRichard Henderson     unsigned rt = a->t;
2172c603e14aSRichard Henderson     unsigned ctl = a->r;
21736fd0c7bcSRichard Henderson     TCGv_i64 tmp;
217498a9cb79SRichard Henderson 
217598a9cb79SRichard Henderson     switch (ctl) {
217635136a77SRichard Henderson     case CR_SAR:
2177c603e14aSRichard Henderson         if (a->e == 0) {
217898a9cb79SRichard Henderson             /* MFSAR without ,W masks low 5 bits.  */
217998a9cb79SRichard Henderson             tmp = dest_gpr(ctx, rt);
21806fd0c7bcSRichard Henderson             tcg_gen_andi_i64(tmp, cpu_sar, 31);
218198a9cb79SRichard Henderson             save_gpr(ctx, rt, tmp);
218235136a77SRichard Henderson             goto done;
218398a9cb79SRichard Henderson         }
218498a9cb79SRichard Henderson         save_gpr(ctx, rt, cpu_sar);
218535136a77SRichard Henderson         goto done;
218635136a77SRichard Henderson     case CR_IT: /* Interval Timer */
218735136a77SRichard Henderson         /* FIXME: Respect PSW_S bit.  */
218835136a77SRichard Henderson         nullify_over(ctx);
218998a9cb79SRichard Henderson         tmp = dest_gpr(ctx, rt);
2190dfd1b812SRichard Henderson         if (translator_io_start(&ctx->base)) {
219131234768SRichard Henderson             ctx->base.is_jmp = DISAS_IAQ_N_STALE;
219249c29d6cSRichard Henderson         }
21930c58c1bcSRichard Henderson         gen_helper_read_interval_timer(tmp);
219498a9cb79SRichard Henderson         save_gpr(ctx, rt, tmp);
219531234768SRichard Henderson         return nullify_end(ctx);
219698a9cb79SRichard Henderson     case 26:
219798a9cb79SRichard Henderson     case 27:
219898a9cb79SRichard Henderson         break;
219998a9cb79SRichard Henderson     default:
220098a9cb79SRichard Henderson         /* All other control registers are privileged.  */
220135136a77SRichard Henderson         CHECK_MOST_PRIVILEGED(EXCP_PRIV_REG);
220235136a77SRichard Henderson         break;
220398a9cb79SRichard Henderson     }
220498a9cb79SRichard Henderson 
2205aac0f603SRichard Henderson     tmp = tcg_temp_new_i64();
22066fd0c7bcSRichard Henderson     tcg_gen_ld_i64(tmp, tcg_env, offsetof(CPUHPPAState, cr[ctl]));
220735136a77SRichard Henderson     save_gpr(ctx, rt, tmp);
220835136a77SRichard Henderson 
220935136a77SRichard Henderson  done:
2210e0137378SRichard Henderson     ctx->null_cond = cond_make_f();
221131234768SRichard Henderson     return true;
221298a9cb79SRichard Henderson }
221398a9cb79SRichard Henderson 
trans_mtsp(DisasContext * ctx,arg_mtsp * a)2214c603e14aSRichard Henderson static bool trans_mtsp(DisasContext *ctx, arg_mtsp *a)
221533423472SRichard Henderson {
2216c603e14aSRichard Henderson     unsigned rr = a->r;
2217c603e14aSRichard Henderson     unsigned rs = a->sp;
2218967662cdSRichard Henderson     TCGv_i64 tmp;
221933423472SRichard Henderson 
222033423472SRichard Henderson     if (rs >= 5) {
222133423472SRichard Henderson         CHECK_MOST_PRIVILEGED(EXCP_PRIV_REG);
222233423472SRichard Henderson     }
222333423472SRichard Henderson     nullify_over(ctx);
222433423472SRichard Henderson 
2225967662cdSRichard Henderson     tmp = tcg_temp_new_i64();
2226967662cdSRichard Henderson     tcg_gen_shli_i64(tmp, load_gpr(ctx, rr), 32);
222733423472SRichard Henderson 
222833423472SRichard Henderson     if (rs >= 4) {
2229967662cdSRichard Henderson         tcg_gen_st_i64(tmp, tcg_env, offsetof(CPUHPPAState, sr[rs]));
2230494737b7SRichard Henderson         ctx->tb_flags &= ~TB_FLAG_SR_SAME;
223133423472SRichard Henderson     } else {
2232967662cdSRichard Henderson         tcg_gen_mov_i64(cpu_sr[rs], tmp);
223333423472SRichard Henderson     }
223433423472SRichard Henderson 
223531234768SRichard Henderson     return nullify_end(ctx);
223633423472SRichard Henderson }
223733423472SRichard Henderson 
trans_mtctl(DisasContext * ctx,arg_mtctl * a)2238c603e14aSRichard Henderson static bool trans_mtctl(DisasContext *ctx, arg_mtctl *a)
223998a9cb79SRichard Henderson {
2240c603e14aSRichard Henderson     unsigned ctl = a->t;
22416fd0c7bcSRichard Henderson     TCGv_i64 reg;
22426fd0c7bcSRichard Henderson     TCGv_i64 tmp;
224398a9cb79SRichard Henderson 
224435136a77SRichard Henderson     if (ctl == CR_SAR) {
22454845f015SSven Schnelle         reg = load_gpr(ctx, a->r);
2246aac0f603SRichard Henderson         tmp = tcg_temp_new_i64();
22476fd0c7bcSRichard Henderson         tcg_gen_andi_i64(tmp, reg, ctx->is_pa20 ? 63 : 31);
224898a9cb79SRichard Henderson         save_or_nullify(ctx, cpu_sar, tmp);
224998a9cb79SRichard Henderson 
2250e0137378SRichard Henderson         ctx->null_cond = cond_make_f();
225131234768SRichard Henderson         return true;
225298a9cb79SRichard Henderson     }
225398a9cb79SRichard Henderson 
225435136a77SRichard Henderson     /* All other control registers are privileged or read-only.  */
225535136a77SRichard Henderson     CHECK_MOST_PRIVILEGED(EXCP_PRIV_REG);
225635136a77SRichard Henderson 
2257c603e14aSRichard Henderson #ifndef CONFIG_USER_ONLY
225835136a77SRichard Henderson     nullify_over(ctx);
22594c34bab0SHelge Deller 
22604c34bab0SHelge Deller     if (ctx->is_pa20) {
22614845f015SSven Schnelle         reg = load_gpr(ctx, a->r);
22624c34bab0SHelge Deller     } else {
22634c34bab0SHelge Deller         reg = tcg_temp_new_i64();
22644c34bab0SHelge Deller         tcg_gen_ext32u_i64(reg, load_gpr(ctx, a->r));
22654c34bab0SHelge Deller     }
22664845f015SSven Schnelle 
226735136a77SRichard Henderson     switch (ctl) {
226835136a77SRichard Henderson     case CR_IT:
2269104281c1SRichard Henderson         if (translator_io_start(&ctx->base)) {
2270104281c1SRichard Henderson             ctx->base.is_jmp = DISAS_IAQ_N_STALE;
2271104281c1SRichard Henderson         }
2272ad75a51eSRichard Henderson         gen_helper_write_interval_timer(tcg_env, reg);
227335136a77SRichard Henderson         break;
22744f5f2548SRichard Henderson     case CR_EIRR:
22756ebebea7SRichard Henderson         /* Helper modifies interrupt lines and is therefore IO. */
22766ebebea7SRichard Henderson         translator_io_start(&ctx->base);
2277ad75a51eSRichard Henderson         gen_helper_write_eirr(tcg_env, reg);
22786ebebea7SRichard Henderson         /* Exit to re-evaluate interrupts in the main loop. */
227931234768SRichard Henderson         ctx->base.is_jmp = DISAS_IAQ_N_STALE_EXIT;
22804f5f2548SRichard Henderson         break;
22814f5f2548SRichard Henderson 
228235136a77SRichard Henderson     case CR_IIASQ:
228335136a77SRichard Henderson     case CR_IIAOQ:
228435136a77SRichard Henderson         /* FIXME: Respect PSW_Q bit */
228535136a77SRichard Henderson         /* The write advances the queue and stores to the back element.  */
2286aac0f603SRichard Henderson         tmp = tcg_temp_new_i64();
22876fd0c7bcSRichard Henderson         tcg_gen_ld_i64(tmp, tcg_env,
228835136a77SRichard Henderson                        offsetof(CPUHPPAState, cr_back[ctl - CR_IIASQ]));
22896fd0c7bcSRichard Henderson         tcg_gen_st_i64(tmp, tcg_env, offsetof(CPUHPPAState, cr[ctl]));
22906fd0c7bcSRichard Henderson         tcg_gen_st_i64(reg, tcg_env,
229135136a77SRichard Henderson                        offsetof(CPUHPPAState, cr_back[ctl - CR_IIASQ]));
229235136a77SRichard Henderson         break;
229335136a77SRichard Henderson 
2294d5de20bdSSven Schnelle     case CR_PID1:
2295d5de20bdSSven Schnelle     case CR_PID2:
2296d5de20bdSSven Schnelle     case CR_PID3:
2297d5de20bdSSven Schnelle     case CR_PID4:
22986fd0c7bcSRichard Henderson         tcg_gen_st_i64(reg, tcg_env, offsetof(CPUHPPAState, cr[ctl]));
2299d5de20bdSSven Schnelle #ifndef CONFIG_USER_ONLY
2300ad75a51eSRichard Henderson         gen_helper_change_prot_id(tcg_env);
2301d5de20bdSSven Schnelle #endif
2302d5de20bdSSven Schnelle         break;
2303d5de20bdSSven Schnelle 
23046ebebea7SRichard Henderson     case CR_EIEM:
23056ebebea7SRichard Henderson         /* Exit to re-evaluate interrupts in the main loop. */
23066ebebea7SRichard Henderson         ctx->base.is_jmp = DISAS_IAQ_N_STALE_EXIT;
23076ebebea7SRichard Henderson         /* FALLTHRU */
230835136a77SRichard Henderson     default:
23096fd0c7bcSRichard Henderson         tcg_gen_st_i64(reg, tcg_env, offsetof(CPUHPPAState, cr[ctl]));
231035136a77SRichard Henderson         break;
231135136a77SRichard Henderson     }
231231234768SRichard Henderson     return nullify_end(ctx);
23134f5f2548SRichard Henderson #endif
231435136a77SRichard Henderson }
231535136a77SRichard Henderson 
trans_mtsarcm(DisasContext * ctx,arg_mtsarcm * a)2316c603e14aSRichard Henderson static bool trans_mtsarcm(DisasContext *ctx, arg_mtsarcm *a)
231798a9cb79SRichard Henderson {
2318aac0f603SRichard Henderson     TCGv_i64 tmp = tcg_temp_new_i64();
231998a9cb79SRichard Henderson 
23206fd0c7bcSRichard Henderson     tcg_gen_not_i64(tmp, load_gpr(ctx, a->r));
23216fd0c7bcSRichard Henderson     tcg_gen_andi_i64(tmp, tmp, ctx->is_pa20 ? 63 : 31);
232298a9cb79SRichard Henderson     save_or_nullify(ctx, cpu_sar, tmp);
232398a9cb79SRichard Henderson 
2324e0137378SRichard Henderson     ctx->null_cond = cond_make_f();
232531234768SRichard Henderson     return true;
232698a9cb79SRichard Henderson }
232798a9cb79SRichard Henderson 
trans_ldsid(DisasContext * ctx,arg_ldsid * a)2328e36f27efSRichard Henderson static bool trans_ldsid(DisasContext *ctx, arg_ldsid *a)
232998a9cb79SRichard Henderson {
23306fd0c7bcSRichard Henderson     TCGv_i64 dest = dest_gpr(ctx, a->t);
233198a9cb79SRichard Henderson 
23322330504cSHelge Deller #ifdef CONFIG_USER_ONLY
23332330504cSHelge Deller     /* We don't implement space registers in user mode. */
23346fd0c7bcSRichard Henderson     tcg_gen_movi_i64(dest, 0);
23352330504cSHelge Deller #else
2336967662cdSRichard Henderson     tcg_gen_mov_i64(dest, space_select(ctx, a->sp, load_gpr(ctx, a->b)));
2337967662cdSRichard Henderson     tcg_gen_shri_i64(dest, dest, 32);
23382330504cSHelge Deller #endif
2339e36f27efSRichard Henderson     save_gpr(ctx, a->t, dest);
234098a9cb79SRichard Henderson 
2341e0137378SRichard Henderson     ctx->null_cond = cond_make_f();
234231234768SRichard Henderson     return true;
234398a9cb79SRichard Henderson }
234498a9cb79SRichard Henderson 
trans_rsm(DisasContext * ctx,arg_rsm * a)2345e36f27efSRichard Henderson static bool trans_rsm(DisasContext *ctx, arg_rsm *a)
2346e36f27efSRichard Henderson {
23477b2d70a1SHelge Deller #ifdef CONFIG_USER_ONLY
2348e36f27efSRichard Henderson     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
23497b2d70a1SHelge Deller #else
23506fd0c7bcSRichard Henderson     TCGv_i64 tmp;
2351e1b5a5edSRichard Henderson 
23527b2d70a1SHelge Deller     /* HP-UX 11i and HP ODE use rsm for read-access to PSW */
23537b2d70a1SHelge Deller     if (a->i) {
23547b2d70a1SHelge Deller         CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
23557b2d70a1SHelge Deller     }
23567b2d70a1SHelge Deller 
2357e1b5a5edSRichard Henderson     nullify_over(ctx);
2358e1b5a5edSRichard Henderson 
2359aac0f603SRichard Henderson     tmp = tcg_temp_new_i64();
23606fd0c7bcSRichard Henderson     tcg_gen_ld_i64(tmp, tcg_env, offsetof(CPUHPPAState, psw));
23616fd0c7bcSRichard Henderson     tcg_gen_andi_i64(tmp, tmp, ~a->i);
2362ad75a51eSRichard Henderson     gen_helper_swap_system_mask(tmp, tcg_env, tmp);
2363e36f27efSRichard Henderson     save_gpr(ctx, a->t, tmp);
2364e1b5a5edSRichard Henderson 
2365e1b5a5edSRichard Henderson     /* Exit the TB to recognize new interrupts, e.g. PSW_M.  */
236631234768SRichard Henderson     ctx->base.is_jmp = DISAS_IAQ_N_STALE_EXIT;
236731234768SRichard Henderson     return nullify_end(ctx);
2368e36f27efSRichard Henderson #endif
2369e1b5a5edSRichard Henderson }
2370e1b5a5edSRichard Henderson 
trans_ssm(DisasContext * ctx,arg_ssm * a)2371e36f27efSRichard Henderson static bool trans_ssm(DisasContext *ctx, arg_ssm *a)
2372e1b5a5edSRichard Henderson {
2373e36f27efSRichard Henderson     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
2374e36f27efSRichard Henderson #ifndef CONFIG_USER_ONLY
23756fd0c7bcSRichard Henderson     TCGv_i64 tmp;
2376e1b5a5edSRichard Henderson 
2377e1b5a5edSRichard Henderson     nullify_over(ctx);
2378e1b5a5edSRichard Henderson 
2379aac0f603SRichard Henderson     tmp = tcg_temp_new_i64();
23806fd0c7bcSRichard Henderson     tcg_gen_ld_i64(tmp, tcg_env, offsetof(CPUHPPAState, psw));
23816fd0c7bcSRichard Henderson     tcg_gen_ori_i64(tmp, tmp, a->i);
2382ad75a51eSRichard Henderson     gen_helper_swap_system_mask(tmp, tcg_env, tmp);
2383e36f27efSRichard Henderson     save_gpr(ctx, a->t, tmp);
2384e1b5a5edSRichard Henderson 
2385e1b5a5edSRichard Henderson     /* Exit the TB to recognize new interrupts, e.g. PSW_I.  */
238631234768SRichard Henderson     ctx->base.is_jmp = DISAS_IAQ_N_STALE_EXIT;
238731234768SRichard Henderson     return nullify_end(ctx);
2388e36f27efSRichard Henderson #endif
2389e1b5a5edSRichard Henderson }
2390e1b5a5edSRichard Henderson 
trans_mtsm(DisasContext * ctx,arg_mtsm * a)2391c603e14aSRichard Henderson static bool trans_mtsm(DisasContext *ctx, arg_mtsm *a)
2392e1b5a5edSRichard Henderson {
2393e1b5a5edSRichard Henderson     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
2394c603e14aSRichard Henderson #ifndef CONFIG_USER_ONLY
23956fd0c7bcSRichard Henderson     TCGv_i64 tmp, reg;
2396e1b5a5edSRichard Henderson     nullify_over(ctx);
2397e1b5a5edSRichard Henderson 
2398c603e14aSRichard Henderson     reg = load_gpr(ctx, a->r);
2399aac0f603SRichard Henderson     tmp = tcg_temp_new_i64();
2400ad75a51eSRichard Henderson     gen_helper_swap_system_mask(tmp, tcg_env, reg);
2401e1b5a5edSRichard Henderson 
2402e1b5a5edSRichard Henderson     /* Exit the TB to recognize new interrupts.  */
240331234768SRichard Henderson     ctx->base.is_jmp = DISAS_IAQ_N_STALE_EXIT;
240431234768SRichard Henderson     return nullify_end(ctx);
2405c603e14aSRichard Henderson #endif
2406e1b5a5edSRichard Henderson }
2407f49b3537SRichard Henderson 
do_rfi(DisasContext * ctx,bool rfi_r)2408e36f27efSRichard Henderson static bool do_rfi(DisasContext *ctx, bool rfi_r)
2409f49b3537SRichard Henderson {
2410f49b3537SRichard Henderson     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
2411e36f27efSRichard Henderson #ifndef CONFIG_USER_ONLY
2412f49b3537SRichard Henderson     nullify_over(ctx);
2413f49b3537SRichard Henderson 
2414e36f27efSRichard Henderson     if (rfi_r) {
2415ad75a51eSRichard Henderson         gen_helper_rfi_r(tcg_env);
2416f49b3537SRichard Henderson     } else {
2417ad75a51eSRichard Henderson         gen_helper_rfi(tcg_env);
2418f49b3537SRichard Henderson     }
241931234768SRichard Henderson     /* Exit the TB to recognize new interrupts.  */
242007ea28b4SRichard Henderson     tcg_gen_exit_tb(NULL, 0);
242131234768SRichard Henderson     ctx->base.is_jmp = DISAS_NORETURN;
2422f49b3537SRichard Henderson 
242331234768SRichard Henderson     return nullify_end(ctx);
2424e36f27efSRichard Henderson #endif
2425f49b3537SRichard Henderson }
24266210db05SHelge Deller 
trans_rfi(DisasContext * ctx,arg_rfi * a)2427e36f27efSRichard Henderson static bool trans_rfi(DisasContext *ctx, arg_rfi *a)
2428e36f27efSRichard Henderson {
2429e36f27efSRichard Henderson     return do_rfi(ctx, false);
2430e36f27efSRichard Henderson }
2431e36f27efSRichard Henderson 
trans_rfi_r(DisasContext * ctx,arg_rfi_r * a)2432e36f27efSRichard Henderson static bool trans_rfi_r(DisasContext *ctx, arg_rfi_r *a)
2433e36f27efSRichard Henderson {
2434e36f27efSRichard Henderson     return do_rfi(ctx, true);
2435e36f27efSRichard Henderson }
2436e36f27efSRichard Henderson 
trans_halt(DisasContext * ctx,arg_halt * a)243796927adbSRichard Henderson static bool trans_halt(DisasContext *ctx, arg_halt *a)
24386210db05SHelge Deller {
24396210db05SHelge Deller     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
244096927adbSRichard Henderson #ifndef CONFIG_USER_ONLY
2441d27fe7c3SRichard Henderson     set_psw_xb(ctx, 0);
24426210db05SHelge Deller     nullify_over(ctx);
2443ad75a51eSRichard Henderson     gen_helper_halt(tcg_env);
244431234768SRichard Henderson     ctx->base.is_jmp = DISAS_NORETURN;
244531234768SRichard Henderson     return nullify_end(ctx);
244696927adbSRichard Henderson #endif
24476210db05SHelge Deller }
244896927adbSRichard Henderson 
trans_reset(DisasContext * ctx,arg_reset * a)244996927adbSRichard Henderson static bool trans_reset(DisasContext *ctx, arg_reset *a)
245096927adbSRichard Henderson {
245196927adbSRichard Henderson     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
245296927adbSRichard Henderson #ifndef CONFIG_USER_ONLY
2453d27fe7c3SRichard Henderson     set_psw_xb(ctx, 0);
245496927adbSRichard Henderson     nullify_over(ctx);
2455ad75a51eSRichard Henderson     gen_helper_reset(tcg_env);
245696927adbSRichard Henderson     ctx->base.is_jmp = DISAS_NORETURN;
245796927adbSRichard Henderson     return nullify_end(ctx);
245896927adbSRichard Henderson #endif
245996927adbSRichard Henderson }
2460e1b5a5edSRichard Henderson 
do_getshadowregs(DisasContext * ctx)2461558c09beSRichard Henderson static bool do_getshadowregs(DisasContext *ctx)
24624a4554c6SHelge Deller {
24634a4554c6SHelge Deller     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
24644a4554c6SHelge Deller     nullify_over(ctx);
2465558c09beSRichard Henderson     tcg_gen_ld_i64(cpu_gr[1], tcg_env, offsetof(CPUHPPAState, shadow[0]));
2466558c09beSRichard Henderson     tcg_gen_ld_i64(cpu_gr[8], tcg_env, offsetof(CPUHPPAState, shadow[1]));
2467558c09beSRichard Henderson     tcg_gen_ld_i64(cpu_gr[9], tcg_env, offsetof(CPUHPPAState, shadow[2]));
2468558c09beSRichard Henderson     tcg_gen_ld_i64(cpu_gr[16], tcg_env, offsetof(CPUHPPAState, shadow[3]));
2469558c09beSRichard Henderson     tcg_gen_ld_i64(cpu_gr[17], tcg_env, offsetof(CPUHPPAState, shadow[4]));
2470558c09beSRichard Henderson     tcg_gen_ld_i64(cpu_gr[24], tcg_env, offsetof(CPUHPPAState, shadow[5]));
2471558c09beSRichard Henderson     tcg_gen_ld_i64(cpu_gr[25], tcg_env, offsetof(CPUHPPAState, shadow[6]));
24724a4554c6SHelge Deller     return nullify_end(ctx);
2473558c09beSRichard Henderson }
2474558c09beSRichard Henderson 
do_putshadowregs(DisasContext * ctx)24753bdf2081SHelge Deller static bool do_putshadowregs(DisasContext *ctx)
24763bdf2081SHelge Deller {
24773bdf2081SHelge Deller     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
24783bdf2081SHelge Deller     nullify_over(ctx);
24793bdf2081SHelge Deller     tcg_gen_st_i64(cpu_gr[1], tcg_env, offsetof(CPUHPPAState, shadow[0]));
24803bdf2081SHelge Deller     tcg_gen_st_i64(cpu_gr[8], tcg_env, offsetof(CPUHPPAState, shadow[1]));
24813bdf2081SHelge Deller     tcg_gen_st_i64(cpu_gr[9], tcg_env, offsetof(CPUHPPAState, shadow[2]));
24823bdf2081SHelge Deller     tcg_gen_st_i64(cpu_gr[16], tcg_env, offsetof(CPUHPPAState, shadow[3]));
24833bdf2081SHelge Deller     tcg_gen_st_i64(cpu_gr[17], tcg_env, offsetof(CPUHPPAState, shadow[4]));
24843bdf2081SHelge Deller     tcg_gen_st_i64(cpu_gr[24], tcg_env, offsetof(CPUHPPAState, shadow[5]));
24853bdf2081SHelge Deller     tcg_gen_st_i64(cpu_gr[25], tcg_env, offsetof(CPUHPPAState, shadow[6]));
24863bdf2081SHelge Deller     return nullify_end(ctx);
24873bdf2081SHelge Deller }
24883bdf2081SHelge Deller 
trans_getshadowregs(DisasContext * ctx,arg_getshadowregs * a)2489558c09beSRichard Henderson static bool trans_getshadowregs(DisasContext *ctx, arg_getshadowregs *a)
2490558c09beSRichard Henderson {
2491558c09beSRichard Henderson     return do_getshadowregs(ctx);
24924a4554c6SHelge Deller }
24934a4554c6SHelge Deller 
trans_nop_addrx(DisasContext * ctx,arg_ldst * a)2494deee69a1SRichard Henderson static bool trans_nop_addrx(DisasContext *ctx, arg_ldst *a)
249598a9cb79SRichard Henderson {
2496deee69a1SRichard Henderson     if (a->m) {
24976fd0c7bcSRichard Henderson         TCGv_i64 dest = dest_gpr(ctx, a->b);
24986fd0c7bcSRichard Henderson         TCGv_i64 src1 = load_gpr(ctx, a->b);
24996fd0c7bcSRichard Henderson         TCGv_i64 src2 = load_gpr(ctx, a->x);
250098a9cb79SRichard Henderson 
250198a9cb79SRichard Henderson         /* The only thing we need to do is the base register modification.  */
25026fd0c7bcSRichard Henderson         tcg_gen_add_i64(dest, src1, src2);
2503deee69a1SRichard Henderson         save_gpr(ctx, a->b, dest);
2504deee69a1SRichard Henderson     }
2505e0137378SRichard Henderson     ctx->null_cond = cond_make_f();
250631234768SRichard Henderson     return true;
250798a9cb79SRichard Henderson }
250898a9cb79SRichard Henderson 
trans_fic(DisasContext * ctx,arg_ldst * a)2509ad1fdacdSSven Schnelle static bool trans_fic(DisasContext *ctx, arg_ldst *a)
2510ad1fdacdSSven Schnelle {
2511ad1fdacdSSven Schnelle     /* End TB for flush instruction cache, so we pick up new insns. */
2512ad1fdacdSSven Schnelle     ctx->base.is_jmp = DISAS_IAQ_N_STALE;
2513ad1fdacdSSven Schnelle     return trans_nop_addrx(ctx, a);
2514ad1fdacdSSven Schnelle }
2515ad1fdacdSSven Schnelle 
trans_probe(DisasContext * ctx,arg_probe * a)2516deee69a1SRichard Henderson static bool trans_probe(DisasContext *ctx, arg_probe *a)
251798a9cb79SRichard Henderson {
25186fd0c7bcSRichard Henderson     TCGv_i64 dest, ofs;
2519eed14219SRichard Henderson     TCGv_i32 level, want;
25206fd0c7bcSRichard Henderson     TCGv_i64 addr;
252198a9cb79SRichard Henderson 
252298a9cb79SRichard Henderson     nullify_over(ctx);
252398a9cb79SRichard Henderson 
2524deee69a1SRichard Henderson     dest = dest_gpr(ctx, a->t);
2525deee69a1SRichard Henderson     form_gva(ctx, &addr, &ofs, a->b, 0, 0, 0, a->sp, 0, false);
2526eed14219SRichard Henderson 
2527deee69a1SRichard Henderson     if (a->imm) {
2528e5d487c9SRichard Henderson         level = tcg_constant_i32(a->ri & 3);
252998a9cb79SRichard Henderson     } else {
2530eed14219SRichard Henderson         level = tcg_temp_new_i32();
25316fd0c7bcSRichard Henderson         tcg_gen_extrl_i64_i32(level, load_gpr(ctx, a->ri));
2532eed14219SRichard Henderson         tcg_gen_andi_i32(level, level, 3);
253398a9cb79SRichard Henderson     }
253429dd6f64SRichard Henderson     want = tcg_constant_i32(a->write ? PAGE_WRITE : PAGE_READ);
2535eed14219SRichard Henderson 
2536ad75a51eSRichard Henderson     gen_helper_probe(dest, tcg_env, addr, level, want);
2537eed14219SRichard Henderson 
2538deee69a1SRichard Henderson     save_gpr(ctx, a->t, dest);
253931234768SRichard Henderson     return nullify_end(ctx);
254098a9cb79SRichard Henderson }
254198a9cb79SRichard Henderson 
trans_ixtlbx(DisasContext * ctx,arg_ixtlbx * a)2542deee69a1SRichard Henderson static bool trans_ixtlbx(DisasContext *ctx, arg_ixtlbx *a)
25438d6ae7fbSRichard Henderson {
25448577f354SRichard Henderson     if (ctx->is_pa20) {
25458577f354SRichard Henderson         return false;
25468577f354SRichard Henderson     }
2547deee69a1SRichard Henderson     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
2548deee69a1SRichard Henderson #ifndef CONFIG_USER_ONLY
25496fd0c7bcSRichard Henderson     TCGv_i64 addr;
25506fd0c7bcSRichard Henderson     TCGv_i64 ofs, reg;
25518d6ae7fbSRichard Henderson 
25528d6ae7fbSRichard Henderson     nullify_over(ctx);
25538d6ae7fbSRichard Henderson 
2554deee69a1SRichard Henderson     form_gva(ctx, &addr, &ofs, a->b, 0, 0, 0, a->sp, 0, false);
2555deee69a1SRichard Henderson     reg = load_gpr(ctx, a->r);
2556deee69a1SRichard Henderson     if (a->addr) {
25578577f354SRichard Henderson         gen_helper_itlba_pa11(tcg_env, addr, reg);
25588d6ae7fbSRichard Henderson     } else {
25598577f354SRichard Henderson         gen_helper_itlbp_pa11(tcg_env, addr, reg);
25608d6ae7fbSRichard Henderson     }
25618d6ae7fbSRichard Henderson 
256232dc7569SSven Schnelle     /* Exit TB for TLB change if mmu is enabled.  */
256332dc7569SSven Schnelle     if (ctx->tb_flags & PSW_C) {
256431234768SRichard Henderson         ctx->base.is_jmp = DISAS_IAQ_N_STALE;
256531234768SRichard Henderson     }
256631234768SRichard Henderson     return nullify_end(ctx);
2567deee69a1SRichard Henderson #endif
25688d6ae7fbSRichard Henderson }
256963300a00SRichard Henderson 
do_pxtlb(DisasContext * ctx,arg_ldst * a,bool local)2570eb25d10fSHelge Deller static bool do_pxtlb(DisasContext *ctx, arg_ldst *a, bool local)
257163300a00SRichard Henderson {
2572deee69a1SRichard Henderson     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
2573deee69a1SRichard Henderson #ifndef CONFIG_USER_ONLY
25746fd0c7bcSRichard Henderson     TCGv_i64 addr;
25756fd0c7bcSRichard Henderson     TCGv_i64 ofs;
257663300a00SRichard Henderson 
257763300a00SRichard Henderson     nullify_over(ctx);
257863300a00SRichard Henderson 
2579deee69a1SRichard Henderson     form_gva(ctx, &addr, &ofs, a->b, a->x, 0, 0, a->sp, a->m, false);
2580eb25d10fSHelge Deller 
2581eb25d10fSHelge Deller     /*
2582eb25d10fSHelge Deller      * Page align now, rather than later, so that we can add in the
2583eb25d10fSHelge Deller      * page_size field from pa2.0 from the low 4 bits of GR[b].
2584eb25d10fSHelge Deller      */
2585eb25d10fSHelge Deller     tcg_gen_andi_i64(addr, addr, TARGET_PAGE_MASK);
2586eb25d10fSHelge Deller     if (ctx->is_pa20) {
2587eb25d10fSHelge Deller         tcg_gen_deposit_i64(addr, addr, load_gpr(ctx, a->b), 0, 4);
258863300a00SRichard Henderson     }
2589eb25d10fSHelge Deller 
2590eb25d10fSHelge Deller     if (local) {
2591eb25d10fSHelge Deller         gen_helper_ptlb_l(tcg_env, addr);
259263300a00SRichard Henderson     } else {
2593ad75a51eSRichard Henderson         gen_helper_ptlb(tcg_env, addr);
259463300a00SRichard Henderson     }
259563300a00SRichard Henderson 
2596eb25d10fSHelge Deller     if (a->m) {
2597eb25d10fSHelge Deller         save_gpr(ctx, a->b, ofs);
2598eb25d10fSHelge Deller     }
2599eb25d10fSHelge Deller 
2600eb25d10fSHelge Deller     /* Exit TB for TLB change if mmu is enabled.  */
2601eb25d10fSHelge Deller     if (ctx->tb_flags & PSW_C) {
2602eb25d10fSHelge Deller         ctx->base.is_jmp = DISAS_IAQ_N_STALE;
2603eb25d10fSHelge Deller     }
2604eb25d10fSHelge Deller     return nullify_end(ctx);
2605eb25d10fSHelge Deller #endif
2606eb25d10fSHelge Deller }
2607eb25d10fSHelge Deller 
trans_pxtlb(DisasContext * ctx,arg_ldst * a)2608eb25d10fSHelge Deller static bool trans_pxtlb(DisasContext *ctx, arg_ldst *a)
2609eb25d10fSHelge Deller {
2610eb25d10fSHelge Deller     return do_pxtlb(ctx, a, false);
2611eb25d10fSHelge Deller }
2612eb25d10fSHelge Deller 
trans_pxtlb_l(DisasContext * ctx,arg_ldst * a)2613eb25d10fSHelge Deller static bool trans_pxtlb_l(DisasContext *ctx, arg_ldst *a)
2614eb25d10fSHelge Deller {
2615eb25d10fSHelge Deller     return ctx->is_pa20 && do_pxtlb(ctx, a, true);
2616eb25d10fSHelge Deller }
2617eb25d10fSHelge Deller 
trans_pxtlbe(DisasContext * ctx,arg_ldst * a)2618eb25d10fSHelge Deller static bool trans_pxtlbe(DisasContext *ctx, arg_ldst *a)
2619eb25d10fSHelge Deller {
2620eb25d10fSHelge Deller     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
2621eb25d10fSHelge Deller #ifndef CONFIG_USER_ONLY
2622eb25d10fSHelge Deller     nullify_over(ctx);
2623eb25d10fSHelge Deller 
2624eb25d10fSHelge Deller     trans_nop_addrx(ctx, a);
2625eb25d10fSHelge Deller     gen_helper_ptlbe(tcg_env);
2626eb25d10fSHelge Deller 
262763300a00SRichard Henderson     /* Exit TB for TLB change if mmu is enabled.  */
262832dc7569SSven Schnelle     if (ctx->tb_flags & PSW_C) {
262931234768SRichard Henderson         ctx->base.is_jmp = DISAS_IAQ_N_STALE;
263031234768SRichard Henderson     }
263131234768SRichard Henderson     return nullify_end(ctx);
2632deee69a1SRichard Henderson #endif
263363300a00SRichard Henderson }
26342dfcca9fSRichard Henderson 
26356797c315SNick Hudson /*
26366797c315SNick Hudson  * Implement the pcxl and pcxl2 Fast TLB Insert instructions.
26376797c315SNick Hudson  * See
26386797c315SNick Hudson  *     https://parisc.wiki.kernel.org/images-parisc/a/a9/Pcxl2_ers.pdf
26396797c315SNick Hudson  *     page 13-9 (195/206)
26406797c315SNick Hudson  */
trans_ixtlbxf(DisasContext * ctx,arg_ixtlbxf * a)26416797c315SNick Hudson static bool trans_ixtlbxf(DisasContext *ctx, arg_ixtlbxf *a)
26426797c315SNick Hudson {
26438577f354SRichard Henderson     if (ctx->is_pa20) {
26448577f354SRichard Henderson         return false;
26458577f354SRichard Henderson     }
26466797c315SNick Hudson     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
26476797c315SNick Hudson #ifndef CONFIG_USER_ONLY
26486fd0c7bcSRichard Henderson     TCGv_i64 addr, atl, stl;
26496fd0c7bcSRichard Henderson     TCGv_i64 reg;
26506797c315SNick Hudson 
26516797c315SNick Hudson     nullify_over(ctx);
26526797c315SNick Hudson 
26536797c315SNick Hudson     /*
26546797c315SNick Hudson      * FIXME:
26556797c315SNick Hudson      *  if (not (pcxl or pcxl2))
26566797c315SNick Hudson      *    return gen_illegal(ctx);
26576797c315SNick Hudson      */
26586797c315SNick Hudson 
26596fd0c7bcSRichard Henderson     atl = tcg_temp_new_i64();
26606fd0c7bcSRichard Henderson     stl = tcg_temp_new_i64();
26616fd0c7bcSRichard Henderson     addr = tcg_temp_new_i64();
26626797c315SNick Hudson 
2663ad75a51eSRichard Henderson     tcg_gen_ld32u_i64(stl, tcg_env,
26646797c315SNick Hudson                       a->data ? offsetof(CPUHPPAState, cr[CR_ISR])
26656797c315SNick Hudson                       : offsetof(CPUHPPAState, cr[CR_IIASQ]));
2666ad75a51eSRichard Henderson     tcg_gen_ld32u_i64(atl, tcg_env,
26676797c315SNick Hudson                       a->data ? offsetof(CPUHPPAState, cr[CR_IOR])
26686797c315SNick Hudson                       : offsetof(CPUHPPAState, cr[CR_IIAOQ]));
26696797c315SNick Hudson     tcg_gen_shli_i64(stl, stl, 32);
2670d265360fSRichard Henderson     tcg_gen_or_i64(addr, atl, stl);
26716797c315SNick Hudson 
26726797c315SNick Hudson     reg = load_gpr(ctx, a->r);
26736797c315SNick Hudson     if (a->addr) {
26748577f354SRichard Henderson         gen_helper_itlba_pa11(tcg_env, addr, reg);
26756797c315SNick Hudson     } else {
26768577f354SRichard Henderson         gen_helper_itlbp_pa11(tcg_env, addr, reg);
26776797c315SNick Hudson     }
26786797c315SNick Hudson 
26796797c315SNick Hudson     /* Exit TB for TLB change if mmu is enabled.  */
26806797c315SNick Hudson     if (ctx->tb_flags & PSW_C) {
26816797c315SNick Hudson         ctx->base.is_jmp = DISAS_IAQ_N_STALE;
26826797c315SNick Hudson     }
26836797c315SNick Hudson     return nullify_end(ctx);
26846797c315SNick Hudson #endif
26856797c315SNick Hudson }
26866797c315SNick Hudson 
trans_ixtlbt(DisasContext * ctx,arg_ixtlbt * a)26878577f354SRichard Henderson static bool trans_ixtlbt(DisasContext *ctx, arg_ixtlbt *a)
26888577f354SRichard Henderson {
26898577f354SRichard Henderson     if (!ctx->is_pa20) {
26908577f354SRichard Henderson         return false;
26918577f354SRichard Henderson     }
26928577f354SRichard Henderson     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
26938577f354SRichard Henderson #ifndef CONFIG_USER_ONLY
26948577f354SRichard Henderson     nullify_over(ctx);
26958577f354SRichard Henderson     {
26968577f354SRichard Henderson         TCGv_i64 src1 = load_gpr(ctx, a->r1);
26978577f354SRichard Henderson         TCGv_i64 src2 = load_gpr(ctx, a->r2);
26988577f354SRichard Henderson 
26998577f354SRichard Henderson         if (a->data) {
27008577f354SRichard Henderson             gen_helper_idtlbt_pa20(tcg_env, src1, src2);
27018577f354SRichard Henderson         } else {
27028577f354SRichard Henderson             gen_helper_iitlbt_pa20(tcg_env, src1, src2);
27038577f354SRichard Henderson         }
27048577f354SRichard Henderson     }
27058577f354SRichard Henderson     /* Exit TB for TLB change if mmu is enabled.  */
27068577f354SRichard Henderson     if (ctx->tb_flags & PSW_C) {
27078577f354SRichard Henderson         ctx->base.is_jmp = DISAS_IAQ_N_STALE;
27088577f354SRichard Henderson     }
27098577f354SRichard Henderson     return nullify_end(ctx);
27108577f354SRichard Henderson #endif
27118577f354SRichard Henderson }
27128577f354SRichard Henderson 
trans_lpa(DisasContext * ctx,arg_ldst * a)2713deee69a1SRichard Henderson static bool trans_lpa(DisasContext *ctx, arg_ldst *a)
27142dfcca9fSRichard Henderson {
2715deee69a1SRichard Henderson     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
2716deee69a1SRichard Henderson #ifndef CONFIG_USER_ONLY
27176fd0c7bcSRichard Henderson     TCGv_i64 vaddr;
27186fd0c7bcSRichard Henderson     TCGv_i64 ofs, paddr;
27192dfcca9fSRichard Henderson 
27202dfcca9fSRichard Henderson     nullify_over(ctx);
27212dfcca9fSRichard Henderson 
2722deee69a1SRichard Henderson     form_gva(ctx, &vaddr, &ofs, a->b, a->x, 0, 0, a->sp, a->m, false);
27232dfcca9fSRichard Henderson 
2724aac0f603SRichard Henderson     paddr = tcg_temp_new_i64();
2725ad75a51eSRichard Henderson     gen_helper_lpa(paddr, tcg_env, vaddr);
27262dfcca9fSRichard Henderson 
27272dfcca9fSRichard Henderson     /* Note that physical address result overrides base modification.  */
2728deee69a1SRichard Henderson     if (a->m) {
2729deee69a1SRichard Henderson         save_gpr(ctx, a->b, ofs);
27302dfcca9fSRichard Henderson     }
2731deee69a1SRichard Henderson     save_gpr(ctx, a->t, paddr);
27322dfcca9fSRichard Henderson 
273331234768SRichard Henderson     return nullify_end(ctx);
2734deee69a1SRichard Henderson #endif
27352dfcca9fSRichard Henderson }
273643a97b81SRichard Henderson 
trans_lci(DisasContext * ctx,arg_lci * a)2737deee69a1SRichard Henderson static bool trans_lci(DisasContext *ctx, arg_lci *a)
273843a97b81SRichard Henderson {
273943a97b81SRichard Henderson     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
274043a97b81SRichard Henderson 
274143a97b81SRichard Henderson     /* The Coherence Index is an implementation-defined function of the
274243a97b81SRichard Henderson        physical address.  Two addresses with the same CI have a coherent
274343a97b81SRichard Henderson        view of the cache.  Our implementation is to return 0 for all,
274443a97b81SRichard Henderson        since the entire address space is coherent.  */
2745a4db4a78SRichard Henderson     save_gpr(ctx, a->t, ctx->zero);
274643a97b81SRichard Henderson 
2747e0137378SRichard Henderson     ctx->null_cond = cond_make_f();
274831234768SRichard Henderson     return true;
274943a97b81SRichard Henderson }
275098a9cb79SRichard Henderson 
trans_add(DisasContext * ctx,arg_rrr_cf_d_sh * a)2751faf97ba1SRichard Henderson static bool trans_add(DisasContext *ctx, arg_rrr_cf_d_sh *a)
2752b2167459SRichard Henderson {
27530c982a28SRichard Henderson     return do_add_reg(ctx, a, false, false, false, false);
2754b2167459SRichard Henderson }
2755b2167459SRichard Henderson 
trans_add_l(DisasContext * ctx,arg_rrr_cf_d_sh * a)2756faf97ba1SRichard Henderson static bool trans_add_l(DisasContext *ctx, arg_rrr_cf_d_sh *a)
2757b2167459SRichard Henderson {
27580c982a28SRichard Henderson     return do_add_reg(ctx, a, true, false, false, false);
2759b2167459SRichard Henderson }
2760b2167459SRichard Henderson 
trans_add_tsv(DisasContext * ctx,arg_rrr_cf_d_sh * a)2761faf97ba1SRichard Henderson static bool trans_add_tsv(DisasContext *ctx, arg_rrr_cf_d_sh *a)
2762b2167459SRichard Henderson {
27630c982a28SRichard Henderson     return do_add_reg(ctx, a, false, true, false, false);
2764b2167459SRichard Henderson }
2765b2167459SRichard Henderson 
trans_add_c(DisasContext * ctx,arg_rrr_cf_d_sh * a)2766faf97ba1SRichard Henderson static bool trans_add_c(DisasContext *ctx, arg_rrr_cf_d_sh *a)
2767b2167459SRichard Henderson {
27680c982a28SRichard Henderson     return do_add_reg(ctx, a, false, false, false, true);
27690c982a28SRichard Henderson }
2770b2167459SRichard Henderson 
trans_add_c_tsv(DisasContext * ctx,arg_rrr_cf_d_sh * a)2771faf97ba1SRichard Henderson static bool trans_add_c_tsv(DisasContext *ctx, arg_rrr_cf_d_sh *a)
27720c982a28SRichard Henderson {
27730c982a28SRichard Henderson     return do_add_reg(ctx, a, false, true, false, true);
27740c982a28SRichard Henderson }
27750c982a28SRichard Henderson 
trans_sub(DisasContext * ctx,arg_rrr_cf_d * a)277663c427c6SRichard Henderson static bool trans_sub(DisasContext *ctx, arg_rrr_cf_d *a)
27770c982a28SRichard Henderson {
27780c982a28SRichard Henderson     return do_sub_reg(ctx, a, false, false, false);
27790c982a28SRichard Henderson }
27800c982a28SRichard Henderson 
trans_sub_tsv(DisasContext * ctx,arg_rrr_cf_d * a)278163c427c6SRichard Henderson static bool trans_sub_tsv(DisasContext *ctx, arg_rrr_cf_d *a)
27820c982a28SRichard Henderson {
27830c982a28SRichard Henderson     return do_sub_reg(ctx, a, true, false, false);
27840c982a28SRichard Henderson }
27850c982a28SRichard Henderson 
trans_sub_tc(DisasContext * ctx,arg_rrr_cf_d * a)278663c427c6SRichard Henderson static bool trans_sub_tc(DisasContext *ctx, arg_rrr_cf_d *a)
27870c982a28SRichard Henderson {
27880c982a28SRichard Henderson     return do_sub_reg(ctx, a, false, false, true);
27890c982a28SRichard Henderson }
27900c982a28SRichard Henderson 
trans_sub_tsv_tc(DisasContext * ctx,arg_rrr_cf_d * a)279163c427c6SRichard Henderson static bool trans_sub_tsv_tc(DisasContext *ctx, arg_rrr_cf_d *a)
27920c982a28SRichard Henderson {
27930c982a28SRichard Henderson     return do_sub_reg(ctx, a, true, false, true);
27940c982a28SRichard Henderson }
27950c982a28SRichard Henderson 
trans_sub_b(DisasContext * ctx,arg_rrr_cf_d * a)279663c427c6SRichard Henderson static bool trans_sub_b(DisasContext *ctx, arg_rrr_cf_d *a)
27970c982a28SRichard Henderson {
27980c982a28SRichard Henderson     return do_sub_reg(ctx, a, false, true, false);
27990c982a28SRichard Henderson }
28000c982a28SRichard Henderson 
trans_sub_b_tsv(DisasContext * ctx,arg_rrr_cf_d * a)280163c427c6SRichard Henderson static bool trans_sub_b_tsv(DisasContext *ctx, arg_rrr_cf_d *a)
28020c982a28SRichard Henderson {
28030c982a28SRichard Henderson     return do_sub_reg(ctx, a, true, true, false);
28040c982a28SRichard Henderson }
28050c982a28SRichard Henderson 
trans_andcm(DisasContext * ctx,arg_rrr_cf_d * a)2806fa8e3bedSRichard Henderson static bool trans_andcm(DisasContext *ctx, arg_rrr_cf_d *a)
28070c982a28SRichard Henderson {
28086fd0c7bcSRichard Henderson     return do_log_reg(ctx, a, tcg_gen_andc_i64);
28090c982a28SRichard Henderson }
28100c982a28SRichard Henderson 
trans_and(DisasContext * ctx,arg_rrr_cf_d * a)2811fa8e3bedSRichard Henderson static bool trans_and(DisasContext *ctx, arg_rrr_cf_d *a)
28120c982a28SRichard Henderson {
28136fd0c7bcSRichard Henderson     return do_log_reg(ctx, a, tcg_gen_and_i64);
28140c982a28SRichard Henderson }
28150c982a28SRichard Henderson 
trans_or(DisasContext * ctx,arg_rrr_cf_d * a)2816fa8e3bedSRichard Henderson static bool trans_or(DisasContext *ctx, arg_rrr_cf_d *a)
28170c982a28SRichard Henderson {
28180c982a28SRichard Henderson     if (a->cf == 0) {
28190c982a28SRichard Henderson         unsigned r2 = a->r2;
28200c982a28SRichard Henderson         unsigned r1 = a->r1;
28210c982a28SRichard Henderson         unsigned rt = a->t;
28220c982a28SRichard Henderson 
28237aee8189SRichard Henderson         if (rt == 0) { /* NOP */
2824e0137378SRichard Henderson             ctx->null_cond = cond_make_f();
28257aee8189SRichard Henderson             return true;
28267aee8189SRichard Henderson         }
28277aee8189SRichard Henderson         if (r2 == 0) { /* COPY */
2828b2167459SRichard Henderson             if (r1 == 0) {
28296fd0c7bcSRichard Henderson                 TCGv_i64 dest = dest_gpr(ctx, rt);
28306fd0c7bcSRichard Henderson                 tcg_gen_movi_i64(dest, 0);
2831b2167459SRichard Henderson                 save_gpr(ctx, rt, dest);
2832b2167459SRichard Henderson             } else {
2833b2167459SRichard Henderson                 save_gpr(ctx, rt, cpu_gr[r1]);
2834b2167459SRichard Henderson             }
2835e0137378SRichard Henderson             ctx->null_cond = cond_make_f();
283631234768SRichard Henderson             return true;
2837b2167459SRichard Henderson         }
28387aee8189SRichard Henderson #ifndef CONFIG_USER_ONLY
28397aee8189SRichard Henderson         /* These are QEMU extensions and are nops in the real architecture:
28407aee8189SRichard Henderson          *
28417aee8189SRichard Henderson          * or %r10,%r10,%r10 -- idle loop; wait for interrupt
28427aee8189SRichard Henderson          * or %r31,%r31,%r31 -- death loop; offline cpu
28437aee8189SRichard Henderson          *                      currently implemented as idle.
28447aee8189SRichard Henderson          */
28457aee8189SRichard Henderson         if ((rt == 10 || rt == 31) && r1 == rt && r2 == rt) { /* PAUSE */
28467aee8189SRichard Henderson             /* No need to check for supervisor, as userland can only pause
28477aee8189SRichard Henderson                until the next timer interrupt.  */
2848d27fe7c3SRichard Henderson 
2849d27fe7c3SRichard Henderson             set_psw_xb(ctx, 0);
2850d27fe7c3SRichard Henderson 
28517aee8189SRichard Henderson             nullify_over(ctx);
28527aee8189SRichard Henderson 
28537aee8189SRichard Henderson             /* Advance the instruction queue.  */
2854bc921866SRichard Henderson             install_iaq_entries(ctx, &ctx->iaq_b, NULL);
28557aee8189SRichard Henderson             nullify_set(ctx, 0);
28567aee8189SRichard Henderson 
28577aee8189SRichard Henderson             /* Tell the qemu main loop to halt until this cpu has work.  */
2858ad75a51eSRichard Henderson             tcg_gen_st_i32(tcg_constant_i32(1), tcg_env,
285929dd6f64SRichard Henderson                            offsetof(CPUState, halted) - offsetof(HPPACPU, env));
28607aee8189SRichard Henderson             gen_excp_1(EXCP_HALTED);
28617aee8189SRichard Henderson             ctx->base.is_jmp = DISAS_NORETURN;
28627aee8189SRichard Henderson 
28637aee8189SRichard Henderson             return nullify_end(ctx);
28647aee8189SRichard Henderson         }
28657aee8189SRichard Henderson #endif
28667aee8189SRichard Henderson     }
28676fd0c7bcSRichard Henderson     return do_log_reg(ctx, a, tcg_gen_or_i64);
28687aee8189SRichard Henderson }
2869b2167459SRichard Henderson 
trans_xor(DisasContext * ctx,arg_rrr_cf_d * a)2870fa8e3bedSRichard Henderson static bool trans_xor(DisasContext *ctx, arg_rrr_cf_d *a)
2871b2167459SRichard Henderson {
28726fd0c7bcSRichard Henderson     return do_log_reg(ctx, a, tcg_gen_xor_i64);
28730c982a28SRichard Henderson }
28740c982a28SRichard Henderson 
trans_cmpclr(DisasContext * ctx,arg_rrr_cf_d * a)2875345aa35fSRichard Henderson static bool trans_cmpclr(DisasContext *ctx, arg_rrr_cf_d *a)
28760c982a28SRichard Henderson {
28776fd0c7bcSRichard Henderson     TCGv_i64 tcg_r1, tcg_r2;
2878b2167459SRichard Henderson 
28790c982a28SRichard Henderson     if (a->cf) {
2880b2167459SRichard Henderson         nullify_over(ctx);
2881b2167459SRichard Henderson     }
28820c982a28SRichard Henderson     tcg_r1 = load_gpr(ctx, a->r1);
28830c982a28SRichard Henderson     tcg_r2 = load_gpr(ctx, a->r2);
2884345aa35fSRichard Henderson     do_cmpclr(ctx, a->t, tcg_r1, tcg_r2, a->cf, a->d);
288531234768SRichard Henderson     return nullify_end(ctx);
2886b2167459SRichard Henderson }
2887b2167459SRichard Henderson 
trans_uxor(DisasContext * ctx,arg_rrr_cf_d * a)2888af240753SRichard Henderson static bool trans_uxor(DisasContext *ctx, arg_rrr_cf_d *a)
2889b2167459SRichard Henderson {
289046bb3d46SRichard Henderson     TCGv_i64 tcg_r1, tcg_r2, dest;
2891b2167459SRichard Henderson 
28920c982a28SRichard Henderson     if (a->cf) {
2893b2167459SRichard Henderson         nullify_over(ctx);
2894b2167459SRichard Henderson     }
289546bb3d46SRichard Henderson 
28960c982a28SRichard Henderson     tcg_r1 = load_gpr(ctx, a->r1);
28970c982a28SRichard Henderson     tcg_r2 = load_gpr(ctx, a->r2);
289846bb3d46SRichard Henderson     dest = dest_gpr(ctx, a->t);
289946bb3d46SRichard Henderson 
290046bb3d46SRichard Henderson     tcg_gen_xor_i64(dest, tcg_r1, tcg_r2);
290146bb3d46SRichard Henderson     save_gpr(ctx, a->t, dest);
290246bb3d46SRichard Henderson 
290346bb3d46SRichard Henderson     ctx->null_cond = do_unit_zero_cond(a->cf, a->d, dest);
290431234768SRichard Henderson     return nullify_end(ctx);
2905b2167459SRichard Henderson }
2906b2167459SRichard Henderson 
do_uaddcm(DisasContext * ctx,arg_rrr_cf_d * a,bool is_tc)2907af240753SRichard Henderson static bool do_uaddcm(DisasContext *ctx, arg_rrr_cf_d *a, bool is_tc)
2908b2167459SRichard Henderson {
29096fd0c7bcSRichard Henderson     TCGv_i64 tcg_r1, tcg_r2, tmp;
2910b2167459SRichard Henderson 
2911ababac16SRichard Henderson     if (a->cf == 0) {
2912ababac16SRichard Henderson         tcg_r2 = load_gpr(ctx, a->r2);
2913ababac16SRichard Henderson         tmp = dest_gpr(ctx, a->t);
2914ababac16SRichard Henderson 
2915ababac16SRichard Henderson         if (a->r1 == 0) {
2916ababac16SRichard Henderson             /* UADDCM r0,src,dst is the common idiom for dst = ~src. */
2917ababac16SRichard Henderson             tcg_gen_not_i64(tmp, tcg_r2);
2918ababac16SRichard Henderson         } else {
2919ababac16SRichard Henderson             /*
2920ababac16SRichard Henderson              * Recall that r1 - r2 == r1 + ~r2 + 1.
2921ababac16SRichard Henderson              * Thus r1 + ~r2 == r1 - r2 - 1,
2922ababac16SRichard Henderson              * which does not require an extra temporary.
2923ababac16SRichard Henderson              */
2924ababac16SRichard Henderson             tcg_r1 = load_gpr(ctx, a->r1);
2925ababac16SRichard Henderson             tcg_gen_sub_i64(tmp, tcg_r1, tcg_r2);
2926ababac16SRichard Henderson             tcg_gen_subi_i64(tmp, tmp, 1);
2927b2167459SRichard Henderson         }
2928ababac16SRichard Henderson         save_gpr(ctx, a->t, tmp);
2929e0137378SRichard Henderson         ctx->null_cond = cond_make_f();
2930ababac16SRichard Henderson         return true;
2931ababac16SRichard Henderson     }
2932ababac16SRichard Henderson 
2933ababac16SRichard Henderson     nullify_over(ctx);
29340c982a28SRichard Henderson     tcg_r1 = load_gpr(ctx, a->r1);
29350c982a28SRichard Henderson     tcg_r2 = load_gpr(ctx, a->r2);
2936aac0f603SRichard Henderson     tmp = tcg_temp_new_i64();
29376fd0c7bcSRichard Henderson     tcg_gen_not_i64(tmp, tcg_r2);
293846bb3d46SRichard Henderson     do_unit_addsub(ctx, a->t, tcg_r1, tmp, a->cf, a->d, is_tc, true);
293931234768SRichard Henderson     return nullify_end(ctx);
2940b2167459SRichard Henderson }
2941b2167459SRichard Henderson 
trans_uaddcm(DisasContext * ctx,arg_rrr_cf_d * a)2942af240753SRichard Henderson static bool trans_uaddcm(DisasContext *ctx, arg_rrr_cf_d *a)
2943b2167459SRichard Henderson {
29440c982a28SRichard Henderson     return do_uaddcm(ctx, a, false);
29450c982a28SRichard Henderson }
29460c982a28SRichard Henderson 
trans_uaddcm_tc(DisasContext * ctx,arg_rrr_cf_d * a)2947af240753SRichard Henderson static bool trans_uaddcm_tc(DisasContext *ctx, arg_rrr_cf_d *a)
29480c982a28SRichard Henderson {
29490c982a28SRichard Henderson     return do_uaddcm(ctx, a, true);
29500c982a28SRichard Henderson }
29510c982a28SRichard Henderson 
do_dcor(DisasContext * ctx,arg_rr_cf_d * a,bool is_i)2952af240753SRichard Henderson static bool do_dcor(DisasContext *ctx, arg_rr_cf_d *a, bool is_i)
29530c982a28SRichard Henderson {
29546fd0c7bcSRichard Henderson     TCGv_i64 tmp;
2955b2167459SRichard Henderson 
2956b2167459SRichard Henderson     nullify_over(ctx);
2957b2167459SRichard Henderson 
2958aac0f603SRichard Henderson     tmp = tcg_temp_new_i64();
2959d0ae87a2SRichard Henderson     tcg_gen_extract2_i64(tmp, cpu_psw_cb, cpu_psw_cb_msb, 4);
2960b2167459SRichard Henderson     if (!is_i) {
29616fd0c7bcSRichard Henderson         tcg_gen_not_i64(tmp, tmp);
2962b2167459SRichard Henderson     }
29636fd0c7bcSRichard Henderson     tcg_gen_andi_i64(tmp, tmp, (uint64_t)0x1111111111111111ull);
29646fd0c7bcSRichard Henderson     tcg_gen_muli_i64(tmp, tmp, 6);
296546bb3d46SRichard Henderson     do_unit_addsub(ctx, a->t, load_gpr(ctx, a->r), tmp,
296646bb3d46SRichard Henderson                    a->cf, a->d, false, is_i);
296731234768SRichard Henderson     return nullify_end(ctx);
2968b2167459SRichard Henderson }
2969b2167459SRichard Henderson 
trans_dcor(DisasContext * ctx,arg_rr_cf_d * a)2970af240753SRichard Henderson static bool trans_dcor(DisasContext *ctx, arg_rr_cf_d *a)
2971b2167459SRichard Henderson {
29720c982a28SRichard Henderson     return do_dcor(ctx, a, false);
29730c982a28SRichard Henderson }
29740c982a28SRichard Henderson 
trans_dcor_i(DisasContext * ctx,arg_rr_cf_d * a)2975af240753SRichard Henderson static bool trans_dcor_i(DisasContext *ctx, arg_rr_cf_d *a)
29760c982a28SRichard Henderson {
29770c982a28SRichard Henderson     return do_dcor(ctx, a, true);
29780c982a28SRichard Henderson }
29790c982a28SRichard Henderson 
trans_ds(DisasContext * ctx,arg_rrr_cf * a)29800c982a28SRichard Henderson static bool trans_ds(DisasContext *ctx, arg_rrr_cf *a)
29810c982a28SRichard Henderson {
2982a4db4a78SRichard Henderson     TCGv_i64 dest, add1, add2, addc, in1, in2;
2983b2167459SRichard Henderson 
2984b2167459SRichard Henderson     nullify_over(ctx);
2985b2167459SRichard Henderson 
29860c982a28SRichard Henderson     in1 = load_gpr(ctx, a->r1);
29870c982a28SRichard Henderson     in2 = load_gpr(ctx, a->r2);
2988b2167459SRichard Henderson 
2989aac0f603SRichard Henderson     add1 = tcg_temp_new_i64();
2990aac0f603SRichard Henderson     add2 = tcg_temp_new_i64();
2991aac0f603SRichard Henderson     addc = tcg_temp_new_i64();
2992aac0f603SRichard Henderson     dest = tcg_temp_new_i64();
2993b2167459SRichard Henderson 
2994b2167459SRichard Henderson     /* Form R1 << 1 | PSW[CB]{8}.  */
29956fd0c7bcSRichard Henderson     tcg_gen_add_i64(add1, in1, in1);
29966fd0c7bcSRichard Henderson     tcg_gen_add_i64(add1, add1, get_psw_carry(ctx, false));
2997b2167459SRichard Henderson 
299872ca8753SRichard Henderson     /*
299972ca8753SRichard Henderson      * Add or subtract R2, depending on PSW[V].  Proper computation of
300072ca8753SRichard Henderson      * carry requires that we subtract via + ~R2 + 1, as described in
300172ca8753SRichard Henderson      * the manual.  By extracting and masking V, we can produce the
300272ca8753SRichard Henderson      * proper inputs to the addition without movcond.
300372ca8753SRichard Henderson      */
30046fd0c7bcSRichard Henderson     tcg_gen_sextract_i64(addc, cpu_psw_v, 31, 1);
30056fd0c7bcSRichard Henderson     tcg_gen_xor_i64(add2, in2, addc);
30066fd0c7bcSRichard Henderson     tcg_gen_andi_i64(addc, addc, 1);
300772ca8753SRichard Henderson 
3008a4db4a78SRichard Henderson     tcg_gen_add2_i64(dest, cpu_psw_cb_msb, add1, ctx->zero, add2, ctx->zero);
3009a4db4a78SRichard Henderson     tcg_gen_add2_i64(dest, cpu_psw_cb_msb, dest, cpu_psw_cb_msb,
3010a4db4a78SRichard Henderson                      addc, ctx->zero);
3011b2167459SRichard Henderson 
3012b2167459SRichard Henderson     /* Write back the result register.  */
30130c982a28SRichard Henderson     save_gpr(ctx, a->t, dest);
3014b2167459SRichard Henderson 
3015b2167459SRichard Henderson     /* Write back PSW[CB].  */
30166fd0c7bcSRichard Henderson     tcg_gen_xor_i64(cpu_psw_cb, add1, add2);
30176fd0c7bcSRichard Henderson     tcg_gen_xor_i64(cpu_psw_cb, cpu_psw_cb, dest);
3018b2167459SRichard Henderson 
3019f8f5986eSRichard Henderson     /*
3020f8f5986eSRichard Henderson      * Write back PSW[V] for the division step.
3021f8f5986eSRichard Henderson      * Shift cb{8} from where it lives in bit 32 to bit 31,
3022f8f5986eSRichard Henderson      * so that it overlaps r2{32} in bit 31.
3023f8f5986eSRichard Henderson      */
3024f8f5986eSRichard Henderson     tcg_gen_shri_i64(cpu_psw_v, cpu_psw_cb, 1);
30256fd0c7bcSRichard Henderson     tcg_gen_xor_i64(cpu_psw_v, cpu_psw_v, in2);
3026b2167459SRichard Henderson 
3027b2167459SRichard Henderson     /* Install the new nullification.  */
30280c982a28SRichard Henderson     if (a->cf) {
3029f8f5986eSRichard Henderson         TCGv_i64 sv = NULL, uv = NULL;
3030b47a4a02SSven Schnelle         if (cond_need_sv(a->cf >> 1)) {
3031f8f5986eSRichard Henderson             sv = do_add_sv(ctx, dest, add1, add2, in1, 1, false);
3032f8f5986eSRichard Henderson         } else if (cond_need_cb(a->cf >> 1)) {
3033f8f5986eSRichard Henderson             uv = do_add_uv(ctx, cpu_psw_cb, NULL, in1, 1, false);
3034b2167459SRichard Henderson         }
3035f8f5986eSRichard Henderson         ctx->null_cond = do_cond(ctx, a->cf, false, dest, uv, sv);
3036b2167459SRichard Henderson     }
3037b2167459SRichard Henderson 
303831234768SRichard Henderson     return nullify_end(ctx);
3039b2167459SRichard Henderson }
3040b2167459SRichard Henderson 
trans_addi(DisasContext * ctx,arg_rri_cf * a)30410588e061SRichard Henderson static bool trans_addi(DisasContext *ctx, arg_rri_cf *a)
3042b2167459SRichard Henderson {
30430588e061SRichard Henderson     return do_add_imm(ctx, a, false, false);
30440588e061SRichard Henderson }
30450588e061SRichard Henderson 
trans_addi_tsv(DisasContext * ctx,arg_rri_cf * a)30460588e061SRichard Henderson static bool trans_addi_tsv(DisasContext *ctx, arg_rri_cf *a)
30470588e061SRichard Henderson {
30480588e061SRichard Henderson     return do_add_imm(ctx, a, true, false);
30490588e061SRichard Henderson }
30500588e061SRichard Henderson 
trans_addi_tc(DisasContext * ctx,arg_rri_cf * a)30510588e061SRichard Henderson static bool trans_addi_tc(DisasContext *ctx, arg_rri_cf *a)
30520588e061SRichard Henderson {
30530588e061SRichard Henderson     return do_add_imm(ctx, a, false, true);
30540588e061SRichard Henderson }
30550588e061SRichard Henderson 
trans_addi_tc_tsv(DisasContext * ctx,arg_rri_cf * a)30560588e061SRichard Henderson static bool trans_addi_tc_tsv(DisasContext *ctx, arg_rri_cf *a)
30570588e061SRichard Henderson {
30580588e061SRichard Henderson     return do_add_imm(ctx, a, true, true);
30590588e061SRichard Henderson }
30600588e061SRichard Henderson 
trans_subi(DisasContext * ctx,arg_rri_cf * a)30610588e061SRichard Henderson static bool trans_subi(DisasContext *ctx, arg_rri_cf *a)
30620588e061SRichard Henderson {
30630588e061SRichard Henderson     return do_sub_imm(ctx, a, false);
30640588e061SRichard Henderson }
30650588e061SRichard Henderson 
trans_subi_tsv(DisasContext * ctx,arg_rri_cf * a)30660588e061SRichard Henderson static bool trans_subi_tsv(DisasContext *ctx, arg_rri_cf *a)
30670588e061SRichard Henderson {
30680588e061SRichard Henderson     return do_sub_imm(ctx, a, true);
30690588e061SRichard Henderson }
30700588e061SRichard Henderson 
trans_cmpiclr(DisasContext * ctx,arg_rri_cf_d * a)3071345aa35fSRichard Henderson static bool trans_cmpiclr(DisasContext *ctx, arg_rri_cf_d *a)
30720588e061SRichard Henderson {
30736fd0c7bcSRichard Henderson     TCGv_i64 tcg_im, tcg_r2;
3074b2167459SRichard Henderson 
30750588e061SRichard Henderson     if (a->cf) {
3076b2167459SRichard Henderson         nullify_over(ctx);
3077b2167459SRichard Henderson     }
3078b2167459SRichard Henderson 
30796fd0c7bcSRichard Henderson     tcg_im = tcg_constant_i64(a->i);
30800588e061SRichard Henderson     tcg_r2 = load_gpr(ctx, a->r);
3081345aa35fSRichard Henderson     do_cmpclr(ctx, a->t, tcg_im, tcg_r2, a->cf, a->d);
3082b2167459SRichard Henderson 
308331234768SRichard Henderson     return nullify_end(ctx);
3084b2167459SRichard Henderson }
3085b2167459SRichard Henderson 
do_multimedia(DisasContext * ctx,arg_rrr * a,void (* fn)(TCGv_i64,TCGv_i64,TCGv_i64))30860843563fSRichard Henderson static bool do_multimedia(DisasContext *ctx, arg_rrr *a,
30870843563fSRichard Henderson                           void (*fn)(TCGv_i64, TCGv_i64, TCGv_i64))
30880843563fSRichard Henderson {
30890843563fSRichard Henderson     TCGv_i64 r1, r2, dest;
30900843563fSRichard Henderson 
30910843563fSRichard Henderson     if (!ctx->is_pa20) {
30920843563fSRichard Henderson         return false;
30930843563fSRichard Henderson     }
30940843563fSRichard Henderson 
30950843563fSRichard Henderson     nullify_over(ctx);
30960843563fSRichard Henderson 
30970843563fSRichard Henderson     r1 = load_gpr(ctx, a->r1);
30980843563fSRichard Henderson     r2 = load_gpr(ctx, a->r2);
30990843563fSRichard Henderson     dest = dest_gpr(ctx, a->t);
31000843563fSRichard Henderson 
31010843563fSRichard Henderson     fn(dest, r1, r2);
31020843563fSRichard Henderson     save_gpr(ctx, a->t, dest);
31030843563fSRichard Henderson 
31040843563fSRichard Henderson     return nullify_end(ctx);
31050843563fSRichard Henderson }
31060843563fSRichard Henderson 
do_multimedia_sh(DisasContext * ctx,arg_rri * a,void (* fn)(TCGv_i64,TCGv_i64,int64_t))3107151f309bSRichard Henderson static bool do_multimedia_sh(DisasContext *ctx, arg_rri *a,
3108151f309bSRichard Henderson                              void (*fn)(TCGv_i64, TCGv_i64, int64_t))
3109151f309bSRichard Henderson {
3110151f309bSRichard Henderson     TCGv_i64 r, dest;
3111151f309bSRichard Henderson 
3112151f309bSRichard Henderson     if (!ctx->is_pa20) {
3113151f309bSRichard Henderson         return false;
3114151f309bSRichard Henderson     }
3115151f309bSRichard Henderson 
3116151f309bSRichard Henderson     nullify_over(ctx);
3117151f309bSRichard Henderson 
3118151f309bSRichard Henderson     r = load_gpr(ctx, a->r);
3119151f309bSRichard Henderson     dest = dest_gpr(ctx, a->t);
3120151f309bSRichard Henderson 
3121151f309bSRichard Henderson     fn(dest, r, a->i);
3122151f309bSRichard Henderson     save_gpr(ctx, a->t, dest);
3123151f309bSRichard Henderson 
3124151f309bSRichard Henderson     return nullify_end(ctx);
3125151f309bSRichard Henderson }
3126151f309bSRichard Henderson 
do_multimedia_shadd(DisasContext * ctx,arg_rrr_sh * a,void (* fn)(TCGv_i64,TCGv_i64,TCGv_i64,TCGv_i32))31273bbb8e48SRichard Henderson static bool do_multimedia_shadd(DisasContext *ctx, arg_rrr_sh *a,
31283bbb8e48SRichard Henderson                                 void (*fn)(TCGv_i64, TCGv_i64,
31293bbb8e48SRichard Henderson                                            TCGv_i64, TCGv_i32))
31303bbb8e48SRichard Henderson {
31313bbb8e48SRichard Henderson     TCGv_i64 r1, r2, dest;
31323bbb8e48SRichard Henderson 
31333bbb8e48SRichard Henderson     if (!ctx->is_pa20) {
31343bbb8e48SRichard Henderson         return false;
31353bbb8e48SRichard Henderson     }
31363bbb8e48SRichard Henderson 
31373bbb8e48SRichard Henderson     nullify_over(ctx);
31383bbb8e48SRichard Henderson 
31393bbb8e48SRichard Henderson     r1 = load_gpr(ctx, a->r1);
31403bbb8e48SRichard Henderson     r2 = load_gpr(ctx, a->r2);
31413bbb8e48SRichard Henderson     dest = dest_gpr(ctx, a->t);
31423bbb8e48SRichard Henderson 
31433bbb8e48SRichard Henderson     fn(dest, r1, r2, tcg_constant_i32(a->sh));
31443bbb8e48SRichard Henderson     save_gpr(ctx, a->t, dest);
31453bbb8e48SRichard Henderson 
31463bbb8e48SRichard Henderson     return nullify_end(ctx);
31473bbb8e48SRichard Henderson }
31483bbb8e48SRichard Henderson 
trans_hadd(DisasContext * ctx,arg_rrr * a)31490843563fSRichard Henderson static bool trans_hadd(DisasContext *ctx, arg_rrr *a)
31500843563fSRichard Henderson {
31510843563fSRichard Henderson     return do_multimedia(ctx, a, tcg_gen_vec_add16_i64);
31520843563fSRichard Henderson }
31530843563fSRichard Henderson 
trans_hadd_ss(DisasContext * ctx,arg_rrr * a)31540843563fSRichard Henderson static bool trans_hadd_ss(DisasContext *ctx, arg_rrr *a)
31550843563fSRichard Henderson {
31560843563fSRichard Henderson     return do_multimedia(ctx, a, gen_helper_hadd_ss);
31570843563fSRichard Henderson }
31580843563fSRichard Henderson 
trans_hadd_us(DisasContext * ctx,arg_rrr * a)31590843563fSRichard Henderson static bool trans_hadd_us(DisasContext *ctx, arg_rrr *a)
31600843563fSRichard Henderson {
31610843563fSRichard Henderson     return do_multimedia(ctx, a, gen_helper_hadd_us);
31620843563fSRichard Henderson }
31630843563fSRichard Henderson 
trans_havg(DisasContext * ctx,arg_rrr * a)31641b3cb7c8SRichard Henderson static bool trans_havg(DisasContext *ctx, arg_rrr *a)
31651b3cb7c8SRichard Henderson {
31661b3cb7c8SRichard Henderson     return do_multimedia(ctx, a, gen_helper_havg);
31671b3cb7c8SRichard Henderson }
31681b3cb7c8SRichard Henderson 
trans_hshl(DisasContext * ctx,arg_rri * a)3169151f309bSRichard Henderson static bool trans_hshl(DisasContext *ctx, arg_rri *a)
3170151f309bSRichard Henderson {
3171151f309bSRichard Henderson     return do_multimedia_sh(ctx, a, tcg_gen_vec_shl16i_i64);
3172151f309bSRichard Henderson }
3173151f309bSRichard Henderson 
trans_hshr_s(DisasContext * ctx,arg_rri * a)3174151f309bSRichard Henderson static bool trans_hshr_s(DisasContext *ctx, arg_rri *a)
3175151f309bSRichard Henderson {
3176151f309bSRichard Henderson     return do_multimedia_sh(ctx, a, tcg_gen_vec_sar16i_i64);
3177151f309bSRichard Henderson }
3178151f309bSRichard Henderson 
trans_hshr_u(DisasContext * ctx,arg_rri * a)3179151f309bSRichard Henderson static bool trans_hshr_u(DisasContext *ctx, arg_rri *a)
3180151f309bSRichard Henderson {
3181151f309bSRichard Henderson     return do_multimedia_sh(ctx, a, tcg_gen_vec_shr16i_i64);
3182151f309bSRichard Henderson }
3183151f309bSRichard Henderson 
trans_hshladd(DisasContext * ctx,arg_rrr_sh * a)31843bbb8e48SRichard Henderson static bool trans_hshladd(DisasContext *ctx, arg_rrr_sh *a)
31853bbb8e48SRichard Henderson {
31863bbb8e48SRichard Henderson     return do_multimedia_shadd(ctx, a, gen_helper_hshladd);
31873bbb8e48SRichard Henderson }
31883bbb8e48SRichard Henderson 
trans_hshradd(DisasContext * ctx,arg_rrr_sh * a)31893bbb8e48SRichard Henderson static bool trans_hshradd(DisasContext *ctx, arg_rrr_sh *a)
31903bbb8e48SRichard Henderson {
31913bbb8e48SRichard Henderson     return do_multimedia_shadd(ctx, a, gen_helper_hshradd);
31923bbb8e48SRichard Henderson }
31933bbb8e48SRichard Henderson 
trans_hsub(DisasContext * ctx,arg_rrr * a)319410c9e58dSRichard Henderson static bool trans_hsub(DisasContext *ctx, arg_rrr *a)
319510c9e58dSRichard Henderson {
319610c9e58dSRichard Henderson     return do_multimedia(ctx, a, tcg_gen_vec_sub16_i64);
319710c9e58dSRichard Henderson }
319810c9e58dSRichard Henderson 
trans_hsub_ss(DisasContext * ctx,arg_rrr * a)319910c9e58dSRichard Henderson static bool trans_hsub_ss(DisasContext *ctx, arg_rrr *a)
320010c9e58dSRichard Henderson {
320110c9e58dSRichard Henderson     return do_multimedia(ctx, a, gen_helper_hsub_ss);
320210c9e58dSRichard Henderson }
320310c9e58dSRichard Henderson 
trans_hsub_us(DisasContext * ctx,arg_rrr * a)320410c9e58dSRichard Henderson static bool trans_hsub_us(DisasContext *ctx, arg_rrr *a)
320510c9e58dSRichard Henderson {
320610c9e58dSRichard Henderson     return do_multimedia(ctx, a, gen_helper_hsub_us);
320710c9e58dSRichard Henderson }
320810c9e58dSRichard Henderson 
gen_mixh_l(TCGv_i64 dst,TCGv_i64 r1,TCGv_i64 r2)3209c2a7ee3fSRichard Henderson static void gen_mixh_l(TCGv_i64 dst, TCGv_i64 r1, TCGv_i64 r2)
3210c2a7ee3fSRichard Henderson {
3211c2a7ee3fSRichard Henderson     uint64_t mask = 0xffff0000ffff0000ull;
3212c2a7ee3fSRichard Henderson     TCGv_i64 tmp = tcg_temp_new_i64();
3213c2a7ee3fSRichard Henderson 
3214c2a7ee3fSRichard Henderson     tcg_gen_andi_i64(tmp, r2, mask);
3215c2a7ee3fSRichard Henderson     tcg_gen_andi_i64(dst, r1, mask);
3216c2a7ee3fSRichard Henderson     tcg_gen_shri_i64(tmp, tmp, 16);
3217c2a7ee3fSRichard Henderson     tcg_gen_or_i64(dst, dst, tmp);
3218c2a7ee3fSRichard Henderson }
3219c2a7ee3fSRichard Henderson 
trans_mixh_l(DisasContext * ctx,arg_rrr * a)3220c2a7ee3fSRichard Henderson static bool trans_mixh_l(DisasContext *ctx, arg_rrr *a)
3221c2a7ee3fSRichard Henderson {
3222c2a7ee3fSRichard Henderson     return do_multimedia(ctx, a, gen_mixh_l);
3223c2a7ee3fSRichard Henderson }
3224c2a7ee3fSRichard Henderson 
gen_mixh_r(TCGv_i64 dst,TCGv_i64 r1,TCGv_i64 r2)3225c2a7ee3fSRichard Henderson static void gen_mixh_r(TCGv_i64 dst, TCGv_i64 r1, TCGv_i64 r2)
3226c2a7ee3fSRichard Henderson {
3227c2a7ee3fSRichard Henderson     uint64_t mask = 0x0000ffff0000ffffull;
3228c2a7ee3fSRichard Henderson     TCGv_i64 tmp = tcg_temp_new_i64();
3229c2a7ee3fSRichard Henderson 
3230c2a7ee3fSRichard Henderson     tcg_gen_andi_i64(tmp, r1, mask);
3231c2a7ee3fSRichard Henderson     tcg_gen_andi_i64(dst, r2, mask);
3232c2a7ee3fSRichard Henderson     tcg_gen_shli_i64(tmp, tmp, 16);
3233c2a7ee3fSRichard Henderson     tcg_gen_or_i64(dst, dst, tmp);
3234c2a7ee3fSRichard Henderson }
3235c2a7ee3fSRichard Henderson 
trans_mixh_r(DisasContext * ctx,arg_rrr * a)3236c2a7ee3fSRichard Henderson static bool trans_mixh_r(DisasContext *ctx, arg_rrr *a)
3237c2a7ee3fSRichard Henderson {
3238c2a7ee3fSRichard Henderson     return do_multimedia(ctx, a, gen_mixh_r);
3239c2a7ee3fSRichard Henderson }
3240c2a7ee3fSRichard Henderson 
gen_mixw_l(TCGv_i64 dst,TCGv_i64 r1,TCGv_i64 r2)3241c2a7ee3fSRichard Henderson static void gen_mixw_l(TCGv_i64 dst, TCGv_i64 r1, TCGv_i64 r2)
3242c2a7ee3fSRichard Henderson {
3243c2a7ee3fSRichard Henderson     TCGv_i64 tmp = tcg_temp_new_i64();
3244c2a7ee3fSRichard Henderson 
3245c2a7ee3fSRichard Henderson     tcg_gen_shri_i64(tmp, r2, 32);
3246c2a7ee3fSRichard Henderson     tcg_gen_deposit_i64(dst, r1, tmp, 0, 32);
3247c2a7ee3fSRichard Henderson }
3248c2a7ee3fSRichard Henderson 
trans_mixw_l(DisasContext * ctx,arg_rrr * a)3249c2a7ee3fSRichard Henderson static bool trans_mixw_l(DisasContext *ctx, arg_rrr *a)
3250c2a7ee3fSRichard Henderson {
3251c2a7ee3fSRichard Henderson     return do_multimedia(ctx, a, gen_mixw_l);
3252c2a7ee3fSRichard Henderson }
3253c2a7ee3fSRichard Henderson 
gen_mixw_r(TCGv_i64 dst,TCGv_i64 r1,TCGv_i64 r2)3254c2a7ee3fSRichard Henderson static void gen_mixw_r(TCGv_i64 dst, TCGv_i64 r1, TCGv_i64 r2)
3255c2a7ee3fSRichard Henderson {
3256c2a7ee3fSRichard Henderson     tcg_gen_deposit_i64(dst, r2, r1, 32, 32);
3257c2a7ee3fSRichard Henderson }
3258c2a7ee3fSRichard Henderson 
trans_mixw_r(DisasContext * ctx,arg_rrr * a)3259c2a7ee3fSRichard Henderson static bool trans_mixw_r(DisasContext *ctx, arg_rrr *a)
3260c2a7ee3fSRichard Henderson {
3261c2a7ee3fSRichard Henderson     return do_multimedia(ctx, a, gen_mixw_r);
3262c2a7ee3fSRichard Henderson }
3263c2a7ee3fSRichard Henderson 
trans_permh(DisasContext * ctx,arg_permh * a)32644e7abdb1SRichard Henderson static bool trans_permh(DisasContext *ctx, arg_permh *a)
32654e7abdb1SRichard Henderson {
32664e7abdb1SRichard Henderson     TCGv_i64 r, t0, t1, t2, t3;
32674e7abdb1SRichard Henderson 
32684e7abdb1SRichard Henderson     if (!ctx->is_pa20) {
32694e7abdb1SRichard Henderson         return false;
32704e7abdb1SRichard Henderson     }
32714e7abdb1SRichard Henderson 
32724e7abdb1SRichard Henderson     nullify_over(ctx);
32734e7abdb1SRichard Henderson 
32744e7abdb1SRichard Henderson     r = load_gpr(ctx, a->r1);
32754e7abdb1SRichard Henderson     t0 = tcg_temp_new_i64();
32764e7abdb1SRichard Henderson     t1 = tcg_temp_new_i64();
32774e7abdb1SRichard Henderson     t2 = tcg_temp_new_i64();
32784e7abdb1SRichard Henderson     t3 = tcg_temp_new_i64();
32794e7abdb1SRichard Henderson 
32804e7abdb1SRichard Henderson     tcg_gen_extract_i64(t0, r, (3 - a->c0) * 16, 16);
32814e7abdb1SRichard Henderson     tcg_gen_extract_i64(t1, r, (3 - a->c1) * 16, 16);
32824e7abdb1SRichard Henderson     tcg_gen_extract_i64(t2, r, (3 - a->c2) * 16, 16);
32834e7abdb1SRichard Henderson     tcg_gen_extract_i64(t3, r, (3 - a->c3) * 16, 16);
32844e7abdb1SRichard Henderson 
32854e7abdb1SRichard Henderson     tcg_gen_deposit_i64(t0, t1, t0, 16, 48);
32864e7abdb1SRichard Henderson     tcg_gen_deposit_i64(t2, t3, t2, 16, 48);
32874e7abdb1SRichard Henderson     tcg_gen_deposit_i64(t0, t2, t0, 32, 32);
32884e7abdb1SRichard Henderson 
32894e7abdb1SRichard Henderson     save_gpr(ctx, a->t, t0);
32904e7abdb1SRichard Henderson     return nullify_end(ctx);
32914e7abdb1SRichard Henderson }
32924e7abdb1SRichard Henderson 
trans_ld(DisasContext * ctx,arg_ldst * a)32931cd012a5SRichard Henderson static bool trans_ld(DisasContext *ctx, arg_ldst *a)
329496d6407fSRichard Henderson {
3295b5caa17cSRichard Henderson     if (ctx->is_pa20) {
3296b5caa17cSRichard Henderson        /*
3297b5caa17cSRichard Henderson         * With pa20, LDB, LDH, LDW, LDD to %g0 are prefetches.
3298b5caa17cSRichard Henderson         * Any base modification still occurs.
3299b5caa17cSRichard Henderson         */
3300b5caa17cSRichard Henderson         if (a->t == 0) {
3301b5caa17cSRichard Henderson             return trans_nop_addrx(ctx, a);
3302b5caa17cSRichard Henderson         }
3303b5caa17cSRichard Henderson     } else if (a->size > MO_32) {
33040786a3b6SHelge Deller         return gen_illegal(ctx);
3305c53e401eSRichard Henderson     }
33061cd012a5SRichard Henderson     return do_load(ctx, a->t, a->b, a->x, a->scale ? a->size : 0,
33071cd012a5SRichard Henderson                    a->disp, a->sp, a->m, a->size | MO_TE);
330896d6407fSRichard Henderson }
330996d6407fSRichard Henderson 
trans_st(DisasContext * ctx,arg_ldst * a)33101cd012a5SRichard Henderson static bool trans_st(DisasContext *ctx, arg_ldst *a)
331196d6407fSRichard Henderson {
33121cd012a5SRichard Henderson     assert(a->x == 0 && a->scale == 0);
3313c53e401eSRichard Henderson     if (!ctx->is_pa20 && a->size > MO_32) {
33140786a3b6SHelge Deller         return gen_illegal(ctx);
331596d6407fSRichard Henderson     }
3316c53e401eSRichard Henderson     return do_store(ctx, a->t, a->b, a->disp, a->sp, a->m, a->size | MO_TE);
33170786a3b6SHelge Deller }
331896d6407fSRichard Henderson 
trans_ldc(DisasContext * ctx,arg_ldst * a)33191cd012a5SRichard Henderson static bool trans_ldc(DisasContext *ctx, arg_ldst *a)
332096d6407fSRichard Henderson {
3321b1af755cSRichard Henderson     MemOp mop = MO_TE | MO_ALIGN | a->size;
3322a4db4a78SRichard Henderson     TCGv_i64 dest, ofs;
33236fd0c7bcSRichard Henderson     TCGv_i64 addr;
332496d6407fSRichard Henderson 
3325c53e401eSRichard Henderson     if (!ctx->is_pa20 && a->size > MO_32) {
332651416c4eSRichard Henderson         return gen_illegal(ctx);
332751416c4eSRichard Henderson     }
332851416c4eSRichard Henderson 
332996d6407fSRichard Henderson     nullify_over(ctx);
333096d6407fSRichard Henderson 
33311cd012a5SRichard Henderson     if (a->m) {
333286f8d05fSRichard Henderson         /* Base register modification.  Make sure if RT == RB,
333386f8d05fSRichard Henderson            we see the result of the load.  */
3334aac0f603SRichard Henderson         dest = tcg_temp_new_i64();
333596d6407fSRichard Henderson     } else {
33361cd012a5SRichard Henderson         dest = dest_gpr(ctx, a->t);
333796d6407fSRichard Henderson     }
333896d6407fSRichard Henderson 
3339c3ea1996SSven Schnelle     form_gva(ctx, &addr, &ofs, a->b, a->x, a->scale ? 3 : 0,
334017fe594cSRichard Henderson              a->disp, a->sp, a->m, MMU_DISABLED(ctx));
3341b1af755cSRichard Henderson 
3342b1af755cSRichard Henderson     /*
3343b1af755cSRichard Henderson      * For hppa1.1, LDCW is undefined unless aligned mod 16.
3344b1af755cSRichard Henderson      * However actual hardware succeeds with aligned mod 4.
3345b1af755cSRichard Henderson      * Detect this case and log a GUEST_ERROR.
3346b1af755cSRichard Henderson      *
3347b1af755cSRichard Henderson      * TODO: HPPA64 relaxes the over-alignment requirement
3348b1af755cSRichard Henderson      * with the ,co completer.
3349b1af755cSRichard Henderson      */
3350b1af755cSRichard Henderson     gen_helper_ldc_check(addr);
3351b1af755cSRichard Henderson 
3352a4db4a78SRichard Henderson     tcg_gen_atomic_xchg_i64(dest, addr, ctx->zero, ctx->mmu_idx, mop);
3353b1af755cSRichard Henderson 
33541cd012a5SRichard Henderson     if (a->m) {
33551cd012a5SRichard Henderson         save_gpr(ctx, a->b, ofs);
335696d6407fSRichard Henderson     }
33571cd012a5SRichard Henderson     save_gpr(ctx, a->t, dest);
335896d6407fSRichard Henderson 
335931234768SRichard Henderson     return nullify_end(ctx);
336096d6407fSRichard Henderson }
336196d6407fSRichard Henderson 
trans_stby(DisasContext * ctx,arg_stby * a)33621cd012a5SRichard Henderson static bool trans_stby(DisasContext *ctx, arg_stby *a)
336396d6407fSRichard Henderson {
33646fd0c7bcSRichard Henderson     TCGv_i64 ofs, val;
33656fd0c7bcSRichard Henderson     TCGv_i64 addr;
336696d6407fSRichard Henderson 
336796d6407fSRichard Henderson     nullify_over(ctx);
336896d6407fSRichard Henderson 
33691cd012a5SRichard Henderson     form_gva(ctx, &addr, &ofs, a->b, 0, 0, a->disp, a->sp, a->m,
337017fe594cSRichard Henderson              MMU_DISABLED(ctx));
33711cd012a5SRichard Henderson     val = load_gpr(ctx, a->r);
33721cd012a5SRichard Henderson     if (a->a) {
3373f9f46db4SEmilio G. Cota         if (tb_cflags(ctx->base.tb) & CF_PARALLEL) {
3374ad75a51eSRichard Henderson             gen_helper_stby_e_parallel(tcg_env, addr, val);
3375f9f46db4SEmilio G. Cota         } else {
3376ad75a51eSRichard Henderson             gen_helper_stby_e(tcg_env, addr, val);
3377f9f46db4SEmilio G. Cota         }
3378f9f46db4SEmilio G. Cota     } else {
3379f9f46db4SEmilio G. Cota         if (tb_cflags(ctx->base.tb) & CF_PARALLEL) {
3380ad75a51eSRichard Henderson             gen_helper_stby_b_parallel(tcg_env, addr, val);
338196d6407fSRichard Henderson         } else {
3382ad75a51eSRichard Henderson             gen_helper_stby_b(tcg_env, addr, val);
338396d6407fSRichard Henderson         }
3384f9f46db4SEmilio G. Cota     }
33851cd012a5SRichard Henderson     if (a->m) {
33866fd0c7bcSRichard Henderson         tcg_gen_andi_i64(ofs, ofs, ~3);
33871cd012a5SRichard Henderson         save_gpr(ctx, a->b, ofs);
338896d6407fSRichard Henderson     }
338996d6407fSRichard Henderson 
339031234768SRichard Henderson     return nullify_end(ctx);
339196d6407fSRichard Henderson }
339296d6407fSRichard Henderson 
trans_stdby(DisasContext * ctx,arg_stby * a)339325460fc5SRichard Henderson static bool trans_stdby(DisasContext *ctx, arg_stby *a)
339425460fc5SRichard Henderson {
33956fd0c7bcSRichard Henderson     TCGv_i64 ofs, val;
33966fd0c7bcSRichard Henderson     TCGv_i64 addr;
339725460fc5SRichard Henderson 
339825460fc5SRichard Henderson     if (!ctx->is_pa20) {
339925460fc5SRichard Henderson         return false;
340025460fc5SRichard Henderson     }
340125460fc5SRichard Henderson     nullify_over(ctx);
340225460fc5SRichard Henderson 
340325460fc5SRichard Henderson     form_gva(ctx, &addr, &ofs, a->b, 0, 0, a->disp, a->sp, a->m,
340417fe594cSRichard Henderson              MMU_DISABLED(ctx));
340525460fc5SRichard Henderson     val = load_gpr(ctx, a->r);
340625460fc5SRichard Henderson     if (a->a) {
340725460fc5SRichard Henderson         if (tb_cflags(ctx->base.tb) & CF_PARALLEL) {
340825460fc5SRichard Henderson             gen_helper_stdby_e_parallel(tcg_env, addr, val);
340925460fc5SRichard Henderson         } else {
341025460fc5SRichard Henderson             gen_helper_stdby_e(tcg_env, addr, val);
341125460fc5SRichard Henderson         }
341225460fc5SRichard Henderson     } else {
341325460fc5SRichard Henderson         if (tb_cflags(ctx->base.tb) & CF_PARALLEL) {
341425460fc5SRichard Henderson             gen_helper_stdby_b_parallel(tcg_env, addr, val);
341525460fc5SRichard Henderson         } else {
341625460fc5SRichard Henderson             gen_helper_stdby_b(tcg_env, addr, val);
341725460fc5SRichard Henderson         }
341825460fc5SRichard Henderson     }
341925460fc5SRichard Henderson     if (a->m) {
34206fd0c7bcSRichard Henderson         tcg_gen_andi_i64(ofs, ofs, ~7);
342125460fc5SRichard Henderson         save_gpr(ctx, a->b, ofs);
342225460fc5SRichard Henderson     }
342325460fc5SRichard Henderson 
342425460fc5SRichard Henderson     return nullify_end(ctx);
342525460fc5SRichard Henderson }
342625460fc5SRichard Henderson 
trans_lda(DisasContext * ctx,arg_ldst * a)34271cd012a5SRichard Henderson static bool trans_lda(DisasContext *ctx, arg_ldst *a)
3428d0a851ccSRichard Henderson {
3429d0a851ccSRichard Henderson     int hold_mmu_idx = ctx->mmu_idx;
3430d0a851ccSRichard Henderson 
3431d0a851ccSRichard Henderson     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
3432451d993dSRichard Henderson     ctx->mmu_idx = ctx->tb_flags & PSW_W ? MMU_ABS_W_IDX : MMU_ABS_IDX;
34331cd012a5SRichard Henderson     trans_ld(ctx, a);
3434d0a851ccSRichard Henderson     ctx->mmu_idx = hold_mmu_idx;
343531234768SRichard Henderson     return true;
3436d0a851ccSRichard Henderson }
3437d0a851ccSRichard Henderson 
trans_sta(DisasContext * ctx,arg_ldst * a)34381cd012a5SRichard Henderson static bool trans_sta(DisasContext *ctx, arg_ldst *a)
3439d0a851ccSRichard Henderson {
3440d0a851ccSRichard Henderson     int hold_mmu_idx = ctx->mmu_idx;
3441d0a851ccSRichard Henderson 
3442d0a851ccSRichard Henderson     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
3443451d993dSRichard Henderson     ctx->mmu_idx = ctx->tb_flags & PSW_W ? MMU_ABS_W_IDX : MMU_ABS_IDX;
34441cd012a5SRichard Henderson     trans_st(ctx, a);
3445d0a851ccSRichard Henderson     ctx->mmu_idx = hold_mmu_idx;
344631234768SRichard Henderson     return true;
3447d0a851ccSRichard Henderson }
344895412a61SRichard Henderson 
trans_ldil(DisasContext * ctx,arg_ldil * a)34490588e061SRichard Henderson static bool trans_ldil(DisasContext *ctx, arg_ldil *a)
3450b2167459SRichard Henderson {
34516fd0c7bcSRichard Henderson     TCGv_i64 tcg_rt = dest_gpr(ctx, a->t);
3452b2167459SRichard Henderson 
34536fd0c7bcSRichard Henderson     tcg_gen_movi_i64(tcg_rt, a->i);
34540588e061SRichard Henderson     save_gpr(ctx, a->t, tcg_rt);
3455e0137378SRichard Henderson     ctx->null_cond = cond_make_f();
345631234768SRichard Henderson     return true;
3457b2167459SRichard Henderson }
3458b2167459SRichard Henderson 
trans_addil(DisasContext * ctx,arg_addil * a)34590588e061SRichard Henderson static bool trans_addil(DisasContext *ctx, arg_addil *a)
3460b2167459SRichard Henderson {
34616fd0c7bcSRichard Henderson     TCGv_i64 tcg_rt = load_gpr(ctx, a->r);
34626fd0c7bcSRichard Henderson     TCGv_i64 tcg_r1 = dest_gpr(ctx, 1);
3463b2167459SRichard Henderson 
34646fd0c7bcSRichard Henderson     tcg_gen_addi_i64(tcg_r1, tcg_rt, a->i);
3465b2167459SRichard Henderson     save_gpr(ctx, 1, tcg_r1);
3466e0137378SRichard Henderson     ctx->null_cond = cond_make_f();
346731234768SRichard Henderson     return true;
3468b2167459SRichard Henderson }
3469b2167459SRichard Henderson 
trans_ldo(DisasContext * ctx,arg_ldo * a)34700588e061SRichard Henderson static bool trans_ldo(DisasContext *ctx, arg_ldo *a)
3471b2167459SRichard Henderson {
34726fd0c7bcSRichard Henderson     TCGv_i64 tcg_rt = dest_gpr(ctx, a->t);
3473b2167459SRichard Henderson 
3474b2167459SRichard Henderson     /* Special case rb == 0, for the LDI pseudo-op.
3475d265360fSRichard Henderson        The COPY pseudo-op is handled for free within tcg_gen_addi_i64.  */
34760588e061SRichard Henderson     if (a->b == 0) {
34776fd0c7bcSRichard Henderson         tcg_gen_movi_i64(tcg_rt, a->i);
3478b2167459SRichard Henderson     } else {
34796fd0c7bcSRichard Henderson         tcg_gen_addi_i64(tcg_rt, cpu_gr[a->b], a->i);
3480b2167459SRichard Henderson     }
34810588e061SRichard Henderson     save_gpr(ctx, a->t, tcg_rt);
3482e0137378SRichard Henderson     ctx->null_cond = cond_make_f();
348331234768SRichard Henderson     return true;
3484b2167459SRichard Henderson }
3485b2167459SRichard Henderson 
do_cmpb(DisasContext * ctx,unsigned r,TCGv_i64 in1,unsigned c,unsigned f,bool d,unsigned n,int disp)34866fd0c7bcSRichard Henderson static bool do_cmpb(DisasContext *ctx, unsigned r, TCGv_i64 in1,
3487e9efd4bcSRichard Henderson                     unsigned c, unsigned f, bool d, unsigned n, int disp)
348898cd9ca7SRichard Henderson {
34896fd0c7bcSRichard Henderson     TCGv_i64 dest, in2, sv;
349098cd9ca7SRichard Henderson     DisasCond cond;
349198cd9ca7SRichard Henderson 
349298cd9ca7SRichard Henderson     in2 = load_gpr(ctx, r);
3493aac0f603SRichard Henderson     dest = tcg_temp_new_i64();
349498cd9ca7SRichard Henderson 
34956fd0c7bcSRichard Henderson     tcg_gen_sub_i64(dest, in1, in2);
349698cd9ca7SRichard Henderson 
3497f764718dSRichard Henderson     sv = NULL;
3498b47a4a02SSven Schnelle     if (cond_need_sv(c)) {
349998cd9ca7SRichard Henderson         sv = do_sub_sv(ctx, dest, in1, in2);
350098cd9ca7SRichard Henderson     }
350198cd9ca7SRichard Henderson 
35024fe9533aSRichard Henderson     cond = do_sub_cond(ctx, c * 2 + f, d, dest, in1, in2, sv);
350301afb7beSRichard Henderson     return do_cbranch(ctx, disp, n, &cond);
350498cd9ca7SRichard Henderson }
350598cd9ca7SRichard Henderson 
trans_cmpb(DisasContext * ctx,arg_cmpb * a)350601afb7beSRichard Henderson static bool trans_cmpb(DisasContext *ctx, arg_cmpb *a)
350798cd9ca7SRichard Henderson {
3508e9efd4bcSRichard Henderson     if (!ctx->is_pa20 && a->d) {
3509e9efd4bcSRichard Henderson         return false;
3510e9efd4bcSRichard Henderson     }
351101afb7beSRichard Henderson     nullify_over(ctx);
3512e9efd4bcSRichard Henderson     return do_cmpb(ctx, a->r2, load_gpr(ctx, a->r1),
3513e9efd4bcSRichard Henderson                    a->c, a->f, a->d, a->n, a->disp);
351401afb7beSRichard Henderson }
351501afb7beSRichard Henderson 
trans_cmpbi(DisasContext * ctx,arg_cmpbi * a)351601afb7beSRichard Henderson static bool trans_cmpbi(DisasContext *ctx, arg_cmpbi *a)
351701afb7beSRichard Henderson {
3518c65c3ee1SRichard Henderson     if (!ctx->is_pa20 && a->d) {
3519c65c3ee1SRichard Henderson         return false;
3520c65c3ee1SRichard Henderson     }
352101afb7beSRichard Henderson     nullify_over(ctx);
35226fd0c7bcSRichard Henderson     return do_cmpb(ctx, a->r, tcg_constant_i64(a->i),
3523c65c3ee1SRichard Henderson                    a->c, a->f, a->d, a->n, a->disp);
352401afb7beSRichard Henderson }
352501afb7beSRichard Henderson 
do_addb(DisasContext * ctx,unsigned r,TCGv_i64 in1,unsigned c,unsigned f,unsigned n,int disp)35266fd0c7bcSRichard Henderson static bool do_addb(DisasContext *ctx, unsigned r, TCGv_i64 in1,
352701afb7beSRichard Henderson                     unsigned c, unsigned f, unsigned n, int disp)
352801afb7beSRichard Henderson {
35296fd0c7bcSRichard Henderson     TCGv_i64 dest, in2, sv, cb_cond;
353098cd9ca7SRichard Henderson     DisasCond cond;
3531bdcccc17SRichard Henderson     bool d = false;
353298cd9ca7SRichard Henderson 
3533f25d3160SRichard Henderson     /*
3534f25d3160SRichard Henderson      * For hppa64, the ADDB conditions change with PSW.W,
3535f25d3160SRichard Henderson      * dropping ZNV, SV, OD in favor of double-word EQ, LT, LE.
3536f25d3160SRichard Henderson      */
3537f25d3160SRichard Henderson     if (ctx->tb_flags & PSW_W) {
3538f25d3160SRichard Henderson         d = c >= 5;
3539f25d3160SRichard Henderson         if (d) {
3540f25d3160SRichard Henderson             c &= 3;
3541f25d3160SRichard Henderson         }
3542f25d3160SRichard Henderson     }
3543f25d3160SRichard Henderson 
354498cd9ca7SRichard Henderson     in2 = load_gpr(ctx, r);
3545aac0f603SRichard Henderson     dest = tcg_temp_new_i64();
3546f764718dSRichard Henderson     sv = NULL;
3547bdcccc17SRichard Henderson     cb_cond = NULL;
354898cd9ca7SRichard Henderson 
3549b47a4a02SSven Schnelle     if (cond_need_cb(c)) {
3550aac0f603SRichard Henderson         TCGv_i64 cb = tcg_temp_new_i64();
3551aac0f603SRichard Henderson         TCGv_i64 cb_msb = tcg_temp_new_i64();
3552bdcccc17SRichard Henderson 
35536fd0c7bcSRichard Henderson         tcg_gen_movi_i64(cb_msb, 0);
35546fd0c7bcSRichard Henderson         tcg_gen_add2_i64(dest, cb_msb, in1, cb_msb, in2, cb_msb);
35556fd0c7bcSRichard Henderson         tcg_gen_xor_i64(cb, in1, in2);
35566fd0c7bcSRichard Henderson         tcg_gen_xor_i64(cb, cb, dest);
3557bdcccc17SRichard Henderson         cb_cond = get_carry(ctx, d, cb, cb_msb);
3558b47a4a02SSven Schnelle     } else {
35596fd0c7bcSRichard Henderson         tcg_gen_add_i64(dest, in1, in2);
3560b47a4a02SSven Schnelle     }
3561b47a4a02SSven Schnelle     if (cond_need_sv(c)) {
3562f8f5986eSRichard Henderson         sv = do_add_sv(ctx, dest, in1, in2, in1, 0, d);
356398cd9ca7SRichard Henderson     }
356498cd9ca7SRichard Henderson 
3565a751eb31SRichard Henderson     cond = do_cond(ctx, c * 2 + f, d, dest, cb_cond, sv);
356643675d20SSven Schnelle     save_gpr(ctx, r, dest);
356701afb7beSRichard Henderson     return do_cbranch(ctx, disp, n, &cond);
356898cd9ca7SRichard Henderson }
356998cd9ca7SRichard Henderson 
trans_addb(DisasContext * ctx,arg_addb * a)357001afb7beSRichard Henderson static bool trans_addb(DisasContext *ctx, arg_addb *a)
357198cd9ca7SRichard Henderson {
357201afb7beSRichard Henderson     nullify_over(ctx);
357301afb7beSRichard Henderson     return do_addb(ctx, a->r2, load_gpr(ctx, a->r1), a->c, a->f, a->n, a->disp);
357401afb7beSRichard Henderson }
357501afb7beSRichard Henderson 
trans_addbi(DisasContext * ctx,arg_addbi * a)357601afb7beSRichard Henderson static bool trans_addbi(DisasContext *ctx, arg_addbi *a)
357701afb7beSRichard Henderson {
357801afb7beSRichard Henderson     nullify_over(ctx);
35796fd0c7bcSRichard Henderson     return do_addb(ctx, a->r, tcg_constant_i64(a->i), a->c, a->f, a->n, a->disp);
358001afb7beSRichard Henderson }
358101afb7beSRichard Henderson 
trans_bb_sar(DisasContext * ctx,arg_bb_sar * a)358201afb7beSRichard Henderson static bool trans_bb_sar(DisasContext *ctx, arg_bb_sar *a)
358301afb7beSRichard Henderson {
35846fd0c7bcSRichard Henderson     TCGv_i64 tmp, tcg_r;
358598cd9ca7SRichard Henderson     DisasCond cond;
358698cd9ca7SRichard Henderson 
358798cd9ca7SRichard Henderson     nullify_over(ctx);
358898cd9ca7SRichard Henderson 
3589aac0f603SRichard Henderson     tmp = tcg_temp_new_i64();
359001afb7beSRichard Henderson     tcg_r = load_gpr(ctx, a->r);
359182d0c831SRichard Henderson     if (a->d) {
359282d0c831SRichard Henderson         tcg_gen_shl_i64(tmp, tcg_r, cpu_sar);
359382d0c831SRichard Henderson     } else {
35941e9ab9fbSRichard Henderson         /* Force shift into [32,63] */
35956fd0c7bcSRichard Henderson         tcg_gen_ori_i64(tmp, cpu_sar, 32);
35966fd0c7bcSRichard Henderson         tcg_gen_shl_i64(tmp, tcg_r, tmp);
35971e9ab9fbSRichard Henderson     }
359898cd9ca7SRichard Henderson 
35994c42fd0dSRichard Henderson     cond = cond_make_ti(a->c ? TCG_COND_GE : TCG_COND_LT, tmp, 0);
360001afb7beSRichard Henderson     return do_cbranch(ctx, a->disp, a->n, &cond);
360198cd9ca7SRichard Henderson }
360298cd9ca7SRichard Henderson 
trans_bb_imm(DisasContext * ctx,arg_bb_imm * a)360301afb7beSRichard Henderson static bool trans_bb_imm(DisasContext *ctx, arg_bb_imm *a)
360498cd9ca7SRichard Henderson {
360501afb7beSRichard Henderson     DisasCond cond;
3606b041ec9dSRichard Henderson     int p = a->p | (a->d ? 0 : 32);
360701afb7beSRichard Henderson 
360801afb7beSRichard Henderson     nullify_over(ctx);
3609b041ec9dSRichard Henderson     cond = cond_make_vi(a->c ? TCG_COND_TSTEQ : TCG_COND_TSTNE,
3610b041ec9dSRichard Henderson                         load_gpr(ctx, a->r), 1ull << (63 - p));
361101afb7beSRichard Henderson     return do_cbranch(ctx, a->disp, a->n, &cond);
361201afb7beSRichard Henderson }
361301afb7beSRichard Henderson 
trans_movb(DisasContext * ctx,arg_movb * a)361401afb7beSRichard Henderson static bool trans_movb(DisasContext *ctx, arg_movb *a)
361501afb7beSRichard Henderson {
36166fd0c7bcSRichard Henderson     TCGv_i64 dest;
361798cd9ca7SRichard Henderson     DisasCond cond;
361898cd9ca7SRichard Henderson 
361998cd9ca7SRichard Henderson     nullify_over(ctx);
362098cd9ca7SRichard Henderson 
362101afb7beSRichard Henderson     dest = dest_gpr(ctx, a->r2);
362201afb7beSRichard Henderson     if (a->r1 == 0) {
36236fd0c7bcSRichard Henderson         tcg_gen_movi_i64(dest, 0);
362498cd9ca7SRichard Henderson     } else {
36256fd0c7bcSRichard Henderson         tcg_gen_mov_i64(dest, cpu_gr[a->r1]);
362698cd9ca7SRichard Henderson     }
362798cd9ca7SRichard Henderson 
36284fa52edfSRichard Henderson     /* All MOVB conditions are 32-bit. */
36294fa52edfSRichard Henderson     cond = do_sed_cond(ctx, a->c, false, dest);
363001afb7beSRichard Henderson     return do_cbranch(ctx, a->disp, a->n, &cond);
363101afb7beSRichard Henderson }
363201afb7beSRichard Henderson 
trans_movbi(DisasContext * ctx,arg_movbi * a)363301afb7beSRichard Henderson static bool trans_movbi(DisasContext *ctx, arg_movbi *a)
363401afb7beSRichard Henderson {
36356fd0c7bcSRichard Henderson     TCGv_i64 dest;
363601afb7beSRichard Henderson     DisasCond cond;
363701afb7beSRichard Henderson 
363801afb7beSRichard Henderson     nullify_over(ctx);
363901afb7beSRichard Henderson 
364001afb7beSRichard Henderson     dest = dest_gpr(ctx, a->r);
36416fd0c7bcSRichard Henderson     tcg_gen_movi_i64(dest, a->i);
364201afb7beSRichard Henderson 
36434fa52edfSRichard Henderson     /* All MOVBI conditions are 32-bit. */
36444fa52edfSRichard Henderson     cond = do_sed_cond(ctx, a->c, false, dest);
364501afb7beSRichard Henderson     return do_cbranch(ctx, a->disp, a->n, &cond);
364698cd9ca7SRichard Henderson }
364798cd9ca7SRichard Henderson 
trans_shrp_sar(DisasContext * ctx,arg_shrp_sar * a)3648f7b775a9SRichard Henderson static bool trans_shrp_sar(DisasContext *ctx, arg_shrp_sar *a)
36490b1347d2SRichard Henderson {
36506fd0c7bcSRichard Henderson     TCGv_i64 dest, src2;
36510b1347d2SRichard Henderson 
3652f7b775a9SRichard Henderson     if (!ctx->is_pa20 && a->d) {
3653f7b775a9SRichard Henderson         return false;
3654f7b775a9SRichard Henderson     }
365530878590SRichard Henderson     if (a->c) {
36560b1347d2SRichard Henderson         nullify_over(ctx);
36570b1347d2SRichard Henderson     }
36580b1347d2SRichard Henderson 
365930878590SRichard Henderson     dest = dest_gpr(ctx, a->t);
3660f7b775a9SRichard Henderson     src2 = load_gpr(ctx, a->r2);
366130878590SRichard Henderson     if (a->r1 == 0) {
3662f7b775a9SRichard Henderson         if (a->d) {
36636fd0c7bcSRichard Henderson             tcg_gen_shr_i64(dest, src2, cpu_sar);
3664f7b775a9SRichard Henderson         } else {
3665aac0f603SRichard Henderson             TCGv_i64 tmp = tcg_temp_new_i64();
3666f7b775a9SRichard Henderson 
36676fd0c7bcSRichard Henderson             tcg_gen_ext32u_i64(dest, src2);
36686fd0c7bcSRichard Henderson             tcg_gen_andi_i64(tmp, cpu_sar, 31);
36696fd0c7bcSRichard Henderson             tcg_gen_shr_i64(dest, dest, tmp);
3670f7b775a9SRichard Henderson         }
367130878590SRichard Henderson     } else if (a->r1 == a->r2) {
3672f7b775a9SRichard Henderson         if (a->d) {
36736fd0c7bcSRichard Henderson             tcg_gen_rotr_i64(dest, src2, cpu_sar);
3674f7b775a9SRichard Henderson         } else {
36750b1347d2SRichard Henderson             TCGv_i32 t32 = tcg_temp_new_i32();
3676e1d635e8SRichard Henderson             TCGv_i32 s32 = tcg_temp_new_i32();
3677e1d635e8SRichard Henderson 
36786fd0c7bcSRichard Henderson             tcg_gen_extrl_i64_i32(t32, src2);
36796fd0c7bcSRichard Henderson             tcg_gen_extrl_i64_i32(s32, cpu_sar);
3680f7b775a9SRichard Henderson             tcg_gen_andi_i32(s32, s32, 31);
3681e1d635e8SRichard Henderson             tcg_gen_rotr_i32(t32, t32, s32);
36826fd0c7bcSRichard Henderson             tcg_gen_extu_i32_i64(dest, t32);
3683f7b775a9SRichard Henderson         }
3684f7b775a9SRichard Henderson     } else {
36856fd0c7bcSRichard Henderson         TCGv_i64 src1 = load_gpr(ctx, a->r1);
3686f7b775a9SRichard Henderson 
3687f7b775a9SRichard Henderson         if (a->d) {
3688aac0f603SRichard Henderson             TCGv_i64 t = tcg_temp_new_i64();
3689aac0f603SRichard Henderson             TCGv_i64 n = tcg_temp_new_i64();
3690f7b775a9SRichard Henderson 
36916fd0c7bcSRichard Henderson             tcg_gen_xori_i64(n, cpu_sar, 63);
3692a01491a2SHelge Deller             tcg_gen_shl_i64(t, src1, n);
36936fd0c7bcSRichard Henderson             tcg_gen_shli_i64(t, t, 1);
3694a01491a2SHelge Deller             tcg_gen_shr_i64(dest, src2, cpu_sar);
36956fd0c7bcSRichard Henderson             tcg_gen_or_i64(dest, dest, t);
36960b1347d2SRichard Henderson         } else {
36970b1347d2SRichard Henderson             TCGv_i64 t = tcg_temp_new_i64();
36980b1347d2SRichard Henderson             TCGv_i64 s = tcg_temp_new_i64();
36990b1347d2SRichard Henderson 
37006fd0c7bcSRichard Henderson             tcg_gen_concat32_i64(t, src2, src1);
3701967662cdSRichard Henderson             tcg_gen_andi_i64(s, cpu_sar, 31);
3702967662cdSRichard Henderson             tcg_gen_shr_i64(dest, t, s);
37030b1347d2SRichard Henderson         }
3704f7b775a9SRichard Henderson     }
370530878590SRichard Henderson     save_gpr(ctx, a->t, dest);
37060b1347d2SRichard Henderson 
37070b1347d2SRichard Henderson     /* Install the new nullification.  */
3708d37fad0aSSven Schnelle     ctx->null_cond = do_sed_cond(ctx, a->c, a->d, dest);
370931234768SRichard Henderson     return nullify_end(ctx);
37100b1347d2SRichard Henderson }
37110b1347d2SRichard Henderson 
trans_shrp_imm(DisasContext * ctx,arg_shrp_imm * a)3712f7b775a9SRichard Henderson static bool trans_shrp_imm(DisasContext *ctx, arg_shrp_imm *a)
37130b1347d2SRichard Henderson {
3714f7b775a9SRichard Henderson     unsigned width, sa;
37156fd0c7bcSRichard Henderson     TCGv_i64 dest, t2;
37160b1347d2SRichard Henderson 
3717f7b775a9SRichard Henderson     if (!ctx->is_pa20 && a->d) {
3718f7b775a9SRichard Henderson         return false;
3719f7b775a9SRichard Henderson     }
372030878590SRichard Henderson     if (a->c) {
37210b1347d2SRichard Henderson         nullify_over(ctx);
37220b1347d2SRichard Henderson     }
37230b1347d2SRichard Henderson 
3724f7b775a9SRichard Henderson     width = a->d ? 64 : 32;
3725f7b775a9SRichard Henderson     sa = width - 1 - a->cpos;
3726f7b775a9SRichard Henderson 
372730878590SRichard Henderson     dest = dest_gpr(ctx, a->t);
372830878590SRichard Henderson     t2 = load_gpr(ctx, a->r2);
372905bfd4dbSRichard Henderson     if (a->r1 == 0) {
37306fd0c7bcSRichard Henderson         tcg_gen_extract_i64(dest, t2, sa, width - sa);
3731c53e401eSRichard Henderson     } else if (width == TARGET_LONG_BITS) {
37326fd0c7bcSRichard Henderson         tcg_gen_extract2_i64(dest, t2, cpu_gr[a->r1], sa);
3733f7b775a9SRichard Henderson     } else {
3734f7b775a9SRichard Henderson         assert(!a->d);
3735f7b775a9SRichard Henderson         if (a->r1 == a->r2) {
37360b1347d2SRichard Henderson             TCGv_i32 t32 = tcg_temp_new_i32();
37376fd0c7bcSRichard Henderson             tcg_gen_extrl_i64_i32(t32, t2);
37380b1347d2SRichard Henderson             tcg_gen_rotri_i32(t32, t32, sa);
37396fd0c7bcSRichard Henderson             tcg_gen_extu_i32_i64(dest, t32);
37400b1347d2SRichard Henderson         } else {
3741967662cdSRichard Henderson             tcg_gen_concat32_i64(dest, t2, cpu_gr[a->r1]);
3742967662cdSRichard Henderson             tcg_gen_extract_i64(dest, dest, sa, 32);
37430b1347d2SRichard Henderson         }
3744f7b775a9SRichard Henderson     }
374530878590SRichard Henderson     save_gpr(ctx, a->t, dest);
37460b1347d2SRichard Henderson 
37470b1347d2SRichard Henderson     /* Install the new nullification.  */
3748d37fad0aSSven Schnelle     ctx->null_cond = do_sed_cond(ctx, a->c, a->d, dest);
374931234768SRichard Henderson     return nullify_end(ctx);
37500b1347d2SRichard Henderson }
37510b1347d2SRichard Henderson 
trans_extr_sar(DisasContext * ctx,arg_extr_sar * a)3752bd792da3SRichard Henderson static bool trans_extr_sar(DisasContext *ctx, arg_extr_sar *a)
37530b1347d2SRichard Henderson {
3754bd792da3SRichard Henderson     unsigned widthm1 = a->d ? 63 : 31;
37556fd0c7bcSRichard Henderson     TCGv_i64 dest, src, tmp;
37560b1347d2SRichard Henderson 
3757bd792da3SRichard Henderson     if (!ctx->is_pa20 && a->d) {
3758bd792da3SRichard Henderson         return false;
3759bd792da3SRichard Henderson     }
376030878590SRichard Henderson     if (a->c) {
37610b1347d2SRichard Henderson         nullify_over(ctx);
37620b1347d2SRichard Henderson     }
37630b1347d2SRichard Henderson 
376430878590SRichard Henderson     dest = dest_gpr(ctx, a->t);
376530878590SRichard Henderson     src = load_gpr(ctx, a->r);
3766aac0f603SRichard Henderson     tmp = tcg_temp_new_i64();
37670b1347d2SRichard Henderson 
37680b1347d2SRichard Henderson     /* Recall that SAR is using big-endian bit numbering.  */
37696fd0c7bcSRichard Henderson     tcg_gen_andi_i64(tmp, cpu_sar, widthm1);
37706fd0c7bcSRichard Henderson     tcg_gen_xori_i64(tmp, tmp, widthm1);
3771d781cb77SRichard Henderson 
377230878590SRichard Henderson     if (a->se) {
3773bd792da3SRichard Henderson         if (!a->d) {
37746fd0c7bcSRichard Henderson             tcg_gen_ext32s_i64(dest, src);
3775bd792da3SRichard Henderson             src = dest;
3776bd792da3SRichard Henderson         }
37776fd0c7bcSRichard Henderson         tcg_gen_sar_i64(dest, src, tmp);
37786fd0c7bcSRichard Henderson         tcg_gen_sextract_i64(dest, dest, 0, a->len);
37790b1347d2SRichard Henderson     } else {
3780bd792da3SRichard Henderson         if (!a->d) {
37816fd0c7bcSRichard Henderson             tcg_gen_ext32u_i64(dest, src);
3782bd792da3SRichard Henderson             src = dest;
3783bd792da3SRichard Henderson         }
37846fd0c7bcSRichard Henderson         tcg_gen_shr_i64(dest, src, tmp);
37856fd0c7bcSRichard Henderson         tcg_gen_extract_i64(dest, dest, 0, a->len);
37860b1347d2SRichard Henderson     }
378730878590SRichard Henderson     save_gpr(ctx, a->t, dest);
37880b1347d2SRichard Henderson 
37890b1347d2SRichard Henderson     /* Install the new nullification.  */
3790bd792da3SRichard Henderson     ctx->null_cond = do_sed_cond(ctx, a->c, a->d, dest);
379131234768SRichard Henderson     return nullify_end(ctx);
37920b1347d2SRichard Henderson }
37930b1347d2SRichard Henderson 
trans_extr_imm(DisasContext * ctx,arg_extr_imm * a)3794bd792da3SRichard Henderson static bool trans_extr_imm(DisasContext *ctx, arg_extr_imm *a)
37950b1347d2SRichard Henderson {
3796bd792da3SRichard Henderson     unsigned len, cpos, width;
37976fd0c7bcSRichard Henderson     TCGv_i64 dest, src;
37980b1347d2SRichard Henderson 
3799bd792da3SRichard Henderson     if (!ctx->is_pa20 && a->d) {
3800bd792da3SRichard Henderson         return false;
3801bd792da3SRichard Henderson     }
380230878590SRichard Henderson     if (a->c) {
38030b1347d2SRichard Henderson         nullify_over(ctx);
38040b1347d2SRichard Henderson     }
38050b1347d2SRichard Henderson 
3806bd792da3SRichard Henderson     len = a->len;
3807bd792da3SRichard Henderson     width = a->d ? 64 : 32;
3808bd792da3SRichard Henderson     cpos = width - 1 - a->pos;
3809bd792da3SRichard Henderson     if (cpos + len > width) {
3810bd792da3SRichard Henderson         len = width - cpos;
3811bd792da3SRichard Henderson     }
3812bd792da3SRichard Henderson 
381330878590SRichard Henderson     dest = dest_gpr(ctx, a->t);
381430878590SRichard Henderson     src = load_gpr(ctx, a->r);
381530878590SRichard Henderson     if (a->se) {
38166fd0c7bcSRichard Henderson         tcg_gen_sextract_i64(dest, src, cpos, len);
38170b1347d2SRichard Henderson     } else {
38186fd0c7bcSRichard Henderson         tcg_gen_extract_i64(dest, src, cpos, len);
38190b1347d2SRichard Henderson     }
382030878590SRichard Henderson     save_gpr(ctx, a->t, dest);
38210b1347d2SRichard Henderson 
38220b1347d2SRichard Henderson     /* Install the new nullification.  */
3823bd792da3SRichard Henderson     ctx->null_cond = do_sed_cond(ctx, a->c, a->d, dest);
382431234768SRichard Henderson     return nullify_end(ctx);
38250b1347d2SRichard Henderson }
38260b1347d2SRichard Henderson 
trans_depi_imm(DisasContext * ctx,arg_depi_imm * a)382772ae4f2bSRichard Henderson static bool trans_depi_imm(DisasContext *ctx, arg_depi_imm *a)
38280b1347d2SRichard Henderson {
382972ae4f2bSRichard Henderson     unsigned len, width;
3830c53e401eSRichard Henderson     uint64_t mask0, mask1;
38316fd0c7bcSRichard Henderson     TCGv_i64 dest;
38320b1347d2SRichard Henderson 
383372ae4f2bSRichard Henderson     if (!ctx->is_pa20 && a->d) {
383472ae4f2bSRichard Henderson         return false;
383572ae4f2bSRichard Henderson     }
383630878590SRichard Henderson     if (a->c) {
38370b1347d2SRichard Henderson         nullify_over(ctx);
38380b1347d2SRichard Henderson     }
383972ae4f2bSRichard Henderson 
384072ae4f2bSRichard Henderson     len = a->len;
384172ae4f2bSRichard Henderson     width = a->d ? 64 : 32;
384272ae4f2bSRichard Henderson     if (a->cpos + len > width) {
384372ae4f2bSRichard Henderson         len = width - a->cpos;
38440b1347d2SRichard Henderson     }
38450b1347d2SRichard Henderson 
384630878590SRichard Henderson     dest = dest_gpr(ctx, a->t);
384730878590SRichard Henderson     mask0 = deposit64(0, a->cpos, len, a->i);
384830878590SRichard Henderson     mask1 = deposit64(-1, a->cpos, len, a->i);
38490b1347d2SRichard Henderson 
385030878590SRichard Henderson     if (a->nz) {
38516fd0c7bcSRichard Henderson         TCGv_i64 src = load_gpr(ctx, a->t);
38526fd0c7bcSRichard Henderson         tcg_gen_andi_i64(dest, src, mask1);
38536fd0c7bcSRichard Henderson         tcg_gen_ori_i64(dest, dest, mask0);
38540b1347d2SRichard Henderson     } else {
38556fd0c7bcSRichard Henderson         tcg_gen_movi_i64(dest, mask0);
38560b1347d2SRichard Henderson     }
385730878590SRichard Henderson     save_gpr(ctx, a->t, dest);
38580b1347d2SRichard Henderson 
38590b1347d2SRichard Henderson     /* Install the new nullification.  */
386072ae4f2bSRichard Henderson     ctx->null_cond = do_sed_cond(ctx, a->c, a->d, dest);
386131234768SRichard Henderson     return nullify_end(ctx);
38620b1347d2SRichard Henderson }
38630b1347d2SRichard Henderson 
trans_dep_imm(DisasContext * ctx,arg_dep_imm * a)386472ae4f2bSRichard Henderson static bool trans_dep_imm(DisasContext *ctx, arg_dep_imm *a)
38650b1347d2SRichard Henderson {
386630878590SRichard Henderson     unsigned rs = a->nz ? a->t : 0;
386772ae4f2bSRichard Henderson     unsigned len, width;
38686fd0c7bcSRichard Henderson     TCGv_i64 dest, val;
38690b1347d2SRichard Henderson 
387072ae4f2bSRichard Henderson     if (!ctx->is_pa20 && a->d) {
387172ae4f2bSRichard Henderson         return false;
387272ae4f2bSRichard Henderson     }
387330878590SRichard Henderson     if (a->c) {
38740b1347d2SRichard Henderson         nullify_over(ctx);
38750b1347d2SRichard Henderson     }
387672ae4f2bSRichard Henderson 
387772ae4f2bSRichard Henderson     len = a->len;
387872ae4f2bSRichard Henderson     width = a->d ? 64 : 32;
387972ae4f2bSRichard Henderson     if (a->cpos + len > width) {
388072ae4f2bSRichard Henderson         len = width - a->cpos;
38810b1347d2SRichard Henderson     }
38820b1347d2SRichard Henderson 
388330878590SRichard Henderson     dest = dest_gpr(ctx, a->t);
388430878590SRichard Henderson     val = load_gpr(ctx, a->r);
38850b1347d2SRichard Henderson     if (rs == 0) {
38866fd0c7bcSRichard Henderson         tcg_gen_deposit_z_i64(dest, val, a->cpos, len);
38870b1347d2SRichard Henderson     } else {
38886fd0c7bcSRichard Henderson         tcg_gen_deposit_i64(dest, cpu_gr[rs], val, a->cpos, len);
38890b1347d2SRichard Henderson     }
389030878590SRichard Henderson     save_gpr(ctx, a->t, dest);
38910b1347d2SRichard Henderson 
38920b1347d2SRichard Henderson     /* Install the new nullification.  */
389372ae4f2bSRichard Henderson     ctx->null_cond = do_sed_cond(ctx, a->c, a->d, dest);
389431234768SRichard Henderson     return nullify_end(ctx);
38950b1347d2SRichard Henderson }
38960b1347d2SRichard Henderson 
do_dep_sar(DisasContext * ctx,unsigned rt,unsigned c,bool d,bool nz,unsigned len,TCGv_i64 val)389772ae4f2bSRichard Henderson static bool do_dep_sar(DisasContext *ctx, unsigned rt, unsigned c,
38986fd0c7bcSRichard Henderson                        bool d, bool nz, unsigned len, TCGv_i64 val)
38990b1347d2SRichard Henderson {
39000b1347d2SRichard Henderson     unsigned rs = nz ? rt : 0;
390172ae4f2bSRichard Henderson     unsigned widthm1 = d ? 63 : 31;
39026fd0c7bcSRichard Henderson     TCGv_i64 mask, tmp, shift, dest;
3903c53e401eSRichard Henderson     uint64_t msb = 1ULL << (len - 1);
39040b1347d2SRichard Henderson 
39050b1347d2SRichard Henderson     dest = dest_gpr(ctx, rt);
3906aac0f603SRichard Henderson     shift = tcg_temp_new_i64();
3907aac0f603SRichard Henderson     tmp = tcg_temp_new_i64();
39080b1347d2SRichard Henderson 
39090b1347d2SRichard Henderson     /* Convert big-endian bit numbering in SAR to left-shift.  */
39106fd0c7bcSRichard Henderson     tcg_gen_andi_i64(shift, cpu_sar, widthm1);
39116fd0c7bcSRichard Henderson     tcg_gen_xori_i64(shift, shift, widthm1);
39120b1347d2SRichard Henderson 
3913aac0f603SRichard Henderson     mask = tcg_temp_new_i64();
39146fd0c7bcSRichard Henderson     tcg_gen_movi_i64(mask, msb + (msb - 1));
39156fd0c7bcSRichard Henderson     tcg_gen_and_i64(tmp, val, mask);
39160b1347d2SRichard Henderson     if (rs) {
39176fd0c7bcSRichard Henderson         tcg_gen_shl_i64(mask, mask, shift);
39186fd0c7bcSRichard Henderson         tcg_gen_shl_i64(tmp, tmp, shift);
39196fd0c7bcSRichard Henderson         tcg_gen_andc_i64(dest, cpu_gr[rs], mask);
39206fd0c7bcSRichard Henderson         tcg_gen_or_i64(dest, dest, tmp);
39210b1347d2SRichard Henderson     } else {
39226fd0c7bcSRichard Henderson         tcg_gen_shl_i64(dest, tmp, shift);
39230b1347d2SRichard Henderson     }
39240b1347d2SRichard Henderson     save_gpr(ctx, rt, dest);
39250b1347d2SRichard Henderson 
39260b1347d2SRichard Henderson     /* Install the new nullification.  */
392772ae4f2bSRichard Henderson     ctx->null_cond = do_sed_cond(ctx, c, d, dest);
392831234768SRichard Henderson     return nullify_end(ctx);
39290b1347d2SRichard Henderson }
39300b1347d2SRichard Henderson 
trans_dep_sar(DisasContext * ctx,arg_dep_sar * a)393172ae4f2bSRichard Henderson static bool trans_dep_sar(DisasContext *ctx, arg_dep_sar *a)
393230878590SRichard Henderson {
393372ae4f2bSRichard Henderson     if (!ctx->is_pa20 && a->d) {
393472ae4f2bSRichard Henderson         return false;
393572ae4f2bSRichard Henderson     }
3936a6deecceSSven Schnelle     if (a->c) {
3937a6deecceSSven Schnelle         nullify_over(ctx);
3938a6deecceSSven Schnelle     }
393972ae4f2bSRichard Henderson     return do_dep_sar(ctx, a->t, a->c, a->d, a->nz, a->len,
394072ae4f2bSRichard Henderson                       load_gpr(ctx, a->r));
394130878590SRichard Henderson }
394230878590SRichard Henderson 
trans_depi_sar(DisasContext * ctx,arg_depi_sar * a)394372ae4f2bSRichard Henderson static bool trans_depi_sar(DisasContext *ctx, arg_depi_sar *a)
394430878590SRichard Henderson {
394572ae4f2bSRichard Henderson     if (!ctx->is_pa20 && a->d) {
394672ae4f2bSRichard Henderson         return false;
394772ae4f2bSRichard Henderson     }
3948a6deecceSSven Schnelle     if (a->c) {
3949a6deecceSSven Schnelle         nullify_over(ctx);
3950a6deecceSSven Schnelle     }
395172ae4f2bSRichard Henderson     return do_dep_sar(ctx, a->t, a->c, a->d, a->nz, a->len,
39526fd0c7bcSRichard Henderson                       tcg_constant_i64(a->i));
395330878590SRichard Henderson }
39540b1347d2SRichard Henderson 
trans_be(DisasContext * ctx,arg_be * a)39558340f534SRichard Henderson static bool trans_be(DisasContext *ctx, arg_be *a)
395698cd9ca7SRichard Henderson {
3957019f4159SRichard Henderson #ifndef CONFIG_USER_ONLY
3958bc921866SRichard Henderson     ctx->iaq_j.space = tcg_temp_new_i64();
3959bc921866SRichard Henderson     load_spr(ctx, ctx->iaq_j.space, a->sp);
3960660eefe1SRichard Henderson #endif
3961660eefe1SRichard Henderson 
3962bc921866SRichard Henderson     ctx->iaq_j.base = tcg_temp_new_i64();
3963bc921866SRichard Henderson     ctx->iaq_j.disp = 0;
3964c301f34eSRichard Henderson 
3965bc921866SRichard Henderson     tcg_gen_addi_i64(ctx->iaq_j.base, load_gpr(ctx, a->b), a->disp);
3966bc921866SRichard Henderson     ctx->iaq_j.base = do_ibranch_priv(ctx, ctx->iaq_j.base);
3967c301f34eSRichard Henderson 
3968bc921866SRichard Henderson     return do_ibranch(ctx, a->l, true, a->n);
396998cd9ca7SRichard Henderson }
397098cd9ca7SRichard Henderson 
trans_bl(DisasContext * ctx,arg_bl * a)39718340f534SRichard Henderson static bool trans_bl(DisasContext *ctx, arg_bl *a)
397298cd9ca7SRichard Henderson {
39732644f80bSRichard Henderson     return do_dbranch(ctx, a->disp, a->l, a->n);
397498cd9ca7SRichard Henderson }
397598cd9ca7SRichard Henderson 
trans_b_gate(DisasContext * ctx,arg_b_gate * a)39768340f534SRichard Henderson static bool trans_b_gate(DisasContext *ctx, arg_b_gate *a)
397743e05652SRichard Henderson {
3978bc921866SRichard Henderson     int64_t disp = a->disp;
3979804cd52dSRichard Henderson     bool indirect = false;
398043e05652SRichard Henderson 
39815ae8adbbSRichard Henderson     /* Trap if PSW[B] is set. */
39825ae8adbbSRichard Henderson     if (ctx->psw_xb & PSW_B) {
398343e05652SRichard Henderson         return gen_illegal(ctx);
398443e05652SRichard Henderson     }
398543e05652SRichard Henderson 
39865ae8adbbSRichard Henderson     nullify_over(ctx);
39875ae8adbbSRichard Henderson 
398843e05652SRichard Henderson #ifndef CONFIG_USER_ONLY
3989804cd52dSRichard Henderson     if (ctx->privilege == 0) {
3990804cd52dSRichard Henderson         /* Privilege cannot decrease. */
3991804cd52dSRichard Henderson     } else if (!(ctx->tb_flags & PSW_C)) {
3992804cd52dSRichard Henderson         /* With paging disabled, priv becomes 0. */
3993bc921866SRichard Henderson         disp -= ctx->privilege;
399443e05652SRichard Henderson     } else {
3995804cd52dSRichard Henderson         /* Adjust the dest offset for the privilege change from the PTE. */
3996804cd52dSRichard Henderson         TCGv_i64 off = tcg_temp_new_i64();
3997804cd52dSRichard Henderson 
3998*6dd9b145SRichard Henderson         copy_iaoq_entry(ctx, off, &ctx->iaq_f);
3999*6dd9b145SRichard Henderson         gen_helper_b_gate_priv(off, tcg_env, off);
4000804cd52dSRichard Henderson 
4001804cd52dSRichard Henderson         ctx->iaq_j.base = off;
4002804cd52dSRichard Henderson         ctx->iaq_j.disp = disp + 8;
4003804cd52dSRichard Henderson         indirect = true;
400443e05652SRichard Henderson     }
400543e05652SRichard Henderson #endif
400643e05652SRichard Henderson 
40076e5f5300SSven Schnelle     if (a->l) {
40086fd0c7bcSRichard Henderson         TCGv_i64 tmp = dest_gpr(ctx, a->l);
40096e5f5300SSven Schnelle         if (ctx->privilege < 3) {
40106fd0c7bcSRichard Henderson             tcg_gen_andi_i64(tmp, tmp, -4);
40116e5f5300SSven Schnelle         }
40126fd0c7bcSRichard Henderson         tcg_gen_ori_i64(tmp, tmp, ctx->privilege);
40136e5f5300SSven Schnelle         save_gpr(ctx, a->l, tmp);
40146e5f5300SSven Schnelle     }
40156e5f5300SSven Schnelle 
4016804cd52dSRichard Henderson     if (indirect) {
4017804cd52dSRichard Henderson         return do_ibranch(ctx, 0, false, a->n);
4018804cd52dSRichard Henderson     }
4019bc921866SRichard Henderson     return do_dbranch(ctx, disp, 0, a->n);
402043e05652SRichard Henderson }
402143e05652SRichard Henderson 
trans_blr(DisasContext * ctx,arg_blr * a)40228340f534SRichard Henderson static bool trans_blr(DisasContext *ctx, arg_blr *a)
402398cd9ca7SRichard Henderson {
4024b35aec85SRichard Henderson     if (a->x) {
4025bc921866SRichard Henderson         DisasIAQE next = iaqe_incr(&ctx->iaq_f, 8);
4026bc921866SRichard Henderson         TCGv_i64 t0 = tcg_temp_new_i64();
4027bc921866SRichard Henderson         TCGv_i64 t1 = tcg_temp_new_i64();
4028bc921866SRichard Henderson 
4029660eefe1SRichard Henderson         /* The computation here never changes privilege level.  */
4030bc921866SRichard Henderson         copy_iaoq_entry(ctx, t0, &next);
4031bc921866SRichard Henderson         tcg_gen_shli_i64(t1, load_gpr(ctx, a->x), 3);
4032bc921866SRichard Henderson         tcg_gen_add_i64(t0, t0, t1);
4033bc921866SRichard Henderson 
4034bc921866SRichard Henderson         ctx->iaq_j = iaqe_next_absv(ctx, t0);
4035bc921866SRichard Henderson         return do_ibranch(ctx, a->l, false, a->n);
4036b35aec85SRichard Henderson     } else {
4037b35aec85SRichard Henderson         /* BLR R0,RX is a good way to load PC+8 into RX.  */
40382644f80bSRichard Henderson         return do_dbranch(ctx, 0, a->l, a->n);
4039b35aec85SRichard Henderson     }
404098cd9ca7SRichard Henderson }
404198cd9ca7SRichard Henderson 
trans_bv(DisasContext * ctx,arg_bv * a)40428340f534SRichard Henderson static bool trans_bv(DisasContext *ctx, arg_bv *a)
404398cd9ca7SRichard Henderson {
40446fd0c7bcSRichard Henderson     TCGv_i64 dest;
404598cd9ca7SRichard Henderson 
40468340f534SRichard Henderson     if (a->x == 0) {
40478340f534SRichard Henderson         dest = load_gpr(ctx, a->b);
404898cd9ca7SRichard Henderson     } else {
4049aac0f603SRichard Henderson         dest = tcg_temp_new_i64();
40506fd0c7bcSRichard Henderson         tcg_gen_shli_i64(dest, load_gpr(ctx, a->x), 3);
40516fd0c7bcSRichard Henderson         tcg_gen_add_i64(dest, dest, load_gpr(ctx, a->b));
405298cd9ca7SRichard Henderson     }
4053660eefe1SRichard Henderson     dest = do_ibranch_priv(ctx, dest);
4054bc921866SRichard Henderson     ctx->iaq_j = iaqe_next_absv(ctx, dest);
4055bc921866SRichard Henderson 
4056bc921866SRichard Henderson     return do_ibranch(ctx, 0, false, a->n);
405798cd9ca7SRichard Henderson }
405898cd9ca7SRichard Henderson 
trans_bve(DisasContext * ctx,arg_bve * a)40598340f534SRichard Henderson static bool trans_bve(DisasContext *ctx, arg_bve *a)
406098cd9ca7SRichard Henderson {
4061019f4159SRichard Henderson     TCGv_i64 b = load_gpr(ctx, a->b);
406298cd9ca7SRichard Henderson 
4063019f4159SRichard Henderson #ifndef CONFIG_USER_ONLY
4064bc921866SRichard Henderson     ctx->iaq_j.space = space_select(ctx, 0, b);
4065c301f34eSRichard Henderson #endif
4066bc921866SRichard Henderson     ctx->iaq_j.base = do_ibranch_priv(ctx, b);
4067bc921866SRichard Henderson     ctx->iaq_j.disp = 0;
4068019f4159SRichard Henderson 
4069bc921866SRichard Henderson     return do_ibranch(ctx, a->l, false, a->n);
407098cd9ca7SRichard Henderson }
407198cd9ca7SRichard Henderson 
trans_nopbts(DisasContext * ctx,arg_nopbts * a)4072a8966ba7SRichard Henderson static bool trans_nopbts(DisasContext *ctx, arg_nopbts *a)
4073a8966ba7SRichard Henderson {
4074a8966ba7SRichard Henderson     /* All branch target stack instructions implement as nop. */
4075a8966ba7SRichard Henderson     return ctx->is_pa20;
4076a8966ba7SRichard Henderson }
4077a8966ba7SRichard Henderson 
40781ca74648SRichard Henderson /*
40791ca74648SRichard Henderson  * Float class 0
40801ca74648SRichard Henderson  */
4081ebe9383cSRichard Henderson 
gen_fcpy_f(TCGv_i32 dst,TCGv_env unused,TCGv_i32 src)40821ca74648SRichard Henderson static void gen_fcpy_f(TCGv_i32 dst, TCGv_env unused, TCGv_i32 src)
4083ebe9383cSRichard Henderson {
4084ebe9383cSRichard Henderson     tcg_gen_mov_i32(dst, src);
4085ebe9383cSRichard Henderson }
4086ebe9383cSRichard Henderson 
trans_fid_f(DisasContext * ctx,arg_fid_f * a)408759f8c04bSHelge Deller static bool trans_fid_f(DisasContext *ctx, arg_fid_f *a)
408859f8c04bSHelge Deller {
4089a300dad3SRichard Henderson     uint64_t ret;
4090a300dad3SRichard Henderson 
4091c53e401eSRichard Henderson     if (ctx->is_pa20) {
4092a300dad3SRichard Henderson         ret = 0x13080000000000ULL; /* PA8700 (PCX-W2) */
4093a300dad3SRichard Henderson     } else {
4094a300dad3SRichard Henderson         ret = 0x0f080000000000ULL; /* PA7300LC (PCX-L2) */
4095a300dad3SRichard Henderson     }
4096a300dad3SRichard Henderson 
409759f8c04bSHelge Deller     nullify_over(ctx);
4098a300dad3SRichard Henderson     save_frd(0, tcg_constant_i64(ret));
409959f8c04bSHelge Deller     return nullify_end(ctx);
410059f8c04bSHelge Deller }
410159f8c04bSHelge Deller 
trans_fcpy_f(DisasContext * ctx,arg_fclass01 * a)41021ca74648SRichard Henderson static bool trans_fcpy_f(DisasContext *ctx, arg_fclass01 *a)
41031ca74648SRichard Henderson {
41041ca74648SRichard Henderson     return do_fop_wew(ctx, a->t, a->r, gen_fcpy_f);
41051ca74648SRichard Henderson }
41061ca74648SRichard Henderson 
gen_fcpy_d(TCGv_i64 dst,TCGv_env unused,TCGv_i64 src)4107ebe9383cSRichard Henderson static void gen_fcpy_d(TCGv_i64 dst, TCGv_env unused, TCGv_i64 src)
4108ebe9383cSRichard Henderson {
4109ebe9383cSRichard Henderson     tcg_gen_mov_i64(dst, src);
4110ebe9383cSRichard Henderson }
4111ebe9383cSRichard Henderson 
trans_fcpy_d(DisasContext * ctx,arg_fclass01 * a)41121ca74648SRichard Henderson static bool trans_fcpy_d(DisasContext *ctx, arg_fclass01 *a)
41131ca74648SRichard Henderson {
41141ca74648SRichard Henderson     return do_fop_ded(ctx, a->t, a->r, gen_fcpy_d);
41151ca74648SRichard Henderson }
41161ca74648SRichard Henderson 
gen_fabs_f(TCGv_i32 dst,TCGv_env unused,TCGv_i32 src)41171ca74648SRichard Henderson static void gen_fabs_f(TCGv_i32 dst, TCGv_env unused, TCGv_i32 src)
4118ebe9383cSRichard Henderson {
4119ebe9383cSRichard Henderson     tcg_gen_andi_i32(dst, src, INT32_MAX);
4120ebe9383cSRichard Henderson }
4121ebe9383cSRichard Henderson 
trans_fabs_f(DisasContext * ctx,arg_fclass01 * a)41221ca74648SRichard Henderson static bool trans_fabs_f(DisasContext *ctx, arg_fclass01 *a)
41231ca74648SRichard Henderson {
41241ca74648SRichard Henderson     return do_fop_wew(ctx, a->t, a->r, gen_fabs_f);
41251ca74648SRichard Henderson }
41261ca74648SRichard Henderson 
gen_fabs_d(TCGv_i64 dst,TCGv_env unused,TCGv_i64 src)4127ebe9383cSRichard Henderson static void gen_fabs_d(TCGv_i64 dst, TCGv_env unused, TCGv_i64 src)
4128ebe9383cSRichard Henderson {
4129ebe9383cSRichard Henderson     tcg_gen_andi_i64(dst, src, INT64_MAX);
4130ebe9383cSRichard Henderson }
4131ebe9383cSRichard Henderson 
trans_fabs_d(DisasContext * ctx,arg_fclass01 * a)41321ca74648SRichard Henderson static bool trans_fabs_d(DisasContext *ctx, arg_fclass01 *a)
41331ca74648SRichard Henderson {
41341ca74648SRichard Henderson     return do_fop_ded(ctx, a->t, a->r, gen_fabs_d);
41351ca74648SRichard Henderson }
41361ca74648SRichard Henderson 
trans_fsqrt_f(DisasContext * ctx,arg_fclass01 * a)41371ca74648SRichard Henderson static bool trans_fsqrt_f(DisasContext *ctx, arg_fclass01 *a)
41381ca74648SRichard Henderson {
41391ca74648SRichard Henderson     return do_fop_wew(ctx, a->t, a->r, gen_helper_fsqrt_s);
41401ca74648SRichard Henderson }
41411ca74648SRichard Henderson 
trans_fsqrt_d(DisasContext * ctx,arg_fclass01 * a)41421ca74648SRichard Henderson static bool trans_fsqrt_d(DisasContext *ctx, arg_fclass01 *a)
41431ca74648SRichard Henderson {
41441ca74648SRichard Henderson     return do_fop_ded(ctx, a->t, a->r, gen_helper_fsqrt_d);
41451ca74648SRichard Henderson }
41461ca74648SRichard Henderson 
trans_frnd_f(DisasContext * ctx,arg_fclass01 * a)41471ca74648SRichard Henderson static bool trans_frnd_f(DisasContext *ctx, arg_fclass01 *a)
41481ca74648SRichard Henderson {
41491ca74648SRichard Henderson     return do_fop_wew(ctx, a->t, a->r, gen_helper_frnd_s);
41501ca74648SRichard Henderson }
41511ca74648SRichard Henderson 
trans_frnd_d(DisasContext * ctx,arg_fclass01 * a)41521ca74648SRichard Henderson static bool trans_frnd_d(DisasContext *ctx, arg_fclass01 *a)
41531ca74648SRichard Henderson {
41541ca74648SRichard Henderson     return do_fop_ded(ctx, a->t, a->r, gen_helper_frnd_d);
41551ca74648SRichard Henderson }
41561ca74648SRichard Henderson 
gen_fneg_f(TCGv_i32 dst,TCGv_env unused,TCGv_i32 src)41571ca74648SRichard Henderson static void gen_fneg_f(TCGv_i32 dst, TCGv_env unused, TCGv_i32 src)
4158ebe9383cSRichard Henderson {
4159ebe9383cSRichard Henderson     tcg_gen_xori_i32(dst, src, INT32_MIN);
4160ebe9383cSRichard Henderson }
4161ebe9383cSRichard Henderson 
trans_fneg_f(DisasContext * ctx,arg_fclass01 * a)41621ca74648SRichard Henderson static bool trans_fneg_f(DisasContext *ctx, arg_fclass01 *a)
41631ca74648SRichard Henderson {
41641ca74648SRichard Henderson     return do_fop_wew(ctx, a->t, a->r, gen_fneg_f);
41651ca74648SRichard Henderson }
41661ca74648SRichard Henderson 
gen_fneg_d(TCGv_i64 dst,TCGv_env unused,TCGv_i64 src)4167ebe9383cSRichard Henderson static void gen_fneg_d(TCGv_i64 dst, TCGv_env unused, TCGv_i64 src)
4168ebe9383cSRichard Henderson {
4169ebe9383cSRichard Henderson     tcg_gen_xori_i64(dst, src, INT64_MIN);
4170ebe9383cSRichard Henderson }
4171ebe9383cSRichard Henderson 
trans_fneg_d(DisasContext * ctx,arg_fclass01 * a)41721ca74648SRichard Henderson static bool trans_fneg_d(DisasContext *ctx, arg_fclass01 *a)
41731ca74648SRichard Henderson {
41741ca74648SRichard Henderson     return do_fop_ded(ctx, a->t, a->r, gen_fneg_d);
41751ca74648SRichard Henderson }
41761ca74648SRichard Henderson 
gen_fnegabs_f(TCGv_i32 dst,TCGv_env unused,TCGv_i32 src)41771ca74648SRichard Henderson static void gen_fnegabs_f(TCGv_i32 dst, TCGv_env unused, TCGv_i32 src)
4178ebe9383cSRichard Henderson {
4179ebe9383cSRichard Henderson     tcg_gen_ori_i32(dst, src, INT32_MIN);
4180ebe9383cSRichard Henderson }
4181ebe9383cSRichard Henderson 
trans_fnegabs_f(DisasContext * ctx,arg_fclass01 * a)41821ca74648SRichard Henderson static bool trans_fnegabs_f(DisasContext *ctx, arg_fclass01 *a)
41831ca74648SRichard Henderson {
41841ca74648SRichard Henderson     return do_fop_wew(ctx, a->t, a->r, gen_fnegabs_f);
41851ca74648SRichard Henderson }
41861ca74648SRichard Henderson 
gen_fnegabs_d(TCGv_i64 dst,TCGv_env unused,TCGv_i64 src)4187ebe9383cSRichard Henderson static void gen_fnegabs_d(TCGv_i64 dst, TCGv_env unused, TCGv_i64 src)
4188ebe9383cSRichard Henderson {
4189ebe9383cSRichard Henderson     tcg_gen_ori_i64(dst, src, INT64_MIN);
4190ebe9383cSRichard Henderson }
4191ebe9383cSRichard Henderson 
trans_fnegabs_d(DisasContext * ctx,arg_fclass01 * a)41921ca74648SRichard Henderson static bool trans_fnegabs_d(DisasContext *ctx, arg_fclass01 *a)
41931ca74648SRichard Henderson {
41941ca74648SRichard Henderson     return do_fop_ded(ctx, a->t, a->r, gen_fnegabs_d);
41951ca74648SRichard Henderson }
41961ca74648SRichard Henderson 
41971ca74648SRichard Henderson /*
41981ca74648SRichard Henderson  * Float class 1
41991ca74648SRichard Henderson  */
42001ca74648SRichard Henderson 
trans_fcnv_d_f(DisasContext * ctx,arg_fclass01 * a)42011ca74648SRichard Henderson static bool trans_fcnv_d_f(DisasContext *ctx, arg_fclass01 *a)
42021ca74648SRichard Henderson {
42031ca74648SRichard Henderson     return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_d_s);
42041ca74648SRichard Henderson }
42051ca74648SRichard Henderson 
trans_fcnv_f_d(DisasContext * ctx,arg_fclass01 * a)42061ca74648SRichard Henderson static bool trans_fcnv_f_d(DisasContext *ctx, arg_fclass01 *a)
42071ca74648SRichard Henderson {
42081ca74648SRichard Henderson     return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_s_d);
42091ca74648SRichard Henderson }
42101ca74648SRichard Henderson 
trans_fcnv_w_f(DisasContext * ctx,arg_fclass01 * a)42111ca74648SRichard Henderson static bool trans_fcnv_w_f(DisasContext *ctx, arg_fclass01 *a)
42121ca74648SRichard Henderson {
42131ca74648SRichard Henderson     return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_w_s);
42141ca74648SRichard Henderson }
42151ca74648SRichard Henderson 
trans_fcnv_q_f(DisasContext * ctx,arg_fclass01 * a)42161ca74648SRichard Henderson static bool trans_fcnv_q_f(DisasContext *ctx, arg_fclass01 *a)
42171ca74648SRichard Henderson {
42181ca74648SRichard Henderson     return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_dw_s);
42191ca74648SRichard Henderson }
42201ca74648SRichard Henderson 
trans_fcnv_w_d(DisasContext * ctx,arg_fclass01 * a)42211ca74648SRichard Henderson static bool trans_fcnv_w_d(DisasContext *ctx, arg_fclass01 *a)
42221ca74648SRichard Henderson {
42231ca74648SRichard Henderson     return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_w_d);
42241ca74648SRichard Henderson }
42251ca74648SRichard Henderson 
trans_fcnv_q_d(DisasContext * ctx,arg_fclass01 * a)42261ca74648SRichard Henderson static bool trans_fcnv_q_d(DisasContext *ctx, arg_fclass01 *a)
42271ca74648SRichard Henderson {
42281ca74648SRichard Henderson     return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_dw_d);
42291ca74648SRichard Henderson }
42301ca74648SRichard Henderson 
trans_fcnv_f_w(DisasContext * ctx,arg_fclass01 * a)42311ca74648SRichard Henderson static bool trans_fcnv_f_w(DisasContext *ctx, arg_fclass01 *a)
42321ca74648SRichard Henderson {
42331ca74648SRichard Henderson     return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_s_w);
42341ca74648SRichard Henderson }
42351ca74648SRichard Henderson 
trans_fcnv_d_w(DisasContext * ctx,arg_fclass01 * a)42361ca74648SRichard Henderson static bool trans_fcnv_d_w(DisasContext *ctx, arg_fclass01 *a)
42371ca74648SRichard Henderson {
42381ca74648SRichard Henderson     return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_d_w);
42391ca74648SRichard Henderson }
42401ca74648SRichard Henderson 
trans_fcnv_f_q(DisasContext * ctx,arg_fclass01 * a)42411ca74648SRichard Henderson static bool trans_fcnv_f_q(DisasContext *ctx, arg_fclass01 *a)
42421ca74648SRichard Henderson {
42431ca74648SRichard Henderson     return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_s_dw);
42441ca74648SRichard Henderson }
42451ca74648SRichard Henderson 
trans_fcnv_d_q(DisasContext * ctx,arg_fclass01 * a)42461ca74648SRichard Henderson static bool trans_fcnv_d_q(DisasContext *ctx, arg_fclass01 *a)
42471ca74648SRichard Henderson {
42481ca74648SRichard Henderson     return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_d_dw);
42491ca74648SRichard Henderson }
42501ca74648SRichard Henderson 
trans_fcnv_t_f_w(DisasContext * ctx,arg_fclass01 * a)42511ca74648SRichard Henderson static bool trans_fcnv_t_f_w(DisasContext *ctx, arg_fclass01 *a)
42521ca74648SRichard Henderson {
42531ca74648SRichard Henderson     return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_t_s_w);
42541ca74648SRichard Henderson }
42551ca74648SRichard Henderson 
trans_fcnv_t_d_w(DisasContext * ctx,arg_fclass01 * a)42561ca74648SRichard Henderson static bool trans_fcnv_t_d_w(DisasContext *ctx, arg_fclass01 *a)
42571ca74648SRichard Henderson {
42581ca74648SRichard Henderson     return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_t_d_w);
42591ca74648SRichard Henderson }
42601ca74648SRichard Henderson 
trans_fcnv_t_f_q(DisasContext * ctx,arg_fclass01 * a)42611ca74648SRichard Henderson static bool trans_fcnv_t_f_q(DisasContext *ctx, arg_fclass01 *a)
42621ca74648SRichard Henderson {
42631ca74648SRichard Henderson     return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_t_s_dw);
42641ca74648SRichard Henderson }
42651ca74648SRichard Henderson 
trans_fcnv_t_d_q(DisasContext * ctx,arg_fclass01 * a)42661ca74648SRichard Henderson static bool trans_fcnv_t_d_q(DisasContext *ctx, arg_fclass01 *a)
42671ca74648SRichard Henderson {
42681ca74648SRichard Henderson     return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_t_d_dw);
42691ca74648SRichard Henderson }
42701ca74648SRichard Henderson 
trans_fcnv_uw_f(DisasContext * ctx,arg_fclass01 * a)42711ca74648SRichard Henderson static bool trans_fcnv_uw_f(DisasContext *ctx, arg_fclass01 *a)
42721ca74648SRichard Henderson {
42731ca74648SRichard Henderson     return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_uw_s);
42741ca74648SRichard Henderson }
42751ca74648SRichard Henderson 
trans_fcnv_uq_f(DisasContext * ctx,arg_fclass01 * a)42761ca74648SRichard Henderson static bool trans_fcnv_uq_f(DisasContext *ctx, arg_fclass01 *a)
42771ca74648SRichard Henderson {
42781ca74648SRichard Henderson     return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_udw_s);
42791ca74648SRichard Henderson }
42801ca74648SRichard Henderson 
trans_fcnv_uw_d(DisasContext * ctx,arg_fclass01 * a)42811ca74648SRichard Henderson static bool trans_fcnv_uw_d(DisasContext *ctx, arg_fclass01 *a)
42821ca74648SRichard Henderson {
42831ca74648SRichard Henderson     return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_uw_d);
42841ca74648SRichard Henderson }
42851ca74648SRichard Henderson 
trans_fcnv_uq_d(DisasContext * ctx,arg_fclass01 * a)42861ca74648SRichard Henderson static bool trans_fcnv_uq_d(DisasContext *ctx, arg_fclass01 *a)
42871ca74648SRichard Henderson {
42881ca74648SRichard Henderson     return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_udw_d);
42891ca74648SRichard Henderson }
42901ca74648SRichard Henderson 
trans_fcnv_f_uw(DisasContext * ctx,arg_fclass01 * a)42911ca74648SRichard Henderson static bool trans_fcnv_f_uw(DisasContext *ctx, arg_fclass01 *a)
42921ca74648SRichard Henderson {
42931ca74648SRichard Henderson     return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_s_uw);
42941ca74648SRichard Henderson }
42951ca74648SRichard Henderson 
trans_fcnv_d_uw(DisasContext * ctx,arg_fclass01 * a)42961ca74648SRichard Henderson static bool trans_fcnv_d_uw(DisasContext *ctx, arg_fclass01 *a)
42971ca74648SRichard Henderson {
42981ca74648SRichard Henderson     return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_d_uw);
42991ca74648SRichard Henderson }
43001ca74648SRichard Henderson 
trans_fcnv_f_uq(DisasContext * ctx,arg_fclass01 * a)43011ca74648SRichard Henderson static bool trans_fcnv_f_uq(DisasContext *ctx, arg_fclass01 *a)
43021ca74648SRichard Henderson {
43031ca74648SRichard Henderson     return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_s_udw);
43041ca74648SRichard Henderson }
43051ca74648SRichard Henderson 
trans_fcnv_d_uq(DisasContext * ctx,arg_fclass01 * a)43061ca74648SRichard Henderson static bool trans_fcnv_d_uq(DisasContext *ctx, arg_fclass01 *a)
43071ca74648SRichard Henderson {
43081ca74648SRichard Henderson     return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_d_udw);
43091ca74648SRichard Henderson }
43101ca74648SRichard Henderson 
trans_fcnv_t_f_uw(DisasContext * ctx,arg_fclass01 * a)43111ca74648SRichard Henderson static bool trans_fcnv_t_f_uw(DisasContext *ctx, arg_fclass01 *a)
43121ca74648SRichard Henderson {
43131ca74648SRichard Henderson     return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_t_s_uw);
43141ca74648SRichard Henderson }
43151ca74648SRichard Henderson 
trans_fcnv_t_d_uw(DisasContext * ctx,arg_fclass01 * a)43161ca74648SRichard Henderson static bool trans_fcnv_t_d_uw(DisasContext *ctx, arg_fclass01 *a)
43171ca74648SRichard Henderson {
43181ca74648SRichard Henderson     return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_t_d_uw);
43191ca74648SRichard Henderson }
43201ca74648SRichard Henderson 
trans_fcnv_t_f_uq(DisasContext * ctx,arg_fclass01 * a)43211ca74648SRichard Henderson static bool trans_fcnv_t_f_uq(DisasContext *ctx, arg_fclass01 *a)
43221ca74648SRichard Henderson {
43231ca74648SRichard Henderson     return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_t_s_udw);
43241ca74648SRichard Henderson }
43251ca74648SRichard Henderson 
trans_fcnv_t_d_uq(DisasContext * ctx,arg_fclass01 * a)43261ca74648SRichard Henderson static bool trans_fcnv_t_d_uq(DisasContext *ctx, arg_fclass01 *a)
43271ca74648SRichard Henderson {
43281ca74648SRichard Henderson     return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_t_d_udw);
43291ca74648SRichard Henderson }
43301ca74648SRichard Henderson 
43311ca74648SRichard Henderson /*
43321ca74648SRichard Henderson  * Float class 2
43331ca74648SRichard Henderson  */
43341ca74648SRichard Henderson 
trans_fcmp_f(DisasContext * ctx,arg_fclass2 * a)43351ca74648SRichard Henderson static bool trans_fcmp_f(DisasContext *ctx, arg_fclass2 *a)
4336ebe9383cSRichard Henderson {
4337ebe9383cSRichard Henderson     TCGv_i32 ta, tb, tc, ty;
4338ebe9383cSRichard Henderson 
4339ebe9383cSRichard Henderson     nullify_over(ctx);
4340ebe9383cSRichard Henderson 
43411ca74648SRichard Henderson     ta = load_frw0_i32(a->r1);
43421ca74648SRichard Henderson     tb = load_frw0_i32(a->r2);
434329dd6f64SRichard Henderson     ty = tcg_constant_i32(a->y);
434429dd6f64SRichard Henderson     tc = tcg_constant_i32(a->c);
4345ebe9383cSRichard Henderson 
4346ad75a51eSRichard Henderson     gen_helper_fcmp_s(tcg_env, ta, tb, ty, tc);
4347ebe9383cSRichard Henderson 
43481ca74648SRichard Henderson     return nullify_end(ctx);
4349ebe9383cSRichard Henderson }
4350ebe9383cSRichard Henderson 
trans_fcmp_d(DisasContext * ctx,arg_fclass2 * a)43511ca74648SRichard Henderson static bool trans_fcmp_d(DisasContext *ctx, arg_fclass2 *a)
4352ebe9383cSRichard Henderson {
4353ebe9383cSRichard Henderson     TCGv_i64 ta, tb;
4354ebe9383cSRichard Henderson     TCGv_i32 tc, ty;
4355ebe9383cSRichard Henderson 
4356ebe9383cSRichard Henderson     nullify_over(ctx);
4357ebe9383cSRichard Henderson 
43581ca74648SRichard Henderson     ta = load_frd0(a->r1);
43591ca74648SRichard Henderson     tb = load_frd0(a->r2);
436029dd6f64SRichard Henderson     ty = tcg_constant_i32(a->y);
436129dd6f64SRichard Henderson     tc = tcg_constant_i32(a->c);
4362ebe9383cSRichard Henderson 
4363ad75a51eSRichard Henderson     gen_helper_fcmp_d(tcg_env, ta, tb, ty, tc);
4364ebe9383cSRichard Henderson 
436531234768SRichard Henderson     return nullify_end(ctx);
4366ebe9383cSRichard Henderson }
4367ebe9383cSRichard Henderson 
trans_ftest(DisasContext * ctx,arg_ftest * a)43681ca74648SRichard Henderson static bool trans_ftest(DisasContext *ctx, arg_ftest *a)
4369ebe9383cSRichard Henderson {
43703692ad21SRichard Henderson     TCGCond tc = TCG_COND_TSTNE;
43713692ad21SRichard Henderson     uint32_t mask;
43726fd0c7bcSRichard Henderson     TCGv_i64 t;
4373ebe9383cSRichard Henderson 
4374ebe9383cSRichard Henderson     nullify_over(ctx);
4375ebe9383cSRichard Henderson 
4376aac0f603SRichard Henderson     t = tcg_temp_new_i64();
43776fd0c7bcSRichard Henderson     tcg_gen_ld32u_i64(t, tcg_env, offsetof(CPUHPPAState, fr0_shadow));
4378ebe9383cSRichard Henderson 
43791ca74648SRichard Henderson     if (a->y == 1) {
43801ca74648SRichard Henderson         switch (a->c) {
4381ebe9383cSRichard Henderson         case 0: /* simple */
4382f33a22c1SRichard Henderson             mask = R_FPSR_C_MASK;
4383f33a22c1SRichard Henderson             break;
4384ebe9383cSRichard Henderson         case 2: /* rej */
43853692ad21SRichard Henderson             tc = TCG_COND_TSTEQ;
4386ebe9383cSRichard Henderson             /* fallthru */
4387ebe9383cSRichard Henderson         case 1: /* acc */
4388f33a22c1SRichard Henderson             mask = R_FPSR_C_MASK | R_FPSR_CQ_MASK;
4389ebe9383cSRichard Henderson             break;
4390ebe9383cSRichard Henderson         case 6: /* rej8 */
43913692ad21SRichard Henderson             tc = TCG_COND_TSTEQ;
4392ebe9383cSRichard Henderson             /* fallthru */
4393ebe9383cSRichard Henderson         case 5: /* acc8 */
4394f33a22c1SRichard Henderson             mask = R_FPSR_C_MASK | R_FPSR_CQ0_6_MASK;
4395ebe9383cSRichard Henderson             break;
4396ebe9383cSRichard Henderson         case 9: /* acc6 */
4397f33a22c1SRichard Henderson             mask = R_FPSR_C_MASK | R_FPSR_CQ0_4_MASK;
4398ebe9383cSRichard Henderson             break;
4399ebe9383cSRichard Henderson         case 13: /* acc4 */
4400f33a22c1SRichard Henderson             mask = R_FPSR_C_MASK | R_FPSR_CQ0_2_MASK;
4401ebe9383cSRichard Henderson             break;
4402ebe9383cSRichard Henderson         case 17: /* acc2 */
4403f33a22c1SRichard Henderson             mask = R_FPSR_C_MASK | R_FPSR_CQ0_MASK;
4404ebe9383cSRichard Henderson             break;
4405ebe9383cSRichard Henderson         default:
44061ca74648SRichard Henderson             gen_illegal(ctx);
44071ca74648SRichard Henderson             return true;
4408ebe9383cSRichard Henderson         }
44091ca74648SRichard Henderson     } else {
44101ca74648SRichard Henderson         unsigned cbit = (a->y ^ 1) - 1;
44113692ad21SRichard Henderson         mask = R_FPSR_CA0_MASK >> cbit;
44121ca74648SRichard Henderson     }
44131ca74648SRichard Henderson 
44143692ad21SRichard Henderson     ctx->null_cond = cond_make_ti(tc, t, mask);
441531234768SRichard Henderson     return nullify_end(ctx);
4416ebe9383cSRichard Henderson }
4417ebe9383cSRichard Henderson 
44181ca74648SRichard Henderson /*
44191ca74648SRichard Henderson  * Float class 2
44201ca74648SRichard Henderson  */
44211ca74648SRichard Henderson 
trans_fadd_f(DisasContext * ctx,arg_fclass3 * a)44221ca74648SRichard Henderson static bool trans_fadd_f(DisasContext *ctx, arg_fclass3 *a)
4423ebe9383cSRichard Henderson {
44241ca74648SRichard Henderson     return do_fop_weww(ctx, a->t, a->r1, a->r2, gen_helper_fadd_s);
44251ca74648SRichard Henderson }
44261ca74648SRichard Henderson 
trans_fadd_d(DisasContext * ctx,arg_fclass3 * a)44271ca74648SRichard Henderson static bool trans_fadd_d(DisasContext *ctx, arg_fclass3 *a)
44281ca74648SRichard Henderson {
44291ca74648SRichard Henderson     return do_fop_dedd(ctx, a->t, a->r1, a->r2, gen_helper_fadd_d);
44301ca74648SRichard Henderson }
44311ca74648SRichard Henderson 
trans_fsub_f(DisasContext * ctx,arg_fclass3 * a)44321ca74648SRichard Henderson static bool trans_fsub_f(DisasContext *ctx, arg_fclass3 *a)
44331ca74648SRichard Henderson {
44341ca74648SRichard Henderson     return do_fop_weww(ctx, a->t, a->r1, a->r2, gen_helper_fsub_s);
44351ca74648SRichard Henderson }
44361ca74648SRichard Henderson 
trans_fsub_d(DisasContext * ctx,arg_fclass3 * a)44371ca74648SRichard Henderson static bool trans_fsub_d(DisasContext *ctx, arg_fclass3 *a)
44381ca74648SRichard Henderson {
44391ca74648SRichard Henderson     return do_fop_dedd(ctx, a->t, a->r1, a->r2, gen_helper_fsub_d);
44401ca74648SRichard Henderson }
44411ca74648SRichard Henderson 
trans_fmpy_f(DisasContext * ctx,arg_fclass3 * a)44421ca74648SRichard Henderson static bool trans_fmpy_f(DisasContext *ctx, arg_fclass3 *a)
44431ca74648SRichard Henderson {
44441ca74648SRichard Henderson     return do_fop_weww(ctx, a->t, a->r1, a->r2, gen_helper_fmpy_s);
44451ca74648SRichard Henderson }
44461ca74648SRichard Henderson 
trans_fmpy_d(DisasContext * ctx,arg_fclass3 * a)44471ca74648SRichard Henderson static bool trans_fmpy_d(DisasContext *ctx, arg_fclass3 *a)
44481ca74648SRichard Henderson {
44491ca74648SRichard Henderson     return do_fop_dedd(ctx, a->t, a->r1, a->r2, gen_helper_fmpy_d);
44501ca74648SRichard Henderson }
44511ca74648SRichard Henderson 
trans_fdiv_f(DisasContext * ctx,arg_fclass3 * a)44521ca74648SRichard Henderson static bool trans_fdiv_f(DisasContext *ctx, arg_fclass3 *a)
44531ca74648SRichard Henderson {
44541ca74648SRichard Henderson     return do_fop_weww(ctx, a->t, a->r1, a->r2, gen_helper_fdiv_s);
44551ca74648SRichard Henderson }
44561ca74648SRichard Henderson 
trans_fdiv_d(DisasContext * ctx,arg_fclass3 * a)44571ca74648SRichard Henderson static bool trans_fdiv_d(DisasContext *ctx, arg_fclass3 *a)
44581ca74648SRichard Henderson {
44591ca74648SRichard Henderson     return do_fop_dedd(ctx, a->t, a->r1, a->r2, gen_helper_fdiv_d);
44601ca74648SRichard Henderson }
44611ca74648SRichard Henderson 
trans_xmpyu(DisasContext * ctx,arg_xmpyu * a)44621ca74648SRichard Henderson static bool trans_xmpyu(DisasContext *ctx, arg_xmpyu *a)
44631ca74648SRichard Henderson {
44641ca74648SRichard Henderson     TCGv_i64 x, y;
4465ebe9383cSRichard Henderson 
4466ebe9383cSRichard Henderson     nullify_over(ctx);
4467ebe9383cSRichard Henderson 
44681ca74648SRichard Henderson     x = load_frw0_i64(a->r1);
44691ca74648SRichard Henderson     y = load_frw0_i64(a->r2);
44701ca74648SRichard Henderson     tcg_gen_mul_i64(x, x, y);
44711ca74648SRichard Henderson     save_frd(a->t, x);
4472ebe9383cSRichard Henderson 
447331234768SRichard Henderson     return nullify_end(ctx);
4474ebe9383cSRichard Henderson }
4475ebe9383cSRichard Henderson 
4476ebe9383cSRichard Henderson /* Convert the fmpyadd single-precision register encodings to standard.  */
fmpyadd_s_reg(unsigned r)4477ebe9383cSRichard Henderson static inline int fmpyadd_s_reg(unsigned r)
4478ebe9383cSRichard Henderson {
4479ebe9383cSRichard Henderson     return (r & 16) * 2 + 16 + (r & 15);
4480ebe9383cSRichard Henderson }
4481ebe9383cSRichard Henderson 
do_fmpyadd_s(DisasContext * ctx,arg_mpyadd * a,bool is_sub)4482b1e2af57SRichard Henderson static bool do_fmpyadd_s(DisasContext *ctx, arg_mpyadd *a, bool is_sub)
4483ebe9383cSRichard Henderson {
4484b1e2af57SRichard Henderson     int tm = fmpyadd_s_reg(a->tm);
4485b1e2af57SRichard Henderson     int ra = fmpyadd_s_reg(a->ra);
4486b1e2af57SRichard Henderson     int ta = fmpyadd_s_reg(a->ta);
4487b1e2af57SRichard Henderson     int rm2 = fmpyadd_s_reg(a->rm2);
4488b1e2af57SRichard Henderson     int rm1 = fmpyadd_s_reg(a->rm1);
4489ebe9383cSRichard Henderson 
4490ebe9383cSRichard Henderson     nullify_over(ctx);
4491ebe9383cSRichard Henderson 
4492ebe9383cSRichard Henderson     do_fop_weww(ctx, tm, rm1, rm2, gen_helper_fmpy_s);
4493ebe9383cSRichard Henderson     do_fop_weww(ctx, ta, ta, ra,
4494ebe9383cSRichard Henderson                 is_sub ? gen_helper_fsub_s : gen_helper_fadd_s);
4495ebe9383cSRichard Henderson 
449631234768SRichard Henderson     return nullify_end(ctx);
4497ebe9383cSRichard Henderson }
4498ebe9383cSRichard Henderson 
trans_fmpyadd_f(DisasContext * ctx,arg_mpyadd * a)4499b1e2af57SRichard Henderson static bool trans_fmpyadd_f(DisasContext *ctx, arg_mpyadd *a)
4500b1e2af57SRichard Henderson {
4501b1e2af57SRichard Henderson     return do_fmpyadd_s(ctx, a, false);
4502b1e2af57SRichard Henderson }
4503b1e2af57SRichard Henderson 
trans_fmpysub_f(DisasContext * ctx,arg_mpyadd * a)4504b1e2af57SRichard Henderson static bool trans_fmpysub_f(DisasContext *ctx, arg_mpyadd *a)
4505b1e2af57SRichard Henderson {
4506b1e2af57SRichard Henderson     return do_fmpyadd_s(ctx, a, true);
4507b1e2af57SRichard Henderson }
4508b1e2af57SRichard Henderson 
do_fmpyadd_d(DisasContext * ctx,arg_mpyadd * a,bool is_sub)4509b1e2af57SRichard Henderson static bool do_fmpyadd_d(DisasContext *ctx, arg_mpyadd *a, bool is_sub)
4510b1e2af57SRichard Henderson {
4511b1e2af57SRichard Henderson     nullify_over(ctx);
4512b1e2af57SRichard Henderson 
4513b1e2af57SRichard Henderson     do_fop_dedd(ctx, a->tm, a->rm1, a->rm2, gen_helper_fmpy_d);
4514b1e2af57SRichard Henderson     do_fop_dedd(ctx, a->ta, a->ta, a->ra,
4515b1e2af57SRichard Henderson                 is_sub ? gen_helper_fsub_d : gen_helper_fadd_d);
4516b1e2af57SRichard Henderson 
4517b1e2af57SRichard Henderson     return nullify_end(ctx);
4518b1e2af57SRichard Henderson }
4519b1e2af57SRichard Henderson 
trans_fmpyadd_d(DisasContext * ctx,arg_mpyadd * a)4520b1e2af57SRichard Henderson static bool trans_fmpyadd_d(DisasContext *ctx, arg_mpyadd *a)
4521b1e2af57SRichard Henderson {
4522b1e2af57SRichard Henderson     return do_fmpyadd_d(ctx, a, false);
4523b1e2af57SRichard Henderson }
4524b1e2af57SRichard Henderson 
trans_fmpysub_d(DisasContext * ctx,arg_mpyadd * a)4525b1e2af57SRichard Henderson static bool trans_fmpysub_d(DisasContext *ctx, arg_mpyadd *a)
4526b1e2af57SRichard Henderson {
4527b1e2af57SRichard Henderson     return do_fmpyadd_d(ctx, a, true);
4528b1e2af57SRichard Henderson }
4529b1e2af57SRichard Henderson 
trans_fmpyfadd_f(DisasContext * ctx,arg_fmpyfadd_f * a)4530c3bad4f8SRichard Henderson static bool trans_fmpyfadd_f(DisasContext *ctx, arg_fmpyfadd_f *a)
4531ebe9383cSRichard Henderson {
4532c3bad4f8SRichard Henderson     TCGv_i32 x, y, z;
4533ebe9383cSRichard Henderson 
4534ebe9383cSRichard Henderson     nullify_over(ctx);
4535c3bad4f8SRichard Henderson     x = load_frw0_i32(a->rm1);
4536c3bad4f8SRichard Henderson     y = load_frw0_i32(a->rm2);
4537c3bad4f8SRichard Henderson     z = load_frw0_i32(a->ra3);
4538ebe9383cSRichard Henderson 
4539c3bad4f8SRichard Henderson     if (a->neg) {
4540ad75a51eSRichard Henderson         gen_helper_fmpynfadd_s(x, tcg_env, x, y, z);
4541ebe9383cSRichard Henderson     } else {
4542ad75a51eSRichard Henderson         gen_helper_fmpyfadd_s(x, tcg_env, x, y, z);
4543ebe9383cSRichard Henderson     }
4544ebe9383cSRichard Henderson 
4545c3bad4f8SRichard Henderson     save_frw_i32(a->t, x);
454631234768SRichard Henderson     return nullify_end(ctx);
4547ebe9383cSRichard Henderson }
4548ebe9383cSRichard Henderson 
trans_fmpyfadd_d(DisasContext * ctx,arg_fmpyfadd_d * a)4549c3bad4f8SRichard Henderson static bool trans_fmpyfadd_d(DisasContext *ctx, arg_fmpyfadd_d *a)
4550ebe9383cSRichard Henderson {
4551c3bad4f8SRichard Henderson     TCGv_i64 x, y, z;
4552ebe9383cSRichard Henderson 
4553ebe9383cSRichard Henderson     nullify_over(ctx);
4554c3bad4f8SRichard Henderson     x = load_frd0(a->rm1);
4555c3bad4f8SRichard Henderson     y = load_frd0(a->rm2);
4556c3bad4f8SRichard Henderson     z = load_frd0(a->ra3);
4557ebe9383cSRichard Henderson 
4558c3bad4f8SRichard Henderson     if (a->neg) {
4559ad75a51eSRichard Henderson         gen_helper_fmpynfadd_d(x, tcg_env, x, y, z);
4560ebe9383cSRichard Henderson     } else {
4561ad75a51eSRichard Henderson         gen_helper_fmpyfadd_d(x, tcg_env, x, y, z);
4562ebe9383cSRichard Henderson     }
4563ebe9383cSRichard Henderson 
4564c3bad4f8SRichard Henderson     save_frd(a->t, x);
456531234768SRichard Henderson     return nullify_end(ctx);
4566ebe9383cSRichard Henderson }
4567ebe9383cSRichard Henderson 
456838193127SRichard Henderson /* Emulate PDC BTLB, called by SeaBIOS-hppa */
trans_diag_btlb(DisasContext * ctx,arg_diag_btlb * a)456938193127SRichard Henderson static bool trans_diag_btlb(DisasContext *ctx, arg_diag_btlb *a)
457015da177bSSven Schnelle {
4571cf6b28d4SHelge Deller     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
4572cf6b28d4SHelge Deller #ifndef CONFIG_USER_ONLY
4573ad75a51eSRichard Henderson     nullify_over(ctx);
4574ad75a51eSRichard Henderson     gen_helper_diag_btlb(tcg_env);
4575cf6b28d4SHelge Deller     return nullify_end(ctx);
457638193127SRichard Henderson #endif
457715da177bSSven Schnelle }
457838193127SRichard Henderson 
457938193127SRichard Henderson /* Print char in %r26 to first serial console, used by SeaBIOS-hppa */
trans_diag_cout(DisasContext * ctx,arg_diag_cout * a)458038193127SRichard Henderson static bool trans_diag_cout(DisasContext *ctx, arg_diag_cout *a)
458138193127SRichard Henderson {
458238193127SRichard Henderson     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
458338193127SRichard Henderson #ifndef CONFIG_USER_ONLY
4584dbca0835SHelge Deller     nullify_over(ctx);
4585dbca0835SHelge Deller     gen_helper_diag_console_output(tcg_env);
4586dbca0835SHelge Deller     return nullify_end(ctx);
4587ad75a51eSRichard Henderson #endif
458838193127SRichard Henderson }
458938193127SRichard Henderson 
trans_diag_getshadowregs_pa1(DisasContext * ctx,arg_empty * a)45903bdf2081SHelge Deller static bool trans_diag_getshadowregs_pa1(DisasContext *ctx, arg_empty *a)
45913bdf2081SHelge Deller {
45923bdf2081SHelge Deller     return !ctx->is_pa20 && do_getshadowregs(ctx);
45933bdf2081SHelge Deller }
45943bdf2081SHelge Deller 
trans_diag_getshadowregs_pa2(DisasContext * ctx,arg_empty * a)45953bdf2081SHelge Deller static bool trans_diag_getshadowregs_pa2(DisasContext *ctx, arg_empty *a)
45963bdf2081SHelge Deller {
45973bdf2081SHelge Deller     return ctx->is_pa20 && do_getshadowregs(ctx);
45983bdf2081SHelge Deller }
45993bdf2081SHelge Deller 
trans_diag_putshadowregs_pa1(DisasContext * ctx,arg_empty * a)46003bdf2081SHelge Deller static bool trans_diag_putshadowregs_pa1(DisasContext *ctx, arg_empty *a)
46013bdf2081SHelge Deller {
46023bdf2081SHelge Deller     return !ctx->is_pa20 && do_putshadowregs(ctx);
46033bdf2081SHelge Deller }
46043bdf2081SHelge Deller 
trans_diag_putshadowregs_pa2(DisasContext * ctx,arg_empty * a)46053bdf2081SHelge Deller static bool trans_diag_putshadowregs_pa2(DisasContext *ctx, arg_empty *a)
46063bdf2081SHelge Deller {
46073bdf2081SHelge Deller     return ctx->is_pa20 && do_putshadowregs(ctx);
46083bdf2081SHelge Deller }
46093bdf2081SHelge Deller 
trans_diag_unimp(DisasContext * ctx,arg_diag_unimp * a)461038193127SRichard Henderson static bool trans_diag_unimp(DisasContext *ctx, arg_diag_unimp *a)
461138193127SRichard Henderson {
461238193127SRichard Henderson     CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR);
4613ad75a51eSRichard Henderson     qemu_log_mask(LOG_UNIMP, "DIAG opcode 0x%04x ignored\n", a->i);
4614ad75a51eSRichard Henderson     return true;
4615ad75a51eSRichard Henderson }
461615da177bSSven Schnelle 
hppa_tr_init_disas_context(DisasContextBase * dcbase,CPUState * cs)4617b542683dSEmilio G. Cota static void hppa_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
461861766fe9SRichard Henderson {
461951b061fbSRichard Henderson     DisasContext *ctx = container_of(dcbase, DisasContext, base);
4620*6dd9b145SRichard Henderson     uint64_t cs_base;
4621f764718dSRichard Henderson     int bound;
462261766fe9SRichard Henderson 
462351b061fbSRichard Henderson     ctx->cs = cs;
4624494737b7SRichard Henderson     ctx->tb_flags = ctx->base.tb->flags;
4625bd6243a3SRichard Henderson     ctx->is_pa20 = hppa_is_pa20(cpu_env(cs));
4626d27fe7c3SRichard Henderson     ctx->psw_xb = ctx->tb_flags & (PSW_X | PSW_B);
46273d68ee7bSRichard Henderson 
46283d68ee7bSRichard Henderson #ifdef CONFIG_USER_ONLY
46293c13b0ffSRichard Henderson     ctx->privilege = PRIV_USER;
46303d68ee7bSRichard Henderson     ctx->mmu_idx = MMU_USER_IDX;
4631217d1a5eSRichard Henderson     ctx->unalign = (ctx->tb_flags & TB_FLAG_UNALIGN ? MO_UNALN : MO_ALIGN);
4632c301f34eSRichard Henderson #else
4633494737b7SRichard Henderson     ctx->privilege = (ctx->tb_flags >> TB_FLAG_PRIV_SHIFT) & 3;
4634bb67ec32SRichard Henderson     ctx->mmu_idx = (ctx->tb_flags & PSW_D
4635bb67ec32SRichard Henderson                     ? PRIV_P_TO_MMU_IDX(ctx->privilege, ctx->tb_flags & PSW_P)
4636451d993dSRichard Henderson                     : ctx->tb_flags & PSW_W ? MMU_ABS_W_IDX : MMU_ABS_IDX);
4637c301f34eSRichard Henderson #endif
46383d68ee7bSRichard Henderson 
46399dfcd243SRichard Henderson     cs_base = ctx->base.tb->cs_base;
4640*6dd9b145SRichard Henderson     ctx->iaoq_first = ctx->base.pc_first + ctx->privilege;
46413d68ee7bSRichard Henderson 
46429dfcd243SRichard Henderson     if (unlikely(cs_base & CS_BASE_DIFFSPACE)) {
4643bc921866SRichard Henderson         ctx->iaq_b.space = cpu_iasq_b;
46449dfcd243SRichard Henderson         ctx->iaq_b.base = cpu_iaoq_b;
46459dfcd243SRichard Henderson     } else if (unlikely(cs_base & CS_BASE_DIFFPAGE)) {
46469dfcd243SRichard Henderson         ctx->iaq_b.base = cpu_iaoq_b;
46479dfcd243SRichard Henderson     } else {
4648*6dd9b145SRichard Henderson         uint64_t iaoq_f_pgofs = ctx->iaoq_first & ~TARGET_PAGE_MASK;
4649*6dd9b145SRichard Henderson         uint64_t iaoq_b_pgofs = cs_base & ~TARGET_PAGE_MASK;
4650*6dd9b145SRichard Henderson         ctx->iaq_b.disp = iaoq_b_pgofs - iaoq_f_pgofs;
4651bc921866SRichard Henderson     }
465261766fe9SRichard Henderson 
4653a4db4a78SRichard Henderson     ctx->zero = tcg_constant_i64(0);
4654a4db4a78SRichard Henderson 
46553d68ee7bSRichard Henderson     /* Bound the number of instructions by those left on the page.  */
46563d68ee7bSRichard Henderson     bound = -(ctx->base.pc_first | TARGET_PAGE_MASK) / 4;
4657b542683dSEmilio G. Cota     ctx->base.max_insns = MIN(ctx->base.max_insns, bound);
465861766fe9SRichard Henderson }
465961766fe9SRichard Henderson 
hppa_tr_tb_start(DisasContextBase * dcbase,CPUState * cs)466051b061fbSRichard Henderson static void hppa_tr_tb_start(DisasContextBase *dcbase, CPUState *cs)
466151b061fbSRichard Henderson {
466251b061fbSRichard Henderson     DisasContext *ctx = container_of(dcbase, DisasContext, base);
466361766fe9SRichard Henderson 
46643d68ee7bSRichard Henderson     /* Seed the nullification status from PSW[N], as saved in TB->FLAGS.  */
466551b061fbSRichard Henderson     ctx->null_cond = cond_make_f();
466651b061fbSRichard Henderson     ctx->psw_n_nonzero = false;
4667494737b7SRichard Henderson     if (ctx->tb_flags & PSW_N) {
466851b061fbSRichard Henderson         ctx->null_cond.c = TCG_COND_ALWAYS;
466951b061fbSRichard Henderson         ctx->psw_n_nonzero = true;
4670129e9cc3SRichard Henderson     }
467151b061fbSRichard Henderson     ctx->null_lab = NULL;
467261766fe9SRichard Henderson }
467361766fe9SRichard Henderson 
hppa_tr_insn_start(DisasContextBase * dcbase,CPUState * cs)467451b061fbSRichard Henderson static void hppa_tr_insn_start(DisasContextBase *dcbase, CPUState *cs)
467551b061fbSRichard Henderson {
467651b061fbSRichard Henderson     DisasContext *ctx = container_of(dcbase, DisasContext, base);
4677*6dd9b145SRichard Henderson     uint64_t iaoq_f, iaoq_b;
4678*6dd9b145SRichard Henderson     int64_t diff;
467951b061fbSRichard Henderson 
4680bc921866SRichard Henderson     tcg_debug_assert(!iaqe_variable(&ctx->iaq_f));
4681*6dd9b145SRichard Henderson 
4682*6dd9b145SRichard Henderson     iaoq_f = ctx->iaoq_first + ctx->iaq_f.disp;
4683*6dd9b145SRichard Henderson     if (iaqe_variable(&ctx->iaq_b)) {
4684*6dd9b145SRichard Henderson         diff = INT32_MIN;
4685*6dd9b145SRichard Henderson     } else {
4686*6dd9b145SRichard Henderson         iaoq_b = ctx->iaoq_first + ctx->iaq_b.disp;
4687*6dd9b145SRichard Henderson         diff = iaoq_b - iaoq_f;
4688*6dd9b145SRichard Henderson         /* Direct branches can only produce a 24-bit displacement. */
4689*6dd9b145SRichard Henderson         tcg_debug_assert(diff == (int32_t)diff);
4690*6dd9b145SRichard Henderson         tcg_debug_assert(diff != INT32_MIN);
4691*6dd9b145SRichard Henderson     }
4692*6dd9b145SRichard Henderson 
4693*6dd9b145SRichard Henderson     tcg_gen_insn_start(iaoq_f & ~TARGET_PAGE_MASK, diff, 0);
469424638bd1SRichard Henderson     ctx->insn_start_updated = false;
469551b061fbSRichard Henderson }
469651b061fbSRichard Henderson 
hppa_tr_translate_insn(DisasContextBase * dcbase,CPUState * cs)469751b061fbSRichard Henderson static void hppa_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs)
469851b061fbSRichard Henderson {
469951b061fbSRichard Henderson     DisasContext *ctx = container_of(dcbase, DisasContext, base);
4700b77af26eSRichard Henderson     CPUHPPAState *env = cpu_env(cs);
470151b061fbSRichard Henderson     DisasJumpType ret;
470251b061fbSRichard Henderson 
470351b061fbSRichard Henderson     /* Execute one insn.  */
4704ba1d0b44SRichard Henderson #ifdef CONFIG_USER_ONLY
4705c301f34eSRichard Henderson     if (ctx->base.pc_next < TARGET_PAGE_SIZE) {
470631234768SRichard Henderson         do_page_zero(ctx);
470731234768SRichard Henderson         ret = ctx->base.is_jmp;
4708869051eaSRichard Henderson         assert(ret != DISAS_NEXT);
4709ba1d0b44SRichard Henderson     } else
4710ba1d0b44SRichard Henderson #endif
4711ba1d0b44SRichard Henderson     {
471261766fe9SRichard Henderson         /* Always fetch the insn, even if nullified, so that we check
471361766fe9SRichard Henderson            the page permissions for execute.  */
47144e116893SIlya Leoshkevich         uint32_t insn = translator_ldl(env, &ctx->base, ctx->base.pc_next);
471561766fe9SRichard Henderson 
4716bc921866SRichard Henderson         /*
4717bc921866SRichard Henderson          * Set up the IA queue for the next insn.
4718bc921866SRichard Henderson          * This will be overwritten by a branch.
4719bc921866SRichard Henderson          */
4720bc921866SRichard Henderson         ctx->iaq_n = NULL;
4721bc921866SRichard Henderson         memset(&ctx->iaq_j, 0, sizeof(ctx->iaq_j));
4722d27fe7c3SRichard Henderson         ctx->psw_b_next = false;
472361766fe9SRichard Henderson 
472451b061fbSRichard Henderson         if (unlikely(ctx->null_cond.c == TCG_COND_ALWAYS)) {
472551b061fbSRichard Henderson             ctx->null_cond.c = TCG_COND_NEVER;
4726869051eaSRichard Henderson             ret = DISAS_NEXT;
4727129e9cc3SRichard Henderson         } else {
47281a19da0dSRichard Henderson             ctx->insn = insn;
472931274b46SRichard Henderson             if (!decode(ctx, insn)) {
473031274b46SRichard Henderson                 gen_illegal(ctx);
473131274b46SRichard Henderson             }
473231234768SRichard Henderson             ret = ctx->base.is_jmp;
473351b061fbSRichard Henderson             assert(ctx->null_lab == NULL);
4734129e9cc3SRichard Henderson         }
4735d27fe7c3SRichard Henderson 
4736d27fe7c3SRichard Henderson         if (ret != DISAS_NORETURN) {
4737d27fe7c3SRichard Henderson             set_psw_xb(ctx, ctx->psw_b_next ? PSW_B : 0);
4738d27fe7c3SRichard Henderson         }
473961766fe9SRichard Henderson     }
474061766fe9SRichard Henderson 
4741dbdccbdfSRichard Henderson     /* If the TranslationBlock must end, do so. */
4742c301f34eSRichard Henderson     ctx->base.pc_next += 4;
4743dbdccbdfSRichard Henderson     if (ret != DISAS_NEXT) {
4744dbdccbdfSRichard Henderson         return;
474561766fe9SRichard Henderson     }
4746dbdccbdfSRichard Henderson     /* Note this also detects a priority change. */
4747bc921866SRichard Henderson     if (iaqe_variable(&ctx->iaq_b)
4748bc921866SRichard Henderson         || ctx->iaq_b.disp != ctx->iaq_f.disp + 4) {
4749dbdccbdfSRichard Henderson         ctx->base.is_jmp = DISAS_IAQ_N_STALE;
4750dbdccbdfSRichard Henderson         return;
475161766fe9SRichard Henderson     }
4752c5d0aec2SRichard Henderson 
4753dbdccbdfSRichard Henderson     /*
4754dbdccbdfSRichard Henderson      * Advance the insn queue.
4755dbdccbdfSRichard Henderson      * The only exit now is DISAS_TOO_MANY from the translator loop.
4756dbdccbdfSRichard Henderson      */
4757bc921866SRichard Henderson     ctx->iaq_f.disp = ctx->iaq_b.disp;
4758bc921866SRichard Henderson     if (!ctx->iaq_n) {
4759bc921866SRichard Henderson         ctx->iaq_b.disp += 4;
4760bc921866SRichard Henderson         return;
4761bc921866SRichard Henderson     }
4762bc921866SRichard Henderson     /*
4763bc921866SRichard Henderson      * If IAQ_Next is variable in any way, we need to copy into the
4764bc921866SRichard Henderson      * IAQ_Back globals, in case the next insn raises an exception.
4765bc921866SRichard Henderson      */
4766bc921866SRichard Henderson     if (ctx->iaq_n->base) {
4767bc921866SRichard Henderson         copy_iaoq_entry(ctx, cpu_iaoq_b, ctx->iaq_n);
4768bc921866SRichard Henderson         ctx->iaq_b.base = cpu_iaoq_b;
4769bc921866SRichard Henderson         ctx->iaq_b.disp = 0;
47700dcd6640SRichard Henderson     } else {
4771bc921866SRichard Henderson         ctx->iaq_b.disp = ctx->iaq_n->disp;
47720dcd6640SRichard Henderson     }
4773bc921866SRichard Henderson     if (ctx->iaq_n->space) {
4774bc921866SRichard Henderson         tcg_gen_mov_i64(cpu_iasq_b, ctx->iaq_n->space);
4775bc921866SRichard Henderson         ctx->iaq_b.space = cpu_iasq_b;
4776c5d0aec2SRichard Henderson     }
477761766fe9SRichard Henderson }
477861766fe9SRichard Henderson 
hppa_tr_tb_stop(DisasContextBase * dcbase,CPUState * cs)477961766fe9SRichard Henderson static void hppa_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)
478061766fe9SRichard Henderson {
478161766fe9SRichard Henderson     DisasContext *ctx = container_of(dcbase, DisasContext, base);
478261766fe9SRichard Henderson     DisasJumpType is_jmp = ctx->base.is_jmp;
4783dbdccbdfSRichard Henderson     /* Assume the insn queue has not been advanced. */
4784bc921866SRichard Henderson     DisasIAQE *f = &ctx->iaq_b;
4785bc921866SRichard Henderson     DisasIAQE *b = ctx->iaq_n;
478661766fe9SRichard Henderson 
478761766fe9SRichard Henderson     switch (is_jmp) {
478861766fe9SRichard Henderson     case DISAS_NORETURN:
478961766fe9SRichard Henderson         break;
479061766fe9SRichard Henderson     case DISAS_TOO_MANY:
4791dbdccbdfSRichard Henderson         /* The insn queue has not been advanced. */
4792bc921866SRichard Henderson         f = &ctx->iaq_f;
4793bc921866SRichard Henderson         b = &ctx->iaq_b;
479461766fe9SRichard Henderson         /* FALLTHRU */
4795dbdccbdfSRichard Henderson     case DISAS_IAQ_N_STALE:
4796bc921866SRichard Henderson         if (use_goto_tb(ctx, f, b)
4797dbdccbdfSRichard Henderson             && (ctx->null_cond.c == TCG_COND_NEVER
4798dbdccbdfSRichard Henderson                 || ctx->null_cond.c == TCG_COND_ALWAYS)) {
4799dbdccbdfSRichard Henderson             nullify_set(ctx, ctx->null_cond.c == TCG_COND_ALWAYS);
4800bc921866SRichard Henderson             gen_goto_tb(ctx, 0, f, b);
48018532a14eSRichard Henderson             break;
480261766fe9SRichard Henderson         }
4803c5d0aec2SRichard Henderson         /* FALLTHRU */
4804dbdccbdfSRichard Henderson     case DISAS_IAQ_N_STALE_EXIT:
4805bc921866SRichard Henderson         install_iaq_entries(ctx, f, b);
4806dbdccbdfSRichard Henderson         nullify_save(ctx);
4807dbdccbdfSRichard Henderson         if (is_jmp == DISAS_IAQ_N_STALE_EXIT) {
4808dbdccbdfSRichard Henderson             tcg_gen_exit_tb(NULL, 0);
4809dbdccbdfSRichard Henderson             break;
4810dbdccbdfSRichard Henderson         }
4811dbdccbdfSRichard Henderson         /* FALLTHRU */
4812dbdccbdfSRichard Henderson     case DISAS_IAQ_N_UPDATED:
4813dbdccbdfSRichard Henderson         tcg_gen_lookup_and_goto_ptr();
4814dbdccbdfSRichard Henderson         break;
4815c5d0aec2SRichard Henderson     case DISAS_EXIT:
4816c5d0aec2SRichard Henderson         tcg_gen_exit_tb(NULL, 0);
481761766fe9SRichard Henderson         break;
481861766fe9SRichard Henderson     default:
481961766fe9SRichard Henderson         g_assert_not_reached();
482061766fe9SRichard Henderson     }
482180603007SRichard Henderson 
482280603007SRichard Henderson     for (DisasDelayException *e = ctx->delay_excp_list; e ; e = e->next) {
482380603007SRichard Henderson         gen_set_label(e->lab);
482480603007SRichard Henderson         if (e->set_n >= 0) {
482580603007SRichard Henderson             tcg_gen_movi_i64(cpu_psw_n, e->set_n);
482680603007SRichard Henderson         }
482780603007SRichard Henderson         if (e->set_iir) {
482880603007SRichard Henderson             tcg_gen_st_i64(tcg_constant_i64(e->insn), tcg_env,
482980603007SRichard Henderson                            offsetof(CPUHPPAState, cr[CR_IIR]));
483080603007SRichard Henderson         }
483180603007SRichard Henderson         install_iaq_entries(ctx, &e->iaq_f, &e->iaq_b);
483280603007SRichard Henderson         gen_excp_1(e->excp);
483380603007SRichard Henderson     }
483461766fe9SRichard Henderson }
483561766fe9SRichard Henderson 
4836962a145cSRichard Henderson #ifdef CONFIG_USER_ONLY
hppa_tr_disas_log(const DisasContextBase * dcbase,CPUState * cs,FILE * logfile)4837b67c567bSRichard Henderson static bool hppa_tr_disas_log(const DisasContextBase *dcbase,
48388eb806a7SRichard Henderson                               CPUState *cs, FILE *logfile)
483961766fe9SRichard Henderson {
4840c301f34eSRichard Henderson     target_ulong pc = dcbase->pc_first;
484161766fe9SRichard Henderson 
484261766fe9SRichard Henderson     switch (pc) {
484361766fe9SRichard Henderson     case 0x00:
48448eb806a7SRichard Henderson         fprintf(logfile, "IN:\n0x00000000:  (null)\n");
4845b67c567bSRichard Henderson         return true;
484661766fe9SRichard Henderson     case 0xb0:
48478eb806a7SRichard Henderson         fprintf(logfile, "IN:\n0x000000b0:  light-weight-syscall\n");
4848b67c567bSRichard Henderson         return true;
484961766fe9SRichard Henderson     case 0xe0:
48508eb806a7SRichard Henderson         fprintf(logfile, "IN:\n0x000000e0:  set-thread-pointer-syscall\n");
4851b67c567bSRichard Henderson         return true;
485261766fe9SRichard Henderson     case 0x100:
48538eb806a7SRichard Henderson         fprintf(logfile, "IN:\n0x00000100:  syscall\n");
4854b67c567bSRichard Henderson         return true;
485561766fe9SRichard Henderson     }
4856b67c567bSRichard Henderson     return false;
485761766fe9SRichard Henderson }
4858962a145cSRichard Henderson #endif
485961766fe9SRichard Henderson 
486061766fe9SRichard Henderson static const TranslatorOps hppa_tr_ops = {
486161766fe9SRichard Henderson     .init_disas_context = hppa_tr_init_disas_context,
486261766fe9SRichard Henderson     .tb_start           = hppa_tr_tb_start,
486361766fe9SRichard Henderson     .insn_start         = hppa_tr_insn_start,
486461766fe9SRichard Henderson     .translate_insn     = hppa_tr_translate_insn,
486561766fe9SRichard Henderson     .tb_stop            = hppa_tr_tb_stop,
4866962a145cSRichard Henderson #ifdef CONFIG_USER_ONLY
486761766fe9SRichard Henderson     .disas_log          = hppa_tr_disas_log,
4868962a145cSRichard Henderson #endif
486961766fe9SRichard Henderson };
487061766fe9SRichard Henderson 
gen_intermediate_code(CPUState * cs,TranslationBlock * tb,int * max_insns,vaddr pc,void * host_pc)4871597f9b2dSRichard Henderson void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int *max_insns,
487232f0c394SAnton Johansson                            vaddr pc, void *host_pc)
487361766fe9SRichard Henderson {
4874bc921866SRichard Henderson     DisasContext ctx = { };
4875306c8721SRichard Henderson     translator_loop(cs, tb, max_insns, pc, host_pc, &hppa_tr_ops, &ctx.base);
487661766fe9SRichard Henderson }
4877