161766fe9SRichard Henderson /* 261766fe9SRichard Henderson * HPPA emulation cpu translation for qemu. 361766fe9SRichard Henderson * 461766fe9SRichard Henderson * Copyright (c) 2016 Richard Henderson <rth@twiddle.net> 561766fe9SRichard Henderson * 661766fe9SRichard Henderson * This library is free software; you can redistribute it and/or 761766fe9SRichard Henderson * modify it under the terms of the GNU Lesser General Public 861766fe9SRichard Henderson * License as published by the Free Software Foundation; either 9d6ea4236SChetan Pant * version 2.1 of the License, or (at your option) any later version. 1061766fe9SRichard Henderson * 1161766fe9SRichard Henderson * This library is distributed in the hope that it will be useful, 1261766fe9SRichard Henderson * but WITHOUT ANY WARRANTY; without even the implied warranty of 1361766fe9SRichard Henderson * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1461766fe9SRichard Henderson * Lesser General Public License for more details. 1561766fe9SRichard Henderson * 1661766fe9SRichard Henderson * You should have received a copy of the GNU Lesser General Public 1761766fe9SRichard Henderson * License along with this library; if not, see <http://www.gnu.org/licenses/>. 1861766fe9SRichard Henderson */ 1961766fe9SRichard Henderson 2061766fe9SRichard Henderson #include "qemu/osdep.h" 2161766fe9SRichard Henderson #include "cpu.h" 2261766fe9SRichard Henderson #include "disas/disas.h" 2361766fe9SRichard Henderson #include "qemu/host-utils.h" 2461766fe9SRichard Henderson #include "exec/exec-all.h" 2574781c08SPhilippe Mathieu-Daudé #include "exec/page-protection.h" 26dcb32f1dSPhilippe Mathieu-Daudé #include "tcg/tcg-op.h" 270843563fSRichard Henderson #include "tcg/tcg-op-gvec.h" 2861766fe9SRichard Henderson #include "exec/helper-proto.h" 2961766fe9SRichard Henderson #include "exec/helper-gen.h" 30869051eaSRichard Henderson #include "exec/translator.h" 3161766fe9SRichard Henderson #include "exec/log.h" 3261766fe9SRichard Henderson 33d53106c9SRichard Henderson #define HELPER_H "helper.h" 34d53106c9SRichard Henderson #include "exec/helper-info.c.inc" 35d53106c9SRichard Henderson #undef HELPER_H 36d53106c9SRichard Henderson 37aac0f603SRichard Henderson /* Choose to use explicit sizes within this file. */ 38aac0f603SRichard Henderson #undef tcg_temp_new 39d53106c9SRichard Henderson 4061766fe9SRichard Henderson typedef struct DisasCond { 4161766fe9SRichard Henderson TCGCond c; 426fd0c7bcSRichard Henderson TCGv_i64 a0, a1; 4361766fe9SRichard Henderson } DisasCond; 4461766fe9SRichard Henderson 45bc921866SRichard Henderson typedef struct DisasIAQE { 46bc921866SRichard Henderson /* IASQ; may be null for no change from TB. */ 47bc921866SRichard Henderson TCGv_i64 space; 480d89cb7cSRichard Henderson /* IAOQ base; may be null for relative address. */ 49bc921866SRichard Henderson TCGv_i64 base; 500d89cb7cSRichard Henderson /* IAOQ addend; if base is null, relative to ctx->iaoq_first. */ 51bc921866SRichard Henderson int64_t disp; 52bc921866SRichard Henderson } DisasIAQE; 53bc921866SRichard Henderson 5480603007SRichard Henderson typedef struct DisasDelayException { 5580603007SRichard Henderson struct DisasDelayException *next; 5680603007SRichard Henderson TCGLabel *lab; 5780603007SRichard Henderson uint32_t insn; 5880603007SRichard Henderson bool set_iir; 5980603007SRichard Henderson int8_t set_n; 6080603007SRichard Henderson uint8_t excp; 6180603007SRichard Henderson /* Saved state at parent insn. */ 6280603007SRichard Henderson DisasIAQE iaq_f, iaq_b; 6380603007SRichard Henderson } DisasDelayException; 6480603007SRichard Henderson 6561766fe9SRichard Henderson typedef struct DisasContext { 66d01a3625SRichard Henderson DisasContextBase base; 6761766fe9SRichard Henderson CPUState *cs; 6861766fe9SRichard Henderson 69bc921866SRichard Henderson /* IAQ_Front, IAQ_Back. */ 70bc921866SRichard Henderson DisasIAQE iaq_f, iaq_b; 71bc921866SRichard Henderson /* IAQ_Next, for jumps, otherwise null for simple advance. */ 72bc921866SRichard Henderson DisasIAQE iaq_j, *iaq_n; 7361766fe9SRichard Henderson 740d89cb7cSRichard Henderson /* IAOQ_Front at entry to TB. */ 750d89cb7cSRichard Henderson uint64_t iaoq_first; 760d89cb7cSRichard Henderson 7761766fe9SRichard Henderson DisasCond null_cond; 7861766fe9SRichard Henderson TCGLabel *null_lab; 7961766fe9SRichard Henderson 8080603007SRichard Henderson DisasDelayException *delay_excp_list; 81a4db4a78SRichard Henderson TCGv_i64 zero; 82a4db4a78SRichard Henderson 831a19da0dSRichard Henderson uint32_t insn; 84494737b7SRichard Henderson uint32_t tb_flags; 853d68ee7bSRichard Henderson int mmu_idx; 863d68ee7bSRichard Henderson int privilege; 87*d27fe7c3SRichard Henderson uint32_t psw_xb; 8861766fe9SRichard Henderson bool psw_n_nonzero; 89*d27fe7c3SRichard Henderson bool psw_b_next; 90bd6243a3SRichard Henderson bool is_pa20; 9124638bd1SRichard Henderson bool insn_start_updated; 92217d1a5eSRichard Henderson 93217d1a5eSRichard Henderson #ifdef CONFIG_USER_ONLY 94217d1a5eSRichard Henderson MemOp unalign; 95217d1a5eSRichard Henderson #endif 9661766fe9SRichard Henderson } DisasContext; 9761766fe9SRichard Henderson 98217d1a5eSRichard Henderson #ifdef CONFIG_USER_ONLY 99217d1a5eSRichard Henderson #define UNALIGN(C) (C)->unalign 10017fe594cSRichard Henderson #define MMU_DISABLED(C) false 101217d1a5eSRichard Henderson #else 1022d4afb03SRichard Henderson #define UNALIGN(C) MO_ALIGN 10317fe594cSRichard Henderson #define MMU_DISABLED(C) MMU_IDX_MMU_DISABLED((C)->mmu_idx) 104217d1a5eSRichard Henderson #endif 105217d1a5eSRichard Henderson 106e36f27efSRichard Henderson /* Note that ssm/rsm instructions number PSW_W and PSW_E differently. */ 107451e4ffdSRichard Henderson static int expand_sm_imm(DisasContext *ctx, int val) 108e36f27efSRichard Henderson { 109881d1073SHelge Deller /* Keep unimplemented bits disabled -- see cpu_hppa_put_psw. */ 110881d1073SHelge Deller if (ctx->is_pa20) { 111e36f27efSRichard Henderson if (val & PSW_SM_W) { 112881d1073SHelge Deller val |= PSW_W; 113881d1073SHelge Deller } 114881d1073SHelge Deller val &= ~(PSW_SM_W | PSW_SM_E | PSW_G); 115881d1073SHelge Deller } else { 116881d1073SHelge Deller val &= ~(PSW_SM_W | PSW_SM_E | PSW_O); 117e36f27efSRichard Henderson } 118e36f27efSRichard Henderson return val; 119e36f27efSRichard Henderson } 120e36f27efSRichard Henderson 121deee69a1SRichard Henderson /* Inverted space register indicates 0 means sr0 not inferred from base. */ 122451e4ffdSRichard Henderson static int expand_sr3x(DisasContext *ctx, int val) 123deee69a1SRichard Henderson { 124deee69a1SRichard Henderson return ~val; 125deee69a1SRichard Henderson } 126deee69a1SRichard Henderson 1271cd012a5SRichard Henderson /* Convert the M:A bits within a memory insn to the tri-state value 1281cd012a5SRichard Henderson we use for the final M. */ 129451e4ffdSRichard Henderson static int ma_to_m(DisasContext *ctx, int val) 1301cd012a5SRichard Henderson { 1311cd012a5SRichard Henderson return val & 2 ? (val & 1 ? -1 : 1) : 0; 1321cd012a5SRichard Henderson } 1331cd012a5SRichard Henderson 134740038d7SRichard Henderson /* Convert the sign of the displacement to a pre or post-modify. */ 135451e4ffdSRichard Henderson static int pos_to_m(DisasContext *ctx, int val) 136740038d7SRichard Henderson { 137740038d7SRichard Henderson return val ? 1 : -1; 138740038d7SRichard Henderson } 139740038d7SRichard Henderson 140451e4ffdSRichard Henderson static int neg_to_m(DisasContext *ctx, int val) 141740038d7SRichard Henderson { 142740038d7SRichard Henderson return val ? -1 : 1; 143740038d7SRichard Henderson } 144740038d7SRichard Henderson 145740038d7SRichard Henderson /* Used for branch targets and fp memory ops. */ 146451e4ffdSRichard Henderson static int expand_shl2(DisasContext *ctx, int val) 14701afb7beSRichard Henderson { 14801afb7beSRichard Henderson return val << 2; 14901afb7beSRichard Henderson } 15001afb7beSRichard Henderson 1510588e061SRichard Henderson /* Used for assemble_21. */ 152451e4ffdSRichard Henderson static int expand_shl11(DisasContext *ctx, int val) 1530588e061SRichard Henderson { 1540588e061SRichard Henderson return val << 11; 1550588e061SRichard Henderson } 1560588e061SRichard Henderson 15772ae4f2bSRichard Henderson static int assemble_6(DisasContext *ctx, int val) 15872ae4f2bSRichard Henderson { 15972ae4f2bSRichard Henderson /* 16072ae4f2bSRichard Henderson * Officially, 32 * x + 32 - y. 16172ae4f2bSRichard Henderson * Here, x is already in bit 5, and y is [4:0]. 16272ae4f2bSRichard Henderson * Since -y = ~y + 1, in 5 bits 32 - y => y ^ 31 + 1, 16372ae4f2bSRichard Henderson * with the overflow from bit 4 summing with x. 16472ae4f2bSRichard Henderson */ 16572ae4f2bSRichard Henderson return (val ^ 31) + 1; 16672ae4f2bSRichard Henderson } 16772ae4f2bSRichard Henderson 1684768c28eSRichard Henderson /* Expander for assemble_16a(s,cat(im10a,0),i). */ 1694768c28eSRichard Henderson static int expand_11a(DisasContext *ctx, int val) 1704768c28eSRichard Henderson { 1714768c28eSRichard Henderson /* 1724768c28eSRichard Henderson * @val is bit 0 and bits [4:15]. 1734768c28eSRichard Henderson * Swizzle thing around depending on PSW.W. 1744768c28eSRichard Henderson */ 1754768c28eSRichard Henderson int im10a = extract32(val, 1, 10); 1764768c28eSRichard Henderson int s = extract32(val, 11, 2); 1774768c28eSRichard Henderson int i = (-(val & 1) << 13) | (im10a << 3); 1784768c28eSRichard Henderson 1794768c28eSRichard Henderson if (ctx->tb_flags & PSW_W) { 1804768c28eSRichard Henderson i ^= s << 13; 1814768c28eSRichard Henderson } 1824768c28eSRichard Henderson return i; 1834768c28eSRichard Henderson } 1844768c28eSRichard Henderson 18546174e14SRichard Henderson /* Expander for assemble_16a(s,im11a,i). */ 18646174e14SRichard Henderson static int expand_12a(DisasContext *ctx, int val) 18746174e14SRichard Henderson { 18846174e14SRichard Henderson /* 18946174e14SRichard Henderson * @val is bit 0 and bits [3:15]. 19046174e14SRichard Henderson * Swizzle thing around depending on PSW.W. 19146174e14SRichard Henderson */ 19246174e14SRichard Henderson int im11a = extract32(val, 1, 11); 19346174e14SRichard Henderson int s = extract32(val, 12, 2); 19446174e14SRichard Henderson int i = (-(val & 1) << 13) | (im11a << 2); 19546174e14SRichard Henderson 19646174e14SRichard Henderson if (ctx->tb_flags & PSW_W) { 19746174e14SRichard Henderson i ^= s << 13; 19846174e14SRichard Henderson } 19946174e14SRichard Henderson return i; 20046174e14SRichard Henderson } 20146174e14SRichard Henderson 20272bace2dSRichard Henderson /* Expander for assemble_16(s,im14). */ 20372bace2dSRichard Henderson static int expand_16(DisasContext *ctx, int val) 20472bace2dSRichard Henderson { 20572bace2dSRichard Henderson /* 20672bace2dSRichard Henderson * @val is bits [0:15], containing both im14 and s. 20772bace2dSRichard Henderson * Swizzle thing around depending on PSW.W. 20872bace2dSRichard Henderson */ 20972bace2dSRichard Henderson int s = extract32(val, 14, 2); 21072bace2dSRichard Henderson int i = (-(val & 1) << 13) | extract32(val, 1, 13); 21172bace2dSRichard Henderson 21272bace2dSRichard Henderson if (ctx->tb_flags & PSW_W) { 21372bace2dSRichard Henderson i ^= s << 13; 21472bace2dSRichard Henderson } 21572bace2dSRichard Henderson return i; 21672bace2dSRichard Henderson } 21772bace2dSRichard Henderson 21872bace2dSRichard Henderson /* The sp field is only present with !PSW_W. */ 21972bace2dSRichard Henderson static int sp0_if_wide(DisasContext *ctx, int sp) 22072bace2dSRichard Henderson { 22172bace2dSRichard Henderson return ctx->tb_flags & PSW_W ? 0 : sp; 22272bace2dSRichard Henderson } 22372bace2dSRichard Henderson 224c65c3ee1SRichard Henderson /* Translate CMPI doubleword conditions to standard. */ 225c65c3ee1SRichard Henderson static int cmpbid_c(DisasContext *ctx, int val) 226c65c3ee1SRichard Henderson { 227c65c3ee1SRichard Henderson return val ? val : 4; /* 0 == "*<<" */ 228c65c3ee1SRichard Henderson } 229c65c3ee1SRichard Henderson 23082d0c831SRichard Henderson /* 23182d0c831SRichard Henderson * In many places pa1.x did not decode the bit that later became 23282d0c831SRichard Henderson * the pa2.0 D bit. Suppress D unless the cpu is pa2.0. 23382d0c831SRichard Henderson */ 23482d0c831SRichard Henderson static int pa20_d(DisasContext *ctx, int val) 23582d0c831SRichard Henderson { 23682d0c831SRichard Henderson return ctx->is_pa20 & val; 23782d0c831SRichard Henderson } 23801afb7beSRichard Henderson 23940f9f908SRichard Henderson /* Include the auto-generated decoder. */ 240abff1abfSPaolo Bonzini #include "decode-insns.c.inc" 24140f9f908SRichard Henderson 24261766fe9SRichard Henderson /* We are not using a goto_tb (for whatever reason), but have updated 24361766fe9SRichard Henderson the iaq (for whatever reason), so don't do it again on exit. */ 244869051eaSRichard Henderson #define DISAS_IAQ_N_UPDATED DISAS_TARGET_0 24561766fe9SRichard Henderson 24661766fe9SRichard Henderson /* We are exiting the TB, but have neither emitted a goto_tb, nor 24761766fe9SRichard Henderson updated the iaq for the next instruction to be executed. */ 248869051eaSRichard Henderson #define DISAS_IAQ_N_STALE DISAS_TARGET_1 24961766fe9SRichard Henderson 250e1b5a5edSRichard Henderson /* Similarly, but we want to return to the main loop immediately 251e1b5a5edSRichard Henderson to recognize unmasked interrupts. */ 252e1b5a5edSRichard Henderson #define DISAS_IAQ_N_STALE_EXIT DISAS_TARGET_2 253c5d0aec2SRichard Henderson #define DISAS_EXIT DISAS_TARGET_3 254e1b5a5edSRichard Henderson 25561766fe9SRichard Henderson /* global register indexes */ 2566fd0c7bcSRichard Henderson static TCGv_i64 cpu_gr[32]; 25733423472SRichard Henderson static TCGv_i64 cpu_sr[4]; 258494737b7SRichard Henderson static TCGv_i64 cpu_srH; 2596fd0c7bcSRichard Henderson static TCGv_i64 cpu_iaoq_f; 2606fd0c7bcSRichard Henderson static TCGv_i64 cpu_iaoq_b; 261c301f34eSRichard Henderson static TCGv_i64 cpu_iasq_f; 262c301f34eSRichard Henderson static TCGv_i64 cpu_iasq_b; 2636fd0c7bcSRichard Henderson static TCGv_i64 cpu_sar; 2646fd0c7bcSRichard Henderson static TCGv_i64 cpu_psw_n; 2656fd0c7bcSRichard Henderson static TCGv_i64 cpu_psw_v; 2666fd0c7bcSRichard Henderson static TCGv_i64 cpu_psw_cb; 2676fd0c7bcSRichard Henderson static TCGv_i64 cpu_psw_cb_msb; 268*d27fe7c3SRichard Henderson static TCGv_i32 cpu_psw_xb; 26961766fe9SRichard Henderson 27061766fe9SRichard Henderson void hppa_translate_init(void) 27161766fe9SRichard Henderson { 27261766fe9SRichard Henderson #define DEF_VAR(V) { &cpu_##V, #V, offsetof(CPUHPPAState, V) } 27361766fe9SRichard Henderson 2746fd0c7bcSRichard Henderson typedef struct { TCGv_i64 *var; const char *name; int ofs; } GlobalVar; 27561766fe9SRichard Henderson static const GlobalVar vars[] = { 27635136a77SRichard Henderson { &cpu_sar, "sar", offsetof(CPUHPPAState, cr[CR_SAR]) }, 27761766fe9SRichard Henderson DEF_VAR(psw_n), 27861766fe9SRichard Henderson DEF_VAR(psw_v), 27961766fe9SRichard Henderson DEF_VAR(psw_cb), 28061766fe9SRichard Henderson DEF_VAR(psw_cb_msb), 28161766fe9SRichard Henderson DEF_VAR(iaoq_f), 28261766fe9SRichard Henderson DEF_VAR(iaoq_b), 28361766fe9SRichard Henderson }; 28461766fe9SRichard Henderson 28561766fe9SRichard Henderson #undef DEF_VAR 28661766fe9SRichard Henderson 28761766fe9SRichard Henderson /* Use the symbolic register names that match the disassembler. */ 28861766fe9SRichard Henderson static const char gr_names[32][4] = { 28961766fe9SRichard Henderson "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", 29061766fe9SRichard Henderson "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", 29161766fe9SRichard Henderson "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", 29261766fe9SRichard Henderson "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31" 29361766fe9SRichard Henderson }; 29433423472SRichard Henderson /* SR[4-7] are not global registers so that we can index them. */ 295494737b7SRichard Henderson static const char sr_names[5][4] = { 296494737b7SRichard Henderson "sr0", "sr1", "sr2", "sr3", "srH" 29733423472SRichard Henderson }; 29861766fe9SRichard Henderson 29961766fe9SRichard Henderson int i; 30061766fe9SRichard Henderson 301f764718dSRichard Henderson cpu_gr[0] = NULL; 30261766fe9SRichard Henderson for (i = 1; i < 32; i++) { 303ad75a51eSRichard Henderson cpu_gr[i] = tcg_global_mem_new(tcg_env, 30461766fe9SRichard Henderson offsetof(CPUHPPAState, gr[i]), 30561766fe9SRichard Henderson gr_names[i]); 30661766fe9SRichard Henderson } 30733423472SRichard Henderson for (i = 0; i < 4; i++) { 308ad75a51eSRichard Henderson cpu_sr[i] = tcg_global_mem_new_i64(tcg_env, 30933423472SRichard Henderson offsetof(CPUHPPAState, sr[i]), 31033423472SRichard Henderson sr_names[i]); 31133423472SRichard Henderson } 312ad75a51eSRichard Henderson cpu_srH = tcg_global_mem_new_i64(tcg_env, 313494737b7SRichard Henderson offsetof(CPUHPPAState, sr[4]), 314494737b7SRichard Henderson sr_names[4]); 31561766fe9SRichard Henderson 31661766fe9SRichard Henderson for (i = 0; i < ARRAY_SIZE(vars); ++i) { 31761766fe9SRichard Henderson const GlobalVar *v = &vars[i]; 318ad75a51eSRichard Henderson *v->var = tcg_global_mem_new(tcg_env, v->ofs, v->name); 31961766fe9SRichard Henderson } 320c301f34eSRichard Henderson 321*d27fe7c3SRichard Henderson cpu_psw_xb = tcg_global_mem_new_i32(tcg_env, 322*d27fe7c3SRichard Henderson offsetof(CPUHPPAState, psw_xb), 323*d27fe7c3SRichard Henderson "psw_xb"); 324ad75a51eSRichard Henderson cpu_iasq_f = tcg_global_mem_new_i64(tcg_env, 325c301f34eSRichard Henderson offsetof(CPUHPPAState, iasq_f), 326c301f34eSRichard Henderson "iasq_f"); 327ad75a51eSRichard Henderson cpu_iasq_b = tcg_global_mem_new_i64(tcg_env, 328c301f34eSRichard Henderson offsetof(CPUHPPAState, iasq_b), 329c301f34eSRichard Henderson "iasq_b"); 33061766fe9SRichard Henderson } 33161766fe9SRichard Henderson 332f5b5c857SRichard Henderson static void set_insn_breg(DisasContext *ctx, int breg) 333f5b5c857SRichard Henderson { 33424638bd1SRichard Henderson assert(!ctx->insn_start_updated); 33524638bd1SRichard Henderson ctx->insn_start_updated = true; 33624638bd1SRichard Henderson tcg_set_insn_start_param(ctx->base.insn_start, 2, breg); 337f5b5c857SRichard Henderson } 338f5b5c857SRichard Henderson 339129e9cc3SRichard Henderson static DisasCond cond_make_f(void) 340129e9cc3SRichard Henderson { 341f764718dSRichard Henderson return (DisasCond){ 342f764718dSRichard Henderson .c = TCG_COND_NEVER, 343f764718dSRichard Henderson .a0 = NULL, 344f764718dSRichard Henderson .a1 = NULL, 345f764718dSRichard Henderson }; 346129e9cc3SRichard Henderson } 347129e9cc3SRichard Henderson 348df0232feSRichard Henderson static DisasCond cond_make_t(void) 349df0232feSRichard Henderson { 350df0232feSRichard Henderson return (DisasCond){ 351df0232feSRichard Henderson .c = TCG_COND_ALWAYS, 352df0232feSRichard Henderson .a0 = NULL, 353df0232feSRichard Henderson .a1 = NULL, 354df0232feSRichard Henderson }; 355df0232feSRichard Henderson } 356df0232feSRichard Henderson 357129e9cc3SRichard Henderson static DisasCond cond_make_n(void) 358129e9cc3SRichard Henderson { 359f764718dSRichard Henderson return (DisasCond){ 360f764718dSRichard Henderson .c = TCG_COND_NE, 361f764718dSRichard Henderson .a0 = cpu_psw_n, 3626fd0c7bcSRichard Henderson .a1 = tcg_constant_i64(0) 363f764718dSRichard Henderson }; 364129e9cc3SRichard Henderson } 365129e9cc3SRichard Henderson 3664c42fd0dSRichard Henderson static DisasCond cond_make_tt(TCGCond c, TCGv_i64 a0, TCGv_i64 a1) 367b47a4a02SSven Schnelle { 368b47a4a02SSven Schnelle assert (c != TCG_COND_NEVER && c != TCG_COND_ALWAYS); 3694fe9533aSRichard Henderson return (DisasCond){ .c = c, .a0 = a0, .a1 = a1 }; 3704fe9533aSRichard Henderson } 3714fe9533aSRichard Henderson 3724c42fd0dSRichard Henderson static DisasCond cond_make_ti(TCGCond c, TCGv_i64 a0, uint64_t imm) 3734fe9533aSRichard Henderson { 3744c42fd0dSRichard Henderson return cond_make_tt(c, a0, tcg_constant_i64(imm)); 375b47a4a02SSven Schnelle } 376b47a4a02SSven Schnelle 3774c42fd0dSRichard Henderson static DisasCond cond_make_vi(TCGCond c, TCGv_i64 a0, uint64_t imm) 378129e9cc3SRichard Henderson { 379aac0f603SRichard Henderson TCGv_i64 tmp = tcg_temp_new_i64(); 3806fd0c7bcSRichard Henderson tcg_gen_mov_i64(tmp, a0); 3814c42fd0dSRichard Henderson return cond_make_ti(c, tmp, imm); 382129e9cc3SRichard Henderson } 383129e9cc3SRichard Henderson 3844c42fd0dSRichard Henderson static DisasCond cond_make_vv(TCGCond c, TCGv_i64 a0, TCGv_i64 a1) 385129e9cc3SRichard Henderson { 386aac0f603SRichard Henderson TCGv_i64 t0 = tcg_temp_new_i64(); 387aac0f603SRichard Henderson TCGv_i64 t1 = tcg_temp_new_i64(); 388129e9cc3SRichard Henderson 3896fd0c7bcSRichard Henderson tcg_gen_mov_i64(t0, a0); 3906fd0c7bcSRichard Henderson tcg_gen_mov_i64(t1, a1); 3914c42fd0dSRichard Henderson return cond_make_tt(c, t0, t1); 392129e9cc3SRichard Henderson } 393129e9cc3SRichard Henderson 3946fd0c7bcSRichard Henderson static TCGv_i64 load_gpr(DisasContext *ctx, unsigned reg) 39561766fe9SRichard Henderson { 39661766fe9SRichard Henderson if (reg == 0) { 397bc3da3cfSRichard Henderson return ctx->zero; 39861766fe9SRichard Henderson } else { 39961766fe9SRichard Henderson return cpu_gr[reg]; 40061766fe9SRichard Henderson } 40161766fe9SRichard Henderson } 40261766fe9SRichard Henderson 4036fd0c7bcSRichard Henderson static TCGv_i64 dest_gpr(DisasContext *ctx, unsigned reg) 40461766fe9SRichard Henderson { 405129e9cc3SRichard Henderson if (reg == 0 || ctx->null_cond.c != TCG_COND_NEVER) { 406aac0f603SRichard Henderson return tcg_temp_new_i64(); 40761766fe9SRichard Henderson } else { 40861766fe9SRichard Henderson return cpu_gr[reg]; 40961766fe9SRichard Henderson } 41061766fe9SRichard Henderson } 41161766fe9SRichard Henderson 4126fd0c7bcSRichard Henderson static void save_or_nullify(DisasContext *ctx, TCGv_i64 dest, TCGv_i64 t) 413129e9cc3SRichard Henderson { 414129e9cc3SRichard Henderson if (ctx->null_cond.c != TCG_COND_NEVER) { 4156fd0c7bcSRichard Henderson tcg_gen_movcond_i64(ctx->null_cond.c, dest, ctx->null_cond.a0, 416129e9cc3SRichard Henderson ctx->null_cond.a1, dest, t); 417129e9cc3SRichard Henderson } else { 4186fd0c7bcSRichard Henderson tcg_gen_mov_i64(dest, t); 419129e9cc3SRichard Henderson } 420129e9cc3SRichard Henderson } 421129e9cc3SRichard Henderson 4226fd0c7bcSRichard Henderson static void save_gpr(DisasContext *ctx, unsigned reg, TCGv_i64 t) 423129e9cc3SRichard Henderson { 424129e9cc3SRichard Henderson if (reg != 0) { 425129e9cc3SRichard Henderson save_or_nullify(ctx, cpu_gr[reg], t); 426129e9cc3SRichard Henderson } 427129e9cc3SRichard Henderson } 428129e9cc3SRichard Henderson 429e03b5686SMarc-André Lureau #if HOST_BIG_ENDIAN 43096d6407fSRichard Henderson # define HI_OFS 0 43196d6407fSRichard Henderson # define LO_OFS 4 43296d6407fSRichard Henderson #else 43396d6407fSRichard Henderson # define HI_OFS 4 43496d6407fSRichard Henderson # define LO_OFS 0 43596d6407fSRichard Henderson #endif 43696d6407fSRichard Henderson 43796d6407fSRichard Henderson static TCGv_i32 load_frw_i32(unsigned rt) 43896d6407fSRichard Henderson { 43996d6407fSRichard Henderson TCGv_i32 ret = tcg_temp_new_i32(); 440ad75a51eSRichard Henderson tcg_gen_ld_i32(ret, tcg_env, 44196d6407fSRichard Henderson offsetof(CPUHPPAState, fr[rt & 31]) 44296d6407fSRichard Henderson + (rt & 32 ? LO_OFS : HI_OFS)); 44396d6407fSRichard Henderson return ret; 44496d6407fSRichard Henderson } 44596d6407fSRichard Henderson 446ebe9383cSRichard Henderson static TCGv_i32 load_frw0_i32(unsigned rt) 447ebe9383cSRichard Henderson { 448ebe9383cSRichard Henderson if (rt == 0) { 4490992a930SRichard Henderson TCGv_i32 ret = tcg_temp_new_i32(); 4500992a930SRichard Henderson tcg_gen_movi_i32(ret, 0); 4510992a930SRichard Henderson return ret; 452ebe9383cSRichard Henderson } else { 453ebe9383cSRichard Henderson return load_frw_i32(rt); 454ebe9383cSRichard Henderson } 455ebe9383cSRichard Henderson } 456ebe9383cSRichard Henderson 457ebe9383cSRichard Henderson static TCGv_i64 load_frw0_i64(unsigned rt) 458ebe9383cSRichard Henderson { 459ebe9383cSRichard Henderson TCGv_i64 ret = tcg_temp_new_i64(); 4600992a930SRichard Henderson if (rt == 0) { 4610992a930SRichard Henderson tcg_gen_movi_i64(ret, 0); 4620992a930SRichard Henderson } else { 463ad75a51eSRichard Henderson tcg_gen_ld32u_i64(ret, tcg_env, 464ebe9383cSRichard Henderson offsetof(CPUHPPAState, fr[rt & 31]) 465ebe9383cSRichard Henderson + (rt & 32 ? LO_OFS : HI_OFS)); 466ebe9383cSRichard Henderson } 4670992a930SRichard Henderson return ret; 468ebe9383cSRichard Henderson } 469ebe9383cSRichard Henderson 47096d6407fSRichard Henderson static void save_frw_i32(unsigned rt, TCGv_i32 val) 47196d6407fSRichard Henderson { 472ad75a51eSRichard Henderson tcg_gen_st_i32(val, tcg_env, 47396d6407fSRichard Henderson offsetof(CPUHPPAState, fr[rt & 31]) 47496d6407fSRichard Henderson + (rt & 32 ? LO_OFS : HI_OFS)); 47596d6407fSRichard Henderson } 47696d6407fSRichard Henderson 47796d6407fSRichard Henderson #undef HI_OFS 47896d6407fSRichard Henderson #undef LO_OFS 47996d6407fSRichard Henderson 48096d6407fSRichard Henderson static TCGv_i64 load_frd(unsigned rt) 48196d6407fSRichard Henderson { 48296d6407fSRichard Henderson TCGv_i64 ret = tcg_temp_new_i64(); 483ad75a51eSRichard Henderson tcg_gen_ld_i64(ret, tcg_env, offsetof(CPUHPPAState, fr[rt])); 48496d6407fSRichard Henderson return ret; 48596d6407fSRichard Henderson } 48696d6407fSRichard Henderson 487ebe9383cSRichard Henderson static TCGv_i64 load_frd0(unsigned rt) 488ebe9383cSRichard Henderson { 489ebe9383cSRichard Henderson if (rt == 0) { 4900992a930SRichard Henderson TCGv_i64 ret = tcg_temp_new_i64(); 4910992a930SRichard Henderson tcg_gen_movi_i64(ret, 0); 4920992a930SRichard Henderson return ret; 493ebe9383cSRichard Henderson } else { 494ebe9383cSRichard Henderson return load_frd(rt); 495ebe9383cSRichard Henderson } 496ebe9383cSRichard Henderson } 497ebe9383cSRichard Henderson 49896d6407fSRichard Henderson static void save_frd(unsigned rt, TCGv_i64 val) 49996d6407fSRichard Henderson { 500ad75a51eSRichard Henderson tcg_gen_st_i64(val, tcg_env, offsetof(CPUHPPAState, fr[rt])); 50196d6407fSRichard Henderson } 50296d6407fSRichard Henderson 50333423472SRichard Henderson static void load_spr(DisasContext *ctx, TCGv_i64 dest, unsigned reg) 50433423472SRichard Henderson { 50533423472SRichard Henderson #ifdef CONFIG_USER_ONLY 50633423472SRichard Henderson tcg_gen_movi_i64(dest, 0); 50733423472SRichard Henderson #else 50833423472SRichard Henderson if (reg < 4) { 50933423472SRichard Henderson tcg_gen_mov_i64(dest, cpu_sr[reg]); 510494737b7SRichard Henderson } else if (ctx->tb_flags & TB_FLAG_SR_SAME) { 511494737b7SRichard Henderson tcg_gen_mov_i64(dest, cpu_srH); 51233423472SRichard Henderson } else { 513ad75a51eSRichard Henderson tcg_gen_ld_i64(dest, tcg_env, offsetof(CPUHPPAState, sr[reg])); 51433423472SRichard Henderson } 51533423472SRichard Henderson #endif 51633423472SRichard Henderson } 51733423472SRichard Henderson 518*d27fe7c3SRichard Henderson /* 519*d27fe7c3SRichard Henderson * Write a value to psw_xb, bearing in mind the known value. 520*d27fe7c3SRichard Henderson * To be used just before exiting the TB, so do not update the known value. 521*d27fe7c3SRichard Henderson */ 522*d27fe7c3SRichard Henderson static void store_psw_xb(DisasContext *ctx, uint32_t xb) 523*d27fe7c3SRichard Henderson { 524*d27fe7c3SRichard Henderson tcg_debug_assert(xb == 0 || xb == PSW_B); 525*d27fe7c3SRichard Henderson if (ctx->psw_xb != xb) { 526*d27fe7c3SRichard Henderson tcg_gen_movi_i32(cpu_psw_xb, xb); 527*d27fe7c3SRichard Henderson } 528*d27fe7c3SRichard Henderson } 529*d27fe7c3SRichard Henderson 530*d27fe7c3SRichard Henderson /* Write a value to psw_xb, and update the known value. */ 531*d27fe7c3SRichard Henderson static void set_psw_xb(DisasContext *ctx, uint32_t xb) 532*d27fe7c3SRichard Henderson { 533*d27fe7c3SRichard Henderson store_psw_xb(ctx, xb); 534*d27fe7c3SRichard Henderson ctx->psw_xb = xb; 535*d27fe7c3SRichard Henderson } 536*d27fe7c3SRichard Henderson 537129e9cc3SRichard Henderson /* Skip over the implementation of an insn that has been nullified. 538129e9cc3SRichard Henderson Use this when the insn is too complex for a conditional move. */ 539129e9cc3SRichard Henderson static void nullify_over(DisasContext *ctx) 540129e9cc3SRichard Henderson { 541129e9cc3SRichard Henderson if (ctx->null_cond.c != TCG_COND_NEVER) { 542129e9cc3SRichard Henderson /* The always condition should have been handled in the main loop. */ 543129e9cc3SRichard Henderson assert(ctx->null_cond.c != TCG_COND_ALWAYS); 544129e9cc3SRichard Henderson 545129e9cc3SRichard Henderson ctx->null_lab = gen_new_label(); 546129e9cc3SRichard Henderson 547129e9cc3SRichard Henderson /* If we're using PSW[N], copy it to a temp because... */ 5486e94937aSRichard Henderson if (ctx->null_cond.a0 == cpu_psw_n) { 549aac0f603SRichard Henderson ctx->null_cond.a0 = tcg_temp_new_i64(); 5506fd0c7bcSRichard Henderson tcg_gen_mov_i64(ctx->null_cond.a0, cpu_psw_n); 551129e9cc3SRichard Henderson } 552129e9cc3SRichard Henderson /* ... we clear it before branching over the implementation, 553129e9cc3SRichard Henderson so that (1) it's clear after nullifying this insn and 554129e9cc3SRichard Henderson (2) if this insn nullifies the next, PSW[N] is valid. */ 555129e9cc3SRichard Henderson if (ctx->psw_n_nonzero) { 556129e9cc3SRichard Henderson ctx->psw_n_nonzero = false; 5576fd0c7bcSRichard Henderson tcg_gen_movi_i64(cpu_psw_n, 0); 558129e9cc3SRichard Henderson } 559129e9cc3SRichard Henderson 5606fd0c7bcSRichard Henderson tcg_gen_brcond_i64(ctx->null_cond.c, ctx->null_cond.a0, 561129e9cc3SRichard Henderson ctx->null_cond.a1, ctx->null_lab); 562e0137378SRichard Henderson ctx->null_cond = cond_make_f(); 563129e9cc3SRichard Henderson } 564129e9cc3SRichard Henderson } 565129e9cc3SRichard Henderson 566129e9cc3SRichard Henderson /* Save the current nullification state to PSW[N]. */ 567129e9cc3SRichard Henderson static void nullify_save(DisasContext *ctx) 568129e9cc3SRichard Henderson { 569129e9cc3SRichard Henderson if (ctx->null_cond.c == TCG_COND_NEVER) { 570129e9cc3SRichard Henderson if (ctx->psw_n_nonzero) { 5716fd0c7bcSRichard Henderson tcg_gen_movi_i64(cpu_psw_n, 0); 572129e9cc3SRichard Henderson } 573129e9cc3SRichard Henderson return; 574129e9cc3SRichard Henderson } 5756e94937aSRichard Henderson if (ctx->null_cond.a0 != cpu_psw_n) { 5766fd0c7bcSRichard Henderson tcg_gen_setcond_i64(ctx->null_cond.c, cpu_psw_n, 577129e9cc3SRichard Henderson ctx->null_cond.a0, ctx->null_cond.a1); 578129e9cc3SRichard Henderson ctx->psw_n_nonzero = true; 579129e9cc3SRichard Henderson } 580e0137378SRichard Henderson ctx->null_cond = cond_make_f(); 581129e9cc3SRichard Henderson } 582129e9cc3SRichard Henderson 583129e9cc3SRichard Henderson /* Set a PSW[N] to X. The intention is that this is used immediately 584129e9cc3SRichard Henderson before a goto_tb/exit_tb, so that there is no fallthru path to other 585129e9cc3SRichard Henderson code within the TB. Therefore we do not update psw_n_nonzero. */ 586129e9cc3SRichard Henderson static void nullify_set(DisasContext *ctx, bool x) 587129e9cc3SRichard Henderson { 588129e9cc3SRichard Henderson if (ctx->psw_n_nonzero || x) { 5896fd0c7bcSRichard Henderson tcg_gen_movi_i64(cpu_psw_n, x); 590129e9cc3SRichard Henderson } 591129e9cc3SRichard Henderson } 592129e9cc3SRichard Henderson 593129e9cc3SRichard Henderson /* Mark the end of an instruction that may have been nullified. 59440f9f908SRichard Henderson This is the pair to nullify_over. Always returns true so that 59540f9f908SRichard Henderson it may be tail-called from a translate function. */ 59631234768SRichard Henderson static bool nullify_end(DisasContext *ctx) 597129e9cc3SRichard Henderson { 598129e9cc3SRichard Henderson TCGLabel *null_lab = ctx->null_lab; 59931234768SRichard Henderson DisasJumpType status = ctx->base.is_jmp; 600129e9cc3SRichard Henderson 601f49b3537SRichard Henderson /* For NEXT, NORETURN, STALE, we can easily continue (or exit). 602f49b3537SRichard Henderson For UPDATED, we cannot update on the nullified path. */ 603f49b3537SRichard Henderson assert(status != DISAS_IAQ_N_UPDATED); 604*d27fe7c3SRichard Henderson /* Taken branches are handled manually. */ 605*d27fe7c3SRichard Henderson assert(!ctx->psw_b_next); 606f49b3537SRichard Henderson 607129e9cc3SRichard Henderson if (likely(null_lab == NULL)) { 608129e9cc3SRichard Henderson /* The current insn wasn't conditional or handled the condition 609129e9cc3SRichard Henderson applied to it without a branch, so the (new) setting of 610129e9cc3SRichard Henderson NULL_COND can be applied directly to the next insn. */ 61131234768SRichard Henderson return true; 612129e9cc3SRichard Henderson } 613129e9cc3SRichard Henderson ctx->null_lab = NULL; 614129e9cc3SRichard Henderson 615129e9cc3SRichard Henderson if (likely(ctx->null_cond.c == TCG_COND_NEVER)) { 616129e9cc3SRichard Henderson /* The next instruction will be unconditional, 617129e9cc3SRichard Henderson and NULL_COND already reflects that. */ 618129e9cc3SRichard Henderson gen_set_label(null_lab); 619129e9cc3SRichard Henderson } else { 620129e9cc3SRichard Henderson /* The insn that we just executed is itself nullifying the next 621129e9cc3SRichard Henderson instruction. Store the condition in the PSW[N] global. 622129e9cc3SRichard Henderson We asserted PSW[N] = 0 in nullify_over, so that after the 623129e9cc3SRichard Henderson label we have the proper value in place. */ 624129e9cc3SRichard Henderson nullify_save(ctx); 625129e9cc3SRichard Henderson gen_set_label(null_lab); 626129e9cc3SRichard Henderson ctx->null_cond = cond_make_n(); 627129e9cc3SRichard Henderson } 628869051eaSRichard Henderson if (status == DISAS_NORETURN) { 62931234768SRichard Henderson ctx->base.is_jmp = DISAS_NEXT; 630129e9cc3SRichard Henderson } 63131234768SRichard Henderson return true; 632129e9cc3SRichard Henderson } 633129e9cc3SRichard Henderson 634bc921866SRichard Henderson static bool iaqe_variable(const DisasIAQE *e) 635bc921866SRichard Henderson { 636bc921866SRichard Henderson return e->base || e->space; 637bc921866SRichard Henderson } 638bc921866SRichard Henderson 639bc921866SRichard Henderson static DisasIAQE iaqe_incr(const DisasIAQE *e, int64_t disp) 640bc921866SRichard Henderson { 641bc921866SRichard Henderson return (DisasIAQE){ 642bc921866SRichard Henderson .space = e->space, 643bc921866SRichard Henderson .base = e->base, 644bc921866SRichard Henderson .disp = e->disp + disp, 645bc921866SRichard Henderson }; 646bc921866SRichard Henderson } 647bc921866SRichard Henderson 648bc921866SRichard Henderson static DisasIAQE iaqe_branchi(DisasContext *ctx, int64_t disp) 649bc921866SRichard Henderson { 650bc921866SRichard Henderson return (DisasIAQE){ 651bc921866SRichard Henderson .space = ctx->iaq_b.space, 652bc921866SRichard Henderson .disp = ctx->iaq_f.disp + 8 + disp, 653bc921866SRichard Henderson }; 654bc921866SRichard Henderson } 655bc921866SRichard Henderson 656bc921866SRichard Henderson static DisasIAQE iaqe_next_absv(DisasContext *ctx, TCGv_i64 var) 657bc921866SRichard Henderson { 658bc921866SRichard Henderson return (DisasIAQE){ 659bc921866SRichard Henderson .space = ctx->iaq_b.space, 660bc921866SRichard Henderson .base = var, 661bc921866SRichard Henderson }; 662bc921866SRichard Henderson } 663bc921866SRichard Henderson 6646fd0c7bcSRichard Henderson static void copy_iaoq_entry(DisasContext *ctx, TCGv_i64 dest, 665bc921866SRichard Henderson const DisasIAQE *src) 66661766fe9SRichard Henderson { 667bc921866SRichard Henderson if (src->base == NULL) { 668081a0ed1SRichard Henderson tcg_gen_movi_i64(dest, ctx->iaoq_first + src->disp); 66961766fe9SRichard Henderson } else { 670bc921866SRichard Henderson tcg_gen_addi_i64(dest, src->base, src->disp); 67161766fe9SRichard Henderson } 67261766fe9SRichard Henderson } 67361766fe9SRichard Henderson 674bc921866SRichard Henderson static void install_iaq_entries(DisasContext *ctx, const DisasIAQE *f, 675bc921866SRichard Henderson const DisasIAQE *b) 67685e6cda0SRichard Henderson { 677bc921866SRichard Henderson DisasIAQE b_next; 67885e6cda0SRichard Henderson 679bc921866SRichard Henderson if (b == NULL) { 680bc921866SRichard Henderson b_next = iaqe_incr(f, 4); 681bc921866SRichard Henderson b = &b_next; 68285e6cda0SRichard Henderson } 683bc921866SRichard Henderson copy_iaoq_entry(ctx, cpu_iaoq_f, f); 684bc921866SRichard Henderson copy_iaoq_entry(ctx, cpu_iaoq_b, b); 685bc921866SRichard Henderson if (f->space) { 686bc921866SRichard Henderson tcg_gen_mov_i64(cpu_iasq_f, f->space); 687588deedaSRichard Henderson } 688bc921866SRichard Henderson if (b->space || f->space) { 689bc921866SRichard Henderson tcg_gen_mov_i64(cpu_iasq_b, b->space ? : f->space); 690588deedaSRichard Henderson } 69185e6cda0SRichard Henderson } 69285e6cda0SRichard Henderson 69343541db0SRichard Henderson static void install_link(DisasContext *ctx, unsigned link, bool with_sr0) 69443541db0SRichard Henderson { 69543541db0SRichard Henderson tcg_debug_assert(ctx->null_cond.c == TCG_COND_NEVER); 69643541db0SRichard Henderson if (!link) { 69743541db0SRichard Henderson return; 69843541db0SRichard Henderson } 6990d89cb7cSRichard Henderson DisasIAQE next = iaqe_incr(&ctx->iaq_b, 4); 7000d89cb7cSRichard Henderson copy_iaoq_entry(ctx, cpu_gr[link], &next); 70143541db0SRichard Henderson #ifndef CONFIG_USER_ONLY 70243541db0SRichard Henderson if (with_sr0) { 70343541db0SRichard Henderson tcg_gen_mov_i64(cpu_sr[0], cpu_iasq_b); 70443541db0SRichard Henderson } 70543541db0SRichard Henderson #endif 70643541db0SRichard Henderson } 70743541db0SRichard Henderson 70861766fe9SRichard Henderson static void gen_excp_1(int exception) 70961766fe9SRichard Henderson { 710ad75a51eSRichard Henderson gen_helper_excp(tcg_env, tcg_constant_i32(exception)); 71161766fe9SRichard Henderson } 71261766fe9SRichard Henderson 71331234768SRichard Henderson static void gen_excp(DisasContext *ctx, int exception) 71461766fe9SRichard Henderson { 715bc921866SRichard Henderson install_iaq_entries(ctx, &ctx->iaq_f, &ctx->iaq_b); 716129e9cc3SRichard Henderson nullify_save(ctx); 71761766fe9SRichard Henderson gen_excp_1(exception); 71831234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 71961766fe9SRichard Henderson } 72061766fe9SRichard Henderson 72180603007SRichard Henderson static DisasDelayException *delay_excp(DisasContext *ctx, uint8_t excp) 72280603007SRichard Henderson { 72380603007SRichard Henderson DisasDelayException *e = tcg_malloc(sizeof(DisasDelayException)); 72480603007SRichard Henderson 72580603007SRichard Henderson memset(e, 0, sizeof(*e)); 72680603007SRichard Henderson e->next = ctx->delay_excp_list; 72780603007SRichard Henderson ctx->delay_excp_list = e; 72880603007SRichard Henderson 72980603007SRichard Henderson e->lab = gen_new_label(); 73080603007SRichard Henderson e->insn = ctx->insn; 73180603007SRichard Henderson e->set_iir = true; 73280603007SRichard Henderson e->set_n = ctx->psw_n_nonzero ? 0 : -1; 73380603007SRichard Henderson e->excp = excp; 73480603007SRichard Henderson e->iaq_f = ctx->iaq_f; 73580603007SRichard Henderson e->iaq_b = ctx->iaq_b; 73680603007SRichard Henderson 73780603007SRichard Henderson return e; 73880603007SRichard Henderson } 73980603007SRichard Henderson 74031234768SRichard Henderson static bool gen_excp_iir(DisasContext *ctx, int exc) 7411a19da0dSRichard Henderson { 74280603007SRichard Henderson if (ctx->null_cond.c == TCG_COND_NEVER) { 7436fd0c7bcSRichard Henderson tcg_gen_st_i64(tcg_constant_i64(ctx->insn), 744ad75a51eSRichard Henderson tcg_env, offsetof(CPUHPPAState, cr[CR_IIR])); 74531234768SRichard Henderson gen_excp(ctx, exc); 74680603007SRichard Henderson } else { 74780603007SRichard Henderson DisasDelayException *e = delay_excp(ctx, exc); 74880603007SRichard Henderson tcg_gen_brcond_i64(tcg_invert_cond(ctx->null_cond.c), 74980603007SRichard Henderson ctx->null_cond.a0, ctx->null_cond.a1, e->lab); 75080603007SRichard Henderson ctx->null_cond = cond_make_f(); 75180603007SRichard Henderson } 75280603007SRichard Henderson return true; 7531a19da0dSRichard Henderson } 7541a19da0dSRichard Henderson 75531234768SRichard Henderson static bool gen_illegal(DisasContext *ctx) 75661766fe9SRichard Henderson { 75731234768SRichard Henderson return gen_excp_iir(ctx, EXCP_ILL); 75861766fe9SRichard Henderson } 75961766fe9SRichard Henderson 76040f9f908SRichard Henderson #ifdef CONFIG_USER_ONLY 76140f9f908SRichard Henderson #define CHECK_MOST_PRIVILEGED(EXCP) \ 76240f9f908SRichard Henderson return gen_excp_iir(ctx, EXCP) 76340f9f908SRichard Henderson #else 764e1b5a5edSRichard Henderson #define CHECK_MOST_PRIVILEGED(EXCP) \ 765e1b5a5edSRichard Henderson do { \ 766e1b5a5edSRichard Henderson if (ctx->privilege != 0) { \ 76731234768SRichard Henderson return gen_excp_iir(ctx, EXCP); \ 768e1b5a5edSRichard Henderson } \ 769e1b5a5edSRichard Henderson } while (0) 77040f9f908SRichard Henderson #endif 771e1b5a5edSRichard Henderson 772bc921866SRichard Henderson static bool use_goto_tb(DisasContext *ctx, const DisasIAQE *f, 773bc921866SRichard Henderson const DisasIAQE *b) 77461766fe9SRichard Henderson { 775bc921866SRichard Henderson return (!iaqe_variable(f) && 776bc921866SRichard Henderson (b == NULL || !iaqe_variable(b)) && 7770d89cb7cSRichard Henderson translator_use_goto_tb(&ctx->base, ctx->iaoq_first + f->disp)); 77861766fe9SRichard Henderson } 77961766fe9SRichard Henderson 780129e9cc3SRichard Henderson /* If the next insn is to be nullified, and it's on the same page, 781129e9cc3SRichard Henderson and we're not attempting to set a breakpoint on it, then we can 782129e9cc3SRichard Henderson totally skip the nullified insn. This avoids creating and 783129e9cc3SRichard Henderson executing a TB that merely branches to the next TB. */ 784129e9cc3SRichard Henderson static bool use_nullify_skip(DisasContext *ctx) 785129e9cc3SRichard Henderson { 786f9b11bc2SRichard Henderson return (!(tb_cflags(ctx->base.tb) & CF_BP_PAGE) 787bc921866SRichard Henderson && !iaqe_variable(&ctx->iaq_b) 7880d89cb7cSRichard Henderson && (((ctx->iaoq_first + ctx->iaq_b.disp) ^ ctx->iaoq_first) 7890d89cb7cSRichard Henderson & TARGET_PAGE_MASK) == 0); 790129e9cc3SRichard Henderson } 791129e9cc3SRichard Henderson 79261766fe9SRichard Henderson static void gen_goto_tb(DisasContext *ctx, int which, 793bc921866SRichard Henderson const DisasIAQE *f, const DisasIAQE *b) 79461766fe9SRichard Henderson { 7959dfcd243SRichard Henderson install_iaq_entries(ctx, f, b); 796bc921866SRichard Henderson if (use_goto_tb(ctx, f, b)) { 79761766fe9SRichard Henderson tcg_gen_goto_tb(which); 79807ea28b4SRichard Henderson tcg_gen_exit_tb(ctx->base.tb, which); 79961766fe9SRichard Henderson } else { 8007f11636dSEmilio G. Cota tcg_gen_lookup_and_goto_ptr(); 80161766fe9SRichard Henderson } 80261766fe9SRichard Henderson } 80361766fe9SRichard Henderson 804b47a4a02SSven Schnelle static bool cond_need_sv(int c) 805b47a4a02SSven Schnelle { 806b47a4a02SSven Schnelle return c == 2 || c == 3 || c == 6; 807b47a4a02SSven Schnelle } 808b47a4a02SSven Schnelle 809b47a4a02SSven Schnelle static bool cond_need_cb(int c) 810b47a4a02SSven Schnelle { 811b47a4a02SSven Schnelle return c == 4 || c == 5; 812b47a4a02SSven Schnelle } 813b47a4a02SSven Schnelle 814b47a4a02SSven Schnelle /* 815b47a4a02SSven Schnelle * Compute conditional for arithmetic. See Page 5-3, Table 5-1, of 816b47a4a02SSven Schnelle * the Parisc 1.1 Architecture Reference Manual for details. 817b47a4a02SSven Schnelle */ 818b2167459SRichard Henderson 819a751eb31SRichard Henderson static DisasCond do_cond(DisasContext *ctx, unsigned cf, bool d, 820fe2d066aSRichard Henderson TCGv_i64 res, TCGv_i64 uv, TCGv_i64 sv) 821b2167459SRichard Henderson { 822d6d46be1SRichard Henderson TCGCond sign_cond, zero_cond; 823d6d46be1SRichard Henderson uint64_t sign_imm, zero_imm; 824b2167459SRichard Henderson DisasCond cond; 8256fd0c7bcSRichard Henderson TCGv_i64 tmp; 826b2167459SRichard Henderson 827d6d46be1SRichard Henderson if (d) { 828d6d46be1SRichard Henderson /* 64-bit condition. */ 829d6d46be1SRichard Henderson sign_imm = 0; 830d6d46be1SRichard Henderson sign_cond = TCG_COND_LT; 831d6d46be1SRichard Henderson zero_imm = 0; 832d6d46be1SRichard Henderson zero_cond = TCG_COND_EQ; 833d6d46be1SRichard Henderson } else { 834d6d46be1SRichard Henderson /* 32-bit condition. */ 835d6d46be1SRichard Henderson sign_imm = 1ull << 31; 836d6d46be1SRichard Henderson sign_cond = TCG_COND_TSTNE; 837d6d46be1SRichard Henderson zero_imm = UINT32_MAX; 838d6d46be1SRichard Henderson zero_cond = TCG_COND_TSTEQ; 839d6d46be1SRichard Henderson } 840d6d46be1SRichard Henderson 841b2167459SRichard Henderson switch (cf >> 1) { 842b47a4a02SSven Schnelle case 0: /* Never / TR (0 / 1) */ 843b2167459SRichard Henderson cond = cond_make_f(); 844b2167459SRichard Henderson break; 845b2167459SRichard Henderson case 1: /* = / <> (Z / !Z) */ 846d6d46be1SRichard Henderson cond = cond_make_vi(zero_cond, res, zero_imm); 847b2167459SRichard Henderson break; 848b47a4a02SSven Schnelle case 2: /* < / >= (N ^ V / !(N ^ V) */ 849aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 8506fd0c7bcSRichard Henderson tcg_gen_xor_i64(tmp, res, sv); 851d6d46be1SRichard Henderson cond = cond_make_ti(sign_cond, tmp, sign_imm); 852b2167459SRichard Henderson break; 853b47a4a02SSven Schnelle case 3: /* <= / > (N ^ V) | Z / !((N ^ V) | Z) */ 854b47a4a02SSven Schnelle /* 855b47a4a02SSven Schnelle * Simplify: 856b47a4a02SSven Schnelle * (N ^ V) | Z 857b47a4a02SSven Schnelle * ((res < 0) ^ (sv < 0)) | !res 858b47a4a02SSven Schnelle * ((res ^ sv) < 0) | !res 859d6d46be1SRichard Henderson * ((res ^ sv) < 0 ? 1 : !res) 860d6d46be1SRichard Henderson * !((res ^ sv) < 0 ? 0 : res) 861b47a4a02SSven Schnelle */ 862aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 863d6d46be1SRichard Henderson tcg_gen_xor_i64(tmp, res, sv); 864d6d46be1SRichard Henderson tcg_gen_movcond_i64(sign_cond, tmp, 865d6d46be1SRichard Henderson tmp, tcg_constant_i64(sign_imm), 866d6d46be1SRichard Henderson ctx->zero, res); 867d6d46be1SRichard Henderson cond = cond_make_ti(zero_cond, tmp, zero_imm); 868b2167459SRichard Henderson break; 869fe2d066aSRichard Henderson case 4: /* NUV / UV (!UV / UV) */ 8704c42fd0dSRichard Henderson cond = cond_make_vi(TCG_COND_EQ, uv, 0); 871b2167459SRichard Henderson break; 872fe2d066aSRichard Henderson case 5: /* ZNV / VNZ (!UV | Z / UV & !Z) */ 873aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 874fe2d066aSRichard Henderson tcg_gen_movcond_i64(TCG_COND_EQ, tmp, uv, ctx->zero, ctx->zero, res); 875d6d46be1SRichard Henderson cond = cond_make_ti(zero_cond, tmp, zero_imm); 876b2167459SRichard Henderson break; 877b2167459SRichard Henderson case 6: /* SV / NSV (V / !V) */ 878d6d46be1SRichard Henderson cond = cond_make_vi(sign_cond, sv, sign_imm); 879b2167459SRichard Henderson break; 880b2167459SRichard Henderson case 7: /* OD / EV */ 881d6d46be1SRichard Henderson cond = cond_make_vi(TCG_COND_TSTNE, res, 1); 882b2167459SRichard Henderson break; 883b2167459SRichard Henderson default: 884b2167459SRichard Henderson g_assert_not_reached(); 885b2167459SRichard Henderson } 886b2167459SRichard Henderson if (cf & 1) { 887b2167459SRichard Henderson cond.c = tcg_invert_cond(cond.c); 888b2167459SRichard Henderson } 889b2167459SRichard Henderson 890b2167459SRichard Henderson return cond; 891b2167459SRichard Henderson } 892b2167459SRichard Henderson 893b2167459SRichard Henderson /* Similar, but for the special case of subtraction without borrow, we 894b2167459SRichard Henderson can use the inputs directly. This can allow other computation to be 895b2167459SRichard Henderson deleted as unused. */ 896b2167459SRichard Henderson 8974fe9533aSRichard Henderson static DisasCond do_sub_cond(DisasContext *ctx, unsigned cf, bool d, 8986fd0c7bcSRichard Henderson TCGv_i64 res, TCGv_i64 in1, 8996fd0c7bcSRichard Henderson TCGv_i64 in2, TCGv_i64 sv) 900b2167459SRichard Henderson { 9014fe9533aSRichard Henderson TCGCond tc; 9024fe9533aSRichard Henderson bool ext_uns; 903b2167459SRichard Henderson 904b2167459SRichard Henderson switch (cf >> 1) { 905b2167459SRichard Henderson case 1: /* = / <> */ 9064fe9533aSRichard Henderson tc = TCG_COND_EQ; 9074fe9533aSRichard Henderson ext_uns = true; 908b2167459SRichard Henderson break; 909b2167459SRichard Henderson case 2: /* < / >= */ 9104fe9533aSRichard Henderson tc = TCG_COND_LT; 9114fe9533aSRichard Henderson ext_uns = false; 912b2167459SRichard Henderson break; 913b2167459SRichard Henderson case 3: /* <= / > */ 9144fe9533aSRichard Henderson tc = TCG_COND_LE; 9154fe9533aSRichard Henderson ext_uns = false; 916b2167459SRichard Henderson break; 917b2167459SRichard Henderson case 4: /* << / >>= */ 9184fe9533aSRichard Henderson tc = TCG_COND_LTU; 9194fe9533aSRichard Henderson ext_uns = true; 920b2167459SRichard Henderson break; 921b2167459SRichard Henderson case 5: /* <<= / >> */ 9224fe9533aSRichard Henderson tc = TCG_COND_LEU; 9234fe9533aSRichard Henderson ext_uns = true; 924b2167459SRichard Henderson break; 925b2167459SRichard Henderson default: 926a751eb31SRichard Henderson return do_cond(ctx, cf, d, res, NULL, sv); 927b2167459SRichard Henderson } 928b2167459SRichard Henderson 9294fe9533aSRichard Henderson if (cf & 1) { 9304fe9533aSRichard Henderson tc = tcg_invert_cond(tc); 9314fe9533aSRichard Henderson } 93282d0c831SRichard Henderson if (!d) { 933aac0f603SRichard Henderson TCGv_i64 t1 = tcg_temp_new_i64(); 934aac0f603SRichard Henderson TCGv_i64 t2 = tcg_temp_new_i64(); 9354fe9533aSRichard Henderson 9364fe9533aSRichard Henderson if (ext_uns) { 9376fd0c7bcSRichard Henderson tcg_gen_ext32u_i64(t1, in1); 9386fd0c7bcSRichard Henderson tcg_gen_ext32u_i64(t2, in2); 9394fe9533aSRichard Henderson } else { 9406fd0c7bcSRichard Henderson tcg_gen_ext32s_i64(t1, in1); 9416fd0c7bcSRichard Henderson tcg_gen_ext32s_i64(t2, in2); 9424fe9533aSRichard Henderson } 9434c42fd0dSRichard Henderson return cond_make_tt(tc, t1, t2); 9444fe9533aSRichard Henderson } 9454c42fd0dSRichard Henderson return cond_make_vv(tc, in1, in2); 946b2167459SRichard Henderson } 947b2167459SRichard Henderson 948df0232feSRichard Henderson /* 949df0232feSRichard Henderson * Similar, but for logicals, where the carry and overflow bits are not 950df0232feSRichard Henderson * computed, and use of them is undefined. 951df0232feSRichard Henderson * 952df0232feSRichard Henderson * Undefined or not, hardware does not trap. It seems reasonable to 953df0232feSRichard Henderson * assume hardware treats cases c={4,5,6} as if C=0 & V=0, since that's 954df0232feSRichard Henderson * how cases c={2,3} are treated. 955df0232feSRichard Henderson */ 956b2167459SRichard Henderson 957b5af8423SRichard Henderson static DisasCond do_log_cond(DisasContext *ctx, unsigned cf, bool d, 9586fd0c7bcSRichard Henderson TCGv_i64 res) 959b2167459SRichard Henderson { 960b5af8423SRichard Henderson TCGCond tc; 961fbe65c64SRichard Henderson uint64_t imm; 962a751eb31SRichard Henderson 963fbe65c64SRichard Henderson switch (cf >> 1) { 964fbe65c64SRichard Henderson case 0: /* never / always */ 965fbe65c64SRichard Henderson case 4: /* undef, C */ 966fbe65c64SRichard Henderson case 5: /* undef, C & !Z */ 967fbe65c64SRichard Henderson case 6: /* undef, V */ 968fbe65c64SRichard Henderson return cf & 1 ? cond_make_t() : cond_make_f(); 969fbe65c64SRichard Henderson case 1: /* == / <> */ 970fbe65c64SRichard Henderson tc = d ? TCG_COND_EQ : TCG_COND_TSTEQ; 971fbe65c64SRichard Henderson imm = d ? 0 : UINT32_MAX; 972b5af8423SRichard Henderson break; 973fbe65c64SRichard Henderson case 2: /* < / >= */ 974fbe65c64SRichard Henderson tc = d ? TCG_COND_LT : TCG_COND_TSTNE; 975fbe65c64SRichard Henderson imm = d ? 0 : 1ull << 31; 976b5af8423SRichard Henderson break; 977fbe65c64SRichard Henderson case 3: /* <= / > */ 978fbe65c64SRichard Henderson tc = cf & 1 ? TCG_COND_GT : TCG_COND_LE; 97982d0c831SRichard Henderson if (!d) { 980aac0f603SRichard Henderson TCGv_i64 tmp = tcg_temp_new_i64(); 9816fd0c7bcSRichard Henderson tcg_gen_ext32s_i64(tmp, res); 9824c42fd0dSRichard Henderson return cond_make_ti(tc, tmp, 0); 983b5af8423SRichard Henderson } 9844c42fd0dSRichard Henderson return cond_make_vi(tc, res, 0); 985fbe65c64SRichard Henderson case 7: /* OD / EV */ 986fbe65c64SRichard Henderson tc = TCG_COND_TSTNE; 987fbe65c64SRichard Henderson imm = 1; 988fbe65c64SRichard Henderson break; 989fbe65c64SRichard Henderson default: 990fbe65c64SRichard Henderson g_assert_not_reached(); 991fbe65c64SRichard Henderson } 992fbe65c64SRichard Henderson if (cf & 1) { 993fbe65c64SRichard Henderson tc = tcg_invert_cond(tc); 994fbe65c64SRichard Henderson } 995fbe65c64SRichard Henderson return cond_make_vi(tc, res, imm); 996b2167459SRichard Henderson } 997b2167459SRichard Henderson 99898cd9ca7SRichard Henderson /* Similar, but for shift/extract/deposit conditions. */ 99998cd9ca7SRichard Henderson 10004fa52edfSRichard Henderson static DisasCond do_sed_cond(DisasContext *ctx, unsigned orig, bool d, 10016fd0c7bcSRichard Henderson TCGv_i64 res) 100298cd9ca7SRichard Henderson { 100398cd9ca7SRichard Henderson unsigned c, f; 100498cd9ca7SRichard Henderson 100598cd9ca7SRichard Henderson /* Convert the compressed condition codes to standard. 100698cd9ca7SRichard Henderson 0-2 are the same as logicals (nv,<,<=), while 3 is OD. 100798cd9ca7SRichard Henderson 4-7 are the reverse of 0-3. */ 100898cd9ca7SRichard Henderson c = orig & 3; 100998cd9ca7SRichard Henderson if (c == 3) { 101098cd9ca7SRichard Henderson c = 7; 101198cd9ca7SRichard Henderson } 101298cd9ca7SRichard Henderson f = (orig & 4) / 4; 101398cd9ca7SRichard Henderson 1014b5af8423SRichard Henderson return do_log_cond(ctx, c * 2 + f, d, res); 101598cd9ca7SRichard Henderson } 101698cd9ca7SRichard Henderson 101746bb3d46SRichard Henderson /* Similar, but for unit zero conditions. */ 101846bb3d46SRichard Henderson static DisasCond do_unit_zero_cond(unsigned cf, bool d, TCGv_i64 res) 1019b2167459SRichard Henderson { 102046bb3d46SRichard Henderson TCGv_i64 tmp; 1021c53e401eSRichard Henderson uint64_t d_repl = d ? 0x0000000100000001ull : 1; 102246bb3d46SRichard Henderson uint64_t ones = 0, sgns = 0; 1023b2167459SRichard Henderson 1024b2167459SRichard Henderson switch (cf >> 1) { 1025578b8132SSven Schnelle case 1: /* SBW / NBW */ 1026578b8132SSven Schnelle if (d) { 102746bb3d46SRichard Henderson ones = d_repl; 102846bb3d46SRichard Henderson sgns = d_repl << 31; 1029578b8132SSven Schnelle } 1030578b8132SSven Schnelle break; 1031b2167459SRichard Henderson case 2: /* SBZ / NBZ */ 103246bb3d46SRichard Henderson ones = d_repl * 0x01010101u; 103346bb3d46SRichard Henderson sgns = ones << 7; 103446bb3d46SRichard Henderson break; 103546bb3d46SRichard Henderson case 3: /* SHZ / NHZ */ 103646bb3d46SRichard Henderson ones = d_repl * 0x00010001u; 103746bb3d46SRichard Henderson sgns = ones << 15; 103846bb3d46SRichard Henderson break; 103946bb3d46SRichard Henderson } 104046bb3d46SRichard Henderson if (ones == 0) { 104146bb3d46SRichard Henderson /* Undefined, or 0/1 (never/always). */ 104246bb3d46SRichard Henderson return cf & 1 ? cond_make_t() : cond_make_f(); 104346bb3d46SRichard Henderson } 104446bb3d46SRichard Henderson 104546bb3d46SRichard Henderson /* 104646bb3d46SRichard Henderson * See hasless(v,1) from 1047b2167459SRichard Henderson * https://graphics.stanford.edu/~seander/bithacks.html#ZeroInWord 1048b2167459SRichard Henderson */ 1049aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 105046bb3d46SRichard Henderson tcg_gen_subi_i64(tmp, res, ones); 10516fd0c7bcSRichard Henderson tcg_gen_andc_i64(tmp, tmp, res); 1052b2167459SRichard Henderson 105325f97be7SRichard Henderson return cond_make_ti(cf & 1 ? TCG_COND_TSTEQ : TCG_COND_TSTNE, tmp, sgns); 1054b2167459SRichard Henderson } 1055b2167459SRichard Henderson 10566fd0c7bcSRichard Henderson static TCGv_i64 get_carry(DisasContext *ctx, bool d, 10576fd0c7bcSRichard Henderson TCGv_i64 cb, TCGv_i64 cb_msb) 105872ca8753SRichard Henderson { 105982d0c831SRichard Henderson if (!d) { 1060aac0f603SRichard Henderson TCGv_i64 t = tcg_temp_new_i64(); 10616fd0c7bcSRichard Henderson tcg_gen_extract_i64(t, cb, 32, 1); 106272ca8753SRichard Henderson return t; 106372ca8753SRichard Henderson } 106472ca8753SRichard Henderson return cb_msb; 106572ca8753SRichard Henderson } 106672ca8753SRichard Henderson 10676fd0c7bcSRichard Henderson static TCGv_i64 get_psw_carry(DisasContext *ctx, bool d) 106872ca8753SRichard Henderson { 106972ca8753SRichard Henderson return get_carry(ctx, d, cpu_psw_cb, cpu_psw_cb_msb); 107072ca8753SRichard Henderson } 107172ca8753SRichard Henderson 1072b2167459SRichard Henderson /* Compute signed overflow for addition. */ 10736fd0c7bcSRichard Henderson static TCGv_i64 do_add_sv(DisasContext *ctx, TCGv_i64 res, 1074f8f5986eSRichard Henderson TCGv_i64 in1, TCGv_i64 in2, 1075f8f5986eSRichard Henderson TCGv_i64 orig_in1, int shift, bool d) 1076b2167459SRichard Henderson { 1077aac0f603SRichard Henderson TCGv_i64 sv = tcg_temp_new_i64(); 1078aac0f603SRichard Henderson TCGv_i64 tmp = tcg_temp_new_i64(); 1079b2167459SRichard Henderson 10806fd0c7bcSRichard Henderson tcg_gen_xor_i64(sv, res, in1); 10816fd0c7bcSRichard Henderson tcg_gen_xor_i64(tmp, in1, in2); 10826fd0c7bcSRichard Henderson tcg_gen_andc_i64(sv, sv, tmp); 1083b2167459SRichard Henderson 1084f8f5986eSRichard Henderson switch (shift) { 1085f8f5986eSRichard Henderson case 0: 1086f8f5986eSRichard Henderson break; 1087f8f5986eSRichard Henderson case 1: 1088f8f5986eSRichard Henderson /* Shift left by one and compare the sign. */ 1089f8f5986eSRichard Henderson tcg_gen_add_i64(tmp, orig_in1, orig_in1); 1090f8f5986eSRichard Henderson tcg_gen_xor_i64(tmp, tmp, orig_in1); 1091f8f5986eSRichard Henderson /* Incorporate into the overflow. */ 1092f8f5986eSRichard Henderson tcg_gen_or_i64(sv, sv, tmp); 1093f8f5986eSRichard Henderson break; 1094f8f5986eSRichard Henderson default: 1095f8f5986eSRichard Henderson { 1096f8f5986eSRichard Henderson int sign_bit = d ? 63 : 31; 1097f8f5986eSRichard Henderson 1098f8f5986eSRichard Henderson /* Compare the sign against all lower bits. */ 1099f8f5986eSRichard Henderson tcg_gen_sextract_i64(tmp, orig_in1, sign_bit, 1); 1100f8f5986eSRichard Henderson tcg_gen_xor_i64(tmp, tmp, orig_in1); 1101f8f5986eSRichard Henderson /* 1102f8f5986eSRichard Henderson * If one of the bits shifting into or through the sign 1103f8f5986eSRichard Henderson * differs, then we have overflow. 1104f8f5986eSRichard Henderson */ 1105f8f5986eSRichard Henderson tcg_gen_extract_i64(tmp, tmp, sign_bit - shift, shift); 1106f8f5986eSRichard Henderson tcg_gen_movcond_i64(TCG_COND_NE, sv, tmp, ctx->zero, 1107f8f5986eSRichard Henderson tcg_constant_i64(-1), sv); 1108f8f5986eSRichard Henderson } 1109f8f5986eSRichard Henderson } 1110b2167459SRichard Henderson return sv; 1111b2167459SRichard Henderson } 1112b2167459SRichard Henderson 1113f8f5986eSRichard Henderson /* Compute unsigned overflow for addition. */ 1114f8f5986eSRichard Henderson static TCGv_i64 do_add_uv(DisasContext *ctx, TCGv_i64 cb, TCGv_i64 cb_msb, 1115f8f5986eSRichard Henderson TCGv_i64 in1, int shift, bool d) 1116f8f5986eSRichard Henderson { 1117f8f5986eSRichard Henderson if (shift == 0) { 1118f8f5986eSRichard Henderson return get_carry(ctx, d, cb, cb_msb); 1119f8f5986eSRichard Henderson } else { 1120f8f5986eSRichard Henderson TCGv_i64 tmp = tcg_temp_new_i64(); 1121f8f5986eSRichard Henderson tcg_gen_extract_i64(tmp, in1, (d ? 63 : 31) - shift, shift); 1122f8f5986eSRichard Henderson tcg_gen_or_i64(tmp, tmp, get_carry(ctx, d, cb, cb_msb)); 1123f8f5986eSRichard Henderson return tmp; 1124f8f5986eSRichard Henderson } 1125f8f5986eSRichard Henderson } 1126f8f5986eSRichard Henderson 1127b2167459SRichard Henderson /* Compute signed overflow for subtraction. */ 11286fd0c7bcSRichard Henderson static TCGv_i64 do_sub_sv(DisasContext *ctx, TCGv_i64 res, 11296fd0c7bcSRichard Henderson TCGv_i64 in1, TCGv_i64 in2) 1130b2167459SRichard Henderson { 1131aac0f603SRichard Henderson TCGv_i64 sv = tcg_temp_new_i64(); 1132aac0f603SRichard Henderson TCGv_i64 tmp = tcg_temp_new_i64(); 1133b2167459SRichard Henderson 11346fd0c7bcSRichard Henderson tcg_gen_xor_i64(sv, res, in1); 11356fd0c7bcSRichard Henderson tcg_gen_xor_i64(tmp, in1, in2); 11366fd0c7bcSRichard Henderson tcg_gen_and_i64(sv, sv, tmp); 1137b2167459SRichard Henderson 1138b2167459SRichard Henderson return sv; 1139b2167459SRichard Henderson } 1140b2167459SRichard Henderson 1141269ca0a9SRichard Henderson static void gen_tc(DisasContext *ctx, DisasCond *cond) 1142269ca0a9SRichard Henderson { 1143269ca0a9SRichard Henderson DisasDelayException *e; 1144269ca0a9SRichard Henderson 1145269ca0a9SRichard Henderson switch (cond->c) { 1146269ca0a9SRichard Henderson case TCG_COND_NEVER: 1147269ca0a9SRichard Henderson break; 1148269ca0a9SRichard Henderson case TCG_COND_ALWAYS: 1149269ca0a9SRichard Henderson gen_excp_iir(ctx, EXCP_COND); 1150269ca0a9SRichard Henderson break; 1151269ca0a9SRichard Henderson default: 1152269ca0a9SRichard Henderson e = delay_excp(ctx, EXCP_COND); 1153269ca0a9SRichard Henderson tcg_gen_brcond_i64(cond->c, cond->a0, cond->a1, e->lab); 1154269ca0a9SRichard Henderson /* In the non-trap path, the condition is known false. */ 1155269ca0a9SRichard Henderson *cond = cond_make_f(); 1156269ca0a9SRichard Henderson break; 1157269ca0a9SRichard Henderson } 1158269ca0a9SRichard Henderson } 1159269ca0a9SRichard Henderson 1160a0ea4becSRichard Henderson static void gen_tsv(DisasContext *ctx, TCGv_i64 *sv, bool d) 1161a0ea4becSRichard Henderson { 1162a0ea4becSRichard Henderson DisasCond cond = do_cond(ctx, /* SV */ 12, d, NULL, NULL, *sv); 1163a0ea4becSRichard Henderson DisasDelayException *e = delay_excp(ctx, EXCP_OVERFLOW); 1164a0ea4becSRichard Henderson 1165a0ea4becSRichard Henderson tcg_gen_brcond_i64(cond.c, cond.a0, cond.a1, e->lab); 1166a0ea4becSRichard Henderson 1167a0ea4becSRichard Henderson /* In the non-trap path, V is known zero. */ 1168a0ea4becSRichard Henderson *sv = tcg_constant_i64(0); 1169a0ea4becSRichard Henderson } 1170a0ea4becSRichard Henderson 1171f8f5986eSRichard Henderson static void do_add(DisasContext *ctx, unsigned rt, TCGv_i64 orig_in1, 11726fd0c7bcSRichard Henderson TCGv_i64 in2, unsigned shift, bool is_l, 1173faf97ba1SRichard Henderson bool is_tsv, bool is_tc, bool is_c, unsigned cf, bool d) 1174b2167459SRichard Henderson { 1175f8f5986eSRichard Henderson TCGv_i64 dest, cb, cb_msb, in1, uv, sv, tmp; 1176b2167459SRichard Henderson unsigned c = cf >> 1; 1177b2167459SRichard Henderson DisasCond cond; 1178b2167459SRichard Henderson 1179aac0f603SRichard Henderson dest = tcg_temp_new_i64(); 1180f764718dSRichard Henderson cb = NULL; 1181f764718dSRichard Henderson cb_msb = NULL; 1182b2167459SRichard Henderson 1183f8f5986eSRichard Henderson in1 = orig_in1; 1184b2167459SRichard Henderson if (shift) { 1185aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 11866fd0c7bcSRichard Henderson tcg_gen_shli_i64(tmp, in1, shift); 1187b2167459SRichard Henderson in1 = tmp; 1188b2167459SRichard Henderson } 1189b2167459SRichard Henderson 1190b47a4a02SSven Schnelle if (!is_l || cond_need_cb(c)) { 1191aac0f603SRichard Henderson cb_msb = tcg_temp_new_i64(); 1192aac0f603SRichard Henderson cb = tcg_temp_new_i64(); 1193bdcccc17SRichard Henderson 1194a4db4a78SRichard Henderson tcg_gen_add2_i64(dest, cb_msb, in1, ctx->zero, in2, ctx->zero); 1195b2167459SRichard Henderson if (is_c) { 11966fd0c7bcSRichard Henderson tcg_gen_add2_i64(dest, cb_msb, dest, cb_msb, 1197a4db4a78SRichard Henderson get_psw_carry(ctx, d), ctx->zero); 1198b2167459SRichard Henderson } 11996fd0c7bcSRichard Henderson tcg_gen_xor_i64(cb, in1, in2); 12006fd0c7bcSRichard Henderson tcg_gen_xor_i64(cb, cb, dest); 1201b2167459SRichard Henderson } else { 12026fd0c7bcSRichard Henderson tcg_gen_add_i64(dest, in1, in2); 1203b2167459SRichard Henderson if (is_c) { 12046fd0c7bcSRichard Henderson tcg_gen_add_i64(dest, dest, get_psw_carry(ctx, d)); 1205b2167459SRichard Henderson } 1206b2167459SRichard Henderson } 1207b2167459SRichard Henderson 1208b2167459SRichard Henderson /* Compute signed overflow if required. */ 1209f764718dSRichard Henderson sv = NULL; 1210b47a4a02SSven Schnelle if (is_tsv || cond_need_sv(c)) { 1211f8f5986eSRichard Henderson sv = do_add_sv(ctx, dest, in1, in2, orig_in1, shift, d); 1212b2167459SRichard Henderson if (is_tsv) { 1213a0ea4becSRichard Henderson gen_tsv(ctx, &sv, d); 1214b2167459SRichard Henderson } 1215b2167459SRichard Henderson } 1216b2167459SRichard Henderson 1217f8f5986eSRichard Henderson /* Compute unsigned overflow if required. */ 1218f8f5986eSRichard Henderson uv = NULL; 1219f8f5986eSRichard Henderson if (cond_need_cb(c)) { 1220f8f5986eSRichard Henderson uv = do_add_uv(ctx, cb, cb_msb, orig_in1, shift, d); 1221f8f5986eSRichard Henderson } 1222f8f5986eSRichard Henderson 1223b2167459SRichard Henderson /* Emit any conditional trap before any writeback. */ 1224f8f5986eSRichard Henderson cond = do_cond(ctx, cf, d, dest, uv, sv); 1225b2167459SRichard Henderson if (is_tc) { 1226269ca0a9SRichard Henderson gen_tc(ctx, &cond); 1227b2167459SRichard Henderson } 1228b2167459SRichard Henderson 1229b2167459SRichard Henderson /* Write back the result. */ 1230b2167459SRichard Henderson if (!is_l) { 1231b2167459SRichard Henderson save_or_nullify(ctx, cpu_psw_cb, cb); 1232b2167459SRichard Henderson save_or_nullify(ctx, cpu_psw_cb_msb, cb_msb); 1233b2167459SRichard Henderson } 1234b2167459SRichard Henderson save_gpr(ctx, rt, dest); 1235b2167459SRichard Henderson 1236b2167459SRichard Henderson /* Install the new nullification. */ 1237b2167459SRichard Henderson ctx->null_cond = cond; 1238b2167459SRichard Henderson } 1239b2167459SRichard Henderson 1240faf97ba1SRichard Henderson static bool do_add_reg(DisasContext *ctx, arg_rrr_cf_d_sh *a, 12410c982a28SRichard Henderson bool is_l, bool is_tsv, bool is_tc, bool is_c) 12420c982a28SRichard Henderson { 12436fd0c7bcSRichard Henderson TCGv_i64 tcg_r1, tcg_r2; 12440c982a28SRichard Henderson 1245269ca0a9SRichard Henderson if (unlikely(is_tc && a->cf == 1)) { 1246269ca0a9SRichard Henderson /* Unconditional trap on condition. */ 1247269ca0a9SRichard Henderson return gen_excp_iir(ctx, EXCP_COND); 1248269ca0a9SRichard Henderson } 12490c982a28SRichard Henderson if (a->cf) { 12500c982a28SRichard Henderson nullify_over(ctx); 12510c982a28SRichard Henderson } 12520c982a28SRichard Henderson tcg_r1 = load_gpr(ctx, a->r1); 12530c982a28SRichard Henderson tcg_r2 = load_gpr(ctx, a->r2); 1254faf97ba1SRichard Henderson do_add(ctx, a->t, tcg_r1, tcg_r2, a->sh, is_l, 1255faf97ba1SRichard Henderson is_tsv, is_tc, is_c, a->cf, a->d); 12560c982a28SRichard Henderson return nullify_end(ctx); 12570c982a28SRichard Henderson } 12580c982a28SRichard Henderson 12590588e061SRichard Henderson static bool do_add_imm(DisasContext *ctx, arg_rri_cf *a, 12600588e061SRichard Henderson bool is_tsv, bool is_tc) 12610588e061SRichard Henderson { 12626fd0c7bcSRichard Henderson TCGv_i64 tcg_im, tcg_r2; 12630588e061SRichard Henderson 1264269ca0a9SRichard Henderson if (unlikely(is_tc && a->cf == 1)) { 1265269ca0a9SRichard Henderson /* Unconditional trap on condition. */ 1266269ca0a9SRichard Henderson return gen_excp_iir(ctx, EXCP_COND); 1267269ca0a9SRichard Henderson } 12680588e061SRichard Henderson if (a->cf) { 12690588e061SRichard Henderson nullify_over(ctx); 12700588e061SRichard Henderson } 12716fd0c7bcSRichard Henderson tcg_im = tcg_constant_i64(a->i); 12720588e061SRichard Henderson tcg_r2 = load_gpr(ctx, a->r); 1273faf97ba1SRichard Henderson /* All ADDI conditions are 32-bit. */ 1274faf97ba1SRichard Henderson do_add(ctx, a->t, tcg_im, tcg_r2, 0, 0, is_tsv, is_tc, 0, a->cf, false); 12750588e061SRichard Henderson return nullify_end(ctx); 12760588e061SRichard Henderson } 12770588e061SRichard Henderson 12786fd0c7bcSRichard Henderson static void do_sub(DisasContext *ctx, unsigned rt, TCGv_i64 in1, 12796fd0c7bcSRichard Henderson TCGv_i64 in2, bool is_tsv, bool is_b, 128063c427c6SRichard Henderson bool is_tc, unsigned cf, bool d) 1281b2167459SRichard Henderson { 1282269ca0a9SRichard Henderson TCGv_i64 dest, sv, cb, cb_msb; 1283b2167459SRichard Henderson unsigned c = cf >> 1; 1284b2167459SRichard Henderson DisasCond cond; 1285b2167459SRichard Henderson 1286aac0f603SRichard Henderson dest = tcg_temp_new_i64(); 1287aac0f603SRichard Henderson cb = tcg_temp_new_i64(); 1288aac0f603SRichard Henderson cb_msb = tcg_temp_new_i64(); 1289b2167459SRichard Henderson 1290b2167459SRichard Henderson if (is_b) { 1291b2167459SRichard Henderson /* DEST,C = IN1 + ~IN2 + C. */ 12926fd0c7bcSRichard Henderson tcg_gen_not_i64(cb, in2); 1293a4db4a78SRichard Henderson tcg_gen_add2_i64(dest, cb_msb, in1, ctx->zero, 1294a4db4a78SRichard Henderson get_psw_carry(ctx, d), ctx->zero); 1295a4db4a78SRichard Henderson tcg_gen_add2_i64(dest, cb_msb, dest, cb_msb, cb, ctx->zero); 12966fd0c7bcSRichard Henderson tcg_gen_xor_i64(cb, cb, in1); 12976fd0c7bcSRichard Henderson tcg_gen_xor_i64(cb, cb, dest); 1298b2167459SRichard Henderson } else { 1299bdcccc17SRichard Henderson /* 1300bdcccc17SRichard Henderson * DEST,C = IN1 + ~IN2 + 1. We can produce the same result in fewer 1301bdcccc17SRichard Henderson * operations by seeding the high word with 1 and subtracting. 1302bdcccc17SRichard Henderson */ 13036fd0c7bcSRichard Henderson TCGv_i64 one = tcg_constant_i64(1); 1304a4db4a78SRichard Henderson tcg_gen_sub2_i64(dest, cb_msb, in1, one, in2, ctx->zero); 13056fd0c7bcSRichard Henderson tcg_gen_eqv_i64(cb, in1, in2); 13066fd0c7bcSRichard Henderson tcg_gen_xor_i64(cb, cb, dest); 1307b2167459SRichard Henderson } 1308b2167459SRichard Henderson 1309b2167459SRichard Henderson /* Compute signed overflow if required. */ 1310f764718dSRichard Henderson sv = NULL; 1311b47a4a02SSven Schnelle if (is_tsv || cond_need_sv(c)) { 1312b2167459SRichard Henderson sv = do_sub_sv(ctx, dest, in1, in2); 1313b2167459SRichard Henderson if (is_tsv) { 1314a0ea4becSRichard Henderson gen_tsv(ctx, &sv, d); 1315b2167459SRichard Henderson } 1316b2167459SRichard Henderson } 1317b2167459SRichard Henderson 1318b2167459SRichard Henderson /* Compute the condition. We cannot use the special case for borrow. */ 1319b2167459SRichard Henderson if (!is_b) { 13204fe9533aSRichard Henderson cond = do_sub_cond(ctx, cf, d, dest, in1, in2, sv); 1321b2167459SRichard Henderson } else { 1322a751eb31SRichard Henderson cond = do_cond(ctx, cf, d, dest, get_carry(ctx, d, cb, cb_msb), sv); 1323b2167459SRichard Henderson } 1324b2167459SRichard Henderson 1325b2167459SRichard Henderson /* Emit any conditional trap before any writeback. */ 1326b2167459SRichard Henderson if (is_tc) { 1327269ca0a9SRichard Henderson gen_tc(ctx, &cond); 1328b2167459SRichard Henderson } 1329b2167459SRichard Henderson 1330b2167459SRichard Henderson /* Write back the result. */ 1331b2167459SRichard Henderson save_or_nullify(ctx, cpu_psw_cb, cb); 1332b2167459SRichard Henderson save_or_nullify(ctx, cpu_psw_cb_msb, cb_msb); 1333b2167459SRichard Henderson save_gpr(ctx, rt, dest); 1334b2167459SRichard Henderson 1335b2167459SRichard Henderson /* Install the new nullification. */ 1336b2167459SRichard Henderson ctx->null_cond = cond; 1337b2167459SRichard Henderson } 1338b2167459SRichard Henderson 133963c427c6SRichard Henderson static bool do_sub_reg(DisasContext *ctx, arg_rrr_cf_d *a, 13400c982a28SRichard Henderson bool is_tsv, bool is_b, bool is_tc) 13410c982a28SRichard Henderson { 13426fd0c7bcSRichard Henderson TCGv_i64 tcg_r1, tcg_r2; 13430c982a28SRichard Henderson 13440c982a28SRichard Henderson if (a->cf) { 13450c982a28SRichard Henderson nullify_over(ctx); 13460c982a28SRichard Henderson } 13470c982a28SRichard Henderson tcg_r1 = load_gpr(ctx, a->r1); 13480c982a28SRichard Henderson tcg_r2 = load_gpr(ctx, a->r2); 134963c427c6SRichard Henderson do_sub(ctx, a->t, tcg_r1, tcg_r2, is_tsv, is_b, is_tc, a->cf, a->d); 13500c982a28SRichard Henderson return nullify_end(ctx); 13510c982a28SRichard Henderson } 13520c982a28SRichard Henderson 13530588e061SRichard Henderson static bool do_sub_imm(DisasContext *ctx, arg_rri_cf *a, bool is_tsv) 13540588e061SRichard Henderson { 13556fd0c7bcSRichard Henderson TCGv_i64 tcg_im, tcg_r2; 13560588e061SRichard Henderson 13570588e061SRichard Henderson if (a->cf) { 13580588e061SRichard Henderson nullify_over(ctx); 13590588e061SRichard Henderson } 13606fd0c7bcSRichard Henderson tcg_im = tcg_constant_i64(a->i); 13610588e061SRichard Henderson tcg_r2 = load_gpr(ctx, a->r); 136263c427c6SRichard Henderson /* All SUBI conditions are 32-bit. */ 136363c427c6SRichard Henderson do_sub(ctx, a->t, tcg_im, tcg_r2, is_tsv, 0, 0, a->cf, false); 13640588e061SRichard Henderson return nullify_end(ctx); 13650588e061SRichard Henderson } 13660588e061SRichard Henderson 13676fd0c7bcSRichard Henderson static void do_cmpclr(DisasContext *ctx, unsigned rt, TCGv_i64 in1, 13686fd0c7bcSRichard Henderson TCGv_i64 in2, unsigned cf, bool d) 1369b2167459SRichard Henderson { 13706fd0c7bcSRichard Henderson TCGv_i64 dest, sv; 1371b2167459SRichard Henderson DisasCond cond; 1372b2167459SRichard Henderson 1373aac0f603SRichard Henderson dest = tcg_temp_new_i64(); 13746fd0c7bcSRichard Henderson tcg_gen_sub_i64(dest, in1, in2); 1375b2167459SRichard Henderson 1376b2167459SRichard Henderson /* Compute signed overflow if required. */ 1377f764718dSRichard Henderson sv = NULL; 1378b47a4a02SSven Schnelle if (cond_need_sv(cf >> 1)) { 1379b2167459SRichard Henderson sv = do_sub_sv(ctx, dest, in1, in2); 1380b2167459SRichard Henderson } 1381b2167459SRichard Henderson 1382b2167459SRichard Henderson /* Form the condition for the compare. */ 13834fe9533aSRichard Henderson cond = do_sub_cond(ctx, cf, d, dest, in1, in2, sv); 1384b2167459SRichard Henderson 1385b2167459SRichard Henderson /* Clear. */ 13866fd0c7bcSRichard Henderson tcg_gen_movi_i64(dest, 0); 1387b2167459SRichard Henderson save_gpr(ctx, rt, dest); 1388b2167459SRichard Henderson 1389b2167459SRichard Henderson /* Install the new nullification. */ 1390b2167459SRichard Henderson ctx->null_cond = cond; 1391b2167459SRichard Henderson } 1392b2167459SRichard Henderson 13936fd0c7bcSRichard Henderson static void do_log(DisasContext *ctx, unsigned rt, TCGv_i64 in1, 13946fd0c7bcSRichard Henderson TCGv_i64 in2, unsigned cf, bool d, 13956fd0c7bcSRichard Henderson void (*fn)(TCGv_i64, TCGv_i64, TCGv_i64)) 1396b2167459SRichard Henderson { 13976fd0c7bcSRichard Henderson TCGv_i64 dest = dest_gpr(ctx, rt); 1398b2167459SRichard Henderson 1399b2167459SRichard Henderson /* Perform the operation, and writeback. */ 1400b2167459SRichard Henderson fn(dest, in1, in2); 1401b2167459SRichard Henderson save_gpr(ctx, rt, dest); 1402b2167459SRichard Henderson 1403b2167459SRichard Henderson /* Install the new nullification. */ 1404b5af8423SRichard Henderson ctx->null_cond = do_log_cond(ctx, cf, d, dest); 1405b2167459SRichard Henderson } 1406b2167459SRichard Henderson 1407fa8e3bedSRichard Henderson static bool do_log_reg(DisasContext *ctx, arg_rrr_cf_d *a, 14086fd0c7bcSRichard Henderson void (*fn)(TCGv_i64, TCGv_i64, TCGv_i64)) 14090c982a28SRichard Henderson { 14106fd0c7bcSRichard Henderson TCGv_i64 tcg_r1, tcg_r2; 14110c982a28SRichard Henderson 14120c982a28SRichard Henderson if (a->cf) { 14130c982a28SRichard Henderson nullify_over(ctx); 14140c982a28SRichard Henderson } 14150c982a28SRichard Henderson tcg_r1 = load_gpr(ctx, a->r1); 14160c982a28SRichard Henderson tcg_r2 = load_gpr(ctx, a->r2); 1417fa8e3bedSRichard Henderson do_log(ctx, a->t, tcg_r1, tcg_r2, a->cf, a->d, fn); 14180c982a28SRichard Henderson return nullify_end(ctx); 14190c982a28SRichard Henderson } 14200c982a28SRichard Henderson 142146bb3d46SRichard Henderson static void do_unit_addsub(DisasContext *ctx, unsigned rt, TCGv_i64 in1, 142246bb3d46SRichard Henderson TCGv_i64 in2, unsigned cf, bool d, 142346bb3d46SRichard Henderson bool is_tc, bool is_add) 1424b2167459SRichard Henderson { 142546bb3d46SRichard Henderson TCGv_i64 dest = tcg_temp_new_i64(); 142646bb3d46SRichard Henderson uint64_t test_cb = 0; 1427b2167459SRichard Henderson DisasCond cond; 1428b2167459SRichard Henderson 142946bb3d46SRichard Henderson /* Select which carry-out bits to test. */ 143046bb3d46SRichard Henderson switch (cf >> 1) { 143146bb3d46SRichard Henderson case 4: /* NDC / SDC -- 4-bit carries */ 143246bb3d46SRichard Henderson test_cb = dup_const(MO_8, 0x88); 143346bb3d46SRichard Henderson break; 143446bb3d46SRichard Henderson case 5: /* NWC / SWC -- 32-bit carries */ 143546bb3d46SRichard Henderson if (d) { 143646bb3d46SRichard Henderson test_cb = dup_const(MO_32, INT32_MIN); 1437b2167459SRichard Henderson } else { 143846bb3d46SRichard Henderson cf &= 1; /* undefined -- map to never/always */ 143946bb3d46SRichard Henderson } 144046bb3d46SRichard Henderson break; 144146bb3d46SRichard Henderson case 6: /* NBC / SBC -- 8-bit carries */ 144246bb3d46SRichard Henderson test_cb = dup_const(MO_8, INT8_MIN); 144346bb3d46SRichard Henderson break; 144446bb3d46SRichard Henderson case 7: /* NHC / SHC -- 16-bit carries */ 144546bb3d46SRichard Henderson test_cb = dup_const(MO_16, INT16_MIN); 144646bb3d46SRichard Henderson break; 144746bb3d46SRichard Henderson } 144846bb3d46SRichard Henderson if (!d) { 144946bb3d46SRichard Henderson test_cb = (uint32_t)test_cb; 145046bb3d46SRichard Henderson } 1451b2167459SRichard Henderson 145246bb3d46SRichard Henderson if (!test_cb) { 145346bb3d46SRichard Henderson /* No need to compute carries if we don't need to test them. */ 145446bb3d46SRichard Henderson if (is_add) { 145546bb3d46SRichard Henderson tcg_gen_add_i64(dest, in1, in2); 145646bb3d46SRichard Henderson } else { 145746bb3d46SRichard Henderson tcg_gen_sub_i64(dest, in1, in2); 145846bb3d46SRichard Henderson } 145946bb3d46SRichard Henderson cond = do_unit_zero_cond(cf, d, dest); 146046bb3d46SRichard Henderson } else { 146146bb3d46SRichard Henderson TCGv_i64 cb = tcg_temp_new_i64(); 146246bb3d46SRichard Henderson 146346bb3d46SRichard Henderson if (d) { 146446bb3d46SRichard Henderson TCGv_i64 cb_msb = tcg_temp_new_i64(); 146546bb3d46SRichard Henderson if (is_add) { 146646bb3d46SRichard Henderson tcg_gen_add2_i64(dest, cb_msb, in1, ctx->zero, in2, ctx->zero); 146746bb3d46SRichard Henderson tcg_gen_xor_i64(cb, in1, in2); 146846bb3d46SRichard Henderson } else { 146946bb3d46SRichard Henderson /* See do_sub, !is_b. */ 147046bb3d46SRichard Henderson TCGv_i64 one = tcg_constant_i64(1); 147146bb3d46SRichard Henderson tcg_gen_sub2_i64(dest, cb_msb, in1, one, in2, ctx->zero); 147246bb3d46SRichard Henderson tcg_gen_eqv_i64(cb, in1, in2); 147346bb3d46SRichard Henderson } 147446bb3d46SRichard Henderson tcg_gen_xor_i64(cb, cb, dest); 147546bb3d46SRichard Henderson tcg_gen_extract2_i64(cb, cb, cb_msb, 1); 147646bb3d46SRichard Henderson } else { 147746bb3d46SRichard Henderson if (is_add) { 147846bb3d46SRichard Henderson tcg_gen_add_i64(dest, in1, in2); 147946bb3d46SRichard Henderson tcg_gen_xor_i64(cb, in1, in2); 148046bb3d46SRichard Henderson } else { 148146bb3d46SRichard Henderson tcg_gen_sub_i64(dest, in1, in2); 148246bb3d46SRichard Henderson tcg_gen_eqv_i64(cb, in1, in2); 148346bb3d46SRichard Henderson } 148446bb3d46SRichard Henderson tcg_gen_xor_i64(cb, cb, dest); 148546bb3d46SRichard Henderson tcg_gen_shri_i64(cb, cb, 1); 148646bb3d46SRichard Henderson } 148746bb3d46SRichard Henderson 14883289ea0eSRichard Henderson cond = cond_make_ti(cf & 1 ? TCG_COND_TSTEQ : TCG_COND_TSTNE, 14893289ea0eSRichard Henderson cb, test_cb); 149046bb3d46SRichard Henderson } 1491b2167459SRichard Henderson 1492b2167459SRichard Henderson if (is_tc) { 1493269ca0a9SRichard Henderson gen_tc(ctx, &cond); 1494b2167459SRichard Henderson } 1495b2167459SRichard Henderson save_gpr(ctx, rt, dest); 1496b2167459SRichard Henderson 1497b2167459SRichard Henderson ctx->null_cond = cond; 1498b2167459SRichard Henderson } 1499b2167459SRichard Henderson 150086f8d05fSRichard Henderson #ifndef CONFIG_USER_ONLY 15018d6ae7fbSRichard Henderson /* The "normal" usage is SP >= 0, wherein SP == 0 selects the space 15028d6ae7fbSRichard Henderson from the top 2 bits of the base register. There are a few system 15038d6ae7fbSRichard Henderson instructions that have a 3-bit space specifier, for which SR0 is 15048d6ae7fbSRichard Henderson not special. To handle this, pass ~SP. */ 15056fd0c7bcSRichard Henderson static TCGv_i64 space_select(DisasContext *ctx, int sp, TCGv_i64 base) 150686f8d05fSRichard Henderson { 150786f8d05fSRichard Henderson TCGv_ptr ptr; 15086fd0c7bcSRichard Henderson TCGv_i64 tmp; 150986f8d05fSRichard Henderson TCGv_i64 spc; 151086f8d05fSRichard Henderson 151186f8d05fSRichard Henderson if (sp != 0) { 15128d6ae7fbSRichard Henderson if (sp < 0) { 15138d6ae7fbSRichard Henderson sp = ~sp; 15148d6ae7fbSRichard Henderson } 15156fd0c7bcSRichard Henderson spc = tcg_temp_new_i64(); 15168d6ae7fbSRichard Henderson load_spr(ctx, spc, sp); 15178d6ae7fbSRichard Henderson return spc; 151886f8d05fSRichard Henderson } 1519494737b7SRichard Henderson if (ctx->tb_flags & TB_FLAG_SR_SAME) { 1520494737b7SRichard Henderson return cpu_srH; 1521494737b7SRichard Henderson } 152286f8d05fSRichard Henderson 152386f8d05fSRichard Henderson ptr = tcg_temp_new_ptr(); 1524aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 15256fd0c7bcSRichard Henderson spc = tcg_temp_new_i64(); 152686f8d05fSRichard Henderson 1527698240d1SRichard Henderson /* Extract top 2 bits of the address, shift left 3 for uint64_t index. */ 15286fd0c7bcSRichard Henderson tcg_gen_shri_i64(tmp, base, (ctx->tb_flags & PSW_W ? 64 : 32) - 5); 15296fd0c7bcSRichard Henderson tcg_gen_andi_i64(tmp, tmp, 030); 15306fd0c7bcSRichard Henderson tcg_gen_trunc_i64_ptr(ptr, tmp); 153186f8d05fSRichard Henderson 1532ad75a51eSRichard Henderson tcg_gen_add_ptr(ptr, ptr, tcg_env); 153386f8d05fSRichard Henderson tcg_gen_ld_i64(spc, ptr, offsetof(CPUHPPAState, sr[4])); 153486f8d05fSRichard Henderson 153586f8d05fSRichard Henderson return spc; 153686f8d05fSRichard Henderson } 153786f8d05fSRichard Henderson #endif 153886f8d05fSRichard Henderson 15396fd0c7bcSRichard Henderson static void form_gva(DisasContext *ctx, TCGv_i64 *pgva, TCGv_i64 *pofs, 1540c53e401eSRichard Henderson unsigned rb, unsigned rx, int scale, int64_t disp, 154186f8d05fSRichard Henderson unsigned sp, int modify, bool is_phys) 154286f8d05fSRichard Henderson { 15436fd0c7bcSRichard Henderson TCGv_i64 base = load_gpr(ctx, rb); 15446fd0c7bcSRichard Henderson TCGv_i64 ofs; 15456fd0c7bcSRichard Henderson TCGv_i64 addr; 154686f8d05fSRichard Henderson 1547f5b5c857SRichard Henderson set_insn_breg(ctx, rb); 1548f5b5c857SRichard Henderson 154986f8d05fSRichard Henderson /* Note that RX is mutually exclusive with DISP. */ 155086f8d05fSRichard Henderson if (rx) { 1551aac0f603SRichard Henderson ofs = tcg_temp_new_i64(); 15526fd0c7bcSRichard Henderson tcg_gen_shli_i64(ofs, cpu_gr[rx], scale); 15536fd0c7bcSRichard Henderson tcg_gen_add_i64(ofs, ofs, base); 155486f8d05fSRichard Henderson } else if (disp || modify) { 1555aac0f603SRichard Henderson ofs = tcg_temp_new_i64(); 15566fd0c7bcSRichard Henderson tcg_gen_addi_i64(ofs, base, disp); 155786f8d05fSRichard Henderson } else { 155886f8d05fSRichard Henderson ofs = base; 155986f8d05fSRichard Henderson } 156086f8d05fSRichard Henderson 156186f8d05fSRichard Henderson *pofs = ofs; 15626fd0c7bcSRichard Henderson *pgva = addr = tcg_temp_new_i64(); 15637d50b696SSven Schnelle tcg_gen_andi_i64(addr, modify <= 0 ? ofs : base, 15647d50b696SSven Schnelle gva_offset_mask(ctx->tb_flags)); 1565698240d1SRichard Henderson #ifndef CONFIG_USER_ONLY 156686f8d05fSRichard Henderson if (!is_phys) { 1567d265360fSRichard Henderson tcg_gen_or_i64(addr, addr, space_select(ctx, sp, base)); 156886f8d05fSRichard Henderson } 156986f8d05fSRichard Henderson #endif 157086f8d05fSRichard Henderson } 157186f8d05fSRichard Henderson 157296d6407fSRichard Henderson /* Emit a memory load. The modify parameter should be 157396d6407fSRichard Henderson * < 0 for pre-modify, 157496d6407fSRichard Henderson * > 0 for post-modify, 157596d6407fSRichard Henderson * = 0 for no base register update. 157696d6407fSRichard Henderson */ 157796d6407fSRichard Henderson static void do_load_32(DisasContext *ctx, TCGv_i32 dest, unsigned rb, 1578c53e401eSRichard Henderson unsigned rx, int scale, int64_t disp, 157914776ab5STony Nguyen unsigned sp, int modify, MemOp mop) 158096d6407fSRichard Henderson { 15816fd0c7bcSRichard Henderson TCGv_i64 ofs; 15826fd0c7bcSRichard Henderson TCGv_i64 addr; 158396d6407fSRichard Henderson 158496d6407fSRichard Henderson /* Caller uses nullify_over/nullify_end. */ 158596d6407fSRichard Henderson assert(ctx->null_cond.c == TCG_COND_NEVER); 158696d6407fSRichard Henderson 158786f8d05fSRichard Henderson form_gva(ctx, &addr, &ofs, rb, rx, scale, disp, sp, modify, 158817fe594cSRichard Henderson MMU_DISABLED(ctx)); 1589c1f55d97SRichard Henderson tcg_gen_qemu_ld_i32(dest, addr, ctx->mmu_idx, mop | UNALIGN(ctx)); 159086f8d05fSRichard Henderson if (modify) { 159186f8d05fSRichard Henderson save_gpr(ctx, rb, ofs); 159296d6407fSRichard Henderson } 159396d6407fSRichard Henderson } 159496d6407fSRichard Henderson 159596d6407fSRichard Henderson static void do_load_64(DisasContext *ctx, TCGv_i64 dest, unsigned rb, 1596c53e401eSRichard Henderson unsigned rx, int scale, int64_t disp, 159714776ab5STony Nguyen unsigned sp, int modify, MemOp mop) 159896d6407fSRichard Henderson { 15996fd0c7bcSRichard Henderson TCGv_i64 ofs; 16006fd0c7bcSRichard Henderson TCGv_i64 addr; 160196d6407fSRichard Henderson 160296d6407fSRichard Henderson /* Caller uses nullify_over/nullify_end. */ 160396d6407fSRichard Henderson assert(ctx->null_cond.c == TCG_COND_NEVER); 160496d6407fSRichard Henderson 160586f8d05fSRichard Henderson form_gva(ctx, &addr, &ofs, rb, rx, scale, disp, sp, modify, 160617fe594cSRichard Henderson MMU_DISABLED(ctx)); 1607217d1a5eSRichard Henderson tcg_gen_qemu_ld_i64(dest, addr, ctx->mmu_idx, mop | UNALIGN(ctx)); 160886f8d05fSRichard Henderson if (modify) { 160986f8d05fSRichard Henderson save_gpr(ctx, rb, ofs); 161096d6407fSRichard Henderson } 161196d6407fSRichard Henderson } 161296d6407fSRichard Henderson 161396d6407fSRichard Henderson static void do_store_32(DisasContext *ctx, TCGv_i32 src, unsigned rb, 1614c53e401eSRichard Henderson unsigned rx, int scale, int64_t disp, 161514776ab5STony Nguyen unsigned sp, int modify, MemOp mop) 161696d6407fSRichard Henderson { 16176fd0c7bcSRichard Henderson TCGv_i64 ofs; 16186fd0c7bcSRichard Henderson TCGv_i64 addr; 161996d6407fSRichard Henderson 162096d6407fSRichard Henderson /* Caller uses nullify_over/nullify_end. */ 162196d6407fSRichard Henderson assert(ctx->null_cond.c == TCG_COND_NEVER); 162296d6407fSRichard Henderson 162386f8d05fSRichard Henderson form_gva(ctx, &addr, &ofs, rb, rx, scale, disp, sp, modify, 162417fe594cSRichard Henderson MMU_DISABLED(ctx)); 1625217d1a5eSRichard Henderson tcg_gen_qemu_st_i32(src, addr, ctx->mmu_idx, mop | UNALIGN(ctx)); 162686f8d05fSRichard Henderson if (modify) { 162786f8d05fSRichard Henderson save_gpr(ctx, rb, ofs); 162896d6407fSRichard Henderson } 162996d6407fSRichard Henderson } 163096d6407fSRichard Henderson 163196d6407fSRichard Henderson static void do_store_64(DisasContext *ctx, TCGv_i64 src, unsigned rb, 1632c53e401eSRichard Henderson unsigned rx, int scale, int64_t disp, 163314776ab5STony Nguyen unsigned sp, int modify, MemOp mop) 163496d6407fSRichard Henderson { 16356fd0c7bcSRichard Henderson TCGv_i64 ofs; 16366fd0c7bcSRichard Henderson TCGv_i64 addr; 163796d6407fSRichard Henderson 163896d6407fSRichard Henderson /* Caller uses nullify_over/nullify_end. */ 163996d6407fSRichard Henderson assert(ctx->null_cond.c == TCG_COND_NEVER); 164096d6407fSRichard Henderson 164186f8d05fSRichard Henderson form_gva(ctx, &addr, &ofs, rb, rx, scale, disp, sp, modify, 164217fe594cSRichard Henderson MMU_DISABLED(ctx)); 1643217d1a5eSRichard Henderson tcg_gen_qemu_st_i64(src, addr, ctx->mmu_idx, mop | UNALIGN(ctx)); 164486f8d05fSRichard Henderson if (modify) { 164586f8d05fSRichard Henderson save_gpr(ctx, rb, ofs); 164696d6407fSRichard Henderson } 164796d6407fSRichard Henderson } 164896d6407fSRichard Henderson 16491cd012a5SRichard Henderson static bool do_load(DisasContext *ctx, unsigned rt, unsigned rb, 1650c53e401eSRichard Henderson unsigned rx, int scale, int64_t disp, 165114776ab5STony Nguyen unsigned sp, int modify, MemOp mop) 165296d6407fSRichard Henderson { 16536fd0c7bcSRichard Henderson TCGv_i64 dest; 165496d6407fSRichard Henderson 165596d6407fSRichard Henderson nullify_over(ctx); 165696d6407fSRichard Henderson 165796d6407fSRichard Henderson if (modify == 0) { 165896d6407fSRichard Henderson /* No base register update. */ 165996d6407fSRichard Henderson dest = dest_gpr(ctx, rt); 166096d6407fSRichard Henderson } else { 166196d6407fSRichard Henderson /* Make sure if RT == RB, we see the result of the load. */ 1662aac0f603SRichard Henderson dest = tcg_temp_new_i64(); 166396d6407fSRichard Henderson } 16646fd0c7bcSRichard Henderson do_load_64(ctx, dest, rb, rx, scale, disp, sp, modify, mop); 166596d6407fSRichard Henderson save_gpr(ctx, rt, dest); 166696d6407fSRichard Henderson 16671cd012a5SRichard Henderson return nullify_end(ctx); 166896d6407fSRichard Henderson } 166996d6407fSRichard Henderson 1670740038d7SRichard Henderson static bool do_floadw(DisasContext *ctx, unsigned rt, unsigned rb, 1671c53e401eSRichard Henderson unsigned rx, int scale, int64_t disp, 167286f8d05fSRichard Henderson unsigned sp, int modify) 167396d6407fSRichard Henderson { 167496d6407fSRichard Henderson TCGv_i32 tmp; 167596d6407fSRichard Henderson 167696d6407fSRichard Henderson nullify_over(ctx); 167796d6407fSRichard Henderson 167896d6407fSRichard Henderson tmp = tcg_temp_new_i32(); 167986f8d05fSRichard Henderson do_load_32(ctx, tmp, rb, rx, scale, disp, sp, modify, MO_TEUL); 168096d6407fSRichard Henderson save_frw_i32(rt, tmp); 168196d6407fSRichard Henderson 168296d6407fSRichard Henderson if (rt == 0) { 1683ad75a51eSRichard Henderson gen_helper_loaded_fr0(tcg_env); 168496d6407fSRichard Henderson } 168596d6407fSRichard Henderson 1686740038d7SRichard Henderson return nullify_end(ctx); 168796d6407fSRichard Henderson } 168896d6407fSRichard Henderson 1689740038d7SRichard Henderson static bool trans_fldw(DisasContext *ctx, arg_ldst *a) 1690740038d7SRichard Henderson { 1691740038d7SRichard Henderson return do_floadw(ctx, a->t, a->b, a->x, a->scale ? 2 : 0, 1692740038d7SRichard Henderson a->disp, a->sp, a->m); 1693740038d7SRichard Henderson } 1694740038d7SRichard Henderson 1695740038d7SRichard Henderson static bool do_floadd(DisasContext *ctx, unsigned rt, unsigned rb, 1696c53e401eSRichard Henderson unsigned rx, int scale, int64_t disp, 169786f8d05fSRichard Henderson unsigned sp, int modify) 169896d6407fSRichard Henderson { 169996d6407fSRichard Henderson TCGv_i64 tmp; 170096d6407fSRichard Henderson 170196d6407fSRichard Henderson nullify_over(ctx); 170296d6407fSRichard Henderson 170396d6407fSRichard Henderson tmp = tcg_temp_new_i64(); 1704fc313c64SFrédéric Pétrot do_load_64(ctx, tmp, rb, rx, scale, disp, sp, modify, MO_TEUQ); 170596d6407fSRichard Henderson save_frd(rt, tmp); 170696d6407fSRichard Henderson 170796d6407fSRichard Henderson if (rt == 0) { 1708ad75a51eSRichard Henderson gen_helper_loaded_fr0(tcg_env); 170996d6407fSRichard Henderson } 171096d6407fSRichard Henderson 1711740038d7SRichard Henderson return nullify_end(ctx); 1712740038d7SRichard Henderson } 1713740038d7SRichard Henderson 1714740038d7SRichard Henderson static bool trans_fldd(DisasContext *ctx, arg_ldst *a) 1715740038d7SRichard Henderson { 1716740038d7SRichard Henderson return do_floadd(ctx, a->t, a->b, a->x, a->scale ? 3 : 0, 1717740038d7SRichard Henderson a->disp, a->sp, a->m); 171896d6407fSRichard Henderson } 171996d6407fSRichard Henderson 17201cd012a5SRichard Henderson static bool do_store(DisasContext *ctx, unsigned rt, unsigned rb, 1721c53e401eSRichard Henderson int64_t disp, unsigned sp, 172214776ab5STony Nguyen int modify, MemOp mop) 172396d6407fSRichard Henderson { 172496d6407fSRichard Henderson nullify_over(ctx); 17256fd0c7bcSRichard Henderson do_store_64(ctx, load_gpr(ctx, rt), rb, 0, 0, disp, sp, modify, mop); 17261cd012a5SRichard Henderson return nullify_end(ctx); 172796d6407fSRichard Henderson } 172896d6407fSRichard Henderson 1729740038d7SRichard Henderson static bool do_fstorew(DisasContext *ctx, unsigned rt, unsigned rb, 1730c53e401eSRichard Henderson unsigned rx, int scale, int64_t disp, 173186f8d05fSRichard Henderson unsigned sp, int modify) 173296d6407fSRichard Henderson { 173396d6407fSRichard Henderson TCGv_i32 tmp; 173496d6407fSRichard Henderson 173596d6407fSRichard Henderson nullify_over(ctx); 173696d6407fSRichard Henderson 173796d6407fSRichard Henderson tmp = load_frw_i32(rt); 173886f8d05fSRichard Henderson do_store_32(ctx, tmp, rb, rx, scale, disp, sp, modify, MO_TEUL); 173996d6407fSRichard Henderson 1740740038d7SRichard Henderson return nullify_end(ctx); 174196d6407fSRichard Henderson } 174296d6407fSRichard Henderson 1743740038d7SRichard Henderson static bool trans_fstw(DisasContext *ctx, arg_ldst *a) 1744740038d7SRichard Henderson { 1745740038d7SRichard Henderson return do_fstorew(ctx, a->t, a->b, a->x, a->scale ? 2 : 0, 1746740038d7SRichard Henderson a->disp, a->sp, a->m); 1747740038d7SRichard Henderson } 1748740038d7SRichard Henderson 1749740038d7SRichard Henderson static bool do_fstored(DisasContext *ctx, unsigned rt, unsigned rb, 1750c53e401eSRichard Henderson unsigned rx, int scale, int64_t disp, 175186f8d05fSRichard Henderson unsigned sp, int modify) 175296d6407fSRichard Henderson { 175396d6407fSRichard Henderson TCGv_i64 tmp; 175496d6407fSRichard Henderson 175596d6407fSRichard Henderson nullify_over(ctx); 175696d6407fSRichard Henderson 175796d6407fSRichard Henderson tmp = load_frd(rt); 1758fc313c64SFrédéric Pétrot do_store_64(ctx, tmp, rb, rx, scale, disp, sp, modify, MO_TEUQ); 175996d6407fSRichard Henderson 1760740038d7SRichard Henderson return nullify_end(ctx); 1761740038d7SRichard Henderson } 1762740038d7SRichard Henderson 1763740038d7SRichard Henderson static bool trans_fstd(DisasContext *ctx, arg_ldst *a) 1764740038d7SRichard Henderson { 1765740038d7SRichard Henderson return do_fstored(ctx, a->t, a->b, a->x, a->scale ? 3 : 0, 1766740038d7SRichard Henderson a->disp, a->sp, a->m); 176796d6407fSRichard Henderson } 176896d6407fSRichard Henderson 17691ca74648SRichard Henderson static bool do_fop_wew(DisasContext *ctx, unsigned rt, unsigned ra, 1770ebe9383cSRichard Henderson void (*func)(TCGv_i32, TCGv_env, TCGv_i32)) 1771ebe9383cSRichard Henderson { 1772ebe9383cSRichard Henderson TCGv_i32 tmp; 1773ebe9383cSRichard Henderson 1774ebe9383cSRichard Henderson nullify_over(ctx); 1775ebe9383cSRichard Henderson tmp = load_frw0_i32(ra); 1776ebe9383cSRichard Henderson 1777ad75a51eSRichard Henderson func(tmp, tcg_env, tmp); 1778ebe9383cSRichard Henderson 1779ebe9383cSRichard Henderson save_frw_i32(rt, tmp); 17801ca74648SRichard Henderson return nullify_end(ctx); 1781ebe9383cSRichard Henderson } 1782ebe9383cSRichard Henderson 17831ca74648SRichard Henderson static bool do_fop_wed(DisasContext *ctx, unsigned rt, unsigned ra, 1784ebe9383cSRichard Henderson void (*func)(TCGv_i32, TCGv_env, TCGv_i64)) 1785ebe9383cSRichard Henderson { 1786ebe9383cSRichard Henderson TCGv_i32 dst; 1787ebe9383cSRichard Henderson TCGv_i64 src; 1788ebe9383cSRichard Henderson 1789ebe9383cSRichard Henderson nullify_over(ctx); 1790ebe9383cSRichard Henderson src = load_frd(ra); 1791ebe9383cSRichard Henderson dst = tcg_temp_new_i32(); 1792ebe9383cSRichard Henderson 1793ad75a51eSRichard Henderson func(dst, tcg_env, src); 1794ebe9383cSRichard Henderson 1795ebe9383cSRichard Henderson save_frw_i32(rt, dst); 17961ca74648SRichard Henderson return nullify_end(ctx); 1797ebe9383cSRichard Henderson } 1798ebe9383cSRichard Henderson 17991ca74648SRichard Henderson static bool do_fop_ded(DisasContext *ctx, unsigned rt, unsigned ra, 1800ebe9383cSRichard Henderson void (*func)(TCGv_i64, TCGv_env, TCGv_i64)) 1801ebe9383cSRichard Henderson { 1802ebe9383cSRichard Henderson TCGv_i64 tmp; 1803ebe9383cSRichard Henderson 1804ebe9383cSRichard Henderson nullify_over(ctx); 1805ebe9383cSRichard Henderson tmp = load_frd0(ra); 1806ebe9383cSRichard Henderson 1807ad75a51eSRichard Henderson func(tmp, tcg_env, tmp); 1808ebe9383cSRichard Henderson 1809ebe9383cSRichard Henderson save_frd(rt, tmp); 18101ca74648SRichard Henderson return nullify_end(ctx); 1811ebe9383cSRichard Henderson } 1812ebe9383cSRichard Henderson 18131ca74648SRichard Henderson static bool do_fop_dew(DisasContext *ctx, unsigned rt, unsigned ra, 1814ebe9383cSRichard Henderson void (*func)(TCGv_i64, TCGv_env, TCGv_i32)) 1815ebe9383cSRichard Henderson { 1816ebe9383cSRichard Henderson TCGv_i32 src; 1817ebe9383cSRichard Henderson TCGv_i64 dst; 1818ebe9383cSRichard Henderson 1819ebe9383cSRichard Henderson nullify_over(ctx); 1820ebe9383cSRichard Henderson src = load_frw0_i32(ra); 1821ebe9383cSRichard Henderson dst = tcg_temp_new_i64(); 1822ebe9383cSRichard Henderson 1823ad75a51eSRichard Henderson func(dst, tcg_env, src); 1824ebe9383cSRichard Henderson 1825ebe9383cSRichard Henderson save_frd(rt, dst); 18261ca74648SRichard Henderson return nullify_end(ctx); 1827ebe9383cSRichard Henderson } 1828ebe9383cSRichard Henderson 18291ca74648SRichard Henderson static bool do_fop_weww(DisasContext *ctx, unsigned rt, 1830ebe9383cSRichard Henderson unsigned ra, unsigned rb, 183131234768SRichard Henderson void (*func)(TCGv_i32, TCGv_env, TCGv_i32, TCGv_i32)) 1832ebe9383cSRichard Henderson { 1833ebe9383cSRichard Henderson TCGv_i32 a, b; 1834ebe9383cSRichard Henderson 1835ebe9383cSRichard Henderson nullify_over(ctx); 1836ebe9383cSRichard Henderson a = load_frw0_i32(ra); 1837ebe9383cSRichard Henderson b = load_frw0_i32(rb); 1838ebe9383cSRichard Henderson 1839ad75a51eSRichard Henderson func(a, tcg_env, a, b); 1840ebe9383cSRichard Henderson 1841ebe9383cSRichard Henderson save_frw_i32(rt, a); 18421ca74648SRichard Henderson return nullify_end(ctx); 1843ebe9383cSRichard Henderson } 1844ebe9383cSRichard Henderson 18451ca74648SRichard Henderson static bool do_fop_dedd(DisasContext *ctx, unsigned rt, 1846ebe9383cSRichard Henderson unsigned ra, unsigned rb, 184731234768SRichard Henderson void (*func)(TCGv_i64, TCGv_env, TCGv_i64, TCGv_i64)) 1848ebe9383cSRichard Henderson { 1849ebe9383cSRichard Henderson TCGv_i64 a, b; 1850ebe9383cSRichard Henderson 1851ebe9383cSRichard Henderson nullify_over(ctx); 1852ebe9383cSRichard Henderson a = load_frd0(ra); 1853ebe9383cSRichard Henderson b = load_frd0(rb); 1854ebe9383cSRichard Henderson 1855ad75a51eSRichard Henderson func(a, tcg_env, a, b); 1856ebe9383cSRichard Henderson 1857ebe9383cSRichard Henderson save_frd(rt, a); 18581ca74648SRichard Henderson return nullify_end(ctx); 1859ebe9383cSRichard Henderson } 1860ebe9383cSRichard Henderson 186198cd9ca7SRichard Henderson /* Emit an unconditional branch to a direct target, which may or may not 186298cd9ca7SRichard Henderson have already had nullification handled. */ 18632644f80bSRichard Henderson static bool do_dbranch(DisasContext *ctx, int64_t disp, 186498cd9ca7SRichard Henderson unsigned link, bool is_n) 186598cd9ca7SRichard Henderson { 1866bc921866SRichard Henderson ctx->iaq_j = iaqe_branchi(ctx, disp); 18672644f80bSRichard Henderson 186898cd9ca7SRichard Henderson if (ctx->null_cond.c == TCG_COND_NEVER && ctx->null_lab == NULL) { 186943541db0SRichard Henderson install_link(ctx, link, false); 187098cd9ca7SRichard Henderson if (is_n) { 1871d08ad0e0SRichard Henderson if (use_nullify_skip(ctx)) { 1872d08ad0e0SRichard Henderson nullify_set(ctx, 0); 1873*d27fe7c3SRichard Henderson store_psw_xb(ctx, 0); 1874bc921866SRichard Henderson gen_goto_tb(ctx, 0, &ctx->iaq_j, NULL); 1875d08ad0e0SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 1876d08ad0e0SRichard Henderson return true; 1877d08ad0e0SRichard Henderson } 187898cd9ca7SRichard Henderson ctx->null_cond.c = TCG_COND_ALWAYS; 187998cd9ca7SRichard Henderson } 1880bc921866SRichard Henderson ctx->iaq_n = &ctx->iaq_j; 1881*d27fe7c3SRichard Henderson ctx->psw_b_next = true; 188298cd9ca7SRichard Henderson } else { 188398cd9ca7SRichard Henderson nullify_over(ctx); 188498cd9ca7SRichard Henderson 188543541db0SRichard Henderson install_link(ctx, link, false); 188698cd9ca7SRichard Henderson if (is_n && use_nullify_skip(ctx)) { 188798cd9ca7SRichard Henderson nullify_set(ctx, 0); 1888*d27fe7c3SRichard Henderson store_psw_xb(ctx, 0); 1889bc921866SRichard Henderson gen_goto_tb(ctx, 0, &ctx->iaq_j, NULL); 189098cd9ca7SRichard Henderson } else { 189198cd9ca7SRichard Henderson nullify_set(ctx, is_n); 1892*d27fe7c3SRichard Henderson store_psw_xb(ctx, PSW_B); 1893bc921866SRichard Henderson gen_goto_tb(ctx, 0, &ctx->iaq_b, &ctx->iaq_j); 189498cd9ca7SRichard Henderson } 189531234768SRichard Henderson nullify_end(ctx); 189698cd9ca7SRichard Henderson 189798cd9ca7SRichard Henderson nullify_set(ctx, 0); 1898*d27fe7c3SRichard Henderson store_psw_xb(ctx, 0); 1899bc921866SRichard Henderson gen_goto_tb(ctx, 1, &ctx->iaq_b, NULL); 190031234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 190198cd9ca7SRichard Henderson } 190201afb7beSRichard Henderson return true; 190398cd9ca7SRichard Henderson } 190498cd9ca7SRichard Henderson 190598cd9ca7SRichard Henderson /* Emit a conditional branch to a direct target. If the branch itself 190698cd9ca7SRichard Henderson is nullified, we should have already used nullify_over. */ 1907c53e401eSRichard Henderson static bool do_cbranch(DisasContext *ctx, int64_t disp, bool is_n, 190898cd9ca7SRichard Henderson DisasCond *cond) 190998cd9ca7SRichard Henderson { 1910bc921866SRichard Henderson DisasIAQE next; 191198cd9ca7SRichard Henderson TCGLabel *taken = NULL; 191298cd9ca7SRichard Henderson TCGCond c = cond->c; 191398cd9ca7SRichard Henderson bool n; 191498cd9ca7SRichard Henderson 191598cd9ca7SRichard Henderson assert(ctx->null_cond.c == TCG_COND_NEVER); 191698cd9ca7SRichard Henderson 191798cd9ca7SRichard Henderson /* Handle TRUE and NEVER as direct branches. */ 191898cd9ca7SRichard Henderson if (c == TCG_COND_ALWAYS) { 19192644f80bSRichard Henderson return do_dbranch(ctx, disp, 0, is_n && disp >= 0); 192098cd9ca7SRichard Henderson } 192198cd9ca7SRichard Henderson 192298cd9ca7SRichard Henderson taken = gen_new_label(); 19236fd0c7bcSRichard Henderson tcg_gen_brcond_i64(c, cond->a0, cond->a1, taken); 192498cd9ca7SRichard Henderson 192598cd9ca7SRichard Henderson /* Not taken: Condition not satisfied; nullify on backward branches. */ 192698cd9ca7SRichard Henderson n = is_n && disp < 0; 192798cd9ca7SRichard Henderson if (n && use_nullify_skip(ctx)) { 192898cd9ca7SRichard Henderson nullify_set(ctx, 0); 1929*d27fe7c3SRichard Henderson store_psw_xb(ctx, 0); 1930bc921866SRichard Henderson next = iaqe_incr(&ctx->iaq_b, 4); 1931bc921866SRichard Henderson gen_goto_tb(ctx, 0, &next, NULL); 193298cd9ca7SRichard Henderson } else { 193398cd9ca7SRichard Henderson if (!n && ctx->null_lab) { 193498cd9ca7SRichard Henderson gen_set_label(ctx->null_lab); 193598cd9ca7SRichard Henderson ctx->null_lab = NULL; 193698cd9ca7SRichard Henderson } 193798cd9ca7SRichard Henderson nullify_set(ctx, n); 1938*d27fe7c3SRichard Henderson store_psw_xb(ctx, 0); 1939bc921866SRichard Henderson gen_goto_tb(ctx, 0, &ctx->iaq_b, NULL); 194098cd9ca7SRichard Henderson } 194198cd9ca7SRichard Henderson 194298cd9ca7SRichard Henderson gen_set_label(taken); 194398cd9ca7SRichard Henderson 194498cd9ca7SRichard Henderson /* Taken: Condition satisfied; nullify on forward branches. */ 194598cd9ca7SRichard Henderson n = is_n && disp >= 0; 1946bc921866SRichard Henderson 1947bc921866SRichard Henderson next = iaqe_branchi(ctx, disp); 194898cd9ca7SRichard Henderson if (n && use_nullify_skip(ctx)) { 194998cd9ca7SRichard Henderson nullify_set(ctx, 0); 1950*d27fe7c3SRichard Henderson store_psw_xb(ctx, 0); 1951bc921866SRichard Henderson gen_goto_tb(ctx, 1, &next, NULL); 195298cd9ca7SRichard Henderson } else { 195398cd9ca7SRichard Henderson nullify_set(ctx, n); 1954*d27fe7c3SRichard Henderson store_psw_xb(ctx, PSW_B); 1955bc921866SRichard Henderson gen_goto_tb(ctx, 1, &ctx->iaq_b, &next); 195698cd9ca7SRichard Henderson } 195798cd9ca7SRichard Henderson 195898cd9ca7SRichard Henderson /* Not taken: the branch itself was nullified. */ 195998cd9ca7SRichard Henderson if (ctx->null_lab) { 196098cd9ca7SRichard Henderson gen_set_label(ctx->null_lab); 196198cd9ca7SRichard Henderson ctx->null_lab = NULL; 196231234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE; 196398cd9ca7SRichard Henderson } else { 196431234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 196598cd9ca7SRichard Henderson } 196601afb7beSRichard Henderson return true; 196798cd9ca7SRichard Henderson } 196898cd9ca7SRichard Henderson 1969bc921866SRichard Henderson /* 1970bc921866SRichard Henderson * Emit an unconditional branch to an indirect target, in ctx->iaq_j. 1971bc921866SRichard Henderson * This handles nullification of the branch itself. 1972bc921866SRichard Henderson */ 1973bc921866SRichard Henderson static bool do_ibranch(DisasContext *ctx, unsigned link, 1974bc921866SRichard Henderson bool with_sr0, bool is_n) 197598cd9ca7SRichard Henderson { 1976d582c1faSRichard Henderson if (ctx->null_cond.c == TCG_COND_NEVER && ctx->null_lab == NULL) { 1977019f4159SRichard Henderson install_link(ctx, link, with_sr0); 197898cd9ca7SRichard Henderson if (is_n) { 1979c301f34eSRichard Henderson if (use_nullify_skip(ctx)) { 1980bc921866SRichard Henderson install_iaq_entries(ctx, &ctx->iaq_j, NULL); 1981c301f34eSRichard Henderson nullify_set(ctx, 0); 198231234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_UPDATED; 198301afb7beSRichard Henderson return true; 1984c301f34eSRichard Henderson } 198598cd9ca7SRichard Henderson ctx->null_cond.c = TCG_COND_ALWAYS; 198698cd9ca7SRichard Henderson } 1987bc921866SRichard Henderson ctx->iaq_n = &ctx->iaq_j; 1988*d27fe7c3SRichard Henderson ctx->psw_b_next = true; 1989d582c1faSRichard Henderson return true; 1990d582c1faSRichard Henderson } 199198cd9ca7SRichard Henderson 1992d582c1faSRichard Henderson nullify_over(ctx); 1993d582c1faSRichard Henderson 1994019f4159SRichard Henderson install_link(ctx, link, with_sr0); 1995d582c1faSRichard Henderson if (is_n && use_nullify_skip(ctx)) { 1996bc921866SRichard Henderson install_iaq_entries(ctx, &ctx->iaq_j, NULL); 1997d582c1faSRichard Henderson nullify_set(ctx, 0); 1998*d27fe7c3SRichard Henderson store_psw_xb(ctx, 0); 1999d582c1faSRichard Henderson } else { 2000bc921866SRichard Henderson install_iaq_entries(ctx, &ctx->iaq_b, &ctx->iaq_j); 2001d582c1faSRichard Henderson nullify_set(ctx, is_n); 2002*d27fe7c3SRichard Henderson store_psw_xb(ctx, PSW_B); 2003d582c1faSRichard Henderson } 2004d582c1faSRichard Henderson 20057f11636dSEmilio G. Cota tcg_gen_lookup_and_goto_ptr(); 2006d582c1faSRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 200701afb7beSRichard Henderson return nullify_end(ctx); 200898cd9ca7SRichard Henderson } 200998cd9ca7SRichard Henderson 2010660eefe1SRichard Henderson /* Implement 2011660eefe1SRichard Henderson * if (IAOQ_Front{30..31} < GR[b]{30..31}) 2012660eefe1SRichard Henderson * IAOQ_Next{30..31} ← GR[b]{30..31}; 2013660eefe1SRichard Henderson * else 2014660eefe1SRichard Henderson * IAOQ_Next{30..31} ← IAOQ_Front{30..31}; 2015660eefe1SRichard Henderson * which keeps the privilege level from being increased. 2016660eefe1SRichard Henderson */ 20176fd0c7bcSRichard Henderson static TCGv_i64 do_ibranch_priv(DisasContext *ctx, TCGv_i64 offset) 2018660eefe1SRichard Henderson { 20191874e6c2SRichard Henderson TCGv_i64 dest = tcg_temp_new_i64(); 2020660eefe1SRichard Henderson switch (ctx->privilege) { 2021660eefe1SRichard Henderson case 0: 2022660eefe1SRichard Henderson /* Privilege 0 is maximum and is allowed to decrease. */ 20231874e6c2SRichard Henderson tcg_gen_mov_i64(dest, offset); 20241874e6c2SRichard Henderson break; 2025660eefe1SRichard Henderson case 3: 2026993119feSRichard Henderson /* Privilege 3 is minimum and is never allowed to increase. */ 20276fd0c7bcSRichard Henderson tcg_gen_ori_i64(dest, offset, 3); 2028660eefe1SRichard Henderson break; 2029660eefe1SRichard Henderson default: 20306fd0c7bcSRichard Henderson tcg_gen_andi_i64(dest, offset, -4); 20316fd0c7bcSRichard Henderson tcg_gen_ori_i64(dest, dest, ctx->privilege); 20320bb02029SRichard Henderson tcg_gen_umax_i64(dest, dest, offset); 2033660eefe1SRichard Henderson break; 2034660eefe1SRichard Henderson } 2035660eefe1SRichard Henderson return dest; 2036660eefe1SRichard Henderson } 2037660eefe1SRichard Henderson 2038ba1d0b44SRichard Henderson #ifdef CONFIG_USER_ONLY 20397ad439dfSRichard Henderson /* On Linux, page zero is normally marked execute only + gateway. 20407ad439dfSRichard Henderson Therefore normal read or write is supposed to fail, but specific 20417ad439dfSRichard Henderson offsets have kernel code mapped to raise permissions to implement 20427ad439dfSRichard Henderson system calls. Handling this via an explicit check here, rather 20437ad439dfSRichard Henderson in than the "be disp(sr2,r0)" instruction that probably sent us 20447ad439dfSRichard Henderson here, is the easiest way to handle the branch delay slot on the 20457ad439dfSRichard Henderson aforementioned BE. */ 204631234768SRichard Henderson static void do_page_zero(DisasContext *ctx) 20477ad439dfSRichard Henderson { 20480d89cb7cSRichard Henderson assert(ctx->iaq_f.disp == 0); 20490d89cb7cSRichard Henderson 20507ad439dfSRichard Henderson /* If by some means we get here with PSW[N]=1, that implies that 20517ad439dfSRichard Henderson the B,GATE instruction would be skipped, and we'd fault on the 20528b81968cSMichael Tokarev next insn within the privileged page. */ 20537ad439dfSRichard Henderson switch (ctx->null_cond.c) { 20547ad439dfSRichard Henderson case TCG_COND_NEVER: 20557ad439dfSRichard Henderson break; 20567ad439dfSRichard Henderson case TCG_COND_ALWAYS: 20576fd0c7bcSRichard Henderson tcg_gen_movi_i64(cpu_psw_n, 0); 20587ad439dfSRichard Henderson goto do_sigill; 20597ad439dfSRichard Henderson default: 20607ad439dfSRichard Henderson /* Since this is always the first (and only) insn within the 20617ad439dfSRichard Henderson TB, we should know the state of PSW[N] from TB->FLAGS. */ 20627ad439dfSRichard Henderson g_assert_not_reached(); 20637ad439dfSRichard Henderson } 20647ad439dfSRichard Henderson 20657ad439dfSRichard Henderson /* Check that we didn't arrive here via some means that allowed 20667ad439dfSRichard Henderson non-sequential instruction execution. Normally the PSW[B] bit 20677ad439dfSRichard Henderson detects this by disallowing the B,GATE instruction to execute 20687ad439dfSRichard Henderson under such conditions. */ 20690d89cb7cSRichard Henderson if (iaqe_variable(&ctx->iaq_b) || ctx->iaq_b.disp != 4) { 20707ad439dfSRichard Henderson goto do_sigill; 20717ad439dfSRichard Henderson } 20727ad439dfSRichard Henderson 20730d89cb7cSRichard Henderson switch (ctx->base.pc_first) { 20747ad439dfSRichard Henderson case 0x00: /* Null pointer call */ 20752986721dSRichard Henderson gen_excp_1(EXCP_IMP); 207631234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 207731234768SRichard Henderson break; 20787ad439dfSRichard Henderson 20797ad439dfSRichard Henderson case 0xb0: /* LWS */ 20807ad439dfSRichard Henderson gen_excp_1(EXCP_SYSCALL_LWS); 208131234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 208231234768SRichard Henderson break; 20837ad439dfSRichard Henderson 20847ad439dfSRichard Henderson case 0xe0: /* SET_THREAD_POINTER */ 2085bc921866SRichard Henderson { 2086bc921866SRichard Henderson DisasIAQE next = { .base = tcg_temp_new_i64() }; 2087bc921866SRichard Henderson 2088bc921866SRichard Henderson tcg_gen_st_i64(cpu_gr[26], tcg_env, 2089bc921866SRichard Henderson offsetof(CPUHPPAState, cr[27])); 20903c13b0ffSRichard Henderson tcg_gen_ori_i64(next.base, cpu_gr[31], PRIV_USER); 2091bc921866SRichard Henderson install_iaq_entries(ctx, &next, NULL); 209231234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_UPDATED; 2093bc921866SRichard Henderson } 209431234768SRichard Henderson break; 20957ad439dfSRichard Henderson 20967ad439dfSRichard Henderson case 0x100: /* SYSCALL */ 20977ad439dfSRichard Henderson gen_excp_1(EXCP_SYSCALL); 209831234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 209931234768SRichard Henderson break; 21007ad439dfSRichard Henderson 21017ad439dfSRichard Henderson default: 21027ad439dfSRichard Henderson do_sigill: 21032986721dSRichard Henderson gen_excp_1(EXCP_ILL); 210431234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 210531234768SRichard Henderson break; 21067ad439dfSRichard Henderson } 21077ad439dfSRichard Henderson } 2108ba1d0b44SRichard Henderson #endif 21097ad439dfSRichard Henderson 2110deee69a1SRichard Henderson static bool trans_nop(DisasContext *ctx, arg_nop *a) 2111b2167459SRichard Henderson { 2112e0137378SRichard Henderson ctx->null_cond = cond_make_f(); 211331234768SRichard Henderson return true; 2114b2167459SRichard Henderson } 2115b2167459SRichard Henderson 211640f9f908SRichard Henderson static bool trans_break(DisasContext *ctx, arg_break *a) 211798a9cb79SRichard Henderson { 211831234768SRichard Henderson return gen_excp_iir(ctx, EXCP_BREAK); 211998a9cb79SRichard Henderson } 212098a9cb79SRichard Henderson 2121e36f27efSRichard Henderson static bool trans_sync(DisasContext *ctx, arg_sync *a) 212298a9cb79SRichard Henderson { 212398a9cb79SRichard Henderson /* No point in nullifying the memory barrier. */ 212498a9cb79SRichard Henderson tcg_gen_mb(TCG_BAR_SC | TCG_MO_ALL); 212598a9cb79SRichard Henderson 2126e0137378SRichard Henderson ctx->null_cond = cond_make_f(); 212731234768SRichard Henderson return true; 212898a9cb79SRichard Henderson } 212998a9cb79SRichard Henderson 2130c603e14aSRichard Henderson static bool trans_mfia(DisasContext *ctx, arg_mfia *a) 213198a9cb79SRichard Henderson { 2132bc921866SRichard Henderson TCGv_i64 dest = dest_gpr(ctx, a->t); 213398a9cb79SRichard Henderson 2134bc921866SRichard Henderson copy_iaoq_entry(ctx, dest, &ctx->iaq_f); 2135bc921866SRichard Henderson tcg_gen_andi_i64(dest, dest, -4); 2136bc921866SRichard Henderson 2137bc921866SRichard Henderson save_gpr(ctx, a->t, dest); 2138e0137378SRichard Henderson ctx->null_cond = cond_make_f(); 213931234768SRichard Henderson return true; 214098a9cb79SRichard Henderson } 214198a9cb79SRichard Henderson 2142c603e14aSRichard Henderson static bool trans_mfsp(DisasContext *ctx, arg_mfsp *a) 214398a9cb79SRichard Henderson { 2144c603e14aSRichard Henderson unsigned rt = a->t; 2145c603e14aSRichard Henderson unsigned rs = a->sp; 214633423472SRichard Henderson TCGv_i64 t0 = tcg_temp_new_i64(); 214798a9cb79SRichard Henderson 214833423472SRichard Henderson load_spr(ctx, t0, rs); 214933423472SRichard Henderson tcg_gen_shri_i64(t0, t0, 32); 215033423472SRichard Henderson 2151967662cdSRichard Henderson save_gpr(ctx, rt, t0); 215298a9cb79SRichard Henderson 2153e0137378SRichard Henderson ctx->null_cond = cond_make_f(); 215431234768SRichard Henderson return true; 215598a9cb79SRichard Henderson } 215698a9cb79SRichard Henderson 2157c603e14aSRichard Henderson static bool trans_mfctl(DisasContext *ctx, arg_mfctl *a) 215898a9cb79SRichard Henderson { 2159c603e14aSRichard Henderson unsigned rt = a->t; 2160c603e14aSRichard Henderson unsigned ctl = a->r; 21616fd0c7bcSRichard Henderson TCGv_i64 tmp; 216298a9cb79SRichard Henderson 216398a9cb79SRichard Henderson switch (ctl) { 216435136a77SRichard Henderson case CR_SAR: 2165c603e14aSRichard Henderson if (a->e == 0) { 216698a9cb79SRichard Henderson /* MFSAR without ,W masks low 5 bits. */ 216798a9cb79SRichard Henderson tmp = dest_gpr(ctx, rt); 21686fd0c7bcSRichard Henderson tcg_gen_andi_i64(tmp, cpu_sar, 31); 216998a9cb79SRichard Henderson save_gpr(ctx, rt, tmp); 217035136a77SRichard Henderson goto done; 217198a9cb79SRichard Henderson } 217298a9cb79SRichard Henderson save_gpr(ctx, rt, cpu_sar); 217335136a77SRichard Henderson goto done; 217435136a77SRichard Henderson case CR_IT: /* Interval Timer */ 217535136a77SRichard Henderson /* FIXME: Respect PSW_S bit. */ 217635136a77SRichard Henderson nullify_over(ctx); 217798a9cb79SRichard Henderson tmp = dest_gpr(ctx, rt); 2178dfd1b812SRichard Henderson if (translator_io_start(&ctx->base)) { 217931234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE; 218049c29d6cSRichard Henderson } 21810c58c1bcSRichard Henderson gen_helper_read_interval_timer(tmp); 218298a9cb79SRichard Henderson save_gpr(ctx, rt, tmp); 218331234768SRichard Henderson return nullify_end(ctx); 218498a9cb79SRichard Henderson case 26: 218598a9cb79SRichard Henderson case 27: 218698a9cb79SRichard Henderson break; 218798a9cb79SRichard Henderson default: 218898a9cb79SRichard Henderson /* All other control registers are privileged. */ 218935136a77SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_REG); 219035136a77SRichard Henderson break; 219198a9cb79SRichard Henderson } 219298a9cb79SRichard Henderson 2193aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 21946fd0c7bcSRichard Henderson tcg_gen_ld_i64(tmp, tcg_env, offsetof(CPUHPPAState, cr[ctl])); 219535136a77SRichard Henderson save_gpr(ctx, rt, tmp); 219635136a77SRichard Henderson 219735136a77SRichard Henderson done: 2198e0137378SRichard Henderson ctx->null_cond = cond_make_f(); 219931234768SRichard Henderson return true; 220098a9cb79SRichard Henderson } 220198a9cb79SRichard Henderson 2202c603e14aSRichard Henderson static bool trans_mtsp(DisasContext *ctx, arg_mtsp *a) 220333423472SRichard Henderson { 2204c603e14aSRichard Henderson unsigned rr = a->r; 2205c603e14aSRichard Henderson unsigned rs = a->sp; 2206967662cdSRichard Henderson TCGv_i64 tmp; 220733423472SRichard Henderson 220833423472SRichard Henderson if (rs >= 5) { 220933423472SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_REG); 221033423472SRichard Henderson } 221133423472SRichard Henderson nullify_over(ctx); 221233423472SRichard Henderson 2213967662cdSRichard Henderson tmp = tcg_temp_new_i64(); 2214967662cdSRichard Henderson tcg_gen_shli_i64(tmp, load_gpr(ctx, rr), 32); 221533423472SRichard Henderson 221633423472SRichard Henderson if (rs >= 4) { 2217967662cdSRichard Henderson tcg_gen_st_i64(tmp, tcg_env, offsetof(CPUHPPAState, sr[rs])); 2218494737b7SRichard Henderson ctx->tb_flags &= ~TB_FLAG_SR_SAME; 221933423472SRichard Henderson } else { 2220967662cdSRichard Henderson tcg_gen_mov_i64(cpu_sr[rs], tmp); 222133423472SRichard Henderson } 222233423472SRichard Henderson 222331234768SRichard Henderson return nullify_end(ctx); 222433423472SRichard Henderson } 222533423472SRichard Henderson 2226c603e14aSRichard Henderson static bool trans_mtctl(DisasContext *ctx, arg_mtctl *a) 222798a9cb79SRichard Henderson { 2228c603e14aSRichard Henderson unsigned ctl = a->t; 22296fd0c7bcSRichard Henderson TCGv_i64 reg; 22306fd0c7bcSRichard Henderson TCGv_i64 tmp; 223198a9cb79SRichard Henderson 223235136a77SRichard Henderson if (ctl == CR_SAR) { 22334845f015SSven Schnelle reg = load_gpr(ctx, a->r); 2234aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 22356fd0c7bcSRichard Henderson tcg_gen_andi_i64(tmp, reg, ctx->is_pa20 ? 63 : 31); 223698a9cb79SRichard Henderson save_or_nullify(ctx, cpu_sar, tmp); 223798a9cb79SRichard Henderson 2238e0137378SRichard Henderson ctx->null_cond = cond_make_f(); 223931234768SRichard Henderson return true; 224098a9cb79SRichard Henderson } 224198a9cb79SRichard Henderson 224235136a77SRichard Henderson /* All other control registers are privileged or read-only. */ 224335136a77SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_REG); 224435136a77SRichard Henderson 2245c603e14aSRichard Henderson #ifndef CONFIG_USER_ONLY 224635136a77SRichard Henderson nullify_over(ctx); 22474c34bab0SHelge Deller 22484c34bab0SHelge Deller if (ctx->is_pa20) { 22494845f015SSven Schnelle reg = load_gpr(ctx, a->r); 22504c34bab0SHelge Deller } else { 22514c34bab0SHelge Deller reg = tcg_temp_new_i64(); 22524c34bab0SHelge Deller tcg_gen_ext32u_i64(reg, load_gpr(ctx, a->r)); 22534c34bab0SHelge Deller } 22544845f015SSven Schnelle 225535136a77SRichard Henderson switch (ctl) { 225635136a77SRichard Henderson case CR_IT: 2257104281c1SRichard Henderson if (translator_io_start(&ctx->base)) { 2258104281c1SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE; 2259104281c1SRichard Henderson } 2260ad75a51eSRichard Henderson gen_helper_write_interval_timer(tcg_env, reg); 226135136a77SRichard Henderson break; 22624f5f2548SRichard Henderson case CR_EIRR: 22636ebebea7SRichard Henderson /* Helper modifies interrupt lines and is therefore IO. */ 22646ebebea7SRichard Henderson translator_io_start(&ctx->base); 2265ad75a51eSRichard Henderson gen_helper_write_eirr(tcg_env, reg); 22666ebebea7SRichard Henderson /* Exit to re-evaluate interrupts in the main loop. */ 226731234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE_EXIT; 22684f5f2548SRichard Henderson break; 22694f5f2548SRichard Henderson 227035136a77SRichard Henderson case CR_IIASQ: 227135136a77SRichard Henderson case CR_IIAOQ: 227235136a77SRichard Henderson /* FIXME: Respect PSW_Q bit */ 227335136a77SRichard Henderson /* The write advances the queue and stores to the back element. */ 2274aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 22756fd0c7bcSRichard Henderson tcg_gen_ld_i64(tmp, tcg_env, 227635136a77SRichard Henderson offsetof(CPUHPPAState, cr_back[ctl - CR_IIASQ])); 22776fd0c7bcSRichard Henderson tcg_gen_st_i64(tmp, tcg_env, offsetof(CPUHPPAState, cr[ctl])); 22786fd0c7bcSRichard Henderson tcg_gen_st_i64(reg, tcg_env, 227935136a77SRichard Henderson offsetof(CPUHPPAState, cr_back[ctl - CR_IIASQ])); 228035136a77SRichard Henderson break; 228135136a77SRichard Henderson 2282d5de20bdSSven Schnelle case CR_PID1: 2283d5de20bdSSven Schnelle case CR_PID2: 2284d5de20bdSSven Schnelle case CR_PID3: 2285d5de20bdSSven Schnelle case CR_PID4: 22866fd0c7bcSRichard Henderson tcg_gen_st_i64(reg, tcg_env, offsetof(CPUHPPAState, cr[ctl])); 2287d5de20bdSSven Schnelle #ifndef CONFIG_USER_ONLY 2288ad75a51eSRichard Henderson gen_helper_change_prot_id(tcg_env); 2289d5de20bdSSven Schnelle #endif 2290d5de20bdSSven Schnelle break; 2291d5de20bdSSven Schnelle 22926ebebea7SRichard Henderson case CR_EIEM: 22936ebebea7SRichard Henderson /* Exit to re-evaluate interrupts in the main loop. */ 22946ebebea7SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE_EXIT; 22956ebebea7SRichard Henderson /* FALLTHRU */ 229635136a77SRichard Henderson default: 22976fd0c7bcSRichard Henderson tcg_gen_st_i64(reg, tcg_env, offsetof(CPUHPPAState, cr[ctl])); 229835136a77SRichard Henderson break; 229935136a77SRichard Henderson } 230031234768SRichard Henderson return nullify_end(ctx); 23014f5f2548SRichard Henderson #endif 230235136a77SRichard Henderson } 230335136a77SRichard Henderson 2304c603e14aSRichard Henderson static bool trans_mtsarcm(DisasContext *ctx, arg_mtsarcm *a) 230598a9cb79SRichard Henderson { 2306aac0f603SRichard Henderson TCGv_i64 tmp = tcg_temp_new_i64(); 230798a9cb79SRichard Henderson 23086fd0c7bcSRichard Henderson tcg_gen_not_i64(tmp, load_gpr(ctx, a->r)); 23096fd0c7bcSRichard Henderson tcg_gen_andi_i64(tmp, tmp, ctx->is_pa20 ? 63 : 31); 231098a9cb79SRichard Henderson save_or_nullify(ctx, cpu_sar, tmp); 231198a9cb79SRichard Henderson 2312e0137378SRichard Henderson ctx->null_cond = cond_make_f(); 231331234768SRichard Henderson return true; 231498a9cb79SRichard Henderson } 231598a9cb79SRichard Henderson 2316e36f27efSRichard Henderson static bool trans_ldsid(DisasContext *ctx, arg_ldsid *a) 231798a9cb79SRichard Henderson { 23186fd0c7bcSRichard Henderson TCGv_i64 dest = dest_gpr(ctx, a->t); 231998a9cb79SRichard Henderson 23202330504cSHelge Deller #ifdef CONFIG_USER_ONLY 23212330504cSHelge Deller /* We don't implement space registers in user mode. */ 23226fd0c7bcSRichard Henderson tcg_gen_movi_i64(dest, 0); 23232330504cSHelge Deller #else 2324967662cdSRichard Henderson tcg_gen_mov_i64(dest, space_select(ctx, a->sp, load_gpr(ctx, a->b))); 2325967662cdSRichard Henderson tcg_gen_shri_i64(dest, dest, 32); 23262330504cSHelge Deller #endif 2327e36f27efSRichard Henderson save_gpr(ctx, a->t, dest); 232898a9cb79SRichard Henderson 2329e0137378SRichard Henderson ctx->null_cond = cond_make_f(); 233031234768SRichard Henderson return true; 233198a9cb79SRichard Henderson } 233298a9cb79SRichard Henderson 2333e36f27efSRichard Henderson static bool trans_rsm(DisasContext *ctx, arg_rsm *a) 2334e36f27efSRichard Henderson { 23357b2d70a1SHelge Deller #ifdef CONFIG_USER_ONLY 2336e36f27efSRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 23377b2d70a1SHelge Deller #else 23386fd0c7bcSRichard Henderson TCGv_i64 tmp; 2339e1b5a5edSRichard Henderson 23407b2d70a1SHelge Deller /* HP-UX 11i and HP ODE use rsm for read-access to PSW */ 23417b2d70a1SHelge Deller if (a->i) { 23427b2d70a1SHelge Deller CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 23437b2d70a1SHelge Deller } 23447b2d70a1SHelge Deller 2345e1b5a5edSRichard Henderson nullify_over(ctx); 2346e1b5a5edSRichard Henderson 2347aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 23486fd0c7bcSRichard Henderson tcg_gen_ld_i64(tmp, tcg_env, offsetof(CPUHPPAState, psw)); 23496fd0c7bcSRichard Henderson tcg_gen_andi_i64(tmp, tmp, ~a->i); 2350ad75a51eSRichard Henderson gen_helper_swap_system_mask(tmp, tcg_env, tmp); 2351e36f27efSRichard Henderson save_gpr(ctx, a->t, tmp); 2352e1b5a5edSRichard Henderson 2353e1b5a5edSRichard Henderson /* Exit the TB to recognize new interrupts, e.g. PSW_M. */ 235431234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE_EXIT; 235531234768SRichard Henderson return nullify_end(ctx); 2356e36f27efSRichard Henderson #endif 2357e1b5a5edSRichard Henderson } 2358e1b5a5edSRichard Henderson 2359e36f27efSRichard Henderson static bool trans_ssm(DisasContext *ctx, arg_ssm *a) 2360e1b5a5edSRichard Henderson { 2361e36f27efSRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 2362e36f27efSRichard Henderson #ifndef CONFIG_USER_ONLY 23636fd0c7bcSRichard Henderson TCGv_i64 tmp; 2364e1b5a5edSRichard Henderson 2365e1b5a5edSRichard Henderson nullify_over(ctx); 2366e1b5a5edSRichard Henderson 2367aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 23686fd0c7bcSRichard Henderson tcg_gen_ld_i64(tmp, tcg_env, offsetof(CPUHPPAState, psw)); 23696fd0c7bcSRichard Henderson tcg_gen_ori_i64(tmp, tmp, a->i); 2370ad75a51eSRichard Henderson gen_helper_swap_system_mask(tmp, tcg_env, tmp); 2371e36f27efSRichard Henderson save_gpr(ctx, a->t, tmp); 2372e1b5a5edSRichard Henderson 2373e1b5a5edSRichard Henderson /* Exit the TB to recognize new interrupts, e.g. PSW_I. */ 237431234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE_EXIT; 237531234768SRichard Henderson return nullify_end(ctx); 2376e36f27efSRichard Henderson #endif 2377e1b5a5edSRichard Henderson } 2378e1b5a5edSRichard Henderson 2379c603e14aSRichard Henderson static bool trans_mtsm(DisasContext *ctx, arg_mtsm *a) 2380e1b5a5edSRichard Henderson { 2381e1b5a5edSRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 2382c603e14aSRichard Henderson #ifndef CONFIG_USER_ONLY 23836fd0c7bcSRichard Henderson TCGv_i64 tmp, reg; 2384e1b5a5edSRichard Henderson nullify_over(ctx); 2385e1b5a5edSRichard Henderson 2386c603e14aSRichard Henderson reg = load_gpr(ctx, a->r); 2387aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 2388ad75a51eSRichard Henderson gen_helper_swap_system_mask(tmp, tcg_env, reg); 2389e1b5a5edSRichard Henderson 2390e1b5a5edSRichard Henderson /* Exit the TB to recognize new interrupts. */ 239131234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE_EXIT; 239231234768SRichard Henderson return nullify_end(ctx); 2393c603e14aSRichard Henderson #endif 2394e1b5a5edSRichard Henderson } 2395f49b3537SRichard Henderson 2396e36f27efSRichard Henderson static bool do_rfi(DisasContext *ctx, bool rfi_r) 2397f49b3537SRichard Henderson { 2398f49b3537SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 2399e36f27efSRichard Henderson #ifndef CONFIG_USER_ONLY 2400f49b3537SRichard Henderson nullify_over(ctx); 2401f49b3537SRichard Henderson 2402e36f27efSRichard Henderson if (rfi_r) { 2403ad75a51eSRichard Henderson gen_helper_rfi_r(tcg_env); 2404f49b3537SRichard Henderson } else { 2405ad75a51eSRichard Henderson gen_helper_rfi(tcg_env); 2406f49b3537SRichard Henderson } 240731234768SRichard Henderson /* Exit the TB to recognize new interrupts. */ 240807ea28b4SRichard Henderson tcg_gen_exit_tb(NULL, 0); 240931234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 2410f49b3537SRichard Henderson 241131234768SRichard Henderson return nullify_end(ctx); 2412e36f27efSRichard Henderson #endif 2413f49b3537SRichard Henderson } 24146210db05SHelge Deller 2415e36f27efSRichard Henderson static bool trans_rfi(DisasContext *ctx, arg_rfi *a) 2416e36f27efSRichard Henderson { 2417e36f27efSRichard Henderson return do_rfi(ctx, false); 2418e36f27efSRichard Henderson } 2419e36f27efSRichard Henderson 2420e36f27efSRichard Henderson static bool trans_rfi_r(DisasContext *ctx, arg_rfi_r *a) 2421e36f27efSRichard Henderson { 2422e36f27efSRichard Henderson return do_rfi(ctx, true); 2423e36f27efSRichard Henderson } 2424e36f27efSRichard Henderson 242596927adbSRichard Henderson static bool trans_halt(DisasContext *ctx, arg_halt *a) 24266210db05SHelge Deller { 24276210db05SHelge Deller CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 242896927adbSRichard Henderson #ifndef CONFIG_USER_ONLY 2429*d27fe7c3SRichard Henderson set_psw_xb(ctx, 0); 24306210db05SHelge Deller nullify_over(ctx); 2431ad75a51eSRichard Henderson gen_helper_halt(tcg_env); 243231234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 243331234768SRichard Henderson return nullify_end(ctx); 243496927adbSRichard Henderson #endif 24356210db05SHelge Deller } 243696927adbSRichard Henderson 243796927adbSRichard Henderson static bool trans_reset(DisasContext *ctx, arg_reset *a) 243896927adbSRichard Henderson { 243996927adbSRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 244096927adbSRichard Henderson #ifndef CONFIG_USER_ONLY 2441*d27fe7c3SRichard Henderson set_psw_xb(ctx, 0); 244296927adbSRichard Henderson nullify_over(ctx); 2443ad75a51eSRichard Henderson gen_helper_reset(tcg_env); 244496927adbSRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 244596927adbSRichard Henderson return nullify_end(ctx); 244696927adbSRichard Henderson #endif 244796927adbSRichard Henderson } 2448e1b5a5edSRichard Henderson 2449558c09beSRichard Henderson static bool do_getshadowregs(DisasContext *ctx) 24504a4554c6SHelge Deller { 24514a4554c6SHelge Deller CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 24524a4554c6SHelge Deller nullify_over(ctx); 2453558c09beSRichard Henderson tcg_gen_ld_i64(cpu_gr[1], tcg_env, offsetof(CPUHPPAState, shadow[0])); 2454558c09beSRichard Henderson tcg_gen_ld_i64(cpu_gr[8], tcg_env, offsetof(CPUHPPAState, shadow[1])); 2455558c09beSRichard Henderson tcg_gen_ld_i64(cpu_gr[9], tcg_env, offsetof(CPUHPPAState, shadow[2])); 2456558c09beSRichard Henderson tcg_gen_ld_i64(cpu_gr[16], tcg_env, offsetof(CPUHPPAState, shadow[3])); 2457558c09beSRichard Henderson tcg_gen_ld_i64(cpu_gr[17], tcg_env, offsetof(CPUHPPAState, shadow[4])); 2458558c09beSRichard Henderson tcg_gen_ld_i64(cpu_gr[24], tcg_env, offsetof(CPUHPPAState, shadow[5])); 2459558c09beSRichard Henderson tcg_gen_ld_i64(cpu_gr[25], tcg_env, offsetof(CPUHPPAState, shadow[6])); 24604a4554c6SHelge Deller return nullify_end(ctx); 2461558c09beSRichard Henderson } 2462558c09beSRichard Henderson 24633bdf2081SHelge Deller static bool do_putshadowregs(DisasContext *ctx) 24643bdf2081SHelge Deller { 24653bdf2081SHelge Deller CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 24663bdf2081SHelge Deller nullify_over(ctx); 24673bdf2081SHelge Deller tcg_gen_st_i64(cpu_gr[1], tcg_env, offsetof(CPUHPPAState, shadow[0])); 24683bdf2081SHelge Deller tcg_gen_st_i64(cpu_gr[8], tcg_env, offsetof(CPUHPPAState, shadow[1])); 24693bdf2081SHelge Deller tcg_gen_st_i64(cpu_gr[9], tcg_env, offsetof(CPUHPPAState, shadow[2])); 24703bdf2081SHelge Deller tcg_gen_st_i64(cpu_gr[16], tcg_env, offsetof(CPUHPPAState, shadow[3])); 24713bdf2081SHelge Deller tcg_gen_st_i64(cpu_gr[17], tcg_env, offsetof(CPUHPPAState, shadow[4])); 24723bdf2081SHelge Deller tcg_gen_st_i64(cpu_gr[24], tcg_env, offsetof(CPUHPPAState, shadow[5])); 24733bdf2081SHelge Deller tcg_gen_st_i64(cpu_gr[25], tcg_env, offsetof(CPUHPPAState, shadow[6])); 24743bdf2081SHelge Deller return nullify_end(ctx); 24753bdf2081SHelge Deller } 24763bdf2081SHelge Deller 2477558c09beSRichard Henderson static bool trans_getshadowregs(DisasContext *ctx, arg_getshadowregs *a) 2478558c09beSRichard Henderson { 2479558c09beSRichard Henderson return do_getshadowregs(ctx); 24804a4554c6SHelge Deller } 24814a4554c6SHelge Deller 2482deee69a1SRichard Henderson static bool trans_nop_addrx(DisasContext *ctx, arg_ldst *a) 248398a9cb79SRichard Henderson { 2484deee69a1SRichard Henderson if (a->m) { 24856fd0c7bcSRichard Henderson TCGv_i64 dest = dest_gpr(ctx, a->b); 24866fd0c7bcSRichard Henderson TCGv_i64 src1 = load_gpr(ctx, a->b); 24876fd0c7bcSRichard Henderson TCGv_i64 src2 = load_gpr(ctx, a->x); 248898a9cb79SRichard Henderson 248998a9cb79SRichard Henderson /* The only thing we need to do is the base register modification. */ 24906fd0c7bcSRichard Henderson tcg_gen_add_i64(dest, src1, src2); 2491deee69a1SRichard Henderson save_gpr(ctx, a->b, dest); 2492deee69a1SRichard Henderson } 2493e0137378SRichard Henderson ctx->null_cond = cond_make_f(); 249431234768SRichard Henderson return true; 249598a9cb79SRichard Henderson } 249698a9cb79SRichard Henderson 2497ad1fdacdSSven Schnelle static bool trans_fic(DisasContext *ctx, arg_ldst *a) 2498ad1fdacdSSven Schnelle { 2499ad1fdacdSSven Schnelle /* End TB for flush instruction cache, so we pick up new insns. */ 2500ad1fdacdSSven Schnelle ctx->base.is_jmp = DISAS_IAQ_N_STALE; 2501ad1fdacdSSven Schnelle return trans_nop_addrx(ctx, a); 2502ad1fdacdSSven Schnelle } 2503ad1fdacdSSven Schnelle 2504deee69a1SRichard Henderson static bool trans_probe(DisasContext *ctx, arg_probe *a) 250598a9cb79SRichard Henderson { 25066fd0c7bcSRichard Henderson TCGv_i64 dest, ofs; 2507eed14219SRichard Henderson TCGv_i32 level, want; 25086fd0c7bcSRichard Henderson TCGv_i64 addr; 250998a9cb79SRichard Henderson 251098a9cb79SRichard Henderson nullify_over(ctx); 251198a9cb79SRichard Henderson 2512deee69a1SRichard Henderson dest = dest_gpr(ctx, a->t); 2513deee69a1SRichard Henderson form_gva(ctx, &addr, &ofs, a->b, 0, 0, 0, a->sp, 0, false); 2514eed14219SRichard Henderson 2515deee69a1SRichard Henderson if (a->imm) { 2516e5d487c9SRichard Henderson level = tcg_constant_i32(a->ri & 3); 251798a9cb79SRichard Henderson } else { 2518eed14219SRichard Henderson level = tcg_temp_new_i32(); 25196fd0c7bcSRichard Henderson tcg_gen_extrl_i64_i32(level, load_gpr(ctx, a->ri)); 2520eed14219SRichard Henderson tcg_gen_andi_i32(level, level, 3); 252198a9cb79SRichard Henderson } 252229dd6f64SRichard Henderson want = tcg_constant_i32(a->write ? PAGE_WRITE : PAGE_READ); 2523eed14219SRichard Henderson 2524ad75a51eSRichard Henderson gen_helper_probe(dest, tcg_env, addr, level, want); 2525eed14219SRichard Henderson 2526deee69a1SRichard Henderson save_gpr(ctx, a->t, dest); 252731234768SRichard Henderson return nullify_end(ctx); 252898a9cb79SRichard Henderson } 252998a9cb79SRichard Henderson 2530deee69a1SRichard Henderson static bool trans_ixtlbx(DisasContext *ctx, arg_ixtlbx *a) 25318d6ae7fbSRichard Henderson { 25328577f354SRichard Henderson if (ctx->is_pa20) { 25338577f354SRichard Henderson return false; 25348577f354SRichard Henderson } 2535deee69a1SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 2536deee69a1SRichard Henderson #ifndef CONFIG_USER_ONLY 25376fd0c7bcSRichard Henderson TCGv_i64 addr; 25386fd0c7bcSRichard Henderson TCGv_i64 ofs, reg; 25398d6ae7fbSRichard Henderson 25408d6ae7fbSRichard Henderson nullify_over(ctx); 25418d6ae7fbSRichard Henderson 2542deee69a1SRichard Henderson form_gva(ctx, &addr, &ofs, a->b, 0, 0, 0, a->sp, 0, false); 2543deee69a1SRichard Henderson reg = load_gpr(ctx, a->r); 2544deee69a1SRichard Henderson if (a->addr) { 25458577f354SRichard Henderson gen_helper_itlba_pa11(tcg_env, addr, reg); 25468d6ae7fbSRichard Henderson } else { 25478577f354SRichard Henderson gen_helper_itlbp_pa11(tcg_env, addr, reg); 25488d6ae7fbSRichard Henderson } 25498d6ae7fbSRichard Henderson 255032dc7569SSven Schnelle /* Exit TB for TLB change if mmu is enabled. */ 255132dc7569SSven Schnelle if (ctx->tb_flags & PSW_C) { 255231234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE; 255331234768SRichard Henderson } 255431234768SRichard Henderson return nullify_end(ctx); 2555deee69a1SRichard Henderson #endif 25568d6ae7fbSRichard Henderson } 255763300a00SRichard Henderson 2558eb25d10fSHelge Deller static bool do_pxtlb(DisasContext *ctx, arg_ldst *a, bool local) 255963300a00SRichard Henderson { 2560deee69a1SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 2561deee69a1SRichard Henderson #ifndef CONFIG_USER_ONLY 25626fd0c7bcSRichard Henderson TCGv_i64 addr; 25636fd0c7bcSRichard Henderson TCGv_i64 ofs; 256463300a00SRichard Henderson 256563300a00SRichard Henderson nullify_over(ctx); 256663300a00SRichard Henderson 2567deee69a1SRichard Henderson form_gva(ctx, &addr, &ofs, a->b, a->x, 0, 0, a->sp, a->m, false); 2568eb25d10fSHelge Deller 2569eb25d10fSHelge Deller /* 2570eb25d10fSHelge Deller * Page align now, rather than later, so that we can add in the 2571eb25d10fSHelge Deller * page_size field from pa2.0 from the low 4 bits of GR[b]. 2572eb25d10fSHelge Deller */ 2573eb25d10fSHelge Deller tcg_gen_andi_i64(addr, addr, TARGET_PAGE_MASK); 2574eb25d10fSHelge Deller if (ctx->is_pa20) { 2575eb25d10fSHelge Deller tcg_gen_deposit_i64(addr, addr, load_gpr(ctx, a->b), 0, 4); 257663300a00SRichard Henderson } 2577eb25d10fSHelge Deller 2578eb25d10fSHelge Deller if (local) { 2579eb25d10fSHelge Deller gen_helper_ptlb_l(tcg_env, addr); 258063300a00SRichard Henderson } else { 2581ad75a51eSRichard Henderson gen_helper_ptlb(tcg_env, addr); 258263300a00SRichard Henderson } 258363300a00SRichard Henderson 2584eb25d10fSHelge Deller if (a->m) { 2585eb25d10fSHelge Deller save_gpr(ctx, a->b, ofs); 2586eb25d10fSHelge Deller } 2587eb25d10fSHelge Deller 2588eb25d10fSHelge Deller /* Exit TB for TLB change if mmu is enabled. */ 2589eb25d10fSHelge Deller if (ctx->tb_flags & PSW_C) { 2590eb25d10fSHelge Deller ctx->base.is_jmp = DISAS_IAQ_N_STALE; 2591eb25d10fSHelge Deller } 2592eb25d10fSHelge Deller return nullify_end(ctx); 2593eb25d10fSHelge Deller #endif 2594eb25d10fSHelge Deller } 2595eb25d10fSHelge Deller 2596eb25d10fSHelge Deller static bool trans_pxtlb(DisasContext *ctx, arg_ldst *a) 2597eb25d10fSHelge Deller { 2598eb25d10fSHelge Deller return do_pxtlb(ctx, a, false); 2599eb25d10fSHelge Deller } 2600eb25d10fSHelge Deller 2601eb25d10fSHelge Deller static bool trans_pxtlb_l(DisasContext *ctx, arg_ldst *a) 2602eb25d10fSHelge Deller { 2603eb25d10fSHelge Deller return ctx->is_pa20 && do_pxtlb(ctx, a, true); 2604eb25d10fSHelge Deller } 2605eb25d10fSHelge Deller 2606eb25d10fSHelge Deller static bool trans_pxtlbe(DisasContext *ctx, arg_ldst *a) 2607eb25d10fSHelge Deller { 2608eb25d10fSHelge Deller CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 2609eb25d10fSHelge Deller #ifndef CONFIG_USER_ONLY 2610eb25d10fSHelge Deller nullify_over(ctx); 2611eb25d10fSHelge Deller 2612eb25d10fSHelge Deller trans_nop_addrx(ctx, a); 2613eb25d10fSHelge Deller gen_helper_ptlbe(tcg_env); 2614eb25d10fSHelge Deller 261563300a00SRichard Henderson /* Exit TB for TLB change if mmu is enabled. */ 261632dc7569SSven Schnelle if (ctx->tb_flags & PSW_C) { 261731234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE; 261831234768SRichard Henderson } 261931234768SRichard Henderson return nullify_end(ctx); 2620deee69a1SRichard Henderson #endif 262163300a00SRichard Henderson } 26222dfcca9fSRichard Henderson 26236797c315SNick Hudson /* 26246797c315SNick Hudson * Implement the pcxl and pcxl2 Fast TLB Insert instructions. 26256797c315SNick Hudson * See 26266797c315SNick Hudson * https://parisc.wiki.kernel.org/images-parisc/a/a9/Pcxl2_ers.pdf 26276797c315SNick Hudson * page 13-9 (195/206) 26286797c315SNick Hudson */ 26296797c315SNick Hudson static bool trans_ixtlbxf(DisasContext *ctx, arg_ixtlbxf *a) 26306797c315SNick Hudson { 26318577f354SRichard Henderson if (ctx->is_pa20) { 26328577f354SRichard Henderson return false; 26338577f354SRichard Henderson } 26346797c315SNick Hudson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 26356797c315SNick Hudson #ifndef CONFIG_USER_ONLY 26366fd0c7bcSRichard Henderson TCGv_i64 addr, atl, stl; 26376fd0c7bcSRichard Henderson TCGv_i64 reg; 26386797c315SNick Hudson 26396797c315SNick Hudson nullify_over(ctx); 26406797c315SNick Hudson 26416797c315SNick Hudson /* 26426797c315SNick Hudson * FIXME: 26436797c315SNick Hudson * if (not (pcxl or pcxl2)) 26446797c315SNick Hudson * return gen_illegal(ctx); 26456797c315SNick Hudson */ 26466797c315SNick Hudson 26476fd0c7bcSRichard Henderson atl = tcg_temp_new_i64(); 26486fd0c7bcSRichard Henderson stl = tcg_temp_new_i64(); 26496fd0c7bcSRichard Henderson addr = tcg_temp_new_i64(); 26506797c315SNick Hudson 2651ad75a51eSRichard Henderson tcg_gen_ld32u_i64(stl, tcg_env, 26526797c315SNick Hudson a->data ? offsetof(CPUHPPAState, cr[CR_ISR]) 26536797c315SNick Hudson : offsetof(CPUHPPAState, cr[CR_IIASQ])); 2654ad75a51eSRichard Henderson tcg_gen_ld32u_i64(atl, tcg_env, 26556797c315SNick Hudson a->data ? offsetof(CPUHPPAState, cr[CR_IOR]) 26566797c315SNick Hudson : offsetof(CPUHPPAState, cr[CR_IIAOQ])); 26576797c315SNick Hudson tcg_gen_shli_i64(stl, stl, 32); 2658d265360fSRichard Henderson tcg_gen_or_i64(addr, atl, stl); 26596797c315SNick Hudson 26606797c315SNick Hudson reg = load_gpr(ctx, a->r); 26616797c315SNick Hudson if (a->addr) { 26628577f354SRichard Henderson gen_helper_itlba_pa11(tcg_env, addr, reg); 26636797c315SNick Hudson } else { 26648577f354SRichard Henderson gen_helper_itlbp_pa11(tcg_env, addr, reg); 26656797c315SNick Hudson } 26666797c315SNick Hudson 26676797c315SNick Hudson /* Exit TB for TLB change if mmu is enabled. */ 26686797c315SNick Hudson if (ctx->tb_flags & PSW_C) { 26696797c315SNick Hudson ctx->base.is_jmp = DISAS_IAQ_N_STALE; 26706797c315SNick Hudson } 26716797c315SNick Hudson return nullify_end(ctx); 26726797c315SNick Hudson #endif 26736797c315SNick Hudson } 26746797c315SNick Hudson 26758577f354SRichard Henderson static bool trans_ixtlbt(DisasContext *ctx, arg_ixtlbt *a) 26768577f354SRichard Henderson { 26778577f354SRichard Henderson if (!ctx->is_pa20) { 26788577f354SRichard Henderson return false; 26798577f354SRichard Henderson } 26808577f354SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 26818577f354SRichard Henderson #ifndef CONFIG_USER_ONLY 26828577f354SRichard Henderson nullify_over(ctx); 26838577f354SRichard Henderson { 26848577f354SRichard Henderson TCGv_i64 src1 = load_gpr(ctx, a->r1); 26858577f354SRichard Henderson TCGv_i64 src2 = load_gpr(ctx, a->r2); 26868577f354SRichard Henderson 26878577f354SRichard Henderson if (a->data) { 26888577f354SRichard Henderson gen_helper_idtlbt_pa20(tcg_env, src1, src2); 26898577f354SRichard Henderson } else { 26908577f354SRichard Henderson gen_helper_iitlbt_pa20(tcg_env, src1, src2); 26918577f354SRichard Henderson } 26928577f354SRichard Henderson } 26938577f354SRichard Henderson /* Exit TB for TLB change if mmu is enabled. */ 26948577f354SRichard Henderson if (ctx->tb_flags & PSW_C) { 26958577f354SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE; 26968577f354SRichard Henderson } 26978577f354SRichard Henderson return nullify_end(ctx); 26988577f354SRichard Henderson #endif 26998577f354SRichard Henderson } 27008577f354SRichard Henderson 2701deee69a1SRichard Henderson static bool trans_lpa(DisasContext *ctx, arg_ldst *a) 27022dfcca9fSRichard Henderson { 2703deee69a1SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 2704deee69a1SRichard Henderson #ifndef CONFIG_USER_ONLY 27056fd0c7bcSRichard Henderson TCGv_i64 vaddr; 27066fd0c7bcSRichard Henderson TCGv_i64 ofs, paddr; 27072dfcca9fSRichard Henderson 27082dfcca9fSRichard Henderson nullify_over(ctx); 27092dfcca9fSRichard Henderson 2710deee69a1SRichard Henderson form_gva(ctx, &vaddr, &ofs, a->b, a->x, 0, 0, a->sp, a->m, false); 27112dfcca9fSRichard Henderson 2712aac0f603SRichard Henderson paddr = tcg_temp_new_i64(); 2713ad75a51eSRichard Henderson gen_helper_lpa(paddr, tcg_env, vaddr); 27142dfcca9fSRichard Henderson 27152dfcca9fSRichard Henderson /* Note that physical address result overrides base modification. */ 2716deee69a1SRichard Henderson if (a->m) { 2717deee69a1SRichard Henderson save_gpr(ctx, a->b, ofs); 27182dfcca9fSRichard Henderson } 2719deee69a1SRichard Henderson save_gpr(ctx, a->t, paddr); 27202dfcca9fSRichard Henderson 272131234768SRichard Henderson return nullify_end(ctx); 2722deee69a1SRichard Henderson #endif 27232dfcca9fSRichard Henderson } 272443a97b81SRichard Henderson 2725deee69a1SRichard Henderson static bool trans_lci(DisasContext *ctx, arg_lci *a) 272643a97b81SRichard Henderson { 272743a97b81SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 272843a97b81SRichard Henderson 272943a97b81SRichard Henderson /* The Coherence Index is an implementation-defined function of the 273043a97b81SRichard Henderson physical address. Two addresses with the same CI have a coherent 273143a97b81SRichard Henderson view of the cache. Our implementation is to return 0 for all, 273243a97b81SRichard Henderson since the entire address space is coherent. */ 2733a4db4a78SRichard Henderson save_gpr(ctx, a->t, ctx->zero); 273443a97b81SRichard Henderson 2735e0137378SRichard Henderson ctx->null_cond = cond_make_f(); 273631234768SRichard Henderson return true; 273743a97b81SRichard Henderson } 273898a9cb79SRichard Henderson 2739faf97ba1SRichard Henderson static bool trans_add(DisasContext *ctx, arg_rrr_cf_d_sh *a) 2740b2167459SRichard Henderson { 27410c982a28SRichard Henderson return do_add_reg(ctx, a, false, false, false, false); 2742b2167459SRichard Henderson } 2743b2167459SRichard Henderson 2744faf97ba1SRichard Henderson static bool trans_add_l(DisasContext *ctx, arg_rrr_cf_d_sh *a) 2745b2167459SRichard Henderson { 27460c982a28SRichard Henderson return do_add_reg(ctx, a, true, false, false, false); 2747b2167459SRichard Henderson } 2748b2167459SRichard Henderson 2749faf97ba1SRichard Henderson static bool trans_add_tsv(DisasContext *ctx, arg_rrr_cf_d_sh *a) 2750b2167459SRichard Henderson { 27510c982a28SRichard Henderson return do_add_reg(ctx, a, false, true, false, false); 2752b2167459SRichard Henderson } 2753b2167459SRichard Henderson 2754faf97ba1SRichard Henderson static bool trans_add_c(DisasContext *ctx, arg_rrr_cf_d_sh *a) 2755b2167459SRichard Henderson { 27560c982a28SRichard Henderson return do_add_reg(ctx, a, false, false, false, true); 27570c982a28SRichard Henderson } 2758b2167459SRichard Henderson 2759faf97ba1SRichard Henderson static bool trans_add_c_tsv(DisasContext *ctx, arg_rrr_cf_d_sh *a) 27600c982a28SRichard Henderson { 27610c982a28SRichard Henderson return do_add_reg(ctx, a, false, true, false, true); 27620c982a28SRichard Henderson } 27630c982a28SRichard Henderson 276463c427c6SRichard Henderson static bool trans_sub(DisasContext *ctx, arg_rrr_cf_d *a) 27650c982a28SRichard Henderson { 27660c982a28SRichard Henderson return do_sub_reg(ctx, a, false, false, false); 27670c982a28SRichard Henderson } 27680c982a28SRichard Henderson 276963c427c6SRichard Henderson static bool trans_sub_tsv(DisasContext *ctx, arg_rrr_cf_d *a) 27700c982a28SRichard Henderson { 27710c982a28SRichard Henderson return do_sub_reg(ctx, a, true, false, false); 27720c982a28SRichard Henderson } 27730c982a28SRichard Henderson 277463c427c6SRichard Henderson static bool trans_sub_tc(DisasContext *ctx, arg_rrr_cf_d *a) 27750c982a28SRichard Henderson { 27760c982a28SRichard Henderson return do_sub_reg(ctx, a, false, false, true); 27770c982a28SRichard Henderson } 27780c982a28SRichard Henderson 277963c427c6SRichard Henderson static bool trans_sub_tsv_tc(DisasContext *ctx, arg_rrr_cf_d *a) 27800c982a28SRichard Henderson { 27810c982a28SRichard Henderson return do_sub_reg(ctx, a, true, false, true); 27820c982a28SRichard Henderson } 27830c982a28SRichard Henderson 278463c427c6SRichard Henderson static bool trans_sub_b(DisasContext *ctx, arg_rrr_cf_d *a) 27850c982a28SRichard Henderson { 27860c982a28SRichard Henderson return do_sub_reg(ctx, a, false, true, false); 27870c982a28SRichard Henderson } 27880c982a28SRichard Henderson 278963c427c6SRichard Henderson static bool trans_sub_b_tsv(DisasContext *ctx, arg_rrr_cf_d *a) 27900c982a28SRichard Henderson { 27910c982a28SRichard Henderson return do_sub_reg(ctx, a, true, true, false); 27920c982a28SRichard Henderson } 27930c982a28SRichard Henderson 2794fa8e3bedSRichard Henderson static bool trans_andcm(DisasContext *ctx, arg_rrr_cf_d *a) 27950c982a28SRichard Henderson { 27966fd0c7bcSRichard Henderson return do_log_reg(ctx, a, tcg_gen_andc_i64); 27970c982a28SRichard Henderson } 27980c982a28SRichard Henderson 2799fa8e3bedSRichard Henderson static bool trans_and(DisasContext *ctx, arg_rrr_cf_d *a) 28000c982a28SRichard Henderson { 28016fd0c7bcSRichard Henderson return do_log_reg(ctx, a, tcg_gen_and_i64); 28020c982a28SRichard Henderson } 28030c982a28SRichard Henderson 2804fa8e3bedSRichard Henderson static bool trans_or(DisasContext *ctx, arg_rrr_cf_d *a) 28050c982a28SRichard Henderson { 28060c982a28SRichard Henderson if (a->cf == 0) { 28070c982a28SRichard Henderson unsigned r2 = a->r2; 28080c982a28SRichard Henderson unsigned r1 = a->r1; 28090c982a28SRichard Henderson unsigned rt = a->t; 28100c982a28SRichard Henderson 28117aee8189SRichard Henderson if (rt == 0) { /* NOP */ 2812e0137378SRichard Henderson ctx->null_cond = cond_make_f(); 28137aee8189SRichard Henderson return true; 28147aee8189SRichard Henderson } 28157aee8189SRichard Henderson if (r2 == 0) { /* COPY */ 2816b2167459SRichard Henderson if (r1 == 0) { 28176fd0c7bcSRichard Henderson TCGv_i64 dest = dest_gpr(ctx, rt); 28186fd0c7bcSRichard Henderson tcg_gen_movi_i64(dest, 0); 2819b2167459SRichard Henderson save_gpr(ctx, rt, dest); 2820b2167459SRichard Henderson } else { 2821b2167459SRichard Henderson save_gpr(ctx, rt, cpu_gr[r1]); 2822b2167459SRichard Henderson } 2823e0137378SRichard Henderson ctx->null_cond = cond_make_f(); 282431234768SRichard Henderson return true; 2825b2167459SRichard Henderson } 28267aee8189SRichard Henderson #ifndef CONFIG_USER_ONLY 28277aee8189SRichard Henderson /* These are QEMU extensions and are nops in the real architecture: 28287aee8189SRichard Henderson * 28297aee8189SRichard Henderson * or %r10,%r10,%r10 -- idle loop; wait for interrupt 28307aee8189SRichard Henderson * or %r31,%r31,%r31 -- death loop; offline cpu 28317aee8189SRichard Henderson * currently implemented as idle. 28327aee8189SRichard Henderson */ 28337aee8189SRichard Henderson if ((rt == 10 || rt == 31) && r1 == rt && r2 == rt) { /* PAUSE */ 28347aee8189SRichard Henderson /* No need to check for supervisor, as userland can only pause 28357aee8189SRichard Henderson until the next timer interrupt. */ 2836*d27fe7c3SRichard Henderson 2837*d27fe7c3SRichard Henderson set_psw_xb(ctx, 0); 2838*d27fe7c3SRichard Henderson 28397aee8189SRichard Henderson nullify_over(ctx); 28407aee8189SRichard Henderson 28417aee8189SRichard Henderson /* Advance the instruction queue. */ 2842bc921866SRichard Henderson install_iaq_entries(ctx, &ctx->iaq_b, NULL); 28437aee8189SRichard Henderson nullify_set(ctx, 0); 28447aee8189SRichard Henderson 28457aee8189SRichard Henderson /* Tell the qemu main loop to halt until this cpu has work. */ 2846ad75a51eSRichard Henderson tcg_gen_st_i32(tcg_constant_i32(1), tcg_env, 284729dd6f64SRichard Henderson offsetof(CPUState, halted) - offsetof(HPPACPU, env)); 28487aee8189SRichard Henderson gen_excp_1(EXCP_HALTED); 28497aee8189SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 28507aee8189SRichard Henderson 28517aee8189SRichard Henderson return nullify_end(ctx); 28527aee8189SRichard Henderson } 28537aee8189SRichard Henderson #endif 28547aee8189SRichard Henderson } 28556fd0c7bcSRichard Henderson return do_log_reg(ctx, a, tcg_gen_or_i64); 28567aee8189SRichard Henderson } 2857b2167459SRichard Henderson 2858fa8e3bedSRichard Henderson static bool trans_xor(DisasContext *ctx, arg_rrr_cf_d *a) 2859b2167459SRichard Henderson { 28606fd0c7bcSRichard Henderson return do_log_reg(ctx, a, tcg_gen_xor_i64); 28610c982a28SRichard Henderson } 28620c982a28SRichard Henderson 2863345aa35fSRichard Henderson static bool trans_cmpclr(DisasContext *ctx, arg_rrr_cf_d *a) 28640c982a28SRichard Henderson { 28656fd0c7bcSRichard Henderson TCGv_i64 tcg_r1, tcg_r2; 2866b2167459SRichard Henderson 28670c982a28SRichard Henderson if (a->cf) { 2868b2167459SRichard Henderson nullify_over(ctx); 2869b2167459SRichard Henderson } 28700c982a28SRichard Henderson tcg_r1 = load_gpr(ctx, a->r1); 28710c982a28SRichard Henderson tcg_r2 = load_gpr(ctx, a->r2); 2872345aa35fSRichard Henderson do_cmpclr(ctx, a->t, tcg_r1, tcg_r2, a->cf, a->d); 287331234768SRichard Henderson return nullify_end(ctx); 2874b2167459SRichard Henderson } 2875b2167459SRichard Henderson 2876af240753SRichard Henderson static bool trans_uxor(DisasContext *ctx, arg_rrr_cf_d *a) 2877b2167459SRichard Henderson { 287846bb3d46SRichard Henderson TCGv_i64 tcg_r1, tcg_r2, dest; 2879b2167459SRichard Henderson 28800c982a28SRichard Henderson if (a->cf) { 2881b2167459SRichard Henderson nullify_over(ctx); 2882b2167459SRichard Henderson } 288346bb3d46SRichard Henderson 28840c982a28SRichard Henderson tcg_r1 = load_gpr(ctx, a->r1); 28850c982a28SRichard Henderson tcg_r2 = load_gpr(ctx, a->r2); 288646bb3d46SRichard Henderson dest = dest_gpr(ctx, a->t); 288746bb3d46SRichard Henderson 288846bb3d46SRichard Henderson tcg_gen_xor_i64(dest, tcg_r1, tcg_r2); 288946bb3d46SRichard Henderson save_gpr(ctx, a->t, dest); 289046bb3d46SRichard Henderson 289146bb3d46SRichard Henderson ctx->null_cond = do_unit_zero_cond(a->cf, a->d, dest); 289231234768SRichard Henderson return nullify_end(ctx); 2893b2167459SRichard Henderson } 2894b2167459SRichard Henderson 2895af240753SRichard Henderson static bool do_uaddcm(DisasContext *ctx, arg_rrr_cf_d *a, bool is_tc) 2896b2167459SRichard Henderson { 28976fd0c7bcSRichard Henderson TCGv_i64 tcg_r1, tcg_r2, tmp; 2898b2167459SRichard Henderson 2899ababac16SRichard Henderson if (a->cf == 0) { 2900ababac16SRichard Henderson tcg_r2 = load_gpr(ctx, a->r2); 2901ababac16SRichard Henderson tmp = dest_gpr(ctx, a->t); 2902ababac16SRichard Henderson 2903ababac16SRichard Henderson if (a->r1 == 0) { 2904ababac16SRichard Henderson /* UADDCM r0,src,dst is the common idiom for dst = ~src. */ 2905ababac16SRichard Henderson tcg_gen_not_i64(tmp, tcg_r2); 2906ababac16SRichard Henderson } else { 2907ababac16SRichard Henderson /* 2908ababac16SRichard Henderson * Recall that r1 - r2 == r1 + ~r2 + 1. 2909ababac16SRichard Henderson * Thus r1 + ~r2 == r1 - r2 - 1, 2910ababac16SRichard Henderson * which does not require an extra temporary. 2911ababac16SRichard Henderson */ 2912ababac16SRichard Henderson tcg_r1 = load_gpr(ctx, a->r1); 2913ababac16SRichard Henderson tcg_gen_sub_i64(tmp, tcg_r1, tcg_r2); 2914ababac16SRichard Henderson tcg_gen_subi_i64(tmp, tmp, 1); 2915b2167459SRichard Henderson } 2916ababac16SRichard Henderson save_gpr(ctx, a->t, tmp); 2917e0137378SRichard Henderson ctx->null_cond = cond_make_f(); 2918ababac16SRichard Henderson return true; 2919ababac16SRichard Henderson } 2920ababac16SRichard Henderson 2921ababac16SRichard Henderson nullify_over(ctx); 29220c982a28SRichard Henderson tcg_r1 = load_gpr(ctx, a->r1); 29230c982a28SRichard Henderson tcg_r2 = load_gpr(ctx, a->r2); 2924aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 29256fd0c7bcSRichard Henderson tcg_gen_not_i64(tmp, tcg_r2); 292646bb3d46SRichard Henderson do_unit_addsub(ctx, a->t, tcg_r1, tmp, a->cf, a->d, is_tc, true); 292731234768SRichard Henderson return nullify_end(ctx); 2928b2167459SRichard Henderson } 2929b2167459SRichard Henderson 2930af240753SRichard Henderson static bool trans_uaddcm(DisasContext *ctx, arg_rrr_cf_d *a) 2931b2167459SRichard Henderson { 29320c982a28SRichard Henderson return do_uaddcm(ctx, a, false); 29330c982a28SRichard Henderson } 29340c982a28SRichard Henderson 2935af240753SRichard Henderson static bool trans_uaddcm_tc(DisasContext *ctx, arg_rrr_cf_d *a) 29360c982a28SRichard Henderson { 29370c982a28SRichard Henderson return do_uaddcm(ctx, a, true); 29380c982a28SRichard Henderson } 29390c982a28SRichard Henderson 2940af240753SRichard Henderson static bool do_dcor(DisasContext *ctx, arg_rr_cf_d *a, bool is_i) 29410c982a28SRichard Henderson { 29426fd0c7bcSRichard Henderson TCGv_i64 tmp; 2943b2167459SRichard Henderson 2944b2167459SRichard Henderson nullify_over(ctx); 2945b2167459SRichard Henderson 2946aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 2947d0ae87a2SRichard Henderson tcg_gen_extract2_i64(tmp, cpu_psw_cb, cpu_psw_cb_msb, 4); 2948b2167459SRichard Henderson if (!is_i) { 29496fd0c7bcSRichard Henderson tcg_gen_not_i64(tmp, tmp); 2950b2167459SRichard Henderson } 29516fd0c7bcSRichard Henderson tcg_gen_andi_i64(tmp, tmp, (uint64_t)0x1111111111111111ull); 29526fd0c7bcSRichard Henderson tcg_gen_muli_i64(tmp, tmp, 6); 295346bb3d46SRichard Henderson do_unit_addsub(ctx, a->t, load_gpr(ctx, a->r), tmp, 295446bb3d46SRichard Henderson a->cf, a->d, false, is_i); 295531234768SRichard Henderson return nullify_end(ctx); 2956b2167459SRichard Henderson } 2957b2167459SRichard Henderson 2958af240753SRichard Henderson static bool trans_dcor(DisasContext *ctx, arg_rr_cf_d *a) 2959b2167459SRichard Henderson { 29600c982a28SRichard Henderson return do_dcor(ctx, a, false); 29610c982a28SRichard Henderson } 29620c982a28SRichard Henderson 2963af240753SRichard Henderson static bool trans_dcor_i(DisasContext *ctx, arg_rr_cf_d *a) 29640c982a28SRichard Henderson { 29650c982a28SRichard Henderson return do_dcor(ctx, a, true); 29660c982a28SRichard Henderson } 29670c982a28SRichard Henderson 29680c982a28SRichard Henderson static bool trans_ds(DisasContext *ctx, arg_rrr_cf *a) 29690c982a28SRichard Henderson { 2970a4db4a78SRichard Henderson TCGv_i64 dest, add1, add2, addc, in1, in2; 2971b2167459SRichard Henderson 2972b2167459SRichard Henderson nullify_over(ctx); 2973b2167459SRichard Henderson 29740c982a28SRichard Henderson in1 = load_gpr(ctx, a->r1); 29750c982a28SRichard Henderson in2 = load_gpr(ctx, a->r2); 2976b2167459SRichard Henderson 2977aac0f603SRichard Henderson add1 = tcg_temp_new_i64(); 2978aac0f603SRichard Henderson add2 = tcg_temp_new_i64(); 2979aac0f603SRichard Henderson addc = tcg_temp_new_i64(); 2980aac0f603SRichard Henderson dest = tcg_temp_new_i64(); 2981b2167459SRichard Henderson 2982b2167459SRichard Henderson /* Form R1 << 1 | PSW[CB]{8}. */ 29836fd0c7bcSRichard Henderson tcg_gen_add_i64(add1, in1, in1); 29846fd0c7bcSRichard Henderson tcg_gen_add_i64(add1, add1, get_psw_carry(ctx, false)); 2985b2167459SRichard Henderson 298672ca8753SRichard Henderson /* 298772ca8753SRichard Henderson * Add or subtract R2, depending on PSW[V]. Proper computation of 298872ca8753SRichard Henderson * carry requires that we subtract via + ~R2 + 1, as described in 298972ca8753SRichard Henderson * the manual. By extracting and masking V, we can produce the 299072ca8753SRichard Henderson * proper inputs to the addition without movcond. 299172ca8753SRichard Henderson */ 29926fd0c7bcSRichard Henderson tcg_gen_sextract_i64(addc, cpu_psw_v, 31, 1); 29936fd0c7bcSRichard Henderson tcg_gen_xor_i64(add2, in2, addc); 29946fd0c7bcSRichard Henderson tcg_gen_andi_i64(addc, addc, 1); 299572ca8753SRichard Henderson 2996a4db4a78SRichard Henderson tcg_gen_add2_i64(dest, cpu_psw_cb_msb, add1, ctx->zero, add2, ctx->zero); 2997a4db4a78SRichard Henderson tcg_gen_add2_i64(dest, cpu_psw_cb_msb, dest, cpu_psw_cb_msb, 2998a4db4a78SRichard Henderson addc, ctx->zero); 2999b2167459SRichard Henderson 3000b2167459SRichard Henderson /* Write back the result register. */ 30010c982a28SRichard Henderson save_gpr(ctx, a->t, dest); 3002b2167459SRichard Henderson 3003b2167459SRichard Henderson /* Write back PSW[CB]. */ 30046fd0c7bcSRichard Henderson tcg_gen_xor_i64(cpu_psw_cb, add1, add2); 30056fd0c7bcSRichard Henderson tcg_gen_xor_i64(cpu_psw_cb, cpu_psw_cb, dest); 3006b2167459SRichard Henderson 3007f8f5986eSRichard Henderson /* 3008f8f5986eSRichard Henderson * Write back PSW[V] for the division step. 3009f8f5986eSRichard Henderson * Shift cb{8} from where it lives in bit 32 to bit 31, 3010f8f5986eSRichard Henderson * so that it overlaps r2{32} in bit 31. 3011f8f5986eSRichard Henderson */ 3012f8f5986eSRichard Henderson tcg_gen_shri_i64(cpu_psw_v, cpu_psw_cb, 1); 30136fd0c7bcSRichard Henderson tcg_gen_xor_i64(cpu_psw_v, cpu_psw_v, in2); 3014b2167459SRichard Henderson 3015b2167459SRichard Henderson /* Install the new nullification. */ 30160c982a28SRichard Henderson if (a->cf) { 3017f8f5986eSRichard Henderson TCGv_i64 sv = NULL, uv = NULL; 3018b47a4a02SSven Schnelle if (cond_need_sv(a->cf >> 1)) { 3019f8f5986eSRichard Henderson sv = do_add_sv(ctx, dest, add1, add2, in1, 1, false); 3020f8f5986eSRichard Henderson } else if (cond_need_cb(a->cf >> 1)) { 3021f8f5986eSRichard Henderson uv = do_add_uv(ctx, cpu_psw_cb, NULL, in1, 1, false); 3022b2167459SRichard Henderson } 3023f8f5986eSRichard Henderson ctx->null_cond = do_cond(ctx, a->cf, false, dest, uv, sv); 3024b2167459SRichard Henderson } 3025b2167459SRichard Henderson 302631234768SRichard Henderson return nullify_end(ctx); 3027b2167459SRichard Henderson } 3028b2167459SRichard Henderson 30290588e061SRichard Henderson static bool trans_addi(DisasContext *ctx, arg_rri_cf *a) 3030b2167459SRichard Henderson { 30310588e061SRichard Henderson return do_add_imm(ctx, a, false, false); 30320588e061SRichard Henderson } 30330588e061SRichard Henderson 30340588e061SRichard Henderson static bool trans_addi_tsv(DisasContext *ctx, arg_rri_cf *a) 30350588e061SRichard Henderson { 30360588e061SRichard Henderson return do_add_imm(ctx, a, true, false); 30370588e061SRichard Henderson } 30380588e061SRichard Henderson 30390588e061SRichard Henderson static bool trans_addi_tc(DisasContext *ctx, arg_rri_cf *a) 30400588e061SRichard Henderson { 30410588e061SRichard Henderson return do_add_imm(ctx, a, false, true); 30420588e061SRichard Henderson } 30430588e061SRichard Henderson 30440588e061SRichard Henderson static bool trans_addi_tc_tsv(DisasContext *ctx, arg_rri_cf *a) 30450588e061SRichard Henderson { 30460588e061SRichard Henderson return do_add_imm(ctx, a, true, true); 30470588e061SRichard Henderson } 30480588e061SRichard Henderson 30490588e061SRichard Henderson static bool trans_subi(DisasContext *ctx, arg_rri_cf *a) 30500588e061SRichard Henderson { 30510588e061SRichard Henderson return do_sub_imm(ctx, a, false); 30520588e061SRichard Henderson } 30530588e061SRichard Henderson 30540588e061SRichard Henderson static bool trans_subi_tsv(DisasContext *ctx, arg_rri_cf *a) 30550588e061SRichard Henderson { 30560588e061SRichard Henderson return do_sub_imm(ctx, a, true); 30570588e061SRichard Henderson } 30580588e061SRichard Henderson 3059345aa35fSRichard Henderson static bool trans_cmpiclr(DisasContext *ctx, arg_rri_cf_d *a) 30600588e061SRichard Henderson { 30616fd0c7bcSRichard Henderson TCGv_i64 tcg_im, tcg_r2; 3062b2167459SRichard Henderson 30630588e061SRichard Henderson if (a->cf) { 3064b2167459SRichard Henderson nullify_over(ctx); 3065b2167459SRichard Henderson } 3066b2167459SRichard Henderson 30676fd0c7bcSRichard Henderson tcg_im = tcg_constant_i64(a->i); 30680588e061SRichard Henderson tcg_r2 = load_gpr(ctx, a->r); 3069345aa35fSRichard Henderson do_cmpclr(ctx, a->t, tcg_im, tcg_r2, a->cf, a->d); 3070b2167459SRichard Henderson 307131234768SRichard Henderson return nullify_end(ctx); 3072b2167459SRichard Henderson } 3073b2167459SRichard Henderson 30740843563fSRichard Henderson static bool do_multimedia(DisasContext *ctx, arg_rrr *a, 30750843563fSRichard Henderson void (*fn)(TCGv_i64, TCGv_i64, TCGv_i64)) 30760843563fSRichard Henderson { 30770843563fSRichard Henderson TCGv_i64 r1, r2, dest; 30780843563fSRichard Henderson 30790843563fSRichard Henderson if (!ctx->is_pa20) { 30800843563fSRichard Henderson return false; 30810843563fSRichard Henderson } 30820843563fSRichard Henderson 30830843563fSRichard Henderson nullify_over(ctx); 30840843563fSRichard Henderson 30850843563fSRichard Henderson r1 = load_gpr(ctx, a->r1); 30860843563fSRichard Henderson r2 = load_gpr(ctx, a->r2); 30870843563fSRichard Henderson dest = dest_gpr(ctx, a->t); 30880843563fSRichard Henderson 30890843563fSRichard Henderson fn(dest, r1, r2); 30900843563fSRichard Henderson save_gpr(ctx, a->t, dest); 30910843563fSRichard Henderson 30920843563fSRichard Henderson return nullify_end(ctx); 30930843563fSRichard Henderson } 30940843563fSRichard Henderson 3095151f309bSRichard Henderson static bool do_multimedia_sh(DisasContext *ctx, arg_rri *a, 3096151f309bSRichard Henderson void (*fn)(TCGv_i64, TCGv_i64, int64_t)) 3097151f309bSRichard Henderson { 3098151f309bSRichard Henderson TCGv_i64 r, dest; 3099151f309bSRichard Henderson 3100151f309bSRichard Henderson if (!ctx->is_pa20) { 3101151f309bSRichard Henderson return false; 3102151f309bSRichard Henderson } 3103151f309bSRichard Henderson 3104151f309bSRichard Henderson nullify_over(ctx); 3105151f309bSRichard Henderson 3106151f309bSRichard Henderson r = load_gpr(ctx, a->r); 3107151f309bSRichard Henderson dest = dest_gpr(ctx, a->t); 3108151f309bSRichard Henderson 3109151f309bSRichard Henderson fn(dest, r, a->i); 3110151f309bSRichard Henderson save_gpr(ctx, a->t, dest); 3111151f309bSRichard Henderson 3112151f309bSRichard Henderson return nullify_end(ctx); 3113151f309bSRichard Henderson } 3114151f309bSRichard Henderson 31153bbb8e48SRichard Henderson static bool do_multimedia_shadd(DisasContext *ctx, arg_rrr_sh *a, 31163bbb8e48SRichard Henderson void (*fn)(TCGv_i64, TCGv_i64, 31173bbb8e48SRichard Henderson TCGv_i64, TCGv_i32)) 31183bbb8e48SRichard Henderson { 31193bbb8e48SRichard Henderson TCGv_i64 r1, r2, dest; 31203bbb8e48SRichard Henderson 31213bbb8e48SRichard Henderson if (!ctx->is_pa20) { 31223bbb8e48SRichard Henderson return false; 31233bbb8e48SRichard Henderson } 31243bbb8e48SRichard Henderson 31253bbb8e48SRichard Henderson nullify_over(ctx); 31263bbb8e48SRichard Henderson 31273bbb8e48SRichard Henderson r1 = load_gpr(ctx, a->r1); 31283bbb8e48SRichard Henderson r2 = load_gpr(ctx, a->r2); 31293bbb8e48SRichard Henderson dest = dest_gpr(ctx, a->t); 31303bbb8e48SRichard Henderson 31313bbb8e48SRichard Henderson fn(dest, r1, r2, tcg_constant_i32(a->sh)); 31323bbb8e48SRichard Henderson save_gpr(ctx, a->t, dest); 31333bbb8e48SRichard Henderson 31343bbb8e48SRichard Henderson return nullify_end(ctx); 31353bbb8e48SRichard Henderson } 31363bbb8e48SRichard Henderson 31370843563fSRichard Henderson static bool trans_hadd(DisasContext *ctx, arg_rrr *a) 31380843563fSRichard Henderson { 31390843563fSRichard Henderson return do_multimedia(ctx, a, tcg_gen_vec_add16_i64); 31400843563fSRichard Henderson } 31410843563fSRichard Henderson 31420843563fSRichard Henderson static bool trans_hadd_ss(DisasContext *ctx, arg_rrr *a) 31430843563fSRichard Henderson { 31440843563fSRichard Henderson return do_multimedia(ctx, a, gen_helper_hadd_ss); 31450843563fSRichard Henderson } 31460843563fSRichard Henderson 31470843563fSRichard Henderson static bool trans_hadd_us(DisasContext *ctx, arg_rrr *a) 31480843563fSRichard Henderson { 31490843563fSRichard Henderson return do_multimedia(ctx, a, gen_helper_hadd_us); 31500843563fSRichard Henderson } 31510843563fSRichard Henderson 31521b3cb7c8SRichard Henderson static bool trans_havg(DisasContext *ctx, arg_rrr *a) 31531b3cb7c8SRichard Henderson { 31541b3cb7c8SRichard Henderson return do_multimedia(ctx, a, gen_helper_havg); 31551b3cb7c8SRichard Henderson } 31561b3cb7c8SRichard Henderson 3157151f309bSRichard Henderson static bool trans_hshl(DisasContext *ctx, arg_rri *a) 3158151f309bSRichard Henderson { 3159151f309bSRichard Henderson return do_multimedia_sh(ctx, a, tcg_gen_vec_shl16i_i64); 3160151f309bSRichard Henderson } 3161151f309bSRichard Henderson 3162151f309bSRichard Henderson static bool trans_hshr_s(DisasContext *ctx, arg_rri *a) 3163151f309bSRichard Henderson { 3164151f309bSRichard Henderson return do_multimedia_sh(ctx, a, tcg_gen_vec_sar16i_i64); 3165151f309bSRichard Henderson } 3166151f309bSRichard Henderson 3167151f309bSRichard Henderson static bool trans_hshr_u(DisasContext *ctx, arg_rri *a) 3168151f309bSRichard Henderson { 3169151f309bSRichard Henderson return do_multimedia_sh(ctx, a, tcg_gen_vec_shr16i_i64); 3170151f309bSRichard Henderson } 3171151f309bSRichard Henderson 31723bbb8e48SRichard Henderson static bool trans_hshladd(DisasContext *ctx, arg_rrr_sh *a) 31733bbb8e48SRichard Henderson { 31743bbb8e48SRichard Henderson return do_multimedia_shadd(ctx, a, gen_helper_hshladd); 31753bbb8e48SRichard Henderson } 31763bbb8e48SRichard Henderson 31773bbb8e48SRichard Henderson static bool trans_hshradd(DisasContext *ctx, arg_rrr_sh *a) 31783bbb8e48SRichard Henderson { 31793bbb8e48SRichard Henderson return do_multimedia_shadd(ctx, a, gen_helper_hshradd); 31803bbb8e48SRichard Henderson } 31813bbb8e48SRichard Henderson 318210c9e58dSRichard Henderson static bool trans_hsub(DisasContext *ctx, arg_rrr *a) 318310c9e58dSRichard Henderson { 318410c9e58dSRichard Henderson return do_multimedia(ctx, a, tcg_gen_vec_sub16_i64); 318510c9e58dSRichard Henderson } 318610c9e58dSRichard Henderson 318710c9e58dSRichard Henderson static bool trans_hsub_ss(DisasContext *ctx, arg_rrr *a) 318810c9e58dSRichard Henderson { 318910c9e58dSRichard Henderson return do_multimedia(ctx, a, gen_helper_hsub_ss); 319010c9e58dSRichard Henderson } 319110c9e58dSRichard Henderson 319210c9e58dSRichard Henderson static bool trans_hsub_us(DisasContext *ctx, arg_rrr *a) 319310c9e58dSRichard Henderson { 319410c9e58dSRichard Henderson return do_multimedia(ctx, a, gen_helper_hsub_us); 319510c9e58dSRichard Henderson } 319610c9e58dSRichard Henderson 3197c2a7ee3fSRichard Henderson static void gen_mixh_l(TCGv_i64 dst, TCGv_i64 r1, TCGv_i64 r2) 3198c2a7ee3fSRichard Henderson { 3199c2a7ee3fSRichard Henderson uint64_t mask = 0xffff0000ffff0000ull; 3200c2a7ee3fSRichard Henderson TCGv_i64 tmp = tcg_temp_new_i64(); 3201c2a7ee3fSRichard Henderson 3202c2a7ee3fSRichard Henderson tcg_gen_andi_i64(tmp, r2, mask); 3203c2a7ee3fSRichard Henderson tcg_gen_andi_i64(dst, r1, mask); 3204c2a7ee3fSRichard Henderson tcg_gen_shri_i64(tmp, tmp, 16); 3205c2a7ee3fSRichard Henderson tcg_gen_or_i64(dst, dst, tmp); 3206c2a7ee3fSRichard Henderson } 3207c2a7ee3fSRichard Henderson 3208c2a7ee3fSRichard Henderson static bool trans_mixh_l(DisasContext *ctx, arg_rrr *a) 3209c2a7ee3fSRichard Henderson { 3210c2a7ee3fSRichard Henderson return do_multimedia(ctx, a, gen_mixh_l); 3211c2a7ee3fSRichard Henderson } 3212c2a7ee3fSRichard Henderson 3213c2a7ee3fSRichard Henderson static void gen_mixh_r(TCGv_i64 dst, TCGv_i64 r1, TCGv_i64 r2) 3214c2a7ee3fSRichard Henderson { 3215c2a7ee3fSRichard Henderson uint64_t mask = 0x0000ffff0000ffffull; 3216c2a7ee3fSRichard Henderson TCGv_i64 tmp = tcg_temp_new_i64(); 3217c2a7ee3fSRichard Henderson 3218c2a7ee3fSRichard Henderson tcg_gen_andi_i64(tmp, r1, mask); 3219c2a7ee3fSRichard Henderson tcg_gen_andi_i64(dst, r2, mask); 3220c2a7ee3fSRichard Henderson tcg_gen_shli_i64(tmp, tmp, 16); 3221c2a7ee3fSRichard Henderson tcg_gen_or_i64(dst, dst, tmp); 3222c2a7ee3fSRichard Henderson } 3223c2a7ee3fSRichard Henderson 3224c2a7ee3fSRichard Henderson static bool trans_mixh_r(DisasContext *ctx, arg_rrr *a) 3225c2a7ee3fSRichard Henderson { 3226c2a7ee3fSRichard Henderson return do_multimedia(ctx, a, gen_mixh_r); 3227c2a7ee3fSRichard Henderson } 3228c2a7ee3fSRichard Henderson 3229c2a7ee3fSRichard Henderson static void gen_mixw_l(TCGv_i64 dst, TCGv_i64 r1, TCGv_i64 r2) 3230c2a7ee3fSRichard Henderson { 3231c2a7ee3fSRichard Henderson TCGv_i64 tmp = tcg_temp_new_i64(); 3232c2a7ee3fSRichard Henderson 3233c2a7ee3fSRichard Henderson tcg_gen_shri_i64(tmp, r2, 32); 3234c2a7ee3fSRichard Henderson tcg_gen_deposit_i64(dst, r1, tmp, 0, 32); 3235c2a7ee3fSRichard Henderson } 3236c2a7ee3fSRichard Henderson 3237c2a7ee3fSRichard Henderson static bool trans_mixw_l(DisasContext *ctx, arg_rrr *a) 3238c2a7ee3fSRichard Henderson { 3239c2a7ee3fSRichard Henderson return do_multimedia(ctx, a, gen_mixw_l); 3240c2a7ee3fSRichard Henderson } 3241c2a7ee3fSRichard Henderson 3242c2a7ee3fSRichard Henderson static void gen_mixw_r(TCGv_i64 dst, TCGv_i64 r1, TCGv_i64 r2) 3243c2a7ee3fSRichard Henderson { 3244c2a7ee3fSRichard Henderson tcg_gen_deposit_i64(dst, r2, r1, 32, 32); 3245c2a7ee3fSRichard Henderson } 3246c2a7ee3fSRichard Henderson 3247c2a7ee3fSRichard Henderson static bool trans_mixw_r(DisasContext *ctx, arg_rrr *a) 3248c2a7ee3fSRichard Henderson { 3249c2a7ee3fSRichard Henderson return do_multimedia(ctx, a, gen_mixw_r); 3250c2a7ee3fSRichard Henderson } 3251c2a7ee3fSRichard Henderson 32524e7abdb1SRichard Henderson static bool trans_permh(DisasContext *ctx, arg_permh *a) 32534e7abdb1SRichard Henderson { 32544e7abdb1SRichard Henderson TCGv_i64 r, t0, t1, t2, t3; 32554e7abdb1SRichard Henderson 32564e7abdb1SRichard Henderson if (!ctx->is_pa20) { 32574e7abdb1SRichard Henderson return false; 32584e7abdb1SRichard Henderson } 32594e7abdb1SRichard Henderson 32604e7abdb1SRichard Henderson nullify_over(ctx); 32614e7abdb1SRichard Henderson 32624e7abdb1SRichard Henderson r = load_gpr(ctx, a->r1); 32634e7abdb1SRichard Henderson t0 = tcg_temp_new_i64(); 32644e7abdb1SRichard Henderson t1 = tcg_temp_new_i64(); 32654e7abdb1SRichard Henderson t2 = tcg_temp_new_i64(); 32664e7abdb1SRichard Henderson t3 = tcg_temp_new_i64(); 32674e7abdb1SRichard Henderson 32684e7abdb1SRichard Henderson tcg_gen_extract_i64(t0, r, (3 - a->c0) * 16, 16); 32694e7abdb1SRichard Henderson tcg_gen_extract_i64(t1, r, (3 - a->c1) * 16, 16); 32704e7abdb1SRichard Henderson tcg_gen_extract_i64(t2, r, (3 - a->c2) * 16, 16); 32714e7abdb1SRichard Henderson tcg_gen_extract_i64(t3, r, (3 - a->c3) * 16, 16); 32724e7abdb1SRichard Henderson 32734e7abdb1SRichard Henderson tcg_gen_deposit_i64(t0, t1, t0, 16, 48); 32744e7abdb1SRichard Henderson tcg_gen_deposit_i64(t2, t3, t2, 16, 48); 32754e7abdb1SRichard Henderson tcg_gen_deposit_i64(t0, t2, t0, 32, 32); 32764e7abdb1SRichard Henderson 32774e7abdb1SRichard Henderson save_gpr(ctx, a->t, t0); 32784e7abdb1SRichard Henderson return nullify_end(ctx); 32794e7abdb1SRichard Henderson } 32804e7abdb1SRichard Henderson 32811cd012a5SRichard Henderson static bool trans_ld(DisasContext *ctx, arg_ldst *a) 328296d6407fSRichard Henderson { 3283b5caa17cSRichard Henderson if (ctx->is_pa20) { 3284b5caa17cSRichard Henderson /* 3285b5caa17cSRichard Henderson * With pa20, LDB, LDH, LDW, LDD to %g0 are prefetches. 3286b5caa17cSRichard Henderson * Any base modification still occurs. 3287b5caa17cSRichard Henderson */ 3288b5caa17cSRichard Henderson if (a->t == 0) { 3289b5caa17cSRichard Henderson return trans_nop_addrx(ctx, a); 3290b5caa17cSRichard Henderson } 3291b5caa17cSRichard Henderson } else if (a->size > MO_32) { 32920786a3b6SHelge Deller return gen_illegal(ctx); 3293c53e401eSRichard Henderson } 32941cd012a5SRichard Henderson return do_load(ctx, a->t, a->b, a->x, a->scale ? a->size : 0, 32951cd012a5SRichard Henderson a->disp, a->sp, a->m, a->size | MO_TE); 329696d6407fSRichard Henderson } 329796d6407fSRichard Henderson 32981cd012a5SRichard Henderson static bool trans_st(DisasContext *ctx, arg_ldst *a) 329996d6407fSRichard Henderson { 33001cd012a5SRichard Henderson assert(a->x == 0 && a->scale == 0); 3301c53e401eSRichard Henderson if (!ctx->is_pa20 && a->size > MO_32) { 33020786a3b6SHelge Deller return gen_illegal(ctx); 330396d6407fSRichard Henderson } 3304c53e401eSRichard Henderson return do_store(ctx, a->t, a->b, a->disp, a->sp, a->m, a->size | MO_TE); 33050786a3b6SHelge Deller } 330696d6407fSRichard Henderson 33071cd012a5SRichard Henderson static bool trans_ldc(DisasContext *ctx, arg_ldst *a) 330896d6407fSRichard Henderson { 3309b1af755cSRichard Henderson MemOp mop = MO_TE | MO_ALIGN | a->size; 3310a4db4a78SRichard Henderson TCGv_i64 dest, ofs; 33116fd0c7bcSRichard Henderson TCGv_i64 addr; 331296d6407fSRichard Henderson 3313c53e401eSRichard Henderson if (!ctx->is_pa20 && a->size > MO_32) { 331451416c4eSRichard Henderson return gen_illegal(ctx); 331551416c4eSRichard Henderson } 331651416c4eSRichard Henderson 331796d6407fSRichard Henderson nullify_over(ctx); 331896d6407fSRichard Henderson 33191cd012a5SRichard Henderson if (a->m) { 332086f8d05fSRichard Henderson /* Base register modification. Make sure if RT == RB, 332186f8d05fSRichard Henderson we see the result of the load. */ 3322aac0f603SRichard Henderson dest = tcg_temp_new_i64(); 332396d6407fSRichard Henderson } else { 33241cd012a5SRichard Henderson dest = dest_gpr(ctx, a->t); 332596d6407fSRichard Henderson } 332696d6407fSRichard Henderson 3327c3ea1996SSven Schnelle form_gva(ctx, &addr, &ofs, a->b, a->x, a->scale ? 3 : 0, 332817fe594cSRichard Henderson a->disp, a->sp, a->m, MMU_DISABLED(ctx)); 3329b1af755cSRichard Henderson 3330b1af755cSRichard Henderson /* 3331b1af755cSRichard Henderson * For hppa1.1, LDCW is undefined unless aligned mod 16. 3332b1af755cSRichard Henderson * However actual hardware succeeds with aligned mod 4. 3333b1af755cSRichard Henderson * Detect this case and log a GUEST_ERROR. 3334b1af755cSRichard Henderson * 3335b1af755cSRichard Henderson * TODO: HPPA64 relaxes the over-alignment requirement 3336b1af755cSRichard Henderson * with the ,co completer. 3337b1af755cSRichard Henderson */ 3338b1af755cSRichard Henderson gen_helper_ldc_check(addr); 3339b1af755cSRichard Henderson 3340a4db4a78SRichard Henderson tcg_gen_atomic_xchg_i64(dest, addr, ctx->zero, ctx->mmu_idx, mop); 3341b1af755cSRichard Henderson 33421cd012a5SRichard Henderson if (a->m) { 33431cd012a5SRichard Henderson save_gpr(ctx, a->b, ofs); 334496d6407fSRichard Henderson } 33451cd012a5SRichard Henderson save_gpr(ctx, a->t, dest); 334696d6407fSRichard Henderson 334731234768SRichard Henderson return nullify_end(ctx); 334896d6407fSRichard Henderson } 334996d6407fSRichard Henderson 33501cd012a5SRichard Henderson static bool trans_stby(DisasContext *ctx, arg_stby *a) 335196d6407fSRichard Henderson { 33526fd0c7bcSRichard Henderson TCGv_i64 ofs, val; 33536fd0c7bcSRichard Henderson TCGv_i64 addr; 335496d6407fSRichard Henderson 335596d6407fSRichard Henderson nullify_over(ctx); 335696d6407fSRichard Henderson 33571cd012a5SRichard Henderson form_gva(ctx, &addr, &ofs, a->b, 0, 0, a->disp, a->sp, a->m, 335817fe594cSRichard Henderson MMU_DISABLED(ctx)); 33591cd012a5SRichard Henderson val = load_gpr(ctx, a->r); 33601cd012a5SRichard Henderson if (a->a) { 3361f9f46db4SEmilio G. Cota if (tb_cflags(ctx->base.tb) & CF_PARALLEL) { 3362ad75a51eSRichard Henderson gen_helper_stby_e_parallel(tcg_env, addr, val); 3363f9f46db4SEmilio G. Cota } else { 3364ad75a51eSRichard Henderson gen_helper_stby_e(tcg_env, addr, val); 3365f9f46db4SEmilio G. Cota } 3366f9f46db4SEmilio G. Cota } else { 3367f9f46db4SEmilio G. Cota if (tb_cflags(ctx->base.tb) & CF_PARALLEL) { 3368ad75a51eSRichard Henderson gen_helper_stby_b_parallel(tcg_env, addr, val); 336996d6407fSRichard Henderson } else { 3370ad75a51eSRichard Henderson gen_helper_stby_b(tcg_env, addr, val); 337196d6407fSRichard Henderson } 3372f9f46db4SEmilio G. Cota } 33731cd012a5SRichard Henderson if (a->m) { 33746fd0c7bcSRichard Henderson tcg_gen_andi_i64(ofs, ofs, ~3); 33751cd012a5SRichard Henderson save_gpr(ctx, a->b, ofs); 337696d6407fSRichard Henderson } 337796d6407fSRichard Henderson 337831234768SRichard Henderson return nullify_end(ctx); 337996d6407fSRichard Henderson } 338096d6407fSRichard Henderson 338125460fc5SRichard Henderson static bool trans_stdby(DisasContext *ctx, arg_stby *a) 338225460fc5SRichard Henderson { 33836fd0c7bcSRichard Henderson TCGv_i64 ofs, val; 33846fd0c7bcSRichard Henderson TCGv_i64 addr; 338525460fc5SRichard Henderson 338625460fc5SRichard Henderson if (!ctx->is_pa20) { 338725460fc5SRichard Henderson return false; 338825460fc5SRichard Henderson } 338925460fc5SRichard Henderson nullify_over(ctx); 339025460fc5SRichard Henderson 339125460fc5SRichard Henderson form_gva(ctx, &addr, &ofs, a->b, 0, 0, a->disp, a->sp, a->m, 339217fe594cSRichard Henderson MMU_DISABLED(ctx)); 339325460fc5SRichard Henderson val = load_gpr(ctx, a->r); 339425460fc5SRichard Henderson if (a->a) { 339525460fc5SRichard Henderson if (tb_cflags(ctx->base.tb) & CF_PARALLEL) { 339625460fc5SRichard Henderson gen_helper_stdby_e_parallel(tcg_env, addr, val); 339725460fc5SRichard Henderson } else { 339825460fc5SRichard Henderson gen_helper_stdby_e(tcg_env, addr, val); 339925460fc5SRichard Henderson } 340025460fc5SRichard Henderson } else { 340125460fc5SRichard Henderson if (tb_cflags(ctx->base.tb) & CF_PARALLEL) { 340225460fc5SRichard Henderson gen_helper_stdby_b_parallel(tcg_env, addr, val); 340325460fc5SRichard Henderson } else { 340425460fc5SRichard Henderson gen_helper_stdby_b(tcg_env, addr, val); 340525460fc5SRichard Henderson } 340625460fc5SRichard Henderson } 340725460fc5SRichard Henderson if (a->m) { 34086fd0c7bcSRichard Henderson tcg_gen_andi_i64(ofs, ofs, ~7); 340925460fc5SRichard Henderson save_gpr(ctx, a->b, ofs); 341025460fc5SRichard Henderson } 341125460fc5SRichard Henderson 341225460fc5SRichard Henderson return nullify_end(ctx); 341325460fc5SRichard Henderson } 341425460fc5SRichard Henderson 34151cd012a5SRichard Henderson static bool trans_lda(DisasContext *ctx, arg_ldst *a) 3416d0a851ccSRichard Henderson { 3417d0a851ccSRichard Henderson int hold_mmu_idx = ctx->mmu_idx; 3418d0a851ccSRichard Henderson 3419d0a851ccSRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 3420451d993dSRichard Henderson ctx->mmu_idx = ctx->tb_flags & PSW_W ? MMU_ABS_W_IDX : MMU_ABS_IDX; 34211cd012a5SRichard Henderson trans_ld(ctx, a); 3422d0a851ccSRichard Henderson ctx->mmu_idx = hold_mmu_idx; 342331234768SRichard Henderson return true; 3424d0a851ccSRichard Henderson } 3425d0a851ccSRichard Henderson 34261cd012a5SRichard Henderson static bool trans_sta(DisasContext *ctx, arg_ldst *a) 3427d0a851ccSRichard Henderson { 3428d0a851ccSRichard Henderson int hold_mmu_idx = ctx->mmu_idx; 3429d0a851ccSRichard Henderson 3430d0a851ccSRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 3431451d993dSRichard Henderson ctx->mmu_idx = ctx->tb_flags & PSW_W ? MMU_ABS_W_IDX : MMU_ABS_IDX; 34321cd012a5SRichard Henderson trans_st(ctx, a); 3433d0a851ccSRichard Henderson ctx->mmu_idx = hold_mmu_idx; 343431234768SRichard Henderson return true; 3435d0a851ccSRichard Henderson } 343695412a61SRichard Henderson 34370588e061SRichard Henderson static bool trans_ldil(DisasContext *ctx, arg_ldil *a) 3438b2167459SRichard Henderson { 34396fd0c7bcSRichard Henderson TCGv_i64 tcg_rt = dest_gpr(ctx, a->t); 3440b2167459SRichard Henderson 34416fd0c7bcSRichard Henderson tcg_gen_movi_i64(tcg_rt, a->i); 34420588e061SRichard Henderson save_gpr(ctx, a->t, tcg_rt); 3443e0137378SRichard Henderson ctx->null_cond = cond_make_f(); 344431234768SRichard Henderson return true; 3445b2167459SRichard Henderson } 3446b2167459SRichard Henderson 34470588e061SRichard Henderson static bool trans_addil(DisasContext *ctx, arg_addil *a) 3448b2167459SRichard Henderson { 34496fd0c7bcSRichard Henderson TCGv_i64 tcg_rt = load_gpr(ctx, a->r); 34506fd0c7bcSRichard Henderson TCGv_i64 tcg_r1 = dest_gpr(ctx, 1); 3451b2167459SRichard Henderson 34526fd0c7bcSRichard Henderson tcg_gen_addi_i64(tcg_r1, tcg_rt, a->i); 3453b2167459SRichard Henderson save_gpr(ctx, 1, tcg_r1); 3454e0137378SRichard Henderson ctx->null_cond = cond_make_f(); 345531234768SRichard Henderson return true; 3456b2167459SRichard Henderson } 3457b2167459SRichard Henderson 34580588e061SRichard Henderson static bool trans_ldo(DisasContext *ctx, arg_ldo *a) 3459b2167459SRichard Henderson { 34606fd0c7bcSRichard Henderson TCGv_i64 tcg_rt = dest_gpr(ctx, a->t); 3461b2167459SRichard Henderson 3462b2167459SRichard Henderson /* Special case rb == 0, for the LDI pseudo-op. 3463d265360fSRichard Henderson The COPY pseudo-op is handled for free within tcg_gen_addi_i64. */ 34640588e061SRichard Henderson if (a->b == 0) { 34656fd0c7bcSRichard Henderson tcg_gen_movi_i64(tcg_rt, a->i); 3466b2167459SRichard Henderson } else { 34676fd0c7bcSRichard Henderson tcg_gen_addi_i64(tcg_rt, cpu_gr[a->b], a->i); 3468b2167459SRichard Henderson } 34690588e061SRichard Henderson save_gpr(ctx, a->t, tcg_rt); 3470e0137378SRichard Henderson ctx->null_cond = cond_make_f(); 347131234768SRichard Henderson return true; 3472b2167459SRichard Henderson } 3473b2167459SRichard Henderson 34746fd0c7bcSRichard Henderson static bool do_cmpb(DisasContext *ctx, unsigned r, TCGv_i64 in1, 3475e9efd4bcSRichard Henderson unsigned c, unsigned f, bool d, unsigned n, int disp) 347698cd9ca7SRichard Henderson { 34776fd0c7bcSRichard Henderson TCGv_i64 dest, in2, sv; 347898cd9ca7SRichard Henderson DisasCond cond; 347998cd9ca7SRichard Henderson 348098cd9ca7SRichard Henderson in2 = load_gpr(ctx, r); 3481aac0f603SRichard Henderson dest = tcg_temp_new_i64(); 348298cd9ca7SRichard Henderson 34836fd0c7bcSRichard Henderson tcg_gen_sub_i64(dest, in1, in2); 348498cd9ca7SRichard Henderson 3485f764718dSRichard Henderson sv = NULL; 3486b47a4a02SSven Schnelle if (cond_need_sv(c)) { 348798cd9ca7SRichard Henderson sv = do_sub_sv(ctx, dest, in1, in2); 348898cd9ca7SRichard Henderson } 348998cd9ca7SRichard Henderson 34904fe9533aSRichard Henderson cond = do_sub_cond(ctx, c * 2 + f, d, dest, in1, in2, sv); 349101afb7beSRichard Henderson return do_cbranch(ctx, disp, n, &cond); 349298cd9ca7SRichard Henderson } 349398cd9ca7SRichard Henderson 349401afb7beSRichard Henderson static bool trans_cmpb(DisasContext *ctx, arg_cmpb *a) 349598cd9ca7SRichard Henderson { 3496e9efd4bcSRichard Henderson if (!ctx->is_pa20 && a->d) { 3497e9efd4bcSRichard Henderson return false; 3498e9efd4bcSRichard Henderson } 349901afb7beSRichard Henderson nullify_over(ctx); 3500e9efd4bcSRichard Henderson return do_cmpb(ctx, a->r2, load_gpr(ctx, a->r1), 3501e9efd4bcSRichard Henderson a->c, a->f, a->d, a->n, a->disp); 350201afb7beSRichard Henderson } 350301afb7beSRichard Henderson 350401afb7beSRichard Henderson static bool trans_cmpbi(DisasContext *ctx, arg_cmpbi *a) 350501afb7beSRichard Henderson { 3506c65c3ee1SRichard Henderson if (!ctx->is_pa20 && a->d) { 3507c65c3ee1SRichard Henderson return false; 3508c65c3ee1SRichard Henderson } 350901afb7beSRichard Henderson nullify_over(ctx); 35106fd0c7bcSRichard Henderson return do_cmpb(ctx, a->r, tcg_constant_i64(a->i), 3511c65c3ee1SRichard Henderson a->c, a->f, a->d, a->n, a->disp); 351201afb7beSRichard Henderson } 351301afb7beSRichard Henderson 35146fd0c7bcSRichard Henderson static bool do_addb(DisasContext *ctx, unsigned r, TCGv_i64 in1, 351501afb7beSRichard Henderson unsigned c, unsigned f, unsigned n, int disp) 351601afb7beSRichard Henderson { 35176fd0c7bcSRichard Henderson TCGv_i64 dest, in2, sv, cb_cond; 351898cd9ca7SRichard Henderson DisasCond cond; 3519bdcccc17SRichard Henderson bool d = false; 352098cd9ca7SRichard Henderson 3521f25d3160SRichard Henderson /* 3522f25d3160SRichard Henderson * For hppa64, the ADDB conditions change with PSW.W, 3523f25d3160SRichard Henderson * dropping ZNV, SV, OD in favor of double-word EQ, LT, LE. 3524f25d3160SRichard Henderson */ 3525f25d3160SRichard Henderson if (ctx->tb_flags & PSW_W) { 3526f25d3160SRichard Henderson d = c >= 5; 3527f25d3160SRichard Henderson if (d) { 3528f25d3160SRichard Henderson c &= 3; 3529f25d3160SRichard Henderson } 3530f25d3160SRichard Henderson } 3531f25d3160SRichard Henderson 353298cd9ca7SRichard Henderson in2 = load_gpr(ctx, r); 3533aac0f603SRichard Henderson dest = tcg_temp_new_i64(); 3534f764718dSRichard Henderson sv = NULL; 3535bdcccc17SRichard Henderson cb_cond = NULL; 353698cd9ca7SRichard Henderson 3537b47a4a02SSven Schnelle if (cond_need_cb(c)) { 3538aac0f603SRichard Henderson TCGv_i64 cb = tcg_temp_new_i64(); 3539aac0f603SRichard Henderson TCGv_i64 cb_msb = tcg_temp_new_i64(); 3540bdcccc17SRichard Henderson 35416fd0c7bcSRichard Henderson tcg_gen_movi_i64(cb_msb, 0); 35426fd0c7bcSRichard Henderson tcg_gen_add2_i64(dest, cb_msb, in1, cb_msb, in2, cb_msb); 35436fd0c7bcSRichard Henderson tcg_gen_xor_i64(cb, in1, in2); 35446fd0c7bcSRichard Henderson tcg_gen_xor_i64(cb, cb, dest); 3545bdcccc17SRichard Henderson cb_cond = get_carry(ctx, d, cb, cb_msb); 3546b47a4a02SSven Schnelle } else { 35476fd0c7bcSRichard Henderson tcg_gen_add_i64(dest, in1, in2); 3548b47a4a02SSven Schnelle } 3549b47a4a02SSven Schnelle if (cond_need_sv(c)) { 3550f8f5986eSRichard Henderson sv = do_add_sv(ctx, dest, in1, in2, in1, 0, d); 355198cd9ca7SRichard Henderson } 355298cd9ca7SRichard Henderson 3553a751eb31SRichard Henderson cond = do_cond(ctx, c * 2 + f, d, dest, cb_cond, sv); 355443675d20SSven Schnelle save_gpr(ctx, r, dest); 355501afb7beSRichard Henderson return do_cbranch(ctx, disp, n, &cond); 355698cd9ca7SRichard Henderson } 355798cd9ca7SRichard Henderson 355801afb7beSRichard Henderson static bool trans_addb(DisasContext *ctx, arg_addb *a) 355998cd9ca7SRichard Henderson { 356001afb7beSRichard Henderson nullify_over(ctx); 356101afb7beSRichard Henderson return do_addb(ctx, a->r2, load_gpr(ctx, a->r1), a->c, a->f, a->n, a->disp); 356201afb7beSRichard Henderson } 356301afb7beSRichard Henderson 356401afb7beSRichard Henderson static bool trans_addbi(DisasContext *ctx, arg_addbi *a) 356501afb7beSRichard Henderson { 356601afb7beSRichard Henderson nullify_over(ctx); 35676fd0c7bcSRichard Henderson return do_addb(ctx, a->r, tcg_constant_i64(a->i), a->c, a->f, a->n, a->disp); 356801afb7beSRichard Henderson } 356901afb7beSRichard Henderson 357001afb7beSRichard Henderson static bool trans_bb_sar(DisasContext *ctx, arg_bb_sar *a) 357101afb7beSRichard Henderson { 35726fd0c7bcSRichard Henderson TCGv_i64 tmp, tcg_r; 357398cd9ca7SRichard Henderson DisasCond cond; 357498cd9ca7SRichard Henderson 357598cd9ca7SRichard Henderson nullify_over(ctx); 357698cd9ca7SRichard Henderson 3577aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 357801afb7beSRichard Henderson tcg_r = load_gpr(ctx, a->r); 357982d0c831SRichard Henderson if (a->d) { 358082d0c831SRichard Henderson tcg_gen_shl_i64(tmp, tcg_r, cpu_sar); 358182d0c831SRichard Henderson } else { 35821e9ab9fbSRichard Henderson /* Force shift into [32,63] */ 35836fd0c7bcSRichard Henderson tcg_gen_ori_i64(tmp, cpu_sar, 32); 35846fd0c7bcSRichard Henderson tcg_gen_shl_i64(tmp, tcg_r, tmp); 35851e9ab9fbSRichard Henderson } 358698cd9ca7SRichard Henderson 35874c42fd0dSRichard Henderson cond = cond_make_ti(a->c ? TCG_COND_GE : TCG_COND_LT, tmp, 0); 358801afb7beSRichard Henderson return do_cbranch(ctx, a->disp, a->n, &cond); 358998cd9ca7SRichard Henderson } 359098cd9ca7SRichard Henderson 359101afb7beSRichard Henderson static bool trans_bb_imm(DisasContext *ctx, arg_bb_imm *a) 359298cd9ca7SRichard Henderson { 359301afb7beSRichard Henderson DisasCond cond; 3594b041ec9dSRichard Henderson int p = a->p | (a->d ? 0 : 32); 359501afb7beSRichard Henderson 359601afb7beSRichard Henderson nullify_over(ctx); 3597b041ec9dSRichard Henderson cond = cond_make_vi(a->c ? TCG_COND_TSTEQ : TCG_COND_TSTNE, 3598b041ec9dSRichard Henderson load_gpr(ctx, a->r), 1ull << (63 - p)); 359901afb7beSRichard Henderson return do_cbranch(ctx, a->disp, a->n, &cond); 360001afb7beSRichard Henderson } 360101afb7beSRichard Henderson 360201afb7beSRichard Henderson static bool trans_movb(DisasContext *ctx, arg_movb *a) 360301afb7beSRichard Henderson { 36046fd0c7bcSRichard Henderson TCGv_i64 dest; 360598cd9ca7SRichard Henderson DisasCond cond; 360698cd9ca7SRichard Henderson 360798cd9ca7SRichard Henderson nullify_over(ctx); 360898cd9ca7SRichard Henderson 360901afb7beSRichard Henderson dest = dest_gpr(ctx, a->r2); 361001afb7beSRichard Henderson if (a->r1 == 0) { 36116fd0c7bcSRichard Henderson tcg_gen_movi_i64(dest, 0); 361298cd9ca7SRichard Henderson } else { 36136fd0c7bcSRichard Henderson tcg_gen_mov_i64(dest, cpu_gr[a->r1]); 361498cd9ca7SRichard Henderson } 361598cd9ca7SRichard Henderson 36164fa52edfSRichard Henderson /* All MOVB conditions are 32-bit. */ 36174fa52edfSRichard Henderson cond = do_sed_cond(ctx, a->c, false, dest); 361801afb7beSRichard Henderson return do_cbranch(ctx, a->disp, a->n, &cond); 361901afb7beSRichard Henderson } 362001afb7beSRichard Henderson 362101afb7beSRichard Henderson static bool trans_movbi(DisasContext *ctx, arg_movbi *a) 362201afb7beSRichard Henderson { 36236fd0c7bcSRichard Henderson TCGv_i64 dest; 362401afb7beSRichard Henderson DisasCond cond; 362501afb7beSRichard Henderson 362601afb7beSRichard Henderson nullify_over(ctx); 362701afb7beSRichard Henderson 362801afb7beSRichard Henderson dest = dest_gpr(ctx, a->r); 36296fd0c7bcSRichard Henderson tcg_gen_movi_i64(dest, a->i); 363001afb7beSRichard Henderson 36314fa52edfSRichard Henderson /* All MOVBI conditions are 32-bit. */ 36324fa52edfSRichard Henderson cond = do_sed_cond(ctx, a->c, false, dest); 363301afb7beSRichard Henderson return do_cbranch(ctx, a->disp, a->n, &cond); 363498cd9ca7SRichard Henderson } 363598cd9ca7SRichard Henderson 3636f7b775a9SRichard Henderson static bool trans_shrp_sar(DisasContext *ctx, arg_shrp_sar *a) 36370b1347d2SRichard Henderson { 36386fd0c7bcSRichard Henderson TCGv_i64 dest, src2; 36390b1347d2SRichard Henderson 3640f7b775a9SRichard Henderson if (!ctx->is_pa20 && a->d) { 3641f7b775a9SRichard Henderson return false; 3642f7b775a9SRichard Henderson } 364330878590SRichard Henderson if (a->c) { 36440b1347d2SRichard Henderson nullify_over(ctx); 36450b1347d2SRichard Henderson } 36460b1347d2SRichard Henderson 364730878590SRichard Henderson dest = dest_gpr(ctx, a->t); 3648f7b775a9SRichard Henderson src2 = load_gpr(ctx, a->r2); 364930878590SRichard Henderson if (a->r1 == 0) { 3650f7b775a9SRichard Henderson if (a->d) { 36516fd0c7bcSRichard Henderson tcg_gen_shr_i64(dest, src2, cpu_sar); 3652f7b775a9SRichard Henderson } else { 3653aac0f603SRichard Henderson TCGv_i64 tmp = tcg_temp_new_i64(); 3654f7b775a9SRichard Henderson 36556fd0c7bcSRichard Henderson tcg_gen_ext32u_i64(dest, src2); 36566fd0c7bcSRichard Henderson tcg_gen_andi_i64(tmp, cpu_sar, 31); 36576fd0c7bcSRichard Henderson tcg_gen_shr_i64(dest, dest, tmp); 3658f7b775a9SRichard Henderson } 365930878590SRichard Henderson } else if (a->r1 == a->r2) { 3660f7b775a9SRichard Henderson if (a->d) { 36616fd0c7bcSRichard Henderson tcg_gen_rotr_i64(dest, src2, cpu_sar); 3662f7b775a9SRichard Henderson } else { 36630b1347d2SRichard Henderson TCGv_i32 t32 = tcg_temp_new_i32(); 3664e1d635e8SRichard Henderson TCGv_i32 s32 = tcg_temp_new_i32(); 3665e1d635e8SRichard Henderson 36666fd0c7bcSRichard Henderson tcg_gen_extrl_i64_i32(t32, src2); 36676fd0c7bcSRichard Henderson tcg_gen_extrl_i64_i32(s32, cpu_sar); 3668f7b775a9SRichard Henderson tcg_gen_andi_i32(s32, s32, 31); 3669e1d635e8SRichard Henderson tcg_gen_rotr_i32(t32, t32, s32); 36706fd0c7bcSRichard Henderson tcg_gen_extu_i32_i64(dest, t32); 3671f7b775a9SRichard Henderson } 3672f7b775a9SRichard Henderson } else { 36736fd0c7bcSRichard Henderson TCGv_i64 src1 = load_gpr(ctx, a->r1); 3674f7b775a9SRichard Henderson 3675f7b775a9SRichard Henderson if (a->d) { 3676aac0f603SRichard Henderson TCGv_i64 t = tcg_temp_new_i64(); 3677aac0f603SRichard Henderson TCGv_i64 n = tcg_temp_new_i64(); 3678f7b775a9SRichard Henderson 36796fd0c7bcSRichard Henderson tcg_gen_xori_i64(n, cpu_sar, 63); 3680a01491a2SHelge Deller tcg_gen_shl_i64(t, src1, n); 36816fd0c7bcSRichard Henderson tcg_gen_shli_i64(t, t, 1); 3682a01491a2SHelge Deller tcg_gen_shr_i64(dest, src2, cpu_sar); 36836fd0c7bcSRichard Henderson tcg_gen_or_i64(dest, dest, t); 36840b1347d2SRichard Henderson } else { 36850b1347d2SRichard Henderson TCGv_i64 t = tcg_temp_new_i64(); 36860b1347d2SRichard Henderson TCGv_i64 s = tcg_temp_new_i64(); 36870b1347d2SRichard Henderson 36886fd0c7bcSRichard Henderson tcg_gen_concat32_i64(t, src2, src1); 3689967662cdSRichard Henderson tcg_gen_andi_i64(s, cpu_sar, 31); 3690967662cdSRichard Henderson tcg_gen_shr_i64(dest, t, s); 36910b1347d2SRichard Henderson } 3692f7b775a9SRichard Henderson } 369330878590SRichard Henderson save_gpr(ctx, a->t, dest); 36940b1347d2SRichard Henderson 36950b1347d2SRichard Henderson /* Install the new nullification. */ 3696d37fad0aSSven Schnelle ctx->null_cond = do_sed_cond(ctx, a->c, a->d, dest); 369731234768SRichard Henderson return nullify_end(ctx); 36980b1347d2SRichard Henderson } 36990b1347d2SRichard Henderson 3700f7b775a9SRichard Henderson static bool trans_shrp_imm(DisasContext *ctx, arg_shrp_imm *a) 37010b1347d2SRichard Henderson { 3702f7b775a9SRichard Henderson unsigned width, sa; 37036fd0c7bcSRichard Henderson TCGv_i64 dest, t2; 37040b1347d2SRichard Henderson 3705f7b775a9SRichard Henderson if (!ctx->is_pa20 && a->d) { 3706f7b775a9SRichard Henderson return false; 3707f7b775a9SRichard Henderson } 370830878590SRichard Henderson if (a->c) { 37090b1347d2SRichard Henderson nullify_over(ctx); 37100b1347d2SRichard Henderson } 37110b1347d2SRichard Henderson 3712f7b775a9SRichard Henderson width = a->d ? 64 : 32; 3713f7b775a9SRichard Henderson sa = width - 1 - a->cpos; 3714f7b775a9SRichard Henderson 371530878590SRichard Henderson dest = dest_gpr(ctx, a->t); 371630878590SRichard Henderson t2 = load_gpr(ctx, a->r2); 371705bfd4dbSRichard Henderson if (a->r1 == 0) { 37186fd0c7bcSRichard Henderson tcg_gen_extract_i64(dest, t2, sa, width - sa); 3719c53e401eSRichard Henderson } else if (width == TARGET_LONG_BITS) { 37206fd0c7bcSRichard Henderson tcg_gen_extract2_i64(dest, t2, cpu_gr[a->r1], sa); 3721f7b775a9SRichard Henderson } else { 3722f7b775a9SRichard Henderson assert(!a->d); 3723f7b775a9SRichard Henderson if (a->r1 == a->r2) { 37240b1347d2SRichard Henderson TCGv_i32 t32 = tcg_temp_new_i32(); 37256fd0c7bcSRichard Henderson tcg_gen_extrl_i64_i32(t32, t2); 37260b1347d2SRichard Henderson tcg_gen_rotri_i32(t32, t32, sa); 37276fd0c7bcSRichard Henderson tcg_gen_extu_i32_i64(dest, t32); 37280b1347d2SRichard Henderson } else { 3729967662cdSRichard Henderson tcg_gen_concat32_i64(dest, t2, cpu_gr[a->r1]); 3730967662cdSRichard Henderson tcg_gen_extract_i64(dest, dest, sa, 32); 37310b1347d2SRichard Henderson } 3732f7b775a9SRichard Henderson } 373330878590SRichard Henderson save_gpr(ctx, a->t, dest); 37340b1347d2SRichard Henderson 37350b1347d2SRichard Henderson /* Install the new nullification. */ 3736d37fad0aSSven Schnelle ctx->null_cond = do_sed_cond(ctx, a->c, a->d, dest); 373731234768SRichard Henderson return nullify_end(ctx); 37380b1347d2SRichard Henderson } 37390b1347d2SRichard Henderson 3740bd792da3SRichard Henderson static bool trans_extr_sar(DisasContext *ctx, arg_extr_sar *a) 37410b1347d2SRichard Henderson { 3742bd792da3SRichard Henderson unsigned widthm1 = a->d ? 63 : 31; 37436fd0c7bcSRichard Henderson TCGv_i64 dest, src, tmp; 37440b1347d2SRichard Henderson 3745bd792da3SRichard Henderson if (!ctx->is_pa20 && a->d) { 3746bd792da3SRichard Henderson return false; 3747bd792da3SRichard Henderson } 374830878590SRichard Henderson if (a->c) { 37490b1347d2SRichard Henderson nullify_over(ctx); 37500b1347d2SRichard Henderson } 37510b1347d2SRichard Henderson 375230878590SRichard Henderson dest = dest_gpr(ctx, a->t); 375330878590SRichard Henderson src = load_gpr(ctx, a->r); 3754aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 37550b1347d2SRichard Henderson 37560b1347d2SRichard Henderson /* Recall that SAR is using big-endian bit numbering. */ 37576fd0c7bcSRichard Henderson tcg_gen_andi_i64(tmp, cpu_sar, widthm1); 37586fd0c7bcSRichard Henderson tcg_gen_xori_i64(tmp, tmp, widthm1); 3759d781cb77SRichard Henderson 376030878590SRichard Henderson if (a->se) { 3761bd792da3SRichard Henderson if (!a->d) { 37626fd0c7bcSRichard Henderson tcg_gen_ext32s_i64(dest, src); 3763bd792da3SRichard Henderson src = dest; 3764bd792da3SRichard Henderson } 37656fd0c7bcSRichard Henderson tcg_gen_sar_i64(dest, src, tmp); 37666fd0c7bcSRichard Henderson tcg_gen_sextract_i64(dest, dest, 0, a->len); 37670b1347d2SRichard Henderson } else { 3768bd792da3SRichard Henderson if (!a->d) { 37696fd0c7bcSRichard Henderson tcg_gen_ext32u_i64(dest, src); 3770bd792da3SRichard Henderson src = dest; 3771bd792da3SRichard Henderson } 37726fd0c7bcSRichard Henderson tcg_gen_shr_i64(dest, src, tmp); 37736fd0c7bcSRichard Henderson tcg_gen_extract_i64(dest, dest, 0, a->len); 37740b1347d2SRichard Henderson } 377530878590SRichard Henderson save_gpr(ctx, a->t, dest); 37760b1347d2SRichard Henderson 37770b1347d2SRichard Henderson /* Install the new nullification. */ 3778bd792da3SRichard Henderson ctx->null_cond = do_sed_cond(ctx, a->c, a->d, dest); 377931234768SRichard Henderson return nullify_end(ctx); 37800b1347d2SRichard Henderson } 37810b1347d2SRichard Henderson 3782bd792da3SRichard Henderson static bool trans_extr_imm(DisasContext *ctx, arg_extr_imm *a) 37830b1347d2SRichard Henderson { 3784bd792da3SRichard Henderson unsigned len, cpos, width; 37856fd0c7bcSRichard Henderson TCGv_i64 dest, src; 37860b1347d2SRichard Henderson 3787bd792da3SRichard Henderson if (!ctx->is_pa20 && a->d) { 3788bd792da3SRichard Henderson return false; 3789bd792da3SRichard Henderson } 379030878590SRichard Henderson if (a->c) { 37910b1347d2SRichard Henderson nullify_over(ctx); 37920b1347d2SRichard Henderson } 37930b1347d2SRichard Henderson 3794bd792da3SRichard Henderson len = a->len; 3795bd792da3SRichard Henderson width = a->d ? 64 : 32; 3796bd792da3SRichard Henderson cpos = width - 1 - a->pos; 3797bd792da3SRichard Henderson if (cpos + len > width) { 3798bd792da3SRichard Henderson len = width - cpos; 3799bd792da3SRichard Henderson } 3800bd792da3SRichard Henderson 380130878590SRichard Henderson dest = dest_gpr(ctx, a->t); 380230878590SRichard Henderson src = load_gpr(ctx, a->r); 380330878590SRichard Henderson if (a->se) { 38046fd0c7bcSRichard Henderson tcg_gen_sextract_i64(dest, src, cpos, len); 38050b1347d2SRichard Henderson } else { 38066fd0c7bcSRichard Henderson tcg_gen_extract_i64(dest, src, cpos, len); 38070b1347d2SRichard Henderson } 380830878590SRichard Henderson save_gpr(ctx, a->t, dest); 38090b1347d2SRichard Henderson 38100b1347d2SRichard Henderson /* Install the new nullification. */ 3811bd792da3SRichard Henderson ctx->null_cond = do_sed_cond(ctx, a->c, a->d, dest); 381231234768SRichard Henderson return nullify_end(ctx); 38130b1347d2SRichard Henderson } 38140b1347d2SRichard Henderson 381572ae4f2bSRichard Henderson static bool trans_depi_imm(DisasContext *ctx, arg_depi_imm *a) 38160b1347d2SRichard Henderson { 381772ae4f2bSRichard Henderson unsigned len, width; 3818c53e401eSRichard Henderson uint64_t mask0, mask1; 38196fd0c7bcSRichard Henderson TCGv_i64 dest; 38200b1347d2SRichard Henderson 382172ae4f2bSRichard Henderson if (!ctx->is_pa20 && a->d) { 382272ae4f2bSRichard Henderson return false; 382372ae4f2bSRichard Henderson } 382430878590SRichard Henderson if (a->c) { 38250b1347d2SRichard Henderson nullify_over(ctx); 38260b1347d2SRichard Henderson } 382772ae4f2bSRichard Henderson 382872ae4f2bSRichard Henderson len = a->len; 382972ae4f2bSRichard Henderson width = a->d ? 64 : 32; 383072ae4f2bSRichard Henderson if (a->cpos + len > width) { 383172ae4f2bSRichard Henderson len = width - a->cpos; 38320b1347d2SRichard Henderson } 38330b1347d2SRichard Henderson 383430878590SRichard Henderson dest = dest_gpr(ctx, a->t); 383530878590SRichard Henderson mask0 = deposit64(0, a->cpos, len, a->i); 383630878590SRichard Henderson mask1 = deposit64(-1, a->cpos, len, a->i); 38370b1347d2SRichard Henderson 383830878590SRichard Henderson if (a->nz) { 38396fd0c7bcSRichard Henderson TCGv_i64 src = load_gpr(ctx, a->t); 38406fd0c7bcSRichard Henderson tcg_gen_andi_i64(dest, src, mask1); 38416fd0c7bcSRichard Henderson tcg_gen_ori_i64(dest, dest, mask0); 38420b1347d2SRichard Henderson } else { 38436fd0c7bcSRichard Henderson tcg_gen_movi_i64(dest, mask0); 38440b1347d2SRichard Henderson } 384530878590SRichard Henderson save_gpr(ctx, a->t, dest); 38460b1347d2SRichard Henderson 38470b1347d2SRichard Henderson /* Install the new nullification. */ 384872ae4f2bSRichard Henderson ctx->null_cond = do_sed_cond(ctx, a->c, a->d, dest); 384931234768SRichard Henderson return nullify_end(ctx); 38500b1347d2SRichard Henderson } 38510b1347d2SRichard Henderson 385272ae4f2bSRichard Henderson static bool trans_dep_imm(DisasContext *ctx, arg_dep_imm *a) 38530b1347d2SRichard Henderson { 385430878590SRichard Henderson unsigned rs = a->nz ? a->t : 0; 385572ae4f2bSRichard Henderson unsigned len, width; 38566fd0c7bcSRichard Henderson TCGv_i64 dest, val; 38570b1347d2SRichard Henderson 385872ae4f2bSRichard Henderson if (!ctx->is_pa20 && a->d) { 385972ae4f2bSRichard Henderson return false; 386072ae4f2bSRichard Henderson } 386130878590SRichard Henderson if (a->c) { 38620b1347d2SRichard Henderson nullify_over(ctx); 38630b1347d2SRichard Henderson } 386472ae4f2bSRichard Henderson 386572ae4f2bSRichard Henderson len = a->len; 386672ae4f2bSRichard Henderson width = a->d ? 64 : 32; 386772ae4f2bSRichard Henderson if (a->cpos + len > width) { 386872ae4f2bSRichard Henderson len = width - a->cpos; 38690b1347d2SRichard Henderson } 38700b1347d2SRichard Henderson 387130878590SRichard Henderson dest = dest_gpr(ctx, a->t); 387230878590SRichard Henderson val = load_gpr(ctx, a->r); 38730b1347d2SRichard Henderson if (rs == 0) { 38746fd0c7bcSRichard Henderson tcg_gen_deposit_z_i64(dest, val, a->cpos, len); 38750b1347d2SRichard Henderson } else { 38766fd0c7bcSRichard Henderson tcg_gen_deposit_i64(dest, cpu_gr[rs], val, a->cpos, len); 38770b1347d2SRichard Henderson } 387830878590SRichard Henderson save_gpr(ctx, a->t, dest); 38790b1347d2SRichard Henderson 38800b1347d2SRichard Henderson /* Install the new nullification. */ 388172ae4f2bSRichard Henderson ctx->null_cond = do_sed_cond(ctx, a->c, a->d, dest); 388231234768SRichard Henderson return nullify_end(ctx); 38830b1347d2SRichard Henderson } 38840b1347d2SRichard Henderson 388572ae4f2bSRichard Henderson static bool do_dep_sar(DisasContext *ctx, unsigned rt, unsigned c, 38866fd0c7bcSRichard Henderson bool d, bool nz, unsigned len, TCGv_i64 val) 38870b1347d2SRichard Henderson { 38880b1347d2SRichard Henderson unsigned rs = nz ? rt : 0; 388972ae4f2bSRichard Henderson unsigned widthm1 = d ? 63 : 31; 38906fd0c7bcSRichard Henderson TCGv_i64 mask, tmp, shift, dest; 3891c53e401eSRichard Henderson uint64_t msb = 1ULL << (len - 1); 38920b1347d2SRichard Henderson 38930b1347d2SRichard Henderson dest = dest_gpr(ctx, rt); 3894aac0f603SRichard Henderson shift = tcg_temp_new_i64(); 3895aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 38960b1347d2SRichard Henderson 38970b1347d2SRichard Henderson /* Convert big-endian bit numbering in SAR to left-shift. */ 38986fd0c7bcSRichard Henderson tcg_gen_andi_i64(shift, cpu_sar, widthm1); 38996fd0c7bcSRichard Henderson tcg_gen_xori_i64(shift, shift, widthm1); 39000b1347d2SRichard Henderson 3901aac0f603SRichard Henderson mask = tcg_temp_new_i64(); 39026fd0c7bcSRichard Henderson tcg_gen_movi_i64(mask, msb + (msb - 1)); 39036fd0c7bcSRichard Henderson tcg_gen_and_i64(tmp, val, mask); 39040b1347d2SRichard Henderson if (rs) { 39056fd0c7bcSRichard Henderson tcg_gen_shl_i64(mask, mask, shift); 39066fd0c7bcSRichard Henderson tcg_gen_shl_i64(tmp, tmp, shift); 39076fd0c7bcSRichard Henderson tcg_gen_andc_i64(dest, cpu_gr[rs], mask); 39086fd0c7bcSRichard Henderson tcg_gen_or_i64(dest, dest, tmp); 39090b1347d2SRichard Henderson } else { 39106fd0c7bcSRichard Henderson tcg_gen_shl_i64(dest, tmp, shift); 39110b1347d2SRichard Henderson } 39120b1347d2SRichard Henderson save_gpr(ctx, rt, dest); 39130b1347d2SRichard Henderson 39140b1347d2SRichard Henderson /* Install the new nullification. */ 391572ae4f2bSRichard Henderson ctx->null_cond = do_sed_cond(ctx, c, d, dest); 391631234768SRichard Henderson return nullify_end(ctx); 39170b1347d2SRichard Henderson } 39180b1347d2SRichard Henderson 391972ae4f2bSRichard Henderson static bool trans_dep_sar(DisasContext *ctx, arg_dep_sar *a) 392030878590SRichard Henderson { 392172ae4f2bSRichard Henderson if (!ctx->is_pa20 && a->d) { 392272ae4f2bSRichard Henderson return false; 392372ae4f2bSRichard Henderson } 3924a6deecceSSven Schnelle if (a->c) { 3925a6deecceSSven Schnelle nullify_over(ctx); 3926a6deecceSSven Schnelle } 392772ae4f2bSRichard Henderson return do_dep_sar(ctx, a->t, a->c, a->d, a->nz, a->len, 392872ae4f2bSRichard Henderson load_gpr(ctx, a->r)); 392930878590SRichard Henderson } 393030878590SRichard Henderson 393172ae4f2bSRichard Henderson static bool trans_depi_sar(DisasContext *ctx, arg_depi_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, 39406fd0c7bcSRichard Henderson tcg_constant_i64(a->i)); 394130878590SRichard Henderson } 39420b1347d2SRichard Henderson 39438340f534SRichard Henderson static bool trans_be(DisasContext *ctx, arg_be *a) 394498cd9ca7SRichard Henderson { 3945019f4159SRichard Henderson #ifndef CONFIG_USER_ONLY 3946bc921866SRichard Henderson ctx->iaq_j.space = tcg_temp_new_i64(); 3947bc921866SRichard Henderson load_spr(ctx, ctx->iaq_j.space, a->sp); 3948c301f34eSRichard Henderson #endif 3949019f4159SRichard Henderson 3950bc921866SRichard Henderson ctx->iaq_j.base = tcg_temp_new_i64(); 3951bc921866SRichard Henderson ctx->iaq_j.disp = 0; 3952bc921866SRichard Henderson 3953bc921866SRichard Henderson tcg_gen_addi_i64(ctx->iaq_j.base, load_gpr(ctx, a->b), a->disp); 3954bc921866SRichard Henderson ctx->iaq_j.base = do_ibranch_priv(ctx, ctx->iaq_j.base); 3955bc921866SRichard Henderson 3956bc921866SRichard Henderson return do_ibranch(ctx, a->l, true, a->n); 395798cd9ca7SRichard Henderson } 395898cd9ca7SRichard Henderson 39598340f534SRichard Henderson static bool trans_bl(DisasContext *ctx, arg_bl *a) 396098cd9ca7SRichard Henderson { 39612644f80bSRichard Henderson return do_dbranch(ctx, a->disp, a->l, a->n); 396298cd9ca7SRichard Henderson } 396398cd9ca7SRichard Henderson 39648340f534SRichard Henderson static bool trans_b_gate(DisasContext *ctx, arg_b_gate *a) 396543e05652SRichard Henderson { 3966bc921866SRichard Henderson int64_t disp = a->disp; 396743e05652SRichard Henderson 39686e5f5300SSven Schnelle nullify_over(ctx); 39696e5f5300SSven Schnelle 397043e05652SRichard Henderson /* Make sure the caller hasn't done something weird with the queue. 397143e05652SRichard Henderson * ??? This is not quite the same as the PSW[B] bit, which would be 397243e05652SRichard Henderson * expensive to track. Real hardware will trap for 397343e05652SRichard Henderson * b gateway 397443e05652SRichard Henderson * b gateway+4 (in delay slot of first branch) 397543e05652SRichard Henderson * However, checking for a non-sequential instruction queue *will* 397643e05652SRichard Henderson * diagnose the security hole 397743e05652SRichard Henderson * b gateway 397843e05652SRichard Henderson * b evil 397943e05652SRichard Henderson * in which instructions at evil would run with increased privs. 398043e05652SRichard Henderson */ 3981bc921866SRichard Henderson if (iaqe_variable(&ctx->iaq_b) || ctx->iaq_b.disp != ctx->iaq_f.disp + 4) { 398243e05652SRichard Henderson return gen_illegal(ctx); 398343e05652SRichard Henderson } 398443e05652SRichard Henderson 398543e05652SRichard Henderson #ifndef CONFIG_USER_ONLY 398643e05652SRichard Henderson if (ctx->tb_flags & PSW_C) { 398794956d7bSPhilippe Mathieu-Daudé int type = hppa_artype_for_page(cpu_env(ctx->cs), ctx->base.pc_next); 398843e05652SRichard Henderson /* If we could not find a TLB entry, then we need to generate an 398943e05652SRichard Henderson ITLB miss exception so the kernel will provide it. 399043e05652SRichard Henderson The resulting TLB fill operation will invalidate this TB and 399143e05652SRichard Henderson we will re-translate, at which point we *will* be able to find 399243e05652SRichard Henderson the TLB entry and determine if this is in fact a gateway page. */ 399343e05652SRichard Henderson if (type < 0) { 399431234768SRichard Henderson gen_excp(ctx, EXCP_ITLB_MISS); 399531234768SRichard Henderson return true; 399643e05652SRichard Henderson } 399743e05652SRichard Henderson /* No change for non-gateway pages or for priv decrease. */ 399843e05652SRichard Henderson if (type >= 4 && type - 4 < ctx->privilege) { 3999bc921866SRichard Henderson disp -= ctx->privilege; 4000bc921866SRichard Henderson disp += type - 4; 400143e05652SRichard Henderson } 400243e05652SRichard Henderson } else { 4003bc921866SRichard Henderson disp -= ctx->privilege; /* priv = 0 */ 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 4016bc921866SRichard Henderson return do_dbranch(ctx, disp, 0, a->n); 401743e05652SRichard Henderson } 401843e05652SRichard Henderson 40198340f534SRichard Henderson static bool trans_blr(DisasContext *ctx, arg_blr *a) 402098cd9ca7SRichard Henderson { 4021b35aec85SRichard Henderson if (a->x) { 4022bc921866SRichard Henderson DisasIAQE next = iaqe_incr(&ctx->iaq_f, 8); 4023bc921866SRichard Henderson TCGv_i64 t0 = tcg_temp_new_i64(); 4024bc921866SRichard Henderson TCGv_i64 t1 = tcg_temp_new_i64(); 4025bc921866SRichard Henderson 4026660eefe1SRichard Henderson /* The computation here never changes privilege level. */ 4027bc921866SRichard Henderson copy_iaoq_entry(ctx, t0, &next); 4028bc921866SRichard Henderson tcg_gen_shli_i64(t1, load_gpr(ctx, a->x), 3); 4029bc921866SRichard Henderson tcg_gen_add_i64(t0, t0, t1); 4030bc921866SRichard Henderson 4031bc921866SRichard Henderson ctx->iaq_j = iaqe_next_absv(ctx, t0); 4032bc921866SRichard Henderson return do_ibranch(ctx, a->l, false, a->n); 4033b35aec85SRichard Henderson } else { 4034b35aec85SRichard Henderson /* BLR R0,RX is a good way to load PC+8 into RX. */ 40352644f80bSRichard Henderson return do_dbranch(ctx, 0, a->l, a->n); 4036b35aec85SRichard Henderson } 403798cd9ca7SRichard Henderson } 403898cd9ca7SRichard Henderson 40398340f534SRichard Henderson static bool trans_bv(DisasContext *ctx, arg_bv *a) 404098cd9ca7SRichard Henderson { 40416fd0c7bcSRichard Henderson TCGv_i64 dest; 404298cd9ca7SRichard Henderson 40438340f534SRichard Henderson if (a->x == 0) { 40448340f534SRichard Henderson dest = load_gpr(ctx, a->b); 404598cd9ca7SRichard Henderson } else { 4046aac0f603SRichard Henderson dest = tcg_temp_new_i64(); 40476fd0c7bcSRichard Henderson tcg_gen_shli_i64(dest, load_gpr(ctx, a->x), 3); 40486fd0c7bcSRichard Henderson tcg_gen_add_i64(dest, dest, load_gpr(ctx, a->b)); 404998cd9ca7SRichard Henderson } 4050660eefe1SRichard Henderson dest = do_ibranch_priv(ctx, dest); 4051bc921866SRichard Henderson ctx->iaq_j = iaqe_next_absv(ctx, dest); 4052bc921866SRichard Henderson 4053bc921866SRichard Henderson return do_ibranch(ctx, 0, false, a->n); 405498cd9ca7SRichard Henderson } 405598cd9ca7SRichard Henderson 40568340f534SRichard Henderson static bool trans_bve(DisasContext *ctx, arg_bve *a) 405798cd9ca7SRichard Henderson { 4058019f4159SRichard Henderson TCGv_i64 b = load_gpr(ctx, a->b); 405998cd9ca7SRichard Henderson 4060019f4159SRichard Henderson #ifndef CONFIG_USER_ONLY 4061bc921866SRichard Henderson ctx->iaq_j.space = space_select(ctx, 0, b); 4062c301f34eSRichard Henderson #endif 4063bc921866SRichard Henderson ctx->iaq_j.base = do_ibranch_priv(ctx, b); 4064bc921866SRichard Henderson ctx->iaq_j.disp = 0; 4065019f4159SRichard Henderson 4066bc921866SRichard Henderson return do_ibranch(ctx, a->l, false, a->n); 406798cd9ca7SRichard Henderson } 406898cd9ca7SRichard Henderson 4069a8966ba7SRichard Henderson static bool trans_nopbts(DisasContext *ctx, arg_nopbts *a) 4070a8966ba7SRichard Henderson { 4071a8966ba7SRichard Henderson /* All branch target stack instructions implement as nop. */ 4072a8966ba7SRichard Henderson return ctx->is_pa20; 4073a8966ba7SRichard Henderson } 4074a8966ba7SRichard Henderson 40751ca74648SRichard Henderson /* 40761ca74648SRichard Henderson * Float class 0 40771ca74648SRichard Henderson */ 4078ebe9383cSRichard Henderson 40791ca74648SRichard Henderson static void gen_fcpy_f(TCGv_i32 dst, TCGv_env unused, TCGv_i32 src) 4080ebe9383cSRichard Henderson { 4081ebe9383cSRichard Henderson tcg_gen_mov_i32(dst, src); 4082ebe9383cSRichard Henderson } 4083ebe9383cSRichard Henderson 408459f8c04bSHelge Deller static bool trans_fid_f(DisasContext *ctx, arg_fid_f *a) 408559f8c04bSHelge Deller { 4086a300dad3SRichard Henderson uint64_t ret; 4087a300dad3SRichard Henderson 4088c53e401eSRichard Henderson if (ctx->is_pa20) { 4089a300dad3SRichard Henderson ret = 0x13080000000000ULL; /* PA8700 (PCX-W2) */ 4090a300dad3SRichard Henderson } else { 4091a300dad3SRichard Henderson ret = 0x0f080000000000ULL; /* PA7300LC (PCX-L2) */ 4092a300dad3SRichard Henderson } 4093a300dad3SRichard Henderson 409459f8c04bSHelge Deller nullify_over(ctx); 4095a300dad3SRichard Henderson save_frd(0, tcg_constant_i64(ret)); 409659f8c04bSHelge Deller return nullify_end(ctx); 409759f8c04bSHelge Deller } 409859f8c04bSHelge Deller 40991ca74648SRichard Henderson static bool trans_fcpy_f(DisasContext *ctx, arg_fclass01 *a) 41001ca74648SRichard Henderson { 41011ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_fcpy_f); 41021ca74648SRichard Henderson } 41031ca74648SRichard Henderson 4104ebe9383cSRichard Henderson static void gen_fcpy_d(TCGv_i64 dst, TCGv_env unused, TCGv_i64 src) 4105ebe9383cSRichard Henderson { 4106ebe9383cSRichard Henderson tcg_gen_mov_i64(dst, src); 4107ebe9383cSRichard Henderson } 4108ebe9383cSRichard Henderson 41091ca74648SRichard Henderson static bool trans_fcpy_d(DisasContext *ctx, arg_fclass01 *a) 41101ca74648SRichard Henderson { 41111ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_fcpy_d); 41121ca74648SRichard Henderson } 41131ca74648SRichard Henderson 41141ca74648SRichard Henderson static void gen_fabs_f(TCGv_i32 dst, TCGv_env unused, TCGv_i32 src) 4115ebe9383cSRichard Henderson { 4116ebe9383cSRichard Henderson tcg_gen_andi_i32(dst, src, INT32_MAX); 4117ebe9383cSRichard Henderson } 4118ebe9383cSRichard Henderson 41191ca74648SRichard Henderson static bool trans_fabs_f(DisasContext *ctx, arg_fclass01 *a) 41201ca74648SRichard Henderson { 41211ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_fabs_f); 41221ca74648SRichard Henderson } 41231ca74648SRichard Henderson 4124ebe9383cSRichard Henderson static void gen_fabs_d(TCGv_i64 dst, TCGv_env unused, TCGv_i64 src) 4125ebe9383cSRichard Henderson { 4126ebe9383cSRichard Henderson tcg_gen_andi_i64(dst, src, INT64_MAX); 4127ebe9383cSRichard Henderson } 4128ebe9383cSRichard Henderson 41291ca74648SRichard Henderson static bool trans_fabs_d(DisasContext *ctx, arg_fclass01 *a) 41301ca74648SRichard Henderson { 41311ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_fabs_d); 41321ca74648SRichard Henderson } 41331ca74648SRichard Henderson 41341ca74648SRichard Henderson static bool trans_fsqrt_f(DisasContext *ctx, arg_fclass01 *a) 41351ca74648SRichard Henderson { 41361ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_fsqrt_s); 41371ca74648SRichard Henderson } 41381ca74648SRichard Henderson 41391ca74648SRichard Henderson static bool trans_fsqrt_d(DisasContext *ctx, arg_fclass01 *a) 41401ca74648SRichard Henderson { 41411ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_fsqrt_d); 41421ca74648SRichard Henderson } 41431ca74648SRichard Henderson 41441ca74648SRichard Henderson static bool trans_frnd_f(DisasContext *ctx, arg_fclass01 *a) 41451ca74648SRichard Henderson { 41461ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_frnd_s); 41471ca74648SRichard Henderson } 41481ca74648SRichard Henderson 41491ca74648SRichard Henderson static bool trans_frnd_d(DisasContext *ctx, arg_fclass01 *a) 41501ca74648SRichard Henderson { 41511ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_frnd_d); 41521ca74648SRichard Henderson } 41531ca74648SRichard Henderson 41541ca74648SRichard Henderson static void gen_fneg_f(TCGv_i32 dst, TCGv_env unused, TCGv_i32 src) 4155ebe9383cSRichard Henderson { 4156ebe9383cSRichard Henderson tcg_gen_xori_i32(dst, src, INT32_MIN); 4157ebe9383cSRichard Henderson } 4158ebe9383cSRichard Henderson 41591ca74648SRichard Henderson static bool trans_fneg_f(DisasContext *ctx, arg_fclass01 *a) 41601ca74648SRichard Henderson { 41611ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_fneg_f); 41621ca74648SRichard Henderson } 41631ca74648SRichard Henderson 4164ebe9383cSRichard Henderson static void gen_fneg_d(TCGv_i64 dst, TCGv_env unused, TCGv_i64 src) 4165ebe9383cSRichard Henderson { 4166ebe9383cSRichard Henderson tcg_gen_xori_i64(dst, src, INT64_MIN); 4167ebe9383cSRichard Henderson } 4168ebe9383cSRichard Henderson 41691ca74648SRichard Henderson static bool trans_fneg_d(DisasContext *ctx, arg_fclass01 *a) 41701ca74648SRichard Henderson { 41711ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_fneg_d); 41721ca74648SRichard Henderson } 41731ca74648SRichard Henderson 41741ca74648SRichard Henderson static void gen_fnegabs_f(TCGv_i32 dst, TCGv_env unused, TCGv_i32 src) 4175ebe9383cSRichard Henderson { 4176ebe9383cSRichard Henderson tcg_gen_ori_i32(dst, src, INT32_MIN); 4177ebe9383cSRichard Henderson } 4178ebe9383cSRichard Henderson 41791ca74648SRichard Henderson static bool trans_fnegabs_f(DisasContext *ctx, arg_fclass01 *a) 41801ca74648SRichard Henderson { 41811ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_fnegabs_f); 41821ca74648SRichard Henderson } 41831ca74648SRichard Henderson 4184ebe9383cSRichard Henderson static void gen_fnegabs_d(TCGv_i64 dst, TCGv_env unused, TCGv_i64 src) 4185ebe9383cSRichard Henderson { 4186ebe9383cSRichard Henderson tcg_gen_ori_i64(dst, src, INT64_MIN); 4187ebe9383cSRichard Henderson } 4188ebe9383cSRichard Henderson 41891ca74648SRichard Henderson static bool trans_fnegabs_d(DisasContext *ctx, arg_fclass01 *a) 41901ca74648SRichard Henderson { 41911ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_fnegabs_d); 41921ca74648SRichard Henderson } 41931ca74648SRichard Henderson 41941ca74648SRichard Henderson /* 41951ca74648SRichard Henderson * Float class 1 41961ca74648SRichard Henderson */ 41971ca74648SRichard Henderson 41981ca74648SRichard Henderson static bool trans_fcnv_d_f(DisasContext *ctx, arg_fclass01 *a) 41991ca74648SRichard Henderson { 42001ca74648SRichard Henderson return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_d_s); 42011ca74648SRichard Henderson } 42021ca74648SRichard Henderson 42031ca74648SRichard Henderson static bool trans_fcnv_f_d(DisasContext *ctx, arg_fclass01 *a) 42041ca74648SRichard Henderson { 42051ca74648SRichard Henderson return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_s_d); 42061ca74648SRichard Henderson } 42071ca74648SRichard Henderson 42081ca74648SRichard Henderson static bool trans_fcnv_w_f(DisasContext *ctx, arg_fclass01 *a) 42091ca74648SRichard Henderson { 42101ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_w_s); 42111ca74648SRichard Henderson } 42121ca74648SRichard Henderson 42131ca74648SRichard Henderson static bool trans_fcnv_q_f(DisasContext *ctx, arg_fclass01 *a) 42141ca74648SRichard Henderson { 42151ca74648SRichard Henderson return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_dw_s); 42161ca74648SRichard Henderson } 42171ca74648SRichard Henderson 42181ca74648SRichard Henderson static bool trans_fcnv_w_d(DisasContext *ctx, arg_fclass01 *a) 42191ca74648SRichard Henderson { 42201ca74648SRichard Henderson return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_w_d); 42211ca74648SRichard Henderson } 42221ca74648SRichard Henderson 42231ca74648SRichard Henderson static bool trans_fcnv_q_d(DisasContext *ctx, arg_fclass01 *a) 42241ca74648SRichard Henderson { 42251ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_dw_d); 42261ca74648SRichard Henderson } 42271ca74648SRichard Henderson 42281ca74648SRichard Henderson static bool trans_fcnv_f_w(DisasContext *ctx, arg_fclass01 *a) 42291ca74648SRichard Henderson { 42301ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_s_w); 42311ca74648SRichard Henderson } 42321ca74648SRichard Henderson 42331ca74648SRichard Henderson static bool trans_fcnv_d_w(DisasContext *ctx, arg_fclass01 *a) 42341ca74648SRichard Henderson { 42351ca74648SRichard Henderson return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_d_w); 42361ca74648SRichard Henderson } 42371ca74648SRichard Henderson 42381ca74648SRichard Henderson static bool trans_fcnv_f_q(DisasContext *ctx, arg_fclass01 *a) 42391ca74648SRichard Henderson { 42401ca74648SRichard Henderson return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_s_dw); 42411ca74648SRichard Henderson } 42421ca74648SRichard Henderson 42431ca74648SRichard Henderson static bool trans_fcnv_d_q(DisasContext *ctx, arg_fclass01 *a) 42441ca74648SRichard Henderson { 42451ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_d_dw); 42461ca74648SRichard Henderson } 42471ca74648SRichard Henderson 42481ca74648SRichard Henderson static bool trans_fcnv_t_f_w(DisasContext *ctx, arg_fclass01 *a) 42491ca74648SRichard Henderson { 42501ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_t_s_w); 42511ca74648SRichard Henderson } 42521ca74648SRichard Henderson 42531ca74648SRichard Henderson static bool trans_fcnv_t_d_w(DisasContext *ctx, arg_fclass01 *a) 42541ca74648SRichard Henderson { 42551ca74648SRichard Henderson return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_t_d_w); 42561ca74648SRichard Henderson } 42571ca74648SRichard Henderson 42581ca74648SRichard Henderson static bool trans_fcnv_t_f_q(DisasContext *ctx, arg_fclass01 *a) 42591ca74648SRichard Henderson { 42601ca74648SRichard Henderson return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_t_s_dw); 42611ca74648SRichard Henderson } 42621ca74648SRichard Henderson 42631ca74648SRichard Henderson static bool trans_fcnv_t_d_q(DisasContext *ctx, arg_fclass01 *a) 42641ca74648SRichard Henderson { 42651ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_t_d_dw); 42661ca74648SRichard Henderson } 42671ca74648SRichard Henderson 42681ca74648SRichard Henderson static bool trans_fcnv_uw_f(DisasContext *ctx, arg_fclass01 *a) 42691ca74648SRichard Henderson { 42701ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_uw_s); 42711ca74648SRichard Henderson } 42721ca74648SRichard Henderson 42731ca74648SRichard Henderson static bool trans_fcnv_uq_f(DisasContext *ctx, arg_fclass01 *a) 42741ca74648SRichard Henderson { 42751ca74648SRichard Henderson return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_udw_s); 42761ca74648SRichard Henderson } 42771ca74648SRichard Henderson 42781ca74648SRichard Henderson static bool trans_fcnv_uw_d(DisasContext *ctx, arg_fclass01 *a) 42791ca74648SRichard Henderson { 42801ca74648SRichard Henderson return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_uw_d); 42811ca74648SRichard Henderson } 42821ca74648SRichard Henderson 42831ca74648SRichard Henderson static bool trans_fcnv_uq_d(DisasContext *ctx, arg_fclass01 *a) 42841ca74648SRichard Henderson { 42851ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_udw_d); 42861ca74648SRichard Henderson } 42871ca74648SRichard Henderson 42881ca74648SRichard Henderson static bool trans_fcnv_f_uw(DisasContext *ctx, arg_fclass01 *a) 42891ca74648SRichard Henderson { 42901ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_s_uw); 42911ca74648SRichard Henderson } 42921ca74648SRichard Henderson 42931ca74648SRichard Henderson static bool trans_fcnv_d_uw(DisasContext *ctx, arg_fclass01 *a) 42941ca74648SRichard Henderson { 42951ca74648SRichard Henderson return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_d_uw); 42961ca74648SRichard Henderson } 42971ca74648SRichard Henderson 42981ca74648SRichard Henderson static bool trans_fcnv_f_uq(DisasContext *ctx, arg_fclass01 *a) 42991ca74648SRichard Henderson { 43001ca74648SRichard Henderson return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_s_udw); 43011ca74648SRichard Henderson } 43021ca74648SRichard Henderson 43031ca74648SRichard Henderson static bool trans_fcnv_d_uq(DisasContext *ctx, arg_fclass01 *a) 43041ca74648SRichard Henderson { 43051ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_d_udw); 43061ca74648SRichard Henderson } 43071ca74648SRichard Henderson 43081ca74648SRichard Henderson static bool trans_fcnv_t_f_uw(DisasContext *ctx, arg_fclass01 *a) 43091ca74648SRichard Henderson { 43101ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_t_s_uw); 43111ca74648SRichard Henderson } 43121ca74648SRichard Henderson 43131ca74648SRichard Henderson static bool trans_fcnv_t_d_uw(DisasContext *ctx, arg_fclass01 *a) 43141ca74648SRichard Henderson { 43151ca74648SRichard Henderson return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_t_d_uw); 43161ca74648SRichard Henderson } 43171ca74648SRichard Henderson 43181ca74648SRichard Henderson static bool trans_fcnv_t_f_uq(DisasContext *ctx, arg_fclass01 *a) 43191ca74648SRichard Henderson { 43201ca74648SRichard Henderson return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_t_s_udw); 43211ca74648SRichard Henderson } 43221ca74648SRichard Henderson 43231ca74648SRichard Henderson static bool trans_fcnv_t_d_uq(DisasContext *ctx, arg_fclass01 *a) 43241ca74648SRichard Henderson { 43251ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_t_d_udw); 43261ca74648SRichard Henderson } 43271ca74648SRichard Henderson 43281ca74648SRichard Henderson /* 43291ca74648SRichard Henderson * Float class 2 43301ca74648SRichard Henderson */ 43311ca74648SRichard Henderson 43321ca74648SRichard Henderson static bool trans_fcmp_f(DisasContext *ctx, arg_fclass2 *a) 4333ebe9383cSRichard Henderson { 4334ebe9383cSRichard Henderson TCGv_i32 ta, tb, tc, ty; 4335ebe9383cSRichard Henderson 4336ebe9383cSRichard Henderson nullify_over(ctx); 4337ebe9383cSRichard Henderson 43381ca74648SRichard Henderson ta = load_frw0_i32(a->r1); 43391ca74648SRichard Henderson tb = load_frw0_i32(a->r2); 434029dd6f64SRichard Henderson ty = tcg_constant_i32(a->y); 434129dd6f64SRichard Henderson tc = tcg_constant_i32(a->c); 4342ebe9383cSRichard Henderson 4343ad75a51eSRichard Henderson gen_helper_fcmp_s(tcg_env, ta, tb, ty, tc); 4344ebe9383cSRichard Henderson 43451ca74648SRichard Henderson return nullify_end(ctx); 4346ebe9383cSRichard Henderson } 4347ebe9383cSRichard Henderson 43481ca74648SRichard Henderson static bool trans_fcmp_d(DisasContext *ctx, arg_fclass2 *a) 4349ebe9383cSRichard Henderson { 4350ebe9383cSRichard Henderson TCGv_i64 ta, tb; 4351ebe9383cSRichard Henderson TCGv_i32 tc, ty; 4352ebe9383cSRichard Henderson 4353ebe9383cSRichard Henderson nullify_over(ctx); 4354ebe9383cSRichard Henderson 43551ca74648SRichard Henderson ta = load_frd0(a->r1); 43561ca74648SRichard Henderson tb = load_frd0(a->r2); 435729dd6f64SRichard Henderson ty = tcg_constant_i32(a->y); 435829dd6f64SRichard Henderson tc = tcg_constant_i32(a->c); 4359ebe9383cSRichard Henderson 4360ad75a51eSRichard Henderson gen_helper_fcmp_d(tcg_env, ta, tb, ty, tc); 4361ebe9383cSRichard Henderson 436231234768SRichard Henderson return nullify_end(ctx); 4363ebe9383cSRichard Henderson } 4364ebe9383cSRichard Henderson 43651ca74648SRichard Henderson static bool trans_ftest(DisasContext *ctx, arg_ftest *a) 4366ebe9383cSRichard Henderson { 43673692ad21SRichard Henderson TCGCond tc = TCG_COND_TSTNE; 43683692ad21SRichard Henderson uint32_t mask; 43696fd0c7bcSRichard Henderson TCGv_i64 t; 4370ebe9383cSRichard Henderson 4371ebe9383cSRichard Henderson nullify_over(ctx); 4372ebe9383cSRichard Henderson 4373aac0f603SRichard Henderson t = tcg_temp_new_i64(); 43746fd0c7bcSRichard Henderson tcg_gen_ld32u_i64(t, tcg_env, offsetof(CPUHPPAState, fr0_shadow)); 4375ebe9383cSRichard Henderson 43761ca74648SRichard Henderson if (a->y == 1) { 43771ca74648SRichard Henderson switch (a->c) { 4378ebe9383cSRichard Henderson case 0: /* simple */ 4379f33a22c1SRichard Henderson mask = R_FPSR_C_MASK; 4380f33a22c1SRichard Henderson break; 4381ebe9383cSRichard Henderson case 2: /* rej */ 43823692ad21SRichard Henderson tc = TCG_COND_TSTEQ; 4383ebe9383cSRichard Henderson /* fallthru */ 4384ebe9383cSRichard Henderson case 1: /* acc */ 4385f33a22c1SRichard Henderson mask = R_FPSR_C_MASK | R_FPSR_CQ_MASK; 4386ebe9383cSRichard Henderson break; 4387ebe9383cSRichard Henderson case 6: /* rej8 */ 43883692ad21SRichard Henderson tc = TCG_COND_TSTEQ; 4389ebe9383cSRichard Henderson /* fallthru */ 4390ebe9383cSRichard Henderson case 5: /* acc8 */ 4391f33a22c1SRichard Henderson mask = R_FPSR_C_MASK | R_FPSR_CQ0_6_MASK; 4392ebe9383cSRichard Henderson break; 4393ebe9383cSRichard Henderson case 9: /* acc6 */ 4394f33a22c1SRichard Henderson mask = R_FPSR_C_MASK | R_FPSR_CQ0_4_MASK; 4395ebe9383cSRichard Henderson break; 4396ebe9383cSRichard Henderson case 13: /* acc4 */ 4397f33a22c1SRichard Henderson mask = R_FPSR_C_MASK | R_FPSR_CQ0_2_MASK; 4398ebe9383cSRichard Henderson break; 4399ebe9383cSRichard Henderson case 17: /* acc2 */ 4400f33a22c1SRichard Henderson mask = R_FPSR_C_MASK | R_FPSR_CQ0_MASK; 4401ebe9383cSRichard Henderson break; 4402ebe9383cSRichard Henderson default: 44031ca74648SRichard Henderson gen_illegal(ctx); 44041ca74648SRichard Henderson return true; 4405ebe9383cSRichard Henderson } 44061ca74648SRichard Henderson } else { 44071ca74648SRichard Henderson unsigned cbit = (a->y ^ 1) - 1; 44083692ad21SRichard Henderson mask = R_FPSR_CA0_MASK >> cbit; 44091ca74648SRichard Henderson } 44101ca74648SRichard Henderson 44113692ad21SRichard Henderson ctx->null_cond = cond_make_ti(tc, t, mask); 441231234768SRichard Henderson return nullify_end(ctx); 4413ebe9383cSRichard Henderson } 4414ebe9383cSRichard Henderson 44151ca74648SRichard Henderson /* 44161ca74648SRichard Henderson * Float class 2 44171ca74648SRichard Henderson */ 44181ca74648SRichard Henderson 44191ca74648SRichard Henderson static bool trans_fadd_f(DisasContext *ctx, arg_fclass3 *a) 4420ebe9383cSRichard Henderson { 44211ca74648SRichard Henderson return do_fop_weww(ctx, a->t, a->r1, a->r2, gen_helper_fadd_s); 44221ca74648SRichard Henderson } 44231ca74648SRichard Henderson 44241ca74648SRichard Henderson static bool trans_fadd_d(DisasContext *ctx, arg_fclass3 *a) 44251ca74648SRichard Henderson { 44261ca74648SRichard Henderson return do_fop_dedd(ctx, a->t, a->r1, a->r2, gen_helper_fadd_d); 44271ca74648SRichard Henderson } 44281ca74648SRichard Henderson 44291ca74648SRichard Henderson static bool trans_fsub_f(DisasContext *ctx, arg_fclass3 *a) 44301ca74648SRichard Henderson { 44311ca74648SRichard Henderson return do_fop_weww(ctx, a->t, a->r1, a->r2, gen_helper_fsub_s); 44321ca74648SRichard Henderson } 44331ca74648SRichard Henderson 44341ca74648SRichard Henderson static bool trans_fsub_d(DisasContext *ctx, arg_fclass3 *a) 44351ca74648SRichard Henderson { 44361ca74648SRichard Henderson return do_fop_dedd(ctx, a->t, a->r1, a->r2, gen_helper_fsub_d); 44371ca74648SRichard Henderson } 44381ca74648SRichard Henderson 44391ca74648SRichard Henderson static bool trans_fmpy_f(DisasContext *ctx, arg_fclass3 *a) 44401ca74648SRichard Henderson { 44411ca74648SRichard Henderson return do_fop_weww(ctx, a->t, a->r1, a->r2, gen_helper_fmpy_s); 44421ca74648SRichard Henderson } 44431ca74648SRichard Henderson 44441ca74648SRichard Henderson static bool trans_fmpy_d(DisasContext *ctx, arg_fclass3 *a) 44451ca74648SRichard Henderson { 44461ca74648SRichard Henderson return do_fop_dedd(ctx, a->t, a->r1, a->r2, gen_helper_fmpy_d); 44471ca74648SRichard Henderson } 44481ca74648SRichard Henderson 44491ca74648SRichard Henderson static bool trans_fdiv_f(DisasContext *ctx, arg_fclass3 *a) 44501ca74648SRichard Henderson { 44511ca74648SRichard Henderson return do_fop_weww(ctx, a->t, a->r1, a->r2, gen_helper_fdiv_s); 44521ca74648SRichard Henderson } 44531ca74648SRichard Henderson 44541ca74648SRichard Henderson static bool trans_fdiv_d(DisasContext *ctx, arg_fclass3 *a) 44551ca74648SRichard Henderson { 44561ca74648SRichard Henderson return do_fop_dedd(ctx, a->t, a->r1, a->r2, gen_helper_fdiv_d); 44571ca74648SRichard Henderson } 44581ca74648SRichard Henderson 44591ca74648SRichard Henderson static bool trans_xmpyu(DisasContext *ctx, arg_xmpyu *a) 44601ca74648SRichard Henderson { 44611ca74648SRichard Henderson TCGv_i64 x, y; 4462ebe9383cSRichard Henderson 4463ebe9383cSRichard Henderson nullify_over(ctx); 4464ebe9383cSRichard Henderson 44651ca74648SRichard Henderson x = load_frw0_i64(a->r1); 44661ca74648SRichard Henderson y = load_frw0_i64(a->r2); 44671ca74648SRichard Henderson tcg_gen_mul_i64(x, x, y); 44681ca74648SRichard Henderson save_frd(a->t, x); 4469ebe9383cSRichard Henderson 447031234768SRichard Henderson return nullify_end(ctx); 4471ebe9383cSRichard Henderson } 4472ebe9383cSRichard Henderson 4473ebe9383cSRichard Henderson /* Convert the fmpyadd single-precision register encodings to standard. */ 4474ebe9383cSRichard Henderson static inline int fmpyadd_s_reg(unsigned r) 4475ebe9383cSRichard Henderson { 4476ebe9383cSRichard Henderson return (r & 16) * 2 + 16 + (r & 15); 4477ebe9383cSRichard Henderson } 4478ebe9383cSRichard Henderson 4479b1e2af57SRichard Henderson static bool do_fmpyadd_s(DisasContext *ctx, arg_mpyadd *a, bool is_sub) 4480ebe9383cSRichard Henderson { 4481b1e2af57SRichard Henderson int tm = fmpyadd_s_reg(a->tm); 4482b1e2af57SRichard Henderson int ra = fmpyadd_s_reg(a->ra); 4483b1e2af57SRichard Henderson int ta = fmpyadd_s_reg(a->ta); 4484b1e2af57SRichard Henderson int rm2 = fmpyadd_s_reg(a->rm2); 4485b1e2af57SRichard Henderson int rm1 = fmpyadd_s_reg(a->rm1); 4486ebe9383cSRichard Henderson 4487ebe9383cSRichard Henderson nullify_over(ctx); 4488ebe9383cSRichard Henderson 4489ebe9383cSRichard Henderson do_fop_weww(ctx, tm, rm1, rm2, gen_helper_fmpy_s); 4490ebe9383cSRichard Henderson do_fop_weww(ctx, ta, ta, ra, 4491ebe9383cSRichard Henderson is_sub ? gen_helper_fsub_s : gen_helper_fadd_s); 4492ebe9383cSRichard Henderson 449331234768SRichard Henderson return nullify_end(ctx); 4494ebe9383cSRichard Henderson } 4495ebe9383cSRichard Henderson 4496b1e2af57SRichard Henderson static bool trans_fmpyadd_f(DisasContext *ctx, arg_mpyadd *a) 4497b1e2af57SRichard Henderson { 4498b1e2af57SRichard Henderson return do_fmpyadd_s(ctx, a, false); 4499b1e2af57SRichard Henderson } 4500b1e2af57SRichard Henderson 4501b1e2af57SRichard Henderson static bool trans_fmpysub_f(DisasContext *ctx, arg_mpyadd *a) 4502b1e2af57SRichard Henderson { 4503b1e2af57SRichard Henderson return do_fmpyadd_s(ctx, a, true); 4504b1e2af57SRichard Henderson } 4505b1e2af57SRichard Henderson 4506b1e2af57SRichard Henderson static bool do_fmpyadd_d(DisasContext *ctx, arg_mpyadd *a, bool is_sub) 4507b1e2af57SRichard Henderson { 4508b1e2af57SRichard Henderson nullify_over(ctx); 4509b1e2af57SRichard Henderson 4510b1e2af57SRichard Henderson do_fop_dedd(ctx, a->tm, a->rm1, a->rm2, gen_helper_fmpy_d); 4511b1e2af57SRichard Henderson do_fop_dedd(ctx, a->ta, a->ta, a->ra, 4512b1e2af57SRichard Henderson is_sub ? gen_helper_fsub_d : gen_helper_fadd_d); 4513b1e2af57SRichard Henderson 4514b1e2af57SRichard Henderson return nullify_end(ctx); 4515b1e2af57SRichard Henderson } 4516b1e2af57SRichard Henderson 4517b1e2af57SRichard Henderson static bool trans_fmpyadd_d(DisasContext *ctx, arg_mpyadd *a) 4518b1e2af57SRichard Henderson { 4519b1e2af57SRichard Henderson return do_fmpyadd_d(ctx, a, false); 4520b1e2af57SRichard Henderson } 4521b1e2af57SRichard Henderson 4522b1e2af57SRichard Henderson static bool trans_fmpysub_d(DisasContext *ctx, arg_mpyadd *a) 4523b1e2af57SRichard Henderson { 4524b1e2af57SRichard Henderson return do_fmpyadd_d(ctx, a, true); 4525b1e2af57SRichard Henderson } 4526b1e2af57SRichard Henderson 4527c3bad4f8SRichard Henderson static bool trans_fmpyfadd_f(DisasContext *ctx, arg_fmpyfadd_f *a) 4528ebe9383cSRichard Henderson { 4529c3bad4f8SRichard Henderson TCGv_i32 x, y, z; 4530ebe9383cSRichard Henderson 4531ebe9383cSRichard Henderson nullify_over(ctx); 4532c3bad4f8SRichard Henderson x = load_frw0_i32(a->rm1); 4533c3bad4f8SRichard Henderson y = load_frw0_i32(a->rm2); 4534c3bad4f8SRichard Henderson z = load_frw0_i32(a->ra3); 4535ebe9383cSRichard Henderson 4536c3bad4f8SRichard Henderson if (a->neg) { 4537ad75a51eSRichard Henderson gen_helper_fmpynfadd_s(x, tcg_env, x, y, z); 4538ebe9383cSRichard Henderson } else { 4539ad75a51eSRichard Henderson gen_helper_fmpyfadd_s(x, tcg_env, x, y, z); 4540ebe9383cSRichard Henderson } 4541ebe9383cSRichard Henderson 4542c3bad4f8SRichard Henderson save_frw_i32(a->t, x); 454331234768SRichard Henderson return nullify_end(ctx); 4544ebe9383cSRichard Henderson } 4545ebe9383cSRichard Henderson 4546c3bad4f8SRichard Henderson static bool trans_fmpyfadd_d(DisasContext *ctx, arg_fmpyfadd_d *a) 4547ebe9383cSRichard Henderson { 4548c3bad4f8SRichard Henderson TCGv_i64 x, y, z; 4549ebe9383cSRichard Henderson 4550ebe9383cSRichard Henderson nullify_over(ctx); 4551c3bad4f8SRichard Henderson x = load_frd0(a->rm1); 4552c3bad4f8SRichard Henderson y = load_frd0(a->rm2); 4553c3bad4f8SRichard Henderson z = load_frd0(a->ra3); 4554ebe9383cSRichard Henderson 4555c3bad4f8SRichard Henderson if (a->neg) { 4556ad75a51eSRichard Henderson gen_helper_fmpynfadd_d(x, tcg_env, x, y, z); 4557ebe9383cSRichard Henderson } else { 4558ad75a51eSRichard Henderson gen_helper_fmpyfadd_d(x, tcg_env, x, y, z); 4559ebe9383cSRichard Henderson } 4560ebe9383cSRichard Henderson 4561c3bad4f8SRichard Henderson save_frd(a->t, x); 456231234768SRichard Henderson return nullify_end(ctx); 4563ebe9383cSRichard Henderson } 4564ebe9383cSRichard Henderson 456538193127SRichard Henderson /* Emulate PDC BTLB, called by SeaBIOS-hppa */ 456638193127SRichard Henderson static bool trans_diag_btlb(DisasContext *ctx, arg_diag_btlb *a) 456715da177bSSven Schnelle { 4568cf6b28d4SHelge Deller CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 4569cf6b28d4SHelge Deller #ifndef CONFIG_USER_ONLY 4570ad75a51eSRichard Henderson nullify_over(ctx); 4571ad75a51eSRichard Henderson gen_helper_diag_btlb(tcg_env); 4572cf6b28d4SHelge Deller return nullify_end(ctx); 457338193127SRichard Henderson #endif 457415da177bSSven Schnelle } 457538193127SRichard Henderson 457638193127SRichard Henderson /* Print char in %r26 to first serial console, used by SeaBIOS-hppa */ 457738193127SRichard Henderson static bool trans_diag_cout(DisasContext *ctx, arg_diag_cout *a) 457838193127SRichard Henderson { 457938193127SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 458038193127SRichard Henderson #ifndef CONFIG_USER_ONLY 4581dbca0835SHelge Deller nullify_over(ctx); 4582dbca0835SHelge Deller gen_helper_diag_console_output(tcg_env); 4583dbca0835SHelge Deller return nullify_end(ctx); 4584ad75a51eSRichard Henderson #endif 458538193127SRichard Henderson } 458638193127SRichard Henderson 45873bdf2081SHelge Deller static bool trans_diag_getshadowregs_pa1(DisasContext *ctx, arg_empty *a) 45883bdf2081SHelge Deller { 45893bdf2081SHelge Deller return !ctx->is_pa20 && do_getshadowregs(ctx); 45903bdf2081SHelge Deller } 45913bdf2081SHelge Deller 45923bdf2081SHelge Deller static bool trans_diag_getshadowregs_pa2(DisasContext *ctx, arg_empty *a) 45933bdf2081SHelge Deller { 45943bdf2081SHelge Deller return ctx->is_pa20 && do_getshadowregs(ctx); 45953bdf2081SHelge Deller } 45963bdf2081SHelge Deller 45973bdf2081SHelge Deller static bool trans_diag_putshadowregs_pa1(DisasContext *ctx, arg_empty *a) 45983bdf2081SHelge Deller { 45993bdf2081SHelge Deller return !ctx->is_pa20 && do_putshadowregs(ctx); 46003bdf2081SHelge Deller } 46013bdf2081SHelge Deller 46023bdf2081SHelge Deller static bool trans_diag_putshadowregs_pa2(DisasContext *ctx, arg_empty *a) 46033bdf2081SHelge Deller { 46043bdf2081SHelge Deller return ctx->is_pa20 && do_putshadowregs(ctx); 46053bdf2081SHelge Deller } 46063bdf2081SHelge Deller 460738193127SRichard Henderson static bool trans_diag_unimp(DisasContext *ctx, arg_diag_unimp *a) 460838193127SRichard Henderson { 460938193127SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 4610ad75a51eSRichard Henderson qemu_log_mask(LOG_UNIMP, "DIAG opcode 0x%04x ignored\n", a->i); 4611ad75a51eSRichard Henderson return true; 4612ad75a51eSRichard Henderson } 461315da177bSSven Schnelle 4614b542683dSEmilio G. Cota static void hppa_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) 461561766fe9SRichard Henderson { 461651b061fbSRichard Henderson DisasContext *ctx = container_of(dcbase, DisasContext, base); 46179dfcd243SRichard Henderson uint64_t cs_base, iaoq_f, iaoq_b; 4618f764718dSRichard Henderson int bound; 461961766fe9SRichard Henderson 462051b061fbSRichard Henderson ctx->cs = cs; 4621494737b7SRichard Henderson ctx->tb_flags = ctx->base.tb->flags; 4622bd6243a3SRichard Henderson ctx->is_pa20 = hppa_is_pa20(cpu_env(cs)); 4623*d27fe7c3SRichard Henderson ctx->psw_xb = ctx->tb_flags & (PSW_X | PSW_B); 46243d68ee7bSRichard Henderson 46253d68ee7bSRichard Henderson #ifdef CONFIG_USER_ONLY 46263c13b0ffSRichard Henderson ctx->privilege = PRIV_USER; 46273d68ee7bSRichard Henderson ctx->mmu_idx = MMU_USER_IDX; 4628217d1a5eSRichard Henderson ctx->unalign = (ctx->tb_flags & TB_FLAG_UNALIGN ? MO_UNALN : MO_ALIGN); 4629c301f34eSRichard Henderson #else 4630494737b7SRichard Henderson ctx->privilege = (ctx->tb_flags >> TB_FLAG_PRIV_SHIFT) & 3; 4631bb67ec32SRichard Henderson ctx->mmu_idx = (ctx->tb_flags & PSW_D 4632bb67ec32SRichard Henderson ? PRIV_P_TO_MMU_IDX(ctx->privilege, ctx->tb_flags & PSW_P) 4633451d993dSRichard Henderson : ctx->tb_flags & PSW_W ? MMU_ABS_W_IDX : MMU_ABS_IDX); 46349dfcd243SRichard Henderson #endif 46353d68ee7bSRichard Henderson 4636c301f34eSRichard Henderson /* Recover the IAOQ values from the GVA + PRIV. */ 46379dfcd243SRichard Henderson cs_base = ctx->base.tb->cs_base; 46389dfcd243SRichard Henderson iaoq_f = cs_base & MAKE_64BIT_MASK(32, 32); 46399dfcd243SRichard Henderson iaoq_f |= ctx->base.pc_first & MAKE_64BIT_MASK(2, 30); 46409dfcd243SRichard Henderson iaoq_f |= ctx->privilege; 46419dfcd243SRichard Henderson ctx->iaoq_first = iaoq_f; 4642c301f34eSRichard Henderson 46439dfcd243SRichard Henderson if (unlikely(cs_base & CS_BASE_DIFFSPACE)) { 4644bc921866SRichard Henderson ctx->iaq_b.space = cpu_iasq_b; 46459dfcd243SRichard Henderson ctx->iaq_b.base = cpu_iaoq_b; 46469dfcd243SRichard Henderson } else if (unlikely(cs_base & CS_BASE_DIFFPAGE)) { 46479dfcd243SRichard Henderson ctx->iaq_b.base = cpu_iaoq_b; 46489dfcd243SRichard Henderson } else { 46499dfcd243SRichard Henderson iaoq_b = (iaoq_f & TARGET_PAGE_MASK) | (cs_base & ~TARGET_PAGE_MASK); 46509dfcd243SRichard Henderson ctx->iaq_b.disp = iaoq_b - iaoq_f; 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 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 467451b061fbSRichard Henderson static void hppa_tr_insn_start(DisasContextBase *dcbase, CPUState *cs) 467551b061fbSRichard Henderson { 467651b061fbSRichard Henderson DisasContext *ctx = container_of(dcbase, DisasContext, base); 467751b061fbSRichard Henderson 4678bc921866SRichard Henderson tcg_debug_assert(!iaqe_variable(&ctx->iaq_f)); 46790d89cb7cSRichard Henderson tcg_gen_insn_start(ctx->iaoq_first + ctx->iaq_f.disp, 46800d89cb7cSRichard Henderson (iaqe_variable(&ctx->iaq_b) ? -1 : 46810d89cb7cSRichard Henderson ctx->iaoq_first + ctx->iaq_b.disp), 0); 468224638bd1SRichard Henderson ctx->insn_start_updated = false; 468351b061fbSRichard Henderson } 468451b061fbSRichard Henderson 468551b061fbSRichard Henderson static void hppa_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) 468651b061fbSRichard Henderson { 468751b061fbSRichard Henderson DisasContext *ctx = container_of(dcbase, DisasContext, base); 4688b77af26eSRichard Henderson CPUHPPAState *env = cpu_env(cs); 468951b061fbSRichard Henderson DisasJumpType ret; 469051b061fbSRichard Henderson 469151b061fbSRichard Henderson /* Execute one insn. */ 4692ba1d0b44SRichard Henderson #ifdef CONFIG_USER_ONLY 4693c301f34eSRichard Henderson if (ctx->base.pc_next < TARGET_PAGE_SIZE) { 469431234768SRichard Henderson do_page_zero(ctx); 469531234768SRichard Henderson ret = ctx->base.is_jmp; 4696869051eaSRichard Henderson assert(ret != DISAS_NEXT); 4697ba1d0b44SRichard Henderson } else 4698ba1d0b44SRichard Henderson #endif 4699ba1d0b44SRichard Henderson { 470061766fe9SRichard Henderson /* Always fetch the insn, even if nullified, so that we check 470161766fe9SRichard Henderson the page permissions for execute. */ 47024e116893SIlya Leoshkevich uint32_t insn = translator_ldl(env, &ctx->base, ctx->base.pc_next); 470361766fe9SRichard Henderson 4704bc921866SRichard Henderson /* 4705bc921866SRichard Henderson * Set up the IA queue for the next insn. 4706bc921866SRichard Henderson * This will be overwritten by a branch. 4707bc921866SRichard Henderson */ 4708bc921866SRichard Henderson ctx->iaq_n = NULL; 4709bc921866SRichard Henderson memset(&ctx->iaq_j, 0, sizeof(ctx->iaq_j)); 4710*d27fe7c3SRichard Henderson ctx->psw_b_next = false; 471161766fe9SRichard Henderson 471251b061fbSRichard Henderson if (unlikely(ctx->null_cond.c == TCG_COND_ALWAYS)) { 471351b061fbSRichard Henderson ctx->null_cond.c = TCG_COND_NEVER; 4714869051eaSRichard Henderson ret = DISAS_NEXT; 4715129e9cc3SRichard Henderson } else { 47161a19da0dSRichard Henderson ctx->insn = insn; 471731274b46SRichard Henderson if (!decode(ctx, insn)) { 471831274b46SRichard Henderson gen_illegal(ctx); 471931274b46SRichard Henderson } 472031234768SRichard Henderson ret = ctx->base.is_jmp; 472151b061fbSRichard Henderson assert(ctx->null_lab == NULL); 4722129e9cc3SRichard Henderson } 4723*d27fe7c3SRichard Henderson 4724*d27fe7c3SRichard Henderson if (ret != DISAS_NORETURN) { 4725*d27fe7c3SRichard Henderson set_psw_xb(ctx, ctx->psw_b_next ? PSW_B : 0); 4726*d27fe7c3SRichard Henderson } 472761766fe9SRichard Henderson } 472861766fe9SRichard Henderson 4729dbdccbdfSRichard Henderson /* If the TranslationBlock must end, do so. */ 4730dbdccbdfSRichard Henderson ctx->base.pc_next += 4; 4731dbdccbdfSRichard Henderson if (ret != DISAS_NEXT) { 4732dbdccbdfSRichard Henderson return; 473361766fe9SRichard Henderson } 4734dbdccbdfSRichard Henderson /* Note this also detects a priority change. */ 4735bc921866SRichard Henderson if (iaqe_variable(&ctx->iaq_b) 4736bc921866SRichard Henderson || ctx->iaq_b.disp != ctx->iaq_f.disp + 4) { 4737dbdccbdfSRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE; 4738dbdccbdfSRichard Henderson return; 4739129e9cc3SRichard Henderson } 4740dbdccbdfSRichard Henderson 4741dbdccbdfSRichard Henderson /* 4742dbdccbdfSRichard Henderson * Advance the insn queue. 4743dbdccbdfSRichard Henderson * The only exit now is DISAS_TOO_MANY from the translator loop. 4744dbdccbdfSRichard Henderson */ 4745bc921866SRichard Henderson ctx->iaq_f.disp = ctx->iaq_b.disp; 4746bc921866SRichard Henderson if (!ctx->iaq_n) { 4747bc921866SRichard Henderson ctx->iaq_b.disp += 4; 4748bc921866SRichard Henderson return; 4749bc921866SRichard Henderson } 4750bc921866SRichard Henderson /* 4751bc921866SRichard Henderson * If IAQ_Next is variable in any way, we need to copy into the 4752bc921866SRichard Henderson * IAQ_Back globals, in case the next insn raises an exception. 4753bc921866SRichard Henderson */ 4754bc921866SRichard Henderson if (ctx->iaq_n->base) { 4755bc921866SRichard Henderson copy_iaoq_entry(ctx, cpu_iaoq_b, ctx->iaq_n); 4756bc921866SRichard Henderson ctx->iaq_b.base = cpu_iaoq_b; 4757bc921866SRichard Henderson ctx->iaq_b.disp = 0; 47580dcd6640SRichard Henderson } else { 4759bc921866SRichard Henderson ctx->iaq_b.disp = ctx->iaq_n->disp; 47600dcd6640SRichard Henderson } 4761bc921866SRichard Henderson if (ctx->iaq_n->space) { 4762bc921866SRichard Henderson tcg_gen_mov_i64(cpu_iasq_b, ctx->iaq_n->space); 4763bc921866SRichard Henderson ctx->iaq_b.space = cpu_iasq_b; 4764142faf5fSRichard Henderson } 476561766fe9SRichard Henderson } 476661766fe9SRichard Henderson 476751b061fbSRichard Henderson static void hppa_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs) 476851b061fbSRichard Henderson { 476951b061fbSRichard Henderson DisasContext *ctx = container_of(dcbase, DisasContext, base); 4770e1b5a5edSRichard Henderson DisasJumpType is_jmp = ctx->base.is_jmp; 4771dbdccbdfSRichard Henderson /* Assume the insn queue has not been advanced. */ 4772bc921866SRichard Henderson DisasIAQE *f = &ctx->iaq_b; 4773bc921866SRichard Henderson DisasIAQE *b = ctx->iaq_n; 477451b061fbSRichard Henderson 4775e1b5a5edSRichard Henderson switch (is_jmp) { 4776869051eaSRichard Henderson case DISAS_NORETURN: 477761766fe9SRichard Henderson break; 477851b061fbSRichard Henderson case DISAS_TOO_MANY: 4779dbdccbdfSRichard Henderson /* The insn queue has not been advanced. */ 4780bc921866SRichard Henderson f = &ctx->iaq_f; 4781bc921866SRichard Henderson b = &ctx->iaq_b; 478261766fe9SRichard Henderson /* FALLTHRU */ 4783dbdccbdfSRichard Henderson case DISAS_IAQ_N_STALE: 4784bc921866SRichard Henderson if (use_goto_tb(ctx, f, b) 4785dbdccbdfSRichard Henderson && (ctx->null_cond.c == TCG_COND_NEVER 4786dbdccbdfSRichard Henderson || ctx->null_cond.c == TCG_COND_ALWAYS)) { 4787dbdccbdfSRichard Henderson nullify_set(ctx, ctx->null_cond.c == TCG_COND_ALWAYS); 4788bc921866SRichard Henderson gen_goto_tb(ctx, 0, f, b); 47898532a14eSRichard Henderson break; 479061766fe9SRichard Henderson } 4791c5d0aec2SRichard Henderson /* FALLTHRU */ 4792dbdccbdfSRichard Henderson case DISAS_IAQ_N_STALE_EXIT: 4793bc921866SRichard Henderson install_iaq_entries(ctx, f, b); 4794dbdccbdfSRichard Henderson nullify_save(ctx); 4795dbdccbdfSRichard Henderson if (is_jmp == DISAS_IAQ_N_STALE_EXIT) { 4796dbdccbdfSRichard Henderson tcg_gen_exit_tb(NULL, 0); 4797dbdccbdfSRichard Henderson break; 4798dbdccbdfSRichard Henderson } 4799dbdccbdfSRichard Henderson /* FALLTHRU */ 4800dbdccbdfSRichard Henderson case DISAS_IAQ_N_UPDATED: 4801dbdccbdfSRichard Henderson tcg_gen_lookup_and_goto_ptr(); 4802dbdccbdfSRichard Henderson break; 4803c5d0aec2SRichard Henderson case DISAS_EXIT: 4804c5d0aec2SRichard Henderson tcg_gen_exit_tb(NULL, 0); 480561766fe9SRichard Henderson break; 480661766fe9SRichard Henderson default: 480751b061fbSRichard Henderson g_assert_not_reached(); 480861766fe9SRichard Henderson } 480980603007SRichard Henderson 481080603007SRichard Henderson for (DisasDelayException *e = ctx->delay_excp_list; e ; e = e->next) { 481180603007SRichard Henderson gen_set_label(e->lab); 481280603007SRichard Henderson if (e->set_n >= 0) { 481380603007SRichard Henderson tcg_gen_movi_i64(cpu_psw_n, e->set_n); 481480603007SRichard Henderson } 481580603007SRichard Henderson if (e->set_iir) { 481680603007SRichard Henderson tcg_gen_st_i64(tcg_constant_i64(e->insn), tcg_env, 481780603007SRichard Henderson offsetof(CPUHPPAState, cr[CR_IIR])); 481880603007SRichard Henderson } 481980603007SRichard Henderson install_iaq_entries(ctx, &e->iaq_f, &e->iaq_b); 482080603007SRichard Henderson gen_excp_1(e->excp); 482180603007SRichard Henderson } 482251b061fbSRichard Henderson } 482361766fe9SRichard Henderson 48248eb806a7SRichard Henderson static void hppa_tr_disas_log(const DisasContextBase *dcbase, 48258eb806a7SRichard Henderson CPUState *cs, FILE *logfile) 482651b061fbSRichard Henderson { 4827c301f34eSRichard Henderson target_ulong pc = dcbase->pc_first; 482861766fe9SRichard Henderson 4829ba1d0b44SRichard Henderson #ifdef CONFIG_USER_ONLY 4830ba1d0b44SRichard Henderson switch (pc) { 48317ad439dfSRichard Henderson case 0x00: 48328eb806a7SRichard Henderson fprintf(logfile, "IN:\n0x00000000: (null)\n"); 4833ba1d0b44SRichard Henderson return; 48347ad439dfSRichard Henderson case 0xb0: 48358eb806a7SRichard Henderson fprintf(logfile, "IN:\n0x000000b0: light-weight-syscall\n"); 4836ba1d0b44SRichard Henderson return; 48377ad439dfSRichard Henderson case 0xe0: 48388eb806a7SRichard Henderson fprintf(logfile, "IN:\n0x000000e0: set-thread-pointer-syscall\n"); 4839ba1d0b44SRichard Henderson return; 48407ad439dfSRichard Henderson case 0x100: 48418eb806a7SRichard Henderson fprintf(logfile, "IN:\n0x00000100: syscall\n"); 4842ba1d0b44SRichard Henderson return; 48437ad439dfSRichard Henderson } 4844ba1d0b44SRichard Henderson #endif 4845ba1d0b44SRichard Henderson 48468eb806a7SRichard Henderson fprintf(logfile, "IN: %s\n", lookup_symbol(pc)); 48478eb806a7SRichard Henderson target_disas(logfile, cs, pc, dcbase->tb->size); 484861766fe9SRichard Henderson } 484951b061fbSRichard Henderson 485051b061fbSRichard Henderson static const TranslatorOps hppa_tr_ops = { 485151b061fbSRichard Henderson .init_disas_context = hppa_tr_init_disas_context, 485251b061fbSRichard Henderson .tb_start = hppa_tr_tb_start, 485351b061fbSRichard Henderson .insn_start = hppa_tr_insn_start, 485451b061fbSRichard Henderson .translate_insn = hppa_tr_translate_insn, 485551b061fbSRichard Henderson .tb_stop = hppa_tr_tb_stop, 485651b061fbSRichard Henderson .disas_log = hppa_tr_disas_log, 485751b061fbSRichard Henderson }; 485851b061fbSRichard Henderson 4859597f9b2dSRichard Henderson void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int *max_insns, 486032f0c394SAnton Johansson vaddr pc, void *host_pc) 486151b061fbSRichard Henderson { 4862bc921866SRichard Henderson DisasContext ctx = { }; 4863306c8721SRichard Henderson translator_loop(cs, tb, max_insns, pc, host_pc, &hppa_tr_ops, &ctx.base); 486461766fe9SRichard Henderson } 4865