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; }) 70*b3c934ddSRichard 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; }) 73*b3c934ddSRichard 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; }) 80*b3c934ddSRichard Henderson # define gen_helper_fcmpule16 ({ qemu_build_not_reached(); NULL; }) 81*b3c934ddSRichard Henderson # define gen_helper_fcmpule32 ({ qemu_build_not_reached(); NULL; }) 82669e0774SRichard Henderson # define gen_helper_fcmpugt8 ({ qemu_build_not_reached(); NULL; }) 83*b3c934ddSRichard Henderson # define gen_helper_fcmpugt16 ({ qemu_build_not_reached(); NULL; }) 84*b3c934ddSRichard 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 5180c2e96c1SRichard Henderson static void gen_op_mulscc(TCGv dst, TCGv src1, TCGv src2) 519fcf5ef2aSThomas Huth { 520b989ce73SRichard Henderson TCGv zero = tcg_constant_tl(0); 52150280618SRichard Henderson TCGv one = tcg_constant_tl(1); 522b989ce73SRichard Henderson TCGv t_src1 = tcg_temp_new(); 523b989ce73SRichard Henderson TCGv t_src2 = tcg_temp_new(); 524b989ce73SRichard Henderson TCGv t0 = tcg_temp_new(); 525fcf5ef2aSThomas Huth 526b989ce73SRichard Henderson tcg_gen_ext32u_tl(t_src1, src1); 527b989ce73SRichard Henderson tcg_gen_ext32u_tl(t_src2, src2); 528fcf5ef2aSThomas Huth 529b989ce73SRichard Henderson /* 530b989ce73SRichard Henderson * if (!(env->y & 1)) 531b989ce73SRichard Henderson * src2 = 0; 532fcf5ef2aSThomas Huth */ 53350280618SRichard Henderson tcg_gen_movcond_tl(TCG_COND_TSTEQ, t_src2, cpu_y, one, zero, t_src2); 534fcf5ef2aSThomas Huth 535b989ce73SRichard Henderson /* 536b989ce73SRichard Henderson * b2 = src1 & 1; 537b989ce73SRichard Henderson * y = (b2 << 31) | (y >> 1); 538b989ce73SRichard Henderson */ 5390b1183e3SPhilippe Mathieu-Daudé tcg_gen_extract_tl(t0, cpu_y, 1, 31); 540b989ce73SRichard Henderson tcg_gen_deposit_tl(cpu_y, t0, src1, 31, 1); 541fcf5ef2aSThomas Huth 542fcf5ef2aSThomas Huth // b1 = N ^ V; 5432a1905c7SRichard Henderson tcg_gen_xor_tl(t0, cpu_cc_N, cpu_cc_V); 544fcf5ef2aSThomas Huth 545b989ce73SRichard Henderson /* 546b989ce73SRichard Henderson * src1 = (b1 << 31) | (src1 >> 1) 547b989ce73SRichard Henderson */ 5482a1905c7SRichard Henderson tcg_gen_andi_tl(t0, t0, 1u << 31); 549b989ce73SRichard Henderson tcg_gen_shri_tl(t_src1, t_src1, 1); 550b989ce73SRichard Henderson tcg_gen_or_tl(t_src1, t_src1, t0); 551fcf5ef2aSThomas Huth 552b989ce73SRichard Henderson gen_op_addcc(dst, t_src1, t_src2); 553fcf5ef2aSThomas Huth } 554fcf5ef2aSThomas Huth 5550c2e96c1SRichard Henderson static void gen_op_multiply(TCGv dst, TCGv src1, TCGv src2, int sign_ext) 556fcf5ef2aSThomas Huth { 557fcf5ef2aSThomas Huth #if TARGET_LONG_BITS == 32 558fcf5ef2aSThomas Huth if (sign_ext) { 559fcf5ef2aSThomas Huth tcg_gen_muls2_tl(dst, cpu_y, src1, src2); 560fcf5ef2aSThomas Huth } else { 561fcf5ef2aSThomas Huth tcg_gen_mulu2_tl(dst, cpu_y, src1, src2); 562fcf5ef2aSThomas Huth } 563fcf5ef2aSThomas Huth #else 564fcf5ef2aSThomas Huth TCGv t0 = tcg_temp_new_i64(); 565fcf5ef2aSThomas Huth TCGv t1 = tcg_temp_new_i64(); 566fcf5ef2aSThomas Huth 567fcf5ef2aSThomas Huth if (sign_ext) { 568fcf5ef2aSThomas Huth tcg_gen_ext32s_i64(t0, src1); 569fcf5ef2aSThomas Huth tcg_gen_ext32s_i64(t1, src2); 570fcf5ef2aSThomas Huth } else { 571fcf5ef2aSThomas Huth tcg_gen_ext32u_i64(t0, src1); 572fcf5ef2aSThomas Huth tcg_gen_ext32u_i64(t1, src2); 573fcf5ef2aSThomas Huth } 574fcf5ef2aSThomas Huth 575fcf5ef2aSThomas Huth tcg_gen_mul_i64(dst, t0, t1); 576fcf5ef2aSThomas Huth tcg_gen_shri_i64(cpu_y, dst, 32); 577fcf5ef2aSThomas Huth #endif 578fcf5ef2aSThomas Huth } 579fcf5ef2aSThomas Huth 5800c2e96c1SRichard Henderson static void gen_op_umul(TCGv dst, TCGv src1, TCGv src2) 581fcf5ef2aSThomas Huth { 582fcf5ef2aSThomas Huth /* zero-extend truncated operands before multiplication */ 583fcf5ef2aSThomas Huth gen_op_multiply(dst, src1, src2, 0); 584fcf5ef2aSThomas Huth } 585fcf5ef2aSThomas Huth 5860c2e96c1SRichard Henderson static void gen_op_smul(TCGv dst, TCGv src1, TCGv src2) 587fcf5ef2aSThomas Huth { 588fcf5ef2aSThomas Huth /* sign-extend truncated operands before multiplication */ 589fcf5ef2aSThomas Huth gen_op_multiply(dst, src1, src2, 1); 590fcf5ef2aSThomas Huth } 591fcf5ef2aSThomas Huth 592680af1b4SRichard Henderson static void gen_op_umulxhi(TCGv dst, TCGv src1, TCGv src2) 593680af1b4SRichard Henderson { 594680af1b4SRichard Henderson TCGv discard = tcg_temp_new(); 595680af1b4SRichard Henderson tcg_gen_mulu2_tl(discard, dst, src1, src2); 596680af1b4SRichard Henderson } 597680af1b4SRichard Henderson 59868a414e9SRichard Henderson static void gen_op_fpmaddx(TCGv_i64 dst, TCGv_i64 src1, 59968a414e9SRichard Henderson TCGv_i64 src2, TCGv_i64 src3) 60068a414e9SRichard Henderson { 60168a414e9SRichard Henderson TCGv_i64 t = tcg_temp_new_i64(); 60268a414e9SRichard Henderson 60368a414e9SRichard Henderson tcg_gen_mul_i64(t, src1, src2); 60468a414e9SRichard Henderson tcg_gen_add_i64(dst, src3, t); 60568a414e9SRichard Henderson } 60668a414e9SRichard Henderson 60768a414e9SRichard Henderson static void gen_op_fpmaddxhi(TCGv_i64 dst, TCGv_i64 src1, 60868a414e9SRichard Henderson TCGv_i64 src2, TCGv_i64 src3) 60968a414e9SRichard Henderson { 61068a414e9SRichard Henderson TCGv_i64 l = tcg_temp_new_i64(); 61168a414e9SRichard Henderson TCGv_i64 h = tcg_temp_new_i64(); 61268a414e9SRichard Henderson TCGv_i64 z = tcg_constant_i64(0); 61368a414e9SRichard Henderson 61468a414e9SRichard Henderson tcg_gen_mulu2_i64(l, h, src1, src2); 61568a414e9SRichard Henderson tcg_gen_add2_i64(l, dst, l, h, src3, z); 61668a414e9SRichard Henderson } 61768a414e9SRichard Henderson 618c2636853SRichard Henderson static void gen_op_sdiv(TCGv dst, TCGv src1, TCGv src2) 619c2636853SRichard Henderson { 62013260103SRichard Henderson #ifdef TARGET_SPARC64 621c2636853SRichard Henderson gen_helper_sdiv(dst, tcg_env, src1, src2); 62213260103SRichard Henderson tcg_gen_ext32s_tl(dst, dst); 62313260103SRichard Henderson #else 62413260103SRichard Henderson TCGv_i64 t64 = tcg_temp_new_i64(); 62513260103SRichard Henderson gen_helper_sdiv(t64, tcg_env, src1, src2); 62613260103SRichard Henderson tcg_gen_trunc_i64_tl(dst, t64); 62713260103SRichard Henderson #endif 628c2636853SRichard Henderson } 629c2636853SRichard Henderson 630c2636853SRichard Henderson static void gen_op_udivcc(TCGv dst, TCGv src1, TCGv src2) 631c2636853SRichard Henderson { 63213260103SRichard Henderson TCGv_i64 t64; 63313260103SRichard Henderson 63413260103SRichard Henderson #ifdef TARGET_SPARC64 63513260103SRichard Henderson t64 = cpu_cc_V; 63613260103SRichard Henderson #else 63713260103SRichard Henderson t64 = tcg_temp_new_i64(); 63813260103SRichard Henderson #endif 63913260103SRichard Henderson 64013260103SRichard Henderson gen_helper_udiv(t64, tcg_env, src1, src2); 64113260103SRichard Henderson 64213260103SRichard Henderson #ifdef TARGET_SPARC64 64313260103SRichard Henderson tcg_gen_ext32u_tl(cpu_cc_N, t64); 64413260103SRichard Henderson tcg_gen_shri_tl(cpu_cc_V, t64, 32); 64513260103SRichard Henderson tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N); 64613260103SRichard Henderson tcg_gen_movi_tl(cpu_icc_C, 0); 64713260103SRichard Henderson #else 64813260103SRichard Henderson tcg_gen_extr_i64_tl(cpu_cc_N, cpu_cc_V, t64); 64913260103SRichard Henderson #endif 65013260103SRichard Henderson tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N); 65113260103SRichard Henderson tcg_gen_movi_tl(cpu_cc_C, 0); 65213260103SRichard Henderson tcg_gen_mov_tl(dst, cpu_cc_N); 653c2636853SRichard Henderson } 654c2636853SRichard Henderson 655c2636853SRichard Henderson static void gen_op_sdivcc(TCGv dst, TCGv src1, TCGv src2) 656c2636853SRichard Henderson { 65713260103SRichard Henderson TCGv_i64 t64; 65813260103SRichard Henderson 65913260103SRichard Henderson #ifdef TARGET_SPARC64 66013260103SRichard Henderson t64 = cpu_cc_V; 66113260103SRichard Henderson #else 66213260103SRichard Henderson t64 = tcg_temp_new_i64(); 66313260103SRichard Henderson #endif 66413260103SRichard Henderson 66513260103SRichard Henderson gen_helper_sdiv(t64, tcg_env, src1, src2); 66613260103SRichard Henderson 66713260103SRichard Henderson #ifdef TARGET_SPARC64 66813260103SRichard Henderson tcg_gen_ext32s_tl(cpu_cc_N, t64); 66913260103SRichard Henderson tcg_gen_shri_tl(cpu_cc_V, t64, 32); 67013260103SRichard Henderson tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N); 67113260103SRichard Henderson tcg_gen_movi_tl(cpu_icc_C, 0); 67213260103SRichard Henderson #else 67313260103SRichard Henderson tcg_gen_extr_i64_tl(cpu_cc_N, cpu_cc_V, t64); 67413260103SRichard Henderson #endif 67513260103SRichard Henderson tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N); 67613260103SRichard Henderson tcg_gen_movi_tl(cpu_cc_C, 0); 67713260103SRichard Henderson tcg_gen_mov_tl(dst, cpu_cc_N); 678c2636853SRichard Henderson } 679c2636853SRichard Henderson 680a9aba13dSRichard Henderson static void gen_op_taddcctv(TCGv dst, TCGv src1, TCGv src2) 681a9aba13dSRichard Henderson { 682a9aba13dSRichard Henderson gen_helper_taddcctv(dst, tcg_env, src1, src2); 683a9aba13dSRichard Henderson } 684a9aba13dSRichard Henderson 685a9aba13dSRichard Henderson static void gen_op_tsubcctv(TCGv dst, TCGv src1, TCGv src2) 686a9aba13dSRichard Henderson { 687a9aba13dSRichard Henderson gen_helper_tsubcctv(dst, tcg_env, src1, src2); 688a9aba13dSRichard Henderson } 689a9aba13dSRichard Henderson 6909c6ec5bcSRichard Henderson static void gen_op_popc(TCGv dst, TCGv src1, TCGv src2) 6919c6ec5bcSRichard Henderson { 6929c6ec5bcSRichard Henderson tcg_gen_ctpop_tl(dst, src2); 6939c6ec5bcSRichard Henderson } 6949c6ec5bcSRichard Henderson 695875ce392SRichard Henderson static void gen_op_lzcnt(TCGv dst, TCGv src) 696875ce392SRichard Henderson { 697875ce392SRichard Henderson tcg_gen_clzi_tl(dst, src, TARGET_LONG_BITS); 698875ce392SRichard Henderson } 699875ce392SRichard Henderson 70045bfed3bSRichard Henderson #ifndef TARGET_SPARC64 70145bfed3bSRichard Henderson static void gen_helper_array8(TCGv dst, TCGv src1, TCGv src2) 70245bfed3bSRichard Henderson { 70345bfed3bSRichard Henderson g_assert_not_reached(); 70445bfed3bSRichard Henderson } 70545bfed3bSRichard Henderson #endif 70645bfed3bSRichard Henderson 70745bfed3bSRichard Henderson static void gen_op_array16(TCGv dst, TCGv src1, TCGv src2) 70845bfed3bSRichard Henderson { 70945bfed3bSRichard Henderson gen_helper_array8(dst, src1, src2); 71045bfed3bSRichard Henderson tcg_gen_shli_tl(dst, dst, 1); 71145bfed3bSRichard Henderson } 71245bfed3bSRichard Henderson 71345bfed3bSRichard Henderson static void gen_op_array32(TCGv dst, TCGv src1, TCGv src2) 71445bfed3bSRichard Henderson { 71545bfed3bSRichard Henderson gen_helper_array8(dst, src1, src2); 71645bfed3bSRichard Henderson tcg_gen_shli_tl(dst, dst, 2); 71745bfed3bSRichard Henderson } 71845bfed3bSRichard Henderson 7192f722641SRichard Henderson static void gen_op_fpack16(TCGv_i32 dst, TCGv_i64 src) 7202f722641SRichard Henderson { 7212f722641SRichard Henderson #ifdef TARGET_SPARC64 7222f722641SRichard Henderson gen_helper_fpack16(dst, cpu_gsr, src); 7232f722641SRichard Henderson #else 7242f722641SRichard Henderson g_assert_not_reached(); 7252f722641SRichard Henderson #endif 7262f722641SRichard Henderson } 7272f722641SRichard Henderson 7282f722641SRichard Henderson static void gen_op_fpackfix(TCGv_i32 dst, TCGv_i64 src) 7292f722641SRichard Henderson { 7302f722641SRichard Henderson #ifdef TARGET_SPARC64 7312f722641SRichard Henderson gen_helper_fpackfix(dst, cpu_gsr, src); 7322f722641SRichard Henderson #else 7332f722641SRichard Henderson g_assert_not_reached(); 7342f722641SRichard Henderson #endif 7352f722641SRichard Henderson } 7362f722641SRichard Henderson 7374b6edc0aSRichard Henderson static void gen_op_fpack32(TCGv_i64 dst, TCGv_i64 src1, TCGv_i64 src2) 7384b6edc0aSRichard Henderson { 7394b6edc0aSRichard Henderson #ifdef TARGET_SPARC64 7404b6edc0aSRichard Henderson gen_helper_fpack32(dst, cpu_gsr, src1, src2); 7414b6edc0aSRichard Henderson #else 7424b6edc0aSRichard Henderson g_assert_not_reached(); 7434b6edc0aSRichard Henderson #endif 7444b6edc0aSRichard Henderson } 7454b6edc0aSRichard Henderson 7460d1d3aafSRichard Henderson static void gen_op_fpadds16s(TCGv_i32 d, TCGv_i32 src1, TCGv_i32 src2) 7470d1d3aafSRichard Henderson { 7480d1d3aafSRichard Henderson TCGv_i32 t[2]; 7490d1d3aafSRichard Henderson 7500d1d3aafSRichard Henderson for (int i = 0; i < 2; i++) { 7510d1d3aafSRichard Henderson TCGv_i32 u = tcg_temp_new_i32(); 7520d1d3aafSRichard Henderson TCGv_i32 v = tcg_temp_new_i32(); 7530d1d3aafSRichard Henderson 7540d1d3aafSRichard Henderson tcg_gen_sextract_i32(u, src1, i * 16, 16); 7550d1d3aafSRichard Henderson tcg_gen_sextract_i32(v, src2, i * 16, 16); 7560d1d3aafSRichard Henderson tcg_gen_add_i32(u, u, v); 7570d1d3aafSRichard Henderson tcg_gen_smax_i32(u, u, tcg_constant_i32(INT16_MIN)); 7580d1d3aafSRichard Henderson tcg_gen_smin_i32(u, u, tcg_constant_i32(INT16_MAX)); 7590d1d3aafSRichard Henderson t[i] = u; 7600d1d3aafSRichard Henderson } 7610d1d3aafSRichard Henderson tcg_gen_deposit_i32(d, t[0], t[1], 16, 16); 7620d1d3aafSRichard Henderson } 7630d1d3aafSRichard Henderson 7640d1d3aafSRichard Henderson static void gen_op_fpsubs16s(TCGv_i32 d, TCGv_i32 src1, TCGv_i32 src2) 7650d1d3aafSRichard Henderson { 7660d1d3aafSRichard Henderson TCGv_i32 t[2]; 7670d1d3aafSRichard Henderson 7680d1d3aafSRichard Henderson for (int i = 0; i < 2; i++) { 7690d1d3aafSRichard Henderson TCGv_i32 u = tcg_temp_new_i32(); 7700d1d3aafSRichard Henderson TCGv_i32 v = tcg_temp_new_i32(); 7710d1d3aafSRichard Henderson 7720d1d3aafSRichard Henderson tcg_gen_sextract_i32(u, src1, i * 16, 16); 7730d1d3aafSRichard Henderson tcg_gen_sextract_i32(v, src2, i * 16, 16); 7740d1d3aafSRichard Henderson tcg_gen_sub_i32(u, u, v); 7750d1d3aafSRichard Henderson tcg_gen_smax_i32(u, u, tcg_constant_i32(INT16_MIN)); 7760d1d3aafSRichard Henderson tcg_gen_smin_i32(u, u, tcg_constant_i32(INT16_MAX)); 7770d1d3aafSRichard Henderson t[i] = u; 7780d1d3aafSRichard Henderson } 7790d1d3aafSRichard Henderson tcg_gen_deposit_i32(d, t[0], t[1], 16, 16); 7800d1d3aafSRichard Henderson } 7810d1d3aafSRichard Henderson 7820d1d3aafSRichard Henderson static void gen_op_fpadds32s(TCGv_i32 d, TCGv_i32 src1, TCGv_i32 src2) 7830d1d3aafSRichard Henderson { 7840d1d3aafSRichard Henderson TCGv_i32 r = tcg_temp_new_i32(); 7850d1d3aafSRichard Henderson TCGv_i32 t = tcg_temp_new_i32(); 7860d1d3aafSRichard Henderson TCGv_i32 v = tcg_temp_new_i32(); 7870d1d3aafSRichard Henderson TCGv_i32 z = tcg_constant_i32(0); 7880d1d3aafSRichard Henderson 7890d1d3aafSRichard Henderson tcg_gen_add_i32(r, src1, src2); 7900d1d3aafSRichard Henderson tcg_gen_xor_i32(t, src1, src2); 7910d1d3aafSRichard Henderson tcg_gen_xor_i32(v, r, src2); 7920d1d3aafSRichard Henderson tcg_gen_andc_i32(v, v, t); 7930d1d3aafSRichard Henderson 7940d1d3aafSRichard Henderson tcg_gen_setcond_i32(TCG_COND_GE, t, r, z); 7950d1d3aafSRichard Henderson tcg_gen_addi_i32(t, t, INT32_MAX); 7960d1d3aafSRichard Henderson 7970d1d3aafSRichard Henderson tcg_gen_movcond_i32(TCG_COND_LT, d, v, z, t, r); 7980d1d3aafSRichard Henderson } 7990d1d3aafSRichard Henderson 8000d1d3aafSRichard Henderson static void gen_op_fpsubs32s(TCGv_i32 d, TCGv_i32 src1, TCGv_i32 src2) 8010d1d3aafSRichard Henderson { 8020d1d3aafSRichard Henderson TCGv_i32 r = tcg_temp_new_i32(); 8030d1d3aafSRichard Henderson TCGv_i32 t = tcg_temp_new_i32(); 8040d1d3aafSRichard Henderson TCGv_i32 v = tcg_temp_new_i32(); 8050d1d3aafSRichard Henderson TCGv_i32 z = tcg_constant_i32(0); 8060d1d3aafSRichard Henderson 8070d1d3aafSRichard Henderson tcg_gen_sub_i32(r, src1, src2); 8080d1d3aafSRichard Henderson tcg_gen_xor_i32(t, src1, src2); 8090d1d3aafSRichard Henderson tcg_gen_xor_i32(v, r, src1); 8100d1d3aafSRichard Henderson tcg_gen_and_i32(v, v, t); 8110d1d3aafSRichard Henderson 8120d1d3aafSRichard Henderson tcg_gen_setcond_i32(TCG_COND_GE, t, r, z); 8130d1d3aafSRichard Henderson tcg_gen_addi_i32(t, t, INT32_MAX); 8140d1d3aafSRichard Henderson 8150d1d3aafSRichard Henderson tcg_gen_movcond_i32(TCG_COND_LT, d, v, z, t, r); 8160d1d3aafSRichard Henderson } 8170d1d3aafSRichard Henderson 818b2b48493SRichard Henderson static void gen_op_faligndata_i(TCGv_i64 dst, TCGv_i64 s1, 819b2b48493SRichard Henderson TCGv_i64 s2, TCGv gsr) 8204b6edc0aSRichard Henderson { 8214b6edc0aSRichard Henderson #ifdef TARGET_SPARC64 8224b6edc0aSRichard Henderson TCGv t1, t2, shift; 8234b6edc0aSRichard Henderson 8244b6edc0aSRichard Henderson t1 = tcg_temp_new(); 8254b6edc0aSRichard Henderson t2 = tcg_temp_new(); 8264b6edc0aSRichard Henderson shift = tcg_temp_new(); 8274b6edc0aSRichard Henderson 828b2b48493SRichard Henderson tcg_gen_andi_tl(shift, gsr, 7); 8294b6edc0aSRichard Henderson tcg_gen_shli_tl(shift, shift, 3); 8304b6edc0aSRichard Henderson tcg_gen_shl_tl(t1, s1, shift); 8314b6edc0aSRichard Henderson 8324b6edc0aSRichard Henderson /* 8334b6edc0aSRichard Henderson * A shift of 64 does not produce 0 in TCG. Divide this into a 8344b6edc0aSRichard Henderson * shift of (up to 63) followed by a constant shift of 1. 8354b6edc0aSRichard Henderson */ 8364b6edc0aSRichard Henderson tcg_gen_xori_tl(shift, shift, 63); 8374b6edc0aSRichard Henderson tcg_gen_shr_tl(t2, s2, shift); 8384b6edc0aSRichard Henderson tcg_gen_shri_tl(t2, t2, 1); 8394b6edc0aSRichard Henderson 8404b6edc0aSRichard Henderson tcg_gen_or_tl(dst, t1, t2); 8414b6edc0aSRichard Henderson #else 8424b6edc0aSRichard Henderson g_assert_not_reached(); 8434b6edc0aSRichard Henderson #endif 8444b6edc0aSRichard Henderson } 8454b6edc0aSRichard Henderson 846b2b48493SRichard Henderson static void gen_op_faligndata_g(TCGv_i64 dst, TCGv_i64 s1, TCGv_i64 s2) 847b2b48493SRichard Henderson { 848b2b48493SRichard Henderson gen_op_faligndata_i(dst, s1, s2, cpu_gsr); 849b2b48493SRichard Henderson } 850b2b48493SRichard Henderson 8514b6edc0aSRichard Henderson static void gen_op_bshuffle(TCGv_i64 dst, TCGv_i64 src1, TCGv_i64 src2) 8524b6edc0aSRichard Henderson { 8534b6edc0aSRichard Henderson #ifdef TARGET_SPARC64 8544b6edc0aSRichard Henderson gen_helper_bshuffle(dst, cpu_gsr, src1, src2); 8554b6edc0aSRichard Henderson #else 8564b6edc0aSRichard Henderson g_assert_not_reached(); 8574b6edc0aSRichard Henderson #endif 8584b6edc0aSRichard Henderson } 8594b6edc0aSRichard Henderson 8607d5ebd8fSRichard Henderson static void gen_op_pdistn(TCGv dst, TCGv_i64 src1, TCGv_i64 src2) 8617d5ebd8fSRichard Henderson { 8627d5ebd8fSRichard Henderson #ifdef TARGET_SPARC64 8637d5ebd8fSRichard Henderson gen_helper_pdist(dst, tcg_constant_i64(0), src1, src2); 8647d5ebd8fSRichard Henderson #else 8657d5ebd8fSRichard Henderson g_assert_not_reached(); 8667d5ebd8fSRichard Henderson #endif 8677d5ebd8fSRichard Henderson } 8687d5ebd8fSRichard Henderson 869a859602cSRichard Henderson static void gen_op_fmul8x16al(TCGv_i64 dst, TCGv_i32 src1, TCGv_i32 src2) 870a859602cSRichard Henderson { 871a859602cSRichard Henderson tcg_gen_ext16s_i32(src2, src2); 872a859602cSRichard Henderson gen_helper_fmul8x16a(dst, src1, src2); 873a859602cSRichard Henderson } 874a859602cSRichard Henderson 875a859602cSRichard Henderson static void gen_op_fmul8x16au(TCGv_i64 dst, TCGv_i32 src1, TCGv_i32 src2) 876a859602cSRichard Henderson { 877a859602cSRichard Henderson tcg_gen_sari_i32(src2, src2, 16); 878a859602cSRichard Henderson gen_helper_fmul8x16a(dst, src1, src2); 879a859602cSRichard Henderson } 880a859602cSRichard Henderson 881be8998e0SRichard Henderson static void gen_op_fmuld8ulx16(TCGv_i64 dst, TCGv_i32 src1, TCGv_i32 src2) 882be8998e0SRichard Henderson { 883be8998e0SRichard Henderson TCGv_i32 t0 = tcg_temp_new_i32(); 884be8998e0SRichard Henderson TCGv_i32 t1 = tcg_temp_new_i32(); 885be8998e0SRichard Henderson TCGv_i32 t2 = tcg_temp_new_i32(); 886be8998e0SRichard Henderson 887be8998e0SRichard Henderson tcg_gen_ext8u_i32(t0, src1); 888be8998e0SRichard Henderson tcg_gen_ext16s_i32(t1, src2); 889be8998e0SRichard Henderson tcg_gen_mul_i32(t0, t0, t1); 890be8998e0SRichard Henderson 891be8998e0SRichard Henderson tcg_gen_extract_i32(t1, src1, 16, 8); 892be8998e0SRichard Henderson tcg_gen_sextract_i32(t2, src2, 16, 16); 893be8998e0SRichard Henderson tcg_gen_mul_i32(t1, t1, t2); 894be8998e0SRichard Henderson 895be8998e0SRichard Henderson tcg_gen_concat_i32_i64(dst, t0, t1); 896be8998e0SRichard Henderson } 897be8998e0SRichard Henderson 898be8998e0SRichard Henderson static void gen_op_fmuld8sux16(TCGv_i64 dst, TCGv_i32 src1, TCGv_i32 src2) 899be8998e0SRichard Henderson { 900be8998e0SRichard Henderson TCGv_i32 t0 = tcg_temp_new_i32(); 901be8998e0SRichard Henderson TCGv_i32 t1 = tcg_temp_new_i32(); 902be8998e0SRichard Henderson TCGv_i32 t2 = tcg_temp_new_i32(); 903be8998e0SRichard Henderson 904be8998e0SRichard Henderson /* 905be8998e0SRichard Henderson * The insn description talks about extracting the upper 8 bits 906be8998e0SRichard Henderson * of the signed 16-bit input rs1, performing the multiply, then 907be8998e0SRichard Henderson * shifting left by 8 bits. Instead, zap the lower 8 bits of 908be8998e0SRichard Henderson * the rs1 input, which avoids the need for two shifts. 909be8998e0SRichard Henderson */ 910be8998e0SRichard Henderson tcg_gen_ext16s_i32(t0, src1); 911be8998e0SRichard Henderson tcg_gen_andi_i32(t0, t0, ~0xff); 912be8998e0SRichard Henderson tcg_gen_ext16s_i32(t1, src2); 913be8998e0SRichard Henderson tcg_gen_mul_i32(t0, t0, t1); 914be8998e0SRichard Henderson 915be8998e0SRichard Henderson tcg_gen_sextract_i32(t1, src1, 16, 16); 916be8998e0SRichard Henderson tcg_gen_andi_i32(t1, t1, ~0xff); 917be8998e0SRichard Henderson tcg_gen_sextract_i32(t2, src2, 16, 16); 918be8998e0SRichard Henderson tcg_gen_mul_i32(t1, t1, t2); 919be8998e0SRichard Henderson 920be8998e0SRichard Henderson tcg_gen_concat_i32_i64(dst, t0, t1); 921be8998e0SRichard Henderson } 922be8998e0SRichard Henderson 9237837185eSRichard Henderson #ifdef TARGET_SPARC64 9247837185eSRichard Henderson static void gen_vec_fchksm16(unsigned vece, TCGv_vec dst, 9257837185eSRichard Henderson TCGv_vec src1, TCGv_vec src2) 9267837185eSRichard Henderson { 9277837185eSRichard Henderson TCGv_vec a = tcg_temp_new_vec_matching(dst); 9287837185eSRichard Henderson TCGv_vec c = tcg_temp_new_vec_matching(dst); 9297837185eSRichard Henderson 9307837185eSRichard Henderson tcg_gen_add_vec(vece, a, src1, src2); 9317837185eSRichard Henderson tcg_gen_cmp_vec(TCG_COND_LTU, vece, c, a, src1); 9327837185eSRichard Henderson /* Vector cmp produces -1 for true, so subtract to add carry. */ 9337837185eSRichard Henderson tcg_gen_sub_vec(vece, dst, a, c); 9347837185eSRichard Henderson } 9357837185eSRichard Henderson 9367837185eSRichard Henderson static void gen_op_fchksm16(unsigned vece, uint32_t dofs, uint32_t aofs, 9377837185eSRichard Henderson uint32_t bofs, uint32_t oprsz, uint32_t maxsz) 9387837185eSRichard Henderson { 9397837185eSRichard Henderson static const TCGOpcode vecop_list[] = { 9407837185eSRichard Henderson INDEX_op_cmp_vec, INDEX_op_add_vec, INDEX_op_sub_vec, 9417837185eSRichard Henderson }; 9427837185eSRichard Henderson static const GVecGen3 op = { 9437837185eSRichard Henderson .fni8 = gen_helper_fchksm16, 9447837185eSRichard Henderson .fniv = gen_vec_fchksm16, 9457837185eSRichard Henderson .opt_opc = vecop_list, 9467837185eSRichard Henderson .vece = MO_16, 9477837185eSRichard Henderson }; 9487837185eSRichard Henderson tcg_gen_gvec_3(dofs, aofs, bofs, oprsz, maxsz, &op); 9497837185eSRichard Henderson } 950d6ff1ccbSRichard Henderson 951d6ff1ccbSRichard Henderson static void gen_vec_fmean16(unsigned vece, TCGv_vec dst, 952d6ff1ccbSRichard Henderson TCGv_vec src1, TCGv_vec src2) 953d6ff1ccbSRichard Henderson { 954d6ff1ccbSRichard Henderson TCGv_vec t = tcg_temp_new_vec_matching(dst); 955d6ff1ccbSRichard Henderson 956d6ff1ccbSRichard Henderson tcg_gen_or_vec(vece, t, src1, src2); 957d6ff1ccbSRichard Henderson tcg_gen_and_vec(vece, t, t, tcg_constant_vec_matching(dst, vece, 1)); 958d6ff1ccbSRichard Henderson tcg_gen_sari_vec(vece, src1, src1, 1); 959d6ff1ccbSRichard Henderson tcg_gen_sari_vec(vece, src2, src2, 1); 960d6ff1ccbSRichard Henderson tcg_gen_add_vec(vece, dst, src1, src2); 961d6ff1ccbSRichard Henderson tcg_gen_add_vec(vece, dst, dst, t); 962d6ff1ccbSRichard Henderson } 963d6ff1ccbSRichard Henderson 964d6ff1ccbSRichard Henderson static void gen_op_fmean16(unsigned vece, uint32_t dofs, uint32_t aofs, 965d6ff1ccbSRichard Henderson uint32_t bofs, uint32_t oprsz, uint32_t maxsz) 966d6ff1ccbSRichard Henderson { 967d6ff1ccbSRichard Henderson static const TCGOpcode vecop_list[] = { 968d6ff1ccbSRichard Henderson INDEX_op_add_vec, INDEX_op_sari_vec, 969d6ff1ccbSRichard Henderson }; 970d6ff1ccbSRichard Henderson static const GVecGen3 op = { 971d6ff1ccbSRichard Henderson .fni8 = gen_helper_fmean16, 972d6ff1ccbSRichard Henderson .fniv = gen_vec_fmean16, 973d6ff1ccbSRichard Henderson .opt_opc = vecop_list, 974d6ff1ccbSRichard Henderson .vece = MO_16, 975d6ff1ccbSRichard Henderson }; 976d6ff1ccbSRichard Henderson tcg_gen_gvec_3(dofs, aofs, bofs, oprsz, maxsz, &op); 977d6ff1ccbSRichard Henderson } 9787837185eSRichard Henderson #else 9797837185eSRichard Henderson #define gen_op_fchksm16 ({ qemu_build_not_reached(); NULL; }) 980d6ff1ccbSRichard Henderson #define gen_op_fmean16 ({ qemu_build_not_reached(); NULL; }) 9817837185eSRichard Henderson #endif 9827837185eSRichard Henderson 98389527e3aSRichard Henderson static void finishing_insn(DisasContext *dc) 98489527e3aSRichard Henderson { 98589527e3aSRichard Henderson /* 98689527e3aSRichard Henderson * From here, there is no future path through an unwinding exception. 98789527e3aSRichard Henderson * If the current insn cannot raise an exception, the computation of 98889527e3aSRichard Henderson * cpu_cond may be able to be elided. 98989527e3aSRichard Henderson */ 99089527e3aSRichard Henderson if (dc->cpu_cond_live) { 99189527e3aSRichard Henderson tcg_gen_discard_tl(cpu_cond); 99289527e3aSRichard Henderson dc->cpu_cond_live = false; 99389527e3aSRichard Henderson } 99489527e3aSRichard Henderson } 99589527e3aSRichard Henderson 9960c2e96c1SRichard Henderson static void gen_generic_branch(DisasContext *dc) 997fcf5ef2aSThomas Huth { 99800ab7e61SRichard Henderson TCGv npc0 = tcg_constant_tl(dc->jump_pc[0]); 99900ab7e61SRichard Henderson TCGv npc1 = tcg_constant_tl(dc->jump_pc[1]); 1000533f042fSRichard Henderson TCGv c2 = tcg_constant_tl(dc->jump.c2); 1001fcf5ef2aSThomas Huth 1002533f042fSRichard Henderson tcg_gen_movcond_tl(dc->jump.cond, cpu_npc, dc->jump.c1, c2, npc0, npc1); 1003fcf5ef2aSThomas Huth } 1004fcf5ef2aSThomas Huth 1005fcf5ef2aSThomas Huth /* call this function before using the condition register as it may 1006fcf5ef2aSThomas Huth have been set for a jump */ 10070c2e96c1SRichard Henderson static void flush_cond(DisasContext *dc) 1008fcf5ef2aSThomas Huth { 1009fcf5ef2aSThomas Huth if (dc->npc == JUMP_PC) { 1010fcf5ef2aSThomas Huth gen_generic_branch(dc); 101199c82c47SRichard Henderson dc->npc = DYNAMIC_PC_LOOKUP; 1012fcf5ef2aSThomas Huth } 1013fcf5ef2aSThomas Huth } 1014fcf5ef2aSThomas Huth 10150c2e96c1SRichard Henderson static void save_npc(DisasContext *dc) 1016fcf5ef2aSThomas Huth { 1017633c4283SRichard Henderson if (dc->npc & 3) { 1018633c4283SRichard Henderson switch (dc->npc) { 1019633c4283SRichard Henderson case JUMP_PC: 1020fcf5ef2aSThomas Huth gen_generic_branch(dc); 102199c82c47SRichard Henderson dc->npc = DYNAMIC_PC_LOOKUP; 1022633c4283SRichard Henderson break; 1023633c4283SRichard Henderson case DYNAMIC_PC: 1024633c4283SRichard Henderson case DYNAMIC_PC_LOOKUP: 1025633c4283SRichard Henderson break; 1026633c4283SRichard Henderson default: 1027633c4283SRichard Henderson g_assert_not_reached(); 1028633c4283SRichard Henderson } 1029633c4283SRichard Henderson } else { 1030fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_npc, dc->npc); 1031fcf5ef2aSThomas Huth } 1032fcf5ef2aSThomas Huth } 1033fcf5ef2aSThomas Huth 10340c2e96c1SRichard Henderson static void save_state(DisasContext *dc) 1035fcf5ef2aSThomas Huth { 1036fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_pc, dc->pc); 1037fcf5ef2aSThomas Huth save_npc(dc); 1038fcf5ef2aSThomas Huth } 1039fcf5ef2aSThomas Huth 1040fcf5ef2aSThomas Huth static void gen_exception(DisasContext *dc, int which) 1041fcf5ef2aSThomas Huth { 104289527e3aSRichard Henderson finishing_insn(dc); 1043fcf5ef2aSThomas Huth save_state(dc); 1044ad75a51eSRichard Henderson gen_helper_raise_exception(tcg_env, tcg_constant_i32(which)); 1045af00be49SEmilio G. Cota dc->base.is_jmp = DISAS_NORETURN; 1046fcf5ef2aSThomas Huth } 1047fcf5ef2aSThomas Huth 1048186e7890SRichard Henderson static TCGLabel *delay_exceptionv(DisasContext *dc, TCGv_i32 excp) 1049fcf5ef2aSThomas Huth { 1050186e7890SRichard Henderson DisasDelayException *e = g_new0(DisasDelayException, 1); 1051186e7890SRichard Henderson 1052186e7890SRichard Henderson e->next = dc->delay_excp_list; 1053186e7890SRichard Henderson dc->delay_excp_list = e; 1054186e7890SRichard Henderson 1055186e7890SRichard Henderson e->lab = gen_new_label(); 1056186e7890SRichard Henderson e->excp = excp; 1057186e7890SRichard Henderson e->pc = dc->pc; 1058186e7890SRichard Henderson /* Caller must have used flush_cond before branch. */ 1059186e7890SRichard Henderson assert(e->npc != JUMP_PC); 1060186e7890SRichard Henderson e->npc = dc->npc; 1061186e7890SRichard Henderson 1062186e7890SRichard Henderson return e->lab; 1063186e7890SRichard Henderson } 1064186e7890SRichard Henderson 1065186e7890SRichard Henderson static TCGLabel *delay_exception(DisasContext *dc, int excp) 1066186e7890SRichard Henderson { 1067186e7890SRichard Henderson return delay_exceptionv(dc, tcg_constant_i32(excp)); 1068186e7890SRichard Henderson } 1069186e7890SRichard Henderson 1070186e7890SRichard Henderson static void gen_check_align(DisasContext *dc, TCGv addr, int mask) 1071186e7890SRichard Henderson { 1072186e7890SRichard Henderson TCGv t = tcg_temp_new(); 1073186e7890SRichard Henderson TCGLabel *lab; 1074186e7890SRichard Henderson 1075186e7890SRichard Henderson tcg_gen_andi_tl(t, addr, mask); 1076186e7890SRichard Henderson 1077186e7890SRichard Henderson flush_cond(dc); 1078186e7890SRichard Henderson lab = delay_exception(dc, TT_UNALIGNED); 1079186e7890SRichard Henderson tcg_gen_brcondi_tl(TCG_COND_NE, t, 0, lab); 1080fcf5ef2aSThomas Huth } 1081fcf5ef2aSThomas Huth 10820c2e96c1SRichard Henderson static void gen_mov_pc_npc(DisasContext *dc) 1083fcf5ef2aSThomas Huth { 108489527e3aSRichard Henderson finishing_insn(dc); 108589527e3aSRichard Henderson 1086633c4283SRichard Henderson if (dc->npc & 3) { 1087633c4283SRichard Henderson switch (dc->npc) { 1088633c4283SRichard Henderson case JUMP_PC: 1089fcf5ef2aSThomas Huth gen_generic_branch(dc); 1090fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_pc, cpu_npc); 109199c82c47SRichard Henderson dc->pc = DYNAMIC_PC_LOOKUP; 1092633c4283SRichard Henderson break; 1093633c4283SRichard Henderson case DYNAMIC_PC: 1094633c4283SRichard Henderson case DYNAMIC_PC_LOOKUP: 1095fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_pc, cpu_npc); 1096633c4283SRichard Henderson dc->pc = dc->npc; 1097633c4283SRichard Henderson break; 1098633c4283SRichard Henderson default: 1099633c4283SRichard Henderson g_assert_not_reached(); 1100633c4283SRichard Henderson } 1101fcf5ef2aSThomas Huth } else { 1102fcf5ef2aSThomas Huth dc->pc = dc->npc; 1103fcf5ef2aSThomas Huth } 1104fcf5ef2aSThomas Huth } 1105fcf5ef2aSThomas Huth 1106fcf5ef2aSThomas Huth static void gen_compare(DisasCompare *cmp, bool xcc, unsigned int cond, 1107fcf5ef2aSThomas Huth DisasContext *dc) 1108fcf5ef2aSThomas Huth { 1109b597eedcSRichard Henderson TCGv t1; 1110fcf5ef2aSThomas Huth 11112a1905c7SRichard Henderson cmp->c1 = t1 = tcg_temp_new(); 1112c8507ebfSRichard Henderson cmp->c2 = 0; 11132a1905c7SRichard Henderson 11142a1905c7SRichard Henderson switch (cond & 7) { 11152a1905c7SRichard Henderson case 0x0: /* never */ 11162a1905c7SRichard Henderson cmp->cond = TCG_COND_NEVER; 1117c8507ebfSRichard Henderson cmp->c1 = tcg_constant_tl(0); 1118fcf5ef2aSThomas Huth break; 11192a1905c7SRichard Henderson 11202a1905c7SRichard Henderson case 0x1: /* eq: Z */ 11212a1905c7SRichard Henderson cmp->cond = TCG_COND_EQ; 11222a1905c7SRichard Henderson if (TARGET_LONG_BITS == 32 || xcc) { 11232a1905c7SRichard Henderson tcg_gen_mov_tl(t1, cpu_cc_Z); 11242a1905c7SRichard Henderson } else { 11252a1905c7SRichard Henderson tcg_gen_ext32u_tl(t1, cpu_icc_Z); 11262a1905c7SRichard Henderson } 11272a1905c7SRichard Henderson break; 11282a1905c7SRichard Henderson 11292a1905c7SRichard Henderson case 0x2: /* le: Z | (N ^ V) */ 11302a1905c7SRichard Henderson /* 11312a1905c7SRichard Henderson * Simplify: 11322a1905c7SRichard Henderson * cc_Z || (N ^ V) < 0 NE 11332a1905c7SRichard Henderson * cc_Z && !((N ^ V) < 0) EQ 11342a1905c7SRichard Henderson * cc_Z & ~((N ^ V) >> TLB) EQ 11352a1905c7SRichard Henderson */ 11362a1905c7SRichard Henderson cmp->cond = TCG_COND_EQ; 11372a1905c7SRichard Henderson tcg_gen_xor_tl(t1, cpu_cc_N, cpu_cc_V); 11382a1905c7SRichard Henderson tcg_gen_sextract_tl(t1, t1, xcc ? 63 : 31, 1); 11392a1905c7SRichard Henderson tcg_gen_andc_tl(t1, xcc ? cpu_cc_Z : cpu_icc_Z, t1); 11402a1905c7SRichard Henderson if (TARGET_LONG_BITS == 64 && !xcc) { 11412a1905c7SRichard Henderson tcg_gen_ext32u_tl(t1, t1); 11422a1905c7SRichard Henderson } 11432a1905c7SRichard Henderson break; 11442a1905c7SRichard Henderson 11452a1905c7SRichard Henderson case 0x3: /* lt: N ^ V */ 11462a1905c7SRichard Henderson cmp->cond = TCG_COND_LT; 11472a1905c7SRichard Henderson tcg_gen_xor_tl(t1, cpu_cc_N, cpu_cc_V); 11482a1905c7SRichard Henderson if (TARGET_LONG_BITS == 64 && !xcc) { 11492a1905c7SRichard Henderson tcg_gen_ext32s_tl(t1, t1); 11502a1905c7SRichard Henderson } 11512a1905c7SRichard Henderson break; 11522a1905c7SRichard Henderson 11532a1905c7SRichard Henderson case 0x4: /* leu: Z | C */ 11542a1905c7SRichard Henderson /* 11552a1905c7SRichard Henderson * Simplify: 11562a1905c7SRichard Henderson * cc_Z == 0 || cc_C != 0 NE 11572a1905c7SRichard Henderson * cc_Z != 0 && cc_C == 0 EQ 11582a1905c7SRichard Henderson * cc_Z & (cc_C ? 0 : -1) EQ 11592a1905c7SRichard Henderson * cc_Z & (cc_C - 1) EQ 11602a1905c7SRichard Henderson */ 11612a1905c7SRichard Henderson cmp->cond = TCG_COND_EQ; 11622a1905c7SRichard Henderson if (TARGET_LONG_BITS == 32 || xcc) { 11632a1905c7SRichard Henderson tcg_gen_subi_tl(t1, cpu_cc_C, 1); 11642a1905c7SRichard Henderson tcg_gen_and_tl(t1, t1, cpu_cc_Z); 11652a1905c7SRichard Henderson } else { 11662a1905c7SRichard Henderson tcg_gen_extract_tl(t1, cpu_icc_C, 32, 1); 11672a1905c7SRichard Henderson tcg_gen_subi_tl(t1, t1, 1); 11682a1905c7SRichard Henderson tcg_gen_and_tl(t1, t1, cpu_icc_Z); 11692a1905c7SRichard Henderson tcg_gen_ext32u_tl(t1, t1); 11702a1905c7SRichard Henderson } 11712a1905c7SRichard Henderson break; 11722a1905c7SRichard Henderson 11732a1905c7SRichard Henderson case 0x5: /* ltu: C */ 11742a1905c7SRichard Henderson cmp->cond = TCG_COND_NE; 11752a1905c7SRichard Henderson if (TARGET_LONG_BITS == 32 || xcc) { 11762a1905c7SRichard Henderson tcg_gen_mov_tl(t1, cpu_cc_C); 11772a1905c7SRichard Henderson } else { 11782a1905c7SRichard Henderson tcg_gen_extract_tl(t1, cpu_icc_C, 32, 1); 11792a1905c7SRichard Henderson } 11802a1905c7SRichard Henderson break; 11812a1905c7SRichard Henderson 11822a1905c7SRichard Henderson case 0x6: /* neg: N */ 11832a1905c7SRichard Henderson cmp->cond = TCG_COND_LT; 11842a1905c7SRichard Henderson if (TARGET_LONG_BITS == 32 || xcc) { 11852a1905c7SRichard Henderson tcg_gen_mov_tl(t1, cpu_cc_N); 11862a1905c7SRichard Henderson } else { 11872a1905c7SRichard Henderson tcg_gen_ext32s_tl(t1, cpu_cc_N); 11882a1905c7SRichard Henderson } 11892a1905c7SRichard Henderson break; 11902a1905c7SRichard Henderson 11912a1905c7SRichard Henderson case 0x7: /* vs: V */ 11922a1905c7SRichard Henderson cmp->cond = TCG_COND_LT; 11932a1905c7SRichard Henderson if (TARGET_LONG_BITS == 32 || xcc) { 11942a1905c7SRichard Henderson tcg_gen_mov_tl(t1, cpu_cc_V); 11952a1905c7SRichard Henderson } else { 11962a1905c7SRichard Henderson tcg_gen_ext32s_tl(t1, cpu_cc_V); 11972a1905c7SRichard Henderson } 11982a1905c7SRichard Henderson break; 11992a1905c7SRichard Henderson } 12002a1905c7SRichard Henderson if (cond & 8) { 12012a1905c7SRichard Henderson cmp->cond = tcg_invert_cond(cmp->cond); 1202fcf5ef2aSThomas Huth } 1203fcf5ef2aSThomas Huth } 1204fcf5ef2aSThomas Huth 1205fcf5ef2aSThomas Huth static void gen_fcompare(DisasCompare *cmp, unsigned int cc, unsigned int cond) 1206fcf5ef2aSThomas Huth { 1207d8c5b92fSRichard Henderson TCGv_i32 fcc = cpu_fcc[cc]; 1208d8c5b92fSRichard Henderson TCGv_i32 c1 = fcc; 1209d8c5b92fSRichard Henderson int c2 = 0; 1210d8c5b92fSRichard Henderson TCGCond tcond; 1211fcf5ef2aSThomas Huth 1212d8c5b92fSRichard Henderson /* 1213d8c5b92fSRichard Henderson * FCC values: 1214d8c5b92fSRichard Henderson * 0 = 1215d8c5b92fSRichard Henderson * 1 < 1216d8c5b92fSRichard Henderson * 2 > 1217d8c5b92fSRichard Henderson * 3 unordered 1218d8c5b92fSRichard Henderson */ 1219d8c5b92fSRichard Henderson switch (cond & 7) { 1220d8c5b92fSRichard Henderson case 0x0: /* fbn */ 1221d8c5b92fSRichard Henderson tcond = TCG_COND_NEVER; 1222fcf5ef2aSThomas Huth break; 1223d8c5b92fSRichard Henderson case 0x1: /* fbne : !0 */ 1224d8c5b92fSRichard Henderson tcond = TCG_COND_NE; 1225fcf5ef2aSThomas Huth break; 1226d8c5b92fSRichard Henderson case 0x2: /* fblg : 1 or 2 */ 1227d8c5b92fSRichard Henderson /* fcc in {1,2} - 1 -> fcc in {0,1} */ 1228d8c5b92fSRichard Henderson c1 = tcg_temp_new_i32(); 1229d8c5b92fSRichard Henderson tcg_gen_addi_i32(c1, fcc, -1); 1230d8c5b92fSRichard Henderson c2 = 1; 1231d8c5b92fSRichard Henderson tcond = TCG_COND_LEU; 1232fcf5ef2aSThomas Huth break; 1233d8c5b92fSRichard Henderson case 0x3: /* fbul : 1 or 3 */ 1234d8c5b92fSRichard Henderson c1 = tcg_temp_new_i32(); 1235d8c5b92fSRichard Henderson tcg_gen_andi_i32(c1, fcc, 1); 1236d8c5b92fSRichard Henderson tcond = TCG_COND_NE; 1237d8c5b92fSRichard Henderson break; 1238d8c5b92fSRichard Henderson case 0x4: /* fbl : 1 */ 1239d8c5b92fSRichard Henderson c2 = 1; 1240d8c5b92fSRichard Henderson tcond = TCG_COND_EQ; 1241d8c5b92fSRichard Henderson break; 1242d8c5b92fSRichard Henderson case 0x5: /* fbug : 2 or 3 */ 1243d8c5b92fSRichard Henderson c2 = 2; 1244d8c5b92fSRichard Henderson tcond = TCG_COND_GEU; 1245d8c5b92fSRichard Henderson break; 1246d8c5b92fSRichard Henderson case 0x6: /* fbg : 2 */ 1247d8c5b92fSRichard Henderson c2 = 2; 1248d8c5b92fSRichard Henderson tcond = TCG_COND_EQ; 1249d8c5b92fSRichard Henderson break; 1250d8c5b92fSRichard Henderson case 0x7: /* fbu : 3 */ 1251d8c5b92fSRichard Henderson c2 = 3; 1252d8c5b92fSRichard Henderson tcond = TCG_COND_EQ; 1253fcf5ef2aSThomas Huth break; 1254fcf5ef2aSThomas Huth } 1255d8c5b92fSRichard Henderson if (cond & 8) { 1256d8c5b92fSRichard Henderson tcond = tcg_invert_cond(tcond); 1257fcf5ef2aSThomas Huth } 1258d8c5b92fSRichard Henderson 1259d8c5b92fSRichard Henderson cmp->cond = tcond; 1260d8c5b92fSRichard Henderson cmp->c2 = c2; 1261d8c5b92fSRichard Henderson cmp->c1 = tcg_temp_new(); 1262d8c5b92fSRichard Henderson tcg_gen_extu_i32_tl(cmp->c1, c1); 1263fcf5ef2aSThomas Huth } 1264fcf5ef2aSThomas Huth 12652c4f56c9SRichard Henderson static bool gen_compare_reg(DisasCompare *cmp, int cond, TCGv r_src) 12662c4f56c9SRichard Henderson { 12672c4f56c9SRichard Henderson static const TCGCond cond_reg[4] = { 1268ab9ffe98SRichard Henderson TCG_COND_NEVER, /* reserved */ 1269fcf5ef2aSThomas Huth TCG_COND_EQ, 1270fcf5ef2aSThomas Huth TCG_COND_LE, 1271fcf5ef2aSThomas Huth TCG_COND_LT, 1272fcf5ef2aSThomas Huth }; 12732c4f56c9SRichard Henderson TCGCond tcond; 1274fcf5ef2aSThomas Huth 12752c4f56c9SRichard Henderson if ((cond & 3) == 0) { 12762c4f56c9SRichard Henderson return false; 12772c4f56c9SRichard Henderson } 12782c4f56c9SRichard Henderson tcond = cond_reg[cond & 3]; 12792c4f56c9SRichard Henderson if (cond & 4) { 12802c4f56c9SRichard Henderson tcond = tcg_invert_cond(tcond); 12812c4f56c9SRichard Henderson } 12822c4f56c9SRichard Henderson 12832c4f56c9SRichard Henderson cmp->cond = tcond; 1284816f89b7SRichard Henderson cmp->c1 = tcg_temp_new(); 1285c8507ebfSRichard Henderson cmp->c2 = 0; 1286816f89b7SRichard Henderson tcg_gen_mov_tl(cmp->c1, r_src); 12872c4f56c9SRichard Henderson return true; 1288fcf5ef2aSThomas Huth } 1289fcf5ef2aSThomas Huth 1290baf3dbf2SRichard Henderson static void gen_op_clear_ieee_excp_and_FTT(void) 1291baf3dbf2SRichard Henderson { 12923590f01eSRichard Henderson tcg_gen_st_i32(tcg_constant_i32(0), tcg_env, 12933590f01eSRichard Henderson offsetof(CPUSPARCState, fsr_cexc_ftt)); 1294baf3dbf2SRichard Henderson } 1295baf3dbf2SRichard Henderson 1296baf3dbf2SRichard Henderson static void gen_op_fmovs(TCGv_i32 dst, TCGv_i32 src) 1297baf3dbf2SRichard Henderson { 1298baf3dbf2SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 1299baf3dbf2SRichard Henderson tcg_gen_mov_i32(dst, src); 1300baf3dbf2SRichard Henderson } 1301baf3dbf2SRichard Henderson 1302baf3dbf2SRichard Henderson static void gen_op_fnegs(TCGv_i32 dst, TCGv_i32 src) 1303baf3dbf2SRichard Henderson { 1304baf3dbf2SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 1305daf457d4SRichard Henderson tcg_gen_xori_i32(dst, src, 1u << 31); 1306baf3dbf2SRichard Henderson } 1307baf3dbf2SRichard Henderson 1308baf3dbf2SRichard Henderson static void gen_op_fabss(TCGv_i32 dst, TCGv_i32 src) 1309baf3dbf2SRichard Henderson { 1310baf3dbf2SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 1311daf457d4SRichard Henderson tcg_gen_andi_i32(dst, src, ~(1u << 31)); 1312baf3dbf2SRichard Henderson } 1313baf3dbf2SRichard Henderson 1314c6d83e4fSRichard Henderson static void gen_op_fmovd(TCGv_i64 dst, TCGv_i64 src) 1315c6d83e4fSRichard Henderson { 1316c6d83e4fSRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 1317c6d83e4fSRichard Henderson tcg_gen_mov_i64(dst, src); 1318c6d83e4fSRichard Henderson } 1319c6d83e4fSRichard Henderson 1320c6d83e4fSRichard Henderson static void gen_op_fnegd(TCGv_i64 dst, TCGv_i64 src) 1321c6d83e4fSRichard Henderson { 1322c6d83e4fSRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 1323daf457d4SRichard Henderson tcg_gen_xori_i64(dst, src, 1ull << 63); 1324c6d83e4fSRichard Henderson } 1325c6d83e4fSRichard Henderson 1326c6d83e4fSRichard Henderson static void gen_op_fabsd(TCGv_i64 dst, TCGv_i64 src) 1327c6d83e4fSRichard Henderson { 1328c6d83e4fSRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 1329daf457d4SRichard Henderson tcg_gen_andi_i64(dst, src, ~(1ull << 63)); 1330daf457d4SRichard Henderson } 1331daf457d4SRichard Henderson 1332daf457d4SRichard Henderson static void gen_op_fnegq(TCGv_i128 dst, TCGv_i128 src) 1333daf457d4SRichard Henderson { 1334daf457d4SRichard Henderson TCGv_i64 l = tcg_temp_new_i64(); 1335daf457d4SRichard Henderson TCGv_i64 h = tcg_temp_new_i64(); 1336daf457d4SRichard Henderson 1337daf457d4SRichard Henderson tcg_gen_extr_i128_i64(l, h, src); 1338daf457d4SRichard Henderson tcg_gen_xori_i64(h, h, 1ull << 63); 1339daf457d4SRichard Henderson tcg_gen_concat_i64_i128(dst, l, h); 1340daf457d4SRichard Henderson } 1341daf457d4SRichard Henderson 1342daf457d4SRichard Henderson static void gen_op_fabsq(TCGv_i128 dst, TCGv_i128 src) 1343daf457d4SRichard Henderson { 1344daf457d4SRichard Henderson TCGv_i64 l = tcg_temp_new_i64(); 1345daf457d4SRichard Henderson TCGv_i64 h = tcg_temp_new_i64(); 1346daf457d4SRichard Henderson 1347daf457d4SRichard Henderson tcg_gen_extr_i128_i64(l, h, src); 1348daf457d4SRichard Henderson tcg_gen_andi_i64(h, h, ~(1ull << 63)); 1349daf457d4SRichard Henderson tcg_gen_concat_i64_i128(dst, l, h); 1350c6d83e4fSRichard Henderson } 1351c6d83e4fSRichard Henderson 13524fd71d19SRichard Henderson static void gen_op_fmadds(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2, TCGv_i32 s3) 13534fd71d19SRichard Henderson { 13544fd71d19SRichard Henderson gen_helper_fmadds(d, tcg_env, s1, s2, s3, tcg_constant_i32(0)); 13554fd71d19SRichard Henderson } 13564fd71d19SRichard Henderson 13574fd71d19SRichard Henderson static void gen_op_fmaddd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2, TCGv_i64 s3) 13584fd71d19SRichard Henderson { 13594fd71d19SRichard Henderson gen_helper_fmaddd(d, tcg_env, s1, s2, s3, tcg_constant_i32(0)); 13604fd71d19SRichard Henderson } 13614fd71d19SRichard Henderson 13624fd71d19SRichard Henderson static void gen_op_fmsubs(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2, TCGv_i32 s3) 13634fd71d19SRichard Henderson { 13644fd71d19SRichard Henderson int op = float_muladd_negate_c; 13654fd71d19SRichard Henderson gen_helper_fmadds(d, tcg_env, s1, s2, s3, tcg_constant_i32(op)); 13664fd71d19SRichard Henderson } 13674fd71d19SRichard Henderson 13684fd71d19SRichard Henderson static void gen_op_fmsubd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2, TCGv_i64 s3) 13694fd71d19SRichard Henderson { 13704fd71d19SRichard Henderson int op = float_muladd_negate_c; 13714fd71d19SRichard Henderson gen_helper_fmaddd(d, tcg_env, s1, s2, s3, tcg_constant_i32(op)); 13724fd71d19SRichard Henderson } 13734fd71d19SRichard Henderson 13744fd71d19SRichard Henderson static void gen_op_fnmsubs(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2, TCGv_i32 s3) 13754fd71d19SRichard Henderson { 13764fd71d19SRichard Henderson int op = float_muladd_negate_c | float_muladd_negate_result; 13774fd71d19SRichard Henderson gen_helper_fmadds(d, tcg_env, s1, s2, s3, tcg_constant_i32(op)); 13784fd71d19SRichard Henderson } 13794fd71d19SRichard Henderson 13804fd71d19SRichard Henderson static void gen_op_fnmsubd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2, TCGv_i64 s3) 13814fd71d19SRichard Henderson { 13824fd71d19SRichard Henderson int op = float_muladd_negate_c | float_muladd_negate_result; 13834fd71d19SRichard Henderson gen_helper_fmaddd(d, tcg_env, s1, s2, s3, tcg_constant_i32(op)); 13844fd71d19SRichard Henderson } 13854fd71d19SRichard Henderson 13864fd71d19SRichard Henderson static void gen_op_fnmadds(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2, TCGv_i32 s3) 13874fd71d19SRichard Henderson { 13884fd71d19SRichard Henderson int op = float_muladd_negate_result; 13894fd71d19SRichard Henderson gen_helper_fmadds(d, tcg_env, s1, s2, s3, tcg_constant_i32(op)); 13904fd71d19SRichard Henderson } 13914fd71d19SRichard Henderson 13924fd71d19SRichard Henderson static void gen_op_fnmaddd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2, TCGv_i64 s3) 13934fd71d19SRichard Henderson { 13944fd71d19SRichard Henderson int op = float_muladd_negate_result; 13954fd71d19SRichard Henderson gen_helper_fmaddd(d, tcg_env, s1, s2, s3, tcg_constant_i32(op)); 13964fd71d19SRichard Henderson } 13974fd71d19SRichard Henderson 13983d50b728SRichard Henderson /* Use muladd to compute (1 * src1) + src2 / 2 with one rounding. */ 13993d50b728SRichard Henderson static void gen_op_fhadds(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2) 14003d50b728SRichard Henderson { 14013d50b728SRichard Henderson TCGv_i32 one = tcg_constant_i32(float32_one); 14023d50b728SRichard Henderson int op = float_muladd_halve_result; 14033d50b728SRichard Henderson gen_helper_fmadds(d, tcg_env, one, s1, s2, tcg_constant_i32(op)); 14043d50b728SRichard Henderson } 14053d50b728SRichard Henderson 14063d50b728SRichard Henderson static void gen_op_fhaddd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2) 14073d50b728SRichard Henderson { 14083d50b728SRichard Henderson TCGv_i64 one = tcg_constant_i64(float64_one); 14093d50b728SRichard Henderson int op = float_muladd_halve_result; 14103d50b728SRichard Henderson gen_helper_fmaddd(d, tcg_env, one, s1, s2, tcg_constant_i32(op)); 14113d50b728SRichard Henderson } 14123d50b728SRichard Henderson 14133d50b728SRichard Henderson /* Use muladd to compute (1 * src1) - src2 / 2 with one rounding. */ 14143d50b728SRichard Henderson static void gen_op_fhsubs(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2) 14153d50b728SRichard Henderson { 14163d50b728SRichard Henderson TCGv_i32 one = tcg_constant_i32(float32_one); 14173d50b728SRichard Henderson int op = float_muladd_negate_c | float_muladd_halve_result; 14183d50b728SRichard Henderson gen_helper_fmadds(d, tcg_env, one, s1, s2, tcg_constant_i32(op)); 14193d50b728SRichard Henderson } 14203d50b728SRichard Henderson 14213d50b728SRichard Henderson static void gen_op_fhsubd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2) 14223d50b728SRichard Henderson { 14233d50b728SRichard Henderson TCGv_i64 one = tcg_constant_i64(float64_one); 14243d50b728SRichard Henderson int op = float_muladd_negate_c | float_muladd_halve_result; 14253d50b728SRichard Henderson gen_helper_fmaddd(d, tcg_env, one, s1, s2, tcg_constant_i32(op)); 14263d50b728SRichard Henderson } 14273d50b728SRichard Henderson 14283d50b728SRichard Henderson /* Use muladd to compute -((1 * src1) + src2 / 2) with one rounding. */ 14293d50b728SRichard Henderson static void gen_op_fnhadds(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2) 14303d50b728SRichard Henderson { 14313d50b728SRichard Henderson TCGv_i32 one = tcg_constant_i32(float32_one); 14323d50b728SRichard Henderson int op = float_muladd_negate_result | float_muladd_halve_result; 14333d50b728SRichard Henderson gen_helper_fmadds(d, tcg_env, one, s1, s2, tcg_constant_i32(op)); 14343d50b728SRichard Henderson } 14353d50b728SRichard Henderson 14363d50b728SRichard Henderson static void gen_op_fnhaddd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2) 14373d50b728SRichard Henderson { 14383d50b728SRichard Henderson TCGv_i64 one = tcg_constant_i64(float64_one); 14393d50b728SRichard Henderson int op = float_muladd_negate_result | float_muladd_halve_result; 14403d50b728SRichard Henderson gen_helper_fmaddd(d, tcg_env, one, s1, s2, tcg_constant_i32(op)); 14413d50b728SRichard Henderson } 14423d50b728SRichard Henderson 14433590f01eSRichard Henderson static void gen_op_fpexception_im(DisasContext *dc, int ftt) 1444fcf5ef2aSThomas Huth { 14453590f01eSRichard Henderson /* 14463590f01eSRichard Henderson * CEXC is only set when succesfully completing an FPop, 14473590f01eSRichard Henderson * or when raising FSR_FTT_IEEE_EXCP, i.e. check_ieee_exception. 14483590f01eSRichard Henderson * Thus we can simply store FTT into this field. 14493590f01eSRichard Henderson */ 14503590f01eSRichard Henderson tcg_gen_st_i32(tcg_constant_i32(ftt), tcg_env, 14513590f01eSRichard Henderson offsetof(CPUSPARCState, fsr_cexc_ftt)); 1452fcf5ef2aSThomas Huth gen_exception(dc, TT_FP_EXCP); 1453fcf5ef2aSThomas Huth } 1454fcf5ef2aSThomas Huth 1455fcf5ef2aSThomas Huth static int gen_trap_ifnofpu(DisasContext *dc) 1456fcf5ef2aSThomas Huth { 1457fcf5ef2aSThomas Huth #if !defined(CONFIG_USER_ONLY) 1458fcf5ef2aSThomas Huth if (!dc->fpu_enabled) { 1459fcf5ef2aSThomas Huth gen_exception(dc, TT_NFPU_INSN); 1460fcf5ef2aSThomas Huth return 1; 1461fcf5ef2aSThomas Huth } 1462fcf5ef2aSThomas Huth #endif 1463fcf5ef2aSThomas Huth return 0; 1464fcf5ef2aSThomas Huth } 1465fcf5ef2aSThomas Huth 1466fcf5ef2aSThomas Huth /* asi moves */ 1467fcf5ef2aSThomas Huth typedef enum { 1468fcf5ef2aSThomas Huth GET_ASI_HELPER, 1469fcf5ef2aSThomas Huth GET_ASI_EXCP, 1470fcf5ef2aSThomas Huth GET_ASI_DIRECT, 1471fcf5ef2aSThomas Huth GET_ASI_DTWINX, 14722786a3f8SRichard Henderson GET_ASI_CODE, 1473fcf5ef2aSThomas Huth GET_ASI_BLOCK, 1474fcf5ef2aSThomas Huth GET_ASI_SHORT, 1475fcf5ef2aSThomas Huth GET_ASI_BCOPY, 1476fcf5ef2aSThomas Huth GET_ASI_BFILL, 1477fcf5ef2aSThomas Huth } ASIType; 1478fcf5ef2aSThomas Huth 1479fcf5ef2aSThomas Huth typedef struct { 1480fcf5ef2aSThomas Huth ASIType type; 1481fcf5ef2aSThomas Huth int asi; 1482fcf5ef2aSThomas Huth int mem_idx; 148314776ab5STony Nguyen MemOp memop; 1484fcf5ef2aSThomas Huth } DisasASI; 1485fcf5ef2aSThomas Huth 1486811cc0b0SRichard Henderson /* 1487811cc0b0SRichard Henderson * Build DisasASI. 1488811cc0b0SRichard Henderson * For asi == -1, treat as non-asi. 1489811cc0b0SRichard Henderson * For ask == -2, treat as immediate offset (v8 error, v9 %asi). 1490811cc0b0SRichard Henderson */ 1491811cc0b0SRichard Henderson static DisasASI resolve_asi(DisasContext *dc, int asi, MemOp memop) 1492fcf5ef2aSThomas Huth { 1493fcf5ef2aSThomas Huth ASIType type = GET_ASI_HELPER; 1494fcf5ef2aSThomas Huth int mem_idx = dc->mem_idx; 1495fcf5ef2aSThomas Huth 1496811cc0b0SRichard Henderson if (asi == -1) { 1497811cc0b0SRichard Henderson /* Artificial "non-asi" case. */ 1498811cc0b0SRichard Henderson type = GET_ASI_DIRECT; 1499811cc0b0SRichard Henderson goto done; 1500811cc0b0SRichard Henderson } 1501811cc0b0SRichard Henderson 1502fcf5ef2aSThomas Huth #ifndef TARGET_SPARC64 1503fcf5ef2aSThomas Huth /* Before v9, all asis are immediate and privileged. */ 1504811cc0b0SRichard Henderson if (asi < 0) { 1505fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 1506fcf5ef2aSThomas Huth type = GET_ASI_EXCP; 1507fcf5ef2aSThomas Huth } else if (supervisor(dc) 1508fcf5ef2aSThomas Huth /* Note that LEON accepts ASI_USERDATA in user mode, for 1509fcf5ef2aSThomas Huth use with CASA. Also note that previous versions of 1510fcf5ef2aSThomas Huth QEMU allowed (and old versions of gcc emitted) ASI_P 1511fcf5ef2aSThomas Huth for LEON, which is incorrect. */ 1512fcf5ef2aSThomas Huth || (asi == ASI_USERDATA 1513fcf5ef2aSThomas Huth && (dc->def->features & CPU_FEATURE_CASA))) { 1514fcf5ef2aSThomas Huth switch (asi) { 1515fcf5ef2aSThomas Huth case ASI_USERDATA: /* User data access */ 1516fcf5ef2aSThomas Huth mem_idx = MMU_USER_IDX; 1517fcf5ef2aSThomas Huth type = GET_ASI_DIRECT; 1518fcf5ef2aSThomas Huth break; 1519fcf5ef2aSThomas Huth case ASI_KERNELDATA: /* Supervisor data access */ 1520fcf5ef2aSThomas Huth mem_idx = MMU_KERNEL_IDX; 1521fcf5ef2aSThomas Huth type = GET_ASI_DIRECT; 1522fcf5ef2aSThomas Huth break; 15232786a3f8SRichard Henderson case ASI_USERTXT: /* User text access */ 15242786a3f8SRichard Henderson mem_idx = MMU_USER_IDX; 15252786a3f8SRichard Henderson type = GET_ASI_CODE; 15262786a3f8SRichard Henderson break; 15272786a3f8SRichard Henderson case ASI_KERNELTXT: /* Supervisor text access */ 15282786a3f8SRichard Henderson mem_idx = MMU_KERNEL_IDX; 15292786a3f8SRichard Henderson type = GET_ASI_CODE; 15302786a3f8SRichard Henderson break; 1531fcf5ef2aSThomas Huth case ASI_M_BYPASS: /* MMU passthrough */ 1532fcf5ef2aSThomas Huth case ASI_LEON_BYPASS: /* LEON MMU passthrough */ 1533fcf5ef2aSThomas Huth mem_idx = MMU_PHYS_IDX; 1534fcf5ef2aSThomas Huth type = GET_ASI_DIRECT; 1535fcf5ef2aSThomas Huth break; 1536fcf5ef2aSThomas Huth case ASI_M_BCOPY: /* Block copy, sta access */ 1537fcf5ef2aSThomas Huth mem_idx = MMU_KERNEL_IDX; 1538fcf5ef2aSThomas Huth type = GET_ASI_BCOPY; 1539fcf5ef2aSThomas Huth break; 1540fcf5ef2aSThomas Huth case ASI_M_BFILL: /* Block fill, stda access */ 1541fcf5ef2aSThomas Huth mem_idx = MMU_KERNEL_IDX; 1542fcf5ef2aSThomas Huth type = GET_ASI_BFILL; 1543fcf5ef2aSThomas Huth break; 1544fcf5ef2aSThomas Huth } 15456e10f37cSKONRAD Frederic 15466e10f37cSKONRAD Frederic /* MMU_PHYS_IDX is used when the MMU is disabled to passthrough the 15476e10f37cSKONRAD Frederic * permissions check in get_physical_address(..). 15486e10f37cSKONRAD Frederic */ 15496e10f37cSKONRAD Frederic mem_idx = (dc->mem_idx == MMU_PHYS_IDX) ? MMU_PHYS_IDX : mem_idx; 1550fcf5ef2aSThomas Huth } else { 1551fcf5ef2aSThomas Huth gen_exception(dc, TT_PRIV_INSN); 1552fcf5ef2aSThomas Huth type = GET_ASI_EXCP; 1553fcf5ef2aSThomas Huth } 1554fcf5ef2aSThomas Huth #else 1555811cc0b0SRichard Henderson if (asi < 0) { 1556fcf5ef2aSThomas Huth asi = dc->asi; 1557fcf5ef2aSThomas Huth } 1558fcf5ef2aSThomas Huth /* With v9, all asis below 0x80 are privileged. */ 1559fcf5ef2aSThomas Huth /* ??? We ought to check cpu_has_hypervisor, but we didn't copy 1560fcf5ef2aSThomas Huth down that bit into DisasContext. For the moment that's ok, 1561fcf5ef2aSThomas Huth since the direct implementations below doesn't have any ASIs 1562fcf5ef2aSThomas Huth in the restricted [0x30, 0x7f] range, and the check will be 1563fcf5ef2aSThomas Huth done properly in the helper. */ 1564fcf5ef2aSThomas Huth if (!supervisor(dc) && asi < 0x80) { 1565fcf5ef2aSThomas Huth gen_exception(dc, TT_PRIV_ACT); 1566fcf5ef2aSThomas Huth type = GET_ASI_EXCP; 1567fcf5ef2aSThomas Huth } else { 1568fcf5ef2aSThomas Huth switch (asi) { 1569fcf5ef2aSThomas Huth case ASI_REAL: /* Bypass */ 1570fcf5ef2aSThomas Huth case ASI_REAL_IO: /* Bypass, non-cacheable */ 1571fcf5ef2aSThomas Huth case ASI_REAL_L: /* Bypass LE */ 1572fcf5ef2aSThomas Huth case ASI_REAL_IO_L: /* Bypass, non-cacheable LE */ 1573fcf5ef2aSThomas Huth case ASI_TWINX_REAL: /* Real address, twinx */ 1574fcf5ef2aSThomas Huth case ASI_TWINX_REAL_L: /* Real address, twinx, LE */ 1575fcf5ef2aSThomas Huth case ASI_QUAD_LDD_PHYS: 1576fcf5ef2aSThomas Huth case ASI_QUAD_LDD_PHYS_L: 1577fcf5ef2aSThomas Huth mem_idx = MMU_PHYS_IDX; 1578fcf5ef2aSThomas Huth break; 1579fcf5ef2aSThomas Huth case ASI_N: /* Nucleus */ 1580fcf5ef2aSThomas Huth case ASI_NL: /* Nucleus LE */ 1581fcf5ef2aSThomas Huth case ASI_TWINX_N: 1582fcf5ef2aSThomas Huth case ASI_TWINX_NL: 1583fcf5ef2aSThomas Huth case ASI_NUCLEUS_QUAD_LDD: 1584fcf5ef2aSThomas Huth case ASI_NUCLEUS_QUAD_LDD_L: 15859a10756dSArtyom Tarasenko if (hypervisor(dc)) { 158684f8f587SArtyom Tarasenko mem_idx = MMU_PHYS_IDX; 15879a10756dSArtyom Tarasenko } else { 1588fcf5ef2aSThomas Huth mem_idx = MMU_NUCLEUS_IDX; 15899a10756dSArtyom Tarasenko } 1590fcf5ef2aSThomas Huth break; 1591fcf5ef2aSThomas Huth case ASI_AIUP: /* As if user primary */ 1592fcf5ef2aSThomas Huth case ASI_AIUPL: /* As if user primary LE */ 1593fcf5ef2aSThomas Huth case ASI_TWINX_AIUP: 1594fcf5ef2aSThomas Huth case ASI_TWINX_AIUP_L: 1595fcf5ef2aSThomas Huth case ASI_BLK_AIUP_4V: 1596fcf5ef2aSThomas Huth case ASI_BLK_AIUP_L_4V: 1597fcf5ef2aSThomas Huth case ASI_BLK_AIUP: 1598fcf5ef2aSThomas Huth case ASI_BLK_AIUPL: 1599fcf5ef2aSThomas Huth mem_idx = MMU_USER_IDX; 1600fcf5ef2aSThomas Huth break; 1601fcf5ef2aSThomas Huth case ASI_AIUS: /* As if user secondary */ 1602fcf5ef2aSThomas Huth case ASI_AIUSL: /* As if user secondary LE */ 1603fcf5ef2aSThomas Huth case ASI_TWINX_AIUS: 1604fcf5ef2aSThomas Huth case ASI_TWINX_AIUS_L: 1605fcf5ef2aSThomas Huth case ASI_BLK_AIUS_4V: 1606fcf5ef2aSThomas Huth case ASI_BLK_AIUS_L_4V: 1607fcf5ef2aSThomas Huth case ASI_BLK_AIUS: 1608fcf5ef2aSThomas Huth case ASI_BLK_AIUSL: 1609fcf5ef2aSThomas Huth mem_idx = MMU_USER_SECONDARY_IDX; 1610fcf5ef2aSThomas Huth break; 1611fcf5ef2aSThomas Huth case ASI_S: /* Secondary */ 1612fcf5ef2aSThomas Huth case ASI_SL: /* Secondary LE */ 1613fcf5ef2aSThomas Huth case ASI_TWINX_S: 1614fcf5ef2aSThomas Huth case ASI_TWINX_SL: 1615fcf5ef2aSThomas Huth case ASI_BLK_COMMIT_S: 1616fcf5ef2aSThomas Huth case ASI_BLK_S: 1617fcf5ef2aSThomas Huth case ASI_BLK_SL: 1618fcf5ef2aSThomas Huth case ASI_FL8_S: 1619fcf5ef2aSThomas Huth case ASI_FL8_SL: 1620fcf5ef2aSThomas Huth case ASI_FL16_S: 1621fcf5ef2aSThomas Huth case ASI_FL16_SL: 1622fcf5ef2aSThomas Huth if (mem_idx == MMU_USER_IDX) { 1623fcf5ef2aSThomas Huth mem_idx = MMU_USER_SECONDARY_IDX; 1624fcf5ef2aSThomas Huth } else if (mem_idx == MMU_KERNEL_IDX) { 1625fcf5ef2aSThomas Huth mem_idx = MMU_KERNEL_SECONDARY_IDX; 1626fcf5ef2aSThomas Huth } 1627fcf5ef2aSThomas Huth break; 1628fcf5ef2aSThomas Huth case ASI_P: /* Primary */ 1629fcf5ef2aSThomas Huth case ASI_PL: /* Primary LE */ 1630fcf5ef2aSThomas Huth case ASI_TWINX_P: 1631fcf5ef2aSThomas Huth case ASI_TWINX_PL: 1632fcf5ef2aSThomas Huth case ASI_BLK_COMMIT_P: 1633fcf5ef2aSThomas Huth case ASI_BLK_P: 1634fcf5ef2aSThomas Huth case ASI_BLK_PL: 1635fcf5ef2aSThomas Huth case ASI_FL8_P: 1636fcf5ef2aSThomas Huth case ASI_FL8_PL: 1637fcf5ef2aSThomas Huth case ASI_FL16_P: 1638fcf5ef2aSThomas Huth case ASI_FL16_PL: 1639fcf5ef2aSThomas Huth break; 1640fcf5ef2aSThomas Huth } 1641fcf5ef2aSThomas Huth switch (asi) { 1642fcf5ef2aSThomas Huth case ASI_REAL: 1643fcf5ef2aSThomas Huth case ASI_REAL_IO: 1644fcf5ef2aSThomas Huth case ASI_REAL_L: 1645fcf5ef2aSThomas Huth case ASI_REAL_IO_L: 1646fcf5ef2aSThomas Huth case ASI_N: 1647fcf5ef2aSThomas Huth case ASI_NL: 1648fcf5ef2aSThomas Huth case ASI_AIUP: 1649fcf5ef2aSThomas Huth case ASI_AIUPL: 1650fcf5ef2aSThomas Huth case ASI_AIUS: 1651fcf5ef2aSThomas Huth case ASI_AIUSL: 1652fcf5ef2aSThomas Huth case ASI_S: 1653fcf5ef2aSThomas Huth case ASI_SL: 1654fcf5ef2aSThomas Huth case ASI_P: 1655fcf5ef2aSThomas Huth case ASI_PL: 1656fcf5ef2aSThomas Huth type = GET_ASI_DIRECT; 1657fcf5ef2aSThomas Huth break; 1658fcf5ef2aSThomas Huth case ASI_TWINX_REAL: 1659fcf5ef2aSThomas Huth case ASI_TWINX_REAL_L: 1660fcf5ef2aSThomas Huth case ASI_TWINX_N: 1661fcf5ef2aSThomas Huth case ASI_TWINX_NL: 1662fcf5ef2aSThomas Huth case ASI_TWINX_AIUP: 1663fcf5ef2aSThomas Huth case ASI_TWINX_AIUP_L: 1664fcf5ef2aSThomas Huth case ASI_TWINX_AIUS: 1665fcf5ef2aSThomas Huth case ASI_TWINX_AIUS_L: 1666fcf5ef2aSThomas Huth case ASI_TWINX_P: 1667fcf5ef2aSThomas Huth case ASI_TWINX_PL: 1668fcf5ef2aSThomas Huth case ASI_TWINX_S: 1669fcf5ef2aSThomas Huth case ASI_TWINX_SL: 1670fcf5ef2aSThomas Huth case ASI_QUAD_LDD_PHYS: 1671fcf5ef2aSThomas Huth case ASI_QUAD_LDD_PHYS_L: 1672fcf5ef2aSThomas Huth case ASI_NUCLEUS_QUAD_LDD: 1673fcf5ef2aSThomas Huth case ASI_NUCLEUS_QUAD_LDD_L: 1674fcf5ef2aSThomas Huth type = GET_ASI_DTWINX; 1675fcf5ef2aSThomas Huth break; 1676fcf5ef2aSThomas Huth case ASI_BLK_COMMIT_P: 1677fcf5ef2aSThomas Huth case ASI_BLK_COMMIT_S: 1678fcf5ef2aSThomas Huth case ASI_BLK_AIUP_4V: 1679fcf5ef2aSThomas Huth case ASI_BLK_AIUP_L_4V: 1680fcf5ef2aSThomas Huth case ASI_BLK_AIUP: 1681fcf5ef2aSThomas Huth case ASI_BLK_AIUPL: 1682fcf5ef2aSThomas Huth case ASI_BLK_AIUS_4V: 1683fcf5ef2aSThomas Huth case ASI_BLK_AIUS_L_4V: 1684fcf5ef2aSThomas Huth case ASI_BLK_AIUS: 1685fcf5ef2aSThomas Huth case ASI_BLK_AIUSL: 1686fcf5ef2aSThomas Huth case ASI_BLK_S: 1687fcf5ef2aSThomas Huth case ASI_BLK_SL: 1688fcf5ef2aSThomas Huth case ASI_BLK_P: 1689fcf5ef2aSThomas Huth case ASI_BLK_PL: 1690fcf5ef2aSThomas Huth type = GET_ASI_BLOCK; 1691fcf5ef2aSThomas Huth break; 1692fcf5ef2aSThomas Huth case ASI_FL8_S: 1693fcf5ef2aSThomas Huth case ASI_FL8_SL: 1694fcf5ef2aSThomas Huth case ASI_FL8_P: 1695fcf5ef2aSThomas Huth case ASI_FL8_PL: 1696fcf5ef2aSThomas Huth memop = MO_UB; 1697fcf5ef2aSThomas Huth type = GET_ASI_SHORT; 1698fcf5ef2aSThomas Huth break; 1699fcf5ef2aSThomas Huth case ASI_FL16_S: 1700fcf5ef2aSThomas Huth case ASI_FL16_SL: 1701fcf5ef2aSThomas Huth case ASI_FL16_P: 1702fcf5ef2aSThomas Huth case ASI_FL16_PL: 1703fcf5ef2aSThomas Huth memop = MO_TEUW; 1704fcf5ef2aSThomas Huth type = GET_ASI_SHORT; 1705fcf5ef2aSThomas Huth break; 1706fcf5ef2aSThomas Huth } 1707fcf5ef2aSThomas Huth /* The little-endian asis all have bit 3 set. */ 1708fcf5ef2aSThomas Huth if (asi & 8) { 1709fcf5ef2aSThomas Huth memop ^= MO_BSWAP; 1710fcf5ef2aSThomas Huth } 1711fcf5ef2aSThomas Huth } 1712fcf5ef2aSThomas Huth #endif 1713fcf5ef2aSThomas Huth 1714811cc0b0SRichard Henderson done: 1715fcf5ef2aSThomas Huth return (DisasASI){ type, asi, mem_idx, memop }; 1716fcf5ef2aSThomas Huth } 1717fcf5ef2aSThomas Huth 1718a76779eeSRichard Henderson #if defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64) 1719a76779eeSRichard Henderson static void gen_helper_ld_asi(TCGv_i64 r, TCGv_env e, TCGv a, 1720a76779eeSRichard Henderson TCGv_i32 asi, TCGv_i32 mop) 1721a76779eeSRichard Henderson { 1722a76779eeSRichard Henderson g_assert_not_reached(); 1723a76779eeSRichard Henderson } 1724a76779eeSRichard Henderson 1725a76779eeSRichard Henderson static void gen_helper_st_asi(TCGv_env e, TCGv a, TCGv_i64 r, 1726a76779eeSRichard Henderson TCGv_i32 asi, TCGv_i32 mop) 1727a76779eeSRichard Henderson { 1728a76779eeSRichard Henderson g_assert_not_reached(); 1729a76779eeSRichard Henderson } 1730a76779eeSRichard Henderson #endif 1731a76779eeSRichard Henderson 173242071fc1SRichard Henderson static void gen_ld_asi(DisasContext *dc, DisasASI *da, TCGv dst, TCGv addr) 1733fcf5ef2aSThomas Huth { 1734c03a0fd1SRichard Henderson switch (da->type) { 1735fcf5ef2aSThomas Huth case GET_ASI_EXCP: 1736fcf5ef2aSThomas Huth break; 1737fcf5ef2aSThomas Huth case GET_ASI_DTWINX: /* Reserved for ldda. */ 1738fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 1739fcf5ef2aSThomas Huth break; 1740fcf5ef2aSThomas Huth case GET_ASI_DIRECT: 1741c03a0fd1SRichard Henderson tcg_gen_qemu_ld_tl(dst, addr, da->mem_idx, da->memop | MO_ALIGN); 1742fcf5ef2aSThomas Huth break; 17432786a3f8SRichard Henderson 17442786a3f8SRichard Henderson case GET_ASI_CODE: 17452786a3f8SRichard Henderson #if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64) 17462786a3f8SRichard Henderson { 17472786a3f8SRichard Henderson MemOpIdx oi = make_memop_idx(da->memop, da->mem_idx); 17482786a3f8SRichard Henderson TCGv_i64 t64 = tcg_temp_new_i64(); 17492786a3f8SRichard Henderson 17502786a3f8SRichard Henderson gen_helper_ld_code(t64, tcg_env, addr, tcg_constant_i32(oi)); 17512786a3f8SRichard Henderson tcg_gen_trunc_i64_tl(dst, t64); 17522786a3f8SRichard Henderson } 17532786a3f8SRichard Henderson break; 17542786a3f8SRichard Henderson #else 17552786a3f8SRichard Henderson g_assert_not_reached(); 17562786a3f8SRichard Henderson #endif 17572786a3f8SRichard Henderson 1758fcf5ef2aSThomas Huth default: 1759fcf5ef2aSThomas Huth { 1760c03a0fd1SRichard Henderson TCGv_i32 r_asi = tcg_constant_i32(da->asi); 1761c03a0fd1SRichard Henderson TCGv_i32 r_mop = tcg_constant_i32(da->memop | MO_ALIGN); 1762fcf5ef2aSThomas Huth 1763fcf5ef2aSThomas Huth save_state(dc); 1764fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64 1765ad75a51eSRichard Henderson gen_helper_ld_asi(dst, tcg_env, addr, r_asi, r_mop); 1766fcf5ef2aSThomas Huth #else 1767fcf5ef2aSThomas Huth { 1768fcf5ef2aSThomas Huth TCGv_i64 t64 = tcg_temp_new_i64(); 1769ad75a51eSRichard Henderson gen_helper_ld_asi(t64, tcg_env, addr, r_asi, r_mop); 1770fcf5ef2aSThomas Huth tcg_gen_trunc_i64_tl(dst, t64); 1771fcf5ef2aSThomas Huth } 1772fcf5ef2aSThomas Huth #endif 1773fcf5ef2aSThomas Huth } 1774fcf5ef2aSThomas Huth break; 1775fcf5ef2aSThomas Huth } 1776fcf5ef2aSThomas Huth } 1777fcf5ef2aSThomas Huth 177842071fc1SRichard Henderson static void gen_st_asi(DisasContext *dc, DisasASI *da, TCGv src, TCGv addr) 1779c03a0fd1SRichard Henderson { 1780c03a0fd1SRichard Henderson switch (da->type) { 1781fcf5ef2aSThomas Huth case GET_ASI_EXCP: 1782fcf5ef2aSThomas Huth break; 1783c03a0fd1SRichard Henderson 1784fcf5ef2aSThomas Huth case GET_ASI_DTWINX: /* Reserved for stda. */ 1785c03a0fd1SRichard Henderson if (TARGET_LONG_BITS == 32) { 1786fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 1787fcf5ef2aSThomas Huth break; 1788c03a0fd1SRichard Henderson } else if (!(dc->def->features & CPU_FEATURE_HYPV)) { 17893390537bSArtyom Tarasenko /* Pre OpenSPARC CPUs don't have these */ 17903390537bSArtyom Tarasenko gen_exception(dc, TT_ILL_INSN); 1791fcf5ef2aSThomas Huth break; 1792c03a0fd1SRichard Henderson } 1793c03a0fd1SRichard Henderson /* In OpenSPARC T1+ CPUs TWINX ASIs in store are ST_BLKINIT_ ASIs */ 1794c03a0fd1SRichard Henderson /* fall through */ 1795c03a0fd1SRichard Henderson 1796c03a0fd1SRichard Henderson case GET_ASI_DIRECT: 1797c03a0fd1SRichard Henderson tcg_gen_qemu_st_tl(src, addr, da->mem_idx, da->memop | MO_ALIGN); 1798c03a0fd1SRichard Henderson break; 1799c03a0fd1SRichard Henderson 1800fcf5ef2aSThomas Huth case GET_ASI_BCOPY: 1801c03a0fd1SRichard Henderson assert(TARGET_LONG_BITS == 32); 180298271007SRichard Henderson /* 180398271007SRichard Henderson * Copy 32 bytes from the address in SRC to ADDR. 180498271007SRichard Henderson * 180598271007SRichard Henderson * From Ross RT625 hyperSPARC manual, section 4.6: 180698271007SRichard Henderson * "Block Copy and Block Fill will work only on cache line boundaries." 180798271007SRichard Henderson * 180898271007SRichard Henderson * It does not specify if an unaliged address is truncated or trapped. 180998271007SRichard Henderson * Previous qemu behaviour was to truncate to 4 byte alignment, which 181098271007SRichard Henderson * is obviously wrong. The only place I can see this used is in the 181198271007SRichard Henderson * Linux kernel which begins with page alignment, advancing by 32, 181298271007SRichard Henderson * so is always aligned. Assume truncation as the simpler option. 181398271007SRichard Henderson * 181498271007SRichard Henderson * Since the loads and stores are paired, allow the copy to happen 181598271007SRichard Henderson * in the host endianness. The copy need not be atomic. 181698271007SRichard Henderson */ 1817fcf5ef2aSThomas Huth { 181898271007SRichard Henderson MemOp mop = MO_128 | MO_ATOM_IFALIGN_PAIR; 1819fcf5ef2aSThomas Huth TCGv saddr = tcg_temp_new(); 1820fcf5ef2aSThomas Huth TCGv daddr = tcg_temp_new(); 182198271007SRichard Henderson TCGv_i128 tmp = tcg_temp_new_i128(); 1822fcf5ef2aSThomas Huth 182398271007SRichard Henderson tcg_gen_andi_tl(saddr, src, -32); 182498271007SRichard Henderson tcg_gen_andi_tl(daddr, addr, -32); 182598271007SRichard Henderson tcg_gen_qemu_ld_i128(tmp, saddr, da->mem_idx, mop); 182698271007SRichard Henderson tcg_gen_qemu_st_i128(tmp, daddr, da->mem_idx, mop); 182798271007SRichard Henderson tcg_gen_addi_tl(saddr, saddr, 16); 182898271007SRichard Henderson tcg_gen_addi_tl(daddr, daddr, 16); 182998271007SRichard Henderson tcg_gen_qemu_ld_i128(tmp, saddr, da->mem_idx, mop); 183098271007SRichard Henderson tcg_gen_qemu_st_i128(tmp, daddr, da->mem_idx, mop); 1831fcf5ef2aSThomas Huth } 1832fcf5ef2aSThomas Huth break; 1833c03a0fd1SRichard Henderson 1834fcf5ef2aSThomas Huth default: 1835fcf5ef2aSThomas Huth { 1836c03a0fd1SRichard Henderson TCGv_i32 r_asi = tcg_constant_i32(da->asi); 1837c03a0fd1SRichard Henderson TCGv_i32 r_mop = tcg_constant_i32(da->memop | MO_ALIGN); 1838fcf5ef2aSThomas Huth 1839fcf5ef2aSThomas Huth save_state(dc); 1840fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64 1841ad75a51eSRichard Henderson gen_helper_st_asi(tcg_env, addr, src, r_asi, r_mop); 1842fcf5ef2aSThomas Huth #else 1843fcf5ef2aSThomas Huth { 1844fcf5ef2aSThomas Huth TCGv_i64 t64 = tcg_temp_new_i64(); 1845fcf5ef2aSThomas Huth tcg_gen_extu_tl_i64(t64, src); 1846ad75a51eSRichard Henderson gen_helper_st_asi(tcg_env, addr, t64, r_asi, r_mop); 1847fcf5ef2aSThomas Huth } 1848fcf5ef2aSThomas Huth #endif 1849fcf5ef2aSThomas Huth 1850fcf5ef2aSThomas Huth /* A write to a TLB register may alter page maps. End the TB. */ 1851fcf5ef2aSThomas Huth dc->npc = DYNAMIC_PC; 1852fcf5ef2aSThomas Huth } 1853fcf5ef2aSThomas Huth break; 1854fcf5ef2aSThomas Huth } 1855fcf5ef2aSThomas Huth } 1856fcf5ef2aSThomas Huth 1857dca544b9SRichard Henderson static void gen_swap_asi(DisasContext *dc, DisasASI *da, 1858c03a0fd1SRichard Henderson TCGv dst, TCGv src, TCGv addr) 1859c03a0fd1SRichard Henderson { 1860c03a0fd1SRichard Henderson switch (da->type) { 1861c03a0fd1SRichard Henderson case GET_ASI_EXCP: 1862c03a0fd1SRichard Henderson break; 1863c03a0fd1SRichard Henderson case GET_ASI_DIRECT: 1864dca544b9SRichard Henderson tcg_gen_atomic_xchg_tl(dst, addr, src, 1865dca544b9SRichard Henderson da->mem_idx, da->memop | MO_ALIGN); 1866c03a0fd1SRichard Henderson break; 1867c03a0fd1SRichard Henderson default: 1868c03a0fd1SRichard Henderson /* ??? Should be DAE_invalid_asi. */ 1869c03a0fd1SRichard Henderson gen_exception(dc, TT_DATA_ACCESS); 1870c03a0fd1SRichard Henderson break; 1871c03a0fd1SRichard Henderson } 1872c03a0fd1SRichard Henderson } 1873c03a0fd1SRichard Henderson 1874d0a11d25SRichard Henderson static void gen_cas_asi(DisasContext *dc, DisasASI *da, 1875c03a0fd1SRichard Henderson TCGv oldv, TCGv newv, TCGv cmpv, TCGv addr) 1876c03a0fd1SRichard Henderson { 1877c03a0fd1SRichard Henderson switch (da->type) { 1878fcf5ef2aSThomas Huth case GET_ASI_EXCP: 1879c03a0fd1SRichard Henderson return; 1880fcf5ef2aSThomas Huth case GET_ASI_DIRECT: 1881c03a0fd1SRichard Henderson tcg_gen_atomic_cmpxchg_tl(oldv, addr, cmpv, newv, 1882c03a0fd1SRichard Henderson da->mem_idx, da->memop | MO_ALIGN); 1883fcf5ef2aSThomas Huth break; 1884fcf5ef2aSThomas Huth default: 1885fcf5ef2aSThomas Huth /* ??? Should be DAE_invalid_asi. */ 1886fcf5ef2aSThomas Huth gen_exception(dc, TT_DATA_ACCESS); 1887fcf5ef2aSThomas Huth break; 1888fcf5ef2aSThomas Huth } 1889fcf5ef2aSThomas Huth } 1890fcf5ef2aSThomas Huth 1891cf07cd1eSRichard Henderson static void gen_ldstub_asi(DisasContext *dc, DisasASI *da, TCGv dst, TCGv addr) 1892c03a0fd1SRichard Henderson { 1893c03a0fd1SRichard Henderson switch (da->type) { 1894fcf5ef2aSThomas Huth case GET_ASI_EXCP: 1895fcf5ef2aSThomas Huth break; 1896fcf5ef2aSThomas Huth case GET_ASI_DIRECT: 1897cf07cd1eSRichard Henderson tcg_gen_atomic_xchg_tl(dst, addr, tcg_constant_tl(0xff), 1898cf07cd1eSRichard Henderson da->mem_idx, MO_UB); 1899fcf5ef2aSThomas Huth break; 1900fcf5ef2aSThomas Huth default: 19013db010c3SRichard Henderson /* ??? In theory, this should be raise DAE_invalid_asi. 19023db010c3SRichard Henderson But the SS-20 roms do ldstuba [%l0] #ASI_M_CTL, %o1. */ 1903af00be49SEmilio G. Cota if (tb_cflags(dc->base.tb) & CF_PARALLEL) { 1904ad75a51eSRichard Henderson gen_helper_exit_atomic(tcg_env); 19053db010c3SRichard Henderson } else { 1906c03a0fd1SRichard Henderson TCGv_i32 r_asi = tcg_constant_i32(da->asi); 190700ab7e61SRichard Henderson TCGv_i32 r_mop = tcg_constant_i32(MO_UB); 19083db010c3SRichard Henderson TCGv_i64 s64, t64; 19093db010c3SRichard Henderson 19103db010c3SRichard Henderson save_state(dc); 19113db010c3SRichard Henderson t64 = tcg_temp_new_i64(); 1912ad75a51eSRichard Henderson gen_helper_ld_asi(t64, tcg_env, addr, r_asi, r_mop); 19133db010c3SRichard Henderson 191400ab7e61SRichard Henderson s64 = tcg_constant_i64(0xff); 1915ad75a51eSRichard Henderson gen_helper_st_asi(tcg_env, addr, s64, r_asi, r_mop); 19163db010c3SRichard Henderson 19173db010c3SRichard Henderson tcg_gen_trunc_i64_tl(dst, t64); 19183db010c3SRichard Henderson 19193db010c3SRichard Henderson /* End the TB. */ 19203db010c3SRichard Henderson dc->npc = DYNAMIC_PC; 19213db010c3SRichard Henderson } 1922fcf5ef2aSThomas Huth break; 1923fcf5ef2aSThomas Huth } 1924fcf5ef2aSThomas Huth } 1925fcf5ef2aSThomas Huth 1926287b1152SRichard Henderson static void gen_ldf_asi(DisasContext *dc, DisasASI *da, MemOp orig_size, 19273259b9e2SRichard Henderson TCGv addr, int rd) 1928fcf5ef2aSThomas Huth { 19293259b9e2SRichard Henderson MemOp memop = da->memop; 19303259b9e2SRichard Henderson MemOp size = memop & MO_SIZE; 1931fcf5ef2aSThomas Huth TCGv_i32 d32; 19321210a036SRichard Henderson TCGv_i64 d64, l64; 1933287b1152SRichard Henderson TCGv addr_tmp; 1934fcf5ef2aSThomas Huth 19353259b9e2SRichard Henderson /* TODO: Use 128-bit load/store below. */ 19363259b9e2SRichard Henderson if (size == MO_128) { 19373259b9e2SRichard Henderson memop = (memop & ~MO_SIZE) | MO_64; 19383259b9e2SRichard Henderson } 19393259b9e2SRichard Henderson 19403259b9e2SRichard Henderson switch (da->type) { 1941fcf5ef2aSThomas Huth case GET_ASI_EXCP: 1942fcf5ef2aSThomas Huth break; 1943fcf5ef2aSThomas Huth 1944fcf5ef2aSThomas Huth case GET_ASI_DIRECT: 19453259b9e2SRichard Henderson memop |= MO_ALIGN_4; 1946fcf5ef2aSThomas Huth switch (size) { 19473259b9e2SRichard Henderson case MO_32: 1948388a6465SRichard Henderson d32 = tcg_temp_new_i32(); 19493259b9e2SRichard Henderson tcg_gen_qemu_ld_i32(d32, addr, da->mem_idx, memop); 1950fcf5ef2aSThomas Huth gen_store_fpr_F(dc, rd, d32); 1951fcf5ef2aSThomas Huth break; 19523259b9e2SRichard Henderson 19533259b9e2SRichard Henderson case MO_64: 19541210a036SRichard Henderson d64 = tcg_temp_new_i64(); 19551210a036SRichard Henderson tcg_gen_qemu_ld_i64(d64, addr, da->mem_idx, memop); 19561210a036SRichard Henderson gen_store_fpr_D(dc, rd, d64); 1957fcf5ef2aSThomas Huth break; 19583259b9e2SRichard Henderson 19593259b9e2SRichard Henderson case MO_128: 1960fcf5ef2aSThomas Huth d64 = tcg_temp_new_i64(); 19611210a036SRichard Henderson l64 = tcg_temp_new_i64(); 19623259b9e2SRichard Henderson tcg_gen_qemu_ld_i64(d64, addr, da->mem_idx, memop); 1963287b1152SRichard Henderson addr_tmp = tcg_temp_new(); 1964287b1152SRichard Henderson tcg_gen_addi_tl(addr_tmp, addr, 8); 19651210a036SRichard Henderson tcg_gen_qemu_ld_i64(l64, addr_tmp, da->mem_idx, memop); 19661210a036SRichard Henderson gen_store_fpr_D(dc, rd, d64); 19671210a036SRichard Henderson gen_store_fpr_D(dc, rd + 2, l64); 1968fcf5ef2aSThomas Huth break; 1969fcf5ef2aSThomas Huth default: 1970fcf5ef2aSThomas Huth g_assert_not_reached(); 1971fcf5ef2aSThomas Huth } 1972fcf5ef2aSThomas Huth break; 1973fcf5ef2aSThomas Huth 1974fcf5ef2aSThomas Huth case GET_ASI_BLOCK: 1975fcf5ef2aSThomas Huth /* Valid for lddfa on aligned registers only. */ 19763259b9e2SRichard Henderson if (orig_size == MO_64 && (rd & 7) == 0) { 1977fcf5ef2aSThomas Huth /* The first operation checks required alignment. */ 1978287b1152SRichard Henderson addr_tmp = tcg_temp_new(); 19791210a036SRichard Henderson d64 = tcg_temp_new_i64(); 1980287b1152SRichard Henderson for (int i = 0; ; ++i) { 19811210a036SRichard Henderson tcg_gen_qemu_ld_i64(d64, addr, da->mem_idx, 19823259b9e2SRichard Henderson memop | (i == 0 ? MO_ALIGN_64 : 0)); 19831210a036SRichard Henderson gen_store_fpr_D(dc, rd + 2 * i, d64); 1984fcf5ef2aSThomas Huth if (i == 7) { 1985fcf5ef2aSThomas Huth break; 1986fcf5ef2aSThomas Huth } 1987287b1152SRichard Henderson tcg_gen_addi_tl(addr_tmp, addr, 8); 1988287b1152SRichard Henderson addr = addr_tmp; 1989fcf5ef2aSThomas Huth } 1990fcf5ef2aSThomas Huth } else { 1991fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 1992fcf5ef2aSThomas Huth } 1993fcf5ef2aSThomas Huth break; 1994fcf5ef2aSThomas Huth 1995fcf5ef2aSThomas Huth case GET_ASI_SHORT: 1996fcf5ef2aSThomas Huth /* Valid for lddfa only. */ 19973259b9e2SRichard Henderson if (orig_size == MO_64) { 19981210a036SRichard Henderson d64 = tcg_temp_new_i64(); 19991210a036SRichard Henderson tcg_gen_qemu_ld_i64(d64, addr, da->mem_idx, memop | MO_ALIGN); 20001210a036SRichard Henderson gen_store_fpr_D(dc, rd, d64); 2001fcf5ef2aSThomas Huth } else { 2002fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 2003fcf5ef2aSThomas Huth } 2004fcf5ef2aSThomas Huth break; 2005fcf5ef2aSThomas Huth 2006fcf5ef2aSThomas Huth default: 2007fcf5ef2aSThomas Huth { 20083259b9e2SRichard Henderson TCGv_i32 r_asi = tcg_constant_i32(da->asi); 20093259b9e2SRichard Henderson TCGv_i32 r_mop = tcg_constant_i32(memop | MO_ALIGN); 2010fcf5ef2aSThomas Huth 2011fcf5ef2aSThomas Huth save_state(dc); 2012fcf5ef2aSThomas Huth /* According to the table in the UA2011 manual, the only 2013fcf5ef2aSThomas Huth other asis that are valid for ldfa/lddfa/ldqfa are 2014fcf5ef2aSThomas Huth the NO_FAULT asis. We still need a helper for these, 2015fcf5ef2aSThomas Huth but we can just use the integer asi helper for them. */ 2016fcf5ef2aSThomas Huth switch (size) { 20173259b9e2SRichard Henderson case MO_32: 2018fcf5ef2aSThomas Huth d64 = tcg_temp_new_i64(); 2019ad75a51eSRichard Henderson gen_helper_ld_asi(d64, tcg_env, addr, r_asi, r_mop); 2020388a6465SRichard Henderson d32 = tcg_temp_new_i32(); 2021fcf5ef2aSThomas Huth tcg_gen_extrl_i64_i32(d32, d64); 2022fcf5ef2aSThomas Huth gen_store_fpr_F(dc, rd, d32); 2023fcf5ef2aSThomas Huth break; 20243259b9e2SRichard Henderson case MO_64: 20251210a036SRichard Henderson d64 = tcg_temp_new_i64(); 20261210a036SRichard Henderson gen_helper_ld_asi(d64, tcg_env, addr, r_asi, r_mop); 20271210a036SRichard Henderson gen_store_fpr_D(dc, rd, d64); 2028fcf5ef2aSThomas Huth break; 20293259b9e2SRichard Henderson case MO_128: 2030fcf5ef2aSThomas Huth d64 = tcg_temp_new_i64(); 20311210a036SRichard Henderson l64 = tcg_temp_new_i64(); 2032ad75a51eSRichard Henderson gen_helper_ld_asi(d64, tcg_env, addr, r_asi, r_mop); 2033287b1152SRichard Henderson addr_tmp = tcg_temp_new(); 2034287b1152SRichard Henderson tcg_gen_addi_tl(addr_tmp, addr, 8); 20351210a036SRichard Henderson gen_helper_ld_asi(l64, tcg_env, addr_tmp, r_asi, r_mop); 20361210a036SRichard Henderson gen_store_fpr_D(dc, rd, d64); 20371210a036SRichard Henderson gen_store_fpr_D(dc, rd + 2, l64); 2038fcf5ef2aSThomas Huth break; 2039fcf5ef2aSThomas Huth default: 2040fcf5ef2aSThomas Huth g_assert_not_reached(); 2041fcf5ef2aSThomas Huth } 2042fcf5ef2aSThomas Huth } 2043fcf5ef2aSThomas Huth break; 2044fcf5ef2aSThomas Huth } 2045fcf5ef2aSThomas Huth } 2046fcf5ef2aSThomas Huth 2047287b1152SRichard Henderson static void gen_stf_asi(DisasContext *dc, DisasASI *da, MemOp orig_size, 20483259b9e2SRichard Henderson TCGv addr, int rd) 20493259b9e2SRichard Henderson { 20503259b9e2SRichard Henderson MemOp memop = da->memop; 20513259b9e2SRichard Henderson MemOp size = memop & MO_SIZE; 2052fcf5ef2aSThomas Huth TCGv_i32 d32; 20531210a036SRichard Henderson TCGv_i64 d64; 2054287b1152SRichard Henderson TCGv addr_tmp; 2055fcf5ef2aSThomas Huth 20563259b9e2SRichard Henderson /* TODO: Use 128-bit load/store below. */ 20573259b9e2SRichard Henderson if (size == MO_128) { 20583259b9e2SRichard Henderson memop = (memop & ~MO_SIZE) | MO_64; 20593259b9e2SRichard Henderson } 20603259b9e2SRichard Henderson 20613259b9e2SRichard Henderson switch (da->type) { 2062fcf5ef2aSThomas Huth case GET_ASI_EXCP: 2063fcf5ef2aSThomas Huth break; 2064fcf5ef2aSThomas Huth 2065fcf5ef2aSThomas Huth case GET_ASI_DIRECT: 20663259b9e2SRichard Henderson memop |= MO_ALIGN_4; 2067fcf5ef2aSThomas Huth switch (size) { 20683259b9e2SRichard Henderson case MO_32: 2069fcf5ef2aSThomas Huth d32 = gen_load_fpr_F(dc, rd); 20703259b9e2SRichard Henderson tcg_gen_qemu_st_i32(d32, addr, da->mem_idx, memop | MO_ALIGN); 2071fcf5ef2aSThomas Huth break; 20723259b9e2SRichard Henderson case MO_64: 20731210a036SRichard Henderson d64 = gen_load_fpr_D(dc, rd); 20741210a036SRichard Henderson tcg_gen_qemu_st_i64(d64, addr, da->mem_idx, memop | MO_ALIGN_4); 2075fcf5ef2aSThomas Huth break; 20763259b9e2SRichard Henderson case MO_128: 2077fcf5ef2aSThomas Huth /* Only 4-byte alignment required. However, it is legal for the 2078fcf5ef2aSThomas Huth cpu to signal the alignment fault, and the OS trap handler is 2079fcf5ef2aSThomas Huth required to fix it up. Requiring 16-byte alignment here avoids 2080fcf5ef2aSThomas Huth having to probe the second page before performing the first 2081fcf5ef2aSThomas Huth write. */ 20821210a036SRichard Henderson d64 = gen_load_fpr_D(dc, rd); 20831210a036SRichard Henderson tcg_gen_qemu_st_i64(d64, addr, da->mem_idx, memop | MO_ALIGN_16); 2084287b1152SRichard Henderson addr_tmp = tcg_temp_new(); 2085287b1152SRichard Henderson tcg_gen_addi_tl(addr_tmp, addr, 8); 20861210a036SRichard Henderson d64 = gen_load_fpr_D(dc, rd + 2); 20871210a036SRichard Henderson tcg_gen_qemu_st_i64(d64, addr_tmp, da->mem_idx, memop); 2088fcf5ef2aSThomas Huth break; 2089fcf5ef2aSThomas Huth default: 2090fcf5ef2aSThomas Huth g_assert_not_reached(); 2091fcf5ef2aSThomas Huth } 2092fcf5ef2aSThomas Huth break; 2093fcf5ef2aSThomas Huth 2094fcf5ef2aSThomas Huth case GET_ASI_BLOCK: 2095fcf5ef2aSThomas Huth /* Valid for stdfa on aligned registers only. */ 20963259b9e2SRichard Henderson if (orig_size == MO_64 && (rd & 7) == 0) { 2097fcf5ef2aSThomas Huth /* The first operation checks required alignment. */ 2098287b1152SRichard Henderson addr_tmp = tcg_temp_new(); 2099287b1152SRichard Henderson for (int i = 0; ; ++i) { 21001210a036SRichard Henderson d64 = gen_load_fpr_D(dc, rd + 2 * i); 21011210a036SRichard Henderson tcg_gen_qemu_st_i64(d64, addr, da->mem_idx, 21023259b9e2SRichard Henderson memop | (i == 0 ? MO_ALIGN_64 : 0)); 2103fcf5ef2aSThomas Huth if (i == 7) { 2104fcf5ef2aSThomas Huth break; 2105fcf5ef2aSThomas Huth } 2106287b1152SRichard Henderson tcg_gen_addi_tl(addr_tmp, addr, 8); 2107287b1152SRichard Henderson addr = addr_tmp; 2108fcf5ef2aSThomas Huth } 2109fcf5ef2aSThomas Huth } else { 2110fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 2111fcf5ef2aSThomas Huth } 2112fcf5ef2aSThomas Huth break; 2113fcf5ef2aSThomas Huth 2114fcf5ef2aSThomas Huth case GET_ASI_SHORT: 2115fcf5ef2aSThomas Huth /* Valid for stdfa only. */ 21163259b9e2SRichard Henderson if (orig_size == MO_64) { 21171210a036SRichard Henderson d64 = gen_load_fpr_D(dc, rd); 21181210a036SRichard Henderson tcg_gen_qemu_st_i64(d64, addr, da->mem_idx, memop | MO_ALIGN); 2119fcf5ef2aSThomas Huth } else { 2120fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 2121fcf5ef2aSThomas Huth } 2122fcf5ef2aSThomas Huth break; 2123fcf5ef2aSThomas Huth 2124fcf5ef2aSThomas Huth default: 2125fcf5ef2aSThomas Huth /* According to the table in the UA2011 manual, the only 2126fcf5ef2aSThomas Huth other asis that are valid for ldfa/lddfa/ldqfa are 2127fcf5ef2aSThomas Huth the PST* asis, which aren't currently handled. */ 2128fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 2129fcf5ef2aSThomas Huth break; 2130fcf5ef2aSThomas Huth } 2131fcf5ef2aSThomas Huth } 2132fcf5ef2aSThomas Huth 213342071fc1SRichard Henderson static void gen_ldda_asi(DisasContext *dc, DisasASI *da, TCGv addr, int rd) 2134fcf5ef2aSThomas Huth { 2135a76779eeSRichard Henderson TCGv hi = gen_dest_gpr(dc, rd); 2136a76779eeSRichard Henderson TCGv lo = gen_dest_gpr(dc, rd + 1); 2137fcf5ef2aSThomas Huth 2138c03a0fd1SRichard Henderson switch (da->type) { 2139fcf5ef2aSThomas Huth case GET_ASI_EXCP: 2140fcf5ef2aSThomas Huth return; 2141fcf5ef2aSThomas Huth 2142fcf5ef2aSThomas Huth case GET_ASI_DTWINX: 2143ebbbec92SRichard Henderson #ifdef TARGET_SPARC64 2144ebbbec92SRichard Henderson { 2145ebbbec92SRichard Henderson MemOp mop = (da->memop & MO_BSWAP) | MO_128 | MO_ALIGN_16; 2146ebbbec92SRichard Henderson TCGv_i128 t = tcg_temp_new_i128(); 2147ebbbec92SRichard Henderson 2148ebbbec92SRichard Henderson tcg_gen_qemu_ld_i128(t, addr, da->mem_idx, mop); 2149ebbbec92SRichard Henderson /* 2150ebbbec92SRichard Henderson * Note that LE twinx acts as if each 64-bit register result is 2151ebbbec92SRichard Henderson * byte swapped. We perform one 128-bit LE load, so must swap 2152ebbbec92SRichard Henderson * the order of the writebacks. 2153ebbbec92SRichard Henderson */ 2154ebbbec92SRichard Henderson if ((mop & MO_BSWAP) == MO_TE) { 2155ebbbec92SRichard Henderson tcg_gen_extr_i128_i64(lo, hi, t); 2156ebbbec92SRichard Henderson } else { 2157ebbbec92SRichard Henderson tcg_gen_extr_i128_i64(hi, lo, t); 2158ebbbec92SRichard Henderson } 2159ebbbec92SRichard Henderson } 2160fcf5ef2aSThomas Huth break; 2161ebbbec92SRichard Henderson #else 2162ebbbec92SRichard Henderson g_assert_not_reached(); 2163ebbbec92SRichard Henderson #endif 2164fcf5ef2aSThomas Huth 2165fcf5ef2aSThomas Huth case GET_ASI_DIRECT: 2166fcf5ef2aSThomas Huth { 2167fcf5ef2aSThomas Huth TCGv_i64 tmp = tcg_temp_new_i64(); 2168fcf5ef2aSThomas Huth 2169c03a0fd1SRichard Henderson tcg_gen_qemu_ld_i64(tmp, addr, da->mem_idx, da->memop | MO_ALIGN); 2170fcf5ef2aSThomas Huth 2171fcf5ef2aSThomas Huth /* Note that LE ldda acts as if each 32-bit register 2172fcf5ef2aSThomas Huth result is byte swapped. Having just performed one 2173fcf5ef2aSThomas Huth 64-bit bswap, we need now to swap the writebacks. */ 2174c03a0fd1SRichard Henderson if ((da->memop & MO_BSWAP) == MO_TE) { 2175a76779eeSRichard Henderson tcg_gen_extr_i64_tl(lo, hi, tmp); 2176fcf5ef2aSThomas Huth } else { 2177a76779eeSRichard Henderson tcg_gen_extr_i64_tl(hi, lo, tmp); 2178fcf5ef2aSThomas Huth } 2179fcf5ef2aSThomas Huth } 2180fcf5ef2aSThomas Huth break; 2181fcf5ef2aSThomas Huth 21822786a3f8SRichard Henderson case GET_ASI_CODE: 21832786a3f8SRichard Henderson #if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64) 21842786a3f8SRichard Henderson { 21852786a3f8SRichard Henderson MemOpIdx oi = make_memop_idx(da->memop, da->mem_idx); 21862786a3f8SRichard Henderson TCGv_i64 tmp = tcg_temp_new_i64(); 21872786a3f8SRichard Henderson 21882786a3f8SRichard Henderson gen_helper_ld_code(tmp, tcg_env, addr, tcg_constant_i32(oi)); 21892786a3f8SRichard Henderson 21902786a3f8SRichard Henderson /* See above. */ 21912786a3f8SRichard Henderson if ((da->memop & MO_BSWAP) == MO_TE) { 21922786a3f8SRichard Henderson tcg_gen_extr_i64_tl(lo, hi, tmp); 21932786a3f8SRichard Henderson } else { 21942786a3f8SRichard Henderson tcg_gen_extr_i64_tl(hi, lo, tmp); 21952786a3f8SRichard Henderson } 21962786a3f8SRichard Henderson } 21972786a3f8SRichard Henderson break; 21982786a3f8SRichard Henderson #else 21992786a3f8SRichard Henderson g_assert_not_reached(); 22002786a3f8SRichard Henderson #endif 22012786a3f8SRichard Henderson 2202fcf5ef2aSThomas Huth default: 2203fcf5ef2aSThomas Huth /* ??? In theory we've handled all of the ASIs that are valid 2204fcf5ef2aSThomas Huth for ldda, and this should raise DAE_invalid_asi. However, 2205fcf5ef2aSThomas Huth real hardware allows others. This can be seen with e.g. 2206fcf5ef2aSThomas Huth FreeBSD 10.3 wrt ASI_IC_TAG. */ 2207fcf5ef2aSThomas Huth { 2208c03a0fd1SRichard Henderson TCGv_i32 r_asi = tcg_constant_i32(da->asi); 2209c03a0fd1SRichard Henderson TCGv_i32 r_mop = tcg_constant_i32(da->memop); 2210fcf5ef2aSThomas Huth TCGv_i64 tmp = tcg_temp_new_i64(); 2211fcf5ef2aSThomas Huth 2212fcf5ef2aSThomas Huth save_state(dc); 2213ad75a51eSRichard Henderson gen_helper_ld_asi(tmp, tcg_env, addr, r_asi, r_mop); 2214fcf5ef2aSThomas Huth 2215fcf5ef2aSThomas Huth /* See above. */ 2216c03a0fd1SRichard Henderson if ((da->memop & MO_BSWAP) == MO_TE) { 2217a76779eeSRichard Henderson tcg_gen_extr_i64_tl(lo, hi, tmp); 2218fcf5ef2aSThomas Huth } else { 2219a76779eeSRichard Henderson tcg_gen_extr_i64_tl(hi, lo, tmp); 2220fcf5ef2aSThomas Huth } 2221fcf5ef2aSThomas Huth } 2222fcf5ef2aSThomas Huth break; 2223fcf5ef2aSThomas Huth } 2224fcf5ef2aSThomas Huth 2225fcf5ef2aSThomas Huth gen_store_gpr(dc, rd, hi); 2226fcf5ef2aSThomas Huth gen_store_gpr(dc, rd + 1, lo); 2227fcf5ef2aSThomas Huth } 2228fcf5ef2aSThomas Huth 222942071fc1SRichard Henderson static void gen_stda_asi(DisasContext *dc, DisasASI *da, TCGv addr, int rd) 2230c03a0fd1SRichard Henderson { 2231c03a0fd1SRichard Henderson TCGv hi = gen_load_gpr(dc, rd); 2232fcf5ef2aSThomas Huth TCGv lo = gen_load_gpr(dc, rd + 1); 2233fcf5ef2aSThomas Huth 2234c03a0fd1SRichard Henderson switch (da->type) { 2235fcf5ef2aSThomas Huth case GET_ASI_EXCP: 2236fcf5ef2aSThomas Huth break; 2237fcf5ef2aSThomas Huth 2238fcf5ef2aSThomas Huth case GET_ASI_DTWINX: 2239ebbbec92SRichard Henderson #ifdef TARGET_SPARC64 2240ebbbec92SRichard Henderson { 2241ebbbec92SRichard Henderson MemOp mop = (da->memop & MO_BSWAP) | MO_128 | MO_ALIGN_16; 2242ebbbec92SRichard Henderson TCGv_i128 t = tcg_temp_new_i128(); 2243ebbbec92SRichard Henderson 2244ebbbec92SRichard Henderson /* 2245ebbbec92SRichard Henderson * Note that LE twinx acts as if each 64-bit register result is 2246ebbbec92SRichard Henderson * byte swapped. We perform one 128-bit LE store, so must swap 2247ebbbec92SRichard Henderson * the order of the construction. 2248ebbbec92SRichard Henderson */ 2249ebbbec92SRichard Henderson if ((mop & MO_BSWAP) == MO_TE) { 2250ebbbec92SRichard Henderson tcg_gen_concat_i64_i128(t, lo, hi); 2251ebbbec92SRichard Henderson } else { 2252ebbbec92SRichard Henderson tcg_gen_concat_i64_i128(t, hi, lo); 2253ebbbec92SRichard Henderson } 2254ebbbec92SRichard Henderson tcg_gen_qemu_st_i128(t, addr, da->mem_idx, mop); 2255ebbbec92SRichard Henderson } 2256fcf5ef2aSThomas Huth break; 2257ebbbec92SRichard Henderson #else 2258ebbbec92SRichard Henderson g_assert_not_reached(); 2259ebbbec92SRichard Henderson #endif 2260fcf5ef2aSThomas Huth 2261fcf5ef2aSThomas Huth case GET_ASI_DIRECT: 2262fcf5ef2aSThomas Huth { 2263fcf5ef2aSThomas Huth TCGv_i64 t64 = tcg_temp_new_i64(); 2264fcf5ef2aSThomas Huth 2265fcf5ef2aSThomas Huth /* Note that LE stda acts as if each 32-bit register result is 2266fcf5ef2aSThomas Huth byte swapped. We will perform one 64-bit LE store, so now 2267fcf5ef2aSThomas Huth we must swap the order of the construction. */ 2268c03a0fd1SRichard Henderson if ((da->memop & MO_BSWAP) == MO_TE) { 2269a76779eeSRichard Henderson tcg_gen_concat_tl_i64(t64, lo, hi); 2270fcf5ef2aSThomas Huth } else { 2271a76779eeSRichard Henderson tcg_gen_concat_tl_i64(t64, hi, lo); 2272fcf5ef2aSThomas Huth } 2273c03a0fd1SRichard Henderson tcg_gen_qemu_st_i64(t64, addr, da->mem_idx, da->memop | MO_ALIGN); 2274fcf5ef2aSThomas Huth } 2275fcf5ef2aSThomas Huth break; 2276fcf5ef2aSThomas Huth 2277a76779eeSRichard Henderson case GET_ASI_BFILL: 2278a76779eeSRichard Henderson assert(TARGET_LONG_BITS == 32); 227954c3e953SRichard Henderson /* 228054c3e953SRichard Henderson * Store 32 bytes of [rd:rd+1] to ADDR. 228154c3e953SRichard Henderson * See comments for GET_ASI_COPY above. 228254c3e953SRichard Henderson */ 2283a76779eeSRichard Henderson { 228454c3e953SRichard Henderson MemOp mop = MO_TE | MO_128 | MO_ATOM_IFALIGN_PAIR; 228554c3e953SRichard Henderson TCGv_i64 t8 = tcg_temp_new_i64(); 228654c3e953SRichard Henderson TCGv_i128 t16 = tcg_temp_new_i128(); 228754c3e953SRichard Henderson TCGv daddr = tcg_temp_new(); 2288a76779eeSRichard Henderson 228954c3e953SRichard Henderson tcg_gen_concat_tl_i64(t8, lo, hi); 229054c3e953SRichard Henderson tcg_gen_concat_i64_i128(t16, t8, t8); 229154c3e953SRichard Henderson tcg_gen_andi_tl(daddr, addr, -32); 229254c3e953SRichard Henderson tcg_gen_qemu_st_i128(t16, daddr, da->mem_idx, mop); 229354c3e953SRichard Henderson tcg_gen_addi_tl(daddr, daddr, 16); 229454c3e953SRichard Henderson tcg_gen_qemu_st_i128(t16, daddr, da->mem_idx, mop); 2295a76779eeSRichard Henderson } 2296a76779eeSRichard Henderson break; 2297a76779eeSRichard Henderson 2298fcf5ef2aSThomas Huth default: 2299fcf5ef2aSThomas Huth /* ??? In theory we've handled all of the ASIs that are valid 2300fcf5ef2aSThomas Huth for stda, and this should raise DAE_invalid_asi. */ 2301fcf5ef2aSThomas Huth { 2302c03a0fd1SRichard Henderson TCGv_i32 r_asi = tcg_constant_i32(da->asi); 2303c03a0fd1SRichard Henderson TCGv_i32 r_mop = tcg_constant_i32(da->memop); 2304fcf5ef2aSThomas Huth TCGv_i64 t64 = tcg_temp_new_i64(); 2305fcf5ef2aSThomas Huth 2306fcf5ef2aSThomas Huth /* See above. */ 2307c03a0fd1SRichard Henderson if ((da->memop & MO_BSWAP) == MO_TE) { 2308a76779eeSRichard Henderson tcg_gen_concat_tl_i64(t64, lo, hi); 2309fcf5ef2aSThomas Huth } else { 2310a76779eeSRichard Henderson tcg_gen_concat_tl_i64(t64, hi, lo); 2311fcf5ef2aSThomas Huth } 2312fcf5ef2aSThomas Huth 2313fcf5ef2aSThomas Huth save_state(dc); 2314ad75a51eSRichard Henderson gen_helper_st_asi(tcg_env, addr, t64, r_asi, r_mop); 2315fcf5ef2aSThomas Huth } 2316fcf5ef2aSThomas Huth break; 2317fcf5ef2aSThomas Huth } 2318fcf5ef2aSThomas Huth } 2319fcf5ef2aSThomas Huth 2320fcf5ef2aSThomas Huth static void gen_fmovs(DisasContext *dc, DisasCompare *cmp, int rd, int rs) 2321fcf5ef2aSThomas Huth { 2322f7ec8155SRichard Henderson #ifdef TARGET_SPARC64 2323fcf5ef2aSThomas Huth TCGv_i32 c32, zero, dst, s1, s2; 2324dd7dbfccSRichard Henderson TCGv_i64 c64 = tcg_temp_new_i64(); 2325fcf5ef2aSThomas Huth 2326fcf5ef2aSThomas Huth /* We have two choices here: extend the 32 bit data and use movcond_i64, 2327fcf5ef2aSThomas Huth or fold the comparison down to 32 bits and use movcond_i32. Choose 2328fcf5ef2aSThomas Huth the later. */ 2329fcf5ef2aSThomas Huth c32 = tcg_temp_new_i32(); 2330c8507ebfSRichard Henderson tcg_gen_setcondi_i64(cmp->cond, c64, cmp->c1, cmp->c2); 2331fcf5ef2aSThomas Huth tcg_gen_extrl_i64_i32(c32, c64); 2332fcf5ef2aSThomas Huth 2333fcf5ef2aSThomas Huth s1 = gen_load_fpr_F(dc, rs); 2334fcf5ef2aSThomas Huth s2 = gen_load_fpr_F(dc, rd); 2335388a6465SRichard Henderson dst = tcg_temp_new_i32(); 233600ab7e61SRichard Henderson zero = tcg_constant_i32(0); 2337fcf5ef2aSThomas Huth 2338fcf5ef2aSThomas Huth tcg_gen_movcond_i32(TCG_COND_NE, dst, c32, zero, s1, s2); 2339fcf5ef2aSThomas Huth 2340fcf5ef2aSThomas Huth gen_store_fpr_F(dc, rd, dst); 2341f7ec8155SRichard Henderson #else 2342f7ec8155SRichard Henderson qemu_build_not_reached(); 2343f7ec8155SRichard Henderson #endif 2344fcf5ef2aSThomas Huth } 2345fcf5ef2aSThomas Huth 2346fcf5ef2aSThomas Huth static void gen_fmovd(DisasContext *dc, DisasCompare *cmp, int rd, int rs) 2347fcf5ef2aSThomas Huth { 2348f7ec8155SRichard Henderson #ifdef TARGET_SPARC64 234952f46d46SRichard Henderson TCGv_i64 dst = tcg_temp_new_i64(); 2350c8507ebfSRichard Henderson tcg_gen_movcond_i64(cmp->cond, dst, cmp->c1, tcg_constant_tl(cmp->c2), 2351fcf5ef2aSThomas Huth gen_load_fpr_D(dc, rs), 2352fcf5ef2aSThomas Huth gen_load_fpr_D(dc, rd)); 2353fcf5ef2aSThomas Huth gen_store_fpr_D(dc, rd, dst); 2354f7ec8155SRichard Henderson #else 2355f7ec8155SRichard Henderson qemu_build_not_reached(); 2356f7ec8155SRichard Henderson #endif 2357fcf5ef2aSThomas Huth } 2358fcf5ef2aSThomas Huth 2359fcf5ef2aSThomas Huth static void gen_fmovq(DisasContext *dc, DisasCompare *cmp, int rd, int rs) 2360fcf5ef2aSThomas Huth { 2361f7ec8155SRichard Henderson #ifdef TARGET_SPARC64 2362c8507ebfSRichard Henderson TCGv c2 = tcg_constant_tl(cmp->c2); 23631210a036SRichard Henderson TCGv_i64 h = tcg_temp_new_i64(); 23641210a036SRichard Henderson TCGv_i64 l = tcg_temp_new_i64(); 2365fcf5ef2aSThomas Huth 23661210a036SRichard Henderson tcg_gen_movcond_i64(cmp->cond, h, cmp->c1, c2, 23671210a036SRichard Henderson gen_load_fpr_D(dc, rs), 23681210a036SRichard Henderson gen_load_fpr_D(dc, rd)); 23691210a036SRichard Henderson tcg_gen_movcond_i64(cmp->cond, l, cmp->c1, c2, 23701210a036SRichard Henderson gen_load_fpr_D(dc, rs + 2), 23711210a036SRichard Henderson gen_load_fpr_D(dc, rd + 2)); 23721210a036SRichard Henderson gen_store_fpr_D(dc, rd, h); 23731210a036SRichard Henderson gen_store_fpr_D(dc, rd + 2, l); 2374f7ec8155SRichard Henderson #else 2375f7ec8155SRichard Henderson qemu_build_not_reached(); 2376f7ec8155SRichard Henderson #endif 2377fcf5ef2aSThomas Huth } 2378fcf5ef2aSThomas Huth 2379f7ec8155SRichard Henderson #ifdef TARGET_SPARC64 23805d617bfbSRichard Henderson static void gen_load_trap_state_at_tl(TCGv_ptr r_tsptr) 2381fcf5ef2aSThomas Huth { 2382fcf5ef2aSThomas Huth TCGv_i32 r_tl = tcg_temp_new_i32(); 2383fcf5ef2aSThomas Huth 2384fcf5ef2aSThomas Huth /* load env->tl into r_tl */ 2385ad75a51eSRichard Henderson tcg_gen_ld_i32(r_tl, tcg_env, offsetof(CPUSPARCState, tl)); 2386fcf5ef2aSThomas Huth 2387fcf5ef2aSThomas Huth /* tl = [0 ... MAXTL_MASK] where MAXTL_MASK must be power of 2 */ 2388fcf5ef2aSThomas Huth tcg_gen_andi_i32(r_tl, r_tl, MAXTL_MASK); 2389fcf5ef2aSThomas Huth 2390fcf5ef2aSThomas Huth /* calculate offset to current trap state from env->ts, reuse r_tl */ 2391fcf5ef2aSThomas Huth tcg_gen_muli_i32(r_tl, r_tl, sizeof (trap_state)); 2392ad75a51eSRichard Henderson tcg_gen_addi_ptr(r_tsptr, tcg_env, offsetof(CPUSPARCState, ts)); 2393fcf5ef2aSThomas Huth 2394fcf5ef2aSThomas Huth /* tsptr = env->ts[env->tl & MAXTL_MASK] */ 2395fcf5ef2aSThomas Huth { 2396fcf5ef2aSThomas Huth TCGv_ptr r_tl_tmp = tcg_temp_new_ptr(); 2397fcf5ef2aSThomas Huth tcg_gen_ext_i32_ptr(r_tl_tmp, r_tl); 2398fcf5ef2aSThomas Huth tcg_gen_add_ptr(r_tsptr, r_tsptr, r_tl_tmp); 2399fcf5ef2aSThomas Huth } 2400fcf5ef2aSThomas Huth } 2401fcf5ef2aSThomas Huth #endif 2402fcf5ef2aSThomas Huth 240306c060d9SRichard Henderson static int extract_dfpreg(DisasContext *dc, int x) 240406c060d9SRichard Henderson { 24050bba7572SRichard Henderson int r = x & 0x1e; 24060bba7572SRichard Henderson #ifdef TARGET_SPARC64 24070bba7572SRichard Henderson r |= (x & 1) << 5; 24080bba7572SRichard Henderson #endif 24090bba7572SRichard Henderson return r; 241006c060d9SRichard Henderson } 241106c060d9SRichard Henderson 241206c060d9SRichard Henderson static int extract_qfpreg(DisasContext *dc, int x) 241306c060d9SRichard Henderson { 24140bba7572SRichard Henderson int r = x & 0x1c; 24150bba7572SRichard Henderson #ifdef TARGET_SPARC64 24160bba7572SRichard Henderson r |= (x & 1) << 5; 24170bba7572SRichard Henderson #endif 24180bba7572SRichard Henderson return r; 241906c060d9SRichard Henderson } 242006c060d9SRichard Henderson 2421878cc677SRichard Henderson /* Include the auto-generated decoder. */ 2422878cc677SRichard Henderson #include "decode-insns.c.inc" 2423878cc677SRichard Henderson 2424878cc677SRichard Henderson #define TRANS(NAME, AVAIL, FUNC, ...) \ 2425878cc677SRichard Henderson static bool trans_##NAME(DisasContext *dc, arg_##NAME *a) \ 2426878cc677SRichard Henderson { return avail_##AVAIL(dc) && FUNC(dc, __VA_ARGS__); } 2427878cc677SRichard Henderson 2428878cc677SRichard Henderson #define avail_ALL(C) true 2429878cc677SRichard Henderson #ifdef TARGET_SPARC64 2430878cc677SRichard Henderson # define avail_32(C) false 2431af25071cSRichard Henderson # define avail_ASR17(C) false 2432d0a11d25SRichard Henderson # define avail_CASA(C) true 2433c2636853SRichard Henderson # define avail_DIV(C) true 2434b5372650SRichard Henderson # define avail_MUL(C) true 24350faef01bSRichard Henderson # define avail_POWERDOWN(C) false 2436878cc677SRichard Henderson # define avail_64(C) true 24374fd71d19SRichard Henderson # define avail_FMAF(C) ((C)->def->features & CPU_FEATURE_FMAF) 24385d617bfbSRichard Henderson # define avail_GL(C) ((C)->def->features & CPU_FEATURE_GL) 2439af25071cSRichard Henderson # define avail_HYPV(C) ((C)->def->features & CPU_FEATURE_HYPV) 244068a414e9SRichard Henderson # define avail_IMA(C) ((C)->def->features & CPU_FEATURE_IMA) 2441b88ce6f2SRichard Henderson # define avail_VIS1(C) ((C)->def->features & CPU_FEATURE_VIS1) 2442b88ce6f2SRichard Henderson # define avail_VIS2(C) ((C)->def->features & CPU_FEATURE_VIS2) 24433335a048SRichard Henderson # define avail_VIS3(C) ((C)->def->features & CPU_FEATURE_VIS3) 24443335a048SRichard Henderson # define avail_VIS3B(C) avail_VIS3(C) 244590b1433dSRichard Henderson # define avail_VIS4(C) ((C)->def->features & CPU_FEATURE_VIS4) 2446878cc677SRichard Henderson #else 2447878cc677SRichard Henderson # define avail_32(C) true 2448af25071cSRichard Henderson # define avail_ASR17(C) ((C)->def->features & CPU_FEATURE_ASR17) 2449d0a11d25SRichard Henderson # define avail_CASA(C) ((C)->def->features & CPU_FEATURE_CASA) 2450c2636853SRichard Henderson # define avail_DIV(C) ((C)->def->features & CPU_FEATURE_DIV) 2451b5372650SRichard Henderson # define avail_MUL(C) ((C)->def->features & CPU_FEATURE_MUL) 24520faef01bSRichard Henderson # define avail_POWERDOWN(C) ((C)->def->features & CPU_FEATURE_POWERDOWN) 2453878cc677SRichard Henderson # define avail_64(C) false 24544fd71d19SRichard Henderson # define avail_FMAF(C) false 24555d617bfbSRichard Henderson # define avail_GL(C) false 2456af25071cSRichard Henderson # define avail_HYPV(C) false 245768a414e9SRichard Henderson # define avail_IMA(C) false 2458b88ce6f2SRichard Henderson # define avail_VIS1(C) false 2459b88ce6f2SRichard Henderson # define avail_VIS2(C) false 24603335a048SRichard Henderson # define avail_VIS3(C) false 24613335a048SRichard Henderson # define avail_VIS3B(C) false 246290b1433dSRichard Henderson # define avail_VIS4(C) false 2463878cc677SRichard Henderson #endif 2464878cc677SRichard Henderson 2465878cc677SRichard Henderson /* Default case for non jump instructions. */ 2466878cc677SRichard Henderson static bool advance_pc(DisasContext *dc) 2467878cc677SRichard Henderson { 24684a8d145dSRichard Henderson TCGLabel *l1; 24694a8d145dSRichard Henderson 247089527e3aSRichard Henderson finishing_insn(dc); 247189527e3aSRichard Henderson 2472878cc677SRichard Henderson if (dc->npc & 3) { 2473878cc677SRichard Henderson switch (dc->npc) { 2474878cc677SRichard Henderson case DYNAMIC_PC: 2475878cc677SRichard Henderson case DYNAMIC_PC_LOOKUP: 2476878cc677SRichard Henderson dc->pc = dc->npc; 2477444d8b30SRichard Henderson tcg_gen_mov_tl(cpu_pc, cpu_npc); 2478444d8b30SRichard Henderson tcg_gen_addi_tl(cpu_npc, cpu_npc, 4); 2479878cc677SRichard Henderson break; 24804a8d145dSRichard Henderson 2481878cc677SRichard Henderson case JUMP_PC: 2482878cc677SRichard Henderson /* we can do a static jump */ 24834a8d145dSRichard Henderson l1 = gen_new_label(); 2484533f042fSRichard Henderson tcg_gen_brcondi_tl(dc->jump.cond, dc->jump.c1, dc->jump.c2, l1); 24854a8d145dSRichard Henderson 24864a8d145dSRichard Henderson /* jump not taken */ 24874a8d145dSRichard Henderson gen_goto_tb(dc, 1, dc->jump_pc[1], dc->jump_pc[1] + 4); 24884a8d145dSRichard Henderson 24894a8d145dSRichard Henderson /* jump taken */ 24904a8d145dSRichard Henderson gen_set_label(l1); 24914a8d145dSRichard Henderson gen_goto_tb(dc, 0, dc->jump_pc[0], dc->jump_pc[0] + 4); 24924a8d145dSRichard Henderson 2493878cc677SRichard Henderson dc->base.is_jmp = DISAS_NORETURN; 2494878cc677SRichard Henderson break; 24954a8d145dSRichard Henderson 2496878cc677SRichard Henderson default: 2497878cc677SRichard Henderson g_assert_not_reached(); 2498878cc677SRichard Henderson } 2499878cc677SRichard Henderson } else { 2500878cc677SRichard Henderson dc->pc = dc->npc; 2501878cc677SRichard Henderson dc->npc = dc->npc + 4; 2502878cc677SRichard Henderson } 2503878cc677SRichard Henderson return true; 2504878cc677SRichard Henderson } 2505878cc677SRichard Henderson 25066d2a0768SRichard Henderson /* 25076d2a0768SRichard Henderson * Major opcodes 00 and 01 -- branches, call, and sethi 25086d2a0768SRichard Henderson */ 25096d2a0768SRichard Henderson 25109d4e2bc7SRichard Henderson static bool advance_jump_cond(DisasContext *dc, DisasCompare *cmp, 25113951b7a8SRichard Henderson bool annul, int disp) 2512276567aaSRichard Henderson { 25133951b7a8SRichard Henderson target_ulong dest = address_mask_i(dc, dc->pc + disp * 4); 2514c76c8045SRichard Henderson target_ulong npc; 2515c76c8045SRichard Henderson 251689527e3aSRichard Henderson finishing_insn(dc); 251789527e3aSRichard Henderson 25182d9bb237SRichard Henderson if (cmp->cond == TCG_COND_ALWAYS) { 25192d9bb237SRichard Henderson if (annul) { 25202d9bb237SRichard Henderson dc->pc = dest; 25212d9bb237SRichard Henderson dc->npc = dest + 4; 25222d9bb237SRichard Henderson } else { 25232d9bb237SRichard Henderson gen_mov_pc_npc(dc); 25242d9bb237SRichard Henderson dc->npc = dest; 25252d9bb237SRichard Henderson } 25262d9bb237SRichard Henderson return true; 25272d9bb237SRichard Henderson } 25282d9bb237SRichard Henderson 25292d9bb237SRichard Henderson if (cmp->cond == TCG_COND_NEVER) { 25302d9bb237SRichard Henderson npc = dc->npc; 25312d9bb237SRichard Henderson if (npc & 3) { 25322d9bb237SRichard Henderson gen_mov_pc_npc(dc); 25332d9bb237SRichard Henderson if (annul) { 25342d9bb237SRichard Henderson tcg_gen_addi_tl(cpu_pc, cpu_pc, 4); 25352d9bb237SRichard Henderson } 25362d9bb237SRichard Henderson tcg_gen_addi_tl(cpu_npc, cpu_pc, 4); 25372d9bb237SRichard Henderson } else { 25382d9bb237SRichard Henderson dc->pc = npc + (annul ? 4 : 0); 25392d9bb237SRichard Henderson dc->npc = dc->pc + 4; 25402d9bb237SRichard Henderson } 25412d9bb237SRichard Henderson return true; 25422d9bb237SRichard Henderson } 25432d9bb237SRichard Henderson 2544c76c8045SRichard Henderson flush_cond(dc); 2545c76c8045SRichard Henderson npc = dc->npc; 25466b3e4cc6SRichard Henderson 2547276567aaSRichard Henderson if (annul) { 25486b3e4cc6SRichard Henderson TCGLabel *l1 = gen_new_label(); 25496b3e4cc6SRichard Henderson 2550c8507ebfSRichard Henderson tcg_gen_brcondi_tl(tcg_invert_cond(cmp->cond), cmp->c1, cmp->c2, l1); 25516b3e4cc6SRichard Henderson gen_goto_tb(dc, 0, npc, dest); 25526b3e4cc6SRichard Henderson gen_set_label(l1); 25536b3e4cc6SRichard Henderson gen_goto_tb(dc, 1, npc + 4, npc + 8); 25546b3e4cc6SRichard Henderson 25556b3e4cc6SRichard Henderson dc->base.is_jmp = DISAS_NORETURN; 2556276567aaSRichard Henderson } else { 25576b3e4cc6SRichard Henderson if (npc & 3) { 25586b3e4cc6SRichard Henderson switch (npc) { 25596b3e4cc6SRichard Henderson case DYNAMIC_PC: 25606b3e4cc6SRichard Henderson case DYNAMIC_PC_LOOKUP: 25616b3e4cc6SRichard Henderson tcg_gen_mov_tl(cpu_pc, cpu_npc); 25626b3e4cc6SRichard Henderson tcg_gen_addi_tl(cpu_npc, cpu_npc, 4); 25639d4e2bc7SRichard Henderson tcg_gen_movcond_tl(cmp->cond, cpu_npc, 2564c8507ebfSRichard Henderson cmp->c1, tcg_constant_tl(cmp->c2), 25656b3e4cc6SRichard Henderson tcg_constant_tl(dest), cpu_npc); 25666b3e4cc6SRichard Henderson dc->pc = npc; 25676b3e4cc6SRichard Henderson break; 25686b3e4cc6SRichard Henderson default: 25696b3e4cc6SRichard Henderson g_assert_not_reached(); 25706b3e4cc6SRichard Henderson } 25716b3e4cc6SRichard Henderson } else { 25726b3e4cc6SRichard Henderson dc->pc = npc; 2573533f042fSRichard Henderson dc->npc = JUMP_PC; 2574533f042fSRichard Henderson dc->jump = *cmp; 25756b3e4cc6SRichard Henderson dc->jump_pc[0] = dest; 25766b3e4cc6SRichard Henderson dc->jump_pc[1] = npc + 4; 2577dd7dbfccSRichard Henderson 2578dd7dbfccSRichard Henderson /* The condition for cpu_cond is always NE -- normalize. */ 2579dd7dbfccSRichard Henderson if (cmp->cond == TCG_COND_NE) { 2580c8507ebfSRichard Henderson tcg_gen_xori_tl(cpu_cond, cmp->c1, cmp->c2); 25819d4e2bc7SRichard Henderson } else { 2582c8507ebfSRichard Henderson tcg_gen_setcondi_tl(cmp->cond, cpu_cond, cmp->c1, cmp->c2); 25839d4e2bc7SRichard Henderson } 258489527e3aSRichard Henderson dc->cpu_cond_live = true; 25856b3e4cc6SRichard Henderson } 2586276567aaSRichard Henderson } 2587276567aaSRichard Henderson return true; 2588276567aaSRichard Henderson } 2589276567aaSRichard Henderson 2590af25071cSRichard Henderson static bool raise_priv(DisasContext *dc) 2591af25071cSRichard Henderson { 2592af25071cSRichard Henderson gen_exception(dc, TT_PRIV_INSN); 2593af25071cSRichard Henderson return true; 2594af25071cSRichard Henderson } 2595af25071cSRichard Henderson 259606c060d9SRichard Henderson static bool raise_unimpfpop(DisasContext *dc) 259706c060d9SRichard Henderson { 259806c060d9SRichard Henderson gen_op_fpexception_im(dc, FSR_FTT_UNIMPFPOP); 259906c060d9SRichard Henderson return true; 260006c060d9SRichard Henderson } 260106c060d9SRichard Henderson 260206c060d9SRichard Henderson static bool gen_trap_float128(DisasContext *dc) 260306c060d9SRichard Henderson { 260406c060d9SRichard Henderson if (dc->def->features & CPU_FEATURE_FLOAT128) { 260506c060d9SRichard Henderson return false; 260606c060d9SRichard Henderson } 260706c060d9SRichard Henderson return raise_unimpfpop(dc); 260806c060d9SRichard Henderson } 260906c060d9SRichard Henderson 2610276567aaSRichard Henderson static bool do_bpcc(DisasContext *dc, arg_bcc *a) 2611276567aaSRichard Henderson { 26121ea9c62aSRichard Henderson DisasCompare cmp; 2613276567aaSRichard Henderson 26141ea9c62aSRichard Henderson gen_compare(&cmp, a->cc, a->cond, dc); 26153951b7a8SRichard Henderson return advance_jump_cond(dc, &cmp, a->a, a->i); 2616276567aaSRichard Henderson } 2617276567aaSRichard Henderson 2618276567aaSRichard Henderson TRANS(Bicc, ALL, do_bpcc, a) 2619276567aaSRichard Henderson TRANS(BPcc, 64, do_bpcc, a) 2620276567aaSRichard Henderson 262145196ea4SRichard Henderson static bool do_fbpfcc(DisasContext *dc, arg_bcc *a) 262245196ea4SRichard Henderson { 2623d5471936SRichard Henderson DisasCompare cmp; 262445196ea4SRichard Henderson 262545196ea4SRichard Henderson if (gen_trap_ifnofpu(dc)) { 262645196ea4SRichard Henderson return true; 262745196ea4SRichard Henderson } 2628d5471936SRichard Henderson gen_fcompare(&cmp, a->cc, a->cond); 26293951b7a8SRichard Henderson return advance_jump_cond(dc, &cmp, a->a, a->i); 263045196ea4SRichard Henderson } 263145196ea4SRichard Henderson 263245196ea4SRichard Henderson TRANS(FBPfcc, 64, do_fbpfcc, a) 263345196ea4SRichard Henderson TRANS(FBfcc, ALL, do_fbpfcc, a) 263445196ea4SRichard Henderson 2635ab9ffe98SRichard Henderson static bool trans_BPr(DisasContext *dc, arg_BPr *a) 2636ab9ffe98SRichard Henderson { 2637ab9ffe98SRichard Henderson DisasCompare cmp; 2638ab9ffe98SRichard Henderson 2639ab9ffe98SRichard Henderson if (!avail_64(dc)) { 2640ab9ffe98SRichard Henderson return false; 2641ab9ffe98SRichard Henderson } 26422c4f56c9SRichard Henderson if (!gen_compare_reg(&cmp, a->cond, gen_load_gpr(dc, a->rs1))) { 2643ab9ffe98SRichard Henderson return false; 2644ab9ffe98SRichard Henderson } 26453951b7a8SRichard Henderson return advance_jump_cond(dc, &cmp, a->a, a->i); 2646ab9ffe98SRichard Henderson } 2647ab9ffe98SRichard Henderson 264823ada1b1SRichard Henderson static bool trans_CALL(DisasContext *dc, arg_CALL *a) 264923ada1b1SRichard Henderson { 265023ada1b1SRichard Henderson target_long target = address_mask_i(dc, dc->pc + a->i * 4); 265123ada1b1SRichard Henderson 265223ada1b1SRichard Henderson gen_store_gpr(dc, 15, tcg_constant_tl(dc->pc)); 265323ada1b1SRichard Henderson gen_mov_pc_npc(dc); 265423ada1b1SRichard Henderson dc->npc = target; 265523ada1b1SRichard Henderson return true; 265623ada1b1SRichard Henderson } 265723ada1b1SRichard Henderson 265845196ea4SRichard Henderson static bool trans_NCP(DisasContext *dc, arg_NCP *a) 265945196ea4SRichard Henderson { 266045196ea4SRichard Henderson /* 266145196ea4SRichard Henderson * For sparc32, always generate the no-coprocessor exception. 266245196ea4SRichard Henderson * For sparc64, always generate illegal instruction. 266345196ea4SRichard Henderson */ 266445196ea4SRichard Henderson #ifdef TARGET_SPARC64 266545196ea4SRichard Henderson return false; 266645196ea4SRichard Henderson #else 266745196ea4SRichard Henderson gen_exception(dc, TT_NCP_INSN); 266845196ea4SRichard Henderson return true; 266945196ea4SRichard Henderson #endif 267045196ea4SRichard Henderson } 267145196ea4SRichard Henderson 26726d2a0768SRichard Henderson static bool trans_SETHI(DisasContext *dc, arg_SETHI *a) 26736d2a0768SRichard Henderson { 26746d2a0768SRichard Henderson /* Special-case %g0 because that's the canonical nop. */ 26756d2a0768SRichard Henderson if (a->rd) { 26766d2a0768SRichard Henderson gen_store_gpr(dc, a->rd, tcg_constant_tl((uint32_t)a->i << 10)); 26776d2a0768SRichard Henderson } 26786d2a0768SRichard Henderson return advance_pc(dc); 26796d2a0768SRichard Henderson } 26806d2a0768SRichard Henderson 26810faef01bSRichard Henderson /* 26820faef01bSRichard Henderson * Major Opcode 10 -- integer, floating-point, vis, and system insns. 26830faef01bSRichard Henderson */ 26840faef01bSRichard Henderson 268530376636SRichard Henderson static bool do_tcc(DisasContext *dc, int cond, int cc, 268630376636SRichard Henderson int rs1, bool imm, int rs2_or_imm) 268730376636SRichard Henderson { 268830376636SRichard Henderson int mask = ((dc->def->features & CPU_FEATURE_HYPV) && supervisor(dc) 268930376636SRichard Henderson ? UA2005_HTRAP_MASK : V8_TRAP_MASK); 269030376636SRichard Henderson DisasCompare cmp; 269130376636SRichard Henderson TCGLabel *lab; 269230376636SRichard Henderson TCGv_i32 trap; 269330376636SRichard Henderson 269430376636SRichard Henderson /* Trap never. */ 269530376636SRichard Henderson if (cond == 0) { 269630376636SRichard Henderson return advance_pc(dc); 269730376636SRichard Henderson } 269830376636SRichard Henderson 269930376636SRichard Henderson /* 270030376636SRichard Henderson * Immediate traps are the most common case. Since this value is 270130376636SRichard Henderson * live across the branch, it really pays to evaluate the constant. 270230376636SRichard Henderson */ 270330376636SRichard Henderson if (rs1 == 0 && (imm || rs2_or_imm == 0)) { 270430376636SRichard Henderson trap = tcg_constant_i32((rs2_or_imm & mask) + TT_TRAP); 270530376636SRichard Henderson } else { 270630376636SRichard Henderson trap = tcg_temp_new_i32(); 270730376636SRichard Henderson tcg_gen_trunc_tl_i32(trap, gen_load_gpr(dc, rs1)); 270830376636SRichard Henderson if (imm) { 270930376636SRichard Henderson tcg_gen_addi_i32(trap, trap, rs2_or_imm); 271030376636SRichard Henderson } else { 271130376636SRichard Henderson TCGv_i32 t2 = tcg_temp_new_i32(); 271230376636SRichard Henderson tcg_gen_trunc_tl_i32(t2, gen_load_gpr(dc, rs2_or_imm)); 271330376636SRichard Henderson tcg_gen_add_i32(trap, trap, t2); 271430376636SRichard Henderson } 271530376636SRichard Henderson tcg_gen_andi_i32(trap, trap, mask); 271630376636SRichard Henderson tcg_gen_addi_i32(trap, trap, TT_TRAP); 271730376636SRichard Henderson } 271830376636SRichard Henderson 271989527e3aSRichard Henderson finishing_insn(dc); 272089527e3aSRichard Henderson 272130376636SRichard Henderson /* Trap always. */ 272230376636SRichard Henderson if (cond == 8) { 272330376636SRichard Henderson save_state(dc); 272430376636SRichard Henderson gen_helper_raise_exception(tcg_env, trap); 272530376636SRichard Henderson dc->base.is_jmp = DISAS_NORETURN; 272630376636SRichard Henderson return true; 272730376636SRichard Henderson } 272830376636SRichard Henderson 272930376636SRichard Henderson /* Conditional trap. */ 273030376636SRichard Henderson flush_cond(dc); 273130376636SRichard Henderson lab = delay_exceptionv(dc, trap); 273230376636SRichard Henderson gen_compare(&cmp, cc, cond, dc); 2733c8507ebfSRichard Henderson tcg_gen_brcondi_tl(cmp.cond, cmp.c1, cmp.c2, lab); 273430376636SRichard Henderson 273530376636SRichard Henderson return advance_pc(dc); 273630376636SRichard Henderson } 273730376636SRichard Henderson 273830376636SRichard Henderson static bool trans_Tcc_r(DisasContext *dc, arg_Tcc_r *a) 273930376636SRichard Henderson { 274030376636SRichard Henderson if (avail_32(dc) && a->cc) { 274130376636SRichard Henderson return false; 274230376636SRichard Henderson } 274330376636SRichard Henderson return do_tcc(dc, a->cond, a->cc, a->rs1, false, a->rs2); 274430376636SRichard Henderson } 274530376636SRichard Henderson 274630376636SRichard Henderson static bool trans_Tcc_i_v7(DisasContext *dc, arg_Tcc_i_v7 *a) 274730376636SRichard Henderson { 274830376636SRichard Henderson if (avail_64(dc)) { 274930376636SRichard Henderson return false; 275030376636SRichard Henderson } 275130376636SRichard Henderson return do_tcc(dc, a->cond, 0, a->rs1, true, a->i); 275230376636SRichard Henderson } 275330376636SRichard Henderson 275430376636SRichard Henderson static bool trans_Tcc_i_v9(DisasContext *dc, arg_Tcc_i_v9 *a) 275530376636SRichard Henderson { 275630376636SRichard Henderson if (avail_32(dc)) { 275730376636SRichard Henderson return false; 275830376636SRichard Henderson } 275930376636SRichard Henderson return do_tcc(dc, a->cond, a->cc, a->rs1, true, a->i); 276030376636SRichard Henderson } 276130376636SRichard Henderson 2762af25071cSRichard Henderson static bool trans_STBAR(DisasContext *dc, arg_STBAR *a) 2763af25071cSRichard Henderson { 2764af25071cSRichard Henderson tcg_gen_mb(TCG_MO_ST_ST | TCG_BAR_SC); 2765af25071cSRichard Henderson return advance_pc(dc); 2766af25071cSRichard Henderson } 2767af25071cSRichard Henderson 2768af25071cSRichard Henderson static bool trans_MEMBAR(DisasContext *dc, arg_MEMBAR *a) 2769af25071cSRichard Henderson { 2770af25071cSRichard Henderson if (avail_32(dc)) { 2771af25071cSRichard Henderson return false; 2772af25071cSRichard Henderson } 2773af25071cSRichard Henderson if (a->mmask) { 2774af25071cSRichard Henderson /* Note TCG_MO_* was modeled on sparc64, so mmask matches. */ 2775af25071cSRichard Henderson tcg_gen_mb(a->mmask | TCG_BAR_SC); 2776af25071cSRichard Henderson } 2777af25071cSRichard Henderson if (a->cmask) { 2778af25071cSRichard Henderson /* For #Sync, etc, end the TB to recognize interrupts. */ 2779af25071cSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 2780af25071cSRichard Henderson } 2781af25071cSRichard Henderson return advance_pc(dc); 2782af25071cSRichard Henderson } 2783af25071cSRichard Henderson 2784af25071cSRichard Henderson static bool do_rd_special(DisasContext *dc, bool priv, int rd, 2785af25071cSRichard Henderson TCGv (*func)(DisasContext *, TCGv)) 2786af25071cSRichard Henderson { 2787af25071cSRichard Henderson if (!priv) { 2788af25071cSRichard Henderson return raise_priv(dc); 2789af25071cSRichard Henderson } 2790af25071cSRichard Henderson gen_store_gpr(dc, rd, func(dc, gen_dest_gpr(dc, rd))); 2791af25071cSRichard Henderson return advance_pc(dc); 2792af25071cSRichard Henderson } 2793af25071cSRichard Henderson 2794af25071cSRichard Henderson static TCGv do_rdy(DisasContext *dc, TCGv dst) 2795af25071cSRichard Henderson { 2796af25071cSRichard Henderson return cpu_y; 2797af25071cSRichard Henderson } 2798af25071cSRichard Henderson 2799af25071cSRichard Henderson static bool trans_RDY(DisasContext *dc, arg_RDY *a) 2800af25071cSRichard Henderson { 2801af25071cSRichard Henderson /* 2802af25071cSRichard Henderson * TODO: Need a feature bit for sparcv8. In the meantime, treat all 2803af25071cSRichard Henderson * 32-bit cpus like sparcv7, which ignores the rs1 field. 2804af25071cSRichard Henderson * This matches after all other ASR, so Leon3 Asr17 is handled first. 2805af25071cSRichard Henderson */ 2806af25071cSRichard Henderson if (avail_64(dc) && a->rs1 != 0) { 2807af25071cSRichard Henderson return false; 2808af25071cSRichard Henderson } 2809af25071cSRichard Henderson return do_rd_special(dc, true, a->rd, do_rdy); 2810af25071cSRichard Henderson } 2811af25071cSRichard Henderson 2812af25071cSRichard Henderson static TCGv do_rd_leon3_config(DisasContext *dc, TCGv dst) 2813af25071cSRichard Henderson { 2814c92948f2SClément Chigot gen_helper_rdasr17(dst, tcg_env); 2815c92948f2SClément Chigot return dst; 2816af25071cSRichard Henderson } 2817af25071cSRichard Henderson 2818af25071cSRichard Henderson TRANS(RDASR17, ASR17, do_rd_special, true, a->rd, do_rd_leon3_config) 2819af25071cSRichard Henderson 2820af25071cSRichard Henderson static TCGv do_rdccr(DisasContext *dc, TCGv dst) 2821af25071cSRichard Henderson { 2822af25071cSRichard Henderson gen_helper_rdccr(dst, tcg_env); 2823af25071cSRichard Henderson return dst; 2824af25071cSRichard Henderson } 2825af25071cSRichard Henderson 2826af25071cSRichard Henderson TRANS(RDCCR, 64, do_rd_special, true, a->rd, do_rdccr) 2827af25071cSRichard Henderson 2828af25071cSRichard Henderson static TCGv do_rdasi(DisasContext *dc, TCGv dst) 2829af25071cSRichard Henderson { 2830af25071cSRichard Henderson #ifdef TARGET_SPARC64 2831af25071cSRichard Henderson return tcg_constant_tl(dc->asi); 2832af25071cSRichard Henderson #else 2833af25071cSRichard Henderson qemu_build_not_reached(); 2834af25071cSRichard Henderson #endif 2835af25071cSRichard Henderson } 2836af25071cSRichard Henderson 2837af25071cSRichard Henderson TRANS(RDASI, 64, do_rd_special, true, a->rd, do_rdasi) 2838af25071cSRichard Henderson 2839af25071cSRichard Henderson static TCGv do_rdtick(DisasContext *dc, TCGv dst) 2840af25071cSRichard Henderson { 2841af25071cSRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr(); 2842af25071cSRichard Henderson 2843af25071cSRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(tick)); 2844af25071cSRichard Henderson if (translator_io_start(&dc->base)) { 2845af25071cSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 2846af25071cSRichard Henderson } 2847af25071cSRichard Henderson gen_helper_tick_get_count(dst, tcg_env, r_tickptr, 2848af25071cSRichard Henderson tcg_constant_i32(dc->mem_idx)); 2849af25071cSRichard Henderson return dst; 2850af25071cSRichard Henderson } 2851af25071cSRichard Henderson 2852af25071cSRichard Henderson /* TODO: non-priv access only allowed when enabled. */ 2853af25071cSRichard Henderson TRANS(RDTICK, 64, do_rd_special, true, a->rd, do_rdtick) 2854af25071cSRichard Henderson 2855af25071cSRichard Henderson static TCGv do_rdpc(DisasContext *dc, TCGv dst) 2856af25071cSRichard Henderson { 2857af25071cSRichard Henderson return tcg_constant_tl(address_mask_i(dc, dc->pc)); 2858af25071cSRichard Henderson } 2859af25071cSRichard Henderson 2860af25071cSRichard Henderson TRANS(RDPC, 64, do_rd_special, true, a->rd, do_rdpc) 2861af25071cSRichard Henderson 2862af25071cSRichard Henderson static TCGv do_rdfprs(DisasContext *dc, TCGv dst) 2863af25071cSRichard Henderson { 2864af25071cSRichard Henderson tcg_gen_ext_i32_tl(dst, cpu_fprs); 2865af25071cSRichard Henderson return dst; 2866af25071cSRichard Henderson } 2867af25071cSRichard Henderson 2868af25071cSRichard Henderson TRANS(RDFPRS, 64, do_rd_special, true, a->rd, do_rdfprs) 2869af25071cSRichard Henderson 2870af25071cSRichard Henderson static TCGv do_rdgsr(DisasContext *dc, TCGv dst) 2871af25071cSRichard Henderson { 2872af25071cSRichard Henderson gen_trap_ifnofpu(dc); 2873af25071cSRichard Henderson return cpu_gsr; 2874af25071cSRichard Henderson } 2875af25071cSRichard Henderson 2876af25071cSRichard Henderson TRANS(RDGSR, 64, do_rd_special, true, a->rd, do_rdgsr) 2877af25071cSRichard Henderson 2878af25071cSRichard Henderson static TCGv do_rdsoftint(DisasContext *dc, TCGv dst) 2879af25071cSRichard Henderson { 2880af25071cSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(softint)); 2881af25071cSRichard Henderson return dst; 2882af25071cSRichard Henderson } 2883af25071cSRichard Henderson 2884af25071cSRichard Henderson TRANS(RDSOFTINT, 64, do_rd_special, supervisor(dc), a->rd, do_rdsoftint) 2885af25071cSRichard Henderson 2886af25071cSRichard Henderson static TCGv do_rdtick_cmpr(DisasContext *dc, TCGv dst) 2887af25071cSRichard Henderson { 2888577efa45SRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(tick_cmpr)); 2889577efa45SRichard Henderson return dst; 2890af25071cSRichard Henderson } 2891af25071cSRichard Henderson 2892af25071cSRichard Henderson /* TODO: non-priv access only allowed when enabled. */ 2893af25071cSRichard Henderson TRANS(RDTICK_CMPR, 64, do_rd_special, true, a->rd, do_rdtick_cmpr) 2894af25071cSRichard Henderson 2895af25071cSRichard Henderson static TCGv do_rdstick(DisasContext *dc, TCGv dst) 2896af25071cSRichard Henderson { 2897af25071cSRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr(); 2898af25071cSRichard Henderson 2899af25071cSRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(stick)); 2900af25071cSRichard Henderson if (translator_io_start(&dc->base)) { 2901af25071cSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 2902af25071cSRichard Henderson } 2903af25071cSRichard Henderson gen_helper_tick_get_count(dst, tcg_env, r_tickptr, 2904af25071cSRichard Henderson tcg_constant_i32(dc->mem_idx)); 2905af25071cSRichard Henderson return dst; 2906af25071cSRichard Henderson } 2907af25071cSRichard Henderson 2908af25071cSRichard Henderson /* TODO: non-priv access only allowed when enabled. */ 2909af25071cSRichard Henderson TRANS(RDSTICK, 64, do_rd_special, true, a->rd, do_rdstick) 2910af25071cSRichard Henderson 2911af25071cSRichard Henderson static TCGv do_rdstick_cmpr(DisasContext *dc, TCGv dst) 2912af25071cSRichard Henderson { 2913577efa45SRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(stick_cmpr)); 2914577efa45SRichard Henderson return dst; 2915af25071cSRichard Henderson } 2916af25071cSRichard Henderson 2917af25071cSRichard Henderson /* TODO: supervisor access only allowed when enabled by hypervisor. */ 2918af25071cSRichard Henderson TRANS(RDSTICK_CMPR, 64, do_rd_special, supervisor(dc), a->rd, do_rdstick_cmpr) 2919af25071cSRichard Henderson 2920af25071cSRichard Henderson /* 2921af25071cSRichard Henderson * UltraSPARC-T1 Strand status. 2922af25071cSRichard Henderson * HYPV check maybe not enough, UA2005 & UA2007 describe 2923af25071cSRichard Henderson * this ASR as impl. dep 2924af25071cSRichard Henderson */ 2925af25071cSRichard Henderson static TCGv do_rdstrand_status(DisasContext *dc, TCGv dst) 2926af25071cSRichard Henderson { 2927af25071cSRichard Henderson return tcg_constant_tl(1); 2928af25071cSRichard Henderson } 2929af25071cSRichard Henderson 2930af25071cSRichard Henderson TRANS(RDSTRAND_STATUS, HYPV, do_rd_special, true, a->rd, do_rdstrand_status) 2931af25071cSRichard Henderson 2932668bb9b7SRichard Henderson static TCGv do_rdpsr(DisasContext *dc, TCGv dst) 2933668bb9b7SRichard Henderson { 2934668bb9b7SRichard Henderson gen_helper_rdpsr(dst, tcg_env); 2935668bb9b7SRichard Henderson return dst; 2936668bb9b7SRichard Henderson } 2937668bb9b7SRichard Henderson 2938668bb9b7SRichard Henderson TRANS(RDPSR, 32, do_rd_special, supervisor(dc), a->rd, do_rdpsr) 2939668bb9b7SRichard Henderson 2940668bb9b7SRichard Henderson static TCGv do_rdhpstate(DisasContext *dc, TCGv dst) 2941668bb9b7SRichard Henderson { 2942668bb9b7SRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hpstate)); 2943668bb9b7SRichard Henderson return dst; 2944668bb9b7SRichard Henderson } 2945668bb9b7SRichard Henderson 2946668bb9b7SRichard Henderson TRANS(RDHPR_hpstate, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhpstate) 2947668bb9b7SRichard Henderson 2948668bb9b7SRichard Henderson static TCGv do_rdhtstate(DisasContext *dc, TCGv dst) 2949668bb9b7SRichard Henderson { 2950668bb9b7SRichard Henderson TCGv_i32 tl = tcg_temp_new_i32(); 2951668bb9b7SRichard Henderson TCGv_ptr tp = tcg_temp_new_ptr(); 2952668bb9b7SRichard Henderson 2953668bb9b7SRichard Henderson tcg_gen_ld_i32(tl, tcg_env, env64_field_offsetof(tl)); 2954668bb9b7SRichard Henderson tcg_gen_andi_i32(tl, tl, MAXTL_MASK); 2955668bb9b7SRichard Henderson tcg_gen_shli_i32(tl, tl, 3); 2956668bb9b7SRichard Henderson tcg_gen_ext_i32_ptr(tp, tl); 2957668bb9b7SRichard Henderson tcg_gen_add_ptr(tp, tp, tcg_env); 2958668bb9b7SRichard Henderson 2959668bb9b7SRichard Henderson tcg_gen_ld_tl(dst, tp, env64_field_offsetof(htstate)); 2960668bb9b7SRichard Henderson return dst; 2961668bb9b7SRichard Henderson } 2962668bb9b7SRichard Henderson 2963668bb9b7SRichard Henderson TRANS(RDHPR_htstate, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhtstate) 2964668bb9b7SRichard Henderson 2965668bb9b7SRichard Henderson static TCGv do_rdhintp(DisasContext *dc, TCGv dst) 2966668bb9b7SRichard Henderson { 29672da789deSRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hintp)); 29682da789deSRichard Henderson return dst; 2969668bb9b7SRichard Henderson } 2970668bb9b7SRichard Henderson 2971668bb9b7SRichard Henderson TRANS(RDHPR_hintp, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhintp) 2972668bb9b7SRichard Henderson 2973668bb9b7SRichard Henderson static TCGv do_rdhtba(DisasContext *dc, TCGv dst) 2974668bb9b7SRichard Henderson { 29752da789deSRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(htba)); 29762da789deSRichard Henderson return dst; 2977668bb9b7SRichard Henderson } 2978668bb9b7SRichard Henderson 2979668bb9b7SRichard Henderson TRANS(RDHPR_htba, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhtba) 2980668bb9b7SRichard Henderson 2981668bb9b7SRichard Henderson static TCGv do_rdhver(DisasContext *dc, TCGv dst) 2982668bb9b7SRichard Henderson { 29832da789deSRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hver)); 29842da789deSRichard Henderson return dst; 2985668bb9b7SRichard Henderson } 2986668bb9b7SRichard Henderson 2987668bb9b7SRichard Henderson TRANS(RDHPR_hver, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhver) 2988668bb9b7SRichard Henderson 2989668bb9b7SRichard Henderson static TCGv do_rdhstick_cmpr(DisasContext *dc, TCGv dst) 2990668bb9b7SRichard Henderson { 2991577efa45SRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hstick_cmpr)); 2992577efa45SRichard Henderson return dst; 2993668bb9b7SRichard Henderson } 2994668bb9b7SRichard Henderson 2995668bb9b7SRichard Henderson TRANS(RDHPR_hstick_cmpr, HYPV, do_rd_special, hypervisor(dc), a->rd, 2996668bb9b7SRichard Henderson do_rdhstick_cmpr) 2997668bb9b7SRichard Henderson 29985d617bfbSRichard Henderson static TCGv do_rdwim(DisasContext *dc, TCGv dst) 29995d617bfbSRichard Henderson { 3000cd6269f7SRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env32_field_offsetof(wim)); 3001cd6269f7SRichard Henderson return dst; 30025d617bfbSRichard Henderson } 30035d617bfbSRichard Henderson 30045d617bfbSRichard Henderson TRANS(RDWIM, 32, do_rd_special, supervisor(dc), a->rd, do_rdwim) 30055d617bfbSRichard Henderson 30065d617bfbSRichard Henderson static TCGv do_rdtpc(DisasContext *dc, TCGv dst) 30075d617bfbSRichard Henderson { 30085d617bfbSRichard Henderson #ifdef TARGET_SPARC64 30095d617bfbSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 30105d617bfbSRichard Henderson 30115d617bfbSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 30125d617bfbSRichard Henderson tcg_gen_ld_tl(dst, r_tsptr, offsetof(trap_state, tpc)); 30135d617bfbSRichard Henderson return dst; 30145d617bfbSRichard Henderson #else 30155d617bfbSRichard Henderson qemu_build_not_reached(); 30165d617bfbSRichard Henderson #endif 30175d617bfbSRichard Henderson } 30185d617bfbSRichard Henderson 30195d617bfbSRichard Henderson TRANS(RDPR_tpc, 64, do_rd_special, supervisor(dc), a->rd, do_rdtpc) 30205d617bfbSRichard Henderson 30215d617bfbSRichard Henderson static TCGv do_rdtnpc(DisasContext *dc, TCGv dst) 30225d617bfbSRichard Henderson { 30235d617bfbSRichard Henderson #ifdef TARGET_SPARC64 30245d617bfbSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 30255d617bfbSRichard Henderson 30265d617bfbSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 30275d617bfbSRichard Henderson tcg_gen_ld_tl(dst, r_tsptr, offsetof(trap_state, tnpc)); 30285d617bfbSRichard Henderson return dst; 30295d617bfbSRichard Henderson #else 30305d617bfbSRichard Henderson qemu_build_not_reached(); 30315d617bfbSRichard Henderson #endif 30325d617bfbSRichard Henderson } 30335d617bfbSRichard Henderson 30345d617bfbSRichard Henderson TRANS(RDPR_tnpc, 64, do_rd_special, supervisor(dc), a->rd, do_rdtnpc) 30355d617bfbSRichard Henderson 30365d617bfbSRichard Henderson static TCGv do_rdtstate(DisasContext *dc, TCGv dst) 30375d617bfbSRichard Henderson { 30385d617bfbSRichard Henderson #ifdef TARGET_SPARC64 30395d617bfbSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 30405d617bfbSRichard Henderson 30415d617bfbSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 30425d617bfbSRichard Henderson tcg_gen_ld_tl(dst, r_tsptr, offsetof(trap_state, tstate)); 30435d617bfbSRichard Henderson return dst; 30445d617bfbSRichard Henderson #else 30455d617bfbSRichard Henderson qemu_build_not_reached(); 30465d617bfbSRichard Henderson #endif 30475d617bfbSRichard Henderson } 30485d617bfbSRichard Henderson 30495d617bfbSRichard Henderson TRANS(RDPR_tstate, 64, do_rd_special, supervisor(dc), a->rd, do_rdtstate) 30505d617bfbSRichard Henderson 30515d617bfbSRichard Henderson static TCGv do_rdtt(DisasContext *dc, TCGv dst) 30525d617bfbSRichard Henderson { 30535d617bfbSRichard Henderson #ifdef TARGET_SPARC64 30545d617bfbSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 30555d617bfbSRichard Henderson 30565d617bfbSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 30575d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, r_tsptr, offsetof(trap_state, tt)); 30585d617bfbSRichard Henderson return dst; 30595d617bfbSRichard Henderson #else 30605d617bfbSRichard Henderson qemu_build_not_reached(); 30615d617bfbSRichard Henderson #endif 30625d617bfbSRichard Henderson } 30635d617bfbSRichard Henderson 30645d617bfbSRichard Henderson TRANS(RDPR_tt, 64, do_rd_special, supervisor(dc), a->rd, do_rdtt) 30655d617bfbSRichard Henderson TRANS(RDPR_tick, 64, do_rd_special, supervisor(dc), a->rd, do_rdtick) 30665d617bfbSRichard Henderson 30675d617bfbSRichard Henderson static TCGv do_rdtba(DisasContext *dc, TCGv dst) 30685d617bfbSRichard Henderson { 30695d617bfbSRichard Henderson return cpu_tbr; 30705d617bfbSRichard Henderson } 30715d617bfbSRichard Henderson 3072e8325dc0SRichard Henderson TRANS(RDTBR, 32, do_rd_special, supervisor(dc), a->rd, do_rdtba) 30735d617bfbSRichard Henderson TRANS(RDPR_tba, 64, do_rd_special, supervisor(dc), a->rd, do_rdtba) 30745d617bfbSRichard Henderson 30755d617bfbSRichard Henderson static TCGv do_rdpstate(DisasContext *dc, TCGv dst) 30765d617bfbSRichard Henderson { 30775d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(pstate)); 30785d617bfbSRichard Henderson return dst; 30795d617bfbSRichard Henderson } 30805d617bfbSRichard Henderson 30815d617bfbSRichard Henderson TRANS(RDPR_pstate, 64, do_rd_special, supervisor(dc), a->rd, do_rdpstate) 30825d617bfbSRichard Henderson 30835d617bfbSRichard Henderson static TCGv do_rdtl(DisasContext *dc, TCGv dst) 30845d617bfbSRichard Henderson { 30855d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(tl)); 30865d617bfbSRichard Henderson return dst; 30875d617bfbSRichard Henderson } 30885d617bfbSRichard Henderson 30895d617bfbSRichard Henderson TRANS(RDPR_tl, 64, do_rd_special, supervisor(dc), a->rd, do_rdtl) 30905d617bfbSRichard Henderson 30915d617bfbSRichard Henderson static TCGv do_rdpil(DisasContext *dc, TCGv dst) 30925d617bfbSRichard Henderson { 30935d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env_field_offsetof(psrpil)); 30945d617bfbSRichard Henderson return dst; 30955d617bfbSRichard Henderson } 30965d617bfbSRichard Henderson 30975d617bfbSRichard Henderson TRANS(RDPR_pil, 64, do_rd_special, supervisor(dc), a->rd, do_rdpil) 30985d617bfbSRichard Henderson 30995d617bfbSRichard Henderson static TCGv do_rdcwp(DisasContext *dc, TCGv dst) 31005d617bfbSRichard Henderson { 31015d617bfbSRichard Henderson gen_helper_rdcwp(dst, tcg_env); 31025d617bfbSRichard Henderson return dst; 31035d617bfbSRichard Henderson } 31045d617bfbSRichard Henderson 31055d617bfbSRichard Henderson TRANS(RDPR_cwp, 64, do_rd_special, supervisor(dc), a->rd, do_rdcwp) 31065d617bfbSRichard Henderson 31075d617bfbSRichard Henderson static TCGv do_rdcansave(DisasContext *dc, TCGv dst) 31085d617bfbSRichard Henderson { 31095d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(cansave)); 31105d617bfbSRichard Henderson return dst; 31115d617bfbSRichard Henderson } 31125d617bfbSRichard Henderson 31135d617bfbSRichard Henderson TRANS(RDPR_cansave, 64, do_rd_special, supervisor(dc), a->rd, do_rdcansave) 31145d617bfbSRichard Henderson 31155d617bfbSRichard Henderson static TCGv do_rdcanrestore(DisasContext *dc, TCGv dst) 31165d617bfbSRichard Henderson { 31175d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(canrestore)); 31185d617bfbSRichard Henderson return dst; 31195d617bfbSRichard Henderson } 31205d617bfbSRichard Henderson 31215d617bfbSRichard Henderson TRANS(RDPR_canrestore, 64, do_rd_special, supervisor(dc), a->rd, 31225d617bfbSRichard Henderson do_rdcanrestore) 31235d617bfbSRichard Henderson 31245d617bfbSRichard Henderson static TCGv do_rdcleanwin(DisasContext *dc, TCGv dst) 31255d617bfbSRichard Henderson { 31265d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(cleanwin)); 31275d617bfbSRichard Henderson return dst; 31285d617bfbSRichard Henderson } 31295d617bfbSRichard Henderson 31305d617bfbSRichard Henderson TRANS(RDPR_cleanwin, 64, do_rd_special, supervisor(dc), a->rd, do_rdcleanwin) 31315d617bfbSRichard Henderson 31325d617bfbSRichard Henderson static TCGv do_rdotherwin(DisasContext *dc, TCGv dst) 31335d617bfbSRichard Henderson { 31345d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(otherwin)); 31355d617bfbSRichard Henderson return dst; 31365d617bfbSRichard Henderson } 31375d617bfbSRichard Henderson 31385d617bfbSRichard Henderson TRANS(RDPR_otherwin, 64, do_rd_special, supervisor(dc), a->rd, do_rdotherwin) 31395d617bfbSRichard Henderson 31405d617bfbSRichard Henderson static TCGv do_rdwstate(DisasContext *dc, TCGv dst) 31415d617bfbSRichard Henderson { 31425d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(wstate)); 31435d617bfbSRichard Henderson return dst; 31445d617bfbSRichard Henderson } 31455d617bfbSRichard Henderson 31465d617bfbSRichard Henderson TRANS(RDPR_wstate, 64, do_rd_special, supervisor(dc), a->rd, do_rdwstate) 31475d617bfbSRichard Henderson 31485d617bfbSRichard Henderson static TCGv do_rdgl(DisasContext *dc, TCGv dst) 31495d617bfbSRichard Henderson { 31505d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(gl)); 31515d617bfbSRichard Henderson return dst; 31525d617bfbSRichard Henderson } 31535d617bfbSRichard Henderson 31545d617bfbSRichard Henderson TRANS(RDPR_gl, GL, do_rd_special, supervisor(dc), a->rd, do_rdgl) 31555d617bfbSRichard Henderson 31565d617bfbSRichard Henderson /* UA2005 strand status */ 31575d617bfbSRichard Henderson static TCGv do_rdssr(DisasContext *dc, TCGv dst) 31585d617bfbSRichard Henderson { 31592da789deSRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(ssr)); 31602da789deSRichard Henderson return dst; 31615d617bfbSRichard Henderson } 31625d617bfbSRichard Henderson 31635d617bfbSRichard Henderson TRANS(RDPR_strand_status, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdssr) 31645d617bfbSRichard Henderson 31655d617bfbSRichard Henderson static TCGv do_rdver(DisasContext *dc, TCGv dst) 31665d617bfbSRichard Henderson { 31672da789deSRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(version)); 31682da789deSRichard Henderson return dst; 31695d617bfbSRichard Henderson } 31705d617bfbSRichard Henderson 31715d617bfbSRichard Henderson TRANS(RDPR_ver, 64, do_rd_special, supervisor(dc), a->rd, do_rdver) 31725d617bfbSRichard Henderson 3173e8325dc0SRichard Henderson static bool trans_FLUSHW(DisasContext *dc, arg_FLUSHW *a) 3174e8325dc0SRichard Henderson { 3175e8325dc0SRichard Henderson if (avail_64(dc)) { 3176e8325dc0SRichard Henderson gen_helper_flushw(tcg_env); 3177e8325dc0SRichard Henderson return advance_pc(dc); 3178e8325dc0SRichard Henderson } 3179e8325dc0SRichard Henderson return false; 3180e8325dc0SRichard Henderson } 3181e8325dc0SRichard Henderson 31820faef01bSRichard Henderson static bool do_wr_special(DisasContext *dc, arg_r_r_ri *a, bool priv, 31830faef01bSRichard Henderson void (*func)(DisasContext *, TCGv)) 31840faef01bSRichard Henderson { 31850faef01bSRichard Henderson TCGv src; 31860faef01bSRichard Henderson 31870faef01bSRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 31880faef01bSRichard Henderson if (!a->imm && (a->rs2_or_imm & ~0x1f)) { 31890faef01bSRichard Henderson return false; 31900faef01bSRichard Henderson } 31910faef01bSRichard Henderson if (!priv) { 31920faef01bSRichard Henderson return raise_priv(dc); 31930faef01bSRichard Henderson } 31940faef01bSRichard Henderson 31950faef01bSRichard Henderson if (a->rs1 == 0 && (a->imm || a->rs2_or_imm == 0)) { 31960faef01bSRichard Henderson src = tcg_constant_tl(a->rs2_or_imm); 31970faef01bSRichard Henderson } else { 31980faef01bSRichard Henderson TCGv src1 = gen_load_gpr(dc, a->rs1); 31990faef01bSRichard Henderson if (a->rs2_or_imm == 0) { 32000faef01bSRichard Henderson src = src1; 32010faef01bSRichard Henderson } else { 32020faef01bSRichard Henderson src = tcg_temp_new(); 32030faef01bSRichard Henderson if (a->imm) { 32040faef01bSRichard Henderson tcg_gen_xori_tl(src, src1, a->rs2_or_imm); 32050faef01bSRichard Henderson } else { 32060faef01bSRichard Henderson tcg_gen_xor_tl(src, src1, gen_load_gpr(dc, a->rs2_or_imm)); 32070faef01bSRichard Henderson } 32080faef01bSRichard Henderson } 32090faef01bSRichard Henderson } 32100faef01bSRichard Henderson func(dc, src); 32110faef01bSRichard Henderson return advance_pc(dc); 32120faef01bSRichard Henderson } 32130faef01bSRichard Henderson 32140faef01bSRichard Henderson static void do_wry(DisasContext *dc, TCGv src) 32150faef01bSRichard Henderson { 32160faef01bSRichard Henderson tcg_gen_ext32u_tl(cpu_y, src); 32170faef01bSRichard Henderson } 32180faef01bSRichard Henderson 32190faef01bSRichard Henderson TRANS(WRY, ALL, do_wr_special, a, true, do_wry) 32200faef01bSRichard Henderson 32210faef01bSRichard Henderson static void do_wrccr(DisasContext *dc, TCGv src) 32220faef01bSRichard Henderson { 32230faef01bSRichard Henderson gen_helper_wrccr(tcg_env, src); 32240faef01bSRichard Henderson } 32250faef01bSRichard Henderson 32260faef01bSRichard Henderson TRANS(WRCCR, 64, do_wr_special, a, true, do_wrccr) 32270faef01bSRichard Henderson 32280faef01bSRichard Henderson static void do_wrasi(DisasContext *dc, TCGv src) 32290faef01bSRichard Henderson { 32300faef01bSRichard Henderson TCGv tmp = tcg_temp_new(); 32310faef01bSRichard Henderson 32320faef01bSRichard Henderson tcg_gen_ext8u_tl(tmp, src); 32330faef01bSRichard Henderson tcg_gen_st32_tl(tmp, tcg_env, env64_field_offsetof(asi)); 32340faef01bSRichard Henderson /* End TB to notice changed ASI. */ 32350faef01bSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 32360faef01bSRichard Henderson } 32370faef01bSRichard Henderson 32380faef01bSRichard Henderson TRANS(WRASI, 64, do_wr_special, a, true, do_wrasi) 32390faef01bSRichard Henderson 32400faef01bSRichard Henderson static void do_wrfprs(DisasContext *dc, TCGv src) 32410faef01bSRichard Henderson { 32420faef01bSRichard Henderson #ifdef TARGET_SPARC64 32430faef01bSRichard Henderson tcg_gen_trunc_tl_i32(cpu_fprs, src); 32440faef01bSRichard Henderson dc->fprs_dirty = 0; 32450faef01bSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 32460faef01bSRichard Henderson #else 32470faef01bSRichard Henderson qemu_build_not_reached(); 32480faef01bSRichard Henderson #endif 32490faef01bSRichard Henderson } 32500faef01bSRichard Henderson 32510faef01bSRichard Henderson TRANS(WRFPRS, 64, do_wr_special, a, true, do_wrfprs) 32520faef01bSRichard Henderson 32530faef01bSRichard Henderson static void do_wrgsr(DisasContext *dc, TCGv src) 32540faef01bSRichard Henderson { 32550faef01bSRichard Henderson gen_trap_ifnofpu(dc); 32560faef01bSRichard Henderson tcg_gen_mov_tl(cpu_gsr, src); 32570faef01bSRichard Henderson } 32580faef01bSRichard Henderson 32590faef01bSRichard Henderson TRANS(WRGSR, 64, do_wr_special, a, true, do_wrgsr) 32600faef01bSRichard Henderson 32610faef01bSRichard Henderson static void do_wrsoftint_set(DisasContext *dc, TCGv src) 32620faef01bSRichard Henderson { 32630faef01bSRichard Henderson gen_helper_set_softint(tcg_env, src); 32640faef01bSRichard Henderson } 32650faef01bSRichard Henderson 32660faef01bSRichard Henderson TRANS(WRSOFTINT_SET, 64, do_wr_special, a, supervisor(dc), do_wrsoftint_set) 32670faef01bSRichard Henderson 32680faef01bSRichard Henderson static void do_wrsoftint_clr(DisasContext *dc, TCGv src) 32690faef01bSRichard Henderson { 32700faef01bSRichard Henderson gen_helper_clear_softint(tcg_env, src); 32710faef01bSRichard Henderson } 32720faef01bSRichard Henderson 32730faef01bSRichard Henderson TRANS(WRSOFTINT_CLR, 64, do_wr_special, a, supervisor(dc), do_wrsoftint_clr) 32740faef01bSRichard Henderson 32750faef01bSRichard Henderson static void do_wrsoftint(DisasContext *dc, TCGv src) 32760faef01bSRichard Henderson { 32770faef01bSRichard Henderson gen_helper_write_softint(tcg_env, src); 32780faef01bSRichard Henderson } 32790faef01bSRichard Henderson 32800faef01bSRichard Henderson TRANS(WRSOFTINT, 64, do_wr_special, a, supervisor(dc), do_wrsoftint) 32810faef01bSRichard Henderson 32820faef01bSRichard Henderson static void do_wrtick_cmpr(DisasContext *dc, TCGv src) 32830faef01bSRichard Henderson { 32840faef01bSRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr(); 32850faef01bSRichard Henderson 3286577efa45SRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(tick_cmpr)); 3287577efa45SRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(tick)); 32880faef01bSRichard Henderson translator_io_start(&dc->base); 3289577efa45SRichard Henderson gen_helper_tick_set_limit(r_tickptr, src); 32900faef01bSRichard Henderson /* End TB to handle timer interrupt */ 32910faef01bSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 32920faef01bSRichard Henderson } 32930faef01bSRichard Henderson 32940faef01bSRichard Henderson TRANS(WRTICK_CMPR, 64, do_wr_special, a, supervisor(dc), do_wrtick_cmpr) 32950faef01bSRichard Henderson 32960faef01bSRichard Henderson static void do_wrstick(DisasContext *dc, TCGv src) 32970faef01bSRichard Henderson { 32980faef01bSRichard Henderson #ifdef TARGET_SPARC64 32990faef01bSRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr(); 33000faef01bSRichard Henderson 33010faef01bSRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, offsetof(CPUSPARCState, stick)); 33020faef01bSRichard Henderson translator_io_start(&dc->base); 33030faef01bSRichard Henderson gen_helper_tick_set_count(r_tickptr, src); 33040faef01bSRichard Henderson /* End TB to handle timer interrupt */ 33050faef01bSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 33060faef01bSRichard Henderson #else 33070faef01bSRichard Henderson qemu_build_not_reached(); 33080faef01bSRichard Henderson #endif 33090faef01bSRichard Henderson } 33100faef01bSRichard Henderson 33110faef01bSRichard Henderson TRANS(WRSTICK, 64, do_wr_special, a, supervisor(dc), do_wrstick) 33120faef01bSRichard Henderson 33130faef01bSRichard Henderson static void do_wrstick_cmpr(DisasContext *dc, TCGv src) 33140faef01bSRichard Henderson { 33150faef01bSRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr(); 33160faef01bSRichard Henderson 3317577efa45SRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(stick_cmpr)); 3318577efa45SRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(stick)); 33190faef01bSRichard Henderson translator_io_start(&dc->base); 3320577efa45SRichard Henderson gen_helper_tick_set_limit(r_tickptr, src); 33210faef01bSRichard Henderson /* End TB to handle timer interrupt */ 33220faef01bSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 33230faef01bSRichard Henderson } 33240faef01bSRichard Henderson 33250faef01bSRichard Henderson TRANS(WRSTICK_CMPR, 64, do_wr_special, a, supervisor(dc), do_wrstick_cmpr) 33260faef01bSRichard Henderson 33270faef01bSRichard Henderson static void do_wrpowerdown(DisasContext *dc, TCGv src) 33280faef01bSRichard Henderson { 332989527e3aSRichard Henderson finishing_insn(dc); 33300faef01bSRichard Henderson save_state(dc); 33310faef01bSRichard Henderson gen_helper_power_down(tcg_env); 33320faef01bSRichard Henderson } 33330faef01bSRichard Henderson 33340faef01bSRichard Henderson TRANS(WRPOWERDOWN, POWERDOWN, do_wr_special, a, supervisor(dc), do_wrpowerdown) 33350faef01bSRichard Henderson 333625524734SRichard Henderson static void do_wrpsr(DisasContext *dc, TCGv src) 333725524734SRichard Henderson { 333825524734SRichard Henderson gen_helper_wrpsr(tcg_env, src); 333925524734SRichard Henderson dc->base.is_jmp = DISAS_EXIT; 334025524734SRichard Henderson } 334125524734SRichard Henderson 334225524734SRichard Henderson TRANS(WRPSR, 32, do_wr_special, a, supervisor(dc), do_wrpsr) 334325524734SRichard Henderson 33449422278eSRichard Henderson static void do_wrwim(DisasContext *dc, TCGv src) 33459422278eSRichard Henderson { 33469422278eSRichard Henderson target_ulong mask = MAKE_64BIT_MASK(0, dc->def->nwindows); 3347cd6269f7SRichard Henderson TCGv tmp = tcg_temp_new(); 3348cd6269f7SRichard Henderson 3349cd6269f7SRichard Henderson tcg_gen_andi_tl(tmp, src, mask); 3350cd6269f7SRichard Henderson tcg_gen_st_tl(tmp, tcg_env, env32_field_offsetof(wim)); 33519422278eSRichard Henderson } 33529422278eSRichard Henderson 33539422278eSRichard Henderson TRANS(WRWIM, 32, do_wr_special, a, supervisor(dc), do_wrwim) 33549422278eSRichard Henderson 33559422278eSRichard Henderson static void do_wrtpc(DisasContext *dc, TCGv src) 33569422278eSRichard Henderson { 33579422278eSRichard Henderson #ifdef TARGET_SPARC64 33589422278eSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 33599422278eSRichard Henderson 33609422278eSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 33619422278eSRichard Henderson tcg_gen_st_tl(src, r_tsptr, offsetof(trap_state, tpc)); 33629422278eSRichard Henderson #else 33639422278eSRichard Henderson qemu_build_not_reached(); 33649422278eSRichard Henderson #endif 33659422278eSRichard Henderson } 33669422278eSRichard Henderson 33679422278eSRichard Henderson TRANS(WRPR_tpc, 64, do_wr_special, a, supervisor(dc), do_wrtpc) 33689422278eSRichard Henderson 33699422278eSRichard Henderson static void do_wrtnpc(DisasContext *dc, TCGv src) 33709422278eSRichard Henderson { 33719422278eSRichard Henderson #ifdef TARGET_SPARC64 33729422278eSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 33739422278eSRichard Henderson 33749422278eSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 33759422278eSRichard Henderson tcg_gen_st_tl(src, r_tsptr, offsetof(trap_state, tnpc)); 33769422278eSRichard Henderson #else 33779422278eSRichard Henderson qemu_build_not_reached(); 33789422278eSRichard Henderson #endif 33799422278eSRichard Henderson } 33809422278eSRichard Henderson 33819422278eSRichard Henderson TRANS(WRPR_tnpc, 64, do_wr_special, a, supervisor(dc), do_wrtnpc) 33829422278eSRichard Henderson 33839422278eSRichard Henderson static void do_wrtstate(DisasContext *dc, TCGv src) 33849422278eSRichard Henderson { 33859422278eSRichard Henderson #ifdef TARGET_SPARC64 33869422278eSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 33879422278eSRichard Henderson 33889422278eSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 33899422278eSRichard Henderson tcg_gen_st_tl(src, r_tsptr, offsetof(trap_state, tstate)); 33909422278eSRichard Henderson #else 33919422278eSRichard Henderson qemu_build_not_reached(); 33929422278eSRichard Henderson #endif 33939422278eSRichard Henderson } 33949422278eSRichard Henderson 33959422278eSRichard Henderson TRANS(WRPR_tstate, 64, do_wr_special, a, supervisor(dc), do_wrtstate) 33969422278eSRichard Henderson 33979422278eSRichard Henderson static void do_wrtt(DisasContext *dc, TCGv src) 33989422278eSRichard Henderson { 33999422278eSRichard Henderson #ifdef TARGET_SPARC64 34009422278eSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 34019422278eSRichard Henderson 34029422278eSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 34039422278eSRichard Henderson tcg_gen_st32_tl(src, r_tsptr, offsetof(trap_state, tt)); 34049422278eSRichard Henderson #else 34059422278eSRichard Henderson qemu_build_not_reached(); 34069422278eSRichard Henderson #endif 34079422278eSRichard Henderson } 34089422278eSRichard Henderson 34099422278eSRichard Henderson TRANS(WRPR_tt, 64, do_wr_special, a, supervisor(dc), do_wrtt) 34109422278eSRichard Henderson 34119422278eSRichard Henderson static void do_wrtick(DisasContext *dc, TCGv src) 34129422278eSRichard Henderson { 34139422278eSRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr(); 34149422278eSRichard Henderson 34159422278eSRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(tick)); 34169422278eSRichard Henderson translator_io_start(&dc->base); 34179422278eSRichard Henderson gen_helper_tick_set_count(r_tickptr, src); 34189422278eSRichard Henderson /* End TB to handle timer interrupt */ 34199422278eSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 34209422278eSRichard Henderson } 34219422278eSRichard Henderson 34229422278eSRichard Henderson TRANS(WRPR_tick, 64, do_wr_special, a, supervisor(dc), do_wrtick) 34239422278eSRichard Henderson 34249422278eSRichard Henderson static void do_wrtba(DisasContext *dc, TCGv src) 34259422278eSRichard Henderson { 34269422278eSRichard Henderson tcg_gen_mov_tl(cpu_tbr, src); 34279422278eSRichard Henderson } 34289422278eSRichard Henderson 34299422278eSRichard Henderson TRANS(WRPR_tba, 64, do_wr_special, a, supervisor(dc), do_wrtba) 34309422278eSRichard Henderson 34319422278eSRichard Henderson static void do_wrpstate(DisasContext *dc, TCGv src) 34329422278eSRichard Henderson { 34339422278eSRichard Henderson save_state(dc); 34349422278eSRichard Henderson if (translator_io_start(&dc->base)) { 34359422278eSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 34369422278eSRichard Henderson } 34379422278eSRichard Henderson gen_helper_wrpstate(tcg_env, src); 34389422278eSRichard Henderson dc->npc = DYNAMIC_PC; 34399422278eSRichard Henderson } 34409422278eSRichard Henderson 34419422278eSRichard Henderson TRANS(WRPR_pstate, 64, do_wr_special, a, supervisor(dc), do_wrpstate) 34429422278eSRichard Henderson 34439422278eSRichard Henderson static void do_wrtl(DisasContext *dc, TCGv src) 34449422278eSRichard Henderson { 34459422278eSRichard Henderson save_state(dc); 34469422278eSRichard Henderson tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(tl)); 34479422278eSRichard Henderson dc->npc = DYNAMIC_PC; 34489422278eSRichard Henderson } 34499422278eSRichard Henderson 34509422278eSRichard Henderson TRANS(WRPR_tl, 64, do_wr_special, a, supervisor(dc), do_wrtl) 34519422278eSRichard Henderson 34529422278eSRichard Henderson static void do_wrpil(DisasContext *dc, TCGv src) 34539422278eSRichard Henderson { 34549422278eSRichard Henderson if (translator_io_start(&dc->base)) { 34559422278eSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 34569422278eSRichard Henderson } 34579422278eSRichard Henderson gen_helper_wrpil(tcg_env, src); 34589422278eSRichard Henderson } 34599422278eSRichard Henderson 34609422278eSRichard Henderson TRANS(WRPR_pil, 64, do_wr_special, a, supervisor(dc), do_wrpil) 34619422278eSRichard Henderson 34629422278eSRichard Henderson static void do_wrcwp(DisasContext *dc, TCGv src) 34639422278eSRichard Henderson { 34649422278eSRichard Henderson gen_helper_wrcwp(tcg_env, src); 34659422278eSRichard Henderson } 34669422278eSRichard Henderson 34679422278eSRichard Henderson TRANS(WRPR_cwp, 64, do_wr_special, a, supervisor(dc), do_wrcwp) 34689422278eSRichard Henderson 34699422278eSRichard Henderson static void do_wrcansave(DisasContext *dc, TCGv src) 34709422278eSRichard Henderson { 34719422278eSRichard Henderson tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(cansave)); 34729422278eSRichard Henderson } 34739422278eSRichard Henderson 34749422278eSRichard Henderson TRANS(WRPR_cansave, 64, do_wr_special, a, supervisor(dc), do_wrcansave) 34759422278eSRichard Henderson 34769422278eSRichard Henderson static void do_wrcanrestore(DisasContext *dc, TCGv src) 34779422278eSRichard Henderson { 34789422278eSRichard Henderson tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(canrestore)); 34799422278eSRichard Henderson } 34809422278eSRichard Henderson 34819422278eSRichard Henderson TRANS(WRPR_canrestore, 64, do_wr_special, a, supervisor(dc), do_wrcanrestore) 34829422278eSRichard Henderson 34839422278eSRichard Henderson static void do_wrcleanwin(DisasContext *dc, TCGv src) 34849422278eSRichard Henderson { 34859422278eSRichard Henderson tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(cleanwin)); 34869422278eSRichard Henderson } 34879422278eSRichard Henderson 34889422278eSRichard Henderson TRANS(WRPR_cleanwin, 64, do_wr_special, a, supervisor(dc), do_wrcleanwin) 34899422278eSRichard Henderson 34909422278eSRichard Henderson static void do_wrotherwin(DisasContext *dc, TCGv src) 34919422278eSRichard Henderson { 34929422278eSRichard Henderson tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(otherwin)); 34939422278eSRichard Henderson } 34949422278eSRichard Henderson 34959422278eSRichard Henderson TRANS(WRPR_otherwin, 64, do_wr_special, a, supervisor(dc), do_wrotherwin) 34969422278eSRichard Henderson 34979422278eSRichard Henderson static void do_wrwstate(DisasContext *dc, TCGv src) 34989422278eSRichard Henderson { 34999422278eSRichard Henderson tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(wstate)); 35009422278eSRichard Henderson } 35019422278eSRichard Henderson 35029422278eSRichard Henderson TRANS(WRPR_wstate, 64, do_wr_special, a, supervisor(dc), do_wrwstate) 35039422278eSRichard Henderson 35049422278eSRichard Henderson static void do_wrgl(DisasContext *dc, TCGv src) 35059422278eSRichard Henderson { 35069422278eSRichard Henderson gen_helper_wrgl(tcg_env, src); 35079422278eSRichard Henderson } 35089422278eSRichard Henderson 35099422278eSRichard Henderson TRANS(WRPR_gl, GL, do_wr_special, a, supervisor(dc), do_wrgl) 35109422278eSRichard Henderson 35119422278eSRichard Henderson /* UA2005 strand status */ 35129422278eSRichard Henderson static void do_wrssr(DisasContext *dc, TCGv src) 35139422278eSRichard Henderson { 35142da789deSRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(ssr)); 35159422278eSRichard Henderson } 35169422278eSRichard Henderson 35179422278eSRichard Henderson TRANS(WRPR_strand_status, HYPV, do_wr_special, a, hypervisor(dc), do_wrssr) 35189422278eSRichard Henderson 3519bb97f2f5SRichard Henderson TRANS(WRTBR, 32, do_wr_special, a, supervisor(dc), do_wrtba) 3520bb97f2f5SRichard Henderson 3521bb97f2f5SRichard Henderson static void do_wrhpstate(DisasContext *dc, TCGv src) 3522bb97f2f5SRichard Henderson { 3523bb97f2f5SRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(hpstate)); 3524bb97f2f5SRichard Henderson dc->base.is_jmp = DISAS_EXIT; 3525bb97f2f5SRichard Henderson } 3526bb97f2f5SRichard Henderson 3527bb97f2f5SRichard Henderson TRANS(WRHPR_hpstate, HYPV, do_wr_special, a, hypervisor(dc), do_wrhpstate) 3528bb97f2f5SRichard Henderson 3529bb97f2f5SRichard Henderson static void do_wrhtstate(DisasContext *dc, TCGv src) 3530bb97f2f5SRichard Henderson { 3531bb97f2f5SRichard Henderson TCGv_i32 tl = tcg_temp_new_i32(); 3532bb97f2f5SRichard Henderson TCGv_ptr tp = tcg_temp_new_ptr(); 3533bb97f2f5SRichard Henderson 3534bb97f2f5SRichard Henderson tcg_gen_ld_i32(tl, tcg_env, env64_field_offsetof(tl)); 3535bb97f2f5SRichard Henderson tcg_gen_andi_i32(tl, tl, MAXTL_MASK); 3536bb97f2f5SRichard Henderson tcg_gen_shli_i32(tl, tl, 3); 3537bb97f2f5SRichard Henderson tcg_gen_ext_i32_ptr(tp, tl); 3538bb97f2f5SRichard Henderson tcg_gen_add_ptr(tp, tp, tcg_env); 3539bb97f2f5SRichard Henderson 3540bb97f2f5SRichard Henderson tcg_gen_st_tl(src, tp, env64_field_offsetof(htstate)); 3541bb97f2f5SRichard Henderson } 3542bb97f2f5SRichard Henderson 3543bb97f2f5SRichard Henderson TRANS(WRHPR_htstate, HYPV, do_wr_special, a, hypervisor(dc), do_wrhtstate) 3544bb97f2f5SRichard Henderson 3545bb97f2f5SRichard Henderson static void do_wrhintp(DisasContext *dc, TCGv src) 3546bb97f2f5SRichard Henderson { 35472da789deSRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(hintp)); 3548bb97f2f5SRichard Henderson } 3549bb97f2f5SRichard Henderson 3550bb97f2f5SRichard Henderson TRANS(WRHPR_hintp, HYPV, do_wr_special, a, hypervisor(dc), do_wrhintp) 3551bb97f2f5SRichard Henderson 3552bb97f2f5SRichard Henderson static void do_wrhtba(DisasContext *dc, TCGv src) 3553bb97f2f5SRichard Henderson { 35542da789deSRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(htba)); 3555bb97f2f5SRichard Henderson } 3556bb97f2f5SRichard Henderson 3557bb97f2f5SRichard Henderson TRANS(WRHPR_htba, HYPV, do_wr_special, a, hypervisor(dc), do_wrhtba) 3558bb97f2f5SRichard Henderson 3559bb97f2f5SRichard Henderson static void do_wrhstick_cmpr(DisasContext *dc, TCGv src) 3560bb97f2f5SRichard Henderson { 3561bb97f2f5SRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr(); 3562bb97f2f5SRichard Henderson 3563577efa45SRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(hstick_cmpr)); 3564bb97f2f5SRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(hstick)); 3565bb97f2f5SRichard Henderson translator_io_start(&dc->base); 3566577efa45SRichard Henderson gen_helper_tick_set_limit(r_tickptr, src); 3567bb97f2f5SRichard Henderson /* End TB to handle timer interrupt */ 3568bb97f2f5SRichard Henderson dc->base.is_jmp = DISAS_EXIT; 3569bb97f2f5SRichard Henderson } 3570bb97f2f5SRichard Henderson 3571bb97f2f5SRichard Henderson TRANS(WRHPR_hstick_cmpr, HYPV, do_wr_special, a, hypervisor(dc), 3572bb97f2f5SRichard Henderson do_wrhstick_cmpr) 3573bb97f2f5SRichard Henderson 357425524734SRichard Henderson static bool do_saved_restored(DisasContext *dc, bool saved) 357525524734SRichard Henderson { 357625524734SRichard Henderson if (!supervisor(dc)) { 357725524734SRichard Henderson return raise_priv(dc); 357825524734SRichard Henderson } 357925524734SRichard Henderson if (saved) { 358025524734SRichard Henderson gen_helper_saved(tcg_env); 358125524734SRichard Henderson } else { 358225524734SRichard Henderson gen_helper_restored(tcg_env); 358325524734SRichard Henderson } 358425524734SRichard Henderson return advance_pc(dc); 358525524734SRichard Henderson } 358625524734SRichard Henderson 358725524734SRichard Henderson TRANS(SAVED, 64, do_saved_restored, true) 358825524734SRichard Henderson TRANS(RESTORED, 64, do_saved_restored, false) 358925524734SRichard Henderson 3590d3825800SRichard Henderson static bool trans_NOP(DisasContext *dc, arg_NOP *a) 3591d3825800SRichard Henderson { 3592d3825800SRichard Henderson return advance_pc(dc); 3593d3825800SRichard Henderson } 3594d3825800SRichard Henderson 35950faef01bSRichard Henderson /* 35960faef01bSRichard Henderson * TODO: Need a feature bit for sparcv8. 35970faef01bSRichard Henderson * In the meantime, treat all 32-bit cpus like sparcv7. 35980faef01bSRichard Henderson */ 35995458fd31SRichard Henderson TRANS(NOP_v7, 32, trans_NOP, a) 36005458fd31SRichard Henderson TRANS(NOP_v9, 64, trans_NOP, a) 36010faef01bSRichard Henderson 3602b597eedcSRichard Henderson static bool do_arith_int(DisasContext *dc, arg_r_r_ri_cc *a, 3603428881deSRichard Henderson void (*func)(TCGv, TCGv, TCGv), 36042a45b736SRichard Henderson void (*funci)(TCGv, TCGv, target_long), 36052a45b736SRichard Henderson bool logic_cc) 3606428881deSRichard Henderson { 3607428881deSRichard Henderson TCGv dst, src1; 3608428881deSRichard Henderson 3609428881deSRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 3610428881deSRichard Henderson if (!a->imm && a->rs2_or_imm & ~0x1f) { 3611428881deSRichard Henderson return false; 3612428881deSRichard Henderson } 3613428881deSRichard Henderson 36142a45b736SRichard Henderson if (logic_cc) { 36152a45b736SRichard Henderson dst = cpu_cc_N; 3616428881deSRichard Henderson } else { 3617428881deSRichard Henderson dst = gen_dest_gpr(dc, a->rd); 3618428881deSRichard Henderson } 3619428881deSRichard Henderson src1 = gen_load_gpr(dc, a->rs1); 3620428881deSRichard Henderson 3621428881deSRichard Henderson if (a->imm || a->rs2_or_imm == 0) { 3622428881deSRichard Henderson if (funci) { 3623428881deSRichard Henderson funci(dst, src1, a->rs2_or_imm); 3624428881deSRichard Henderson } else { 3625428881deSRichard Henderson func(dst, src1, tcg_constant_tl(a->rs2_or_imm)); 3626428881deSRichard Henderson } 3627428881deSRichard Henderson } else { 3628428881deSRichard Henderson func(dst, src1, cpu_regs[a->rs2_or_imm]); 3629428881deSRichard Henderson } 36302a45b736SRichard Henderson 36312a45b736SRichard Henderson if (logic_cc) { 36322a45b736SRichard Henderson if (TARGET_LONG_BITS == 64) { 36332a45b736SRichard Henderson tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N); 36342a45b736SRichard Henderson tcg_gen_movi_tl(cpu_icc_C, 0); 36352a45b736SRichard Henderson } 36362a45b736SRichard Henderson tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N); 36372a45b736SRichard Henderson tcg_gen_movi_tl(cpu_cc_C, 0); 36382a45b736SRichard Henderson tcg_gen_movi_tl(cpu_cc_V, 0); 36392a45b736SRichard Henderson } 36402a45b736SRichard Henderson 3641428881deSRichard Henderson gen_store_gpr(dc, a->rd, dst); 3642428881deSRichard Henderson return advance_pc(dc); 3643428881deSRichard Henderson } 3644428881deSRichard Henderson 3645b597eedcSRichard Henderson static bool do_arith(DisasContext *dc, arg_r_r_ri_cc *a, 3646428881deSRichard Henderson void (*func)(TCGv, TCGv, TCGv), 3647428881deSRichard Henderson void (*funci)(TCGv, TCGv, target_long), 3648428881deSRichard Henderson void (*func_cc)(TCGv, TCGv, TCGv)) 3649428881deSRichard Henderson { 3650428881deSRichard Henderson if (a->cc) { 3651b597eedcSRichard Henderson return do_arith_int(dc, a, func_cc, NULL, false); 3652428881deSRichard Henderson } 3653b597eedcSRichard Henderson return do_arith_int(dc, a, func, funci, false); 3654428881deSRichard Henderson } 3655428881deSRichard Henderson 3656428881deSRichard Henderson static bool do_logic(DisasContext *dc, arg_r_r_ri_cc *a, 3657428881deSRichard Henderson void (*func)(TCGv, TCGv, TCGv), 3658428881deSRichard Henderson void (*funci)(TCGv, TCGv, target_long)) 3659428881deSRichard Henderson { 3660b597eedcSRichard Henderson return do_arith_int(dc, a, func, funci, a->cc); 3661428881deSRichard Henderson } 3662428881deSRichard Henderson 3663b597eedcSRichard Henderson TRANS(ADD, ALL, do_arith, a, tcg_gen_add_tl, tcg_gen_addi_tl, gen_op_addcc) 3664b597eedcSRichard Henderson TRANS(SUB, ALL, do_arith, a, tcg_gen_sub_tl, tcg_gen_subi_tl, gen_op_subcc) 3665b597eedcSRichard Henderson TRANS(ADDC, ALL, do_arith, a, gen_op_addc, NULL, gen_op_addccc) 3666b597eedcSRichard Henderson TRANS(SUBC, ALL, do_arith, a, gen_op_subc, NULL, gen_op_subccc) 3667428881deSRichard Henderson 3668b597eedcSRichard Henderson TRANS(TADDcc, ALL, do_arith, a, NULL, NULL, gen_op_taddcc) 3669b597eedcSRichard Henderson TRANS(TSUBcc, ALL, do_arith, a, NULL, NULL, gen_op_tsubcc) 3670b597eedcSRichard Henderson TRANS(TADDccTV, ALL, do_arith, a, NULL, NULL, gen_op_taddcctv) 3671b597eedcSRichard Henderson TRANS(TSUBccTV, ALL, do_arith, a, NULL, NULL, gen_op_tsubcctv) 3672a9aba13dSRichard Henderson 3673428881deSRichard Henderson TRANS(AND, ALL, do_logic, a, tcg_gen_and_tl, tcg_gen_andi_tl) 3674428881deSRichard Henderson TRANS(XOR, ALL, do_logic, a, tcg_gen_xor_tl, tcg_gen_xori_tl) 3675428881deSRichard Henderson TRANS(ANDN, ALL, do_logic, a, tcg_gen_andc_tl, NULL) 3676428881deSRichard Henderson TRANS(ORN, ALL, do_logic, a, tcg_gen_orc_tl, NULL) 3677428881deSRichard Henderson TRANS(XORN, ALL, do_logic, a, tcg_gen_eqv_tl, NULL) 3678428881deSRichard Henderson 3679b597eedcSRichard Henderson TRANS(MULX, 64, do_arith, a, tcg_gen_mul_tl, tcg_gen_muli_tl, NULL) 3680b5372650SRichard Henderson TRANS(UMUL, MUL, do_logic, a, gen_op_umul, NULL) 3681b5372650SRichard Henderson TRANS(SMUL, MUL, do_logic, a, gen_op_smul, NULL) 3682b597eedcSRichard Henderson TRANS(MULScc, ALL, do_arith, a, NULL, NULL, gen_op_mulscc) 368322188d7dSRichard Henderson 36843a6b8de3SRichard Henderson TRANS(UDIVcc, DIV, do_arith, a, NULL, NULL, gen_op_udivcc) 3685b597eedcSRichard Henderson TRANS(SDIV, DIV, do_arith, a, gen_op_sdiv, NULL, gen_op_sdivcc) 36864ee85ea9SRichard Henderson 36879c6ec5bcSRichard Henderson /* TODO: Should have feature bit -- comes in with UltraSparc T2. */ 3688b597eedcSRichard Henderson TRANS(POPC, 64, do_arith, a, gen_op_popc, NULL, NULL) 36899c6ec5bcSRichard Henderson 3690428881deSRichard Henderson static bool trans_OR(DisasContext *dc, arg_r_r_ri_cc *a) 3691428881deSRichard Henderson { 3692428881deSRichard Henderson /* OR with %g0 is the canonical alias for MOV. */ 3693428881deSRichard Henderson if (!a->cc && a->rs1 == 0) { 3694428881deSRichard Henderson if (a->imm || a->rs2_or_imm == 0) { 3695428881deSRichard Henderson gen_store_gpr(dc, a->rd, tcg_constant_tl(a->rs2_or_imm)); 3696428881deSRichard Henderson } else if (a->rs2_or_imm & ~0x1f) { 3697428881deSRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 3698428881deSRichard Henderson return false; 3699428881deSRichard Henderson } else { 3700428881deSRichard Henderson gen_store_gpr(dc, a->rd, cpu_regs[a->rs2_or_imm]); 3701428881deSRichard Henderson } 3702428881deSRichard Henderson return advance_pc(dc); 3703428881deSRichard Henderson } 3704428881deSRichard Henderson return do_logic(dc, a, tcg_gen_or_tl, tcg_gen_ori_tl); 3705428881deSRichard Henderson } 3706428881deSRichard Henderson 37073a6b8de3SRichard Henderson static bool trans_UDIV(DisasContext *dc, arg_r_r_ri *a) 37083a6b8de3SRichard Henderson { 37093a6b8de3SRichard Henderson TCGv_i64 t1, t2; 37103a6b8de3SRichard Henderson TCGv dst; 37113a6b8de3SRichard Henderson 37123a6b8de3SRichard Henderson if (!avail_DIV(dc)) { 37133a6b8de3SRichard Henderson return false; 37143a6b8de3SRichard Henderson } 37153a6b8de3SRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 37163a6b8de3SRichard Henderson if (!a->imm && a->rs2_or_imm & ~0x1f) { 37173a6b8de3SRichard Henderson return false; 37183a6b8de3SRichard Henderson } 37193a6b8de3SRichard Henderson 37203a6b8de3SRichard Henderson if (unlikely(a->rs2_or_imm == 0)) { 37213a6b8de3SRichard Henderson gen_exception(dc, TT_DIV_ZERO); 37223a6b8de3SRichard Henderson return true; 37233a6b8de3SRichard Henderson } 37243a6b8de3SRichard Henderson 37253a6b8de3SRichard Henderson if (a->imm) { 37263a6b8de3SRichard Henderson t2 = tcg_constant_i64((uint32_t)a->rs2_or_imm); 37273a6b8de3SRichard Henderson } else { 37283a6b8de3SRichard Henderson TCGLabel *lab; 37293a6b8de3SRichard Henderson TCGv_i32 n2; 37303a6b8de3SRichard Henderson 37313a6b8de3SRichard Henderson finishing_insn(dc); 37323a6b8de3SRichard Henderson flush_cond(dc); 37333a6b8de3SRichard Henderson 37343a6b8de3SRichard Henderson n2 = tcg_temp_new_i32(); 37353a6b8de3SRichard Henderson tcg_gen_trunc_tl_i32(n2, cpu_regs[a->rs2_or_imm]); 37363a6b8de3SRichard Henderson 37373a6b8de3SRichard Henderson lab = delay_exception(dc, TT_DIV_ZERO); 37383a6b8de3SRichard Henderson tcg_gen_brcondi_i32(TCG_COND_EQ, n2, 0, lab); 37393a6b8de3SRichard Henderson 37403a6b8de3SRichard Henderson t2 = tcg_temp_new_i64(); 37413a6b8de3SRichard Henderson #ifdef TARGET_SPARC64 37423a6b8de3SRichard Henderson tcg_gen_ext32u_i64(t2, cpu_regs[a->rs2_or_imm]); 37433a6b8de3SRichard Henderson #else 37443a6b8de3SRichard Henderson tcg_gen_extu_i32_i64(t2, cpu_regs[a->rs2_or_imm]); 37453a6b8de3SRichard Henderson #endif 37463a6b8de3SRichard Henderson } 37473a6b8de3SRichard Henderson 37483a6b8de3SRichard Henderson t1 = tcg_temp_new_i64(); 37493a6b8de3SRichard Henderson tcg_gen_concat_tl_i64(t1, gen_load_gpr(dc, a->rs1), cpu_y); 37503a6b8de3SRichard Henderson 37513a6b8de3SRichard Henderson tcg_gen_divu_i64(t1, t1, t2); 37523a6b8de3SRichard Henderson tcg_gen_umin_i64(t1, t1, tcg_constant_i64(UINT32_MAX)); 37533a6b8de3SRichard Henderson 37543a6b8de3SRichard Henderson dst = gen_dest_gpr(dc, a->rd); 37553a6b8de3SRichard Henderson tcg_gen_trunc_i64_tl(dst, t1); 37563a6b8de3SRichard Henderson gen_store_gpr(dc, a->rd, dst); 37573a6b8de3SRichard Henderson return advance_pc(dc); 37583a6b8de3SRichard Henderson } 37593a6b8de3SRichard Henderson 3760f3141174SRichard Henderson static bool trans_UDIVX(DisasContext *dc, arg_r_r_ri *a) 3761f3141174SRichard Henderson { 3762f3141174SRichard Henderson TCGv dst, src1, src2; 3763f3141174SRichard Henderson 3764f3141174SRichard Henderson if (!avail_64(dc)) { 3765f3141174SRichard Henderson return false; 3766f3141174SRichard Henderson } 3767f3141174SRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 3768f3141174SRichard Henderson if (!a->imm && a->rs2_or_imm & ~0x1f) { 3769f3141174SRichard Henderson return false; 3770f3141174SRichard Henderson } 3771f3141174SRichard Henderson 3772f3141174SRichard Henderson if (unlikely(a->rs2_or_imm == 0)) { 3773f3141174SRichard Henderson gen_exception(dc, TT_DIV_ZERO); 3774f3141174SRichard Henderson return true; 3775f3141174SRichard Henderson } 3776f3141174SRichard Henderson 3777f3141174SRichard Henderson if (a->imm) { 3778f3141174SRichard Henderson src2 = tcg_constant_tl(a->rs2_or_imm); 3779f3141174SRichard Henderson } else { 3780f3141174SRichard Henderson TCGLabel *lab; 3781f3141174SRichard Henderson 3782f3141174SRichard Henderson finishing_insn(dc); 3783f3141174SRichard Henderson flush_cond(dc); 3784f3141174SRichard Henderson 3785f3141174SRichard Henderson lab = delay_exception(dc, TT_DIV_ZERO); 3786f3141174SRichard Henderson src2 = cpu_regs[a->rs2_or_imm]; 3787f3141174SRichard Henderson tcg_gen_brcondi_tl(TCG_COND_EQ, src2, 0, lab); 3788f3141174SRichard Henderson } 3789f3141174SRichard Henderson 3790f3141174SRichard Henderson dst = gen_dest_gpr(dc, a->rd); 3791f3141174SRichard Henderson src1 = gen_load_gpr(dc, a->rs1); 3792f3141174SRichard Henderson 3793f3141174SRichard Henderson tcg_gen_divu_tl(dst, src1, src2); 3794f3141174SRichard Henderson gen_store_gpr(dc, a->rd, dst); 3795f3141174SRichard Henderson return advance_pc(dc); 3796f3141174SRichard Henderson } 3797f3141174SRichard Henderson 3798f3141174SRichard Henderson static bool trans_SDIVX(DisasContext *dc, arg_r_r_ri *a) 3799f3141174SRichard Henderson { 3800f3141174SRichard Henderson TCGv dst, src1, src2; 3801f3141174SRichard Henderson 3802f3141174SRichard Henderson if (!avail_64(dc)) { 3803f3141174SRichard Henderson return false; 3804f3141174SRichard Henderson } 3805f3141174SRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 3806f3141174SRichard Henderson if (!a->imm && a->rs2_or_imm & ~0x1f) { 3807f3141174SRichard Henderson return false; 3808f3141174SRichard Henderson } 3809f3141174SRichard Henderson 3810f3141174SRichard Henderson if (unlikely(a->rs2_or_imm == 0)) { 3811f3141174SRichard Henderson gen_exception(dc, TT_DIV_ZERO); 3812f3141174SRichard Henderson return true; 3813f3141174SRichard Henderson } 3814f3141174SRichard Henderson 3815f3141174SRichard Henderson dst = gen_dest_gpr(dc, a->rd); 3816f3141174SRichard Henderson src1 = gen_load_gpr(dc, a->rs1); 3817f3141174SRichard Henderson 3818f3141174SRichard Henderson if (a->imm) { 3819f3141174SRichard Henderson if (unlikely(a->rs2_or_imm == -1)) { 3820f3141174SRichard Henderson tcg_gen_neg_tl(dst, src1); 3821f3141174SRichard Henderson gen_store_gpr(dc, a->rd, dst); 3822f3141174SRichard Henderson return advance_pc(dc); 3823f3141174SRichard Henderson } 3824f3141174SRichard Henderson src2 = tcg_constant_tl(a->rs2_or_imm); 3825f3141174SRichard Henderson } else { 3826f3141174SRichard Henderson TCGLabel *lab; 3827f3141174SRichard Henderson TCGv t1, t2; 3828f3141174SRichard Henderson 3829f3141174SRichard Henderson finishing_insn(dc); 3830f3141174SRichard Henderson flush_cond(dc); 3831f3141174SRichard Henderson 3832f3141174SRichard Henderson lab = delay_exception(dc, TT_DIV_ZERO); 3833f3141174SRichard Henderson src2 = cpu_regs[a->rs2_or_imm]; 3834f3141174SRichard Henderson tcg_gen_brcondi_tl(TCG_COND_EQ, src2, 0, lab); 3835f3141174SRichard Henderson 3836f3141174SRichard Henderson /* 3837f3141174SRichard Henderson * Need to avoid INT64_MIN / -1, which will trap on x86 host. 3838f3141174SRichard Henderson * Set SRC2 to 1 as a new divisor, to produce the correct result. 3839f3141174SRichard Henderson */ 3840f3141174SRichard Henderson t1 = tcg_temp_new(); 3841f3141174SRichard Henderson t2 = tcg_temp_new(); 3842f3141174SRichard Henderson tcg_gen_setcondi_tl(TCG_COND_EQ, t1, src1, (target_long)INT64_MIN); 3843f3141174SRichard Henderson tcg_gen_setcondi_tl(TCG_COND_EQ, t2, src2, -1); 3844f3141174SRichard Henderson tcg_gen_and_tl(t1, t1, t2); 3845f3141174SRichard Henderson tcg_gen_movcond_tl(TCG_COND_NE, t1, t1, tcg_constant_tl(0), 3846f3141174SRichard Henderson tcg_constant_tl(1), src2); 3847f3141174SRichard Henderson src2 = t1; 3848f3141174SRichard Henderson } 3849f3141174SRichard Henderson 3850f3141174SRichard Henderson tcg_gen_div_tl(dst, src1, src2); 3851f3141174SRichard Henderson gen_store_gpr(dc, a->rd, dst); 3852f3141174SRichard Henderson return advance_pc(dc); 3853f3141174SRichard Henderson } 3854f3141174SRichard Henderson 3855b88ce6f2SRichard Henderson static bool gen_edge(DisasContext *dc, arg_r_r_r *a, 385643db5838SRichard Henderson int width, bool cc, bool little_endian) 3857b88ce6f2SRichard Henderson { 385843db5838SRichard Henderson TCGv dst, s1, s2, l, r, t, m; 385943db5838SRichard Henderson uint64_t amask = address_mask_i(dc, -8); 3860b88ce6f2SRichard Henderson 3861b88ce6f2SRichard Henderson dst = gen_dest_gpr(dc, a->rd); 3862b88ce6f2SRichard Henderson s1 = gen_load_gpr(dc, a->rs1); 3863b88ce6f2SRichard Henderson s2 = gen_load_gpr(dc, a->rs2); 3864b88ce6f2SRichard Henderson 3865b88ce6f2SRichard Henderson if (cc) { 3866f828df74SRichard Henderson gen_op_subcc(cpu_cc_N, s1, s2); 3867b88ce6f2SRichard Henderson } 3868b88ce6f2SRichard Henderson 386943db5838SRichard Henderson l = tcg_temp_new(); 387043db5838SRichard Henderson r = tcg_temp_new(); 387143db5838SRichard Henderson t = tcg_temp_new(); 387243db5838SRichard Henderson 3873b88ce6f2SRichard Henderson switch (width) { 3874b88ce6f2SRichard Henderson case 8: 387543db5838SRichard Henderson tcg_gen_andi_tl(l, s1, 7); 387643db5838SRichard Henderson tcg_gen_andi_tl(r, s2, 7); 387743db5838SRichard Henderson tcg_gen_xori_tl(r, r, 7); 387843db5838SRichard Henderson m = tcg_constant_tl(0xff); 3879b88ce6f2SRichard Henderson break; 3880b88ce6f2SRichard Henderson case 16: 388143db5838SRichard Henderson tcg_gen_extract_tl(l, s1, 1, 2); 388243db5838SRichard Henderson tcg_gen_extract_tl(r, s2, 1, 2); 388343db5838SRichard Henderson tcg_gen_xori_tl(r, r, 3); 388443db5838SRichard Henderson m = tcg_constant_tl(0xf); 3885b88ce6f2SRichard Henderson break; 3886b88ce6f2SRichard Henderson case 32: 388743db5838SRichard Henderson tcg_gen_extract_tl(l, s1, 2, 1); 388843db5838SRichard Henderson tcg_gen_extract_tl(r, s2, 2, 1); 388943db5838SRichard Henderson tcg_gen_xori_tl(r, r, 1); 389043db5838SRichard Henderson m = tcg_constant_tl(0x3); 3891b88ce6f2SRichard Henderson break; 3892b88ce6f2SRichard Henderson default: 3893b88ce6f2SRichard Henderson abort(); 3894b88ce6f2SRichard Henderson } 3895b88ce6f2SRichard Henderson 389643db5838SRichard Henderson /* Compute Left Edge */ 389743db5838SRichard Henderson if (little_endian) { 389843db5838SRichard Henderson tcg_gen_shl_tl(l, m, l); 389943db5838SRichard Henderson tcg_gen_and_tl(l, l, m); 390043db5838SRichard Henderson } else { 390143db5838SRichard Henderson tcg_gen_shr_tl(l, m, l); 390243db5838SRichard Henderson } 390343db5838SRichard Henderson /* Compute Right Edge */ 390443db5838SRichard Henderson if (little_endian) { 390543db5838SRichard Henderson tcg_gen_shr_tl(r, m, r); 390643db5838SRichard Henderson } else { 390743db5838SRichard Henderson tcg_gen_shl_tl(r, m, r); 390843db5838SRichard Henderson tcg_gen_and_tl(r, r, m); 390943db5838SRichard Henderson } 3910b88ce6f2SRichard Henderson 391143db5838SRichard Henderson /* Compute dst = (s1 == s2 under amask ? l : l & r) */ 391243db5838SRichard Henderson tcg_gen_xor_tl(t, s1, s2); 391343db5838SRichard Henderson tcg_gen_and_tl(r, r, l); 391443db5838SRichard Henderson tcg_gen_movcond_tl(TCG_COND_TSTEQ, dst, t, tcg_constant_tl(amask), r, l); 3915b88ce6f2SRichard Henderson 3916b88ce6f2SRichard Henderson gen_store_gpr(dc, a->rd, dst); 3917b88ce6f2SRichard Henderson return advance_pc(dc); 3918b88ce6f2SRichard Henderson } 3919b88ce6f2SRichard Henderson 3920b88ce6f2SRichard Henderson TRANS(EDGE8cc, VIS1, gen_edge, a, 8, 1, 0) 3921b88ce6f2SRichard Henderson TRANS(EDGE8Lcc, VIS1, gen_edge, a, 8, 1, 1) 3922b88ce6f2SRichard Henderson TRANS(EDGE16cc, VIS1, gen_edge, a, 16, 1, 0) 3923b88ce6f2SRichard Henderson TRANS(EDGE16Lcc, VIS1, gen_edge, a, 16, 1, 1) 3924b88ce6f2SRichard Henderson TRANS(EDGE32cc, VIS1, gen_edge, a, 32, 1, 0) 3925b88ce6f2SRichard Henderson TRANS(EDGE32Lcc, VIS1, gen_edge, a, 32, 1, 1) 3926b88ce6f2SRichard Henderson 3927b88ce6f2SRichard Henderson TRANS(EDGE8N, VIS2, gen_edge, a, 8, 0, 0) 3928b88ce6f2SRichard Henderson TRANS(EDGE8LN, VIS2, gen_edge, a, 8, 0, 1) 3929b88ce6f2SRichard Henderson TRANS(EDGE16N, VIS2, gen_edge, a, 16, 0, 0) 3930b88ce6f2SRichard Henderson TRANS(EDGE16LN, VIS2, gen_edge, a, 16, 0, 1) 3931b88ce6f2SRichard Henderson TRANS(EDGE32N, VIS2, gen_edge, a, 32, 0, 0) 3932b88ce6f2SRichard Henderson TRANS(EDGE32LN, VIS2, gen_edge, a, 32, 0, 1) 3933b88ce6f2SRichard Henderson 3934875ce392SRichard Henderson static bool do_rr(DisasContext *dc, arg_r_r *a, 3935875ce392SRichard Henderson void (*func)(TCGv, TCGv)) 3936875ce392SRichard Henderson { 3937875ce392SRichard Henderson TCGv dst = gen_dest_gpr(dc, a->rd); 3938875ce392SRichard Henderson TCGv src = gen_load_gpr(dc, a->rs); 3939875ce392SRichard Henderson 3940875ce392SRichard Henderson func(dst, src); 3941875ce392SRichard Henderson gen_store_gpr(dc, a->rd, dst); 3942875ce392SRichard Henderson return advance_pc(dc); 3943875ce392SRichard Henderson } 3944875ce392SRichard Henderson 3945875ce392SRichard Henderson TRANS(LZCNT, VIS3, do_rr, a, gen_op_lzcnt) 3946875ce392SRichard Henderson 394745bfed3bSRichard Henderson static bool do_rrr(DisasContext *dc, arg_r_r_r *a, 394845bfed3bSRichard Henderson void (*func)(TCGv, TCGv, TCGv)) 394945bfed3bSRichard Henderson { 395045bfed3bSRichard Henderson TCGv dst = gen_dest_gpr(dc, a->rd); 395145bfed3bSRichard Henderson TCGv src1 = gen_load_gpr(dc, a->rs1); 395245bfed3bSRichard Henderson TCGv src2 = gen_load_gpr(dc, a->rs2); 395345bfed3bSRichard Henderson 395445bfed3bSRichard Henderson func(dst, src1, src2); 395545bfed3bSRichard Henderson gen_store_gpr(dc, a->rd, dst); 395645bfed3bSRichard Henderson return advance_pc(dc); 395745bfed3bSRichard Henderson } 395845bfed3bSRichard Henderson 395945bfed3bSRichard Henderson TRANS(ARRAY8, VIS1, do_rrr, a, gen_helper_array8) 396045bfed3bSRichard Henderson TRANS(ARRAY16, VIS1, do_rrr, a, gen_op_array16) 396145bfed3bSRichard Henderson TRANS(ARRAY32, VIS1, do_rrr, a, gen_op_array32) 396245bfed3bSRichard Henderson 3963015fc6fcSRichard Henderson TRANS(ADDXC, VIS3, do_rrr, a, gen_op_addxc) 3964015fc6fcSRichard Henderson TRANS(ADDXCcc, VIS3, do_rrr, a, gen_op_addxccc) 3965015fc6fcSRichard Henderson 3966680af1b4SRichard Henderson TRANS(UMULXHI, VIS3, do_rrr, a, gen_op_umulxhi) 3967680af1b4SRichard Henderson 39689e20ca94SRichard Henderson static void gen_op_alignaddr(TCGv dst, TCGv s1, TCGv s2) 39699e20ca94SRichard Henderson { 39709e20ca94SRichard Henderson #ifdef TARGET_SPARC64 39719e20ca94SRichard Henderson TCGv tmp = tcg_temp_new(); 39729e20ca94SRichard Henderson 39739e20ca94SRichard Henderson tcg_gen_add_tl(tmp, s1, s2); 39749e20ca94SRichard Henderson tcg_gen_andi_tl(dst, tmp, -8); 39759e20ca94SRichard Henderson tcg_gen_deposit_tl(cpu_gsr, cpu_gsr, tmp, 0, 3); 39769e20ca94SRichard Henderson #else 39779e20ca94SRichard Henderson g_assert_not_reached(); 39789e20ca94SRichard Henderson #endif 39799e20ca94SRichard Henderson } 39809e20ca94SRichard Henderson 39819e20ca94SRichard Henderson static void gen_op_alignaddrl(TCGv dst, TCGv s1, TCGv s2) 39829e20ca94SRichard Henderson { 39839e20ca94SRichard Henderson #ifdef TARGET_SPARC64 39849e20ca94SRichard Henderson TCGv tmp = tcg_temp_new(); 39859e20ca94SRichard Henderson 39869e20ca94SRichard Henderson tcg_gen_add_tl(tmp, s1, s2); 39879e20ca94SRichard Henderson tcg_gen_andi_tl(dst, tmp, -8); 39889e20ca94SRichard Henderson tcg_gen_neg_tl(tmp, tmp); 39899e20ca94SRichard Henderson tcg_gen_deposit_tl(cpu_gsr, cpu_gsr, tmp, 0, 3); 39909e20ca94SRichard Henderson #else 39919e20ca94SRichard Henderson g_assert_not_reached(); 39929e20ca94SRichard Henderson #endif 39939e20ca94SRichard Henderson } 39949e20ca94SRichard Henderson 39959e20ca94SRichard Henderson TRANS(ALIGNADDR, VIS1, do_rrr, a, gen_op_alignaddr) 39969e20ca94SRichard Henderson TRANS(ALIGNADDRL, VIS1, do_rrr, a, gen_op_alignaddrl) 39979e20ca94SRichard Henderson 399839ca3490SRichard Henderson static void gen_op_bmask(TCGv dst, TCGv s1, TCGv s2) 399939ca3490SRichard Henderson { 400039ca3490SRichard Henderson #ifdef TARGET_SPARC64 400139ca3490SRichard Henderson tcg_gen_add_tl(dst, s1, s2); 400239ca3490SRichard Henderson tcg_gen_deposit_tl(cpu_gsr, cpu_gsr, dst, 32, 32); 400339ca3490SRichard Henderson #else 400439ca3490SRichard Henderson g_assert_not_reached(); 400539ca3490SRichard Henderson #endif 400639ca3490SRichard Henderson } 400739ca3490SRichard Henderson 400839ca3490SRichard Henderson TRANS(BMASK, VIS2, do_rrr, a, gen_op_bmask) 400939ca3490SRichard Henderson 4010c973b4e8SRichard Henderson static bool do_cmask(DisasContext *dc, int rs2, void (*func)(TCGv, TCGv, TCGv)) 4011c973b4e8SRichard Henderson { 4012c973b4e8SRichard Henderson func(cpu_gsr, cpu_gsr, gen_load_gpr(dc, rs2)); 4013c973b4e8SRichard Henderson return true; 4014c973b4e8SRichard Henderson } 4015c973b4e8SRichard Henderson 4016c973b4e8SRichard Henderson TRANS(CMASK8, VIS3, do_cmask, a->rs2, gen_helper_cmask8) 4017c973b4e8SRichard Henderson TRANS(CMASK16, VIS3, do_cmask, a->rs2, gen_helper_cmask16) 4018c973b4e8SRichard Henderson TRANS(CMASK32, VIS3, do_cmask, a->rs2, gen_helper_cmask32) 4019c973b4e8SRichard Henderson 40205fc546eeSRichard Henderson static bool do_shift_r(DisasContext *dc, arg_shiftr *a, bool l, bool u) 40215fc546eeSRichard Henderson { 40225fc546eeSRichard Henderson TCGv dst, src1, src2; 40235fc546eeSRichard Henderson 40245fc546eeSRichard Henderson /* Reject 64-bit shifts for sparc32. */ 40255fc546eeSRichard Henderson if (avail_32(dc) && a->x) { 40265fc546eeSRichard Henderson return false; 40275fc546eeSRichard Henderson } 40285fc546eeSRichard Henderson 40295fc546eeSRichard Henderson src2 = tcg_temp_new(); 40305fc546eeSRichard Henderson tcg_gen_andi_tl(src2, gen_load_gpr(dc, a->rs2), a->x ? 63 : 31); 40315fc546eeSRichard Henderson src1 = gen_load_gpr(dc, a->rs1); 40325fc546eeSRichard Henderson dst = gen_dest_gpr(dc, a->rd); 40335fc546eeSRichard Henderson 40345fc546eeSRichard Henderson if (l) { 40355fc546eeSRichard Henderson tcg_gen_shl_tl(dst, src1, src2); 40365fc546eeSRichard Henderson if (!a->x) { 40375fc546eeSRichard Henderson tcg_gen_ext32u_tl(dst, dst); 40385fc546eeSRichard Henderson } 40395fc546eeSRichard Henderson } else if (u) { 40405fc546eeSRichard Henderson if (!a->x) { 40415fc546eeSRichard Henderson tcg_gen_ext32u_tl(dst, src1); 40425fc546eeSRichard Henderson src1 = dst; 40435fc546eeSRichard Henderson } 40445fc546eeSRichard Henderson tcg_gen_shr_tl(dst, src1, src2); 40455fc546eeSRichard Henderson } else { 40465fc546eeSRichard Henderson if (!a->x) { 40475fc546eeSRichard Henderson tcg_gen_ext32s_tl(dst, src1); 40485fc546eeSRichard Henderson src1 = dst; 40495fc546eeSRichard Henderson } 40505fc546eeSRichard Henderson tcg_gen_sar_tl(dst, src1, src2); 40515fc546eeSRichard Henderson } 40525fc546eeSRichard Henderson gen_store_gpr(dc, a->rd, dst); 40535fc546eeSRichard Henderson return advance_pc(dc); 40545fc546eeSRichard Henderson } 40555fc546eeSRichard Henderson 40565fc546eeSRichard Henderson TRANS(SLL_r, ALL, do_shift_r, a, true, true) 40575fc546eeSRichard Henderson TRANS(SRL_r, ALL, do_shift_r, a, false, true) 40585fc546eeSRichard Henderson TRANS(SRA_r, ALL, do_shift_r, a, false, false) 40595fc546eeSRichard Henderson 40605fc546eeSRichard Henderson static bool do_shift_i(DisasContext *dc, arg_shifti *a, bool l, bool u) 40615fc546eeSRichard Henderson { 40625fc546eeSRichard Henderson TCGv dst, src1; 40635fc546eeSRichard Henderson 40645fc546eeSRichard Henderson /* Reject 64-bit shifts for sparc32. */ 40655fc546eeSRichard Henderson if (avail_32(dc) && (a->x || a->i >= 32)) { 40665fc546eeSRichard Henderson return false; 40675fc546eeSRichard Henderson } 40685fc546eeSRichard Henderson 40695fc546eeSRichard Henderson src1 = gen_load_gpr(dc, a->rs1); 40705fc546eeSRichard Henderson dst = gen_dest_gpr(dc, a->rd); 40715fc546eeSRichard Henderson 40725fc546eeSRichard Henderson if (avail_32(dc) || a->x) { 40735fc546eeSRichard Henderson if (l) { 40745fc546eeSRichard Henderson tcg_gen_shli_tl(dst, src1, a->i); 40755fc546eeSRichard Henderson } else if (u) { 40765fc546eeSRichard Henderson tcg_gen_shri_tl(dst, src1, a->i); 40775fc546eeSRichard Henderson } else { 40785fc546eeSRichard Henderson tcg_gen_sari_tl(dst, src1, a->i); 40795fc546eeSRichard Henderson } 40805fc546eeSRichard Henderson } else { 40815fc546eeSRichard Henderson if (l) { 40825fc546eeSRichard Henderson tcg_gen_deposit_z_tl(dst, src1, a->i, 32 - a->i); 40835fc546eeSRichard Henderson } else if (u) { 40845fc546eeSRichard Henderson tcg_gen_extract_tl(dst, src1, a->i, 32 - a->i); 40855fc546eeSRichard Henderson } else { 40865fc546eeSRichard Henderson tcg_gen_sextract_tl(dst, src1, a->i, 32 - a->i); 40875fc546eeSRichard Henderson } 40885fc546eeSRichard Henderson } 40895fc546eeSRichard Henderson gen_store_gpr(dc, a->rd, dst); 40905fc546eeSRichard Henderson return advance_pc(dc); 40915fc546eeSRichard Henderson } 40925fc546eeSRichard Henderson 40935fc546eeSRichard Henderson TRANS(SLL_i, ALL, do_shift_i, a, true, true) 40945fc546eeSRichard Henderson TRANS(SRL_i, ALL, do_shift_i, a, false, true) 40955fc546eeSRichard Henderson TRANS(SRA_i, ALL, do_shift_i, a, false, false) 40965fc546eeSRichard Henderson 4097fb4ed7aaSRichard Henderson static TCGv gen_rs2_or_imm(DisasContext *dc, bool imm, int rs2_or_imm) 4098fb4ed7aaSRichard Henderson { 4099fb4ed7aaSRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 4100fb4ed7aaSRichard Henderson if (!imm && rs2_or_imm & ~0x1f) { 4101fb4ed7aaSRichard Henderson return NULL; 4102fb4ed7aaSRichard Henderson } 4103fb4ed7aaSRichard Henderson if (imm || rs2_or_imm == 0) { 4104fb4ed7aaSRichard Henderson return tcg_constant_tl(rs2_or_imm); 4105fb4ed7aaSRichard Henderson } else { 4106fb4ed7aaSRichard Henderson return cpu_regs[rs2_or_imm]; 4107fb4ed7aaSRichard Henderson } 4108fb4ed7aaSRichard Henderson } 4109fb4ed7aaSRichard Henderson 4110fb4ed7aaSRichard Henderson static bool do_mov_cond(DisasContext *dc, DisasCompare *cmp, int rd, TCGv src2) 4111fb4ed7aaSRichard Henderson { 4112fb4ed7aaSRichard Henderson TCGv dst = gen_load_gpr(dc, rd); 4113c8507ebfSRichard Henderson TCGv c2 = tcg_constant_tl(cmp->c2); 4114fb4ed7aaSRichard Henderson 4115c8507ebfSRichard Henderson tcg_gen_movcond_tl(cmp->cond, dst, cmp->c1, c2, src2, dst); 4116fb4ed7aaSRichard Henderson gen_store_gpr(dc, rd, dst); 4117fb4ed7aaSRichard Henderson return advance_pc(dc); 4118fb4ed7aaSRichard Henderson } 4119fb4ed7aaSRichard Henderson 4120fb4ed7aaSRichard Henderson static bool trans_MOVcc(DisasContext *dc, arg_MOVcc *a) 4121fb4ed7aaSRichard Henderson { 4122fb4ed7aaSRichard Henderson TCGv src2 = gen_rs2_or_imm(dc, a->imm, a->rs2_or_imm); 4123fb4ed7aaSRichard Henderson DisasCompare cmp; 4124fb4ed7aaSRichard Henderson 4125fb4ed7aaSRichard Henderson if (src2 == NULL) { 4126fb4ed7aaSRichard Henderson return false; 4127fb4ed7aaSRichard Henderson } 4128fb4ed7aaSRichard Henderson gen_compare(&cmp, a->cc, a->cond, dc); 4129fb4ed7aaSRichard Henderson return do_mov_cond(dc, &cmp, a->rd, src2); 4130fb4ed7aaSRichard Henderson } 4131fb4ed7aaSRichard Henderson 4132fb4ed7aaSRichard Henderson static bool trans_MOVfcc(DisasContext *dc, arg_MOVfcc *a) 4133fb4ed7aaSRichard Henderson { 4134fb4ed7aaSRichard Henderson TCGv src2 = gen_rs2_or_imm(dc, a->imm, a->rs2_or_imm); 4135fb4ed7aaSRichard Henderson DisasCompare cmp; 4136fb4ed7aaSRichard Henderson 4137fb4ed7aaSRichard Henderson if (src2 == NULL) { 4138fb4ed7aaSRichard Henderson return false; 4139fb4ed7aaSRichard Henderson } 4140fb4ed7aaSRichard Henderson gen_fcompare(&cmp, a->cc, a->cond); 4141fb4ed7aaSRichard Henderson return do_mov_cond(dc, &cmp, a->rd, src2); 4142fb4ed7aaSRichard Henderson } 4143fb4ed7aaSRichard Henderson 4144fb4ed7aaSRichard Henderson static bool trans_MOVR(DisasContext *dc, arg_MOVR *a) 4145fb4ed7aaSRichard Henderson { 4146fb4ed7aaSRichard Henderson TCGv src2 = gen_rs2_or_imm(dc, a->imm, a->rs2_or_imm); 4147fb4ed7aaSRichard Henderson DisasCompare cmp; 4148fb4ed7aaSRichard Henderson 4149fb4ed7aaSRichard Henderson if (src2 == NULL) { 4150fb4ed7aaSRichard Henderson return false; 4151fb4ed7aaSRichard Henderson } 41522c4f56c9SRichard Henderson if (!gen_compare_reg(&cmp, a->cond, gen_load_gpr(dc, a->rs1))) { 41532c4f56c9SRichard Henderson return false; 41542c4f56c9SRichard Henderson } 4155fb4ed7aaSRichard Henderson return do_mov_cond(dc, &cmp, a->rd, src2); 4156fb4ed7aaSRichard Henderson } 4157fb4ed7aaSRichard Henderson 415886b82fe0SRichard Henderson static bool do_add_special(DisasContext *dc, arg_r_r_ri *a, 415986b82fe0SRichard Henderson bool (*func)(DisasContext *dc, int rd, TCGv src)) 416086b82fe0SRichard Henderson { 416186b82fe0SRichard Henderson TCGv src1, sum; 416286b82fe0SRichard Henderson 416386b82fe0SRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 416486b82fe0SRichard Henderson if (!a->imm && a->rs2_or_imm & ~0x1f) { 416586b82fe0SRichard Henderson return false; 416686b82fe0SRichard Henderson } 416786b82fe0SRichard Henderson 416886b82fe0SRichard Henderson /* 416986b82fe0SRichard Henderson * Always load the sum into a new temporary. 417086b82fe0SRichard Henderson * This is required to capture the value across a window change, 417186b82fe0SRichard Henderson * e.g. SAVE and RESTORE, and may be optimized away otherwise. 417286b82fe0SRichard Henderson */ 417386b82fe0SRichard Henderson sum = tcg_temp_new(); 417486b82fe0SRichard Henderson src1 = gen_load_gpr(dc, a->rs1); 417586b82fe0SRichard Henderson if (a->imm || a->rs2_or_imm == 0) { 417686b82fe0SRichard Henderson tcg_gen_addi_tl(sum, src1, a->rs2_or_imm); 417786b82fe0SRichard Henderson } else { 417886b82fe0SRichard Henderson tcg_gen_add_tl(sum, src1, cpu_regs[a->rs2_or_imm]); 417986b82fe0SRichard Henderson } 418086b82fe0SRichard Henderson return func(dc, a->rd, sum); 418186b82fe0SRichard Henderson } 418286b82fe0SRichard Henderson 418386b82fe0SRichard Henderson static bool do_jmpl(DisasContext *dc, int rd, TCGv src) 418486b82fe0SRichard Henderson { 418586b82fe0SRichard Henderson /* 418686b82fe0SRichard Henderson * Preserve pc across advance, so that we can delay 418786b82fe0SRichard Henderson * the writeback to rd until after src is consumed. 418886b82fe0SRichard Henderson */ 418986b82fe0SRichard Henderson target_ulong cur_pc = dc->pc; 419086b82fe0SRichard Henderson 419186b82fe0SRichard Henderson gen_check_align(dc, src, 3); 419286b82fe0SRichard Henderson 419386b82fe0SRichard Henderson gen_mov_pc_npc(dc); 419486b82fe0SRichard Henderson tcg_gen_mov_tl(cpu_npc, src); 419586b82fe0SRichard Henderson gen_address_mask(dc, cpu_npc); 419686b82fe0SRichard Henderson gen_store_gpr(dc, rd, tcg_constant_tl(cur_pc)); 419786b82fe0SRichard Henderson 419886b82fe0SRichard Henderson dc->npc = DYNAMIC_PC_LOOKUP; 419986b82fe0SRichard Henderson return true; 420086b82fe0SRichard Henderson } 420186b82fe0SRichard Henderson 420286b82fe0SRichard Henderson TRANS(JMPL, ALL, do_add_special, a, do_jmpl) 420386b82fe0SRichard Henderson 420486b82fe0SRichard Henderson static bool do_rett(DisasContext *dc, int rd, TCGv src) 420586b82fe0SRichard Henderson { 420686b82fe0SRichard Henderson if (!supervisor(dc)) { 420786b82fe0SRichard Henderson return raise_priv(dc); 420886b82fe0SRichard Henderson } 420986b82fe0SRichard Henderson 421086b82fe0SRichard Henderson gen_check_align(dc, src, 3); 421186b82fe0SRichard Henderson 421286b82fe0SRichard Henderson gen_mov_pc_npc(dc); 421386b82fe0SRichard Henderson tcg_gen_mov_tl(cpu_npc, src); 421486b82fe0SRichard Henderson gen_helper_rett(tcg_env); 421586b82fe0SRichard Henderson 421686b82fe0SRichard Henderson dc->npc = DYNAMIC_PC; 421786b82fe0SRichard Henderson return true; 421886b82fe0SRichard Henderson } 421986b82fe0SRichard Henderson 422086b82fe0SRichard Henderson TRANS(RETT, 32, do_add_special, a, do_rett) 422186b82fe0SRichard Henderson 422286b82fe0SRichard Henderson static bool do_return(DisasContext *dc, int rd, TCGv src) 422386b82fe0SRichard Henderson { 422486b82fe0SRichard Henderson gen_check_align(dc, src, 3); 42250dfae4f9SRichard Henderson gen_helper_restore(tcg_env); 422686b82fe0SRichard Henderson 422786b82fe0SRichard Henderson gen_mov_pc_npc(dc); 422886b82fe0SRichard Henderson tcg_gen_mov_tl(cpu_npc, src); 422986b82fe0SRichard Henderson gen_address_mask(dc, cpu_npc); 423086b82fe0SRichard Henderson 423186b82fe0SRichard Henderson dc->npc = DYNAMIC_PC_LOOKUP; 423286b82fe0SRichard Henderson return true; 423386b82fe0SRichard Henderson } 423486b82fe0SRichard Henderson 423586b82fe0SRichard Henderson TRANS(RETURN, 64, do_add_special, a, do_return) 423686b82fe0SRichard Henderson 4237d3825800SRichard Henderson static bool do_save(DisasContext *dc, int rd, TCGv src) 4238d3825800SRichard Henderson { 4239d3825800SRichard Henderson gen_helper_save(tcg_env); 4240d3825800SRichard Henderson gen_store_gpr(dc, rd, src); 4241d3825800SRichard Henderson return advance_pc(dc); 4242d3825800SRichard Henderson } 4243d3825800SRichard Henderson 4244d3825800SRichard Henderson TRANS(SAVE, ALL, do_add_special, a, do_save) 4245d3825800SRichard Henderson 4246d3825800SRichard Henderson static bool do_restore(DisasContext *dc, int rd, TCGv src) 4247d3825800SRichard Henderson { 4248d3825800SRichard Henderson gen_helper_restore(tcg_env); 4249d3825800SRichard Henderson gen_store_gpr(dc, rd, src); 4250d3825800SRichard Henderson return advance_pc(dc); 4251d3825800SRichard Henderson } 4252d3825800SRichard Henderson 4253d3825800SRichard Henderson TRANS(RESTORE, ALL, do_add_special, a, do_restore) 4254d3825800SRichard Henderson 42558f75b8a4SRichard Henderson static bool do_done_retry(DisasContext *dc, bool done) 42568f75b8a4SRichard Henderson { 42578f75b8a4SRichard Henderson if (!supervisor(dc)) { 42588f75b8a4SRichard Henderson return raise_priv(dc); 42598f75b8a4SRichard Henderson } 42608f75b8a4SRichard Henderson dc->npc = DYNAMIC_PC; 42618f75b8a4SRichard Henderson dc->pc = DYNAMIC_PC; 42628f75b8a4SRichard Henderson translator_io_start(&dc->base); 42638f75b8a4SRichard Henderson if (done) { 42648f75b8a4SRichard Henderson gen_helper_done(tcg_env); 42658f75b8a4SRichard Henderson } else { 42668f75b8a4SRichard Henderson gen_helper_retry(tcg_env); 42678f75b8a4SRichard Henderson } 42688f75b8a4SRichard Henderson return true; 42698f75b8a4SRichard Henderson } 42708f75b8a4SRichard Henderson 42718f75b8a4SRichard Henderson TRANS(DONE, 64, do_done_retry, true) 42728f75b8a4SRichard Henderson TRANS(RETRY, 64, do_done_retry, false) 42738f75b8a4SRichard Henderson 42740880d20bSRichard Henderson /* 42750880d20bSRichard Henderson * Major opcode 11 -- load and store instructions 42760880d20bSRichard Henderson */ 42770880d20bSRichard Henderson 42780880d20bSRichard Henderson static TCGv gen_ldst_addr(DisasContext *dc, int rs1, bool imm, int rs2_or_imm) 42790880d20bSRichard Henderson { 42800880d20bSRichard Henderson TCGv addr, tmp = NULL; 42810880d20bSRichard Henderson 42820880d20bSRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 42830880d20bSRichard Henderson if (!imm && rs2_or_imm & ~0x1f) { 42840880d20bSRichard Henderson return NULL; 42850880d20bSRichard Henderson } 42860880d20bSRichard Henderson 42870880d20bSRichard Henderson addr = gen_load_gpr(dc, rs1); 42880880d20bSRichard Henderson if (rs2_or_imm) { 42890880d20bSRichard Henderson tmp = tcg_temp_new(); 42900880d20bSRichard Henderson if (imm) { 42910880d20bSRichard Henderson tcg_gen_addi_tl(tmp, addr, rs2_or_imm); 42920880d20bSRichard Henderson } else { 42930880d20bSRichard Henderson tcg_gen_add_tl(tmp, addr, cpu_regs[rs2_or_imm]); 42940880d20bSRichard Henderson } 42950880d20bSRichard Henderson addr = tmp; 42960880d20bSRichard Henderson } 42970880d20bSRichard Henderson if (AM_CHECK(dc)) { 42980880d20bSRichard Henderson if (!tmp) { 42990880d20bSRichard Henderson tmp = tcg_temp_new(); 43000880d20bSRichard Henderson } 43010880d20bSRichard Henderson tcg_gen_ext32u_tl(tmp, addr); 43020880d20bSRichard Henderson addr = tmp; 43030880d20bSRichard Henderson } 43040880d20bSRichard Henderson return addr; 43050880d20bSRichard Henderson } 43060880d20bSRichard Henderson 43070880d20bSRichard Henderson static bool do_ld_gpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp mop) 43080880d20bSRichard Henderson { 43090880d20bSRichard Henderson TCGv reg, addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 43100880d20bSRichard Henderson DisasASI da; 43110880d20bSRichard Henderson 43120880d20bSRichard Henderson if (addr == NULL) { 43130880d20bSRichard Henderson return false; 43140880d20bSRichard Henderson } 43150880d20bSRichard Henderson da = resolve_asi(dc, a->asi, mop); 43160880d20bSRichard Henderson 43170880d20bSRichard Henderson reg = gen_dest_gpr(dc, a->rd); 431842071fc1SRichard Henderson gen_ld_asi(dc, &da, reg, addr); 43190880d20bSRichard Henderson gen_store_gpr(dc, a->rd, reg); 43200880d20bSRichard Henderson return advance_pc(dc); 43210880d20bSRichard Henderson } 43220880d20bSRichard Henderson 43230880d20bSRichard Henderson TRANS(LDUW, ALL, do_ld_gpr, a, MO_TEUL) 43240880d20bSRichard Henderson TRANS(LDUB, ALL, do_ld_gpr, a, MO_UB) 43250880d20bSRichard Henderson TRANS(LDUH, ALL, do_ld_gpr, a, MO_TEUW) 43260880d20bSRichard Henderson TRANS(LDSB, ALL, do_ld_gpr, a, MO_SB) 43270880d20bSRichard Henderson TRANS(LDSH, ALL, do_ld_gpr, a, MO_TESW) 43280880d20bSRichard Henderson TRANS(LDSW, 64, do_ld_gpr, a, MO_TESL) 43290880d20bSRichard Henderson TRANS(LDX, 64, do_ld_gpr, a, MO_TEUQ) 43300880d20bSRichard Henderson 43310880d20bSRichard Henderson static bool do_st_gpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp mop) 43320880d20bSRichard Henderson { 43330880d20bSRichard Henderson TCGv reg, addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 43340880d20bSRichard Henderson DisasASI da; 43350880d20bSRichard Henderson 43360880d20bSRichard Henderson if (addr == NULL) { 43370880d20bSRichard Henderson return false; 43380880d20bSRichard Henderson } 43390880d20bSRichard Henderson da = resolve_asi(dc, a->asi, mop); 43400880d20bSRichard Henderson 43410880d20bSRichard Henderson reg = gen_load_gpr(dc, a->rd); 434242071fc1SRichard Henderson gen_st_asi(dc, &da, reg, addr); 43430880d20bSRichard Henderson return advance_pc(dc); 43440880d20bSRichard Henderson } 43450880d20bSRichard Henderson 43460880d20bSRichard Henderson TRANS(STW, ALL, do_st_gpr, a, MO_TEUL) 43470880d20bSRichard Henderson TRANS(STB, ALL, do_st_gpr, a, MO_UB) 43480880d20bSRichard Henderson TRANS(STH, ALL, do_st_gpr, a, MO_TEUW) 43490880d20bSRichard Henderson TRANS(STX, 64, do_st_gpr, a, MO_TEUQ) 43500880d20bSRichard Henderson 43510880d20bSRichard Henderson static bool trans_LDD(DisasContext *dc, arg_r_r_ri_asi *a) 43520880d20bSRichard Henderson { 43530880d20bSRichard Henderson TCGv addr; 43540880d20bSRichard Henderson DisasASI da; 43550880d20bSRichard Henderson 43560880d20bSRichard Henderson if (a->rd & 1) { 43570880d20bSRichard Henderson return false; 43580880d20bSRichard Henderson } 43590880d20bSRichard Henderson addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 43600880d20bSRichard Henderson if (addr == NULL) { 43610880d20bSRichard Henderson return false; 43620880d20bSRichard Henderson } 43630880d20bSRichard Henderson da = resolve_asi(dc, a->asi, MO_TEUQ); 436442071fc1SRichard Henderson gen_ldda_asi(dc, &da, addr, a->rd); 43650880d20bSRichard Henderson return advance_pc(dc); 43660880d20bSRichard Henderson } 43670880d20bSRichard Henderson 43680880d20bSRichard Henderson static bool trans_STD(DisasContext *dc, arg_r_r_ri_asi *a) 43690880d20bSRichard Henderson { 43700880d20bSRichard Henderson TCGv addr; 43710880d20bSRichard Henderson DisasASI da; 43720880d20bSRichard Henderson 43730880d20bSRichard Henderson if (a->rd & 1) { 43740880d20bSRichard Henderson return false; 43750880d20bSRichard Henderson } 43760880d20bSRichard Henderson addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 43770880d20bSRichard Henderson if (addr == NULL) { 43780880d20bSRichard Henderson return false; 43790880d20bSRichard Henderson } 43800880d20bSRichard Henderson da = resolve_asi(dc, a->asi, MO_TEUQ); 438142071fc1SRichard Henderson gen_stda_asi(dc, &da, addr, a->rd); 43820880d20bSRichard Henderson return advance_pc(dc); 43830880d20bSRichard Henderson } 43840880d20bSRichard Henderson 4385cf07cd1eSRichard Henderson static bool trans_LDSTUB(DisasContext *dc, arg_r_r_ri_asi *a) 4386cf07cd1eSRichard Henderson { 4387cf07cd1eSRichard Henderson TCGv addr, reg; 4388cf07cd1eSRichard Henderson DisasASI da; 4389cf07cd1eSRichard Henderson 4390cf07cd1eSRichard Henderson addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 4391cf07cd1eSRichard Henderson if (addr == NULL) { 4392cf07cd1eSRichard Henderson return false; 4393cf07cd1eSRichard Henderson } 4394cf07cd1eSRichard Henderson da = resolve_asi(dc, a->asi, MO_UB); 4395cf07cd1eSRichard Henderson 4396cf07cd1eSRichard Henderson reg = gen_dest_gpr(dc, a->rd); 4397cf07cd1eSRichard Henderson gen_ldstub_asi(dc, &da, reg, addr); 4398cf07cd1eSRichard Henderson gen_store_gpr(dc, a->rd, reg); 4399cf07cd1eSRichard Henderson return advance_pc(dc); 4400cf07cd1eSRichard Henderson } 4401cf07cd1eSRichard Henderson 4402dca544b9SRichard Henderson static bool trans_SWAP(DisasContext *dc, arg_r_r_ri_asi *a) 4403dca544b9SRichard Henderson { 4404dca544b9SRichard Henderson TCGv addr, dst, src; 4405dca544b9SRichard Henderson DisasASI da; 4406dca544b9SRichard Henderson 4407dca544b9SRichard Henderson addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 4408dca544b9SRichard Henderson if (addr == NULL) { 4409dca544b9SRichard Henderson return false; 4410dca544b9SRichard Henderson } 4411dca544b9SRichard Henderson da = resolve_asi(dc, a->asi, MO_TEUL); 4412dca544b9SRichard Henderson 4413dca544b9SRichard Henderson dst = gen_dest_gpr(dc, a->rd); 4414dca544b9SRichard Henderson src = gen_load_gpr(dc, a->rd); 4415dca544b9SRichard Henderson gen_swap_asi(dc, &da, dst, src, addr); 4416dca544b9SRichard Henderson gen_store_gpr(dc, a->rd, dst); 4417dca544b9SRichard Henderson return advance_pc(dc); 4418dca544b9SRichard Henderson } 4419dca544b9SRichard Henderson 4420d0a11d25SRichard Henderson static bool do_casa(DisasContext *dc, arg_r_r_ri_asi *a, MemOp mop) 4421d0a11d25SRichard Henderson { 4422d0a11d25SRichard Henderson TCGv addr, o, n, c; 4423d0a11d25SRichard Henderson DisasASI da; 4424d0a11d25SRichard Henderson 4425d0a11d25SRichard Henderson addr = gen_ldst_addr(dc, a->rs1, true, 0); 4426d0a11d25SRichard Henderson if (addr == NULL) { 4427d0a11d25SRichard Henderson return false; 4428d0a11d25SRichard Henderson } 4429d0a11d25SRichard Henderson da = resolve_asi(dc, a->asi, mop); 4430d0a11d25SRichard Henderson 4431d0a11d25SRichard Henderson o = gen_dest_gpr(dc, a->rd); 4432d0a11d25SRichard Henderson n = gen_load_gpr(dc, a->rd); 4433d0a11d25SRichard Henderson c = gen_load_gpr(dc, a->rs2_or_imm); 4434d0a11d25SRichard Henderson gen_cas_asi(dc, &da, o, n, c, addr); 4435d0a11d25SRichard Henderson gen_store_gpr(dc, a->rd, o); 4436d0a11d25SRichard Henderson return advance_pc(dc); 4437d0a11d25SRichard Henderson } 4438d0a11d25SRichard Henderson 4439d0a11d25SRichard Henderson TRANS(CASA, CASA, do_casa, a, MO_TEUL) 4440d0a11d25SRichard Henderson TRANS(CASXA, 64, do_casa, a, MO_TEUQ) 4441d0a11d25SRichard Henderson 444206c060d9SRichard Henderson static bool do_ld_fpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp sz) 444306c060d9SRichard Henderson { 444406c060d9SRichard Henderson TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 444506c060d9SRichard Henderson DisasASI da; 444606c060d9SRichard Henderson 444706c060d9SRichard Henderson if (addr == NULL) { 444806c060d9SRichard Henderson return false; 444906c060d9SRichard Henderson } 445006c060d9SRichard Henderson if (gen_trap_ifnofpu(dc)) { 445106c060d9SRichard Henderson return true; 445206c060d9SRichard Henderson } 445306c060d9SRichard Henderson if (sz == MO_128 && gen_trap_float128(dc)) { 445406c060d9SRichard Henderson return true; 445506c060d9SRichard Henderson } 445606c060d9SRichard Henderson da = resolve_asi(dc, a->asi, MO_TE | sz); 4457287b1152SRichard Henderson gen_ldf_asi(dc, &da, sz, addr, a->rd); 445806c060d9SRichard Henderson gen_update_fprs_dirty(dc, a->rd); 445906c060d9SRichard Henderson return advance_pc(dc); 446006c060d9SRichard Henderson } 446106c060d9SRichard Henderson 446206c060d9SRichard Henderson TRANS(LDF, ALL, do_ld_fpr, a, MO_32) 446306c060d9SRichard Henderson TRANS(LDDF, ALL, do_ld_fpr, a, MO_64) 446406c060d9SRichard Henderson TRANS(LDQF, ALL, do_ld_fpr, a, MO_128) 446506c060d9SRichard Henderson 4466287b1152SRichard Henderson TRANS(LDFA, 64, do_ld_fpr, a, MO_32) 4467287b1152SRichard Henderson TRANS(LDDFA, 64, do_ld_fpr, a, MO_64) 4468287b1152SRichard Henderson TRANS(LDQFA, 64, do_ld_fpr, a, MO_128) 4469287b1152SRichard Henderson 447006c060d9SRichard Henderson static bool do_st_fpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp sz) 447106c060d9SRichard Henderson { 447206c060d9SRichard Henderson TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 447306c060d9SRichard Henderson DisasASI da; 447406c060d9SRichard Henderson 447506c060d9SRichard Henderson if (addr == NULL) { 447606c060d9SRichard Henderson return false; 447706c060d9SRichard Henderson } 447806c060d9SRichard Henderson if (gen_trap_ifnofpu(dc)) { 447906c060d9SRichard Henderson return true; 448006c060d9SRichard Henderson } 448106c060d9SRichard Henderson if (sz == MO_128 && gen_trap_float128(dc)) { 448206c060d9SRichard Henderson return true; 448306c060d9SRichard Henderson } 448406c060d9SRichard Henderson da = resolve_asi(dc, a->asi, MO_TE | sz); 4485287b1152SRichard Henderson gen_stf_asi(dc, &da, sz, addr, a->rd); 448606c060d9SRichard Henderson return advance_pc(dc); 448706c060d9SRichard Henderson } 448806c060d9SRichard Henderson 448906c060d9SRichard Henderson TRANS(STF, ALL, do_st_fpr, a, MO_32) 449006c060d9SRichard Henderson TRANS(STDF, ALL, do_st_fpr, a, MO_64) 449106c060d9SRichard Henderson TRANS(STQF, ALL, do_st_fpr, a, MO_128) 449206c060d9SRichard Henderson 4493287b1152SRichard Henderson TRANS(STFA, 64, do_st_fpr, a, MO_32) 4494287b1152SRichard Henderson TRANS(STDFA, 64, do_st_fpr, a, MO_64) 4495287b1152SRichard Henderson TRANS(STQFA, 64, do_st_fpr, a, MO_128) 4496287b1152SRichard Henderson 449706c060d9SRichard Henderson static bool trans_STDFQ(DisasContext *dc, arg_STDFQ *a) 449806c060d9SRichard Henderson { 449906c060d9SRichard Henderson if (!avail_32(dc)) { 450006c060d9SRichard Henderson return false; 450106c060d9SRichard Henderson } 450206c060d9SRichard Henderson if (!supervisor(dc)) { 450306c060d9SRichard Henderson return raise_priv(dc); 450406c060d9SRichard Henderson } 450506c060d9SRichard Henderson if (gen_trap_ifnofpu(dc)) { 450606c060d9SRichard Henderson return true; 450706c060d9SRichard Henderson } 450806c060d9SRichard Henderson gen_op_fpexception_im(dc, FSR_FTT_SEQ_ERROR); 450906c060d9SRichard Henderson return true; 451006c060d9SRichard Henderson } 451106c060d9SRichard Henderson 4512d8c5b92fSRichard Henderson static bool trans_LDFSR(DisasContext *dc, arg_r_r_ri *a) 45133d3c0673SRichard Henderson { 45143590f01eSRichard Henderson TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 4515d8c5b92fSRichard Henderson TCGv_i32 tmp; 45163590f01eSRichard Henderson 45173d3c0673SRichard Henderson if (addr == NULL) { 45183d3c0673SRichard Henderson return false; 45193d3c0673SRichard Henderson } 45203d3c0673SRichard Henderson if (gen_trap_ifnofpu(dc)) { 45213d3c0673SRichard Henderson return true; 45223d3c0673SRichard Henderson } 4523d8c5b92fSRichard Henderson 4524d8c5b92fSRichard Henderson tmp = tcg_temp_new_i32(); 4525d8c5b92fSRichard Henderson tcg_gen_qemu_ld_i32(tmp, addr, dc->mem_idx, MO_TEUL | MO_ALIGN); 4526d8c5b92fSRichard Henderson 4527d8c5b92fSRichard Henderson tcg_gen_extract_i32(cpu_fcc[0], tmp, FSR_FCC0_SHIFT, 2); 4528d8c5b92fSRichard Henderson /* LDFSR does not change FCC[1-3]. */ 4529d8c5b92fSRichard Henderson 4530d8c5b92fSRichard Henderson gen_helper_set_fsr_nofcc_noftt(tcg_env, tmp); 45313d3c0673SRichard Henderson return advance_pc(dc); 45323d3c0673SRichard Henderson } 45333d3c0673SRichard Henderson 4534298c52f7SRichard Henderson static bool do_ldxfsr(DisasContext *dc, arg_r_r_ri *a, bool entire) 4535d8c5b92fSRichard Henderson { 4536d8c5b92fSRichard Henderson #ifdef TARGET_SPARC64 4537d8c5b92fSRichard Henderson TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 4538d8c5b92fSRichard Henderson TCGv_i64 t64; 4539d8c5b92fSRichard Henderson TCGv_i32 lo, hi; 4540d8c5b92fSRichard Henderson 4541d8c5b92fSRichard Henderson if (addr == NULL) { 4542d8c5b92fSRichard Henderson return false; 4543d8c5b92fSRichard Henderson } 4544d8c5b92fSRichard Henderson if (gen_trap_ifnofpu(dc)) { 4545d8c5b92fSRichard Henderson return true; 4546d8c5b92fSRichard Henderson } 4547d8c5b92fSRichard Henderson 4548d8c5b92fSRichard Henderson t64 = tcg_temp_new_i64(); 4549d8c5b92fSRichard Henderson tcg_gen_qemu_ld_i64(t64, addr, dc->mem_idx, MO_TEUQ | MO_ALIGN); 4550d8c5b92fSRichard Henderson 4551d8c5b92fSRichard Henderson lo = tcg_temp_new_i32(); 4552d8c5b92fSRichard Henderson hi = cpu_fcc[3]; 4553d8c5b92fSRichard Henderson tcg_gen_extr_i64_i32(lo, hi, t64); 4554d8c5b92fSRichard Henderson tcg_gen_extract_i32(cpu_fcc[0], lo, FSR_FCC0_SHIFT, 2); 4555d8c5b92fSRichard Henderson tcg_gen_extract_i32(cpu_fcc[1], hi, FSR_FCC1_SHIFT - 32, 2); 4556d8c5b92fSRichard Henderson tcg_gen_extract_i32(cpu_fcc[2], hi, FSR_FCC2_SHIFT - 32, 2); 4557d8c5b92fSRichard Henderson tcg_gen_extract_i32(cpu_fcc[3], hi, FSR_FCC3_SHIFT - 32, 2); 4558d8c5b92fSRichard Henderson 4559298c52f7SRichard Henderson if (entire) { 4560298c52f7SRichard Henderson gen_helper_set_fsr_nofcc(tcg_env, lo); 4561298c52f7SRichard Henderson } else { 4562d8c5b92fSRichard Henderson gen_helper_set_fsr_nofcc_noftt(tcg_env, lo); 4563298c52f7SRichard Henderson } 4564d8c5b92fSRichard Henderson return advance_pc(dc); 4565d8c5b92fSRichard Henderson #else 4566d8c5b92fSRichard Henderson return false; 4567d8c5b92fSRichard Henderson #endif 4568d8c5b92fSRichard Henderson } 45693d3c0673SRichard Henderson 4570298c52f7SRichard Henderson TRANS(LDXFSR, 64, do_ldxfsr, a, false) 4571298c52f7SRichard Henderson TRANS(LDXEFSR, VIS3B, do_ldxfsr, a, true) 4572298c52f7SRichard Henderson 45733d3c0673SRichard Henderson static bool do_stfsr(DisasContext *dc, arg_r_r_ri *a, MemOp mop) 45743d3c0673SRichard Henderson { 45753d3c0673SRichard Henderson TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 45761ccd6e13SRichard Henderson TCGv fsr; 45771ccd6e13SRichard Henderson 45783d3c0673SRichard Henderson if (addr == NULL) { 45793d3c0673SRichard Henderson return false; 45803d3c0673SRichard Henderson } 45813d3c0673SRichard Henderson if (gen_trap_ifnofpu(dc)) { 45823d3c0673SRichard Henderson return true; 45833d3c0673SRichard Henderson } 45841ccd6e13SRichard Henderson 45851ccd6e13SRichard Henderson fsr = tcg_temp_new(); 45861ccd6e13SRichard Henderson gen_helper_get_fsr(fsr, tcg_env); 45871ccd6e13SRichard Henderson tcg_gen_qemu_st_tl(fsr, addr, dc->mem_idx, mop | MO_ALIGN); 45883d3c0673SRichard Henderson return advance_pc(dc); 45893d3c0673SRichard Henderson } 45903d3c0673SRichard Henderson 45913d3c0673SRichard Henderson TRANS(STFSR, ALL, do_stfsr, a, MO_TEUL) 45923d3c0673SRichard Henderson TRANS(STXFSR, 64, do_stfsr, a, MO_TEUQ) 45933d3c0673SRichard Henderson 45941210a036SRichard Henderson static bool do_fc(DisasContext *dc, int rd, int32_t c) 45953a38260eSRichard Henderson { 45963a38260eSRichard Henderson if (gen_trap_ifnofpu(dc)) { 45973a38260eSRichard Henderson return true; 45983a38260eSRichard Henderson } 45991210a036SRichard Henderson gen_store_fpr_F(dc, rd, tcg_constant_i32(c)); 46003a38260eSRichard Henderson return advance_pc(dc); 46013a38260eSRichard Henderson } 46023a38260eSRichard Henderson 46033a38260eSRichard Henderson TRANS(FZEROs, VIS1, do_fc, a->rd, 0) 46041210a036SRichard Henderson TRANS(FONEs, VIS1, do_fc, a->rd, -1) 46053a38260eSRichard Henderson 46063a38260eSRichard Henderson static bool do_dc(DisasContext *dc, int rd, int64_t c) 46073a38260eSRichard Henderson { 46083a38260eSRichard Henderson if (gen_trap_ifnofpu(dc)) { 46093a38260eSRichard Henderson return true; 46103a38260eSRichard Henderson } 46111210a036SRichard Henderson gen_store_fpr_D(dc, rd, tcg_constant_i64(c)); 46123a38260eSRichard Henderson return advance_pc(dc); 46133a38260eSRichard Henderson } 46143a38260eSRichard Henderson 46153a38260eSRichard Henderson TRANS(FZEROd, VIS1, do_dc, a->rd, 0) 46163a38260eSRichard Henderson TRANS(FONEd, VIS1, do_dc, a->rd, -1) 46173a38260eSRichard Henderson 4618baf3dbf2SRichard Henderson static bool do_ff(DisasContext *dc, arg_r_r *a, 4619baf3dbf2SRichard Henderson void (*func)(TCGv_i32, TCGv_i32)) 4620baf3dbf2SRichard Henderson { 4621baf3dbf2SRichard Henderson TCGv_i32 tmp; 4622baf3dbf2SRichard Henderson 4623baf3dbf2SRichard Henderson if (gen_trap_ifnofpu(dc)) { 4624baf3dbf2SRichard Henderson return true; 4625baf3dbf2SRichard Henderson } 4626baf3dbf2SRichard Henderson 4627baf3dbf2SRichard Henderson tmp = gen_load_fpr_F(dc, a->rs); 4628baf3dbf2SRichard Henderson func(tmp, tmp); 4629baf3dbf2SRichard Henderson gen_store_fpr_F(dc, a->rd, tmp); 4630baf3dbf2SRichard Henderson return advance_pc(dc); 4631baf3dbf2SRichard Henderson } 4632baf3dbf2SRichard Henderson 4633baf3dbf2SRichard Henderson TRANS(FMOVs, ALL, do_ff, a, gen_op_fmovs) 4634baf3dbf2SRichard Henderson TRANS(FNEGs, ALL, do_ff, a, gen_op_fnegs) 4635baf3dbf2SRichard Henderson TRANS(FABSs, ALL, do_ff, a, gen_op_fabss) 4636baf3dbf2SRichard Henderson TRANS(FSRCs, VIS1, do_ff, a, tcg_gen_mov_i32) 4637baf3dbf2SRichard Henderson TRANS(FNOTs, VIS1, do_ff, a, tcg_gen_not_i32) 4638baf3dbf2SRichard Henderson 46392f722641SRichard Henderson static bool do_fd(DisasContext *dc, arg_r_r *a, 46402f722641SRichard Henderson void (*func)(TCGv_i32, TCGv_i64)) 46412f722641SRichard Henderson { 46422f722641SRichard Henderson TCGv_i32 dst; 46432f722641SRichard Henderson TCGv_i64 src; 46442f722641SRichard Henderson 46452f722641SRichard Henderson if (gen_trap_ifnofpu(dc)) { 46462f722641SRichard Henderson return true; 46472f722641SRichard Henderson } 46482f722641SRichard Henderson 4649388a6465SRichard Henderson dst = tcg_temp_new_i32(); 46502f722641SRichard Henderson src = gen_load_fpr_D(dc, a->rs); 46512f722641SRichard Henderson func(dst, src); 46522f722641SRichard Henderson gen_store_fpr_F(dc, a->rd, dst); 46532f722641SRichard Henderson return advance_pc(dc); 46542f722641SRichard Henderson } 46552f722641SRichard Henderson 46562f722641SRichard Henderson TRANS(FPACK16, VIS1, do_fd, a, gen_op_fpack16) 46572f722641SRichard Henderson TRANS(FPACKFIX, VIS1, do_fd, a, gen_op_fpackfix) 46582f722641SRichard Henderson 4659119cb94fSRichard Henderson static bool do_env_ff(DisasContext *dc, arg_r_r *a, 4660119cb94fSRichard Henderson void (*func)(TCGv_i32, TCGv_env, TCGv_i32)) 4661119cb94fSRichard Henderson { 4662119cb94fSRichard Henderson TCGv_i32 tmp; 4663119cb94fSRichard Henderson 4664119cb94fSRichard Henderson if (gen_trap_ifnofpu(dc)) { 4665119cb94fSRichard Henderson return true; 4666119cb94fSRichard Henderson } 4667119cb94fSRichard Henderson 4668119cb94fSRichard Henderson tmp = gen_load_fpr_F(dc, a->rs); 4669119cb94fSRichard Henderson func(tmp, tcg_env, tmp); 4670119cb94fSRichard Henderson gen_store_fpr_F(dc, a->rd, tmp); 4671119cb94fSRichard Henderson return advance_pc(dc); 4672119cb94fSRichard Henderson } 4673119cb94fSRichard Henderson 4674119cb94fSRichard Henderson TRANS(FSQRTs, ALL, do_env_ff, a, gen_helper_fsqrts) 4675119cb94fSRichard Henderson TRANS(FiTOs, ALL, do_env_ff, a, gen_helper_fitos) 4676119cb94fSRichard Henderson TRANS(FsTOi, ALL, do_env_ff, a, gen_helper_fstoi) 4677119cb94fSRichard Henderson 46788c94bcd8SRichard Henderson static bool do_env_fd(DisasContext *dc, arg_r_r *a, 46798c94bcd8SRichard Henderson void (*func)(TCGv_i32, TCGv_env, TCGv_i64)) 46808c94bcd8SRichard Henderson { 46818c94bcd8SRichard Henderson TCGv_i32 dst; 46828c94bcd8SRichard Henderson TCGv_i64 src; 46838c94bcd8SRichard Henderson 46848c94bcd8SRichard Henderson if (gen_trap_ifnofpu(dc)) { 46858c94bcd8SRichard Henderson return true; 46868c94bcd8SRichard Henderson } 46878c94bcd8SRichard Henderson 4688388a6465SRichard Henderson dst = tcg_temp_new_i32(); 46898c94bcd8SRichard Henderson src = gen_load_fpr_D(dc, a->rs); 46908c94bcd8SRichard Henderson func(dst, tcg_env, src); 46918c94bcd8SRichard Henderson gen_store_fpr_F(dc, a->rd, dst); 46928c94bcd8SRichard Henderson return advance_pc(dc); 46938c94bcd8SRichard Henderson } 46948c94bcd8SRichard Henderson 46958c94bcd8SRichard Henderson TRANS(FdTOs, ALL, do_env_fd, a, gen_helper_fdtos) 46968c94bcd8SRichard Henderson TRANS(FdTOi, ALL, do_env_fd, a, gen_helper_fdtoi) 46978c94bcd8SRichard Henderson TRANS(FxTOs, 64, do_env_fd, a, gen_helper_fxtos) 46988c94bcd8SRichard Henderson 4699c6d83e4fSRichard Henderson static bool do_dd(DisasContext *dc, arg_r_r *a, 4700c6d83e4fSRichard Henderson void (*func)(TCGv_i64, TCGv_i64)) 4701c6d83e4fSRichard Henderson { 4702c6d83e4fSRichard Henderson TCGv_i64 dst, src; 4703c6d83e4fSRichard Henderson 4704c6d83e4fSRichard Henderson if (gen_trap_ifnofpu(dc)) { 4705c6d83e4fSRichard Henderson return true; 4706c6d83e4fSRichard Henderson } 4707c6d83e4fSRichard Henderson 470852f46d46SRichard Henderson dst = tcg_temp_new_i64(); 4709c6d83e4fSRichard Henderson src = gen_load_fpr_D(dc, a->rs); 4710c6d83e4fSRichard Henderson func(dst, src); 4711c6d83e4fSRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 4712c6d83e4fSRichard Henderson return advance_pc(dc); 4713c6d83e4fSRichard Henderson } 4714c6d83e4fSRichard Henderson 4715c6d83e4fSRichard Henderson TRANS(FMOVd, 64, do_dd, a, gen_op_fmovd) 4716c6d83e4fSRichard Henderson TRANS(FNEGd, 64, do_dd, a, gen_op_fnegd) 4717c6d83e4fSRichard Henderson TRANS(FABSd, 64, do_dd, a, gen_op_fabsd) 4718c6d83e4fSRichard Henderson TRANS(FSRCd, VIS1, do_dd, a, tcg_gen_mov_i64) 4719c6d83e4fSRichard Henderson TRANS(FNOTd, VIS1, do_dd, a, tcg_gen_not_i64) 4720c6d83e4fSRichard Henderson 47218aa418b3SRichard Henderson static bool do_env_dd(DisasContext *dc, arg_r_r *a, 47228aa418b3SRichard Henderson void (*func)(TCGv_i64, TCGv_env, TCGv_i64)) 47238aa418b3SRichard Henderson { 47248aa418b3SRichard Henderson TCGv_i64 dst, src; 47258aa418b3SRichard Henderson 47268aa418b3SRichard Henderson if (gen_trap_ifnofpu(dc)) { 47278aa418b3SRichard Henderson return true; 47288aa418b3SRichard Henderson } 47298aa418b3SRichard Henderson 473052f46d46SRichard Henderson dst = tcg_temp_new_i64(); 47318aa418b3SRichard Henderson src = gen_load_fpr_D(dc, a->rs); 47328aa418b3SRichard Henderson func(dst, tcg_env, src); 47338aa418b3SRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 47348aa418b3SRichard Henderson return advance_pc(dc); 47358aa418b3SRichard Henderson } 47368aa418b3SRichard Henderson 47378aa418b3SRichard Henderson TRANS(FSQRTd, ALL, do_env_dd, a, gen_helper_fsqrtd) 47388aa418b3SRichard Henderson TRANS(FxTOd, 64, do_env_dd, a, gen_helper_fxtod) 47398aa418b3SRichard Henderson TRANS(FdTOx, 64, do_env_dd, a, gen_helper_fdtox) 47408aa418b3SRichard Henderson 47417b616f36SRichard Henderson static bool do_df(DisasContext *dc, arg_r_r *a, 47427b616f36SRichard Henderson void (*func)(TCGv_i64, TCGv_i32)) 47437b616f36SRichard Henderson { 47447b616f36SRichard Henderson TCGv_i64 dst; 47457b616f36SRichard Henderson TCGv_i32 src; 47467b616f36SRichard Henderson 47477b616f36SRichard Henderson if (gen_trap_ifnofpu(dc)) { 47487b616f36SRichard Henderson return true; 47497b616f36SRichard Henderson } 47507b616f36SRichard Henderson 47517b616f36SRichard Henderson dst = tcg_temp_new_i64(); 47527b616f36SRichard Henderson src = gen_load_fpr_F(dc, a->rs); 47537b616f36SRichard Henderson func(dst, src); 47547b616f36SRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 47557b616f36SRichard Henderson return advance_pc(dc); 47567b616f36SRichard Henderson } 47577b616f36SRichard Henderson 47587b616f36SRichard Henderson TRANS(FEXPAND, VIS1, do_df, a, gen_helper_fexpand) 47597b616f36SRichard Henderson 4760199d43efSRichard Henderson static bool do_env_df(DisasContext *dc, arg_r_r *a, 4761199d43efSRichard Henderson void (*func)(TCGv_i64, TCGv_env, TCGv_i32)) 4762199d43efSRichard Henderson { 4763199d43efSRichard Henderson TCGv_i64 dst; 4764199d43efSRichard Henderson TCGv_i32 src; 4765199d43efSRichard Henderson 4766199d43efSRichard Henderson if (gen_trap_ifnofpu(dc)) { 4767199d43efSRichard Henderson return true; 4768199d43efSRichard Henderson } 4769199d43efSRichard Henderson 477052f46d46SRichard Henderson dst = tcg_temp_new_i64(); 4771199d43efSRichard Henderson src = gen_load_fpr_F(dc, a->rs); 4772199d43efSRichard Henderson func(dst, tcg_env, src); 4773199d43efSRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 4774199d43efSRichard Henderson return advance_pc(dc); 4775199d43efSRichard Henderson } 4776199d43efSRichard Henderson 4777199d43efSRichard Henderson TRANS(FiTOd, ALL, do_env_df, a, gen_helper_fitod) 4778199d43efSRichard Henderson TRANS(FsTOd, ALL, do_env_df, a, gen_helper_fstod) 4779199d43efSRichard Henderson TRANS(FsTOx, 64, do_env_df, a, gen_helper_fstox) 4780199d43efSRichard Henderson 4781daf457d4SRichard Henderson static bool do_qq(DisasContext *dc, arg_r_r *a, 4782daf457d4SRichard Henderson void (*func)(TCGv_i128, TCGv_i128)) 4783f4e18df5SRichard Henderson { 478433ec4245SRichard Henderson TCGv_i128 t; 4785f4e18df5SRichard Henderson 4786f4e18df5SRichard Henderson if (gen_trap_ifnofpu(dc)) { 4787f4e18df5SRichard Henderson return true; 4788f4e18df5SRichard Henderson } 4789f4e18df5SRichard Henderson if (gen_trap_float128(dc)) { 4790f4e18df5SRichard Henderson return true; 4791f4e18df5SRichard Henderson } 4792f4e18df5SRichard Henderson 4793f4e18df5SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 479433ec4245SRichard Henderson t = gen_load_fpr_Q(dc, a->rs); 4795daf457d4SRichard Henderson func(t, t); 479633ec4245SRichard Henderson gen_store_fpr_Q(dc, a->rd, t); 4797f4e18df5SRichard Henderson return advance_pc(dc); 4798f4e18df5SRichard Henderson } 4799f4e18df5SRichard Henderson 4800daf457d4SRichard Henderson TRANS(FMOVq, 64, do_qq, a, tcg_gen_mov_i128) 4801daf457d4SRichard Henderson TRANS(FNEGq, 64, do_qq, a, gen_op_fnegq) 4802daf457d4SRichard Henderson TRANS(FABSq, 64, do_qq, a, gen_op_fabsq) 4803f4e18df5SRichard Henderson 4804c995216bSRichard Henderson static bool do_env_qq(DisasContext *dc, arg_r_r *a, 4805e41716beSRichard Henderson void (*func)(TCGv_i128, TCGv_env, TCGv_i128)) 4806c995216bSRichard Henderson { 4807e41716beSRichard Henderson TCGv_i128 t; 4808e41716beSRichard Henderson 4809c995216bSRichard Henderson if (gen_trap_ifnofpu(dc)) { 4810c995216bSRichard Henderson return true; 4811c995216bSRichard Henderson } 4812c995216bSRichard Henderson if (gen_trap_float128(dc)) { 4813c995216bSRichard Henderson return true; 4814c995216bSRichard Henderson } 4815c995216bSRichard Henderson 4816e41716beSRichard Henderson t = gen_load_fpr_Q(dc, a->rs); 4817e41716beSRichard Henderson func(t, tcg_env, t); 4818e41716beSRichard Henderson gen_store_fpr_Q(dc, a->rd, t); 4819c995216bSRichard Henderson return advance_pc(dc); 4820c995216bSRichard Henderson } 4821c995216bSRichard Henderson 4822c995216bSRichard Henderson TRANS(FSQRTq, ALL, do_env_qq, a, gen_helper_fsqrtq) 4823c995216bSRichard Henderson 4824bd9c5c42SRichard Henderson static bool do_env_fq(DisasContext *dc, arg_r_r *a, 4825d81e3efeSRichard Henderson void (*func)(TCGv_i32, TCGv_env, TCGv_i128)) 4826bd9c5c42SRichard Henderson { 4827d81e3efeSRichard Henderson TCGv_i128 src; 4828bd9c5c42SRichard Henderson TCGv_i32 dst; 4829bd9c5c42SRichard Henderson 4830bd9c5c42SRichard Henderson if (gen_trap_ifnofpu(dc)) { 4831bd9c5c42SRichard Henderson return true; 4832bd9c5c42SRichard Henderson } 4833bd9c5c42SRichard Henderson if (gen_trap_float128(dc)) { 4834bd9c5c42SRichard Henderson return true; 4835bd9c5c42SRichard Henderson } 4836bd9c5c42SRichard Henderson 4837d81e3efeSRichard Henderson src = gen_load_fpr_Q(dc, a->rs); 4838388a6465SRichard Henderson dst = tcg_temp_new_i32(); 4839d81e3efeSRichard Henderson func(dst, tcg_env, src); 4840bd9c5c42SRichard Henderson gen_store_fpr_F(dc, a->rd, dst); 4841bd9c5c42SRichard Henderson return advance_pc(dc); 4842bd9c5c42SRichard Henderson } 4843bd9c5c42SRichard Henderson 4844bd9c5c42SRichard Henderson TRANS(FqTOs, ALL, do_env_fq, a, gen_helper_fqtos) 4845bd9c5c42SRichard Henderson TRANS(FqTOi, ALL, do_env_fq, a, gen_helper_fqtoi) 4846bd9c5c42SRichard Henderson 48471617586fSRichard Henderson static bool do_env_dq(DisasContext *dc, arg_r_r *a, 484825a5769eSRichard Henderson void (*func)(TCGv_i64, TCGv_env, TCGv_i128)) 48491617586fSRichard Henderson { 485025a5769eSRichard Henderson TCGv_i128 src; 48511617586fSRichard Henderson TCGv_i64 dst; 48521617586fSRichard Henderson 48531617586fSRichard Henderson if (gen_trap_ifnofpu(dc)) { 48541617586fSRichard Henderson return true; 48551617586fSRichard Henderson } 48561617586fSRichard Henderson if (gen_trap_float128(dc)) { 48571617586fSRichard Henderson return true; 48581617586fSRichard Henderson } 48591617586fSRichard Henderson 486025a5769eSRichard Henderson src = gen_load_fpr_Q(dc, a->rs); 486152f46d46SRichard Henderson dst = tcg_temp_new_i64(); 486225a5769eSRichard Henderson func(dst, tcg_env, src); 48631617586fSRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 48641617586fSRichard Henderson return advance_pc(dc); 48651617586fSRichard Henderson } 48661617586fSRichard Henderson 48671617586fSRichard Henderson TRANS(FqTOd, ALL, do_env_dq, a, gen_helper_fqtod) 48681617586fSRichard Henderson TRANS(FqTOx, 64, do_env_dq, a, gen_helper_fqtox) 48691617586fSRichard Henderson 487013ebcc77SRichard Henderson static bool do_env_qf(DisasContext *dc, arg_r_r *a, 48710b2a61ccSRichard Henderson void (*func)(TCGv_i128, TCGv_env, TCGv_i32)) 487213ebcc77SRichard Henderson { 487313ebcc77SRichard Henderson TCGv_i32 src; 48740b2a61ccSRichard Henderson TCGv_i128 dst; 487513ebcc77SRichard Henderson 487613ebcc77SRichard Henderson if (gen_trap_ifnofpu(dc)) { 487713ebcc77SRichard Henderson return true; 487813ebcc77SRichard Henderson } 487913ebcc77SRichard Henderson if (gen_trap_float128(dc)) { 488013ebcc77SRichard Henderson return true; 488113ebcc77SRichard Henderson } 488213ebcc77SRichard Henderson 488313ebcc77SRichard Henderson src = gen_load_fpr_F(dc, a->rs); 48840b2a61ccSRichard Henderson dst = tcg_temp_new_i128(); 48850b2a61ccSRichard Henderson func(dst, tcg_env, src); 48860b2a61ccSRichard Henderson gen_store_fpr_Q(dc, a->rd, dst); 488713ebcc77SRichard Henderson return advance_pc(dc); 488813ebcc77SRichard Henderson } 488913ebcc77SRichard Henderson 489013ebcc77SRichard Henderson TRANS(FiTOq, ALL, do_env_qf, a, gen_helper_fitoq) 489113ebcc77SRichard Henderson TRANS(FsTOq, ALL, do_env_qf, a, gen_helper_fstoq) 489213ebcc77SRichard Henderson 48937b8e3e1aSRichard Henderson static bool do_env_qd(DisasContext *dc, arg_r_r *a, 4894fdc50716SRichard Henderson void (*func)(TCGv_i128, TCGv_env, TCGv_i64)) 48957b8e3e1aSRichard Henderson { 48967b8e3e1aSRichard Henderson TCGv_i64 src; 4897fdc50716SRichard Henderson TCGv_i128 dst; 48987b8e3e1aSRichard Henderson 48997b8e3e1aSRichard Henderson if (gen_trap_ifnofpu(dc)) { 49007b8e3e1aSRichard Henderson return true; 49017b8e3e1aSRichard Henderson } 49027b8e3e1aSRichard Henderson if (gen_trap_float128(dc)) { 49037b8e3e1aSRichard Henderson return true; 49047b8e3e1aSRichard Henderson } 49057b8e3e1aSRichard Henderson 49067b8e3e1aSRichard Henderson src = gen_load_fpr_D(dc, a->rs); 4907fdc50716SRichard Henderson dst = tcg_temp_new_i128(); 4908fdc50716SRichard Henderson func(dst, tcg_env, src); 4909fdc50716SRichard Henderson gen_store_fpr_Q(dc, a->rd, dst); 49107b8e3e1aSRichard Henderson return advance_pc(dc); 49117b8e3e1aSRichard Henderson } 49127b8e3e1aSRichard Henderson 49137b8e3e1aSRichard Henderson TRANS(FdTOq, ALL, do_env_qd, a, gen_helper_fdtoq) 49147b8e3e1aSRichard Henderson TRANS(FxTOq, 64, do_env_qd, a, gen_helper_fxtoq) 49157b8e3e1aSRichard Henderson 49167f10b52fSRichard Henderson static bool do_fff(DisasContext *dc, arg_r_r_r *a, 49177f10b52fSRichard Henderson void (*func)(TCGv_i32, TCGv_i32, TCGv_i32)) 49187f10b52fSRichard Henderson { 49197f10b52fSRichard Henderson TCGv_i32 src1, src2; 49207f10b52fSRichard Henderson 49217f10b52fSRichard Henderson if (gen_trap_ifnofpu(dc)) { 49227f10b52fSRichard Henderson return true; 49237f10b52fSRichard Henderson } 49247f10b52fSRichard Henderson 49257f10b52fSRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1); 49267f10b52fSRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2); 49277f10b52fSRichard Henderson func(src1, src1, src2); 49287f10b52fSRichard Henderson gen_store_fpr_F(dc, a->rd, src1); 49297f10b52fSRichard Henderson return advance_pc(dc); 49307f10b52fSRichard Henderson } 49317f10b52fSRichard Henderson 49327f10b52fSRichard Henderson TRANS(FPADD16s, VIS1, do_fff, a, tcg_gen_vec_add16_i32) 49337f10b52fSRichard Henderson TRANS(FPADD32s, VIS1, do_fff, a, tcg_gen_add_i32) 49347f10b52fSRichard Henderson TRANS(FPSUB16s, VIS1, do_fff, a, tcg_gen_vec_sub16_i32) 49357f10b52fSRichard Henderson TRANS(FPSUB32s, VIS1, do_fff, a, tcg_gen_sub_i32) 49367f10b52fSRichard Henderson TRANS(FNORs, VIS1, do_fff, a, tcg_gen_nor_i32) 49377f10b52fSRichard Henderson TRANS(FANDNOTs, VIS1, do_fff, a, tcg_gen_andc_i32) 49387f10b52fSRichard Henderson TRANS(FXORs, VIS1, do_fff, a, tcg_gen_xor_i32) 49397f10b52fSRichard Henderson TRANS(FNANDs, VIS1, do_fff, a, tcg_gen_nand_i32) 49407f10b52fSRichard Henderson TRANS(FANDs, VIS1, do_fff, a, tcg_gen_and_i32) 49417f10b52fSRichard Henderson TRANS(FXNORs, VIS1, do_fff, a, tcg_gen_eqv_i32) 49427f10b52fSRichard Henderson TRANS(FORNOTs, VIS1, do_fff, a, tcg_gen_orc_i32) 49437f10b52fSRichard Henderson TRANS(FORs, VIS1, do_fff, a, tcg_gen_or_i32) 49447f10b52fSRichard Henderson 49453d50b728SRichard Henderson TRANS(FHADDs, VIS3, do_fff, a, gen_op_fhadds) 49463d50b728SRichard Henderson TRANS(FHSUBs, VIS3, do_fff, a, gen_op_fhsubs) 49473d50b728SRichard Henderson TRANS(FNHADDs, VIS3, do_fff, a, gen_op_fnhadds) 49483d50b728SRichard Henderson 49490d1d3aafSRichard Henderson TRANS(FPADDS16s, VIS3, do_fff, a, gen_op_fpadds16s) 49500d1d3aafSRichard Henderson TRANS(FPSUBS16s, VIS3, do_fff, a, gen_op_fpsubs16s) 49510d1d3aafSRichard Henderson TRANS(FPADDS32s, VIS3, do_fff, a, gen_op_fpadds32s) 49520d1d3aafSRichard Henderson TRANS(FPSUBS32s, VIS3, do_fff, a, gen_op_fpsubs32s) 49530d1d3aafSRichard Henderson 4954c1514961SRichard Henderson static bool do_env_fff(DisasContext *dc, arg_r_r_r *a, 4955c1514961SRichard Henderson void (*func)(TCGv_i32, TCGv_env, TCGv_i32, TCGv_i32)) 4956c1514961SRichard Henderson { 4957c1514961SRichard Henderson TCGv_i32 src1, src2; 4958c1514961SRichard Henderson 4959c1514961SRichard Henderson if (gen_trap_ifnofpu(dc)) { 4960c1514961SRichard Henderson return true; 4961c1514961SRichard Henderson } 4962c1514961SRichard Henderson 4963c1514961SRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1); 4964c1514961SRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2); 4965c1514961SRichard Henderson func(src1, tcg_env, src1, src2); 4966c1514961SRichard Henderson gen_store_fpr_F(dc, a->rd, src1); 4967c1514961SRichard Henderson return advance_pc(dc); 4968c1514961SRichard Henderson } 4969c1514961SRichard Henderson 4970c1514961SRichard Henderson TRANS(FADDs, ALL, do_env_fff, a, gen_helper_fadds) 4971c1514961SRichard Henderson TRANS(FSUBs, ALL, do_env_fff, a, gen_helper_fsubs) 4972c1514961SRichard Henderson TRANS(FMULs, ALL, do_env_fff, a, gen_helper_fmuls) 4973c1514961SRichard Henderson TRANS(FDIVs, ALL, do_env_fff, a, gen_helper_fdivs) 49743d50b728SRichard Henderson TRANS(FNADDs, VIS3, do_env_fff, a, gen_helper_fnadds) 49753d50b728SRichard Henderson TRANS(FNMULs, VIS3, do_env_fff, a, gen_helper_fnmuls) 4976c1514961SRichard Henderson 4977a859602cSRichard Henderson static bool do_dff(DisasContext *dc, arg_r_r_r *a, 4978a859602cSRichard Henderson void (*func)(TCGv_i64, TCGv_i32, TCGv_i32)) 4979a859602cSRichard Henderson { 4980a859602cSRichard Henderson TCGv_i64 dst; 4981a859602cSRichard Henderson TCGv_i32 src1, src2; 4982a859602cSRichard Henderson 4983a859602cSRichard Henderson if (gen_trap_ifnofpu(dc)) { 4984a859602cSRichard Henderson return true; 4985a859602cSRichard Henderson } 4986a859602cSRichard Henderson 498752f46d46SRichard Henderson dst = tcg_temp_new_i64(); 4988a859602cSRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1); 4989a859602cSRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2); 4990a859602cSRichard Henderson func(dst, src1, src2); 4991a859602cSRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 4992a859602cSRichard Henderson return advance_pc(dc); 4993a859602cSRichard Henderson } 4994a859602cSRichard Henderson 4995a859602cSRichard Henderson TRANS(FMUL8x16AU, VIS1, do_dff, a, gen_op_fmul8x16au) 4996a859602cSRichard Henderson TRANS(FMUL8x16AL, VIS1, do_dff, a, gen_op_fmul8x16al) 4997be8998e0SRichard Henderson TRANS(FMULD8SUx16, VIS1, do_dff, a, gen_op_fmuld8sux16) 4998be8998e0SRichard Henderson TRANS(FMULD8ULx16, VIS1, do_dff, a, gen_op_fmuld8ulx16) 4999d3ef26afSRichard Henderson TRANS(FPMERGE, VIS1, do_dff, a, gen_helper_fpmerge) 5000a859602cSRichard Henderson 50019157dcccSRichard Henderson static bool do_dfd(DisasContext *dc, arg_r_r_r *a, 50029157dcccSRichard Henderson void (*func)(TCGv_i64, TCGv_i32, TCGv_i64)) 50039157dcccSRichard Henderson { 50049157dcccSRichard Henderson TCGv_i64 dst, src2; 50059157dcccSRichard Henderson TCGv_i32 src1; 50069157dcccSRichard Henderson 50079157dcccSRichard Henderson if (gen_trap_ifnofpu(dc)) { 50089157dcccSRichard Henderson return true; 50099157dcccSRichard Henderson } 50109157dcccSRichard Henderson 501152f46d46SRichard Henderson dst = tcg_temp_new_i64(); 50129157dcccSRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1); 50139157dcccSRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2); 50149157dcccSRichard Henderson func(dst, src1, src2); 50159157dcccSRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 50169157dcccSRichard Henderson return advance_pc(dc); 50179157dcccSRichard Henderson } 50189157dcccSRichard Henderson 50199157dcccSRichard Henderson TRANS(FMUL8x16, VIS1, do_dfd, a, gen_helper_fmul8x16) 50209157dcccSRichard Henderson 502128c131a3SRichard Henderson static bool do_gvec_ddd(DisasContext *dc, arg_r_r_r *a, MemOp vece, 502228c131a3SRichard Henderson void (*func)(unsigned, uint32_t, uint32_t, 502328c131a3SRichard Henderson uint32_t, uint32_t, uint32_t)) 502428c131a3SRichard Henderson { 502528c131a3SRichard Henderson if (gen_trap_ifnofpu(dc)) { 502628c131a3SRichard Henderson return true; 502728c131a3SRichard Henderson } 502828c131a3SRichard Henderson 502928c131a3SRichard Henderson func(vece, gen_offset_fpr_D(a->rd), gen_offset_fpr_D(a->rs1), 503028c131a3SRichard Henderson gen_offset_fpr_D(a->rs2), 8, 8); 503128c131a3SRichard Henderson return advance_pc(dc); 503228c131a3SRichard Henderson } 503328c131a3SRichard Henderson 5034b99c1bbdSRichard Henderson TRANS(FPADD8, VIS4, do_gvec_ddd, a, MO_8, tcg_gen_gvec_add) 503528c131a3SRichard Henderson TRANS(FPADD16, VIS1, do_gvec_ddd, a, MO_16, tcg_gen_gvec_add) 503628c131a3SRichard Henderson TRANS(FPADD32, VIS1, do_gvec_ddd, a, MO_32, tcg_gen_gvec_add) 5037b99c1bbdSRichard Henderson 5038b99c1bbdSRichard Henderson TRANS(FPSUB8, VIS4, do_gvec_ddd, a, MO_8, tcg_gen_gvec_sub) 503928c131a3SRichard Henderson TRANS(FPSUB16, VIS1, do_gvec_ddd, a, MO_16, tcg_gen_gvec_sub) 504028c131a3SRichard Henderson TRANS(FPSUB32, VIS1, do_gvec_ddd, a, MO_32, tcg_gen_gvec_sub) 5041b99c1bbdSRichard Henderson 50427837185eSRichard Henderson TRANS(FCHKSM16, VIS3, do_gvec_ddd, a, MO_16, gen_op_fchksm16) 5043d6ff1ccbSRichard Henderson TRANS(FMEAN16, VIS3, do_gvec_ddd, a, MO_16, gen_op_fmean16) 504428c131a3SRichard Henderson 5045b99c1bbdSRichard Henderson TRANS(FPADDS8, VIS4, do_gvec_ddd, a, MO_8, tcg_gen_gvec_ssadd) 50460d1d3aafSRichard Henderson TRANS(FPADDS16, VIS3, do_gvec_ddd, a, MO_16, tcg_gen_gvec_ssadd) 50470d1d3aafSRichard Henderson TRANS(FPADDS32, VIS3, do_gvec_ddd, a, MO_32, tcg_gen_gvec_ssadd) 5048b99c1bbdSRichard Henderson TRANS(FPADDUS8, VIS4, do_gvec_ddd, a, MO_8, tcg_gen_gvec_usadd) 5049b99c1bbdSRichard Henderson TRANS(FPADDUS16, VIS4, do_gvec_ddd, a, MO_16, tcg_gen_gvec_usadd) 5050b99c1bbdSRichard Henderson 5051b99c1bbdSRichard Henderson TRANS(FPSUBS8, VIS4, do_gvec_ddd, a, MO_8, tcg_gen_gvec_sssub) 50520d1d3aafSRichard Henderson TRANS(FPSUBS16, VIS3, do_gvec_ddd, a, MO_16, tcg_gen_gvec_sssub) 50530d1d3aafSRichard Henderson TRANS(FPSUBS32, VIS3, do_gvec_ddd, a, MO_32, tcg_gen_gvec_sssub) 5054b99c1bbdSRichard Henderson TRANS(FPSUBUS8, VIS4, do_gvec_ddd, a, MO_8, tcg_gen_gvec_ussub) 5055b99c1bbdSRichard Henderson TRANS(FPSUBUS16, VIS4, do_gvec_ddd, a, MO_16, tcg_gen_gvec_ussub) 50560d1d3aafSRichard Henderson 5057fbc5c8d4SRichard Henderson TRANS(FSLL16, VIS3, do_gvec_ddd, a, MO_16, tcg_gen_gvec_shlv) 5058fbc5c8d4SRichard Henderson TRANS(FSLL32, VIS3, do_gvec_ddd, a, MO_32, tcg_gen_gvec_shlv) 5059fbc5c8d4SRichard Henderson TRANS(FSRL16, VIS3, do_gvec_ddd, a, MO_16, tcg_gen_gvec_shrv) 5060fbc5c8d4SRichard Henderson TRANS(FSRL32, VIS3, do_gvec_ddd, a, MO_32, tcg_gen_gvec_shrv) 5061fbc5c8d4SRichard Henderson TRANS(FSRA16, VIS3, do_gvec_ddd, a, MO_16, tcg_gen_gvec_sarv) 5062fbc5c8d4SRichard Henderson TRANS(FSRA32, VIS3, do_gvec_ddd, a, MO_32, tcg_gen_gvec_sarv) 5063fbc5c8d4SRichard Henderson 5064e06c9f83SRichard Henderson static bool do_ddd(DisasContext *dc, arg_r_r_r *a, 5065e06c9f83SRichard Henderson void (*func)(TCGv_i64, TCGv_i64, TCGv_i64)) 5066e06c9f83SRichard Henderson { 5067e06c9f83SRichard Henderson TCGv_i64 dst, src1, src2; 5068e06c9f83SRichard Henderson 5069e06c9f83SRichard Henderson if (gen_trap_ifnofpu(dc)) { 5070e06c9f83SRichard Henderson return true; 5071e06c9f83SRichard Henderson } 5072e06c9f83SRichard Henderson 507352f46d46SRichard Henderson dst = tcg_temp_new_i64(); 5074e06c9f83SRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1); 5075e06c9f83SRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2); 5076e06c9f83SRichard Henderson func(dst, src1, src2); 5077e06c9f83SRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 5078e06c9f83SRichard Henderson return advance_pc(dc); 5079e06c9f83SRichard Henderson } 5080e06c9f83SRichard Henderson 5081e06c9f83SRichard Henderson TRANS(FMUL8SUx16, VIS1, do_ddd, a, gen_helper_fmul8sux16) 5082e06c9f83SRichard Henderson TRANS(FMUL8ULx16, VIS1, do_ddd, a, gen_helper_fmul8ulx16) 5083e06c9f83SRichard Henderson 5084e06c9f83SRichard Henderson TRANS(FNORd, VIS1, do_ddd, a, tcg_gen_nor_i64) 5085e06c9f83SRichard Henderson TRANS(FANDNOTd, VIS1, do_ddd, a, tcg_gen_andc_i64) 5086e06c9f83SRichard Henderson TRANS(FXORd, VIS1, do_ddd, a, tcg_gen_xor_i64) 5087e06c9f83SRichard Henderson TRANS(FNANDd, VIS1, do_ddd, a, tcg_gen_nand_i64) 5088e06c9f83SRichard Henderson TRANS(FANDd, VIS1, do_ddd, a, tcg_gen_and_i64) 5089e06c9f83SRichard Henderson TRANS(FXNORd, VIS1, do_ddd, a, tcg_gen_eqv_i64) 5090e06c9f83SRichard Henderson TRANS(FORNOTd, VIS1, do_ddd, a, tcg_gen_orc_i64) 5091e06c9f83SRichard Henderson TRANS(FORd, VIS1, do_ddd, a, tcg_gen_or_i64) 5092e06c9f83SRichard Henderson 50934b6edc0aSRichard Henderson TRANS(FPACK32, VIS1, do_ddd, a, gen_op_fpack32) 5094b2b48493SRichard Henderson TRANS(FALIGNDATAg, VIS1, do_ddd, a, gen_op_faligndata_g) 50954b6edc0aSRichard Henderson TRANS(BSHUFFLE, VIS2, do_ddd, a, gen_op_bshuffle) 50964b6edc0aSRichard Henderson 50973d50b728SRichard Henderson TRANS(FHADDd, VIS3, do_ddd, a, gen_op_fhaddd) 50983d50b728SRichard Henderson TRANS(FHSUBd, VIS3, do_ddd, a, gen_op_fhsubd) 50993d50b728SRichard Henderson TRANS(FNHADDd, VIS3, do_ddd, a, gen_op_fnhaddd) 51003d50b728SRichard Henderson 5101bc3f14a9SRichard Henderson TRANS(FPADD64, VIS3B, do_ddd, a, tcg_gen_add_i64) 5102bc3f14a9SRichard Henderson TRANS(FPSUB64, VIS3B, do_ddd, a, tcg_gen_sub_i64) 5103fbc5c8d4SRichard Henderson TRANS(FSLAS16, VIS3, do_ddd, a, gen_helper_fslas16) 5104fbc5c8d4SRichard Henderson TRANS(FSLAS32, VIS3, do_ddd, a, gen_helper_fslas32) 5105bc3f14a9SRichard Henderson 5106e2fa6bd1SRichard Henderson static bool do_rdd(DisasContext *dc, arg_r_r_r *a, 5107e2fa6bd1SRichard Henderson void (*func)(TCGv, TCGv_i64, TCGv_i64)) 5108e2fa6bd1SRichard Henderson { 5109e2fa6bd1SRichard Henderson TCGv_i64 src1, src2; 5110e2fa6bd1SRichard Henderson TCGv dst; 5111e2fa6bd1SRichard Henderson 5112e2fa6bd1SRichard Henderson if (gen_trap_ifnofpu(dc)) { 5113e2fa6bd1SRichard Henderson return true; 5114e2fa6bd1SRichard Henderson } 5115e2fa6bd1SRichard Henderson 5116e2fa6bd1SRichard Henderson dst = gen_dest_gpr(dc, a->rd); 5117e2fa6bd1SRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1); 5118e2fa6bd1SRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2); 5119e2fa6bd1SRichard Henderson func(dst, src1, src2); 5120e2fa6bd1SRichard Henderson gen_store_gpr(dc, a->rd, dst); 5121e2fa6bd1SRichard Henderson return advance_pc(dc); 5122e2fa6bd1SRichard Henderson } 5123e2fa6bd1SRichard Henderson 5124e2fa6bd1SRichard Henderson TRANS(FPCMPLE16, VIS1, do_rdd, a, gen_helper_fcmple16) 5125e2fa6bd1SRichard Henderson TRANS(FPCMPNE16, VIS1, do_rdd, a, gen_helper_fcmpne16) 5126e2fa6bd1SRichard Henderson TRANS(FPCMPGT16, VIS1, do_rdd, a, gen_helper_fcmpgt16) 5127e2fa6bd1SRichard Henderson TRANS(FPCMPEQ16, VIS1, do_rdd, a, gen_helper_fcmpeq16) 5128*b3c934ddSRichard Henderson TRANS(FPCMPULE16, VIS4, do_rdd, a, gen_helper_fcmpule16) 5129*b3c934ddSRichard Henderson TRANS(FPCMPUGT16, VIS4, do_rdd, a, gen_helper_fcmpugt16) 5130e2fa6bd1SRichard Henderson 5131e2fa6bd1SRichard Henderson TRANS(FPCMPLE32, VIS1, do_rdd, a, gen_helper_fcmple32) 5132e2fa6bd1SRichard Henderson TRANS(FPCMPNE32, VIS1, do_rdd, a, gen_helper_fcmpne32) 5133e2fa6bd1SRichard Henderson TRANS(FPCMPGT32, VIS1, do_rdd, a, gen_helper_fcmpgt32) 5134e2fa6bd1SRichard Henderson TRANS(FPCMPEQ32, VIS1, do_rdd, a, gen_helper_fcmpeq32) 5135*b3c934ddSRichard Henderson TRANS(FPCMPULE32, VIS4, do_rdd, a, gen_helper_fcmpule32) 5136*b3c934ddSRichard Henderson TRANS(FPCMPUGT32, VIS4, do_rdd, a, gen_helper_fcmpugt32) 5137e2fa6bd1SRichard Henderson 5138669e0774SRichard Henderson TRANS(FPCMPEQ8, VIS3B, do_rdd, a, gen_helper_fcmpeq8) 5139669e0774SRichard Henderson TRANS(FPCMPNE8, VIS3B, do_rdd, a, gen_helper_fcmpne8) 5140669e0774SRichard Henderson TRANS(FPCMPULE8, VIS3B, do_rdd, a, gen_helper_fcmpule8) 5141669e0774SRichard Henderson TRANS(FPCMPUGT8, VIS3B, do_rdd, a, gen_helper_fcmpugt8) 5142*b3c934ddSRichard Henderson TRANS(FPCMPLE8, VIS4, do_rdd, a, gen_helper_fcmple8) 5143*b3c934ddSRichard Henderson TRANS(FPCMPGT8, VIS4, do_rdd, a, gen_helper_fcmpgt8) 5144669e0774SRichard Henderson 51457d5ebd8fSRichard Henderson TRANS(PDISTN, VIS3, do_rdd, a, gen_op_pdistn) 5146029b0283SRichard Henderson TRANS(XMULX, VIS3, do_rrr, a, gen_helper_xmulx) 5147029b0283SRichard Henderson TRANS(XMULXHI, VIS3, do_rrr, a, gen_helper_xmulxhi) 51487d5ebd8fSRichard Henderson 5149f2a59b0aSRichard Henderson static bool do_env_ddd(DisasContext *dc, arg_r_r_r *a, 5150f2a59b0aSRichard Henderson void (*func)(TCGv_i64, TCGv_env, TCGv_i64, TCGv_i64)) 5151f2a59b0aSRichard Henderson { 5152f2a59b0aSRichard Henderson TCGv_i64 dst, src1, src2; 5153f2a59b0aSRichard Henderson 5154f2a59b0aSRichard Henderson if (gen_trap_ifnofpu(dc)) { 5155f2a59b0aSRichard Henderson return true; 5156f2a59b0aSRichard Henderson } 5157f2a59b0aSRichard Henderson 515852f46d46SRichard Henderson dst = tcg_temp_new_i64(); 5159f2a59b0aSRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1); 5160f2a59b0aSRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2); 5161f2a59b0aSRichard Henderson func(dst, tcg_env, src1, src2); 5162f2a59b0aSRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 5163f2a59b0aSRichard Henderson return advance_pc(dc); 5164f2a59b0aSRichard Henderson } 5165f2a59b0aSRichard Henderson 5166f2a59b0aSRichard Henderson TRANS(FADDd, ALL, do_env_ddd, a, gen_helper_faddd) 5167f2a59b0aSRichard Henderson TRANS(FSUBd, ALL, do_env_ddd, a, gen_helper_fsubd) 5168f2a59b0aSRichard Henderson TRANS(FMULd, ALL, do_env_ddd, a, gen_helper_fmuld) 5169f2a59b0aSRichard Henderson TRANS(FDIVd, ALL, do_env_ddd, a, gen_helper_fdivd) 51703d50b728SRichard Henderson TRANS(FNADDd, VIS3, do_env_ddd, a, gen_helper_fnaddd) 51713d50b728SRichard Henderson TRANS(FNMULd, VIS3, do_env_ddd, a, gen_helper_fnmuld) 5172f2a59b0aSRichard Henderson 5173ff4c711bSRichard Henderson static bool trans_FsMULd(DisasContext *dc, arg_r_r_r *a) 5174ff4c711bSRichard Henderson { 5175ff4c711bSRichard Henderson TCGv_i64 dst; 5176ff4c711bSRichard Henderson TCGv_i32 src1, src2; 5177ff4c711bSRichard Henderson 5178ff4c711bSRichard Henderson if (gen_trap_ifnofpu(dc)) { 5179ff4c711bSRichard Henderson return true; 5180ff4c711bSRichard Henderson } 5181ff4c711bSRichard Henderson if (!(dc->def->features & CPU_FEATURE_FSMULD)) { 5182ff4c711bSRichard Henderson return raise_unimpfpop(dc); 5183ff4c711bSRichard Henderson } 5184ff4c711bSRichard Henderson 518552f46d46SRichard Henderson dst = tcg_temp_new_i64(); 5186ff4c711bSRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1); 5187ff4c711bSRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2); 5188ff4c711bSRichard Henderson gen_helper_fsmuld(dst, tcg_env, src1, src2); 5189ff4c711bSRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 5190ff4c711bSRichard Henderson return advance_pc(dc); 5191ff4c711bSRichard Henderson } 5192ff4c711bSRichard Henderson 51933d50b728SRichard Henderson static bool trans_FNsMULd(DisasContext *dc, arg_r_r_r *a) 51943d50b728SRichard Henderson { 51953d50b728SRichard Henderson TCGv_i64 dst; 51963d50b728SRichard Henderson TCGv_i32 src1, src2; 51973d50b728SRichard Henderson 51983d50b728SRichard Henderson if (!avail_VIS3(dc)) { 51993d50b728SRichard Henderson return false; 52003d50b728SRichard Henderson } 52013d50b728SRichard Henderson if (gen_trap_ifnofpu(dc)) { 52023d50b728SRichard Henderson return true; 52033d50b728SRichard Henderson } 52043d50b728SRichard Henderson dst = tcg_temp_new_i64(); 52053d50b728SRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1); 52063d50b728SRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2); 52073d50b728SRichard Henderson gen_helper_fnsmuld(dst, tcg_env, src1, src2); 52083d50b728SRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 52093d50b728SRichard Henderson return advance_pc(dc); 52103d50b728SRichard Henderson } 52113d50b728SRichard Henderson 52124fd71d19SRichard Henderson static bool do_ffff(DisasContext *dc, arg_r_r_r_r *a, 52134fd71d19SRichard Henderson void (*func)(TCGv_i32, TCGv_i32, TCGv_i32, TCGv_i32)) 52144fd71d19SRichard Henderson { 52154fd71d19SRichard Henderson TCGv_i32 dst, src1, src2, src3; 52164fd71d19SRichard Henderson 52174fd71d19SRichard Henderson if (gen_trap_ifnofpu(dc)) { 52184fd71d19SRichard Henderson return true; 52194fd71d19SRichard Henderson } 52204fd71d19SRichard Henderson 52214fd71d19SRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1); 52224fd71d19SRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2); 52234fd71d19SRichard Henderson src3 = gen_load_fpr_F(dc, a->rs3); 52244fd71d19SRichard Henderson dst = tcg_temp_new_i32(); 52254fd71d19SRichard Henderson func(dst, src1, src2, src3); 52264fd71d19SRichard Henderson gen_store_fpr_F(dc, a->rd, dst); 52274fd71d19SRichard Henderson return advance_pc(dc); 52284fd71d19SRichard Henderson } 52294fd71d19SRichard Henderson 52304fd71d19SRichard Henderson TRANS(FMADDs, FMAF, do_ffff, a, gen_op_fmadds) 52314fd71d19SRichard Henderson TRANS(FMSUBs, FMAF, do_ffff, a, gen_op_fmsubs) 52324fd71d19SRichard Henderson TRANS(FNMSUBs, FMAF, do_ffff, a, gen_op_fnmsubs) 52334fd71d19SRichard Henderson TRANS(FNMADDs, FMAF, do_ffff, a, gen_op_fnmadds) 52344fd71d19SRichard Henderson 52354fd71d19SRichard Henderson static bool do_dddd(DisasContext *dc, arg_r_r_r_r *a, 5236afb04344SRichard Henderson void (*func)(TCGv_i64, TCGv_i64, TCGv_i64, TCGv_i64)) 5237afb04344SRichard Henderson { 52384fd71d19SRichard Henderson TCGv_i64 dst, src1, src2, src3; 5239afb04344SRichard Henderson 5240afb04344SRichard Henderson if (gen_trap_ifnofpu(dc)) { 5241afb04344SRichard Henderson return true; 5242afb04344SRichard Henderson } 5243afb04344SRichard Henderson 524452f46d46SRichard Henderson dst = tcg_temp_new_i64(); 5245afb04344SRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1); 5246afb04344SRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2); 52474fd71d19SRichard Henderson src3 = gen_load_fpr_D(dc, a->rs3); 52484fd71d19SRichard Henderson func(dst, src1, src2, src3); 5249afb04344SRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 5250afb04344SRichard Henderson return advance_pc(dc); 5251afb04344SRichard Henderson } 5252afb04344SRichard Henderson 5253afb04344SRichard Henderson TRANS(PDIST, VIS1, do_dddd, a, gen_helper_pdist) 52544fd71d19SRichard Henderson TRANS(FMADDd, FMAF, do_dddd, a, gen_op_fmaddd) 52554fd71d19SRichard Henderson TRANS(FMSUBd, FMAF, do_dddd, a, gen_op_fmsubd) 52564fd71d19SRichard Henderson TRANS(FNMSUBd, FMAF, do_dddd, a, gen_op_fnmsubd) 52574fd71d19SRichard Henderson TRANS(FNMADDd, FMAF, do_dddd, a, gen_op_fnmaddd) 525868a414e9SRichard Henderson TRANS(FPMADDX, IMA, do_dddd, a, gen_op_fpmaddx) 525968a414e9SRichard Henderson TRANS(FPMADDXHI, IMA, do_dddd, a, gen_op_fpmaddxhi) 5260afb04344SRichard Henderson 5261b2b48493SRichard Henderson static bool trans_FALIGNDATAi(DisasContext *dc, arg_r_r_r *a) 5262b2b48493SRichard Henderson { 5263b2b48493SRichard Henderson TCGv_i64 dst, src1, src2; 5264b2b48493SRichard Henderson TCGv src3; 5265b2b48493SRichard Henderson 5266b2b48493SRichard Henderson if (!avail_VIS4(dc)) { 5267b2b48493SRichard Henderson return false; 5268b2b48493SRichard Henderson } 5269b2b48493SRichard Henderson if (gen_trap_ifnofpu(dc)) { 5270b2b48493SRichard Henderson return true; 5271b2b48493SRichard Henderson } 5272b2b48493SRichard Henderson 5273b2b48493SRichard Henderson dst = tcg_temp_new_i64(); 5274b2b48493SRichard Henderson src1 = gen_load_fpr_D(dc, a->rd); 5275b2b48493SRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2); 5276b2b48493SRichard Henderson src3 = gen_load_gpr(dc, a->rs1); 5277b2b48493SRichard Henderson gen_op_faligndata_i(dst, src1, src2, src3); 5278b2b48493SRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 5279b2b48493SRichard Henderson return advance_pc(dc); 5280b2b48493SRichard Henderson } 5281b2b48493SRichard Henderson 5282a4056239SRichard Henderson static bool do_env_qqq(DisasContext *dc, arg_r_r_r *a, 528316bedf89SRichard Henderson void (*func)(TCGv_i128, TCGv_env, TCGv_i128, TCGv_i128)) 5284a4056239SRichard Henderson { 528516bedf89SRichard Henderson TCGv_i128 src1, src2; 528616bedf89SRichard Henderson 5287a4056239SRichard Henderson if (gen_trap_ifnofpu(dc)) { 5288a4056239SRichard Henderson return true; 5289a4056239SRichard Henderson } 5290a4056239SRichard Henderson if (gen_trap_float128(dc)) { 5291a4056239SRichard Henderson return true; 5292a4056239SRichard Henderson } 5293a4056239SRichard Henderson 529416bedf89SRichard Henderson src1 = gen_load_fpr_Q(dc, a->rs1); 529516bedf89SRichard Henderson src2 = gen_load_fpr_Q(dc, a->rs2); 529616bedf89SRichard Henderson func(src1, tcg_env, src1, src2); 529716bedf89SRichard Henderson gen_store_fpr_Q(dc, a->rd, src1); 5298a4056239SRichard Henderson return advance_pc(dc); 5299a4056239SRichard Henderson } 5300a4056239SRichard Henderson 5301a4056239SRichard Henderson TRANS(FADDq, ALL, do_env_qqq, a, gen_helper_faddq) 5302a4056239SRichard Henderson TRANS(FSUBq, ALL, do_env_qqq, a, gen_helper_fsubq) 5303a4056239SRichard Henderson TRANS(FMULq, ALL, do_env_qqq, a, gen_helper_fmulq) 5304a4056239SRichard Henderson TRANS(FDIVq, ALL, do_env_qqq, a, gen_helper_fdivq) 5305a4056239SRichard Henderson 53065e3b17bbSRichard Henderson static bool trans_FdMULq(DisasContext *dc, arg_r_r_r *a) 53075e3b17bbSRichard Henderson { 53085e3b17bbSRichard Henderson TCGv_i64 src1, src2; 5309ba21dc99SRichard Henderson TCGv_i128 dst; 53105e3b17bbSRichard Henderson 53115e3b17bbSRichard Henderson if (gen_trap_ifnofpu(dc)) { 53125e3b17bbSRichard Henderson return true; 53135e3b17bbSRichard Henderson } 53145e3b17bbSRichard Henderson if (gen_trap_float128(dc)) { 53155e3b17bbSRichard Henderson return true; 53165e3b17bbSRichard Henderson } 53175e3b17bbSRichard Henderson 53185e3b17bbSRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1); 53195e3b17bbSRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2); 5320ba21dc99SRichard Henderson dst = tcg_temp_new_i128(); 5321ba21dc99SRichard Henderson gen_helper_fdmulq(dst, tcg_env, src1, src2); 5322ba21dc99SRichard Henderson gen_store_fpr_Q(dc, a->rd, dst); 53235e3b17bbSRichard Henderson return advance_pc(dc); 53245e3b17bbSRichard Henderson } 53255e3b17bbSRichard Henderson 5326f7ec8155SRichard Henderson static bool do_fmovr(DisasContext *dc, arg_FMOVRs *a, bool is_128, 5327f7ec8155SRichard Henderson void (*func)(DisasContext *, DisasCompare *, int, int)) 5328f7ec8155SRichard Henderson { 5329f7ec8155SRichard Henderson DisasCompare cmp; 5330f7ec8155SRichard Henderson 53312c4f56c9SRichard Henderson if (!gen_compare_reg(&cmp, a->cond, gen_load_gpr(dc, a->rs1))) { 53322c4f56c9SRichard Henderson return false; 53332c4f56c9SRichard Henderson } 5334f7ec8155SRichard Henderson if (gen_trap_ifnofpu(dc)) { 5335f7ec8155SRichard Henderson return true; 5336f7ec8155SRichard Henderson } 5337f7ec8155SRichard Henderson if (is_128 && gen_trap_float128(dc)) { 5338f7ec8155SRichard Henderson return true; 5339f7ec8155SRichard Henderson } 5340f7ec8155SRichard Henderson 5341f7ec8155SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 5342f7ec8155SRichard Henderson func(dc, &cmp, a->rd, a->rs2); 5343f7ec8155SRichard Henderson return advance_pc(dc); 5344f7ec8155SRichard Henderson } 5345f7ec8155SRichard Henderson 5346f7ec8155SRichard Henderson TRANS(FMOVRs, 64, do_fmovr, a, false, gen_fmovs) 5347f7ec8155SRichard Henderson TRANS(FMOVRd, 64, do_fmovr, a, false, gen_fmovd) 5348f7ec8155SRichard Henderson TRANS(FMOVRq, 64, do_fmovr, a, true, gen_fmovq) 5349f7ec8155SRichard Henderson 5350f7ec8155SRichard Henderson static bool do_fmovcc(DisasContext *dc, arg_FMOVscc *a, bool is_128, 5351f7ec8155SRichard Henderson void (*func)(DisasContext *, DisasCompare *, int, int)) 5352f7ec8155SRichard Henderson { 5353f7ec8155SRichard Henderson DisasCompare cmp; 5354f7ec8155SRichard Henderson 5355f7ec8155SRichard Henderson if (gen_trap_ifnofpu(dc)) { 5356f7ec8155SRichard Henderson return true; 5357f7ec8155SRichard Henderson } 5358f7ec8155SRichard Henderson if (is_128 && gen_trap_float128(dc)) { 5359f7ec8155SRichard Henderson return true; 5360f7ec8155SRichard Henderson } 5361f7ec8155SRichard Henderson 5362f7ec8155SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 5363f7ec8155SRichard Henderson gen_compare(&cmp, a->cc, a->cond, dc); 5364f7ec8155SRichard Henderson func(dc, &cmp, a->rd, a->rs2); 5365f7ec8155SRichard Henderson return advance_pc(dc); 5366f7ec8155SRichard Henderson } 5367f7ec8155SRichard Henderson 5368f7ec8155SRichard Henderson TRANS(FMOVscc, 64, do_fmovcc, a, false, gen_fmovs) 5369f7ec8155SRichard Henderson TRANS(FMOVdcc, 64, do_fmovcc, a, false, gen_fmovd) 5370f7ec8155SRichard Henderson TRANS(FMOVqcc, 64, do_fmovcc, a, true, gen_fmovq) 5371f7ec8155SRichard Henderson 5372f7ec8155SRichard Henderson static bool do_fmovfcc(DisasContext *dc, arg_FMOVsfcc *a, bool is_128, 5373f7ec8155SRichard Henderson void (*func)(DisasContext *, DisasCompare *, int, int)) 5374f7ec8155SRichard Henderson { 5375f7ec8155SRichard Henderson DisasCompare cmp; 5376f7ec8155SRichard Henderson 5377f7ec8155SRichard Henderson if (gen_trap_ifnofpu(dc)) { 5378f7ec8155SRichard Henderson return true; 5379f7ec8155SRichard Henderson } 5380f7ec8155SRichard Henderson if (is_128 && gen_trap_float128(dc)) { 5381f7ec8155SRichard Henderson return true; 5382f7ec8155SRichard Henderson } 5383f7ec8155SRichard Henderson 5384f7ec8155SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 5385f7ec8155SRichard Henderson gen_fcompare(&cmp, a->cc, a->cond); 5386f7ec8155SRichard Henderson func(dc, &cmp, a->rd, a->rs2); 5387f7ec8155SRichard Henderson return advance_pc(dc); 5388f7ec8155SRichard Henderson } 5389f7ec8155SRichard Henderson 5390f7ec8155SRichard Henderson TRANS(FMOVsfcc, 64, do_fmovfcc, a, false, gen_fmovs) 5391f7ec8155SRichard Henderson TRANS(FMOVdfcc, 64, do_fmovfcc, a, false, gen_fmovd) 5392f7ec8155SRichard Henderson TRANS(FMOVqfcc, 64, do_fmovfcc, a, true, gen_fmovq) 5393f7ec8155SRichard Henderson 539440f9ad21SRichard Henderson static bool do_fcmps(DisasContext *dc, arg_FCMPs *a, bool e) 539540f9ad21SRichard Henderson { 539640f9ad21SRichard Henderson TCGv_i32 src1, src2; 539740f9ad21SRichard Henderson 539840f9ad21SRichard Henderson if (avail_32(dc) && a->cc != 0) { 539940f9ad21SRichard Henderson return false; 540040f9ad21SRichard Henderson } 540140f9ad21SRichard Henderson if (gen_trap_ifnofpu(dc)) { 540240f9ad21SRichard Henderson return true; 540340f9ad21SRichard Henderson } 540440f9ad21SRichard Henderson 540540f9ad21SRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1); 540640f9ad21SRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2); 540740f9ad21SRichard Henderson if (e) { 5408d8c5b92fSRichard Henderson gen_helper_fcmpes(cpu_fcc[a->cc], tcg_env, src1, src2); 540940f9ad21SRichard Henderson } else { 5410d8c5b92fSRichard Henderson gen_helper_fcmps(cpu_fcc[a->cc], tcg_env, src1, src2); 541140f9ad21SRichard Henderson } 541240f9ad21SRichard Henderson return advance_pc(dc); 541340f9ad21SRichard Henderson } 541440f9ad21SRichard Henderson 541540f9ad21SRichard Henderson TRANS(FCMPs, ALL, do_fcmps, a, false) 541640f9ad21SRichard Henderson TRANS(FCMPEs, ALL, do_fcmps, a, true) 541740f9ad21SRichard Henderson 541840f9ad21SRichard Henderson static bool do_fcmpd(DisasContext *dc, arg_FCMPd *a, bool e) 541940f9ad21SRichard Henderson { 542040f9ad21SRichard Henderson TCGv_i64 src1, src2; 542140f9ad21SRichard Henderson 542240f9ad21SRichard Henderson if (avail_32(dc) && a->cc != 0) { 542340f9ad21SRichard Henderson return false; 542440f9ad21SRichard Henderson } 542540f9ad21SRichard Henderson if (gen_trap_ifnofpu(dc)) { 542640f9ad21SRichard Henderson return true; 542740f9ad21SRichard Henderson } 542840f9ad21SRichard Henderson 542940f9ad21SRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1); 543040f9ad21SRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2); 543140f9ad21SRichard Henderson if (e) { 5432d8c5b92fSRichard Henderson gen_helper_fcmped(cpu_fcc[a->cc], tcg_env, src1, src2); 543340f9ad21SRichard Henderson } else { 5434d8c5b92fSRichard Henderson gen_helper_fcmpd(cpu_fcc[a->cc], tcg_env, src1, src2); 543540f9ad21SRichard Henderson } 543640f9ad21SRichard Henderson return advance_pc(dc); 543740f9ad21SRichard Henderson } 543840f9ad21SRichard Henderson 543940f9ad21SRichard Henderson TRANS(FCMPd, ALL, do_fcmpd, a, false) 544040f9ad21SRichard Henderson TRANS(FCMPEd, ALL, do_fcmpd, a, true) 544140f9ad21SRichard Henderson 544240f9ad21SRichard Henderson static bool do_fcmpq(DisasContext *dc, arg_FCMPq *a, bool e) 544340f9ad21SRichard Henderson { 5444f3ceafadSRichard Henderson TCGv_i128 src1, src2; 5445f3ceafadSRichard Henderson 544640f9ad21SRichard Henderson if (avail_32(dc) && a->cc != 0) { 544740f9ad21SRichard Henderson return false; 544840f9ad21SRichard Henderson } 544940f9ad21SRichard Henderson if (gen_trap_ifnofpu(dc)) { 545040f9ad21SRichard Henderson return true; 545140f9ad21SRichard Henderson } 545240f9ad21SRichard Henderson if (gen_trap_float128(dc)) { 545340f9ad21SRichard Henderson return true; 545440f9ad21SRichard Henderson } 545540f9ad21SRichard Henderson 5456f3ceafadSRichard Henderson src1 = gen_load_fpr_Q(dc, a->rs1); 5457f3ceafadSRichard Henderson src2 = gen_load_fpr_Q(dc, a->rs2); 545840f9ad21SRichard Henderson if (e) { 5459d8c5b92fSRichard Henderson gen_helper_fcmpeq(cpu_fcc[a->cc], tcg_env, src1, src2); 546040f9ad21SRichard Henderson } else { 5461d8c5b92fSRichard Henderson gen_helper_fcmpq(cpu_fcc[a->cc], tcg_env, src1, src2); 546240f9ad21SRichard Henderson } 546340f9ad21SRichard Henderson return advance_pc(dc); 546440f9ad21SRichard Henderson } 546540f9ad21SRichard Henderson 546640f9ad21SRichard Henderson TRANS(FCMPq, ALL, do_fcmpq, a, false) 546740f9ad21SRichard Henderson TRANS(FCMPEq, ALL, do_fcmpq, a, true) 546840f9ad21SRichard Henderson 54691d3ed3d7SRichard Henderson static bool trans_FLCMPs(DisasContext *dc, arg_FLCMPs *a) 54701d3ed3d7SRichard Henderson { 54711d3ed3d7SRichard Henderson TCGv_i32 src1, src2; 54721d3ed3d7SRichard Henderson 54731d3ed3d7SRichard Henderson if (!avail_VIS3(dc)) { 54741d3ed3d7SRichard Henderson return false; 54751d3ed3d7SRichard Henderson } 54761d3ed3d7SRichard Henderson if (gen_trap_ifnofpu(dc)) { 54771d3ed3d7SRichard Henderson return true; 54781d3ed3d7SRichard Henderson } 54791d3ed3d7SRichard Henderson 54801d3ed3d7SRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1); 54811d3ed3d7SRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2); 54821d3ed3d7SRichard Henderson gen_helper_flcmps(cpu_fcc[a->cc], src1, src2); 54831d3ed3d7SRichard Henderson return advance_pc(dc); 54841d3ed3d7SRichard Henderson } 54851d3ed3d7SRichard Henderson 54861d3ed3d7SRichard Henderson static bool trans_FLCMPd(DisasContext *dc, arg_FLCMPd *a) 54871d3ed3d7SRichard Henderson { 54881d3ed3d7SRichard Henderson TCGv_i64 src1, src2; 54891d3ed3d7SRichard Henderson 54901d3ed3d7SRichard Henderson if (!avail_VIS3(dc)) { 54911d3ed3d7SRichard Henderson return false; 54921d3ed3d7SRichard Henderson } 54931d3ed3d7SRichard Henderson if (gen_trap_ifnofpu(dc)) { 54941d3ed3d7SRichard Henderson return true; 54951d3ed3d7SRichard Henderson } 54961d3ed3d7SRichard Henderson 54971d3ed3d7SRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1); 54981d3ed3d7SRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2); 54991d3ed3d7SRichard Henderson gen_helper_flcmpd(cpu_fcc[a->cc], src1, src2); 55001d3ed3d7SRichard Henderson return advance_pc(dc); 55011d3ed3d7SRichard Henderson } 55021d3ed3d7SRichard Henderson 550309b157e6SRichard Henderson static bool do_movf2r(DisasContext *dc, arg_r_r *a, 550409b157e6SRichard Henderson int (*offset)(unsigned int), 550509b157e6SRichard Henderson void (*load)(TCGv, TCGv_ptr, tcg_target_long)) 550609b157e6SRichard Henderson { 550709b157e6SRichard Henderson TCGv dst; 550809b157e6SRichard Henderson 550909b157e6SRichard Henderson if (gen_trap_ifnofpu(dc)) { 551009b157e6SRichard Henderson return true; 551109b157e6SRichard Henderson } 551209b157e6SRichard Henderson dst = gen_dest_gpr(dc, a->rd); 551309b157e6SRichard Henderson load(dst, tcg_env, offset(a->rs)); 551409b157e6SRichard Henderson gen_store_gpr(dc, a->rd, dst); 551509b157e6SRichard Henderson return advance_pc(dc); 551609b157e6SRichard Henderson } 551709b157e6SRichard Henderson 551809b157e6SRichard Henderson TRANS(MOVsTOsw, VIS3B, do_movf2r, a, gen_offset_fpr_F, tcg_gen_ld32s_tl) 551909b157e6SRichard Henderson TRANS(MOVsTOuw, VIS3B, do_movf2r, a, gen_offset_fpr_F, tcg_gen_ld32u_tl) 552009b157e6SRichard Henderson TRANS(MOVdTOx, VIS3B, do_movf2r, a, gen_offset_fpr_D, tcg_gen_ld_tl) 552109b157e6SRichard Henderson 552209b157e6SRichard Henderson static bool do_movr2f(DisasContext *dc, arg_r_r *a, 552309b157e6SRichard Henderson int (*offset)(unsigned int), 552409b157e6SRichard Henderson void (*store)(TCGv, TCGv_ptr, tcg_target_long)) 552509b157e6SRichard Henderson { 552609b157e6SRichard Henderson TCGv src; 552709b157e6SRichard Henderson 552809b157e6SRichard Henderson if (gen_trap_ifnofpu(dc)) { 552909b157e6SRichard Henderson return true; 553009b157e6SRichard Henderson } 553109b157e6SRichard Henderson src = gen_load_gpr(dc, a->rs); 553209b157e6SRichard Henderson store(src, tcg_env, offset(a->rd)); 553309b157e6SRichard Henderson return advance_pc(dc); 553409b157e6SRichard Henderson } 553509b157e6SRichard Henderson 553609b157e6SRichard Henderson TRANS(MOVwTOs, VIS3B, do_movr2f, a, gen_offset_fpr_F, tcg_gen_st32_tl) 553709b157e6SRichard Henderson TRANS(MOVxTOd, VIS3B, do_movr2f, a, gen_offset_fpr_D, tcg_gen_st_tl) 553809b157e6SRichard Henderson 55396e61bc94SEmilio G. Cota static void sparc_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) 5540fcf5ef2aSThomas Huth { 55416e61bc94SEmilio G. Cota DisasContext *dc = container_of(dcbase, DisasContext, base); 55426e61bc94SEmilio G. Cota int bound; 5543af00be49SEmilio G. Cota 5544af00be49SEmilio G. Cota dc->pc = dc->base.pc_first; 55456e61bc94SEmilio G. Cota dc->npc = (target_ulong)dc->base.tb->cs_base; 55466e61bc94SEmilio G. Cota dc->mem_idx = dc->base.tb->flags & TB_FLAG_MMU_MASK; 554777976769SPhilippe Mathieu-Daudé dc->def = &cpu_env(cs)->def; 55486e61bc94SEmilio G. Cota dc->fpu_enabled = tb_fpu_enabled(dc->base.tb->flags); 55496e61bc94SEmilio G. Cota dc->address_mask_32bit = tb_am_enabled(dc->base.tb->flags); 5550c9b459aaSArtyom Tarasenko #ifndef CONFIG_USER_ONLY 55516e61bc94SEmilio G. Cota dc->supervisor = (dc->base.tb->flags & TB_FLAG_SUPER) != 0; 5552c9b459aaSArtyom Tarasenko #endif 5553fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64 5554fcf5ef2aSThomas Huth dc->fprs_dirty = 0; 55556e61bc94SEmilio G. Cota dc->asi = (dc->base.tb->flags >> TB_FLAG_ASI_SHIFT) & 0xff; 5556c9b459aaSArtyom Tarasenko #ifndef CONFIG_USER_ONLY 55576e61bc94SEmilio G. Cota dc->hypervisor = (dc->base.tb->flags & TB_FLAG_HYPER) != 0; 5558c9b459aaSArtyom Tarasenko #endif 5559fcf5ef2aSThomas Huth #endif 55606e61bc94SEmilio G. Cota /* 55616e61bc94SEmilio G. Cota * if we reach a page boundary, we stop generation so that the 55626e61bc94SEmilio G. Cota * PC of a TT_TFAULT exception is always in the right page 55636e61bc94SEmilio G. Cota */ 55646e61bc94SEmilio G. Cota bound = -(dc->base.pc_first | TARGET_PAGE_MASK) / 4; 55656e61bc94SEmilio G. Cota dc->base.max_insns = MIN(dc->base.max_insns, bound); 5566af00be49SEmilio G. Cota } 5567fcf5ef2aSThomas Huth 55686e61bc94SEmilio G. Cota static void sparc_tr_tb_start(DisasContextBase *db, CPUState *cs) 55696e61bc94SEmilio G. Cota { 55706e61bc94SEmilio G. Cota } 55716e61bc94SEmilio G. Cota 55726e61bc94SEmilio G. Cota static void sparc_tr_insn_start(DisasContextBase *dcbase, CPUState *cs) 55736e61bc94SEmilio G. Cota { 55746e61bc94SEmilio G. Cota DisasContext *dc = container_of(dcbase, DisasContext, base); 5575633c4283SRichard Henderson target_ulong npc = dc->npc; 55766e61bc94SEmilio G. Cota 5577633c4283SRichard Henderson if (npc & 3) { 5578633c4283SRichard Henderson switch (npc) { 5579633c4283SRichard Henderson case JUMP_PC: 5580fcf5ef2aSThomas Huth assert(dc->jump_pc[1] == dc->pc + 4); 5581633c4283SRichard Henderson npc = dc->jump_pc[0] | JUMP_PC; 5582633c4283SRichard Henderson break; 5583633c4283SRichard Henderson case DYNAMIC_PC: 5584633c4283SRichard Henderson case DYNAMIC_PC_LOOKUP: 5585633c4283SRichard Henderson npc = DYNAMIC_PC; 5586633c4283SRichard Henderson break; 5587633c4283SRichard Henderson default: 5588633c4283SRichard Henderson g_assert_not_reached(); 5589fcf5ef2aSThomas Huth } 55906e61bc94SEmilio G. Cota } 5591633c4283SRichard Henderson tcg_gen_insn_start(dc->pc, npc); 5592633c4283SRichard Henderson } 5593fcf5ef2aSThomas Huth 55946e61bc94SEmilio G. Cota static void sparc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) 55956e61bc94SEmilio G. Cota { 55966e61bc94SEmilio G. Cota DisasContext *dc = container_of(dcbase, DisasContext, base); 55976e61bc94SEmilio G. Cota unsigned int insn; 5598fcf5ef2aSThomas Huth 559977976769SPhilippe Mathieu-Daudé insn = translator_ldl(cpu_env(cs), &dc->base, dc->pc); 5600af00be49SEmilio G. Cota dc->base.pc_next += 4; 5601878cc677SRichard Henderson 5602878cc677SRichard Henderson if (!decode(dc, insn)) { 5603ba9c09b4SRichard Henderson gen_exception(dc, TT_ILL_INSN); 5604878cc677SRichard Henderson } 5605fcf5ef2aSThomas Huth 5606af00be49SEmilio G. Cota if (dc->base.is_jmp == DISAS_NORETURN) { 56076e61bc94SEmilio G. Cota return; 5608c5e6ccdfSEmilio G. Cota } 5609af00be49SEmilio G. Cota if (dc->pc != dc->base.pc_next) { 56106e61bc94SEmilio G. Cota dc->base.is_jmp = DISAS_TOO_MANY; 5611af00be49SEmilio G. Cota } 56126e61bc94SEmilio G. Cota } 5613fcf5ef2aSThomas Huth 56146e61bc94SEmilio G. Cota static void sparc_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs) 56156e61bc94SEmilio G. Cota { 56166e61bc94SEmilio G. Cota DisasContext *dc = container_of(dcbase, DisasContext, base); 5617186e7890SRichard Henderson DisasDelayException *e, *e_next; 5618633c4283SRichard Henderson bool may_lookup; 56196e61bc94SEmilio G. Cota 562089527e3aSRichard Henderson finishing_insn(dc); 562189527e3aSRichard Henderson 562246bb0137SMark Cave-Ayland switch (dc->base.is_jmp) { 562346bb0137SMark Cave-Ayland case DISAS_NEXT: 562446bb0137SMark Cave-Ayland case DISAS_TOO_MANY: 5625633c4283SRichard Henderson if (((dc->pc | dc->npc) & 3) == 0) { 5626fcf5ef2aSThomas Huth /* static PC and NPC: we can use direct chaining */ 5627fcf5ef2aSThomas Huth gen_goto_tb(dc, 0, dc->pc, dc->npc); 5628633c4283SRichard Henderson break; 5629fcf5ef2aSThomas Huth } 5630633c4283SRichard Henderson 5631930f1865SRichard Henderson may_lookup = true; 5632633c4283SRichard Henderson if (dc->pc & 3) { 5633633c4283SRichard Henderson switch (dc->pc) { 5634633c4283SRichard Henderson case DYNAMIC_PC_LOOKUP: 5635633c4283SRichard Henderson break; 5636633c4283SRichard Henderson case DYNAMIC_PC: 5637633c4283SRichard Henderson may_lookup = false; 5638633c4283SRichard Henderson break; 5639633c4283SRichard Henderson default: 5640633c4283SRichard Henderson g_assert_not_reached(); 5641633c4283SRichard Henderson } 5642633c4283SRichard Henderson } else { 5643633c4283SRichard Henderson tcg_gen_movi_tl(cpu_pc, dc->pc); 5644633c4283SRichard Henderson } 5645633c4283SRichard Henderson 5646930f1865SRichard Henderson if (dc->npc & 3) { 5647930f1865SRichard Henderson switch (dc->npc) { 5648930f1865SRichard Henderson case JUMP_PC: 5649930f1865SRichard Henderson gen_generic_branch(dc); 5650930f1865SRichard Henderson break; 5651930f1865SRichard Henderson case DYNAMIC_PC: 5652930f1865SRichard Henderson may_lookup = false; 5653930f1865SRichard Henderson break; 5654930f1865SRichard Henderson case DYNAMIC_PC_LOOKUP: 5655930f1865SRichard Henderson break; 5656930f1865SRichard Henderson default: 5657930f1865SRichard Henderson g_assert_not_reached(); 5658930f1865SRichard Henderson } 5659930f1865SRichard Henderson } else { 5660930f1865SRichard Henderson tcg_gen_movi_tl(cpu_npc, dc->npc); 5661930f1865SRichard Henderson } 5662633c4283SRichard Henderson if (may_lookup) { 5663633c4283SRichard Henderson tcg_gen_lookup_and_goto_ptr(); 5664633c4283SRichard Henderson } else { 566507ea28b4SRichard Henderson tcg_gen_exit_tb(NULL, 0); 5666fcf5ef2aSThomas Huth } 566746bb0137SMark Cave-Ayland break; 566846bb0137SMark Cave-Ayland 566946bb0137SMark Cave-Ayland case DISAS_NORETURN: 567046bb0137SMark Cave-Ayland break; 567146bb0137SMark Cave-Ayland 567246bb0137SMark Cave-Ayland case DISAS_EXIT: 567346bb0137SMark Cave-Ayland /* Exit TB */ 567446bb0137SMark Cave-Ayland save_state(dc); 567546bb0137SMark Cave-Ayland tcg_gen_exit_tb(NULL, 0); 567646bb0137SMark Cave-Ayland break; 567746bb0137SMark Cave-Ayland 567846bb0137SMark Cave-Ayland default: 567946bb0137SMark Cave-Ayland g_assert_not_reached(); 5680fcf5ef2aSThomas Huth } 5681186e7890SRichard Henderson 5682186e7890SRichard Henderson for (e = dc->delay_excp_list; e ; e = e_next) { 5683186e7890SRichard Henderson gen_set_label(e->lab); 5684186e7890SRichard Henderson 5685186e7890SRichard Henderson tcg_gen_movi_tl(cpu_pc, e->pc); 5686186e7890SRichard Henderson if (e->npc % 4 == 0) { 5687186e7890SRichard Henderson tcg_gen_movi_tl(cpu_npc, e->npc); 5688186e7890SRichard Henderson } 5689186e7890SRichard Henderson gen_helper_raise_exception(tcg_env, e->excp); 5690186e7890SRichard Henderson 5691186e7890SRichard Henderson e_next = e->next; 5692186e7890SRichard Henderson g_free(e); 5693186e7890SRichard Henderson } 5694fcf5ef2aSThomas Huth } 56956e61bc94SEmilio G. Cota 56966e61bc94SEmilio G. Cota static const TranslatorOps sparc_tr_ops = { 56976e61bc94SEmilio G. Cota .init_disas_context = sparc_tr_init_disas_context, 56986e61bc94SEmilio G. Cota .tb_start = sparc_tr_tb_start, 56996e61bc94SEmilio G. Cota .insn_start = sparc_tr_insn_start, 57006e61bc94SEmilio G. Cota .translate_insn = sparc_tr_translate_insn, 57016e61bc94SEmilio G. Cota .tb_stop = sparc_tr_tb_stop, 57026e61bc94SEmilio G. Cota }; 57036e61bc94SEmilio G. Cota 5704597f9b2dSRichard Henderson void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int *max_insns, 570532f0c394SAnton Johansson vaddr pc, void *host_pc) 57066e61bc94SEmilio G. Cota { 57076e61bc94SEmilio G. Cota DisasContext dc = {}; 57086e61bc94SEmilio G. Cota 5709306c8721SRichard Henderson translator_loop(cs, tb, max_insns, pc, host_pc, &sparc_tr_ops, &dc.base); 5710fcf5ef2aSThomas Huth } 5711fcf5ef2aSThomas Huth 571255c3ceefSRichard Henderson void sparc_tcg_init(void) 5713fcf5ef2aSThomas Huth { 5714fcf5ef2aSThomas Huth static const char gregnames[32][4] = { 5715fcf5ef2aSThomas Huth "g0", "g1", "g2", "g3", "g4", "g5", "g6", "g7", 5716fcf5ef2aSThomas Huth "o0", "o1", "o2", "o3", "o4", "o5", "o6", "o7", 5717fcf5ef2aSThomas Huth "l0", "l1", "l2", "l3", "l4", "l5", "l6", "l7", 5718fcf5ef2aSThomas Huth "i0", "i1", "i2", "i3", "i4", "i5", "i6", "i7", 5719fcf5ef2aSThomas Huth }; 5720fcf5ef2aSThomas Huth 5721d8c5b92fSRichard Henderson static const struct { TCGv_i32 *ptr; int off; const char *name; } r32[] = { 5722d8c5b92fSRichard Henderson #ifdef TARGET_SPARC64 5723d8c5b92fSRichard Henderson { &cpu_fprs, offsetof(CPUSPARCState, fprs), "fprs" }, 5724d8c5b92fSRichard Henderson { &cpu_fcc[0], offsetof(CPUSPARCState, fcc[0]), "fcc0" }, 5725d8c5b92fSRichard Henderson { &cpu_fcc[1], offsetof(CPUSPARCState, fcc[1]), "fcc1" }, 5726d8c5b92fSRichard Henderson { &cpu_fcc[2], offsetof(CPUSPARCState, fcc[2]), "fcc2" }, 5727d8c5b92fSRichard Henderson { &cpu_fcc[3], offsetof(CPUSPARCState, fcc[3]), "fcc3" }, 5728d8c5b92fSRichard Henderson #else 5729d8c5b92fSRichard Henderson { &cpu_fcc[0], offsetof(CPUSPARCState, fcc[0]), "fcc" }, 5730d8c5b92fSRichard Henderson #endif 5731d8c5b92fSRichard Henderson }; 5732d8c5b92fSRichard Henderson 5733fcf5ef2aSThomas Huth static const struct { TCGv *ptr; int off; const char *name; } rtl[] = { 5734fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64 5735fcf5ef2aSThomas Huth { &cpu_gsr, offsetof(CPUSPARCState, gsr), "gsr" }, 57362a1905c7SRichard Henderson { &cpu_xcc_Z, offsetof(CPUSPARCState, xcc_Z), "xcc_Z" }, 57372a1905c7SRichard Henderson { &cpu_xcc_C, offsetof(CPUSPARCState, xcc_C), "xcc_C" }, 5738fcf5ef2aSThomas Huth #endif 57392a1905c7SRichard Henderson { &cpu_cc_N, offsetof(CPUSPARCState, cc_N), "cc_N" }, 57402a1905c7SRichard Henderson { &cpu_cc_V, offsetof(CPUSPARCState, cc_V), "cc_V" }, 57412a1905c7SRichard Henderson { &cpu_icc_Z, offsetof(CPUSPARCState, icc_Z), "icc_Z" }, 57422a1905c7SRichard Henderson { &cpu_icc_C, offsetof(CPUSPARCState, icc_C), "icc_C" }, 5743fcf5ef2aSThomas Huth { &cpu_cond, offsetof(CPUSPARCState, cond), "cond" }, 5744fcf5ef2aSThomas Huth { &cpu_pc, offsetof(CPUSPARCState, pc), "pc" }, 5745fcf5ef2aSThomas Huth { &cpu_npc, offsetof(CPUSPARCState, npc), "npc" }, 5746fcf5ef2aSThomas Huth { &cpu_y, offsetof(CPUSPARCState, y), "y" }, 5747fcf5ef2aSThomas Huth { &cpu_tbr, offsetof(CPUSPARCState, tbr), "tbr" }, 5748fcf5ef2aSThomas Huth }; 5749fcf5ef2aSThomas Huth 5750fcf5ef2aSThomas Huth unsigned int i; 5751fcf5ef2aSThomas Huth 5752ad75a51eSRichard Henderson cpu_regwptr = tcg_global_mem_new_ptr(tcg_env, 5753fcf5ef2aSThomas Huth offsetof(CPUSPARCState, regwptr), 5754fcf5ef2aSThomas Huth "regwptr"); 5755fcf5ef2aSThomas Huth 5756d8c5b92fSRichard Henderson for (i = 0; i < ARRAY_SIZE(r32); ++i) { 5757d8c5b92fSRichard Henderson *r32[i].ptr = tcg_global_mem_new_i32(tcg_env, r32[i].off, r32[i].name); 5758d8c5b92fSRichard Henderson } 5759d8c5b92fSRichard Henderson 5760fcf5ef2aSThomas Huth for (i = 0; i < ARRAY_SIZE(rtl); ++i) { 5761ad75a51eSRichard Henderson *rtl[i].ptr = tcg_global_mem_new(tcg_env, rtl[i].off, rtl[i].name); 5762fcf5ef2aSThomas Huth } 5763fcf5ef2aSThomas Huth 5764f764718dSRichard Henderson cpu_regs[0] = NULL; 5765fcf5ef2aSThomas Huth for (i = 1; i < 8; ++i) { 5766ad75a51eSRichard Henderson cpu_regs[i] = tcg_global_mem_new(tcg_env, 5767fcf5ef2aSThomas Huth offsetof(CPUSPARCState, gregs[i]), 5768fcf5ef2aSThomas Huth gregnames[i]); 5769fcf5ef2aSThomas Huth } 5770fcf5ef2aSThomas Huth 5771fcf5ef2aSThomas Huth for (i = 8; i < 32; ++i) { 5772fcf5ef2aSThomas Huth cpu_regs[i] = tcg_global_mem_new(cpu_regwptr, 5773fcf5ef2aSThomas Huth (i - 8) * sizeof(target_ulong), 5774fcf5ef2aSThomas Huth gregnames[i]); 5775fcf5ef2aSThomas Huth } 5776fcf5ef2aSThomas Huth } 5777fcf5ef2aSThomas Huth 5778f36aaa53SRichard Henderson void sparc_restore_state_to_opc(CPUState *cs, 5779f36aaa53SRichard Henderson const TranslationBlock *tb, 5780f36aaa53SRichard Henderson const uint64_t *data) 5781fcf5ef2aSThomas Huth { 578277976769SPhilippe Mathieu-Daudé CPUSPARCState *env = cpu_env(cs); 5783fcf5ef2aSThomas Huth target_ulong pc = data[0]; 5784fcf5ef2aSThomas Huth target_ulong npc = data[1]; 5785fcf5ef2aSThomas Huth 5786fcf5ef2aSThomas Huth env->pc = pc; 5787fcf5ef2aSThomas Huth if (npc == DYNAMIC_PC) { 5788fcf5ef2aSThomas Huth /* dynamic NPC: already stored */ 5789fcf5ef2aSThomas Huth } else if (npc & JUMP_PC) { 5790fcf5ef2aSThomas Huth /* jump PC: use 'cond' and the jump targets of the translation */ 5791fcf5ef2aSThomas Huth if (env->cond) { 5792fcf5ef2aSThomas Huth env->npc = npc & ~3; 5793fcf5ef2aSThomas Huth } else { 5794fcf5ef2aSThomas Huth env->npc = pc + 4; 5795fcf5ef2aSThomas Huth } 5796fcf5ef2aSThomas Huth } else { 5797fcf5ef2aSThomas Huth env->npc = npc; 5798fcf5ef2aSThomas Huth } 5799fcf5ef2aSThomas Huth } 5800