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 961766fe9SRichard Henderson * version 2 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 "trace-tcg.h" 3161766fe9SRichard Henderson #include "exec/log.h" 3261766fe9SRichard Henderson 33eaa3783bSRichard Henderson /* Since we have a distinction between register size and address size, 34eaa3783bSRichard Henderson we need to redefine all of these. */ 35eaa3783bSRichard Henderson 36eaa3783bSRichard Henderson #undef TCGv 37eaa3783bSRichard Henderson #undef tcg_temp_new 38eaa3783bSRichard Henderson #undef tcg_global_reg_new 39eaa3783bSRichard Henderson #undef tcg_global_mem_new 40eaa3783bSRichard Henderson #undef tcg_temp_local_new 41eaa3783bSRichard Henderson #undef tcg_temp_free 42eaa3783bSRichard Henderson 43eaa3783bSRichard Henderson #if TARGET_LONG_BITS == 64 44eaa3783bSRichard Henderson #define TCGv_tl TCGv_i64 45eaa3783bSRichard Henderson #define tcg_temp_new_tl tcg_temp_new_i64 46eaa3783bSRichard Henderson #define tcg_temp_free_tl tcg_temp_free_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_temp_free_tl tcg_temp_free_i32 56eaa3783bSRichard Henderson #define tcg_gen_extu_reg_tl tcg_gen_mov_i32 57eaa3783bSRichard Henderson #endif 58eaa3783bSRichard Henderson 59eaa3783bSRichard Henderson #if TARGET_REGISTER_BITS == 64 60eaa3783bSRichard Henderson #define TCGv_reg TCGv_i64 61eaa3783bSRichard Henderson 62eaa3783bSRichard Henderson #define tcg_temp_new tcg_temp_new_i64 63eaa3783bSRichard Henderson #define tcg_global_reg_new tcg_global_reg_new_i64 64eaa3783bSRichard Henderson #define tcg_global_mem_new tcg_global_mem_new_i64 65eaa3783bSRichard Henderson #define tcg_temp_local_new tcg_temp_local_new_i64 66eaa3783bSRichard Henderson #define tcg_temp_free tcg_temp_free_i64 67eaa3783bSRichard Henderson 68eaa3783bSRichard Henderson #define tcg_gen_movi_reg tcg_gen_movi_i64 69eaa3783bSRichard Henderson #define tcg_gen_mov_reg tcg_gen_mov_i64 70eaa3783bSRichard Henderson #define tcg_gen_ld8u_reg tcg_gen_ld8u_i64 71eaa3783bSRichard Henderson #define tcg_gen_ld8s_reg tcg_gen_ld8s_i64 72eaa3783bSRichard Henderson #define tcg_gen_ld16u_reg tcg_gen_ld16u_i64 73eaa3783bSRichard Henderson #define tcg_gen_ld16s_reg tcg_gen_ld16s_i64 74eaa3783bSRichard Henderson #define tcg_gen_ld32u_reg tcg_gen_ld32u_i64 75eaa3783bSRichard Henderson #define tcg_gen_ld32s_reg tcg_gen_ld32s_i64 76eaa3783bSRichard Henderson #define tcg_gen_ld_reg tcg_gen_ld_i64 77eaa3783bSRichard Henderson #define tcg_gen_st8_reg tcg_gen_st8_i64 78eaa3783bSRichard Henderson #define tcg_gen_st16_reg tcg_gen_st16_i64 79eaa3783bSRichard Henderson #define tcg_gen_st32_reg tcg_gen_st32_i64 80eaa3783bSRichard Henderson #define tcg_gen_st_reg tcg_gen_st_i64 81eaa3783bSRichard Henderson #define tcg_gen_add_reg tcg_gen_add_i64 82eaa3783bSRichard Henderson #define tcg_gen_addi_reg tcg_gen_addi_i64 83eaa3783bSRichard Henderson #define tcg_gen_sub_reg tcg_gen_sub_i64 84eaa3783bSRichard Henderson #define tcg_gen_neg_reg tcg_gen_neg_i64 85eaa3783bSRichard Henderson #define tcg_gen_subfi_reg tcg_gen_subfi_i64 86eaa3783bSRichard Henderson #define tcg_gen_subi_reg tcg_gen_subi_i64 87eaa3783bSRichard Henderson #define tcg_gen_and_reg tcg_gen_and_i64 88eaa3783bSRichard Henderson #define tcg_gen_andi_reg tcg_gen_andi_i64 89eaa3783bSRichard Henderson #define tcg_gen_or_reg tcg_gen_or_i64 90eaa3783bSRichard Henderson #define tcg_gen_ori_reg tcg_gen_ori_i64 91eaa3783bSRichard Henderson #define tcg_gen_xor_reg tcg_gen_xor_i64 92eaa3783bSRichard Henderson #define tcg_gen_xori_reg tcg_gen_xori_i64 93eaa3783bSRichard Henderson #define tcg_gen_not_reg tcg_gen_not_i64 94eaa3783bSRichard Henderson #define tcg_gen_shl_reg tcg_gen_shl_i64 95eaa3783bSRichard Henderson #define tcg_gen_shli_reg tcg_gen_shli_i64 96eaa3783bSRichard Henderson #define tcg_gen_shr_reg tcg_gen_shr_i64 97eaa3783bSRichard Henderson #define tcg_gen_shri_reg tcg_gen_shri_i64 98eaa3783bSRichard Henderson #define tcg_gen_sar_reg tcg_gen_sar_i64 99eaa3783bSRichard Henderson #define tcg_gen_sari_reg tcg_gen_sari_i64 100eaa3783bSRichard Henderson #define tcg_gen_brcond_reg tcg_gen_brcond_i64 101eaa3783bSRichard Henderson #define tcg_gen_brcondi_reg tcg_gen_brcondi_i64 102eaa3783bSRichard Henderson #define tcg_gen_setcond_reg tcg_gen_setcond_i64 103eaa3783bSRichard Henderson #define tcg_gen_setcondi_reg tcg_gen_setcondi_i64 104eaa3783bSRichard Henderson #define tcg_gen_mul_reg tcg_gen_mul_i64 105eaa3783bSRichard Henderson #define tcg_gen_muli_reg tcg_gen_muli_i64 106eaa3783bSRichard Henderson #define tcg_gen_div_reg tcg_gen_div_i64 107eaa3783bSRichard Henderson #define tcg_gen_rem_reg tcg_gen_rem_i64 108eaa3783bSRichard Henderson #define tcg_gen_divu_reg tcg_gen_divu_i64 109eaa3783bSRichard Henderson #define tcg_gen_remu_reg tcg_gen_remu_i64 110eaa3783bSRichard Henderson #define tcg_gen_discard_reg tcg_gen_discard_i64 111eaa3783bSRichard Henderson #define tcg_gen_trunc_reg_i32 tcg_gen_extrl_i64_i32 112eaa3783bSRichard Henderson #define tcg_gen_trunc_i64_reg tcg_gen_mov_i64 113eaa3783bSRichard Henderson #define tcg_gen_extu_i32_reg tcg_gen_extu_i32_i64 114eaa3783bSRichard Henderson #define tcg_gen_ext_i32_reg tcg_gen_ext_i32_i64 115eaa3783bSRichard Henderson #define tcg_gen_extu_reg_i64 tcg_gen_mov_i64 116eaa3783bSRichard Henderson #define tcg_gen_ext_reg_i64 tcg_gen_mov_i64 117eaa3783bSRichard Henderson #define tcg_gen_ext8u_reg tcg_gen_ext8u_i64 118eaa3783bSRichard Henderson #define tcg_gen_ext8s_reg tcg_gen_ext8s_i64 119eaa3783bSRichard Henderson #define tcg_gen_ext16u_reg tcg_gen_ext16u_i64 120eaa3783bSRichard Henderson #define tcg_gen_ext16s_reg tcg_gen_ext16s_i64 121eaa3783bSRichard Henderson #define tcg_gen_ext32u_reg tcg_gen_ext32u_i64 122eaa3783bSRichard Henderson #define tcg_gen_ext32s_reg tcg_gen_ext32s_i64 123eaa3783bSRichard Henderson #define tcg_gen_bswap16_reg tcg_gen_bswap16_i64 124eaa3783bSRichard Henderson #define tcg_gen_bswap32_reg tcg_gen_bswap32_i64 125eaa3783bSRichard Henderson #define tcg_gen_bswap64_reg tcg_gen_bswap64_i64 126eaa3783bSRichard Henderson #define tcg_gen_concat_reg_i64 tcg_gen_concat32_i64 127eaa3783bSRichard Henderson #define tcg_gen_andc_reg tcg_gen_andc_i64 128eaa3783bSRichard Henderson #define tcg_gen_eqv_reg tcg_gen_eqv_i64 129eaa3783bSRichard Henderson #define tcg_gen_nand_reg tcg_gen_nand_i64 130eaa3783bSRichard Henderson #define tcg_gen_nor_reg tcg_gen_nor_i64 131eaa3783bSRichard Henderson #define tcg_gen_orc_reg tcg_gen_orc_i64 132eaa3783bSRichard Henderson #define tcg_gen_clz_reg tcg_gen_clz_i64 133eaa3783bSRichard Henderson #define tcg_gen_ctz_reg tcg_gen_ctz_i64 134eaa3783bSRichard Henderson #define tcg_gen_clzi_reg tcg_gen_clzi_i64 135eaa3783bSRichard Henderson #define tcg_gen_ctzi_reg tcg_gen_ctzi_i64 136eaa3783bSRichard Henderson #define tcg_gen_clrsb_reg tcg_gen_clrsb_i64 137eaa3783bSRichard Henderson #define tcg_gen_ctpop_reg tcg_gen_ctpop_i64 138eaa3783bSRichard Henderson #define tcg_gen_rotl_reg tcg_gen_rotl_i64 139eaa3783bSRichard Henderson #define tcg_gen_rotli_reg tcg_gen_rotli_i64 140eaa3783bSRichard Henderson #define tcg_gen_rotr_reg tcg_gen_rotr_i64 141eaa3783bSRichard Henderson #define tcg_gen_rotri_reg tcg_gen_rotri_i64 142eaa3783bSRichard Henderson #define tcg_gen_deposit_reg tcg_gen_deposit_i64 143eaa3783bSRichard Henderson #define tcg_gen_deposit_z_reg tcg_gen_deposit_z_i64 144eaa3783bSRichard Henderson #define tcg_gen_extract_reg tcg_gen_extract_i64 145eaa3783bSRichard Henderson #define tcg_gen_sextract_reg tcg_gen_sextract_i64 146eaa3783bSRichard Henderson #define tcg_const_reg tcg_const_i64 147eaa3783bSRichard Henderson #define tcg_const_local_reg tcg_const_local_i64 148eaa3783bSRichard Henderson #define tcg_gen_movcond_reg tcg_gen_movcond_i64 149eaa3783bSRichard Henderson #define tcg_gen_add2_reg tcg_gen_add2_i64 150eaa3783bSRichard Henderson #define tcg_gen_sub2_reg tcg_gen_sub2_i64 151eaa3783bSRichard Henderson #define tcg_gen_qemu_ld_reg tcg_gen_qemu_ld_i64 152eaa3783bSRichard Henderson #define tcg_gen_qemu_st_reg tcg_gen_qemu_st_i64 153eaa3783bSRichard Henderson #define tcg_gen_atomic_xchg_reg tcg_gen_atomic_xchg_i64 1545bfa8034SRichard Henderson #define tcg_gen_trunc_reg_ptr tcg_gen_trunc_i64_ptr 155eaa3783bSRichard Henderson #else 156eaa3783bSRichard Henderson #define TCGv_reg TCGv_i32 157eaa3783bSRichard Henderson #define tcg_temp_new tcg_temp_new_i32 158eaa3783bSRichard Henderson #define tcg_global_reg_new tcg_global_reg_new_i32 159eaa3783bSRichard Henderson #define tcg_global_mem_new tcg_global_mem_new_i32 160eaa3783bSRichard Henderson #define tcg_temp_local_new tcg_temp_local_new_i32 161eaa3783bSRichard Henderson #define tcg_temp_free tcg_temp_free_i32 162eaa3783bSRichard Henderson 163eaa3783bSRichard Henderson #define tcg_gen_movi_reg tcg_gen_movi_i32 164eaa3783bSRichard Henderson #define tcg_gen_mov_reg tcg_gen_mov_i32 165eaa3783bSRichard Henderson #define tcg_gen_ld8u_reg tcg_gen_ld8u_i32 166eaa3783bSRichard Henderson #define tcg_gen_ld8s_reg tcg_gen_ld8s_i32 167eaa3783bSRichard Henderson #define tcg_gen_ld16u_reg tcg_gen_ld16u_i32 168eaa3783bSRichard Henderson #define tcg_gen_ld16s_reg tcg_gen_ld16s_i32 169eaa3783bSRichard Henderson #define tcg_gen_ld32u_reg tcg_gen_ld_i32 170eaa3783bSRichard Henderson #define tcg_gen_ld32s_reg tcg_gen_ld_i32 171eaa3783bSRichard Henderson #define tcg_gen_ld_reg tcg_gen_ld_i32 172eaa3783bSRichard Henderson #define tcg_gen_st8_reg tcg_gen_st8_i32 173eaa3783bSRichard Henderson #define tcg_gen_st16_reg tcg_gen_st16_i32 174eaa3783bSRichard Henderson #define tcg_gen_st32_reg tcg_gen_st32_i32 175eaa3783bSRichard Henderson #define tcg_gen_st_reg tcg_gen_st_i32 176eaa3783bSRichard Henderson #define tcg_gen_add_reg tcg_gen_add_i32 177eaa3783bSRichard Henderson #define tcg_gen_addi_reg tcg_gen_addi_i32 178eaa3783bSRichard Henderson #define tcg_gen_sub_reg tcg_gen_sub_i32 179eaa3783bSRichard Henderson #define tcg_gen_neg_reg tcg_gen_neg_i32 180eaa3783bSRichard Henderson #define tcg_gen_subfi_reg tcg_gen_subfi_i32 181eaa3783bSRichard Henderson #define tcg_gen_subi_reg tcg_gen_subi_i32 182eaa3783bSRichard Henderson #define tcg_gen_and_reg tcg_gen_and_i32 183eaa3783bSRichard Henderson #define tcg_gen_andi_reg tcg_gen_andi_i32 184eaa3783bSRichard Henderson #define tcg_gen_or_reg tcg_gen_or_i32 185eaa3783bSRichard Henderson #define tcg_gen_ori_reg tcg_gen_ori_i32 186eaa3783bSRichard Henderson #define tcg_gen_xor_reg tcg_gen_xor_i32 187eaa3783bSRichard Henderson #define tcg_gen_xori_reg tcg_gen_xori_i32 188eaa3783bSRichard Henderson #define tcg_gen_not_reg tcg_gen_not_i32 189eaa3783bSRichard Henderson #define tcg_gen_shl_reg tcg_gen_shl_i32 190eaa3783bSRichard Henderson #define tcg_gen_shli_reg tcg_gen_shli_i32 191eaa3783bSRichard Henderson #define tcg_gen_shr_reg tcg_gen_shr_i32 192eaa3783bSRichard Henderson #define tcg_gen_shri_reg tcg_gen_shri_i32 193eaa3783bSRichard Henderson #define tcg_gen_sar_reg tcg_gen_sar_i32 194eaa3783bSRichard Henderson #define tcg_gen_sari_reg tcg_gen_sari_i32 195eaa3783bSRichard Henderson #define tcg_gen_brcond_reg tcg_gen_brcond_i32 196eaa3783bSRichard Henderson #define tcg_gen_brcondi_reg tcg_gen_brcondi_i32 197eaa3783bSRichard Henderson #define tcg_gen_setcond_reg tcg_gen_setcond_i32 198eaa3783bSRichard Henderson #define tcg_gen_setcondi_reg tcg_gen_setcondi_i32 199eaa3783bSRichard Henderson #define tcg_gen_mul_reg tcg_gen_mul_i32 200eaa3783bSRichard Henderson #define tcg_gen_muli_reg tcg_gen_muli_i32 201eaa3783bSRichard Henderson #define tcg_gen_div_reg tcg_gen_div_i32 202eaa3783bSRichard Henderson #define tcg_gen_rem_reg tcg_gen_rem_i32 203eaa3783bSRichard Henderson #define tcg_gen_divu_reg tcg_gen_divu_i32 204eaa3783bSRichard Henderson #define tcg_gen_remu_reg tcg_gen_remu_i32 205eaa3783bSRichard Henderson #define tcg_gen_discard_reg tcg_gen_discard_i32 206eaa3783bSRichard Henderson #define tcg_gen_trunc_reg_i32 tcg_gen_mov_i32 207eaa3783bSRichard Henderson #define tcg_gen_trunc_i64_reg tcg_gen_extrl_i64_i32 208eaa3783bSRichard Henderson #define tcg_gen_extu_i32_reg tcg_gen_mov_i32 209eaa3783bSRichard Henderson #define tcg_gen_ext_i32_reg tcg_gen_mov_i32 210eaa3783bSRichard Henderson #define tcg_gen_extu_reg_i64 tcg_gen_extu_i32_i64 211eaa3783bSRichard Henderson #define tcg_gen_ext_reg_i64 tcg_gen_ext_i32_i64 212eaa3783bSRichard Henderson #define tcg_gen_ext8u_reg tcg_gen_ext8u_i32 213eaa3783bSRichard Henderson #define tcg_gen_ext8s_reg tcg_gen_ext8s_i32 214eaa3783bSRichard Henderson #define tcg_gen_ext16u_reg tcg_gen_ext16u_i32 215eaa3783bSRichard Henderson #define tcg_gen_ext16s_reg tcg_gen_ext16s_i32 216eaa3783bSRichard Henderson #define tcg_gen_ext32u_reg tcg_gen_mov_i32 217eaa3783bSRichard Henderson #define tcg_gen_ext32s_reg tcg_gen_mov_i32 218eaa3783bSRichard Henderson #define tcg_gen_bswap16_reg tcg_gen_bswap16_i32 219eaa3783bSRichard Henderson #define tcg_gen_bswap32_reg tcg_gen_bswap32_i32 220eaa3783bSRichard Henderson #define tcg_gen_concat_reg_i64 tcg_gen_concat_i32_i64 221eaa3783bSRichard Henderson #define tcg_gen_andc_reg tcg_gen_andc_i32 222eaa3783bSRichard Henderson #define tcg_gen_eqv_reg tcg_gen_eqv_i32 223eaa3783bSRichard Henderson #define tcg_gen_nand_reg tcg_gen_nand_i32 224eaa3783bSRichard Henderson #define tcg_gen_nor_reg tcg_gen_nor_i32 225eaa3783bSRichard Henderson #define tcg_gen_orc_reg tcg_gen_orc_i32 226eaa3783bSRichard Henderson #define tcg_gen_clz_reg tcg_gen_clz_i32 227eaa3783bSRichard Henderson #define tcg_gen_ctz_reg tcg_gen_ctz_i32 228eaa3783bSRichard Henderson #define tcg_gen_clzi_reg tcg_gen_clzi_i32 229eaa3783bSRichard Henderson #define tcg_gen_ctzi_reg tcg_gen_ctzi_i32 230eaa3783bSRichard Henderson #define tcg_gen_clrsb_reg tcg_gen_clrsb_i32 231eaa3783bSRichard Henderson #define tcg_gen_ctpop_reg tcg_gen_ctpop_i32 232eaa3783bSRichard Henderson #define tcg_gen_rotl_reg tcg_gen_rotl_i32 233eaa3783bSRichard Henderson #define tcg_gen_rotli_reg tcg_gen_rotli_i32 234eaa3783bSRichard Henderson #define tcg_gen_rotr_reg tcg_gen_rotr_i32 235eaa3783bSRichard Henderson #define tcg_gen_rotri_reg tcg_gen_rotri_i32 236eaa3783bSRichard Henderson #define tcg_gen_deposit_reg tcg_gen_deposit_i32 237eaa3783bSRichard Henderson #define tcg_gen_deposit_z_reg tcg_gen_deposit_z_i32 238eaa3783bSRichard Henderson #define tcg_gen_extract_reg tcg_gen_extract_i32 239eaa3783bSRichard Henderson #define tcg_gen_sextract_reg tcg_gen_sextract_i32 240eaa3783bSRichard Henderson #define tcg_const_reg tcg_const_i32 241eaa3783bSRichard Henderson #define tcg_const_local_reg tcg_const_local_i32 242eaa3783bSRichard Henderson #define tcg_gen_movcond_reg tcg_gen_movcond_i32 243eaa3783bSRichard Henderson #define tcg_gen_add2_reg tcg_gen_add2_i32 244eaa3783bSRichard Henderson #define tcg_gen_sub2_reg tcg_gen_sub2_i32 245eaa3783bSRichard Henderson #define tcg_gen_qemu_ld_reg tcg_gen_qemu_ld_i32 246eaa3783bSRichard Henderson #define tcg_gen_qemu_st_reg tcg_gen_qemu_st_i32 247eaa3783bSRichard Henderson #define tcg_gen_atomic_xchg_reg tcg_gen_atomic_xchg_i32 2485bfa8034SRichard Henderson #define tcg_gen_trunc_reg_ptr tcg_gen_ext_i32_ptr 249eaa3783bSRichard Henderson #endif /* TARGET_REGISTER_BITS */ 250eaa3783bSRichard Henderson 25161766fe9SRichard Henderson typedef struct DisasCond { 25261766fe9SRichard Henderson TCGCond c; 253eaa3783bSRichard Henderson TCGv_reg a0, a1; 25461766fe9SRichard Henderson bool a0_is_n; 25561766fe9SRichard Henderson bool a1_is_0; 25661766fe9SRichard Henderson } DisasCond; 25761766fe9SRichard Henderson 25861766fe9SRichard Henderson typedef struct DisasContext { 259d01a3625SRichard Henderson DisasContextBase base; 26061766fe9SRichard Henderson CPUState *cs; 26161766fe9SRichard Henderson 262eaa3783bSRichard Henderson target_ureg iaoq_f; 263eaa3783bSRichard Henderson target_ureg iaoq_b; 264eaa3783bSRichard Henderson target_ureg iaoq_n; 265eaa3783bSRichard Henderson TCGv_reg iaoq_n_var; 26661766fe9SRichard Henderson 26786f8d05fSRichard Henderson int ntempr, ntempl; 2685eecd37aSRichard Henderson TCGv_reg tempr[8]; 26986f8d05fSRichard Henderson TCGv_tl templ[4]; 27061766fe9SRichard Henderson 27161766fe9SRichard Henderson DisasCond null_cond; 27261766fe9SRichard Henderson TCGLabel *null_lab; 27361766fe9SRichard Henderson 2741a19da0dSRichard Henderson uint32_t insn; 275494737b7SRichard Henderson uint32_t tb_flags; 2763d68ee7bSRichard Henderson int mmu_idx; 2773d68ee7bSRichard Henderson int privilege; 27861766fe9SRichard Henderson bool psw_n_nonzero; 27961766fe9SRichard Henderson } DisasContext; 28061766fe9SRichard Henderson 281e36f27efSRichard Henderson /* Note that ssm/rsm instructions number PSW_W and PSW_E differently. */ 282451e4ffdSRichard Henderson static int expand_sm_imm(DisasContext *ctx, int val) 283e36f27efSRichard Henderson { 284e36f27efSRichard Henderson if (val & PSW_SM_E) { 285e36f27efSRichard Henderson val = (val & ~PSW_SM_E) | PSW_E; 286e36f27efSRichard Henderson } 287e36f27efSRichard Henderson if (val & PSW_SM_W) { 288e36f27efSRichard Henderson val = (val & ~PSW_SM_W) | PSW_W; 289e36f27efSRichard Henderson } 290e36f27efSRichard Henderson return val; 291e36f27efSRichard Henderson } 292e36f27efSRichard Henderson 293deee69a1SRichard Henderson /* Inverted space register indicates 0 means sr0 not inferred from base. */ 294451e4ffdSRichard Henderson static int expand_sr3x(DisasContext *ctx, int val) 295deee69a1SRichard Henderson { 296deee69a1SRichard Henderson return ~val; 297deee69a1SRichard Henderson } 298deee69a1SRichard Henderson 2991cd012a5SRichard Henderson /* Convert the M:A bits within a memory insn to the tri-state value 3001cd012a5SRichard Henderson we use for the final M. */ 301451e4ffdSRichard Henderson static int ma_to_m(DisasContext *ctx, int val) 3021cd012a5SRichard Henderson { 3031cd012a5SRichard Henderson return val & 2 ? (val & 1 ? -1 : 1) : 0; 3041cd012a5SRichard Henderson } 3051cd012a5SRichard Henderson 306740038d7SRichard Henderson /* Convert the sign of the displacement to a pre or post-modify. */ 307451e4ffdSRichard Henderson static int pos_to_m(DisasContext *ctx, int val) 308740038d7SRichard Henderson { 309740038d7SRichard Henderson return val ? 1 : -1; 310740038d7SRichard Henderson } 311740038d7SRichard Henderson 312451e4ffdSRichard Henderson static int neg_to_m(DisasContext *ctx, int val) 313740038d7SRichard Henderson { 314740038d7SRichard Henderson return val ? -1 : 1; 315740038d7SRichard Henderson } 316740038d7SRichard Henderson 317740038d7SRichard Henderson /* Used for branch targets and fp memory ops. */ 318451e4ffdSRichard Henderson static int expand_shl2(DisasContext *ctx, int val) 31901afb7beSRichard Henderson { 32001afb7beSRichard Henderson return val << 2; 32101afb7beSRichard Henderson } 32201afb7beSRichard Henderson 323740038d7SRichard Henderson /* Used for fp memory ops. */ 324451e4ffdSRichard Henderson static int expand_shl3(DisasContext *ctx, int val) 325740038d7SRichard Henderson { 326740038d7SRichard Henderson return val << 3; 327740038d7SRichard Henderson } 328740038d7SRichard Henderson 3290588e061SRichard Henderson /* Used for assemble_21. */ 330451e4ffdSRichard Henderson static int expand_shl11(DisasContext *ctx, int val) 3310588e061SRichard Henderson { 3320588e061SRichard Henderson return val << 11; 3330588e061SRichard Henderson } 3340588e061SRichard Henderson 33501afb7beSRichard Henderson 33640f9f908SRichard Henderson /* Include the auto-generated decoder. */ 33740f9f908SRichard Henderson #include "decode.inc.c" 33840f9f908SRichard Henderson 33961766fe9SRichard Henderson /* We are not using a goto_tb (for whatever reason), but have updated 34061766fe9SRichard Henderson the iaq (for whatever reason), so don't do it again on exit. */ 341869051eaSRichard Henderson #define DISAS_IAQ_N_UPDATED DISAS_TARGET_0 34261766fe9SRichard Henderson 34361766fe9SRichard Henderson /* We are exiting the TB, but have neither emitted a goto_tb, nor 34461766fe9SRichard Henderson updated the iaq for the next instruction to be executed. */ 345869051eaSRichard Henderson #define DISAS_IAQ_N_STALE DISAS_TARGET_1 34661766fe9SRichard Henderson 347e1b5a5edSRichard Henderson /* Similarly, but we want to return to the main loop immediately 348e1b5a5edSRichard Henderson to recognize unmasked interrupts. */ 349e1b5a5edSRichard Henderson #define DISAS_IAQ_N_STALE_EXIT DISAS_TARGET_2 350c5d0aec2SRichard Henderson #define DISAS_EXIT DISAS_TARGET_3 351e1b5a5edSRichard Henderson 35261766fe9SRichard Henderson /* global register indexes */ 353eaa3783bSRichard Henderson static TCGv_reg cpu_gr[32]; 35433423472SRichard Henderson static TCGv_i64 cpu_sr[4]; 355494737b7SRichard Henderson static TCGv_i64 cpu_srH; 356eaa3783bSRichard Henderson static TCGv_reg cpu_iaoq_f; 357eaa3783bSRichard Henderson static TCGv_reg cpu_iaoq_b; 358c301f34eSRichard Henderson static TCGv_i64 cpu_iasq_f; 359c301f34eSRichard Henderson static TCGv_i64 cpu_iasq_b; 360eaa3783bSRichard Henderson static TCGv_reg cpu_sar; 361eaa3783bSRichard Henderson static TCGv_reg cpu_psw_n; 362eaa3783bSRichard Henderson static TCGv_reg cpu_psw_v; 363eaa3783bSRichard Henderson static TCGv_reg cpu_psw_cb; 364eaa3783bSRichard Henderson static TCGv_reg cpu_psw_cb_msb; 36561766fe9SRichard Henderson 36661766fe9SRichard Henderson #include "exec/gen-icount.h" 36761766fe9SRichard Henderson 36861766fe9SRichard Henderson void hppa_translate_init(void) 36961766fe9SRichard Henderson { 37061766fe9SRichard Henderson #define DEF_VAR(V) { &cpu_##V, #V, offsetof(CPUHPPAState, V) } 37161766fe9SRichard Henderson 372eaa3783bSRichard Henderson typedef struct { TCGv_reg *var; const char *name; int ofs; } GlobalVar; 37361766fe9SRichard Henderson static const GlobalVar vars[] = { 37435136a77SRichard Henderson { &cpu_sar, "sar", offsetof(CPUHPPAState, cr[CR_SAR]) }, 37561766fe9SRichard Henderson DEF_VAR(psw_n), 37661766fe9SRichard Henderson DEF_VAR(psw_v), 37761766fe9SRichard Henderson DEF_VAR(psw_cb), 37861766fe9SRichard Henderson DEF_VAR(psw_cb_msb), 37961766fe9SRichard Henderson DEF_VAR(iaoq_f), 38061766fe9SRichard Henderson DEF_VAR(iaoq_b), 38161766fe9SRichard Henderson }; 38261766fe9SRichard Henderson 38361766fe9SRichard Henderson #undef DEF_VAR 38461766fe9SRichard Henderson 38561766fe9SRichard Henderson /* Use the symbolic register names that match the disassembler. */ 38661766fe9SRichard Henderson static const char gr_names[32][4] = { 38761766fe9SRichard Henderson "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", 38861766fe9SRichard Henderson "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", 38961766fe9SRichard Henderson "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", 39061766fe9SRichard Henderson "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31" 39161766fe9SRichard Henderson }; 39233423472SRichard Henderson /* SR[4-7] are not global registers so that we can index them. */ 393494737b7SRichard Henderson static const char sr_names[5][4] = { 394494737b7SRichard Henderson "sr0", "sr1", "sr2", "sr3", "srH" 39533423472SRichard Henderson }; 39661766fe9SRichard Henderson 39761766fe9SRichard Henderson int i; 39861766fe9SRichard Henderson 399f764718dSRichard Henderson cpu_gr[0] = NULL; 40061766fe9SRichard Henderson for (i = 1; i < 32; i++) { 40161766fe9SRichard Henderson cpu_gr[i] = tcg_global_mem_new(cpu_env, 40261766fe9SRichard Henderson offsetof(CPUHPPAState, gr[i]), 40361766fe9SRichard Henderson gr_names[i]); 40461766fe9SRichard Henderson } 40533423472SRichard Henderson for (i = 0; i < 4; i++) { 40633423472SRichard Henderson cpu_sr[i] = tcg_global_mem_new_i64(cpu_env, 40733423472SRichard Henderson offsetof(CPUHPPAState, sr[i]), 40833423472SRichard Henderson sr_names[i]); 40933423472SRichard Henderson } 410494737b7SRichard Henderson cpu_srH = tcg_global_mem_new_i64(cpu_env, 411494737b7SRichard Henderson offsetof(CPUHPPAState, sr[4]), 412494737b7SRichard Henderson sr_names[4]); 41361766fe9SRichard Henderson 41461766fe9SRichard Henderson for (i = 0; i < ARRAY_SIZE(vars); ++i) { 41561766fe9SRichard Henderson const GlobalVar *v = &vars[i]; 41661766fe9SRichard Henderson *v->var = tcg_global_mem_new(cpu_env, v->ofs, v->name); 41761766fe9SRichard Henderson } 418c301f34eSRichard Henderson 419c301f34eSRichard Henderson cpu_iasq_f = tcg_global_mem_new_i64(cpu_env, 420c301f34eSRichard Henderson offsetof(CPUHPPAState, iasq_f), 421c301f34eSRichard Henderson "iasq_f"); 422c301f34eSRichard Henderson cpu_iasq_b = tcg_global_mem_new_i64(cpu_env, 423c301f34eSRichard Henderson offsetof(CPUHPPAState, iasq_b), 424c301f34eSRichard Henderson "iasq_b"); 42561766fe9SRichard Henderson } 42661766fe9SRichard Henderson 427129e9cc3SRichard Henderson static DisasCond cond_make_f(void) 428129e9cc3SRichard Henderson { 429f764718dSRichard Henderson return (DisasCond){ 430f764718dSRichard Henderson .c = TCG_COND_NEVER, 431f764718dSRichard Henderson .a0 = NULL, 432f764718dSRichard Henderson .a1 = NULL, 433f764718dSRichard Henderson }; 434129e9cc3SRichard Henderson } 435129e9cc3SRichard Henderson 436df0232feSRichard Henderson static DisasCond cond_make_t(void) 437df0232feSRichard Henderson { 438df0232feSRichard Henderson return (DisasCond){ 439df0232feSRichard Henderson .c = TCG_COND_ALWAYS, 440df0232feSRichard Henderson .a0 = NULL, 441df0232feSRichard Henderson .a1 = NULL, 442df0232feSRichard Henderson }; 443df0232feSRichard Henderson } 444df0232feSRichard Henderson 445129e9cc3SRichard Henderson static DisasCond cond_make_n(void) 446129e9cc3SRichard Henderson { 447f764718dSRichard Henderson return (DisasCond){ 448f764718dSRichard Henderson .c = TCG_COND_NE, 449f764718dSRichard Henderson .a0 = cpu_psw_n, 450f764718dSRichard Henderson .a0_is_n = true, 451f764718dSRichard Henderson .a1 = NULL, 452f764718dSRichard Henderson .a1_is_0 = true 453f764718dSRichard Henderson }; 454129e9cc3SRichard Henderson } 455129e9cc3SRichard Henderson 456b47a4a02SSven Schnelle static DisasCond cond_make_0_tmp(TCGCond c, TCGv_reg a0) 457b47a4a02SSven Schnelle { 458b47a4a02SSven Schnelle assert (c != TCG_COND_NEVER && c != TCG_COND_ALWAYS); 459b47a4a02SSven Schnelle return (DisasCond){ 460b47a4a02SSven Schnelle .c = c, .a0 = a0, .a1_is_0 = true 461b47a4a02SSven Schnelle }; 462b47a4a02SSven Schnelle } 463b47a4a02SSven Schnelle 464eaa3783bSRichard Henderson static DisasCond cond_make_0(TCGCond c, TCGv_reg a0) 465129e9cc3SRichard Henderson { 466b47a4a02SSven Schnelle TCGv_reg tmp = tcg_temp_new(); 467b47a4a02SSven Schnelle tcg_gen_mov_reg(tmp, a0); 468b47a4a02SSven Schnelle return cond_make_0_tmp(c, tmp); 469129e9cc3SRichard Henderson } 470129e9cc3SRichard Henderson 471eaa3783bSRichard Henderson static DisasCond cond_make(TCGCond c, TCGv_reg a0, TCGv_reg a1) 472129e9cc3SRichard Henderson { 473129e9cc3SRichard Henderson DisasCond r = { .c = c }; 474129e9cc3SRichard Henderson 475129e9cc3SRichard Henderson assert (c != TCG_COND_NEVER && c != TCG_COND_ALWAYS); 476129e9cc3SRichard Henderson r.a0 = tcg_temp_new(); 477eaa3783bSRichard Henderson tcg_gen_mov_reg(r.a0, a0); 478129e9cc3SRichard Henderson r.a1 = tcg_temp_new(); 479eaa3783bSRichard Henderson tcg_gen_mov_reg(r.a1, a1); 480129e9cc3SRichard Henderson 481129e9cc3SRichard Henderson return r; 482129e9cc3SRichard Henderson } 483129e9cc3SRichard Henderson 484129e9cc3SRichard Henderson static void cond_prep(DisasCond *cond) 485129e9cc3SRichard Henderson { 486129e9cc3SRichard Henderson if (cond->a1_is_0) { 487129e9cc3SRichard Henderson cond->a1_is_0 = false; 488eaa3783bSRichard Henderson cond->a1 = tcg_const_reg(0); 489129e9cc3SRichard Henderson } 490129e9cc3SRichard Henderson } 491129e9cc3SRichard Henderson 492129e9cc3SRichard Henderson static void cond_free(DisasCond *cond) 493129e9cc3SRichard Henderson { 494129e9cc3SRichard Henderson switch (cond->c) { 495129e9cc3SRichard Henderson default: 496129e9cc3SRichard Henderson if (!cond->a0_is_n) { 497129e9cc3SRichard Henderson tcg_temp_free(cond->a0); 498129e9cc3SRichard Henderson } 499129e9cc3SRichard Henderson if (!cond->a1_is_0) { 500129e9cc3SRichard Henderson tcg_temp_free(cond->a1); 501129e9cc3SRichard Henderson } 502129e9cc3SRichard Henderson cond->a0_is_n = false; 503129e9cc3SRichard Henderson cond->a1_is_0 = false; 504f764718dSRichard Henderson cond->a0 = NULL; 505f764718dSRichard Henderson cond->a1 = NULL; 506129e9cc3SRichard Henderson /* fallthru */ 507129e9cc3SRichard Henderson case TCG_COND_ALWAYS: 508129e9cc3SRichard Henderson cond->c = TCG_COND_NEVER; 509129e9cc3SRichard Henderson break; 510129e9cc3SRichard Henderson case TCG_COND_NEVER: 511129e9cc3SRichard Henderson break; 512129e9cc3SRichard Henderson } 513129e9cc3SRichard Henderson } 514129e9cc3SRichard Henderson 515eaa3783bSRichard Henderson static TCGv_reg get_temp(DisasContext *ctx) 51661766fe9SRichard Henderson { 51786f8d05fSRichard Henderson unsigned i = ctx->ntempr++; 51886f8d05fSRichard Henderson g_assert(i < ARRAY_SIZE(ctx->tempr)); 51986f8d05fSRichard Henderson return ctx->tempr[i] = tcg_temp_new(); 52061766fe9SRichard Henderson } 52161766fe9SRichard Henderson 52286f8d05fSRichard Henderson #ifndef CONFIG_USER_ONLY 52386f8d05fSRichard Henderson static TCGv_tl get_temp_tl(DisasContext *ctx) 52486f8d05fSRichard Henderson { 52586f8d05fSRichard Henderson unsigned i = ctx->ntempl++; 52686f8d05fSRichard Henderson g_assert(i < ARRAY_SIZE(ctx->templ)); 52786f8d05fSRichard Henderson return ctx->templ[i] = tcg_temp_new_tl(); 52886f8d05fSRichard Henderson } 52986f8d05fSRichard Henderson #endif 53086f8d05fSRichard Henderson 531eaa3783bSRichard Henderson static TCGv_reg load_const(DisasContext *ctx, target_sreg v) 53261766fe9SRichard Henderson { 533eaa3783bSRichard Henderson TCGv_reg t = get_temp(ctx); 534eaa3783bSRichard Henderson tcg_gen_movi_reg(t, v); 53561766fe9SRichard Henderson return t; 53661766fe9SRichard Henderson } 53761766fe9SRichard Henderson 538eaa3783bSRichard Henderson static TCGv_reg load_gpr(DisasContext *ctx, unsigned reg) 53961766fe9SRichard Henderson { 54061766fe9SRichard Henderson if (reg == 0) { 541eaa3783bSRichard Henderson TCGv_reg t = get_temp(ctx); 542eaa3783bSRichard Henderson tcg_gen_movi_reg(t, 0); 54361766fe9SRichard Henderson return t; 54461766fe9SRichard Henderson } else { 54561766fe9SRichard Henderson return cpu_gr[reg]; 54661766fe9SRichard Henderson } 54761766fe9SRichard Henderson } 54861766fe9SRichard Henderson 549eaa3783bSRichard Henderson static TCGv_reg dest_gpr(DisasContext *ctx, unsigned reg) 55061766fe9SRichard Henderson { 551129e9cc3SRichard Henderson if (reg == 0 || ctx->null_cond.c != TCG_COND_NEVER) { 55261766fe9SRichard Henderson return get_temp(ctx); 55361766fe9SRichard Henderson } else { 55461766fe9SRichard Henderson return cpu_gr[reg]; 55561766fe9SRichard Henderson } 55661766fe9SRichard Henderson } 55761766fe9SRichard Henderson 558eaa3783bSRichard Henderson static void save_or_nullify(DisasContext *ctx, TCGv_reg dest, TCGv_reg t) 559129e9cc3SRichard Henderson { 560129e9cc3SRichard Henderson if (ctx->null_cond.c != TCG_COND_NEVER) { 561129e9cc3SRichard Henderson cond_prep(&ctx->null_cond); 562eaa3783bSRichard Henderson tcg_gen_movcond_reg(ctx->null_cond.c, dest, ctx->null_cond.a0, 563129e9cc3SRichard Henderson ctx->null_cond.a1, dest, t); 564129e9cc3SRichard Henderson } else { 565eaa3783bSRichard Henderson tcg_gen_mov_reg(dest, t); 566129e9cc3SRichard Henderson } 567129e9cc3SRichard Henderson } 568129e9cc3SRichard Henderson 569eaa3783bSRichard Henderson static void save_gpr(DisasContext *ctx, unsigned reg, TCGv_reg t) 570129e9cc3SRichard Henderson { 571129e9cc3SRichard Henderson if (reg != 0) { 572129e9cc3SRichard Henderson save_or_nullify(ctx, cpu_gr[reg], t); 573129e9cc3SRichard Henderson } 574129e9cc3SRichard Henderson } 575129e9cc3SRichard Henderson 57696d6407fSRichard Henderson #ifdef HOST_WORDS_BIGENDIAN 57796d6407fSRichard Henderson # define HI_OFS 0 57896d6407fSRichard Henderson # define LO_OFS 4 57996d6407fSRichard Henderson #else 58096d6407fSRichard Henderson # define HI_OFS 4 58196d6407fSRichard Henderson # define LO_OFS 0 58296d6407fSRichard Henderson #endif 58396d6407fSRichard Henderson 58496d6407fSRichard Henderson static TCGv_i32 load_frw_i32(unsigned rt) 58596d6407fSRichard Henderson { 58696d6407fSRichard Henderson TCGv_i32 ret = tcg_temp_new_i32(); 58796d6407fSRichard Henderson tcg_gen_ld_i32(ret, cpu_env, 58896d6407fSRichard Henderson offsetof(CPUHPPAState, fr[rt & 31]) 58996d6407fSRichard Henderson + (rt & 32 ? LO_OFS : HI_OFS)); 59096d6407fSRichard Henderson return ret; 59196d6407fSRichard Henderson } 59296d6407fSRichard Henderson 593ebe9383cSRichard Henderson static TCGv_i32 load_frw0_i32(unsigned rt) 594ebe9383cSRichard Henderson { 595ebe9383cSRichard Henderson if (rt == 0) { 596ebe9383cSRichard Henderson return tcg_const_i32(0); 597ebe9383cSRichard Henderson } else { 598ebe9383cSRichard Henderson return load_frw_i32(rt); 599ebe9383cSRichard Henderson } 600ebe9383cSRichard Henderson } 601ebe9383cSRichard Henderson 602ebe9383cSRichard Henderson static TCGv_i64 load_frw0_i64(unsigned rt) 603ebe9383cSRichard Henderson { 604ebe9383cSRichard Henderson if (rt == 0) { 605ebe9383cSRichard Henderson return tcg_const_i64(0); 606ebe9383cSRichard Henderson } else { 607ebe9383cSRichard Henderson TCGv_i64 ret = tcg_temp_new_i64(); 608ebe9383cSRichard Henderson tcg_gen_ld32u_i64(ret, cpu_env, 609ebe9383cSRichard Henderson offsetof(CPUHPPAState, fr[rt & 31]) 610ebe9383cSRichard Henderson + (rt & 32 ? LO_OFS : HI_OFS)); 611ebe9383cSRichard Henderson return ret; 612ebe9383cSRichard Henderson } 613ebe9383cSRichard Henderson } 614ebe9383cSRichard Henderson 61596d6407fSRichard Henderson static void save_frw_i32(unsigned rt, TCGv_i32 val) 61696d6407fSRichard Henderson { 61796d6407fSRichard Henderson tcg_gen_st_i32(val, cpu_env, 61896d6407fSRichard Henderson offsetof(CPUHPPAState, fr[rt & 31]) 61996d6407fSRichard Henderson + (rt & 32 ? LO_OFS : HI_OFS)); 62096d6407fSRichard Henderson } 62196d6407fSRichard Henderson 62296d6407fSRichard Henderson #undef HI_OFS 62396d6407fSRichard Henderson #undef LO_OFS 62496d6407fSRichard Henderson 62596d6407fSRichard Henderson static TCGv_i64 load_frd(unsigned rt) 62696d6407fSRichard Henderson { 62796d6407fSRichard Henderson TCGv_i64 ret = tcg_temp_new_i64(); 62896d6407fSRichard Henderson tcg_gen_ld_i64(ret, cpu_env, offsetof(CPUHPPAState, fr[rt])); 62996d6407fSRichard Henderson return ret; 63096d6407fSRichard Henderson } 63196d6407fSRichard Henderson 632ebe9383cSRichard Henderson static TCGv_i64 load_frd0(unsigned rt) 633ebe9383cSRichard Henderson { 634ebe9383cSRichard Henderson if (rt == 0) { 635ebe9383cSRichard Henderson return tcg_const_i64(0); 636ebe9383cSRichard Henderson } else { 637ebe9383cSRichard Henderson return load_frd(rt); 638ebe9383cSRichard Henderson } 639ebe9383cSRichard Henderson } 640ebe9383cSRichard Henderson 64196d6407fSRichard Henderson static void save_frd(unsigned rt, TCGv_i64 val) 64296d6407fSRichard Henderson { 64396d6407fSRichard Henderson tcg_gen_st_i64(val, cpu_env, offsetof(CPUHPPAState, fr[rt])); 64496d6407fSRichard Henderson } 64596d6407fSRichard Henderson 64633423472SRichard Henderson static void load_spr(DisasContext *ctx, TCGv_i64 dest, unsigned reg) 64733423472SRichard Henderson { 64833423472SRichard Henderson #ifdef CONFIG_USER_ONLY 64933423472SRichard Henderson tcg_gen_movi_i64(dest, 0); 65033423472SRichard Henderson #else 65133423472SRichard Henderson if (reg < 4) { 65233423472SRichard Henderson tcg_gen_mov_i64(dest, cpu_sr[reg]); 653494737b7SRichard Henderson } else if (ctx->tb_flags & TB_FLAG_SR_SAME) { 654494737b7SRichard Henderson tcg_gen_mov_i64(dest, cpu_srH); 65533423472SRichard Henderson } else { 65633423472SRichard Henderson tcg_gen_ld_i64(dest, cpu_env, offsetof(CPUHPPAState, sr[reg])); 65733423472SRichard Henderson } 65833423472SRichard Henderson #endif 65933423472SRichard Henderson } 66033423472SRichard Henderson 661129e9cc3SRichard Henderson /* Skip over the implementation of an insn that has been nullified. 662129e9cc3SRichard Henderson Use this when the insn is too complex for a conditional move. */ 663129e9cc3SRichard Henderson static void nullify_over(DisasContext *ctx) 664129e9cc3SRichard Henderson { 665129e9cc3SRichard Henderson if (ctx->null_cond.c != TCG_COND_NEVER) { 666129e9cc3SRichard Henderson /* The always condition should have been handled in the main loop. */ 667129e9cc3SRichard Henderson assert(ctx->null_cond.c != TCG_COND_ALWAYS); 668129e9cc3SRichard Henderson 669129e9cc3SRichard Henderson ctx->null_lab = gen_new_label(); 670129e9cc3SRichard Henderson cond_prep(&ctx->null_cond); 671129e9cc3SRichard Henderson 672129e9cc3SRichard Henderson /* If we're using PSW[N], copy it to a temp because... */ 673129e9cc3SRichard Henderson if (ctx->null_cond.a0_is_n) { 674129e9cc3SRichard Henderson ctx->null_cond.a0_is_n = false; 675129e9cc3SRichard Henderson ctx->null_cond.a0 = tcg_temp_new(); 676eaa3783bSRichard Henderson tcg_gen_mov_reg(ctx->null_cond.a0, cpu_psw_n); 677129e9cc3SRichard Henderson } 678129e9cc3SRichard Henderson /* ... we clear it before branching over the implementation, 679129e9cc3SRichard Henderson so that (1) it's clear after nullifying this insn and 680129e9cc3SRichard Henderson (2) if this insn nullifies the next, PSW[N] is valid. */ 681129e9cc3SRichard Henderson if (ctx->psw_n_nonzero) { 682129e9cc3SRichard Henderson ctx->psw_n_nonzero = false; 683eaa3783bSRichard Henderson tcg_gen_movi_reg(cpu_psw_n, 0); 684129e9cc3SRichard Henderson } 685129e9cc3SRichard Henderson 686eaa3783bSRichard Henderson tcg_gen_brcond_reg(ctx->null_cond.c, ctx->null_cond.a0, 687129e9cc3SRichard Henderson ctx->null_cond.a1, ctx->null_lab); 688129e9cc3SRichard Henderson cond_free(&ctx->null_cond); 689129e9cc3SRichard Henderson } 690129e9cc3SRichard Henderson } 691129e9cc3SRichard Henderson 692129e9cc3SRichard Henderson /* Save the current nullification state to PSW[N]. */ 693129e9cc3SRichard Henderson static void nullify_save(DisasContext *ctx) 694129e9cc3SRichard Henderson { 695129e9cc3SRichard Henderson if (ctx->null_cond.c == TCG_COND_NEVER) { 696129e9cc3SRichard Henderson if (ctx->psw_n_nonzero) { 697eaa3783bSRichard Henderson tcg_gen_movi_reg(cpu_psw_n, 0); 698129e9cc3SRichard Henderson } 699129e9cc3SRichard Henderson return; 700129e9cc3SRichard Henderson } 701129e9cc3SRichard Henderson if (!ctx->null_cond.a0_is_n) { 702129e9cc3SRichard Henderson cond_prep(&ctx->null_cond); 703eaa3783bSRichard Henderson tcg_gen_setcond_reg(ctx->null_cond.c, cpu_psw_n, 704129e9cc3SRichard Henderson ctx->null_cond.a0, ctx->null_cond.a1); 705129e9cc3SRichard Henderson ctx->psw_n_nonzero = true; 706129e9cc3SRichard Henderson } 707129e9cc3SRichard Henderson cond_free(&ctx->null_cond); 708129e9cc3SRichard Henderson } 709129e9cc3SRichard Henderson 710129e9cc3SRichard Henderson /* Set a PSW[N] to X. The intention is that this is used immediately 711129e9cc3SRichard Henderson before a goto_tb/exit_tb, so that there is no fallthru path to other 712129e9cc3SRichard Henderson code within the TB. Therefore we do not update psw_n_nonzero. */ 713129e9cc3SRichard Henderson static void nullify_set(DisasContext *ctx, bool x) 714129e9cc3SRichard Henderson { 715129e9cc3SRichard Henderson if (ctx->psw_n_nonzero || x) { 716eaa3783bSRichard Henderson tcg_gen_movi_reg(cpu_psw_n, x); 717129e9cc3SRichard Henderson } 718129e9cc3SRichard Henderson } 719129e9cc3SRichard Henderson 720129e9cc3SRichard Henderson /* Mark the end of an instruction that may have been nullified. 72140f9f908SRichard Henderson This is the pair to nullify_over. Always returns true so that 72240f9f908SRichard Henderson it may be tail-called from a translate function. */ 72331234768SRichard Henderson static bool nullify_end(DisasContext *ctx) 724129e9cc3SRichard Henderson { 725129e9cc3SRichard Henderson TCGLabel *null_lab = ctx->null_lab; 72631234768SRichard Henderson DisasJumpType status = ctx->base.is_jmp; 727129e9cc3SRichard Henderson 728f49b3537SRichard Henderson /* For NEXT, NORETURN, STALE, we can easily continue (or exit). 729f49b3537SRichard Henderson For UPDATED, we cannot update on the nullified path. */ 730f49b3537SRichard Henderson assert(status != DISAS_IAQ_N_UPDATED); 731f49b3537SRichard Henderson 732129e9cc3SRichard Henderson if (likely(null_lab == NULL)) { 733129e9cc3SRichard Henderson /* The current insn wasn't conditional or handled the condition 734129e9cc3SRichard Henderson applied to it without a branch, so the (new) setting of 735129e9cc3SRichard Henderson NULL_COND can be applied directly to the next insn. */ 73631234768SRichard Henderson return true; 737129e9cc3SRichard Henderson } 738129e9cc3SRichard Henderson ctx->null_lab = NULL; 739129e9cc3SRichard Henderson 740129e9cc3SRichard Henderson if (likely(ctx->null_cond.c == TCG_COND_NEVER)) { 741129e9cc3SRichard Henderson /* The next instruction will be unconditional, 742129e9cc3SRichard Henderson and NULL_COND already reflects that. */ 743129e9cc3SRichard Henderson gen_set_label(null_lab); 744129e9cc3SRichard Henderson } else { 745129e9cc3SRichard Henderson /* The insn that we just executed is itself nullifying the next 746129e9cc3SRichard Henderson instruction. Store the condition in the PSW[N] global. 747129e9cc3SRichard Henderson We asserted PSW[N] = 0 in nullify_over, so that after the 748129e9cc3SRichard Henderson label we have the proper value in place. */ 749129e9cc3SRichard Henderson nullify_save(ctx); 750129e9cc3SRichard Henderson gen_set_label(null_lab); 751129e9cc3SRichard Henderson ctx->null_cond = cond_make_n(); 752129e9cc3SRichard Henderson } 753869051eaSRichard Henderson if (status == DISAS_NORETURN) { 75431234768SRichard Henderson ctx->base.is_jmp = DISAS_NEXT; 755129e9cc3SRichard Henderson } 75631234768SRichard Henderson return true; 757129e9cc3SRichard Henderson } 758129e9cc3SRichard Henderson 759eaa3783bSRichard Henderson static void copy_iaoq_entry(TCGv_reg dest, target_ureg ival, TCGv_reg vval) 76061766fe9SRichard Henderson { 76161766fe9SRichard Henderson if (unlikely(ival == -1)) { 762eaa3783bSRichard Henderson tcg_gen_mov_reg(dest, vval); 76361766fe9SRichard Henderson } else { 764eaa3783bSRichard Henderson tcg_gen_movi_reg(dest, ival); 76561766fe9SRichard Henderson } 76661766fe9SRichard Henderson } 76761766fe9SRichard Henderson 768eaa3783bSRichard Henderson static inline target_ureg iaoq_dest(DisasContext *ctx, target_sreg disp) 76961766fe9SRichard Henderson { 77061766fe9SRichard Henderson return ctx->iaoq_f + disp + 8; 77161766fe9SRichard Henderson } 77261766fe9SRichard Henderson 77361766fe9SRichard Henderson static void gen_excp_1(int exception) 77461766fe9SRichard Henderson { 77561766fe9SRichard Henderson TCGv_i32 t = tcg_const_i32(exception); 77661766fe9SRichard Henderson gen_helper_excp(cpu_env, t); 77761766fe9SRichard Henderson tcg_temp_free_i32(t); 77861766fe9SRichard Henderson } 77961766fe9SRichard Henderson 78031234768SRichard Henderson static void gen_excp(DisasContext *ctx, int exception) 78161766fe9SRichard Henderson { 78261766fe9SRichard Henderson copy_iaoq_entry(cpu_iaoq_f, ctx->iaoq_f, cpu_iaoq_f); 78361766fe9SRichard Henderson copy_iaoq_entry(cpu_iaoq_b, ctx->iaoq_b, cpu_iaoq_b); 784129e9cc3SRichard Henderson nullify_save(ctx); 78561766fe9SRichard Henderson gen_excp_1(exception); 78631234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 78761766fe9SRichard Henderson } 78861766fe9SRichard Henderson 78931234768SRichard Henderson static bool gen_excp_iir(DisasContext *ctx, int exc) 7901a19da0dSRichard Henderson { 79131234768SRichard Henderson TCGv_reg tmp; 79231234768SRichard Henderson 79331234768SRichard Henderson nullify_over(ctx); 79431234768SRichard Henderson tmp = tcg_const_reg(ctx->insn); 7951a19da0dSRichard Henderson tcg_gen_st_reg(tmp, cpu_env, offsetof(CPUHPPAState, cr[CR_IIR])); 7961a19da0dSRichard Henderson tcg_temp_free(tmp); 79731234768SRichard Henderson gen_excp(ctx, exc); 79831234768SRichard Henderson return nullify_end(ctx); 7991a19da0dSRichard Henderson } 8001a19da0dSRichard Henderson 80131234768SRichard Henderson static bool gen_illegal(DisasContext *ctx) 80261766fe9SRichard Henderson { 80331234768SRichard Henderson return gen_excp_iir(ctx, EXCP_ILL); 80461766fe9SRichard Henderson } 80561766fe9SRichard Henderson 80640f9f908SRichard Henderson #ifdef CONFIG_USER_ONLY 80740f9f908SRichard Henderson #define CHECK_MOST_PRIVILEGED(EXCP) \ 80840f9f908SRichard Henderson return gen_excp_iir(ctx, EXCP) 80940f9f908SRichard Henderson #else 810e1b5a5edSRichard Henderson #define CHECK_MOST_PRIVILEGED(EXCP) \ 811e1b5a5edSRichard Henderson do { \ 812e1b5a5edSRichard Henderson if (ctx->privilege != 0) { \ 81331234768SRichard Henderson return gen_excp_iir(ctx, EXCP); \ 814e1b5a5edSRichard Henderson } \ 815e1b5a5edSRichard Henderson } while (0) 81640f9f908SRichard Henderson #endif 817e1b5a5edSRichard Henderson 818eaa3783bSRichard Henderson static bool use_goto_tb(DisasContext *ctx, target_ureg dest) 81961766fe9SRichard Henderson { 820f3b423ecSRichard Henderson /* Suppress goto_tb for page crossing, IO, or single-steping. */ 821f3b423ecSRichard Henderson return !(((ctx->base.pc_first ^ dest) & TARGET_PAGE_MASK) 822f3b423ecSRichard Henderson || (tb_cflags(ctx->base.tb) & CF_LAST_IO) 823f3b423ecSRichard Henderson || ctx->base.singlestep_enabled); 82461766fe9SRichard Henderson } 82561766fe9SRichard Henderson 826129e9cc3SRichard Henderson /* If the next insn is to be nullified, and it's on the same page, 827129e9cc3SRichard Henderson and we're not attempting to set a breakpoint on it, then we can 828129e9cc3SRichard Henderson totally skip the nullified insn. This avoids creating and 829129e9cc3SRichard Henderson executing a TB that merely branches to the next TB. */ 830129e9cc3SRichard Henderson static bool use_nullify_skip(DisasContext *ctx) 831129e9cc3SRichard Henderson { 832129e9cc3SRichard Henderson return (((ctx->iaoq_b ^ ctx->iaoq_f) & TARGET_PAGE_MASK) == 0 833129e9cc3SRichard Henderson && !cpu_breakpoint_test(ctx->cs, ctx->iaoq_b, BP_ANY)); 834129e9cc3SRichard Henderson } 835129e9cc3SRichard Henderson 83661766fe9SRichard Henderson static void gen_goto_tb(DisasContext *ctx, int which, 837eaa3783bSRichard Henderson target_ureg f, target_ureg b) 83861766fe9SRichard Henderson { 83961766fe9SRichard Henderson if (f != -1 && b != -1 && use_goto_tb(ctx, f)) { 84061766fe9SRichard Henderson tcg_gen_goto_tb(which); 841eaa3783bSRichard Henderson tcg_gen_movi_reg(cpu_iaoq_f, f); 842eaa3783bSRichard Henderson tcg_gen_movi_reg(cpu_iaoq_b, b); 84307ea28b4SRichard Henderson tcg_gen_exit_tb(ctx->base.tb, which); 84461766fe9SRichard Henderson } else { 84561766fe9SRichard Henderson copy_iaoq_entry(cpu_iaoq_f, f, cpu_iaoq_b); 84661766fe9SRichard Henderson copy_iaoq_entry(cpu_iaoq_b, b, ctx->iaoq_n_var); 847d01a3625SRichard Henderson if (ctx->base.singlestep_enabled) { 84861766fe9SRichard Henderson gen_excp_1(EXCP_DEBUG); 84961766fe9SRichard Henderson } else { 8507f11636dSEmilio G. Cota tcg_gen_lookup_and_goto_ptr(); 85161766fe9SRichard Henderson } 85261766fe9SRichard Henderson } 85361766fe9SRichard Henderson } 85461766fe9SRichard Henderson 855b47a4a02SSven Schnelle static bool cond_need_sv(int c) 856b47a4a02SSven Schnelle { 857b47a4a02SSven Schnelle return c == 2 || c == 3 || c == 6; 858b47a4a02SSven Schnelle } 859b47a4a02SSven Schnelle 860b47a4a02SSven Schnelle static bool cond_need_cb(int c) 861b47a4a02SSven Schnelle { 862b47a4a02SSven Schnelle return c == 4 || c == 5; 863b47a4a02SSven Schnelle } 864b47a4a02SSven Schnelle 865b47a4a02SSven Schnelle /* 866b47a4a02SSven Schnelle * Compute conditional for arithmetic. See Page 5-3, Table 5-1, of 867b47a4a02SSven Schnelle * the Parisc 1.1 Architecture Reference Manual for details. 868b47a4a02SSven Schnelle */ 869b2167459SRichard Henderson 870eaa3783bSRichard Henderson static DisasCond do_cond(unsigned cf, TCGv_reg res, 871eaa3783bSRichard Henderson TCGv_reg cb_msb, TCGv_reg sv) 872b2167459SRichard Henderson { 873b2167459SRichard Henderson DisasCond cond; 874eaa3783bSRichard Henderson TCGv_reg tmp; 875b2167459SRichard Henderson 876b2167459SRichard Henderson switch (cf >> 1) { 877b47a4a02SSven Schnelle case 0: /* Never / TR (0 / 1) */ 878b2167459SRichard Henderson cond = cond_make_f(); 879b2167459SRichard Henderson break; 880b2167459SRichard Henderson case 1: /* = / <> (Z / !Z) */ 881b2167459SRichard Henderson cond = cond_make_0(TCG_COND_EQ, res); 882b2167459SRichard Henderson break; 883b47a4a02SSven Schnelle case 2: /* < / >= (N ^ V / !(N ^ V) */ 884b47a4a02SSven Schnelle tmp = tcg_temp_new(); 885b47a4a02SSven Schnelle tcg_gen_xor_reg(tmp, res, sv); 886b47a4a02SSven Schnelle cond = cond_make_0_tmp(TCG_COND_LT, tmp); 887b2167459SRichard Henderson break; 888b47a4a02SSven Schnelle case 3: /* <= / > (N ^ V) | Z / !((N ^ V) | Z) */ 889b47a4a02SSven Schnelle /* 890b47a4a02SSven Schnelle * Simplify: 891b47a4a02SSven Schnelle * (N ^ V) | Z 892b47a4a02SSven Schnelle * ((res < 0) ^ (sv < 0)) | !res 893b47a4a02SSven Schnelle * ((res ^ sv) < 0) | !res 894b47a4a02SSven Schnelle * (~(res ^ sv) >= 0) | !res 895b47a4a02SSven Schnelle * !(~(res ^ sv) >> 31) | !res 896b47a4a02SSven Schnelle * !(~(res ^ sv) >> 31 & res) 897b47a4a02SSven Schnelle */ 898b47a4a02SSven Schnelle tmp = tcg_temp_new(); 899b47a4a02SSven Schnelle tcg_gen_eqv_reg(tmp, res, sv); 900b47a4a02SSven Schnelle tcg_gen_sari_reg(tmp, tmp, TARGET_REGISTER_BITS - 1); 901b47a4a02SSven Schnelle tcg_gen_and_reg(tmp, tmp, res); 902b47a4a02SSven Schnelle cond = cond_make_0_tmp(TCG_COND_EQ, tmp); 903b2167459SRichard Henderson break; 904b2167459SRichard Henderson case 4: /* NUV / UV (!C / C) */ 905b2167459SRichard Henderson cond = cond_make_0(TCG_COND_EQ, cb_msb); 906b2167459SRichard Henderson break; 907b2167459SRichard Henderson case 5: /* ZNV / VNZ (!C | Z / C & !Z) */ 908b2167459SRichard Henderson tmp = tcg_temp_new(); 909eaa3783bSRichard Henderson tcg_gen_neg_reg(tmp, cb_msb); 910eaa3783bSRichard Henderson tcg_gen_and_reg(tmp, tmp, res); 911b47a4a02SSven Schnelle cond = cond_make_0_tmp(TCG_COND_EQ, tmp); 912b2167459SRichard Henderson break; 913b2167459SRichard Henderson case 6: /* SV / NSV (V / !V) */ 914b2167459SRichard Henderson cond = cond_make_0(TCG_COND_LT, sv); 915b2167459SRichard Henderson break; 916b2167459SRichard Henderson case 7: /* OD / EV */ 917b2167459SRichard Henderson tmp = tcg_temp_new(); 918eaa3783bSRichard Henderson tcg_gen_andi_reg(tmp, res, 1); 919b47a4a02SSven Schnelle cond = cond_make_0_tmp(TCG_COND_NE, tmp); 920b2167459SRichard Henderson break; 921b2167459SRichard Henderson default: 922b2167459SRichard Henderson g_assert_not_reached(); 923b2167459SRichard Henderson } 924b2167459SRichard Henderson if (cf & 1) { 925b2167459SRichard Henderson cond.c = tcg_invert_cond(cond.c); 926b2167459SRichard Henderson } 927b2167459SRichard Henderson 928b2167459SRichard Henderson return cond; 929b2167459SRichard Henderson } 930b2167459SRichard Henderson 931b2167459SRichard Henderson /* Similar, but for the special case of subtraction without borrow, we 932b2167459SRichard Henderson can use the inputs directly. This can allow other computation to be 933b2167459SRichard Henderson deleted as unused. */ 934b2167459SRichard Henderson 935eaa3783bSRichard Henderson static DisasCond do_sub_cond(unsigned cf, TCGv_reg res, 936eaa3783bSRichard Henderson TCGv_reg in1, TCGv_reg in2, TCGv_reg sv) 937b2167459SRichard Henderson { 938b2167459SRichard Henderson DisasCond cond; 939b2167459SRichard Henderson 940b2167459SRichard Henderson switch (cf >> 1) { 941b2167459SRichard Henderson case 1: /* = / <> */ 942b2167459SRichard Henderson cond = cond_make(TCG_COND_EQ, in1, in2); 943b2167459SRichard Henderson break; 944b2167459SRichard Henderson case 2: /* < / >= */ 945b2167459SRichard Henderson cond = cond_make(TCG_COND_LT, in1, in2); 946b2167459SRichard Henderson break; 947b2167459SRichard Henderson case 3: /* <= / > */ 948b2167459SRichard Henderson cond = cond_make(TCG_COND_LE, in1, in2); 949b2167459SRichard Henderson break; 950b2167459SRichard Henderson case 4: /* << / >>= */ 951b2167459SRichard Henderson cond = cond_make(TCG_COND_LTU, in1, in2); 952b2167459SRichard Henderson break; 953b2167459SRichard Henderson case 5: /* <<= / >> */ 954b2167459SRichard Henderson cond = cond_make(TCG_COND_LEU, in1, in2); 955b2167459SRichard Henderson break; 956b2167459SRichard Henderson default: 957b47a4a02SSven Schnelle return do_cond(cf, res, NULL, sv); 958b2167459SRichard Henderson } 959b2167459SRichard Henderson if (cf & 1) { 960b2167459SRichard Henderson cond.c = tcg_invert_cond(cond.c); 961b2167459SRichard Henderson } 962b2167459SRichard Henderson 963b2167459SRichard Henderson return cond; 964b2167459SRichard Henderson } 965b2167459SRichard Henderson 966df0232feSRichard Henderson /* 967df0232feSRichard Henderson * Similar, but for logicals, where the carry and overflow bits are not 968df0232feSRichard Henderson * computed, and use of them is undefined. 969df0232feSRichard Henderson * 970df0232feSRichard Henderson * Undefined or not, hardware does not trap. It seems reasonable to 971df0232feSRichard Henderson * assume hardware treats cases c={4,5,6} as if C=0 & V=0, since that's 972df0232feSRichard Henderson * how cases c={2,3} are treated. 973df0232feSRichard Henderson */ 974b2167459SRichard Henderson 975eaa3783bSRichard Henderson static DisasCond do_log_cond(unsigned cf, TCGv_reg res) 976b2167459SRichard Henderson { 977df0232feSRichard Henderson switch (cf) { 978df0232feSRichard Henderson case 0: /* never */ 979df0232feSRichard Henderson case 9: /* undef, C */ 980df0232feSRichard Henderson case 11: /* undef, C & !Z */ 981df0232feSRichard Henderson case 12: /* undef, V */ 982df0232feSRichard Henderson return cond_make_f(); 983df0232feSRichard Henderson 984df0232feSRichard Henderson case 1: /* true */ 985df0232feSRichard Henderson case 8: /* undef, !C */ 986df0232feSRichard Henderson case 10: /* undef, !C | Z */ 987df0232feSRichard Henderson case 13: /* undef, !V */ 988df0232feSRichard Henderson return cond_make_t(); 989df0232feSRichard Henderson 990df0232feSRichard Henderson case 2: /* == */ 991df0232feSRichard Henderson return cond_make_0(TCG_COND_EQ, res); 992df0232feSRichard Henderson case 3: /* <> */ 993df0232feSRichard Henderson return cond_make_0(TCG_COND_NE, res); 994df0232feSRichard Henderson case 4: /* < */ 995df0232feSRichard Henderson return cond_make_0(TCG_COND_LT, res); 996df0232feSRichard Henderson case 5: /* >= */ 997df0232feSRichard Henderson return cond_make_0(TCG_COND_GE, res); 998df0232feSRichard Henderson case 6: /* <= */ 999df0232feSRichard Henderson return cond_make_0(TCG_COND_LE, res); 1000df0232feSRichard Henderson case 7: /* > */ 1001df0232feSRichard Henderson return cond_make_0(TCG_COND_GT, res); 1002df0232feSRichard Henderson 1003df0232feSRichard Henderson case 14: /* OD */ 1004df0232feSRichard Henderson case 15: /* EV */ 1005df0232feSRichard Henderson return do_cond(cf, res, NULL, NULL); 1006df0232feSRichard Henderson 1007df0232feSRichard Henderson default: 1008df0232feSRichard Henderson g_assert_not_reached(); 1009b2167459SRichard Henderson } 1010b2167459SRichard Henderson } 1011b2167459SRichard Henderson 101298cd9ca7SRichard Henderson /* Similar, but for shift/extract/deposit conditions. */ 101398cd9ca7SRichard Henderson 1014eaa3783bSRichard Henderson static DisasCond do_sed_cond(unsigned orig, TCGv_reg res) 101598cd9ca7SRichard Henderson { 101698cd9ca7SRichard Henderson unsigned c, f; 101798cd9ca7SRichard Henderson 101898cd9ca7SRichard Henderson /* Convert the compressed condition codes to standard. 101998cd9ca7SRichard Henderson 0-2 are the same as logicals (nv,<,<=), while 3 is OD. 102098cd9ca7SRichard Henderson 4-7 are the reverse of 0-3. */ 102198cd9ca7SRichard Henderson c = orig & 3; 102298cd9ca7SRichard Henderson if (c == 3) { 102398cd9ca7SRichard Henderson c = 7; 102498cd9ca7SRichard Henderson } 102598cd9ca7SRichard Henderson f = (orig & 4) / 4; 102698cd9ca7SRichard Henderson 102798cd9ca7SRichard Henderson return do_log_cond(c * 2 + f, res); 102898cd9ca7SRichard Henderson } 102998cd9ca7SRichard Henderson 1030b2167459SRichard Henderson /* Similar, but for unit conditions. */ 1031b2167459SRichard Henderson 1032eaa3783bSRichard Henderson static DisasCond do_unit_cond(unsigned cf, TCGv_reg res, 1033eaa3783bSRichard Henderson TCGv_reg in1, TCGv_reg in2) 1034b2167459SRichard Henderson { 1035b2167459SRichard Henderson DisasCond cond; 1036eaa3783bSRichard Henderson TCGv_reg tmp, cb = NULL; 1037b2167459SRichard Henderson 1038b2167459SRichard Henderson if (cf & 8) { 1039b2167459SRichard Henderson /* Since we want to test lots of carry-out bits all at once, do not 1040b2167459SRichard Henderson * do our normal thing and compute carry-in of bit B+1 since that 1041b2167459SRichard Henderson * leaves us with carry bits spread across two words. 1042b2167459SRichard Henderson */ 1043b2167459SRichard Henderson cb = tcg_temp_new(); 1044b2167459SRichard Henderson tmp = tcg_temp_new(); 1045eaa3783bSRichard Henderson tcg_gen_or_reg(cb, in1, in2); 1046eaa3783bSRichard Henderson tcg_gen_and_reg(tmp, in1, in2); 1047eaa3783bSRichard Henderson tcg_gen_andc_reg(cb, cb, res); 1048eaa3783bSRichard Henderson tcg_gen_or_reg(cb, cb, tmp); 1049b2167459SRichard Henderson tcg_temp_free(tmp); 1050b2167459SRichard Henderson } 1051b2167459SRichard Henderson 1052b2167459SRichard Henderson switch (cf >> 1) { 1053b2167459SRichard Henderson case 0: /* never / TR */ 1054b2167459SRichard Henderson case 1: /* undefined */ 1055b2167459SRichard Henderson case 5: /* undefined */ 1056b2167459SRichard Henderson cond = cond_make_f(); 1057b2167459SRichard Henderson break; 1058b2167459SRichard Henderson 1059b2167459SRichard Henderson case 2: /* SBZ / NBZ */ 1060b2167459SRichard Henderson /* See hasless(v,1) from 1061b2167459SRichard Henderson * https://graphics.stanford.edu/~seander/bithacks.html#ZeroInWord 1062b2167459SRichard Henderson */ 1063b2167459SRichard Henderson tmp = tcg_temp_new(); 1064eaa3783bSRichard Henderson tcg_gen_subi_reg(tmp, res, 0x01010101u); 1065eaa3783bSRichard Henderson tcg_gen_andc_reg(tmp, tmp, res); 1066eaa3783bSRichard Henderson tcg_gen_andi_reg(tmp, tmp, 0x80808080u); 1067b2167459SRichard Henderson cond = cond_make_0(TCG_COND_NE, tmp); 1068b2167459SRichard Henderson tcg_temp_free(tmp); 1069b2167459SRichard Henderson break; 1070b2167459SRichard Henderson 1071b2167459SRichard Henderson case 3: /* SHZ / NHZ */ 1072b2167459SRichard Henderson tmp = tcg_temp_new(); 1073eaa3783bSRichard Henderson tcg_gen_subi_reg(tmp, res, 0x00010001u); 1074eaa3783bSRichard Henderson tcg_gen_andc_reg(tmp, tmp, res); 1075eaa3783bSRichard Henderson tcg_gen_andi_reg(tmp, tmp, 0x80008000u); 1076b2167459SRichard Henderson cond = cond_make_0(TCG_COND_NE, tmp); 1077b2167459SRichard Henderson tcg_temp_free(tmp); 1078b2167459SRichard Henderson break; 1079b2167459SRichard Henderson 1080b2167459SRichard Henderson case 4: /* SDC / NDC */ 1081eaa3783bSRichard Henderson tcg_gen_andi_reg(cb, cb, 0x88888888u); 1082b2167459SRichard Henderson cond = cond_make_0(TCG_COND_NE, cb); 1083b2167459SRichard Henderson break; 1084b2167459SRichard Henderson 1085b2167459SRichard Henderson case 6: /* SBC / NBC */ 1086eaa3783bSRichard Henderson tcg_gen_andi_reg(cb, cb, 0x80808080u); 1087b2167459SRichard Henderson cond = cond_make_0(TCG_COND_NE, cb); 1088b2167459SRichard Henderson break; 1089b2167459SRichard Henderson 1090b2167459SRichard Henderson case 7: /* SHC / NHC */ 1091eaa3783bSRichard Henderson tcg_gen_andi_reg(cb, cb, 0x80008000u); 1092b2167459SRichard Henderson cond = cond_make_0(TCG_COND_NE, cb); 1093b2167459SRichard Henderson break; 1094b2167459SRichard Henderson 1095b2167459SRichard Henderson default: 1096b2167459SRichard Henderson g_assert_not_reached(); 1097b2167459SRichard Henderson } 1098b2167459SRichard Henderson if (cf & 8) { 1099b2167459SRichard Henderson tcg_temp_free(cb); 1100b2167459SRichard Henderson } 1101b2167459SRichard Henderson if (cf & 1) { 1102b2167459SRichard Henderson cond.c = tcg_invert_cond(cond.c); 1103b2167459SRichard Henderson } 1104b2167459SRichard Henderson 1105b2167459SRichard Henderson return cond; 1106b2167459SRichard Henderson } 1107b2167459SRichard Henderson 1108b2167459SRichard Henderson /* Compute signed overflow for addition. */ 1109eaa3783bSRichard Henderson static TCGv_reg do_add_sv(DisasContext *ctx, TCGv_reg res, 1110eaa3783bSRichard Henderson TCGv_reg in1, TCGv_reg in2) 1111b2167459SRichard Henderson { 1112eaa3783bSRichard Henderson TCGv_reg sv = get_temp(ctx); 1113eaa3783bSRichard Henderson TCGv_reg tmp = tcg_temp_new(); 1114b2167459SRichard Henderson 1115eaa3783bSRichard Henderson tcg_gen_xor_reg(sv, res, in1); 1116eaa3783bSRichard Henderson tcg_gen_xor_reg(tmp, in1, in2); 1117eaa3783bSRichard Henderson tcg_gen_andc_reg(sv, sv, tmp); 1118b2167459SRichard Henderson tcg_temp_free(tmp); 1119b2167459SRichard Henderson 1120b2167459SRichard Henderson return sv; 1121b2167459SRichard Henderson } 1122b2167459SRichard Henderson 1123b2167459SRichard Henderson /* Compute signed overflow for subtraction. */ 1124eaa3783bSRichard Henderson static TCGv_reg do_sub_sv(DisasContext *ctx, TCGv_reg res, 1125eaa3783bSRichard Henderson TCGv_reg in1, TCGv_reg in2) 1126b2167459SRichard Henderson { 1127eaa3783bSRichard Henderson TCGv_reg sv = get_temp(ctx); 1128eaa3783bSRichard Henderson TCGv_reg tmp = tcg_temp_new(); 1129b2167459SRichard Henderson 1130eaa3783bSRichard Henderson tcg_gen_xor_reg(sv, res, in1); 1131eaa3783bSRichard Henderson tcg_gen_xor_reg(tmp, in1, in2); 1132eaa3783bSRichard Henderson tcg_gen_and_reg(sv, sv, tmp); 1133b2167459SRichard Henderson tcg_temp_free(tmp); 1134b2167459SRichard Henderson 1135b2167459SRichard Henderson return sv; 1136b2167459SRichard Henderson } 1137b2167459SRichard Henderson 113831234768SRichard Henderson static void do_add(DisasContext *ctx, unsigned rt, TCGv_reg in1, 1139eaa3783bSRichard Henderson TCGv_reg in2, unsigned shift, bool is_l, 1140eaa3783bSRichard Henderson bool is_tsv, bool is_tc, bool is_c, unsigned cf) 1141b2167459SRichard Henderson { 1142eaa3783bSRichard Henderson TCGv_reg dest, cb, cb_msb, sv, tmp; 1143b2167459SRichard Henderson unsigned c = cf >> 1; 1144b2167459SRichard Henderson DisasCond cond; 1145b2167459SRichard Henderson 1146b2167459SRichard Henderson dest = tcg_temp_new(); 1147f764718dSRichard Henderson cb = NULL; 1148f764718dSRichard Henderson cb_msb = NULL; 1149b2167459SRichard Henderson 1150b2167459SRichard Henderson if (shift) { 1151b2167459SRichard Henderson tmp = get_temp(ctx); 1152eaa3783bSRichard Henderson tcg_gen_shli_reg(tmp, in1, shift); 1153b2167459SRichard Henderson in1 = tmp; 1154b2167459SRichard Henderson } 1155b2167459SRichard Henderson 1156b47a4a02SSven Schnelle if (!is_l || cond_need_cb(c)) { 1157eaa3783bSRichard Henderson TCGv_reg zero = tcg_const_reg(0); 1158b2167459SRichard Henderson cb_msb = get_temp(ctx); 1159eaa3783bSRichard Henderson tcg_gen_add2_reg(dest, cb_msb, in1, zero, in2, zero); 1160b2167459SRichard Henderson if (is_c) { 1161eaa3783bSRichard Henderson tcg_gen_add2_reg(dest, cb_msb, dest, cb_msb, cpu_psw_cb_msb, zero); 1162b2167459SRichard Henderson } 1163b2167459SRichard Henderson tcg_temp_free(zero); 1164b2167459SRichard Henderson if (!is_l) { 1165b2167459SRichard Henderson cb = get_temp(ctx); 1166eaa3783bSRichard Henderson tcg_gen_xor_reg(cb, in1, in2); 1167eaa3783bSRichard Henderson tcg_gen_xor_reg(cb, cb, dest); 1168b2167459SRichard Henderson } 1169b2167459SRichard Henderson } else { 1170eaa3783bSRichard Henderson tcg_gen_add_reg(dest, in1, in2); 1171b2167459SRichard Henderson if (is_c) { 1172eaa3783bSRichard Henderson tcg_gen_add_reg(dest, dest, cpu_psw_cb_msb); 1173b2167459SRichard Henderson } 1174b2167459SRichard Henderson } 1175b2167459SRichard Henderson 1176b2167459SRichard Henderson /* Compute signed overflow if required. */ 1177f764718dSRichard Henderson sv = NULL; 1178b47a4a02SSven Schnelle if (is_tsv || cond_need_sv(c)) { 1179b2167459SRichard Henderson sv = do_add_sv(ctx, dest, in1, in2); 1180b2167459SRichard Henderson if (is_tsv) { 1181b2167459SRichard Henderson /* ??? Need to include overflow from shift. */ 1182b2167459SRichard Henderson gen_helper_tsv(cpu_env, sv); 1183b2167459SRichard Henderson } 1184b2167459SRichard Henderson } 1185b2167459SRichard Henderson 1186b2167459SRichard Henderson /* Emit any conditional trap before any writeback. */ 1187b2167459SRichard Henderson cond = do_cond(cf, dest, cb_msb, sv); 1188b2167459SRichard Henderson if (is_tc) { 1189b2167459SRichard Henderson cond_prep(&cond); 1190b2167459SRichard Henderson tmp = tcg_temp_new(); 1191eaa3783bSRichard Henderson tcg_gen_setcond_reg(cond.c, tmp, cond.a0, cond.a1); 1192b2167459SRichard Henderson gen_helper_tcond(cpu_env, tmp); 1193b2167459SRichard Henderson tcg_temp_free(tmp); 1194b2167459SRichard Henderson } 1195b2167459SRichard Henderson 1196b2167459SRichard Henderson /* Write back the result. */ 1197b2167459SRichard Henderson if (!is_l) { 1198b2167459SRichard Henderson save_or_nullify(ctx, cpu_psw_cb, cb); 1199b2167459SRichard Henderson save_or_nullify(ctx, cpu_psw_cb_msb, cb_msb); 1200b2167459SRichard Henderson } 1201b2167459SRichard Henderson save_gpr(ctx, rt, dest); 1202b2167459SRichard Henderson tcg_temp_free(dest); 1203b2167459SRichard Henderson 1204b2167459SRichard Henderson /* Install the new nullification. */ 1205b2167459SRichard Henderson cond_free(&ctx->null_cond); 1206b2167459SRichard Henderson ctx->null_cond = cond; 1207b2167459SRichard Henderson } 1208b2167459SRichard Henderson 12090c982a28SRichard Henderson static bool do_add_reg(DisasContext *ctx, arg_rrr_cf_sh *a, 12100c982a28SRichard Henderson bool is_l, bool is_tsv, bool is_tc, bool is_c) 12110c982a28SRichard Henderson { 12120c982a28SRichard Henderson TCGv_reg tcg_r1, tcg_r2; 12130c982a28SRichard Henderson 12140c982a28SRichard Henderson if (a->cf) { 12150c982a28SRichard Henderson nullify_over(ctx); 12160c982a28SRichard Henderson } 12170c982a28SRichard Henderson tcg_r1 = load_gpr(ctx, a->r1); 12180c982a28SRichard Henderson tcg_r2 = load_gpr(ctx, a->r2); 12190c982a28SRichard Henderson do_add(ctx, a->t, tcg_r1, tcg_r2, a->sh, is_l, is_tsv, is_tc, is_c, a->cf); 12200c982a28SRichard Henderson return nullify_end(ctx); 12210c982a28SRichard Henderson } 12220c982a28SRichard Henderson 12230588e061SRichard Henderson static bool do_add_imm(DisasContext *ctx, arg_rri_cf *a, 12240588e061SRichard Henderson bool is_tsv, bool is_tc) 12250588e061SRichard Henderson { 12260588e061SRichard Henderson TCGv_reg tcg_im, tcg_r2; 12270588e061SRichard Henderson 12280588e061SRichard Henderson if (a->cf) { 12290588e061SRichard Henderson nullify_over(ctx); 12300588e061SRichard Henderson } 12310588e061SRichard Henderson tcg_im = load_const(ctx, a->i); 12320588e061SRichard Henderson tcg_r2 = load_gpr(ctx, a->r); 12330588e061SRichard Henderson do_add(ctx, a->t, tcg_im, tcg_r2, 0, 0, is_tsv, is_tc, 0, a->cf); 12340588e061SRichard Henderson return nullify_end(ctx); 12350588e061SRichard Henderson } 12360588e061SRichard Henderson 123731234768SRichard Henderson static void do_sub(DisasContext *ctx, unsigned rt, TCGv_reg in1, 1238eaa3783bSRichard Henderson TCGv_reg in2, bool is_tsv, bool is_b, 1239eaa3783bSRichard Henderson bool is_tc, unsigned cf) 1240b2167459SRichard Henderson { 1241eaa3783bSRichard Henderson TCGv_reg dest, sv, cb, cb_msb, zero, tmp; 1242b2167459SRichard Henderson unsigned c = cf >> 1; 1243b2167459SRichard Henderson DisasCond cond; 1244b2167459SRichard Henderson 1245b2167459SRichard Henderson dest = tcg_temp_new(); 1246b2167459SRichard Henderson cb = tcg_temp_new(); 1247b2167459SRichard Henderson cb_msb = tcg_temp_new(); 1248b2167459SRichard Henderson 1249eaa3783bSRichard Henderson zero = tcg_const_reg(0); 1250b2167459SRichard Henderson if (is_b) { 1251b2167459SRichard Henderson /* DEST,C = IN1 + ~IN2 + C. */ 1252eaa3783bSRichard Henderson tcg_gen_not_reg(cb, in2); 1253eaa3783bSRichard Henderson tcg_gen_add2_reg(dest, cb_msb, in1, zero, cpu_psw_cb_msb, zero); 1254eaa3783bSRichard Henderson tcg_gen_add2_reg(dest, cb_msb, dest, cb_msb, cb, zero); 1255eaa3783bSRichard Henderson tcg_gen_xor_reg(cb, cb, in1); 1256eaa3783bSRichard Henderson tcg_gen_xor_reg(cb, cb, dest); 1257b2167459SRichard Henderson } else { 1258b2167459SRichard Henderson /* DEST,C = IN1 + ~IN2 + 1. We can produce the same result in fewer 1259b2167459SRichard Henderson operations by seeding the high word with 1 and subtracting. */ 1260eaa3783bSRichard Henderson tcg_gen_movi_reg(cb_msb, 1); 1261eaa3783bSRichard Henderson tcg_gen_sub2_reg(dest, cb_msb, in1, cb_msb, in2, zero); 1262eaa3783bSRichard Henderson tcg_gen_eqv_reg(cb, in1, in2); 1263eaa3783bSRichard Henderson tcg_gen_xor_reg(cb, cb, dest); 1264b2167459SRichard Henderson } 1265b2167459SRichard Henderson tcg_temp_free(zero); 1266b2167459SRichard Henderson 1267b2167459SRichard Henderson /* Compute signed overflow if required. */ 1268f764718dSRichard Henderson sv = NULL; 1269b47a4a02SSven Schnelle if (is_tsv || cond_need_sv(c)) { 1270b2167459SRichard Henderson sv = do_sub_sv(ctx, dest, in1, in2); 1271b2167459SRichard Henderson if (is_tsv) { 1272b2167459SRichard Henderson gen_helper_tsv(cpu_env, sv); 1273b2167459SRichard Henderson } 1274b2167459SRichard Henderson } 1275b2167459SRichard Henderson 1276b2167459SRichard Henderson /* Compute the condition. We cannot use the special case for borrow. */ 1277b2167459SRichard Henderson if (!is_b) { 1278b2167459SRichard Henderson cond = do_sub_cond(cf, dest, in1, in2, sv); 1279b2167459SRichard Henderson } else { 1280b2167459SRichard Henderson cond = do_cond(cf, dest, cb_msb, sv); 1281b2167459SRichard Henderson } 1282b2167459SRichard Henderson 1283b2167459SRichard Henderson /* Emit any conditional trap before any writeback. */ 1284b2167459SRichard Henderson if (is_tc) { 1285b2167459SRichard Henderson cond_prep(&cond); 1286b2167459SRichard Henderson tmp = tcg_temp_new(); 1287eaa3783bSRichard Henderson tcg_gen_setcond_reg(cond.c, tmp, cond.a0, cond.a1); 1288b2167459SRichard Henderson gen_helper_tcond(cpu_env, tmp); 1289b2167459SRichard Henderson tcg_temp_free(tmp); 1290b2167459SRichard Henderson } 1291b2167459SRichard Henderson 1292b2167459SRichard Henderson /* Write back the result. */ 1293b2167459SRichard Henderson save_or_nullify(ctx, cpu_psw_cb, cb); 1294b2167459SRichard Henderson save_or_nullify(ctx, cpu_psw_cb_msb, cb_msb); 1295b2167459SRichard Henderson save_gpr(ctx, rt, dest); 1296b2167459SRichard Henderson tcg_temp_free(dest); 1297*79826f99SRichard Henderson tcg_temp_free(cb); 1298*79826f99SRichard Henderson tcg_temp_free(cb_msb); 1299b2167459SRichard Henderson 1300b2167459SRichard Henderson /* Install the new nullification. */ 1301b2167459SRichard Henderson cond_free(&ctx->null_cond); 1302b2167459SRichard Henderson ctx->null_cond = cond; 1303b2167459SRichard Henderson } 1304b2167459SRichard Henderson 13050c982a28SRichard Henderson static bool do_sub_reg(DisasContext *ctx, arg_rrr_cf *a, 13060c982a28SRichard Henderson bool is_tsv, bool is_b, bool is_tc) 13070c982a28SRichard Henderson { 13080c982a28SRichard Henderson TCGv_reg tcg_r1, tcg_r2; 13090c982a28SRichard Henderson 13100c982a28SRichard Henderson if (a->cf) { 13110c982a28SRichard Henderson nullify_over(ctx); 13120c982a28SRichard Henderson } 13130c982a28SRichard Henderson tcg_r1 = load_gpr(ctx, a->r1); 13140c982a28SRichard Henderson tcg_r2 = load_gpr(ctx, a->r2); 13150c982a28SRichard Henderson do_sub(ctx, a->t, tcg_r1, tcg_r2, is_tsv, is_b, is_tc, a->cf); 13160c982a28SRichard Henderson return nullify_end(ctx); 13170c982a28SRichard Henderson } 13180c982a28SRichard Henderson 13190588e061SRichard Henderson static bool do_sub_imm(DisasContext *ctx, arg_rri_cf *a, bool is_tsv) 13200588e061SRichard Henderson { 13210588e061SRichard Henderson TCGv_reg tcg_im, tcg_r2; 13220588e061SRichard Henderson 13230588e061SRichard Henderson if (a->cf) { 13240588e061SRichard Henderson nullify_over(ctx); 13250588e061SRichard Henderson } 13260588e061SRichard Henderson tcg_im = load_const(ctx, a->i); 13270588e061SRichard Henderson tcg_r2 = load_gpr(ctx, a->r); 13280588e061SRichard Henderson do_sub(ctx, a->t, tcg_im, tcg_r2, is_tsv, 0, 0, a->cf); 13290588e061SRichard Henderson return nullify_end(ctx); 13300588e061SRichard Henderson } 13310588e061SRichard Henderson 133231234768SRichard Henderson static void do_cmpclr(DisasContext *ctx, unsigned rt, TCGv_reg in1, 1333eaa3783bSRichard Henderson TCGv_reg in2, unsigned cf) 1334b2167459SRichard Henderson { 1335eaa3783bSRichard Henderson TCGv_reg dest, sv; 1336b2167459SRichard Henderson DisasCond cond; 1337b2167459SRichard Henderson 1338b2167459SRichard Henderson dest = tcg_temp_new(); 1339eaa3783bSRichard Henderson tcg_gen_sub_reg(dest, in1, in2); 1340b2167459SRichard Henderson 1341b2167459SRichard Henderson /* Compute signed overflow if required. */ 1342f764718dSRichard Henderson sv = NULL; 1343b47a4a02SSven Schnelle if (cond_need_sv(cf >> 1)) { 1344b2167459SRichard Henderson sv = do_sub_sv(ctx, dest, in1, in2); 1345b2167459SRichard Henderson } 1346b2167459SRichard Henderson 1347b2167459SRichard Henderson /* Form the condition for the compare. */ 1348b2167459SRichard Henderson cond = do_sub_cond(cf, dest, in1, in2, sv); 1349b2167459SRichard Henderson 1350b2167459SRichard Henderson /* Clear. */ 1351eaa3783bSRichard Henderson tcg_gen_movi_reg(dest, 0); 1352b2167459SRichard Henderson save_gpr(ctx, rt, dest); 1353b2167459SRichard Henderson tcg_temp_free(dest); 1354b2167459SRichard Henderson 1355b2167459SRichard Henderson /* Install the new nullification. */ 1356b2167459SRichard Henderson cond_free(&ctx->null_cond); 1357b2167459SRichard Henderson ctx->null_cond = cond; 1358b2167459SRichard Henderson } 1359b2167459SRichard Henderson 136031234768SRichard Henderson static void do_log(DisasContext *ctx, unsigned rt, TCGv_reg in1, 1361eaa3783bSRichard Henderson TCGv_reg in2, unsigned cf, 1362eaa3783bSRichard Henderson void (*fn)(TCGv_reg, TCGv_reg, TCGv_reg)) 1363b2167459SRichard Henderson { 1364eaa3783bSRichard Henderson TCGv_reg dest = dest_gpr(ctx, rt); 1365b2167459SRichard Henderson 1366b2167459SRichard Henderson /* Perform the operation, and writeback. */ 1367b2167459SRichard Henderson fn(dest, in1, in2); 1368b2167459SRichard Henderson save_gpr(ctx, rt, dest); 1369b2167459SRichard Henderson 1370b2167459SRichard Henderson /* Install the new nullification. */ 1371b2167459SRichard Henderson cond_free(&ctx->null_cond); 1372b2167459SRichard Henderson if (cf) { 1373b2167459SRichard Henderson ctx->null_cond = do_log_cond(cf, dest); 1374b2167459SRichard Henderson } 1375b2167459SRichard Henderson } 1376b2167459SRichard Henderson 13770c982a28SRichard Henderson static bool do_log_reg(DisasContext *ctx, arg_rrr_cf *a, 13780c982a28SRichard Henderson void (*fn)(TCGv_reg, TCGv_reg, TCGv_reg)) 13790c982a28SRichard Henderson { 13800c982a28SRichard Henderson TCGv_reg tcg_r1, tcg_r2; 13810c982a28SRichard Henderson 13820c982a28SRichard Henderson if (a->cf) { 13830c982a28SRichard Henderson nullify_over(ctx); 13840c982a28SRichard Henderson } 13850c982a28SRichard Henderson tcg_r1 = load_gpr(ctx, a->r1); 13860c982a28SRichard Henderson tcg_r2 = load_gpr(ctx, a->r2); 13870c982a28SRichard Henderson do_log(ctx, a->t, tcg_r1, tcg_r2, a->cf, fn); 13880c982a28SRichard Henderson return nullify_end(ctx); 13890c982a28SRichard Henderson } 13900c982a28SRichard Henderson 139131234768SRichard Henderson static void do_unit(DisasContext *ctx, unsigned rt, TCGv_reg in1, 1392eaa3783bSRichard Henderson TCGv_reg in2, unsigned cf, bool is_tc, 1393eaa3783bSRichard Henderson void (*fn)(TCGv_reg, TCGv_reg, TCGv_reg)) 1394b2167459SRichard Henderson { 1395eaa3783bSRichard Henderson TCGv_reg dest; 1396b2167459SRichard Henderson DisasCond cond; 1397b2167459SRichard Henderson 1398b2167459SRichard Henderson if (cf == 0) { 1399b2167459SRichard Henderson dest = dest_gpr(ctx, rt); 1400b2167459SRichard Henderson fn(dest, in1, in2); 1401b2167459SRichard Henderson save_gpr(ctx, rt, dest); 1402b2167459SRichard Henderson cond_free(&ctx->null_cond); 1403b2167459SRichard Henderson } else { 1404b2167459SRichard Henderson dest = tcg_temp_new(); 1405b2167459SRichard Henderson fn(dest, in1, in2); 1406b2167459SRichard Henderson 1407b2167459SRichard Henderson cond = do_unit_cond(cf, dest, in1, in2); 1408b2167459SRichard Henderson 1409b2167459SRichard Henderson if (is_tc) { 1410eaa3783bSRichard Henderson TCGv_reg tmp = tcg_temp_new(); 1411b2167459SRichard Henderson cond_prep(&cond); 1412eaa3783bSRichard Henderson tcg_gen_setcond_reg(cond.c, tmp, cond.a0, cond.a1); 1413b2167459SRichard Henderson gen_helper_tcond(cpu_env, tmp); 1414b2167459SRichard Henderson tcg_temp_free(tmp); 1415b2167459SRichard Henderson } 1416b2167459SRichard Henderson save_gpr(ctx, rt, dest); 1417b2167459SRichard Henderson 1418b2167459SRichard Henderson cond_free(&ctx->null_cond); 1419b2167459SRichard Henderson ctx->null_cond = cond; 1420b2167459SRichard Henderson } 1421b2167459SRichard Henderson } 1422b2167459SRichard Henderson 142386f8d05fSRichard Henderson #ifndef CONFIG_USER_ONLY 14248d6ae7fbSRichard Henderson /* The "normal" usage is SP >= 0, wherein SP == 0 selects the space 14258d6ae7fbSRichard Henderson from the top 2 bits of the base register. There are a few system 14268d6ae7fbSRichard Henderson instructions that have a 3-bit space specifier, for which SR0 is 14278d6ae7fbSRichard Henderson not special. To handle this, pass ~SP. */ 142886f8d05fSRichard Henderson static TCGv_i64 space_select(DisasContext *ctx, int sp, TCGv_reg base) 142986f8d05fSRichard Henderson { 143086f8d05fSRichard Henderson TCGv_ptr ptr; 143186f8d05fSRichard Henderson TCGv_reg tmp; 143286f8d05fSRichard Henderson TCGv_i64 spc; 143386f8d05fSRichard Henderson 143486f8d05fSRichard Henderson if (sp != 0) { 14358d6ae7fbSRichard Henderson if (sp < 0) { 14368d6ae7fbSRichard Henderson sp = ~sp; 14378d6ae7fbSRichard Henderson } 14388d6ae7fbSRichard Henderson spc = get_temp_tl(ctx); 14398d6ae7fbSRichard Henderson load_spr(ctx, spc, sp); 14408d6ae7fbSRichard Henderson return spc; 144186f8d05fSRichard Henderson } 1442494737b7SRichard Henderson if (ctx->tb_flags & TB_FLAG_SR_SAME) { 1443494737b7SRichard Henderson return cpu_srH; 1444494737b7SRichard Henderson } 144586f8d05fSRichard Henderson 144686f8d05fSRichard Henderson ptr = tcg_temp_new_ptr(); 144786f8d05fSRichard Henderson tmp = tcg_temp_new(); 144886f8d05fSRichard Henderson spc = get_temp_tl(ctx); 144986f8d05fSRichard Henderson 145086f8d05fSRichard Henderson tcg_gen_shri_reg(tmp, base, TARGET_REGISTER_BITS - 5); 145186f8d05fSRichard Henderson tcg_gen_andi_reg(tmp, tmp, 030); 145286f8d05fSRichard Henderson tcg_gen_trunc_reg_ptr(ptr, tmp); 145386f8d05fSRichard Henderson tcg_temp_free(tmp); 145486f8d05fSRichard Henderson 145586f8d05fSRichard Henderson tcg_gen_add_ptr(ptr, ptr, cpu_env); 145686f8d05fSRichard Henderson tcg_gen_ld_i64(spc, ptr, offsetof(CPUHPPAState, sr[4])); 145786f8d05fSRichard Henderson tcg_temp_free_ptr(ptr); 145886f8d05fSRichard Henderson 145986f8d05fSRichard Henderson return spc; 146086f8d05fSRichard Henderson } 146186f8d05fSRichard Henderson #endif 146286f8d05fSRichard Henderson 146386f8d05fSRichard Henderson static void form_gva(DisasContext *ctx, TCGv_tl *pgva, TCGv_reg *pofs, 146486f8d05fSRichard Henderson unsigned rb, unsigned rx, int scale, target_sreg disp, 146586f8d05fSRichard Henderson unsigned sp, int modify, bool is_phys) 146686f8d05fSRichard Henderson { 146786f8d05fSRichard Henderson TCGv_reg base = load_gpr(ctx, rb); 146886f8d05fSRichard Henderson TCGv_reg ofs; 146986f8d05fSRichard Henderson 147086f8d05fSRichard Henderson /* Note that RX is mutually exclusive with DISP. */ 147186f8d05fSRichard Henderson if (rx) { 147286f8d05fSRichard Henderson ofs = get_temp(ctx); 147386f8d05fSRichard Henderson tcg_gen_shli_reg(ofs, cpu_gr[rx], scale); 147486f8d05fSRichard Henderson tcg_gen_add_reg(ofs, ofs, base); 147586f8d05fSRichard Henderson } else if (disp || modify) { 147686f8d05fSRichard Henderson ofs = get_temp(ctx); 147786f8d05fSRichard Henderson tcg_gen_addi_reg(ofs, base, disp); 147886f8d05fSRichard Henderson } else { 147986f8d05fSRichard Henderson ofs = base; 148086f8d05fSRichard Henderson } 148186f8d05fSRichard Henderson 148286f8d05fSRichard Henderson *pofs = ofs; 148386f8d05fSRichard Henderson #ifdef CONFIG_USER_ONLY 148486f8d05fSRichard Henderson *pgva = (modify <= 0 ? ofs : base); 148586f8d05fSRichard Henderson #else 148686f8d05fSRichard Henderson TCGv_tl addr = get_temp_tl(ctx); 148786f8d05fSRichard Henderson tcg_gen_extu_reg_tl(addr, modify <= 0 ? ofs : base); 1488494737b7SRichard Henderson if (ctx->tb_flags & PSW_W) { 148986f8d05fSRichard Henderson tcg_gen_andi_tl(addr, addr, 0x3fffffffffffffffull); 149086f8d05fSRichard Henderson } 149186f8d05fSRichard Henderson if (!is_phys) { 149286f8d05fSRichard Henderson tcg_gen_or_tl(addr, addr, space_select(ctx, sp, base)); 149386f8d05fSRichard Henderson } 149486f8d05fSRichard Henderson *pgva = addr; 149586f8d05fSRichard Henderson #endif 149686f8d05fSRichard Henderson } 149786f8d05fSRichard Henderson 149896d6407fSRichard Henderson /* Emit a memory load. The modify parameter should be 149996d6407fSRichard Henderson * < 0 for pre-modify, 150096d6407fSRichard Henderson * > 0 for post-modify, 150196d6407fSRichard Henderson * = 0 for no base register update. 150296d6407fSRichard Henderson */ 150396d6407fSRichard Henderson static void do_load_32(DisasContext *ctx, TCGv_i32 dest, 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); 151586f8d05fSRichard Henderson tcg_gen_qemu_ld_reg(dest, addr, ctx->mmu_idx, mop); 151686f8d05fSRichard Henderson if (modify) { 151786f8d05fSRichard Henderson save_gpr(ctx, rb, ofs); 151896d6407fSRichard Henderson } 151996d6407fSRichard Henderson } 152096d6407fSRichard Henderson 152196d6407fSRichard Henderson static void do_load_64(DisasContext *ctx, TCGv_i64 dest, unsigned rb, 1522eaa3783bSRichard Henderson unsigned rx, int scale, target_sreg disp, 152314776ab5STony Nguyen unsigned sp, int modify, MemOp mop) 152496d6407fSRichard Henderson { 152586f8d05fSRichard Henderson TCGv_reg ofs; 152686f8d05fSRichard Henderson TCGv_tl addr; 152796d6407fSRichard Henderson 152896d6407fSRichard Henderson /* Caller uses nullify_over/nullify_end. */ 152996d6407fSRichard Henderson assert(ctx->null_cond.c == TCG_COND_NEVER); 153096d6407fSRichard Henderson 153186f8d05fSRichard Henderson form_gva(ctx, &addr, &ofs, rb, rx, scale, disp, sp, modify, 153286f8d05fSRichard Henderson ctx->mmu_idx == MMU_PHYS_IDX); 15333d68ee7bSRichard Henderson tcg_gen_qemu_ld_i64(dest, addr, ctx->mmu_idx, mop); 153486f8d05fSRichard Henderson if (modify) { 153586f8d05fSRichard Henderson save_gpr(ctx, rb, ofs); 153696d6407fSRichard Henderson } 153796d6407fSRichard Henderson } 153896d6407fSRichard Henderson 153996d6407fSRichard Henderson static void do_store_32(DisasContext *ctx, TCGv_i32 src, unsigned rb, 1540eaa3783bSRichard Henderson unsigned rx, int scale, target_sreg disp, 154114776ab5STony Nguyen unsigned sp, int modify, MemOp mop) 154296d6407fSRichard Henderson { 154386f8d05fSRichard Henderson TCGv_reg ofs; 154486f8d05fSRichard Henderson TCGv_tl addr; 154596d6407fSRichard Henderson 154696d6407fSRichard Henderson /* Caller uses nullify_over/nullify_end. */ 154796d6407fSRichard Henderson assert(ctx->null_cond.c == TCG_COND_NEVER); 154896d6407fSRichard Henderson 154986f8d05fSRichard Henderson form_gva(ctx, &addr, &ofs, rb, rx, scale, disp, sp, modify, 155086f8d05fSRichard Henderson ctx->mmu_idx == MMU_PHYS_IDX); 155186f8d05fSRichard Henderson tcg_gen_qemu_st_i32(src, addr, ctx->mmu_idx, mop); 155286f8d05fSRichard Henderson if (modify) { 155386f8d05fSRichard Henderson save_gpr(ctx, rb, ofs); 155496d6407fSRichard Henderson } 155596d6407fSRichard Henderson } 155696d6407fSRichard Henderson 155796d6407fSRichard Henderson static void do_store_64(DisasContext *ctx, TCGv_i64 src, unsigned rb, 1558eaa3783bSRichard Henderson unsigned rx, int scale, target_sreg disp, 155914776ab5STony Nguyen unsigned sp, int modify, MemOp mop) 156096d6407fSRichard Henderson { 156186f8d05fSRichard Henderson TCGv_reg ofs; 156286f8d05fSRichard Henderson TCGv_tl addr; 156396d6407fSRichard Henderson 156496d6407fSRichard Henderson /* Caller uses nullify_over/nullify_end. */ 156596d6407fSRichard Henderson assert(ctx->null_cond.c == TCG_COND_NEVER); 156696d6407fSRichard Henderson 156786f8d05fSRichard Henderson form_gva(ctx, &addr, &ofs, rb, rx, scale, disp, sp, modify, 156886f8d05fSRichard Henderson ctx->mmu_idx == MMU_PHYS_IDX); 156986f8d05fSRichard Henderson tcg_gen_qemu_st_i64(src, addr, ctx->mmu_idx, mop); 157086f8d05fSRichard Henderson if (modify) { 157186f8d05fSRichard Henderson save_gpr(ctx, rb, ofs); 157296d6407fSRichard Henderson } 157396d6407fSRichard Henderson } 157496d6407fSRichard Henderson 1575eaa3783bSRichard Henderson #if TARGET_REGISTER_BITS == 64 1576eaa3783bSRichard Henderson #define do_load_reg do_load_64 1577eaa3783bSRichard Henderson #define do_store_reg do_store_64 157896d6407fSRichard Henderson #else 1579eaa3783bSRichard Henderson #define do_load_reg do_load_32 1580eaa3783bSRichard Henderson #define do_store_reg do_store_32 158196d6407fSRichard Henderson #endif 158296d6407fSRichard Henderson 15831cd012a5SRichard Henderson static bool do_load(DisasContext *ctx, unsigned rt, unsigned rb, 1584eaa3783bSRichard Henderson unsigned rx, int scale, target_sreg disp, 158514776ab5STony Nguyen unsigned sp, int modify, MemOp mop) 158696d6407fSRichard Henderson { 1587eaa3783bSRichard Henderson TCGv_reg dest; 158896d6407fSRichard Henderson 158996d6407fSRichard Henderson nullify_over(ctx); 159096d6407fSRichard Henderson 159196d6407fSRichard Henderson if (modify == 0) { 159296d6407fSRichard Henderson /* No base register update. */ 159396d6407fSRichard Henderson dest = dest_gpr(ctx, rt); 159496d6407fSRichard Henderson } else { 159596d6407fSRichard Henderson /* Make sure if RT == RB, we see the result of the load. */ 159696d6407fSRichard Henderson dest = get_temp(ctx); 159796d6407fSRichard Henderson } 159886f8d05fSRichard Henderson do_load_reg(ctx, dest, rb, rx, scale, disp, sp, modify, mop); 159996d6407fSRichard Henderson save_gpr(ctx, rt, dest); 160096d6407fSRichard Henderson 16011cd012a5SRichard Henderson return nullify_end(ctx); 160296d6407fSRichard Henderson } 160396d6407fSRichard Henderson 1604740038d7SRichard Henderson static bool do_floadw(DisasContext *ctx, unsigned rt, unsigned rb, 1605eaa3783bSRichard Henderson unsigned rx, int scale, target_sreg disp, 160686f8d05fSRichard Henderson unsigned sp, int modify) 160796d6407fSRichard Henderson { 160896d6407fSRichard Henderson TCGv_i32 tmp; 160996d6407fSRichard Henderson 161096d6407fSRichard Henderson nullify_over(ctx); 161196d6407fSRichard Henderson 161296d6407fSRichard Henderson tmp = tcg_temp_new_i32(); 161386f8d05fSRichard Henderson do_load_32(ctx, tmp, rb, rx, scale, disp, sp, modify, MO_TEUL); 161496d6407fSRichard Henderson save_frw_i32(rt, tmp); 161596d6407fSRichard Henderson tcg_temp_free_i32(tmp); 161696d6407fSRichard Henderson 161796d6407fSRichard Henderson if (rt == 0) { 161896d6407fSRichard Henderson gen_helper_loaded_fr0(cpu_env); 161996d6407fSRichard Henderson } 162096d6407fSRichard Henderson 1621740038d7SRichard Henderson return nullify_end(ctx); 162296d6407fSRichard Henderson } 162396d6407fSRichard Henderson 1624740038d7SRichard Henderson static bool trans_fldw(DisasContext *ctx, arg_ldst *a) 1625740038d7SRichard Henderson { 1626740038d7SRichard Henderson return do_floadw(ctx, a->t, a->b, a->x, a->scale ? 2 : 0, 1627740038d7SRichard Henderson a->disp, a->sp, a->m); 1628740038d7SRichard Henderson } 1629740038d7SRichard Henderson 1630740038d7SRichard Henderson static bool do_floadd(DisasContext *ctx, unsigned rt, unsigned rb, 1631eaa3783bSRichard Henderson unsigned rx, int scale, target_sreg disp, 163286f8d05fSRichard Henderson unsigned sp, int modify) 163396d6407fSRichard Henderson { 163496d6407fSRichard Henderson TCGv_i64 tmp; 163596d6407fSRichard Henderson 163696d6407fSRichard Henderson nullify_over(ctx); 163796d6407fSRichard Henderson 163896d6407fSRichard Henderson tmp = tcg_temp_new_i64(); 163986f8d05fSRichard Henderson do_load_64(ctx, tmp, rb, rx, scale, disp, sp, modify, MO_TEQ); 164096d6407fSRichard Henderson save_frd(rt, tmp); 164196d6407fSRichard Henderson tcg_temp_free_i64(tmp); 164296d6407fSRichard Henderson 164396d6407fSRichard Henderson if (rt == 0) { 164496d6407fSRichard Henderson gen_helper_loaded_fr0(cpu_env); 164596d6407fSRichard Henderson } 164696d6407fSRichard Henderson 1647740038d7SRichard Henderson return nullify_end(ctx); 1648740038d7SRichard Henderson } 1649740038d7SRichard Henderson 1650740038d7SRichard Henderson static bool trans_fldd(DisasContext *ctx, arg_ldst *a) 1651740038d7SRichard Henderson { 1652740038d7SRichard Henderson return do_floadd(ctx, a->t, a->b, a->x, a->scale ? 3 : 0, 1653740038d7SRichard Henderson a->disp, a->sp, a->m); 165496d6407fSRichard Henderson } 165596d6407fSRichard Henderson 16561cd012a5SRichard Henderson static bool do_store(DisasContext *ctx, unsigned rt, unsigned rb, 165786f8d05fSRichard Henderson target_sreg disp, unsigned sp, 165814776ab5STony Nguyen int modify, MemOp mop) 165996d6407fSRichard Henderson { 166096d6407fSRichard Henderson nullify_over(ctx); 166186f8d05fSRichard Henderson do_store_reg(ctx, load_gpr(ctx, rt), rb, 0, 0, disp, sp, modify, mop); 16621cd012a5SRichard Henderson return nullify_end(ctx); 166396d6407fSRichard Henderson } 166496d6407fSRichard Henderson 1665740038d7SRichard Henderson static bool do_fstorew(DisasContext *ctx, unsigned rt, unsigned rb, 1666eaa3783bSRichard Henderson unsigned rx, int scale, target_sreg disp, 166786f8d05fSRichard Henderson unsigned sp, int modify) 166896d6407fSRichard Henderson { 166996d6407fSRichard Henderson TCGv_i32 tmp; 167096d6407fSRichard Henderson 167196d6407fSRichard Henderson nullify_over(ctx); 167296d6407fSRichard Henderson 167396d6407fSRichard Henderson tmp = load_frw_i32(rt); 167486f8d05fSRichard Henderson do_store_32(ctx, tmp, rb, rx, scale, disp, sp, modify, MO_TEUL); 167596d6407fSRichard Henderson tcg_temp_free_i32(tmp); 167696d6407fSRichard Henderson 1677740038d7SRichard Henderson return nullify_end(ctx); 167896d6407fSRichard Henderson } 167996d6407fSRichard Henderson 1680740038d7SRichard Henderson static bool trans_fstw(DisasContext *ctx, arg_ldst *a) 1681740038d7SRichard Henderson { 1682740038d7SRichard Henderson return do_fstorew(ctx, a->t, a->b, a->x, a->scale ? 2 : 0, 1683740038d7SRichard Henderson a->disp, a->sp, a->m); 1684740038d7SRichard Henderson } 1685740038d7SRichard Henderson 1686740038d7SRichard Henderson static bool do_fstored(DisasContext *ctx, unsigned rt, unsigned rb, 1687eaa3783bSRichard Henderson unsigned rx, int scale, target_sreg disp, 168886f8d05fSRichard Henderson unsigned sp, int modify) 168996d6407fSRichard Henderson { 169096d6407fSRichard Henderson TCGv_i64 tmp; 169196d6407fSRichard Henderson 169296d6407fSRichard Henderson nullify_over(ctx); 169396d6407fSRichard Henderson 169496d6407fSRichard Henderson tmp = load_frd(rt); 169586f8d05fSRichard Henderson do_store_64(ctx, tmp, rb, rx, scale, disp, sp, modify, MO_TEQ); 169696d6407fSRichard Henderson tcg_temp_free_i64(tmp); 169796d6407fSRichard Henderson 1698740038d7SRichard Henderson return nullify_end(ctx); 1699740038d7SRichard Henderson } 1700740038d7SRichard Henderson 1701740038d7SRichard Henderson static bool trans_fstd(DisasContext *ctx, arg_ldst *a) 1702740038d7SRichard Henderson { 1703740038d7SRichard Henderson return do_fstored(ctx, a->t, a->b, a->x, a->scale ? 3 : 0, 1704740038d7SRichard Henderson a->disp, a->sp, a->m); 170596d6407fSRichard Henderson } 170696d6407fSRichard Henderson 17071ca74648SRichard Henderson static bool do_fop_wew(DisasContext *ctx, unsigned rt, unsigned ra, 1708ebe9383cSRichard Henderson void (*func)(TCGv_i32, TCGv_env, TCGv_i32)) 1709ebe9383cSRichard Henderson { 1710ebe9383cSRichard Henderson TCGv_i32 tmp; 1711ebe9383cSRichard Henderson 1712ebe9383cSRichard Henderson nullify_over(ctx); 1713ebe9383cSRichard Henderson tmp = load_frw0_i32(ra); 1714ebe9383cSRichard Henderson 1715ebe9383cSRichard Henderson func(tmp, cpu_env, tmp); 1716ebe9383cSRichard Henderson 1717ebe9383cSRichard Henderson save_frw_i32(rt, tmp); 1718ebe9383cSRichard Henderson tcg_temp_free_i32(tmp); 17191ca74648SRichard Henderson return nullify_end(ctx); 1720ebe9383cSRichard Henderson } 1721ebe9383cSRichard Henderson 17221ca74648SRichard Henderson static bool do_fop_wed(DisasContext *ctx, unsigned rt, unsigned ra, 1723ebe9383cSRichard Henderson void (*func)(TCGv_i32, TCGv_env, TCGv_i64)) 1724ebe9383cSRichard Henderson { 1725ebe9383cSRichard Henderson TCGv_i32 dst; 1726ebe9383cSRichard Henderson TCGv_i64 src; 1727ebe9383cSRichard Henderson 1728ebe9383cSRichard Henderson nullify_over(ctx); 1729ebe9383cSRichard Henderson src = load_frd(ra); 1730ebe9383cSRichard Henderson dst = tcg_temp_new_i32(); 1731ebe9383cSRichard Henderson 1732ebe9383cSRichard Henderson func(dst, cpu_env, src); 1733ebe9383cSRichard Henderson 1734ebe9383cSRichard Henderson tcg_temp_free_i64(src); 1735ebe9383cSRichard Henderson save_frw_i32(rt, dst); 1736ebe9383cSRichard Henderson tcg_temp_free_i32(dst); 17371ca74648SRichard Henderson return nullify_end(ctx); 1738ebe9383cSRichard Henderson } 1739ebe9383cSRichard Henderson 17401ca74648SRichard Henderson static bool do_fop_ded(DisasContext *ctx, unsigned rt, unsigned ra, 1741ebe9383cSRichard Henderson void (*func)(TCGv_i64, TCGv_env, TCGv_i64)) 1742ebe9383cSRichard Henderson { 1743ebe9383cSRichard Henderson TCGv_i64 tmp; 1744ebe9383cSRichard Henderson 1745ebe9383cSRichard Henderson nullify_over(ctx); 1746ebe9383cSRichard Henderson tmp = load_frd0(ra); 1747ebe9383cSRichard Henderson 1748ebe9383cSRichard Henderson func(tmp, cpu_env, tmp); 1749ebe9383cSRichard Henderson 1750ebe9383cSRichard Henderson save_frd(rt, tmp); 1751ebe9383cSRichard Henderson tcg_temp_free_i64(tmp); 17521ca74648SRichard Henderson return nullify_end(ctx); 1753ebe9383cSRichard Henderson } 1754ebe9383cSRichard Henderson 17551ca74648SRichard Henderson static bool do_fop_dew(DisasContext *ctx, unsigned rt, unsigned ra, 1756ebe9383cSRichard Henderson void (*func)(TCGv_i64, TCGv_env, TCGv_i32)) 1757ebe9383cSRichard Henderson { 1758ebe9383cSRichard Henderson TCGv_i32 src; 1759ebe9383cSRichard Henderson TCGv_i64 dst; 1760ebe9383cSRichard Henderson 1761ebe9383cSRichard Henderson nullify_over(ctx); 1762ebe9383cSRichard Henderson src = load_frw0_i32(ra); 1763ebe9383cSRichard Henderson dst = tcg_temp_new_i64(); 1764ebe9383cSRichard Henderson 1765ebe9383cSRichard Henderson func(dst, cpu_env, src); 1766ebe9383cSRichard Henderson 1767ebe9383cSRichard Henderson tcg_temp_free_i32(src); 1768ebe9383cSRichard Henderson save_frd(rt, dst); 1769ebe9383cSRichard Henderson tcg_temp_free_i64(dst); 17701ca74648SRichard Henderson return nullify_end(ctx); 1771ebe9383cSRichard Henderson } 1772ebe9383cSRichard Henderson 17731ca74648SRichard Henderson static bool do_fop_weww(DisasContext *ctx, unsigned rt, 1774ebe9383cSRichard Henderson unsigned ra, unsigned rb, 177531234768SRichard Henderson void (*func)(TCGv_i32, TCGv_env, TCGv_i32, TCGv_i32)) 1776ebe9383cSRichard Henderson { 1777ebe9383cSRichard Henderson TCGv_i32 a, b; 1778ebe9383cSRichard Henderson 1779ebe9383cSRichard Henderson nullify_over(ctx); 1780ebe9383cSRichard Henderson a = load_frw0_i32(ra); 1781ebe9383cSRichard Henderson b = load_frw0_i32(rb); 1782ebe9383cSRichard Henderson 1783ebe9383cSRichard Henderson func(a, cpu_env, a, b); 1784ebe9383cSRichard Henderson 1785ebe9383cSRichard Henderson tcg_temp_free_i32(b); 1786ebe9383cSRichard Henderson save_frw_i32(rt, a); 1787ebe9383cSRichard Henderson tcg_temp_free_i32(a); 17881ca74648SRichard Henderson return nullify_end(ctx); 1789ebe9383cSRichard Henderson } 1790ebe9383cSRichard Henderson 17911ca74648SRichard Henderson static bool do_fop_dedd(DisasContext *ctx, unsigned rt, 1792ebe9383cSRichard Henderson unsigned ra, unsigned rb, 179331234768SRichard Henderson void (*func)(TCGv_i64, TCGv_env, TCGv_i64, TCGv_i64)) 1794ebe9383cSRichard Henderson { 1795ebe9383cSRichard Henderson TCGv_i64 a, b; 1796ebe9383cSRichard Henderson 1797ebe9383cSRichard Henderson nullify_over(ctx); 1798ebe9383cSRichard Henderson a = load_frd0(ra); 1799ebe9383cSRichard Henderson b = load_frd0(rb); 1800ebe9383cSRichard Henderson 1801ebe9383cSRichard Henderson func(a, cpu_env, a, b); 1802ebe9383cSRichard Henderson 1803ebe9383cSRichard Henderson tcg_temp_free_i64(b); 1804ebe9383cSRichard Henderson save_frd(rt, a); 1805ebe9383cSRichard Henderson tcg_temp_free_i64(a); 18061ca74648SRichard Henderson return nullify_end(ctx); 1807ebe9383cSRichard Henderson } 1808ebe9383cSRichard Henderson 180998cd9ca7SRichard Henderson /* Emit an unconditional branch to a direct target, which may or may not 181098cd9ca7SRichard Henderson have already had nullification handled. */ 181101afb7beSRichard Henderson static bool do_dbranch(DisasContext *ctx, target_ureg dest, 181298cd9ca7SRichard Henderson unsigned link, bool is_n) 181398cd9ca7SRichard Henderson { 181498cd9ca7SRichard Henderson if (ctx->null_cond.c == TCG_COND_NEVER && ctx->null_lab == NULL) { 181598cd9ca7SRichard Henderson if (link != 0) { 181698cd9ca7SRichard Henderson copy_iaoq_entry(cpu_gr[link], ctx->iaoq_n, ctx->iaoq_n_var); 181798cd9ca7SRichard Henderson } 181898cd9ca7SRichard Henderson ctx->iaoq_n = dest; 181998cd9ca7SRichard Henderson if (is_n) { 182098cd9ca7SRichard Henderson ctx->null_cond.c = TCG_COND_ALWAYS; 182198cd9ca7SRichard Henderson } 182298cd9ca7SRichard Henderson } else { 182398cd9ca7SRichard Henderson nullify_over(ctx); 182498cd9ca7SRichard Henderson 182598cd9ca7SRichard Henderson if (link != 0) { 182698cd9ca7SRichard Henderson copy_iaoq_entry(cpu_gr[link], ctx->iaoq_n, ctx->iaoq_n_var); 182798cd9ca7SRichard Henderson } 182898cd9ca7SRichard Henderson 182998cd9ca7SRichard Henderson if (is_n && use_nullify_skip(ctx)) { 183098cd9ca7SRichard Henderson nullify_set(ctx, 0); 183198cd9ca7SRichard Henderson gen_goto_tb(ctx, 0, dest, dest + 4); 183298cd9ca7SRichard Henderson } else { 183398cd9ca7SRichard Henderson nullify_set(ctx, is_n); 183498cd9ca7SRichard Henderson gen_goto_tb(ctx, 0, ctx->iaoq_b, dest); 183598cd9ca7SRichard Henderson } 183698cd9ca7SRichard Henderson 183731234768SRichard Henderson nullify_end(ctx); 183898cd9ca7SRichard Henderson 183998cd9ca7SRichard Henderson nullify_set(ctx, 0); 184098cd9ca7SRichard Henderson gen_goto_tb(ctx, 1, ctx->iaoq_b, ctx->iaoq_n); 184131234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 184298cd9ca7SRichard Henderson } 184301afb7beSRichard Henderson return true; 184498cd9ca7SRichard Henderson } 184598cd9ca7SRichard Henderson 184698cd9ca7SRichard Henderson /* Emit a conditional branch to a direct target. If the branch itself 184798cd9ca7SRichard Henderson is nullified, we should have already used nullify_over. */ 184801afb7beSRichard Henderson static bool do_cbranch(DisasContext *ctx, target_sreg disp, bool is_n, 184998cd9ca7SRichard Henderson DisasCond *cond) 185098cd9ca7SRichard Henderson { 1851eaa3783bSRichard Henderson target_ureg dest = iaoq_dest(ctx, disp); 185298cd9ca7SRichard Henderson TCGLabel *taken = NULL; 185398cd9ca7SRichard Henderson TCGCond c = cond->c; 185498cd9ca7SRichard Henderson bool n; 185598cd9ca7SRichard Henderson 185698cd9ca7SRichard Henderson assert(ctx->null_cond.c == TCG_COND_NEVER); 185798cd9ca7SRichard Henderson 185898cd9ca7SRichard Henderson /* Handle TRUE and NEVER as direct branches. */ 185998cd9ca7SRichard Henderson if (c == TCG_COND_ALWAYS) { 186001afb7beSRichard Henderson return do_dbranch(ctx, dest, 0, is_n && disp >= 0); 186198cd9ca7SRichard Henderson } 186298cd9ca7SRichard Henderson if (c == TCG_COND_NEVER) { 186301afb7beSRichard Henderson return do_dbranch(ctx, ctx->iaoq_n, 0, is_n && disp < 0); 186498cd9ca7SRichard Henderson } 186598cd9ca7SRichard Henderson 186698cd9ca7SRichard Henderson taken = gen_new_label(); 186798cd9ca7SRichard Henderson cond_prep(cond); 1868eaa3783bSRichard Henderson tcg_gen_brcond_reg(c, cond->a0, cond->a1, taken); 186998cd9ca7SRichard Henderson cond_free(cond); 187098cd9ca7SRichard Henderson 187198cd9ca7SRichard Henderson /* Not taken: Condition not satisfied; nullify on backward branches. */ 187298cd9ca7SRichard Henderson n = is_n && disp < 0; 187398cd9ca7SRichard Henderson if (n && use_nullify_skip(ctx)) { 187498cd9ca7SRichard Henderson nullify_set(ctx, 0); 1875a881c8e7SRichard Henderson gen_goto_tb(ctx, 0, ctx->iaoq_n, ctx->iaoq_n + 4); 187698cd9ca7SRichard Henderson } else { 187798cd9ca7SRichard Henderson if (!n && ctx->null_lab) { 187898cd9ca7SRichard Henderson gen_set_label(ctx->null_lab); 187998cd9ca7SRichard Henderson ctx->null_lab = NULL; 188098cd9ca7SRichard Henderson } 188198cd9ca7SRichard Henderson nullify_set(ctx, n); 1882c301f34eSRichard Henderson if (ctx->iaoq_n == -1) { 1883c301f34eSRichard Henderson /* The temporary iaoq_n_var died at the branch above. 1884c301f34eSRichard Henderson Regenerate it here instead of saving it. */ 1885c301f34eSRichard Henderson tcg_gen_addi_reg(ctx->iaoq_n_var, cpu_iaoq_b, 4); 1886c301f34eSRichard Henderson } 1887a881c8e7SRichard Henderson gen_goto_tb(ctx, 0, ctx->iaoq_b, ctx->iaoq_n); 188898cd9ca7SRichard Henderson } 188998cd9ca7SRichard Henderson 189098cd9ca7SRichard Henderson gen_set_label(taken); 189198cd9ca7SRichard Henderson 189298cd9ca7SRichard Henderson /* Taken: Condition satisfied; nullify on forward branches. */ 189398cd9ca7SRichard Henderson n = is_n && disp >= 0; 189498cd9ca7SRichard Henderson if (n && use_nullify_skip(ctx)) { 189598cd9ca7SRichard Henderson nullify_set(ctx, 0); 1896a881c8e7SRichard Henderson gen_goto_tb(ctx, 1, dest, dest + 4); 189798cd9ca7SRichard Henderson } else { 189898cd9ca7SRichard Henderson nullify_set(ctx, n); 1899a881c8e7SRichard Henderson gen_goto_tb(ctx, 1, ctx->iaoq_b, dest); 190098cd9ca7SRichard Henderson } 190198cd9ca7SRichard Henderson 190298cd9ca7SRichard Henderson /* Not taken: the branch itself was nullified. */ 190398cd9ca7SRichard Henderson if (ctx->null_lab) { 190498cd9ca7SRichard Henderson gen_set_label(ctx->null_lab); 190598cd9ca7SRichard Henderson ctx->null_lab = NULL; 190631234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE; 190798cd9ca7SRichard Henderson } else { 190831234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 190998cd9ca7SRichard Henderson } 191001afb7beSRichard Henderson return true; 191198cd9ca7SRichard Henderson } 191298cd9ca7SRichard Henderson 191398cd9ca7SRichard Henderson /* Emit an unconditional branch to an indirect target. This handles 191498cd9ca7SRichard Henderson nullification of the branch itself. */ 191501afb7beSRichard Henderson static bool do_ibranch(DisasContext *ctx, TCGv_reg dest, 191698cd9ca7SRichard Henderson unsigned link, bool is_n) 191798cd9ca7SRichard Henderson { 1918eaa3783bSRichard Henderson TCGv_reg a0, a1, next, tmp; 191998cd9ca7SRichard Henderson TCGCond c; 192098cd9ca7SRichard Henderson 192198cd9ca7SRichard Henderson assert(ctx->null_lab == NULL); 192298cd9ca7SRichard Henderson 192398cd9ca7SRichard Henderson if (ctx->null_cond.c == TCG_COND_NEVER) { 192498cd9ca7SRichard Henderson if (link != 0) { 192598cd9ca7SRichard Henderson copy_iaoq_entry(cpu_gr[link], ctx->iaoq_n, ctx->iaoq_n_var); 192698cd9ca7SRichard Henderson } 192798cd9ca7SRichard Henderson next = get_temp(ctx); 1928eaa3783bSRichard Henderson tcg_gen_mov_reg(next, dest); 192998cd9ca7SRichard Henderson if (is_n) { 1930c301f34eSRichard Henderson if (use_nullify_skip(ctx)) { 1931c301f34eSRichard Henderson tcg_gen_mov_reg(cpu_iaoq_f, next); 1932c301f34eSRichard Henderson tcg_gen_addi_reg(cpu_iaoq_b, next, 4); 1933c301f34eSRichard Henderson nullify_set(ctx, 0); 193431234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_UPDATED; 193501afb7beSRichard Henderson return true; 1936c301f34eSRichard Henderson } 193798cd9ca7SRichard Henderson ctx->null_cond.c = TCG_COND_ALWAYS; 193898cd9ca7SRichard Henderson } 1939c301f34eSRichard Henderson ctx->iaoq_n = -1; 1940c301f34eSRichard Henderson ctx->iaoq_n_var = next; 194198cd9ca7SRichard Henderson } else if (is_n && use_nullify_skip(ctx)) { 194298cd9ca7SRichard Henderson /* The (conditional) branch, B, nullifies the next insn, N, 194398cd9ca7SRichard Henderson and we're allowed to skip execution N (no single-step or 19444137cb83SRichard Henderson tracepoint in effect). Since the goto_ptr that we must use 194598cd9ca7SRichard Henderson for the indirect branch consumes no special resources, we 194698cd9ca7SRichard Henderson can (conditionally) skip B and continue execution. */ 194798cd9ca7SRichard Henderson /* The use_nullify_skip test implies we have a known control path. */ 194898cd9ca7SRichard Henderson tcg_debug_assert(ctx->iaoq_b != -1); 194998cd9ca7SRichard Henderson tcg_debug_assert(ctx->iaoq_n != -1); 195098cd9ca7SRichard Henderson 195198cd9ca7SRichard Henderson /* We do have to handle the non-local temporary, DEST, before 195298cd9ca7SRichard Henderson branching. Since IOAQ_F is not really live at this point, we 195398cd9ca7SRichard Henderson can simply store DEST optimistically. Similarly with IAOQ_B. */ 1954eaa3783bSRichard Henderson tcg_gen_mov_reg(cpu_iaoq_f, dest); 1955eaa3783bSRichard Henderson tcg_gen_addi_reg(cpu_iaoq_b, dest, 4); 195698cd9ca7SRichard Henderson 195798cd9ca7SRichard Henderson nullify_over(ctx); 195898cd9ca7SRichard Henderson if (link != 0) { 1959eaa3783bSRichard Henderson tcg_gen_movi_reg(cpu_gr[link], ctx->iaoq_n); 196098cd9ca7SRichard Henderson } 19617f11636dSEmilio G. Cota tcg_gen_lookup_and_goto_ptr(); 196201afb7beSRichard Henderson return nullify_end(ctx); 196398cd9ca7SRichard Henderson } else { 196498cd9ca7SRichard Henderson cond_prep(&ctx->null_cond); 196598cd9ca7SRichard Henderson c = ctx->null_cond.c; 196698cd9ca7SRichard Henderson a0 = ctx->null_cond.a0; 196798cd9ca7SRichard Henderson a1 = ctx->null_cond.a1; 196898cd9ca7SRichard Henderson 196998cd9ca7SRichard Henderson tmp = tcg_temp_new(); 197098cd9ca7SRichard Henderson next = get_temp(ctx); 197198cd9ca7SRichard Henderson 197298cd9ca7SRichard Henderson copy_iaoq_entry(tmp, ctx->iaoq_n, ctx->iaoq_n_var); 1973eaa3783bSRichard Henderson tcg_gen_movcond_reg(c, next, a0, a1, tmp, dest); 197498cd9ca7SRichard Henderson ctx->iaoq_n = -1; 197598cd9ca7SRichard Henderson ctx->iaoq_n_var = next; 197698cd9ca7SRichard Henderson 197798cd9ca7SRichard Henderson if (link != 0) { 1978eaa3783bSRichard Henderson tcg_gen_movcond_reg(c, cpu_gr[link], a0, a1, cpu_gr[link], tmp); 197998cd9ca7SRichard Henderson } 198098cd9ca7SRichard Henderson 198198cd9ca7SRichard Henderson if (is_n) { 198298cd9ca7SRichard Henderson /* The branch nullifies the next insn, which means the state of N 198398cd9ca7SRichard Henderson after the branch is the inverse of the state of N that applied 198498cd9ca7SRichard Henderson to the branch. */ 1985eaa3783bSRichard Henderson tcg_gen_setcond_reg(tcg_invert_cond(c), cpu_psw_n, a0, a1); 198698cd9ca7SRichard Henderson cond_free(&ctx->null_cond); 198798cd9ca7SRichard Henderson ctx->null_cond = cond_make_n(); 198898cd9ca7SRichard Henderson ctx->psw_n_nonzero = true; 198998cd9ca7SRichard Henderson } else { 199098cd9ca7SRichard Henderson cond_free(&ctx->null_cond); 199198cd9ca7SRichard Henderson } 199298cd9ca7SRichard Henderson } 199301afb7beSRichard Henderson return true; 199498cd9ca7SRichard Henderson } 199598cd9ca7SRichard Henderson 1996660eefe1SRichard Henderson /* Implement 1997660eefe1SRichard Henderson * if (IAOQ_Front{30..31} < GR[b]{30..31}) 1998660eefe1SRichard Henderson * IAOQ_Next{30..31} ← GR[b]{30..31}; 1999660eefe1SRichard Henderson * else 2000660eefe1SRichard Henderson * IAOQ_Next{30..31} ← IAOQ_Front{30..31}; 2001660eefe1SRichard Henderson * which keeps the privilege level from being increased. 2002660eefe1SRichard Henderson */ 2003660eefe1SRichard Henderson static TCGv_reg do_ibranch_priv(DisasContext *ctx, TCGv_reg offset) 2004660eefe1SRichard Henderson { 2005660eefe1SRichard Henderson TCGv_reg dest; 2006660eefe1SRichard Henderson switch (ctx->privilege) { 2007660eefe1SRichard Henderson case 0: 2008660eefe1SRichard Henderson /* Privilege 0 is maximum and is allowed to decrease. */ 2009660eefe1SRichard Henderson return offset; 2010660eefe1SRichard Henderson case 3: 2011993119feSRichard Henderson /* Privilege 3 is minimum and is never allowed to increase. */ 2012660eefe1SRichard Henderson dest = get_temp(ctx); 2013660eefe1SRichard Henderson tcg_gen_ori_reg(dest, offset, 3); 2014660eefe1SRichard Henderson break; 2015660eefe1SRichard Henderson default: 2016993119feSRichard Henderson dest = get_temp(ctx); 2017660eefe1SRichard Henderson tcg_gen_andi_reg(dest, offset, -4); 2018660eefe1SRichard Henderson tcg_gen_ori_reg(dest, dest, ctx->privilege); 2019660eefe1SRichard Henderson tcg_gen_movcond_reg(TCG_COND_GTU, dest, dest, offset, dest, offset); 2020660eefe1SRichard Henderson break; 2021660eefe1SRichard Henderson } 2022660eefe1SRichard Henderson return dest; 2023660eefe1SRichard Henderson } 2024660eefe1SRichard Henderson 2025ba1d0b44SRichard Henderson #ifdef CONFIG_USER_ONLY 20267ad439dfSRichard Henderson /* On Linux, page zero is normally marked execute only + gateway. 20277ad439dfSRichard Henderson Therefore normal read or write is supposed to fail, but specific 20287ad439dfSRichard Henderson offsets have kernel code mapped to raise permissions to implement 20297ad439dfSRichard Henderson system calls. Handling this via an explicit check here, rather 20307ad439dfSRichard Henderson in than the "be disp(sr2,r0)" instruction that probably sent us 20317ad439dfSRichard Henderson here, is the easiest way to handle the branch delay slot on the 20327ad439dfSRichard Henderson aforementioned BE. */ 203331234768SRichard Henderson static void do_page_zero(DisasContext *ctx) 20347ad439dfSRichard Henderson { 20357ad439dfSRichard Henderson /* If by some means we get here with PSW[N]=1, that implies that 20367ad439dfSRichard Henderson the B,GATE instruction would be skipped, and we'd fault on the 20377ad439dfSRichard Henderson next insn within the privilaged page. */ 20387ad439dfSRichard Henderson switch (ctx->null_cond.c) { 20397ad439dfSRichard Henderson case TCG_COND_NEVER: 20407ad439dfSRichard Henderson break; 20417ad439dfSRichard Henderson case TCG_COND_ALWAYS: 2042eaa3783bSRichard Henderson tcg_gen_movi_reg(cpu_psw_n, 0); 20437ad439dfSRichard Henderson goto do_sigill; 20447ad439dfSRichard Henderson default: 20457ad439dfSRichard Henderson /* Since this is always the first (and only) insn within the 20467ad439dfSRichard Henderson TB, we should know the state of PSW[N] from TB->FLAGS. */ 20477ad439dfSRichard Henderson g_assert_not_reached(); 20487ad439dfSRichard Henderson } 20497ad439dfSRichard Henderson 20507ad439dfSRichard Henderson /* Check that we didn't arrive here via some means that allowed 20517ad439dfSRichard Henderson non-sequential instruction execution. Normally the PSW[B] bit 20527ad439dfSRichard Henderson detects this by disallowing the B,GATE instruction to execute 20537ad439dfSRichard Henderson under such conditions. */ 20547ad439dfSRichard Henderson if (ctx->iaoq_b != ctx->iaoq_f + 4) { 20557ad439dfSRichard Henderson goto do_sigill; 20567ad439dfSRichard Henderson } 20577ad439dfSRichard Henderson 2058ebd0e151SRichard Henderson switch (ctx->iaoq_f & -4) { 20597ad439dfSRichard Henderson case 0x00: /* Null pointer call */ 20602986721dSRichard Henderson gen_excp_1(EXCP_IMP); 206131234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 206231234768SRichard Henderson break; 20637ad439dfSRichard Henderson 20647ad439dfSRichard Henderson case 0xb0: /* LWS */ 20657ad439dfSRichard Henderson gen_excp_1(EXCP_SYSCALL_LWS); 206631234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 206731234768SRichard Henderson break; 20687ad439dfSRichard Henderson 20697ad439dfSRichard Henderson case 0xe0: /* SET_THREAD_POINTER */ 207035136a77SRichard Henderson tcg_gen_st_reg(cpu_gr[26], cpu_env, offsetof(CPUHPPAState, cr[27])); 2071ebd0e151SRichard Henderson tcg_gen_ori_reg(cpu_iaoq_f, cpu_gr[31], 3); 2072eaa3783bSRichard Henderson tcg_gen_addi_reg(cpu_iaoq_b, cpu_iaoq_f, 4); 207331234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_UPDATED; 207431234768SRichard Henderson break; 20757ad439dfSRichard Henderson 20767ad439dfSRichard Henderson case 0x100: /* SYSCALL */ 20777ad439dfSRichard Henderson gen_excp_1(EXCP_SYSCALL); 207831234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 207931234768SRichard Henderson break; 20807ad439dfSRichard Henderson 20817ad439dfSRichard Henderson default: 20827ad439dfSRichard Henderson do_sigill: 20832986721dSRichard Henderson gen_excp_1(EXCP_ILL); 208431234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 208531234768SRichard Henderson break; 20867ad439dfSRichard Henderson } 20877ad439dfSRichard Henderson } 2088ba1d0b44SRichard Henderson #endif 20897ad439dfSRichard Henderson 2090deee69a1SRichard Henderson static bool trans_nop(DisasContext *ctx, arg_nop *a) 2091b2167459SRichard Henderson { 2092b2167459SRichard Henderson cond_free(&ctx->null_cond); 209331234768SRichard Henderson return true; 2094b2167459SRichard Henderson } 2095b2167459SRichard Henderson 209640f9f908SRichard Henderson static bool trans_break(DisasContext *ctx, arg_break *a) 209798a9cb79SRichard Henderson { 209831234768SRichard Henderson return gen_excp_iir(ctx, EXCP_BREAK); 209998a9cb79SRichard Henderson } 210098a9cb79SRichard Henderson 2101e36f27efSRichard Henderson static bool trans_sync(DisasContext *ctx, arg_sync *a) 210298a9cb79SRichard Henderson { 210398a9cb79SRichard Henderson /* No point in nullifying the memory barrier. */ 210498a9cb79SRichard Henderson tcg_gen_mb(TCG_BAR_SC | TCG_MO_ALL); 210598a9cb79SRichard Henderson 210698a9cb79SRichard Henderson cond_free(&ctx->null_cond); 210731234768SRichard Henderson return true; 210898a9cb79SRichard Henderson } 210998a9cb79SRichard Henderson 2110c603e14aSRichard Henderson static bool trans_mfia(DisasContext *ctx, arg_mfia *a) 211198a9cb79SRichard Henderson { 2112c603e14aSRichard Henderson unsigned rt = a->t; 2113eaa3783bSRichard Henderson TCGv_reg tmp = dest_gpr(ctx, rt); 2114eaa3783bSRichard Henderson tcg_gen_movi_reg(tmp, ctx->iaoq_f); 211598a9cb79SRichard Henderson save_gpr(ctx, rt, tmp); 211698a9cb79SRichard Henderson 211798a9cb79SRichard Henderson cond_free(&ctx->null_cond); 211831234768SRichard Henderson return true; 211998a9cb79SRichard Henderson } 212098a9cb79SRichard Henderson 2121c603e14aSRichard Henderson static bool trans_mfsp(DisasContext *ctx, arg_mfsp *a) 212298a9cb79SRichard Henderson { 2123c603e14aSRichard Henderson unsigned rt = a->t; 2124c603e14aSRichard Henderson unsigned rs = a->sp; 212533423472SRichard Henderson TCGv_i64 t0 = tcg_temp_new_i64(); 212633423472SRichard Henderson TCGv_reg t1 = tcg_temp_new(); 212798a9cb79SRichard Henderson 212833423472SRichard Henderson load_spr(ctx, t0, rs); 212933423472SRichard Henderson tcg_gen_shri_i64(t0, t0, 32); 213033423472SRichard Henderson tcg_gen_trunc_i64_reg(t1, t0); 213133423472SRichard Henderson 213233423472SRichard Henderson save_gpr(ctx, rt, t1); 213333423472SRichard Henderson tcg_temp_free(t1); 213433423472SRichard Henderson tcg_temp_free_i64(t0); 213598a9cb79SRichard Henderson 213698a9cb79SRichard Henderson cond_free(&ctx->null_cond); 213731234768SRichard Henderson return true; 213898a9cb79SRichard Henderson } 213998a9cb79SRichard Henderson 2140c603e14aSRichard Henderson static bool trans_mfctl(DisasContext *ctx, arg_mfctl *a) 214198a9cb79SRichard Henderson { 2142c603e14aSRichard Henderson unsigned rt = a->t; 2143c603e14aSRichard Henderson unsigned ctl = a->r; 2144eaa3783bSRichard Henderson TCGv_reg tmp; 214598a9cb79SRichard Henderson 214698a9cb79SRichard Henderson switch (ctl) { 214735136a77SRichard Henderson case CR_SAR: 214898a9cb79SRichard Henderson #ifdef TARGET_HPPA64 2149c603e14aSRichard Henderson if (a->e == 0) { 215098a9cb79SRichard Henderson /* MFSAR without ,W masks low 5 bits. */ 215198a9cb79SRichard Henderson tmp = dest_gpr(ctx, rt); 2152eaa3783bSRichard Henderson tcg_gen_andi_reg(tmp, cpu_sar, 31); 215398a9cb79SRichard Henderson save_gpr(ctx, rt, tmp); 215435136a77SRichard Henderson goto done; 215598a9cb79SRichard Henderson } 215698a9cb79SRichard Henderson #endif 215798a9cb79SRichard Henderson save_gpr(ctx, rt, cpu_sar); 215835136a77SRichard Henderson goto done; 215935136a77SRichard Henderson case CR_IT: /* Interval Timer */ 216035136a77SRichard Henderson /* FIXME: Respect PSW_S bit. */ 216135136a77SRichard Henderson nullify_over(ctx); 216298a9cb79SRichard Henderson tmp = dest_gpr(ctx, rt); 216384b41e65SEmilio G. Cota if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) { 216449c29d6cSRichard Henderson gen_io_start(); 216549c29d6cSRichard Henderson gen_helper_read_interval_timer(tmp); 216631234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE; 216749c29d6cSRichard Henderson } else { 216849c29d6cSRichard Henderson gen_helper_read_interval_timer(tmp); 216949c29d6cSRichard Henderson } 217098a9cb79SRichard Henderson save_gpr(ctx, rt, tmp); 217131234768SRichard Henderson return nullify_end(ctx); 217298a9cb79SRichard Henderson case 26: 217398a9cb79SRichard Henderson case 27: 217498a9cb79SRichard Henderson break; 217598a9cb79SRichard Henderson default: 217698a9cb79SRichard Henderson /* All other control registers are privileged. */ 217735136a77SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_REG); 217835136a77SRichard Henderson break; 217998a9cb79SRichard Henderson } 218098a9cb79SRichard Henderson 218135136a77SRichard Henderson tmp = get_temp(ctx); 218235136a77SRichard Henderson tcg_gen_ld_reg(tmp, cpu_env, offsetof(CPUHPPAState, cr[ctl])); 218335136a77SRichard Henderson save_gpr(ctx, rt, tmp); 218435136a77SRichard Henderson 218535136a77SRichard Henderson done: 218698a9cb79SRichard Henderson cond_free(&ctx->null_cond); 218731234768SRichard Henderson return true; 218898a9cb79SRichard Henderson } 218998a9cb79SRichard Henderson 2190c603e14aSRichard Henderson static bool trans_mtsp(DisasContext *ctx, arg_mtsp *a) 219133423472SRichard Henderson { 2192c603e14aSRichard Henderson unsigned rr = a->r; 2193c603e14aSRichard Henderson unsigned rs = a->sp; 219433423472SRichard Henderson TCGv_i64 t64; 219533423472SRichard Henderson 219633423472SRichard Henderson if (rs >= 5) { 219733423472SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_REG); 219833423472SRichard Henderson } 219933423472SRichard Henderson nullify_over(ctx); 220033423472SRichard Henderson 220133423472SRichard Henderson t64 = tcg_temp_new_i64(); 220233423472SRichard Henderson tcg_gen_extu_reg_i64(t64, load_gpr(ctx, rr)); 220333423472SRichard Henderson tcg_gen_shli_i64(t64, t64, 32); 220433423472SRichard Henderson 220533423472SRichard Henderson if (rs >= 4) { 220633423472SRichard Henderson tcg_gen_st_i64(t64, cpu_env, offsetof(CPUHPPAState, sr[rs])); 2207494737b7SRichard Henderson ctx->tb_flags &= ~TB_FLAG_SR_SAME; 220833423472SRichard Henderson } else { 220933423472SRichard Henderson tcg_gen_mov_i64(cpu_sr[rs], t64); 221033423472SRichard Henderson } 221133423472SRichard Henderson tcg_temp_free_i64(t64); 221233423472SRichard Henderson 221331234768SRichard Henderson return nullify_end(ctx); 221433423472SRichard Henderson } 221533423472SRichard Henderson 2216c603e14aSRichard Henderson static bool trans_mtctl(DisasContext *ctx, arg_mtctl *a) 221798a9cb79SRichard Henderson { 2218c603e14aSRichard Henderson unsigned ctl = a->t; 22194845f015SSven Schnelle TCGv_reg reg; 2220eaa3783bSRichard Henderson TCGv_reg tmp; 222198a9cb79SRichard Henderson 222235136a77SRichard Henderson if (ctl == CR_SAR) { 22234845f015SSven Schnelle reg = load_gpr(ctx, a->r); 222498a9cb79SRichard Henderson tmp = tcg_temp_new(); 222535136a77SRichard Henderson tcg_gen_andi_reg(tmp, reg, TARGET_REGISTER_BITS - 1); 222698a9cb79SRichard Henderson save_or_nullify(ctx, cpu_sar, tmp); 222798a9cb79SRichard Henderson tcg_temp_free(tmp); 222898a9cb79SRichard Henderson 222998a9cb79SRichard Henderson cond_free(&ctx->null_cond); 223031234768SRichard Henderson return true; 223198a9cb79SRichard Henderson } 223298a9cb79SRichard Henderson 223335136a77SRichard Henderson /* All other control registers are privileged or read-only. */ 223435136a77SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_REG); 223535136a77SRichard Henderson 2236c603e14aSRichard Henderson #ifndef CONFIG_USER_ONLY 223735136a77SRichard Henderson nullify_over(ctx); 22384845f015SSven Schnelle reg = load_gpr(ctx, a->r); 22394845f015SSven Schnelle 224035136a77SRichard Henderson switch (ctl) { 224135136a77SRichard Henderson case CR_IT: 224249c29d6cSRichard Henderson gen_helper_write_interval_timer(cpu_env, reg); 224335136a77SRichard Henderson break; 22444f5f2548SRichard Henderson case CR_EIRR: 22454f5f2548SRichard Henderson gen_helper_write_eirr(cpu_env, reg); 22464f5f2548SRichard Henderson break; 22474f5f2548SRichard Henderson case CR_EIEM: 22484f5f2548SRichard Henderson gen_helper_write_eiem(cpu_env, reg); 224931234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE_EXIT; 22504f5f2548SRichard Henderson break; 22514f5f2548SRichard Henderson 225235136a77SRichard Henderson case CR_IIASQ: 225335136a77SRichard Henderson case CR_IIAOQ: 225435136a77SRichard Henderson /* FIXME: Respect PSW_Q bit */ 225535136a77SRichard Henderson /* The write advances the queue and stores to the back element. */ 225635136a77SRichard Henderson tmp = get_temp(ctx); 225735136a77SRichard Henderson tcg_gen_ld_reg(tmp, cpu_env, 225835136a77SRichard Henderson offsetof(CPUHPPAState, cr_back[ctl - CR_IIASQ])); 225935136a77SRichard Henderson tcg_gen_st_reg(tmp, cpu_env, offsetof(CPUHPPAState, cr[ctl])); 226035136a77SRichard Henderson tcg_gen_st_reg(reg, cpu_env, 226135136a77SRichard Henderson offsetof(CPUHPPAState, cr_back[ctl - CR_IIASQ])); 226235136a77SRichard Henderson break; 226335136a77SRichard Henderson 2264d5de20bdSSven Schnelle case CR_PID1: 2265d5de20bdSSven Schnelle case CR_PID2: 2266d5de20bdSSven Schnelle case CR_PID3: 2267d5de20bdSSven Schnelle case CR_PID4: 2268d5de20bdSSven Schnelle tcg_gen_st_reg(reg, cpu_env, offsetof(CPUHPPAState, cr[ctl])); 2269d5de20bdSSven Schnelle #ifndef CONFIG_USER_ONLY 2270d5de20bdSSven Schnelle gen_helper_change_prot_id(cpu_env); 2271d5de20bdSSven Schnelle #endif 2272d5de20bdSSven Schnelle break; 2273d5de20bdSSven Schnelle 227435136a77SRichard Henderson default: 227535136a77SRichard Henderson tcg_gen_st_reg(reg, cpu_env, offsetof(CPUHPPAState, cr[ctl])); 227635136a77SRichard Henderson break; 227735136a77SRichard Henderson } 227831234768SRichard Henderson return nullify_end(ctx); 22794f5f2548SRichard Henderson #endif 228035136a77SRichard Henderson } 228135136a77SRichard Henderson 2282c603e14aSRichard Henderson static bool trans_mtsarcm(DisasContext *ctx, arg_mtsarcm *a) 228398a9cb79SRichard Henderson { 2284eaa3783bSRichard Henderson TCGv_reg tmp = tcg_temp_new(); 228598a9cb79SRichard Henderson 2286c603e14aSRichard Henderson tcg_gen_not_reg(tmp, load_gpr(ctx, a->r)); 2287eaa3783bSRichard Henderson tcg_gen_andi_reg(tmp, tmp, TARGET_REGISTER_BITS - 1); 228898a9cb79SRichard Henderson save_or_nullify(ctx, cpu_sar, tmp); 228998a9cb79SRichard Henderson tcg_temp_free(tmp); 229098a9cb79SRichard Henderson 229198a9cb79SRichard Henderson cond_free(&ctx->null_cond); 229231234768SRichard Henderson return true; 229398a9cb79SRichard Henderson } 229498a9cb79SRichard Henderson 2295e36f27efSRichard Henderson static bool trans_ldsid(DisasContext *ctx, arg_ldsid *a) 229698a9cb79SRichard Henderson { 2297e36f27efSRichard Henderson TCGv_reg dest = dest_gpr(ctx, a->t); 229898a9cb79SRichard Henderson 22992330504cSHelge Deller #ifdef CONFIG_USER_ONLY 23002330504cSHelge Deller /* We don't implement space registers in user mode. */ 2301eaa3783bSRichard Henderson tcg_gen_movi_reg(dest, 0); 23022330504cSHelge Deller #else 23032330504cSHelge Deller TCGv_i64 t0 = tcg_temp_new_i64(); 23042330504cSHelge Deller 2305e36f27efSRichard Henderson tcg_gen_mov_i64(t0, space_select(ctx, a->sp, load_gpr(ctx, a->b))); 23062330504cSHelge Deller tcg_gen_shri_i64(t0, t0, 32); 23072330504cSHelge Deller tcg_gen_trunc_i64_reg(dest, t0); 23082330504cSHelge Deller 23092330504cSHelge Deller tcg_temp_free_i64(t0); 23102330504cSHelge Deller #endif 2311e36f27efSRichard Henderson save_gpr(ctx, a->t, dest); 231298a9cb79SRichard Henderson 231398a9cb79SRichard Henderson cond_free(&ctx->null_cond); 231431234768SRichard Henderson return true; 231598a9cb79SRichard Henderson } 231698a9cb79SRichard Henderson 2317e36f27efSRichard Henderson static bool trans_rsm(DisasContext *ctx, arg_rsm *a) 2318e36f27efSRichard Henderson { 2319e36f27efSRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 2320e1b5a5edSRichard Henderson #ifndef CONFIG_USER_ONLY 2321e1b5a5edSRichard Henderson TCGv_reg tmp; 2322e1b5a5edSRichard Henderson 2323e1b5a5edSRichard Henderson nullify_over(ctx); 2324e1b5a5edSRichard Henderson 2325e1b5a5edSRichard Henderson tmp = get_temp(ctx); 2326e1b5a5edSRichard Henderson tcg_gen_ld_reg(tmp, cpu_env, offsetof(CPUHPPAState, psw)); 2327e36f27efSRichard Henderson tcg_gen_andi_reg(tmp, tmp, ~a->i); 2328e1b5a5edSRichard Henderson gen_helper_swap_system_mask(tmp, cpu_env, tmp); 2329e36f27efSRichard Henderson save_gpr(ctx, a->t, tmp); 2330e1b5a5edSRichard Henderson 2331e1b5a5edSRichard Henderson /* Exit the TB to recognize new interrupts, e.g. PSW_M. */ 233231234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE_EXIT; 233331234768SRichard Henderson return nullify_end(ctx); 2334e36f27efSRichard Henderson #endif 2335e1b5a5edSRichard Henderson } 2336e1b5a5edSRichard Henderson 2337e36f27efSRichard Henderson static bool trans_ssm(DisasContext *ctx, arg_ssm *a) 2338e1b5a5edSRichard Henderson { 2339e36f27efSRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 2340e36f27efSRichard Henderson #ifndef CONFIG_USER_ONLY 2341e1b5a5edSRichard Henderson TCGv_reg tmp; 2342e1b5a5edSRichard Henderson 2343e1b5a5edSRichard Henderson nullify_over(ctx); 2344e1b5a5edSRichard Henderson 2345e1b5a5edSRichard Henderson tmp = get_temp(ctx); 2346e1b5a5edSRichard Henderson tcg_gen_ld_reg(tmp, cpu_env, offsetof(CPUHPPAState, psw)); 2347e36f27efSRichard Henderson tcg_gen_ori_reg(tmp, tmp, a->i); 2348e1b5a5edSRichard Henderson gen_helper_swap_system_mask(tmp, cpu_env, tmp); 2349e36f27efSRichard Henderson save_gpr(ctx, a->t, tmp); 2350e1b5a5edSRichard Henderson 2351e1b5a5edSRichard Henderson /* Exit the TB to recognize new interrupts, e.g. PSW_I. */ 235231234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE_EXIT; 235331234768SRichard Henderson return nullify_end(ctx); 2354e36f27efSRichard Henderson #endif 2355e1b5a5edSRichard Henderson } 2356e1b5a5edSRichard Henderson 2357c603e14aSRichard Henderson static bool trans_mtsm(DisasContext *ctx, arg_mtsm *a) 2358e1b5a5edSRichard Henderson { 2359e1b5a5edSRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 2360c603e14aSRichard Henderson #ifndef CONFIG_USER_ONLY 2361c603e14aSRichard Henderson TCGv_reg tmp, reg; 2362e1b5a5edSRichard Henderson nullify_over(ctx); 2363e1b5a5edSRichard Henderson 2364c603e14aSRichard Henderson reg = load_gpr(ctx, a->r); 2365e1b5a5edSRichard Henderson tmp = get_temp(ctx); 2366e1b5a5edSRichard Henderson gen_helper_swap_system_mask(tmp, cpu_env, reg); 2367e1b5a5edSRichard Henderson 2368e1b5a5edSRichard Henderson /* Exit the TB to recognize new interrupts. */ 236931234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE_EXIT; 237031234768SRichard Henderson return nullify_end(ctx); 2371c603e14aSRichard Henderson #endif 2372e1b5a5edSRichard Henderson } 2373f49b3537SRichard Henderson 2374e36f27efSRichard Henderson static bool do_rfi(DisasContext *ctx, bool rfi_r) 2375f49b3537SRichard Henderson { 2376f49b3537SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 2377e36f27efSRichard Henderson #ifndef CONFIG_USER_ONLY 2378f49b3537SRichard Henderson nullify_over(ctx); 2379f49b3537SRichard Henderson 2380e36f27efSRichard Henderson if (rfi_r) { 2381f49b3537SRichard Henderson gen_helper_rfi_r(cpu_env); 2382f49b3537SRichard Henderson } else { 2383f49b3537SRichard Henderson gen_helper_rfi(cpu_env); 2384f49b3537SRichard Henderson } 238531234768SRichard Henderson /* Exit the TB to recognize new interrupts. */ 2386f49b3537SRichard Henderson if (ctx->base.singlestep_enabled) { 2387f49b3537SRichard Henderson gen_excp_1(EXCP_DEBUG); 2388f49b3537SRichard Henderson } else { 238907ea28b4SRichard Henderson tcg_gen_exit_tb(NULL, 0); 2390f49b3537SRichard Henderson } 239131234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 2392f49b3537SRichard Henderson 239331234768SRichard Henderson return nullify_end(ctx); 2394e36f27efSRichard Henderson #endif 2395f49b3537SRichard Henderson } 23966210db05SHelge Deller 2397e36f27efSRichard Henderson static bool trans_rfi(DisasContext *ctx, arg_rfi *a) 2398e36f27efSRichard Henderson { 2399e36f27efSRichard Henderson return do_rfi(ctx, false); 2400e36f27efSRichard Henderson } 2401e36f27efSRichard Henderson 2402e36f27efSRichard Henderson static bool trans_rfi_r(DisasContext *ctx, arg_rfi_r *a) 2403e36f27efSRichard Henderson { 2404e36f27efSRichard Henderson return do_rfi(ctx, true); 2405e36f27efSRichard Henderson } 2406e36f27efSRichard Henderson 240796927adbSRichard Henderson static bool trans_halt(DisasContext *ctx, arg_halt *a) 24086210db05SHelge Deller { 24096210db05SHelge Deller CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 241096927adbSRichard Henderson #ifndef CONFIG_USER_ONLY 24116210db05SHelge Deller nullify_over(ctx); 24126210db05SHelge Deller gen_helper_halt(cpu_env); 241331234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 241431234768SRichard Henderson return nullify_end(ctx); 241596927adbSRichard Henderson #endif 24166210db05SHelge Deller } 241796927adbSRichard Henderson 241896927adbSRichard Henderson static bool trans_reset(DisasContext *ctx, arg_reset *a) 241996927adbSRichard Henderson { 242096927adbSRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 242196927adbSRichard Henderson #ifndef CONFIG_USER_ONLY 242296927adbSRichard Henderson nullify_over(ctx); 242396927adbSRichard Henderson gen_helper_reset(cpu_env); 242496927adbSRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 242596927adbSRichard Henderson return nullify_end(ctx); 242696927adbSRichard Henderson #endif 242796927adbSRichard Henderson } 2428e1b5a5edSRichard Henderson 2429deee69a1SRichard Henderson static bool trans_nop_addrx(DisasContext *ctx, arg_ldst *a) 243098a9cb79SRichard Henderson { 2431deee69a1SRichard Henderson if (a->m) { 2432deee69a1SRichard Henderson TCGv_reg dest = dest_gpr(ctx, a->b); 2433deee69a1SRichard Henderson TCGv_reg src1 = load_gpr(ctx, a->b); 2434deee69a1SRichard Henderson TCGv_reg src2 = load_gpr(ctx, a->x); 243598a9cb79SRichard Henderson 243698a9cb79SRichard Henderson /* The only thing we need to do is the base register modification. */ 2437eaa3783bSRichard Henderson tcg_gen_add_reg(dest, src1, src2); 2438deee69a1SRichard Henderson save_gpr(ctx, a->b, dest); 2439deee69a1SRichard Henderson } 244098a9cb79SRichard Henderson cond_free(&ctx->null_cond); 244131234768SRichard Henderson return true; 244298a9cb79SRichard Henderson } 244398a9cb79SRichard Henderson 2444deee69a1SRichard Henderson static bool trans_probe(DisasContext *ctx, arg_probe *a) 244598a9cb79SRichard Henderson { 244686f8d05fSRichard Henderson TCGv_reg dest, ofs; 2447eed14219SRichard Henderson TCGv_i32 level, want; 244886f8d05fSRichard Henderson TCGv_tl addr; 244998a9cb79SRichard Henderson 245098a9cb79SRichard Henderson nullify_over(ctx); 245198a9cb79SRichard Henderson 2452deee69a1SRichard Henderson dest = dest_gpr(ctx, a->t); 2453deee69a1SRichard Henderson form_gva(ctx, &addr, &ofs, a->b, 0, 0, 0, a->sp, 0, false); 2454eed14219SRichard Henderson 2455deee69a1SRichard Henderson if (a->imm) { 2456deee69a1SRichard Henderson level = tcg_const_i32(a->ri); 245798a9cb79SRichard Henderson } else { 2458eed14219SRichard Henderson level = tcg_temp_new_i32(); 2459deee69a1SRichard Henderson tcg_gen_trunc_reg_i32(level, load_gpr(ctx, a->ri)); 2460eed14219SRichard Henderson tcg_gen_andi_i32(level, level, 3); 246198a9cb79SRichard Henderson } 2462deee69a1SRichard Henderson want = tcg_const_i32(a->write ? PAGE_WRITE : PAGE_READ); 2463eed14219SRichard Henderson 2464eed14219SRichard Henderson gen_helper_probe(dest, cpu_env, addr, level, want); 2465eed14219SRichard Henderson 2466eed14219SRichard Henderson tcg_temp_free_i32(want); 2467eed14219SRichard Henderson tcg_temp_free_i32(level); 2468eed14219SRichard Henderson 2469deee69a1SRichard Henderson save_gpr(ctx, a->t, dest); 247031234768SRichard Henderson return nullify_end(ctx); 247198a9cb79SRichard Henderson } 247298a9cb79SRichard Henderson 2473deee69a1SRichard Henderson static bool trans_ixtlbx(DisasContext *ctx, arg_ixtlbx *a) 24748d6ae7fbSRichard Henderson { 2475deee69a1SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 2476deee69a1SRichard Henderson #ifndef CONFIG_USER_ONLY 24778d6ae7fbSRichard Henderson TCGv_tl addr; 24788d6ae7fbSRichard Henderson TCGv_reg ofs, reg; 24798d6ae7fbSRichard Henderson 24808d6ae7fbSRichard Henderson nullify_over(ctx); 24818d6ae7fbSRichard Henderson 2482deee69a1SRichard Henderson form_gva(ctx, &addr, &ofs, a->b, 0, 0, 0, a->sp, 0, false); 2483deee69a1SRichard Henderson reg = load_gpr(ctx, a->r); 2484deee69a1SRichard Henderson if (a->addr) { 24858d6ae7fbSRichard Henderson gen_helper_itlba(cpu_env, addr, reg); 24868d6ae7fbSRichard Henderson } else { 24878d6ae7fbSRichard Henderson gen_helper_itlbp(cpu_env, addr, reg); 24888d6ae7fbSRichard Henderson } 24898d6ae7fbSRichard Henderson 249032dc7569SSven Schnelle /* Exit TB for TLB change if mmu is enabled. */ 249132dc7569SSven Schnelle if (ctx->tb_flags & PSW_C) { 249231234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE; 249331234768SRichard Henderson } 249431234768SRichard Henderson return nullify_end(ctx); 2495deee69a1SRichard Henderson #endif 24968d6ae7fbSRichard Henderson } 249763300a00SRichard Henderson 2498deee69a1SRichard Henderson static bool trans_pxtlbx(DisasContext *ctx, arg_pxtlbx *a) 249963300a00SRichard Henderson { 2500deee69a1SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 2501deee69a1SRichard Henderson #ifndef CONFIG_USER_ONLY 250263300a00SRichard Henderson TCGv_tl addr; 250363300a00SRichard Henderson TCGv_reg ofs; 250463300a00SRichard Henderson 250563300a00SRichard Henderson nullify_over(ctx); 250663300a00SRichard Henderson 2507deee69a1SRichard Henderson form_gva(ctx, &addr, &ofs, a->b, a->x, 0, 0, a->sp, a->m, false); 2508deee69a1SRichard Henderson if (a->m) { 2509deee69a1SRichard Henderson save_gpr(ctx, a->b, ofs); 251063300a00SRichard Henderson } 2511deee69a1SRichard Henderson if (a->local) { 251263300a00SRichard Henderson gen_helper_ptlbe(cpu_env); 251363300a00SRichard Henderson } else { 251463300a00SRichard Henderson gen_helper_ptlb(cpu_env, addr); 251563300a00SRichard Henderson } 251663300a00SRichard Henderson 251763300a00SRichard Henderson /* Exit TB for TLB change if mmu is enabled. */ 251832dc7569SSven Schnelle if (ctx->tb_flags & PSW_C) { 251931234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE; 252031234768SRichard Henderson } 252131234768SRichard Henderson return nullify_end(ctx); 2522deee69a1SRichard Henderson #endif 252363300a00SRichard Henderson } 25242dfcca9fSRichard Henderson 25256797c315SNick Hudson /* 25266797c315SNick Hudson * Implement the pcxl and pcxl2 Fast TLB Insert instructions. 25276797c315SNick Hudson * See 25286797c315SNick Hudson * https://parisc.wiki.kernel.org/images-parisc/a/a9/Pcxl2_ers.pdf 25296797c315SNick Hudson * page 13-9 (195/206) 25306797c315SNick Hudson */ 25316797c315SNick Hudson static bool trans_ixtlbxf(DisasContext *ctx, arg_ixtlbxf *a) 25326797c315SNick Hudson { 25336797c315SNick Hudson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 25346797c315SNick Hudson #ifndef CONFIG_USER_ONLY 25356797c315SNick Hudson TCGv_tl addr, atl, stl; 25366797c315SNick Hudson TCGv_reg reg; 25376797c315SNick Hudson 25386797c315SNick Hudson nullify_over(ctx); 25396797c315SNick Hudson 25406797c315SNick Hudson /* 25416797c315SNick Hudson * FIXME: 25426797c315SNick Hudson * if (not (pcxl or pcxl2)) 25436797c315SNick Hudson * return gen_illegal(ctx); 25446797c315SNick Hudson * 25456797c315SNick Hudson * Note for future: these are 32-bit systems; no hppa64. 25466797c315SNick Hudson */ 25476797c315SNick Hudson 25486797c315SNick Hudson atl = tcg_temp_new_tl(); 25496797c315SNick Hudson stl = tcg_temp_new_tl(); 25506797c315SNick Hudson addr = tcg_temp_new_tl(); 25516797c315SNick Hudson 25526797c315SNick Hudson tcg_gen_ld32u_i64(stl, cpu_env, 25536797c315SNick Hudson a->data ? offsetof(CPUHPPAState, cr[CR_ISR]) 25546797c315SNick Hudson : offsetof(CPUHPPAState, cr[CR_IIASQ])); 25556797c315SNick Hudson tcg_gen_ld32u_i64(atl, cpu_env, 25566797c315SNick Hudson a->data ? offsetof(CPUHPPAState, cr[CR_IOR]) 25576797c315SNick Hudson : offsetof(CPUHPPAState, cr[CR_IIAOQ])); 25586797c315SNick Hudson tcg_gen_shli_i64(stl, stl, 32); 25596797c315SNick Hudson tcg_gen_or_tl(addr, atl, stl); 25606797c315SNick Hudson tcg_temp_free_tl(atl); 25616797c315SNick Hudson tcg_temp_free_tl(stl); 25626797c315SNick Hudson 25636797c315SNick Hudson reg = load_gpr(ctx, a->r); 25646797c315SNick Hudson if (a->addr) { 25656797c315SNick Hudson gen_helper_itlba(cpu_env, addr, reg); 25666797c315SNick Hudson } else { 25676797c315SNick Hudson gen_helper_itlbp(cpu_env, addr, reg); 25686797c315SNick Hudson } 25696797c315SNick Hudson tcg_temp_free_tl(addr); 25706797c315SNick Hudson 25716797c315SNick Hudson /* Exit TB for TLB change if mmu is enabled. */ 25726797c315SNick Hudson if (ctx->tb_flags & PSW_C) { 25736797c315SNick Hudson ctx->base.is_jmp = DISAS_IAQ_N_STALE; 25746797c315SNick Hudson } 25756797c315SNick Hudson return nullify_end(ctx); 25766797c315SNick Hudson #endif 25776797c315SNick Hudson } 25786797c315SNick Hudson 2579deee69a1SRichard Henderson static bool trans_lpa(DisasContext *ctx, arg_ldst *a) 25802dfcca9fSRichard Henderson { 2581deee69a1SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 2582deee69a1SRichard Henderson #ifndef CONFIG_USER_ONLY 25832dfcca9fSRichard Henderson TCGv_tl vaddr; 25842dfcca9fSRichard Henderson TCGv_reg ofs, paddr; 25852dfcca9fSRichard Henderson 25862dfcca9fSRichard Henderson nullify_over(ctx); 25872dfcca9fSRichard Henderson 2588deee69a1SRichard Henderson form_gva(ctx, &vaddr, &ofs, a->b, a->x, 0, 0, a->sp, a->m, false); 25892dfcca9fSRichard Henderson 25902dfcca9fSRichard Henderson paddr = tcg_temp_new(); 25912dfcca9fSRichard Henderson gen_helper_lpa(paddr, cpu_env, vaddr); 25922dfcca9fSRichard Henderson 25932dfcca9fSRichard Henderson /* Note that physical address result overrides base modification. */ 2594deee69a1SRichard Henderson if (a->m) { 2595deee69a1SRichard Henderson save_gpr(ctx, a->b, ofs); 25962dfcca9fSRichard Henderson } 2597deee69a1SRichard Henderson save_gpr(ctx, a->t, paddr); 25982dfcca9fSRichard Henderson tcg_temp_free(paddr); 25992dfcca9fSRichard Henderson 260031234768SRichard Henderson return nullify_end(ctx); 2601deee69a1SRichard Henderson #endif 26022dfcca9fSRichard Henderson } 260343a97b81SRichard Henderson 2604deee69a1SRichard Henderson static bool trans_lci(DisasContext *ctx, arg_lci *a) 260543a97b81SRichard Henderson { 260643a97b81SRichard Henderson TCGv_reg ci; 260743a97b81SRichard Henderson 260843a97b81SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 260943a97b81SRichard Henderson 261043a97b81SRichard Henderson /* The Coherence Index is an implementation-defined function of the 261143a97b81SRichard Henderson physical address. Two addresses with the same CI have a coherent 261243a97b81SRichard Henderson view of the cache. Our implementation is to return 0 for all, 261343a97b81SRichard Henderson since the entire address space is coherent. */ 261443a97b81SRichard Henderson ci = tcg_const_reg(0); 2615deee69a1SRichard Henderson save_gpr(ctx, a->t, ci); 261643a97b81SRichard Henderson tcg_temp_free(ci); 261743a97b81SRichard Henderson 261831234768SRichard Henderson cond_free(&ctx->null_cond); 261931234768SRichard Henderson return true; 262043a97b81SRichard Henderson } 262198a9cb79SRichard Henderson 26220c982a28SRichard Henderson static bool trans_add(DisasContext *ctx, arg_rrr_cf_sh *a) 2623b2167459SRichard Henderson { 26240c982a28SRichard Henderson return do_add_reg(ctx, a, false, false, false, false); 2625b2167459SRichard Henderson } 2626b2167459SRichard Henderson 26270c982a28SRichard Henderson static bool trans_add_l(DisasContext *ctx, arg_rrr_cf_sh *a) 2628b2167459SRichard Henderson { 26290c982a28SRichard Henderson return do_add_reg(ctx, a, true, false, false, false); 2630b2167459SRichard Henderson } 2631b2167459SRichard Henderson 26320c982a28SRichard Henderson static bool trans_add_tsv(DisasContext *ctx, arg_rrr_cf_sh *a) 2633b2167459SRichard Henderson { 26340c982a28SRichard Henderson return do_add_reg(ctx, a, false, true, false, false); 2635b2167459SRichard Henderson } 2636b2167459SRichard Henderson 26370c982a28SRichard Henderson static bool trans_add_c(DisasContext *ctx, arg_rrr_cf_sh *a) 2638b2167459SRichard Henderson { 26390c982a28SRichard Henderson return do_add_reg(ctx, a, false, false, false, true); 26400c982a28SRichard Henderson } 2641b2167459SRichard Henderson 26420c982a28SRichard Henderson static bool trans_add_c_tsv(DisasContext *ctx, arg_rrr_cf_sh *a) 26430c982a28SRichard Henderson { 26440c982a28SRichard Henderson return do_add_reg(ctx, a, false, true, false, true); 26450c982a28SRichard Henderson } 26460c982a28SRichard Henderson 26470c982a28SRichard Henderson static bool trans_sub(DisasContext *ctx, arg_rrr_cf *a) 26480c982a28SRichard Henderson { 26490c982a28SRichard Henderson return do_sub_reg(ctx, a, false, false, false); 26500c982a28SRichard Henderson } 26510c982a28SRichard Henderson 26520c982a28SRichard Henderson static bool trans_sub_tsv(DisasContext *ctx, arg_rrr_cf *a) 26530c982a28SRichard Henderson { 26540c982a28SRichard Henderson return do_sub_reg(ctx, a, true, false, false); 26550c982a28SRichard Henderson } 26560c982a28SRichard Henderson 26570c982a28SRichard Henderson static bool trans_sub_tc(DisasContext *ctx, arg_rrr_cf *a) 26580c982a28SRichard Henderson { 26590c982a28SRichard Henderson return do_sub_reg(ctx, a, false, false, true); 26600c982a28SRichard Henderson } 26610c982a28SRichard Henderson 26620c982a28SRichard Henderson static bool trans_sub_tsv_tc(DisasContext *ctx, arg_rrr_cf *a) 26630c982a28SRichard Henderson { 26640c982a28SRichard Henderson return do_sub_reg(ctx, a, true, false, true); 26650c982a28SRichard Henderson } 26660c982a28SRichard Henderson 26670c982a28SRichard Henderson static bool trans_sub_b(DisasContext *ctx, arg_rrr_cf *a) 26680c982a28SRichard Henderson { 26690c982a28SRichard Henderson return do_sub_reg(ctx, a, false, true, false); 26700c982a28SRichard Henderson } 26710c982a28SRichard Henderson 26720c982a28SRichard Henderson static bool trans_sub_b_tsv(DisasContext *ctx, arg_rrr_cf *a) 26730c982a28SRichard Henderson { 26740c982a28SRichard Henderson return do_sub_reg(ctx, a, true, true, false); 26750c982a28SRichard Henderson } 26760c982a28SRichard Henderson 26770c982a28SRichard Henderson static bool trans_andcm(DisasContext *ctx, arg_rrr_cf *a) 26780c982a28SRichard Henderson { 26790c982a28SRichard Henderson return do_log_reg(ctx, a, tcg_gen_andc_reg); 26800c982a28SRichard Henderson } 26810c982a28SRichard Henderson 26820c982a28SRichard Henderson static bool trans_and(DisasContext *ctx, arg_rrr_cf *a) 26830c982a28SRichard Henderson { 26840c982a28SRichard Henderson return do_log_reg(ctx, a, tcg_gen_and_reg); 26850c982a28SRichard Henderson } 26860c982a28SRichard Henderson 26870c982a28SRichard Henderson static bool trans_or(DisasContext *ctx, arg_rrr_cf *a) 26880c982a28SRichard Henderson { 26890c982a28SRichard Henderson if (a->cf == 0) { 26900c982a28SRichard Henderson unsigned r2 = a->r2; 26910c982a28SRichard Henderson unsigned r1 = a->r1; 26920c982a28SRichard Henderson unsigned rt = a->t; 26930c982a28SRichard Henderson 26947aee8189SRichard Henderson if (rt == 0) { /* NOP */ 26957aee8189SRichard Henderson cond_free(&ctx->null_cond); 26967aee8189SRichard Henderson return true; 26977aee8189SRichard Henderson } 26987aee8189SRichard Henderson if (r2 == 0) { /* COPY */ 2699b2167459SRichard Henderson if (r1 == 0) { 2700eaa3783bSRichard Henderson TCGv_reg dest = dest_gpr(ctx, rt); 2701eaa3783bSRichard Henderson tcg_gen_movi_reg(dest, 0); 2702b2167459SRichard Henderson save_gpr(ctx, rt, dest); 2703b2167459SRichard Henderson } else { 2704b2167459SRichard Henderson save_gpr(ctx, rt, cpu_gr[r1]); 2705b2167459SRichard Henderson } 2706b2167459SRichard Henderson cond_free(&ctx->null_cond); 270731234768SRichard Henderson return true; 2708b2167459SRichard Henderson } 27097aee8189SRichard Henderson #ifndef CONFIG_USER_ONLY 27107aee8189SRichard Henderson /* These are QEMU extensions and are nops in the real architecture: 27117aee8189SRichard Henderson * 27127aee8189SRichard Henderson * or %r10,%r10,%r10 -- idle loop; wait for interrupt 27137aee8189SRichard Henderson * or %r31,%r31,%r31 -- death loop; offline cpu 27147aee8189SRichard Henderson * currently implemented as idle. 27157aee8189SRichard Henderson */ 27167aee8189SRichard Henderson if ((rt == 10 || rt == 31) && r1 == rt && r2 == rt) { /* PAUSE */ 27177aee8189SRichard Henderson TCGv_i32 tmp; 27187aee8189SRichard Henderson 27197aee8189SRichard Henderson /* No need to check for supervisor, as userland can only pause 27207aee8189SRichard Henderson until the next timer interrupt. */ 27217aee8189SRichard Henderson nullify_over(ctx); 27227aee8189SRichard Henderson 27237aee8189SRichard Henderson /* Advance the instruction queue. */ 27247aee8189SRichard Henderson copy_iaoq_entry(cpu_iaoq_f, ctx->iaoq_b, cpu_iaoq_b); 27257aee8189SRichard Henderson copy_iaoq_entry(cpu_iaoq_b, ctx->iaoq_n, ctx->iaoq_n_var); 27267aee8189SRichard Henderson nullify_set(ctx, 0); 27277aee8189SRichard Henderson 27287aee8189SRichard Henderson /* Tell the qemu main loop to halt until this cpu has work. */ 27297aee8189SRichard Henderson tmp = tcg_const_i32(1); 27307aee8189SRichard Henderson tcg_gen_st_i32(tmp, cpu_env, -offsetof(HPPACPU, env) + 27317aee8189SRichard Henderson offsetof(CPUState, halted)); 27327aee8189SRichard Henderson tcg_temp_free_i32(tmp); 27337aee8189SRichard Henderson gen_excp_1(EXCP_HALTED); 27347aee8189SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 27357aee8189SRichard Henderson 27367aee8189SRichard Henderson return nullify_end(ctx); 27377aee8189SRichard Henderson } 27387aee8189SRichard Henderson #endif 27397aee8189SRichard Henderson } 27400c982a28SRichard Henderson return do_log_reg(ctx, a, tcg_gen_or_reg); 27417aee8189SRichard Henderson } 2742b2167459SRichard Henderson 27430c982a28SRichard Henderson static bool trans_xor(DisasContext *ctx, arg_rrr_cf *a) 2744b2167459SRichard Henderson { 27450c982a28SRichard Henderson return do_log_reg(ctx, a, tcg_gen_xor_reg); 27460c982a28SRichard Henderson } 27470c982a28SRichard Henderson 27480c982a28SRichard Henderson static bool trans_cmpclr(DisasContext *ctx, arg_rrr_cf *a) 27490c982a28SRichard Henderson { 2750eaa3783bSRichard Henderson TCGv_reg tcg_r1, tcg_r2; 2751b2167459SRichard Henderson 27520c982a28SRichard Henderson if (a->cf) { 2753b2167459SRichard Henderson nullify_over(ctx); 2754b2167459SRichard Henderson } 27550c982a28SRichard Henderson tcg_r1 = load_gpr(ctx, a->r1); 27560c982a28SRichard Henderson tcg_r2 = load_gpr(ctx, a->r2); 27570c982a28SRichard Henderson do_cmpclr(ctx, a->t, tcg_r1, tcg_r2, a->cf); 275831234768SRichard Henderson return nullify_end(ctx); 2759b2167459SRichard Henderson } 2760b2167459SRichard Henderson 27610c982a28SRichard Henderson static bool trans_uxor(DisasContext *ctx, arg_rrr_cf *a) 2762b2167459SRichard Henderson { 2763eaa3783bSRichard Henderson TCGv_reg tcg_r1, tcg_r2; 2764b2167459SRichard Henderson 27650c982a28SRichard Henderson if (a->cf) { 2766b2167459SRichard Henderson nullify_over(ctx); 2767b2167459SRichard Henderson } 27680c982a28SRichard Henderson tcg_r1 = load_gpr(ctx, a->r1); 27690c982a28SRichard Henderson tcg_r2 = load_gpr(ctx, a->r2); 27700c982a28SRichard Henderson do_unit(ctx, a->t, tcg_r1, tcg_r2, a->cf, false, tcg_gen_xor_reg); 277131234768SRichard Henderson return nullify_end(ctx); 2772b2167459SRichard Henderson } 2773b2167459SRichard Henderson 27740c982a28SRichard Henderson static bool do_uaddcm(DisasContext *ctx, arg_rrr_cf *a, bool is_tc) 2775b2167459SRichard Henderson { 2776eaa3783bSRichard Henderson TCGv_reg tcg_r1, tcg_r2, tmp; 2777b2167459SRichard Henderson 27780c982a28SRichard Henderson if (a->cf) { 2779b2167459SRichard Henderson nullify_over(ctx); 2780b2167459SRichard Henderson } 27810c982a28SRichard Henderson tcg_r1 = load_gpr(ctx, a->r1); 27820c982a28SRichard Henderson tcg_r2 = load_gpr(ctx, a->r2); 2783b2167459SRichard Henderson tmp = get_temp(ctx); 2784eaa3783bSRichard Henderson tcg_gen_not_reg(tmp, tcg_r2); 27850c982a28SRichard Henderson do_unit(ctx, a->t, tcg_r1, tmp, a->cf, is_tc, tcg_gen_add_reg); 278631234768SRichard Henderson return nullify_end(ctx); 2787b2167459SRichard Henderson } 2788b2167459SRichard Henderson 27890c982a28SRichard Henderson static bool trans_uaddcm(DisasContext *ctx, arg_rrr_cf *a) 2790b2167459SRichard Henderson { 27910c982a28SRichard Henderson return do_uaddcm(ctx, a, false); 27920c982a28SRichard Henderson } 27930c982a28SRichard Henderson 27940c982a28SRichard Henderson static bool trans_uaddcm_tc(DisasContext *ctx, arg_rrr_cf *a) 27950c982a28SRichard Henderson { 27960c982a28SRichard Henderson return do_uaddcm(ctx, a, true); 27970c982a28SRichard Henderson } 27980c982a28SRichard Henderson 27990c982a28SRichard Henderson static bool do_dcor(DisasContext *ctx, arg_rr_cf *a, bool is_i) 28000c982a28SRichard Henderson { 2801eaa3783bSRichard Henderson TCGv_reg tmp; 2802b2167459SRichard Henderson 2803b2167459SRichard Henderson nullify_over(ctx); 2804b2167459SRichard Henderson 2805b2167459SRichard Henderson tmp = get_temp(ctx); 2806eaa3783bSRichard Henderson tcg_gen_shri_reg(tmp, cpu_psw_cb, 3); 2807b2167459SRichard Henderson if (!is_i) { 2808eaa3783bSRichard Henderson tcg_gen_not_reg(tmp, tmp); 2809b2167459SRichard Henderson } 2810eaa3783bSRichard Henderson tcg_gen_andi_reg(tmp, tmp, 0x11111111); 2811eaa3783bSRichard Henderson tcg_gen_muli_reg(tmp, tmp, 6); 281260e29463SSven Schnelle do_unit(ctx, a->t, load_gpr(ctx, a->r), tmp, a->cf, false, 2813eaa3783bSRichard Henderson is_i ? tcg_gen_add_reg : tcg_gen_sub_reg); 281431234768SRichard Henderson return nullify_end(ctx); 2815b2167459SRichard Henderson } 2816b2167459SRichard Henderson 28170c982a28SRichard Henderson static bool trans_dcor(DisasContext *ctx, arg_rr_cf *a) 2818b2167459SRichard Henderson { 28190c982a28SRichard Henderson return do_dcor(ctx, a, false); 28200c982a28SRichard Henderson } 28210c982a28SRichard Henderson 28220c982a28SRichard Henderson static bool trans_dcor_i(DisasContext *ctx, arg_rr_cf *a) 28230c982a28SRichard Henderson { 28240c982a28SRichard Henderson return do_dcor(ctx, a, true); 28250c982a28SRichard Henderson } 28260c982a28SRichard Henderson 28270c982a28SRichard Henderson static bool trans_ds(DisasContext *ctx, arg_rrr_cf *a) 28280c982a28SRichard Henderson { 2829eaa3783bSRichard Henderson TCGv_reg dest, add1, add2, addc, zero, in1, in2; 2830b2167459SRichard Henderson 2831b2167459SRichard Henderson nullify_over(ctx); 2832b2167459SRichard Henderson 28330c982a28SRichard Henderson in1 = load_gpr(ctx, a->r1); 28340c982a28SRichard Henderson in2 = load_gpr(ctx, a->r2); 2835b2167459SRichard Henderson 2836b2167459SRichard Henderson add1 = tcg_temp_new(); 2837b2167459SRichard Henderson add2 = tcg_temp_new(); 2838b2167459SRichard Henderson addc = tcg_temp_new(); 2839b2167459SRichard Henderson dest = tcg_temp_new(); 2840eaa3783bSRichard Henderson zero = tcg_const_reg(0); 2841b2167459SRichard Henderson 2842b2167459SRichard Henderson /* Form R1 << 1 | PSW[CB]{8}. */ 2843eaa3783bSRichard Henderson tcg_gen_add_reg(add1, in1, in1); 2844eaa3783bSRichard Henderson tcg_gen_add_reg(add1, add1, cpu_psw_cb_msb); 2845b2167459SRichard Henderson 2846b2167459SRichard Henderson /* Add or subtract R2, depending on PSW[V]. Proper computation of 2847b2167459SRichard Henderson carry{8} requires that we subtract via + ~R2 + 1, as described in 2848b2167459SRichard Henderson the manual. By extracting and masking V, we can produce the 2849b2167459SRichard Henderson proper inputs to the addition without movcond. */ 2850eaa3783bSRichard Henderson tcg_gen_sari_reg(addc, cpu_psw_v, TARGET_REGISTER_BITS - 1); 2851eaa3783bSRichard Henderson tcg_gen_xor_reg(add2, in2, addc); 2852eaa3783bSRichard Henderson tcg_gen_andi_reg(addc, addc, 1); 2853b2167459SRichard Henderson /* ??? This is only correct for 32-bit. */ 2854b2167459SRichard Henderson tcg_gen_add2_i32(dest, cpu_psw_cb_msb, add1, zero, add2, zero); 2855b2167459SRichard Henderson tcg_gen_add2_i32(dest, cpu_psw_cb_msb, dest, cpu_psw_cb_msb, addc, zero); 2856b2167459SRichard Henderson 2857b2167459SRichard Henderson tcg_temp_free(addc); 2858b2167459SRichard Henderson tcg_temp_free(zero); 2859b2167459SRichard Henderson 2860b2167459SRichard Henderson /* Write back the result register. */ 28610c982a28SRichard Henderson save_gpr(ctx, a->t, dest); 2862b2167459SRichard Henderson 2863b2167459SRichard Henderson /* Write back PSW[CB]. */ 2864eaa3783bSRichard Henderson tcg_gen_xor_reg(cpu_psw_cb, add1, add2); 2865eaa3783bSRichard Henderson tcg_gen_xor_reg(cpu_psw_cb, cpu_psw_cb, dest); 2866b2167459SRichard Henderson 2867b2167459SRichard Henderson /* Write back PSW[V] for the division step. */ 2868eaa3783bSRichard Henderson tcg_gen_neg_reg(cpu_psw_v, cpu_psw_cb_msb); 2869eaa3783bSRichard Henderson tcg_gen_xor_reg(cpu_psw_v, cpu_psw_v, in2); 2870b2167459SRichard Henderson 2871b2167459SRichard Henderson /* Install the new nullification. */ 28720c982a28SRichard Henderson if (a->cf) { 2873eaa3783bSRichard Henderson TCGv_reg sv = NULL; 2874b47a4a02SSven Schnelle if (cond_need_sv(a->cf >> 1)) { 2875b2167459SRichard Henderson /* ??? The lshift is supposed to contribute to overflow. */ 2876b2167459SRichard Henderson sv = do_add_sv(ctx, dest, add1, add2); 2877b2167459SRichard Henderson } 28780c982a28SRichard Henderson ctx->null_cond = do_cond(a->cf, dest, cpu_psw_cb_msb, sv); 2879b2167459SRichard Henderson } 2880b2167459SRichard Henderson 2881b2167459SRichard Henderson tcg_temp_free(add1); 2882b2167459SRichard Henderson tcg_temp_free(add2); 2883b2167459SRichard Henderson tcg_temp_free(dest); 2884b2167459SRichard Henderson 288531234768SRichard Henderson return nullify_end(ctx); 2886b2167459SRichard Henderson } 2887b2167459SRichard Henderson 28880588e061SRichard Henderson static bool trans_addi(DisasContext *ctx, arg_rri_cf *a) 2889b2167459SRichard Henderson { 28900588e061SRichard Henderson return do_add_imm(ctx, a, false, false); 28910588e061SRichard Henderson } 28920588e061SRichard Henderson 28930588e061SRichard Henderson static bool trans_addi_tsv(DisasContext *ctx, arg_rri_cf *a) 28940588e061SRichard Henderson { 28950588e061SRichard Henderson return do_add_imm(ctx, a, true, false); 28960588e061SRichard Henderson } 28970588e061SRichard Henderson 28980588e061SRichard Henderson static bool trans_addi_tc(DisasContext *ctx, arg_rri_cf *a) 28990588e061SRichard Henderson { 29000588e061SRichard Henderson return do_add_imm(ctx, a, false, true); 29010588e061SRichard Henderson } 29020588e061SRichard Henderson 29030588e061SRichard Henderson static bool trans_addi_tc_tsv(DisasContext *ctx, arg_rri_cf *a) 29040588e061SRichard Henderson { 29050588e061SRichard Henderson return do_add_imm(ctx, a, true, true); 29060588e061SRichard Henderson } 29070588e061SRichard Henderson 29080588e061SRichard Henderson static bool trans_subi(DisasContext *ctx, arg_rri_cf *a) 29090588e061SRichard Henderson { 29100588e061SRichard Henderson return do_sub_imm(ctx, a, false); 29110588e061SRichard Henderson } 29120588e061SRichard Henderson 29130588e061SRichard Henderson static bool trans_subi_tsv(DisasContext *ctx, arg_rri_cf *a) 29140588e061SRichard Henderson { 29150588e061SRichard Henderson return do_sub_imm(ctx, a, true); 29160588e061SRichard Henderson } 29170588e061SRichard Henderson 29180588e061SRichard Henderson static bool trans_cmpiclr(DisasContext *ctx, arg_rri_cf *a) 29190588e061SRichard Henderson { 2920eaa3783bSRichard Henderson TCGv_reg tcg_im, tcg_r2; 2921b2167459SRichard Henderson 29220588e061SRichard Henderson if (a->cf) { 2923b2167459SRichard Henderson nullify_over(ctx); 2924b2167459SRichard Henderson } 2925b2167459SRichard Henderson 29260588e061SRichard Henderson tcg_im = load_const(ctx, a->i); 29270588e061SRichard Henderson tcg_r2 = load_gpr(ctx, a->r); 29280588e061SRichard Henderson do_cmpclr(ctx, a->t, tcg_im, tcg_r2, a->cf); 2929b2167459SRichard Henderson 293031234768SRichard Henderson return nullify_end(ctx); 2931b2167459SRichard Henderson } 2932b2167459SRichard Henderson 29331cd012a5SRichard Henderson static bool trans_ld(DisasContext *ctx, arg_ldst *a) 293496d6407fSRichard Henderson { 29351cd012a5SRichard Henderson return do_load(ctx, a->t, a->b, a->x, a->scale ? a->size : 0, 29361cd012a5SRichard Henderson a->disp, a->sp, a->m, a->size | MO_TE); 293796d6407fSRichard Henderson } 293896d6407fSRichard Henderson 29391cd012a5SRichard Henderson static bool trans_st(DisasContext *ctx, arg_ldst *a) 294096d6407fSRichard Henderson { 29411cd012a5SRichard Henderson assert(a->x == 0 && a->scale == 0); 29421cd012a5SRichard Henderson return do_store(ctx, a->t, a->b, a->disp, a->sp, a->m, a->size | MO_TE); 294396d6407fSRichard Henderson } 294496d6407fSRichard Henderson 29451cd012a5SRichard Henderson static bool trans_ldc(DisasContext *ctx, arg_ldst *a) 294696d6407fSRichard Henderson { 2947b1af755cSRichard Henderson MemOp mop = MO_TE | MO_ALIGN | a->size; 294886f8d05fSRichard Henderson TCGv_reg zero, dest, ofs; 294986f8d05fSRichard Henderson TCGv_tl addr; 295096d6407fSRichard Henderson 295196d6407fSRichard Henderson nullify_over(ctx); 295296d6407fSRichard Henderson 29531cd012a5SRichard Henderson if (a->m) { 295486f8d05fSRichard Henderson /* Base register modification. Make sure if RT == RB, 295586f8d05fSRichard Henderson we see the result of the load. */ 295696d6407fSRichard Henderson dest = get_temp(ctx); 295796d6407fSRichard Henderson } else { 29581cd012a5SRichard Henderson dest = dest_gpr(ctx, a->t); 295996d6407fSRichard Henderson } 296096d6407fSRichard Henderson 29611cd012a5SRichard Henderson form_gva(ctx, &addr, &ofs, a->b, a->x, a->scale ? a->size : 0, 29621cd012a5SRichard Henderson a->disp, a->sp, a->m, ctx->mmu_idx == MMU_PHYS_IDX); 2963b1af755cSRichard Henderson 2964b1af755cSRichard Henderson /* 2965b1af755cSRichard Henderson * For hppa1.1, LDCW is undefined unless aligned mod 16. 2966b1af755cSRichard Henderson * However actual hardware succeeds with aligned mod 4. 2967b1af755cSRichard Henderson * Detect this case and log a GUEST_ERROR. 2968b1af755cSRichard Henderson * 2969b1af755cSRichard Henderson * TODO: HPPA64 relaxes the over-alignment requirement 2970b1af755cSRichard Henderson * with the ,co completer. 2971b1af755cSRichard Henderson */ 2972b1af755cSRichard Henderson gen_helper_ldc_check(addr); 2973b1af755cSRichard Henderson 2974eaa3783bSRichard Henderson zero = tcg_const_reg(0); 297586f8d05fSRichard Henderson tcg_gen_atomic_xchg_reg(dest, addr, zero, ctx->mmu_idx, mop); 2976b1af755cSRichard Henderson tcg_temp_free(zero); 2977b1af755cSRichard Henderson 29781cd012a5SRichard Henderson if (a->m) { 29791cd012a5SRichard Henderson save_gpr(ctx, a->b, ofs); 298096d6407fSRichard Henderson } 29811cd012a5SRichard Henderson save_gpr(ctx, a->t, dest); 298296d6407fSRichard Henderson 298331234768SRichard Henderson return nullify_end(ctx); 298496d6407fSRichard Henderson } 298596d6407fSRichard Henderson 29861cd012a5SRichard Henderson static bool trans_stby(DisasContext *ctx, arg_stby *a) 298796d6407fSRichard Henderson { 298886f8d05fSRichard Henderson TCGv_reg ofs, val; 298986f8d05fSRichard Henderson TCGv_tl addr; 299096d6407fSRichard Henderson 299196d6407fSRichard Henderson nullify_over(ctx); 299296d6407fSRichard Henderson 29931cd012a5SRichard Henderson form_gva(ctx, &addr, &ofs, a->b, 0, 0, a->disp, a->sp, a->m, 299486f8d05fSRichard Henderson ctx->mmu_idx == MMU_PHYS_IDX); 29951cd012a5SRichard Henderson val = load_gpr(ctx, a->r); 29961cd012a5SRichard Henderson if (a->a) { 2997f9f46db4SEmilio G. Cota if (tb_cflags(ctx->base.tb) & CF_PARALLEL) { 2998f9f46db4SEmilio G. Cota gen_helper_stby_e_parallel(cpu_env, addr, val); 2999f9f46db4SEmilio G. Cota } else { 300096d6407fSRichard Henderson gen_helper_stby_e(cpu_env, addr, val); 3001f9f46db4SEmilio G. Cota } 3002f9f46db4SEmilio G. Cota } else { 3003f9f46db4SEmilio G. Cota if (tb_cflags(ctx->base.tb) & CF_PARALLEL) { 3004f9f46db4SEmilio G. Cota gen_helper_stby_b_parallel(cpu_env, addr, val); 300596d6407fSRichard Henderson } else { 300696d6407fSRichard Henderson gen_helper_stby_b(cpu_env, addr, val); 300796d6407fSRichard Henderson } 3008f9f46db4SEmilio G. Cota } 30091cd012a5SRichard Henderson if (a->m) { 301086f8d05fSRichard Henderson tcg_gen_andi_reg(ofs, ofs, ~3); 30111cd012a5SRichard Henderson save_gpr(ctx, a->b, ofs); 301296d6407fSRichard Henderson } 301396d6407fSRichard Henderson 301431234768SRichard Henderson return nullify_end(ctx); 301596d6407fSRichard Henderson } 301696d6407fSRichard Henderson 30171cd012a5SRichard Henderson static bool trans_lda(DisasContext *ctx, arg_ldst *a) 3018d0a851ccSRichard Henderson { 3019d0a851ccSRichard Henderson int hold_mmu_idx = ctx->mmu_idx; 3020d0a851ccSRichard Henderson 3021d0a851ccSRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 3022d0a851ccSRichard Henderson ctx->mmu_idx = MMU_PHYS_IDX; 30231cd012a5SRichard Henderson trans_ld(ctx, a); 3024d0a851ccSRichard Henderson ctx->mmu_idx = hold_mmu_idx; 302531234768SRichard Henderson return true; 3026d0a851ccSRichard Henderson } 3027d0a851ccSRichard Henderson 30281cd012a5SRichard Henderson static bool trans_sta(DisasContext *ctx, arg_ldst *a) 3029d0a851ccSRichard Henderson { 3030d0a851ccSRichard Henderson int hold_mmu_idx = ctx->mmu_idx; 3031d0a851ccSRichard Henderson 3032d0a851ccSRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 3033d0a851ccSRichard Henderson ctx->mmu_idx = MMU_PHYS_IDX; 30341cd012a5SRichard Henderson trans_st(ctx, a); 3035d0a851ccSRichard Henderson ctx->mmu_idx = hold_mmu_idx; 303631234768SRichard Henderson return true; 3037d0a851ccSRichard Henderson } 303895412a61SRichard Henderson 30390588e061SRichard Henderson static bool trans_ldil(DisasContext *ctx, arg_ldil *a) 3040b2167459SRichard Henderson { 30410588e061SRichard Henderson TCGv_reg tcg_rt = dest_gpr(ctx, a->t); 3042b2167459SRichard Henderson 30430588e061SRichard Henderson tcg_gen_movi_reg(tcg_rt, a->i); 30440588e061SRichard Henderson save_gpr(ctx, a->t, tcg_rt); 3045b2167459SRichard Henderson cond_free(&ctx->null_cond); 304631234768SRichard Henderson return true; 3047b2167459SRichard Henderson } 3048b2167459SRichard Henderson 30490588e061SRichard Henderson static bool trans_addil(DisasContext *ctx, arg_addil *a) 3050b2167459SRichard Henderson { 30510588e061SRichard Henderson TCGv_reg tcg_rt = load_gpr(ctx, a->r); 3052eaa3783bSRichard Henderson TCGv_reg tcg_r1 = dest_gpr(ctx, 1); 3053b2167459SRichard Henderson 30540588e061SRichard Henderson tcg_gen_addi_reg(tcg_r1, tcg_rt, a->i); 3055b2167459SRichard Henderson save_gpr(ctx, 1, tcg_r1); 3056b2167459SRichard Henderson cond_free(&ctx->null_cond); 305731234768SRichard Henderson return true; 3058b2167459SRichard Henderson } 3059b2167459SRichard Henderson 30600588e061SRichard Henderson static bool trans_ldo(DisasContext *ctx, arg_ldo *a) 3061b2167459SRichard Henderson { 30620588e061SRichard Henderson TCGv_reg tcg_rt = dest_gpr(ctx, a->t); 3063b2167459SRichard Henderson 3064b2167459SRichard Henderson /* Special case rb == 0, for the LDI pseudo-op. 3065b2167459SRichard Henderson The COPY pseudo-op is handled for free within tcg_gen_addi_tl. */ 30660588e061SRichard Henderson if (a->b == 0) { 30670588e061SRichard Henderson tcg_gen_movi_reg(tcg_rt, a->i); 3068b2167459SRichard Henderson } else { 30690588e061SRichard Henderson tcg_gen_addi_reg(tcg_rt, cpu_gr[a->b], a->i); 3070b2167459SRichard Henderson } 30710588e061SRichard Henderson save_gpr(ctx, a->t, tcg_rt); 3072b2167459SRichard Henderson cond_free(&ctx->null_cond); 307331234768SRichard Henderson return true; 3074b2167459SRichard Henderson } 3075b2167459SRichard Henderson 307601afb7beSRichard Henderson static bool do_cmpb(DisasContext *ctx, unsigned r, TCGv_reg in1, 307701afb7beSRichard Henderson unsigned c, unsigned f, unsigned n, int disp) 307898cd9ca7SRichard Henderson { 307901afb7beSRichard Henderson TCGv_reg dest, in2, sv; 308098cd9ca7SRichard Henderson DisasCond cond; 308198cd9ca7SRichard Henderson 308298cd9ca7SRichard Henderson in2 = load_gpr(ctx, r); 308398cd9ca7SRichard Henderson dest = get_temp(ctx); 308498cd9ca7SRichard Henderson 3085eaa3783bSRichard Henderson tcg_gen_sub_reg(dest, in1, in2); 308698cd9ca7SRichard Henderson 3087f764718dSRichard Henderson sv = NULL; 3088b47a4a02SSven Schnelle if (cond_need_sv(c)) { 308998cd9ca7SRichard Henderson sv = do_sub_sv(ctx, dest, in1, in2); 309098cd9ca7SRichard Henderson } 309198cd9ca7SRichard Henderson 309201afb7beSRichard Henderson cond = do_sub_cond(c * 2 + f, dest, in1, in2, sv); 309301afb7beSRichard Henderson return do_cbranch(ctx, disp, n, &cond); 309498cd9ca7SRichard Henderson } 309598cd9ca7SRichard Henderson 309601afb7beSRichard Henderson static bool trans_cmpb(DisasContext *ctx, arg_cmpb *a) 309798cd9ca7SRichard Henderson { 309801afb7beSRichard Henderson nullify_over(ctx); 309901afb7beSRichard Henderson return do_cmpb(ctx, a->r2, load_gpr(ctx, a->r1), a->c, a->f, a->n, a->disp); 310001afb7beSRichard Henderson } 310101afb7beSRichard Henderson 310201afb7beSRichard Henderson static bool trans_cmpbi(DisasContext *ctx, arg_cmpbi *a) 310301afb7beSRichard Henderson { 310401afb7beSRichard Henderson nullify_over(ctx); 310501afb7beSRichard Henderson return do_cmpb(ctx, a->r, load_const(ctx, a->i), a->c, a->f, a->n, a->disp); 310601afb7beSRichard Henderson } 310701afb7beSRichard Henderson 310801afb7beSRichard Henderson static bool do_addb(DisasContext *ctx, unsigned r, TCGv_reg in1, 310901afb7beSRichard Henderson unsigned c, unsigned f, unsigned n, int disp) 311001afb7beSRichard Henderson { 311101afb7beSRichard Henderson TCGv_reg dest, in2, sv, cb_msb; 311298cd9ca7SRichard Henderson DisasCond cond; 311398cd9ca7SRichard Henderson 311498cd9ca7SRichard Henderson in2 = load_gpr(ctx, r); 311543675d20SSven Schnelle dest = tcg_temp_new(); 3116f764718dSRichard Henderson sv = NULL; 3117f764718dSRichard Henderson cb_msb = NULL; 311898cd9ca7SRichard Henderson 3119b47a4a02SSven Schnelle if (cond_need_cb(c)) { 312098cd9ca7SRichard Henderson cb_msb = get_temp(ctx); 3121eaa3783bSRichard Henderson tcg_gen_movi_reg(cb_msb, 0); 3122eaa3783bSRichard Henderson tcg_gen_add2_reg(dest, cb_msb, in1, cb_msb, in2, cb_msb); 3123b47a4a02SSven Schnelle } else { 3124eaa3783bSRichard Henderson tcg_gen_add_reg(dest, in1, in2); 3125b47a4a02SSven Schnelle } 3126b47a4a02SSven Schnelle if (cond_need_sv(c)) { 312798cd9ca7SRichard Henderson sv = do_add_sv(ctx, dest, in1, in2); 312898cd9ca7SRichard Henderson } 312998cd9ca7SRichard Henderson 313001afb7beSRichard Henderson cond = do_cond(c * 2 + f, dest, cb_msb, sv); 313143675d20SSven Schnelle save_gpr(ctx, r, dest); 313243675d20SSven Schnelle tcg_temp_free(dest); 313301afb7beSRichard Henderson return do_cbranch(ctx, disp, n, &cond); 313498cd9ca7SRichard Henderson } 313598cd9ca7SRichard Henderson 313601afb7beSRichard Henderson static bool trans_addb(DisasContext *ctx, arg_addb *a) 313798cd9ca7SRichard Henderson { 313801afb7beSRichard Henderson nullify_over(ctx); 313901afb7beSRichard Henderson return do_addb(ctx, a->r2, load_gpr(ctx, a->r1), a->c, a->f, a->n, a->disp); 314001afb7beSRichard Henderson } 314101afb7beSRichard Henderson 314201afb7beSRichard Henderson static bool trans_addbi(DisasContext *ctx, arg_addbi *a) 314301afb7beSRichard Henderson { 314401afb7beSRichard Henderson nullify_over(ctx); 314501afb7beSRichard Henderson return do_addb(ctx, a->r, load_const(ctx, a->i), a->c, a->f, a->n, a->disp); 314601afb7beSRichard Henderson } 314701afb7beSRichard Henderson 314801afb7beSRichard Henderson static bool trans_bb_sar(DisasContext *ctx, arg_bb_sar *a) 314901afb7beSRichard Henderson { 3150eaa3783bSRichard Henderson TCGv_reg tmp, tcg_r; 315198cd9ca7SRichard Henderson DisasCond cond; 315298cd9ca7SRichard Henderson 315398cd9ca7SRichard Henderson nullify_over(ctx); 315498cd9ca7SRichard Henderson 315598cd9ca7SRichard Henderson tmp = tcg_temp_new(); 315601afb7beSRichard Henderson tcg_r = load_gpr(ctx, a->r); 3157eaa3783bSRichard Henderson tcg_gen_shl_reg(tmp, tcg_r, cpu_sar); 315898cd9ca7SRichard Henderson 315901afb7beSRichard Henderson cond = cond_make_0(a->c ? TCG_COND_GE : TCG_COND_LT, tmp); 316098cd9ca7SRichard Henderson tcg_temp_free(tmp); 316101afb7beSRichard Henderson return do_cbranch(ctx, a->disp, a->n, &cond); 316298cd9ca7SRichard Henderson } 316398cd9ca7SRichard Henderson 316401afb7beSRichard Henderson static bool trans_bb_imm(DisasContext *ctx, arg_bb_imm *a) 316598cd9ca7SRichard Henderson { 316601afb7beSRichard Henderson TCGv_reg tmp, tcg_r; 316701afb7beSRichard Henderson DisasCond cond; 316801afb7beSRichard Henderson 316901afb7beSRichard Henderson nullify_over(ctx); 317001afb7beSRichard Henderson 317101afb7beSRichard Henderson tmp = tcg_temp_new(); 317201afb7beSRichard Henderson tcg_r = load_gpr(ctx, a->r); 317301afb7beSRichard Henderson tcg_gen_shli_reg(tmp, tcg_r, a->p); 317401afb7beSRichard Henderson 317501afb7beSRichard Henderson cond = cond_make_0(a->c ? TCG_COND_GE : TCG_COND_LT, tmp); 317601afb7beSRichard Henderson tcg_temp_free(tmp); 317701afb7beSRichard Henderson return do_cbranch(ctx, a->disp, a->n, &cond); 317801afb7beSRichard Henderson } 317901afb7beSRichard Henderson 318001afb7beSRichard Henderson static bool trans_movb(DisasContext *ctx, arg_movb *a) 318101afb7beSRichard Henderson { 3182eaa3783bSRichard Henderson TCGv_reg dest; 318398cd9ca7SRichard Henderson DisasCond cond; 318498cd9ca7SRichard Henderson 318598cd9ca7SRichard Henderson nullify_over(ctx); 318698cd9ca7SRichard Henderson 318701afb7beSRichard Henderson dest = dest_gpr(ctx, a->r2); 318801afb7beSRichard Henderson if (a->r1 == 0) { 3189eaa3783bSRichard Henderson tcg_gen_movi_reg(dest, 0); 319098cd9ca7SRichard Henderson } else { 319101afb7beSRichard Henderson tcg_gen_mov_reg(dest, cpu_gr[a->r1]); 319298cd9ca7SRichard Henderson } 319398cd9ca7SRichard Henderson 319401afb7beSRichard Henderson cond = do_sed_cond(a->c, dest); 319501afb7beSRichard Henderson return do_cbranch(ctx, a->disp, a->n, &cond); 319601afb7beSRichard Henderson } 319701afb7beSRichard Henderson 319801afb7beSRichard Henderson static bool trans_movbi(DisasContext *ctx, arg_movbi *a) 319901afb7beSRichard Henderson { 320001afb7beSRichard Henderson TCGv_reg dest; 320101afb7beSRichard Henderson DisasCond cond; 320201afb7beSRichard Henderson 320301afb7beSRichard Henderson nullify_over(ctx); 320401afb7beSRichard Henderson 320501afb7beSRichard Henderson dest = dest_gpr(ctx, a->r); 320601afb7beSRichard Henderson tcg_gen_movi_reg(dest, a->i); 320701afb7beSRichard Henderson 320801afb7beSRichard Henderson cond = do_sed_cond(a->c, dest); 320901afb7beSRichard Henderson return do_cbranch(ctx, a->disp, a->n, &cond); 321098cd9ca7SRichard Henderson } 321198cd9ca7SRichard Henderson 321230878590SRichard Henderson static bool trans_shrpw_sar(DisasContext *ctx, arg_shrpw_sar *a) 32130b1347d2SRichard Henderson { 3214eaa3783bSRichard Henderson TCGv_reg dest; 32150b1347d2SRichard Henderson 321630878590SRichard Henderson if (a->c) { 32170b1347d2SRichard Henderson nullify_over(ctx); 32180b1347d2SRichard Henderson } 32190b1347d2SRichard Henderson 322030878590SRichard Henderson dest = dest_gpr(ctx, a->t); 322130878590SRichard Henderson if (a->r1 == 0) { 322230878590SRichard Henderson tcg_gen_ext32u_reg(dest, load_gpr(ctx, a->r2)); 3223eaa3783bSRichard Henderson tcg_gen_shr_reg(dest, dest, cpu_sar); 322430878590SRichard Henderson } else if (a->r1 == a->r2) { 32250b1347d2SRichard Henderson TCGv_i32 t32 = tcg_temp_new_i32(); 322630878590SRichard Henderson tcg_gen_trunc_reg_i32(t32, load_gpr(ctx, a->r2)); 32270b1347d2SRichard Henderson tcg_gen_rotr_i32(t32, t32, cpu_sar); 3228eaa3783bSRichard Henderson tcg_gen_extu_i32_reg(dest, t32); 32290b1347d2SRichard Henderson tcg_temp_free_i32(t32); 32300b1347d2SRichard Henderson } else { 32310b1347d2SRichard Henderson TCGv_i64 t = tcg_temp_new_i64(); 32320b1347d2SRichard Henderson TCGv_i64 s = tcg_temp_new_i64(); 32330b1347d2SRichard Henderson 323430878590SRichard Henderson tcg_gen_concat_reg_i64(t, load_gpr(ctx, a->r2), load_gpr(ctx, a->r1)); 3235eaa3783bSRichard Henderson tcg_gen_extu_reg_i64(s, cpu_sar); 32360b1347d2SRichard Henderson tcg_gen_shr_i64(t, t, s); 3237eaa3783bSRichard Henderson tcg_gen_trunc_i64_reg(dest, t); 32380b1347d2SRichard Henderson 32390b1347d2SRichard Henderson tcg_temp_free_i64(t); 32400b1347d2SRichard Henderson tcg_temp_free_i64(s); 32410b1347d2SRichard Henderson } 324230878590SRichard Henderson save_gpr(ctx, a->t, dest); 32430b1347d2SRichard Henderson 32440b1347d2SRichard Henderson /* Install the new nullification. */ 32450b1347d2SRichard Henderson cond_free(&ctx->null_cond); 324630878590SRichard Henderson if (a->c) { 324730878590SRichard Henderson ctx->null_cond = do_sed_cond(a->c, dest); 32480b1347d2SRichard Henderson } 324931234768SRichard Henderson return nullify_end(ctx); 32500b1347d2SRichard Henderson } 32510b1347d2SRichard Henderson 325230878590SRichard Henderson static bool trans_shrpw_imm(DisasContext *ctx, arg_shrpw_imm *a) 32530b1347d2SRichard Henderson { 325430878590SRichard Henderson unsigned sa = 31 - a->cpos; 3255eaa3783bSRichard Henderson TCGv_reg dest, t2; 32560b1347d2SRichard Henderson 325730878590SRichard Henderson if (a->c) { 32580b1347d2SRichard Henderson nullify_over(ctx); 32590b1347d2SRichard Henderson } 32600b1347d2SRichard Henderson 326130878590SRichard Henderson dest = dest_gpr(ctx, a->t); 326230878590SRichard Henderson t2 = load_gpr(ctx, a->r2); 326330878590SRichard Henderson if (a->r1 == a->r2) { 32640b1347d2SRichard Henderson TCGv_i32 t32 = tcg_temp_new_i32(); 3265eaa3783bSRichard Henderson tcg_gen_trunc_reg_i32(t32, t2); 32660b1347d2SRichard Henderson tcg_gen_rotri_i32(t32, t32, sa); 3267eaa3783bSRichard Henderson tcg_gen_extu_i32_reg(dest, t32); 32680b1347d2SRichard Henderson tcg_temp_free_i32(t32); 326930878590SRichard Henderson } else if (a->r1 == 0) { 3270eaa3783bSRichard Henderson tcg_gen_extract_reg(dest, t2, sa, 32 - sa); 32710b1347d2SRichard Henderson } else { 3272eaa3783bSRichard Henderson TCGv_reg t0 = tcg_temp_new(); 3273eaa3783bSRichard Henderson tcg_gen_extract_reg(t0, t2, sa, 32 - sa); 327430878590SRichard Henderson tcg_gen_deposit_reg(dest, t0, cpu_gr[a->r1], 32 - sa, sa); 32750b1347d2SRichard Henderson tcg_temp_free(t0); 32760b1347d2SRichard Henderson } 327730878590SRichard Henderson save_gpr(ctx, a->t, dest); 32780b1347d2SRichard Henderson 32790b1347d2SRichard Henderson /* Install the new nullification. */ 32800b1347d2SRichard Henderson cond_free(&ctx->null_cond); 328130878590SRichard Henderson if (a->c) { 328230878590SRichard Henderson ctx->null_cond = do_sed_cond(a->c, dest); 32830b1347d2SRichard Henderson } 328431234768SRichard Henderson return nullify_end(ctx); 32850b1347d2SRichard Henderson } 32860b1347d2SRichard Henderson 328730878590SRichard Henderson static bool trans_extrw_sar(DisasContext *ctx, arg_extrw_sar *a) 32880b1347d2SRichard Henderson { 328930878590SRichard Henderson unsigned len = 32 - a->clen; 3290eaa3783bSRichard Henderson TCGv_reg dest, src, tmp; 32910b1347d2SRichard Henderson 329230878590SRichard Henderson if (a->c) { 32930b1347d2SRichard Henderson nullify_over(ctx); 32940b1347d2SRichard Henderson } 32950b1347d2SRichard Henderson 329630878590SRichard Henderson dest = dest_gpr(ctx, a->t); 329730878590SRichard Henderson src = load_gpr(ctx, a->r); 32980b1347d2SRichard Henderson tmp = tcg_temp_new(); 32990b1347d2SRichard Henderson 33000b1347d2SRichard Henderson /* Recall that SAR is using big-endian bit numbering. */ 3301eaa3783bSRichard Henderson tcg_gen_xori_reg(tmp, cpu_sar, TARGET_REGISTER_BITS - 1); 330230878590SRichard Henderson if (a->se) { 3303eaa3783bSRichard Henderson tcg_gen_sar_reg(dest, src, tmp); 3304eaa3783bSRichard Henderson tcg_gen_sextract_reg(dest, dest, 0, len); 33050b1347d2SRichard Henderson } else { 3306eaa3783bSRichard Henderson tcg_gen_shr_reg(dest, src, tmp); 3307eaa3783bSRichard Henderson tcg_gen_extract_reg(dest, dest, 0, len); 33080b1347d2SRichard Henderson } 33090b1347d2SRichard Henderson tcg_temp_free(tmp); 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 trans_extrw_imm(DisasContext *ctx, arg_extrw_imm *a) 33210b1347d2SRichard Henderson { 332230878590SRichard Henderson unsigned len = 32 - a->clen; 332330878590SRichard Henderson unsigned cpos = 31 - a->pos; 3324eaa3783bSRichard Henderson TCGv_reg dest, src; 33250b1347d2SRichard Henderson 332630878590SRichard Henderson if (a->c) { 33270b1347d2SRichard Henderson nullify_over(ctx); 33280b1347d2SRichard Henderson } 33290b1347d2SRichard Henderson 333030878590SRichard Henderson dest = dest_gpr(ctx, a->t); 333130878590SRichard Henderson src = load_gpr(ctx, a->r); 333230878590SRichard Henderson if (a->se) { 3333eaa3783bSRichard Henderson tcg_gen_sextract_reg(dest, src, cpos, len); 33340b1347d2SRichard Henderson } else { 3335eaa3783bSRichard Henderson tcg_gen_extract_reg(dest, src, cpos, len); 33360b1347d2SRichard Henderson } 333730878590SRichard Henderson save_gpr(ctx, a->t, dest); 33380b1347d2SRichard Henderson 33390b1347d2SRichard Henderson /* Install the new nullification. */ 33400b1347d2SRichard Henderson cond_free(&ctx->null_cond); 334130878590SRichard Henderson if (a->c) { 334230878590SRichard Henderson ctx->null_cond = do_sed_cond(a->c, dest); 33430b1347d2SRichard Henderson } 334431234768SRichard Henderson return nullify_end(ctx); 33450b1347d2SRichard Henderson } 33460b1347d2SRichard Henderson 334730878590SRichard Henderson static bool trans_depwi_imm(DisasContext *ctx, arg_depwi_imm *a) 33480b1347d2SRichard Henderson { 334930878590SRichard Henderson unsigned len = 32 - a->clen; 3350eaa3783bSRichard Henderson target_sreg mask0, mask1; 3351eaa3783bSRichard Henderson TCGv_reg dest; 33520b1347d2SRichard Henderson 335330878590SRichard Henderson if (a->c) { 33540b1347d2SRichard Henderson nullify_over(ctx); 33550b1347d2SRichard Henderson } 335630878590SRichard Henderson if (a->cpos + len > 32) { 335730878590SRichard Henderson len = 32 - a->cpos; 33580b1347d2SRichard Henderson } 33590b1347d2SRichard Henderson 336030878590SRichard Henderson dest = dest_gpr(ctx, a->t); 336130878590SRichard Henderson mask0 = deposit64(0, a->cpos, len, a->i); 336230878590SRichard Henderson mask1 = deposit64(-1, a->cpos, len, a->i); 33630b1347d2SRichard Henderson 336430878590SRichard Henderson if (a->nz) { 336530878590SRichard Henderson TCGv_reg src = load_gpr(ctx, a->t); 33660b1347d2SRichard Henderson if (mask1 != -1) { 3367eaa3783bSRichard Henderson tcg_gen_andi_reg(dest, src, mask1); 33680b1347d2SRichard Henderson src = dest; 33690b1347d2SRichard Henderson } 3370eaa3783bSRichard Henderson tcg_gen_ori_reg(dest, src, mask0); 33710b1347d2SRichard Henderson } else { 3372eaa3783bSRichard Henderson tcg_gen_movi_reg(dest, mask0); 33730b1347d2SRichard Henderson } 337430878590SRichard Henderson save_gpr(ctx, a->t, dest); 33750b1347d2SRichard Henderson 33760b1347d2SRichard Henderson /* Install the new nullification. */ 33770b1347d2SRichard Henderson cond_free(&ctx->null_cond); 337830878590SRichard Henderson if (a->c) { 337930878590SRichard Henderson ctx->null_cond = do_sed_cond(a->c, dest); 33800b1347d2SRichard Henderson } 338131234768SRichard Henderson return nullify_end(ctx); 33820b1347d2SRichard Henderson } 33830b1347d2SRichard Henderson 338430878590SRichard Henderson static bool trans_depw_imm(DisasContext *ctx, arg_depw_imm *a) 33850b1347d2SRichard Henderson { 338630878590SRichard Henderson unsigned rs = a->nz ? a->t : 0; 338730878590SRichard Henderson unsigned len = 32 - a->clen; 3388eaa3783bSRichard Henderson TCGv_reg dest, val; 33890b1347d2SRichard Henderson 339030878590SRichard Henderson if (a->c) { 33910b1347d2SRichard Henderson nullify_over(ctx); 33920b1347d2SRichard Henderson } 339330878590SRichard Henderson if (a->cpos + len > 32) { 339430878590SRichard Henderson len = 32 - a->cpos; 33950b1347d2SRichard Henderson } 33960b1347d2SRichard Henderson 339730878590SRichard Henderson dest = dest_gpr(ctx, a->t); 339830878590SRichard Henderson val = load_gpr(ctx, a->r); 33990b1347d2SRichard Henderson if (rs == 0) { 340030878590SRichard Henderson tcg_gen_deposit_z_reg(dest, val, a->cpos, len); 34010b1347d2SRichard Henderson } else { 340230878590SRichard Henderson tcg_gen_deposit_reg(dest, cpu_gr[rs], val, a->cpos, len); 34030b1347d2SRichard Henderson } 340430878590SRichard Henderson save_gpr(ctx, a->t, dest); 34050b1347d2SRichard Henderson 34060b1347d2SRichard Henderson /* Install the new nullification. */ 34070b1347d2SRichard Henderson cond_free(&ctx->null_cond); 340830878590SRichard Henderson if (a->c) { 340930878590SRichard Henderson ctx->null_cond = do_sed_cond(a->c, dest); 34100b1347d2SRichard Henderson } 341131234768SRichard Henderson return nullify_end(ctx); 34120b1347d2SRichard Henderson } 34130b1347d2SRichard Henderson 341430878590SRichard Henderson static bool do_depw_sar(DisasContext *ctx, unsigned rt, unsigned c, 341530878590SRichard Henderson unsigned nz, unsigned clen, TCGv_reg val) 34160b1347d2SRichard Henderson { 34170b1347d2SRichard Henderson unsigned rs = nz ? rt : 0; 34180b1347d2SRichard Henderson unsigned len = 32 - clen; 341930878590SRichard Henderson TCGv_reg mask, tmp, shift, dest; 34200b1347d2SRichard Henderson unsigned msb = 1U << (len - 1); 34210b1347d2SRichard Henderson 34220b1347d2SRichard Henderson dest = dest_gpr(ctx, rt); 34230b1347d2SRichard Henderson shift = tcg_temp_new(); 34240b1347d2SRichard Henderson tmp = tcg_temp_new(); 34250b1347d2SRichard Henderson 34260b1347d2SRichard Henderson /* Convert big-endian bit numbering in SAR to left-shift. */ 3427eaa3783bSRichard Henderson tcg_gen_xori_reg(shift, cpu_sar, TARGET_REGISTER_BITS - 1); 34280b1347d2SRichard Henderson 3429eaa3783bSRichard Henderson mask = tcg_const_reg(msb + (msb - 1)); 3430eaa3783bSRichard Henderson tcg_gen_and_reg(tmp, val, mask); 34310b1347d2SRichard Henderson if (rs) { 3432eaa3783bSRichard Henderson tcg_gen_shl_reg(mask, mask, shift); 3433eaa3783bSRichard Henderson tcg_gen_shl_reg(tmp, tmp, shift); 3434eaa3783bSRichard Henderson tcg_gen_andc_reg(dest, cpu_gr[rs], mask); 3435eaa3783bSRichard Henderson tcg_gen_or_reg(dest, dest, tmp); 34360b1347d2SRichard Henderson } else { 3437eaa3783bSRichard Henderson tcg_gen_shl_reg(dest, tmp, shift); 34380b1347d2SRichard Henderson } 34390b1347d2SRichard Henderson tcg_temp_free(shift); 34400b1347d2SRichard Henderson tcg_temp_free(mask); 34410b1347d2SRichard Henderson tcg_temp_free(tmp); 34420b1347d2SRichard Henderson save_gpr(ctx, rt, dest); 34430b1347d2SRichard Henderson 34440b1347d2SRichard Henderson /* Install the new nullification. */ 34450b1347d2SRichard Henderson cond_free(&ctx->null_cond); 34460b1347d2SRichard Henderson if (c) { 34470b1347d2SRichard Henderson ctx->null_cond = do_sed_cond(c, dest); 34480b1347d2SRichard Henderson } 344931234768SRichard Henderson return nullify_end(ctx); 34500b1347d2SRichard Henderson } 34510b1347d2SRichard Henderson 345230878590SRichard Henderson static bool trans_depw_sar(DisasContext *ctx, arg_depw_sar *a) 345330878590SRichard Henderson { 3454a6deecceSSven Schnelle if (a->c) { 3455a6deecceSSven Schnelle nullify_over(ctx); 3456a6deecceSSven Schnelle } 345730878590SRichard Henderson return do_depw_sar(ctx, a->t, a->c, a->nz, a->clen, load_gpr(ctx, a->r)); 345830878590SRichard Henderson } 345930878590SRichard Henderson 346030878590SRichard Henderson static bool trans_depwi_sar(DisasContext *ctx, arg_depwi_sar *a) 346130878590SRichard Henderson { 3462a6deecceSSven Schnelle if (a->c) { 3463a6deecceSSven Schnelle nullify_over(ctx); 3464a6deecceSSven Schnelle } 346530878590SRichard Henderson return do_depw_sar(ctx, a->t, a->c, a->nz, a->clen, load_const(ctx, a->i)); 346630878590SRichard Henderson } 34670b1347d2SRichard Henderson 34688340f534SRichard Henderson static bool trans_be(DisasContext *ctx, arg_be *a) 346998cd9ca7SRichard Henderson { 3470660eefe1SRichard Henderson TCGv_reg tmp; 347198cd9ca7SRichard Henderson 3472c301f34eSRichard Henderson #ifdef CONFIG_USER_ONLY 347398cd9ca7SRichard Henderson /* ??? It seems like there should be a good way of using 347498cd9ca7SRichard Henderson "be disp(sr2, r0)", the canonical gateway entry mechanism 347598cd9ca7SRichard Henderson to our advantage. But that appears to be inconvenient to 347698cd9ca7SRichard Henderson manage along side branch delay slots. Therefore we handle 347798cd9ca7SRichard Henderson entry into the gateway page via absolute address. */ 347898cd9ca7SRichard Henderson /* Since we don't implement spaces, just branch. Do notice the special 347998cd9ca7SRichard Henderson case of "be disp(*,r0)" using a direct branch to disp, so that we can 348098cd9ca7SRichard Henderson goto_tb to the TB containing the syscall. */ 34818340f534SRichard Henderson if (a->b == 0) { 34828340f534SRichard Henderson return do_dbranch(ctx, a->disp, a->l, a->n); 348398cd9ca7SRichard Henderson } 3484c301f34eSRichard Henderson #else 3485c301f34eSRichard Henderson nullify_over(ctx); 3486660eefe1SRichard Henderson #endif 3487660eefe1SRichard Henderson 3488660eefe1SRichard Henderson tmp = get_temp(ctx); 34898340f534SRichard Henderson tcg_gen_addi_reg(tmp, load_gpr(ctx, a->b), a->disp); 3490660eefe1SRichard Henderson tmp = do_ibranch_priv(ctx, tmp); 3491c301f34eSRichard Henderson 3492c301f34eSRichard Henderson #ifdef CONFIG_USER_ONLY 34938340f534SRichard Henderson return do_ibranch(ctx, tmp, a->l, a->n); 3494c301f34eSRichard Henderson #else 3495c301f34eSRichard Henderson TCGv_i64 new_spc = tcg_temp_new_i64(); 3496c301f34eSRichard Henderson 34978340f534SRichard Henderson load_spr(ctx, new_spc, a->sp); 34988340f534SRichard Henderson if (a->l) { 3499c301f34eSRichard Henderson copy_iaoq_entry(cpu_gr[31], ctx->iaoq_n, ctx->iaoq_n_var); 3500c301f34eSRichard Henderson tcg_gen_mov_i64(cpu_sr[0], cpu_iasq_f); 3501c301f34eSRichard Henderson } 35028340f534SRichard Henderson if (a->n && use_nullify_skip(ctx)) { 3503c301f34eSRichard Henderson tcg_gen_mov_reg(cpu_iaoq_f, tmp); 3504c301f34eSRichard Henderson tcg_gen_addi_reg(cpu_iaoq_b, cpu_iaoq_f, 4); 3505c301f34eSRichard Henderson tcg_gen_mov_i64(cpu_iasq_f, new_spc); 3506c301f34eSRichard Henderson tcg_gen_mov_i64(cpu_iasq_b, cpu_iasq_f); 3507c301f34eSRichard Henderson } else { 3508c301f34eSRichard Henderson copy_iaoq_entry(cpu_iaoq_f, ctx->iaoq_b, cpu_iaoq_b); 3509c301f34eSRichard Henderson if (ctx->iaoq_b == -1) { 3510c301f34eSRichard Henderson tcg_gen_mov_i64(cpu_iasq_f, cpu_iasq_b); 3511c301f34eSRichard Henderson } 3512c301f34eSRichard Henderson tcg_gen_mov_reg(cpu_iaoq_b, tmp); 3513c301f34eSRichard Henderson tcg_gen_mov_i64(cpu_iasq_b, new_spc); 35148340f534SRichard Henderson nullify_set(ctx, a->n); 3515c301f34eSRichard Henderson } 3516c301f34eSRichard Henderson tcg_temp_free_i64(new_spc); 3517c301f34eSRichard Henderson tcg_gen_lookup_and_goto_ptr(); 351831234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 351931234768SRichard Henderson return nullify_end(ctx); 3520c301f34eSRichard Henderson #endif 352198cd9ca7SRichard Henderson } 352298cd9ca7SRichard Henderson 35238340f534SRichard Henderson static bool trans_bl(DisasContext *ctx, arg_bl *a) 352498cd9ca7SRichard Henderson { 35258340f534SRichard Henderson return do_dbranch(ctx, iaoq_dest(ctx, a->disp), a->l, a->n); 352698cd9ca7SRichard Henderson } 352798cd9ca7SRichard Henderson 35288340f534SRichard Henderson static bool trans_b_gate(DisasContext *ctx, arg_b_gate *a) 352943e05652SRichard Henderson { 35308340f534SRichard Henderson target_ureg dest = iaoq_dest(ctx, a->disp); 353143e05652SRichard Henderson 35326e5f5300SSven Schnelle nullify_over(ctx); 35336e5f5300SSven Schnelle 353443e05652SRichard Henderson /* Make sure the caller hasn't done something weird with the queue. 353543e05652SRichard Henderson * ??? This is not quite the same as the PSW[B] bit, which would be 353643e05652SRichard Henderson * expensive to track. Real hardware will trap for 353743e05652SRichard Henderson * b gateway 353843e05652SRichard Henderson * b gateway+4 (in delay slot of first branch) 353943e05652SRichard Henderson * However, checking for a non-sequential instruction queue *will* 354043e05652SRichard Henderson * diagnose the security hole 354143e05652SRichard Henderson * b gateway 354243e05652SRichard Henderson * b evil 354343e05652SRichard Henderson * in which instructions at evil would run with increased privs. 354443e05652SRichard Henderson */ 354543e05652SRichard Henderson if (ctx->iaoq_b == -1 || ctx->iaoq_b != ctx->iaoq_f + 4) { 354643e05652SRichard Henderson return gen_illegal(ctx); 354743e05652SRichard Henderson } 354843e05652SRichard Henderson 354943e05652SRichard Henderson #ifndef CONFIG_USER_ONLY 355043e05652SRichard Henderson if (ctx->tb_flags & PSW_C) { 355143e05652SRichard Henderson CPUHPPAState *env = ctx->cs->env_ptr; 355243e05652SRichard Henderson int type = hppa_artype_for_page(env, ctx->base.pc_next); 355343e05652SRichard Henderson /* If we could not find a TLB entry, then we need to generate an 355443e05652SRichard Henderson ITLB miss exception so the kernel will provide it. 355543e05652SRichard Henderson The resulting TLB fill operation will invalidate this TB and 355643e05652SRichard Henderson we will re-translate, at which point we *will* be able to find 355743e05652SRichard Henderson the TLB entry and determine if this is in fact a gateway page. */ 355843e05652SRichard Henderson if (type < 0) { 355931234768SRichard Henderson gen_excp(ctx, EXCP_ITLB_MISS); 356031234768SRichard Henderson return true; 356143e05652SRichard Henderson } 356243e05652SRichard Henderson /* No change for non-gateway pages or for priv decrease. */ 356343e05652SRichard Henderson if (type >= 4 && type - 4 < ctx->privilege) { 356443e05652SRichard Henderson dest = deposit32(dest, 0, 2, type - 4); 356543e05652SRichard Henderson } 356643e05652SRichard Henderson } else { 356743e05652SRichard Henderson dest &= -4; /* priv = 0 */ 356843e05652SRichard Henderson } 356943e05652SRichard Henderson #endif 357043e05652SRichard Henderson 35716e5f5300SSven Schnelle if (a->l) { 35726e5f5300SSven Schnelle TCGv_reg tmp = dest_gpr(ctx, a->l); 35736e5f5300SSven Schnelle if (ctx->privilege < 3) { 35746e5f5300SSven Schnelle tcg_gen_andi_reg(tmp, tmp, -4); 35756e5f5300SSven Schnelle } 35766e5f5300SSven Schnelle tcg_gen_ori_reg(tmp, tmp, ctx->privilege); 35776e5f5300SSven Schnelle save_gpr(ctx, a->l, tmp); 35786e5f5300SSven Schnelle } 35796e5f5300SSven Schnelle 35806e5f5300SSven Schnelle return do_dbranch(ctx, dest, 0, a->n); 358143e05652SRichard Henderson } 358243e05652SRichard Henderson 35838340f534SRichard Henderson static bool trans_blr(DisasContext *ctx, arg_blr *a) 358498cd9ca7SRichard Henderson { 3585b35aec85SRichard Henderson if (a->x) { 3586eaa3783bSRichard Henderson TCGv_reg tmp = get_temp(ctx); 35878340f534SRichard Henderson tcg_gen_shli_reg(tmp, load_gpr(ctx, a->x), 3); 3588eaa3783bSRichard Henderson tcg_gen_addi_reg(tmp, tmp, ctx->iaoq_f + 8); 3589660eefe1SRichard Henderson /* The computation here never changes privilege level. */ 35908340f534SRichard Henderson return do_ibranch(ctx, tmp, a->l, a->n); 3591b35aec85SRichard Henderson } else { 3592b35aec85SRichard Henderson /* BLR R0,RX is a good way to load PC+8 into RX. */ 3593b35aec85SRichard Henderson return do_dbranch(ctx, ctx->iaoq_f + 8, a->l, a->n); 3594b35aec85SRichard Henderson } 359598cd9ca7SRichard Henderson } 359698cd9ca7SRichard Henderson 35978340f534SRichard Henderson static bool trans_bv(DisasContext *ctx, arg_bv *a) 359898cd9ca7SRichard Henderson { 3599eaa3783bSRichard Henderson TCGv_reg dest; 360098cd9ca7SRichard Henderson 36018340f534SRichard Henderson if (a->x == 0) { 36028340f534SRichard Henderson dest = load_gpr(ctx, a->b); 360398cd9ca7SRichard Henderson } else { 360498cd9ca7SRichard Henderson dest = get_temp(ctx); 36058340f534SRichard Henderson tcg_gen_shli_reg(dest, load_gpr(ctx, a->x), 3); 36068340f534SRichard Henderson tcg_gen_add_reg(dest, dest, load_gpr(ctx, a->b)); 360798cd9ca7SRichard Henderson } 3608660eefe1SRichard Henderson dest = do_ibranch_priv(ctx, dest); 36098340f534SRichard Henderson return do_ibranch(ctx, dest, 0, a->n); 361098cd9ca7SRichard Henderson } 361198cd9ca7SRichard Henderson 36128340f534SRichard Henderson static bool trans_bve(DisasContext *ctx, arg_bve *a) 361398cd9ca7SRichard Henderson { 3614660eefe1SRichard Henderson TCGv_reg dest; 361598cd9ca7SRichard Henderson 3616c301f34eSRichard Henderson #ifdef CONFIG_USER_ONLY 36178340f534SRichard Henderson dest = do_ibranch_priv(ctx, load_gpr(ctx, a->b)); 36188340f534SRichard Henderson return do_ibranch(ctx, dest, a->l, a->n); 3619c301f34eSRichard Henderson #else 3620c301f34eSRichard Henderson nullify_over(ctx); 36218340f534SRichard Henderson dest = do_ibranch_priv(ctx, load_gpr(ctx, a->b)); 3622c301f34eSRichard Henderson 3623c301f34eSRichard Henderson copy_iaoq_entry(cpu_iaoq_f, ctx->iaoq_b, cpu_iaoq_b); 3624c301f34eSRichard Henderson if (ctx->iaoq_b == -1) { 3625c301f34eSRichard Henderson tcg_gen_mov_i64(cpu_iasq_f, cpu_iasq_b); 3626c301f34eSRichard Henderson } 3627c301f34eSRichard Henderson copy_iaoq_entry(cpu_iaoq_b, -1, dest); 3628c301f34eSRichard Henderson tcg_gen_mov_i64(cpu_iasq_b, space_select(ctx, 0, dest)); 36298340f534SRichard Henderson if (a->l) { 36308340f534SRichard Henderson copy_iaoq_entry(cpu_gr[a->l], ctx->iaoq_n, ctx->iaoq_n_var); 3631c301f34eSRichard Henderson } 36328340f534SRichard Henderson nullify_set(ctx, a->n); 3633c301f34eSRichard Henderson tcg_gen_lookup_and_goto_ptr(); 363431234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 363531234768SRichard Henderson return nullify_end(ctx); 3636c301f34eSRichard Henderson #endif 363798cd9ca7SRichard Henderson } 363898cd9ca7SRichard Henderson 36391ca74648SRichard Henderson /* 36401ca74648SRichard Henderson * Float class 0 36411ca74648SRichard Henderson */ 3642ebe9383cSRichard Henderson 36431ca74648SRichard Henderson static void gen_fcpy_f(TCGv_i32 dst, TCGv_env unused, TCGv_i32 src) 3644ebe9383cSRichard Henderson { 3645ebe9383cSRichard Henderson tcg_gen_mov_i32(dst, src); 3646ebe9383cSRichard Henderson } 3647ebe9383cSRichard Henderson 36481ca74648SRichard Henderson static bool trans_fcpy_f(DisasContext *ctx, arg_fclass01 *a) 36491ca74648SRichard Henderson { 36501ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_fcpy_f); 36511ca74648SRichard Henderson } 36521ca74648SRichard Henderson 3653ebe9383cSRichard Henderson static void gen_fcpy_d(TCGv_i64 dst, TCGv_env unused, TCGv_i64 src) 3654ebe9383cSRichard Henderson { 3655ebe9383cSRichard Henderson tcg_gen_mov_i64(dst, src); 3656ebe9383cSRichard Henderson } 3657ebe9383cSRichard Henderson 36581ca74648SRichard Henderson static bool trans_fcpy_d(DisasContext *ctx, arg_fclass01 *a) 36591ca74648SRichard Henderson { 36601ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_fcpy_d); 36611ca74648SRichard Henderson } 36621ca74648SRichard Henderson 36631ca74648SRichard Henderson static void gen_fabs_f(TCGv_i32 dst, TCGv_env unused, TCGv_i32 src) 3664ebe9383cSRichard Henderson { 3665ebe9383cSRichard Henderson tcg_gen_andi_i32(dst, src, INT32_MAX); 3666ebe9383cSRichard Henderson } 3667ebe9383cSRichard Henderson 36681ca74648SRichard Henderson static bool trans_fabs_f(DisasContext *ctx, arg_fclass01 *a) 36691ca74648SRichard Henderson { 36701ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_fabs_f); 36711ca74648SRichard Henderson } 36721ca74648SRichard Henderson 3673ebe9383cSRichard Henderson static void gen_fabs_d(TCGv_i64 dst, TCGv_env unused, TCGv_i64 src) 3674ebe9383cSRichard Henderson { 3675ebe9383cSRichard Henderson tcg_gen_andi_i64(dst, src, INT64_MAX); 3676ebe9383cSRichard Henderson } 3677ebe9383cSRichard Henderson 36781ca74648SRichard Henderson static bool trans_fabs_d(DisasContext *ctx, arg_fclass01 *a) 36791ca74648SRichard Henderson { 36801ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_fabs_d); 36811ca74648SRichard Henderson } 36821ca74648SRichard Henderson 36831ca74648SRichard Henderson static bool trans_fsqrt_f(DisasContext *ctx, arg_fclass01 *a) 36841ca74648SRichard Henderson { 36851ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_fsqrt_s); 36861ca74648SRichard Henderson } 36871ca74648SRichard Henderson 36881ca74648SRichard Henderson static bool trans_fsqrt_d(DisasContext *ctx, arg_fclass01 *a) 36891ca74648SRichard Henderson { 36901ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_fsqrt_d); 36911ca74648SRichard Henderson } 36921ca74648SRichard Henderson 36931ca74648SRichard Henderson static bool trans_frnd_f(DisasContext *ctx, arg_fclass01 *a) 36941ca74648SRichard Henderson { 36951ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_frnd_s); 36961ca74648SRichard Henderson } 36971ca74648SRichard Henderson 36981ca74648SRichard Henderson static bool trans_frnd_d(DisasContext *ctx, arg_fclass01 *a) 36991ca74648SRichard Henderson { 37001ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_frnd_d); 37011ca74648SRichard Henderson } 37021ca74648SRichard Henderson 37031ca74648SRichard Henderson static void gen_fneg_f(TCGv_i32 dst, TCGv_env unused, TCGv_i32 src) 3704ebe9383cSRichard Henderson { 3705ebe9383cSRichard Henderson tcg_gen_xori_i32(dst, src, INT32_MIN); 3706ebe9383cSRichard Henderson } 3707ebe9383cSRichard Henderson 37081ca74648SRichard Henderson static bool trans_fneg_f(DisasContext *ctx, arg_fclass01 *a) 37091ca74648SRichard Henderson { 37101ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_fneg_f); 37111ca74648SRichard Henderson } 37121ca74648SRichard Henderson 3713ebe9383cSRichard Henderson static void gen_fneg_d(TCGv_i64 dst, TCGv_env unused, TCGv_i64 src) 3714ebe9383cSRichard Henderson { 3715ebe9383cSRichard Henderson tcg_gen_xori_i64(dst, src, INT64_MIN); 3716ebe9383cSRichard Henderson } 3717ebe9383cSRichard Henderson 37181ca74648SRichard Henderson static bool trans_fneg_d(DisasContext *ctx, arg_fclass01 *a) 37191ca74648SRichard Henderson { 37201ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_fneg_d); 37211ca74648SRichard Henderson } 37221ca74648SRichard Henderson 37231ca74648SRichard Henderson static void gen_fnegabs_f(TCGv_i32 dst, TCGv_env unused, TCGv_i32 src) 3724ebe9383cSRichard Henderson { 3725ebe9383cSRichard Henderson tcg_gen_ori_i32(dst, src, INT32_MIN); 3726ebe9383cSRichard Henderson } 3727ebe9383cSRichard Henderson 37281ca74648SRichard Henderson static bool trans_fnegabs_f(DisasContext *ctx, arg_fclass01 *a) 37291ca74648SRichard Henderson { 37301ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_fnegabs_f); 37311ca74648SRichard Henderson } 37321ca74648SRichard Henderson 3733ebe9383cSRichard Henderson static void gen_fnegabs_d(TCGv_i64 dst, TCGv_env unused, TCGv_i64 src) 3734ebe9383cSRichard Henderson { 3735ebe9383cSRichard Henderson tcg_gen_ori_i64(dst, src, INT64_MIN); 3736ebe9383cSRichard Henderson } 3737ebe9383cSRichard Henderson 37381ca74648SRichard Henderson static bool trans_fnegabs_d(DisasContext *ctx, arg_fclass01 *a) 37391ca74648SRichard Henderson { 37401ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_fnegabs_d); 37411ca74648SRichard Henderson } 37421ca74648SRichard Henderson 37431ca74648SRichard Henderson /* 37441ca74648SRichard Henderson * Float class 1 37451ca74648SRichard Henderson */ 37461ca74648SRichard Henderson 37471ca74648SRichard Henderson static bool trans_fcnv_d_f(DisasContext *ctx, arg_fclass01 *a) 37481ca74648SRichard Henderson { 37491ca74648SRichard Henderson return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_d_s); 37501ca74648SRichard Henderson } 37511ca74648SRichard Henderson 37521ca74648SRichard Henderson static bool trans_fcnv_f_d(DisasContext *ctx, arg_fclass01 *a) 37531ca74648SRichard Henderson { 37541ca74648SRichard Henderson return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_s_d); 37551ca74648SRichard Henderson } 37561ca74648SRichard Henderson 37571ca74648SRichard Henderson static bool trans_fcnv_w_f(DisasContext *ctx, arg_fclass01 *a) 37581ca74648SRichard Henderson { 37591ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_w_s); 37601ca74648SRichard Henderson } 37611ca74648SRichard Henderson 37621ca74648SRichard Henderson static bool trans_fcnv_q_f(DisasContext *ctx, arg_fclass01 *a) 37631ca74648SRichard Henderson { 37641ca74648SRichard Henderson return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_dw_s); 37651ca74648SRichard Henderson } 37661ca74648SRichard Henderson 37671ca74648SRichard Henderson static bool trans_fcnv_w_d(DisasContext *ctx, arg_fclass01 *a) 37681ca74648SRichard Henderson { 37691ca74648SRichard Henderson return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_w_d); 37701ca74648SRichard Henderson } 37711ca74648SRichard Henderson 37721ca74648SRichard Henderson static bool trans_fcnv_q_d(DisasContext *ctx, arg_fclass01 *a) 37731ca74648SRichard Henderson { 37741ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_dw_d); 37751ca74648SRichard Henderson } 37761ca74648SRichard Henderson 37771ca74648SRichard Henderson static bool trans_fcnv_f_w(DisasContext *ctx, arg_fclass01 *a) 37781ca74648SRichard Henderson { 37791ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_s_w); 37801ca74648SRichard Henderson } 37811ca74648SRichard Henderson 37821ca74648SRichard Henderson static bool trans_fcnv_d_w(DisasContext *ctx, arg_fclass01 *a) 37831ca74648SRichard Henderson { 37841ca74648SRichard Henderson return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_d_w); 37851ca74648SRichard Henderson } 37861ca74648SRichard Henderson 37871ca74648SRichard Henderson static bool trans_fcnv_f_q(DisasContext *ctx, arg_fclass01 *a) 37881ca74648SRichard Henderson { 37891ca74648SRichard Henderson return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_s_dw); 37901ca74648SRichard Henderson } 37911ca74648SRichard Henderson 37921ca74648SRichard Henderson static bool trans_fcnv_d_q(DisasContext *ctx, arg_fclass01 *a) 37931ca74648SRichard Henderson { 37941ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_d_dw); 37951ca74648SRichard Henderson } 37961ca74648SRichard Henderson 37971ca74648SRichard Henderson static bool trans_fcnv_t_f_w(DisasContext *ctx, arg_fclass01 *a) 37981ca74648SRichard Henderson { 37991ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_t_s_w); 38001ca74648SRichard Henderson } 38011ca74648SRichard Henderson 38021ca74648SRichard Henderson static bool trans_fcnv_t_d_w(DisasContext *ctx, arg_fclass01 *a) 38031ca74648SRichard Henderson { 38041ca74648SRichard Henderson return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_t_d_w); 38051ca74648SRichard Henderson } 38061ca74648SRichard Henderson 38071ca74648SRichard Henderson static bool trans_fcnv_t_f_q(DisasContext *ctx, arg_fclass01 *a) 38081ca74648SRichard Henderson { 38091ca74648SRichard Henderson return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_t_s_dw); 38101ca74648SRichard Henderson } 38111ca74648SRichard Henderson 38121ca74648SRichard Henderson static bool trans_fcnv_t_d_q(DisasContext *ctx, arg_fclass01 *a) 38131ca74648SRichard Henderson { 38141ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_t_d_dw); 38151ca74648SRichard Henderson } 38161ca74648SRichard Henderson 38171ca74648SRichard Henderson static bool trans_fcnv_uw_f(DisasContext *ctx, arg_fclass01 *a) 38181ca74648SRichard Henderson { 38191ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_uw_s); 38201ca74648SRichard Henderson } 38211ca74648SRichard Henderson 38221ca74648SRichard Henderson static bool trans_fcnv_uq_f(DisasContext *ctx, arg_fclass01 *a) 38231ca74648SRichard Henderson { 38241ca74648SRichard Henderson return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_udw_s); 38251ca74648SRichard Henderson } 38261ca74648SRichard Henderson 38271ca74648SRichard Henderson static bool trans_fcnv_uw_d(DisasContext *ctx, arg_fclass01 *a) 38281ca74648SRichard Henderson { 38291ca74648SRichard Henderson return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_uw_d); 38301ca74648SRichard Henderson } 38311ca74648SRichard Henderson 38321ca74648SRichard Henderson static bool trans_fcnv_uq_d(DisasContext *ctx, arg_fclass01 *a) 38331ca74648SRichard Henderson { 38341ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_udw_d); 38351ca74648SRichard Henderson } 38361ca74648SRichard Henderson 38371ca74648SRichard Henderson static bool trans_fcnv_f_uw(DisasContext *ctx, arg_fclass01 *a) 38381ca74648SRichard Henderson { 38391ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_s_uw); 38401ca74648SRichard Henderson } 38411ca74648SRichard Henderson 38421ca74648SRichard Henderson static bool trans_fcnv_d_uw(DisasContext *ctx, arg_fclass01 *a) 38431ca74648SRichard Henderson { 38441ca74648SRichard Henderson return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_d_uw); 38451ca74648SRichard Henderson } 38461ca74648SRichard Henderson 38471ca74648SRichard Henderson static bool trans_fcnv_f_uq(DisasContext *ctx, arg_fclass01 *a) 38481ca74648SRichard Henderson { 38491ca74648SRichard Henderson return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_s_udw); 38501ca74648SRichard Henderson } 38511ca74648SRichard Henderson 38521ca74648SRichard Henderson static bool trans_fcnv_d_uq(DisasContext *ctx, arg_fclass01 *a) 38531ca74648SRichard Henderson { 38541ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_d_udw); 38551ca74648SRichard Henderson } 38561ca74648SRichard Henderson 38571ca74648SRichard Henderson static bool trans_fcnv_t_f_uw(DisasContext *ctx, arg_fclass01 *a) 38581ca74648SRichard Henderson { 38591ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_t_s_uw); 38601ca74648SRichard Henderson } 38611ca74648SRichard Henderson 38621ca74648SRichard Henderson static bool trans_fcnv_t_d_uw(DisasContext *ctx, arg_fclass01 *a) 38631ca74648SRichard Henderson { 38641ca74648SRichard Henderson return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_t_d_uw); 38651ca74648SRichard Henderson } 38661ca74648SRichard Henderson 38671ca74648SRichard Henderson static bool trans_fcnv_t_f_uq(DisasContext *ctx, arg_fclass01 *a) 38681ca74648SRichard Henderson { 38691ca74648SRichard Henderson return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_t_s_udw); 38701ca74648SRichard Henderson } 38711ca74648SRichard Henderson 38721ca74648SRichard Henderson static bool trans_fcnv_t_d_uq(DisasContext *ctx, arg_fclass01 *a) 38731ca74648SRichard Henderson { 38741ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_t_d_udw); 38751ca74648SRichard Henderson } 38761ca74648SRichard Henderson 38771ca74648SRichard Henderson /* 38781ca74648SRichard Henderson * Float class 2 38791ca74648SRichard Henderson */ 38801ca74648SRichard Henderson 38811ca74648SRichard Henderson static bool trans_fcmp_f(DisasContext *ctx, arg_fclass2 *a) 3882ebe9383cSRichard Henderson { 3883ebe9383cSRichard Henderson TCGv_i32 ta, tb, tc, ty; 3884ebe9383cSRichard Henderson 3885ebe9383cSRichard Henderson nullify_over(ctx); 3886ebe9383cSRichard Henderson 38871ca74648SRichard Henderson ta = load_frw0_i32(a->r1); 38881ca74648SRichard Henderson tb = load_frw0_i32(a->r2); 38891ca74648SRichard Henderson ty = tcg_const_i32(a->y); 38901ca74648SRichard Henderson tc = tcg_const_i32(a->c); 3891ebe9383cSRichard Henderson 3892ebe9383cSRichard Henderson gen_helper_fcmp_s(cpu_env, ta, tb, ty, tc); 3893ebe9383cSRichard Henderson 3894ebe9383cSRichard Henderson tcg_temp_free_i32(ta); 3895ebe9383cSRichard Henderson tcg_temp_free_i32(tb); 3896ebe9383cSRichard Henderson tcg_temp_free_i32(ty); 3897ebe9383cSRichard Henderson tcg_temp_free_i32(tc); 3898ebe9383cSRichard Henderson 38991ca74648SRichard Henderson return nullify_end(ctx); 3900ebe9383cSRichard Henderson } 3901ebe9383cSRichard Henderson 39021ca74648SRichard Henderson static bool trans_fcmp_d(DisasContext *ctx, arg_fclass2 *a) 3903ebe9383cSRichard Henderson { 3904ebe9383cSRichard Henderson TCGv_i64 ta, tb; 3905ebe9383cSRichard Henderson TCGv_i32 tc, ty; 3906ebe9383cSRichard Henderson 3907ebe9383cSRichard Henderson nullify_over(ctx); 3908ebe9383cSRichard Henderson 39091ca74648SRichard Henderson ta = load_frd0(a->r1); 39101ca74648SRichard Henderson tb = load_frd0(a->r2); 39111ca74648SRichard Henderson ty = tcg_const_i32(a->y); 39121ca74648SRichard Henderson tc = tcg_const_i32(a->c); 3913ebe9383cSRichard Henderson 3914ebe9383cSRichard Henderson gen_helper_fcmp_d(cpu_env, ta, tb, ty, tc); 3915ebe9383cSRichard Henderson 3916ebe9383cSRichard Henderson tcg_temp_free_i64(ta); 3917ebe9383cSRichard Henderson tcg_temp_free_i64(tb); 3918ebe9383cSRichard Henderson tcg_temp_free_i32(ty); 3919ebe9383cSRichard Henderson tcg_temp_free_i32(tc); 3920ebe9383cSRichard Henderson 392131234768SRichard Henderson return nullify_end(ctx); 3922ebe9383cSRichard Henderson } 3923ebe9383cSRichard Henderson 39241ca74648SRichard Henderson static bool trans_ftest(DisasContext *ctx, arg_ftest *a) 3925ebe9383cSRichard Henderson { 3926eaa3783bSRichard Henderson TCGv_reg t; 3927ebe9383cSRichard Henderson 3928ebe9383cSRichard Henderson nullify_over(ctx); 3929ebe9383cSRichard Henderson 39301ca74648SRichard Henderson t = get_temp(ctx); 3931eaa3783bSRichard Henderson tcg_gen_ld32u_reg(t, cpu_env, offsetof(CPUHPPAState, fr0_shadow)); 3932ebe9383cSRichard Henderson 39331ca74648SRichard Henderson if (a->y == 1) { 3934ebe9383cSRichard Henderson int mask; 3935ebe9383cSRichard Henderson bool inv = false; 3936ebe9383cSRichard Henderson 39371ca74648SRichard Henderson switch (a->c) { 3938ebe9383cSRichard Henderson case 0: /* simple */ 3939eaa3783bSRichard Henderson tcg_gen_andi_reg(t, t, 0x4000000); 3940ebe9383cSRichard Henderson ctx->null_cond = cond_make_0(TCG_COND_NE, t); 3941ebe9383cSRichard Henderson goto done; 3942ebe9383cSRichard Henderson case 2: /* rej */ 3943ebe9383cSRichard Henderson inv = true; 3944ebe9383cSRichard Henderson /* fallthru */ 3945ebe9383cSRichard Henderson case 1: /* acc */ 3946ebe9383cSRichard Henderson mask = 0x43ff800; 3947ebe9383cSRichard Henderson break; 3948ebe9383cSRichard Henderson case 6: /* rej8 */ 3949ebe9383cSRichard Henderson inv = true; 3950ebe9383cSRichard Henderson /* fallthru */ 3951ebe9383cSRichard Henderson case 5: /* acc8 */ 3952ebe9383cSRichard Henderson mask = 0x43f8000; 3953ebe9383cSRichard Henderson break; 3954ebe9383cSRichard Henderson case 9: /* acc6 */ 3955ebe9383cSRichard Henderson mask = 0x43e0000; 3956ebe9383cSRichard Henderson break; 3957ebe9383cSRichard Henderson case 13: /* acc4 */ 3958ebe9383cSRichard Henderson mask = 0x4380000; 3959ebe9383cSRichard Henderson break; 3960ebe9383cSRichard Henderson case 17: /* acc2 */ 3961ebe9383cSRichard Henderson mask = 0x4200000; 3962ebe9383cSRichard Henderson break; 3963ebe9383cSRichard Henderson default: 39641ca74648SRichard Henderson gen_illegal(ctx); 39651ca74648SRichard Henderson return true; 3966ebe9383cSRichard Henderson } 3967ebe9383cSRichard Henderson if (inv) { 3968eaa3783bSRichard Henderson TCGv_reg c = load_const(ctx, mask); 3969eaa3783bSRichard Henderson tcg_gen_or_reg(t, t, c); 3970ebe9383cSRichard Henderson ctx->null_cond = cond_make(TCG_COND_EQ, t, c); 3971ebe9383cSRichard Henderson } else { 3972eaa3783bSRichard Henderson tcg_gen_andi_reg(t, t, mask); 3973ebe9383cSRichard Henderson ctx->null_cond = cond_make_0(TCG_COND_EQ, t); 3974ebe9383cSRichard Henderson } 39751ca74648SRichard Henderson } else { 39761ca74648SRichard Henderson unsigned cbit = (a->y ^ 1) - 1; 39771ca74648SRichard Henderson 39781ca74648SRichard Henderson tcg_gen_extract_reg(t, t, 21 - cbit, 1); 39791ca74648SRichard Henderson ctx->null_cond = cond_make_0(TCG_COND_NE, t); 39801ca74648SRichard Henderson tcg_temp_free(t); 39811ca74648SRichard Henderson } 39821ca74648SRichard Henderson 3983ebe9383cSRichard Henderson done: 398431234768SRichard Henderson return nullify_end(ctx); 3985ebe9383cSRichard Henderson } 3986ebe9383cSRichard Henderson 39871ca74648SRichard Henderson /* 39881ca74648SRichard Henderson * Float class 2 39891ca74648SRichard Henderson */ 39901ca74648SRichard Henderson 39911ca74648SRichard Henderson static bool trans_fadd_f(DisasContext *ctx, arg_fclass3 *a) 3992ebe9383cSRichard Henderson { 39931ca74648SRichard Henderson return do_fop_weww(ctx, a->t, a->r1, a->r2, gen_helper_fadd_s); 39941ca74648SRichard Henderson } 39951ca74648SRichard Henderson 39961ca74648SRichard Henderson static bool trans_fadd_d(DisasContext *ctx, arg_fclass3 *a) 39971ca74648SRichard Henderson { 39981ca74648SRichard Henderson return do_fop_dedd(ctx, a->t, a->r1, a->r2, gen_helper_fadd_d); 39991ca74648SRichard Henderson } 40001ca74648SRichard Henderson 40011ca74648SRichard Henderson static bool trans_fsub_f(DisasContext *ctx, arg_fclass3 *a) 40021ca74648SRichard Henderson { 40031ca74648SRichard Henderson return do_fop_weww(ctx, a->t, a->r1, a->r2, gen_helper_fsub_s); 40041ca74648SRichard Henderson } 40051ca74648SRichard Henderson 40061ca74648SRichard Henderson static bool trans_fsub_d(DisasContext *ctx, arg_fclass3 *a) 40071ca74648SRichard Henderson { 40081ca74648SRichard Henderson return do_fop_dedd(ctx, a->t, a->r1, a->r2, gen_helper_fsub_d); 40091ca74648SRichard Henderson } 40101ca74648SRichard Henderson 40111ca74648SRichard Henderson static bool trans_fmpy_f(DisasContext *ctx, arg_fclass3 *a) 40121ca74648SRichard Henderson { 40131ca74648SRichard Henderson return do_fop_weww(ctx, a->t, a->r1, a->r2, gen_helper_fmpy_s); 40141ca74648SRichard Henderson } 40151ca74648SRichard Henderson 40161ca74648SRichard Henderson static bool trans_fmpy_d(DisasContext *ctx, arg_fclass3 *a) 40171ca74648SRichard Henderson { 40181ca74648SRichard Henderson return do_fop_dedd(ctx, a->t, a->r1, a->r2, gen_helper_fmpy_d); 40191ca74648SRichard Henderson } 40201ca74648SRichard Henderson 40211ca74648SRichard Henderson static bool trans_fdiv_f(DisasContext *ctx, arg_fclass3 *a) 40221ca74648SRichard Henderson { 40231ca74648SRichard Henderson return do_fop_weww(ctx, a->t, a->r1, a->r2, gen_helper_fdiv_s); 40241ca74648SRichard Henderson } 40251ca74648SRichard Henderson 40261ca74648SRichard Henderson static bool trans_fdiv_d(DisasContext *ctx, arg_fclass3 *a) 40271ca74648SRichard Henderson { 40281ca74648SRichard Henderson return do_fop_dedd(ctx, a->t, a->r1, a->r2, gen_helper_fdiv_d); 40291ca74648SRichard Henderson } 40301ca74648SRichard Henderson 40311ca74648SRichard Henderson static bool trans_xmpyu(DisasContext *ctx, arg_xmpyu *a) 40321ca74648SRichard Henderson { 40331ca74648SRichard Henderson TCGv_i64 x, y; 4034ebe9383cSRichard Henderson 4035ebe9383cSRichard Henderson nullify_over(ctx); 4036ebe9383cSRichard Henderson 40371ca74648SRichard Henderson x = load_frw0_i64(a->r1); 40381ca74648SRichard Henderson y = load_frw0_i64(a->r2); 40391ca74648SRichard Henderson tcg_gen_mul_i64(x, x, y); 40401ca74648SRichard Henderson save_frd(a->t, x); 40411ca74648SRichard Henderson tcg_temp_free_i64(x); 40421ca74648SRichard Henderson tcg_temp_free_i64(y); 4043ebe9383cSRichard Henderson 404431234768SRichard Henderson return nullify_end(ctx); 4045ebe9383cSRichard Henderson } 4046ebe9383cSRichard Henderson 4047ebe9383cSRichard Henderson /* Convert the fmpyadd single-precision register encodings to standard. */ 4048ebe9383cSRichard Henderson static inline int fmpyadd_s_reg(unsigned r) 4049ebe9383cSRichard Henderson { 4050ebe9383cSRichard Henderson return (r & 16) * 2 + 16 + (r & 15); 4051ebe9383cSRichard Henderson } 4052ebe9383cSRichard Henderson 4053b1e2af57SRichard Henderson static bool do_fmpyadd_s(DisasContext *ctx, arg_mpyadd *a, bool is_sub) 4054ebe9383cSRichard Henderson { 4055b1e2af57SRichard Henderson int tm = fmpyadd_s_reg(a->tm); 4056b1e2af57SRichard Henderson int ra = fmpyadd_s_reg(a->ra); 4057b1e2af57SRichard Henderson int ta = fmpyadd_s_reg(a->ta); 4058b1e2af57SRichard Henderson int rm2 = fmpyadd_s_reg(a->rm2); 4059b1e2af57SRichard Henderson int rm1 = fmpyadd_s_reg(a->rm1); 4060ebe9383cSRichard Henderson 4061ebe9383cSRichard Henderson nullify_over(ctx); 4062ebe9383cSRichard Henderson 4063ebe9383cSRichard Henderson do_fop_weww(ctx, tm, rm1, rm2, gen_helper_fmpy_s); 4064ebe9383cSRichard Henderson do_fop_weww(ctx, ta, ta, ra, 4065ebe9383cSRichard Henderson is_sub ? gen_helper_fsub_s : gen_helper_fadd_s); 4066ebe9383cSRichard Henderson 406731234768SRichard Henderson return nullify_end(ctx); 4068ebe9383cSRichard Henderson } 4069ebe9383cSRichard Henderson 4070b1e2af57SRichard Henderson static bool trans_fmpyadd_f(DisasContext *ctx, arg_mpyadd *a) 4071b1e2af57SRichard Henderson { 4072b1e2af57SRichard Henderson return do_fmpyadd_s(ctx, a, false); 4073b1e2af57SRichard Henderson } 4074b1e2af57SRichard Henderson 4075b1e2af57SRichard Henderson static bool trans_fmpysub_f(DisasContext *ctx, arg_mpyadd *a) 4076b1e2af57SRichard Henderson { 4077b1e2af57SRichard Henderson return do_fmpyadd_s(ctx, a, true); 4078b1e2af57SRichard Henderson } 4079b1e2af57SRichard Henderson 4080b1e2af57SRichard Henderson static bool do_fmpyadd_d(DisasContext *ctx, arg_mpyadd *a, bool is_sub) 4081b1e2af57SRichard Henderson { 4082b1e2af57SRichard Henderson nullify_over(ctx); 4083b1e2af57SRichard Henderson 4084b1e2af57SRichard Henderson do_fop_dedd(ctx, a->tm, a->rm1, a->rm2, gen_helper_fmpy_d); 4085b1e2af57SRichard Henderson do_fop_dedd(ctx, a->ta, a->ta, a->ra, 4086b1e2af57SRichard Henderson is_sub ? gen_helper_fsub_d : gen_helper_fadd_d); 4087b1e2af57SRichard Henderson 4088b1e2af57SRichard Henderson return nullify_end(ctx); 4089b1e2af57SRichard Henderson } 4090b1e2af57SRichard Henderson 4091b1e2af57SRichard Henderson static bool trans_fmpyadd_d(DisasContext *ctx, arg_mpyadd *a) 4092b1e2af57SRichard Henderson { 4093b1e2af57SRichard Henderson return do_fmpyadd_d(ctx, a, false); 4094b1e2af57SRichard Henderson } 4095b1e2af57SRichard Henderson 4096b1e2af57SRichard Henderson static bool trans_fmpysub_d(DisasContext *ctx, arg_mpyadd *a) 4097b1e2af57SRichard Henderson { 4098b1e2af57SRichard Henderson return do_fmpyadd_d(ctx, a, true); 4099b1e2af57SRichard Henderson } 4100b1e2af57SRichard Henderson 4101c3bad4f8SRichard Henderson static bool trans_fmpyfadd_f(DisasContext *ctx, arg_fmpyfadd_f *a) 4102ebe9383cSRichard Henderson { 4103c3bad4f8SRichard Henderson TCGv_i32 x, y, z; 4104ebe9383cSRichard Henderson 4105ebe9383cSRichard Henderson nullify_over(ctx); 4106c3bad4f8SRichard Henderson x = load_frw0_i32(a->rm1); 4107c3bad4f8SRichard Henderson y = load_frw0_i32(a->rm2); 4108c3bad4f8SRichard Henderson z = load_frw0_i32(a->ra3); 4109ebe9383cSRichard Henderson 4110c3bad4f8SRichard Henderson if (a->neg) { 4111c3bad4f8SRichard Henderson gen_helper_fmpynfadd_s(x, cpu_env, x, y, z); 4112ebe9383cSRichard Henderson } else { 4113c3bad4f8SRichard Henderson gen_helper_fmpyfadd_s(x, cpu_env, x, y, z); 4114ebe9383cSRichard Henderson } 4115ebe9383cSRichard Henderson 4116c3bad4f8SRichard Henderson tcg_temp_free_i32(y); 4117c3bad4f8SRichard Henderson tcg_temp_free_i32(z); 4118c3bad4f8SRichard Henderson save_frw_i32(a->t, x); 4119c3bad4f8SRichard Henderson tcg_temp_free_i32(x); 412031234768SRichard Henderson return nullify_end(ctx); 4121ebe9383cSRichard Henderson } 4122ebe9383cSRichard Henderson 4123c3bad4f8SRichard Henderson static bool trans_fmpyfadd_d(DisasContext *ctx, arg_fmpyfadd_d *a) 4124ebe9383cSRichard Henderson { 4125c3bad4f8SRichard Henderson TCGv_i64 x, y, z; 4126ebe9383cSRichard Henderson 4127ebe9383cSRichard Henderson nullify_over(ctx); 4128c3bad4f8SRichard Henderson x = load_frd0(a->rm1); 4129c3bad4f8SRichard Henderson y = load_frd0(a->rm2); 4130c3bad4f8SRichard Henderson z = load_frd0(a->ra3); 4131ebe9383cSRichard Henderson 4132c3bad4f8SRichard Henderson if (a->neg) { 4133c3bad4f8SRichard Henderson gen_helper_fmpynfadd_d(x, cpu_env, x, y, z); 4134ebe9383cSRichard Henderson } else { 4135c3bad4f8SRichard Henderson gen_helper_fmpyfadd_d(x, cpu_env, x, y, z); 4136ebe9383cSRichard Henderson } 4137ebe9383cSRichard Henderson 4138c3bad4f8SRichard Henderson tcg_temp_free_i64(y); 4139c3bad4f8SRichard Henderson tcg_temp_free_i64(z); 4140c3bad4f8SRichard Henderson save_frd(a->t, x); 4141c3bad4f8SRichard Henderson tcg_temp_free_i64(x); 414231234768SRichard Henderson return nullify_end(ctx); 4143ebe9383cSRichard Henderson } 4144ebe9383cSRichard Henderson 414515da177bSSven Schnelle static bool trans_diag(DisasContext *ctx, arg_diag *a) 414615da177bSSven Schnelle { 414715da177bSSven Schnelle qemu_log_mask(LOG_UNIMP, "DIAG opcode ignored\n"); 414815da177bSSven Schnelle cond_free(&ctx->null_cond); 414915da177bSSven Schnelle return true; 415015da177bSSven Schnelle } 415115da177bSSven Schnelle 4152b542683dSEmilio G. Cota static void hppa_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) 415361766fe9SRichard Henderson { 415451b061fbSRichard Henderson DisasContext *ctx = container_of(dcbase, DisasContext, base); 4155f764718dSRichard Henderson int bound; 415661766fe9SRichard Henderson 415751b061fbSRichard Henderson ctx->cs = cs; 4158494737b7SRichard Henderson ctx->tb_flags = ctx->base.tb->flags; 41593d68ee7bSRichard Henderson 41603d68ee7bSRichard Henderson #ifdef CONFIG_USER_ONLY 41613d68ee7bSRichard Henderson ctx->privilege = MMU_USER_IDX; 41623d68ee7bSRichard Henderson ctx->mmu_idx = MMU_USER_IDX; 4163ebd0e151SRichard Henderson ctx->iaoq_f = ctx->base.pc_first | MMU_USER_IDX; 4164ebd0e151SRichard Henderson ctx->iaoq_b = ctx->base.tb->cs_base | MMU_USER_IDX; 4165c301f34eSRichard Henderson #else 4166494737b7SRichard Henderson ctx->privilege = (ctx->tb_flags >> TB_FLAG_PRIV_SHIFT) & 3; 4167494737b7SRichard Henderson ctx->mmu_idx = (ctx->tb_flags & PSW_D ? ctx->privilege : MMU_PHYS_IDX); 41683d68ee7bSRichard Henderson 4169c301f34eSRichard Henderson /* Recover the IAOQ values from the GVA + PRIV. */ 4170c301f34eSRichard Henderson uint64_t cs_base = ctx->base.tb->cs_base; 4171c301f34eSRichard Henderson uint64_t iasq_f = cs_base & ~0xffffffffull; 4172c301f34eSRichard Henderson int32_t diff = cs_base; 4173c301f34eSRichard Henderson 4174c301f34eSRichard Henderson ctx->iaoq_f = (ctx->base.pc_first & ~iasq_f) + ctx->privilege; 4175c301f34eSRichard Henderson ctx->iaoq_b = (diff ? ctx->iaoq_f + diff : -1); 4176c301f34eSRichard Henderson #endif 417751b061fbSRichard Henderson ctx->iaoq_n = -1; 4178f764718dSRichard Henderson ctx->iaoq_n_var = NULL; 417961766fe9SRichard Henderson 41803d68ee7bSRichard Henderson /* Bound the number of instructions by those left on the page. */ 41813d68ee7bSRichard Henderson bound = -(ctx->base.pc_first | TARGET_PAGE_MASK) / 4; 4182b542683dSEmilio G. Cota ctx->base.max_insns = MIN(ctx->base.max_insns, bound); 41833d68ee7bSRichard Henderson 418486f8d05fSRichard Henderson ctx->ntempr = 0; 418586f8d05fSRichard Henderson ctx->ntempl = 0; 418686f8d05fSRichard Henderson memset(ctx->tempr, 0, sizeof(ctx->tempr)); 418786f8d05fSRichard Henderson memset(ctx->templ, 0, sizeof(ctx->templ)); 418861766fe9SRichard Henderson } 418961766fe9SRichard Henderson 419051b061fbSRichard Henderson static void hppa_tr_tb_start(DisasContextBase *dcbase, CPUState *cs) 419151b061fbSRichard Henderson { 419251b061fbSRichard Henderson DisasContext *ctx = container_of(dcbase, DisasContext, base); 419361766fe9SRichard Henderson 41943d68ee7bSRichard Henderson /* Seed the nullification status from PSW[N], as saved in TB->FLAGS. */ 419551b061fbSRichard Henderson ctx->null_cond = cond_make_f(); 419651b061fbSRichard Henderson ctx->psw_n_nonzero = false; 4197494737b7SRichard Henderson if (ctx->tb_flags & PSW_N) { 419851b061fbSRichard Henderson ctx->null_cond.c = TCG_COND_ALWAYS; 419951b061fbSRichard Henderson ctx->psw_n_nonzero = true; 4200129e9cc3SRichard Henderson } 420151b061fbSRichard Henderson ctx->null_lab = NULL; 420261766fe9SRichard Henderson } 420361766fe9SRichard Henderson 420451b061fbSRichard Henderson static void hppa_tr_insn_start(DisasContextBase *dcbase, CPUState *cs) 420551b061fbSRichard Henderson { 420651b061fbSRichard Henderson DisasContext *ctx = container_of(dcbase, DisasContext, base); 420751b061fbSRichard Henderson 420851b061fbSRichard Henderson tcg_gen_insn_start(ctx->iaoq_f, ctx->iaoq_b); 420951b061fbSRichard Henderson } 421051b061fbSRichard Henderson 421151b061fbSRichard Henderson static bool hppa_tr_breakpoint_check(DisasContextBase *dcbase, CPUState *cs, 421251b061fbSRichard Henderson const CPUBreakpoint *bp) 421351b061fbSRichard Henderson { 421451b061fbSRichard Henderson DisasContext *ctx = container_of(dcbase, DisasContext, base); 421551b061fbSRichard Henderson 421631234768SRichard Henderson gen_excp(ctx, EXCP_DEBUG); 4217c301f34eSRichard Henderson ctx->base.pc_next += 4; 421851b061fbSRichard Henderson return true; 421951b061fbSRichard Henderson } 422051b061fbSRichard Henderson 422151b061fbSRichard Henderson static void hppa_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) 422251b061fbSRichard Henderson { 422351b061fbSRichard Henderson DisasContext *ctx = container_of(dcbase, DisasContext, base); 422451b061fbSRichard Henderson CPUHPPAState *env = cs->env_ptr; 422551b061fbSRichard Henderson DisasJumpType ret; 422651b061fbSRichard Henderson int i, n; 422751b061fbSRichard Henderson 422851b061fbSRichard Henderson /* Execute one insn. */ 4229ba1d0b44SRichard Henderson #ifdef CONFIG_USER_ONLY 4230c301f34eSRichard Henderson if (ctx->base.pc_next < TARGET_PAGE_SIZE) { 423131234768SRichard Henderson do_page_zero(ctx); 423231234768SRichard Henderson ret = ctx->base.is_jmp; 4233869051eaSRichard Henderson assert(ret != DISAS_NEXT); 4234ba1d0b44SRichard Henderson } else 4235ba1d0b44SRichard Henderson #endif 4236ba1d0b44SRichard Henderson { 423761766fe9SRichard Henderson /* Always fetch the insn, even if nullified, so that we check 423861766fe9SRichard Henderson the page permissions for execute. */ 4239d3733cbbSEmilio G. Cota uint32_t insn = translator_ldl(env, ctx->base.pc_next); 424061766fe9SRichard Henderson 424161766fe9SRichard Henderson /* Set up the IA queue for the next insn. 424261766fe9SRichard Henderson This will be overwritten by a branch. */ 424351b061fbSRichard Henderson if (ctx->iaoq_b == -1) { 424451b061fbSRichard Henderson ctx->iaoq_n = -1; 424551b061fbSRichard Henderson ctx->iaoq_n_var = get_temp(ctx); 4246eaa3783bSRichard Henderson tcg_gen_addi_reg(ctx->iaoq_n_var, cpu_iaoq_b, 4); 424761766fe9SRichard Henderson } else { 424851b061fbSRichard Henderson ctx->iaoq_n = ctx->iaoq_b + 4; 4249f764718dSRichard Henderson ctx->iaoq_n_var = NULL; 425061766fe9SRichard Henderson } 425161766fe9SRichard Henderson 425251b061fbSRichard Henderson if (unlikely(ctx->null_cond.c == TCG_COND_ALWAYS)) { 425351b061fbSRichard Henderson ctx->null_cond.c = TCG_COND_NEVER; 4254869051eaSRichard Henderson ret = DISAS_NEXT; 4255129e9cc3SRichard Henderson } else { 42561a19da0dSRichard Henderson ctx->insn = insn; 425731274b46SRichard Henderson if (!decode(ctx, insn)) { 425831274b46SRichard Henderson gen_illegal(ctx); 425931274b46SRichard Henderson } 426031234768SRichard Henderson ret = ctx->base.is_jmp; 426151b061fbSRichard Henderson assert(ctx->null_lab == NULL); 4262129e9cc3SRichard Henderson } 426361766fe9SRichard Henderson } 426461766fe9SRichard Henderson 426551b061fbSRichard Henderson /* Free any temporaries allocated. */ 426686f8d05fSRichard Henderson for (i = 0, n = ctx->ntempr; i < n; ++i) { 426786f8d05fSRichard Henderson tcg_temp_free(ctx->tempr[i]); 426886f8d05fSRichard Henderson ctx->tempr[i] = NULL; 426961766fe9SRichard Henderson } 427086f8d05fSRichard Henderson for (i = 0, n = ctx->ntempl; i < n; ++i) { 427186f8d05fSRichard Henderson tcg_temp_free_tl(ctx->templ[i]); 427286f8d05fSRichard Henderson ctx->templ[i] = NULL; 427386f8d05fSRichard Henderson } 427486f8d05fSRichard Henderson ctx->ntempr = 0; 427586f8d05fSRichard Henderson ctx->ntempl = 0; 427661766fe9SRichard Henderson 42773d68ee7bSRichard Henderson /* Advance the insn queue. Note that this check also detects 42783d68ee7bSRichard Henderson a priority change within the instruction queue. */ 427951b061fbSRichard Henderson if (ret == DISAS_NEXT && ctx->iaoq_b != ctx->iaoq_f + 4) { 4280c301f34eSRichard Henderson if (ctx->iaoq_b != -1 && ctx->iaoq_n != -1 4281c301f34eSRichard Henderson && use_goto_tb(ctx, ctx->iaoq_b) 4282c301f34eSRichard Henderson && (ctx->null_cond.c == TCG_COND_NEVER 4283c301f34eSRichard Henderson || ctx->null_cond.c == TCG_COND_ALWAYS)) { 428451b061fbSRichard Henderson nullify_set(ctx, ctx->null_cond.c == TCG_COND_ALWAYS); 428551b061fbSRichard Henderson gen_goto_tb(ctx, 0, ctx->iaoq_b, ctx->iaoq_n); 428631234768SRichard Henderson ctx->base.is_jmp = ret = DISAS_NORETURN; 4287129e9cc3SRichard Henderson } else { 428831234768SRichard Henderson ctx->base.is_jmp = ret = DISAS_IAQ_N_STALE; 428961766fe9SRichard Henderson } 4290129e9cc3SRichard Henderson } 429151b061fbSRichard Henderson ctx->iaoq_f = ctx->iaoq_b; 429251b061fbSRichard Henderson ctx->iaoq_b = ctx->iaoq_n; 4293c301f34eSRichard Henderson ctx->base.pc_next += 4; 429461766fe9SRichard Henderson 4295c5d0aec2SRichard Henderson switch (ret) { 4296c5d0aec2SRichard Henderson case DISAS_NORETURN: 4297c5d0aec2SRichard Henderson case DISAS_IAQ_N_UPDATED: 4298c5d0aec2SRichard Henderson break; 4299c5d0aec2SRichard Henderson 4300c5d0aec2SRichard Henderson case DISAS_NEXT: 4301c5d0aec2SRichard Henderson case DISAS_IAQ_N_STALE: 4302c5d0aec2SRichard Henderson case DISAS_IAQ_N_STALE_EXIT: 430351b061fbSRichard Henderson if (ctx->iaoq_f == -1) { 4304eaa3783bSRichard Henderson tcg_gen_mov_reg(cpu_iaoq_f, cpu_iaoq_b); 430551b061fbSRichard Henderson copy_iaoq_entry(cpu_iaoq_b, ctx->iaoq_n, ctx->iaoq_n_var); 4306c301f34eSRichard Henderson #ifndef CONFIG_USER_ONLY 4307c301f34eSRichard Henderson tcg_gen_mov_i64(cpu_iasq_f, cpu_iasq_b); 4308c301f34eSRichard Henderson #endif 430951b061fbSRichard Henderson nullify_save(ctx); 4310c5d0aec2SRichard Henderson ctx->base.is_jmp = (ret == DISAS_IAQ_N_STALE_EXIT 4311c5d0aec2SRichard Henderson ? DISAS_EXIT 4312c5d0aec2SRichard Henderson : DISAS_IAQ_N_UPDATED); 431351b061fbSRichard Henderson } else if (ctx->iaoq_b == -1) { 4314eaa3783bSRichard Henderson tcg_gen_mov_reg(cpu_iaoq_b, ctx->iaoq_n_var); 431561766fe9SRichard Henderson } 4316c5d0aec2SRichard Henderson break; 4317c5d0aec2SRichard Henderson 4318c5d0aec2SRichard Henderson default: 4319c5d0aec2SRichard Henderson g_assert_not_reached(); 4320c5d0aec2SRichard Henderson } 432161766fe9SRichard Henderson } 432261766fe9SRichard Henderson 432351b061fbSRichard Henderson static void hppa_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs) 432451b061fbSRichard Henderson { 432551b061fbSRichard Henderson DisasContext *ctx = container_of(dcbase, DisasContext, base); 4326e1b5a5edSRichard Henderson DisasJumpType is_jmp = ctx->base.is_jmp; 432751b061fbSRichard Henderson 4328e1b5a5edSRichard Henderson switch (is_jmp) { 4329869051eaSRichard Henderson case DISAS_NORETURN: 433061766fe9SRichard Henderson break; 433151b061fbSRichard Henderson case DISAS_TOO_MANY: 4332869051eaSRichard Henderson case DISAS_IAQ_N_STALE: 4333e1b5a5edSRichard Henderson case DISAS_IAQ_N_STALE_EXIT: 433451b061fbSRichard Henderson copy_iaoq_entry(cpu_iaoq_f, ctx->iaoq_f, cpu_iaoq_f); 433551b061fbSRichard Henderson copy_iaoq_entry(cpu_iaoq_b, ctx->iaoq_b, cpu_iaoq_b); 433651b061fbSRichard Henderson nullify_save(ctx); 433761766fe9SRichard Henderson /* FALLTHRU */ 4338869051eaSRichard Henderson case DISAS_IAQ_N_UPDATED: 433951b061fbSRichard Henderson if (ctx->base.singlestep_enabled) { 434061766fe9SRichard Henderson gen_excp_1(EXCP_DEBUG); 4341c5d0aec2SRichard Henderson } else if (is_jmp != DISAS_IAQ_N_STALE_EXIT) { 43427f11636dSEmilio G. Cota tcg_gen_lookup_and_goto_ptr(); 434361766fe9SRichard Henderson } 4344c5d0aec2SRichard Henderson /* FALLTHRU */ 4345c5d0aec2SRichard Henderson case DISAS_EXIT: 4346c5d0aec2SRichard Henderson tcg_gen_exit_tb(NULL, 0); 434761766fe9SRichard Henderson break; 434861766fe9SRichard Henderson default: 434951b061fbSRichard Henderson g_assert_not_reached(); 435061766fe9SRichard Henderson } 435151b061fbSRichard Henderson } 435261766fe9SRichard Henderson 435351b061fbSRichard Henderson static void hppa_tr_disas_log(const DisasContextBase *dcbase, CPUState *cs) 435451b061fbSRichard Henderson { 4355c301f34eSRichard Henderson target_ulong pc = dcbase->pc_first; 435661766fe9SRichard Henderson 4357ba1d0b44SRichard Henderson #ifdef CONFIG_USER_ONLY 4358ba1d0b44SRichard Henderson switch (pc) { 43597ad439dfSRichard Henderson case 0x00: 436051b061fbSRichard Henderson qemu_log("IN:\n0x00000000: (null)\n"); 4361ba1d0b44SRichard Henderson return; 43627ad439dfSRichard Henderson case 0xb0: 436351b061fbSRichard Henderson qemu_log("IN:\n0x000000b0: light-weight-syscall\n"); 4364ba1d0b44SRichard Henderson return; 43657ad439dfSRichard Henderson case 0xe0: 436651b061fbSRichard Henderson qemu_log("IN:\n0x000000e0: set-thread-pointer-syscall\n"); 4367ba1d0b44SRichard Henderson return; 43687ad439dfSRichard Henderson case 0x100: 436951b061fbSRichard Henderson qemu_log("IN:\n0x00000100: syscall\n"); 4370ba1d0b44SRichard Henderson return; 43717ad439dfSRichard Henderson } 4372ba1d0b44SRichard Henderson #endif 4373ba1d0b44SRichard Henderson 4374ba1d0b44SRichard Henderson qemu_log("IN: %s\n", lookup_symbol(pc)); 4375eaa3783bSRichard Henderson log_target_disas(cs, pc, dcbase->tb->size); 437661766fe9SRichard Henderson } 437751b061fbSRichard Henderson 437851b061fbSRichard Henderson static const TranslatorOps hppa_tr_ops = { 437951b061fbSRichard Henderson .init_disas_context = hppa_tr_init_disas_context, 438051b061fbSRichard Henderson .tb_start = hppa_tr_tb_start, 438151b061fbSRichard Henderson .insn_start = hppa_tr_insn_start, 438251b061fbSRichard Henderson .breakpoint_check = hppa_tr_breakpoint_check, 438351b061fbSRichard Henderson .translate_insn = hppa_tr_translate_insn, 438451b061fbSRichard Henderson .tb_stop = hppa_tr_tb_stop, 438551b061fbSRichard Henderson .disas_log = hppa_tr_disas_log, 438651b061fbSRichard Henderson }; 438751b061fbSRichard Henderson 43888b86d6d2SRichard Henderson void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns) 438951b061fbSRichard Henderson { 439051b061fbSRichard Henderson DisasContext ctx; 43918b86d6d2SRichard Henderson translator_loop(&hppa_tr_ops, &ctx.base, cs, tb, max_insns); 439261766fe9SRichard Henderson } 439361766fe9SRichard Henderson 439461766fe9SRichard Henderson void restore_state_to_opc(CPUHPPAState *env, TranslationBlock *tb, 439561766fe9SRichard Henderson target_ulong *data) 439661766fe9SRichard Henderson { 439761766fe9SRichard Henderson env->iaoq_f = data[0]; 439886f8d05fSRichard Henderson if (data[1] != (target_ureg)-1) { 439961766fe9SRichard Henderson env->iaoq_b = data[1]; 440061766fe9SRichard Henderson } 440161766fe9SRichard Henderson /* Since we were executing the instruction at IAOQ_F, and took some 440261766fe9SRichard Henderson sort of action that provoked the cpu_restore_state, we can infer 440361766fe9SRichard Henderson that the instruction was not nullified. */ 440461766fe9SRichard Henderson env->psw_n = 0; 440561766fe9SRichard Henderson } 4406