161766fe9SRichard Henderson /* 261766fe9SRichard Henderson * HPPA emulation cpu translation for qemu. 361766fe9SRichard Henderson * 461766fe9SRichard Henderson * Copyright (c) 2016 Richard Henderson <rth@twiddle.net> 561766fe9SRichard Henderson * 661766fe9SRichard Henderson * This library is free software; you can redistribute it and/or 761766fe9SRichard Henderson * modify it under the terms of the GNU Lesser General Public 861766fe9SRichard Henderson * License as published by the Free Software Foundation; either 9d6ea4236SChetan Pant * version 2.1 of the License, or (at your option) any later version. 1061766fe9SRichard Henderson * 1161766fe9SRichard Henderson * This library is distributed in the hope that it will be useful, 1261766fe9SRichard Henderson * but WITHOUT ANY WARRANTY; without even the implied warranty of 1361766fe9SRichard Henderson * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1461766fe9SRichard Henderson * Lesser General Public License for more details. 1561766fe9SRichard Henderson * 1661766fe9SRichard Henderson * You should have received a copy of the GNU Lesser General Public 1761766fe9SRichard Henderson * License along with this library; if not, see <http://www.gnu.org/licenses/>. 1861766fe9SRichard Henderson */ 1961766fe9SRichard Henderson 2061766fe9SRichard Henderson #include "qemu/osdep.h" 2161766fe9SRichard Henderson #include "cpu.h" 2261766fe9SRichard Henderson #include "disas/disas.h" 2361766fe9SRichard Henderson #include "qemu/host-utils.h" 2461766fe9SRichard Henderson #include "exec/exec-all.h" 25dcb32f1dSPhilippe Mathieu-Daudé #include "tcg/tcg-op.h" 2661766fe9SRichard Henderson #include "exec/helper-proto.h" 2761766fe9SRichard Henderson #include "exec/helper-gen.h" 28869051eaSRichard Henderson #include "exec/translator.h" 2961766fe9SRichard Henderson #include "exec/log.h" 3061766fe9SRichard Henderson 31d53106c9SRichard Henderson #define HELPER_H "helper.h" 32d53106c9SRichard Henderson #include "exec/helper-info.c.inc" 33d53106c9SRichard Henderson #undef HELPER_H 34d53106c9SRichard Henderson 35d53106c9SRichard Henderson 36eaa3783bSRichard Henderson /* Since we have a distinction between register size and address size, 37eaa3783bSRichard Henderson we need to redefine all of these. */ 38eaa3783bSRichard Henderson 39eaa3783bSRichard Henderson #undef TCGv 40eaa3783bSRichard Henderson #undef tcg_temp_new 41eaa3783bSRichard Henderson #undef tcg_global_mem_new 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 #if TARGET_REGISTER_BITS == 64 47eaa3783bSRichard Henderson #define tcg_gen_extu_reg_tl tcg_gen_mov_i64 48eaa3783bSRichard Henderson #else 49eaa3783bSRichard Henderson #define tcg_gen_extu_reg_tl tcg_gen_extu_i32_i64 50eaa3783bSRichard Henderson #endif 51eaa3783bSRichard Henderson #else 52eaa3783bSRichard Henderson #define TCGv_tl TCGv_i32 53eaa3783bSRichard Henderson #define tcg_temp_new_tl tcg_temp_new_i32 54eaa3783bSRichard Henderson #define tcg_gen_extu_reg_tl tcg_gen_mov_i32 55eaa3783bSRichard Henderson #endif 56eaa3783bSRichard Henderson 57eaa3783bSRichard Henderson #if TARGET_REGISTER_BITS == 64 58eaa3783bSRichard Henderson #define TCGv_reg TCGv_i64 59eaa3783bSRichard Henderson 60eaa3783bSRichard Henderson #define tcg_temp_new tcg_temp_new_i64 61eaa3783bSRichard Henderson #define tcg_global_mem_new tcg_global_mem_new_i64 62eaa3783bSRichard Henderson 63eaa3783bSRichard Henderson #define tcg_gen_movi_reg tcg_gen_movi_i64 64eaa3783bSRichard Henderson #define tcg_gen_mov_reg tcg_gen_mov_i64 65eaa3783bSRichard Henderson #define tcg_gen_ld8u_reg tcg_gen_ld8u_i64 66eaa3783bSRichard Henderson #define tcg_gen_ld8s_reg tcg_gen_ld8s_i64 67eaa3783bSRichard Henderson #define tcg_gen_ld16u_reg tcg_gen_ld16u_i64 68eaa3783bSRichard Henderson #define tcg_gen_ld16s_reg tcg_gen_ld16s_i64 69eaa3783bSRichard Henderson #define tcg_gen_ld32u_reg tcg_gen_ld32u_i64 70eaa3783bSRichard Henderson #define tcg_gen_ld32s_reg tcg_gen_ld32s_i64 71eaa3783bSRichard Henderson #define tcg_gen_ld_reg tcg_gen_ld_i64 72eaa3783bSRichard Henderson #define tcg_gen_st8_reg tcg_gen_st8_i64 73eaa3783bSRichard Henderson #define tcg_gen_st16_reg tcg_gen_st16_i64 74eaa3783bSRichard Henderson #define tcg_gen_st32_reg tcg_gen_st32_i64 75eaa3783bSRichard Henderson #define tcg_gen_st_reg tcg_gen_st_i64 76eaa3783bSRichard Henderson #define tcg_gen_add_reg tcg_gen_add_i64 77eaa3783bSRichard Henderson #define tcg_gen_addi_reg tcg_gen_addi_i64 78eaa3783bSRichard Henderson #define tcg_gen_sub_reg tcg_gen_sub_i64 79eaa3783bSRichard Henderson #define tcg_gen_neg_reg tcg_gen_neg_i64 80eaa3783bSRichard Henderson #define tcg_gen_subfi_reg tcg_gen_subfi_i64 81eaa3783bSRichard Henderson #define tcg_gen_subi_reg tcg_gen_subi_i64 82eaa3783bSRichard Henderson #define tcg_gen_and_reg tcg_gen_and_i64 83eaa3783bSRichard Henderson #define tcg_gen_andi_reg tcg_gen_andi_i64 84eaa3783bSRichard Henderson #define tcg_gen_or_reg tcg_gen_or_i64 85eaa3783bSRichard Henderson #define tcg_gen_ori_reg tcg_gen_ori_i64 86eaa3783bSRichard Henderson #define tcg_gen_xor_reg tcg_gen_xor_i64 87eaa3783bSRichard Henderson #define tcg_gen_xori_reg tcg_gen_xori_i64 88eaa3783bSRichard Henderson #define tcg_gen_not_reg tcg_gen_not_i64 89eaa3783bSRichard Henderson #define tcg_gen_shl_reg tcg_gen_shl_i64 90eaa3783bSRichard Henderson #define tcg_gen_shli_reg tcg_gen_shli_i64 91eaa3783bSRichard Henderson #define tcg_gen_shr_reg tcg_gen_shr_i64 92eaa3783bSRichard Henderson #define tcg_gen_shri_reg tcg_gen_shri_i64 93eaa3783bSRichard Henderson #define tcg_gen_sar_reg tcg_gen_sar_i64 94eaa3783bSRichard Henderson #define tcg_gen_sari_reg tcg_gen_sari_i64 95eaa3783bSRichard Henderson #define tcg_gen_brcond_reg tcg_gen_brcond_i64 96eaa3783bSRichard Henderson #define tcg_gen_brcondi_reg tcg_gen_brcondi_i64 97eaa3783bSRichard Henderson #define tcg_gen_setcond_reg tcg_gen_setcond_i64 98eaa3783bSRichard Henderson #define tcg_gen_setcondi_reg tcg_gen_setcondi_i64 99eaa3783bSRichard Henderson #define tcg_gen_mul_reg tcg_gen_mul_i64 100eaa3783bSRichard Henderson #define tcg_gen_muli_reg tcg_gen_muli_i64 101eaa3783bSRichard Henderson #define tcg_gen_div_reg tcg_gen_div_i64 102eaa3783bSRichard Henderson #define tcg_gen_rem_reg tcg_gen_rem_i64 103eaa3783bSRichard Henderson #define tcg_gen_divu_reg tcg_gen_divu_i64 104eaa3783bSRichard Henderson #define tcg_gen_remu_reg tcg_gen_remu_i64 105eaa3783bSRichard Henderson #define tcg_gen_discard_reg tcg_gen_discard_i64 106eaa3783bSRichard Henderson #define tcg_gen_trunc_reg_i32 tcg_gen_extrl_i64_i32 107eaa3783bSRichard Henderson #define tcg_gen_trunc_i64_reg tcg_gen_mov_i64 108eaa3783bSRichard Henderson #define tcg_gen_extu_i32_reg tcg_gen_extu_i32_i64 109eaa3783bSRichard Henderson #define tcg_gen_ext_i32_reg tcg_gen_ext_i32_i64 110eaa3783bSRichard Henderson #define tcg_gen_extu_reg_i64 tcg_gen_mov_i64 111eaa3783bSRichard Henderson #define tcg_gen_ext_reg_i64 tcg_gen_mov_i64 112eaa3783bSRichard Henderson #define tcg_gen_ext8u_reg tcg_gen_ext8u_i64 113eaa3783bSRichard Henderson #define tcg_gen_ext8s_reg tcg_gen_ext8s_i64 114eaa3783bSRichard Henderson #define tcg_gen_ext16u_reg tcg_gen_ext16u_i64 115eaa3783bSRichard Henderson #define tcg_gen_ext16s_reg tcg_gen_ext16s_i64 116eaa3783bSRichard Henderson #define tcg_gen_ext32u_reg tcg_gen_ext32u_i64 117eaa3783bSRichard Henderson #define tcg_gen_ext32s_reg tcg_gen_ext32s_i64 118eaa3783bSRichard Henderson #define tcg_gen_bswap16_reg tcg_gen_bswap16_i64 119eaa3783bSRichard Henderson #define tcg_gen_bswap32_reg tcg_gen_bswap32_i64 120eaa3783bSRichard Henderson #define tcg_gen_bswap64_reg tcg_gen_bswap64_i64 121eaa3783bSRichard Henderson #define tcg_gen_concat_reg_i64 tcg_gen_concat32_i64 122eaa3783bSRichard Henderson #define tcg_gen_andc_reg tcg_gen_andc_i64 123eaa3783bSRichard Henderson #define tcg_gen_eqv_reg tcg_gen_eqv_i64 124eaa3783bSRichard Henderson #define tcg_gen_nand_reg tcg_gen_nand_i64 125eaa3783bSRichard Henderson #define tcg_gen_nor_reg tcg_gen_nor_i64 126eaa3783bSRichard Henderson #define tcg_gen_orc_reg tcg_gen_orc_i64 127eaa3783bSRichard Henderson #define tcg_gen_clz_reg tcg_gen_clz_i64 128eaa3783bSRichard Henderson #define tcg_gen_ctz_reg tcg_gen_ctz_i64 129eaa3783bSRichard Henderson #define tcg_gen_clzi_reg tcg_gen_clzi_i64 130eaa3783bSRichard Henderson #define tcg_gen_ctzi_reg tcg_gen_ctzi_i64 131eaa3783bSRichard Henderson #define tcg_gen_clrsb_reg tcg_gen_clrsb_i64 132eaa3783bSRichard Henderson #define tcg_gen_ctpop_reg tcg_gen_ctpop_i64 133eaa3783bSRichard Henderson #define tcg_gen_rotl_reg tcg_gen_rotl_i64 134eaa3783bSRichard Henderson #define tcg_gen_rotli_reg tcg_gen_rotli_i64 135eaa3783bSRichard Henderson #define tcg_gen_rotr_reg tcg_gen_rotr_i64 136eaa3783bSRichard Henderson #define tcg_gen_rotri_reg tcg_gen_rotri_i64 137eaa3783bSRichard Henderson #define tcg_gen_deposit_reg tcg_gen_deposit_i64 138eaa3783bSRichard Henderson #define tcg_gen_deposit_z_reg tcg_gen_deposit_z_i64 139eaa3783bSRichard Henderson #define tcg_gen_extract_reg tcg_gen_extract_i64 140eaa3783bSRichard Henderson #define tcg_gen_sextract_reg tcg_gen_sextract_i64 14105bfd4dbSRichard Henderson #define tcg_gen_extract2_reg tcg_gen_extract2_i64 14229dd6f64SRichard Henderson #define tcg_constant_reg tcg_constant_i64 143eaa3783bSRichard Henderson #define tcg_gen_movcond_reg tcg_gen_movcond_i64 144eaa3783bSRichard Henderson #define tcg_gen_add2_reg tcg_gen_add2_i64 145eaa3783bSRichard Henderson #define tcg_gen_sub2_reg tcg_gen_sub2_i64 146eaa3783bSRichard Henderson #define tcg_gen_qemu_ld_reg tcg_gen_qemu_ld_i64 147eaa3783bSRichard Henderson #define tcg_gen_qemu_st_reg tcg_gen_qemu_st_i64 148eaa3783bSRichard Henderson #define tcg_gen_atomic_xchg_reg tcg_gen_atomic_xchg_i64 1495bfa8034SRichard Henderson #define tcg_gen_trunc_reg_ptr tcg_gen_trunc_i64_ptr 150eaa3783bSRichard Henderson #else 151eaa3783bSRichard Henderson #define TCGv_reg TCGv_i32 152eaa3783bSRichard Henderson #define tcg_temp_new tcg_temp_new_i32 153eaa3783bSRichard Henderson #define tcg_global_mem_new tcg_global_mem_new_i32 154eaa3783bSRichard Henderson 155eaa3783bSRichard Henderson #define tcg_gen_movi_reg tcg_gen_movi_i32 156eaa3783bSRichard Henderson #define tcg_gen_mov_reg tcg_gen_mov_i32 157eaa3783bSRichard Henderson #define tcg_gen_ld8u_reg tcg_gen_ld8u_i32 158eaa3783bSRichard Henderson #define tcg_gen_ld8s_reg tcg_gen_ld8s_i32 159eaa3783bSRichard Henderson #define tcg_gen_ld16u_reg tcg_gen_ld16u_i32 160eaa3783bSRichard Henderson #define tcg_gen_ld16s_reg tcg_gen_ld16s_i32 161eaa3783bSRichard Henderson #define tcg_gen_ld32u_reg tcg_gen_ld_i32 162eaa3783bSRichard Henderson #define tcg_gen_ld32s_reg tcg_gen_ld_i32 163eaa3783bSRichard Henderson #define tcg_gen_ld_reg tcg_gen_ld_i32 164eaa3783bSRichard Henderson #define tcg_gen_st8_reg tcg_gen_st8_i32 165eaa3783bSRichard Henderson #define tcg_gen_st16_reg tcg_gen_st16_i32 166eaa3783bSRichard Henderson #define tcg_gen_st32_reg tcg_gen_st32_i32 167eaa3783bSRichard Henderson #define tcg_gen_st_reg tcg_gen_st_i32 168eaa3783bSRichard Henderson #define tcg_gen_add_reg tcg_gen_add_i32 169eaa3783bSRichard Henderson #define tcg_gen_addi_reg tcg_gen_addi_i32 170eaa3783bSRichard Henderson #define tcg_gen_sub_reg tcg_gen_sub_i32 171eaa3783bSRichard Henderson #define tcg_gen_neg_reg tcg_gen_neg_i32 172eaa3783bSRichard Henderson #define tcg_gen_subfi_reg tcg_gen_subfi_i32 173eaa3783bSRichard Henderson #define tcg_gen_subi_reg tcg_gen_subi_i32 174eaa3783bSRichard Henderson #define tcg_gen_and_reg tcg_gen_and_i32 175eaa3783bSRichard Henderson #define tcg_gen_andi_reg tcg_gen_andi_i32 176eaa3783bSRichard Henderson #define tcg_gen_or_reg tcg_gen_or_i32 177eaa3783bSRichard Henderson #define tcg_gen_ori_reg tcg_gen_ori_i32 178eaa3783bSRichard Henderson #define tcg_gen_xor_reg tcg_gen_xor_i32 179eaa3783bSRichard Henderson #define tcg_gen_xori_reg tcg_gen_xori_i32 180eaa3783bSRichard Henderson #define tcg_gen_not_reg tcg_gen_not_i32 181eaa3783bSRichard Henderson #define tcg_gen_shl_reg tcg_gen_shl_i32 182eaa3783bSRichard Henderson #define tcg_gen_shli_reg tcg_gen_shli_i32 183eaa3783bSRichard Henderson #define tcg_gen_shr_reg tcg_gen_shr_i32 184eaa3783bSRichard Henderson #define tcg_gen_shri_reg tcg_gen_shri_i32 185eaa3783bSRichard Henderson #define tcg_gen_sar_reg tcg_gen_sar_i32 186eaa3783bSRichard Henderson #define tcg_gen_sari_reg tcg_gen_sari_i32 187eaa3783bSRichard Henderson #define tcg_gen_brcond_reg tcg_gen_brcond_i32 188eaa3783bSRichard Henderson #define tcg_gen_brcondi_reg tcg_gen_brcondi_i32 189eaa3783bSRichard Henderson #define tcg_gen_setcond_reg tcg_gen_setcond_i32 190eaa3783bSRichard Henderson #define tcg_gen_setcondi_reg tcg_gen_setcondi_i32 191eaa3783bSRichard Henderson #define tcg_gen_mul_reg tcg_gen_mul_i32 192eaa3783bSRichard Henderson #define tcg_gen_muli_reg tcg_gen_muli_i32 193eaa3783bSRichard Henderson #define tcg_gen_div_reg tcg_gen_div_i32 194eaa3783bSRichard Henderson #define tcg_gen_rem_reg tcg_gen_rem_i32 195eaa3783bSRichard Henderson #define tcg_gen_divu_reg tcg_gen_divu_i32 196eaa3783bSRichard Henderson #define tcg_gen_remu_reg tcg_gen_remu_i32 197eaa3783bSRichard Henderson #define tcg_gen_discard_reg tcg_gen_discard_i32 198eaa3783bSRichard Henderson #define tcg_gen_trunc_reg_i32 tcg_gen_mov_i32 199eaa3783bSRichard Henderson #define tcg_gen_trunc_i64_reg tcg_gen_extrl_i64_i32 200eaa3783bSRichard Henderson #define tcg_gen_extu_i32_reg tcg_gen_mov_i32 201eaa3783bSRichard Henderson #define tcg_gen_ext_i32_reg tcg_gen_mov_i32 202eaa3783bSRichard Henderson #define tcg_gen_extu_reg_i64 tcg_gen_extu_i32_i64 203eaa3783bSRichard Henderson #define tcg_gen_ext_reg_i64 tcg_gen_ext_i32_i64 204eaa3783bSRichard Henderson #define tcg_gen_ext8u_reg tcg_gen_ext8u_i32 205eaa3783bSRichard Henderson #define tcg_gen_ext8s_reg tcg_gen_ext8s_i32 206eaa3783bSRichard Henderson #define tcg_gen_ext16u_reg tcg_gen_ext16u_i32 207eaa3783bSRichard Henderson #define tcg_gen_ext16s_reg tcg_gen_ext16s_i32 208eaa3783bSRichard Henderson #define tcg_gen_ext32u_reg tcg_gen_mov_i32 209eaa3783bSRichard Henderson #define tcg_gen_ext32s_reg tcg_gen_mov_i32 210eaa3783bSRichard Henderson #define tcg_gen_bswap16_reg tcg_gen_bswap16_i32 211eaa3783bSRichard Henderson #define tcg_gen_bswap32_reg tcg_gen_bswap32_i32 212eaa3783bSRichard Henderson #define tcg_gen_concat_reg_i64 tcg_gen_concat_i32_i64 213eaa3783bSRichard Henderson #define tcg_gen_andc_reg tcg_gen_andc_i32 214eaa3783bSRichard Henderson #define tcg_gen_eqv_reg tcg_gen_eqv_i32 215eaa3783bSRichard Henderson #define tcg_gen_nand_reg tcg_gen_nand_i32 216eaa3783bSRichard Henderson #define tcg_gen_nor_reg tcg_gen_nor_i32 217eaa3783bSRichard Henderson #define tcg_gen_orc_reg tcg_gen_orc_i32 218eaa3783bSRichard Henderson #define tcg_gen_clz_reg tcg_gen_clz_i32 219eaa3783bSRichard Henderson #define tcg_gen_ctz_reg tcg_gen_ctz_i32 220eaa3783bSRichard Henderson #define tcg_gen_clzi_reg tcg_gen_clzi_i32 221eaa3783bSRichard Henderson #define tcg_gen_ctzi_reg tcg_gen_ctzi_i32 222eaa3783bSRichard Henderson #define tcg_gen_clrsb_reg tcg_gen_clrsb_i32 223eaa3783bSRichard Henderson #define tcg_gen_ctpop_reg tcg_gen_ctpop_i32 224eaa3783bSRichard Henderson #define tcg_gen_rotl_reg tcg_gen_rotl_i32 225eaa3783bSRichard Henderson #define tcg_gen_rotli_reg tcg_gen_rotli_i32 226eaa3783bSRichard Henderson #define tcg_gen_rotr_reg tcg_gen_rotr_i32 227eaa3783bSRichard Henderson #define tcg_gen_rotri_reg tcg_gen_rotri_i32 228eaa3783bSRichard Henderson #define tcg_gen_deposit_reg tcg_gen_deposit_i32 229eaa3783bSRichard Henderson #define tcg_gen_deposit_z_reg tcg_gen_deposit_z_i32 230eaa3783bSRichard Henderson #define tcg_gen_extract_reg tcg_gen_extract_i32 231eaa3783bSRichard Henderson #define tcg_gen_sextract_reg tcg_gen_sextract_i32 23205bfd4dbSRichard Henderson #define tcg_gen_extract2_reg tcg_gen_extract2_i32 23329dd6f64SRichard Henderson #define tcg_constant_reg tcg_constant_i32 234eaa3783bSRichard Henderson #define tcg_gen_movcond_reg tcg_gen_movcond_i32 235eaa3783bSRichard Henderson #define tcg_gen_add2_reg tcg_gen_add2_i32 236eaa3783bSRichard Henderson #define tcg_gen_sub2_reg tcg_gen_sub2_i32 237eaa3783bSRichard Henderson #define tcg_gen_qemu_ld_reg tcg_gen_qemu_ld_i32 238eaa3783bSRichard Henderson #define tcg_gen_qemu_st_reg tcg_gen_qemu_st_i32 239eaa3783bSRichard Henderson #define tcg_gen_atomic_xchg_reg tcg_gen_atomic_xchg_i32 2405bfa8034SRichard Henderson #define tcg_gen_trunc_reg_ptr tcg_gen_ext_i32_ptr 241eaa3783bSRichard Henderson #endif /* TARGET_REGISTER_BITS */ 242eaa3783bSRichard Henderson 24361766fe9SRichard Henderson typedef struct DisasCond { 24461766fe9SRichard Henderson TCGCond c; 245eaa3783bSRichard Henderson TCGv_reg a0, a1; 24661766fe9SRichard Henderson } DisasCond; 24761766fe9SRichard Henderson 24861766fe9SRichard Henderson typedef struct DisasContext { 249d01a3625SRichard Henderson DisasContextBase base; 25061766fe9SRichard Henderson CPUState *cs; 25161766fe9SRichard Henderson 252eaa3783bSRichard Henderson target_ureg iaoq_f; 253eaa3783bSRichard Henderson target_ureg iaoq_b; 254eaa3783bSRichard Henderson target_ureg iaoq_n; 255eaa3783bSRichard Henderson TCGv_reg iaoq_n_var; 25661766fe9SRichard Henderson 25761766fe9SRichard Henderson DisasCond null_cond; 25861766fe9SRichard Henderson TCGLabel *null_lab; 25961766fe9SRichard Henderson 2601a19da0dSRichard Henderson uint32_t insn; 261494737b7SRichard Henderson uint32_t tb_flags; 2623d68ee7bSRichard Henderson int mmu_idx; 2633d68ee7bSRichard Henderson int privilege; 26461766fe9SRichard Henderson bool psw_n_nonzero; 265217d1a5eSRichard Henderson 266217d1a5eSRichard Henderson #ifdef CONFIG_USER_ONLY 267217d1a5eSRichard Henderson MemOp unalign; 268217d1a5eSRichard Henderson #endif 26961766fe9SRichard Henderson } DisasContext; 27061766fe9SRichard Henderson 271217d1a5eSRichard Henderson #ifdef CONFIG_USER_ONLY 272217d1a5eSRichard Henderson #define UNALIGN(C) (C)->unalign 273217d1a5eSRichard Henderson #else 2742d4afb03SRichard Henderson #define UNALIGN(C) MO_ALIGN 275217d1a5eSRichard Henderson #endif 276217d1a5eSRichard Henderson 277e36f27efSRichard Henderson /* Note that ssm/rsm instructions number PSW_W and PSW_E differently. */ 278451e4ffdSRichard Henderson static int expand_sm_imm(DisasContext *ctx, int val) 279e36f27efSRichard Henderson { 280e36f27efSRichard Henderson if (val & PSW_SM_E) { 281e36f27efSRichard Henderson val = (val & ~PSW_SM_E) | PSW_E; 282e36f27efSRichard Henderson } 283e36f27efSRichard Henderson if (val & PSW_SM_W) { 284e36f27efSRichard Henderson val = (val & ~PSW_SM_W) | PSW_W; 285e36f27efSRichard Henderson } 286e36f27efSRichard Henderson return val; 287e36f27efSRichard Henderson } 288e36f27efSRichard Henderson 289deee69a1SRichard Henderson /* Inverted space register indicates 0 means sr0 not inferred from base. */ 290451e4ffdSRichard Henderson static int expand_sr3x(DisasContext *ctx, int val) 291deee69a1SRichard Henderson { 292deee69a1SRichard Henderson return ~val; 293deee69a1SRichard Henderson } 294deee69a1SRichard Henderson 2951cd012a5SRichard Henderson /* Convert the M:A bits within a memory insn to the tri-state value 2961cd012a5SRichard Henderson we use for the final M. */ 297451e4ffdSRichard Henderson static int ma_to_m(DisasContext *ctx, int val) 2981cd012a5SRichard Henderson { 2991cd012a5SRichard Henderson return val & 2 ? (val & 1 ? -1 : 1) : 0; 3001cd012a5SRichard Henderson } 3011cd012a5SRichard Henderson 302740038d7SRichard Henderson /* Convert the sign of the displacement to a pre or post-modify. */ 303451e4ffdSRichard Henderson static int pos_to_m(DisasContext *ctx, int val) 304740038d7SRichard Henderson { 305740038d7SRichard Henderson return val ? 1 : -1; 306740038d7SRichard Henderson } 307740038d7SRichard Henderson 308451e4ffdSRichard Henderson static int neg_to_m(DisasContext *ctx, int val) 309740038d7SRichard Henderson { 310740038d7SRichard Henderson return val ? -1 : 1; 311740038d7SRichard Henderson } 312740038d7SRichard Henderson 313740038d7SRichard Henderson /* Used for branch targets and fp memory ops. */ 314451e4ffdSRichard Henderson static int expand_shl2(DisasContext *ctx, int val) 31501afb7beSRichard Henderson { 31601afb7beSRichard Henderson return val << 2; 31701afb7beSRichard Henderson } 31801afb7beSRichard Henderson 319740038d7SRichard Henderson /* Used for fp memory ops. */ 320451e4ffdSRichard Henderson static int expand_shl3(DisasContext *ctx, int val) 321740038d7SRichard Henderson { 322740038d7SRichard Henderson return val << 3; 323740038d7SRichard Henderson } 324740038d7SRichard Henderson 3250588e061SRichard Henderson /* Used for assemble_21. */ 326451e4ffdSRichard Henderson static int expand_shl11(DisasContext *ctx, int val) 3270588e061SRichard Henderson { 3280588e061SRichard Henderson return val << 11; 3290588e061SRichard Henderson } 3300588e061SRichard Henderson 33101afb7beSRichard Henderson 33240f9f908SRichard Henderson /* Include the auto-generated decoder. */ 333abff1abfSPaolo Bonzini #include "decode-insns.c.inc" 33440f9f908SRichard Henderson 33561766fe9SRichard Henderson /* We are not using a goto_tb (for whatever reason), but have updated 33661766fe9SRichard Henderson the iaq (for whatever reason), so don't do it again on exit. */ 337869051eaSRichard Henderson #define DISAS_IAQ_N_UPDATED DISAS_TARGET_0 33861766fe9SRichard Henderson 33961766fe9SRichard Henderson /* We are exiting the TB, but have neither emitted a goto_tb, nor 34061766fe9SRichard Henderson updated the iaq for the next instruction to be executed. */ 341869051eaSRichard Henderson #define DISAS_IAQ_N_STALE DISAS_TARGET_1 34261766fe9SRichard Henderson 343e1b5a5edSRichard Henderson /* Similarly, but we want to return to the main loop immediately 344e1b5a5edSRichard Henderson to recognize unmasked interrupts. */ 345e1b5a5edSRichard Henderson #define DISAS_IAQ_N_STALE_EXIT DISAS_TARGET_2 346c5d0aec2SRichard Henderson #define DISAS_EXIT DISAS_TARGET_3 347e1b5a5edSRichard Henderson 34861766fe9SRichard Henderson /* global register indexes */ 349eaa3783bSRichard Henderson static TCGv_reg cpu_gr[32]; 35033423472SRichard Henderson static TCGv_i64 cpu_sr[4]; 351494737b7SRichard Henderson static TCGv_i64 cpu_srH; 352eaa3783bSRichard Henderson static TCGv_reg cpu_iaoq_f; 353eaa3783bSRichard Henderson static TCGv_reg cpu_iaoq_b; 354c301f34eSRichard Henderson static TCGv_i64 cpu_iasq_f; 355c301f34eSRichard Henderson static TCGv_i64 cpu_iasq_b; 356eaa3783bSRichard Henderson static TCGv_reg cpu_sar; 357eaa3783bSRichard Henderson static TCGv_reg cpu_psw_n; 358eaa3783bSRichard Henderson static TCGv_reg cpu_psw_v; 359eaa3783bSRichard Henderson static TCGv_reg cpu_psw_cb; 360eaa3783bSRichard Henderson static TCGv_reg cpu_psw_cb_msb; 36161766fe9SRichard Henderson 36261766fe9SRichard Henderson void hppa_translate_init(void) 36361766fe9SRichard Henderson { 36461766fe9SRichard Henderson #define DEF_VAR(V) { &cpu_##V, #V, offsetof(CPUHPPAState, V) } 36561766fe9SRichard Henderson 366eaa3783bSRichard Henderson typedef struct { TCGv_reg *var; const char *name; int ofs; } GlobalVar; 36761766fe9SRichard Henderson static const GlobalVar vars[] = { 36835136a77SRichard Henderson { &cpu_sar, "sar", offsetof(CPUHPPAState, cr[CR_SAR]) }, 36961766fe9SRichard Henderson DEF_VAR(psw_n), 37061766fe9SRichard Henderson DEF_VAR(psw_v), 37161766fe9SRichard Henderson DEF_VAR(psw_cb), 37261766fe9SRichard Henderson DEF_VAR(psw_cb_msb), 37361766fe9SRichard Henderson DEF_VAR(iaoq_f), 37461766fe9SRichard Henderson DEF_VAR(iaoq_b), 37561766fe9SRichard Henderson }; 37661766fe9SRichard Henderson 37761766fe9SRichard Henderson #undef DEF_VAR 37861766fe9SRichard Henderson 37961766fe9SRichard Henderson /* Use the symbolic register names that match the disassembler. */ 38061766fe9SRichard Henderson static const char gr_names[32][4] = { 38161766fe9SRichard Henderson "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", 38261766fe9SRichard Henderson "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", 38361766fe9SRichard Henderson "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", 38461766fe9SRichard Henderson "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31" 38561766fe9SRichard Henderson }; 38633423472SRichard Henderson /* SR[4-7] are not global registers so that we can index them. */ 387494737b7SRichard Henderson static const char sr_names[5][4] = { 388494737b7SRichard Henderson "sr0", "sr1", "sr2", "sr3", "srH" 38933423472SRichard Henderson }; 39061766fe9SRichard Henderson 39161766fe9SRichard Henderson int i; 39261766fe9SRichard Henderson 393f764718dSRichard Henderson cpu_gr[0] = NULL; 39461766fe9SRichard Henderson for (i = 1; i < 32; i++) { 395ad75a51eSRichard Henderson cpu_gr[i] = tcg_global_mem_new(tcg_env, 39661766fe9SRichard Henderson offsetof(CPUHPPAState, gr[i]), 39761766fe9SRichard Henderson gr_names[i]); 39861766fe9SRichard Henderson } 39933423472SRichard Henderson for (i = 0; i < 4; i++) { 400ad75a51eSRichard Henderson cpu_sr[i] = tcg_global_mem_new_i64(tcg_env, 40133423472SRichard Henderson offsetof(CPUHPPAState, sr[i]), 40233423472SRichard Henderson sr_names[i]); 40333423472SRichard Henderson } 404ad75a51eSRichard Henderson cpu_srH = tcg_global_mem_new_i64(tcg_env, 405494737b7SRichard Henderson offsetof(CPUHPPAState, sr[4]), 406494737b7SRichard Henderson sr_names[4]); 40761766fe9SRichard Henderson 40861766fe9SRichard Henderson for (i = 0; i < ARRAY_SIZE(vars); ++i) { 40961766fe9SRichard Henderson const GlobalVar *v = &vars[i]; 410ad75a51eSRichard Henderson *v->var = tcg_global_mem_new(tcg_env, v->ofs, v->name); 41161766fe9SRichard Henderson } 412c301f34eSRichard Henderson 413ad75a51eSRichard Henderson cpu_iasq_f = tcg_global_mem_new_i64(tcg_env, 414c301f34eSRichard Henderson offsetof(CPUHPPAState, iasq_f), 415c301f34eSRichard Henderson "iasq_f"); 416ad75a51eSRichard Henderson cpu_iasq_b = tcg_global_mem_new_i64(tcg_env, 417c301f34eSRichard Henderson offsetof(CPUHPPAState, iasq_b), 418c301f34eSRichard Henderson "iasq_b"); 41961766fe9SRichard Henderson } 42061766fe9SRichard Henderson 421129e9cc3SRichard Henderson static DisasCond cond_make_f(void) 422129e9cc3SRichard Henderson { 423f764718dSRichard Henderson return (DisasCond){ 424f764718dSRichard Henderson .c = TCG_COND_NEVER, 425f764718dSRichard Henderson .a0 = NULL, 426f764718dSRichard Henderson .a1 = NULL, 427f764718dSRichard Henderson }; 428129e9cc3SRichard Henderson } 429129e9cc3SRichard Henderson 430df0232feSRichard Henderson static DisasCond cond_make_t(void) 431df0232feSRichard Henderson { 432df0232feSRichard Henderson return (DisasCond){ 433df0232feSRichard Henderson .c = TCG_COND_ALWAYS, 434df0232feSRichard Henderson .a0 = NULL, 435df0232feSRichard Henderson .a1 = NULL, 436df0232feSRichard Henderson }; 437df0232feSRichard Henderson } 438df0232feSRichard Henderson 439129e9cc3SRichard Henderson static DisasCond cond_make_n(void) 440129e9cc3SRichard Henderson { 441f764718dSRichard Henderson return (DisasCond){ 442f764718dSRichard Henderson .c = TCG_COND_NE, 443f764718dSRichard Henderson .a0 = cpu_psw_n, 4446e94937aSRichard Henderson .a1 = tcg_constant_reg(0) 445f764718dSRichard Henderson }; 446129e9cc3SRichard Henderson } 447129e9cc3SRichard Henderson 448b47a4a02SSven Schnelle static DisasCond cond_make_0_tmp(TCGCond c, TCGv_reg a0) 449b47a4a02SSven Schnelle { 450b47a4a02SSven Schnelle assert (c != TCG_COND_NEVER && c != TCG_COND_ALWAYS); 451b47a4a02SSven Schnelle return (DisasCond){ 4526e94937aSRichard Henderson .c = c, .a0 = a0, .a1 = tcg_constant_reg(0) 453b47a4a02SSven Schnelle }; 454b47a4a02SSven Schnelle } 455b47a4a02SSven Schnelle 456eaa3783bSRichard Henderson static DisasCond cond_make_0(TCGCond c, TCGv_reg a0) 457129e9cc3SRichard Henderson { 458b47a4a02SSven Schnelle TCGv_reg tmp = tcg_temp_new(); 459b47a4a02SSven Schnelle tcg_gen_mov_reg(tmp, a0); 460b47a4a02SSven Schnelle return cond_make_0_tmp(c, tmp); 461129e9cc3SRichard Henderson } 462129e9cc3SRichard Henderson 463eaa3783bSRichard Henderson static DisasCond cond_make(TCGCond c, TCGv_reg a0, TCGv_reg a1) 464129e9cc3SRichard Henderson { 465129e9cc3SRichard Henderson DisasCond r = { .c = c }; 466129e9cc3SRichard Henderson 467129e9cc3SRichard Henderson assert (c != TCG_COND_NEVER && c != TCG_COND_ALWAYS); 468129e9cc3SRichard Henderson r.a0 = tcg_temp_new(); 469eaa3783bSRichard Henderson tcg_gen_mov_reg(r.a0, a0); 470129e9cc3SRichard Henderson r.a1 = tcg_temp_new(); 471eaa3783bSRichard Henderson tcg_gen_mov_reg(r.a1, a1); 472129e9cc3SRichard Henderson 473129e9cc3SRichard Henderson return r; 474129e9cc3SRichard Henderson } 475129e9cc3SRichard Henderson 476129e9cc3SRichard Henderson static void cond_free(DisasCond *cond) 477129e9cc3SRichard Henderson { 478129e9cc3SRichard Henderson switch (cond->c) { 479129e9cc3SRichard Henderson default: 480f764718dSRichard Henderson cond->a0 = NULL; 481f764718dSRichard Henderson cond->a1 = NULL; 482129e9cc3SRichard Henderson /* fallthru */ 483129e9cc3SRichard Henderson case TCG_COND_ALWAYS: 484129e9cc3SRichard Henderson cond->c = TCG_COND_NEVER; 485129e9cc3SRichard Henderson break; 486129e9cc3SRichard Henderson case TCG_COND_NEVER: 487129e9cc3SRichard Henderson break; 488129e9cc3SRichard Henderson } 489129e9cc3SRichard Henderson } 490129e9cc3SRichard Henderson 491eaa3783bSRichard Henderson static TCGv_reg load_gpr(DisasContext *ctx, unsigned reg) 49261766fe9SRichard Henderson { 49361766fe9SRichard Henderson if (reg == 0) { 494e12c6309SRichard Henderson TCGv_reg t = tcg_temp_new(); 495eaa3783bSRichard Henderson tcg_gen_movi_reg(t, 0); 49661766fe9SRichard Henderson return t; 49761766fe9SRichard Henderson } else { 49861766fe9SRichard Henderson return cpu_gr[reg]; 49961766fe9SRichard Henderson } 50061766fe9SRichard Henderson } 50161766fe9SRichard Henderson 502eaa3783bSRichard Henderson static TCGv_reg dest_gpr(DisasContext *ctx, unsigned reg) 50361766fe9SRichard Henderson { 504129e9cc3SRichard Henderson if (reg == 0 || ctx->null_cond.c != TCG_COND_NEVER) { 505e12c6309SRichard Henderson return tcg_temp_new(); 50661766fe9SRichard Henderson } else { 50761766fe9SRichard Henderson return cpu_gr[reg]; 50861766fe9SRichard Henderson } 50961766fe9SRichard Henderson } 51061766fe9SRichard Henderson 511eaa3783bSRichard Henderson static void save_or_nullify(DisasContext *ctx, TCGv_reg dest, TCGv_reg t) 512129e9cc3SRichard Henderson { 513129e9cc3SRichard Henderson if (ctx->null_cond.c != TCG_COND_NEVER) { 514eaa3783bSRichard Henderson tcg_gen_movcond_reg(ctx->null_cond.c, dest, ctx->null_cond.a0, 515129e9cc3SRichard Henderson ctx->null_cond.a1, dest, t); 516129e9cc3SRichard Henderson } else { 517eaa3783bSRichard Henderson tcg_gen_mov_reg(dest, t); 518129e9cc3SRichard Henderson } 519129e9cc3SRichard Henderson } 520129e9cc3SRichard Henderson 521eaa3783bSRichard Henderson static void save_gpr(DisasContext *ctx, unsigned reg, TCGv_reg t) 522129e9cc3SRichard Henderson { 523129e9cc3SRichard Henderson if (reg != 0) { 524129e9cc3SRichard Henderson save_or_nullify(ctx, cpu_gr[reg], t); 525129e9cc3SRichard Henderson } 526129e9cc3SRichard Henderson } 527129e9cc3SRichard Henderson 528e03b5686SMarc-André Lureau #if HOST_BIG_ENDIAN 52996d6407fSRichard Henderson # define HI_OFS 0 53096d6407fSRichard Henderson # define LO_OFS 4 53196d6407fSRichard Henderson #else 53296d6407fSRichard Henderson # define HI_OFS 4 53396d6407fSRichard Henderson # define LO_OFS 0 53496d6407fSRichard Henderson #endif 53596d6407fSRichard Henderson 53696d6407fSRichard Henderson static TCGv_i32 load_frw_i32(unsigned rt) 53796d6407fSRichard Henderson { 53896d6407fSRichard Henderson TCGv_i32 ret = tcg_temp_new_i32(); 539ad75a51eSRichard Henderson tcg_gen_ld_i32(ret, tcg_env, 54096d6407fSRichard Henderson offsetof(CPUHPPAState, fr[rt & 31]) 54196d6407fSRichard Henderson + (rt & 32 ? LO_OFS : HI_OFS)); 54296d6407fSRichard Henderson return ret; 54396d6407fSRichard Henderson } 54496d6407fSRichard Henderson 545ebe9383cSRichard Henderson static TCGv_i32 load_frw0_i32(unsigned rt) 546ebe9383cSRichard Henderson { 547ebe9383cSRichard Henderson if (rt == 0) { 5480992a930SRichard Henderson TCGv_i32 ret = tcg_temp_new_i32(); 5490992a930SRichard Henderson tcg_gen_movi_i32(ret, 0); 5500992a930SRichard Henderson return ret; 551ebe9383cSRichard Henderson } else { 552ebe9383cSRichard Henderson return load_frw_i32(rt); 553ebe9383cSRichard Henderson } 554ebe9383cSRichard Henderson } 555ebe9383cSRichard Henderson 556ebe9383cSRichard Henderson static TCGv_i64 load_frw0_i64(unsigned rt) 557ebe9383cSRichard Henderson { 558ebe9383cSRichard Henderson TCGv_i64 ret = tcg_temp_new_i64(); 5590992a930SRichard Henderson if (rt == 0) { 5600992a930SRichard Henderson tcg_gen_movi_i64(ret, 0); 5610992a930SRichard Henderson } else { 562ad75a51eSRichard Henderson tcg_gen_ld32u_i64(ret, tcg_env, 563ebe9383cSRichard Henderson offsetof(CPUHPPAState, fr[rt & 31]) 564ebe9383cSRichard Henderson + (rt & 32 ? LO_OFS : HI_OFS)); 565ebe9383cSRichard Henderson } 5660992a930SRichard Henderson return ret; 567ebe9383cSRichard Henderson } 568ebe9383cSRichard Henderson 56996d6407fSRichard Henderson static void save_frw_i32(unsigned rt, TCGv_i32 val) 57096d6407fSRichard Henderson { 571ad75a51eSRichard Henderson tcg_gen_st_i32(val, tcg_env, 57296d6407fSRichard Henderson offsetof(CPUHPPAState, fr[rt & 31]) 57396d6407fSRichard Henderson + (rt & 32 ? LO_OFS : HI_OFS)); 57496d6407fSRichard Henderson } 57596d6407fSRichard Henderson 57696d6407fSRichard Henderson #undef HI_OFS 57796d6407fSRichard Henderson #undef LO_OFS 57896d6407fSRichard Henderson 57996d6407fSRichard Henderson static TCGv_i64 load_frd(unsigned rt) 58096d6407fSRichard Henderson { 58196d6407fSRichard Henderson TCGv_i64 ret = tcg_temp_new_i64(); 582ad75a51eSRichard Henderson tcg_gen_ld_i64(ret, tcg_env, offsetof(CPUHPPAState, fr[rt])); 58396d6407fSRichard Henderson return ret; 58496d6407fSRichard Henderson } 58596d6407fSRichard Henderson 586ebe9383cSRichard Henderson static TCGv_i64 load_frd0(unsigned rt) 587ebe9383cSRichard Henderson { 588ebe9383cSRichard Henderson if (rt == 0) { 5890992a930SRichard Henderson TCGv_i64 ret = tcg_temp_new_i64(); 5900992a930SRichard Henderson tcg_gen_movi_i64(ret, 0); 5910992a930SRichard Henderson return ret; 592ebe9383cSRichard Henderson } else { 593ebe9383cSRichard Henderson return load_frd(rt); 594ebe9383cSRichard Henderson } 595ebe9383cSRichard Henderson } 596ebe9383cSRichard Henderson 59796d6407fSRichard Henderson static void save_frd(unsigned rt, TCGv_i64 val) 59896d6407fSRichard Henderson { 599ad75a51eSRichard Henderson tcg_gen_st_i64(val, tcg_env, offsetof(CPUHPPAState, fr[rt])); 60096d6407fSRichard Henderson } 60196d6407fSRichard Henderson 60233423472SRichard Henderson static void load_spr(DisasContext *ctx, TCGv_i64 dest, unsigned reg) 60333423472SRichard Henderson { 60433423472SRichard Henderson #ifdef CONFIG_USER_ONLY 60533423472SRichard Henderson tcg_gen_movi_i64(dest, 0); 60633423472SRichard Henderson #else 60733423472SRichard Henderson if (reg < 4) { 60833423472SRichard Henderson tcg_gen_mov_i64(dest, cpu_sr[reg]); 609494737b7SRichard Henderson } else if (ctx->tb_flags & TB_FLAG_SR_SAME) { 610494737b7SRichard Henderson tcg_gen_mov_i64(dest, cpu_srH); 61133423472SRichard Henderson } else { 612ad75a51eSRichard Henderson tcg_gen_ld_i64(dest, tcg_env, offsetof(CPUHPPAState, sr[reg])); 61333423472SRichard Henderson } 61433423472SRichard Henderson #endif 61533423472SRichard Henderson } 61633423472SRichard Henderson 617129e9cc3SRichard Henderson /* Skip over the implementation of an insn that has been nullified. 618129e9cc3SRichard Henderson Use this when the insn is too complex for a conditional move. */ 619129e9cc3SRichard Henderson static void nullify_over(DisasContext *ctx) 620129e9cc3SRichard Henderson { 621129e9cc3SRichard Henderson if (ctx->null_cond.c != TCG_COND_NEVER) { 622129e9cc3SRichard Henderson /* The always condition should have been handled in the main loop. */ 623129e9cc3SRichard Henderson assert(ctx->null_cond.c != TCG_COND_ALWAYS); 624129e9cc3SRichard Henderson 625129e9cc3SRichard Henderson ctx->null_lab = gen_new_label(); 626129e9cc3SRichard Henderson 627129e9cc3SRichard Henderson /* If we're using PSW[N], copy it to a temp because... */ 6286e94937aSRichard Henderson if (ctx->null_cond.a0 == cpu_psw_n) { 629129e9cc3SRichard Henderson ctx->null_cond.a0 = tcg_temp_new(); 630eaa3783bSRichard Henderson tcg_gen_mov_reg(ctx->null_cond.a0, cpu_psw_n); 631129e9cc3SRichard Henderson } 632129e9cc3SRichard Henderson /* ... we clear it before branching over the implementation, 633129e9cc3SRichard Henderson so that (1) it's clear after nullifying this insn and 634129e9cc3SRichard Henderson (2) if this insn nullifies the next, PSW[N] is valid. */ 635129e9cc3SRichard Henderson if (ctx->psw_n_nonzero) { 636129e9cc3SRichard Henderson ctx->psw_n_nonzero = false; 637eaa3783bSRichard Henderson tcg_gen_movi_reg(cpu_psw_n, 0); 638129e9cc3SRichard Henderson } 639129e9cc3SRichard Henderson 640eaa3783bSRichard Henderson tcg_gen_brcond_reg(ctx->null_cond.c, ctx->null_cond.a0, 641129e9cc3SRichard Henderson ctx->null_cond.a1, ctx->null_lab); 642129e9cc3SRichard Henderson cond_free(&ctx->null_cond); 643129e9cc3SRichard Henderson } 644129e9cc3SRichard Henderson } 645129e9cc3SRichard Henderson 646129e9cc3SRichard Henderson /* Save the current nullification state to PSW[N]. */ 647129e9cc3SRichard Henderson static void nullify_save(DisasContext *ctx) 648129e9cc3SRichard Henderson { 649129e9cc3SRichard Henderson if (ctx->null_cond.c == TCG_COND_NEVER) { 650129e9cc3SRichard Henderson if (ctx->psw_n_nonzero) { 651eaa3783bSRichard Henderson tcg_gen_movi_reg(cpu_psw_n, 0); 652129e9cc3SRichard Henderson } 653129e9cc3SRichard Henderson return; 654129e9cc3SRichard Henderson } 6556e94937aSRichard Henderson if (ctx->null_cond.a0 != cpu_psw_n) { 656eaa3783bSRichard Henderson tcg_gen_setcond_reg(ctx->null_cond.c, cpu_psw_n, 657129e9cc3SRichard Henderson ctx->null_cond.a0, ctx->null_cond.a1); 658129e9cc3SRichard Henderson ctx->psw_n_nonzero = true; 659129e9cc3SRichard Henderson } 660129e9cc3SRichard Henderson cond_free(&ctx->null_cond); 661129e9cc3SRichard Henderson } 662129e9cc3SRichard Henderson 663129e9cc3SRichard Henderson /* Set a PSW[N] to X. The intention is that this is used immediately 664129e9cc3SRichard Henderson before a goto_tb/exit_tb, so that there is no fallthru path to other 665129e9cc3SRichard Henderson code within the TB. Therefore we do not update psw_n_nonzero. */ 666129e9cc3SRichard Henderson static void nullify_set(DisasContext *ctx, bool x) 667129e9cc3SRichard Henderson { 668129e9cc3SRichard Henderson if (ctx->psw_n_nonzero || x) { 669eaa3783bSRichard Henderson tcg_gen_movi_reg(cpu_psw_n, x); 670129e9cc3SRichard Henderson } 671129e9cc3SRichard Henderson } 672129e9cc3SRichard Henderson 673129e9cc3SRichard Henderson /* Mark the end of an instruction that may have been nullified. 67440f9f908SRichard Henderson This is the pair to nullify_over. Always returns true so that 67540f9f908SRichard Henderson it may be tail-called from a translate function. */ 67631234768SRichard Henderson static bool nullify_end(DisasContext *ctx) 677129e9cc3SRichard Henderson { 678129e9cc3SRichard Henderson TCGLabel *null_lab = ctx->null_lab; 67931234768SRichard Henderson DisasJumpType status = ctx->base.is_jmp; 680129e9cc3SRichard Henderson 681f49b3537SRichard Henderson /* For NEXT, NORETURN, STALE, we can easily continue (or exit). 682f49b3537SRichard Henderson For UPDATED, we cannot update on the nullified path. */ 683f49b3537SRichard Henderson assert(status != DISAS_IAQ_N_UPDATED); 684f49b3537SRichard Henderson 685129e9cc3SRichard Henderson if (likely(null_lab == NULL)) { 686129e9cc3SRichard Henderson /* The current insn wasn't conditional or handled the condition 687129e9cc3SRichard Henderson applied to it without a branch, so the (new) setting of 688129e9cc3SRichard Henderson NULL_COND can be applied directly to the next insn. */ 68931234768SRichard Henderson return true; 690129e9cc3SRichard Henderson } 691129e9cc3SRichard Henderson ctx->null_lab = NULL; 692129e9cc3SRichard Henderson 693129e9cc3SRichard Henderson if (likely(ctx->null_cond.c == TCG_COND_NEVER)) { 694129e9cc3SRichard Henderson /* The next instruction will be unconditional, 695129e9cc3SRichard Henderson and NULL_COND already reflects that. */ 696129e9cc3SRichard Henderson gen_set_label(null_lab); 697129e9cc3SRichard Henderson } else { 698129e9cc3SRichard Henderson /* The insn that we just executed is itself nullifying the next 699129e9cc3SRichard Henderson instruction. Store the condition in the PSW[N] global. 700129e9cc3SRichard Henderson We asserted PSW[N] = 0 in nullify_over, so that after the 701129e9cc3SRichard Henderson label we have the proper value in place. */ 702129e9cc3SRichard Henderson nullify_save(ctx); 703129e9cc3SRichard Henderson gen_set_label(null_lab); 704129e9cc3SRichard Henderson ctx->null_cond = cond_make_n(); 705129e9cc3SRichard Henderson } 706869051eaSRichard Henderson if (status == DISAS_NORETURN) { 70731234768SRichard Henderson ctx->base.is_jmp = DISAS_NEXT; 708129e9cc3SRichard Henderson } 70931234768SRichard Henderson return true; 710129e9cc3SRichard Henderson } 711129e9cc3SRichard Henderson 712eaa3783bSRichard Henderson static void copy_iaoq_entry(TCGv_reg dest, target_ureg ival, TCGv_reg vval) 71361766fe9SRichard Henderson { 71461766fe9SRichard Henderson if (unlikely(ival == -1)) { 715eaa3783bSRichard Henderson tcg_gen_mov_reg(dest, vval); 71661766fe9SRichard Henderson } else { 717eaa3783bSRichard Henderson tcg_gen_movi_reg(dest, ival); 71861766fe9SRichard Henderson } 71961766fe9SRichard Henderson } 72061766fe9SRichard Henderson 721eaa3783bSRichard Henderson static inline target_ureg iaoq_dest(DisasContext *ctx, target_sreg disp) 72261766fe9SRichard Henderson { 72361766fe9SRichard Henderson return ctx->iaoq_f + disp + 8; 72461766fe9SRichard Henderson } 72561766fe9SRichard Henderson 72661766fe9SRichard Henderson static void gen_excp_1(int exception) 72761766fe9SRichard Henderson { 728ad75a51eSRichard Henderson gen_helper_excp(tcg_env, tcg_constant_i32(exception)); 72961766fe9SRichard Henderson } 73061766fe9SRichard Henderson 73131234768SRichard Henderson static void gen_excp(DisasContext *ctx, int exception) 73261766fe9SRichard Henderson { 73361766fe9SRichard Henderson copy_iaoq_entry(cpu_iaoq_f, ctx->iaoq_f, cpu_iaoq_f); 73461766fe9SRichard Henderson copy_iaoq_entry(cpu_iaoq_b, ctx->iaoq_b, cpu_iaoq_b); 735129e9cc3SRichard Henderson nullify_save(ctx); 73661766fe9SRichard Henderson gen_excp_1(exception); 73731234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 73861766fe9SRichard Henderson } 73961766fe9SRichard Henderson 74031234768SRichard Henderson static bool gen_excp_iir(DisasContext *ctx, int exc) 7411a19da0dSRichard Henderson { 74231234768SRichard Henderson nullify_over(ctx); 74329dd6f64SRichard Henderson tcg_gen_st_reg(tcg_constant_reg(ctx->insn), 744ad75a51eSRichard Henderson tcg_env, offsetof(CPUHPPAState, cr[CR_IIR])); 74531234768SRichard Henderson gen_excp(ctx, exc); 74631234768SRichard Henderson return nullify_end(ctx); 7471a19da0dSRichard Henderson } 7481a19da0dSRichard Henderson 74931234768SRichard Henderson static bool gen_illegal(DisasContext *ctx) 75061766fe9SRichard Henderson { 75131234768SRichard Henderson return gen_excp_iir(ctx, EXCP_ILL); 75261766fe9SRichard Henderson } 75361766fe9SRichard Henderson 75440f9f908SRichard Henderson #ifdef CONFIG_USER_ONLY 75540f9f908SRichard Henderson #define CHECK_MOST_PRIVILEGED(EXCP) \ 75640f9f908SRichard Henderson return gen_excp_iir(ctx, EXCP) 75740f9f908SRichard Henderson #else 758e1b5a5edSRichard Henderson #define CHECK_MOST_PRIVILEGED(EXCP) \ 759e1b5a5edSRichard Henderson do { \ 760e1b5a5edSRichard Henderson if (ctx->privilege != 0) { \ 76131234768SRichard Henderson return gen_excp_iir(ctx, EXCP); \ 762e1b5a5edSRichard Henderson } \ 763e1b5a5edSRichard Henderson } while (0) 76440f9f908SRichard Henderson #endif 765e1b5a5edSRichard Henderson 766eaa3783bSRichard Henderson static bool use_goto_tb(DisasContext *ctx, target_ureg dest) 76761766fe9SRichard Henderson { 76857f91498SRichard Henderson return translator_use_goto_tb(&ctx->base, dest); 76961766fe9SRichard Henderson } 77061766fe9SRichard Henderson 771129e9cc3SRichard Henderson /* If the next insn is to be nullified, and it's on the same page, 772129e9cc3SRichard Henderson and we're not attempting to set a breakpoint on it, then we can 773129e9cc3SRichard Henderson totally skip the nullified insn. This avoids creating and 774129e9cc3SRichard Henderson executing a TB that merely branches to the next TB. */ 775129e9cc3SRichard Henderson static bool use_nullify_skip(DisasContext *ctx) 776129e9cc3SRichard Henderson { 777129e9cc3SRichard Henderson return (((ctx->iaoq_b ^ ctx->iaoq_f) & TARGET_PAGE_MASK) == 0 778129e9cc3SRichard Henderson && !cpu_breakpoint_test(ctx->cs, ctx->iaoq_b, BP_ANY)); 779129e9cc3SRichard Henderson } 780129e9cc3SRichard Henderson 78161766fe9SRichard Henderson static void gen_goto_tb(DisasContext *ctx, int which, 782eaa3783bSRichard Henderson target_ureg f, target_ureg b) 78361766fe9SRichard Henderson { 78461766fe9SRichard Henderson if (f != -1 && b != -1 && use_goto_tb(ctx, f)) { 78561766fe9SRichard Henderson tcg_gen_goto_tb(which); 786eaa3783bSRichard Henderson tcg_gen_movi_reg(cpu_iaoq_f, f); 787eaa3783bSRichard Henderson tcg_gen_movi_reg(cpu_iaoq_b, b); 78807ea28b4SRichard Henderson tcg_gen_exit_tb(ctx->base.tb, which); 78961766fe9SRichard Henderson } else { 79061766fe9SRichard Henderson copy_iaoq_entry(cpu_iaoq_f, f, cpu_iaoq_b); 79161766fe9SRichard Henderson copy_iaoq_entry(cpu_iaoq_b, b, ctx->iaoq_n_var); 7927f11636dSEmilio G. Cota tcg_gen_lookup_and_goto_ptr(); 79361766fe9SRichard Henderson } 79461766fe9SRichard Henderson } 79561766fe9SRichard Henderson 796b47a4a02SSven Schnelle static bool cond_need_sv(int c) 797b47a4a02SSven Schnelle { 798b47a4a02SSven Schnelle return c == 2 || c == 3 || c == 6; 799b47a4a02SSven Schnelle } 800b47a4a02SSven Schnelle 801b47a4a02SSven Schnelle static bool cond_need_cb(int c) 802b47a4a02SSven Schnelle { 803b47a4a02SSven Schnelle return c == 4 || c == 5; 804b47a4a02SSven Schnelle } 805b47a4a02SSven Schnelle 80672ca8753SRichard Henderson /* Need extensions from TCGv_i32 to TCGv_reg. */ 80772ca8753SRichard Henderson static bool cond_need_ext(DisasContext *ctx, bool d) 80872ca8753SRichard Henderson { 80972ca8753SRichard Henderson return TARGET_REGISTER_BITS == 64 && !d; 81072ca8753SRichard Henderson } 81172ca8753SRichard Henderson 812b47a4a02SSven Schnelle /* 813b47a4a02SSven Schnelle * Compute conditional for arithmetic. See Page 5-3, Table 5-1, of 814b47a4a02SSven Schnelle * the Parisc 1.1 Architecture Reference Manual for details. 815b47a4a02SSven Schnelle */ 816b2167459SRichard Henderson 817eaa3783bSRichard Henderson static DisasCond do_cond(unsigned cf, TCGv_reg res, 818eaa3783bSRichard Henderson TCGv_reg cb_msb, TCGv_reg sv) 819b2167459SRichard Henderson { 820b2167459SRichard Henderson DisasCond cond; 821eaa3783bSRichard Henderson TCGv_reg tmp; 822b2167459SRichard Henderson 823b2167459SRichard Henderson switch (cf >> 1) { 824b47a4a02SSven Schnelle case 0: /* Never / TR (0 / 1) */ 825b2167459SRichard Henderson cond = cond_make_f(); 826b2167459SRichard Henderson break; 827b2167459SRichard Henderson case 1: /* = / <> (Z / !Z) */ 828b2167459SRichard Henderson cond = cond_make_0(TCG_COND_EQ, res); 829b2167459SRichard Henderson break; 830b47a4a02SSven Schnelle case 2: /* < / >= (N ^ V / !(N ^ V) */ 831b47a4a02SSven Schnelle tmp = tcg_temp_new(); 832b47a4a02SSven Schnelle tcg_gen_xor_reg(tmp, res, sv); 833b47a4a02SSven Schnelle cond = cond_make_0_tmp(TCG_COND_LT, tmp); 834b2167459SRichard Henderson break; 835b47a4a02SSven Schnelle case 3: /* <= / > (N ^ V) | Z / !((N ^ V) | Z) */ 836b47a4a02SSven Schnelle /* 837b47a4a02SSven Schnelle * Simplify: 838b47a4a02SSven Schnelle * (N ^ V) | Z 839b47a4a02SSven Schnelle * ((res < 0) ^ (sv < 0)) | !res 840b47a4a02SSven Schnelle * ((res ^ sv) < 0) | !res 841b47a4a02SSven Schnelle * (~(res ^ sv) >= 0) | !res 842b47a4a02SSven Schnelle * !(~(res ^ sv) >> 31) | !res 843b47a4a02SSven Schnelle * !(~(res ^ sv) >> 31 & res) 844b47a4a02SSven Schnelle */ 845b47a4a02SSven Schnelle tmp = tcg_temp_new(); 846b47a4a02SSven Schnelle tcg_gen_eqv_reg(tmp, res, sv); 847b47a4a02SSven Schnelle tcg_gen_sari_reg(tmp, tmp, TARGET_REGISTER_BITS - 1); 848b47a4a02SSven Schnelle tcg_gen_and_reg(tmp, tmp, res); 849b47a4a02SSven Schnelle cond = cond_make_0_tmp(TCG_COND_EQ, tmp); 850b2167459SRichard Henderson break; 851b2167459SRichard Henderson case 4: /* NUV / UV (!C / C) */ 852b2167459SRichard Henderson cond = cond_make_0(TCG_COND_EQ, cb_msb); 853b2167459SRichard Henderson break; 854b2167459SRichard Henderson case 5: /* ZNV / VNZ (!C | Z / C & !Z) */ 855b2167459SRichard Henderson tmp = tcg_temp_new(); 856eaa3783bSRichard Henderson tcg_gen_neg_reg(tmp, cb_msb); 857eaa3783bSRichard Henderson tcg_gen_and_reg(tmp, tmp, res); 858b47a4a02SSven Schnelle cond = cond_make_0_tmp(TCG_COND_EQ, tmp); 859b2167459SRichard Henderson break; 860b2167459SRichard Henderson case 6: /* SV / NSV (V / !V) */ 861b2167459SRichard Henderson cond = cond_make_0(TCG_COND_LT, sv); 862b2167459SRichard Henderson break; 863b2167459SRichard Henderson case 7: /* OD / EV */ 864b2167459SRichard Henderson tmp = tcg_temp_new(); 865eaa3783bSRichard Henderson tcg_gen_andi_reg(tmp, res, 1); 866b47a4a02SSven Schnelle cond = cond_make_0_tmp(TCG_COND_NE, tmp); 867b2167459SRichard Henderson break; 868b2167459SRichard Henderson default: 869b2167459SRichard Henderson g_assert_not_reached(); 870b2167459SRichard Henderson } 871b2167459SRichard Henderson if (cf & 1) { 872b2167459SRichard Henderson cond.c = tcg_invert_cond(cond.c); 873b2167459SRichard Henderson } 874b2167459SRichard Henderson 875b2167459SRichard Henderson return cond; 876b2167459SRichard Henderson } 877b2167459SRichard Henderson 878b2167459SRichard Henderson /* Similar, but for the special case of subtraction without borrow, we 879b2167459SRichard Henderson can use the inputs directly. This can allow other computation to be 880b2167459SRichard Henderson deleted as unused. */ 881b2167459SRichard Henderson 882eaa3783bSRichard Henderson static DisasCond do_sub_cond(unsigned cf, TCGv_reg res, 883eaa3783bSRichard Henderson TCGv_reg in1, TCGv_reg in2, TCGv_reg sv) 884b2167459SRichard Henderson { 885b2167459SRichard Henderson DisasCond cond; 886b2167459SRichard Henderson 887b2167459SRichard Henderson switch (cf >> 1) { 888b2167459SRichard Henderson case 1: /* = / <> */ 889b2167459SRichard Henderson cond = cond_make(TCG_COND_EQ, in1, in2); 890b2167459SRichard Henderson break; 891b2167459SRichard Henderson case 2: /* < / >= */ 892b2167459SRichard Henderson cond = cond_make(TCG_COND_LT, in1, in2); 893b2167459SRichard Henderson break; 894b2167459SRichard Henderson case 3: /* <= / > */ 895b2167459SRichard Henderson cond = cond_make(TCG_COND_LE, in1, in2); 896b2167459SRichard Henderson break; 897b2167459SRichard Henderson case 4: /* << / >>= */ 898b2167459SRichard Henderson cond = cond_make(TCG_COND_LTU, in1, in2); 899b2167459SRichard Henderson break; 900b2167459SRichard Henderson case 5: /* <<= / >> */ 901b2167459SRichard Henderson cond = cond_make(TCG_COND_LEU, in1, in2); 902b2167459SRichard Henderson break; 903b2167459SRichard Henderson default: 904b47a4a02SSven Schnelle return do_cond(cf, res, NULL, sv); 905b2167459SRichard Henderson } 906b2167459SRichard Henderson if (cf & 1) { 907b2167459SRichard Henderson cond.c = tcg_invert_cond(cond.c); 908b2167459SRichard Henderson } 909b2167459SRichard Henderson 910b2167459SRichard Henderson return cond; 911b2167459SRichard Henderson } 912b2167459SRichard Henderson 913df0232feSRichard Henderson /* 914df0232feSRichard Henderson * Similar, but for logicals, where the carry and overflow bits are not 915df0232feSRichard Henderson * computed, and use of them is undefined. 916df0232feSRichard Henderson * 917df0232feSRichard Henderson * Undefined or not, hardware does not trap. It seems reasonable to 918df0232feSRichard Henderson * assume hardware treats cases c={4,5,6} as if C=0 & V=0, since that's 919df0232feSRichard Henderson * how cases c={2,3} are treated. 920df0232feSRichard Henderson */ 921b2167459SRichard Henderson 922eaa3783bSRichard Henderson static DisasCond do_log_cond(unsigned cf, TCGv_reg res) 923b2167459SRichard Henderson { 924df0232feSRichard Henderson switch (cf) { 925df0232feSRichard Henderson case 0: /* never */ 926df0232feSRichard Henderson case 9: /* undef, C */ 927df0232feSRichard Henderson case 11: /* undef, C & !Z */ 928df0232feSRichard Henderson case 12: /* undef, V */ 929df0232feSRichard Henderson return cond_make_f(); 930df0232feSRichard Henderson 931df0232feSRichard Henderson case 1: /* true */ 932df0232feSRichard Henderson case 8: /* undef, !C */ 933df0232feSRichard Henderson case 10: /* undef, !C | Z */ 934df0232feSRichard Henderson case 13: /* undef, !V */ 935df0232feSRichard Henderson return cond_make_t(); 936df0232feSRichard Henderson 937df0232feSRichard Henderson case 2: /* == */ 938df0232feSRichard Henderson return cond_make_0(TCG_COND_EQ, res); 939df0232feSRichard Henderson case 3: /* <> */ 940df0232feSRichard Henderson return cond_make_0(TCG_COND_NE, res); 941df0232feSRichard Henderson case 4: /* < */ 942df0232feSRichard Henderson return cond_make_0(TCG_COND_LT, res); 943df0232feSRichard Henderson case 5: /* >= */ 944df0232feSRichard Henderson return cond_make_0(TCG_COND_GE, res); 945df0232feSRichard Henderson case 6: /* <= */ 946df0232feSRichard Henderson return cond_make_0(TCG_COND_LE, res); 947df0232feSRichard Henderson case 7: /* > */ 948df0232feSRichard Henderson return cond_make_0(TCG_COND_GT, res); 949df0232feSRichard Henderson 950df0232feSRichard Henderson case 14: /* OD */ 951df0232feSRichard Henderson case 15: /* EV */ 952df0232feSRichard Henderson return do_cond(cf, res, NULL, NULL); 953df0232feSRichard Henderson 954df0232feSRichard Henderson default: 955df0232feSRichard Henderson g_assert_not_reached(); 956b2167459SRichard Henderson } 957b2167459SRichard Henderson } 958b2167459SRichard Henderson 95998cd9ca7SRichard Henderson /* Similar, but for shift/extract/deposit conditions. */ 96098cd9ca7SRichard Henderson 961eaa3783bSRichard Henderson static DisasCond do_sed_cond(unsigned orig, TCGv_reg res) 96298cd9ca7SRichard Henderson { 96398cd9ca7SRichard Henderson unsigned c, f; 96498cd9ca7SRichard Henderson 96598cd9ca7SRichard Henderson /* Convert the compressed condition codes to standard. 96698cd9ca7SRichard Henderson 0-2 are the same as logicals (nv,<,<=), while 3 is OD. 96798cd9ca7SRichard Henderson 4-7 are the reverse of 0-3. */ 96898cd9ca7SRichard Henderson c = orig & 3; 96998cd9ca7SRichard Henderson if (c == 3) { 97098cd9ca7SRichard Henderson c = 7; 97198cd9ca7SRichard Henderson } 97298cd9ca7SRichard Henderson f = (orig & 4) / 4; 97398cd9ca7SRichard Henderson 97498cd9ca7SRichard Henderson return do_log_cond(c * 2 + f, res); 97598cd9ca7SRichard Henderson } 97698cd9ca7SRichard Henderson 977b2167459SRichard Henderson /* Similar, but for unit conditions. */ 978b2167459SRichard Henderson 979eaa3783bSRichard Henderson static DisasCond do_unit_cond(unsigned cf, TCGv_reg res, 980eaa3783bSRichard Henderson TCGv_reg in1, TCGv_reg in2) 981b2167459SRichard Henderson { 982b2167459SRichard Henderson DisasCond cond; 983eaa3783bSRichard Henderson TCGv_reg tmp, cb = NULL; 984b2167459SRichard Henderson 985b2167459SRichard Henderson if (cf & 8) { 986b2167459SRichard Henderson /* Since we want to test lots of carry-out bits all at once, do not 987b2167459SRichard Henderson * do our normal thing and compute carry-in of bit B+1 since that 988b2167459SRichard Henderson * leaves us with carry bits spread across two words. 989b2167459SRichard Henderson */ 990b2167459SRichard Henderson cb = tcg_temp_new(); 991b2167459SRichard Henderson tmp = tcg_temp_new(); 992eaa3783bSRichard Henderson tcg_gen_or_reg(cb, in1, in2); 993eaa3783bSRichard Henderson tcg_gen_and_reg(tmp, in1, in2); 994eaa3783bSRichard Henderson tcg_gen_andc_reg(cb, cb, res); 995eaa3783bSRichard Henderson tcg_gen_or_reg(cb, cb, tmp); 996b2167459SRichard Henderson } 997b2167459SRichard Henderson 998b2167459SRichard Henderson switch (cf >> 1) { 999b2167459SRichard Henderson case 0: /* never / TR */ 1000b2167459SRichard Henderson case 1: /* undefined */ 1001b2167459SRichard Henderson case 5: /* undefined */ 1002b2167459SRichard Henderson cond = cond_make_f(); 1003b2167459SRichard Henderson break; 1004b2167459SRichard Henderson 1005b2167459SRichard Henderson case 2: /* SBZ / NBZ */ 1006b2167459SRichard Henderson /* See hasless(v,1) from 1007b2167459SRichard Henderson * https://graphics.stanford.edu/~seander/bithacks.html#ZeroInWord 1008b2167459SRichard Henderson */ 1009b2167459SRichard Henderson tmp = tcg_temp_new(); 1010eaa3783bSRichard Henderson tcg_gen_subi_reg(tmp, res, 0x01010101u); 1011eaa3783bSRichard Henderson tcg_gen_andc_reg(tmp, tmp, res); 1012eaa3783bSRichard Henderson tcg_gen_andi_reg(tmp, tmp, 0x80808080u); 1013b2167459SRichard Henderson cond = cond_make_0(TCG_COND_NE, tmp); 1014b2167459SRichard Henderson break; 1015b2167459SRichard Henderson 1016b2167459SRichard Henderson case 3: /* SHZ / NHZ */ 1017b2167459SRichard Henderson tmp = tcg_temp_new(); 1018eaa3783bSRichard Henderson tcg_gen_subi_reg(tmp, res, 0x00010001u); 1019eaa3783bSRichard Henderson tcg_gen_andc_reg(tmp, tmp, res); 1020eaa3783bSRichard Henderson tcg_gen_andi_reg(tmp, tmp, 0x80008000u); 1021b2167459SRichard Henderson cond = cond_make_0(TCG_COND_NE, tmp); 1022b2167459SRichard Henderson break; 1023b2167459SRichard Henderson 1024b2167459SRichard Henderson case 4: /* SDC / NDC */ 1025eaa3783bSRichard Henderson tcg_gen_andi_reg(cb, cb, 0x88888888u); 1026b2167459SRichard Henderson cond = cond_make_0(TCG_COND_NE, cb); 1027b2167459SRichard Henderson break; 1028b2167459SRichard Henderson 1029b2167459SRichard Henderson case 6: /* SBC / NBC */ 1030eaa3783bSRichard Henderson tcg_gen_andi_reg(cb, cb, 0x80808080u); 1031b2167459SRichard Henderson cond = cond_make_0(TCG_COND_NE, cb); 1032b2167459SRichard Henderson break; 1033b2167459SRichard Henderson 1034b2167459SRichard Henderson case 7: /* SHC / NHC */ 1035eaa3783bSRichard Henderson tcg_gen_andi_reg(cb, cb, 0x80008000u); 1036b2167459SRichard Henderson cond = cond_make_0(TCG_COND_NE, cb); 1037b2167459SRichard Henderson break; 1038b2167459SRichard Henderson 1039b2167459SRichard Henderson default: 1040b2167459SRichard Henderson g_assert_not_reached(); 1041b2167459SRichard Henderson } 1042b2167459SRichard Henderson if (cf & 1) { 1043b2167459SRichard Henderson cond.c = tcg_invert_cond(cond.c); 1044b2167459SRichard Henderson } 1045b2167459SRichard Henderson 1046b2167459SRichard Henderson return cond; 1047b2167459SRichard Henderson } 1048b2167459SRichard Henderson 104972ca8753SRichard Henderson static TCGv_reg get_carry(DisasContext *ctx, bool d, 105072ca8753SRichard Henderson TCGv_reg cb, TCGv_reg cb_msb) 105172ca8753SRichard Henderson { 105272ca8753SRichard Henderson if (cond_need_ext(ctx, d)) { 105372ca8753SRichard Henderson TCGv_reg t = tcg_temp_new(); 105472ca8753SRichard Henderson tcg_gen_extract_reg(t, cb, 32, 1); 105572ca8753SRichard Henderson return t; 105672ca8753SRichard Henderson } 105772ca8753SRichard Henderson return cb_msb; 105872ca8753SRichard Henderson } 105972ca8753SRichard Henderson 106072ca8753SRichard Henderson static TCGv_reg get_psw_carry(DisasContext *ctx, bool d) 106172ca8753SRichard Henderson { 106272ca8753SRichard Henderson return get_carry(ctx, d, cpu_psw_cb, cpu_psw_cb_msb); 106372ca8753SRichard Henderson } 106472ca8753SRichard Henderson 1065b2167459SRichard Henderson /* Compute signed overflow for addition. */ 1066eaa3783bSRichard Henderson static TCGv_reg do_add_sv(DisasContext *ctx, TCGv_reg res, 1067eaa3783bSRichard Henderson TCGv_reg in1, TCGv_reg in2) 1068b2167459SRichard Henderson { 1069e12c6309SRichard Henderson TCGv_reg sv = tcg_temp_new(); 1070eaa3783bSRichard Henderson TCGv_reg tmp = tcg_temp_new(); 1071b2167459SRichard Henderson 1072eaa3783bSRichard Henderson tcg_gen_xor_reg(sv, res, in1); 1073eaa3783bSRichard Henderson tcg_gen_xor_reg(tmp, in1, in2); 1074eaa3783bSRichard Henderson tcg_gen_andc_reg(sv, sv, tmp); 1075b2167459SRichard Henderson 1076b2167459SRichard Henderson return sv; 1077b2167459SRichard Henderson } 1078b2167459SRichard Henderson 1079b2167459SRichard Henderson /* Compute signed overflow for subtraction. */ 1080eaa3783bSRichard Henderson static TCGv_reg do_sub_sv(DisasContext *ctx, TCGv_reg res, 1081eaa3783bSRichard Henderson TCGv_reg in1, TCGv_reg in2) 1082b2167459SRichard Henderson { 1083e12c6309SRichard Henderson TCGv_reg sv = tcg_temp_new(); 1084eaa3783bSRichard Henderson TCGv_reg tmp = tcg_temp_new(); 1085b2167459SRichard Henderson 1086eaa3783bSRichard Henderson tcg_gen_xor_reg(sv, res, in1); 1087eaa3783bSRichard Henderson tcg_gen_xor_reg(tmp, in1, in2); 1088eaa3783bSRichard Henderson tcg_gen_and_reg(sv, sv, tmp); 1089b2167459SRichard Henderson 1090b2167459SRichard Henderson return sv; 1091b2167459SRichard Henderson } 1092b2167459SRichard Henderson 109331234768SRichard Henderson static void do_add(DisasContext *ctx, unsigned rt, TCGv_reg in1, 1094eaa3783bSRichard Henderson TCGv_reg in2, unsigned shift, bool is_l, 1095eaa3783bSRichard Henderson bool is_tsv, bool is_tc, bool is_c, unsigned cf) 1096b2167459SRichard Henderson { 1097bdcccc17SRichard Henderson TCGv_reg dest, cb, cb_msb, cb_cond, sv, tmp; 1098b2167459SRichard Henderson unsigned c = cf >> 1; 1099b2167459SRichard Henderson DisasCond cond; 1100bdcccc17SRichard Henderson bool d = false; 1101b2167459SRichard Henderson 1102b2167459SRichard Henderson dest = tcg_temp_new(); 1103f764718dSRichard Henderson cb = NULL; 1104f764718dSRichard Henderson cb_msb = NULL; 1105bdcccc17SRichard Henderson cb_cond = NULL; 1106b2167459SRichard Henderson 1107b2167459SRichard Henderson if (shift) { 1108e12c6309SRichard Henderson tmp = tcg_temp_new(); 1109eaa3783bSRichard Henderson tcg_gen_shli_reg(tmp, in1, shift); 1110b2167459SRichard Henderson in1 = tmp; 1111b2167459SRichard Henderson } 1112b2167459SRichard Henderson 1113b47a4a02SSven Schnelle if (!is_l || cond_need_cb(c)) { 111429dd6f64SRichard Henderson TCGv_reg zero = tcg_constant_reg(0); 1115e12c6309SRichard Henderson cb_msb = tcg_temp_new(); 1116bdcccc17SRichard Henderson cb = tcg_temp_new(); 1117bdcccc17SRichard Henderson 1118eaa3783bSRichard Henderson tcg_gen_add2_reg(dest, cb_msb, in1, zero, in2, zero); 1119b2167459SRichard Henderson if (is_c) { 1120bdcccc17SRichard Henderson tcg_gen_add2_reg(dest, cb_msb, dest, cb_msb, 1121bdcccc17SRichard Henderson get_psw_carry(ctx, d), zero); 1122b2167459SRichard Henderson } 1123eaa3783bSRichard Henderson tcg_gen_xor_reg(cb, in1, in2); 1124eaa3783bSRichard Henderson tcg_gen_xor_reg(cb, cb, dest); 1125bdcccc17SRichard Henderson if (cond_need_cb(c)) { 1126bdcccc17SRichard Henderson cb_cond = get_carry(ctx, d, cb, cb_msb); 1127b2167459SRichard Henderson } 1128b2167459SRichard Henderson } else { 1129eaa3783bSRichard Henderson tcg_gen_add_reg(dest, in1, in2); 1130b2167459SRichard Henderson if (is_c) { 1131bdcccc17SRichard Henderson tcg_gen_add_reg(dest, dest, get_psw_carry(ctx, d)); 1132b2167459SRichard Henderson } 1133b2167459SRichard Henderson } 1134b2167459SRichard Henderson 1135b2167459SRichard Henderson /* Compute signed overflow if required. */ 1136f764718dSRichard Henderson sv = NULL; 1137b47a4a02SSven Schnelle if (is_tsv || cond_need_sv(c)) { 1138b2167459SRichard Henderson sv = do_add_sv(ctx, dest, in1, in2); 1139b2167459SRichard Henderson if (is_tsv) { 1140b2167459SRichard Henderson /* ??? Need to include overflow from shift. */ 1141ad75a51eSRichard Henderson gen_helper_tsv(tcg_env, sv); 1142b2167459SRichard Henderson } 1143b2167459SRichard Henderson } 1144b2167459SRichard Henderson 1145b2167459SRichard Henderson /* Emit any conditional trap before any writeback. */ 1146bdcccc17SRichard Henderson cond = do_cond(cf, dest, cb_cond, sv); 1147b2167459SRichard Henderson if (is_tc) { 1148b2167459SRichard Henderson tmp = tcg_temp_new(); 1149eaa3783bSRichard Henderson tcg_gen_setcond_reg(cond.c, tmp, cond.a0, cond.a1); 1150ad75a51eSRichard Henderson gen_helper_tcond(tcg_env, tmp); 1151b2167459SRichard Henderson } 1152b2167459SRichard Henderson 1153b2167459SRichard Henderson /* Write back the result. */ 1154b2167459SRichard Henderson if (!is_l) { 1155b2167459SRichard Henderson save_or_nullify(ctx, cpu_psw_cb, cb); 1156b2167459SRichard Henderson save_or_nullify(ctx, cpu_psw_cb_msb, cb_msb); 1157b2167459SRichard Henderson } 1158b2167459SRichard Henderson save_gpr(ctx, rt, dest); 1159b2167459SRichard Henderson 1160b2167459SRichard Henderson /* Install the new nullification. */ 1161b2167459SRichard Henderson cond_free(&ctx->null_cond); 1162b2167459SRichard Henderson ctx->null_cond = cond; 1163b2167459SRichard Henderson } 1164b2167459SRichard Henderson 11650c982a28SRichard Henderson static bool do_add_reg(DisasContext *ctx, arg_rrr_cf_sh *a, 11660c982a28SRichard Henderson bool is_l, bool is_tsv, bool is_tc, bool is_c) 11670c982a28SRichard Henderson { 11680c982a28SRichard Henderson TCGv_reg tcg_r1, tcg_r2; 11690c982a28SRichard Henderson 11700c982a28SRichard Henderson if (a->cf) { 11710c982a28SRichard Henderson nullify_over(ctx); 11720c982a28SRichard Henderson } 11730c982a28SRichard Henderson tcg_r1 = load_gpr(ctx, a->r1); 11740c982a28SRichard Henderson tcg_r2 = load_gpr(ctx, a->r2); 11750c982a28SRichard Henderson do_add(ctx, a->t, tcg_r1, tcg_r2, a->sh, is_l, is_tsv, is_tc, is_c, a->cf); 11760c982a28SRichard Henderson return nullify_end(ctx); 11770c982a28SRichard Henderson } 11780c982a28SRichard Henderson 11790588e061SRichard Henderson static bool do_add_imm(DisasContext *ctx, arg_rri_cf *a, 11800588e061SRichard Henderson bool is_tsv, bool is_tc) 11810588e061SRichard Henderson { 11820588e061SRichard Henderson TCGv_reg tcg_im, tcg_r2; 11830588e061SRichard Henderson 11840588e061SRichard Henderson if (a->cf) { 11850588e061SRichard Henderson nullify_over(ctx); 11860588e061SRichard Henderson } 1187d4e58033SRichard Henderson tcg_im = tcg_constant_reg(a->i); 11880588e061SRichard Henderson tcg_r2 = load_gpr(ctx, a->r); 11890588e061SRichard Henderson do_add(ctx, a->t, tcg_im, tcg_r2, 0, 0, is_tsv, is_tc, 0, a->cf); 11900588e061SRichard Henderson return nullify_end(ctx); 11910588e061SRichard Henderson } 11920588e061SRichard Henderson 119331234768SRichard Henderson static void do_sub(DisasContext *ctx, unsigned rt, TCGv_reg in1, 1194eaa3783bSRichard Henderson TCGv_reg in2, bool is_tsv, bool is_b, 1195eaa3783bSRichard Henderson bool is_tc, unsigned cf) 1196b2167459SRichard Henderson { 1197eaa3783bSRichard Henderson TCGv_reg dest, sv, cb, cb_msb, zero, tmp; 1198b2167459SRichard Henderson unsigned c = cf >> 1; 1199b2167459SRichard Henderson DisasCond cond; 1200bdcccc17SRichard Henderson bool d = false; 1201b2167459SRichard Henderson 1202b2167459SRichard Henderson dest = tcg_temp_new(); 1203b2167459SRichard Henderson cb = tcg_temp_new(); 1204b2167459SRichard Henderson cb_msb = tcg_temp_new(); 1205b2167459SRichard Henderson 120629dd6f64SRichard Henderson zero = tcg_constant_reg(0); 1207b2167459SRichard Henderson if (is_b) { 1208b2167459SRichard Henderson /* DEST,C = IN1 + ~IN2 + C. */ 1209eaa3783bSRichard Henderson tcg_gen_not_reg(cb, in2); 1210bdcccc17SRichard Henderson tcg_gen_add2_reg(dest, cb_msb, in1, zero, get_psw_carry(ctx, d), zero); 1211eaa3783bSRichard Henderson tcg_gen_add2_reg(dest, cb_msb, dest, cb_msb, cb, zero); 1212eaa3783bSRichard Henderson tcg_gen_xor_reg(cb, cb, in1); 1213eaa3783bSRichard Henderson tcg_gen_xor_reg(cb, cb, dest); 1214b2167459SRichard Henderson } else { 1215bdcccc17SRichard Henderson /* 1216bdcccc17SRichard Henderson * DEST,C = IN1 + ~IN2 + 1. We can produce the same result in fewer 1217bdcccc17SRichard Henderson * operations by seeding the high word with 1 and subtracting. 1218bdcccc17SRichard Henderson */ 1219bdcccc17SRichard Henderson TCGv_reg one = tcg_constant_reg(1); 1220bdcccc17SRichard Henderson tcg_gen_sub2_reg(dest, cb_msb, in1, one, in2, zero); 1221eaa3783bSRichard Henderson tcg_gen_eqv_reg(cb, in1, in2); 1222eaa3783bSRichard Henderson tcg_gen_xor_reg(cb, cb, dest); 1223b2167459SRichard Henderson } 1224b2167459SRichard Henderson 1225b2167459SRichard Henderson /* Compute signed overflow if required. */ 1226f764718dSRichard Henderson sv = NULL; 1227b47a4a02SSven Schnelle if (is_tsv || cond_need_sv(c)) { 1228b2167459SRichard Henderson sv = do_sub_sv(ctx, dest, in1, in2); 1229b2167459SRichard Henderson if (is_tsv) { 1230ad75a51eSRichard Henderson gen_helper_tsv(tcg_env, sv); 1231b2167459SRichard Henderson } 1232b2167459SRichard Henderson } 1233b2167459SRichard Henderson 1234b2167459SRichard Henderson /* Compute the condition. We cannot use the special case for borrow. */ 1235b2167459SRichard Henderson if (!is_b) { 1236b2167459SRichard Henderson cond = do_sub_cond(cf, dest, in1, in2, sv); 1237b2167459SRichard Henderson } else { 1238bdcccc17SRichard Henderson cond = do_cond(cf, dest, get_carry(ctx, d, cb, cb_msb), sv); 1239b2167459SRichard Henderson } 1240b2167459SRichard Henderson 1241b2167459SRichard Henderson /* Emit any conditional trap before any writeback. */ 1242b2167459SRichard Henderson if (is_tc) { 1243b2167459SRichard Henderson tmp = tcg_temp_new(); 1244eaa3783bSRichard Henderson tcg_gen_setcond_reg(cond.c, tmp, cond.a0, cond.a1); 1245ad75a51eSRichard Henderson gen_helper_tcond(tcg_env, tmp); 1246b2167459SRichard Henderson } 1247b2167459SRichard Henderson 1248b2167459SRichard Henderson /* Write back the result. */ 1249b2167459SRichard Henderson save_or_nullify(ctx, cpu_psw_cb, cb); 1250b2167459SRichard Henderson save_or_nullify(ctx, cpu_psw_cb_msb, cb_msb); 1251b2167459SRichard Henderson save_gpr(ctx, rt, dest); 1252b2167459SRichard Henderson 1253b2167459SRichard Henderson /* Install the new nullification. */ 1254b2167459SRichard Henderson cond_free(&ctx->null_cond); 1255b2167459SRichard Henderson ctx->null_cond = cond; 1256b2167459SRichard Henderson } 1257b2167459SRichard Henderson 12580c982a28SRichard Henderson static bool do_sub_reg(DisasContext *ctx, arg_rrr_cf *a, 12590c982a28SRichard Henderson bool is_tsv, bool is_b, bool is_tc) 12600c982a28SRichard Henderson { 12610c982a28SRichard Henderson TCGv_reg tcg_r1, tcg_r2; 12620c982a28SRichard Henderson 12630c982a28SRichard Henderson if (a->cf) { 12640c982a28SRichard Henderson nullify_over(ctx); 12650c982a28SRichard Henderson } 12660c982a28SRichard Henderson tcg_r1 = load_gpr(ctx, a->r1); 12670c982a28SRichard Henderson tcg_r2 = load_gpr(ctx, a->r2); 12680c982a28SRichard Henderson do_sub(ctx, a->t, tcg_r1, tcg_r2, is_tsv, is_b, is_tc, a->cf); 12690c982a28SRichard Henderson return nullify_end(ctx); 12700c982a28SRichard Henderson } 12710c982a28SRichard Henderson 12720588e061SRichard Henderson static bool do_sub_imm(DisasContext *ctx, arg_rri_cf *a, bool is_tsv) 12730588e061SRichard Henderson { 12740588e061SRichard Henderson TCGv_reg tcg_im, tcg_r2; 12750588e061SRichard Henderson 12760588e061SRichard Henderson if (a->cf) { 12770588e061SRichard Henderson nullify_over(ctx); 12780588e061SRichard Henderson } 1279d4e58033SRichard Henderson tcg_im = tcg_constant_reg(a->i); 12800588e061SRichard Henderson tcg_r2 = load_gpr(ctx, a->r); 12810588e061SRichard Henderson do_sub(ctx, a->t, tcg_im, tcg_r2, is_tsv, 0, 0, a->cf); 12820588e061SRichard Henderson return nullify_end(ctx); 12830588e061SRichard Henderson } 12840588e061SRichard Henderson 128531234768SRichard Henderson static void do_cmpclr(DisasContext *ctx, unsigned rt, TCGv_reg in1, 1286eaa3783bSRichard Henderson TCGv_reg in2, unsigned cf) 1287b2167459SRichard Henderson { 1288eaa3783bSRichard Henderson TCGv_reg dest, sv; 1289b2167459SRichard Henderson DisasCond cond; 1290b2167459SRichard Henderson 1291b2167459SRichard Henderson dest = tcg_temp_new(); 1292eaa3783bSRichard Henderson tcg_gen_sub_reg(dest, in1, in2); 1293b2167459SRichard Henderson 1294b2167459SRichard Henderson /* Compute signed overflow if required. */ 1295f764718dSRichard Henderson sv = NULL; 1296b47a4a02SSven Schnelle if (cond_need_sv(cf >> 1)) { 1297b2167459SRichard Henderson sv = do_sub_sv(ctx, dest, in1, in2); 1298b2167459SRichard Henderson } 1299b2167459SRichard Henderson 1300b2167459SRichard Henderson /* Form the condition for the compare. */ 1301b2167459SRichard Henderson cond = do_sub_cond(cf, dest, in1, in2, sv); 1302b2167459SRichard Henderson 1303b2167459SRichard Henderson /* Clear. */ 1304eaa3783bSRichard Henderson tcg_gen_movi_reg(dest, 0); 1305b2167459SRichard Henderson save_gpr(ctx, rt, dest); 1306b2167459SRichard Henderson 1307b2167459SRichard Henderson /* Install the new nullification. */ 1308b2167459SRichard Henderson cond_free(&ctx->null_cond); 1309b2167459SRichard Henderson ctx->null_cond = cond; 1310b2167459SRichard Henderson } 1311b2167459SRichard Henderson 131231234768SRichard Henderson static void do_log(DisasContext *ctx, unsigned rt, TCGv_reg in1, 1313eaa3783bSRichard Henderson TCGv_reg in2, unsigned cf, 1314eaa3783bSRichard Henderson void (*fn)(TCGv_reg, TCGv_reg, TCGv_reg)) 1315b2167459SRichard Henderson { 1316eaa3783bSRichard Henderson TCGv_reg dest = dest_gpr(ctx, rt); 1317b2167459SRichard Henderson 1318b2167459SRichard Henderson /* Perform the operation, and writeback. */ 1319b2167459SRichard Henderson fn(dest, in1, in2); 1320b2167459SRichard Henderson save_gpr(ctx, rt, dest); 1321b2167459SRichard Henderson 1322b2167459SRichard Henderson /* Install the new nullification. */ 1323b2167459SRichard Henderson cond_free(&ctx->null_cond); 1324b2167459SRichard Henderson if (cf) { 1325b2167459SRichard Henderson ctx->null_cond = do_log_cond(cf, dest); 1326b2167459SRichard Henderson } 1327b2167459SRichard Henderson } 1328b2167459SRichard Henderson 13290c982a28SRichard Henderson static bool do_log_reg(DisasContext *ctx, arg_rrr_cf *a, 13300c982a28SRichard Henderson void (*fn)(TCGv_reg, TCGv_reg, TCGv_reg)) 13310c982a28SRichard Henderson { 13320c982a28SRichard Henderson TCGv_reg tcg_r1, tcg_r2; 13330c982a28SRichard Henderson 13340c982a28SRichard Henderson if (a->cf) { 13350c982a28SRichard Henderson nullify_over(ctx); 13360c982a28SRichard Henderson } 13370c982a28SRichard Henderson tcg_r1 = load_gpr(ctx, a->r1); 13380c982a28SRichard Henderson tcg_r2 = load_gpr(ctx, a->r2); 13390c982a28SRichard Henderson do_log(ctx, a->t, tcg_r1, tcg_r2, a->cf, fn); 13400c982a28SRichard Henderson return nullify_end(ctx); 13410c982a28SRichard Henderson } 13420c982a28SRichard Henderson 134331234768SRichard Henderson static void do_unit(DisasContext *ctx, unsigned rt, TCGv_reg in1, 1344eaa3783bSRichard Henderson TCGv_reg in2, unsigned cf, bool is_tc, 1345eaa3783bSRichard Henderson void (*fn)(TCGv_reg, TCGv_reg, TCGv_reg)) 1346b2167459SRichard Henderson { 1347eaa3783bSRichard Henderson TCGv_reg dest; 1348b2167459SRichard Henderson DisasCond cond; 1349b2167459SRichard Henderson 1350b2167459SRichard Henderson if (cf == 0) { 1351b2167459SRichard Henderson dest = dest_gpr(ctx, rt); 1352b2167459SRichard Henderson fn(dest, in1, in2); 1353b2167459SRichard Henderson save_gpr(ctx, rt, dest); 1354b2167459SRichard Henderson cond_free(&ctx->null_cond); 1355b2167459SRichard Henderson } else { 1356b2167459SRichard Henderson dest = tcg_temp_new(); 1357b2167459SRichard Henderson fn(dest, in1, in2); 1358b2167459SRichard Henderson 1359b2167459SRichard Henderson cond = do_unit_cond(cf, dest, in1, in2); 1360b2167459SRichard Henderson 1361b2167459SRichard Henderson if (is_tc) { 1362eaa3783bSRichard Henderson TCGv_reg tmp = tcg_temp_new(); 1363eaa3783bSRichard Henderson tcg_gen_setcond_reg(cond.c, tmp, cond.a0, cond.a1); 1364ad75a51eSRichard Henderson gen_helper_tcond(tcg_env, tmp); 1365b2167459SRichard Henderson } 1366b2167459SRichard Henderson save_gpr(ctx, rt, dest); 1367b2167459SRichard Henderson 1368b2167459SRichard Henderson cond_free(&ctx->null_cond); 1369b2167459SRichard Henderson ctx->null_cond = cond; 1370b2167459SRichard Henderson } 1371b2167459SRichard Henderson } 1372b2167459SRichard Henderson 137386f8d05fSRichard Henderson #ifndef CONFIG_USER_ONLY 13748d6ae7fbSRichard Henderson /* The "normal" usage is SP >= 0, wherein SP == 0 selects the space 13758d6ae7fbSRichard Henderson from the top 2 bits of the base register. There are a few system 13768d6ae7fbSRichard Henderson instructions that have a 3-bit space specifier, for which SR0 is 13778d6ae7fbSRichard Henderson not special. To handle this, pass ~SP. */ 137886f8d05fSRichard Henderson static TCGv_i64 space_select(DisasContext *ctx, int sp, TCGv_reg base) 137986f8d05fSRichard Henderson { 138086f8d05fSRichard Henderson TCGv_ptr ptr; 138186f8d05fSRichard Henderson TCGv_reg tmp; 138286f8d05fSRichard Henderson TCGv_i64 spc; 138386f8d05fSRichard Henderson 138486f8d05fSRichard Henderson if (sp != 0) { 13858d6ae7fbSRichard Henderson if (sp < 0) { 13868d6ae7fbSRichard Henderson sp = ~sp; 13878d6ae7fbSRichard Henderson } 1388a6779861SRichard Henderson spc = tcg_temp_new_tl(); 13898d6ae7fbSRichard Henderson load_spr(ctx, spc, sp); 13908d6ae7fbSRichard Henderson return spc; 139186f8d05fSRichard Henderson } 1392494737b7SRichard Henderson if (ctx->tb_flags & TB_FLAG_SR_SAME) { 1393494737b7SRichard Henderson return cpu_srH; 1394494737b7SRichard Henderson } 139586f8d05fSRichard Henderson 139686f8d05fSRichard Henderson ptr = tcg_temp_new_ptr(); 139786f8d05fSRichard Henderson tmp = tcg_temp_new(); 1398a6779861SRichard Henderson spc = tcg_temp_new_tl(); 139986f8d05fSRichard Henderson 140086f8d05fSRichard Henderson tcg_gen_shri_reg(tmp, base, TARGET_REGISTER_BITS - 5); 140186f8d05fSRichard Henderson tcg_gen_andi_reg(tmp, tmp, 030); 140286f8d05fSRichard Henderson tcg_gen_trunc_reg_ptr(ptr, tmp); 140386f8d05fSRichard Henderson 1404ad75a51eSRichard Henderson tcg_gen_add_ptr(ptr, ptr, tcg_env); 140586f8d05fSRichard Henderson tcg_gen_ld_i64(spc, ptr, offsetof(CPUHPPAState, sr[4])); 140686f8d05fSRichard Henderson 140786f8d05fSRichard Henderson return spc; 140886f8d05fSRichard Henderson } 140986f8d05fSRichard Henderson #endif 141086f8d05fSRichard Henderson 141186f8d05fSRichard Henderson static void form_gva(DisasContext *ctx, TCGv_tl *pgva, TCGv_reg *pofs, 141286f8d05fSRichard Henderson unsigned rb, unsigned rx, int scale, target_sreg disp, 141386f8d05fSRichard Henderson unsigned sp, int modify, bool is_phys) 141486f8d05fSRichard Henderson { 141586f8d05fSRichard Henderson TCGv_reg base = load_gpr(ctx, rb); 141686f8d05fSRichard Henderson TCGv_reg ofs; 141786f8d05fSRichard Henderson 141886f8d05fSRichard Henderson /* Note that RX is mutually exclusive with DISP. */ 141986f8d05fSRichard Henderson if (rx) { 1420e12c6309SRichard Henderson ofs = tcg_temp_new(); 142186f8d05fSRichard Henderson tcg_gen_shli_reg(ofs, cpu_gr[rx], scale); 142286f8d05fSRichard Henderson tcg_gen_add_reg(ofs, ofs, base); 142386f8d05fSRichard Henderson } else if (disp || modify) { 1424e12c6309SRichard Henderson ofs = tcg_temp_new(); 142586f8d05fSRichard Henderson tcg_gen_addi_reg(ofs, base, disp); 142686f8d05fSRichard Henderson } else { 142786f8d05fSRichard Henderson ofs = base; 142886f8d05fSRichard Henderson } 142986f8d05fSRichard Henderson 143086f8d05fSRichard Henderson *pofs = ofs; 143186f8d05fSRichard Henderson #ifdef CONFIG_USER_ONLY 143286f8d05fSRichard Henderson *pgva = (modify <= 0 ? ofs : base); 143386f8d05fSRichard Henderson #else 1434a6779861SRichard Henderson TCGv_tl addr = tcg_temp_new_tl(); 143586f8d05fSRichard Henderson tcg_gen_extu_reg_tl(addr, modify <= 0 ? ofs : base); 1436494737b7SRichard Henderson if (ctx->tb_flags & PSW_W) { 143786f8d05fSRichard Henderson tcg_gen_andi_tl(addr, addr, 0x3fffffffffffffffull); 143886f8d05fSRichard Henderson } 143986f8d05fSRichard Henderson if (!is_phys) { 144086f8d05fSRichard Henderson tcg_gen_or_tl(addr, addr, space_select(ctx, sp, base)); 144186f8d05fSRichard Henderson } 144286f8d05fSRichard Henderson *pgva = addr; 144386f8d05fSRichard Henderson #endif 144486f8d05fSRichard Henderson } 144586f8d05fSRichard Henderson 144696d6407fSRichard Henderson /* Emit a memory load. The modify parameter should be 144796d6407fSRichard Henderson * < 0 for pre-modify, 144896d6407fSRichard Henderson * > 0 for post-modify, 144996d6407fSRichard Henderson * = 0 for no base register update. 145096d6407fSRichard Henderson */ 145196d6407fSRichard Henderson static void do_load_32(DisasContext *ctx, TCGv_i32 dest, unsigned rb, 1452eaa3783bSRichard Henderson unsigned rx, int scale, target_sreg disp, 145314776ab5STony Nguyen unsigned sp, int modify, MemOp mop) 145496d6407fSRichard Henderson { 145586f8d05fSRichard Henderson TCGv_reg ofs; 145686f8d05fSRichard Henderson TCGv_tl addr; 145796d6407fSRichard Henderson 145896d6407fSRichard Henderson /* Caller uses nullify_over/nullify_end. */ 145996d6407fSRichard Henderson assert(ctx->null_cond.c == TCG_COND_NEVER); 146096d6407fSRichard Henderson 146186f8d05fSRichard Henderson form_gva(ctx, &addr, &ofs, rb, rx, scale, disp, sp, modify, 146286f8d05fSRichard Henderson ctx->mmu_idx == MMU_PHYS_IDX); 1463c1f55d97SRichard Henderson tcg_gen_qemu_ld_i32(dest, addr, ctx->mmu_idx, mop | UNALIGN(ctx)); 146486f8d05fSRichard Henderson if (modify) { 146586f8d05fSRichard Henderson save_gpr(ctx, rb, ofs); 146696d6407fSRichard Henderson } 146796d6407fSRichard Henderson } 146896d6407fSRichard Henderson 146996d6407fSRichard Henderson static void do_load_64(DisasContext *ctx, TCGv_i64 dest, unsigned rb, 1470eaa3783bSRichard Henderson unsigned rx, int scale, target_sreg disp, 147114776ab5STony Nguyen unsigned sp, int modify, MemOp mop) 147296d6407fSRichard Henderson { 147386f8d05fSRichard Henderson TCGv_reg ofs; 147486f8d05fSRichard Henderson TCGv_tl addr; 147596d6407fSRichard Henderson 147696d6407fSRichard Henderson /* Caller uses nullify_over/nullify_end. */ 147796d6407fSRichard Henderson assert(ctx->null_cond.c == TCG_COND_NEVER); 147896d6407fSRichard Henderson 147986f8d05fSRichard Henderson form_gva(ctx, &addr, &ofs, rb, rx, scale, disp, sp, modify, 148086f8d05fSRichard Henderson ctx->mmu_idx == MMU_PHYS_IDX); 1481217d1a5eSRichard Henderson tcg_gen_qemu_ld_i64(dest, addr, ctx->mmu_idx, mop | UNALIGN(ctx)); 148286f8d05fSRichard Henderson if (modify) { 148386f8d05fSRichard Henderson save_gpr(ctx, rb, ofs); 148496d6407fSRichard Henderson } 148596d6407fSRichard Henderson } 148696d6407fSRichard Henderson 148796d6407fSRichard Henderson static void do_store_32(DisasContext *ctx, TCGv_i32 src, unsigned rb, 1488eaa3783bSRichard Henderson unsigned rx, int scale, target_sreg disp, 148914776ab5STony Nguyen unsigned sp, int modify, MemOp mop) 149096d6407fSRichard Henderson { 149186f8d05fSRichard Henderson TCGv_reg ofs; 149286f8d05fSRichard Henderson TCGv_tl addr; 149396d6407fSRichard Henderson 149496d6407fSRichard Henderson /* Caller uses nullify_over/nullify_end. */ 149596d6407fSRichard Henderson assert(ctx->null_cond.c == TCG_COND_NEVER); 149696d6407fSRichard Henderson 149786f8d05fSRichard Henderson form_gva(ctx, &addr, &ofs, rb, rx, scale, disp, sp, modify, 149886f8d05fSRichard Henderson ctx->mmu_idx == MMU_PHYS_IDX); 1499217d1a5eSRichard Henderson tcg_gen_qemu_st_i32(src, addr, ctx->mmu_idx, mop | UNALIGN(ctx)); 150086f8d05fSRichard Henderson if (modify) { 150186f8d05fSRichard Henderson save_gpr(ctx, rb, ofs); 150296d6407fSRichard Henderson } 150396d6407fSRichard Henderson } 150496d6407fSRichard Henderson 150596d6407fSRichard Henderson static void do_store_64(DisasContext *ctx, TCGv_i64 src, unsigned rb, 1506eaa3783bSRichard Henderson unsigned rx, int scale, target_sreg disp, 150714776ab5STony Nguyen unsigned sp, int modify, MemOp mop) 150896d6407fSRichard Henderson { 150986f8d05fSRichard Henderson TCGv_reg ofs; 151086f8d05fSRichard Henderson TCGv_tl addr; 151196d6407fSRichard Henderson 151296d6407fSRichard Henderson /* Caller uses nullify_over/nullify_end. */ 151396d6407fSRichard Henderson assert(ctx->null_cond.c == TCG_COND_NEVER); 151496d6407fSRichard Henderson 151586f8d05fSRichard Henderson form_gva(ctx, &addr, &ofs, rb, rx, scale, disp, sp, modify, 151686f8d05fSRichard Henderson ctx->mmu_idx == MMU_PHYS_IDX); 1517217d1a5eSRichard Henderson tcg_gen_qemu_st_i64(src, addr, ctx->mmu_idx, mop | UNALIGN(ctx)); 151886f8d05fSRichard Henderson if (modify) { 151986f8d05fSRichard Henderson save_gpr(ctx, rb, ofs); 152096d6407fSRichard Henderson } 152196d6407fSRichard Henderson } 152296d6407fSRichard Henderson 1523eaa3783bSRichard Henderson #if TARGET_REGISTER_BITS == 64 1524eaa3783bSRichard Henderson #define do_load_reg do_load_64 1525eaa3783bSRichard Henderson #define do_store_reg do_store_64 152696d6407fSRichard Henderson #else 1527eaa3783bSRichard Henderson #define do_load_reg do_load_32 1528eaa3783bSRichard Henderson #define do_store_reg do_store_32 152996d6407fSRichard Henderson #endif 153096d6407fSRichard Henderson 15311cd012a5SRichard Henderson static bool do_load(DisasContext *ctx, unsigned rt, unsigned rb, 1532eaa3783bSRichard Henderson unsigned rx, int scale, target_sreg disp, 153314776ab5STony Nguyen unsigned sp, int modify, MemOp mop) 153496d6407fSRichard Henderson { 1535eaa3783bSRichard Henderson TCGv_reg dest; 153696d6407fSRichard Henderson 153796d6407fSRichard Henderson nullify_over(ctx); 153896d6407fSRichard Henderson 153996d6407fSRichard Henderson if (modify == 0) { 154096d6407fSRichard Henderson /* No base register update. */ 154196d6407fSRichard Henderson dest = dest_gpr(ctx, rt); 154296d6407fSRichard Henderson } else { 154396d6407fSRichard Henderson /* Make sure if RT == RB, we see the result of the load. */ 1544e12c6309SRichard Henderson dest = tcg_temp_new(); 154596d6407fSRichard Henderson } 154686f8d05fSRichard Henderson do_load_reg(ctx, dest, rb, rx, scale, disp, sp, modify, mop); 154796d6407fSRichard Henderson save_gpr(ctx, rt, dest); 154896d6407fSRichard Henderson 15491cd012a5SRichard Henderson return nullify_end(ctx); 155096d6407fSRichard Henderson } 155196d6407fSRichard Henderson 1552740038d7SRichard Henderson static bool do_floadw(DisasContext *ctx, unsigned rt, unsigned rb, 1553eaa3783bSRichard Henderson unsigned rx, int scale, target_sreg disp, 155486f8d05fSRichard Henderson unsigned sp, int modify) 155596d6407fSRichard Henderson { 155696d6407fSRichard Henderson TCGv_i32 tmp; 155796d6407fSRichard Henderson 155896d6407fSRichard Henderson nullify_over(ctx); 155996d6407fSRichard Henderson 156096d6407fSRichard Henderson tmp = tcg_temp_new_i32(); 156186f8d05fSRichard Henderson do_load_32(ctx, tmp, rb, rx, scale, disp, sp, modify, MO_TEUL); 156296d6407fSRichard Henderson save_frw_i32(rt, tmp); 156396d6407fSRichard Henderson 156496d6407fSRichard Henderson if (rt == 0) { 1565ad75a51eSRichard Henderson gen_helper_loaded_fr0(tcg_env); 156696d6407fSRichard Henderson } 156796d6407fSRichard Henderson 1568740038d7SRichard Henderson return nullify_end(ctx); 156996d6407fSRichard Henderson } 157096d6407fSRichard Henderson 1571740038d7SRichard Henderson static bool trans_fldw(DisasContext *ctx, arg_ldst *a) 1572740038d7SRichard Henderson { 1573740038d7SRichard Henderson return do_floadw(ctx, a->t, a->b, a->x, a->scale ? 2 : 0, 1574740038d7SRichard Henderson a->disp, a->sp, a->m); 1575740038d7SRichard Henderson } 1576740038d7SRichard Henderson 1577740038d7SRichard Henderson static bool do_floadd(DisasContext *ctx, unsigned rt, unsigned rb, 1578eaa3783bSRichard Henderson unsigned rx, int scale, target_sreg disp, 157986f8d05fSRichard Henderson unsigned sp, int modify) 158096d6407fSRichard Henderson { 158196d6407fSRichard Henderson TCGv_i64 tmp; 158296d6407fSRichard Henderson 158396d6407fSRichard Henderson nullify_over(ctx); 158496d6407fSRichard Henderson 158596d6407fSRichard Henderson tmp = tcg_temp_new_i64(); 1586fc313c64SFrédéric Pétrot do_load_64(ctx, tmp, rb, rx, scale, disp, sp, modify, MO_TEUQ); 158796d6407fSRichard Henderson save_frd(rt, tmp); 158896d6407fSRichard Henderson 158996d6407fSRichard Henderson if (rt == 0) { 1590ad75a51eSRichard Henderson gen_helper_loaded_fr0(tcg_env); 159196d6407fSRichard Henderson } 159296d6407fSRichard Henderson 1593740038d7SRichard Henderson return nullify_end(ctx); 1594740038d7SRichard Henderson } 1595740038d7SRichard Henderson 1596740038d7SRichard Henderson static bool trans_fldd(DisasContext *ctx, arg_ldst *a) 1597740038d7SRichard Henderson { 1598740038d7SRichard Henderson return do_floadd(ctx, a->t, a->b, a->x, a->scale ? 3 : 0, 1599740038d7SRichard Henderson a->disp, a->sp, a->m); 160096d6407fSRichard Henderson } 160196d6407fSRichard Henderson 16021cd012a5SRichard Henderson static bool do_store(DisasContext *ctx, unsigned rt, unsigned rb, 160386f8d05fSRichard Henderson target_sreg disp, unsigned sp, 160414776ab5STony Nguyen int modify, MemOp mop) 160596d6407fSRichard Henderson { 160696d6407fSRichard Henderson nullify_over(ctx); 160786f8d05fSRichard Henderson do_store_reg(ctx, load_gpr(ctx, rt), rb, 0, 0, disp, sp, modify, mop); 16081cd012a5SRichard Henderson return nullify_end(ctx); 160996d6407fSRichard Henderson } 161096d6407fSRichard Henderson 1611740038d7SRichard Henderson static bool do_fstorew(DisasContext *ctx, unsigned rt, unsigned rb, 1612eaa3783bSRichard Henderson unsigned rx, int scale, target_sreg disp, 161386f8d05fSRichard Henderson unsigned sp, int modify) 161496d6407fSRichard Henderson { 161596d6407fSRichard Henderson TCGv_i32 tmp; 161696d6407fSRichard Henderson 161796d6407fSRichard Henderson nullify_over(ctx); 161896d6407fSRichard Henderson 161996d6407fSRichard Henderson tmp = load_frw_i32(rt); 162086f8d05fSRichard Henderson do_store_32(ctx, tmp, rb, rx, scale, disp, sp, modify, MO_TEUL); 162196d6407fSRichard Henderson 1622740038d7SRichard Henderson return nullify_end(ctx); 162396d6407fSRichard Henderson } 162496d6407fSRichard Henderson 1625740038d7SRichard Henderson static bool trans_fstw(DisasContext *ctx, arg_ldst *a) 1626740038d7SRichard Henderson { 1627740038d7SRichard Henderson return do_fstorew(ctx, a->t, a->b, a->x, a->scale ? 2 : 0, 1628740038d7SRichard Henderson a->disp, a->sp, a->m); 1629740038d7SRichard Henderson } 1630740038d7SRichard Henderson 1631740038d7SRichard Henderson static bool do_fstored(DisasContext *ctx, unsigned rt, unsigned rb, 1632eaa3783bSRichard Henderson unsigned rx, int scale, target_sreg disp, 163386f8d05fSRichard Henderson unsigned sp, int modify) 163496d6407fSRichard Henderson { 163596d6407fSRichard Henderson TCGv_i64 tmp; 163696d6407fSRichard Henderson 163796d6407fSRichard Henderson nullify_over(ctx); 163896d6407fSRichard Henderson 163996d6407fSRichard Henderson tmp = load_frd(rt); 1640fc313c64SFrédéric Pétrot do_store_64(ctx, tmp, rb, rx, scale, disp, sp, modify, MO_TEUQ); 164196d6407fSRichard Henderson 1642740038d7SRichard Henderson return nullify_end(ctx); 1643740038d7SRichard Henderson } 1644740038d7SRichard Henderson 1645740038d7SRichard Henderson static bool trans_fstd(DisasContext *ctx, arg_ldst *a) 1646740038d7SRichard Henderson { 1647740038d7SRichard Henderson return do_fstored(ctx, a->t, a->b, a->x, a->scale ? 3 : 0, 1648740038d7SRichard Henderson a->disp, a->sp, a->m); 164996d6407fSRichard Henderson } 165096d6407fSRichard Henderson 16511ca74648SRichard Henderson static bool do_fop_wew(DisasContext *ctx, unsigned rt, unsigned ra, 1652ebe9383cSRichard Henderson void (*func)(TCGv_i32, TCGv_env, TCGv_i32)) 1653ebe9383cSRichard Henderson { 1654ebe9383cSRichard Henderson TCGv_i32 tmp; 1655ebe9383cSRichard Henderson 1656ebe9383cSRichard Henderson nullify_over(ctx); 1657ebe9383cSRichard Henderson tmp = load_frw0_i32(ra); 1658ebe9383cSRichard Henderson 1659ad75a51eSRichard Henderson func(tmp, tcg_env, tmp); 1660ebe9383cSRichard Henderson 1661ebe9383cSRichard Henderson save_frw_i32(rt, tmp); 16621ca74648SRichard Henderson return nullify_end(ctx); 1663ebe9383cSRichard Henderson } 1664ebe9383cSRichard Henderson 16651ca74648SRichard Henderson static bool do_fop_wed(DisasContext *ctx, unsigned rt, unsigned ra, 1666ebe9383cSRichard Henderson void (*func)(TCGv_i32, TCGv_env, TCGv_i64)) 1667ebe9383cSRichard Henderson { 1668ebe9383cSRichard Henderson TCGv_i32 dst; 1669ebe9383cSRichard Henderson TCGv_i64 src; 1670ebe9383cSRichard Henderson 1671ebe9383cSRichard Henderson nullify_over(ctx); 1672ebe9383cSRichard Henderson src = load_frd(ra); 1673ebe9383cSRichard Henderson dst = tcg_temp_new_i32(); 1674ebe9383cSRichard Henderson 1675ad75a51eSRichard Henderson func(dst, tcg_env, src); 1676ebe9383cSRichard Henderson 1677ebe9383cSRichard Henderson save_frw_i32(rt, dst); 16781ca74648SRichard Henderson return nullify_end(ctx); 1679ebe9383cSRichard Henderson } 1680ebe9383cSRichard Henderson 16811ca74648SRichard Henderson static bool do_fop_ded(DisasContext *ctx, unsigned rt, unsigned ra, 1682ebe9383cSRichard Henderson void (*func)(TCGv_i64, TCGv_env, TCGv_i64)) 1683ebe9383cSRichard Henderson { 1684ebe9383cSRichard Henderson TCGv_i64 tmp; 1685ebe9383cSRichard Henderson 1686ebe9383cSRichard Henderson nullify_over(ctx); 1687ebe9383cSRichard Henderson tmp = load_frd0(ra); 1688ebe9383cSRichard Henderson 1689ad75a51eSRichard Henderson func(tmp, tcg_env, tmp); 1690ebe9383cSRichard Henderson 1691ebe9383cSRichard Henderson save_frd(rt, tmp); 16921ca74648SRichard Henderson return nullify_end(ctx); 1693ebe9383cSRichard Henderson } 1694ebe9383cSRichard Henderson 16951ca74648SRichard Henderson static bool do_fop_dew(DisasContext *ctx, unsigned rt, unsigned ra, 1696ebe9383cSRichard Henderson void (*func)(TCGv_i64, TCGv_env, TCGv_i32)) 1697ebe9383cSRichard Henderson { 1698ebe9383cSRichard Henderson TCGv_i32 src; 1699ebe9383cSRichard Henderson TCGv_i64 dst; 1700ebe9383cSRichard Henderson 1701ebe9383cSRichard Henderson nullify_over(ctx); 1702ebe9383cSRichard Henderson src = load_frw0_i32(ra); 1703ebe9383cSRichard Henderson dst = tcg_temp_new_i64(); 1704ebe9383cSRichard Henderson 1705ad75a51eSRichard Henderson func(dst, tcg_env, src); 1706ebe9383cSRichard Henderson 1707ebe9383cSRichard Henderson save_frd(rt, dst); 17081ca74648SRichard Henderson return nullify_end(ctx); 1709ebe9383cSRichard Henderson } 1710ebe9383cSRichard Henderson 17111ca74648SRichard Henderson static bool do_fop_weww(DisasContext *ctx, unsigned rt, 1712ebe9383cSRichard Henderson unsigned ra, unsigned rb, 171331234768SRichard Henderson void (*func)(TCGv_i32, TCGv_env, TCGv_i32, TCGv_i32)) 1714ebe9383cSRichard Henderson { 1715ebe9383cSRichard Henderson TCGv_i32 a, b; 1716ebe9383cSRichard Henderson 1717ebe9383cSRichard Henderson nullify_over(ctx); 1718ebe9383cSRichard Henderson a = load_frw0_i32(ra); 1719ebe9383cSRichard Henderson b = load_frw0_i32(rb); 1720ebe9383cSRichard Henderson 1721ad75a51eSRichard Henderson func(a, tcg_env, a, b); 1722ebe9383cSRichard Henderson 1723ebe9383cSRichard Henderson save_frw_i32(rt, a); 17241ca74648SRichard Henderson return nullify_end(ctx); 1725ebe9383cSRichard Henderson } 1726ebe9383cSRichard Henderson 17271ca74648SRichard Henderson static bool do_fop_dedd(DisasContext *ctx, unsigned rt, 1728ebe9383cSRichard Henderson unsigned ra, unsigned rb, 172931234768SRichard Henderson void (*func)(TCGv_i64, TCGv_env, TCGv_i64, TCGv_i64)) 1730ebe9383cSRichard Henderson { 1731ebe9383cSRichard Henderson TCGv_i64 a, b; 1732ebe9383cSRichard Henderson 1733ebe9383cSRichard Henderson nullify_over(ctx); 1734ebe9383cSRichard Henderson a = load_frd0(ra); 1735ebe9383cSRichard Henderson b = load_frd0(rb); 1736ebe9383cSRichard Henderson 1737ad75a51eSRichard Henderson func(a, tcg_env, a, b); 1738ebe9383cSRichard Henderson 1739ebe9383cSRichard Henderson save_frd(rt, a); 17401ca74648SRichard Henderson return nullify_end(ctx); 1741ebe9383cSRichard Henderson } 1742ebe9383cSRichard Henderson 174398cd9ca7SRichard Henderson /* Emit an unconditional branch to a direct target, which may or may not 174498cd9ca7SRichard Henderson have already had nullification handled. */ 174501afb7beSRichard Henderson static bool do_dbranch(DisasContext *ctx, target_ureg dest, 174698cd9ca7SRichard Henderson unsigned link, bool is_n) 174798cd9ca7SRichard Henderson { 174898cd9ca7SRichard Henderson if (ctx->null_cond.c == TCG_COND_NEVER && ctx->null_lab == NULL) { 174998cd9ca7SRichard Henderson if (link != 0) { 175098cd9ca7SRichard Henderson copy_iaoq_entry(cpu_gr[link], ctx->iaoq_n, ctx->iaoq_n_var); 175198cd9ca7SRichard Henderson } 175298cd9ca7SRichard Henderson ctx->iaoq_n = dest; 175398cd9ca7SRichard Henderson if (is_n) { 175498cd9ca7SRichard Henderson ctx->null_cond.c = TCG_COND_ALWAYS; 175598cd9ca7SRichard Henderson } 175698cd9ca7SRichard Henderson } else { 175798cd9ca7SRichard Henderson nullify_over(ctx); 175898cd9ca7SRichard Henderson 175998cd9ca7SRichard Henderson if (link != 0) { 176098cd9ca7SRichard Henderson copy_iaoq_entry(cpu_gr[link], ctx->iaoq_n, ctx->iaoq_n_var); 176198cd9ca7SRichard Henderson } 176298cd9ca7SRichard Henderson 176398cd9ca7SRichard Henderson if (is_n && use_nullify_skip(ctx)) { 176498cd9ca7SRichard Henderson nullify_set(ctx, 0); 176598cd9ca7SRichard Henderson gen_goto_tb(ctx, 0, dest, dest + 4); 176698cd9ca7SRichard Henderson } else { 176798cd9ca7SRichard Henderson nullify_set(ctx, is_n); 176898cd9ca7SRichard Henderson gen_goto_tb(ctx, 0, ctx->iaoq_b, dest); 176998cd9ca7SRichard Henderson } 177098cd9ca7SRichard Henderson 177131234768SRichard Henderson nullify_end(ctx); 177298cd9ca7SRichard Henderson 177398cd9ca7SRichard Henderson nullify_set(ctx, 0); 177498cd9ca7SRichard Henderson gen_goto_tb(ctx, 1, ctx->iaoq_b, ctx->iaoq_n); 177531234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 177698cd9ca7SRichard Henderson } 177701afb7beSRichard Henderson return true; 177898cd9ca7SRichard Henderson } 177998cd9ca7SRichard Henderson 178098cd9ca7SRichard Henderson /* Emit a conditional branch to a direct target. If the branch itself 178198cd9ca7SRichard Henderson is nullified, we should have already used nullify_over. */ 178201afb7beSRichard Henderson static bool do_cbranch(DisasContext *ctx, target_sreg disp, bool is_n, 178398cd9ca7SRichard Henderson DisasCond *cond) 178498cd9ca7SRichard Henderson { 1785eaa3783bSRichard Henderson target_ureg dest = iaoq_dest(ctx, disp); 178698cd9ca7SRichard Henderson TCGLabel *taken = NULL; 178798cd9ca7SRichard Henderson TCGCond c = cond->c; 178898cd9ca7SRichard Henderson bool n; 178998cd9ca7SRichard Henderson 179098cd9ca7SRichard Henderson assert(ctx->null_cond.c == TCG_COND_NEVER); 179198cd9ca7SRichard Henderson 179298cd9ca7SRichard Henderson /* Handle TRUE and NEVER as direct branches. */ 179398cd9ca7SRichard Henderson if (c == TCG_COND_ALWAYS) { 179401afb7beSRichard Henderson return do_dbranch(ctx, dest, 0, is_n && disp >= 0); 179598cd9ca7SRichard Henderson } 179698cd9ca7SRichard Henderson if (c == TCG_COND_NEVER) { 179701afb7beSRichard Henderson return do_dbranch(ctx, ctx->iaoq_n, 0, is_n && disp < 0); 179898cd9ca7SRichard Henderson } 179998cd9ca7SRichard Henderson 180098cd9ca7SRichard Henderson taken = gen_new_label(); 1801eaa3783bSRichard Henderson tcg_gen_brcond_reg(c, cond->a0, cond->a1, taken); 180298cd9ca7SRichard Henderson cond_free(cond); 180398cd9ca7SRichard Henderson 180498cd9ca7SRichard Henderson /* Not taken: Condition not satisfied; nullify on backward branches. */ 180598cd9ca7SRichard Henderson n = is_n && disp < 0; 180698cd9ca7SRichard Henderson if (n && use_nullify_skip(ctx)) { 180798cd9ca7SRichard Henderson nullify_set(ctx, 0); 1808a881c8e7SRichard Henderson gen_goto_tb(ctx, 0, ctx->iaoq_n, ctx->iaoq_n + 4); 180998cd9ca7SRichard Henderson } else { 181098cd9ca7SRichard Henderson if (!n && ctx->null_lab) { 181198cd9ca7SRichard Henderson gen_set_label(ctx->null_lab); 181298cd9ca7SRichard Henderson ctx->null_lab = NULL; 181398cd9ca7SRichard Henderson } 181498cd9ca7SRichard Henderson nullify_set(ctx, n); 1815c301f34eSRichard Henderson if (ctx->iaoq_n == -1) { 1816c301f34eSRichard Henderson /* The temporary iaoq_n_var died at the branch above. 1817c301f34eSRichard Henderson Regenerate it here instead of saving it. */ 1818c301f34eSRichard Henderson tcg_gen_addi_reg(ctx->iaoq_n_var, cpu_iaoq_b, 4); 1819c301f34eSRichard Henderson } 1820a881c8e7SRichard Henderson gen_goto_tb(ctx, 0, ctx->iaoq_b, ctx->iaoq_n); 182198cd9ca7SRichard Henderson } 182298cd9ca7SRichard Henderson 182398cd9ca7SRichard Henderson gen_set_label(taken); 182498cd9ca7SRichard Henderson 182598cd9ca7SRichard Henderson /* Taken: Condition satisfied; nullify on forward branches. */ 182698cd9ca7SRichard Henderson n = is_n && disp >= 0; 182798cd9ca7SRichard Henderson if (n && use_nullify_skip(ctx)) { 182898cd9ca7SRichard Henderson nullify_set(ctx, 0); 1829a881c8e7SRichard Henderson gen_goto_tb(ctx, 1, dest, dest + 4); 183098cd9ca7SRichard Henderson } else { 183198cd9ca7SRichard Henderson nullify_set(ctx, n); 1832a881c8e7SRichard Henderson gen_goto_tb(ctx, 1, ctx->iaoq_b, dest); 183398cd9ca7SRichard Henderson } 183498cd9ca7SRichard Henderson 183598cd9ca7SRichard Henderson /* Not taken: the branch itself was nullified. */ 183698cd9ca7SRichard Henderson if (ctx->null_lab) { 183798cd9ca7SRichard Henderson gen_set_label(ctx->null_lab); 183898cd9ca7SRichard Henderson ctx->null_lab = NULL; 183931234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE; 184098cd9ca7SRichard Henderson } else { 184131234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 184298cd9ca7SRichard Henderson } 184301afb7beSRichard Henderson return true; 184498cd9ca7SRichard Henderson } 184598cd9ca7SRichard Henderson 184698cd9ca7SRichard Henderson /* Emit an unconditional branch to an indirect target. This handles 184798cd9ca7SRichard Henderson nullification of the branch itself. */ 184801afb7beSRichard Henderson static bool do_ibranch(DisasContext *ctx, TCGv_reg dest, 184998cd9ca7SRichard Henderson unsigned link, bool is_n) 185098cd9ca7SRichard Henderson { 1851eaa3783bSRichard Henderson TCGv_reg a0, a1, next, tmp; 185298cd9ca7SRichard Henderson TCGCond c; 185398cd9ca7SRichard Henderson 185498cd9ca7SRichard Henderson assert(ctx->null_lab == NULL); 185598cd9ca7SRichard Henderson 185698cd9ca7SRichard Henderson if (ctx->null_cond.c == TCG_COND_NEVER) { 185798cd9ca7SRichard Henderson if (link != 0) { 185898cd9ca7SRichard Henderson copy_iaoq_entry(cpu_gr[link], ctx->iaoq_n, ctx->iaoq_n_var); 185998cd9ca7SRichard Henderson } 1860e12c6309SRichard Henderson next = tcg_temp_new(); 1861eaa3783bSRichard Henderson tcg_gen_mov_reg(next, dest); 186298cd9ca7SRichard Henderson if (is_n) { 1863c301f34eSRichard Henderson if (use_nullify_skip(ctx)) { 1864c301f34eSRichard Henderson tcg_gen_mov_reg(cpu_iaoq_f, next); 1865c301f34eSRichard Henderson tcg_gen_addi_reg(cpu_iaoq_b, next, 4); 1866c301f34eSRichard Henderson nullify_set(ctx, 0); 186731234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_UPDATED; 186801afb7beSRichard Henderson return true; 1869c301f34eSRichard Henderson } 187098cd9ca7SRichard Henderson ctx->null_cond.c = TCG_COND_ALWAYS; 187198cd9ca7SRichard Henderson } 1872c301f34eSRichard Henderson ctx->iaoq_n = -1; 1873c301f34eSRichard Henderson ctx->iaoq_n_var = next; 187498cd9ca7SRichard Henderson } else if (is_n && use_nullify_skip(ctx)) { 187598cd9ca7SRichard Henderson /* The (conditional) branch, B, nullifies the next insn, N, 187698cd9ca7SRichard Henderson and we're allowed to skip execution N (no single-step or 18774137cb83SRichard Henderson tracepoint in effect). Since the goto_ptr that we must use 187898cd9ca7SRichard Henderson for the indirect branch consumes no special resources, we 187998cd9ca7SRichard Henderson can (conditionally) skip B and continue execution. */ 188098cd9ca7SRichard Henderson /* The use_nullify_skip test implies we have a known control path. */ 188198cd9ca7SRichard Henderson tcg_debug_assert(ctx->iaoq_b != -1); 188298cd9ca7SRichard Henderson tcg_debug_assert(ctx->iaoq_n != -1); 188398cd9ca7SRichard Henderson 188498cd9ca7SRichard Henderson /* We do have to handle the non-local temporary, DEST, before 188598cd9ca7SRichard Henderson branching. Since IOAQ_F is not really live at this point, we 188698cd9ca7SRichard Henderson can simply store DEST optimistically. Similarly with IAOQ_B. */ 1887eaa3783bSRichard Henderson tcg_gen_mov_reg(cpu_iaoq_f, dest); 1888eaa3783bSRichard Henderson tcg_gen_addi_reg(cpu_iaoq_b, dest, 4); 188998cd9ca7SRichard Henderson 189098cd9ca7SRichard Henderson nullify_over(ctx); 189198cd9ca7SRichard Henderson if (link != 0) { 1892eaa3783bSRichard Henderson tcg_gen_movi_reg(cpu_gr[link], ctx->iaoq_n); 189398cd9ca7SRichard Henderson } 18947f11636dSEmilio G. Cota tcg_gen_lookup_and_goto_ptr(); 189501afb7beSRichard Henderson return nullify_end(ctx); 189698cd9ca7SRichard Henderson } else { 189798cd9ca7SRichard Henderson c = ctx->null_cond.c; 189898cd9ca7SRichard Henderson a0 = ctx->null_cond.a0; 189998cd9ca7SRichard Henderson a1 = ctx->null_cond.a1; 190098cd9ca7SRichard Henderson 190198cd9ca7SRichard Henderson tmp = tcg_temp_new(); 1902e12c6309SRichard Henderson next = tcg_temp_new(); 190398cd9ca7SRichard Henderson 190498cd9ca7SRichard Henderson copy_iaoq_entry(tmp, ctx->iaoq_n, ctx->iaoq_n_var); 1905eaa3783bSRichard Henderson tcg_gen_movcond_reg(c, next, a0, a1, tmp, dest); 190698cd9ca7SRichard Henderson ctx->iaoq_n = -1; 190798cd9ca7SRichard Henderson ctx->iaoq_n_var = next; 190898cd9ca7SRichard Henderson 190998cd9ca7SRichard Henderson if (link != 0) { 1910eaa3783bSRichard Henderson tcg_gen_movcond_reg(c, cpu_gr[link], a0, a1, cpu_gr[link], tmp); 191198cd9ca7SRichard Henderson } 191298cd9ca7SRichard Henderson 191398cd9ca7SRichard Henderson if (is_n) { 191498cd9ca7SRichard Henderson /* The branch nullifies the next insn, which means the state of N 191598cd9ca7SRichard Henderson after the branch is the inverse of the state of N that applied 191698cd9ca7SRichard Henderson to the branch. */ 1917eaa3783bSRichard Henderson tcg_gen_setcond_reg(tcg_invert_cond(c), cpu_psw_n, a0, a1); 191898cd9ca7SRichard Henderson cond_free(&ctx->null_cond); 191998cd9ca7SRichard Henderson ctx->null_cond = cond_make_n(); 192098cd9ca7SRichard Henderson ctx->psw_n_nonzero = true; 192198cd9ca7SRichard Henderson } else { 192298cd9ca7SRichard Henderson cond_free(&ctx->null_cond); 192398cd9ca7SRichard Henderson } 192498cd9ca7SRichard Henderson } 192501afb7beSRichard Henderson return true; 192698cd9ca7SRichard Henderson } 192798cd9ca7SRichard Henderson 1928660eefe1SRichard Henderson /* Implement 1929660eefe1SRichard Henderson * if (IAOQ_Front{30..31} < GR[b]{30..31}) 1930660eefe1SRichard Henderson * IAOQ_Next{30..31} ← GR[b]{30..31}; 1931660eefe1SRichard Henderson * else 1932660eefe1SRichard Henderson * IAOQ_Next{30..31} ← IAOQ_Front{30..31}; 1933660eefe1SRichard Henderson * which keeps the privilege level from being increased. 1934660eefe1SRichard Henderson */ 1935660eefe1SRichard Henderson static TCGv_reg do_ibranch_priv(DisasContext *ctx, TCGv_reg offset) 1936660eefe1SRichard Henderson { 1937660eefe1SRichard Henderson TCGv_reg dest; 1938660eefe1SRichard Henderson switch (ctx->privilege) { 1939660eefe1SRichard Henderson case 0: 1940660eefe1SRichard Henderson /* Privilege 0 is maximum and is allowed to decrease. */ 1941660eefe1SRichard Henderson return offset; 1942660eefe1SRichard Henderson case 3: 1943993119feSRichard Henderson /* Privilege 3 is minimum and is never allowed to increase. */ 1944e12c6309SRichard Henderson dest = tcg_temp_new(); 1945660eefe1SRichard Henderson tcg_gen_ori_reg(dest, offset, 3); 1946660eefe1SRichard Henderson break; 1947660eefe1SRichard Henderson default: 1948e12c6309SRichard Henderson dest = tcg_temp_new(); 1949660eefe1SRichard Henderson tcg_gen_andi_reg(dest, offset, -4); 1950660eefe1SRichard Henderson tcg_gen_ori_reg(dest, dest, ctx->privilege); 1951660eefe1SRichard Henderson tcg_gen_movcond_reg(TCG_COND_GTU, dest, dest, offset, dest, offset); 1952660eefe1SRichard Henderson break; 1953660eefe1SRichard Henderson } 1954660eefe1SRichard Henderson return dest; 1955660eefe1SRichard Henderson } 1956660eefe1SRichard Henderson 1957ba1d0b44SRichard Henderson #ifdef CONFIG_USER_ONLY 19587ad439dfSRichard Henderson /* On Linux, page zero is normally marked execute only + gateway. 19597ad439dfSRichard Henderson Therefore normal read or write is supposed to fail, but specific 19607ad439dfSRichard Henderson offsets have kernel code mapped to raise permissions to implement 19617ad439dfSRichard Henderson system calls. Handling this via an explicit check here, rather 19627ad439dfSRichard Henderson in than the "be disp(sr2,r0)" instruction that probably sent us 19637ad439dfSRichard Henderson here, is the easiest way to handle the branch delay slot on the 19647ad439dfSRichard Henderson aforementioned BE. */ 196531234768SRichard Henderson static void do_page_zero(DisasContext *ctx) 19667ad439dfSRichard Henderson { 19677ad439dfSRichard Henderson /* If by some means we get here with PSW[N]=1, that implies that 19687ad439dfSRichard Henderson the B,GATE instruction would be skipped, and we'd fault on the 19698b81968cSMichael Tokarev next insn within the privileged page. */ 19707ad439dfSRichard Henderson switch (ctx->null_cond.c) { 19717ad439dfSRichard Henderson case TCG_COND_NEVER: 19727ad439dfSRichard Henderson break; 19737ad439dfSRichard Henderson case TCG_COND_ALWAYS: 1974eaa3783bSRichard Henderson tcg_gen_movi_reg(cpu_psw_n, 0); 19757ad439dfSRichard Henderson goto do_sigill; 19767ad439dfSRichard Henderson default: 19777ad439dfSRichard Henderson /* Since this is always the first (and only) insn within the 19787ad439dfSRichard Henderson TB, we should know the state of PSW[N] from TB->FLAGS. */ 19797ad439dfSRichard Henderson g_assert_not_reached(); 19807ad439dfSRichard Henderson } 19817ad439dfSRichard Henderson 19827ad439dfSRichard Henderson /* Check that we didn't arrive here via some means that allowed 19837ad439dfSRichard Henderson non-sequential instruction execution. Normally the PSW[B] bit 19847ad439dfSRichard Henderson detects this by disallowing the B,GATE instruction to execute 19857ad439dfSRichard Henderson under such conditions. */ 19867ad439dfSRichard Henderson if (ctx->iaoq_b != ctx->iaoq_f + 4) { 19877ad439dfSRichard Henderson goto do_sigill; 19887ad439dfSRichard Henderson } 19897ad439dfSRichard Henderson 1990ebd0e151SRichard Henderson switch (ctx->iaoq_f & -4) { 19917ad439dfSRichard Henderson case 0x00: /* Null pointer call */ 19922986721dSRichard Henderson gen_excp_1(EXCP_IMP); 199331234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 199431234768SRichard Henderson break; 19957ad439dfSRichard Henderson 19967ad439dfSRichard Henderson case 0xb0: /* LWS */ 19977ad439dfSRichard Henderson gen_excp_1(EXCP_SYSCALL_LWS); 199831234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 199931234768SRichard Henderson break; 20007ad439dfSRichard Henderson 20017ad439dfSRichard Henderson case 0xe0: /* SET_THREAD_POINTER */ 2002ad75a51eSRichard Henderson tcg_gen_st_reg(cpu_gr[26], tcg_env, offsetof(CPUHPPAState, cr[27])); 2003ebd0e151SRichard Henderson tcg_gen_ori_reg(cpu_iaoq_f, cpu_gr[31], 3); 2004eaa3783bSRichard Henderson tcg_gen_addi_reg(cpu_iaoq_b, cpu_iaoq_f, 4); 200531234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_UPDATED; 200631234768SRichard Henderson break; 20077ad439dfSRichard Henderson 20087ad439dfSRichard Henderson case 0x100: /* SYSCALL */ 20097ad439dfSRichard Henderson gen_excp_1(EXCP_SYSCALL); 201031234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 201131234768SRichard Henderson break; 20127ad439dfSRichard Henderson 20137ad439dfSRichard Henderson default: 20147ad439dfSRichard Henderson do_sigill: 20152986721dSRichard Henderson gen_excp_1(EXCP_ILL); 201631234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 201731234768SRichard Henderson break; 20187ad439dfSRichard Henderson } 20197ad439dfSRichard Henderson } 2020ba1d0b44SRichard Henderson #endif 20217ad439dfSRichard Henderson 2022deee69a1SRichard Henderson static bool trans_nop(DisasContext *ctx, arg_nop *a) 2023b2167459SRichard Henderson { 2024b2167459SRichard Henderson cond_free(&ctx->null_cond); 202531234768SRichard Henderson return true; 2026b2167459SRichard Henderson } 2027b2167459SRichard Henderson 202840f9f908SRichard Henderson static bool trans_break(DisasContext *ctx, arg_break *a) 202998a9cb79SRichard Henderson { 203031234768SRichard Henderson return gen_excp_iir(ctx, EXCP_BREAK); 203198a9cb79SRichard Henderson } 203298a9cb79SRichard Henderson 2033e36f27efSRichard Henderson static bool trans_sync(DisasContext *ctx, arg_sync *a) 203498a9cb79SRichard Henderson { 203598a9cb79SRichard Henderson /* No point in nullifying the memory barrier. */ 203698a9cb79SRichard Henderson tcg_gen_mb(TCG_BAR_SC | TCG_MO_ALL); 203798a9cb79SRichard Henderson 203898a9cb79SRichard Henderson cond_free(&ctx->null_cond); 203931234768SRichard Henderson return true; 204098a9cb79SRichard Henderson } 204198a9cb79SRichard Henderson 2042c603e14aSRichard Henderson static bool trans_mfia(DisasContext *ctx, arg_mfia *a) 204398a9cb79SRichard Henderson { 2044c603e14aSRichard Henderson unsigned rt = a->t; 2045eaa3783bSRichard Henderson TCGv_reg tmp = dest_gpr(ctx, rt); 2046eaa3783bSRichard Henderson tcg_gen_movi_reg(tmp, ctx->iaoq_f); 204798a9cb79SRichard Henderson save_gpr(ctx, rt, tmp); 204898a9cb79SRichard Henderson 204998a9cb79SRichard Henderson cond_free(&ctx->null_cond); 205031234768SRichard Henderson return true; 205198a9cb79SRichard Henderson } 205298a9cb79SRichard Henderson 2053c603e14aSRichard Henderson static bool trans_mfsp(DisasContext *ctx, arg_mfsp *a) 205498a9cb79SRichard Henderson { 2055c603e14aSRichard Henderson unsigned rt = a->t; 2056c603e14aSRichard Henderson unsigned rs = a->sp; 205733423472SRichard Henderson TCGv_i64 t0 = tcg_temp_new_i64(); 205833423472SRichard Henderson TCGv_reg t1 = tcg_temp_new(); 205998a9cb79SRichard Henderson 206033423472SRichard Henderson load_spr(ctx, t0, rs); 206133423472SRichard Henderson tcg_gen_shri_i64(t0, t0, 32); 206233423472SRichard Henderson tcg_gen_trunc_i64_reg(t1, t0); 206333423472SRichard Henderson 206433423472SRichard Henderson save_gpr(ctx, rt, t1); 206598a9cb79SRichard Henderson 206698a9cb79SRichard Henderson cond_free(&ctx->null_cond); 206731234768SRichard Henderson return true; 206898a9cb79SRichard Henderson } 206998a9cb79SRichard Henderson 2070c603e14aSRichard Henderson static bool trans_mfctl(DisasContext *ctx, arg_mfctl *a) 207198a9cb79SRichard Henderson { 2072c603e14aSRichard Henderson unsigned rt = a->t; 2073c603e14aSRichard Henderson unsigned ctl = a->r; 2074eaa3783bSRichard Henderson TCGv_reg tmp; 207598a9cb79SRichard Henderson 207698a9cb79SRichard Henderson switch (ctl) { 207735136a77SRichard Henderson case CR_SAR: 207898a9cb79SRichard Henderson #ifdef TARGET_HPPA64 2079c603e14aSRichard Henderson if (a->e == 0) { 208098a9cb79SRichard Henderson /* MFSAR without ,W masks low 5 bits. */ 208198a9cb79SRichard Henderson tmp = dest_gpr(ctx, rt); 2082eaa3783bSRichard Henderson tcg_gen_andi_reg(tmp, cpu_sar, 31); 208398a9cb79SRichard Henderson save_gpr(ctx, rt, tmp); 208435136a77SRichard Henderson goto done; 208598a9cb79SRichard Henderson } 208698a9cb79SRichard Henderson #endif 208798a9cb79SRichard Henderson save_gpr(ctx, rt, cpu_sar); 208835136a77SRichard Henderson goto done; 208935136a77SRichard Henderson case CR_IT: /* Interval Timer */ 209035136a77SRichard Henderson /* FIXME: Respect PSW_S bit. */ 209135136a77SRichard Henderson nullify_over(ctx); 209298a9cb79SRichard Henderson tmp = dest_gpr(ctx, rt); 2093dfd1b812SRichard Henderson if (translator_io_start(&ctx->base)) { 209449c29d6cSRichard Henderson gen_helper_read_interval_timer(tmp); 209531234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE; 209649c29d6cSRichard Henderson } else { 209749c29d6cSRichard Henderson gen_helper_read_interval_timer(tmp); 209849c29d6cSRichard Henderson } 209998a9cb79SRichard Henderson save_gpr(ctx, rt, tmp); 210031234768SRichard Henderson return nullify_end(ctx); 210198a9cb79SRichard Henderson case 26: 210298a9cb79SRichard Henderson case 27: 210398a9cb79SRichard Henderson break; 210498a9cb79SRichard Henderson default: 210598a9cb79SRichard Henderson /* All other control registers are privileged. */ 210635136a77SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_REG); 210735136a77SRichard Henderson break; 210898a9cb79SRichard Henderson } 210998a9cb79SRichard Henderson 2110e12c6309SRichard Henderson tmp = tcg_temp_new(); 2111ad75a51eSRichard Henderson tcg_gen_ld_reg(tmp, tcg_env, offsetof(CPUHPPAState, cr[ctl])); 211235136a77SRichard Henderson save_gpr(ctx, rt, tmp); 211335136a77SRichard Henderson 211435136a77SRichard Henderson done: 211598a9cb79SRichard Henderson cond_free(&ctx->null_cond); 211631234768SRichard Henderson return true; 211798a9cb79SRichard Henderson } 211898a9cb79SRichard Henderson 2119c603e14aSRichard Henderson static bool trans_mtsp(DisasContext *ctx, arg_mtsp *a) 212033423472SRichard Henderson { 2121c603e14aSRichard Henderson unsigned rr = a->r; 2122c603e14aSRichard Henderson unsigned rs = a->sp; 212333423472SRichard Henderson TCGv_i64 t64; 212433423472SRichard Henderson 212533423472SRichard Henderson if (rs >= 5) { 212633423472SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_REG); 212733423472SRichard Henderson } 212833423472SRichard Henderson nullify_over(ctx); 212933423472SRichard Henderson 213033423472SRichard Henderson t64 = tcg_temp_new_i64(); 213133423472SRichard Henderson tcg_gen_extu_reg_i64(t64, load_gpr(ctx, rr)); 213233423472SRichard Henderson tcg_gen_shli_i64(t64, t64, 32); 213333423472SRichard Henderson 213433423472SRichard Henderson if (rs >= 4) { 2135ad75a51eSRichard Henderson tcg_gen_st_i64(t64, tcg_env, offsetof(CPUHPPAState, sr[rs])); 2136494737b7SRichard Henderson ctx->tb_flags &= ~TB_FLAG_SR_SAME; 213733423472SRichard Henderson } else { 213833423472SRichard Henderson tcg_gen_mov_i64(cpu_sr[rs], t64); 213933423472SRichard Henderson } 214033423472SRichard Henderson 214131234768SRichard Henderson return nullify_end(ctx); 214233423472SRichard Henderson } 214333423472SRichard Henderson 2144c603e14aSRichard Henderson static bool trans_mtctl(DisasContext *ctx, arg_mtctl *a) 214598a9cb79SRichard Henderson { 2146c603e14aSRichard Henderson unsigned ctl = a->t; 21474845f015SSven Schnelle TCGv_reg reg; 2148eaa3783bSRichard Henderson TCGv_reg tmp; 214998a9cb79SRichard Henderson 215035136a77SRichard Henderson if (ctl == CR_SAR) { 21514845f015SSven Schnelle reg = load_gpr(ctx, a->r); 215298a9cb79SRichard Henderson tmp = tcg_temp_new(); 215335136a77SRichard Henderson tcg_gen_andi_reg(tmp, reg, TARGET_REGISTER_BITS - 1); 215498a9cb79SRichard Henderson save_or_nullify(ctx, cpu_sar, tmp); 215598a9cb79SRichard Henderson 215698a9cb79SRichard Henderson cond_free(&ctx->null_cond); 215731234768SRichard Henderson return true; 215898a9cb79SRichard Henderson } 215998a9cb79SRichard Henderson 216035136a77SRichard Henderson /* All other control registers are privileged or read-only. */ 216135136a77SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_REG); 216235136a77SRichard Henderson 2163c603e14aSRichard Henderson #ifndef CONFIG_USER_ONLY 216435136a77SRichard Henderson nullify_over(ctx); 21654845f015SSven Schnelle reg = load_gpr(ctx, a->r); 21664845f015SSven Schnelle 216735136a77SRichard Henderson switch (ctl) { 216835136a77SRichard Henderson case CR_IT: 2169ad75a51eSRichard Henderson gen_helper_write_interval_timer(tcg_env, reg); 217035136a77SRichard Henderson break; 21714f5f2548SRichard Henderson case CR_EIRR: 2172ad75a51eSRichard Henderson gen_helper_write_eirr(tcg_env, reg); 21734f5f2548SRichard Henderson break; 21744f5f2548SRichard Henderson case CR_EIEM: 2175ad75a51eSRichard Henderson gen_helper_write_eiem(tcg_env, reg); 217631234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE_EXIT; 21774f5f2548SRichard Henderson break; 21784f5f2548SRichard Henderson 217935136a77SRichard Henderson case CR_IIASQ: 218035136a77SRichard Henderson case CR_IIAOQ: 218135136a77SRichard Henderson /* FIXME: Respect PSW_Q bit */ 218235136a77SRichard Henderson /* The write advances the queue and stores to the back element. */ 2183e12c6309SRichard Henderson tmp = tcg_temp_new(); 2184ad75a51eSRichard Henderson tcg_gen_ld_reg(tmp, tcg_env, 218535136a77SRichard Henderson offsetof(CPUHPPAState, cr_back[ctl - CR_IIASQ])); 2186ad75a51eSRichard Henderson tcg_gen_st_reg(tmp, tcg_env, offsetof(CPUHPPAState, cr[ctl])); 2187ad75a51eSRichard Henderson tcg_gen_st_reg(reg, tcg_env, 218835136a77SRichard Henderson offsetof(CPUHPPAState, cr_back[ctl - CR_IIASQ])); 218935136a77SRichard Henderson break; 219035136a77SRichard Henderson 2191d5de20bdSSven Schnelle case CR_PID1: 2192d5de20bdSSven Schnelle case CR_PID2: 2193d5de20bdSSven Schnelle case CR_PID3: 2194d5de20bdSSven Schnelle case CR_PID4: 2195ad75a51eSRichard Henderson tcg_gen_st_reg(reg, tcg_env, offsetof(CPUHPPAState, cr[ctl])); 2196d5de20bdSSven Schnelle #ifndef CONFIG_USER_ONLY 2197ad75a51eSRichard Henderson gen_helper_change_prot_id(tcg_env); 2198d5de20bdSSven Schnelle #endif 2199d5de20bdSSven Schnelle break; 2200d5de20bdSSven Schnelle 220135136a77SRichard Henderson default: 2202ad75a51eSRichard Henderson tcg_gen_st_reg(reg, tcg_env, offsetof(CPUHPPAState, cr[ctl])); 220335136a77SRichard Henderson break; 220435136a77SRichard Henderson } 220531234768SRichard Henderson return nullify_end(ctx); 22064f5f2548SRichard Henderson #endif 220735136a77SRichard Henderson } 220835136a77SRichard Henderson 2209c603e14aSRichard Henderson static bool trans_mtsarcm(DisasContext *ctx, arg_mtsarcm *a) 221098a9cb79SRichard Henderson { 2211eaa3783bSRichard Henderson TCGv_reg tmp = tcg_temp_new(); 221298a9cb79SRichard Henderson 2213c603e14aSRichard Henderson tcg_gen_not_reg(tmp, load_gpr(ctx, a->r)); 2214eaa3783bSRichard Henderson tcg_gen_andi_reg(tmp, tmp, TARGET_REGISTER_BITS - 1); 221598a9cb79SRichard Henderson save_or_nullify(ctx, cpu_sar, tmp); 221698a9cb79SRichard Henderson 221798a9cb79SRichard Henderson cond_free(&ctx->null_cond); 221831234768SRichard Henderson return true; 221998a9cb79SRichard Henderson } 222098a9cb79SRichard Henderson 2221e36f27efSRichard Henderson static bool trans_ldsid(DisasContext *ctx, arg_ldsid *a) 222298a9cb79SRichard Henderson { 2223e36f27efSRichard Henderson TCGv_reg dest = dest_gpr(ctx, a->t); 222498a9cb79SRichard Henderson 22252330504cSHelge Deller #ifdef CONFIG_USER_ONLY 22262330504cSHelge Deller /* We don't implement space registers in user mode. */ 2227eaa3783bSRichard Henderson tcg_gen_movi_reg(dest, 0); 22282330504cSHelge Deller #else 22292330504cSHelge Deller TCGv_i64 t0 = tcg_temp_new_i64(); 22302330504cSHelge Deller 2231e36f27efSRichard Henderson tcg_gen_mov_i64(t0, space_select(ctx, a->sp, load_gpr(ctx, a->b))); 22322330504cSHelge Deller tcg_gen_shri_i64(t0, t0, 32); 22332330504cSHelge Deller tcg_gen_trunc_i64_reg(dest, t0); 22342330504cSHelge Deller #endif 2235e36f27efSRichard Henderson save_gpr(ctx, a->t, dest); 223698a9cb79SRichard Henderson 223798a9cb79SRichard Henderson cond_free(&ctx->null_cond); 223831234768SRichard Henderson return true; 223998a9cb79SRichard Henderson } 224098a9cb79SRichard Henderson 2241e36f27efSRichard Henderson static bool trans_rsm(DisasContext *ctx, arg_rsm *a) 2242e36f27efSRichard Henderson { 2243e36f27efSRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 2244e1b5a5edSRichard Henderson #ifndef CONFIG_USER_ONLY 2245e1b5a5edSRichard Henderson TCGv_reg tmp; 2246e1b5a5edSRichard Henderson 2247e1b5a5edSRichard Henderson nullify_over(ctx); 2248e1b5a5edSRichard Henderson 2249e12c6309SRichard Henderson tmp = tcg_temp_new(); 2250ad75a51eSRichard Henderson tcg_gen_ld_reg(tmp, tcg_env, offsetof(CPUHPPAState, psw)); 2251e36f27efSRichard Henderson tcg_gen_andi_reg(tmp, tmp, ~a->i); 2252ad75a51eSRichard Henderson gen_helper_swap_system_mask(tmp, tcg_env, tmp); 2253e36f27efSRichard Henderson save_gpr(ctx, a->t, tmp); 2254e1b5a5edSRichard Henderson 2255e1b5a5edSRichard Henderson /* Exit the TB to recognize new interrupts, e.g. PSW_M. */ 225631234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE_EXIT; 225731234768SRichard Henderson return nullify_end(ctx); 2258e36f27efSRichard Henderson #endif 2259e1b5a5edSRichard Henderson } 2260e1b5a5edSRichard Henderson 2261e36f27efSRichard Henderson static bool trans_ssm(DisasContext *ctx, arg_ssm *a) 2262e1b5a5edSRichard Henderson { 2263e36f27efSRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 2264e36f27efSRichard Henderson #ifndef CONFIG_USER_ONLY 2265e1b5a5edSRichard Henderson TCGv_reg tmp; 2266e1b5a5edSRichard Henderson 2267e1b5a5edSRichard Henderson nullify_over(ctx); 2268e1b5a5edSRichard Henderson 2269e12c6309SRichard Henderson tmp = tcg_temp_new(); 2270ad75a51eSRichard Henderson tcg_gen_ld_reg(tmp, tcg_env, offsetof(CPUHPPAState, psw)); 2271e36f27efSRichard Henderson tcg_gen_ori_reg(tmp, tmp, a->i); 2272ad75a51eSRichard Henderson gen_helper_swap_system_mask(tmp, tcg_env, tmp); 2273e36f27efSRichard Henderson save_gpr(ctx, a->t, tmp); 2274e1b5a5edSRichard Henderson 2275e1b5a5edSRichard Henderson /* Exit the TB to recognize new interrupts, e.g. PSW_I. */ 227631234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE_EXIT; 227731234768SRichard Henderson return nullify_end(ctx); 2278e36f27efSRichard Henderson #endif 2279e1b5a5edSRichard Henderson } 2280e1b5a5edSRichard Henderson 2281c603e14aSRichard Henderson static bool trans_mtsm(DisasContext *ctx, arg_mtsm *a) 2282e1b5a5edSRichard Henderson { 2283e1b5a5edSRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 2284c603e14aSRichard Henderson #ifndef CONFIG_USER_ONLY 2285c603e14aSRichard Henderson TCGv_reg tmp, reg; 2286e1b5a5edSRichard Henderson nullify_over(ctx); 2287e1b5a5edSRichard Henderson 2288c603e14aSRichard Henderson reg = load_gpr(ctx, a->r); 2289e12c6309SRichard Henderson tmp = tcg_temp_new(); 2290ad75a51eSRichard Henderson gen_helper_swap_system_mask(tmp, tcg_env, reg); 2291e1b5a5edSRichard Henderson 2292e1b5a5edSRichard Henderson /* Exit the TB to recognize new interrupts. */ 229331234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE_EXIT; 229431234768SRichard Henderson return nullify_end(ctx); 2295c603e14aSRichard Henderson #endif 2296e1b5a5edSRichard Henderson } 2297f49b3537SRichard Henderson 2298e36f27efSRichard Henderson static bool do_rfi(DisasContext *ctx, bool rfi_r) 2299f49b3537SRichard Henderson { 2300f49b3537SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 2301e36f27efSRichard Henderson #ifndef CONFIG_USER_ONLY 2302f49b3537SRichard Henderson nullify_over(ctx); 2303f49b3537SRichard Henderson 2304e36f27efSRichard Henderson if (rfi_r) { 2305ad75a51eSRichard Henderson gen_helper_rfi_r(tcg_env); 2306f49b3537SRichard Henderson } else { 2307ad75a51eSRichard Henderson gen_helper_rfi(tcg_env); 2308f49b3537SRichard Henderson } 230931234768SRichard Henderson /* Exit the TB to recognize new interrupts. */ 231007ea28b4SRichard Henderson tcg_gen_exit_tb(NULL, 0); 231131234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 2312f49b3537SRichard Henderson 231331234768SRichard Henderson return nullify_end(ctx); 2314e36f27efSRichard Henderson #endif 2315f49b3537SRichard Henderson } 23166210db05SHelge Deller 2317e36f27efSRichard Henderson static bool trans_rfi(DisasContext *ctx, arg_rfi *a) 2318e36f27efSRichard Henderson { 2319e36f27efSRichard Henderson return do_rfi(ctx, false); 2320e36f27efSRichard Henderson } 2321e36f27efSRichard Henderson 2322e36f27efSRichard Henderson static bool trans_rfi_r(DisasContext *ctx, arg_rfi_r *a) 2323e36f27efSRichard Henderson { 2324e36f27efSRichard Henderson return do_rfi(ctx, true); 2325e36f27efSRichard Henderson } 2326e36f27efSRichard Henderson 232796927adbSRichard Henderson static bool trans_halt(DisasContext *ctx, arg_halt *a) 23286210db05SHelge Deller { 23296210db05SHelge Deller CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 233096927adbSRichard Henderson #ifndef CONFIG_USER_ONLY 23316210db05SHelge Deller nullify_over(ctx); 2332ad75a51eSRichard Henderson gen_helper_halt(tcg_env); 233331234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 233431234768SRichard Henderson return nullify_end(ctx); 233596927adbSRichard Henderson #endif 23366210db05SHelge Deller } 233796927adbSRichard Henderson 233896927adbSRichard Henderson static bool trans_reset(DisasContext *ctx, arg_reset *a) 233996927adbSRichard Henderson { 234096927adbSRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 234196927adbSRichard Henderson #ifndef CONFIG_USER_ONLY 234296927adbSRichard Henderson nullify_over(ctx); 2343ad75a51eSRichard Henderson gen_helper_reset(tcg_env); 234496927adbSRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 234596927adbSRichard Henderson return nullify_end(ctx); 234696927adbSRichard Henderson #endif 234796927adbSRichard Henderson } 2348e1b5a5edSRichard Henderson 23494a4554c6SHelge Deller static bool trans_getshadowregs(DisasContext *ctx, arg_getshadowregs *a) 23504a4554c6SHelge Deller { 23514a4554c6SHelge Deller CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 23524a4554c6SHelge Deller #ifndef CONFIG_USER_ONLY 23534a4554c6SHelge Deller nullify_over(ctx); 2354ad75a51eSRichard Henderson gen_helper_getshadowregs(tcg_env); 23554a4554c6SHelge Deller return nullify_end(ctx); 23564a4554c6SHelge Deller #endif 23574a4554c6SHelge Deller } 23584a4554c6SHelge Deller 2359deee69a1SRichard Henderson static bool trans_nop_addrx(DisasContext *ctx, arg_ldst *a) 236098a9cb79SRichard Henderson { 2361deee69a1SRichard Henderson if (a->m) { 2362deee69a1SRichard Henderson TCGv_reg dest = dest_gpr(ctx, a->b); 2363deee69a1SRichard Henderson TCGv_reg src1 = load_gpr(ctx, a->b); 2364deee69a1SRichard Henderson TCGv_reg src2 = load_gpr(ctx, a->x); 236598a9cb79SRichard Henderson 236698a9cb79SRichard Henderson /* The only thing we need to do is the base register modification. */ 2367eaa3783bSRichard Henderson tcg_gen_add_reg(dest, src1, src2); 2368deee69a1SRichard Henderson save_gpr(ctx, a->b, dest); 2369deee69a1SRichard Henderson } 237098a9cb79SRichard Henderson cond_free(&ctx->null_cond); 237131234768SRichard Henderson return true; 237298a9cb79SRichard Henderson } 237398a9cb79SRichard Henderson 2374deee69a1SRichard Henderson static bool trans_probe(DisasContext *ctx, arg_probe *a) 237598a9cb79SRichard Henderson { 237686f8d05fSRichard Henderson TCGv_reg dest, ofs; 2377eed14219SRichard Henderson TCGv_i32 level, want; 237886f8d05fSRichard Henderson TCGv_tl addr; 237998a9cb79SRichard Henderson 238098a9cb79SRichard Henderson nullify_over(ctx); 238198a9cb79SRichard Henderson 2382deee69a1SRichard Henderson dest = dest_gpr(ctx, a->t); 2383deee69a1SRichard Henderson form_gva(ctx, &addr, &ofs, a->b, 0, 0, 0, a->sp, 0, false); 2384eed14219SRichard Henderson 2385deee69a1SRichard Henderson if (a->imm) { 238629dd6f64SRichard Henderson level = tcg_constant_i32(a->ri); 238798a9cb79SRichard Henderson } else { 2388eed14219SRichard Henderson level = tcg_temp_new_i32(); 2389deee69a1SRichard Henderson tcg_gen_trunc_reg_i32(level, load_gpr(ctx, a->ri)); 2390eed14219SRichard Henderson tcg_gen_andi_i32(level, level, 3); 239198a9cb79SRichard Henderson } 239229dd6f64SRichard Henderson want = tcg_constant_i32(a->write ? PAGE_WRITE : PAGE_READ); 2393eed14219SRichard Henderson 2394ad75a51eSRichard Henderson gen_helper_probe(dest, tcg_env, addr, level, want); 2395eed14219SRichard Henderson 2396deee69a1SRichard Henderson save_gpr(ctx, a->t, dest); 239731234768SRichard Henderson return nullify_end(ctx); 239898a9cb79SRichard Henderson } 239998a9cb79SRichard Henderson 2400deee69a1SRichard Henderson static bool trans_ixtlbx(DisasContext *ctx, arg_ixtlbx *a) 24018d6ae7fbSRichard Henderson { 2402deee69a1SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 2403deee69a1SRichard Henderson #ifndef CONFIG_USER_ONLY 24048d6ae7fbSRichard Henderson TCGv_tl addr; 24058d6ae7fbSRichard Henderson TCGv_reg ofs, reg; 24068d6ae7fbSRichard Henderson 24078d6ae7fbSRichard Henderson nullify_over(ctx); 24088d6ae7fbSRichard Henderson 2409deee69a1SRichard Henderson form_gva(ctx, &addr, &ofs, a->b, 0, 0, 0, a->sp, 0, false); 2410deee69a1SRichard Henderson reg = load_gpr(ctx, a->r); 2411deee69a1SRichard Henderson if (a->addr) { 2412ad75a51eSRichard Henderson gen_helper_itlba(tcg_env, addr, reg); 24138d6ae7fbSRichard Henderson } else { 2414ad75a51eSRichard Henderson gen_helper_itlbp(tcg_env, addr, reg); 24158d6ae7fbSRichard Henderson } 24168d6ae7fbSRichard Henderson 241732dc7569SSven Schnelle /* Exit TB for TLB change if mmu is enabled. */ 241832dc7569SSven Schnelle if (ctx->tb_flags & PSW_C) { 241931234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE; 242031234768SRichard Henderson } 242131234768SRichard Henderson return nullify_end(ctx); 2422deee69a1SRichard Henderson #endif 24238d6ae7fbSRichard Henderson } 242463300a00SRichard Henderson 2425deee69a1SRichard Henderson static bool trans_pxtlbx(DisasContext *ctx, arg_pxtlbx *a) 242663300a00SRichard Henderson { 2427deee69a1SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 2428deee69a1SRichard Henderson #ifndef CONFIG_USER_ONLY 242963300a00SRichard Henderson TCGv_tl addr; 243063300a00SRichard Henderson TCGv_reg ofs; 243163300a00SRichard Henderson 243263300a00SRichard Henderson nullify_over(ctx); 243363300a00SRichard Henderson 2434deee69a1SRichard Henderson form_gva(ctx, &addr, &ofs, a->b, a->x, 0, 0, a->sp, a->m, false); 2435deee69a1SRichard Henderson if (a->m) { 2436deee69a1SRichard Henderson save_gpr(ctx, a->b, ofs); 243763300a00SRichard Henderson } 2438deee69a1SRichard Henderson if (a->local) { 2439ad75a51eSRichard Henderson gen_helper_ptlbe(tcg_env); 244063300a00SRichard Henderson } else { 2441ad75a51eSRichard Henderson gen_helper_ptlb(tcg_env, addr); 244263300a00SRichard Henderson } 244363300a00SRichard Henderson 244463300a00SRichard Henderson /* Exit TB for TLB change if mmu is enabled. */ 244532dc7569SSven Schnelle if (ctx->tb_flags & PSW_C) { 244631234768SRichard Henderson ctx->base.is_jmp = DISAS_IAQ_N_STALE; 244731234768SRichard Henderson } 244831234768SRichard Henderson return nullify_end(ctx); 2449deee69a1SRichard Henderson #endif 245063300a00SRichard Henderson } 24512dfcca9fSRichard Henderson 24526797c315SNick Hudson /* 24536797c315SNick Hudson * Implement the pcxl and pcxl2 Fast TLB Insert instructions. 24546797c315SNick Hudson * See 24556797c315SNick Hudson * https://parisc.wiki.kernel.org/images-parisc/a/a9/Pcxl2_ers.pdf 24566797c315SNick Hudson * page 13-9 (195/206) 24576797c315SNick Hudson */ 24586797c315SNick Hudson static bool trans_ixtlbxf(DisasContext *ctx, arg_ixtlbxf *a) 24596797c315SNick Hudson { 24606797c315SNick Hudson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 24616797c315SNick Hudson #ifndef CONFIG_USER_ONLY 24626797c315SNick Hudson TCGv_tl addr, atl, stl; 24636797c315SNick Hudson TCGv_reg reg; 24646797c315SNick Hudson 24656797c315SNick Hudson nullify_over(ctx); 24666797c315SNick Hudson 24676797c315SNick Hudson /* 24686797c315SNick Hudson * FIXME: 24696797c315SNick Hudson * if (not (pcxl or pcxl2)) 24706797c315SNick Hudson * return gen_illegal(ctx); 24716797c315SNick Hudson * 24726797c315SNick Hudson * Note for future: these are 32-bit systems; no hppa64. 24736797c315SNick Hudson */ 24746797c315SNick Hudson 24756797c315SNick Hudson atl = tcg_temp_new_tl(); 24766797c315SNick Hudson stl = tcg_temp_new_tl(); 24776797c315SNick Hudson addr = tcg_temp_new_tl(); 24786797c315SNick Hudson 2479ad75a51eSRichard Henderson tcg_gen_ld32u_i64(stl, tcg_env, 24806797c315SNick Hudson a->data ? offsetof(CPUHPPAState, cr[CR_ISR]) 24816797c315SNick Hudson : offsetof(CPUHPPAState, cr[CR_IIASQ])); 2482ad75a51eSRichard Henderson tcg_gen_ld32u_i64(atl, tcg_env, 24836797c315SNick Hudson a->data ? offsetof(CPUHPPAState, cr[CR_IOR]) 24846797c315SNick Hudson : offsetof(CPUHPPAState, cr[CR_IIAOQ])); 24856797c315SNick Hudson tcg_gen_shli_i64(stl, stl, 32); 24866797c315SNick Hudson tcg_gen_or_tl(addr, atl, stl); 24876797c315SNick Hudson 24886797c315SNick Hudson reg = load_gpr(ctx, a->r); 24896797c315SNick Hudson if (a->addr) { 2490ad75a51eSRichard Henderson gen_helper_itlba(tcg_env, addr, reg); 24916797c315SNick Hudson } else { 2492ad75a51eSRichard Henderson gen_helper_itlbp(tcg_env, addr, reg); 24936797c315SNick Hudson } 24946797c315SNick Hudson 24956797c315SNick Hudson /* Exit TB for TLB change if mmu is enabled. */ 24966797c315SNick Hudson if (ctx->tb_flags & PSW_C) { 24976797c315SNick Hudson ctx->base.is_jmp = DISAS_IAQ_N_STALE; 24986797c315SNick Hudson } 24996797c315SNick Hudson return nullify_end(ctx); 25006797c315SNick Hudson #endif 25016797c315SNick Hudson } 25026797c315SNick Hudson 2503deee69a1SRichard Henderson static bool trans_lpa(DisasContext *ctx, arg_ldst *a) 25042dfcca9fSRichard Henderson { 2505deee69a1SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 2506deee69a1SRichard Henderson #ifndef CONFIG_USER_ONLY 25072dfcca9fSRichard Henderson TCGv_tl vaddr; 25082dfcca9fSRichard Henderson TCGv_reg ofs, paddr; 25092dfcca9fSRichard Henderson 25102dfcca9fSRichard Henderson nullify_over(ctx); 25112dfcca9fSRichard Henderson 2512deee69a1SRichard Henderson form_gva(ctx, &vaddr, &ofs, a->b, a->x, 0, 0, a->sp, a->m, false); 25132dfcca9fSRichard Henderson 25142dfcca9fSRichard Henderson paddr = tcg_temp_new(); 2515ad75a51eSRichard Henderson gen_helper_lpa(paddr, tcg_env, vaddr); 25162dfcca9fSRichard Henderson 25172dfcca9fSRichard Henderson /* Note that physical address result overrides base modification. */ 2518deee69a1SRichard Henderson if (a->m) { 2519deee69a1SRichard Henderson save_gpr(ctx, a->b, ofs); 25202dfcca9fSRichard Henderson } 2521deee69a1SRichard Henderson save_gpr(ctx, a->t, paddr); 25222dfcca9fSRichard Henderson 252331234768SRichard Henderson return nullify_end(ctx); 2524deee69a1SRichard Henderson #endif 25252dfcca9fSRichard Henderson } 252643a97b81SRichard Henderson 2527deee69a1SRichard Henderson static bool trans_lci(DisasContext *ctx, arg_lci *a) 252843a97b81SRichard Henderson { 252943a97b81SRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 253043a97b81SRichard Henderson 253143a97b81SRichard Henderson /* The Coherence Index is an implementation-defined function of the 253243a97b81SRichard Henderson physical address. Two addresses with the same CI have a coherent 253343a97b81SRichard Henderson view of the cache. Our implementation is to return 0 for all, 253443a97b81SRichard Henderson since the entire address space is coherent. */ 253529dd6f64SRichard Henderson save_gpr(ctx, a->t, tcg_constant_reg(0)); 253643a97b81SRichard Henderson 253731234768SRichard Henderson cond_free(&ctx->null_cond); 253831234768SRichard Henderson return true; 253943a97b81SRichard Henderson } 254098a9cb79SRichard Henderson 25410c982a28SRichard Henderson static bool trans_add(DisasContext *ctx, arg_rrr_cf_sh *a) 2542b2167459SRichard Henderson { 25430c982a28SRichard Henderson return do_add_reg(ctx, a, false, false, false, false); 2544b2167459SRichard Henderson } 2545b2167459SRichard Henderson 25460c982a28SRichard Henderson static bool trans_add_l(DisasContext *ctx, arg_rrr_cf_sh *a) 2547b2167459SRichard Henderson { 25480c982a28SRichard Henderson return do_add_reg(ctx, a, true, false, false, false); 2549b2167459SRichard Henderson } 2550b2167459SRichard Henderson 25510c982a28SRichard Henderson static bool trans_add_tsv(DisasContext *ctx, arg_rrr_cf_sh *a) 2552b2167459SRichard Henderson { 25530c982a28SRichard Henderson return do_add_reg(ctx, a, false, true, false, false); 2554b2167459SRichard Henderson } 2555b2167459SRichard Henderson 25560c982a28SRichard Henderson static bool trans_add_c(DisasContext *ctx, arg_rrr_cf_sh *a) 2557b2167459SRichard Henderson { 25580c982a28SRichard Henderson return do_add_reg(ctx, a, false, false, false, true); 25590c982a28SRichard Henderson } 2560b2167459SRichard Henderson 25610c982a28SRichard Henderson static bool trans_add_c_tsv(DisasContext *ctx, arg_rrr_cf_sh *a) 25620c982a28SRichard Henderson { 25630c982a28SRichard Henderson return do_add_reg(ctx, a, false, true, false, true); 25640c982a28SRichard Henderson } 25650c982a28SRichard Henderson 25660c982a28SRichard Henderson static bool trans_sub(DisasContext *ctx, arg_rrr_cf *a) 25670c982a28SRichard Henderson { 25680c982a28SRichard Henderson return do_sub_reg(ctx, a, false, false, false); 25690c982a28SRichard Henderson } 25700c982a28SRichard Henderson 25710c982a28SRichard Henderson static bool trans_sub_tsv(DisasContext *ctx, arg_rrr_cf *a) 25720c982a28SRichard Henderson { 25730c982a28SRichard Henderson return do_sub_reg(ctx, a, true, false, false); 25740c982a28SRichard Henderson } 25750c982a28SRichard Henderson 25760c982a28SRichard Henderson static bool trans_sub_tc(DisasContext *ctx, arg_rrr_cf *a) 25770c982a28SRichard Henderson { 25780c982a28SRichard Henderson return do_sub_reg(ctx, a, false, false, true); 25790c982a28SRichard Henderson } 25800c982a28SRichard Henderson 25810c982a28SRichard Henderson static bool trans_sub_tsv_tc(DisasContext *ctx, arg_rrr_cf *a) 25820c982a28SRichard Henderson { 25830c982a28SRichard Henderson return do_sub_reg(ctx, a, true, false, true); 25840c982a28SRichard Henderson } 25850c982a28SRichard Henderson 25860c982a28SRichard Henderson static bool trans_sub_b(DisasContext *ctx, arg_rrr_cf *a) 25870c982a28SRichard Henderson { 25880c982a28SRichard Henderson return do_sub_reg(ctx, a, false, true, false); 25890c982a28SRichard Henderson } 25900c982a28SRichard Henderson 25910c982a28SRichard Henderson static bool trans_sub_b_tsv(DisasContext *ctx, arg_rrr_cf *a) 25920c982a28SRichard Henderson { 25930c982a28SRichard Henderson return do_sub_reg(ctx, a, true, true, false); 25940c982a28SRichard Henderson } 25950c982a28SRichard Henderson 25960c982a28SRichard Henderson static bool trans_andcm(DisasContext *ctx, arg_rrr_cf *a) 25970c982a28SRichard Henderson { 25980c982a28SRichard Henderson return do_log_reg(ctx, a, tcg_gen_andc_reg); 25990c982a28SRichard Henderson } 26000c982a28SRichard Henderson 26010c982a28SRichard Henderson static bool trans_and(DisasContext *ctx, arg_rrr_cf *a) 26020c982a28SRichard Henderson { 26030c982a28SRichard Henderson return do_log_reg(ctx, a, tcg_gen_and_reg); 26040c982a28SRichard Henderson } 26050c982a28SRichard Henderson 26060c982a28SRichard Henderson static bool trans_or(DisasContext *ctx, arg_rrr_cf *a) 26070c982a28SRichard Henderson { 26080c982a28SRichard Henderson if (a->cf == 0) { 26090c982a28SRichard Henderson unsigned r2 = a->r2; 26100c982a28SRichard Henderson unsigned r1 = a->r1; 26110c982a28SRichard Henderson unsigned rt = a->t; 26120c982a28SRichard Henderson 26137aee8189SRichard Henderson if (rt == 0) { /* NOP */ 26147aee8189SRichard Henderson cond_free(&ctx->null_cond); 26157aee8189SRichard Henderson return true; 26167aee8189SRichard Henderson } 26177aee8189SRichard Henderson if (r2 == 0) { /* COPY */ 2618b2167459SRichard Henderson if (r1 == 0) { 2619eaa3783bSRichard Henderson TCGv_reg dest = dest_gpr(ctx, rt); 2620eaa3783bSRichard Henderson tcg_gen_movi_reg(dest, 0); 2621b2167459SRichard Henderson save_gpr(ctx, rt, dest); 2622b2167459SRichard Henderson } else { 2623b2167459SRichard Henderson save_gpr(ctx, rt, cpu_gr[r1]); 2624b2167459SRichard Henderson } 2625b2167459SRichard Henderson cond_free(&ctx->null_cond); 262631234768SRichard Henderson return true; 2627b2167459SRichard Henderson } 26287aee8189SRichard Henderson #ifndef CONFIG_USER_ONLY 26297aee8189SRichard Henderson /* These are QEMU extensions and are nops in the real architecture: 26307aee8189SRichard Henderson * 26317aee8189SRichard Henderson * or %r10,%r10,%r10 -- idle loop; wait for interrupt 26327aee8189SRichard Henderson * or %r31,%r31,%r31 -- death loop; offline cpu 26337aee8189SRichard Henderson * currently implemented as idle. 26347aee8189SRichard Henderson */ 26357aee8189SRichard Henderson if ((rt == 10 || rt == 31) && r1 == rt && r2 == rt) { /* PAUSE */ 26367aee8189SRichard Henderson /* No need to check for supervisor, as userland can only pause 26377aee8189SRichard Henderson until the next timer interrupt. */ 26387aee8189SRichard Henderson nullify_over(ctx); 26397aee8189SRichard Henderson 26407aee8189SRichard Henderson /* Advance the instruction queue. */ 26417aee8189SRichard Henderson copy_iaoq_entry(cpu_iaoq_f, ctx->iaoq_b, cpu_iaoq_b); 26427aee8189SRichard Henderson copy_iaoq_entry(cpu_iaoq_b, ctx->iaoq_n, ctx->iaoq_n_var); 26437aee8189SRichard Henderson nullify_set(ctx, 0); 26447aee8189SRichard Henderson 26457aee8189SRichard Henderson /* Tell the qemu main loop to halt until this cpu has work. */ 2646ad75a51eSRichard Henderson tcg_gen_st_i32(tcg_constant_i32(1), tcg_env, 264729dd6f64SRichard Henderson offsetof(CPUState, halted) - offsetof(HPPACPU, env)); 26487aee8189SRichard Henderson gen_excp_1(EXCP_HALTED); 26497aee8189SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 26507aee8189SRichard Henderson 26517aee8189SRichard Henderson return nullify_end(ctx); 26527aee8189SRichard Henderson } 26537aee8189SRichard Henderson #endif 26547aee8189SRichard Henderson } 26550c982a28SRichard Henderson return do_log_reg(ctx, a, tcg_gen_or_reg); 26567aee8189SRichard Henderson } 2657b2167459SRichard Henderson 26580c982a28SRichard Henderson static bool trans_xor(DisasContext *ctx, arg_rrr_cf *a) 2659b2167459SRichard Henderson { 26600c982a28SRichard Henderson return do_log_reg(ctx, a, tcg_gen_xor_reg); 26610c982a28SRichard Henderson } 26620c982a28SRichard Henderson 26630c982a28SRichard Henderson static bool trans_cmpclr(DisasContext *ctx, arg_rrr_cf *a) 26640c982a28SRichard Henderson { 2665eaa3783bSRichard Henderson TCGv_reg tcg_r1, tcg_r2; 2666b2167459SRichard Henderson 26670c982a28SRichard Henderson if (a->cf) { 2668b2167459SRichard Henderson nullify_over(ctx); 2669b2167459SRichard Henderson } 26700c982a28SRichard Henderson tcg_r1 = load_gpr(ctx, a->r1); 26710c982a28SRichard Henderson tcg_r2 = load_gpr(ctx, a->r2); 26720c982a28SRichard Henderson do_cmpclr(ctx, a->t, tcg_r1, tcg_r2, a->cf); 267331234768SRichard Henderson return nullify_end(ctx); 2674b2167459SRichard Henderson } 2675b2167459SRichard Henderson 26760c982a28SRichard Henderson static bool trans_uxor(DisasContext *ctx, arg_rrr_cf *a) 2677b2167459SRichard Henderson { 2678eaa3783bSRichard Henderson TCGv_reg tcg_r1, tcg_r2; 2679b2167459SRichard Henderson 26800c982a28SRichard Henderson if (a->cf) { 2681b2167459SRichard Henderson nullify_over(ctx); 2682b2167459SRichard Henderson } 26830c982a28SRichard Henderson tcg_r1 = load_gpr(ctx, a->r1); 26840c982a28SRichard Henderson tcg_r2 = load_gpr(ctx, a->r2); 26850c982a28SRichard Henderson do_unit(ctx, a->t, tcg_r1, tcg_r2, a->cf, false, tcg_gen_xor_reg); 268631234768SRichard Henderson return nullify_end(ctx); 2687b2167459SRichard Henderson } 2688b2167459SRichard Henderson 26890c982a28SRichard Henderson static bool do_uaddcm(DisasContext *ctx, arg_rrr_cf *a, bool is_tc) 2690b2167459SRichard Henderson { 2691eaa3783bSRichard Henderson TCGv_reg tcg_r1, tcg_r2, tmp; 2692b2167459SRichard Henderson 26930c982a28SRichard Henderson if (a->cf) { 2694b2167459SRichard Henderson nullify_over(ctx); 2695b2167459SRichard Henderson } 26960c982a28SRichard Henderson tcg_r1 = load_gpr(ctx, a->r1); 26970c982a28SRichard Henderson tcg_r2 = load_gpr(ctx, a->r2); 2698e12c6309SRichard Henderson tmp = tcg_temp_new(); 2699eaa3783bSRichard Henderson tcg_gen_not_reg(tmp, tcg_r2); 27000c982a28SRichard Henderson do_unit(ctx, a->t, tcg_r1, tmp, a->cf, is_tc, tcg_gen_add_reg); 270131234768SRichard Henderson return nullify_end(ctx); 2702b2167459SRichard Henderson } 2703b2167459SRichard Henderson 27040c982a28SRichard Henderson static bool trans_uaddcm(DisasContext *ctx, arg_rrr_cf *a) 2705b2167459SRichard Henderson { 27060c982a28SRichard Henderson return do_uaddcm(ctx, a, false); 27070c982a28SRichard Henderson } 27080c982a28SRichard Henderson 27090c982a28SRichard Henderson static bool trans_uaddcm_tc(DisasContext *ctx, arg_rrr_cf *a) 27100c982a28SRichard Henderson { 27110c982a28SRichard Henderson return do_uaddcm(ctx, a, true); 27120c982a28SRichard Henderson } 27130c982a28SRichard Henderson 27140c982a28SRichard Henderson static bool do_dcor(DisasContext *ctx, arg_rr_cf *a, bool is_i) 27150c982a28SRichard Henderson { 2716eaa3783bSRichard Henderson TCGv_reg tmp; 2717b2167459SRichard Henderson 2718b2167459SRichard Henderson nullify_over(ctx); 2719b2167459SRichard Henderson 2720e12c6309SRichard Henderson tmp = tcg_temp_new(); 2721eaa3783bSRichard Henderson tcg_gen_shri_reg(tmp, cpu_psw_cb, 3); 2722b2167459SRichard Henderson if (!is_i) { 2723eaa3783bSRichard Henderson tcg_gen_not_reg(tmp, tmp); 2724b2167459SRichard Henderson } 2725eaa3783bSRichard Henderson tcg_gen_andi_reg(tmp, tmp, 0x11111111); 2726eaa3783bSRichard Henderson tcg_gen_muli_reg(tmp, tmp, 6); 272760e29463SSven Schnelle do_unit(ctx, a->t, load_gpr(ctx, a->r), tmp, a->cf, false, 2728eaa3783bSRichard Henderson is_i ? tcg_gen_add_reg : tcg_gen_sub_reg); 272931234768SRichard Henderson return nullify_end(ctx); 2730b2167459SRichard Henderson } 2731b2167459SRichard Henderson 27320c982a28SRichard Henderson static bool trans_dcor(DisasContext *ctx, arg_rr_cf *a) 2733b2167459SRichard Henderson { 27340c982a28SRichard Henderson return do_dcor(ctx, a, false); 27350c982a28SRichard Henderson } 27360c982a28SRichard Henderson 27370c982a28SRichard Henderson static bool trans_dcor_i(DisasContext *ctx, arg_rr_cf *a) 27380c982a28SRichard Henderson { 27390c982a28SRichard Henderson return do_dcor(ctx, a, true); 27400c982a28SRichard Henderson } 27410c982a28SRichard Henderson 27420c982a28SRichard Henderson static bool trans_ds(DisasContext *ctx, arg_rrr_cf *a) 27430c982a28SRichard Henderson { 2744eaa3783bSRichard Henderson TCGv_reg dest, add1, add2, addc, zero, in1, in2; 274572ca8753SRichard Henderson TCGv_reg cout; 2746b2167459SRichard Henderson 2747b2167459SRichard Henderson nullify_over(ctx); 2748b2167459SRichard Henderson 27490c982a28SRichard Henderson in1 = load_gpr(ctx, a->r1); 27500c982a28SRichard Henderson in2 = load_gpr(ctx, a->r2); 2751b2167459SRichard Henderson 2752b2167459SRichard Henderson add1 = tcg_temp_new(); 2753b2167459SRichard Henderson add2 = tcg_temp_new(); 2754b2167459SRichard Henderson addc = tcg_temp_new(); 2755b2167459SRichard Henderson dest = tcg_temp_new(); 275629dd6f64SRichard Henderson zero = tcg_constant_reg(0); 2757b2167459SRichard Henderson 2758b2167459SRichard Henderson /* Form R1 << 1 | PSW[CB]{8}. */ 2759eaa3783bSRichard Henderson tcg_gen_add_reg(add1, in1, in1); 276072ca8753SRichard Henderson tcg_gen_add_reg(add1, add1, get_psw_carry(ctx, false)); 2761b2167459SRichard Henderson 276272ca8753SRichard Henderson /* 276372ca8753SRichard Henderson * Add or subtract R2, depending on PSW[V]. Proper computation of 276472ca8753SRichard Henderson * carry requires that we subtract via + ~R2 + 1, as described in 276572ca8753SRichard Henderson * the manual. By extracting and masking V, we can produce the 276672ca8753SRichard Henderson * proper inputs to the addition without movcond. 276772ca8753SRichard Henderson */ 276872ca8753SRichard Henderson tcg_gen_sextract_reg(addc, cpu_psw_v, 31, 1); 2769eaa3783bSRichard Henderson tcg_gen_xor_reg(add2, in2, addc); 2770eaa3783bSRichard Henderson tcg_gen_andi_reg(addc, addc, 1); 277172ca8753SRichard Henderson 277272ca8753SRichard Henderson tcg_gen_add2_reg(dest, cpu_psw_cb_msb, add1, zero, add2, zero); 277372ca8753SRichard Henderson tcg_gen_add2_reg(dest, cpu_psw_cb_msb, dest, cpu_psw_cb_msb, addc, zero); 2774b2167459SRichard Henderson 2775b2167459SRichard Henderson /* Write back the result register. */ 27760c982a28SRichard Henderson save_gpr(ctx, a->t, dest); 2777b2167459SRichard Henderson 2778b2167459SRichard Henderson /* Write back PSW[CB]. */ 2779eaa3783bSRichard Henderson tcg_gen_xor_reg(cpu_psw_cb, add1, add2); 2780eaa3783bSRichard Henderson tcg_gen_xor_reg(cpu_psw_cb, cpu_psw_cb, dest); 2781b2167459SRichard Henderson 2782b2167459SRichard Henderson /* Write back PSW[V] for the division step. */ 278372ca8753SRichard Henderson cout = get_psw_carry(ctx, false); 278472ca8753SRichard Henderson tcg_gen_neg_reg(cpu_psw_v, cout); 2785eaa3783bSRichard Henderson tcg_gen_xor_reg(cpu_psw_v, cpu_psw_v, in2); 2786b2167459SRichard Henderson 2787b2167459SRichard Henderson /* Install the new nullification. */ 27880c982a28SRichard Henderson if (a->cf) { 2789eaa3783bSRichard Henderson TCGv_reg sv = NULL; 2790b47a4a02SSven Schnelle if (cond_need_sv(a->cf >> 1)) { 2791b2167459SRichard Henderson /* ??? The lshift is supposed to contribute to overflow. */ 2792b2167459SRichard Henderson sv = do_add_sv(ctx, dest, add1, add2); 2793b2167459SRichard Henderson } 279472ca8753SRichard Henderson ctx->null_cond = do_cond(a->cf, dest, cout, sv); 2795b2167459SRichard Henderson } 2796b2167459SRichard Henderson 279731234768SRichard Henderson return nullify_end(ctx); 2798b2167459SRichard Henderson } 2799b2167459SRichard Henderson 28000588e061SRichard Henderson static bool trans_addi(DisasContext *ctx, arg_rri_cf *a) 2801b2167459SRichard Henderson { 28020588e061SRichard Henderson return do_add_imm(ctx, a, false, false); 28030588e061SRichard Henderson } 28040588e061SRichard Henderson 28050588e061SRichard Henderson static bool trans_addi_tsv(DisasContext *ctx, arg_rri_cf *a) 28060588e061SRichard Henderson { 28070588e061SRichard Henderson return do_add_imm(ctx, a, true, false); 28080588e061SRichard Henderson } 28090588e061SRichard Henderson 28100588e061SRichard Henderson static bool trans_addi_tc(DisasContext *ctx, arg_rri_cf *a) 28110588e061SRichard Henderson { 28120588e061SRichard Henderson return do_add_imm(ctx, a, false, true); 28130588e061SRichard Henderson } 28140588e061SRichard Henderson 28150588e061SRichard Henderson static bool trans_addi_tc_tsv(DisasContext *ctx, arg_rri_cf *a) 28160588e061SRichard Henderson { 28170588e061SRichard Henderson return do_add_imm(ctx, a, true, true); 28180588e061SRichard Henderson } 28190588e061SRichard Henderson 28200588e061SRichard Henderson static bool trans_subi(DisasContext *ctx, arg_rri_cf *a) 28210588e061SRichard Henderson { 28220588e061SRichard Henderson return do_sub_imm(ctx, a, false); 28230588e061SRichard Henderson } 28240588e061SRichard Henderson 28250588e061SRichard Henderson static bool trans_subi_tsv(DisasContext *ctx, arg_rri_cf *a) 28260588e061SRichard Henderson { 28270588e061SRichard Henderson return do_sub_imm(ctx, a, true); 28280588e061SRichard Henderson } 28290588e061SRichard Henderson 28300588e061SRichard Henderson static bool trans_cmpiclr(DisasContext *ctx, arg_rri_cf *a) 28310588e061SRichard Henderson { 2832eaa3783bSRichard Henderson TCGv_reg tcg_im, tcg_r2; 2833b2167459SRichard Henderson 28340588e061SRichard Henderson if (a->cf) { 2835b2167459SRichard Henderson nullify_over(ctx); 2836b2167459SRichard Henderson } 2837b2167459SRichard Henderson 2838d4e58033SRichard Henderson tcg_im = tcg_constant_reg(a->i); 28390588e061SRichard Henderson tcg_r2 = load_gpr(ctx, a->r); 28400588e061SRichard Henderson do_cmpclr(ctx, a->t, tcg_im, tcg_r2, a->cf); 2841b2167459SRichard Henderson 284231234768SRichard Henderson return nullify_end(ctx); 2843b2167459SRichard Henderson } 2844b2167459SRichard Henderson 28451cd012a5SRichard Henderson static bool trans_ld(DisasContext *ctx, arg_ldst *a) 284696d6407fSRichard Henderson { 28470786a3b6SHelge Deller if (unlikely(TARGET_REGISTER_BITS == 32 && a->size > MO_32)) { 28480786a3b6SHelge Deller return gen_illegal(ctx); 28490786a3b6SHelge Deller } else { 28501cd012a5SRichard Henderson return do_load(ctx, a->t, a->b, a->x, a->scale ? a->size : 0, 28511cd012a5SRichard Henderson a->disp, a->sp, a->m, a->size | MO_TE); 285296d6407fSRichard Henderson } 28530786a3b6SHelge Deller } 285496d6407fSRichard Henderson 28551cd012a5SRichard Henderson static bool trans_st(DisasContext *ctx, arg_ldst *a) 285696d6407fSRichard Henderson { 28571cd012a5SRichard Henderson assert(a->x == 0 && a->scale == 0); 28580786a3b6SHelge Deller if (unlikely(TARGET_REGISTER_BITS == 32 && a->size > MO_32)) { 28590786a3b6SHelge Deller return gen_illegal(ctx); 28600786a3b6SHelge Deller } else { 28611cd012a5SRichard Henderson return do_store(ctx, a->t, a->b, a->disp, a->sp, a->m, a->size | MO_TE); 286296d6407fSRichard Henderson } 28630786a3b6SHelge Deller } 286496d6407fSRichard Henderson 28651cd012a5SRichard Henderson static bool trans_ldc(DisasContext *ctx, arg_ldst *a) 286696d6407fSRichard Henderson { 2867b1af755cSRichard Henderson MemOp mop = MO_TE | MO_ALIGN | a->size; 286886f8d05fSRichard Henderson TCGv_reg zero, dest, ofs; 286986f8d05fSRichard Henderson TCGv_tl addr; 287096d6407fSRichard Henderson 287196d6407fSRichard Henderson nullify_over(ctx); 287296d6407fSRichard Henderson 28731cd012a5SRichard Henderson if (a->m) { 287486f8d05fSRichard Henderson /* Base register modification. Make sure if RT == RB, 287586f8d05fSRichard Henderson we see the result of the load. */ 2876e12c6309SRichard Henderson dest = tcg_temp_new(); 287796d6407fSRichard Henderson } else { 28781cd012a5SRichard Henderson dest = dest_gpr(ctx, a->t); 287996d6407fSRichard Henderson } 288096d6407fSRichard Henderson 28811cd012a5SRichard Henderson form_gva(ctx, &addr, &ofs, a->b, a->x, a->scale ? a->size : 0, 28821cd012a5SRichard Henderson a->disp, a->sp, a->m, ctx->mmu_idx == MMU_PHYS_IDX); 2883b1af755cSRichard Henderson 2884b1af755cSRichard Henderson /* 2885b1af755cSRichard Henderson * For hppa1.1, LDCW is undefined unless aligned mod 16. 2886b1af755cSRichard Henderson * However actual hardware succeeds with aligned mod 4. 2887b1af755cSRichard Henderson * Detect this case and log a GUEST_ERROR. 2888b1af755cSRichard Henderson * 2889b1af755cSRichard Henderson * TODO: HPPA64 relaxes the over-alignment requirement 2890b1af755cSRichard Henderson * with the ,co completer. 2891b1af755cSRichard Henderson */ 2892b1af755cSRichard Henderson gen_helper_ldc_check(addr); 2893b1af755cSRichard Henderson 289429dd6f64SRichard Henderson zero = tcg_constant_reg(0); 289586f8d05fSRichard Henderson tcg_gen_atomic_xchg_reg(dest, addr, zero, ctx->mmu_idx, mop); 2896b1af755cSRichard Henderson 28971cd012a5SRichard Henderson if (a->m) { 28981cd012a5SRichard Henderson save_gpr(ctx, a->b, ofs); 289996d6407fSRichard Henderson } 29001cd012a5SRichard Henderson save_gpr(ctx, a->t, dest); 290196d6407fSRichard Henderson 290231234768SRichard Henderson return nullify_end(ctx); 290396d6407fSRichard Henderson } 290496d6407fSRichard Henderson 29051cd012a5SRichard Henderson static bool trans_stby(DisasContext *ctx, arg_stby *a) 290696d6407fSRichard Henderson { 290786f8d05fSRichard Henderson TCGv_reg ofs, val; 290886f8d05fSRichard Henderson TCGv_tl addr; 290996d6407fSRichard Henderson 291096d6407fSRichard Henderson nullify_over(ctx); 291196d6407fSRichard Henderson 29121cd012a5SRichard Henderson form_gva(ctx, &addr, &ofs, a->b, 0, 0, a->disp, a->sp, a->m, 291386f8d05fSRichard Henderson ctx->mmu_idx == MMU_PHYS_IDX); 29141cd012a5SRichard Henderson val = load_gpr(ctx, a->r); 29151cd012a5SRichard Henderson if (a->a) { 2916f9f46db4SEmilio G. Cota if (tb_cflags(ctx->base.tb) & CF_PARALLEL) { 2917ad75a51eSRichard Henderson gen_helper_stby_e_parallel(tcg_env, addr, val); 2918f9f46db4SEmilio G. Cota } else { 2919ad75a51eSRichard Henderson gen_helper_stby_e(tcg_env, addr, val); 2920f9f46db4SEmilio G. Cota } 2921f9f46db4SEmilio G. Cota } else { 2922f9f46db4SEmilio G. Cota if (tb_cflags(ctx->base.tb) & CF_PARALLEL) { 2923ad75a51eSRichard Henderson gen_helper_stby_b_parallel(tcg_env, addr, val); 292496d6407fSRichard Henderson } else { 2925ad75a51eSRichard Henderson gen_helper_stby_b(tcg_env, addr, val); 292696d6407fSRichard Henderson } 2927f9f46db4SEmilio G. Cota } 29281cd012a5SRichard Henderson if (a->m) { 292986f8d05fSRichard Henderson tcg_gen_andi_reg(ofs, ofs, ~3); 29301cd012a5SRichard Henderson save_gpr(ctx, a->b, ofs); 293196d6407fSRichard Henderson } 293296d6407fSRichard Henderson 293331234768SRichard Henderson return nullify_end(ctx); 293496d6407fSRichard Henderson } 293596d6407fSRichard Henderson 29361cd012a5SRichard Henderson static bool trans_lda(DisasContext *ctx, arg_ldst *a) 2937d0a851ccSRichard Henderson { 2938d0a851ccSRichard Henderson int hold_mmu_idx = ctx->mmu_idx; 2939d0a851ccSRichard Henderson 2940d0a851ccSRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 2941d0a851ccSRichard Henderson ctx->mmu_idx = MMU_PHYS_IDX; 29421cd012a5SRichard Henderson trans_ld(ctx, a); 2943d0a851ccSRichard Henderson ctx->mmu_idx = hold_mmu_idx; 294431234768SRichard Henderson return true; 2945d0a851ccSRichard Henderson } 2946d0a851ccSRichard Henderson 29471cd012a5SRichard Henderson static bool trans_sta(DisasContext *ctx, arg_ldst *a) 2948d0a851ccSRichard Henderson { 2949d0a851ccSRichard Henderson int hold_mmu_idx = ctx->mmu_idx; 2950d0a851ccSRichard Henderson 2951d0a851ccSRichard Henderson CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 2952d0a851ccSRichard Henderson ctx->mmu_idx = MMU_PHYS_IDX; 29531cd012a5SRichard Henderson trans_st(ctx, a); 2954d0a851ccSRichard Henderson ctx->mmu_idx = hold_mmu_idx; 295531234768SRichard Henderson return true; 2956d0a851ccSRichard Henderson } 295795412a61SRichard Henderson 29580588e061SRichard Henderson static bool trans_ldil(DisasContext *ctx, arg_ldil *a) 2959b2167459SRichard Henderson { 29600588e061SRichard Henderson TCGv_reg tcg_rt = dest_gpr(ctx, a->t); 2961b2167459SRichard Henderson 29620588e061SRichard Henderson tcg_gen_movi_reg(tcg_rt, a->i); 29630588e061SRichard Henderson save_gpr(ctx, a->t, tcg_rt); 2964b2167459SRichard Henderson cond_free(&ctx->null_cond); 296531234768SRichard Henderson return true; 2966b2167459SRichard Henderson } 2967b2167459SRichard Henderson 29680588e061SRichard Henderson static bool trans_addil(DisasContext *ctx, arg_addil *a) 2969b2167459SRichard Henderson { 29700588e061SRichard Henderson TCGv_reg tcg_rt = load_gpr(ctx, a->r); 2971eaa3783bSRichard Henderson TCGv_reg tcg_r1 = dest_gpr(ctx, 1); 2972b2167459SRichard Henderson 29730588e061SRichard Henderson tcg_gen_addi_reg(tcg_r1, tcg_rt, a->i); 2974b2167459SRichard Henderson save_gpr(ctx, 1, tcg_r1); 2975b2167459SRichard Henderson cond_free(&ctx->null_cond); 297631234768SRichard Henderson return true; 2977b2167459SRichard Henderson } 2978b2167459SRichard Henderson 29790588e061SRichard Henderson static bool trans_ldo(DisasContext *ctx, arg_ldo *a) 2980b2167459SRichard Henderson { 29810588e061SRichard Henderson TCGv_reg tcg_rt = dest_gpr(ctx, a->t); 2982b2167459SRichard Henderson 2983b2167459SRichard Henderson /* Special case rb == 0, for the LDI pseudo-op. 2984b2167459SRichard Henderson The COPY pseudo-op is handled for free within tcg_gen_addi_tl. */ 29850588e061SRichard Henderson if (a->b == 0) { 29860588e061SRichard Henderson tcg_gen_movi_reg(tcg_rt, a->i); 2987b2167459SRichard Henderson } else { 29880588e061SRichard Henderson tcg_gen_addi_reg(tcg_rt, cpu_gr[a->b], a->i); 2989b2167459SRichard Henderson } 29900588e061SRichard Henderson save_gpr(ctx, a->t, tcg_rt); 2991b2167459SRichard Henderson cond_free(&ctx->null_cond); 299231234768SRichard Henderson return true; 2993b2167459SRichard Henderson } 2994b2167459SRichard Henderson 299501afb7beSRichard Henderson static bool do_cmpb(DisasContext *ctx, unsigned r, TCGv_reg in1, 299601afb7beSRichard Henderson unsigned c, unsigned f, unsigned n, int disp) 299798cd9ca7SRichard Henderson { 299801afb7beSRichard Henderson TCGv_reg dest, in2, sv; 299998cd9ca7SRichard Henderson DisasCond cond; 300098cd9ca7SRichard Henderson 300198cd9ca7SRichard Henderson in2 = load_gpr(ctx, r); 3002e12c6309SRichard Henderson dest = tcg_temp_new(); 300398cd9ca7SRichard Henderson 3004eaa3783bSRichard Henderson tcg_gen_sub_reg(dest, in1, in2); 300598cd9ca7SRichard Henderson 3006f764718dSRichard Henderson sv = NULL; 3007b47a4a02SSven Schnelle if (cond_need_sv(c)) { 300898cd9ca7SRichard Henderson sv = do_sub_sv(ctx, dest, in1, in2); 300998cd9ca7SRichard Henderson } 301098cd9ca7SRichard Henderson 301101afb7beSRichard Henderson cond = do_sub_cond(c * 2 + f, dest, in1, in2, sv); 301201afb7beSRichard Henderson return do_cbranch(ctx, disp, n, &cond); 301398cd9ca7SRichard Henderson } 301498cd9ca7SRichard Henderson 301501afb7beSRichard Henderson static bool trans_cmpb(DisasContext *ctx, arg_cmpb *a) 301698cd9ca7SRichard Henderson { 301701afb7beSRichard Henderson nullify_over(ctx); 301801afb7beSRichard Henderson return do_cmpb(ctx, a->r2, load_gpr(ctx, a->r1), a->c, a->f, a->n, a->disp); 301901afb7beSRichard Henderson } 302001afb7beSRichard Henderson 302101afb7beSRichard Henderson static bool trans_cmpbi(DisasContext *ctx, arg_cmpbi *a) 302201afb7beSRichard Henderson { 302301afb7beSRichard Henderson nullify_over(ctx); 3024d4e58033SRichard Henderson return do_cmpb(ctx, a->r, tcg_constant_reg(a->i), a->c, a->f, a->n, a->disp); 302501afb7beSRichard Henderson } 302601afb7beSRichard Henderson 302701afb7beSRichard Henderson static bool do_addb(DisasContext *ctx, unsigned r, TCGv_reg in1, 302801afb7beSRichard Henderson unsigned c, unsigned f, unsigned n, int disp) 302901afb7beSRichard Henderson { 3030bdcccc17SRichard Henderson TCGv_reg dest, in2, sv, cb_cond; 303198cd9ca7SRichard Henderson DisasCond cond; 3032bdcccc17SRichard Henderson bool d = false; 303398cd9ca7SRichard Henderson 303498cd9ca7SRichard Henderson in2 = load_gpr(ctx, r); 303543675d20SSven Schnelle dest = tcg_temp_new(); 3036f764718dSRichard Henderson sv = NULL; 3037bdcccc17SRichard Henderson cb_cond = NULL; 303898cd9ca7SRichard Henderson 3039b47a4a02SSven Schnelle if (cond_need_cb(c)) { 3040bdcccc17SRichard Henderson TCGv_reg cb = tcg_temp_new(); 3041bdcccc17SRichard Henderson TCGv_reg cb_msb = tcg_temp_new(); 3042bdcccc17SRichard Henderson 3043eaa3783bSRichard Henderson tcg_gen_movi_reg(cb_msb, 0); 3044eaa3783bSRichard Henderson tcg_gen_add2_reg(dest, cb_msb, in1, cb_msb, in2, cb_msb); 3045bdcccc17SRichard Henderson tcg_gen_xor_reg(cb, in1, in2); 3046bdcccc17SRichard Henderson tcg_gen_xor_reg(cb, cb, dest); 3047bdcccc17SRichard Henderson cb_cond = get_carry(ctx, d, cb, cb_msb); 3048b47a4a02SSven Schnelle } else { 3049eaa3783bSRichard Henderson tcg_gen_add_reg(dest, in1, in2); 3050b47a4a02SSven Schnelle } 3051b47a4a02SSven Schnelle if (cond_need_sv(c)) { 305298cd9ca7SRichard Henderson sv = do_add_sv(ctx, dest, in1, in2); 305398cd9ca7SRichard Henderson } 305498cd9ca7SRichard Henderson 3055bdcccc17SRichard Henderson cond = do_cond(c * 2 + f, dest, cb_cond, sv); 305643675d20SSven Schnelle save_gpr(ctx, r, dest); 305701afb7beSRichard Henderson return do_cbranch(ctx, disp, n, &cond); 305898cd9ca7SRichard Henderson } 305998cd9ca7SRichard Henderson 306001afb7beSRichard Henderson static bool trans_addb(DisasContext *ctx, arg_addb *a) 306198cd9ca7SRichard Henderson { 306201afb7beSRichard Henderson nullify_over(ctx); 306301afb7beSRichard Henderson return do_addb(ctx, a->r2, load_gpr(ctx, a->r1), a->c, a->f, a->n, a->disp); 306401afb7beSRichard Henderson } 306501afb7beSRichard Henderson 306601afb7beSRichard Henderson static bool trans_addbi(DisasContext *ctx, arg_addbi *a) 306701afb7beSRichard Henderson { 306801afb7beSRichard Henderson nullify_over(ctx); 3069d4e58033SRichard Henderson return do_addb(ctx, a->r, tcg_constant_reg(a->i), a->c, a->f, a->n, a->disp); 307001afb7beSRichard Henderson } 307101afb7beSRichard Henderson 307201afb7beSRichard Henderson static bool trans_bb_sar(DisasContext *ctx, arg_bb_sar *a) 307301afb7beSRichard Henderson { 3074eaa3783bSRichard Henderson TCGv_reg tmp, tcg_r; 307598cd9ca7SRichard Henderson DisasCond cond; 3076*1e9ab9fbSRichard Henderson bool d = false; 307798cd9ca7SRichard Henderson 307898cd9ca7SRichard Henderson nullify_over(ctx); 307998cd9ca7SRichard Henderson 308098cd9ca7SRichard Henderson tmp = tcg_temp_new(); 308101afb7beSRichard Henderson tcg_r = load_gpr(ctx, a->r); 3082*1e9ab9fbSRichard Henderson if (cond_need_ext(ctx, d)) { 3083*1e9ab9fbSRichard Henderson /* Force shift into [32,63] */ 3084*1e9ab9fbSRichard Henderson tcg_gen_ori_reg(tmp, cpu_sar, 32); 3085*1e9ab9fbSRichard Henderson tcg_gen_shl_reg(tmp, tcg_r, tmp); 3086*1e9ab9fbSRichard Henderson } else { 3087eaa3783bSRichard Henderson tcg_gen_shl_reg(tmp, tcg_r, cpu_sar); 3088*1e9ab9fbSRichard Henderson } 308998cd9ca7SRichard Henderson 3090*1e9ab9fbSRichard Henderson cond = cond_make_0_tmp(a->c ? TCG_COND_GE : TCG_COND_LT, tmp); 309101afb7beSRichard Henderson return do_cbranch(ctx, a->disp, a->n, &cond); 309298cd9ca7SRichard Henderson } 309398cd9ca7SRichard Henderson 309401afb7beSRichard Henderson static bool trans_bb_imm(DisasContext *ctx, arg_bb_imm *a) 309598cd9ca7SRichard Henderson { 309601afb7beSRichard Henderson TCGv_reg tmp, tcg_r; 309701afb7beSRichard Henderson DisasCond cond; 3098*1e9ab9fbSRichard Henderson bool d = false; 3099*1e9ab9fbSRichard Henderson int p; 310001afb7beSRichard Henderson 310101afb7beSRichard Henderson nullify_over(ctx); 310201afb7beSRichard Henderson 310301afb7beSRichard Henderson tmp = tcg_temp_new(); 310401afb7beSRichard Henderson tcg_r = load_gpr(ctx, a->r); 3105*1e9ab9fbSRichard Henderson p = a->p | (cond_need_ext(ctx, d) ? 32 : 0); 3106*1e9ab9fbSRichard Henderson tcg_gen_shli_reg(tmp, tcg_r, p); 310701afb7beSRichard Henderson 310801afb7beSRichard Henderson cond = cond_make_0(a->c ? TCG_COND_GE : TCG_COND_LT, tmp); 310901afb7beSRichard Henderson return do_cbranch(ctx, a->disp, a->n, &cond); 311001afb7beSRichard Henderson } 311101afb7beSRichard Henderson 311201afb7beSRichard Henderson static bool trans_movb(DisasContext *ctx, arg_movb *a) 311301afb7beSRichard Henderson { 3114eaa3783bSRichard Henderson TCGv_reg dest; 311598cd9ca7SRichard Henderson DisasCond cond; 311698cd9ca7SRichard Henderson 311798cd9ca7SRichard Henderson nullify_over(ctx); 311898cd9ca7SRichard Henderson 311901afb7beSRichard Henderson dest = dest_gpr(ctx, a->r2); 312001afb7beSRichard Henderson if (a->r1 == 0) { 3121eaa3783bSRichard Henderson tcg_gen_movi_reg(dest, 0); 312298cd9ca7SRichard Henderson } else { 312301afb7beSRichard Henderson tcg_gen_mov_reg(dest, cpu_gr[a->r1]); 312498cd9ca7SRichard Henderson } 312598cd9ca7SRichard Henderson 312601afb7beSRichard Henderson cond = do_sed_cond(a->c, dest); 312701afb7beSRichard Henderson return do_cbranch(ctx, a->disp, a->n, &cond); 312801afb7beSRichard Henderson } 312901afb7beSRichard Henderson 313001afb7beSRichard Henderson static bool trans_movbi(DisasContext *ctx, arg_movbi *a) 313101afb7beSRichard Henderson { 313201afb7beSRichard Henderson TCGv_reg dest; 313301afb7beSRichard Henderson DisasCond cond; 313401afb7beSRichard Henderson 313501afb7beSRichard Henderson nullify_over(ctx); 313601afb7beSRichard Henderson 313701afb7beSRichard Henderson dest = dest_gpr(ctx, a->r); 313801afb7beSRichard Henderson tcg_gen_movi_reg(dest, a->i); 313901afb7beSRichard Henderson 314001afb7beSRichard Henderson cond = do_sed_cond(a->c, dest); 314101afb7beSRichard Henderson return do_cbranch(ctx, a->disp, a->n, &cond); 314298cd9ca7SRichard Henderson } 314398cd9ca7SRichard Henderson 314430878590SRichard Henderson static bool trans_shrpw_sar(DisasContext *ctx, arg_shrpw_sar *a) 31450b1347d2SRichard Henderson { 3146eaa3783bSRichard Henderson TCGv_reg dest; 31470b1347d2SRichard Henderson 314830878590SRichard Henderson if (a->c) { 31490b1347d2SRichard Henderson nullify_over(ctx); 31500b1347d2SRichard Henderson } 31510b1347d2SRichard Henderson 315230878590SRichard Henderson dest = dest_gpr(ctx, a->t); 315330878590SRichard Henderson if (a->r1 == 0) { 315430878590SRichard Henderson tcg_gen_ext32u_reg(dest, load_gpr(ctx, a->r2)); 3155eaa3783bSRichard Henderson tcg_gen_shr_reg(dest, dest, cpu_sar); 315630878590SRichard Henderson } else if (a->r1 == a->r2) { 31570b1347d2SRichard Henderson TCGv_i32 t32 = tcg_temp_new_i32(); 3158e1d635e8SRichard Henderson TCGv_i32 s32 = tcg_temp_new_i32(); 3159e1d635e8SRichard Henderson 316030878590SRichard Henderson tcg_gen_trunc_reg_i32(t32, load_gpr(ctx, a->r2)); 3161e1d635e8SRichard Henderson tcg_gen_trunc_reg_i32(s32, cpu_sar); 3162e1d635e8SRichard Henderson tcg_gen_rotr_i32(t32, t32, s32); 3163eaa3783bSRichard Henderson tcg_gen_extu_i32_reg(dest, t32); 31640b1347d2SRichard Henderson } else { 31650b1347d2SRichard Henderson TCGv_i64 t = tcg_temp_new_i64(); 31660b1347d2SRichard Henderson TCGv_i64 s = tcg_temp_new_i64(); 31670b1347d2SRichard Henderson 316830878590SRichard Henderson tcg_gen_concat_reg_i64(t, load_gpr(ctx, a->r2), load_gpr(ctx, a->r1)); 3169eaa3783bSRichard Henderson tcg_gen_extu_reg_i64(s, cpu_sar); 31700b1347d2SRichard Henderson tcg_gen_shr_i64(t, t, s); 3171eaa3783bSRichard Henderson tcg_gen_trunc_i64_reg(dest, t); 31720b1347d2SRichard Henderson } 317330878590SRichard Henderson save_gpr(ctx, a->t, dest); 31740b1347d2SRichard Henderson 31750b1347d2SRichard Henderson /* Install the new nullification. */ 31760b1347d2SRichard Henderson cond_free(&ctx->null_cond); 317730878590SRichard Henderson if (a->c) { 317830878590SRichard Henderson ctx->null_cond = do_sed_cond(a->c, dest); 31790b1347d2SRichard Henderson } 318031234768SRichard Henderson return nullify_end(ctx); 31810b1347d2SRichard Henderson } 31820b1347d2SRichard Henderson 318330878590SRichard Henderson static bool trans_shrpw_imm(DisasContext *ctx, arg_shrpw_imm *a) 31840b1347d2SRichard Henderson { 318530878590SRichard Henderson unsigned sa = 31 - a->cpos; 3186eaa3783bSRichard Henderson TCGv_reg dest, t2; 31870b1347d2SRichard Henderson 318830878590SRichard Henderson if (a->c) { 31890b1347d2SRichard Henderson nullify_over(ctx); 31900b1347d2SRichard Henderson } 31910b1347d2SRichard Henderson 319230878590SRichard Henderson dest = dest_gpr(ctx, a->t); 319330878590SRichard Henderson t2 = load_gpr(ctx, a->r2); 319405bfd4dbSRichard Henderson if (a->r1 == 0) { 319505bfd4dbSRichard Henderson tcg_gen_extract_reg(dest, t2, sa, 32 - sa); 319605bfd4dbSRichard Henderson } else if (TARGET_REGISTER_BITS == 32) { 319705bfd4dbSRichard Henderson tcg_gen_extract2_reg(dest, t2, cpu_gr[a->r1], sa); 319805bfd4dbSRichard Henderson } else if (a->r1 == a->r2) { 31990b1347d2SRichard Henderson TCGv_i32 t32 = tcg_temp_new_i32(); 3200eaa3783bSRichard Henderson tcg_gen_trunc_reg_i32(t32, t2); 32010b1347d2SRichard Henderson tcg_gen_rotri_i32(t32, t32, sa); 3202eaa3783bSRichard Henderson tcg_gen_extu_i32_reg(dest, t32); 32030b1347d2SRichard Henderson } else { 320405bfd4dbSRichard Henderson TCGv_i64 t64 = tcg_temp_new_i64(); 320505bfd4dbSRichard Henderson tcg_gen_concat_reg_i64(t64, t2, cpu_gr[a->r1]); 320605bfd4dbSRichard Henderson tcg_gen_shri_i64(t64, t64, sa); 320705bfd4dbSRichard Henderson tcg_gen_trunc_i64_reg(dest, t64); 32080b1347d2SRichard Henderson } 320930878590SRichard Henderson save_gpr(ctx, a->t, dest); 32100b1347d2SRichard Henderson 32110b1347d2SRichard Henderson /* Install the new nullification. */ 32120b1347d2SRichard Henderson cond_free(&ctx->null_cond); 321330878590SRichard Henderson if (a->c) { 321430878590SRichard Henderson ctx->null_cond = do_sed_cond(a->c, dest); 32150b1347d2SRichard Henderson } 321631234768SRichard Henderson return nullify_end(ctx); 32170b1347d2SRichard Henderson } 32180b1347d2SRichard Henderson 321930878590SRichard Henderson static bool trans_extrw_sar(DisasContext *ctx, arg_extrw_sar *a) 32200b1347d2SRichard Henderson { 322130878590SRichard Henderson unsigned len = 32 - a->clen; 3222eaa3783bSRichard Henderson TCGv_reg dest, src, tmp; 32230b1347d2SRichard Henderson 322430878590SRichard Henderson if (a->c) { 32250b1347d2SRichard Henderson nullify_over(ctx); 32260b1347d2SRichard Henderson } 32270b1347d2SRichard Henderson 322830878590SRichard Henderson dest = dest_gpr(ctx, a->t); 322930878590SRichard Henderson src = load_gpr(ctx, a->r); 32300b1347d2SRichard Henderson tmp = tcg_temp_new(); 32310b1347d2SRichard Henderson 32320b1347d2SRichard Henderson /* Recall that SAR is using big-endian bit numbering. */ 3233eaa3783bSRichard Henderson tcg_gen_xori_reg(tmp, cpu_sar, TARGET_REGISTER_BITS - 1); 323430878590SRichard Henderson if (a->se) { 3235eaa3783bSRichard Henderson tcg_gen_sar_reg(dest, src, tmp); 3236eaa3783bSRichard Henderson tcg_gen_sextract_reg(dest, dest, 0, len); 32370b1347d2SRichard Henderson } else { 3238eaa3783bSRichard Henderson tcg_gen_shr_reg(dest, src, tmp); 3239eaa3783bSRichard Henderson tcg_gen_extract_reg(dest, dest, 0, len); 32400b1347d2SRichard Henderson } 324130878590SRichard Henderson save_gpr(ctx, a->t, dest); 32420b1347d2SRichard Henderson 32430b1347d2SRichard Henderson /* Install the new nullification. */ 32440b1347d2SRichard Henderson cond_free(&ctx->null_cond); 324530878590SRichard Henderson if (a->c) { 324630878590SRichard Henderson ctx->null_cond = do_sed_cond(a->c, dest); 32470b1347d2SRichard Henderson } 324831234768SRichard Henderson return nullify_end(ctx); 32490b1347d2SRichard Henderson } 32500b1347d2SRichard Henderson 325130878590SRichard Henderson static bool trans_extrw_imm(DisasContext *ctx, arg_extrw_imm *a) 32520b1347d2SRichard Henderson { 325330878590SRichard Henderson unsigned len = 32 - a->clen; 325430878590SRichard Henderson unsigned cpos = 31 - a->pos; 3255eaa3783bSRichard Henderson TCGv_reg dest, src; 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 src = load_gpr(ctx, a->r); 326330878590SRichard Henderson if (a->se) { 3264eaa3783bSRichard Henderson tcg_gen_sextract_reg(dest, src, cpos, len); 32650b1347d2SRichard Henderson } else { 3266eaa3783bSRichard Henderson tcg_gen_extract_reg(dest, src, cpos, len); 32670b1347d2SRichard Henderson } 326830878590SRichard Henderson save_gpr(ctx, a->t, dest); 32690b1347d2SRichard Henderson 32700b1347d2SRichard Henderson /* Install the new nullification. */ 32710b1347d2SRichard Henderson cond_free(&ctx->null_cond); 327230878590SRichard Henderson if (a->c) { 327330878590SRichard Henderson ctx->null_cond = do_sed_cond(a->c, dest); 32740b1347d2SRichard Henderson } 327531234768SRichard Henderson return nullify_end(ctx); 32760b1347d2SRichard Henderson } 32770b1347d2SRichard Henderson 327830878590SRichard Henderson static bool trans_depwi_imm(DisasContext *ctx, arg_depwi_imm *a) 32790b1347d2SRichard Henderson { 328030878590SRichard Henderson unsigned len = 32 - a->clen; 3281eaa3783bSRichard Henderson target_sreg mask0, mask1; 3282eaa3783bSRichard Henderson TCGv_reg dest; 32830b1347d2SRichard Henderson 328430878590SRichard Henderson if (a->c) { 32850b1347d2SRichard Henderson nullify_over(ctx); 32860b1347d2SRichard Henderson } 328730878590SRichard Henderson if (a->cpos + len > 32) { 328830878590SRichard Henderson len = 32 - a->cpos; 32890b1347d2SRichard Henderson } 32900b1347d2SRichard Henderson 329130878590SRichard Henderson dest = dest_gpr(ctx, a->t); 329230878590SRichard Henderson mask0 = deposit64(0, a->cpos, len, a->i); 329330878590SRichard Henderson mask1 = deposit64(-1, a->cpos, len, a->i); 32940b1347d2SRichard Henderson 329530878590SRichard Henderson if (a->nz) { 329630878590SRichard Henderson TCGv_reg src = load_gpr(ctx, a->t); 32970b1347d2SRichard Henderson if (mask1 != -1) { 3298eaa3783bSRichard Henderson tcg_gen_andi_reg(dest, src, mask1); 32990b1347d2SRichard Henderson src = dest; 33000b1347d2SRichard Henderson } 3301eaa3783bSRichard Henderson tcg_gen_ori_reg(dest, src, mask0); 33020b1347d2SRichard Henderson } else { 3303eaa3783bSRichard Henderson tcg_gen_movi_reg(dest, mask0); 33040b1347d2SRichard Henderson } 330530878590SRichard Henderson save_gpr(ctx, a->t, dest); 33060b1347d2SRichard Henderson 33070b1347d2SRichard Henderson /* Install the new nullification. */ 33080b1347d2SRichard Henderson cond_free(&ctx->null_cond); 330930878590SRichard Henderson if (a->c) { 331030878590SRichard Henderson ctx->null_cond = do_sed_cond(a->c, dest); 33110b1347d2SRichard Henderson } 331231234768SRichard Henderson return nullify_end(ctx); 33130b1347d2SRichard Henderson } 33140b1347d2SRichard Henderson 331530878590SRichard Henderson static bool trans_depw_imm(DisasContext *ctx, arg_depw_imm *a) 33160b1347d2SRichard Henderson { 331730878590SRichard Henderson unsigned rs = a->nz ? a->t : 0; 331830878590SRichard Henderson unsigned len = 32 - a->clen; 3319eaa3783bSRichard Henderson TCGv_reg dest, val; 33200b1347d2SRichard Henderson 332130878590SRichard Henderson if (a->c) { 33220b1347d2SRichard Henderson nullify_over(ctx); 33230b1347d2SRichard Henderson } 332430878590SRichard Henderson if (a->cpos + len > 32) { 332530878590SRichard Henderson len = 32 - a->cpos; 33260b1347d2SRichard Henderson } 33270b1347d2SRichard Henderson 332830878590SRichard Henderson dest = dest_gpr(ctx, a->t); 332930878590SRichard Henderson val = load_gpr(ctx, a->r); 33300b1347d2SRichard Henderson if (rs == 0) { 333130878590SRichard Henderson tcg_gen_deposit_z_reg(dest, val, a->cpos, len); 33320b1347d2SRichard Henderson } else { 333330878590SRichard Henderson tcg_gen_deposit_reg(dest, cpu_gr[rs], val, a->cpos, len); 33340b1347d2SRichard Henderson } 333530878590SRichard Henderson save_gpr(ctx, a->t, dest); 33360b1347d2SRichard Henderson 33370b1347d2SRichard Henderson /* Install the new nullification. */ 33380b1347d2SRichard Henderson cond_free(&ctx->null_cond); 333930878590SRichard Henderson if (a->c) { 334030878590SRichard Henderson ctx->null_cond = do_sed_cond(a->c, dest); 33410b1347d2SRichard Henderson } 334231234768SRichard Henderson return nullify_end(ctx); 33430b1347d2SRichard Henderson } 33440b1347d2SRichard Henderson 334530878590SRichard Henderson static bool do_depw_sar(DisasContext *ctx, unsigned rt, unsigned c, 334630878590SRichard Henderson unsigned nz, unsigned clen, TCGv_reg val) 33470b1347d2SRichard Henderson { 33480b1347d2SRichard Henderson unsigned rs = nz ? rt : 0; 33490b1347d2SRichard Henderson unsigned len = 32 - clen; 335030878590SRichard Henderson TCGv_reg mask, tmp, shift, dest; 33510b1347d2SRichard Henderson unsigned msb = 1U << (len - 1); 33520b1347d2SRichard Henderson 33530b1347d2SRichard Henderson dest = dest_gpr(ctx, rt); 33540b1347d2SRichard Henderson shift = tcg_temp_new(); 33550b1347d2SRichard Henderson tmp = tcg_temp_new(); 33560b1347d2SRichard Henderson 33570b1347d2SRichard Henderson /* Convert big-endian bit numbering in SAR to left-shift. */ 3358eaa3783bSRichard Henderson tcg_gen_xori_reg(shift, cpu_sar, TARGET_REGISTER_BITS - 1); 33590b1347d2SRichard Henderson 33600992a930SRichard Henderson mask = tcg_temp_new(); 33610992a930SRichard Henderson tcg_gen_movi_reg(mask, msb + (msb - 1)); 3362eaa3783bSRichard Henderson tcg_gen_and_reg(tmp, val, mask); 33630b1347d2SRichard Henderson if (rs) { 3364eaa3783bSRichard Henderson tcg_gen_shl_reg(mask, mask, shift); 3365eaa3783bSRichard Henderson tcg_gen_shl_reg(tmp, tmp, shift); 3366eaa3783bSRichard Henderson tcg_gen_andc_reg(dest, cpu_gr[rs], mask); 3367eaa3783bSRichard Henderson tcg_gen_or_reg(dest, dest, tmp); 33680b1347d2SRichard Henderson } else { 3369eaa3783bSRichard Henderson tcg_gen_shl_reg(dest, tmp, shift); 33700b1347d2SRichard Henderson } 33710b1347d2SRichard Henderson save_gpr(ctx, rt, dest); 33720b1347d2SRichard Henderson 33730b1347d2SRichard Henderson /* Install the new nullification. */ 33740b1347d2SRichard Henderson cond_free(&ctx->null_cond); 33750b1347d2SRichard Henderson if (c) { 33760b1347d2SRichard Henderson ctx->null_cond = do_sed_cond(c, dest); 33770b1347d2SRichard Henderson } 337831234768SRichard Henderson return nullify_end(ctx); 33790b1347d2SRichard Henderson } 33800b1347d2SRichard Henderson 338130878590SRichard Henderson static bool trans_depw_sar(DisasContext *ctx, arg_depw_sar *a) 338230878590SRichard Henderson { 3383a6deecceSSven Schnelle if (a->c) { 3384a6deecceSSven Schnelle nullify_over(ctx); 3385a6deecceSSven Schnelle } 338630878590SRichard Henderson return do_depw_sar(ctx, a->t, a->c, a->nz, a->clen, load_gpr(ctx, a->r)); 338730878590SRichard Henderson } 338830878590SRichard Henderson 338930878590SRichard Henderson static bool trans_depwi_sar(DisasContext *ctx, arg_depwi_sar *a) 339030878590SRichard Henderson { 3391a6deecceSSven Schnelle if (a->c) { 3392a6deecceSSven Schnelle nullify_over(ctx); 3393a6deecceSSven Schnelle } 3394d4e58033SRichard Henderson return do_depw_sar(ctx, a->t, a->c, a->nz, a->clen, tcg_constant_reg(a->i)); 339530878590SRichard Henderson } 33960b1347d2SRichard Henderson 33978340f534SRichard Henderson static bool trans_be(DisasContext *ctx, arg_be *a) 339898cd9ca7SRichard Henderson { 3399660eefe1SRichard Henderson TCGv_reg tmp; 340098cd9ca7SRichard Henderson 3401c301f34eSRichard Henderson #ifdef CONFIG_USER_ONLY 340298cd9ca7SRichard Henderson /* ??? It seems like there should be a good way of using 340398cd9ca7SRichard Henderson "be disp(sr2, r0)", the canonical gateway entry mechanism 340498cd9ca7SRichard Henderson to our advantage. But that appears to be inconvenient to 340598cd9ca7SRichard Henderson manage along side branch delay slots. Therefore we handle 340698cd9ca7SRichard Henderson entry into the gateway page via absolute address. */ 340798cd9ca7SRichard Henderson /* Since we don't implement spaces, just branch. Do notice the special 340898cd9ca7SRichard Henderson case of "be disp(*,r0)" using a direct branch to disp, so that we can 340998cd9ca7SRichard Henderson goto_tb to the TB containing the syscall. */ 34108340f534SRichard Henderson if (a->b == 0) { 34118340f534SRichard Henderson return do_dbranch(ctx, a->disp, a->l, a->n); 341298cd9ca7SRichard Henderson } 3413c301f34eSRichard Henderson #else 3414c301f34eSRichard Henderson nullify_over(ctx); 3415660eefe1SRichard Henderson #endif 3416660eefe1SRichard Henderson 3417e12c6309SRichard Henderson tmp = tcg_temp_new(); 34188340f534SRichard Henderson tcg_gen_addi_reg(tmp, load_gpr(ctx, a->b), a->disp); 3419660eefe1SRichard Henderson tmp = do_ibranch_priv(ctx, tmp); 3420c301f34eSRichard Henderson 3421c301f34eSRichard Henderson #ifdef CONFIG_USER_ONLY 34228340f534SRichard Henderson return do_ibranch(ctx, tmp, a->l, a->n); 3423c301f34eSRichard Henderson #else 3424c301f34eSRichard Henderson TCGv_i64 new_spc = tcg_temp_new_i64(); 3425c301f34eSRichard Henderson 34268340f534SRichard Henderson load_spr(ctx, new_spc, a->sp); 34278340f534SRichard Henderson if (a->l) { 3428c301f34eSRichard Henderson copy_iaoq_entry(cpu_gr[31], ctx->iaoq_n, ctx->iaoq_n_var); 3429c301f34eSRichard Henderson tcg_gen_mov_i64(cpu_sr[0], cpu_iasq_f); 3430c301f34eSRichard Henderson } 34318340f534SRichard Henderson if (a->n && use_nullify_skip(ctx)) { 3432c301f34eSRichard Henderson tcg_gen_mov_reg(cpu_iaoq_f, tmp); 3433c301f34eSRichard Henderson tcg_gen_addi_reg(cpu_iaoq_b, cpu_iaoq_f, 4); 3434c301f34eSRichard Henderson tcg_gen_mov_i64(cpu_iasq_f, new_spc); 3435c301f34eSRichard Henderson tcg_gen_mov_i64(cpu_iasq_b, cpu_iasq_f); 3436c301f34eSRichard Henderson } else { 3437c301f34eSRichard Henderson copy_iaoq_entry(cpu_iaoq_f, ctx->iaoq_b, cpu_iaoq_b); 3438c301f34eSRichard Henderson if (ctx->iaoq_b == -1) { 3439c301f34eSRichard Henderson tcg_gen_mov_i64(cpu_iasq_f, cpu_iasq_b); 3440c301f34eSRichard Henderson } 3441c301f34eSRichard Henderson tcg_gen_mov_reg(cpu_iaoq_b, tmp); 3442c301f34eSRichard Henderson tcg_gen_mov_i64(cpu_iasq_b, new_spc); 34438340f534SRichard Henderson nullify_set(ctx, a->n); 3444c301f34eSRichard Henderson } 3445c301f34eSRichard Henderson tcg_gen_lookup_and_goto_ptr(); 344631234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 344731234768SRichard Henderson return nullify_end(ctx); 3448c301f34eSRichard Henderson #endif 344998cd9ca7SRichard Henderson } 345098cd9ca7SRichard Henderson 34518340f534SRichard Henderson static bool trans_bl(DisasContext *ctx, arg_bl *a) 345298cd9ca7SRichard Henderson { 34538340f534SRichard Henderson return do_dbranch(ctx, iaoq_dest(ctx, a->disp), a->l, a->n); 345498cd9ca7SRichard Henderson } 345598cd9ca7SRichard Henderson 34568340f534SRichard Henderson static bool trans_b_gate(DisasContext *ctx, arg_b_gate *a) 345743e05652SRichard Henderson { 34588340f534SRichard Henderson target_ureg dest = iaoq_dest(ctx, a->disp); 345943e05652SRichard Henderson 34606e5f5300SSven Schnelle nullify_over(ctx); 34616e5f5300SSven Schnelle 346243e05652SRichard Henderson /* Make sure the caller hasn't done something weird with the queue. 346343e05652SRichard Henderson * ??? This is not quite the same as the PSW[B] bit, which would be 346443e05652SRichard Henderson * expensive to track. Real hardware will trap for 346543e05652SRichard Henderson * b gateway 346643e05652SRichard Henderson * b gateway+4 (in delay slot of first branch) 346743e05652SRichard Henderson * However, checking for a non-sequential instruction queue *will* 346843e05652SRichard Henderson * diagnose the security hole 346943e05652SRichard Henderson * b gateway 347043e05652SRichard Henderson * b evil 347143e05652SRichard Henderson * in which instructions at evil would run with increased privs. 347243e05652SRichard Henderson */ 347343e05652SRichard Henderson if (ctx->iaoq_b == -1 || ctx->iaoq_b != ctx->iaoq_f + 4) { 347443e05652SRichard Henderson return gen_illegal(ctx); 347543e05652SRichard Henderson } 347643e05652SRichard Henderson 347743e05652SRichard Henderson #ifndef CONFIG_USER_ONLY 347843e05652SRichard Henderson if (ctx->tb_flags & PSW_C) { 3479b77af26eSRichard Henderson CPUHPPAState *env = cpu_env(ctx->cs); 348043e05652SRichard Henderson int type = hppa_artype_for_page(env, ctx->base.pc_next); 348143e05652SRichard Henderson /* If we could not find a TLB entry, then we need to generate an 348243e05652SRichard Henderson ITLB miss exception so the kernel will provide it. 348343e05652SRichard Henderson The resulting TLB fill operation will invalidate this TB and 348443e05652SRichard Henderson we will re-translate, at which point we *will* be able to find 348543e05652SRichard Henderson the TLB entry and determine if this is in fact a gateway page. */ 348643e05652SRichard Henderson if (type < 0) { 348731234768SRichard Henderson gen_excp(ctx, EXCP_ITLB_MISS); 348831234768SRichard Henderson return true; 348943e05652SRichard Henderson } 349043e05652SRichard Henderson /* No change for non-gateway pages or for priv decrease. */ 349143e05652SRichard Henderson if (type >= 4 && type - 4 < ctx->privilege) { 349243e05652SRichard Henderson dest = deposit32(dest, 0, 2, type - 4); 349343e05652SRichard Henderson } 349443e05652SRichard Henderson } else { 349543e05652SRichard Henderson dest &= -4; /* priv = 0 */ 349643e05652SRichard Henderson } 349743e05652SRichard Henderson #endif 349843e05652SRichard Henderson 34996e5f5300SSven Schnelle if (a->l) { 35006e5f5300SSven Schnelle TCGv_reg tmp = dest_gpr(ctx, a->l); 35016e5f5300SSven Schnelle if (ctx->privilege < 3) { 35026e5f5300SSven Schnelle tcg_gen_andi_reg(tmp, tmp, -4); 35036e5f5300SSven Schnelle } 35046e5f5300SSven Schnelle tcg_gen_ori_reg(tmp, tmp, ctx->privilege); 35056e5f5300SSven Schnelle save_gpr(ctx, a->l, tmp); 35066e5f5300SSven Schnelle } 35076e5f5300SSven Schnelle 35086e5f5300SSven Schnelle return do_dbranch(ctx, dest, 0, a->n); 350943e05652SRichard Henderson } 351043e05652SRichard Henderson 35118340f534SRichard Henderson static bool trans_blr(DisasContext *ctx, arg_blr *a) 351298cd9ca7SRichard Henderson { 3513b35aec85SRichard Henderson if (a->x) { 3514e12c6309SRichard Henderson TCGv_reg tmp = tcg_temp_new(); 35158340f534SRichard Henderson tcg_gen_shli_reg(tmp, load_gpr(ctx, a->x), 3); 3516eaa3783bSRichard Henderson tcg_gen_addi_reg(tmp, tmp, ctx->iaoq_f + 8); 3517660eefe1SRichard Henderson /* The computation here never changes privilege level. */ 35188340f534SRichard Henderson return do_ibranch(ctx, tmp, a->l, a->n); 3519b35aec85SRichard Henderson } else { 3520b35aec85SRichard Henderson /* BLR R0,RX is a good way to load PC+8 into RX. */ 3521b35aec85SRichard Henderson return do_dbranch(ctx, ctx->iaoq_f + 8, a->l, a->n); 3522b35aec85SRichard Henderson } 352398cd9ca7SRichard Henderson } 352498cd9ca7SRichard Henderson 35258340f534SRichard Henderson static bool trans_bv(DisasContext *ctx, arg_bv *a) 352698cd9ca7SRichard Henderson { 3527eaa3783bSRichard Henderson TCGv_reg dest; 352898cd9ca7SRichard Henderson 35298340f534SRichard Henderson if (a->x == 0) { 35308340f534SRichard Henderson dest = load_gpr(ctx, a->b); 353198cd9ca7SRichard Henderson } else { 3532e12c6309SRichard Henderson dest = tcg_temp_new(); 35338340f534SRichard Henderson tcg_gen_shli_reg(dest, load_gpr(ctx, a->x), 3); 35348340f534SRichard Henderson tcg_gen_add_reg(dest, dest, load_gpr(ctx, a->b)); 353598cd9ca7SRichard Henderson } 3536660eefe1SRichard Henderson dest = do_ibranch_priv(ctx, dest); 35378340f534SRichard Henderson return do_ibranch(ctx, dest, 0, a->n); 353898cd9ca7SRichard Henderson } 353998cd9ca7SRichard Henderson 35408340f534SRichard Henderson static bool trans_bve(DisasContext *ctx, arg_bve *a) 354198cd9ca7SRichard Henderson { 3542660eefe1SRichard Henderson TCGv_reg dest; 354398cd9ca7SRichard Henderson 3544c301f34eSRichard Henderson #ifdef CONFIG_USER_ONLY 35458340f534SRichard Henderson dest = do_ibranch_priv(ctx, load_gpr(ctx, a->b)); 35468340f534SRichard Henderson return do_ibranch(ctx, dest, a->l, a->n); 3547c301f34eSRichard Henderson #else 3548c301f34eSRichard Henderson nullify_over(ctx); 35498340f534SRichard Henderson dest = do_ibranch_priv(ctx, load_gpr(ctx, a->b)); 3550c301f34eSRichard Henderson 3551c301f34eSRichard Henderson copy_iaoq_entry(cpu_iaoq_f, ctx->iaoq_b, cpu_iaoq_b); 3552c301f34eSRichard Henderson if (ctx->iaoq_b == -1) { 3553c301f34eSRichard Henderson tcg_gen_mov_i64(cpu_iasq_f, cpu_iasq_b); 3554c301f34eSRichard Henderson } 3555c301f34eSRichard Henderson copy_iaoq_entry(cpu_iaoq_b, -1, dest); 3556c301f34eSRichard Henderson tcg_gen_mov_i64(cpu_iasq_b, space_select(ctx, 0, dest)); 35578340f534SRichard Henderson if (a->l) { 35588340f534SRichard Henderson copy_iaoq_entry(cpu_gr[a->l], ctx->iaoq_n, ctx->iaoq_n_var); 3559c301f34eSRichard Henderson } 35608340f534SRichard Henderson nullify_set(ctx, a->n); 3561c301f34eSRichard Henderson tcg_gen_lookup_and_goto_ptr(); 356231234768SRichard Henderson ctx->base.is_jmp = DISAS_NORETURN; 356331234768SRichard Henderson return nullify_end(ctx); 3564c301f34eSRichard Henderson #endif 356598cd9ca7SRichard Henderson } 356698cd9ca7SRichard Henderson 35671ca74648SRichard Henderson /* 35681ca74648SRichard Henderson * Float class 0 35691ca74648SRichard Henderson */ 3570ebe9383cSRichard Henderson 35711ca74648SRichard Henderson static void gen_fcpy_f(TCGv_i32 dst, TCGv_env unused, TCGv_i32 src) 3572ebe9383cSRichard Henderson { 3573ebe9383cSRichard Henderson tcg_gen_mov_i32(dst, src); 3574ebe9383cSRichard Henderson } 3575ebe9383cSRichard Henderson 357659f8c04bSHelge Deller static bool trans_fid_f(DisasContext *ctx, arg_fid_f *a) 357759f8c04bSHelge Deller { 3578a300dad3SRichard Henderson uint64_t ret; 3579a300dad3SRichard Henderson 3580a300dad3SRichard Henderson if (TARGET_REGISTER_BITS == 64) { 3581a300dad3SRichard Henderson ret = 0x13080000000000ULL; /* PA8700 (PCX-W2) */ 3582a300dad3SRichard Henderson } else { 3583a300dad3SRichard Henderson ret = 0x0f080000000000ULL; /* PA7300LC (PCX-L2) */ 3584a300dad3SRichard Henderson } 3585a300dad3SRichard Henderson 358659f8c04bSHelge Deller nullify_over(ctx); 3587a300dad3SRichard Henderson save_frd(0, tcg_constant_i64(ret)); 358859f8c04bSHelge Deller return nullify_end(ctx); 358959f8c04bSHelge Deller } 359059f8c04bSHelge Deller 35911ca74648SRichard Henderson static bool trans_fcpy_f(DisasContext *ctx, arg_fclass01 *a) 35921ca74648SRichard Henderson { 35931ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_fcpy_f); 35941ca74648SRichard Henderson } 35951ca74648SRichard Henderson 3596ebe9383cSRichard Henderson static void gen_fcpy_d(TCGv_i64 dst, TCGv_env unused, TCGv_i64 src) 3597ebe9383cSRichard Henderson { 3598ebe9383cSRichard Henderson tcg_gen_mov_i64(dst, src); 3599ebe9383cSRichard Henderson } 3600ebe9383cSRichard Henderson 36011ca74648SRichard Henderson static bool trans_fcpy_d(DisasContext *ctx, arg_fclass01 *a) 36021ca74648SRichard Henderson { 36031ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_fcpy_d); 36041ca74648SRichard Henderson } 36051ca74648SRichard Henderson 36061ca74648SRichard Henderson static void gen_fabs_f(TCGv_i32 dst, TCGv_env unused, TCGv_i32 src) 3607ebe9383cSRichard Henderson { 3608ebe9383cSRichard Henderson tcg_gen_andi_i32(dst, src, INT32_MAX); 3609ebe9383cSRichard Henderson } 3610ebe9383cSRichard Henderson 36111ca74648SRichard Henderson static bool trans_fabs_f(DisasContext *ctx, arg_fclass01 *a) 36121ca74648SRichard Henderson { 36131ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_fabs_f); 36141ca74648SRichard Henderson } 36151ca74648SRichard Henderson 3616ebe9383cSRichard Henderson static void gen_fabs_d(TCGv_i64 dst, TCGv_env unused, TCGv_i64 src) 3617ebe9383cSRichard Henderson { 3618ebe9383cSRichard Henderson tcg_gen_andi_i64(dst, src, INT64_MAX); 3619ebe9383cSRichard Henderson } 3620ebe9383cSRichard Henderson 36211ca74648SRichard Henderson static bool trans_fabs_d(DisasContext *ctx, arg_fclass01 *a) 36221ca74648SRichard Henderson { 36231ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_fabs_d); 36241ca74648SRichard Henderson } 36251ca74648SRichard Henderson 36261ca74648SRichard Henderson static bool trans_fsqrt_f(DisasContext *ctx, arg_fclass01 *a) 36271ca74648SRichard Henderson { 36281ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_fsqrt_s); 36291ca74648SRichard Henderson } 36301ca74648SRichard Henderson 36311ca74648SRichard Henderson static bool trans_fsqrt_d(DisasContext *ctx, arg_fclass01 *a) 36321ca74648SRichard Henderson { 36331ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_fsqrt_d); 36341ca74648SRichard Henderson } 36351ca74648SRichard Henderson 36361ca74648SRichard Henderson static bool trans_frnd_f(DisasContext *ctx, arg_fclass01 *a) 36371ca74648SRichard Henderson { 36381ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_frnd_s); 36391ca74648SRichard Henderson } 36401ca74648SRichard Henderson 36411ca74648SRichard Henderson static bool trans_frnd_d(DisasContext *ctx, arg_fclass01 *a) 36421ca74648SRichard Henderson { 36431ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_frnd_d); 36441ca74648SRichard Henderson } 36451ca74648SRichard Henderson 36461ca74648SRichard Henderson static void gen_fneg_f(TCGv_i32 dst, TCGv_env unused, TCGv_i32 src) 3647ebe9383cSRichard Henderson { 3648ebe9383cSRichard Henderson tcg_gen_xori_i32(dst, src, INT32_MIN); 3649ebe9383cSRichard Henderson } 3650ebe9383cSRichard Henderson 36511ca74648SRichard Henderson static bool trans_fneg_f(DisasContext *ctx, arg_fclass01 *a) 36521ca74648SRichard Henderson { 36531ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_fneg_f); 36541ca74648SRichard Henderson } 36551ca74648SRichard Henderson 3656ebe9383cSRichard Henderson static void gen_fneg_d(TCGv_i64 dst, TCGv_env unused, TCGv_i64 src) 3657ebe9383cSRichard Henderson { 3658ebe9383cSRichard Henderson tcg_gen_xori_i64(dst, src, INT64_MIN); 3659ebe9383cSRichard Henderson } 3660ebe9383cSRichard Henderson 36611ca74648SRichard Henderson static bool trans_fneg_d(DisasContext *ctx, arg_fclass01 *a) 36621ca74648SRichard Henderson { 36631ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_fneg_d); 36641ca74648SRichard Henderson } 36651ca74648SRichard Henderson 36661ca74648SRichard Henderson static void gen_fnegabs_f(TCGv_i32 dst, TCGv_env unused, TCGv_i32 src) 3667ebe9383cSRichard Henderson { 3668ebe9383cSRichard Henderson tcg_gen_ori_i32(dst, src, INT32_MIN); 3669ebe9383cSRichard Henderson } 3670ebe9383cSRichard Henderson 36711ca74648SRichard Henderson static bool trans_fnegabs_f(DisasContext *ctx, arg_fclass01 *a) 36721ca74648SRichard Henderson { 36731ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_fnegabs_f); 36741ca74648SRichard Henderson } 36751ca74648SRichard Henderson 3676ebe9383cSRichard Henderson static void gen_fnegabs_d(TCGv_i64 dst, TCGv_env unused, TCGv_i64 src) 3677ebe9383cSRichard Henderson { 3678ebe9383cSRichard Henderson tcg_gen_ori_i64(dst, src, INT64_MIN); 3679ebe9383cSRichard Henderson } 3680ebe9383cSRichard Henderson 36811ca74648SRichard Henderson static bool trans_fnegabs_d(DisasContext *ctx, arg_fclass01 *a) 36821ca74648SRichard Henderson { 36831ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_fnegabs_d); 36841ca74648SRichard Henderson } 36851ca74648SRichard Henderson 36861ca74648SRichard Henderson /* 36871ca74648SRichard Henderson * Float class 1 36881ca74648SRichard Henderson */ 36891ca74648SRichard Henderson 36901ca74648SRichard Henderson static bool trans_fcnv_d_f(DisasContext *ctx, arg_fclass01 *a) 36911ca74648SRichard Henderson { 36921ca74648SRichard Henderson return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_d_s); 36931ca74648SRichard Henderson } 36941ca74648SRichard Henderson 36951ca74648SRichard Henderson static bool trans_fcnv_f_d(DisasContext *ctx, arg_fclass01 *a) 36961ca74648SRichard Henderson { 36971ca74648SRichard Henderson return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_s_d); 36981ca74648SRichard Henderson } 36991ca74648SRichard Henderson 37001ca74648SRichard Henderson static bool trans_fcnv_w_f(DisasContext *ctx, arg_fclass01 *a) 37011ca74648SRichard Henderson { 37021ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_w_s); 37031ca74648SRichard Henderson } 37041ca74648SRichard Henderson 37051ca74648SRichard Henderson static bool trans_fcnv_q_f(DisasContext *ctx, arg_fclass01 *a) 37061ca74648SRichard Henderson { 37071ca74648SRichard Henderson return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_dw_s); 37081ca74648SRichard Henderson } 37091ca74648SRichard Henderson 37101ca74648SRichard Henderson static bool trans_fcnv_w_d(DisasContext *ctx, arg_fclass01 *a) 37111ca74648SRichard Henderson { 37121ca74648SRichard Henderson return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_w_d); 37131ca74648SRichard Henderson } 37141ca74648SRichard Henderson 37151ca74648SRichard Henderson static bool trans_fcnv_q_d(DisasContext *ctx, arg_fclass01 *a) 37161ca74648SRichard Henderson { 37171ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_dw_d); 37181ca74648SRichard Henderson } 37191ca74648SRichard Henderson 37201ca74648SRichard Henderson static bool trans_fcnv_f_w(DisasContext *ctx, arg_fclass01 *a) 37211ca74648SRichard Henderson { 37221ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_s_w); 37231ca74648SRichard Henderson } 37241ca74648SRichard Henderson 37251ca74648SRichard Henderson static bool trans_fcnv_d_w(DisasContext *ctx, arg_fclass01 *a) 37261ca74648SRichard Henderson { 37271ca74648SRichard Henderson return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_d_w); 37281ca74648SRichard Henderson } 37291ca74648SRichard Henderson 37301ca74648SRichard Henderson static bool trans_fcnv_f_q(DisasContext *ctx, arg_fclass01 *a) 37311ca74648SRichard Henderson { 37321ca74648SRichard Henderson return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_s_dw); 37331ca74648SRichard Henderson } 37341ca74648SRichard Henderson 37351ca74648SRichard Henderson static bool trans_fcnv_d_q(DisasContext *ctx, arg_fclass01 *a) 37361ca74648SRichard Henderson { 37371ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_d_dw); 37381ca74648SRichard Henderson } 37391ca74648SRichard Henderson 37401ca74648SRichard Henderson static bool trans_fcnv_t_f_w(DisasContext *ctx, arg_fclass01 *a) 37411ca74648SRichard Henderson { 37421ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_t_s_w); 37431ca74648SRichard Henderson } 37441ca74648SRichard Henderson 37451ca74648SRichard Henderson static bool trans_fcnv_t_d_w(DisasContext *ctx, arg_fclass01 *a) 37461ca74648SRichard Henderson { 37471ca74648SRichard Henderson return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_t_d_w); 37481ca74648SRichard Henderson } 37491ca74648SRichard Henderson 37501ca74648SRichard Henderson static bool trans_fcnv_t_f_q(DisasContext *ctx, arg_fclass01 *a) 37511ca74648SRichard Henderson { 37521ca74648SRichard Henderson return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_t_s_dw); 37531ca74648SRichard Henderson } 37541ca74648SRichard Henderson 37551ca74648SRichard Henderson static bool trans_fcnv_t_d_q(DisasContext *ctx, arg_fclass01 *a) 37561ca74648SRichard Henderson { 37571ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_t_d_dw); 37581ca74648SRichard Henderson } 37591ca74648SRichard Henderson 37601ca74648SRichard Henderson static bool trans_fcnv_uw_f(DisasContext *ctx, arg_fclass01 *a) 37611ca74648SRichard Henderson { 37621ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_uw_s); 37631ca74648SRichard Henderson } 37641ca74648SRichard Henderson 37651ca74648SRichard Henderson static bool trans_fcnv_uq_f(DisasContext *ctx, arg_fclass01 *a) 37661ca74648SRichard Henderson { 37671ca74648SRichard Henderson return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_udw_s); 37681ca74648SRichard Henderson } 37691ca74648SRichard Henderson 37701ca74648SRichard Henderson static bool trans_fcnv_uw_d(DisasContext *ctx, arg_fclass01 *a) 37711ca74648SRichard Henderson { 37721ca74648SRichard Henderson return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_uw_d); 37731ca74648SRichard Henderson } 37741ca74648SRichard Henderson 37751ca74648SRichard Henderson static bool trans_fcnv_uq_d(DisasContext *ctx, arg_fclass01 *a) 37761ca74648SRichard Henderson { 37771ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_udw_d); 37781ca74648SRichard Henderson } 37791ca74648SRichard Henderson 37801ca74648SRichard Henderson static bool trans_fcnv_f_uw(DisasContext *ctx, arg_fclass01 *a) 37811ca74648SRichard Henderson { 37821ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_s_uw); 37831ca74648SRichard Henderson } 37841ca74648SRichard Henderson 37851ca74648SRichard Henderson static bool trans_fcnv_d_uw(DisasContext *ctx, arg_fclass01 *a) 37861ca74648SRichard Henderson { 37871ca74648SRichard Henderson return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_d_uw); 37881ca74648SRichard Henderson } 37891ca74648SRichard Henderson 37901ca74648SRichard Henderson static bool trans_fcnv_f_uq(DisasContext *ctx, arg_fclass01 *a) 37911ca74648SRichard Henderson { 37921ca74648SRichard Henderson return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_s_udw); 37931ca74648SRichard Henderson } 37941ca74648SRichard Henderson 37951ca74648SRichard Henderson static bool trans_fcnv_d_uq(DisasContext *ctx, arg_fclass01 *a) 37961ca74648SRichard Henderson { 37971ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_d_udw); 37981ca74648SRichard Henderson } 37991ca74648SRichard Henderson 38001ca74648SRichard Henderson static bool trans_fcnv_t_f_uw(DisasContext *ctx, arg_fclass01 *a) 38011ca74648SRichard Henderson { 38021ca74648SRichard Henderson return do_fop_wew(ctx, a->t, a->r, gen_helper_fcnv_t_s_uw); 38031ca74648SRichard Henderson } 38041ca74648SRichard Henderson 38051ca74648SRichard Henderson static bool trans_fcnv_t_d_uw(DisasContext *ctx, arg_fclass01 *a) 38061ca74648SRichard Henderson { 38071ca74648SRichard Henderson return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_t_d_uw); 38081ca74648SRichard Henderson } 38091ca74648SRichard Henderson 38101ca74648SRichard Henderson static bool trans_fcnv_t_f_uq(DisasContext *ctx, arg_fclass01 *a) 38111ca74648SRichard Henderson { 38121ca74648SRichard Henderson return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_t_s_udw); 38131ca74648SRichard Henderson } 38141ca74648SRichard Henderson 38151ca74648SRichard Henderson static bool trans_fcnv_t_d_uq(DisasContext *ctx, arg_fclass01 *a) 38161ca74648SRichard Henderson { 38171ca74648SRichard Henderson return do_fop_ded(ctx, a->t, a->r, gen_helper_fcnv_t_d_udw); 38181ca74648SRichard Henderson } 38191ca74648SRichard Henderson 38201ca74648SRichard Henderson /* 38211ca74648SRichard Henderson * Float class 2 38221ca74648SRichard Henderson */ 38231ca74648SRichard Henderson 38241ca74648SRichard Henderson static bool trans_fcmp_f(DisasContext *ctx, arg_fclass2 *a) 3825ebe9383cSRichard Henderson { 3826ebe9383cSRichard Henderson TCGv_i32 ta, tb, tc, ty; 3827ebe9383cSRichard Henderson 3828ebe9383cSRichard Henderson nullify_over(ctx); 3829ebe9383cSRichard Henderson 38301ca74648SRichard Henderson ta = load_frw0_i32(a->r1); 38311ca74648SRichard Henderson tb = load_frw0_i32(a->r2); 383229dd6f64SRichard Henderson ty = tcg_constant_i32(a->y); 383329dd6f64SRichard Henderson tc = tcg_constant_i32(a->c); 3834ebe9383cSRichard Henderson 3835ad75a51eSRichard Henderson gen_helper_fcmp_s(tcg_env, ta, tb, ty, tc); 3836ebe9383cSRichard Henderson 38371ca74648SRichard Henderson return nullify_end(ctx); 3838ebe9383cSRichard Henderson } 3839ebe9383cSRichard Henderson 38401ca74648SRichard Henderson static bool trans_fcmp_d(DisasContext *ctx, arg_fclass2 *a) 3841ebe9383cSRichard Henderson { 3842ebe9383cSRichard Henderson TCGv_i64 ta, tb; 3843ebe9383cSRichard Henderson TCGv_i32 tc, ty; 3844ebe9383cSRichard Henderson 3845ebe9383cSRichard Henderson nullify_over(ctx); 3846ebe9383cSRichard Henderson 38471ca74648SRichard Henderson ta = load_frd0(a->r1); 38481ca74648SRichard Henderson tb = load_frd0(a->r2); 384929dd6f64SRichard Henderson ty = tcg_constant_i32(a->y); 385029dd6f64SRichard Henderson tc = tcg_constant_i32(a->c); 3851ebe9383cSRichard Henderson 3852ad75a51eSRichard Henderson gen_helper_fcmp_d(tcg_env, ta, tb, ty, tc); 3853ebe9383cSRichard Henderson 385431234768SRichard Henderson return nullify_end(ctx); 3855ebe9383cSRichard Henderson } 3856ebe9383cSRichard Henderson 38571ca74648SRichard Henderson static bool trans_ftest(DisasContext *ctx, arg_ftest *a) 3858ebe9383cSRichard Henderson { 3859eaa3783bSRichard Henderson TCGv_reg t; 3860ebe9383cSRichard Henderson 3861ebe9383cSRichard Henderson nullify_over(ctx); 3862ebe9383cSRichard Henderson 3863e12c6309SRichard Henderson t = tcg_temp_new(); 3864ad75a51eSRichard Henderson tcg_gen_ld32u_reg(t, tcg_env, offsetof(CPUHPPAState, fr0_shadow)); 3865ebe9383cSRichard Henderson 38661ca74648SRichard Henderson if (a->y == 1) { 3867ebe9383cSRichard Henderson int mask; 3868ebe9383cSRichard Henderson bool inv = false; 3869ebe9383cSRichard Henderson 38701ca74648SRichard Henderson switch (a->c) { 3871ebe9383cSRichard Henderson case 0: /* simple */ 3872eaa3783bSRichard Henderson tcg_gen_andi_reg(t, t, 0x4000000); 3873ebe9383cSRichard Henderson ctx->null_cond = cond_make_0(TCG_COND_NE, t); 3874ebe9383cSRichard Henderson goto done; 3875ebe9383cSRichard Henderson case 2: /* rej */ 3876ebe9383cSRichard Henderson inv = true; 3877ebe9383cSRichard Henderson /* fallthru */ 3878ebe9383cSRichard Henderson case 1: /* acc */ 3879ebe9383cSRichard Henderson mask = 0x43ff800; 3880ebe9383cSRichard Henderson break; 3881ebe9383cSRichard Henderson case 6: /* rej8 */ 3882ebe9383cSRichard Henderson inv = true; 3883ebe9383cSRichard Henderson /* fallthru */ 3884ebe9383cSRichard Henderson case 5: /* acc8 */ 3885ebe9383cSRichard Henderson mask = 0x43f8000; 3886ebe9383cSRichard Henderson break; 3887ebe9383cSRichard Henderson case 9: /* acc6 */ 3888ebe9383cSRichard Henderson mask = 0x43e0000; 3889ebe9383cSRichard Henderson break; 3890ebe9383cSRichard Henderson case 13: /* acc4 */ 3891ebe9383cSRichard Henderson mask = 0x4380000; 3892ebe9383cSRichard Henderson break; 3893ebe9383cSRichard Henderson case 17: /* acc2 */ 3894ebe9383cSRichard Henderson mask = 0x4200000; 3895ebe9383cSRichard Henderson break; 3896ebe9383cSRichard Henderson default: 38971ca74648SRichard Henderson gen_illegal(ctx); 38981ca74648SRichard Henderson return true; 3899ebe9383cSRichard Henderson } 3900ebe9383cSRichard Henderson if (inv) { 3901d4e58033SRichard Henderson TCGv_reg c = tcg_constant_reg(mask); 3902eaa3783bSRichard Henderson tcg_gen_or_reg(t, t, c); 3903ebe9383cSRichard Henderson ctx->null_cond = cond_make(TCG_COND_EQ, t, c); 3904ebe9383cSRichard Henderson } else { 3905eaa3783bSRichard Henderson tcg_gen_andi_reg(t, t, mask); 3906ebe9383cSRichard Henderson ctx->null_cond = cond_make_0(TCG_COND_EQ, t); 3907ebe9383cSRichard Henderson } 39081ca74648SRichard Henderson } else { 39091ca74648SRichard Henderson unsigned cbit = (a->y ^ 1) - 1; 39101ca74648SRichard Henderson 39111ca74648SRichard Henderson tcg_gen_extract_reg(t, t, 21 - cbit, 1); 39121ca74648SRichard Henderson ctx->null_cond = cond_make_0(TCG_COND_NE, t); 39131ca74648SRichard Henderson } 39141ca74648SRichard Henderson 3915ebe9383cSRichard Henderson done: 391631234768SRichard Henderson return nullify_end(ctx); 3917ebe9383cSRichard Henderson } 3918ebe9383cSRichard Henderson 39191ca74648SRichard Henderson /* 39201ca74648SRichard Henderson * Float class 2 39211ca74648SRichard Henderson */ 39221ca74648SRichard Henderson 39231ca74648SRichard Henderson static bool trans_fadd_f(DisasContext *ctx, arg_fclass3 *a) 3924ebe9383cSRichard Henderson { 39251ca74648SRichard Henderson return do_fop_weww(ctx, a->t, a->r1, a->r2, gen_helper_fadd_s); 39261ca74648SRichard Henderson } 39271ca74648SRichard Henderson 39281ca74648SRichard Henderson static bool trans_fadd_d(DisasContext *ctx, arg_fclass3 *a) 39291ca74648SRichard Henderson { 39301ca74648SRichard Henderson return do_fop_dedd(ctx, a->t, a->r1, a->r2, gen_helper_fadd_d); 39311ca74648SRichard Henderson } 39321ca74648SRichard Henderson 39331ca74648SRichard Henderson static bool trans_fsub_f(DisasContext *ctx, arg_fclass3 *a) 39341ca74648SRichard Henderson { 39351ca74648SRichard Henderson return do_fop_weww(ctx, a->t, a->r1, a->r2, gen_helper_fsub_s); 39361ca74648SRichard Henderson } 39371ca74648SRichard Henderson 39381ca74648SRichard Henderson static bool trans_fsub_d(DisasContext *ctx, arg_fclass3 *a) 39391ca74648SRichard Henderson { 39401ca74648SRichard Henderson return do_fop_dedd(ctx, a->t, a->r1, a->r2, gen_helper_fsub_d); 39411ca74648SRichard Henderson } 39421ca74648SRichard Henderson 39431ca74648SRichard Henderson static bool trans_fmpy_f(DisasContext *ctx, arg_fclass3 *a) 39441ca74648SRichard Henderson { 39451ca74648SRichard Henderson return do_fop_weww(ctx, a->t, a->r1, a->r2, gen_helper_fmpy_s); 39461ca74648SRichard Henderson } 39471ca74648SRichard Henderson 39481ca74648SRichard Henderson static bool trans_fmpy_d(DisasContext *ctx, arg_fclass3 *a) 39491ca74648SRichard Henderson { 39501ca74648SRichard Henderson return do_fop_dedd(ctx, a->t, a->r1, a->r2, gen_helper_fmpy_d); 39511ca74648SRichard Henderson } 39521ca74648SRichard Henderson 39531ca74648SRichard Henderson static bool trans_fdiv_f(DisasContext *ctx, arg_fclass3 *a) 39541ca74648SRichard Henderson { 39551ca74648SRichard Henderson return do_fop_weww(ctx, a->t, a->r1, a->r2, gen_helper_fdiv_s); 39561ca74648SRichard Henderson } 39571ca74648SRichard Henderson 39581ca74648SRichard Henderson static bool trans_fdiv_d(DisasContext *ctx, arg_fclass3 *a) 39591ca74648SRichard Henderson { 39601ca74648SRichard Henderson return do_fop_dedd(ctx, a->t, a->r1, a->r2, gen_helper_fdiv_d); 39611ca74648SRichard Henderson } 39621ca74648SRichard Henderson 39631ca74648SRichard Henderson static bool trans_xmpyu(DisasContext *ctx, arg_xmpyu *a) 39641ca74648SRichard Henderson { 39651ca74648SRichard Henderson TCGv_i64 x, y; 3966ebe9383cSRichard Henderson 3967ebe9383cSRichard Henderson nullify_over(ctx); 3968ebe9383cSRichard Henderson 39691ca74648SRichard Henderson x = load_frw0_i64(a->r1); 39701ca74648SRichard Henderson y = load_frw0_i64(a->r2); 39711ca74648SRichard Henderson tcg_gen_mul_i64(x, x, y); 39721ca74648SRichard Henderson save_frd(a->t, x); 3973ebe9383cSRichard Henderson 397431234768SRichard Henderson return nullify_end(ctx); 3975ebe9383cSRichard Henderson } 3976ebe9383cSRichard Henderson 3977ebe9383cSRichard Henderson /* Convert the fmpyadd single-precision register encodings to standard. */ 3978ebe9383cSRichard Henderson static inline int fmpyadd_s_reg(unsigned r) 3979ebe9383cSRichard Henderson { 3980ebe9383cSRichard Henderson return (r & 16) * 2 + 16 + (r & 15); 3981ebe9383cSRichard Henderson } 3982ebe9383cSRichard Henderson 3983b1e2af57SRichard Henderson static bool do_fmpyadd_s(DisasContext *ctx, arg_mpyadd *a, bool is_sub) 3984ebe9383cSRichard Henderson { 3985b1e2af57SRichard Henderson int tm = fmpyadd_s_reg(a->tm); 3986b1e2af57SRichard Henderson int ra = fmpyadd_s_reg(a->ra); 3987b1e2af57SRichard Henderson int ta = fmpyadd_s_reg(a->ta); 3988b1e2af57SRichard Henderson int rm2 = fmpyadd_s_reg(a->rm2); 3989b1e2af57SRichard Henderson int rm1 = fmpyadd_s_reg(a->rm1); 3990ebe9383cSRichard Henderson 3991ebe9383cSRichard Henderson nullify_over(ctx); 3992ebe9383cSRichard Henderson 3993ebe9383cSRichard Henderson do_fop_weww(ctx, tm, rm1, rm2, gen_helper_fmpy_s); 3994ebe9383cSRichard Henderson do_fop_weww(ctx, ta, ta, ra, 3995ebe9383cSRichard Henderson is_sub ? gen_helper_fsub_s : gen_helper_fadd_s); 3996ebe9383cSRichard Henderson 399731234768SRichard Henderson return nullify_end(ctx); 3998ebe9383cSRichard Henderson } 3999ebe9383cSRichard Henderson 4000b1e2af57SRichard Henderson static bool trans_fmpyadd_f(DisasContext *ctx, arg_mpyadd *a) 4001b1e2af57SRichard Henderson { 4002b1e2af57SRichard Henderson return do_fmpyadd_s(ctx, a, false); 4003b1e2af57SRichard Henderson } 4004b1e2af57SRichard Henderson 4005b1e2af57SRichard Henderson static bool trans_fmpysub_f(DisasContext *ctx, arg_mpyadd *a) 4006b1e2af57SRichard Henderson { 4007b1e2af57SRichard Henderson return do_fmpyadd_s(ctx, a, true); 4008b1e2af57SRichard Henderson } 4009b1e2af57SRichard Henderson 4010b1e2af57SRichard Henderson static bool do_fmpyadd_d(DisasContext *ctx, arg_mpyadd *a, bool is_sub) 4011b1e2af57SRichard Henderson { 4012b1e2af57SRichard Henderson nullify_over(ctx); 4013b1e2af57SRichard Henderson 4014b1e2af57SRichard Henderson do_fop_dedd(ctx, a->tm, a->rm1, a->rm2, gen_helper_fmpy_d); 4015b1e2af57SRichard Henderson do_fop_dedd(ctx, a->ta, a->ta, a->ra, 4016b1e2af57SRichard Henderson is_sub ? gen_helper_fsub_d : gen_helper_fadd_d); 4017b1e2af57SRichard Henderson 4018b1e2af57SRichard Henderson return nullify_end(ctx); 4019b1e2af57SRichard Henderson } 4020b1e2af57SRichard Henderson 4021b1e2af57SRichard Henderson static bool trans_fmpyadd_d(DisasContext *ctx, arg_mpyadd *a) 4022b1e2af57SRichard Henderson { 4023b1e2af57SRichard Henderson return do_fmpyadd_d(ctx, a, false); 4024b1e2af57SRichard Henderson } 4025b1e2af57SRichard Henderson 4026b1e2af57SRichard Henderson static bool trans_fmpysub_d(DisasContext *ctx, arg_mpyadd *a) 4027b1e2af57SRichard Henderson { 4028b1e2af57SRichard Henderson return do_fmpyadd_d(ctx, a, true); 4029b1e2af57SRichard Henderson } 4030b1e2af57SRichard Henderson 4031c3bad4f8SRichard Henderson static bool trans_fmpyfadd_f(DisasContext *ctx, arg_fmpyfadd_f *a) 4032ebe9383cSRichard Henderson { 4033c3bad4f8SRichard Henderson TCGv_i32 x, y, z; 4034ebe9383cSRichard Henderson 4035ebe9383cSRichard Henderson nullify_over(ctx); 4036c3bad4f8SRichard Henderson x = load_frw0_i32(a->rm1); 4037c3bad4f8SRichard Henderson y = load_frw0_i32(a->rm2); 4038c3bad4f8SRichard Henderson z = load_frw0_i32(a->ra3); 4039ebe9383cSRichard Henderson 4040c3bad4f8SRichard Henderson if (a->neg) { 4041ad75a51eSRichard Henderson gen_helper_fmpynfadd_s(x, tcg_env, x, y, z); 4042ebe9383cSRichard Henderson } else { 4043ad75a51eSRichard Henderson gen_helper_fmpyfadd_s(x, tcg_env, x, y, z); 4044ebe9383cSRichard Henderson } 4045ebe9383cSRichard Henderson 4046c3bad4f8SRichard Henderson save_frw_i32(a->t, x); 404731234768SRichard Henderson return nullify_end(ctx); 4048ebe9383cSRichard Henderson } 4049ebe9383cSRichard Henderson 4050c3bad4f8SRichard Henderson static bool trans_fmpyfadd_d(DisasContext *ctx, arg_fmpyfadd_d *a) 4051ebe9383cSRichard Henderson { 4052c3bad4f8SRichard Henderson TCGv_i64 x, y, z; 4053ebe9383cSRichard Henderson 4054ebe9383cSRichard Henderson nullify_over(ctx); 4055c3bad4f8SRichard Henderson x = load_frd0(a->rm1); 4056c3bad4f8SRichard Henderson y = load_frd0(a->rm2); 4057c3bad4f8SRichard Henderson z = load_frd0(a->ra3); 4058ebe9383cSRichard Henderson 4059c3bad4f8SRichard Henderson if (a->neg) { 4060ad75a51eSRichard Henderson gen_helper_fmpynfadd_d(x, tcg_env, x, y, z); 4061ebe9383cSRichard Henderson } else { 4062ad75a51eSRichard Henderson gen_helper_fmpyfadd_d(x, tcg_env, x, y, z); 4063ebe9383cSRichard Henderson } 4064ebe9383cSRichard Henderson 4065c3bad4f8SRichard Henderson save_frd(a->t, x); 406631234768SRichard Henderson return nullify_end(ctx); 4067ebe9383cSRichard Henderson } 4068ebe9383cSRichard Henderson 406915da177bSSven Schnelle static bool trans_diag(DisasContext *ctx, arg_diag *a) 407015da177bSSven Schnelle { 4071cf6b28d4SHelge Deller CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); 4072cf6b28d4SHelge Deller #ifndef CONFIG_USER_ONLY 4073cf6b28d4SHelge Deller if (a->i == 0x100) { 4074cf6b28d4SHelge Deller /* emulate PDC BTLB, called by SeaBIOS-hppa */ 4075ad75a51eSRichard Henderson nullify_over(ctx); 4076ad75a51eSRichard Henderson gen_helper_diag_btlb(tcg_env); 4077cf6b28d4SHelge Deller return nullify_end(ctx); 407815da177bSSven Schnelle } 4079ad75a51eSRichard Henderson #endif 4080ad75a51eSRichard Henderson qemu_log_mask(LOG_UNIMP, "DIAG opcode 0x%04x ignored\n", a->i); 4081ad75a51eSRichard Henderson return true; 4082ad75a51eSRichard Henderson } 408315da177bSSven Schnelle 4084b542683dSEmilio G. Cota static void hppa_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) 408561766fe9SRichard Henderson { 408651b061fbSRichard Henderson DisasContext *ctx = container_of(dcbase, DisasContext, base); 4087f764718dSRichard Henderson int bound; 408861766fe9SRichard Henderson 408951b061fbSRichard Henderson ctx->cs = cs; 4090494737b7SRichard Henderson ctx->tb_flags = ctx->base.tb->flags; 40913d68ee7bSRichard Henderson 40923d68ee7bSRichard Henderson #ifdef CONFIG_USER_ONLY 4093c01e5dfbSHelge Deller ctx->privilege = MMU_IDX_TO_PRIV(MMU_USER_IDX); 40943d68ee7bSRichard Henderson ctx->mmu_idx = MMU_USER_IDX; 4095c01e5dfbSHelge Deller ctx->iaoq_f = ctx->base.pc_first | ctx->privilege; 4096c01e5dfbSHelge Deller ctx->iaoq_b = ctx->base.tb->cs_base | ctx->privilege; 4097217d1a5eSRichard Henderson ctx->unalign = (ctx->tb_flags & TB_FLAG_UNALIGN ? MO_UNALN : MO_ALIGN); 4098c301f34eSRichard Henderson #else 4099494737b7SRichard Henderson ctx->privilege = (ctx->tb_flags >> TB_FLAG_PRIV_SHIFT) & 3; 4100bb67ec32SRichard Henderson ctx->mmu_idx = (ctx->tb_flags & PSW_D 4101bb67ec32SRichard Henderson ? PRIV_P_TO_MMU_IDX(ctx->privilege, ctx->tb_flags & PSW_P) 4102bb67ec32SRichard Henderson : MMU_PHYS_IDX); 41033d68ee7bSRichard Henderson 4104c301f34eSRichard Henderson /* Recover the IAOQ values from the GVA + PRIV. */ 4105c301f34eSRichard Henderson uint64_t cs_base = ctx->base.tb->cs_base; 4106c301f34eSRichard Henderson uint64_t iasq_f = cs_base & ~0xffffffffull; 4107c301f34eSRichard Henderson int32_t diff = cs_base; 4108c301f34eSRichard Henderson 4109c301f34eSRichard Henderson ctx->iaoq_f = (ctx->base.pc_first & ~iasq_f) + ctx->privilege; 4110c301f34eSRichard Henderson ctx->iaoq_b = (diff ? ctx->iaoq_f + diff : -1); 4111c301f34eSRichard Henderson #endif 411251b061fbSRichard Henderson ctx->iaoq_n = -1; 4113f764718dSRichard Henderson ctx->iaoq_n_var = NULL; 411461766fe9SRichard Henderson 41153d68ee7bSRichard Henderson /* Bound the number of instructions by those left on the page. */ 41163d68ee7bSRichard Henderson bound = -(ctx->base.pc_first | TARGET_PAGE_MASK) / 4; 4117b542683dSEmilio G. Cota ctx->base.max_insns = MIN(ctx->base.max_insns, bound); 411861766fe9SRichard Henderson } 411961766fe9SRichard Henderson 412051b061fbSRichard Henderson static void hppa_tr_tb_start(DisasContextBase *dcbase, CPUState *cs) 412151b061fbSRichard Henderson { 412251b061fbSRichard Henderson DisasContext *ctx = container_of(dcbase, DisasContext, base); 412361766fe9SRichard Henderson 41243d68ee7bSRichard Henderson /* Seed the nullification status from PSW[N], as saved in TB->FLAGS. */ 412551b061fbSRichard Henderson ctx->null_cond = cond_make_f(); 412651b061fbSRichard Henderson ctx->psw_n_nonzero = false; 4127494737b7SRichard Henderson if (ctx->tb_flags & PSW_N) { 412851b061fbSRichard Henderson ctx->null_cond.c = TCG_COND_ALWAYS; 412951b061fbSRichard Henderson ctx->psw_n_nonzero = true; 4130129e9cc3SRichard Henderson } 413151b061fbSRichard Henderson ctx->null_lab = NULL; 413261766fe9SRichard Henderson } 413361766fe9SRichard Henderson 413451b061fbSRichard Henderson static void hppa_tr_insn_start(DisasContextBase *dcbase, CPUState *cs) 413551b061fbSRichard Henderson { 413651b061fbSRichard Henderson DisasContext *ctx = container_of(dcbase, DisasContext, base); 413751b061fbSRichard Henderson 413851b061fbSRichard Henderson tcg_gen_insn_start(ctx->iaoq_f, ctx->iaoq_b); 413951b061fbSRichard Henderson } 414051b061fbSRichard Henderson 414151b061fbSRichard Henderson static void hppa_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) 414251b061fbSRichard Henderson { 414351b061fbSRichard Henderson DisasContext *ctx = container_of(dcbase, DisasContext, base); 4144b77af26eSRichard Henderson CPUHPPAState *env = cpu_env(cs); 414551b061fbSRichard Henderson DisasJumpType ret; 414651b061fbSRichard Henderson 414751b061fbSRichard Henderson /* Execute one insn. */ 4148ba1d0b44SRichard Henderson #ifdef CONFIG_USER_ONLY 4149c301f34eSRichard Henderson if (ctx->base.pc_next < TARGET_PAGE_SIZE) { 415031234768SRichard Henderson do_page_zero(ctx); 415131234768SRichard Henderson ret = ctx->base.is_jmp; 4152869051eaSRichard Henderson assert(ret != DISAS_NEXT); 4153ba1d0b44SRichard Henderson } else 4154ba1d0b44SRichard Henderson #endif 4155ba1d0b44SRichard Henderson { 415661766fe9SRichard Henderson /* Always fetch the insn, even if nullified, so that we check 415761766fe9SRichard Henderson the page permissions for execute. */ 41584e116893SIlya Leoshkevich uint32_t insn = translator_ldl(env, &ctx->base, ctx->base.pc_next); 415961766fe9SRichard Henderson 416061766fe9SRichard Henderson /* Set up the IA queue for the next insn. 416161766fe9SRichard Henderson This will be overwritten by a branch. */ 416251b061fbSRichard Henderson if (ctx->iaoq_b == -1) { 416351b061fbSRichard Henderson ctx->iaoq_n = -1; 4164e12c6309SRichard Henderson ctx->iaoq_n_var = tcg_temp_new(); 4165eaa3783bSRichard Henderson tcg_gen_addi_reg(ctx->iaoq_n_var, cpu_iaoq_b, 4); 416661766fe9SRichard Henderson } else { 416751b061fbSRichard Henderson ctx->iaoq_n = ctx->iaoq_b + 4; 4168f764718dSRichard Henderson ctx->iaoq_n_var = NULL; 416961766fe9SRichard Henderson } 417061766fe9SRichard Henderson 417151b061fbSRichard Henderson if (unlikely(ctx->null_cond.c == TCG_COND_ALWAYS)) { 417251b061fbSRichard Henderson ctx->null_cond.c = TCG_COND_NEVER; 4173869051eaSRichard Henderson ret = DISAS_NEXT; 4174129e9cc3SRichard Henderson } else { 41751a19da0dSRichard Henderson ctx->insn = insn; 417631274b46SRichard Henderson if (!decode(ctx, insn)) { 417731274b46SRichard Henderson gen_illegal(ctx); 417831274b46SRichard Henderson } 417931234768SRichard Henderson ret = ctx->base.is_jmp; 418051b061fbSRichard Henderson assert(ctx->null_lab == NULL); 4181129e9cc3SRichard Henderson } 418261766fe9SRichard Henderson } 418361766fe9SRichard Henderson 41843d68ee7bSRichard Henderson /* Advance the insn queue. Note that this check also detects 41853d68ee7bSRichard Henderson a priority change within the instruction queue. */ 418651b061fbSRichard Henderson if (ret == DISAS_NEXT && ctx->iaoq_b != ctx->iaoq_f + 4) { 4187c301f34eSRichard Henderson if (ctx->iaoq_b != -1 && ctx->iaoq_n != -1 4188c301f34eSRichard Henderson && use_goto_tb(ctx, ctx->iaoq_b) 4189c301f34eSRichard Henderson && (ctx->null_cond.c == TCG_COND_NEVER 4190c301f34eSRichard Henderson || ctx->null_cond.c == TCG_COND_ALWAYS)) { 419151b061fbSRichard Henderson nullify_set(ctx, ctx->null_cond.c == TCG_COND_ALWAYS); 419251b061fbSRichard Henderson gen_goto_tb(ctx, 0, ctx->iaoq_b, ctx->iaoq_n); 419331234768SRichard Henderson ctx->base.is_jmp = ret = DISAS_NORETURN; 4194129e9cc3SRichard Henderson } else { 419531234768SRichard Henderson ctx->base.is_jmp = ret = DISAS_IAQ_N_STALE; 419661766fe9SRichard Henderson } 4197129e9cc3SRichard Henderson } 419851b061fbSRichard Henderson ctx->iaoq_f = ctx->iaoq_b; 419951b061fbSRichard Henderson ctx->iaoq_b = ctx->iaoq_n; 4200c301f34eSRichard Henderson ctx->base.pc_next += 4; 420161766fe9SRichard Henderson 4202c5d0aec2SRichard Henderson switch (ret) { 4203c5d0aec2SRichard Henderson case DISAS_NORETURN: 4204c5d0aec2SRichard Henderson case DISAS_IAQ_N_UPDATED: 4205c5d0aec2SRichard Henderson break; 4206c5d0aec2SRichard Henderson 4207c5d0aec2SRichard Henderson case DISAS_NEXT: 4208c5d0aec2SRichard Henderson case DISAS_IAQ_N_STALE: 4209c5d0aec2SRichard Henderson case DISAS_IAQ_N_STALE_EXIT: 421051b061fbSRichard Henderson if (ctx->iaoq_f == -1) { 4211eaa3783bSRichard Henderson tcg_gen_mov_reg(cpu_iaoq_f, cpu_iaoq_b); 421251b061fbSRichard Henderson copy_iaoq_entry(cpu_iaoq_b, ctx->iaoq_n, ctx->iaoq_n_var); 4213c301f34eSRichard Henderson #ifndef CONFIG_USER_ONLY 4214c301f34eSRichard Henderson tcg_gen_mov_i64(cpu_iasq_f, cpu_iasq_b); 4215c301f34eSRichard Henderson #endif 421651b061fbSRichard Henderson nullify_save(ctx); 4217c5d0aec2SRichard Henderson ctx->base.is_jmp = (ret == DISAS_IAQ_N_STALE_EXIT 4218c5d0aec2SRichard Henderson ? DISAS_EXIT 4219c5d0aec2SRichard Henderson : DISAS_IAQ_N_UPDATED); 422051b061fbSRichard Henderson } else if (ctx->iaoq_b == -1) { 4221eaa3783bSRichard Henderson tcg_gen_mov_reg(cpu_iaoq_b, ctx->iaoq_n_var); 422261766fe9SRichard Henderson } 4223c5d0aec2SRichard Henderson break; 4224c5d0aec2SRichard Henderson 4225c5d0aec2SRichard Henderson default: 4226c5d0aec2SRichard Henderson g_assert_not_reached(); 4227c5d0aec2SRichard Henderson } 422861766fe9SRichard Henderson } 422961766fe9SRichard Henderson 423051b061fbSRichard Henderson static void hppa_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs) 423151b061fbSRichard Henderson { 423251b061fbSRichard Henderson DisasContext *ctx = container_of(dcbase, DisasContext, base); 4233e1b5a5edSRichard Henderson DisasJumpType is_jmp = ctx->base.is_jmp; 423451b061fbSRichard Henderson 4235e1b5a5edSRichard Henderson switch (is_jmp) { 4236869051eaSRichard Henderson case DISAS_NORETURN: 423761766fe9SRichard Henderson break; 423851b061fbSRichard Henderson case DISAS_TOO_MANY: 4239869051eaSRichard Henderson case DISAS_IAQ_N_STALE: 4240e1b5a5edSRichard Henderson case DISAS_IAQ_N_STALE_EXIT: 424151b061fbSRichard Henderson copy_iaoq_entry(cpu_iaoq_f, ctx->iaoq_f, cpu_iaoq_f); 424251b061fbSRichard Henderson copy_iaoq_entry(cpu_iaoq_b, ctx->iaoq_b, cpu_iaoq_b); 424351b061fbSRichard Henderson nullify_save(ctx); 424461766fe9SRichard Henderson /* FALLTHRU */ 4245869051eaSRichard Henderson case DISAS_IAQ_N_UPDATED: 42468532a14eSRichard Henderson if (is_jmp != DISAS_IAQ_N_STALE_EXIT) { 42477f11636dSEmilio G. Cota tcg_gen_lookup_and_goto_ptr(); 42488532a14eSRichard Henderson break; 424961766fe9SRichard Henderson } 4250c5d0aec2SRichard Henderson /* FALLTHRU */ 4251c5d0aec2SRichard Henderson case DISAS_EXIT: 4252c5d0aec2SRichard Henderson tcg_gen_exit_tb(NULL, 0); 425361766fe9SRichard Henderson break; 425461766fe9SRichard Henderson default: 425551b061fbSRichard Henderson g_assert_not_reached(); 425661766fe9SRichard Henderson } 425751b061fbSRichard Henderson } 425861766fe9SRichard Henderson 42598eb806a7SRichard Henderson static void hppa_tr_disas_log(const DisasContextBase *dcbase, 42608eb806a7SRichard Henderson CPUState *cs, FILE *logfile) 426151b061fbSRichard Henderson { 4262c301f34eSRichard Henderson target_ulong pc = dcbase->pc_first; 426361766fe9SRichard Henderson 4264ba1d0b44SRichard Henderson #ifdef CONFIG_USER_ONLY 4265ba1d0b44SRichard Henderson switch (pc) { 42667ad439dfSRichard Henderson case 0x00: 42678eb806a7SRichard Henderson fprintf(logfile, "IN:\n0x00000000: (null)\n"); 4268ba1d0b44SRichard Henderson return; 42697ad439dfSRichard Henderson case 0xb0: 42708eb806a7SRichard Henderson fprintf(logfile, "IN:\n0x000000b0: light-weight-syscall\n"); 4271ba1d0b44SRichard Henderson return; 42727ad439dfSRichard Henderson case 0xe0: 42738eb806a7SRichard Henderson fprintf(logfile, "IN:\n0x000000e0: set-thread-pointer-syscall\n"); 4274ba1d0b44SRichard Henderson return; 42757ad439dfSRichard Henderson case 0x100: 42768eb806a7SRichard Henderson fprintf(logfile, "IN:\n0x00000100: syscall\n"); 4277ba1d0b44SRichard Henderson return; 42787ad439dfSRichard Henderson } 4279ba1d0b44SRichard Henderson #endif 4280ba1d0b44SRichard Henderson 42818eb806a7SRichard Henderson fprintf(logfile, "IN: %s\n", lookup_symbol(pc)); 42828eb806a7SRichard Henderson target_disas(logfile, cs, pc, dcbase->tb->size); 428361766fe9SRichard Henderson } 428451b061fbSRichard Henderson 428551b061fbSRichard Henderson static const TranslatorOps hppa_tr_ops = { 428651b061fbSRichard Henderson .init_disas_context = hppa_tr_init_disas_context, 428751b061fbSRichard Henderson .tb_start = hppa_tr_tb_start, 428851b061fbSRichard Henderson .insn_start = hppa_tr_insn_start, 428951b061fbSRichard Henderson .translate_insn = hppa_tr_translate_insn, 429051b061fbSRichard Henderson .tb_stop = hppa_tr_tb_stop, 429151b061fbSRichard Henderson .disas_log = hppa_tr_disas_log, 429251b061fbSRichard Henderson }; 429351b061fbSRichard Henderson 4294597f9b2dSRichard Henderson void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int *max_insns, 4295306c8721SRichard Henderson target_ulong pc, void *host_pc) 429651b061fbSRichard Henderson { 429751b061fbSRichard Henderson DisasContext ctx; 4298306c8721SRichard Henderson translator_loop(cs, tb, max_insns, pc, host_pc, &hppa_tr_ops, &ctx.base); 429961766fe9SRichard Henderson } 4300