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" 2661766fe9SRichard Henderson #include "exec/cpu_ldst.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 36d53106c9SRichard Henderson 37eaa3783bSRichard Henderson /* Since we have a distinction between register size and address size, 38eaa3783bSRichard Henderson we need to redefine all of these. */ 39eaa3783bSRichard Henderson 40eaa3783bSRichard Henderson #undef TCGv 41eaa3783bSRichard Henderson #undef tcg_temp_new 42eaa3783bSRichard Henderson #undef tcg_global_mem_new 43eaa3783bSRichard Henderson 44eaa3783bSRichard Henderson #if TARGET_LONG_BITS == 64 45eaa3783bSRichard Henderson #define TCGv_tl TCGv_i64 46eaa3783bSRichard Henderson #define tcg_temp_new_tl tcg_temp_new_i64 47eaa3783bSRichard Henderson #if TARGET_REGISTER_BITS == 64 48eaa3783bSRichard Henderson #define tcg_gen_extu_reg_tl tcg_gen_mov_i64 49eaa3783bSRichard Henderson #else 50eaa3783bSRichard Henderson #define tcg_gen_extu_reg_tl tcg_gen_extu_i32_i64 51eaa3783bSRichard Henderson #endif 52eaa3783bSRichard Henderson #else 53eaa3783bSRichard Henderson #define TCGv_tl TCGv_i32 54eaa3783bSRichard Henderson #define tcg_temp_new_tl tcg_temp_new_i32 55eaa3783bSRichard Henderson #define tcg_gen_extu_reg_tl tcg_gen_mov_i32 56eaa3783bSRichard Henderson #endif 57eaa3783bSRichard Henderson 58eaa3783bSRichard Henderson #if TARGET_REGISTER_BITS == 64 59eaa3783bSRichard Henderson #define TCGv_reg TCGv_i64 60eaa3783bSRichard Henderson 61eaa3783bSRichard Henderson #define tcg_temp_new tcg_temp_new_i64 62eaa3783bSRichard Henderson #define tcg_global_mem_new tcg_global_mem_new_i64 63eaa3783bSRichard Henderson 64eaa3783bSRichard Henderson #define tcg_gen_movi_reg tcg_gen_movi_i64 65eaa3783bSRichard Henderson #define tcg_gen_mov_reg tcg_gen_mov_i64 66eaa3783bSRichard Henderson #define tcg_gen_ld8u_reg tcg_gen_ld8u_i64 67eaa3783bSRichard Henderson #define tcg_gen_ld8s_reg tcg_gen_ld8s_i64 68eaa3783bSRichard Henderson #define tcg_gen_ld16u_reg tcg_gen_ld16u_i64 69eaa3783bSRichard Henderson #define tcg_gen_ld16s_reg tcg_gen_ld16s_i64 70eaa3783bSRichard Henderson #define tcg_gen_ld32u_reg tcg_gen_ld32u_i64 71eaa3783bSRichard Henderson #define tcg_gen_ld32s_reg tcg_gen_ld32s_i64 72eaa3783bSRichard Henderson #define tcg_gen_ld_reg tcg_gen_ld_i64 73eaa3783bSRichard Henderson #define tcg_gen_st8_reg tcg_gen_st8_i64 74eaa3783bSRichard Henderson #define tcg_gen_st16_reg tcg_gen_st16_i64 75eaa3783bSRichard Henderson #define tcg_gen_st32_reg tcg_gen_st32_i64 76eaa3783bSRichard Henderson #define tcg_gen_st_reg tcg_gen_st_i64 77eaa3783bSRichard Henderson #define tcg_gen_add_reg tcg_gen_add_i64 78eaa3783bSRichard Henderson #define tcg_gen_addi_reg tcg_gen_addi_i64 79eaa3783bSRichard Henderson #define tcg_gen_sub_reg tcg_gen_sub_i64 80eaa3783bSRichard Henderson #define tcg_gen_neg_reg tcg_gen_neg_i64 81eaa3783bSRichard Henderson #define tcg_gen_subfi_reg tcg_gen_subfi_i64 82eaa3783bSRichard Henderson #define tcg_gen_subi_reg tcg_gen_subi_i64 83eaa3783bSRichard Henderson #define tcg_gen_and_reg tcg_gen_and_i64 84eaa3783bSRichard Henderson #define tcg_gen_andi_reg tcg_gen_andi_i64 85eaa3783bSRichard Henderson #define tcg_gen_or_reg tcg_gen_or_i64 86eaa3783bSRichard Henderson #define tcg_gen_ori_reg tcg_gen_ori_i64 87eaa3783bSRichard Henderson #define tcg_gen_xor_reg tcg_gen_xor_i64 88eaa3783bSRichard Henderson #define tcg_gen_xori_reg tcg_gen_xori_i64 89eaa3783bSRichard Henderson #define tcg_gen_not_reg tcg_gen_not_i64 90eaa3783bSRichard Henderson #define tcg_gen_shl_reg tcg_gen_shl_i64 91eaa3783bSRichard Henderson #define tcg_gen_shli_reg tcg_gen_shli_i64 92eaa3783bSRichard Henderson #define tcg_gen_shr_reg tcg_gen_shr_i64 93eaa3783bSRichard Henderson #define tcg_gen_shri_reg tcg_gen_shri_i64 94eaa3783bSRichard Henderson #define tcg_gen_sar_reg tcg_gen_sar_i64 95eaa3783bSRichard Henderson #define tcg_gen_sari_reg tcg_gen_sari_i64 96eaa3783bSRichard Henderson #define tcg_gen_brcond_reg tcg_gen_brcond_i64 97eaa3783bSRichard Henderson #define tcg_gen_brcondi_reg tcg_gen_brcondi_i64 98eaa3783bSRichard Henderson #define tcg_gen_setcond_reg tcg_gen_setcond_i64 99eaa3783bSRichard Henderson #define tcg_gen_setcondi_reg tcg_gen_setcondi_i64 100eaa3783bSRichard Henderson #define tcg_gen_mul_reg tcg_gen_mul_i64 101eaa3783bSRichard Henderson #define tcg_gen_muli_reg tcg_gen_muli_i64 102eaa3783bSRichard Henderson #define tcg_gen_div_reg tcg_gen_div_i64 103eaa3783bSRichard Henderson #define tcg_gen_rem_reg tcg_gen_rem_i64 104eaa3783bSRichard Henderson #define tcg_gen_divu_reg tcg_gen_divu_i64 105eaa3783bSRichard Henderson #define tcg_gen_remu_reg tcg_gen_remu_i64 106eaa3783bSRichard Henderson #define tcg_gen_discard_reg tcg_gen_discard_i64 107eaa3783bSRichard Henderson #define tcg_gen_trunc_reg_i32 tcg_gen_extrl_i64_i32 108eaa3783bSRichard Henderson #define tcg_gen_trunc_i64_reg tcg_gen_mov_i64 109eaa3783bSRichard Henderson #define tcg_gen_extu_i32_reg tcg_gen_extu_i32_i64 110eaa3783bSRichard Henderson #define tcg_gen_ext_i32_reg tcg_gen_ext_i32_i64 111eaa3783bSRichard Henderson #define tcg_gen_extu_reg_i64 tcg_gen_mov_i64 112eaa3783bSRichard Henderson #define tcg_gen_ext_reg_i64 tcg_gen_mov_i64 113eaa3783bSRichard Henderson #define tcg_gen_ext8u_reg tcg_gen_ext8u_i64 114eaa3783bSRichard Henderson #define tcg_gen_ext8s_reg tcg_gen_ext8s_i64 115eaa3783bSRichard Henderson #define tcg_gen_ext16u_reg tcg_gen_ext16u_i64 116eaa3783bSRichard Henderson #define tcg_gen_ext16s_reg tcg_gen_ext16s_i64 117eaa3783bSRichard Henderson #define tcg_gen_ext32u_reg tcg_gen_ext32u_i64 118eaa3783bSRichard Henderson #define tcg_gen_ext32s_reg tcg_gen_ext32s_i64 119eaa3783bSRichard Henderson #define tcg_gen_bswap16_reg tcg_gen_bswap16_i64 120eaa3783bSRichard Henderson #define tcg_gen_bswap32_reg tcg_gen_bswap32_i64 121eaa3783bSRichard Henderson #define tcg_gen_bswap64_reg tcg_gen_bswap64_i64 122eaa3783bSRichard Henderson #define tcg_gen_concat_reg_i64 tcg_gen_concat32_i64 123eaa3783bSRichard Henderson #define tcg_gen_andc_reg tcg_gen_andc_i64 124eaa3783bSRichard Henderson #define tcg_gen_eqv_reg tcg_gen_eqv_i64 125eaa3783bSRichard Henderson #define tcg_gen_nand_reg tcg_gen_nand_i64 126eaa3783bSRichard Henderson #define tcg_gen_nor_reg tcg_gen_nor_i64 127eaa3783bSRichard Henderson #define tcg_gen_orc_reg tcg_gen_orc_i64 128eaa3783bSRichard Henderson #define tcg_gen_clz_reg tcg_gen_clz_i64 129eaa3783bSRichard Henderson #define tcg_gen_ctz_reg tcg_gen_ctz_i64 130eaa3783bSRichard Henderson #define tcg_gen_clzi_reg tcg_gen_clzi_i64 131eaa3783bSRichard Henderson #define tcg_gen_ctzi_reg tcg_gen_ctzi_i64 132eaa3783bSRichard Henderson #define tcg_gen_clrsb_reg tcg_gen_clrsb_i64 133eaa3783bSRichard Henderson #define tcg_gen_ctpop_reg tcg_gen_ctpop_i64 134eaa3783bSRichard Henderson #define tcg_gen_rotl_reg tcg_gen_rotl_i64 135eaa3783bSRichard Henderson #define tcg_gen_rotli_reg tcg_gen_rotli_i64 136eaa3783bSRichard Henderson #define tcg_gen_rotr_reg tcg_gen_rotr_i64 137eaa3783bSRichard Henderson #define tcg_gen_rotri_reg tcg_gen_rotri_i64 138eaa3783bSRichard Henderson #define tcg_gen_deposit_reg tcg_gen_deposit_i64 139eaa3783bSRichard Henderson #define tcg_gen_deposit_z_reg tcg_gen_deposit_z_i64 140eaa3783bSRichard Henderson #define tcg_gen_extract_reg tcg_gen_extract_i64 141eaa3783bSRichard Henderson #define tcg_gen_sextract_reg tcg_gen_sextract_i64 14205bfd4dbSRichard Henderson #define tcg_gen_extract2_reg tcg_gen_extract2_i64 14329dd6f64SRichard Henderson #define tcg_constant_reg tcg_constant_i64 144eaa3783bSRichard Henderson #define tcg_gen_movcond_reg tcg_gen_movcond_i64 145eaa3783bSRichard Henderson #define tcg_gen_add2_reg tcg_gen_add2_i64 146eaa3783bSRichard Henderson #define tcg_gen_sub2_reg tcg_gen_sub2_i64 147eaa3783bSRichard Henderson #define tcg_gen_qemu_ld_reg tcg_gen_qemu_ld_i64 148eaa3783bSRichard Henderson #define tcg_gen_qemu_st_reg tcg_gen_qemu_st_i64 149eaa3783bSRichard Henderson #define tcg_gen_atomic_xchg_reg tcg_gen_atomic_xchg_i64 1505bfa8034SRichard Henderson #define tcg_gen_trunc_reg_ptr tcg_gen_trunc_i64_ptr 151eaa3783bSRichard Henderson #else 152eaa3783bSRichard Henderson #define TCGv_reg TCGv_i32 153eaa3783bSRichard Henderson #define tcg_temp_new tcg_temp_new_i32 154eaa3783bSRichard Henderson #define tcg_global_mem_new tcg_global_mem_new_i32 155eaa3783bSRichard Henderson 156eaa3783bSRichard Henderson #define tcg_gen_movi_reg tcg_gen_movi_i32 157eaa3783bSRichard Henderson #define tcg_gen_mov_reg tcg_gen_mov_i32 158eaa3783bSRichard Henderson #define tcg_gen_ld8u_reg tcg_gen_ld8u_i32 159eaa3783bSRichard Henderson #define tcg_gen_ld8s_reg tcg_gen_ld8s_i32 160eaa3783bSRichard Henderson #define tcg_gen_ld16u_reg tcg_gen_ld16u_i32 161eaa3783bSRichard Henderson #define tcg_gen_ld16s_reg tcg_gen_ld16s_i32 162eaa3783bSRichard Henderson #define tcg_gen_ld32u_reg tcg_gen_ld_i32 163eaa3783bSRichard Henderson #define tcg_gen_ld32s_reg tcg_gen_ld_i32 164eaa3783bSRichard Henderson #define tcg_gen_ld_reg tcg_gen_ld_i32 165eaa3783bSRichard Henderson #define tcg_gen_st8_reg tcg_gen_st8_i32 166eaa3783bSRichard Henderson #define tcg_gen_st16_reg tcg_gen_st16_i32 167eaa3783bSRichard Henderson #define tcg_gen_st32_reg tcg_gen_st32_i32 168eaa3783bSRichard Henderson #define tcg_gen_st_reg tcg_gen_st_i32 169eaa3783bSRichard Henderson #define tcg_gen_add_reg tcg_gen_add_i32 170eaa3783bSRichard Henderson #define tcg_gen_addi_reg tcg_gen_addi_i32 171eaa3783bSRichard Henderson #define tcg_gen_sub_reg tcg_gen_sub_i32 172eaa3783bSRichard Henderson #define tcg_gen_neg_reg tcg_gen_neg_i32 173eaa3783bSRichard Henderson #define tcg_gen_subfi_reg tcg_gen_subfi_i32 174eaa3783bSRichard Henderson #define tcg_gen_subi_reg tcg_gen_subi_i32 175eaa3783bSRichard Henderson #define tcg_gen_and_reg tcg_gen_and_i32 176eaa3783bSRichard Henderson #define tcg_gen_andi_reg tcg_gen_andi_i32 177eaa3783bSRichard Henderson #define tcg_gen_or_reg tcg_gen_or_i32 178eaa3783bSRichard Henderson #define tcg_gen_ori_reg tcg_gen_ori_i32 179eaa3783bSRichard Henderson #define tcg_gen_xor_reg tcg_gen_xor_i32 180eaa3783bSRichard Henderson #define tcg_gen_xori_reg tcg_gen_xori_i32 181eaa3783bSRichard Henderson #define tcg_gen_not_reg tcg_gen_not_i32 182eaa3783bSRichard Henderson #define tcg_gen_shl_reg tcg_gen_shl_i32 183eaa3783bSRichard Henderson #define tcg_gen_shli_reg tcg_gen_shli_i32 184eaa3783bSRichard Henderson #define tcg_gen_shr_reg tcg_gen_shr_i32 185eaa3783bSRichard Henderson #define tcg_gen_shri_reg tcg_gen_shri_i32 186eaa3783bSRichard Henderson #define tcg_gen_sar_reg tcg_gen_sar_i32 187eaa3783bSRichard Henderson #define tcg_gen_sari_reg tcg_gen_sari_i32 188eaa3783bSRichard Henderson #define tcg_gen_brcond_reg tcg_gen_brcond_i32 189eaa3783bSRichard Henderson #define tcg_gen_brcondi_reg tcg_gen_brcondi_i32 190eaa3783bSRichard Henderson #define tcg_gen_setcond_reg tcg_gen_setcond_i32 191eaa3783bSRichard Henderson #define tcg_gen_setcondi_reg tcg_gen_setcondi_i32 192eaa3783bSRichard Henderson #define tcg_gen_mul_reg tcg_gen_mul_i32 193eaa3783bSRichard Henderson #define tcg_gen_muli_reg tcg_gen_muli_i32 194eaa3783bSRichard Henderson #define tcg_gen_div_reg tcg_gen_div_i32 195eaa3783bSRichard Henderson #define tcg_gen_rem_reg tcg_gen_rem_i32 196eaa3783bSRichard Henderson #define tcg_gen_divu_reg tcg_gen_divu_i32 197eaa3783bSRichard Henderson #define tcg_gen_remu_reg tcg_gen_remu_i32 198eaa3783bSRichard Henderson #define tcg_gen_discard_reg tcg_gen_discard_i32 199eaa3783bSRichard Henderson #define tcg_gen_trunc_reg_i32 tcg_gen_mov_i32 200eaa3783bSRichard Henderson #define tcg_gen_trunc_i64_reg tcg_gen_extrl_i64_i32 201eaa3783bSRichard Henderson #define tcg_gen_extu_i32_reg tcg_gen_mov_i32 202eaa3783bSRichard Henderson #define tcg_gen_ext_i32_reg tcg_gen_mov_i32 203eaa3783bSRichard Henderson #define tcg_gen_extu_reg_i64 tcg_gen_extu_i32_i64 204eaa3783bSRichard Henderson #define tcg_gen_ext_reg_i64 tcg_gen_ext_i32_i64 205eaa3783bSRichard Henderson #define tcg_gen_ext8u_reg tcg_gen_ext8u_i32 206eaa3783bSRichard Henderson #define tcg_gen_ext8s_reg tcg_gen_ext8s_i32 207eaa3783bSRichard Henderson #define tcg_gen_ext16u_reg tcg_gen_ext16u_i32 208eaa3783bSRichard Henderson #define tcg_gen_ext16s_reg tcg_gen_ext16s_i32 209eaa3783bSRichard Henderson #define tcg_gen_ext32u_reg tcg_gen_mov_i32 210eaa3783bSRichard Henderson #define tcg_gen_ext32s_reg tcg_gen_mov_i32 211eaa3783bSRichard Henderson #define tcg_gen_bswap16_reg tcg_gen_bswap16_i32 212eaa3783bSRichard Henderson #define tcg_gen_bswap32_reg tcg_gen_bswap32_i32 213eaa3783bSRichard Henderson #define tcg_gen_concat_reg_i64 tcg_gen_concat_i32_i64 214eaa3783bSRichard Henderson #define tcg_gen_andc_reg tcg_gen_andc_i32 215eaa3783bSRichard Henderson #define tcg_gen_eqv_reg tcg_gen_eqv_i32 216eaa3783bSRichard Henderson #define tcg_gen_nand_reg tcg_gen_nand_i32 217eaa3783bSRichard Henderson #define tcg_gen_nor_reg tcg_gen_nor_i32 218eaa3783bSRichard Henderson #define tcg_gen_orc_reg tcg_gen_orc_i32 219eaa3783bSRichard Henderson #define tcg_gen_clz_reg tcg_gen_clz_i32 220eaa3783bSRichard Henderson #define tcg_gen_ctz_reg tcg_gen_ctz_i32 221eaa3783bSRichard Henderson #define tcg_gen_clzi_reg tcg_gen_clzi_i32 222eaa3783bSRichard Henderson #define tcg_gen_ctzi_reg tcg_gen_ctzi_i32 223eaa3783bSRichard Henderson #define tcg_gen_clrsb_reg tcg_gen_clrsb_i32 224eaa3783bSRichard Henderson #define tcg_gen_ctpop_reg tcg_gen_ctpop_i32 225eaa3783bSRichard Henderson #define tcg_gen_rotl_reg tcg_gen_rotl_i32 226eaa3783bSRichard Henderson #define tcg_gen_rotli_reg tcg_gen_rotli_i32 227eaa3783bSRichard Henderson #define tcg_gen_rotr_reg tcg_gen_rotr_i32 228eaa3783bSRichard Henderson #define tcg_gen_rotri_reg tcg_gen_rotri_i32 229eaa3783bSRichard Henderson #define tcg_gen_deposit_reg tcg_gen_deposit_i32 230eaa3783bSRichard Henderson #define tcg_gen_deposit_z_reg tcg_gen_deposit_z_i32 231eaa3783bSRichard Henderson #define tcg_gen_extract_reg tcg_gen_extract_i32 232eaa3783bSRichard Henderson #define tcg_gen_sextract_reg tcg_gen_sextract_i32 23305bfd4dbSRichard Henderson #define tcg_gen_extract2_reg tcg_gen_extract2_i32 23429dd6f64SRichard Henderson #define tcg_constant_reg tcg_constant_i32 235eaa3783bSRichard Henderson #define tcg_gen_movcond_reg tcg_gen_movcond_i32 236eaa3783bSRichard Henderson #define tcg_gen_add2_reg tcg_gen_add2_i32 237eaa3783bSRichard Henderson #define tcg_gen_sub2_reg tcg_gen_sub2_i32 238eaa3783bSRichard Henderson #define tcg_gen_qemu_ld_reg tcg_gen_qemu_ld_i32 239eaa3783bSRichard Henderson #define tcg_gen_qemu_st_reg tcg_gen_qemu_st_i32 240eaa3783bSRichard Henderson #define tcg_gen_atomic_xchg_reg tcg_gen_atomic_xchg_i32 2415bfa8034SRichard Henderson #define tcg_gen_trunc_reg_ptr tcg_gen_ext_i32_ptr 242eaa3783bSRichard Henderson #endif /* TARGET_REGISTER_BITS */ 243eaa3783bSRichard Henderson 24461766fe9SRichard Henderson typedef struct DisasCond { 24561766fe9SRichard Henderson TCGCond c; 246eaa3783bSRichard Henderson TCGv_reg a0, a1; 24761766fe9SRichard Henderson } DisasCond; 24861766fe9SRichard Henderson 24961766fe9SRichard Henderson typedef struct DisasContext { 250d01a3625SRichard Henderson DisasContextBase base; 25161766fe9SRichard Henderson CPUState *cs; 25261766fe9SRichard Henderson 253eaa3783bSRichard Henderson target_ureg iaoq_f; 254eaa3783bSRichard Henderson target_ureg iaoq_b; 255eaa3783bSRichard Henderson target_ureg iaoq_n; 256eaa3783bSRichard Henderson TCGv_reg iaoq_n_var; 25761766fe9SRichard Henderson 25886f8d05fSRichard Henderson int ntempr, ntempl; 2595eecd37aSRichard Henderson TCGv_reg tempr[8]; 26086f8d05fSRichard Henderson TCGv_tl templ[4]; 26161766fe9SRichard Henderson 26261766fe9SRichard Henderson DisasCond null_cond; 26361766fe9SRichard Henderson TCGLabel *null_lab; 26461766fe9SRichard Henderson 2651a19da0dSRichard Henderson uint32_t insn; 266494737b7SRichard Henderson uint32_t tb_flags; 2673d68ee7bSRichard Henderson int mmu_idx; 2683d68ee7bSRichard Henderson int privilege; 26961766fe9SRichard Henderson bool psw_n_nonzero; 270217d1a5eSRichard Henderson 271217d1a5eSRichard Henderson #ifdef CONFIG_USER_ONLY 272217d1a5eSRichard Henderson MemOp unalign; 273217d1a5eSRichard Henderson #endif 27461766fe9SRichard Henderson } DisasContext; 27561766fe9SRichard Henderson 276217d1a5eSRichard Henderson #ifdef CONFIG_USER_ONLY 277217d1a5eSRichard Henderson #define UNALIGN(C) (C)->unalign 278217d1a5eSRichard Henderson #else 2792d4afb03SRichard Henderson #define UNALIGN(C) MO_ALIGN 280217d1a5eSRichard Henderson #endif 281217d1a5eSRichard Henderson 282e36f27efSRichard Henderson /* Note that ssm/rsm instructions number PSW_W and PSW_E differently. */ 283451e4ffdSRichard Henderson static int expand_sm_imm(DisasContext *ctx, int val) 284e36f27efSRichard Henderson { 285e36f27efSRichard Henderson if (val & PSW_SM_E) { 286e36f27efSRichard Henderson val = (val & ~PSW_SM_E) | PSW_E; 287e36f27efSRichard Henderson } 288e36f27efSRichard Henderson if (val & PSW_SM_W) { 289e36f27efSRichard Henderson val = (val & ~PSW_SM_W) | PSW_W; 290e36f27efSRichard Henderson } 291e36f27efSRichard Henderson return val; 292e36f27efSRichard Henderson } 293e36f27efSRichard Henderson 294deee69a1SRichard Henderson /* Inverted space register indicates 0 means sr0 not inferred from base. */ 295451e4ffdSRichard Henderson static int expand_sr3x(DisasContext *ctx, int val) 296deee69a1SRichard Henderson { 297deee69a1SRichard Henderson return ~val; 298deee69a1SRichard Henderson } 299deee69a1SRichard Henderson 3001cd012a5SRichard Henderson /* Convert the M:A bits within a memory insn to the tri-state value 3011cd012a5SRichard Henderson we use for the final M. */ 302451e4ffdSRichard Henderson static int ma_to_m(DisasContext *ctx, int val) 3031cd012a5SRichard Henderson { 3041cd012a5SRichard Henderson return val & 2 ? (val & 1 ? -1 : 1) : 0; 3051cd012a5SRichard Henderson } 3061cd012a5SRichard Henderson 307740038d7SRichard Henderson /* Convert the sign of the displacement to a pre or post-modify. */ 308451e4ffdSRichard Henderson static int pos_to_m(DisasContext *ctx, int val) 309740038d7SRichard Henderson { 310740038d7SRichard Henderson return val ? 1 : -1; 311740038d7SRichard Henderson } 312740038d7SRichard Henderson 313451e4ffdSRichard Henderson static int neg_to_m(DisasContext *ctx, int val) 314740038d7SRichard Henderson { 315740038d7SRichard Henderson return val ? -1 : 1; 316740038d7SRichard Henderson } 317740038d7SRichard Henderson 318740038d7SRichard Henderson /* Used for branch targets and fp memory ops. */ 319451e4ffdSRichard Henderson static int expand_shl2(DisasContext *ctx, int val) 32001afb7beSRichard Henderson { 32101afb7beSRichard Henderson return val << 2; 32201afb7beSRichard Henderson } 32301afb7beSRichard Henderson 324740038d7SRichard Henderson /* Used for fp memory ops. */ 325451e4ffdSRichard Henderson static int expand_shl3(DisasContext *ctx, int val) 326740038d7SRichard Henderson { 327740038d7SRichard Henderson return val << 3; 328740038d7SRichard Henderson } 329740038d7SRichard Henderson 3300588e061SRichard Henderson /* Used for assemble_21. */ 331451e4ffdSRichard Henderson static int expand_shl11(DisasContext *ctx, int val) 3320588e061SRichard Henderson { 3330588e061SRichard Henderson return val << 11; 3340588e061SRichard Henderson } 3350588e061SRichard Henderson 33601afb7beSRichard Henderson 33740f9f908SRichard Henderson /* Include the auto-generated decoder. */ 338abff1abfSPaolo Bonzini #include "decode-insns.c.inc" 33940f9f908SRichard Henderson 34061766fe9SRichard Henderson /* We are not using a goto_tb (for whatever reason), but have updated 34161766fe9SRichard Henderson the iaq (for whatever reason), so don't do it again on exit. */ 342869051eaSRichard Henderson #define DISAS_IAQ_N_UPDATED DISAS_TARGET_0 34361766fe9SRichard Henderson 34461766fe9SRichard Henderson /* We are exiting the TB, but have neither emitted a goto_tb, nor 34561766fe9SRichard Henderson updated the iaq for the next instruction to be executed. */ 346869051eaSRichard Henderson #define DISAS_IAQ_N_STALE DISAS_TARGET_1 34761766fe9SRichard Henderson 348e1b5a5edSRichard Henderson /* Similarly, but we want to return to the main loop immediately 349e1b5a5edSRichard Henderson to recognize unmasked interrupts. */ 350e1b5a5edSRichard Henderson #define DISAS_IAQ_N_STALE_EXIT DISAS_TARGET_2 351c5d0aec2SRichard Henderson #define DISAS_EXIT DISAS_TARGET_3 352e1b5a5edSRichard Henderson 35361766fe9SRichard Henderson /* global register indexes */ 354eaa3783bSRichard Henderson static TCGv_reg cpu_gr[32]; 35533423472SRichard Henderson static TCGv_i64 cpu_sr[4]; 356494737b7SRichard Henderson static TCGv_i64 cpu_srH; 357eaa3783bSRichard Henderson static TCGv_reg cpu_iaoq_f; 358eaa3783bSRichard Henderson static TCGv_reg cpu_iaoq_b; 359c301f34eSRichard Henderson static TCGv_i64 cpu_iasq_f; 360c301f34eSRichard Henderson static TCGv_i64 cpu_iasq_b; 361eaa3783bSRichard Henderson static TCGv_reg cpu_sar; 362eaa3783bSRichard Henderson static TCGv_reg cpu_psw_n; 363eaa3783bSRichard Henderson static TCGv_reg cpu_psw_v; 364eaa3783bSRichard Henderson static TCGv_reg cpu_psw_cb; 365eaa3783bSRichard Henderson static TCGv_reg cpu_psw_cb_msb; 36661766fe9SRichard Henderson 36761766fe9SRichard Henderson void hppa_translate_init(void) 36861766fe9SRichard Henderson { 36961766fe9SRichard Henderson #define DEF_VAR(V) { &cpu_##V, #V, offsetof(CPUHPPAState, V) } 37061766fe9SRichard Henderson 371eaa3783bSRichard Henderson typedef struct { TCGv_reg *var; const char *name; int ofs; } GlobalVar; 37261766fe9SRichard Henderson static const GlobalVar vars[] = { 37335136a77SRichard Henderson { &cpu_sar, "sar", offsetof(CPUHPPAState, cr[CR_SAR]) }, 37461766fe9SRichard Henderson DEF_VAR(psw_n), 37561766fe9SRichard Henderson DEF_VAR(psw_v), 37661766fe9SRichard Henderson DEF_VAR(psw_cb), 37761766fe9SRichard Henderson DEF_VAR(psw_cb_msb), 37861766fe9SRichard Henderson DEF_VAR(iaoq_f), 37961766fe9SRichard Henderson DEF_VAR(iaoq_b), 38061766fe9SRichard Henderson }; 38161766fe9SRichard Henderson 38261766fe9SRichard Henderson #undef DEF_VAR 38361766fe9SRichard Henderson 38461766fe9SRichard Henderson /* Use the symbolic register names that match the disassembler. */ 38561766fe9SRichard Henderson static const char gr_names[32][4] = { 38661766fe9SRichard Henderson "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", 38761766fe9SRichard Henderson "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", 38861766fe9SRichard Henderson "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", 38961766fe9SRichard Henderson "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31" 39061766fe9SRichard Henderson }; 39133423472SRichard Henderson /* SR[4-7] are not global registers so that we can index them. */ 392494737b7SRichard Henderson static const char sr_names[5][4] = { 393494737b7SRichard Henderson "sr0", "sr1", "sr2", "sr3", "srH" 39433423472SRichard Henderson }; 39561766fe9SRichard Henderson 39661766fe9SRichard Henderson int i; 39761766fe9SRichard Henderson 398f764718dSRichard Henderson cpu_gr[0] = NULL; 39961766fe9SRichard Henderson for (i = 1; i < 32; i++) { 40061766fe9SRichard Henderson cpu_gr[i] = tcg_global_mem_new(cpu_env, 40161766fe9SRichard Henderson offsetof(CPUHPPAState, gr[i]), 40261766fe9SRichard Henderson gr_names[i]); 40361766fe9SRichard Henderson } 40433423472SRichard Henderson for (i = 0; i < 4; i++) { 40533423472SRichard Henderson cpu_sr[i] = tcg_global_mem_new_i64(cpu_env, 40633423472SRichard Henderson offsetof(CPUHPPAState, sr[i]), 40733423472SRichard Henderson sr_names[i]); 40833423472SRichard Henderson } 409494737b7SRichard Henderson cpu_srH = tcg_global_mem_new_i64(cpu_env, 410494737b7SRichard Henderson offsetof(CPUHPPAState, sr[4]), 411494737b7SRichard Henderson sr_names[4]); 41261766fe9SRichard Henderson 41361766fe9SRichard Henderson for (i = 0; i < ARRAY_SIZE(vars); ++i) { 41461766fe9SRichard Henderson const GlobalVar *v = &vars[i]; 41561766fe9SRichard Henderson *v->var = tcg_global_mem_new(cpu_env, v->ofs, v->name); 41661766fe9SRichard Henderson } 417c301f34eSRichard Henderson 418c301f34eSRichard Henderson cpu_iasq_f = tcg_global_mem_new_i64(cpu_env, 419c301f34eSRichard Henderson offsetof(CPUHPPAState, iasq_f), 420c301f34eSRichard Henderson "iasq_f"); 421c301f34eSRichard Henderson cpu_iasq_b = tcg_global_mem_new_i64(cpu_env, 422c301f34eSRichard Henderson offsetof(CPUHPPAState, iasq_b), 423c301f34eSRichard Henderson "iasq_b"); 42461766fe9SRichard Henderson } 42561766fe9SRichard Henderson 426129e9cc3SRichard Henderson static DisasCond cond_make_f(void) 427129e9cc3SRichard Henderson { 428f764718dSRichard Henderson return (DisasCond){ 429f764718dSRichard Henderson .c = TCG_COND_NEVER, 430f764718dSRichard Henderson .a0 = NULL, 431f764718dSRichard Henderson .a1 = NULL, 432f764718dSRichard Henderson }; 433129e9cc3SRichard Henderson } 434129e9cc3SRichard Henderson 435df0232feSRichard Henderson static DisasCond cond_make_t(void) 436df0232feSRichard Henderson { 437df0232feSRichard Henderson return (DisasCond){ 438df0232feSRichard Henderson .c = TCG_COND_ALWAYS, 439df0232feSRichard Henderson .a0 = NULL, 440df0232feSRichard Henderson .a1 = NULL, 441df0232feSRichard Henderson }; 442df0232feSRichard Henderson } 443df0232feSRichard Henderson 444129e9cc3SRichard Henderson static DisasCond cond_make_n(void) 445129e9cc3SRichard Henderson { 446f764718dSRichard Henderson return (DisasCond){ 447f764718dSRichard Henderson .c = TCG_COND_NE, 448f764718dSRichard Henderson .a0 = cpu_psw_n, 4496e94937aSRichard Henderson .a1 = tcg_constant_reg(0) 450f764718dSRichard Henderson }; 451129e9cc3SRichard Henderson } 452129e9cc3SRichard Henderson 453b47a4a02SSven Schnelle static DisasCond cond_make_0_tmp(TCGCond c, TCGv_reg a0) 454b47a4a02SSven Schnelle { 455b47a4a02SSven Schnelle assert (c != TCG_COND_NEVER && c != TCG_COND_ALWAYS); 456b47a4a02SSven Schnelle return (DisasCond){ 4576e94937aSRichard Henderson .c = c, .a0 = a0, .a1 = tcg_constant_reg(0) 458b47a4a02SSven Schnelle }; 459b47a4a02SSven Schnelle } 460b47a4a02SSven Schnelle 461eaa3783bSRichard Henderson static DisasCond cond_make_0(TCGCond c, TCGv_reg a0) 462129e9cc3SRichard Henderson { 463b47a4a02SSven Schnelle TCGv_reg tmp = tcg_temp_new(); 464b47a4a02SSven Schnelle tcg_gen_mov_reg(tmp, a0); 465b47a4a02SSven Schnelle return cond_make_0_tmp(c, tmp); 466129e9cc3SRichard Henderson } 467129e9cc3SRichard Henderson 468eaa3783bSRichard Henderson static DisasCond cond_make(TCGCond c, TCGv_reg a0, TCGv_reg a1) 469129e9cc3SRichard Henderson { 470129e9cc3SRichard Henderson DisasCond r = { .c = c }; 471129e9cc3SRichard Henderson 472129e9cc3SRichard Henderson assert (c != TCG_COND_NEVER && c != TCG_COND_ALWAYS); 473129e9cc3SRichard Henderson r.a0 = tcg_temp_new(); 474eaa3783bSRichard Henderson tcg_gen_mov_reg(r.a0, a0); 475129e9cc3SRichard Henderson r.a1 = tcg_temp_new(); 476eaa3783bSRichard Henderson tcg_gen_mov_reg(r.a1, a1); 477129e9cc3SRichard Henderson 478129e9cc3SRichard Henderson return r; 479129e9cc3SRichard Henderson } 480129e9cc3SRichard Henderson 481129e9cc3SRichard Henderson static void cond_free(DisasCond *cond) 482129e9cc3SRichard Henderson { 483129e9cc3SRichard Henderson switch (cond->c) { 484129e9cc3SRichard Henderson default: 485f764718dSRichard Henderson cond->a0 = NULL; 486f764718dSRichard Henderson cond->a1 = NULL; 487129e9cc3SRichard Henderson /* fallthru */ 488129e9cc3SRichard Henderson case TCG_COND_ALWAYS: 489129e9cc3SRichard Henderson cond->c = TCG_COND_NEVER; 490129e9cc3SRichard Henderson break; 491129e9cc3SRichard Henderson case TCG_COND_NEVER: 492129e9cc3SRichard Henderson break; 493129e9cc3SRichard Henderson } 494129e9cc3SRichard Henderson } 495129e9cc3SRichard Henderson 496eaa3783bSRichard Henderson static TCGv_reg get_temp(DisasContext *ctx) 49761766fe9SRichard Henderson { 49886f8d05fSRichard Henderson unsigned i = ctx->ntempr++; 49986f8d05fSRichard Henderson g_assert(i < ARRAY_SIZE(ctx->tempr)); 50086f8d05fSRichard Henderson return ctx->tempr[i] = tcg_temp_new(); 50161766fe9SRichard Henderson } 50261766fe9SRichard Henderson 50386f8d05fSRichard Henderson #ifndef CONFIG_USER_ONLY 50486f8d05fSRichard Henderson static TCGv_tl get_temp_tl(DisasContext *ctx) 50586f8d05fSRichard Henderson { 50686f8d05fSRichard Henderson unsigned i = ctx->ntempl++; 50786f8d05fSRichard Henderson g_assert(i < ARRAY_SIZE(ctx->templ)); 50886f8d05fSRichard Henderson return ctx->templ[i] = tcg_temp_new_tl(); 50986f8d05fSRichard Henderson } 51086f8d05fSRichard Henderson #endif 51186f8d05fSRichard Henderson 512eaa3783bSRichard Henderson static TCGv_reg load_const(DisasContext *ctx, target_sreg v) 51361766fe9SRichard Henderson { 514eaa3783bSRichard Henderson TCGv_reg t = get_temp(ctx); 515eaa3783bSRichard Henderson tcg_gen_movi_reg(t, v); 51661766fe9SRichard Henderson return t; 51761766fe9SRichard Henderson } 51861766fe9SRichard Henderson 519eaa3783bSRichard Henderson static TCGv_reg load_gpr(DisasContext *ctx, unsigned reg) 52061766fe9SRichard Henderson { 52161766fe9SRichard Henderson if (reg == 0) { 522eaa3783bSRichard Henderson TCGv_reg t = get_temp(ctx); 523eaa3783bSRichard Henderson tcg_gen_movi_reg(t, 0); 52461766fe9SRichard Henderson return t; 52561766fe9SRichard Henderson } else { 52661766fe9SRichard Henderson return cpu_gr[reg]; 52761766fe9SRichard Henderson } 52861766fe9SRichard Henderson } 52961766fe9SRichard Henderson 530eaa3783bSRichard Henderson static TCGv_reg dest_gpr(DisasContext *ctx, unsigned reg) 53161766fe9SRichard Henderson { 532129e9cc3SRichard Henderson if (reg == 0 || ctx->null_cond.c != TCG_COND_NEVER) { 53361766fe9SRichard Henderson return get_temp(ctx); 53461766fe9SRichard Henderson } else { 53561766fe9SRichard Henderson return cpu_gr[reg]; 53661766fe9SRichard Henderson } 53761766fe9SRichard Henderson } 53861766fe9SRichard Henderson 539eaa3783bSRichard Henderson static void save_or_nullify(DisasContext *ctx, TCGv_reg dest, TCGv_reg t) 540129e9cc3SRichard Henderson { 541129e9cc3SRichard Henderson if (ctx->null_cond.c != TCG_COND_NEVER) { 542eaa3783bSRichard Henderson tcg_gen_movcond_reg(ctx->null_cond.c, dest, ctx->null_cond.a0, 543129e9cc3SRichard Henderson ctx->null_cond.a1, dest, t); 544129e9cc3SRichard Henderson } else { 545eaa3783bSRichard Henderson tcg_gen_mov_reg(dest, t); 546129e9cc3SRichard Henderson } 547129e9cc3SRichard Henderson } 548129e9cc3SRichard Henderson 549eaa3783bSRichard Henderson static void save_gpr(DisasContext *ctx, unsigned reg, TCGv_reg t) 550129e9cc3SRichard Henderson { 551129e9cc3SRichard Henderson if (reg != 0) { 552129e9cc3SRichard Henderson save_or_nullify(ctx, cpu_gr[reg], t); 553129e9cc3SRichard Henderson } 554129e9cc3SRichard Henderson } 555129e9cc3SRichard Henderson 556e03b5686SMarc-André Lureau #if HOST_BIG_ENDIAN 55796d6407fSRichard Henderson # define HI_OFS 0 55896d6407fSRichard Henderson # define LO_OFS 4 55996d6407fSRichard Henderson #else 56096d6407fSRichard Henderson # define HI_OFS 4 56196d6407fSRichard Henderson # define LO_OFS 0 56296d6407fSRichard Henderson #endif 56396d6407fSRichard Henderson 56496d6407fSRichard Henderson static TCGv_i32 load_frw_i32(unsigned rt) 56596d6407fSRichard Henderson { 56696d6407fSRichard Henderson TCGv_i32 ret = tcg_temp_new_i32(); 56796d6407fSRichard Henderson tcg_gen_ld_i32(ret, cpu_env, 56896d6407fSRichard Henderson offsetof(CPUHPPAState, fr[rt & 31]) 56996d6407fSRichard Henderson + (rt & 32 ? LO_OFS : HI_OFS)); 57096d6407fSRichard Henderson return ret; 57196d6407fSRichard Henderson } 57296d6407fSRichard Henderson 573ebe9383cSRichard Henderson static TCGv_i32 load_frw0_i32(unsigned rt) 574ebe9383cSRichard Henderson { 575ebe9383cSRichard Henderson if (rt == 0) { 5760992a930SRichard Henderson TCGv_i32 ret = tcg_temp_new_i32(); 5770992a930SRichard Henderson tcg_gen_movi_i32(ret, 0); 5780992a930SRichard Henderson return ret; 579ebe9383cSRichard Henderson } else { 580ebe9383cSRichard Henderson return load_frw_i32(rt); 581ebe9383cSRichard Henderson } 582ebe9383cSRichard Henderson } 583ebe9383cSRichard Henderson 584ebe9383cSRichard Henderson static TCGv_i64 load_frw0_i64(unsigned rt) 585ebe9383cSRichard Henderson { 586ebe9383cSRichard Henderson TCGv_i64 ret = tcg_temp_new_i64(); 5870992a930SRichard Henderson if (rt == 0) { 5880992a930SRichard Henderson tcg_gen_movi_i64(ret, 0); 5890992a930SRichard Henderson } else { 590ebe9383cSRichard Henderson tcg_gen_ld32u_i64(ret, cpu_env, 591ebe9383cSRichard Henderson offsetof(CPUHPPAState, fr[rt & 31]) 592ebe9383cSRichard Henderson + (rt & 32 ? LO_OFS : HI_OFS)); 593ebe9383cSRichard Henderson } 5940992a930SRichard Henderson return ret; 595ebe9383cSRichard Henderson } 596ebe9383cSRichard Henderson 59796d6407fSRichard Henderson static void save_frw_i32(unsigned rt, TCGv_i32 val) 59896d6407fSRichard Henderson { 59996d6407fSRichard Henderson tcg_gen_st_i32(val, cpu_env, 60096d6407fSRichard Henderson offsetof(CPUHPPAState, fr[rt & 31]) 60196d6407fSRichard Henderson + (rt & 32 ? LO_OFS : HI_OFS)); 60296d6407fSRichard Henderson } 60396d6407fSRichard Henderson 60496d6407fSRichard Henderson #undef HI_OFS 60596d6407fSRichard Henderson #undef LO_OFS 60696d6407fSRichard Henderson 60796d6407fSRichard Henderson static TCGv_i64 load_frd(unsigned rt) 60896d6407fSRichard Henderson { 60996d6407fSRichard Henderson TCGv_i64 ret = tcg_temp_new_i64(); 61096d6407fSRichard Henderson tcg_gen_ld_i64(ret, cpu_env, offsetof(CPUHPPAState, fr[rt])); 61196d6407fSRichard Henderson return ret; 61296d6407fSRichard Henderson } 61396d6407fSRichard Henderson 614ebe9383cSRichard Henderson static TCGv_i64 load_frd0(unsigned rt) 615ebe9383cSRichard Henderson { 616ebe9383cSRichard Henderson if (rt == 0) { 6170992a930SRichard Henderson TCGv_i64 ret = tcg_temp_new_i64(); 6180992a930SRichard Henderson tcg_gen_movi_i64(ret, 0); 6190992a930SRichard Henderson return ret; 620ebe9383cSRichard Henderson } else { 621ebe9383cSRichard Henderson return load_frd(rt); 622ebe9383cSRichard Henderson } 623ebe9383cSRichard Henderson } 624ebe9383cSRichard Henderson 62596d6407fSRichard Henderson static void save_frd(unsigned rt, TCGv_i64 val) 62696d6407fSRichard Henderson { 62796d6407fSRichard Henderson tcg_gen_st_i64(val, cpu_env, offsetof(CPUHPPAState, fr[rt])); 62896d6407fSRichard Henderson } 62996d6407fSRichard Henderson 63033423472SRichard Henderson static void load_spr(DisasContext *ctx, TCGv_i64 dest, unsigned reg) 63133423472SRichard Henderson { 63233423472SRichard Henderson #ifdef CONFIG_USER_ONLY 63333423472SRichard Henderson tcg_gen_movi_i64(dest, 0); 63433423472SRichard Henderson #else 63533423472SRichard Henderson if (reg < 4) { 63633423472SRichard Henderson tcg_gen_mov_i64(dest, cpu_sr[reg]); 637494737b7SRichard Henderson } else if (ctx->tb_flags & TB_FLAG_SR_SAME) { 638494737b7SRichard Henderson tcg_gen_mov_i64(dest, cpu_srH); 63933423472SRichard Henderson } else { 64033423472SRichard Henderson tcg_gen_ld_i64(dest, cpu_env, offsetof(CPUHPPAState, sr[reg])); 64133423472SRichard Henderson } 64233423472SRichard Henderson #endif 64333423472SRichard Henderson } 64433423472SRichard Henderson 645129e9cc3SRichard Henderson /* Skip over the implementation of an insn that has been nullified. 646129e9cc3SRichard Henderson Use this when the insn is too complex for a conditional move. */ 647129e9cc3SRichard Henderson static void nullify_over(DisasContext *ctx) 648129e9cc3SRichard Henderson { 649129e9cc3SRichard Henderson if (ctx->null_cond.c != TCG_COND_NEVER) { 650129e9cc3SRichard Henderson /* The always condition should have been handled in the main loop. */ 651129e9cc3SRichard Henderson assert(ctx->null_cond.c != TCG_COND_ALWAYS); 652129e9cc3SRichard Henderson 653129e9cc3SRichard Henderson ctx->null_lab = gen_new_label(); 654129e9cc3SRichard Henderson 655129e9cc3SRichard Henderson /* If we're using PSW[N], copy it to a temp because... */ 6566e94937aSRichard Henderson if (ctx->null_cond.a0 == cpu_psw_n) { 657129e9cc3SRichard Henderson ctx->null_cond.a0 = tcg_temp_new(); 658eaa3783bSRichard Henderson tcg_gen_mov_reg(ctx->null_cond.a0, cpu_psw_n); 659129e9cc3SRichard Henderson } 660129e9cc3SRichard Henderson /* ... we clear it before branching over the implementation, 661129e9cc3SRichard Henderson so that (1) it's clear after nullifying this insn and 662129e9cc3SRichard Henderson (2) if this insn nullifies the next, PSW[N] is valid. */ 663129e9cc3SRichard Henderson if (ctx->psw_n_nonzero) { 664129e9cc3SRichard Henderson ctx->psw_n_nonzero = false; 665eaa3783bSRichard Henderson tcg_gen_movi_reg(cpu_psw_n, 0); 666129e9cc3SRichard Henderson } 667129e9cc3SRichard Henderson 668eaa3783bSRichard Henderson tcg_gen_brcond_reg(ctx->null_cond.c, ctx->null_cond.a0, 669129e9cc3SRichard Henderson ctx->null_cond.a1, ctx->null_lab); 670129e9cc3SRichard Henderson cond_free(&ctx->null_cond); 671129e9cc3SRichard Henderson } 672129e9cc3SRichard Henderson } 673129e9cc3SRichard Henderson 674129e9cc3SRichard Henderson /* Save the current nullification state to PSW[N]. */ 675129e9cc3SRichard Henderson static void nullify_save(DisasContext *ctx) 676129e9cc3SRichard Henderson { 677129e9cc3SRichard Henderson if (ctx->null_cond.c == TCG_COND_NEVER) { 678129e9cc3SRichard Henderson if (ctx->psw_n_nonzero) { 679eaa3783bSRichard Henderson tcg_gen_movi_reg(cpu_psw_n, 0); 680129e9cc3SRichard Henderson } 681129e9cc3SRichard Henderson return; 682129e9cc3SRichard Henderson } 6836e94937aSRichard Henderson if (ctx->null_cond.a0 != cpu_psw_n) { 684eaa3783bSRichard Henderson tcg_gen_setcond_reg(ctx->null_cond.c, cpu_psw_n, 685129e9cc3SRichard Henderson ctx->null_cond.a0, ctx->null_cond.a1); 686129e9cc3SRichard Henderson ctx->psw_n_nonzero = true; 687129e9cc3SRichard Henderson } 688129e9cc3SRichard Henderson cond_free(&ctx->null_cond); 689129e9cc3SRichard Henderson } 690129e9cc3SRichard Henderson 691129e9cc3SRichard Henderson /* Set a PSW[N] to X. The intention is that this is used immediately 692129e9cc3SRichard Henderson before a goto_tb/exit_tb, so that there is no fallthru path to other 693129e9cc3SRichard Henderson code within the TB. Therefore we do not update psw_n_nonzero. */ 694129e9cc3SRichard Henderson static void nullify_set(DisasContext *ctx, bool x) 695129e9cc3SRichard Henderson { 696129e9cc3SRichard Henderson if (ctx->psw_n_nonzero || x) { 697eaa3783bSRichard Henderson tcg_gen_movi_reg(cpu_psw_n, x); 698129e9cc3SRichard Henderson } 699129e9cc3SRichard Henderson } 700129e9cc3SRichard Henderson 701129e9cc3SRichard Henderson /* Mark the end of an instruction that may have been nullified. 70240f9f908SRichard Henderson This is the pair to nullify_over. Always returns true so that 70340f9f908SRichard Henderson it may be tail-called from a translate function. */ 70431234768SRichard Henderson static bool nullify_end(DisasContext *ctx) 705129e9cc3SRichard Henderson { 706129e9cc3SRichard Henderson TCGLabel *null_lab = ctx->null_lab; 70731234768SRichard Henderson DisasJumpType status = ctx->base.is_jmp; 708129e9cc3SRichard Henderson 709f49b3537SRichard Henderson /* For NEXT, NORETURN, STALE, we can easily continue (or exit). 710f49b3537SRichard Henderson For UPDATED, we cannot update on the nullified path. */ 711f49b3537SRichard Henderson assert(status != DISAS_IAQ_N_UPDATED); 712f49b3537SRichard Henderson 713129e9cc3SRichard Henderson if (likely(null_lab == NULL)) { 714129e9cc3SRichard Henderson /* The current insn wasn't conditional or handled the condition 715129e9cc3SRichard Henderson applied to it without a branch, so the (new) setting of 716129e9cc3SRichard Henderson NULL_COND can be applied directly to the next insn. */ 71731234768SRichard Henderson return true; 718129e9cc3SRichard Henderson } 719129e9cc3SRichard Henderson ctx->null_lab = NULL; 720129e9cc3SRichard Henderson 721129e9cc3SRichard Henderson if (likely(ctx->null_cond.c == TCG_COND_NEVER)) { 722129e9cc3SRichard Henderson /* The next instruction will be unconditional, 723129e9cc3SRichard Henderson and NULL_COND already reflects that. */ 724129e9cc3SRichard Henderson gen_set_label(null_lab); 725129e9cc3SRichard Henderson } else { 726129e9cc3SRichard Henderson /* The insn that we just executed is itself nullifying the next 727129e9cc3SRichard Henderson instruction. Store the condition in the PSW[N] global. 728129e9cc3SRichard Henderson We asserted PSW[N] = 0 in nullify_over, so that after the 729129e9cc3SRichard Henderson label we have the proper value in place. */ 730129e9cc3SRichard Henderson nullify_save(ctx); 731129e9cc3SRichard Henderson gen_set_label(null_lab); 732129e9cc3SRichard Henderson ctx->null_cond = cond_make_n(); 733129e9cc3SRichard Henderson } 734869051eaSRichard Henderson if (status == DISAS_NORETURN) { 73531234768SRichard Henderson ctx->base.is_jmp = DISAS_NEXT; 736129e9cc3SRichard Henderson } 73731234768SRichard Henderson return true; 738129e9cc3SRichard Henderson } 739129e9cc3SRichard Henderson 740eaa3783bSRichard Henderson static void copy_iaoq_entry(TCGv_reg dest, target_ureg ival, TCGv_reg vval) 74161766fe9SRichard Henderson { 74261766fe9SRichard Henderson if (unlikely(ival == -1)) { 743eaa3783bSRichard Henderson tcg_gen_mov_reg(dest, vval); 74461766fe9SRichard Henderson } else { 745eaa3783bSRichard Henderson tcg_gen_movi_reg(dest, ival); 74661766fe9SRichard Henderson } 74761766fe9SRichard Henderson } 74861766fe9SRichard Henderson 749eaa3783bSRichard Henderson static inline target_ureg iaoq_dest(DisasContext *ctx, target_sreg disp) 75061766fe9SRichard Henderson { 75161766fe9SRichard Henderson return ctx->iaoq_f + disp + 8; 75261766fe9SRichard Henderson } 75361766fe9SRichard Henderson 75461766fe9SRichard Henderson static void gen_excp_1(int exception) 75561766fe9SRichard Henderson { 75629dd6f64SRichard Henderson gen_helper_excp(cpu_env, tcg_constant_i32(exception)); 75761766fe9SRichard Henderson } 75861766fe9SRichard Henderson 75931234768SRichard Henderson static void gen_excp(DisasContext *ctx, int exception) 76061766fe9SRichard Henderson { 76161766fe9SRichard Henderson copy_iaoq_entry(cpu_iaoq_f, ctx->iaoq_f, cpu_iaoq_f); 76261766fe9SRichard Henderson copy_iaoq_entry(cpu_iaoq_b, ctx->iaoq_b, cpu_iaoq_b); 763129e9cc3SRichard Henderson nullify_save(ctx); 76461766fe9SRichard Henderson gen_excp_1(exception); 76531234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 76661766fe9SRichard Henderson } 76761766fe9SRichard Henderson 76831234768SRichard Henderson static bool gen_excp_iir(DisasContext *ctx, int exc) 7691a19da0dSRichard Henderson { 77031234768SRichard Henderson nullify_over(ctx); 77129dd6f64SRichard Henderson tcg_gen_st_reg(tcg_constant_reg(ctx->insn), 77229dd6f64SRichard Henderson cpu_env, offsetof(CPUHPPAState, cr[CR_IIR])); 77331234768SRichard Henderson gen_excp(ctx, exc); 77431234768SRichard Henderson return nullify_end(ctx); 7751a19da0dSRichard Henderson } 7761a19da0dSRichard Henderson 77731234768SRichard Henderson static bool gen_illegal(DisasContext *ctx) 77861766fe9SRichard Henderson { 77931234768SRichard Henderson return gen_excp_iir(ctx, EXCP_ILL); 78061766fe9SRichard Henderson } 78161766fe9SRichard Henderson 78240f9f908SRichard Henderson #ifdef CONFIG_USER_ONLY 78340f9f908SRichard Henderson #define CHECK_MOST_PRIVILEGED(EXCP) \ 78440f9f908SRichard Henderson return gen_excp_iir(ctx, EXCP) 78540f9f908SRichard Henderson #else 786e1b5a5edSRichard Henderson #define CHECK_MOST_PRIVILEGED(EXCP) \ 787e1b5a5edSRichard Henderson do { \ 788e1b5a5edSRichard Henderson if (ctx->privilege != 0) { \ 78931234768SRichard Henderson return gen_excp_iir(ctx, EXCP); \ 790e1b5a5edSRichard Henderson } \ 791e1b5a5edSRichard Henderson } while (0) 79240f9f908SRichard Henderson #endif 793e1b5a5edSRichard Henderson 794eaa3783bSRichard Henderson static bool use_goto_tb(DisasContext *ctx, target_ureg dest) 79561766fe9SRichard Henderson { 79657f91498SRichard Henderson return translator_use_goto_tb(&ctx->base, dest); 79761766fe9SRichard Henderson } 79861766fe9SRichard Henderson 799129e9cc3SRichard Henderson /* If the next insn is to be nullified, and it's on the same page, 800129e9cc3SRichard Henderson and we're not attempting to set a breakpoint on it, then we can 801129e9cc3SRichard Henderson totally skip the nullified insn. This avoids creating and 802129e9cc3SRichard Henderson executing a TB that merely branches to the next TB. */ 803129e9cc3SRichard Henderson static bool use_nullify_skip(DisasContext *ctx) 804129e9cc3SRichard Henderson { 805129e9cc3SRichard Henderson return (((ctx->iaoq_b ^ ctx->iaoq_f) & TARGET_PAGE_MASK) == 0 806129e9cc3SRichard Henderson && !cpu_breakpoint_test(ctx->cs, ctx->iaoq_b, BP_ANY)); 807129e9cc3SRichard Henderson } 808129e9cc3SRichard Henderson 80961766fe9SRichard Henderson static void gen_goto_tb(DisasContext *ctx, int which, 810eaa3783bSRichard Henderson target_ureg f, target_ureg b) 81161766fe9SRichard Henderson { 81261766fe9SRichard Henderson if (f != -1 && b != -1 && use_goto_tb(ctx, f)) { 81361766fe9SRichard Henderson tcg_gen_goto_tb(which); 814eaa3783bSRichard Henderson tcg_gen_movi_reg(cpu_iaoq_f, f); 815eaa3783bSRichard Henderson tcg_gen_movi_reg(cpu_iaoq_b, b); 81607ea28b4SRichard Henderson tcg_gen_exit_tb(ctx->base.tb, which); 81761766fe9SRichard Henderson } else { 81861766fe9SRichard Henderson copy_iaoq_entry(cpu_iaoq_f, f, cpu_iaoq_b); 81961766fe9SRichard Henderson copy_iaoq_entry(cpu_iaoq_b, b, ctx->iaoq_n_var); 8207f11636dSEmilio G. Cota tcg_gen_lookup_and_goto_ptr(); 82161766fe9SRichard Henderson } 82261766fe9SRichard Henderson } 82361766fe9SRichard Henderson 824b47a4a02SSven Schnelle static bool cond_need_sv(int c) 825b47a4a02SSven Schnelle { 826b47a4a02SSven Schnelle return c == 2 || c == 3 || c == 6; 827b47a4a02SSven Schnelle } 828b47a4a02SSven Schnelle 829b47a4a02SSven Schnelle static bool cond_need_cb(int c) 830b47a4a02SSven Schnelle { 831b47a4a02SSven Schnelle return c == 4 || c == 5; 832b47a4a02SSven Schnelle } 833b47a4a02SSven Schnelle 834b47a4a02SSven Schnelle /* 835b47a4a02SSven Schnelle * Compute conditional for arithmetic. See Page 5-3, Table 5-1, of 836b47a4a02SSven Schnelle * the Parisc 1.1 Architecture Reference Manual for details. 837b47a4a02SSven Schnelle */ 838b2167459SRichard Henderson 839eaa3783bSRichard Henderson static DisasCond do_cond(unsigned cf, TCGv_reg res, 840eaa3783bSRichard Henderson TCGv_reg cb_msb, TCGv_reg sv) 841b2167459SRichard Henderson { 842b2167459SRichard Henderson DisasCond cond; 843eaa3783bSRichard Henderson TCGv_reg tmp; 844b2167459SRichard Henderson 845b2167459SRichard Henderson switch (cf >> 1) { 846b47a4a02SSven Schnelle case 0: /* Never / TR (0 / 1) */ 847b2167459SRichard Henderson cond = cond_make_f(); 848b2167459SRichard Henderson break; 849b2167459SRichard Henderson case 1: /* = / <> (Z / !Z) */ 850b2167459SRichard Henderson cond = cond_make_0(TCG_COND_EQ, res); 851b2167459SRichard Henderson break; 852b47a4a02SSven Schnelle case 2: /* < / >= (N ^ V / !(N ^ V) */ 853b47a4a02SSven Schnelle tmp = tcg_temp_new(); 854b47a4a02SSven Schnelle tcg_gen_xor_reg(tmp, res, sv); 855b47a4a02SSven Schnelle cond = cond_make_0_tmp(TCG_COND_LT, tmp); 856b2167459SRichard Henderson break; 857b47a4a02SSven Schnelle case 3: /* <= / > (N ^ V) | Z / !((N ^ V) | Z) */ 858b47a4a02SSven Schnelle /* 859b47a4a02SSven Schnelle * Simplify: 860b47a4a02SSven Schnelle * (N ^ V) | Z 861b47a4a02SSven Schnelle * ((res < 0) ^ (sv < 0)) | !res 862b47a4a02SSven Schnelle * ((res ^ sv) < 0) | !res 863b47a4a02SSven Schnelle * (~(res ^ sv) >= 0) | !res 864b47a4a02SSven Schnelle * !(~(res ^ sv) >> 31) | !res 865b47a4a02SSven Schnelle * !(~(res ^ sv) >> 31 & res) 866b47a4a02SSven Schnelle */ 867b47a4a02SSven Schnelle tmp = tcg_temp_new(); 868b47a4a02SSven Schnelle tcg_gen_eqv_reg(tmp, res, sv); 869b47a4a02SSven Schnelle tcg_gen_sari_reg(tmp, tmp, TARGET_REGISTER_BITS - 1); 870b47a4a02SSven Schnelle tcg_gen_and_reg(tmp, tmp, res); 871b47a4a02SSven Schnelle cond = cond_make_0_tmp(TCG_COND_EQ, tmp); 872b2167459SRichard Henderson break; 873b2167459SRichard Henderson case 4: /* NUV / UV (!C / C) */ 874b2167459SRichard Henderson cond = cond_make_0(TCG_COND_EQ, cb_msb); 875b2167459SRichard Henderson break; 876b2167459SRichard Henderson case 5: /* ZNV / VNZ (!C | Z / C & !Z) */ 877b2167459SRichard Henderson tmp = tcg_temp_new(); 878eaa3783bSRichard Henderson tcg_gen_neg_reg(tmp, cb_msb); 879eaa3783bSRichard Henderson tcg_gen_and_reg(tmp, tmp, res); 880b47a4a02SSven Schnelle cond = cond_make_0_tmp(TCG_COND_EQ, tmp); 881b2167459SRichard Henderson break; 882b2167459SRichard Henderson case 6: /* SV / NSV (V / !V) */ 883b2167459SRichard Henderson cond = cond_make_0(TCG_COND_LT, sv); 884b2167459SRichard Henderson break; 885b2167459SRichard Henderson case 7: /* OD / EV */ 886b2167459SRichard Henderson tmp = tcg_temp_new(); 887eaa3783bSRichard Henderson tcg_gen_andi_reg(tmp, res, 1); 888b47a4a02SSven Schnelle cond = cond_make_0_tmp(TCG_COND_NE, tmp); 889b2167459SRichard Henderson break; 890b2167459SRichard Henderson default: 891b2167459SRichard Henderson g_assert_not_reached(); 892b2167459SRichard Henderson } 893b2167459SRichard Henderson if (cf & 1) { 894b2167459SRichard Henderson cond.c = tcg_invert_cond(cond.c); 895b2167459SRichard Henderson } 896b2167459SRichard Henderson 897b2167459SRichard Henderson return cond; 898b2167459SRichard Henderson } 899b2167459SRichard Henderson 900b2167459SRichard Henderson /* Similar, but for the special case of subtraction without borrow, we 901b2167459SRichard Henderson can use the inputs directly. This can allow other computation to be 902b2167459SRichard Henderson deleted as unused. */ 903b2167459SRichard Henderson 904eaa3783bSRichard Henderson static DisasCond do_sub_cond(unsigned cf, TCGv_reg res, 905eaa3783bSRichard Henderson TCGv_reg in1, TCGv_reg in2, TCGv_reg sv) 906b2167459SRichard Henderson { 907b2167459SRichard Henderson DisasCond cond; 908b2167459SRichard Henderson 909b2167459SRichard Henderson switch (cf >> 1) { 910b2167459SRichard Henderson case 1: /* = / <> */ 911b2167459SRichard Henderson cond = cond_make(TCG_COND_EQ, in1, in2); 912b2167459SRichard Henderson break; 913b2167459SRichard Henderson case 2: /* < / >= */ 914b2167459SRichard Henderson cond = cond_make(TCG_COND_LT, in1, in2); 915b2167459SRichard Henderson break; 916b2167459SRichard Henderson case 3: /* <= / > */ 917b2167459SRichard Henderson cond = cond_make(TCG_COND_LE, in1, in2); 918b2167459SRichard Henderson break; 919b2167459SRichard Henderson case 4: /* << / >>= */ 920b2167459SRichard Henderson cond = cond_make(TCG_COND_LTU, in1, in2); 921b2167459SRichard Henderson break; 922b2167459SRichard Henderson case 5: /* <<= / >> */ 923b2167459SRichard Henderson cond = cond_make(TCG_COND_LEU, in1, in2); 924b2167459SRichard Henderson break; 925b2167459SRichard Henderson default: 926b47a4a02SSven Schnelle return do_cond(cf, res, NULL, sv); 927b2167459SRichard Henderson } 928b2167459SRichard Henderson if (cf & 1) { 929b2167459SRichard Henderson cond.c = tcg_invert_cond(cond.c); 930b2167459SRichard Henderson } 931b2167459SRichard Henderson 932b2167459SRichard Henderson return cond; 933b2167459SRichard Henderson } 934b2167459SRichard Henderson 935df0232feSRichard Henderson /* 936df0232feSRichard Henderson * Similar, but for logicals, where the carry and overflow bits are not 937df0232feSRichard Henderson * computed, and use of them is undefined. 938df0232feSRichard Henderson * 939df0232feSRichard Henderson * Undefined or not, hardware does not trap. It seems reasonable to 940df0232feSRichard Henderson * assume hardware treats cases c={4,5,6} as if C=0 & V=0, since that's 941df0232feSRichard Henderson * how cases c={2,3} are treated. 942df0232feSRichard Henderson */ 943b2167459SRichard Henderson 944eaa3783bSRichard Henderson static DisasCond do_log_cond(unsigned cf, TCGv_reg res) 945b2167459SRichard Henderson { 946df0232feSRichard Henderson switch (cf) { 947df0232feSRichard Henderson case 0: /* never */ 948df0232feSRichard Henderson case 9: /* undef, C */ 949df0232feSRichard Henderson case 11: /* undef, C & !Z */ 950df0232feSRichard Henderson case 12: /* undef, V */ 951df0232feSRichard Henderson return cond_make_f(); 952df0232feSRichard Henderson 953df0232feSRichard Henderson case 1: /* true */ 954df0232feSRichard Henderson case 8: /* undef, !C */ 955df0232feSRichard Henderson case 10: /* undef, !C | Z */ 956df0232feSRichard Henderson case 13: /* undef, !V */ 957df0232feSRichard Henderson return cond_make_t(); 958df0232feSRichard Henderson 959df0232feSRichard Henderson case 2: /* == */ 960df0232feSRichard Henderson return cond_make_0(TCG_COND_EQ, res); 961df0232feSRichard Henderson case 3: /* <> */ 962df0232feSRichard Henderson return cond_make_0(TCG_COND_NE, res); 963df0232feSRichard Henderson case 4: /* < */ 964df0232feSRichard Henderson return cond_make_0(TCG_COND_LT, res); 965df0232feSRichard Henderson case 5: /* >= */ 966df0232feSRichard Henderson return cond_make_0(TCG_COND_GE, res); 967df0232feSRichard Henderson case 6: /* <= */ 968df0232feSRichard Henderson return cond_make_0(TCG_COND_LE, res); 969df0232feSRichard Henderson case 7: /* > */ 970df0232feSRichard Henderson return cond_make_0(TCG_COND_GT, res); 971df0232feSRichard Henderson 972df0232feSRichard Henderson case 14: /* OD */ 973df0232feSRichard Henderson case 15: /* EV */ 974df0232feSRichard Henderson return do_cond(cf, res, NULL, NULL); 975df0232feSRichard Henderson 976df0232feSRichard Henderson default: 977df0232feSRichard Henderson g_assert_not_reached(); 978b2167459SRichard Henderson } 979b2167459SRichard Henderson } 980b2167459SRichard Henderson 98198cd9ca7SRichard Henderson /* Similar, but for shift/extract/deposit conditions. */ 98298cd9ca7SRichard Henderson 983eaa3783bSRichard Henderson static DisasCond do_sed_cond(unsigned orig, TCGv_reg res) 98498cd9ca7SRichard Henderson { 98598cd9ca7SRichard Henderson unsigned c, f; 98698cd9ca7SRichard Henderson 98798cd9ca7SRichard Henderson /* Convert the compressed condition codes to standard. 98898cd9ca7SRichard Henderson 0-2 are the same as logicals (nv,<,<=), while 3 is OD. 98998cd9ca7SRichard Henderson 4-7 are the reverse of 0-3. */ 99098cd9ca7SRichard Henderson c = orig & 3; 99198cd9ca7SRichard Henderson if (c == 3) { 99298cd9ca7SRichard Henderson c = 7; 99398cd9ca7SRichard Henderson } 99498cd9ca7SRichard Henderson f = (orig & 4) / 4; 99598cd9ca7SRichard Henderson 99698cd9ca7SRichard Henderson return do_log_cond(c * 2 + f, res); 99798cd9ca7SRichard Henderson } 99898cd9ca7SRichard Henderson 999b2167459SRichard Henderson /* Similar, but for unit conditions. */ 1000b2167459SRichard Henderson 1001eaa3783bSRichard Henderson static DisasCond do_unit_cond(unsigned cf, TCGv_reg res, 1002eaa3783bSRichard Henderson TCGv_reg in1, TCGv_reg in2) 1003b2167459SRichard Henderson { 1004b2167459SRichard Henderson DisasCond cond; 1005eaa3783bSRichard Henderson TCGv_reg tmp, cb = NULL; 1006b2167459SRichard Henderson 1007b2167459SRichard Henderson if (cf & 8) { 1008b2167459SRichard Henderson /* Since we want to test lots of carry-out bits all at once, do not 1009b2167459SRichard Henderson * do our normal thing and compute carry-in of bit B+1 since that 1010b2167459SRichard Henderson * leaves us with carry bits spread across two words. 1011b2167459SRichard Henderson */ 1012b2167459SRichard Henderson cb = tcg_temp_new(); 1013b2167459SRichard Henderson tmp = tcg_temp_new(); 1014eaa3783bSRichard Henderson tcg_gen_or_reg(cb, in1, in2); 1015eaa3783bSRichard Henderson tcg_gen_and_reg(tmp, in1, in2); 1016eaa3783bSRichard Henderson tcg_gen_andc_reg(cb, cb, res); 1017eaa3783bSRichard Henderson tcg_gen_or_reg(cb, cb, tmp); 1018b2167459SRichard Henderson } 1019b2167459SRichard Henderson 1020b2167459SRichard Henderson switch (cf >> 1) { 1021b2167459SRichard Henderson case 0: /* never / TR */ 1022b2167459SRichard Henderson case 1: /* undefined */ 1023b2167459SRichard Henderson case 5: /* undefined */ 1024b2167459SRichard Henderson cond = cond_make_f(); 1025b2167459SRichard Henderson break; 1026b2167459SRichard Henderson 1027b2167459SRichard Henderson case 2: /* SBZ / NBZ */ 1028b2167459SRichard Henderson /* See hasless(v,1) from 1029b2167459SRichard Henderson * https://graphics.stanford.edu/~seander/bithacks.html#ZeroInWord 1030b2167459SRichard Henderson */ 1031b2167459SRichard Henderson tmp = tcg_temp_new(); 1032eaa3783bSRichard Henderson tcg_gen_subi_reg(tmp, res, 0x01010101u); 1033eaa3783bSRichard Henderson tcg_gen_andc_reg(tmp, tmp, res); 1034eaa3783bSRichard Henderson tcg_gen_andi_reg(tmp, tmp, 0x80808080u); 1035b2167459SRichard Henderson cond = cond_make_0(TCG_COND_NE, tmp); 1036b2167459SRichard Henderson break; 1037b2167459SRichard Henderson 1038b2167459SRichard Henderson case 3: /* SHZ / NHZ */ 1039b2167459SRichard Henderson tmp = tcg_temp_new(); 1040eaa3783bSRichard Henderson tcg_gen_subi_reg(tmp, res, 0x00010001u); 1041eaa3783bSRichard Henderson tcg_gen_andc_reg(tmp, tmp, res); 1042eaa3783bSRichard Henderson tcg_gen_andi_reg(tmp, tmp, 0x80008000u); 1043b2167459SRichard Henderson cond = cond_make_0(TCG_COND_NE, tmp); 1044b2167459SRichard Henderson break; 1045b2167459SRichard Henderson 1046b2167459SRichard Henderson case 4: /* SDC / NDC */ 1047eaa3783bSRichard Henderson tcg_gen_andi_reg(cb, cb, 0x88888888u); 1048b2167459SRichard Henderson cond = cond_make_0(TCG_COND_NE, cb); 1049b2167459SRichard Henderson break; 1050b2167459SRichard Henderson 1051b2167459SRichard Henderson case 6: /* SBC / NBC */ 1052eaa3783bSRichard Henderson tcg_gen_andi_reg(cb, cb, 0x80808080u); 1053b2167459SRichard Henderson cond = cond_make_0(TCG_COND_NE, cb); 1054b2167459SRichard Henderson break; 1055b2167459SRichard Henderson 1056b2167459SRichard Henderson case 7: /* SHC / NHC */ 1057eaa3783bSRichard Henderson tcg_gen_andi_reg(cb, cb, 0x80008000u); 1058b2167459SRichard Henderson cond = cond_make_0(TCG_COND_NE, cb); 1059b2167459SRichard Henderson break; 1060b2167459SRichard Henderson 1061b2167459SRichard Henderson default: 1062b2167459SRichard Henderson g_assert_not_reached(); 1063b2167459SRichard Henderson } 1064b2167459SRichard Henderson if (cf & 1) { 1065b2167459SRichard Henderson cond.c = tcg_invert_cond(cond.c); 1066b2167459SRichard Henderson } 1067b2167459SRichard Henderson 1068b2167459SRichard Henderson return cond; 1069b2167459SRichard Henderson } 1070b2167459SRichard Henderson 1071b2167459SRichard Henderson /* Compute signed overflow for addition. */ 1072eaa3783bSRichard Henderson static TCGv_reg do_add_sv(DisasContext *ctx, TCGv_reg res, 1073eaa3783bSRichard Henderson TCGv_reg in1, TCGv_reg in2) 1074b2167459SRichard Henderson { 1075eaa3783bSRichard Henderson TCGv_reg sv = get_temp(ctx); 1076eaa3783bSRichard Henderson TCGv_reg tmp = tcg_temp_new(); 1077b2167459SRichard Henderson 1078eaa3783bSRichard Henderson tcg_gen_xor_reg(sv, res, in1); 1079eaa3783bSRichard Henderson tcg_gen_xor_reg(tmp, in1, in2); 1080eaa3783bSRichard Henderson tcg_gen_andc_reg(sv, sv, tmp); 1081b2167459SRichard Henderson 1082b2167459SRichard Henderson return sv; 1083b2167459SRichard Henderson } 1084b2167459SRichard Henderson 1085b2167459SRichard Henderson /* Compute signed overflow for subtraction. */ 1086eaa3783bSRichard Henderson static TCGv_reg do_sub_sv(DisasContext *ctx, TCGv_reg res, 1087eaa3783bSRichard Henderson TCGv_reg in1, TCGv_reg in2) 1088b2167459SRichard Henderson { 1089eaa3783bSRichard Henderson TCGv_reg sv = get_temp(ctx); 1090eaa3783bSRichard Henderson TCGv_reg tmp = tcg_temp_new(); 1091b2167459SRichard Henderson 1092eaa3783bSRichard Henderson tcg_gen_xor_reg(sv, res, in1); 1093eaa3783bSRichard Henderson tcg_gen_xor_reg(tmp, in1, in2); 1094eaa3783bSRichard Henderson tcg_gen_and_reg(sv, sv, tmp); 1095b2167459SRichard Henderson 1096b2167459SRichard Henderson return sv; 1097b2167459SRichard Henderson } 1098b2167459SRichard Henderson 109931234768SRichard Henderson static void do_add(DisasContext *ctx, unsigned rt, TCGv_reg in1, 1100eaa3783bSRichard Henderson TCGv_reg in2, unsigned shift, bool is_l, 1101eaa3783bSRichard Henderson bool is_tsv, bool is_tc, bool is_c, unsigned cf) 1102b2167459SRichard Henderson { 1103eaa3783bSRichard Henderson TCGv_reg dest, cb, cb_msb, sv, tmp; 1104b2167459SRichard Henderson unsigned c = cf >> 1; 1105b2167459SRichard Henderson DisasCond cond; 1106b2167459SRichard Henderson 1107b2167459SRichard Henderson dest = tcg_temp_new(); 1108f764718dSRichard Henderson cb = NULL; 1109f764718dSRichard Henderson cb_msb = NULL; 1110b2167459SRichard Henderson 1111b2167459SRichard Henderson if (shift) { 1112b2167459SRichard Henderson tmp = get_temp(ctx); 1113eaa3783bSRichard Henderson tcg_gen_shli_reg(tmp, in1, shift); 1114b2167459SRichard Henderson in1 = tmp; 1115b2167459SRichard Henderson } 1116b2167459SRichard Henderson 1117b47a4a02SSven Schnelle if (!is_l || cond_need_cb(c)) { 111829dd6f64SRichard Henderson TCGv_reg zero = tcg_constant_reg(0); 1119b2167459SRichard Henderson cb_msb = get_temp(ctx); 1120eaa3783bSRichard Henderson tcg_gen_add2_reg(dest, cb_msb, in1, zero, in2, zero); 1121b2167459SRichard Henderson if (is_c) { 1122eaa3783bSRichard Henderson tcg_gen_add2_reg(dest, cb_msb, dest, cb_msb, cpu_psw_cb_msb, zero); 1123b2167459SRichard Henderson } 1124b2167459SRichard Henderson if (!is_l) { 1125b2167459SRichard Henderson cb = get_temp(ctx); 1126eaa3783bSRichard Henderson tcg_gen_xor_reg(cb, in1, in2); 1127eaa3783bSRichard Henderson tcg_gen_xor_reg(cb, cb, dest); 1128b2167459SRichard Henderson } 1129b2167459SRichard Henderson } else { 1130eaa3783bSRichard Henderson tcg_gen_add_reg(dest, in1, in2); 1131b2167459SRichard Henderson if (is_c) { 1132eaa3783bSRichard Henderson tcg_gen_add_reg(dest, dest, cpu_psw_cb_msb); 1133b2167459SRichard Henderson } 1134b2167459SRichard Henderson } 1135b2167459SRichard Henderson 1136b2167459SRichard Henderson /* Compute signed overflow if required. */ 1137f764718dSRichard Henderson sv = NULL; 1138b47a4a02SSven Schnelle if (is_tsv || cond_need_sv(c)) { 1139b2167459SRichard Henderson sv = do_add_sv(ctx, dest, in1, in2); 1140b2167459SRichard Henderson if (is_tsv) { 1141b2167459SRichard Henderson /* ??? Need to include overflow from shift. */ 1142b2167459SRichard Henderson gen_helper_tsv(cpu_env, sv); 1143b2167459SRichard Henderson } 1144b2167459SRichard Henderson } 1145b2167459SRichard Henderson 1146b2167459SRichard Henderson /* Emit any conditional trap before any writeback. */ 1147b2167459SRichard Henderson cond = do_cond(cf, dest, cb_msb, sv); 1148b2167459SRichard Henderson if (is_tc) { 1149b2167459SRichard Henderson tmp = tcg_temp_new(); 1150eaa3783bSRichard Henderson tcg_gen_setcond_reg(cond.c, tmp, cond.a0, cond.a1); 1151b2167459SRichard Henderson gen_helper_tcond(cpu_env, tmp); 1152b2167459SRichard Henderson } 1153b2167459SRichard Henderson 1154b2167459SRichard Henderson /* Write back the result. */ 1155b2167459SRichard Henderson if (!is_l) { 1156b2167459SRichard Henderson save_or_nullify(ctx, cpu_psw_cb, cb); 1157b2167459SRichard Henderson save_or_nullify(ctx, cpu_psw_cb_msb, cb_msb); 1158b2167459SRichard Henderson } 1159b2167459SRichard Henderson save_gpr(ctx, rt, dest); 1160b2167459SRichard Henderson 1161b2167459SRichard Henderson /* Install the new nullification. */ 1162b2167459SRichard Henderson cond_free(&ctx->null_cond); 1163b2167459SRichard Henderson ctx->null_cond = cond; 1164b2167459SRichard Henderson } 1165b2167459SRichard Henderson 11660c982a28SRichard Henderson static bool do_add_reg(DisasContext *ctx, arg_rrr_cf_sh *a, 11670c982a28SRichard Henderson bool is_l, bool is_tsv, bool is_tc, bool is_c) 11680c982a28SRichard Henderson { 11690c982a28SRichard Henderson TCGv_reg tcg_r1, tcg_r2; 11700c982a28SRichard Henderson 11710c982a28SRichard Henderson if (a->cf) { 11720c982a28SRichard Henderson nullify_over(ctx); 11730c982a28SRichard Henderson } 11740c982a28SRichard Henderson tcg_r1 = load_gpr(ctx, a->r1); 11750c982a28SRichard Henderson tcg_r2 = load_gpr(ctx, a->r2); 11760c982a28SRichard Henderson do_add(ctx, a->t, tcg_r1, tcg_r2, a->sh, is_l, is_tsv, is_tc, is_c, a->cf); 11770c982a28SRichard Henderson return nullify_end(ctx); 11780c982a28SRichard Henderson } 11790c982a28SRichard Henderson 11800588e061SRichard Henderson static bool do_add_imm(DisasContext *ctx, arg_rri_cf *a, 11810588e061SRichard Henderson bool is_tsv, bool is_tc) 11820588e061SRichard Henderson { 11830588e061SRichard Henderson TCGv_reg tcg_im, tcg_r2; 11840588e061SRichard Henderson 11850588e061SRichard Henderson if (a->cf) { 11860588e061SRichard Henderson nullify_over(ctx); 11870588e061SRichard Henderson } 11880588e061SRichard Henderson tcg_im = load_const(ctx, a->i); 11890588e061SRichard Henderson tcg_r2 = load_gpr(ctx, a->r); 11900588e061SRichard Henderson do_add(ctx, a->t, tcg_im, tcg_r2, 0, 0, is_tsv, is_tc, 0, a->cf); 11910588e061SRichard Henderson return nullify_end(ctx); 11920588e061SRichard Henderson } 11930588e061SRichard Henderson 119431234768SRichard Henderson static void do_sub(DisasContext *ctx, unsigned rt, TCGv_reg in1, 1195eaa3783bSRichard Henderson TCGv_reg in2, bool is_tsv, bool is_b, 1196eaa3783bSRichard Henderson bool is_tc, unsigned cf) 1197b2167459SRichard Henderson { 1198eaa3783bSRichard Henderson TCGv_reg dest, sv, cb, cb_msb, zero, tmp; 1199b2167459SRichard Henderson unsigned c = cf >> 1; 1200b2167459SRichard Henderson DisasCond cond; 1201b2167459SRichard Henderson 1202b2167459SRichard Henderson dest = tcg_temp_new(); 1203b2167459SRichard Henderson cb = tcg_temp_new(); 1204b2167459SRichard Henderson cb_msb = tcg_temp_new(); 1205b2167459SRichard Henderson 120629dd6f64SRichard Henderson zero = tcg_constant_reg(0); 1207b2167459SRichard Henderson if (is_b) { 1208b2167459SRichard Henderson /* DEST,C = IN1 + ~IN2 + C. */ 1209eaa3783bSRichard Henderson tcg_gen_not_reg(cb, in2); 1210eaa3783bSRichard Henderson tcg_gen_add2_reg(dest, cb_msb, in1, zero, cpu_psw_cb_msb, zero); 1211eaa3783bSRichard Henderson tcg_gen_add2_reg(dest, cb_msb, dest, cb_msb, cb, zero); 1212eaa3783bSRichard Henderson tcg_gen_xor_reg(cb, cb, in1); 1213eaa3783bSRichard Henderson tcg_gen_xor_reg(cb, cb, dest); 1214b2167459SRichard Henderson } else { 1215b2167459SRichard Henderson /* DEST,C = IN1 + ~IN2 + 1. We can produce the same result in fewer 1216b2167459SRichard Henderson operations by seeding the high word with 1 and subtracting. */ 1217eaa3783bSRichard Henderson tcg_gen_movi_reg(cb_msb, 1); 1218eaa3783bSRichard Henderson tcg_gen_sub2_reg(dest, cb_msb, in1, cb_msb, in2, zero); 1219eaa3783bSRichard Henderson tcg_gen_eqv_reg(cb, in1, in2); 1220eaa3783bSRichard Henderson tcg_gen_xor_reg(cb, cb, dest); 1221b2167459SRichard Henderson } 1222b2167459SRichard Henderson 1223b2167459SRichard Henderson /* Compute signed overflow if required. */ 1224f764718dSRichard Henderson sv = NULL; 1225b47a4a02SSven Schnelle if (is_tsv || cond_need_sv(c)) { 1226b2167459SRichard Henderson sv = do_sub_sv(ctx, dest, in1, in2); 1227b2167459SRichard Henderson if (is_tsv) { 1228b2167459SRichard Henderson gen_helper_tsv(cpu_env, sv); 1229b2167459SRichard Henderson } 1230b2167459SRichard Henderson } 1231b2167459SRichard Henderson 1232b2167459SRichard Henderson /* Compute the condition. We cannot use the special case for borrow. */ 1233b2167459SRichard Henderson if (!is_b) { 1234b2167459SRichard Henderson cond = do_sub_cond(cf, dest, in1, in2, sv); 1235b2167459SRichard Henderson } else { 1236b2167459SRichard Henderson cond = do_cond(cf, dest, cb_msb, sv); 1237b2167459SRichard Henderson } 1238b2167459SRichard Henderson 1239b2167459SRichard Henderson /* Emit any conditional trap before any writeback. */ 1240b2167459SRichard Henderson if (is_tc) { 1241b2167459SRichard Henderson tmp = tcg_temp_new(); 1242eaa3783bSRichard Henderson tcg_gen_setcond_reg(cond.c, tmp, cond.a0, cond.a1); 1243b2167459SRichard Henderson gen_helper_tcond(cpu_env, tmp); 1244b2167459SRichard Henderson } 1245b2167459SRichard Henderson 1246b2167459SRichard Henderson /* Write back the result. */ 1247b2167459SRichard Henderson save_or_nullify(ctx, cpu_psw_cb, cb); 1248b2167459SRichard Henderson save_or_nullify(ctx, cpu_psw_cb_msb, cb_msb); 1249b2167459SRichard Henderson save_gpr(ctx, rt, dest); 1250b2167459SRichard Henderson 1251b2167459SRichard Henderson /* Install the new nullification. */ 1252b2167459SRichard Henderson cond_free(&ctx->null_cond); 1253b2167459SRichard Henderson ctx->null_cond = cond; 1254b2167459SRichard Henderson } 1255b2167459SRichard Henderson 12560c982a28SRichard Henderson static bool do_sub_reg(DisasContext *ctx, arg_rrr_cf *a, 12570c982a28SRichard Henderson bool is_tsv, bool is_b, bool is_tc) 12580c982a28SRichard Henderson { 12590c982a28SRichard Henderson TCGv_reg tcg_r1, tcg_r2; 12600c982a28SRichard Henderson 12610c982a28SRichard Henderson if (a->cf) { 12620c982a28SRichard Henderson nullify_over(ctx); 12630c982a28SRichard Henderson } 12640c982a28SRichard Henderson tcg_r1 = load_gpr(ctx, a->r1); 12650c982a28SRichard Henderson tcg_r2 = load_gpr(ctx, a->r2); 12660c982a28SRichard Henderson do_sub(ctx, a->t, tcg_r1, tcg_r2, is_tsv, is_b, is_tc, a->cf); 12670c982a28SRichard Henderson return nullify_end(ctx); 12680c982a28SRichard Henderson } 12690c982a28SRichard Henderson 12700588e061SRichard Henderson static bool do_sub_imm(DisasContext *ctx, arg_rri_cf *a, bool is_tsv) 12710588e061SRichard Henderson { 12720588e061SRichard Henderson TCGv_reg tcg_im, tcg_r2; 12730588e061SRichard Henderson 12740588e061SRichard Henderson if (a->cf) { 12750588e061SRichard Henderson nullify_over(ctx); 12760588e061SRichard Henderson } 12770588e061SRichard Henderson tcg_im = load_const(ctx, a->i); 12780588e061SRichard Henderson tcg_r2 = load_gpr(ctx, a->r); 12790588e061SRichard Henderson do_sub(ctx, a->t, tcg_im, tcg_r2, is_tsv, 0, 0, a->cf); 12800588e061SRichard Henderson return nullify_end(ctx); 12810588e061SRichard Henderson } 12820588e061SRichard Henderson 128331234768SRichard Henderson static void do_cmpclr(DisasContext *ctx, unsigned rt, TCGv_reg in1, 1284eaa3783bSRichard Henderson TCGv_reg in2, unsigned cf) 1285b2167459SRichard Henderson { 1286eaa3783bSRichard Henderson TCGv_reg dest, sv; 1287b2167459SRichard Henderson DisasCond cond; 1288b2167459SRichard Henderson 1289b2167459SRichard Henderson dest = tcg_temp_new(); 1290eaa3783bSRichard Henderson tcg_gen_sub_reg(dest, in1, in2); 1291b2167459SRichard Henderson 1292b2167459SRichard Henderson /* Compute signed overflow if required. */ 1293f764718dSRichard Henderson sv = NULL; 1294b47a4a02SSven Schnelle if (cond_need_sv(cf >> 1)) { 1295b2167459SRichard Henderson sv = do_sub_sv(ctx, dest, in1, in2); 1296b2167459SRichard Henderson } 1297b2167459SRichard Henderson 1298b2167459SRichard Henderson /* Form the condition for the compare. */ 1299b2167459SRichard Henderson cond = do_sub_cond(cf, dest, in1, in2, sv); 1300b2167459SRichard Henderson 1301b2167459SRichard Henderson /* Clear. */ 1302eaa3783bSRichard Henderson tcg_gen_movi_reg(dest, 0); 1303b2167459SRichard Henderson save_gpr(ctx, rt, dest); 1304b2167459SRichard Henderson 1305b2167459SRichard Henderson /* Install the new nullification. */ 1306b2167459SRichard Henderson cond_free(&ctx->null_cond); 1307b2167459SRichard Henderson ctx->null_cond = cond; 1308b2167459SRichard Henderson } 1309b2167459SRichard Henderson 131031234768SRichard Henderson static void do_log(DisasContext *ctx, unsigned rt, TCGv_reg in1, 1311eaa3783bSRichard Henderson TCGv_reg in2, unsigned cf, 1312eaa3783bSRichard Henderson void (*fn)(TCGv_reg, TCGv_reg, TCGv_reg)) 1313b2167459SRichard Henderson { 1314eaa3783bSRichard Henderson TCGv_reg dest = dest_gpr(ctx, rt); 1315b2167459SRichard Henderson 1316b2167459SRichard Henderson /* Perform the operation, and writeback. */ 1317b2167459SRichard Henderson fn(dest, in1, in2); 1318b2167459SRichard Henderson save_gpr(ctx, rt, dest); 1319b2167459SRichard Henderson 1320b2167459SRichard Henderson /* Install the new nullification. */ 1321b2167459SRichard Henderson cond_free(&ctx->null_cond); 1322b2167459SRichard Henderson if (cf) { 1323b2167459SRichard Henderson ctx->null_cond = do_log_cond(cf, dest); 1324b2167459SRichard Henderson } 1325b2167459SRichard Henderson } 1326b2167459SRichard Henderson 13270c982a28SRichard Henderson static bool do_log_reg(DisasContext *ctx, arg_rrr_cf *a, 13280c982a28SRichard Henderson void (*fn)(TCGv_reg, TCGv_reg, TCGv_reg)) 13290c982a28SRichard Henderson { 13300c982a28SRichard Henderson TCGv_reg tcg_r1, tcg_r2; 13310c982a28SRichard Henderson 13320c982a28SRichard Henderson if (a->cf) { 13330c982a28SRichard Henderson nullify_over(ctx); 13340c982a28SRichard Henderson } 13350c982a28SRichard Henderson tcg_r1 = load_gpr(ctx, a->r1); 13360c982a28SRichard Henderson tcg_r2 = load_gpr(ctx, a->r2); 13370c982a28SRichard Henderson do_log(ctx, a->t, tcg_r1, tcg_r2, a->cf, fn); 13380c982a28SRichard Henderson return nullify_end(ctx); 13390c982a28SRichard Henderson } 13400c982a28SRichard Henderson 134131234768SRichard Henderson static void do_unit(DisasContext *ctx, unsigned rt, TCGv_reg in1, 1342eaa3783bSRichard Henderson TCGv_reg in2, unsigned cf, bool is_tc, 1343eaa3783bSRichard Henderson void (*fn)(TCGv_reg, TCGv_reg, TCGv_reg)) 1344b2167459SRichard Henderson { 1345eaa3783bSRichard Henderson TCGv_reg dest; 1346b2167459SRichard Henderson DisasCond cond; 1347b2167459SRichard Henderson 1348b2167459SRichard Henderson if (cf == 0) { 1349b2167459SRichard Henderson dest = dest_gpr(ctx, rt); 1350b2167459SRichard Henderson fn(dest, in1, in2); 1351b2167459SRichard Henderson save_gpr(ctx, rt, dest); 1352b2167459SRichard Henderson cond_free(&ctx->null_cond); 1353b2167459SRichard Henderson } else { 1354b2167459SRichard Henderson dest = tcg_temp_new(); 1355b2167459SRichard Henderson fn(dest, in1, in2); 1356b2167459SRichard Henderson 1357b2167459SRichard Henderson cond = do_unit_cond(cf, dest, in1, in2); 1358b2167459SRichard Henderson 1359b2167459SRichard Henderson if (is_tc) { 1360eaa3783bSRichard Henderson TCGv_reg tmp = tcg_temp_new(); 1361eaa3783bSRichard Henderson tcg_gen_setcond_reg(cond.c, tmp, cond.a0, cond.a1); 1362b2167459SRichard Henderson gen_helper_tcond(cpu_env, tmp); 1363b2167459SRichard Henderson } 1364b2167459SRichard Henderson save_gpr(ctx, rt, dest); 1365b2167459SRichard Henderson 1366b2167459SRichard Henderson cond_free(&ctx->null_cond); 1367b2167459SRichard Henderson ctx->null_cond = cond; 1368b2167459SRichard Henderson } 1369b2167459SRichard Henderson } 1370b2167459SRichard Henderson 137186f8d05fSRichard Henderson #ifndef CONFIG_USER_ONLY 13728d6ae7fbSRichard Henderson /* The "normal" usage is SP >= 0, wherein SP == 0 selects the space 13738d6ae7fbSRichard Henderson from the top 2 bits of the base register. There are a few system 13748d6ae7fbSRichard Henderson instructions that have a 3-bit space specifier, for which SR0 is 13758d6ae7fbSRichard Henderson not special. To handle this, pass ~SP. */ 137686f8d05fSRichard Henderson static TCGv_i64 space_select(DisasContext *ctx, int sp, TCGv_reg base) 137786f8d05fSRichard Henderson { 137886f8d05fSRichard Henderson TCGv_ptr ptr; 137986f8d05fSRichard Henderson TCGv_reg tmp; 138086f8d05fSRichard Henderson TCGv_i64 spc; 138186f8d05fSRichard Henderson 138286f8d05fSRichard Henderson if (sp != 0) { 13838d6ae7fbSRichard Henderson if (sp < 0) { 13848d6ae7fbSRichard Henderson sp = ~sp; 13858d6ae7fbSRichard Henderson } 13868d6ae7fbSRichard Henderson spc = get_temp_tl(ctx); 13878d6ae7fbSRichard Henderson load_spr(ctx, spc, sp); 13888d6ae7fbSRichard Henderson return spc; 138986f8d05fSRichard Henderson } 1390494737b7SRichard Henderson if (ctx->tb_flags & TB_FLAG_SR_SAME) { 1391494737b7SRichard Henderson return cpu_srH; 1392494737b7SRichard Henderson } 139386f8d05fSRichard Henderson 139486f8d05fSRichard Henderson ptr = tcg_temp_new_ptr(); 139586f8d05fSRichard Henderson tmp = tcg_temp_new(); 139686f8d05fSRichard Henderson spc = get_temp_tl(ctx); 139786f8d05fSRichard Henderson 139886f8d05fSRichard Henderson tcg_gen_shri_reg(tmp, base, TARGET_REGISTER_BITS - 5); 139986f8d05fSRichard Henderson tcg_gen_andi_reg(tmp, tmp, 030); 140086f8d05fSRichard Henderson tcg_gen_trunc_reg_ptr(ptr, tmp); 140186f8d05fSRichard Henderson 140286f8d05fSRichard Henderson tcg_gen_add_ptr(ptr, ptr, cpu_env); 140386f8d05fSRichard Henderson tcg_gen_ld_i64(spc, ptr, offsetof(CPUHPPAState, sr[4])); 140486f8d05fSRichard Henderson 140586f8d05fSRichard Henderson return spc; 140686f8d05fSRichard Henderson } 140786f8d05fSRichard Henderson #endif 140886f8d05fSRichard Henderson 140986f8d05fSRichard Henderson static void form_gva(DisasContext *ctx, TCGv_tl *pgva, TCGv_reg *pofs, 141086f8d05fSRichard Henderson unsigned rb, unsigned rx, int scale, target_sreg disp, 141186f8d05fSRichard Henderson unsigned sp, int modify, bool is_phys) 141286f8d05fSRichard Henderson { 141386f8d05fSRichard Henderson TCGv_reg base = load_gpr(ctx, rb); 141486f8d05fSRichard Henderson TCGv_reg ofs; 141586f8d05fSRichard Henderson 141686f8d05fSRichard Henderson /* Note that RX is mutually exclusive with DISP. */ 141786f8d05fSRichard Henderson if (rx) { 141886f8d05fSRichard Henderson ofs = get_temp(ctx); 141986f8d05fSRichard Henderson tcg_gen_shli_reg(ofs, cpu_gr[rx], scale); 142086f8d05fSRichard Henderson tcg_gen_add_reg(ofs, ofs, base); 142186f8d05fSRichard Henderson } else if (disp || modify) { 142286f8d05fSRichard Henderson ofs = get_temp(ctx); 142386f8d05fSRichard Henderson tcg_gen_addi_reg(ofs, base, disp); 142486f8d05fSRichard Henderson } else { 142586f8d05fSRichard Henderson ofs = base; 142686f8d05fSRichard Henderson } 142786f8d05fSRichard Henderson 142886f8d05fSRichard Henderson *pofs = ofs; 142986f8d05fSRichard Henderson #ifdef CONFIG_USER_ONLY 143086f8d05fSRichard Henderson *pgva = (modify <= 0 ? ofs : base); 143186f8d05fSRichard Henderson #else 143286f8d05fSRichard Henderson TCGv_tl addr = get_temp_tl(ctx); 143386f8d05fSRichard Henderson tcg_gen_extu_reg_tl(addr, modify <= 0 ? ofs : base); 1434494737b7SRichard Henderson if (ctx->tb_flags & PSW_W) { 143586f8d05fSRichard Henderson tcg_gen_andi_tl(addr, addr, 0x3fffffffffffffffull); 143686f8d05fSRichard Henderson } 143786f8d05fSRichard Henderson if (!is_phys) { 143886f8d05fSRichard Henderson tcg_gen_or_tl(addr, addr, space_select(ctx, sp, base)); 143986f8d05fSRichard Henderson } 144086f8d05fSRichard Henderson *pgva = addr; 144186f8d05fSRichard Henderson #endif 144286f8d05fSRichard Henderson } 144386f8d05fSRichard Henderson 144496d6407fSRichard Henderson /* Emit a memory load. The modify parameter should be 144596d6407fSRichard Henderson * < 0 for pre-modify, 144696d6407fSRichard Henderson * > 0 for post-modify, 144796d6407fSRichard Henderson * = 0 for no base register update. 144896d6407fSRichard Henderson */ 144996d6407fSRichard Henderson static void do_load_32(DisasContext *ctx, TCGv_i32 dest, unsigned rb, 1450eaa3783bSRichard Henderson unsigned rx, int scale, target_sreg disp, 145114776ab5STony Nguyen unsigned sp, int modify, MemOp mop) 145296d6407fSRichard Henderson { 145386f8d05fSRichard Henderson TCGv_reg ofs; 145486f8d05fSRichard Henderson TCGv_tl addr; 145596d6407fSRichard Henderson 145696d6407fSRichard Henderson /* Caller uses nullify_over/nullify_end. */ 145796d6407fSRichard Henderson assert(ctx->null_cond.c == TCG_COND_NEVER); 145896d6407fSRichard Henderson 145986f8d05fSRichard Henderson form_gva(ctx, &addr, &ofs, rb, rx, scale, disp, sp, modify, 146086f8d05fSRichard Henderson ctx->mmu_idx == MMU_PHYS_IDX); 1461217d1a5eSRichard Henderson tcg_gen_qemu_ld_reg(dest, addr, ctx->mmu_idx, mop | UNALIGN(ctx)); 146286f8d05fSRichard Henderson if (modify) { 146386f8d05fSRichard Henderson save_gpr(ctx, rb, ofs); 146496d6407fSRichard Henderson } 146596d6407fSRichard Henderson } 146696d6407fSRichard Henderson 146796d6407fSRichard Henderson static void do_load_64(DisasContext *ctx, TCGv_i64 dest, unsigned rb, 1468eaa3783bSRichard Henderson unsigned rx, int scale, target_sreg disp, 146914776ab5STony Nguyen unsigned sp, int modify, MemOp mop) 147096d6407fSRichard Henderson { 147186f8d05fSRichard Henderson TCGv_reg ofs; 147286f8d05fSRichard Henderson TCGv_tl addr; 147396d6407fSRichard Henderson 147496d6407fSRichard Henderson /* Caller uses nullify_over/nullify_end. */ 147596d6407fSRichard Henderson assert(ctx->null_cond.c == TCG_COND_NEVER); 147696d6407fSRichard Henderson 147786f8d05fSRichard Henderson form_gva(ctx, &addr, &ofs, rb, rx, scale, disp, sp, modify, 147886f8d05fSRichard Henderson ctx->mmu_idx == MMU_PHYS_IDX); 1479217d1a5eSRichard Henderson tcg_gen_qemu_ld_i64(dest, addr, ctx->mmu_idx, mop | UNALIGN(ctx)); 148086f8d05fSRichard Henderson if (modify) { 148186f8d05fSRichard Henderson save_gpr(ctx, rb, ofs); 148296d6407fSRichard Henderson } 148396d6407fSRichard Henderson } 148496d6407fSRichard Henderson 148596d6407fSRichard Henderson static void do_store_32(DisasContext *ctx, TCGv_i32 src, unsigned rb, 1486eaa3783bSRichard Henderson unsigned rx, int scale, target_sreg disp, 148714776ab5STony Nguyen unsigned sp, int modify, MemOp mop) 148896d6407fSRichard Henderson { 148986f8d05fSRichard Henderson TCGv_reg ofs; 149086f8d05fSRichard Henderson TCGv_tl addr; 149196d6407fSRichard Henderson 149296d6407fSRichard Henderson /* Caller uses nullify_over/nullify_end. */ 149396d6407fSRichard Henderson assert(ctx->null_cond.c == TCG_COND_NEVER); 149496d6407fSRichard Henderson 149586f8d05fSRichard Henderson form_gva(ctx, &addr, &ofs, rb, rx, scale, disp, sp, modify, 149686f8d05fSRichard Henderson ctx->mmu_idx == MMU_PHYS_IDX); 1497217d1a5eSRichard Henderson tcg_gen_qemu_st_i32(src, addr, ctx->mmu_idx, mop | UNALIGN(ctx)); 149886f8d05fSRichard Henderson if (modify) { 149986f8d05fSRichard Henderson save_gpr(ctx, rb, ofs); 150096d6407fSRichard Henderson } 150196d6407fSRichard Henderson } 150296d6407fSRichard Henderson 150396d6407fSRichard Henderson static void do_store_64(DisasContext *ctx, TCGv_i64 src, unsigned rb, 1504eaa3783bSRichard Henderson unsigned rx, int scale, target_sreg disp, 150514776ab5STony Nguyen unsigned sp, int modify, MemOp mop) 150696d6407fSRichard Henderson { 150786f8d05fSRichard Henderson TCGv_reg ofs; 150886f8d05fSRichard Henderson TCGv_tl addr; 150996d6407fSRichard Henderson 151096d6407fSRichard Henderson /* Caller uses nullify_over/nullify_end. */ 151196d6407fSRichard Henderson assert(ctx->null_cond.c == TCG_COND_NEVER); 151296d6407fSRichard Henderson 151386f8d05fSRichard Henderson form_gva(ctx, &addr, &ofs, rb, rx, scale, disp, sp, modify, 151486f8d05fSRichard Henderson ctx->mmu_idx == MMU_PHYS_IDX); 1515217d1a5eSRichard Henderson tcg_gen_qemu_st_i64(src, addr, ctx->mmu_idx, mop | UNALIGN(ctx)); 151686f8d05fSRichard Henderson if (modify) { 151786f8d05fSRichard Henderson save_gpr(ctx, rb, ofs); 151896d6407fSRichard Henderson } 151996d6407fSRichard Henderson } 152096d6407fSRichard Henderson 1521eaa3783bSRichard Henderson #if TARGET_REGISTER_BITS == 64 1522eaa3783bSRichard Henderson #define do_load_reg do_load_64 1523eaa3783bSRichard Henderson #define do_store_reg do_store_64 152496d6407fSRichard Henderson #else 1525eaa3783bSRichard Henderson #define do_load_reg do_load_32 1526eaa3783bSRichard Henderson #define do_store_reg do_store_32 152796d6407fSRichard Henderson #endif 152896d6407fSRichard Henderson 15291cd012a5SRichard Henderson static bool do_load(DisasContext *ctx, unsigned rt, unsigned rb, 1530eaa3783bSRichard Henderson unsigned rx, int scale, target_sreg disp, 153114776ab5STony Nguyen unsigned sp, int modify, MemOp mop) 153296d6407fSRichard Henderson { 1533eaa3783bSRichard Henderson TCGv_reg dest; 153496d6407fSRichard Henderson 153596d6407fSRichard Henderson nullify_over(ctx); 153696d6407fSRichard Henderson 153796d6407fSRichard Henderson if (modify == 0) { 153896d6407fSRichard Henderson /* No base register update. */ 153996d6407fSRichard Henderson dest = dest_gpr(ctx, rt); 154096d6407fSRichard Henderson } else { 154196d6407fSRichard Henderson /* Make sure if RT == RB, we see the result of the load. */ 154296d6407fSRichard Henderson dest = get_temp(ctx); 154396d6407fSRichard Henderson } 154486f8d05fSRichard Henderson do_load_reg(ctx, dest, rb, rx, scale, disp, sp, modify, mop); 154596d6407fSRichard Henderson save_gpr(ctx, rt, dest); 154696d6407fSRichard Henderson 15471cd012a5SRichard Henderson return nullify_end(ctx); 154896d6407fSRichard Henderson } 154996d6407fSRichard Henderson 1550740038d7SRichard Henderson static bool do_floadw(DisasContext *ctx, unsigned rt, unsigned rb, 1551eaa3783bSRichard Henderson unsigned rx, int scale, target_sreg disp, 155286f8d05fSRichard Henderson unsigned sp, int modify) 155396d6407fSRichard Henderson { 155496d6407fSRichard Henderson TCGv_i32 tmp; 155596d6407fSRichard Henderson 155696d6407fSRichard Henderson nullify_over(ctx); 155796d6407fSRichard Henderson 155896d6407fSRichard Henderson tmp = tcg_temp_new_i32(); 155986f8d05fSRichard Henderson do_load_32(ctx, tmp, rb, rx, scale, disp, sp, modify, MO_TEUL); 156096d6407fSRichard Henderson save_frw_i32(rt, tmp); 156196d6407fSRichard Henderson 156296d6407fSRichard Henderson if (rt == 0) { 156396d6407fSRichard Henderson gen_helper_loaded_fr0(cpu_env); 156496d6407fSRichard Henderson } 156596d6407fSRichard Henderson 1566740038d7SRichard Henderson return nullify_end(ctx); 156796d6407fSRichard Henderson } 156896d6407fSRichard Henderson 1569740038d7SRichard Henderson static bool trans_fldw(DisasContext *ctx, arg_ldst *a) 1570740038d7SRichard Henderson { 1571740038d7SRichard Henderson return do_floadw(ctx, a->t, a->b, a->x, a->scale ? 2 : 0, 1572740038d7SRichard Henderson a->disp, a->sp, a->m); 1573740038d7SRichard Henderson } 1574740038d7SRichard Henderson 1575740038d7SRichard Henderson static bool do_floadd(DisasContext *ctx, unsigned rt, unsigned rb, 1576eaa3783bSRichard Henderson unsigned rx, int scale, target_sreg disp, 157786f8d05fSRichard Henderson unsigned sp, int modify) 157896d6407fSRichard Henderson { 157996d6407fSRichard Henderson TCGv_i64 tmp; 158096d6407fSRichard Henderson 158196d6407fSRichard Henderson nullify_over(ctx); 158296d6407fSRichard Henderson 158396d6407fSRichard Henderson tmp = tcg_temp_new_i64(); 1584fc313c64SFrédéric Pétrot do_load_64(ctx, tmp, rb, rx, scale, disp, sp, modify, MO_TEUQ); 158596d6407fSRichard Henderson save_frd(rt, tmp); 158696d6407fSRichard Henderson 158796d6407fSRichard Henderson if (rt == 0) { 158896d6407fSRichard Henderson gen_helper_loaded_fr0(cpu_env); 158996d6407fSRichard Henderson } 159096d6407fSRichard Henderson 1591740038d7SRichard Henderson return nullify_end(ctx); 1592740038d7SRichard Henderson } 1593740038d7SRichard Henderson 1594740038d7SRichard Henderson static bool trans_fldd(DisasContext *ctx, arg_ldst *a) 1595740038d7SRichard Henderson { 1596740038d7SRichard Henderson return do_floadd(ctx, a->t, a->b, a->x, a->scale ? 3 : 0, 1597740038d7SRichard Henderson a->disp, a->sp, a->m); 159896d6407fSRichard Henderson } 159996d6407fSRichard Henderson 16001cd012a5SRichard Henderson static bool do_store(DisasContext *ctx, unsigned rt, unsigned rb, 160186f8d05fSRichard Henderson target_sreg disp, unsigned sp, 160214776ab5STony Nguyen int modify, MemOp mop) 160396d6407fSRichard Henderson { 160496d6407fSRichard Henderson nullify_over(ctx); 160586f8d05fSRichard Henderson do_store_reg(ctx, load_gpr(ctx, rt), rb, 0, 0, disp, sp, modify, mop); 16061cd012a5SRichard Henderson return nullify_end(ctx); 160796d6407fSRichard Henderson } 160896d6407fSRichard Henderson 1609740038d7SRichard Henderson static bool do_fstorew(DisasContext *ctx, unsigned rt, unsigned rb, 1610eaa3783bSRichard Henderson unsigned rx, int scale, target_sreg disp, 161186f8d05fSRichard Henderson unsigned sp, int modify) 161296d6407fSRichard Henderson { 161396d6407fSRichard Henderson TCGv_i32 tmp; 161496d6407fSRichard Henderson 161596d6407fSRichard Henderson nullify_over(ctx); 161696d6407fSRichard Henderson 161796d6407fSRichard Henderson tmp = load_frw_i32(rt); 161886f8d05fSRichard Henderson do_store_32(ctx, tmp, rb, rx, scale, disp, sp, modify, MO_TEUL); 161996d6407fSRichard Henderson 1620740038d7SRichard Henderson return nullify_end(ctx); 162196d6407fSRichard Henderson } 162296d6407fSRichard Henderson 1623740038d7SRichard Henderson static bool trans_fstw(DisasContext *ctx, arg_ldst *a) 1624740038d7SRichard Henderson { 1625740038d7SRichard Henderson return do_fstorew(ctx, a->t, a->b, a->x, a->scale ? 2 : 0, 1626740038d7SRichard Henderson a->disp, a->sp, a->m); 1627740038d7SRichard Henderson } 1628740038d7SRichard Henderson 1629740038d7SRichard Henderson static bool do_fstored(DisasContext *ctx, unsigned rt, unsigned rb, 1630eaa3783bSRichard Henderson unsigned rx, int scale, target_sreg disp, 163186f8d05fSRichard Henderson unsigned sp, int modify) 163296d6407fSRichard Henderson { 163396d6407fSRichard Henderson TCGv_i64 tmp; 163496d6407fSRichard Henderson 163596d6407fSRichard Henderson nullify_over(ctx); 163696d6407fSRichard Henderson 163796d6407fSRichard Henderson tmp = load_frd(rt); 1638fc313c64SFrédéric Pétrot do_store_64(ctx, tmp, rb, rx, scale, disp, sp, modify, MO_TEUQ); 163996d6407fSRichard Henderson 1640740038d7SRichard Henderson return nullify_end(ctx); 1641740038d7SRichard Henderson } 1642740038d7SRichard Henderson 1643740038d7SRichard Henderson static bool trans_fstd(DisasContext *ctx, arg_ldst *a) 1644740038d7SRichard Henderson { 1645740038d7SRichard Henderson return do_fstored(ctx, a->t, a->b, a->x, a->scale ? 3 : 0, 1646740038d7SRichard Henderson a->disp, a->sp, a->m); 164796d6407fSRichard Henderson } 164896d6407fSRichard Henderson 16491ca74648SRichard Henderson static bool do_fop_wew(DisasContext *ctx, unsigned rt, unsigned ra, 1650ebe9383cSRichard Henderson void (*func)(TCGv_i32, TCGv_env, TCGv_i32)) 1651ebe9383cSRichard Henderson { 1652ebe9383cSRichard Henderson TCGv_i32 tmp; 1653ebe9383cSRichard Henderson 1654ebe9383cSRichard Henderson nullify_over(ctx); 1655ebe9383cSRichard Henderson tmp = load_frw0_i32(ra); 1656ebe9383cSRichard Henderson 1657ebe9383cSRichard Henderson func(tmp, cpu_env, tmp); 1658ebe9383cSRichard Henderson 1659ebe9383cSRichard Henderson save_frw_i32(rt, tmp); 16601ca74648SRichard Henderson return nullify_end(ctx); 1661ebe9383cSRichard Henderson } 1662ebe9383cSRichard Henderson 16631ca74648SRichard Henderson static bool do_fop_wed(DisasContext *ctx, unsigned rt, unsigned ra, 1664ebe9383cSRichard Henderson void (*func)(TCGv_i32, TCGv_env, TCGv_i64)) 1665ebe9383cSRichard Henderson { 1666ebe9383cSRichard Henderson TCGv_i32 dst; 1667ebe9383cSRichard Henderson TCGv_i64 src; 1668ebe9383cSRichard Henderson 1669ebe9383cSRichard Henderson nullify_over(ctx); 1670ebe9383cSRichard Henderson src = load_frd(ra); 1671ebe9383cSRichard Henderson dst = tcg_temp_new_i32(); 1672ebe9383cSRichard Henderson 1673ebe9383cSRichard Henderson func(dst, cpu_env, src); 1674ebe9383cSRichard Henderson 1675ebe9383cSRichard Henderson save_frw_i32(rt, dst); 16761ca74648SRichard Henderson return nullify_end(ctx); 1677ebe9383cSRichard Henderson } 1678ebe9383cSRichard Henderson 16791ca74648SRichard Henderson static bool do_fop_ded(DisasContext *ctx, unsigned rt, unsigned ra, 1680ebe9383cSRichard Henderson void (*func)(TCGv_i64, TCGv_env, TCGv_i64)) 1681ebe9383cSRichard Henderson { 1682ebe9383cSRichard Henderson TCGv_i64 tmp; 1683ebe9383cSRichard Henderson 1684ebe9383cSRichard Henderson nullify_over(ctx); 1685ebe9383cSRichard Henderson tmp = load_frd0(ra); 1686ebe9383cSRichard Henderson 1687ebe9383cSRichard Henderson func(tmp, cpu_env, tmp); 1688ebe9383cSRichard Henderson 1689ebe9383cSRichard Henderson save_frd(rt, tmp); 16901ca74648SRichard Henderson return nullify_end(ctx); 1691ebe9383cSRichard Henderson } 1692ebe9383cSRichard Henderson 16931ca74648SRichard Henderson static bool do_fop_dew(DisasContext *ctx, unsigned rt, unsigned ra, 1694ebe9383cSRichard Henderson void (*func)(TCGv_i64, TCGv_env, TCGv_i32)) 1695ebe9383cSRichard Henderson { 1696ebe9383cSRichard Henderson TCGv_i32 src; 1697ebe9383cSRichard Henderson TCGv_i64 dst; 1698ebe9383cSRichard Henderson 1699ebe9383cSRichard Henderson nullify_over(ctx); 1700ebe9383cSRichard Henderson src = load_frw0_i32(ra); 1701ebe9383cSRichard Henderson dst = tcg_temp_new_i64(); 1702ebe9383cSRichard Henderson 1703ebe9383cSRichard Henderson func(dst, cpu_env, src); 1704ebe9383cSRichard Henderson 1705ebe9383cSRichard Henderson save_frd(rt, dst); 17061ca74648SRichard Henderson return nullify_end(ctx); 1707ebe9383cSRichard Henderson } 1708ebe9383cSRichard Henderson 17091ca74648SRichard Henderson static bool do_fop_weww(DisasContext *ctx, unsigned rt, 1710ebe9383cSRichard Henderson unsigned ra, unsigned rb, 171131234768SRichard Henderson void (*func)(TCGv_i32, TCGv_env, TCGv_i32, TCGv_i32)) 1712ebe9383cSRichard Henderson { 1713ebe9383cSRichard Henderson TCGv_i32 a, b; 1714ebe9383cSRichard Henderson 1715ebe9383cSRichard Henderson nullify_over(ctx); 1716ebe9383cSRichard Henderson a = load_frw0_i32(ra); 1717ebe9383cSRichard Henderson b = load_frw0_i32(rb); 1718ebe9383cSRichard Henderson 1719ebe9383cSRichard Henderson func(a, cpu_env, a, b); 1720ebe9383cSRichard Henderson 1721ebe9383cSRichard Henderson save_frw_i32(rt, a); 17221ca74648SRichard Henderson return nullify_end(ctx); 1723ebe9383cSRichard Henderson } 1724ebe9383cSRichard Henderson 17251ca74648SRichard Henderson static bool do_fop_dedd(DisasContext *ctx, unsigned rt, 1726ebe9383cSRichard Henderson unsigned ra, unsigned rb, 172731234768SRichard Henderson void (*func)(TCGv_i64, TCGv_env, TCGv_i64, TCGv_i64)) 1728ebe9383cSRichard Henderson { 1729ebe9383cSRichard Henderson TCGv_i64 a, b; 1730ebe9383cSRichard Henderson 1731ebe9383cSRichard Henderson nullify_over(ctx); 1732ebe9383cSRichard Henderson a = load_frd0(ra); 1733ebe9383cSRichard Henderson b = load_frd0(rb); 1734ebe9383cSRichard Henderson 1735ebe9383cSRichard Henderson func(a, cpu_env, a, b); 1736ebe9383cSRichard Henderson 1737ebe9383cSRichard Henderson save_frd(rt, a); 17381ca74648SRichard Henderson return nullify_end(ctx); 1739ebe9383cSRichard Henderson } 1740ebe9383cSRichard Henderson 174198cd9ca7SRichard Henderson /* Emit an unconditional branch to a direct target, which may or may not 174298cd9ca7SRichard Henderson have already had nullification handled. */ 174301afb7beSRichard Henderson static bool do_dbranch(DisasContext *ctx, target_ureg dest, 174498cd9ca7SRichard Henderson unsigned link, bool is_n) 174598cd9ca7SRichard Henderson { 174698cd9ca7SRichard Henderson if (ctx->null_cond.c == TCG_COND_NEVER && ctx->null_lab == NULL) { 174798cd9ca7SRichard Henderson if (link != 0) { 174898cd9ca7SRichard Henderson copy_iaoq_entry(cpu_gr[link], ctx->iaoq_n, ctx->iaoq_n_var); 174998cd9ca7SRichard Henderson } 175098cd9ca7SRichard Henderson ctx->iaoq_n = dest; 175198cd9ca7SRichard Henderson if (is_n) { 175298cd9ca7SRichard Henderson ctx->null_cond.c = TCG_COND_ALWAYS; 175398cd9ca7SRichard Henderson } 175498cd9ca7SRichard Henderson } else { 175598cd9ca7SRichard Henderson nullify_over(ctx); 175698cd9ca7SRichard Henderson 175798cd9ca7SRichard Henderson if (link != 0) { 175898cd9ca7SRichard Henderson copy_iaoq_entry(cpu_gr[link], ctx->iaoq_n, ctx->iaoq_n_var); 175998cd9ca7SRichard Henderson } 176098cd9ca7SRichard Henderson 176198cd9ca7SRichard Henderson if (is_n && use_nullify_skip(ctx)) { 176298cd9ca7SRichard Henderson nullify_set(ctx, 0); 176398cd9ca7SRichard Henderson gen_goto_tb(ctx, 0, dest, dest + 4); 176498cd9ca7SRichard Henderson } else { 176598cd9ca7SRichard Henderson nullify_set(ctx, is_n); 176698cd9ca7SRichard Henderson gen_goto_tb(ctx, 0, ctx->iaoq_b, dest); 176798cd9ca7SRichard Henderson } 176898cd9ca7SRichard Henderson 176931234768SRichard Henderson nullify_end(ctx); 177098cd9ca7SRichard Henderson 177198cd9ca7SRichard Henderson nullify_set(ctx, 0); 177298cd9ca7SRichard Henderson gen_goto_tb(ctx, 1, ctx->iaoq_b, ctx->iaoq_n); 177331234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 177498cd9ca7SRichard Henderson } 177501afb7beSRichard Henderson return true; 177698cd9ca7SRichard Henderson } 177798cd9ca7SRichard Henderson 177898cd9ca7SRichard Henderson /* Emit a conditional branch to a direct target. If the branch itself 177998cd9ca7SRichard Henderson is nullified, we should have already used nullify_over. */ 178001afb7beSRichard Henderson static bool do_cbranch(DisasContext *ctx, target_sreg disp, bool is_n, 178198cd9ca7SRichard Henderson DisasCond *cond) 178298cd9ca7SRichard Henderson { 1783eaa3783bSRichard Henderson target_ureg dest = iaoq_dest(ctx, disp); 178498cd9ca7SRichard Henderson TCGLabel *taken = NULL; 178598cd9ca7SRichard Henderson TCGCond c = cond->c; 178698cd9ca7SRichard Henderson bool n; 178798cd9ca7SRichard Henderson 178898cd9ca7SRichard Henderson assert(ctx->null_cond.c == TCG_COND_NEVER); 178998cd9ca7SRichard Henderson 179098cd9ca7SRichard Henderson /* Handle TRUE and NEVER as direct branches. */ 179198cd9ca7SRichard Henderson if (c == TCG_COND_ALWAYS) { 179201afb7beSRichard Henderson return do_dbranch(ctx, dest, 0, is_n && disp >= 0); 179398cd9ca7SRichard Henderson } 179498cd9ca7SRichard Henderson if (c == TCG_COND_NEVER) { 179501afb7beSRichard Henderson return do_dbranch(ctx, ctx->iaoq_n, 0, is_n && disp < 0); 179698cd9ca7SRichard Henderson } 179798cd9ca7SRichard Henderson 179898cd9ca7SRichard Henderson taken = gen_new_label(); 1799eaa3783bSRichard Henderson tcg_gen_brcond_reg(c, cond->a0, cond->a1, taken); 180098cd9ca7SRichard Henderson cond_free(cond); 180198cd9ca7SRichard Henderson 180298cd9ca7SRichard Henderson /* Not taken: Condition not satisfied; nullify on backward branches. */ 180398cd9ca7SRichard Henderson n = is_n && disp < 0; 180498cd9ca7SRichard Henderson if (n && use_nullify_skip(ctx)) { 180598cd9ca7SRichard Henderson nullify_set(ctx, 0); 1806a881c8e7SRichard Henderson gen_goto_tb(ctx, 0, ctx->iaoq_n, ctx->iaoq_n + 4); 180798cd9ca7SRichard Henderson } else { 180898cd9ca7SRichard Henderson if (!n && ctx->null_lab) { 180998cd9ca7SRichard Henderson gen_set_label(ctx->null_lab); 181098cd9ca7SRichard Henderson ctx->null_lab = NULL; 181198cd9ca7SRichard Henderson } 181298cd9ca7SRichard Henderson nullify_set(ctx, n); 1813c301f34eSRichard Henderson if (ctx->iaoq_n == -1) { 1814c301f34eSRichard Henderson /* The temporary iaoq_n_var died at the branch above. 1815c301f34eSRichard Henderson Regenerate it here instead of saving it. */ 1816c301f34eSRichard Henderson tcg_gen_addi_reg(ctx->iaoq_n_var, cpu_iaoq_b, 4); 1817c301f34eSRichard Henderson } 1818a881c8e7SRichard Henderson gen_goto_tb(ctx, 0, ctx->iaoq_b, ctx->iaoq_n); 181998cd9ca7SRichard Henderson } 182098cd9ca7SRichard Henderson 182198cd9ca7SRichard Henderson gen_set_label(taken); 182298cd9ca7SRichard Henderson 182398cd9ca7SRichard Henderson /* Taken: Condition satisfied; nullify on forward branches. */ 182498cd9ca7SRichard Henderson n = is_n && disp >= 0; 182598cd9ca7SRichard Henderson if (n && use_nullify_skip(ctx)) { 182698cd9ca7SRichard Henderson nullify_set(ctx, 0); 1827a881c8e7SRichard Henderson gen_goto_tb(ctx, 1, dest, dest + 4); 182898cd9ca7SRichard Henderson } else { 182998cd9ca7SRichard Henderson nullify_set(ctx, n); 1830a881c8e7SRichard Henderson gen_goto_tb(ctx, 1, ctx->iaoq_b, dest); 183198cd9ca7SRichard Henderson } 183298cd9ca7SRichard Henderson 183398cd9ca7SRichard Henderson /* Not taken: the branch itself was nullified. */ 183498cd9ca7SRichard Henderson if (ctx->null_lab) { 183598cd9ca7SRichard Henderson gen_set_label(ctx->null_lab); 183698cd9ca7SRichard Henderson ctx->null_lab = NULL; 183731234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE; 183898cd9ca7SRichard Henderson } else { 183931234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 184098cd9ca7SRichard Henderson } 184101afb7beSRichard Henderson return true; 184298cd9ca7SRichard Henderson } 184398cd9ca7SRichard Henderson 184498cd9ca7SRichard Henderson /* Emit an unconditional branch to an indirect target. This handles 184598cd9ca7SRichard Henderson nullification of the branch itself. */ 184601afb7beSRichard Henderson static bool do_ibranch(DisasContext *ctx, TCGv_reg dest, 184798cd9ca7SRichard Henderson unsigned link, bool is_n) 184898cd9ca7SRichard Henderson { 1849eaa3783bSRichard Henderson TCGv_reg a0, a1, next, tmp; 185098cd9ca7SRichard Henderson TCGCond c; 185198cd9ca7SRichard Henderson 185298cd9ca7SRichard Henderson assert(ctx->null_lab == NULL); 185398cd9ca7SRichard Henderson 185498cd9ca7SRichard Henderson if (ctx->null_cond.c == TCG_COND_NEVER) { 185598cd9ca7SRichard Henderson if (link != 0) { 185698cd9ca7SRichard Henderson copy_iaoq_entry(cpu_gr[link], ctx->iaoq_n, ctx->iaoq_n_var); 185798cd9ca7SRichard Henderson } 185898cd9ca7SRichard Henderson next = get_temp(ctx); 1859eaa3783bSRichard Henderson tcg_gen_mov_reg(next, dest); 186098cd9ca7SRichard Henderson if (is_n) { 1861c301f34eSRichard Henderson if (use_nullify_skip(ctx)) { 1862c301f34eSRichard Henderson tcg_gen_mov_reg(cpu_iaoq_f, next); 1863c301f34eSRichard Henderson tcg_gen_addi_reg(cpu_iaoq_b, next, 4); 1864c301f34eSRichard Henderson nullify_set(ctx, 0); 186531234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_UPDATED; 186601afb7beSRichard Henderson return true; 1867c301f34eSRichard Henderson } 186898cd9ca7SRichard Henderson ctx->null_cond.c = TCG_COND_ALWAYS; 186998cd9ca7SRichard Henderson } 1870c301f34eSRichard Henderson ctx->iaoq_n = -1; 1871c301f34eSRichard Henderson ctx->iaoq_n_var = next; 187298cd9ca7SRichard Henderson } else if (is_n && use_nullify_skip(ctx)) { 187398cd9ca7SRichard Henderson /* The (conditional) branch, B, nullifies the next insn, N, 187498cd9ca7SRichard Henderson and we're allowed to skip execution N (no single-step or 18754137cb83SRichard Henderson tracepoint in effect). Since the goto_ptr that we must use 187698cd9ca7SRichard Henderson for the indirect branch consumes no special resources, we 187798cd9ca7SRichard Henderson can (conditionally) skip B and continue execution. */ 187898cd9ca7SRichard Henderson /* The use_nullify_skip test implies we have a known control path. */ 187998cd9ca7SRichard Henderson tcg_debug_assert(ctx->iaoq_b != -1); 188098cd9ca7SRichard Henderson tcg_debug_assert(ctx->iaoq_n != -1); 188198cd9ca7SRichard Henderson 188298cd9ca7SRichard Henderson /* We do have to handle the non-local temporary, DEST, before 188398cd9ca7SRichard Henderson branching. Since IOAQ_F is not really live at this point, we 188498cd9ca7SRichard Henderson can simply store DEST optimistically. Similarly with IAOQ_B. */ 1885eaa3783bSRichard Henderson tcg_gen_mov_reg(cpu_iaoq_f, dest); 1886eaa3783bSRichard Henderson tcg_gen_addi_reg(cpu_iaoq_b, dest, 4); 188798cd9ca7SRichard Henderson 188898cd9ca7SRichard Henderson nullify_over(ctx); 188998cd9ca7SRichard Henderson if (link != 0) { 1890eaa3783bSRichard Henderson tcg_gen_movi_reg(cpu_gr[link], ctx->iaoq_n); 189198cd9ca7SRichard Henderson } 18927f11636dSEmilio G. Cota tcg_gen_lookup_and_goto_ptr(); 189301afb7beSRichard Henderson return nullify_end(ctx); 189498cd9ca7SRichard Henderson } else { 189598cd9ca7SRichard Henderson c = ctx->null_cond.c; 189698cd9ca7SRichard Henderson a0 = ctx->null_cond.a0; 189798cd9ca7SRichard Henderson a1 = ctx->null_cond.a1; 189898cd9ca7SRichard Henderson 189998cd9ca7SRichard Henderson tmp = tcg_temp_new(); 190098cd9ca7SRichard Henderson next = get_temp(ctx); 190198cd9ca7SRichard Henderson 190298cd9ca7SRichard Henderson copy_iaoq_entry(tmp, ctx->iaoq_n, ctx->iaoq_n_var); 1903eaa3783bSRichard Henderson tcg_gen_movcond_reg(c, next, a0, a1, tmp, dest); 190498cd9ca7SRichard Henderson ctx->iaoq_n = -1; 190598cd9ca7SRichard Henderson ctx->iaoq_n_var = next; 190698cd9ca7SRichard Henderson 190798cd9ca7SRichard Henderson if (link != 0) { 1908eaa3783bSRichard Henderson tcg_gen_movcond_reg(c, cpu_gr[link], a0, a1, cpu_gr[link], tmp); 190998cd9ca7SRichard Henderson } 191098cd9ca7SRichard Henderson 191198cd9ca7SRichard Henderson if (is_n) { 191298cd9ca7SRichard Henderson /* The branch nullifies the next insn, which means the state of N 191398cd9ca7SRichard Henderson after the branch is the inverse of the state of N that applied 191498cd9ca7SRichard Henderson to the branch. */ 1915eaa3783bSRichard Henderson tcg_gen_setcond_reg(tcg_invert_cond(c), cpu_psw_n, a0, a1); 191698cd9ca7SRichard Henderson cond_free(&ctx->null_cond); 191798cd9ca7SRichard Henderson ctx->null_cond = cond_make_n(); 191898cd9ca7SRichard Henderson ctx->psw_n_nonzero = true; 191998cd9ca7SRichard Henderson } else { 192098cd9ca7SRichard Henderson cond_free(&ctx->null_cond); 192198cd9ca7SRichard Henderson } 192298cd9ca7SRichard Henderson } 192301afb7beSRichard Henderson return true; 192498cd9ca7SRichard Henderson } 192598cd9ca7SRichard Henderson 1926660eefe1SRichard Henderson /* Implement 1927660eefe1SRichard Henderson * if (IAOQ_Front{30..31} < GR[b]{30..31}) 1928660eefe1SRichard Henderson * IAOQ_Next{30..31} ← GR[b]{30..31}; 1929660eefe1SRichard Henderson * else 1930660eefe1SRichard Henderson * IAOQ_Next{30..31} ← IAOQ_Front{30..31}; 1931660eefe1SRichard Henderson * which keeps the privilege level from being increased. 1932660eefe1SRichard Henderson */ 1933660eefe1SRichard Henderson static TCGv_reg do_ibranch_priv(DisasContext *ctx, TCGv_reg offset) 1934660eefe1SRichard Henderson { 1935660eefe1SRichard Henderson TCGv_reg dest; 1936660eefe1SRichard Henderson switch (ctx->privilege) { 1937660eefe1SRichard Henderson case 0: 1938660eefe1SRichard Henderson /* Privilege 0 is maximum and is allowed to decrease. */ 1939660eefe1SRichard Henderson return offset; 1940660eefe1SRichard Henderson case 3: 1941993119feSRichard Henderson /* Privilege 3 is minimum and is never allowed to increase. */ 1942660eefe1SRichard Henderson dest = get_temp(ctx); 1943660eefe1SRichard Henderson tcg_gen_ori_reg(dest, offset, 3); 1944660eefe1SRichard Henderson break; 1945660eefe1SRichard Henderson default: 1946993119feSRichard Henderson dest = get_temp(ctx); 1947660eefe1SRichard Henderson tcg_gen_andi_reg(dest, offset, -4); 1948660eefe1SRichard Henderson tcg_gen_ori_reg(dest, dest, ctx->privilege); 1949660eefe1SRichard Henderson tcg_gen_movcond_reg(TCG_COND_GTU, dest, dest, offset, dest, offset); 1950660eefe1SRichard Henderson break; 1951660eefe1SRichard Henderson } 1952660eefe1SRichard Henderson return dest; 1953660eefe1SRichard Henderson } 1954660eefe1SRichard Henderson 1955ba1d0b44SRichard Henderson #ifdef CONFIG_USER_ONLY 19567ad439dfSRichard Henderson /* On Linux, page zero is normally marked execute only + gateway. 19577ad439dfSRichard Henderson Therefore normal read or write is supposed to fail, but specific 19587ad439dfSRichard Henderson offsets have kernel code mapped to raise permissions to implement 19597ad439dfSRichard Henderson system calls. Handling this via an explicit check here, rather 19607ad439dfSRichard Henderson in than the "be disp(sr2,r0)" instruction that probably sent us 19617ad439dfSRichard Henderson here, is the easiest way to handle the branch delay slot on the 19627ad439dfSRichard Henderson aforementioned BE. */ 196331234768SRichard Henderson static void do_page_zero(DisasContext *ctx) 19647ad439dfSRichard Henderson { 19657ad439dfSRichard Henderson /* If by some means we get here with PSW[N]=1, that implies that 19667ad439dfSRichard Henderson the B,GATE instruction would be skipped, and we'd fault on the 19678b81968cSMichael Tokarev next insn within the privileged page. */ 19687ad439dfSRichard Henderson switch (ctx->null_cond.c) { 19697ad439dfSRichard Henderson case TCG_COND_NEVER: 19707ad439dfSRichard Henderson break; 19717ad439dfSRichard Henderson case TCG_COND_ALWAYS: 1972eaa3783bSRichard Henderson tcg_gen_movi_reg(cpu_psw_n, 0); 19737ad439dfSRichard Henderson goto do_sigill; 19747ad439dfSRichard Henderson default: 19757ad439dfSRichard Henderson /* Since this is always the first (and only) insn within the 19767ad439dfSRichard Henderson TB, we should know the state of PSW[N] from TB->FLAGS. */ 19777ad439dfSRichard Henderson g_assert_not_reached(); 19787ad439dfSRichard Henderson } 19797ad439dfSRichard Henderson 19807ad439dfSRichard Henderson /* Check that we didn't arrive here via some means that allowed 19817ad439dfSRichard Henderson non-sequential instruction execution. Normally the PSW[B] bit 19827ad439dfSRichard Henderson detects this by disallowing the B,GATE instruction to execute 19837ad439dfSRichard Henderson under such conditions. */ 19847ad439dfSRichard Henderson if (ctx->iaoq_b != ctx->iaoq_f + 4) { 19857ad439dfSRichard Henderson goto do_sigill; 19867ad439dfSRichard Henderson } 19877ad439dfSRichard Henderson 1988ebd0e151SRichard Henderson switch (ctx->iaoq_f & -4) { 19897ad439dfSRichard Henderson case 0x00: /* Null pointer call */ 19902986721dSRichard Henderson gen_excp_1(EXCP_IMP); 199131234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 199231234768SRichard Henderson break; 19937ad439dfSRichard Henderson 19947ad439dfSRichard Henderson case 0xb0: /* LWS */ 19957ad439dfSRichard Henderson gen_excp_1(EXCP_SYSCALL_LWS); 199631234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 199731234768SRichard Henderson break; 19987ad439dfSRichard Henderson 19997ad439dfSRichard Henderson case 0xe0: /* SET_THREAD_POINTER */ 200035136a77SRichard Henderson tcg_gen_st_reg(cpu_gr[26], cpu_env, offsetof(CPUHPPAState, cr[27])); 2001ebd0e151SRichard Henderson tcg_gen_ori_reg(cpu_iaoq_f, cpu_gr[31], 3); 2002eaa3783bSRichard Henderson tcg_gen_addi_reg(cpu_iaoq_b, cpu_iaoq_f, 4); 200331234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_UPDATED; 200431234768SRichard Henderson break; 20057ad439dfSRichard Henderson 20067ad439dfSRichard Henderson case 0x100: /* SYSCALL */ 20077ad439dfSRichard Henderson gen_excp_1(EXCP_SYSCALL); 200831234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 200931234768SRichard Henderson break; 20107ad439dfSRichard Henderson 20117ad439dfSRichard Henderson default: 20127ad439dfSRichard Henderson do_sigill: 20132986721dSRichard Henderson gen_excp_1(EXCP_ILL); 201431234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 201531234768SRichard Henderson break; 20167ad439dfSRichard Henderson } 20177ad439dfSRichard Henderson } 2018ba1d0b44SRichard Henderson #endif 20197ad439dfSRichard Henderson 2020deee69a1SRichard Henderson static bool trans_nop(DisasContext *ctx, arg_nop *a) 2021b2167459SRichard Henderson { 2022b2167459SRichard Henderson cond_free(&ctx->null_cond); 202331234768SRichard Henderson return true; 2024b2167459SRichard Henderson } 2025b2167459SRichard Henderson 202640f9f908SRichard Henderson static bool trans_break(DisasContext *ctx, arg_break *a) 202798a9cb79SRichard Henderson { 202831234768SRichard Henderson return gen_excp_iir(ctx, EXCP_BREAK); 202998a9cb79SRichard Henderson } 203098a9cb79SRichard Henderson 2031e36f27efSRichard Henderson static bool trans_sync(DisasContext *ctx, arg_sync *a) 203298a9cb79SRichard Henderson { 203398a9cb79SRichard Henderson /* No point in nullifying the memory barrier. */ 203498a9cb79SRichard Henderson tcg_gen_mb(TCG_BAR_SC | TCG_MO_ALL); 203598a9cb79SRichard Henderson 203698a9cb79SRichard Henderson cond_free(&ctx->null_cond); 203731234768SRichard Henderson return true; 203898a9cb79SRichard Henderson } 203998a9cb79SRichard Henderson 2040c603e14aSRichard Henderson static bool trans_mfia(DisasContext *ctx, arg_mfia *a) 204198a9cb79SRichard Henderson { 2042c603e14aSRichard Henderson unsigned rt = a->t; 2043eaa3783bSRichard Henderson TCGv_reg tmp = dest_gpr(ctx, rt); 2044eaa3783bSRichard Henderson tcg_gen_movi_reg(tmp, ctx->iaoq_f); 204598a9cb79SRichard Henderson save_gpr(ctx, rt, tmp); 204698a9cb79SRichard Henderson 204798a9cb79SRichard Henderson cond_free(&ctx->null_cond); 204831234768SRichard Henderson return true; 204998a9cb79SRichard Henderson } 205098a9cb79SRichard Henderson 2051c603e14aSRichard Henderson static bool trans_mfsp(DisasContext *ctx, arg_mfsp *a) 205298a9cb79SRichard Henderson { 2053c603e14aSRichard Henderson unsigned rt = a->t; 2054c603e14aSRichard Henderson unsigned rs = a->sp; 205533423472SRichard Henderson TCGv_i64 t0 = tcg_temp_new_i64(); 205633423472SRichard Henderson TCGv_reg t1 = tcg_temp_new(); 205798a9cb79SRichard Henderson 205833423472SRichard Henderson load_spr(ctx, t0, rs); 205933423472SRichard Henderson tcg_gen_shri_i64(t0, t0, 32); 206033423472SRichard Henderson tcg_gen_trunc_i64_reg(t1, t0); 206133423472SRichard Henderson 206233423472SRichard Henderson save_gpr(ctx, rt, t1); 206398a9cb79SRichard Henderson 206498a9cb79SRichard Henderson cond_free(&ctx->null_cond); 206531234768SRichard Henderson return true; 206698a9cb79SRichard Henderson } 206798a9cb79SRichard Henderson 2068c603e14aSRichard Henderson static bool trans_mfctl(DisasContext *ctx, arg_mfctl *a) 206998a9cb79SRichard Henderson { 2070c603e14aSRichard Henderson unsigned rt = a->t; 2071c603e14aSRichard Henderson unsigned ctl = a->r; 2072eaa3783bSRichard Henderson TCGv_reg tmp; 207398a9cb79SRichard Henderson 207498a9cb79SRichard Henderson switch (ctl) { 207535136a77SRichard Henderson case CR_SAR: 207698a9cb79SRichard Henderson #ifdef TARGET_HPPA64 2077c603e14aSRichard Henderson if (a->e == 0) { 207898a9cb79SRichard Henderson /* MFSAR without ,W masks low 5 bits. */ 207998a9cb79SRichard Henderson tmp = dest_gpr(ctx, rt); 2080eaa3783bSRichard Henderson tcg_gen_andi_reg(tmp, cpu_sar, 31); 208198a9cb79SRichard Henderson save_gpr(ctx, rt, tmp); 208235136a77SRichard Henderson goto done; 208398a9cb79SRichard Henderson } 208498a9cb79SRichard Henderson #endif 208598a9cb79SRichard Henderson save_gpr(ctx, rt, cpu_sar); 208635136a77SRichard Henderson goto done; 208735136a77SRichard Henderson case CR_IT: /* Interval Timer */ 208835136a77SRichard Henderson /* FIXME: Respect PSW_S bit. */ 208935136a77SRichard Henderson nullify_over(ctx); 209098a9cb79SRichard Henderson tmp = dest_gpr(ctx, rt); 2091dfd1b812SRichard Henderson if (translator_io_start(&ctx->base)) { 209249c29d6cSRichard Henderson gen_helper_read_interval_timer(tmp); 209331234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE; 209449c29d6cSRichard Henderson } else { 209549c29d6cSRichard Henderson gen_helper_read_interval_timer(tmp); 209649c29d6cSRichard Henderson } 209798a9cb79SRichard Henderson save_gpr(ctx, rt, tmp); 209831234768SRichard Henderson return nullify_end(ctx); 209998a9cb79SRichard Henderson case 26: 210098a9cb79SRichard Henderson case 27: 210198a9cb79SRichard Henderson break; 210298a9cb79SRichard Henderson default: 210398a9cb79SRichard Henderson /* All other control registers are privileged. */ 210435136a77SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_REG); 210535136a77SRichard Henderson break; 210698a9cb79SRichard Henderson } 210798a9cb79SRichard Henderson 210835136a77SRichard Henderson tmp = get_temp(ctx); 210935136a77SRichard Henderson tcg_gen_ld_reg(tmp, cpu_env, offsetof(CPUHPPAState, cr[ctl])); 211035136a77SRichard Henderson save_gpr(ctx, rt, tmp); 211135136a77SRichard Henderson 211235136a77SRichard Henderson done: 211398a9cb79SRichard Henderson cond_free(&ctx->null_cond); 211431234768SRichard Henderson return true; 211598a9cb79SRichard Henderson } 211698a9cb79SRichard Henderson 2117c603e14aSRichard Henderson static bool trans_mtsp(DisasContext *ctx, arg_mtsp *a) 211833423472SRichard Henderson { 2119c603e14aSRichard Henderson unsigned rr = a->r; 2120c603e14aSRichard Henderson unsigned rs = a->sp; 212133423472SRichard Henderson TCGv_i64 t64; 212233423472SRichard Henderson 212333423472SRichard Henderson if (rs >= 5) { 212433423472SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_REG); 212533423472SRichard Henderson } 212633423472SRichard Henderson nullify_over(ctx); 212733423472SRichard Henderson 212833423472SRichard Henderson t64 = tcg_temp_new_i64(); 212933423472SRichard Henderson tcg_gen_extu_reg_i64(t64, load_gpr(ctx, rr)); 213033423472SRichard Henderson tcg_gen_shli_i64(t64, t64, 32); 213133423472SRichard Henderson 213233423472SRichard Henderson if (rs >= 4) { 213333423472SRichard Henderson tcg_gen_st_i64(t64, cpu_env, offsetof(CPUHPPAState, sr[rs])); 2134494737b7SRichard Henderson ctx->tb_flags &= ~TB_FLAG_SR_SAME; 213533423472SRichard Henderson } else { 213633423472SRichard Henderson tcg_gen_mov_i64(cpu_sr[rs], t64); 213733423472SRichard Henderson } 213833423472SRichard Henderson 213931234768SRichard Henderson return nullify_end(ctx); 214033423472SRichard Henderson } 214133423472SRichard Henderson 2142c603e14aSRichard Henderson static bool trans_mtctl(DisasContext *ctx, arg_mtctl *a) 214398a9cb79SRichard Henderson { 2144c603e14aSRichard Henderson unsigned ctl = a->t; 21454845f015SSven Schnelle TCGv_reg reg; 2146eaa3783bSRichard Henderson TCGv_reg tmp; 214798a9cb79SRichard Henderson 214835136a77SRichard Henderson if (ctl == CR_SAR) { 21494845f015SSven Schnelle reg = load_gpr(ctx, a->r); 215098a9cb79SRichard Henderson tmp = tcg_temp_new(); 215135136a77SRichard Henderson tcg_gen_andi_reg(tmp, reg, TARGET_REGISTER_BITS - 1); 215298a9cb79SRichard Henderson save_or_nullify(ctx, cpu_sar, tmp); 215398a9cb79SRichard Henderson 215498a9cb79SRichard Henderson cond_free(&ctx->null_cond); 215531234768SRichard Henderson return true; 215698a9cb79SRichard Henderson } 215798a9cb79SRichard Henderson 215835136a77SRichard Henderson /* All other control registers are privileged or read-only. */ 215935136a77SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_REG); 216035136a77SRichard Henderson 2161c603e14aSRichard Henderson #ifndef CONFIG_USER_ONLY 216235136a77SRichard Henderson nullify_over(ctx); 21634845f015SSven Schnelle reg = load_gpr(ctx, a->r); 21644845f015SSven Schnelle 216535136a77SRichard Henderson switch (ctl) { 216635136a77SRichard Henderson case CR_IT: 216749c29d6cSRichard Henderson gen_helper_write_interval_timer(cpu_env, reg); 216835136a77SRichard Henderson break; 21694f5f2548SRichard Henderson case CR_EIRR: 21704f5f2548SRichard Henderson gen_helper_write_eirr(cpu_env, reg); 21714f5f2548SRichard Henderson break; 21724f5f2548SRichard Henderson case CR_EIEM: 21734f5f2548SRichard Henderson gen_helper_write_eiem(cpu_env, reg); 217431234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE_EXIT; 21754f5f2548SRichard Henderson break; 21764f5f2548SRichard Henderson 217735136a77SRichard Henderson case CR_IIASQ: 217835136a77SRichard Henderson case CR_IIAOQ: 217935136a77SRichard Henderson /* FIXME: Respect PSW_Q bit */ 218035136a77SRichard Henderson /* The write advances the queue and stores to the back element. */ 218135136a77SRichard Henderson tmp = get_temp(ctx); 218235136a77SRichard Henderson tcg_gen_ld_reg(tmp, cpu_env, 218335136a77SRichard Henderson offsetof(CPUHPPAState, cr_back[ctl - CR_IIASQ])); 218435136a77SRichard Henderson tcg_gen_st_reg(tmp, cpu_env, offsetof(CPUHPPAState, cr[ctl])); 218535136a77SRichard Henderson tcg_gen_st_reg(reg, cpu_env, 218635136a77SRichard Henderson offsetof(CPUHPPAState, cr_back[ctl - CR_IIASQ])); 218735136a77SRichard Henderson break; 218835136a77SRichard Henderson 2189d5de20bdSSven Schnelle case CR_PID1: 2190d5de20bdSSven Schnelle case CR_PID2: 2191d5de20bdSSven Schnelle case CR_PID3: 2192d5de20bdSSven Schnelle case CR_PID4: 2193d5de20bdSSven Schnelle tcg_gen_st_reg(reg, cpu_env, offsetof(CPUHPPAState, cr[ctl])); 2194d5de20bdSSven Schnelle #ifndef CONFIG_USER_ONLY 2195d5de20bdSSven Schnelle gen_helper_change_prot_id(cpu_env); 2196d5de20bdSSven Schnelle #endif 2197d5de20bdSSven Schnelle break; 2198d5de20bdSSven Schnelle 219935136a77SRichard Henderson default: 220035136a77SRichard Henderson tcg_gen_st_reg(reg, cpu_env, offsetof(CPUHPPAState, cr[ctl])); 220135136a77SRichard Henderson break; 220235136a77SRichard Henderson } 220331234768SRichard Henderson return nullify_end(ctx); 22044f5f2548SRichard Henderson #endif 220535136a77SRichard Henderson } 220635136a77SRichard Henderson 2207c603e14aSRichard Henderson static bool trans_mtsarcm(DisasContext *ctx, arg_mtsarcm *a) 220898a9cb79SRichard Henderson { 2209eaa3783bSRichard Henderson TCGv_reg tmp = tcg_temp_new(); 221098a9cb79SRichard Henderson 2211c603e14aSRichard Henderson tcg_gen_not_reg(tmp, load_gpr(ctx, a->r)); 2212eaa3783bSRichard Henderson tcg_gen_andi_reg(tmp, tmp, TARGET_REGISTER_BITS - 1); 221398a9cb79SRichard Henderson save_or_nullify(ctx, cpu_sar, tmp); 221498a9cb79SRichard Henderson 221598a9cb79SRichard Henderson cond_free(&ctx->null_cond); 221631234768SRichard Henderson return true; 221798a9cb79SRichard Henderson } 221898a9cb79SRichard Henderson 2219e36f27efSRichard Henderson static bool trans_ldsid(DisasContext *ctx, arg_ldsid *a) 222098a9cb79SRichard Henderson { 2221e36f27efSRichard Henderson TCGv_reg dest = dest_gpr(ctx, a->t); 222298a9cb79SRichard Henderson 22232330504cSHelge Deller #ifdef CONFIG_USER_ONLY 22242330504cSHelge Deller /* We don't implement space registers in user mode. */ 2225eaa3783bSRichard Henderson tcg_gen_movi_reg(dest, 0); 22262330504cSHelge Deller #else 22272330504cSHelge Deller TCGv_i64 t0 = tcg_temp_new_i64(); 22282330504cSHelge Deller 2229e36f27efSRichard Henderson tcg_gen_mov_i64(t0, space_select(ctx, a->sp, load_gpr(ctx, a->b))); 22302330504cSHelge Deller tcg_gen_shri_i64(t0, t0, 32); 22312330504cSHelge Deller tcg_gen_trunc_i64_reg(dest, t0); 22322330504cSHelge Deller #endif 2233e36f27efSRichard Henderson save_gpr(ctx, a->t, dest); 223498a9cb79SRichard Henderson 223598a9cb79SRichard Henderson cond_free(&ctx->null_cond); 223631234768SRichard Henderson return true; 223798a9cb79SRichard Henderson } 223898a9cb79SRichard Henderson 2239e36f27efSRichard Henderson static bool trans_rsm(DisasContext *ctx, arg_rsm *a) 2240e36f27efSRichard Henderson { 2241e36f27efSRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 2242e1b5a5edSRichard Henderson #ifndef CONFIG_USER_ONLY 2243e1b5a5edSRichard Henderson TCGv_reg tmp; 2244e1b5a5edSRichard Henderson 2245e1b5a5edSRichard Henderson nullify_over(ctx); 2246e1b5a5edSRichard Henderson 2247e1b5a5edSRichard Henderson tmp = get_temp(ctx); 2248e1b5a5edSRichard Henderson tcg_gen_ld_reg(tmp, cpu_env, offsetof(CPUHPPAState, psw)); 2249e36f27efSRichard Henderson tcg_gen_andi_reg(tmp, tmp, ~a->i); 2250e1b5a5edSRichard Henderson gen_helper_swap_system_mask(tmp, cpu_env, tmp); 2251e36f27efSRichard Henderson save_gpr(ctx, a->t, tmp); 2252e1b5a5edSRichard Henderson 2253e1b5a5edSRichard Henderson /* Exit the TB to recognize new interrupts, e.g. PSW_M. */ 225431234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE_EXIT; 225531234768SRichard Henderson return nullify_end(ctx); 2256e36f27efSRichard Henderson #endif 2257e1b5a5edSRichard Henderson } 2258e1b5a5edSRichard Henderson 2259e36f27efSRichard Henderson static bool trans_ssm(DisasContext *ctx, arg_ssm *a) 2260e1b5a5edSRichard Henderson { 2261e36f27efSRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 2262e36f27efSRichard Henderson #ifndef CONFIG_USER_ONLY 2263e1b5a5edSRichard Henderson TCGv_reg tmp; 2264e1b5a5edSRichard Henderson 2265e1b5a5edSRichard Henderson nullify_over(ctx); 2266e1b5a5edSRichard Henderson 2267e1b5a5edSRichard Henderson tmp = get_temp(ctx); 2268e1b5a5edSRichard Henderson tcg_gen_ld_reg(tmp, cpu_env, offsetof(CPUHPPAState, psw)); 2269e36f27efSRichard Henderson tcg_gen_ori_reg(tmp, tmp, a->i); 2270e1b5a5edSRichard Henderson gen_helper_swap_system_mask(tmp, cpu_env, tmp); 2271e36f27efSRichard Henderson save_gpr(ctx, a->t, tmp); 2272e1b5a5edSRichard Henderson 2273e1b5a5edSRichard Henderson /* Exit the TB to recognize new interrupts, e.g. PSW_I. */ 227431234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE_EXIT; 227531234768SRichard Henderson return nullify_end(ctx); 2276e36f27efSRichard Henderson #endif 2277e1b5a5edSRichard Henderson } 2278e1b5a5edSRichard Henderson 2279c603e14aSRichard Henderson static bool trans_mtsm(DisasContext *ctx, arg_mtsm *a) 2280e1b5a5edSRichard Henderson { 2281e1b5a5edSRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 2282c603e14aSRichard Henderson #ifndef CONFIG_USER_ONLY 2283c603e14aSRichard Henderson TCGv_reg tmp, reg; 2284e1b5a5edSRichard Henderson nullify_over(ctx); 2285e1b5a5edSRichard Henderson 2286c603e14aSRichard Henderson reg = load_gpr(ctx, a->r); 2287e1b5a5edSRichard Henderson tmp = get_temp(ctx); 2288e1b5a5edSRichard Henderson gen_helper_swap_system_mask(tmp, cpu_env, reg); 2289e1b5a5edSRichard Henderson 2290e1b5a5edSRichard Henderson /* Exit the TB to recognize new interrupts. */ 229131234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE_EXIT; 229231234768SRichard Henderson return nullify_end(ctx); 2293c603e14aSRichard Henderson #endif 2294e1b5a5edSRichard Henderson } 2295f49b3537SRichard Henderson 2296e36f27efSRichard Henderson static bool do_rfi(DisasContext *ctx, bool rfi_r) 2297f49b3537SRichard Henderson { 2298f49b3537SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 2299e36f27efSRichard Henderson #ifndef CONFIG_USER_ONLY 2300f49b3537SRichard Henderson nullify_over(ctx); 2301f49b3537SRichard Henderson 2302e36f27efSRichard Henderson if (rfi_r) { 2303f49b3537SRichard Henderson gen_helper_rfi_r(cpu_env); 2304f49b3537SRichard Henderson } else { 2305f49b3537SRichard Henderson gen_helper_rfi(cpu_env); 2306f49b3537SRichard Henderson } 230731234768SRichard Henderson /* Exit the TB to recognize new interrupts. */ 230807ea28b4SRichard Henderson tcg_gen_exit_tb(NULL, 0); 230931234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 2310f49b3537SRichard Henderson 231131234768SRichard Henderson return nullify_end(ctx); 2312e36f27efSRichard Henderson #endif 2313f49b3537SRichard Henderson } 23146210db05SHelge Deller 2315e36f27efSRichard Henderson static bool trans_rfi(DisasContext *ctx, arg_rfi *a) 2316e36f27efSRichard Henderson { 2317e36f27efSRichard Henderson return do_rfi(ctx, false); 2318e36f27efSRichard Henderson } 2319e36f27efSRichard Henderson 2320e36f27efSRichard Henderson static bool trans_rfi_r(DisasContext *ctx, arg_rfi_r *a) 2321e36f27efSRichard Henderson { 2322e36f27efSRichard Henderson return do_rfi(ctx, true); 2323e36f27efSRichard Henderson } 2324e36f27efSRichard Henderson 232596927adbSRichard Henderson static bool trans_halt(DisasContext *ctx, arg_halt *a) 23266210db05SHelge Deller { 23276210db05SHelge Deller CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 232896927adbSRichard Henderson #ifndef CONFIG_USER_ONLY 23296210db05SHelge Deller nullify_over(ctx); 23306210db05SHelge Deller gen_helper_halt(cpu_env); 233131234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 233231234768SRichard Henderson return nullify_end(ctx); 233396927adbSRichard Henderson #endif 23346210db05SHelge Deller } 233596927adbSRichard Henderson 233696927adbSRichard Henderson static bool trans_reset(DisasContext *ctx, arg_reset *a) 233796927adbSRichard Henderson { 233896927adbSRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 233996927adbSRichard Henderson #ifndef CONFIG_USER_ONLY 234096927adbSRichard Henderson nullify_over(ctx); 234196927adbSRichard Henderson gen_helper_reset(cpu_env); 234296927adbSRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 234396927adbSRichard Henderson return nullify_end(ctx); 234496927adbSRichard Henderson #endif 234596927adbSRichard Henderson } 2346e1b5a5edSRichard Henderson 23474a4554c6SHelge Deller static bool trans_getshadowregs(DisasContext *ctx, arg_getshadowregs *a) 23484a4554c6SHelge Deller { 23494a4554c6SHelge Deller CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 23504a4554c6SHelge Deller #ifndef CONFIG_USER_ONLY 23514a4554c6SHelge Deller nullify_over(ctx); 23524a4554c6SHelge Deller gen_helper_getshadowregs(cpu_env); 23534a4554c6SHelge Deller return nullify_end(ctx); 23544a4554c6SHelge Deller #endif 23554a4554c6SHelge Deller } 23564a4554c6SHelge Deller 2357deee69a1SRichard Henderson static bool trans_nop_addrx(DisasContext *ctx, arg_ldst *a) 235898a9cb79SRichard Henderson { 2359deee69a1SRichard Henderson if (a->m) { 2360deee69a1SRichard Henderson TCGv_reg dest = dest_gpr(ctx, a->b); 2361deee69a1SRichard Henderson TCGv_reg src1 = load_gpr(ctx, a->b); 2362deee69a1SRichard Henderson TCGv_reg src2 = load_gpr(ctx, a->x); 236398a9cb79SRichard Henderson 236498a9cb79SRichard Henderson /* The only thing we need to do is the base register modification. */ 2365eaa3783bSRichard Henderson tcg_gen_add_reg(dest, src1, src2); 2366deee69a1SRichard Henderson save_gpr(ctx, a->b, dest); 2367deee69a1SRichard Henderson } 236898a9cb79SRichard Henderson cond_free(&ctx->null_cond); 236931234768SRichard Henderson return true; 237098a9cb79SRichard Henderson } 237198a9cb79SRichard Henderson 2372deee69a1SRichard Henderson static bool trans_probe(DisasContext *ctx, arg_probe *a) 237398a9cb79SRichard Henderson { 237486f8d05fSRichard Henderson TCGv_reg dest, ofs; 2375eed14219SRichard Henderson TCGv_i32 level, want; 237686f8d05fSRichard Henderson TCGv_tl addr; 237798a9cb79SRichard Henderson 237898a9cb79SRichard Henderson nullify_over(ctx); 237998a9cb79SRichard Henderson 2380deee69a1SRichard Henderson dest = dest_gpr(ctx, a->t); 2381deee69a1SRichard Henderson form_gva(ctx, &addr, &ofs, a->b, 0, 0, 0, a->sp, 0, false); 2382eed14219SRichard Henderson 2383deee69a1SRichard Henderson if (a->imm) { 238429dd6f64SRichard Henderson level = tcg_constant_i32(a->ri); 238598a9cb79SRichard Henderson } else { 2386eed14219SRichard Henderson level = tcg_temp_new_i32(); 2387deee69a1SRichard Henderson tcg_gen_trunc_reg_i32(level, load_gpr(ctx, a->ri)); 2388eed14219SRichard Henderson tcg_gen_andi_i32(level, level, 3); 238998a9cb79SRichard Henderson } 239029dd6f64SRichard Henderson want = tcg_constant_i32(a->write ? PAGE_WRITE : PAGE_READ); 2391eed14219SRichard Henderson 2392eed14219SRichard Henderson gen_helper_probe(dest, cpu_env, addr, level, want); 2393eed14219SRichard Henderson 2394deee69a1SRichard Henderson save_gpr(ctx, a->t, dest); 239531234768SRichard Henderson return nullify_end(ctx); 239698a9cb79SRichard Henderson } 239798a9cb79SRichard Henderson 2398deee69a1SRichard Henderson static bool trans_ixtlbx(DisasContext *ctx, arg_ixtlbx *a) 23998d6ae7fbSRichard Henderson { 2400deee69a1SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 2401deee69a1SRichard Henderson #ifndef CONFIG_USER_ONLY 24028d6ae7fbSRichard Henderson TCGv_tl addr; 24038d6ae7fbSRichard Henderson TCGv_reg ofs, reg; 24048d6ae7fbSRichard Henderson 24058d6ae7fbSRichard Henderson nullify_over(ctx); 24068d6ae7fbSRichard Henderson 2407deee69a1SRichard Henderson form_gva(ctx, &addr, &ofs, a->b, 0, 0, 0, a->sp, 0, false); 2408deee69a1SRichard Henderson reg = load_gpr(ctx, a->r); 2409deee69a1SRichard Henderson if (a->addr) { 24108d6ae7fbSRichard Henderson gen_helper_itlba(cpu_env, addr, reg); 24118d6ae7fbSRichard Henderson } else { 24128d6ae7fbSRichard Henderson gen_helper_itlbp(cpu_env, addr, reg); 24138d6ae7fbSRichard Henderson } 24148d6ae7fbSRichard Henderson 241532dc7569SSven Schnelle /* Exit TB for TLB change if mmu is enabled. */ 241632dc7569SSven Schnelle if (ctx->tb_flags & PSW_C) { 241731234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE; 241831234768SRichard Henderson } 241931234768SRichard Henderson return nullify_end(ctx); 2420deee69a1SRichard Henderson #endif 24218d6ae7fbSRichard Henderson } 242263300a00SRichard Henderson 2423deee69a1SRichard Henderson static bool trans_pxtlbx(DisasContext *ctx, arg_pxtlbx *a) 242463300a00SRichard Henderson { 2425deee69a1SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 2426deee69a1SRichard Henderson #ifndef CONFIG_USER_ONLY 242763300a00SRichard Henderson TCGv_tl addr; 242863300a00SRichard Henderson TCGv_reg ofs; 242963300a00SRichard Henderson 243063300a00SRichard Henderson nullify_over(ctx); 243163300a00SRichard Henderson 2432deee69a1SRichard Henderson form_gva(ctx, &addr, &ofs, a->b, a->x, 0, 0, a->sp, a->m, false); 2433deee69a1SRichard Henderson if (a->m) { 2434deee69a1SRichard Henderson save_gpr(ctx, a->b, ofs); 243563300a00SRichard Henderson } 2436deee69a1SRichard Henderson if (a->local) { 243763300a00SRichard Henderson gen_helper_ptlbe(cpu_env); 243863300a00SRichard Henderson } else { 243963300a00SRichard Henderson gen_helper_ptlb(cpu_env, addr); 244063300a00SRichard Henderson } 244163300a00SRichard Henderson 244263300a00SRichard Henderson /* Exit TB for TLB change if mmu is enabled. */ 244332dc7569SSven Schnelle if (ctx->tb_flags & PSW_C) { 244431234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE; 244531234768SRichard Henderson } 244631234768SRichard Henderson return nullify_end(ctx); 2447deee69a1SRichard Henderson #endif 244863300a00SRichard Henderson } 24492dfcca9fSRichard Henderson 24506797c315SNick Hudson /* 24516797c315SNick Hudson * Implement the pcxl and pcxl2 Fast TLB Insert instructions. 24526797c315SNick Hudson * See 24536797c315SNick Hudson * https://parisc.wiki.kernel.org/images-parisc/a/a9/Pcxl2_ers.pdf 24546797c315SNick Hudson * page 13-9 (195/206) 24556797c315SNick Hudson */ 24566797c315SNick Hudson static bool trans_ixtlbxf(DisasContext *ctx, arg_ixtlbxf *a) 24576797c315SNick Hudson { 24586797c315SNick Hudson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 24596797c315SNick Hudson #ifndef CONFIG_USER_ONLY 24606797c315SNick Hudson TCGv_tl addr, atl, stl; 24616797c315SNick Hudson TCGv_reg reg; 24626797c315SNick Hudson 24636797c315SNick Hudson nullify_over(ctx); 24646797c315SNick Hudson 24656797c315SNick Hudson /* 24666797c315SNick Hudson * FIXME: 24676797c315SNick Hudson * if (not (pcxl or pcxl2)) 24686797c315SNick Hudson * return gen_illegal(ctx); 24696797c315SNick Hudson * 24706797c315SNick Hudson * Note for future: these are 32-bit systems; no hppa64. 24716797c315SNick Hudson */ 24726797c315SNick Hudson 24736797c315SNick Hudson atl = tcg_temp_new_tl(); 24746797c315SNick Hudson stl = tcg_temp_new_tl(); 24756797c315SNick Hudson addr = tcg_temp_new_tl(); 24766797c315SNick Hudson 24776797c315SNick Hudson tcg_gen_ld32u_i64(stl, cpu_env, 24786797c315SNick Hudson a->data ? offsetof(CPUHPPAState, cr[CR_ISR]) 24796797c315SNick Hudson : offsetof(CPUHPPAState, cr[CR_IIASQ])); 24806797c315SNick Hudson tcg_gen_ld32u_i64(atl, cpu_env, 24816797c315SNick Hudson a->data ? offsetof(CPUHPPAState, cr[CR_IOR]) 24826797c315SNick Hudson : offsetof(CPUHPPAState, cr[CR_IIAOQ])); 24836797c315SNick Hudson tcg_gen_shli_i64(stl, stl, 32); 24846797c315SNick Hudson tcg_gen_or_tl(addr, atl, stl); 24856797c315SNick Hudson 24866797c315SNick Hudson reg = load_gpr(ctx, a->r); 24876797c315SNick Hudson if (a->addr) { 24886797c315SNick Hudson gen_helper_itlba(cpu_env, addr, reg); 24896797c315SNick Hudson } else { 24906797c315SNick Hudson gen_helper_itlbp(cpu_env, addr, reg); 24916797c315SNick Hudson } 24926797c315SNick Hudson 24936797c315SNick Hudson /* Exit TB for TLB change if mmu is enabled. */ 24946797c315SNick Hudson if (ctx->tb_flags & PSW_C) { 24956797c315SNick Hudson ctx->base.is_jmp = DISAS_IAQ_N_STALE; 24966797c315SNick Hudson } 24976797c315SNick Hudson return nullify_end(ctx); 24986797c315SNick Hudson #endif 24996797c315SNick Hudson } 25006797c315SNick Hudson 2501deee69a1SRichard Henderson static bool trans_lpa(DisasContext *ctx, arg_ldst *a) 25022dfcca9fSRichard Henderson { 2503deee69a1SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 2504deee69a1SRichard Henderson #ifndef CONFIG_USER_ONLY 25052dfcca9fSRichard Henderson TCGv_tl vaddr; 25062dfcca9fSRichard Henderson TCGv_reg ofs, paddr; 25072dfcca9fSRichard Henderson 25082dfcca9fSRichard Henderson nullify_over(ctx); 25092dfcca9fSRichard Henderson 2510deee69a1SRichard Henderson form_gva(ctx, &vaddr, &ofs, a->b, a->x, 0, 0, a->sp, a->m, false); 25112dfcca9fSRichard Henderson 25122dfcca9fSRichard Henderson paddr = tcg_temp_new(); 25132dfcca9fSRichard Henderson gen_helper_lpa(paddr, cpu_env, vaddr); 25142dfcca9fSRichard Henderson 25152dfcca9fSRichard Henderson /* Note that physical address result overrides base modification. */ 2516deee69a1SRichard Henderson if (a->m) { 2517deee69a1SRichard Henderson save_gpr(ctx, a->b, ofs); 25182dfcca9fSRichard Henderson } 2519deee69a1SRichard Henderson save_gpr(ctx, a->t, paddr); 25202dfcca9fSRichard Henderson 252131234768SRichard Henderson return nullify_end(ctx); 2522deee69a1SRichard Henderson #endif 25232dfcca9fSRichard Henderson } 252443a97b81SRichard Henderson 2525deee69a1SRichard Henderson static bool trans_lci(DisasContext *ctx, arg_lci *a) 252643a97b81SRichard Henderson { 252743a97b81SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 252843a97b81SRichard Henderson 252943a97b81SRichard Henderson /* The Coherence Index is an implementation-defined function of the 253043a97b81SRichard Henderson physical address. Two addresses with the same CI have a coherent 253143a97b81SRichard Henderson view of the cache. Our implementation is to return 0 for all, 253243a97b81SRichard Henderson since the entire address space is coherent. */ 253329dd6f64SRichard Henderson save_gpr(ctx, a->t, tcg_constant_reg(0)); 253443a97b81SRichard Henderson 253531234768SRichard Henderson cond_free(&ctx->null_cond); 253631234768SRichard Henderson return true; 253743a97b81SRichard Henderson } 253898a9cb79SRichard Henderson 25390c982a28SRichard Henderson static bool trans_add(DisasContext *ctx, arg_rrr_cf_sh *a) 2540b2167459SRichard Henderson { 25410c982a28SRichard Henderson return do_add_reg(ctx, a, false, false, false, false); 2542b2167459SRichard Henderson } 2543b2167459SRichard Henderson 25440c982a28SRichard Henderson static bool trans_add_l(DisasContext *ctx, arg_rrr_cf_sh *a) 2545b2167459SRichard Henderson { 25460c982a28SRichard Henderson return do_add_reg(ctx, a, true, false, false, false); 2547b2167459SRichard Henderson } 2548b2167459SRichard Henderson 25490c982a28SRichard Henderson static bool trans_add_tsv(DisasContext *ctx, arg_rrr_cf_sh *a) 2550b2167459SRichard Henderson { 25510c982a28SRichard Henderson return do_add_reg(ctx, a, false, true, false, false); 2552b2167459SRichard Henderson } 2553b2167459SRichard Henderson 25540c982a28SRichard Henderson static bool trans_add_c(DisasContext *ctx, arg_rrr_cf_sh *a) 2555b2167459SRichard Henderson { 25560c982a28SRichard Henderson return do_add_reg(ctx, a, false, false, false, true); 25570c982a28SRichard Henderson } 2558b2167459SRichard Henderson 25590c982a28SRichard Henderson static bool trans_add_c_tsv(DisasContext *ctx, arg_rrr_cf_sh *a) 25600c982a28SRichard Henderson { 25610c982a28SRichard Henderson return do_add_reg(ctx, a, false, true, false, true); 25620c982a28SRichard Henderson } 25630c982a28SRichard Henderson 25640c982a28SRichard Henderson static bool trans_sub(DisasContext *ctx, arg_rrr_cf *a) 25650c982a28SRichard Henderson { 25660c982a28SRichard Henderson return do_sub_reg(ctx, a, false, false, false); 25670c982a28SRichard Henderson } 25680c982a28SRichard Henderson 25690c982a28SRichard Henderson static bool trans_sub_tsv(DisasContext *ctx, arg_rrr_cf *a) 25700c982a28SRichard Henderson { 25710c982a28SRichard Henderson return do_sub_reg(ctx, a, true, false, false); 25720c982a28SRichard Henderson } 25730c982a28SRichard Henderson 25740c982a28SRichard Henderson static bool trans_sub_tc(DisasContext *ctx, arg_rrr_cf *a) 25750c982a28SRichard Henderson { 25760c982a28SRichard Henderson return do_sub_reg(ctx, a, false, false, true); 25770c982a28SRichard Henderson } 25780c982a28SRichard Henderson 25790c982a28SRichard Henderson static bool trans_sub_tsv_tc(DisasContext *ctx, arg_rrr_cf *a) 25800c982a28SRichard Henderson { 25810c982a28SRichard Henderson return do_sub_reg(ctx, a, true, false, true); 25820c982a28SRichard Henderson } 25830c982a28SRichard Henderson 25840c982a28SRichard Henderson static bool trans_sub_b(DisasContext *ctx, arg_rrr_cf *a) 25850c982a28SRichard Henderson { 25860c982a28SRichard Henderson return do_sub_reg(ctx, a, false, true, false); 25870c982a28SRichard Henderson } 25880c982a28SRichard Henderson 25890c982a28SRichard Henderson static bool trans_sub_b_tsv(DisasContext *ctx, arg_rrr_cf *a) 25900c982a28SRichard Henderson { 25910c982a28SRichard Henderson return do_sub_reg(ctx, a, true, true, false); 25920c982a28SRichard Henderson } 25930c982a28SRichard Henderson 25940c982a28SRichard Henderson static bool trans_andcm(DisasContext *ctx, arg_rrr_cf *a) 25950c982a28SRichard Henderson { 25960c982a28SRichard Henderson return do_log_reg(ctx, a, tcg_gen_andc_reg); 25970c982a28SRichard Henderson } 25980c982a28SRichard Henderson 25990c982a28SRichard Henderson static bool trans_and(DisasContext *ctx, arg_rrr_cf *a) 26000c982a28SRichard Henderson { 26010c982a28SRichard Henderson return do_log_reg(ctx, a, tcg_gen_and_reg); 26020c982a28SRichard Henderson } 26030c982a28SRichard Henderson 26040c982a28SRichard Henderson static bool trans_or(DisasContext *ctx, arg_rrr_cf *a) 26050c982a28SRichard Henderson { 26060c982a28SRichard Henderson if (a->cf == 0) { 26070c982a28SRichard Henderson unsigned r2 = a->r2; 26080c982a28SRichard Henderson unsigned r1 = a->r1; 26090c982a28SRichard Henderson unsigned rt = a->t; 26100c982a28SRichard Henderson 26117aee8189SRichard Henderson if (rt == 0) { /* NOP */ 26127aee8189SRichard Henderson cond_free(&ctx->null_cond); 26137aee8189SRichard Henderson return true; 26147aee8189SRichard Henderson } 26157aee8189SRichard Henderson if (r2 == 0) { /* COPY */ 2616b2167459SRichard Henderson if (r1 == 0) { 2617eaa3783bSRichard Henderson TCGv_reg dest = dest_gpr(ctx, rt); 2618eaa3783bSRichard Henderson tcg_gen_movi_reg(dest, 0); 2619b2167459SRichard Henderson save_gpr(ctx, rt, dest); 2620b2167459SRichard Henderson } else { 2621b2167459SRichard Henderson save_gpr(ctx, rt, cpu_gr[r1]); 2622b2167459SRichard Henderson } 2623b2167459SRichard Henderson cond_free(&ctx->null_cond); 262431234768SRichard Henderson return true; 2625b2167459SRichard Henderson } 26267aee8189SRichard Henderson #ifndef CONFIG_USER_ONLY 26277aee8189SRichard Henderson /* These are QEMU extensions and are nops in the real architecture: 26287aee8189SRichard Henderson * 26297aee8189SRichard Henderson * or %r10,%r10,%r10 -- idle loop; wait for interrupt 26307aee8189SRichard Henderson * or %r31,%r31,%r31 -- death loop; offline cpu 26317aee8189SRichard Henderson * currently implemented as idle. 26327aee8189SRichard Henderson */ 26337aee8189SRichard Henderson if ((rt == 10 || rt == 31) && r1 == rt && r2 == rt) { /* PAUSE */ 26347aee8189SRichard Henderson /* No need to check for supervisor, as userland can only pause 26357aee8189SRichard Henderson until the next timer interrupt. */ 26367aee8189SRichard Henderson nullify_over(ctx); 26377aee8189SRichard Henderson 26387aee8189SRichard Henderson /* Advance the instruction queue. */ 26397aee8189SRichard Henderson copy_iaoq_entry(cpu_iaoq_f, ctx->iaoq_b, cpu_iaoq_b); 26407aee8189SRichard Henderson copy_iaoq_entry(cpu_iaoq_b, ctx->iaoq_n, ctx->iaoq_n_var); 26417aee8189SRichard Henderson nullify_set(ctx, 0); 26427aee8189SRichard Henderson 26437aee8189SRichard Henderson /* Tell the qemu main loop to halt until this cpu has work. */ 264429dd6f64SRichard Henderson tcg_gen_st_i32(tcg_constant_i32(1), cpu_env, 264529dd6f64SRichard Henderson offsetof(CPUState, halted) - offsetof(HPPACPU, env)); 26467aee8189SRichard Henderson gen_excp_1(EXCP_HALTED); 26477aee8189SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 26487aee8189SRichard Henderson 26497aee8189SRichard Henderson return nullify_end(ctx); 26507aee8189SRichard Henderson } 26517aee8189SRichard Henderson #endif 26527aee8189SRichard Henderson } 26530c982a28SRichard Henderson return do_log_reg(ctx, a, tcg_gen_or_reg); 26547aee8189SRichard Henderson } 2655b2167459SRichard Henderson 26560c982a28SRichard Henderson static bool trans_xor(DisasContext *ctx, arg_rrr_cf *a) 2657b2167459SRichard Henderson { 26580c982a28SRichard Henderson return do_log_reg(ctx, a, tcg_gen_xor_reg); 26590c982a28SRichard Henderson } 26600c982a28SRichard Henderson 26610c982a28SRichard Henderson static bool trans_cmpclr(DisasContext *ctx, arg_rrr_cf *a) 26620c982a28SRichard Henderson { 2663eaa3783bSRichard Henderson TCGv_reg tcg_r1, tcg_r2; 2664b2167459SRichard Henderson 26650c982a28SRichard Henderson if (a->cf) { 2666b2167459SRichard Henderson nullify_over(ctx); 2667b2167459SRichard Henderson } 26680c982a28SRichard Henderson tcg_r1 = load_gpr(ctx, a->r1); 26690c982a28SRichard Henderson tcg_r2 = load_gpr(ctx, a->r2); 26700c982a28SRichard Henderson do_cmpclr(ctx, a->t, tcg_r1, tcg_r2, a->cf); 267131234768SRichard Henderson return nullify_end(ctx); 2672b2167459SRichard Henderson } 2673b2167459SRichard Henderson 26740c982a28SRichard Henderson static bool trans_uxor(DisasContext *ctx, arg_rrr_cf *a) 2675b2167459SRichard Henderson { 2676eaa3783bSRichard Henderson TCGv_reg tcg_r1, tcg_r2; 2677b2167459SRichard Henderson 26780c982a28SRichard Henderson if (a->cf) { 2679b2167459SRichard Henderson nullify_over(ctx); 2680b2167459SRichard Henderson } 26810c982a28SRichard Henderson tcg_r1 = load_gpr(ctx, a->r1); 26820c982a28SRichard Henderson tcg_r2 = load_gpr(ctx, a->r2); 26830c982a28SRichard Henderson do_unit(ctx, a->t, tcg_r1, tcg_r2, a->cf, false, tcg_gen_xor_reg); 268431234768SRichard Henderson return nullify_end(ctx); 2685b2167459SRichard Henderson } 2686b2167459SRichard Henderson 26870c982a28SRichard Henderson static bool do_uaddcm(DisasContext *ctx, arg_rrr_cf *a, bool is_tc) 2688b2167459SRichard Henderson { 2689eaa3783bSRichard Henderson TCGv_reg tcg_r1, tcg_r2, tmp; 2690b2167459SRichard Henderson 26910c982a28SRichard Henderson if (a->cf) { 2692b2167459SRichard Henderson nullify_over(ctx); 2693b2167459SRichard Henderson } 26940c982a28SRichard Henderson tcg_r1 = load_gpr(ctx, a->r1); 26950c982a28SRichard Henderson tcg_r2 = load_gpr(ctx, a->r2); 2696b2167459SRichard Henderson tmp = get_temp(ctx); 2697eaa3783bSRichard Henderson tcg_gen_not_reg(tmp, tcg_r2); 26980c982a28SRichard Henderson do_unit(ctx, a->t, tcg_r1, tmp, a->cf, is_tc, tcg_gen_add_reg); 269931234768SRichard Henderson return nullify_end(ctx); 2700b2167459SRichard Henderson } 2701b2167459SRichard Henderson 27020c982a28SRichard Henderson static bool trans_uaddcm(DisasContext *ctx, arg_rrr_cf *a) 2703b2167459SRichard Henderson { 27040c982a28SRichard Henderson return do_uaddcm(ctx, a, false); 27050c982a28SRichard Henderson } 27060c982a28SRichard Henderson 27070c982a28SRichard Henderson static bool trans_uaddcm_tc(DisasContext *ctx, arg_rrr_cf *a) 27080c982a28SRichard Henderson { 27090c982a28SRichard Henderson return do_uaddcm(ctx, a, true); 27100c982a28SRichard Henderson } 27110c982a28SRichard Henderson 27120c982a28SRichard Henderson static bool do_dcor(DisasContext *ctx, arg_rr_cf *a, bool is_i) 27130c982a28SRichard Henderson { 2714eaa3783bSRichard Henderson TCGv_reg tmp; 2715b2167459SRichard Henderson 2716b2167459SRichard Henderson nullify_over(ctx); 2717b2167459SRichard Henderson 2718b2167459SRichard Henderson tmp = get_temp(ctx); 2719eaa3783bSRichard Henderson tcg_gen_shri_reg(tmp, cpu_psw_cb, 3); 2720b2167459SRichard Henderson if (!is_i) { 2721eaa3783bSRichard Henderson tcg_gen_not_reg(tmp, tmp); 2722b2167459SRichard Henderson } 2723eaa3783bSRichard Henderson tcg_gen_andi_reg(tmp, tmp, 0x11111111); 2724eaa3783bSRichard Henderson tcg_gen_muli_reg(tmp, tmp, 6); 272560e29463SSven Schnelle do_unit(ctx, a->t, load_gpr(ctx, a->r), tmp, a->cf, false, 2726eaa3783bSRichard Henderson is_i ? tcg_gen_add_reg : tcg_gen_sub_reg); 272731234768SRichard Henderson return nullify_end(ctx); 2728b2167459SRichard Henderson } 2729b2167459SRichard Henderson 27300c982a28SRichard Henderson static bool trans_dcor(DisasContext *ctx, arg_rr_cf *a) 2731b2167459SRichard Henderson { 27320c982a28SRichard Henderson return do_dcor(ctx, a, false); 27330c982a28SRichard Henderson } 27340c982a28SRichard Henderson 27350c982a28SRichard Henderson static bool trans_dcor_i(DisasContext *ctx, arg_rr_cf *a) 27360c982a28SRichard Henderson { 27370c982a28SRichard Henderson return do_dcor(ctx, a, true); 27380c982a28SRichard Henderson } 27390c982a28SRichard Henderson 27400c982a28SRichard Henderson static bool trans_ds(DisasContext *ctx, arg_rrr_cf *a) 27410c982a28SRichard Henderson { 2742eaa3783bSRichard Henderson TCGv_reg dest, add1, add2, addc, zero, in1, in2; 2743b2167459SRichard Henderson 2744b2167459SRichard Henderson nullify_over(ctx); 2745b2167459SRichard Henderson 27460c982a28SRichard Henderson in1 = load_gpr(ctx, a->r1); 27470c982a28SRichard Henderson in2 = load_gpr(ctx, a->r2); 2748b2167459SRichard Henderson 2749b2167459SRichard Henderson add1 = tcg_temp_new(); 2750b2167459SRichard Henderson add2 = tcg_temp_new(); 2751b2167459SRichard Henderson addc = tcg_temp_new(); 2752b2167459SRichard Henderson dest = tcg_temp_new(); 275329dd6f64SRichard Henderson zero = tcg_constant_reg(0); 2754b2167459SRichard Henderson 2755b2167459SRichard Henderson /* Form R1 << 1 | PSW[CB]{8}. */ 2756eaa3783bSRichard Henderson tcg_gen_add_reg(add1, in1, in1); 2757eaa3783bSRichard Henderson tcg_gen_add_reg(add1, add1, cpu_psw_cb_msb); 2758b2167459SRichard Henderson 2759b2167459SRichard Henderson /* Add or subtract R2, depending on PSW[V]. Proper computation of 2760b2167459SRichard Henderson carry{8} requires that we subtract via + ~R2 + 1, as described in 2761b2167459SRichard Henderson the manual. By extracting and masking V, we can produce the 2762b2167459SRichard Henderson proper inputs to the addition without movcond. */ 2763eaa3783bSRichard Henderson tcg_gen_sari_reg(addc, cpu_psw_v, TARGET_REGISTER_BITS - 1); 2764eaa3783bSRichard Henderson tcg_gen_xor_reg(add2, in2, addc); 2765eaa3783bSRichard Henderson tcg_gen_andi_reg(addc, addc, 1); 2766b2167459SRichard Henderson /* ??? This is only correct for 32-bit. */ 2767b2167459SRichard Henderson tcg_gen_add2_i32(dest, cpu_psw_cb_msb, add1, zero, add2, zero); 2768b2167459SRichard Henderson tcg_gen_add2_i32(dest, cpu_psw_cb_msb, dest, cpu_psw_cb_msb, addc, zero); 2769b2167459SRichard Henderson 2770b2167459SRichard Henderson /* Write back the result register. */ 27710c982a28SRichard Henderson save_gpr(ctx, a->t, dest); 2772b2167459SRichard Henderson 2773b2167459SRichard Henderson /* Write back PSW[CB]. */ 2774eaa3783bSRichard Henderson tcg_gen_xor_reg(cpu_psw_cb, add1, add2); 2775eaa3783bSRichard Henderson tcg_gen_xor_reg(cpu_psw_cb, cpu_psw_cb, dest); 2776b2167459SRichard Henderson 2777b2167459SRichard Henderson /* Write back PSW[V] for the division step. */ 2778eaa3783bSRichard Henderson tcg_gen_neg_reg(cpu_psw_v, cpu_psw_cb_msb); 2779eaa3783bSRichard Henderson tcg_gen_xor_reg(cpu_psw_v, cpu_psw_v, in2); 2780b2167459SRichard Henderson 2781b2167459SRichard Henderson /* Install the new nullification. */ 27820c982a28SRichard Henderson if (a->cf) { 2783eaa3783bSRichard Henderson TCGv_reg sv = NULL; 2784b47a4a02SSven Schnelle if (cond_need_sv(a->cf >> 1)) { 2785b2167459SRichard Henderson /* ??? The lshift is supposed to contribute to overflow. */ 2786b2167459SRichard Henderson sv = do_add_sv(ctx, dest, add1, add2); 2787b2167459SRichard Henderson } 27880c982a28SRichard Henderson ctx->null_cond = do_cond(a->cf, dest, cpu_psw_cb_msb, sv); 2789b2167459SRichard Henderson } 2790b2167459SRichard Henderson 279131234768SRichard Henderson return nullify_end(ctx); 2792b2167459SRichard Henderson } 2793b2167459SRichard Henderson 27940588e061SRichard Henderson static bool trans_addi(DisasContext *ctx, arg_rri_cf *a) 2795b2167459SRichard Henderson { 27960588e061SRichard Henderson return do_add_imm(ctx, a, false, false); 27970588e061SRichard Henderson } 27980588e061SRichard Henderson 27990588e061SRichard Henderson static bool trans_addi_tsv(DisasContext *ctx, arg_rri_cf *a) 28000588e061SRichard Henderson { 28010588e061SRichard Henderson return do_add_imm(ctx, a, true, false); 28020588e061SRichard Henderson } 28030588e061SRichard Henderson 28040588e061SRichard Henderson static bool trans_addi_tc(DisasContext *ctx, arg_rri_cf *a) 28050588e061SRichard Henderson { 28060588e061SRichard Henderson return do_add_imm(ctx, a, false, true); 28070588e061SRichard Henderson } 28080588e061SRichard Henderson 28090588e061SRichard Henderson static bool trans_addi_tc_tsv(DisasContext *ctx, arg_rri_cf *a) 28100588e061SRichard Henderson { 28110588e061SRichard Henderson return do_add_imm(ctx, a, true, true); 28120588e061SRichard Henderson } 28130588e061SRichard Henderson 28140588e061SRichard Henderson static bool trans_subi(DisasContext *ctx, arg_rri_cf *a) 28150588e061SRichard Henderson { 28160588e061SRichard Henderson return do_sub_imm(ctx, a, false); 28170588e061SRichard Henderson } 28180588e061SRichard Henderson 28190588e061SRichard Henderson static bool trans_subi_tsv(DisasContext *ctx, arg_rri_cf *a) 28200588e061SRichard Henderson { 28210588e061SRichard Henderson return do_sub_imm(ctx, a, true); 28220588e061SRichard Henderson } 28230588e061SRichard Henderson 28240588e061SRichard Henderson static bool trans_cmpiclr(DisasContext *ctx, arg_rri_cf *a) 28250588e061SRichard Henderson { 2826eaa3783bSRichard Henderson TCGv_reg tcg_im, tcg_r2; 2827b2167459SRichard Henderson 28280588e061SRichard Henderson if (a->cf) { 2829b2167459SRichard Henderson nullify_over(ctx); 2830b2167459SRichard Henderson } 2831b2167459SRichard Henderson 28320588e061SRichard Henderson tcg_im = load_const(ctx, a->i); 28330588e061SRichard Henderson tcg_r2 = load_gpr(ctx, a->r); 28340588e061SRichard Henderson do_cmpclr(ctx, a->t, tcg_im, tcg_r2, a->cf); 2835b2167459SRichard Henderson 283631234768SRichard Henderson return nullify_end(ctx); 2837b2167459SRichard Henderson } 2838b2167459SRichard Henderson 28391cd012a5SRichard Henderson static bool trans_ld(DisasContext *ctx, arg_ldst *a) 284096d6407fSRichard Henderson { 28410786a3b6SHelge Deller if (unlikely(TARGET_REGISTER_BITS == 32 && a->size > MO_32)) { 28420786a3b6SHelge Deller return gen_illegal(ctx); 28430786a3b6SHelge Deller } else { 28441cd012a5SRichard Henderson return do_load(ctx, a->t, a->b, a->x, a->scale ? a->size : 0, 28451cd012a5SRichard Henderson a->disp, a->sp, a->m, a->size | MO_TE); 284696d6407fSRichard Henderson } 28470786a3b6SHelge Deller } 284896d6407fSRichard Henderson 28491cd012a5SRichard Henderson static bool trans_st(DisasContext *ctx, arg_ldst *a) 285096d6407fSRichard Henderson { 28511cd012a5SRichard Henderson assert(a->x == 0 && a->scale == 0); 28520786a3b6SHelge Deller if (unlikely(TARGET_REGISTER_BITS == 32 && a->size > MO_32)) { 28530786a3b6SHelge Deller return gen_illegal(ctx); 28540786a3b6SHelge Deller } else { 28551cd012a5SRichard Henderson return do_store(ctx, a->t, a->b, a->disp, a->sp, a->m, a->size | MO_TE); 285696d6407fSRichard Henderson } 28570786a3b6SHelge Deller } 285896d6407fSRichard Henderson 28591cd012a5SRichard Henderson static bool trans_ldc(DisasContext *ctx, arg_ldst *a) 286096d6407fSRichard Henderson { 2861b1af755cSRichard Henderson MemOp mop = MO_TE | MO_ALIGN | a->size; 286286f8d05fSRichard Henderson TCGv_reg zero, dest, ofs; 286386f8d05fSRichard Henderson TCGv_tl addr; 286496d6407fSRichard Henderson 286596d6407fSRichard Henderson nullify_over(ctx); 286696d6407fSRichard Henderson 28671cd012a5SRichard Henderson if (a->m) { 286886f8d05fSRichard Henderson /* Base register modification. Make sure if RT == RB, 286986f8d05fSRichard Henderson we see the result of the load. */ 287096d6407fSRichard Henderson dest = get_temp(ctx); 287196d6407fSRichard Henderson } else { 28721cd012a5SRichard Henderson dest = dest_gpr(ctx, a->t); 287396d6407fSRichard Henderson } 287496d6407fSRichard Henderson 28751cd012a5SRichard Henderson form_gva(ctx, &addr, &ofs, a->b, a->x, a->scale ? a->size : 0, 28761cd012a5SRichard Henderson a->disp, a->sp, a->m, ctx->mmu_idx == MMU_PHYS_IDX); 2877b1af755cSRichard Henderson 2878b1af755cSRichard Henderson /* 2879b1af755cSRichard Henderson * For hppa1.1, LDCW is undefined unless aligned mod 16. 2880b1af755cSRichard Henderson * However actual hardware succeeds with aligned mod 4. 2881b1af755cSRichard Henderson * Detect this case and log a GUEST_ERROR. 2882b1af755cSRichard Henderson * 2883b1af755cSRichard Henderson * TODO: HPPA64 relaxes the over-alignment requirement 2884b1af755cSRichard Henderson * with the ,co completer. 2885b1af755cSRichard Henderson */ 2886b1af755cSRichard Henderson gen_helper_ldc_check(addr); 2887b1af755cSRichard Henderson 288829dd6f64SRichard Henderson zero = tcg_constant_reg(0); 288986f8d05fSRichard Henderson tcg_gen_atomic_xchg_reg(dest, addr, zero, ctx->mmu_idx, mop); 2890b1af755cSRichard Henderson 28911cd012a5SRichard Henderson if (a->m) { 28921cd012a5SRichard Henderson save_gpr(ctx, a->b, ofs); 289396d6407fSRichard Henderson } 28941cd012a5SRichard Henderson save_gpr(ctx, a->t, dest); 289596d6407fSRichard Henderson 289631234768SRichard Henderson return nullify_end(ctx); 289796d6407fSRichard Henderson } 289896d6407fSRichard Henderson 28991cd012a5SRichard Henderson static bool trans_stby(DisasContext *ctx, arg_stby *a) 290096d6407fSRichard Henderson { 290186f8d05fSRichard Henderson TCGv_reg ofs, val; 290286f8d05fSRichard Henderson TCGv_tl addr; 290396d6407fSRichard Henderson 290496d6407fSRichard Henderson nullify_over(ctx); 290596d6407fSRichard Henderson 29061cd012a5SRichard Henderson form_gva(ctx, &addr, &ofs, a->b, 0, 0, a->disp, a->sp, a->m, 290786f8d05fSRichard Henderson ctx->mmu_idx == MMU_PHYS_IDX); 29081cd012a5SRichard Henderson val = load_gpr(ctx, a->r); 29091cd012a5SRichard Henderson if (a->a) { 2910f9f46db4SEmilio G. Cota if (tb_cflags(ctx->base.tb) & CF_PARALLEL) { 2911f9f46db4SEmilio G. Cota gen_helper_stby_e_parallel(cpu_env, addr, val); 2912f9f46db4SEmilio G. Cota } else { 291396d6407fSRichard Henderson gen_helper_stby_e(cpu_env, addr, val); 2914f9f46db4SEmilio G. Cota } 2915f9f46db4SEmilio G. Cota } else { 2916f9f46db4SEmilio G. Cota if (tb_cflags(ctx->base.tb) & CF_PARALLEL) { 2917f9f46db4SEmilio G. Cota gen_helper_stby_b_parallel(cpu_env, addr, val); 291896d6407fSRichard Henderson } else { 291996d6407fSRichard Henderson gen_helper_stby_b(cpu_env, addr, val); 292096d6407fSRichard Henderson } 2921f9f46db4SEmilio G. Cota } 29221cd012a5SRichard Henderson if (a->m) { 292386f8d05fSRichard Henderson tcg_gen_andi_reg(ofs, ofs, ~3); 29241cd012a5SRichard Henderson save_gpr(ctx, a->b, ofs); 292596d6407fSRichard Henderson } 292696d6407fSRichard Henderson 292731234768SRichard Henderson return nullify_end(ctx); 292896d6407fSRichard Henderson } 292996d6407fSRichard Henderson 29301cd012a5SRichard Henderson static bool trans_lda(DisasContext *ctx, arg_ldst *a) 2931d0a851ccSRichard Henderson { 2932d0a851ccSRichard Henderson int hold_mmu_idx = ctx->mmu_idx; 2933d0a851ccSRichard Henderson 2934d0a851ccSRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 2935d0a851ccSRichard Henderson ctx->mmu_idx = MMU_PHYS_IDX; 29361cd012a5SRichard Henderson trans_ld(ctx, a); 2937d0a851ccSRichard Henderson ctx->mmu_idx = hold_mmu_idx; 293831234768SRichard Henderson return true; 2939d0a851ccSRichard Henderson } 2940d0a851ccSRichard Henderson 29411cd012a5SRichard Henderson static bool trans_sta(DisasContext *ctx, arg_ldst *a) 2942d0a851ccSRichard Henderson { 2943d0a851ccSRichard Henderson int hold_mmu_idx = ctx->mmu_idx; 2944d0a851ccSRichard Henderson 2945d0a851ccSRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 2946d0a851ccSRichard Henderson ctx->mmu_idx = MMU_PHYS_IDX; 29471cd012a5SRichard Henderson trans_st(ctx, a); 2948d0a851ccSRichard Henderson ctx->mmu_idx = hold_mmu_idx; 294931234768SRichard Henderson return true; 2950d0a851ccSRichard Henderson } 295195412a61SRichard Henderson 29520588e061SRichard Henderson static bool trans_ldil(DisasContext *ctx, arg_ldil *a) 2953b2167459SRichard Henderson { 29540588e061SRichard Henderson TCGv_reg tcg_rt = dest_gpr(ctx, a->t); 2955b2167459SRichard Henderson 29560588e061SRichard Henderson tcg_gen_movi_reg(tcg_rt, a->i); 29570588e061SRichard Henderson save_gpr(ctx, a->t, tcg_rt); 2958b2167459SRichard Henderson cond_free(&ctx->null_cond); 295931234768SRichard Henderson return true; 2960b2167459SRichard Henderson } 2961b2167459SRichard Henderson 29620588e061SRichard Henderson static bool trans_addil(DisasContext *ctx, arg_addil *a) 2963b2167459SRichard Henderson { 29640588e061SRichard Henderson TCGv_reg tcg_rt = load_gpr(ctx, a->r); 2965eaa3783bSRichard Henderson TCGv_reg tcg_r1 = dest_gpr(ctx, 1); 2966b2167459SRichard Henderson 29670588e061SRichard Henderson tcg_gen_addi_reg(tcg_r1, tcg_rt, a->i); 2968b2167459SRichard Henderson save_gpr(ctx, 1, tcg_r1); 2969b2167459SRichard Henderson cond_free(&ctx->null_cond); 297031234768SRichard Henderson return true; 2971b2167459SRichard Henderson } 2972b2167459SRichard Henderson 29730588e061SRichard Henderson static bool trans_ldo(DisasContext *ctx, arg_ldo *a) 2974b2167459SRichard Henderson { 29750588e061SRichard Henderson TCGv_reg tcg_rt = dest_gpr(ctx, a->t); 2976b2167459SRichard Henderson 2977b2167459SRichard Henderson /* Special case rb == 0, for the LDI pseudo-op. 2978b2167459SRichard Henderson The COPY pseudo-op is handled for free within tcg_gen_addi_tl. */ 29790588e061SRichard Henderson if (a->b == 0) { 29800588e061SRichard Henderson tcg_gen_movi_reg(tcg_rt, a->i); 2981b2167459SRichard Henderson } else { 29820588e061SRichard Henderson tcg_gen_addi_reg(tcg_rt, cpu_gr[a->b], a->i); 2983b2167459SRichard Henderson } 29840588e061SRichard Henderson save_gpr(ctx, a->t, tcg_rt); 2985b2167459SRichard Henderson cond_free(&ctx->null_cond); 298631234768SRichard Henderson return true; 2987b2167459SRichard Henderson } 2988b2167459SRichard Henderson 298901afb7beSRichard Henderson static bool do_cmpb(DisasContext *ctx, unsigned r, TCGv_reg in1, 299001afb7beSRichard Henderson unsigned c, unsigned f, unsigned n, int disp) 299198cd9ca7SRichard Henderson { 299201afb7beSRichard Henderson TCGv_reg dest, in2, sv; 299398cd9ca7SRichard Henderson DisasCond cond; 299498cd9ca7SRichard Henderson 299598cd9ca7SRichard Henderson in2 = load_gpr(ctx, r); 299698cd9ca7SRichard Henderson dest = get_temp(ctx); 299798cd9ca7SRichard Henderson 2998eaa3783bSRichard Henderson tcg_gen_sub_reg(dest, in1, in2); 299998cd9ca7SRichard Henderson 3000f764718dSRichard Henderson sv = NULL; 3001b47a4a02SSven Schnelle if (cond_need_sv(c)) { 300298cd9ca7SRichard Henderson sv = do_sub_sv(ctx, dest, in1, in2); 300398cd9ca7SRichard Henderson } 300498cd9ca7SRichard Henderson 300501afb7beSRichard Henderson cond = do_sub_cond(c * 2 + f, dest, in1, in2, sv); 300601afb7beSRichard Henderson return do_cbranch(ctx, disp, n, &cond); 300798cd9ca7SRichard Henderson } 300898cd9ca7SRichard Henderson 300901afb7beSRichard Henderson static bool trans_cmpb(DisasContext *ctx, arg_cmpb *a) 301098cd9ca7SRichard Henderson { 301101afb7beSRichard Henderson nullify_over(ctx); 301201afb7beSRichard Henderson return do_cmpb(ctx, a->r2, load_gpr(ctx, a->r1), a->c, a->f, a->n, a->disp); 301301afb7beSRichard Henderson } 301401afb7beSRichard Henderson 301501afb7beSRichard Henderson static bool trans_cmpbi(DisasContext *ctx, arg_cmpbi *a) 301601afb7beSRichard Henderson { 301701afb7beSRichard Henderson nullify_over(ctx); 301801afb7beSRichard Henderson return do_cmpb(ctx, a->r, load_const(ctx, a->i), a->c, a->f, a->n, a->disp); 301901afb7beSRichard Henderson } 302001afb7beSRichard Henderson 302101afb7beSRichard Henderson static bool do_addb(DisasContext *ctx, unsigned r, TCGv_reg in1, 302201afb7beSRichard Henderson unsigned c, unsigned f, unsigned n, int disp) 302301afb7beSRichard Henderson { 302401afb7beSRichard Henderson TCGv_reg dest, in2, sv, cb_msb; 302598cd9ca7SRichard Henderson DisasCond cond; 302698cd9ca7SRichard Henderson 302798cd9ca7SRichard Henderson in2 = load_gpr(ctx, r); 302843675d20SSven Schnelle dest = tcg_temp_new(); 3029f764718dSRichard Henderson sv = NULL; 3030f764718dSRichard Henderson cb_msb = NULL; 303198cd9ca7SRichard Henderson 3032b47a4a02SSven Schnelle if (cond_need_cb(c)) { 303398cd9ca7SRichard Henderson cb_msb = get_temp(ctx); 3034eaa3783bSRichard Henderson tcg_gen_movi_reg(cb_msb, 0); 3035eaa3783bSRichard Henderson tcg_gen_add2_reg(dest, cb_msb, in1, cb_msb, in2, cb_msb); 3036b47a4a02SSven Schnelle } else { 3037eaa3783bSRichard Henderson tcg_gen_add_reg(dest, in1, in2); 3038b47a4a02SSven Schnelle } 3039b47a4a02SSven Schnelle if (cond_need_sv(c)) { 304098cd9ca7SRichard Henderson sv = do_add_sv(ctx, dest, in1, in2); 304198cd9ca7SRichard Henderson } 304298cd9ca7SRichard Henderson 304301afb7beSRichard Henderson cond = do_cond(c * 2 + f, dest, cb_msb, sv); 304443675d20SSven Schnelle save_gpr(ctx, r, dest); 304501afb7beSRichard Henderson return do_cbranch(ctx, disp, n, &cond); 304698cd9ca7SRichard Henderson } 304798cd9ca7SRichard Henderson 304801afb7beSRichard Henderson static bool trans_addb(DisasContext *ctx, arg_addb *a) 304998cd9ca7SRichard Henderson { 305001afb7beSRichard Henderson nullify_over(ctx); 305101afb7beSRichard Henderson return do_addb(ctx, a->r2, load_gpr(ctx, a->r1), a->c, a->f, a->n, a->disp); 305201afb7beSRichard Henderson } 305301afb7beSRichard Henderson 305401afb7beSRichard Henderson static bool trans_addbi(DisasContext *ctx, arg_addbi *a) 305501afb7beSRichard Henderson { 305601afb7beSRichard Henderson nullify_over(ctx); 305701afb7beSRichard Henderson return do_addb(ctx, a->r, load_const(ctx, a->i), a->c, a->f, a->n, a->disp); 305801afb7beSRichard Henderson } 305901afb7beSRichard Henderson 306001afb7beSRichard Henderson static bool trans_bb_sar(DisasContext *ctx, arg_bb_sar *a) 306101afb7beSRichard Henderson { 3062eaa3783bSRichard Henderson TCGv_reg tmp, tcg_r; 306398cd9ca7SRichard Henderson DisasCond cond; 306498cd9ca7SRichard Henderson 306598cd9ca7SRichard Henderson nullify_over(ctx); 306698cd9ca7SRichard Henderson 306798cd9ca7SRichard Henderson tmp = tcg_temp_new(); 306801afb7beSRichard Henderson tcg_r = load_gpr(ctx, a->r); 3069eaa3783bSRichard Henderson tcg_gen_shl_reg(tmp, tcg_r, cpu_sar); 307098cd9ca7SRichard Henderson 307101afb7beSRichard Henderson cond = cond_make_0(a->c ? TCG_COND_GE : TCG_COND_LT, tmp); 307201afb7beSRichard Henderson return do_cbranch(ctx, a->disp, a->n, &cond); 307398cd9ca7SRichard Henderson } 307498cd9ca7SRichard Henderson 307501afb7beSRichard Henderson static bool trans_bb_imm(DisasContext *ctx, arg_bb_imm *a) 307698cd9ca7SRichard Henderson { 307701afb7beSRichard Henderson TCGv_reg tmp, tcg_r; 307801afb7beSRichard Henderson DisasCond cond; 307901afb7beSRichard Henderson 308001afb7beSRichard Henderson nullify_over(ctx); 308101afb7beSRichard Henderson 308201afb7beSRichard Henderson tmp = tcg_temp_new(); 308301afb7beSRichard Henderson tcg_r = load_gpr(ctx, a->r); 308401afb7beSRichard Henderson tcg_gen_shli_reg(tmp, tcg_r, a->p); 308501afb7beSRichard Henderson 308601afb7beSRichard Henderson cond = cond_make_0(a->c ? TCG_COND_GE : TCG_COND_LT, tmp); 308701afb7beSRichard Henderson return do_cbranch(ctx, a->disp, a->n, &cond); 308801afb7beSRichard Henderson } 308901afb7beSRichard Henderson 309001afb7beSRichard Henderson static bool trans_movb(DisasContext *ctx, arg_movb *a) 309101afb7beSRichard Henderson { 3092eaa3783bSRichard Henderson TCGv_reg dest; 309398cd9ca7SRichard Henderson DisasCond cond; 309498cd9ca7SRichard Henderson 309598cd9ca7SRichard Henderson nullify_over(ctx); 309698cd9ca7SRichard Henderson 309701afb7beSRichard Henderson dest = dest_gpr(ctx, a->r2); 309801afb7beSRichard Henderson if (a->r1 == 0) { 3099eaa3783bSRichard Henderson tcg_gen_movi_reg(dest, 0); 310098cd9ca7SRichard Henderson } else { 310101afb7beSRichard Henderson tcg_gen_mov_reg(dest, cpu_gr[a->r1]); 310298cd9ca7SRichard Henderson } 310398cd9ca7SRichard Henderson 310401afb7beSRichard Henderson cond = do_sed_cond(a->c, dest); 310501afb7beSRichard Henderson return do_cbranch(ctx, a->disp, a->n, &cond); 310601afb7beSRichard Henderson } 310701afb7beSRichard Henderson 310801afb7beSRichard Henderson static bool trans_movbi(DisasContext *ctx, arg_movbi *a) 310901afb7beSRichard Henderson { 311001afb7beSRichard Henderson TCGv_reg dest; 311101afb7beSRichard Henderson DisasCond cond; 311201afb7beSRichard Henderson 311301afb7beSRichard Henderson nullify_over(ctx); 311401afb7beSRichard Henderson 311501afb7beSRichard Henderson dest = dest_gpr(ctx, a->r); 311601afb7beSRichard Henderson tcg_gen_movi_reg(dest, a->i); 311701afb7beSRichard Henderson 311801afb7beSRichard Henderson cond = do_sed_cond(a->c, dest); 311901afb7beSRichard Henderson return do_cbranch(ctx, a->disp, a->n, &cond); 312098cd9ca7SRichard Henderson } 312198cd9ca7SRichard Henderson 312230878590SRichard Henderson static bool trans_shrpw_sar(DisasContext *ctx, arg_shrpw_sar *a) 31230b1347d2SRichard Henderson { 3124eaa3783bSRichard Henderson TCGv_reg dest; 31250b1347d2SRichard Henderson 312630878590SRichard Henderson if (a->c) { 31270b1347d2SRichard Henderson nullify_over(ctx); 31280b1347d2SRichard Henderson } 31290b1347d2SRichard Henderson 313030878590SRichard Henderson dest = dest_gpr(ctx, a->t); 313130878590SRichard Henderson if (a->r1 == 0) { 313230878590SRichard Henderson tcg_gen_ext32u_reg(dest, load_gpr(ctx, a->r2)); 3133eaa3783bSRichard Henderson tcg_gen_shr_reg(dest, dest, cpu_sar); 313430878590SRichard Henderson } else if (a->r1 == a->r2) { 31350b1347d2SRichard Henderson TCGv_i32 t32 = tcg_temp_new_i32(); 313630878590SRichard Henderson tcg_gen_trunc_reg_i32(t32, load_gpr(ctx, a->r2)); 31370b1347d2SRichard Henderson tcg_gen_rotr_i32(t32, t32, cpu_sar); 3138eaa3783bSRichard Henderson tcg_gen_extu_i32_reg(dest, t32); 31390b1347d2SRichard Henderson } else { 31400b1347d2SRichard Henderson TCGv_i64 t = tcg_temp_new_i64(); 31410b1347d2SRichard Henderson TCGv_i64 s = tcg_temp_new_i64(); 31420b1347d2SRichard Henderson 314330878590SRichard Henderson tcg_gen_concat_reg_i64(t, load_gpr(ctx, a->r2), load_gpr(ctx, a->r1)); 3144eaa3783bSRichard Henderson tcg_gen_extu_reg_i64(s, cpu_sar); 31450b1347d2SRichard Henderson tcg_gen_shr_i64(t, t, s); 3146eaa3783bSRichard Henderson tcg_gen_trunc_i64_reg(dest, t); 31470b1347d2SRichard Henderson } 314830878590SRichard Henderson save_gpr(ctx, a->t, dest); 31490b1347d2SRichard Henderson 31500b1347d2SRichard Henderson /* Install the new nullification. */ 31510b1347d2SRichard Henderson cond_free(&ctx->null_cond); 315230878590SRichard Henderson if (a->c) { 315330878590SRichard Henderson ctx->null_cond = do_sed_cond(a->c, dest); 31540b1347d2SRichard Henderson } 315531234768SRichard Henderson return nullify_end(ctx); 31560b1347d2SRichard Henderson } 31570b1347d2SRichard Henderson 315830878590SRichard Henderson static bool trans_shrpw_imm(DisasContext *ctx, arg_shrpw_imm *a) 31590b1347d2SRichard Henderson { 316030878590SRichard Henderson unsigned sa = 31 - a->cpos; 3161eaa3783bSRichard Henderson TCGv_reg dest, t2; 31620b1347d2SRichard Henderson 316330878590SRichard Henderson if (a->c) { 31640b1347d2SRichard Henderson nullify_over(ctx); 31650b1347d2SRichard Henderson } 31660b1347d2SRichard Henderson 316730878590SRichard Henderson dest = dest_gpr(ctx, a->t); 316830878590SRichard Henderson t2 = load_gpr(ctx, a->r2); 316905bfd4dbSRichard Henderson if (a->r1 == 0) { 317005bfd4dbSRichard Henderson tcg_gen_extract_reg(dest, t2, sa, 32 - sa); 317105bfd4dbSRichard Henderson } else if (TARGET_REGISTER_BITS == 32) { 317205bfd4dbSRichard Henderson tcg_gen_extract2_reg(dest, t2, cpu_gr[a->r1], sa); 317305bfd4dbSRichard Henderson } else if (a->r1 == a->r2) { 31740b1347d2SRichard Henderson TCGv_i32 t32 = tcg_temp_new_i32(); 3175eaa3783bSRichard Henderson tcg_gen_trunc_reg_i32(t32, t2); 31760b1347d2SRichard Henderson tcg_gen_rotri_i32(t32, t32, sa); 3177eaa3783bSRichard Henderson tcg_gen_extu_i32_reg(dest, t32); 31780b1347d2SRichard Henderson } else { 317905bfd4dbSRichard Henderson TCGv_i64 t64 = tcg_temp_new_i64(); 318005bfd4dbSRichard Henderson tcg_gen_concat_reg_i64(t64, t2, cpu_gr[a->r1]); 318105bfd4dbSRichard Henderson tcg_gen_shri_i64(t64, t64, sa); 318205bfd4dbSRichard Henderson tcg_gen_trunc_i64_reg(dest, t64); 31830b1347d2SRichard Henderson } 318430878590SRichard Henderson save_gpr(ctx, a->t, dest); 31850b1347d2SRichard Henderson 31860b1347d2SRichard Henderson /* Install the new nullification. */ 31870b1347d2SRichard Henderson cond_free(&ctx->null_cond); 318830878590SRichard Henderson if (a->c) { 318930878590SRichard Henderson ctx->null_cond = do_sed_cond(a->c, dest); 31900b1347d2SRichard Henderson } 319131234768SRichard Henderson return nullify_end(ctx); 31920b1347d2SRichard Henderson } 31930b1347d2SRichard Henderson 319430878590SRichard Henderson static bool trans_extrw_sar(DisasContext *ctx, arg_extrw_sar *a) 31950b1347d2SRichard Henderson { 319630878590SRichard Henderson unsigned len = 32 - a->clen; 3197eaa3783bSRichard Henderson TCGv_reg dest, src, tmp; 31980b1347d2SRichard Henderson 319930878590SRichard Henderson if (a->c) { 32000b1347d2SRichard Henderson nullify_over(ctx); 32010b1347d2SRichard Henderson } 32020b1347d2SRichard Henderson 320330878590SRichard Henderson dest = dest_gpr(ctx, a->t); 320430878590SRichard Henderson src = load_gpr(ctx, a->r); 32050b1347d2SRichard Henderson tmp = tcg_temp_new(); 32060b1347d2SRichard Henderson 32070b1347d2SRichard Henderson /* Recall that SAR is using big-endian bit numbering. */ 3208eaa3783bSRichard Henderson tcg_gen_xori_reg(tmp, cpu_sar, TARGET_REGISTER_BITS - 1); 320930878590SRichard Henderson if (a->se) { 3210eaa3783bSRichard Henderson tcg_gen_sar_reg(dest, src, tmp); 3211eaa3783bSRichard Henderson tcg_gen_sextract_reg(dest, dest, 0, len); 32120b1347d2SRichard Henderson } else { 3213eaa3783bSRichard Henderson tcg_gen_shr_reg(dest, src, tmp); 3214eaa3783bSRichard Henderson tcg_gen_extract_reg(dest, dest, 0, len); 32150b1347d2SRichard Henderson } 321630878590SRichard Henderson save_gpr(ctx, a->t, dest); 32170b1347d2SRichard Henderson 32180b1347d2SRichard Henderson /* Install the new nullification. */ 32190b1347d2SRichard Henderson cond_free(&ctx->null_cond); 322030878590SRichard Henderson if (a->c) { 322130878590SRichard Henderson ctx->null_cond = do_sed_cond(a->c, dest); 32220b1347d2SRichard Henderson } 322331234768SRichard Henderson return nullify_end(ctx); 32240b1347d2SRichard Henderson } 32250b1347d2SRichard Henderson 322630878590SRichard Henderson static bool trans_extrw_imm(DisasContext *ctx, arg_extrw_imm *a) 32270b1347d2SRichard Henderson { 322830878590SRichard Henderson unsigned len = 32 - a->clen; 322930878590SRichard Henderson unsigned cpos = 31 - a->pos; 3230eaa3783bSRichard Henderson TCGv_reg dest, src; 32310b1347d2SRichard Henderson 323230878590SRichard Henderson if (a->c) { 32330b1347d2SRichard Henderson nullify_over(ctx); 32340b1347d2SRichard Henderson } 32350b1347d2SRichard Henderson 323630878590SRichard Henderson dest = dest_gpr(ctx, a->t); 323730878590SRichard Henderson src = load_gpr(ctx, a->r); 323830878590SRichard Henderson if (a->se) { 3239eaa3783bSRichard Henderson tcg_gen_sextract_reg(dest, src, cpos, len); 32400b1347d2SRichard Henderson } else { 3241eaa3783bSRichard Henderson tcg_gen_extract_reg(dest, src, cpos, len); 32420b1347d2SRichard Henderson } 324330878590SRichard Henderson save_gpr(ctx, a->t, dest); 32440b1347d2SRichard Henderson 32450b1347d2SRichard Henderson /* Install the new nullification. */ 32460b1347d2SRichard Henderson cond_free(&ctx->null_cond); 324730878590SRichard Henderson if (a->c) { 324830878590SRichard Henderson ctx->null_cond = do_sed_cond(a->c, dest); 32490b1347d2SRichard Henderson } 325031234768SRichard Henderson return nullify_end(ctx); 32510b1347d2SRichard Henderson } 32520b1347d2SRichard Henderson 325330878590SRichard Henderson static bool trans_depwi_imm(DisasContext *ctx, arg_depwi_imm *a) 32540b1347d2SRichard Henderson { 325530878590SRichard Henderson unsigned len = 32 - a->clen; 3256eaa3783bSRichard Henderson target_sreg mask0, mask1; 3257eaa3783bSRichard Henderson TCGv_reg dest; 32580b1347d2SRichard Henderson 325930878590SRichard Henderson if (a->c) { 32600b1347d2SRichard Henderson nullify_over(ctx); 32610b1347d2SRichard Henderson } 326230878590SRichard Henderson if (a->cpos + len > 32) { 326330878590SRichard Henderson len = 32 - a->cpos; 32640b1347d2SRichard Henderson } 32650b1347d2SRichard Henderson 326630878590SRichard Henderson dest = dest_gpr(ctx, a->t); 326730878590SRichard Henderson mask0 = deposit64(0, a->cpos, len, a->i); 326830878590SRichard Henderson mask1 = deposit64(-1, a->cpos, len, a->i); 32690b1347d2SRichard Henderson 327030878590SRichard Henderson if (a->nz) { 327130878590SRichard Henderson TCGv_reg src = load_gpr(ctx, a->t); 32720b1347d2SRichard Henderson if (mask1 != -1) { 3273eaa3783bSRichard Henderson tcg_gen_andi_reg(dest, src, mask1); 32740b1347d2SRichard Henderson src = dest; 32750b1347d2SRichard Henderson } 3276eaa3783bSRichard Henderson tcg_gen_ori_reg(dest, src, mask0); 32770b1347d2SRichard Henderson } else { 3278eaa3783bSRichard Henderson tcg_gen_movi_reg(dest, mask0); 32790b1347d2SRichard Henderson } 328030878590SRichard Henderson save_gpr(ctx, a->t, dest); 32810b1347d2SRichard Henderson 32820b1347d2SRichard Henderson /* Install the new nullification. */ 32830b1347d2SRichard Henderson cond_free(&ctx->null_cond); 328430878590SRichard Henderson if (a->c) { 328530878590SRichard Henderson ctx->null_cond = do_sed_cond(a->c, dest); 32860b1347d2SRichard Henderson } 328731234768SRichard Henderson return nullify_end(ctx); 32880b1347d2SRichard Henderson } 32890b1347d2SRichard Henderson 329030878590SRichard Henderson static bool trans_depw_imm(DisasContext *ctx, arg_depw_imm *a) 32910b1347d2SRichard Henderson { 329230878590SRichard Henderson unsigned rs = a->nz ? a->t : 0; 329330878590SRichard Henderson unsigned len = 32 - a->clen; 3294eaa3783bSRichard Henderson TCGv_reg dest, val; 32950b1347d2SRichard Henderson 329630878590SRichard Henderson if (a->c) { 32970b1347d2SRichard Henderson nullify_over(ctx); 32980b1347d2SRichard Henderson } 329930878590SRichard Henderson if (a->cpos + len > 32) { 330030878590SRichard Henderson len = 32 - a->cpos; 33010b1347d2SRichard Henderson } 33020b1347d2SRichard Henderson 330330878590SRichard Henderson dest = dest_gpr(ctx, a->t); 330430878590SRichard Henderson val = load_gpr(ctx, a->r); 33050b1347d2SRichard Henderson if (rs == 0) { 330630878590SRichard Henderson tcg_gen_deposit_z_reg(dest, val, a->cpos, len); 33070b1347d2SRichard Henderson } else { 330830878590SRichard Henderson tcg_gen_deposit_reg(dest, cpu_gr[rs], val, a->cpos, len); 33090b1347d2SRichard Henderson } 331030878590SRichard Henderson save_gpr(ctx, a->t, dest); 33110b1347d2SRichard Henderson 33120b1347d2SRichard Henderson /* Install the new nullification. */ 33130b1347d2SRichard Henderson cond_free(&ctx->null_cond); 331430878590SRichard Henderson if (a->c) { 331530878590SRichard Henderson ctx->null_cond = do_sed_cond(a->c, dest); 33160b1347d2SRichard Henderson } 331731234768SRichard Henderson return nullify_end(ctx); 33180b1347d2SRichard Henderson } 33190b1347d2SRichard Henderson 332030878590SRichard Henderson static bool do_depw_sar(DisasContext *ctx, unsigned rt, unsigned c, 332130878590SRichard Henderson unsigned nz, unsigned clen, TCGv_reg val) 33220b1347d2SRichard Henderson { 33230b1347d2SRichard Henderson unsigned rs = nz ? rt : 0; 33240b1347d2SRichard Henderson unsigned len = 32 - clen; 332530878590SRichard Henderson TCGv_reg mask, tmp, shift, dest; 33260b1347d2SRichard Henderson unsigned msb = 1U << (len - 1); 33270b1347d2SRichard Henderson 33280b1347d2SRichard Henderson dest = dest_gpr(ctx, rt); 33290b1347d2SRichard Henderson shift = tcg_temp_new(); 33300b1347d2SRichard Henderson tmp = tcg_temp_new(); 33310b1347d2SRichard Henderson 33320b1347d2SRichard Henderson /* Convert big-endian bit numbering in SAR to left-shift. */ 3333eaa3783bSRichard Henderson tcg_gen_xori_reg(shift, cpu_sar, TARGET_REGISTER_BITS - 1); 33340b1347d2SRichard Henderson 33350992a930SRichard Henderson mask = tcg_temp_new(); 33360992a930SRichard Henderson tcg_gen_movi_reg(mask, msb + (msb - 1)); 3337eaa3783bSRichard Henderson tcg_gen_and_reg(tmp, val, mask); 33380b1347d2SRichard Henderson if (rs) { 3339eaa3783bSRichard Henderson tcg_gen_shl_reg(mask, mask, shift); 3340eaa3783bSRichard Henderson tcg_gen_shl_reg(tmp, tmp, shift); 3341eaa3783bSRichard Henderson tcg_gen_andc_reg(dest, cpu_gr[rs], mask); 3342eaa3783bSRichard Henderson tcg_gen_or_reg(dest, dest, tmp); 33430b1347d2SRichard Henderson } else { 3344eaa3783bSRichard Henderson tcg_gen_shl_reg(dest, tmp, shift); 33450b1347d2SRichard Henderson } 33460b1347d2SRichard Henderson save_gpr(ctx, rt, dest); 33470b1347d2SRichard Henderson 33480b1347d2SRichard Henderson /* Install the new nullification. */ 33490b1347d2SRichard Henderson cond_free(&ctx->null_cond); 33500b1347d2SRichard Henderson if (c) { 33510b1347d2SRichard Henderson ctx->null_cond = do_sed_cond(c, dest); 33520b1347d2SRichard Henderson } 335331234768SRichard Henderson return nullify_end(ctx); 33540b1347d2SRichard Henderson } 33550b1347d2SRichard Henderson 335630878590SRichard Henderson static bool trans_depw_sar(DisasContext *ctx, arg_depw_sar *a) 335730878590SRichard Henderson { 3358a6deecceSSven Schnelle if (a->c) { 3359a6deecceSSven Schnelle nullify_over(ctx); 3360a6deecceSSven Schnelle } 336130878590SRichard Henderson return do_depw_sar(ctx, a->t, a->c, a->nz, a->clen, load_gpr(ctx, a->r)); 336230878590SRichard Henderson } 336330878590SRichard Henderson 336430878590SRichard Henderson static bool trans_depwi_sar(DisasContext *ctx, arg_depwi_sar *a) 336530878590SRichard Henderson { 3366a6deecceSSven Schnelle if (a->c) { 3367a6deecceSSven Schnelle nullify_over(ctx); 3368a6deecceSSven Schnelle } 336930878590SRichard Henderson return do_depw_sar(ctx, a->t, a->c, a->nz, a->clen, load_const(ctx, a->i)); 337030878590SRichard Henderson } 33710b1347d2SRichard Henderson 33728340f534SRichard Henderson static bool trans_be(DisasContext *ctx, arg_be *a) 337398cd9ca7SRichard Henderson { 3374660eefe1SRichard Henderson TCGv_reg tmp; 337598cd9ca7SRichard Henderson 3376c301f34eSRichard Henderson #ifdef CONFIG_USER_ONLY 337798cd9ca7SRichard Henderson /* ??? It seems like there should be a good way of using 337898cd9ca7SRichard Henderson "be disp(sr2, r0)", the canonical gateway entry mechanism 337998cd9ca7SRichard Henderson to our advantage. But that appears to be inconvenient to 338098cd9ca7SRichard Henderson manage along side branch delay slots. Therefore we handle 338198cd9ca7SRichard Henderson entry into the gateway page via absolute address. */ 338298cd9ca7SRichard Henderson /* Since we don't implement spaces, just branch. Do notice the special 338398cd9ca7SRichard Henderson case of "be disp(*,r0)" using a direct branch to disp, so that we can 338498cd9ca7SRichard Henderson goto_tb to the TB containing the syscall. */ 33858340f534SRichard Henderson if (a->b == 0) { 33868340f534SRichard Henderson return do_dbranch(ctx, a->disp, a->l, a->n); 338798cd9ca7SRichard Henderson } 3388c301f34eSRichard Henderson #else 3389c301f34eSRichard Henderson nullify_over(ctx); 3390660eefe1SRichard Henderson #endif 3391660eefe1SRichard Henderson 3392660eefe1SRichard Henderson tmp = get_temp(ctx); 33938340f534SRichard Henderson tcg_gen_addi_reg(tmp, load_gpr(ctx, a->b), a->disp); 3394660eefe1SRichard Henderson tmp = do_ibranch_priv(ctx, tmp); 3395c301f34eSRichard Henderson 3396c301f34eSRichard Henderson #ifdef CONFIG_USER_ONLY 33978340f534SRichard Henderson return do_ibranch(ctx, tmp, a->l, a->n); 3398c301f34eSRichard Henderson #else 3399c301f34eSRichard Henderson TCGv_i64 new_spc = tcg_temp_new_i64(); 3400c301f34eSRichard Henderson 34018340f534SRichard Henderson load_spr(ctx, new_spc, a->sp); 34028340f534SRichard Henderson if (a->l) { 3403c301f34eSRichard Henderson copy_iaoq_entry(cpu_gr[31], ctx->iaoq_n, ctx->iaoq_n_var); 3404c301f34eSRichard Henderson tcg_gen_mov_i64(cpu_sr[0], cpu_iasq_f); 3405c301f34eSRichard Henderson } 34068340f534SRichard Henderson if (a->n && use_nullify_skip(ctx)) { 3407c301f34eSRichard Henderson tcg_gen_mov_reg(cpu_iaoq_f, tmp); 3408c301f34eSRichard Henderson tcg_gen_addi_reg(cpu_iaoq_b, cpu_iaoq_f, 4); 3409c301f34eSRichard Henderson tcg_gen_mov_i64(cpu_iasq_f, new_spc); 3410c301f34eSRichard Henderson tcg_gen_mov_i64(cpu_iasq_b, cpu_iasq_f); 3411c301f34eSRichard Henderson } else { 3412c301f34eSRichard Henderson copy_iaoq_entry(cpu_iaoq_f, ctx->iaoq_b, cpu_iaoq_b); 3413c301f34eSRichard Henderson if (ctx->iaoq_b == -1) { 3414c301f34eSRichard Henderson tcg_gen_mov_i64(cpu_iasq_f, cpu_iasq_b); 3415c301f34eSRichard Henderson } 3416c301f34eSRichard Henderson tcg_gen_mov_reg(cpu_iaoq_b, tmp); 3417c301f34eSRichard Henderson tcg_gen_mov_i64(cpu_iasq_b, new_spc); 34188340f534SRichard Henderson nullify_set(ctx, a->n); 3419c301f34eSRichard Henderson } 3420c301f34eSRichard Henderson tcg_gen_lookup_and_goto_ptr(); 342131234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 342231234768SRichard Henderson return nullify_end(ctx); 3423c301f34eSRichard Henderson #endif 342498cd9ca7SRichard Henderson } 342598cd9ca7SRichard Henderson 34268340f534SRichard Henderson static bool trans_bl(DisasContext *ctx, arg_bl *a) 342798cd9ca7SRichard Henderson { 34288340f534SRichard Henderson return do_dbranch(ctx, iaoq_dest(ctx, a->disp), a->l, a->n); 342998cd9ca7SRichard Henderson } 343098cd9ca7SRichard Henderson 34318340f534SRichard Henderson static bool trans_b_gate(DisasContext *ctx, arg_b_gate *a) 343243e05652SRichard Henderson { 34338340f534SRichard Henderson target_ureg dest = iaoq_dest(ctx, a->disp); 343443e05652SRichard Henderson 34356e5f5300SSven Schnelle nullify_over(ctx); 34366e5f5300SSven Schnelle 343743e05652SRichard Henderson /* Make sure the caller hasn't done something weird with the queue. 343843e05652SRichard Henderson * ??? This is not quite the same as the PSW[B] bit, which would be 343943e05652SRichard Henderson * expensive to track. Real hardware will trap for 344043e05652SRichard Henderson * b gateway 344143e05652SRichard Henderson * b gateway+4 (in delay slot of first branch) 344243e05652SRichard Henderson * However, checking for a non-sequential instruction queue *will* 344343e05652SRichard Henderson * diagnose the security hole 344443e05652SRichard Henderson * b gateway 344543e05652SRichard Henderson * b evil 344643e05652SRichard Henderson * in which instructions at evil would run with increased privs. 344743e05652SRichard Henderson */ 344843e05652SRichard Henderson if (ctx->iaoq_b == -1 || ctx->iaoq_b != ctx->iaoq_f + 4) { 344943e05652SRichard Henderson return gen_illegal(ctx); 345043e05652SRichard Henderson } 345143e05652SRichard Henderson 345243e05652SRichard Henderson #ifndef CONFIG_USER_ONLY 345343e05652SRichard Henderson if (ctx->tb_flags & PSW_C) { 345443e05652SRichard Henderson CPUHPPAState *env = ctx->cs->env_ptr; 345543e05652SRichard Henderson int type = hppa_artype_for_page(env, ctx->base.pc_next); 345643e05652SRichard Henderson /* If we could not find a TLB entry, then we need to generate an 345743e05652SRichard Henderson ITLB miss exception so the kernel will provide it. 345843e05652SRichard Henderson The resulting TLB fill operation will invalidate this TB and 345943e05652SRichard Henderson we will re-translate, at which point we *will* be able to find 346043e05652SRichard Henderson the TLB entry and determine if this is in fact a gateway page. */ 346143e05652SRichard Henderson if (type < 0) { 346231234768SRichard Henderson gen_excp(ctx, EXCP_ITLB_MISS); 346331234768SRichard Henderson return true; 346443e05652SRichard Henderson } 346543e05652SRichard Henderson /* No change for non-gateway pages or for priv decrease. */ 346643e05652SRichard Henderson if (type >= 4 && type - 4 < ctx->privilege) { 346743e05652SRichard Henderson dest = deposit32(dest, 0, 2, type - 4); 346843e05652SRichard Henderson } 346943e05652SRichard Henderson } else { 347043e05652SRichard Henderson dest &= -4; /* priv = 0 */ 347143e05652SRichard Henderson } 347243e05652SRichard Henderson #endif 347343e05652SRichard Henderson 34746e5f5300SSven Schnelle if (a->l) { 34756e5f5300SSven Schnelle TCGv_reg tmp = dest_gpr(ctx, a->l); 34766e5f5300SSven Schnelle if (ctx->privilege < 3) { 34776e5f5300SSven Schnelle tcg_gen_andi_reg(tmp, tmp, -4); 34786e5f5300SSven Schnelle } 34796e5f5300SSven Schnelle tcg_gen_ori_reg(tmp, tmp, ctx->privilege); 34806e5f5300SSven Schnelle save_gpr(ctx, a->l, tmp); 34816e5f5300SSven Schnelle } 34826e5f5300SSven Schnelle 34836e5f5300SSven Schnelle return do_dbranch(ctx, dest, 0, a->n); 348443e05652SRichard Henderson } 348543e05652SRichard Henderson 34868340f534SRichard Henderson static bool trans_blr(DisasContext *ctx, arg_blr *a) 348798cd9ca7SRichard Henderson { 3488b35aec85SRichard Henderson if (a->x) { 3489eaa3783bSRichard Henderson TCGv_reg tmp = get_temp(ctx); 34908340f534SRichard Henderson tcg_gen_shli_reg(tmp, load_gpr(ctx, a->x), 3); 3491eaa3783bSRichard Henderson tcg_gen_addi_reg(tmp, tmp, ctx->iaoq_f + 8); 3492660eefe1SRichard Henderson /* The computation here never changes privilege level. */ 34938340f534SRichard Henderson return do_ibranch(ctx, tmp, a->l, a->n); 3494b35aec85SRichard Henderson } else { 3495b35aec85SRichard Henderson /* BLR R0,RX is a good way to load PC+8 into RX. */ 3496b35aec85SRichard Henderson return do_dbranch(ctx, ctx->iaoq_f + 8, a->l, a->n); 3497b35aec85SRichard Henderson } 349898cd9ca7SRichard Henderson } 349998cd9ca7SRichard Henderson 35008340f534SRichard Henderson static bool trans_bv(DisasContext *ctx, arg_bv *a) 350198cd9ca7SRichard Henderson { 3502eaa3783bSRichard Henderson TCGv_reg dest; 350398cd9ca7SRichard Henderson 35048340f534SRichard Henderson if (a->x == 0) { 35058340f534SRichard Henderson dest = load_gpr(ctx, a->b); 350698cd9ca7SRichard Henderson } else { 350798cd9ca7SRichard Henderson dest = get_temp(ctx); 35088340f534SRichard Henderson tcg_gen_shli_reg(dest, load_gpr(ctx, a->x), 3); 35098340f534SRichard Henderson tcg_gen_add_reg(dest, dest, load_gpr(ctx, a->b)); 351098cd9ca7SRichard Henderson } 3511660eefe1SRichard Henderson dest = do_ibranch_priv(ctx, dest); 35128340f534SRichard Henderson return do_ibranch(ctx, dest, 0, a->n); 351398cd9ca7SRichard Henderson } 351498cd9ca7SRichard Henderson 35158340f534SRichard Henderson static bool trans_bve(DisasContext *ctx, arg_bve *a) 351698cd9ca7SRichard Henderson { 3517660eefe1SRichard Henderson TCGv_reg dest; 351898cd9ca7SRichard Henderson 3519c301f34eSRichard Henderson #ifdef CONFIG_USER_ONLY 35208340f534SRichard Henderson dest = do_ibranch_priv(ctx, load_gpr(ctx, a->b)); 35218340f534SRichard Henderson return do_ibranch(ctx, dest, a->l, a->n); 3522c301f34eSRichard Henderson #else 3523c301f34eSRichard Henderson nullify_over(ctx); 35248340f534SRichard Henderson dest = do_ibranch_priv(ctx, load_gpr(ctx, a->b)); 3525c301f34eSRichard Henderson 3526c301f34eSRichard Henderson copy_iaoq_entry(cpu_iaoq_f, ctx->iaoq_b, cpu_iaoq_b); 3527c301f34eSRichard Henderson if (ctx->iaoq_b == -1) { 3528c301f34eSRichard Henderson tcg_gen_mov_i64(cpu_iasq_f, cpu_iasq_b); 3529c301f34eSRichard Henderson } 3530c301f34eSRichard Henderson copy_iaoq_entry(cpu_iaoq_b, -1, dest); 3531c301f34eSRichard Henderson tcg_gen_mov_i64(cpu_iasq_b, space_select(ctx, 0, dest)); 35328340f534SRichard Henderson if (a->l) { 35338340f534SRichard Henderson copy_iaoq_entry(cpu_gr[a->l], ctx->iaoq_n, ctx->iaoq_n_var); 3534c301f34eSRichard Henderson } 35358340f534SRichard Henderson nullify_set(ctx, a->n); 3536c301f34eSRichard Henderson tcg_gen_lookup_and_goto_ptr(); 353731234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 353831234768SRichard Henderson return nullify_end(ctx); 3539c301f34eSRichard Henderson #endif 354098cd9ca7SRichard Henderson } 354198cd9ca7SRichard Henderson 35421ca74648SRichard Henderson /* 35431ca74648SRichard Henderson * Float class 0 35441ca74648SRichard Henderson */ 3545ebe9383cSRichard Henderson 35461ca74648SRichard Henderson static void gen_fcpy_f(TCGv_i32 dst, TCGv_env unused, TCGv_i32 src) 3547ebe9383cSRichard Henderson { 3548ebe9383cSRichard Henderson tcg_gen_mov_i32(dst, src); 3549ebe9383cSRichard Henderson } 3550ebe9383cSRichard Henderson 355159f8c04bSHelge Deller static bool trans_fid_f(DisasContext *ctx, arg_fid_f *a) 355259f8c04bSHelge Deller { 3553a300dad3SRichard Henderson uint64_t ret; 3554a300dad3SRichard Henderson 3555a300dad3SRichard Henderson if (TARGET_REGISTER_BITS == 64) { 3556a300dad3SRichard Henderson ret = 0x13080000000000ULL; /* PA8700 (PCX-W2) */ 3557a300dad3SRichard Henderson } else { 3558a300dad3SRichard Henderson ret = 0x0f080000000000ULL; /* PA7300LC (PCX-L2) */ 3559a300dad3SRichard Henderson } 3560a300dad3SRichard Henderson 356159f8c04bSHelge Deller nullify_over(ctx); 3562a300dad3SRichard Henderson save_frd(0, tcg_constant_i64(ret)); 356359f8c04bSHelge Deller return nullify_end(ctx); 356459f8c04bSHelge Deller } 356559f8c04bSHelge Deller 35661ca74648SRichard Henderson static bool trans_fcpy_f(DisasContext *ctx, arg_fclass01 *a) 35671ca74648SRichard Henderson { 35681ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_fcpy_f); 35691ca74648SRichard Henderson } 35701ca74648SRichard Henderson 3571ebe9383cSRichard Henderson static void gen_fcpy_d(TCGv_i64 dst, TCGv_env unused, TCGv_i64 src) 3572ebe9383cSRichard Henderson { 3573ebe9383cSRichard Henderson tcg_gen_mov_i64(dst, src); 3574ebe9383cSRichard Henderson } 3575ebe9383cSRichard Henderson 35761ca74648SRichard Henderson static bool trans_fcpy_d(DisasContext *ctx, arg_fclass01 *a) 35771ca74648SRichard Henderson { 35781ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_fcpy_d); 35791ca74648SRichard Henderson } 35801ca74648SRichard Henderson 35811ca74648SRichard Henderson static void gen_fabs_f(TCGv_i32 dst, TCGv_env unused, TCGv_i32 src) 3582ebe9383cSRichard Henderson { 3583ebe9383cSRichard Henderson tcg_gen_andi_i32(dst, src, INT32_MAX); 3584ebe9383cSRichard Henderson } 3585ebe9383cSRichard Henderson 35861ca74648SRichard Henderson static bool trans_fabs_f(DisasContext *ctx, arg_fclass01 *a) 35871ca74648SRichard Henderson { 35881ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_fabs_f); 35891ca74648SRichard Henderson } 35901ca74648SRichard Henderson 3591ebe9383cSRichard Henderson static void gen_fabs_d(TCGv_i64 dst, TCGv_env unused, TCGv_i64 src) 3592ebe9383cSRichard Henderson { 3593ebe9383cSRichard Henderson tcg_gen_andi_i64(dst, src, INT64_MAX); 3594ebe9383cSRichard Henderson } 3595ebe9383cSRichard Henderson 35961ca74648SRichard Henderson static bool trans_fabs_d(DisasContext *ctx, arg_fclass01 *a) 35971ca74648SRichard Henderson { 35981ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_fabs_d); 35991ca74648SRichard Henderson } 36001ca74648SRichard Henderson 36011ca74648SRichard Henderson static bool trans_fsqrt_f(DisasContext *ctx, arg_fclass01 *a) 36021ca74648SRichard Henderson { 36031ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_fsqrt_s); 36041ca74648SRichard Henderson } 36051ca74648SRichard Henderson 36061ca74648SRichard Henderson static bool trans_fsqrt_d(DisasContext *ctx, arg_fclass01 *a) 36071ca74648SRichard Henderson { 36081ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_fsqrt_d); 36091ca74648SRichard Henderson } 36101ca74648SRichard Henderson 36111ca74648SRichard Henderson static bool trans_frnd_f(DisasContext *ctx, arg_fclass01 *a) 36121ca74648SRichard Henderson { 36131ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_frnd_s); 36141ca74648SRichard Henderson } 36151ca74648SRichard Henderson 36161ca74648SRichard Henderson static bool trans_frnd_d(DisasContext *ctx, arg_fclass01 *a) 36171ca74648SRichard Henderson { 36181ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_frnd_d); 36191ca74648SRichard Henderson } 36201ca74648SRichard Henderson 36211ca74648SRichard Henderson static void gen_fneg_f(TCGv_i32 dst, TCGv_env unused, TCGv_i32 src) 3622ebe9383cSRichard Henderson { 3623ebe9383cSRichard Henderson tcg_gen_xori_i32(dst, src, INT32_MIN); 3624ebe9383cSRichard Henderson } 3625ebe9383cSRichard Henderson 36261ca74648SRichard Henderson static bool trans_fneg_f(DisasContext *ctx, arg_fclass01 *a) 36271ca74648SRichard Henderson { 36281ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_fneg_f); 36291ca74648SRichard Henderson } 36301ca74648SRichard Henderson 3631ebe9383cSRichard Henderson static void gen_fneg_d(TCGv_i64 dst, TCGv_env unused, TCGv_i64 src) 3632ebe9383cSRichard Henderson { 3633ebe9383cSRichard Henderson tcg_gen_xori_i64(dst, src, INT64_MIN); 3634ebe9383cSRichard Henderson } 3635ebe9383cSRichard Henderson 36361ca74648SRichard Henderson static bool trans_fneg_d(DisasContext *ctx, arg_fclass01 *a) 36371ca74648SRichard Henderson { 36381ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_fneg_d); 36391ca74648SRichard Henderson } 36401ca74648SRichard Henderson 36411ca74648SRichard Henderson static void gen_fnegabs_f(TCGv_i32 dst, TCGv_env unused, TCGv_i32 src) 3642ebe9383cSRichard Henderson { 3643ebe9383cSRichard Henderson tcg_gen_ori_i32(dst, src, INT32_MIN); 3644ebe9383cSRichard Henderson } 3645ebe9383cSRichard Henderson 36461ca74648SRichard Henderson static bool trans_fnegabs_f(DisasContext *ctx, arg_fclass01 *a) 36471ca74648SRichard Henderson { 36481ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_fnegabs_f); 36491ca74648SRichard Henderson } 36501ca74648SRichard Henderson 3651ebe9383cSRichard Henderson static void gen_fnegabs_d(TCGv_i64 dst, TCGv_env unused, TCGv_i64 src) 3652ebe9383cSRichard Henderson { 3653ebe9383cSRichard Henderson tcg_gen_ori_i64(dst, src, INT64_MIN); 3654ebe9383cSRichard Henderson } 3655ebe9383cSRichard Henderson 36561ca74648SRichard Henderson static bool trans_fnegabs_d(DisasContext *ctx, arg_fclass01 *a) 36571ca74648SRichard Henderson { 36581ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_fnegabs_d); 36591ca74648SRichard Henderson } 36601ca74648SRichard Henderson 36611ca74648SRichard Henderson /* 36621ca74648SRichard Henderson * Float class 1 36631ca74648SRichard Henderson */ 36641ca74648SRichard Henderson 36651ca74648SRichard Henderson static bool trans_fcnv_d_f(DisasContext *ctx, arg_fclass01 *a) 36661ca74648SRichard Henderson { 36671ca74648SRichard Henderson return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_d_s); 36681ca74648SRichard Henderson } 36691ca74648SRichard Henderson 36701ca74648SRichard Henderson static bool trans_fcnv_f_d(DisasContext *ctx, arg_fclass01 *a) 36711ca74648SRichard Henderson { 36721ca74648SRichard Henderson return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_s_d); 36731ca74648SRichard Henderson } 36741ca74648SRichard Henderson 36751ca74648SRichard Henderson static bool trans_fcnv_w_f(DisasContext *ctx, arg_fclass01 *a) 36761ca74648SRichard Henderson { 36771ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_w_s); 36781ca74648SRichard Henderson } 36791ca74648SRichard Henderson 36801ca74648SRichard Henderson static bool trans_fcnv_q_f(DisasContext *ctx, arg_fclass01 *a) 36811ca74648SRichard Henderson { 36821ca74648SRichard Henderson return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_dw_s); 36831ca74648SRichard Henderson } 36841ca74648SRichard Henderson 36851ca74648SRichard Henderson static bool trans_fcnv_w_d(DisasContext *ctx, arg_fclass01 *a) 36861ca74648SRichard Henderson { 36871ca74648SRichard Henderson return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_w_d); 36881ca74648SRichard Henderson } 36891ca74648SRichard Henderson 36901ca74648SRichard Henderson static bool trans_fcnv_q_d(DisasContext *ctx, arg_fclass01 *a) 36911ca74648SRichard Henderson { 36921ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_dw_d); 36931ca74648SRichard Henderson } 36941ca74648SRichard Henderson 36951ca74648SRichard Henderson static bool trans_fcnv_f_w(DisasContext *ctx, arg_fclass01 *a) 36961ca74648SRichard Henderson { 36971ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_s_w); 36981ca74648SRichard Henderson } 36991ca74648SRichard Henderson 37001ca74648SRichard Henderson static bool trans_fcnv_d_w(DisasContext *ctx, arg_fclass01 *a) 37011ca74648SRichard Henderson { 37021ca74648SRichard Henderson return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_d_w); 37031ca74648SRichard Henderson } 37041ca74648SRichard Henderson 37051ca74648SRichard Henderson static bool trans_fcnv_f_q(DisasContext *ctx, arg_fclass01 *a) 37061ca74648SRichard Henderson { 37071ca74648SRichard Henderson return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_s_dw); 37081ca74648SRichard Henderson } 37091ca74648SRichard Henderson 37101ca74648SRichard Henderson static bool trans_fcnv_d_q(DisasContext *ctx, arg_fclass01 *a) 37111ca74648SRichard Henderson { 37121ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_d_dw); 37131ca74648SRichard Henderson } 37141ca74648SRichard Henderson 37151ca74648SRichard Henderson static bool trans_fcnv_t_f_w(DisasContext *ctx, arg_fclass01 *a) 37161ca74648SRichard Henderson { 37171ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_t_s_w); 37181ca74648SRichard Henderson } 37191ca74648SRichard Henderson 37201ca74648SRichard Henderson static bool trans_fcnv_t_d_w(DisasContext *ctx, arg_fclass01 *a) 37211ca74648SRichard Henderson { 37221ca74648SRichard Henderson return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_t_d_w); 37231ca74648SRichard Henderson } 37241ca74648SRichard Henderson 37251ca74648SRichard Henderson static bool trans_fcnv_t_f_q(DisasContext *ctx, arg_fclass01 *a) 37261ca74648SRichard Henderson { 37271ca74648SRichard Henderson return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_t_s_dw); 37281ca74648SRichard Henderson } 37291ca74648SRichard Henderson 37301ca74648SRichard Henderson static bool trans_fcnv_t_d_q(DisasContext *ctx, arg_fclass01 *a) 37311ca74648SRichard Henderson { 37321ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_t_d_dw); 37331ca74648SRichard Henderson } 37341ca74648SRichard Henderson 37351ca74648SRichard Henderson static bool trans_fcnv_uw_f(DisasContext *ctx, arg_fclass01 *a) 37361ca74648SRichard Henderson { 37371ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_uw_s); 37381ca74648SRichard Henderson } 37391ca74648SRichard Henderson 37401ca74648SRichard Henderson static bool trans_fcnv_uq_f(DisasContext *ctx, arg_fclass01 *a) 37411ca74648SRichard Henderson { 37421ca74648SRichard Henderson return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_udw_s); 37431ca74648SRichard Henderson } 37441ca74648SRichard Henderson 37451ca74648SRichard Henderson static bool trans_fcnv_uw_d(DisasContext *ctx, arg_fclass01 *a) 37461ca74648SRichard Henderson { 37471ca74648SRichard Henderson return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_uw_d); 37481ca74648SRichard Henderson } 37491ca74648SRichard Henderson 37501ca74648SRichard Henderson static bool trans_fcnv_uq_d(DisasContext *ctx, arg_fclass01 *a) 37511ca74648SRichard Henderson { 37521ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_udw_d); 37531ca74648SRichard Henderson } 37541ca74648SRichard Henderson 37551ca74648SRichard Henderson static bool trans_fcnv_f_uw(DisasContext *ctx, arg_fclass01 *a) 37561ca74648SRichard Henderson { 37571ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_s_uw); 37581ca74648SRichard Henderson } 37591ca74648SRichard Henderson 37601ca74648SRichard Henderson static bool trans_fcnv_d_uw(DisasContext *ctx, arg_fclass01 *a) 37611ca74648SRichard Henderson { 37621ca74648SRichard Henderson return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_d_uw); 37631ca74648SRichard Henderson } 37641ca74648SRichard Henderson 37651ca74648SRichard Henderson static bool trans_fcnv_f_uq(DisasContext *ctx, arg_fclass01 *a) 37661ca74648SRichard Henderson { 37671ca74648SRichard Henderson return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_s_udw); 37681ca74648SRichard Henderson } 37691ca74648SRichard Henderson 37701ca74648SRichard Henderson static bool trans_fcnv_d_uq(DisasContext *ctx, arg_fclass01 *a) 37711ca74648SRichard Henderson { 37721ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_d_udw); 37731ca74648SRichard Henderson } 37741ca74648SRichard Henderson 37751ca74648SRichard Henderson static bool trans_fcnv_t_f_uw(DisasContext *ctx, arg_fclass01 *a) 37761ca74648SRichard Henderson { 37771ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_t_s_uw); 37781ca74648SRichard Henderson } 37791ca74648SRichard Henderson 37801ca74648SRichard Henderson static bool trans_fcnv_t_d_uw(DisasContext *ctx, arg_fclass01 *a) 37811ca74648SRichard Henderson { 37821ca74648SRichard Henderson return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_t_d_uw); 37831ca74648SRichard Henderson } 37841ca74648SRichard Henderson 37851ca74648SRichard Henderson static bool trans_fcnv_t_f_uq(DisasContext *ctx, arg_fclass01 *a) 37861ca74648SRichard Henderson { 37871ca74648SRichard Henderson return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_t_s_udw); 37881ca74648SRichard Henderson } 37891ca74648SRichard Henderson 37901ca74648SRichard Henderson static bool trans_fcnv_t_d_uq(DisasContext *ctx, arg_fclass01 *a) 37911ca74648SRichard Henderson { 37921ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_t_d_udw); 37931ca74648SRichard Henderson } 37941ca74648SRichard Henderson 37951ca74648SRichard Henderson /* 37961ca74648SRichard Henderson * Float class 2 37971ca74648SRichard Henderson */ 37981ca74648SRichard Henderson 37991ca74648SRichard Henderson static bool trans_fcmp_f(DisasContext *ctx, arg_fclass2 *a) 3800ebe9383cSRichard Henderson { 3801ebe9383cSRichard Henderson TCGv_i32 ta, tb, tc, ty; 3802ebe9383cSRichard Henderson 3803ebe9383cSRichard Henderson nullify_over(ctx); 3804ebe9383cSRichard Henderson 38051ca74648SRichard Henderson ta = load_frw0_i32(a->r1); 38061ca74648SRichard Henderson tb = load_frw0_i32(a->r2); 380729dd6f64SRichard Henderson ty = tcg_constant_i32(a->y); 380829dd6f64SRichard Henderson tc = tcg_constant_i32(a->c); 3809ebe9383cSRichard Henderson 3810ebe9383cSRichard Henderson gen_helper_fcmp_s(cpu_env, ta, tb, ty, tc); 3811ebe9383cSRichard Henderson 38121ca74648SRichard Henderson return nullify_end(ctx); 3813ebe9383cSRichard Henderson } 3814ebe9383cSRichard Henderson 38151ca74648SRichard Henderson static bool trans_fcmp_d(DisasContext *ctx, arg_fclass2 *a) 3816ebe9383cSRichard Henderson { 3817ebe9383cSRichard Henderson TCGv_i64 ta, tb; 3818ebe9383cSRichard Henderson TCGv_i32 tc, ty; 3819ebe9383cSRichard Henderson 3820ebe9383cSRichard Henderson nullify_over(ctx); 3821ebe9383cSRichard Henderson 38221ca74648SRichard Henderson ta = load_frd0(a->r1); 38231ca74648SRichard Henderson tb = load_frd0(a->r2); 382429dd6f64SRichard Henderson ty = tcg_constant_i32(a->y); 382529dd6f64SRichard Henderson tc = tcg_constant_i32(a->c); 3826ebe9383cSRichard Henderson 3827ebe9383cSRichard Henderson gen_helper_fcmp_d(cpu_env, ta, tb, ty, tc); 3828ebe9383cSRichard Henderson 382931234768SRichard Henderson return nullify_end(ctx); 3830ebe9383cSRichard Henderson } 3831ebe9383cSRichard Henderson 38321ca74648SRichard Henderson static bool trans_ftest(DisasContext *ctx, arg_ftest *a) 3833ebe9383cSRichard Henderson { 3834eaa3783bSRichard Henderson TCGv_reg t; 3835ebe9383cSRichard Henderson 3836ebe9383cSRichard Henderson nullify_over(ctx); 3837ebe9383cSRichard Henderson 38381ca74648SRichard Henderson t = get_temp(ctx); 3839eaa3783bSRichard Henderson tcg_gen_ld32u_reg(t, cpu_env, offsetof(CPUHPPAState, fr0_shadow)); 3840ebe9383cSRichard Henderson 38411ca74648SRichard Henderson if (a->y == 1) { 3842ebe9383cSRichard Henderson int mask; 3843ebe9383cSRichard Henderson bool inv = false; 3844ebe9383cSRichard Henderson 38451ca74648SRichard Henderson switch (a->c) { 3846ebe9383cSRichard Henderson case 0: /* simple */ 3847eaa3783bSRichard Henderson tcg_gen_andi_reg(t, t, 0x4000000); 3848ebe9383cSRichard Henderson ctx->null_cond = cond_make_0(TCG_COND_NE, t); 3849ebe9383cSRichard Henderson goto done; 3850ebe9383cSRichard Henderson case 2: /* rej */ 3851ebe9383cSRichard Henderson inv = true; 3852ebe9383cSRichard Henderson /* fallthru */ 3853ebe9383cSRichard Henderson case 1: /* acc */ 3854ebe9383cSRichard Henderson mask = 0x43ff800; 3855ebe9383cSRichard Henderson break; 3856ebe9383cSRichard Henderson case 6: /* rej8 */ 3857ebe9383cSRichard Henderson inv = true; 3858ebe9383cSRichard Henderson /* fallthru */ 3859ebe9383cSRichard Henderson case 5: /* acc8 */ 3860ebe9383cSRichard Henderson mask = 0x43f8000; 3861ebe9383cSRichard Henderson break; 3862ebe9383cSRichard Henderson case 9: /* acc6 */ 3863ebe9383cSRichard Henderson mask = 0x43e0000; 3864ebe9383cSRichard Henderson break; 3865ebe9383cSRichard Henderson case 13: /* acc4 */ 3866ebe9383cSRichard Henderson mask = 0x4380000; 3867ebe9383cSRichard Henderson break; 3868ebe9383cSRichard Henderson case 17: /* acc2 */ 3869ebe9383cSRichard Henderson mask = 0x4200000; 3870ebe9383cSRichard Henderson break; 3871ebe9383cSRichard Henderson default: 38721ca74648SRichard Henderson gen_illegal(ctx); 38731ca74648SRichard Henderson return true; 3874ebe9383cSRichard Henderson } 3875ebe9383cSRichard Henderson if (inv) { 3876eaa3783bSRichard Henderson TCGv_reg c = load_const(ctx, mask); 3877eaa3783bSRichard Henderson tcg_gen_or_reg(t, t, c); 3878ebe9383cSRichard Henderson ctx->null_cond = cond_make(TCG_COND_EQ, t, c); 3879ebe9383cSRichard Henderson } else { 3880eaa3783bSRichard Henderson tcg_gen_andi_reg(t, t, mask); 3881ebe9383cSRichard Henderson ctx->null_cond = cond_make_0(TCG_COND_EQ, t); 3882ebe9383cSRichard Henderson } 38831ca74648SRichard Henderson } else { 38841ca74648SRichard Henderson unsigned cbit = (a->y ^ 1) - 1; 38851ca74648SRichard Henderson 38861ca74648SRichard Henderson tcg_gen_extract_reg(t, t, 21 - cbit, 1); 38871ca74648SRichard Henderson ctx->null_cond = cond_make_0(TCG_COND_NE, t); 38881ca74648SRichard Henderson } 38891ca74648SRichard Henderson 3890ebe9383cSRichard Henderson done: 389131234768SRichard Henderson return nullify_end(ctx); 3892ebe9383cSRichard Henderson } 3893ebe9383cSRichard Henderson 38941ca74648SRichard Henderson /* 38951ca74648SRichard Henderson * Float class 2 38961ca74648SRichard Henderson */ 38971ca74648SRichard Henderson 38981ca74648SRichard Henderson static bool trans_fadd_f(DisasContext *ctx, arg_fclass3 *a) 3899ebe9383cSRichard Henderson { 39001ca74648SRichard Henderson return do_fop_weww(ctx, a->t, a->r1, a->r2, gen_helper_fadd_s); 39011ca74648SRichard Henderson } 39021ca74648SRichard Henderson 39031ca74648SRichard Henderson static bool trans_fadd_d(DisasContext *ctx, arg_fclass3 *a) 39041ca74648SRichard Henderson { 39051ca74648SRichard Henderson return do_fop_dedd(ctx, a->t, a->r1, a->r2, gen_helper_fadd_d); 39061ca74648SRichard Henderson } 39071ca74648SRichard Henderson 39081ca74648SRichard Henderson static bool trans_fsub_f(DisasContext *ctx, arg_fclass3 *a) 39091ca74648SRichard Henderson { 39101ca74648SRichard Henderson return do_fop_weww(ctx, a->t, a->r1, a->r2, gen_helper_fsub_s); 39111ca74648SRichard Henderson } 39121ca74648SRichard Henderson 39131ca74648SRichard Henderson static bool trans_fsub_d(DisasContext *ctx, arg_fclass3 *a) 39141ca74648SRichard Henderson { 39151ca74648SRichard Henderson return do_fop_dedd(ctx, a->t, a->r1, a->r2, gen_helper_fsub_d); 39161ca74648SRichard Henderson } 39171ca74648SRichard Henderson 39181ca74648SRichard Henderson static bool trans_fmpy_f(DisasContext *ctx, arg_fclass3 *a) 39191ca74648SRichard Henderson { 39201ca74648SRichard Henderson return do_fop_weww(ctx, a->t, a->r1, a->r2, gen_helper_fmpy_s); 39211ca74648SRichard Henderson } 39221ca74648SRichard Henderson 39231ca74648SRichard Henderson static bool trans_fmpy_d(DisasContext *ctx, arg_fclass3 *a) 39241ca74648SRichard Henderson { 39251ca74648SRichard Henderson return do_fop_dedd(ctx, a->t, a->r1, a->r2, gen_helper_fmpy_d); 39261ca74648SRichard Henderson } 39271ca74648SRichard Henderson 39281ca74648SRichard Henderson static bool trans_fdiv_f(DisasContext *ctx, arg_fclass3 *a) 39291ca74648SRichard Henderson { 39301ca74648SRichard Henderson return do_fop_weww(ctx, a->t, a->r1, a->r2, gen_helper_fdiv_s); 39311ca74648SRichard Henderson } 39321ca74648SRichard Henderson 39331ca74648SRichard Henderson static bool trans_fdiv_d(DisasContext *ctx, arg_fclass3 *a) 39341ca74648SRichard Henderson { 39351ca74648SRichard Henderson return do_fop_dedd(ctx, a->t, a->r1, a->r2, gen_helper_fdiv_d); 39361ca74648SRichard Henderson } 39371ca74648SRichard Henderson 39381ca74648SRichard Henderson static bool trans_xmpyu(DisasContext *ctx, arg_xmpyu *a) 39391ca74648SRichard Henderson { 39401ca74648SRichard Henderson TCGv_i64 x, y; 3941ebe9383cSRichard Henderson 3942ebe9383cSRichard Henderson nullify_over(ctx); 3943ebe9383cSRichard Henderson 39441ca74648SRichard Henderson x = load_frw0_i64(a->r1); 39451ca74648SRichard Henderson y = load_frw0_i64(a->r2); 39461ca74648SRichard Henderson tcg_gen_mul_i64(x, x, y); 39471ca74648SRichard Henderson save_frd(a->t, x); 3948ebe9383cSRichard Henderson 394931234768SRichard Henderson return nullify_end(ctx); 3950ebe9383cSRichard Henderson } 3951ebe9383cSRichard Henderson 3952ebe9383cSRichard Henderson /* Convert the fmpyadd single-precision register encodings to standard. */ 3953ebe9383cSRichard Henderson static inline int fmpyadd_s_reg(unsigned r) 3954ebe9383cSRichard Henderson { 3955ebe9383cSRichard Henderson return (r & 16) * 2 + 16 + (r & 15); 3956ebe9383cSRichard Henderson } 3957ebe9383cSRichard Henderson 3958b1e2af57SRichard Henderson static bool do_fmpyadd_s(DisasContext *ctx, arg_mpyadd *a, bool is_sub) 3959ebe9383cSRichard Henderson { 3960b1e2af57SRichard Henderson int tm = fmpyadd_s_reg(a->tm); 3961b1e2af57SRichard Henderson int ra = fmpyadd_s_reg(a->ra); 3962b1e2af57SRichard Henderson int ta = fmpyadd_s_reg(a->ta); 3963b1e2af57SRichard Henderson int rm2 = fmpyadd_s_reg(a->rm2); 3964b1e2af57SRichard Henderson int rm1 = fmpyadd_s_reg(a->rm1); 3965ebe9383cSRichard Henderson 3966ebe9383cSRichard Henderson nullify_over(ctx); 3967ebe9383cSRichard Henderson 3968ebe9383cSRichard Henderson do_fop_weww(ctx, tm, rm1, rm2, gen_helper_fmpy_s); 3969ebe9383cSRichard Henderson do_fop_weww(ctx, ta, ta, ra, 3970ebe9383cSRichard Henderson is_sub ? gen_helper_fsub_s : gen_helper_fadd_s); 3971ebe9383cSRichard Henderson 397231234768SRichard Henderson return nullify_end(ctx); 3973ebe9383cSRichard Henderson } 3974ebe9383cSRichard Henderson 3975b1e2af57SRichard Henderson static bool trans_fmpyadd_f(DisasContext *ctx, arg_mpyadd *a) 3976b1e2af57SRichard Henderson { 3977b1e2af57SRichard Henderson return do_fmpyadd_s(ctx, a, false); 3978b1e2af57SRichard Henderson } 3979b1e2af57SRichard Henderson 3980b1e2af57SRichard Henderson static bool trans_fmpysub_f(DisasContext *ctx, arg_mpyadd *a) 3981b1e2af57SRichard Henderson { 3982b1e2af57SRichard Henderson return do_fmpyadd_s(ctx, a, true); 3983b1e2af57SRichard Henderson } 3984b1e2af57SRichard Henderson 3985b1e2af57SRichard Henderson static bool do_fmpyadd_d(DisasContext *ctx, arg_mpyadd *a, bool is_sub) 3986b1e2af57SRichard Henderson { 3987b1e2af57SRichard Henderson nullify_over(ctx); 3988b1e2af57SRichard Henderson 3989b1e2af57SRichard Henderson do_fop_dedd(ctx, a->tm, a->rm1, a->rm2, gen_helper_fmpy_d); 3990b1e2af57SRichard Henderson do_fop_dedd(ctx, a->ta, a->ta, a->ra, 3991b1e2af57SRichard Henderson is_sub ? gen_helper_fsub_d : gen_helper_fadd_d); 3992b1e2af57SRichard Henderson 3993b1e2af57SRichard Henderson return nullify_end(ctx); 3994b1e2af57SRichard Henderson } 3995b1e2af57SRichard Henderson 3996b1e2af57SRichard Henderson static bool trans_fmpyadd_d(DisasContext *ctx, arg_mpyadd *a) 3997b1e2af57SRichard Henderson { 3998b1e2af57SRichard Henderson return do_fmpyadd_d(ctx, a, false); 3999b1e2af57SRichard Henderson } 4000b1e2af57SRichard Henderson 4001b1e2af57SRichard Henderson static bool trans_fmpysub_d(DisasContext *ctx, arg_mpyadd *a) 4002b1e2af57SRichard Henderson { 4003b1e2af57SRichard Henderson return do_fmpyadd_d(ctx, a, true); 4004b1e2af57SRichard Henderson } 4005b1e2af57SRichard Henderson 4006c3bad4f8SRichard Henderson static bool trans_fmpyfadd_f(DisasContext *ctx, arg_fmpyfadd_f *a) 4007ebe9383cSRichard Henderson { 4008c3bad4f8SRichard Henderson TCGv_i32 x, y, z; 4009ebe9383cSRichard Henderson 4010ebe9383cSRichard Henderson nullify_over(ctx); 4011c3bad4f8SRichard Henderson x = load_frw0_i32(a->rm1); 4012c3bad4f8SRichard Henderson y = load_frw0_i32(a->rm2); 4013c3bad4f8SRichard Henderson z = load_frw0_i32(a->ra3); 4014ebe9383cSRichard Henderson 4015c3bad4f8SRichard Henderson if (a->neg) { 4016c3bad4f8SRichard Henderson gen_helper_fmpynfadd_s(x, cpu_env, x, y, z); 4017ebe9383cSRichard Henderson } else { 4018c3bad4f8SRichard Henderson gen_helper_fmpyfadd_s(x, cpu_env, x, y, z); 4019ebe9383cSRichard Henderson } 4020ebe9383cSRichard Henderson 4021c3bad4f8SRichard Henderson save_frw_i32(a->t, x); 402231234768SRichard Henderson return nullify_end(ctx); 4023ebe9383cSRichard Henderson } 4024ebe9383cSRichard Henderson 4025c3bad4f8SRichard Henderson static bool trans_fmpyfadd_d(DisasContext *ctx, arg_fmpyfadd_d *a) 4026ebe9383cSRichard Henderson { 4027c3bad4f8SRichard Henderson TCGv_i64 x, y, z; 4028ebe9383cSRichard Henderson 4029ebe9383cSRichard Henderson nullify_over(ctx); 4030c3bad4f8SRichard Henderson x = load_frd0(a->rm1); 4031c3bad4f8SRichard Henderson y = load_frd0(a->rm2); 4032c3bad4f8SRichard Henderson z = load_frd0(a->ra3); 4033ebe9383cSRichard Henderson 4034c3bad4f8SRichard Henderson if (a->neg) { 4035c3bad4f8SRichard Henderson gen_helper_fmpynfadd_d(x, cpu_env, x, y, z); 4036ebe9383cSRichard Henderson } else { 4037c3bad4f8SRichard Henderson gen_helper_fmpyfadd_d(x, cpu_env, x, y, z); 4038ebe9383cSRichard Henderson } 4039ebe9383cSRichard Henderson 4040c3bad4f8SRichard Henderson save_frd(a->t, x); 404131234768SRichard Henderson return nullify_end(ctx); 4042ebe9383cSRichard Henderson } 4043ebe9383cSRichard Henderson 404415da177bSSven Schnelle static bool trans_diag(DisasContext *ctx, arg_diag *a) 404515da177bSSven Schnelle { 404615da177bSSven Schnelle qemu_log_mask(LOG_UNIMP, "DIAG opcode ignored\n"); 404715da177bSSven Schnelle cond_free(&ctx->null_cond); 404815da177bSSven Schnelle return true; 404915da177bSSven Schnelle } 405015da177bSSven Schnelle 4051b542683dSEmilio G. Cota static void hppa_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) 405261766fe9SRichard Henderson { 405351b061fbSRichard Henderson DisasContext *ctx = container_of(dcbase, DisasContext, base); 4054f764718dSRichard Henderson int bound; 405561766fe9SRichard Henderson 405651b061fbSRichard Henderson ctx->cs = cs; 4057494737b7SRichard Henderson ctx->tb_flags = ctx->base.tb->flags; 40583d68ee7bSRichard Henderson 40593d68ee7bSRichard Henderson #ifdef CONFIG_USER_ONLY 4060*c01e5dfbSHelge Deller ctx->privilege = MMU_IDX_TO_PRIV(MMU_USER_IDX); 40613d68ee7bSRichard Henderson ctx->mmu_idx = MMU_USER_IDX; 4062*c01e5dfbSHelge Deller ctx->iaoq_f = ctx->base.pc_first | ctx->privilege; 4063*c01e5dfbSHelge Deller ctx->iaoq_b = ctx->base.tb->cs_base | ctx->privilege; 4064217d1a5eSRichard Henderson ctx->unalign = (ctx->tb_flags & TB_FLAG_UNALIGN ? MO_UNALN : MO_ALIGN); 4065c301f34eSRichard Henderson #else 4066494737b7SRichard Henderson ctx->privilege = (ctx->tb_flags >> TB_FLAG_PRIV_SHIFT) & 3; 4067*c01e5dfbSHelge Deller ctx->mmu_idx = (ctx->tb_flags & PSW_D ? 4068*c01e5dfbSHelge Deller PRIV_TO_MMU_IDX(ctx->privilege) : MMU_PHYS_IDX); 40693d68ee7bSRichard Henderson 4070c301f34eSRichard Henderson /* Recover the IAOQ values from the GVA + PRIV. */ 4071c301f34eSRichard Henderson uint64_t cs_base = ctx->base.tb->cs_base; 4072c301f34eSRichard Henderson uint64_t iasq_f = cs_base & ~0xffffffffull; 4073c301f34eSRichard Henderson int32_t diff = cs_base; 4074c301f34eSRichard Henderson 4075c301f34eSRichard Henderson ctx->iaoq_f = (ctx->base.pc_first & ~iasq_f) + ctx->privilege; 4076c301f34eSRichard Henderson ctx->iaoq_b = (diff ? ctx->iaoq_f + diff : -1); 4077c301f34eSRichard Henderson #endif 407851b061fbSRichard Henderson ctx->iaoq_n = -1; 4079f764718dSRichard Henderson ctx->iaoq_n_var = NULL; 408061766fe9SRichard Henderson 40813d68ee7bSRichard Henderson /* Bound the number of instructions by those left on the page. */ 40823d68ee7bSRichard Henderson bound = -(ctx->base.pc_first | TARGET_PAGE_MASK) / 4; 4083b542683dSEmilio G. Cota ctx->base.max_insns = MIN(ctx->base.max_insns, bound); 40843d68ee7bSRichard Henderson 408586f8d05fSRichard Henderson ctx->ntempr = 0; 408686f8d05fSRichard Henderson ctx->ntempl = 0; 408786f8d05fSRichard Henderson memset(ctx->tempr, 0, sizeof(ctx->tempr)); 408886f8d05fSRichard Henderson memset(ctx->templ, 0, sizeof(ctx->templ)); 408961766fe9SRichard Henderson } 409061766fe9SRichard Henderson 409151b061fbSRichard Henderson static void hppa_tr_tb_start(DisasContextBase *dcbase, CPUState *cs) 409251b061fbSRichard Henderson { 409351b061fbSRichard Henderson DisasContext *ctx = container_of(dcbase, DisasContext, base); 409461766fe9SRichard Henderson 40953d68ee7bSRichard Henderson /* Seed the nullification status from PSW[N], as saved in TB->FLAGS. */ 409651b061fbSRichard Henderson ctx->null_cond = cond_make_f(); 409751b061fbSRichard Henderson ctx->psw_n_nonzero = false; 4098494737b7SRichard Henderson if (ctx->tb_flags & PSW_N) { 409951b061fbSRichard Henderson ctx->null_cond.c = TCG_COND_ALWAYS; 410051b061fbSRichard Henderson ctx->psw_n_nonzero = true; 4101129e9cc3SRichard Henderson } 410251b061fbSRichard Henderson ctx->null_lab = NULL; 410361766fe9SRichard Henderson } 410461766fe9SRichard Henderson 410551b061fbSRichard Henderson static void hppa_tr_insn_start(DisasContextBase *dcbase, CPUState *cs) 410651b061fbSRichard Henderson { 410751b061fbSRichard Henderson DisasContext *ctx = container_of(dcbase, DisasContext, base); 410851b061fbSRichard Henderson 410951b061fbSRichard Henderson tcg_gen_insn_start(ctx->iaoq_f, ctx->iaoq_b); 411051b061fbSRichard Henderson } 411151b061fbSRichard Henderson 411251b061fbSRichard Henderson static void hppa_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) 411351b061fbSRichard Henderson { 411451b061fbSRichard Henderson DisasContext *ctx = container_of(dcbase, DisasContext, base); 411551b061fbSRichard Henderson CPUHPPAState *env = cs->env_ptr; 411651b061fbSRichard Henderson DisasJumpType ret; 411751b061fbSRichard Henderson int i, n; 411851b061fbSRichard Henderson 411951b061fbSRichard Henderson /* Execute one insn. */ 4120ba1d0b44SRichard Henderson #ifdef CONFIG_USER_ONLY 4121c301f34eSRichard Henderson if (ctx->base.pc_next < TARGET_PAGE_SIZE) { 412231234768SRichard Henderson do_page_zero(ctx); 412331234768SRichard Henderson ret = ctx->base.is_jmp; 4124869051eaSRichard Henderson assert(ret != DISAS_NEXT); 4125ba1d0b44SRichard Henderson } else 4126ba1d0b44SRichard Henderson #endif 4127ba1d0b44SRichard Henderson { 412861766fe9SRichard Henderson /* Always fetch the insn, even if nullified, so that we check 412961766fe9SRichard Henderson the page permissions for execute. */ 41304e116893SIlya Leoshkevich uint32_t insn = translator_ldl(env, &ctx->base, ctx->base.pc_next); 413161766fe9SRichard Henderson 413261766fe9SRichard Henderson /* Set up the IA queue for the next insn. 413361766fe9SRichard Henderson This will be overwritten by a branch. */ 413451b061fbSRichard Henderson if (ctx->iaoq_b == -1) { 413551b061fbSRichard Henderson ctx->iaoq_n = -1; 413651b061fbSRichard Henderson ctx->iaoq_n_var = get_temp(ctx); 4137eaa3783bSRichard Henderson tcg_gen_addi_reg(ctx->iaoq_n_var, cpu_iaoq_b, 4); 413861766fe9SRichard Henderson } else { 413951b061fbSRichard Henderson ctx->iaoq_n = ctx->iaoq_b + 4; 4140f764718dSRichard Henderson ctx->iaoq_n_var = NULL; 414161766fe9SRichard Henderson } 414261766fe9SRichard Henderson 414351b061fbSRichard Henderson if (unlikely(ctx->null_cond.c == TCG_COND_ALWAYS)) { 414451b061fbSRichard Henderson ctx->null_cond.c = TCG_COND_NEVER; 4145869051eaSRichard Henderson ret = DISAS_NEXT; 4146129e9cc3SRichard Henderson } else { 41471a19da0dSRichard Henderson ctx->insn = insn; 414831274b46SRichard Henderson if (!decode(ctx, insn)) { 414931274b46SRichard Henderson gen_illegal(ctx); 415031274b46SRichard Henderson } 415131234768SRichard Henderson ret = ctx->base.is_jmp; 415251b061fbSRichard Henderson assert(ctx->null_lab == NULL); 4153129e9cc3SRichard Henderson } 415461766fe9SRichard Henderson } 415561766fe9SRichard Henderson 4156af187238SRichard Henderson /* Forget any temporaries allocated. */ 415786f8d05fSRichard Henderson for (i = 0, n = ctx->ntempr; i < n; ++i) { 415886f8d05fSRichard Henderson ctx->tempr[i] = NULL; 415961766fe9SRichard Henderson } 416086f8d05fSRichard Henderson for (i = 0, n = ctx->ntempl; i < n; ++i) { 416186f8d05fSRichard Henderson ctx->templ[i] = NULL; 416286f8d05fSRichard Henderson } 416386f8d05fSRichard Henderson ctx->ntempr = 0; 416486f8d05fSRichard Henderson ctx->ntempl = 0; 416561766fe9SRichard Henderson 41663d68ee7bSRichard Henderson /* Advance the insn queue. Note that this check also detects 41673d68ee7bSRichard Henderson a priority change within the instruction queue. */ 416851b061fbSRichard Henderson if (ret == DISAS_NEXT && ctx->iaoq_b != ctx->iaoq_f + 4) { 4169c301f34eSRichard Henderson if (ctx->iaoq_b != -1 && ctx->iaoq_n != -1 4170c301f34eSRichard Henderson && use_goto_tb(ctx, ctx->iaoq_b) 4171c301f34eSRichard Henderson && (ctx->null_cond.c == TCG_COND_NEVER 4172c301f34eSRichard Henderson || ctx->null_cond.c == TCG_COND_ALWAYS)) { 417351b061fbSRichard Henderson nullify_set(ctx, ctx->null_cond.c == TCG_COND_ALWAYS); 417451b061fbSRichard Henderson gen_goto_tb(ctx, 0, ctx->iaoq_b, ctx->iaoq_n); 417531234768SRichard Henderson ctx->base.is_jmp = ret = DISAS_NORETURN; 4176129e9cc3SRichard Henderson } else { 417731234768SRichard Henderson ctx->base.is_jmp = ret = DISAS_IAQ_N_STALE; 417861766fe9SRichard Henderson } 4179129e9cc3SRichard Henderson } 418051b061fbSRichard Henderson ctx->iaoq_f = ctx->iaoq_b; 418151b061fbSRichard Henderson ctx->iaoq_b = ctx->iaoq_n; 4182c301f34eSRichard Henderson ctx->base.pc_next += 4; 418361766fe9SRichard Henderson 4184c5d0aec2SRichard Henderson switch (ret) { 4185c5d0aec2SRichard Henderson case DISAS_NORETURN: 4186c5d0aec2SRichard Henderson case DISAS_IAQ_N_UPDATED: 4187c5d0aec2SRichard Henderson break; 4188c5d0aec2SRichard Henderson 4189c5d0aec2SRichard Henderson case DISAS_NEXT: 4190c5d0aec2SRichard Henderson case DISAS_IAQ_N_STALE: 4191c5d0aec2SRichard Henderson case DISAS_IAQ_N_STALE_EXIT: 419251b061fbSRichard Henderson if (ctx->iaoq_f == -1) { 4193eaa3783bSRichard Henderson tcg_gen_mov_reg(cpu_iaoq_f, cpu_iaoq_b); 419451b061fbSRichard Henderson copy_iaoq_entry(cpu_iaoq_b, ctx->iaoq_n, ctx->iaoq_n_var); 4195c301f34eSRichard Henderson #ifndef CONFIG_USER_ONLY 4196c301f34eSRichard Henderson tcg_gen_mov_i64(cpu_iasq_f, cpu_iasq_b); 4197c301f34eSRichard Henderson #endif 419851b061fbSRichard Henderson nullify_save(ctx); 4199c5d0aec2SRichard Henderson ctx->base.is_jmp = (ret == DISAS_IAQ_N_STALE_EXIT 4200c5d0aec2SRichard Henderson ? DISAS_EXIT 4201c5d0aec2SRichard Henderson : DISAS_IAQ_N_UPDATED); 420251b061fbSRichard Henderson } else if (ctx->iaoq_b == -1) { 4203eaa3783bSRichard Henderson tcg_gen_mov_reg(cpu_iaoq_b, ctx->iaoq_n_var); 420461766fe9SRichard Henderson } 4205c5d0aec2SRichard Henderson break; 4206c5d0aec2SRichard Henderson 4207c5d0aec2SRichard Henderson default: 4208c5d0aec2SRichard Henderson g_assert_not_reached(); 4209c5d0aec2SRichard Henderson } 421061766fe9SRichard Henderson } 421161766fe9SRichard Henderson 421251b061fbSRichard Henderson static void hppa_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs) 421351b061fbSRichard Henderson { 421451b061fbSRichard Henderson DisasContext *ctx = container_of(dcbase, DisasContext, base); 4215e1b5a5edSRichard Henderson DisasJumpType is_jmp = ctx->base.is_jmp; 421651b061fbSRichard Henderson 4217e1b5a5edSRichard Henderson switch (is_jmp) { 4218869051eaSRichard Henderson case DISAS_NORETURN: 421961766fe9SRichard Henderson break; 422051b061fbSRichard Henderson case DISAS_TOO_MANY: 4221869051eaSRichard Henderson case DISAS_IAQ_N_STALE: 4222e1b5a5edSRichard Henderson case DISAS_IAQ_N_STALE_EXIT: 422351b061fbSRichard Henderson copy_iaoq_entry(cpu_iaoq_f, ctx->iaoq_f, cpu_iaoq_f); 422451b061fbSRichard Henderson copy_iaoq_entry(cpu_iaoq_b, ctx->iaoq_b, cpu_iaoq_b); 422551b061fbSRichard Henderson nullify_save(ctx); 422661766fe9SRichard Henderson /* FALLTHRU */ 4227869051eaSRichard Henderson case DISAS_IAQ_N_UPDATED: 42288532a14eSRichard Henderson if (is_jmp != DISAS_IAQ_N_STALE_EXIT) { 42297f11636dSEmilio G. Cota tcg_gen_lookup_and_goto_ptr(); 42308532a14eSRichard Henderson break; 423161766fe9SRichard Henderson } 4232c5d0aec2SRichard Henderson /* FALLTHRU */ 4233c5d0aec2SRichard Henderson case DISAS_EXIT: 4234c5d0aec2SRichard Henderson tcg_gen_exit_tb(NULL, 0); 423561766fe9SRichard Henderson break; 423661766fe9SRichard Henderson default: 423751b061fbSRichard Henderson g_assert_not_reached(); 423861766fe9SRichard Henderson } 423951b061fbSRichard Henderson } 424061766fe9SRichard Henderson 42418eb806a7SRichard Henderson static void hppa_tr_disas_log(const DisasContextBase *dcbase, 42428eb806a7SRichard Henderson CPUState *cs, FILE *logfile) 424351b061fbSRichard Henderson { 4244c301f34eSRichard Henderson target_ulong pc = dcbase->pc_first; 424561766fe9SRichard Henderson 4246ba1d0b44SRichard Henderson #ifdef CONFIG_USER_ONLY 4247ba1d0b44SRichard Henderson switch (pc) { 42487ad439dfSRichard Henderson case 0x00: 42498eb806a7SRichard Henderson fprintf(logfile, "IN:\n0x00000000: (null)\n"); 4250ba1d0b44SRichard Henderson return; 42517ad439dfSRichard Henderson case 0xb0: 42528eb806a7SRichard Henderson fprintf(logfile, "IN:\n0x000000b0: light-weight-syscall\n"); 4253ba1d0b44SRichard Henderson return; 42547ad439dfSRichard Henderson case 0xe0: 42558eb806a7SRichard Henderson fprintf(logfile, "IN:\n0x000000e0: set-thread-pointer-syscall\n"); 4256ba1d0b44SRichard Henderson return; 42577ad439dfSRichard Henderson case 0x100: 42588eb806a7SRichard Henderson fprintf(logfile, "IN:\n0x00000100: syscall\n"); 4259ba1d0b44SRichard Henderson return; 42607ad439dfSRichard Henderson } 4261ba1d0b44SRichard Henderson #endif 4262ba1d0b44SRichard Henderson 42638eb806a7SRichard Henderson fprintf(logfile, "IN: %s\n", lookup_symbol(pc)); 42648eb806a7SRichard Henderson target_disas(logfile, cs, pc, dcbase->tb->size); 426561766fe9SRichard Henderson } 426651b061fbSRichard Henderson 426751b061fbSRichard Henderson static const TranslatorOps hppa_tr_ops = { 426851b061fbSRichard Henderson .init_disas_context = hppa_tr_init_disas_context, 426951b061fbSRichard Henderson .tb_start = hppa_tr_tb_start, 427051b061fbSRichard Henderson .insn_start = hppa_tr_insn_start, 427151b061fbSRichard Henderson .translate_insn = hppa_tr_translate_insn, 427251b061fbSRichard Henderson .tb_stop = hppa_tr_tb_stop, 427351b061fbSRichard Henderson .disas_log = hppa_tr_disas_log, 427451b061fbSRichard Henderson }; 427551b061fbSRichard Henderson 4276597f9b2dSRichard Henderson void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int *max_insns, 4277306c8721SRichard Henderson target_ulong pc, void *host_pc) 427851b061fbSRichard Henderson { 427951b061fbSRichard Henderson DisasContext ctx; 4280306c8721SRichard Henderson translator_loop(cs, tb, max_insns, pc, host_pc, &hppa_tr_ops, &ctx.base); 428161766fe9SRichard Henderson } 4282