161766fe9SRichard Henderson /* 261766fe9SRichard Henderson * HPPA emulation cpu translation for qemu. 361766fe9SRichard Henderson * 461766fe9SRichard Henderson * Copyright (c) 2016 Richard Henderson <rth@twiddle.net> 561766fe9SRichard Henderson * 661766fe9SRichard Henderson * This library is free software; you can redistribute it and/or 761766fe9SRichard Henderson * modify it under the terms of the GNU Lesser General Public 861766fe9SRichard Henderson * License as published by the Free Software Foundation; either 9d6ea4236SChetan Pant * version 2.1 of the License, or (at your option) any later version. 1061766fe9SRichard Henderson * 1161766fe9SRichard Henderson * This library is distributed in the hope that it will be useful, 1261766fe9SRichard Henderson * but WITHOUT ANY WARRANTY; without even the implied warranty of 1361766fe9SRichard Henderson * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1461766fe9SRichard Henderson * Lesser General Public License for more details. 1561766fe9SRichard Henderson * 1661766fe9SRichard Henderson * You should have received a copy of the GNU Lesser General Public 1761766fe9SRichard Henderson * License along with this library; if not, see <http://www.gnu.org/licenses/>. 1861766fe9SRichard Henderson */ 1961766fe9SRichard Henderson 2061766fe9SRichard Henderson #include "qemu/osdep.h" 2161766fe9SRichard Henderson #include "cpu.h" 2261766fe9SRichard Henderson #include "disas/disas.h" 2361766fe9SRichard Henderson #include "qemu/host-utils.h" 2461766fe9SRichard Henderson #include "exec/exec-all.h" 25dcb32f1dSPhilippe Mathieu-Daudé #include "tcg/tcg-op.h" 260843563fSRichard Henderson #include "tcg/tcg-op-gvec.h" 2761766fe9SRichard Henderson #include "exec/helper-proto.h" 2861766fe9SRichard Henderson #include "exec/helper-gen.h" 29869051eaSRichard Henderson #include "exec/translator.h" 3061766fe9SRichard Henderson #include "exec/log.h" 3161766fe9SRichard Henderson 32d53106c9SRichard Henderson #define HELPER_H "helper.h" 33d53106c9SRichard Henderson #include "exec/helper-info.c.inc" 34d53106c9SRichard Henderson #undef HELPER_H 35d53106c9SRichard Henderson 36aac0f603SRichard Henderson /* Choose to use explicit sizes within this file. */ 37aac0f603SRichard Henderson #undef tcg_temp_new 38d53106c9SRichard Henderson 3961766fe9SRichard Henderson typedef struct DisasCond { 4061766fe9SRichard Henderson TCGCond c; 416fd0c7bcSRichard Henderson TCGv_i64 a0, a1; 4261766fe9SRichard Henderson } DisasCond; 4361766fe9SRichard Henderson 4461766fe9SRichard Henderson typedef struct DisasContext { 45d01a3625SRichard Henderson DisasContextBase base; 4661766fe9SRichard Henderson CPUState *cs; 4761766fe9SRichard Henderson 48c53e401eSRichard Henderson uint64_t iaoq_f; 49c53e401eSRichard Henderson uint64_t iaoq_b; 50c53e401eSRichard Henderson uint64_t iaoq_n; 516fd0c7bcSRichard Henderson TCGv_i64 iaoq_n_var; 5261766fe9SRichard Henderson 5361766fe9SRichard Henderson DisasCond null_cond; 5461766fe9SRichard Henderson TCGLabel *null_lab; 5561766fe9SRichard Henderson 56a4db4a78SRichard Henderson TCGv_i64 zero; 57a4db4a78SRichard Henderson 581a19da0dSRichard Henderson uint32_t insn; 59494737b7SRichard Henderson uint32_t tb_flags; 603d68ee7bSRichard Henderson int mmu_idx; 613d68ee7bSRichard Henderson int privilege; 6261766fe9SRichard Henderson bool psw_n_nonzero; 63bd6243a3SRichard Henderson bool is_pa20; 64217d1a5eSRichard Henderson 65217d1a5eSRichard Henderson #ifdef CONFIG_USER_ONLY 66217d1a5eSRichard Henderson MemOp unalign; 67217d1a5eSRichard Henderson #endif 6861766fe9SRichard Henderson } DisasContext; 6961766fe9SRichard Henderson 70217d1a5eSRichard Henderson #ifdef CONFIG_USER_ONLY 71217d1a5eSRichard Henderson #define UNALIGN(C) (C)->unalign 72217d1a5eSRichard Henderson #else 732d4afb03SRichard Henderson #define UNALIGN(C) MO_ALIGN 74217d1a5eSRichard Henderson #endif 75217d1a5eSRichard Henderson 76e36f27efSRichard Henderson /* Note that ssm/rsm instructions number PSW_W and PSW_E differently. */ 77451e4ffdSRichard Henderson static int expand_sm_imm(DisasContext *ctx, int val) 78e36f27efSRichard Henderson { 79e36f27efSRichard Henderson if (val & PSW_SM_E) { 80e36f27efSRichard Henderson val = (val & ~PSW_SM_E) | PSW_E; 81e36f27efSRichard Henderson } 82e36f27efSRichard Henderson if (val & PSW_SM_W) { 83e36f27efSRichard Henderson val = (val & ~PSW_SM_W) | PSW_W; 84e36f27efSRichard Henderson } 85e36f27efSRichard Henderson return val; 86e36f27efSRichard Henderson } 87e36f27efSRichard Henderson 88deee69a1SRichard Henderson /* Inverted space register indicates 0 means sr0 not inferred from base. */ 89451e4ffdSRichard Henderson static int expand_sr3x(DisasContext *ctx, int val) 90deee69a1SRichard Henderson { 91deee69a1SRichard Henderson return ~val; 92deee69a1SRichard Henderson } 93deee69a1SRichard Henderson 941cd012a5SRichard Henderson /* Convert the M:A bits within a memory insn to the tri-state value 951cd012a5SRichard Henderson we use for the final M. */ 96451e4ffdSRichard Henderson static int ma_to_m(DisasContext *ctx, int val) 971cd012a5SRichard Henderson { 981cd012a5SRichard Henderson return val & 2 ? (val & 1 ? -1 : 1) : 0; 991cd012a5SRichard Henderson } 1001cd012a5SRichard Henderson 101740038d7SRichard Henderson /* Convert the sign of the displacement to a pre or post-modify. */ 102451e4ffdSRichard Henderson static int pos_to_m(DisasContext *ctx, int val) 103740038d7SRichard Henderson { 104740038d7SRichard Henderson return val ? 1 : -1; 105740038d7SRichard Henderson } 106740038d7SRichard Henderson 107451e4ffdSRichard Henderson static int neg_to_m(DisasContext *ctx, int val) 108740038d7SRichard Henderson { 109740038d7SRichard Henderson return val ? -1 : 1; 110740038d7SRichard Henderson } 111740038d7SRichard Henderson 112740038d7SRichard Henderson /* Used for branch targets and fp memory ops. */ 113451e4ffdSRichard Henderson static int expand_shl2(DisasContext *ctx, int val) 11401afb7beSRichard Henderson { 11501afb7beSRichard Henderson return val << 2; 11601afb7beSRichard Henderson } 11701afb7beSRichard Henderson 118740038d7SRichard Henderson /* Used for fp memory ops. */ 119451e4ffdSRichard Henderson static int expand_shl3(DisasContext *ctx, int val) 120740038d7SRichard Henderson { 121740038d7SRichard Henderson return val << 3; 122740038d7SRichard Henderson } 123740038d7SRichard Henderson 1240588e061SRichard Henderson /* Used for assemble_21. */ 125451e4ffdSRichard Henderson static int expand_shl11(DisasContext *ctx, int val) 1260588e061SRichard Henderson { 1270588e061SRichard Henderson return val << 11; 1280588e061SRichard Henderson } 1290588e061SRichard Henderson 13072ae4f2bSRichard Henderson static int assemble_6(DisasContext *ctx, int val) 13172ae4f2bSRichard Henderson { 13272ae4f2bSRichard Henderson /* 13372ae4f2bSRichard Henderson * Officially, 32 * x + 32 - y. 13472ae4f2bSRichard Henderson * Here, x is already in bit 5, and y is [4:0]. 13572ae4f2bSRichard Henderson * Since -y = ~y + 1, in 5 bits 32 - y => y ^ 31 + 1, 13672ae4f2bSRichard Henderson * with the overflow from bit 4 summing with x. 13772ae4f2bSRichard Henderson */ 13872ae4f2bSRichard Henderson return (val ^ 31) + 1; 13972ae4f2bSRichard Henderson } 14072ae4f2bSRichard Henderson 141c65c3ee1SRichard Henderson /* Translate CMPI doubleword conditions to standard. */ 142c65c3ee1SRichard Henderson static int cmpbid_c(DisasContext *ctx, int val) 143c65c3ee1SRichard Henderson { 144c65c3ee1SRichard Henderson return val ? val : 4; /* 0 == "*<<" */ 145c65c3ee1SRichard Henderson } 146c65c3ee1SRichard Henderson 14701afb7beSRichard Henderson 14840f9f908SRichard Henderson /* Include the auto-generated decoder. */ 149abff1abfSPaolo Bonzini #include "decode-insns.c.inc" 15040f9f908SRichard Henderson 15161766fe9SRichard Henderson /* We are not using a goto_tb (for whatever reason), but have updated 15261766fe9SRichard Henderson the iaq (for whatever reason), so don't do it again on exit. */ 153869051eaSRichard Henderson #define DISAS_IAQ_N_UPDATED DISAS_TARGET_0 15461766fe9SRichard Henderson 15561766fe9SRichard Henderson /* We are exiting the TB, but have neither emitted a goto_tb, nor 15661766fe9SRichard Henderson updated the iaq for the next instruction to be executed. */ 157869051eaSRichard Henderson #define DISAS_IAQ_N_STALE DISAS_TARGET_1 15861766fe9SRichard Henderson 159e1b5a5edSRichard Henderson /* Similarly, but we want to return to the main loop immediately 160e1b5a5edSRichard Henderson to recognize unmasked interrupts. */ 161e1b5a5edSRichard Henderson #define DISAS_IAQ_N_STALE_EXIT DISAS_TARGET_2 162c5d0aec2SRichard Henderson #define DISAS_EXIT DISAS_TARGET_3 163e1b5a5edSRichard Henderson 16461766fe9SRichard Henderson /* global register indexes */ 1656fd0c7bcSRichard Henderson static TCGv_i64 cpu_gr[32]; 16633423472SRichard Henderson static TCGv_i64 cpu_sr[4]; 167494737b7SRichard Henderson static TCGv_i64 cpu_srH; 1686fd0c7bcSRichard Henderson static TCGv_i64 cpu_iaoq_f; 1696fd0c7bcSRichard Henderson static TCGv_i64 cpu_iaoq_b; 170c301f34eSRichard Henderson static TCGv_i64 cpu_iasq_f; 171c301f34eSRichard Henderson static TCGv_i64 cpu_iasq_b; 1726fd0c7bcSRichard Henderson static TCGv_i64 cpu_sar; 1736fd0c7bcSRichard Henderson static TCGv_i64 cpu_psw_n; 1746fd0c7bcSRichard Henderson static TCGv_i64 cpu_psw_v; 1756fd0c7bcSRichard Henderson static TCGv_i64 cpu_psw_cb; 1766fd0c7bcSRichard Henderson static TCGv_i64 cpu_psw_cb_msb; 17761766fe9SRichard Henderson 17861766fe9SRichard Henderson void hppa_translate_init(void) 17961766fe9SRichard Henderson { 18061766fe9SRichard Henderson #define DEF_VAR(V) { &cpu_##V, #V, offsetof(CPUHPPAState, V) } 18161766fe9SRichard Henderson 1826fd0c7bcSRichard Henderson typedef struct { TCGv_i64 *var; const char *name; int ofs; } GlobalVar; 18361766fe9SRichard Henderson static const GlobalVar vars[] = { 18435136a77SRichard Henderson { &cpu_sar, "sar", offsetof(CPUHPPAState, cr[CR_SAR]) }, 18561766fe9SRichard Henderson DEF_VAR(psw_n), 18661766fe9SRichard Henderson DEF_VAR(psw_v), 18761766fe9SRichard Henderson DEF_VAR(psw_cb), 18861766fe9SRichard Henderson DEF_VAR(psw_cb_msb), 18961766fe9SRichard Henderson DEF_VAR(iaoq_f), 19061766fe9SRichard Henderson DEF_VAR(iaoq_b), 19161766fe9SRichard Henderson }; 19261766fe9SRichard Henderson 19361766fe9SRichard Henderson #undef DEF_VAR 19461766fe9SRichard Henderson 19561766fe9SRichard Henderson /* Use the symbolic register names that match the disassembler. */ 19661766fe9SRichard Henderson static const char gr_names[32][4] = { 19761766fe9SRichard Henderson "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", 19861766fe9SRichard Henderson "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", 19961766fe9SRichard Henderson "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", 20061766fe9SRichard Henderson "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31" 20161766fe9SRichard Henderson }; 20233423472SRichard Henderson /* SR[4-7] are not global registers so that we can index them. */ 203494737b7SRichard Henderson static const char sr_names[5][4] = { 204494737b7SRichard Henderson "sr0", "sr1", "sr2", "sr3", "srH" 20533423472SRichard Henderson }; 20661766fe9SRichard Henderson 20761766fe9SRichard Henderson int i; 20861766fe9SRichard Henderson 209f764718dSRichard Henderson cpu_gr[0] = NULL; 21061766fe9SRichard Henderson for (i = 1; i < 32; i++) { 211ad75a51eSRichard Henderson cpu_gr[i] = tcg_global_mem_new(tcg_env, 21261766fe9SRichard Henderson offsetof(CPUHPPAState, gr[i]), 21361766fe9SRichard Henderson gr_names[i]); 21461766fe9SRichard Henderson } 21533423472SRichard Henderson for (i = 0; i < 4; i++) { 216ad75a51eSRichard Henderson cpu_sr[i] = tcg_global_mem_new_i64(tcg_env, 21733423472SRichard Henderson offsetof(CPUHPPAState, sr[i]), 21833423472SRichard Henderson sr_names[i]); 21933423472SRichard Henderson } 220ad75a51eSRichard Henderson cpu_srH = tcg_global_mem_new_i64(tcg_env, 221494737b7SRichard Henderson offsetof(CPUHPPAState, sr[4]), 222494737b7SRichard Henderson sr_names[4]); 22361766fe9SRichard Henderson 22461766fe9SRichard Henderson for (i = 0; i < ARRAY_SIZE(vars); ++i) { 22561766fe9SRichard Henderson const GlobalVar *v = &vars[i]; 226ad75a51eSRichard Henderson *v->var = tcg_global_mem_new(tcg_env, v->ofs, v->name); 22761766fe9SRichard Henderson } 228c301f34eSRichard Henderson 229ad75a51eSRichard Henderson cpu_iasq_f = tcg_global_mem_new_i64(tcg_env, 230c301f34eSRichard Henderson offsetof(CPUHPPAState, iasq_f), 231c301f34eSRichard Henderson "iasq_f"); 232ad75a51eSRichard Henderson cpu_iasq_b = tcg_global_mem_new_i64(tcg_env, 233c301f34eSRichard Henderson offsetof(CPUHPPAState, iasq_b), 234c301f34eSRichard Henderson "iasq_b"); 23561766fe9SRichard Henderson } 23661766fe9SRichard Henderson 237129e9cc3SRichard Henderson static DisasCond cond_make_f(void) 238129e9cc3SRichard Henderson { 239f764718dSRichard Henderson return (DisasCond){ 240f764718dSRichard Henderson .c = TCG_COND_NEVER, 241f764718dSRichard Henderson .a0 = NULL, 242f764718dSRichard Henderson .a1 = NULL, 243f764718dSRichard Henderson }; 244129e9cc3SRichard Henderson } 245129e9cc3SRichard Henderson 246df0232feSRichard Henderson static DisasCond cond_make_t(void) 247df0232feSRichard Henderson { 248df0232feSRichard Henderson return (DisasCond){ 249df0232feSRichard Henderson .c = TCG_COND_ALWAYS, 250df0232feSRichard Henderson .a0 = NULL, 251df0232feSRichard Henderson .a1 = NULL, 252df0232feSRichard Henderson }; 253df0232feSRichard Henderson } 254df0232feSRichard Henderson 255129e9cc3SRichard Henderson static DisasCond cond_make_n(void) 256129e9cc3SRichard Henderson { 257f764718dSRichard Henderson return (DisasCond){ 258f764718dSRichard Henderson .c = TCG_COND_NE, 259f764718dSRichard Henderson .a0 = cpu_psw_n, 2606fd0c7bcSRichard Henderson .a1 = tcg_constant_i64(0) 261f764718dSRichard Henderson }; 262129e9cc3SRichard Henderson } 263129e9cc3SRichard Henderson 2646fd0c7bcSRichard Henderson static DisasCond cond_make_tmp(TCGCond c, TCGv_i64 a0, TCGv_i64 a1) 265b47a4a02SSven Schnelle { 266b47a4a02SSven Schnelle assert (c != TCG_COND_NEVER && c != TCG_COND_ALWAYS); 2674fe9533aSRichard Henderson return (DisasCond){ .c = c, .a0 = a0, .a1 = a1 }; 2684fe9533aSRichard Henderson } 2694fe9533aSRichard Henderson 2706fd0c7bcSRichard Henderson static DisasCond cond_make_0_tmp(TCGCond c, TCGv_i64 a0) 2714fe9533aSRichard Henderson { 2726fd0c7bcSRichard Henderson return cond_make_tmp(c, a0, tcg_constant_i64(0)); 273b47a4a02SSven Schnelle } 274b47a4a02SSven Schnelle 2756fd0c7bcSRichard Henderson static DisasCond cond_make_0(TCGCond c, TCGv_i64 a0) 276129e9cc3SRichard Henderson { 277aac0f603SRichard Henderson TCGv_i64 tmp = tcg_temp_new_i64(); 2786fd0c7bcSRichard Henderson tcg_gen_mov_i64(tmp, a0); 279b47a4a02SSven Schnelle return cond_make_0_tmp(c, tmp); 280129e9cc3SRichard Henderson } 281129e9cc3SRichard Henderson 2826fd0c7bcSRichard Henderson static DisasCond cond_make(TCGCond c, TCGv_i64 a0, TCGv_i64 a1) 283129e9cc3SRichard Henderson { 284aac0f603SRichard Henderson TCGv_i64 t0 = tcg_temp_new_i64(); 285aac0f603SRichard Henderson TCGv_i64 t1 = tcg_temp_new_i64(); 286129e9cc3SRichard Henderson 2876fd0c7bcSRichard Henderson tcg_gen_mov_i64(t0, a0); 2886fd0c7bcSRichard Henderson tcg_gen_mov_i64(t1, a1); 2894fe9533aSRichard Henderson return cond_make_tmp(c, t0, t1); 290129e9cc3SRichard Henderson } 291129e9cc3SRichard Henderson 292129e9cc3SRichard Henderson static void cond_free(DisasCond *cond) 293129e9cc3SRichard Henderson { 294129e9cc3SRichard Henderson switch (cond->c) { 295129e9cc3SRichard Henderson default: 296f764718dSRichard Henderson cond->a0 = NULL; 297f764718dSRichard Henderson cond->a1 = NULL; 298129e9cc3SRichard Henderson /* fallthru */ 299129e9cc3SRichard Henderson case TCG_COND_ALWAYS: 300129e9cc3SRichard Henderson cond->c = TCG_COND_NEVER; 301129e9cc3SRichard Henderson break; 302129e9cc3SRichard Henderson case TCG_COND_NEVER: 303129e9cc3SRichard Henderson break; 304129e9cc3SRichard Henderson } 305129e9cc3SRichard Henderson } 306129e9cc3SRichard Henderson 3076fd0c7bcSRichard Henderson static TCGv_i64 load_gpr(DisasContext *ctx, unsigned reg) 30861766fe9SRichard Henderson { 30961766fe9SRichard Henderson if (reg == 0) { 310bc3da3cfSRichard Henderson return ctx->zero; 31161766fe9SRichard Henderson } else { 31261766fe9SRichard Henderson return cpu_gr[reg]; 31361766fe9SRichard Henderson } 31461766fe9SRichard Henderson } 31561766fe9SRichard Henderson 3166fd0c7bcSRichard Henderson static TCGv_i64 dest_gpr(DisasContext *ctx, unsigned reg) 31761766fe9SRichard Henderson { 318129e9cc3SRichard Henderson if (reg == 0 || ctx->null_cond.c != TCG_COND_NEVER) { 319aac0f603SRichard Henderson return tcg_temp_new_i64(); 32061766fe9SRichard Henderson } else { 32161766fe9SRichard Henderson return cpu_gr[reg]; 32261766fe9SRichard Henderson } 32361766fe9SRichard Henderson } 32461766fe9SRichard Henderson 3256fd0c7bcSRichard Henderson static void save_or_nullify(DisasContext *ctx, TCGv_i64 dest, TCGv_i64 t) 326129e9cc3SRichard Henderson { 327129e9cc3SRichard Henderson if (ctx->null_cond.c != TCG_COND_NEVER) { 3286fd0c7bcSRichard Henderson tcg_gen_movcond_i64(ctx->null_cond.c, dest, ctx->null_cond.a0, 329129e9cc3SRichard Henderson ctx->null_cond.a1, dest, t); 330129e9cc3SRichard Henderson } else { 3316fd0c7bcSRichard Henderson tcg_gen_mov_i64(dest, t); 332129e9cc3SRichard Henderson } 333129e9cc3SRichard Henderson } 334129e9cc3SRichard Henderson 3356fd0c7bcSRichard Henderson static void save_gpr(DisasContext *ctx, unsigned reg, TCGv_i64 t) 336129e9cc3SRichard Henderson { 337129e9cc3SRichard Henderson if (reg != 0) { 338129e9cc3SRichard Henderson save_or_nullify(ctx, cpu_gr[reg], t); 339129e9cc3SRichard Henderson } 340129e9cc3SRichard Henderson } 341129e9cc3SRichard Henderson 342e03b5686SMarc-André Lureau #if HOST_BIG_ENDIAN 34396d6407fSRichard Henderson # define HI_OFS 0 34496d6407fSRichard Henderson # define LO_OFS 4 34596d6407fSRichard Henderson #else 34696d6407fSRichard Henderson # define HI_OFS 4 34796d6407fSRichard Henderson # define LO_OFS 0 34896d6407fSRichard Henderson #endif 34996d6407fSRichard Henderson 35096d6407fSRichard Henderson static TCGv_i32 load_frw_i32(unsigned rt) 35196d6407fSRichard Henderson { 35296d6407fSRichard Henderson TCGv_i32 ret = tcg_temp_new_i32(); 353ad75a51eSRichard Henderson tcg_gen_ld_i32(ret, tcg_env, 35496d6407fSRichard Henderson offsetof(CPUHPPAState, fr[rt & 31]) 35596d6407fSRichard Henderson + (rt & 32 ? LO_OFS : HI_OFS)); 35696d6407fSRichard Henderson return ret; 35796d6407fSRichard Henderson } 35896d6407fSRichard Henderson 359ebe9383cSRichard Henderson static TCGv_i32 load_frw0_i32(unsigned rt) 360ebe9383cSRichard Henderson { 361ebe9383cSRichard Henderson if (rt == 0) { 3620992a930SRichard Henderson TCGv_i32 ret = tcg_temp_new_i32(); 3630992a930SRichard Henderson tcg_gen_movi_i32(ret, 0); 3640992a930SRichard Henderson return ret; 365ebe9383cSRichard Henderson } else { 366ebe9383cSRichard Henderson return load_frw_i32(rt); 367ebe9383cSRichard Henderson } 368ebe9383cSRichard Henderson } 369ebe9383cSRichard Henderson 370ebe9383cSRichard Henderson static TCGv_i64 load_frw0_i64(unsigned rt) 371ebe9383cSRichard Henderson { 372ebe9383cSRichard Henderson TCGv_i64 ret = tcg_temp_new_i64(); 3730992a930SRichard Henderson if (rt == 0) { 3740992a930SRichard Henderson tcg_gen_movi_i64(ret, 0); 3750992a930SRichard Henderson } else { 376ad75a51eSRichard Henderson tcg_gen_ld32u_i64(ret, tcg_env, 377ebe9383cSRichard Henderson offsetof(CPUHPPAState, fr[rt & 31]) 378ebe9383cSRichard Henderson + (rt & 32 ? LO_OFS : HI_OFS)); 379ebe9383cSRichard Henderson } 3800992a930SRichard Henderson return ret; 381ebe9383cSRichard Henderson } 382ebe9383cSRichard Henderson 38396d6407fSRichard Henderson static void save_frw_i32(unsigned rt, TCGv_i32 val) 38496d6407fSRichard Henderson { 385ad75a51eSRichard Henderson tcg_gen_st_i32(val, tcg_env, 38696d6407fSRichard Henderson offsetof(CPUHPPAState, fr[rt & 31]) 38796d6407fSRichard Henderson + (rt & 32 ? LO_OFS : HI_OFS)); 38896d6407fSRichard Henderson } 38996d6407fSRichard Henderson 39096d6407fSRichard Henderson #undef HI_OFS 39196d6407fSRichard Henderson #undef LO_OFS 39296d6407fSRichard Henderson 39396d6407fSRichard Henderson static TCGv_i64 load_frd(unsigned rt) 39496d6407fSRichard Henderson { 39596d6407fSRichard Henderson TCGv_i64 ret = tcg_temp_new_i64(); 396ad75a51eSRichard Henderson tcg_gen_ld_i64(ret, tcg_env, offsetof(CPUHPPAState, fr[rt])); 39796d6407fSRichard Henderson return ret; 39896d6407fSRichard Henderson } 39996d6407fSRichard Henderson 400ebe9383cSRichard Henderson static TCGv_i64 load_frd0(unsigned rt) 401ebe9383cSRichard Henderson { 402ebe9383cSRichard Henderson if (rt == 0) { 4030992a930SRichard Henderson TCGv_i64 ret = tcg_temp_new_i64(); 4040992a930SRichard Henderson tcg_gen_movi_i64(ret, 0); 4050992a930SRichard Henderson return ret; 406ebe9383cSRichard Henderson } else { 407ebe9383cSRichard Henderson return load_frd(rt); 408ebe9383cSRichard Henderson } 409ebe9383cSRichard Henderson } 410ebe9383cSRichard Henderson 41196d6407fSRichard Henderson static void save_frd(unsigned rt, TCGv_i64 val) 41296d6407fSRichard Henderson { 413ad75a51eSRichard Henderson tcg_gen_st_i64(val, tcg_env, offsetof(CPUHPPAState, fr[rt])); 41496d6407fSRichard Henderson } 41596d6407fSRichard Henderson 41633423472SRichard Henderson static void load_spr(DisasContext *ctx, TCGv_i64 dest, unsigned reg) 41733423472SRichard Henderson { 41833423472SRichard Henderson #ifdef CONFIG_USER_ONLY 41933423472SRichard Henderson tcg_gen_movi_i64(dest, 0); 42033423472SRichard Henderson #else 42133423472SRichard Henderson if (reg < 4) { 42233423472SRichard Henderson tcg_gen_mov_i64(dest, cpu_sr[reg]); 423494737b7SRichard Henderson } else if (ctx->tb_flags & TB_FLAG_SR_SAME) { 424494737b7SRichard Henderson tcg_gen_mov_i64(dest, cpu_srH); 42533423472SRichard Henderson } else { 426ad75a51eSRichard Henderson tcg_gen_ld_i64(dest, tcg_env, offsetof(CPUHPPAState, sr[reg])); 42733423472SRichard Henderson } 42833423472SRichard Henderson #endif 42933423472SRichard Henderson } 43033423472SRichard Henderson 431129e9cc3SRichard Henderson /* Skip over the implementation of an insn that has been nullified. 432129e9cc3SRichard Henderson Use this when the insn is too complex for a conditional move. */ 433129e9cc3SRichard Henderson static void nullify_over(DisasContext *ctx) 434129e9cc3SRichard Henderson { 435129e9cc3SRichard Henderson if (ctx->null_cond.c != TCG_COND_NEVER) { 436129e9cc3SRichard Henderson /* The always condition should have been handled in the main loop. */ 437129e9cc3SRichard Henderson assert(ctx->null_cond.c != TCG_COND_ALWAYS); 438129e9cc3SRichard Henderson 439129e9cc3SRichard Henderson ctx->null_lab = gen_new_label(); 440129e9cc3SRichard Henderson 441129e9cc3SRichard Henderson /* If we're using PSW[N], copy it to a temp because... */ 4426e94937aSRichard Henderson if (ctx->null_cond.a0 == cpu_psw_n) { 443aac0f603SRichard Henderson ctx->null_cond.a0 = tcg_temp_new_i64(); 4446fd0c7bcSRichard Henderson tcg_gen_mov_i64(ctx->null_cond.a0, cpu_psw_n); 445129e9cc3SRichard Henderson } 446129e9cc3SRichard Henderson /* ... we clear it before branching over the implementation, 447129e9cc3SRichard Henderson so that (1) it's clear after nullifying this insn and 448129e9cc3SRichard Henderson (2) if this insn nullifies the next, PSW[N] is valid. */ 449129e9cc3SRichard Henderson if (ctx->psw_n_nonzero) { 450129e9cc3SRichard Henderson ctx->psw_n_nonzero = false; 4516fd0c7bcSRichard Henderson tcg_gen_movi_i64(cpu_psw_n, 0); 452129e9cc3SRichard Henderson } 453129e9cc3SRichard Henderson 4546fd0c7bcSRichard Henderson tcg_gen_brcond_i64(ctx->null_cond.c, ctx->null_cond.a0, 455129e9cc3SRichard Henderson ctx->null_cond.a1, ctx->null_lab); 456129e9cc3SRichard Henderson cond_free(&ctx->null_cond); 457129e9cc3SRichard Henderson } 458129e9cc3SRichard Henderson } 459129e9cc3SRichard Henderson 460129e9cc3SRichard Henderson /* Save the current nullification state to PSW[N]. */ 461129e9cc3SRichard Henderson static void nullify_save(DisasContext *ctx) 462129e9cc3SRichard Henderson { 463129e9cc3SRichard Henderson if (ctx->null_cond.c == TCG_COND_NEVER) { 464129e9cc3SRichard Henderson if (ctx->psw_n_nonzero) { 4656fd0c7bcSRichard Henderson tcg_gen_movi_i64(cpu_psw_n, 0); 466129e9cc3SRichard Henderson } 467129e9cc3SRichard Henderson return; 468129e9cc3SRichard Henderson } 4696e94937aSRichard Henderson if (ctx->null_cond.a0 != cpu_psw_n) { 4706fd0c7bcSRichard Henderson tcg_gen_setcond_i64(ctx->null_cond.c, cpu_psw_n, 471129e9cc3SRichard Henderson ctx->null_cond.a0, ctx->null_cond.a1); 472129e9cc3SRichard Henderson ctx->psw_n_nonzero = true; 473129e9cc3SRichard Henderson } 474129e9cc3SRichard Henderson cond_free(&ctx->null_cond); 475129e9cc3SRichard Henderson } 476129e9cc3SRichard Henderson 477129e9cc3SRichard Henderson /* Set a PSW[N] to X. The intention is that this is used immediately 478129e9cc3SRichard Henderson before a goto_tb/exit_tb, so that there is no fallthru path to other 479129e9cc3SRichard Henderson code within the TB. Therefore we do not update psw_n_nonzero. */ 480129e9cc3SRichard Henderson static void nullify_set(DisasContext *ctx, bool x) 481129e9cc3SRichard Henderson { 482129e9cc3SRichard Henderson if (ctx->psw_n_nonzero || x) { 4836fd0c7bcSRichard Henderson tcg_gen_movi_i64(cpu_psw_n, x); 484129e9cc3SRichard Henderson } 485129e9cc3SRichard Henderson } 486129e9cc3SRichard Henderson 487129e9cc3SRichard Henderson /* Mark the end of an instruction that may have been nullified. 48840f9f908SRichard Henderson This is the pair to nullify_over. Always returns true so that 48940f9f908SRichard Henderson it may be tail-called from a translate function. */ 49031234768SRichard Henderson static bool nullify_end(DisasContext *ctx) 491129e9cc3SRichard Henderson { 492129e9cc3SRichard Henderson TCGLabel *null_lab = ctx->null_lab; 49331234768SRichard Henderson DisasJumpType status = ctx->base.is_jmp; 494129e9cc3SRichard Henderson 495f49b3537SRichard Henderson /* For NEXT, NORETURN, STALE, we can easily continue (or exit). 496f49b3537SRichard Henderson For UPDATED, we cannot update on the nullified path. */ 497f49b3537SRichard Henderson assert(status != DISAS_IAQ_N_UPDATED); 498f49b3537SRichard Henderson 499129e9cc3SRichard Henderson if (likely(null_lab == NULL)) { 500129e9cc3SRichard Henderson /* The current insn wasn't conditional or handled the condition 501129e9cc3SRichard Henderson applied to it without a branch, so the (new) setting of 502129e9cc3SRichard Henderson NULL_COND can be applied directly to the next insn. */ 50331234768SRichard Henderson return true; 504129e9cc3SRichard Henderson } 505129e9cc3SRichard Henderson ctx->null_lab = NULL; 506129e9cc3SRichard Henderson 507129e9cc3SRichard Henderson if (likely(ctx->null_cond.c == TCG_COND_NEVER)) { 508129e9cc3SRichard Henderson /* The next instruction will be unconditional, 509129e9cc3SRichard Henderson and NULL_COND already reflects that. */ 510129e9cc3SRichard Henderson gen_set_label(null_lab); 511129e9cc3SRichard Henderson } else { 512129e9cc3SRichard Henderson /* The insn that we just executed is itself nullifying the next 513129e9cc3SRichard Henderson instruction. Store the condition in the PSW[N] global. 514129e9cc3SRichard Henderson We asserted PSW[N] = 0 in nullify_over, so that after the 515129e9cc3SRichard Henderson label we have the proper value in place. */ 516129e9cc3SRichard Henderson nullify_save(ctx); 517129e9cc3SRichard Henderson gen_set_label(null_lab); 518129e9cc3SRichard Henderson ctx->null_cond = cond_make_n(); 519129e9cc3SRichard Henderson } 520869051eaSRichard Henderson if (status == DISAS_NORETURN) { 52131234768SRichard Henderson ctx->base.is_jmp = DISAS_NEXT; 522129e9cc3SRichard Henderson } 52331234768SRichard Henderson return true; 524129e9cc3SRichard Henderson } 525129e9cc3SRichard Henderson 526c53e401eSRichard Henderson static uint64_t gva_offset_mask(DisasContext *ctx) 527698240d1SRichard Henderson { 528698240d1SRichard Henderson return (ctx->tb_flags & PSW_W 529698240d1SRichard Henderson ? MAKE_64BIT_MASK(0, 62) 530698240d1SRichard Henderson : MAKE_64BIT_MASK(0, 32)); 531698240d1SRichard Henderson } 532698240d1SRichard Henderson 5336fd0c7bcSRichard Henderson static void copy_iaoq_entry(DisasContext *ctx, TCGv_i64 dest, 5346fd0c7bcSRichard Henderson uint64_t ival, TCGv_i64 vval) 53561766fe9SRichard Henderson { 536c53e401eSRichard Henderson uint64_t mask = gva_offset_mask(ctx); 537f13bf343SRichard Henderson 538f13bf343SRichard Henderson if (ival != -1) { 5396fd0c7bcSRichard Henderson tcg_gen_movi_i64(dest, ival & mask); 540f13bf343SRichard Henderson return; 541f13bf343SRichard Henderson } 542f13bf343SRichard Henderson tcg_debug_assert(vval != NULL); 543f13bf343SRichard Henderson 544f13bf343SRichard Henderson /* 545f13bf343SRichard Henderson * We know that the IAOQ is already properly masked. 546f13bf343SRichard Henderson * This optimization is primarily for "iaoq_f = iaoq_b". 547f13bf343SRichard Henderson */ 548f13bf343SRichard Henderson if (vval == cpu_iaoq_f || vval == cpu_iaoq_b) { 5496fd0c7bcSRichard Henderson tcg_gen_mov_i64(dest, vval); 55061766fe9SRichard Henderson } else { 5516fd0c7bcSRichard Henderson tcg_gen_andi_i64(dest, vval, mask); 55261766fe9SRichard Henderson } 55361766fe9SRichard Henderson } 55461766fe9SRichard Henderson 555c53e401eSRichard Henderson static inline uint64_t iaoq_dest(DisasContext *ctx, int64_t disp) 55661766fe9SRichard Henderson { 55761766fe9SRichard Henderson return ctx->iaoq_f + disp + 8; 55861766fe9SRichard Henderson } 55961766fe9SRichard Henderson 56061766fe9SRichard Henderson static void gen_excp_1(int exception) 56161766fe9SRichard Henderson { 562ad75a51eSRichard Henderson gen_helper_excp(tcg_env, tcg_constant_i32(exception)); 56361766fe9SRichard Henderson } 56461766fe9SRichard Henderson 56531234768SRichard Henderson static void gen_excp(DisasContext *ctx, int exception) 56661766fe9SRichard Henderson { 567741322f4SRichard Henderson copy_iaoq_entry(ctx, cpu_iaoq_f, ctx->iaoq_f, cpu_iaoq_f); 568741322f4SRichard Henderson copy_iaoq_entry(ctx, cpu_iaoq_b, ctx->iaoq_b, cpu_iaoq_b); 569129e9cc3SRichard Henderson nullify_save(ctx); 57061766fe9SRichard Henderson gen_excp_1(exception); 57131234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 57261766fe9SRichard Henderson } 57361766fe9SRichard Henderson 57431234768SRichard Henderson static bool gen_excp_iir(DisasContext *ctx, int exc) 5751a19da0dSRichard Henderson { 57631234768SRichard Henderson nullify_over(ctx); 5776fd0c7bcSRichard Henderson tcg_gen_st_i64(tcg_constant_i64(ctx->insn), 578ad75a51eSRichard Henderson tcg_env, offsetof(CPUHPPAState, cr[CR_IIR])); 57931234768SRichard Henderson gen_excp(ctx, exc); 58031234768SRichard Henderson return nullify_end(ctx); 5811a19da0dSRichard Henderson } 5821a19da0dSRichard Henderson 58331234768SRichard Henderson static bool gen_illegal(DisasContext *ctx) 58461766fe9SRichard Henderson { 58531234768SRichard Henderson return gen_excp_iir(ctx, EXCP_ILL); 58661766fe9SRichard Henderson } 58761766fe9SRichard Henderson 58840f9f908SRichard Henderson #ifdef CONFIG_USER_ONLY 58940f9f908SRichard Henderson #define CHECK_MOST_PRIVILEGED(EXCP) \ 59040f9f908SRichard Henderson return gen_excp_iir(ctx, EXCP) 59140f9f908SRichard Henderson #else 592e1b5a5edSRichard Henderson #define CHECK_MOST_PRIVILEGED(EXCP) \ 593e1b5a5edSRichard Henderson do { \ 594e1b5a5edSRichard Henderson if (ctx->privilege != 0) { \ 59531234768SRichard Henderson return gen_excp_iir(ctx, EXCP); \ 596e1b5a5edSRichard Henderson } \ 597e1b5a5edSRichard Henderson } while (0) 59840f9f908SRichard Henderson #endif 599e1b5a5edSRichard Henderson 600c53e401eSRichard Henderson static bool use_goto_tb(DisasContext *ctx, uint64_t dest) 60161766fe9SRichard Henderson { 60257f91498SRichard Henderson return translator_use_goto_tb(&ctx->base, dest); 60361766fe9SRichard Henderson } 60461766fe9SRichard Henderson 605129e9cc3SRichard Henderson /* If the next insn is to be nullified, and it's on the same page, 606129e9cc3SRichard Henderson and we're not attempting to set a breakpoint on it, then we can 607129e9cc3SRichard Henderson totally skip the nullified insn. This avoids creating and 608129e9cc3SRichard Henderson executing a TB that merely branches to the next TB. */ 609129e9cc3SRichard Henderson static bool use_nullify_skip(DisasContext *ctx) 610129e9cc3SRichard Henderson { 611129e9cc3SRichard Henderson return (((ctx->iaoq_b ^ ctx->iaoq_f) & TARGET_PAGE_MASK) == 0 612129e9cc3SRichard Henderson && !cpu_breakpoint_test(ctx->cs, ctx->iaoq_b, BP_ANY)); 613129e9cc3SRichard Henderson } 614129e9cc3SRichard Henderson 61561766fe9SRichard Henderson static void gen_goto_tb(DisasContext *ctx, int which, 616c53e401eSRichard Henderson uint64_t f, uint64_t b) 61761766fe9SRichard Henderson { 61861766fe9SRichard Henderson if (f != -1 && b != -1 && use_goto_tb(ctx, f)) { 61961766fe9SRichard Henderson tcg_gen_goto_tb(which); 620a0180973SRichard Henderson copy_iaoq_entry(ctx, cpu_iaoq_f, f, NULL); 621a0180973SRichard Henderson copy_iaoq_entry(ctx, cpu_iaoq_b, b, NULL); 62207ea28b4SRichard Henderson tcg_gen_exit_tb(ctx->base.tb, which); 62361766fe9SRichard Henderson } else { 624741322f4SRichard Henderson copy_iaoq_entry(ctx, cpu_iaoq_f, f, cpu_iaoq_b); 625741322f4SRichard Henderson copy_iaoq_entry(ctx, cpu_iaoq_b, b, ctx->iaoq_n_var); 6267f11636dSEmilio G. Cota tcg_gen_lookup_and_goto_ptr(); 62761766fe9SRichard Henderson } 62861766fe9SRichard Henderson } 62961766fe9SRichard Henderson 630b47a4a02SSven Schnelle static bool cond_need_sv(int c) 631b47a4a02SSven Schnelle { 632b47a4a02SSven Schnelle return c == 2 || c == 3 || c == 6; 633b47a4a02SSven Schnelle } 634b47a4a02SSven Schnelle 635b47a4a02SSven Schnelle static bool cond_need_cb(int c) 636b47a4a02SSven Schnelle { 637b47a4a02SSven Schnelle return c == 4 || c == 5; 638b47a4a02SSven Schnelle } 639b47a4a02SSven Schnelle 6406fd0c7bcSRichard Henderson /* Need extensions from TCGv_i32 to TCGv_i64. */ 64172ca8753SRichard Henderson static bool cond_need_ext(DisasContext *ctx, bool d) 64272ca8753SRichard Henderson { 643c53e401eSRichard Henderson return !(ctx->is_pa20 && d); 64472ca8753SRichard Henderson } 64572ca8753SRichard Henderson 646b47a4a02SSven Schnelle /* 647b47a4a02SSven Schnelle * Compute conditional for arithmetic. See Page 5-3, Table 5-1, of 648b47a4a02SSven Schnelle * the Parisc 1.1 Architecture Reference Manual for details. 649b47a4a02SSven Schnelle */ 650b2167459SRichard Henderson 651a751eb31SRichard Henderson static DisasCond do_cond(DisasContext *ctx, unsigned cf, bool d, 6526fd0c7bcSRichard Henderson TCGv_i64 res, TCGv_i64 cb_msb, TCGv_i64 sv) 653b2167459SRichard Henderson { 654b2167459SRichard Henderson DisasCond cond; 6556fd0c7bcSRichard Henderson TCGv_i64 tmp; 656b2167459SRichard Henderson 657b2167459SRichard Henderson switch (cf >> 1) { 658b47a4a02SSven Schnelle case 0: /* Never / TR (0 / 1) */ 659b2167459SRichard Henderson cond = cond_make_f(); 660b2167459SRichard Henderson break; 661b2167459SRichard Henderson case 1: /* = / <> (Z / !Z) */ 662a751eb31SRichard Henderson if (cond_need_ext(ctx, d)) { 663aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 6646fd0c7bcSRichard Henderson tcg_gen_ext32u_i64(tmp, res); 665a751eb31SRichard Henderson res = tmp; 666a751eb31SRichard Henderson } 667b2167459SRichard Henderson cond = cond_make_0(TCG_COND_EQ, res); 668b2167459SRichard Henderson break; 669b47a4a02SSven Schnelle case 2: /* < / >= (N ^ V / !(N ^ V) */ 670aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 6716fd0c7bcSRichard Henderson tcg_gen_xor_i64(tmp, res, sv); 672a751eb31SRichard Henderson if (cond_need_ext(ctx, d)) { 6736fd0c7bcSRichard Henderson tcg_gen_ext32s_i64(tmp, tmp); 674a751eb31SRichard Henderson } 675b47a4a02SSven Schnelle cond = cond_make_0_tmp(TCG_COND_LT, tmp); 676b2167459SRichard Henderson break; 677b47a4a02SSven Schnelle case 3: /* <= / > (N ^ V) | Z / !((N ^ V) | Z) */ 678b47a4a02SSven Schnelle /* 679b47a4a02SSven Schnelle * Simplify: 680b47a4a02SSven Schnelle * (N ^ V) | Z 681b47a4a02SSven Schnelle * ((res < 0) ^ (sv < 0)) | !res 682b47a4a02SSven Schnelle * ((res ^ sv) < 0) | !res 683b47a4a02SSven Schnelle * (~(res ^ sv) >= 0) | !res 684b47a4a02SSven Schnelle * !(~(res ^ sv) >> 31) | !res 685b47a4a02SSven Schnelle * !(~(res ^ sv) >> 31 & res) 686b47a4a02SSven Schnelle */ 687aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 6886fd0c7bcSRichard Henderson tcg_gen_eqv_i64(tmp, res, sv); 689a751eb31SRichard Henderson if (cond_need_ext(ctx, d)) { 6906fd0c7bcSRichard Henderson tcg_gen_sextract_i64(tmp, tmp, 31, 1); 6916fd0c7bcSRichard Henderson tcg_gen_and_i64(tmp, tmp, res); 6926fd0c7bcSRichard Henderson tcg_gen_ext32u_i64(tmp, tmp); 693a751eb31SRichard Henderson } else { 6946fd0c7bcSRichard Henderson tcg_gen_sari_i64(tmp, tmp, 63); 6956fd0c7bcSRichard Henderson tcg_gen_and_i64(tmp, tmp, res); 696a751eb31SRichard Henderson } 697b47a4a02SSven Schnelle cond = cond_make_0_tmp(TCG_COND_EQ, tmp); 698b2167459SRichard Henderson break; 699b2167459SRichard Henderson case 4: /* NUV / UV (!C / C) */ 700a751eb31SRichard Henderson /* Only bit 0 of cb_msb is ever set. */ 701b2167459SRichard Henderson cond = cond_make_0(TCG_COND_EQ, cb_msb); 702b2167459SRichard Henderson break; 703b2167459SRichard Henderson case 5: /* ZNV / VNZ (!C | Z / C & !Z) */ 704aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 7056fd0c7bcSRichard Henderson tcg_gen_neg_i64(tmp, cb_msb); 7066fd0c7bcSRichard Henderson tcg_gen_and_i64(tmp, tmp, res); 707a751eb31SRichard Henderson if (cond_need_ext(ctx, d)) { 7086fd0c7bcSRichard Henderson tcg_gen_ext32u_i64(tmp, tmp); 709a751eb31SRichard Henderson } 710b47a4a02SSven Schnelle cond = cond_make_0_tmp(TCG_COND_EQ, tmp); 711b2167459SRichard Henderson break; 712b2167459SRichard Henderson case 6: /* SV / NSV (V / !V) */ 713a751eb31SRichard Henderson if (cond_need_ext(ctx, d)) { 714aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 7156fd0c7bcSRichard Henderson tcg_gen_ext32s_i64(tmp, sv); 716a751eb31SRichard Henderson sv = tmp; 717a751eb31SRichard Henderson } 718b2167459SRichard Henderson cond = cond_make_0(TCG_COND_LT, sv); 719b2167459SRichard Henderson break; 720b2167459SRichard Henderson case 7: /* OD / EV */ 721aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 7226fd0c7bcSRichard Henderson tcg_gen_andi_i64(tmp, res, 1); 723b47a4a02SSven Schnelle cond = cond_make_0_tmp(TCG_COND_NE, tmp); 724b2167459SRichard Henderson break; 725b2167459SRichard Henderson default: 726b2167459SRichard Henderson g_assert_not_reached(); 727b2167459SRichard Henderson } 728b2167459SRichard Henderson if (cf & 1) { 729b2167459SRichard Henderson cond.c = tcg_invert_cond(cond.c); 730b2167459SRichard Henderson } 731b2167459SRichard Henderson 732b2167459SRichard Henderson return cond; 733b2167459SRichard Henderson } 734b2167459SRichard Henderson 735b2167459SRichard Henderson /* Similar, but for the special case of subtraction without borrow, we 736b2167459SRichard Henderson can use the inputs directly. This can allow other computation to be 737b2167459SRichard Henderson deleted as unused. */ 738b2167459SRichard Henderson 7394fe9533aSRichard Henderson static DisasCond do_sub_cond(DisasContext *ctx, unsigned cf, bool d, 7406fd0c7bcSRichard Henderson TCGv_i64 res, TCGv_i64 in1, 7416fd0c7bcSRichard Henderson TCGv_i64 in2, TCGv_i64 sv) 742b2167459SRichard Henderson { 7434fe9533aSRichard Henderson TCGCond tc; 7444fe9533aSRichard Henderson bool ext_uns; 745b2167459SRichard Henderson 746b2167459SRichard Henderson switch (cf >> 1) { 747b2167459SRichard Henderson case 1: /* = / <> */ 7484fe9533aSRichard Henderson tc = TCG_COND_EQ; 7494fe9533aSRichard Henderson ext_uns = true; 750b2167459SRichard Henderson break; 751b2167459SRichard Henderson case 2: /* < / >= */ 7524fe9533aSRichard Henderson tc = TCG_COND_LT; 7534fe9533aSRichard Henderson ext_uns = false; 754b2167459SRichard Henderson break; 755b2167459SRichard Henderson case 3: /* <= / > */ 7564fe9533aSRichard Henderson tc = TCG_COND_LE; 7574fe9533aSRichard Henderson ext_uns = false; 758b2167459SRichard Henderson break; 759b2167459SRichard Henderson case 4: /* << / >>= */ 7604fe9533aSRichard Henderson tc = TCG_COND_LTU; 7614fe9533aSRichard Henderson ext_uns = true; 762b2167459SRichard Henderson break; 763b2167459SRichard Henderson case 5: /* <<= / >> */ 7644fe9533aSRichard Henderson tc = TCG_COND_LEU; 7654fe9533aSRichard Henderson ext_uns = true; 766b2167459SRichard Henderson break; 767b2167459SRichard Henderson default: 768a751eb31SRichard Henderson return do_cond(ctx, cf, d, res, NULL, sv); 769b2167459SRichard Henderson } 770b2167459SRichard Henderson 7714fe9533aSRichard Henderson if (cf & 1) { 7724fe9533aSRichard Henderson tc = tcg_invert_cond(tc); 7734fe9533aSRichard Henderson } 7744fe9533aSRichard Henderson if (cond_need_ext(ctx, d)) { 775aac0f603SRichard Henderson TCGv_i64 t1 = tcg_temp_new_i64(); 776aac0f603SRichard Henderson TCGv_i64 t2 = tcg_temp_new_i64(); 7774fe9533aSRichard Henderson 7784fe9533aSRichard Henderson if (ext_uns) { 7796fd0c7bcSRichard Henderson tcg_gen_ext32u_i64(t1, in1); 7806fd0c7bcSRichard Henderson tcg_gen_ext32u_i64(t2, in2); 7814fe9533aSRichard Henderson } else { 7826fd0c7bcSRichard Henderson tcg_gen_ext32s_i64(t1, in1); 7836fd0c7bcSRichard Henderson tcg_gen_ext32s_i64(t2, in2); 7844fe9533aSRichard Henderson } 7854fe9533aSRichard Henderson return cond_make_tmp(tc, t1, t2); 7864fe9533aSRichard Henderson } 7874fe9533aSRichard Henderson return cond_make(tc, in1, in2); 788b2167459SRichard Henderson } 789b2167459SRichard Henderson 790df0232feSRichard Henderson /* 791df0232feSRichard Henderson * Similar, but for logicals, where the carry and overflow bits are not 792df0232feSRichard Henderson * computed, and use of them is undefined. 793df0232feSRichard Henderson * 794df0232feSRichard Henderson * Undefined or not, hardware does not trap. It seems reasonable to 795df0232feSRichard Henderson * assume hardware treats cases c={4,5,6} as if C=0 & V=0, since that's 796df0232feSRichard Henderson * how cases c={2,3} are treated. 797df0232feSRichard Henderson */ 798b2167459SRichard Henderson 799b5af8423SRichard Henderson static DisasCond do_log_cond(DisasContext *ctx, unsigned cf, bool d, 8006fd0c7bcSRichard Henderson TCGv_i64 res) 801b2167459SRichard Henderson { 802b5af8423SRichard Henderson TCGCond tc; 803b5af8423SRichard Henderson bool ext_uns; 804a751eb31SRichard Henderson 805df0232feSRichard Henderson switch (cf) { 806df0232feSRichard Henderson case 0: /* never */ 807df0232feSRichard Henderson case 9: /* undef, C */ 808df0232feSRichard Henderson case 11: /* undef, C & !Z */ 809df0232feSRichard Henderson case 12: /* undef, V */ 810df0232feSRichard Henderson return cond_make_f(); 811df0232feSRichard Henderson 812df0232feSRichard Henderson case 1: /* true */ 813df0232feSRichard Henderson case 8: /* undef, !C */ 814df0232feSRichard Henderson case 10: /* undef, !C | Z */ 815df0232feSRichard Henderson case 13: /* undef, !V */ 816df0232feSRichard Henderson return cond_make_t(); 817df0232feSRichard Henderson 818df0232feSRichard Henderson case 2: /* == */ 819b5af8423SRichard Henderson tc = TCG_COND_EQ; 820b5af8423SRichard Henderson ext_uns = true; 821b5af8423SRichard Henderson break; 822df0232feSRichard Henderson case 3: /* <> */ 823b5af8423SRichard Henderson tc = TCG_COND_NE; 824b5af8423SRichard Henderson ext_uns = true; 825b5af8423SRichard Henderson break; 826df0232feSRichard Henderson case 4: /* < */ 827b5af8423SRichard Henderson tc = TCG_COND_LT; 828b5af8423SRichard Henderson ext_uns = false; 829b5af8423SRichard Henderson break; 830df0232feSRichard Henderson case 5: /* >= */ 831b5af8423SRichard Henderson tc = TCG_COND_GE; 832b5af8423SRichard Henderson ext_uns = false; 833b5af8423SRichard Henderson break; 834df0232feSRichard Henderson case 6: /* <= */ 835b5af8423SRichard Henderson tc = TCG_COND_LE; 836b5af8423SRichard Henderson ext_uns = false; 837b5af8423SRichard Henderson break; 838df0232feSRichard Henderson case 7: /* > */ 839b5af8423SRichard Henderson tc = TCG_COND_GT; 840b5af8423SRichard Henderson ext_uns = false; 841b5af8423SRichard Henderson break; 842df0232feSRichard Henderson 843df0232feSRichard Henderson case 14: /* OD */ 844df0232feSRichard Henderson case 15: /* EV */ 845a751eb31SRichard Henderson return do_cond(ctx, cf, d, res, NULL, NULL); 846df0232feSRichard Henderson 847df0232feSRichard Henderson default: 848df0232feSRichard Henderson g_assert_not_reached(); 849b2167459SRichard Henderson } 850b5af8423SRichard Henderson 851b5af8423SRichard Henderson if (cond_need_ext(ctx, d)) { 852aac0f603SRichard Henderson TCGv_i64 tmp = tcg_temp_new_i64(); 853b5af8423SRichard Henderson 854b5af8423SRichard Henderson if (ext_uns) { 8556fd0c7bcSRichard Henderson tcg_gen_ext32u_i64(tmp, res); 856b5af8423SRichard Henderson } else { 8576fd0c7bcSRichard Henderson tcg_gen_ext32s_i64(tmp, res); 858b5af8423SRichard Henderson } 859b5af8423SRichard Henderson return cond_make_0_tmp(tc, tmp); 860b5af8423SRichard Henderson } 861b5af8423SRichard Henderson return cond_make_0(tc, res); 862b2167459SRichard Henderson } 863b2167459SRichard Henderson 86498cd9ca7SRichard Henderson /* Similar, but for shift/extract/deposit conditions. */ 86598cd9ca7SRichard Henderson 8664fa52edfSRichard Henderson static DisasCond do_sed_cond(DisasContext *ctx, unsigned orig, bool d, 8676fd0c7bcSRichard Henderson TCGv_i64 res) 86898cd9ca7SRichard Henderson { 86998cd9ca7SRichard Henderson unsigned c, f; 87098cd9ca7SRichard Henderson 87198cd9ca7SRichard Henderson /* Convert the compressed condition codes to standard. 87298cd9ca7SRichard Henderson 0-2 are the same as logicals (nv,<,<=), while 3 is OD. 87398cd9ca7SRichard Henderson 4-7 are the reverse of 0-3. */ 87498cd9ca7SRichard Henderson c = orig & 3; 87598cd9ca7SRichard Henderson if (c == 3) { 87698cd9ca7SRichard Henderson c = 7; 87798cd9ca7SRichard Henderson } 87898cd9ca7SRichard Henderson f = (orig & 4) / 4; 87998cd9ca7SRichard Henderson 880b5af8423SRichard Henderson return do_log_cond(ctx, c * 2 + f, d, res); 88198cd9ca7SRichard Henderson } 88298cd9ca7SRichard Henderson 883b2167459SRichard Henderson /* Similar, but for unit conditions. */ 884b2167459SRichard Henderson 8856fd0c7bcSRichard Henderson static DisasCond do_unit_cond(unsigned cf, bool d, TCGv_i64 res, 8866fd0c7bcSRichard Henderson TCGv_i64 in1, TCGv_i64 in2) 887b2167459SRichard Henderson { 888b2167459SRichard Henderson DisasCond cond; 8896fd0c7bcSRichard Henderson TCGv_i64 tmp, cb = NULL; 890c53e401eSRichard Henderson uint64_t d_repl = d ? 0x0000000100000001ull : 1; 891b2167459SRichard Henderson 892b2167459SRichard Henderson if (cf & 8) { 893b2167459SRichard Henderson /* Since we want to test lots of carry-out bits all at once, do not 894b2167459SRichard Henderson * do our normal thing and compute carry-in of bit B+1 since that 895b2167459SRichard Henderson * leaves us with carry bits spread across two words. 896b2167459SRichard Henderson */ 897aac0f603SRichard Henderson cb = tcg_temp_new_i64(); 898aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 8996fd0c7bcSRichard Henderson tcg_gen_or_i64(cb, in1, in2); 9006fd0c7bcSRichard Henderson tcg_gen_and_i64(tmp, in1, in2); 9016fd0c7bcSRichard Henderson tcg_gen_andc_i64(cb, cb, res); 9026fd0c7bcSRichard Henderson tcg_gen_or_i64(cb, cb, tmp); 903b2167459SRichard Henderson } 904b2167459SRichard Henderson 905b2167459SRichard Henderson switch (cf >> 1) { 906b2167459SRichard Henderson case 0: /* never / TR */ 907b2167459SRichard Henderson case 1: /* undefined */ 908b2167459SRichard Henderson case 5: /* undefined */ 909b2167459SRichard Henderson cond = cond_make_f(); 910b2167459SRichard Henderson break; 911b2167459SRichard Henderson 912b2167459SRichard Henderson case 2: /* SBZ / NBZ */ 913b2167459SRichard Henderson /* See hasless(v,1) from 914b2167459SRichard Henderson * https://graphics.stanford.edu/~seander/bithacks.html#ZeroInWord 915b2167459SRichard Henderson */ 916aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 9176fd0c7bcSRichard Henderson tcg_gen_subi_i64(tmp, res, d_repl * 0x01010101u); 9186fd0c7bcSRichard Henderson tcg_gen_andc_i64(tmp, tmp, res); 9196fd0c7bcSRichard Henderson tcg_gen_andi_i64(tmp, tmp, d_repl * 0x80808080u); 920b2167459SRichard Henderson cond = cond_make_0(TCG_COND_NE, tmp); 921b2167459SRichard Henderson break; 922b2167459SRichard Henderson 923b2167459SRichard Henderson case 3: /* SHZ / NHZ */ 924aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 9256fd0c7bcSRichard Henderson tcg_gen_subi_i64(tmp, res, d_repl * 0x00010001u); 9266fd0c7bcSRichard Henderson tcg_gen_andc_i64(tmp, tmp, res); 9276fd0c7bcSRichard Henderson tcg_gen_andi_i64(tmp, tmp, d_repl * 0x80008000u); 928b2167459SRichard Henderson cond = cond_make_0(TCG_COND_NE, tmp); 929b2167459SRichard Henderson break; 930b2167459SRichard Henderson 931b2167459SRichard Henderson case 4: /* SDC / NDC */ 9326fd0c7bcSRichard Henderson tcg_gen_andi_i64(cb, cb, d_repl * 0x88888888u); 933b2167459SRichard Henderson cond = cond_make_0(TCG_COND_NE, cb); 934b2167459SRichard Henderson break; 935b2167459SRichard Henderson 936b2167459SRichard Henderson case 6: /* SBC / NBC */ 9376fd0c7bcSRichard Henderson tcg_gen_andi_i64(cb, cb, d_repl * 0x80808080u); 938b2167459SRichard Henderson cond = cond_make_0(TCG_COND_NE, cb); 939b2167459SRichard Henderson break; 940b2167459SRichard Henderson 941b2167459SRichard Henderson case 7: /* SHC / NHC */ 9426fd0c7bcSRichard Henderson tcg_gen_andi_i64(cb, cb, d_repl * 0x80008000u); 943b2167459SRichard Henderson cond = cond_make_0(TCG_COND_NE, cb); 944b2167459SRichard Henderson break; 945b2167459SRichard Henderson 946b2167459SRichard Henderson default: 947b2167459SRichard Henderson g_assert_not_reached(); 948b2167459SRichard Henderson } 949b2167459SRichard Henderson if (cf & 1) { 950b2167459SRichard Henderson cond.c = tcg_invert_cond(cond.c); 951b2167459SRichard Henderson } 952b2167459SRichard Henderson 953b2167459SRichard Henderson return cond; 954b2167459SRichard Henderson } 955b2167459SRichard Henderson 9566fd0c7bcSRichard Henderson static TCGv_i64 get_carry(DisasContext *ctx, bool d, 9576fd0c7bcSRichard Henderson TCGv_i64 cb, TCGv_i64 cb_msb) 95872ca8753SRichard Henderson { 95972ca8753SRichard Henderson if (cond_need_ext(ctx, d)) { 960aac0f603SRichard Henderson TCGv_i64 t = tcg_temp_new_i64(); 9616fd0c7bcSRichard Henderson tcg_gen_extract_i64(t, cb, 32, 1); 96272ca8753SRichard Henderson return t; 96372ca8753SRichard Henderson } 96472ca8753SRichard Henderson return cb_msb; 96572ca8753SRichard Henderson } 96672ca8753SRichard Henderson 9676fd0c7bcSRichard Henderson static TCGv_i64 get_psw_carry(DisasContext *ctx, bool d) 96872ca8753SRichard Henderson { 96972ca8753SRichard Henderson return get_carry(ctx, d, cpu_psw_cb, cpu_psw_cb_msb); 97072ca8753SRichard Henderson } 97172ca8753SRichard Henderson 972b2167459SRichard Henderson /* Compute signed overflow for addition. */ 9736fd0c7bcSRichard Henderson static TCGv_i64 do_add_sv(DisasContext *ctx, TCGv_i64 res, 9746fd0c7bcSRichard Henderson TCGv_i64 in1, TCGv_i64 in2) 975b2167459SRichard Henderson { 976aac0f603SRichard Henderson TCGv_i64 sv = tcg_temp_new_i64(); 977aac0f603SRichard Henderson TCGv_i64 tmp = tcg_temp_new_i64(); 978b2167459SRichard Henderson 9796fd0c7bcSRichard Henderson tcg_gen_xor_i64(sv, res, in1); 9806fd0c7bcSRichard Henderson tcg_gen_xor_i64(tmp, in1, in2); 9816fd0c7bcSRichard Henderson tcg_gen_andc_i64(sv, sv, tmp); 982b2167459SRichard Henderson 983b2167459SRichard Henderson return sv; 984b2167459SRichard Henderson } 985b2167459SRichard Henderson 986b2167459SRichard Henderson /* Compute signed overflow for subtraction. */ 9876fd0c7bcSRichard Henderson static TCGv_i64 do_sub_sv(DisasContext *ctx, TCGv_i64 res, 9886fd0c7bcSRichard Henderson TCGv_i64 in1, TCGv_i64 in2) 989b2167459SRichard Henderson { 990aac0f603SRichard Henderson TCGv_i64 sv = tcg_temp_new_i64(); 991aac0f603SRichard Henderson TCGv_i64 tmp = tcg_temp_new_i64(); 992b2167459SRichard Henderson 9936fd0c7bcSRichard Henderson tcg_gen_xor_i64(sv, res, in1); 9946fd0c7bcSRichard Henderson tcg_gen_xor_i64(tmp, in1, in2); 9956fd0c7bcSRichard Henderson tcg_gen_and_i64(sv, sv, tmp); 996b2167459SRichard Henderson 997b2167459SRichard Henderson return sv; 998b2167459SRichard Henderson } 999b2167459SRichard Henderson 10006fd0c7bcSRichard Henderson static void do_add(DisasContext *ctx, unsigned rt, TCGv_i64 in1, 10016fd0c7bcSRichard Henderson TCGv_i64 in2, unsigned shift, bool is_l, 1002faf97ba1SRichard Henderson bool is_tsv, bool is_tc, bool is_c, unsigned cf, bool d) 1003b2167459SRichard Henderson { 10046fd0c7bcSRichard Henderson TCGv_i64 dest, cb, cb_msb, cb_cond, sv, tmp; 1005b2167459SRichard Henderson unsigned c = cf >> 1; 1006b2167459SRichard Henderson DisasCond cond; 1007b2167459SRichard Henderson 1008aac0f603SRichard Henderson dest = tcg_temp_new_i64(); 1009f764718dSRichard Henderson cb = NULL; 1010f764718dSRichard Henderson cb_msb = NULL; 1011bdcccc17SRichard Henderson cb_cond = NULL; 1012b2167459SRichard Henderson 1013b2167459SRichard Henderson if (shift) { 1014aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 10156fd0c7bcSRichard Henderson tcg_gen_shli_i64(tmp, in1, shift); 1016b2167459SRichard Henderson in1 = tmp; 1017b2167459SRichard Henderson } 1018b2167459SRichard Henderson 1019b47a4a02SSven Schnelle if (!is_l || cond_need_cb(c)) { 1020aac0f603SRichard Henderson cb_msb = tcg_temp_new_i64(); 1021aac0f603SRichard Henderson cb = tcg_temp_new_i64(); 1022bdcccc17SRichard Henderson 1023a4db4a78SRichard Henderson tcg_gen_add2_i64(dest, cb_msb, in1, ctx->zero, in2, ctx->zero); 1024b2167459SRichard Henderson if (is_c) { 10256fd0c7bcSRichard Henderson tcg_gen_add2_i64(dest, cb_msb, dest, cb_msb, 1026a4db4a78SRichard Henderson get_psw_carry(ctx, d), ctx->zero); 1027b2167459SRichard Henderson } 10286fd0c7bcSRichard Henderson tcg_gen_xor_i64(cb, in1, in2); 10296fd0c7bcSRichard Henderson tcg_gen_xor_i64(cb, cb, dest); 1030bdcccc17SRichard Henderson if (cond_need_cb(c)) { 1031bdcccc17SRichard Henderson cb_cond = get_carry(ctx, d, cb, cb_msb); 1032b2167459SRichard Henderson } 1033b2167459SRichard Henderson } else { 10346fd0c7bcSRichard Henderson tcg_gen_add_i64(dest, in1, in2); 1035b2167459SRichard Henderson if (is_c) { 10366fd0c7bcSRichard Henderson tcg_gen_add_i64(dest, dest, get_psw_carry(ctx, d)); 1037b2167459SRichard Henderson } 1038b2167459SRichard Henderson } 1039b2167459SRichard Henderson 1040b2167459SRichard Henderson /* Compute signed overflow if required. */ 1041f764718dSRichard Henderson sv = NULL; 1042b47a4a02SSven Schnelle if (is_tsv || cond_need_sv(c)) { 1043b2167459SRichard Henderson sv = do_add_sv(ctx, dest, in1, in2); 1044b2167459SRichard Henderson if (is_tsv) { 1045b2167459SRichard Henderson /* ??? Need to include overflow from shift. */ 1046ad75a51eSRichard Henderson gen_helper_tsv(tcg_env, sv); 1047b2167459SRichard Henderson } 1048b2167459SRichard Henderson } 1049b2167459SRichard Henderson 1050b2167459SRichard Henderson /* Emit any conditional trap before any writeback. */ 1051a751eb31SRichard Henderson cond = do_cond(ctx, cf, d, dest, cb_cond, sv); 1052b2167459SRichard Henderson if (is_tc) { 1053aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 10546fd0c7bcSRichard Henderson tcg_gen_setcond_i64(cond.c, tmp, cond.a0, cond.a1); 1055ad75a51eSRichard Henderson gen_helper_tcond(tcg_env, tmp); 1056b2167459SRichard Henderson } 1057b2167459SRichard Henderson 1058b2167459SRichard Henderson /* Write back the result. */ 1059b2167459SRichard Henderson if (!is_l) { 1060b2167459SRichard Henderson save_or_nullify(ctx, cpu_psw_cb, cb); 1061b2167459SRichard Henderson save_or_nullify(ctx, cpu_psw_cb_msb, cb_msb); 1062b2167459SRichard Henderson } 1063b2167459SRichard Henderson save_gpr(ctx, rt, dest); 1064b2167459SRichard Henderson 1065b2167459SRichard Henderson /* Install the new nullification. */ 1066b2167459SRichard Henderson cond_free(&ctx->null_cond); 1067b2167459SRichard Henderson ctx->null_cond = cond; 1068b2167459SRichard Henderson } 1069b2167459SRichard Henderson 1070faf97ba1SRichard Henderson static bool do_add_reg(DisasContext *ctx, arg_rrr_cf_d_sh *a, 10710c982a28SRichard Henderson bool is_l, bool is_tsv, bool is_tc, bool is_c) 10720c982a28SRichard Henderson { 10736fd0c7bcSRichard Henderson TCGv_i64 tcg_r1, tcg_r2; 10740c982a28SRichard Henderson 10750c982a28SRichard Henderson if (a->cf) { 10760c982a28SRichard Henderson nullify_over(ctx); 10770c982a28SRichard Henderson } 10780c982a28SRichard Henderson tcg_r1 = load_gpr(ctx, a->r1); 10790c982a28SRichard Henderson tcg_r2 = load_gpr(ctx, a->r2); 1080faf97ba1SRichard Henderson do_add(ctx, a->t, tcg_r1, tcg_r2, a->sh, is_l, 1081faf97ba1SRichard Henderson is_tsv, is_tc, is_c, a->cf, a->d); 10820c982a28SRichard Henderson return nullify_end(ctx); 10830c982a28SRichard Henderson } 10840c982a28SRichard Henderson 10850588e061SRichard Henderson static bool do_add_imm(DisasContext *ctx, arg_rri_cf *a, 10860588e061SRichard Henderson bool is_tsv, bool is_tc) 10870588e061SRichard Henderson { 10886fd0c7bcSRichard Henderson TCGv_i64 tcg_im, tcg_r2; 10890588e061SRichard Henderson 10900588e061SRichard Henderson if (a->cf) { 10910588e061SRichard Henderson nullify_over(ctx); 10920588e061SRichard Henderson } 10936fd0c7bcSRichard Henderson tcg_im = tcg_constant_i64(a->i); 10940588e061SRichard Henderson tcg_r2 = load_gpr(ctx, a->r); 1095faf97ba1SRichard Henderson /* All ADDI conditions are 32-bit. */ 1096faf97ba1SRichard Henderson do_add(ctx, a->t, tcg_im, tcg_r2, 0, 0, is_tsv, is_tc, 0, a->cf, false); 10970588e061SRichard Henderson return nullify_end(ctx); 10980588e061SRichard Henderson } 10990588e061SRichard Henderson 11006fd0c7bcSRichard Henderson static void do_sub(DisasContext *ctx, unsigned rt, TCGv_i64 in1, 11016fd0c7bcSRichard Henderson TCGv_i64 in2, bool is_tsv, bool is_b, 110263c427c6SRichard Henderson bool is_tc, unsigned cf, bool d) 1103b2167459SRichard Henderson { 1104a4db4a78SRichard Henderson TCGv_i64 dest, sv, cb, cb_msb, tmp; 1105b2167459SRichard Henderson unsigned c = cf >> 1; 1106b2167459SRichard Henderson DisasCond cond; 1107b2167459SRichard Henderson 1108aac0f603SRichard Henderson dest = tcg_temp_new_i64(); 1109aac0f603SRichard Henderson cb = tcg_temp_new_i64(); 1110aac0f603SRichard Henderson cb_msb = tcg_temp_new_i64(); 1111b2167459SRichard Henderson 1112b2167459SRichard Henderson if (is_b) { 1113b2167459SRichard Henderson /* DEST,C = IN1 + ~IN2 + C. */ 11146fd0c7bcSRichard Henderson tcg_gen_not_i64(cb, in2); 1115a4db4a78SRichard Henderson tcg_gen_add2_i64(dest, cb_msb, in1, ctx->zero, 1116a4db4a78SRichard Henderson get_psw_carry(ctx, d), ctx->zero); 1117a4db4a78SRichard Henderson tcg_gen_add2_i64(dest, cb_msb, dest, cb_msb, cb, ctx->zero); 11186fd0c7bcSRichard Henderson tcg_gen_xor_i64(cb, cb, in1); 11196fd0c7bcSRichard Henderson tcg_gen_xor_i64(cb, cb, dest); 1120b2167459SRichard Henderson } else { 1121bdcccc17SRichard Henderson /* 1122bdcccc17SRichard Henderson * DEST,C = IN1 + ~IN2 + 1. We can produce the same result in fewer 1123bdcccc17SRichard Henderson * operations by seeding the high word with 1 and subtracting. 1124bdcccc17SRichard Henderson */ 11256fd0c7bcSRichard Henderson TCGv_i64 one = tcg_constant_i64(1); 1126a4db4a78SRichard Henderson tcg_gen_sub2_i64(dest, cb_msb, in1, one, in2, ctx->zero); 11276fd0c7bcSRichard Henderson tcg_gen_eqv_i64(cb, in1, in2); 11286fd0c7bcSRichard Henderson tcg_gen_xor_i64(cb, cb, dest); 1129b2167459SRichard Henderson } 1130b2167459SRichard Henderson 1131b2167459SRichard Henderson /* Compute signed overflow if required. */ 1132f764718dSRichard Henderson sv = NULL; 1133b47a4a02SSven Schnelle if (is_tsv || cond_need_sv(c)) { 1134b2167459SRichard Henderson sv = do_sub_sv(ctx, dest, in1, in2); 1135b2167459SRichard Henderson if (is_tsv) { 1136ad75a51eSRichard Henderson gen_helper_tsv(tcg_env, sv); 1137b2167459SRichard Henderson } 1138b2167459SRichard Henderson } 1139b2167459SRichard Henderson 1140b2167459SRichard Henderson /* Compute the condition. We cannot use the special case for borrow. */ 1141b2167459SRichard Henderson if (!is_b) { 11424fe9533aSRichard Henderson cond = do_sub_cond(ctx, cf, d, dest, in1, in2, sv); 1143b2167459SRichard Henderson } else { 1144a751eb31SRichard Henderson cond = do_cond(ctx, cf, d, dest, get_carry(ctx, d, cb, cb_msb), sv); 1145b2167459SRichard Henderson } 1146b2167459SRichard Henderson 1147b2167459SRichard Henderson /* Emit any conditional trap before any writeback. */ 1148b2167459SRichard Henderson if (is_tc) { 1149aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 11506fd0c7bcSRichard Henderson tcg_gen_setcond_i64(cond.c, tmp, cond.a0, cond.a1); 1151ad75a51eSRichard Henderson gen_helper_tcond(tcg_env, tmp); 1152b2167459SRichard Henderson } 1153b2167459SRichard Henderson 1154b2167459SRichard Henderson /* Write back the result. */ 1155b2167459SRichard Henderson save_or_nullify(ctx, cpu_psw_cb, cb); 1156b2167459SRichard Henderson save_or_nullify(ctx, cpu_psw_cb_msb, cb_msb); 1157b2167459SRichard Henderson save_gpr(ctx, rt, dest); 1158b2167459SRichard Henderson 1159b2167459SRichard Henderson /* Install the new nullification. */ 1160b2167459SRichard Henderson cond_free(&ctx->null_cond); 1161b2167459SRichard Henderson ctx->null_cond = cond; 1162b2167459SRichard Henderson } 1163b2167459SRichard Henderson 116463c427c6SRichard Henderson static bool do_sub_reg(DisasContext *ctx, arg_rrr_cf_d *a, 11650c982a28SRichard Henderson bool is_tsv, bool is_b, bool is_tc) 11660c982a28SRichard Henderson { 11676fd0c7bcSRichard Henderson TCGv_i64 tcg_r1, tcg_r2; 11680c982a28SRichard Henderson 11690c982a28SRichard Henderson if (a->cf) { 11700c982a28SRichard Henderson nullify_over(ctx); 11710c982a28SRichard Henderson } 11720c982a28SRichard Henderson tcg_r1 = load_gpr(ctx, a->r1); 11730c982a28SRichard Henderson tcg_r2 = load_gpr(ctx, a->r2); 117463c427c6SRichard Henderson do_sub(ctx, a->t, tcg_r1, tcg_r2, is_tsv, is_b, is_tc, a->cf, a->d); 11750c982a28SRichard Henderson return nullify_end(ctx); 11760c982a28SRichard Henderson } 11770c982a28SRichard Henderson 11780588e061SRichard Henderson static bool do_sub_imm(DisasContext *ctx, arg_rri_cf *a, bool is_tsv) 11790588e061SRichard Henderson { 11806fd0c7bcSRichard Henderson TCGv_i64 tcg_im, tcg_r2; 11810588e061SRichard Henderson 11820588e061SRichard Henderson if (a->cf) { 11830588e061SRichard Henderson nullify_over(ctx); 11840588e061SRichard Henderson } 11856fd0c7bcSRichard Henderson tcg_im = tcg_constant_i64(a->i); 11860588e061SRichard Henderson tcg_r2 = load_gpr(ctx, a->r); 118763c427c6SRichard Henderson /* All SUBI conditions are 32-bit. */ 118863c427c6SRichard Henderson do_sub(ctx, a->t, tcg_im, tcg_r2, is_tsv, 0, 0, a->cf, false); 11890588e061SRichard Henderson return nullify_end(ctx); 11900588e061SRichard Henderson } 11910588e061SRichard Henderson 11926fd0c7bcSRichard Henderson static void do_cmpclr(DisasContext *ctx, unsigned rt, TCGv_i64 in1, 11936fd0c7bcSRichard Henderson TCGv_i64 in2, unsigned cf, bool d) 1194b2167459SRichard Henderson { 11956fd0c7bcSRichard Henderson TCGv_i64 dest, sv; 1196b2167459SRichard Henderson DisasCond cond; 1197b2167459SRichard Henderson 1198aac0f603SRichard Henderson dest = tcg_temp_new_i64(); 11996fd0c7bcSRichard Henderson tcg_gen_sub_i64(dest, in1, in2); 1200b2167459SRichard Henderson 1201b2167459SRichard Henderson /* Compute signed overflow if required. */ 1202f764718dSRichard Henderson sv = NULL; 1203b47a4a02SSven Schnelle if (cond_need_sv(cf >> 1)) { 1204b2167459SRichard Henderson sv = do_sub_sv(ctx, dest, in1, in2); 1205b2167459SRichard Henderson } 1206b2167459SRichard Henderson 1207b2167459SRichard Henderson /* Form the condition for the compare. */ 12084fe9533aSRichard Henderson cond = do_sub_cond(ctx, cf, d, dest, in1, in2, sv); 1209b2167459SRichard Henderson 1210b2167459SRichard Henderson /* Clear. */ 12116fd0c7bcSRichard Henderson tcg_gen_movi_i64(dest, 0); 1212b2167459SRichard Henderson save_gpr(ctx, rt, dest); 1213b2167459SRichard Henderson 1214b2167459SRichard Henderson /* Install the new nullification. */ 1215b2167459SRichard Henderson cond_free(&ctx->null_cond); 1216b2167459SRichard Henderson ctx->null_cond = cond; 1217b2167459SRichard Henderson } 1218b2167459SRichard Henderson 12196fd0c7bcSRichard Henderson static void do_log(DisasContext *ctx, unsigned rt, TCGv_i64 in1, 12206fd0c7bcSRichard Henderson TCGv_i64 in2, unsigned cf, bool d, 12216fd0c7bcSRichard Henderson void (*fn)(TCGv_i64, TCGv_i64, TCGv_i64)) 1222b2167459SRichard Henderson { 12236fd0c7bcSRichard Henderson TCGv_i64 dest = dest_gpr(ctx, rt); 1224b2167459SRichard Henderson 1225b2167459SRichard Henderson /* Perform the operation, and writeback. */ 1226b2167459SRichard Henderson fn(dest, in1, in2); 1227b2167459SRichard Henderson save_gpr(ctx, rt, dest); 1228b2167459SRichard Henderson 1229b2167459SRichard Henderson /* Install the new nullification. */ 1230b2167459SRichard Henderson cond_free(&ctx->null_cond); 1231b2167459SRichard Henderson if (cf) { 1232b5af8423SRichard Henderson ctx->null_cond = do_log_cond(ctx, cf, d, dest); 1233b2167459SRichard Henderson } 1234b2167459SRichard Henderson } 1235b2167459SRichard Henderson 1236fa8e3bedSRichard Henderson static bool do_log_reg(DisasContext *ctx, arg_rrr_cf_d *a, 12376fd0c7bcSRichard Henderson void (*fn)(TCGv_i64, TCGv_i64, TCGv_i64)) 12380c982a28SRichard Henderson { 12396fd0c7bcSRichard Henderson TCGv_i64 tcg_r1, tcg_r2; 12400c982a28SRichard Henderson 12410c982a28SRichard Henderson if (a->cf) { 12420c982a28SRichard Henderson nullify_over(ctx); 12430c982a28SRichard Henderson } 12440c982a28SRichard Henderson tcg_r1 = load_gpr(ctx, a->r1); 12450c982a28SRichard Henderson tcg_r2 = load_gpr(ctx, a->r2); 1246fa8e3bedSRichard Henderson do_log(ctx, a->t, tcg_r1, tcg_r2, a->cf, a->d, fn); 12470c982a28SRichard Henderson return nullify_end(ctx); 12480c982a28SRichard Henderson } 12490c982a28SRichard Henderson 12506fd0c7bcSRichard Henderson static void do_unit(DisasContext *ctx, unsigned rt, TCGv_i64 in1, 12516fd0c7bcSRichard Henderson TCGv_i64 in2, unsigned cf, bool d, bool is_tc, 12526fd0c7bcSRichard Henderson void (*fn)(TCGv_i64, TCGv_i64, TCGv_i64)) 1253b2167459SRichard Henderson { 12546fd0c7bcSRichard Henderson TCGv_i64 dest; 1255b2167459SRichard Henderson DisasCond cond; 1256b2167459SRichard Henderson 1257b2167459SRichard Henderson if (cf == 0) { 1258b2167459SRichard Henderson dest = dest_gpr(ctx, rt); 1259b2167459SRichard Henderson fn(dest, in1, in2); 1260b2167459SRichard Henderson save_gpr(ctx, rt, dest); 1261b2167459SRichard Henderson cond_free(&ctx->null_cond); 1262b2167459SRichard Henderson } else { 1263aac0f603SRichard Henderson dest = tcg_temp_new_i64(); 1264b2167459SRichard Henderson fn(dest, in1, in2); 1265b2167459SRichard Henderson 126659963d8fSRichard Henderson cond = do_unit_cond(cf, d, dest, in1, in2); 1267b2167459SRichard Henderson 1268b2167459SRichard Henderson if (is_tc) { 1269aac0f603SRichard Henderson TCGv_i64 tmp = tcg_temp_new_i64(); 12706fd0c7bcSRichard Henderson tcg_gen_setcond_i64(cond.c, tmp, cond.a0, cond.a1); 1271ad75a51eSRichard Henderson gen_helper_tcond(tcg_env, tmp); 1272b2167459SRichard Henderson } 1273b2167459SRichard Henderson save_gpr(ctx, rt, dest); 1274b2167459SRichard Henderson 1275b2167459SRichard Henderson cond_free(&ctx->null_cond); 1276b2167459SRichard Henderson ctx->null_cond = cond; 1277b2167459SRichard Henderson } 1278b2167459SRichard Henderson } 1279b2167459SRichard Henderson 128086f8d05fSRichard Henderson #ifndef CONFIG_USER_ONLY 12818d6ae7fbSRichard Henderson /* The "normal" usage is SP >= 0, wherein SP == 0 selects the space 12828d6ae7fbSRichard Henderson from the top 2 bits of the base register. There are a few system 12838d6ae7fbSRichard Henderson instructions that have a 3-bit space specifier, for which SR0 is 12848d6ae7fbSRichard Henderson not special. To handle this, pass ~SP. */ 12856fd0c7bcSRichard Henderson static TCGv_i64 space_select(DisasContext *ctx, int sp, TCGv_i64 base) 128686f8d05fSRichard Henderson { 128786f8d05fSRichard Henderson TCGv_ptr ptr; 12886fd0c7bcSRichard Henderson TCGv_i64 tmp; 128986f8d05fSRichard Henderson TCGv_i64 spc; 129086f8d05fSRichard Henderson 129186f8d05fSRichard Henderson if (sp != 0) { 12928d6ae7fbSRichard Henderson if (sp < 0) { 12938d6ae7fbSRichard Henderson sp = ~sp; 12948d6ae7fbSRichard Henderson } 12956fd0c7bcSRichard Henderson spc = tcg_temp_new_i64(); 12968d6ae7fbSRichard Henderson load_spr(ctx, spc, sp); 12978d6ae7fbSRichard Henderson return spc; 129886f8d05fSRichard Henderson } 1299494737b7SRichard Henderson if (ctx->tb_flags & TB_FLAG_SR_SAME) { 1300494737b7SRichard Henderson return cpu_srH; 1301494737b7SRichard Henderson } 130286f8d05fSRichard Henderson 130386f8d05fSRichard Henderson ptr = tcg_temp_new_ptr(); 1304aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 13056fd0c7bcSRichard Henderson spc = tcg_temp_new_i64(); 130686f8d05fSRichard Henderson 1307698240d1SRichard Henderson /* Extract top 2 bits of the address, shift left 3 for uint64_t index. */ 13086fd0c7bcSRichard Henderson tcg_gen_shri_i64(tmp, base, (ctx->tb_flags & PSW_W ? 64 : 32) - 5); 13096fd0c7bcSRichard Henderson tcg_gen_andi_i64(tmp, tmp, 030); 13106fd0c7bcSRichard Henderson tcg_gen_trunc_i64_ptr(ptr, tmp); 131186f8d05fSRichard Henderson 1312ad75a51eSRichard Henderson tcg_gen_add_ptr(ptr, ptr, tcg_env); 131386f8d05fSRichard Henderson tcg_gen_ld_i64(spc, ptr, offsetof(CPUHPPAState, sr[4])); 131486f8d05fSRichard Henderson 131586f8d05fSRichard Henderson return spc; 131686f8d05fSRichard Henderson } 131786f8d05fSRichard Henderson #endif 131886f8d05fSRichard Henderson 13196fd0c7bcSRichard Henderson static void form_gva(DisasContext *ctx, TCGv_i64 *pgva, TCGv_i64 *pofs, 1320c53e401eSRichard Henderson unsigned rb, unsigned rx, int scale, int64_t disp, 132186f8d05fSRichard Henderson unsigned sp, int modify, bool is_phys) 132286f8d05fSRichard Henderson { 13236fd0c7bcSRichard Henderson TCGv_i64 base = load_gpr(ctx, rb); 13246fd0c7bcSRichard Henderson TCGv_i64 ofs; 13256fd0c7bcSRichard Henderson TCGv_i64 addr; 132686f8d05fSRichard Henderson 132786f8d05fSRichard Henderson /* Note that RX is mutually exclusive with DISP. */ 132886f8d05fSRichard Henderson if (rx) { 1329aac0f603SRichard Henderson ofs = tcg_temp_new_i64(); 13306fd0c7bcSRichard Henderson tcg_gen_shli_i64(ofs, cpu_gr[rx], scale); 13316fd0c7bcSRichard Henderson tcg_gen_add_i64(ofs, ofs, base); 133286f8d05fSRichard Henderson } else if (disp || modify) { 1333aac0f603SRichard Henderson ofs = tcg_temp_new_i64(); 13346fd0c7bcSRichard Henderson tcg_gen_addi_i64(ofs, base, disp); 133586f8d05fSRichard Henderson } else { 133686f8d05fSRichard Henderson ofs = base; 133786f8d05fSRichard Henderson } 133886f8d05fSRichard Henderson 133986f8d05fSRichard Henderson *pofs = ofs; 13406fd0c7bcSRichard Henderson *pgva = addr = tcg_temp_new_i64(); 1341d265360fSRichard Henderson tcg_gen_andi_i64(addr, modify <= 0 ? ofs : base, gva_offset_mask(ctx)); 1342698240d1SRichard Henderson #ifndef CONFIG_USER_ONLY 134386f8d05fSRichard Henderson if (!is_phys) { 1344d265360fSRichard Henderson tcg_gen_or_i64(addr, addr, space_select(ctx, sp, base)); 134586f8d05fSRichard Henderson } 134686f8d05fSRichard Henderson #endif 134786f8d05fSRichard Henderson } 134886f8d05fSRichard Henderson 134996d6407fSRichard Henderson /* Emit a memory load. The modify parameter should be 135096d6407fSRichard Henderson * < 0 for pre-modify, 135196d6407fSRichard Henderson * > 0 for post-modify, 135296d6407fSRichard Henderson * = 0 for no base register update. 135396d6407fSRichard Henderson */ 135496d6407fSRichard Henderson static void do_load_32(DisasContext *ctx, TCGv_i32 dest, unsigned rb, 1355c53e401eSRichard Henderson unsigned rx, int scale, int64_t disp, 135614776ab5STony Nguyen unsigned sp, int modify, MemOp mop) 135796d6407fSRichard Henderson { 13586fd0c7bcSRichard Henderson TCGv_i64 ofs; 13596fd0c7bcSRichard Henderson TCGv_i64 addr; 136096d6407fSRichard Henderson 136196d6407fSRichard Henderson /* Caller uses nullify_over/nullify_end. */ 136296d6407fSRichard Henderson assert(ctx->null_cond.c == TCG_COND_NEVER); 136396d6407fSRichard Henderson 136486f8d05fSRichard Henderson form_gva(ctx, &addr, &ofs, rb, rx, scale, disp, sp, modify, 136586f8d05fSRichard Henderson ctx->mmu_idx == MMU_PHYS_IDX); 1366c1f55d97SRichard Henderson tcg_gen_qemu_ld_i32(dest, addr, ctx->mmu_idx, mop | UNALIGN(ctx)); 136786f8d05fSRichard Henderson if (modify) { 136886f8d05fSRichard Henderson save_gpr(ctx, rb, ofs); 136996d6407fSRichard Henderson } 137096d6407fSRichard Henderson } 137196d6407fSRichard Henderson 137296d6407fSRichard Henderson static void do_load_64(DisasContext *ctx, TCGv_i64 dest, unsigned rb, 1373c53e401eSRichard Henderson unsigned rx, int scale, int64_t disp, 137414776ab5STony Nguyen unsigned sp, int modify, MemOp mop) 137596d6407fSRichard Henderson { 13766fd0c7bcSRichard Henderson TCGv_i64 ofs; 13776fd0c7bcSRichard Henderson TCGv_i64 addr; 137896d6407fSRichard Henderson 137996d6407fSRichard Henderson /* Caller uses nullify_over/nullify_end. */ 138096d6407fSRichard Henderson assert(ctx->null_cond.c == TCG_COND_NEVER); 138196d6407fSRichard Henderson 138286f8d05fSRichard Henderson form_gva(ctx, &addr, &ofs, rb, rx, scale, disp, sp, modify, 138386f8d05fSRichard Henderson ctx->mmu_idx == MMU_PHYS_IDX); 1384217d1a5eSRichard Henderson tcg_gen_qemu_ld_i64(dest, addr, ctx->mmu_idx, mop | UNALIGN(ctx)); 138586f8d05fSRichard Henderson if (modify) { 138686f8d05fSRichard Henderson save_gpr(ctx, rb, ofs); 138796d6407fSRichard Henderson } 138896d6407fSRichard Henderson } 138996d6407fSRichard Henderson 139096d6407fSRichard Henderson static void do_store_32(DisasContext *ctx, TCGv_i32 src, unsigned rb, 1391c53e401eSRichard Henderson unsigned rx, int scale, int64_t disp, 139214776ab5STony Nguyen unsigned sp, int modify, MemOp mop) 139396d6407fSRichard Henderson { 13946fd0c7bcSRichard Henderson TCGv_i64 ofs; 13956fd0c7bcSRichard Henderson TCGv_i64 addr; 139696d6407fSRichard Henderson 139796d6407fSRichard Henderson /* Caller uses nullify_over/nullify_end. */ 139896d6407fSRichard Henderson assert(ctx->null_cond.c == TCG_COND_NEVER); 139996d6407fSRichard Henderson 140086f8d05fSRichard Henderson form_gva(ctx, &addr, &ofs, rb, rx, scale, disp, sp, modify, 140186f8d05fSRichard Henderson ctx->mmu_idx == MMU_PHYS_IDX); 1402217d1a5eSRichard Henderson tcg_gen_qemu_st_i32(src, addr, ctx->mmu_idx, mop | UNALIGN(ctx)); 140386f8d05fSRichard Henderson if (modify) { 140486f8d05fSRichard Henderson save_gpr(ctx, rb, ofs); 140596d6407fSRichard Henderson } 140696d6407fSRichard Henderson } 140796d6407fSRichard Henderson 140896d6407fSRichard Henderson static void do_store_64(DisasContext *ctx, TCGv_i64 src, unsigned rb, 1409c53e401eSRichard Henderson unsigned rx, int scale, int64_t disp, 141014776ab5STony Nguyen unsigned sp, int modify, MemOp mop) 141196d6407fSRichard Henderson { 14126fd0c7bcSRichard Henderson TCGv_i64 ofs; 14136fd0c7bcSRichard Henderson TCGv_i64 addr; 141496d6407fSRichard Henderson 141596d6407fSRichard Henderson /* Caller uses nullify_over/nullify_end. */ 141696d6407fSRichard Henderson assert(ctx->null_cond.c == TCG_COND_NEVER); 141796d6407fSRichard Henderson 141886f8d05fSRichard Henderson form_gva(ctx, &addr, &ofs, rb, rx, scale, disp, sp, modify, 141986f8d05fSRichard Henderson ctx->mmu_idx == MMU_PHYS_IDX); 1420217d1a5eSRichard Henderson tcg_gen_qemu_st_i64(src, addr, ctx->mmu_idx, mop | UNALIGN(ctx)); 142186f8d05fSRichard Henderson if (modify) { 142286f8d05fSRichard Henderson save_gpr(ctx, rb, ofs); 142396d6407fSRichard Henderson } 142496d6407fSRichard Henderson } 142596d6407fSRichard Henderson 14261cd012a5SRichard Henderson static bool do_load(DisasContext *ctx, unsigned rt, unsigned rb, 1427c53e401eSRichard Henderson unsigned rx, int scale, int64_t disp, 142814776ab5STony Nguyen unsigned sp, int modify, MemOp mop) 142996d6407fSRichard Henderson { 14306fd0c7bcSRichard Henderson TCGv_i64 dest; 143196d6407fSRichard Henderson 143296d6407fSRichard Henderson nullify_over(ctx); 143396d6407fSRichard Henderson 143496d6407fSRichard Henderson if (modify == 0) { 143596d6407fSRichard Henderson /* No base register update. */ 143696d6407fSRichard Henderson dest = dest_gpr(ctx, rt); 143796d6407fSRichard Henderson } else { 143896d6407fSRichard Henderson /* Make sure if RT == RB, we see the result of the load. */ 1439aac0f603SRichard Henderson dest = tcg_temp_new_i64(); 144096d6407fSRichard Henderson } 14416fd0c7bcSRichard Henderson do_load_64(ctx, dest, rb, rx, scale, disp, sp, modify, mop); 144296d6407fSRichard Henderson save_gpr(ctx, rt, dest); 144396d6407fSRichard Henderson 14441cd012a5SRichard Henderson return nullify_end(ctx); 144596d6407fSRichard Henderson } 144696d6407fSRichard Henderson 1447740038d7SRichard Henderson static bool do_floadw(DisasContext *ctx, unsigned rt, unsigned rb, 1448c53e401eSRichard Henderson unsigned rx, int scale, int64_t disp, 144986f8d05fSRichard Henderson unsigned sp, int modify) 145096d6407fSRichard Henderson { 145196d6407fSRichard Henderson TCGv_i32 tmp; 145296d6407fSRichard Henderson 145396d6407fSRichard Henderson nullify_over(ctx); 145496d6407fSRichard Henderson 145596d6407fSRichard Henderson tmp = tcg_temp_new_i32(); 145686f8d05fSRichard Henderson do_load_32(ctx, tmp, rb, rx, scale, disp, sp, modify, MO_TEUL); 145796d6407fSRichard Henderson save_frw_i32(rt, tmp); 145896d6407fSRichard Henderson 145996d6407fSRichard Henderson if (rt == 0) { 1460ad75a51eSRichard Henderson gen_helper_loaded_fr0(tcg_env); 146196d6407fSRichard Henderson } 146296d6407fSRichard Henderson 1463740038d7SRichard Henderson return nullify_end(ctx); 146496d6407fSRichard Henderson } 146596d6407fSRichard Henderson 1466740038d7SRichard Henderson static bool trans_fldw(DisasContext *ctx, arg_ldst *a) 1467740038d7SRichard Henderson { 1468740038d7SRichard Henderson return do_floadw(ctx, a->t, a->b, a->x, a->scale ? 2 : 0, 1469740038d7SRichard Henderson a->disp, a->sp, a->m); 1470740038d7SRichard Henderson } 1471740038d7SRichard Henderson 1472740038d7SRichard Henderson static bool do_floadd(DisasContext *ctx, unsigned rt, unsigned rb, 1473c53e401eSRichard Henderson unsigned rx, int scale, int64_t disp, 147486f8d05fSRichard Henderson unsigned sp, int modify) 147596d6407fSRichard Henderson { 147696d6407fSRichard Henderson TCGv_i64 tmp; 147796d6407fSRichard Henderson 147896d6407fSRichard Henderson nullify_over(ctx); 147996d6407fSRichard Henderson 148096d6407fSRichard Henderson tmp = tcg_temp_new_i64(); 1481fc313c64SFrédéric Pétrot do_load_64(ctx, tmp, rb, rx, scale, disp, sp, modify, MO_TEUQ); 148296d6407fSRichard Henderson save_frd(rt, tmp); 148396d6407fSRichard Henderson 148496d6407fSRichard Henderson if (rt == 0) { 1485ad75a51eSRichard Henderson gen_helper_loaded_fr0(tcg_env); 148696d6407fSRichard Henderson } 148796d6407fSRichard Henderson 1488740038d7SRichard Henderson return nullify_end(ctx); 1489740038d7SRichard Henderson } 1490740038d7SRichard Henderson 1491740038d7SRichard Henderson static bool trans_fldd(DisasContext *ctx, arg_ldst *a) 1492740038d7SRichard Henderson { 1493740038d7SRichard Henderson return do_floadd(ctx, a->t, a->b, a->x, a->scale ? 3 : 0, 1494740038d7SRichard Henderson a->disp, a->sp, a->m); 149596d6407fSRichard Henderson } 149696d6407fSRichard Henderson 14971cd012a5SRichard Henderson static bool do_store(DisasContext *ctx, unsigned rt, unsigned rb, 1498c53e401eSRichard Henderson int64_t disp, unsigned sp, 149914776ab5STony Nguyen int modify, MemOp mop) 150096d6407fSRichard Henderson { 150196d6407fSRichard Henderson nullify_over(ctx); 15026fd0c7bcSRichard Henderson do_store_64(ctx, load_gpr(ctx, rt), rb, 0, 0, disp, sp, modify, mop); 15031cd012a5SRichard Henderson return nullify_end(ctx); 150496d6407fSRichard Henderson } 150596d6407fSRichard Henderson 1506740038d7SRichard Henderson static bool do_fstorew(DisasContext *ctx, unsigned rt, unsigned rb, 1507c53e401eSRichard Henderson unsigned rx, int scale, int64_t disp, 150886f8d05fSRichard Henderson unsigned sp, int modify) 150996d6407fSRichard Henderson { 151096d6407fSRichard Henderson TCGv_i32 tmp; 151196d6407fSRichard Henderson 151296d6407fSRichard Henderson nullify_over(ctx); 151396d6407fSRichard Henderson 151496d6407fSRichard Henderson tmp = load_frw_i32(rt); 151586f8d05fSRichard Henderson do_store_32(ctx, tmp, rb, rx, scale, disp, sp, modify, MO_TEUL); 151696d6407fSRichard Henderson 1517740038d7SRichard Henderson return nullify_end(ctx); 151896d6407fSRichard Henderson } 151996d6407fSRichard Henderson 1520740038d7SRichard Henderson static bool trans_fstw(DisasContext *ctx, arg_ldst *a) 1521740038d7SRichard Henderson { 1522740038d7SRichard Henderson return do_fstorew(ctx, a->t, a->b, a->x, a->scale ? 2 : 0, 1523740038d7SRichard Henderson a->disp, a->sp, a->m); 1524740038d7SRichard Henderson } 1525740038d7SRichard Henderson 1526740038d7SRichard Henderson static bool do_fstored(DisasContext *ctx, unsigned rt, unsigned rb, 1527c53e401eSRichard Henderson unsigned rx, int scale, int64_t disp, 152886f8d05fSRichard Henderson unsigned sp, int modify) 152996d6407fSRichard Henderson { 153096d6407fSRichard Henderson TCGv_i64 tmp; 153196d6407fSRichard Henderson 153296d6407fSRichard Henderson nullify_over(ctx); 153396d6407fSRichard Henderson 153496d6407fSRichard Henderson tmp = load_frd(rt); 1535fc313c64SFrédéric Pétrot do_store_64(ctx, tmp, rb, rx, scale, disp, sp, modify, MO_TEUQ); 153696d6407fSRichard Henderson 1537740038d7SRichard Henderson return nullify_end(ctx); 1538740038d7SRichard Henderson } 1539740038d7SRichard Henderson 1540740038d7SRichard Henderson static bool trans_fstd(DisasContext *ctx, arg_ldst *a) 1541740038d7SRichard Henderson { 1542740038d7SRichard Henderson return do_fstored(ctx, a->t, a->b, a->x, a->scale ? 3 : 0, 1543740038d7SRichard Henderson a->disp, a->sp, a->m); 154496d6407fSRichard Henderson } 154596d6407fSRichard Henderson 15461ca74648SRichard Henderson static bool do_fop_wew(DisasContext *ctx, unsigned rt, unsigned ra, 1547ebe9383cSRichard Henderson void (*func)(TCGv_i32, TCGv_env, TCGv_i32)) 1548ebe9383cSRichard Henderson { 1549ebe9383cSRichard Henderson TCGv_i32 tmp; 1550ebe9383cSRichard Henderson 1551ebe9383cSRichard Henderson nullify_over(ctx); 1552ebe9383cSRichard Henderson tmp = load_frw0_i32(ra); 1553ebe9383cSRichard Henderson 1554ad75a51eSRichard Henderson func(tmp, tcg_env, tmp); 1555ebe9383cSRichard Henderson 1556ebe9383cSRichard Henderson save_frw_i32(rt, tmp); 15571ca74648SRichard Henderson return nullify_end(ctx); 1558ebe9383cSRichard Henderson } 1559ebe9383cSRichard Henderson 15601ca74648SRichard Henderson static bool do_fop_wed(DisasContext *ctx, unsigned rt, unsigned ra, 1561ebe9383cSRichard Henderson void (*func)(TCGv_i32, TCGv_env, TCGv_i64)) 1562ebe9383cSRichard Henderson { 1563ebe9383cSRichard Henderson TCGv_i32 dst; 1564ebe9383cSRichard Henderson TCGv_i64 src; 1565ebe9383cSRichard Henderson 1566ebe9383cSRichard Henderson nullify_over(ctx); 1567ebe9383cSRichard Henderson src = load_frd(ra); 1568ebe9383cSRichard Henderson dst = tcg_temp_new_i32(); 1569ebe9383cSRichard Henderson 1570ad75a51eSRichard Henderson func(dst, tcg_env, src); 1571ebe9383cSRichard Henderson 1572ebe9383cSRichard Henderson save_frw_i32(rt, dst); 15731ca74648SRichard Henderson return nullify_end(ctx); 1574ebe9383cSRichard Henderson } 1575ebe9383cSRichard Henderson 15761ca74648SRichard Henderson static bool do_fop_ded(DisasContext *ctx, unsigned rt, unsigned ra, 1577ebe9383cSRichard Henderson void (*func)(TCGv_i64, TCGv_env, TCGv_i64)) 1578ebe9383cSRichard Henderson { 1579ebe9383cSRichard Henderson TCGv_i64 tmp; 1580ebe9383cSRichard Henderson 1581ebe9383cSRichard Henderson nullify_over(ctx); 1582ebe9383cSRichard Henderson tmp = load_frd0(ra); 1583ebe9383cSRichard Henderson 1584ad75a51eSRichard Henderson func(tmp, tcg_env, tmp); 1585ebe9383cSRichard Henderson 1586ebe9383cSRichard Henderson save_frd(rt, tmp); 15871ca74648SRichard Henderson return nullify_end(ctx); 1588ebe9383cSRichard Henderson } 1589ebe9383cSRichard Henderson 15901ca74648SRichard Henderson static bool do_fop_dew(DisasContext *ctx, unsigned rt, unsigned ra, 1591ebe9383cSRichard Henderson void (*func)(TCGv_i64, TCGv_env, TCGv_i32)) 1592ebe9383cSRichard Henderson { 1593ebe9383cSRichard Henderson TCGv_i32 src; 1594ebe9383cSRichard Henderson TCGv_i64 dst; 1595ebe9383cSRichard Henderson 1596ebe9383cSRichard Henderson nullify_over(ctx); 1597ebe9383cSRichard Henderson src = load_frw0_i32(ra); 1598ebe9383cSRichard Henderson dst = tcg_temp_new_i64(); 1599ebe9383cSRichard Henderson 1600ad75a51eSRichard Henderson func(dst, tcg_env, src); 1601ebe9383cSRichard Henderson 1602ebe9383cSRichard Henderson save_frd(rt, dst); 16031ca74648SRichard Henderson return nullify_end(ctx); 1604ebe9383cSRichard Henderson } 1605ebe9383cSRichard Henderson 16061ca74648SRichard Henderson static bool do_fop_weww(DisasContext *ctx, unsigned rt, 1607ebe9383cSRichard Henderson unsigned ra, unsigned rb, 160831234768SRichard Henderson void (*func)(TCGv_i32, TCGv_env, TCGv_i32, TCGv_i32)) 1609ebe9383cSRichard Henderson { 1610ebe9383cSRichard Henderson TCGv_i32 a, b; 1611ebe9383cSRichard Henderson 1612ebe9383cSRichard Henderson nullify_over(ctx); 1613ebe9383cSRichard Henderson a = load_frw0_i32(ra); 1614ebe9383cSRichard Henderson b = load_frw0_i32(rb); 1615ebe9383cSRichard Henderson 1616ad75a51eSRichard Henderson func(a, tcg_env, a, b); 1617ebe9383cSRichard Henderson 1618ebe9383cSRichard Henderson save_frw_i32(rt, a); 16191ca74648SRichard Henderson return nullify_end(ctx); 1620ebe9383cSRichard Henderson } 1621ebe9383cSRichard Henderson 16221ca74648SRichard Henderson static bool do_fop_dedd(DisasContext *ctx, unsigned rt, 1623ebe9383cSRichard Henderson unsigned ra, unsigned rb, 162431234768SRichard Henderson void (*func)(TCGv_i64, TCGv_env, TCGv_i64, TCGv_i64)) 1625ebe9383cSRichard Henderson { 1626ebe9383cSRichard Henderson TCGv_i64 a, b; 1627ebe9383cSRichard Henderson 1628ebe9383cSRichard Henderson nullify_over(ctx); 1629ebe9383cSRichard Henderson a = load_frd0(ra); 1630ebe9383cSRichard Henderson b = load_frd0(rb); 1631ebe9383cSRichard Henderson 1632ad75a51eSRichard Henderson func(a, tcg_env, a, b); 1633ebe9383cSRichard Henderson 1634ebe9383cSRichard Henderson save_frd(rt, a); 16351ca74648SRichard Henderson return nullify_end(ctx); 1636ebe9383cSRichard Henderson } 1637ebe9383cSRichard Henderson 163898cd9ca7SRichard Henderson /* Emit an unconditional branch to a direct target, which may or may not 163998cd9ca7SRichard Henderson have already had nullification handled. */ 1640c53e401eSRichard Henderson static bool do_dbranch(DisasContext *ctx, uint64_t dest, 164198cd9ca7SRichard Henderson unsigned link, bool is_n) 164298cd9ca7SRichard Henderson { 164398cd9ca7SRichard Henderson if (ctx->null_cond.c == TCG_COND_NEVER && ctx->null_lab == NULL) { 164498cd9ca7SRichard Henderson if (link != 0) { 1645741322f4SRichard Henderson copy_iaoq_entry(ctx, cpu_gr[link], ctx->iaoq_n, ctx->iaoq_n_var); 164698cd9ca7SRichard Henderson } 164798cd9ca7SRichard Henderson ctx->iaoq_n = dest; 164898cd9ca7SRichard Henderson if (is_n) { 164998cd9ca7SRichard Henderson ctx->null_cond.c = TCG_COND_ALWAYS; 165098cd9ca7SRichard Henderson } 165198cd9ca7SRichard Henderson } else { 165298cd9ca7SRichard Henderson nullify_over(ctx); 165398cd9ca7SRichard Henderson 165498cd9ca7SRichard Henderson if (link != 0) { 1655741322f4SRichard Henderson copy_iaoq_entry(ctx, cpu_gr[link], ctx->iaoq_n, ctx->iaoq_n_var); 165698cd9ca7SRichard Henderson } 165798cd9ca7SRichard Henderson 165898cd9ca7SRichard Henderson if (is_n && use_nullify_skip(ctx)) { 165998cd9ca7SRichard Henderson nullify_set(ctx, 0); 166098cd9ca7SRichard Henderson gen_goto_tb(ctx, 0, dest, dest + 4); 166198cd9ca7SRichard Henderson } else { 166298cd9ca7SRichard Henderson nullify_set(ctx, is_n); 166398cd9ca7SRichard Henderson gen_goto_tb(ctx, 0, ctx->iaoq_b, dest); 166498cd9ca7SRichard Henderson } 166598cd9ca7SRichard Henderson 166631234768SRichard Henderson nullify_end(ctx); 166798cd9ca7SRichard Henderson 166898cd9ca7SRichard Henderson nullify_set(ctx, 0); 166998cd9ca7SRichard Henderson gen_goto_tb(ctx, 1, ctx->iaoq_b, ctx->iaoq_n); 167031234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 167198cd9ca7SRichard Henderson } 167201afb7beSRichard Henderson return true; 167398cd9ca7SRichard Henderson } 167498cd9ca7SRichard Henderson 167598cd9ca7SRichard Henderson /* Emit a conditional branch to a direct target. If the branch itself 167698cd9ca7SRichard Henderson is nullified, we should have already used nullify_over. */ 1677c53e401eSRichard Henderson static bool do_cbranch(DisasContext *ctx, int64_t disp, bool is_n, 167898cd9ca7SRichard Henderson DisasCond *cond) 167998cd9ca7SRichard Henderson { 1680c53e401eSRichard Henderson uint64_t dest = iaoq_dest(ctx, disp); 168198cd9ca7SRichard Henderson TCGLabel *taken = NULL; 168298cd9ca7SRichard Henderson TCGCond c = cond->c; 168398cd9ca7SRichard Henderson bool n; 168498cd9ca7SRichard Henderson 168598cd9ca7SRichard Henderson assert(ctx->null_cond.c == TCG_COND_NEVER); 168698cd9ca7SRichard Henderson 168798cd9ca7SRichard Henderson /* Handle TRUE and NEVER as direct branches. */ 168898cd9ca7SRichard Henderson if (c == TCG_COND_ALWAYS) { 168901afb7beSRichard Henderson return do_dbranch(ctx, dest, 0, is_n && disp >= 0); 169098cd9ca7SRichard Henderson } 169198cd9ca7SRichard Henderson if (c == TCG_COND_NEVER) { 169201afb7beSRichard Henderson return do_dbranch(ctx, ctx->iaoq_n, 0, is_n && disp < 0); 169398cd9ca7SRichard Henderson } 169498cd9ca7SRichard Henderson 169598cd9ca7SRichard Henderson taken = gen_new_label(); 16966fd0c7bcSRichard Henderson tcg_gen_brcond_i64(c, cond->a0, cond->a1, taken); 169798cd9ca7SRichard Henderson cond_free(cond); 169898cd9ca7SRichard Henderson 169998cd9ca7SRichard Henderson /* Not taken: Condition not satisfied; nullify on backward branches. */ 170098cd9ca7SRichard Henderson n = is_n && disp < 0; 170198cd9ca7SRichard Henderson if (n && use_nullify_skip(ctx)) { 170298cd9ca7SRichard Henderson nullify_set(ctx, 0); 1703a881c8e7SRichard Henderson gen_goto_tb(ctx, 0, ctx->iaoq_n, ctx->iaoq_n + 4); 170498cd9ca7SRichard Henderson } else { 170598cd9ca7SRichard Henderson if (!n && ctx->null_lab) { 170698cd9ca7SRichard Henderson gen_set_label(ctx->null_lab); 170798cd9ca7SRichard Henderson ctx->null_lab = NULL; 170898cd9ca7SRichard Henderson } 170998cd9ca7SRichard Henderson nullify_set(ctx, n); 1710c301f34eSRichard Henderson if (ctx->iaoq_n == -1) { 1711c301f34eSRichard Henderson /* The temporary iaoq_n_var died at the branch above. 1712c301f34eSRichard Henderson Regenerate it here instead of saving it. */ 17136fd0c7bcSRichard Henderson tcg_gen_addi_i64(ctx->iaoq_n_var, cpu_iaoq_b, 4); 1714c301f34eSRichard Henderson } 1715a881c8e7SRichard Henderson gen_goto_tb(ctx, 0, ctx->iaoq_b, ctx->iaoq_n); 171698cd9ca7SRichard Henderson } 171798cd9ca7SRichard Henderson 171898cd9ca7SRichard Henderson gen_set_label(taken); 171998cd9ca7SRichard Henderson 172098cd9ca7SRichard Henderson /* Taken: Condition satisfied; nullify on forward branches. */ 172198cd9ca7SRichard Henderson n = is_n && disp >= 0; 172298cd9ca7SRichard Henderson if (n && use_nullify_skip(ctx)) { 172398cd9ca7SRichard Henderson nullify_set(ctx, 0); 1724a881c8e7SRichard Henderson gen_goto_tb(ctx, 1, dest, dest + 4); 172598cd9ca7SRichard Henderson } else { 172698cd9ca7SRichard Henderson nullify_set(ctx, n); 1727a881c8e7SRichard Henderson gen_goto_tb(ctx, 1, ctx->iaoq_b, dest); 172898cd9ca7SRichard Henderson } 172998cd9ca7SRichard Henderson 173098cd9ca7SRichard Henderson /* Not taken: the branch itself was nullified. */ 173198cd9ca7SRichard Henderson if (ctx->null_lab) { 173298cd9ca7SRichard Henderson gen_set_label(ctx->null_lab); 173398cd9ca7SRichard Henderson ctx->null_lab = NULL; 173431234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE; 173598cd9ca7SRichard Henderson } else { 173631234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 173798cd9ca7SRichard Henderson } 173801afb7beSRichard Henderson return true; 173998cd9ca7SRichard Henderson } 174098cd9ca7SRichard Henderson 174198cd9ca7SRichard Henderson /* Emit an unconditional branch to an indirect target. This handles 174298cd9ca7SRichard Henderson nullification of the branch itself. */ 17436fd0c7bcSRichard Henderson static bool do_ibranch(DisasContext *ctx, TCGv_i64 dest, 174498cd9ca7SRichard Henderson unsigned link, bool is_n) 174598cd9ca7SRichard Henderson { 17466fd0c7bcSRichard Henderson TCGv_i64 a0, a1, next, tmp; 174798cd9ca7SRichard Henderson TCGCond c; 174898cd9ca7SRichard Henderson 174998cd9ca7SRichard Henderson assert(ctx->null_lab == NULL); 175098cd9ca7SRichard Henderson 175198cd9ca7SRichard Henderson if (ctx->null_cond.c == TCG_COND_NEVER) { 175298cd9ca7SRichard Henderson if (link != 0) { 1753741322f4SRichard Henderson copy_iaoq_entry(ctx, cpu_gr[link], ctx->iaoq_n, ctx->iaoq_n_var); 175498cd9ca7SRichard Henderson } 1755aac0f603SRichard Henderson next = tcg_temp_new_i64(); 17566fd0c7bcSRichard Henderson tcg_gen_mov_i64(next, dest); 175798cd9ca7SRichard Henderson if (is_n) { 1758c301f34eSRichard Henderson if (use_nullify_skip(ctx)) { 1759a0180973SRichard Henderson copy_iaoq_entry(ctx, cpu_iaoq_f, -1, next); 17606fd0c7bcSRichard Henderson tcg_gen_addi_i64(next, next, 4); 1761a0180973SRichard Henderson copy_iaoq_entry(ctx, cpu_iaoq_b, -1, next); 1762c301f34eSRichard Henderson nullify_set(ctx, 0); 176331234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_UPDATED; 176401afb7beSRichard Henderson return true; 1765c301f34eSRichard Henderson } 176698cd9ca7SRichard Henderson ctx->null_cond.c = TCG_COND_ALWAYS; 176798cd9ca7SRichard Henderson } 1768c301f34eSRichard Henderson ctx->iaoq_n = -1; 1769c301f34eSRichard Henderson ctx->iaoq_n_var = next; 177098cd9ca7SRichard Henderson } else if (is_n && use_nullify_skip(ctx)) { 177198cd9ca7SRichard Henderson /* The (conditional) branch, B, nullifies the next insn, N, 177298cd9ca7SRichard Henderson and we're allowed to skip execution N (no single-step or 17734137cb83SRichard Henderson tracepoint in effect). Since the goto_ptr that we must use 177498cd9ca7SRichard Henderson for the indirect branch consumes no special resources, we 177598cd9ca7SRichard Henderson can (conditionally) skip B and continue execution. */ 177698cd9ca7SRichard Henderson /* The use_nullify_skip test implies we have a known control path. */ 177798cd9ca7SRichard Henderson tcg_debug_assert(ctx->iaoq_b != -1); 177898cd9ca7SRichard Henderson tcg_debug_assert(ctx->iaoq_n != -1); 177998cd9ca7SRichard Henderson 178098cd9ca7SRichard Henderson /* We do have to handle the non-local temporary, DEST, before 178198cd9ca7SRichard Henderson branching. Since IOAQ_F is not really live at this point, we 178298cd9ca7SRichard Henderson can simply store DEST optimistically. Similarly with IAOQ_B. */ 1783a0180973SRichard Henderson copy_iaoq_entry(ctx, cpu_iaoq_f, -1, dest); 1784aac0f603SRichard Henderson next = tcg_temp_new_i64(); 17856fd0c7bcSRichard Henderson tcg_gen_addi_i64(next, dest, 4); 1786a0180973SRichard Henderson copy_iaoq_entry(ctx, cpu_iaoq_b, -1, next); 178798cd9ca7SRichard Henderson 178898cd9ca7SRichard Henderson nullify_over(ctx); 178998cd9ca7SRichard Henderson if (link != 0) { 17909a91dd84SRichard Henderson copy_iaoq_entry(ctx, cpu_gr[link], ctx->iaoq_n, ctx->iaoq_n_var); 179198cd9ca7SRichard Henderson } 17927f11636dSEmilio G. Cota tcg_gen_lookup_and_goto_ptr(); 179301afb7beSRichard Henderson return nullify_end(ctx); 179498cd9ca7SRichard Henderson } else { 179598cd9ca7SRichard Henderson c = ctx->null_cond.c; 179698cd9ca7SRichard Henderson a0 = ctx->null_cond.a0; 179798cd9ca7SRichard Henderson a1 = ctx->null_cond.a1; 179898cd9ca7SRichard Henderson 1799aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 1800aac0f603SRichard Henderson next = tcg_temp_new_i64(); 180198cd9ca7SRichard Henderson 1802741322f4SRichard Henderson copy_iaoq_entry(ctx, tmp, ctx->iaoq_n, ctx->iaoq_n_var); 18036fd0c7bcSRichard Henderson tcg_gen_movcond_i64(c, next, a0, a1, tmp, dest); 180498cd9ca7SRichard Henderson ctx->iaoq_n = -1; 180598cd9ca7SRichard Henderson ctx->iaoq_n_var = next; 180698cd9ca7SRichard Henderson 180798cd9ca7SRichard Henderson if (link != 0) { 18086fd0c7bcSRichard Henderson tcg_gen_movcond_i64(c, cpu_gr[link], a0, a1, cpu_gr[link], tmp); 180998cd9ca7SRichard Henderson } 181098cd9ca7SRichard Henderson 181198cd9ca7SRichard Henderson if (is_n) { 181298cd9ca7SRichard Henderson /* The branch nullifies the next insn, which means the state of N 181398cd9ca7SRichard Henderson after the branch is the inverse of the state of N that applied 181498cd9ca7SRichard Henderson to the branch. */ 18156fd0c7bcSRichard Henderson tcg_gen_setcond_i64(tcg_invert_cond(c), cpu_psw_n, a0, a1); 181698cd9ca7SRichard Henderson cond_free(&ctx->null_cond); 181798cd9ca7SRichard Henderson ctx->null_cond = cond_make_n(); 181898cd9ca7SRichard Henderson ctx->psw_n_nonzero = true; 181998cd9ca7SRichard Henderson } else { 182098cd9ca7SRichard Henderson cond_free(&ctx->null_cond); 182198cd9ca7SRichard Henderson } 182298cd9ca7SRichard Henderson } 182301afb7beSRichard Henderson return true; 182498cd9ca7SRichard Henderson } 182598cd9ca7SRichard Henderson 1826660eefe1SRichard Henderson /* Implement 1827660eefe1SRichard Henderson * if (IAOQ_Front{30..31} < GR[b]{30..31}) 1828660eefe1SRichard Henderson * IAOQ_Next{30..31} ← GR[b]{30..31}; 1829660eefe1SRichard Henderson * else 1830660eefe1SRichard Henderson * IAOQ_Next{30..31} ← IAOQ_Front{30..31}; 1831660eefe1SRichard Henderson * which keeps the privilege level from being increased. 1832660eefe1SRichard Henderson */ 18336fd0c7bcSRichard Henderson static TCGv_i64 do_ibranch_priv(DisasContext *ctx, TCGv_i64 offset) 1834660eefe1SRichard Henderson { 18356fd0c7bcSRichard Henderson TCGv_i64 dest; 1836660eefe1SRichard Henderson switch (ctx->privilege) { 1837660eefe1SRichard Henderson case 0: 1838660eefe1SRichard Henderson /* Privilege 0 is maximum and is allowed to decrease. */ 1839660eefe1SRichard Henderson return offset; 1840660eefe1SRichard Henderson case 3: 1841993119feSRichard Henderson /* Privilege 3 is minimum and is never allowed to increase. */ 1842aac0f603SRichard Henderson dest = tcg_temp_new_i64(); 18436fd0c7bcSRichard Henderson tcg_gen_ori_i64(dest, offset, 3); 1844660eefe1SRichard Henderson break; 1845660eefe1SRichard Henderson default: 1846aac0f603SRichard Henderson dest = tcg_temp_new_i64(); 18476fd0c7bcSRichard Henderson tcg_gen_andi_i64(dest, offset, -4); 18486fd0c7bcSRichard Henderson tcg_gen_ori_i64(dest, dest, ctx->privilege); 18496fd0c7bcSRichard Henderson tcg_gen_movcond_i64(TCG_COND_GTU, dest, dest, offset, dest, offset); 1850660eefe1SRichard Henderson break; 1851660eefe1SRichard Henderson } 1852660eefe1SRichard Henderson return dest; 1853660eefe1SRichard Henderson } 1854660eefe1SRichard Henderson 1855ba1d0b44SRichard Henderson #ifdef CONFIG_USER_ONLY 18567ad439dfSRichard Henderson /* On Linux, page zero is normally marked execute only + gateway. 18577ad439dfSRichard Henderson Therefore normal read or write is supposed to fail, but specific 18587ad439dfSRichard Henderson offsets have kernel code mapped to raise permissions to implement 18597ad439dfSRichard Henderson system calls. Handling this via an explicit check here, rather 18607ad439dfSRichard Henderson in than the "be disp(sr2,r0)" instruction that probably sent us 18617ad439dfSRichard Henderson here, is the easiest way to handle the branch delay slot on the 18627ad439dfSRichard Henderson aforementioned BE. */ 186331234768SRichard Henderson static void do_page_zero(DisasContext *ctx) 18647ad439dfSRichard Henderson { 18656fd0c7bcSRichard Henderson TCGv_i64 tmp; 1866a0180973SRichard Henderson 18677ad439dfSRichard Henderson /* If by some means we get here with PSW[N]=1, that implies that 18687ad439dfSRichard Henderson the B,GATE instruction would be skipped, and we'd fault on the 18698b81968cSMichael Tokarev next insn within the privileged page. */ 18707ad439dfSRichard Henderson switch (ctx->null_cond.c) { 18717ad439dfSRichard Henderson case TCG_COND_NEVER: 18727ad439dfSRichard Henderson break; 18737ad439dfSRichard Henderson case TCG_COND_ALWAYS: 18746fd0c7bcSRichard Henderson tcg_gen_movi_i64(cpu_psw_n, 0); 18757ad439dfSRichard Henderson goto do_sigill; 18767ad439dfSRichard Henderson default: 18777ad439dfSRichard Henderson /* Since this is always the first (and only) insn within the 18787ad439dfSRichard Henderson TB, we should know the state of PSW[N] from TB->FLAGS. */ 18797ad439dfSRichard Henderson g_assert_not_reached(); 18807ad439dfSRichard Henderson } 18817ad439dfSRichard Henderson 18827ad439dfSRichard Henderson /* Check that we didn't arrive here via some means that allowed 18837ad439dfSRichard Henderson non-sequential instruction execution. Normally the PSW[B] bit 18847ad439dfSRichard Henderson detects this by disallowing the B,GATE instruction to execute 18857ad439dfSRichard Henderson under such conditions. */ 18867ad439dfSRichard Henderson if (ctx->iaoq_b != ctx->iaoq_f + 4) { 18877ad439dfSRichard Henderson goto do_sigill; 18887ad439dfSRichard Henderson } 18897ad439dfSRichard Henderson 1890ebd0e151SRichard Henderson switch (ctx->iaoq_f & -4) { 18917ad439dfSRichard Henderson case 0x00: /* Null pointer call */ 18922986721dSRichard Henderson gen_excp_1(EXCP_IMP); 189331234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 189431234768SRichard Henderson break; 18957ad439dfSRichard Henderson 18967ad439dfSRichard Henderson case 0xb0: /* LWS */ 18977ad439dfSRichard Henderson gen_excp_1(EXCP_SYSCALL_LWS); 189831234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 189931234768SRichard Henderson break; 19007ad439dfSRichard Henderson 19017ad439dfSRichard Henderson case 0xe0: /* SET_THREAD_POINTER */ 19026fd0c7bcSRichard Henderson tcg_gen_st_i64(cpu_gr[26], tcg_env, offsetof(CPUHPPAState, cr[27])); 1903aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 19046fd0c7bcSRichard Henderson tcg_gen_ori_i64(tmp, cpu_gr[31], 3); 1905a0180973SRichard Henderson copy_iaoq_entry(ctx, cpu_iaoq_f, -1, tmp); 19066fd0c7bcSRichard Henderson tcg_gen_addi_i64(tmp, tmp, 4); 1907a0180973SRichard Henderson copy_iaoq_entry(ctx, cpu_iaoq_b, -1, tmp); 190831234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_UPDATED; 190931234768SRichard Henderson break; 19107ad439dfSRichard Henderson 19117ad439dfSRichard Henderson case 0x100: /* SYSCALL */ 19127ad439dfSRichard Henderson gen_excp_1(EXCP_SYSCALL); 191331234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 191431234768SRichard Henderson break; 19157ad439dfSRichard Henderson 19167ad439dfSRichard Henderson default: 19177ad439dfSRichard Henderson do_sigill: 19182986721dSRichard Henderson gen_excp_1(EXCP_ILL); 191931234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 192031234768SRichard Henderson break; 19217ad439dfSRichard Henderson } 19227ad439dfSRichard Henderson } 1923ba1d0b44SRichard Henderson #endif 19247ad439dfSRichard Henderson 1925deee69a1SRichard Henderson static bool trans_nop(DisasContext *ctx, arg_nop *a) 1926b2167459SRichard Henderson { 1927b2167459SRichard Henderson cond_free(&ctx->null_cond); 192831234768SRichard Henderson return true; 1929b2167459SRichard Henderson } 1930b2167459SRichard Henderson 193140f9f908SRichard Henderson static bool trans_break(DisasContext *ctx, arg_break *a) 193298a9cb79SRichard Henderson { 193331234768SRichard Henderson return gen_excp_iir(ctx, EXCP_BREAK); 193498a9cb79SRichard Henderson } 193598a9cb79SRichard Henderson 1936e36f27efSRichard Henderson static bool trans_sync(DisasContext *ctx, arg_sync *a) 193798a9cb79SRichard Henderson { 193898a9cb79SRichard Henderson /* No point in nullifying the memory barrier. */ 193998a9cb79SRichard Henderson tcg_gen_mb(TCG_BAR_SC | TCG_MO_ALL); 194098a9cb79SRichard Henderson 194198a9cb79SRichard Henderson cond_free(&ctx->null_cond); 194231234768SRichard Henderson return true; 194398a9cb79SRichard Henderson } 194498a9cb79SRichard Henderson 1945c603e14aSRichard Henderson static bool trans_mfia(DisasContext *ctx, arg_mfia *a) 194698a9cb79SRichard Henderson { 1947c603e14aSRichard Henderson unsigned rt = a->t; 19486fd0c7bcSRichard Henderson TCGv_i64 tmp = dest_gpr(ctx, rt); 19496fd0c7bcSRichard Henderson tcg_gen_movi_i64(tmp, ctx->iaoq_f); 195098a9cb79SRichard Henderson save_gpr(ctx, rt, tmp); 195198a9cb79SRichard Henderson 195298a9cb79SRichard Henderson cond_free(&ctx->null_cond); 195331234768SRichard Henderson return true; 195498a9cb79SRichard Henderson } 195598a9cb79SRichard Henderson 1956c603e14aSRichard Henderson static bool trans_mfsp(DisasContext *ctx, arg_mfsp *a) 195798a9cb79SRichard Henderson { 1958c603e14aSRichard Henderson unsigned rt = a->t; 1959c603e14aSRichard Henderson unsigned rs = a->sp; 196033423472SRichard Henderson TCGv_i64 t0 = tcg_temp_new_i64(); 196198a9cb79SRichard Henderson 196233423472SRichard Henderson load_spr(ctx, t0, rs); 196333423472SRichard Henderson tcg_gen_shri_i64(t0, t0, 32); 196433423472SRichard Henderson 1965967662cdSRichard Henderson save_gpr(ctx, rt, t0); 196698a9cb79SRichard Henderson 196798a9cb79SRichard Henderson cond_free(&ctx->null_cond); 196831234768SRichard Henderson return true; 196998a9cb79SRichard Henderson } 197098a9cb79SRichard Henderson 1971c603e14aSRichard Henderson static bool trans_mfctl(DisasContext *ctx, arg_mfctl *a) 197298a9cb79SRichard Henderson { 1973c603e14aSRichard Henderson unsigned rt = a->t; 1974c603e14aSRichard Henderson unsigned ctl = a->r; 19756fd0c7bcSRichard Henderson TCGv_i64 tmp; 197698a9cb79SRichard Henderson 197798a9cb79SRichard Henderson switch (ctl) { 197835136a77SRichard Henderson case CR_SAR: 1979c603e14aSRichard Henderson if (a->e == 0) { 198098a9cb79SRichard Henderson /* MFSAR without ,W masks low 5 bits. */ 198198a9cb79SRichard Henderson tmp = dest_gpr(ctx, rt); 19826fd0c7bcSRichard Henderson tcg_gen_andi_i64(tmp, cpu_sar, 31); 198398a9cb79SRichard Henderson save_gpr(ctx, rt, tmp); 198435136a77SRichard Henderson goto done; 198598a9cb79SRichard Henderson } 198698a9cb79SRichard Henderson save_gpr(ctx, rt, cpu_sar); 198735136a77SRichard Henderson goto done; 198835136a77SRichard Henderson case CR_IT: /* Interval Timer */ 198935136a77SRichard Henderson /* FIXME: Respect PSW_S bit. */ 199035136a77SRichard Henderson nullify_over(ctx); 199198a9cb79SRichard Henderson tmp = dest_gpr(ctx, rt); 1992dfd1b812SRichard Henderson if (translator_io_start(&ctx->base)) { 199349c29d6cSRichard Henderson gen_helper_read_interval_timer(tmp); 199431234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE; 199549c29d6cSRichard Henderson } else { 199649c29d6cSRichard Henderson gen_helper_read_interval_timer(tmp); 199749c29d6cSRichard Henderson } 199898a9cb79SRichard Henderson save_gpr(ctx, rt, tmp); 199931234768SRichard Henderson return nullify_end(ctx); 200098a9cb79SRichard Henderson case 26: 200198a9cb79SRichard Henderson case 27: 200298a9cb79SRichard Henderson break; 200398a9cb79SRichard Henderson default: 200498a9cb79SRichard Henderson /* All other control registers are privileged. */ 200535136a77SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_REG); 200635136a77SRichard Henderson break; 200798a9cb79SRichard Henderson } 200898a9cb79SRichard Henderson 2009aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 20106fd0c7bcSRichard Henderson tcg_gen_ld_i64(tmp, tcg_env, offsetof(CPUHPPAState, cr[ctl])); 201135136a77SRichard Henderson save_gpr(ctx, rt, tmp); 201235136a77SRichard Henderson 201335136a77SRichard Henderson done: 201498a9cb79SRichard Henderson cond_free(&ctx->null_cond); 201531234768SRichard Henderson return true; 201698a9cb79SRichard Henderson } 201798a9cb79SRichard Henderson 2018c603e14aSRichard Henderson static bool trans_mtsp(DisasContext *ctx, arg_mtsp *a) 201933423472SRichard Henderson { 2020c603e14aSRichard Henderson unsigned rr = a->r; 2021c603e14aSRichard Henderson unsigned rs = a->sp; 2022967662cdSRichard Henderson TCGv_i64 tmp; 202333423472SRichard Henderson 202433423472SRichard Henderson if (rs >= 5) { 202533423472SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_REG); 202633423472SRichard Henderson } 202733423472SRichard Henderson nullify_over(ctx); 202833423472SRichard Henderson 2029967662cdSRichard Henderson tmp = tcg_temp_new_i64(); 2030967662cdSRichard Henderson tcg_gen_shli_i64(tmp, load_gpr(ctx, rr), 32); 203133423472SRichard Henderson 203233423472SRichard Henderson if (rs >= 4) { 2033967662cdSRichard Henderson tcg_gen_st_i64(tmp, tcg_env, offsetof(CPUHPPAState, sr[rs])); 2034494737b7SRichard Henderson ctx->tb_flags &= ~TB_FLAG_SR_SAME; 203533423472SRichard Henderson } else { 2036967662cdSRichard Henderson tcg_gen_mov_i64(cpu_sr[rs], tmp); 203733423472SRichard Henderson } 203833423472SRichard Henderson 203931234768SRichard Henderson return nullify_end(ctx); 204033423472SRichard Henderson } 204133423472SRichard Henderson 2042c603e14aSRichard Henderson static bool trans_mtctl(DisasContext *ctx, arg_mtctl *a) 204398a9cb79SRichard Henderson { 2044c603e14aSRichard Henderson unsigned ctl = a->t; 20456fd0c7bcSRichard Henderson TCGv_i64 reg; 20466fd0c7bcSRichard Henderson TCGv_i64 tmp; 204798a9cb79SRichard Henderson 204835136a77SRichard Henderson if (ctl == CR_SAR) { 20494845f015SSven Schnelle reg = load_gpr(ctx, a->r); 2050aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 20516fd0c7bcSRichard Henderson tcg_gen_andi_i64(tmp, reg, ctx->is_pa20 ? 63 : 31); 205298a9cb79SRichard Henderson save_or_nullify(ctx, cpu_sar, tmp); 205398a9cb79SRichard Henderson 205498a9cb79SRichard Henderson cond_free(&ctx->null_cond); 205531234768SRichard Henderson return true; 205698a9cb79SRichard Henderson } 205798a9cb79SRichard Henderson 205835136a77SRichard Henderson /* All other control registers are privileged or read-only. */ 205935136a77SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_REG); 206035136a77SRichard Henderson 2061c603e14aSRichard Henderson #ifndef CONFIG_USER_ONLY 206235136a77SRichard Henderson nullify_over(ctx); 20634845f015SSven Schnelle reg = load_gpr(ctx, a->r); 20644845f015SSven Schnelle 206535136a77SRichard Henderson switch (ctl) { 206635136a77SRichard Henderson case CR_IT: 2067ad75a51eSRichard Henderson gen_helper_write_interval_timer(tcg_env, reg); 206835136a77SRichard Henderson break; 20694f5f2548SRichard Henderson case CR_EIRR: 2070ad75a51eSRichard Henderson gen_helper_write_eirr(tcg_env, reg); 20714f5f2548SRichard Henderson break; 20724f5f2548SRichard Henderson case CR_EIEM: 2073ad75a51eSRichard Henderson gen_helper_write_eiem(tcg_env, reg); 207431234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE_EXIT; 20754f5f2548SRichard Henderson break; 20764f5f2548SRichard Henderson 207735136a77SRichard Henderson case CR_IIASQ: 207835136a77SRichard Henderson case CR_IIAOQ: 207935136a77SRichard Henderson /* FIXME: Respect PSW_Q bit */ 208035136a77SRichard Henderson /* The write advances the queue and stores to the back element. */ 2081aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 20826fd0c7bcSRichard Henderson tcg_gen_ld_i64(tmp, tcg_env, 208335136a77SRichard Henderson offsetof(CPUHPPAState, cr_back[ctl - CR_IIASQ])); 20846fd0c7bcSRichard Henderson tcg_gen_st_i64(tmp, tcg_env, offsetof(CPUHPPAState, cr[ctl])); 20856fd0c7bcSRichard Henderson tcg_gen_st_i64(reg, tcg_env, 208635136a77SRichard Henderson offsetof(CPUHPPAState, cr_back[ctl - CR_IIASQ])); 208735136a77SRichard Henderson break; 208835136a77SRichard Henderson 2089d5de20bdSSven Schnelle case CR_PID1: 2090d5de20bdSSven Schnelle case CR_PID2: 2091d5de20bdSSven Schnelle case CR_PID3: 2092d5de20bdSSven Schnelle case CR_PID4: 20936fd0c7bcSRichard Henderson tcg_gen_st_i64(reg, tcg_env, offsetof(CPUHPPAState, cr[ctl])); 2094d5de20bdSSven Schnelle #ifndef CONFIG_USER_ONLY 2095ad75a51eSRichard Henderson gen_helper_change_prot_id(tcg_env); 2096d5de20bdSSven Schnelle #endif 2097d5de20bdSSven Schnelle break; 2098d5de20bdSSven Schnelle 209935136a77SRichard Henderson default: 21006fd0c7bcSRichard Henderson tcg_gen_st_i64(reg, tcg_env, offsetof(CPUHPPAState, cr[ctl])); 210135136a77SRichard Henderson break; 210235136a77SRichard Henderson } 210331234768SRichard Henderson return nullify_end(ctx); 21044f5f2548SRichard Henderson #endif 210535136a77SRichard Henderson } 210635136a77SRichard Henderson 2107c603e14aSRichard Henderson static bool trans_mtsarcm(DisasContext *ctx, arg_mtsarcm *a) 210898a9cb79SRichard Henderson { 2109aac0f603SRichard Henderson TCGv_i64 tmp = tcg_temp_new_i64(); 211098a9cb79SRichard Henderson 21116fd0c7bcSRichard Henderson tcg_gen_not_i64(tmp, load_gpr(ctx, a->r)); 21126fd0c7bcSRichard Henderson tcg_gen_andi_i64(tmp, tmp, ctx->is_pa20 ? 63 : 31); 211398a9cb79SRichard Henderson save_or_nullify(ctx, cpu_sar, tmp); 211498a9cb79SRichard Henderson 211598a9cb79SRichard Henderson cond_free(&ctx->null_cond); 211631234768SRichard Henderson return true; 211798a9cb79SRichard Henderson } 211898a9cb79SRichard Henderson 2119e36f27efSRichard Henderson static bool trans_ldsid(DisasContext *ctx, arg_ldsid *a) 212098a9cb79SRichard Henderson { 21216fd0c7bcSRichard Henderson TCGv_i64 dest = dest_gpr(ctx, a->t); 212298a9cb79SRichard Henderson 21232330504cSHelge Deller #ifdef CONFIG_USER_ONLY 21242330504cSHelge Deller /* We don't implement space registers in user mode. */ 21256fd0c7bcSRichard Henderson tcg_gen_movi_i64(dest, 0); 21262330504cSHelge Deller #else 2127967662cdSRichard Henderson tcg_gen_mov_i64(dest, space_select(ctx, a->sp, load_gpr(ctx, a->b))); 2128967662cdSRichard Henderson tcg_gen_shri_i64(dest, dest, 32); 21292330504cSHelge Deller #endif 2130e36f27efSRichard Henderson save_gpr(ctx, a->t, dest); 213198a9cb79SRichard Henderson 213298a9cb79SRichard Henderson cond_free(&ctx->null_cond); 213331234768SRichard Henderson return true; 213498a9cb79SRichard Henderson } 213598a9cb79SRichard Henderson 2136e36f27efSRichard Henderson static bool trans_rsm(DisasContext *ctx, arg_rsm *a) 2137e36f27efSRichard Henderson { 2138e36f27efSRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 2139e1b5a5edSRichard Henderson #ifndef CONFIG_USER_ONLY 21406fd0c7bcSRichard Henderson TCGv_i64 tmp; 2141e1b5a5edSRichard Henderson 2142e1b5a5edSRichard Henderson nullify_over(ctx); 2143e1b5a5edSRichard Henderson 2144aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 21456fd0c7bcSRichard Henderson tcg_gen_ld_i64(tmp, tcg_env, offsetof(CPUHPPAState, psw)); 21466fd0c7bcSRichard Henderson tcg_gen_andi_i64(tmp, tmp, ~a->i); 2147ad75a51eSRichard Henderson gen_helper_swap_system_mask(tmp, tcg_env, tmp); 2148e36f27efSRichard Henderson save_gpr(ctx, a->t, tmp); 2149e1b5a5edSRichard Henderson 2150e1b5a5edSRichard Henderson /* Exit the TB to recognize new interrupts, e.g. PSW_M. */ 215131234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE_EXIT; 215231234768SRichard Henderson return nullify_end(ctx); 2153e36f27efSRichard Henderson #endif 2154e1b5a5edSRichard Henderson } 2155e1b5a5edSRichard Henderson 2156e36f27efSRichard Henderson static bool trans_ssm(DisasContext *ctx, arg_ssm *a) 2157e1b5a5edSRichard Henderson { 2158e36f27efSRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 2159e36f27efSRichard Henderson #ifndef CONFIG_USER_ONLY 21606fd0c7bcSRichard Henderson TCGv_i64 tmp; 2161e1b5a5edSRichard Henderson 2162e1b5a5edSRichard Henderson nullify_over(ctx); 2163e1b5a5edSRichard Henderson 2164aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 21656fd0c7bcSRichard Henderson tcg_gen_ld_i64(tmp, tcg_env, offsetof(CPUHPPAState, psw)); 21666fd0c7bcSRichard Henderson tcg_gen_ori_i64(tmp, tmp, a->i); 2167ad75a51eSRichard Henderson gen_helper_swap_system_mask(tmp, tcg_env, tmp); 2168e36f27efSRichard Henderson save_gpr(ctx, a->t, tmp); 2169e1b5a5edSRichard Henderson 2170e1b5a5edSRichard Henderson /* Exit the TB to recognize new interrupts, e.g. PSW_I. */ 217131234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE_EXIT; 217231234768SRichard Henderson return nullify_end(ctx); 2173e36f27efSRichard Henderson #endif 2174e1b5a5edSRichard Henderson } 2175e1b5a5edSRichard Henderson 2176c603e14aSRichard Henderson static bool trans_mtsm(DisasContext *ctx, arg_mtsm *a) 2177e1b5a5edSRichard Henderson { 2178e1b5a5edSRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 2179c603e14aSRichard Henderson #ifndef CONFIG_USER_ONLY 21806fd0c7bcSRichard Henderson TCGv_i64 tmp, reg; 2181e1b5a5edSRichard Henderson nullify_over(ctx); 2182e1b5a5edSRichard Henderson 2183c603e14aSRichard Henderson reg = load_gpr(ctx, a->r); 2184aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 2185ad75a51eSRichard Henderson gen_helper_swap_system_mask(tmp, tcg_env, reg); 2186e1b5a5edSRichard Henderson 2187e1b5a5edSRichard Henderson /* Exit the TB to recognize new interrupts. */ 218831234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE_EXIT; 218931234768SRichard Henderson return nullify_end(ctx); 2190c603e14aSRichard Henderson #endif 2191e1b5a5edSRichard Henderson } 2192f49b3537SRichard Henderson 2193e36f27efSRichard Henderson static bool do_rfi(DisasContext *ctx, bool rfi_r) 2194f49b3537SRichard Henderson { 2195f49b3537SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 2196e36f27efSRichard Henderson #ifndef CONFIG_USER_ONLY 2197f49b3537SRichard Henderson nullify_over(ctx); 2198f49b3537SRichard Henderson 2199e36f27efSRichard Henderson if (rfi_r) { 2200ad75a51eSRichard Henderson gen_helper_rfi_r(tcg_env); 2201f49b3537SRichard Henderson } else { 2202ad75a51eSRichard Henderson gen_helper_rfi(tcg_env); 2203f49b3537SRichard Henderson } 220431234768SRichard Henderson /* Exit the TB to recognize new interrupts. */ 220507ea28b4SRichard Henderson tcg_gen_exit_tb(NULL, 0); 220631234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 2207f49b3537SRichard Henderson 220831234768SRichard Henderson return nullify_end(ctx); 2209e36f27efSRichard Henderson #endif 2210f49b3537SRichard Henderson } 22116210db05SHelge Deller 2212e36f27efSRichard Henderson static bool trans_rfi(DisasContext *ctx, arg_rfi *a) 2213e36f27efSRichard Henderson { 2214e36f27efSRichard Henderson return do_rfi(ctx, false); 2215e36f27efSRichard Henderson } 2216e36f27efSRichard Henderson 2217e36f27efSRichard Henderson static bool trans_rfi_r(DisasContext *ctx, arg_rfi_r *a) 2218e36f27efSRichard Henderson { 2219e36f27efSRichard Henderson return do_rfi(ctx, true); 2220e36f27efSRichard Henderson } 2221e36f27efSRichard Henderson 222296927adbSRichard Henderson static bool trans_halt(DisasContext *ctx, arg_halt *a) 22236210db05SHelge Deller { 22246210db05SHelge Deller CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 222596927adbSRichard Henderson #ifndef CONFIG_USER_ONLY 22266210db05SHelge Deller nullify_over(ctx); 2227ad75a51eSRichard Henderson gen_helper_halt(tcg_env); 222831234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 222931234768SRichard Henderson return nullify_end(ctx); 223096927adbSRichard Henderson #endif 22316210db05SHelge Deller } 223296927adbSRichard Henderson 223396927adbSRichard Henderson static bool trans_reset(DisasContext *ctx, arg_reset *a) 223496927adbSRichard Henderson { 223596927adbSRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 223696927adbSRichard Henderson #ifndef CONFIG_USER_ONLY 223796927adbSRichard Henderson nullify_over(ctx); 2238ad75a51eSRichard Henderson gen_helper_reset(tcg_env); 223996927adbSRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 224096927adbSRichard Henderson return nullify_end(ctx); 224196927adbSRichard Henderson #endif 224296927adbSRichard Henderson } 2243e1b5a5edSRichard Henderson 22444a4554c6SHelge Deller static bool trans_getshadowregs(DisasContext *ctx, arg_getshadowregs *a) 22454a4554c6SHelge Deller { 22464a4554c6SHelge Deller CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 22474a4554c6SHelge Deller #ifndef CONFIG_USER_ONLY 22484a4554c6SHelge Deller nullify_over(ctx); 2249ad75a51eSRichard Henderson gen_helper_getshadowregs(tcg_env); 22504a4554c6SHelge Deller return nullify_end(ctx); 22514a4554c6SHelge Deller #endif 22524a4554c6SHelge Deller } 22534a4554c6SHelge Deller 2254deee69a1SRichard Henderson static bool trans_nop_addrx(DisasContext *ctx, arg_ldst *a) 225598a9cb79SRichard Henderson { 2256deee69a1SRichard Henderson if (a->m) { 22576fd0c7bcSRichard Henderson TCGv_i64 dest = dest_gpr(ctx, a->b); 22586fd0c7bcSRichard Henderson TCGv_i64 src1 = load_gpr(ctx, a->b); 22596fd0c7bcSRichard Henderson TCGv_i64 src2 = load_gpr(ctx, a->x); 226098a9cb79SRichard Henderson 226198a9cb79SRichard Henderson /* The only thing we need to do is the base register modification. */ 22626fd0c7bcSRichard Henderson tcg_gen_add_i64(dest, src1, src2); 2263deee69a1SRichard Henderson save_gpr(ctx, a->b, dest); 2264deee69a1SRichard Henderson } 226598a9cb79SRichard Henderson cond_free(&ctx->null_cond); 226631234768SRichard Henderson return true; 226798a9cb79SRichard Henderson } 226898a9cb79SRichard Henderson 2269deee69a1SRichard Henderson static bool trans_probe(DisasContext *ctx, arg_probe *a) 227098a9cb79SRichard Henderson { 22716fd0c7bcSRichard Henderson TCGv_i64 dest, ofs; 2272eed14219SRichard Henderson TCGv_i32 level, want; 22736fd0c7bcSRichard Henderson TCGv_i64 addr; 227498a9cb79SRichard Henderson 227598a9cb79SRichard Henderson nullify_over(ctx); 227698a9cb79SRichard Henderson 2277deee69a1SRichard Henderson dest = dest_gpr(ctx, a->t); 2278deee69a1SRichard Henderson form_gva(ctx, &addr, &ofs, a->b, 0, 0, 0, a->sp, 0, false); 2279eed14219SRichard Henderson 2280deee69a1SRichard Henderson if (a->imm) { 228129dd6f64SRichard Henderson level = tcg_constant_i32(a->ri); 228298a9cb79SRichard Henderson } else { 2283eed14219SRichard Henderson level = tcg_temp_new_i32(); 22846fd0c7bcSRichard Henderson tcg_gen_extrl_i64_i32(level, load_gpr(ctx, a->ri)); 2285eed14219SRichard Henderson tcg_gen_andi_i32(level, level, 3); 228698a9cb79SRichard Henderson } 228729dd6f64SRichard Henderson want = tcg_constant_i32(a->write ? PAGE_WRITE : PAGE_READ); 2288eed14219SRichard Henderson 2289ad75a51eSRichard Henderson gen_helper_probe(dest, tcg_env, addr, level, want); 2290eed14219SRichard Henderson 2291deee69a1SRichard Henderson save_gpr(ctx, a->t, dest); 229231234768SRichard Henderson return nullify_end(ctx); 229398a9cb79SRichard Henderson } 229498a9cb79SRichard Henderson 2295deee69a1SRichard Henderson static bool trans_ixtlbx(DisasContext *ctx, arg_ixtlbx *a) 22968d6ae7fbSRichard Henderson { 22978577f354SRichard Henderson if (ctx->is_pa20) { 22988577f354SRichard Henderson return false; 22998577f354SRichard Henderson } 2300deee69a1SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 2301deee69a1SRichard Henderson #ifndef CONFIG_USER_ONLY 23026fd0c7bcSRichard Henderson TCGv_i64 addr; 23036fd0c7bcSRichard Henderson TCGv_i64 ofs, reg; 23048d6ae7fbSRichard Henderson 23058d6ae7fbSRichard Henderson nullify_over(ctx); 23068d6ae7fbSRichard Henderson 2307deee69a1SRichard Henderson form_gva(ctx, &addr, &ofs, a->b, 0, 0, 0, a->sp, 0, false); 2308deee69a1SRichard Henderson reg = load_gpr(ctx, a->r); 2309deee69a1SRichard Henderson if (a->addr) { 23108577f354SRichard Henderson gen_helper_itlba_pa11(tcg_env, addr, reg); 23118d6ae7fbSRichard Henderson } else { 23128577f354SRichard Henderson gen_helper_itlbp_pa11(tcg_env, addr, reg); 23138d6ae7fbSRichard Henderson } 23148d6ae7fbSRichard Henderson 231532dc7569SSven Schnelle /* Exit TB for TLB change if mmu is enabled. */ 231632dc7569SSven Schnelle if (ctx->tb_flags & PSW_C) { 231731234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE; 231831234768SRichard Henderson } 231931234768SRichard Henderson return nullify_end(ctx); 2320deee69a1SRichard Henderson #endif 23218d6ae7fbSRichard Henderson } 232263300a00SRichard Henderson 2323deee69a1SRichard Henderson static bool trans_pxtlbx(DisasContext *ctx, arg_pxtlbx *a) 232463300a00SRichard Henderson { 2325deee69a1SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 2326deee69a1SRichard Henderson #ifndef CONFIG_USER_ONLY 23276fd0c7bcSRichard Henderson TCGv_i64 addr; 23286fd0c7bcSRichard Henderson TCGv_i64 ofs; 232963300a00SRichard Henderson 233063300a00SRichard Henderson nullify_over(ctx); 233163300a00SRichard Henderson 2332deee69a1SRichard Henderson form_gva(ctx, &addr, &ofs, a->b, a->x, 0, 0, a->sp, a->m, false); 2333deee69a1SRichard Henderson if (a->m) { 2334deee69a1SRichard Henderson save_gpr(ctx, a->b, ofs); 233563300a00SRichard Henderson } 2336deee69a1SRichard Henderson if (a->local) { 2337ad75a51eSRichard Henderson gen_helper_ptlbe(tcg_env); 233863300a00SRichard Henderson } else { 2339ad75a51eSRichard Henderson gen_helper_ptlb(tcg_env, addr); 234063300a00SRichard Henderson } 234163300a00SRichard Henderson 234263300a00SRichard Henderson /* Exit TB for TLB change if mmu is enabled. */ 234332dc7569SSven Schnelle if (ctx->tb_flags & PSW_C) { 234431234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE; 234531234768SRichard Henderson } 234631234768SRichard Henderson return nullify_end(ctx); 2347deee69a1SRichard Henderson #endif 234863300a00SRichard Henderson } 23492dfcca9fSRichard Henderson 23506797c315SNick Hudson /* 23516797c315SNick Hudson * Implement the pcxl and pcxl2 Fast TLB Insert instructions. 23526797c315SNick Hudson * See 23536797c315SNick Hudson * https://parisc.wiki.kernel.org/images-parisc/a/a9/Pcxl2_ers.pdf 23546797c315SNick Hudson * page 13-9 (195/206) 23556797c315SNick Hudson */ 23566797c315SNick Hudson static bool trans_ixtlbxf(DisasContext *ctx, arg_ixtlbxf *a) 23576797c315SNick Hudson { 23588577f354SRichard Henderson if (ctx->is_pa20) { 23598577f354SRichard Henderson return false; 23608577f354SRichard Henderson } 23616797c315SNick Hudson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 23626797c315SNick Hudson #ifndef CONFIG_USER_ONLY 23636fd0c7bcSRichard Henderson TCGv_i64 addr, atl, stl; 23646fd0c7bcSRichard Henderson TCGv_i64 reg; 23656797c315SNick Hudson 23666797c315SNick Hudson nullify_over(ctx); 23676797c315SNick Hudson 23686797c315SNick Hudson /* 23696797c315SNick Hudson * FIXME: 23706797c315SNick Hudson * if (not (pcxl or pcxl2)) 23716797c315SNick Hudson * return gen_illegal(ctx); 23726797c315SNick Hudson */ 23736797c315SNick Hudson 23746fd0c7bcSRichard Henderson atl = tcg_temp_new_i64(); 23756fd0c7bcSRichard Henderson stl = tcg_temp_new_i64(); 23766fd0c7bcSRichard Henderson addr = tcg_temp_new_i64(); 23776797c315SNick Hudson 2378ad75a51eSRichard Henderson tcg_gen_ld32u_i64(stl, tcg_env, 23796797c315SNick Hudson a->data ? offsetof(CPUHPPAState, cr[CR_ISR]) 23806797c315SNick Hudson : offsetof(CPUHPPAState, cr[CR_IIASQ])); 2381ad75a51eSRichard Henderson tcg_gen_ld32u_i64(atl, tcg_env, 23826797c315SNick Hudson a->data ? offsetof(CPUHPPAState, cr[CR_IOR]) 23836797c315SNick Hudson : offsetof(CPUHPPAState, cr[CR_IIAOQ])); 23846797c315SNick Hudson tcg_gen_shli_i64(stl, stl, 32); 2385d265360fSRichard Henderson tcg_gen_or_i64(addr, atl, stl); 23866797c315SNick Hudson 23876797c315SNick Hudson reg = load_gpr(ctx, a->r); 23886797c315SNick Hudson if (a->addr) { 23898577f354SRichard Henderson gen_helper_itlba_pa11(tcg_env, addr, reg); 23906797c315SNick Hudson } else { 23918577f354SRichard Henderson gen_helper_itlbp_pa11(tcg_env, addr, reg); 23926797c315SNick Hudson } 23936797c315SNick Hudson 23946797c315SNick Hudson /* Exit TB for TLB change if mmu is enabled. */ 23956797c315SNick Hudson if (ctx->tb_flags & PSW_C) { 23966797c315SNick Hudson ctx->base.is_jmp = DISAS_IAQ_N_STALE; 23976797c315SNick Hudson } 23986797c315SNick Hudson return nullify_end(ctx); 23996797c315SNick Hudson #endif 24006797c315SNick Hudson } 24016797c315SNick Hudson 24028577f354SRichard Henderson static bool trans_ixtlbt(DisasContext *ctx, arg_ixtlbt *a) 24038577f354SRichard Henderson { 24048577f354SRichard Henderson if (!ctx->is_pa20) { 24058577f354SRichard Henderson return false; 24068577f354SRichard Henderson } 24078577f354SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 24088577f354SRichard Henderson #ifndef CONFIG_USER_ONLY 24098577f354SRichard Henderson nullify_over(ctx); 24108577f354SRichard Henderson { 24118577f354SRichard Henderson TCGv_i64 src1 = load_gpr(ctx, a->r1); 24128577f354SRichard Henderson TCGv_i64 src2 = load_gpr(ctx, a->r2); 24138577f354SRichard Henderson 24148577f354SRichard Henderson if (a->data) { 24158577f354SRichard Henderson gen_helper_idtlbt_pa20(tcg_env, src1, src2); 24168577f354SRichard Henderson } else { 24178577f354SRichard Henderson gen_helper_iitlbt_pa20(tcg_env, src1, src2); 24188577f354SRichard Henderson } 24198577f354SRichard Henderson } 24208577f354SRichard Henderson /* Exit TB for TLB change if mmu is enabled. */ 24218577f354SRichard Henderson if (ctx->tb_flags & PSW_C) { 24228577f354SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE; 24238577f354SRichard Henderson } 24248577f354SRichard Henderson return nullify_end(ctx); 24258577f354SRichard Henderson #endif 24268577f354SRichard Henderson } 24278577f354SRichard Henderson 2428deee69a1SRichard Henderson static bool trans_lpa(DisasContext *ctx, arg_ldst *a) 24292dfcca9fSRichard Henderson { 2430deee69a1SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 2431deee69a1SRichard Henderson #ifndef CONFIG_USER_ONLY 24326fd0c7bcSRichard Henderson TCGv_i64 vaddr; 24336fd0c7bcSRichard Henderson TCGv_i64 ofs, paddr; 24342dfcca9fSRichard Henderson 24352dfcca9fSRichard Henderson nullify_over(ctx); 24362dfcca9fSRichard Henderson 2437deee69a1SRichard Henderson form_gva(ctx, &vaddr, &ofs, a->b, a->x, 0, 0, a->sp, a->m, false); 24382dfcca9fSRichard Henderson 2439aac0f603SRichard Henderson paddr = tcg_temp_new_i64(); 2440ad75a51eSRichard Henderson gen_helper_lpa(paddr, tcg_env, vaddr); 24412dfcca9fSRichard Henderson 24422dfcca9fSRichard Henderson /* Note that physical address result overrides base modification. */ 2443deee69a1SRichard Henderson if (a->m) { 2444deee69a1SRichard Henderson save_gpr(ctx, a->b, ofs); 24452dfcca9fSRichard Henderson } 2446deee69a1SRichard Henderson save_gpr(ctx, a->t, paddr); 24472dfcca9fSRichard Henderson 244831234768SRichard Henderson return nullify_end(ctx); 2449deee69a1SRichard Henderson #endif 24502dfcca9fSRichard Henderson } 245143a97b81SRichard Henderson 2452deee69a1SRichard Henderson static bool trans_lci(DisasContext *ctx, arg_lci *a) 245343a97b81SRichard Henderson { 245443a97b81SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 245543a97b81SRichard Henderson 245643a97b81SRichard Henderson /* The Coherence Index is an implementation-defined function of the 245743a97b81SRichard Henderson physical address. Two addresses with the same CI have a coherent 245843a97b81SRichard Henderson view of the cache. Our implementation is to return 0 for all, 245943a97b81SRichard Henderson since the entire address space is coherent. */ 2460a4db4a78SRichard Henderson save_gpr(ctx, a->t, ctx->zero); 246143a97b81SRichard Henderson 246231234768SRichard Henderson cond_free(&ctx->null_cond); 246331234768SRichard Henderson return true; 246443a97b81SRichard Henderson } 246598a9cb79SRichard Henderson 2466faf97ba1SRichard Henderson static bool trans_add(DisasContext *ctx, arg_rrr_cf_d_sh *a) 2467b2167459SRichard Henderson { 24680c982a28SRichard Henderson return do_add_reg(ctx, a, false, false, false, false); 2469b2167459SRichard Henderson } 2470b2167459SRichard Henderson 2471faf97ba1SRichard Henderson static bool trans_add_l(DisasContext *ctx, arg_rrr_cf_d_sh *a) 2472b2167459SRichard Henderson { 24730c982a28SRichard Henderson return do_add_reg(ctx, a, true, false, false, false); 2474b2167459SRichard Henderson } 2475b2167459SRichard Henderson 2476faf97ba1SRichard Henderson static bool trans_add_tsv(DisasContext *ctx, arg_rrr_cf_d_sh *a) 2477b2167459SRichard Henderson { 24780c982a28SRichard Henderson return do_add_reg(ctx, a, false, true, false, false); 2479b2167459SRichard Henderson } 2480b2167459SRichard Henderson 2481faf97ba1SRichard Henderson static bool trans_add_c(DisasContext *ctx, arg_rrr_cf_d_sh *a) 2482b2167459SRichard Henderson { 24830c982a28SRichard Henderson return do_add_reg(ctx, a, false, false, false, true); 24840c982a28SRichard Henderson } 2485b2167459SRichard Henderson 2486faf97ba1SRichard Henderson static bool trans_add_c_tsv(DisasContext *ctx, arg_rrr_cf_d_sh *a) 24870c982a28SRichard Henderson { 24880c982a28SRichard Henderson return do_add_reg(ctx, a, false, true, false, true); 24890c982a28SRichard Henderson } 24900c982a28SRichard Henderson 249163c427c6SRichard Henderson static bool trans_sub(DisasContext *ctx, arg_rrr_cf_d *a) 24920c982a28SRichard Henderson { 24930c982a28SRichard Henderson return do_sub_reg(ctx, a, false, false, false); 24940c982a28SRichard Henderson } 24950c982a28SRichard Henderson 249663c427c6SRichard Henderson static bool trans_sub_tsv(DisasContext *ctx, arg_rrr_cf_d *a) 24970c982a28SRichard Henderson { 24980c982a28SRichard Henderson return do_sub_reg(ctx, a, true, false, false); 24990c982a28SRichard Henderson } 25000c982a28SRichard Henderson 250163c427c6SRichard Henderson static bool trans_sub_tc(DisasContext *ctx, arg_rrr_cf_d *a) 25020c982a28SRichard Henderson { 25030c982a28SRichard Henderson return do_sub_reg(ctx, a, false, false, true); 25040c982a28SRichard Henderson } 25050c982a28SRichard Henderson 250663c427c6SRichard Henderson static bool trans_sub_tsv_tc(DisasContext *ctx, arg_rrr_cf_d *a) 25070c982a28SRichard Henderson { 25080c982a28SRichard Henderson return do_sub_reg(ctx, a, true, false, true); 25090c982a28SRichard Henderson } 25100c982a28SRichard Henderson 251163c427c6SRichard Henderson static bool trans_sub_b(DisasContext *ctx, arg_rrr_cf_d *a) 25120c982a28SRichard Henderson { 25130c982a28SRichard Henderson return do_sub_reg(ctx, a, false, true, false); 25140c982a28SRichard Henderson } 25150c982a28SRichard Henderson 251663c427c6SRichard Henderson static bool trans_sub_b_tsv(DisasContext *ctx, arg_rrr_cf_d *a) 25170c982a28SRichard Henderson { 25180c982a28SRichard Henderson return do_sub_reg(ctx, a, true, true, false); 25190c982a28SRichard Henderson } 25200c982a28SRichard Henderson 2521fa8e3bedSRichard Henderson static bool trans_andcm(DisasContext *ctx, arg_rrr_cf_d *a) 25220c982a28SRichard Henderson { 25236fd0c7bcSRichard Henderson return do_log_reg(ctx, a, tcg_gen_andc_i64); 25240c982a28SRichard Henderson } 25250c982a28SRichard Henderson 2526fa8e3bedSRichard Henderson static bool trans_and(DisasContext *ctx, arg_rrr_cf_d *a) 25270c982a28SRichard Henderson { 25286fd0c7bcSRichard Henderson return do_log_reg(ctx, a, tcg_gen_and_i64); 25290c982a28SRichard Henderson } 25300c982a28SRichard Henderson 2531fa8e3bedSRichard Henderson static bool trans_or(DisasContext *ctx, arg_rrr_cf_d *a) 25320c982a28SRichard Henderson { 25330c982a28SRichard Henderson if (a->cf == 0) { 25340c982a28SRichard Henderson unsigned r2 = a->r2; 25350c982a28SRichard Henderson unsigned r1 = a->r1; 25360c982a28SRichard Henderson unsigned rt = a->t; 25370c982a28SRichard Henderson 25387aee8189SRichard Henderson if (rt == 0) { /* NOP */ 25397aee8189SRichard Henderson cond_free(&ctx->null_cond); 25407aee8189SRichard Henderson return true; 25417aee8189SRichard Henderson } 25427aee8189SRichard Henderson if (r2 == 0) { /* COPY */ 2543b2167459SRichard Henderson if (r1 == 0) { 25446fd0c7bcSRichard Henderson TCGv_i64 dest = dest_gpr(ctx, rt); 25456fd0c7bcSRichard Henderson tcg_gen_movi_i64(dest, 0); 2546b2167459SRichard Henderson save_gpr(ctx, rt, dest); 2547b2167459SRichard Henderson } else { 2548b2167459SRichard Henderson save_gpr(ctx, rt, cpu_gr[r1]); 2549b2167459SRichard Henderson } 2550b2167459SRichard Henderson cond_free(&ctx->null_cond); 255131234768SRichard Henderson return true; 2552b2167459SRichard Henderson } 25537aee8189SRichard Henderson #ifndef CONFIG_USER_ONLY 25547aee8189SRichard Henderson /* These are QEMU extensions and are nops in the real architecture: 25557aee8189SRichard Henderson * 25567aee8189SRichard Henderson * or %r10,%r10,%r10 -- idle loop; wait for interrupt 25577aee8189SRichard Henderson * or %r31,%r31,%r31 -- death loop; offline cpu 25587aee8189SRichard Henderson * currently implemented as idle. 25597aee8189SRichard Henderson */ 25607aee8189SRichard Henderson if ((rt == 10 || rt == 31) && r1 == rt && r2 == rt) { /* PAUSE */ 25617aee8189SRichard Henderson /* No need to check for supervisor, as userland can only pause 25627aee8189SRichard Henderson until the next timer interrupt. */ 25637aee8189SRichard Henderson nullify_over(ctx); 25647aee8189SRichard Henderson 25657aee8189SRichard Henderson /* Advance the instruction queue. */ 2566741322f4SRichard Henderson copy_iaoq_entry(ctx, cpu_iaoq_f, ctx->iaoq_b, cpu_iaoq_b); 2567741322f4SRichard Henderson copy_iaoq_entry(ctx, cpu_iaoq_b, ctx->iaoq_n, ctx->iaoq_n_var); 25687aee8189SRichard Henderson nullify_set(ctx, 0); 25697aee8189SRichard Henderson 25707aee8189SRichard Henderson /* Tell the qemu main loop to halt until this cpu has work. */ 2571ad75a51eSRichard Henderson tcg_gen_st_i32(tcg_constant_i32(1), tcg_env, 257229dd6f64SRichard Henderson offsetof(CPUState, halted) - offsetof(HPPACPU, env)); 25737aee8189SRichard Henderson gen_excp_1(EXCP_HALTED); 25747aee8189SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 25757aee8189SRichard Henderson 25767aee8189SRichard Henderson return nullify_end(ctx); 25777aee8189SRichard Henderson } 25787aee8189SRichard Henderson #endif 25797aee8189SRichard Henderson } 25806fd0c7bcSRichard Henderson return do_log_reg(ctx, a, tcg_gen_or_i64); 25817aee8189SRichard Henderson } 2582b2167459SRichard Henderson 2583fa8e3bedSRichard Henderson static bool trans_xor(DisasContext *ctx, arg_rrr_cf_d *a) 2584b2167459SRichard Henderson { 25856fd0c7bcSRichard Henderson return do_log_reg(ctx, a, tcg_gen_xor_i64); 25860c982a28SRichard Henderson } 25870c982a28SRichard Henderson 2588345aa35fSRichard Henderson static bool trans_cmpclr(DisasContext *ctx, arg_rrr_cf_d *a) 25890c982a28SRichard Henderson { 25906fd0c7bcSRichard Henderson TCGv_i64 tcg_r1, tcg_r2; 2591b2167459SRichard Henderson 25920c982a28SRichard Henderson if (a->cf) { 2593b2167459SRichard Henderson nullify_over(ctx); 2594b2167459SRichard Henderson } 25950c982a28SRichard Henderson tcg_r1 = load_gpr(ctx, a->r1); 25960c982a28SRichard Henderson tcg_r2 = load_gpr(ctx, a->r2); 2597345aa35fSRichard Henderson do_cmpclr(ctx, a->t, tcg_r1, tcg_r2, a->cf, a->d); 259831234768SRichard Henderson return nullify_end(ctx); 2599b2167459SRichard Henderson } 2600b2167459SRichard Henderson 2601af240753SRichard Henderson static bool trans_uxor(DisasContext *ctx, arg_rrr_cf_d *a) 2602b2167459SRichard Henderson { 26036fd0c7bcSRichard Henderson TCGv_i64 tcg_r1, tcg_r2; 2604b2167459SRichard Henderson 26050c982a28SRichard Henderson if (a->cf) { 2606b2167459SRichard Henderson nullify_over(ctx); 2607b2167459SRichard Henderson } 26080c982a28SRichard Henderson tcg_r1 = load_gpr(ctx, a->r1); 26090c982a28SRichard Henderson tcg_r2 = load_gpr(ctx, a->r2); 26106fd0c7bcSRichard Henderson do_unit(ctx, a->t, tcg_r1, tcg_r2, a->cf, a->d, false, tcg_gen_xor_i64); 261131234768SRichard Henderson return nullify_end(ctx); 2612b2167459SRichard Henderson } 2613b2167459SRichard Henderson 2614af240753SRichard Henderson static bool do_uaddcm(DisasContext *ctx, arg_rrr_cf_d *a, bool is_tc) 2615b2167459SRichard Henderson { 26166fd0c7bcSRichard Henderson TCGv_i64 tcg_r1, tcg_r2, tmp; 2617b2167459SRichard Henderson 26180c982a28SRichard Henderson if (a->cf) { 2619b2167459SRichard Henderson nullify_over(ctx); 2620b2167459SRichard Henderson } 26210c982a28SRichard Henderson tcg_r1 = load_gpr(ctx, a->r1); 26220c982a28SRichard Henderson tcg_r2 = load_gpr(ctx, a->r2); 2623aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 26246fd0c7bcSRichard Henderson tcg_gen_not_i64(tmp, tcg_r2); 26256fd0c7bcSRichard Henderson do_unit(ctx, a->t, tcg_r1, tmp, a->cf, a->d, is_tc, tcg_gen_add_i64); 262631234768SRichard Henderson return nullify_end(ctx); 2627b2167459SRichard Henderson } 2628b2167459SRichard Henderson 2629af240753SRichard Henderson static bool trans_uaddcm(DisasContext *ctx, arg_rrr_cf_d *a) 2630b2167459SRichard Henderson { 26310c982a28SRichard Henderson return do_uaddcm(ctx, a, false); 26320c982a28SRichard Henderson } 26330c982a28SRichard Henderson 2634af240753SRichard Henderson static bool trans_uaddcm_tc(DisasContext *ctx, arg_rrr_cf_d *a) 26350c982a28SRichard Henderson { 26360c982a28SRichard Henderson return do_uaddcm(ctx, a, true); 26370c982a28SRichard Henderson } 26380c982a28SRichard Henderson 2639af240753SRichard Henderson static bool do_dcor(DisasContext *ctx, arg_rr_cf_d *a, bool is_i) 26400c982a28SRichard Henderson { 26416fd0c7bcSRichard Henderson TCGv_i64 tmp; 2642b2167459SRichard Henderson 2643b2167459SRichard Henderson nullify_over(ctx); 2644b2167459SRichard Henderson 2645aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 26466fd0c7bcSRichard Henderson tcg_gen_shri_i64(tmp, cpu_psw_cb, 3); 2647b2167459SRichard Henderson if (!is_i) { 26486fd0c7bcSRichard Henderson tcg_gen_not_i64(tmp, tmp); 2649b2167459SRichard Henderson } 26506fd0c7bcSRichard Henderson tcg_gen_andi_i64(tmp, tmp, (uint64_t)0x1111111111111111ull); 26516fd0c7bcSRichard Henderson tcg_gen_muli_i64(tmp, tmp, 6); 2652af240753SRichard Henderson do_unit(ctx, a->t, load_gpr(ctx, a->r), tmp, a->cf, a->d, false, 26536fd0c7bcSRichard Henderson is_i ? tcg_gen_add_i64 : tcg_gen_sub_i64); 265431234768SRichard Henderson return nullify_end(ctx); 2655b2167459SRichard Henderson } 2656b2167459SRichard Henderson 2657af240753SRichard Henderson static bool trans_dcor(DisasContext *ctx, arg_rr_cf_d *a) 2658b2167459SRichard Henderson { 26590c982a28SRichard Henderson return do_dcor(ctx, a, false); 26600c982a28SRichard Henderson } 26610c982a28SRichard Henderson 2662af240753SRichard Henderson static bool trans_dcor_i(DisasContext *ctx, arg_rr_cf_d *a) 26630c982a28SRichard Henderson { 26640c982a28SRichard Henderson return do_dcor(ctx, a, true); 26650c982a28SRichard Henderson } 26660c982a28SRichard Henderson 26670c982a28SRichard Henderson static bool trans_ds(DisasContext *ctx, arg_rrr_cf *a) 26680c982a28SRichard Henderson { 2669a4db4a78SRichard Henderson TCGv_i64 dest, add1, add2, addc, in1, in2; 26706fd0c7bcSRichard Henderson TCGv_i64 cout; 2671b2167459SRichard Henderson 2672b2167459SRichard Henderson nullify_over(ctx); 2673b2167459SRichard Henderson 26740c982a28SRichard Henderson in1 = load_gpr(ctx, a->r1); 26750c982a28SRichard Henderson in2 = load_gpr(ctx, a->r2); 2676b2167459SRichard Henderson 2677aac0f603SRichard Henderson add1 = tcg_temp_new_i64(); 2678aac0f603SRichard Henderson add2 = tcg_temp_new_i64(); 2679aac0f603SRichard Henderson addc = tcg_temp_new_i64(); 2680aac0f603SRichard Henderson dest = tcg_temp_new_i64(); 2681b2167459SRichard Henderson 2682b2167459SRichard Henderson /* Form R1 << 1 | PSW[CB]{8}. */ 26836fd0c7bcSRichard Henderson tcg_gen_add_i64(add1, in1, in1); 26846fd0c7bcSRichard Henderson tcg_gen_add_i64(add1, add1, get_psw_carry(ctx, false)); 2685b2167459SRichard Henderson 268672ca8753SRichard Henderson /* 268772ca8753SRichard Henderson * Add or subtract R2, depending on PSW[V]. Proper computation of 268872ca8753SRichard Henderson * carry requires that we subtract via + ~R2 + 1, as described in 268972ca8753SRichard Henderson * the manual. By extracting and masking V, we can produce the 269072ca8753SRichard Henderson * proper inputs to the addition without movcond. 269172ca8753SRichard Henderson */ 26926fd0c7bcSRichard Henderson tcg_gen_sextract_i64(addc, cpu_psw_v, 31, 1); 26936fd0c7bcSRichard Henderson tcg_gen_xor_i64(add2, in2, addc); 26946fd0c7bcSRichard Henderson tcg_gen_andi_i64(addc, addc, 1); 269572ca8753SRichard Henderson 2696a4db4a78SRichard Henderson tcg_gen_add2_i64(dest, cpu_psw_cb_msb, add1, ctx->zero, add2, ctx->zero); 2697a4db4a78SRichard Henderson tcg_gen_add2_i64(dest, cpu_psw_cb_msb, dest, cpu_psw_cb_msb, 2698a4db4a78SRichard Henderson addc, ctx->zero); 2699b2167459SRichard Henderson 2700b2167459SRichard Henderson /* Write back the result register. */ 27010c982a28SRichard Henderson save_gpr(ctx, a->t, dest); 2702b2167459SRichard Henderson 2703b2167459SRichard Henderson /* Write back PSW[CB]. */ 27046fd0c7bcSRichard Henderson tcg_gen_xor_i64(cpu_psw_cb, add1, add2); 27056fd0c7bcSRichard Henderson tcg_gen_xor_i64(cpu_psw_cb, cpu_psw_cb, dest); 2706b2167459SRichard Henderson 2707b2167459SRichard Henderson /* Write back PSW[V] for the division step. */ 270872ca8753SRichard Henderson cout = get_psw_carry(ctx, false); 27096fd0c7bcSRichard Henderson tcg_gen_neg_i64(cpu_psw_v, cout); 27106fd0c7bcSRichard Henderson tcg_gen_xor_i64(cpu_psw_v, cpu_psw_v, in2); 2711b2167459SRichard Henderson 2712b2167459SRichard Henderson /* Install the new nullification. */ 27130c982a28SRichard Henderson if (a->cf) { 27146fd0c7bcSRichard Henderson TCGv_i64 sv = NULL; 2715b47a4a02SSven Schnelle if (cond_need_sv(a->cf >> 1)) { 2716b2167459SRichard Henderson /* ??? The lshift is supposed to contribute to overflow. */ 2717b2167459SRichard Henderson sv = do_add_sv(ctx, dest, add1, add2); 2718b2167459SRichard Henderson } 2719a751eb31SRichard Henderson ctx->null_cond = do_cond(ctx, a->cf, false, dest, cout, sv); 2720b2167459SRichard Henderson } 2721b2167459SRichard Henderson 272231234768SRichard Henderson return nullify_end(ctx); 2723b2167459SRichard Henderson } 2724b2167459SRichard Henderson 27250588e061SRichard Henderson static bool trans_addi(DisasContext *ctx, arg_rri_cf *a) 2726b2167459SRichard Henderson { 27270588e061SRichard Henderson return do_add_imm(ctx, a, false, false); 27280588e061SRichard Henderson } 27290588e061SRichard Henderson 27300588e061SRichard Henderson static bool trans_addi_tsv(DisasContext *ctx, arg_rri_cf *a) 27310588e061SRichard Henderson { 27320588e061SRichard Henderson return do_add_imm(ctx, a, true, false); 27330588e061SRichard Henderson } 27340588e061SRichard Henderson 27350588e061SRichard Henderson static bool trans_addi_tc(DisasContext *ctx, arg_rri_cf *a) 27360588e061SRichard Henderson { 27370588e061SRichard Henderson return do_add_imm(ctx, a, false, true); 27380588e061SRichard Henderson } 27390588e061SRichard Henderson 27400588e061SRichard Henderson static bool trans_addi_tc_tsv(DisasContext *ctx, arg_rri_cf *a) 27410588e061SRichard Henderson { 27420588e061SRichard Henderson return do_add_imm(ctx, a, true, true); 27430588e061SRichard Henderson } 27440588e061SRichard Henderson 27450588e061SRichard Henderson static bool trans_subi(DisasContext *ctx, arg_rri_cf *a) 27460588e061SRichard Henderson { 27470588e061SRichard Henderson return do_sub_imm(ctx, a, false); 27480588e061SRichard Henderson } 27490588e061SRichard Henderson 27500588e061SRichard Henderson static bool trans_subi_tsv(DisasContext *ctx, arg_rri_cf *a) 27510588e061SRichard Henderson { 27520588e061SRichard Henderson return do_sub_imm(ctx, a, true); 27530588e061SRichard Henderson } 27540588e061SRichard Henderson 2755345aa35fSRichard Henderson static bool trans_cmpiclr(DisasContext *ctx, arg_rri_cf_d *a) 27560588e061SRichard Henderson { 27576fd0c7bcSRichard Henderson TCGv_i64 tcg_im, tcg_r2; 2758b2167459SRichard Henderson 27590588e061SRichard Henderson if (a->cf) { 2760b2167459SRichard Henderson nullify_over(ctx); 2761b2167459SRichard Henderson } 2762b2167459SRichard Henderson 27636fd0c7bcSRichard Henderson tcg_im = tcg_constant_i64(a->i); 27640588e061SRichard Henderson tcg_r2 = load_gpr(ctx, a->r); 2765345aa35fSRichard Henderson do_cmpclr(ctx, a->t, tcg_im, tcg_r2, a->cf, a->d); 2766b2167459SRichard Henderson 276731234768SRichard Henderson return nullify_end(ctx); 2768b2167459SRichard Henderson } 2769b2167459SRichard Henderson 27700843563fSRichard Henderson static bool do_multimedia(DisasContext *ctx, arg_rrr *a, 27710843563fSRichard Henderson void (*fn)(TCGv_i64, TCGv_i64, TCGv_i64)) 27720843563fSRichard Henderson { 27730843563fSRichard Henderson TCGv_i64 r1, r2, dest; 27740843563fSRichard Henderson 27750843563fSRichard Henderson if (!ctx->is_pa20) { 27760843563fSRichard Henderson return false; 27770843563fSRichard Henderson } 27780843563fSRichard Henderson 27790843563fSRichard Henderson nullify_over(ctx); 27800843563fSRichard Henderson 27810843563fSRichard Henderson r1 = load_gpr(ctx, a->r1); 27820843563fSRichard Henderson r2 = load_gpr(ctx, a->r2); 27830843563fSRichard Henderson dest = dest_gpr(ctx, a->t); 27840843563fSRichard Henderson 27850843563fSRichard Henderson fn(dest, r1, r2); 27860843563fSRichard Henderson save_gpr(ctx, a->t, dest); 27870843563fSRichard Henderson 27880843563fSRichard Henderson return nullify_end(ctx); 27890843563fSRichard Henderson } 27900843563fSRichard Henderson 2791151f309bSRichard Henderson static bool do_multimedia_sh(DisasContext *ctx, arg_rri *a, 2792151f309bSRichard Henderson void (*fn)(TCGv_i64, TCGv_i64, int64_t)) 2793151f309bSRichard Henderson { 2794151f309bSRichard Henderson TCGv_i64 r, dest; 2795151f309bSRichard Henderson 2796151f309bSRichard Henderson if (!ctx->is_pa20) { 2797151f309bSRichard Henderson return false; 2798151f309bSRichard Henderson } 2799151f309bSRichard Henderson 2800151f309bSRichard Henderson nullify_over(ctx); 2801151f309bSRichard Henderson 2802151f309bSRichard Henderson r = load_gpr(ctx, a->r); 2803151f309bSRichard Henderson dest = dest_gpr(ctx, a->t); 2804151f309bSRichard Henderson 2805151f309bSRichard Henderson fn(dest, r, a->i); 2806151f309bSRichard Henderson save_gpr(ctx, a->t, dest); 2807151f309bSRichard Henderson 2808151f309bSRichard Henderson return nullify_end(ctx); 2809151f309bSRichard Henderson } 2810151f309bSRichard Henderson 28113bbb8e48SRichard Henderson static bool do_multimedia_shadd(DisasContext *ctx, arg_rrr_sh *a, 28123bbb8e48SRichard Henderson void (*fn)(TCGv_i64, TCGv_i64, 28133bbb8e48SRichard Henderson TCGv_i64, TCGv_i32)) 28143bbb8e48SRichard Henderson { 28153bbb8e48SRichard Henderson TCGv_i64 r1, r2, dest; 28163bbb8e48SRichard Henderson 28173bbb8e48SRichard Henderson if (!ctx->is_pa20) { 28183bbb8e48SRichard Henderson return false; 28193bbb8e48SRichard Henderson } 28203bbb8e48SRichard Henderson 28213bbb8e48SRichard Henderson nullify_over(ctx); 28223bbb8e48SRichard Henderson 28233bbb8e48SRichard Henderson r1 = load_gpr(ctx, a->r1); 28243bbb8e48SRichard Henderson r2 = load_gpr(ctx, a->r2); 28253bbb8e48SRichard Henderson dest = dest_gpr(ctx, a->t); 28263bbb8e48SRichard Henderson 28273bbb8e48SRichard Henderson fn(dest, r1, r2, tcg_constant_i32(a->sh)); 28283bbb8e48SRichard Henderson save_gpr(ctx, a->t, dest); 28293bbb8e48SRichard Henderson 28303bbb8e48SRichard Henderson return nullify_end(ctx); 28313bbb8e48SRichard Henderson } 28323bbb8e48SRichard Henderson 28330843563fSRichard Henderson static bool trans_hadd(DisasContext *ctx, arg_rrr *a) 28340843563fSRichard Henderson { 28350843563fSRichard Henderson return do_multimedia(ctx, a, tcg_gen_vec_add16_i64); 28360843563fSRichard Henderson } 28370843563fSRichard Henderson 28380843563fSRichard Henderson static bool trans_hadd_ss(DisasContext *ctx, arg_rrr *a) 28390843563fSRichard Henderson { 28400843563fSRichard Henderson return do_multimedia(ctx, a, gen_helper_hadd_ss); 28410843563fSRichard Henderson } 28420843563fSRichard Henderson 28430843563fSRichard Henderson static bool trans_hadd_us(DisasContext *ctx, arg_rrr *a) 28440843563fSRichard Henderson { 28450843563fSRichard Henderson return do_multimedia(ctx, a, gen_helper_hadd_us); 28460843563fSRichard Henderson } 28470843563fSRichard Henderson 28481b3cb7c8SRichard Henderson static bool trans_havg(DisasContext *ctx, arg_rrr *a) 28491b3cb7c8SRichard Henderson { 28501b3cb7c8SRichard Henderson return do_multimedia(ctx, a, gen_helper_havg); 28511b3cb7c8SRichard Henderson } 28521b3cb7c8SRichard Henderson 2853151f309bSRichard Henderson static bool trans_hshl(DisasContext *ctx, arg_rri *a) 2854151f309bSRichard Henderson { 2855151f309bSRichard Henderson return do_multimedia_sh(ctx, a, tcg_gen_vec_shl16i_i64); 2856151f309bSRichard Henderson } 2857151f309bSRichard Henderson 2858151f309bSRichard Henderson static bool trans_hshr_s(DisasContext *ctx, arg_rri *a) 2859151f309bSRichard Henderson { 2860151f309bSRichard Henderson return do_multimedia_sh(ctx, a, tcg_gen_vec_sar16i_i64); 2861151f309bSRichard Henderson } 2862151f309bSRichard Henderson 2863151f309bSRichard Henderson static bool trans_hshr_u(DisasContext *ctx, arg_rri *a) 2864151f309bSRichard Henderson { 2865151f309bSRichard Henderson return do_multimedia_sh(ctx, a, tcg_gen_vec_shr16i_i64); 2866151f309bSRichard Henderson } 2867151f309bSRichard Henderson 28683bbb8e48SRichard Henderson static bool trans_hshladd(DisasContext *ctx, arg_rrr_sh *a) 28693bbb8e48SRichard Henderson { 28703bbb8e48SRichard Henderson return do_multimedia_shadd(ctx, a, gen_helper_hshladd); 28713bbb8e48SRichard Henderson } 28723bbb8e48SRichard Henderson 28733bbb8e48SRichard Henderson static bool trans_hshradd(DisasContext *ctx, arg_rrr_sh *a) 28743bbb8e48SRichard Henderson { 28753bbb8e48SRichard Henderson return do_multimedia_shadd(ctx, a, gen_helper_hshradd); 28763bbb8e48SRichard Henderson } 28773bbb8e48SRichard Henderson 287810c9e58dSRichard Henderson static bool trans_hsub(DisasContext *ctx, arg_rrr *a) 287910c9e58dSRichard Henderson { 288010c9e58dSRichard Henderson return do_multimedia(ctx, a, tcg_gen_vec_sub16_i64); 288110c9e58dSRichard Henderson } 288210c9e58dSRichard Henderson 288310c9e58dSRichard Henderson static bool trans_hsub_ss(DisasContext *ctx, arg_rrr *a) 288410c9e58dSRichard Henderson { 288510c9e58dSRichard Henderson return do_multimedia(ctx, a, gen_helper_hsub_ss); 288610c9e58dSRichard Henderson } 288710c9e58dSRichard Henderson 288810c9e58dSRichard Henderson static bool trans_hsub_us(DisasContext *ctx, arg_rrr *a) 288910c9e58dSRichard Henderson { 289010c9e58dSRichard Henderson return do_multimedia(ctx, a, gen_helper_hsub_us); 289110c9e58dSRichard Henderson } 289210c9e58dSRichard Henderson 2893c2a7ee3fSRichard Henderson static void gen_mixh_l(TCGv_i64 dst, TCGv_i64 r1, TCGv_i64 r2) 2894c2a7ee3fSRichard Henderson { 2895c2a7ee3fSRichard Henderson uint64_t mask = 0xffff0000ffff0000ull; 2896c2a7ee3fSRichard Henderson TCGv_i64 tmp = tcg_temp_new_i64(); 2897c2a7ee3fSRichard Henderson 2898c2a7ee3fSRichard Henderson tcg_gen_andi_i64(tmp, r2, mask); 2899c2a7ee3fSRichard Henderson tcg_gen_andi_i64(dst, r1, mask); 2900c2a7ee3fSRichard Henderson tcg_gen_shri_i64(tmp, tmp, 16); 2901c2a7ee3fSRichard Henderson tcg_gen_or_i64(dst, dst, tmp); 2902c2a7ee3fSRichard Henderson } 2903c2a7ee3fSRichard Henderson 2904c2a7ee3fSRichard Henderson static bool trans_mixh_l(DisasContext *ctx, arg_rrr *a) 2905c2a7ee3fSRichard Henderson { 2906c2a7ee3fSRichard Henderson return do_multimedia(ctx, a, gen_mixh_l); 2907c2a7ee3fSRichard Henderson } 2908c2a7ee3fSRichard Henderson 2909c2a7ee3fSRichard Henderson static void gen_mixh_r(TCGv_i64 dst, TCGv_i64 r1, TCGv_i64 r2) 2910c2a7ee3fSRichard Henderson { 2911c2a7ee3fSRichard Henderson uint64_t mask = 0x0000ffff0000ffffull; 2912c2a7ee3fSRichard Henderson TCGv_i64 tmp = tcg_temp_new_i64(); 2913c2a7ee3fSRichard Henderson 2914c2a7ee3fSRichard Henderson tcg_gen_andi_i64(tmp, r1, mask); 2915c2a7ee3fSRichard Henderson tcg_gen_andi_i64(dst, r2, mask); 2916c2a7ee3fSRichard Henderson tcg_gen_shli_i64(tmp, tmp, 16); 2917c2a7ee3fSRichard Henderson tcg_gen_or_i64(dst, dst, tmp); 2918c2a7ee3fSRichard Henderson } 2919c2a7ee3fSRichard Henderson 2920c2a7ee3fSRichard Henderson static bool trans_mixh_r(DisasContext *ctx, arg_rrr *a) 2921c2a7ee3fSRichard Henderson { 2922c2a7ee3fSRichard Henderson return do_multimedia(ctx, a, gen_mixh_r); 2923c2a7ee3fSRichard Henderson } 2924c2a7ee3fSRichard Henderson 2925c2a7ee3fSRichard Henderson static void gen_mixw_l(TCGv_i64 dst, TCGv_i64 r1, TCGv_i64 r2) 2926c2a7ee3fSRichard Henderson { 2927c2a7ee3fSRichard Henderson TCGv_i64 tmp = tcg_temp_new_i64(); 2928c2a7ee3fSRichard Henderson 2929c2a7ee3fSRichard Henderson tcg_gen_shri_i64(tmp, r2, 32); 2930c2a7ee3fSRichard Henderson tcg_gen_deposit_i64(dst, r1, tmp, 0, 32); 2931c2a7ee3fSRichard Henderson } 2932c2a7ee3fSRichard Henderson 2933c2a7ee3fSRichard Henderson static bool trans_mixw_l(DisasContext *ctx, arg_rrr *a) 2934c2a7ee3fSRichard Henderson { 2935c2a7ee3fSRichard Henderson return do_multimedia(ctx, a, gen_mixw_l); 2936c2a7ee3fSRichard Henderson } 2937c2a7ee3fSRichard Henderson 2938c2a7ee3fSRichard Henderson static void gen_mixw_r(TCGv_i64 dst, TCGv_i64 r1, TCGv_i64 r2) 2939c2a7ee3fSRichard Henderson { 2940c2a7ee3fSRichard Henderson tcg_gen_deposit_i64(dst, r2, r1, 32, 32); 2941c2a7ee3fSRichard Henderson } 2942c2a7ee3fSRichard Henderson 2943c2a7ee3fSRichard Henderson static bool trans_mixw_r(DisasContext *ctx, arg_rrr *a) 2944c2a7ee3fSRichard Henderson { 2945c2a7ee3fSRichard Henderson return do_multimedia(ctx, a, gen_mixw_r); 2946c2a7ee3fSRichard Henderson } 2947c2a7ee3fSRichard Henderson 29484e7abdb1SRichard Henderson static bool trans_permh(DisasContext *ctx, arg_permh *a) 29494e7abdb1SRichard Henderson { 29504e7abdb1SRichard Henderson TCGv_i64 r, t0, t1, t2, t3; 29514e7abdb1SRichard Henderson 29524e7abdb1SRichard Henderson if (!ctx->is_pa20) { 29534e7abdb1SRichard Henderson return false; 29544e7abdb1SRichard Henderson } 29554e7abdb1SRichard Henderson 29564e7abdb1SRichard Henderson nullify_over(ctx); 29574e7abdb1SRichard Henderson 29584e7abdb1SRichard Henderson r = load_gpr(ctx, a->r1); 29594e7abdb1SRichard Henderson t0 = tcg_temp_new_i64(); 29604e7abdb1SRichard Henderson t1 = tcg_temp_new_i64(); 29614e7abdb1SRichard Henderson t2 = tcg_temp_new_i64(); 29624e7abdb1SRichard Henderson t3 = tcg_temp_new_i64(); 29634e7abdb1SRichard Henderson 29644e7abdb1SRichard Henderson tcg_gen_extract_i64(t0, r, (3 - a->c0) * 16, 16); 29654e7abdb1SRichard Henderson tcg_gen_extract_i64(t1, r, (3 - a->c1) * 16, 16); 29664e7abdb1SRichard Henderson tcg_gen_extract_i64(t2, r, (3 - a->c2) * 16, 16); 29674e7abdb1SRichard Henderson tcg_gen_extract_i64(t3, r, (3 - a->c3) * 16, 16); 29684e7abdb1SRichard Henderson 29694e7abdb1SRichard Henderson tcg_gen_deposit_i64(t0, t1, t0, 16, 48); 29704e7abdb1SRichard Henderson tcg_gen_deposit_i64(t2, t3, t2, 16, 48); 29714e7abdb1SRichard Henderson tcg_gen_deposit_i64(t0, t2, t0, 32, 32); 29724e7abdb1SRichard Henderson 29734e7abdb1SRichard Henderson save_gpr(ctx, a->t, t0); 29744e7abdb1SRichard Henderson return nullify_end(ctx); 29754e7abdb1SRichard Henderson } 29764e7abdb1SRichard Henderson 29771cd012a5SRichard Henderson static bool trans_ld(DisasContext *ctx, arg_ldst *a) 297896d6407fSRichard Henderson { 2979*b5caa17cSRichard Henderson if (ctx->is_pa20) { 2980*b5caa17cSRichard Henderson /* 2981*b5caa17cSRichard Henderson * With pa20, LDB, LDH, LDW, LDD to %g0 are prefetches. 2982*b5caa17cSRichard Henderson * Any base modification still occurs. 2983*b5caa17cSRichard Henderson */ 2984*b5caa17cSRichard Henderson if (a->t == 0) { 2985*b5caa17cSRichard Henderson return trans_nop_addrx(ctx, a); 2986*b5caa17cSRichard Henderson } 2987*b5caa17cSRichard Henderson } else if (a->size > MO_32) { 29880786a3b6SHelge Deller return gen_illegal(ctx); 2989c53e401eSRichard Henderson } 29901cd012a5SRichard Henderson return do_load(ctx, a->t, a->b, a->x, a->scale ? a->size : 0, 29911cd012a5SRichard Henderson a->disp, a->sp, a->m, a->size | MO_TE); 299296d6407fSRichard Henderson } 299396d6407fSRichard Henderson 29941cd012a5SRichard Henderson static bool trans_st(DisasContext *ctx, arg_ldst *a) 299596d6407fSRichard Henderson { 29961cd012a5SRichard Henderson assert(a->x == 0 && a->scale == 0); 2997c53e401eSRichard Henderson if (!ctx->is_pa20 && a->size > MO_32) { 29980786a3b6SHelge Deller return gen_illegal(ctx); 299996d6407fSRichard Henderson } 3000c53e401eSRichard Henderson return do_store(ctx, a->t, a->b, a->disp, a->sp, a->m, a->size | MO_TE); 30010786a3b6SHelge Deller } 300296d6407fSRichard Henderson 30031cd012a5SRichard Henderson static bool trans_ldc(DisasContext *ctx, arg_ldst *a) 300496d6407fSRichard Henderson { 3005b1af755cSRichard Henderson MemOp mop = MO_TE | MO_ALIGN | a->size; 3006a4db4a78SRichard Henderson TCGv_i64 dest, ofs; 30076fd0c7bcSRichard Henderson TCGv_i64 addr; 300896d6407fSRichard Henderson 3009c53e401eSRichard Henderson if (!ctx->is_pa20 && a->size > MO_32) { 301051416c4eSRichard Henderson return gen_illegal(ctx); 301151416c4eSRichard Henderson } 301251416c4eSRichard Henderson 301396d6407fSRichard Henderson nullify_over(ctx); 301496d6407fSRichard Henderson 30151cd012a5SRichard Henderson if (a->m) { 301686f8d05fSRichard Henderson /* Base register modification. Make sure if RT == RB, 301786f8d05fSRichard Henderson we see the result of the load. */ 3018aac0f603SRichard Henderson dest = tcg_temp_new_i64(); 301996d6407fSRichard Henderson } else { 30201cd012a5SRichard Henderson dest = dest_gpr(ctx, a->t); 302196d6407fSRichard Henderson } 302296d6407fSRichard Henderson 30231cd012a5SRichard Henderson form_gva(ctx, &addr, &ofs, a->b, a->x, a->scale ? a->size : 0, 30241cd012a5SRichard Henderson a->disp, a->sp, a->m, ctx->mmu_idx == MMU_PHYS_IDX); 3025b1af755cSRichard Henderson 3026b1af755cSRichard Henderson /* 3027b1af755cSRichard Henderson * For hppa1.1, LDCW is undefined unless aligned mod 16. 3028b1af755cSRichard Henderson * However actual hardware succeeds with aligned mod 4. 3029b1af755cSRichard Henderson * Detect this case and log a GUEST_ERROR. 3030b1af755cSRichard Henderson * 3031b1af755cSRichard Henderson * TODO: HPPA64 relaxes the over-alignment requirement 3032b1af755cSRichard Henderson * with the ,co completer. 3033b1af755cSRichard Henderson */ 3034b1af755cSRichard Henderson gen_helper_ldc_check(addr); 3035b1af755cSRichard Henderson 3036a4db4a78SRichard Henderson tcg_gen_atomic_xchg_i64(dest, addr, ctx->zero, ctx->mmu_idx, mop); 3037b1af755cSRichard Henderson 30381cd012a5SRichard Henderson if (a->m) { 30391cd012a5SRichard Henderson save_gpr(ctx, a->b, ofs); 304096d6407fSRichard Henderson } 30411cd012a5SRichard Henderson save_gpr(ctx, a->t, dest); 304296d6407fSRichard Henderson 304331234768SRichard Henderson return nullify_end(ctx); 304496d6407fSRichard Henderson } 304596d6407fSRichard Henderson 30461cd012a5SRichard Henderson static bool trans_stby(DisasContext *ctx, arg_stby *a) 304796d6407fSRichard Henderson { 30486fd0c7bcSRichard Henderson TCGv_i64 ofs, val; 30496fd0c7bcSRichard Henderson TCGv_i64 addr; 305096d6407fSRichard Henderson 305196d6407fSRichard Henderson nullify_over(ctx); 305296d6407fSRichard Henderson 30531cd012a5SRichard Henderson form_gva(ctx, &addr, &ofs, a->b, 0, 0, a->disp, a->sp, a->m, 305486f8d05fSRichard Henderson ctx->mmu_idx == MMU_PHYS_IDX); 30551cd012a5SRichard Henderson val = load_gpr(ctx, a->r); 30561cd012a5SRichard Henderson if (a->a) { 3057f9f46db4SEmilio G. Cota if (tb_cflags(ctx->base.tb) & CF_PARALLEL) { 3058ad75a51eSRichard Henderson gen_helper_stby_e_parallel(tcg_env, addr, val); 3059f9f46db4SEmilio G. Cota } else { 3060ad75a51eSRichard Henderson gen_helper_stby_e(tcg_env, addr, val); 3061f9f46db4SEmilio G. Cota } 3062f9f46db4SEmilio G. Cota } else { 3063f9f46db4SEmilio G. Cota if (tb_cflags(ctx->base.tb) & CF_PARALLEL) { 3064ad75a51eSRichard Henderson gen_helper_stby_b_parallel(tcg_env, addr, val); 306596d6407fSRichard Henderson } else { 3066ad75a51eSRichard Henderson gen_helper_stby_b(tcg_env, addr, val); 306796d6407fSRichard Henderson } 3068f9f46db4SEmilio G. Cota } 30691cd012a5SRichard Henderson if (a->m) { 30706fd0c7bcSRichard Henderson tcg_gen_andi_i64(ofs, ofs, ~3); 30711cd012a5SRichard Henderson save_gpr(ctx, a->b, ofs); 307296d6407fSRichard Henderson } 307396d6407fSRichard Henderson 307431234768SRichard Henderson return nullify_end(ctx); 307596d6407fSRichard Henderson } 307696d6407fSRichard Henderson 307725460fc5SRichard Henderson static bool trans_stdby(DisasContext *ctx, arg_stby *a) 307825460fc5SRichard Henderson { 30796fd0c7bcSRichard Henderson TCGv_i64 ofs, val; 30806fd0c7bcSRichard Henderson TCGv_i64 addr; 308125460fc5SRichard Henderson 308225460fc5SRichard Henderson if (!ctx->is_pa20) { 308325460fc5SRichard Henderson return false; 308425460fc5SRichard Henderson } 308525460fc5SRichard Henderson nullify_over(ctx); 308625460fc5SRichard Henderson 308725460fc5SRichard Henderson form_gva(ctx, &addr, &ofs, a->b, 0, 0, a->disp, a->sp, a->m, 308825460fc5SRichard Henderson ctx->mmu_idx == MMU_PHYS_IDX); 308925460fc5SRichard Henderson val = load_gpr(ctx, a->r); 309025460fc5SRichard Henderson if (a->a) { 309125460fc5SRichard Henderson if (tb_cflags(ctx->base.tb) & CF_PARALLEL) { 309225460fc5SRichard Henderson gen_helper_stdby_e_parallel(tcg_env, addr, val); 309325460fc5SRichard Henderson } else { 309425460fc5SRichard Henderson gen_helper_stdby_e(tcg_env, addr, val); 309525460fc5SRichard Henderson } 309625460fc5SRichard Henderson } else { 309725460fc5SRichard Henderson if (tb_cflags(ctx->base.tb) & CF_PARALLEL) { 309825460fc5SRichard Henderson gen_helper_stdby_b_parallel(tcg_env, addr, val); 309925460fc5SRichard Henderson } else { 310025460fc5SRichard Henderson gen_helper_stdby_b(tcg_env, addr, val); 310125460fc5SRichard Henderson } 310225460fc5SRichard Henderson } 310325460fc5SRichard Henderson if (a->m) { 31046fd0c7bcSRichard Henderson tcg_gen_andi_i64(ofs, ofs, ~7); 310525460fc5SRichard Henderson save_gpr(ctx, a->b, ofs); 310625460fc5SRichard Henderson } 310725460fc5SRichard Henderson 310825460fc5SRichard Henderson return nullify_end(ctx); 310925460fc5SRichard Henderson } 311025460fc5SRichard Henderson 31111cd012a5SRichard Henderson static bool trans_lda(DisasContext *ctx, arg_ldst *a) 3112d0a851ccSRichard Henderson { 3113d0a851ccSRichard Henderson int hold_mmu_idx = ctx->mmu_idx; 3114d0a851ccSRichard Henderson 3115d0a851ccSRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 3116d0a851ccSRichard Henderson ctx->mmu_idx = MMU_PHYS_IDX; 31171cd012a5SRichard Henderson trans_ld(ctx, a); 3118d0a851ccSRichard Henderson ctx->mmu_idx = hold_mmu_idx; 311931234768SRichard Henderson return true; 3120d0a851ccSRichard Henderson } 3121d0a851ccSRichard Henderson 31221cd012a5SRichard Henderson static bool trans_sta(DisasContext *ctx, arg_ldst *a) 3123d0a851ccSRichard Henderson { 3124d0a851ccSRichard Henderson int hold_mmu_idx = ctx->mmu_idx; 3125d0a851ccSRichard Henderson 3126d0a851ccSRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 3127d0a851ccSRichard Henderson ctx->mmu_idx = MMU_PHYS_IDX; 31281cd012a5SRichard Henderson trans_st(ctx, a); 3129d0a851ccSRichard Henderson ctx->mmu_idx = hold_mmu_idx; 313031234768SRichard Henderson return true; 3131d0a851ccSRichard Henderson } 313295412a61SRichard Henderson 31330588e061SRichard Henderson static bool trans_ldil(DisasContext *ctx, arg_ldil *a) 3134b2167459SRichard Henderson { 31356fd0c7bcSRichard Henderson TCGv_i64 tcg_rt = dest_gpr(ctx, a->t); 3136b2167459SRichard Henderson 31376fd0c7bcSRichard Henderson tcg_gen_movi_i64(tcg_rt, a->i); 31380588e061SRichard Henderson save_gpr(ctx, a->t, tcg_rt); 3139b2167459SRichard Henderson cond_free(&ctx->null_cond); 314031234768SRichard Henderson return true; 3141b2167459SRichard Henderson } 3142b2167459SRichard Henderson 31430588e061SRichard Henderson static bool trans_addil(DisasContext *ctx, arg_addil *a) 3144b2167459SRichard Henderson { 31456fd0c7bcSRichard Henderson TCGv_i64 tcg_rt = load_gpr(ctx, a->r); 31466fd0c7bcSRichard Henderson TCGv_i64 tcg_r1 = dest_gpr(ctx, 1); 3147b2167459SRichard Henderson 31486fd0c7bcSRichard Henderson tcg_gen_addi_i64(tcg_r1, tcg_rt, a->i); 3149b2167459SRichard Henderson save_gpr(ctx, 1, tcg_r1); 3150b2167459SRichard Henderson cond_free(&ctx->null_cond); 315131234768SRichard Henderson return true; 3152b2167459SRichard Henderson } 3153b2167459SRichard Henderson 31540588e061SRichard Henderson static bool trans_ldo(DisasContext *ctx, arg_ldo *a) 3155b2167459SRichard Henderson { 31566fd0c7bcSRichard Henderson TCGv_i64 tcg_rt = dest_gpr(ctx, a->t); 3157b2167459SRichard Henderson 3158b2167459SRichard Henderson /* Special case rb == 0, for the LDI pseudo-op. 3159d265360fSRichard Henderson The COPY pseudo-op is handled for free within tcg_gen_addi_i64. */ 31600588e061SRichard Henderson if (a->b == 0) { 31616fd0c7bcSRichard Henderson tcg_gen_movi_i64(tcg_rt, a->i); 3162b2167459SRichard Henderson } else { 31636fd0c7bcSRichard Henderson tcg_gen_addi_i64(tcg_rt, cpu_gr[a->b], a->i); 3164b2167459SRichard Henderson } 31650588e061SRichard Henderson save_gpr(ctx, a->t, tcg_rt); 3166b2167459SRichard Henderson cond_free(&ctx->null_cond); 316731234768SRichard Henderson return true; 3168b2167459SRichard Henderson } 3169b2167459SRichard Henderson 31706fd0c7bcSRichard Henderson static bool do_cmpb(DisasContext *ctx, unsigned r, TCGv_i64 in1, 3171e9efd4bcSRichard Henderson unsigned c, unsigned f, bool d, unsigned n, int disp) 317298cd9ca7SRichard Henderson { 31736fd0c7bcSRichard Henderson TCGv_i64 dest, in2, sv; 317498cd9ca7SRichard Henderson DisasCond cond; 317598cd9ca7SRichard Henderson 317698cd9ca7SRichard Henderson in2 = load_gpr(ctx, r); 3177aac0f603SRichard Henderson dest = tcg_temp_new_i64(); 317898cd9ca7SRichard Henderson 31796fd0c7bcSRichard Henderson tcg_gen_sub_i64(dest, in1, in2); 318098cd9ca7SRichard Henderson 3181f764718dSRichard Henderson sv = NULL; 3182b47a4a02SSven Schnelle if (cond_need_sv(c)) { 318398cd9ca7SRichard Henderson sv = do_sub_sv(ctx, dest, in1, in2); 318498cd9ca7SRichard Henderson } 318598cd9ca7SRichard Henderson 31864fe9533aSRichard Henderson cond = do_sub_cond(ctx, c * 2 + f, d, dest, in1, in2, sv); 318701afb7beSRichard Henderson return do_cbranch(ctx, disp, n, &cond); 318898cd9ca7SRichard Henderson } 318998cd9ca7SRichard Henderson 319001afb7beSRichard Henderson static bool trans_cmpb(DisasContext *ctx, arg_cmpb *a) 319198cd9ca7SRichard Henderson { 3192e9efd4bcSRichard Henderson if (!ctx->is_pa20 && a->d) { 3193e9efd4bcSRichard Henderson return false; 3194e9efd4bcSRichard Henderson } 319501afb7beSRichard Henderson nullify_over(ctx); 3196e9efd4bcSRichard Henderson return do_cmpb(ctx, a->r2, load_gpr(ctx, a->r1), 3197e9efd4bcSRichard Henderson a->c, a->f, a->d, a->n, a->disp); 319801afb7beSRichard Henderson } 319901afb7beSRichard Henderson 320001afb7beSRichard Henderson static bool trans_cmpbi(DisasContext *ctx, arg_cmpbi *a) 320101afb7beSRichard Henderson { 3202c65c3ee1SRichard Henderson if (!ctx->is_pa20 && a->d) { 3203c65c3ee1SRichard Henderson return false; 3204c65c3ee1SRichard Henderson } 320501afb7beSRichard Henderson nullify_over(ctx); 32066fd0c7bcSRichard Henderson return do_cmpb(ctx, a->r, tcg_constant_i64(a->i), 3207c65c3ee1SRichard Henderson a->c, a->f, a->d, a->n, a->disp); 320801afb7beSRichard Henderson } 320901afb7beSRichard Henderson 32106fd0c7bcSRichard Henderson static bool do_addb(DisasContext *ctx, unsigned r, TCGv_i64 in1, 321101afb7beSRichard Henderson unsigned c, unsigned f, unsigned n, int disp) 321201afb7beSRichard Henderson { 32136fd0c7bcSRichard Henderson TCGv_i64 dest, in2, sv, cb_cond; 321498cd9ca7SRichard Henderson DisasCond cond; 3215bdcccc17SRichard Henderson bool d = false; 321698cd9ca7SRichard Henderson 3217f25d3160SRichard Henderson /* 3218f25d3160SRichard Henderson * For hppa64, the ADDB conditions change with PSW.W, 3219f25d3160SRichard Henderson * dropping ZNV, SV, OD in favor of double-word EQ, LT, LE. 3220f25d3160SRichard Henderson */ 3221f25d3160SRichard Henderson if (ctx->tb_flags & PSW_W) { 3222f25d3160SRichard Henderson d = c >= 5; 3223f25d3160SRichard Henderson if (d) { 3224f25d3160SRichard Henderson c &= 3; 3225f25d3160SRichard Henderson } 3226f25d3160SRichard Henderson } 3227f25d3160SRichard Henderson 322898cd9ca7SRichard Henderson in2 = load_gpr(ctx, r); 3229aac0f603SRichard Henderson dest = tcg_temp_new_i64(); 3230f764718dSRichard Henderson sv = NULL; 3231bdcccc17SRichard Henderson cb_cond = NULL; 323298cd9ca7SRichard Henderson 3233b47a4a02SSven Schnelle if (cond_need_cb(c)) { 3234aac0f603SRichard Henderson TCGv_i64 cb = tcg_temp_new_i64(); 3235aac0f603SRichard Henderson TCGv_i64 cb_msb = tcg_temp_new_i64(); 3236bdcccc17SRichard Henderson 32376fd0c7bcSRichard Henderson tcg_gen_movi_i64(cb_msb, 0); 32386fd0c7bcSRichard Henderson tcg_gen_add2_i64(dest, cb_msb, in1, cb_msb, in2, cb_msb); 32396fd0c7bcSRichard Henderson tcg_gen_xor_i64(cb, in1, in2); 32406fd0c7bcSRichard Henderson tcg_gen_xor_i64(cb, cb, dest); 3241bdcccc17SRichard Henderson cb_cond = get_carry(ctx, d, cb, cb_msb); 3242b47a4a02SSven Schnelle } else { 32436fd0c7bcSRichard Henderson tcg_gen_add_i64(dest, in1, in2); 3244b47a4a02SSven Schnelle } 3245b47a4a02SSven Schnelle if (cond_need_sv(c)) { 324698cd9ca7SRichard Henderson sv = do_add_sv(ctx, dest, in1, in2); 324798cd9ca7SRichard Henderson } 324898cd9ca7SRichard Henderson 3249a751eb31SRichard Henderson cond = do_cond(ctx, c * 2 + f, d, dest, cb_cond, sv); 325043675d20SSven Schnelle save_gpr(ctx, r, dest); 325101afb7beSRichard Henderson return do_cbranch(ctx, disp, n, &cond); 325298cd9ca7SRichard Henderson } 325398cd9ca7SRichard Henderson 325401afb7beSRichard Henderson static bool trans_addb(DisasContext *ctx, arg_addb *a) 325598cd9ca7SRichard Henderson { 325601afb7beSRichard Henderson nullify_over(ctx); 325701afb7beSRichard Henderson return do_addb(ctx, a->r2, load_gpr(ctx, a->r1), a->c, a->f, a->n, a->disp); 325801afb7beSRichard Henderson } 325901afb7beSRichard Henderson 326001afb7beSRichard Henderson static bool trans_addbi(DisasContext *ctx, arg_addbi *a) 326101afb7beSRichard Henderson { 326201afb7beSRichard Henderson nullify_over(ctx); 32636fd0c7bcSRichard Henderson return do_addb(ctx, a->r, tcg_constant_i64(a->i), a->c, a->f, a->n, a->disp); 326401afb7beSRichard Henderson } 326501afb7beSRichard Henderson 326601afb7beSRichard Henderson static bool trans_bb_sar(DisasContext *ctx, arg_bb_sar *a) 326701afb7beSRichard Henderson { 32686fd0c7bcSRichard Henderson TCGv_i64 tmp, tcg_r; 326998cd9ca7SRichard Henderson DisasCond cond; 327098cd9ca7SRichard Henderson 327198cd9ca7SRichard Henderson nullify_over(ctx); 327298cd9ca7SRichard Henderson 3273aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 327401afb7beSRichard Henderson tcg_r = load_gpr(ctx, a->r); 327584e224d4SRichard Henderson if (cond_need_ext(ctx, a->d)) { 32761e9ab9fbSRichard Henderson /* Force shift into [32,63] */ 32776fd0c7bcSRichard Henderson tcg_gen_ori_i64(tmp, cpu_sar, 32); 32786fd0c7bcSRichard Henderson tcg_gen_shl_i64(tmp, tcg_r, tmp); 32791e9ab9fbSRichard Henderson } else { 32806fd0c7bcSRichard Henderson tcg_gen_shl_i64(tmp, tcg_r, cpu_sar); 32811e9ab9fbSRichard Henderson } 328298cd9ca7SRichard Henderson 32831e9ab9fbSRichard Henderson cond = cond_make_0_tmp(a->c ? TCG_COND_GE : TCG_COND_LT, tmp); 328401afb7beSRichard Henderson return do_cbranch(ctx, a->disp, a->n, &cond); 328598cd9ca7SRichard Henderson } 328698cd9ca7SRichard Henderson 328701afb7beSRichard Henderson static bool trans_bb_imm(DisasContext *ctx, arg_bb_imm *a) 328898cd9ca7SRichard Henderson { 32896fd0c7bcSRichard Henderson TCGv_i64 tmp, tcg_r; 329001afb7beSRichard Henderson DisasCond cond; 32911e9ab9fbSRichard Henderson int p; 329201afb7beSRichard Henderson 329301afb7beSRichard Henderson nullify_over(ctx); 329401afb7beSRichard Henderson 3295aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 329601afb7beSRichard Henderson tcg_r = load_gpr(ctx, a->r); 329784e224d4SRichard Henderson p = a->p | (cond_need_ext(ctx, a->d) ? 32 : 0); 32986fd0c7bcSRichard Henderson tcg_gen_shli_i64(tmp, tcg_r, p); 329901afb7beSRichard Henderson 330001afb7beSRichard Henderson cond = cond_make_0(a->c ? TCG_COND_GE : TCG_COND_LT, tmp); 330101afb7beSRichard Henderson return do_cbranch(ctx, a->disp, a->n, &cond); 330201afb7beSRichard Henderson } 330301afb7beSRichard Henderson 330401afb7beSRichard Henderson static bool trans_movb(DisasContext *ctx, arg_movb *a) 330501afb7beSRichard Henderson { 33066fd0c7bcSRichard Henderson TCGv_i64 dest; 330798cd9ca7SRichard Henderson DisasCond cond; 330898cd9ca7SRichard Henderson 330998cd9ca7SRichard Henderson nullify_over(ctx); 331098cd9ca7SRichard Henderson 331101afb7beSRichard Henderson dest = dest_gpr(ctx, a->r2); 331201afb7beSRichard Henderson if (a->r1 == 0) { 33136fd0c7bcSRichard Henderson tcg_gen_movi_i64(dest, 0); 331498cd9ca7SRichard Henderson } else { 33156fd0c7bcSRichard Henderson tcg_gen_mov_i64(dest, cpu_gr[a->r1]); 331698cd9ca7SRichard Henderson } 331798cd9ca7SRichard Henderson 33184fa52edfSRichard Henderson /* All MOVB conditions are 32-bit. */ 33194fa52edfSRichard Henderson cond = do_sed_cond(ctx, a->c, false, dest); 332001afb7beSRichard Henderson return do_cbranch(ctx, a->disp, a->n, &cond); 332101afb7beSRichard Henderson } 332201afb7beSRichard Henderson 332301afb7beSRichard Henderson static bool trans_movbi(DisasContext *ctx, arg_movbi *a) 332401afb7beSRichard Henderson { 33256fd0c7bcSRichard Henderson TCGv_i64 dest; 332601afb7beSRichard Henderson DisasCond cond; 332701afb7beSRichard Henderson 332801afb7beSRichard Henderson nullify_over(ctx); 332901afb7beSRichard Henderson 333001afb7beSRichard Henderson dest = dest_gpr(ctx, a->r); 33316fd0c7bcSRichard Henderson tcg_gen_movi_i64(dest, a->i); 333201afb7beSRichard Henderson 33334fa52edfSRichard Henderson /* All MOVBI conditions are 32-bit. */ 33344fa52edfSRichard Henderson cond = do_sed_cond(ctx, a->c, false, dest); 333501afb7beSRichard Henderson return do_cbranch(ctx, a->disp, a->n, &cond); 333698cd9ca7SRichard Henderson } 333798cd9ca7SRichard Henderson 3338f7b775a9SRichard Henderson static bool trans_shrp_sar(DisasContext *ctx, arg_shrp_sar *a) 33390b1347d2SRichard Henderson { 33406fd0c7bcSRichard Henderson TCGv_i64 dest, src2; 33410b1347d2SRichard Henderson 3342f7b775a9SRichard Henderson if (!ctx->is_pa20 && a->d) { 3343f7b775a9SRichard Henderson return false; 3344f7b775a9SRichard Henderson } 334530878590SRichard Henderson if (a->c) { 33460b1347d2SRichard Henderson nullify_over(ctx); 33470b1347d2SRichard Henderson } 33480b1347d2SRichard Henderson 334930878590SRichard Henderson dest = dest_gpr(ctx, a->t); 3350f7b775a9SRichard Henderson src2 = load_gpr(ctx, a->r2); 335130878590SRichard Henderson if (a->r1 == 0) { 3352f7b775a9SRichard Henderson if (a->d) { 33536fd0c7bcSRichard Henderson tcg_gen_shr_i64(dest, src2, cpu_sar); 3354f7b775a9SRichard Henderson } else { 3355aac0f603SRichard Henderson TCGv_i64 tmp = tcg_temp_new_i64(); 3356f7b775a9SRichard Henderson 33576fd0c7bcSRichard Henderson tcg_gen_ext32u_i64(dest, src2); 33586fd0c7bcSRichard Henderson tcg_gen_andi_i64(tmp, cpu_sar, 31); 33596fd0c7bcSRichard Henderson tcg_gen_shr_i64(dest, dest, tmp); 3360f7b775a9SRichard Henderson } 336130878590SRichard Henderson } else if (a->r1 == a->r2) { 3362f7b775a9SRichard Henderson if (a->d) { 33636fd0c7bcSRichard Henderson tcg_gen_rotr_i64(dest, src2, cpu_sar); 3364f7b775a9SRichard Henderson } else { 33650b1347d2SRichard Henderson TCGv_i32 t32 = tcg_temp_new_i32(); 3366e1d635e8SRichard Henderson TCGv_i32 s32 = tcg_temp_new_i32(); 3367e1d635e8SRichard Henderson 33686fd0c7bcSRichard Henderson tcg_gen_extrl_i64_i32(t32, src2); 33696fd0c7bcSRichard Henderson tcg_gen_extrl_i64_i32(s32, cpu_sar); 3370f7b775a9SRichard Henderson tcg_gen_andi_i32(s32, s32, 31); 3371e1d635e8SRichard Henderson tcg_gen_rotr_i32(t32, t32, s32); 33726fd0c7bcSRichard Henderson tcg_gen_extu_i32_i64(dest, t32); 3373f7b775a9SRichard Henderson } 3374f7b775a9SRichard Henderson } else { 33756fd0c7bcSRichard Henderson TCGv_i64 src1 = load_gpr(ctx, a->r1); 3376f7b775a9SRichard Henderson 3377f7b775a9SRichard Henderson if (a->d) { 3378aac0f603SRichard Henderson TCGv_i64 t = tcg_temp_new_i64(); 3379aac0f603SRichard Henderson TCGv_i64 n = tcg_temp_new_i64(); 3380f7b775a9SRichard Henderson 33816fd0c7bcSRichard Henderson tcg_gen_xori_i64(n, cpu_sar, 63); 33826fd0c7bcSRichard Henderson tcg_gen_shl_i64(t, src2, n); 33836fd0c7bcSRichard Henderson tcg_gen_shli_i64(t, t, 1); 33846fd0c7bcSRichard Henderson tcg_gen_shr_i64(dest, src1, cpu_sar); 33856fd0c7bcSRichard Henderson tcg_gen_or_i64(dest, dest, t); 33860b1347d2SRichard Henderson } else { 33870b1347d2SRichard Henderson TCGv_i64 t = tcg_temp_new_i64(); 33880b1347d2SRichard Henderson TCGv_i64 s = tcg_temp_new_i64(); 33890b1347d2SRichard Henderson 33906fd0c7bcSRichard Henderson tcg_gen_concat32_i64(t, src2, src1); 3391967662cdSRichard Henderson tcg_gen_andi_i64(s, cpu_sar, 31); 3392967662cdSRichard Henderson tcg_gen_shr_i64(dest, t, s); 33930b1347d2SRichard Henderson } 3394f7b775a9SRichard Henderson } 339530878590SRichard Henderson save_gpr(ctx, a->t, dest); 33960b1347d2SRichard Henderson 33970b1347d2SRichard Henderson /* Install the new nullification. */ 33980b1347d2SRichard Henderson cond_free(&ctx->null_cond); 339930878590SRichard Henderson if (a->c) { 34004fa52edfSRichard Henderson ctx->null_cond = do_sed_cond(ctx, a->c, false, dest); 34010b1347d2SRichard Henderson } 340231234768SRichard Henderson return nullify_end(ctx); 34030b1347d2SRichard Henderson } 34040b1347d2SRichard Henderson 3405f7b775a9SRichard Henderson static bool trans_shrp_imm(DisasContext *ctx, arg_shrp_imm *a) 34060b1347d2SRichard Henderson { 3407f7b775a9SRichard Henderson unsigned width, sa; 34086fd0c7bcSRichard Henderson TCGv_i64 dest, t2; 34090b1347d2SRichard Henderson 3410f7b775a9SRichard Henderson if (!ctx->is_pa20 && a->d) { 3411f7b775a9SRichard Henderson return false; 3412f7b775a9SRichard Henderson } 341330878590SRichard Henderson if (a->c) { 34140b1347d2SRichard Henderson nullify_over(ctx); 34150b1347d2SRichard Henderson } 34160b1347d2SRichard Henderson 3417f7b775a9SRichard Henderson width = a->d ? 64 : 32; 3418f7b775a9SRichard Henderson sa = width - 1 - a->cpos; 3419f7b775a9SRichard Henderson 342030878590SRichard Henderson dest = dest_gpr(ctx, a->t); 342130878590SRichard Henderson t2 = load_gpr(ctx, a->r2); 342205bfd4dbSRichard Henderson if (a->r1 == 0) { 34236fd0c7bcSRichard Henderson tcg_gen_extract_i64(dest, t2, sa, width - sa); 3424c53e401eSRichard Henderson } else if (width == TARGET_LONG_BITS) { 34256fd0c7bcSRichard Henderson tcg_gen_extract2_i64(dest, t2, cpu_gr[a->r1], sa); 3426f7b775a9SRichard Henderson } else { 3427f7b775a9SRichard Henderson assert(!a->d); 3428f7b775a9SRichard Henderson if (a->r1 == a->r2) { 34290b1347d2SRichard Henderson TCGv_i32 t32 = tcg_temp_new_i32(); 34306fd0c7bcSRichard Henderson tcg_gen_extrl_i64_i32(t32, t2); 34310b1347d2SRichard Henderson tcg_gen_rotri_i32(t32, t32, sa); 34326fd0c7bcSRichard Henderson tcg_gen_extu_i32_i64(dest, t32); 34330b1347d2SRichard Henderson } else { 3434967662cdSRichard Henderson tcg_gen_concat32_i64(dest, t2, cpu_gr[a->r1]); 3435967662cdSRichard Henderson tcg_gen_extract_i64(dest, dest, sa, 32); 34360b1347d2SRichard Henderson } 3437f7b775a9SRichard Henderson } 343830878590SRichard Henderson save_gpr(ctx, a->t, dest); 34390b1347d2SRichard Henderson 34400b1347d2SRichard Henderson /* Install the new nullification. */ 34410b1347d2SRichard Henderson cond_free(&ctx->null_cond); 344230878590SRichard Henderson if (a->c) { 34434fa52edfSRichard Henderson ctx->null_cond = do_sed_cond(ctx, a->c, false, dest); 34440b1347d2SRichard Henderson } 344531234768SRichard Henderson return nullify_end(ctx); 34460b1347d2SRichard Henderson } 34470b1347d2SRichard Henderson 3448bd792da3SRichard Henderson static bool trans_extr_sar(DisasContext *ctx, arg_extr_sar *a) 34490b1347d2SRichard Henderson { 3450bd792da3SRichard Henderson unsigned widthm1 = a->d ? 63 : 31; 34516fd0c7bcSRichard Henderson TCGv_i64 dest, src, tmp; 34520b1347d2SRichard Henderson 3453bd792da3SRichard Henderson if (!ctx->is_pa20 && a->d) { 3454bd792da3SRichard Henderson return false; 3455bd792da3SRichard Henderson } 345630878590SRichard Henderson if (a->c) { 34570b1347d2SRichard Henderson nullify_over(ctx); 34580b1347d2SRichard Henderson } 34590b1347d2SRichard Henderson 346030878590SRichard Henderson dest = dest_gpr(ctx, a->t); 346130878590SRichard Henderson src = load_gpr(ctx, a->r); 3462aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 34630b1347d2SRichard Henderson 34640b1347d2SRichard Henderson /* Recall that SAR is using big-endian bit numbering. */ 34656fd0c7bcSRichard Henderson tcg_gen_andi_i64(tmp, cpu_sar, widthm1); 34666fd0c7bcSRichard Henderson tcg_gen_xori_i64(tmp, tmp, widthm1); 3467d781cb77SRichard Henderson 346830878590SRichard Henderson if (a->se) { 3469bd792da3SRichard Henderson if (!a->d) { 34706fd0c7bcSRichard Henderson tcg_gen_ext32s_i64(dest, src); 3471bd792da3SRichard Henderson src = dest; 3472bd792da3SRichard Henderson } 34736fd0c7bcSRichard Henderson tcg_gen_sar_i64(dest, src, tmp); 34746fd0c7bcSRichard Henderson tcg_gen_sextract_i64(dest, dest, 0, a->len); 34750b1347d2SRichard Henderson } else { 3476bd792da3SRichard Henderson if (!a->d) { 34776fd0c7bcSRichard Henderson tcg_gen_ext32u_i64(dest, src); 3478bd792da3SRichard Henderson src = dest; 3479bd792da3SRichard Henderson } 34806fd0c7bcSRichard Henderson tcg_gen_shr_i64(dest, src, tmp); 34816fd0c7bcSRichard Henderson tcg_gen_extract_i64(dest, dest, 0, a->len); 34820b1347d2SRichard Henderson } 348330878590SRichard Henderson save_gpr(ctx, a->t, dest); 34840b1347d2SRichard Henderson 34850b1347d2SRichard Henderson /* Install the new nullification. */ 34860b1347d2SRichard Henderson cond_free(&ctx->null_cond); 348730878590SRichard Henderson if (a->c) { 3488bd792da3SRichard Henderson ctx->null_cond = do_sed_cond(ctx, a->c, a->d, dest); 34890b1347d2SRichard Henderson } 349031234768SRichard Henderson return nullify_end(ctx); 34910b1347d2SRichard Henderson } 34920b1347d2SRichard Henderson 3493bd792da3SRichard Henderson static bool trans_extr_imm(DisasContext *ctx, arg_extr_imm *a) 34940b1347d2SRichard Henderson { 3495bd792da3SRichard Henderson unsigned len, cpos, width; 34966fd0c7bcSRichard Henderson TCGv_i64 dest, src; 34970b1347d2SRichard Henderson 3498bd792da3SRichard Henderson if (!ctx->is_pa20 && a->d) { 3499bd792da3SRichard Henderson return false; 3500bd792da3SRichard Henderson } 350130878590SRichard Henderson if (a->c) { 35020b1347d2SRichard Henderson nullify_over(ctx); 35030b1347d2SRichard Henderson } 35040b1347d2SRichard Henderson 3505bd792da3SRichard Henderson len = a->len; 3506bd792da3SRichard Henderson width = a->d ? 64 : 32; 3507bd792da3SRichard Henderson cpos = width - 1 - a->pos; 3508bd792da3SRichard Henderson if (cpos + len > width) { 3509bd792da3SRichard Henderson len = width - cpos; 3510bd792da3SRichard Henderson } 3511bd792da3SRichard Henderson 351230878590SRichard Henderson dest = dest_gpr(ctx, a->t); 351330878590SRichard Henderson src = load_gpr(ctx, a->r); 351430878590SRichard Henderson if (a->se) { 35156fd0c7bcSRichard Henderson tcg_gen_sextract_i64(dest, src, cpos, len); 35160b1347d2SRichard Henderson } else { 35176fd0c7bcSRichard Henderson tcg_gen_extract_i64(dest, src, cpos, len); 35180b1347d2SRichard Henderson } 351930878590SRichard Henderson save_gpr(ctx, a->t, dest); 35200b1347d2SRichard Henderson 35210b1347d2SRichard Henderson /* Install the new nullification. */ 35220b1347d2SRichard Henderson cond_free(&ctx->null_cond); 352330878590SRichard Henderson if (a->c) { 3524bd792da3SRichard Henderson ctx->null_cond = do_sed_cond(ctx, a->c, a->d, dest); 35250b1347d2SRichard Henderson } 352631234768SRichard Henderson return nullify_end(ctx); 35270b1347d2SRichard Henderson } 35280b1347d2SRichard Henderson 352972ae4f2bSRichard Henderson static bool trans_depi_imm(DisasContext *ctx, arg_depi_imm *a) 35300b1347d2SRichard Henderson { 353172ae4f2bSRichard Henderson unsigned len, width; 3532c53e401eSRichard Henderson uint64_t mask0, mask1; 35336fd0c7bcSRichard Henderson TCGv_i64 dest; 35340b1347d2SRichard Henderson 353572ae4f2bSRichard Henderson if (!ctx->is_pa20 && a->d) { 353672ae4f2bSRichard Henderson return false; 353772ae4f2bSRichard Henderson } 353830878590SRichard Henderson if (a->c) { 35390b1347d2SRichard Henderson nullify_over(ctx); 35400b1347d2SRichard Henderson } 354172ae4f2bSRichard Henderson 354272ae4f2bSRichard Henderson len = a->len; 354372ae4f2bSRichard Henderson width = a->d ? 64 : 32; 354472ae4f2bSRichard Henderson if (a->cpos + len > width) { 354572ae4f2bSRichard Henderson len = width - a->cpos; 35460b1347d2SRichard Henderson } 35470b1347d2SRichard Henderson 354830878590SRichard Henderson dest = dest_gpr(ctx, a->t); 354930878590SRichard Henderson mask0 = deposit64(0, a->cpos, len, a->i); 355030878590SRichard Henderson mask1 = deposit64(-1, a->cpos, len, a->i); 35510b1347d2SRichard Henderson 355230878590SRichard Henderson if (a->nz) { 35536fd0c7bcSRichard Henderson TCGv_i64 src = load_gpr(ctx, a->t); 35546fd0c7bcSRichard Henderson tcg_gen_andi_i64(dest, src, mask1); 35556fd0c7bcSRichard Henderson tcg_gen_ori_i64(dest, dest, mask0); 35560b1347d2SRichard Henderson } else { 35576fd0c7bcSRichard Henderson tcg_gen_movi_i64(dest, mask0); 35580b1347d2SRichard Henderson } 355930878590SRichard Henderson save_gpr(ctx, a->t, dest); 35600b1347d2SRichard Henderson 35610b1347d2SRichard Henderson /* Install the new nullification. */ 35620b1347d2SRichard Henderson cond_free(&ctx->null_cond); 356330878590SRichard Henderson if (a->c) { 356472ae4f2bSRichard Henderson ctx->null_cond = do_sed_cond(ctx, a->c, a->d, dest); 35650b1347d2SRichard Henderson } 356631234768SRichard Henderson return nullify_end(ctx); 35670b1347d2SRichard Henderson } 35680b1347d2SRichard Henderson 356972ae4f2bSRichard Henderson static bool trans_dep_imm(DisasContext *ctx, arg_dep_imm *a) 35700b1347d2SRichard Henderson { 357130878590SRichard Henderson unsigned rs = a->nz ? a->t : 0; 357272ae4f2bSRichard Henderson unsigned len, width; 35736fd0c7bcSRichard Henderson TCGv_i64 dest, val; 35740b1347d2SRichard Henderson 357572ae4f2bSRichard Henderson if (!ctx->is_pa20 && a->d) { 357672ae4f2bSRichard Henderson return false; 357772ae4f2bSRichard Henderson } 357830878590SRichard Henderson if (a->c) { 35790b1347d2SRichard Henderson nullify_over(ctx); 35800b1347d2SRichard Henderson } 358172ae4f2bSRichard Henderson 358272ae4f2bSRichard Henderson len = a->len; 358372ae4f2bSRichard Henderson width = a->d ? 64 : 32; 358472ae4f2bSRichard Henderson if (a->cpos + len > width) { 358572ae4f2bSRichard Henderson len = width - a->cpos; 35860b1347d2SRichard Henderson } 35870b1347d2SRichard Henderson 358830878590SRichard Henderson dest = dest_gpr(ctx, a->t); 358930878590SRichard Henderson val = load_gpr(ctx, a->r); 35900b1347d2SRichard Henderson if (rs == 0) { 35916fd0c7bcSRichard Henderson tcg_gen_deposit_z_i64(dest, val, a->cpos, len); 35920b1347d2SRichard Henderson } else { 35936fd0c7bcSRichard Henderson tcg_gen_deposit_i64(dest, cpu_gr[rs], val, a->cpos, len); 35940b1347d2SRichard Henderson } 359530878590SRichard Henderson save_gpr(ctx, a->t, dest); 35960b1347d2SRichard Henderson 35970b1347d2SRichard Henderson /* Install the new nullification. */ 35980b1347d2SRichard Henderson cond_free(&ctx->null_cond); 359930878590SRichard Henderson if (a->c) { 360072ae4f2bSRichard Henderson ctx->null_cond = do_sed_cond(ctx, a->c, a->d, dest); 36010b1347d2SRichard Henderson } 360231234768SRichard Henderson return nullify_end(ctx); 36030b1347d2SRichard Henderson } 36040b1347d2SRichard Henderson 360572ae4f2bSRichard Henderson static bool do_dep_sar(DisasContext *ctx, unsigned rt, unsigned c, 36066fd0c7bcSRichard Henderson bool d, bool nz, unsigned len, TCGv_i64 val) 36070b1347d2SRichard Henderson { 36080b1347d2SRichard Henderson unsigned rs = nz ? rt : 0; 360972ae4f2bSRichard Henderson unsigned widthm1 = d ? 63 : 31; 36106fd0c7bcSRichard Henderson TCGv_i64 mask, tmp, shift, dest; 3611c53e401eSRichard Henderson uint64_t msb = 1ULL << (len - 1); 36120b1347d2SRichard Henderson 36130b1347d2SRichard Henderson dest = dest_gpr(ctx, rt); 3614aac0f603SRichard Henderson shift = tcg_temp_new_i64(); 3615aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 36160b1347d2SRichard Henderson 36170b1347d2SRichard Henderson /* Convert big-endian bit numbering in SAR to left-shift. */ 36186fd0c7bcSRichard Henderson tcg_gen_andi_i64(shift, cpu_sar, widthm1); 36196fd0c7bcSRichard Henderson tcg_gen_xori_i64(shift, shift, widthm1); 36200b1347d2SRichard Henderson 3621aac0f603SRichard Henderson mask = tcg_temp_new_i64(); 36226fd0c7bcSRichard Henderson tcg_gen_movi_i64(mask, msb + (msb - 1)); 36236fd0c7bcSRichard Henderson tcg_gen_and_i64(tmp, val, mask); 36240b1347d2SRichard Henderson if (rs) { 36256fd0c7bcSRichard Henderson tcg_gen_shl_i64(mask, mask, shift); 36266fd0c7bcSRichard Henderson tcg_gen_shl_i64(tmp, tmp, shift); 36276fd0c7bcSRichard Henderson tcg_gen_andc_i64(dest, cpu_gr[rs], mask); 36286fd0c7bcSRichard Henderson tcg_gen_or_i64(dest, dest, tmp); 36290b1347d2SRichard Henderson } else { 36306fd0c7bcSRichard Henderson tcg_gen_shl_i64(dest, tmp, shift); 36310b1347d2SRichard Henderson } 36320b1347d2SRichard Henderson save_gpr(ctx, rt, dest); 36330b1347d2SRichard Henderson 36340b1347d2SRichard Henderson /* Install the new nullification. */ 36350b1347d2SRichard Henderson cond_free(&ctx->null_cond); 36360b1347d2SRichard Henderson if (c) { 363772ae4f2bSRichard Henderson ctx->null_cond = do_sed_cond(ctx, c, d, dest); 36380b1347d2SRichard Henderson } 363931234768SRichard Henderson return nullify_end(ctx); 36400b1347d2SRichard Henderson } 36410b1347d2SRichard Henderson 364272ae4f2bSRichard Henderson static bool trans_dep_sar(DisasContext *ctx, arg_dep_sar *a) 364330878590SRichard Henderson { 364472ae4f2bSRichard Henderson if (!ctx->is_pa20 && a->d) { 364572ae4f2bSRichard Henderson return false; 364672ae4f2bSRichard Henderson } 3647a6deecceSSven Schnelle if (a->c) { 3648a6deecceSSven Schnelle nullify_over(ctx); 3649a6deecceSSven Schnelle } 365072ae4f2bSRichard Henderson return do_dep_sar(ctx, a->t, a->c, a->d, a->nz, a->len, 365172ae4f2bSRichard Henderson load_gpr(ctx, a->r)); 365230878590SRichard Henderson } 365330878590SRichard Henderson 365472ae4f2bSRichard Henderson static bool trans_depi_sar(DisasContext *ctx, arg_depi_sar *a) 365530878590SRichard Henderson { 365672ae4f2bSRichard Henderson if (!ctx->is_pa20 && a->d) { 365772ae4f2bSRichard Henderson return false; 365872ae4f2bSRichard Henderson } 3659a6deecceSSven Schnelle if (a->c) { 3660a6deecceSSven Schnelle nullify_over(ctx); 3661a6deecceSSven Schnelle } 366272ae4f2bSRichard Henderson return do_dep_sar(ctx, a->t, a->c, a->d, a->nz, a->len, 36636fd0c7bcSRichard Henderson tcg_constant_i64(a->i)); 366430878590SRichard Henderson } 36650b1347d2SRichard Henderson 36668340f534SRichard Henderson static bool trans_be(DisasContext *ctx, arg_be *a) 366798cd9ca7SRichard Henderson { 36686fd0c7bcSRichard Henderson TCGv_i64 tmp; 366998cd9ca7SRichard Henderson 3670c301f34eSRichard Henderson #ifdef CONFIG_USER_ONLY 367198cd9ca7SRichard Henderson /* ??? It seems like there should be a good way of using 367298cd9ca7SRichard Henderson "be disp(sr2, r0)", the canonical gateway entry mechanism 367398cd9ca7SRichard Henderson to our advantage. But that appears to be inconvenient to 367498cd9ca7SRichard Henderson manage along side branch delay slots. Therefore we handle 367598cd9ca7SRichard Henderson entry into the gateway page via absolute address. */ 367698cd9ca7SRichard Henderson /* Since we don't implement spaces, just branch. Do notice the special 367798cd9ca7SRichard Henderson case of "be disp(*,r0)" using a direct branch to disp, so that we can 367898cd9ca7SRichard Henderson goto_tb to the TB containing the syscall. */ 36798340f534SRichard Henderson if (a->b == 0) { 36808340f534SRichard Henderson return do_dbranch(ctx, a->disp, a->l, a->n); 368198cd9ca7SRichard Henderson } 3682c301f34eSRichard Henderson #else 3683c301f34eSRichard Henderson nullify_over(ctx); 3684660eefe1SRichard Henderson #endif 3685660eefe1SRichard Henderson 3686aac0f603SRichard Henderson tmp = tcg_temp_new_i64(); 36876fd0c7bcSRichard Henderson tcg_gen_addi_i64(tmp, load_gpr(ctx, a->b), a->disp); 3688660eefe1SRichard Henderson tmp = do_ibranch_priv(ctx, tmp); 3689c301f34eSRichard Henderson 3690c301f34eSRichard Henderson #ifdef CONFIG_USER_ONLY 36918340f534SRichard Henderson return do_ibranch(ctx, tmp, a->l, a->n); 3692c301f34eSRichard Henderson #else 3693c301f34eSRichard Henderson TCGv_i64 new_spc = tcg_temp_new_i64(); 3694c301f34eSRichard Henderson 36958340f534SRichard Henderson load_spr(ctx, new_spc, a->sp); 36968340f534SRichard Henderson if (a->l) { 3697741322f4SRichard Henderson copy_iaoq_entry(ctx, cpu_gr[31], ctx->iaoq_n, ctx->iaoq_n_var); 3698c301f34eSRichard Henderson tcg_gen_mov_i64(cpu_sr[0], cpu_iasq_f); 3699c301f34eSRichard Henderson } 37008340f534SRichard Henderson if (a->n && use_nullify_skip(ctx)) { 3701a0180973SRichard Henderson copy_iaoq_entry(ctx, cpu_iaoq_f, -1, tmp); 37026fd0c7bcSRichard Henderson tcg_gen_addi_i64(tmp, tmp, 4); 3703a0180973SRichard Henderson copy_iaoq_entry(ctx, cpu_iaoq_b, -1, tmp); 3704c301f34eSRichard Henderson tcg_gen_mov_i64(cpu_iasq_f, new_spc); 3705c301f34eSRichard Henderson tcg_gen_mov_i64(cpu_iasq_b, cpu_iasq_f); 3706c301f34eSRichard Henderson } else { 3707741322f4SRichard Henderson copy_iaoq_entry(ctx, cpu_iaoq_f, ctx->iaoq_b, cpu_iaoq_b); 3708c301f34eSRichard Henderson if (ctx->iaoq_b == -1) { 3709c301f34eSRichard Henderson tcg_gen_mov_i64(cpu_iasq_f, cpu_iasq_b); 3710c301f34eSRichard Henderson } 3711a0180973SRichard Henderson copy_iaoq_entry(ctx, cpu_iaoq_b, -1, tmp); 3712c301f34eSRichard Henderson tcg_gen_mov_i64(cpu_iasq_b, new_spc); 37138340f534SRichard Henderson nullify_set(ctx, a->n); 3714c301f34eSRichard Henderson } 3715c301f34eSRichard Henderson tcg_gen_lookup_and_goto_ptr(); 371631234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 371731234768SRichard Henderson return nullify_end(ctx); 3718c301f34eSRichard Henderson #endif 371998cd9ca7SRichard Henderson } 372098cd9ca7SRichard Henderson 37218340f534SRichard Henderson static bool trans_bl(DisasContext *ctx, arg_bl *a) 372298cd9ca7SRichard Henderson { 37238340f534SRichard Henderson return do_dbranch(ctx, iaoq_dest(ctx, a->disp), a->l, a->n); 372498cd9ca7SRichard Henderson } 372598cd9ca7SRichard Henderson 37268340f534SRichard Henderson static bool trans_b_gate(DisasContext *ctx, arg_b_gate *a) 372743e05652SRichard Henderson { 3728c53e401eSRichard Henderson uint64_t dest = iaoq_dest(ctx, a->disp); 372943e05652SRichard Henderson 37306e5f5300SSven Schnelle nullify_over(ctx); 37316e5f5300SSven Schnelle 373243e05652SRichard Henderson /* Make sure the caller hasn't done something weird with the queue. 373343e05652SRichard Henderson * ??? This is not quite the same as the PSW[B] bit, which would be 373443e05652SRichard Henderson * expensive to track. Real hardware will trap for 373543e05652SRichard Henderson * b gateway 373643e05652SRichard Henderson * b gateway+4 (in delay slot of first branch) 373743e05652SRichard Henderson * However, checking for a non-sequential instruction queue *will* 373843e05652SRichard Henderson * diagnose the security hole 373943e05652SRichard Henderson * b gateway 374043e05652SRichard Henderson * b evil 374143e05652SRichard Henderson * in which instructions at evil would run with increased privs. 374243e05652SRichard Henderson */ 374343e05652SRichard Henderson if (ctx->iaoq_b == -1 || ctx->iaoq_b != ctx->iaoq_f + 4) { 374443e05652SRichard Henderson return gen_illegal(ctx); 374543e05652SRichard Henderson } 374643e05652SRichard Henderson 374743e05652SRichard Henderson #ifndef CONFIG_USER_ONLY 374843e05652SRichard Henderson if (ctx->tb_flags & PSW_C) { 3749b77af26eSRichard Henderson CPUHPPAState *env = cpu_env(ctx->cs); 375043e05652SRichard Henderson int type = hppa_artype_for_page(env, ctx->base.pc_next); 375143e05652SRichard Henderson /* If we could not find a TLB entry, then we need to generate an 375243e05652SRichard Henderson ITLB miss exception so the kernel will provide it. 375343e05652SRichard Henderson The resulting TLB fill operation will invalidate this TB and 375443e05652SRichard Henderson we will re-translate, at which point we *will* be able to find 375543e05652SRichard Henderson the TLB entry and determine if this is in fact a gateway page. */ 375643e05652SRichard Henderson if (type < 0) { 375731234768SRichard Henderson gen_excp(ctx, EXCP_ITLB_MISS); 375831234768SRichard Henderson return true; 375943e05652SRichard Henderson } 376043e05652SRichard Henderson /* No change for non-gateway pages or for priv decrease. */ 376143e05652SRichard Henderson if (type >= 4 && type - 4 < ctx->privilege) { 376243e05652SRichard Henderson dest = deposit32(dest, 0, 2, type - 4); 376343e05652SRichard Henderson } 376443e05652SRichard Henderson } else { 376543e05652SRichard Henderson dest &= -4; /* priv = 0 */ 376643e05652SRichard Henderson } 376743e05652SRichard Henderson #endif 376843e05652SRichard Henderson 37696e5f5300SSven Schnelle if (a->l) { 37706fd0c7bcSRichard Henderson TCGv_i64 tmp = dest_gpr(ctx, a->l); 37716e5f5300SSven Schnelle if (ctx->privilege < 3) { 37726fd0c7bcSRichard Henderson tcg_gen_andi_i64(tmp, tmp, -4); 37736e5f5300SSven Schnelle } 37746fd0c7bcSRichard Henderson tcg_gen_ori_i64(tmp, tmp, ctx->privilege); 37756e5f5300SSven Schnelle save_gpr(ctx, a->l, tmp); 37766e5f5300SSven Schnelle } 37776e5f5300SSven Schnelle 37786e5f5300SSven Schnelle return do_dbranch(ctx, dest, 0, a->n); 377943e05652SRichard Henderson } 378043e05652SRichard Henderson 37818340f534SRichard Henderson static bool trans_blr(DisasContext *ctx, arg_blr *a) 378298cd9ca7SRichard Henderson { 3783b35aec85SRichard Henderson if (a->x) { 3784aac0f603SRichard Henderson TCGv_i64 tmp = tcg_temp_new_i64(); 37856fd0c7bcSRichard Henderson tcg_gen_shli_i64(tmp, load_gpr(ctx, a->x), 3); 37866fd0c7bcSRichard Henderson tcg_gen_addi_i64(tmp, tmp, ctx->iaoq_f + 8); 3787660eefe1SRichard Henderson /* The computation here never changes privilege level. */ 37888340f534SRichard Henderson return do_ibranch(ctx, tmp, a->l, a->n); 3789b35aec85SRichard Henderson } else { 3790b35aec85SRichard Henderson /* BLR R0,RX is a good way to load PC+8 into RX. */ 3791b35aec85SRichard Henderson return do_dbranch(ctx, ctx->iaoq_f + 8, a->l, a->n); 3792b35aec85SRichard Henderson } 379398cd9ca7SRichard Henderson } 379498cd9ca7SRichard Henderson 37958340f534SRichard Henderson static bool trans_bv(DisasContext *ctx, arg_bv *a) 379698cd9ca7SRichard Henderson { 37976fd0c7bcSRichard Henderson TCGv_i64 dest; 379898cd9ca7SRichard Henderson 37998340f534SRichard Henderson if (a->x == 0) { 38008340f534SRichard Henderson dest = load_gpr(ctx, a->b); 380198cd9ca7SRichard Henderson } else { 3802aac0f603SRichard Henderson dest = tcg_temp_new_i64(); 38036fd0c7bcSRichard Henderson tcg_gen_shli_i64(dest, load_gpr(ctx, a->x), 3); 38046fd0c7bcSRichard Henderson tcg_gen_add_i64(dest, dest, load_gpr(ctx, a->b)); 380598cd9ca7SRichard Henderson } 3806660eefe1SRichard Henderson dest = do_ibranch_priv(ctx, dest); 38078340f534SRichard Henderson return do_ibranch(ctx, dest, 0, a->n); 380898cd9ca7SRichard Henderson } 380998cd9ca7SRichard Henderson 38108340f534SRichard Henderson static bool trans_bve(DisasContext *ctx, arg_bve *a) 381198cd9ca7SRichard Henderson { 38126fd0c7bcSRichard Henderson TCGv_i64 dest; 381398cd9ca7SRichard Henderson 3814c301f34eSRichard Henderson #ifdef CONFIG_USER_ONLY 38158340f534SRichard Henderson dest = do_ibranch_priv(ctx, load_gpr(ctx, a->b)); 38168340f534SRichard Henderson return do_ibranch(ctx, dest, a->l, a->n); 3817c301f34eSRichard Henderson #else 3818c301f34eSRichard Henderson nullify_over(ctx); 38198340f534SRichard Henderson dest = do_ibranch_priv(ctx, load_gpr(ctx, a->b)); 3820c301f34eSRichard Henderson 3821741322f4SRichard Henderson copy_iaoq_entry(ctx, cpu_iaoq_f, ctx->iaoq_b, cpu_iaoq_b); 3822c301f34eSRichard Henderson if (ctx->iaoq_b == -1) { 3823c301f34eSRichard Henderson tcg_gen_mov_i64(cpu_iasq_f, cpu_iasq_b); 3824c301f34eSRichard Henderson } 3825741322f4SRichard Henderson copy_iaoq_entry(ctx, cpu_iaoq_b, -1, dest); 3826c301f34eSRichard Henderson tcg_gen_mov_i64(cpu_iasq_b, space_select(ctx, 0, dest)); 38278340f534SRichard Henderson if (a->l) { 3828741322f4SRichard Henderson copy_iaoq_entry(ctx, cpu_gr[a->l], ctx->iaoq_n, ctx->iaoq_n_var); 3829c301f34eSRichard Henderson } 38308340f534SRichard Henderson nullify_set(ctx, a->n); 3831c301f34eSRichard Henderson tcg_gen_lookup_and_goto_ptr(); 383231234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 383331234768SRichard Henderson return nullify_end(ctx); 3834c301f34eSRichard Henderson #endif 383598cd9ca7SRichard Henderson } 383698cd9ca7SRichard Henderson 3837a8966ba7SRichard Henderson static bool trans_nopbts(DisasContext *ctx, arg_nopbts *a) 3838a8966ba7SRichard Henderson { 3839a8966ba7SRichard Henderson /* All branch target stack instructions implement as nop. */ 3840a8966ba7SRichard Henderson return ctx->is_pa20; 3841a8966ba7SRichard Henderson } 3842a8966ba7SRichard Henderson 38431ca74648SRichard Henderson /* 38441ca74648SRichard Henderson * Float class 0 38451ca74648SRichard Henderson */ 3846ebe9383cSRichard Henderson 38471ca74648SRichard Henderson static void gen_fcpy_f(TCGv_i32 dst, TCGv_env unused, TCGv_i32 src) 3848ebe9383cSRichard Henderson { 3849ebe9383cSRichard Henderson tcg_gen_mov_i32(dst, src); 3850ebe9383cSRichard Henderson } 3851ebe9383cSRichard Henderson 385259f8c04bSHelge Deller static bool trans_fid_f(DisasContext *ctx, arg_fid_f *a) 385359f8c04bSHelge Deller { 3854a300dad3SRichard Henderson uint64_t ret; 3855a300dad3SRichard Henderson 3856c53e401eSRichard Henderson if (ctx->is_pa20) { 3857a300dad3SRichard Henderson ret = 0x13080000000000ULL; /* PA8700 (PCX-W2) */ 3858a300dad3SRichard Henderson } else { 3859a300dad3SRichard Henderson ret = 0x0f080000000000ULL; /* PA7300LC (PCX-L2) */ 3860a300dad3SRichard Henderson } 3861a300dad3SRichard Henderson 386259f8c04bSHelge Deller nullify_over(ctx); 3863a300dad3SRichard Henderson save_frd(0, tcg_constant_i64(ret)); 386459f8c04bSHelge Deller return nullify_end(ctx); 386559f8c04bSHelge Deller } 386659f8c04bSHelge Deller 38671ca74648SRichard Henderson static bool trans_fcpy_f(DisasContext *ctx, arg_fclass01 *a) 38681ca74648SRichard Henderson { 38691ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_fcpy_f); 38701ca74648SRichard Henderson } 38711ca74648SRichard Henderson 3872ebe9383cSRichard Henderson static void gen_fcpy_d(TCGv_i64 dst, TCGv_env unused, TCGv_i64 src) 3873ebe9383cSRichard Henderson { 3874ebe9383cSRichard Henderson tcg_gen_mov_i64(dst, src); 3875ebe9383cSRichard Henderson } 3876ebe9383cSRichard Henderson 38771ca74648SRichard Henderson static bool trans_fcpy_d(DisasContext *ctx, arg_fclass01 *a) 38781ca74648SRichard Henderson { 38791ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_fcpy_d); 38801ca74648SRichard Henderson } 38811ca74648SRichard Henderson 38821ca74648SRichard Henderson static void gen_fabs_f(TCGv_i32 dst, TCGv_env unused, TCGv_i32 src) 3883ebe9383cSRichard Henderson { 3884ebe9383cSRichard Henderson tcg_gen_andi_i32(dst, src, INT32_MAX); 3885ebe9383cSRichard Henderson } 3886ebe9383cSRichard Henderson 38871ca74648SRichard Henderson static bool trans_fabs_f(DisasContext *ctx, arg_fclass01 *a) 38881ca74648SRichard Henderson { 38891ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_fabs_f); 38901ca74648SRichard Henderson } 38911ca74648SRichard Henderson 3892ebe9383cSRichard Henderson static void gen_fabs_d(TCGv_i64 dst, TCGv_env unused, TCGv_i64 src) 3893ebe9383cSRichard Henderson { 3894ebe9383cSRichard Henderson tcg_gen_andi_i64(dst, src, INT64_MAX); 3895ebe9383cSRichard Henderson } 3896ebe9383cSRichard Henderson 38971ca74648SRichard Henderson static bool trans_fabs_d(DisasContext *ctx, arg_fclass01 *a) 38981ca74648SRichard Henderson { 38991ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_fabs_d); 39001ca74648SRichard Henderson } 39011ca74648SRichard Henderson 39021ca74648SRichard Henderson static bool trans_fsqrt_f(DisasContext *ctx, arg_fclass01 *a) 39031ca74648SRichard Henderson { 39041ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_fsqrt_s); 39051ca74648SRichard Henderson } 39061ca74648SRichard Henderson 39071ca74648SRichard Henderson static bool trans_fsqrt_d(DisasContext *ctx, arg_fclass01 *a) 39081ca74648SRichard Henderson { 39091ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_fsqrt_d); 39101ca74648SRichard Henderson } 39111ca74648SRichard Henderson 39121ca74648SRichard Henderson static bool trans_frnd_f(DisasContext *ctx, arg_fclass01 *a) 39131ca74648SRichard Henderson { 39141ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_frnd_s); 39151ca74648SRichard Henderson } 39161ca74648SRichard Henderson 39171ca74648SRichard Henderson static bool trans_frnd_d(DisasContext *ctx, arg_fclass01 *a) 39181ca74648SRichard Henderson { 39191ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_frnd_d); 39201ca74648SRichard Henderson } 39211ca74648SRichard Henderson 39221ca74648SRichard Henderson static void gen_fneg_f(TCGv_i32 dst, TCGv_env unused, TCGv_i32 src) 3923ebe9383cSRichard Henderson { 3924ebe9383cSRichard Henderson tcg_gen_xori_i32(dst, src, INT32_MIN); 3925ebe9383cSRichard Henderson } 3926ebe9383cSRichard Henderson 39271ca74648SRichard Henderson static bool trans_fneg_f(DisasContext *ctx, arg_fclass01 *a) 39281ca74648SRichard Henderson { 39291ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_fneg_f); 39301ca74648SRichard Henderson } 39311ca74648SRichard Henderson 3932ebe9383cSRichard Henderson static void gen_fneg_d(TCGv_i64 dst, TCGv_env unused, TCGv_i64 src) 3933ebe9383cSRichard Henderson { 3934ebe9383cSRichard Henderson tcg_gen_xori_i64(dst, src, INT64_MIN); 3935ebe9383cSRichard Henderson } 3936ebe9383cSRichard Henderson 39371ca74648SRichard Henderson static bool trans_fneg_d(DisasContext *ctx, arg_fclass01 *a) 39381ca74648SRichard Henderson { 39391ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_fneg_d); 39401ca74648SRichard Henderson } 39411ca74648SRichard Henderson 39421ca74648SRichard Henderson static void gen_fnegabs_f(TCGv_i32 dst, TCGv_env unused, TCGv_i32 src) 3943ebe9383cSRichard Henderson { 3944ebe9383cSRichard Henderson tcg_gen_ori_i32(dst, src, INT32_MIN); 3945ebe9383cSRichard Henderson } 3946ebe9383cSRichard Henderson 39471ca74648SRichard Henderson static bool trans_fnegabs_f(DisasContext *ctx, arg_fclass01 *a) 39481ca74648SRichard Henderson { 39491ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_fnegabs_f); 39501ca74648SRichard Henderson } 39511ca74648SRichard Henderson 3952ebe9383cSRichard Henderson static void gen_fnegabs_d(TCGv_i64 dst, TCGv_env unused, TCGv_i64 src) 3953ebe9383cSRichard Henderson { 3954ebe9383cSRichard Henderson tcg_gen_ori_i64(dst, src, INT64_MIN); 3955ebe9383cSRichard Henderson } 3956ebe9383cSRichard Henderson 39571ca74648SRichard Henderson static bool trans_fnegabs_d(DisasContext *ctx, arg_fclass01 *a) 39581ca74648SRichard Henderson { 39591ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_fnegabs_d); 39601ca74648SRichard Henderson } 39611ca74648SRichard Henderson 39621ca74648SRichard Henderson /* 39631ca74648SRichard Henderson * Float class 1 39641ca74648SRichard Henderson */ 39651ca74648SRichard Henderson 39661ca74648SRichard Henderson static bool trans_fcnv_d_f(DisasContext *ctx, arg_fclass01 *a) 39671ca74648SRichard Henderson { 39681ca74648SRichard Henderson return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_d_s); 39691ca74648SRichard Henderson } 39701ca74648SRichard Henderson 39711ca74648SRichard Henderson static bool trans_fcnv_f_d(DisasContext *ctx, arg_fclass01 *a) 39721ca74648SRichard Henderson { 39731ca74648SRichard Henderson return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_s_d); 39741ca74648SRichard Henderson } 39751ca74648SRichard Henderson 39761ca74648SRichard Henderson static bool trans_fcnv_w_f(DisasContext *ctx, arg_fclass01 *a) 39771ca74648SRichard Henderson { 39781ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_w_s); 39791ca74648SRichard Henderson } 39801ca74648SRichard Henderson 39811ca74648SRichard Henderson static bool trans_fcnv_q_f(DisasContext *ctx, arg_fclass01 *a) 39821ca74648SRichard Henderson { 39831ca74648SRichard Henderson return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_dw_s); 39841ca74648SRichard Henderson } 39851ca74648SRichard Henderson 39861ca74648SRichard Henderson static bool trans_fcnv_w_d(DisasContext *ctx, arg_fclass01 *a) 39871ca74648SRichard Henderson { 39881ca74648SRichard Henderson return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_w_d); 39891ca74648SRichard Henderson } 39901ca74648SRichard Henderson 39911ca74648SRichard Henderson static bool trans_fcnv_q_d(DisasContext *ctx, arg_fclass01 *a) 39921ca74648SRichard Henderson { 39931ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_dw_d); 39941ca74648SRichard Henderson } 39951ca74648SRichard Henderson 39961ca74648SRichard Henderson static bool trans_fcnv_f_w(DisasContext *ctx, arg_fclass01 *a) 39971ca74648SRichard Henderson { 39981ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_s_w); 39991ca74648SRichard Henderson } 40001ca74648SRichard Henderson 40011ca74648SRichard Henderson static bool trans_fcnv_d_w(DisasContext *ctx, arg_fclass01 *a) 40021ca74648SRichard Henderson { 40031ca74648SRichard Henderson return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_d_w); 40041ca74648SRichard Henderson } 40051ca74648SRichard Henderson 40061ca74648SRichard Henderson static bool trans_fcnv_f_q(DisasContext *ctx, arg_fclass01 *a) 40071ca74648SRichard Henderson { 40081ca74648SRichard Henderson return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_s_dw); 40091ca74648SRichard Henderson } 40101ca74648SRichard Henderson 40111ca74648SRichard Henderson static bool trans_fcnv_d_q(DisasContext *ctx, arg_fclass01 *a) 40121ca74648SRichard Henderson { 40131ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_d_dw); 40141ca74648SRichard Henderson } 40151ca74648SRichard Henderson 40161ca74648SRichard Henderson static bool trans_fcnv_t_f_w(DisasContext *ctx, arg_fclass01 *a) 40171ca74648SRichard Henderson { 40181ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_t_s_w); 40191ca74648SRichard Henderson } 40201ca74648SRichard Henderson 40211ca74648SRichard Henderson static bool trans_fcnv_t_d_w(DisasContext *ctx, arg_fclass01 *a) 40221ca74648SRichard Henderson { 40231ca74648SRichard Henderson return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_t_d_w); 40241ca74648SRichard Henderson } 40251ca74648SRichard Henderson 40261ca74648SRichard Henderson static bool trans_fcnv_t_f_q(DisasContext *ctx, arg_fclass01 *a) 40271ca74648SRichard Henderson { 40281ca74648SRichard Henderson return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_t_s_dw); 40291ca74648SRichard Henderson } 40301ca74648SRichard Henderson 40311ca74648SRichard Henderson static bool trans_fcnv_t_d_q(DisasContext *ctx, arg_fclass01 *a) 40321ca74648SRichard Henderson { 40331ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_t_d_dw); 40341ca74648SRichard Henderson } 40351ca74648SRichard Henderson 40361ca74648SRichard Henderson static bool trans_fcnv_uw_f(DisasContext *ctx, arg_fclass01 *a) 40371ca74648SRichard Henderson { 40381ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_uw_s); 40391ca74648SRichard Henderson } 40401ca74648SRichard Henderson 40411ca74648SRichard Henderson static bool trans_fcnv_uq_f(DisasContext *ctx, arg_fclass01 *a) 40421ca74648SRichard Henderson { 40431ca74648SRichard Henderson return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_udw_s); 40441ca74648SRichard Henderson } 40451ca74648SRichard Henderson 40461ca74648SRichard Henderson static bool trans_fcnv_uw_d(DisasContext *ctx, arg_fclass01 *a) 40471ca74648SRichard Henderson { 40481ca74648SRichard Henderson return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_uw_d); 40491ca74648SRichard Henderson } 40501ca74648SRichard Henderson 40511ca74648SRichard Henderson static bool trans_fcnv_uq_d(DisasContext *ctx, arg_fclass01 *a) 40521ca74648SRichard Henderson { 40531ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_udw_d); 40541ca74648SRichard Henderson } 40551ca74648SRichard Henderson 40561ca74648SRichard Henderson static bool trans_fcnv_f_uw(DisasContext *ctx, arg_fclass01 *a) 40571ca74648SRichard Henderson { 40581ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_s_uw); 40591ca74648SRichard Henderson } 40601ca74648SRichard Henderson 40611ca74648SRichard Henderson static bool trans_fcnv_d_uw(DisasContext *ctx, arg_fclass01 *a) 40621ca74648SRichard Henderson { 40631ca74648SRichard Henderson return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_d_uw); 40641ca74648SRichard Henderson } 40651ca74648SRichard Henderson 40661ca74648SRichard Henderson static bool trans_fcnv_f_uq(DisasContext *ctx, arg_fclass01 *a) 40671ca74648SRichard Henderson { 40681ca74648SRichard Henderson return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_s_udw); 40691ca74648SRichard Henderson } 40701ca74648SRichard Henderson 40711ca74648SRichard Henderson static bool trans_fcnv_d_uq(DisasContext *ctx, arg_fclass01 *a) 40721ca74648SRichard Henderson { 40731ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_d_udw); 40741ca74648SRichard Henderson } 40751ca74648SRichard Henderson 40761ca74648SRichard Henderson static bool trans_fcnv_t_f_uw(DisasContext *ctx, arg_fclass01 *a) 40771ca74648SRichard Henderson { 40781ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_t_s_uw); 40791ca74648SRichard Henderson } 40801ca74648SRichard Henderson 40811ca74648SRichard Henderson static bool trans_fcnv_t_d_uw(DisasContext *ctx, arg_fclass01 *a) 40821ca74648SRichard Henderson { 40831ca74648SRichard Henderson return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_t_d_uw); 40841ca74648SRichard Henderson } 40851ca74648SRichard Henderson 40861ca74648SRichard Henderson static bool trans_fcnv_t_f_uq(DisasContext *ctx, arg_fclass01 *a) 40871ca74648SRichard Henderson { 40881ca74648SRichard Henderson return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_t_s_udw); 40891ca74648SRichard Henderson } 40901ca74648SRichard Henderson 40911ca74648SRichard Henderson static bool trans_fcnv_t_d_uq(DisasContext *ctx, arg_fclass01 *a) 40921ca74648SRichard Henderson { 40931ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_t_d_udw); 40941ca74648SRichard Henderson } 40951ca74648SRichard Henderson 40961ca74648SRichard Henderson /* 40971ca74648SRichard Henderson * Float class 2 40981ca74648SRichard Henderson */ 40991ca74648SRichard Henderson 41001ca74648SRichard Henderson static bool trans_fcmp_f(DisasContext *ctx, arg_fclass2 *a) 4101ebe9383cSRichard Henderson { 4102ebe9383cSRichard Henderson TCGv_i32 ta, tb, tc, ty; 4103ebe9383cSRichard Henderson 4104ebe9383cSRichard Henderson nullify_over(ctx); 4105ebe9383cSRichard Henderson 41061ca74648SRichard Henderson ta = load_frw0_i32(a->r1); 41071ca74648SRichard Henderson tb = load_frw0_i32(a->r2); 410829dd6f64SRichard Henderson ty = tcg_constant_i32(a->y); 410929dd6f64SRichard Henderson tc = tcg_constant_i32(a->c); 4110ebe9383cSRichard Henderson 4111ad75a51eSRichard Henderson gen_helper_fcmp_s(tcg_env, ta, tb, ty, tc); 4112ebe9383cSRichard Henderson 41131ca74648SRichard Henderson return nullify_end(ctx); 4114ebe9383cSRichard Henderson } 4115ebe9383cSRichard Henderson 41161ca74648SRichard Henderson static bool trans_fcmp_d(DisasContext *ctx, arg_fclass2 *a) 4117ebe9383cSRichard Henderson { 4118ebe9383cSRichard Henderson TCGv_i64 ta, tb; 4119ebe9383cSRichard Henderson TCGv_i32 tc, ty; 4120ebe9383cSRichard Henderson 4121ebe9383cSRichard Henderson nullify_over(ctx); 4122ebe9383cSRichard Henderson 41231ca74648SRichard Henderson ta = load_frd0(a->r1); 41241ca74648SRichard Henderson tb = load_frd0(a->r2); 412529dd6f64SRichard Henderson ty = tcg_constant_i32(a->y); 412629dd6f64SRichard Henderson tc = tcg_constant_i32(a->c); 4127ebe9383cSRichard Henderson 4128ad75a51eSRichard Henderson gen_helper_fcmp_d(tcg_env, ta, tb, ty, tc); 4129ebe9383cSRichard Henderson 413031234768SRichard Henderson return nullify_end(ctx); 4131ebe9383cSRichard Henderson } 4132ebe9383cSRichard Henderson 41331ca74648SRichard Henderson static bool trans_ftest(DisasContext *ctx, arg_ftest *a) 4134ebe9383cSRichard Henderson { 41356fd0c7bcSRichard Henderson TCGv_i64 t; 4136ebe9383cSRichard Henderson 4137ebe9383cSRichard Henderson nullify_over(ctx); 4138ebe9383cSRichard Henderson 4139aac0f603SRichard Henderson t = tcg_temp_new_i64(); 41406fd0c7bcSRichard Henderson tcg_gen_ld32u_i64(t, tcg_env, offsetof(CPUHPPAState, fr0_shadow)); 4141ebe9383cSRichard Henderson 41421ca74648SRichard Henderson if (a->y == 1) { 4143ebe9383cSRichard Henderson int mask; 4144ebe9383cSRichard Henderson bool inv = false; 4145ebe9383cSRichard Henderson 41461ca74648SRichard Henderson switch (a->c) { 4147ebe9383cSRichard Henderson case 0: /* simple */ 41486fd0c7bcSRichard Henderson tcg_gen_andi_i64(t, t, 0x4000000); 4149ebe9383cSRichard Henderson ctx->null_cond = cond_make_0(TCG_COND_NE, t); 4150ebe9383cSRichard Henderson goto done; 4151ebe9383cSRichard Henderson case 2: /* rej */ 4152ebe9383cSRichard Henderson inv = true; 4153ebe9383cSRichard Henderson /* fallthru */ 4154ebe9383cSRichard Henderson case 1: /* acc */ 4155ebe9383cSRichard Henderson mask = 0x43ff800; 4156ebe9383cSRichard Henderson break; 4157ebe9383cSRichard Henderson case 6: /* rej8 */ 4158ebe9383cSRichard Henderson inv = true; 4159ebe9383cSRichard Henderson /* fallthru */ 4160ebe9383cSRichard Henderson case 5: /* acc8 */ 4161ebe9383cSRichard Henderson mask = 0x43f8000; 4162ebe9383cSRichard Henderson break; 4163ebe9383cSRichard Henderson case 9: /* acc6 */ 4164ebe9383cSRichard Henderson mask = 0x43e0000; 4165ebe9383cSRichard Henderson break; 4166ebe9383cSRichard Henderson case 13: /* acc4 */ 4167ebe9383cSRichard Henderson mask = 0x4380000; 4168ebe9383cSRichard Henderson break; 4169ebe9383cSRichard Henderson case 17: /* acc2 */ 4170ebe9383cSRichard Henderson mask = 0x4200000; 4171ebe9383cSRichard Henderson break; 4172ebe9383cSRichard Henderson default: 41731ca74648SRichard Henderson gen_illegal(ctx); 41741ca74648SRichard Henderson return true; 4175ebe9383cSRichard Henderson } 4176ebe9383cSRichard Henderson if (inv) { 41776fd0c7bcSRichard Henderson TCGv_i64 c = tcg_constant_i64(mask); 41786fd0c7bcSRichard Henderson tcg_gen_or_i64(t, t, c); 4179ebe9383cSRichard Henderson ctx->null_cond = cond_make(TCG_COND_EQ, t, c); 4180ebe9383cSRichard Henderson } else { 41816fd0c7bcSRichard Henderson tcg_gen_andi_i64(t, t, mask); 4182ebe9383cSRichard Henderson ctx->null_cond = cond_make_0(TCG_COND_EQ, t); 4183ebe9383cSRichard Henderson } 41841ca74648SRichard Henderson } else { 41851ca74648SRichard Henderson unsigned cbit = (a->y ^ 1) - 1; 41861ca74648SRichard Henderson 41876fd0c7bcSRichard Henderson tcg_gen_extract_i64(t, t, 21 - cbit, 1); 41881ca74648SRichard Henderson ctx->null_cond = cond_make_0(TCG_COND_NE, t); 41891ca74648SRichard Henderson } 41901ca74648SRichard Henderson 4191ebe9383cSRichard Henderson done: 419231234768SRichard Henderson return nullify_end(ctx); 4193ebe9383cSRichard Henderson } 4194ebe9383cSRichard Henderson 41951ca74648SRichard Henderson /* 41961ca74648SRichard Henderson * Float class 2 41971ca74648SRichard Henderson */ 41981ca74648SRichard Henderson 41991ca74648SRichard Henderson static bool trans_fadd_f(DisasContext *ctx, arg_fclass3 *a) 4200ebe9383cSRichard Henderson { 42011ca74648SRichard Henderson return do_fop_weww(ctx, a->t, a->r1, a->r2, gen_helper_fadd_s); 42021ca74648SRichard Henderson } 42031ca74648SRichard Henderson 42041ca74648SRichard Henderson static bool trans_fadd_d(DisasContext *ctx, arg_fclass3 *a) 42051ca74648SRichard Henderson { 42061ca74648SRichard Henderson return do_fop_dedd(ctx, a->t, a->r1, a->r2, gen_helper_fadd_d); 42071ca74648SRichard Henderson } 42081ca74648SRichard Henderson 42091ca74648SRichard Henderson static bool trans_fsub_f(DisasContext *ctx, arg_fclass3 *a) 42101ca74648SRichard Henderson { 42111ca74648SRichard Henderson return do_fop_weww(ctx, a->t, a->r1, a->r2, gen_helper_fsub_s); 42121ca74648SRichard Henderson } 42131ca74648SRichard Henderson 42141ca74648SRichard Henderson static bool trans_fsub_d(DisasContext *ctx, arg_fclass3 *a) 42151ca74648SRichard Henderson { 42161ca74648SRichard Henderson return do_fop_dedd(ctx, a->t, a->r1, a->r2, gen_helper_fsub_d); 42171ca74648SRichard Henderson } 42181ca74648SRichard Henderson 42191ca74648SRichard Henderson static bool trans_fmpy_f(DisasContext *ctx, arg_fclass3 *a) 42201ca74648SRichard Henderson { 42211ca74648SRichard Henderson return do_fop_weww(ctx, a->t, a->r1, a->r2, gen_helper_fmpy_s); 42221ca74648SRichard Henderson } 42231ca74648SRichard Henderson 42241ca74648SRichard Henderson static bool trans_fmpy_d(DisasContext *ctx, arg_fclass3 *a) 42251ca74648SRichard Henderson { 42261ca74648SRichard Henderson return do_fop_dedd(ctx, a->t, a->r1, a->r2, gen_helper_fmpy_d); 42271ca74648SRichard Henderson } 42281ca74648SRichard Henderson 42291ca74648SRichard Henderson static bool trans_fdiv_f(DisasContext *ctx, arg_fclass3 *a) 42301ca74648SRichard Henderson { 42311ca74648SRichard Henderson return do_fop_weww(ctx, a->t, a->r1, a->r2, gen_helper_fdiv_s); 42321ca74648SRichard Henderson } 42331ca74648SRichard Henderson 42341ca74648SRichard Henderson static bool trans_fdiv_d(DisasContext *ctx, arg_fclass3 *a) 42351ca74648SRichard Henderson { 42361ca74648SRichard Henderson return do_fop_dedd(ctx, a->t, a->r1, a->r2, gen_helper_fdiv_d); 42371ca74648SRichard Henderson } 42381ca74648SRichard Henderson 42391ca74648SRichard Henderson static bool trans_xmpyu(DisasContext *ctx, arg_xmpyu *a) 42401ca74648SRichard Henderson { 42411ca74648SRichard Henderson TCGv_i64 x, y; 4242ebe9383cSRichard Henderson 4243ebe9383cSRichard Henderson nullify_over(ctx); 4244ebe9383cSRichard Henderson 42451ca74648SRichard Henderson x = load_frw0_i64(a->r1); 42461ca74648SRichard Henderson y = load_frw0_i64(a->r2); 42471ca74648SRichard Henderson tcg_gen_mul_i64(x, x, y); 42481ca74648SRichard Henderson save_frd(a->t, x); 4249ebe9383cSRichard Henderson 425031234768SRichard Henderson return nullify_end(ctx); 4251ebe9383cSRichard Henderson } 4252ebe9383cSRichard Henderson 4253ebe9383cSRichard Henderson /* Convert the fmpyadd single-precision register encodings to standard. */ 4254ebe9383cSRichard Henderson static inline int fmpyadd_s_reg(unsigned r) 4255ebe9383cSRichard Henderson { 4256ebe9383cSRichard Henderson return (r & 16) * 2 + 16 + (r & 15); 4257ebe9383cSRichard Henderson } 4258ebe9383cSRichard Henderson 4259b1e2af57SRichard Henderson static bool do_fmpyadd_s(DisasContext *ctx, arg_mpyadd *a, bool is_sub) 4260ebe9383cSRichard Henderson { 4261b1e2af57SRichard Henderson int tm = fmpyadd_s_reg(a->tm); 4262b1e2af57SRichard Henderson int ra = fmpyadd_s_reg(a->ra); 4263b1e2af57SRichard Henderson int ta = fmpyadd_s_reg(a->ta); 4264b1e2af57SRichard Henderson int rm2 = fmpyadd_s_reg(a->rm2); 4265b1e2af57SRichard Henderson int rm1 = fmpyadd_s_reg(a->rm1); 4266ebe9383cSRichard Henderson 4267ebe9383cSRichard Henderson nullify_over(ctx); 4268ebe9383cSRichard Henderson 4269ebe9383cSRichard Henderson do_fop_weww(ctx, tm, rm1, rm2, gen_helper_fmpy_s); 4270ebe9383cSRichard Henderson do_fop_weww(ctx, ta, ta, ra, 4271ebe9383cSRichard Henderson is_sub ? gen_helper_fsub_s : gen_helper_fadd_s); 4272ebe9383cSRichard Henderson 427331234768SRichard Henderson return nullify_end(ctx); 4274ebe9383cSRichard Henderson } 4275ebe9383cSRichard Henderson 4276b1e2af57SRichard Henderson static bool trans_fmpyadd_f(DisasContext *ctx, arg_mpyadd *a) 4277b1e2af57SRichard Henderson { 4278b1e2af57SRichard Henderson return do_fmpyadd_s(ctx, a, false); 4279b1e2af57SRichard Henderson } 4280b1e2af57SRichard Henderson 4281b1e2af57SRichard Henderson static bool trans_fmpysub_f(DisasContext *ctx, arg_mpyadd *a) 4282b1e2af57SRichard Henderson { 4283b1e2af57SRichard Henderson return do_fmpyadd_s(ctx, a, true); 4284b1e2af57SRichard Henderson } 4285b1e2af57SRichard Henderson 4286b1e2af57SRichard Henderson static bool do_fmpyadd_d(DisasContext *ctx, arg_mpyadd *a, bool is_sub) 4287b1e2af57SRichard Henderson { 4288b1e2af57SRichard Henderson nullify_over(ctx); 4289b1e2af57SRichard Henderson 4290b1e2af57SRichard Henderson do_fop_dedd(ctx, a->tm, a->rm1, a->rm2, gen_helper_fmpy_d); 4291b1e2af57SRichard Henderson do_fop_dedd(ctx, a->ta, a->ta, a->ra, 4292b1e2af57SRichard Henderson is_sub ? gen_helper_fsub_d : gen_helper_fadd_d); 4293b1e2af57SRichard Henderson 4294b1e2af57SRichard Henderson return nullify_end(ctx); 4295b1e2af57SRichard Henderson } 4296b1e2af57SRichard Henderson 4297b1e2af57SRichard Henderson static bool trans_fmpyadd_d(DisasContext *ctx, arg_mpyadd *a) 4298b1e2af57SRichard Henderson { 4299b1e2af57SRichard Henderson return do_fmpyadd_d(ctx, a, false); 4300b1e2af57SRichard Henderson } 4301b1e2af57SRichard Henderson 4302b1e2af57SRichard Henderson static bool trans_fmpysub_d(DisasContext *ctx, arg_mpyadd *a) 4303b1e2af57SRichard Henderson { 4304b1e2af57SRichard Henderson return do_fmpyadd_d(ctx, a, true); 4305b1e2af57SRichard Henderson } 4306b1e2af57SRichard Henderson 4307c3bad4f8SRichard Henderson static bool trans_fmpyfadd_f(DisasContext *ctx, arg_fmpyfadd_f *a) 4308ebe9383cSRichard Henderson { 4309c3bad4f8SRichard Henderson TCGv_i32 x, y, z; 4310ebe9383cSRichard Henderson 4311ebe9383cSRichard Henderson nullify_over(ctx); 4312c3bad4f8SRichard Henderson x = load_frw0_i32(a->rm1); 4313c3bad4f8SRichard Henderson y = load_frw0_i32(a->rm2); 4314c3bad4f8SRichard Henderson z = load_frw0_i32(a->ra3); 4315ebe9383cSRichard Henderson 4316c3bad4f8SRichard Henderson if (a->neg) { 4317ad75a51eSRichard Henderson gen_helper_fmpynfadd_s(x, tcg_env, x, y, z); 4318ebe9383cSRichard Henderson } else { 4319ad75a51eSRichard Henderson gen_helper_fmpyfadd_s(x, tcg_env, x, y, z); 4320ebe9383cSRichard Henderson } 4321ebe9383cSRichard Henderson 4322c3bad4f8SRichard Henderson save_frw_i32(a->t, x); 432331234768SRichard Henderson return nullify_end(ctx); 4324ebe9383cSRichard Henderson } 4325ebe9383cSRichard Henderson 4326c3bad4f8SRichard Henderson static bool trans_fmpyfadd_d(DisasContext *ctx, arg_fmpyfadd_d *a) 4327ebe9383cSRichard Henderson { 4328c3bad4f8SRichard Henderson TCGv_i64 x, y, z; 4329ebe9383cSRichard Henderson 4330ebe9383cSRichard Henderson nullify_over(ctx); 4331c3bad4f8SRichard Henderson x = load_frd0(a->rm1); 4332c3bad4f8SRichard Henderson y = load_frd0(a->rm2); 4333c3bad4f8SRichard Henderson z = load_frd0(a->ra3); 4334ebe9383cSRichard Henderson 4335c3bad4f8SRichard Henderson if (a->neg) { 4336ad75a51eSRichard Henderson gen_helper_fmpynfadd_d(x, tcg_env, x, y, z); 4337ebe9383cSRichard Henderson } else { 4338ad75a51eSRichard Henderson gen_helper_fmpyfadd_d(x, tcg_env, x, y, z); 4339ebe9383cSRichard Henderson } 4340ebe9383cSRichard Henderson 4341c3bad4f8SRichard Henderson save_frd(a->t, x); 434231234768SRichard Henderson return nullify_end(ctx); 4343ebe9383cSRichard Henderson } 4344ebe9383cSRichard Henderson 434515da177bSSven Schnelle static bool trans_diag(DisasContext *ctx, arg_diag *a) 434615da177bSSven Schnelle { 4347cf6b28d4SHelge Deller CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 4348cf6b28d4SHelge Deller #ifndef CONFIG_USER_ONLY 4349cf6b28d4SHelge Deller if (a->i == 0x100) { 4350cf6b28d4SHelge Deller /* emulate PDC BTLB, called by SeaBIOS-hppa */ 4351ad75a51eSRichard Henderson nullify_over(ctx); 4352ad75a51eSRichard Henderson gen_helper_diag_btlb(tcg_env); 4353cf6b28d4SHelge Deller return nullify_end(ctx); 435415da177bSSven Schnelle } 4355ad75a51eSRichard Henderson #endif 4356ad75a51eSRichard Henderson qemu_log_mask(LOG_UNIMP, "DIAG opcode 0x%04x ignored\n", a->i); 4357ad75a51eSRichard Henderson return true; 4358ad75a51eSRichard Henderson } 435915da177bSSven Schnelle 4360b542683dSEmilio G. Cota static void hppa_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) 436161766fe9SRichard Henderson { 436251b061fbSRichard Henderson DisasContext *ctx = container_of(dcbase, DisasContext, base); 4363f764718dSRichard Henderson int bound; 436461766fe9SRichard Henderson 436551b061fbSRichard Henderson ctx->cs = cs; 4366494737b7SRichard Henderson ctx->tb_flags = ctx->base.tb->flags; 4367bd6243a3SRichard Henderson ctx->is_pa20 = hppa_is_pa20(cpu_env(cs)); 43683d68ee7bSRichard Henderson 43693d68ee7bSRichard Henderson #ifdef CONFIG_USER_ONLY 4370c01e5dfbSHelge Deller ctx->privilege = MMU_IDX_TO_PRIV(MMU_USER_IDX); 43713d68ee7bSRichard Henderson ctx->mmu_idx = MMU_USER_IDX; 4372c01e5dfbSHelge Deller ctx->iaoq_f = ctx->base.pc_first | ctx->privilege; 4373c01e5dfbSHelge Deller ctx->iaoq_b = ctx->base.tb->cs_base | ctx->privilege; 4374217d1a5eSRichard Henderson ctx->unalign = (ctx->tb_flags & TB_FLAG_UNALIGN ? MO_UNALN : MO_ALIGN); 4375c301f34eSRichard Henderson #else 4376494737b7SRichard Henderson ctx->privilege = (ctx->tb_flags >> TB_FLAG_PRIV_SHIFT) & 3; 4377bb67ec32SRichard Henderson ctx->mmu_idx = (ctx->tb_flags & PSW_D 4378bb67ec32SRichard Henderson ? PRIV_P_TO_MMU_IDX(ctx->privilege, ctx->tb_flags & PSW_P) 4379bb67ec32SRichard Henderson : MMU_PHYS_IDX); 43803d68ee7bSRichard Henderson 4381c301f34eSRichard Henderson /* Recover the IAOQ values from the GVA + PRIV. */ 4382c301f34eSRichard Henderson uint64_t cs_base = ctx->base.tb->cs_base; 4383c301f34eSRichard Henderson uint64_t iasq_f = cs_base & ~0xffffffffull; 4384c301f34eSRichard Henderson int32_t diff = cs_base; 4385c301f34eSRichard Henderson 4386c301f34eSRichard Henderson ctx->iaoq_f = (ctx->base.pc_first & ~iasq_f) + ctx->privilege; 4387c301f34eSRichard Henderson ctx->iaoq_b = (diff ? ctx->iaoq_f + diff : -1); 4388c301f34eSRichard Henderson #endif 438951b061fbSRichard Henderson ctx->iaoq_n = -1; 4390f764718dSRichard Henderson ctx->iaoq_n_var = NULL; 439161766fe9SRichard Henderson 4392a4db4a78SRichard Henderson ctx->zero = tcg_constant_i64(0); 4393a4db4a78SRichard Henderson 43943d68ee7bSRichard Henderson /* Bound the number of instructions by those left on the page. */ 43953d68ee7bSRichard Henderson bound = -(ctx->base.pc_first | TARGET_PAGE_MASK) / 4; 4396b542683dSEmilio G. Cota ctx->base.max_insns = MIN(ctx->base.max_insns, bound); 439761766fe9SRichard Henderson } 439861766fe9SRichard Henderson 439951b061fbSRichard Henderson static void hppa_tr_tb_start(DisasContextBase *dcbase, CPUState *cs) 440051b061fbSRichard Henderson { 440151b061fbSRichard Henderson DisasContext *ctx = container_of(dcbase, DisasContext, base); 440261766fe9SRichard Henderson 44033d68ee7bSRichard Henderson /* Seed the nullification status from PSW[N], as saved in TB->FLAGS. */ 440451b061fbSRichard Henderson ctx->null_cond = cond_make_f(); 440551b061fbSRichard Henderson ctx->psw_n_nonzero = false; 4406494737b7SRichard Henderson if (ctx->tb_flags & PSW_N) { 440751b061fbSRichard Henderson ctx->null_cond.c = TCG_COND_ALWAYS; 440851b061fbSRichard Henderson ctx->psw_n_nonzero = true; 4409129e9cc3SRichard Henderson } 441051b061fbSRichard Henderson ctx->null_lab = NULL; 441161766fe9SRichard Henderson } 441261766fe9SRichard Henderson 441351b061fbSRichard Henderson static void hppa_tr_insn_start(DisasContextBase *dcbase, CPUState *cs) 441451b061fbSRichard Henderson { 441551b061fbSRichard Henderson DisasContext *ctx = container_of(dcbase, DisasContext, base); 441651b061fbSRichard Henderson 441751b061fbSRichard Henderson tcg_gen_insn_start(ctx->iaoq_f, ctx->iaoq_b); 441851b061fbSRichard Henderson } 441951b061fbSRichard Henderson 442051b061fbSRichard Henderson static void hppa_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) 442151b061fbSRichard Henderson { 442251b061fbSRichard Henderson DisasContext *ctx = container_of(dcbase, DisasContext, base); 4423b77af26eSRichard Henderson CPUHPPAState *env = cpu_env(cs); 442451b061fbSRichard Henderson DisasJumpType ret; 442551b061fbSRichard Henderson 442651b061fbSRichard Henderson /* Execute one insn. */ 4427ba1d0b44SRichard Henderson #ifdef CONFIG_USER_ONLY 4428c301f34eSRichard Henderson if (ctx->base.pc_next < TARGET_PAGE_SIZE) { 442931234768SRichard Henderson do_page_zero(ctx); 443031234768SRichard Henderson ret = ctx->base.is_jmp; 4431869051eaSRichard Henderson assert(ret != DISAS_NEXT); 4432ba1d0b44SRichard Henderson } else 4433ba1d0b44SRichard Henderson #endif 4434ba1d0b44SRichard Henderson { 443561766fe9SRichard Henderson /* Always fetch the insn, even if nullified, so that we check 443661766fe9SRichard Henderson the page permissions for execute. */ 44374e116893SIlya Leoshkevich uint32_t insn = translator_ldl(env, &ctx->base, ctx->base.pc_next); 443861766fe9SRichard Henderson 443961766fe9SRichard Henderson /* Set up the IA queue for the next insn. 444061766fe9SRichard Henderson This will be overwritten by a branch. */ 444151b061fbSRichard Henderson if (ctx->iaoq_b == -1) { 444251b061fbSRichard Henderson ctx->iaoq_n = -1; 4443aac0f603SRichard Henderson ctx->iaoq_n_var = tcg_temp_new_i64(); 44446fd0c7bcSRichard Henderson tcg_gen_addi_i64(ctx->iaoq_n_var, cpu_iaoq_b, 4); 444561766fe9SRichard Henderson } else { 444651b061fbSRichard Henderson ctx->iaoq_n = ctx->iaoq_b + 4; 4447f764718dSRichard Henderson ctx->iaoq_n_var = NULL; 444861766fe9SRichard Henderson } 444961766fe9SRichard Henderson 445051b061fbSRichard Henderson if (unlikely(ctx->null_cond.c == TCG_COND_ALWAYS)) { 445151b061fbSRichard Henderson ctx->null_cond.c = TCG_COND_NEVER; 4452869051eaSRichard Henderson ret = DISAS_NEXT; 4453129e9cc3SRichard Henderson } else { 44541a19da0dSRichard Henderson ctx->insn = insn; 445531274b46SRichard Henderson if (!decode(ctx, insn)) { 445631274b46SRichard Henderson gen_illegal(ctx); 445731274b46SRichard Henderson } 445831234768SRichard Henderson ret = ctx->base.is_jmp; 445951b061fbSRichard Henderson assert(ctx->null_lab == NULL); 4460129e9cc3SRichard Henderson } 446161766fe9SRichard Henderson } 446261766fe9SRichard Henderson 44633d68ee7bSRichard Henderson /* Advance the insn queue. Note that this check also detects 44643d68ee7bSRichard Henderson a priority change within the instruction queue. */ 446551b061fbSRichard Henderson if (ret == DISAS_NEXT && ctx->iaoq_b != ctx->iaoq_f + 4) { 4466c301f34eSRichard Henderson if (ctx->iaoq_b != -1 && ctx->iaoq_n != -1 4467c301f34eSRichard Henderson && use_goto_tb(ctx, ctx->iaoq_b) 4468c301f34eSRichard Henderson && (ctx->null_cond.c == TCG_COND_NEVER 4469c301f34eSRichard Henderson || ctx->null_cond.c == TCG_COND_ALWAYS)) { 447051b061fbSRichard Henderson nullify_set(ctx, ctx->null_cond.c == TCG_COND_ALWAYS); 447151b061fbSRichard Henderson gen_goto_tb(ctx, 0, ctx->iaoq_b, ctx->iaoq_n); 447231234768SRichard Henderson ctx->base.is_jmp = ret = DISAS_NORETURN; 4473129e9cc3SRichard Henderson } else { 447431234768SRichard Henderson ctx->base.is_jmp = ret = DISAS_IAQ_N_STALE; 447561766fe9SRichard Henderson } 4476129e9cc3SRichard Henderson } 447751b061fbSRichard Henderson ctx->iaoq_f = ctx->iaoq_b; 447851b061fbSRichard Henderson ctx->iaoq_b = ctx->iaoq_n; 4479c301f34eSRichard Henderson ctx->base.pc_next += 4; 448061766fe9SRichard Henderson 4481c5d0aec2SRichard Henderson switch (ret) { 4482c5d0aec2SRichard Henderson case DISAS_NORETURN: 4483c5d0aec2SRichard Henderson case DISAS_IAQ_N_UPDATED: 4484c5d0aec2SRichard Henderson break; 4485c5d0aec2SRichard Henderson 4486c5d0aec2SRichard Henderson case DISAS_NEXT: 4487c5d0aec2SRichard Henderson case DISAS_IAQ_N_STALE: 4488c5d0aec2SRichard Henderson case DISAS_IAQ_N_STALE_EXIT: 448951b061fbSRichard Henderson if (ctx->iaoq_f == -1) { 4490a0180973SRichard Henderson copy_iaoq_entry(ctx, cpu_iaoq_f, -1, cpu_iaoq_b); 4491741322f4SRichard Henderson copy_iaoq_entry(ctx, cpu_iaoq_b, ctx->iaoq_n, ctx->iaoq_n_var); 4492c301f34eSRichard Henderson #ifndef CONFIG_USER_ONLY 4493c301f34eSRichard Henderson tcg_gen_mov_i64(cpu_iasq_f, cpu_iasq_b); 4494c301f34eSRichard Henderson #endif 449551b061fbSRichard Henderson nullify_save(ctx); 4496c5d0aec2SRichard Henderson ctx->base.is_jmp = (ret == DISAS_IAQ_N_STALE_EXIT 4497c5d0aec2SRichard Henderson ? DISAS_EXIT 4498c5d0aec2SRichard Henderson : DISAS_IAQ_N_UPDATED); 449951b061fbSRichard Henderson } else if (ctx->iaoq_b == -1) { 4500a0180973SRichard Henderson copy_iaoq_entry(ctx, cpu_iaoq_b, -1, ctx->iaoq_n_var); 450161766fe9SRichard Henderson } 4502c5d0aec2SRichard Henderson break; 4503c5d0aec2SRichard Henderson 4504c5d0aec2SRichard Henderson default: 4505c5d0aec2SRichard Henderson g_assert_not_reached(); 4506c5d0aec2SRichard Henderson } 450761766fe9SRichard Henderson } 450861766fe9SRichard Henderson 450951b061fbSRichard Henderson static void hppa_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs) 451051b061fbSRichard Henderson { 451151b061fbSRichard Henderson DisasContext *ctx = container_of(dcbase, DisasContext, base); 4512e1b5a5edSRichard Henderson DisasJumpType is_jmp = ctx->base.is_jmp; 451351b061fbSRichard Henderson 4514e1b5a5edSRichard Henderson switch (is_jmp) { 4515869051eaSRichard Henderson case DISAS_NORETURN: 451661766fe9SRichard Henderson break; 451751b061fbSRichard Henderson case DISAS_TOO_MANY: 4518869051eaSRichard Henderson case DISAS_IAQ_N_STALE: 4519e1b5a5edSRichard Henderson case DISAS_IAQ_N_STALE_EXIT: 4520741322f4SRichard Henderson copy_iaoq_entry(ctx, cpu_iaoq_f, ctx->iaoq_f, cpu_iaoq_f); 4521741322f4SRichard Henderson copy_iaoq_entry(ctx, cpu_iaoq_b, ctx->iaoq_b, cpu_iaoq_b); 452251b061fbSRichard Henderson nullify_save(ctx); 452361766fe9SRichard Henderson /* FALLTHRU */ 4524869051eaSRichard Henderson case DISAS_IAQ_N_UPDATED: 45258532a14eSRichard Henderson if (is_jmp != DISAS_IAQ_N_STALE_EXIT) { 45267f11636dSEmilio G. Cota tcg_gen_lookup_and_goto_ptr(); 45278532a14eSRichard Henderson break; 452861766fe9SRichard Henderson } 4529c5d0aec2SRichard Henderson /* FALLTHRU */ 4530c5d0aec2SRichard Henderson case DISAS_EXIT: 4531c5d0aec2SRichard Henderson tcg_gen_exit_tb(NULL, 0); 453261766fe9SRichard Henderson break; 453361766fe9SRichard Henderson default: 453451b061fbSRichard Henderson g_assert_not_reached(); 453561766fe9SRichard Henderson } 453651b061fbSRichard Henderson } 453761766fe9SRichard Henderson 45388eb806a7SRichard Henderson static void hppa_tr_disas_log(const DisasContextBase *dcbase, 45398eb806a7SRichard Henderson CPUState *cs, FILE *logfile) 454051b061fbSRichard Henderson { 4541c301f34eSRichard Henderson target_ulong pc = dcbase->pc_first; 454261766fe9SRichard Henderson 4543ba1d0b44SRichard Henderson #ifdef CONFIG_USER_ONLY 4544ba1d0b44SRichard Henderson switch (pc) { 45457ad439dfSRichard Henderson case 0x00: 45468eb806a7SRichard Henderson fprintf(logfile, "IN:\n0x00000000: (null)\n"); 4547ba1d0b44SRichard Henderson return; 45487ad439dfSRichard Henderson case 0xb0: 45498eb806a7SRichard Henderson fprintf(logfile, "IN:\n0x000000b0: light-weight-syscall\n"); 4550ba1d0b44SRichard Henderson return; 45517ad439dfSRichard Henderson case 0xe0: 45528eb806a7SRichard Henderson fprintf(logfile, "IN:\n0x000000e0: set-thread-pointer-syscall\n"); 4553ba1d0b44SRichard Henderson return; 45547ad439dfSRichard Henderson case 0x100: 45558eb806a7SRichard Henderson fprintf(logfile, "IN:\n0x00000100: syscall\n"); 4556ba1d0b44SRichard Henderson return; 45577ad439dfSRichard Henderson } 4558ba1d0b44SRichard Henderson #endif 4559ba1d0b44SRichard Henderson 45608eb806a7SRichard Henderson fprintf(logfile, "IN: %s\n", lookup_symbol(pc)); 45618eb806a7SRichard Henderson target_disas(logfile, cs, pc, dcbase->tb->size); 456261766fe9SRichard Henderson } 456351b061fbSRichard Henderson 456451b061fbSRichard Henderson static const TranslatorOps hppa_tr_ops = { 456551b061fbSRichard Henderson .init_disas_context = hppa_tr_init_disas_context, 456651b061fbSRichard Henderson .tb_start = hppa_tr_tb_start, 456751b061fbSRichard Henderson .insn_start = hppa_tr_insn_start, 456851b061fbSRichard Henderson .translate_insn = hppa_tr_translate_insn, 456951b061fbSRichard Henderson .tb_stop = hppa_tr_tb_stop, 457051b061fbSRichard Henderson .disas_log = hppa_tr_disas_log, 457151b061fbSRichard Henderson }; 457251b061fbSRichard Henderson 4573597f9b2dSRichard Henderson void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int *max_insns, 4574306c8721SRichard Henderson target_ulong pc, void *host_pc) 457551b061fbSRichard Henderson { 457651b061fbSRichard Henderson DisasContext ctx; 4577306c8721SRichard Henderson translator_loop(cs, tb, max_insns, pc, host_pc, &hppa_tr_ops, &ctx.base); 457861766fe9SRichard Henderson } 4579