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 "exec/helper-proto.h" 25fcf5ef2aSThomas Huth #include "exec/exec-all.h" 26dcb32f1dSPhilippe Mathieu-Daudé #include "tcg/tcg-op.h" 27fafba1bbSRichard Henderson #include "tcg/tcg-op-gvec.h" 28fcf5ef2aSThomas Huth #include "exec/helper-gen.h" 29c5e6ccdfSEmilio G. Cota #include "exec/translator.h" 30fcf5ef2aSThomas Huth #include "exec/log.h" 314fd71d19SRichard Henderson #include "fpu/softfloat.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() 40c92948f2SClément Chigot # define gen_helper_rdasr17(D, E) qemu_build_not_reached() 4186b82fe0SRichard Henderson # define gen_helper_rett(E) qemu_build_not_reached() 420faef01bSRichard Henderson # define gen_helper_power_down(E) qemu_build_not_reached() 4325524734SRichard Henderson # define gen_helper_wrpsr(E, S) qemu_build_not_reached() 44668bb9b7SRichard Henderson #else 450faef01bSRichard Henderson # define gen_helper_clear_softint(E, S) qemu_build_not_reached() 468f75b8a4SRichard Henderson # define gen_helper_done(E) qemu_build_not_reached() 47e8325dc0SRichard Henderson # define gen_helper_flushw(E) qemu_build_not_reached() 48a859602cSRichard Henderson # define gen_helper_fmul8x16a(D, S1, S2) qemu_build_not_reached() 49af25071cSRichard Henderson # define gen_helper_rdccr(D, E) qemu_build_not_reached() 505d617bfbSRichard Henderson # define gen_helper_rdcwp(D, E) qemu_build_not_reached() 5125524734SRichard Henderson # define gen_helper_restored(E) qemu_build_not_reached() 528f75b8a4SRichard Henderson # define gen_helper_retry(E) qemu_build_not_reached() 5325524734SRichard Henderson # define gen_helper_saved(E) qemu_build_not_reached() 540faef01bSRichard Henderson # define gen_helper_set_softint(E, S) qemu_build_not_reached() 55af25071cSRichard Henderson # define gen_helper_tick_get_count(D, E, T, C) qemu_build_not_reached() 569422278eSRichard Henderson # define gen_helper_tick_set_count(P, S) qemu_build_not_reached() 57bb97f2f5SRichard Henderson # define gen_helper_tick_set_limit(P, S) qemu_build_not_reached() 580faef01bSRichard Henderson # define gen_helper_wrccr(E, S) qemu_build_not_reached() 599422278eSRichard Henderson # define gen_helper_wrcwp(E, S) qemu_build_not_reached() 609422278eSRichard Henderson # define gen_helper_wrgl(E, S) qemu_build_not_reached() 610faef01bSRichard Henderson # define gen_helper_write_softint(E, S) qemu_build_not_reached() 629422278eSRichard Henderson # define gen_helper_wrpil(E, S) qemu_build_not_reached() 639422278eSRichard Henderson # define gen_helper_wrpstate(E, S) qemu_build_not_reached() 64c973b4e8SRichard Henderson # define gen_helper_cmask8 ({ qemu_build_not_reached(); NULL; }) 65c973b4e8SRichard Henderson # define gen_helper_cmask16 ({ qemu_build_not_reached(); NULL; }) 66c973b4e8SRichard Henderson # define gen_helper_cmask32 ({ qemu_build_not_reached(); NULL; }) 67669e0774SRichard Henderson # define gen_helper_fcmpeq8 ({ qemu_build_not_reached(); NULL; }) 68e2fa6bd1SRichard Henderson # define gen_helper_fcmpeq16 ({ qemu_build_not_reached(); NULL; }) 69e2fa6bd1SRichard Henderson # define gen_helper_fcmpeq32 ({ qemu_build_not_reached(); NULL; }) 70b3c934ddSRichard Henderson # define gen_helper_fcmpgt8 ({ qemu_build_not_reached(); NULL; }) 71e2fa6bd1SRichard Henderson # define gen_helper_fcmpgt16 ({ qemu_build_not_reached(); NULL; }) 72e2fa6bd1SRichard Henderson # define gen_helper_fcmpgt32 ({ qemu_build_not_reached(); NULL; }) 73b3c934ddSRichard Henderson # define gen_helper_fcmple8 ({ qemu_build_not_reached(); NULL; }) 74e2fa6bd1SRichard Henderson # define gen_helper_fcmple16 ({ qemu_build_not_reached(); NULL; }) 75e2fa6bd1SRichard Henderson # define gen_helper_fcmple32 ({ qemu_build_not_reached(); NULL; }) 76669e0774SRichard Henderson # define gen_helper_fcmpne8 ({ qemu_build_not_reached(); NULL; }) 77e2fa6bd1SRichard Henderson # define gen_helper_fcmpne16 ({ qemu_build_not_reached(); NULL; }) 78e2fa6bd1SRichard Henderson # define gen_helper_fcmpne32 ({ qemu_build_not_reached(); NULL; }) 79669e0774SRichard Henderson # define gen_helper_fcmpule8 ({ qemu_build_not_reached(); NULL; }) 80b3c934ddSRichard Henderson # define gen_helper_fcmpule16 ({ qemu_build_not_reached(); NULL; }) 81b3c934ddSRichard Henderson # define gen_helper_fcmpule32 ({ qemu_build_not_reached(); NULL; }) 82669e0774SRichard Henderson # define gen_helper_fcmpugt8 ({ qemu_build_not_reached(); NULL; }) 83b3c934ddSRichard Henderson # define gen_helper_fcmpugt16 ({ qemu_build_not_reached(); NULL; }) 84b3c934ddSRichard Henderson # define gen_helper_fcmpugt32 ({ qemu_build_not_reached(); NULL; }) 858aa418b3SRichard Henderson # define gen_helper_fdtox ({ qemu_build_not_reached(); NULL; }) 86e06c9f83SRichard Henderson # define gen_helper_fexpand ({ qemu_build_not_reached(); NULL; }) 87e06c9f83SRichard Henderson # define gen_helper_fmul8sux16 ({ qemu_build_not_reached(); NULL; }) 88e06c9f83SRichard Henderson # define gen_helper_fmul8ulx16 ({ qemu_build_not_reached(); NULL; }) 89e06c9f83SRichard Henderson # define gen_helper_fmul8x16 ({ qemu_build_not_reached(); NULL; }) 90e06c9f83SRichard Henderson # define gen_helper_fpmerge ({ qemu_build_not_reached(); NULL; }) 911617586fSRichard Henderson # define gen_helper_fqtox ({ qemu_build_not_reached(); NULL; }) 92fbc5c8d4SRichard Henderson # define gen_helper_fslas16 ({ qemu_build_not_reached(); NULL; }) 93fbc5c8d4SRichard Henderson # define gen_helper_fslas32 ({ qemu_build_not_reached(); NULL; }) 94199d43efSRichard Henderson # define gen_helper_fstox ({ qemu_build_not_reached(); NULL; }) 958aa418b3SRichard Henderson # define gen_helper_fxtod ({ qemu_build_not_reached(); NULL; }) 967b8e3e1aSRichard Henderson # define gen_helper_fxtoq ({ qemu_build_not_reached(); NULL; }) 97f4e18df5SRichard Henderson # define gen_helper_fxtos ({ qemu_build_not_reached(); NULL; }) 98afb04344SRichard Henderson # define gen_helper_pdist ({ qemu_build_not_reached(); NULL; }) 99029b0283SRichard Henderson # define gen_helper_xmulx ({ qemu_build_not_reached(); NULL; }) 100029b0283SRichard Henderson # define gen_helper_xmulxhi ({ qemu_build_not_reached(); NULL; }) 101668bb9b7SRichard Henderson # define MAXTL_MASK 0 102af25071cSRichard Henderson #endif 103af25071cSRichard Henderson 104633c4283SRichard Henderson /* Dynamic PC, must exit to main loop. */ 105633c4283SRichard Henderson #define DYNAMIC_PC 1 106633c4283SRichard Henderson /* Dynamic PC, one of two values according to jump_pc[T2]. */ 107633c4283SRichard Henderson #define JUMP_PC 2 108633c4283SRichard Henderson /* Dynamic PC, may lookup next TB. */ 109633c4283SRichard Henderson #define DYNAMIC_PC_LOOKUP 3 110fcf5ef2aSThomas Huth 11146bb0137SMark Cave-Ayland #define DISAS_EXIT DISAS_TARGET_0 11246bb0137SMark Cave-Ayland 113fcf5ef2aSThomas Huth /* global register indexes */ 114fcf5ef2aSThomas Huth static TCGv_ptr cpu_regwptr; 115c9fa8e58SRichard Henderson static TCGv cpu_pc, cpu_npc; 116fcf5ef2aSThomas Huth static TCGv cpu_regs[32]; 117fcf5ef2aSThomas Huth static TCGv cpu_y; 118fcf5ef2aSThomas Huth static TCGv cpu_tbr; 119fcf5ef2aSThomas Huth static TCGv cpu_cond; 1202a1905c7SRichard Henderson static TCGv cpu_cc_N; 1212a1905c7SRichard Henderson static TCGv cpu_cc_V; 1222a1905c7SRichard Henderson static TCGv cpu_icc_Z; 1232a1905c7SRichard Henderson static TCGv cpu_icc_C; 124fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64 1252a1905c7SRichard Henderson static TCGv cpu_xcc_Z; 1262a1905c7SRichard Henderson static TCGv cpu_xcc_C; 1272a1905c7SRichard Henderson static TCGv_i32 cpu_fprs; 128fcf5ef2aSThomas Huth static TCGv cpu_gsr; 129fcf5ef2aSThomas Huth #else 130af25071cSRichard Henderson # define cpu_fprs ({ qemu_build_not_reached(); (TCGv)NULL; }) 131af25071cSRichard Henderson # define cpu_gsr ({ qemu_build_not_reached(); (TCGv)NULL; }) 132fcf5ef2aSThomas Huth #endif 1332a1905c7SRichard Henderson 1342a1905c7SRichard Henderson #ifdef TARGET_SPARC64 1352a1905c7SRichard Henderson #define cpu_cc_Z cpu_xcc_Z 1362a1905c7SRichard Henderson #define cpu_cc_C cpu_xcc_C 1372a1905c7SRichard Henderson #else 1382a1905c7SRichard Henderson #define cpu_cc_Z cpu_icc_Z 1392a1905c7SRichard Henderson #define cpu_cc_C cpu_icc_C 1402a1905c7SRichard Henderson #define cpu_xcc_Z ({ qemu_build_not_reached(); NULL; }) 1412a1905c7SRichard Henderson #define cpu_xcc_C ({ qemu_build_not_reached(); NULL; }) 1422a1905c7SRichard Henderson #endif 1432a1905c7SRichard Henderson 1441210a036SRichard Henderson /* Floating point comparison registers */ 145d8c5b92fSRichard Henderson static TCGv_i32 cpu_fcc[TARGET_FCCREGS]; 146fcf5ef2aSThomas Huth 147af25071cSRichard Henderson #define env_field_offsetof(X) offsetof(CPUSPARCState, X) 148af25071cSRichard Henderson #ifdef TARGET_SPARC64 149cd6269f7SRichard Henderson # define env32_field_offsetof(X) ({ qemu_build_not_reached(); 0; }) 150af25071cSRichard Henderson # define env64_field_offsetof(X) env_field_offsetof(X) 151af25071cSRichard Henderson #else 152cd6269f7SRichard Henderson # define env32_field_offsetof(X) env_field_offsetof(X) 153af25071cSRichard Henderson # define env64_field_offsetof(X) ({ qemu_build_not_reached(); 0; }) 154af25071cSRichard Henderson #endif 155af25071cSRichard Henderson 156533f042fSRichard Henderson typedef struct DisasCompare { 157533f042fSRichard Henderson TCGCond cond; 158533f042fSRichard Henderson TCGv c1; 159533f042fSRichard Henderson int c2; 160533f042fSRichard Henderson } DisasCompare; 161533f042fSRichard Henderson 162186e7890SRichard Henderson typedef struct DisasDelayException { 163186e7890SRichard Henderson struct DisasDelayException *next; 164186e7890SRichard Henderson TCGLabel *lab; 165186e7890SRichard Henderson TCGv_i32 excp; 166186e7890SRichard Henderson /* Saved state at parent insn. */ 167186e7890SRichard Henderson target_ulong pc; 168186e7890SRichard Henderson target_ulong npc; 169186e7890SRichard Henderson } DisasDelayException; 170186e7890SRichard Henderson 171fcf5ef2aSThomas Huth typedef struct DisasContext { 172af00be49SEmilio G. Cota DisasContextBase base; 173fcf5ef2aSThomas Huth target_ulong pc; /* current Program Counter: integer or DYNAMIC_PC */ 174fcf5ef2aSThomas Huth target_ulong npc; /* next PC: integer or DYNAMIC_PC or JUMP_PC */ 175533f042fSRichard Henderson 176533f042fSRichard Henderson /* Used when JUMP_PC value is used. */ 177533f042fSRichard Henderson DisasCompare jump; 178533f042fSRichard Henderson target_ulong jump_pc[2]; 179533f042fSRichard Henderson 180fcf5ef2aSThomas Huth int mem_idx; 18189527e3aSRichard Henderson bool cpu_cond_live; 182c9b459aaSArtyom Tarasenko bool fpu_enabled; 183c9b459aaSArtyom Tarasenko bool address_mask_32bit; 184c9b459aaSArtyom Tarasenko #ifndef CONFIG_USER_ONLY 185c9b459aaSArtyom Tarasenko bool supervisor; 186c9b459aaSArtyom Tarasenko #ifdef TARGET_SPARC64 187c9b459aaSArtyom Tarasenko bool hypervisor; 188c9b459aaSArtyom Tarasenko #endif 189c9b459aaSArtyom Tarasenko #endif 190c9b459aaSArtyom Tarasenko 191fcf5ef2aSThomas Huth sparc_def_t *def; 192fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64 193fcf5ef2aSThomas Huth int fprs_dirty; 194fcf5ef2aSThomas Huth int asi; 195fcf5ef2aSThomas Huth #endif 196186e7890SRichard Henderson DisasDelayException *delay_excp_list; 197fcf5ef2aSThomas Huth } DisasContext; 198fcf5ef2aSThomas Huth 199fcf5ef2aSThomas Huth // This function uses non-native bit order 200fcf5ef2aSThomas Huth #define GET_FIELD(X, FROM, TO) \ 201fcf5ef2aSThomas Huth ((X) >> (31 - (TO)) & ((1 << ((TO) - (FROM) + 1)) - 1)) 202fcf5ef2aSThomas Huth 203fcf5ef2aSThomas Huth // This function uses the order in the manuals, i.e. bit 0 is 2^0 204fcf5ef2aSThomas Huth #define GET_FIELD_SP(X, FROM, TO) \ 205fcf5ef2aSThomas Huth GET_FIELD(X, 31 - (TO), 31 - (FROM)) 206fcf5ef2aSThomas Huth 207fcf5ef2aSThomas Huth #define GET_FIELDs(x,a,b) sign_extend (GET_FIELD(x,a,b), (b) - (a) + 1) 208fcf5ef2aSThomas Huth #define GET_FIELD_SPs(x,a,b) sign_extend (GET_FIELD_SP(x,a,b), ((b) - (a) + 1)) 209fcf5ef2aSThomas Huth 210fcf5ef2aSThomas Huth #define UA2005_HTRAP_MASK 0xff 211fcf5ef2aSThomas Huth #define V8_TRAP_MASK 0x7f 212fcf5ef2aSThomas Huth 213fcf5ef2aSThomas Huth #define IS_IMM (insn & (1<<13)) 214fcf5ef2aSThomas Huth 2150c2e96c1SRichard Henderson static void gen_update_fprs_dirty(DisasContext *dc, int rd) 216fcf5ef2aSThomas Huth { 217fcf5ef2aSThomas Huth #if defined(TARGET_SPARC64) 218fcf5ef2aSThomas Huth int bit = (rd < 32) ? 1 : 2; 219fcf5ef2aSThomas Huth /* If we know we've already set this bit within the TB, 220fcf5ef2aSThomas Huth we can avoid setting it again. */ 221fcf5ef2aSThomas Huth if (!(dc->fprs_dirty & bit)) { 222fcf5ef2aSThomas Huth dc->fprs_dirty |= bit; 223fcf5ef2aSThomas Huth tcg_gen_ori_i32(cpu_fprs, cpu_fprs, bit); 224fcf5ef2aSThomas Huth } 225fcf5ef2aSThomas Huth #endif 226fcf5ef2aSThomas Huth } 227fcf5ef2aSThomas Huth 228fcf5ef2aSThomas Huth /* floating point registers moves */ 2291210a036SRichard Henderson 2301210a036SRichard Henderson static int gen_offset_fpr_F(unsigned int reg) 2311210a036SRichard Henderson { 2321210a036SRichard Henderson int ret; 2331210a036SRichard Henderson 2341210a036SRichard Henderson tcg_debug_assert(reg < 32); 2351210a036SRichard Henderson ret= offsetof(CPUSPARCState, fpr[reg / 2]); 2361210a036SRichard Henderson if (reg & 1) { 2371210a036SRichard Henderson ret += offsetof(CPU_DoubleU, l.lower); 2381210a036SRichard Henderson } else { 2391210a036SRichard Henderson ret += offsetof(CPU_DoubleU, l.upper); 2401210a036SRichard Henderson } 2411210a036SRichard Henderson return ret; 2421210a036SRichard Henderson } 2431210a036SRichard Henderson 244fcf5ef2aSThomas Huth static TCGv_i32 gen_load_fpr_F(DisasContext *dc, unsigned int src) 245fcf5ef2aSThomas Huth { 24636ab4623SRichard Henderson TCGv_i32 ret = tcg_temp_new_i32(); 2471210a036SRichard Henderson tcg_gen_ld_i32(ret, tcg_env, gen_offset_fpr_F(src)); 248dc41aa7dSRichard Henderson return ret; 249fcf5ef2aSThomas Huth } 250fcf5ef2aSThomas Huth 251fcf5ef2aSThomas Huth static void gen_store_fpr_F(DisasContext *dc, unsigned int dst, TCGv_i32 v) 252fcf5ef2aSThomas Huth { 2531210a036SRichard Henderson tcg_gen_st_i32(v, tcg_env, gen_offset_fpr_F(dst)); 254fcf5ef2aSThomas Huth gen_update_fprs_dirty(dc, dst); 255fcf5ef2aSThomas Huth } 256fcf5ef2aSThomas Huth 2571210a036SRichard Henderson static int gen_offset_fpr_D(unsigned int reg) 2581210a036SRichard Henderson { 2591210a036SRichard Henderson tcg_debug_assert(reg < 64); 2601210a036SRichard Henderson tcg_debug_assert(reg % 2 == 0); 2611210a036SRichard Henderson return offsetof(CPUSPARCState, fpr[reg / 2]); 2621210a036SRichard Henderson } 2631210a036SRichard Henderson 264fcf5ef2aSThomas Huth static TCGv_i64 gen_load_fpr_D(DisasContext *dc, unsigned int src) 265fcf5ef2aSThomas Huth { 2661210a036SRichard Henderson TCGv_i64 ret = tcg_temp_new_i64(); 2671210a036SRichard Henderson tcg_gen_ld_i64(ret, tcg_env, gen_offset_fpr_D(src)); 2681210a036SRichard Henderson return ret; 269fcf5ef2aSThomas Huth } 270fcf5ef2aSThomas Huth 271fcf5ef2aSThomas Huth static void gen_store_fpr_D(DisasContext *dc, unsigned int dst, TCGv_i64 v) 272fcf5ef2aSThomas Huth { 2731210a036SRichard Henderson tcg_gen_st_i64(v, tcg_env, gen_offset_fpr_D(dst)); 274fcf5ef2aSThomas Huth gen_update_fprs_dirty(dc, dst); 275fcf5ef2aSThomas Huth } 276fcf5ef2aSThomas Huth 27733ec4245SRichard Henderson static TCGv_i128 gen_load_fpr_Q(DisasContext *dc, unsigned int src) 27833ec4245SRichard Henderson { 27933ec4245SRichard Henderson TCGv_i128 ret = tcg_temp_new_i128(); 2801210a036SRichard Henderson TCGv_i64 h = gen_load_fpr_D(dc, src); 2811210a036SRichard Henderson TCGv_i64 l = gen_load_fpr_D(dc, src + 2); 28233ec4245SRichard Henderson 2831210a036SRichard Henderson tcg_gen_concat_i64_i128(ret, l, h); 28433ec4245SRichard Henderson return ret; 28533ec4245SRichard Henderson } 28633ec4245SRichard Henderson 28733ec4245SRichard Henderson static void gen_store_fpr_Q(DisasContext *dc, unsigned int dst, TCGv_i128 v) 28833ec4245SRichard Henderson { 2891210a036SRichard Henderson TCGv_i64 h = tcg_temp_new_i64(); 2901210a036SRichard Henderson TCGv_i64 l = tcg_temp_new_i64(); 2911210a036SRichard Henderson 2921210a036SRichard Henderson tcg_gen_extr_i128_i64(l, h, v); 2931210a036SRichard Henderson gen_store_fpr_D(dc, dst, h); 2941210a036SRichard Henderson gen_store_fpr_D(dc, dst + 2, l); 29533ec4245SRichard Henderson } 29633ec4245SRichard Henderson 297fcf5ef2aSThomas Huth /* moves */ 298fcf5ef2aSThomas Huth #ifdef CONFIG_USER_ONLY 299fcf5ef2aSThomas Huth #define supervisor(dc) 0 300fcf5ef2aSThomas Huth #define hypervisor(dc) 0 301fcf5ef2aSThomas Huth #else 302fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64 303c9b459aaSArtyom Tarasenko #define hypervisor(dc) (dc->hypervisor) 304c9b459aaSArtyom Tarasenko #define supervisor(dc) (dc->supervisor | dc->hypervisor) 305fcf5ef2aSThomas Huth #else 306c9b459aaSArtyom Tarasenko #define supervisor(dc) (dc->supervisor) 307668bb9b7SRichard Henderson #define hypervisor(dc) 0 308fcf5ef2aSThomas Huth #endif 309fcf5ef2aSThomas Huth #endif 310fcf5ef2aSThomas Huth 311b1bc09eaSRichard Henderson #if !defined(TARGET_SPARC64) 312b1bc09eaSRichard Henderson # define AM_CHECK(dc) false 313b1bc09eaSRichard Henderson #elif defined(TARGET_ABI32) 314b1bc09eaSRichard Henderson # define AM_CHECK(dc) true 315b1bc09eaSRichard Henderson #elif defined(CONFIG_USER_ONLY) 316b1bc09eaSRichard Henderson # define AM_CHECK(dc) false 317fcf5ef2aSThomas Huth #else 318b1bc09eaSRichard Henderson # define AM_CHECK(dc) ((dc)->address_mask_32bit) 319fcf5ef2aSThomas Huth #endif 320fcf5ef2aSThomas Huth 3210c2e96c1SRichard Henderson static void gen_address_mask(DisasContext *dc, TCGv addr) 322fcf5ef2aSThomas Huth { 323b1bc09eaSRichard Henderson if (AM_CHECK(dc)) { 324fcf5ef2aSThomas Huth tcg_gen_andi_tl(addr, addr, 0xffffffffULL); 325b1bc09eaSRichard Henderson } 326fcf5ef2aSThomas Huth } 327fcf5ef2aSThomas Huth 32823ada1b1SRichard Henderson static target_ulong address_mask_i(DisasContext *dc, target_ulong addr) 32923ada1b1SRichard Henderson { 33023ada1b1SRichard Henderson return AM_CHECK(dc) ? (uint32_t)addr : addr; 33123ada1b1SRichard Henderson } 33223ada1b1SRichard Henderson 3330c2e96c1SRichard Henderson static TCGv gen_load_gpr(DisasContext *dc, int reg) 334fcf5ef2aSThomas Huth { 335fcf5ef2aSThomas Huth if (reg > 0) { 336fcf5ef2aSThomas Huth assert(reg < 32); 337fcf5ef2aSThomas Huth return cpu_regs[reg]; 338fcf5ef2aSThomas Huth } else { 33952123f14SRichard Henderson TCGv t = tcg_temp_new(); 340fcf5ef2aSThomas Huth tcg_gen_movi_tl(t, 0); 341fcf5ef2aSThomas Huth return t; 342fcf5ef2aSThomas Huth } 343fcf5ef2aSThomas Huth } 344fcf5ef2aSThomas Huth 3450c2e96c1SRichard Henderson static void gen_store_gpr(DisasContext *dc, int reg, TCGv v) 346fcf5ef2aSThomas Huth { 347fcf5ef2aSThomas Huth if (reg > 0) { 348fcf5ef2aSThomas Huth assert(reg < 32); 349fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_regs[reg], v); 350fcf5ef2aSThomas Huth } 351fcf5ef2aSThomas Huth } 352fcf5ef2aSThomas Huth 3530c2e96c1SRichard Henderson static TCGv gen_dest_gpr(DisasContext *dc, int reg) 354fcf5ef2aSThomas Huth { 355fcf5ef2aSThomas Huth if (reg > 0) { 356fcf5ef2aSThomas Huth assert(reg < 32); 357fcf5ef2aSThomas Huth return cpu_regs[reg]; 358fcf5ef2aSThomas Huth } else { 35952123f14SRichard Henderson return tcg_temp_new(); 360fcf5ef2aSThomas Huth } 361fcf5ef2aSThomas Huth } 362fcf5ef2aSThomas Huth 3635645aa2eSRichard Henderson static bool use_goto_tb(DisasContext *s, target_ulong pc, target_ulong npc) 364fcf5ef2aSThomas Huth { 3655645aa2eSRichard Henderson return translator_use_goto_tb(&s->base, pc) && 3665645aa2eSRichard Henderson translator_use_goto_tb(&s->base, npc); 367fcf5ef2aSThomas Huth } 368fcf5ef2aSThomas Huth 3695645aa2eSRichard Henderson static void gen_goto_tb(DisasContext *s, int tb_num, 370fcf5ef2aSThomas Huth target_ulong pc, target_ulong npc) 371fcf5ef2aSThomas Huth { 372fcf5ef2aSThomas Huth if (use_goto_tb(s, pc, npc)) { 373fcf5ef2aSThomas Huth /* jump to same page: we can use a direct jump */ 374fcf5ef2aSThomas Huth tcg_gen_goto_tb(tb_num); 375fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_pc, pc); 376fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_npc, npc); 37707ea28b4SRichard Henderson tcg_gen_exit_tb(s->base.tb, tb_num); 378fcf5ef2aSThomas Huth } else { 379f67ccb2fSRichard Henderson /* jump to another page: we can use an indirect jump */ 380fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_pc, pc); 381fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_npc, npc); 382f67ccb2fSRichard Henderson tcg_gen_lookup_and_goto_ptr(); 383fcf5ef2aSThomas Huth } 384fcf5ef2aSThomas Huth } 385fcf5ef2aSThomas Huth 386b989ce73SRichard Henderson static TCGv gen_carry32(void) 387fcf5ef2aSThomas Huth { 388b989ce73SRichard Henderson if (TARGET_LONG_BITS == 64) { 389b989ce73SRichard Henderson TCGv t = tcg_temp_new(); 390b989ce73SRichard Henderson tcg_gen_extract_tl(t, cpu_icc_C, 32, 1); 391b989ce73SRichard Henderson return t; 392b989ce73SRichard Henderson } 393b989ce73SRichard Henderson return cpu_icc_C; 394fcf5ef2aSThomas Huth } 395fcf5ef2aSThomas Huth 396b989ce73SRichard Henderson static void gen_op_addcc_int(TCGv dst, TCGv src1, TCGv src2, TCGv cin) 397fcf5ef2aSThomas Huth { 398b989ce73SRichard Henderson TCGv z = tcg_constant_tl(0); 399fcf5ef2aSThomas Huth 400b989ce73SRichard Henderson if (cin) { 401b989ce73SRichard Henderson tcg_gen_add2_tl(cpu_cc_N, cpu_cc_C, src1, z, cin, z); 402b989ce73SRichard Henderson tcg_gen_add2_tl(cpu_cc_N, cpu_cc_C, cpu_cc_N, cpu_cc_C, src2, z); 403b989ce73SRichard Henderson } else { 404b989ce73SRichard Henderson tcg_gen_add2_tl(cpu_cc_N, cpu_cc_C, src1, z, src2, z); 405b989ce73SRichard Henderson } 406b989ce73SRichard Henderson tcg_gen_xor_tl(cpu_cc_Z, src1, src2); 407b989ce73SRichard Henderson tcg_gen_xor_tl(cpu_cc_V, cpu_cc_N, src2); 408b989ce73SRichard Henderson tcg_gen_andc_tl(cpu_cc_V, cpu_cc_V, cpu_cc_Z); 409b989ce73SRichard Henderson if (TARGET_LONG_BITS == 64) { 410b989ce73SRichard Henderson /* 411b989ce73SRichard Henderson * Carry-in to bit 32 is result ^ src1 ^ src2. 412b989ce73SRichard Henderson * We already have the src xor term in Z, from computation of V. 413b989ce73SRichard Henderson */ 414b989ce73SRichard Henderson tcg_gen_xor_tl(cpu_icc_C, cpu_cc_Z, cpu_cc_N); 415b989ce73SRichard Henderson tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N); 416b989ce73SRichard Henderson } 417b989ce73SRichard Henderson tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N); 418b989ce73SRichard Henderson tcg_gen_mov_tl(dst, cpu_cc_N); 419b989ce73SRichard Henderson } 420fcf5ef2aSThomas Huth 421b989ce73SRichard Henderson static void gen_op_addcc(TCGv dst, TCGv src1, TCGv src2) 422b989ce73SRichard Henderson { 423b989ce73SRichard Henderson gen_op_addcc_int(dst, src1, src2, NULL); 424b989ce73SRichard Henderson } 425fcf5ef2aSThomas Huth 426b989ce73SRichard Henderson static void gen_op_taddcc(TCGv dst, TCGv src1, TCGv src2) 427b989ce73SRichard Henderson { 428b989ce73SRichard Henderson TCGv t = tcg_temp_new(); 429b989ce73SRichard Henderson 430b989ce73SRichard Henderson /* Save the tag bits around modification of dst. */ 431b989ce73SRichard Henderson tcg_gen_or_tl(t, src1, src2); 432b989ce73SRichard Henderson 433b989ce73SRichard Henderson gen_op_addcc(dst, src1, src2); 434b989ce73SRichard Henderson 435b989ce73SRichard Henderson /* Incorprate tag bits into icc.V */ 436b989ce73SRichard Henderson tcg_gen_andi_tl(t, t, 3); 437b989ce73SRichard Henderson tcg_gen_neg_tl(t, t); 438b989ce73SRichard Henderson tcg_gen_ext32u_tl(t, t); 439b989ce73SRichard Henderson tcg_gen_or_tl(cpu_cc_V, cpu_cc_V, t); 440b989ce73SRichard Henderson } 441b989ce73SRichard Henderson 442b989ce73SRichard Henderson static void gen_op_addc(TCGv dst, TCGv src1, TCGv src2) 443b989ce73SRichard Henderson { 444b989ce73SRichard Henderson tcg_gen_add_tl(dst, src1, src2); 445b989ce73SRichard Henderson tcg_gen_add_tl(dst, dst, gen_carry32()); 446b989ce73SRichard Henderson } 447b989ce73SRichard Henderson 448b989ce73SRichard Henderson static void gen_op_addccc(TCGv dst, TCGv src1, TCGv src2) 449b989ce73SRichard Henderson { 450b989ce73SRichard Henderson gen_op_addcc_int(dst, src1, src2, gen_carry32()); 451fcf5ef2aSThomas Huth } 452fcf5ef2aSThomas Huth 453015fc6fcSRichard Henderson static void gen_op_addxc(TCGv dst, TCGv src1, TCGv src2) 454015fc6fcSRichard Henderson { 455015fc6fcSRichard Henderson tcg_gen_add_tl(dst, src1, src2); 456015fc6fcSRichard Henderson tcg_gen_add_tl(dst, dst, cpu_cc_C); 457015fc6fcSRichard Henderson } 458015fc6fcSRichard Henderson 459015fc6fcSRichard Henderson static void gen_op_addxccc(TCGv dst, TCGv src1, TCGv src2) 460015fc6fcSRichard Henderson { 461015fc6fcSRichard Henderson gen_op_addcc_int(dst, src1, src2, cpu_cc_C); 462015fc6fcSRichard Henderson } 463015fc6fcSRichard Henderson 464f828df74SRichard Henderson static void gen_op_subcc_int(TCGv dst, TCGv src1, TCGv src2, TCGv cin) 465fcf5ef2aSThomas Huth { 466f828df74SRichard Henderson TCGv z = tcg_constant_tl(0); 467fcf5ef2aSThomas Huth 468f828df74SRichard Henderson if (cin) { 469f828df74SRichard Henderson tcg_gen_sub2_tl(cpu_cc_N, cpu_cc_C, src1, z, cin, z); 470f828df74SRichard Henderson tcg_gen_sub2_tl(cpu_cc_N, cpu_cc_C, cpu_cc_N, cpu_cc_C, src2, z); 471f828df74SRichard Henderson } else { 472f828df74SRichard Henderson tcg_gen_sub2_tl(cpu_cc_N, cpu_cc_C, src1, z, src2, z); 473f828df74SRichard Henderson } 474f828df74SRichard Henderson tcg_gen_neg_tl(cpu_cc_C, cpu_cc_C); 475f828df74SRichard Henderson tcg_gen_xor_tl(cpu_cc_Z, src1, src2); 476f828df74SRichard Henderson tcg_gen_xor_tl(cpu_cc_V, cpu_cc_N, src1); 477f828df74SRichard Henderson tcg_gen_and_tl(cpu_cc_V, cpu_cc_V, cpu_cc_Z); 478f828df74SRichard Henderson #ifdef TARGET_SPARC64 479f828df74SRichard Henderson tcg_gen_xor_tl(cpu_icc_C, cpu_cc_Z, cpu_cc_N); 480f828df74SRichard Henderson tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N); 481fcf5ef2aSThomas Huth #endif 482f828df74SRichard Henderson tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N); 483f828df74SRichard Henderson tcg_gen_mov_tl(dst, cpu_cc_N); 484fcf5ef2aSThomas Huth } 485fcf5ef2aSThomas Huth 486f828df74SRichard Henderson static void gen_op_subcc(TCGv dst, TCGv src1, TCGv src2) 487fcf5ef2aSThomas Huth { 488f828df74SRichard Henderson gen_op_subcc_int(dst, src1, src2, NULL); 489fcf5ef2aSThomas Huth } 490fcf5ef2aSThomas Huth 491f828df74SRichard Henderson static void gen_op_tsubcc(TCGv dst, TCGv src1, TCGv src2) 492fcf5ef2aSThomas Huth { 493f828df74SRichard Henderson TCGv t = tcg_temp_new(); 494fcf5ef2aSThomas Huth 495f828df74SRichard Henderson /* Save the tag bits around modification of dst. */ 496f828df74SRichard Henderson tcg_gen_or_tl(t, src1, src2); 497fcf5ef2aSThomas Huth 498f828df74SRichard Henderson gen_op_subcc(dst, src1, src2); 499f828df74SRichard Henderson 500f828df74SRichard Henderson /* Incorprate tag bits into icc.V */ 501f828df74SRichard Henderson tcg_gen_andi_tl(t, t, 3); 502f828df74SRichard Henderson tcg_gen_neg_tl(t, t); 503f828df74SRichard Henderson tcg_gen_ext32u_tl(t, t); 504f828df74SRichard Henderson tcg_gen_or_tl(cpu_cc_V, cpu_cc_V, t); 505f828df74SRichard Henderson } 506f828df74SRichard Henderson 507f828df74SRichard Henderson static void gen_op_subc(TCGv dst, TCGv src1, TCGv src2) 508f828df74SRichard Henderson { 509fcf5ef2aSThomas Huth tcg_gen_sub_tl(dst, src1, src2); 510f828df74SRichard Henderson tcg_gen_sub_tl(dst, dst, gen_carry32()); 511fcf5ef2aSThomas Huth } 512fcf5ef2aSThomas Huth 513f828df74SRichard Henderson static void gen_op_subccc(TCGv dst, TCGv src1, TCGv src2) 514dfebb950SRichard Henderson { 515f828df74SRichard Henderson gen_op_subcc_int(dst, src1, src2, gen_carry32()); 516dfebb950SRichard Henderson } 517dfebb950SRichard Henderson 51856f2ef9cSRichard Henderson static void gen_op_subxc(TCGv dst, TCGv src1, TCGv src2) 51956f2ef9cSRichard Henderson { 52056f2ef9cSRichard Henderson tcg_gen_sub_tl(dst, src1, src2); 52156f2ef9cSRichard Henderson tcg_gen_sub_tl(dst, dst, cpu_cc_C); 52256f2ef9cSRichard Henderson } 52356f2ef9cSRichard Henderson 52456f2ef9cSRichard Henderson static void gen_op_subxccc(TCGv dst, TCGv src1, TCGv src2) 52556f2ef9cSRichard Henderson { 52656f2ef9cSRichard Henderson gen_op_subcc_int(dst, src1, src2, cpu_cc_C); 52756f2ef9cSRichard Henderson } 52856f2ef9cSRichard Henderson 5290c2e96c1SRichard Henderson static void gen_op_mulscc(TCGv dst, TCGv src1, TCGv src2) 530fcf5ef2aSThomas Huth { 531b989ce73SRichard Henderson TCGv zero = tcg_constant_tl(0); 53250280618SRichard Henderson TCGv one = tcg_constant_tl(1); 533b989ce73SRichard Henderson TCGv t_src1 = tcg_temp_new(); 534b989ce73SRichard Henderson TCGv t_src2 = tcg_temp_new(); 535b989ce73SRichard Henderson TCGv t0 = tcg_temp_new(); 536fcf5ef2aSThomas Huth 537b989ce73SRichard Henderson tcg_gen_ext32u_tl(t_src1, src1); 538b989ce73SRichard Henderson tcg_gen_ext32u_tl(t_src2, src2); 539fcf5ef2aSThomas Huth 540b989ce73SRichard Henderson /* 541b989ce73SRichard Henderson * if (!(env->y & 1)) 542b989ce73SRichard Henderson * src2 = 0; 543fcf5ef2aSThomas Huth */ 54450280618SRichard Henderson tcg_gen_movcond_tl(TCG_COND_TSTEQ, t_src2, cpu_y, one, zero, t_src2); 545fcf5ef2aSThomas Huth 546b989ce73SRichard Henderson /* 547b989ce73SRichard Henderson * b2 = src1 & 1; 548b989ce73SRichard Henderson * y = (b2 << 31) | (y >> 1); 549b989ce73SRichard Henderson */ 5500b1183e3SPhilippe Mathieu-Daudé tcg_gen_extract_tl(t0, cpu_y, 1, 31); 551b989ce73SRichard Henderson tcg_gen_deposit_tl(cpu_y, t0, src1, 31, 1); 552fcf5ef2aSThomas Huth 553fcf5ef2aSThomas Huth // b1 = N ^ V; 5542a1905c7SRichard Henderson tcg_gen_xor_tl(t0, cpu_cc_N, cpu_cc_V); 555fcf5ef2aSThomas Huth 556b989ce73SRichard Henderson /* 557b989ce73SRichard Henderson * src1 = (b1 << 31) | (src1 >> 1) 558b989ce73SRichard Henderson */ 5592a1905c7SRichard Henderson tcg_gen_andi_tl(t0, t0, 1u << 31); 560b989ce73SRichard Henderson tcg_gen_shri_tl(t_src1, t_src1, 1); 561b989ce73SRichard Henderson tcg_gen_or_tl(t_src1, t_src1, t0); 562fcf5ef2aSThomas Huth 563b989ce73SRichard Henderson gen_op_addcc(dst, t_src1, t_src2); 564fcf5ef2aSThomas Huth } 565fcf5ef2aSThomas Huth 5660c2e96c1SRichard Henderson static void gen_op_multiply(TCGv dst, TCGv src1, TCGv src2, int sign_ext) 567fcf5ef2aSThomas Huth { 568fcf5ef2aSThomas Huth #if TARGET_LONG_BITS == 32 569fcf5ef2aSThomas Huth if (sign_ext) { 570fcf5ef2aSThomas Huth tcg_gen_muls2_tl(dst, cpu_y, src1, src2); 571fcf5ef2aSThomas Huth } else { 572fcf5ef2aSThomas Huth tcg_gen_mulu2_tl(dst, cpu_y, src1, src2); 573fcf5ef2aSThomas Huth } 574fcf5ef2aSThomas Huth #else 575fcf5ef2aSThomas Huth TCGv t0 = tcg_temp_new_i64(); 576fcf5ef2aSThomas Huth TCGv t1 = tcg_temp_new_i64(); 577fcf5ef2aSThomas Huth 578fcf5ef2aSThomas Huth if (sign_ext) { 579fcf5ef2aSThomas Huth tcg_gen_ext32s_i64(t0, src1); 580fcf5ef2aSThomas Huth tcg_gen_ext32s_i64(t1, src2); 581fcf5ef2aSThomas Huth } else { 582fcf5ef2aSThomas Huth tcg_gen_ext32u_i64(t0, src1); 583fcf5ef2aSThomas Huth tcg_gen_ext32u_i64(t1, src2); 584fcf5ef2aSThomas Huth } 585fcf5ef2aSThomas Huth 586fcf5ef2aSThomas Huth tcg_gen_mul_i64(dst, t0, t1); 587fcf5ef2aSThomas Huth tcg_gen_shri_i64(cpu_y, dst, 32); 588fcf5ef2aSThomas Huth #endif 589fcf5ef2aSThomas Huth } 590fcf5ef2aSThomas Huth 5910c2e96c1SRichard Henderson static void gen_op_umul(TCGv dst, TCGv src1, TCGv src2) 592fcf5ef2aSThomas Huth { 593fcf5ef2aSThomas Huth /* zero-extend truncated operands before multiplication */ 594fcf5ef2aSThomas Huth gen_op_multiply(dst, src1, src2, 0); 595fcf5ef2aSThomas Huth } 596fcf5ef2aSThomas Huth 5970c2e96c1SRichard Henderson static void gen_op_smul(TCGv dst, TCGv src1, TCGv src2) 598fcf5ef2aSThomas Huth { 599fcf5ef2aSThomas Huth /* sign-extend truncated operands before multiplication */ 600fcf5ef2aSThomas Huth gen_op_multiply(dst, src1, src2, 1); 601fcf5ef2aSThomas Huth } 602fcf5ef2aSThomas Huth 603680af1b4SRichard Henderson static void gen_op_umulxhi(TCGv dst, TCGv src1, TCGv src2) 604680af1b4SRichard Henderson { 605680af1b4SRichard Henderson TCGv discard = tcg_temp_new(); 606680af1b4SRichard Henderson tcg_gen_mulu2_tl(discard, dst, src1, src2); 607680af1b4SRichard Henderson } 608680af1b4SRichard Henderson 60968a414e9SRichard Henderson static void gen_op_fpmaddx(TCGv_i64 dst, TCGv_i64 src1, 61068a414e9SRichard Henderson TCGv_i64 src2, TCGv_i64 src3) 61168a414e9SRichard Henderson { 61268a414e9SRichard Henderson TCGv_i64 t = tcg_temp_new_i64(); 61368a414e9SRichard Henderson 61468a414e9SRichard Henderson tcg_gen_mul_i64(t, src1, src2); 61568a414e9SRichard Henderson tcg_gen_add_i64(dst, src3, t); 61668a414e9SRichard Henderson } 61768a414e9SRichard Henderson 61868a414e9SRichard Henderson static void gen_op_fpmaddxhi(TCGv_i64 dst, TCGv_i64 src1, 61968a414e9SRichard Henderson TCGv_i64 src2, TCGv_i64 src3) 62068a414e9SRichard Henderson { 62168a414e9SRichard Henderson TCGv_i64 l = tcg_temp_new_i64(); 62268a414e9SRichard Henderson TCGv_i64 h = tcg_temp_new_i64(); 62368a414e9SRichard Henderson TCGv_i64 z = tcg_constant_i64(0); 62468a414e9SRichard Henderson 62568a414e9SRichard Henderson tcg_gen_mulu2_i64(l, h, src1, src2); 62668a414e9SRichard Henderson tcg_gen_add2_i64(l, dst, l, h, src3, z); 62768a414e9SRichard Henderson } 62868a414e9SRichard Henderson 629c2636853SRichard Henderson static void gen_op_sdiv(TCGv dst, TCGv src1, TCGv src2) 630c2636853SRichard Henderson { 63113260103SRichard Henderson #ifdef TARGET_SPARC64 632c2636853SRichard Henderson gen_helper_sdiv(dst, tcg_env, src1, src2); 63313260103SRichard Henderson tcg_gen_ext32s_tl(dst, dst); 63413260103SRichard Henderson #else 63513260103SRichard Henderson TCGv_i64 t64 = tcg_temp_new_i64(); 63613260103SRichard Henderson gen_helper_sdiv(t64, tcg_env, src1, src2); 63713260103SRichard Henderson tcg_gen_trunc_i64_tl(dst, t64); 63813260103SRichard Henderson #endif 639c2636853SRichard Henderson } 640c2636853SRichard Henderson 641c2636853SRichard Henderson static void gen_op_udivcc(TCGv dst, TCGv src1, TCGv src2) 642c2636853SRichard Henderson { 64313260103SRichard Henderson TCGv_i64 t64; 64413260103SRichard Henderson 64513260103SRichard Henderson #ifdef TARGET_SPARC64 64613260103SRichard Henderson t64 = cpu_cc_V; 64713260103SRichard Henderson #else 64813260103SRichard Henderson t64 = tcg_temp_new_i64(); 64913260103SRichard Henderson #endif 65013260103SRichard Henderson 65113260103SRichard Henderson gen_helper_udiv(t64, tcg_env, src1, src2); 65213260103SRichard Henderson 65313260103SRichard Henderson #ifdef TARGET_SPARC64 65413260103SRichard Henderson tcg_gen_ext32u_tl(cpu_cc_N, t64); 65513260103SRichard Henderson tcg_gen_shri_tl(cpu_cc_V, t64, 32); 65613260103SRichard Henderson tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N); 65713260103SRichard Henderson tcg_gen_movi_tl(cpu_icc_C, 0); 65813260103SRichard Henderson #else 65913260103SRichard Henderson tcg_gen_extr_i64_tl(cpu_cc_N, cpu_cc_V, t64); 66013260103SRichard Henderson #endif 66113260103SRichard Henderson tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N); 66213260103SRichard Henderson tcg_gen_movi_tl(cpu_cc_C, 0); 66313260103SRichard Henderson tcg_gen_mov_tl(dst, cpu_cc_N); 664c2636853SRichard Henderson } 665c2636853SRichard Henderson 666c2636853SRichard Henderson static void gen_op_sdivcc(TCGv dst, TCGv src1, TCGv src2) 667c2636853SRichard Henderson { 66813260103SRichard Henderson TCGv_i64 t64; 66913260103SRichard Henderson 67013260103SRichard Henderson #ifdef TARGET_SPARC64 67113260103SRichard Henderson t64 = cpu_cc_V; 67213260103SRichard Henderson #else 67313260103SRichard Henderson t64 = tcg_temp_new_i64(); 67413260103SRichard Henderson #endif 67513260103SRichard Henderson 67613260103SRichard Henderson gen_helper_sdiv(t64, tcg_env, src1, src2); 67713260103SRichard Henderson 67813260103SRichard Henderson #ifdef TARGET_SPARC64 67913260103SRichard Henderson tcg_gen_ext32s_tl(cpu_cc_N, t64); 68013260103SRichard Henderson tcg_gen_shri_tl(cpu_cc_V, t64, 32); 68113260103SRichard Henderson tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N); 68213260103SRichard Henderson tcg_gen_movi_tl(cpu_icc_C, 0); 68313260103SRichard Henderson #else 68413260103SRichard Henderson tcg_gen_extr_i64_tl(cpu_cc_N, cpu_cc_V, t64); 68513260103SRichard Henderson #endif 68613260103SRichard Henderson tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N); 68713260103SRichard Henderson tcg_gen_movi_tl(cpu_cc_C, 0); 68813260103SRichard Henderson tcg_gen_mov_tl(dst, cpu_cc_N); 689c2636853SRichard Henderson } 690c2636853SRichard Henderson 691a9aba13dSRichard Henderson static void gen_op_taddcctv(TCGv dst, TCGv src1, TCGv src2) 692a9aba13dSRichard Henderson { 693a9aba13dSRichard Henderson gen_helper_taddcctv(dst, tcg_env, src1, src2); 694a9aba13dSRichard Henderson } 695a9aba13dSRichard Henderson 696a9aba13dSRichard Henderson static void gen_op_tsubcctv(TCGv dst, TCGv src1, TCGv src2) 697a9aba13dSRichard Henderson { 698a9aba13dSRichard Henderson gen_helper_tsubcctv(dst, tcg_env, src1, src2); 699a9aba13dSRichard Henderson } 700a9aba13dSRichard Henderson 7019c6ec5bcSRichard Henderson static void gen_op_popc(TCGv dst, TCGv src1, TCGv src2) 7029c6ec5bcSRichard Henderson { 7039c6ec5bcSRichard Henderson tcg_gen_ctpop_tl(dst, src2); 7049c6ec5bcSRichard Henderson } 7059c6ec5bcSRichard Henderson 706875ce392SRichard Henderson static void gen_op_lzcnt(TCGv dst, TCGv src) 707875ce392SRichard Henderson { 708875ce392SRichard Henderson tcg_gen_clzi_tl(dst, src, TARGET_LONG_BITS); 709875ce392SRichard Henderson } 710875ce392SRichard Henderson 71145bfed3bSRichard Henderson #ifndef TARGET_SPARC64 71245bfed3bSRichard Henderson static void gen_helper_array8(TCGv dst, TCGv src1, TCGv src2) 71345bfed3bSRichard Henderson { 71445bfed3bSRichard Henderson g_assert_not_reached(); 71545bfed3bSRichard Henderson } 71645bfed3bSRichard Henderson #endif 71745bfed3bSRichard Henderson 71845bfed3bSRichard Henderson static void gen_op_array16(TCGv dst, TCGv src1, TCGv src2) 71945bfed3bSRichard Henderson { 72045bfed3bSRichard Henderson gen_helper_array8(dst, src1, src2); 72145bfed3bSRichard Henderson tcg_gen_shli_tl(dst, dst, 1); 72245bfed3bSRichard Henderson } 72345bfed3bSRichard Henderson 72445bfed3bSRichard Henderson static void gen_op_array32(TCGv dst, TCGv src1, TCGv src2) 72545bfed3bSRichard Henderson { 72645bfed3bSRichard Henderson gen_helper_array8(dst, src1, src2); 72745bfed3bSRichard Henderson tcg_gen_shli_tl(dst, dst, 2); 72845bfed3bSRichard Henderson } 72945bfed3bSRichard Henderson 7302f722641SRichard Henderson static void gen_op_fpack16(TCGv_i32 dst, TCGv_i64 src) 7312f722641SRichard Henderson { 7322f722641SRichard Henderson #ifdef TARGET_SPARC64 7332f722641SRichard Henderson gen_helper_fpack16(dst, cpu_gsr, src); 7342f722641SRichard Henderson #else 7352f722641SRichard Henderson g_assert_not_reached(); 7362f722641SRichard Henderson #endif 7372f722641SRichard Henderson } 7382f722641SRichard Henderson 7392f722641SRichard Henderson static void gen_op_fpackfix(TCGv_i32 dst, TCGv_i64 src) 7402f722641SRichard Henderson { 7412f722641SRichard Henderson #ifdef TARGET_SPARC64 7422f722641SRichard Henderson gen_helper_fpackfix(dst, cpu_gsr, src); 7432f722641SRichard Henderson #else 7442f722641SRichard Henderson g_assert_not_reached(); 7452f722641SRichard Henderson #endif 7462f722641SRichard Henderson } 7472f722641SRichard Henderson 7484b6edc0aSRichard Henderson static void gen_op_fpack32(TCGv_i64 dst, TCGv_i64 src1, TCGv_i64 src2) 7494b6edc0aSRichard Henderson { 7504b6edc0aSRichard Henderson #ifdef TARGET_SPARC64 7514b6edc0aSRichard Henderson gen_helper_fpack32(dst, cpu_gsr, src1, src2); 7524b6edc0aSRichard Henderson #else 7534b6edc0aSRichard Henderson g_assert_not_reached(); 7544b6edc0aSRichard Henderson #endif 7554b6edc0aSRichard Henderson } 7564b6edc0aSRichard Henderson 7570d1d3aafSRichard Henderson static void gen_op_fpadds16s(TCGv_i32 d, TCGv_i32 src1, TCGv_i32 src2) 7580d1d3aafSRichard Henderson { 7590d1d3aafSRichard Henderson TCGv_i32 t[2]; 7600d1d3aafSRichard Henderson 7610d1d3aafSRichard Henderson for (int i = 0; i < 2; i++) { 7620d1d3aafSRichard Henderson TCGv_i32 u = tcg_temp_new_i32(); 7630d1d3aafSRichard Henderson TCGv_i32 v = tcg_temp_new_i32(); 7640d1d3aafSRichard Henderson 7650d1d3aafSRichard Henderson tcg_gen_sextract_i32(u, src1, i * 16, 16); 7660d1d3aafSRichard Henderson tcg_gen_sextract_i32(v, src2, i * 16, 16); 7670d1d3aafSRichard Henderson tcg_gen_add_i32(u, u, v); 7680d1d3aafSRichard Henderson tcg_gen_smax_i32(u, u, tcg_constant_i32(INT16_MIN)); 7690d1d3aafSRichard Henderson tcg_gen_smin_i32(u, u, tcg_constant_i32(INT16_MAX)); 7700d1d3aafSRichard Henderson t[i] = u; 7710d1d3aafSRichard Henderson } 7720d1d3aafSRichard Henderson tcg_gen_deposit_i32(d, t[0], t[1], 16, 16); 7730d1d3aafSRichard Henderson } 7740d1d3aafSRichard Henderson 7750d1d3aafSRichard Henderson static void gen_op_fpsubs16s(TCGv_i32 d, TCGv_i32 src1, TCGv_i32 src2) 7760d1d3aafSRichard Henderson { 7770d1d3aafSRichard Henderson TCGv_i32 t[2]; 7780d1d3aafSRichard Henderson 7790d1d3aafSRichard Henderson for (int i = 0; i < 2; i++) { 7800d1d3aafSRichard Henderson TCGv_i32 u = tcg_temp_new_i32(); 7810d1d3aafSRichard Henderson TCGv_i32 v = tcg_temp_new_i32(); 7820d1d3aafSRichard Henderson 7830d1d3aafSRichard Henderson tcg_gen_sextract_i32(u, src1, i * 16, 16); 7840d1d3aafSRichard Henderson tcg_gen_sextract_i32(v, src2, i * 16, 16); 7850d1d3aafSRichard Henderson tcg_gen_sub_i32(u, u, v); 7860d1d3aafSRichard Henderson tcg_gen_smax_i32(u, u, tcg_constant_i32(INT16_MIN)); 7870d1d3aafSRichard Henderson tcg_gen_smin_i32(u, u, tcg_constant_i32(INT16_MAX)); 7880d1d3aafSRichard Henderson t[i] = u; 7890d1d3aafSRichard Henderson } 7900d1d3aafSRichard Henderson tcg_gen_deposit_i32(d, t[0], t[1], 16, 16); 7910d1d3aafSRichard Henderson } 7920d1d3aafSRichard Henderson 7930d1d3aafSRichard Henderson static void gen_op_fpadds32s(TCGv_i32 d, TCGv_i32 src1, TCGv_i32 src2) 7940d1d3aafSRichard Henderson { 7950d1d3aafSRichard Henderson TCGv_i32 r = tcg_temp_new_i32(); 7960d1d3aafSRichard Henderson TCGv_i32 t = tcg_temp_new_i32(); 7970d1d3aafSRichard Henderson TCGv_i32 v = tcg_temp_new_i32(); 7980d1d3aafSRichard Henderson TCGv_i32 z = tcg_constant_i32(0); 7990d1d3aafSRichard Henderson 8000d1d3aafSRichard Henderson tcg_gen_add_i32(r, src1, src2); 8010d1d3aafSRichard Henderson tcg_gen_xor_i32(t, src1, src2); 8020d1d3aafSRichard Henderson tcg_gen_xor_i32(v, r, src2); 8030d1d3aafSRichard Henderson tcg_gen_andc_i32(v, v, t); 8040d1d3aafSRichard Henderson 8050d1d3aafSRichard Henderson tcg_gen_setcond_i32(TCG_COND_GE, t, r, z); 8060d1d3aafSRichard Henderson tcg_gen_addi_i32(t, t, INT32_MAX); 8070d1d3aafSRichard Henderson 8080d1d3aafSRichard Henderson tcg_gen_movcond_i32(TCG_COND_LT, d, v, z, t, r); 8090d1d3aafSRichard Henderson } 8100d1d3aafSRichard Henderson 8110d1d3aafSRichard Henderson static void gen_op_fpsubs32s(TCGv_i32 d, TCGv_i32 src1, TCGv_i32 src2) 8120d1d3aafSRichard Henderson { 8130d1d3aafSRichard Henderson TCGv_i32 r = tcg_temp_new_i32(); 8140d1d3aafSRichard Henderson TCGv_i32 t = tcg_temp_new_i32(); 8150d1d3aafSRichard Henderson TCGv_i32 v = tcg_temp_new_i32(); 8160d1d3aafSRichard Henderson TCGv_i32 z = tcg_constant_i32(0); 8170d1d3aafSRichard Henderson 8180d1d3aafSRichard Henderson tcg_gen_sub_i32(r, src1, src2); 8190d1d3aafSRichard Henderson tcg_gen_xor_i32(t, src1, src2); 8200d1d3aafSRichard Henderson tcg_gen_xor_i32(v, r, src1); 8210d1d3aafSRichard Henderson tcg_gen_and_i32(v, v, t); 8220d1d3aafSRichard Henderson 8230d1d3aafSRichard Henderson tcg_gen_setcond_i32(TCG_COND_GE, t, r, z); 8240d1d3aafSRichard Henderson tcg_gen_addi_i32(t, t, INT32_MAX); 8250d1d3aafSRichard Henderson 8260d1d3aafSRichard Henderson tcg_gen_movcond_i32(TCG_COND_LT, d, v, z, t, r); 8270d1d3aafSRichard Henderson } 8280d1d3aafSRichard Henderson 829b2b48493SRichard Henderson static void gen_op_faligndata_i(TCGv_i64 dst, TCGv_i64 s1, 830b2b48493SRichard Henderson TCGv_i64 s2, TCGv gsr) 8314b6edc0aSRichard Henderson { 8324b6edc0aSRichard Henderson #ifdef TARGET_SPARC64 8334b6edc0aSRichard Henderson TCGv t1, t2, shift; 8344b6edc0aSRichard Henderson 8354b6edc0aSRichard Henderson t1 = tcg_temp_new(); 8364b6edc0aSRichard Henderson t2 = tcg_temp_new(); 8374b6edc0aSRichard Henderson shift = tcg_temp_new(); 8384b6edc0aSRichard Henderson 839b2b48493SRichard Henderson tcg_gen_andi_tl(shift, gsr, 7); 8404b6edc0aSRichard Henderson tcg_gen_shli_tl(shift, shift, 3); 8414b6edc0aSRichard Henderson tcg_gen_shl_tl(t1, s1, shift); 8424b6edc0aSRichard Henderson 8434b6edc0aSRichard Henderson /* 8444b6edc0aSRichard Henderson * A shift of 64 does not produce 0 in TCG. Divide this into a 8454b6edc0aSRichard Henderson * shift of (up to 63) followed by a constant shift of 1. 8464b6edc0aSRichard Henderson */ 8474b6edc0aSRichard Henderson tcg_gen_xori_tl(shift, shift, 63); 8484b6edc0aSRichard Henderson tcg_gen_shr_tl(t2, s2, shift); 8494b6edc0aSRichard Henderson tcg_gen_shri_tl(t2, t2, 1); 8504b6edc0aSRichard Henderson 8514b6edc0aSRichard Henderson tcg_gen_or_tl(dst, t1, t2); 8524b6edc0aSRichard Henderson #else 8534b6edc0aSRichard Henderson g_assert_not_reached(); 8544b6edc0aSRichard Henderson #endif 8554b6edc0aSRichard Henderson } 8564b6edc0aSRichard Henderson 857b2b48493SRichard Henderson static void gen_op_faligndata_g(TCGv_i64 dst, TCGv_i64 s1, TCGv_i64 s2) 858b2b48493SRichard Henderson { 859b2b48493SRichard Henderson gen_op_faligndata_i(dst, s1, s2, cpu_gsr); 860b2b48493SRichard Henderson } 861b2b48493SRichard Henderson 8624b6edc0aSRichard Henderson static void gen_op_bshuffle(TCGv_i64 dst, TCGv_i64 src1, TCGv_i64 src2) 8634b6edc0aSRichard Henderson { 8644b6edc0aSRichard Henderson #ifdef TARGET_SPARC64 8654b6edc0aSRichard Henderson gen_helper_bshuffle(dst, cpu_gsr, src1, src2); 8664b6edc0aSRichard Henderson #else 8674b6edc0aSRichard Henderson g_assert_not_reached(); 8684b6edc0aSRichard Henderson #endif 8694b6edc0aSRichard Henderson } 8704b6edc0aSRichard Henderson 8717d5ebd8fSRichard Henderson static void gen_op_pdistn(TCGv dst, TCGv_i64 src1, TCGv_i64 src2) 8727d5ebd8fSRichard Henderson { 8737d5ebd8fSRichard Henderson #ifdef TARGET_SPARC64 8747d5ebd8fSRichard Henderson gen_helper_pdist(dst, tcg_constant_i64(0), src1, src2); 8757d5ebd8fSRichard Henderson #else 8767d5ebd8fSRichard Henderson g_assert_not_reached(); 8777d5ebd8fSRichard Henderson #endif 8787d5ebd8fSRichard Henderson } 8797d5ebd8fSRichard Henderson 880a859602cSRichard Henderson static void gen_op_fmul8x16al(TCGv_i64 dst, TCGv_i32 src1, TCGv_i32 src2) 881a859602cSRichard Henderson { 882a859602cSRichard Henderson tcg_gen_ext16s_i32(src2, src2); 883a859602cSRichard Henderson gen_helper_fmul8x16a(dst, src1, src2); 884a859602cSRichard Henderson } 885a859602cSRichard Henderson 886a859602cSRichard Henderson static void gen_op_fmul8x16au(TCGv_i64 dst, TCGv_i32 src1, TCGv_i32 src2) 887a859602cSRichard Henderson { 888a859602cSRichard Henderson tcg_gen_sari_i32(src2, src2, 16); 889a859602cSRichard Henderson gen_helper_fmul8x16a(dst, src1, src2); 890a859602cSRichard Henderson } 891a859602cSRichard Henderson 892be8998e0SRichard Henderson static void gen_op_fmuld8ulx16(TCGv_i64 dst, TCGv_i32 src1, TCGv_i32 src2) 893be8998e0SRichard Henderson { 894be8998e0SRichard Henderson TCGv_i32 t0 = tcg_temp_new_i32(); 895be8998e0SRichard Henderson TCGv_i32 t1 = tcg_temp_new_i32(); 896be8998e0SRichard Henderson TCGv_i32 t2 = tcg_temp_new_i32(); 897be8998e0SRichard Henderson 898be8998e0SRichard Henderson tcg_gen_ext8u_i32(t0, src1); 899be8998e0SRichard Henderson tcg_gen_ext16s_i32(t1, src2); 900be8998e0SRichard Henderson tcg_gen_mul_i32(t0, t0, t1); 901be8998e0SRichard Henderson 902be8998e0SRichard Henderson tcg_gen_extract_i32(t1, src1, 16, 8); 903be8998e0SRichard Henderson tcg_gen_sextract_i32(t2, src2, 16, 16); 904be8998e0SRichard Henderson tcg_gen_mul_i32(t1, t1, t2); 905be8998e0SRichard Henderson 906be8998e0SRichard Henderson tcg_gen_concat_i32_i64(dst, t0, t1); 907be8998e0SRichard Henderson } 908be8998e0SRichard Henderson 909be8998e0SRichard Henderson static void gen_op_fmuld8sux16(TCGv_i64 dst, TCGv_i32 src1, TCGv_i32 src2) 910be8998e0SRichard Henderson { 911be8998e0SRichard Henderson TCGv_i32 t0 = tcg_temp_new_i32(); 912be8998e0SRichard Henderson TCGv_i32 t1 = tcg_temp_new_i32(); 913be8998e0SRichard Henderson TCGv_i32 t2 = tcg_temp_new_i32(); 914be8998e0SRichard Henderson 915be8998e0SRichard Henderson /* 916be8998e0SRichard Henderson * The insn description talks about extracting the upper 8 bits 917be8998e0SRichard Henderson * of the signed 16-bit input rs1, performing the multiply, then 918be8998e0SRichard Henderson * shifting left by 8 bits. Instead, zap the lower 8 bits of 919be8998e0SRichard Henderson * the rs1 input, which avoids the need for two shifts. 920be8998e0SRichard Henderson */ 921be8998e0SRichard Henderson tcg_gen_ext16s_i32(t0, src1); 922be8998e0SRichard Henderson tcg_gen_andi_i32(t0, t0, ~0xff); 923be8998e0SRichard Henderson tcg_gen_ext16s_i32(t1, src2); 924be8998e0SRichard Henderson tcg_gen_mul_i32(t0, t0, t1); 925be8998e0SRichard Henderson 926be8998e0SRichard Henderson tcg_gen_sextract_i32(t1, src1, 16, 16); 927be8998e0SRichard Henderson tcg_gen_andi_i32(t1, t1, ~0xff); 928be8998e0SRichard Henderson tcg_gen_sextract_i32(t2, src2, 16, 16); 929be8998e0SRichard Henderson tcg_gen_mul_i32(t1, t1, t2); 930be8998e0SRichard Henderson 931be8998e0SRichard Henderson tcg_gen_concat_i32_i64(dst, t0, t1); 932be8998e0SRichard Henderson } 933be8998e0SRichard Henderson 9347837185eSRichard Henderson #ifdef TARGET_SPARC64 9357837185eSRichard Henderson static void gen_vec_fchksm16(unsigned vece, TCGv_vec dst, 9367837185eSRichard Henderson TCGv_vec src1, TCGv_vec src2) 9377837185eSRichard Henderson { 9387837185eSRichard Henderson TCGv_vec a = tcg_temp_new_vec_matching(dst); 9397837185eSRichard Henderson TCGv_vec c = tcg_temp_new_vec_matching(dst); 9407837185eSRichard Henderson 9417837185eSRichard Henderson tcg_gen_add_vec(vece, a, src1, src2); 9427837185eSRichard Henderson tcg_gen_cmp_vec(TCG_COND_LTU, vece, c, a, src1); 9437837185eSRichard Henderson /* Vector cmp produces -1 for true, so subtract to add carry. */ 9447837185eSRichard Henderson tcg_gen_sub_vec(vece, dst, a, c); 9457837185eSRichard Henderson } 9467837185eSRichard Henderson 9477837185eSRichard Henderson static void gen_op_fchksm16(unsigned vece, uint32_t dofs, uint32_t aofs, 9487837185eSRichard Henderson uint32_t bofs, uint32_t oprsz, uint32_t maxsz) 9497837185eSRichard Henderson { 9507837185eSRichard Henderson static const TCGOpcode vecop_list[] = { 9517837185eSRichard Henderson INDEX_op_cmp_vec, INDEX_op_add_vec, INDEX_op_sub_vec, 9527837185eSRichard Henderson }; 9537837185eSRichard Henderson static const GVecGen3 op = { 9547837185eSRichard Henderson .fni8 = gen_helper_fchksm16, 9557837185eSRichard Henderson .fniv = gen_vec_fchksm16, 9567837185eSRichard Henderson .opt_opc = vecop_list, 9577837185eSRichard Henderson .vece = MO_16, 9587837185eSRichard Henderson }; 9597837185eSRichard Henderson tcg_gen_gvec_3(dofs, aofs, bofs, oprsz, maxsz, &op); 9607837185eSRichard Henderson } 961d6ff1ccbSRichard Henderson 962d6ff1ccbSRichard Henderson static void gen_vec_fmean16(unsigned vece, TCGv_vec dst, 963d6ff1ccbSRichard Henderson TCGv_vec src1, TCGv_vec src2) 964d6ff1ccbSRichard Henderson { 965d6ff1ccbSRichard Henderson TCGv_vec t = tcg_temp_new_vec_matching(dst); 966d6ff1ccbSRichard Henderson 967d6ff1ccbSRichard Henderson tcg_gen_or_vec(vece, t, src1, src2); 968d6ff1ccbSRichard Henderson tcg_gen_and_vec(vece, t, t, tcg_constant_vec_matching(dst, vece, 1)); 969d6ff1ccbSRichard Henderson tcg_gen_sari_vec(vece, src1, src1, 1); 970d6ff1ccbSRichard Henderson tcg_gen_sari_vec(vece, src2, src2, 1); 971d6ff1ccbSRichard Henderson tcg_gen_add_vec(vece, dst, src1, src2); 972d6ff1ccbSRichard Henderson tcg_gen_add_vec(vece, dst, dst, t); 973d6ff1ccbSRichard Henderson } 974d6ff1ccbSRichard Henderson 975d6ff1ccbSRichard Henderson static void gen_op_fmean16(unsigned vece, uint32_t dofs, uint32_t aofs, 976d6ff1ccbSRichard Henderson uint32_t bofs, uint32_t oprsz, uint32_t maxsz) 977d6ff1ccbSRichard Henderson { 978d6ff1ccbSRichard Henderson static const TCGOpcode vecop_list[] = { 979d6ff1ccbSRichard Henderson INDEX_op_add_vec, INDEX_op_sari_vec, 980d6ff1ccbSRichard Henderson }; 981d6ff1ccbSRichard Henderson static const GVecGen3 op = { 982d6ff1ccbSRichard Henderson .fni8 = gen_helper_fmean16, 983d6ff1ccbSRichard Henderson .fniv = gen_vec_fmean16, 984d6ff1ccbSRichard Henderson .opt_opc = vecop_list, 985d6ff1ccbSRichard Henderson .vece = MO_16, 986d6ff1ccbSRichard Henderson }; 987d6ff1ccbSRichard Henderson tcg_gen_gvec_3(dofs, aofs, bofs, oprsz, maxsz, &op); 988d6ff1ccbSRichard Henderson } 9897837185eSRichard Henderson #else 9907837185eSRichard Henderson #define gen_op_fchksm16 ({ qemu_build_not_reached(); NULL; }) 991d6ff1ccbSRichard Henderson #define gen_op_fmean16 ({ qemu_build_not_reached(); NULL; }) 9927837185eSRichard Henderson #endif 9937837185eSRichard Henderson 99489527e3aSRichard Henderson static void finishing_insn(DisasContext *dc) 99589527e3aSRichard Henderson { 99689527e3aSRichard Henderson /* 99789527e3aSRichard Henderson * From here, there is no future path through an unwinding exception. 99889527e3aSRichard Henderson * If the current insn cannot raise an exception, the computation of 99989527e3aSRichard Henderson * cpu_cond may be able to be elided. 100089527e3aSRichard Henderson */ 100189527e3aSRichard Henderson if (dc->cpu_cond_live) { 100289527e3aSRichard Henderson tcg_gen_discard_tl(cpu_cond); 100389527e3aSRichard Henderson dc->cpu_cond_live = false; 100489527e3aSRichard Henderson } 100589527e3aSRichard Henderson } 100689527e3aSRichard Henderson 10070c2e96c1SRichard Henderson static void gen_generic_branch(DisasContext *dc) 1008fcf5ef2aSThomas Huth { 100900ab7e61SRichard Henderson TCGv npc0 = tcg_constant_tl(dc->jump_pc[0]); 101000ab7e61SRichard Henderson TCGv npc1 = tcg_constant_tl(dc->jump_pc[1]); 1011533f042fSRichard Henderson TCGv c2 = tcg_constant_tl(dc->jump.c2); 1012fcf5ef2aSThomas Huth 1013533f042fSRichard Henderson tcg_gen_movcond_tl(dc->jump.cond, cpu_npc, dc->jump.c1, c2, npc0, npc1); 1014fcf5ef2aSThomas Huth } 1015fcf5ef2aSThomas Huth 1016fcf5ef2aSThomas Huth /* call this function before using the condition register as it may 1017fcf5ef2aSThomas Huth have been set for a jump */ 10180c2e96c1SRichard Henderson static void flush_cond(DisasContext *dc) 1019fcf5ef2aSThomas Huth { 1020fcf5ef2aSThomas Huth if (dc->npc == JUMP_PC) { 1021fcf5ef2aSThomas Huth gen_generic_branch(dc); 102299c82c47SRichard Henderson dc->npc = DYNAMIC_PC_LOOKUP; 1023fcf5ef2aSThomas Huth } 1024fcf5ef2aSThomas Huth } 1025fcf5ef2aSThomas Huth 10260c2e96c1SRichard Henderson static void save_npc(DisasContext *dc) 1027fcf5ef2aSThomas Huth { 1028633c4283SRichard Henderson if (dc->npc & 3) { 1029633c4283SRichard Henderson switch (dc->npc) { 1030633c4283SRichard Henderson case JUMP_PC: 1031fcf5ef2aSThomas Huth gen_generic_branch(dc); 103299c82c47SRichard Henderson dc->npc = DYNAMIC_PC_LOOKUP; 1033633c4283SRichard Henderson break; 1034633c4283SRichard Henderson case DYNAMIC_PC: 1035633c4283SRichard Henderson case DYNAMIC_PC_LOOKUP: 1036633c4283SRichard Henderson break; 1037633c4283SRichard Henderson default: 1038633c4283SRichard Henderson g_assert_not_reached(); 1039633c4283SRichard Henderson } 1040633c4283SRichard Henderson } else { 1041fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_npc, dc->npc); 1042fcf5ef2aSThomas Huth } 1043fcf5ef2aSThomas Huth } 1044fcf5ef2aSThomas Huth 10450c2e96c1SRichard Henderson static void save_state(DisasContext *dc) 1046fcf5ef2aSThomas Huth { 1047fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_pc, dc->pc); 1048fcf5ef2aSThomas Huth save_npc(dc); 1049fcf5ef2aSThomas Huth } 1050fcf5ef2aSThomas Huth 1051fcf5ef2aSThomas Huth static void gen_exception(DisasContext *dc, int which) 1052fcf5ef2aSThomas Huth { 105389527e3aSRichard Henderson finishing_insn(dc); 1054fcf5ef2aSThomas Huth save_state(dc); 1055ad75a51eSRichard Henderson gen_helper_raise_exception(tcg_env, tcg_constant_i32(which)); 1056af00be49SEmilio G. Cota dc->base.is_jmp = DISAS_NORETURN; 1057fcf5ef2aSThomas Huth } 1058fcf5ef2aSThomas Huth 1059186e7890SRichard Henderson static TCGLabel *delay_exceptionv(DisasContext *dc, TCGv_i32 excp) 1060fcf5ef2aSThomas Huth { 1061186e7890SRichard Henderson DisasDelayException *e = g_new0(DisasDelayException, 1); 1062186e7890SRichard Henderson 1063186e7890SRichard Henderson e->next = dc->delay_excp_list; 1064186e7890SRichard Henderson dc->delay_excp_list = e; 1065186e7890SRichard Henderson 1066186e7890SRichard Henderson e->lab = gen_new_label(); 1067186e7890SRichard Henderson e->excp = excp; 1068186e7890SRichard Henderson e->pc = dc->pc; 1069186e7890SRichard Henderson /* Caller must have used flush_cond before branch. */ 1070186e7890SRichard Henderson assert(e->npc != JUMP_PC); 1071186e7890SRichard Henderson e->npc = dc->npc; 1072186e7890SRichard Henderson 1073186e7890SRichard Henderson return e->lab; 1074186e7890SRichard Henderson } 1075186e7890SRichard Henderson 1076186e7890SRichard Henderson static TCGLabel *delay_exception(DisasContext *dc, int excp) 1077186e7890SRichard Henderson { 1078186e7890SRichard Henderson return delay_exceptionv(dc, tcg_constant_i32(excp)); 1079186e7890SRichard Henderson } 1080186e7890SRichard Henderson 1081186e7890SRichard Henderson static void gen_check_align(DisasContext *dc, TCGv addr, int mask) 1082186e7890SRichard Henderson { 1083186e7890SRichard Henderson TCGv t = tcg_temp_new(); 1084186e7890SRichard Henderson TCGLabel *lab; 1085186e7890SRichard Henderson 1086186e7890SRichard Henderson tcg_gen_andi_tl(t, addr, mask); 1087186e7890SRichard Henderson 1088186e7890SRichard Henderson flush_cond(dc); 1089186e7890SRichard Henderson lab = delay_exception(dc, TT_UNALIGNED); 1090186e7890SRichard Henderson tcg_gen_brcondi_tl(TCG_COND_NE, t, 0, lab); 1091fcf5ef2aSThomas Huth } 1092fcf5ef2aSThomas Huth 10930c2e96c1SRichard Henderson static void gen_mov_pc_npc(DisasContext *dc) 1094fcf5ef2aSThomas Huth { 109589527e3aSRichard Henderson finishing_insn(dc); 109689527e3aSRichard Henderson 1097633c4283SRichard Henderson if (dc->npc & 3) { 1098633c4283SRichard Henderson switch (dc->npc) { 1099633c4283SRichard Henderson case JUMP_PC: 1100fcf5ef2aSThomas Huth gen_generic_branch(dc); 1101fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_pc, cpu_npc); 110299c82c47SRichard Henderson dc->pc = DYNAMIC_PC_LOOKUP; 1103633c4283SRichard Henderson break; 1104633c4283SRichard Henderson case DYNAMIC_PC: 1105633c4283SRichard Henderson case DYNAMIC_PC_LOOKUP: 1106fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_pc, cpu_npc); 1107633c4283SRichard Henderson dc->pc = dc->npc; 1108633c4283SRichard Henderson break; 1109633c4283SRichard Henderson default: 1110633c4283SRichard Henderson g_assert_not_reached(); 1111633c4283SRichard Henderson } 1112fcf5ef2aSThomas Huth } else { 1113fcf5ef2aSThomas Huth dc->pc = dc->npc; 1114fcf5ef2aSThomas Huth } 1115fcf5ef2aSThomas Huth } 1116fcf5ef2aSThomas Huth 1117fcf5ef2aSThomas Huth static void gen_compare(DisasCompare *cmp, bool xcc, unsigned int cond, 1118fcf5ef2aSThomas Huth DisasContext *dc) 1119fcf5ef2aSThomas Huth { 1120b597eedcSRichard Henderson TCGv t1; 1121fcf5ef2aSThomas Huth 11222a1905c7SRichard Henderson cmp->c1 = t1 = tcg_temp_new(); 1123c8507ebfSRichard Henderson cmp->c2 = 0; 11242a1905c7SRichard Henderson 11252a1905c7SRichard Henderson switch (cond & 7) { 11262a1905c7SRichard Henderson case 0x0: /* never */ 11272a1905c7SRichard Henderson cmp->cond = TCG_COND_NEVER; 1128c8507ebfSRichard Henderson cmp->c1 = tcg_constant_tl(0); 1129fcf5ef2aSThomas Huth break; 11302a1905c7SRichard Henderson 11312a1905c7SRichard Henderson case 0x1: /* eq: Z */ 11322a1905c7SRichard Henderson cmp->cond = TCG_COND_EQ; 11332a1905c7SRichard Henderson if (TARGET_LONG_BITS == 32 || xcc) { 11342a1905c7SRichard Henderson tcg_gen_mov_tl(t1, cpu_cc_Z); 11352a1905c7SRichard Henderson } else { 11362a1905c7SRichard Henderson tcg_gen_ext32u_tl(t1, cpu_icc_Z); 11372a1905c7SRichard Henderson } 11382a1905c7SRichard Henderson break; 11392a1905c7SRichard Henderson 11402a1905c7SRichard Henderson case 0x2: /* le: Z | (N ^ V) */ 11412a1905c7SRichard Henderson /* 11422a1905c7SRichard Henderson * Simplify: 11432a1905c7SRichard Henderson * cc_Z || (N ^ V) < 0 NE 11442a1905c7SRichard Henderson * cc_Z && !((N ^ V) < 0) EQ 11452a1905c7SRichard Henderson * cc_Z & ~((N ^ V) >> TLB) EQ 11462a1905c7SRichard Henderson */ 11472a1905c7SRichard Henderson cmp->cond = TCG_COND_EQ; 11482a1905c7SRichard Henderson tcg_gen_xor_tl(t1, cpu_cc_N, cpu_cc_V); 11492a1905c7SRichard Henderson tcg_gen_sextract_tl(t1, t1, xcc ? 63 : 31, 1); 11502a1905c7SRichard Henderson tcg_gen_andc_tl(t1, xcc ? cpu_cc_Z : cpu_icc_Z, t1); 11512a1905c7SRichard Henderson if (TARGET_LONG_BITS == 64 && !xcc) { 11522a1905c7SRichard Henderson tcg_gen_ext32u_tl(t1, t1); 11532a1905c7SRichard Henderson } 11542a1905c7SRichard Henderson break; 11552a1905c7SRichard Henderson 11562a1905c7SRichard Henderson case 0x3: /* lt: N ^ V */ 11572a1905c7SRichard Henderson cmp->cond = TCG_COND_LT; 11582a1905c7SRichard Henderson tcg_gen_xor_tl(t1, cpu_cc_N, cpu_cc_V); 11592a1905c7SRichard Henderson if (TARGET_LONG_BITS == 64 && !xcc) { 11602a1905c7SRichard Henderson tcg_gen_ext32s_tl(t1, t1); 11612a1905c7SRichard Henderson } 11622a1905c7SRichard Henderson break; 11632a1905c7SRichard Henderson 11642a1905c7SRichard Henderson case 0x4: /* leu: Z | C */ 11652a1905c7SRichard Henderson /* 11662a1905c7SRichard Henderson * Simplify: 11672a1905c7SRichard Henderson * cc_Z == 0 || cc_C != 0 NE 11682a1905c7SRichard Henderson * cc_Z != 0 && cc_C == 0 EQ 11692a1905c7SRichard Henderson * cc_Z & (cc_C ? 0 : -1) EQ 11702a1905c7SRichard Henderson * cc_Z & (cc_C - 1) EQ 11712a1905c7SRichard Henderson */ 11722a1905c7SRichard Henderson cmp->cond = TCG_COND_EQ; 11732a1905c7SRichard Henderson if (TARGET_LONG_BITS == 32 || xcc) { 11742a1905c7SRichard Henderson tcg_gen_subi_tl(t1, cpu_cc_C, 1); 11752a1905c7SRichard Henderson tcg_gen_and_tl(t1, t1, cpu_cc_Z); 11762a1905c7SRichard Henderson } else { 11772a1905c7SRichard Henderson tcg_gen_extract_tl(t1, cpu_icc_C, 32, 1); 11782a1905c7SRichard Henderson tcg_gen_subi_tl(t1, t1, 1); 11792a1905c7SRichard Henderson tcg_gen_and_tl(t1, t1, cpu_icc_Z); 11802a1905c7SRichard Henderson tcg_gen_ext32u_tl(t1, t1); 11812a1905c7SRichard Henderson } 11822a1905c7SRichard Henderson break; 11832a1905c7SRichard Henderson 11842a1905c7SRichard Henderson case 0x5: /* ltu: C */ 11852a1905c7SRichard Henderson cmp->cond = TCG_COND_NE; 11862a1905c7SRichard Henderson if (TARGET_LONG_BITS == 32 || xcc) { 11872a1905c7SRichard Henderson tcg_gen_mov_tl(t1, cpu_cc_C); 11882a1905c7SRichard Henderson } else { 11892a1905c7SRichard Henderson tcg_gen_extract_tl(t1, cpu_icc_C, 32, 1); 11902a1905c7SRichard Henderson } 11912a1905c7SRichard Henderson break; 11922a1905c7SRichard Henderson 11932a1905c7SRichard Henderson case 0x6: /* neg: N */ 11942a1905c7SRichard Henderson cmp->cond = TCG_COND_LT; 11952a1905c7SRichard Henderson if (TARGET_LONG_BITS == 32 || xcc) { 11962a1905c7SRichard Henderson tcg_gen_mov_tl(t1, cpu_cc_N); 11972a1905c7SRichard Henderson } else { 11982a1905c7SRichard Henderson tcg_gen_ext32s_tl(t1, cpu_cc_N); 11992a1905c7SRichard Henderson } 12002a1905c7SRichard Henderson break; 12012a1905c7SRichard Henderson 12022a1905c7SRichard Henderson case 0x7: /* vs: V */ 12032a1905c7SRichard Henderson cmp->cond = TCG_COND_LT; 12042a1905c7SRichard Henderson if (TARGET_LONG_BITS == 32 || xcc) { 12052a1905c7SRichard Henderson tcg_gen_mov_tl(t1, cpu_cc_V); 12062a1905c7SRichard Henderson } else { 12072a1905c7SRichard Henderson tcg_gen_ext32s_tl(t1, cpu_cc_V); 12082a1905c7SRichard Henderson } 12092a1905c7SRichard Henderson break; 12102a1905c7SRichard Henderson } 12112a1905c7SRichard Henderson if (cond & 8) { 12122a1905c7SRichard Henderson cmp->cond = tcg_invert_cond(cmp->cond); 1213fcf5ef2aSThomas Huth } 1214fcf5ef2aSThomas Huth } 1215fcf5ef2aSThomas Huth 1216fcf5ef2aSThomas Huth static void gen_fcompare(DisasCompare *cmp, unsigned int cc, unsigned int cond) 1217fcf5ef2aSThomas Huth { 1218d8c5b92fSRichard Henderson TCGv_i32 fcc = cpu_fcc[cc]; 1219d8c5b92fSRichard Henderson TCGv_i32 c1 = fcc; 1220d8c5b92fSRichard Henderson int c2 = 0; 1221d8c5b92fSRichard Henderson TCGCond tcond; 1222fcf5ef2aSThomas Huth 1223d8c5b92fSRichard Henderson /* 1224d8c5b92fSRichard Henderson * FCC values: 1225d8c5b92fSRichard Henderson * 0 = 1226d8c5b92fSRichard Henderson * 1 < 1227d8c5b92fSRichard Henderson * 2 > 1228d8c5b92fSRichard Henderson * 3 unordered 1229d8c5b92fSRichard Henderson */ 1230d8c5b92fSRichard Henderson switch (cond & 7) { 1231d8c5b92fSRichard Henderson case 0x0: /* fbn */ 1232d8c5b92fSRichard Henderson tcond = TCG_COND_NEVER; 1233fcf5ef2aSThomas Huth break; 1234d8c5b92fSRichard Henderson case 0x1: /* fbne : !0 */ 1235d8c5b92fSRichard Henderson tcond = TCG_COND_NE; 1236fcf5ef2aSThomas Huth break; 1237d8c5b92fSRichard Henderson case 0x2: /* fblg : 1 or 2 */ 1238d8c5b92fSRichard Henderson /* fcc in {1,2} - 1 -> fcc in {0,1} */ 1239d8c5b92fSRichard Henderson c1 = tcg_temp_new_i32(); 1240d8c5b92fSRichard Henderson tcg_gen_addi_i32(c1, fcc, -1); 1241d8c5b92fSRichard Henderson c2 = 1; 1242d8c5b92fSRichard Henderson tcond = TCG_COND_LEU; 1243fcf5ef2aSThomas Huth break; 1244d8c5b92fSRichard Henderson case 0x3: /* fbul : 1 or 3 */ 1245d8c5b92fSRichard Henderson c1 = tcg_temp_new_i32(); 1246d8c5b92fSRichard Henderson tcg_gen_andi_i32(c1, fcc, 1); 1247d8c5b92fSRichard Henderson tcond = TCG_COND_NE; 1248d8c5b92fSRichard Henderson break; 1249d8c5b92fSRichard Henderson case 0x4: /* fbl : 1 */ 1250d8c5b92fSRichard Henderson c2 = 1; 1251d8c5b92fSRichard Henderson tcond = TCG_COND_EQ; 1252d8c5b92fSRichard Henderson break; 1253d8c5b92fSRichard Henderson case 0x5: /* fbug : 2 or 3 */ 1254d8c5b92fSRichard Henderson c2 = 2; 1255d8c5b92fSRichard Henderson tcond = TCG_COND_GEU; 1256d8c5b92fSRichard Henderson break; 1257d8c5b92fSRichard Henderson case 0x6: /* fbg : 2 */ 1258d8c5b92fSRichard Henderson c2 = 2; 1259d8c5b92fSRichard Henderson tcond = TCG_COND_EQ; 1260d8c5b92fSRichard Henderson break; 1261d8c5b92fSRichard Henderson case 0x7: /* fbu : 3 */ 1262d8c5b92fSRichard Henderson c2 = 3; 1263d8c5b92fSRichard Henderson tcond = TCG_COND_EQ; 1264fcf5ef2aSThomas Huth break; 1265fcf5ef2aSThomas Huth } 1266d8c5b92fSRichard Henderson if (cond & 8) { 1267d8c5b92fSRichard Henderson tcond = tcg_invert_cond(tcond); 1268fcf5ef2aSThomas Huth } 1269d8c5b92fSRichard Henderson 1270d8c5b92fSRichard Henderson cmp->cond = tcond; 1271d8c5b92fSRichard Henderson cmp->c2 = c2; 1272d8c5b92fSRichard Henderson cmp->c1 = tcg_temp_new(); 1273d8c5b92fSRichard Henderson tcg_gen_extu_i32_tl(cmp->c1, c1); 1274fcf5ef2aSThomas Huth } 1275fcf5ef2aSThomas Huth 12762c4f56c9SRichard Henderson static bool gen_compare_reg(DisasCompare *cmp, int cond, TCGv r_src) 12772c4f56c9SRichard Henderson { 12782c4f56c9SRichard Henderson static const TCGCond cond_reg[4] = { 1279ab9ffe98SRichard Henderson TCG_COND_NEVER, /* reserved */ 1280fcf5ef2aSThomas Huth TCG_COND_EQ, 1281fcf5ef2aSThomas Huth TCG_COND_LE, 1282fcf5ef2aSThomas Huth TCG_COND_LT, 1283fcf5ef2aSThomas Huth }; 12842c4f56c9SRichard Henderson TCGCond tcond; 1285fcf5ef2aSThomas Huth 12862c4f56c9SRichard Henderson if ((cond & 3) == 0) { 12872c4f56c9SRichard Henderson return false; 12882c4f56c9SRichard Henderson } 12892c4f56c9SRichard Henderson tcond = cond_reg[cond & 3]; 12902c4f56c9SRichard Henderson if (cond & 4) { 12912c4f56c9SRichard Henderson tcond = tcg_invert_cond(tcond); 12922c4f56c9SRichard Henderson } 12932c4f56c9SRichard Henderson 12942c4f56c9SRichard Henderson cmp->cond = tcond; 1295816f89b7SRichard Henderson cmp->c1 = tcg_temp_new(); 1296c8507ebfSRichard Henderson cmp->c2 = 0; 1297816f89b7SRichard Henderson tcg_gen_mov_tl(cmp->c1, r_src); 12982c4f56c9SRichard Henderson return true; 1299fcf5ef2aSThomas Huth } 1300fcf5ef2aSThomas Huth 1301baf3dbf2SRichard Henderson static void gen_op_clear_ieee_excp_and_FTT(void) 1302baf3dbf2SRichard Henderson { 13033590f01eSRichard Henderson tcg_gen_st_i32(tcg_constant_i32(0), tcg_env, 13043590f01eSRichard Henderson offsetof(CPUSPARCState, fsr_cexc_ftt)); 1305baf3dbf2SRichard Henderson } 1306baf3dbf2SRichard Henderson 1307baf3dbf2SRichard Henderson static void gen_op_fmovs(TCGv_i32 dst, TCGv_i32 src) 1308baf3dbf2SRichard Henderson { 1309baf3dbf2SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 1310baf3dbf2SRichard Henderson tcg_gen_mov_i32(dst, src); 1311baf3dbf2SRichard Henderson } 1312baf3dbf2SRichard Henderson 1313baf3dbf2SRichard Henderson static void gen_op_fnegs(TCGv_i32 dst, TCGv_i32 src) 1314baf3dbf2SRichard Henderson { 1315baf3dbf2SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 1316daf457d4SRichard Henderson tcg_gen_xori_i32(dst, src, 1u << 31); 1317baf3dbf2SRichard Henderson } 1318baf3dbf2SRichard Henderson 1319baf3dbf2SRichard Henderson static void gen_op_fabss(TCGv_i32 dst, TCGv_i32 src) 1320baf3dbf2SRichard Henderson { 1321baf3dbf2SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 1322daf457d4SRichard Henderson tcg_gen_andi_i32(dst, src, ~(1u << 31)); 1323baf3dbf2SRichard Henderson } 1324baf3dbf2SRichard Henderson 1325c6d83e4fSRichard Henderson static void gen_op_fmovd(TCGv_i64 dst, TCGv_i64 src) 1326c6d83e4fSRichard Henderson { 1327c6d83e4fSRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 1328c6d83e4fSRichard Henderson tcg_gen_mov_i64(dst, src); 1329c6d83e4fSRichard Henderson } 1330c6d83e4fSRichard Henderson 1331c6d83e4fSRichard Henderson static void gen_op_fnegd(TCGv_i64 dst, TCGv_i64 src) 1332c6d83e4fSRichard Henderson { 1333c6d83e4fSRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 1334daf457d4SRichard Henderson tcg_gen_xori_i64(dst, src, 1ull << 63); 1335c6d83e4fSRichard Henderson } 1336c6d83e4fSRichard Henderson 1337c6d83e4fSRichard Henderson static void gen_op_fabsd(TCGv_i64 dst, TCGv_i64 src) 1338c6d83e4fSRichard Henderson { 1339c6d83e4fSRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 1340daf457d4SRichard Henderson tcg_gen_andi_i64(dst, src, ~(1ull << 63)); 1341daf457d4SRichard Henderson } 1342daf457d4SRichard Henderson 1343daf457d4SRichard Henderson static void gen_op_fnegq(TCGv_i128 dst, TCGv_i128 src) 1344daf457d4SRichard Henderson { 1345daf457d4SRichard Henderson TCGv_i64 l = tcg_temp_new_i64(); 1346daf457d4SRichard Henderson TCGv_i64 h = tcg_temp_new_i64(); 1347daf457d4SRichard Henderson 1348daf457d4SRichard Henderson tcg_gen_extr_i128_i64(l, h, src); 1349daf457d4SRichard Henderson tcg_gen_xori_i64(h, h, 1ull << 63); 1350daf457d4SRichard Henderson tcg_gen_concat_i64_i128(dst, l, h); 1351daf457d4SRichard Henderson } 1352daf457d4SRichard Henderson 1353daf457d4SRichard Henderson static void gen_op_fabsq(TCGv_i128 dst, TCGv_i128 src) 1354daf457d4SRichard Henderson { 1355daf457d4SRichard Henderson TCGv_i64 l = tcg_temp_new_i64(); 1356daf457d4SRichard Henderson TCGv_i64 h = tcg_temp_new_i64(); 1357daf457d4SRichard Henderson 1358daf457d4SRichard Henderson tcg_gen_extr_i128_i64(l, h, src); 1359daf457d4SRichard Henderson tcg_gen_andi_i64(h, h, ~(1ull << 63)); 1360daf457d4SRichard Henderson tcg_gen_concat_i64_i128(dst, l, h); 1361c6d83e4fSRichard Henderson } 1362c6d83e4fSRichard Henderson 13634fd71d19SRichard Henderson static void gen_op_fmadds(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2, TCGv_i32 s3) 13644fd71d19SRichard Henderson { 13654fd71d19SRichard Henderson gen_helper_fmadds(d, tcg_env, s1, s2, s3, tcg_constant_i32(0)); 13664fd71d19SRichard Henderson } 13674fd71d19SRichard Henderson 13684fd71d19SRichard Henderson static void gen_op_fmaddd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2, TCGv_i64 s3) 13694fd71d19SRichard Henderson { 13704fd71d19SRichard Henderson gen_helper_fmaddd(d, tcg_env, s1, s2, s3, tcg_constant_i32(0)); 13714fd71d19SRichard Henderson } 13724fd71d19SRichard Henderson 13734fd71d19SRichard Henderson static void gen_op_fmsubs(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2, TCGv_i32 s3) 13744fd71d19SRichard Henderson { 13754fd71d19SRichard Henderson int op = float_muladd_negate_c; 13764fd71d19SRichard Henderson gen_helper_fmadds(d, tcg_env, s1, s2, s3, tcg_constant_i32(op)); 13774fd71d19SRichard Henderson } 13784fd71d19SRichard Henderson 13794fd71d19SRichard Henderson static void gen_op_fmsubd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2, TCGv_i64 s3) 13804fd71d19SRichard Henderson { 13814fd71d19SRichard Henderson int op = float_muladd_negate_c; 13824fd71d19SRichard Henderson gen_helper_fmaddd(d, tcg_env, s1, s2, s3, tcg_constant_i32(op)); 13834fd71d19SRichard Henderson } 13844fd71d19SRichard Henderson 13854fd71d19SRichard Henderson static void gen_op_fnmsubs(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2, TCGv_i32 s3) 13864fd71d19SRichard Henderson { 13874fd71d19SRichard Henderson int op = float_muladd_negate_c | float_muladd_negate_result; 13884fd71d19SRichard Henderson gen_helper_fmadds(d, tcg_env, s1, s2, s3, tcg_constant_i32(op)); 13894fd71d19SRichard Henderson } 13904fd71d19SRichard Henderson 13914fd71d19SRichard Henderson static void gen_op_fnmsubd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2, TCGv_i64 s3) 13924fd71d19SRichard Henderson { 13934fd71d19SRichard Henderson int op = float_muladd_negate_c | float_muladd_negate_result; 13944fd71d19SRichard Henderson gen_helper_fmaddd(d, tcg_env, s1, s2, s3, tcg_constant_i32(op)); 13954fd71d19SRichard Henderson } 13964fd71d19SRichard Henderson 13974fd71d19SRichard Henderson static void gen_op_fnmadds(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2, TCGv_i32 s3) 13984fd71d19SRichard Henderson { 13994fd71d19SRichard Henderson int op = float_muladd_negate_result; 14004fd71d19SRichard Henderson gen_helper_fmadds(d, tcg_env, s1, s2, s3, tcg_constant_i32(op)); 14014fd71d19SRichard Henderson } 14024fd71d19SRichard Henderson 14034fd71d19SRichard Henderson static void gen_op_fnmaddd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2, TCGv_i64 s3) 14044fd71d19SRichard Henderson { 14054fd71d19SRichard Henderson int op = float_muladd_negate_result; 14064fd71d19SRichard Henderson gen_helper_fmaddd(d, tcg_env, s1, s2, s3, tcg_constant_i32(op)); 14074fd71d19SRichard Henderson } 14084fd71d19SRichard Henderson 14093d50b728SRichard Henderson /* Use muladd to compute (1 * src1) + src2 / 2 with one rounding. */ 14103d50b728SRichard Henderson static void gen_op_fhadds(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2) 14113d50b728SRichard Henderson { 14123d50b728SRichard Henderson TCGv_i32 one = tcg_constant_i32(float32_one); 14133d50b728SRichard Henderson int op = float_muladd_halve_result; 14143d50b728SRichard Henderson gen_helper_fmadds(d, tcg_env, one, s1, s2, tcg_constant_i32(op)); 14153d50b728SRichard Henderson } 14163d50b728SRichard Henderson 14173d50b728SRichard Henderson static void gen_op_fhaddd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2) 14183d50b728SRichard Henderson { 14193d50b728SRichard Henderson TCGv_i64 one = tcg_constant_i64(float64_one); 14203d50b728SRichard Henderson int op = float_muladd_halve_result; 14213d50b728SRichard Henderson gen_helper_fmaddd(d, tcg_env, one, s1, s2, tcg_constant_i32(op)); 14223d50b728SRichard Henderson } 14233d50b728SRichard Henderson 14243d50b728SRichard Henderson /* Use muladd to compute (1 * src1) - src2 / 2 with one rounding. */ 14253d50b728SRichard Henderson static void gen_op_fhsubs(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2) 14263d50b728SRichard Henderson { 14273d50b728SRichard Henderson TCGv_i32 one = tcg_constant_i32(float32_one); 14283d50b728SRichard Henderson int op = float_muladd_negate_c | float_muladd_halve_result; 14293d50b728SRichard Henderson gen_helper_fmadds(d, tcg_env, one, s1, s2, tcg_constant_i32(op)); 14303d50b728SRichard Henderson } 14313d50b728SRichard Henderson 14323d50b728SRichard Henderson static void gen_op_fhsubd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2) 14333d50b728SRichard Henderson { 14343d50b728SRichard Henderson TCGv_i64 one = tcg_constant_i64(float64_one); 14353d50b728SRichard Henderson int op = float_muladd_negate_c | float_muladd_halve_result; 14363d50b728SRichard Henderson gen_helper_fmaddd(d, tcg_env, one, s1, s2, tcg_constant_i32(op)); 14373d50b728SRichard Henderson } 14383d50b728SRichard Henderson 14393d50b728SRichard Henderson /* Use muladd to compute -((1 * src1) + src2 / 2) with one rounding. */ 14403d50b728SRichard Henderson static void gen_op_fnhadds(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2) 14413d50b728SRichard Henderson { 14423d50b728SRichard Henderson TCGv_i32 one = tcg_constant_i32(float32_one); 14433d50b728SRichard Henderson int op = float_muladd_negate_result | float_muladd_halve_result; 14443d50b728SRichard Henderson gen_helper_fmadds(d, tcg_env, one, s1, s2, tcg_constant_i32(op)); 14453d50b728SRichard Henderson } 14463d50b728SRichard Henderson 14473d50b728SRichard Henderson static void gen_op_fnhaddd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2) 14483d50b728SRichard Henderson { 14493d50b728SRichard Henderson TCGv_i64 one = tcg_constant_i64(float64_one); 14503d50b728SRichard Henderson int op = float_muladd_negate_result | float_muladd_halve_result; 14513d50b728SRichard Henderson gen_helper_fmaddd(d, tcg_env, one, s1, s2, tcg_constant_i32(op)); 14523d50b728SRichard Henderson } 14533d50b728SRichard Henderson 14543590f01eSRichard Henderson static void gen_op_fpexception_im(DisasContext *dc, int ftt) 1455fcf5ef2aSThomas Huth { 14563590f01eSRichard Henderson /* 14573590f01eSRichard Henderson * CEXC is only set when succesfully completing an FPop, 14583590f01eSRichard Henderson * or when raising FSR_FTT_IEEE_EXCP, i.e. check_ieee_exception. 14593590f01eSRichard Henderson * Thus we can simply store FTT into this field. 14603590f01eSRichard Henderson */ 14613590f01eSRichard Henderson tcg_gen_st_i32(tcg_constant_i32(ftt), tcg_env, 14623590f01eSRichard Henderson offsetof(CPUSPARCState, fsr_cexc_ftt)); 1463fcf5ef2aSThomas Huth gen_exception(dc, TT_FP_EXCP); 1464fcf5ef2aSThomas Huth } 1465fcf5ef2aSThomas Huth 1466fcf5ef2aSThomas Huth static int gen_trap_ifnofpu(DisasContext *dc) 1467fcf5ef2aSThomas Huth { 1468fcf5ef2aSThomas Huth #if !defined(CONFIG_USER_ONLY) 1469fcf5ef2aSThomas Huth if (!dc->fpu_enabled) { 1470fcf5ef2aSThomas Huth gen_exception(dc, TT_NFPU_INSN); 1471fcf5ef2aSThomas Huth return 1; 1472fcf5ef2aSThomas Huth } 1473fcf5ef2aSThomas Huth #endif 1474fcf5ef2aSThomas Huth return 0; 1475fcf5ef2aSThomas Huth } 1476fcf5ef2aSThomas Huth 1477fcf5ef2aSThomas Huth /* asi moves */ 1478fcf5ef2aSThomas Huth typedef enum { 1479fcf5ef2aSThomas Huth GET_ASI_HELPER, 1480fcf5ef2aSThomas Huth GET_ASI_EXCP, 1481fcf5ef2aSThomas Huth GET_ASI_DIRECT, 1482fcf5ef2aSThomas Huth GET_ASI_DTWINX, 14832786a3f8SRichard Henderson GET_ASI_CODE, 1484fcf5ef2aSThomas Huth GET_ASI_BLOCK, 1485fcf5ef2aSThomas Huth GET_ASI_SHORT, 1486fcf5ef2aSThomas Huth GET_ASI_BCOPY, 1487fcf5ef2aSThomas Huth GET_ASI_BFILL, 1488fcf5ef2aSThomas Huth } ASIType; 1489fcf5ef2aSThomas Huth 1490fcf5ef2aSThomas Huth typedef struct { 1491fcf5ef2aSThomas Huth ASIType type; 1492fcf5ef2aSThomas Huth int asi; 1493fcf5ef2aSThomas Huth int mem_idx; 149414776ab5STony Nguyen MemOp memop; 1495fcf5ef2aSThomas Huth } DisasASI; 1496fcf5ef2aSThomas Huth 1497811cc0b0SRichard Henderson /* 1498811cc0b0SRichard Henderson * Build DisasASI. 1499811cc0b0SRichard Henderson * For asi == -1, treat as non-asi. 1500811cc0b0SRichard Henderson * For ask == -2, treat as immediate offset (v8 error, v9 %asi). 1501811cc0b0SRichard Henderson */ 1502811cc0b0SRichard Henderson static DisasASI resolve_asi(DisasContext *dc, int asi, MemOp memop) 1503fcf5ef2aSThomas Huth { 1504fcf5ef2aSThomas Huth ASIType type = GET_ASI_HELPER; 1505fcf5ef2aSThomas Huth int mem_idx = dc->mem_idx; 1506fcf5ef2aSThomas Huth 1507811cc0b0SRichard Henderson if (asi == -1) { 1508811cc0b0SRichard Henderson /* Artificial "non-asi" case. */ 1509811cc0b0SRichard Henderson type = GET_ASI_DIRECT; 1510811cc0b0SRichard Henderson goto done; 1511811cc0b0SRichard Henderson } 1512811cc0b0SRichard Henderson 1513fcf5ef2aSThomas Huth #ifndef TARGET_SPARC64 1514fcf5ef2aSThomas Huth /* Before v9, all asis are immediate and privileged. */ 1515811cc0b0SRichard Henderson if (asi < 0) { 1516fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 1517fcf5ef2aSThomas Huth type = GET_ASI_EXCP; 1518fcf5ef2aSThomas Huth } else if (supervisor(dc) 1519fcf5ef2aSThomas Huth /* Note that LEON accepts ASI_USERDATA in user mode, for 1520fcf5ef2aSThomas Huth use with CASA. Also note that previous versions of 1521fcf5ef2aSThomas Huth QEMU allowed (and old versions of gcc emitted) ASI_P 1522fcf5ef2aSThomas Huth for LEON, which is incorrect. */ 1523fcf5ef2aSThomas Huth || (asi == ASI_USERDATA 1524fcf5ef2aSThomas Huth && (dc->def->features & CPU_FEATURE_CASA))) { 1525fcf5ef2aSThomas Huth switch (asi) { 1526fcf5ef2aSThomas Huth case ASI_USERDATA: /* User data access */ 1527fcf5ef2aSThomas Huth mem_idx = MMU_USER_IDX; 1528fcf5ef2aSThomas Huth type = GET_ASI_DIRECT; 1529fcf5ef2aSThomas Huth break; 1530fcf5ef2aSThomas Huth case ASI_KERNELDATA: /* Supervisor data access */ 1531fcf5ef2aSThomas Huth mem_idx = MMU_KERNEL_IDX; 1532fcf5ef2aSThomas Huth type = GET_ASI_DIRECT; 1533fcf5ef2aSThomas Huth break; 15342786a3f8SRichard Henderson case ASI_USERTXT: /* User text access */ 15352786a3f8SRichard Henderson mem_idx = MMU_USER_IDX; 15362786a3f8SRichard Henderson type = GET_ASI_CODE; 15372786a3f8SRichard Henderson break; 15382786a3f8SRichard Henderson case ASI_KERNELTXT: /* Supervisor text access */ 15392786a3f8SRichard Henderson mem_idx = MMU_KERNEL_IDX; 15402786a3f8SRichard Henderson type = GET_ASI_CODE; 15412786a3f8SRichard Henderson break; 1542fcf5ef2aSThomas Huth case ASI_M_BYPASS: /* MMU passthrough */ 1543fcf5ef2aSThomas Huth case ASI_LEON_BYPASS: /* LEON MMU passthrough */ 1544fcf5ef2aSThomas Huth mem_idx = MMU_PHYS_IDX; 1545fcf5ef2aSThomas Huth type = GET_ASI_DIRECT; 1546fcf5ef2aSThomas Huth break; 1547fcf5ef2aSThomas Huth case ASI_M_BCOPY: /* Block copy, sta access */ 1548fcf5ef2aSThomas Huth mem_idx = MMU_KERNEL_IDX; 1549fcf5ef2aSThomas Huth type = GET_ASI_BCOPY; 1550fcf5ef2aSThomas Huth break; 1551fcf5ef2aSThomas Huth case ASI_M_BFILL: /* Block fill, stda access */ 1552fcf5ef2aSThomas Huth mem_idx = MMU_KERNEL_IDX; 1553fcf5ef2aSThomas Huth type = GET_ASI_BFILL; 1554fcf5ef2aSThomas Huth break; 1555fcf5ef2aSThomas Huth } 15566e10f37cSKONRAD Frederic 15576e10f37cSKONRAD Frederic /* MMU_PHYS_IDX is used when the MMU is disabled to passthrough the 15586e10f37cSKONRAD Frederic * permissions check in get_physical_address(..). 15596e10f37cSKONRAD Frederic */ 15606e10f37cSKONRAD Frederic mem_idx = (dc->mem_idx == MMU_PHYS_IDX) ? MMU_PHYS_IDX : mem_idx; 1561fcf5ef2aSThomas Huth } else { 1562fcf5ef2aSThomas Huth gen_exception(dc, TT_PRIV_INSN); 1563fcf5ef2aSThomas Huth type = GET_ASI_EXCP; 1564fcf5ef2aSThomas Huth } 1565fcf5ef2aSThomas Huth #else 1566811cc0b0SRichard Henderson if (asi < 0) { 1567fcf5ef2aSThomas Huth asi = dc->asi; 1568fcf5ef2aSThomas Huth } 1569fcf5ef2aSThomas Huth /* With v9, all asis below 0x80 are privileged. */ 1570fcf5ef2aSThomas Huth /* ??? We ought to check cpu_has_hypervisor, but we didn't copy 1571fcf5ef2aSThomas Huth down that bit into DisasContext. For the moment that's ok, 1572fcf5ef2aSThomas Huth since the direct implementations below doesn't have any ASIs 1573fcf5ef2aSThomas Huth in the restricted [0x30, 0x7f] range, and the check will be 1574fcf5ef2aSThomas Huth done properly in the helper. */ 1575fcf5ef2aSThomas Huth if (!supervisor(dc) && asi < 0x80) { 1576fcf5ef2aSThomas Huth gen_exception(dc, TT_PRIV_ACT); 1577fcf5ef2aSThomas Huth type = GET_ASI_EXCP; 1578fcf5ef2aSThomas Huth } else { 1579fcf5ef2aSThomas Huth switch (asi) { 1580fcf5ef2aSThomas Huth case ASI_REAL: /* Bypass */ 1581fcf5ef2aSThomas Huth case ASI_REAL_IO: /* Bypass, non-cacheable */ 1582fcf5ef2aSThomas Huth case ASI_REAL_L: /* Bypass LE */ 1583fcf5ef2aSThomas Huth case ASI_REAL_IO_L: /* Bypass, non-cacheable LE */ 1584fcf5ef2aSThomas Huth case ASI_TWINX_REAL: /* Real address, twinx */ 1585fcf5ef2aSThomas Huth case ASI_TWINX_REAL_L: /* Real address, twinx, LE */ 1586fcf5ef2aSThomas Huth case ASI_QUAD_LDD_PHYS: 1587fcf5ef2aSThomas Huth case ASI_QUAD_LDD_PHYS_L: 1588fcf5ef2aSThomas Huth mem_idx = MMU_PHYS_IDX; 1589fcf5ef2aSThomas Huth break; 1590fcf5ef2aSThomas Huth case ASI_N: /* Nucleus */ 1591fcf5ef2aSThomas Huth case ASI_NL: /* Nucleus LE */ 1592fcf5ef2aSThomas Huth case ASI_TWINX_N: 1593fcf5ef2aSThomas Huth case ASI_TWINX_NL: 1594fcf5ef2aSThomas Huth case ASI_NUCLEUS_QUAD_LDD: 1595fcf5ef2aSThomas Huth case ASI_NUCLEUS_QUAD_LDD_L: 15969a10756dSArtyom Tarasenko if (hypervisor(dc)) { 159784f8f587SArtyom Tarasenko mem_idx = MMU_PHYS_IDX; 15989a10756dSArtyom Tarasenko } else { 1599fcf5ef2aSThomas Huth mem_idx = MMU_NUCLEUS_IDX; 16009a10756dSArtyom Tarasenko } 1601fcf5ef2aSThomas Huth break; 1602fcf5ef2aSThomas Huth case ASI_AIUP: /* As if user primary */ 1603fcf5ef2aSThomas Huth case ASI_AIUPL: /* As if user primary LE */ 1604fcf5ef2aSThomas Huth case ASI_TWINX_AIUP: 1605fcf5ef2aSThomas Huth case ASI_TWINX_AIUP_L: 1606fcf5ef2aSThomas Huth case ASI_BLK_AIUP_4V: 1607fcf5ef2aSThomas Huth case ASI_BLK_AIUP_L_4V: 1608fcf5ef2aSThomas Huth case ASI_BLK_AIUP: 1609fcf5ef2aSThomas Huth case ASI_BLK_AIUPL: 1610fcf5ef2aSThomas Huth mem_idx = MMU_USER_IDX; 1611fcf5ef2aSThomas Huth break; 1612fcf5ef2aSThomas Huth case ASI_AIUS: /* As if user secondary */ 1613fcf5ef2aSThomas Huth case ASI_AIUSL: /* As if user secondary LE */ 1614fcf5ef2aSThomas Huth case ASI_TWINX_AIUS: 1615fcf5ef2aSThomas Huth case ASI_TWINX_AIUS_L: 1616fcf5ef2aSThomas Huth case ASI_BLK_AIUS_4V: 1617fcf5ef2aSThomas Huth case ASI_BLK_AIUS_L_4V: 1618fcf5ef2aSThomas Huth case ASI_BLK_AIUS: 1619fcf5ef2aSThomas Huth case ASI_BLK_AIUSL: 1620fcf5ef2aSThomas Huth mem_idx = MMU_USER_SECONDARY_IDX; 1621fcf5ef2aSThomas Huth break; 1622fcf5ef2aSThomas Huth case ASI_S: /* Secondary */ 1623fcf5ef2aSThomas Huth case ASI_SL: /* Secondary LE */ 1624fcf5ef2aSThomas Huth case ASI_TWINX_S: 1625fcf5ef2aSThomas Huth case ASI_TWINX_SL: 1626fcf5ef2aSThomas Huth case ASI_BLK_COMMIT_S: 1627fcf5ef2aSThomas Huth case ASI_BLK_S: 1628fcf5ef2aSThomas Huth case ASI_BLK_SL: 1629fcf5ef2aSThomas Huth case ASI_FL8_S: 1630fcf5ef2aSThomas Huth case ASI_FL8_SL: 1631fcf5ef2aSThomas Huth case ASI_FL16_S: 1632fcf5ef2aSThomas Huth case ASI_FL16_SL: 1633fcf5ef2aSThomas Huth if (mem_idx == MMU_USER_IDX) { 1634fcf5ef2aSThomas Huth mem_idx = MMU_USER_SECONDARY_IDX; 1635fcf5ef2aSThomas Huth } else if (mem_idx == MMU_KERNEL_IDX) { 1636fcf5ef2aSThomas Huth mem_idx = MMU_KERNEL_SECONDARY_IDX; 1637fcf5ef2aSThomas Huth } 1638fcf5ef2aSThomas Huth break; 1639fcf5ef2aSThomas Huth case ASI_P: /* Primary */ 1640fcf5ef2aSThomas Huth case ASI_PL: /* Primary LE */ 1641fcf5ef2aSThomas Huth case ASI_TWINX_P: 1642fcf5ef2aSThomas Huth case ASI_TWINX_PL: 1643fcf5ef2aSThomas Huth case ASI_BLK_COMMIT_P: 1644fcf5ef2aSThomas Huth case ASI_BLK_P: 1645fcf5ef2aSThomas Huth case ASI_BLK_PL: 1646fcf5ef2aSThomas Huth case ASI_FL8_P: 1647fcf5ef2aSThomas Huth case ASI_FL8_PL: 1648fcf5ef2aSThomas Huth case ASI_FL16_P: 1649fcf5ef2aSThomas Huth case ASI_FL16_PL: 1650fcf5ef2aSThomas Huth break; 1651fcf5ef2aSThomas Huth } 1652fcf5ef2aSThomas Huth switch (asi) { 1653fcf5ef2aSThomas Huth case ASI_REAL: 1654fcf5ef2aSThomas Huth case ASI_REAL_IO: 1655fcf5ef2aSThomas Huth case ASI_REAL_L: 1656fcf5ef2aSThomas Huth case ASI_REAL_IO_L: 1657fcf5ef2aSThomas Huth case ASI_N: 1658fcf5ef2aSThomas Huth case ASI_NL: 1659fcf5ef2aSThomas Huth case ASI_AIUP: 1660fcf5ef2aSThomas Huth case ASI_AIUPL: 1661fcf5ef2aSThomas Huth case ASI_AIUS: 1662fcf5ef2aSThomas Huth case ASI_AIUSL: 1663fcf5ef2aSThomas Huth case ASI_S: 1664fcf5ef2aSThomas Huth case ASI_SL: 1665fcf5ef2aSThomas Huth case ASI_P: 1666fcf5ef2aSThomas Huth case ASI_PL: 1667fcf5ef2aSThomas Huth type = GET_ASI_DIRECT; 1668fcf5ef2aSThomas Huth break; 1669fcf5ef2aSThomas Huth case ASI_TWINX_REAL: 1670fcf5ef2aSThomas Huth case ASI_TWINX_REAL_L: 1671fcf5ef2aSThomas Huth case ASI_TWINX_N: 1672fcf5ef2aSThomas Huth case ASI_TWINX_NL: 1673fcf5ef2aSThomas Huth case ASI_TWINX_AIUP: 1674fcf5ef2aSThomas Huth case ASI_TWINX_AIUP_L: 1675fcf5ef2aSThomas Huth case ASI_TWINX_AIUS: 1676fcf5ef2aSThomas Huth case ASI_TWINX_AIUS_L: 1677fcf5ef2aSThomas Huth case ASI_TWINX_P: 1678fcf5ef2aSThomas Huth case ASI_TWINX_PL: 1679fcf5ef2aSThomas Huth case ASI_TWINX_S: 1680fcf5ef2aSThomas Huth case ASI_TWINX_SL: 1681fcf5ef2aSThomas Huth case ASI_QUAD_LDD_PHYS: 1682fcf5ef2aSThomas Huth case ASI_QUAD_LDD_PHYS_L: 1683fcf5ef2aSThomas Huth case ASI_NUCLEUS_QUAD_LDD: 1684fcf5ef2aSThomas Huth case ASI_NUCLEUS_QUAD_LDD_L: 1685fcf5ef2aSThomas Huth type = GET_ASI_DTWINX; 1686fcf5ef2aSThomas Huth break; 1687fcf5ef2aSThomas Huth case ASI_BLK_COMMIT_P: 1688fcf5ef2aSThomas Huth case ASI_BLK_COMMIT_S: 1689fcf5ef2aSThomas Huth case ASI_BLK_AIUP_4V: 1690fcf5ef2aSThomas Huth case ASI_BLK_AIUP_L_4V: 1691fcf5ef2aSThomas Huth case ASI_BLK_AIUP: 1692fcf5ef2aSThomas Huth case ASI_BLK_AIUPL: 1693fcf5ef2aSThomas Huth case ASI_BLK_AIUS_4V: 1694fcf5ef2aSThomas Huth case ASI_BLK_AIUS_L_4V: 1695fcf5ef2aSThomas Huth case ASI_BLK_AIUS: 1696fcf5ef2aSThomas Huth case ASI_BLK_AIUSL: 1697fcf5ef2aSThomas Huth case ASI_BLK_S: 1698fcf5ef2aSThomas Huth case ASI_BLK_SL: 1699fcf5ef2aSThomas Huth case ASI_BLK_P: 1700fcf5ef2aSThomas Huth case ASI_BLK_PL: 1701fcf5ef2aSThomas Huth type = GET_ASI_BLOCK; 1702fcf5ef2aSThomas Huth break; 1703fcf5ef2aSThomas Huth case ASI_FL8_S: 1704fcf5ef2aSThomas Huth case ASI_FL8_SL: 1705fcf5ef2aSThomas Huth case ASI_FL8_P: 1706fcf5ef2aSThomas Huth case ASI_FL8_PL: 1707fcf5ef2aSThomas Huth memop = MO_UB; 1708fcf5ef2aSThomas Huth type = GET_ASI_SHORT; 1709fcf5ef2aSThomas Huth break; 1710fcf5ef2aSThomas Huth case ASI_FL16_S: 1711fcf5ef2aSThomas Huth case ASI_FL16_SL: 1712fcf5ef2aSThomas Huth case ASI_FL16_P: 1713fcf5ef2aSThomas Huth case ASI_FL16_PL: 1714fcf5ef2aSThomas Huth memop = MO_TEUW; 1715fcf5ef2aSThomas Huth type = GET_ASI_SHORT; 1716fcf5ef2aSThomas Huth break; 1717fcf5ef2aSThomas Huth } 1718fcf5ef2aSThomas Huth /* The little-endian asis all have bit 3 set. */ 1719fcf5ef2aSThomas Huth if (asi & 8) { 1720fcf5ef2aSThomas Huth memop ^= MO_BSWAP; 1721fcf5ef2aSThomas Huth } 1722fcf5ef2aSThomas Huth } 1723fcf5ef2aSThomas Huth #endif 1724fcf5ef2aSThomas Huth 1725811cc0b0SRichard Henderson done: 1726fcf5ef2aSThomas Huth return (DisasASI){ type, asi, mem_idx, memop }; 1727fcf5ef2aSThomas Huth } 1728fcf5ef2aSThomas Huth 1729a76779eeSRichard Henderson #if defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64) 1730a76779eeSRichard Henderson static void gen_helper_ld_asi(TCGv_i64 r, TCGv_env e, TCGv a, 1731a76779eeSRichard Henderson TCGv_i32 asi, TCGv_i32 mop) 1732a76779eeSRichard Henderson { 1733a76779eeSRichard Henderson g_assert_not_reached(); 1734a76779eeSRichard Henderson } 1735a76779eeSRichard Henderson 1736a76779eeSRichard Henderson static void gen_helper_st_asi(TCGv_env e, TCGv a, TCGv_i64 r, 1737a76779eeSRichard Henderson TCGv_i32 asi, TCGv_i32 mop) 1738a76779eeSRichard Henderson { 1739a76779eeSRichard Henderson g_assert_not_reached(); 1740a76779eeSRichard Henderson } 1741a76779eeSRichard Henderson #endif 1742a76779eeSRichard Henderson 174342071fc1SRichard Henderson static void gen_ld_asi(DisasContext *dc, DisasASI *da, TCGv dst, TCGv addr) 1744fcf5ef2aSThomas Huth { 1745c03a0fd1SRichard Henderson switch (da->type) { 1746fcf5ef2aSThomas Huth case GET_ASI_EXCP: 1747fcf5ef2aSThomas Huth break; 1748fcf5ef2aSThomas Huth case GET_ASI_DTWINX: /* Reserved for ldda. */ 1749fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 1750fcf5ef2aSThomas Huth break; 1751fcf5ef2aSThomas Huth case GET_ASI_DIRECT: 1752c03a0fd1SRichard Henderson tcg_gen_qemu_ld_tl(dst, addr, da->mem_idx, da->memop | MO_ALIGN); 1753fcf5ef2aSThomas Huth break; 17542786a3f8SRichard Henderson 17552786a3f8SRichard Henderson case GET_ASI_CODE: 17562786a3f8SRichard Henderson #if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64) 17572786a3f8SRichard Henderson { 17582786a3f8SRichard Henderson MemOpIdx oi = make_memop_idx(da->memop, da->mem_idx); 17592786a3f8SRichard Henderson TCGv_i64 t64 = tcg_temp_new_i64(); 17602786a3f8SRichard Henderson 17612786a3f8SRichard Henderson gen_helper_ld_code(t64, tcg_env, addr, tcg_constant_i32(oi)); 17622786a3f8SRichard Henderson tcg_gen_trunc_i64_tl(dst, t64); 17632786a3f8SRichard Henderson } 17642786a3f8SRichard Henderson break; 17652786a3f8SRichard Henderson #else 17662786a3f8SRichard Henderson g_assert_not_reached(); 17672786a3f8SRichard Henderson #endif 17682786a3f8SRichard Henderson 1769fcf5ef2aSThomas Huth default: 1770fcf5ef2aSThomas Huth { 1771c03a0fd1SRichard Henderson TCGv_i32 r_asi = tcg_constant_i32(da->asi); 1772c03a0fd1SRichard Henderson TCGv_i32 r_mop = tcg_constant_i32(da->memop | MO_ALIGN); 1773fcf5ef2aSThomas Huth 1774fcf5ef2aSThomas Huth save_state(dc); 1775fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64 1776ad75a51eSRichard Henderson gen_helper_ld_asi(dst, tcg_env, addr, r_asi, r_mop); 1777fcf5ef2aSThomas Huth #else 1778fcf5ef2aSThomas Huth { 1779fcf5ef2aSThomas Huth TCGv_i64 t64 = tcg_temp_new_i64(); 1780ad75a51eSRichard Henderson gen_helper_ld_asi(t64, tcg_env, addr, r_asi, r_mop); 1781fcf5ef2aSThomas Huth tcg_gen_trunc_i64_tl(dst, t64); 1782fcf5ef2aSThomas Huth } 1783fcf5ef2aSThomas Huth #endif 1784fcf5ef2aSThomas Huth } 1785fcf5ef2aSThomas Huth break; 1786fcf5ef2aSThomas Huth } 1787fcf5ef2aSThomas Huth } 1788fcf5ef2aSThomas Huth 178942071fc1SRichard Henderson static void gen_st_asi(DisasContext *dc, DisasASI *da, TCGv src, TCGv addr) 1790c03a0fd1SRichard Henderson { 1791c03a0fd1SRichard Henderson switch (da->type) { 1792fcf5ef2aSThomas Huth case GET_ASI_EXCP: 1793fcf5ef2aSThomas Huth break; 1794c03a0fd1SRichard Henderson 1795fcf5ef2aSThomas Huth case GET_ASI_DTWINX: /* Reserved for stda. */ 1796c03a0fd1SRichard Henderson if (TARGET_LONG_BITS == 32) { 1797fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 1798fcf5ef2aSThomas Huth break; 1799c03a0fd1SRichard Henderson } else if (!(dc->def->features & CPU_FEATURE_HYPV)) { 18003390537bSArtyom Tarasenko /* Pre OpenSPARC CPUs don't have these */ 18013390537bSArtyom Tarasenko gen_exception(dc, TT_ILL_INSN); 1802fcf5ef2aSThomas Huth break; 1803c03a0fd1SRichard Henderson } 1804c03a0fd1SRichard Henderson /* In OpenSPARC T1+ CPUs TWINX ASIs in store are ST_BLKINIT_ ASIs */ 1805c03a0fd1SRichard Henderson /* fall through */ 1806c03a0fd1SRichard Henderson 1807c03a0fd1SRichard Henderson case GET_ASI_DIRECT: 1808c03a0fd1SRichard Henderson tcg_gen_qemu_st_tl(src, addr, da->mem_idx, da->memop | MO_ALIGN); 1809c03a0fd1SRichard Henderson break; 1810c03a0fd1SRichard Henderson 1811fcf5ef2aSThomas Huth case GET_ASI_BCOPY: 1812c03a0fd1SRichard Henderson assert(TARGET_LONG_BITS == 32); 181398271007SRichard Henderson /* 181498271007SRichard Henderson * Copy 32 bytes from the address in SRC to ADDR. 181598271007SRichard Henderson * 181698271007SRichard Henderson * From Ross RT625 hyperSPARC manual, section 4.6: 181798271007SRichard Henderson * "Block Copy and Block Fill will work only on cache line boundaries." 181898271007SRichard Henderson * 181998271007SRichard Henderson * It does not specify if an unaliged address is truncated or trapped. 182098271007SRichard Henderson * Previous qemu behaviour was to truncate to 4 byte alignment, which 182198271007SRichard Henderson * is obviously wrong. The only place I can see this used is in the 182298271007SRichard Henderson * Linux kernel which begins with page alignment, advancing by 32, 182398271007SRichard Henderson * so is always aligned. Assume truncation as the simpler option. 182498271007SRichard Henderson * 182598271007SRichard Henderson * Since the loads and stores are paired, allow the copy to happen 182698271007SRichard Henderson * in the host endianness. The copy need not be atomic. 182798271007SRichard Henderson */ 1828fcf5ef2aSThomas Huth { 182998271007SRichard Henderson MemOp mop = MO_128 | MO_ATOM_IFALIGN_PAIR; 1830fcf5ef2aSThomas Huth TCGv saddr = tcg_temp_new(); 1831fcf5ef2aSThomas Huth TCGv daddr = tcg_temp_new(); 183298271007SRichard Henderson TCGv_i128 tmp = tcg_temp_new_i128(); 1833fcf5ef2aSThomas Huth 183498271007SRichard Henderson tcg_gen_andi_tl(saddr, src, -32); 183598271007SRichard Henderson tcg_gen_andi_tl(daddr, addr, -32); 183698271007SRichard Henderson tcg_gen_qemu_ld_i128(tmp, saddr, da->mem_idx, mop); 183798271007SRichard Henderson tcg_gen_qemu_st_i128(tmp, daddr, da->mem_idx, mop); 183898271007SRichard Henderson tcg_gen_addi_tl(saddr, saddr, 16); 183998271007SRichard Henderson tcg_gen_addi_tl(daddr, daddr, 16); 184098271007SRichard Henderson tcg_gen_qemu_ld_i128(tmp, saddr, da->mem_idx, mop); 184198271007SRichard Henderson tcg_gen_qemu_st_i128(tmp, daddr, da->mem_idx, mop); 1842fcf5ef2aSThomas Huth } 1843fcf5ef2aSThomas Huth break; 1844c03a0fd1SRichard Henderson 1845fcf5ef2aSThomas Huth default: 1846fcf5ef2aSThomas Huth { 1847c03a0fd1SRichard Henderson TCGv_i32 r_asi = tcg_constant_i32(da->asi); 1848c03a0fd1SRichard Henderson TCGv_i32 r_mop = tcg_constant_i32(da->memop | MO_ALIGN); 1849fcf5ef2aSThomas Huth 1850fcf5ef2aSThomas Huth save_state(dc); 1851fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64 1852ad75a51eSRichard Henderson gen_helper_st_asi(tcg_env, addr, src, r_asi, r_mop); 1853fcf5ef2aSThomas Huth #else 1854fcf5ef2aSThomas Huth { 1855fcf5ef2aSThomas Huth TCGv_i64 t64 = tcg_temp_new_i64(); 1856fcf5ef2aSThomas Huth tcg_gen_extu_tl_i64(t64, src); 1857ad75a51eSRichard Henderson gen_helper_st_asi(tcg_env, addr, t64, r_asi, r_mop); 1858fcf5ef2aSThomas Huth } 1859fcf5ef2aSThomas Huth #endif 1860fcf5ef2aSThomas Huth 1861fcf5ef2aSThomas Huth /* A write to a TLB register may alter page maps. End the TB. */ 1862fcf5ef2aSThomas Huth dc->npc = DYNAMIC_PC; 1863fcf5ef2aSThomas Huth } 1864fcf5ef2aSThomas Huth break; 1865fcf5ef2aSThomas Huth } 1866fcf5ef2aSThomas Huth } 1867fcf5ef2aSThomas Huth 1868dca544b9SRichard Henderson static void gen_swap_asi(DisasContext *dc, DisasASI *da, 1869c03a0fd1SRichard Henderson TCGv dst, TCGv src, TCGv addr) 1870c03a0fd1SRichard Henderson { 1871c03a0fd1SRichard Henderson switch (da->type) { 1872c03a0fd1SRichard Henderson case GET_ASI_EXCP: 1873c03a0fd1SRichard Henderson break; 1874c03a0fd1SRichard Henderson case GET_ASI_DIRECT: 1875dca544b9SRichard Henderson tcg_gen_atomic_xchg_tl(dst, addr, src, 1876dca544b9SRichard Henderson da->mem_idx, da->memop | MO_ALIGN); 1877c03a0fd1SRichard Henderson break; 1878c03a0fd1SRichard Henderson default: 1879c03a0fd1SRichard Henderson /* ??? Should be DAE_invalid_asi. */ 1880c03a0fd1SRichard Henderson gen_exception(dc, TT_DATA_ACCESS); 1881c03a0fd1SRichard Henderson break; 1882c03a0fd1SRichard Henderson } 1883c03a0fd1SRichard Henderson } 1884c03a0fd1SRichard Henderson 1885d0a11d25SRichard Henderson static void gen_cas_asi(DisasContext *dc, DisasASI *da, 1886c03a0fd1SRichard Henderson TCGv oldv, TCGv newv, TCGv cmpv, TCGv addr) 1887c03a0fd1SRichard Henderson { 1888c03a0fd1SRichard Henderson switch (da->type) { 1889fcf5ef2aSThomas Huth case GET_ASI_EXCP: 1890c03a0fd1SRichard Henderson return; 1891fcf5ef2aSThomas Huth case GET_ASI_DIRECT: 1892c03a0fd1SRichard Henderson tcg_gen_atomic_cmpxchg_tl(oldv, addr, cmpv, newv, 1893c03a0fd1SRichard Henderson da->mem_idx, da->memop | MO_ALIGN); 1894fcf5ef2aSThomas Huth break; 1895fcf5ef2aSThomas Huth default: 1896fcf5ef2aSThomas Huth /* ??? Should be DAE_invalid_asi. */ 1897fcf5ef2aSThomas Huth gen_exception(dc, TT_DATA_ACCESS); 1898fcf5ef2aSThomas Huth break; 1899fcf5ef2aSThomas Huth } 1900fcf5ef2aSThomas Huth } 1901fcf5ef2aSThomas Huth 1902cf07cd1eSRichard Henderson static void gen_ldstub_asi(DisasContext *dc, DisasASI *da, TCGv dst, TCGv addr) 1903c03a0fd1SRichard Henderson { 1904c03a0fd1SRichard Henderson switch (da->type) { 1905fcf5ef2aSThomas Huth case GET_ASI_EXCP: 1906fcf5ef2aSThomas Huth break; 1907fcf5ef2aSThomas Huth case GET_ASI_DIRECT: 1908cf07cd1eSRichard Henderson tcg_gen_atomic_xchg_tl(dst, addr, tcg_constant_tl(0xff), 1909cf07cd1eSRichard Henderson da->mem_idx, MO_UB); 1910fcf5ef2aSThomas Huth break; 1911fcf5ef2aSThomas Huth default: 19123db010c3SRichard Henderson /* ??? In theory, this should be raise DAE_invalid_asi. 19133db010c3SRichard Henderson But the SS-20 roms do ldstuba [%l0] #ASI_M_CTL, %o1. */ 1914af00be49SEmilio G. Cota if (tb_cflags(dc->base.tb) & CF_PARALLEL) { 1915ad75a51eSRichard Henderson gen_helper_exit_atomic(tcg_env); 19163db010c3SRichard Henderson } else { 1917c03a0fd1SRichard Henderson TCGv_i32 r_asi = tcg_constant_i32(da->asi); 191800ab7e61SRichard Henderson TCGv_i32 r_mop = tcg_constant_i32(MO_UB); 19193db010c3SRichard Henderson TCGv_i64 s64, t64; 19203db010c3SRichard Henderson 19213db010c3SRichard Henderson save_state(dc); 19223db010c3SRichard Henderson t64 = tcg_temp_new_i64(); 1923ad75a51eSRichard Henderson gen_helper_ld_asi(t64, tcg_env, addr, r_asi, r_mop); 19243db010c3SRichard Henderson 192500ab7e61SRichard Henderson s64 = tcg_constant_i64(0xff); 1926ad75a51eSRichard Henderson gen_helper_st_asi(tcg_env, addr, s64, r_asi, r_mop); 19273db010c3SRichard Henderson 19283db010c3SRichard Henderson tcg_gen_trunc_i64_tl(dst, t64); 19293db010c3SRichard Henderson 19303db010c3SRichard Henderson /* End the TB. */ 19313db010c3SRichard Henderson dc->npc = DYNAMIC_PC; 19323db010c3SRichard Henderson } 1933fcf5ef2aSThomas Huth break; 1934fcf5ef2aSThomas Huth } 1935fcf5ef2aSThomas Huth } 1936fcf5ef2aSThomas Huth 1937287b1152SRichard Henderson static void gen_ldf_asi(DisasContext *dc, DisasASI *da, MemOp orig_size, 19383259b9e2SRichard Henderson TCGv addr, int rd) 1939fcf5ef2aSThomas Huth { 19403259b9e2SRichard Henderson MemOp memop = da->memop; 19413259b9e2SRichard Henderson MemOp size = memop & MO_SIZE; 1942fcf5ef2aSThomas Huth TCGv_i32 d32; 19431210a036SRichard Henderson TCGv_i64 d64, l64; 1944287b1152SRichard Henderson TCGv addr_tmp; 1945fcf5ef2aSThomas Huth 19463259b9e2SRichard Henderson /* TODO: Use 128-bit load/store below. */ 19473259b9e2SRichard Henderson if (size == MO_128) { 19483259b9e2SRichard Henderson memop = (memop & ~MO_SIZE) | MO_64; 19493259b9e2SRichard Henderson } 19503259b9e2SRichard Henderson 19513259b9e2SRichard Henderson switch (da->type) { 1952fcf5ef2aSThomas Huth case GET_ASI_EXCP: 1953fcf5ef2aSThomas Huth break; 1954fcf5ef2aSThomas Huth 1955fcf5ef2aSThomas Huth case GET_ASI_DIRECT: 19563259b9e2SRichard Henderson memop |= MO_ALIGN_4; 1957fcf5ef2aSThomas Huth switch (size) { 19583259b9e2SRichard Henderson case MO_32: 1959388a6465SRichard Henderson d32 = tcg_temp_new_i32(); 19603259b9e2SRichard Henderson tcg_gen_qemu_ld_i32(d32, addr, da->mem_idx, memop); 1961fcf5ef2aSThomas Huth gen_store_fpr_F(dc, rd, d32); 1962fcf5ef2aSThomas Huth break; 19633259b9e2SRichard Henderson 19643259b9e2SRichard Henderson case MO_64: 19651210a036SRichard Henderson d64 = tcg_temp_new_i64(); 19661210a036SRichard Henderson tcg_gen_qemu_ld_i64(d64, addr, da->mem_idx, memop); 19671210a036SRichard Henderson gen_store_fpr_D(dc, rd, d64); 1968fcf5ef2aSThomas Huth break; 19693259b9e2SRichard Henderson 19703259b9e2SRichard Henderson case MO_128: 1971fcf5ef2aSThomas Huth d64 = tcg_temp_new_i64(); 19721210a036SRichard Henderson l64 = tcg_temp_new_i64(); 19733259b9e2SRichard Henderson tcg_gen_qemu_ld_i64(d64, addr, da->mem_idx, memop); 1974287b1152SRichard Henderson addr_tmp = tcg_temp_new(); 1975287b1152SRichard Henderson tcg_gen_addi_tl(addr_tmp, addr, 8); 19761210a036SRichard Henderson tcg_gen_qemu_ld_i64(l64, addr_tmp, da->mem_idx, memop); 19771210a036SRichard Henderson gen_store_fpr_D(dc, rd, d64); 19781210a036SRichard Henderson gen_store_fpr_D(dc, rd + 2, l64); 1979fcf5ef2aSThomas Huth break; 1980fcf5ef2aSThomas Huth default: 1981fcf5ef2aSThomas Huth g_assert_not_reached(); 1982fcf5ef2aSThomas Huth } 1983fcf5ef2aSThomas Huth break; 1984fcf5ef2aSThomas Huth 1985fcf5ef2aSThomas Huth case GET_ASI_BLOCK: 1986fcf5ef2aSThomas Huth /* Valid for lddfa on aligned registers only. */ 19873259b9e2SRichard Henderson if (orig_size == MO_64 && (rd & 7) == 0) { 1988fcf5ef2aSThomas Huth /* The first operation checks required alignment. */ 1989287b1152SRichard Henderson addr_tmp = tcg_temp_new(); 19901210a036SRichard Henderson d64 = tcg_temp_new_i64(); 1991287b1152SRichard Henderson for (int i = 0; ; ++i) { 19921210a036SRichard Henderson tcg_gen_qemu_ld_i64(d64, addr, da->mem_idx, 19933259b9e2SRichard Henderson memop | (i == 0 ? MO_ALIGN_64 : 0)); 19941210a036SRichard Henderson gen_store_fpr_D(dc, rd + 2 * i, d64); 1995fcf5ef2aSThomas Huth if (i == 7) { 1996fcf5ef2aSThomas Huth break; 1997fcf5ef2aSThomas Huth } 1998287b1152SRichard Henderson tcg_gen_addi_tl(addr_tmp, addr, 8); 1999287b1152SRichard Henderson addr = addr_tmp; 2000fcf5ef2aSThomas Huth } 2001fcf5ef2aSThomas Huth } else { 2002fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 2003fcf5ef2aSThomas Huth } 2004fcf5ef2aSThomas Huth break; 2005fcf5ef2aSThomas Huth 2006fcf5ef2aSThomas Huth case GET_ASI_SHORT: 2007fcf5ef2aSThomas Huth /* Valid for lddfa only. */ 20083259b9e2SRichard Henderson if (orig_size == MO_64) { 20091210a036SRichard Henderson d64 = tcg_temp_new_i64(); 20101210a036SRichard Henderson tcg_gen_qemu_ld_i64(d64, addr, da->mem_idx, memop | MO_ALIGN); 20111210a036SRichard Henderson gen_store_fpr_D(dc, rd, d64); 2012fcf5ef2aSThomas Huth } else { 2013fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 2014fcf5ef2aSThomas Huth } 2015fcf5ef2aSThomas Huth break; 2016fcf5ef2aSThomas Huth 2017fcf5ef2aSThomas Huth default: 2018fcf5ef2aSThomas Huth { 20193259b9e2SRichard Henderson TCGv_i32 r_asi = tcg_constant_i32(da->asi); 20203259b9e2SRichard Henderson TCGv_i32 r_mop = tcg_constant_i32(memop | MO_ALIGN); 2021fcf5ef2aSThomas Huth 2022fcf5ef2aSThomas Huth save_state(dc); 2023fcf5ef2aSThomas Huth /* According to the table in the UA2011 manual, the only 2024fcf5ef2aSThomas Huth other asis that are valid for ldfa/lddfa/ldqfa are 2025fcf5ef2aSThomas Huth the NO_FAULT asis. We still need a helper for these, 2026fcf5ef2aSThomas Huth but we can just use the integer asi helper for them. */ 2027fcf5ef2aSThomas Huth switch (size) { 20283259b9e2SRichard Henderson case MO_32: 2029fcf5ef2aSThomas Huth d64 = tcg_temp_new_i64(); 2030ad75a51eSRichard Henderson gen_helper_ld_asi(d64, tcg_env, addr, r_asi, r_mop); 2031388a6465SRichard Henderson d32 = tcg_temp_new_i32(); 2032fcf5ef2aSThomas Huth tcg_gen_extrl_i64_i32(d32, d64); 2033fcf5ef2aSThomas Huth gen_store_fpr_F(dc, rd, d32); 2034fcf5ef2aSThomas Huth break; 20353259b9e2SRichard Henderson case MO_64: 20361210a036SRichard Henderson d64 = tcg_temp_new_i64(); 20371210a036SRichard Henderson gen_helper_ld_asi(d64, tcg_env, addr, r_asi, r_mop); 20381210a036SRichard Henderson gen_store_fpr_D(dc, rd, d64); 2039fcf5ef2aSThomas Huth break; 20403259b9e2SRichard Henderson case MO_128: 2041fcf5ef2aSThomas Huth d64 = tcg_temp_new_i64(); 20421210a036SRichard Henderson l64 = tcg_temp_new_i64(); 2043ad75a51eSRichard Henderson gen_helper_ld_asi(d64, tcg_env, addr, r_asi, r_mop); 2044287b1152SRichard Henderson addr_tmp = tcg_temp_new(); 2045287b1152SRichard Henderson tcg_gen_addi_tl(addr_tmp, addr, 8); 20461210a036SRichard Henderson gen_helper_ld_asi(l64, tcg_env, addr_tmp, r_asi, r_mop); 20471210a036SRichard Henderson gen_store_fpr_D(dc, rd, d64); 20481210a036SRichard Henderson gen_store_fpr_D(dc, rd + 2, l64); 2049fcf5ef2aSThomas Huth break; 2050fcf5ef2aSThomas Huth default: 2051fcf5ef2aSThomas Huth g_assert_not_reached(); 2052fcf5ef2aSThomas Huth } 2053fcf5ef2aSThomas Huth } 2054fcf5ef2aSThomas Huth break; 2055fcf5ef2aSThomas Huth } 2056fcf5ef2aSThomas Huth } 2057fcf5ef2aSThomas Huth 2058287b1152SRichard Henderson static void gen_stf_asi(DisasContext *dc, DisasASI *da, MemOp orig_size, 20593259b9e2SRichard Henderson TCGv addr, int rd) 20603259b9e2SRichard Henderson { 20613259b9e2SRichard Henderson MemOp memop = da->memop; 20623259b9e2SRichard Henderson MemOp size = memop & MO_SIZE; 2063fcf5ef2aSThomas Huth TCGv_i32 d32; 20641210a036SRichard Henderson TCGv_i64 d64; 2065287b1152SRichard Henderson TCGv addr_tmp; 2066fcf5ef2aSThomas Huth 20673259b9e2SRichard Henderson /* TODO: Use 128-bit load/store below. */ 20683259b9e2SRichard Henderson if (size == MO_128) { 20693259b9e2SRichard Henderson memop = (memop & ~MO_SIZE) | MO_64; 20703259b9e2SRichard Henderson } 20713259b9e2SRichard Henderson 20723259b9e2SRichard Henderson switch (da->type) { 2073fcf5ef2aSThomas Huth case GET_ASI_EXCP: 2074fcf5ef2aSThomas Huth break; 2075fcf5ef2aSThomas Huth 2076fcf5ef2aSThomas Huth case GET_ASI_DIRECT: 20773259b9e2SRichard Henderson memop |= MO_ALIGN_4; 2078fcf5ef2aSThomas Huth switch (size) { 20793259b9e2SRichard Henderson case MO_32: 2080fcf5ef2aSThomas Huth d32 = gen_load_fpr_F(dc, rd); 20813259b9e2SRichard Henderson tcg_gen_qemu_st_i32(d32, addr, da->mem_idx, memop | MO_ALIGN); 2082fcf5ef2aSThomas Huth break; 20833259b9e2SRichard Henderson case MO_64: 20841210a036SRichard Henderson d64 = gen_load_fpr_D(dc, rd); 20851210a036SRichard Henderson tcg_gen_qemu_st_i64(d64, addr, da->mem_idx, memop | MO_ALIGN_4); 2086fcf5ef2aSThomas Huth break; 20873259b9e2SRichard Henderson case MO_128: 2088fcf5ef2aSThomas Huth /* Only 4-byte alignment required. However, it is legal for the 2089fcf5ef2aSThomas Huth cpu to signal the alignment fault, and the OS trap handler is 2090fcf5ef2aSThomas Huth required to fix it up. Requiring 16-byte alignment here avoids 2091fcf5ef2aSThomas Huth having to probe the second page before performing the first 2092fcf5ef2aSThomas Huth write. */ 20931210a036SRichard Henderson d64 = gen_load_fpr_D(dc, rd); 20941210a036SRichard Henderson tcg_gen_qemu_st_i64(d64, addr, da->mem_idx, memop | MO_ALIGN_16); 2095287b1152SRichard Henderson addr_tmp = tcg_temp_new(); 2096287b1152SRichard Henderson tcg_gen_addi_tl(addr_tmp, addr, 8); 20971210a036SRichard Henderson d64 = gen_load_fpr_D(dc, rd + 2); 20981210a036SRichard Henderson tcg_gen_qemu_st_i64(d64, addr_tmp, da->mem_idx, memop); 2099fcf5ef2aSThomas Huth break; 2100fcf5ef2aSThomas Huth default: 2101fcf5ef2aSThomas Huth g_assert_not_reached(); 2102fcf5ef2aSThomas Huth } 2103fcf5ef2aSThomas Huth break; 2104fcf5ef2aSThomas Huth 2105fcf5ef2aSThomas Huth case GET_ASI_BLOCK: 2106fcf5ef2aSThomas Huth /* Valid for stdfa on aligned registers only. */ 21073259b9e2SRichard Henderson if (orig_size == MO_64 && (rd & 7) == 0) { 2108fcf5ef2aSThomas Huth /* The first operation checks required alignment. */ 2109287b1152SRichard Henderson addr_tmp = tcg_temp_new(); 2110287b1152SRichard Henderson for (int i = 0; ; ++i) { 21111210a036SRichard Henderson d64 = gen_load_fpr_D(dc, rd + 2 * i); 21121210a036SRichard Henderson tcg_gen_qemu_st_i64(d64, addr, da->mem_idx, 21133259b9e2SRichard Henderson memop | (i == 0 ? MO_ALIGN_64 : 0)); 2114fcf5ef2aSThomas Huth if (i == 7) { 2115fcf5ef2aSThomas Huth break; 2116fcf5ef2aSThomas Huth } 2117287b1152SRichard Henderson tcg_gen_addi_tl(addr_tmp, addr, 8); 2118287b1152SRichard Henderson addr = addr_tmp; 2119fcf5ef2aSThomas Huth } 2120fcf5ef2aSThomas Huth } else { 2121fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 2122fcf5ef2aSThomas Huth } 2123fcf5ef2aSThomas Huth break; 2124fcf5ef2aSThomas Huth 2125fcf5ef2aSThomas Huth case GET_ASI_SHORT: 2126fcf5ef2aSThomas Huth /* Valid for stdfa only. */ 21273259b9e2SRichard Henderson if (orig_size == MO_64) { 21281210a036SRichard Henderson d64 = gen_load_fpr_D(dc, rd); 21291210a036SRichard Henderson tcg_gen_qemu_st_i64(d64, addr, da->mem_idx, memop | MO_ALIGN); 2130fcf5ef2aSThomas Huth } else { 2131fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 2132fcf5ef2aSThomas Huth } 2133fcf5ef2aSThomas Huth break; 2134fcf5ef2aSThomas Huth 2135fcf5ef2aSThomas Huth default: 2136fcf5ef2aSThomas Huth /* According to the table in the UA2011 manual, the only 2137fcf5ef2aSThomas Huth other asis that are valid for ldfa/lddfa/ldqfa are 2138fcf5ef2aSThomas Huth the PST* asis, which aren't currently handled. */ 2139fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 2140fcf5ef2aSThomas Huth break; 2141fcf5ef2aSThomas Huth } 2142fcf5ef2aSThomas Huth } 2143fcf5ef2aSThomas Huth 214442071fc1SRichard Henderson static void gen_ldda_asi(DisasContext *dc, DisasASI *da, TCGv addr, int rd) 2145fcf5ef2aSThomas Huth { 2146a76779eeSRichard Henderson TCGv hi = gen_dest_gpr(dc, rd); 2147a76779eeSRichard Henderson TCGv lo = gen_dest_gpr(dc, rd + 1); 2148fcf5ef2aSThomas Huth 2149c03a0fd1SRichard Henderson switch (da->type) { 2150fcf5ef2aSThomas Huth case GET_ASI_EXCP: 2151fcf5ef2aSThomas Huth return; 2152fcf5ef2aSThomas Huth 2153fcf5ef2aSThomas Huth case GET_ASI_DTWINX: 2154ebbbec92SRichard Henderson #ifdef TARGET_SPARC64 2155ebbbec92SRichard Henderson { 2156ebbbec92SRichard Henderson MemOp mop = (da->memop & MO_BSWAP) | MO_128 | MO_ALIGN_16; 2157ebbbec92SRichard Henderson TCGv_i128 t = tcg_temp_new_i128(); 2158ebbbec92SRichard Henderson 2159ebbbec92SRichard Henderson tcg_gen_qemu_ld_i128(t, addr, da->mem_idx, mop); 2160ebbbec92SRichard Henderson /* 2161ebbbec92SRichard Henderson * Note that LE twinx acts as if each 64-bit register result is 2162ebbbec92SRichard Henderson * byte swapped. We perform one 128-bit LE load, so must swap 2163ebbbec92SRichard Henderson * the order of the writebacks. 2164ebbbec92SRichard Henderson */ 2165ebbbec92SRichard Henderson if ((mop & MO_BSWAP) == MO_TE) { 2166ebbbec92SRichard Henderson tcg_gen_extr_i128_i64(lo, hi, t); 2167ebbbec92SRichard Henderson } else { 2168ebbbec92SRichard Henderson tcg_gen_extr_i128_i64(hi, lo, t); 2169ebbbec92SRichard Henderson } 2170ebbbec92SRichard Henderson } 2171fcf5ef2aSThomas Huth break; 2172ebbbec92SRichard Henderson #else 2173ebbbec92SRichard Henderson g_assert_not_reached(); 2174ebbbec92SRichard Henderson #endif 2175fcf5ef2aSThomas Huth 2176fcf5ef2aSThomas Huth case GET_ASI_DIRECT: 2177fcf5ef2aSThomas Huth { 2178fcf5ef2aSThomas Huth TCGv_i64 tmp = tcg_temp_new_i64(); 2179fcf5ef2aSThomas Huth 2180c03a0fd1SRichard Henderson tcg_gen_qemu_ld_i64(tmp, addr, da->mem_idx, da->memop | MO_ALIGN); 2181fcf5ef2aSThomas Huth 2182fcf5ef2aSThomas Huth /* Note that LE ldda acts as if each 32-bit register 2183fcf5ef2aSThomas Huth result is byte swapped. Having just performed one 2184fcf5ef2aSThomas Huth 64-bit bswap, we need now to swap the writebacks. */ 2185c03a0fd1SRichard Henderson if ((da->memop & MO_BSWAP) == MO_TE) { 2186a76779eeSRichard Henderson tcg_gen_extr_i64_tl(lo, hi, tmp); 2187fcf5ef2aSThomas Huth } else { 2188a76779eeSRichard Henderson tcg_gen_extr_i64_tl(hi, lo, tmp); 2189fcf5ef2aSThomas Huth } 2190fcf5ef2aSThomas Huth } 2191fcf5ef2aSThomas Huth break; 2192fcf5ef2aSThomas Huth 21932786a3f8SRichard Henderson case GET_ASI_CODE: 21942786a3f8SRichard Henderson #if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64) 21952786a3f8SRichard Henderson { 21962786a3f8SRichard Henderson MemOpIdx oi = make_memop_idx(da->memop, da->mem_idx); 21972786a3f8SRichard Henderson TCGv_i64 tmp = tcg_temp_new_i64(); 21982786a3f8SRichard Henderson 21992786a3f8SRichard Henderson gen_helper_ld_code(tmp, tcg_env, addr, tcg_constant_i32(oi)); 22002786a3f8SRichard Henderson 22012786a3f8SRichard Henderson /* See above. */ 22022786a3f8SRichard Henderson if ((da->memop & MO_BSWAP) == MO_TE) { 22032786a3f8SRichard Henderson tcg_gen_extr_i64_tl(lo, hi, tmp); 22042786a3f8SRichard Henderson } else { 22052786a3f8SRichard Henderson tcg_gen_extr_i64_tl(hi, lo, tmp); 22062786a3f8SRichard Henderson } 22072786a3f8SRichard Henderson } 22082786a3f8SRichard Henderson break; 22092786a3f8SRichard Henderson #else 22102786a3f8SRichard Henderson g_assert_not_reached(); 22112786a3f8SRichard Henderson #endif 22122786a3f8SRichard Henderson 2213fcf5ef2aSThomas Huth default: 2214fcf5ef2aSThomas Huth /* ??? In theory we've handled all of the ASIs that are valid 2215fcf5ef2aSThomas Huth for ldda, and this should raise DAE_invalid_asi. However, 2216fcf5ef2aSThomas Huth real hardware allows others. This can be seen with e.g. 2217fcf5ef2aSThomas Huth FreeBSD 10.3 wrt ASI_IC_TAG. */ 2218fcf5ef2aSThomas Huth { 2219c03a0fd1SRichard Henderson TCGv_i32 r_asi = tcg_constant_i32(da->asi); 2220c03a0fd1SRichard Henderson TCGv_i32 r_mop = tcg_constant_i32(da->memop); 2221fcf5ef2aSThomas Huth TCGv_i64 tmp = tcg_temp_new_i64(); 2222fcf5ef2aSThomas Huth 2223fcf5ef2aSThomas Huth save_state(dc); 2224ad75a51eSRichard Henderson gen_helper_ld_asi(tmp, tcg_env, addr, r_asi, r_mop); 2225fcf5ef2aSThomas Huth 2226fcf5ef2aSThomas Huth /* See above. */ 2227c03a0fd1SRichard Henderson if ((da->memop & MO_BSWAP) == MO_TE) { 2228a76779eeSRichard Henderson tcg_gen_extr_i64_tl(lo, hi, tmp); 2229fcf5ef2aSThomas Huth } else { 2230a76779eeSRichard Henderson tcg_gen_extr_i64_tl(hi, lo, tmp); 2231fcf5ef2aSThomas Huth } 2232fcf5ef2aSThomas Huth } 2233fcf5ef2aSThomas Huth break; 2234fcf5ef2aSThomas Huth } 2235fcf5ef2aSThomas Huth 2236fcf5ef2aSThomas Huth gen_store_gpr(dc, rd, hi); 2237fcf5ef2aSThomas Huth gen_store_gpr(dc, rd + 1, lo); 2238fcf5ef2aSThomas Huth } 2239fcf5ef2aSThomas Huth 224042071fc1SRichard Henderson static void gen_stda_asi(DisasContext *dc, DisasASI *da, TCGv addr, int rd) 2241c03a0fd1SRichard Henderson { 2242c03a0fd1SRichard Henderson TCGv hi = gen_load_gpr(dc, rd); 2243fcf5ef2aSThomas Huth TCGv lo = gen_load_gpr(dc, rd + 1); 2244fcf5ef2aSThomas Huth 2245c03a0fd1SRichard Henderson switch (da->type) { 2246fcf5ef2aSThomas Huth case GET_ASI_EXCP: 2247fcf5ef2aSThomas Huth break; 2248fcf5ef2aSThomas Huth 2249fcf5ef2aSThomas Huth case GET_ASI_DTWINX: 2250ebbbec92SRichard Henderson #ifdef TARGET_SPARC64 2251ebbbec92SRichard Henderson { 2252ebbbec92SRichard Henderson MemOp mop = (da->memop & MO_BSWAP) | MO_128 | MO_ALIGN_16; 2253ebbbec92SRichard Henderson TCGv_i128 t = tcg_temp_new_i128(); 2254ebbbec92SRichard Henderson 2255ebbbec92SRichard Henderson /* 2256ebbbec92SRichard Henderson * Note that LE twinx acts as if each 64-bit register result is 2257ebbbec92SRichard Henderson * byte swapped. We perform one 128-bit LE store, so must swap 2258ebbbec92SRichard Henderson * the order of the construction. 2259ebbbec92SRichard Henderson */ 2260ebbbec92SRichard Henderson if ((mop & MO_BSWAP) == MO_TE) { 2261ebbbec92SRichard Henderson tcg_gen_concat_i64_i128(t, lo, hi); 2262ebbbec92SRichard Henderson } else { 2263ebbbec92SRichard Henderson tcg_gen_concat_i64_i128(t, hi, lo); 2264ebbbec92SRichard Henderson } 2265ebbbec92SRichard Henderson tcg_gen_qemu_st_i128(t, addr, da->mem_idx, mop); 2266ebbbec92SRichard Henderson } 2267fcf5ef2aSThomas Huth break; 2268ebbbec92SRichard Henderson #else 2269ebbbec92SRichard Henderson g_assert_not_reached(); 2270ebbbec92SRichard Henderson #endif 2271fcf5ef2aSThomas Huth 2272fcf5ef2aSThomas Huth case GET_ASI_DIRECT: 2273fcf5ef2aSThomas Huth { 2274fcf5ef2aSThomas Huth TCGv_i64 t64 = tcg_temp_new_i64(); 2275fcf5ef2aSThomas Huth 2276fcf5ef2aSThomas Huth /* Note that LE stda acts as if each 32-bit register result is 2277fcf5ef2aSThomas Huth byte swapped. We will perform one 64-bit LE store, so now 2278fcf5ef2aSThomas Huth we must swap the order of the construction. */ 2279c03a0fd1SRichard Henderson if ((da->memop & MO_BSWAP) == MO_TE) { 2280a76779eeSRichard Henderson tcg_gen_concat_tl_i64(t64, lo, hi); 2281fcf5ef2aSThomas Huth } else { 2282a76779eeSRichard Henderson tcg_gen_concat_tl_i64(t64, hi, lo); 2283fcf5ef2aSThomas Huth } 2284c03a0fd1SRichard Henderson tcg_gen_qemu_st_i64(t64, addr, da->mem_idx, da->memop | MO_ALIGN); 2285fcf5ef2aSThomas Huth } 2286fcf5ef2aSThomas Huth break; 2287fcf5ef2aSThomas Huth 2288a76779eeSRichard Henderson case GET_ASI_BFILL: 2289a76779eeSRichard Henderson assert(TARGET_LONG_BITS == 32); 229054c3e953SRichard Henderson /* 229154c3e953SRichard Henderson * Store 32 bytes of [rd:rd+1] to ADDR. 229254c3e953SRichard Henderson * See comments for GET_ASI_COPY above. 229354c3e953SRichard Henderson */ 2294a76779eeSRichard Henderson { 229554c3e953SRichard Henderson MemOp mop = MO_TE | MO_128 | MO_ATOM_IFALIGN_PAIR; 229654c3e953SRichard Henderson TCGv_i64 t8 = tcg_temp_new_i64(); 229754c3e953SRichard Henderson TCGv_i128 t16 = tcg_temp_new_i128(); 229854c3e953SRichard Henderson TCGv daddr = tcg_temp_new(); 2299a76779eeSRichard Henderson 230054c3e953SRichard Henderson tcg_gen_concat_tl_i64(t8, lo, hi); 230154c3e953SRichard Henderson tcg_gen_concat_i64_i128(t16, t8, t8); 230254c3e953SRichard Henderson tcg_gen_andi_tl(daddr, addr, -32); 230354c3e953SRichard Henderson tcg_gen_qemu_st_i128(t16, daddr, da->mem_idx, mop); 230454c3e953SRichard Henderson tcg_gen_addi_tl(daddr, daddr, 16); 230554c3e953SRichard Henderson tcg_gen_qemu_st_i128(t16, daddr, da->mem_idx, mop); 2306a76779eeSRichard Henderson } 2307a76779eeSRichard Henderson break; 2308a76779eeSRichard Henderson 2309fcf5ef2aSThomas Huth default: 2310fcf5ef2aSThomas Huth /* ??? In theory we've handled all of the ASIs that are valid 2311fcf5ef2aSThomas Huth for stda, and this should raise DAE_invalid_asi. */ 2312fcf5ef2aSThomas Huth { 2313c03a0fd1SRichard Henderson TCGv_i32 r_asi = tcg_constant_i32(da->asi); 2314c03a0fd1SRichard Henderson TCGv_i32 r_mop = tcg_constant_i32(da->memop); 2315fcf5ef2aSThomas Huth TCGv_i64 t64 = tcg_temp_new_i64(); 2316fcf5ef2aSThomas Huth 2317fcf5ef2aSThomas Huth /* See above. */ 2318c03a0fd1SRichard Henderson if ((da->memop & MO_BSWAP) == MO_TE) { 2319a76779eeSRichard Henderson tcg_gen_concat_tl_i64(t64, lo, hi); 2320fcf5ef2aSThomas Huth } else { 2321a76779eeSRichard Henderson tcg_gen_concat_tl_i64(t64, hi, lo); 2322fcf5ef2aSThomas Huth } 2323fcf5ef2aSThomas Huth 2324fcf5ef2aSThomas Huth save_state(dc); 2325ad75a51eSRichard Henderson gen_helper_st_asi(tcg_env, addr, t64, r_asi, r_mop); 2326fcf5ef2aSThomas Huth } 2327fcf5ef2aSThomas Huth break; 2328fcf5ef2aSThomas Huth } 2329fcf5ef2aSThomas Huth } 2330fcf5ef2aSThomas Huth 2331fcf5ef2aSThomas Huth static void gen_fmovs(DisasContext *dc, DisasCompare *cmp, int rd, int rs) 2332fcf5ef2aSThomas Huth { 2333f7ec8155SRichard Henderson #ifdef TARGET_SPARC64 2334fcf5ef2aSThomas Huth TCGv_i32 c32, zero, dst, s1, s2; 2335dd7dbfccSRichard Henderson TCGv_i64 c64 = tcg_temp_new_i64(); 2336fcf5ef2aSThomas Huth 2337fcf5ef2aSThomas Huth /* We have two choices here: extend the 32 bit data and use movcond_i64, 2338fcf5ef2aSThomas Huth or fold the comparison down to 32 bits and use movcond_i32. Choose 2339fcf5ef2aSThomas Huth the later. */ 2340fcf5ef2aSThomas Huth c32 = tcg_temp_new_i32(); 2341c8507ebfSRichard Henderson tcg_gen_setcondi_i64(cmp->cond, c64, cmp->c1, cmp->c2); 2342fcf5ef2aSThomas Huth tcg_gen_extrl_i64_i32(c32, c64); 2343fcf5ef2aSThomas Huth 2344fcf5ef2aSThomas Huth s1 = gen_load_fpr_F(dc, rs); 2345fcf5ef2aSThomas Huth s2 = gen_load_fpr_F(dc, rd); 2346388a6465SRichard Henderson dst = tcg_temp_new_i32(); 234700ab7e61SRichard Henderson zero = tcg_constant_i32(0); 2348fcf5ef2aSThomas Huth 2349fcf5ef2aSThomas Huth tcg_gen_movcond_i32(TCG_COND_NE, dst, c32, zero, s1, s2); 2350fcf5ef2aSThomas Huth 2351fcf5ef2aSThomas Huth gen_store_fpr_F(dc, rd, dst); 2352f7ec8155SRichard Henderson #else 2353f7ec8155SRichard Henderson qemu_build_not_reached(); 2354f7ec8155SRichard Henderson #endif 2355fcf5ef2aSThomas Huth } 2356fcf5ef2aSThomas Huth 2357fcf5ef2aSThomas Huth static void gen_fmovd(DisasContext *dc, DisasCompare *cmp, int rd, int rs) 2358fcf5ef2aSThomas Huth { 2359f7ec8155SRichard Henderson #ifdef TARGET_SPARC64 236052f46d46SRichard Henderson TCGv_i64 dst = tcg_temp_new_i64(); 2361c8507ebfSRichard Henderson tcg_gen_movcond_i64(cmp->cond, dst, cmp->c1, tcg_constant_tl(cmp->c2), 2362fcf5ef2aSThomas Huth gen_load_fpr_D(dc, rs), 2363fcf5ef2aSThomas Huth gen_load_fpr_D(dc, rd)); 2364fcf5ef2aSThomas Huth gen_store_fpr_D(dc, rd, dst); 2365f7ec8155SRichard Henderson #else 2366f7ec8155SRichard Henderson qemu_build_not_reached(); 2367f7ec8155SRichard Henderson #endif 2368fcf5ef2aSThomas Huth } 2369fcf5ef2aSThomas Huth 2370fcf5ef2aSThomas Huth static void gen_fmovq(DisasContext *dc, DisasCompare *cmp, int rd, int rs) 2371fcf5ef2aSThomas Huth { 2372f7ec8155SRichard Henderson #ifdef TARGET_SPARC64 2373c8507ebfSRichard Henderson TCGv c2 = tcg_constant_tl(cmp->c2); 23741210a036SRichard Henderson TCGv_i64 h = tcg_temp_new_i64(); 23751210a036SRichard Henderson TCGv_i64 l = tcg_temp_new_i64(); 2376fcf5ef2aSThomas Huth 23771210a036SRichard Henderson tcg_gen_movcond_i64(cmp->cond, h, cmp->c1, c2, 23781210a036SRichard Henderson gen_load_fpr_D(dc, rs), 23791210a036SRichard Henderson gen_load_fpr_D(dc, rd)); 23801210a036SRichard Henderson tcg_gen_movcond_i64(cmp->cond, l, cmp->c1, c2, 23811210a036SRichard Henderson gen_load_fpr_D(dc, rs + 2), 23821210a036SRichard Henderson gen_load_fpr_D(dc, rd + 2)); 23831210a036SRichard Henderson gen_store_fpr_D(dc, rd, h); 23841210a036SRichard Henderson gen_store_fpr_D(dc, rd + 2, l); 2385f7ec8155SRichard Henderson #else 2386f7ec8155SRichard Henderson qemu_build_not_reached(); 2387f7ec8155SRichard Henderson #endif 2388fcf5ef2aSThomas Huth } 2389fcf5ef2aSThomas Huth 2390f7ec8155SRichard Henderson #ifdef TARGET_SPARC64 23915d617bfbSRichard Henderson static void gen_load_trap_state_at_tl(TCGv_ptr r_tsptr) 2392fcf5ef2aSThomas Huth { 2393fcf5ef2aSThomas Huth TCGv_i32 r_tl = tcg_temp_new_i32(); 2394fcf5ef2aSThomas Huth 2395fcf5ef2aSThomas Huth /* load env->tl into r_tl */ 2396ad75a51eSRichard Henderson tcg_gen_ld_i32(r_tl, tcg_env, offsetof(CPUSPARCState, tl)); 2397fcf5ef2aSThomas Huth 2398fcf5ef2aSThomas Huth /* tl = [0 ... MAXTL_MASK] where MAXTL_MASK must be power of 2 */ 2399fcf5ef2aSThomas Huth tcg_gen_andi_i32(r_tl, r_tl, MAXTL_MASK); 2400fcf5ef2aSThomas Huth 2401fcf5ef2aSThomas Huth /* calculate offset to current trap state from env->ts, reuse r_tl */ 2402fcf5ef2aSThomas Huth tcg_gen_muli_i32(r_tl, r_tl, sizeof (trap_state)); 2403ad75a51eSRichard Henderson tcg_gen_addi_ptr(r_tsptr, tcg_env, offsetof(CPUSPARCState, ts)); 2404fcf5ef2aSThomas Huth 2405fcf5ef2aSThomas Huth /* tsptr = env->ts[env->tl & MAXTL_MASK] */ 2406fcf5ef2aSThomas Huth { 2407fcf5ef2aSThomas Huth TCGv_ptr r_tl_tmp = tcg_temp_new_ptr(); 2408fcf5ef2aSThomas Huth tcg_gen_ext_i32_ptr(r_tl_tmp, r_tl); 2409fcf5ef2aSThomas Huth tcg_gen_add_ptr(r_tsptr, r_tsptr, r_tl_tmp); 2410fcf5ef2aSThomas Huth } 2411fcf5ef2aSThomas Huth } 2412fcf5ef2aSThomas Huth #endif 2413fcf5ef2aSThomas Huth 241406c060d9SRichard Henderson static int extract_dfpreg(DisasContext *dc, int x) 241506c060d9SRichard Henderson { 24160bba7572SRichard Henderson int r = x & 0x1e; 24170bba7572SRichard Henderson #ifdef TARGET_SPARC64 24180bba7572SRichard Henderson r |= (x & 1) << 5; 24190bba7572SRichard Henderson #endif 24200bba7572SRichard Henderson return r; 242106c060d9SRichard Henderson } 242206c060d9SRichard Henderson 242306c060d9SRichard Henderson static int extract_qfpreg(DisasContext *dc, int x) 242406c060d9SRichard Henderson { 24250bba7572SRichard Henderson int r = x & 0x1c; 24260bba7572SRichard Henderson #ifdef TARGET_SPARC64 24270bba7572SRichard Henderson r |= (x & 1) << 5; 24280bba7572SRichard Henderson #endif 24290bba7572SRichard Henderson return r; 243006c060d9SRichard Henderson } 243106c060d9SRichard Henderson 2432878cc677SRichard Henderson /* Include the auto-generated decoder. */ 2433878cc677SRichard Henderson #include "decode-insns.c.inc" 2434878cc677SRichard Henderson 2435878cc677SRichard Henderson #define TRANS(NAME, AVAIL, FUNC, ...) \ 2436878cc677SRichard Henderson static bool trans_##NAME(DisasContext *dc, arg_##NAME *a) \ 2437878cc677SRichard Henderson { return avail_##AVAIL(dc) && FUNC(dc, __VA_ARGS__); } 2438878cc677SRichard Henderson 2439878cc677SRichard Henderson #define avail_ALL(C) true 2440878cc677SRichard Henderson #ifdef TARGET_SPARC64 2441878cc677SRichard Henderson # define avail_32(C) false 2442af25071cSRichard Henderson # define avail_ASR17(C) false 2443d0a11d25SRichard Henderson # define avail_CASA(C) true 2444c2636853SRichard Henderson # define avail_DIV(C) true 2445b5372650SRichard Henderson # define avail_MUL(C) true 24460faef01bSRichard Henderson # define avail_POWERDOWN(C) false 2447878cc677SRichard Henderson # define avail_64(C) true 24484fd71d19SRichard Henderson # define avail_FMAF(C) ((C)->def->features & CPU_FEATURE_FMAF) 24495d617bfbSRichard Henderson # define avail_GL(C) ((C)->def->features & CPU_FEATURE_GL) 2450af25071cSRichard Henderson # define avail_HYPV(C) ((C)->def->features & CPU_FEATURE_HYPV) 245168a414e9SRichard Henderson # define avail_IMA(C) ((C)->def->features & CPU_FEATURE_IMA) 2452b88ce6f2SRichard Henderson # define avail_VIS1(C) ((C)->def->features & CPU_FEATURE_VIS1) 2453b88ce6f2SRichard Henderson # define avail_VIS2(C) ((C)->def->features & CPU_FEATURE_VIS2) 24543335a048SRichard Henderson # define avail_VIS3(C) ((C)->def->features & CPU_FEATURE_VIS3) 24553335a048SRichard Henderson # define avail_VIS3B(C) avail_VIS3(C) 245690b1433dSRichard Henderson # define avail_VIS4(C) ((C)->def->features & CPU_FEATURE_VIS4) 2457878cc677SRichard Henderson #else 2458878cc677SRichard Henderson # define avail_32(C) true 2459af25071cSRichard Henderson # define avail_ASR17(C) ((C)->def->features & CPU_FEATURE_ASR17) 2460d0a11d25SRichard Henderson # define avail_CASA(C) ((C)->def->features & CPU_FEATURE_CASA) 2461c2636853SRichard Henderson # define avail_DIV(C) ((C)->def->features & CPU_FEATURE_DIV) 2462b5372650SRichard Henderson # define avail_MUL(C) ((C)->def->features & CPU_FEATURE_MUL) 24630faef01bSRichard Henderson # define avail_POWERDOWN(C) ((C)->def->features & CPU_FEATURE_POWERDOWN) 2464878cc677SRichard Henderson # define avail_64(C) false 24654fd71d19SRichard Henderson # define avail_FMAF(C) false 24665d617bfbSRichard Henderson # define avail_GL(C) false 2467af25071cSRichard Henderson # define avail_HYPV(C) false 246868a414e9SRichard Henderson # define avail_IMA(C) false 2469b88ce6f2SRichard Henderson # define avail_VIS1(C) false 2470b88ce6f2SRichard Henderson # define avail_VIS2(C) false 24713335a048SRichard Henderson # define avail_VIS3(C) false 24723335a048SRichard Henderson # define avail_VIS3B(C) false 247390b1433dSRichard Henderson # define avail_VIS4(C) false 2474878cc677SRichard Henderson #endif 2475878cc677SRichard Henderson 2476878cc677SRichard Henderson /* Default case for non jump instructions. */ 2477878cc677SRichard Henderson static bool advance_pc(DisasContext *dc) 2478878cc677SRichard Henderson { 24794a8d145dSRichard Henderson TCGLabel *l1; 24804a8d145dSRichard Henderson 248189527e3aSRichard Henderson finishing_insn(dc); 248289527e3aSRichard Henderson 2483878cc677SRichard Henderson if (dc->npc & 3) { 2484878cc677SRichard Henderson switch (dc->npc) { 2485878cc677SRichard Henderson case DYNAMIC_PC: 2486878cc677SRichard Henderson case DYNAMIC_PC_LOOKUP: 2487878cc677SRichard Henderson dc->pc = dc->npc; 2488444d8b30SRichard Henderson tcg_gen_mov_tl(cpu_pc, cpu_npc); 2489444d8b30SRichard Henderson tcg_gen_addi_tl(cpu_npc, cpu_npc, 4); 2490878cc677SRichard Henderson break; 24914a8d145dSRichard Henderson 2492878cc677SRichard Henderson case JUMP_PC: 2493878cc677SRichard Henderson /* we can do a static jump */ 24944a8d145dSRichard Henderson l1 = gen_new_label(); 2495533f042fSRichard Henderson tcg_gen_brcondi_tl(dc->jump.cond, dc->jump.c1, dc->jump.c2, l1); 24964a8d145dSRichard Henderson 24974a8d145dSRichard Henderson /* jump not taken */ 24984a8d145dSRichard Henderson gen_goto_tb(dc, 1, dc->jump_pc[1], dc->jump_pc[1] + 4); 24994a8d145dSRichard Henderson 25004a8d145dSRichard Henderson /* jump taken */ 25014a8d145dSRichard Henderson gen_set_label(l1); 25024a8d145dSRichard Henderson gen_goto_tb(dc, 0, dc->jump_pc[0], dc->jump_pc[0] + 4); 25034a8d145dSRichard Henderson 2504878cc677SRichard Henderson dc->base.is_jmp = DISAS_NORETURN; 2505878cc677SRichard Henderson break; 25064a8d145dSRichard Henderson 2507878cc677SRichard Henderson default: 2508878cc677SRichard Henderson g_assert_not_reached(); 2509878cc677SRichard Henderson } 2510878cc677SRichard Henderson } else { 2511878cc677SRichard Henderson dc->pc = dc->npc; 2512878cc677SRichard Henderson dc->npc = dc->npc + 4; 2513878cc677SRichard Henderson } 2514878cc677SRichard Henderson return true; 2515878cc677SRichard Henderson } 2516878cc677SRichard Henderson 25176d2a0768SRichard Henderson /* 25186d2a0768SRichard Henderson * Major opcodes 00 and 01 -- branches, call, and sethi 25196d2a0768SRichard Henderson */ 25206d2a0768SRichard Henderson 25219d4e2bc7SRichard Henderson static bool advance_jump_cond(DisasContext *dc, DisasCompare *cmp, 25223951b7a8SRichard Henderson bool annul, int disp) 2523276567aaSRichard Henderson { 25243951b7a8SRichard Henderson target_ulong dest = address_mask_i(dc, dc->pc + disp * 4); 2525c76c8045SRichard Henderson target_ulong npc; 2526c76c8045SRichard Henderson 252789527e3aSRichard Henderson finishing_insn(dc); 252889527e3aSRichard Henderson 25292d9bb237SRichard Henderson if (cmp->cond == TCG_COND_ALWAYS) { 25302d9bb237SRichard Henderson if (annul) { 25312d9bb237SRichard Henderson dc->pc = dest; 25322d9bb237SRichard Henderson dc->npc = dest + 4; 25332d9bb237SRichard Henderson } else { 25342d9bb237SRichard Henderson gen_mov_pc_npc(dc); 25352d9bb237SRichard Henderson dc->npc = dest; 25362d9bb237SRichard Henderson } 25372d9bb237SRichard Henderson return true; 25382d9bb237SRichard Henderson } 25392d9bb237SRichard Henderson 25402d9bb237SRichard Henderson if (cmp->cond == TCG_COND_NEVER) { 25412d9bb237SRichard Henderson npc = dc->npc; 25422d9bb237SRichard Henderson if (npc & 3) { 25432d9bb237SRichard Henderson gen_mov_pc_npc(dc); 25442d9bb237SRichard Henderson if (annul) { 25452d9bb237SRichard Henderson tcg_gen_addi_tl(cpu_pc, cpu_pc, 4); 25462d9bb237SRichard Henderson } 25472d9bb237SRichard Henderson tcg_gen_addi_tl(cpu_npc, cpu_pc, 4); 25482d9bb237SRichard Henderson } else { 25492d9bb237SRichard Henderson dc->pc = npc + (annul ? 4 : 0); 25502d9bb237SRichard Henderson dc->npc = dc->pc + 4; 25512d9bb237SRichard Henderson } 25522d9bb237SRichard Henderson return true; 25532d9bb237SRichard Henderson } 25542d9bb237SRichard Henderson 2555c76c8045SRichard Henderson flush_cond(dc); 2556c76c8045SRichard Henderson npc = dc->npc; 25576b3e4cc6SRichard Henderson 2558276567aaSRichard Henderson if (annul) { 25596b3e4cc6SRichard Henderson TCGLabel *l1 = gen_new_label(); 25606b3e4cc6SRichard Henderson 2561c8507ebfSRichard Henderson tcg_gen_brcondi_tl(tcg_invert_cond(cmp->cond), cmp->c1, cmp->c2, l1); 25626b3e4cc6SRichard Henderson gen_goto_tb(dc, 0, npc, dest); 25636b3e4cc6SRichard Henderson gen_set_label(l1); 25646b3e4cc6SRichard Henderson gen_goto_tb(dc, 1, npc + 4, npc + 8); 25656b3e4cc6SRichard Henderson 25666b3e4cc6SRichard Henderson dc->base.is_jmp = DISAS_NORETURN; 2567276567aaSRichard Henderson } else { 25686b3e4cc6SRichard Henderson if (npc & 3) { 25696b3e4cc6SRichard Henderson switch (npc) { 25706b3e4cc6SRichard Henderson case DYNAMIC_PC: 25716b3e4cc6SRichard Henderson case DYNAMIC_PC_LOOKUP: 25726b3e4cc6SRichard Henderson tcg_gen_mov_tl(cpu_pc, cpu_npc); 25736b3e4cc6SRichard Henderson tcg_gen_addi_tl(cpu_npc, cpu_npc, 4); 25749d4e2bc7SRichard Henderson tcg_gen_movcond_tl(cmp->cond, cpu_npc, 2575c8507ebfSRichard Henderson cmp->c1, tcg_constant_tl(cmp->c2), 25766b3e4cc6SRichard Henderson tcg_constant_tl(dest), cpu_npc); 25776b3e4cc6SRichard Henderson dc->pc = npc; 25786b3e4cc6SRichard Henderson break; 25796b3e4cc6SRichard Henderson default: 25806b3e4cc6SRichard Henderson g_assert_not_reached(); 25816b3e4cc6SRichard Henderson } 25826b3e4cc6SRichard Henderson } else { 25836b3e4cc6SRichard Henderson dc->pc = npc; 2584533f042fSRichard Henderson dc->npc = JUMP_PC; 2585533f042fSRichard Henderson dc->jump = *cmp; 25866b3e4cc6SRichard Henderson dc->jump_pc[0] = dest; 25876b3e4cc6SRichard Henderson dc->jump_pc[1] = npc + 4; 2588dd7dbfccSRichard Henderson 2589dd7dbfccSRichard Henderson /* The condition for cpu_cond is always NE -- normalize. */ 2590dd7dbfccSRichard Henderson if (cmp->cond == TCG_COND_NE) { 2591c8507ebfSRichard Henderson tcg_gen_xori_tl(cpu_cond, cmp->c1, cmp->c2); 25929d4e2bc7SRichard Henderson } else { 2593c8507ebfSRichard Henderson tcg_gen_setcondi_tl(cmp->cond, cpu_cond, cmp->c1, cmp->c2); 25949d4e2bc7SRichard Henderson } 259589527e3aSRichard Henderson dc->cpu_cond_live = true; 25966b3e4cc6SRichard Henderson } 2597276567aaSRichard Henderson } 2598276567aaSRichard Henderson return true; 2599276567aaSRichard Henderson } 2600276567aaSRichard Henderson 2601af25071cSRichard Henderson static bool raise_priv(DisasContext *dc) 2602af25071cSRichard Henderson { 2603af25071cSRichard Henderson gen_exception(dc, TT_PRIV_INSN); 2604af25071cSRichard Henderson return true; 2605af25071cSRichard Henderson } 2606af25071cSRichard Henderson 260706c060d9SRichard Henderson static bool raise_unimpfpop(DisasContext *dc) 260806c060d9SRichard Henderson { 260906c060d9SRichard Henderson gen_op_fpexception_im(dc, FSR_FTT_UNIMPFPOP); 261006c060d9SRichard Henderson return true; 261106c060d9SRichard Henderson } 261206c060d9SRichard Henderson 261306c060d9SRichard Henderson static bool gen_trap_float128(DisasContext *dc) 261406c060d9SRichard Henderson { 261506c060d9SRichard Henderson if (dc->def->features & CPU_FEATURE_FLOAT128) { 261606c060d9SRichard Henderson return false; 261706c060d9SRichard Henderson } 261806c060d9SRichard Henderson return raise_unimpfpop(dc); 261906c060d9SRichard Henderson } 262006c060d9SRichard Henderson 2621276567aaSRichard Henderson static bool do_bpcc(DisasContext *dc, arg_bcc *a) 2622276567aaSRichard Henderson { 26231ea9c62aSRichard Henderson DisasCompare cmp; 2624276567aaSRichard Henderson 26251ea9c62aSRichard Henderson gen_compare(&cmp, a->cc, a->cond, dc); 26263951b7a8SRichard Henderson return advance_jump_cond(dc, &cmp, a->a, a->i); 2627276567aaSRichard Henderson } 2628276567aaSRichard Henderson 2629276567aaSRichard Henderson TRANS(Bicc, ALL, do_bpcc, a) 2630276567aaSRichard Henderson TRANS(BPcc, 64, do_bpcc, a) 2631276567aaSRichard Henderson 263245196ea4SRichard Henderson static bool do_fbpfcc(DisasContext *dc, arg_bcc *a) 263345196ea4SRichard Henderson { 2634d5471936SRichard Henderson DisasCompare cmp; 263545196ea4SRichard Henderson 263645196ea4SRichard Henderson if (gen_trap_ifnofpu(dc)) { 263745196ea4SRichard Henderson return true; 263845196ea4SRichard Henderson } 2639d5471936SRichard Henderson gen_fcompare(&cmp, a->cc, a->cond); 26403951b7a8SRichard Henderson return advance_jump_cond(dc, &cmp, a->a, a->i); 264145196ea4SRichard Henderson } 264245196ea4SRichard Henderson 264345196ea4SRichard Henderson TRANS(FBPfcc, 64, do_fbpfcc, a) 264445196ea4SRichard Henderson TRANS(FBfcc, ALL, do_fbpfcc, a) 264545196ea4SRichard Henderson 2646ab9ffe98SRichard Henderson static bool trans_BPr(DisasContext *dc, arg_BPr *a) 2647ab9ffe98SRichard Henderson { 2648ab9ffe98SRichard Henderson DisasCompare cmp; 2649ab9ffe98SRichard Henderson 2650ab9ffe98SRichard Henderson if (!avail_64(dc)) { 2651ab9ffe98SRichard Henderson return false; 2652ab9ffe98SRichard Henderson } 26532c4f56c9SRichard Henderson if (!gen_compare_reg(&cmp, a->cond, gen_load_gpr(dc, a->rs1))) { 2654ab9ffe98SRichard Henderson return false; 2655ab9ffe98SRichard Henderson } 26563951b7a8SRichard Henderson return advance_jump_cond(dc, &cmp, a->a, a->i); 2657ab9ffe98SRichard Henderson } 2658ab9ffe98SRichard Henderson 265923ada1b1SRichard Henderson static bool trans_CALL(DisasContext *dc, arg_CALL *a) 266023ada1b1SRichard Henderson { 266123ada1b1SRichard Henderson target_long target = address_mask_i(dc, dc->pc + a->i * 4); 266223ada1b1SRichard Henderson 266323ada1b1SRichard Henderson gen_store_gpr(dc, 15, tcg_constant_tl(dc->pc)); 266423ada1b1SRichard Henderson gen_mov_pc_npc(dc); 266523ada1b1SRichard Henderson dc->npc = target; 266623ada1b1SRichard Henderson return true; 266723ada1b1SRichard Henderson } 266823ada1b1SRichard Henderson 266945196ea4SRichard Henderson static bool trans_NCP(DisasContext *dc, arg_NCP *a) 267045196ea4SRichard Henderson { 267145196ea4SRichard Henderson /* 267245196ea4SRichard Henderson * For sparc32, always generate the no-coprocessor exception. 267345196ea4SRichard Henderson * For sparc64, always generate illegal instruction. 267445196ea4SRichard Henderson */ 267545196ea4SRichard Henderson #ifdef TARGET_SPARC64 267645196ea4SRichard Henderson return false; 267745196ea4SRichard Henderson #else 267845196ea4SRichard Henderson gen_exception(dc, TT_NCP_INSN); 267945196ea4SRichard Henderson return true; 268045196ea4SRichard Henderson #endif 268145196ea4SRichard Henderson } 268245196ea4SRichard Henderson 26836d2a0768SRichard Henderson static bool trans_SETHI(DisasContext *dc, arg_SETHI *a) 26846d2a0768SRichard Henderson { 26856d2a0768SRichard Henderson /* Special-case %g0 because that's the canonical nop. */ 26866d2a0768SRichard Henderson if (a->rd) { 26876d2a0768SRichard Henderson gen_store_gpr(dc, a->rd, tcg_constant_tl((uint32_t)a->i << 10)); 26886d2a0768SRichard Henderson } 26896d2a0768SRichard Henderson return advance_pc(dc); 26906d2a0768SRichard Henderson } 26916d2a0768SRichard Henderson 26920faef01bSRichard Henderson /* 26930faef01bSRichard Henderson * Major Opcode 10 -- integer, floating-point, vis, and system insns. 26940faef01bSRichard Henderson */ 26950faef01bSRichard Henderson 269630376636SRichard Henderson static bool do_tcc(DisasContext *dc, int cond, int cc, 269730376636SRichard Henderson int rs1, bool imm, int rs2_or_imm) 269830376636SRichard Henderson { 269930376636SRichard Henderson int mask = ((dc->def->features & CPU_FEATURE_HYPV) && supervisor(dc) 270030376636SRichard Henderson ? UA2005_HTRAP_MASK : V8_TRAP_MASK); 270130376636SRichard Henderson DisasCompare cmp; 270230376636SRichard Henderson TCGLabel *lab; 270330376636SRichard Henderson TCGv_i32 trap; 270430376636SRichard Henderson 270530376636SRichard Henderson /* Trap never. */ 270630376636SRichard Henderson if (cond == 0) { 270730376636SRichard Henderson return advance_pc(dc); 270830376636SRichard Henderson } 270930376636SRichard Henderson 271030376636SRichard Henderson /* 271130376636SRichard Henderson * Immediate traps are the most common case. Since this value is 271230376636SRichard Henderson * live across the branch, it really pays to evaluate the constant. 271330376636SRichard Henderson */ 271430376636SRichard Henderson if (rs1 == 0 && (imm || rs2_or_imm == 0)) { 271530376636SRichard Henderson trap = tcg_constant_i32((rs2_or_imm & mask) + TT_TRAP); 271630376636SRichard Henderson } else { 271730376636SRichard Henderson trap = tcg_temp_new_i32(); 271830376636SRichard Henderson tcg_gen_trunc_tl_i32(trap, gen_load_gpr(dc, rs1)); 271930376636SRichard Henderson if (imm) { 272030376636SRichard Henderson tcg_gen_addi_i32(trap, trap, rs2_or_imm); 272130376636SRichard Henderson } else { 272230376636SRichard Henderson TCGv_i32 t2 = tcg_temp_new_i32(); 272330376636SRichard Henderson tcg_gen_trunc_tl_i32(t2, gen_load_gpr(dc, rs2_or_imm)); 272430376636SRichard Henderson tcg_gen_add_i32(trap, trap, t2); 272530376636SRichard Henderson } 272630376636SRichard Henderson tcg_gen_andi_i32(trap, trap, mask); 272730376636SRichard Henderson tcg_gen_addi_i32(trap, trap, TT_TRAP); 272830376636SRichard Henderson } 272930376636SRichard Henderson 273089527e3aSRichard Henderson finishing_insn(dc); 273189527e3aSRichard Henderson 273230376636SRichard Henderson /* Trap always. */ 273330376636SRichard Henderson if (cond == 8) { 273430376636SRichard Henderson save_state(dc); 273530376636SRichard Henderson gen_helper_raise_exception(tcg_env, trap); 273630376636SRichard Henderson dc->base.is_jmp = DISAS_NORETURN; 273730376636SRichard Henderson return true; 273830376636SRichard Henderson } 273930376636SRichard Henderson 274030376636SRichard Henderson /* Conditional trap. */ 274130376636SRichard Henderson flush_cond(dc); 274230376636SRichard Henderson lab = delay_exceptionv(dc, trap); 274330376636SRichard Henderson gen_compare(&cmp, cc, cond, dc); 2744c8507ebfSRichard Henderson tcg_gen_brcondi_tl(cmp.cond, cmp.c1, cmp.c2, lab); 274530376636SRichard Henderson 274630376636SRichard Henderson return advance_pc(dc); 274730376636SRichard Henderson } 274830376636SRichard Henderson 274930376636SRichard Henderson static bool trans_Tcc_r(DisasContext *dc, arg_Tcc_r *a) 275030376636SRichard Henderson { 275130376636SRichard Henderson if (avail_32(dc) && a->cc) { 275230376636SRichard Henderson return false; 275330376636SRichard Henderson } 275430376636SRichard Henderson return do_tcc(dc, a->cond, a->cc, a->rs1, false, a->rs2); 275530376636SRichard Henderson } 275630376636SRichard Henderson 275730376636SRichard Henderson static bool trans_Tcc_i_v7(DisasContext *dc, arg_Tcc_i_v7 *a) 275830376636SRichard Henderson { 275930376636SRichard Henderson if (avail_64(dc)) { 276030376636SRichard Henderson return false; 276130376636SRichard Henderson } 276230376636SRichard Henderson return do_tcc(dc, a->cond, 0, a->rs1, true, a->i); 276330376636SRichard Henderson } 276430376636SRichard Henderson 276530376636SRichard Henderson static bool trans_Tcc_i_v9(DisasContext *dc, arg_Tcc_i_v9 *a) 276630376636SRichard Henderson { 276730376636SRichard Henderson if (avail_32(dc)) { 276830376636SRichard Henderson return false; 276930376636SRichard Henderson } 277030376636SRichard Henderson return do_tcc(dc, a->cond, a->cc, a->rs1, true, a->i); 277130376636SRichard Henderson } 277230376636SRichard Henderson 2773af25071cSRichard Henderson static bool trans_STBAR(DisasContext *dc, arg_STBAR *a) 2774af25071cSRichard Henderson { 2775af25071cSRichard Henderson tcg_gen_mb(TCG_MO_ST_ST | TCG_BAR_SC); 2776af25071cSRichard Henderson return advance_pc(dc); 2777af25071cSRichard Henderson } 2778af25071cSRichard Henderson 2779af25071cSRichard Henderson static bool trans_MEMBAR(DisasContext *dc, arg_MEMBAR *a) 2780af25071cSRichard Henderson { 2781af25071cSRichard Henderson if (avail_32(dc)) { 2782af25071cSRichard Henderson return false; 2783af25071cSRichard Henderson } 2784af25071cSRichard Henderson if (a->mmask) { 2785af25071cSRichard Henderson /* Note TCG_MO_* was modeled on sparc64, so mmask matches. */ 2786af25071cSRichard Henderson tcg_gen_mb(a->mmask | TCG_BAR_SC); 2787af25071cSRichard Henderson } 2788af25071cSRichard Henderson if (a->cmask) { 2789af25071cSRichard Henderson /* For #Sync, etc, end the TB to recognize interrupts. */ 2790af25071cSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 2791af25071cSRichard Henderson } 2792af25071cSRichard Henderson return advance_pc(dc); 2793af25071cSRichard Henderson } 2794af25071cSRichard Henderson 2795af25071cSRichard Henderson static bool do_rd_special(DisasContext *dc, bool priv, int rd, 2796af25071cSRichard Henderson TCGv (*func)(DisasContext *, TCGv)) 2797af25071cSRichard Henderson { 2798af25071cSRichard Henderson if (!priv) { 2799af25071cSRichard Henderson return raise_priv(dc); 2800af25071cSRichard Henderson } 2801af25071cSRichard Henderson gen_store_gpr(dc, rd, func(dc, gen_dest_gpr(dc, rd))); 2802af25071cSRichard Henderson return advance_pc(dc); 2803af25071cSRichard Henderson } 2804af25071cSRichard Henderson 2805af25071cSRichard Henderson static TCGv do_rdy(DisasContext *dc, TCGv dst) 2806af25071cSRichard Henderson { 2807af25071cSRichard Henderson return cpu_y; 2808af25071cSRichard Henderson } 2809af25071cSRichard Henderson 2810af25071cSRichard Henderson static bool trans_RDY(DisasContext *dc, arg_RDY *a) 2811af25071cSRichard Henderson { 2812af25071cSRichard Henderson /* 2813af25071cSRichard Henderson * TODO: Need a feature bit for sparcv8. In the meantime, treat all 2814af25071cSRichard Henderson * 32-bit cpus like sparcv7, which ignores the rs1 field. 2815af25071cSRichard Henderson * This matches after all other ASR, so Leon3 Asr17 is handled first. 2816af25071cSRichard Henderson */ 2817af25071cSRichard Henderson if (avail_64(dc) && a->rs1 != 0) { 2818af25071cSRichard Henderson return false; 2819af25071cSRichard Henderson } 2820af25071cSRichard Henderson return do_rd_special(dc, true, a->rd, do_rdy); 2821af25071cSRichard Henderson } 2822af25071cSRichard Henderson 2823af25071cSRichard Henderson static TCGv do_rd_leon3_config(DisasContext *dc, TCGv dst) 2824af25071cSRichard Henderson { 2825c92948f2SClément Chigot gen_helper_rdasr17(dst, tcg_env); 2826c92948f2SClément Chigot return dst; 2827af25071cSRichard Henderson } 2828af25071cSRichard Henderson 2829af25071cSRichard Henderson TRANS(RDASR17, ASR17, do_rd_special, true, a->rd, do_rd_leon3_config) 2830af25071cSRichard Henderson 2831af25071cSRichard Henderson static TCGv do_rdccr(DisasContext *dc, TCGv dst) 2832af25071cSRichard Henderson { 2833af25071cSRichard Henderson gen_helper_rdccr(dst, tcg_env); 2834af25071cSRichard Henderson return dst; 2835af25071cSRichard Henderson } 2836af25071cSRichard Henderson 2837af25071cSRichard Henderson TRANS(RDCCR, 64, do_rd_special, true, a->rd, do_rdccr) 2838af25071cSRichard Henderson 2839af25071cSRichard Henderson static TCGv do_rdasi(DisasContext *dc, TCGv dst) 2840af25071cSRichard Henderson { 2841af25071cSRichard Henderson #ifdef TARGET_SPARC64 2842af25071cSRichard Henderson return tcg_constant_tl(dc->asi); 2843af25071cSRichard Henderson #else 2844af25071cSRichard Henderson qemu_build_not_reached(); 2845af25071cSRichard Henderson #endif 2846af25071cSRichard Henderson } 2847af25071cSRichard Henderson 2848af25071cSRichard Henderson TRANS(RDASI, 64, do_rd_special, true, a->rd, do_rdasi) 2849af25071cSRichard Henderson 2850af25071cSRichard Henderson static TCGv do_rdtick(DisasContext *dc, TCGv dst) 2851af25071cSRichard Henderson { 2852af25071cSRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr(); 2853af25071cSRichard Henderson 2854af25071cSRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(tick)); 2855af25071cSRichard Henderson if (translator_io_start(&dc->base)) { 2856af25071cSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 2857af25071cSRichard Henderson } 2858af25071cSRichard Henderson gen_helper_tick_get_count(dst, tcg_env, r_tickptr, 2859af25071cSRichard Henderson tcg_constant_i32(dc->mem_idx)); 2860af25071cSRichard Henderson return dst; 2861af25071cSRichard Henderson } 2862af25071cSRichard Henderson 2863af25071cSRichard Henderson /* TODO: non-priv access only allowed when enabled. */ 2864af25071cSRichard Henderson TRANS(RDTICK, 64, do_rd_special, true, a->rd, do_rdtick) 2865af25071cSRichard Henderson 2866af25071cSRichard Henderson static TCGv do_rdpc(DisasContext *dc, TCGv dst) 2867af25071cSRichard Henderson { 2868af25071cSRichard Henderson return tcg_constant_tl(address_mask_i(dc, dc->pc)); 2869af25071cSRichard Henderson } 2870af25071cSRichard Henderson 2871af25071cSRichard Henderson TRANS(RDPC, 64, do_rd_special, true, a->rd, do_rdpc) 2872af25071cSRichard Henderson 2873af25071cSRichard Henderson static TCGv do_rdfprs(DisasContext *dc, TCGv dst) 2874af25071cSRichard Henderson { 2875af25071cSRichard Henderson tcg_gen_ext_i32_tl(dst, cpu_fprs); 2876af25071cSRichard Henderson return dst; 2877af25071cSRichard Henderson } 2878af25071cSRichard Henderson 2879af25071cSRichard Henderson TRANS(RDFPRS, 64, do_rd_special, true, a->rd, do_rdfprs) 2880af25071cSRichard Henderson 2881af25071cSRichard Henderson static TCGv do_rdgsr(DisasContext *dc, TCGv dst) 2882af25071cSRichard Henderson { 2883af25071cSRichard Henderson gen_trap_ifnofpu(dc); 2884af25071cSRichard Henderson return cpu_gsr; 2885af25071cSRichard Henderson } 2886af25071cSRichard Henderson 2887af25071cSRichard Henderson TRANS(RDGSR, 64, do_rd_special, true, a->rd, do_rdgsr) 2888af25071cSRichard Henderson 2889af25071cSRichard Henderson static TCGv do_rdsoftint(DisasContext *dc, TCGv dst) 2890af25071cSRichard Henderson { 2891af25071cSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(softint)); 2892af25071cSRichard Henderson return dst; 2893af25071cSRichard Henderson } 2894af25071cSRichard Henderson 2895af25071cSRichard Henderson TRANS(RDSOFTINT, 64, do_rd_special, supervisor(dc), a->rd, do_rdsoftint) 2896af25071cSRichard Henderson 2897af25071cSRichard Henderson static TCGv do_rdtick_cmpr(DisasContext *dc, TCGv dst) 2898af25071cSRichard Henderson { 2899577efa45SRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(tick_cmpr)); 2900577efa45SRichard Henderson return dst; 2901af25071cSRichard Henderson } 2902af25071cSRichard Henderson 2903af25071cSRichard Henderson /* TODO: non-priv access only allowed when enabled. */ 2904af25071cSRichard Henderson TRANS(RDTICK_CMPR, 64, do_rd_special, true, a->rd, do_rdtick_cmpr) 2905af25071cSRichard Henderson 2906af25071cSRichard Henderson static TCGv do_rdstick(DisasContext *dc, TCGv dst) 2907af25071cSRichard Henderson { 2908af25071cSRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr(); 2909af25071cSRichard Henderson 2910af25071cSRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(stick)); 2911af25071cSRichard Henderson if (translator_io_start(&dc->base)) { 2912af25071cSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 2913af25071cSRichard Henderson } 2914af25071cSRichard Henderson gen_helper_tick_get_count(dst, tcg_env, r_tickptr, 2915af25071cSRichard Henderson tcg_constant_i32(dc->mem_idx)); 2916af25071cSRichard Henderson return dst; 2917af25071cSRichard Henderson } 2918af25071cSRichard Henderson 2919af25071cSRichard Henderson /* TODO: non-priv access only allowed when enabled. */ 2920af25071cSRichard Henderson TRANS(RDSTICK, 64, do_rd_special, true, a->rd, do_rdstick) 2921af25071cSRichard Henderson 2922af25071cSRichard Henderson static TCGv do_rdstick_cmpr(DisasContext *dc, TCGv dst) 2923af25071cSRichard Henderson { 2924577efa45SRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(stick_cmpr)); 2925577efa45SRichard Henderson return dst; 2926af25071cSRichard Henderson } 2927af25071cSRichard Henderson 2928af25071cSRichard Henderson /* TODO: supervisor access only allowed when enabled by hypervisor. */ 2929af25071cSRichard Henderson TRANS(RDSTICK_CMPR, 64, do_rd_special, supervisor(dc), a->rd, do_rdstick_cmpr) 2930af25071cSRichard Henderson 2931af25071cSRichard Henderson /* 2932af25071cSRichard Henderson * UltraSPARC-T1 Strand status. 2933af25071cSRichard Henderson * HYPV check maybe not enough, UA2005 & UA2007 describe 2934af25071cSRichard Henderson * this ASR as impl. dep 2935af25071cSRichard Henderson */ 2936af25071cSRichard Henderson static TCGv do_rdstrand_status(DisasContext *dc, TCGv dst) 2937af25071cSRichard Henderson { 2938af25071cSRichard Henderson return tcg_constant_tl(1); 2939af25071cSRichard Henderson } 2940af25071cSRichard Henderson 2941af25071cSRichard Henderson TRANS(RDSTRAND_STATUS, HYPV, do_rd_special, true, a->rd, do_rdstrand_status) 2942af25071cSRichard Henderson 2943668bb9b7SRichard Henderson static TCGv do_rdpsr(DisasContext *dc, TCGv dst) 2944668bb9b7SRichard Henderson { 2945668bb9b7SRichard Henderson gen_helper_rdpsr(dst, tcg_env); 2946668bb9b7SRichard Henderson return dst; 2947668bb9b7SRichard Henderson } 2948668bb9b7SRichard Henderson 2949668bb9b7SRichard Henderson TRANS(RDPSR, 32, do_rd_special, supervisor(dc), a->rd, do_rdpsr) 2950668bb9b7SRichard Henderson 2951668bb9b7SRichard Henderson static TCGv do_rdhpstate(DisasContext *dc, TCGv dst) 2952668bb9b7SRichard Henderson { 2953668bb9b7SRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hpstate)); 2954668bb9b7SRichard Henderson return dst; 2955668bb9b7SRichard Henderson } 2956668bb9b7SRichard Henderson 2957668bb9b7SRichard Henderson TRANS(RDHPR_hpstate, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhpstate) 2958668bb9b7SRichard Henderson 2959668bb9b7SRichard Henderson static TCGv do_rdhtstate(DisasContext *dc, TCGv dst) 2960668bb9b7SRichard Henderson { 2961668bb9b7SRichard Henderson TCGv_i32 tl = tcg_temp_new_i32(); 2962668bb9b7SRichard Henderson TCGv_ptr tp = tcg_temp_new_ptr(); 2963668bb9b7SRichard Henderson 2964668bb9b7SRichard Henderson tcg_gen_ld_i32(tl, tcg_env, env64_field_offsetof(tl)); 2965668bb9b7SRichard Henderson tcg_gen_andi_i32(tl, tl, MAXTL_MASK); 2966668bb9b7SRichard Henderson tcg_gen_shli_i32(tl, tl, 3); 2967668bb9b7SRichard Henderson tcg_gen_ext_i32_ptr(tp, tl); 2968668bb9b7SRichard Henderson tcg_gen_add_ptr(tp, tp, tcg_env); 2969668bb9b7SRichard Henderson 2970668bb9b7SRichard Henderson tcg_gen_ld_tl(dst, tp, env64_field_offsetof(htstate)); 2971668bb9b7SRichard Henderson return dst; 2972668bb9b7SRichard Henderson } 2973668bb9b7SRichard Henderson 2974668bb9b7SRichard Henderson TRANS(RDHPR_htstate, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhtstate) 2975668bb9b7SRichard Henderson 2976668bb9b7SRichard Henderson static TCGv do_rdhintp(DisasContext *dc, TCGv dst) 2977668bb9b7SRichard Henderson { 29782da789deSRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hintp)); 29792da789deSRichard Henderson return dst; 2980668bb9b7SRichard Henderson } 2981668bb9b7SRichard Henderson 2982668bb9b7SRichard Henderson TRANS(RDHPR_hintp, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhintp) 2983668bb9b7SRichard Henderson 2984668bb9b7SRichard Henderson static TCGv do_rdhtba(DisasContext *dc, TCGv dst) 2985668bb9b7SRichard Henderson { 29862da789deSRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(htba)); 29872da789deSRichard Henderson return dst; 2988668bb9b7SRichard Henderson } 2989668bb9b7SRichard Henderson 2990668bb9b7SRichard Henderson TRANS(RDHPR_htba, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhtba) 2991668bb9b7SRichard Henderson 2992668bb9b7SRichard Henderson static TCGv do_rdhver(DisasContext *dc, TCGv dst) 2993668bb9b7SRichard Henderson { 29942da789deSRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hver)); 29952da789deSRichard Henderson return dst; 2996668bb9b7SRichard Henderson } 2997668bb9b7SRichard Henderson 2998668bb9b7SRichard Henderson TRANS(RDHPR_hver, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhver) 2999668bb9b7SRichard Henderson 3000668bb9b7SRichard Henderson static TCGv do_rdhstick_cmpr(DisasContext *dc, TCGv dst) 3001668bb9b7SRichard Henderson { 3002577efa45SRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hstick_cmpr)); 3003577efa45SRichard Henderson return dst; 3004668bb9b7SRichard Henderson } 3005668bb9b7SRichard Henderson 3006668bb9b7SRichard Henderson TRANS(RDHPR_hstick_cmpr, HYPV, do_rd_special, hypervisor(dc), a->rd, 3007668bb9b7SRichard Henderson do_rdhstick_cmpr) 3008668bb9b7SRichard Henderson 30095d617bfbSRichard Henderson static TCGv do_rdwim(DisasContext *dc, TCGv dst) 30105d617bfbSRichard Henderson { 3011cd6269f7SRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env32_field_offsetof(wim)); 3012cd6269f7SRichard Henderson return dst; 30135d617bfbSRichard Henderson } 30145d617bfbSRichard Henderson 30155d617bfbSRichard Henderson TRANS(RDWIM, 32, do_rd_special, supervisor(dc), a->rd, do_rdwim) 30165d617bfbSRichard Henderson 30175d617bfbSRichard Henderson static TCGv do_rdtpc(DisasContext *dc, TCGv dst) 30185d617bfbSRichard Henderson { 30195d617bfbSRichard Henderson #ifdef TARGET_SPARC64 30205d617bfbSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 30215d617bfbSRichard Henderson 30225d617bfbSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 30235d617bfbSRichard Henderson tcg_gen_ld_tl(dst, r_tsptr, offsetof(trap_state, tpc)); 30245d617bfbSRichard Henderson return dst; 30255d617bfbSRichard Henderson #else 30265d617bfbSRichard Henderson qemu_build_not_reached(); 30275d617bfbSRichard Henderson #endif 30285d617bfbSRichard Henderson } 30295d617bfbSRichard Henderson 30305d617bfbSRichard Henderson TRANS(RDPR_tpc, 64, do_rd_special, supervisor(dc), a->rd, do_rdtpc) 30315d617bfbSRichard Henderson 30325d617bfbSRichard Henderson static TCGv do_rdtnpc(DisasContext *dc, TCGv dst) 30335d617bfbSRichard Henderson { 30345d617bfbSRichard Henderson #ifdef TARGET_SPARC64 30355d617bfbSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 30365d617bfbSRichard Henderson 30375d617bfbSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 30385d617bfbSRichard Henderson tcg_gen_ld_tl(dst, r_tsptr, offsetof(trap_state, tnpc)); 30395d617bfbSRichard Henderson return dst; 30405d617bfbSRichard Henderson #else 30415d617bfbSRichard Henderson qemu_build_not_reached(); 30425d617bfbSRichard Henderson #endif 30435d617bfbSRichard Henderson } 30445d617bfbSRichard Henderson 30455d617bfbSRichard Henderson TRANS(RDPR_tnpc, 64, do_rd_special, supervisor(dc), a->rd, do_rdtnpc) 30465d617bfbSRichard Henderson 30475d617bfbSRichard Henderson static TCGv do_rdtstate(DisasContext *dc, TCGv dst) 30485d617bfbSRichard Henderson { 30495d617bfbSRichard Henderson #ifdef TARGET_SPARC64 30505d617bfbSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 30515d617bfbSRichard Henderson 30525d617bfbSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 30535d617bfbSRichard Henderson tcg_gen_ld_tl(dst, r_tsptr, offsetof(trap_state, tstate)); 30545d617bfbSRichard Henderson return dst; 30555d617bfbSRichard Henderson #else 30565d617bfbSRichard Henderson qemu_build_not_reached(); 30575d617bfbSRichard Henderson #endif 30585d617bfbSRichard Henderson } 30595d617bfbSRichard Henderson 30605d617bfbSRichard Henderson TRANS(RDPR_tstate, 64, do_rd_special, supervisor(dc), a->rd, do_rdtstate) 30615d617bfbSRichard Henderson 30625d617bfbSRichard Henderson static TCGv do_rdtt(DisasContext *dc, TCGv dst) 30635d617bfbSRichard Henderson { 30645d617bfbSRichard Henderson #ifdef TARGET_SPARC64 30655d617bfbSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 30665d617bfbSRichard Henderson 30675d617bfbSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 30685d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, r_tsptr, offsetof(trap_state, tt)); 30695d617bfbSRichard Henderson return dst; 30705d617bfbSRichard Henderson #else 30715d617bfbSRichard Henderson qemu_build_not_reached(); 30725d617bfbSRichard Henderson #endif 30735d617bfbSRichard Henderson } 30745d617bfbSRichard Henderson 30755d617bfbSRichard Henderson TRANS(RDPR_tt, 64, do_rd_special, supervisor(dc), a->rd, do_rdtt) 30765d617bfbSRichard Henderson TRANS(RDPR_tick, 64, do_rd_special, supervisor(dc), a->rd, do_rdtick) 30775d617bfbSRichard Henderson 30785d617bfbSRichard Henderson static TCGv do_rdtba(DisasContext *dc, TCGv dst) 30795d617bfbSRichard Henderson { 30805d617bfbSRichard Henderson return cpu_tbr; 30815d617bfbSRichard Henderson } 30825d617bfbSRichard Henderson 3083e8325dc0SRichard Henderson TRANS(RDTBR, 32, do_rd_special, supervisor(dc), a->rd, do_rdtba) 30845d617bfbSRichard Henderson TRANS(RDPR_tba, 64, do_rd_special, supervisor(dc), a->rd, do_rdtba) 30855d617bfbSRichard Henderson 30865d617bfbSRichard Henderson static TCGv do_rdpstate(DisasContext *dc, TCGv dst) 30875d617bfbSRichard Henderson { 30885d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(pstate)); 30895d617bfbSRichard Henderson return dst; 30905d617bfbSRichard Henderson } 30915d617bfbSRichard Henderson 30925d617bfbSRichard Henderson TRANS(RDPR_pstate, 64, do_rd_special, supervisor(dc), a->rd, do_rdpstate) 30935d617bfbSRichard Henderson 30945d617bfbSRichard Henderson static TCGv do_rdtl(DisasContext *dc, TCGv dst) 30955d617bfbSRichard Henderson { 30965d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(tl)); 30975d617bfbSRichard Henderson return dst; 30985d617bfbSRichard Henderson } 30995d617bfbSRichard Henderson 31005d617bfbSRichard Henderson TRANS(RDPR_tl, 64, do_rd_special, supervisor(dc), a->rd, do_rdtl) 31015d617bfbSRichard Henderson 31025d617bfbSRichard Henderson static TCGv do_rdpil(DisasContext *dc, TCGv dst) 31035d617bfbSRichard Henderson { 31045d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env_field_offsetof(psrpil)); 31055d617bfbSRichard Henderson return dst; 31065d617bfbSRichard Henderson } 31075d617bfbSRichard Henderson 31085d617bfbSRichard Henderson TRANS(RDPR_pil, 64, do_rd_special, supervisor(dc), a->rd, do_rdpil) 31095d617bfbSRichard Henderson 31105d617bfbSRichard Henderson static TCGv do_rdcwp(DisasContext *dc, TCGv dst) 31115d617bfbSRichard Henderson { 31125d617bfbSRichard Henderson gen_helper_rdcwp(dst, tcg_env); 31135d617bfbSRichard Henderson return dst; 31145d617bfbSRichard Henderson } 31155d617bfbSRichard Henderson 31165d617bfbSRichard Henderson TRANS(RDPR_cwp, 64, do_rd_special, supervisor(dc), a->rd, do_rdcwp) 31175d617bfbSRichard Henderson 31185d617bfbSRichard Henderson static TCGv do_rdcansave(DisasContext *dc, TCGv dst) 31195d617bfbSRichard Henderson { 31205d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(cansave)); 31215d617bfbSRichard Henderson return dst; 31225d617bfbSRichard Henderson } 31235d617bfbSRichard Henderson 31245d617bfbSRichard Henderson TRANS(RDPR_cansave, 64, do_rd_special, supervisor(dc), a->rd, do_rdcansave) 31255d617bfbSRichard Henderson 31265d617bfbSRichard Henderson static TCGv do_rdcanrestore(DisasContext *dc, TCGv dst) 31275d617bfbSRichard Henderson { 31285d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(canrestore)); 31295d617bfbSRichard Henderson return dst; 31305d617bfbSRichard Henderson } 31315d617bfbSRichard Henderson 31325d617bfbSRichard Henderson TRANS(RDPR_canrestore, 64, do_rd_special, supervisor(dc), a->rd, 31335d617bfbSRichard Henderson do_rdcanrestore) 31345d617bfbSRichard Henderson 31355d617bfbSRichard Henderson static TCGv do_rdcleanwin(DisasContext *dc, TCGv dst) 31365d617bfbSRichard Henderson { 31375d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(cleanwin)); 31385d617bfbSRichard Henderson return dst; 31395d617bfbSRichard Henderson } 31405d617bfbSRichard Henderson 31415d617bfbSRichard Henderson TRANS(RDPR_cleanwin, 64, do_rd_special, supervisor(dc), a->rd, do_rdcleanwin) 31425d617bfbSRichard Henderson 31435d617bfbSRichard Henderson static TCGv do_rdotherwin(DisasContext *dc, TCGv dst) 31445d617bfbSRichard Henderson { 31455d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(otherwin)); 31465d617bfbSRichard Henderson return dst; 31475d617bfbSRichard Henderson } 31485d617bfbSRichard Henderson 31495d617bfbSRichard Henderson TRANS(RDPR_otherwin, 64, do_rd_special, supervisor(dc), a->rd, do_rdotherwin) 31505d617bfbSRichard Henderson 31515d617bfbSRichard Henderson static TCGv do_rdwstate(DisasContext *dc, TCGv dst) 31525d617bfbSRichard Henderson { 31535d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(wstate)); 31545d617bfbSRichard Henderson return dst; 31555d617bfbSRichard Henderson } 31565d617bfbSRichard Henderson 31575d617bfbSRichard Henderson TRANS(RDPR_wstate, 64, do_rd_special, supervisor(dc), a->rd, do_rdwstate) 31585d617bfbSRichard Henderson 31595d617bfbSRichard Henderson static TCGv do_rdgl(DisasContext *dc, TCGv dst) 31605d617bfbSRichard Henderson { 31615d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(gl)); 31625d617bfbSRichard Henderson return dst; 31635d617bfbSRichard Henderson } 31645d617bfbSRichard Henderson 31655d617bfbSRichard Henderson TRANS(RDPR_gl, GL, do_rd_special, supervisor(dc), a->rd, do_rdgl) 31665d617bfbSRichard Henderson 31675d617bfbSRichard Henderson /* UA2005 strand status */ 31685d617bfbSRichard Henderson static TCGv do_rdssr(DisasContext *dc, TCGv dst) 31695d617bfbSRichard Henderson { 31702da789deSRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(ssr)); 31712da789deSRichard Henderson return dst; 31725d617bfbSRichard Henderson } 31735d617bfbSRichard Henderson 31745d617bfbSRichard Henderson TRANS(RDPR_strand_status, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdssr) 31755d617bfbSRichard Henderson 31765d617bfbSRichard Henderson static TCGv do_rdver(DisasContext *dc, TCGv dst) 31775d617bfbSRichard Henderson { 31782da789deSRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(version)); 31792da789deSRichard Henderson return dst; 31805d617bfbSRichard Henderson } 31815d617bfbSRichard Henderson 31825d617bfbSRichard Henderson TRANS(RDPR_ver, 64, do_rd_special, supervisor(dc), a->rd, do_rdver) 31835d617bfbSRichard Henderson 3184e8325dc0SRichard Henderson static bool trans_FLUSHW(DisasContext *dc, arg_FLUSHW *a) 3185e8325dc0SRichard Henderson { 3186e8325dc0SRichard Henderson if (avail_64(dc)) { 3187e8325dc0SRichard Henderson gen_helper_flushw(tcg_env); 3188e8325dc0SRichard Henderson return advance_pc(dc); 3189e8325dc0SRichard Henderson } 3190e8325dc0SRichard Henderson return false; 3191e8325dc0SRichard Henderson } 3192e8325dc0SRichard Henderson 31930faef01bSRichard Henderson static bool do_wr_special(DisasContext *dc, arg_r_r_ri *a, bool priv, 31940faef01bSRichard Henderson void (*func)(DisasContext *, TCGv)) 31950faef01bSRichard Henderson { 31960faef01bSRichard Henderson TCGv src; 31970faef01bSRichard Henderson 31980faef01bSRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 31990faef01bSRichard Henderson if (!a->imm && (a->rs2_or_imm & ~0x1f)) { 32000faef01bSRichard Henderson return false; 32010faef01bSRichard Henderson } 32020faef01bSRichard Henderson if (!priv) { 32030faef01bSRichard Henderson return raise_priv(dc); 32040faef01bSRichard Henderson } 32050faef01bSRichard Henderson 32060faef01bSRichard Henderson if (a->rs1 == 0 && (a->imm || a->rs2_or_imm == 0)) { 32070faef01bSRichard Henderson src = tcg_constant_tl(a->rs2_or_imm); 32080faef01bSRichard Henderson } else { 32090faef01bSRichard Henderson TCGv src1 = gen_load_gpr(dc, a->rs1); 32100faef01bSRichard Henderson if (a->rs2_or_imm == 0) { 32110faef01bSRichard Henderson src = src1; 32120faef01bSRichard Henderson } else { 32130faef01bSRichard Henderson src = tcg_temp_new(); 32140faef01bSRichard Henderson if (a->imm) { 32150faef01bSRichard Henderson tcg_gen_xori_tl(src, src1, a->rs2_or_imm); 32160faef01bSRichard Henderson } else { 32170faef01bSRichard Henderson tcg_gen_xor_tl(src, src1, gen_load_gpr(dc, a->rs2_or_imm)); 32180faef01bSRichard Henderson } 32190faef01bSRichard Henderson } 32200faef01bSRichard Henderson } 32210faef01bSRichard Henderson func(dc, src); 32220faef01bSRichard Henderson return advance_pc(dc); 32230faef01bSRichard Henderson } 32240faef01bSRichard Henderson 32250faef01bSRichard Henderson static void do_wry(DisasContext *dc, TCGv src) 32260faef01bSRichard Henderson { 32270faef01bSRichard Henderson tcg_gen_ext32u_tl(cpu_y, src); 32280faef01bSRichard Henderson } 32290faef01bSRichard Henderson 32300faef01bSRichard Henderson TRANS(WRY, ALL, do_wr_special, a, true, do_wry) 32310faef01bSRichard Henderson 32320faef01bSRichard Henderson static void do_wrccr(DisasContext *dc, TCGv src) 32330faef01bSRichard Henderson { 32340faef01bSRichard Henderson gen_helper_wrccr(tcg_env, src); 32350faef01bSRichard Henderson } 32360faef01bSRichard Henderson 32370faef01bSRichard Henderson TRANS(WRCCR, 64, do_wr_special, a, true, do_wrccr) 32380faef01bSRichard Henderson 32390faef01bSRichard Henderson static void do_wrasi(DisasContext *dc, TCGv src) 32400faef01bSRichard Henderson { 32410faef01bSRichard Henderson TCGv tmp = tcg_temp_new(); 32420faef01bSRichard Henderson 32430faef01bSRichard Henderson tcg_gen_ext8u_tl(tmp, src); 32440faef01bSRichard Henderson tcg_gen_st32_tl(tmp, tcg_env, env64_field_offsetof(asi)); 32450faef01bSRichard Henderson /* End TB to notice changed ASI. */ 32460faef01bSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 32470faef01bSRichard Henderson } 32480faef01bSRichard Henderson 32490faef01bSRichard Henderson TRANS(WRASI, 64, do_wr_special, a, true, do_wrasi) 32500faef01bSRichard Henderson 32510faef01bSRichard Henderson static void do_wrfprs(DisasContext *dc, TCGv src) 32520faef01bSRichard Henderson { 32530faef01bSRichard Henderson #ifdef TARGET_SPARC64 32540faef01bSRichard Henderson tcg_gen_trunc_tl_i32(cpu_fprs, src); 32550faef01bSRichard Henderson dc->fprs_dirty = 0; 32560faef01bSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 32570faef01bSRichard Henderson #else 32580faef01bSRichard Henderson qemu_build_not_reached(); 32590faef01bSRichard Henderson #endif 32600faef01bSRichard Henderson } 32610faef01bSRichard Henderson 32620faef01bSRichard Henderson TRANS(WRFPRS, 64, do_wr_special, a, true, do_wrfprs) 32630faef01bSRichard Henderson 32640faef01bSRichard Henderson static void do_wrgsr(DisasContext *dc, TCGv src) 32650faef01bSRichard Henderson { 32660faef01bSRichard Henderson gen_trap_ifnofpu(dc); 32670faef01bSRichard Henderson tcg_gen_mov_tl(cpu_gsr, src); 32680faef01bSRichard Henderson } 32690faef01bSRichard Henderson 32700faef01bSRichard Henderson TRANS(WRGSR, 64, do_wr_special, a, true, do_wrgsr) 32710faef01bSRichard Henderson 32720faef01bSRichard Henderson static void do_wrsoftint_set(DisasContext *dc, TCGv src) 32730faef01bSRichard Henderson { 32740faef01bSRichard Henderson gen_helper_set_softint(tcg_env, src); 32750faef01bSRichard Henderson } 32760faef01bSRichard Henderson 32770faef01bSRichard Henderson TRANS(WRSOFTINT_SET, 64, do_wr_special, a, supervisor(dc), do_wrsoftint_set) 32780faef01bSRichard Henderson 32790faef01bSRichard Henderson static void do_wrsoftint_clr(DisasContext *dc, TCGv src) 32800faef01bSRichard Henderson { 32810faef01bSRichard Henderson gen_helper_clear_softint(tcg_env, src); 32820faef01bSRichard Henderson } 32830faef01bSRichard Henderson 32840faef01bSRichard Henderson TRANS(WRSOFTINT_CLR, 64, do_wr_special, a, supervisor(dc), do_wrsoftint_clr) 32850faef01bSRichard Henderson 32860faef01bSRichard Henderson static void do_wrsoftint(DisasContext *dc, TCGv src) 32870faef01bSRichard Henderson { 32880faef01bSRichard Henderson gen_helper_write_softint(tcg_env, src); 32890faef01bSRichard Henderson } 32900faef01bSRichard Henderson 32910faef01bSRichard Henderson TRANS(WRSOFTINT, 64, do_wr_special, a, supervisor(dc), do_wrsoftint) 32920faef01bSRichard Henderson 32930faef01bSRichard Henderson static void do_wrtick_cmpr(DisasContext *dc, TCGv src) 32940faef01bSRichard Henderson { 32950faef01bSRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr(); 32960faef01bSRichard Henderson 3297577efa45SRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(tick_cmpr)); 3298577efa45SRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(tick)); 32990faef01bSRichard Henderson translator_io_start(&dc->base); 3300577efa45SRichard Henderson gen_helper_tick_set_limit(r_tickptr, src); 33010faef01bSRichard Henderson /* End TB to handle timer interrupt */ 33020faef01bSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 33030faef01bSRichard Henderson } 33040faef01bSRichard Henderson 33050faef01bSRichard Henderson TRANS(WRTICK_CMPR, 64, do_wr_special, a, supervisor(dc), do_wrtick_cmpr) 33060faef01bSRichard Henderson 33070faef01bSRichard Henderson static void do_wrstick(DisasContext *dc, TCGv src) 33080faef01bSRichard Henderson { 33090faef01bSRichard Henderson #ifdef TARGET_SPARC64 33100faef01bSRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr(); 33110faef01bSRichard Henderson 33120faef01bSRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, offsetof(CPUSPARCState, stick)); 33130faef01bSRichard Henderson translator_io_start(&dc->base); 33140faef01bSRichard Henderson gen_helper_tick_set_count(r_tickptr, src); 33150faef01bSRichard Henderson /* End TB to handle timer interrupt */ 33160faef01bSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 33170faef01bSRichard Henderson #else 33180faef01bSRichard Henderson qemu_build_not_reached(); 33190faef01bSRichard Henderson #endif 33200faef01bSRichard Henderson } 33210faef01bSRichard Henderson 33220faef01bSRichard Henderson TRANS(WRSTICK, 64, do_wr_special, a, supervisor(dc), do_wrstick) 33230faef01bSRichard Henderson 33240faef01bSRichard Henderson static void do_wrstick_cmpr(DisasContext *dc, TCGv src) 33250faef01bSRichard Henderson { 33260faef01bSRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr(); 33270faef01bSRichard Henderson 3328577efa45SRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(stick_cmpr)); 3329577efa45SRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(stick)); 33300faef01bSRichard Henderson translator_io_start(&dc->base); 3331577efa45SRichard Henderson gen_helper_tick_set_limit(r_tickptr, src); 33320faef01bSRichard Henderson /* End TB to handle timer interrupt */ 33330faef01bSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 33340faef01bSRichard Henderson } 33350faef01bSRichard Henderson 33360faef01bSRichard Henderson TRANS(WRSTICK_CMPR, 64, do_wr_special, a, supervisor(dc), do_wrstick_cmpr) 33370faef01bSRichard Henderson 33380faef01bSRichard Henderson static void do_wrpowerdown(DisasContext *dc, TCGv src) 33390faef01bSRichard Henderson { 334089527e3aSRichard Henderson finishing_insn(dc); 33410faef01bSRichard Henderson save_state(dc); 33420faef01bSRichard Henderson gen_helper_power_down(tcg_env); 33430faef01bSRichard Henderson } 33440faef01bSRichard Henderson 33450faef01bSRichard Henderson TRANS(WRPOWERDOWN, POWERDOWN, do_wr_special, a, supervisor(dc), do_wrpowerdown) 33460faef01bSRichard Henderson 3347*6fbc032cSRichard Henderson static void do_wrmwait(DisasContext *dc, TCGv src) 3348*6fbc032cSRichard Henderson { 3349*6fbc032cSRichard Henderson /* 3350*6fbc032cSRichard Henderson * TODO: This is a stub version of mwait, which merely recognizes 3351*6fbc032cSRichard Henderson * interrupts immediately and does not wait. 3352*6fbc032cSRichard Henderson */ 3353*6fbc032cSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 3354*6fbc032cSRichard Henderson } 3355*6fbc032cSRichard Henderson 3356*6fbc032cSRichard Henderson TRANS(WRMWAIT, VIS4, do_wr_special, a, true, do_wrmwait) 3357*6fbc032cSRichard Henderson 335825524734SRichard Henderson static void do_wrpsr(DisasContext *dc, TCGv src) 335925524734SRichard Henderson { 336025524734SRichard Henderson gen_helper_wrpsr(tcg_env, src); 336125524734SRichard Henderson dc->base.is_jmp = DISAS_EXIT; 336225524734SRichard Henderson } 336325524734SRichard Henderson 336425524734SRichard Henderson TRANS(WRPSR, 32, do_wr_special, a, supervisor(dc), do_wrpsr) 336525524734SRichard Henderson 33669422278eSRichard Henderson static void do_wrwim(DisasContext *dc, TCGv src) 33679422278eSRichard Henderson { 33689422278eSRichard Henderson target_ulong mask = MAKE_64BIT_MASK(0, dc->def->nwindows); 3369cd6269f7SRichard Henderson TCGv tmp = tcg_temp_new(); 3370cd6269f7SRichard Henderson 3371cd6269f7SRichard Henderson tcg_gen_andi_tl(tmp, src, mask); 3372cd6269f7SRichard Henderson tcg_gen_st_tl(tmp, tcg_env, env32_field_offsetof(wim)); 33739422278eSRichard Henderson } 33749422278eSRichard Henderson 33759422278eSRichard Henderson TRANS(WRWIM, 32, do_wr_special, a, supervisor(dc), do_wrwim) 33769422278eSRichard Henderson 33779422278eSRichard Henderson static void do_wrtpc(DisasContext *dc, TCGv src) 33789422278eSRichard Henderson { 33799422278eSRichard Henderson #ifdef TARGET_SPARC64 33809422278eSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 33819422278eSRichard Henderson 33829422278eSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 33839422278eSRichard Henderson tcg_gen_st_tl(src, r_tsptr, offsetof(trap_state, tpc)); 33849422278eSRichard Henderson #else 33859422278eSRichard Henderson qemu_build_not_reached(); 33869422278eSRichard Henderson #endif 33879422278eSRichard Henderson } 33889422278eSRichard Henderson 33899422278eSRichard Henderson TRANS(WRPR_tpc, 64, do_wr_special, a, supervisor(dc), do_wrtpc) 33909422278eSRichard Henderson 33919422278eSRichard Henderson static void do_wrtnpc(DisasContext *dc, TCGv src) 33929422278eSRichard Henderson { 33939422278eSRichard Henderson #ifdef TARGET_SPARC64 33949422278eSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 33959422278eSRichard Henderson 33969422278eSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 33979422278eSRichard Henderson tcg_gen_st_tl(src, r_tsptr, offsetof(trap_state, tnpc)); 33989422278eSRichard Henderson #else 33999422278eSRichard Henderson qemu_build_not_reached(); 34009422278eSRichard Henderson #endif 34019422278eSRichard Henderson } 34029422278eSRichard Henderson 34039422278eSRichard Henderson TRANS(WRPR_tnpc, 64, do_wr_special, a, supervisor(dc), do_wrtnpc) 34049422278eSRichard Henderson 34059422278eSRichard Henderson static void do_wrtstate(DisasContext *dc, TCGv src) 34069422278eSRichard Henderson { 34079422278eSRichard Henderson #ifdef TARGET_SPARC64 34089422278eSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 34099422278eSRichard Henderson 34109422278eSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 34119422278eSRichard Henderson tcg_gen_st_tl(src, r_tsptr, offsetof(trap_state, tstate)); 34129422278eSRichard Henderson #else 34139422278eSRichard Henderson qemu_build_not_reached(); 34149422278eSRichard Henderson #endif 34159422278eSRichard Henderson } 34169422278eSRichard Henderson 34179422278eSRichard Henderson TRANS(WRPR_tstate, 64, do_wr_special, a, supervisor(dc), do_wrtstate) 34189422278eSRichard Henderson 34199422278eSRichard Henderson static void do_wrtt(DisasContext *dc, TCGv src) 34209422278eSRichard Henderson { 34219422278eSRichard Henderson #ifdef TARGET_SPARC64 34229422278eSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 34239422278eSRichard Henderson 34249422278eSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 34259422278eSRichard Henderson tcg_gen_st32_tl(src, r_tsptr, offsetof(trap_state, tt)); 34269422278eSRichard Henderson #else 34279422278eSRichard Henderson qemu_build_not_reached(); 34289422278eSRichard Henderson #endif 34299422278eSRichard Henderson } 34309422278eSRichard Henderson 34319422278eSRichard Henderson TRANS(WRPR_tt, 64, do_wr_special, a, supervisor(dc), do_wrtt) 34329422278eSRichard Henderson 34339422278eSRichard Henderson static void do_wrtick(DisasContext *dc, TCGv src) 34349422278eSRichard Henderson { 34359422278eSRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr(); 34369422278eSRichard Henderson 34379422278eSRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(tick)); 34389422278eSRichard Henderson translator_io_start(&dc->base); 34399422278eSRichard Henderson gen_helper_tick_set_count(r_tickptr, src); 34409422278eSRichard Henderson /* End TB to handle timer interrupt */ 34419422278eSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 34429422278eSRichard Henderson } 34439422278eSRichard Henderson 34449422278eSRichard Henderson TRANS(WRPR_tick, 64, do_wr_special, a, supervisor(dc), do_wrtick) 34459422278eSRichard Henderson 34469422278eSRichard Henderson static void do_wrtba(DisasContext *dc, TCGv src) 34479422278eSRichard Henderson { 34489422278eSRichard Henderson tcg_gen_mov_tl(cpu_tbr, src); 34499422278eSRichard Henderson } 34509422278eSRichard Henderson 34519422278eSRichard Henderson TRANS(WRPR_tba, 64, do_wr_special, a, supervisor(dc), do_wrtba) 34529422278eSRichard Henderson 34539422278eSRichard Henderson static void do_wrpstate(DisasContext *dc, TCGv src) 34549422278eSRichard Henderson { 34559422278eSRichard Henderson save_state(dc); 34569422278eSRichard Henderson if (translator_io_start(&dc->base)) { 34579422278eSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 34589422278eSRichard Henderson } 34599422278eSRichard Henderson gen_helper_wrpstate(tcg_env, src); 34609422278eSRichard Henderson dc->npc = DYNAMIC_PC; 34619422278eSRichard Henderson } 34629422278eSRichard Henderson 34639422278eSRichard Henderson TRANS(WRPR_pstate, 64, do_wr_special, a, supervisor(dc), do_wrpstate) 34649422278eSRichard Henderson 34659422278eSRichard Henderson static void do_wrtl(DisasContext *dc, TCGv src) 34669422278eSRichard Henderson { 34679422278eSRichard Henderson save_state(dc); 34689422278eSRichard Henderson tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(tl)); 34699422278eSRichard Henderson dc->npc = DYNAMIC_PC; 34709422278eSRichard Henderson } 34719422278eSRichard Henderson 34729422278eSRichard Henderson TRANS(WRPR_tl, 64, do_wr_special, a, supervisor(dc), do_wrtl) 34739422278eSRichard Henderson 34749422278eSRichard Henderson static void do_wrpil(DisasContext *dc, TCGv src) 34759422278eSRichard Henderson { 34769422278eSRichard Henderson if (translator_io_start(&dc->base)) { 34779422278eSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 34789422278eSRichard Henderson } 34799422278eSRichard Henderson gen_helper_wrpil(tcg_env, src); 34809422278eSRichard Henderson } 34819422278eSRichard Henderson 34829422278eSRichard Henderson TRANS(WRPR_pil, 64, do_wr_special, a, supervisor(dc), do_wrpil) 34839422278eSRichard Henderson 34849422278eSRichard Henderson static void do_wrcwp(DisasContext *dc, TCGv src) 34859422278eSRichard Henderson { 34869422278eSRichard Henderson gen_helper_wrcwp(tcg_env, src); 34879422278eSRichard Henderson } 34889422278eSRichard Henderson 34899422278eSRichard Henderson TRANS(WRPR_cwp, 64, do_wr_special, a, supervisor(dc), do_wrcwp) 34909422278eSRichard Henderson 34919422278eSRichard Henderson static void do_wrcansave(DisasContext *dc, TCGv src) 34929422278eSRichard Henderson { 34939422278eSRichard Henderson tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(cansave)); 34949422278eSRichard Henderson } 34959422278eSRichard Henderson 34969422278eSRichard Henderson TRANS(WRPR_cansave, 64, do_wr_special, a, supervisor(dc), do_wrcansave) 34979422278eSRichard Henderson 34989422278eSRichard Henderson static void do_wrcanrestore(DisasContext *dc, TCGv src) 34999422278eSRichard Henderson { 35009422278eSRichard Henderson tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(canrestore)); 35019422278eSRichard Henderson } 35029422278eSRichard Henderson 35039422278eSRichard Henderson TRANS(WRPR_canrestore, 64, do_wr_special, a, supervisor(dc), do_wrcanrestore) 35049422278eSRichard Henderson 35059422278eSRichard Henderson static void do_wrcleanwin(DisasContext *dc, TCGv src) 35069422278eSRichard Henderson { 35079422278eSRichard Henderson tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(cleanwin)); 35089422278eSRichard Henderson } 35099422278eSRichard Henderson 35109422278eSRichard Henderson TRANS(WRPR_cleanwin, 64, do_wr_special, a, supervisor(dc), do_wrcleanwin) 35119422278eSRichard Henderson 35129422278eSRichard Henderson static void do_wrotherwin(DisasContext *dc, TCGv src) 35139422278eSRichard Henderson { 35149422278eSRichard Henderson tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(otherwin)); 35159422278eSRichard Henderson } 35169422278eSRichard Henderson 35179422278eSRichard Henderson TRANS(WRPR_otherwin, 64, do_wr_special, a, supervisor(dc), do_wrotherwin) 35189422278eSRichard Henderson 35199422278eSRichard Henderson static void do_wrwstate(DisasContext *dc, TCGv src) 35209422278eSRichard Henderson { 35219422278eSRichard Henderson tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(wstate)); 35229422278eSRichard Henderson } 35239422278eSRichard Henderson 35249422278eSRichard Henderson TRANS(WRPR_wstate, 64, do_wr_special, a, supervisor(dc), do_wrwstate) 35259422278eSRichard Henderson 35269422278eSRichard Henderson static void do_wrgl(DisasContext *dc, TCGv src) 35279422278eSRichard Henderson { 35289422278eSRichard Henderson gen_helper_wrgl(tcg_env, src); 35299422278eSRichard Henderson } 35309422278eSRichard Henderson 35319422278eSRichard Henderson TRANS(WRPR_gl, GL, do_wr_special, a, supervisor(dc), do_wrgl) 35329422278eSRichard Henderson 35339422278eSRichard Henderson /* UA2005 strand status */ 35349422278eSRichard Henderson static void do_wrssr(DisasContext *dc, TCGv src) 35359422278eSRichard Henderson { 35362da789deSRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(ssr)); 35379422278eSRichard Henderson } 35389422278eSRichard Henderson 35399422278eSRichard Henderson TRANS(WRPR_strand_status, HYPV, do_wr_special, a, hypervisor(dc), do_wrssr) 35409422278eSRichard Henderson 3541bb97f2f5SRichard Henderson TRANS(WRTBR, 32, do_wr_special, a, supervisor(dc), do_wrtba) 3542bb97f2f5SRichard Henderson 3543bb97f2f5SRichard Henderson static void do_wrhpstate(DisasContext *dc, TCGv src) 3544bb97f2f5SRichard Henderson { 3545bb97f2f5SRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(hpstate)); 3546bb97f2f5SRichard Henderson dc->base.is_jmp = DISAS_EXIT; 3547bb97f2f5SRichard Henderson } 3548bb97f2f5SRichard Henderson 3549bb97f2f5SRichard Henderson TRANS(WRHPR_hpstate, HYPV, do_wr_special, a, hypervisor(dc), do_wrhpstate) 3550bb97f2f5SRichard Henderson 3551bb97f2f5SRichard Henderson static void do_wrhtstate(DisasContext *dc, TCGv src) 3552bb97f2f5SRichard Henderson { 3553bb97f2f5SRichard Henderson TCGv_i32 tl = tcg_temp_new_i32(); 3554bb97f2f5SRichard Henderson TCGv_ptr tp = tcg_temp_new_ptr(); 3555bb97f2f5SRichard Henderson 3556bb97f2f5SRichard Henderson tcg_gen_ld_i32(tl, tcg_env, env64_field_offsetof(tl)); 3557bb97f2f5SRichard Henderson tcg_gen_andi_i32(tl, tl, MAXTL_MASK); 3558bb97f2f5SRichard Henderson tcg_gen_shli_i32(tl, tl, 3); 3559bb97f2f5SRichard Henderson tcg_gen_ext_i32_ptr(tp, tl); 3560bb97f2f5SRichard Henderson tcg_gen_add_ptr(tp, tp, tcg_env); 3561bb97f2f5SRichard Henderson 3562bb97f2f5SRichard Henderson tcg_gen_st_tl(src, tp, env64_field_offsetof(htstate)); 3563bb97f2f5SRichard Henderson } 3564bb97f2f5SRichard Henderson 3565bb97f2f5SRichard Henderson TRANS(WRHPR_htstate, HYPV, do_wr_special, a, hypervisor(dc), do_wrhtstate) 3566bb97f2f5SRichard Henderson 3567bb97f2f5SRichard Henderson static void do_wrhintp(DisasContext *dc, TCGv src) 3568bb97f2f5SRichard Henderson { 35692da789deSRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(hintp)); 3570bb97f2f5SRichard Henderson } 3571bb97f2f5SRichard Henderson 3572bb97f2f5SRichard Henderson TRANS(WRHPR_hintp, HYPV, do_wr_special, a, hypervisor(dc), do_wrhintp) 3573bb97f2f5SRichard Henderson 3574bb97f2f5SRichard Henderson static void do_wrhtba(DisasContext *dc, TCGv src) 3575bb97f2f5SRichard Henderson { 35762da789deSRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(htba)); 3577bb97f2f5SRichard Henderson } 3578bb97f2f5SRichard Henderson 3579bb97f2f5SRichard Henderson TRANS(WRHPR_htba, HYPV, do_wr_special, a, hypervisor(dc), do_wrhtba) 3580bb97f2f5SRichard Henderson 3581bb97f2f5SRichard Henderson static void do_wrhstick_cmpr(DisasContext *dc, TCGv src) 3582bb97f2f5SRichard Henderson { 3583bb97f2f5SRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr(); 3584bb97f2f5SRichard Henderson 3585577efa45SRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(hstick_cmpr)); 3586bb97f2f5SRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(hstick)); 3587bb97f2f5SRichard Henderson translator_io_start(&dc->base); 3588577efa45SRichard Henderson gen_helper_tick_set_limit(r_tickptr, src); 3589bb97f2f5SRichard Henderson /* End TB to handle timer interrupt */ 3590bb97f2f5SRichard Henderson dc->base.is_jmp = DISAS_EXIT; 3591bb97f2f5SRichard Henderson } 3592bb97f2f5SRichard Henderson 3593bb97f2f5SRichard Henderson TRANS(WRHPR_hstick_cmpr, HYPV, do_wr_special, a, hypervisor(dc), 3594bb97f2f5SRichard Henderson do_wrhstick_cmpr) 3595bb97f2f5SRichard Henderson 359625524734SRichard Henderson static bool do_saved_restored(DisasContext *dc, bool saved) 359725524734SRichard Henderson { 359825524734SRichard Henderson if (!supervisor(dc)) { 359925524734SRichard Henderson return raise_priv(dc); 360025524734SRichard Henderson } 360125524734SRichard Henderson if (saved) { 360225524734SRichard Henderson gen_helper_saved(tcg_env); 360325524734SRichard Henderson } else { 360425524734SRichard Henderson gen_helper_restored(tcg_env); 360525524734SRichard Henderson } 360625524734SRichard Henderson return advance_pc(dc); 360725524734SRichard Henderson } 360825524734SRichard Henderson 360925524734SRichard Henderson TRANS(SAVED, 64, do_saved_restored, true) 361025524734SRichard Henderson TRANS(RESTORED, 64, do_saved_restored, false) 361125524734SRichard Henderson 3612d3825800SRichard Henderson static bool trans_NOP(DisasContext *dc, arg_NOP *a) 3613d3825800SRichard Henderson { 3614d3825800SRichard Henderson return advance_pc(dc); 3615d3825800SRichard Henderson } 3616d3825800SRichard Henderson 36170faef01bSRichard Henderson /* 36180faef01bSRichard Henderson * TODO: Need a feature bit for sparcv8. 36190faef01bSRichard Henderson * In the meantime, treat all 32-bit cpus like sparcv7. 36200faef01bSRichard Henderson */ 36215458fd31SRichard Henderson TRANS(NOP_v7, 32, trans_NOP, a) 36225458fd31SRichard Henderson TRANS(NOP_v9, 64, trans_NOP, a) 36230faef01bSRichard Henderson 3624b597eedcSRichard Henderson static bool do_arith_int(DisasContext *dc, arg_r_r_ri_cc *a, 3625428881deSRichard Henderson void (*func)(TCGv, TCGv, TCGv), 36262a45b736SRichard Henderson void (*funci)(TCGv, TCGv, target_long), 36272a45b736SRichard Henderson bool logic_cc) 3628428881deSRichard Henderson { 3629428881deSRichard Henderson TCGv dst, src1; 3630428881deSRichard Henderson 3631428881deSRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 3632428881deSRichard Henderson if (!a->imm && a->rs2_or_imm & ~0x1f) { 3633428881deSRichard Henderson return false; 3634428881deSRichard Henderson } 3635428881deSRichard Henderson 36362a45b736SRichard Henderson if (logic_cc) { 36372a45b736SRichard Henderson dst = cpu_cc_N; 3638428881deSRichard Henderson } else { 3639428881deSRichard Henderson dst = gen_dest_gpr(dc, a->rd); 3640428881deSRichard Henderson } 3641428881deSRichard Henderson src1 = gen_load_gpr(dc, a->rs1); 3642428881deSRichard Henderson 3643428881deSRichard Henderson if (a->imm || a->rs2_or_imm == 0) { 3644428881deSRichard Henderson if (funci) { 3645428881deSRichard Henderson funci(dst, src1, a->rs2_or_imm); 3646428881deSRichard Henderson } else { 3647428881deSRichard Henderson func(dst, src1, tcg_constant_tl(a->rs2_or_imm)); 3648428881deSRichard Henderson } 3649428881deSRichard Henderson } else { 3650428881deSRichard Henderson func(dst, src1, cpu_regs[a->rs2_or_imm]); 3651428881deSRichard Henderson } 36522a45b736SRichard Henderson 36532a45b736SRichard Henderson if (logic_cc) { 36542a45b736SRichard Henderson if (TARGET_LONG_BITS == 64) { 36552a45b736SRichard Henderson tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N); 36562a45b736SRichard Henderson tcg_gen_movi_tl(cpu_icc_C, 0); 36572a45b736SRichard Henderson } 36582a45b736SRichard Henderson tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N); 36592a45b736SRichard Henderson tcg_gen_movi_tl(cpu_cc_C, 0); 36602a45b736SRichard Henderson tcg_gen_movi_tl(cpu_cc_V, 0); 36612a45b736SRichard Henderson } 36622a45b736SRichard Henderson 3663428881deSRichard Henderson gen_store_gpr(dc, a->rd, dst); 3664428881deSRichard Henderson return advance_pc(dc); 3665428881deSRichard Henderson } 3666428881deSRichard Henderson 3667b597eedcSRichard Henderson static bool do_arith(DisasContext *dc, arg_r_r_ri_cc *a, 3668428881deSRichard Henderson void (*func)(TCGv, TCGv, TCGv), 3669428881deSRichard Henderson void (*funci)(TCGv, TCGv, target_long), 3670428881deSRichard Henderson void (*func_cc)(TCGv, TCGv, TCGv)) 3671428881deSRichard Henderson { 3672428881deSRichard Henderson if (a->cc) { 3673b597eedcSRichard Henderson return do_arith_int(dc, a, func_cc, NULL, false); 3674428881deSRichard Henderson } 3675b597eedcSRichard Henderson return do_arith_int(dc, a, func, funci, false); 3676428881deSRichard Henderson } 3677428881deSRichard Henderson 3678428881deSRichard Henderson static bool do_logic(DisasContext *dc, arg_r_r_ri_cc *a, 3679428881deSRichard Henderson void (*func)(TCGv, TCGv, TCGv), 3680428881deSRichard Henderson void (*funci)(TCGv, TCGv, target_long)) 3681428881deSRichard Henderson { 3682b597eedcSRichard Henderson return do_arith_int(dc, a, func, funci, a->cc); 3683428881deSRichard Henderson } 3684428881deSRichard Henderson 3685b597eedcSRichard Henderson TRANS(ADD, ALL, do_arith, a, tcg_gen_add_tl, tcg_gen_addi_tl, gen_op_addcc) 3686b597eedcSRichard Henderson TRANS(SUB, ALL, do_arith, a, tcg_gen_sub_tl, tcg_gen_subi_tl, gen_op_subcc) 3687b597eedcSRichard Henderson TRANS(ADDC, ALL, do_arith, a, gen_op_addc, NULL, gen_op_addccc) 3688b597eedcSRichard Henderson TRANS(SUBC, ALL, do_arith, a, gen_op_subc, NULL, gen_op_subccc) 3689428881deSRichard Henderson 3690b597eedcSRichard Henderson TRANS(TADDcc, ALL, do_arith, a, NULL, NULL, gen_op_taddcc) 3691b597eedcSRichard Henderson TRANS(TSUBcc, ALL, do_arith, a, NULL, NULL, gen_op_tsubcc) 3692b597eedcSRichard Henderson TRANS(TADDccTV, ALL, do_arith, a, NULL, NULL, gen_op_taddcctv) 3693b597eedcSRichard Henderson TRANS(TSUBccTV, ALL, do_arith, a, NULL, NULL, gen_op_tsubcctv) 3694a9aba13dSRichard Henderson 3695428881deSRichard Henderson TRANS(AND, ALL, do_logic, a, tcg_gen_and_tl, tcg_gen_andi_tl) 3696428881deSRichard Henderson TRANS(XOR, ALL, do_logic, a, tcg_gen_xor_tl, tcg_gen_xori_tl) 3697428881deSRichard Henderson TRANS(ANDN, ALL, do_logic, a, tcg_gen_andc_tl, NULL) 3698428881deSRichard Henderson TRANS(ORN, ALL, do_logic, a, tcg_gen_orc_tl, NULL) 3699428881deSRichard Henderson TRANS(XORN, ALL, do_logic, a, tcg_gen_eqv_tl, NULL) 3700428881deSRichard Henderson 3701b597eedcSRichard Henderson TRANS(MULX, 64, do_arith, a, tcg_gen_mul_tl, tcg_gen_muli_tl, NULL) 3702b5372650SRichard Henderson TRANS(UMUL, MUL, do_logic, a, gen_op_umul, NULL) 3703b5372650SRichard Henderson TRANS(SMUL, MUL, do_logic, a, gen_op_smul, NULL) 3704b597eedcSRichard Henderson TRANS(MULScc, ALL, do_arith, a, NULL, NULL, gen_op_mulscc) 370522188d7dSRichard Henderson 37063a6b8de3SRichard Henderson TRANS(UDIVcc, DIV, do_arith, a, NULL, NULL, gen_op_udivcc) 3707b597eedcSRichard Henderson TRANS(SDIV, DIV, do_arith, a, gen_op_sdiv, NULL, gen_op_sdivcc) 37084ee85ea9SRichard Henderson 37099c6ec5bcSRichard Henderson /* TODO: Should have feature bit -- comes in with UltraSparc T2. */ 3710b597eedcSRichard Henderson TRANS(POPC, 64, do_arith, a, gen_op_popc, NULL, NULL) 37119c6ec5bcSRichard Henderson 3712428881deSRichard Henderson static bool trans_OR(DisasContext *dc, arg_r_r_ri_cc *a) 3713428881deSRichard Henderson { 3714428881deSRichard Henderson /* OR with %g0 is the canonical alias for MOV. */ 3715428881deSRichard Henderson if (!a->cc && a->rs1 == 0) { 3716428881deSRichard Henderson if (a->imm || a->rs2_or_imm == 0) { 3717428881deSRichard Henderson gen_store_gpr(dc, a->rd, tcg_constant_tl(a->rs2_or_imm)); 3718428881deSRichard Henderson } else if (a->rs2_or_imm & ~0x1f) { 3719428881deSRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 3720428881deSRichard Henderson return false; 3721428881deSRichard Henderson } else { 3722428881deSRichard Henderson gen_store_gpr(dc, a->rd, cpu_regs[a->rs2_or_imm]); 3723428881deSRichard Henderson } 3724428881deSRichard Henderson return advance_pc(dc); 3725428881deSRichard Henderson } 3726428881deSRichard Henderson return do_logic(dc, a, tcg_gen_or_tl, tcg_gen_ori_tl); 3727428881deSRichard Henderson } 3728428881deSRichard Henderson 37293a6b8de3SRichard Henderson static bool trans_UDIV(DisasContext *dc, arg_r_r_ri *a) 37303a6b8de3SRichard Henderson { 37313a6b8de3SRichard Henderson TCGv_i64 t1, t2; 37323a6b8de3SRichard Henderson TCGv dst; 37333a6b8de3SRichard Henderson 37343a6b8de3SRichard Henderson if (!avail_DIV(dc)) { 37353a6b8de3SRichard Henderson return false; 37363a6b8de3SRichard Henderson } 37373a6b8de3SRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 37383a6b8de3SRichard Henderson if (!a->imm && a->rs2_or_imm & ~0x1f) { 37393a6b8de3SRichard Henderson return false; 37403a6b8de3SRichard Henderson } 37413a6b8de3SRichard Henderson 37423a6b8de3SRichard Henderson if (unlikely(a->rs2_or_imm == 0)) { 37433a6b8de3SRichard Henderson gen_exception(dc, TT_DIV_ZERO); 37443a6b8de3SRichard Henderson return true; 37453a6b8de3SRichard Henderson } 37463a6b8de3SRichard Henderson 37473a6b8de3SRichard Henderson if (a->imm) { 37483a6b8de3SRichard Henderson t2 = tcg_constant_i64((uint32_t)a->rs2_or_imm); 37493a6b8de3SRichard Henderson } else { 37503a6b8de3SRichard Henderson TCGLabel *lab; 37513a6b8de3SRichard Henderson TCGv_i32 n2; 37523a6b8de3SRichard Henderson 37533a6b8de3SRichard Henderson finishing_insn(dc); 37543a6b8de3SRichard Henderson flush_cond(dc); 37553a6b8de3SRichard Henderson 37563a6b8de3SRichard Henderson n2 = tcg_temp_new_i32(); 37573a6b8de3SRichard Henderson tcg_gen_trunc_tl_i32(n2, cpu_regs[a->rs2_or_imm]); 37583a6b8de3SRichard Henderson 37593a6b8de3SRichard Henderson lab = delay_exception(dc, TT_DIV_ZERO); 37603a6b8de3SRichard Henderson tcg_gen_brcondi_i32(TCG_COND_EQ, n2, 0, lab); 37613a6b8de3SRichard Henderson 37623a6b8de3SRichard Henderson t2 = tcg_temp_new_i64(); 37633a6b8de3SRichard Henderson #ifdef TARGET_SPARC64 37643a6b8de3SRichard Henderson tcg_gen_ext32u_i64(t2, cpu_regs[a->rs2_or_imm]); 37653a6b8de3SRichard Henderson #else 37663a6b8de3SRichard Henderson tcg_gen_extu_i32_i64(t2, cpu_regs[a->rs2_or_imm]); 37673a6b8de3SRichard Henderson #endif 37683a6b8de3SRichard Henderson } 37693a6b8de3SRichard Henderson 37703a6b8de3SRichard Henderson t1 = tcg_temp_new_i64(); 37713a6b8de3SRichard Henderson tcg_gen_concat_tl_i64(t1, gen_load_gpr(dc, a->rs1), cpu_y); 37723a6b8de3SRichard Henderson 37733a6b8de3SRichard Henderson tcg_gen_divu_i64(t1, t1, t2); 37743a6b8de3SRichard Henderson tcg_gen_umin_i64(t1, t1, tcg_constant_i64(UINT32_MAX)); 37753a6b8de3SRichard Henderson 37763a6b8de3SRichard Henderson dst = gen_dest_gpr(dc, a->rd); 37773a6b8de3SRichard Henderson tcg_gen_trunc_i64_tl(dst, t1); 37783a6b8de3SRichard Henderson gen_store_gpr(dc, a->rd, dst); 37793a6b8de3SRichard Henderson return advance_pc(dc); 37803a6b8de3SRichard Henderson } 37813a6b8de3SRichard Henderson 3782f3141174SRichard Henderson static bool trans_UDIVX(DisasContext *dc, arg_r_r_ri *a) 3783f3141174SRichard Henderson { 3784f3141174SRichard Henderson TCGv dst, src1, src2; 3785f3141174SRichard Henderson 3786f3141174SRichard Henderson if (!avail_64(dc)) { 3787f3141174SRichard Henderson return false; 3788f3141174SRichard Henderson } 3789f3141174SRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 3790f3141174SRichard Henderson if (!a->imm && a->rs2_or_imm & ~0x1f) { 3791f3141174SRichard Henderson return false; 3792f3141174SRichard Henderson } 3793f3141174SRichard Henderson 3794f3141174SRichard Henderson if (unlikely(a->rs2_or_imm == 0)) { 3795f3141174SRichard Henderson gen_exception(dc, TT_DIV_ZERO); 3796f3141174SRichard Henderson return true; 3797f3141174SRichard Henderson } 3798f3141174SRichard Henderson 3799f3141174SRichard Henderson if (a->imm) { 3800f3141174SRichard Henderson src2 = tcg_constant_tl(a->rs2_or_imm); 3801f3141174SRichard Henderson } else { 3802f3141174SRichard Henderson TCGLabel *lab; 3803f3141174SRichard Henderson 3804f3141174SRichard Henderson finishing_insn(dc); 3805f3141174SRichard Henderson flush_cond(dc); 3806f3141174SRichard Henderson 3807f3141174SRichard Henderson lab = delay_exception(dc, TT_DIV_ZERO); 3808f3141174SRichard Henderson src2 = cpu_regs[a->rs2_or_imm]; 3809f3141174SRichard Henderson tcg_gen_brcondi_tl(TCG_COND_EQ, src2, 0, lab); 3810f3141174SRichard Henderson } 3811f3141174SRichard Henderson 3812f3141174SRichard Henderson dst = gen_dest_gpr(dc, a->rd); 3813f3141174SRichard Henderson src1 = gen_load_gpr(dc, a->rs1); 3814f3141174SRichard Henderson 3815f3141174SRichard Henderson tcg_gen_divu_tl(dst, src1, src2); 3816f3141174SRichard Henderson gen_store_gpr(dc, a->rd, dst); 3817f3141174SRichard Henderson return advance_pc(dc); 3818f3141174SRichard Henderson } 3819f3141174SRichard Henderson 3820f3141174SRichard Henderson static bool trans_SDIVX(DisasContext *dc, arg_r_r_ri *a) 3821f3141174SRichard Henderson { 3822f3141174SRichard Henderson TCGv dst, src1, src2; 3823f3141174SRichard Henderson 3824f3141174SRichard Henderson if (!avail_64(dc)) { 3825f3141174SRichard Henderson return false; 3826f3141174SRichard Henderson } 3827f3141174SRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 3828f3141174SRichard Henderson if (!a->imm && a->rs2_or_imm & ~0x1f) { 3829f3141174SRichard Henderson return false; 3830f3141174SRichard Henderson } 3831f3141174SRichard Henderson 3832f3141174SRichard Henderson if (unlikely(a->rs2_or_imm == 0)) { 3833f3141174SRichard Henderson gen_exception(dc, TT_DIV_ZERO); 3834f3141174SRichard Henderson return true; 3835f3141174SRichard Henderson } 3836f3141174SRichard Henderson 3837f3141174SRichard Henderson dst = gen_dest_gpr(dc, a->rd); 3838f3141174SRichard Henderson src1 = gen_load_gpr(dc, a->rs1); 3839f3141174SRichard Henderson 3840f3141174SRichard Henderson if (a->imm) { 3841f3141174SRichard Henderson if (unlikely(a->rs2_or_imm == -1)) { 3842f3141174SRichard Henderson tcg_gen_neg_tl(dst, src1); 3843f3141174SRichard Henderson gen_store_gpr(dc, a->rd, dst); 3844f3141174SRichard Henderson return advance_pc(dc); 3845f3141174SRichard Henderson } 3846f3141174SRichard Henderson src2 = tcg_constant_tl(a->rs2_or_imm); 3847f3141174SRichard Henderson } else { 3848f3141174SRichard Henderson TCGLabel *lab; 3849f3141174SRichard Henderson TCGv t1, t2; 3850f3141174SRichard Henderson 3851f3141174SRichard Henderson finishing_insn(dc); 3852f3141174SRichard Henderson flush_cond(dc); 3853f3141174SRichard Henderson 3854f3141174SRichard Henderson lab = delay_exception(dc, TT_DIV_ZERO); 3855f3141174SRichard Henderson src2 = cpu_regs[a->rs2_or_imm]; 3856f3141174SRichard Henderson tcg_gen_brcondi_tl(TCG_COND_EQ, src2, 0, lab); 3857f3141174SRichard Henderson 3858f3141174SRichard Henderson /* 3859f3141174SRichard Henderson * Need to avoid INT64_MIN / -1, which will trap on x86 host. 3860f3141174SRichard Henderson * Set SRC2 to 1 as a new divisor, to produce the correct result. 3861f3141174SRichard Henderson */ 3862f3141174SRichard Henderson t1 = tcg_temp_new(); 3863f3141174SRichard Henderson t2 = tcg_temp_new(); 3864f3141174SRichard Henderson tcg_gen_setcondi_tl(TCG_COND_EQ, t1, src1, (target_long)INT64_MIN); 3865f3141174SRichard Henderson tcg_gen_setcondi_tl(TCG_COND_EQ, t2, src2, -1); 3866f3141174SRichard Henderson tcg_gen_and_tl(t1, t1, t2); 3867f3141174SRichard Henderson tcg_gen_movcond_tl(TCG_COND_NE, t1, t1, tcg_constant_tl(0), 3868f3141174SRichard Henderson tcg_constant_tl(1), src2); 3869f3141174SRichard Henderson src2 = t1; 3870f3141174SRichard Henderson } 3871f3141174SRichard Henderson 3872f3141174SRichard Henderson tcg_gen_div_tl(dst, src1, src2); 3873f3141174SRichard Henderson gen_store_gpr(dc, a->rd, dst); 3874f3141174SRichard Henderson return advance_pc(dc); 3875f3141174SRichard Henderson } 3876f3141174SRichard Henderson 3877b88ce6f2SRichard Henderson static bool gen_edge(DisasContext *dc, arg_r_r_r *a, 387843db5838SRichard Henderson int width, bool cc, bool little_endian) 3879b88ce6f2SRichard Henderson { 388043db5838SRichard Henderson TCGv dst, s1, s2, l, r, t, m; 388143db5838SRichard Henderson uint64_t amask = address_mask_i(dc, -8); 3882b88ce6f2SRichard Henderson 3883b88ce6f2SRichard Henderson dst = gen_dest_gpr(dc, a->rd); 3884b88ce6f2SRichard Henderson s1 = gen_load_gpr(dc, a->rs1); 3885b88ce6f2SRichard Henderson s2 = gen_load_gpr(dc, a->rs2); 3886b88ce6f2SRichard Henderson 3887b88ce6f2SRichard Henderson if (cc) { 3888f828df74SRichard Henderson gen_op_subcc(cpu_cc_N, s1, s2); 3889b88ce6f2SRichard Henderson } 3890b88ce6f2SRichard Henderson 389143db5838SRichard Henderson l = tcg_temp_new(); 389243db5838SRichard Henderson r = tcg_temp_new(); 389343db5838SRichard Henderson t = tcg_temp_new(); 389443db5838SRichard Henderson 3895b88ce6f2SRichard Henderson switch (width) { 3896b88ce6f2SRichard Henderson case 8: 389743db5838SRichard Henderson tcg_gen_andi_tl(l, s1, 7); 389843db5838SRichard Henderson tcg_gen_andi_tl(r, s2, 7); 389943db5838SRichard Henderson tcg_gen_xori_tl(r, r, 7); 390043db5838SRichard Henderson m = tcg_constant_tl(0xff); 3901b88ce6f2SRichard Henderson break; 3902b88ce6f2SRichard Henderson case 16: 390343db5838SRichard Henderson tcg_gen_extract_tl(l, s1, 1, 2); 390443db5838SRichard Henderson tcg_gen_extract_tl(r, s2, 1, 2); 390543db5838SRichard Henderson tcg_gen_xori_tl(r, r, 3); 390643db5838SRichard Henderson m = tcg_constant_tl(0xf); 3907b88ce6f2SRichard Henderson break; 3908b88ce6f2SRichard Henderson case 32: 390943db5838SRichard Henderson tcg_gen_extract_tl(l, s1, 2, 1); 391043db5838SRichard Henderson tcg_gen_extract_tl(r, s2, 2, 1); 391143db5838SRichard Henderson tcg_gen_xori_tl(r, r, 1); 391243db5838SRichard Henderson m = tcg_constant_tl(0x3); 3913b88ce6f2SRichard Henderson break; 3914b88ce6f2SRichard Henderson default: 3915b88ce6f2SRichard Henderson abort(); 3916b88ce6f2SRichard Henderson } 3917b88ce6f2SRichard Henderson 391843db5838SRichard Henderson /* Compute Left Edge */ 391943db5838SRichard Henderson if (little_endian) { 392043db5838SRichard Henderson tcg_gen_shl_tl(l, m, l); 392143db5838SRichard Henderson tcg_gen_and_tl(l, l, m); 392243db5838SRichard Henderson } else { 392343db5838SRichard Henderson tcg_gen_shr_tl(l, m, l); 392443db5838SRichard Henderson } 392543db5838SRichard Henderson /* Compute Right Edge */ 392643db5838SRichard Henderson if (little_endian) { 392743db5838SRichard Henderson tcg_gen_shr_tl(r, m, r); 392843db5838SRichard Henderson } else { 392943db5838SRichard Henderson tcg_gen_shl_tl(r, m, r); 393043db5838SRichard Henderson tcg_gen_and_tl(r, r, m); 393143db5838SRichard Henderson } 3932b88ce6f2SRichard Henderson 393343db5838SRichard Henderson /* Compute dst = (s1 == s2 under amask ? l : l & r) */ 393443db5838SRichard Henderson tcg_gen_xor_tl(t, s1, s2); 393543db5838SRichard Henderson tcg_gen_and_tl(r, r, l); 393643db5838SRichard Henderson tcg_gen_movcond_tl(TCG_COND_TSTEQ, dst, t, tcg_constant_tl(amask), r, l); 3937b88ce6f2SRichard Henderson 3938b88ce6f2SRichard Henderson gen_store_gpr(dc, a->rd, dst); 3939b88ce6f2SRichard Henderson return advance_pc(dc); 3940b88ce6f2SRichard Henderson } 3941b88ce6f2SRichard Henderson 3942b88ce6f2SRichard Henderson TRANS(EDGE8cc, VIS1, gen_edge, a, 8, 1, 0) 3943b88ce6f2SRichard Henderson TRANS(EDGE8Lcc, VIS1, gen_edge, a, 8, 1, 1) 3944b88ce6f2SRichard Henderson TRANS(EDGE16cc, VIS1, gen_edge, a, 16, 1, 0) 3945b88ce6f2SRichard Henderson TRANS(EDGE16Lcc, VIS1, gen_edge, a, 16, 1, 1) 3946b88ce6f2SRichard Henderson TRANS(EDGE32cc, VIS1, gen_edge, a, 32, 1, 0) 3947b88ce6f2SRichard Henderson TRANS(EDGE32Lcc, VIS1, gen_edge, a, 32, 1, 1) 3948b88ce6f2SRichard Henderson 3949b88ce6f2SRichard Henderson TRANS(EDGE8N, VIS2, gen_edge, a, 8, 0, 0) 3950b88ce6f2SRichard Henderson TRANS(EDGE8LN, VIS2, gen_edge, a, 8, 0, 1) 3951b88ce6f2SRichard Henderson TRANS(EDGE16N, VIS2, gen_edge, a, 16, 0, 0) 3952b88ce6f2SRichard Henderson TRANS(EDGE16LN, VIS2, gen_edge, a, 16, 0, 1) 3953b88ce6f2SRichard Henderson TRANS(EDGE32N, VIS2, gen_edge, a, 32, 0, 0) 3954b88ce6f2SRichard Henderson TRANS(EDGE32LN, VIS2, gen_edge, a, 32, 0, 1) 3955b88ce6f2SRichard Henderson 3956875ce392SRichard Henderson static bool do_rr(DisasContext *dc, arg_r_r *a, 3957875ce392SRichard Henderson void (*func)(TCGv, TCGv)) 3958875ce392SRichard Henderson { 3959875ce392SRichard Henderson TCGv dst = gen_dest_gpr(dc, a->rd); 3960875ce392SRichard Henderson TCGv src = gen_load_gpr(dc, a->rs); 3961875ce392SRichard Henderson 3962875ce392SRichard Henderson func(dst, src); 3963875ce392SRichard Henderson gen_store_gpr(dc, a->rd, dst); 3964875ce392SRichard Henderson return advance_pc(dc); 3965875ce392SRichard Henderson } 3966875ce392SRichard Henderson 3967875ce392SRichard Henderson TRANS(LZCNT, VIS3, do_rr, a, gen_op_lzcnt) 3968875ce392SRichard Henderson 396945bfed3bSRichard Henderson static bool do_rrr(DisasContext *dc, arg_r_r_r *a, 397045bfed3bSRichard Henderson void (*func)(TCGv, TCGv, TCGv)) 397145bfed3bSRichard Henderson { 397245bfed3bSRichard Henderson TCGv dst = gen_dest_gpr(dc, a->rd); 397345bfed3bSRichard Henderson TCGv src1 = gen_load_gpr(dc, a->rs1); 397445bfed3bSRichard Henderson TCGv src2 = gen_load_gpr(dc, a->rs2); 397545bfed3bSRichard Henderson 397645bfed3bSRichard Henderson func(dst, src1, src2); 397745bfed3bSRichard Henderson gen_store_gpr(dc, a->rd, dst); 397845bfed3bSRichard Henderson return advance_pc(dc); 397945bfed3bSRichard Henderson } 398045bfed3bSRichard Henderson 398145bfed3bSRichard Henderson TRANS(ARRAY8, VIS1, do_rrr, a, gen_helper_array8) 398245bfed3bSRichard Henderson TRANS(ARRAY16, VIS1, do_rrr, a, gen_op_array16) 398345bfed3bSRichard Henderson TRANS(ARRAY32, VIS1, do_rrr, a, gen_op_array32) 398445bfed3bSRichard Henderson 3985015fc6fcSRichard Henderson TRANS(ADDXC, VIS3, do_rrr, a, gen_op_addxc) 3986015fc6fcSRichard Henderson TRANS(ADDXCcc, VIS3, do_rrr, a, gen_op_addxccc) 3987015fc6fcSRichard Henderson 398856f2ef9cSRichard Henderson TRANS(SUBXC, VIS4, do_rrr, a, gen_op_subxc) 398956f2ef9cSRichard Henderson TRANS(SUBXCcc, VIS4, do_rrr, a, gen_op_subxccc) 399056f2ef9cSRichard Henderson 3991680af1b4SRichard Henderson TRANS(UMULXHI, VIS3, do_rrr, a, gen_op_umulxhi) 3992680af1b4SRichard Henderson 39939e20ca94SRichard Henderson static void gen_op_alignaddr(TCGv dst, TCGv s1, TCGv s2) 39949e20ca94SRichard Henderson { 39959e20ca94SRichard Henderson #ifdef TARGET_SPARC64 39969e20ca94SRichard Henderson TCGv tmp = tcg_temp_new(); 39979e20ca94SRichard Henderson 39989e20ca94SRichard Henderson tcg_gen_add_tl(tmp, s1, s2); 39999e20ca94SRichard Henderson tcg_gen_andi_tl(dst, tmp, -8); 40009e20ca94SRichard Henderson tcg_gen_deposit_tl(cpu_gsr, cpu_gsr, tmp, 0, 3); 40019e20ca94SRichard Henderson #else 40029e20ca94SRichard Henderson g_assert_not_reached(); 40039e20ca94SRichard Henderson #endif 40049e20ca94SRichard Henderson } 40059e20ca94SRichard Henderson 40069e20ca94SRichard Henderson static void gen_op_alignaddrl(TCGv dst, TCGv s1, TCGv s2) 40079e20ca94SRichard Henderson { 40089e20ca94SRichard Henderson #ifdef TARGET_SPARC64 40099e20ca94SRichard Henderson TCGv tmp = tcg_temp_new(); 40109e20ca94SRichard Henderson 40119e20ca94SRichard Henderson tcg_gen_add_tl(tmp, s1, s2); 40129e20ca94SRichard Henderson tcg_gen_andi_tl(dst, tmp, -8); 40139e20ca94SRichard Henderson tcg_gen_neg_tl(tmp, tmp); 40149e20ca94SRichard Henderson tcg_gen_deposit_tl(cpu_gsr, cpu_gsr, tmp, 0, 3); 40159e20ca94SRichard Henderson #else 40169e20ca94SRichard Henderson g_assert_not_reached(); 40179e20ca94SRichard Henderson #endif 40189e20ca94SRichard Henderson } 40199e20ca94SRichard Henderson 40209e20ca94SRichard Henderson TRANS(ALIGNADDR, VIS1, do_rrr, a, gen_op_alignaddr) 40219e20ca94SRichard Henderson TRANS(ALIGNADDRL, VIS1, do_rrr, a, gen_op_alignaddrl) 40229e20ca94SRichard Henderson 402339ca3490SRichard Henderson static void gen_op_bmask(TCGv dst, TCGv s1, TCGv s2) 402439ca3490SRichard Henderson { 402539ca3490SRichard Henderson #ifdef TARGET_SPARC64 402639ca3490SRichard Henderson tcg_gen_add_tl(dst, s1, s2); 402739ca3490SRichard Henderson tcg_gen_deposit_tl(cpu_gsr, cpu_gsr, dst, 32, 32); 402839ca3490SRichard Henderson #else 402939ca3490SRichard Henderson g_assert_not_reached(); 403039ca3490SRichard Henderson #endif 403139ca3490SRichard Henderson } 403239ca3490SRichard Henderson 403339ca3490SRichard Henderson TRANS(BMASK, VIS2, do_rrr, a, gen_op_bmask) 403439ca3490SRichard Henderson 4035c973b4e8SRichard Henderson static bool do_cmask(DisasContext *dc, int rs2, void (*func)(TCGv, TCGv, TCGv)) 4036c973b4e8SRichard Henderson { 4037c973b4e8SRichard Henderson func(cpu_gsr, cpu_gsr, gen_load_gpr(dc, rs2)); 4038c973b4e8SRichard Henderson return true; 4039c973b4e8SRichard Henderson } 4040c973b4e8SRichard Henderson 4041c973b4e8SRichard Henderson TRANS(CMASK8, VIS3, do_cmask, a->rs2, gen_helper_cmask8) 4042c973b4e8SRichard Henderson TRANS(CMASK16, VIS3, do_cmask, a->rs2, gen_helper_cmask16) 4043c973b4e8SRichard Henderson TRANS(CMASK32, VIS3, do_cmask, a->rs2, gen_helper_cmask32) 4044c973b4e8SRichard Henderson 40455fc546eeSRichard Henderson static bool do_shift_r(DisasContext *dc, arg_shiftr *a, bool l, bool u) 40465fc546eeSRichard Henderson { 40475fc546eeSRichard Henderson TCGv dst, src1, src2; 40485fc546eeSRichard Henderson 40495fc546eeSRichard Henderson /* Reject 64-bit shifts for sparc32. */ 40505fc546eeSRichard Henderson if (avail_32(dc) && a->x) { 40515fc546eeSRichard Henderson return false; 40525fc546eeSRichard Henderson } 40535fc546eeSRichard Henderson 40545fc546eeSRichard Henderson src2 = tcg_temp_new(); 40555fc546eeSRichard Henderson tcg_gen_andi_tl(src2, gen_load_gpr(dc, a->rs2), a->x ? 63 : 31); 40565fc546eeSRichard Henderson src1 = gen_load_gpr(dc, a->rs1); 40575fc546eeSRichard Henderson dst = gen_dest_gpr(dc, a->rd); 40585fc546eeSRichard Henderson 40595fc546eeSRichard Henderson if (l) { 40605fc546eeSRichard Henderson tcg_gen_shl_tl(dst, src1, src2); 40615fc546eeSRichard Henderson if (!a->x) { 40625fc546eeSRichard Henderson tcg_gen_ext32u_tl(dst, dst); 40635fc546eeSRichard Henderson } 40645fc546eeSRichard Henderson } else if (u) { 40655fc546eeSRichard Henderson if (!a->x) { 40665fc546eeSRichard Henderson tcg_gen_ext32u_tl(dst, src1); 40675fc546eeSRichard Henderson src1 = dst; 40685fc546eeSRichard Henderson } 40695fc546eeSRichard Henderson tcg_gen_shr_tl(dst, src1, src2); 40705fc546eeSRichard Henderson } else { 40715fc546eeSRichard Henderson if (!a->x) { 40725fc546eeSRichard Henderson tcg_gen_ext32s_tl(dst, src1); 40735fc546eeSRichard Henderson src1 = dst; 40745fc546eeSRichard Henderson } 40755fc546eeSRichard Henderson tcg_gen_sar_tl(dst, src1, src2); 40765fc546eeSRichard Henderson } 40775fc546eeSRichard Henderson gen_store_gpr(dc, a->rd, dst); 40785fc546eeSRichard Henderson return advance_pc(dc); 40795fc546eeSRichard Henderson } 40805fc546eeSRichard Henderson 40815fc546eeSRichard Henderson TRANS(SLL_r, ALL, do_shift_r, a, true, true) 40825fc546eeSRichard Henderson TRANS(SRL_r, ALL, do_shift_r, a, false, true) 40835fc546eeSRichard Henderson TRANS(SRA_r, ALL, do_shift_r, a, false, false) 40845fc546eeSRichard Henderson 40855fc546eeSRichard Henderson static bool do_shift_i(DisasContext *dc, arg_shifti *a, bool l, bool u) 40865fc546eeSRichard Henderson { 40875fc546eeSRichard Henderson TCGv dst, src1; 40885fc546eeSRichard Henderson 40895fc546eeSRichard Henderson /* Reject 64-bit shifts for sparc32. */ 40905fc546eeSRichard Henderson if (avail_32(dc) && (a->x || a->i >= 32)) { 40915fc546eeSRichard Henderson return false; 40925fc546eeSRichard Henderson } 40935fc546eeSRichard Henderson 40945fc546eeSRichard Henderson src1 = gen_load_gpr(dc, a->rs1); 40955fc546eeSRichard Henderson dst = gen_dest_gpr(dc, a->rd); 40965fc546eeSRichard Henderson 40975fc546eeSRichard Henderson if (avail_32(dc) || a->x) { 40985fc546eeSRichard Henderson if (l) { 40995fc546eeSRichard Henderson tcg_gen_shli_tl(dst, src1, a->i); 41005fc546eeSRichard Henderson } else if (u) { 41015fc546eeSRichard Henderson tcg_gen_shri_tl(dst, src1, a->i); 41025fc546eeSRichard Henderson } else { 41035fc546eeSRichard Henderson tcg_gen_sari_tl(dst, src1, a->i); 41045fc546eeSRichard Henderson } 41055fc546eeSRichard Henderson } else { 41065fc546eeSRichard Henderson if (l) { 41075fc546eeSRichard Henderson tcg_gen_deposit_z_tl(dst, src1, a->i, 32 - a->i); 41085fc546eeSRichard Henderson } else if (u) { 41095fc546eeSRichard Henderson tcg_gen_extract_tl(dst, src1, a->i, 32 - a->i); 41105fc546eeSRichard Henderson } else { 41115fc546eeSRichard Henderson tcg_gen_sextract_tl(dst, src1, a->i, 32 - a->i); 41125fc546eeSRichard Henderson } 41135fc546eeSRichard Henderson } 41145fc546eeSRichard Henderson gen_store_gpr(dc, a->rd, dst); 41155fc546eeSRichard Henderson return advance_pc(dc); 41165fc546eeSRichard Henderson } 41175fc546eeSRichard Henderson 41185fc546eeSRichard Henderson TRANS(SLL_i, ALL, do_shift_i, a, true, true) 41195fc546eeSRichard Henderson TRANS(SRL_i, ALL, do_shift_i, a, false, true) 41205fc546eeSRichard Henderson TRANS(SRA_i, ALL, do_shift_i, a, false, false) 41215fc546eeSRichard Henderson 4122fb4ed7aaSRichard Henderson static TCGv gen_rs2_or_imm(DisasContext *dc, bool imm, int rs2_or_imm) 4123fb4ed7aaSRichard Henderson { 4124fb4ed7aaSRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 4125fb4ed7aaSRichard Henderson if (!imm && rs2_or_imm & ~0x1f) { 4126fb4ed7aaSRichard Henderson return NULL; 4127fb4ed7aaSRichard Henderson } 4128fb4ed7aaSRichard Henderson if (imm || rs2_or_imm == 0) { 4129fb4ed7aaSRichard Henderson return tcg_constant_tl(rs2_or_imm); 4130fb4ed7aaSRichard Henderson } else { 4131fb4ed7aaSRichard Henderson return cpu_regs[rs2_or_imm]; 4132fb4ed7aaSRichard Henderson } 4133fb4ed7aaSRichard Henderson } 4134fb4ed7aaSRichard Henderson 4135fb4ed7aaSRichard Henderson static bool do_mov_cond(DisasContext *dc, DisasCompare *cmp, int rd, TCGv src2) 4136fb4ed7aaSRichard Henderson { 4137fb4ed7aaSRichard Henderson TCGv dst = gen_load_gpr(dc, rd); 4138c8507ebfSRichard Henderson TCGv c2 = tcg_constant_tl(cmp->c2); 4139fb4ed7aaSRichard Henderson 4140c8507ebfSRichard Henderson tcg_gen_movcond_tl(cmp->cond, dst, cmp->c1, c2, src2, dst); 4141fb4ed7aaSRichard Henderson gen_store_gpr(dc, rd, dst); 4142fb4ed7aaSRichard Henderson return advance_pc(dc); 4143fb4ed7aaSRichard Henderson } 4144fb4ed7aaSRichard Henderson 4145fb4ed7aaSRichard Henderson static bool trans_MOVcc(DisasContext *dc, arg_MOVcc *a) 4146fb4ed7aaSRichard Henderson { 4147fb4ed7aaSRichard Henderson TCGv src2 = gen_rs2_or_imm(dc, a->imm, a->rs2_or_imm); 4148fb4ed7aaSRichard Henderson DisasCompare cmp; 4149fb4ed7aaSRichard Henderson 4150fb4ed7aaSRichard Henderson if (src2 == NULL) { 4151fb4ed7aaSRichard Henderson return false; 4152fb4ed7aaSRichard Henderson } 4153fb4ed7aaSRichard Henderson gen_compare(&cmp, a->cc, a->cond, dc); 4154fb4ed7aaSRichard Henderson return do_mov_cond(dc, &cmp, a->rd, src2); 4155fb4ed7aaSRichard Henderson } 4156fb4ed7aaSRichard Henderson 4157fb4ed7aaSRichard Henderson static bool trans_MOVfcc(DisasContext *dc, arg_MOVfcc *a) 4158fb4ed7aaSRichard Henderson { 4159fb4ed7aaSRichard Henderson TCGv src2 = gen_rs2_or_imm(dc, a->imm, a->rs2_or_imm); 4160fb4ed7aaSRichard Henderson DisasCompare cmp; 4161fb4ed7aaSRichard Henderson 4162fb4ed7aaSRichard Henderson if (src2 == NULL) { 4163fb4ed7aaSRichard Henderson return false; 4164fb4ed7aaSRichard Henderson } 4165fb4ed7aaSRichard Henderson gen_fcompare(&cmp, a->cc, a->cond); 4166fb4ed7aaSRichard Henderson return do_mov_cond(dc, &cmp, a->rd, src2); 4167fb4ed7aaSRichard Henderson } 4168fb4ed7aaSRichard Henderson 4169fb4ed7aaSRichard Henderson static bool trans_MOVR(DisasContext *dc, arg_MOVR *a) 4170fb4ed7aaSRichard Henderson { 4171fb4ed7aaSRichard Henderson TCGv src2 = gen_rs2_or_imm(dc, a->imm, a->rs2_or_imm); 4172fb4ed7aaSRichard Henderson DisasCompare cmp; 4173fb4ed7aaSRichard Henderson 4174fb4ed7aaSRichard Henderson if (src2 == NULL) { 4175fb4ed7aaSRichard Henderson return false; 4176fb4ed7aaSRichard Henderson } 41772c4f56c9SRichard Henderson if (!gen_compare_reg(&cmp, a->cond, gen_load_gpr(dc, a->rs1))) { 41782c4f56c9SRichard Henderson return false; 41792c4f56c9SRichard Henderson } 4180fb4ed7aaSRichard Henderson return do_mov_cond(dc, &cmp, a->rd, src2); 4181fb4ed7aaSRichard Henderson } 4182fb4ed7aaSRichard Henderson 418386b82fe0SRichard Henderson static bool do_add_special(DisasContext *dc, arg_r_r_ri *a, 418486b82fe0SRichard Henderson bool (*func)(DisasContext *dc, int rd, TCGv src)) 418586b82fe0SRichard Henderson { 418686b82fe0SRichard Henderson TCGv src1, sum; 418786b82fe0SRichard Henderson 418886b82fe0SRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 418986b82fe0SRichard Henderson if (!a->imm && a->rs2_or_imm & ~0x1f) { 419086b82fe0SRichard Henderson return false; 419186b82fe0SRichard Henderson } 419286b82fe0SRichard Henderson 419386b82fe0SRichard Henderson /* 419486b82fe0SRichard Henderson * Always load the sum into a new temporary. 419586b82fe0SRichard Henderson * This is required to capture the value across a window change, 419686b82fe0SRichard Henderson * e.g. SAVE and RESTORE, and may be optimized away otherwise. 419786b82fe0SRichard Henderson */ 419886b82fe0SRichard Henderson sum = tcg_temp_new(); 419986b82fe0SRichard Henderson src1 = gen_load_gpr(dc, a->rs1); 420086b82fe0SRichard Henderson if (a->imm || a->rs2_or_imm == 0) { 420186b82fe0SRichard Henderson tcg_gen_addi_tl(sum, src1, a->rs2_or_imm); 420286b82fe0SRichard Henderson } else { 420386b82fe0SRichard Henderson tcg_gen_add_tl(sum, src1, cpu_regs[a->rs2_or_imm]); 420486b82fe0SRichard Henderson } 420586b82fe0SRichard Henderson return func(dc, a->rd, sum); 420686b82fe0SRichard Henderson } 420786b82fe0SRichard Henderson 420886b82fe0SRichard Henderson static bool do_jmpl(DisasContext *dc, int rd, TCGv src) 420986b82fe0SRichard Henderson { 421086b82fe0SRichard Henderson /* 421186b82fe0SRichard Henderson * Preserve pc across advance, so that we can delay 421286b82fe0SRichard Henderson * the writeback to rd until after src is consumed. 421386b82fe0SRichard Henderson */ 421486b82fe0SRichard Henderson target_ulong cur_pc = dc->pc; 421586b82fe0SRichard Henderson 421686b82fe0SRichard Henderson gen_check_align(dc, src, 3); 421786b82fe0SRichard Henderson 421886b82fe0SRichard Henderson gen_mov_pc_npc(dc); 421986b82fe0SRichard Henderson tcg_gen_mov_tl(cpu_npc, src); 422086b82fe0SRichard Henderson gen_address_mask(dc, cpu_npc); 422186b82fe0SRichard Henderson gen_store_gpr(dc, rd, tcg_constant_tl(cur_pc)); 422286b82fe0SRichard Henderson 422386b82fe0SRichard Henderson dc->npc = DYNAMIC_PC_LOOKUP; 422486b82fe0SRichard Henderson return true; 422586b82fe0SRichard Henderson } 422686b82fe0SRichard Henderson 422786b82fe0SRichard Henderson TRANS(JMPL, ALL, do_add_special, a, do_jmpl) 422886b82fe0SRichard Henderson 422986b82fe0SRichard Henderson static bool do_rett(DisasContext *dc, int rd, TCGv src) 423086b82fe0SRichard Henderson { 423186b82fe0SRichard Henderson if (!supervisor(dc)) { 423286b82fe0SRichard Henderson return raise_priv(dc); 423386b82fe0SRichard Henderson } 423486b82fe0SRichard Henderson 423586b82fe0SRichard Henderson gen_check_align(dc, src, 3); 423686b82fe0SRichard Henderson 423786b82fe0SRichard Henderson gen_mov_pc_npc(dc); 423886b82fe0SRichard Henderson tcg_gen_mov_tl(cpu_npc, src); 423986b82fe0SRichard Henderson gen_helper_rett(tcg_env); 424086b82fe0SRichard Henderson 424186b82fe0SRichard Henderson dc->npc = DYNAMIC_PC; 424286b82fe0SRichard Henderson return true; 424386b82fe0SRichard Henderson } 424486b82fe0SRichard Henderson 424586b82fe0SRichard Henderson TRANS(RETT, 32, do_add_special, a, do_rett) 424686b82fe0SRichard Henderson 424786b82fe0SRichard Henderson static bool do_return(DisasContext *dc, int rd, TCGv src) 424886b82fe0SRichard Henderson { 424986b82fe0SRichard Henderson gen_check_align(dc, src, 3); 42500dfae4f9SRichard Henderson gen_helper_restore(tcg_env); 425186b82fe0SRichard Henderson 425286b82fe0SRichard Henderson gen_mov_pc_npc(dc); 425386b82fe0SRichard Henderson tcg_gen_mov_tl(cpu_npc, src); 425486b82fe0SRichard Henderson gen_address_mask(dc, cpu_npc); 425586b82fe0SRichard Henderson 425686b82fe0SRichard Henderson dc->npc = DYNAMIC_PC_LOOKUP; 425786b82fe0SRichard Henderson return true; 425886b82fe0SRichard Henderson } 425986b82fe0SRichard Henderson 426086b82fe0SRichard Henderson TRANS(RETURN, 64, do_add_special, a, do_return) 426186b82fe0SRichard Henderson 4262d3825800SRichard Henderson static bool do_save(DisasContext *dc, int rd, TCGv src) 4263d3825800SRichard Henderson { 4264d3825800SRichard Henderson gen_helper_save(tcg_env); 4265d3825800SRichard Henderson gen_store_gpr(dc, rd, src); 4266d3825800SRichard Henderson return advance_pc(dc); 4267d3825800SRichard Henderson } 4268d3825800SRichard Henderson 4269d3825800SRichard Henderson TRANS(SAVE, ALL, do_add_special, a, do_save) 4270d3825800SRichard Henderson 4271d3825800SRichard Henderson static bool do_restore(DisasContext *dc, int rd, TCGv src) 4272d3825800SRichard Henderson { 4273d3825800SRichard Henderson gen_helper_restore(tcg_env); 4274d3825800SRichard Henderson gen_store_gpr(dc, rd, src); 4275d3825800SRichard Henderson return advance_pc(dc); 4276d3825800SRichard Henderson } 4277d3825800SRichard Henderson 4278d3825800SRichard Henderson TRANS(RESTORE, ALL, do_add_special, a, do_restore) 4279d3825800SRichard Henderson 42808f75b8a4SRichard Henderson static bool do_done_retry(DisasContext *dc, bool done) 42818f75b8a4SRichard Henderson { 42828f75b8a4SRichard Henderson if (!supervisor(dc)) { 42838f75b8a4SRichard Henderson return raise_priv(dc); 42848f75b8a4SRichard Henderson } 42858f75b8a4SRichard Henderson dc->npc = DYNAMIC_PC; 42868f75b8a4SRichard Henderson dc->pc = DYNAMIC_PC; 42878f75b8a4SRichard Henderson translator_io_start(&dc->base); 42888f75b8a4SRichard Henderson if (done) { 42898f75b8a4SRichard Henderson gen_helper_done(tcg_env); 42908f75b8a4SRichard Henderson } else { 42918f75b8a4SRichard Henderson gen_helper_retry(tcg_env); 42928f75b8a4SRichard Henderson } 42938f75b8a4SRichard Henderson return true; 42948f75b8a4SRichard Henderson } 42958f75b8a4SRichard Henderson 42968f75b8a4SRichard Henderson TRANS(DONE, 64, do_done_retry, true) 42978f75b8a4SRichard Henderson TRANS(RETRY, 64, do_done_retry, false) 42988f75b8a4SRichard Henderson 42990880d20bSRichard Henderson /* 43000880d20bSRichard Henderson * Major opcode 11 -- load and store instructions 43010880d20bSRichard Henderson */ 43020880d20bSRichard Henderson 43030880d20bSRichard Henderson static TCGv gen_ldst_addr(DisasContext *dc, int rs1, bool imm, int rs2_or_imm) 43040880d20bSRichard Henderson { 43050880d20bSRichard Henderson TCGv addr, tmp = NULL; 43060880d20bSRichard Henderson 43070880d20bSRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 43080880d20bSRichard Henderson if (!imm && rs2_or_imm & ~0x1f) { 43090880d20bSRichard Henderson return NULL; 43100880d20bSRichard Henderson } 43110880d20bSRichard Henderson 43120880d20bSRichard Henderson addr = gen_load_gpr(dc, rs1); 43130880d20bSRichard Henderson if (rs2_or_imm) { 43140880d20bSRichard Henderson tmp = tcg_temp_new(); 43150880d20bSRichard Henderson if (imm) { 43160880d20bSRichard Henderson tcg_gen_addi_tl(tmp, addr, rs2_or_imm); 43170880d20bSRichard Henderson } else { 43180880d20bSRichard Henderson tcg_gen_add_tl(tmp, addr, cpu_regs[rs2_or_imm]); 43190880d20bSRichard Henderson } 43200880d20bSRichard Henderson addr = tmp; 43210880d20bSRichard Henderson } 43220880d20bSRichard Henderson if (AM_CHECK(dc)) { 43230880d20bSRichard Henderson if (!tmp) { 43240880d20bSRichard Henderson tmp = tcg_temp_new(); 43250880d20bSRichard Henderson } 43260880d20bSRichard Henderson tcg_gen_ext32u_tl(tmp, addr); 43270880d20bSRichard Henderson addr = tmp; 43280880d20bSRichard Henderson } 43290880d20bSRichard Henderson return addr; 43300880d20bSRichard Henderson } 43310880d20bSRichard Henderson 43320880d20bSRichard Henderson static bool do_ld_gpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp mop) 43330880d20bSRichard Henderson { 43340880d20bSRichard Henderson TCGv reg, addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 43350880d20bSRichard Henderson DisasASI da; 43360880d20bSRichard Henderson 43370880d20bSRichard Henderson if (addr == NULL) { 43380880d20bSRichard Henderson return false; 43390880d20bSRichard Henderson } 43400880d20bSRichard Henderson da = resolve_asi(dc, a->asi, mop); 43410880d20bSRichard Henderson 43420880d20bSRichard Henderson reg = gen_dest_gpr(dc, a->rd); 434342071fc1SRichard Henderson gen_ld_asi(dc, &da, reg, addr); 43440880d20bSRichard Henderson gen_store_gpr(dc, a->rd, reg); 43450880d20bSRichard Henderson return advance_pc(dc); 43460880d20bSRichard Henderson } 43470880d20bSRichard Henderson 43480880d20bSRichard Henderson TRANS(LDUW, ALL, do_ld_gpr, a, MO_TEUL) 43490880d20bSRichard Henderson TRANS(LDUB, ALL, do_ld_gpr, a, MO_UB) 43500880d20bSRichard Henderson TRANS(LDUH, ALL, do_ld_gpr, a, MO_TEUW) 43510880d20bSRichard Henderson TRANS(LDSB, ALL, do_ld_gpr, a, MO_SB) 43520880d20bSRichard Henderson TRANS(LDSH, ALL, do_ld_gpr, a, MO_TESW) 43530880d20bSRichard Henderson TRANS(LDSW, 64, do_ld_gpr, a, MO_TESL) 43540880d20bSRichard Henderson TRANS(LDX, 64, do_ld_gpr, a, MO_TEUQ) 43550880d20bSRichard Henderson 43560880d20bSRichard Henderson static bool do_st_gpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp mop) 43570880d20bSRichard Henderson { 43580880d20bSRichard Henderson TCGv reg, addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 43590880d20bSRichard Henderson DisasASI da; 43600880d20bSRichard Henderson 43610880d20bSRichard Henderson if (addr == NULL) { 43620880d20bSRichard Henderson return false; 43630880d20bSRichard Henderson } 43640880d20bSRichard Henderson da = resolve_asi(dc, a->asi, mop); 43650880d20bSRichard Henderson 43660880d20bSRichard Henderson reg = gen_load_gpr(dc, a->rd); 436742071fc1SRichard Henderson gen_st_asi(dc, &da, reg, addr); 43680880d20bSRichard Henderson return advance_pc(dc); 43690880d20bSRichard Henderson } 43700880d20bSRichard Henderson 43710880d20bSRichard Henderson TRANS(STW, ALL, do_st_gpr, a, MO_TEUL) 43720880d20bSRichard Henderson TRANS(STB, ALL, do_st_gpr, a, MO_UB) 43730880d20bSRichard Henderson TRANS(STH, ALL, do_st_gpr, a, MO_TEUW) 43740880d20bSRichard Henderson TRANS(STX, 64, do_st_gpr, a, MO_TEUQ) 43750880d20bSRichard Henderson 43760880d20bSRichard Henderson static bool trans_LDD(DisasContext *dc, arg_r_r_ri_asi *a) 43770880d20bSRichard Henderson { 43780880d20bSRichard Henderson TCGv addr; 43790880d20bSRichard Henderson DisasASI da; 43800880d20bSRichard Henderson 43810880d20bSRichard Henderson if (a->rd & 1) { 43820880d20bSRichard Henderson return false; 43830880d20bSRichard Henderson } 43840880d20bSRichard Henderson addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 43850880d20bSRichard Henderson if (addr == NULL) { 43860880d20bSRichard Henderson return false; 43870880d20bSRichard Henderson } 43880880d20bSRichard Henderson da = resolve_asi(dc, a->asi, MO_TEUQ); 438942071fc1SRichard Henderson gen_ldda_asi(dc, &da, addr, a->rd); 43900880d20bSRichard Henderson return advance_pc(dc); 43910880d20bSRichard Henderson } 43920880d20bSRichard Henderson 43930880d20bSRichard Henderson static bool trans_STD(DisasContext *dc, arg_r_r_ri_asi *a) 43940880d20bSRichard Henderson { 43950880d20bSRichard Henderson TCGv addr; 43960880d20bSRichard Henderson DisasASI da; 43970880d20bSRichard Henderson 43980880d20bSRichard Henderson if (a->rd & 1) { 43990880d20bSRichard Henderson return false; 44000880d20bSRichard Henderson } 44010880d20bSRichard Henderson addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 44020880d20bSRichard Henderson if (addr == NULL) { 44030880d20bSRichard Henderson return false; 44040880d20bSRichard Henderson } 44050880d20bSRichard Henderson da = resolve_asi(dc, a->asi, MO_TEUQ); 440642071fc1SRichard Henderson gen_stda_asi(dc, &da, addr, a->rd); 44070880d20bSRichard Henderson return advance_pc(dc); 44080880d20bSRichard Henderson } 44090880d20bSRichard Henderson 4410cf07cd1eSRichard Henderson static bool trans_LDSTUB(DisasContext *dc, arg_r_r_ri_asi *a) 4411cf07cd1eSRichard Henderson { 4412cf07cd1eSRichard Henderson TCGv addr, reg; 4413cf07cd1eSRichard Henderson DisasASI da; 4414cf07cd1eSRichard Henderson 4415cf07cd1eSRichard Henderson addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 4416cf07cd1eSRichard Henderson if (addr == NULL) { 4417cf07cd1eSRichard Henderson return false; 4418cf07cd1eSRichard Henderson } 4419cf07cd1eSRichard Henderson da = resolve_asi(dc, a->asi, MO_UB); 4420cf07cd1eSRichard Henderson 4421cf07cd1eSRichard Henderson reg = gen_dest_gpr(dc, a->rd); 4422cf07cd1eSRichard Henderson gen_ldstub_asi(dc, &da, reg, addr); 4423cf07cd1eSRichard Henderson gen_store_gpr(dc, a->rd, reg); 4424cf07cd1eSRichard Henderson return advance_pc(dc); 4425cf07cd1eSRichard Henderson } 4426cf07cd1eSRichard Henderson 4427dca544b9SRichard Henderson static bool trans_SWAP(DisasContext *dc, arg_r_r_ri_asi *a) 4428dca544b9SRichard Henderson { 4429dca544b9SRichard Henderson TCGv addr, dst, src; 4430dca544b9SRichard Henderson DisasASI da; 4431dca544b9SRichard Henderson 4432dca544b9SRichard Henderson addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 4433dca544b9SRichard Henderson if (addr == NULL) { 4434dca544b9SRichard Henderson return false; 4435dca544b9SRichard Henderson } 4436dca544b9SRichard Henderson da = resolve_asi(dc, a->asi, MO_TEUL); 4437dca544b9SRichard Henderson 4438dca544b9SRichard Henderson dst = gen_dest_gpr(dc, a->rd); 4439dca544b9SRichard Henderson src = gen_load_gpr(dc, a->rd); 4440dca544b9SRichard Henderson gen_swap_asi(dc, &da, dst, src, addr); 4441dca544b9SRichard Henderson gen_store_gpr(dc, a->rd, dst); 4442dca544b9SRichard Henderson return advance_pc(dc); 4443dca544b9SRichard Henderson } 4444dca544b9SRichard Henderson 4445d0a11d25SRichard Henderson static bool do_casa(DisasContext *dc, arg_r_r_ri_asi *a, MemOp mop) 4446d0a11d25SRichard Henderson { 4447d0a11d25SRichard Henderson TCGv addr, o, n, c; 4448d0a11d25SRichard Henderson DisasASI da; 4449d0a11d25SRichard Henderson 4450d0a11d25SRichard Henderson addr = gen_ldst_addr(dc, a->rs1, true, 0); 4451d0a11d25SRichard Henderson if (addr == NULL) { 4452d0a11d25SRichard Henderson return false; 4453d0a11d25SRichard Henderson } 4454d0a11d25SRichard Henderson da = resolve_asi(dc, a->asi, mop); 4455d0a11d25SRichard Henderson 4456d0a11d25SRichard Henderson o = gen_dest_gpr(dc, a->rd); 4457d0a11d25SRichard Henderson n = gen_load_gpr(dc, a->rd); 4458d0a11d25SRichard Henderson c = gen_load_gpr(dc, a->rs2_or_imm); 4459d0a11d25SRichard Henderson gen_cas_asi(dc, &da, o, n, c, addr); 4460d0a11d25SRichard Henderson gen_store_gpr(dc, a->rd, o); 4461d0a11d25SRichard Henderson return advance_pc(dc); 4462d0a11d25SRichard Henderson } 4463d0a11d25SRichard Henderson 4464d0a11d25SRichard Henderson TRANS(CASA, CASA, do_casa, a, MO_TEUL) 4465d0a11d25SRichard Henderson TRANS(CASXA, 64, do_casa, a, MO_TEUQ) 4466d0a11d25SRichard Henderson 446706c060d9SRichard Henderson static bool do_ld_fpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp sz) 446806c060d9SRichard Henderson { 446906c060d9SRichard Henderson TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 447006c060d9SRichard Henderson DisasASI da; 447106c060d9SRichard Henderson 447206c060d9SRichard Henderson if (addr == NULL) { 447306c060d9SRichard Henderson return false; 447406c060d9SRichard Henderson } 447506c060d9SRichard Henderson if (gen_trap_ifnofpu(dc)) { 447606c060d9SRichard Henderson return true; 447706c060d9SRichard Henderson } 447806c060d9SRichard Henderson if (sz == MO_128 && gen_trap_float128(dc)) { 447906c060d9SRichard Henderson return true; 448006c060d9SRichard Henderson } 448106c060d9SRichard Henderson da = resolve_asi(dc, a->asi, MO_TE | sz); 4482287b1152SRichard Henderson gen_ldf_asi(dc, &da, sz, addr, a->rd); 448306c060d9SRichard Henderson gen_update_fprs_dirty(dc, a->rd); 448406c060d9SRichard Henderson return advance_pc(dc); 448506c060d9SRichard Henderson } 448606c060d9SRichard Henderson 448706c060d9SRichard Henderson TRANS(LDF, ALL, do_ld_fpr, a, MO_32) 448806c060d9SRichard Henderson TRANS(LDDF, ALL, do_ld_fpr, a, MO_64) 448906c060d9SRichard Henderson TRANS(LDQF, ALL, do_ld_fpr, a, MO_128) 449006c060d9SRichard Henderson 4491287b1152SRichard Henderson TRANS(LDFA, 64, do_ld_fpr, a, MO_32) 4492287b1152SRichard Henderson TRANS(LDDFA, 64, do_ld_fpr, a, MO_64) 4493287b1152SRichard Henderson TRANS(LDQFA, 64, do_ld_fpr, a, MO_128) 4494287b1152SRichard Henderson 449506c060d9SRichard Henderson static bool do_st_fpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp sz) 449606c060d9SRichard Henderson { 449706c060d9SRichard Henderson TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 449806c060d9SRichard Henderson DisasASI da; 449906c060d9SRichard Henderson 450006c060d9SRichard Henderson if (addr == NULL) { 450106c060d9SRichard Henderson return false; 450206c060d9SRichard Henderson } 450306c060d9SRichard Henderson if (gen_trap_ifnofpu(dc)) { 450406c060d9SRichard Henderson return true; 450506c060d9SRichard Henderson } 450606c060d9SRichard Henderson if (sz == MO_128 && gen_trap_float128(dc)) { 450706c060d9SRichard Henderson return true; 450806c060d9SRichard Henderson } 450906c060d9SRichard Henderson da = resolve_asi(dc, a->asi, MO_TE | sz); 4510287b1152SRichard Henderson gen_stf_asi(dc, &da, sz, addr, a->rd); 451106c060d9SRichard Henderson return advance_pc(dc); 451206c060d9SRichard Henderson } 451306c060d9SRichard Henderson 451406c060d9SRichard Henderson TRANS(STF, ALL, do_st_fpr, a, MO_32) 451506c060d9SRichard Henderson TRANS(STDF, ALL, do_st_fpr, a, MO_64) 451606c060d9SRichard Henderson TRANS(STQF, ALL, do_st_fpr, a, MO_128) 451706c060d9SRichard Henderson 4518287b1152SRichard Henderson TRANS(STFA, 64, do_st_fpr, a, MO_32) 4519287b1152SRichard Henderson TRANS(STDFA, 64, do_st_fpr, a, MO_64) 4520287b1152SRichard Henderson TRANS(STQFA, 64, do_st_fpr, a, MO_128) 4521287b1152SRichard Henderson 452206c060d9SRichard Henderson static bool trans_STDFQ(DisasContext *dc, arg_STDFQ *a) 452306c060d9SRichard Henderson { 452406c060d9SRichard Henderson if (!avail_32(dc)) { 452506c060d9SRichard Henderson return false; 452606c060d9SRichard Henderson } 452706c060d9SRichard Henderson if (!supervisor(dc)) { 452806c060d9SRichard Henderson return raise_priv(dc); 452906c060d9SRichard Henderson } 453006c060d9SRichard Henderson if (gen_trap_ifnofpu(dc)) { 453106c060d9SRichard Henderson return true; 453206c060d9SRichard Henderson } 453306c060d9SRichard Henderson gen_op_fpexception_im(dc, FSR_FTT_SEQ_ERROR); 453406c060d9SRichard Henderson return true; 453506c060d9SRichard Henderson } 453606c060d9SRichard Henderson 4537d8c5b92fSRichard Henderson static bool trans_LDFSR(DisasContext *dc, arg_r_r_ri *a) 45383d3c0673SRichard Henderson { 45393590f01eSRichard Henderson TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 4540d8c5b92fSRichard Henderson TCGv_i32 tmp; 45413590f01eSRichard Henderson 45423d3c0673SRichard Henderson if (addr == NULL) { 45433d3c0673SRichard Henderson return false; 45443d3c0673SRichard Henderson } 45453d3c0673SRichard Henderson if (gen_trap_ifnofpu(dc)) { 45463d3c0673SRichard Henderson return true; 45473d3c0673SRichard Henderson } 4548d8c5b92fSRichard Henderson 4549d8c5b92fSRichard Henderson tmp = tcg_temp_new_i32(); 4550d8c5b92fSRichard Henderson tcg_gen_qemu_ld_i32(tmp, addr, dc->mem_idx, MO_TEUL | MO_ALIGN); 4551d8c5b92fSRichard Henderson 4552d8c5b92fSRichard Henderson tcg_gen_extract_i32(cpu_fcc[0], tmp, FSR_FCC0_SHIFT, 2); 4553d8c5b92fSRichard Henderson /* LDFSR does not change FCC[1-3]. */ 4554d8c5b92fSRichard Henderson 4555d8c5b92fSRichard Henderson gen_helper_set_fsr_nofcc_noftt(tcg_env, tmp); 45563d3c0673SRichard Henderson return advance_pc(dc); 45573d3c0673SRichard Henderson } 45583d3c0673SRichard Henderson 4559298c52f7SRichard Henderson static bool do_ldxfsr(DisasContext *dc, arg_r_r_ri *a, bool entire) 4560d8c5b92fSRichard Henderson { 4561d8c5b92fSRichard Henderson #ifdef TARGET_SPARC64 4562d8c5b92fSRichard Henderson TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 4563d8c5b92fSRichard Henderson TCGv_i64 t64; 4564d8c5b92fSRichard Henderson TCGv_i32 lo, hi; 4565d8c5b92fSRichard Henderson 4566d8c5b92fSRichard Henderson if (addr == NULL) { 4567d8c5b92fSRichard Henderson return false; 4568d8c5b92fSRichard Henderson } 4569d8c5b92fSRichard Henderson if (gen_trap_ifnofpu(dc)) { 4570d8c5b92fSRichard Henderson return true; 4571d8c5b92fSRichard Henderson } 4572d8c5b92fSRichard Henderson 4573d8c5b92fSRichard Henderson t64 = tcg_temp_new_i64(); 4574d8c5b92fSRichard Henderson tcg_gen_qemu_ld_i64(t64, addr, dc->mem_idx, MO_TEUQ | MO_ALIGN); 4575d8c5b92fSRichard Henderson 4576d8c5b92fSRichard Henderson lo = tcg_temp_new_i32(); 4577d8c5b92fSRichard Henderson hi = cpu_fcc[3]; 4578d8c5b92fSRichard Henderson tcg_gen_extr_i64_i32(lo, hi, t64); 4579d8c5b92fSRichard Henderson tcg_gen_extract_i32(cpu_fcc[0], lo, FSR_FCC0_SHIFT, 2); 4580d8c5b92fSRichard Henderson tcg_gen_extract_i32(cpu_fcc[1], hi, FSR_FCC1_SHIFT - 32, 2); 4581d8c5b92fSRichard Henderson tcg_gen_extract_i32(cpu_fcc[2], hi, FSR_FCC2_SHIFT - 32, 2); 4582d8c5b92fSRichard Henderson tcg_gen_extract_i32(cpu_fcc[3], hi, FSR_FCC3_SHIFT - 32, 2); 4583d8c5b92fSRichard Henderson 4584298c52f7SRichard Henderson if (entire) { 4585298c52f7SRichard Henderson gen_helper_set_fsr_nofcc(tcg_env, lo); 4586298c52f7SRichard Henderson } else { 4587d8c5b92fSRichard Henderson gen_helper_set_fsr_nofcc_noftt(tcg_env, lo); 4588298c52f7SRichard Henderson } 4589d8c5b92fSRichard Henderson return advance_pc(dc); 4590d8c5b92fSRichard Henderson #else 4591d8c5b92fSRichard Henderson return false; 4592d8c5b92fSRichard Henderson #endif 4593d8c5b92fSRichard Henderson } 45943d3c0673SRichard Henderson 4595298c52f7SRichard Henderson TRANS(LDXFSR, 64, do_ldxfsr, a, false) 4596298c52f7SRichard Henderson TRANS(LDXEFSR, VIS3B, do_ldxfsr, a, true) 4597298c52f7SRichard Henderson 45983d3c0673SRichard Henderson static bool do_stfsr(DisasContext *dc, arg_r_r_ri *a, MemOp mop) 45993d3c0673SRichard Henderson { 46003d3c0673SRichard Henderson TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 46011ccd6e13SRichard Henderson TCGv fsr; 46021ccd6e13SRichard Henderson 46033d3c0673SRichard Henderson if (addr == NULL) { 46043d3c0673SRichard Henderson return false; 46053d3c0673SRichard Henderson } 46063d3c0673SRichard Henderson if (gen_trap_ifnofpu(dc)) { 46073d3c0673SRichard Henderson return true; 46083d3c0673SRichard Henderson } 46091ccd6e13SRichard Henderson 46101ccd6e13SRichard Henderson fsr = tcg_temp_new(); 46111ccd6e13SRichard Henderson gen_helper_get_fsr(fsr, tcg_env); 46121ccd6e13SRichard Henderson tcg_gen_qemu_st_tl(fsr, addr, dc->mem_idx, mop | MO_ALIGN); 46133d3c0673SRichard Henderson return advance_pc(dc); 46143d3c0673SRichard Henderson } 46153d3c0673SRichard Henderson 46163d3c0673SRichard Henderson TRANS(STFSR, ALL, do_stfsr, a, MO_TEUL) 46173d3c0673SRichard Henderson TRANS(STXFSR, 64, do_stfsr, a, MO_TEUQ) 46183d3c0673SRichard Henderson 46191210a036SRichard Henderson static bool do_fc(DisasContext *dc, int rd, int32_t c) 46203a38260eSRichard Henderson { 46213a38260eSRichard Henderson if (gen_trap_ifnofpu(dc)) { 46223a38260eSRichard Henderson return true; 46233a38260eSRichard Henderson } 46241210a036SRichard Henderson gen_store_fpr_F(dc, rd, tcg_constant_i32(c)); 46253a38260eSRichard Henderson return advance_pc(dc); 46263a38260eSRichard Henderson } 46273a38260eSRichard Henderson 46283a38260eSRichard Henderson TRANS(FZEROs, VIS1, do_fc, a->rd, 0) 46291210a036SRichard Henderson TRANS(FONEs, VIS1, do_fc, a->rd, -1) 46303a38260eSRichard Henderson 46313a38260eSRichard Henderson static bool do_dc(DisasContext *dc, int rd, int64_t c) 46323a38260eSRichard Henderson { 46333a38260eSRichard Henderson if (gen_trap_ifnofpu(dc)) { 46343a38260eSRichard Henderson return true; 46353a38260eSRichard Henderson } 46361210a036SRichard Henderson gen_store_fpr_D(dc, rd, tcg_constant_i64(c)); 46373a38260eSRichard Henderson return advance_pc(dc); 46383a38260eSRichard Henderson } 46393a38260eSRichard Henderson 46403a38260eSRichard Henderson TRANS(FZEROd, VIS1, do_dc, a->rd, 0) 46413a38260eSRichard Henderson TRANS(FONEd, VIS1, do_dc, a->rd, -1) 46423a38260eSRichard Henderson 4643baf3dbf2SRichard Henderson static bool do_ff(DisasContext *dc, arg_r_r *a, 4644baf3dbf2SRichard Henderson void (*func)(TCGv_i32, TCGv_i32)) 4645baf3dbf2SRichard Henderson { 4646baf3dbf2SRichard Henderson TCGv_i32 tmp; 4647baf3dbf2SRichard Henderson 4648baf3dbf2SRichard Henderson if (gen_trap_ifnofpu(dc)) { 4649baf3dbf2SRichard Henderson return true; 4650baf3dbf2SRichard Henderson } 4651baf3dbf2SRichard Henderson 4652baf3dbf2SRichard Henderson tmp = gen_load_fpr_F(dc, a->rs); 4653baf3dbf2SRichard Henderson func(tmp, tmp); 4654baf3dbf2SRichard Henderson gen_store_fpr_F(dc, a->rd, tmp); 4655baf3dbf2SRichard Henderson return advance_pc(dc); 4656baf3dbf2SRichard Henderson } 4657baf3dbf2SRichard Henderson 4658baf3dbf2SRichard Henderson TRANS(FMOVs, ALL, do_ff, a, gen_op_fmovs) 4659baf3dbf2SRichard Henderson TRANS(FNEGs, ALL, do_ff, a, gen_op_fnegs) 4660baf3dbf2SRichard Henderson TRANS(FABSs, ALL, do_ff, a, gen_op_fabss) 4661baf3dbf2SRichard Henderson TRANS(FSRCs, VIS1, do_ff, a, tcg_gen_mov_i32) 4662baf3dbf2SRichard Henderson TRANS(FNOTs, VIS1, do_ff, a, tcg_gen_not_i32) 4663baf3dbf2SRichard Henderson 46642f722641SRichard Henderson static bool do_fd(DisasContext *dc, arg_r_r *a, 46652f722641SRichard Henderson void (*func)(TCGv_i32, TCGv_i64)) 46662f722641SRichard Henderson { 46672f722641SRichard Henderson TCGv_i32 dst; 46682f722641SRichard Henderson TCGv_i64 src; 46692f722641SRichard Henderson 46702f722641SRichard Henderson if (gen_trap_ifnofpu(dc)) { 46712f722641SRichard Henderson return true; 46722f722641SRichard Henderson } 46732f722641SRichard Henderson 4674388a6465SRichard Henderson dst = tcg_temp_new_i32(); 46752f722641SRichard Henderson src = gen_load_fpr_D(dc, a->rs); 46762f722641SRichard Henderson func(dst, src); 46772f722641SRichard Henderson gen_store_fpr_F(dc, a->rd, dst); 46782f722641SRichard Henderson return advance_pc(dc); 46792f722641SRichard Henderson } 46802f722641SRichard Henderson 46812f722641SRichard Henderson TRANS(FPACK16, VIS1, do_fd, a, gen_op_fpack16) 46822f722641SRichard Henderson TRANS(FPACKFIX, VIS1, do_fd, a, gen_op_fpackfix) 46832f722641SRichard Henderson 4684119cb94fSRichard Henderson static bool do_env_ff(DisasContext *dc, arg_r_r *a, 4685119cb94fSRichard Henderson void (*func)(TCGv_i32, TCGv_env, TCGv_i32)) 4686119cb94fSRichard Henderson { 4687119cb94fSRichard Henderson TCGv_i32 tmp; 4688119cb94fSRichard Henderson 4689119cb94fSRichard Henderson if (gen_trap_ifnofpu(dc)) { 4690119cb94fSRichard Henderson return true; 4691119cb94fSRichard Henderson } 4692119cb94fSRichard Henderson 4693119cb94fSRichard Henderson tmp = gen_load_fpr_F(dc, a->rs); 4694119cb94fSRichard Henderson func(tmp, tcg_env, tmp); 4695119cb94fSRichard Henderson gen_store_fpr_F(dc, a->rd, tmp); 4696119cb94fSRichard Henderson return advance_pc(dc); 4697119cb94fSRichard Henderson } 4698119cb94fSRichard Henderson 4699119cb94fSRichard Henderson TRANS(FSQRTs, ALL, do_env_ff, a, gen_helper_fsqrts) 4700119cb94fSRichard Henderson TRANS(FiTOs, ALL, do_env_ff, a, gen_helper_fitos) 4701119cb94fSRichard Henderson TRANS(FsTOi, ALL, do_env_ff, a, gen_helper_fstoi) 4702119cb94fSRichard Henderson 47038c94bcd8SRichard Henderson static bool do_env_fd(DisasContext *dc, arg_r_r *a, 47048c94bcd8SRichard Henderson void (*func)(TCGv_i32, TCGv_env, TCGv_i64)) 47058c94bcd8SRichard Henderson { 47068c94bcd8SRichard Henderson TCGv_i32 dst; 47078c94bcd8SRichard Henderson TCGv_i64 src; 47088c94bcd8SRichard Henderson 47098c94bcd8SRichard Henderson if (gen_trap_ifnofpu(dc)) { 47108c94bcd8SRichard Henderson return true; 47118c94bcd8SRichard Henderson } 47128c94bcd8SRichard Henderson 4713388a6465SRichard Henderson dst = tcg_temp_new_i32(); 47148c94bcd8SRichard Henderson src = gen_load_fpr_D(dc, a->rs); 47158c94bcd8SRichard Henderson func(dst, tcg_env, src); 47168c94bcd8SRichard Henderson gen_store_fpr_F(dc, a->rd, dst); 47178c94bcd8SRichard Henderson return advance_pc(dc); 47188c94bcd8SRichard Henderson } 47198c94bcd8SRichard Henderson 47208c94bcd8SRichard Henderson TRANS(FdTOs, ALL, do_env_fd, a, gen_helper_fdtos) 47218c94bcd8SRichard Henderson TRANS(FdTOi, ALL, do_env_fd, a, gen_helper_fdtoi) 47228c94bcd8SRichard Henderson TRANS(FxTOs, 64, do_env_fd, a, gen_helper_fxtos) 47238c94bcd8SRichard Henderson 4724c6d83e4fSRichard Henderson static bool do_dd(DisasContext *dc, arg_r_r *a, 4725c6d83e4fSRichard Henderson void (*func)(TCGv_i64, TCGv_i64)) 4726c6d83e4fSRichard Henderson { 4727c6d83e4fSRichard Henderson TCGv_i64 dst, src; 4728c6d83e4fSRichard Henderson 4729c6d83e4fSRichard Henderson if (gen_trap_ifnofpu(dc)) { 4730c6d83e4fSRichard Henderson return true; 4731c6d83e4fSRichard Henderson } 4732c6d83e4fSRichard Henderson 473352f46d46SRichard Henderson dst = tcg_temp_new_i64(); 4734c6d83e4fSRichard Henderson src = gen_load_fpr_D(dc, a->rs); 4735c6d83e4fSRichard Henderson func(dst, src); 4736c6d83e4fSRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 4737c6d83e4fSRichard Henderson return advance_pc(dc); 4738c6d83e4fSRichard Henderson } 4739c6d83e4fSRichard Henderson 4740c6d83e4fSRichard Henderson TRANS(FMOVd, 64, do_dd, a, gen_op_fmovd) 4741c6d83e4fSRichard Henderson TRANS(FNEGd, 64, do_dd, a, gen_op_fnegd) 4742c6d83e4fSRichard Henderson TRANS(FABSd, 64, do_dd, a, gen_op_fabsd) 4743c6d83e4fSRichard Henderson TRANS(FSRCd, VIS1, do_dd, a, tcg_gen_mov_i64) 4744c6d83e4fSRichard Henderson TRANS(FNOTd, VIS1, do_dd, a, tcg_gen_not_i64) 4745c6d83e4fSRichard Henderson 47468aa418b3SRichard Henderson static bool do_env_dd(DisasContext *dc, arg_r_r *a, 47478aa418b3SRichard Henderson void (*func)(TCGv_i64, TCGv_env, TCGv_i64)) 47488aa418b3SRichard Henderson { 47498aa418b3SRichard Henderson TCGv_i64 dst, src; 47508aa418b3SRichard Henderson 47518aa418b3SRichard Henderson if (gen_trap_ifnofpu(dc)) { 47528aa418b3SRichard Henderson return true; 47538aa418b3SRichard Henderson } 47548aa418b3SRichard Henderson 475552f46d46SRichard Henderson dst = tcg_temp_new_i64(); 47568aa418b3SRichard Henderson src = gen_load_fpr_D(dc, a->rs); 47578aa418b3SRichard Henderson func(dst, tcg_env, src); 47588aa418b3SRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 47598aa418b3SRichard Henderson return advance_pc(dc); 47608aa418b3SRichard Henderson } 47618aa418b3SRichard Henderson 47628aa418b3SRichard Henderson TRANS(FSQRTd, ALL, do_env_dd, a, gen_helper_fsqrtd) 47638aa418b3SRichard Henderson TRANS(FxTOd, 64, do_env_dd, a, gen_helper_fxtod) 47648aa418b3SRichard Henderson TRANS(FdTOx, 64, do_env_dd, a, gen_helper_fdtox) 47658aa418b3SRichard Henderson 47667b616f36SRichard Henderson static bool do_df(DisasContext *dc, arg_r_r *a, 47677b616f36SRichard Henderson void (*func)(TCGv_i64, TCGv_i32)) 47687b616f36SRichard Henderson { 47697b616f36SRichard Henderson TCGv_i64 dst; 47707b616f36SRichard Henderson TCGv_i32 src; 47717b616f36SRichard Henderson 47727b616f36SRichard Henderson if (gen_trap_ifnofpu(dc)) { 47737b616f36SRichard Henderson return true; 47747b616f36SRichard Henderson } 47757b616f36SRichard Henderson 47767b616f36SRichard Henderson dst = tcg_temp_new_i64(); 47777b616f36SRichard Henderson src = gen_load_fpr_F(dc, a->rs); 47787b616f36SRichard Henderson func(dst, src); 47797b616f36SRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 47807b616f36SRichard Henderson return advance_pc(dc); 47817b616f36SRichard Henderson } 47827b616f36SRichard Henderson 47837b616f36SRichard Henderson TRANS(FEXPAND, VIS1, do_df, a, gen_helper_fexpand) 47847b616f36SRichard Henderson 4785199d43efSRichard Henderson static bool do_env_df(DisasContext *dc, arg_r_r *a, 4786199d43efSRichard Henderson void (*func)(TCGv_i64, TCGv_env, TCGv_i32)) 4787199d43efSRichard Henderson { 4788199d43efSRichard Henderson TCGv_i64 dst; 4789199d43efSRichard Henderson TCGv_i32 src; 4790199d43efSRichard Henderson 4791199d43efSRichard Henderson if (gen_trap_ifnofpu(dc)) { 4792199d43efSRichard Henderson return true; 4793199d43efSRichard Henderson } 4794199d43efSRichard Henderson 479552f46d46SRichard Henderson dst = tcg_temp_new_i64(); 4796199d43efSRichard Henderson src = gen_load_fpr_F(dc, a->rs); 4797199d43efSRichard Henderson func(dst, tcg_env, src); 4798199d43efSRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 4799199d43efSRichard Henderson return advance_pc(dc); 4800199d43efSRichard Henderson } 4801199d43efSRichard Henderson 4802199d43efSRichard Henderson TRANS(FiTOd, ALL, do_env_df, a, gen_helper_fitod) 4803199d43efSRichard Henderson TRANS(FsTOd, ALL, do_env_df, a, gen_helper_fstod) 4804199d43efSRichard Henderson TRANS(FsTOx, 64, do_env_df, a, gen_helper_fstox) 4805199d43efSRichard Henderson 4806daf457d4SRichard Henderson static bool do_qq(DisasContext *dc, arg_r_r *a, 4807daf457d4SRichard Henderson void (*func)(TCGv_i128, TCGv_i128)) 4808f4e18df5SRichard Henderson { 480933ec4245SRichard Henderson TCGv_i128 t; 4810f4e18df5SRichard Henderson 4811f4e18df5SRichard Henderson if (gen_trap_ifnofpu(dc)) { 4812f4e18df5SRichard Henderson return true; 4813f4e18df5SRichard Henderson } 4814f4e18df5SRichard Henderson if (gen_trap_float128(dc)) { 4815f4e18df5SRichard Henderson return true; 4816f4e18df5SRichard Henderson } 4817f4e18df5SRichard Henderson 4818f4e18df5SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 481933ec4245SRichard Henderson t = gen_load_fpr_Q(dc, a->rs); 4820daf457d4SRichard Henderson func(t, t); 482133ec4245SRichard Henderson gen_store_fpr_Q(dc, a->rd, t); 4822f4e18df5SRichard Henderson return advance_pc(dc); 4823f4e18df5SRichard Henderson } 4824f4e18df5SRichard Henderson 4825daf457d4SRichard Henderson TRANS(FMOVq, 64, do_qq, a, tcg_gen_mov_i128) 4826daf457d4SRichard Henderson TRANS(FNEGq, 64, do_qq, a, gen_op_fnegq) 4827daf457d4SRichard Henderson TRANS(FABSq, 64, do_qq, a, gen_op_fabsq) 4828f4e18df5SRichard Henderson 4829c995216bSRichard Henderson static bool do_env_qq(DisasContext *dc, arg_r_r *a, 4830e41716beSRichard Henderson void (*func)(TCGv_i128, TCGv_env, TCGv_i128)) 4831c995216bSRichard Henderson { 4832e41716beSRichard Henderson TCGv_i128 t; 4833e41716beSRichard Henderson 4834c995216bSRichard Henderson if (gen_trap_ifnofpu(dc)) { 4835c995216bSRichard Henderson return true; 4836c995216bSRichard Henderson } 4837c995216bSRichard Henderson if (gen_trap_float128(dc)) { 4838c995216bSRichard Henderson return true; 4839c995216bSRichard Henderson } 4840c995216bSRichard Henderson 4841e41716beSRichard Henderson t = gen_load_fpr_Q(dc, a->rs); 4842e41716beSRichard Henderson func(t, tcg_env, t); 4843e41716beSRichard Henderson gen_store_fpr_Q(dc, a->rd, t); 4844c995216bSRichard Henderson return advance_pc(dc); 4845c995216bSRichard Henderson } 4846c995216bSRichard Henderson 4847c995216bSRichard Henderson TRANS(FSQRTq, ALL, do_env_qq, a, gen_helper_fsqrtq) 4848c995216bSRichard Henderson 4849bd9c5c42SRichard Henderson static bool do_env_fq(DisasContext *dc, arg_r_r *a, 4850d81e3efeSRichard Henderson void (*func)(TCGv_i32, TCGv_env, TCGv_i128)) 4851bd9c5c42SRichard Henderson { 4852d81e3efeSRichard Henderson TCGv_i128 src; 4853bd9c5c42SRichard Henderson TCGv_i32 dst; 4854bd9c5c42SRichard Henderson 4855bd9c5c42SRichard Henderson if (gen_trap_ifnofpu(dc)) { 4856bd9c5c42SRichard Henderson return true; 4857bd9c5c42SRichard Henderson } 4858bd9c5c42SRichard Henderson if (gen_trap_float128(dc)) { 4859bd9c5c42SRichard Henderson return true; 4860bd9c5c42SRichard Henderson } 4861bd9c5c42SRichard Henderson 4862d81e3efeSRichard Henderson src = gen_load_fpr_Q(dc, a->rs); 4863388a6465SRichard Henderson dst = tcg_temp_new_i32(); 4864d81e3efeSRichard Henderson func(dst, tcg_env, src); 4865bd9c5c42SRichard Henderson gen_store_fpr_F(dc, a->rd, dst); 4866bd9c5c42SRichard Henderson return advance_pc(dc); 4867bd9c5c42SRichard Henderson } 4868bd9c5c42SRichard Henderson 4869bd9c5c42SRichard Henderson TRANS(FqTOs, ALL, do_env_fq, a, gen_helper_fqtos) 4870bd9c5c42SRichard Henderson TRANS(FqTOi, ALL, do_env_fq, a, gen_helper_fqtoi) 4871bd9c5c42SRichard Henderson 48721617586fSRichard Henderson static bool do_env_dq(DisasContext *dc, arg_r_r *a, 487325a5769eSRichard Henderson void (*func)(TCGv_i64, TCGv_env, TCGv_i128)) 48741617586fSRichard Henderson { 487525a5769eSRichard Henderson TCGv_i128 src; 48761617586fSRichard Henderson TCGv_i64 dst; 48771617586fSRichard Henderson 48781617586fSRichard Henderson if (gen_trap_ifnofpu(dc)) { 48791617586fSRichard Henderson return true; 48801617586fSRichard Henderson } 48811617586fSRichard Henderson if (gen_trap_float128(dc)) { 48821617586fSRichard Henderson return true; 48831617586fSRichard Henderson } 48841617586fSRichard Henderson 488525a5769eSRichard Henderson src = gen_load_fpr_Q(dc, a->rs); 488652f46d46SRichard Henderson dst = tcg_temp_new_i64(); 488725a5769eSRichard Henderson func(dst, tcg_env, src); 48881617586fSRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 48891617586fSRichard Henderson return advance_pc(dc); 48901617586fSRichard Henderson } 48911617586fSRichard Henderson 48921617586fSRichard Henderson TRANS(FqTOd, ALL, do_env_dq, a, gen_helper_fqtod) 48931617586fSRichard Henderson TRANS(FqTOx, 64, do_env_dq, a, gen_helper_fqtox) 48941617586fSRichard Henderson 489513ebcc77SRichard Henderson static bool do_env_qf(DisasContext *dc, arg_r_r *a, 48960b2a61ccSRichard Henderson void (*func)(TCGv_i128, TCGv_env, TCGv_i32)) 489713ebcc77SRichard Henderson { 489813ebcc77SRichard Henderson TCGv_i32 src; 48990b2a61ccSRichard Henderson TCGv_i128 dst; 490013ebcc77SRichard Henderson 490113ebcc77SRichard Henderson if (gen_trap_ifnofpu(dc)) { 490213ebcc77SRichard Henderson return true; 490313ebcc77SRichard Henderson } 490413ebcc77SRichard Henderson if (gen_trap_float128(dc)) { 490513ebcc77SRichard Henderson return true; 490613ebcc77SRichard Henderson } 490713ebcc77SRichard Henderson 490813ebcc77SRichard Henderson src = gen_load_fpr_F(dc, a->rs); 49090b2a61ccSRichard Henderson dst = tcg_temp_new_i128(); 49100b2a61ccSRichard Henderson func(dst, tcg_env, src); 49110b2a61ccSRichard Henderson gen_store_fpr_Q(dc, a->rd, dst); 491213ebcc77SRichard Henderson return advance_pc(dc); 491313ebcc77SRichard Henderson } 491413ebcc77SRichard Henderson 491513ebcc77SRichard Henderson TRANS(FiTOq, ALL, do_env_qf, a, gen_helper_fitoq) 491613ebcc77SRichard Henderson TRANS(FsTOq, ALL, do_env_qf, a, gen_helper_fstoq) 491713ebcc77SRichard Henderson 49187b8e3e1aSRichard Henderson static bool do_env_qd(DisasContext *dc, arg_r_r *a, 4919fdc50716SRichard Henderson void (*func)(TCGv_i128, TCGv_env, TCGv_i64)) 49207b8e3e1aSRichard Henderson { 49217b8e3e1aSRichard Henderson TCGv_i64 src; 4922fdc50716SRichard Henderson TCGv_i128 dst; 49237b8e3e1aSRichard Henderson 49247b8e3e1aSRichard Henderson if (gen_trap_ifnofpu(dc)) { 49257b8e3e1aSRichard Henderson return true; 49267b8e3e1aSRichard Henderson } 49277b8e3e1aSRichard Henderson if (gen_trap_float128(dc)) { 49287b8e3e1aSRichard Henderson return true; 49297b8e3e1aSRichard Henderson } 49307b8e3e1aSRichard Henderson 49317b8e3e1aSRichard Henderson src = gen_load_fpr_D(dc, a->rs); 4932fdc50716SRichard Henderson dst = tcg_temp_new_i128(); 4933fdc50716SRichard Henderson func(dst, tcg_env, src); 4934fdc50716SRichard Henderson gen_store_fpr_Q(dc, a->rd, dst); 49357b8e3e1aSRichard Henderson return advance_pc(dc); 49367b8e3e1aSRichard Henderson } 49377b8e3e1aSRichard Henderson 49387b8e3e1aSRichard Henderson TRANS(FdTOq, ALL, do_env_qd, a, gen_helper_fdtoq) 49397b8e3e1aSRichard Henderson TRANS(FxTOq, 64, do_env_qd, a, gen_helper_fxtoq) 49407b8e3e1aSRichard Henderson 49417f10b52fSRichard Henderson static bool do_fff(DisasContext *dc, arg_r_r_r *a, 49427f10b52fSRichard Henderson void (*func)(TCGv_i32, TCGv_i32, TCGv_i32)) 49437f10b52fSRichard Henderson { 49447f10b52fSRichard Henderson TCGv_i32 src1, src2; 49457f10b52fSRichard Henderson 49467f10b52fSRichard Henderson if (gen_trap_ifnofpu(dc)) { 49477f10b52fSRichard Henderson return true; 49487f10b52fSRichard Henderson } 49497f10b52fSRichard Henderson 49507f10b52fSRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1); 49517f10b52fSRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2); 49527f10b52fSRichard Henderson func(src1, src1, src2); 49537f10b52fSRichard Henderson gen_store_fpr_F(dc, a->rd, src1); 49547f10b52fSRichard Henderson return advance_pc(dc); 49557f10b52fSRichard Henderson } 49567f10b52fSRichard Henderson 49577f10b52fSRichard Henderson TRANS(FPADD16s, VIS1, do_fff, a, tcg_gen_vec_add16_i32) 49587f10b52fSRichard Henderson TRANS(FPADD32s, VIS1, do_fff, a, tcg_gen_add_i32) 49597f10b52fSRichard Henderson TRANS(FPSUB16s, VIS1, do_fff, a, tcg_gen_vec_sub16_i32) 49607f10b52fSRichard Henderson TRANS(FPSUB32s, VIS1, do_fff, a, tcg_gen_sub_i32) 49617f10b52fSRichard Henderson TRANS(FNORs, VIS1, do_fff, a, tcg_gen_nor_i32) 49627f10b52fSRichard Henderson TRANS(FANDNOTs, VIS1, do_fff, a, tcg_gen_andc_i32) 49637f10b52fSRichard Henderson TRANS(FXORs, VIS1, do_fff, a, tcg_gen_xor_i32) 49647f10b52fSRichard Henderson TRANS(FNANDs, VIS1, do_fff, a, tcg_gen_nand_i32) 49657f10b52fSRichard Henderson TRANS(FANDs, VIS1, do_fff, a, tcg_gen_and_i32) 49667f10b52fSRichard Henderson TRANS(FXNORs, VIS1, do_fff, a, tcg_gen_eqv_i32) 49677f10b52fSRichard Henderson TRANS(FORNOTs, VIS1, do_fff, a, tcg_gen_orc_i32) 49687f10b52fSRichard Henderson TRANS(FORs, VIS1, do_fff, a, tcg_gen_or_i32) 49697f10b52fSRichard Henderson 49703d50b728SRichard Henderson TRANS(FHADDs, VIS3, do_fff, a, gen_op_fhadds) 49713d50b728SRichard Henderson TRANS(FHSUBs, VIS3, do_fff, a, gen_op_fhsubs) 49723d50b728SRichard Henderson TRANS(FNHADDs, VIS3, do_fff, a, gen_op_fnhadds) 49733d50b728SRichard Henderson 49740d1d3aafSRichard Henderson TRANS(FPADDS16s, VIS3, do_fff, a, gen_op_fpadds16s) 49750d1d3aafSRichard Henderson TRANS(FPSUBS16s, VIS3, do_fff, a, gen_op_fpsubs16s) 49760d1d3aafSRichard Henderson TRANS(FPADDS32s, VIS3, do_fff, a, gen_op_fpadds32s) 49770d1d3aafSRichard Henderson TRANS(FPSUBS32s, VIS3, do_fff, a, gen_op_fpsubs32s) 49780d1d3aafSRichard Henderson 4979c1514961SRichard Henderson static bool do_env_fff(DisasContext *dc, arg_r_r_r *a, 4980c1514961SRichard Henderson void (*func)(TCGv_i32, TCGv_env, TCGv_i32, TCGv_i32)) 4981c1514961SRichard Henderson { 4982c1514961SRichard Henderson TCGv_i32 src1, src2; 4983c1514961SRichard Henderson 4984c1514961SRichard Henderson if (gen_trap_ifnofpu(dc)) { 4985c1514961SRichard Henderson return true; 4986c1514961SRichard Henderson } 4987c1514961SRichard Henderson 4988c1514961SRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1); 4989c1514961SRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2); 4990c1514961SRichard Henderson func(src1, tcg_env, src1, src2); 4991c1514961SRichard Henderson gen_store_fpr_F(dc, a->rd, src1); 4992c1514961SRichard Henderson return advance_pc(dc); 4993c1514961SRichard Henderson } 4994c1514961SRichard Henderson 4995c1514961SRichard Henderson TRANS(FADDs, ALL, do_env_fff, a, gen_helper_fadds) 4996c1514961SRichard Henderson TRANS(FSUBs, ALL, do_env_fff, a, gen_helper_fsubs) 4997c1514961SRichard Henderson TRANS(FMULs, ALL, do_env_fff, a, gen_helper_fmuls) 4998c1514961SRichard Henderson TRANS(FDIVs, ALL, do_env_fff, a, gen_helper_fdivs) 49993d50b728SRichard Henderson TRANS(FNADDs, VIS3, do_env_fff, a, gen_helper_fnadds) 50003d50b728SRichard Henderson TRANS(FNMULs, VIS3, do_env_fff, a, gen_helper_fnmuls) 5001c1514961SRichard Henderson 5002a859602cSRichard Henderson static bool do_dff(DisasContext *dc, arg_r_r_r *a, 5003a859602cSRichard Henderson void (*func)(TCGv_i64, TCGv_i32, TCGv_i32)) 5004a859602cSRichard Henderson { 5005a859602cSRichard Henderson TCGv_i64 dst; 5006a859602cSRichard Henderson TCGv_i32 src1, src2; 5007a859602cSRichard Henderson 5008a859602cSRichard Henderson if (gen_trap_ifnofpu(dc)) { 5009a859602cSRichard Henderson return true; 5010a859602cSRichard Henderson } 5011a859602cSRichard Henderson 501252f46d46SRichard Henderson dst = tcg_temp_new_i64(); 5013a859602cSRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1); 5014a859602cSRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2); 5015a859602cSRichard Henderson func(dst, src1, src2); 5016a859602cSRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 5017a859602cSRichard Henderson return advance_pc(dc); 5018a859602cSRichard Henderson } 5019a859602cSRichard Henderson 5020a859602cSRichard Henderson TRANS(FMUL8x16AU, VIS1, do_dff, a, gen_op_fmul8x16au) 5021a859602cSRichard Henderson TRANS(FMUL8x16AL, VIS1, do_dff, a, gen_op_fmul8x16al) 5022be8998e0SRichard Henderson TRANS(FMULD8SUx16, VIS1, do_dff, a, gen_op_fmuld8sux16) 5023be8998e0SRichard Henderson TRANS(FMULD8ULx16, VIS1, do_dff, a, gen_op_fmuld8ulx16) 5024d3ef26afSRichard Henderson TRANS(FPMERGE, VIS1, do_dff, a, gen_helper_fpmerge) 5025a859602cSRichard Henderson 50269157dcccSRichard Henderson static bool do_dfd(DisasContext *dc, arg_r_r_r *a, 50279157dcccSRichard Henderson void (*func)(TCGv_i64, TCGv_i32, TCGv_i64)) 50289157dcccSRichard Henderson { 50299157dcccSRichard Henderson TCGv_i64 dst, src2; 50309157dcccSRichard Henderson TCGv_i32 src1; 50319157dcccSRichard Henderson 50329157dcccSRichard Henderson if (gen_trap_ifnofpu(dc)) { 50339157dcccSRichard Henderson return true; 50349157dcccSRichard Henderson } 50359157dcccSRichard Henderson 503652f46d46SRichard Henderson dst = tcg_temp_new_i64(); 50379157dcccSRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1); 50389157dcccSRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2); 50399157dcccSRichard Henderson func(dst, src1, src2); 50409157dcccSRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 50419157dcccSRichard Henderson return advance_pc(dc); 50429157dcccSRichard Henderson } 50439157dcccSRichard Henderson 50449157dcccSRichard Henderson TRANS(FMUL8x16, VIS1, do_dfd, a, gen_helper_fmul8x16) 50459157dcccSRichard Henderson 504628c131a3SRichard Henderson static bool do_gvec_ddd(DisasContext *dc, arg_r_r_r *a, MemOp vece, 504728c131a3SRichard Henderson void (*func)(unsigned, uint32_t, uint32_t, 504828c131a3SRichard Henderson uint32_t, uint32_t, uint32_t)) 504928c131a3SRichard Henderson { 505028c131a3SRichard Henderson if (gen_trap_ifnofpu(dc)) { 505128c131a3SRichard Henderson return true; 505228c131a3SRichard Henderson } 505328c131a3SRichard Henderson 505428c131a3SRichard Henderson func(vece, gen_offset_fpr_D(a->rd), gen_offset_fpr_D(a->rs1), 505528c131a3SRichard Henderson gen_offset_fpr_D(a->rs2), 8, 8); 505628c131a3SRichard Henderson return advance_pc(dc); 505728c131a3SRichard Henderson } 505828c131a3SRichard Henderson 5059b99c1bbdSRichard Henderson TRANS(FPADD8, VIS4, do_gvec_ddd, a, MO_8, tcg_gen_gvec_add) 506028c131a3SRichard Henderson TRANS(FPADD16, VIS1, do_gvec_ddd, a, MO_16, tcg_gen_gvec_add) 506128c131a3SRichard Henderson TRANS(FPADD32, VIS1, do_gvec_ddd, a, MO_32, tcg_gen_gvec_add) 5062b99c1bbdSRichard Henderson 5063b99c1bbdSRichard Henderson TRANS(FPSUB8, VIS4, do_gvec_ddd, a, MO_8, tcg_gen_gvec_sub) 506428c131a3SRichard Henderson TRANS(FPSUB16, VIS1, do_gvec_ddd, a, MO_16, tcg_gen_gvec_sub) 506528c131a3SRichard Henderson TRANS(FPSUB32, VIS1, do_gvec_ddd, a, MO_32, tcg_gen_gvec_sub) 5066b99c1bbdSRichard Henderson 50677837185eSRichard Henderson TRANS(FCHKSM16, VIS3, do_gvec_ddd, a, MO_16, gen_op_fchksm16) 5068d6ff1ccbSRichard Henderson TRANS(FMEAN16, VIS3, do_gvec_ddd, a, MO_16, gen_op_fmean16) 506928c131a3SRichard Henderson 5070b99c1bbdSRichard Henderson TRANS(FPADDS8, VIS4, do_gvec_ddd, a, MO_8, tcg_gen_gvec_ssadd) 50710d1d3aafSRichard Henderson TRANS(FPADDS16, VIS3, do_gvec_ddd, a, MO_16, tcg_gen_gvec_ssadd) 50720d1d3aafSRichard Henderson TRANS(FPADDS32, VIS3, do_gvec_ddd, a, MO_32, tcg_gen_gvec_ssadd) 5073b99c1bbdSRichard Henderson TRANS(FPADDUS8, VIS4, do_gvec_ddd, a, MO_8, tcg_gen_gvec_usadd) 5074b99c1bbdSRichard Henderson TRANS(FPADDUS16, VIS4, do_gvec_ddd, a, MO_16, tcg_gen_gvec_usadd) 5075b99c1bbdSRichard Henderson 5076b99c1bbdSRichard Henderson TRANS(FPSUBS8, VIS4, do_gvec_ddd, a, MO_8, tcg_gen_gvec_sssub) 50770d1d3aafSRichard Henderson TRANS(FPSUBS16, VIS3, do_gvec_ddd, a, MO_16, tcg_gen_gvec_sssub) 50780d1d3aafSRichard Henderson TRANS(FPSUBS32, VIS3, do_gvec_ddd, a, MO_32, tcg_gen_gvec_sssub) 5079b99c1bbdSRichard Henderson TRANS(FPSUBUS8, VIS4, do_gvec_ddd, a, MO_8, tcg_gen_gvec_ussub) 5080b99c1bbdSRichard Henderson TRANS(FPSUBUS16, VIS4, do_gvec_ddd, a, MO_16, tcg_gen_gvec_ussub) 50810d1d3aafSRichard Henderson 5082fbc5c8d4SRichard Henderson TRANS(FSLL16, VIS3, do_gvec_ddd, a, MO_16, tcg_gen_gvec_shlv) 5083fbc5c8d4SRichard Henderson TRANS(FSLL32, VIS3, do_gvec_ddd, a, MO_32, tcg_gen_gvec_shlv) 5084fbc5c8d4SRichard Henderson TRANS(FSRL16, VIS3, do_gvec_ddd, a, MO_16, tcg_gen_gvec_shrv) 5085fbc5c8d4SRichard Henderson TRANS(FSRL32, VIS3, do_gvec_ddd, a, MO_32, tcg_gen_gvec_shrv) 5086fbc5c8d4SRichard Henderson TRANS(FSRA16, VIS3, do_gvec_ddd, a, MO_16, tcg_gen_gvec_sarv) 5087fbc5c8d4SRichard Henderson TRANS(FSRA32, VIS3, do_gvec_ddd, a, MO_32, tcg_gen_gvec_sarv) 5088fbc5c8d4SRichard Henderson 5089db11dfeaSRichard Henderson TRANS(FPMIN8, VIS4, do_gvec_ddd, a, MO_8, tcg_gen_gvec_smin) 5090db11dfeaSRichard Henderson TRANS(FPMIN16, VIS4, do_gvec_ddd, a, MO_16, tcg_gen_gvec_smin) 5091db11dfeaSRichard Henderson TRANS(FPMIN32, VIS4, do_gvec_ddd, a, MO_32, tcg_gen_gvec_smin) 5092db11dfeaSRichard Henderson TRANS(FPMINU8, VIS4, do_gvec_ddd, a, MO_8, tcg_gen_gvec_umin) 5093db11dfeaSRichard Henderson TRANS(FPMINU16, VIS4, do_gvec_ddd, a, MO_16, tcg_gen_gvec_umin) 5094db11dfeaSRichard Henderson TRANS(FPMINU32, VIS4, do_gvec_ddd, a, MO_32, tcg_gen_gvec_umin) 5095db11dfeaSRichard Henderson 5096db11dfeaSRichard Henderson TRANS(FPMAX8, VIS4, do_gvec_ddd, a, MO_8, tcg_gen_gvec_smax) 5097db11dfeaSRichard Henderson TRANS(FPMAX16, VIS4, do_gvec_ddd, a, MO_16, tcg_gen_gvec_smax) 5098db11dfeaSRichard Henderson TRANS(FPMAX32, VIS4, do_gvec_ddd, a, MO_32, tcg_gen_gvec_smax) 5099db11dfeaSRichard Henderson TRANS(FPMAXU8, VIS4, do_gvec_ddd, a, MO_8, tcg_gen_gvec_umax) 5100db11dfeaSRichard Henderson TRANS(FPMAXU16, VIS4, do_gvec_ddd, a, MO_16, tcg_gen_gvec_umax) 5101db11dfeaSRichard Henderson TRANS(FPMAXU32, VIS4, do_gvec_ddd, a, MO_32, tcg_gen_gvec_umax) 5102db11dfeaSRichard Henderson 5103e06c9f83SRichard Henderson static bool do_ddd(DisasContext *dc, arg_r_r_r *a, 5104e06c9f83SRichard Henderson void (*func)(TCGv_i64, TCGv_i64, TCGv_i64)) 5105e06c9f83SRichard Henderson { 5106e06c9f83SRichard Henderson TCGv_i64 dst, src1, src2; 5107e06c9f83SRichard Henderson 5108e06c9f83SRichard Henderson if (gen_trap_ifnofpu(dc)) { 5109e06c9f83SRichard Henderson return true; 5110e06c9f83SRichard Henderson } 5111e06c9f83SRichard Henderson 511252f46d46SRichard Henderson dst = tcg_temp_new_i64(); 5113e06c9f83SRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1); 5114e06c9f83SRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2); 5115e06c9f83SRichard Henderson func(dst, src1, src2); 5116e06c9f83SRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 5117e06c9f83SRichard Henderson return advance_pc(dc); 5118e06c9f83SRichard Henderson } 5119e06c9f83SRichard Henderson 5120e06c9f83SRichard Henderson TRANS(FMUL8SUx16, VIS1, do_ddd, a, gen_helper_fmul8sux16) 5121e06c9f83SRichard Henderson TRANS(FMUL8ULx16, VIS1, do_ddd, a, gen_helper_fmul8ulx16) 5122e06c9f83SRichard Henderson 5123e06c9f83SRichard Henderson TRANS(FNORd, VIS1, do_ddd, a, tcg_gen_nor_i64) 5124e06c9f83SRichard Henderson TRANS(FANDNOTd, VIS1, do_ddd, a, tcg_gen_andc_i64) 5125e06c9f83SRichard Henderson TRANS(FXORd, VIS1, do_ddd, a, tcg_gen_xor_i64) 5126e06c9f83SRichard Henderson TRANS(FNANDd, VIS1, do_ddd, a, tcg_gen_nand_i64) 5127e06c9f83SRichard Henderson TRANS(FANDd, VIS1, do_ddd, a, tcg_gen_and_i64) 5128e06c9f83SRichard Henderson TRANS(FXNORd, VIS1, do_ddd, a, tcg_gen_eqv_i64) 5129e06c9f83SRichard Henderson TRANS(FORNOTd, VIS1, do_ddd, a, tcg_gen_orc_i64) 5130e06c9f83SRichard Henderson TRANS(FORd, VIS1, do_ddd, a, tcg_gen_or_i64) 5131e06c9f83SRichard Henderson 51324b6edc0aSRichard Henderson TRANS(FPACK32, VIS1, do_ddd, a, gen_op_fpack32) 5133b2b48493SRichard Henderson TRANS(FALIGNDATAg, VIS1, do_ddd, a, gen_op_faligndata_g) 51344b6edc0aSRichard Henderson TRANS(BSHUFFLE, VIS2, do_ddd, a, gen_op_bshuffle) 51354b6edc0aSRichard Henderson 51363d50b728SRichard Henderson TRANS(FHADDd, VIS3, do_ddd, a, gen_op_fhaddd) 51373d50b728SRichard Henderson TRANS(FHSUBd, VIS3, do_ddd, a, gen_op_fhsubd) 51383d50b728SRichard Henderson TRANS(FNHADDd, VIS3, do_ddd, a, gen_op_fnhaddd) 51393d50b728SRichard Henderson 5140bc3f14a9SRichard Henderson TRANS(FPADD64, VIS3B, do_ddd, a, tcg_gen_add_i64) 5141bc3f14a9SRichard Henderson TRANS(FPSUB64, VIS3B, do_ddd, a, tcg_gen_sub_i64) 5142fbc5c8d4SRichard Henderson TRANS(FSLAS16, VIS3, do_ddd, a, gen_helper_fslas16) 5143fbc5c8d4SRichard Henderson TRANS(FSLAS32, VIS3, do_ddd, a, gen_helper_fslas32) 5144bc3f14a9SRichard Henderson 5145e2fa6bd1SRichard Henderson static bool do_rdd(DisasContext *dc, arg_r_r_r *a, 5146e2fa6bd1SRichard Henderson void (*func)(TCGv, TCGv_i64, TCGv_i64)) 5147e2fa6bd1SRichard Henderson { 5148e2fa6bd1SRichard Henderson TCGv_i64 src1, src2; 5149e2fa6bd1SRichard Henderson TCGv dst; 5150e2fa6bd1SRichard Henderson 5151e2fa6bd1SRichard Henderson if (gen_trap_ifnofpu(dc)) { 5152e2fa6bd1SRichard Henderson return true; 5153e2fa6bd1SRichard Henderson } 5154e2fa6bd1SRichard Henderson 5155e2fa6bd1SRichard Henderson dst = gen_dest_gpr(dc, a->rd); 5156e2fa6bd1SRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1); 5157e2fa6bd1SRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2); 5158e2fa6bd1SRichard Henderson func(dst, src1, src2); 5159e2fa6bd1SRichard Henderson gen_store_gpr(dc, a->rd, dst); 5160e2fa6bd1SRichard Henderson return advance_pc(dc); 5161e2fa6bd1SRichard Henderson } 5162e2fa6bd1SRichard Henderson 5163e2fa6bd1SRichard Henderson TRANS(FPCMPLE16, VIS1, do_rdd, a, gen_helper_fcmple16) 5164e2fa6bd1SRichard Henderson TRANS(FPCMPNE16, VIS1, do_rdd, a, gen_helper_fcmpne16) 5165e2fa6bd1SRichard Henderson TRANS(FPCMPGT16, VIS1, do_rdd, a, gen_helper_fcmpgt16) 5166e2fa6bd1SRichard Henderson TRANS(FPCMPEQ16, VIS1, do_rdd, a, gen_helper_fcmpeq16) 5167b3c934ddSRichard Henderson TRANS(FPCMPULE16, VIS4, do_rdd, a, gen_helper_fcmpule16) 5168b3c934ddSRichard Henderson TRANS(FPCMPUGT16, VIS4, do_rdd, a, gen_helper_fcmpugt16) 5169e2fa6bd1SRichard Henderson 5170e2fa6bd1SRichard Henderson TRANS(FPCMPLE32, VIS1, do_rdd, a, gen_helper_fcmple32) 5171e2fa6bd1SRichard Henderson TRANS(FPCMPNE32, VIS1, do_rdd, a, gen_helper_fcmpne32) 5172e2fa6bd1SRichard Henderson TRANS(FPCMPGT32, VIS1, do_rdd, a, gen_helper_fcmpgt32) 5173e2fa6bd1SRichard Henderson TRANS(FPCMPEQ32, VIS1, do_rdd, a, gen_helper_fcmpeq32) 5174b3c934ddSRichard Henderson TRANS(FPCMPULE32, VIS4, do_rdd, a, gen_helper_fcmpule32) 5175b3c934ddSRichard Henderson TRANS(FPCMPUGT32, VIS4, do_rdd, a, gen_helper_fcmpugt32) 5176e2fa6bd1SRichard Henderson 5177669e0774SRichard Henderson TRANS(FPCMPEQ8, VIS3B, do_rdd, a, gen_helper_fcmpeq8) 5178669e0774SRichard Henderson TRANS(FPCMPNE8, VIS3B, do_rdd, a, gen_helper_fcmpne8) 5179669e0774SRichard Henderson TRANS(FPCMPULE8, VIS3B, do_rdd, a, gen_helper_fcmpule8) 5180669e0774SRichard Henderson TRANS(FPCMPUGT8, VIS3B, do_rdd, a, gen_helper_fcmpugt8) 5181b3c934ddSRichard Henderson TRANS(FPCMPLE8, VIS4, do_rdd, a, gen_helper_fcmple8) 5182b3c934ddSRichard Henderson TRANS(FPCMPGT8, VIS4, do_rdd, a, gen_helper_fcmpgt8) 5183669e0774SRichard Henderson 51847d5ebd8fSRichard Henderson TRANS(PDISTN, VIS3, do_rdd, a, gen_op_pdistn) 5185029b0283SRichard Henderson TRANS(XMULX, VIS3, do_rrr, a, gen_helper_xmulx) 5186029b0283SRichard Henderson TRANS(XMULXHI, VIS3, do_rrr, a, gen_helper_xmulxhi) 51877d5ebd8fSRichard Henderson 5188f2a59b0aSRichard Henderson static bool do_env_ddd(DisasContext *dc, arg_r_r_r *a, 5189f2a59b0aSRichard Henderson void (*func)(TCGv_i64, TCGv_env, TCGv_i64, TCGv_i64)) 5190f2a59b0aSRichard Henderson { 5191f2a59b0aSRichard Henderson TCGv_i64 dst, src1, src2; 5192f2a59b0aSRichard Henderson 5193f2a59b0aSRichard Henderson if (gen_trap_ifnofpu(dc)) { 5194f2a59b0aSRichard Henderson return true; 5195f2a59b0aSRichard Henderson } 5196f2a59b0aSRichard Henderson 519752f46d46SRichard Henderson dst = tcg_temp_new_i64(); 5198f2a59b0aSRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1); 5199f2a59b0aSRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2); 5200f2a59b0aSRichard Henderson func(dst, tcg_env, src1, src2); 5201f2a59b0aSRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 5202f2a59b0aSRichard Henderson return advance_pc(dc); 5203f2a59b0aSRichard Henderson } 5204f2a59b0aSRichard Henderson 5205f2a59b0aSRichard Henderson TRANS(FADDd, ALL, do_env_ddd, a, gen_helper_faddd) 5206f2a59b0aSRichard Henderson TRANS(FSUBd, ALL, do_env_ddd, a, gen_helper_fsubd) 5207f2a59b0aSRichard Henderson TRANS(FMULd, ALL, do_env_ddd, a, gen_helper_fmuld) 5208f2a59b0aSRichard Henderson TRANS(FDIVd, ALL, do_env_ddd, a, gen_helper_fdivd) 52093d50b728SRichard Henderson TRANS(FNADDd, VIS3, do_env_ddd, a, gen_helper_fnaddd) 52103d50b728SRichard Henderson TRANS(FNMULd, VIS3, do_env_ddd, a, gen_helper_fnmuld) 5211f2a59b0aSRichard Henderson 5212ff4c711bSRichard Henderson static bool trans_FsMULd(DisasContext *dc, arg_r_r_r *a) 5213ff4c711bSRichard Henderson { 5214ff4c711bSRichard Henderson TCGv_i64 dst; 5215ff4c711bSRichard Henderson TCGv_i32 src1, src2; 5216ff4c711bSRichard Henderson 5217ff4c711bSRichard Henderson if (gen_trap_ifnofpu(dc)) { 5218ff4c711bSRichard Henderson return true; 5219ff4c711bSRichard Henderson } 5220ff4c711bSRichard Henderson if (!(dc->def->features & CPU_FEATURE_FSMULD)) { 5221ff4c711bSRichard Henderson return raise_unimpfpop(dc); 5222ff4c711bSRichard Henderson } 5223ff4c711bSRichard Henderson 522452f46d46SRichard Henderson dst = tcg_temp_new_i64(); 5225ff4c711bSRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1); 5226ff4c711bSRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2); 5227ff4c711bSRichard Henderson gen_helper_fsmuld(dst, tcg_env, src1, src2); 5228ff4c711bSRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 5229ff4c711bSRichard Henderson return advance_pc(dc); 5230ff4c711bSRichard Henderson } 5231ff4c711bSRichard Henderson 52323d50b728SRichard Henderson static bool trans_FNsMULd(DisasContext *dc, arg_r_r_r *a) 52333d50b728SRichard Henderson { 52343d50b728SRichard Henderson TCGv_i64 dst; 52353d50b728SRichard Henderson TCGv_i32 src1, src2; 52363d50b728SRichard Henderson 52373d50b728SRichard Henderson if (!avail_VIS3(dc)) { 52383d50b728SRichard Henderson return false; 52393d50b728SRichard Henderson } 52403d50b728SRichard Henderson if (gen_trap_ifnofpu(dc)) { 52413d50b728SRichard Henderson return true; 52423d50b728SRichard Henderson } 52433d50b728SRichard Henderson dst = tcg_temp_new_i64(); 52443d50b728SRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1); 52453d50b728SRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2); 52463d50b728SRichard Henderson gen_helper_fnsmuld(dst, tcg_env, src1, src2); 52473d50b728SRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 52483d50b728SRichard Henderson return advance_pc(dc); 52493d50b728SRichard Henderson } 52503d50b728SRichard Henderson 52514fd71d19SRichard Henderson static bool do_ffff(DisasContext *dc, arg_r_r_r_r *a, 52524fd71d19SRichard Henderson void (*func)(TCGv_i32, TCGv_i32, TCGv_i32, TCGv_i32)) 52534fd71d19SRichard Henderson { 52544fd71d19SRichard Henderson TCGv_i32 dst, src1, src2, src3; 52554fd71d19SRichard Henderson 52564fd71d19SRichard Henderson if (gen_trap_ifnofpu(dc)) { 52574fd71d19SRichard Henderson return true; 52584fd71d19SRichard Henderson } 52594fd71d19SRichard Henderson 52604fd71d19SRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1); 52614fd71d19SRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2); 52624fd71d19SRichard Henderson src3 = gen_load_fpr_F(dc, a->rs3); 52634fd71d19SRichard Henderson dst = tcg_temp_new_i32(); 52644fd71d19SRichard Henderson func(dst, src1, src2, src3); 52654fd71d19SRichard Henderson gen_store_fpr_F(dc, a->rd, dst); 52664fd71d19SRichard Henderson return advance_pc(dc); 52674fd71d19SRichard Henderson } 52684fd71d19SRichard Henderson 52694fd71d19SRichard Henderson TRANS(FMADDs, FMAF, do_ffff, a, gen_op_fmadds) 52704fd71d19SRichard Henderson TRANS(FMSUBs, FMAF, do_ffff, a, gen_op_fmsubs) 52714fd71d19SRichard Henderson TRANS(FNMSUBs, FMAF, do_ffff, a, gen_op_fnmsubs) 52724fd71d19SRichard Henderson TRANS(FNMADDs, FMAF, do_ffff, a, gen_op_fnmadds) 52734fd71d19SRichard Henderson 52744fd71d19SRichard Henderson static bool do_dddd(DisasContext *dc, arg_r_r_r_r *a, 5275afb04344SRichard Henderson void (*func)(TCGv_i64, TCGv_i64, TCGv_i64, TCGv_i64)) 5276afb04344SRichard Henderson { 52774fd71d19SRichard Henderson TCGv_i64 dst, src1, src2, src3; 5278afb04344SRichard Henderson 5279afb04344SRichard Henderson if (gen_trap_ifnofpu(dc)) { 5280afb04344SRichard Henderson return true; 5281afb04344SRichard Henderson } 5282afb04344SRichard Henderson 528352f46d46SRichard Henderson dst = tcg_temp_new_i64(); 5284afb04344SRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1); 5285afb04344SRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2); 52864fd71d19SRichard Henderson src3 = gen_load_fpr_D(dc, a->rs3); 52874fd71d19SRichard Henderson func(dst, src1, src2, src3); 5288afb04344SRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 5289afb04344SRichard Henderson return advance_pc(dc); 5290afb04344SRichard Henderson } 5291afb04344SRichard Henderson 5292afb04344SRichard Henderson TRANS(PDIST, VIS1, do_dddd, a, gen_helper_pdist) 52934fd71d19SRichard Henderson TRANS(FMADDd, FMAF, do_dddd, a, gen_op_fmaddd) 52944fd71d19SRichard Henderson TRANS(FMSUBd, FMAF, do_dddd, a, gen_op_fmsubd) 52954fd71d19SRichard Henderson TRANS(FNMSUBd, FMAF, do_dddd, a, gen_op_fnmsubd) 52964fd71d19SRichard Henderson TRANS(FNMADDd, FMAF, do_dddd, a, gen_op_fnmaddd) 529768a414e9SRichard Henderson TRANS(FPMADDX, IMA, do_dddd, a, gen_op_fpmaddx) 529868a414e9SRichard Henderson TRANS(FPMADDXHI, IMA, do_dddd, a, gen_op_fpmaddxhi) 5299afb04344SRichard Henderson 5300b2b48493SRichard Henderson static bool trans_FALIGNDATAi(DisasContext *dc, arg_r_r_r *a) 5301b2b48493SRichard Henderson { 5302b2b48493SRichard Henderson TCGv_i64 dst, src1, src2; 5303b2b48493SRichard Henderson TCGv src3; 5304b2b48493SRichard Henderson 5305b2b48493SRichard Henderson if (!avail_VIS4(dc)) { 5306b2b48493SRichard Henderson return false; 5307b2b48493SRichard Henderson } 5308b2b48493SRichard Henderson if (gen_trap_ifnofpu(dc)) { 5309b2b48493SRichard Henderson return true; 5310b2b48493SRichard Henderson } 5311b2b48493SRichard Henderson 5312b2b48493SRichard Henderson dst = tcg_temp_new_i64(); 5313b2b48493SRichard Henderson src1 = gen_load_fpr_D(dc, a->rd); 5314b2b48493SRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2); 5315b2b48493SRichard Henderson src3 = gen_load_gpr(dc, a->rs1); 5316b2b48493SRichard Henderson gen_op_faligndata_i(dst, src1, src2, src3); 5317b2b48493SRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 5318b2b48493SRichard Henderson return advance_pc(dc); 5319b2b48493SRichard Henderson } 5320b2b48493SRichard Henderson 5321a4056239SRichard Henderson static bool do_env_qqq(DisasContext *dc, arg_r_r_r *a, 532216bedf89SRichard Henderson void (*func)(TCGv_i128, TCGv_env, TCGv_i128, TCGv_i128)) 5323a4056239SRichard Henderson { 532416bedf89SRichard Henderson TCGv_i128 src1, src2; 532516bedf89SRichard Henderson 5326a4056239SRichard Henderson if (gen_trap_ifnofpu(dc)) { 5327a4056239SRichard Henderson return true; 5328a4056239SRichard Henderson } 5329a4056239SRichard Henderson if (gen_trap_float128(dc)) { 5330a4056239SRichard Henderson return true; 5331a4056239SRichard Henderson } 5332a4056239SRichard Henderson 533316bedf89SRichard Henderson src1 = gen_load_fpr_Q(dc, a->rs1); 533416bedf89SRichard Henderson src2 = gen_load_fpr_Q(dc, a->rs2); 533516bedf89SRichard Henderson func(src1, tcg_env, src1, src2); 533616bedf89SRichard Henderson gen_store_fpr_Q(dc, a->rd, src1); 5337a4056239SRichard Henderson return advance_pc(dc); 5338a4056239SRichard Henderson } 5339a4056239SRichard Henderson 5340a4056239SRichard Henderson TRANS(FADDq, ALL, do_env_qqq, a, gen_helper_faddq) 5341a4056239SRichard Henderson TRANS(FSUBq, ALL, do_env_qqq, a, gen_helper_fsubq) 5342a4056239SRichard Henderson TRANS(FMULq, ALL, do_env_qqq, a, gen_helper_fmulq) 5343a4056239SRichard Henderson TRANS(FDIVq, ALL, do_env_qqq, a, gen_helper_fdivq) 5344a4056239SRichard Henderson 53455e3b17bbSRichard Henderson static bool trans_FdMULq(DisasContext *dc, arg_r_r_r *a) 53465e3b17bbSRichard Henderson { 53475e3b17bbSRichard Henderson TCGv_i64 src1, src2; 5348ba21dc99SRichard Henderson TCGv_i128 dst; 53495e3b17bbSRichard Henderson 53505e3b17bbSRichard Henderson if (gen_trap_ifnofpu(dc)) { 53515e3b17bbSRichard Henderson return true; 53525e3b17bbSRichard Henderson } 53535e3b17bbSRichard Henderson if (gen_trap_float128(dc)) { 53545e3b17bbSRichard Henderson return true; 53555e3b17bbSRichard Henderson } 53565e3b17bbSRichard Henderson 53575e3b17bbSRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1); 53585e3b17bbSRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2); 5359ba21dc99SRichard Henderson dst = tcg_temp_new_i128(); 5360ba21dc99SRichard Henderson gen_helper_fdmulq(dst, tcg_env, src1, src2); 5361ba21dc99SRichard Henderson gen_store_fpr_Q(dc, a->rd, dst); 53625e3b17bbSRichard Henderson return advance_pc(dc); 53635e3b17bbSRichard Henderson } 53645e3b17bbSRichard Henderson 5365f7ec8155SRichard Henderson static bool do_fmovr(DisasContext *dc, arg_FMOVRs *a, bool is_128, 5366f7ec8155SRichard Henderson void (*func)(DisasContext *, DisasCompare *, int, int)) 5367f7ec8155SRichard Henderson { 5368f7ec8155SRichard Henderson DisasCompare cmp; 5369f7ec8155SRichard Henderson 53702c4f56c9SRichard Henderson if (!gen_compare_reg(&cmp, a->cond, gen_load_gpr(dc, a->rs1))) { 53712c4f56c9SRichard Henderson return false; 53722c4f56c9SRichard Henderson } 5373f7ec8155SRichard Henderson if (gen_trap_ifnofpu(dc)) { 5374f7ec8155SRichard Henderson return true; 5375f7ec8155SRichard Henderson } 5376f7ec8155SRichard Henderson if (is_128 && gen_trap_float128(dc)) { 5377f7ec8155SRichard Henderson return true; 5378f7ec8155SRichard Henderson } 5379f7ec8155SRichard Henderson 5380f7ec8155SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 5381f7ec8155SRichard Henderson func(dc, &cmp, a->rd, a->rs2); 5382f7ec8155SRichard Henderson return advance_pc(dc); 5383f7ec8155SRichard Henderson } 5384f7ec8155SRichard Henderson 5385f7ec8155SRichard Henderson TRANS(FMOVRs, 64, do_fmovr, a, false, gen_fmovs) 5386f7ec8155SRichard Henderson TRANS(FMOVRd, 64, do_fmovr, a, false, gen_fmovd) 5387f7ec8155SRichard Henderson TRANS(FMOVRq, 64, do_fmovr, a, true, gen_fmovq) 5388f7ec8155SRichard Henderson 5389f7ec8155SRichard Henderson static bool do_fmovcc(DisasContext *dc, arg_FMOVscc *a, bool is_128, 5390f7ec8155SRichard Henderson void (*func)(DisasContext *, DisasCompare *, int, int)) 5391f7ec8155SRichard Henderson { 5392f7ec8155SRichard Henderson DisasCompare cmp; 5393f7ec8155SRichard Henderson 5394f7ec8155SRichard Henderson if (gen_trap_ifnofpu(dc)) { 5395f7ec8155SRichard Henderson return true; 5396f7ec8155SRichard Henderson } 5397f7ec8155SRichard Henderson if (is_128 && gen_trap_float128(dc)) { 5398f7ec8155SRichard Henderson return true; 5399f7ec8155SRichard Henderson } 5400f7ec8155SRichard Henderson 5401f7ec8155SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 5402f7ec8155SRichard Henderson gen_compare(&cmp, a->cc, a->cond, dc); 5403f7ec8155SRichard Henderson func(dc, &cmp, a->rd, a->rs2); 5404f7ec8155SRichard Henderson return advance_pc(dc); 5405f7ec8155SRichard Henderson } 5406f7ec8155SRichard Henderson 5407f7ec8155SRichard Henderson TRANS(FMOVscc, 64, do_fmovcc, a, false, gen_fmovs) 5408f7ec8155SRichard Henderson TRANS(FMOVdcc, 64, do_fmovcc, a, false, gen_fmovd) 5409f7ec8155SRichard Henderson TRANS(FMOVqcc, 64, do_fmovcc, a, true, gen_fmovq) 5410f7ec8155SRichard Henderson 5411f7ec8155SRichard Henderson static bool do_fmovfcc(DisasContext *dc, arg_FMOVsfcc *a, bool is_128, 5412f7ec8155SRichard Henderson void (*func)(DisasContext *, DisasCompare *, int, int)) 5413f7ec8155SRichard Henderson { 5414f7ec8155SRichard Henderson DisasCompare cmp; 5415f7ec8155SRichard Henderson 5416f7ec8155SRichard Henderson if (gen_trap_ifnofpu(dc)) { 5417f7ec8155SRichard Henderson return true; 5418f7ec8155SRichard Henderson } 5419f7ec8155SRichard Henderson if (is_128 && gen_trap_float128(dc)) { 5420f7ec8155SRichard Henderson return true; 5421f7ec8155SRichard Henderson } 5422f7ec8155SRichard Henderson 5423f7ec8155SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 5424f7ec8155SRichard Henderson gen_fcompare(&cmp, a->cc, a->cond); 5425f7ec8155SRichard Henderson func(dc, &cmp, a->rd, a->rs2); 5426f7ec8155SRichard Henderson return advance_pc(dc); 5427f7ec8155SRichard Henderson } 5428f7ec8155SRichard Henderson 5429f7ec8155SRichard Henderson TRANS(FMOVsfcc, 64, do_fmovfcc, a, false, gen_fmovs) 5430f7ec8155SRichard Henderson TRANS(FMOVdfcc, 64, do_fmovfcc, a, false, gen_fmovd) 5431f7ec8155SRichard Henderson TRANS(FMOVqfcc, 64, do_fmovfcc, a, true, gen_fmovq) 5432f7ec8155SRichard Henderson 543340f9ad21SRichard Henderson static bool do_fcmps(DisasContext *dc, arg_FCMPs *a, bool e) 543440f9ad21SRichard Henderson { 543540f9ad21SRichard Henderson TCGv_i32 src1, src2; 543640f9ad21SRichard Henderson 543740f9ad21SRichard Henderson if (avail_32(dc) && a->cc != 0) { 543840f9ad21SRichard Henderson return false; 543940f9ad21SRichard Henderson } 544040f9ad21SRichard Henderson if (gen_trap_ifnofpu(dc)) { 544140f9ad21SRichard Henderson return true; 544240f9ad21SRichard Henderson } 544340f9ad21SRichard Henderson 544440f9ad21SRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1); 544540f9ad21SRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2); 544640f9ad21SRichard Henderson if (e) { 5447d8c5b92fSRichard Henderson gen_helper_fcmpes(cpu_fcc[a->cc], tcg_env, src1, src2); 544840f9ad21SRichard Henderson } else { 5449d8c5b92fSRichard Henderson gen_helper_fcmps(cpu_fcc[a->cc], tcg_env, src1, src2); 545040f9ad21SRichard Henderson } 545140f9ad21SRichard Henderson return advance_pc(dc); 545240f9ad21SRichard Henderson } 545340f9ad21SRichard Henderson 545440f9ad21SRichard Henderson TRANS(FCMPs, ALL, do_fcmps, a, false) 545540f9ad21SRichard Henderson TRANS(FCMPEs, ALL, do_fcmps, a, true) 545640f9ad21SRichard Henderson 545740f9ad21SRichard Henderson static bool do_fcmpd(DisasContext *dc, arg_FCMPd *a, bool e) 545840f9ad21SRichard Henderson { 545940f9ad21SRichard Henderson TCGv_i64 src1, src2; 546040f9ad21SRichard Henderson 546140f9ad21SRichard Henderson if (avail_32(dc) && a->cc != 0) { 546240f9ad21SRichard Henderson return false; 546340f9ad21SRichard Henderson } 546440f9ad21SRichard Henderson if (gen_trap_ifnofpu(dc)) { 546540f9ad21SRichard Henderson return true; 546640f9ad21SRichard Henderson } 546740f9ad21SRichard Henderson 546840f9ad21SRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1); 546940f9ad21SRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2); 547040f9ad21SRichard Henderson if (e) { 5471d8c5b92fSRichard Henderson gen_helper_fcmped(cpu_fcc[a->cc], tcg_env, src1, src2); 547240f9ad21SRichard Henderson } else { 5473d8c5b92fSRichard Henderson gen_helper_fcmpd(cpu_fcc[a->cc], tcg_env, src1, src2); 547440f9ad21SRichard Henderson } 547540f9ad21SRichard Henderson return advance_pc(dc); 547640f9ad21SRichard Henderson } 547740f9ad21SRichard Henderson 547840f9ad21SRichard Henderson TRANS(FCMPd, ALL, do_fcmpd, a, false) 547940f9ad21SRichard Henderson TRANS(FCMPEd, ALL, do_fcmpd, a, true) 548040f9ad21SRichard Henderson 548140f9ad21SRichard Henderson static bool do_fcmpq(DisasContext *dc, arg_FCMPq *a, bool e) 548240f9ad21SRichard Henderson { 5483f3ceafadSRichard Henderson TCGv_i128 src1, src2; 5484f3ceafadSRichard Henderson 548540f9ad21SRichard Henderson if (avail_32(dc) && a->cc != 0) { 548640f9ad21SRichard Henderson return false; 548740f9ad21SRichard Henderson } 548840f9ad21SRichard Henderson if (gen_trap_ifnofpu(dc)) { 548940f9ad21SRichard Henderson return true; 549040f9ad21SRichard Henderson } 549140f9ad21SRichard Henderson if (gen_trap_float128(dc)) { 549240f9ad21SRichard Henderson return true; 549340f9ad21SRichard Henderson } 549440f9ad21SRichard Henderson 5495f3ceafadSRichard Henderson src1 = gen_load_fpr_Q(dc, a->rs1); 5496f3ceafadSRichard Henderson src2 = gen_load_fpr_Q(dc, a->rs2); 549740f9ad21SRichard Henderson if (e) { 5498d8c5b92fSRichard Henderson gen_helper_fcmpeq(cpu_fcc[a->cc], tcg_env, src1, src2); 549940f9ad21SRichard Henderson } else { 5500d8c5b92fSRichard Henderson gen_helper_fcmpq(cpu_fcc[a->cc], tcg_env, src1, src2); 550140f9ad21SRichard Henderson } 550240f9ad21SRichard Henderson return advance_pc(dc); 550340f9ad21SRichard Henderson } 550440f9ad21SRichard Henderson 550540f9ad21SRichard Henderson TRANS(FCMPq, ALL, do_fcmpq, a, false) 550640f9ad21SRichard Henderson TRANS(FCMPEq, ALL, do_fcmpq, a, true) 550740f9ad21SRichard Henderson 55081d3ed3d7SRichard Henderson static bool trans_FLCMPs(DisasContext *dc, arg_FLCMPs *a) 55091d3ed3d7SRichard Henderson { 55101d3ed3d7SRichard Henderson TCGv_i32 src1, src2; 55111d3ed3d7SRichard Henderson 55121d3ed3d7SRichard Henderson if (!avail_VIS3(dc)) { 55131d3ed3d7SRichard Henderson return false; 55141d3ed3d7SRichard Henderson } 55151d3ed3d7SRichard Henderson if (gen_trap_ifnofpu(dc)) { 55161d3ed3d7SRichard Henderson return true; 55171d3ed3d7SRichard Henderson } 55181d3ed3d7SRichard Henderson 55191d3ed3d7SRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1); 55201d3ed3d7SRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2); 55211d3ed3d7SRichard Henderson gen_helper_flcmps(cpu_fcc[a->cc], src1, src2); 55221d3ed3d7SRichard Henderson return advance_pc(dc); 55231d3ed3d7SRichard Henderson } 55241d3ed3d7SRichard Henderson 55251d3ed3d7SRichard Henderson static bool trans_FLCMPd(DisasContext *dc, arg_FLCMPd *a) 55261d3ed3d7SRichard Henderson { 55271d3ed3d7SRichard Henderson TCGv_i64 src1, src2; 55281d3ed3d7SRichard Henderson 55291d3ed3d7SRichard Henderson if (!avail_VIS3(dc)) { 55301d3ed3d7SRichard Henderson return false; 55311d3ed3d7SRichard Henderson } 55321d3ed3d7SRichard Henderson if (gen_trap_ifnofpu(dc)) { 55331d3ed3d7SRichard Henderson return true; 55341d3ed3d7SRichard Henderson } 55351d3ed3d7SRichard Henderson 55361d3ed3d7SRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1); 55371d3ed3d7SRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2); 55381d3ed3d7SRichard Henderson gen_helper_flcmpd(cpu_fcc[a->cc], src1, src2); 55391d3ed3d7SRichard Henderson return advance_pc(dc); 55401d3ed3d7SRichard Henderson } 55411d3ed3d7SRichard Henderson 554209b157e6SRichard Henderson static bool do_movf2r(DisasContext *dc, arg_r_r *a, 554309b157e6SRichard Henderson int (*offset)(unsigned int), 554409b157e6SRichard Henderson void (*load)(TCGv, TCGv_ptr, tcg_target_long)) 554509b157e6SRichard Henderson { 554609b157e6SRichard Henderson TCGv dst; 554709b157e6SRichard Henderson 554809b157e6SRichard Henderson if (gen_trap_ifnofpu(dc)) { 554909b157e6SRichard Henderson return true; 555009b157e6SRichard Henderson } 555109b157e6SRichard Henderson dst = gen_dest_gpr(dc, a->rd); 555209b157e6SRichard Henderson load(dst, tcg_env, offset(a->rs)); 555309b157e6SRichard Henderson gen_store_gpr(dc, a->rd, dst); 555409b157e6SRichard Henderson return advance_pc(dc); 555509b157e6SRichard Henderson } 555609b157e6SRichard Henderson 555709b157e6SRichard Henderson TRANS(MOVsTOsw, VIS3B, do_movf2r, a, gen_offset_fpr_F, tcg_gen_ld32s_tl) 555809b157e6SRichard Henderson TRANS(MOVsTOuw, VIS3B, do_movf2r, a, gen_offset_fpr_F, tcg_gen_ld32u_tl) 555909b157e6SRichard Henderson TRANS(MOVdTOx, VIS3B, do_movf2r, a, gen_offset_fpr_D, tcg_gen_ld_tl) 556009b157e6SRichard Henderson 556109b157e6SRichard Henderson static bool do_movr2f(DisasContext *dc, arg_r_r *a, 556209b157e6SRichard Henderson int (*offset)(unsigned int), 556309b157e6SRichard Henderson void (*store)(TCGv, TCGv_ptr, tcg_target_long)) 556409b157e6SRichard Henderson { 556509b157e6SRichard Henderson TCGv src; 556609b157e6SRichard Henderson 556709b157e6SRichard Henderson if (gen_trap_ifnofpu(dc)) { 556809b157e6SRichard Henderson return true; 556909b157e6SRichard Henderson } 557009b157e6SRichard Henderson src = gen_load_gpr(dc, a->rs); 557109b157e6SRichard Henderson store(src, tcg_env, offset(a->rd)); 557209b157e6SRichard Henderson return advance_pc(dc); 557309b157e6SRichard Henderson } 557409b157e6SRichard Henderson 557509b157e6SRichard Henderson TRANS(MOVwTOs, VIS3B, do_movr2f, a, gen_offset_fpr_F, tcg_gen_st32_tl) 557609b157e6SRichard Henderson TRANS(MOVxTOd, VIS3B, do_movr2f, a, gen_offset_fpr_D, tcg_gen_st_tl) 557709b157e6SRichard Henderson 55786e61bc94SEmilio G. Cota static void sparc_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) 5579fcf5ef2aSThomas Huth { 55806e61bc94SEmilio G. Cota DisasContext *dc = container_of(dcbase, DisasContext, base); 55816e61bc94SEmilio G. Cota int bound; 5582af00be49SEmilio G. Cota 5583af00be49SEmilio G. Cota dc->pc = dc->base.pc_first; 55846e61bc94SEmilio G. Cota dc->npc = (target_ulong)dc->base.tb->cs_base; 55856e61bc94SEmilio G. Cota dc->mem_idx = dc->base.tb->flags & TB_FLAG_MMU_MASK; 558677976769SPhilippe Mathieu-Daudé dc->def = &cpu_env(cs)->def; 55876e61bc94SEmilio G. Cota dc->fpu_enabled = tb_fpu_enabled(dc->base.tb->flags); 55886e61bc94SEmilio G. Cota dc->address_mask_32bit = tb_am_enabled(dc->base.tb->flags); 5589c9b459aaSArtyom Tarasenko #ifndef CONFIG_USER_ONLY 55906e61bc94SEmilio G. Cota dc->supervisor = (dc->base.tb->flags & TB_FLAG_SUPER) != 0; 5591c9b459aaSArtyom Tarasenko #endif 5592fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64 5593fcf5ef2aSThomas Huth dc->fprs_dirty = 0; 55946e61bc94SEmilio G. Cota dc->asi = (dc->base.tb->flags >> TB_FLAG_ASI_SHIFT) & 0xff; 5595c9b459aaSArtyom Tarasenko #ifndef CONFIG_USER_ONLY 55966e61bc94SEmilio G. Cota dc->hypervisor = (dc->base.tb->flags & TB_FLAG_HYPER) != 0; 5597c9b459aaSArtyom Tarasenko #endif 5598fcf5ef2aSThomas Huth #endif 55996e61bc94SEmilio G. Cota /* 56006e61bc94SEmilio G. Cota * if we reach a page boundary, we stop generation so that the 56016e61bc94SEmilio G. Cota * PC of a TT_TFAULT exception is always in the right page 56026e61bc94SEmilio G. Cota */ 56036e61bc94SEmilio G. Cota bound = -(dc->base.pc_first | TARGET_PAGE_MASK) / 4; 56046e61bc94SEmilio G. Cota dc->base.max_insns = MIN(dc->base.max_insns, bound); 5605af00be49SEmilio G. Cota } 5606fcf5ef2aSThomas Huth 56076e61bc94SEmilio G. Cota static void sparc_tr_tb_start(DisasContextBase *db, CPUState *cs) 56086e61bc94SEmilio G. Cota { 56096e61bc94SEmilio G. Cota } 56106e61bc94SEmilio G. Cota 56116e61bc94SEmilio G. Cota static void sparc_tr_insn_start(DisasContextBase *dcbase, CPUState *cs) 56126e61bc94SEmilio G. Cota { 56136e61bc94SEmilio G. Cota DisasContext *dc = container_of(dcbase, DisasContext, base); 5614633c4283SRichard Henderson target_ulong npc = dc->npc; 56156e61bc94SEmilio G. Cota 5616633c4283SRichard Henderson if (npc & 3) { 5617633c4283SRichard Henderson switch (npc) { 5618633c4283SRichard Henderson case JUMP_PC: 5619fcf5ef2aSThomas Huth assert(dc->jump_pc[1] == dc->pc + 4); 5620633c4283SRichard Henderson npc = dc->jump_pc[0] | JUMP_PC; 5621633c4283SRichard Henderson break; 5622633c4283SRichard Henderson case DYNAMIC_PC: 5623633c4283SRichard Henderson case DYNAMIC_PC_LOOKUP: 5624633c4283SRichard Henderson npc = DYNAMIC_PC; 5625633c4283SRichard Henderson break; 5626633c4283SRichard Henderson default: 5627633c4283SRichard Henderson g_assert_not_reached(); 5628fcf5ef2aSThomas Huth } 56296e61bc94SEmilio G. Cota } 5630633c4283SRichard Henderson tcg_gen_insn_start(dc->pc, npc); 5631633c4283SRichard Henderson } 5632fcf5ef2aSThomas Huth 56336e61bc94SEmilio G. Cota static void sparc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) 56346e61bc94SEmilio G. Cota { 56356e61bc94SEmilio G. Cota DisasContext *dc = container_of(dcbase, DisasContext, base); 56366e61bc94SEmilio G. Cota unsigned int insn; 5637fcf5ef2aSThomas Huth 563877976769SPhilippe Mathieu-Daudé insn = translator_ldl(cpu_env(cs), &dc->base, dc->pc); 5639af00be49SEmilio G. Cota dc->base.pc_next += 4; 5640878cc677SRichard Henderson 5641878cc677SRichard Henderson if (!decode(dc, insn)) { 5642ba9c09b4SRichard Henderson gen_exception(dc, TT_ILL_INSN); 5643878cc677SRichard Henderson } 5644fcf5ef2aSThomas Huth 5645af00be49SEmilio G. Cota if (dc->base.is_jmp == DISAS_NORETURN) { 56466e61bc94SEmilio G. Cota return; 5647c5e6ccdfSEmilio G. Cota } 5648af00be49SEmilio G. Cota if (dc->pc != dc->base.pc_next) { 56496e61bc94SEmilio G. Cota dc->base.is_jmp = DISAS_TOO_MANY; 5650af00be49SEmilio G. Cota } 56516e61bc94SEmilio G. Cota } 5652fcf5ef2aSThomas Huth 56536e61bc94SEmilio G. Cota static void sparc_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs) 56546e61bc94SEmilio G. Cota { 56556e61bc94SEmilio G. Cota DisasContext *dc = container_of(dcbase, DisasContext, base); 5656186e7890SRichard Henderson DisasDelayException *e, *e_next; 5657633c4283SRichard Henderson bool may_lookup; 56586e61bc94SEmilio G. Cota 565989527e3aSRichard Henderson finishing_insn(dc); 566089527e3aSRichard Henderson 566146bb0137SMark Cave-Ayland switch (dc->base.is_jmp) { 566246bb0137SMark Cave-Ayland case DISAS_NEXT: 566346bb0137SMark Cave-Ayland case DISAS_TOO_MANY: 5664633c4283SRichard Henderson if (((dc->pc | dc->npc) & 3) == 0) { 5665fcf5ef2aSThomas Huth /* static PC and NPC: we can use direct chaining */ 5666fcf5ef2aSThomas Huth gen_goto_tb(dc, 0, dc->pc, dc->npc); 5667633c4283SRichard Henderson break; 5668fcf5ef2aSThomas Huth } 5669633c4283SRichard Henderson 5670930f1865SRichard Henderson may_lookup = true; 5671633c4283SRichard Henderson if (dc->pc & 3) { 5672633c4283SRichard Henderson switch (dc->pc) { 5673633c4283SRichard Henderson case DYNAMIC_PC_LOOKUP: 5674633c4283SRichard Henderson break; 5675633c4283SRichard Henderson case DYNAMIC_PC: 5676633c4283SRichard Henderson may_lookup = false; 5677633c4283SRichard Henderson break; 5678633c4283SRichard Henderson default: 5679633c4283SRichard Henderson g_assert_not_reached(); 5680633c4283SRichard Henderson } 5681633c4283SRichard Henderson } else { 5682633c4283SRichard Henderson tcg_gen_movi_tl(cpu_pc, dc->pc); 5683633c4283SRichard Henderson } 5684633c4283SRichard Henderson 5685930f1865SRichard Henderson if (dc->npc & 3) { 5686930f1865SRichard Henderson switch (dc->npc) { 5687930f1865SRichard Henderson case JUMP_PC: 5688930f1865SRichard Henderson gen_generic_branch(dc); 5689930f1865SRichard Henderson break; 5690930f1865SRichard Henderson case DYNAMIC_PC: 5691930f1865SRichard Henderson may_lookup = false; 5692930f1865SRichard Henderson break; 5693930f1865SRichard Henderson case DYNAMIC_PC_LOOKUP: 5694930f1865SRichard Henderson break; 5695930f1865SRichard Henderson default: 5696930f1865SRichard Henderson g_assert_not_reached(); 5697930f1865SRichard Henderson } 5698930f1865SRichard Henderson } else { 5699930f1865SRichard Henderson tcg_gen_movi_tl(cpu_npc, dc->npc); 5700930f1865SRichard Henderson } 5701633c4283SRichard Henderson if (may_lookup) { 5702633c4283SRichard Henderson tcg_gen_lookup_and_goto_ptr(); 5703633c4283SRichard Henderson } else { 570407ea28b4SRichard Henderson tcg_gen_exit_tb(NULL, 0); 5705fcf5ef2aSThomas Huth } 570646bb0137SMark Cave-Ayland break; 570746bb0137SMark Cave-Ayland 570846bb0137SMark Cave-Ayland case DISAS_NORETURN: 570946bb0137SMark Cave-Ayland break; 571046bb0137SMark Cave-Ayland 571146bb0137SMark Cave-Ayland case DISAS_EXIT: 571246bb0137SMark Cave-Ayland /* Exit TB */ 571346bb0137SMark Cave-Ayland save_state(dc); 571446bb0137SMark Cave-Ayland tcg_gen_exit_tb(NULL, 0); 571546bb0137SMark Cave-Ayland break; 571646bb0137SMark Cave-Ayland 571746bb0137SMark Cave-Ayland default: 571846bb0137SMark Cave-Ayland g_assert_not_reached(); 5719fcf5ef2aSThomas Huth } 5720186e7890SRichard Henderson 5721186e7890SRichard Henderson for (e = dc->delay_excp_list; e ; e = e_next) { 5722186e7890SRichard Henderson gen_set_label(e->lab); 5723186e7890SRichard Henderson 5724186e7890SRichard Henderson tcg_gen_movi_tl(cpu_pc, e->pc); 5725186e7890SRichard Henderson if (e->npc % 4 == 0) { 5726186e7890SRichard Henderson tcg_gen_movi_tl(cpu_npc, e->npc); 5727186e7890SRichard Henderson } 5728186e7890SRichard Henderson gen_helper_raise_exception(tcg_env, e->excp); 5729186e7890SRichard Henderson 5730186e7890SRichard Henderson e_next = e->next; 5731186e7890SRichard Henderson g_free(e); 5732186e7890SRichard Henderson } 5733fcf5ef2aSThomas Huth } 57346e61bc94SEmilio G. Cota 57356e61bc94SEmilio G. Cota static const TranslatorOps sparc_tr_ops = { 57366e61bc94SEmilio G. Cota .init_disas_context = sparc_tr_init_disas_context, 57376e61bc94SEmilio G. Cota .tb_start = sparc_tr_tb_start, 57386e61bc94SEmilio G. Cota .insn_start = sparc_tr_insn_start, 57396e61bc94SEmilio G. Cota .translate_insn = sparc_tr_translate_insn, 57406e61bc94SEmilio G. Cota .tb_stop = sparc_tr_tb_stop, 57416e61bc94SEmilio G. Cota }; 57426e61bc94SEmilio G. Cota 5743597f9b2dSRichard Henderson void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int *max_insns, 574432f0c394SAnton Johansson vaddr pc, void *host_pc) 57456e61bc94SEmilio G. Cota { 57466e61bc94SEmilio G. Cota DisasContext dc = {}; 57476e61bc94SEmilio G. Cota 5748306c8721SRichard Henderson translator_loop(cs, tb, max_insns, pc, host_pc, &sparc_tr_ops, &dc.base); 5749fcf5ef2aSThomas Huth } 5750fcf5ef2aSThomas Huth 575155c3ceefSRichard Henderson void sparc_tcg_init(void) 5752fcf5ef2aSThomas Huth { 5753fcf5ef2aSThomas Huth static const char gregnames[32][4] = { 5754fcf5ef2aSThomas Huth "g0", "g1", "g2", "g3", "g4", "g5", "g6", "g7", 5755fcf5ef2aSThomas Huth "o0", "o1", "o2", "o3", "o4", "o5", "o6", "o7", 5756fcf5ef2aSThomas Huth "l0", "l1", "l2", "l3", "l4", "l5", "l6", "l7", 5757fcf5ef2aSThomas Huth "i0", "i1", "i2", "i3", "i4", "i5", "i6", "i7", 5758fcf5ef2aSThomas Huth }; 5759fcf5ef2aSThomas Huth 5760d8c5b92fSRichard Henderson static const struct { TCGv_i32 *ptr; int off; const char *name; } r32[] = { 5761d8c5b92fSRichard Henderson #ifdef TARGET_SPARC64 5762d8c5b92fSRichard Henderson { &cpu_fprs, offsetof(CPUSPARCState, fprs), "fprs" }, 5763d8c5b92fSRichard Henderson { &cpu_fcc[0], offsetof(CPUSPARCState, fcc[0]), "fcc0" }, 5764d8c5b92fSRichard Henderson { &cpu_fcc[1], offsetof(CPUSPARCState, fcc[1]), "fcc1" }, 5765d8c5b92fSRichard Henderson { &cpu_fcc[2], offsetof(CPUSPARCState, fcc[2]), "fcc2" }, 5766d8c5b92fSRichard Henderson { &cpu_fcc[3], offsetof(CPUSPARCState, fcc[3]), "fcc3" }, 5767d8c5b92fSRichard Henderson #else 5768d8c5b92fSRichard Henderson { &cpu_fcc[0], offsetof(CPUSPARCState, fcc[0]), "fcc" }, 5769d8c5b92fSRichard Henderson #endif 5770d8c5b92fSRichard Henderson }; 5771d8c5b92fSRichard Henderson 5772fcf5ef2aSThomas Huth static const struct { TCGv *ptr; int off; const char *name; } rtl[] = { 5773fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64 5774fcf5ef2aSThomas Huth { &cpu_gsr, offsetof(CPUSPARCState, gsr), "gsr" }, 57752a1905c7SRichard Henderson { &cpu_xcc_Z, offsetof(CPUSPARCState, xcc_Z), "xcc_Z" }, 57762a1905c7SRichard Henderson { &cpu_xcc_C, offsetof(CPUSPARCState, xcc_C), "xcc_C" }, 5777fcf5ef2aSThomas Huth #endif 57782a1905c7SRichard Henderson { &cpu_cc_N, offsetof(CPUSPARCState, cc_N), "cc_N" }, 57792a1905c7SRichard Henderson { &cpu_cc_V, offsetof(CPUSPARCState, cc_V), "cc_V" }, 57802a1905c7SRichard Henderson { &cpu_icc_Z, offsetof(CPUSPARCState, icc_Z), "icc_Z" }, 57812a1905c7SRichard Henderson { &cpu_icc_C, offsetof(CPUSPARCState, icc_C), "icc_C" }, 5782fcf5ef2aSThomas Huth { &cpu_cond, offsetof(CPUSPARCState, cond), "cond" }, 5783fcf5ef2aSThomas Huth { &cpu_pc, offsetof(CPUSPARCState, pc), "pc" }, 5784fcf5ef2aSThomas Huth { &cpu_npc, offsetof(CPUSPARCState, npc), "npc" }, 5785fcf5ef2aSThomas Huth { &cpu_y, offsetof(CPUSPARCState, y), "y" }, 5786fcf5ef2aSThomas Huth { &cpu_tbr, offsetof(CPUSPARCState, tbr), "tbr" }, 5787fcf5ef2aSThomas Huth }; 5788fcf5ef2aSThomas Huth 5789fcf5ef2aSThomas Huth unsigned int i; 5790fcf5ef2aSThomas Huth 5791ad75a51eSRichard Henderson cpu_regwptr = tcg_global_mem_new_ptr(tcg_env, 5792fcf5ef2aSThomas Huth offsetof(CPUSPARCState, regwptr), 5793fcf5ef2aSThomas Huth "regwptr"); 5794fcf5ef2aSThomas Huth 5795d8c5b92fSRichard Henderson for (i = 0; i < ARRAY_SIZE(r32); ++i) { 5796d8c5b92fSRichard Henderson *r32[i].ptr = tcg_global_mem_new_i32(tcg_env, r32[i].off, r32[i].name); 5797d8c5b92fSRichard Henderson } 5798d8c5b92fSRichard Henderson 5799fcf5ef2aSThomas Huth for (i = 0; i < ARRAY_SIZE(rtl); ++i) { 5800ad75a51eSRichard Henderson *rtl[i].ptr = tcg_global_mem_new(tcg_env, rtl[i].off, rtl[i].name); 5801fcf5ef2aSThomas Huth } 5802fcf5ef2aSThomas Huth 5803f764718dSRichard Henderson cpu_regs[0] = NULL; 5804fcf5ef2aSThomas Huth for (i = 1; i < 8; ++i) { 5805ad75a51eSRichard Henderson cpu_regs[i] = tcg_global_mem_new(tcg_env, 5806fcf5ef2aSThomas Huth offsetof(CPUSPARCState, gregs[i]), 5807fcf5ef2aSThomas Huth gregnames[i]); 5808fcf5ef2aSThomas Huth } 5809fcf5ef2aSThomas Huth 5810fcf5ef2aSThomas Huth for (i = 8; i < 32; ++i) { 5811fcf5ef2aSThomas Huth cpu_regs[i] = tcg_global_mem_new(cpu_regwptr, 5812fcf5ef2aSThomas Huth (i - 8) * sizeof(target_ulong), 5813fcf5ef2aSThomas Huth gregnames[i]); 5814fcf5ef2aSThomas Huth } 5815fcf5ef2aSThomas Huth } 5816fcf5ef2aSThomas Huth 5817f36aaa53SRichard Henderson void sparc_restore_state_to_opc(CPUState *cs, 5818f36aaa53SRichard Henderson const TranslationBlock *tb, 5819f36aaa53SRichard Henderson const uint64_t *data) 5820fcf5ef2aSThomas Huth { 582177976769SPhilippe Mathieu-Daudé CPUSPARCState *env = cpu_env(cs); 5822fcf5ef2aSThomas Huth target_ulong pc = data[0]; 5823fcf5ef2aSThomas Huth target_ulong npc = data[1]; 5824fcf5ef2aSThomas Huth 5825fcf5ef2aSThomas Huth env->pc = pc; 5826fcf5ef2aSThomas Huth if (npc == DYNAMIC_PC) { 5827fcf5ef2aSThomas Huth /* dynamic NPC: already stored */ 5828fcf5ef2aSThomas Huth } else if (npc & JUMP_PC) { 5829fcf5ef2aSThomas Huth /* jump PC: use 'cond' and the jump targets of the translation */ 5830fcf5ef2aSThomas Huth if (env->cond) { 5831fcf5ef2aSThomas Huth env->npc = npc & ~3; 5832fcf5ef2aSThomas Huth } else { 5833fcf5ef2aSThomas Huth env->npc = pc + 4; 5834fcf5ef2aSThomas Huth } 5835fcf5ef2aSThomas Huth } else { 5836fcf5ef2aSThomas Huth env->npc = npc; 5837fcf5ef2aSThomas Huth } 5838fcf5ef2aSThomas Huth } 5839