1fcf5ef2aSThomas Huth /* 2fcf5ef2aSThomas Huth SPARC translation 3fcf5ef2aSThomas Huth 4fcf5ef2aSThomas Huth Copyright (C) 2003 Thomas M. Ogrisegg <tom@fnord.at> 5fcf5ef2aSThomas Huth Copyright (C) 2003-2005 Fabrice Bellard 6fcf5ef2aSThomas Huth 7fcf5ef2aSThomas Huth This library is free software; you can redistribute it and/or 8fcf5ef2aSThomas Huth modify it under the terms of the GNU Lesser General Public 9fcf5ef2aSThomas Huth License as published by the Free Software Foundation; either 105650b549SChetan Pant version 2.1 of the License, or (at your option) any later version. 11fcf5ef2aSThomas Huth 12fcf5ef2aSThomas Huth This library is distributed in the hope that it will be useful, 13fcf5ef2aSThomas Huth but WITHOUT ANY WARRANTY; without even the implied warranty of 14fcf5ef2aSThomas Huth MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15fcf5ef2aSThomas Huth Lesser General Public License for more details. 16fcf5ef2aSThomas Huth 17fcf5ef2aSThomas Huth You should have received a copy of the GNU Lesser General Public 18fcf5ef2aSThomas Huth License along with this library; if not, see <http://www.gnu.org/licenses/>. 19fcf5ef2aSThomas Huth */ 20fcf5ef2aSThomas Huth 21fcf5ef2aSThomas Huth #include "qemu/osdep.h" 22fcf5ef2aSThomas Huth 23fcf5ef2aSThomas Huth #include "cpu.h" 24fcf5ef2aSThomas Huth #include "disas/disas.h" 25fcf5ef2aSThomas Huth #include "exec/helper-proto.h" 26fcf5ef2aSThomas Huth #include "exec/exec-all.h" 27dcb32f1dSPhilippe Mathieu-Daudé #include "tcg/tcg-op.h" 28fafba1bbSRichard Henderson #include "tcg/tcg-op-gvec.h" 29fcf5ef2aSThomas Huth #include "exec/helper-gen.h" 30c5e6ccdfSEmilio G. Cota #include "exec/translator.h" 31fcf5ef2aSThomas Huth #include "exec/log.h" 32fcf5ef2aSThomas Huth #include "asi.h" 33fcf5ef2aSThomas Huth 34d53106c9SRichard Henderson #define HELPER_H "helper.h" 35d53106c9SRichard Henderson #include "exec/helper-info.c.inc" 36d53106c9SRichard Henderson #undef HELPER_H 37fcf5ef2aSThomas Huth 38668bb9b7SRichard Henderson #ifdef TARGET_SPARC64 39668bb9b7SRichard Henderson # define gen_helper_rdpsr(D, E) qemu_build_not_reached() 4086b82fe0SRichard Henderson # define gen_helper_rett(E) qemu_build_not_reached() 410faef01bSRichard Henderson # define gen_helper_power_down(E) qemu_build_not_reached() 4225524734SRichard Henderson # define gen_helper_wrpsr(E, S) qemu_build_not_reached() 43668bb9b7SRichard Henderson #else 440faef01bSRichard Henderson # define gen_helper_clear_softint(E, S) qemu_build_not_reached() 458f75b8a4SRichard Henderson # define gen_helper_done(E) qemu_build_not_reached() 46e8325dc0SRichard Henderson # define gen_helper_flushw(E) qemu_build_not_reached() 47af25071cSRichard Henderson # define gen_helper_rdccr(D, E) qemu_build_not_reached() 485d617bfbSRichard Henderson # define gen_helper_rdcwp(D, E) qemu_build_not_reached() 4925524734SRichard Henderson # define gen_helper_restored(E) qemu_build_not_reached() 508f75b8a4SRichard Henderson # define gen_helper_retry(E) qemu_build_not_reached() 5125524734SRichard Henderson # define gen_helper_saved(E) qemu_build_not_reached() 520faef01bSRichard Henderson # define gen_helper_set_softint(E, S) qemu_build_not_reached() 53af25071cSRichard Henderson # define gen_helper_tick_get_count(D, E, T, C) qemu_build_not_reached() 549422278eSRichard Henderson # define gen_helper_tick_set_count(P, S) qemu_build_not_reached() 55bb97f2f5SRichard Henderson # define gen_helper_tick_set_limit(P, S) qemu_build_not_reached() 560faef01bSRichard Henderson # define gen_helper_wrccr(E, S) qemu_build_not_reached() 579422278eSRichard Henderson # define gen_helper_wrcwp(E, S) qemu_build_not_reached() 589422278eSRichard Henderson # define gen_helper_wrgl(E, S) qemu_build_not_reached() 590faef01bSRichard Henderson # define gen_helper_write_softint(E, S) qemu_build_not_reached() 609422278eSRichard Henderson # define gen_helper_wrpil(E, S) qemu_build_not_reached() 619422278eSRichard Henderson # define gen_helper_wrpstate(E, S) qemu_build_not_reached() 62e2fa6bd1SRichard Henderson # define gen_helper_fcmpeq16 ({ qemu_build_not_reached(); NULL; }) 63e2fa6bd1SRichard Henderson # define gen_helper_fcmpeq32 ({ qemu_build_not_reached(); NULL; }) 64e2fa6bd1SRichard Henderson # define gen_helper_fcmpgt16 ({ qemu_build_not_reached(); NULL; }) 65e2fa6bd1SRichard Henderson # define gen_helper_fcmpgt32 ({ qemu_build_not_reached(); NULL; }) 66e2fa6bd1SRichard Henderson # define gen_helper_fcmple16 ({ qemu_build_not_reached(); NULL; }) 67e2fa6bd1SRichard Henderson # define gen_helper_fcmple32 ({ qemu_build_not_reached(); NULL; }) 68e2fa6bd1SRichard Henderson # define gen_helper_fcmpne16 ({ qemu_build_not_reached(); NULL; }) 69e2fa6bd1SRichard Henderson # define gen_helper_fcmpne32 ({ qemu_build_not_reached(); NULL; }) 708aa418b3SRichard Henderson # define gen_helper_fdtox ({ qemu_build_not_reached(); NULL; }) 71e06c9f83SRichard Henderson # define gen_helper_fexpand ({ qemu_build_not_reached(); NULL; }) 72e06c9f83SRichard Henderson # define gen_helper_fmul8sux16 ({ qemu_build_not_reached(); NULL; }) 73e06c9f83SRichard Henderson # define gen_helper_fmul8ulx16 ({ qemu_build_not_reached(); NULL; }) 74e06c9f83SRichard Henderson # define gen_helper_fmul8x16al ({ qemu_build_not_reached(); NULL; }) 75e06c9f83SRichard Henderson # define gen_helper_fmul8x16au ({ qemu_build_not_reached(); NULL; }) 76e06c9f83SRichard Henderson # define gen_helper_fmul8x16 ({ qemu_build_not_reached(); NULL; }) 77e06c9f83SRichard Henderson # define gen_helper_fmuld8sux16 ({ qemu_build_not_reached(); NULL; }) 78e06c9f83SRichard Henderson # define gen_helper_fmuld8ulx16 ({ qemu_build_not_reached(); NULL; }) 79e06c9f83SRichard Henderson # define gen_helper_fpmerge ({ qemu_build_not_reached(); NULL; }) 801617586fSRichard Henderson # define gen_helper_fqtox ({ qemu_build_not_reached(); NULL; }) 81199d43efSRichard Henderson # define gen_helper_fstox ({ qemu_build_not_reached(); NULL; }) 828aa418b3SRichard Henderson # define gen_helper_fxtod ({ qemu_build_not_reached(); NULL; }) 837b8e3e1aSRichard Henderson # define gen_helper_fxtoq ({ qemu_build_not_reached(); NULL; }) 84f4e18df5SRichard Henderson # define gen_helper_fxtos ({ qemu_build_not_reached(); NULL; }) 85afb04344SRichard Henderson # define gen_helper_pdist ({ qemu_build_not_reached(); NULL; }) 86da681406SRichard Henderson # define FSR_LDXFSR_MASK 0 87da681406SRichard Henderson # define FSR_LDXFSR_OLDMASK 0 88668bb9b7SRichard Henderson # define MAXTL_MASK 0 89af25071cSRichard Henderson #endif 90af25071cSRichard Henderson 91633c4283SRichard Henderson /* Dynamic PC, must exit to main loop. */ 92633c4283SRichard Henderson #define DYNAMIC_PC 1 93633c4283SRichard Henderson /* Dynamic PC, one of two values according to jump_pc[T2]. */ 94633c4283SRichard Henderson #define JUMP_PC 2 95633c4283SRichard Henderson /* Dynamic PC, may lookup next TB. */ 96633c4283SRichard Henderson #define DYNAMIC_PC_LOOKUP 3 97fcf5ef2aSThomas Huth 9846bb0137SMark Cave-Ayland #define DISAS_EXIT DISAS_TARGET_0 9946bb0137SMark Cave-Ayland 100fcf5ef2aSThomas Huth /* global register indexes */ 101fcf5ef2aSThomas Huth static TCGv_ptr cpu_regwptr; 102fcf5ef2aSThomas Huth static TCGv cpu_fsr, cpu_pc, cpu_npc; 103fcf5ef2aSThomas Huth static TCGv cpu_regs[32]; 104fcf5ef2aSThomas Huth static TCGv cpu_y; 105fcf5ef2aSThomas Huth static TCGv cpu_tbr; 106fcf5ef2aSThomas Huth static TCGv cpu_cond; 1072a1905c7SRichard Henderson static TCGv cpu_cc_N; 1082a1905c7SRichard Henderson static TCGv cpu_cc_V; 1092a1905c7SRichard Henderson static TCGv cpu_icc_Z; 1102a1905c7SRichard Henderson static TCGv cpu_icc_C; 111fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64 1122a1905c7SRichard Henderson static TCGv cpu_xcc_Z; 1132a1905c7SRichard Henderson static TCGv cpu_xcc_C; 1142a1905c7SRichard Henderson static TCGv_i32 cpu_fprs; 115fcf5ef2aSThomas Huth static TCGv cpu_gsr; 116fcf5ef2aSThomas Huth #else 117af25071cSRichard Henderson # define cpu_fprs ({ qemu_build_not_reached(); (TCGv)NULL; }) 118af25071cSRichard Henderson # define cpu_gsr ({ qemu_build_not_reached(); (TCGv)NULL; }) 119fcf5ef2aSThomas Huth #endif 1202a1905c7SRichard Henderson 1212a1905c7SRichard Henderson #ifdef TARGET_SPARC64 1222a1905c7SRichard Henderson #define cpu_cc_Z cpu_xcc_Z 1232a1905c7SRichard Henderson #define cpu_cc_C cpu_xcc_C 1242a1905c7SRichard Henderson #else 1252a1905c7SRichard Henderson #define cpu_cc_Z cpu_icc_Z 1262a1905c7SRichard Henderson #define cpu_cc_C cpu_icc_C 1272a1905c7SRichard Henderson #define cpu_xcc_Z ({ qemu_build_not_reached(); NULL; }) 1282a1905c7SRichard Henderson #define cpu_xcc_C ({ qemu_build_not_reached(); NULL; }) 1292a1905c7SRichard Henderson #endif 1302a1905c7SRichard Henderson 131fcf5ef2aSThomas Huth /* Floating point registers */ 132fcf5ef2aSThomas Huth static TCGv_i64 cpu_fpr[TARGET_DPREGS]; 133fcf5ef2aSThomas Huth 134af25071cSRichard Henderson #define env_field_offsetof(X) offsetof(CPUSPARCState, X) 135af25071cSRichard Henderson #ifdef TARGET_SPARC64 136cd6269f7SRichard Henderson # define env32_field_offsetof(X) ({ qemu_build_not_reached(); 0; }) 137af25071cSRichard Henderson # define env64_field_offsetof(X) env_field_offsetof(X) 138af25071cSRichard Henderson #else 139cd6269f7SRichard Henderson # define env32_field_offsetof(X) env_field_offsetof(X) 140af25071cSRichard Henderson # define env64_field_offsetof(X) ({ qemu_build_not_reached(); 0; }) 141af25071cSRichard Henderson #endif 142af25071cSRichard Henderson 143533f042fSRichard Henderson typedef struct DisasCompare { 144533f042fSRichard Henderson TCGCond cond; 145533f042fSRichard Henderson TCGv c1; 146533f042fSRichard Henderson int c2; 147533f042fSRichard Henderson } DisasCompare; 148533f042fSRichard Henderson 149186e7890SRichard Henderson typedef struct DisasDelayException { 150186e7890SRichard Henderson struct DisasDelayException *next; 151186e7890SRichard Henderson TCGLabel *lab; 152186e7890SRichard Henderson TCGv_i32 excp; 153186e7890SRichard Henderson /* Saved state at parent insn. */ 154186e7890SRichard Henderson target_ulong pc; 155186e7890SRichard Henderson target_ulong npc; 156186e7890SRichard Henderson } DisasDelayException; 157186e7890SRichard Henderson 158fcf5ef2aSThomas Huth typedef struct DisasContext { 159af00be49SEmilio G. Cota DisasContextBase base; 160fcf5ef2aSThomas Huth target_ulong pc; /* current Program Counter: integer or DYNAMIC_PC */ 161fcf5ef2aSThomas Huth target_ulong npc; /* next PC: integer or DYNAMIC_PC or JUMP_PC */ 162533f042fSRichard Henderson 163533f042fSRichard Henderson /* Used when JUMP_PC value is used. */ 164533f042fSRichard Henderson DisasCompare jump; 165533f042fSRichard Henderson target_ulong jump_pc[2]; 166533f042fSRichard Henderson 167fcf5ef2aSThomas Huth int mem_idx; 16889527e3aSRichard Henderson bool cpu_cond_live; 169c9b459aaSArtyom Tarasenko bool fpu_enabled; 170c9b459aaSArtyom Tarasenko bool address_mask_32bit; 171c9b459aaSArtyom Tarasenko #ifndef CONFIG_USER_ONLY 172c9b459aaSArtyom Tarasenko bool supervisor; 173c9b459aaSArtyom Tarasenko #ifdef TARGET_SPARC64 174c9b459aaSArtyom Tarasenko bool hypervisor; 175c9b459aaSArtyom Tarasenko #endif 176c9b459aaSArtyom Tarasenko #endif 177c9b459aaSArtyom Tarasenko 178fcf5ef2aSThomas Huth sparc_def_t *def; 179fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64 180fcf5ef2aSThomas Huth int fprs_dirty; 181fcf5ef2aSThomas Huth int asi; 182fcf5ef2aSThomas Huth #endif 183186e7890SRichard Henderson DisasDelayException *delay_excp_list; 184fcf5ef2aSThomas Huth } DisasContext; 185fcf5ef2aSThomas Huth 186fcf5ef2aSThomas Huth // This function uses non-native bit order 187fcf5ef2aSThomas Huth #define GET_FIELD(X, FROM, TO) \ 188fcf5ef2aSThomas Huth ((X) >> (31 - (TO)) & ((1 << ((TO) - (FROM) + 1)) - 1)) 189fcf5ef2aSThomas Huth 190fcf5ef2aSThomas Huth // This function uses the order in the manuals, i.e. bit 0 is 2^0 191fcf5ef2aSThomas Huth #define GET_FIELD_SP(X, FROM, TO) \ 192fcf5ef2aSThomas Huth GET_FIELD(X, 31 - (TO), 31 - (FROM)) 193fcf5ef2aSThomas Huth 194fcf5ef2aSThomas Huth #define GET_FIELDs(x,a,b) sign_extend (GET_FIELD(x,a,b), (b) - (a) + 1) 195fcf5ef2aSThomas Huth #define GET_FIELD_SPs(x,a,b) sign_extend (GET_FIELD_SP(x,a,b), ((b) - (a) + 1)) 196fcf5ef2aSThomas Huth 197fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64 198fcf5ef2aSThomas Huth #define DFPREG(r) (((r & 1) << 5) | (r & 0x1e)) 199fcf5ef2aSThomas Huth #define QFPREG(r) (((r & 1) << 5) | (r & 0x1c)) 200fcf5ef2aSThomas Huth #else 201fcf5ef2aSThomas Huth #define DFPREG(r) (r & 0x1e) 202fcf5ef2aSThomas Huth #define QFPREG(r) (r & 0x1c) 203fcf5ef2aSThomas Huth #endif 204fcf5ef2aSThomas Huth 205fcf5ef2aSThomas Huth #define UA2005_HTRAP_MASK 0xff 206fcf5ef2aSThomas Huth #define V8_TRAP_MASK 0x7f 207fcf5ef2aSThomas Huth 208fcf5ef2aSThomas Huth #define IS_IMM (insn & (1<<13)) 209fcf5ef2aSThomas Huth 2100c2e96c1SRichard Henderson static void gen_update_fprs_dirty(DisasContext *dc, int rd) 211fcf5ef2aSThomas Huth { 212fcf5ef2aSThomas Huth #if defined(TARGET_SPARC64) 213fcf5ef2aSThomas Huth int bit = (rd < 32) ? 1 : 2; 214fcf5ef2aSThomas Huth /* If we know we've already set this bit within the TB, 215fcf5ef2aSThomas Huth we can avoid setting it again. */ 216fcf5ef2aSThomas Huth if (!(dc->fprs_dirty & bit)) { 217fcf5ef2aSThomas Huth dc->fprs_dirty |= bit; 218fcf5ef2aSThomas Huth tcg_gen_ori_i32(cpu_fprs, cpu_fprs, bit); 219fcf5ef2aSThomas Huth } 220fcf5ef2aSThomas Huth #endif 221fcf5ef2aSThomas Huth } 222fcf5ef2aSThomas Huth 223fcf5ef2aSThomas Huth /* floating point registers moves */ 224fcf5ef2aSThomas Huth static TCGv_i32 gen_load_fpr_F(DisasContext *dc, unsigned int src) 225fcf5ef2aSThomas Huth { 22636ab4623SRichard Henderson TCGv_i32 ret = tcg_temp_new_i32(); 227dc41aa7dSRichard Henderson if (src & 1) { 228dc41aa7dSRichard Henderson tcg_gen_extrl_i64_i32(ret, cpu_fpr[src / 2]); 229dc41aa7dSRichard Henderson } else { 230dc41aa7dSRichard Henderson tcg_gen_extrh_i64_i32(ret, cpu_fpr[src / 2]); 231fcf5ef2aSThomas Huth } 232dc41aa7dSRichard Henderson return ret; 233fcf5ef2aSThomas Huth } 234fcf5ef2aSThomas Huth 235fcf5ef2aSThomas Huth static void gen_store_fpr_F(DisasContext *dc, unsigned int dst, TCGv_i32 v) 236fcf5ef2aSThomas Huth { 2378e7bbc75SRichard Henderson TCGv_i64 t = tcg_temp_new_i64(); 2388e7bbc75SRichard Henderson 2398e7bbc75SRichard Henderson tcg_gen_extu_i32_i64(t, v); 240fcf5ef2aSThomas Huth tcg_gen_deposit_i64(cpu_fpr[dst / 2], cpu_fpr[dst / 2], t, 241fcf5ef2aSThomas Huth (dst & 1 ? 0 : 32), 32); 242fcf5ef2aSThomas Huth gen_update_fprs_dirty(dc, dst); 243fcf5ef2aSThomas Huth } 244fcf5ef2aSThomas Huth 245fcf5ef2aSThomas Huth static TCGv_i64 gen_load_fpr_D(DisasContext *dc, unsigned int src) 246fcf5ef2aSThomas Huth { 247fcf5ef2aSThomas Huth src = DFPREG(src); 248fcf5ef2aSThomas Huth return cpu_fpr[src / 2]; 249fcf5ef2aSThomas Huth } 250fcf5ef2aSThomas Huth 251fcf5ef2aSThomas Huth static void gen_store_fpr_D(DisasContext *dc, unsigned int dst, TCGv_i64 v) 252fcf5ef2aSThomas Huth { 253fcf5ef2aSThomas Huth dst = DFPREG(dst); 254fcf5ef2aSThomas Huth tcg_gen_mov_i64(cpu_fpr[dst / 2], v); 255fcf5ef2aSThomas Huth gen_update_fprs_dirty(dc, dst); 256fcf5ef2aSThomas Huth } 257fcf5ef2aSThomas Huth 258fcf5ef2aSThomas Huth static TCGv_i64 gen_dest_fpr_D(DisasContext *dc, unsigned int dst) 259fcf5ef2aSThomas Huth { 260fcf5ef2aSThomas Huth return cpu_fpr[DFPREG(dst) / 2]; 261fcf5ef2aSThomas Huth } 262fcf5ef2aSThomas Huth 26333ec4245SRichard Henderson static TCGv_i128 gen_load_fpr_Q(DisasContext *dc, unsigned int src) 26433ec4245SRichard Henderson { 26533ec4245SRichard Henderson TCGv_i128 ret = tcg_temp_new_i128(); 26633ec4245SRichard Henderson 26733ec4245SRichard Henderson src = QFPREG(src); 26833ec4245SRichard Henderson tcg_gen_concat_i64_i128(ret, cpu_fpr[src / 2 + 1], cpu_fpr[src / 2]); 26933ec4245SRichard Henderson return ret; 27033ec4245SRichard Henderson } 27133ec4245SRichard Henderson 27233ec4245SRichard Henderson static void gen_store_fpr_Q(DisasContext *dc, unsigned int dst, TCGv_i128 v) 27333ec4245SRichard Henderson { 27433ec4245SRichard Henderson dst = DFPREG(dst); 27533ec4245SRichard Henderson tcg_gen_extr_i128_i64(cpu_fpr[dst / 2 + 1], cpu_fpr[dst / 2], v); 27633ec4245SRichard Henderson gen_update_fprs_dirty(dc, dst); 27733ec4245SRichard Henderson } 27833ec4245SRichard Henderson 279fcf5ef2aSThomas Huth static void gen_op_load_fpr_QT0(unsigned int src) 280fcf5ef2aSThomas Huth { 281ad75a51eSRichard Henderson tcg_gen_st_i64(cpu_fpr[src / 2], tcg_env, offsetof(CPUSPARCState, qt0) + 282fcf5ef2aSThomas Huth offsetof(CPU_QuadU, ll.upper)); 283ad75a51eSRichard Henderson tcg_gen_st_i64(cpu_fpr[src/2 + 1], tcg_env, offsetof(CPUSPARCState, qt0) + 284fcf5ef2aSThomas Huth offsetof(CPU_QuadU, ll.lower)); 285fcf5ef2aSThomas Huth } 286fcf5ef2aSThomas Huth 287fcf5ef2aSThomas Huth static void gen_op_load_fpr_QT1(unsigned int src) 288fcf5ef2aSThomas Huth { 289ad75a51eSRichard Henderson tcg_gen_st_i64(cpu_fpr[src / 2], tcg_env, offsetof(CPUSPARCState, qt1) + 290fcf5ef2aSThomas Huth offsetof(CPU_QuadU, ll.upper)); 291ad75a51eSRichard Henderson tcg_gen_st_i64(cpu_fpr[src/2 + 1], tcg_env, offsetof(CPUSPARCState, qt1) + 292fcf5ef2aSThomas Huth offsetof(CPU_QuadU, ll.lower)); 293fcf5ef2aSThomas Huth } 294fcf5ef2aSThomas Huth 295fcf5ef2aSThomas Huth static void gen_op_store_QT0_fpr(unsigned int dst) 296fcf5ef2aSThomas Huth { 297ad75a51eSRichard Henderson tcg_gen_ld_i64(cpu_fpr[dst / 2], tcg_env, offsetof(CPUSPARCState, qt0) + 298fcf5ef2aSThomas Huth offsetof(CPU_QuadU, ll.upper)); 299ad75a51eSRichard Henderson tcg_gen_ld_i64(cpu_fpr[dst/2 + 1], tcg_env, offsetof(CPUSPARCState, qt0) + 300fcf5ef2aSThomas Huth offsetof(CPU_QuadU, ll.lower)); 301fcf5ef2aSThomas Huth } 302fcf5ef2aSThomas Huth 303fcf5ef2aSThomas Huth /* moves */ 304fcf5ef2aSThomas Huth #ifdef CONFIG_USER_ONLY 305fcf5ef2aSThomas Huth #define supervisor(dc) 0 306fcf5ef2aSThomas Huth #define hypervisor(dc) 0 307fcf5ef2aSThomas Huth #else 308fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64 309c9b459aaSArtyom Tarasenko #define hypervisor(dc) (dc->hypervisor) 310c9b459aaSArtyom Tarasenko #define supervisor(dc) (dc->supervisor | dc->hypervisor) 311fcf5ef2aSThomas Huth #else 312c9b459aaSArtyom Tarasenko #define supervisor(dc) (dc->supervisor) 313668bb9b7SRichard Henderson #define hypervisor(dc) 0 314fcf5ef2aSThomas Huth #endif 315fcf5ef2aSThomas Huth #endif 316fcf5ef2aSThomas Huth 317b1bc09eaSRichard Henderson #if !defined(TARGET_SPARC64) 318b1bc09eaSRichard Henderson # define AM_CHECK(dc) false 319b1bc09eaSRichard Henderson #elif defined(TARGET_ABI32) 320b1bc09eaSRichard Henderson # define AM_CHECK(dc) true 321b1bc09eaSRichard Henderson #elif defined(CONFIG_USER_ONLY) 322b1bc09eaSRichard Henderson # define AM_CHECK(dc) false 323fcf5ef2aSThomas Huth #else 324b1bc09eaSRichard Henderson # define AM_CHECK(dc) ((dc)->address_mask_32bit) 325fcf5ef2aSThomas Huth #endif 326fcf5ef2aSThomas Huth 3270c2e96c1SRichard Henderson static void gen_address_mask(DisasContext *dc, TCGv addr) 328fcf5ef2aSThomas Huth { 329b1bc09eaSRichard Henderson if (AM_CHECK(dc)) { 330fcf5ef2aSThomas Huth tcg_gen_andi_tl(addr, addr, 0xffffffffULL); 331b1bc09eaSRichard Henderson } 332fcf5ef2aSThomas Huth } 333fcf5ef2aSThomas Huth 33423ada1b1SRichard Henderson static target_ulong address_mask_i(DisasContext *dc, target_ulong addr) 33523ada1b1SRichard Henderson { 33623ada1b1SRichard Henderson return AM_CHECK(dc) ? (uint32_t)addr : addr; 33723ada1b1SRichard Henderson } 33823ada1b1SRichard Henderson 3390c2e96c1SRichard Henderson static TCGv gen_load_gpr(DisasContext *dc, int reg) 340fcf5ef2aSThomas Huth { 341fcf5ef2aSThomas Huth if (reg > 0) { 342fcf5ef2aSThomas Huth assert(reg < 32); 343fcf5ef2aSThomas Huth return cpu_regs[reg]; 344fcf5ef2aSThomas Huth } else { 34552123f14SRichard Henderson TCGv t = tcg_temp_new(); 346fcf5ef2aSThomas Huth tcg_gen_movi_tl(t, 0); 347fcf5ef2aSThomas Huth return t; 348fcf5ef2aSThomas Huth } 349fcf5ef2aSThomas Huth } 350fcf5ef2aSThomas Huth 3510c2e96c1SRichard Henderson static void gen_store_gpr(DisasContext *dc, int reg, TCGv v) 352fcf5ef2aSThomas Huth { 353fcf5ef2aSThomas Huth if (reg > 0) { 354fcf5ef2aSThomas Huth assert(reg < 32); 355fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_regs[reg], v); 356fcf5ef2aSThomas Huth } 357fcf5ef2aSThomas Huth } 358fcf5ef2aSThomas Huth 3590c2e96c1SRichard Henderson static TCGv gen_dest_gpr(DisasContext *dc, int reg) 360fcf5ef2aSThomas Huth { 361fcf5ef2aSThomas Huth if (reg > 0) { 362fcf5ef2aSThomas Huth assert(reg < 32); 363fcf5ef2aSThomas Huth return cpu_regs[reg]; 364fcf5ef2aSThomas Huth } else { 36552123f14SRichard Henderson return tcg_temp_new(); 366fcf5ef2aSThomas Huth } 367fcf5ef2aSThomas Huth } 368fcf5ef2aSThomas Huth 3695645aa2eSRichard Henderson static bool use_goto_tb(DisasContext *s, target_ulong pc, target_ulong npc) 370fcf5ef2aSThomas Huth { 3715645aa2eSRichard Henderson return translator_use_goto_tb(&s->base, pc) && 3725645aa2eSRichard Henderson translator_use_goto_tb(&s->base, npc); 373fcf5ef2aSThomas Huth } 374fcf5ef2aSThomas Huth 3755645aa2eSRichard Henderson static void gen_goto_tb(DisasContext *s, int tb_num, 376fcf5ef2aSThomas Huth target_ulong pc, target_ulong npc) 377fcf5ef2aSThomas Huth { 378fcf5ef2aSThomas Huth if (use_goto_tb(s, pc, npc)) { 379fcf5ef2aSThomas Huth /* jump to same page: we can use a direct jump */ 380fcf5ef2aSThomas Huth tcg_gen_goto_tb(tb_num); 381fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_pc, pc); 382fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_npc, npc); 38307ea28b4SRichard Henderson tcg_gen_exit_tb(s->base.tb, tb_num); 384fcf5ef2aSThomas Huth } else { 385f67ccb2fSRichard Henderson /* jump to another page: we can use an indirect jump */ 386fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_pc, pc); 387fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_npc, npc); 388f67ccb2fSRichard Henderson tcg_gen_lookup_and_goto_ptr(); 389fcf5ef2aSThomas Huth } 390fcf5ef2aSThomas Huth } 391fcf5ef2aSThomas Huth 392b989ce73SRichard Henderson static TCGv gen_carry32(void) 393fcf5ef2aSThomas Huth { 394b989ce73SRichard Henderson if (TARGET_LONG_BITS == 64) { 395b989ce73SRichard Henderson TCGv t = tcg_temp_new(); 396b989ce73SRichard Henderson tcg_gen_extract_tl(t, cpu_icc_C, 32, 1); 397b989ce73SRichard Henderson return t; 398b989ce73SRichard Henderson } 399b989ce73SRichard Henderson return cpu_icc_C; 400fcf5ef2aSThomas Huth } 401fcf5ef2aSThomas Huth 402b989ce73SRichard Henderson static void gen_op_addcc_int(TCGv dst, TCGv src1, TCGv src2, TCGv cin) 403fcf5ef2aSThomas Huth { 404b989ce73SRichard Henderson TCGv z = tcg_constant_tl(0); 405fcf5ef2aSThomas Huth 406b989ce73SRichard Henderson if (cin) { 407b989ce73SRichard Henderson tcg_gen_add2_tl(cpu_cc_N, cpu_cc_C, src1, z, cin, z); 408b989ce73SRichard Henderson tcg_gen_add2_tl(cpu_cc_N, cpu_cc_C, cpu_cc_N, cpu_cc_C, src2, z); 409b989ce73SRichard Henderson } else { 410b989ce73SRichard Henderson tcg_gen_add2_tl(cpu_cc_N, cpu_cc_C, src1, z, src2, z); 411b989ce73SRichard Henderson } 412b989ce73SRichard Henderson tcg_gen_xor_tl(cpu_cc_Z, src1, src2); 413b989ce73SRichard Henderson tcg_gen_xor_tl(cpu_cc_V, cpu_cc_N, src2); 414b989ce73SRichard Henderson tcg_gen_andc_tl(cpu_cc_V, cpu_cc_V, cpu_cc_Z); 415b989ce73SRichard Henderson if (TARGET_LONG_BITS == 64) { 416b989ce73SRichard Henderson /* 417b989ce73SRichard Henderson * Carry-in to bit 32 is result ^ src1 ^ src2. 418b989ce73SRichard Henderson * We already have the src xor term in Z, from computation of V. 419b989ce73SRichard Henderson */ 420b989ce73SRichard Henderson tcg_gen_xor_tl(cpu_icc_C, cpu_cc_Z, cpu_cc_N); 421b989ce73SRichard Henderson tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N); 422b989ce73SRichard Henderson } 423b989ce73SRichard Henderson tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N); 424b989ce73SRichard Henderson tcg_gen_mov_tl(dst, cpu_cc_N); 425b989ce73SRichard Henderson } 426fcf5ef2aSThomas Huth 427b989ce73SRichard Henderson static void gen_op_addcc(TCGv dst, TCGv src1, TCGv src2) 428b989ce73SRichard Henderson { 429b989ce73SRichard Henderson gen_op_addcc_int(dst, src1, src2, NULL); 430b989ce73SRichard Henderson } 431fcf5ef2aSThomas Huth 432b989ce73SRichard Henderson static void gen_op_taddcc(TCGv dst, TCGv src1, TCGv src2) 433b989ce73SRichard Henderson { 434b989ce73SRichard Henderson TCGv t = tcg_temp_new(); 435b989ce73SRichard Henderson 436b989ce73SRichard Henderson /* Save the tag bits around modification of dst. */ 437b989ce73SRichard Henderson tcg_gen_or_tl(t, src1, src2); 438b989ce73SRichard Henderson 439b989ce73SRichard Henderson gen_op_addcc(dst, src1, src2); 440b989ce73SRichard Henderson 441b989ce73SRichard Henderson /* Incorprate tag bits into icc.V */ 442b989ce73SRichard Henderson tcg_gen_andi_tl(t, t, 3); 443b989ce73SRichard Henderson tcg_gen_neg_tl(t, t); 444b989ce73SRichard Henderson tcg_gen_ext32u_tl(t, t); 445b989ce73SRichard Henderson tcg_gen_or_tl(cpu_cc_V, cpu_cc_V, t); 446b989ce73SRichard Henderson } 447b989ce73SRichard Henderson 448b989ce73SRichard Henderson static void gen_op_addc(TCGv dst, TCGv src1, TCGv src2) 449b989ce73SRichard Henderson { 450b989ce73SRichard Henderson tcg_gen_add_tl(dst, src1, src2); 451b989ce73SRichard Henderson tcg_gen_add_tl(dst, dst, gen_carry32()); 452b989ce73SRichard Henderson } 453b989ce73SRichard Henderson 454b989ce73SRichard Henderson static void gen_op_addccc(TCGv dst, TCGv src1, TCGv src2) 455b989ce73SRichard Henderson { 456b989ce73SRichard Henderson gen_op_addcc_int(dst, src1, src2, gen_carry32()); 457fcf5ef2aSThomas Huth } 458fcf5ef2aSThomas Huth 459f828df74SRichard Henderson static void gen_op_subcc_int(TCGv dst, TCGv src1, TCGv src2, TCGv cin) 460fcf5ef2aSThomas Huth { 461f828df74SRichard Henderson TCGv z = tcg_constant_tl(0); 462fcf5ef2aSThomas Huth 463f828df74SRichard Henderson if (cin) { 464f828df74SRichard Henderson tcg_gen_sub2_tl(cpu_cc_N, cpu_cc_C, src1, z, cin, z); 465f828df74SRichard Henderson tcg_gen_sub2_tl(cpu_cc_N, cpu_cc_C, cpu_cc_N, cpu_cc_C, src2, z); 466f828df74SRichard Henderson } else { 467f828df74SRichard Henderson tcg_gen_sub2_tl(cpu_cc_N, cpu_cc_C, src1, z, src2, z); 468f828df74SRichard Henderson } 469f828df74SRichard Henderson tcg_gen_neg_tl(cpu_cc_C, cpu_cc_C); 470f828df74SRichard Henderson tcg_gen_xor_tl(cpu_cc_Z, src1, src2); 471f828df74SRichard Henderson tcg_gen_xor_tl(cpu_cc_V, cpu_cc_N, src1); 472f828df74SRichard Henderson tcg_gen_and_tl(cpu_cc_V, cpu_cc_V, cpu_cc_Z); 473f828df74SRichard Henderson #ifdef TARGET_SPARC64 474f828df74SRichard Henderson tcg_gen_xor_tl(cpu_icc_C, cpu_cc_Z, cpu_cc_N); 475f828df74SRichard Henderson tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N); 476fcf5ef2aSThomas Huth #endif 477f828df74SRichard Henderson tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N); 478f828df74SRichard Henderson tcg_gen_mov_tl(dst, cpu_cc_N); 479fcf5ef2aSThomas Huth } 480fcf5ef2aSThomas Huth 481f828df74SRichard Henderson static void gen_op_subcc(TCGv dst, TCGv src1, TCGv src2) 482fcf5ef2aSThomas Huth { 483f828df74SRichard Henderson gen_op_subcc_int(dst, src1, src2, NULL); 484fcf5ef2aSThomas Huth } 485fcf5ef2aSThomas Huth 486f828df74SRichard Henderson static void gen_op_tsubcc(TCGv dst, TCGv src1, TCGv src2) 487fcf5ef2aSThomas Huth { 488f828df74SRichard Henderson TCGv t = tcg_temp_new(); 489fcf5ef2aSThomas Huth 490f828df74SRichard Henderson /* Save the tag bits around modification of dst. */ 491f828df74SRichard Henderson tcg_gen_or_tl(t, src1, src2); 492fcf5ef2aSThomas Huth 493f828df74SRichard Henderson gen_op_subcc(dst, src1, src2); 494f828df74SRichard Henderson 495f828df74SRichard Henderson /* Incorprate tag bits into icc.V */ 496f828df74SRichard Henderson tcg_gen_andi_tl(t, t, 3); 497f828df74SRichard Henderson tcg_gen_neg_tl(t, t); 498f828df74SRichard Henderson tcg_gen_ext32u_tl(t, t); 499f828df74SRichard Henderson tcg_gen_or_tl(cpu_cc_V, cpu_cc_V, t); 500f828df74SRichard Henderson } 501f828df74SRichard Henderson 502f828df74SRichard Henderson static void gen_op_subc(TCGv dst, TCGv src1, TCGv src2) 503f828df74SRichard Henderson { 504fcf5ef2aSThomas Huth tcg_gen_sub_tl(dst, src1, src2); 505f828df74SRichard Henderson tcg_gen_sub_tl(dst, dst, gen_carry32()); 506fcf5ef2aSThomas Huth } 507fcf5ef2aSThomas Huth 508f828df74SRichard Henderson static void gen_op_subccc(TCGv dst, TCGv src1, TCGv src2) 509dfebb950SRichard Henderson { 510f828df74SRichard Henderson gen_op_subcc_int(dst, src1, src2, gen_carry32()); 511dfebb950SRichard Henderson } 512dfebb950SRichard Henderson 5130c2e96c1SRichard Henderson static void gen_op_mulscc(TCGv dst, TCGv src1, TCGv src2) 514fcf5ef2aSThomas Huth { 515b989ce73SRichard Henderson TCGv zero = tcg_constant_tl(0); 516b989ce73SRichard Henderson TCGv t_src1 = tcg_temp_new(); 517b989ce73SRichard Henderson TCGv t_src2 = tcg_temp_new(); 518b989ce73SRichard Henderson TCGv t0 = tcg_temp_new(); 519fcf5ef2aSThomas Huth 520b989ce73SRichard Henderson tcg_gen_ext32u_tl(t_src1, src1); 521b989ce73SRichard Henderson tcg_gen_ext32u_tl(t_src2, src2); 522fcf5ef2aSThomas Huth 523b989ce73SRichard Henderson /* 524b989ce73SRichard Henderson * if (!(env->y & 1)) 525b989ce73SRichard Henderson * src2 = 0; 526fcf5ef2aSThomas Huth */ 527b989ce73SRichard Henderson tcg_gen_andi_tl(t0, cpu_y, 0x1); 528b989ce73SRichard Henderson tcg_gen_movcond_tl(TCG_COND_EQ, t_src2, t0, zero, zero, t_src2); 529fcf5ef2aSThomas Huth 530b989ce73SRichard Henderson /* 531b989ce73SRichard Henderson * b2 = src1 & 1; 532b989ce73SRichard Henderson * y = (b2 << 31) | (y >> 1); 533b989ce73SRichard Henderson */ 5340b1183e3SPhilippe Mathieu-Daudé tcg_gen_extract_tl(t0, cpu_y, 1, 31); 535b989ce73SRichard Henderson tcg_gen_deposit_tl(cpu_y, t0, src1, 31, 1); 536fcf5ef2aSThomas Huth 537fcf5ef2aSThomas Huth // b1 = N ^ V; 5382a1905c7SRichard Henderson tcg_gen_xor_tl(t0, cpu_cc_N, cpu_cc_V); 539fcf5ef2aSThomas Huth 540b989ce73SRichard Henderson /* 541b989ce73SRichard Henderson * src1 = (b1 << 31) | (src1 >> 1) 542b989ce73SRichard Henderson */ 5432a1905c7SRichard Henderson tcg_gen_andi_tl(t0, t0, 1u << 31); 544b989ce73SRichard Henderson tcg_gen_shri_tl(t_src1, t_src1, 1); 545b989ce73SRichard Henderson tcg_gen_or_tl(t_src1, t_src1, t0); 546fcf5ef2aSThomas Huth 547b989ce73SRichard Henderson gen_op_addcc(dst, t_src1, t_src2); 548fcf5ef2aSThomas Huth } 549fcf5ef2aSThomas Huth 5500c2e96c1SRichard Henderson static void gen_op_multiply(TCGv dst, TCGv src1, TCGv src2, int sign_ext) 551fcf5ef2aSThomas Huth { 552fcf5ef2aSThomas Huth #if TARGET_LONG_BITS == 32 553fcf5ef2aSThomas Huth if (sign_ext) { 554fcf5ef2aSThomas Huth tcg_gen_muls2_tl(dst, cpu_y, src1, src2); 555fcf5ef2aSThomas Huth } else { 556fcf5ef2aSThomas Huth tcg_gen_mulu2_tl(dst, cpu_y, src1, src2); 557fcf5ef2aSThomas Huth } 558fcf5ef2aSThomas Huth #else 559fcf5ef2aSThomas Huth TCGv t0 = tcg_temp_new_i64(); 560fcf5ef2aSThomas Huth TCGv t1 = tcg_temp_new_i64(); 561fcf5ef2aSThomas Huth 562fcf5ef2aSThomas Huth if (sign_ext) { 563fcf5ef2aSThomas Huth tcg_gen_ext32s_i64(t0, src1); 564fcf5ef2aSThomas Huth tcg_gen_ext32s_i64(t1, src2); 565fcf5ef2aSThomas Huth } else { 566fcf5ef2aSThomas Huth tcg_gen_ext32u_i64(t0, src1); 567fcf5ef2aSThomas Huth tcg_gen_ext32u_i64(t1, src2); 568fcf5ef2aSThomas Huth } 569fcf5ef2aSThomas Huth 570fcf5ef2aSThomas Huth tcg_gen_mul_i64(dst, t0, t1); 571fcf5ef2aSThomas Huth tcg_gen_shri_i64(cpu_y, dst, 32); 572fcf5ef2aSThomas Huth #endif 573fcf5ef2aSThomas Huth } 574fcf5ef2aSThomas Huth 5750c2e96c1SRichard Henderson static void gen_op_umul(TCGv dst, TCGv src1, TCGv src2) 576fcf5ef2aSThomas Huth { 577fcf5ef2aSThomas Huth /* zero-extend truncated operands before multiplication */ 578fcf5ef2aSThomas Huth gen_op_multiply(dst, src1, src2, 0); 579fcf5ef2aSThomas Huth } 580fcf5ef2aSThomas Huth 5810c2e96c1SRichard Henderson static void gen_op_smul(TCGv dst, TCGv src1, TCGv src2) 582fcf5ef2aSThomas Huth { 583fcf5ef2aSThomas Huth /* sign-extend truncated operands before multiplication */ 584fcf5ef2aSThomas Huth gen_op_multiply(dst, src1, src2, 1); 585fcf5ef2aSThomas Huth } 586fcf5ef2aSThomas Huth 587c2636853SRichard Henderson static void gen_op_sdiv(TCGv dst, TCGv src1, TCGv src2) 588c2636853SRichard Henderson { 58913260103SRichard Henderson #ifdef TARGET_SPARC64 590c2636853SRichard Henderson gen_helper_sdiv(dst, tcg_env, src1, src2); 59113260103SRichard Henderson tcg_gen_ext32s_tl(dst, dst); 59213260103SRichard Henderson #else 59313260103SRichard Henderson TCGv_i64 t64 = tcg_temp_new_i64(); 59413260103SRichard Henderson gen_helper_sdiv(t64, tcg_env, src1, src2); 59513260103SRichard Henderson tcg_gen_trunc_i64_tl(dst, t64); 59613260103SRichard Henderson #endif 597c2636853SRichard Henderson } 598c2636853SRichard Henderson 599c2636853SRichard Henderson static void gen_op_udivcc(TCGv dst, TCGv src1, TCGv src2) 600c2636853SRichard Henderson { 60113260103SRichard Henderson TCGv_i64 t64; 60213260103SRichard Henderson 60313260103SRichard Henderson #ifdef TARGET_SPARC64 60413260103SRichard Henderson t64 = cpu_cc_V; 60513260103SRichard Henderson #else 60613260103SRichard Henderson t64 = tcg_temp_new_i64(); 60713260103SRichard Henderson #endif 60813260103SRichard Henderson 60913260103SRichard Henderson gen_helper_udiv(t64, tcg_env, src1, src2); 61013260103SRichard Henderson 61113260103SRichard Henderson #ifdef TARGET_SPARC64 61213260103SRichard Henderson tcg_gen_ext32u_tl(cpu_cc_N, t64); 61313260103SRichard Henderson tcg_gen_shri_tl(cpu_cc_V, t64, 32); 61413260103SRichard Henderson tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N); 61513260103SRichard Henderson tcg_gen_movi_tl(cpu_icc_C, 0); 61613260103SRichard Henderson #else 61713260103SRichard Henderson tcg_gen_extr_i64_tl(cpu_cc_N, cpu_cc_V, t64); 61813260103SRichard Henderson #endif 61913260103SRichard Henderson tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N); 62013260103SRichard Henderson tcg_gen_movi_tl(cpu_cc_C, 0); 62113260103SRichard Henderson tcg_gen_mov_tl(dst, cpu_cc_N); 622c2636853SRichard Henderson } 623c2636853SRichard Henderson 624c2636853SRichard Henderson static void gen_op_sdivcc(TCGv dst, TCGv src1, TCGv src2) 625c2636853SRichard Henderson { 62613260103SRichard Henderson TCGv_i64 t64; 62713260103SRichard Henderson 62813260103SRichard Henderson #ifdef TARGET_SPARC64 62913260103SRichard Henderson t64 = cpu_cc_V; 63013260103SRichard Henderson #else 63113260103SRichard Henderson t64 = tcg_temp_new_i64(); 63213260103SRichard Henderson #endif 63313260103SRichard Henderson 63413260103SRichard Henderson gen_helper_sdiv(t64, tcg_env, src1, src2); 63513260103SRichard Henderson 63613260103SRichard Henderson #ifdef TARGET_SPARC64 63713260103SRichard Henderson tcg_gen_ext32s_tl(cpu_cc_N, t64); 63813260103SRichard Henderson tcg_gen_shri_tl(cpu_cc_V, t64, 32); 63913260103SRichard Henderson tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N); 64013260103SRichard Henderson tcg_gen_movi_tl(cpu_icc_C, 0); 64113260103SRichard Henderson #else 64213260103SRichard Henderson tcg_gen_extr_i64_tl(cpu_cc_N, cpu_cc_V, t64); 64313260103SRichard Henderson #endif 64413260103SRichard Henderson tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N); 64513260103SRichard Henderson tcg_gen_movi_tl(cpu_cc_C, 0); 64613260103SRichard Henderson tcg_gen_mov_tl(dst, cpu_cc_N); 647c2636853SRichard Henderson } 648c2636853SRichard Henderson 649a9aba13dSRichard Henderson static void gen_op_taddcctv(TCGv dst, TCGv src1, TCGv src2) 650a9aba13dSRichard Henderson { 651a9aba13dSRichard Henderson gen_helper_taddcctv(dst, tcg_env, src1, src2); 652a9aba13dSRichard Henderson } 653a9aba13dSRichard Henderson 654a9aba13dSRichard Henderson static void gen_op_tsubcctv(TCGv dst, TCGv src1, TCGv src2) 655a9aba13dSRichard Henderson { 656a9aba13dSRichard Henderson gen_helper_tsubcctv(dst, tcg_env, src1, src2); 657a9aba13dSRichard Henderson } 658a9aba13dSRichard Henderson 6599c6ec5bcSRichard Henderson static void gen_op_popc(TCGv dst, TCGv src1, TCGv src2) 6609c6ec5bcSRichard Henderson { 6619c6ec5bcSRichard Henderson tcg_gen_ctpop_tl(dst, src2); 6629c6ec5bcSRichard Henderson } 6639c6ec5bcSRichard Henderson 66445bfed3bSRichard Henderson #ifndef TARGET_SPARC64 66545bfed3bSRichard Henderson static void gen_helper_array8(TCGv dst, TCGv src1, TCGv src2) 66645bfed3bSRichard Henderson { 66745bfed3bSRichard Henderson g_assert_not_reached(); 66845bfed3bSRichard Henderson } 66945bfed3bSRichard Henderson #endif 67045bfed3bSRichard Henderson 67145bfed3bSRichard Henderson static void gen_op_array16(TCGv dst, TCGv src1, TCGv src2) 67245bfed3bSRichard Henderson { 67345bfed3bSRichard Henderson gen_helper_array8(dst, src1, src2); 67445bfed3bSRichard Henderson tcg_gen_shli_tl(dst, dst, 1); 67545bfed3bSRichard Henderson } 67645bfed3bSRichard Henderson 67745bfed3bSRichard Henderson static void gen_op_array32(TCGv dst, TCGv src1, TCGv src2) 67845bfed3bSRichard Henderson { 67945bfed3bSRichard Henderson gen_helper_array8(dst, src1, src2); 68045bfed3bSRichard Henderson tcg_gen_shli_tl(dst, dst, 2); 68145bfed3bSRichard Henderson } 68245bfed3bSRichard Henderson 6832f722641SRichard Henderson static void gen_op_fpack16(TCGv_i32 dst, TCGv_i64 src) 6842f722641SRichard Henderson { 6852f722641SRichard Henderson #ifdef TARGET_SPARC64 6862f722641SRichard Henderson gen_helper_fpack16(dst, cpu_gsr, src); 6872f722641SRichard Henderson #else 6882f722641SRichard Henderson g_assert_not_reached(); 6892f722641SRichard Henderson #endif 6902f722641SRichard Henderson } 6912f722641SRichard Henderson 6922f722641SRichard Henderson static void gen_op_fpackfix(TCGv_i32 dst, TCGv_i64 src) 6932f722641SRichard Henderson { 6942f722641SRichard Henderson #ifdef TARGET_SPARC64 6952f722641SRichard Henderson gen_helper_fpackfix(dst, cpu_gsr, src); 6962f722641SRichard Henderson #else 6972f722641SRichard Henderson g_assert_not_reached(); 6982f722641SRichard Henderson #endif 6992f722641SRichard Henderson } 7002f722641SRichard Henderson 7014b6edc0aSRichard Henderson static void gen_op_fpack32(TCGv_i64 dst, TCGv_i64 src1, TCGv_i64 src2) 7024b6edc0aSRichard Henderson { 7034b6edc0aSRichard Henderson #ifdef TARGET_SPARC64 7044b6edc0aSRichard Henderson gen_helper_fpack32(dst, cpu_gsr, src1, src2); 7054b6edc0aSRichard Henderson #else 7064b6edc0aSRichard Henderson g_assert_not_reached(); 7074b6edc0aSRichard Henderson #endif 7084b6edc0aSRichard Henderson } 7094b6edc0aSRichard Henderson 7104b6edc0aSRichard Henderson static void gen_op_faligndata(TCGv_i64 dst, TCGv_i64 s1, TCGv_i64 s2) 7114b6edc0aSRichard Henderson { 7124b6edc0aSRichard Henderson #ifdef TARGET_SPARC64 7134b6edc0aSRichard Henderson TCGv t1, t2, shift; 7144b6edc0aSRichard Henderson 7154b6edc0aSRichard Henderson t1 = tcg_temp_new(); 7164b6edc0aSRichard Henderson t2 = tcg_temp_new(); 7174b6edc0aSRichard Henderson shift = tcg_temp_new(); 7184b6edc0aSRichard Henderson 7194b6edc0aSRichard Henderson tcg_gen_andi_tl(shift, cpu_gsr, 7); 7204b6edc0aSRichard Henderson tcg_gen_shli_tl(shift, shift, 3); 7214b6edc0aSRichard Henderson tcg_gen_shl_tl(t1, s1, shift); 7224b6edc0aSRichard Henderson 7234b6edc0aSRichard Henderson /* 7244b6edc0aSRichard Henderson * A shift of 64 does not produce 0 in TCG. Divide this into a 7254b6edc0aSRichard Henderson * shift of (up to 63) followed by a constant shift of 1. 7264b6edc0aSRichard Henderson */ 7274b6edc0aSRichard Henderson tcg_gen_xori_tl(shift, shift, 63); 7284b6edc0aSRichard Henderson tcg_gen_shr_tl(t2, s2, shift); 7294b6edc0aSRichard Henderson tcg_gen_shri_tl(t2, t2, 1); 7304b6edc0aSRichard Henderson 7314b6edc0aSRichard Henderson tcg_gen_or_tl(dst, t1, t2); 7324b6edc0aSRichard Henderson #else 7334b6edc0aSRichard Henderson g_assert_not_reached(); 7344b6edc0aSRichard Henderson #endif 7354b6edc0aSRichard Henderson } 7364b6edc0aSRichard Henderson 7374b6edc0aSRichard Henderson static void gen_op_bshuffle(TCGv_i64 dst, TCGv_i64 src1, TCGv_i64 src2) 7384b6edc0aSRichard Henderson { 7394b6edc0aSRichard Henderson #ifdef TARGET_SPARC64 7404b6edc0aSRichard Henderson gen_helper_bshuffle(dst, cpu_gsr, src1, src2); 7414b6edc0aSRichard Henderson #else 7424b6edc0aSRichard Henderson g_assert_not_reached(); 7434b6edc0aSRichard Henderson #endif 7444b6edc0aSRichard Henderson } 7454b6edc0aSRichard Henderson 746fcf5ef2aSThomas Huth // 1 7470c2e96c1SRichard Henderson static void gen_op_eval_ba(TCGv dst) 748fcf5ef2aSThomas Huth { 749fcf5ef2aSThomas Huth tcg_gen_movi_tl(dst, 1); 750fcf5ef2aSThomas Huth } 751fcf5ef2aSThomas Huth 752fcf5ef2aSThomas Huth // 0 7530c2e96c1SRichard Henderson static void gen_op_eval_bn(TCGv dst) 754fcf5ef2aSThomas Huth { 755fcf5ef2aSThomas Huth tcg_gen_movi_tl(dst, 0); 756fcf5ef2aSThomas Huth } 757fcf5ef2aSThomas Huth 758fcf5ef2aSThomas Huth /* 759fcf5ef2aSThomas Huth FPSR bit field FCC1 | FCC0: 760fcf5ef2aSThomas Huth 0 = 761fcf5ef2aSThomas Huth 1 < 762fcf5ef2aSThomas Huth 2 > 763fcf5ef2aSThomas Huth 3 unordered 764fcf5ef2aSThomas Huth */ 7650c2e96c1SRichard Henderson static void gen_mov_reg_FCC0(TCGv reg, TCGv src, 766fcf5ef2aSThomas Huth unsigned int fcc_offset) 767fcf5ef2aSThomas Huth { 768fcf5ef2aSThomas Huth tcg_gen_shri_tl(reg, src, FSR_FCC0_SHIFT + fcc_offset); 769fcf5ef2aSThomas Huth tcg_gen_andi_tl(reg, reg, 0x1); 770fcf5ef2aSThomas Huth } 771fcf5ef2aSThomas Huth 7720c2e96c1SRichard Henderson static void gen_mov_reg_FCC1(TCGv reg, TCGv src, unsigned int fcc_offset) 773fcf5ef2aSThomas Huth { 774fcf5ef2aSThomas Huth tcg_gen_shri_tl(reg, src, FSR_FCC1_SHIFT + fcc_offset); 775fcf5ef2aSThomas Huth tcg_gen_andi_tl(reg, reg, 0x1); 776fcf5ef2aSThomas Huth } 777fcf5ef2aSThomas Huth 778fcf5ef2aSThomas Huth // !0: FCC0 | FCC1 7790c2e96c1SRichard Henderson static void gen_op_eval_fbne(TCGv dst, TCGv src, unsigned int fcc_offset) 780fcf5ef2aSThomas Huth { 781fcf5ef2aSThomas Huth TCGv t0 = tcg_temp_new(); 782fcf5ef2aSThomas Huth gen_mov_reg_FCC0(dst, src, fcc_offset); 783fcf5ef2aSThomas Huth gen_mov_reg_FCC1(t0, src, fcc_offset); 784fcf5ef2aSThomas Huth tcg_gen_or_tl(dst, dst, t0); 785fcf5ef2aSThomas Huth } 786fcf5ef2aSThomas Huth 787fcf5ef2aSThomas Huth // 1 or 2: FCC0 ^ FCC1 7880c2e96c1SRichard Henderson static void gen_op_eval_fblg(TCGv dst, TCGv src, unsigned int fcc_offset) 789fcf5ef2aSThomas Huth { 790fcf5ef2aSThomas Huth TCGv t0 = tcg_temp_new(); 791fcf5ef2aSThomas Huth gen_mov_reg_FCC0(dst, src, fcc_offset); 792fcf5ef2aSThomas Huth gen_mov_reg_FCC1(t0, src, fcc_offset); 793fcf5ef2aSThomas Huth tcg_gen_xor_tl(dst, dst, t0); 794fcf5ef2aSThomas Huth } 795fcf5ef2aSThomas Huth 796fcf5ef2aSThomas Huth // 1 or 3: FCC0 7970c2e96c1SRichard Henderson static void gen_op_eval_fbul(TCGv dst, TCGv src, unsigned int fcc_offset) 798fcf5ef2aSThomas Huth { 799fcf5ef2aSThomas Huth gen_mov_reg_FCC0(dst, src, fcc_offset); 800fcf5ef2aSThomas Huth } 801fcf5ef2aSThomas Huth 802fcf5ef2aSThomas Huth // 1: FCC0 & !FCC1 8030c2e96c1SRichard Henderson static void gen_op_eval_fbl(TCGv dst, TCGv src, unsigned int fcc_offset) 804fcf5ef2aSThomas Huth { 805fcf5ef2aSThomas Huth TCGv t0 = tcg_temp_new(); 806fcf5ef2aSThomas Huth gen_mov_reg_FCC0(dst, src, fcc_offset); 807fcf5ef2aSThomas Huth gen_mov_reg_FCC1(t0, src, fcc_offset); 808fcf5ef2aSThomas Huth tcg_gen_andc_tl(dst, dst, t0); 809fcf5ef2aSThomas Huth } 810fcf5ef2aSThomas Huth 811fcf5ef2aSThomas Huth // 2 or 3: FCC1 8120c2e96c1SRichard Henderson static void gen_op_eval_fbug(TCGv dst, TCGv src, unsigned int fcc_offset) 813fcf5ef2aSThomas Huth { 814fcf5ef2aSThomas Huth gen_mov_reg_FCC1(dst, src, fcc_offset); 815fcf5ef2aSThomas Huth } 816fcf5ef2aSThomas Huth 817fcf5ef2aSThomas Huth // 2: !FCC0 & FCC1 8180c2e96c1SRichard Henderson static void gen_op_eval_fbg(TCGv dst, TCGv src, unsigned int fcc_offset) 819fcf5ef2aSThomas Huth { 820fcf5ef2aSThomas Huth TCGv t0 = tcg_temp_new(); 821fcf5ef2aSThomas Huth gen_mov_reg_FCC0(dst, src, fcc_offset); 822fcf5ef2aSThomas Huth gen_mov_reg_FCC1(t0, src, fcc_offset); 823fcf5ef2aSThomas Huth tcg_gen_andc_tl(dst, t0, dst); 824fcf5ef2aSThomas Huth } 825fcf5ef2aSThomas Huth 826fcf5ef2aSThomas Huth // 3: FCC0 & FCC1 8270c2e96c1SRichard Henderson static void gen_op_eval_fbu(TCGv dst, TCGv src, unsigned int fcc_offset) 828fcf5ef2aSThomas Huth { 829fcf5ef2aSThomas Huth TCGv t0 = tcg_temp_new(); 830fcf5ef2aSThomas Huth gen_mov_reg_FCC0(dst, src, fcc_offset); 831fcf5ef2aSThomas Huth gen_mov_reg_FCC1(t0, src, fcc_offset); 832fcf5ef2aSThomas Huth tcg_gen_and_tl(dst, dst, t0); 833fcf5ef2aSThomas Huth } 834fcf5ef2aSThomas Huth 835fcf5ef2aSThomas Huth // 0: !(FCC0 | FCC1) 8360c2e96c1SRichard Henderson static void gen_op_eval_fbe(TCGv dst, TCGv src, unsigned int fcc_offset) 837fcf5ef2aSThomas Huth { 838fcf5ef2aSThomas Huth TCGv t0 = tcg_temp_new(); 839fcf5ef2aSThomas Huth gen_mov_reg_FCC0(dst, src, fcc_offset); 840fcf5ef2aSThomas Huth gen_mov_reg_FCC1(t0, src, fcc_offset); 841fcf5ef2aSThomas Huth tcg_gen_or_tl(dst, dst, t0); 842fcf5ef2aSThomas Huth tcg_gen_xori_tl(dst, dst, 0x1); 843fcf5ef2aSThomas Huth } 844fcf5ef2aSThomas Huth 845fcf5ef2aSThomas Huth // 0 or 3: !(FCC0 ^ FCC1) 8460c2e96c1SRichard Henderson static void gen_op_eval_fbue(TCGv dst, TCGv src, unsigned int fcc_offset) 847fcf5ef2aSThomas Huth { 848fcf5ef2aSThomas Huth TCGv t0 = tcg_temp_new(); 849fcf5ef2aSThomas Huth gen_mov_reg_FCC0(dst, src, fcc_offset); 850fcf5ef2aSThomas Huth gen_mov_reg_FCC1(t0, src, fcc_offset); 851fcf5ef2aSThomas Huth tcg_gen_xor_tl(dst, dst, t0); 852fcf5ef2aSThomas Huth tcg_gen_xori_tl(dst, dst, 0x1); 853fcf5ef2aSThomas Huth } 854fcf5ef2aSThomas Huth 855fcf5ef2aSThomas Huth // 0 or 2: !FCC0 8560c2e96c1SRichard Henderson static void gen_op_eval_fbge(TCGv dst, TCGv src, unsigned int fcc_offset) 857fcf5ef2aSThomas Huth { 858fcf5ef2aSThomas Huth gen_mov_reg_FCC0(dst, src, fcc_offset); 859fcf5ef2aSThomas Huth tcg_gen_xori_tl(dst, dst, 0x1); 860fcf5ef2aSThomas Huth } 861fcf5ef2aSThomas Huth 862fcf5ef2aSThomas Huth // !1: !(FCC0 & !FCC1) 8630c2e96c1SRichard Henderson static void gen_op_eval_fbuge(TCGv dst, TCGv src, unsigned int fcc_offset) 864fcf5ef2aSThomas Huth { 865fcf5ef2aSThomas Huth TCGv t0 = tcg_temp_new(); 866fcf5ef2aSThomas Huth gen_mov_reg_FCC0(dst, src, fcc_offset); 867fcf5ef2aSThomas Huth gen_mov_reg_FCC1(t0, src, fcc_offset); 868fcf5ef2aSThomas Huth tcg_gen_andc_tl(dst, dst, t0); 869fcf5ef2aSThomas Huth tcg_gen_xori_tl(dst, dst, 0x1); 870fcf5ef2aSThomas Huth } 871fcf5ef2aSThomas Huth 872fcf5ef2aSThomas Huth // 0 or 1: !FCC1 8730c2e96c1SRichard Henderson static void gen_op_eval_fble(TCGv dst, TCGv src, unsigned int fcc_offset) 874fcf5ef2aSThomas Huth { 875fcf5ef2aSThomas Huth gen_mov_reg_FCC1(dst, src, fcc_offset); 876fcf5ef2aSThomas Huth tcg_gen_xori_tl(dst, dst, 0x1); 877fcf5ef2aSThomas Huth } 878fcf5ef2aSThomas Huth 879fcf5ef2aSThomas Huth // !2: !(!FCC0 & FCC1) 8800c2e96c1SRichard Henderson static void gen_op_eval_fbule(TCGv dst, TCGv src, unsigned int fcc_offset) 881fcf5ef2aSThomas Huth { 882fcf5ef2aSThomas Huth TCGv t0 = tcg_temp_new(); 883fcf5ef2aSThomas Huth gen_mov_reg_FCC0(dst, src, fcc_offset); 884fcf5ef2aSThomas Huth gen_mov_reg_FCC1(t0, src, fcc_offset); 885fcf5ef2aSThomas Huth tcg_gen_andc_tl(dst, t0, dst); 886fcf5ef2aSThomas Huth tcg_gen_xori_tl(dst, dst, 0x1); 887fcf5ef2aSThomas Huth } 888fcf5ef2aSThomas Huth 889fcf5ef2aSThomas Huth // !3: !(FCC0 & FCC1) 8900c2e96c1SRichard Henderson static void gen_op_eval_fbo(TCGv dst, TCGv src, unsigned int fcc_offset) 891fcf5ef2aSThomas Huth { 892fcf5ef2aSThomas Huth TCGv t0 = tcg_temp_new(); 893fcf5ef2aSThomas Huth gen_mov_reg_FCC0(dst, src, fcc_offset); 894fcf5ef2aSThomas Huth gen_mov_reg_FCC1(t0, src, fcc_offset); 895fcf5ef2aSThomas Huth tcg_gen_and_tl(dst, dst, t0); 896fcf5ef2aSThomas Huth tcg_gen_xori_tl(dst, dst, 0x1); 897fcf5ef2aSThomas Huth } 898fcf5ef2aSThomas Huth 89989527e3aSRichard Henderson static void finishing_insn(DisasContext *dc) 90089527e3aSRichard Henderson { 90189527e3aSRichard Henderson /* 90289527e3aSRichard Henderson * From here, there is no future path through an unwinding exception. 90389527e3aSRichard Henderson * If the current insn cannot raise an exception, the computation of 90489527e3aSRichard Henderson * cpu_cond may be able to be elided. 90589527e3aSRichard Henderson */ 90689527e3aSRichard Henderson if (dc->cpu_cond_live) { 90789527e3aSRichard Henderson tcg_gen_discard_tl(cpu_cond); 90889527e3aSRichard Henderson dc->cpu_cond_live = false; 90989527e3aSRichard Henderson } 91089527e3aSRichard Henderson } 91189527e3aSRichard Henderson 9120c2e96c1SRichard Henderson static void gen_generic_branch(DisasContext *dc) 913fcf5ef2aSThomas Huth { 91400ab7e61SRichard Henderson TCGv npc0 = tcg_constant_tl(dc->jump_pc[0]); 91500ab7e61SRichard Henderson TCGv npc1 = tcg_constant_tl(dc->jump_pc[1]); 916533f042fSRichard Henderson TCGv c2 = tcg_constant_tl(dc->jump.c2); 917fcf5ef2aSThomas Huth 918533f042fSRichard Henderson tcg_gen_movcond_tl(dc->jump.cond, cpu_npc, dc->jump.c1, c2, npc0, npc1); 919fcf5ef2aSThomas Huth } 920fcf5ef2aSThomas Huth 921fcf5ef2aSThomas Huth /* call this function before using the condition register as it may 922fcf5ef2aSThomas Huth have been set for a jump */ 9230c2e96c1SRichard Henderson static void flush_cond(DisasContext *dc) 924fcf5ef2aSThomas Huth { 925fcf5ef2aSThomas Huth if (dc->npc == JUMP_PC) { 926fcf5ef2aSThomas Huth gen_generic_branch(dc); 92799c82c47SRichard Henderson dc->npc = DYNAMIC_PC_LOOKUP; 928fcf5ef2aSThomas Huth } 929fcf5ef2aSThomas Huth } 930fcf5ef2aSThomas Huth 9310c2e96c1SRichard Henderson static void save_npc(DisasContext *dc) 932fcf5ef2aSThomas Huth { 933633c4283SRichard Henderson if (dc->npc & 3) { 934633c4283SRichard Henderson switch (dc->npc) { 935633c4283SRichard Henderson case JUMP_PC: 936fcf5ef2aSThomas Huth gen_generic_branch(dc); 93799c82c47SRichard Henderson dc->npc = DYNAMIC_PC_LOOKUP; 938633c4283SRichard Henderson break; 939633c4283SRichard Henderson case DYNAMIC_PC: 940633c4283SRichard Henderson case DYNAMIC_PC_LOOKUP: 941633c4283SRichard Henderson break; 942633c4283SRichard Henderson default: 943633c4283SRichard Henderson g_assert_not_reached(); 944633c4283SRichard Henderson } 945633c4283SRichard Henderson } else { 946fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_npc, dc->npc); 947fcf5ef2aSThomas Huth } 948fcf5ef2aSThomas Huth } 949fcf5ef2aSThomas Huth 9500c2e96c1SRichard Henderson static void save_state(DisasContext *dc) 951fcf5ef2aSThomas Huth { 952fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_pc, dc->pc); 953fcf5ef2aSThomas Huth save_npc(dc); 954fcf5ef2aSThomas Huth } 955fcf5ef2aSThomas Huth 956fcf5ef2aSThomas Huth static void gen_exception(DisasContext *dc, int which) 957fcf5ef2aSThomas Huth { 95889527e3aSRichard Henderson finishing_insn(dc); 959fcf5ef2aSThomas Huth save_state(dc); 960ad75a51eSRichard Henderson gen_helper_raise_exception(tcg_env, tcg_constant_i32(which)); 961af00be49SEmilio G. Cota dc->base.is_jmp = DISAS_NORETURN; 962fcf5ef2aSThomas Huth } 963fcf5ef2aSThomas Huth 964186e7890SRichard Henderson static TCGLabel *delay_exceptionv(DisasContext *dc, TCGv_i32 excp) 965fcf5ef2aSThomas Huth { 966186e7890SRichard Henderson DisasDelayException *e = g_new0(DisasDelayException, 1); 967186e7890SRichard Henderson 968186e7890SRichard Henderson e->next = dc->delay_excp_list; 969186e7890SRichard Henderson dc->delay_excp_list = e; 970186e7890SRichard Henderson 971186e7890SRichard Henderson e->lab = gen_new_label(); 972186e7890SRichard Henderson e->excp = excp; 973186e7890SRichard Henderson e->pc = dc->pc; 974186e7890SRichard Henderson /* Caller must have used flush_cond before branch. */ 975186e7890SRichard Henderson assert(e->npc != JUMP_PC); 976186e7890SRichard Henderson e->npc = dc->npc; 977186e7890SRichard Henderson 978186e7890SRichard Henderson return e->lab; 979186e7890SRichard Henderson } 980186e7890SRichard Henderson 981186e7890SRichard Henderson static TCGLabel *delay_exception(DisasContext *dc, int excp) 982186e7890SRichard Henderson { 983186e7890SRichard Henderson return delay_exceptionv(dc, tcg_constant_i32(excp)); 984186e7890SRichard Henderson } 985186e7890SRichard Henderson 986186e7890SRichard Henderson static void gen_check_align(DisasContext *dc, TCGv addr, int mask) 987186e7890SRichard Henderson { 988186e7890SRichard Henderson TCGv t = tcg_temp_new(); 989186e7890SRichard Henderson TCGLabel *lab; 990186e7890SRichard Henderson 991186e7890SRichard Henderson tcg_gen_andi_tl(t, addr, mask); 992186e7890SRichard Henderson 993186e7890SRichard Henderson flush_cond(dc); 994186e7890SRichard Henderson lab = delay_exception(dc, TT_UNALIGNED); 995186e7890SRichard Henderson tcg_gen_brcondi_tl(TCG_COND_NE, t, 0, lab); 996fcf5ef2aSThomas Huth } 997fcf5ef2aSThomas Huth 9980c2e96c1SRichard Henderson static void gen_mov_pc_npc(DisasContext *dc) 999fcf5ef2aSThomas Huth { 100089527e3aSRichard Henderson finishing_insn(dc); 100189527e3aSRichard Henderson 1002633c4283SRichard Henderson if (dc->npc & 3) { 1003633c4283SRichard Henderson switch (dc->npc) { 1004633c4283SRichard Henderson case JUMP_PC: 1005fcf5ef2aSThomas Huth gen_generic_branch(dc); 1006fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_pc, cpu_npc); 100799c82c47SRichard Henderson dc->pc = DYNAMIC_PC_LOOKUP; 1008633c4283SRichard Henderson break; 1009633c4283SRichard Henderson case DYNAMIC_PC: 1010633c4283SRichard Henderson case DYNAMIC_PC_LOOKUP: 1011fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_pc, cpu_npc); 1012633c4283SRichard Henderson dc->pc = dc->npc; 1013633c4283SRichard Henderson break; 1014633c4283SRichard Henderson default: 1015633c4283SRichard Henderson g_assert_not_reached(); 1016633c4283SRichard Henderson } 1017fcf5ef2aSThomas Huth } else { 1018fcf5ef2aSThomas Huth dc->pc = dc->npc; 1019fcf5ef2aSThomas Huth } 1020fcf5ef2aSThomas Huth } 1021fcf5ef2aSThomas Huth 1022fcf5ef2aSThomas Huth static void gen_compare(DisasCompare *cmp, bool xcc, unsigned int cond, 1023fcf5ef2aSThomas Huth DisasContext *dc) 1024fcf5ef2aSThomas Huth { 1025b597eedcSRichard Henderson TCGv t1; 1026fcf5ef2aSThomas Huth 10272a1905c7SRichard Henderson cmp->c1 = t1 = tcg_temp_new(); 1028c8507ebfSRichard Henderson cmp->c2 = 0; 10292a1905c7SRichard Henderson 10302a1905c7SRichard Henderson switch (cond & 7) { 10312a1905c7SRichard Henderson case 0x0: /* never */ 10322a1905c7SRichard Henderson cmp->cond = TCG_COND_NEVER; 1033c8507ebfSRichard Henderson cmp->c1 = tcg_constant_tl(0); 1034fcf5ef2aSThomas Huth break; 10352a1905c7SRichard Henderson 10362a1905c7SRichard Henderson case 0x1: /* eq: Z */ 10372a1905c7SRichard Henderson cmp->cond = TCG_COND_EQ; 10382a1905c7SRichard Henderson if (TARGET_LONG_BITS == 32 || xcc) { 10392a1905c7SRichard Henderson tcg_gen_mov_tl(t1, cpu_cc_Z); 10402a1905c7SRichard Henderson } else { 10412a1905c7SRichard Henderson tcg_gen_ext32u_tl(t1, cpu_icc_Z); 10422a1905c7SRichard Henderson } 10432a1905c7SRichard Henderson break; 10442a1905c7SRichard Henderson 10452a1905c7SRichard Henderson case 0x2: /* le: Z | (N ^ V) */ 10462a1905c7SRichard Henderson /* 10472a1905c7SRichard Henderson * Simplify: 10482a1905c7SRichard Henderson * cc_Z || (N ^ V) < 0 NE 10492a1905c7SRichard Henderson * cc_Z && !((N ^ V) < 0) EQ 10502a1905c7SRichard Henderson * cc_Z & ~((N ^ V) >> TLB) EQ 10512a1905c7SRichard Henderson */ 10522a1905c7SRichard Henderson cmp->cond = TCG_COND_EQ; 10532a1905c7SRichard Henderson tcg_gen_xor_tl(t1, cpu_cc_N, cpu_cc_V); 10542a1905c7SRichard Henderson tcg_gen_sextract_tl(t1, t1, xcc ? 63 : 31, 1); 10552a1905c7SRichard Henderson tcg_gen_andc_tl(t1, xcc ? cpu_cc_Z : cpu_icc_Z, t1); 10562a1905c7SRichard Henderson if (TARGET_LONG_BITS == 64 && !xcc) { 10572a1905c7SRichard Henderson tcg_gen_ext32u_tl(t1, t1); 10582a1905c7SRichard Henderson } 10592a1905c7SRichard Henderson break; 10602a1905c7SRichard Henderson 10612a1905c7SRichard Henderson case 0x3: /* lt: N ^ V */ 10622a1905c7SRichard Henderson cmp->cond = TCG_COND_LT; 10632a1905c7SRichard Henderson tcg_gen_xor_tl(t1, cpu_cc_N, cpu_cc_V); 10642a1905c7SRichard Henderson if (TARGET_LONG_BITS == 64 && !xcc) { 10652a1905c7SRichard Henderson tcg_gen_ext32s_tl(t1, t1); 10662a1905c7SRichard Henderson } 10672a1905c7SRichard Henderson break; 10682a1905c7SRichard Henderson 10692a1905c7SRichard Henderson case 0x4: /* leu: Z | C */ 10702a1905c7SRichard Henderson /* 10712a1905c7SRichard Henderson * Simplify: 10722a1905c7SRichard Henderson * cc_Z == 0 || cc_C != 0 NE 10732a1905c7SRichard Henderson * cc_Z != 0 && cc_C == 0 EQ 10742a1905c7SRichard Henderson * cc_Z & (cc_C ? 0 : -1) EQ 10752a1905c7SRichard Henderson * cc_Z & (cc_C - 1) EQ 10762a1905c7SRichard Henderson */ 10772a1905c7SRichard Henderson cmp->cond = TCG_COND_EQ; 10782a1905c7SRichard Henderson if (TARGET_LONG_BITS == 32 || xcc) { 10792a1905c7SRichard Henderson tcg_gen_subi_tl(t1, cpu_cc_C, 1); 10802a1905c7SRichard Henderson tcg_gen_and_tl(t1, t1, cpu_cc_Z); 10812a1905c7SRichard Henderson } else { 10822a1905c7SRichard Henderson tcg_gen_extract_tl(t1, cpu_icc_C, 32, 1); 10832a1905c7SRichard Henderson tcg_gen_subi_tl(t1, t1, 1); 10842a1905c7SRichard Henderson tcg_gen_and_tl(t1, t1, cpu_icc_Z); 10852a1905c7SRichard Henderson tcg_gen_ext32u_tl(t1, t1); 10862a1905c7SRichard Henderson } 10872a1905c7SRichard Henderson break; 10882a1905c7SRichard Henderson 10892a1905c7SRichard Henderson case 0x5: /* ltu: C */ 10902a1905c7SRichard Henderson cmp->cond = TCG_COND_NE; 10912a1905c7SRichard Henderson if (TARGET_LONG_BITS == 32 || xcc) { 10922a1905c7SRichard Henderson tcg_gen_mov_tl(t1, cpu_cc_C); 10932a1905c7SRichard Henderson } else { 10942a1905c7SRichard Henderson tcg_gen_extract_tl(t1, cpu_icc_C, 32, 1); 10952a1905c7SRichard Henderson } 10962a1905c7SRichard Henderson break; 10972a1905c7SRichard Henderson 10982a1905c7SRichard Henderson case 0x6: /* neg: N */ 10992a1905c7SRichard Henderson cmp->cond = TCG_COND_LT; 11002a1905c7SRichard Henderson if (TARGET_LONG_BITS == 32 || xcc) { 11012a1905c7SRichard Henderson tcg_gen_mov_tl(t1, cpu_cc_N); 11022a1905c7SRichard Henderson } else { 11032a1905c7SRichard Henderson tcg_gen_ext32s_tl(t1, cpu_cc_N); 11042a1905c7SRichard Henderson } 11052a1905c7SRichard Henderson break; 11062a1905c7SRichard Henderson 11072a1905c7SRichard Henderson case 0x7: /* vs: V */ 11082a1905c7SRichard Henderson cmp->cond = TCG_COND_LT; 11092a1905c7SRichard Henderson if (TARGET_LONG_BITS == 32 || xcc) { 11102a1905c7SRichard Henderson tcg_gen_mov_tl(t1, cpu_cc_V); 11112a1905c7SRichard Henderson } else { 11122a1905c7SRichard Henderson tcg_gen_ext32s_tl(t1, cpu_cc_V); 11132a1905c7SRichard Henderson } 11142a1905c7SRichard Henderson break; 11152a1905c7SRichard Henderson } 11162a1905c7SRichard Henderson if (cond & 8) { 11172a1905c7SRichard Henderson cmp->cond = tcg_invert_cond(cmp->cond); 1118fcf5ef2aSThomas Huth } 1119fcf5ef2aSThomas Huth } 1120fcf5ef2aSThomas Huth 1121fcf5ef2aSThomas Huth static void gen_fcompare(DisasCompare *cmp, unsigned int cc, unsigned int cond) 1122fcf5ef2aSThomas Huth { 1123fcf5ef2aSThomas Huth unsigned int offset; 1124fcf5ef2aSThomas Huth TCGv r_dst; 1125fcf5ef2aSThomas Huth 1126fcf5ef2aSThomas Huth /* For now we still generate a straight boolean result. */ 1127fcf5ef2aSThomas Huth cmp->cond = TCG_COND_NE; 1128fcf5ef2aSThomas Huth cmp->c1 = r_dst = tcg_temp_new(); 1129c8507ebfSRichard Henderson cmp->c2 = 0; 1130fcf5ef2aSThomas Huth 1131fcf5ef2aSThomas Huth switch (cc) { 1132fcf5ef2aSThomas Huth default: 1133fcf5ef2aSThomas Huth case 0x0: 1134fcf5ef2aSThomas Huth offset = 0; 1135fcf5ef2aSThomas Huth break; 1136fcf5ef2aSThomas Huth case 0x1: 1137fcf5ef2aSThomas Huth offset = 32 - 10; 1138fcf5ef2aSThomas Huth break; 1139fcf5ef2aSThomas Huth case 0x2: 1140fcf5ef2aSThomas Huth offset = 34 - 10; 1141fcf5ef2aSThomas Huth break; 1142fcf5ef2aSThomas Huth case 0x3: 1143fcf5ef2aSThomas Huth offset = 36 - 10; 1144fcf5ef2aSThomas Huth break; 1145fcf5ef2aSThomas Huth } 1146fcf5ef2aSThomas Huth 1147fcf5ef2aSThomas Huth switch (cond) { 1148fcf5ef2aSThomas Huth case 0x0: 1149fcf5ef2aSThomas Huth gen_op_eval_bn(r_dst); 1150fcf5ef2aSThomas Huth break; 1151fcf5ef2aSThomas Huth case 0x1: 1152fcf5ef2aSThomas Huth gen_op_eval_fbne(r_dst, cpu_fsr, offset); 1153fcf5ef2aSThomas Huth break; 1154fcf5ef2aSThomas Huth case 0x2: 1155fcf5ef2aSThomas Huth gen_op_eval_fblg(r_dst, cpu_fsr, offset); 1156fcf5ef2aSThomas Huth break; 1157fcf5ef2aSThomas Huth case 0x3: 1158fcf5ef2aSThomas Huth gen_op_eval_fbul(r_dst, cpu_fsr, offset); 1159fcf5ef2aSThomas Huth break; 1160fcf5ef2aSThomas Huth case 0x4: 1161fcf5ef2aSThomas Huth gen_op_eval_fbl(r_dst, cpu_fsr, offset); 1162fcf5ef2aSThomas Huth break; 1163fcf5ef2aSThomas Huth case 0x5: 1164fcf5ef2aSThomas Huth gen_op_eval_fbug(r_dst, cpu_fsr, offset); 1165fcf5ef2aSThomas Huth break; 1166fcf5ef2aSThomas Huth case 0x6: 1167fcf5ef2aSThomas Huth gen_op_eval_fbg(r_dst, cpu_fsr, offset); 1168fcf5ef2aSThomas Huth break; 1169fcf5ef2aSThomas Huth case 0x7: 1170fcf5ef2aSThomas Huth gen_op_eval_fbu(r_dst, cpu_fsr, offset); 1171fcf5ef2aSThomas Huth break; 1172fcf5ef2aSThomas Huth case 0x8: 1173fcf5ef2aSThomas Huth gen_op_eval_ba(r_dst); 1174fcf5ef2aSThomas Huth break; 1175fcf5ef2aSThomas Huth case 0x9: 1176fcf5ef2aSThomas Huth gen_op_eval_fbe(r_dst, cpu_fsr, offset); 1177fcf5ef2aSThomas Huth break; 1178fcf5ef2aSThomas Huth case 0xa: 1179fcf5ef2aSThomas Huth gen_op_eval_fbue(r_dst, cpu_fsr, offset); 1180fcf5ef2aSThomas Huth break; 1181fcf5ef2aSThomas Huth case 0xb: 1182fcf5ef2aSThomas Huth gen_op_eval_fbge(r_dst, cpu_fsr, offset); 1183fcf5ef2aSThomas Huth break; 1184fcf5ef2aSThomas Huth case 0xc: 1185fcf5ef2aSThomas Huth gen_op_eval_fbuge(r_dst, cpu_fsr, offset); 1186fcf5ef2aSThomas Huth break; 1187fcf5ef2aSThomas Huth case 0xd: 1188fcf5ef2aSThomas Huth gen_op_eval_fble(r_dst, cpu_fsr, offset); 1189fcf5ef2aSThomas Huth break; 1190fcf5ef2aSThomas Huth case 0xe: 1191fcf5ef2aSThomas Huth gen_op_eval_fbule(r_dst, cpu_fsr, offset); 1192fcf5ef2aSThomas Huth break; 1193fcf5ef2aSThomas Huth case 0xf: 1194fcf5ef2aSThomas Huth gen_op_eval_fbo(r_dst, cpu_fsr, offset); 1195fcf5ef2aSThomas Huth break; 1196fcf5ef2aSThomas Huth } 1197fcf5ef2aSThomas Huth } 1198fcf5ef2aSThomas Huth 11992c4f56c9SRichard Henderson static bool gen_compare_reg(DisasCompare *cmp, int cond, TCGv r_src) 12002c4f56c9SRichard Henderson { 12012c4f56c9SRichard Henderson static const TCGCond cond_reg[4] = { 1202ab9ffe98SRichard Henderson TCG_COND_NEVER, /* reserved */ 1203fcf5ef2aSThomas Huth TCG_COND_EQ, 1204fcf5ef2aSThomas Huth TCG_COND_LE, 1205fcf5ef2aSThomas Huth TCG_COND_LT, 1206fcf5ef2aSThomas Huth }; 12072c4f56c9SRichard Henderson TCGCond tcond; 1208fcf5ef2aSThomas Huth 12092c4f56c9SRichard Henderson if ((cond & 3) == 0) { 12102c4f56c9SRichard Henderson return false; 12112c4f56c9SRichard Henderson } 12122c4f56c9SRichard Henderson tcond = cond_reg[cond & 3]; 12132c4f56c9SRichard Henderson if (cond & 4) { 12142c4f56c9SRichard Henderson tcond = tcg_invert_cond(tcond); 12152c4f56c9SRichard Henderson } 12162c4f56c9SRichard Henderson 12172c4f56c9SRichard Henderson cmp->cond = tcond; 1218816f89b7SRichard Henderson cmp->c1 = tcg_temp_new(); 1219c8507ebfSRichard Henderson cmp->c2 = 0; 1220816f89b7SRichard Henderson tcg_gen_mov_tl(cmp->c1, r_src); 12212c4f56c9SRichard Henderson return true; 1222fcf5ef2aSThomas Huth } 1223fcf5ef2aSThomas Huth 1224baf3dbf2SRichard Henderson static void gen_op_clear_ieee_excp_and_FTT(void) 1225baf3dbf2SRichard Henderson { 1226baf3dbf2SRichard Henderson tcg_gen_andi_tl(cpu_fsr, cpu_fsr, FSR_FTT_CEXC_NMASK); 1227baf3dbf2SRichard Henderson } 1228baf3dbf2SRichard Henderson 1229baf3dbf2SRichard Henderson static void gen_op_fmovs(TCGv_i32 dst, TCGv_i32 src) 1230baf3dbf2SRichard Henderson { 1231baf3dbf2SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 1232baf3dbf2SRichard Henderson tcg_gen_mov_i32(dst, src); 1233baf3dbf2SRichard Henderson } 1234baf3dbf2SRichard Henderson 1235baf3dbf2SRichard Henderson static void gen_op_fnegs(TCGv_i32 dst, TCGv_i32 src) 1236baf3dbf2SRichard Henderson { 1237baf3dbf2SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 1238daf457d4SRichard Henderson tcg_gen_xori_i32(dst, src, 1u << 31); 1239baf3dbf2SRichard Henderson } 1240baf3dbf2SRichard Henderson 1241baf3dbf2SRichard Henderson static void gen_op_fabss(TCGv_i32 dst, TCGv_i32 src) 1242baf3dbf2SRichard Henderson { 1243baf3dbf2SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 1244daf457d4SRichard Henderson tcg_gen_andi_i32(dst, src, ~(1u << 31)); 1245baf3dbf2SRichard Henderson } 1246baf3dbf2SRichard Henderson 1247c6d83e4fSRichard Henderson static void gen_op_fmovd(TCGv_i64 dst, TCGv_i64 src) 1248c6d83e4fSRichard Henderson { 1249c6d83e4fSRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 1250c6d83e4fSRichard Henderson tcg_gen_mov_i64(dst, src); 1251c6d83e4fSRichard Henderson } 1252c6d83e4fSRichard Henderson 1253c6d83e4fSRichard Henderson static void gen_op_fnegd(TCGv_i64 dst, TCGv_i64 src) 1254c6d83e4fSRichard Henderson { 1255c6d83e4fSRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 1256daf457d4SRichard Henderson tcg_gen_xori_i64(dst, src, 1ull << 63); 1257c6d83e4fSRichard Henderson } 1258c6d83e4fSRichard Henderson 1259c6d83e4fSRichard Henderson static void gen_op_fabsd(TCGv_i64 dst, TCGv_i64 src) 1260c6d83e4fSRichard Henderson { 1261c6d83e4fSRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 1262daf457d4SRichard Henderson tcg_gen_andi_i64(dst, src, ~(1ull << 63)); 1263daf457d4SRichard Henderson } 1264daf457d4SRichard Henderson 1265daf457d4SRichard Henderson static void gen_op_fnegq(TCGv_i128 dst, TCGv_i128 src) 1266daf457d4SRichard Henderson { 1267daf457d4SRichard Henderson TCGv_i64 l = tcg_temp_new_i64(); 1268daf457d4SRichard Henderson TCGv_i64 h = tcg_temp_new_i64(); 1269daf457d4SRichard Henderson 1270daf457d4SRichard Henderson tcg_gen_extr_i128_i64(l, h, src); 1271daf457d4SRichard Henderson tcg_gen_xori_i64(h, h, 1ull << 63); 1272daf457d4SRichard Henderson tcg_gen_concat_i64_i128(dst, l, h); 1273daf457d4SRichard Henderson } 1274daf457d4SRichard Henderson 1275daf457d4SRichard Henderson static void gen_op_fabsq(TCGv_i128 dst, TCGv_i128 src) 1276daf457d4SRichard Henderson { 1277daf457d4SRichard Henderson TCGv_i64 l = tcg_temp_new_i64(); 1278daf457d4SRichard Henderson TCGv_i64 h = tcg_temp_new_i64(); 1279daf457d4SRichard Henderson 1280daf457d4SRichard Henderson tcg_gen_extr_i128_i64(l, h, src); 1281daf457d4SRichard Henderson tcg_gen_andi_i64(h, h, ~(1ull << 63)); 1282daf457d4SRichard Henderson tcg_gen_concat_i64_i128(dst, l, h); 1283c6d83e4fSRichard Henderson } 1284c6d83e4fSRichard Henderson 1285fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64 12860c2e96c1SRichard Henderson static void gen_op_fcmps(int fccno, TCGv_i32 r_rs1, TCGv_i32 r_rs2) 1287fcf5ef2aSThomas Huth { 1288fcf5ef2aSThomas Huth switch (fccno) { 1289fcf5ef2aSThomas Huth case 0: 1290ad75a51eSRichard Henderson gen_helper_fcmps(cpu_fsr, tcg_env, r_rs1, r_rs2); 1291fcf5ef2aSThomas Huth break; 1292fcf5ef2aSThomas Huth case 1: 1293ad75a51eSRichard Henderson gen_helper_fcmps_fcc1(cpu_fsr, tcg_env, r_rs1, r_rs2); 1294fcf5ef2aSThomas Huth break; 1295fcf5ef2aSThomas Huth case 2: 1296ad75a51eSRichard Henderson gen_helper_fcmps_fcc2(cpu_fsr, tcg_env, r_rs1, r_rs2); 1297fcf5ef2aSThomas Huth break; 1298fcf5ef2aSThomas Huth case 3: 1299ad75a51eSRichard Henderson gen_helper_fcmps_fcc3(cpu_fsr, tcg_env, r_rs1, r_rs2); 1300fcf5ef2aSThomas Huth break; 1301fcf5ef2aSThomas Huth } 1302fcf5ef2aSThomas Huth } 1303fcf5ef2aSThomas Huth 13040c2e96c1SRichard Henderson static void gen_op_fcmpd(int fccno, TCGv_i64 r_rs1, TCGv_i64 r_rs2) 1305fcf5ef2aSThomas Huth { 1306fcf5ef2aSThomas Huth switch (fccno) { 1307fcf5ef2aSThomas Huth case 0: 1308ad75a51eSRichard Henderson gen_helper_fcmpd(cpu_fsr, tcg_env, r_rs1, r_rs2); 1309fcf5ef2aSThomas Huth break; 1310fcf5ef2aSThomas Huth case 1: 1311ad75a51eSRichard Henderson gen_helper_fcmpd_fcc1(cpu_fsr, tcg_env, r_rs1, r_rs2); 1312fcf5ef2aSThomas Huth break; 1313fcf5ef2aSThomas Huth case 2: 1314ad75a51eSRichard Henderson gen_helper_fcmpd_fcc2(cpu_fsr, tcg_env, r_rs1, r_rs2); 1315fcf5ef2aSThomas Huth break; 1316fcf5ef2aSThomas Huth case 3: 1317ad75a51eSRichard Henderson gen_helper_fcmpd_fcc3(cpu_fsr, tcg_env, r_rs1, r_rs2); 1318fcf5ef2aSThomas Huth break; 1319fcf5ef2aSThomas Huth } 1320fcf5ef2aSThomas Huth } 1321fcf5ef2aSThomas Huth 13220c2e96c1SRichard Henderson static void gen_op_fcmpq(int fccno) 1323fcf5ef2aSThomas Huth { 1324fcf5ef2aSThomas Huth switch (fccno) { 1325fcf5ef2aSThomas Huth case 0: 1326ad75a51eSRichard Henderson gen_helper_fcmpq(cpu_fsr, tcg_env); 1327fcf5ef2aSThomas Huth break; 1328fcf5ef2aSThomas Huth case 1: 1329ad75a51eSRichard Henderson gen_helper_fcmpq_fcc1(cpu_fsr, tcg_env); 1330fcf5ef2aSThomas Huth break; 1331fcf5ef2aSThomas Huth case 2: 1332ad75a51eSRichard Henderson gen_helper_fcmpq_fcc2(cpu_fsr, tcg_env); 1333fcf5ef2aSThomas Huth break; 1334fcf5ef2aSThomas Huth case 3: 1335ad75a51eSRichard Henderson gen_helper_fcmpq_fcc3(cpu_fsr, tcg_env); 1336fcf5ef2aSThomas Huth break; 1337fcf5ef2aSThomas Huth } 1338fcf5ef2aSThomas Huth } 1339fcf5ef2aSThomas Huth 13400c2e96c1SRichard Henderson static void gen_op_fcmpes(int fccno, TCGv_i32 r_rs1, TCGv_i32 r_rs2) 1341fcf5ef2aSThomas Huth { 1342fcf5ef2aSThomas Huth switch (fccno) { 1343fcf5ef2aSThomas Huth case 0: 1344ad75a51eSRichard Henderson gen_helper_fcmpes(cpu_fsr, tcg_env, r_rs1, r_rs2); 1345fcf5ef2aSThomas Huth break; 1346fcf5ef2aSThomas Huth case 1: 1347ad75a51eSRichard Henderson gen_helper_fcmpes_fcc1(cpu_fsr, tcg_env, r_rs1, r_rs2); 1348fcf5ef2aSThomas Huth break; 1349fcf5ef2aSThomas Huth case 2: 1350ad75a51eSRichard Henderson gen_helper_fcmpes_fcc2(cpu_fsr, tcg_env, r_rs1, r_rs2); 1351fcf5ef2aSThomas Huth break; 1352fcf5ef2aSThomas Huth case 3: 1353ad75a51eSRichard Henderson gen_helper_fcmpes_fcc3(cpu_fsr, tcg_env, r_rs1, r_rs2); 1354fcf5ef2aSThomas Huth break; 1355fcf5ef2aSThomas Huth } 1356fcf5ef2aSThomas Huth } 1357fcf5ef2aSThomas Huth 13580c2e96c1SRichard Henderson static void gen_op_fcmped(int fccno, TCGv_i64 r_rs1, TCGv_i64 r_rs2) 1359fcf5ef2aSThomas Huth { 1360fcf5ef2aSThomas Huth switch (fccno) { 1361fcf5ef2aSThomas Huth case 0: 1362ad75a51eSRichard Henderson gen_helper_fcmped(cpu_fsr, tcg_env, r_rs1, r_rs2); 1363fcf5ef2aSThomas Huth break; 1364fcf5ef2aSThomas Huth case 1: 1365ad75a51eSRichard Henderson gen_helper_fcmped_fcc1(cpu_fsr, tcg_env, r_rs1, r_rs2); 1366fcf5ef2aSThomas Huth break; 1367fcf5ef2aSThomas Huth case 2: 1368ad75a51eSRichard Henderson gen_helper_fcmped_fcc2(cpu_fsr, tcg_env, r_rs1, r_rs2); 1369fcf5ef2aSThomas Huth break; 1370fcf5ef2aSThomas Huth case 3: 1371ad75a51eSRichard Henderson gen_helper_fcmped_fcc3(cpu_fsr, tcg_env, r_rs1, r_rs2); 1372fcf5ef2aSThomas Huth break; 1373fcf5ef2aSThomas Huth } 1374fcf5ef2aSThomas Huth } 1375fcf5ef2aSThomas Huth 13760c2e96c1SRichard Henderson static void gen_op_fcmpeq(int fccno) 1377fcf5ef2aSThomas Huth { 1378fcf5ef2aSThomas Huth switch (fccno) { 1379fcf5ef2aSThomas Huth case 0: 1380ad75a51eSRichard Henderson gen_helper_fcmpeq(cpu_fsr, tcg_env); 1381fcf5ef2aSThomas Huth break; 1382fcf5ef2aSThomas Huth case 1: 1383ad75a51eSRichard Henderson gen_helper_fcmpeq_fcc1(cpu_fsr, tcg_env); 1384fcf5ef2aSThomas Huth break; 1385fcf5ef2aSThomas Huth case 2: 1386ad75a51eSRichard Henderson gen_helper_fcmpeq_fcc2(cpu_fsr, tcg_env); 1387fcf5ef2aSThomas Huth break; 1388fcf5ef2aSThomas Huth case 3: 1389ad75a51eSRichard Henderson gen_helper_fcmpeq_fcc3(cpu_fsr, tcg_env); 1390fcf5ef2aSThomas Huth break; 1391fcf5ef2aSThomas Huth } 1392fcf5ef2aSThomas Huth } 1393fcf5ef2aSThomas Huth 1394fcf5ef2aSThomas Huth #else 1395fcf5ef2aSThomas Huth 13960c2e96c1SRichard Henderson static void gen_op_fcmps(int fccno, TCGv r_rs1, TCGv r_rs2) 1397fcf5ef2aSThomas Huth { 1398ad75a51eSRichard Henderson gen_helper_fcmps(cpu_fsr, tcg_env, r_rs1, r_rs2); 1399fcf5ef2aSThomas Huth } 1400fcf5ef2aSThomas Huth 14010c2e96c1SRichard Henderson static void gen_op_fcmpd(int fccno, TCGv_i64 r_rs1, TCGv_i64 r_rs2) 1402fcf5ef2aSThomas Huth { 1403ad75a51eSRichard Henderson gen_helper_fcmpd(cpu_fsr, tcg_env, r_rs1, r_rs2); 1404fcf5ef2aSThomas Huth } 1405fcf5ef2aSThomas Huth 14060c2e96c1SRichard Henderson static void gen_op_fcmpq(int fccno) 1407fcf5ef2aSThomas Huth { 1408ad75a51eSRichard Henderson gen_helper_fcmpq(cpu_fsr, tcg_env); 1409fcf5ef2aSThomas Huth } 1410fcf5ef2aSThomas Huth 14110c2e96c1SRichard Henderson static void gen_op_fcmpes(int fccno, TCGv r_rs1, TCGv r_rs2) 1412fcf5ef2aSThomas Huth { 1413ad75a51eSRichard Henderson gen_helper_fcmpes(cpu_fsr, tcg_env, r_rs1, r_rs2); 1414fcf5ef2aSThomas Huth } 1415fcf5ef2aSThomas Huth 14160c2e96c1SRichard Henderson static void gen_op_fcmped(int fccno, TCGv_i64 r_rs1, TCGv_i64 r_rs2) 1417fcf5ef2aSThomas Huth { 1418ad75a51eSRichard Henderson gen_helper_fcmped(cpu_fsr, tcg_env, r_rs1, r_rs2); 1419fcf5ef2aSThomas Huth } 1420fcf5ef2aSThomas Huth 14210c2e96c1SRichard Henderson static void gen_op_fcmpeq(int fccno) 1422fcf5ef2aSThomas Huth { 1423ad75a51eSRichard Henderson gen_helper_fcmpeq(cpu_fsr, tcg_env); 1424fcf5ef2aSThomas Huth } 1425fcf5ef2aSThomas Huth #endif 1426fcf5ef2aSThomas Huth 1427fcf5ef2aSThomas Huth static void gen_op_fpexception_im(DisasContext *dc, int fsr_flags) 1428fcf5ef2aSThomas Huth { 1429fcf5ef2aSThomas Huth tcg_gen_andi_tl(cpu_fsr, cpu_fsr, FSR_FTT_NMASK); 1430fcf5ef2aSThomas Huth tcg_gen_ori_tl(cpu_fsr, cpu_fsr, fsr_flags); 1431fcf5ef2aSThomas Huth gen_exception(dc, TT_FP_EXCP); 1432fcf5ef2aSThomas Huth } 1433fcf5ef2aSThomas Huth 1434fcf5ef2aSThomas Huth static int gen_trap_ifnofpu(DisasContext *dc) 1435fcf5ef2aSThomas Huth { 1436fcf5ef2aSThomas Huth #if !defined(CONFIG_USER_ONLY) 1437fcf5ef2aSThomas Huth if (!dc->fpu_enabled) { 1438fcf5ef2aSThomas Huth gen_exception(dc, TT_NFPU_INSN); 1439fcf5ef2aSThomas Huth return 1; 1440fcf5ef2aSThomas Huth } 1441fcf5ef2aSThomas Huth #endif 1442fcf5ef2aSThomas Huth return 0; 1443fcf5ef2aSThomas Huth } 1444fcf5ef2aSThomas Huth 1445fcf5ef2aSThomas Huth /* asi moves */ 1446fcf5ef2aSThomas Huth typedef enum { 1447fcf5ef2aSThomas Huth GET_ASI_HELPER, 1448fcf5ef2aSThomas Huth GET_ASI_EXCP, 1449fcf5ef2aSThomas Huth GET_ASI_DIRECT, 1450fcf5ef2aSThomas Huth GET_ASI_DTWINX, 1451fcf5ef2aSThomas Huth GET_ASI_BLOCK, 1452fcf5ef2aSThomas Huth GET_ASI_SHORT, 1453fcf5ef2aSThomas Huth GET_ASI_BCOPY, 1454fcf5ef2aSThomas Huth GET_ASI_BFILL, 1455fcf5ef2aSThomas Huth } ASIType; 1456fcf5ef2aSThomas Huth 1457fcf5ef2aSThomas Huth typedef struct { 1458fcf5ef2aSThomas Huth ASIType type; 1459fcf5ef2aSThomas Huth int asi; 1460fcf5ef2aSThomas Huth int mem_idx; 146114776ab5STony Nguyen MemOp memop; 1462fcf5ef2aSThomas Huth } DisasASI; 1463fcf5ef2aSThomas Huth 1464811cc0b0SRichard Henderson /* 1465811cc0b0SRichard Henderson * Build DisasASI. 1466811cc0b0SRichard Henderson * For asi == -1, treat as non-asi. 1467811cc0b0SRichard Henderson * For ask == -2, treat as immediate offset (v8 error, v9 %asi). 1468811cc0b0SRichard Henderson */ 1469811cc0b0SRichard Henderson static DisasASI resolve_asi(DisasContext *dc, int asi, MemOp memop) 1470fcf5ef2aSThomas Huth { 1471fcf5ef2aSThomas Huth ASIType type = GET_ASI_HELPER; 1472fcf5ef2aSThomas Huth int mem_idx = dc->mem_idx; 1473fcf5ef2aSThomas Huth 1474811cc0b0SRichard Henderson if (asi == -1) { 1475811cc0b0SRichard Henderson /* Artificial "non-asi" case. */ 1476811cc0b0SRichard Henderson type = GET_ASI_DIRECT; 1477811cc0b0SRichard Henderson goto done; 1478811cc0b0SRichard Henderson } 1479811cc0b0SRichard Henderson 1480fcf5ef2aSThomas Huth #ifndef TARGET_SPARC64 1481fcf5ef2aSThomas Huth /* Before v9, all asis are immediate and privileged. */ 1482811cc0b0SRichard Henderson if (asi < 0) { 1483fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 1484fcf5ef2aSThomas Huth type = GET_ASI_EXCP; 1485fcf5ef2aSThomas Huth } else if (supervisor(dc) 1486fcf5ef2aSThomas Huth /* Note that LEON accepts ASI_USERDATA in user mode, for 1487fcf5ef2aSThomas Huth use with CASA. Also note that previous versions of 1488fcf5ef2aSThomas Huth QEMU allowed (and old versions of gcc emitted) ASI_P 1489fcf5ef2aSThomas Huth for LEON, which is incorrect. */ 1490fcf5ef2aSThomas Huth || (asi == ASI_USERDATA 1491fcf5ef2aSThomas Huth && (dc->def->features & CPU_FEATURE_CASA))) { 1492fcf5ef2aSThomas Huth switch (asi) { 1493fcf5ef2aSThomas Huth case ASI_USERDATA: /* User data access */ 1494fcf5ef2aSThomas Huth mem_idx = MMU_USER_IDX; 1495fcf5ef2aSThomas Huth type = GET_ASI_DIRECT; 1496fcf5ef2aSThomas Huth break; 1497fcf5ef2aSThomas Huth case ASI_KERNELDATA: /* Supervisor data access */ 1498fcf5ef2aSThomas Huth mem_idx = MMU_KERNEL_IDX; 1499fcf5ef2aSThomas Huth type = GET_ASI_DIRECT; 1500fcf5ef2aSThomas Huth break; 1501fcf5ef2aSThomas Huth case ASI_M_BYPASS: /* MMU passthrough */ 1502fcf5ef2aSThomas Huth case ASI_LEON_BYPASS: /* LEON MMU passthrough */ 1503fcf5ef2aSThomas Huth mem_idx = MMU_PHYS_IDX; 1504fcf5ef2aSThomas Huth type = GET_ASI_DIRECT; 1505fcf5ef2aSThomas Huth break; 1506fcf5ef2aSThomas Huth case ASI_M_BCOPY: /* Block copy, sta access */ 1507fcf5ef2aSThomas Huth mem_idx = MMU_KERNEL_IDX; 1508fcf5ef2aSThomas Huth type = GET_ASI_BCOPY; 1509fcf5ef2aSThomas Huth break; 1510fcf5ef2aSThomas Huth case ASI_M_BFILL: /* Block fill, stda access */ 1511fcf5ef2aSThomas Huth mem_idx = MMU_KERNEL_IDX; 1512fcf5ef2aSThomas Huth type = GET_ASI_BFILL; 1513fcf5ef2aSThomas Huth break; 1514fcf5ef2aSThomas Huth } 15156e10f37cSKONRAD Frederic 15166e10f37cSKONRAD Frederic /* MMU_PHYS_IDX is used when the MMU is disabled to passthrough the 15176e10f37cSKONRAD Frederic * permissions check in get_physical_address(..). 15186e10f37cSKONRAD Frederic */ 15196e10f37cSKONRAD Frederic mem_idx = (dc->mem_idx == MMU_PHYS_IDX) ? MMU_PHYS_IDX : mem_idx; 1520fcf5ef2aSThomas Huth } else { 1521fcf5ef2aSThomas Huth gen_exception(dc, TT_PRIV_INSN); 1522fcf5ef2aSThomas Huth type = GET_ASI_EXCP; 1523fcf5ef2aSThomas Huth } 1524fcf5ef2aSThomas Huth #else 1525811cc0b0SRichard Henderson if (asi < 0) { 1526fcf5ef2aSThomas Huth asi = dc->asi; 1527fcf5ef2aSThomas Huth } 1528fcf5ef2aSThomas Huth /* With v9, all asis below 0x80 are privileged. */ 1529fcf5ef2aSThomas Huth /* ??? We ought to check cpu_has_hypervisor, but we didn't copy 1530fcf5ef2aSThomas Huth down that bit into DisasContext. For the moment that's ok, 1531fcf5ef2aSThomas Huth since the direct implementations below doesn't have any ASIs 1532fcf5ef2aSThomas Huth in the restricted [0x30, 0x7f] range, and the check will be 1533fcf5ef2aSThomas Huth done properly in the helper. */ 1534fcf5ef2aSThomas Huth if (!supervisor(dc) && asi < 0x80) { 1535fcf5ef2aSThomas Huth gen_exception(dc, TT_PRIV_ACT); 1536fcf5ef2aSThomas Huth type = GET_ASI_EXCP; 1537fcf5ef2aSThomas Huth } else { 1538fcf5ef2aSThomas Huth switch (asi) { 1539fcf5ef2aSThomas Huth case ASI_REAL: /* Bypass */ 1540fcf5ef2aSThomas Huth case ASI_REAL_IO: /* Bypass, non-cacheable */ 1541fcf5ef2aSThomas Huth case ASI_REAL_L: /* Bypass LE */ 1542fcf5ef2aSThomas Huth case ASI_REAL_IO_L: /* Bypass, non-cacheable LE */ 1543fcf5ef2aSThomas Huth case ASI_TWINX_REAL: /* Real address, twinx */ 1544fcf5ef2aSThomas Huth case ASI_TWINX_REAL_L: /* Real address, twinx, LE */ 1545fcf5ef2aSThomas Huth case ASI_QUAD_LDD_PHYS: 1546fcf5ef2aSThomas Huth case ASI_QUAD_LDD_PHYS_L: 1547fcf5ef2aSThomas Huth mem_idx = MMU_PHYS_IDX; 1548fcf5ef2aSThomas Huth break; 1549fcf5ef2aSThomas Huth case ASI_N: /* Nucleus */ 1550fcf5ef2aSThomas Huth case ASI_NL: /* Nucleus LE */ 1551fcf5ef2aSThomas Huth case ASI_TWINX_N: 1552fcf5ef2aSThomas Huth case ASI_TWINX_NL: 1553fcf5ef2aSThomas Huth case ASI_NUCLEUS_QUAD_LDD: 1554fcf5ef2aSThomas Huth case ASI_NUCLEUS_QUAD_LDD_L: 15559a10756dSArtyom Tarasenko if (hypervisor(dc)) { 155684f8f587SArtyom Tarasenko mem_idx = MMU_PHYS_IDX; 15579a10756dSArtyom Tarasenko } else { 1558fcf5ef2aSThomas Huth mem_idx = MMU_NUCLEUS_IDX; 15599a10756dSArtyom Tarasenko } 1560fcf5ef2aSThomas Huth break; 1561fcf5ef2aSThomas Huth case ASI_AIUP: /* As if user primary */ 1562fcf5ef2aSThomas Huth case ASI_AIUPL: /* As if user primary LE */ 1563fcf5ef2aSThomas Huth case ASI_TWINX_AIUP: 1564fcf5ef2aSThomas Huth case ASI_TWINX_AIUP_L: 1565fcf5ef2aSThomas Huth case ASI_BLK_AIUP_4V: 1566fcf5ef2aSThomas Huth case ASI_BLK_AIUP_L_4V: 1567fcf5ef2aSThomas Huth case ASI_BLK_AIUP: 1568fcf5ef2aSThomas Huth case ASI_BLK_AIUPL: 1569fcf5ef2aSThomas Huth mem_idx = MMU_USER_IDX; 1570fcf5ef2aSThomas Huth break; 1571fcf5ef2aSThomas Huth case ASI_AIUS: /* As if user secondary */ 1572fcf5ef2aSThomas Huth case ASI_AIUSL: /* As if user secondary LE */ 1573fcf5ef2aSThomas Huth case ASI_TWINX_AIUS: 1574fcf5ef2aSThomas Huth case ASI_TWINX_AIUS_L: 1575fcf5ef2aSThomas Huth case ASI_BLK_AIUS_4V: 1576fcf5ef2aSThomas Huth case ASI_BLK_AIUS_L_4V: 1577fcf5ef2aSThomas Huth case ASI_BLK_AIUS: 1578fcf5ef2aSThomas Huth case ASI_BLK_AIUSL: 1579fcf5ef2aSThomas Huth mem_idx = MMU_USER_SECONDARY_IDX; 1580fcf5ef2aSThomas Huth break; 1581fcf5ef2aSThomas Huth case ASI_S: /* Secondary */ 1582fcf5ef2aSThomas Huth case ASI_SL: /* Secondary LE */ 1583fcf5ef2aSThomas Huth case ASI_TWINX_S: 1584fcf5ef2aSThomas Huth case ASI_TWINX_SL: 1585fcf5ef2aSThomas Huth case ASI_BLK_COMMIT_S: 1586fcf5ef2aSThomas Huth case ASI_BLK_S: 1587fcf5ef2aSThomas Huth case ASI_BLK_SL: 1588fcf5ef2aSThomas Huth case ASI_FL8_S: 1589fcf5ef2aSThomas Huth case ASI_FL8_SL: 1590fcf5ef2aSThomas Huth case ASI_FL16_S: 1591fcf5ef2aSThomas Huth case ASI_FL16_SL: 1592fcf5ef2aSThomas Huth if (mem_idx == MMU_USER_IDX) { 1593fcf5ef2aSThomas Huth mem_idx = MMU_USER_SECONDARY_IDX; 1594fcf5ef2aSThomas Huth } else if (mem_idx == MMU_KERNEL_IDX) { 1595fcf5ef2aSThomas Huth mem_idx = MMU_KERNEL_SECONDARY_IDX; 1596fcf5ef2aSThomas Huth } 1597fcf5ef2aSThomas Huth break; 1598fcf5ef2aSThomas Huth case ASI_P: /* Primary */ 1599fcf5ef2aSThomas Huth case ASI_PL: /* Primary LE */ 1600fcf5ef2aSThomas Huth case ASI_TWINX_P: 1601fcf5ef2aSThomas Huth case ASI_TWINX_PL: 1602fcf5ef2aSThomas Huth case ASI_BLK_COMMIT_P: 1603fcf5ef2aSThomas Huth case ASI_BLK_P: 1604fcf5ef2aSThomas Huth case ASI_BLK_PL: 1605fcf5ef2aSThomas Huth case ASI_FL8_P: 1606fcf5ef2aSThomas Huth case ASI_FL8_PL: 1607fcf5ef2aSThomas Huth case ASI_FL16_P: 1608fcf5ef2aSThomas Huth case ASI_FL16_PL: 1609fcf5ef2aSThomas Huth break; 1610fcf5ef2aSThomas Huth } 1611fcf5ef2aSThomas Huth switch (asi) { 1612fcf5ef2aSThomas Huth case ASI_REAL: 1613fcf5ef2aSThomas Huth case ASI_REAL_IO: 1614fcf5ef2aSThomas Huth case ASI_REAL_L: 1615fcf5ef2aSThomas Huth case ASI_REAL_IO_L: 1616fcf5ef2aSThomas Huth case ASI_N: 1617fcf5ef2aSThomas Huth case ASI_NL: 1618fcf5ef2aSThomas Huth case ASI_AIUP: 1619fcf5ef2aSThomas Huth case ASI_AIUPL: 1620fcf5ef2aSThomas Huth case ASI_AIUS: 1621fcf5ef2aSThomas Huth case ASI_AIUSL: 1622fcf5ef2aSThomas Huth case ASI_S: 1623fcf5ef2aSThomas Huth case ASI_SL: 1624fcf5ef2aSThomas Huth case ASI_P: 1625fcf5ef2aSThomas Huth case ASI_PL: 1626fcf5ef2aSThomas Huth type = GET_ASI_DIRECT; 1627fcf5ef2aSThomas Huth break; 1628fcf5ef2aSThomas Huth case ASI_TWINX_REAL: 1629fcf5ef2aSThomas Huth case ASI_TWINX_REAL_L: 1630fcf5ef2aSThomas Huth case ASI_TWINX_N: 1631fcf5ef2aSThomas Huth case ASI_TWINX_NL: 1632fcf5ef2aSThomas Huth case ASI_TWINX_AIUP: 1633fcf5ef2aSThomas Huth case ASI_TWINX_AIUP_L: 1634fcf5ef2aSThomas Huth case ASI_TWINX_AIUS: 1635fcf5ef2aSThomas Huth case ASI_TWINX_AIUS_L: 1636fcf5ef2aSThomas Huth case ASI_TWINX_P: 1637fcf5ef2aSThomas Huth case ASI_TWINX_PL: 1638fcf5ef2aSThomas Huth case ASI_TWINX_S: 1639fcf5ef2aSThomas Huth case ASI_TWINX_SL: 1640fcf5ef2aSThomas Huth case ASI_QUAD_LDD_PHYS: 1641fcf5ef2aSThomas Huth case ASI_QUAD_LDD_PHYS_L: 1642fcf5ef2aSThomas Huth case ASI_NUCLEUS_QUAD_LDD: 1643fcf5ef2aSThomas Huth case ASI_NUCLEUS_QUAD_LDD_L: 1644fcf5ef2aSThomas Huth type = GET_ASI_DTWINX; 1645fcf5ef2aSThomas Huth break; 1646fcf5ef2aSThomas Huth case ASI_BLK_COMMIT_P: 1647fcf5ef2aSThomas Huth case ASI_BLK_COMMIT_S: 1648fcf5ef2aSThomas Huth case ASI_BLK_AIUP_4V: 1649fcf5ef2aSThomas Huth case ASI_BLK_AIUP_L_4V: 1650fcf5ef2aSThomas Huth case ASI_BLK_AIUP: 1651fcf5ef2aSThomas Huth case ASI_BLK_AIUPL: 1652fcf5ef2aSThomas Huth case ASI_BLK_AIUS_4V: 1653fcf5ef2aSThomas Huth case ASI_BLK_AIUS_L_4V: 1654fcf5ef2aSThomas Huth case ASI_BLK_AIUS: 1655fcf5ef2aSThomas Huth case ASI_BLK_AIUSL: 1656fcf5ef2aSThomas Huth case ASI_BLK_S: 1657fcf5ef2aSThomas Huth case ASI_BLK_SL: 1658fcf5ef2aSThomas Huth case ASI_BLK_P: 1659fcf5ef2aSThomas Huth case ASI_BLK_PL: 1660fcf5ef2aSThomas Huth type = GET_ASI_BLOCK; 1661fcf5ef2aSThomas Huth break; 1662fcf5ef2aSThomas Huth case ASI_FL8_S: 1663fcf5ef2aSThomas Huth case ASI_FL8_SL: 1664fcf5ef2aSThomas Huth case ASI_FL8_P: 1665fcf5ef2aSThomas Huth case ASI_FL8_PL: 1666fcf5ef2aSThomas Huth memop = MO_UB; 1667fcf5ef2aSThomas Huth type = GET_ASI_SHORT; 1668fcf5ef2aSThomas Huth break; 1669fcf5ef2aSThomas Huth case ASI_FL16_S: 1670fcf5ef2aSThomas Huth case ASI_FL16_SL: 1671fcf5ef2aSThomas Huth case ASI_FL16_P: 1672fcf5ef2aSThomas Huth case ASI_FL16_PL: 1673fcf5ef2aSThomas Huth memop = MO_TEUW; 1674fcf5ef2aSThomas Huth type = GET_ASI_SHORT; 1675fcf5ef2aSThomas Huth break; 1676fcf5ef2aSThomas Huth } 1677fcf5ef2aSThomas Huth /* The little-endian asis all have bit 3 set. */ 1678fcf5ef2aSThomas Huth if (asi & 8) { 1679fcf5ef2aSThomas Huth memop ^= MO_BSWAP; 1680fcf5ef2aSThomas Huth } 1681fcf5ef2aSThomas Huth } 1682fcf5ef2aSThomas Huth #endif 1683fcf5ef2aSThomas Huth 1684811cc0b0SRichard Henderson done: 1685fcf5ef2aSThomas Huth return (DisasASI){ type, asi, mem_idx, memop }; 1686fcf5ef2aSThomas Huth } 1687fcf5ef2aSThomas Huth 1688a76779eeSRichard Henderson #if defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64) 1689a76779eeSRichard Henderson static void gen_helper_ld_asi(TCGv_i64 r, TCGv_env e, TCGv a, 1690a76779eeSRichard Henderson TCGv_i32 asi, TCGv_i32 mop) 1691a76779eeSRichard Henderson { 1692a76779eeSRichard Henderson g_assert_not_reached(); 1693a76779eeSRichard Henderson } 1694a76779eeSRichard Henderson 1695a76779eeSRichard Henderson static void gen_helper_st_asi(TCGv_env e, TCGv a, TCGv_i64 r, 1696a76779eeSRichard Henderson TCGv_i32 asi, TCGv_i32 mop) 1697a76779eeSRichard Henderson { 1698a76779eeSRichard Henderson g_assert_not_reached(); 1699a76779eeSRichard Henderson } 1700a76779eeSRichard Henderson #endif 1701a76779eeSRichard Henderson 170242071fc1SRichard Henderson static void gen_ld_asi(DisasContext *dc, DisasASI *da, TCGv dst, TCGv addr) 1703fcf5ef2aSThomas Huth { 1704c03a0fd1SRichard Henderson switch (da->type) { 1705fcf5ef2aSThomas Huth case GET_ASI_EXCP: 1706fcf5ef2aSThomas Huth break; 1707fcf5ef2aSThomas Huth case GET_ASI_DTWINX: /* Reserved for ldda. */ 1708fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 1709fcf5ef2aSThomas Huth break; 1710fcf5ef2aSThomas Huth case GET_ASI_DIRECT: 1711c03a0fd1SRichard Henderson tcg_gen_qemu_ld_tl(dst, addr, da->mem_idx, da->memop | MO_ALIGN); 1712fcf5ef2aSThomas Huth break; 1713fcf5ef2aSThomas Huth default: 1714fcf5ef2aSThomas Huth { 1715c03a0fd1SRichard Henderson TCGv_i32 r_asi = tcg_constant_i32(da->asi); 1716c03a0fd1SRichard Henderson TCGv_i32 r_mop = tcg_constant_i32(da->memop | MO_ALIGN); 1717fcf5ef2aSThomas Huth 1718fcf5ef2aSThomas Huth save_state(dc); 1719fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64 1720ad75a51eSRichard Henderson gen_helper_ld_asi(dst, tcg_env, addr, r_asi, r_mop); 1721fcf5ef2aSThomas Huth #else 1722fcf5ef2aSThomas Huth { 1723fcf5ef2aSThomas Huth TCGv_i64 t64 = tcg_temp_new_i64(); 1724ad75a51eSRichard Henderson gen_helper_ld_asi(t64, tcg_env, addr, r_asi, r_mop); 1725fcf5ef2aSThomas Huth tcg_gen_trunc_i64_tl(dst, t64); 1726fcf5ef2aSThomas Huth } 1727fcf5ef2aSThomas Huth #endif 1728fcf5ef2aSThomas Huth } 1729fcf5ef2aSThomas Huth break; 1730fcf5ef2aSThomas Huth } 1731fcf5ef2aSThomas Huth } 1732fcf5ef2aSThomas Huth 173342071fc1SRichard Henderson static void gen_st_asi(DisasContext *dc, DisasASI *da, TCGv src, TCGv addr) 1734c03a0fd1SRichard Henderson { 1735c03a0fd1SRichard Henderson switch (da->type) { 1736fcf5ef2aSThomas Huth case GET_ASI_EXCP: 1737fcf5ef2aSThomas Huth break; 1738c03a0fd1SRichard Henderson 1739fcf5ef2aSThomas Huth case GET_ASI_DTWINX: /* Reserved for stda. */ 1740c03a0fd1SRichard Henderson if (TARGET_LONG_BITS == 32) { 1741fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 1742fcf5ef2aSThomas Huth break; 1743c03a0fd1SRichard Henderson } else if (!(dc->def->features & CPU_FEATURE_HYPV)) { 17443390537bSArtyom Tarasenko /* Pre OpenSPARC CPUs don't have these */ 17453390537bSArtyom Tarasenko gen_exception(dc, TT_ILL_INSN); 1746fcf5ef2aSThomas Huth break; 1747c03a0fd1SRichard Henderson } 1748c03a0fd1SRichard Henderson /* In OpenSPARC T1+ CPUs TWINX ASIs in store are ST_BLKINIT_ ASIs */ 1749c03a0fd1SRichard Henderson /* fall through */ 1750c03a0fd1SRichard Henderson 1751c03a0fd1SRichard Henderson case GET_ASI_DIRECT: 1752c03a0fd1SRichard Henderson tcg_gen_qemu_st_tl(src, addr, da->mem_idx, da->memop | MO_ALIGN); 1753c03a0fd1SRichard Henderson break; 1754c03a0fd1SRichard Henderson 1755fcf5ef2aSThomas Huth case GET_ASI_BCOPY: 1756c03a0fd1SRichard Henderson assert(TARGET_LONG_BITS == 32); 175798271007SRichard Henderson /* 175898271007SRichard Henderson * Copy 32 bytes from the address in SRC to ADDR. 175998271007SRichard Henderson * 176098271007SRichard Henderson * From Ross RT625 hyperSPARC manual, section 4.6: 176198271007SRichard Henderson * "Block Copy and Block Fill will work only on cache line boundaries." 176298271007SRichard Henderson * 176398271007SRichard Henderson * It does not specify if an unaliged address is truncated or trapped. 176498271007SRichard Henderson * Previous qemu behaviour was to truncate to 4 byte alignment, which 176598271007SRichard Henderson * is obviously wrong. The only place I can see this used is in the 176698271007SRichard Henderson * Linux kernel which begins with page alignment, advancing by 32, 176798271007SRichard Henderson * so is always aligned. Assume truncation as the simpler option. 176898271007SRichard Henderson * 176998271007SRichard Henderson * Since the loads and stores are paired, allow the copy to happen 177098271007SRichard Henderson * in the host endianness. The copy need not be atomic. 177198271007SRichard Henderson */ 1772fcf5ef2aSThomas Huth { 177398271007SRichard Henderson MemOp mop = MO_128 | MO_ATOM_IFALIGN_PAIR; 1774fcf5ef2aSThomas Huth TCGv saddr = tcg_temp_new(); 1775fcf5ef2aSThomas Huth TCGv daddr = tcg_temp_new(); 177698271007SRichard Henderson TCGv_i128 tmp = tcg_temp_new_i128(); 1777fcf5ef2aSThomas Huth 177898271007SRichard Henderson tcg_gen_andi_tl(saddr, src, -32); 177998271007SRichard Henderson tcg_gen_andi_tl(daddr, addr, -32); 178098271007SRichard Henderson tcg_gen_qemu_ld_i128(tmp, saddr, da->mem_idx, mop); 178198271007SRichard Henderson tcg_gen_qemu_st_i128(tmp, daddr, da->mem_idx, mop); 178298271007SRichard Henderson tcg_gen_addi_tl(saddr, saddr, 16); 178398271007SRichard Henderson tcg_gen_addi_tl(daddr, daddr, 16); 178498271007SRichard Henderson tcg_gen_qemu_ld_i128(tmp, saddr, da->mem_idx, mop); 178598271007SRichard Henderson tcg_gen_qemu_st_i128(tmp, daddr, da->mem_idx, mop); 1786fcf5ef2aSThomas Huth } 1787fcf5ef2aSThomas Huth break; 1788c03a0fd1SRichard Henderson 1789fcf5ef2aSThomas Huth default: 1790fcf5ef2aSThomas Huth { 1791c03a0fd1SRichard Henderson TCGv_i32 r_asi = tcg_constant_i32(da->asi); 1792c03a0fd1SRichard Henderson TCGv_i32 r_mop = tcg_constant_i32(da->memop | MO_ALIGN); 1793fcf5ef2aSThomas Huth 1794fcf5ef2aSThomas Huth save_state(dc); 1795fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64 1796ad75a51eSRichard Henderson gen_helper_st_asi(tcg_env, addr, src, r_asi, r_mop); 1797fcf5ef2aSThomas Huth #else 1798fcf5ef2aSThomas Huth { 1799fcf5ef2aSThomas Huth TCGv_i64 t64 = tcg_temp_new_i64(); 1800fcf5ef2aSThomas Huth tcg_gen_extu_tl_i64(t64, src); 1801ad75a51eSRichard Henderson gen_helper_st_asi(tcg_env, addr, t64, r_asi, r_mop); 1802fcf5ef2aSThomas Huth } 1803fcf5ef2aSThomas Huth #endif 1804fcf5ef2aSThomas Huth 1805fcf5ef2aSThomas Huth /* A write to a TLB register may alter page maps. End the TB. */ 1806fcf5ef2aSThomas Huth dc->npc = DYNAMIC_PC; 1807fcf5ef2aSThomas Huth } 1808fcf5ef2aSThomas Huth break; 1809fcf5ef2aSThomas Huth } 1810fcf5ef2aSThomas Huth } 1811fcf5ef2aSThomas Huth 1812dca544b9SRichard Henderson static void gen_swap_asi(DisasContext *dc, DisasASI *da, 1813c03a0fd1SRichard Henderson TCGv dst, TCGv src, TCGv addr) 1814c03a0fd1SRichard Henderson { 1815c03a0fd1SRichard Henderson switch (da->type) { 1816c03a0fd1SRichard Henderson case GET_ASI_EXCP: 1817c03a0fd1SRichard Henderson break; 1818c03a0fd1SRichard Henderson case GET_ASI_DIRECT: 1819dca544b9SRichard Henderson tcg_gen_atomic_xchg_tl(dst, addr, src, 1820dca544b9SRichard Henderson da->mem_idx, da->memop | MO_ALIGN); 1821c03a0fd1SRichard Henderson break; 1822c03a0fd1SRichard Henderson default: 1823c03a0fd1SRichard Henderson /* ??? Should be DAE_invalid_asi. */ 1824c03a0fd1SRichard Henderson gen_exception(dc, TT_DATA_ACCESS); 1825c03a0fd1SRichard Henderson break; 1826c03a0fd1SRichard Henderson } 1827c03a0fd1SRichard Henderson } 1828c03a0fd1SRichard Henderson 1829d0a11d25SRichard Henderson static void gen_cas_asi(DisasContext *dc, DisasASI *da, 1830c03a0fd1SRichard Henderson TCGv oldv, TCGv newv, TCGv cmpv, TCGv addr) 1831c03a0fd1SRichard Henderson { 1832c03a0fd1SRichard Henderson switch (da->type) { 1833fcf5ef2aSThomas Huth case GET_ASI_EXCP: 1834c03a0fd1SRichard Henderson return; 1835fcf5ef2aSThomas Huth case GET_ASI_DIRECT: 1836c03a0fd1SRichard Henderson tcg_gen_atomic_cmpxchg_tl(oldv, addr, cmpv, newv, 1837c03a0fd1SRichard Henderson da->mem_idx, da->memop | MO_ALIGN); 1838fcf5ef2aSThomas Huth break; 1839fcf5ef2aSThomas Huth default: 1840fcf5ef2aSThomas Huth /* ??? Should be DAE_invalid_asi. */ 1841fcf5ef2aSThomas Huth gen_exception(dc, TT_DATA_ACCESS); 1842fcf5ef2aSThomas Huth break; 1843fcf5ef2aSThomas Huth } 1844fcf5ef2aSThomas Huth } 1845fcf5ef2aSThomas Huth 1846cf07cd1eSRichard Henderson static void gen_ldstub_asi(DisasContext *dc, DisasASI *da, TCGv dst, TCGv addr) 1847c03a0fd1SRichard Henderson { 1848c03a0fd1SRichard Henderson switch (da->type) { 1849fcf5ef2aSThomas Huth case GET_ASI_EXCP: 1850fcf5ef2aSThomas Huth break; 1851fcf5ef2aSThomas Huth case GET_ASI_DIRECT: 1852cf07cd1eSRichard Henderson tcg_gen_atomic_xchg_tl(dst, addr, tcg_constant_tl(0xff), 1853cf07cd1eSRichard Henderson da->mem_idx, MO_UB); 1854fcf5ef2aSThomas Huth break; 1855fcf5ef2aSThomas Huth default: 18563db010c3SRichard Henderson /* ??? In theory, this should be raise DAE_invalid_asi. 18573db010c3SRichard Henderson But the SS-20 roms do ldstuba [%l0] #ASI_M_CTL, %o1. */ 1858af00be49SEmilio G. Cota if (tb_cflags(dc->base.tb) & CF_PARALLEL) { 1859ad75a51eSRichard Henderson gen_helper_exit_atomic(tcg_env); 18603db010c3SRichard Henderson } else { 1861c03a0fd1SRichard Henderson TCGv_i32 r_asi = tcg_constant_i32(da->asi); 186200ab7e61SRichard Henderson TCGv_i32 r_mop = tcg_constant_i32(MO_UB); 18633db010c3SRichard Henderson TCGv_i64 s64, t64; 18643db010c3SRichard Henderson 18653db010c3SRichard Henderson save_state(dc); 18663db010c3SRichard Henderson t64 = tcg_temp_new_i64(); 1867ad75a51eSRichard Henderson gen_helper_ld_asi(t64, tcg_env, addr, r_asi, r_mop); 18683db010c3SRichard Henderson 186900ab7e61SRichard Henderson s64 = tcg_constant_i64(0xff); 1870ad75a51eSRichard Henderson gen_helper_st_asi(tcg_env, addr, s64, r_asi, r_mop); 18713db010c3SRichard Henderson 18723db010c3SRichard Henderson tcg_gen_trunc_i64_tl(dst, t64); 18733db010c3SRichard Henderson 18743db010c3SRichard Henderson /* End the TB. */ 18753db010c3SRichard Henderson dc->npc = DYNAMIC_PC; 18763db010c3SRichard Henderson } 1877fcf5ef2aSThomas Huth break; 1878fcf5ef2aSThomas Huth } 1879fcf5ef2aSThomas Huth } 1880fcf5ef2aSThomas Huth 1881287b1152SRichard Henderson static void gen_ldf_asi(DisasContext *dc, DisasASI *da, MemOp orig_size, 18823259b9e2SRichard Henderson TCGv addr, int rd) 1883fcf5ef2aSThomas Huth { 18843259b9e2SRichard Henderson MemOp memop = da->memop; 18853259b9e2SRichard Henderson MemOp size = memop & MO_SIZE; 1886fcf5ef2aSThomas Huth TCGv_i32 d32; 1887fcf5ef2aSThomas Huth TCGv_i64 d64; 1888287b1152SRichard Henderson TCGv addr_tmp; 1889fcf5ef2aSThomas Huth 18903259b9e2SRichard Henderson /* TODO: Use 128-bit load/store below. */ 18913259b9e2SRichard Henderson if (size == MO_128) { 18923259b9e2SRichard Henderson memop = (memop & ~MO_SIZE) | MO_64; 18933259b9e2SRichard Henderson } 18943259b9e2SRichard Henderson 18953259b9e2SRichard Henderson switch (da->type) { 1896fcf5ef2aSThomas Huth case GET_ASI_EXCP: 1897fcf5ef2aSThomas Huth break; 1898fcf5ef2aSThomas Huth 1899fcf5ef2aSThomas Huth case GET_ASI_DIRECT: 19003259b9e2SRichard Henderson memop |= MO_ALIGN_4; 1901fcf5ef2aSThomas Huth switch (size) { 19023259b9e2SRichard Henderson case MO_32: 1903388a6465SRichard Henderson d32 = tcg_temp_new_i32(); 19043259b9e2SRichard Henderson tcg_gen_qemu_ld_i32(d32, addr, da->mem_idx, memop); 1905fcf5ef2aSThomas Huth gen_store_fpr_F(dc, rd, d32); 1906fcf5ef2aSThomas Huth break; 19073259b9e2SRichard Henderson 19083259b9e2SRichard Henderson case MO_64: 19093259b9e2SRichard Henderson tcg_gen_qemu_ld_i64(cpu_fpr[rd / 2], addr, da->mem_idx, memop); 1910fcf5ef2aSThomas Huth break; 19113259b9e2SRichard Henderson 19123259b9e2SRichard Henderson case MO_128: 1913fcf5ef2aSThomas Huth d64 = tcg_temp_new_i64(); 19143259b9e2SRichard Henderson tcg_gen_qemu_ld_i64(d64, addr, da->mem_idx, memop); 1915287b1152SRichard Henderson addr_tmp = tcg_temp_new(); 1916287b1152SRichard Henderson tcg_gen_addi_tl(addr_tmp, addr, 8); 1917287b1152SRichard Henderson tcg_gen_qemu_ld_i64(cpu_fpr[rd / 2 + 1], addr_tmp, da->mem_idx, memop); 1918fcf5ef2aSThomas Huth tcg_gen_mov_i64(cpu_fpr[rd / 2], d64); 1919fcf5ef2aSThomas Huth break; 1920fcf5ef2aSThomas Huth default: 1921fcf5ef2aSThomas Huth g_assert_not_reached(); 1922fcf5ef2aSThomas Huth } 1923fcf5ef2aSThomas Huth break; 1924fcf5ef2aSThomas Huth 1925fcf5ef2aSThomas Huth case GET_ASI_BLOCK: 1926fcf5ef2aSThomas Huth /* Valid for lddfa on aligned registers only. */ 19273259b9e2SRichard Henderson if (orig_size == MO_64 && (rd & 7) == 0) { 1928fcf5ef2aSThomas Huth /* The first operation checks required alignment. */ 1929287b1152SRichard Henderson addr_tmp = tcg_temp_new(); 1930287b1152SRichard Henderson for (int i = 0; ; ++i) { 19313259b9e2SRichard Henderson tcg_gen_qemu_ld_i64(cpu_fpr[rd / 2 + i], addr, da->mem_idx, 19323259b9e2SRichard Henderson memop | (i == 0 ? MO_ALIGN_64 : 0)); 1933fcf5ef2aSThomas Huth if (i == 7) { 1934fcf5ef2aSThomas Huth break; 1935fcf5ef2aSThomas Huth } 1936287b1152SRichard Henderson tcg_gen_addi_tl(addr_tmp, addr, 8); 1937287b1152SRichard Henderson addr = addr_tmp; 1938fcf5ef2aSThomas Huth } 1939fcf5ef2aSThomas Huth } else { 1940fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 1941fcf5ef2aSThomas Huth } 1942fcf5ef2aSThomas Huth break; 1943fcf5ef2aSThomas Huth 1944fcf5ef2aSThomas Huth case GET_ASI_SHORT: 1945fcf5ef2aSThomas Huth /* Valid for lddfa only. */ 19463259b9e2SRichard Henderson if (orig_size == MO_64) { 19473259b9e2SRichard Henderson tcg_gen_qemu_ld_i64(cpu_fpr[rd / 2], addr, da->mem_idx, 19483259b9e2SRichard Henderson memop | MO_ALIGN); 1949fcf5ef2aSThomas Huth } else { 1950fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 1951fcf5ef2aSThomas Huth } 1952fcf5ef2aSThomas Huth break; 1953fcf5ef2aSThomas Huth 1954fcf5ef2aSThomas Huth default: 1955fcf5ef2aSThomas Huth { 19563259b9e2SRichard Henderson TCGv_i32 r_asi = tcg_constant_i32(da->asi); 19573259b9e2SRichard Henderson TCGv_i32 r_mop = tcg_constant_i32(memop | MO_ALIGN); 1958fcf5ef2aSThomas Huth 1959fcf5ef2aSThomas Huth save_state(dc); 1960fcf5ef2aSThomas Huth /* According to the table in the UA2011 manual, the only 1961fcf5ef2aSThomas Huth other asis that are valid for ldfa/lddfa/ldqfa are 1962fcf5ef2aSThomas Huth the NO_FAULT asis. We still need a helper for these, 1963fcf5ef2aSThomas Huth but we can just use the integer asi helper for them. */ 1964fcf5ef2aSThomas Huth switch (size) { 19653259b9e2SRichard Henderson case MO_32: 1966fcf5ef2aSThomas Huth d64 = tcg_temp_new_i64(); 1967ad75a51eSRichard Henderson gen_helper_ld_asi(d64, tcg_env, addr, r_asi, r_mop); 1968388a6465SRichard Henderson d32 = tcg_temp_new_i32(); 1969fcf5ef2aSThomas Huth tcg_gen_extrl_i64_i32(d32, d64); 1970fcf5ef2aSThomas Huth gen_store_fpr_F(dc, rd, d32); 1971fcf5ef2aSThomas Huth break; 19723259b9e2SRichard Henderson case MO_64: 19733259b9e2SRichard Henderson gen_helper_ld_asi(cpu_fpr[rd / 2], tcg_env, addr, 19743259b9e2SRichard Henderson r_asi, r_mop); 1975fcf5ef2aSThomas Huth break; 19763259b9e2SRichard Henderson case MO_128: 1977fcf5ef2aSThomas Huth d64 = tcg_temp_new_i64(); 1978ad75a51eSRichard Henderson gen_helper_ld_asi(d64, tcg_env, addr, r_asi, r_mop); 1979287b1152SRichard Henderson addr_tmp = tcg_temp_new(); 1980287b1152SRichard Henderson tcg_gen_addi_tl(addr_tmp, addr, 8); 1981287b1152SRichard Henderson gen_helper_ld_asi(cpu_fpr[rd / 2 + 1], tcg_env, addr_tmp, 19823259b9e2SRichard Henderson r_asi, r_mop); 1983fcf5ef2aSThomas Huth tcg_gen_mov_i64(cpu_fpr[rd / 2], d64); 1984fcf5ef2aSThomas Huth break; 1985fcf5ef2aSThomas Huth default: 1986fcf5ef2aSThomas Huth g_assert_not_reached(); 1987fcf5ef2aSThomas Huth } 1988fcf5ef2aSThomas Huth } 1989fcf5ef2aSThomas Huth break; 1990fcf5ef2aSThomas Huth } 1991fcf5ef2aSThomas Huth } 1992fcf5ef2aSThomas Huth 1993287b1152SRichard Henderson static void gen_stf_asi(DisasContext *dc, DisasASI *da, MemOp orig_size, 19943259b9e2SRichard Henderson TCGv addr, int rd) 19953259b9e2SRichard Henderson { 19963259b9e2SRichard Henderson MemOp memop = da->memop; 19973259b9e2SRichard Henderson MemOp size = memop & MO_SIZE; 1998fcf5ef2aSThomas Huth TCGv_i32 d32; 1999287b1152SRichard Henderson TCGv addr_tmp; 2000fcf5ef2aSThomas Huth 20013259b9e2SRichard Henderson /* TODO: Use 128-bit load/store below. */ 20023259b9e2SRichard Henderson if (size == MO_128) { 20033259b9e2SRichard Henderson memop = (memop & ~MO_SIZE) | MO_64; 20043259b9e2SRichard Henderson } 20053259b9e2SRichard Henderson 20063259b9e2SRichard Henderson switch (da->type) { 2007fcf5ef2aSThomas Huth case GET_ASI_EXCP: 2008fcf5ef2aSThomas Huth break; 2009fcf5ef2aSThomas Huth 2010fcf5ef2aSThomas Huth case GET_ASI_DIRECT: 20113259b9e2SRichard Henderson memop |= MO_ALIGN_4; 2012fcf5ef2aSThomas Huth switch (size) { 20133259b9e2SRichard Henderson case MO_32: 2014fcf5ef2aSThomas Huth d32 = gen_load_fpr_F(dc, rd); 20153259b9e2SRichard Henderson tcg_gen_qemu_st_i32(d32, addr, da->mem_idx, memop | MO_ALIGN); 2016fcf5ef2aSThomas Huth break; 20173259b9e2SRichard Henderson case MO_64: 20183259b9e2SRichard Henderson tcg_gen_qemu_st_i64(cpu_fpr[rd / 2], addr, da->mem_idx, 20193259b9e2SRichard Henderson memop | MO_ALIGN_4); 2020fcf5ef2aSThomas Huth break; 20213259b9e2SRichard Henderson case MO_128: 2022fcf5ef2aSThomas Huth /* Only 4-byte alignment required. However, it is legal for the 2023fcf5ef2aSThomas Huth cpu to signal the alignment fault, and the OS trap handler is 2024fcf5ef2aSThomas Huth required to fix it up. Requiring 16-byte alignment here avoids 2025fcf5ef2aSThomas Huth having to probe the second page before performing the first 2026fcf5ef2aSThomas Huth write. */ 20273259b9e2SRichard Henderson tcg_gen_qemu_st_i64(cpu_fpr[rd / 2], addr, da->mem_idx, 20283259b9e2SRichard Henderson memop | MO_ALIGN_16); 2029287b1152SRichard Henderson addr_tmp = tcg_temp_new(); 2030287b1152SRichard Henderson tcg_gen_addi_tl(addr_tmp, addr, 8); 2031287b1152SRichard Henderson tcg_gen_qemu_st_i64(cpu_fpr[rd / 2 + 1], addr_tmp, da->mem_idx, memop); 2032fcf5ef2aSThomas Huth break; 2033fcf5ef2aSThomas Huth default: 2034fcf5ef2aSThomas Huth g_assert_not_reached(); 2035fcf5ef2aSThomas Huth } 2036fcf5ef2aSThomas Huth break; 2037fcf5ef2aSThomas Huth 2038fcf5ef2aSThomas Huth case GET_ASI_BLOCK: 2039fcf5ef2aSThomas Huth /* Valid for stdfa on aligned registers only. */ 20403259b9e2SRichard Henderson if (orig_size == MO_64 && (rd & 7) == 0) { 2041fcf5ef2aSThomas Huth /* The first operation checks required alignment. */ 2042287b1152SRichard Henderson addr_tmp = tcg_temp_new(); 2043287b1152SRichard Henderson for (int i = 0; ; ++i) { 20443259b9e2SRichard Henderson tcg_gen_qemu_st_i64(cpu_fpr[rd / 2 + i], addr, da->mem_idx, 20453259b9e2SRichard Henderson memop | (i == 0 ? MO_ALIGN_64 : 0)); 2046fcf5ef2aSThomas Huth if (i == 7) { 2047fcf5ef2aSThomas Huth break; 2048fcf5ef2aSThomas Huth } 2049287b1152SRichard Henderson tcg_gen_addi_tl(addr_tmp, addr, 8); 2050287b1152SRichard Henderson addr = addr_tmp; 2051fcf5ef2aSThomas Huth } 2052fcf5ef2aSThomas Huth } else { 2053fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 2054fcf5ef2aSThomas Huth } 2055fcf5ef2aSThomas Huth break; 2056fcf5ef2aSThomas Huth 2057fcf5ef2aSThomas Huth case GET_ASI_SHORT: 2058fcf5ef2aSThomas Huth /* Valid for stdfa only. */ 20593259b9e2SRichard Henderson if (orig_size == MO_64) { 20603259b9e2SRichard Henderson tcg_gen_qemu_st_i64(cpu_fpr[rd / 2], addr, da->mem_idx, 20613259b9e2SRichard Henderson memop | MO_ALIGN); 2062fcf5ef2aSThomas Huth } else { 2063fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 2064fcf5ef2aSThomas Huth } 2065fcf5ef2aSThomas Huth break; 2066fcf5ef2aSThomas Huth 2067fcf5ef2aSThomas Huth default: 2068fcf5ef2aSThomas Huth /* According to the table in the UA2011 manual, the only 2069fcf5ef2aSThomas Huth other asis that are valid for ldfa/lddfa/ldqfa are 2070fcf5ef2aSThomas Huth the PST* asis, which aren't currently handled. */ 2071fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 2072fcf5ef2aSThomas Huth break; 2073fcf5ef2aSThomas Huth } 2074fcf5ef2aSThomas Huth } 2075fcf5ef2aSThomas Huth 207642071fc1SRichard Henderson static void gen_ldda_asi(DisasContext *dc, DisasASI *da, TCGv addr, int rd) 2077fcf5ef2aSThomas Huth { 2078a76779eeSRichard Henderson TCGv hi = gen_dest_gpr(dc, rd); 2079a76779eeSRichard Henderson TCGv lo = gen_dest_gpr(dc, rd + 1); 2080fcf5ef2aSThomas Huth 2081c03a0fd1SRichard Henderson switch (da->type) { 2082fcf5ef2aSThomas Huth case GET_ASI_EXCP: 2083fcf5ef2aSThomas Huth return; 2084fcf5ef2aSThomas Huth 2085fcf5ef2aSThomas Huth case GET_ASI_DTWINX: 2086ebbbec92SRichard Henderson #ifdef TARGET_SPARC64 2087ebbbec92SRichard Henderson { 2088ebbbec92SRichard Henderson MemOp mop = (da->memop & MO_BSWAP) | MO_128 | MO_ALIGN_16; 2089ebbbec92SRichard Henderson TCGv_i128 t = tcg_temp_new_i128(); 2090ebbbec92SRichard Henderson 2091ebbbec92SRichard Henderson tcg_gen_qemu_ld_i128(t, addr, da->mem_idx, mop); 2092ebbbec92SRichard Henderson /* 2093ebbbec92SRichard Henderson * Note that LE twinx acts as if each 64-bit register result is 2094ebbbec92SRichard Henderson * byte swapped. We perform one 128-bit LE load, so must swap 2095ebbbec92SRichard Henderson * the order of the writebacks. 2096ebbbec92SRichard Henderson */ 2097ebbbec92SRichard Henderson if ((mop & MO_BSWAP) == MO_TE) { 2098ebbbec92SRichard Henderson tcg_gen_extr_i128_i64(lo, hi, t); 2099ebbbec92SRichard Henderson } else { 2100ebbbec92SRichard Henderson tcg_gen_extr_i128_i64(hi, lo, t); 2101ebbbec92SRichard Henderson } 2102ebbbec92SRichard Henderson } 2103fcf5ef2aSThomas Huth break; 2104ebbbec92SRichard Henderson #else 2105ebbbec92SRichard Henderson g_assert_not_reached(); 2106ebbbec92SRichard Henderson #endif 2107fcf5ef2aSThomas Huth 2108fcf5ef2aSThomas Huth case GET_ASI_DIRECT: 2109fcf5ef2aSThomas Huth { 2110fcf5ef2aSThomas Huth TCGv_i64 tmp = tcg_temp_new_i64(); 2111fcf5ef2aSThomas Huth 2112c03a0fd1SRichard Henderson tcg_gen_qemu_ld_i64(tmp, addr, da->mem_idx, da->memop | MO_ALIGN); 2113fcf5ef2aSThomas Huth 2114fcf5ef2aSThomas Huth /* Note that LE ldda acts as if each 32-bit register 2115fcf5ef2aSThomas Huth result is byte swapped. Having just performed one 2116fcf5ef2aSThomas Huth 64-bit bswap, we need now to swap the writebacks. */ 2117c03a0fd1SRichard Henderson if ((da->memop & MO_BSWAP) == MO_TE) { 2118a76779eeSRichard Henderson tcg_gen_extr_i64_tl(lo, hi, tmp); 2119fcf5ef2aSThomas Huth } else { 2120a76779eeSRichard Henderson tcg_gen_extr_i64_tl(hi, lo, tmp); 2121fcf5ef2aSThomas Huth } 2122fcf5ef2aSThomas Huth } 2123fcf5ef2aSThomas Huth break; 2124fcf5ef2aSThomas Huth 2125fcf5ef2aSThomas Huth default: 2126fcf5ef2aSThomas Huth /* ??? In theory we've handled all of the ASIs that are valid 2127fcf5ef2aSThomas Huth for ldda, and this should raise DAE_invalid_asi. However, 2128fcf5ef2aSThomas Huth real hardware allows others. This can be seen with e.g. 2129fcf5ef2aSThomas Huth FreeBSD 10.3 wrt ASI_IC_TAG. */ 2130fcf5ef2aSThomas Huth { 2131c03a0fd1SRichard Henderson TCGv_i32 r_asi = tcg_constant_i32(da->asi); 2132c03a0fd1SRichard Henderson TCGv_i32 r_mop = tcg_constant_i32(da->memop); 2133fcf5ef2aSThomas Huth TCGv_i64 tmp = tcg_temp_new_i64(); 2134fcf5ef2aSThomas Huth 2135fcf5ef2aSThomas Huth save_state(dc); 2136ad75a51eSRichard Henderson gen_helper_ld_asi(tmp, tcg_env, addr, r_asi, r_mop); 2137fcf5ef2aSThomas Huth 2138fcf5ef2aSThomas Huth /* See above. */ 2139c03a0fd1SRichard Henderson if ((da->memop & MO_BSWAP) == MO_TE) { 2140a76779eeSRichard Henderson tcg_gen_extr_i64_tl(lo, hi, tmp); 2141fcf5ef2aSThomas Huth } else { 2142a76779eeSRichard Henderson tcg_gen_extr_i64_tl(hi, lo, tmp); 2143fcf5ef2aSThomas Huth } 2144fcf5ef2aSThomas Huth } 2145fcf5ef2aSThomas Huth break; 2146fcf5ef2aSThomas Huth } 2147fcf5ef2aSThomas Huth 2148fcf5ef2aSThomas Huth gen_store_gpr(dc, rd, hi); 2149fcf5ef2aSThomas Huth gen_store_gpr(dc, rd + 1, lo); 2150fcf5ef2aSThomas Huth } 2151fcf5ef2aSThomas Huth 215242071fc1SRichard Henderson static void gen_stda_asi(DisasContext *dc, DisasASI *da, TCGv addr, int rd) 2153c03a0fd1SRichard Henderson { 2154c03a0fd1SRichard Henderson TCGv hi = gen_load_gpr(dc, rd); 2155fcf5ef2aSThomas Huth TCGv lo = gen_load_gpr(dc, rd + 1); 2156fcf5ef2aSThomas Huth 2157c03a0fd1SRichard Henderson switch (da->type) { 2158fcf5ef2aSThomas Huth case GET_ASI_EXCP: 2159fcf5ef2aSThomas Huth break; 2160fcf5ef2aSThomas Huth 2161fcf5ef2aSThomas Huth case GET_ASI_DTWINX: 2162ebbbec92SRichard Henderson #ifdef TARGET_SPARC64 2163ebbbec92SRichard Henderson { 2164ebbbec92SRichard Henderson MemOp mop = (da->memop & MO_BSWAP) | MO_128 | MO_ALIGN_16; 2165ebbbec92SRichard Henderson TCGv_i128 t = tcg_temp_new_i128(); 2166ebbbec92SRichard Henderson 2167ebbbec92SRichard Henderson /* 2168ebbbec92SRichard Henderson * Note that LE twinx acts as if each 64-bit register result is 2169ebbbec92SRichard Henderson * byte swapped. We perform one 128-bit LE store, so must swap 2170ebbbec92SRichard Henderson * the order of the construction. 2171ebbbec92SRichard Henderson */ 2172ebbbec92SRichard Henderson if ((mop & MO_BSWAP) == MO_TE) { 2173ebbbec92SRichard Henderson tcg_gen_concat_i64_i128(t, lo, hi); 2174ebbbec92SRichard Henderson } else { 2175ebbbec92SRichard Henderson tcg_gen_concat_i64_i128(t, hi, lo); 2176ebbbec92SRichard Henderson } 2177ebbbec92SRichard Henderson tcg_gen_qemu_st_i128(t, addr, da->mem_idx, mop); 2178ebbbec92SRichard Henderson } 2179fcf5ef2aSThomas Huth break; 2180ebbbec92SRichard Henderson #else 2181ebbbec92SRichard Henderson g_assert_not_reached(); 2182ebbbec92SRichard Henderson #endif 2183fcf5ef2aSThomas Huth 2184fcf5ef2aSThomas Huth case GET_ASI_DIRECT: 2185fcf5ef2aSThomas Huth { 2186fcf5ef2aSThomas Huth TCGv_i64 t64 = tcg_temp_new_i64(); 2187fcf5ef2aSThomas Huth 2188fcf5ef2aSThomas Huth /* Note that LE stda acts as if each 32-bit register result is 2189fcf5ef2aSThomas Huth byte swapped. We will perform one 64-bit LE store, so now 2190fcf5ef2aSThomas Huth we must swap the order of the construction. */ 2191c03a0fd1SRichard Henderson if ((da->memop & MO_BSWAP) == MO_TE) { 2192a76779eeSRichard Henderson tcg_gen_concat_tl_i64(t64, lo, hi); 2193fcf5ef2aSThomas Huth } else { 2194a76779eeSRichard Henderson tcg_gen_concat_tl_i64(t64, hi, lo); 2195fcf5ef2aSThomas Huth } 2196c03a0fd1SRichard Henderson tcg_gen_qemu_st_i64(t64, addr, da->mem_idx, da->memop | MO_ALIGN); 2197fcf5ef2aSThomas Huth } 2198fcf5ef2aSThomas Huth break; 2199fcf5ef2aSThomas Huth 2200a76779eeSRichard Henderson case GET_ASI_BFILL: 2201a76779eeSRichard Henderson assert(TARGET_LONG_BITS == 32); 220254c3e953SRichard Henderson /* 220354c3e953SRichard Henderson * Store 32 bytes of [rd:rd+1] to ADDR. 220454c3e953SRichard Henderson * See comments for GET_ASI_COPY above. 220554c3e953SRichard Henderson */ 2206a76779eeSRichard Henderson { 220754c3e953SRichard Henderson MemOp mop = MO_TE | MO_128 | MO_ATOM_IFALIGN_PAIR; 220854c3e953SRichard Henderson TCGv_i64 t8 = tcg_temp_new_i64(); 220954c3e953SRichard Henderson TCGv_i128 t16 = tcg_temp_new_i128(); 221054c3e953SRichard Henderson TCGv daddr = tcg_temp_new(); 2211a76779eeSRichard Henderson 221254c3e953SRichard Henderson tcg_gen_concat_tl_i64(t8, lo, hi); 221354c3e953SRichard Henderson tcg_gen_concat_i64_i128(t16, t8, t8); 221454c3e953SRichard Henderson tcg_gen_andi_tl(daddr, addr, -32); 221554c3e953SRichard Henderson tcg_gen_qemu_st_i128(t16, daddr, da->mem_idx, mop); 221654c3e953SRichard Henderson tcg_gen_addi_tl(daddr, daddr, 16); 221754c3e953SRichard Henderson tcg_gen_qemu_st_i128(t16, daddr, da->mem_idx, mop); 2218a76779eeSRichard Henderson } 2219a76779eeSRichard Henderson break; 2220a76779eeSRichard Henderson 2221fcf5ef2aSThomas Huth default: 2222fcf5ef2aSThomas Huth /* ??? In theory we've handled all of the ASIs that are valid 2223fcf5ef2aSThomas Huth for stda, and this should raise DAE_invalid_asi. */ 2224fcf5ef2aSThomas Huth { 2225c03a0fd1SRichard Henderson TCGv_i32 r_asi = tcg_constant_i32(da->asi); 2226c03a0fd1SRichard Henderson TCGv_i32 r_mop = tcg_constant_i32(da->memop); 2227fcf5ef2aSThomas Huth TCGv_i64 t64 = tcg_temp_new_i64(); 2228fcf5ef2aSThomas Huth 2229fcf5ef2aSThomas Huth /* See above. */ 2230c03a0fd1SRichard Henderson if ((da->memop & MO_BSWAP) == MO_TE) { 2231a76779eeSRichard Henderson tcg_gen_concat_tl_i64(t64, lo, hi); 2232fcf5ef2aSThomas Huth } else { 2233a76779eeSRichard Henderson tcg_gen_concat_tl_i64(t64, hi, lo); 2234fcf5ef2aSThomas Huth } 2235fcf5ef2aSThomas Huth 2236fcf5ef2aSThomas Huth save_state(dc); 2237ad75a51eSRichard Henderson gen_helper_st_asi(tcg_env, addr, t64, r_asi, r_mop); 2238fcf5ef2aSThomas Huth } 2239fcf5ef2aSThomas Huth break; 2240fcf5ef2aSThomas Huth } 2241fcf5ef2aSThomas Huth } 2242fcf5ef2aSThomas Huth 2243fcf5ef2aSThomas Huth static void gen_fmovs(DisasContext *dc, DisasCompare *cmp, int rd, int rs) 2244fcf5ef2aSThomas Huth { 2245f7ec8155SRichard Henderson #ifdef TARGET_SPARC64 2246fcf5ef2aSThomas Huth TCGv_i32 c32, zero, dst, s1, s2; 2247dd7dbfccSRichard Henderson TCGv_i64 c64 = tcg_temp_new_i64(); 2248fcf5ef2aSThomas Huth 2249fcf5ef2aSThomas Huth /* We have two choices here: extend the 32 bit data and use movcond_i64, 2250fcf5ef2aSThomas Huth or fold the comparison down to 32 bits and use movcond_i32. Choose 2251fcf5ef2aSThomas Huth the later. */ 2252fcf5ef2aSThomas Huth c32 = tcg_temp_new_i32(); 2253c8507ebfSRichard Henderson tcg_gen_setcondi_i64(cmp->cond, c64, cmp->c1, cmp->c2); 2254fcf5ef2aSThomas Huth tcg_gen_extrl_i64_i32(c32, c64); 2255fcf5ef2aSThomas Huth 2256fcf5ef2aSThomas Huth s1 = gen_load_fpr_F(dc, rs); 2257fcf5ef2aSThomas Huth s2 = gen_load_fpr_F(dc, rd); 2258388a6465SRichard Henderson dst = tcg_temp_new_i32(); 225900ab7e61SRichard Henderson zero = tcg_constant_i32(0); 2260fcf5ef2aSThomas Huth 2261fcf5ef2aSThomas Huth tcg_gen_movcond_i32(TCG_COND_NE, dst, c32, zero, s1, s2); 2262fcf5ef2aSThomas Huth 2263fcf5ef2aSThomas Huth gen_store_fpr_F(dc, rd, dst); 2264f7ec8155SRichard Henderson #else 2265f7ec8155SRichard Henderson qemu_build_not_reached(); 2266f7ec8155SRichard Henderson #endif 2267fcf5ef2aSThomas Huth } 2268fcf5ef2aSThomas Huth 2269fcf5ef2aSThomas Huth static void gen_fmovd(DisasContext *dc, DisasCompare *cmp, int rd, int rs) 2270fcf5ef2aSThomas Huth { 2271f7ec8155SRichard Henderson #ifdef TARGET_SPARC64 2272fcf5ef2aSThomas Huth TCGv_i64 dst = gen_dest_fpr_D(dc, rd); 2273c8507ebfSRichard Henderson tcg_gen_movcond_i64(cmp->cond, dst, cmp->c1, tcg_constant_tl(cmp->c2), 2274fcf5ef2aSThomas Huth gen_load_fpr_D(dc, rs), 2275fcf5ef2aSThomas Huth gen_load_fpr_D(dc, rd)); 2276fcf5ef2aSThomas Huth gen_store_fpr_D(dc, rd, dst); 2277f7ec8155SRichard Henderson #else 2278f7ec8155SRichard Henderson qemu_build_not_reached(); 2279f7ec8155SRichard Henderson #endif 2280fcf5ef2aSThomas Huth } 2281fcf5ef2aSThomas Huth 2282fcf5ef2aSThomas Huth static void gen_fmovq(DisasContext *dc, DisasCompare *cmp, int rd, int rs) 2283fcf5ef2aSThomas Huth { 2284f7ec8155SRichard Henderson #ifdef TARGET_SPARC64 2285fcf5ef2aSThomas Huth int qd = QFPREG(rd); 2286fcf5ef2aSThomas Huth int qs = QFPREG(rs); 2287c8507ebfSRichard Henderson TCGv c2 = tcg_constant_tl(cmp->c2); 2288fcf5ef2aSThomas Huth 2289c8507ebfSRichard Henderson tcg_gen_movcond_i64(cmp->cond, cpu_fpr[qd / 2], cmp->c1, c2, 2290fcf5ef2aSThomas Huth cpu_fpr[qs / 2], cpu_fpr[qd / 2]); 2291c8507ebfSRichard Henderson tcg_gen_movcond_i64(cmp->cond, cpu_fpr[qd / 2 + 1], cmp->c1, c2, 2292fcf5ef2aSThomas Huth cpu_fpr[qs / 2 + 1], cpu_fpr[qd / 2 + 1]); 2293fcf5ef2aSThomas Huth 2294fcf5ef2aSThomas Huth gen_update_fprs_dirty(dc, qd); 2295f7ec8155SRichard Henderson #else 2296f7ec8155SRichard Henderson qemu_build_not_reached(); 2297f7ec8155SRichard Henderson #endif 2298fcf5ef2aSThomas Huth } 2299fcf5ef2aSThomas Huth 2300f7ec8155SRichard Henderson #ifdef TARGET_SPARC64 23015d617bfbSRichard Henderson static void gen_load_trap_state_at_tl(TCGv_ptr r_tsptr) 2302fcf5ef2aSThomas Huth { 2303fcf5ef2aSThomas Huth TCGv_i32 r_tl = tcg_temp_new_i32(); 2304fcf5ef2aSThomas Huth 2305fcf5ef2aSThomas Huth /* load env->tl into r_tl */ 2306ad75a51eSRichard Henderson tcg_gen_ld_i32(r_tl, tcg_env, offsetof(CPUSPARCState, tl)); 2307fcf5ef2aSThomas Huth 2308fcf5ef2aSThomas Huth /* tl = [0 ... MAXTL_MASK] where MAXTL_MASK must be power of 2 */ 2309fcf5ef2aSThomas Huth tcg_gen_andi_i32(r_tl, r_tl, MAXTL_MASK); 2310fcf5ef2aSThomas Huth 2311fcf5ef2aSThomas Huth /* calculate offset to current trap state from env->ts, reuse r_tl */ 2312fcf5ef2aSThomas Huth tcg_gen_muli_i32(r_tl, r_tl, sizeof (trap_state)); 2313ad75a51eSRichard Henderson tcg_gen_addi_ptr(r_tsptr, tcg_env, offsetof(CPUSPARCState, ts)); 2314fcf5ef2aSThomas Huth 2315fcf5ef2aSThomas Huth /* tsptr = env->ts[env->tl & MAXTL_MASK] */ 2316fcf5ef2aSThomas Huth { 2317fcf5ef2aSThomas Huth TCGv_ptr r_tl_tmp = tcg_temp_new_ptr(); 2318fcf5ef2aSThomas Huth tcg_gen_ext_i32_ptr(r_tl_tmp, r_tl); 2319fcf5ef2aSThomas Huth tcg_gen_add_ptr(r_tsptr, r_tsptr, r_tl_tmp); 2320fcf5ef2aSThomas Huth } 2321fcf5ef2aSThomas Huth } 2322fcf5ef2aSThomas Huth #endif 2323fcf5ef2aSThomas Huth 232406c060d9SRichard Henderson static int extract_dfpreg(DisasContext *dc, int x) 232506c060d9SRichard Henderson { 232606c060d9SRichard Henderson return DFPREG(x); 232706c060d9SRichard Henderson } 232806c060d9SRichard Henderson 232906c060d9SRichard Henderson static int extract_qfpreg(DisasContext *dc, int x) 233006c060d9SRichard Henderson { 233106c060d9SRichard Henderson return QFPREG(x); 233206c060d9SRichard Henderson } 233306c060d9SRichard Henderson 2334878cc677SRichard Henderson /* Include the auto-generated decoder. */ 2335878cc677SRichard Henderson #include "decode-insns.c.inc" 2336878cc677SRichard Henderson 2337878cc677SRichard Henderson #define TRANS(NAME, AVAIL, FUNC, ...) \ 2338878cc677SRichard Henderson static bool trans_##NAME(DisasContext *dc, arg_##NAME *a) \ 2339878cc677SRichard Henderson { return avail_##AVAIL(dc) && FUNC(dc, __VA_ARGS__); } 2340878cc677SRichard Henderson 2341878cc677SRichard Henderson #define avail_ALL(C) true 2342878cc677SRichard Henderson #ifdef TARGET_SPARC64 2343878cc677SRichard Henderson # define avail_32(C) false 2344af25071cSRichard Henderson # define avail_ASR17(C) false 2345d0a11d25SRichard Henderson # define avail_CASA(C) true 2346c2636853SRichard Henderson # define avail_DIV(C) true 2347b5372650SRichard Henderson # define avail_MUL(C) true 23480faef01bSRichard Henderson # define avail_POWERDOWN(C) false 2349878cc677SRichard Henderson # define avail_64(C) true 23505d617bfbSRichard Henderson # define avail_GL(C) ((C)->def->features & CPU_FEATURE_GL) 2351af25071cSRichard Henderson # define avail_HYPV(C) ((C)->def->features & CPU_FEATURE_HYPV) 2352b88ce6f2SRichard Henderson # define avail_VIS1(C) ((C)->def->features & CPU_FEATURE_VIS1) 2353b88ce6f2SRichard Henderson # define avail_VIS2(C) ((C)->def->features & CPU_FEATURE_VIS2) 2354878cc677SRichard Henderson #else 2355878cc677SRichard Henderson # define avail_32(C) true 2356af25071cSRichard Henderson # define avail_ASR17(C) ((C)->def->features & CPU_FEATURE_ASR17) 2357d0a11d25SRichard Henderson # define avail_CASA(C) ((C)->def->features & CPU_FEATURE_CASA) 2358c2636853SRichard Henderson # define avail_DIV(C) ((C)->def->features & CPU_FEATURE_DIV) 2359b5372650SRichard Henderson # define avail_MUL(C) ((C)->def->features & CPU_FEATURE_MUL) 23600faef01bSRichard Henderson # define avail_POWERDOWN(C) ((C)->def->features & CPU_FEATURE_POWERDOWN) 2361878cc677SRichard Henderson # define avail_64(C) false 23625d617bfbSRichard Henderson # define avail_GL(C) false 2363af25071cSRichard Henderson # define avail_HYPV(C) false 2364b88ce6f2SRichard Henderson # define avail_VIS1(C) false 2365b88ce6f2SRichard Henderson # define avail_VIS2(C) false 2366878cc677SRichard Henderson #endif 2367878cc677SRichard Henderson 2368878cc677SRichard Henderson /* Default case for non jump instructions. */ 2369878cc677SRichard Henderson static bool advance_pc(DisasContext *dc) 2370878cc677SRichard Henderson { 23714a8d145dSRichard Henderson TCGLabel *l1; 23724a8d145dSRichard Henderson 237389527e3aSRichard Henderson finishing_insn(dc); 237489527e3aSRichard Henderson 2375878cc677SRichard Henderson if (dc->npc & 3) { 2376878cc677SRichard Henderson switch (dc->npc) { 2377878cc677SRichard Henderson case DYNAMIC_PC: 2378878cc677SRichard Henderson case DYNAMIC_PC_LOOKUP: 2379878cc677SRichard Henderson dc->pc = dc->npc; 2380444d8b30SRichard Henderson tcg_gen_mov_tl(cpu_pc, cpu_npc); 2381444d8b30SRichard Henderson tcg_gen_addi_tl(cpu_npc, cpu_npc, 4); 2382878cc677SRichard Henderson break; 23834a8d145dSRichard Henderson 2384878cc677SRichard Henderson case JUMP_PC: 2385878cc677SRichard Henderson /* we can do a static jump */ 23864a8d145dSRichard Henderson l1 = gen_new_label(); 2387533f042fSRichard Henderson tcg_gen_brcondi_tl(dc->jump.cond, dc->jump.c1, dc->jump.c2, l1); 23884a8d145dSRichard Henderson 23894a8d145dSRichard Henderson /* jump not taken */ 23904a8d145dSRichard Henderson gen_goto_tb(dc, 1, dc->jump_pc[1], dc->jump_pc[1] + 4); 23914a8d145dSRichard Henderson 23924a8d145dSRichard Henderson /* jump taken */ 23934a8d145dSRichard Henderson gen_set_label(l1); 23944a8d145dSRichard Henderson gen_goto_tb(dc, 0, dc->jump_pc[0], dc->jump_pc[0] + 4); 23954a8d145dSRichard Henderson 2396878cc677SRichard Henderson dc->base.is_jmp = DISAS_NORETURN; 2397878cc677SRichard Henderson break; 23984a8d145dSRichard Henderson 2399878cc677SRichard Henderson default: 2400878cc677SRichard Henderson g_assert_not_reached(); 2401878cc677SRichard Henderson } 2402878cc677SRichard Henderson } else { 2403878cc677SRichard Henderson dc->pc = dc->npc; 2404878cc677SRichard Henderson dc->npc = dc->npc + 4; 2405878cc677SRichard Henderson } 2406878cc677SRichard Henderson return true; 2407878cc677SRichard Henderson } 2408878cc677SRichard Henderson 24096d2a0768SRichard Henderson /* 24106d2a0768SRichard Henderson * Major opcodes 00 and 01 -- branches, call, and sethi 24116d2a0768SRichard Henderson */ 24126d2a0768SRichard Henderson 24139d4e2bc7SRichard Henderson static bool advance_jump_cond(DisasContext *dc, DisasCompare *cmp, 24143951b7a8SRichard Henderson bool annul, int disp) 2415276567aaSRichard Henderson { 24163951b7a8SRichard Henderson target_ulong dest = address_mask_i(dc, dc->pc + disp * 4); 2417c76c8045SRichard Henderson target_ulong npc; 2418c76c8045SRichard Henderson 241989527e3aSRichard Henderson finishing_insn(dc); 242089527e3aSRichard Henderson 24212d9bb237SRichard Henderson if (cmp->cond == TCG_COND_ALWAYS) { 24222d9bb237SRichard Henderson if (annul) { 24232d9bb237SRichard Henderson dc->pc = dest; 24242d9bb237SRichard Henderson dc->npc = dest + 4; 24252d9bb237SRichard Henderson } else { 24262d9bb237SRichard Henderson gen_mov_pc_npc(dc); 24272d9bb237SRichard Henderson dc->npc = dest; 24282d9bb237SRichard Henderson } 24292d9bb237SRichard Henderson return true; 24302d9bb237SRichard Henderson } 24312d9bb237SRichard Henderson 24322d9bb237SRichard Henderson if (cmp->cond == TCG_COND_NEVER) { 24332d9bb237SRichard Henderson npc = dc->npc; 24342d9bb237SRichard Henderson if (npc & 3) { 24352d9bb237SRichard Henderson gen_mov_pc_npc(dc); 24362d9bb237SRichard Henderson if (annul) { 24372d9bb237SRichard Henderson tcg_gen_addi_tl(cpu_pc, cpu_pc, 4); 24382d9bb237SRichard Henderson } 24392d9bb237SRichard Henderson tcg_gen_addi_tl(cpu_npc, cpu_pc, 4); 24402d9bb237SRichard Henderson } else { 24412d9bb237SRichard Henderson dc->pc = npc + (annul ? 4 : 0); 24422d9bb237SRichard Henderson dc->npc = dc->pc + 4; 24432d9bb237SRichard Henderson } 24442d9bb237SRichard Henderson return true; 24452d9bb237SRichard Henderson } 24462d9bb237SRichard Henderson 2447c76c8045SRichard Henderson flush_cond(dc); 2448c76c8045SRichard Henderson npc = dc->npc; 24496b3e4cc6SRichard Henderson 2450276567aaSRichard Henderson if (annul) { 24516b3e4cc6SRichard Henderson TCGLabel *l1 = gen_new_label(); 24526b3e4cc6SRichard Henderson 2453c8507ebfSRichard Henderson tcg_gen_brcondi_tl(tcg_invert_cond(cmp->cond), cmp->c1, cmp->c2, l1); 24546b3e4cc6SRichard Henderson gen_goto_tb(dc, 0, npc, dest); 24556b3e4cc6SRichard Henderson gen_set_label(l1); 24566b3e4cc6SRichard Henderson gen_goto_tb(dc, 1, npc + 4, npc + 8); 24576b3e4cc6SRichard Henderson 24586b3e4cc6SRichard Henderson dc->base.is_jmp = DISAS_NORETURN; 2459276567aaSRichard Henderson } else { 24606b3e4cc6SRichard Henderson if (npc & 3) { 24616b3e4cc6SRichard Henderson switch (npc) { 24626b3e4cc6SRichard Henderson case DYNAMIC_PC: 24636b3e4cc6SRichard Henderson case DYNAMIC_PC_LOOKUP: 24646b3e4cc6SRichard Henderson tcg_gen_mov_tl(cpu_pc, cpu_npc); 24656b3e4cc6SRichard Henderson tcg_gen_addi_tl(cpu_npc, cpu_npc, 4); 24669d4e2bc7SRichard Henderson tcg_gen_movcond_tl(cmp->cond, cpu_npc, 2467c8507ebfSRichard Henderson cmp->c1, tcg_constant_tl(cmp->c2), 24686b3e4cc6SRichard Henderson tcg_constant_tl(dest), cpu_npc); 24696b3e4cc6SRichard Henderson dc->pc = npc; 24706b3e4cc6SRichard Henderson break; 24716b3e4cc6SRichard Henderson default: 24726b3e4cc6SRichard Henderson g_assert_not_reached(); 24736b3e4cc6SRichard Henderson } 24746b3e4cc6SRichard Henderson } else { 24756b3e4cc6SRichard Henderson dc->pc = npc; 2476533f042fSRichard Henderson dc->npc = JUMP_PC; 2477533f042fSRichard Henderson dc->jump = *cmp; 24786b3e4cc6SRichard Henderson dc->jump_pc[0] = dest; 24796b3e4cc6SRichard Henderson dc->jump_pc[1] = npc + 4; 2480dd7dbfccSRichard Henderson 2481dd7dbfccSRichard Henderson /* The condition for cpu_cond is always NE -- normalize. */ 2482dd7dbfccSRichard Henderson if (cmp->cond == TCG_COND_NE) { 2483c8507ebfSRichard Henderson tcg_gen_xori_tl(cpu_cond, cmp->c1, cmp->c2); 24849d4e2bc7SRichard Henderson } else { 2485c8507ebfSRichard Henderson tcg_gen_setcondi_tl(cmp->cond, cpu_cond, cmp->c1, cmp->c2); 24869d4e2bc7SRichard Henderson } 248789527e3aSRichard Henderson dc->cpu_cond_live = true; 24886b3e4cc6SRichard Henderson } 2489276567aaSRichard Henderson } 2490276567aaSRichard Henderson return true; 2491276567aaSRichard Henderson } 2492276567aaSRichard Henderson 2493af25071cSRichard Henderson static bool raise_priv(DisasContext *dc) 2494af25071cSRichard Henderson { 2495af25071cSRichard Henderson gen_exception(dc, TT_PRIV_INSN); 2496af25071cSRichard Henderson return true; 2497af25071cSRichard Henderson } 2498af25071cSRichard Henderson 249906c060d9SRichard Henderson static bool raise_unimpfpop(DisasContext *dc) 250006c060d9SRichard Henderson { 250106c060d9SRichard Henderson gen_op_fpexception_im(dc, FSR_FTT_UNIMPFPOP); 250206c060d9SRichard Henderson return true; 250306c060d9SRichard Henderson } 250406c060d9SRichard Henderson 250506c060d9SRichard Henderson static bool gen_trap_float128(DisasContext *dc) 250606c060d9SRichard Henderson { 250706c060d9SRichard Henderson if (dc->def->features & CPU_FEATURE_FLOAT128) { 250806c060d9SRichard Henderson return false; 250906c060d9SRichard Henderson } 251006c060d9SRichard Henderson return raise_unimpfpop(dc); 251106c060d9SRichard Henderson } 251206c060d9SRichard Henderson 2513276567aaSRichard Henderson static bool do_bpcc(DisasContext *dc, arg_bcc *a) 2514276567aaSRichard Henderson { 25151ea9c62aSRichard Henderson DisasCompare cmp; 2516276567aaSRichard Henderson 25171ea9c62aSRichard Henderson gen_compare(&cmp, a->cc, a->cond, dc); 25183951b7a8SRichard Henderson return advance_jump_cond(dc, &cmp, a->a, a->i); 2519276567aaSRichard Henderson } 2520276567aaSRichard Henderson 2521276567aaSRichard Henderson TRANS(Bicc, ALL, do_bpcc, a) 2522276567aaSRichard Henderson TRANS(BPcc, 64, do_bpcc, a) 2523276567aaSRichard Henderson 252445196ea4SRichard Henderson static bool do_fbpfcc(DisasContext *dc, arg_bcc *a) 252545196ea4SRichard Henderson { 2526d5471936SRichard Henderson DisasCompare cmp; 252745196ea4SRichard Henderson 252845196ea4SRichard Henderson if (gen_trap_ifnofpu(dc)) { 252945196ea4SRichard Henderson return true; 253045196ea4SRichard Henderson } 2531d5471936SRichard Henderson gen_fcompare(&cmp, a->cc, a->cond); 25323951b7a8SRichard Henderson return advance_jump_cond(dc, &cmp, a->a, a->i); 253345196ea4SRichard Henderson } 253445196ea4SRichard Henderson 253545196ea4SRichard Henderson TRANS(FBPfcc, 64, do_fbpfcc, a) 253645196ea4SRichard Henderson TRANS(FBfcc, ALL, do_fbpfcc, a) 253745196ea4SRichard Henderson 2538ab9ffe98SRichard Henderson static bool trans_BPr(DisasContext *dc, arg_BPr *a) 2539ab9ffe98SRichard Henderson { 2540ab9ffe98SRichard Henderson DisasCompare cmp; 2541ab9ffe98SRichard Henderson 2542ab9ffe98SRichard Henderson if (!avail_64(dc)) { 2543ab9ffe98SRichard Henderson return false; 2544ab9ffe98SRichard Henderson } 25452c4f56c9SRichard Henderson if (!gen_compare_reg(&cmp, a->cond, gen_load_gpr(dc, a->rs1))) { 2546ab9ffe98SRichard Henderson return false; 2547ab9ffe98SRichard Henderson } 25483951b7a8SRichard Henderson return advance_jump_cond(dc, &cmp, a->a, a->i); 2549ab9ffe98SRichard Henderson } 2550ab9ffe98SRichard Henderson 255123ada1b1SRichard Henderson static bool trans_CALL(DisasContext *dc, arg_CALL *a) 255223ada1b1SRichard Henderson { 255323ada1b1SRichard Henderson target_long target = address_mask_i(dc, dc->pc + a->i * 4); 255423ada1b1SRichard Henderson 255523ada1b1SRichard Henderson gen_store_gpr(dc, 15, tcg_constant_tl(dc->pc)); 255623ada1b1SRichard Henderson gen_mov_pc_npc(dc); 255723ada1b1SRichard Henderson dc->npc = target; 255823ada1b1SRichard Henderson return true; 255923ada1b1SRichard Henderson } 256023ada1b1SRichard Henderson 256145196ea4SRichard Henderson static bool trans_NCP(DisasContext *dc, arg_NCP *a) 256245196ea4SRichard Henderson { 256345196ea4SRichard Henderson /* 256445196ea4SRichard Henderson * For sparc32, always generate the no-coprocessor exception. 256545196ea4SRichard Henderson * For sparc64, always generate illegal instruction. 256645196ea4SRichard Henderson */ 256745196ea4SRichard Henderson #ifdef TARGET_SPARC64 256845196ea4SRichard Henderson return false; 256945196ea4SRichard Henderson #else 257045196ea4SRichard Henderson gen_exception(dc, TT_NCP_INSN); 257145196ea4SRichard Henderson return true; 257245196ea4SRichard Henderson #endif 257345196ea4SRichard Henderson } 257445196ea4SRichard Henderson 25756d2a0768SRichard Henderson static bool trans_SETHI(DisasContext *dc, arg_SETHI *a) 25766d2a0768SRichard Henderson { 25776d2a0768SRichard Henderson /* Special-case %g0 because that's the canonical nop. */ 25786d2a0768SRichard Henderson if (a->rd) { 25796d2a0768SRichard Henderson gen_store_gpr(dc, a->rd, tcg_constant_tl((uint32_t)a->i << 10)); 25806d2a0768SRichard Henderson } 25816d2a0768SRichard Henderson return advance_pc(dc); 25826d2a0768SRichard Henderson } 25836d2a0768SRichard Henderson 25840faef01bSRichard Henderson /* 25850faef01bSRichard Henderson * Major Opcode 10 -- integer, floating-point, vis, and system insns. 25860faef01bSRichard Henderson */ 25870faef01bSRichard Henderson 258830376636SRichard Henderson static bool do_tcc(DisasContext *dc, int cond, int cc, 258930376636SRichard Henderson int rs1, bool imm, int rs2_or_imm) 259030376636SRichard Henderson { 259130376636SRichard Henderson int mask = ((dc->def->features & CPU_FEATURE_HYPV) && supervisor(dc) 259230376636SRichard Henderson ? UA2005_HTRAP_MASK : V8_TRAP_MASK); 259330376636SRichard Henderson DisasCompare cmp; 259430376636SRichard Henderson TCGLabel *lab; 259530376636SRichard Henderson TCGv_i32 trap; 259630376636SRichard Henderson 259730376636SRichard Henderson /* Trap never. */ 259830376636SRichard Henderson if (cond == 0) { 259930376636SRichard Henderson return advance_pc(dc); 260030376636SRichard Henderson } 260130376636SRichard Henderson 260230376636SRichard Henderson /* 260330376636SRichard Henderson * Immediate traps are the most common case. Since this value is 260430376636SRichard Henderson * live across the branch, it really pays to evaluate the constant. 260530376636SRichard Henderson */ 260630376636SRichard Henderson if (rs1 == 0 && (imm || rs2_or_imm == 0)) { 260730376636SRichard Henderson trap = tcg_constant_i32((rs2_or_imm & mask) + TT_TRAP); 260830376636SRichard Henderson } else { 260930376636SRichard Henderson trap = tcg_temp_new_i32(); 261030376636SRichard Henderson tcg_gen_trunc_tl_i32(trap, gen_load_gpr(dc, rs1)); 261130376636SRichard Henderson if (imm) { 261230376636SRichard Henderson tcg_gen_addi_i32(trap, trap, rs2_or_imm); 261330376636SRichard Henderson } else { 261430376636SRichard Henderson TCGv_i32 t2 = tcg_temp_new_i32(); 261530376636SRichard Henderson tcg_gen_trunc_tl_i32(t2, gen_load_gpr(dc, rs2_or_imm)); 261630376636SRichard Henderson tcg_gen_add_i32(trap, trap, t2); 261730376636SRichard Henderson } 261830376636SRichard Henderson tcg_gen_andi_i32(trap, trap, mask); 261930376636SRichard Henderson tcg_gen_addi_i32(trap, trap, TT_TRAP); 262030376636SRichard Henderson } 262130376636SRichard Henderson 262289527e3aSRichard Henderson finishing_insn(dc); 262389527e3aSRichard Henderson 262430376636SRichard Henderson /* Trap always. */ 262530376636SRichard Henderson if (cond == 8) { 262630376636SRichard Henderson save_state(dc); 262730376636SRichard Henderson gen_helper_raise_exception(tcg_env, trap); 262830376636SRichard Henderson dc->base.is_jmp = DISAS_NORETURN; 262930376636SRichard Henderson return true; 263030376636SRichard Henderson } 263130376636SRichard Henderson 263230376636SRichard Henderson /* Conditional trap. */ 263330376636SRichard Henderson flush_cond(dc); 263430376636SRichard Henderson lab = delay_exceptionv(dc, trap); 263530376636SRichard Henderson gen_compare(&cmp, cc, cond, dc); 2636c8507ebfSRichard Henderson tcg_gen_brcondi_tl(cmp.cond, cmp.c1, cmp.c2, lab); 263730376636SRichard Henderson 263830376636SRichard Henderson return advance_pc(dc); 263930376636SRichard Henderson } 264030376636SRichard Henderson 264130376636SRichard Henderson static bool trans_Tcc_r(DisasContext *dc, arg_Tcc_r *a) 264230376636SRichard Henderson { 264330376636SRichard Henderson if (avail_32(dc) && a->cc) { 264430376636SRichard Henderson return false; 264530376636SRichard Henderson } 264630376636SRichard Henderson return do_tcc(dc, a->cond, a->cc, a->rs1, false, a->rs2); 264730376636SRichard Henderson } 264830376636SRichard Henderson 264930376636SRichard Henderson static bool trans_Tcc_i_v7(DisasContext *dc, arg_Tcc_i_v7 *a) 265030376636SRichard Henderson { 265130376636SRichard Henderson if (avail_64(dc)) { 265230376636SRichard Henderson return false; 265330376636SRichard Henderson } 265430376636SRichard Henderson return do_tcc(dc, a->cond, 0, a->rs1, true, a->i); 265530376636SRichard Henderson } 265630376636SRichard Henderson 265730376636SRichard Henderson static bool trans_Tcc_i_v9(DisasContext *dc, arg_Tcc_i_v9 *a) 265830376636SRichard Henderson { 265930376636SRichard Henderson if (avail_32(dc)) { 266030376636SRichard Henderson return false; 266130376636SRichard Henderson } 266230376636SRichard Henderson return do_tcc(dc, a->cond, a->cc, a->rs1, true, a->i); 266330376636SRichard Henderson } 266430376636SRichard Henderson 2665af25071cSRichard Henderson static bool trans_STBAR(DisasContext *dc, arg_STBAR *a) 2666af25071cSRichard Henderson { 2667af25071cSRichard Henderson tcg_gen_mb(TCG_MO_ST_ST | TCG_BAR_SC); 2668af25071cSRichard Henderson return advance_pc(dc); 2669af25071cSRichard Henderson } 2670af25071cSRichard Henderson 2671af25071cSRichard Henderson static bool trans_MEMBAR(DisasContext *dc, arg_MEMBAR *a) 2672af25071cSRichard Henderson { 2673af25071cSRichard Henderson if (avail_32(dc)) { 2674af25071cSRichard Henderson return false; 2675af25071cSRichard Henderson } 2676af25071cSRichard Henderson if (a->mmask) { 2677af25071cSRichard Henderson /* Note TCG_MO_* was modeled on sparc64, so mmask matches. */ 2678af25071cSRichard Henderson tcg_gen_mb(a->mmask | TCG_BAR_SC); 2679af25071cSRichard Henderson } 2680af25071cSRichard Henderson if (a->cmask) { 2681af25071cSRichard Henderson /* For #Sync, etc, end the TB to recognize interrupts. */ 2682af25071cSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 2683af25071cSRichard Henderson } 2684af25071cSRichard Henderson return advance_pc(dc); 2685af25071cSRichard Henderson } 2686af25071cSRichard Henderson 2687af25071cSRichard Henderson static bool do_rd_special(DisasContext *dc, bool priv, int rd, 2688af25071cSRichard Henderson TCGv (*func)(DisasContext *, TCGv)) 2689af25071cSRichard Henderson { 2690af25071cSRichard Henderson if (!priv) { 2691af25071cSRichard Henderson return raise_priv(dc); 2692af25071cSRichard Henderson } 2693af25071cSRichard Henderson gen_store_gpr(dc, rd, func(dc, gen_dest_gpr(dc, rd))); 2694af25071cSRichard Henderson return advance_pc(dc); 2695af25071cSRichard Henderson } 2696af25071cSRichard Henderson 2697af25071cSRichard Henderson static TCGv do_rdy(DisasContext *dc, TCGv dst) 2698af25071cSRichard Henderson { 2699af25071cSRichard Henderson return cpu_y; 2700af25071cSRichard Henderson } 2701af25071cSRichard Henderson 2702af25071cSRichard Henderson static bool trans_RDY(DisasContext *dc, arg_RDY *a) 2703af25071cSRichard Henderson { 2704af25071cSRichard Henderson /* 2705af25071cSRichard Henderson * TODO: Need a feature bit for sparcv8. In the meantime, treat all 2706af25071cSRichard Henderson * 32-bit cpus like sparcv7, which ignores the rs1 field. 2707af25071cSRichard Henderson * This matches after all other ASR, so Leon3 Asr17 is handled first. 2708af25071cSRichard Henderson */ 2709af25071cSRichard Henderson if (avail_64(dc) && a->rs1 != 0) { 2710af25071cSRichard Henderson return false; 2711af25071cSRichard Henderson } 2712af25071cSRichard Henderson return do_rd_special(dc, true, a->rd, do_rdy); 2713af25071cSRichard Henderson } 2714af25071cSRichard Henderson 2715af25071cSRichard Henderson static TCGv do_rd_leon3_config(DisasContext *dc, TCGv dst) 2716af25071cSRichard Henderson { 2717af25071cSRichard Henderson uint32_t val; 2718af25071cSRichard Henderson 2719af25071cSRichard Henderson /* 2720af25071cSRichard Henderson * TODO: There are many more fields to be filled, 2721af25071cSRichard Henderson * some of which are writable. 2722af25071cSRichard Henderson */ 2723af25071cSRichard Henderson val = dc->def->nwindows - 1; /* [4:0] NWIN */ 2724af25071cSRichard Henderson val |= 1 << 8; /* [8] V8 */ 2725af25071cSRichard Henderson 2726af25071cSRichard Henderson return tcg_constant_tl(val); 2727af25071cSRichard Henderson } 2728af25071cSRichard Henderson 2729af25071cSRichard Henderson TRANS(RDASR17, ASR17, do_rd_special, true, a->rd, do_rd_leon3_config) 2730af25071cSRichard Henderson 2731af25071cSRichard Henderson static TCGv do_rdccr(DisasContext *dc, TCGv dst) 2732af25071cSRichard Henderson { 2733af25071cSRichard Henderson gen_helper_rdccr(dst, tcg_env); 2734af25071cSRichard Henderson return dst; 2735af25071cSRichard Henderson } 2736af25071cSRichard Henderson 2737af25071cSRichard Henderson TRANS(RDCCR, 64, do_rd_special, true, a->rd, do_rdccr) 2738af25071cSRichard Henderson 2739af25071cSRichard Henderson static TCGv do_rdasi(DisasContext *dc, TCGv dst) 2740af25071cSRichard Henderson { 2741af25071cSRichard Henderson #ifdef TARGET_SPARC64 2742af25071cSRichard Henderson return tcg_constant_tl(dc->asi); 2743af25071cSRichard Henderson #else 2744af25071cSRichard Henderson qemu_build_not_reached(); 2745af25071cSRichard Henderson #endif 2746af25071cSRichard Henderson } 2747af25071cSRichard Henderson 2748af25071cSRichard Henderson TRANS(RDASI, 64, do_rd_special, true, a->rd, do_rdasi) 2749af25071cSRichard Henderson 2750af25071cSRichard Henderson static TCGv do_rdtick(DisasContext *dc, TCGv dst) 2751af25071cSRichard Henderson { 2752af25071cSRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr(); 2753af25071cSRichard Henderson 2754af25071cSRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(tick)); 2755af25071cSRichard Henderson if (translator_io_start(&dc->base)) { 2756af25071cSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 2757af25071cSRichard Henderson } 2758af25071cSRichard Henderson gen_helper_tick_get_count(dst, tcg_env, r_tickptr, 2759af25071cSRichard Henderson tcg_constant_i32(dc->mem_idx)); 2760af25071cSRichard Henderson return dst; 2761af25071cSRichard Henderson } 2762af25071cSRichard Henderson 2763af25071cSRichard Henderson /* TODO: non-priv access only allowed when enabled. */ 2764af25071cSRichard Henderson TRANS(RDTICK, 64, do_rd_special, true, a->rd, do_rdtick) 2765af25071cSRichard Henderson 2766af25071cSRichard Henderson static TCGv do_rdpc(DisasContext *dc, TCGv dst) 2767af25071cSRichard Henderson { 2768af25071cSRichard Henderson return tcg_constant_tl(address_mask_i(dc, dc->pc)); 2769af25071cSRichard Henderson } 2770af25071cSRichard Henderson 2771af25071cSRichard Henderson TRANS(RDPC, 64, do_rd_special, true, a->rd, do_rdpc) 2772af25071cSRichard Henderson 2773af25071cSRichard Henderson static TCGv do_rdfprs(DisasContext *dc, TCGv dst) 2774af25071cSRichard Henderson { 2775af25071cSRichard Henderson tcg_gen_ext_i32_tl(dst, cpu_fprs); 2776af25071cSRichard Henderson return dst; 2777af25071cSRichard Henderson } 2778af25071cSRichard Henderson 2779af25071cSRichard Henderson TRANS(RDFPRS, 64, do_rd_special, true, a->rd, do_rdfprs) 2780af25071cSRichard Henderson 2781af25071cSRichard Henderson static TCGv do_rdgsr(DisasContext *dc, TCGv dst) 2782af25071cSRichard Henderson { 2783af25071cSRichard Henderson gen_trap_ifnofpu(dc); 2784af25071cSRichard Henderson return cpu_gsr; 2785af25071cSRichard Henderson } 2786af25071cSRichard Henderson 2787af25071cSRichard Henderson TRANS(RDGSR, 64, do_rd_special, true, a->rd, do_rdgsr) 2788af25071cSRichard Henderson 2789af25071cSRichard Henderson static TCGv do_rdsoftint(DisasContext *dc, TCGv dst) 2790af25071cSRichard Henderson { 2791af25071cSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(softint)); 2792af25071cSRichard Henderson return dst; 2793af25071cSRichard Henderson } 2794af25071cSRichard Henderson 2795af25071cSRichard Henderson TRANS(RDSOFTINT, 64, do_rd_special, supervisor(dc), a->rd, do_rdsoftint) 2796af25071cSRichard Henderson 2797af25071cSRichard Henderson static TCGv do_rdtick_cmpr(DisasContext *dc, TCGv dst) 2798af25071cSRichard Henderson { 2799577efa45SRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(tick_cmpr)); 2800577efa45SRichard Henderson return dst; 2801af25071cSRichard Henderson } 2802af25071cSRichard Henderson 2803af25071cSRichard Henderson /* TODO: non-priv access only allowed when enabled. */ 2804af25071cSRichard Henderson TRANS(RDTICK_CMPR, 64, do_rd_special, true, a->rd, do_rdtick_cmpr) 2805af25071cSRichard Henderson 2806af25071cSRichard Henderson static TCGv do_rdstick(DisasContext *dc, TCGv dst) 2807af25071cSRichard Henderson { 2808af25071cSRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr(); 2809af25071cSRichard Henderson 2810af25071cSRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(stick)); 2811af25071cSRichard Henderson if (translator_io_start(&dc->base)) { 2812af25071cSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 2813af25071cSRichard Henderson } 2814af25071cSRichard Henderson gen_helper_tick_get_count(dst, tcg_env, r_tickptr, 2815af25071cSRichard Henderson tcg_constant_i32(dc->mem_idx)); 2816af25071cSRichard Henderson return dst; 2817af25071cSRichard Henderson } 2818af25071cSRichard Henderson 2819af25071cSRichard Henderson /* TODO: non-priv access only allowed when enabled. */ 2820af25071cSRichard Henderson TRANS(RDSTICK, 64, do_rd_special, true, a->rd, do_rdstick) 2821af25071cSRichard Henderson 2822af25071cSRichard Henderson static TCGv do_rdstick_cmpr(DisasContext *dc, TCGv dst) 2823af25071cSRichard Henderson { 2824577efa45SRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(stick_cmpr)); 2825577efa45SRichard Henderson return dst; 2826af25071cSRichard Henderson } 2827af25071cSRichard Henderson 2828af25071cSRichard Henderson /* TODO: supervisor access only allowed when enabled by hypervisor. */ 2829af25071cSRichard Henderson TRANS(RDSTICK_CMPR, 64, do_rd_special, supervisor(dc), a->rd, do_rdstick_cmpr) 2830af25071cSRichard Henderson 2831af25071cSRichard Henderson /* 2832af25071cSRichard Henderson * UltraSPARC-T1 Strand status. 2833af25071cSRichard Henderson * HYPV check maybe not enough, UA2005 & UA2007 describe 2834af25071cSRichard Henderson * this ASR as impl. dep 2835af25071cSRichard Henderson */ 2836af25071cSRichard Henderson static TCGv do_rdstrand_status(DisasContext *dc, TCGv dst) 2837af25071cSRichard Henderson { 2838af25071cSRichard Henderson return tcg_constant_tl(1); 2839af25071cSRichard Henderson } 2840af25071cSRichard Henderson 2841af25071cSRichard Henderson TRANS(RDSTRAND_STATUS, HYPV, do_rd_special, true, a->rd, do_rdstrand_status) 2842af25071cSRichard Henderson 2843668bb9b7SRichard Henderson static TCGv do_rdpsr(DisasContext *dc, TCGv dst) 2844668bb9b7SRichard Henderson { 2845668bb9b7SRichard Henderson gen_helper_rdpsr(dst, tcg_env); 2846668bb9b7SRichard Henderson return dst; 2847668bb9b7SRichard Henderson } 2848668bb9b7SRichard Henderson 2849668bb9b7SRichard Henderson TRANS(RDPSR, 32, do_rd_special, supervisor(dc), a->rd, do_rdpsr) 2850668bb9b7SRichard Henderson 2851668bb9b7SRichard Henderson static TCGv do_rdhpstate(DisasContext *dc, TCGv dst) 2852668bb9b7SRichard Henderson { 2853668bb9b7SRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hpstate)); 2854668bb9b7SRichard Henderson return dst; 2855668bb9b7SRichard Henderson } 2856668bb9b7SRichard Henderson 2857668bb9b7SRichard Henderson TRANS(RDHPR_hpstate, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhpstate) 2858668bb9b7SRichard Henderson 2859668bb9b7SRichard Henderson static TCGv do_rdhtstate(DisasContext *dc, TCGv dst) 2860668bb9b7SRichard Henderson { 2861668bb9b7SRichard Henderson TCGv_i32 tl = tcg_temp_new_i32(); 2862668bb9b7SRichard Henderson TCGv_ptr tp = tcg_temp_new_ptr(); 2863668bb9b7SRichard Henderson 2864668bb9b7SRichard Henderson tcg_gen_ld_i32(tl, tcg_env, env64_field_offsetof(tl)); 2865668bb9b7SRichard Henderson tcg_gen_andi_i32(tl, tl, MAXTL_MASK); 2866668bb9b7SRichard Henderson tcg_gen_shli_i32(tl, tl, 3); 2867668bb9b7SRichard Henderson tcg_gen_ext_i32_ptr(tp, tl); 2868668bb9b7SRichard Henderson tcg_gen_add_ptr(tp, tp, tcg_env); 2869668bb9b7SRichard Henderson 2870668bb9b7SRichard Henderson tcg_gen_ld_tl(dst, tp, env64_field_offsetof(htstate)); 2871668bb9b7SRichard Henderson return dst; 2872668bb9b7SRichard Henderson } 2873668bb9b7SRichard Henderson 2874668bb9b7SRichard Henderson TRANS(RDHPR_htstate, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhtstate) 2875668bb9b7SRichard Henderson 2876668bb9b7SRichard Henderson static TCGv do_rdhintp(DisasContext *dc, TCGv dst) 2877668bb9b7SRichard Henderson { 28782da789deSRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hintp)); 28792da789deSRichard Henderson return dst; 2880668bb9b7SRichard Henderson } 2881668bb9b7SRichard Henderson 2882668bb9b7SRichard Henderson TRANS(RDHPR_hintp, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhintp) 2883668bb9b7SRichard Henderson 2884668bb9b7SRichard Henderson static TCGv do_rdhtba(DisasContext *dc, TCGv dst) 2885668bb9b7SRichard Henderson { 28862da789deSRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(htba)); 28872da789deSRichard Henderson return dst; 2888668bb9b7SRichard Henderson } 2889668bb9b7SRichard Henderson 2890668bb9b7SRichard Henderson TRANS(RDHPR_htba, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhtba) 2891668bb9b7SRichard Henderson 2892668bb9b7SRichard Henderson static TCGv do_rdhver(DisasContext *dc, TCGv dst) 2893668bb9b7SRichard Henderson { 28942da789deSRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hver)); 28952da789deSRichard Henderson return dst; 2896668bb9b7SRichard Henderson } 2897668bb9b7SRichard Henderson 2898668bb9b7SRichard Henderson TRANS(RDHPR_hver, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhver) 2899668bb9b7SRichard Henderson 2900668bb9b7SRichard Henderson static TCGv do_rdhstick_cmpr(DisasContext *dc, TCGv dst) 2901668bb9b7SRichard Henderson { 2902577efa45SRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hstick_cmpr)); 2903577efa45SRichard Henderson return dst; 2904668bb9b7SRichard Henderson } 2905668bb9b7SRichard Henderson 2906668bb9b7SRichard Henderson TRANS(RDHPR_hstick_cmpr, HYPV, do_rd_special, hypervisor(dc), a->rd, 2907668bb9b7SRichard Henderson do_rdhstick_cmpr) 2908668bb9b7SRichard Henderson 29095d617bfbSRichard Henderson static TCGv do_rdwim(DisasContext *dc, TCGv dst) 29105d617bfbSRichard Henderson { 2911cd6269f7SRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env32_field_offsetof(wim)); 2912cd6269f7SRichard Henderson return dst; 29135d617bfbSRichard Henderson } 29145d617bfbSRichard Henderson 29155d617bfbSRichard Henderson TRANS(RDWIM, 32, do_rd_special, supervisor(dc), a->rd, do_rdwim) 29165d617bfbSRichard Henderson 29175d617bfbSRichard Henderson static TCGv do_rdtpc(DisasContext *dc, TCGv dst) 29185d617bfbSRichard Henderson { 29195d617bfbSRichard Henderson #ifdef TARGET_SPARC64 29205d617bfbSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 29215d617bfbSRichard Henderson 29225d617bfbSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 29235d617bfbSRichard Henderson tcg_gen_ld_tl(dst, r_tsptr, offsetof(trap_state, tpc)); 29245d617bfbSRichard Henderson return dst; 29255d617bfbSRichard Henderson #else 29265d617bfbSRichard Henderson qemu_build_not_reached(); 29275d617bfbSRichard Henderson #endif 29285d617bfbSRichard Henderson } 29295d617bfbSRichard Henderson 29305d617bfbSRichard Henderson TRANS(RDPR_tpc, 64, do_rd_special, supervisor(dc), a->rd, do_rdtpc) 29315d617bfbSRichard Henderson 29325d617bfbSRichard Henderson static TCGv do_rdtnpc(DisasContext *dc, TCGv dst) 29335d617bfbSRichard Henderson { 29345d617bfbSRichard Henderson #ifdef TARGET_SPARC64 29355d617bfbSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 29365d617bfbSRichard Henderson 29375d617bfbSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 29385d617bfbSRichard Henderson tcg_gen_ld_tl(dst, r_tsptr, offsetof(trap_state, tnpc)); 29395d617bfbSRichard Henderson return dst; 29405d617bfbSRichard Henderson #else 29415d617bfbSRichard Henderson qemu_build_not_reached(); 29425d617bfbSRichard Henderson #endif 29435d617bfbSRichard Henderson } 29445d617bfbSRichard Henderson 29455d617bfbSRichard Henderson TRANS(RDPR_tnpc, 64, do_rd_special, supervisor(dc), a->rd, do_rdtnpc) 29465d617bfbSRichard Henderson 29475d617bfbSRichard Henderson static TCGv do_rdtstate(DisasContext *dc, TCGv dst) 29485d617bfbSRichard Henderson { 29495d617bfbSRichard Henderson #ifdef TARGET_SPARC64 29505d617bfbSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 29515d617bfbSRichard Henderson 29525d617bfbSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 29535d617bfbSRichard Henderson tcg_gen_ld_tl(dst, r_tsptr, offsetof(trap_state, tstate)); 29545d617bfbSRichard Henderson return dst; 29555d617bfbSRichard Henderson #else 29565d617bfbSRichard Henderson qemu_build_not_reached(); 29575d617bfbSRichard Henderson #endif 29585d617bfbSRichard Henderson } 29595d617bfbSRichard Henderson 29605d617bfbSRichard Henderson TRANS(RDPR_tstate, 64, do_rd_special, supervisor(dc), a->rd, do_rdtstate) 29615d617bfbSRichard Henderson 29625d617bfbSRichard Henderson static TCGv do_rdtt(DisasContext *dc, TCGv dst) 29635d617bfbSRichard Henderson { 29645d617bfbSRichard Henderson #ifdef TARGET_SPARC64 29655d617bfbSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 29665d617bfbSRichard Henderson 29675d617bfbSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 29685d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, r_tsptr, offsetof(trap_state, tt)); 29695d617bfbSRichard Henderson return dst; 29705d617bfbSRichard Henderson #else 29715d617bfbSRichard Henderson qemu_build_not_reached(); 29725d617bfbSRichard Henderson #endif 29735d617bfbSRichard Henderson } 29745d617bfbSRichard Henderson 29755d617bfbSRichard Henderson TRANS(RDPR_tt, 64, do_rd_special, supervisor(dc), a->rd, do_rdtt) 29765d617bfbSRichard Henderson TRANS(RDPR_tick, 64, do_rd_special, supervisor(dc), a->rd, do_rdtick) 29775d617bfbSRichard Henderson 29785d617bfbSRichard Henderson static TCGv do_rdtba(DisasContext *dc, TCGv dst) 29795d617bfbSRichard Henderson { 29805d617bfbSRichard Henderson return cpu_tbr; 29815d617bfbSRichard Henderson } 29825d617bfbSRichard Henderson 2983e8325dc0SRichard Henderson TRANS(RDTBR, 32, do_rd_special, supervisor(dc), a->rd, do_rdtba) 29845d617bfbSRichard Henderson TRANS(RDPR_tba, 64, do_rd_special, supervisor(dc), a->rd, do_rdtba) 29855d617bfbSRichard Henderson 29865d617bfbSRichard Henderson static TCGv do_rdpstate(DisasContext *dc, TCGv dst) 29875d617bfbSRichard Henderson { 29885d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(pstate)); 29895d617bfbSRichard Henderson return dst; 29905d617bfbSRichard Henderson } 29915d617bfbSRichard Henderson 29925d617bfbSRichard Henderson TRANS(RDPR_pstate, 64, do_rd_special, supervisor(dc), a->rd, do_rdpstate) 29935d617bfbSRichard Henderson 29945d617bfbSRichard Henderson static TCGv do_rdtl(DisasContext *dc, TCGv dst) 29955d617bfbSRichard Henderson { 29965d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(tl)); 29975d617bfbSRichard Henderson return dst; 29985d617bfbSRichard Henderson } 29995d617bfbSRichard Henderson 30005d617bfbSRichard Henderson TRANS(RDPR_tl, 64, do_rd_special, supervisor(dc), a->rd, do_rdtl) 30015d617bfbSRichard Henderson 30025d617bfbSRichard Henderson static TCGv do_rdpil(DisasContext *dc, TCGv dst) 30035d617bfbSRichard Henderson { 30045d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env_field_offsetof(psrpil)); 30055d617bfbSRichard Henderson return dst; 30065d617bfbSRichard Henderson } 30075d617bfbSRichard Henderson 30085d617bfbSRichard Henderson TRANS(RDPR_pil, 64, do_rd_special, supervisor(dc), a->rd, do_rdpil) 30095d617bfbSRichard Henderson 30105d617bfbSRichard Henderson static TCGv do_rdcwp(DisasContext *dc, TCGv dst) 30115d617bfbSRichard Henderson { 30125d617bfbSRichard Henderson gen_helper_rdcwp(dst, tcg_env); 30135d617bfbSRichard Henderson return dst; 30145d617bfbSRichard Henderson } 30155d617bfbSRichard Henderson 30165d617bfbSRichard Henderson TRANS(RDPR_cwp, 64, do_rd_special, supervisor(dc), a->rd, do_rdcwp) 30175d617bfbSRichard Henderson 30185d617bfbSRichard Henderson static TCGv do_rdcansave(DisasContext *dc, TCGv dst) 30195d617bfbSRichard Henderson { 30205d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(cansave)); 30215d617bfbSRichard Henderson return dst; 30225d617bfbSRichard Henderson } 30235d617bfbSRichard Henderson 30245d617bfbSRichard Henderson TRANS(RDPR_cansave, 64, do_rd_special, supervisor(dc), a->rd, do_rdcansave) 30255d617bfbSRichard Henderson 30265d617bfbSRichard Henderson static TCGv do_rdcanrestore(DisasContext *dc, TCGv dst) 30275d617bfbSRichard Henderson { 30285d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(canrestore)); 30295d617bfbSRichard Henderson return dst; 30305d617bfbSRichard Henderson } 30315d617bfbSRichard Henderson 30325d617bfbSRichard Henderson TRANS(RDPR_canrestore, 64, do_rd_special, supervisor(dc), a->rd, 30335d617bfbSRichard Henderson do_rdcanrestore) 30345d617bfbSRichard Henderson 30355d617bfbSRichard Henderson static TCGv do_rdcleanwin(DisasContext *dc, TCGv dst) 30365d617bfbSRichard Henderson { 30375d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(cleanwin)); 30385d617bfbSRichard Henderson return dst; 30395d617bfbSRichard Henderson } 30405d617bfbSRichard Henderson 30415d617bfbSRichard Henderson TRANS(RDPR_cleanwin, 64, do_rd_special, supervisor(dc), a->rd, do_rdcleanwin) 30425d617bfbSRichard Henderson 30435d617bfbSRichard Henderson static TCGv do_rdotherwin(DisasContext *dc, TCGv dst) 30445d617bfbSRichard Henderson { 30455d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(otherwin)); 30465d617bfbSRichard Henderson return dst; 30475d617bfbSRichard Henderson } 30485d617bfbSRichard Henderson 30495d617bfbSRichard Henderson TRANS(RDPR_otherwin, 64, do_rd_special, supervisor(dc), a->rd, do_rdotherwin) 30505d617bfbSRichard Henderson 30515d617bfbSRichard Henderson static TCGv do_rdwstate(DisasContext *dc, TCGv dst) 30525d617bfbSRichard Henderson { 30535d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(wstate)); 30545d617bfbSRichard Henderson return dst; 30555d617bfbSRichard Henderson } 30565d617bfbSRichard Henderson 30575d617bfbSRichard Henderson TRANS(RDPR_wstate, 64, do_rd_special, supervisor(dc), a->rd, do_rdwstate) 30585d617bfbSRichard Henderson 30595d617bfbSRichard Henderson static TCGv do_rdgl(DisasContext *dc, TCGv dst) 30605d617bfbSRichard Henderson { 30615d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(gl)); 30625d617bfbSRichard Henderson return dst; 30635d617bfbSRichard Henderson } 30645d617bfbSRichard Henderson 30655d617bfbSRichard Henderson TRANS(RDPR_gl, GL, do_rd_special, supervisor(dc), a->rd, do_rdgl) 30665d617bfbSRichard Henderson 30675d617bfbSRichard Henderson /* UA2005 strand status */ 30685d617bfbSRichard Henderson static TCGv do_rdssr(DisasContext *dc, TCGv dst) 30695d617bfbSRichard Henderson { 30702da789deSRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(ssr)); 30712da789deSRichard Henderson return dst; 30725d617bfbSRichard Henderson } 30735d617bfbSRichard Henderson 30745d617bfbSRichard Henderson TRANS(RDPR_strand_status, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdssr) 30755d617bfbSRichard Henderson 30765d617bfbSRichard Henderson static TCGv do_rdver(DisasContext *dc, TCGv dst) 30775d617bfbSRichard Henderson { 30782da789deSRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(version)); 30792da789deSRichard Henderson return dst; 30805d617bfbSRichard Henderson } 30815d617bfbSRichard Henderson 30825d617bfbSRichard Henderson TRANS(RDPR_ver, 64, do_rd_special, supervisor(dc), a->rd, do_rdver) 30835d617bfbSRichard Henderson 3084e8325dc0SRichard Henderson static bool trans_FLUSHW(DisasContext *dc, arg_FLUSHW *a) 3085e8325dc0SRichard Henderson { 3086e8325dc0SRichard Henderson if (avail_64(dc)) { 3087e8325dc0SRichard Henderson gen_helper_flushw(tcg_env); 3088e8325dc0SRichard Henderson return advance_pc(dc); 3089e8325dc0SRichard Henderson } 3090e8325dc0SRichard Henderson return false; 3091e8325dc0SRichard Henderson } 3092e8325dc0SRichard Henderson 30930faef01bSRichard Henderson static bool do_wr_special(DisasContext *dc, arg_r_r_ri *a, bool priv, 30940faef01bSRichard Henderson void (*func)(DisasContext *, TCGv)) 30950faef01bSRichard Henderson { 30960faef01bSRichard Henderson TCGv src; 30970faef01bSRichard Henderson 30980faef01bSRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 30990faef01bSRichard Henderson if (!a->imm && (a->rs2_or_imm & ~0x1f)) { 31000faef01bSRichard Henderson return false; 31010faef01bSRichard Henderson } 31020faef01bSRichard Henderson if (!priv) { 31030faef01bSRichard Henderson return raise_priv(dc); 31040faef01bSRichard Henderson } 31050faef01bSRichard Henderson 31060faef01bSRichard Henderson if (a->rs1 == 0 && (a->imm || a->rs2_or_imm == 0)) { 31070faef01bSRichard Henderson src = tcg_constant_tl(a->rs2_or_imm); 31080faef01bSRichard Henderson } else { 31090faef01bSRichard Henderson TCGv src1 = gen_load_gpr(dc, a->rs1); 31100faef01bSRichard Henderson if (a->rs2_or_imm == 0) { 31110faef01bSRichard Henderson src = src1; 31120faef01bSRichard Henderson } else { 31130faef01bSRichard Henderson src = tcg_temp_new(); 31140faef01bSRichard Henderson if (a->imm) { 31150faef01bSRichard Henderson tcg_gen_xori_tl(src, src1, a->rs2_or_imm); 31160faef01bSRichard Henderson } else { 31170faef01bSRichard Henderson tcg_gen_xor_tl(src, src1, gen_load_gpr(dc, a->rs2_or_imm)); 31180faef01bSRichard Henderson } 31190faef01bSRichard Henderson } 31200faef01bSRichard Henderson } 31210faef01bSRichard Henderson func(dc, src); 31220faef01bSRichard Henderson return advance_pc(dc); 31230faef01bSRichard Henderson } 31240faef01bSRichard Henderson 31250faef01bSRichard Henderson static void do_wry(DisasContext *dc, TCGv src) 31260faef01bSRichard Henderson { 31270faef01bSRichard Henderson tcg_gen_ext32u_tl(cpu_y, src); 31280faef01bSRichard Henderson } 31290faef01bSRichard Henderson 31300faef01bSRichard Henderson TRANS(WRY, ALL, do_wr_special, a, true, do_wry) 31310faef01bSRichard Henderson 31320faef01bSRichard Henderson static void do_wrccr(DisasContext *dc, TCGv src) 31330faef01bSRichard Henderson { 31340faef01bSRichard Henderson gen_helper_wrccr(tcg_env, src); 31350faef01bSRichard Henderson } 31360faef01bSRichard Henderson 31370faef01bSRichard Henderson TRANS(WRCCR, 64, do_wr_special, a, true, do_wrccr) 31380faef01bSRichard Henderson 31390faef01bSRichard Henderson static void do_wrasi(DisasContext *dc, TCGv src) 31400faef01bSRichard Henderson { 31410faef01bSRichard Henderson TCGv tmp = tcg_temp_new(); 31420faef01bSRichard Henderson 31430faef01bSRichard Henderson tcg_gen_ext8u_tl(tmp, src); 31440faef01bSRichard Henderson tcg_gen_st32_tl(tmp, tcg_env, env64_field_offsetof(asi)); 31450faef01bSRichard Henderson /* End TB to notice changed ASI. */ 31460faef01bSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 31470faef01bSRichard Henderson } 31480faef01bSRichard Henderson 31490faef01bSRichard Henderson TRANS(WRASI, 64, do_wr_special, a, true, do_wrasi) 31500faef01bSRichard Henderson 31510faef01bSRichard Henderson static void do_wrfprs(DisasContext *dc, TCGv src) 31520faef01bSRichard Henderson { 31530faef01bSRichard Henderson #ifdef TARGET_SPARC64 31540faef01bSRichard Henderson tcg_gen_trunc_tl_i32(cpu_fprs, src); 31550faef01bSRichard Henderson dc->fprs_dirty = 0; 31560faef01bSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 31570faef01bSRichard Henderson #else 31580faef01bSRichard Henderson qemu_build_not_reached(); 31590faef01bSRichard Henderson #endif 31600faef01bSRichard Henderson } 31610faef01bSRichard Henderson 31620faef01bSRichard Henderson TRANS(WRFPRS, 64, do_wr_special, a, true, do_wrfprs) 31630faef01bSRichard Henderson 31640faef01bSRichard Henderson static void do_wrgsr(DisasContext *dc, TCGv src) 31650faef01bSRichard Henderson { 31660faef01bSRichard Henderson gen_trap_ifnofpu(dc); 31670faef01bSRichard Henderson tcg_gen_mov_tl(cpu_gsr, src); 31680faef01bSRichard Henderson } 31690faef01bSRichard Henderson 31700faef01bSRichard Henderson TRANS(WRGSR, 64, do_wr_special, a, true, do_wrgsr) 31710faef01bSRichard Henderson 31720faef01bSRichard Henderson static void do_wrsoftint_set(DisasContext *dc, TCGv src) 31730faef01bSRichard Henderson { 31740faef01bSRichard Henderson gen_helper_set_softint(tcg_env, src); 31750faef01bSRichard Henderson } 31760faef01bSRichard Henderson 31770faef01bSRichard Henderson TRANS(WRSOFTINT_SET, 64, do_wr_special, a, supervisor(dc), do_wrsoftint_set) 31780faef01bSRichard Henderson 31790faef01bSRichard Henderson static void do_wrsoftint_clr(DisasContext *dc, TCGv src) 31800faef01bSRichard Henderson { 31810faef01bSRichard Henderson gen_helper_clear_softint(tcg_env, src); 31820faef01bSRichard Henderson } 31830faef01bSRichard Henderson 31840faef01bSRichard Henderson TRANS(WRSOFTINT_CLR, 64, do_wr_special, a, supervisor(dc), do_wrsoftint_clr) 31850faef01bSRichard Henderson 31860faef01bSRichard Henderson static void do_wrsoftint(DisasContext *dc, TCGv src) 31870faef01bSRichard Henderson { 31880faef01bSRichard Henderson gen_helper_write_softint(tcg_env, src); 31890faef01bSRichard Henderson } 31900faef01bSRichard Henderson 31910faef01bSRichard Henderson TRANS(WRSOFTINT, 64, do_wr_special, a, supervisor(dc), do_wrsoftint) 31920faef01bSRichard Henderson 31930faef01bSRichard Henderson static void do_wrtick_cmpr(DisasContext *dc, TCGv src) 31940faef01bSRichard Henderson { 31950faef01bSRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr(); 31960faef01bSRichard Henderson 3197577efa45SRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(tick_cmpr)); 3198577efa45SRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(tick)); 31990faef01bSRichard Henderson translator_io_start(&dc->base); 3200577efa45SRichard Henderson gen_helper_tick_set_limit(r_tickptr, src); 32010faef01bSRichard Henderson /* End TB to handle timer interrupt */ 32020faef01bSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 32030faef01bSRichard Henderson } 32040faef01bSRichard Henderson 32050faef01bSRichard Henderson TRANS(WRTICK_CMPR, 64, do_wr_special, a, supervisor(dc), do_wrtick_cmpr) 32060faef01bSRichard Henderson 32070faef01bSRichard Henderson static void do_wrstick(DisasContext *dc, TCGv src) 32080faef01bSRichard Henderson { 32090faef01bSRichard Henderson #ifdef TARGET_SPARC64 32100faef01bSRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr(); 32110faef01bSRichard Henderson 32120faef01bSRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, offsetof(CPUSPARCState, stick)); 32130faef01bSRichard Henderson translator_io_start(&dc->base); 32140faef01bSRichard Henderson gen_helper_tick_set_count(r_tickptr, src); 32150faef01bSRichard Henderson /* End TB to handle timer interrupt */ 32160faef01bSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 32170faef01bSRichard Henderson #else 32180faef01bSRichard Henderson qemu_build_not_reached(); 32190faef01bSRichard Henderson #endif 32200faef01bSRichard Henderson } 32210faef01bSRichard Henderson 32220faef01bSRichard Henderson TRANS(WRSTICK, 64, do_wr_special, a, supervisor(dc), do_wrstick) 32230faef01bSRichard Henderson 32240faef01bSRichard Henderson static void do_wrstick_cmpr(DisasContext *dc, TCGv src) 32250faef01bSRichard Henderson { 32260faef01bSRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr(); 32270faef01bSRichard Henderson 3228577efa45SRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(stick_cmpr)); 3229577efa45SRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(stick)); 32300faef01bSRichard Henderson translator_io_start(&dc->base); 3231577efa45SRichard Henderson gen_helper_tick_set_limit(r_tickptr, src); 32320faef01bSRichard Henderson /* End TB to handle timer interrupt */ 32330faef01bSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 32340faef01bSRichard Henderson } 32350faef01bSRichard Henderson 32360faef01bSRichard Henderson TRANS(WRSTICK_CMPR, 64, do_wr_special, a, supervisor(dc), do_wrstick_cmpr) 32370faef01bSRichard Henderson 32380faef01bSRichard Henderson static void do_wrpowerdown(DisasContext *dc, TCGv src) 32390faef01bSRichard Henderson { 324089527e3aSRichard Henderson finishing_insn(dc); 32410faef01bSRichard Henderson save_state(dc); 32420faef01bSRichard Henderson gen_helper_power_down(tcg_env); 32430faef01bSRichard Henderson } 32440faef01bSRichard Henderson 32450faef01bSRichard Henderson TRANS(WRPOWERDOWN, POWERDOWN, do_wr_special, a, supervisor(dc), do_wrpowerdown) 32460faef01bSRichard Henderson 324725524734SRichard Henderson static void do_wrpsr(DisasContext *dc, TCGv src) 324825524734SRichard Henderson { 324925524734SRichard Henderson gen_helper_wrpsr(tcg_env, src); 325025524734SRichard Henderson dc->base.is_jmp = DISAS_EXIT; 325125524734SRichard Henderson } 325225524734SRichard Henderson 325325524734SRichard Henderson TRANS(WRPSR, 32, do_wr_special, a, supervisor(dc), do_wrpsr) 325425524734SRichard Henderson 32559422278eSRichard Henderson static void do_wrwim(DisasContext *dc, TCGv src) 32569422278eSRichard Henderson { 32579422278eSRichard Henderson target_ulong mask = MAKE_64BIT_MASK(0, dc->def->nwindows); 3258cd6269f7SRichard Henderson TCGv tmp = tcg_temp_new(); 3259cd6269f7SRichard Henderson 3260cd6269f7SRichard Henderson tcg_gen_andi_tl(tmp, src, mask); 3261cd6269f7SRichard Henderson tcg_gen_st_tl(tmp, tcg_env, env32_field_offsetof(wim)); 32629422278eSRichard Henderson } 32639422278eSRichard Henderson 32649422278eSRichard Henderson TRANS(WRWIM, 32, do_wr_special, a, supervisor(dc), do_wrwim) 32659422278eSRichard Henderson 32669422278eSRichard Henderson static void do_wrtpc(DisasContext *dc, TCGv src) 32679422278eSRichard Henderson { 32689422278eSRichard Henderson #ifdef TARGET_SPARC64 32699422278eSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 32709422278eSRichard Henderson 32719422278eSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 32729422278eSRichard Henderson tcg_gen_st_tl(src, r_tsptr, offsetof(trap_state, tpc)); 32739422278eSRichard Henderson #else 32749422278eSRichard Henderson qemu_build_not_reached(); 32759422278eSRichard Henderson #endif 32769422278eSRichard Henderson } 32779422278eSRichard Henderson 32789422278eSRichard Henderson TRANS(WRPR_tpc, 64, do_wr_special, a, supervisor(dc), do_wrtpc) 32799422278eSRichard Henderson 32809422278eSRichard Henderson static void do_wrtnpc(DisasContext *dc, TCGv src) 32819422278eSRichard Henderson { 32829422278eSRichard Henderson #ifdef TARGET_SPARC64 32839422278eSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 32849422278eSRichard Henderson 32859422278eSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 32869422278eSRichard Henderson tcg_gen_st_tl(src, r_tsptr, offsetof(trap_state, tnpc)); 32879422278eSRichard Henderson #else 32889422278eSRichard Henderson qemu_build_not_reached(); 32899422278eSRichard Henderson #endif 32909422278eSRichard Henderson } 32919422278eSRichard Henderson 32929422278eSRichard Henderson TRANS(WRPR_tnpc, 64, do_wr_special, a, supervisor(dc), do_wrtnpc) 32939422278eSRichard Henderson 32949422278eSRichard Henderson static void do_wrtstate(DisasContext *dc, TCGv src) 32959422278eSRichard Henderson { 32969422278eSRichard Henderson #ifdef TARGET_SPARC64 32979422278eSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 32989422278eSRichard Henderson 32999422278eSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 33009422278eSRichard Henderson tcg_gen_st_tl(src, r_tsptr, offsetof(trap_state, tstate)); 33019422278eSRichard Henderson #else 33029422278eSRichard Henderson qemu_build_not_reached(); 33039422278eSRichard Henderson #endif 33049422278eSRichard Henderson } 33059422278eSRichard Henderson 33069422278eSRichard Henderson TRANS(WRPR_tstate, 64, do_wr_special, a, supervisor(dc), do_wrtstate) 33079422278eSRichard Henderson 33089422278eSRichard Henderson static void do_wrtt(DisasContext *dc, TCGv src) 33099422278eSRichard Henderson { 33109422278eSRichard Henderson #ifdef TARGET_SPARC64 33119422278eSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 33129422278eSRichard Henderson 33139422278eSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 33149422278eSRichard Henderson tcg_gen_st32_tl(src, r_tsptr, offsetof(trap_state, tt)); 33159422278eSRichard Henderson #else 33169422278eSRichard Henderson qemu_build_not_reached(); 33179422278eSRichard Henderson #endif 33189422278eSRichard Henderson } 33199422278eSRichard Henderson 33209422278eSRichard Henderson TRANS(WRPR_tt, 64, do_wr_special, a, supervisor(dc), do_wrtt) 33219422278eSRichard Henderson 33229422278eSRichard Henderson static void do_wrtick(DisasContext *dc, TCGv src) 33239422278eSRichard Henderson { 33249422278eSRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr(); 33259422278eSRichard Henderson 33269422278eSRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(tick)); 33279422278eSRichard Henderson translator_io_start(&dc->base); 33289422278eSRichard Henderson gen_helper_tick_set_count(r_tickptr, src); 33299422278eSRichard Henderson /* End TB to handle timer interrupt */ 33309422278eSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 33319422278eSRichard Henderson } 33329422278eSRichard Henderson 33339422278eSRichard Henderson TRANS(WRPR_tick, 64, do_wr_special, a, supervisor(dc), do_wrtick) 33349422278eSRichard Henderson 33359422278eSRichard Henderson static void do_wrtba(DisasContext *dc, TCGv src) 33369422278eSRichard Henderson { 33379422278eSRichard Henderson tcg_gen_mov_tl(cpu_tbr, src); 33389422278eSRichard Henderson } 33399422278eSRichard Henderson 33409422278eSRichard Henderson TRANS(WRPR_tba, 64, do_wr_special, a, supervisor(dc), do_wrtba) 33419422278eSRichard Henderson 33429422278eSRichard Henderson static void do_wrpstate(DisasContext *dc, TCGv src) 33439422278eSRichard Henderson { 33449422278eSRichard Henderson save_state(dc); 33459422278eSRichard Henderson if (translator_io_start(&dc->base)) { 33469422278eSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 33479422278eSRichard Henderson } 33489422278eSRichard Henderson gen_helper_wrpstate(tcg_env, src); 33499422278eSRichard Henderson dc->npc = DYNAMIC_PC; 33509422278eSRichard Henderson } 33519422278eSRichard Henderson 33529422278eSRichard Henderson TRANS(WRPR_pstate, 64, do_wr_special, a, supervisor(dc), do_wrpstate) 33539422278eSRichard Henderson 33549422278eSRichard Henderson static void do_wrtl(DisasContext *dc, TCGv src) 33559422278eSRichard Henderson { 33569422278eSRichard Henderson save_state(dc); 33579422278eSRichard Henderson tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(tl)); 33589422278eSRichard Henderson dc->npc = DYNAMIC_PC; 33599422278eSRichard Henderson } 33609422278eSRichard Henderson 33619422278eSRichard Henderson TRANS(WRPR_tl, 64, do_wr_special, a, supervisor(dc), do_wrtl) 33629422278eSRichard Henderson 33639422278eSRichard Henderson static void do_wrpil(DisasContext *dc, TCGv src) 33649422278eSRichard Henderson { 33659422278eSRichard Henderson if (translator_io_start(&dc->base)) { 33669422278eSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 33679422278eSRichard Henderson } 33689422278eSRichard Henderson gen_helper_wrpil(tcg_env, src); 33699422278eSRichard Henderson } 33709422278eSRichard Henderson 33719422278eSRichard Henderson TRANS(WRPR_pil, 64, do_wr_special, a, supervisor(dc), do_wrpil) 33729422278eSRichard Henderson 33739422278eSRichard Henderson static void do_wrcwp(DisasContext *dc, TCGv src) 33749422278eSRichard Henderson { 33759422278eSRichard Henderson gen_helper_wrcwp(tcg_env, src); 33769422278eSRichard Henderson } 33779422278eSRichard Henderson 33789422278eSRichard Henderson TRANS(WRPR_cwp, 64, do_wr_special, a, supervisor(dc), do_wrcwp) 33799422278eSRichard Henderson 33809422278eSRichard Henderson static void do_wrcansave(DisasContext *dc, TCGv src) 33819422278eSRichard Henderson { 33829422278eSRichard Henderson tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(cansave)); 33839422278eSRichard Henderson } 33849422278eSRichard Henderson 33859422278eSRichard Henderson TRANS(WRPR_cansave, 64, do_wr_special, a, supervisor(dc), do_wrcansave) 33869422278eSRichard Henderson 33879422278eSRichard Henderson static void do_wrcanrestore(DisasContext *dc, TCGv src) 33889422278eSRichard Henderson { 33899422278eSRichard Henderson tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(canrestore)); 33909422278eSRichard Henderson } 33919422278eSRichard Henderson 33929422278eSRichard Henderson TRANS(WRPR_canrestore, 64, do_wr_special, a, supervisor(dc), do_wrcanrestore) 33939422278eSRichard Henderson 33949422278eSRichard Henderson static void do_wrcleanwin(DisasContext *dc, TCGv src) 33959422278eSRichard Henderson { 33969422278eSRichard Henderson tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(cleanwin)); 33979422278eSRichard Henderson } 33989422278eSRichard Henderson 33999422278eSRichard Henderson TRANS(WRPR_cleanwin, 64, do_wr_special, a, supervisor(dc), do_wrcleanwin) 34009422278eSRichard Henderson 34019422278eSRichard Henderson static void do_wrotherwin(DisasContext *dc, TCGv src) 34029422278eSRichard Henderson { 34039422278eSRichard Henderson tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(otherwin)); 34049422278eSRichard Henderson } 34059422278eSRichard Henderson 34069422278eSRichard Henderson TRANS(WRPR_otherwin, 64, do_wr_special, a, supervisor(dc), do_wrotherwin) 34079422278eSRichard Henderson 34089422278eSRichard Henderson static void do_wrwstate(DisasContext *dc, TCGv src) 34099422278eSRichard Henderson { 34109422278eSRichard Henderson tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(wstate)); 34119422278eSRichard Henderson } 34129422278eSRichard Henderson 34139422278eSRichard Henderson TRANS(WRPR_wstate, 64, do_wr_special, a, supervisor(dc), do_wrwstate) 34149422278eSRichard Henderson 34159422278eSRichard Henderson static void do_wrgl(DisasContext *dc, TCGv src) 34169422278eSRichard Henderson { 34179422278eSRichard Henderson gen_helper_wrgl(tcg_env, src); 34189422278eSRichard Henderson } 34199422278eSRichard Henderson 34209422278eSRichard Henderson TRANS(WRPR_gl, GL, do_wr_special, a, supervisor(dc), do_wrgl) 34219422278eSRichard Henderson 34229422278eSRichard Henderson /* UA2005 strand status */ 34239422278eSRichard Henderson static void do_wrssr(DisasContext *dc, TCGv src) 34249422278eSRichard Henderson { 34252da789deSRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(ssr)); 34269422278eSRichard Henderson } 34279422278eSRichard Henderson 34289422278eSRichard Henderson TRANS(WRPR_strand_status, HYPV, do_wr_special, a, hypervisor(dc), do_wrssr) 34299422278eSRichard Henderson 3430bb97f2f5SRichard Henderson TRANS(WRTBR, 32, do_wr_special, a, supervisor(dc), do_wrtba) 3431bb97f2f5SRichard Henderson 3432bb97f2f5SRichard Henderson static void do_wrhpstate(DisasContext *dc, TCGv src) 3433bb97f2f5SRichard Henderson { 3434bb97f2f5SRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(hpstate)); 3435bb97f2f5SRichard Henderson dc->base.is_jmp = DISAS_EXIT; 3436bb97f2f5SRichard Henderson } 3437bb97f2f5SRichard Henderson 3438bb97f2f5SRichard Henderson TRANS(WRHPR_hpstate, HYPV, do_wr_special, a, hypervisor(dc), do_wrhpstate) 3439bb97f2f5SRichard Henderson 3440bb97f2f5SRichard Henderson static void do_wrhtstate(DisasContext *dc, TCGv src) 3441bb97f2f5SRichard Henderson { 3442bb97f2f5SRichard Henderson TCGv_i32 tl = tcg_temp_new_i32(); 3443bb97f2f5SRichard Henderson TCGv_ptr tp = tcg_temp_new_ptr(); 3444bb97f2f5SRichard Henderson 3445bb97f2f5SRichard Henderson tcg_gen_ld_i32(tl, tcg_env, env64_field_offsetof(tl)); 3446bb97f2f5SRichard Henderson tcg_gen_andi_i32(tl, tl, MAXTL_MASK); 3447bb97f2f5SRichard Henderson tcg_gen_shli_i32(tl, tl, 3); 3448bb97f2f5SRichard Henderson tcg_gen_ext_i32_ptr(tp, tl); 3449bb97f2f5SRichard Henderson tcg_gen_add_ptr(tp, tp, tcg_env); 3450bb97f2f5SRichard Henderson 3451bb97f2f5SRichard Henderson tcg_gen_st_tl(src, tp, env64_field_offsetof(htstate)); 3452bb97f2f5SRichard Henderson } 3453bb97f2f5SRichard Henderson 3454bb97f2f5SRichard Henderson TRANS(WRHPR_htstate, HYPV, do_wr_special, a, hypervisor(dc), do_wrhtstate) 3455bb97f2f5SRichard Henderson 3456bb97f2f5SRichard Henderson static void do_wrhintp(DisasContext *dc, TCGv src) 3457bb97f2f5SRichard Henderson { 34582da789deSRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(hintp)); 3459bb97f2f5SRichard Henderson } 3460bb97f2f5SRichard Henderson 3461bb97f2f5SRichard Henderson TRANS(WRHPR_hintp, HYPV, do_wr_special, a, hypervisor(dc), do_wrhintp) 3462bb97f2f5SRichard Henderson 3463bb97f2f5SRichard Henderson static void do_wrhtba(DisasContext *dc, TCGv src) 3464bb97f2f5SRichard Henderson { 34652da789deSRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(htba)); 3466bb97f2f5SRichard Henderson } 3467bb97f2f5SRichard Henderson 3468bb97f2f5SRichard Henderson TRANS(WRHPR_htba, HYPV, do_wr_special, a, hypervisor(dc), do_wrhtba) 3469bb97f2f5SRichard Henderson 3470bb97f2f5SRichard Henderson static void do_wrhstick_cmpr(DisasContext *dc, TCGv src) 3471bb97f2f5SRichard Henderson { 3472bb97f2f5SRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr(); 3473bb97f2f5SRichard Henderson 3474577efa45SRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(hstick_cmpr)); 3475bb97f2f5SRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(hstick)); 3476bb97f2f5SRichard Henderson translator_io_start(&dc->base); 3477577efa45SRichard Henderson gen_helper_tick_set_limit(r_tickptr, src); 3478bb97f2f5SRichard Henderson /* End TB to handle timer interrupt */ 3479bb97f2f5SRichard Henderson dc->base.is_jmp = DISAS_EXIT; 3480bb97f2f5SRichard Henderson } 3481bb97f2f5SRichard Henderson 3482bb97f2f5SRichard Henderson TRANS(WRHPR_hstick_cmpr, HYPV, do_wr_special, a, hypervisor(dc), 3483bb97f2f5SRichard Henderson do_wrhstick_cmpr) 3484bb97f2f5SRichard Henderson 348525524734SRichard Henderson static bool do_saved_restored(DisasContext *dc, bool saved) 348625524734SRichard Henderson { 348725524734SRichard Henderson if (!supervisor(dc)) { 348825524734SRichard Henderson return raise_priv(dc); 348925524734SRichard Henderson } 349025524734SRichard Henderson if (saved) { 349125524734SRichard Henderson gen_helper_saved(tcg_env); 349225524734SRichard Henderson } else { 349325524734SRichard Henderson gen_helper_restored(tcg_env); 349425524734SRichard Henderson } 349525524734SRichard Henderson return advance_pc(dc); 349625524734SRichard Henderson } 349725524734SRichard Henderson 349825524734SRichard Henderson TRANS(SAVED, 64, do_saved_restored, true) 349925524734SRichard Henderson TRANS(RESTORED, 64, do_saved_restored, false) 350025524734SRichard Henderson 3501d3825800SRichard Henderson static bool trans_NOP(DisasContext *dc, arg_NOP *a) 3502d3825800SRichard Henderson { 3503d3825800SRichard Henderson return advance_pc(dc); 3504d3825800SRichard Henderson } 3505d3825800SRichard Henderson 35060faef01bSRichard Henderson /* 35070faef01bSRichard Henderson * TODO: Need a feature bit for sparcv8. 35080faef01bSRichard Henderson * In the meantime, treat all 32-bit cpus like sparcv7. 35090faef01bSRichard Henderson */ 35105458fd31SRichard Henderson TRANS(NOP_v7, 32, trans_NOP, a) 35115458fd31SRichard Henderson TRANS(NOP_v9, 64, trans_NOP, a) 35120faef01bSRichard Henderson 3513b597eedcSRichard Henderson static bool do_arith_int(DisasContext *dc, arg_r_r_ri_cc *a, 3514428881deSRichard Henderson void (*func)(TCGv, TCGv, TCGv), 35152a45b736SRichard Henderson void (*funci)(TCGv, TCGv, target_long), 35162a45b736SRichard Henderson bool logic_cc) 3517428881deSRichard Henderson { 3518428881deSRichard Henderson TCGv dst, src1; 3519428881deSRichard Henderson 3520428881deSRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 3521428881deSRichard Henderson if (!a->imm && a->rs2_or_imm & ~0x1f) { 3522428881deSRichard Henderson return false; 3523428881deSRichard Henderson } 3524428881deSRichard Henderson 35252a45b736SRichard Henderson if (logic_cc) { 35262a45b736SRichard Henderson dst = cpu_cc_N; 3527428881deSRichard Henderson } else { 3528428881deSRichard Henderson dst = gen_dest_gpr(dc, a->rd); 3529428881deSRichard Henderson } 3530428881deSRichard Henderson src1 = gen_load_gpr(dc, a->rs1); 3531428881deSRichard Henderson 3532428881deSRichard Henderson if (a->imm || a->rs2_or_imm == 0) { 3533428881deSRichard Henderson if (funci) { 3534428881deSRichard Henderson funci(dst, src1, a->rs2_or_imm); 3535428881deSRichard Henderson } else { 3536428881deSRichard Henderson func(dst, src1, tcg_constant_tl(a->rs2_or_imm)); 3537428881deSRichard Henderson } 3538428881deSRichard Henderson } else { 3539428881deSRichard Henderson func(dst, src1, cpu_regs[a->rs2_or_imm]); 3540428881deSRichard Henderson } 35412a45b736SRichard Henderson 35422a45b736SRichard Henderson if (logic_cc) { 35432a45b736SRichard Henderson if (TARGET_LONG_BITS == 64) { 35442a45b736SRichard Henderson tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N); 35452a45b736SRichard Henderson tcg_gen_movi_tl(cpu_icc_C, 0); 35462a45b736SRichard Henderson } 35472a45b736SRichard Henderson tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N); 35482a45b736SRichard Henderson tcg_gen_movi_tl(cpu_cc_C, 0); 35492a45b736SRichard Henderson tcg_gen_movi_tl(cpu_cc_V, 0); 35502a45b736SRichard Henderson } 35512a45b736SRichard Henderson 3552428881deSRichard Henderson gen_store_gpr(dc, a->rd, dst); 3553428881deSRichard Henderson return advance_pc(dc); 3554428881deSRichard Henderson } 3555428881deSRichard Henderson 3556b597eedcSRichard Henderson static bool do_arith(DisasContext *dc, arg_r_r_ri_cc *a, 3557428881deSRichard Henderson void (*func)(TCGv, TCGv, TCGv), 3558428881deSRichard Henderson void (*funci)(TCGv, TCGv, target_long), 3559428881deSRichard Henderson void (*func_cc)(TCGv, TCGv, TCGv)) 3560428881deSRichard Henderson { 3561428881deSRichard Henderson if (a->cc) { 3562b597eedcSRichard Henderson return do_arith_int(dc, a, func_cc, NULL, false); 3563428881deSRichard Henderson } 3564b597eedcSRichard Henderson return do_arith_int(dc, a, func, funci, false); 3565428881deSRichard Henderson } 3566428881deSRichard Henderson 3567428881deSRichard Henderson static bool do_logic(DisasContext *dc, arg_r_r_ri_cc *a, 3568428881deSRichard Henderson void (*func)(TCGv, TCGv, TCGv), 3569428881deSRichard Henderson void (*funci)(TCGv, TCGv, target_long)) 3570428881deSRichard Henderson { 3571b597eedcSRichard Henderson return do_arith_int(dc, a, func, funci, a->cc); 3572428881deSRichard Henderson } 3573428881deSRichard Henderson 3574b597eedcSRichard Henderson TRANS(ADD, ALL, do_arith, a, tcg_gen_add_tl, tcg_gen_addi_tl, gen_op_addcc) 3575b597eedcSRichard Henderson TRANS(SUB, ALL, do_arith, a, tcg_gen_sub_tl, tcg_gen_subi_tl, gen_op_subcc) 3576b597eedcSRichard Henderson TRANS(ADDC, ALL, do_arith, a, gen_op_addc, NULL, gen_op_addccc) 3577b597eedcSRichard Henderson TRANS(SUBC, ALL, do_arith, a, gen_op_subc, NULL, gen_op_subccc) 3578428881deSRichard Henderson 3579b597eedcSRichard Henderson TRANS(TADDcc, ALL, do_arith, a, NULL, NULL, gen_op_taddcc) 3580b597eedcSRichard Henderson TRANS(TSUBcc, ALL, do_arith, a, NULL, NULL, gen_op_tsubcc) 3581b597eedcSRichard Henderson TRANS(TADDccTV, ALL, do_arith, a, NULL, NULL, gen_op_taddcctv) 3582b597eedcSRichard Henderson TRANS(TSUBccTV, ALL, do_arith, a, NULL, NULL, gen_op_tsubcctv) 3583a9aba13dSRichard Henderson 3584428881deSRichard Henderson TRANS(AND, ALL, do_logic, a, tcg_gen_and_tl, tcg_gen_andi_tl) 3585428881deSRichard Henderson TRANS(XOR, ALL, do_logic, a, tcg_gen_xor_tl, tcg_gen_xori_tl) 3586428881deSRichard Henderson TRANS(ANDN, ALL, do_logic, a, tcg_gen_andc_tl, NULL) 3587428881deSRichard Henderson TRANS(ORN, ALL, do_logic, a, tcg_gen_orc_tl, NULL) 3588428881deSRichard Henderson TRANS(XORN, ALL, do_logic, a, tcg_gen_eqv_tl, NULL) 3589428881deSRichard Henderson 3590b597eedcSRichard Henderson TRANS(MULX, 64, do_arith, a, tcg_gen_mul_tl, tcg_gen_muli_tl, NULL) 3591b5372650SRichard Henderson TRANS(UMUL, MUL, do_logic, a, gen_op_umul, NULL) 3592b5372650SRichard Henderson TRANS(SMUL, MUL, do_logic, a, gen_op_smul, NULL) 3593b597eedcSRichard Henderson TRANS(MULScc, ALL, do_arith, a, NULL, NULL, gen_op_mulscc) 359422188d7dSRichard Henderson 35953a6b8de3SRichard Henderson TRANS(UDIVcc, DIV, do_arith, a, NULL, NULL, gen_op_udivcc) 3596b597eedcSRichard Henderson TRANS(SDIV, DIV, do_arith, a, gen_op_sdiv, NULL, gen_op_sdivcc) 35974ee85ea9SRichard Henderson 35989c6ec5bcSRichard Henderson /* TODO: Should have feature bit -- comes in with UltraSparc T2. */ 3599b597eedcSRichard Henderson TRANS(POPC, 64, do_arith, a, gen_op_popc, NULL, NULL) 36009c6ec5bcSRichard Henderson 3601428881deSRichard Henderson static bool trans_OR(DisasContext *dc, arg_r_r_ri_cc *a) 3602428881deSRichard Henderson { 3603428881deSRichard Henderson /* OR with %g0 is the canonical alias for MOV. */ 3604428881deSRichard Henderson if (!a->cc && a->rs1 == 0) { 3605428881deSRichard Henderson if (a->imm || a->rs2_or_imm == 0) { 3606428881deSRichard Henderson gen_store_gpr(dc, a->rd, tcg_constant_tl(a->rs2_or_imm)); 3607428881deSRichard Henderson } else if (a->rs2_or_imm & ~0x1f) { 3608428881deSRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 3609428881deSRichard Henderson return false; 3610428881deSRichard Henderson } else { 3611428881deSRichard Henderson gen_store_gpr(dc, a->rd, cpu_regs[a->rs2_or_imm]); 3612428881deSRichard Henderson } 3613428881deSRichard Henderson return advance_pc(dc); 3614428881deSRichard Henderson } 3615428881deSRichard Henderson return do_logic(dc, a, tcg_gen_or_tl, tcg_gen_ori_tl); 3616428881deSRichard Henderson } 3617428881deSRichard Henderson 36183a6b8de3SRichard Henderson static bool trans_UDIV(DisasContext *dc, arg_r_r_ri *a) 36193a6b8de3SRichard Henderson { 36203a6b8de3SRichard Henderson TCGv_i64 t1, t2; 36213a6b8de3SRichard Henderson TCGv dst; 36223a6b8de3SRichard Henderson 36233a6b8de3SRichard Henderson if (!avail_DIV(dc)) { 36243a6b8de3SRichard Henderson return false; 36253a6b8de3SRichard Henderson } 36263a6b8de3SRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 36273a6b8de3SRichard Henderson if (!a->imm && a->rs2_or_imm & ~0x1f) { 36283a6b8de3SRichard Henderson return false; 36293a6b8de3SRichard Henderson } 36303a6b8de3SRichard Henderson 36313a6b8de3SRichard Henderson if (unlikely(a->rs2_or_imm == 0)) { 36323a6b8de3SRichard Henderson gen_exception(dc, TT_DIV_ZERO); 36333a6b8de3SRichard Henderson return true; 36343a6b8de3SRichard Henderson } 36353a6b8de3SRichard Henderson 36363a6b8de3SRichard Henderson if (a->imm) { 36373a6b8de3SRichard Henderson t2 = tcg_constant_i64((uint32_t)a->rs2_or_imm); 36383a6b8de3SRichard Henderson } else { 36393a6b8de3SRichard Henderson TCGLabel *lab; 36403a6b8de3SRichard Henderson TCGv_i32 n2; 36413a6b8de3SRichard Henderson 36423a6b8de3SRichard Henderson finishing_insn(dc); 36433a6b8de3SRichard Henderson flush_cond(dc); 36443a6b8de3SRichard Henderson 36453a6b8de3SRichard Henderson n2 = tcg_temp_new_i32(); 36463a6b8de3SRichard Henderson tcg_gen_trunc_tl_i32(n2, cpu_regs[a->rs2_or_imm]); 36473a6b8de3SRichard Henderson 36483a6b8de3SRichard Henderson lab = delay_exception(dc, TT_DIV_ZERO); 36493a6b8de3SRichard Henderson tcg_gen_brcondi_i32(TCG_COND_EQ, n2, 0, lab); 36503a6b8de3SRichard Henderson 36513a6b8de3SRichard Henderson t2 = tcg_temp_new_i64(); 36523a6b8de3SRichard Henderson #ifdef TARGET_SPARC64 36533a6b8de3SRichard Henderson tcg_gen_ext32u_i64(t2, cpu_regs[a->rs2_or_imm]); 36543a6b8de3SRichard Henderson #else 36553a6b8de3SRichard Henderson tcg_gen_extu_i32_i64(t2, cpu_regs[a->rs2_or_imm]); 36563a6b8de3SRichard Henderson #endif 36573a6b8de3SRichard Henderson } 36583a6b8de3SRichard Henderson 36593a6b8de3SRichard Henderson t1 = tcg_temp_new_i64(); 36603a6b8de3SRichard Henderson tcg_gen_concat_tl_i64(t1, gen_load_gpr(dc, a->rs1), cpu_y); 36613a6b8de3SRichard Henderson 36623a6b8de3SRichard Henderson tcg_gen_divu_i64(t1, t1, t2); 36633a6b8de3SRichard Henderson tcg_gen_umin_i64(t1, t1, tcg_constant_i64(UINT32_MAX)); 36643a6b8de3SRichard Henderson 36653a6b8de3SRichard Henderson dst = gen_dest_gpr(dc, a->rd); 36663a6b8de3SRichard Henderson tcg_gen_trunc_i64_tl(dst, t1); 36673a6b8de3SRichard Henderson gen_store_gpr(dc, a->rd, dst); 36683a6b8de3SRichard Henderson return advance_pc(dc); 36693a6b8de3SRichard Henderson } 36703a6b8de3SRichard Henderson 3671f3141174SRichard Henderson static bool trans_UDIVX(DisasContext *dc, arg_r_r_ri *a) 3672f3141174SRichard Henderson { 3673f3141174SRichard Henderson TCGv dst, src1, src2; 3674f3141174SRichard Henderson 3675f3141174SRichard Henderson if (!avail_64(dc)) { 3676f3141174SRichard Henderson return false; 3677f3141174SRichard Henderson } 3678f3141174SRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 3679f3141174SRichard Henderson if (!a->imm && a->rs2_or_imm & ~0x1f) { 3680f3141174SRichard Henderson return false; 3681f3141174SRichard Henderson } 3682f3141174SRichard Henderson 3683f3141174SRichard Henderson if (unlikely(a->rs2_or_imm == 0)) { 3684f3141174SRichard Henderson gen_exception(dc, TT_DIV_ZERO); 3685f3141174SRichard Henderson return true; 3686f3141174SRichard Henderson } 3687f3141174SRichard Henderson 3688f3141174SRichard Henderson if (a->imm) { 3689f3141174SRichard Henderson src2 = tcg_constant_tl(a->rs2_or_imm); 3690f3141174SRichard Henderson } else { 3691f3141174SRichard Henderson TCGLabel *lab; 3692f3141174SRichard Henderson 3693f3141174SRichard Henderson finishing_insn(dc); 3694f3141174SRichard Henderson flush_cond(dc); 3695f3141174SRichard Henderson 3696f3141174SRichard Henderson lab = delay_exception(dc, TT_DIV_ZERO); 3697f3141174SRichard Henderson src2 = cpu_regs[a->rs2_or_imm]; 3698f3141174SRichard Henderson tcg_gen_brcondi_tl(TCG_COND_EQ, src2, 0, lab); 3699f3141174SRichard Henderson } 3700f3141174SRichard Henderson 3701f3141174SRichard Henderson dst = gen_dest_gpr(dc, a->rd); 3702f3141174SRichard Henderson src1 = gen_load_gpr(dc, a->rs1); 3703f3141174SRichard Henderson 3704f3141174SRichard Henderson tcg_gen_divu_tl(dst, src1, src2); 3705f3141174SRichard Henderson gen_store_gpr(dc, a->rd, dst); 3706f3141174SRichard Henderson return advance_pc(dc); 3707f3141174SRichard Henderson } 3708f3141174SRichard Henderson 3709f3141174SRichard Henderson static bool trans_SDIVX(DisasContext *dc, arg_r_r_ri *a) 3710f3141174SRichard Henderson { 3711f3141174SRichard Henderson TCGv dst, src1, src2; 3712f3141174SRichard Henderson 3713f3141174SRichard Henderson if (!avail_64(dc)) { 3714f3141174SRichard Henderson return false; 3715f3141174SRichard Henderson } 3716f3141174SRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 3717f3141174SRichard Henderson if (!a->imm && a->rs2_or_imm & ~0x1f) { 3718f3141174SRichard Henderson return false; 3719f3141174SRichard Henderson } 3720f3141174SRichard Henderson 3721f3141174SRichard Henderson if (unlikely(a->rs2_or_imm == 0)) { 3722f3141174SRichard Henderson gen_exception(dc, TT_DIV_ZERO); 3723f3141174SRichard Henderson return true; 3724f3141174SRichard Henderson } 3725f3141174SRichard Henderson 3726f3141174SRichard Henderson dst = gen_dest_gpr(dc, a->rd); 3727f3141174SRichard Henderson src1 = gen_load_gpr(dc, a->rs1); 3728f3141174SRichard Henderson 3729f3141174SRichard Henderson if (a->imm) { 3730f3141174SRichard Henderson if (unlikely(a->rs2_or_imm == -1)) { 3731f3141174SRichard Henderson tcg_gen_neg_tl(dst, src1); 3732f3141174SRichard Henderson gen_store_gpr(dc, a->rd, dst); 3733f3141174SRichard Henderson return advance_pc(dc); 3734f3141174SRichard Henderson } 3735f3141174SRichard Henderson src2 = tcg_constant_tl(a->rs2_or_imm); 3736f3141174SRichard Henderson } else { 3737f3141174SRichard Henderson TCGLabel *lab; 3738f3141174SRichard Henderson TCGv t1, t2; 3739f3141174SRichard Henderson 3740f3141174SRichard Henderson finishing_insn(dc); 3741f3141174SRichard Henderson flush_cond(dc); 3742f3141174SRichard Henderson 3743f3141174SRichard Henderson lab = delay_exception(dc, TT_DIV_ZERO); 3744f3141174SRichard Henderson src2 = cpu_regs[a->rs2_or_imm]; 3745f3141174SRichard Henderson tcg_gen_brcondi_tl(TCG_COND_EQ, src2, 0, lab); 3746f3141174SRichard Henderson 3747f3141174SRichard Henderson /* 3748f3141174SRichard Henderson * Need to avoid INT64_MIN / -1, which will trap on x86 host. 3749f3141174SRichard Henderson * Set SRC2 to 1 as a new divisor, to produce the correct result. 3750f3141174SRichard Henderson */ 3751f3141174SRichard Henderson t1 = tcg_temp_new(); 3752f3141174SRichard Henderson t2 = tcg_temp_new(); 3753f3141174SRichard Henderson tcg_gen_setcondi_tl(TCG_COND_EQ, t1, src1, (target_long)INT64_MIN); 3754f3141174SRichard Henderson tcg_gen_setcondi_tl(TCG_COND_EQ, t2, src2, -1); 3755f3141174SRichard Henderson tcg_gen_and_tl(t1, t1, t2); 3756f3141174SRichard Henderson tcg_gen_movcond_tl(TCG_COND_NE, t1, t1, tcg_constant_tl(0), 3757f3141174SRichard Henderson tcg_constant_tl(1), src2); 3758f3141174SRichard Henderson src2 = t1; 3759f3141174SRichard Henderson } 3760f3141174SRichard Henderson 3761f3141174SRichard Henderson tcg_gen_div_tl(dst, src1, src2); 3762f3141174SRichard Henderson gen_store_gpr(dc, a->rd, dst); 3763f3141174SRichard Henderson return advance_pc(dc); 3764f3141174SRichard Henderson } 3765f3141174SRichard Henderson 3766b88ce6f2SRichard Henderson static bool gen_edge(DisasContext *dc, arg_r_r_r *a, 3767b88ce6f2SRichard Henderson int width, bool cc, bool left) 3768b88ce6f2SRichard Henderson { 3769b88ce6f2SRichard Henderson TCGv dst, s1, s2, lo1, lo2; 3770b88ce6f2SRichard Henderson uint64_t amask, tabl, tabr; 3771b88ce6f2SRichard Henderson int shift, imask, omask; 3772b88ce6f2SRichard Henderson 3773b88ce6f2SRichard Henderson dst = gen_dest_gpr(dc, a->rd); 3774b88ce6f2SRichard Henderson s1 = gen_load_gpr(dc, a->rs1); 3775b88ce6f2SRichard Henderson s2 = gen_load_gpr(dc, a->rs2); 3776b88ce6f2SRichard Henderson 3777b88ce6f2SRichard Henderson if (cc) { 3778f828df74SRichard Henderson gen_op_subcc(cpu_cc_N, s1, s2); 3779b88ce6f2SRichard Henderson } 3780b88ce6f2SRichard Henderson 3781b88ce6f2SRichard Henderson /* 3782b88ce6f2SRichard Henderson * Theory of operation: there are two tables, left and right (not to 3783b88ce6f2SRichard Henderson * be confused with the left and right versions of the opcode). These 3784b88ce6f2SRichard Henderson * are indexed by the low 3 bits of the inputs. To make things "easy", 3785b88ce6f2SRichard Henderson * these tables are loaded into two constants, TABL and TABR below. 3786b88ce6f2SRichard Henderson * The operation index = (input & imask) << shift calculates the index 3787b88ce6f2SRichard Henderson * into the constant, while val = (table >> index) & omask calculates 3788b88ce6f2SRichard Henderson * the value we're looking for. 3789b88ce6f2SRichard Henderson */ 3790b88ce6f2SRichard Henderson switch (width) { 3791b88ce6f2SRichard Henderson case 8: 3792b88ce6f2SRichard Henderson imask = 0x7; 3793b88ce6f2SRichard Henderson shift = 3; 3794b88ce6f2SRichard Henderson omask = 0xff; 3795b88ce6f2SRichard Henderson if (left) { 3796b88ce6f2SRichard Henderson tabl = 0x80c0e0f0f8fcfeffULL; 3797b88ce6f2SRichard Henderson tabr = 0xff7f3f1f0f070301ULL; 3798b88ce6f2SRichard Henderson } else { 3799b88ce6f2SRichard Henderson tabl = 0x0103070f1f3f7fffULL; 3800b88ce6f2SRichard Henderson tabr = 0xfffefcf8f0e0c080ULL; 3801b88ce6f2SRichard Henderson } 3802b88ce6f2SRichard Henderson break; 3803b88ce6f2SRichard Henderson case 16: 3804b88ce6f2SRichard Henderson imask = 0x6; 3805b88ce6f2SRichard Henderson shift = 1; 3806b88ce6f2SRichard Henderson omask = 0xf; 3807b88ce6f2SRichard Henderson if (left) { 3808b88ce6f2SRichard Henderson tabl = 0x8cef; 3809b88ce6f2SRichard Henderson tabr = 0xf731; 3810b88ce6f2SRichard Henderson } else { 3811b88ce6f2SRichard Henderson tabl = 0x137f; 3812b88ce6f2SRichard Henderson tabr = 0xfec8; 3813b88ce6f2SRichard Henderson } 3814b88ce6f2SRichard Henderson break; 3815b88ce6f2SRichard Henderson case 32: 3816b88ce6f2SRichard Henderson imask = 0x4; 3817b88ce6f2SRichard Henderson shift = 0; 3818b88ce6f2SRichard Henderson omask = 0x3; 3819b88ce6f2SRichard Henderson if (left) { 3820b88ce6f2SRichard Henderson tabl = (2 << 2) | 3; 3821b88ce6f2SRichard Henderson tabr = (3 << 2) | 1; 3822b88ce6f2SRichard Henderson } else { 3823b88ce6f2SRichard Henderson tabl = (1 << 2) | 3; 3824b88ce6f2SRichard Henderson tabr = (3 << 2) | 2; 3825b88ce6f2SRichard Henderson } 3826b88ce6f2SRichard Henderson break; 3827b88ce6f2SRichard Henderson default: 3828b88ce6f2SRichard Henderson abort(); 3829b88ce6f2SRichard Henderson } 3830b88ce6f2SRichard Henderson 3831b88ce6f2SRichard Henderson lo1 = tcg_temp_new(); 3832b88ce6f2SRichard Henderson lo2 = tcg_temp_new(); 3833b88ce6f2SRichard Henderson tcg_gen_andi_tl(lo1, s1, imask); 3834b88ce6f2SRichard Henderson tcg_gen_andi_tl(lo2, s2, imask); 3835b88ce6f2SRichard Henderson tcg_gen_shli_tl(lo1, lo1, shift); 3836b88ce6f2SRichard Henderson tcg_gen_shli_tl(lo2, lo2, shift); 3837b88ce6f2SRichard Henderson 3838b88ce6f2SRichard Henderson tcg_gen_shr_tl(lo1, tcg_constant_tl(tabl), lo1); 3839b88ce6f2SRichard Henderson tcg_gen_shr_tl(lo2, tcg_constant_tl(tabr), lo2); 3840b88ce6f2SRichard Henderson tcg_gen_andi_tl(lo1, lo1, omask); 3841b88ce6f2SRichard Henderson tcg_gen_andi_tl(lo2, lo2, omask); 3842b88ce6f2SRichard Henderson 3843b88ce6f2SRichard Henderson amask = address_mask_i(dc, -8); 3844b88ce6f2SRichard Henderson tcg_gen_andi_tl(s1, s1, amask); 3845b88ce6f2SRichard Henderson tcg_gen_andi_tl(s2, s2, amask); 3846b88ce6f2SRichard Henderson 3847b88ce6f2SRichard Henderson /* Compute dst = (s1 == s2 ? lo1 : lo1 & lo2). */ 3848b88ce6f2SRichard Henderson tcg_gen_and_tl(lo2, lo2, lo1); 3849b88ce6f2SRichard Henderson tcg_gen_movcond_tl(TCG_COND_EQ, dst, s1, s2, lo1, lo2); 3850b88ce6f2SRichard Henderson 3851b88ce6f2SRichard Henderson gen_store_gpr(dc, a->rd, dst); 3852b88ce6f2SRichard Henderson return advance_pc(dc); 3853b88ce6f2SRichard Henderson } 3854b88ce6f2SRichard Henderson 3855b88ce6f2SRichard Henderson TRANS(EDGE8cc, VIS1, gen_edge, a, 8, 1, 0) 3856b88ce6f2SRichard Henderson TRANS(EDGE8Lcc, VIS1, gen_edge, a, 8, 1, 1) 3857b88ce6f2SRichard Henderson TRANS(EDGE16cc, VIS1, gen_edge, a, 16, 1, 0) 3858b88ce6f2SRichard Henderson TRANS(EDGE16Lcc, VIS1, gen_edge, a, 16, 1, 1) 3859b88ce6f2SRichard Henderson TRANS(EDGE32cc, VIS1, gen_edge, a, 32, 1, 0) 3860b88ce6f2SRichard Henderson TRANS(EDGE32Lcc, VIS1, gen_edge, a, 32, 1, 1) 3861b88ce6f2SRichard Henderson 3862b88ce6f2SRichard Henderson TRANS(EDGE8N, VIS2, gen_edge, a, 8, 0, 0) 3863b88ce6f2SRichard Henderson TRANS(EDGE8LN, VIS2, gen_edge, a, 8, 0, 1) 3864b88ce6f2SRichard Henderson TRANS(EDGE16N, VIS2, gen_edge, a, 16, 0, 0) 3865b88ce6f2SRichard Henderson TRANS(EDGE16LN, VIS2, gen_edge, a, 16, 0, 1) 3866b88ce6f2SRichard Henderson TRANS(EDGE32N, VIS2, gen_edge, a, 32, 0, 0) 3867b88ce6f2SRichard Henderson TRANS(EDGE32LN, VIS2, gen_edge, a, 32, 0, 1) 3868b88ce6f2SRichard Henderson 386945bfed3bSRichard Henderson static bool do_rrr(DisasContext *dc, arg_r_r_r *a, 387045bfed3bSRichard Henderson void (*func)(TCGv, TCGv, TCGv)) 387145bfed3bSRichard Henderson { 387245bfed3bSRichard Henderson TCGv dst = gen_dest_gpr(dc, a->rd); 387345bfed3bSRichard Henderson TCGv src1 = gen_load_gpr(dc, a->rs1); 387445bfed3bSRichard Henderson TCGv src2 = gen_load_gpr(dc, a->rs2); 387545bfed3bSRichard Henderson 387645bfed3bSRichard Henderson func(dst, src1, src2); 387745bfed3bSRichard Henderson gen_store_gpr(dc, a->rd, dst); 387845bfed3bSRichard Henderson return advance_pc(dc); 387945bfed3bSRichard Henderson } 388045bfed3bSRichard Henderson 388145bfed3bSRichard Henderson TRANS(ARRAY8, VIS1, do_rrr, a, gen_helper_array8) 388245bfed3bSRichard Henderson TRANS(ARRAY16, VIS1, do_rrr, a, gen_op_array16) 388345bfed3bSRichard Henderson TRANS(ARRAY32, VIS1, do_rrr, a, gen_op_array32) 388445bfed3bSRichard Henderson 38859e20ca94SRichard Henderson static void gen_op_alignaddr(TCGv dst, TCGv s1, TCGv s2) 38869e20ca94SRichard Henderson { 38879e20ca94SRichard Henderson #ifdef TARGET_SPARC64 38889e20ca94SRichard Henderson TCGv tmp = tcg_temp_new(); 38899e20ca94SRichard Henderson 38909e20ca94SRichard Henderson tcg_gen_add_tl(tmp, s1, s2); 38919e20ca94SRichard Henderson tcg_gen_andi_tl(dst, tmp, -8); 38929e20ca94SRichard Henderson tcg_gen_deposit_tl(cpu_gsr, cpu_gsr, tmp, 0, 3); 38939e20ca94SRichard Henderson #else 38949e20ca94SRichard Henderson g_assert_not_reached(); 38959e20ca94SRichard Henderson #endif 38969e20ca94SRichard Henderson } 38979e20ca94SRichard Henderson 38989e20ca94SRichard Henderson static void gen_op_alignaddrl(TCGv dst, TCGv s1, TCGv s2) 38999e20ca94SRichard Henderson { 39009e20ca94SRichard Henderson #ifdef TARGET_SPARC64 39019e20ca94SRichard Henderson TCGv tmp = tcg_temp_new(); 39029e20ca94SRichard Henderson 39039e20ca94SRichard Henderson tcg_gen_add_tl(tmp, s1, s2); 39049e20ca94SRichard Henderson tcg_gen_andi_tl(dst, tmp, -8); 39059e20ca94SRichard Henderson tcg_gen_neg_tl(tmp, tmp); 39069e20ca94SRichard Henderson tcg_gen_deposit_tl(cpu_gsr, cpu_gsr, tmp, 0, 3); 39079e20ca94SRichard Henderson #else 39089e20ca94SRichard Henderson g_assert_not_reached(); 39099e20ca94SRichard Henderson #endif 39109e20ca94SRichard Henderson } 39119e20ca94SRichard Henderson 39129e20ca94SRichard Henderson TRANS(ALIGNADDR, VIS1, do_rrr, a, gen_op_alignaddr) 39139e20ca94SRichard Henderson TRANS(ALIGNADDRL, VIS1, do_rrr, a, gen_op_alignaddrl) 39149e20ca94SRichard Henderson 391539ca3490SRichard Henderson static void gen_op_bmask(TCGv dst, TCGv s1, TCGv s2) 391639ca3490SRichard Henderson { 391739ca3490SRichard Henderson #ifdef TARGET_SPARC64 391839ca3490SRichard Henderson tcg_gen_add_tl(dst, s1, s2); 391939ca3490SRichard Henderson tcg_gen_deposit_tl(cpu_gsr, cpu_gsr, dst, 32, 32); 392039ca3490SRichard Henderson #else 392139ca3490SRichard Henderson g_assert_not_reached(); 392239ca3490SRichard Henderson #endif 392339ca3490SRichard Henderson } 392439ca3490SRichard Henderson 392539ca3490SRichard Henderson TRANS(BMASK, VIS2, do_rrr, a, gen_op_bmask) 392639ca3490SRichard Henderson 39275fc546eeSRichard Henderson static bool do_shift_r(DisasContext *dc, arg_shiftr *a, bool l, bool u) 39285fc546eeSRichard Henderson { 39295fc546eeSRichard Henderson TCGv dst, src1, src2; 39305fc546eeSRichard Henderson 39315fc546eeSRichard Henderson /* Reject 64-bit shifts for sparc32. */ 39325fc546eeSRichard Henderson if (avail_32(dc) && a->x) { 39335fc546eeSRichard Henderson return false; 39345fc546eeSRichard Henderson } 39355fc546eeSRichard Henderson 39365fc546eeSRichard Henderson src2 = tcg_temp_new(); 39375fc546eeSRichard Henderson tcg_gen_andi_tl(src2, gen_load_gpr(dc, a->rs2), a->x ? 63 : 31); 39385fc546eeSRichard Henderson src1 = gen_load_gpr(dc, a->rs1); 39395fc546eeSRichard Henderson dst = gen_dest_gpr(dc, a->rd); 39405fc546eeSRichard Henderson 39415fc546eeSRichard Henderson if (l) { 39425fc546eeSRichard Henderson tcg_gen_shl_tl(dst, src1, src2); 39435fc546eeSRichard Henderson if (!a->x) { 39445fc546eeSRichard Henderson tcg_gen_ext32u_tl(dst, dst); 39455fc546eeSRichard Henderson } 39465fc546eeSRichard Henderson } else if (u) { 39475fc546eeSRichard Henderson if (!a->x) { 39485fc546eeSRichard Henderson tcg_gen_ext32u_tl(dst, src1); 39495fc546eeSRichard Henderson src1 = dst; 39505fc546eeSRichard Henderson } 39515fc546eeSRichard Henderson tcg_gen_shr_tl(dst, src1, src2); 39525fc546eeSRichard Henderson } else { 39535fc546eeSRichard Henderson if (!a->x) { 39545fc546eeSRichard Henderson tcg_gen_ext32s_tl(dst, src1); 39555fc546eeSRichard Henderson src1 = dst; 39565fc546eeSRichard Henderson } 39575fc546eeSRichard Henderson tcg_gen_sar_tl(dst, src1, src2); 39585fc546eeSRichard Henderson } 39595fc546eeSRichard Henderson gen_store_gpr(dc, a->rd, dst); 39605fc546eeSRichard Henderson return advance_pc(dc); 39615fc546eeSRichard Henderson } 39625fc546eeSRichard Henderson 39635fc546eeSRichard Henderson TRANS(SLL_r, ALL, do_shift_r, a, true, true) 39645fc546eeSRichard Henderson TRANS(SRL_r, ALL, do_shift_r, a, false, true) 39655fc546eeSRichard Henderson TRANS(SRA_r, ALL, do_shift_r, a, false, false) 39665fc546eeSRichard Henderson 39675fc546eeSRichard Henderson static bool do_shift_i(DisasContext *dc, arg_shifti *a, bool l, bool u) 39685fc546eeSRichard Henderson { 39695fc546eeSRichard Henderson TCGv dst, src1; 39705fc546eeSRichard Henderson 39715fc546eeSRichard Henderson /* Reject 64-bit shifts for sparc32. */ 39725fc546eeSRichard Henderson if (avail_32(dc) && (a->x || a->i >= 32)) { 39735fc546eeSRichard Henderson return false; 39745fc546eeSRichard Henderson } 39755fc546eeSRichard Henderson 39765fc546eeSRichard Henderson src1 = gen_load_gpr(dc, a->rs1); 39775fc546eeSRichard Henderson dst = gen_dest_gpr(dc, a->rd); 39785fc546eeSRichard Henderson 39795fc546eeSRichard Henderson if (avail_32(dc) || a->x) { 39805fc546eeSRichard Henderson if (l) { 39815fc546eeSRichard Henderson tcg_gen_shli_tl(dst, src1, a->i); 39825fc546eeSRichard Henderson } else if (u) { 39835fc546eeSRichard Henderson tcg_gen_shri_tl(dst, src1, a->i); 39845fc546eeSRichard Henderson } else { 39855fc546eeSRichard Henderson tcg_gen_sari_tl(dst, src1, a->i); 39865fc546eeSRichard Henderson } 39875fc546eeSRichard Henderson } else { 39885fc546eeSRichard Henderson if (l) { 39895fc546eeSRichard Henderson tcg_gen_deposit_z_tl(dst, src1, a->i, 32 - a->i); 39905fc546eeSRichard Henderson } else if (u) { 39915fc546eeSRichard Henderson tcg_gen_extract_tl(dst, src1, a->i, 32 - a->i); 39925fc546eeSRichard Henderson } else { 39935fc546eeSRichard Henderson tcg_gen_sextract_tl(dst, src1, a->i, 32 - a->i); 39945fc546eeSRichard Henderson } 39955fc546eeSRichard Henderson } 39965fc546eeSRichard Henderson gen_store_gpr(dc, a->rd, dst); 39975fc546eeSRichard Henderson return advance_pc(dc); 39985fc546eeSRichard Henderson } 39995fc546eeSRichard Henderson 40005fc546eeSRichard Henderson TRANS(SLL_i, ALL, do_shift_i, a, true, true) 40015fc546eeSRichard Henderson TRANS(SRL_i, ALL, do_shift_i, a, false, true) 40025fc546eeSRichard Henderson TRANS(SRA_i, ALL, do_shift_i, a, false, false) 40035fc546eeSRichard Henderson 4004fb4ed7aaSRichard Henderson static TCGv gen_rs2_or_imm(DisasContext *dc, bool imm, int rs2_or_imm) 4005fb4ed7aaSRichard Henderson { 4006fb4ed7aaSRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 4007fb4ed7aaSRichard Henderson if (!imm && rs2_or_imm & ~0x1f) { 4008fb4ed7aaSRichard Henderson return NULL; 4009fb4ed7aaSRichard Henderson } 4010fb4ed7aaSRichard Henderson if (imm || rs2_or_imm == 0) { 4011fb4ed7aaSRichard Henderson return tcg_constant_tl(rs2_or_imm); 4012fb4ed7aaSRichard Henderson } else { 4013fb4ed7aaSRichard Henderson return cpu_regs[rs2_or_imm]; 4014fb4ed7aaSRichard Henderson } 4015fb4ed7aaSRichard Henderson } 4016fb4ed7aaSRichard Henderson 4017fb4ed7aaSRichard Henderson static bool do_mov_cond(DisasContext *dc, DisasCompare *cmp, int rd, TCGv src2) 4018fb4ed7aaSRichard Henderson { 4019fb4ed7aaSRichard Henderson TCGv dst = gen_load_gpr(dc, rd); 4020c8507ebfSRichard Henderson TCGv c2 = tcg_constant_tl(cmp->c2); 4021fb4ed7aaSRichard Henderson 4022c8507ebfSRichard Henderson tcg_gen_movcond_tl(cmp->cond, dst, cmp->c1, c2, src2, dst); 4023fb4ed7aaSRichard Henderson gen_store_gpr(dc, rd, dst); 4024fb4ed7aaSRichard Henderson return advance_pc(dc); 4025fb4ed7aaSRichard Henderson } 4026fb4ed7aaSRichard Henderson 4027fb4ed7aaSRichard Henderson static bool trans_MOVcc(DisasContext *dc, arg_MOVcc *a) 4028fb4ed7aaSRichard Henderson { 4029fb4ed7aaSRichard Henderson TCGv src2 = gen_rs2_or_imm(dc, a->imm, a->rs2_or_imm); 4030fb4ed7aaSRichard Henderson DisasCompare cmp; 4031fb4ed7aaSRichard Henderson 4032fb4ed7aaSRichard Henderson if (src2 == NULL) { 4033fb4ed7aaSRichard Henderson return false; 4034fb4ed7aaSRichard Henderson } 4035fb4ed7aaSRichard Henderson gen_compare(&cmp, a->cc, a->cond, dc); 4036fb4ed7aaSRichard Henderson return do_mov_cond(dc, &cmp, a->rd, src2); 4037fb4ed7aaSRichard Henderson } 4038fb4ed7aaSRichard Henderson 4039fb4ed7aaSRichard Henderson static bool trans_MOVfcc(DisasContext *dc, arg_MOVfcc *a) 4040fb4ed7aaSRichard Henderson { 4041fb4ed7aaSRichard Henderson TCGv src2 = gen_rs2_or_imm(dc, a->imm, a->rs2_or_imm); 4042fb4ed7aaSRichard Henderson DisasCompare cmp; 4043fb4ed7aaSRichard Henderson 4044fb4ed7aaSRichard Henderson if (src2 == NULL) { 4045fb4ed7aaSRichard Henderson return false; 4046fb4ed7aaSRichard Henderson } 4047fb4ed7aaSRichard Henderson gen_fcompare(&cmp, a->cc, a->cond); 4048fb4ed7aaSRichard Henderson return do_mov_cond(dc, &cmp, a->rd, src2); 4049fb4ed7aaSRichard Henderson } 4050fb4ed7aaSRichard Henderson 4051fb4ed7aaSRichard Henderson static bool trans_MOVR(DisasContext *dc, arg_MOVR *a) 4052fb4ed7aaSRichard Henderson { 4053fb4ed7aaSRichard Henderson TCGv src2 = gen_rs2_or_imm(dc, a->imm, a->rs2_or_imm); 4054fb4ed7aaSRichard Henderson DisasCompare cmp; 4055fb4ed7aaSRichard Henderson 4056fb4ed7aaSRichard Henderson if (src2 == NULL) { 4057fb4ed7aaSRichard Henderson return false; 4058fb4ed7aaSRichard Henderson } 40592c4f56c9SRichard Henderson if (!gen_compare_reg(&cmp, a->cond, gen_load_gpr(dc, a->rs1))) { 40602c4f56c9SRichard Henderson return false; 40612c4f56c9SRichard Henderson } 4062fb4ed7aaSRichard Henderson return do_mov_cond(dc, &cmp, a->rd, src2); 4063fb4ed7aaSRichard Henderson } 4064fb4ed7aaSRichard Henderson 406586b82fe0SRichard Henderson static bool do_add_special(DisasContext *dc, arg_r_r_ri *a, 406686b82fe0SRichard Henderson bool (*func)(DisasContext *dc, int rd, TCGv src)) 406786b82fe0SRichard Henderson { 406886b82fe0SRichard Henderson TCGv src1, sum; 406986b82fe0SRichard Henderson 407086b82fe0SRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 407186b82fe0SRichard Henderson if (!a->imm && a->rs2_or_imm & ~0x1f) { 407286b82fe0SRichard Henderson return false; 407386b82fe0SRichard Henderson } 407486b82fe0SRichard Henderson 407586b82fe0SRichard Henderson /* 407686b82fe0SRichard Henderson * Always load the sum into a new temporary. 407786b82fe0SRichard Henderson * This is required to capture the value across a window change, 407886b82fe0SRichard Henderson * e.g. SAVE and RESTORE, and may be optimized away otherwise. 407986b82fe0SRichard Henderson */ 408086b82fe0SRichard Henderson sum = tcg_temp_new(); 408186b82fe0SRichard Henderson src1 = gen_load_gpr(dc, a->rs1); 408286b82fe0SRichard Henderson if (a->imm || a->rs2_or_imm == 0) { 408386b82fe0SRichard Henderson tcg_gen_addi_tl(sum, src1, a->rs2_or_imm); 408486b82fe0SRichard Henderson } else { 408586b82fe0SRichard Henderson tcg_gen_add_tl(sum, src1, cpu_regs[a->rs2_or_imm]); 408686b82fe0SRichard Henderson } 408786b82fe0SRichard Henderson return func(dc, a->rd, sum); 408886b82fe0SRichard Henderson } 408986b82fe0SRichard Henderson 409086b82fe0SRichard Henderson static bool do_jmpl(DisasContext *dc, int rd, TCGv src) 409186b82fe0SRichard Henderson { 409286b82fe0SRichard Henderson /* 409386b82fe0SRichard Henderson * Preserve pc across advance, so that we can delay 409486b82fe0SRichard Henderson * the writeback to rd until after src is consumed. 409586b82fe0SRichard Henderson */ 409686b82fe0SRichard Henderson target_ulong cur_pc = dc->pc; 409786b82fe0SRichard Henderson 409886b82fe0SRichard Henderson gen_check_align(dc, src, 3); 409986b82fe0SRichard Henderson 410086b82fe0SRichard Henderson gen_mov_pc_npc(dc); 410186b82fe0SRichard Henderson tcg_gen_mov_tl(cpu_npc, src); 410286b82fe0SRichard Henderson gen_address_mask(dc, cpu_npc); 410386b82fe0SRichard Henderson gen_store_gpr(dc, rd, tcg_constant_tl(cur_pc)); 410486b82fe0SRichard Henderson 410586b82fe0SRichard Henderson dc->npc = DYNAMIC_PC_LOOKUP; 410686b82fe0SRichard Henderson return true; 410786b82fe0SRichard Henderson } 410886b82fe0SRichard Henderson 410986b82fe0SRichard Henderson TRANS(JMPL, ALL, do_add_special, a, do_jmpl) 411086b82fe0SRichard Henderson 411186b82fe0SRichard Henderson static bool do_rett(DisasContext *dc, int rd, TCGv src) 411286b82fe0SRichard Henderson { 411386b82fe0SRichard Henderson if (!supervisor(dc)) { 411486b82fe0SRichard Henderson return raise_priv(dc); 411586b82fe0SRichard Henderson } 411686b82fe0SRichard Henderson 411786b82fe0SRichard Henderson gen_check_align(dc, src, 3); 411886b82fe0SRichard Henderson 411986b82fe0SRichard Henderson gen_mov_pc_npc(dc); 412086b82fe0SRichard Henderson tcg_gen_mov_tl(cpu_npc, src); 412186b82fe0SRichard Henderson gen_helper_rett(tcg_env); 412286b82fe0SRichard Henderson 412386b82fe0SRichard Henderson dc->npc = DYNAMIC_PC; 412486b82fe0SRichard Henderson return true; 412586b82fe0SRichard Henderson } 412686b82fe0SRichard Henderson 412786b82fe0SRichard Henderson TRANS(RETT, 32, do_add_special, a, do_rett) 412886b82fe0SRichard Henderson 412986b82fe0SRichard Henderson static bool do_return(DisasContext *dc, int rd, TCGv src) 413086b82fe0SRichard Henderson { 413186b82fe0SRichard Henderson gen_check_align(dc, src, 3); 41320dfae4f9SRichard Henderson gen_helper_restore(tcg_env); 413386b82fe0SRichard Henderson 413486b82fe0SRichard Henderson gen_mov_pc_npc(dc); 413586b82fe0SRichard Henderson tcg_gen_mov_tl(cpu_npc, src); 413686b82fe0SRichard Henderson gen_address_mask(dc, cpu_npc); 413786b82fe0SRichard Henderson 413886b82fe0SRichard Henderson dc->npc = DYNAMIC_PC_LOOKUP; 413986b82fe0SRichard Henderson return true; 414086b82fe0SRichard Henderson } 414186b82fe0SRichard Henderson 414286b82fe0SRichard Henderson TRANS(RETURN, 64, do_add_special, a, do_return) 414386b82fe0SRichard Henderson 4144d3825800SRichard Henderson static bool do_save(DisasContext *dc, int rd, TCGv src) 4145d3825800SRichard Henderson { 4146d3825800SRichard Henderson gen_helper_save(tcg_env); 4147d3825800SRichard Henderson gen_store_gpr(dc, rd, src); 4148d3825800SRichard Henderson return advance_pc(dc); 4149d3825800SRichard Henderson } 4150d3825800SRichard Henderson 4151d3825800SRichard Henderson TRANS(SAVE, ALL, do_add_special, a, do_save) 4152d3825800SRichard Henderson 4153d3825800SRichard Henderson static bool do_restore(DisasContext *dc, int rd, TCGv src) 4154d3825800SRichard Henderson { 4155d3825800SRichard Henderson gen_helper_restore(tcg_env); 4156d3825800SRichard Henderson gen_store_gpr(dc, rd, src); 4157d3825800SRichard Henderson return advance_pc(dc); 4158d3825800SRichard Henderson } 4159d3825800SRichard Henderson 4160d3825800SRichard Henderson TRANS(RESTORE, ALL, do_add_special, a, do_restore) 4161d3825800SRichard Henderson 41628f75b8a4SRichard Henderson static bool do_done_retry(DisasContext *dc, bool done) 41638f75b8a4SRichard Henderson { 41648f75b8a4SRichard Henderson if (!supervisor(dc)) { 41658f75b8a4SRichard Henderson return raise_priv(dc); 41668f75b8a4SRichard Henderson } 41678f75b8a4SRichard Henderson dc->npc = DYNAMIC_PC; 41688f75b8a4SRichard Henderson dc->pc = DYNAMIC_PC; 41698f75b8a4SRichard Henderson translator_io_start(&dc->base); 41708f75b8a4SRichard Henderson if (done) { 41718f75b8a4SRichard Henderson gen_helper_done(tcg_env); 41728f75b8a4SRichard Henderson } else { 41738f75b8a4SRichard Henderson gen_helper_retry(tcg_env); 41748f75b8a4SRichard Henderson } 41758f75b8a4SRichard Henderson return true; 41768f75b8a4SRichard Henderson } 41778f75b8a4SRichard Henderson 41788f75b8a4SRichard Henderson TRANS(DONE, 64, do_done_retry, true) 41798f75b8a4SRichard Henderson TRANS(RETRY, 64, do_done_retry, false) 41808f75b8a4SRichard Henderson 41810880d20bSRichard Henderson /* 41820880d20bSRichard Henderson * Major opcode 11 -- load and store instructions 41830880d20bSRichard Henderson */ 41840880d20bSRichard Henderson 41850880d20bSRichard Henderson static TCGv gen_ldst_addr(DisasContext *dc, int rs1, bool imm, int rs2_or_imm) 41860880d20bSRichard Henderson { 41870880d20bSRichard Henderson TCGv addr, tmp = NULL; 41880880d20bSRichard Henderson 41890880d20bSRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 41900880d20bSRichard Henderson if (!imm && rs2_or_imm & ~0x1f) { 41910880d20bSRichard Henderson return NULL; 41920880d20bSRichard Henderson } 41930880d20bSRichard Henderson 41940880d20bSRichard Henderson addr = gen_load_gpr(dc, rs1); 41950880d20bSRichard Henderson if (rs2_or_imm) { 41960880d20bSRichard Henderson tmp = tcg_temp_new(); 41970880d20bSRichard Henderson if (imm) { 41980880d20bSRichard Henderson tcg_gen_addi_tl(tmp, addr, rs2_or_imm); 41990880d20bSRichard Henderson } else { 42000880d20bSRichard Henderson tcg_gen_add_tl(tmp, addr, cpu_regs[rs2_or_imm]); 42010880d20bSRichard Henderson } 42020880d20bSRichard Henderson addr = tmp; 42030880d20bSRichard Henderson } 42040880d20bSRichard Henderson if (AM_CHECK(dc)) { 42050880d20bSRichard Henderson if (!tmp) { 42060880d20bSRichard Henderson tmp = tcg_temp_new(); 42070880d20bSRichard Henderson } 42080880d20bSRichard Henderson tcg_gen_ext32u_tl(tmp, addr); 42090880d20bSRichard Henderson addr = tmp; 42100880d20bSRichard Henderson } 42110880d20bSRichard Henderson return addr; 42120880d20bSRichard Henderson } 42130880d20bSRichard Henderson 42140880d20bSRichard Henderson static bool do_ld_gpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp mop) 42150880d20bSRichard Henderson { 42160880d20bSRichard Henderson TCGv reg, addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 42170880d20bSRichard Henderson DisasASI da; 42180880d20bSRichard Henderson 42190880d20bSRichard Henderson if (addr == NULL) { 42200880d20bSRichard Henderson return false; 42210880d20bSRichard Henderson } 42220880d20bSRichard Henderson da = resolve_asi(dc, a->asi, mop); 42230880d20bSRichard Henderson 42240880d20bSRichard Henderson reg = gen_dest_gpr(dc, a->rd); 422542071fc1SRichard Henderson gen_ld_asi(dc, &da, reg, addr); 42260880d20bSRichard Henderson gen_store_gpr(dc, a->rd, reg); 42270880d20bSRichard Henderson return advance_pc(dc); 42280880d20bSRichard Henderson } 42290880d20bSRichard Henderson 42300880d20bSRichard Henderson TRANS(LDUW, ALL, do_ld_gpr, a, MO_TEUL) 42310880d20bSRichard Henderson TRANS(LDUB, ALL, do_ld_gpr, a, MO_UB) 42320880d20bSRichard Henderson TRANS(LDUH, ALL, do_ld_gpr, a, MO_TEUW) 42330880d20bSRichard Henderson TRANS(LDSB, ALL, do_ld_gpr, a, MO_SB) 42340880d20bSRichard Henderson TRANS(LDSH, ALL, do_ld_gpr, a, MO_TESW) 42350880d20bSRichard Henderson TRANS(LDSW, 64, do_ld_gpr, a, MO_TESL) 42360880d20bSRichard Henderson TRANS(LDX, 64, do_ld_gpr, a, MO_TEUQ) 42370880d20bSRichard Henderson 42380880d20bSRichard Henderson static bool do_st_gpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp mop) 42390880d20bSRichard Henderson { 42400880d20bSRichard Henderson TCGv reg, addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 42410880d20bSRichard Henderson DisasASI da; 42420880d20bSRichard Henderson 42430880d20bSRichard Henderson if (addr == NULL) { 42440880d20bSRichard Henderson return false; 42450880d20bSRichard Henderson } 42460880d20bSRichard Henderson da = resolve_asi(dc, a->asi, mop); 42470880d20bSRichard Henderson 42480880d20bSRichard Henderson reg = gen_load_gpr(dc, a->rd); 424942071fc1SRichard Henderson gen_st_asi(dc, &da, reg, addr); 42500880d20bSRichard Henderson return advance_pc(dc); 42510880d20bSRichard Henderson } 42520880d20bSRichard Henderson 42530880d20bSRichard Henderson TRANS(STW, ALL, do_st_gpr, a, MO_TEUL) 42540880d20bSRichard Henderson TRANS(STB, ALL, do_st_gpr, a, MO_UB) 42550880d20bSRichard Henderson TRANS(STH, ALL, do_st_gpr, a, MO_TEUW) 42560880d20bSRichard Henderson TRANS(STX, 64, do_st_gpr, a, MO_TEUQ) 42570880d20bSRichard Henderson 42580880d20bSRichard Henderson static bool trans_LDD(DisasContext *dc, arg_r_r_ri_asi *a) 42590880d20bSRichard Henderson { 42600880d20bSRichard Henderson TCGv addr; 42610880d20bSRichard Henderson DisasASI da; 42620880d20bSRichard Henderson 42630880d20bSRichard Henderson if (a->rd & 1) { 42640880d20bSRichard Henderson return false; 42650880d20bSRichard Henderson } 42660880d20bSRichard Henderson addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 42670880d20bSRichard Henderson if (addr == NULL) { 42680880d20bSRichard Henderson return false; 42690880d20bSRichard Henderson } 42700880d20bSRichard Henderson da = resolve_asi(dc, a->asi, MO_TEUQ); 427142071fc1SRichard Henderson gen_ldda_asi(dc, &da, addr, a->rd); 42720880d20bSRichard Henderson return advance_pc(dc); 42730880d20bSRichard Henderson } 42740880d20bSRichard Henderson 42750880d20bSRichard Henderson static bool trans_STD(DisasContext *dc, arg_r_r_ri_asi *a) 42760880d20bSRichard Henderson { 42770880d20bSRichard Henderson TCGv addr; 42780880d20bSRichard Henderson DisasASI da; 42790880d20bSRichard Henderson 42800880d20bSRichard Henderson if (a->rd & 1) { 42810880d20bSRichard Henderson return false; 42820880d20bSRichard Henderson } 42830880d20bSRichard Henderson addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 42840880d20bSRichard Henderson if (addr == NULL) { 42850880d20bSRichard Henderson return false; 42860880d20bSRichard Henderson } 42870880d20bSRichard Henderson da = resolve_asi(dc, a->asi, MO_TEUQ); 428842071fc1SRichard Henderson gen_stda_asi(dc, &da, addr, a->rd); 42890880d20bSRichard Henderson return advance_pc(dc); 42900880d20bSRichard Henderson } 42910880d20bSRichard Henderson 4292cf07cd1eSRichard Henderson static bool trans_LDSTUB(DisasContext *dc, arg_r_r_ri_asi *a) 4293cf07cd1eSRichard Henderson { 4294cf07cd1eSRichard Henderson TCGv addr, reg; 4295cf07cd1eSRichard Henderson DisasASI da; 4296cf07cd1eSRichard Henderson 4297cf07cd1eSRichard Henderson addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 4298cf07cd1eSRichard Henderson if (addr == NULL) { 4299cf07cd1eSRichard Henderson return false; 4300cf07cd1eSRichard Henderson } 4301cf07cd1eSRichard Henderson da = resolve_asi(dc, a->asi, MO_UB); 4302cf07cd1eSRichard Henderson 4303cf07cd1eSRichard Henderson reg = gen_dest_gpr(dc, a->rd); 4304cf07cd1eSRichard Henderson gen_ldstub_asi(dc, &da, reg, addr); 4305cf07cd1eSRichard Henderson gen_store_gpr(dc, a->rd, reg); 4306cf07cd1eSRichard Henderson return advance_pc(dc); 4307cf07cd1eSRichard Henderson } 4308cf07cd1eSRichard Henderson 4309dca544b9SRichard Henderson static bool trans_SWAP(DisasContext *dc, arg_r_r_ri_asi *a) 4310dca544b9SRichard Henderson { 4311dca544b9SRichard Henderson TCGv addr, dst, src; 4312dca544b9SRichard Henderson DisasASI da; 4313dca544b9SRichard Henderson 4314dca544b9SRichard Henderson addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 4315dca544b9SRichard Henderson if (addr == NULL) { 4316dca544b9SRichard Henderson return false; 4317dca544b9SRichard Henderson } 4318dca544b9SRichard Henderson da = resolve_asi(dc, a->asi, MO_TEUL); 4319dca544b9SRichard Henderson 4320dca544b9SRichard Henderson dst = gen_dest_gpr(dc, a->rd); 4321dca544b9SRichard Henderson src = gen_load_gpr(dc, a->rd); 4322dca544b9SRichard Henderson gen_swap_asi(dc, &da, dst, src, addr); 4323dca544b9SRichard Henderson gen_store_gpr(dc, a->rd, dst); 4324dca544b9SRichard Henderson return advance_pc(dc); 4325dca544b9SRichard Henderson } 4326dca544b9SRichard Henderson 4327d0a11d25SRichard Henderson static bool do_casa(DisasContext *dc, arg_r_r_ri_asi *a, MemOp mop) 4328d0a11d25SRichard Henderson { 4329d0a11d25SRichard Henderson TCGv addr, o, n, c; 4330d0a11d25SRichard Henderson DisasASI da; 4331d0a11d25SRichard Henderson 4332d0a11d25SRichard Henderson addr = gen_ldst_addr(dc, a->rs1, true, 0); 4333d0a11d25SRichard Henderson if (addr == NULL) { 4334d0a11d25SRichard Henderson return false; 4335d0a11d25SRichard Henderson } 4336d0a11d25SRichard Henderson da = resolve_asi(dc, a->asi, mop); 4337d0a11d25SRichard Henderson 4338d0a11d25SRichard Henderson o = gen_dest_gpr(dc, a->rd); 4339d0a11d25SRichard Henderson n = gen_load_gpr(dc, a->rd); 4340d0a11d25SRichard Henderson c = gen_load_gpr(dc, a->rs2_or_imm); 4341d0a11d25SRichard Henderson gen_cas_asi(dc, &da, o, n, c, addr); 4342d0a11d25SRichard Henderson gen_store_gpr(dc, a->rd, o); 4343d0a11d25SRichard Henderson return advance_pc(dc); 4344d0a11d25SRichard Henderson } 4345d0a11d25SRichard Henderson 4346d0a11d25SRichard Henderson TRANS(CASA, CASA, do_casa, a, MO_TEUL) 4347d0a11d25SRichard Henderson TRANS(CASXA, 64, do_casa, a, MO_TEUQ) 4348d0a11d25SRichard Henderson 434906c060d9SRichard Henderson static bool do_ld_fpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp sz) 435006c060d9SRichard Henderson { 435106c060d9SRichard Henderson TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 435206c060d9SRichard Henderson DisasASI da; 435306c060d9SRichard Henderson 435406c060d9SRichard Henderson if (addr == NULL) { 435506c060d9SRichard Henderson return false; 435606c060d9SRichard Henderson } 435706c060d9SRichard Henderson if (gen_trap_ifnofpu(dc)) { 435806c060d9SRichard Henderson return true; 435906c060d9SRichard Henderson } 436006c060d9SRichard Henderson if (sz == MO_128 && gen_trap_float128(dc)) { 436106c060d9SRichard Henderson return true; 436206c060d9SRichard Henderson } 436306c060d9SRichard Henderson da = resolve_asi(dc, a->asi, MO_TE | sz); 4364287b1152SRichard Henderson gen_ldf_asi(dc, &da, sz, addr, a->rd); 436506c060d9SRichard Henderson gen_update_fprs_dirty(dc, a->rd); 436606c060d9SRichard Henderson return advance_pc(dc); 436706c060d9SRichard Henderson } 436806c060d9SRichard Henderson 436906c060d9SRichard Henderson TRANS(LDF, ALL, do_ld_fpr, a, MO_32) 437006c060d9SRichard Henderson TRANS(LDDF, ALL, do_ld_fpr, a, MO_64) 437106c060d9SRichard Henderson TRANS(LDQF, ALL, do_ld_fpr, a, MO_128) 437206c060d9SRichard Henderson 4373287b1152SRichard Henderson TRANS(LDFA, 64, do_ld_fpr, a, MO_32) 4374287b1152SRichard Henderson TRANS(LDDFA, 64, do_ld_fpr, a, MO_64) 4375287b1152SRichard Henderson TRANS(LDQFA, 64, do_ld_fpr, a, MO_128) 4376287b1152SRichard Henderson 437706c060d9SRichard Henderson static bool do_st_fpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp sz) 437806c060d9SRichard Henderson { 437906c060d9SRichard Henderson TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 438006c060d9SRichard Henderson DisasASI da; 438106c060d9SRichard Henderson 438206c060d9SRichard Henderson if (addr == NULL) { 438306c060d9SRichard Henderson return false; 438406c060d9SRichard Henderson } 438506c060d9SRichard Henderson if (gen_trap_ifnofpu(dc)) { 438606c060d9SRichard Henderson return true; 438706c060d9SRichard Henderson } 438806c060d9SRichard Henderson if (sz == MO_128 && gen_trap_float128(dc)) { 438906c060d9SRichard Henderson return true; 439006c060d9SRichard Henderson } 439106c060d9SRichard Henderson da = resolve_asi(dc, a->asi, MO_TE | sz); 4392287b1152SRichard Henderson gen_stf_asi(dc, &da, sz, addr, a->rd); 439306c060d9SRichard Henderson return advance_pc(dc); 439406c060d9SRichard Henderson } 439506c060d9SRichard Henderson 439606c060d9SRichard Henderson TRANS(STF, ALL, do_st_fpr, a, MO_32) 439706c060d9SRichard Henderson TRANS(STDF, ALL, do_st_fpr, a, MO_64) 439806c060d9SRichard Henderson TRANS(STQF, ALL, do_st_fpr, a, MO_128) 439906c060d9SRichard Henderson 4400287b1152SRichard Henderson TRANS(STFA, 64, do_st_fpr, a, MO_32) 4401287b1152SRichard Henderson TRANS(STDFA, 64, do_st_fpr, a, MO_64) 4402287b1152SRichard Henderson TRANS(STQFA, 64, do_st_fpr, a, MO_128) 4403287b1152SRichard Henderson 440406c060d9SRichard Henderson static bool trans_STDFQ(DisasContext *dc, arg_STDFQ *a) 440506c060d9SRichard Henderson { 440606c060d9SRichard Henderson if (!avail_32(dc)) { 440706c060d9SRichard Henderson return false; 440806c060d9SRichard Henderson } 440906c060d9SRichard Henderson if (!supervisor(dc)) { 441006c060d9SRichard Henderson return raise_priv(dc); 441106c060d9SRichard Henderson } 441206c060d9SRichard Henderson if (gen_trap_ifnofpu(dc)) { 441306c060d9SRichard Henderson return true; 441406c060d9SRichard Henderson } 441506c060d9SRichard Henderson gen_op_fpexception_im(dc, FSR_FTT_SEQ_ERROR); 441606c060d9SRichard Henderson return true; 441706c060d9SRichard Henderson } 441806c060d9SRichard Henderson 4419da681406SRichard Henderson static bool do_ldfsr(DisasContext *dc, arg_r_r_ri *a, MemOp mop, 4420da681406SRichard Henderson target_ulong new_mask, target_ulong old_mask) 44213d3c0673SRichard Henderson { 4422da681406SRichard Henderson TCGv tmp, addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 44233d3c0673SRichard Henderson if (addr == NULL) { 44243d3c0673SRichard Henderson return false; 44253d3c0673SRichard Henderson } 44263d3c0673SRichard Henderson if (gen_trap_ifnofpu(dc)) { 44273d3c0673SRichard Henderson return true; 44283d3c0673SRichard Henderson } 4429da681406SRichard Henderson tmp = tcg_temp_new(); 4430da681406SRichard Henderson tcg_gen_qemu_ld_tl(tmp, addr, dc->mem_idx, mop | MO_ALIGN); 4431da681406SRichard Henderson tcg_gen_andi_tl(tmp, tmp, new_mask); 4432da681406SRichard Henderson tcg_gen_andi_tl(cpu_fsr, cpu_fsr, old_mask); 4433da681406SRichard Henderson tcg_gen_or_tl(cpu_fsr, cpu_fsr, tmp); 4434da681406SRichard Henderson gen_helper_set_fsr(tcg_env, cpu_fsr); 44353d3c0673SRichard Henderson return advance_pc(dc); 44363d3c0673SRichard Henderson } 44373d3c0673SRichard Henderson 4438da681406SRichard Henderson TRANS(LDFSR, ALL, do_ldfsr, a, MO_TEUL, FSR_LDFSR_MASK, FSR_LDFSR_OLDMASK) 4439da681406SRichard Henderson TRANS(LDXFSR, 64, do_ldfsr, a, MO_TEUQ, FSR_LDXFSR_MASK, FSR_LDXFSR_OLDMASK) 44403d3c0673SRichard Henderson 44413d3c0673SRichard Henderson static bool do_stfsr(DisasContext *dc, arg_r_r_ri *a, MemOp mop) 44423d3c0673SRichard Henderson { 44433d3c0673SRichard Henderson TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 44443d3c0673SRichard Henderson if (addr == NULL) { 44453d3c0673SRichard Henderson return false; 44463d3c0673SRichard Henderson } 44473d3c0673SRichard Henderson if (gen_trap_ifnofpu(dc)) { 44483d3c0673SRichard Henderson return true; 44493d3c0673SRichard Henderson } 44503d3c0673SRichard Henderson tcg_gen_qemu_st_tl(cpu_fsr, addr, dc->mem_idx, mop | MO_ALIGN); 44513d3c0673SRichard Henderson return advance_pc(dc); 44523d3c0673SRichard Henderson } 44533d3c0673SRichard Henderson 44543d3c0673SRichard Henderson TRANS(STFSR, ALL, do_stfsr, a, MO_TEUL) 44553d3c0673SRichard Henderson TRANS(STXFSR, 64, do_stfsr, a, MO_TEUQ) 44563d3c0673SRichard Henderson 44573a38260eSRichard Henderson static bool do_fc(DisasContext *dc, int rd, bool c) 44583a38260eSRichard Henderson { 44593a38260eSRichard Henderson uint64_t mask; 44603a38260eSRichard Henderson 44613a38260eSRichard Henderson if (gen_trap_ifnofpu(dc)) { 44623a38260eSRichard Henderson return true; 44633a38260eSRichard Henderson } 44643a38260eSRichard Henderson 44653a38260eSRichard Henderson if (rd & 1) { 44663a38260eSRichard Henderson mask = MAKE_64BIT_MASK(0, 32); 44673a38260eSRichard Henderson } else { 44683a38260eSRichard Henderson mask = MAKE_64BIT_MASK(32, 32); 44693a38260eSRichard Henderson } 44703a38260eSRichard Henderson if (c) { 44713a38260eSRichard Henderson tcg_gen_ori_i64(cpu_fpr[rd / 2], cpu_fpr[rd / 2], mask); 44723a38260eSRichard Henderson } else { 44733a38260eSRichard Henderson tcg_gen_andi_i64(cpu_fpr[rd / 2], cpu_fpr[rd / 2], ~mask); 44743a38260eSRichard Henderson } 44753a38260eSRichard Henderson gen_update_fprs_dirty(dc, rd); 44763a38260eSRichard Henderson return advance_pc(dc); 44773a38260eSRichard Henderson } 44783a38260eSRichard Henderson 44793a38260eSRichard Henderson TRANS(FZEROs, VIS1, do_fc, a->rd, 0) 44803a38260eSRichard Henderson TRANS(FONEs, VIS1, do_fc, a->rd, 1) 44813a38260eSRichard Henderson 44823a38260eSRichard Henderson static bool do_dc(DisasContext *dc, int rd, int64_t c) 44833a38260eSRichard Henderson { 44843a38260eSRichard Henderson if (gen_trap_ifnofpu(dc)) { 44853a38260eSRichard Henderson return true; 44863a38260eSRichard Henderson } 44873a38260eSRichard Henderson 44883a38260eSRichard Henderson tcg_gen_movi_i64(cpu_fpr[rd / 2], c); 44893a38260eSRichard Henderson gen_update_fprs_dirty(dc, rd); 44903a38260eSRichard Henderson return advance_pc(dc); 44913a38260eSRichard Henderson } 44923a38260eSRichard Henderson 44933a38260eSRichard Henderson TRANS(FZEROd, VIS1, do_dc, a->rd, 0) 44943a38260eSRichard Henderson TRANS(FONEd, VIS1, do_dc, a->rd, -1) 44953a38260eSRichard Henderson 4496baf3dbf2SRichard Henderson static bool do_ff(DisasContext *dc, arg_r_r *a, 4497baf3dbf2SRichard Henderson void (*func)(TCGv_i32, TCGv_i32)) 4498baf3dbf2SRichard Henderson { 4499baf3dbf2SRichard Henderson TCGv_i32 tmp; 4500baf3dbf2SRichard Henderson 4501baf3dbf2SRichard Henderson if (gen_trap_ifnofpu(dc)) { 4502baf3dbf2SRichard Henderson return true; 4503baf3dbf2SRichard Henderson } 4504baf3dbf2SRichard Henderson 4505baf3dbf2SRichard Henderson tmp = gen_load_fpr_F(dc, a->rs); 4506baf3dbf2SRichard Henderson func(tmp, tmp); 4507baf3dbf2SRichard Henderson gen_store_fpr_F(dc, a->rd, tmp); 4508baf3dbf2SRichard Henderson return advance_pc(dc); 4509baf3dbf2SRichard Henderson } 4510baf3dbf2SRichard Henderson 4511baf3dbf2SRichard Henderson TRANS(FMOVs, ALL, do_ff, a, gen_op_fmovs) 4512baf3dbf2SRichard Henderson TRANS(FNEGs, ALL, do_ff, a, gen_op_fnegs) 4513baf3dbf2SRichard Henderson TRANS(FABSs, ALL, do_ff, a, gen_op_fabss) 4514baf3dbf2SRichard Henderson TRANS(FSRCs, VIS1, do_ff, a, tcg_gen_mov_i32) 4515baf3dbf2SRichard Henderson TRANS(FNOTs, VIS1, do_ff, a, tcg_gen_not_i32) 4516baf3dbf2SRichard Henderson 45172f722641SRichard Henderson static bool do_fd(DisasContext *dc, arg_r_r *a, 45182f722641SRichard Henderson void (*func)(TCGv_i32, TCGv_i64)) 45192f722641SRichard Henderson { 45202f722641SRichard Henderson TCGv_i32 dst; 45212f722641SRichard Henderson TCGv_i64 src; 45222f722641SRichard Henderson 45232f722641SRichard Henderson if (gen_trap_ifnofpu(dc)) { 45242f722641SRichard Henderson return true; 45252f722641SRichard Henderson } 45262f722641SRichard Henderson 4527388a6465SRichard Henderson dst = tcg_temp_new_i32(); 45282f722641SRichard Henderson src = gen_load_fpr_D(dc, a->rs); 45292f722641SRichard Henderson func(dst, src); 45302f722641SRichard Henderson gen_store_fpr_F(dc, a->rd, dst); 45312f722641SRichard Henderson return advance_pc(dc); 45322f722641SRichard Henderson } 45332f722641SRichard Henderson 45342f722641SRichard Henderson TRANS(FPACK16, VIS1, do_fd, a, gen_op_fpack16) 45352f722641SRichard Henderson TRANS(FPACKFIX, VIS1, do_fd, a, gen_op_fpackfix) 45362f722641SRichard Henderson 4537119cb94fSRichard Henderson static bool do_env_ff(DisasContext *dc, arg_r_r *a, 4538119cb94fSRichard Henderson void (*func)(TCGv_i32, TCGv_env, TCGv_i32)) 4539119cb94fSRichard Henderson { 4540119cb94fSRichard Henderson TCGv_i32 tmp; 4541119cb94fSRichard Henderson 4542119cb94fSRichard Henderson if (gen_trap_ifnofpu(dc)) { 4543119cb94fSRichard Henderson return true; 4544119cb94fSRichard Henderson } 4545119cb94fSRichard Henderson 4546119cb94fSRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 4547119cb94fSRichard Henderson tmp = gen_load_fpr_F(dc, a->rs); 4548119cb94fSRichard Henderson func(tmp, tcg_env, tmp); 4549119cb94fSRichard Henderson gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env); 4550119cb94fSRichard Henderson gen_store_fpr_F(dc, a->rd, tmp); 4551119cb94fSRichard Henderson return advance_pc(dc); 4552119cb94fSRichard Henderson } 4553119cb94fSRichard Henderson 4554119cb94fSRichard Henderson TRANS(FSQRTs, ALL, do_env_ff, a, gen_helper_fsqrts) 4555119cb94fSRichard Henderson TRANS(FiTOs, ALL, do_env_ff, a, gen_helper_fitos) 4556119cb94fSRichard Henderson TRANS(FsTOi, ALL, do_env_ff, a, gen_helper_fstoi) 4557119cb94fSRichard Henderson 45588c94bcd8SRichard Henderson static bool do_env_fd(DisasContext *dc, arg_r_r *a, 45598c94bcd8SRichard Henderson void (*func)(TCGv_i32, TCGv_env, TCGv_i64)) 45608c94bcd8SRichard Henderson { 45618c94bcd8SRichard Henderson TCGv_i32 dst; 45628c94bcd8SRichard Henderson TCGv_i64 src; 45638c94bcd8SRichard Henderson 45648c94bcd8SRichard Henderson if (gen_trap_ifnofpu(dc)) { 45658c94bcd8SRichard Henderson return true; 45668c94bcd8SRichard Henderson } 45678c94bcd8SRichard Henderson 45688c94bcd8SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 4569388a6465SRichard Henderson dst = tcg_temp_new_i32(); 45708c94bcd8SRichard Henderson src = gen_load_fpr_D(dc, a->rs); 45718c94bcd8SRichard Henderson func(dst, tcg_env, src); 45728c94bcd8SRichard Henderson gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env); 45738c94bcd8SRichard Henderson gen_store_fpr_F(dc, a->rd, dst); 45748c94bcd8SRichard Henderson return advance_pc(dc); 45758c94bcd8SRichard Henderson } 45768c94bcd8SRichard Henderson 45778c94bcd8SRichard Henderson TRANS(FdTOs, ALL, do_env_fd, a, gen_helper_fdtos) 45788c94bcd8SRichard Henderson TRANS(FdTOi, ALL, do_env_fd, a, gen_helper_fdtoi) 45798c94bcd8SRichard Henderson TRANS(FxTOs, 64, do_env_fd, a, gen_helper_fxtos) 45808c94bcd8SRichard Henderson 4581c6d83e4fSRichard Henderson static bool do_dd(DisasContext *dc, arg_r_r *a, 4582c6d83e4fSRichard Henderson void (*func)(TCGv_i64, TCGv_i64)) 4583c6d83e4fSRichard Henderson { 4584c6d83e4fSRichard Henderson TCGv_i64 dst, src; 4585c6d83e4fSRichard Henderson 4586c6d83e4fSRichard Henderson if (gen_trap_ifnofpu(dc)) { 4587c6d83e4fSRichard Henderson return true; 4588c6d83e4fSRichard Henderson } 4589c6d83e4fSRichard Henderson 4590c6d83e4fSRichard Henderson dst = gen_dest_fpr_D(dc, a->rd); 4591c6d83e4fSRichard Henderson src = gen_load_fpr_D(dc, a->rs); 4592c6d83e4fSRichard Henderson func(dst, src); 4593c6d83e4fSRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 4594c6d83e4fSRichard Henderson return advance_pc(dc); 4595c6d83e4fSRichard Henderson } 4596c6d83e4fSRichard Henderson 4597c6d83e4fSRichard Henderson TRANS(FMOVd, 64, do_dd, a, gen_op_fmovd) 4598c6d83e4fSRichard Henderson TRANS(FNEGd, 64, do_dd, a, gen_op_fnegd) 4599c6d83e4fSRichard Henderson TRANS(FABSd, 64, do_dd, a, gen_op_fabsd) 4600c6d83e4fSRichard Henderson TRANS(FSRCd, VIS1, do_dd, a, tcg_gen_mov_i64) 4601c6d83e4fSRichard Henderson TRANS(FNOTd, VIS1, do_dd, a, tcg_gen_not_i64) 4602c6d83e4fSRichard Henderson 46038aa418b3SRichard Henderson static bool do_env_dd(DisasContext *dc, arg_r_r *a, 46048aa418b3SRichard Henderson void (*func)(TCGv_i64, TCGv_env, TCGv_i64)) 46058aa418b3SRichard Henderson { 46068aa418b3SRichard Henderson TCGv_i64 dst, src; 46078aa418b3SRichard Henderson 46088aa418b3SRichard Henderson if (gen_trap_ifnofpu(dc)) { 46098aa418b3SRichard Henderson return true; 46108aa418b3SRichard Henderson } 46118aa418b3SRichard Henderson 46128aa418b3SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 46138aa418b3SRichard Henderson dst = gen_dest_fpr_D(dc, a->rd); 46148aa418b3SRichard Henderson src = gen_load_fpr_D(dc, a->rs); 46158aa418b3SRichard Henderson func(dst, tcg_env, src); 46168aa418b3SRichard Henderson gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env); 46178aa418b3SRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 46188aa418b3SRichard Henderson return advance_pc(dc); 46198aa418b3SRichard Henderson } 46208aa418b3SRichard Henderson 46218aa418b3SRichard Henderson TRANS(FSQRTd, ALL, do_env_dd, a, gen_helper_fsqrtd) 46228aa418b3SRichard Henderson TRANS(FxTOd, 64, do_env_dd, a, gen_helper_fxtod) 46238aa418b3SRichard Henderson TRANS(FdTOx, 64, do_env_dd, a, gen_helper_fdtox) 46248aa418b3SRichard Henderson 4625199d43efSRichard Henderson static bool do_env_df(DisasContext *dc, arg_r_r *a, 4626199d43efSRichard Henderson void (*func)(TCGv_i64, TCGv_env, TCGv_i32)) 4627199d43efSRichard Henderson { 4628199d43efSRichard Henderson TCGv_i64 dst; 4629199d43efSRichard Henderson TCGv_i32 src; 4630199d43efSRichard Henderson 4631199d43efSRichard Henderson if (gen_trap_ifnofpu(dc)) { 4632199d43efSRichard Henderson return true; 4633199d43efSRichard Henderson } 4634199d43efSRichard Henderson 4635199d43efSRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 4636199d43efSRichard Henderson dst = gen_dest_fpr_D(dc, a->rd); 4637199d43efSRichard Henderson src = gen_load_fpr_F(dc, a->rs); 4638199d43efSRichard Henderson func(dst, tcg_env, src); 4639199d43efSRichard Henderson gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env); 4640199d43efSRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 4641199d43efSRichard Henderson return advance_pc(dc); 4642199d43efSRichard Henderson } 4643199d43efSRichard Henderson 4644199d43efSRichard Henderson TRANS(FiTOd, ALL, do_env_df, a, gen_helper_fitod) 4645199d43efSRichard Henderson TRANS(FsTOd, ALL, do_env_df, a, gen_helper_fstod) 4646199d43efSRichard Henderson TRANS(FsTOx, 64, do_env_df, a, gen_helper_fstox) 4647199d43efSRichard Henderson 4648daf457d4SRichard Henderson static bool do_qq(DisasContext *dc, arg_r_r *a, 4649daf457d4SRichard Henderson void (*func)(TCGv_i128, TCGv_i128)) 4650f4e18df5SRichard Henderson { 465133ec4245SRichard Henderson TCGv_i128 t; 4652f4e18df5SRichard Henderson 4653f4e18df5SRichard Henderson if (gen_trap_ifnofpu(dc)) { 4654f4e18df5SRichard Henderson return true; 4655f4e18df5SRichard Henderson } 4656f4e18df5SRichard Henderson if (gen_trap_float128(dc)) { 4657f4e18df5SRichard Henderson return true; 4658f4e18df5SRichard Henderson } 4659f4e18df5SRichard Henderson 4660f4e18df5SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 466133ec4245SRichard Henderson t = gen_load_fpr_Q(dc, a->rs); 4662daf457d4SRichard Henderson func(t, t); 466333ec4245SRichard Henderson gen_store_fpr_Q(dc, a->rd, t); 4664f4e18df5SRichard Henderson return advance_pc(dc); 4665f4e18df5SRichard Henderson } 4666f4e18df5SRichard Henderson 4667daf457d4SRichard Henderson TRANS(FMOVq, 64, do_qq, a, tcg_gen_mov_i128) 4668daf457d4SRichard Henderson TRANS(FNEGq, 64, do_qq, a, gen_op_fnegq) 4669daf457d4SRichard Henderson TRANS(FABSq, 64, do_qq, a, gen_op_fabsq) 4670f4e18df5SRichard Henderson 4671c995216bSRichard Henderson static bool do_env_qq(DisasContext *dc, arg_r_r *a, 4672e41716beSRichard Henderson void (*func)(TCGv_i128, TCGv_env, TCGv_i128)) 4673c995216bSRichard Henderson { 4674e41716beSRichard Henderson TCGv_i128 t; 4675e41716beSRichard Henderson 4676c995216bSRichard Henderson if (gen_trap_ifnofpu(dc)) { 4677c995216bSRichard Henderson return true; 4678c995216bSRichard Henderson } 4679c995216bSRichard Henderson if (gen_trap_float128(dc)) { 4680c995216bSRichard Henderson return true; 4681c995216bSRichard Henderson } 4682c995216bSRichard Henderson 4683c995216bSRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 4684e41716beSRichard Henderson 4685e41716beSRichard Henderson t = gen_load_fpr_Q(dc, a->rs); 4686e41716beSRichard Henderson func(t, tcg_env, t); 4687c995216bSRichard Henderson gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env); 4688e41716beSRichard Henderson gen_store_fpr_Q(dc, a->rd, t); 4689c995216bSRichard Henderson return advance_pc(dc); 4690c995216bSRichard Henderson } 4691c995216bSRichard Henderson 4692c995216bSRichard Henderson TRANS(FSQRTq, ALL, do_env_qq, a, gen_helper_fsqrtq) 4693c995216bSRichard Henderson 4694bd9c5c42SRichard Henderson static bool do_env_fq(DisasContext *dc, arg_r_r *a, 4695d81e3efeSRichard Henderson void (*func)(TCGv_i32, TCGv_env, TCGv_i128)) 4696bd9c5c42SRichard Henderson { 4697d81e3efeSRichard Henderson TCGv_i128 src; 4698bd9c5c42SRichard Henderson TCGv_i32 dst; 4699bd9c5c42SRichard Henderson 4700bd9c5c42SRichard Henderson if (gen_trap_ifnofpu(dc)) { 4701bd9c5c42SRichard Henderson return true; 4702bd9c5c42SRichard Henderson } 4703bd9c5c42SRichard Henderson if (gen_trap_float128(dc)) { 4704bd9c5c42SRichard Henderson return true; 4705bd9c5c42SRichard Henderson } 4706bd9c5c42SRichard Henderson 4707bd9c5c42SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 4708d81e3efeSRichard Henderson src = gen_load_fpr_Q(dc, a->rs); 4709388a6465SRichard Henderson dst = tcg_temp_new_i32(); 4710d81e3efeSRichard Henderson func(dst, tcg_env, src); 4711bd9c5c42SRichard Henderson gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env); 4712bd9c5c42SRichard Henderson gen_store_fpr_F(dc, a->rd, dst); 4713bd9c5c42SRichard Henderson return advance_pc(dc); 4714bd9c5c42SRichard Henderson } 4715bd9c5c42SRichard Henderson 4716bd9c5c42SRichard Henderson TRANS(FqTOs, ALL, do_env_fq, a, gen_helper_fqtos) 4717bd9c5c42SRichard Henderson TRANS(FqTOi, ALL, do_env_fq, a, gen_helper_fqtoi) 4718bd9c5c42SRichard Henderson 47191617586fSRichard Henderson static bool do_env_dq(DisasContext *dc, arg_r_r *a, 4720*25a5769eSRichard Henderson void (*func)(TCGv_i64, TCGv_env, TCGv_i128)) 47211617586fSRichard Henderson { 4722*25a5769eSRichard Henderson TCGv_i128 src; 47231617586fSRichard Henderson TCGv_i64 dst; 47241617586fSRichard Henderson 47251617586fSRichard Henderson if (gen_trap_ifnofpu(dc)) { 47261617586fSRichard Henderson return true; 47271617586fSRichard Henderson } 47281617586fSRichard Henderson if (gen_trap_float128(dc)) { 47291617586fSRichard Henderson return true; 47301617586fSRichard Henderson } 47311617586fSRichard Henderson 47321617586fSRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 4733*25a5769eSRichard Henderson src = gen_load_fpr_Q(dc, a->rs); 47341617586fSRichard Henderson dst = gen_dest_fpr_D(dc, a->rd); 4735*25a5769eSRichard Henderson func(dst, tcg_env, src); 47361617586fSRichard Henderson gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env); 47371617586fSRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 47381617586fSRichard Henderson return advance_pc(dc); 47391617586fSRichard Henderson } 47401617586fSRichard Henderson 47411617586fSRichard Henderson TRANS(FqTOd, ALL, do_env_dq, a, gen_helper_fqtod) 47421617586fSRichard Henderson TRANS(FqTOx, 64, do_env_dq, a, gen_helper_fqtox) 47431617586fSRichard Henderson 474413ebcc77SRichard Henderson static bool do_env_qf(DisasContext *dc, arg_r_r *a, 474513ebcc77SRichard Henderson void (*func)(TCGv_env, TCGv_i32)) 474613ebcc77SRichard Henderson { 474713ebcc77SRichard Henderson TCGv_i32 src; 474813ebcc77SRichard Henderson 474913ebcc77SRichard Henderson if (gen_trap_ifnofpu(dc)) { 475013ebcc77SRichard Henderson return true; 475113ebcc77SRichard Henderson } 475213ebcc77SRichard Henderson if (gen_trap_float128(dc)) { 475313ebcc77SRichard Henderson return true; 475413ebcc77SRichard Henderson } 475513ebcc77SRichard Henderson 475613ebcc77SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 475713ebcc77SRichard Henderson src = gen_load_fpr_F(dc, a->rs); 475813ebcc77SRichard Henderson func(tcg_env, src); 475913ebcc77SRichard Henderson gen_op_store_QT0_fpr(QFPREG(a->rd)); 476013ebcc77SRichard Henderson gen_update_fprs_dirty(dc, QFPREG(a->rd)); 476113ebcc77SRichard Henderson return advance_pc(dc); 476213ebcc77SRichard Henderson } 476313ebcc77SRichard Henderson 476413ebcc77SRichard Henderson TRANS(FiTOq, ALL, do_env_qf, a, gen_helper_fitoq) 476513ebcc77SRichard Henderson TRANS(FsTOq, ALL, do_env_qf, a, gen_helper_fstoq) 476613ebcc77SRichard Henderson 47677b8e3e1aSRichard Henderson static bool do_env_qd(DisasContext *dc, arg_r_r *a, 47687b8e3e1aSRichard Henderson void (*func)(TCGv_env, TCGv_i64)) 47697b8e3e1aSRichard Henderson { 47707b8e3e1aSRichard Henderson TCGv_i64 src; 47717b8e3e1aSRichard Henderson 47727b8e3e1aSRichard Henderson if (gen_trap_ifnofpu(dc)) { 47737b8e3e1aSRichard Henderson return true; 47747b8e3e1aSRichard Henderson } 47757b8e3e1aSRichard Henderson if (gen_trap_float128(dc)) { 47767b8e3e1aSRichard Henderson return true; 47777b8e3e1aSRichard Henderson } 47787b8e3e1aSRichard Henderson 47797b8e3e1aSRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 47807b8e3e1aSRichard Henderson src = gen_load_fpr_D(dc, a->rs); 47817b8e3e1aSRichard Henderson func(tcg_env, src); 47827b8e3e1aSRichard Henderson gen_op_store_QT0_fpr(QFPREG(a->rd)); 47837b8e3e1aSRichard Henderson gen_update_fprs_dirty(dc, QFPREG(a->rd)); 47847b8e3e1aSRichard Henderson return advance_pc(dc); 47857b8e3e1aSRichard Henderson } 47867b8e3e1aSRichard Henderson 47877b8e3e1aSRichard Henderson TRANS(FdTOq, ALL, do_env_qd, a, gen_helper_fdtoq) 47887b8e3e1aSRichard Henderson TRANS(FxTOq, 64, do_env_qd, a, gen_helper_fxtoq) 47897b8e3e1aSRichard Henderson 47907f10b52fSRichard Henderson static bool do_fff(DisasContext *dc, arg_r_r_r *a, 47917f10b52fSRichard Henderson void (*func)(TCGv_i32, TCGv_i32, TCGv_i32)) 47927f10b52fSRichard Henderson { 47937f10b52fSRichard Henderson TCGv_i32 src1, src2; 47947f10b52fSRichard Henderson 47957f10b52fSRichard Henderson if (gen_trap_ifnofpu(dc)) { 47967f10b52fSRichard Henderson return true; 47977f10b52fSRichard Henderson } 47987f10b52fSRichard Henderson 47997f10b52fSRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1); 48007f10b52fSRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2); 48017f10b52fSRichard Henderson func(src1, src1, src2); 48027f10b52fSRichard Henderson gen_store_fpr_F(dc, a->rd, src1); 48037f10b52fSRichard Henderson return advance_pc(dc); 48047f10b52fSRichard Henderson } 48057f10b52fSRichard Henderson 48067f10b52fSRichard Henderson TRANS(FPADD16s, VIS1, do_fff, a, tcg_gen_vec_add16_i32) 48077f10b52fSRichard Henderson TRANS(FPADD32s, VIS1, do_fff, a, tcg_gen_add_i32) 48087f10b52fSRichard Henderson TRANS(FPSUB16s, VIS1, do_fff, a, tcg_gen_vec_sub16_i32) 48097f10b52fSRichard Henderson TRANS(FPSUB32s, VIS1, do_fff, a, tcg_gen_sub_i32) 48107f10b52fSRichard Henderson TRANS(FNORs, VIS1, do_fff, a, tcg_gen_nor_i32) 48117f10b52fSRichard Henderson TRANS(FANDNOTs, VIS1, do_fff, a, tcg_gen_andc_i32) 48127f10b52fSRichard Henderson TRANS(FXORs, VIS1, do_fff, a, tcg_gen_xor_i32) 48137f10b52fSRichard Henderson TRANS(FNANDs, VIS1, do_fff, a, tcg_gen_nand_i32) 48147f10b52fSRichard Henderson TRANS(FANDs, VIS1, do_fff, a, tcg_gen_and_i32) 48157f10b52fSRichard Henderson TRANS(FXNORs, VIS1, do_fff, a, tcg_gen_eqv_i32) 48167f10b52fSRichard Henderson TRANS(FORNOTs, VIS1, do_fff, a, tcg_gen_orc_i32) 48177f10b52fSRichard Henderson TRANS(FORs, VIS1, do_fff, a, tcg_gen_or_i32) 48187f10b52fSRichard Henderson 4819c1514961SRichard Henderson static bool do_env_fff(DisasContext *dc, arg_r_r_r *a, 4820c1514961SRichard Henderson void (*func)(TCGv_i32, TCGv_env, TCGv_i32, TCGv_i32)) 4821c1514961SRichard Henderson { 4822c1514961SRichard Henderson TCGv_i32 src1, src2; 4823c1514961SRichard Henderson 4824c1514961SRichard Henderson if (gen_trap_ifnofpu(dc)) { 4825c1514961SRichard Henderson return true; 4826c1514961SRichard Henderson } 4827c1514961SRichard Henderson 4828c1514961SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 4829c1514961SRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1); 4830c1514961SRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2); 4831c1514961SRichard Henderson func(src1, tcg_env, src1, src2); 4832c1514961SRichard Henderson gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env); 4833c1514961SRichard Henderson gen_store_fpr_F(dc, a->rd, src1); 4834c1514961SRichard Henderson return advance_pc(dc); 4835c1514961SRichard Henderson } 4836c1514961SRichard Henderson 4837c1514961SRichard Henderson TRANS(FADDs, ALL, do_env_fff, a, gen_helper_fadds) 4838c1514961SRichard Henderson TRANS(FSUBs, ALL, do_env_fff, a, gen_helper_fsubs) 4839c1514961SRichard Henderson TRANS(FMULs, ALL, do_env_fff, a, gen_helper_fmuls) 4840c1514961SRichard Henderson TRANS(FDIVs, ALL, do_env_fff, a, gen_helper_fdivs) 4841c1514961SRichard Henderson 4842e06c9f83SRichard Henderson static bool do_ddd(DisasContext *dc, arg_r_r_r *a, 4843e06c9f83SRichard Henderson void (*func)(TCGv_i64, TCGv_i64, TCGv_i64)) 4844e06c9f83SRichard Henderson { 4845e06c9f83SRichard Henderson TCGv_i64 dst, src1, src2; 4846e06c9f83SRichard Henderson 4847e06c9f83SRichard Henderson if (gen_trap_ifnofpu(dc)) { 4848e06c9f83SRichard Henderson return true; 4849e06c9f83SRichard Henderson } 4850e06c9f83SRichard Henderson 4851e06c9f83SRichard Henderson dst = gen_dest_fpr_D(dc, a->rd); 4852e06c9f83SRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1); 4853e06c9f83SRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2); 4854e06c9f83SRichard Henderson func(dst, src1, src2); 4855e06c9f83SRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 4856e06c9f83SRichard Henderson return advance_pc(dc); 4857e06c9f83SRichard Henderson } 4858e06c9f83SRichard Henderson 4859e06c9f83SRichard Henderson TRANS(FMUL8x16, VIS1, do_ddd, a, gen_helper_fmul8x16) 4860e06c9f83SRichard Henderson TRANS(FMUL8x16AU, VIS1, do_ddd, a, gen_helper_fmul8x16au) 4861e06c9f83SRichard Henderson TRANS(FMUL8x16AL, VIS1, do_ddd, a, gen_helper_fmul8x16al) 4862e06c9f83SRichard Henderson TRANS(FMUL8SUx16, VIS1, do_ddd, a, gen_helper_fmul8sux16) 4863e06c9f83SRichard Henderson TRANS(FMUL8ULx16, VIS1, do_ddd, a, gen_helper_fmul8ulx16) 4864e06c9f83SRichard Henderson TRANS(FMULD8SUx16, VIS1, do_ddd, a, gen_helper_fmuld8sux16) 4865e06c9f83SRichard Henderson TRANS(FMULD8ULx16, VIS1, do_ddd, a, gen_helper_fmuld8ulx16) 4866e06c9f83SRichard Henderson TRANS(FPMERGE, VIS1, do_ddd, a, gen_helper_fpmerge) 4867e06c9f83SRichard Henderson TRANS(FEXPAND, VIS1, do_ddd, a, gen_helper_fexpand) 4868e06c9f83SRichard Henderson 4869e06c9f83SRichard Henderson TRANS(FPADD16, VIS1, do_ddd, a, tcg_gen_vec_add16_i64) 4870e06c9f83SRichard Henderson TRANS(FPADD32, VIS1, do_ddd, a, tcg_gen_vec_add32_i64) 4871e06c9f83SRichard Henderson TRANS(FPSUB16, VIS1, do_ddd, a, tcg_gen_vec_sub16_i64) 4872e06c9f83SRichard Henderson TRANS(FPSUB32, VIS1, do_ddd, a, tcg_gen_vec_sub32_i64) 4873e06c9f83SRichard Henderson TRANS(FNORd, VIS1, do_ddd, a, tcg_gen_nor_i64) 4874e06c9f83SRichard Henderson TRANS(FANDNOTd, VIS1, do_ddd, a, tcg_gen_andc_i64) 4875e06c9f83SRichard Henderson TRANS(FXORd, VIS1, do_ddd, a, tcg_gen_xor_i64) 4876e06c9f83SRichard Henderson TRANS(FNANDd, VIS1, do_ddd, a, tcg_gen_nand_i64) 4877e06c9f83SRichard Henderson TRANS(FANDd, VIS1, do_ddd, a, tcg_gen_and_i64) 4878e06c9f83SRichard Henderson TRANS(FXNORd, VIS1, do_ddd, a, tcg_gen_eqv_i64) 4879e06c9f83SRichard Henderson TRANS(FORNOTd, VIS1, do_ddd, a, tcg_gen_orc_i64) 4880e06c9f83SRichard Henderson TRANS(FORd, VIS1, do_ddd, a, tcg_gen_or_i64) 4881e06c9f83SRichard Henderson 48824b6edc0aSRichard Henderson TRANS(FPACK32, VIS1, do_ddd, a, gen_op_fpack32) 48834b6edc0aSRichard Henderson TRANS(FALIGNDATAg, VIS1, do_ddd, a, gen_op_faligndata) 48844b6edc0aSRichard Henderson TRANS(BSHUFFLE, VIS2, do_ddd, a, gen_op_bshuffle) 48854b6edc0aSRichard Henderson 4886e2fa6bd1SRichard Henderson static bool do_rdd(DisasContext *dc, arg_r_r_r *a, 4887e2fa6bd1SRichard Henderson void (*func)(TCGv, TCGv_i64, TCGv_i64)) 4888e2fa6bd1SRichard Henderson { 4889e2fa6bd1SRichard Henderson TCGv_i64 src1, src2; 4890e2fa6bd1SRichard Henderson TCGv dst; 4891e2fa6bd1SRichard Henderson 4892e2fa6bd1SRichard Henderson if (gen_trap_ifnofpu(dc)) { 4893e2fa6bd1SRichard Henderson return true; 4894e2fa6bd1SRichard Henderson } 4895e2fa6bd1SRichard Henderson 4896e2fa6bd1SRichard Henderson dst = gen_dest_gpr(dc, a->rd); 4897e2fa6bd1SRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1); 4898e2fa6bd1SRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2); 4899e2fa6bd1SRichard Henderson func(dst, src1, src2); 4900e2fa6bd1SRichard Henderson gen_store_gpr(dc, a->rd, dst); 4901e2fa6bd1SRichard Henderson return advance_pc(dc); 4902e2fa6bd1SRichard Henderson } 4903e2fa6bd1SRichard Henderson 4904e2fa6bd1SRichard Henderson TRANS(FPCMPLE16, VIS1, do_rdd, a, gen_helper_fcmple16) 4905e2fa6bd1SRichard Henderson TRANS(FPCMPNE16, VIS1, do_rdd, a, gen_helper_fcmpne16) 4906e2fa6bd1SRichard Henderson TRANS(FPCMPGT16, VIS1, do_rdd, a, gen_helper_fcmpgt16) 4907e2fa6bd1SRichard Henderson TRANS(FPCMPEQ16, VIS1, do_rdd, a, gen_helper_fcmpeq16) 4908e2fa6bd1SRichard Henderson 4909e2fa6bd1SRichard Henderson TRANS(FPCMPLE32, VIS1, do_rdd, a, gen_helper_fcmple32) 4910e2fa6bd1SRichard Henderson TRANS(FPCMPNE32, VIS1, do_rdd, a, gen_helper_fcmpne32) 4911e2fa6bd1SRichard Henderson TRANS(FPCMPGT32, VIS1, do_rdd, a, gen_helper_fcmpgt32) 4912e2fa6bd1SRichard Henderson TRANS(FPCMPEQ32, VIS1, do_rdd, a, gen_helper_fcmpeq32) 4913e2fa6bd1SRichard Henderson 4914f2a59b0aSRichard Henderson static bool do_env_ddd(DisasContext *dc, arg_r_r_r *a, 4915f2a59b0aSRichard Henderson void (*func)(TCGv_i64, TCGv_env, TCGv_i64, TCGv_i64)) 4916f2a59b0aSRichard Henderson { 4917f2a59b0aSRichard Henderson TCGv_i64 dst, src1, src2; 4918f2a59b0aSRichard Henderson 4919f2a59b0aSRichard Henderson if (gen_trap_ifnofpu(dc)) { 4920f2a59b0aSRichard Henderson return true; 4921f2a59b0aSRichard Henderson } 4922f2a59b0aSRichard Henderson 4923f2a59b0aSRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 4924f2a59b0aSRichard Henderson dst = gen_dest_fpr_D(dc, a->rd); 4925f2a59b0aSRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1); 4926f2a59b0aSRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2); 4927f2a59b0aSRichard Henderson func(dst, tcg_env, src1, src2); 4928f2a59b0aSRichard Henderson gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env); 4929f2a59b0aSRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 4930f2a59b0aSRichard Henderson return advance_pc(dc); 4931f2a59b0aSRichard Henderson } 4932f2a59b0aSRichard Henderson 4933f2a59b0aSRichard Henderson TRANS(FADDd, ALL, do_env_ddd, a, gen_helper_faddd) 4934f2a59b0aSRichard Henderson TRANS(FSUBd, ALL, do_env_ddd, a, gen_helper_fsubd) 4935f2a59b0aSRichard Henderson TRANS(FMULd, ALL, do_env_ddd, a, gen_helper_fmuld) 4936f2a59b0aSRichard Henderson TRANS(FDIVd, ALL, do_env_ddd, a, gen_helper_fdivd) 4937f2a59b0aSRichard Henderson 4938ff4c711bSRichard Henderson static bool trans_FsMULd(DisasContext *dc, arg_r_r_r *a) 4939ff4c711bSRichard Henderson { 4940ff4c711bSRichard Henderson TCGv_i64 dst; 4941ff4c711bSRichard Henderson TCGv_i32 src1, src2; 4942ff4c711bSRichard Henderson 4943ff4c711bSRichard Henderson if (gen_trap_ifnofpu(dc)) { 4944ff4c711bSRichard Henderson return true; 4945ff4c711bSRichard Henderson } 4946ff4c711bSRichard Henderson if (!(dc->def->features & CPU_FEATURE_FSMULD)) { 4947ff4c711bSRichard Henderson return raise_unimpfpop(dc); 4948ff4c711bSRichard Henderson } 4949ff4c711bSRichard Henderson 4950ff4c711bSRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 4951ff4c711bSRichard Henderson dst = gen_dest_fpr_D(dc, a->rd); 4952ff4c711bSRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1); 4953ff4c711bSRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2); 4954ff4c711bSRichard Henderson gen_helper_fsmuld(dst, tcg_env, src1, src2); 4955ff4c711bSRichard Henderson gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env); 4956ff4c711bSRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 4957ff4c711bSRichard Henderson return advance_pc(dc); 4958ff4c711bSRichard Henderson } 4959ff4c711bSRichard Henderson 4960afb04344SRichard Henderson static bool do_dddd(DisasContext *dc, arg_r_r_r *a, 4961afb04344SRichard Henderson void (*func)(TCGv_i64, TCGv_i64, TCGv_i64, TCGv_i64)) 4962afb04344SRichard Henderson { 4963afb04344SRichard Henderson TCGv_i64 dst, src0, src1, src2; 4964afb04344SRichard Henderson 4965afb04344SRichard Henderson if (gen_trap_ifnofpu(dc)) { 4966afb04344SRichard Henderson return true; 4967afb04344SRichard Henderson } 4968afb04344SRichard Henderson 4969afb04344SRichard Henderson dst = gen_dest_fpr_D(dc, a->rd); 4970afb04344SRichard Henderson src0 = gen_load_fpr_D(dc, a->rd); 4971afb04344SRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1); 4972afb04344SRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2); 4973afb04344SRichard Henderson func(dst, src0, src1, src2); 4974afb04344SRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 4975afb04344SRichard Henderson return advance_pc(dc); 4976afb04344SRichard Henderson } 4977afb04344SRichard Henderson 4978afb04344SRichard Henderson TRANS(PDIST, VIS1, do_dddd, a, gen_helper_pdist) 4979afb04344SRichard Henderson 4980a4056239SRichard Henderson static bool do_env_qqq(DisasContext *dc, arg_r_r_r *a, 498116bedf89SRichard Henderson void (*func)(TCGv_i128, TCGv_env, TCGv_i128, TCGv_i128)) 4982a4056239SRichard Henderson { 498316bedf89SRichard Henderson TCGv_i128 src1, src2; 498416bedf89SRichard Henderson 4985a4056239SRichard Henderson if (gen_trap_ifnofpu(dc)) { 4986a4056239SRichard Henderson return true; 4987a4056239SRichard Henderson } 4988a4056239SRichard Henderson if (gen_trap_float128(dc)) { 4989a4056239SRichard Henderson return true; 4990a4056239SRichard Henderson } 4991a4056239SRichard Henderson 4992a4056239SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 499316bedf89SRichard Henderson src1 = gen_load_fpr_Q(dc, a->rs1); 499416bedf89SRichard Henderson src2 = gen_load_fpr_Q(dc, a->rs2); 499516bedf89SRichard Henderson func(src1, tcg_env, src1, src2); 4996a4056239SRichard Henderson gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env); 499716bedf89SRichard Henderson gen_store_fpr_Q(dc, a->rd, src1); 4998a4056239SRichard Henderson return advance_pc(dc); 4999a4056239SRichard Henderson } 5000a4056239SRichard Henderson 5001a4056239SRichard Henderson TRANS(FADDq, ALL, do_env_qqq, a, gen_helper_faddq) 5002a4056239SRichard Henderson TRANS(FSUBq, ALL, do_env_qqq, a, gen_helper_fsubq) 5003a4056239SRichard Henderson TRANS(FMULq, ALL, do_env_qqq, a, gen_helper_fmulq) 5004a4056239SRichard Henderson TRANS(FDIVq, ALL, do_env_qqq, a, gen_helper_fdivq) 5005a4056239SRichard Henderson 50065e3b17bbSRichard Henderson static bool trans_FdMULq(DisasContext *dc, arg_r_r_r *a) 50075e3b17bbSRichard Henderson { 50085e3b17bbSRichard Henderson TCGv_i64 src1, src2; 50095e3b17bbSRichard Henderson 50105e3b17bbSRichard Henderson if (gen_trap_ifnofpu(dc)) { 50115e3b17bbSRichard Henderson return true; 50125e3b17bbSRichard Henderson } 50135e3b17bbSRichard Henderson if (gen_trap_float128(dc)) { 50145e3b17bbSRichard Henderson return true; 50155e3b17bbSRichard Henderson } 50165e3b17bbSRichard Henderson 50175e3b17bbSRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 50185e3b17bbSRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1); 50195e3b17bbSRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2); 50205e3b17bbSRichard Henderson gen_helper_fdmulq(tcg_env, src1, src2); 50215e3b17bbSRichard Henderson gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env); 50225e3b17bbSRichard Henderson gen_op_store_QT0_fpr(QFPREG(a->rd)); 50235e3b17bbSRichard Henderson gen_update_fprs_dirty(dc, QFPREG(a->rd)); 50245e3b17bbSRichard Henderson return advance_pc(dc); 50255e3b17bbSRichard Henderson } 50265e3b17bbSRichard Henderson 5027f7ec8155SRichard Henderson static bool do_fmovr(DisasContext *dc, arg_FMOVRs *a, bool is_128, 5028f7ec8155SRichard Henderson void (*func)(DisasContext *, DisasCompare *, int, int)) 5029f7ec8155SRichard Henderson { 5030f7ec8155SRichard Henderson DisasCompare cmp; 5031f7ec8155SRichard Henderson 50322c4f56c9SRichard Henderson if (!gen_compare_reg(&cmp, a->cond, gen_load_gpr(dc, a->rs1))) { 50332c4f56c9SRichard Henderson return false; 50342c4f56c9SRichard Henderson } 5035f7ec8155SRichard Henderson if (gen_trap_ifnofpu(dc)) { 5036f7ec8155SRichard Henderson return true; 5037f7ec8155SRichard Henderson } 5038f7ec8155SRichard Henderson if (is_128 && gen_trap_float128(dc)) { 5039f7ec8155SRichard Henderson return true; 5040f7ec8155SRichard Henderson } 5041f7ec8155SRichard Henderson 5042f7ec8155SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 5043f7ec8155SRichard Henderson func(dc, &cmp, a->rd, a->rs2); 5044f7ec8155SRichard Henderson return advance_pc(dc); 5045f7ec8155SRichard Henderson } 5046f7ec8155SRichard Henderson 5047f7ec8155SRichard Henderson TRANS(FMOVRs, 64, do_fmovr, a, false, gen_fmovs) 5048f7ec8155SRichard Henderson TRANS(FMOVRd, 64, do_fmovr, a, false, gen_fmovd) 5049f7ec8155SRichard Henderson TRANS(FMOVRq, 64, do_fmovr, a, true, gen_fmovq) 5050f7ec8155SRichard Henderson 5051f7ec8155SRichard Henderson static bool do_fmovcc(DisasContext *dc, arg_FMOVscc *a, bool is_128, 5052f7ec8155SRichard Henderson void (*func)(DisasContext *, DisasCompare *, int, int)) 5053f7ec8155SRichard Henderson { 5054f7ec8155SRichard Henderson DisasCompare cmp; 5055f7ec8155SRichard Henderson 5056f7ec8155SRichard Henderson if (gen_trap_ifnofpu(dc)) { 5057f7ec8155SRichard Henderson return true; 5058f7ec8155SRichard Henderson } 5059f7ec8155SRichard Henderson if (is_128 && gen_trap_float128(dc)) { 5060f7ec8155SRichard Henderson return true; 5061f7ec8155SRichard Henderson } 5062f7ec8155SRichard Henderson 5063f7ec8155SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 5064f7ec8155SRichard Henderson gen_compare(&cmp, a->cc, a->cond, dc); 5065f7ec8155SRichard Henderson func(dc, &cmp, a->rd, a->rs2); 5066f7ec8155SRichard Henderson return advance_pc(dc); 5067f7ec8155SRichard Henderson } 5068f7ec8155SRichard Henderson 5069f7ec8155SRichard Henderson TRANS(FMOVscc, 64, do_fmovcc, a, false, gen_fmovs) 5070f7ec8155SRichard Henderson TRANS(FMOVdcc, 64, do_fmovcc, a, false, gen_fmovd) 5071f7ec8155SRichard Henderson TRANS(FMOVqcc, 64, do_fmovcc, a, true, gen_fmovq) 5072f7ec8155SRichard Henderson 5073f7ec8155SRichard Henderson static bool do_fmovfcc(DisasContext *dc, arg_FMOVsfcc *a, bool is_128, 5074f7ec8155SRichard Henderson void (*func)(DisasContext *, DisasCompare *, int, int)) 5075f7ec8155SRichard Henderson { 5076f7ec8155SRichard Henderson DisasCompare cmp; 5077f7ec8155SRichard Henderson 5078f7ec8155SRichard Henderson if (gen_trap_ifnofpu(dc)) { 5079f7ec8155SRichard Henderson return true; 5080f7ec8155SRichard Henderson } 5081f7ec8155SRichard Henderson if (is_128 && gen_trap_float128(dc)) { 5082f7ec8155SRichard Henderson return true; 5083f7ec8155SRichard Henderson } 5084f7ec8155SRichard Henderson 5085f7ec8155SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 5086f7ec8155SRichard Henderson gen_fcompare(&cmp, a->cc, a->cond); 5087f7ec8155SRichard Henderson func(dc, &cmp, a->rd, a->rs2); 5088f7ec8155SRichard Henderson return advance_pc(dc); 5089f7ec8155SRichard Henderson } 5090f7ec8155SRichard Henderson 5091f7ec8155SRichard Henderson TRANS(FMOVsfcc, 64, do_fmovfcc, a, false, gen_fmovs) 5092f7ec8155SRichard Henderson TRANS(FMOVdfcc, 64, do_fmovfcc, a, false, gen_fmovd) 5093f7ec8155SRichard Henderson TRANS(FMOVqfcc, 64, do_fmovfcc, a, true, gen_fmovq) 5094f7ec8155SRichard Henderson 509540f9ad21SRichard Henderson static bool do_fcmps(DisasContext *dc, arg_FCMPs *a, bool e) 509640f9ad21SRichard Henderson { 509740f9ad21SRichard Henderson TCGv_i32 src1, src2; 509840f9ad21SRichard Henderson 509940f9ad21SRichard Henderson if (avail_32(dc) && a->cc != 0) { 510040f9ad21SRichard Henderson return false; 510140f9ad21SRichard Henderson } 510240f9ad21SRichard Henderson if (gen_trap_ifnofpu(dc)) { 510340f9ad21SRichard Henderson return true; 510440f9ad21SRichard Henderson } 510540f9ad21SRichard Henderson 510640f9ad21SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 510740f9ad21SRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1); 510840f9ad21SRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2); 510940f9ad21SRichard Henderson if (e) { 511040f9ad21SRichard Henderson gen_op_fcmpes(a->cc, src1, src2); 511140f9ad21SRichard Henderson } else { 511240f9ad21SRichard Henderson gen_op_fcmps(a->cc, src1, src2); 511340f9ad21SRichard Henderson } 511440f9ad21SRichard Henderson return advance_pc(dc); 511540f9ad21SRichard Henderson } 511640f9ad21SRichard Henderson 511740f9ad21SRichard Henderson TRANS(FCMPs, ALL, do_fcmps, a, false) 511840f9ad21SRichard Henderson TRANS(FCMPEs, ALL, do_fcmps, a, true) 511940f9ad21SRichard Henderson 512040f9ad21SRichard Henderson static bool do_fcmpd(DisasContext *dc, arg_FCMPd *a, bool e) 512140f9ad21SRichard Henderson { 512240f9ad21SRichard Henderson TCGv_i64 src1, src2; 512340f9ad21SRichard Henderson 512440f9ad21SRichard Henderson if (avail_32(dc) && a->cc != 0) { 512540f9ad21SRichard Henderson return false; 512640f9ad21SRichard Henderson } 512740f9ad21SRichard Henderson if (gen_trap_ifnofpu(dc)) { 512840f9ad21SRichard Henderson return true; 512940f9ad21SRichard Henderson } 513040f9ad21SRichard Henderson 513140f9ad21SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 513240f9ad21SRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1); 513340f9ad21SRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2); 513440f9ad21SRichard Henderson if (e) { 513540f9ad21SRichard Henderson gen_op_fcmped(a->cc, src1, src2); 513640f9ad21SRichard Henderson } else { 513740f9ad21SRichard Henderson gen_op_fcmpd(a->cc, src1, src2); 513840f9ad21SRichard Henderson } 513940f9ad21SRichard Henderson return advance_pc(dc); 514040f9ad21SRichard Henderson } 514140f9ad21SRichard Henderson 514240f9ad21SRichard Henderson TRANS(FCMPd, ALL, do_fcmpd, a, false) 514340f9ad21SRichard Henderson TRANS(FCMPEd, ALL, do_fcmpd, a, true) 514440f9ad21SRichard Henderson 514540f9ad21SRichard Henderson static bool do_fcmpq(DisasContext *dc, arg_FCMPq *a, bool e) 514640f9ad21SRichard Henderson { 514740f9ad21SRichard Henderson if (avail_32(dc) && a->cc != 0) { 514840f9ad21SRichard Henderson return false; 514940f9ad21SRichard Henderson } 515040f9ad21SRichard Henderson if (gen_trap_ifnofpu(dc)) { 515140f9ad21SRichard Henderson return true; 515240f9ad21SRichard Henderson } 515340f9ad21SRichard Henderson if (gen_trap_float128(dc)) { 515440f9ad21SRichard Henderson return true; 515540f9ad21SRichard Henderson } 515640f9ad21SRichard Henderson 515740f9ad21SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 515840f9ad21SRichard Henderson gen_op_load_fpr_QT0(QFPREG(a->rs1)); 515940f9ad21SRichard Henderson gen_op_load_fpr_QT1(QFPREG(a->rs2)); 516040f9ad21SRichard Henderson if (e) { 516140f9ad21SRichard Henderson gen_op_fcmpeq(a->cc); 516240f9ad21SRichard Henderson } else { 516340f9ad21SRichard Henderson gen_op_fcmpq(a->cc); 516440f9ad21SRichard Henderson } 516540f9ad21SRichard Henderson return advance_pc(dc); 516640f9ad21SRichard Henderson } 516740f9ad21SRichard Henderson 516840f9ad21SRichard Henderson TRANS(FCMPq, ALL, do_fcmpq, a, false) 516940f9ad21SRichard Henderson TRANS(FCMPEq, ALL, do_fcmpq, a, true) 517040f9ad21SRichard Henderson 51716e61bc94SEmilio G. Cota static void sparc_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) 5172fcf5ef2aSThomas Huth { 51736e61bc94SEmilio G. Cota DisasContext *dc = container_of(dcbase, DisasContext, base); 5174b77af26eSRichard Henderson CPUSPARCState *env = cpu_env(cs); 51756e61bc94SEmilio G. Cota int bound; 5176af00be49SEmilio G. Cota 5177af00be49SEmilio G. Cota dc->pc = dc->base.pc_first; 51786e61bc94SEmilio G. Cota dc->npc = (target_ulong)dc->base.tb->cs_base; 51796e61bc94SEmilio G. Cota dc->mem_idx = dc->base.tb->flags & TB_FLAG_MMU_MASK; 5180576e1c4cSIgor Mammedov dc->def = &env->def; 51816e61bc94SEmilio G. Cota dc->fpu_enabled = tb_fpu_enabled(dc->base.tb->flags); 51826e61bc94SEmilio G. Cota dc->address_mask_32bit = tb_am_enabled(dc->base.tb->flags); 5183c9b459aaSArtyom Tarasenko #ifndef CONFIG_USER_ONLY 51846e61bc94SEmilio G. Cota dc->supervisor = (dc->base.tb->flags & TB_FLAG_SUPER) != 0; 5185c9b459aaSArtyom Tarasenko #endif 5186fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64 5187fcf5ef2aSThomas Huth dc->fprs_dirty = 0; 51886e61bc94SEmilio G. Cota dc->asi = (dc->base.tb->flags >> TB_FLAG_ASI_SHIFT) & 0xff; 5189c9b459aaSArtyom Tarasenko #ifndef CONFIG_USER_ONLY 51906e61bc94SEmilio G. Cota dc->hypervisor = (dc->base.tb->flags & TB_FLAG_HYPER) != 0; 5191c9b459aaSArtyom Tarasenko #endif 5192fcf5ef2aSThomas Huth #endif 51936e61bc94SEmilio G. Cota /* 51946e61bc94SEmilio G. Cota * if we reach a page boundary, we stop generation so that the 51956e61bc94SEmilio G. Cota * PC of a TT_TFAULT exception is always in the right page 51966e61bc94SEmilio G. Cota */ 51976e61bc94SEmilio G. Cota bound = -(dc->base.pc_first | TARGET_PAGE_MASK) / 4; 51986e61bc94SEmilio G. Cota dc->base.max_insns = MIN(dc->base.max_insns, bound); 5199af00be49SEmilio G. Cota } 5200fcf5ef2aSThomas Huth 52016e61bc94SEmilio G. Cota static void sparc_tr_tb_start(DisasContextBase *db, CPUState *cs) 52026e61bc94SEmilio G. Cota { 52036e61bc94SEmilio G. Cota } 52046e61bc94SEmilio G. Cota 52056e61bc94SEmilio G. Cota static void sparc_tr_insn_start(DisasContextBase *dcbase, CPUState *cs) 52066e61bc94SEmilio G. Cota { 52076e61bc94SEmilio G. Cota DisasContext *dc = container_of(dcbase, DisasContext, base); 5208633c4283SRichard Henderson target_ulong npc = dc->npc; 52096e61bc94SEmilio G. Cota 5210633c4283SRichard Henderson if (npc & 3) { 5211633c4283SRichard Henderson switch (npc) { 5212633c4283SRichard Henderson case JUMP_PC: 5213fcf5ef2aSThomas Huth assert(dc->jump_pc[1] == dc->pc + 4); 5214633c4283SRichard Henderson npc = dc->jump_pc[0] | JUMP_PC; 5215633c4283SRichard Henderson break; 5216633c4283SRichard Henderson case DYNAMIC_PC: 5217633c4283SRichard Henderson case DYNAMIC_PC_LOOKUP: 5218633c4283SRichard Henderson npc = DYNAMIC_PC; 5219633c4283SRichard Henderson break; 5220633c4283SRichard Henderson default: 5221633c4283SRichard Henderson g_assert_not_reached(); 5222fcf5ef2aSThomas Huth } 52236e61bc94SEmilio G. Cota } 5224633c4283SRichard Henderson tcg_gen_insn_start(dc->pc, npc); 5225633c4283SRichard Henderson } 5226fcf5ef2aSThomas Huth 52276e61bc94SEmilio G. Cota static void sparc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) 52286e61bc94SEmilio G. Cota { 52296e61bc94SEmilio G. Cota DisasContext *dc = container_of(dcbase, DisasContext, base); 5230b77af26eSRichard Henderson CPUSPARCState *env = cpu_env(cs); 52316e61bc94SEmilio G. Cota unsigned int insn; 5232fcf5ef2aSThomas Huth 52334e116893SIlya Leoshkevich insn = translator_ldl(env, &dc->base, dc->pc); 5234af00be49SEmilio G. Cota dc->base.pc_next += 4; 5235878cc677SRichard Henderson 5236878cc677SRichard Henderson if (!decode(dc, insn)) { 5237ba9c09b4SRichard Henderson gen_exception(dc, TT_ILL_INSN); 5238878cc677SRichard Henderson } 5239fcf5ef2aSThomas Huth 5240af00be49SEmilio G. Cota if (dc->base.is_jmp == DISAS_NORETURN) { 52416e61bc94SEmilio G. Cota return; 5242c5e6ccdfSEmilio G. Cota } 5243af00be49SEmilio G. Cota if (dc->pc != dc->base.pc_next) { 52446e61bc94SEmilio G. Cota dc->base.is_jmp = DISAS_TOO_MANY; 5245af00be49SEmilio G. Cota } 52466e61bc94SEmilio G. Cota } 5247fcf5ef2aSThomas Huth 52486e61bc94SEmilio G. Cota static void sparc_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs) 52496e61bc94SEmilio G. Cota { 52506e61bc94SEmilio G. Cota DisasContext *dc = container_of(dcbase, DisasContext, base); 5251186e7890SRichard Henderson DisasDelayException *e, *e_next; 5252633c4283SRichard Henderson bool may_lookup; 52536e61bc94SEmilio G. Cota 525489527e3aSRichard Henderson finishing_insn(dc); 525589527e3aSRichard Henderson 525646bb0137SMark Cave-Ayland switch (dc->base.is_jmp) { 525746bb0137SMark Cave-Ayland case DISAS_NEXT: 525846bb0137SMark Cave-Ayland case DISAS_TOO_MANY: 5259633c4283SRichard Henderson if (((dc->pc | dc->npc) & 3) == 0) { 5260fcf5ef2aSThomas Huth /* static PC and NPC: we can use direct chaining */ 5261fcf5ef2aSThomas Huth gen_goto_tb(dc, 0, dc->pc, dc->npc); 5262633c4283SRichard Henderson break; 5263fcf5ef2aSThomas Huth } 5264633c4283SRichard Henderson 5265930f1865SRichard Henderson may_lookup = true; 5266633c4283SRichard Henderson if (dc->pc & 3) { 5267633c4283SRichard Henderson switch (dc->pc) { 5268633c4283SRichard Henderson case DYNAMIC_PC_LOOKUP: 5269633c4283SRichard Henderson break; 5270633c4283SRichard Henderson case DYNAMIC_PC: 5271633c4283SRichard Henderson may_lookup = false; 5272633c4283SRichard Henderson break; 5273633c4283SRichard Henderson default: 5274633c4283SRichard Henderson g_assert_not_reached(); 5275633c4283SRichard Henderson } 5276633c4283SRichard Henderson } else { 5277633c4283SRichard Henderson tcg_gen_movi_tl(cpu_pc, dc->pc); 5278633c4283SRichard Henderson } 5279633c4283SRichard Henderson 5280930f1865SRichard Henderson if (dc->npc & 3) { 5281930f1865SRichard Henderson switch (dc->npc) { 5282930f1865SRichard Henderson case JUMP_PC: 5283930f1865SRichard Henderson gen_generic_branch(dc); 5284930f1865SRichard Henderson break; 5285930f1865SRichard Henderson case DYNAMIC_PC: 5286930f1865SRichard Henderson may_lookup = false; 5287930f1865SRichard Henderson break; 5288930f1865SRichard Henderson case DYNAMIC_PC_LOOKUP: 5289930f1865SRichard Henderson break; 5290930f1865SRichard Henderson default: 5291930f1865SRichard Henderson g_assert_not_reached(); 5292930f1865SRichard Henderson } 5293930f1865SRichard Henderson } else { 5294930f1865SRichard Henderson tcg_gen_movi_tl(cpu_npc, dc->npc); 5295930f1865SRichard Henderson } 5296633c4283SRichard Henderson if (may_lookup) { 5297633c4283SRichard Henderson tcg_gen_lookup_and_goto_ptr(); 5298633c4283SRichard Henderson } else { 529907ea28b4SRichard Henderson tcg_gen_exit_tb(NULL, 0); 5300fcf5ef2aSThomas Huth } 530146bb0137SMark Cave-Ayland break; 530246bb0137SMark Cave-Ayland 530346bb0137SMark Cave-Ayland case DISAS_NORETURN: 530446bb0137SMark Cave-Ayland break; 530546bb0137SMark Cave-Ayland 530646bb0137SMark Cave-Ayland case DISAS_EXIT: 530746bb0137SMark Cave-Ayland /* Exit TB */ 530846bb0137SMark Cave-Ayland save_state(dc); 530946bb0137SMark Cave-Ayland tcg_gen_exit_tb(NULL, 0); 531046bb0137SMark Cave-Ayland break; 531146bb0137SMark Cave-Ayland 531246bb0137SMark Cave-Ayland default: 531346bb0137SMark Cave-Ayland g_assert_not_reached(); 5314fcf5ef2aSThomas Huth } 5315186e7890SRichard Henderson 5316186e7890SRichard Henderson for (e = dc->delay_excp_list; e ; e = e_next) { 5317186e7890SRichard Henderson gen_set_label(e->lab); 5318186e7890SRichard Henderson 5319186e7890SRichard Henderson tcg_gen_movi_tl(cpu_pc, e->pc); 5320186e7890SRichard Henderson if (e->npc % 4 == 0) { 5321186e7890SRichard Henderson tcg_gen_movi_tl(cpu_npc, e->npc); 5322186e7890SRichard Henderson } 5323186e7890SRichard Henderson gen_helper_raise_exception(tcg_env, e->excp); 5324186e7890SRichard Henderson 5325186e7890SRichard Henderson e_next = e->next; 5326186e7890SRichard Henderson g_free(e); 5327186e7890SRichard Henderson } 5328fcf5ef2aSThomas Huth } 53296e61bc94SEmilio G. Cota 53308eb806a7SRichard Henderson static void sparc_tr_disas_log(const DisasContextBase *dcbase, 53318eb806a7SRichard Henderson CPUState *cpu, FILE *logfile) 53326e61bc94SEmilio G. Cota { 53338eb806a7SRichard Henderson fprintf(logfile, "IN: %s\n", lookup_symbol(dcbase->pc_first)); 53348eb806a7SRichard Henderson target_disas(logfile, cpu, dcbase->pc_first, dcbase->tb->size); 53356e61bc94SEmilio G. Cota } 53366e61bc94SEmilio G. Cota 53376e61bc94SEmilio G. Cota static const TranslatorOps sparc_tr_ops = { 53386e61bc94SEmilio G. Cota .init_disas_context = sparc_tr_init_disas_context, 53396e61bc94SEmilio G. Cota .tb_start = sparc_tr_tb_start, 53406e61bc94SEmilio G. Cota .insn_start = sparc_tr_insn_start, 53416e61bc94SEmilio G. Cota .translate_insn = sparc_tr_translate_insn, 53426e61bc94SEmilio G. Cota .tb_stop = sparc_tr_tb_stop, 53436e61bc94SEmilio G. Cota .disas_log = sparc_tr_disas_log, 53446e61bc94SEmilio G. Cota }; 53456e61bc94SEmilio G. Cota 5346597f9b2dSRichard Henderson void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int *max_insns, 534732f0c394SAnton Johansson vaddr pc, void *host_pc) 53486e61bc94SEmilio G. Cota { 53496e61bc94SEmilio G. Cota DisasContext dc = {}; 53506e61bc94SEmilio G. Cota 5351306c8721SRichard Henderson translator_loop(cs, tb, max_insns, pc, host_pc, &sparc_tr_ops, &dc.base); 5352fcf5ef2aSThomas Huth } 5353fcf5ef2aSThomas Huth 535455c3ceefSRichard Henderson void sparc_tcg_init(void) 5355fcf5ef2aSThomas Huth { 5356fcf5ef2aSThomas Huth static const char gregnames[32][4] = { 5357fcf5ef2aSThomas Huth "g0", "g1", "g2", "g3", "g4", "g5", "g6", "g7", 5358fcf5ef2aSThomas Huth "o0", "o1", "o2", "o3", "o4", "o5", "o6", "o7", 5359fcf5ef2aSThomas Huth "l0", "l1", "l2", "l3", "l4", "l5", "l6", "l7", 5360fcf5ef2aSThomas Huth "i0", "i1", "i2", "i3", "i4", "i5", "i6", "i7", 5361fcf5ef2aSThomas Huth }; 5362fcf5ef2aSThomas Huth static const char fregnames[32][4] = { 5363fcf5ef2aSThomas Huth "f0", "f2", "f4", "f6", "f8", "f10", "f12", "f14", 5364fcf5ef2aSThomas Huth "f16", "f18", "f20", "f22", "f24", "f26", "f28", "f30", 5365fcf5ef2aSThomas Huth "f32", "f34", "f36", "f38", "f40", "f42", "f44", "f46", 5366fcf5ef2aSThomas Huth "f48", "f50", "f52", "f54", "f56", "f58", "f60", "f62", 5367fcf5ef2aSThomas Huth }; 5368fcf5ef2aSThomas Huth 5369fcf5ef2aSThomas Huth static const struct { TCGv *ptr; int off; const char *name; } rtl[] = { 5370fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64 5371fcf5ef2aSThomas Huth { &cpu_gsr, offsetof(CPUSPARCState, gsr), "gsr" }, 53722a1905c7SRichard Henderson { &cpu_xcc_Z, offsetof(CPUSPARCState, xcc_Z), "xcc_Z" }, 53732a1905c7SRichard Henderson { &cpu_xcc_C, offsetof(CPUSPARCState, xcc_C), "xcc_C" }, 5374fcf5ef2aSThomas Huth #endif 53752a1905c7SRichard Henderson { &cpu_cc_N, offsetof(CPUSPARCState, cc_N), "cc_N" }, 53762a1905c7SRichard Henderson { &cpu_cc_V, offsetof(CPUSPARCState, cc_V), "cc_V" }, 53772a1905c7SRichard Henderson { &cpu_icc_Z, offsetof(CPUSPARCState, icc_Z), "icc_Z" }, 53782a1905c7SRichard Henderson { &cpu_icc_C, offsetof(CPUSPARCState, icc_C), "icc_C" }, 5379fcf5ef2aSThomas Huth { &cpu_cond, offsetof(CPUSPARCState, cond), "cond" }, 5380fcf5ef2aSThomas Huth { &cpu_fsr, offsetof(CPUSPARCState, fsr), "fsr" }, 5381fcf5ef2aSThomas Huth { &cpu_pc, offsetof(CPUSPARCState, pc), "pc" }, 5382fcf5ef2aSThomas Huth { &cpu_npc, offsetof(CPUSPARCState, npc), "npc" }, 5383fcf5ef2aSThomas Huth { &cpu_y, offsetof(CPUSPARCState, y), "y" }, 5384fcf5ef2aSThomas Huth { &cpu_tbr, offsetof(CPUSPARCState, tbr), "tbr" }, 5385fcf5ef2aSThomas Huth }; 5386fcf5ef2aSThomas Huth 5387fcf5ef2aSThomas Huth unsigned int i; 5388fcf5ef2aSThomas Huth 5389ad75a51eSRichard Henderson cpu_regwptr = tcg_global_mem_new_ptr(tcg_env, 5390fcf5ef2aSThomas Huth offsetof(CPUSPARCState, regwptr), 5391fcf5ef2aSThomas Huth "regwptr"); 5392fcf5ef2aSThomas Huth 5393fcf5ef2aSThomas Huth for (i = 0; i < ARRAY_SIZE(rtl); ++i) { 5394ad75a51eSRichard Henderson *rtl[i].ptr = tcg_global_mem_new(tcg_env, rtl[i].off, rtl[i].name); 5395fcf5ef2aSThomas Huth } 5396fcf5ef2aSThomas Huth 5397f764718dSRichard Henderson cpu_regs[0] = NULL; 5398fcf5ef2aSThomas Huth for (i = 1; i < 8; ++i) { 5399ad75a51eSRichard Henderson cpu_regs[i] = tcg_global_mem_new(tcg_env, 5400fcf5ef2aSThomas Huth offsetof(CPUSPARCState, gregs[i]), 5401fcf5ef2aSThomas Huth gregnames[i]); 5402fcf5ef2aSThomas Huth } 5403fcf5ef2aSThomas Huth 5404fcf5ef2aSThomas Huth for (i = 8; i < 32; ++i) { 5405fcf5ef2aSThomas Huth cpu_regs[i] = tcg_global_mem_new(cpu_regwptr, 5406fcf5ef2aSThomas Huth (i - 8) * sizeof(target_ulong), 5407fcf5ef2aSThomas Huth gregnames[i]); 5408fcf5ef2aSThomas Huth } 5409fcf5ef2aSThomas Huth 5410fcf5ef2aSThomas Huth for (i = 0; i < TARGET_DPREGS; i++) { 5411ad75a51eSRichard Henderson cpu_fpr[i] = tcg_global_mem_new_i64(tcg_env, 5412fcf5ef2aSThomas Huth offsetof(CPUSPARCState, fpr[i]), 5413fcf5ef2aSThomas Huth fregnames[i]); 5414fcf5ef2aSThomas Huth } 5415b597eedcSRichard Henderson 5416b597eedcSRichard Henderson #ifdef TARGET_SPARC64 5417b597eedcSRichard Henderson cpu_fprs = tcg_global_mem_new_i32(tcg_env, 5418b597eedcSRichard Henderson offsetof(CPUSPARCState, fprs), "fprs"); 5419b597eedcSRichard Henderson #endif 5420fcf5ef2aSThomas Huth } 5421fcf5ef2aSThomas Huth 5422f36aaa53SRichard Henderson void sparc_restore_state_to_opc(CPUState *cs, 5423f36aaa53SRichard Henderson const TranslationBlock *tb, 5424f36aaa53SRichard Henderson const uint64_t *data) 5425fcf5ef2aSThomas Huth { 5426f36aaa53SRichard Henderson SPARCCPU *cpu = SPARC_CPU(cs); 5427f36aaa53SRichard Henderson CPUSPARCState *env = &cpu->env; 5428fcf5ef2aSThomas Huth target_ulong pc = data[0]; 5429fcf5ef2aSThomas Huth target_ulong npc = data[1]; 5430fcf5ef2aSThomas Huth 5431fcf5ef2aSThomas Huth env->pc = pc; 5432fcf5ef2aSThomas Huth if (npc == DYNAMIC_PC) { 5433fcf5ef2aSThomas Huth /* dynamic NPC: already stored */ 5434fcf5ef2aSThomas Huth } else if (npc & JUMP_PC) { 5435fcf5ef2aSThomas Huth /* jump PC: use 'cond' and the jump targets of the translation */ 5436fcf5ef2aSThomas Huth if (env->cond) { 5437fcf5ef2aSThomas Huth env->npc = npc & ~3; 5438fcf5ef2aSThomas Huth } else { 5439fcf5ef2aSThomas Huth env->npc = pc + 4; 5440fcf5ef2aSThomas Huth } 5441fcf5ef2aSThomas Huth } else { 5442fcf5ef2aSThomas Huth env->npc = npc; 5443fcf5ef2aSThomas Huth } 5444fcf5ef2aSThomas Huth } 5445