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; }) 70e2fa6bd1SRichard Henderson # define gen_helper_fcmpgt16 ({ qemu_build_not_reached(); NULL; }) 71e2fa6bd1SRichard Henderson # define gen_helper_fcmpgt32 ({ qemu_build_not_reached(); NULL; }) 72e2fa6bd1SRichard Henderson # define gen_helper_fcmple16 ({ qemu_build_not_reached(); NULL; }) 73e2fa6bd1SRichard Henderson # define gen_helper_fcmple32 ({ qemu_build_not_reached(); NULL; }) 74669e0774SRichard Henderson # define gen_helper_fcmpne8 ({ qemu_build_not_reached(); NULL; }) 75e2fa6bd1SRichard Henderson # define gen_helper_fcmpne16 ({ qemu_build_not_reached(); NULL; }) 76e2fa6bd1SRichard Henderson # define gen_helper_fcmpne32 ({ qemu_build_not_reached(); NULL; }) 77669e0774SRichard Henderson # define gen_helper_fcmpule8 ({ qemu_build_not_reached(); NULL; }) 78669e0774SRichard Henderson # define gen_helper_fcmpugt8 ({ qemu_build_not_reached(); NULL; }) 798aa418b3SRichard Henderson # define gen_helper_fdtox ({ qemu_build_not_reached(); NULL; }) 80e06c9f83SRichard Henderson # define gen_helper_fexpand ({ qemu_build_not_reached(); NULL; }) 81e06c9f83SRichard Henderson # define gen_helper_fmul8sux16 ({ qemu_build_not_reached(); NULL; }) 82e06c9f83SRichard Henderson # define gen_helper_fmul8ulx16 ({ qemu_build_not_reached(); NULL; }) 83e06c9f83SRichard Henderson # define gen_helper_fmul8x16 ({ qemu_build_not_reached(); NULL; }) 84e06c9f83SRichard Henderson # define gen_helper_fpmerge ({ qemu_build_not_reached(); NULL; }) 851617586fSRichard Henderson # define gen_helper_fqtox ({ qemu_build_not_reached(); NULL; }) 86fbc5c8d4SRichard Henderson # define gen_helper_fslas16 ({ qemu_build_not_reached(); NULL; }) 87fbc5c8d4SRichard Henderson # define gen_helper_fslas32 ({ qemu_build_not_reached(); NULL; }) 88199d43efSRichard Henderson # define gen_helper_fstox ({ qemu_build_not_reached(); NULL; }) 898aa418b3SRichard Henderson # define gen_helper_fxtod ({ qemu_build_not_reached(); NULL; }) 907b8e3e1aSRichard Henderson # define gen_helper_fxtoq ({ qemu_build_not_reached(); NULL; }) 91f4e18df5SRichard Henderson # define gen_helper_fxtos ({ qemu_build_not_reached(); NULL; }) 92afb04344SRichard Henderson # define gen_helper_pdist ({ qemu_build_not_reached(); NULL; }) 93029b0283SRichard Henderson # define gen_helper_xmulx ({ qemu_build_not_reached(); NULL; }) 94029b0283SRichard Henderson # define gen_helper_xmulxhi ({ qemu_build_not_reached(); NULL; }) 95668bb9b7SRichard Henderson # define MAXTL_MASK 0 96af25071cSRichard Henderson #endif 97af25071cSRichard Henderson 98633c4283SRichard Henderson /* Dynamic PC, must exit to main loop. */ 99633c4283SRichard Henderson #define DYNAMIC_PC 1 100633c4283SRichard Henderson /* Dynamic PC, one of two values according to jump_pc[T2]. */ 101633c4283SRichard Henderson #define JUMP_PC 2 102633c4283SRichard Henderson /* Dynamic PC, may lookup next TB. */ 103633c4283SRichard Henderson #define DYNAMIC_PC_LOOKUP 3 104fcf5ef2aSThomas Huth 10546bb0137SMark Cave-Ayland #define DISAS_EXIT DISAS_TARGET_0 10646bb0137SMark Cave-Ayland 107fcf5ef2aSThomas Huth /* global register indexes */ 108fcf5ef2aSThomas Huth static TCGv_ptr cpu_regwptr; 109c9fa8e58SRichard Henderson static TCGv cpu_pc, cpu_npc; 110fcf5ef2aSThomas Huth static TCGv cpu_regs[32]; 111fcf5ef2aSThomas Huth static TCGv cpu_y; 112fcf5ef2aSThomas Huth static TCGv cpu_tbr; 113fcf5ef2aSThomas Huth static TCGv cpu_cond; 1142a1905c7SRichard Henderson static TCGv cpu_cc_N; 1152a1905c7SRichard Henderson static TCGv cpu_cc_V; 1162a1905c7SRichard Henderson static TCGv cpu_icc_Z; 1172a1905c7SRichard Henderson static TCGv cpu_icc_C; 118fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64 1192a1905c7SRichard Henderson static TCGv cpu_xcc_Z; 1202a1905c7SRichard Henderson static TCGv cpu_xcc_C; 1212a1905c7SRichard Henderson static TCGv_i32 cpu_fprs; 122fcf5ef2aSThomas Huth static TCGv cpu_gsr; 123fcf5ef2aSThomas Huth #else 124af25071cSRichard Henderson # define cpu_fprs ({ qemu_build_not_reached(); (TCGv)NULL; }) 125af25071cSRichard Henderson # define cpu_gsr ({ qemu_build_not_reached(); (TCGv)NULL; }) 126fcf5ef2aSThomas Huth #endif 1272a1905c7SRichard Henderson 1282a1905c7SRichard Henderson #ifdef TARGET_SPARC64 1292a1905c7SRichard Henderson #define cpu_cc_Z cpu_xcc_Z 1302a1905c7SRichard Henderson #define cpu_cc_C cpu_xcc_C 1312a1905c7SRichard Henderson #else 1322a1905c7SRichard Henderson #define cpu_cc_Z cpu_icc_Z 1332a1905c7SRichard Henderson #define cpu_cc_C cpu_icc_C 1342a1905c7SRichard Henderson #define cpu_xcc_Z ({ qemu_build_not_reached(); NULL; }) 1352a1905c7SRichard Henderson #define cpu_xcc_C ({ qemu_build_not_reached(); NULL; }) 1362a1905c7SRichard Henderson #endif 1372a1905c7SRichard Henderson 1381210a036SRichard Henderson /* Floating point comparison registers */ 139d8c5b92fSRichard Henderson static TCGv_i32 cpu_fcc[TARGET_FCCREGS]; 140fcf5ef2aSThomas Huth 141af25071cSRichard Henderson #define env_field_offsetof(X) offsetof(CPUSPARCState, X) 142af25071cSRichard Henderson #ifdef TARGET_SPARC64 143cd6269f7SRichard Henderson # define env32_field_offsetof(X) ({ qemu_build_not_reached(); 0; }) 144af25071cSRichard Henderson # define env64_field_offsetof(X) env_field_offsetof(X) 145af25071cSRichard Henderson #else 146cd6269f7SRichard Henderson # define env32_field_offsetof(X) env_field_offsetof(X) 147af25071cSRichard Henderson # define env64_field_offsetof(X) ({ qemu_build_not_reached(); 0; }) 148af25071cSRichard Henderson #endif 149af25071cSRichard Henderson 150533f042fSRichard Henderson typedef struct DisasCompare { 151533f042fSRichard Henderson TCGCond cond; 152533f042fSRichard Henderson TCGv c1; 153533f042fSRichard Henderson int c2; 154533f042fSRichard Henderson } DisasCompare; 155533f042fSRichard Henderson 156186e7890SRichard Henderson typedef struct DisasDelayException { 157186e7890SRichard Henderson struct DisasDelayException *next; 158186e7890SRichard Henderson TCGLabel *lab; 159186e7890SRichard Henderson TCGv_i32 excp; 160186e7890SRichard Henderson /* Saved state at parent insn. */ 161186e7890SRichard Henderson target_ulong pc; 162186e7890SRichard Henderson target_ulong npc; 163186e7890SRichard Henderson } DisasDelayException; 164186e7890SRichard Henderson 165fcf5ef2aSThomas Huth typedef struct DisasContext { 166af00be49SEmilio G. Cota DisasContextBase base; 167fcf5ef2aSThomas Huth target_ulong pc; /* current Program Counter: integer or DYNAMIC_PC */ 168fcf5ef2aSThomas Huth target_ulong npc; /* next PC: integer or DYNAMIC_PC or JUMP_PC */ 169533f042fSRichard Henderson 170533f042fSRichard Henderson /* Used when JUMP_PC value is used. */ 171533f042fSRichard Henderson DisasCompare jump; 172533f042fSRichard Henderson target_ulong jump_pc[2]; 173533f042fSRichard Henderson 174fcf5ef2aSThomas Huth int mem_idx; 17589527e3aSRichard Henderson bool cpu_cond_live; 176c9b459aaSArtyom Tarasenko bool fpu_enabled; 177c9b459aaSArtyom Tarasenko bool address_mask_32bit; 178c9b459aaSArtyom Tarasenko #ifndef CONFIG_USER_ONLY 179c9b459aaSArtyom Tarasenko bool supervisor; 180c9b459aaSArtyom Tarasenko #ifdef TARGET_SPARC64 181c9b459aaSArtyom Tarasenko bool hypervisor; 182c9b459aaSArtyom Tarasenko #endif 183c9b459aaSArtyom Tarasenko #endif 184c9b459aaSArtyom Tarasenko 185fcf5ef2aSThomas Huth sparc_def_t *def; 186fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64 187fcf5ef2aSThomas Huth int fprs_dirty; 188fcf5ef2aSThomas Huth int asi; 189fcf5ef2aSThomas Huth #endif 190186e7890SRichard Henderson DisasDelayException *delay_excp_list; 191fcf5ef2aSThomas Huth } DisasContext; 192fcf5ef2aSThomas Huth 193fcf5ef2aSThomas Huth // This function uses non-native bit order 194fcf5ef2aSThomas Huth #define GET_FIELD(X, FROM, TO) \ 195fcf5ef2aSThomas Huth ((X) >> (31 - (TO)) & ((1 << ((TO) - (FROM) + 1)) - 1)) 196fcf5ef2aSThomas Huth 197fcf5ef2aSThomas Huth // This function uses the order in the manuals, i.e. bit 0 is 2^0 198fcf5ef2aSThomas Huth #define GET_FIELD_SP(X, FROM, TO) \ 199fcf5ef2aSThomas Huth GET_FIELD(X, 31 - (TO), 31 - (FROM)) 200fcf5ef2aSThomas Huth 201fcf5ef2aSThomas Huth #define GET_FIELDs(x,a,b) sign_extend (GET_FIELD(x,a,b), (b) - (a) + 1) 202fcf5ef2aSThomas Huth #define GET_FIELD_SPs(x,a,b) sign_extend (GET_FIELD_SP(x,a,b), ((b) - (a) + 1)) 203fcf5ef2aSThomas Huth 204fcf5ef2aSThomas Huth #define UA2005_HTRAP_MASK 0xff 205fcf5ef2aSThomas Huth #define V8_TRAP_MASK 0x7f 206fcf5ef2aSThomas Huth 207fcf5ef2aSThomas Huth #define IS_IMM (insn & (1<<13)) 208fcf5ef2aSThomas Huth 2090c2e96c1SRichard Henderson static void gen_update_fprs_dirty(DisasContext *dc, int rd) 210fcf5ef2aSThomas Huth { 211fcf5ef2aSThomas Huth #if defined(TARGET_SPARC64) 212fcf5ef2aSThomas Huth int bit = (rd < 32) ? 1 : 2; 213fcf5ef2aSThomas Huth /* If we know we've already set this bit within the TB, 214fcf5ef2aSThomas Huth we can avoid setting it again. */ 215fcf5ef2aSThomas Huth if (!(dc->fprs_dirty & bit)) { 216fcf5ef2aSThomas Huth dc->fprs_dirty |= bit; 217fcf5ef2aSThomas Huth tcg_gen_ori_i32(cpu_fprs, cpu_fprs, bit); 218fcf5ef2aSThomas Huth } 219fcf5ef2aSThomas Huth #endif 220fcf5ef2aSThomas Huth } 221fcf5ef2aSThomas Huth 222fcf5ef2aSThomas Huth /* floating point registers moves */ 2231210a036SRichard Henderson 2241210a036SRichard Henderson static int gen_offset_fpr_F(unsigned int reg) 2251210a036SRichard Henderson { 2261210a036SRichard Henderson int ret; 2271210a036SRichard Henderson 2281210a036SRichard Henderson tcg_debug_assert(reg < 32); 2291210a036SRichard Henderson ret= offsetof(CPUSPARCState, fpr[reg / 2]); 2301210a036SRichard Henderson if (reg & 1) { 2311210a036SRichard Henderson ret += offsetof(CPU_DoubleU, l.lower); 2321210a036SRichard Henderson } else { 2331210a036SRichard Henderson ret += offsetof(CPU_DoubleU, l.upper); 2341210a036SRichard Henderson } 2351210a036SRichard Henderson return ret; 2361210a036SRichard Henderson } 2371210a036SRichard Henderson 238fcf5ef2aSThomas Huth static TCGv_i32 gen_load_fpr_F(DisasContext *dc, unsigned int src) 239fcf5ef2aSThomas Huth { 24036ab4623SRichard Henderson TCGv_i32 ret = tcg_temp_new_i32(); 2411210a036SRichard Henderson tcg_gen_ld_i32(ret, tcg_env, gen_offset_fpr_F(src)); 242dc41aa7dSRichard Henderson return ret; 243fcf5ef2aSThomas Huth } 244fcf5ef2aSThomas Huth 245fcf5ef2aSThomas Huth static void gen_store_fpr_F(DisasContext *dc, unsigned int dst, TCGv_i32 v) 246fcf5ef2aSThomas Huth { 2471210a036SRichard Henderson tcg_gen_st_i32(v, tcg_env, gen_offset_fpr_F(dst)); 248fcf5ef2aSThomas Huth gen_update_fprs_dirty(dc, dst); 249fcf5ef2aSThomas Huth } 250fcf5ef2aSThomas Huth 2511210a036SRichard Henderson static int gen_offset_fpr_D(unsigned int reg) 2521210a036SRichard Henderson { 2531210a036SRichard Henderson tcg_debug_assert(reg < 64); 2541210a036SRichard Henderson tcg_debug_assert(reg % 2 == 0); 2551210a036SRichard Henderson return offsetof(CPUSPARCState, fpr[reg / 2]); 2561210a036SRichard Henderson } 2571210a036SRichard Henderson 258fcf5ef2aSThomas Huth static TCGv_i64 gen_load_fpr_D(DisasContext *dc, unsigned int src) 259fcf5ef2aSThomas Huth { 2601210a036SRichard Henderson TCGv_i64 ret = tcg_temp_new_i64(); 2611210a036SRichard Henderson tcg_gen_ld_i64(ret, tcg_env, gen_offset_fpr_D(src)); 2621210a036SRichard Henderson return ret; 263fcf5ef2aSThomas Huth } 264fcf5ef2aSThomas Huth 265fcf5ef2aSThomas Huth static void gen_store_fpr_D(DisasContext *dc, unsigned int dst, TCGv_i64 v) 266fcf5ef2aSThomas Huth { 2671210a036SRichard Henderson tcg_gen_st_i64(v, tcg_env, gen_offset_fpr_D(dst)); 268fcf5ef2aSThomas Huth gen_update_fprs_dirty(dc, dst); 269fcf5ef2aSThomas Huth } 270fcf5ef2aSThomas Huth 27133ec4245SRichard Henderson static TCGv_i128 gen_load_fpr_Q(DisasContext *dc, unsigned int src) 27233ec4245SRichard Henderson { 27333ec4245SRichard Henderson TCGv_i128 ret = tcg_temp_new_i128(); 2741210a036SRichard Henderson TCGv_i64 h = gen_load_fpr_D(dc, src); 2751210a036SRichard Henderson TCGv_i64 l = gen_load_fpr_D(dc, src + 2); 27633ec4245SRichard Henderson 2771210a036SRichard Henderson tcg_gen_concat_i64_i128(ret, l, h); 27833ec4245SRichard Henderson return ret; 27933ec4245SRichard Henderson } 28033ec4245SRichard Henderson 28133ec4245SRichard Henderson static void gen_store_fpr_Q(DisasContext *dc, unsigned int dst, TCGv_i128 v) 28233ec4245SRichard Henderson { 2831210a036SRichard Henderson TCGv_i64 h = tcg_temp_new_i64(); 2841210a036SRichard Henderson TCGv_i64 l = tcg_temp_new_i64(); 2851210a036SRichard Henderson 2861210a036SRichard Henderson tcg_gen_extr_i128_i64(l, h, v); 2871210a036SRichard Henderson gen_store_fpr_D(dc, dst, h); 2881210a036SRichard Henderson gen_store_fpr_D(dc, dst + 2, l); 28933ec4245SRichard Henderson } 29033ec4245SRichard Henderson 291fcf5ef2aSThomas Huth /* moves */ 292fcf5ef2aSThomas Huth #ifdef CONFIG_USER_ONLY 293fcf5ef2aSThomas Huth #define supervisor(dc) 0 294fcf5ef2aSThomas Huth #define hypervisor(dc) 0 295fcf5ef2aSThomas Huth #else 296fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64 297c9b459aaSArtyom Tarasenko #define hypervisor(dc) (dc->hypervisor) 298c9b459aaSArtyom Tarasenko #define supervisor(dc) (dc->supervisor | dc->hypervisor) 299fcf5ef2aSThomas Huth #else 300c9b459aaSArtyom Tarasenko #define supervisor(dc) (dc->supervisor) 301668bb9b7SRichard Henderson #define hypervisor(dc) 0 302fcf5ef2aSThomas Huth #endif 303fcf5ef2aSThomas Huth #endif 304fcf5ef2aSThomas Huth 305b1bc09eaSRichard Henderson #if !defined(TARGET_SPARC64) 306b1bc09eaSRichard Henderson # define AM_CHECK(dc) false 307b1bc09eaSRichard Henderson #elif defined(TARGET_ABI32) 308b1bc09eaSRichard Henderson # define AM_CHECK(dc) true 309b1bc09eaSRichard Henderson #elif defined(CONFIG_USER_ONLY) 310b1bc09eaSRichard Henderson # define AM_CHECK(dc) false 311fcf5ef2aSThomas Huth #else 312b1bc09eaSRichard Henderson # define AM_CHECK(dc) ((dc)->address_mask_32bit) 313fcf5ef2aSThomas Huth #endif 314fcf5ef2aSThomas Huth 3150c2e96c1SRichard Henderson static void gen_address_mask(DisasContext *dc, TCGv addr) 316fcf5ef2aSThomas Huth { 317b1bc09eaSRichard Henderson if (AM_CHECK(dc)) { 318fcf5ef2aSThomas Huth tcg_gen_andi_tl(addr, addr, 0xffffffffULL); 319b1bc09eaSRichard Henderson } 320fcf5ef2aSThomas Huth } 321fcf5ef2aSThomas Huth 32223ada1b1SRichard Henderson static target_ulong address_mask_i(DisasContext *dc, target_ulong addr) 32323ada1b1SRichard Henderson { 32423ada1b1SRichard Henderson return AM_CHECK(dc) ? (uint32_t)addr : addr; 32523ada1b1SRichard Henderson } 32623ada1b1SRichard Henderson 3270c2e96c1SRichard Henderson static TCGv gen_load_gpr(DisasContext *dc, int reg) 328fcf5ef2aSThomas Huth { 329fcf5ef2aSThomas Huth if (reg > 0) { 330fcf5ef2aSThomas Huth assert(reg < 32); 331fcf5ef2aSThomas Huth return cpu_regs[reg]; 332fcf5ef2aSThomas Huth } else { 33352123f14SRichard Henderson TCGv t = tcg_temp_new(); 334fcf5ef2aSThomas Huth tcg_gen_movi_tl(t, 0); 335fcf5ef2aSThomas Huth return t; 336fcf5ef2aSThomas Huth } 337fcf5ef2aSThomas Huth } 338fcf5ef2aSThomas Huth 3390c2e96c1SRichard Henderson static void gen_store_gpr(DisasContext *dc, int reg, TCGv v) 340fcf5ef2aSThomas Huth { 341fcf5ef2aSThomas Huth if (reg > 0) { 342fcf5ef2aSThomas Huth assert(reg < 32); 343fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_regs[reg], v); 344fcf5ef2aSThomas Huth } 345fcf5ef2aSThomas Huth } 346fcf5ef2aSThomas Huth 3470c2e96c1SRichard Henderson static TCGv gen_dest_gpr(DisasContext *dc, int reg) 348fcf5ef2aSThomas Huth { 349fcf5ef2aSThomas Huth if (reg > 0) { 350fcf5ef2aSThomas Huth assert(reg < 32); 351fcf5ef2aSThomas Huth return cpu_regs[reg]; 352fcf5ef2aSThomas Huth } else { 35352123f14SRichard Henderson return tcg_temp_new(); 354fcf5ef2aSThomas Huth } 355fcf5ef2aSThomas Huth } 356fcf5ef2aSThomas Huth 3575645aa2eSRichard Henderson static bool use_goto_tb(DisasContext *s, target_ulong pc, target_ulong npc) 358fcf5ef2aSThomas Huth { 3595645aa2eSRichard Henderson return translator_use_goto_tb(&s->base, pc) && 3605645aa2eSRichard Henderson translator_use_goto_tb(&s->base, npc); 361fcf5ef2aSThomas Huth } 362fcf5ef2aSThomas Huth 3635645aa2eSRichard Henderson static void gen_goto_tb(DisasContext *s, int tb_num, 364fcf5ef2aSThomas Huth target_ulong pc, target_ulong npc) 365fcf5ef2aSThomas Huth { 366fcf5ef2aSThomas Huth if (use_goto_tb(s, pc, npc)) { 367fcf5ef2aSThomas Huth /* jump to same page: we can use a direct jump */ 368fcf5ef2aSThomas Huth tcg_gen_goto_tb(tb_num); 369fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_pc, pc); 370fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_npc, npc); 37107ea28b4SRichard Henderson tcg_gen_exit_tb(s->base.tb, tb_num); 372fcf5ef2aSThomas Huth } else { 373f67ccb2fSRichard Henderson /* jump to another page: we can use an indirect jump */ 374fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_pc, pc); 375fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_npc, npc); 376f67ccb2fSRichard Henderson tcg_gen_lookup_and_goto_ptr(); 377fcf5ef2aSThomas Huth } 378fcf5ef2aSThomas Huth } 379fcf5ef2aSThomas Huth 380b989ce73SRichard Henderson static TCGv gen_carry32(void) 381fcf5ef2aSThomas Huth { 382b989ce73SRichard Henderson if (TARGET_LONG_BITS == 64) { 383b989ce73SRichard Henderson TCGv t = tcg_temp_new(); 384b989ce73SRichard Henderson tcg_gen_extract_tl(t, cpu_icc_C, 32, 1); 385b989ce73SRichard Henderson return t; 386b989ce73SRichard Henderson } 387b989ce73SRichard Henderson return cpu_icc_C; 388fcf5ef2aSThomas Huth } 389fcf5ef2aSThomas Huth 390b989ce73SRichard Henderson static void gen_op_addcc_int(TCGv dst, TCGv src1, TCGv src2, TCGv cin) 391fcf5ef2aSThomas Huth { 392b989ce73SRichard Henderson TCGv z = tcg_constant_tl(0); 393fcf5ef2aSThomas Huth 394b989ce73SRichard Henderson if (cin) { 395b989ce73SRichard Henderson tcg_gen_add2_tl(cpu_cc_N, cpu_cc_C, src1, z, cin, z); 396b989ce73SRichard Henderson tcg_gen_add2_tl(cpu_cc_N, cpu_cc_C, cpu_cc_N, cpu_cc_C, src2, z); 397b989ce73SRichard Henderson } else { 398b989ce73SRichard Henderson tcg_gen_add2_tl(cpu_cc_N, cpu_cc_C, src1, z, src2, z); 399b989ce73SRichard Henderson } 400b989ce73SRichard Henderson tcg_gen_xor_tl(cpu_cc_Z, src1, src2); 401b989ce73SRichard Henderson tcg_gen_xor_tl(cpu_cc_V, cpu_cc_N, src2); 402b989ce73SRichard Henderson tcg_gen_andc_tl(cpu_cc_V, cpu_cc_V, cpu_cc_Z); 403b989ce73SRichard Henderson if (TARGET_LONG_BITS == 64) { 404b989ce73SRichard Henderson /* 405b989ce73SRichard Henderson * Carry-in to bit 32 is result ^ src1 ^ src2. 406b989ce73SRichard Henderson * We already have the src xor term in Z, from computation of V. 407b989ce73SRichard Henderson */ 408b989ce73SRichard Henderson tcg_gen_xor_tl(cpu_icc_C, cpu_cc_Z, cpu_cc_N); 409b989ce73SRichard Henderson tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N); 410b989ce73SRichard Henderson } 411b989ce73SRichard Henderson tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N); 412b989ce73SRichard Henderson tcg_gen_mov_tl(dst, cpu_cc_N); 413b989ce73SRichard Henderson } 414fcf5ef2aSThomas Huth 415b989ce73SRichard Henderson static void gen_op_addcc(TCGv dst, TCGv src1, TCGv src2) 416b989ce73SRichard Henderson { 417b989ce73SRichard Henderson gen_op_addcc_int(dst, src1, src2, NULL); 418b989ce73SRichard Henderson } 419fcf5ef2aSThomas Huth 420b989ce73SRichard Henderson static void gen_op_taddcc(TCGv dst, TCGv src1, TCGv src2) 421b989ce73SRichard Henderson { 422b989ce73SRichard Henderson TCGv t = tcg_temp_new(); 423b989ce73SRichard Henderson 424b989ce73SRichard Henderson /* Save the tag bits around modification of dst. */ 425b989ce73SRichard Henderson tcg_gen_or_tl(t, src1, src2); 426b989ce73SRichard Henderson 427b989ce73SRichard Henderson gen_op_addcc(dst, src1, src2); 428b989ce73SRichard Henderson 429b989ce73SRichard Henderson /* Incorprate tag bits into icc.V */ 430b989ce73SRichard Henderson tcg_gen_andi_tl(t, t, 3); 431b989ce73SRichard Henderson tcg_gen_neg_tl(t, t); 432b989ce73SRichard Henderson tcg_gen_ext32u_tl(t, t); 433b989ce73SRichard Henderson tcg_gen_or_tl(cpu_cc_V, cpu_cc_V, t); 434b989ce73SRichard Henderson } 435b989ce73SRichard Henderson 436b989ce73SRichard Henderson static void gen_op_addc(TCGv dst, TCGv src1, TCGv src2) 437b989ce73SRichard Henderson { 438b989ce73SRichard Henderson tcg_gen_add_tl(dst, src1, src2); 439b989ce73SRichard Henderson tcg_gen_add_tl(dst, dst, gen_carry32()); 440b989ce73SRichard Henderson } 441b989ce73SRichard Henderson 442b989ce73SRichard Henderson static void gen_op_addccc(TCGv dst, TCGv src1, TCGv src2) 443b989ce73SRichard Henderson { 444b989ce73SRichard Henderson gen_op_addcc_int(dst, src1, src2, gen_carry32()); 445fcf5ef2aSThomas Huth } 446fcf5ef2aSThomas Huth 447015fc6fcSRichard Henderson static void gen_op_addxc(TCGv dst, TCGv src1, TCGv src2) 448015fc6fcSRichard Henderson { 449015fc6fcSRichard Henderson tcg_gen_add_tl(dst, src1, src2); 450015fc6fcSRichard Henderson tcg_gen_add_tl(dst, dst, cpu_cc_C); 451015fc6fcSRichard Henderson } 452015fc6fcSRichard Henderson 453015fc6fcSRichard Henderson static void gen_op_addxccc(TCGv dst, TCGv src1, TCGv src2) 454015fc6fcSRichard Henderson { 455015fc6fcSRichard Henderson gen_op_addcc_int(dst, src1, src2, cpu_cc_C); 456015fc6fcSRichard Henderson } 457015fc6fcSRichard Henderson 458f828df74SRichard Henderson static void gen_op_subcc_int(TCGv dst, TCGv src1, TCGv src2, TCGv cin) 459fcf5ef2aSThomas Huth { 460f828df74SRichard Henderson TCGv z = tcg_constant_tl(0); 461fcf5ef2aSThomas Huth 462f828df74SRichard Henderson if (cin) { 463f828df74SRichard Henderson tcg_gen_sub2_tl(cpu_cc_N, cpu_cc_C, src1, z, cin, z); 464f828df74SRichard Henderson tcg_gen_sub2_tl(cpu_cc_N, cpu_cc_C, cpu_cc_N, cpu_cc_C, src2, z); 465f828df74SRichard Henderson } else { 466f828df74SRichard Henderson tcg_gen_sub2_tl(cpu_cc_N, cpu_cc_C, src1, z, src2, z); 467f828df74SRichard Henderson } 468f828df74SRichard Henderson tcg_gen_neg_tl(cpu_cc_C, cpu_cc_C); 469f828df74SRichard Henderson tcg_gen_xor_tl(cpu_cc_Z, src1, src2); 470f828df74SRichard Henderson tcg_gen_xor_tl(cpu_cc_V, cpu_cc_N, src1); 471f828df74SRichard Henderson tcg_gen_and_tl(cpu_cc_V, cpu_cc_V, cpu_cc_Z); 472f828df74SRichard Henderson #ifdef TARGET_SPARC64 473f828df74SRichard Henderson tcg_gen_xor_tl(cpu_icc_C, cpu_cc_Z, cpu_cc_N); 474f828df74SRichard Henderson tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N); 475fcf5ef2aSThomas Huth #endif 476f828df74SRichard Henderson tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N); 477f828df74SRichard Henderson tcg_gen_mov_tl(dst, cpu_cc_N); 478fcf5ef2aSThomas Huth } 479fcf5ef2aSThomas Huth 480f828df74SRichard Henderson static void gen_op_subcc(TCGv dst, TCGv src1, TCGv src2) 481fcf5ef2aSThomas Huth { 482f828df74SRichard Henderson gen_op_subcc_int(dst, src1, src2, NULL); 483fcf5ef2aSThomas Huth } 484fcf5ef2aSThomas Huth 485f828df74SRichard Henderson static void gen_op_tsubcc(TCGv dst, TCGv src1, TCGv src2) 486fcf5ef2aSThomas Huth { 487f828df74SRichard Henderson TCGv t = tcg_temp_new(); 488fcf5ef2aSThomas Huth 489f828df74SRichard Henderson /* Save the tag bits around modification of dst. */ 490f828df74SRichard Henderson tcg_gen_or_tl(t, src1, src2); 491fcf5ef2aSThomas Huth 492f828df74SRichard Henderson gen_op_subcc(dst, src1, src2); 493f828df74SRichard Henderson 494f828df74SRichard Henderson /* Incorprate tag bits into icc.V */ 495f828df74SRichard Henderson tcg_gen_andi_tl(t, t, 3); 496f828df74SRichard Henderson tcg_gen_neg_tl(t, t); 497f828df74SRichard Henderson tcg_gen_ext32u_tl(t, t); 498f828df74SRichard Henderson tcg_gen_or_tl(cpu_cc_V, cpu_cc_V, t); 499f828df74SRichard Henderson } 500f828df74SRichard Henderson 501f828df74SRichard Henderson static void gen_op_subc(TCGv dst, TCGv src1, TCGv src2) 502f828df74SRichard Henderson { 503fcf5ef2aSThomas Huth tcg_gen_sub_tl(dst, src1, src2); 504f828df74SRichard Henderson tcg_gen_sub_tl(dst, dst, gen_carry32()); 505fcf5ef2aSThomas Huth } 506fcf5ef2aSThomas Huth 507f828df74SRichard Henderson static void gen_op_subccc(TCGv dst, TCGv src1, TCGv src2) 508dfebb950SRichard Henderson { 509f828df74SRichard Henderson gen_op_subcc_int(dst, src1, src2, gen_carry32()); 510dfebb950SRichard Henderson } 511dfebb950SRichard Henderson 5120c2e96c1SRichard Henderson static void gen_op_mulscc(TCGv dst, TCGv src1, TCGv src2) 513fcf5ef2aSThomas Huth { 514b989ce73SRichard Henderson TCGv zero = tcg_constant_tl(0); 51550280618SRichard Henderson TCGv one = tcg_constant_tl(1); 516b989ce73SRichard Henderson TCGv t_src1 = tcg_temp_new(); 517b989ce73SRichard Henderson TCGv t_src2 = tcg_temp_new(); 518b989ce73SRichard Henderson TCGv t0 = tcg_temp_new(); 519fcf5ef2aSThomas Huth 520b989ce73SRichard Henderson tcg_gen_ext32u_tl(t_src1, src1); 521b989ce73SRichard Henderson tcg_gen_ext32u_tl(t_src2, src2); 522fcf5ef2aSThomas Huth 523b989ce73SRichard Henderson /* 524b989ce73SRichard Henderson * if (!(env->y & 1)) 525b989ce73SRichard Henderson * src2 = 0; 526fcf5ef2aSThomas Huth */ 52750280618SRichard Henderson tcg_gen_movcond_tl(TCG_COND_TSTEQ, t_src2, cpu_y, one, zero, t_src2); 528fcf5ef2aSThomas Huth 529b989ce73SRichard Henderson /* 530b989ce73SRichard Henderson * b2 = src1 & 1; 531b989ce73SRichard Henderson * y = (b2 << 31) | (y >> 1); 532b989ce73SRichard Henderson */ 5330b1183e3SPhilippe Mathieu-Daudé tcg_gen_extract_tl(t0, cpu_y, 1, 31); 534b989ce73SRichard Henderson tcg_gen_deposit_tl(cpu_y, t0, src1, 31, 1); 535fcf5ef2aSThomas Huth 536fcf5ef2aSThomas Huth // b1 = N ^ V; 5372a1905c7SRichard Henderson tcg_gen_xor_tl(t0, cpu_cc_N, cpu_cc_V); 538fcf5ef2aSThomas Huth 539b989ce73SRichard Henderson /* 540b989ce73SRichard Henderson * src1 = (b1 << 31) | (src1 >> 1) 541b989ce73SRichard Henderson */ 5422a1905c7SRichard Henderson tcg_gen_andi_tl(t0, t0, 1u << 31); 543b989ce73SRichard Henderson tcg_gen_shri_tl(t_src1, t_src1, 1); 544b989ce73SRichard Henderson tcg_gen_or_tl(t_src1, t_src1, t0); 545fcf5ef2aSThomas Huth 546b989ce73SRichard Henderson gen_op_addcc(dst, t_src1, t_src2); 547fcf5ef2aSThomas Huth } 548fcf5ef2aSThomas Huth 5490c2e96c1SRichard Henderson static void gen_op_multiply(TCGv dst, TCGv src1, TCGv src2, int sign_ext) 550fcf5ef2aSThomas Huth { 551fcf5ef2aSThomas Huth #if TARGET_LONG_BITS == 32 552fcf5ef2aSThomas Huth if (sign_ext) { 553fcf5ef2aSThomas Huth tcg_gen_muls2_tl(dst, cpu_y, src1, src2); 554fcf5ef2aSThomas Huth } else { 555fcf5ef2aSThomas Huth tcg_gen_mulu2_tl(dst, cpu_y, src1, src2); 556fcf5ef2aSThomas Huth } 557fcf5ef2aSThomas Huth #else 558fcf5ef2aSThomas Huth TCGv t0 = tcg_temp_new_i64(); 559fcf5ef2aSThomas Huth TCGv t1 = tcg_temp_new_i64(); 560fcf5ef2aSThomas Huth 561fcf5ef2aSThomas Huth if (sign_ext) { 562fcf5ef2aSThomas Huth tcg_gen_ext32s_i64(t0, src1); 563fcf5ef2aSThomas Huth tcg_gen_ext32s_i64(t1, src2); 564fcf5ef2aSThomas Huth } else { 565fcf5ef2aSThomas Huth tcg_gen_ext32u_i64(t0, src1); 566fcf5ef2aSThomas Huth tcg_gen_ext32u_i64(t1, src2); 567fcf5ef2aSThomas Huth } 568fcf5ef2aSThomas Huth 569fcf5ef2aSThomas Huth tcg_gen_mul_i64(dst, t0, t1); 570fcf5ef2aSThomas Huth tcg_gen_shri_i64(cpu_y, dst, 32); 571fcf5ef2aSThomas Huth #endif 572fcf5ef2aSThomas Huth } 573fcf5ef2aSThomas Huth 5740c2e96c1SRichard Henderson static void gen_op_umul(TCGv dst, TCGv src1, TCGv src2) 575fcf5ef2aSThomas Huth { 576fcf5ef2aSThomas Huth /* zero-extend truncated operands before multiplication */ 577fcf5ef2aSThomas Huth gen_op_multiply(dst, src1, src2, 0); 578fcf5ef2aSThomas Huth } 579fcf5ef2aSThomas Huth 5800c2e96c1SRichard Henderson static void gen_op_smul(TCGv dst, TCGv src1, TCGv src2) 581fcf5ef2aSThomas Huth { 582fcf5ef2aSThomas Huth /* sign-extend truncated operands before multiplication */ 583fcf5ef2aSThomas Huth gen_op_multiply(dst, src1, src2, 1); 584fcf5ef2aSThomas Huth } 585fcf5ef2aSThomas Huth 586680af1b4SRichard Henderson static void gen_op_umulxhi(TCGv dst, TCGv src1, TCGv src2) 587680af1b4SRichard Henderson { 588680af1b4SRichard Henderson TCGv discard = tcg_temp_new(); 589680af1b4SRichard Henderson tcg_gen_mulu2_tl(discard, dst, src1, src2); 590680af1b4SRichard Henderson } 591680af1b4SRichard Henderson 59268a414e9SRichard Henderson static void gen_op_fpmaddx(TCGv_i64 dst, TCGv_i64 src1, 59368a414e9SRichard Henderson TCGv_i64 src2, TCGv_i64 src3) 59468a414e9SRichard Henderson { 59568a414e9SRichard Henderson TCGv_i64 t = tcg_temp_new_i64(); 59668a414e9SRichard Henderson 59768a414e9SRichard Henderson tcg_gen_mul_i64(t, src1, src2); 59868a414e9SRichard Henderson tcg_gen_add_i64(dst, src3, t); 59968a414e9SRichard Henderson } 60068a414e9SRichard Henderson 60168a414e9SRichard Henderson static void gen_op_fpmaddxhi(TCGv_i64 dst, TCGv_i64 src1, 60268a414e9SRichard Henderson TCGv_i64 src2, TCGv_i64 src3) 60368a414e9SRichard Henderson { 60468a414e9SRichard Henderson TCGv_i64 l = tcg_temp_new_i64(); 60568a414e9SRichard Henderson TCGv_i64 h = tcg_temp_new_i64(); 60668a414e9SRichard Henderson TCGv_i64 z = tcg_constant_i64(0); 60768a414e9SRichard Henderson 60868a414e9SRichard Henderson tcg_gen_mulu2_i64(l, h, src1, src2); 60968a414e9SRichard Henderson tcg_gen_add2_i64(l, dst, l, h, src3, z); 61068a414e9SRichard Henderson } 61168a414e9SRichard Henderson 612c2636853SRichard Henderson static void gen_op_sdiv(TCGv dst, TCGv src1, TCGv src2) 613c2636853SRichard Henderson { 61413260103SRichard Henderson #ifdef TARGET_SPARC64 615c2636853SRichard Henderson gen_helper_sdiv(dst, tcg_env, src1, src2); 61613260103SRichard Henderson tcg_gen_ext32s_tl(dst, dst); 61713260103SRichard Henderson #else 61813260103SRichard Henderson TCGv_i64 t64 = tcg_temp_new_i64(); 61913260103SRichard Henderson gen_helper_sdiv(t64, tcg_env, src1, src2); 62013260103SRichard Henderson tcg_gen_trunc_i64_tl(dst, t64); 62113260103SRichard Henderson #endif 622c2636853SRichard Henderson } 623c2636853SRichard Henderson 624c2636853SRichard Henderson static void gen_op_udivcc(TCGv dst, TCGv src1, TCGv src2) 625c2636853SRichard Henderson { 62613260103SRichard Henderson TCGv_i64 t64; 62713260103SRichard Henderson 62813260103SRichard Henderson #ifdef TARGET_SPARC64 62913260103SRichard Henderson t64 = cpu_cc_V; 63013260103SRichard Henderson #else 63113260103SRichard Henderson t64 = tcg_temp_new_i64(); 63213260103SRichard Henderson #endif 63313260103SRichard Henderson 63413260103SRichard Henderson gen_helper_udiv(t64, tcg_env, src1, src2); 63513260103SRichard Henderson 63613260103SRichard Henderson #ifdef TARGET_SPARC64 63713260103SRichard Henderson tcg_gen_ext32u_tl(cpu_cc_N, t64); 63813260103SRichard Henderson tcg_gen_shri_tl(cpu_cc_V, t64, 32); 63913260103SRichard Henderson tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N); 64013260103SRichard Henderson tcg_gen_movi_tl(cpu_icc_C, 0); 64113260103SRichard Henderson #else 64213260103SRichard Henderson tcg_gen_extr_i64_tl(cpu_cc_N, cpu_cc_V, t64); 64313260103SRichard Henderson #endif 64413260103SRichard Henderson tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N); 64513260103SRichard Henderson tcg_gen_movi_tl(cpu_cc_C, 0); 64613260103SRichard Henderson tcg_gen_mov_tl(dst, cpu_cc_N); 647c2636853SRichard Henderson } 648c2636853SRichard Henderson 649c2636853SRichard Henderson static void gen_op_sdivcc(TCGv dst, TCGv src1, TCGv src2) 650c2636853SRichard Henderson { 65113260103SRichard Henderson TCGv_i64 t64; 65213260103SRichard Henderson 65313260103SRichard Henderson #ifdef TARGET_SPARC64 65413260103SRichard Henderson t64 = cpu_cc_V; 65513260103SRichard Henderson #else 65613260103SRichard Henderson t64 = tcg_temp_new_i64(); 65713260103SRichard Henderson #endif 65813260103SRichard Henderson 65913260103SRichard Henderson gen_helper_sdiv(t64, tcg_env, src1, src2); 66013260103SRichard Henderson 66113260103SRichard Henderson #ifdef TARGET_SPARC64 66213260103SRichard Henderson tcg_gen_ext32s_tl(cpu_cc_N, t64); 66313260103SRichard Henderson tcg_gen_shri_tl(cpu_cc_V, t64, 32); 66413260103SRichard Henderson tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N); 66513260103SRichard Henderson tcg_gen_movi_tl(cpu_icc_C, 0); 66613260103SRichard Henderson #else 66713260103SRichard Henderson tcg_gen_extr_i64_tl(cpu_cc_N, cpu_cc_V, t64); 66813260103SRichard Henderson #endif 66913260103SRichard Henderson tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N); 67013260103SRichard Henderson tcg_gen_movi_tl(cpu_cc_C, 0); 67113260103SRichard Henderson tcg_gen_mov_tl(dst, cpu_cc_N); 672c2636853SRichard Henderson } 673c2636853SRichard Henderson 674a9aba13dSRichard Henderson static void gen_op_taddcctv(TCGv dst, TCGv src1, TCGv src2) 675a9aba13dSRichard Henderson { 676a9aba13dSRichard Henderson gen_helper_taddcctv(dst, tcg_env, src1, src2); 677a9aba13dSRichard Henderson } 678a9aba13dSRichard Henderson 679a9aba13dSRichard Henderson static void gen_op_tsubcctv(TCGv dst, TCGv src1, TCGv src2) 680a9aba13dSRichard Henderson { 681a9aba13dSRichard Henderson gen_helper_tsubcctv(dst, tcg_env, src1, src2); 682a9aba13dSRichard Henderson } 683a9aba13dSRichard Henderson 6849c6ec5bcSRichard Henderson static void gen_op_popc(TCGv dst, TCGv src1, TCGv src2) 6859c6ec5bcSRichard Henderson { 6869c6ec5bcSRichard Henderson tcg_gen_ctpop_tl(dst, src2); 6879c6ec5bcSRichard Henderson } 6889c6ec5bcSRichard Henderson 689875ce392SRichard Henderson static void gen_op_lzcnt(TCGv dst, TCGv src) 690875ce392SRichard Henderson { 691875ce392SRichard Henderson tcg_gen_clzi_tl(dst, src, TARGET_LONG_BITS); 692875ce392SRichard Henderson } 693875ce392SRichard Henderson 69445bfed3bSRichard Henderson #ifndef TARGET_SPARC64 69545bfed3bSRichard Henderson static void gen_helper_array8(TCGv dst, TCGv src1, TCGv src2) 69645bfed3bSRichard Henderson { 69745bfed3bSRichard Henderson g_assert_not_reached(); 69845bfed3bSRichard Henderson } 69945bfed3bSRichard Henderson #endif 70045bfed3bSRichard Henderson 70145bfed3bSRichard Henderson static void gen_op_array16(TCGv dst, TCGv src1, TCGv src2) 70245bfed3bSRichard Henderson { 70345bfed3bSRichard Henderson gen_helper_array8(dst, src1, src2); 70445bfed3bSRichard Henderson tcg_gen_shli_tl(dst, dst, 1); 70545bfed3bSRichard Henderson } 70645bfed3bSRichard Henderson 70745bfed3bSRichard Henderson static void gen_op_array32(TCGv dst, TCGv src1, TCGv src2) 70845bfed3bSRichard Henderson { 70945bfed3bSRichard Henderson gen_helper_array8(dst, src1, src2); 71045bfed3bSRichard Henderson tcg_gen_shli_tl(dst, dst, 2); 71145bfed3bSRichard Henderson } 71245bfed3bSRichard Henderson 7132f722641SRichard Henderson static void gen_op_fpack16(TCGv_i32 dst, TCGv_i64 src) 7142f722641SRichard Henderson { 7152f722641SRichard Henderson #ifdef TARGET_SPARC64 7162f722641SRichard Henderson gen_helper_fpack16(dst, cpu_gsr, src); 7172f722641SRichard Henderson #else 7182f722641SRichard Henderson g_assert_not_reached(); 7192f722641SRichard Henderson #endif 7202f722641SRichard Henderson } 7212f722641SRichard Henderson 7222f722641SRichard Henderson static void gen_op_fpackfix(TCGv_i32 dst, TCGv_i64 src) 7232f722641SRichard Henderson { 7242f722641SRichard Henderson #ifdef TARGET_SPARC64 7252f722641SRichard Henderson gen_helper_fpackfix(dst, cpu_gsr, src); 7262f722641SRichard Henderson #else 7272f722641SRichard Henderson g_assert_not_reached(); 7282f722641SRichard Henderson #endif 7292f722641SRichard Henderson } 7302f722641SRichard Henderson 7314b6edc0aSRichard Henderson static void gen_op_fpack32(TCGv_i64 dst, TCGv_i64 src1, TCGv_i64 src2) 7324b6edc0aSRichard Henderson { 7334b6edc0aSRichard Henderson #ifdef TARGET_SPARC64 7344b6edc0aSRichard Henderson gen_helper_fpack32(dst, cpu_gsr, src1, src2); 7354b6edc0aSRichard Henderson #else 7364b6edc0aSRichard Henderson g_assert_not_reached(); 7374b6edc0aSRichard Henderson #endif 7384b6edc0aSRichard Henderson } 7394b6edc0aSRichard Henderson 7400d1d3aafSRichard Henderson static void gen_op_fpadds16s(TCGv_i32 d, TCGv_i32 src1, TCGv_i32 src2) 7410d1d3aafSRichard Henderson { 7420d1d3aafSRichard Henderson TCGv_i32 t[2]; 7430d1d3aafSRichard Henderson 7440d1d3aafSRichard Henderson for (int i = 0; i < 2; i++) { 7450d1d3aafSRichard Henderson TCGv_i32 u = tcg_temp_new_i32(); 7460d1d3aafSRichard Henderson TCGv_i32 v = tcg_temp_new_i32(); 7470d1d3aafSRichard Henderson 7480d1d3aafSRichard Henderson tcg_gen_sextract_i32(u, src1, i * 16, 16); 7490d1d3aafSRichard Henderson tcg_gen_sextract_i32(v, src2, i * 16, 16); 7500d1d3aafSRichard Henderson tcg_gen_add_i32(u, u, v); 7510d1d3aafSRichard Henderson tcg_gen_smax_i32(u, u, tcg_constant_i32(INT16_MIN)); 7520d1d3aafSRichard Henderson tcg_gen_smin_i32(u, u, tcg_constant_i32(INT16_MAX)); 7530d1d3aafSRichard Henderson t[i] = u; 7540d1d3aafSRichard Henderson } 7550d1d3aafSRichard Henderson tcg_gen_deposit_i32(d, t[0], t[1], 16, 16); 7560d1d3aafSRichard Henderson } 7570d1d3aafSRichard Henderson 7580d1d3aafSRichard Henderson static void gen_op_fpsubs16s(TCGv_i32 d, TCGv_i32 src1, TCGv_i32 src2) 7590d1d3aafSRichard Henderson { 7600d1d3aafSRichard Henderson TCGv_i32 t[2]; 7610d1d3aafSRichard Henderson 7620d1d3aafSRichard Henderson for (int i = 0; i < 2; i++) { 7630d1d3aafSRichard Henderson TCGv_i32 u = tcg_temp_new_i32(); 7640d1d3aafSRichard Henderson TCGv_i32 v = tcg_temp_new_i32(); 7650d1d3aafSRichard Henderson 7660d1d3aafSRichard Henderson tcg_gen_sextract_i32(u, src1, i * 16, 16); 7670d1d3aafSRichard Henderson tcg_gen_sextract_i32(v, src2, i * 16, 16); 7680d1d3aafSRichard Henderson tcg_gen_sub_i32(u, u, v); 7690d1d3aafSRichard Henderson tcg_gen_smax_i32(u, u, tcg_constant_i32(INT16_MIN)); 7700d1d3aafSRichard Henderson tcg_gen_smin_i32(u, u, tcg_constant_i32(INT16_MAX)); 7710d1d3aafSRichard Henderson t[i] = u; 7720d1d3aafSRichard Henderson } 7730d1d3aafSRichard Henderson tcg_gen_deposit_i32(d, t[0], t[1], 16, 16); 7740d1d3aafSRichard Henderson } 7750d1d3aafSRichard Henderson 7760d1d3aafSRichard Henderson static void gen_op_fpadds32s(TCGv_i32 d, TCGv_i32 src1, TCGv_i32 src2) 7770d1d3aafSRichard Henderson { 7780d1d3aafSRichard Henderson TCGv_i32 r = tcg_temp_new_i32(); 7790d1d3aafSRichard Henderson TCGv_i32 t = tcg_temp_new_i32(); 7800d1d3aafSRichard Henderson TCGv_i32 v = tcg_temp_new_i32(); 7810d1d3aafSRichard Henderson TCGv_i32 z = tcg_constant_i32(0); 7820d1d3aafSRichard Henderson 7830d1d3aafSRichard Henderson tcg_gen_add_i32(r, src1, src2); 7840d1d3aafSRichard Henderson tcg_gen_xor_i32(t, src1, src2); 7850d1d3aafSRichard Henderson tcg_gen_xor_i32(v, r, src2); 7860d1d3aafSRichard Henderson tcg_gen_andc_i32(v, v, t); 7870d1d3aafSRichard Henderson 7880d1d3aafSRichard Henderson tcg_gen_setcond_i32(TCG_COND_GE, t, r, z); 7890d1d3aafSRichard Henderson tcg_gen_addi_i32(t, t, INT32_MAX); 7900d1d3aafSRichard Henderson 7910d1d3aafSRichard Henderson tcg_gen_movcond_i32(TCG_COND_LT, d, v, z, t, r); 7920d1d3aafSRichard Henderson } 7930d1d3aafSRichard Henderson 7940d1d3aafSRichard Henderson static void gen_op_fpsubs32s(TCGv_i32 d, TCGv_i32 src1, TCGv_i32 src2) 7950d1d3aafSRichard Henderson { 7960d1d3aafSRichard Henderson TCGv_i32 r = tcg_temp_new_i32(); 7970d1d3aafSRichard Henderson TCGv_i32 t = tcg_temp_new_i32(); 7980d1d3aafSRichard Henderson TCGv_i32 v = tcg_temp_new_i32(); 7990d1d3aafSRichard Henderson TCGv_i32 z = tcg_constant_i32(0); 8000d1d3aafSRichard Henderson 8010d1d3aafSRichard Henderson tcg_gen_sub_i32(r, src1, src2); 8020d1d3aafSRichard Henderson tcg_gen_xor_i32(t, src1, src2); 8030d1d3aafSRichard Henderson tcg_gen_xor_i32(v, r, src1); 8040d1d3aafSRichard Henderson tcg_gen_and_i32(v, v, t); 8050d1d3aafSRichard Henderson 8060d1d3aafSRichard Henderson tcg_gen_setcond_i32(TCG_COND_GE, t, r, z); 8070d1d3aafSRichard Henderson tcg_gen_addi_i32(t, t, INT32_MAX); 8080d1d3aafSRichard Henderson 8090d1d3aafSRichard Henderson tcg_gen_movcond_i32(TCG_COND_LT, d, v, z, t, r); 8100d1d3aafSRichard Henderson } 8110d1d3aafSRichard Henderson 8124b6edc0aSRichard Henderson static void gen_op_faligndata(TCGv_i64 dst, TCGv_i64 s1, TCGv_i64 s2) 8134b6edc0aSRichard Henderson { 8144b6edc0aSRichard Henderson #ifdef TARGET_SPARC64 8154b6edc0aSRichard Henderson TCGv t1, t2, shift; 8164b6edc0aSRichard Henderson 8174b6edc0aSRichard Henderson t1 = tcg_temp_new(); 8184b6edc0aSRichard Henderson t2 = tcg_temp_new(); 8194b6edc0aSRichard Henderson shift = tcg_temp_new(); 8204b6edc0aSRichard Henderson 8214b6edc0aSRichard Henderson tcg_gen_andi_tl(shift, cpu_gsr, 7); 8224b6edc0aSRichard Henderson tcg_gen_shli_tl(shift, shift, 3); 8234b6edc0aSRichard Henderson tcg_gen_shl_tl(t1, s1, shift); 8244b6edc0aSRichard Henderson 8254b6edc0aSRichard Henderson /* 8264b6edc0aSRichard Henderson * A shift of 64 does not produce 0 in TCG. Divide this into a 8274b6edc0aSRichard Henderson * shift of (up to 63) followed by a constant shift of 1. 8284b6edc0aSRichard Henderson */ 8294b6edc0aSRichard Henderson tcg_gen_xori_tl(shift, shift, 63); 8304b6edc0aSRichard Henderson tcg_gen_shr_tl(t2, s2, shift); 8314b6edc0aSRichard Henderson tcg_gen_shri_tl(t2, t2, 1); 8324b6edc0aSRichard Henderson 8334b6edc0aSRichard Henderson tcg_gen_or_tl(dst, t1, t2); 8344b6edc0aSRichard Henderson #else 8354b6edc0aSRichard Henderson g_assert_not_reached(); 8364b6edc0aSRichard Henderson #endif 8374b6edc0aSRichard Henderson } 8384b6edc0aSRichard Henderson 8394b6edc0aSRichard Henderson static void gen_op_bshuffle(TCGv_i64 dst, TCGv_i64 src1, TCGv_i64 src2) 8404b6edc0aSRichard Henderson { 8414b6edc0aSRichard Henderson #ifdef TARGET_SPARC64 8424b6edc0aSRichard Henderson gen_helper_bshuffle(dst, cpu_gsr, src1, src2); 8434b6edc0aSRichard Henderson #else 8444b6edc0aSRichard Henderson g_assert_not_reached(); 8454b6edc0aSRichard Henderson #endif 8464b6edc0aSRichard Henderson } 8474b6edc0aSRichard Henderson 8487d5ebd8fSRichard Henderson static void gen_op_pdistn(TCGv dst, TCGv_i64 src1, TCGv_i64 src2) 8497d5ebd8fSRichard Henderson { 8507d5ebd8fSRichard Henderson #ifdef TARGET_SPARC64 8517d5ebd8fSRichard Henderson gen_helper_pdist(dst, tcg_constant_i64(0), src1, src2); 8527d5ebd8fSRichard Henderson #else 8537d5ebd8fSRichard Henderson g_assert_not_reached(); 8547d5ebd8fSRichard Henderson #endif 8557d5ebd8fSRichard Henderson } 8567d5ebd8fSRichard Henderson 857a859602cSRichard Henderson static void gen_op_fmul8x16al(TCGv_i64 dst, TCGv_i32 src1, TCGv_i32 src2) 858a859602cSRichard Henderson { 859a859602cSRichard Henderson tcg_gen_ext16s_i32(src2, src2); 860a859602cSRichard Henderson gen_helper_fmul8x16a(dst, src1, src2); 861a859602cSRichard Henderson } 862a859602cSRichard Henderson 863a859602cSRichard Henderson static void gen_op_fmul8x16au(TCGv_i64 dst, TCGv_i32 src1, TCGv_i32 src2) 864a859602cSRichard Henderson { 865a859602cSRichard Henderson tcg_gen_sari_i32(src2, src2, 16); 866a859602cSRichard Henderson gen_helper_fmul8x16a(dst, src1, src2); 867a859602cSRichard Henderson } 868a859602cSRichard Henderson 869be8998e0SRichard Henderson static void gen_op_fmuld8ulx16(TCGv_i64 dst, TCGv_i32 src1, TCGv_i32 src2) 870be8998e0SRichard Henderson { 871be8998e0SRichard Henderson TCGv_i32 t0 = tcg_temp_new_i32(); 872be8998e0SRichard Henderson TCGv_i32 t1 = tcg_temp_new_i32(); 873be8998e0SRichard Henderson TCGv_i32 t2 = tcg_temp_new_i32(); 874be8998e0SRichard Henderson 875be8998e0SRichard Henderson tcg_gen_ext8u_i32(t0, src1); 876be8998e0SRichard Henderson tcg_gen_ext16s_i32(t1, src2); 877be8998e0SRichard Henderson tcg_gen_mul_i32(t0, t0, t1); 878be8998e0SRichard Henderson 879be8998e0SRichard Henderson tcg_gen_extract_i32(t1, src1, 16, 8); 880be8998e0SRichard Henderson tcg_gen_sextract_i32(t2, src2, 16, 16); 881be8998e0SRichard Henderson tcg_gen_mul_i32(t1, t1, t2); 882be8998e0SRichard Henderson 883be8998e0SRichard Henderson tcg_gen_concat_i32_i64(dst, t0, t1); 884be8998e0SRichard Henderson } 885be8998e0SRichard Henderson 886be8998e0SRichard Henderson static void gen_op_fmuld8sux16(TCGv_i64 dst, TCGv_i32 src1, TCGv_i32 src2) 887be8998e0SRichard Henderson { 888be8998e0SRichard Henderson TCGv_i32 t0 = tcg_temp_new_i32(); 889be8998e0SRichard Henderson TCGv_i32 t1 = tcg_temp_new_i32(); 890be8998e0SRichard Henderson TCGv_i32 t2 = tcg_temp_new_i32(); 891be8998e0SRichard Henderson 892be8998e0SRichard Henderson /* 893be8998e0SRichard Henderson * The insn description talks about extracting the upper 8 bits 894be8998e0SRichard Henderson * of the signed 16-bit input rs1, performing the multiply, then 895be8998e0SRichard Henderson * shifting left by 8 bits. Instead, zap the lower 8 bits of 896be8998e0SRichard Henderson * the rs1 input, which avoids the need for two shifts. 897be8998e0SRichard Henderson */ 898be8998e0SRichard Henderson tcg_gen_ext16s_i32(t0, src1); 899be8998e0SRichard Henderson tcg_gen_andi_i32(t0, t0, ~0xff); 900be8998e0SRichard Henderson tcg_gen_ext16s_i32(t1, src2); 901be8998e0SRichard Henderson tcg_gen_mul_i32(t0, t0, t1); 902be8998e0SRichard Henderson 903be8998e0SRichard Henderson tcg_gen_sextract_i32(t1, src1, 16, 16); 904be8998e0SRichard Henderson tcg_gen_andi_i32(t1, t1, ~0xff); 905be8998e0SRichard Henderson tcg_gen_sextract_i32(t2, src2, 16, 16); 906be8998e0SRichard Henderson tcg_gen_mul_i32(t1, t1, t2); 907be8998e0SRichard Henderson 908be8998e0SRichard Henderson tcg_gen_concat_i32_i64(dst, t0, t1); 909be8998e0SRichard Henderson } 910be8998e0SRichard Henderson 9117837185eSRichard Henderson #ifdef TARGET_SPARC64 9127837185eSRichard Henderson static void gen_vec_fchksm16(unsigned vece, TCGv_vec dst, 9137837185eSRichard Henderson TCGv_vec src1, TCGv_vec src2) 9147837185eSRichard Henderson { 9157837185eSRichard Henderson TCGv_vec a = tcg_temp_new_vec_matching(dst); 9167837185eSRichard Henderson TCGv_vec c = tcg_temp_new_vec_matching(dst); 9177837185eSRichard Henderson 9187837185eSRichard Henderson tcg_gen_add_vec(vece, a, src1, src2); 9197837185eSRichard Henderson tcg_gen_cmp_vec(TCG_COND_LTU, vece, c, a, src1); 9207837185eSRichard Henderson /* Vector cmp produces -1 for true, so subtract to add carry. */ 9217837185eSRichard Henderson tcg_gen_sub_vec(vece, dst, a, c); 9227837185eSRichard Henderson } 9237837185eSRichard Henderson 9247837185eSRichard Henderson static void gen_op_fchksm16(unsigned vece, uint32_t dofs, uint32_t aofs, 9257837185eSRichard Henderson uint32_t bofs, uint32_t oprsz, uint32_t maxsz) 9267837185eSRichard Henderson { 9277837185eSRichard Henderson static const TCGOpcode vecop_list[] = { 9287837185eSRichard Henderson INDEX_op_cmp_vec, INDEX_op_add_vec, INDEX_op_sub_vec, 9297837185eSRichard Henderson }; 9307837185eSRichard Henderson static const GVecGen3 op = { 9317837185eSRichard Henderson .fni8 = gen_helper_fchksm16, 9327837185eSRichard Henderson .fniv = gen_vec_fchksm16, 9337837185eSRichard Henderson .opt_opc = vecop_list, 9347837185eSRichard Henderson .vece = MO_16, 9357837185eSRichard Henderson }; 9367837185eSRichard Henderson tcg_gen_gvec_3(dofs, aofs, bofs, oprsz, maxsz, &op); 9377837185eSRichard Henderson } 938d6ff1ccbSRichard Henderson 939d6ff1ccbSRichard Henderson static void gen_vec_fmean16(unsigned vece, TCGv_vec dst, 940d6ff1ccbSRichard Henderson TCGv_vec src1, TCGv_vec src2) 941d6ff1ccbSRichard Henderson { 942d6ff1ccbSRichard Henderson TCGv_vec t = tcg_temp_new_vec_matching(dst); 943d6ff1ccbSRichard Henderson 944d6ff1ccbSRichard Henderson tcg_gen_or_vec(vece, t, src1, src2); 945d6ff1ccbSRichard Henderson tcg_gen_and_vec(vece, t, t, tcg_constant_vec_matching(dst, vece, 1)); 946d6ff1ccbSRichard Henderson tcg_gen_sari_vec(vece, src1, src1, 1); 947d6ff1ccbSRichard Henderson tcg_gen_sari_vec(vece, src2, src2, 1); 948d6ff1ccbSRichard Henderson tcg_gen_add_vec(vece, dst, src1, src2); 949d6ff1ccbSRichard Henderson tcg_gen_add_vec(vece, dst, dst, t); 950d6ff1ccbSRichard Henderson } 951d6ff1ccbSRichard Henderson 952d6ff1ccbSRichard Henderson static void gen_op_fmean16(unsigned vece, uint32_t dofs, uint32_t aofs, 953d6ff1ccbSRichard Henderson uint32_t bofs, uint32_t oprsz, uint32_t maxsz) 954d6ff1ccbSRichard Henderson { 955d6ff1ccbSRichard Henderson static const TCGOpcode vecop_list[] = { 956d6ff1ccbSRichard Henderson INDEX_op_add_vec, INDEX_op_sari_vec, 957d6ff1ccbSRichard Henderson }; 958d6ff1ccbSRichard Henderson static const GVecGen3 op = { 959d6ff1ccbSRichard Henderson .fni8 = gen_helper_fmean16, 960d6ff1ccbSRichard Henderson .fniv = gen_vec_fmean16, 961d6ff1ccbSRichard Henderson .opt_opc = vecop_list, 962d6ff1ccbSRichard Henderson .vece = MO_16, 963d6ff1ccbSRichard Henderson }; 964d6ff1ccbSRichard Henderson tcg_gen_gvec_3(dofs, aofs, bofs, oprsz, maxsz, &op); 965d6ff1ccbSRichard Henderson } 9667837185eSRichard Henderson #else 9677837185eSRichard Henderson #define gen_op_fchksm16 ({ qemu_build_not_reached(); NULL; }) 968d6ff1ccbSRichard Henderson #define gen_op_fmean16 ({ qemu_build_not_reached(); NULL; }) 9697837185eSRichard Henderson #endif 9707837185eSRichard Henderson 97189527e3aSRichard Henderson static void finishing_insn(DisasContext *dc) 97289527e3aSRichard Henderson { 97389527e3aSRichard Henderson /* 97489527e3aSRichard Henderson * From here, there is no future path through an unwinding exception. 97589527e3aSRichard Henderson * If the current insn cannot raise an exception, the computation of 97689527e3aSRichard Henderson * cpu_cond may be able to be elided. 97789527e3aSRichard Henderson */ 97889527e3aSRichard Henderson if (dc->cpu_cond_live) { 97989527e3aSRichard Henderson tcg_gen_discard_tl(cpu_cond); 98089527e3aSRichard Henderson dc->cpu_cond_live = false; 98189527e3aSRichard Henderson } 98289527e3aSRichard Henderson } 98389527e3aSRichard Henderson 9840c2e96c1SRichard Henderson static void gen_generic_branch(DisasContext *dc) 985fcf5ef2aSThomas Huth { 98600ab7e61SRichard Henderson TCGv npc0 = tcg_constant_tl(dc->jump_pc[0]); 98700ab7e61SRichard Henderson TCGv npc1 = tcg_constant_tl(dc->jump_pc[1]); 988533f042fSRichard Henderson TCGv c2 = tcg_constant_tl(dc->jump.c2); 989fcf5ef2aSThomas Huth 990533f042fSRichard Henderson tcg_gen_movcond_tl(dc->jump.cond, cpu_npc, dc->jump.c1, c2, npc0, npc1); 991fcf5ef2aSThomas Huth } 992fcf5ef2aSThomas Huth 993fcf5ef2aSThomas Huth /* call this function before using the condition register as it may 994fcf5ef2aSThomas Huth have been set for a jump */ 9950c2e96c1SRichard Henderson static void flush_cond(DisasContext *dc) 996fcf5ef2aSThomas Huth { 997fcf5ef2aSThomas Huth if (dc->npc == JUMP_PC) { 998fcf5ef2aSThomas Huth gen_generic_branch(dc); 99999c82c47SRichard Henderson dc->npc = DYNAMIC_PC_LOOKUP; 1000fcf5ef2aSThomas Huth } 1001fcf5ef2aSThomas Huth } 1002fcf5ef2aSThomas Huth 10030c2e96c1SRichard Henderson static void save_npc(DisasContext *dc) 1004fcf5ef2aSThomas Huth { 1005633c4283SRichard Henderson if (dc->npc & 3) { 1006633c4283SRichard Henderson switch (dc->npc) { 1007633c4283SRichard Henderson case JUMP_PC: 1008fcf5ef2aSThomas Huth gen_generic_branch(dc); 100999c82c47SRichard Henderson dc->npc = DYNAMIC_PC_LOOKUP; 1010633c4283SRichard Henderson break; 1011633c4283SRichard Henderson case DYNAMIC_PC: 1012633c4283SRichard Henderson case DYNAMIC_PC_LOOKUP: 1013633c4283SRichard Henderson break; 1014633c4283SRichard Henderson default: 1015633c4283SRichard Henderson g_assert_not_reached(); 1016633c4283SRichard Henderson } 1017633c4283SRichard Henderson } else { 1018fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_npc, dc->npc); 1019fcf5ef2aSThomas Huth } 1020fcf5ef2aSThomas Huth } 1021fcf5ef2aSThomas Huth 10220c2e96c1SRichard Henderson static void save_state(DisasContext *dc) 1023fcf5ef2aSThomas Huth { 1024fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_pc, dc->pc); 1025fcf5ef2aSThomas Huth save_npc(dc); 1026fcf5ef2aSThomas Huth } 1027fcf5ef2aSThomas Huth 1028fcf5ef2aSThomas Huth static void gen_exception(DisasContext *dc, int which) 1029fcf5ef2aSThomas Huth { 103089527e3aSRichard Henderson finishing_insn(dc); 1031fcf5ef2aSThomas Huth save_state(dc); 1032ad75a51eSRichard Henderson gen_helper_raise_exception(tcg_env, tcg_constant_i32(which)); 1033af00be49SEmilio G. Cota dc->base.is_jmp = DISAS_NORETURN; 1034fcf5ef2aSThomas Huth } 1035fcf5ef2aSThomas Huth 1036186e7890SRichard Henderson static TCGLabel *delay_exceptionv(DisasContext *dc, TCGv_i32 excp) 1037fcf5ef2aSThomas Huth { 1038186e7890SRichard Henderson DisasDelayException *e = g_new0(DisasDelayException, 1); 1039186e7890SRichard Henderson 1040186e7890SRichard Henderson e->next = dc->delay_excp_list; 1041186e7890SRichard Henderson dc->delay_excp_list = e; 1042186e7890SRichard Henderson 1043186e7890SRichard Henderson e->lab = gen_new_label(); 1044186e7890SRichard Henderson e->excp = excp; 1045186e7890SRichard Henderson e->pc = dc->pc; 1046186e7890SRichard Henderson /* Caller must have used flush_cond before branch. */ 1047186e7890SRichard Henderson assert(e->npc != JUMP_PC); 1048186e7890SRichard Henderson e->npc = dc->npc; 1049186e7890SRichard Henderson 1050186e7890SRichard Henderson return e->lab; 1051186e7890SRichard Henderson } 1052186e7890SRichard Henderson 1053186e7890SRichard Henderson static TCGLabel *delay_exception(DisasContext *dc, int excp) 1054186e7890SRichard Henderson { 1055186e7890SRichard Henderson return delay_exceptionv(dc, tcg_constant_i32(excp)); 1056186e7890SRichard Henderson } 1057186e7890SRichard Henderson 1058186e7890SRichard Henderson static void gen_check_align(DisasContext *dc, TCGv addr, int mask) 1059186e7890SRichard Henderson { 1060186e7890SRichard Henderson TCGv t = tcg_temp_new(); 1061186e7890SRichard Henderson TCGLabel *lab; 1062186e7890SRichard Henderson 1063186e7890SRichard Henderson tcg_gen_andi_tl(t, addr, mask); 1064186e7890SRichard Henderson 1065186e7890SRichard Henderson flush_cond(dc); 1066186e7890SRichard Henderson lab = delay_exception(dc, TT_UNALIGNED); 1067186e7890SRichard Henderson tcg_gen_brcondi_tl(TCG_COND_NE, t, 0, lab); 1068fcf5ef2aSThomas Huth } 1069fcf5ef2aSThomas Huth 10700c2e96c1SRichard Henderson static void gen_mov_pc_npc(DisasContext *dc) 1071fcf5ef2aSThomas Huth { 107289527e3aSRichard Henderson finishing_insn(dc); 107389527e3aSRichard Henderson 1074633c4283SRichard Henderson if (dc->npc & 3) { 1075633c4283SRichard Henderson switch (dc->npc) { 1076633c4283SRichard Henderson case JUMP_PC: 1077fcf5ef2aSThomas Huth gen_generic_branch(dc); 1078fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_pc, cpu_npc); 107999c82c47SRichard Henderson dc->pc = DYNAMIC_PC_LOOKUP; 1080633c4283SRichard Henderson break; 1081633c4283SRichard Henderson case DYNAMIC_PC: 1082633c4283SRichard Henderson case DYNAMIC_PC_LOOKUP: 1083fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_pc, cpu_npc); 1084633c4283SRichard Henderson dc->pc = dc->npc; 1085633c4283SRichard Henderson break; 1086633c4283SRichard Henderson default: 1087633c4283SRichard Henderson g_assert_not_reached(); 1088633c4283SRichard Henderson } 1089fcf5ef2aSThomas Huth } else { 1090fcf5ef2aSThomas Huth dc->pc = dc->npc; 1091fcf5ef2aSThomas Huth } 1092fcf5ef2aSThomas Huth } 1093fcf5ef2aSThomas Huth 1094fcf5ef2aSThomas Huth static void gen_compare(DisasCompare *cmp, bool xcc, unsigned int cond, 1095fcf5ef2aSThomas Huth DisasContext *dc) 1096fcf5ef2aSThomas Huth { 1097b597eedcSRichard Henderson TCGv t1; 1098fcf5ef2aSThomas Huth 10992a1905c7SRichard Henderson cmp->c1 = t1 = tcg_temp_new(); 1100c8507ebfSRichard Henderson cmp->c2 = 0; 11012a1905c7SRichard Henderson 11022a1905c7SRichard Henderson switch (cond & 7) { 11032a1905c7SRichard Henderson case 0x0: /* never */ 11042a1905c7SRichard Henderson cmp->cond = TCG_COND_NEVER; 1105c8507ebfSRichard Henderson cmp->c1 = tcg_constant_tl(0); 1106fcf5ef2aSThomas Huth break; 11072a1905c7SRichard Henderson 11082a1905c7SRichard Henderson case 0x1: /* eq: Z */ 11092a1905c7SRichard Henderson cmp->cond = TCG_COND_EQ; 11102a1905c7SRichard Henderson if (TARGET_LONG_BITS == 32 || xcc) { 11112a1905c7SRichard Henderson tcg_gen_mov_tl(t1, cpu_cc_Z); 11122a1905c7SRichard Henderson } else { 11132a1905c7SRichard Henderson tcg_gen_ext32u_tl(t1, cpu_icc_Z); 11142a1905c7SRichard Henderson } 11152a1905c7SRichard Henderson break; 11162a1905c7SRichard Henderson 11172a1905c7SRichard Henderson case 0x2: /* le: Z | (N ^ V) */ 11182a1905c7SRichard Henderson /* 11192a1905c7SRichard Henderson * Simplify: 11202a1905c7SRichard Henderson * cc_Z || (N ^ V) < 0 NE 11212a1905c7SRichard Henderson * cc_Z && !((N ^ V) < 0) EQ 11222a1905c7SRichard Henderson * cc_Z & ~((N ^ V) >> TLB) EQ 11232a1905c7SRichard Henderson */ 11242a1905c7SRichard Henderson cmp->cond = TCG_COND_EQ; 11252a1905c7SRichard Henderson tcg_gen_xor_tl(t1, cpu_cc_N, cpu_cc_V); 11262a1905c7SRichard Henderson tcg_gen_sextract_tl(t1, t1, xcc ? 63 : 31, 1); 11272a1905c7SRichard Henderson tcg_gen_andc_tl(t1, xcc ? cpu_cc_Z : cpu_icc_Z, t1); 11282a1905c7SRichard Henderson if (TARGET_LONG_BITS == 64 && !xcc) { 11292a1905c7SRichard Henderson tcg_gen_ext32u_tl(t1, t1); 11302a1905c7SRichard Henderson } 11312a1905c7SRichard Henderson break; 11322a1905c7SRichard Henderson 11332a1905c7SRichard Henderson case 0x3: /* lt: N ^ V */ 11342a1905c7SRichard Henderson cmp->cond = TCG_COND_LT; 11352a1905c7SRichard Henderson tcg_gen_xor_tl(t1, cpu_cc_N, cpu_cc_V); 11362a1905c7SRichard Henderson if (TARGET_LONG_BITS == 64 && !xcc) { 11372a1905c7SRichard Henderson tcg_gen_ext32s_tl(t1, t1); 11382a1905c7SRichard Henderson } 11392a1905c7SRichard Henderson break; 11402a1905c7SRichard Henderson 11412a1905c7SRichard Henderson case 0x4: /* leu: Z | C */ 11422a1905c7SRichard Henderson /* 11432a1905c7SRichard Henderson * Simplify: 11442a1905c7SRichard Henderson * cc_Z == 0 || cc_C != 0 NE 11452a1905c7SRichard Henderson * cc_Z != 0 && cc_C == 0 EQ 11462a1905c7SRichard Henderson * cc_Z & (cc_C ? 0 : -1) EQ 11472a1905c7SRichard Henderson * cc_Z & (cc_C - 1) EQ 11482a1905c7SRichard Henderson */ 11492a1905c7SRichard Henderson cmp->cond = TCG_COND_EQ; 11502a1905c7SRichard Henderson if (TARGET_LONG_BITS == 32 || xcc) { 11512a1905c7SRichard Henderson tcg_gen_subi_tl(t1, cpu_cc_C, 1); 11522a1905c7SRichard Henderson tcg_gen_and_tl(t1, t1, cpu_cc_Z); 11532a1905c7SRichard Henderson } else { 11542a1905c7SRichard Henderson tcg_gen_extract_tl(t1, cpu_icc_C, 32, 1); 11552a1905c7SRichard Henderson tcg_gen_subi_tl(t1, t1, 1); 11562a1905c7SRichard Henderson tcg_gen_and_tl(t1, t1, cpu_icc_Z); 11572a1905c7SRichard Henderson tcg_gen_ext32u_tl(t1, t1); 11582a1905c7SRichard Henderson } 11592a1905c7SRichard Henderson break; 11602a1905c7SRichard Henderson 11612a1905c7SRichard Henderson case 0x5: /* ltu: C */ 11622a1905c7SRichard Henderson cmp->cond = TCG_COND_NE; 11632a1905c7SRichard Henderson if (TARGET_LONG_BITS == 32 || xcc) { 11642a1905c7SRichard Henderson tcg_gen_mov_tl(t1, cpu_cc_C); 11652a1905c7SRichard Henderson } else { 11662a1905c7SRichard Henderson tcg_gen_extract_tl(t1, cpu_icc_C, 32, 1); 11672a1905c7SRichard Henderson } 11682a1905c7SRichard Henderson break; 11692a1905c7SRichard Henderson 11702a1905c7SRichard Henderson case 0x6: /* neg: N */ 11712a1905c7SRichard Henderson cmp->cond = TCG_COND_LT; 11722a1905c7SRichard Henderson if (TARGET_LONG_BITS == 32 || xcc) { 11732a1905c7SRichard Henderson tcg_gen_mov_tl(t1, cpu_cc_N); 11742a1905c7SRichard Henderson } else { 11752a1905c7SRichard Henderson tcg_gen_ext32s_tl(t1, cpu_cc_N); 11762a1905c7SRichard Henderson } 11772a1905c7SRichard Henderson break; 11782a1905c7SRichard Henderson 11792a1905c7SRichard Henderson case 0x7: /* vs: V */ 11802a1905c7SRichard Henderson cmp->cond = TCG_COND_LT; 11812a1905c7SRichard Henderson if (TARGET_LONG_BITS == 32 || xcc) { 11822a1905c7SRichard Henderson tcg_gen_mov_tl(t1, cpu_cc_V); 11832a1905c7SRichard Henderson } else { 11842a1905c7SRichard Henderson tcg_gen_ext32s_tl(t1, cpu_cc_V); 11852a1905c7SRichard Henderson } 11862a1905c7SRichard Henderson break; 11872a1905c7SRichard Henderson } 11882a1905c7SRichard Henderson if (cond & 8) { 11892a1905c7SRichard Henderson cmp->cond = tcg_invert_cond(cmp->cond); 1190fcf5ef2aSThomas Huth } 1191fcf5ef2aSThomas Huth } 1192fcf5ef2aSThomas Huth 1193fcf5ef2aSThomas Huth static void gen_fcompare(DisasCompare *cmp, unsigned int cc, unsigned int cond) 1194fcf5ef2aSThomas Huth { 1195d8c5b92fSRichard Henderson TCGv_i32 fcc = cpu_fcc[cc]; 1196d8c5b92fSRichard Henderson TCGv_i32 c1 = fcc; 1197d8c5b92fSRichard Henderson int c2 = 0; 1198d8c5b92fSRichard Henderson TCGCond tcond; 1199fcf5ef2aSThomas Huth 1200d8c5b92fSRichard Henderson /* 1201d8c5b92fSRichard Henderson * FCC values: 1202d8c5b92fSRichard Henderson * 0 = 1203d8c5b92fSRichard Henderson * 1 < 1204d8c5b92fSRichard Henderson * 2 > 1205d8c5b92fSRichard Henderson * 3 unordered 1206d8c5b92fSRichard Henderson */ 1207d8c5b92fSRichard Henderson switch (cond & 7) { 1208d8c5b92fSRichard Henderson case 0x0: /* fbn */ 1209d8c5b92fSRichard Henderson tcond = TCG_COND_NEVER; 1210fcf5ef2aSThomas Huth break; 1211d8c5b92fSRichard Henderson case 0x1: /* fbne : !0 */ 1212d8c5b92fSRichard Henderson tcond = TCG_COND_NE; 1213fcf5ef2aSThomas Huth break; 1214d8c5b92fSRichard Henderson case 0x2: /* fblg : 1 or 2 */ 1215d8c5b92fSRichard Henderson /* fcc in {1,2} - 1 -> fcc in {0,1} */ 1216d8c5b92fSRichard Henderson c1 = tcg_temp_new_i32(); 1217d8c5b92fSRichard Henderson tcg_gen_addi_i32(c1, fcc, -1); 1218d8c5b92fSRichard Henderson c2 = 1; 1219d8c5b92fSRichard Henderson tcond = TCG_COND_LEU; 1220fcf5ef2aSThomas Huth break; 1221d8c5b92fSRichard Henderson case 0x3: /* fbul : 1 or 3 */ 1222d8c5b92fSRichard Henderson c1 = tcg_temp_new_i32(); 1223d8c5b92fSRichard Henderson tcg_gen_andi_i32(c1, fcc, 1); 1224d8c5b92fSRichard Henderson tcond = TCG_COND_NE; 1225d8c5b92fSRichard Henderson break; 1226d8c5b92fSRichard Henderson case 0x4: /* fbl : 1 */ 1227d8c5b92fSRichard Henderson c2 = 1; 1228d8c5b92fSRichard Henderson tcond = TCG_COND_EQ; 1229d8c5b92fSRichard Henderson break; 1230d8c5b92fSRichard Henderson case 0x5: /* fbug : 2 or 3 */ 1231d8c5b92fSRichard Henderson c2 = 2; 1232d8c5b92fSRichard Henderson tcond = TCG_COND_GEU; 1233d8c5b92fSRichard Henderson break; 1234d8c5b92fSRichard Henderson case 0x6: /* fbg : 2 */ 1235d8c5b92fSRichard Henderson c2 = 2; 1236d8c5b92fSRichard Henderson tcond = TCG_COND_EQ; 1237d8c5b92fSRichard Henderson break; 1238d8c5b92fSRichard Henderson case 0x7: /* fbu : 3 */ 1239d8c5b92fSRichard Henderson c2 = 3; 1240d8c5b92fSRichard Henderson tcond = TCG_COND_EQ; 1241fcf5ef2aSThomas Huth break; 1242fcf5ef2aSThomas Huth } 1243d8c5b92fSRichard Henderson if (cond & 8) { 1244d8c5b92fSRichard Henderson tcond = tcg_invert_cond(tcond); 1245fcf5ef2aSThomas Huth } 1246d8c5b92fSRichard Henderson 1247d8c5b92fSRichard Henderson cmp->cond = tcond; 1248d8c5b92fSRichard Henderson cmp->c2 = c2; 1249d8c5b92fSRichard Henderson cmp->c1 = tcg_temp_new(); 1250d8c5b92fSRichard Henderson tcg_gen_extu_i32_tl(cmp->c1, c1); 1251fcf5ef2aSThomas Huth } 1252fcf5ef2aSThomas Huth 12532c4f56c9SRichard Henderson static bool gen_compare_reg(DisasCompare *cmp, int cond, TCGv r_src) 12542c4f56c9SRichard Henderson { 12552c4f56c9SRichard Henderson static const TCGCond cond_reg[4] = { 1256ab9ffe98SRichard Henderson TCG_COND_NEVER, /* reserved */ 1257fcf5ef2aSThomas Huth TCG_COND_EQ, 1258fcf5ef2aSThomas Huth TCG_COND_LE, 1259fcf5ef2aSThomas Huth TCG_COND_LT, 1260fcf5ef2aSThomas Huth }; 12612c4f56c9SRichard Henderson TCGCond tcond; 1262fcf5ef2aSThomas Huth 12632c4f56c9SRichard Henderson if ((cond & 3) == 0) { 12642c4f56c9SRichard Henderson return false; 12652c4f56c9SRichard Henderson } 12662c4f56c9SRichard Henderson tcond = cond_reg[cond & 3]; 12672c4f56c9SRichard Henderson if (cond & 4) { 12682c4f56c9SRichard Henderson tcond = tcg_invert_cond(tcond); 12692c4f56c9SRichard Henderson } 12702c4f56c9SRichard Henderson 12712c4f56c9SRichard Henderson cmp->cond = tcond; 1272816f89b7SRichard Henderson cmp->c1 = tcg_temp_new(); 1273c8507ebfSRichard Henderson cmp->c2 = 0; 1274816f89b7SRichard Henderson tcg_gen_mov_tl(cmp->c1, r_src); 12752c4f56c9SRichard Henderson return true; 1276fcf5ef2aSThomas Huth } 1277fcf5ef2aSThomas Huth 1278baf3dbf2SRichard Henderson static void gen_op_clear_ieee_excp_and_FTT(void) 1279baf3dbf2SRichard Henderson { 12803590f01eSRichard Henderson tcg_gen_st_i32(tcg_constant_i32(0), tcg_env, 12813590f01eSRichard Henderson offsetof(CPUSPARCState, fsr_cexc_ftt)); 1282baf3dbf2SRichard Henderson } 1283baf3dbf2SRichard Henderson 1284baf3dbf2SRichard Henderson static void gen_op_fmovs(TCGv_i32 dst, TCGv_i32 src) 1285baf3dbf2SRichard Henderson { 1286baf3dbf2SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 1287baf3dbf2SRichard Henderson tcg_gen_mov_i32(dst, src); 1288baf3dbf2SRichard Henderson } 1289baf3dbf2SRichard Henderson 1290baf3dbf2SRichard Henderson static void gen_op_fnegs(TCGv_i32 dst, TCGv_i32 src) 1291baf3dbf2SRichard Henderson { 1292baf3dbf2SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 1293daf457d4SRichard Henderson tcg_gen_xori_i32(dst, src, 1u << 31); 1294baf3dbf2SRichard Henderson } 1295baf3dbf2SRichard Henderson 1296baf3dbf2SRichard Henderson static void gen_op_fabss(TCGv_i32 dst, TCGv_i32 src) 1297baf3dbf2SRichard Henderson { 1298baf3dbf2SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 1299daf457d4SRichard Henderson tcg_gen_andi_i32(dst, src, ~(1u << 31)); 1300baf3dbf2SRichard Henderson } 1301baf3dbf2SRichard Henderson 1302c6d83e4fSRichard Henderson static void gen_op_fmovd(TCGv_i64 dst, TCGv_i64 src) 1303c6d83e4fSRichard Henderson { 1304c6d83e4fSRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 1305c6d83e4fSRichard Henderson tcg_gen_mov_i64(dst, src); 1306c6d83e4fSRichard Henderson } 1307c6d83e4fSRichard Henderson 1308c6d83e4fSRichard Henderson static void gen_op_fnegd(TCGv_i64 dst, TCGv_i64 src) 1309c6d83e4fSRichard Henderson { 1310c6d83e4fSRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 1311daf457d4SRichard Henderson tcg_gen_xori_i64(dst, src, 1ull << 63); 1312c6d83e4fSRichard Henderson } 1313c6d83e4fSRichard Henderson 1314c6d83e4fSRichard Henderson static void gen_op_fabsd(TCGv_i64 dst, TCGv_i64 src) 1315c6d83e4fSRichard Henderson { 1316c6d83e4fSRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 1317daf457d4SRichard Henderson tcg_gen_andi_i64(dst, src, ~(1ull << 63)); 1318daf457d4SRichard Henderson } 1319daf457d4SRichard Henderson 1320daf457d4SRichard Henderson static void gen_op_fnegq(TCGv_i128 dst, TCGv_i128 src) 1321daf457d4SRichard Henderson { 1322daf457d4SRichard Henderson TCGv_i64 l = tcg_temp_new_i64(); 1323daf457d4SRichard Henderson TCGv_i64 h = tcg_temp_new_i64(); 1324daf457d4SRichard Henderson 1325daf457d4SRichard Henderson tcg_gen_extr_i128_i64(l, h, src); 1326daf457d4SRichard Henderson tcg_gen_xori_i64(h, h, 1ull << 63); 1327daf457d4SRichard Henderson tcg_gen_concat_i64_i128(dst, l, h); 1328daf457d4SRichard Henderson } 1329daf457d4SRichard Henderson 1330daf457d4SRichard Henderson static void gen_op_fabsq(TCGv_i128 dst, TCGv_i128 src) 1331daf457d4SRichard Henderson { 1332daf457d4SRichard Henderson TCGv_i64 l = tcg_temp_new_i64(); 1333daf457d4SRichard Henderson TCGv_i64 h = tcg_temp_new_i64(); 1334daf457d4SRichard Henderson 1335daf457d4SRichard Henderson tcg_gen_extr_i128_i64(l, h, src); 1336daf457d4SRichard Henderson tcg_gen_andi_i64(h, h, ~(1ull << 63)); 1337daf457d4SRichard Henderson tcg_gen_concat_i64_i128(dst, l, h); 1338c6d83e4fSRichard Henderson } 1339c6d83e4fSRichard Henderson 13404fd71d19SRichard Henderson static void gen_op_fmadds(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2, TCGv_i32 s3) 13414fd71d19SRichard Henderson { 13424fd71d19SRichard Henderson gen_helper_fmadds(d, tcg_env, s1, s2, s3, tcg_constant_i32(0)); 13434fd71d19SRichard Henderson } 13444fd71d19SRichard Henderson 13454fd71d19SRichard Henderson static void gen_op_fmaddd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2, TCGv_i64 s3) 13464fd71d19SRichard Henderson { 13474fd71d19SRichard Henderson gen_helper_fmaddd(d, tcg_env, s1, s2, s3, tcg_constant_i32(0)); 13484fd71d19SRichard Henderson } 13494fd71d19SRichard Henderson 13504fd71d19SRichard Henderson static void gen_op_fmsubs(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2, TCGv_i32 s3) 13514fd71d19SRichard Henderson { 13524fd71d19SRichard Henderson int op = float_muladd_negate_c; 13534fd71d19SRichard Henderson gen_helper_fmadds(d, tcg_env, s1, s2, s3, tcg_constant_i32(op)); 13544fd71d19SRichard Henderson } 13554fd71d19SRichard Henderson 13564fd71d19SRichard Henderson static void gen_op_fmsubd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2, TCGv_i64 s3) 13574fd71d19SRichard Henderson { 13584fd71d19SRichard Henderson int op = float_muladd_negate_c; 13594fd71d19SRichard Henderson gen_helper_fmaddd(d, tcg_env, s1, s2, s3, tcg_constant_i32(op)); 13604fd71d19SRichard Henderson } 13614fd71d19SRichard Henderson 13624fd71d19SRichard Henderson static void gen_op_fnmsubs(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2, TCGv_i32 s3) 13634fd71d19SRichard Henderson { 13644fd71d19SRichard Henderson int op = float_muladd_negate_c | float_muladd_negate_result; 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_fnmsubd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2, TCGv_i64 s3) 13694fd71d19SRichard Henderson { 13704fd71d19SRichard Henderson int op = float_muladd_negate_c | float_muladd_negate_result; 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_fnmadds(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2, TCGv_i32 s3) 13754fd71d19SRichard Henderson { 13764fd71d19SRichard Henderson int op = 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_fnmaddd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2, TCGv_i64 s3) 13814fd71d19SRichard Henderson { 13824fd71d19SRichard Henderson int op = float_muladd_negate_result; 13834fd71d19SRichard Henderson gen_helper_fmaddd(d, tcg_env, s1, s2, s3, tcg_constant_i32(op)); 13844fd71d19SRichard Henderson } 13854fd71d19SRichard Henderson 13863d50b728SRichard Henderson /* Use muladd to compute (1 * src1) + src2 / 2 with one rounding. */ 13873d50b728SRichard Henderson static void gen_op_fhadds(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2) 13883d50b728SRichard Henderson { 13893d50b728SRichard Henderson TCGv_i32 one = tcg_constant_i32(float32_one); 13903d50b728SRichard Henderson int op = float_muladd_halve_result; 13913d50b728SRichard Henderson gen_helper_fmadds(d, tcg_env, one, s1, s2, tcg_constant_i32(op)); 13923d50b728SRichard Henderson } 13933d50b728SRichard Henderson 13943d50b728SRichard Henderson static void gen_op_fhaddd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2) 13953d50b728SRichard Henderson { 13963d50b728SRichard Henderson TCGv_i64 one = tcg_constant_i64(float64_one); 13973d50b728SRichard Henderson int op = float_muladd_halve_result; 13983d50b728SRichard Henderson gen_helper_fmaddd(d, tcg_env, one, s1, s2, tcg_constant_i32(op)); 13993d50b728SRichard Henderson } 14003d50b728SRichard Henderson 14013d50b728SRichard Henderson /* Use muladd to compute (1 * src1) - src2 / 2 with one rounding. */ 14023d50b728SRichard Henderson static void gen_op_fhsubs(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2) 14033d50b728SRichard Henderson { 14043d50b728SRichard Henderson TCGv_i32 one = tcg_constant_i32(float32_one); 14053d50b728SRichard Henderson int op = float_muladd_negate_c | float_muladd_halve_result; 14063d50b728SRichard Henderson gen_helper_fmadds(d, tcg_env, one, s1, s2, tcg_constant_i32(op)); 14073d50b728SRichard Henderson } 14083d50b728SRichard Henderson 14093d50b728SRichard Henderson static void gen_op_fhsubd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2) 14103d50b728SRichard Henderson { 14113d50b728SRichard Henderson TCGv_i64 one = tcg_constant_i64(float64_one); 14123d50b728SRichard Henderson int op = float_muladd_negate_c | float_muladd_halve_result; 14133d50b728SRichard Henderson gen_helper_fmaddd(d, tcg_env, one, s1, s2, tcg_constant_i32(op)); 14143d50b728SRichard Henderson } 14153d50b728SRichard Henderson 14163d50b728SRichard Henderson /* Use muladd to compute -((1 * src1) + src2 / 2) with one rounding. */ 14173d50b728SRichard Henderson static void gen_op_fnhadds(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2) 14183d50b728SRichard Henderson { 14193d50b728SRichard Henderson TCGv_i32 one = tcg_constant_i32(float32_one); 14203d50b728SRichard Henderson int op = float_muladd_negate_result | float_muladd_halve_result; 14213d50b728SRichard Henderson gen_helper_fmadds(d, tcg_env, one, s1, s2, tcg_constant_i32(op)); 14223d50b728SRichard Henderson } 14233d50b728SRichard Henderson 14243d50b728SRichard Henderson static void gen_op_fnhaddd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2) 14253d50b728SRichard Henderson { 14263d50b728SRichard Henderson TCGv_i64 one = tcg_constant_i64(float64_one); 14273d50b728SRichard Henderson int op = float_muladd_negate_result | float_muladd_halve_result; 14283d50b728SRichard Henderson gen_helper_fmaddd(d, tcg_env, one, s1, s2, tcg_constant_i32(op)); 14293d50b728SRichard Henderson } 14303d50b728SRichard Henderson 14313590f01eSRichard Henderson static void gen_op_fpexception_im(DisasContext *dc, int ftt) 1432fcf5ef2aSThomas Huth { 14333590f01eSRichard Henderson /* 14343590f01eSRichard Henderson * CEXC is only set when succesfully completing an FPop, 14353590f01eSRichard Henderson * or when raising FSR_FTT_IEEE_EXCP, i.e. check_ieee_exception. 14363590f01eSRichard Henderson * Thus we can simply store FTT into this field. 14373590f01eSRichard Henderson */ 14383590f01eSRichard Henderson tcg_gen_st_i32(tcg_constant_i32(ftt), tcg_env, 14393590f01eSRichard Henderson offsetof(CPUSPARCState, fsr_cexc_ftt)); 1440fcf5ef2aSThomas Huth gen_exception(dc, TT_FP_EXCP); 1441fcf5ef2aSThomas Huth } 1442fcf5ef2aSThomas Huth 1443fcf5ef2aSThomas Huth static int gen_trap_ifnofpu(DisasContext *dc) 1444fcf5ef2aSThomas Huth { 1445fcf5ef2aSThomas Huth #if !defined(CONFIG_USER_ONLY) 1446fcf5ef2aSThomas Huth if (!dc->fpu_enabled) { 1447fcf5ef2aSThomas Huth gen_exception(dc, TT_NFPU_INSN); 1448fcf5ef2aSThomas Huth return 1; 1449fcf5ef2aSThomas Huth } 1450fcf5ef2aSThomas Huth #endif 1451fcf5ef2aSThomas Huth return 0; 1452fcf5ef2aSThomas Huth } 1453fcf5ef2aSThomas Huth 1454fcf5ef2aSThomas Huth /* asi moves */ 1455fcf5ef2aSThomas Huth typedef enum { 1456fcf5ef2aSThomas Huth GET_ASI_HELPER, 1457fcf5ef2aSThomas Huth GET_ASI_EXCP, 1458fcf5ef2aSThomas Huth GET_ASI_DIRECT, 1459fcf5ef2aSThomas Huth GET_ASI_DTWINX, 14602786a3f8SRichard Henderson GET_ASI_CODE, 1461fcf5ef2aSThomas Huth GET_ASI_BLOCK, 1462fcf5ef2aSThomas Huth GET_ASI_SHORT, 1463fcf5ef2aSThomas Huth GET_ASI_BCOPY, 1464fcf5ef2aSThomas Huth GET_ASI_BFILL, 1465fcf5ef2aSThomas Huth } ASIType; 1466fcf5ef2aSThomas Huth 1467fcf5ef2aSThomas Huth typedef struct { 1468fcf5ef2aSThomas Huth ASIType type; 1469fcf5ef2aSThomas Huth int asi; 1470fcf5ef2aSThomas Huth int mem_idx; 147114776ab5STony Nguyen MemOp memop; 1472fcf5ef2aSThomas Huth } DisasASI; 1473fcf5ef2aSThomas Huth 1474811cc0b0SRichard Henderson /* 1475811cc0b0SRichard Henderson * Build DisasASI. 1476811cc0b0SRichard Henderson * For asi == -1, treat as non-asi. 1477811cc0b0SRichard Henderson * For ask == -2, treat as immediate offset (v8 error, v9 %asi). 1478811cc0b0SRichard Henderson */ 1479811cc0b0SRichard Henderson static DisasASI resolve_asi(DisasContext *dc, int asi, MemOp memop) 1480fcf5ef2aSThomas Huth { 1481fcf5ef2aSThomas Huth ASIType type = GET_ASI_HELPER; 1482fcf5ef2aSThomas Huth int mem_idx = dc->mem_idx; 1483fcf5ef2aSThomas Huth 1484811cc0b0SRichard Henderson if (asi == -1) { 1485811cc0b0SRichard Henderson /* Artificial "non-asi" case. */ 1486811cc0b0SRichard Henderson type = GET_ASI_DIRECT; 1487811cc0b0SRichard Henderson goto done; 1488811cc0b0SRichard Henderson } 1489811cc0b0SRichard Henderson 1490fcf5ef2aSThomas Huth #ifndef TARGET_SPARC64 1491fcf5ef2aSThomas Huth /* Before v9, all asis are immediate and privileged. */ 1492811cc0b0SRichard Henderson if (asi < 0) { 1493fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 1494fcf5ef2aSThomas Huth type = GET_ASI_EXCP; 1495fcf5ef2aSThomas Huth } else if (supervisor(dc) 1496fcf5ef2aSThomas Huth /* Note that LEON accepts ASI_USERDATA in user mode, for 1497fcf5ef2aSThomas Huth use with CASA. Also note that previous versions of 1498fcf5ef2aSThomas Huth QEMU allowed (and old versions of gcc emitted) ASI_P 1499fcf5ef2aSThomas Huth for LEON, which is incorrect. */ 1500fcf5ef2aSThomas Huth || (asi == ASI_USERDATA 1501fcf5ef2aSThomas Huth && (dc->def->features & CPU_FEATURE_CASA))) { 1502fcf5ef2aSThomas Huth switch (asi) { 1503fcf5ef2aSThomas Huth case ASI_USERDATA: /* User data access */ 1504fcf5ef2aSThomas Huth mem_idx = MMU_USER_IDX; 1505fcf5ef2aSThomas Huth type = GET_ASI_DIRECT; 1506fcf5ef2aSThomas Huth break; 1507fcf5ef2aSThomas Huth case ASI_KERNELDATA: /* Supervisor data access */ 1508fcf5ef2aSThomas Huth mem_idx = MMU_KERNEL_IDX; 1509fcf5ef2aSThomas Huth type = GET_ASI_DIRECT; 1510fcf5ef2aSThomas Huth break; 15112786a3f8SRichard Henderson case ASI_USERTXT: /* User text access */ 15122786a3f8SRichard Henderson mem_idx = MMU_USER_IDX; 15132786a3f8SRichard Henderson type = GET_ASI_CODE; 15142786a3f8SRichard Henderson break; 15152786a3f8SRichard Henderson case ASI_KERNELTXT: /* Supervisor text access */ 15162786a3f8SRichard Henderson mem_idx = MMU_KERNEL_IDX; 15172786a3f8SRichard Henderson type = GET_ASI_CODE; 15182786a3f8SRichard Henderson break; 1519fcf5ef2aSThomas Huth case ASI_M_BYPASS: /* MMU passthrough */ 1520fcf5ef2aSThomas Huth case ASI_LEON_BYPASS: /* LEON MMU passthrough */ 1521fcf5ef2aSThomas Huth mem_idx = MMU_PHYS_IDX; 1522fcf5ef2aSThomas Huth type = GET_ASI_DIRECT; 1523fcf5ef2aSThomas Huth break; 1524fcf5ef2aSThomas Huth case ASI_M_BCOPY: /* Block copy, sta access */ 1525fcf5ef2aSThomas Huth mem_idx = MMU_KERNEL_IDX; 1526fcf5ef2aSThomas Huth type = GET_ASI_BCOPY; 1527fcf5ef2aSThomas Huth break; 1528fcf5ef2aSThomas Huth case ASI_M_BFILL: /* Block fill, stda access */ 1529fcf5ef2aSThomas Huth mem_idx = MMU_KERNEL_IDX; 1530fcf5ef2aSThomas Huth type = GET_ASI_BFILL; 1531fcf5ef2aSThomas Huth break; 1532fcf5ef2aSThomas Huth } 15336e10f37cSKONRAD Frederic 15346e10f37cSKONRAD Frederic /* MMU_PHYS_IDX is used when the MMU is disabled to passthrough the 15356e10f37cSKONRAD Frederic * permissions check in get_physical_address(..). 15366e10f37cSKONRAD Frederic */ 15376e10f37cSKONRAD Frederic mem_idx = (dc->mem_idx == MMU_PHYS_IDX) ? MMU_PHYS_IDX : mem_idx; 1538fcf5ef2aSThomas Huth } else { 1539fcf5ef2aSThomas Huth gen_exception(dc, TT_PRIV_INSN); 1540fcf5ef2aSThomas Huth type = GET_ASI_EXCP; 1541fcf5ef2aSThomas Huth } 1542fcf5ef2aSThomas Huth #else 1543811cc0b0SRichard Henderson if (asi < 0) { 1544fcf5ef2aSThomas Huth asi = dc->asi; 1545fcf5ef2aSThomas Huth } 1546fcf5ef2aSThomas Huth /* With v9, all asis below 0x80 are privileged. */ 1547fcf5ef2aSThomas Huth /* ??? We ought to check cpu_has_hypervisor, but we didn't copy 1548fcf5ef2aSThomas Huth down that bit into DisasContext. For the moment that's ok, 1549fcf5ef2aSThomas Huth since the direct implementations below doesn't have any ASIs 1550fcf5ef2aSThomas Huth in the restricted [0x30, 0x7f] range, and the check will be 1551fcf5ef2aSThomas Huth done properly in the helper. */ 1552fcf5ef2aSThomas Huth if (!supervisor(dc) && asi < 0x80) { 1553fcf5ef2aSThomas Huth gen_exception(dc, TT_PRIV_ACT); 1554fcf5ef2aSThomas Huth type = GET_ASI_EXCP; 1555fcf5ef2aSThomas Huth } else { 1556fcf5ef2aSThomas Huth switch (asi) { 1557fcf5ef2aSThomas Huth case ASI_REAL: /* Bypass */ 1558fcf5ef2aSThomas Huth case ASI_REAL_IO: /* Bypass, non-cacheable */ 1559fcf5ef2aSThomas Huth case ASI_REAL_L: /* Bypass LE */ 1560fcf5ef2aSThomas Huth case ASI_REAL_IO_L: /* Bypass, non-cacheable LE */ 1561fcf5ef2aSThomas Huth case ASI_TWINX_REAL: /* Real address, twinx */ 1562fcf5ef2aSThomas Huth case ASI_TWINX_REAL_L: /* Real address, twinx, LE */ 1563fcf5ef2aSThomas Huth case ASI_QUAD_LDD_PHYS: 1564fcf5ef2aSThomas Huth case ASI_QUAD_LDD_PHYS_L: 1565fcf5ef2aSThomas Huth mem_idx = MMU_PHYS_IDX; 1566fcf5ef2aSThomas Huth break; 1567fcf5ef2aSThomas Huth case ASI_N: /* Nucleus */ 1568fcf5ef2aSThomas Huth case ASI_NL: /* Nucleus LE */ 1569fcf5ef2aSThomas Huth case ASI_TWINX_N: 1570fcf5ef2aSThomas Huth case ASI_TWINX_NL: 1571fcf5ef2aSThomas Huth case ASI_NUCLEUS_QUAD_LDD: 1572fcf5ef2aSThomas Huth case ASI_NUCLEUS_QUAD_LDD_L: 15739a10756dSArtyom Tarasenko if (hypervisor(dc)) { 157484f8f587SArtyom Tarasenko mem_idx = MMU_PHYS_IDX; 15759a10756dSArtyom Tarasenko } else { 1576fcf5ef2aSThomas Huth mem_idx = MMU_NUCLEUS_IDX; 15779a10756dSArtyom Tarasenko } 1578fcf5ef2aSThomas Huth break; 1579fcf5ef2aSThomas Huth case ASI_AIUP: /* As if user primary */ 1580fcf5ef2aSThomas Huth case ASI_AIUPL: /* As if user primary LE */ 1581fcf5ef2aSThomas Huth case ASI_TWINX_AIUP: 1582fcf5ef2aSThomas Huth case ASI_TWINX_AIUP_L: 1583fcf5ef2aSThomas Huth case ASI_BLK_AIUP_4V: 1584fcf5ef2aSThomas Huth case ASI_BLK_AIUP_L_4V: 1585fcf5ef2aSThomas Huth case ASI_BLK_AIUP: 1586fcf5ef2aSThomas Huth case ASI_BLK_AIUPL: 1587fcf5ef2aSThomas Huth mem_idx = MMU_USER_IDX; 1588fcf5ef2aSThomas Huth break; 1589fcf5ef2aSThomas Huth case ASI_AIUS: /* As if user secondary */ 1590fcf5ef2aSThomas Huth case ASI_AIUSL: /* As if user secondary LE */ 1591fcf5ef2aSThomas Huth case ASI_TWINX_AIUS: 1592fcf5ef2aSThomas Huth case ASI_TWINX_AIUS_L: 1593fcf5ef2aSThomas Huth case ASI_BLK_AIUS_4V: 1594fcf5ef2aSThomas Huth case ASI_BLK_AIUS_L_4V: 1595fcf5ef2aSThomas Huth case ASI_BLK_AIUS: 1596fcf5ef2aSThomas Huth case ASI_BLK_AIUSL: 1597fcf5ef2aSThomas Huth mem_idx = MMU_USER_SECONDARY_IDX; 1598fcf5ef2aSThomas Huth break; 1599fcf5ef2aSThomas Huth case ASI_S: /* Secondary */ 1600fcf5ef2aSThomas Huth case ASI_SL: /* Secondary LE */ 1601fcf5ef2aSThomas Huth case ASI_TWINX_S: 1602fcf5ef2aSThomas Huth case ASI_TWINX_SL: 1603fcf5ef2aSThomas Huth case ASI_BLK_COMMIT_S: 1604fcf5ef2aSThomas Huth case ASI_BLK_S: 1605fcf5ef2aSThomas Huth case ASI_BLK_SL: 1606fcf5ef2aSThomas Huth case ASI_FL8_S: 1607fcf5ef2aSThomas Huth case ASI_FL8_SL: 1608fcf5ef2aSThomas Huth case ASI_FL16_S: 1609fcf5ef2aSThomas Huth case ASI_FL16_SL: 1610fcf5ef2aSThomas Huth if (mem_idx == MMU_USER_IDX) { 1611fcf5ef2aSThomas Huth mem_idx = MMU_USER_SECONDARY_IDX; 1612fcf5ef2aSThomas Huth } else if (mem_idx == MMU_KERNEL_IDX) { 1613fcf5ef2aSThomas Huth mem_idx = MMU_KERNEL_SECONDARY_IDX; 1614fcf5ef2aSThomas Huth } 1615fcf5ef2aSThomas Huth break; 1616fcf5ef2aSThomas Huth case ASI_P: /* Primary */ 1617fcf5ef2aSThomas Huth case ASI_PL: /* Primary LE */ 1618fcf5ef2aSThomas Huth case ASI_TWINX_P: 1619fcf5ef2aSThomas Huth case ASI_TWINX_PL: 1620fcf5ef2aSThomas Huth case ASI_BLK_COMMIT_P: 1621fcf5ef2aSThomas Huth case ASI_BLK_P: 1622fcf5ef2aSThomas Huth case ASI_BLK_PL: 1623fcf5ef2aSThomas Huth case ASI_FL8_P: 1624fcf5ef2aSThomas Huth case ASI_FL8_PL: 1625fcf5ef2aSThomas Huth case ASI_FL16_P: 1626fcf5ef2aSThomas Huth case ASI_FL16_PL: 1627fcf5ef2aSThomas Huth break; 1628fcf5ef2aSThomas Huth } 1629fcf5ef2aSThomas Huth switch (asi) { 1630fcf5ef2aSThomas Huth case ASI_REAL: 1631fcf5ef2aSThomas Huth case ASI_REAL_IO: 1632fcf5ef2aSThomas Huth case ASI_REAL_L: 1633fcf5ef2aSThomas Huth case ASI_REAL_IO_L: 1634fcf5ef2aSThomas Huth case ASI_N: 1635fcf5ef2aSThomas Huth case ASI_NL: 1636fcf5ef2aSThomas Huth case ASI_AIUP: 1637fcf5ef2aSThomas Huth case ASI_AIUPL: 1638fcf5ef2aSThomas Huth case ASI_AIUS: 1639fcf5ef2aSThomas Huth case ASI_AIUSL: 1640fcf5ef2aSThomas Huth case ASI_S: 1641fcf5ef2aSThomas Huth case ASI_SL: 1642fcf5ef2aSThomas Huth case ASI_P: 1643fcf5ef2aSThomas Huth case ASI_PL: 1644fcf5ef2aSThomas Huth type = GET_ASI_DIRECT; 1645fcf5ef2aSThomas Huth break; 1646fcf5ef2aSThomas Huth case ASI_TWINX_REAL: 1647fcf5ef2aSThomas Huth case ASI_TWINX_REAL_L: 1648fcf5ef2aSThomas Huth case ASI_TWINX_N: 1649fcf5ef2aSThomas Huth case ASI_TWINX_NL: 1650fcf5ef2aSThomas Huth case ASI_TWINX_AIUP: 1651fcf5ef2aSThomas Huth case ASI_TWINX_AIUP_L: 1652fcf5ef2aSThomas Huth case ASI_TWINX_AIUS: 1653fcf5ef2aSThomas Huth case ASI_TWINX_AIUS_L: 1654fcf5ef2aSThomas Huth case ASI_TWINX_P: 1655fcf5ef2aSThomas Huth case ASI_TWINX_PL: 1656fcf5ef2aSThomas Huth case ASI_TWINX_S: 1657fcf5ef2aSThomas Huth case ASI_TWINX_SL: 1658fcf5ef2aSThomas Huth case ASI_QUAD_LDD_PHYS: 1659fcf5ef2aSThomas Huth case ASI_QUAD_LDD_PHYS_L: 1660fcf5ef2aSThomas Huth case ASI_NUCLEUS_QUAD_LDD: 1661fcf5ef2aSThomas Huth case ASI_NUCLEUS_QUAD_LDD_L: 1662fcf5ef2aSThomas Huth type = GET_ASI_DTWINX; 1663fcf5ef2aSThomas Huth break; 1664fcf5ef2aSThomas Huth case ASI_BLK_COMMIT_P: 1665fcf5ef2aSThomas Huth case ASI_BLK_COMMIT_S: 1666fcf5ef2aSThomas Huth case ASI_BLK_AIUP_4V: 1667fcf5ef2aSThomas Huth case ASI_BLK_AIUP_L_4V: 1668fcf5ef2aSThomas Huth case ASI_BLK_AIUP: 1669fcf5ef2aSThomas Huth case ASI_BLK_AIUPL: 1670fcf5ef2aSThomas Huth case ASI_BLK_AIUS_4V: 1671fcf5ef2aSThomas Huth case ASI_BLK_AIUS_L_4V: 1672fcf5ef2aSThomas Huth case ASI_BLK_AIUS: 1673fcf5ef2aSThomas Huth case ASI_BLK_AIUSL: 1674fcf5ef2aSThomas Huth case ASI_BLK_S: 1675fcf5ef2aSThomas Huth case ASI_BLK_SL: 1676fcf5ef2aSThomas Huth case ASI_BLK_P: 1677fcf5ef2aSThomas Huth case ASI_BLK_PL: 1678fcf5ef2aSThomas Huth type = GET_ASI_BLOCK; 1679fcf5ef2aSThomas Huth break; 1680fcf5ef2aSThomas Huth case ASI_FL8_S: 1681fcf5ef2aSThomas Huth case ASI_FL8_SL: 1682fcf5ef2aSThomas Huth case ASI_FL8_P: 1683fcf5ef2aSThomas Huth case ASI_FL8_PL: 1684fcf5ef2aSThomas Huth memop = MO_UB; 1685fcf5ef2aSThomas Huth type = GET_ASI_SHORT; 1686fcf5ef2aSThomas Huth break; 1687fcf5ef2aSThomas Huth case ASI_FL16_S: 1688fcf5ef2aSThomas Huth case ASI_FL16_SL: 1689fcf5ef2aSThomas Huth case ASI_FL16_P: 1690fcf5ef2aSThomas Huth case ASI_FL16_PL: 1691fcf5ef2aSThomas Huth memop = MO_TEUW; 1692fcf5ef2aSThomas Huth type = GET_ASI_SHORT; 1693fcf5ef2aSThomas Huth break; 1694fcf5ef2aSThomas Huth } 1695fcf5ef2aSThomas Huth /* The little-endian asis all have bit 3 set. */ 1696fcf5ef2aSThomas Huth if (asi & 8) { 1697fcf5ef2aSThomas Huth memop ^= MO_BSWAP; 1698fcf5ef2aSThomas Huth } 1699fcf5ef2aSThomas Huth } 1700fcf5ef2aSThomas Huth #endif 1701fcf5ef2aSThomas Huth 1702811cc0b0SRichard Henderson done: 1703fcf5ef2aSThomas Huth return (DisasASI){ type, asi, mem_idx, memop }; 1704fcf5ef2aSThomas Huth } 1705fcf5ef2aSThomas Huth 1706a76779eeSRichard Henderson #if defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64) 1707a76779eeSRichard Henderson static void gen_helper_ld_asi(TCGv_i64 r, TCGv_env e, TCGv a, 1708a76779eeSRichard Henderson TCGv_i32 asi, TCGv_i32 mop) 1709a76779eeSRichard Henderson { 1710a76779eeSRichard Henderson g_assert_not_reached(); 1711a76779eeSRichard Henderson } 1712a76779eeSRichard Henderson 1713a76779eeSRichard Henderson static void gen_helper_st_asi(TCGv_env e, TCGv a, TCGv_i64 r, 1714a76779eeSRichard Henderson TCGv_i32 asi, TCGv_i32 mop) 1715a76779eeSRichard Henderson { 1716a76779eeSRichard Henderson g_assert_not_reached(); 1717a76779eeSRichard Henderson } 1718a76779eeSRichard Henderson #endif 1719a76779eeSRichard Henderson 172042071fc1SRichard Henderson static void gen_ld_asi(DisasContext *dc, DisasASI *da, TCGv dst, TCGv addr) 1721fcf5ef2aSThomas Huth { 1722c03a0fd1SRichard Henderson switch (da->type) { 1723fcf5ef2aSThomas Huth case GET_ASI_EXCP: 1724fcf5ef2aSThomas Huth break; 1725fcf5ef2aSThomas Huth case GET_ASI_DTWINX: /* Reserved for ldda. */ 1726fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 1727fcf5ef2aSThomas Huth break; 1728fcf5ef2aSThomas Huth case GET_ASI_DIRECT: 1729c03a0fd1SRichard Henderson tcg_gen_qemu_ld_tl(dst, addr, da->mem_idx, da->memop | MO_ALIGN); 1730fcf5ef2aSThomas Huth break; 17312786a3f8SRichard Henderson 17322786a3f8SRichard Henderson case GET_ASI_CODE: 17332786a3f8SRichard Henderson #if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64) 17342786a3f8SRichard Henderson { 17352786a3f8SRichard Henderson MemOpIdx oi = make_memop_idx(da->memop, da->mem_idx); 17362786a3f8SRichard Henderson TCGv_i64 t64 = tcg_temp_new_i64(); 17372786a3f8SRichard Henderson 17382786a3f8SRichard Henderson gen_helper_ld_code(t64, tcg_env, addr, tcg_constant_i32(oi)); 17392786a3f8SRichard Henderson tcg_gen_trunc_i64_tl(dst, t64); 17402786a3f8SRichard Henderson } 17412786a3f8SRichard Henderson break; 17422786a3f8SRichard Henderson #else 17432786a3f8SRichard Henderson g_assert_not_reached(); 17442786a3f8SRichard Henderson #endif 17452786a3f8SRichard Henderson 1746fcf5ef2aSThomas Huth default: 1747fcf5ef2aSThomas Huth { 1748c03a0fd1SRichard Henderson TCGv_i32 r_asi = tcg_constant_i32(da->asi); 1749c03a0fd1SRichard Henderson TCGv_i32 r_mop = tcg_constant_i32(da->memop | MO_ALIGN); 1750fcf5ef2aSThomas Huth 1751fcf5ef2aSThomas Huth save_state(dc); 1752fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64 1753ad75a51eSRichard Henderson gen_helper_ld_asi(dst, tcg_env, addr, r_asi, r_mop); 1754fcf5ef2aSThomas Huth #else 1755fcf5ef2aSThomas Huth { 1756fcf5ef2aSThomas Huth TCGv_i64 t64 = tcg_temp_new_i64(); 1757ad75a51eSRichard Henderson gen_helper_ld_asi(t64, tcg_env, addr, r_asi, r_mop); 1758fcf5ef2aSThomas Huth tcg_gen_trunc_i64_tl(dst, t64); 1759fcf5ef2aSThomas Huth } 1760fcf5ef2aSThomas Huth #endif 1761fcf5ef2aSThomas Huth } 1762fcf5ef2aSThomas Huth break; 1763fcf5ef2aSThomas Huth } 1764fcf5ef2aSThomas Huth } 1765fcf5ef2aSThomas Huth 176642071fc1SRichard Henderson static void gen_st_asi(DisasContext *dc, DisasASI *da, TCGv src, TCGv addr) 1767c03a0fd1SRichard Henderson { 1768c03a0fd1SRichard Henderson switch (da->type) { 1769fcf5ef2aSThomas Huth case GET_ASI_EXCP: 1770fcf5ef2aSThomas Huth break; 1771c03a0fd1SRichard Henderson 1772fcf5ef2aSThomas Huth case GET_ASI_DTWINX: /* Reserved for stda. */ 1773c03a0fd1SRichard Henderson if (TARGET_LONG_BITS == 32) { 1774fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 1775fcf5ef2aSThomas Huth break; 1776c03a0fd1SRichard Henderson } else if (!(dc->def->features & CPU_FEATURE_HYPV)) { 17773390537bSArtyom Tarasenko /* Pre OpenSPARC CPUs don't have these */ 17783390537bSArtyom Tarasenko gen_exception(dc, TT_ILL_INSN); 1779fcf5ef2aSThomas Huth break; 1780c03a0fd1SRichard Henderson } 1781c03a0fd1SRichard Henderson /* In OpenSPARC T1+ CPUs TWINX ASIs in store are ST_BLKINIT_ ASIs */ 1782c03a0fd1SRichard Henderson /* fall through */ 1783c03a0fd1SRichard Henderson 1784c03a0fd1SRichard Henderson case GET_ASI_DIRECT: 1785c03a0fd1SRichard Henderson tcg_gen_qemu_st_tl(src, addr, da->mem_idx, da->memop | MO_ALIGN); 1786c03a0fd1SRichard Henderson break; 1787c03a0fd1SRichard Henderson 1788fcf5ef2aSThomas Huth case GET_ASI_BCOPY: 1789c03a0fd1SRichard Henderson assert(TARGET_LONG_BITS == 32); 179098271007SRichard Henderson /* 179198271007SRichard Henderson * Copy 32 bytes from the address in SRC to ADDR. 179298271007SRichard Henderson * 179398271007SRichard Henderson * From Ross RT625 hyperSPARC manual, section 4.6: 179498271007SRichard Henderson * "Block Copy and Block Fill will work only on cache line boundaries." 179598271007SRichard Henderson * 179698271007SRichard Henderson * It does not specify if an unaliged address is truncated or trapped. 179798271007SRichard Henderson * Previous qemu behaviour was to truncate to 4 byte alignment, which 179898271007SRichard Henderson * is obviously wrong. The only place I can see this used is in the 179998271007SRichard Henderson * Linux kernel which begins with page alignment, advancing by 32, 180098271007SRichard Henderson * so is always aligned. Assume truncation as the simpler option. 180198271007SRichard Henderson * 180298271007SRichard Henderson * Since the loads and stores are paired, allow the copy to happen 180398271007SRichard Henderson * in the host endianness. The copy need not be atomic. 180498271007SRichard Henderson */ 1805fcf5ef2aSThomas Huth { 180698271007SRichard Henderson MemOp mop = MO_128 | MO_ATOM_IFALIGN_PAIR; 1807fcf5ef2aSThomas Huth TCGv saddr = tcg_temp_new(); 1808fcf5ef2aSThomas Huth TCGv daddr = tcg_temp_new(); 180998271007SRichard Henderson TCGv_i128 tmp = tcg_temp_new_i128(); 1810fcf5ef2aSThomas Huth 181198271007SRichard Henderson tcg_gen_andi_tl(saddr, src, -32); 181298271007SRichard Henderson tcg_gen_andi_tl(daddr, addr, -32); 181398271007SRichard Henderson tcg_gen_qemu_ld_i128(tmp, saddr, da->mem_idx, mop); 181498271007SRichard Henderson tcg_gen_qemu_st_i128(tmp, daddr, da->mem_idx, mop); 181598271007SRichard Henderson tcg_gen_addi_tl(saddr, saddr, 16); 181698271007SRichard Henderson tcg_gen_addi_tl(daddr, daddr, 16); 181798271007SRichard Henderson tcg_gen_qemu_ld_i128(tmp, saddr, da->mem_idx, mop); 181898271007SRichard Henderson tcg_gen_qemu_st_i128(tmp, daddr, da->mem_idx, mop); 1819fcf5ef2aSThomas Huth } 1820fcf5ef2aSThomas Huth break; 1821c03a0fd1SRichard Henderson 1822fcf5ef2aSThomas Huth default: 1823fcf5ef2aSThomas Huth { 1824c03a0fd1SRichard Henderson TCGv_i32 r_asi = tcg_constant_i32(da->asi); 1825c03a0fd1SRichard Henderson TCGv_i32 r_mop = tcg_constant_i32(da->memop | MO_ALIGN); 1826fcf5ef2aSThomas Huth 1827fcf5ef2aSThomas Huth save_state(dc); 1828fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64 1829ad75a51eSRichard Henderson gen_helper_st_asi(tcg_env, addr, src, r_asi, r_mop); 1830fcf5ef2aSThomas Huth #else 1831fcf5ef2aSThomas Huth { 1832fcf5ef2aSThomas Huth TCGv_i64 t64 = tcg_temp_new_i64(); 1833fcf5ef2aSThomas Huth tcg_gen_extu_tl_i64(t64, src); 1834ad75a51eSRichard Henderson gen_helper_st_asi(tcg_env, addr, t64, r_asi, r_mop); 1835fcf5ef2aSThomas Huth } 1836fcf5ef2aSThomas Huth #endif 1837fcf5ef2aSThomas Huth 1838fcf5ef2aSThomas Huth /* A write to a TLB register may alter page maps. End the TB. */ 1839fcf5ef2aSThomas Huth dc->npc = DYNAMIC_PC; 1840fcf5ef2aSThomas Huth } 1841fcf5ef2aSThomas Huth break; 1842fcf5ef2aSThomas Huth } 1843fcf5ef2aSThomas Huth } 1844fcf5ef2aSThomas Huth 1845dca544b9SRichard Henderson static void gen_swap_asi(DisasContext *dc, DisasASI *da, 1846c03a0fd1SRichard Henderson TCGv dst, TCGv src, TCGv addr) 1847c03a0fd1SRichard Henderson { 1848c03a0fd1SRichard Henderson switch (da->type) { 1849c03a0fd1SRichard Henderson case GET_ASI_EXCP: 1850c03a0fd1SRichard Henderson break; 1851c03a0fd1SRichard Henderson case GET_ASI_DIRECT: 1852dca544b9SRichard Henderson tcg_gen_atomic_xchg_tl(dst, addr, src, 1853dca544b9SRichard Henderson da->mem_idx, da->memop | MO_ALIGN); 1854c03a0fd1SRichard Henderson break; 1855c03a0fd1SRichard Henderson default: 1856c03a0fd1SRichard Henderson /* ??? Should be DAE_invalid_asi. */ 1857c03a0fd1SRichard Henderson gen_exception(dc, TT_DATA_ACCESS); 1858c03a0fd1SRichard Henderson break; 1859c03a0fd1SRichard Henderson } 1860c03a0fd1SRichard Henderson } 1861c03a0fd1SRichard Henderson 1862d0a11d25SRichard Henderson static void gen_cas_asi(DisasContext *dc, DisasASI *da, 1863c03a0fd1SRichard Henderson TCGv oldv, TCGv newv, TCGv cmpv, TCGv addr) 1864c03a0fd1SRichard Henderson { 1865c03a0fd1SRichard Henderson switch (da->type) { 1866fcf5ef2aSThomas Huth case GET_ASI_EXCP: 1867c03a0fd1SRichard Henderson return; 1868fcf5ef2aSThomas Huth case GET_ASI_DIRECT: 1869c03a0fd1SRichard Henderson tcg_gen_atomic_cmpxchg_tl(oldv, addr, cmpv, newv, 1870c03a0fd1SRichard Henderson da->mem_idx, da->memop | MO_ALIGN); 1871fcf5ef2aSThomas Huth break; 1872fcf5ef2aSThomas Huth default: 1873fcf5ef2aSThomas Huth /* ??? Should be DAE_invalid_asi. */ 1874fcf5ef2aSThomas Huth gen_exception(dc, TT_DATA_ACCESS); 1875fcf5ef2aSThomas Huth break; 1876fcf5ef2aSThomas Huth } 1877fcf5ef2aSThomas Huth } 1878fcf5ef2aSThomas Huth 1879cf07cd1eSRichard Henderson static void gen_ldstub_asi(DisasContext *dc, DisasASI *da, TCGv dst, TCGv addr) 1880c03a0fd1SRichard Henderson { 1881c03a0fd1SRichard Henderson switch (da->type) { 1882fcf5ef2aSThomas Huth case GET_ASI_EXCP: 1883fcf5ef2aSThomas Huth break; 1884fcf5ef2aSThomas Huth case GET_ASI_DIRECT: 1885cf07cd1eSRichard Henderson tcg_gen_atomic_xchg_tl(dst, addr, tcg_constant_tl(0xff), 1886cf07cd1eSRichard Henderson da->mem_idx, MO_UB); 1887fcf5ef2aSThomas Huth break; 1888fcf5ef2aSThomas Huth default: 18893db010c3SRichard Henderson /* ??? In theory, this should be raise DAE_invalid_asi. 18903db010c3SRichard Henderson But the SS-20 roms do ldstuba [%l0] #ASI_M_CTL, %o1. */ 1891af00be49SEmilio G. Cota if (tb_cflags(dc->base.tb) & CF_PARALLEL) { 1892ad75a51eSRichard Henderson gen_helper_exit_atomic(tcg_env); 18933db010c3SRichard Henderson } else { 1894c03a0fd1SRichard Henderson TCGv_i32 r_asi = tcg_constant_i32(da->asi); 189500ab7e61SRichard Henderson TCGv_i32 r_mop = tcg_constant_i32(MO_UB); 18963db010c3SRichard Henderson TCGv_i64 s64, t64; 18973db010c3SRichard Henderson 18983db010c3SRichard Henderson save_state(dc); 18993db010c3SRichard Henderson t64 = tcg_temp_new_i64(); 1900ad75a51eSRichard Henderson gen_helper_ld_asi(t64, tcg_env, addr, r_asi, r_mop); 19013db010c3SRichard Henderson 190200ab7e61SRichard Henderson s64 = tcg_constant_i64(0xff); 1903ad75a51eSRichard Henderson gen_helper_st_asi(tcg_env, addr, s64, r_asi, r_mop); 19043db010c3SRichard Henderson 19053db010c3SRichard Henderson tcg_gen_trunc_i64_tl(dst, t64); 19063db010c3SRichard Henderson 19073db010c3SRichard Henderson /* End the TB. */ 19083db010c3SRichard Henderson dc->npc = DYNAMIC_PC; 19093db010c3SRichard Henderson } 1910fcf5ef2aSThomas Huth break; 1911fcf5ef2aSThomas Huth } 1912fcf5ef2aSThomas Huth } 1913fcf5ef2aSThomas Huth 1914287b1152SRichard Henderson static void gen_ldf_asi(DisasContext *dc, DisasASI *da, MemOp orig_size, 19153259b9e2SRichard Henderson TCGv addr, int rd) 1916fcf5ef2aSThomas Huth { 19173259b9e2SRichard Henderson MemOp memop = da->memop; 19183259b9e2SRichard Henderson MemOp size = memop & MO_SIZE; 1919fcf5ef2aSThomas Huth TCGv_i32 d32; 19201210a036SRichard Henderson TCGv_i64 d64, l64; 1921287b1152SRichard Henderson TCGv addr_tmp; 1922fcf5ef2aSThomas Huth 19233259b9e2SRichard Henderson /* TODO: Use 128-bit load/store below. */ 19243259b9e2SRichard Henderson if (size == MO_128) { 19253259b9e2SRichard Henderson memop = (memop & ~MO_SIZE) | MO_64; 19263259b9e2SRichard Henderson } 19273259b9e2SRichard Henderson 19283259b9e2SRichard Henderson switch (da->type) { 1929fcf5ef2aSThomas Huth case GET_ASI_EXCP: 1930fcf5ef2aSThomas Huth break; 1931fcf5ef2aSThomas Huth 1932fcf5ef2aSThomas Huth case GET_ASI_DIRECT: 19333259b9e2SRichard Henderson memop |= MO_ALIGN_4; 1934fcf5ef2aSThomas Huth switch (size) { 19353259b9e2SRichard Henderson case MO_32: 1936388a6465SRichard Henderson d32 = tcg_temp_new_i32(); 19373259b9e2SRichard Henderson tcg_gen_qemu_ld_i32(d32, addr, da->mem_idx, memop); 1938fcf5ef2aSThomas Huth gen_store_fpr_F(dc, rd, d32); 1939fcf5ef2aSThomas Huth break; 19403259b9e2SRichard Henderson 19413259b9e2SRichard Henderson case MO_64: 19421210a036SRichard Henderson d64 = tcg_temp_new_i64(); 19431210a036SRichard Henderson tcg_gen_qemu_ld_i64(d64, addr, da->mem_idx, memop); 19441210a036SRichard Henderson gen_store_fpr_D(dc, rd, d64); 1945fcf5ef2aSThomas Huth break; 19463259b9e2SRichard Henderson 19473259b9e2SRichard Henderson case MO_128: 1948fcf5ef2aSThomas Huth d64 = tcg_temp_new_i64(); 19491210a036SRichard Henderson l64 = tcg_temp_new_i64(); 19503259b9e2SRichard Henderson tcg_gen_qemu_ld_i64(d64, addr, da->mem_idx, memop); 1951287b1152SRichard Henderson addr_tmp = tcg_temp_new(); 1952287b1152SRichard Henderson tcg_gen_addi_tl(addr_tmp, addr, 8); 19531210a036SRichard Henderson tcg_gen_qemu_ld_i64(l64, addr_tmp, da->mem_idx, memop); 19541210a036SRichard Henderson gen_store_fpr_D(dc, rd, d64); 19551210a036SRichard Henderson gen_store_fpr_D(dc, rd + 2, l64); 1956fcf5ef2aSThomas Huth break; 1957fcf5ef2aSThomas Huth default: 1958fcf5ef2aSThomas Huth g_assert_not_reached(); 1959fcf5ef2aSThomas Huth } 1960fcf5ef2aSThomas Huth break; 1961fcf5ef2aSThomas Huth 1962fcf5ef2aSThomas Huth case GET_ASI_BLOCK: 1963fcf5ef2aSThomas Huth /* Valid for lddfa on aligned registers only. */ 19643259b9e2SRichard Henderson if (orig_size == MO_64 && (rd & 7) == 0) { 1965fcf5ef2aSThomas Huth /* The first operation checks required alignment. */ 1966287b1152SRichard Henderson addr_tmp = tcg_temp_new(); 19671210a036SRichard Henderson d64 = tcg_temp_new_i64(); 1968287b1152SRichard Henderson for (int i = 0; ; ++i) { 19691210a036SRichard Henderson tcg_gen_qemu_ld_i64(d64, addr, da->mem_idx, 19703259b9e2SRichard Henderson memop | (i == 0 ? MO_ALIGN_64 : 0)); 19711210a036SRichard Henderson gen_store_fpr_D(dc, rd + 2 * i, d64); 1972fcf5ef2aSThomas Huth if (i == 7) { 1973fcf5ef2aSThomas Huth break; 1974fcf5ef2aSThomas Huth } 1975287b1152SRichard Henderson tcg_gen_addi_tl(addr_tmp, addr, 8); 1976287b1152SRichard Henderson addr = addr_tmp; 1977fcf5ef2aSThomas Huth } 1978fcf5ef2aSThomas Huth } else { 1979fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 1980fcf5ef2aSThomas Huth } 1981fcf5ef2aSThomas Huth break; 1982fcf5ef2aSThomas Huth 1983fcf5ef2aSThomas Huth case GET_ASI_SHORT: 1984fcf5ef2aSThomas Huth /* Valid for lddfa only. */ 19853259b9e2SRichard Henderson if (orig_size == MO_64) { 19861210a036SRichard Henderson d64 = tcg_temp_new_i64(); 19871210a036SRichard Henderson tcg_gen_qemu_ld_i64(d64, addr, da->mem_idx, memop | MO_ALIGN); 19881210a036SRichard Henderson gen_store_fpr_D(dc, rd, d64); 1989fcf5ef2aSThomas Huth } else { 1990fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 1991fcf5ef2aSThomas Huth } 1992fcf5ef2aSThomas Huth break; 1993fcf5ef2aSThomas Huth 1994fcf5ef2aSThomas Huth default: 1995fcf5ef2aSThomas Huth { 19963259b9e2SRichard Henderson TCGv_i32 r_asi = tcg_constant_i32(da->asi); 19973259b9e2SRichard Henderson TCGv_i32 r_mop = tcg_constant_i32(memop | MO_ALIGN); 1998fcf5ef2aSThomas Huth 1999fcf5ef2aSThomas Huth save_state(dc); 2000fcf5ef2aSThomas Huth /* According to the table in the UA2011 manual, the only 2001fcf5ef2aSThomas Huth other asis that are valid for ldfa/lddfa/ldqfa are 2002fcf5ef2aSThomas Huth the NO_FAULT asis. We still need a helper for these, 2003fcf5ef2aSThomas Huth but we can just use the integer asi helper for them. */ 2004fcf5ef2aSThomas Huth switch (size) { 20053259b9e2SRichard Henderson case MO_32: 2006fcf5ef2aSThomas Huth d64 = tcg_temp_new_i64(); 2007ad75a51eSRichard Henderson gen_helper_ld_asi(d64, tcg_env, addr, r_asi, r_mop); 2008388a6465SRichard Henderson d32 = tcg_temp_new_i32(); 2009fcf5ef2aSThomas Huth tcg_gen_extrl_i64_i32(d32, d64); 2010fcf5ef2aSThomas Huth gen_store_fpr_F(dc, rd, d32); 2011fcf5ef2aSThomas Huth break; 20123259b9e2SRichard Henderson case MO_64: 20131210a036SRichard Henderson d64 = tcg_temp_new_i64(); 20141210a036SRichard Henderson gen_helper_ld_asi(d64, tcg_env, addr, r_asi, r_mop); 20151210a036SRichard Henderson gen_store_fpr_D(dc, rd, d64); 2016fcf5ef2aSThomas Huth break; 20173259b9e2SRichard Henderson case MO_128: 2018fcf5ef2aSThomas Huth d64 = tcg_temp_new_i64(); 20191210a036SRichard Henderson l64 = tcg_temp_new_i64(); 2020ad75a51eSRichard Henderson gen_helper_ld_asi(d64, tcg_env, addr, r_asi, r_mop); 2021287b1152SRichard Henderson addr_tmp = tcg_temp_new(); 2022287b1152SRichard Henderson tcg_gen_addi_tl(addr_tmp, addr, 8); 20231210a036SRichard Henderson gen_helper_ld_asi(l64, tcg_env, addr_tmp, r_asi, r_mop); 20241210a036SRichard Henderson gen_store_fpr_D(dc, rd, d64); 20251210a036SRichard Henderson gen_store_fpr_D(dc, rd + 2, l64); 2026fcf5ef2aSThomas Huth break; 2027fcf5ef2aSThomas Huth default: 2028fcf5ef2aSThomas Huth g_assert_not_reached(); 2029fcf5ef2aSThomas Huth } 2030fcf5ef2aSThomas Huth } 2031fcf5ef2aSThomas Huth break; 2032fcf5ef2aSThomas Huth } 2033fcf5ef2aSThomas Huth } 2034fcf5ef2aSThomas Huth 2035287b1152SRichard Henderson static void gen_stf_asi(DisasContext *dc, DisasASI *da, MemOp orig_size, 20363259b9e2SRichard Henderson TCGv addr, int rd) 20373259b9e2SRichard Henderson { 20383259b9e2SRichard Henderson MemOp memop = da->memop; 20393259b9e2SRichard Henderson MemOp size = memop & MO_SIZE; 2040fcf5ef2aSThomas Huth TCGv_i32 d32; 20411210a036SRichard Henderson TCGv_i64 d64; 2042287b1152SRichard Henderson TCGv addr_tmp; 2043fcf5ef2aSThomas Huth 20443259b9e2SRichard Henderson /* TODO: Use 128-bit load/store below. */ 20453259b9e2SRichard Henderson if (size == MO_128) { 20463259b9e2SRichard Henderson memop = (memop & ~MO_SIZE) | MO_64; 20473259b9e2SRichard Henderson } 20483259b9e2SRichard Henderson 20493259b9e2SRichard Henderson switch (da->type) { 2050fcf5ef2aSThomas Huth case GET_ASI_EXCP: 2051fcf5ef2aSThomas Huth break; 2052fcf5ef2aSThomas Huth 2053fcf5ef2aSThomas Huth case GET_ASI_DIRECT: 20543259b9e2SRichard Henderson memop |= MO_ALIGN_4; 2055fcf5ef2aSThomas Huth switch (size) { 20563259b9e2SRichard Henderson case MO_32: 2057fcf5ef2aSThomas Huth d32 = gen_load_fpr_F(dc, rd); 20583259b9e2SRichard Henderson tcg_gen_qemu_st_i32(d32, addr, da->mem_idx, memop | MO_ALIGN); 2059fcf5ef2aSThomas Huth break; 20603259b9e2SRichard Henderson case MO_64: 20611210a036SRichard Henderson d64 = gen_load_fpr_D(dc, rd); 20621210a036SRichard Henderson tcg_gen_qemu_st_i64(d64, addr, da->mem_idx, memop | MO_ALIGN_4); 2063fcf5ef2aSThomas Huth break; 20643259b9e2SRichard Henderson case MO_128: 2065fcf5ef2aSThomas Huth /* Only 4-byte alignment required. However, it is legal for the 2066fcf5ef2aSThomas Huth cpu to signal the alignment fault, and the OS trap handler is 2067fcf5ef2aSThomas Huth required to fix it up. Requiring 16-byte alignment here avoids 2068fcf5ef2aSThomas Huth having to probe the second page before performing the first 2069fcf5ef2aSThomas Huth write. */ 20701210a036SRichard Henderson d64 = gen_load_fpr_D(dc, rd); 20711210a036SRichard Henderson tcg_gen_qemu_st_i64(d64, addr, da->mem_idx, memop | MO_ALIGN_16); 2072287b1152SRichard Henderson addr_tmp = tcg_temp_new(); 2073287b1152SRichard Henderson tcg_gen_addi_tl(addr_tmp, addr, 8); 20741210a036SRichard Henderson d64 = gen_load_fpr_D(dc, rd + 2); 20751210a036SRichard Henderson tcg_gen_qemu_st_i64(d64, addr_tmp, da->mem_idx, memop); 2076fcf5ef2aSThomas Huth break; 2077fcf5ef2aSThomas Huth default: 2078fcf5ef2aSThomas Huth g_assert_not_reached(); 2079fcf5ef2aSThomas Huth } 2080fcf5ef2aSThomas Huth break; 2081fcf5ef2aSThomas Huth 2082fcf5ef2aSThomas Huth case GET_ASI_BLOCK: 2083fcf5ef2aSThomas Huth /* Valid for stdfa on aligned registers only. */ 20843259b9e2SRichard Henderson if (orig_size == MO_64 && (rd & 7) == 0) { 2085fcf5ef2aSThomas Huth /* The first operation checks required alignment. */ 2086287b1152SRichard Henderson addr_tmp = tcg_temp_new(); 2087287b1152SRichard Henderson for (int i = 0; ; ++i) { 20881210a036SRichard Henderson d64 = gen_load_fpr_D(dc, rd + 2 * i); 20891210a036SRichard Henderson tcg_gen_qemu_st_i64(d64, addr, da->mem_idx, 20903259b9e2SRichard Henderson memop | (i == 0 ? MO_ALIGN_64 : 0)); 2091fcf5ef2aSThomas Huth if (i == 7) { 2092fcf5ef2aSThomas Huth break; 2093fcf5ef2aSThomas Huth } 2094287b1152SRichard Henderson tcg_gen_addi_tl(addr_tmp, addr, 8); 2095287b1152SRichard Henderson addr = addr_tmp; 2096fcf5ef2aSThomas Huth } 2097fcf5ef2aSThomas Huth } else { 2098fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 2099fcf5ef2aSThomas Huth } 2100fcf5ef2aSThomas Huth break; 2101fcf5ef2aSThomas Huth 2102fcf5ef2aSThomas Huth case GET_ASI_SHORT: 2103fcf5ef2aSThomas Huth /* Valid for stdfa only. */ 21043259b9e2SRichard Henderson if (orig_size == MO_64) { 21051210a036SRichard Henderson d64 = gen_load_fpr_D(dc, rd); 21061210a036SRichard Henderson tcg_gen_qemu_st_i64(d64, addr, da->mem_idx, memop | MO_ALIGN); 2107fcf5ef2aSThomas Huth } else { 2108fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 2109fcf5ef2aSThomas Huth } 2110fcf5ef2aSThomas Huth break; 2111fcf5ef2aSThomas Huth 2112fcf5ef2aSThomas Huth default: 2113fcf5ef2aSThomas Huth /* According to the table in the UA2011 manual, the only 2114fcf5ef2aSThomas Huth other asis that are valid for ldfa/lddfa/ldqfa are 2115fcf5ef2aSThomas Huth the PST* asis, which aren't currently handled. */ 2116fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 2117fcf5ef2aSThomas Huth break; 2118fcf5ef2aSThomas Huth } 2119fcf5ef2aSThomas Huth } 2120fcf5ef2aSThomas Huth 212142071fc1SRichard Henderson static void gen_ldda_asi(DisasContext *dc, DisasASI *da, TCGv addr, int rd) 2122fcf5ef2aSThomas Huth { 2123a76779eeSRichard Henderson TCGv hi = gen_dest_gpr(dc, rd); 2124a76779eeSRichard Henderson TCGv lo = gen_dest_gpr(dc, rd + 1); 2125fcf5ef2aSThomas Huth 2126c03a0fd1SRichard Henderson switch (da->type) { 2127fcf5ef2aSThomas Huth case GET_ASI_EXCP: 2128fcf5ef2aSThomas Huth return; 2129fcf5ef2aSThomas Huth 2130fcf5ef2aSThomas Huth case GET_ASI_DTWINX: 2131ebbbec92SRichard Henderson #ifdef TARGET_SPARC64 2132ebbbec92SRichard Henderson { 2133ebbbec92SRichard Henderson MemOp mop = (da->memop & MO_BSWAP) | MO_128 | MO_ALIGN_16; 2134ebbbec92SRichard Henderson TCGv_i128 t = tcg_temp_new_i128(); 2135ebbbec92SRichard Henderson 2136ebbbec92SRichard Henderson tcg_gen_qemu_ld_i128(t, addr, da->mem_idx, mop); 2137ebbbec92SRichard Henderson /* 2138ebbbec92SRichard Henderson * Note that LE twinx acts as if each 64-bit register result is 2139ebbbec92SRichard Henderson * byte swapped. We perform one 128-bit LE load, so must swap 2140ebbbec92SRichard Henderson * the order of the writebacks. 2141ebbbec92SRichard Henderson */ 2142ebbbec92SRichard Henderson if ((mop & MO_BSWAP) == MO_TE) { 2143ebbbec92SRichard Henderson tcg_gen_extr_i128_i64(lo, hi, t); 2144ebbbec92SRichard Henderson } else { 2145ebbbec92SRichard Henderson tcg_gen_extr_i128_i64(hi, lo, t); 2146ebbbec92SRichard Henderson } 2147ebbbec92SRichard Henderson } 2148fcf5ef2aSThomas Huth break; 2149ebbbec92SRichard Henderson #else 2150ebbbec92SRichard Henderson g_assert_not_reached(); 2151ebbbec92SRichard Henderson #endif 2152fcf5ef2aSThomas Huth 2153fcf5ef2aSThomas Huth case GET_ASI_DIRECT: 2154fcf5ef2aSThomas Huth { 2155fcf5ef2aSThomas Huth TCGv_i64 tmp = tcg_temp_new_i64(); 2156fcf5ef2aSThomas Huth 2157c03a0fd1SRichard Henderson tcg_gen_qemu_ld_i64(tmp, addr, da->mem_idx, da->memop | MO_ALIGN); 2158fcf5ef2aSThomas Huth 2159fcf5ef2aSThomas Huth /* Note that LE ldda acts as if each 32-bit register 2160fcf5ef2aSThomas Huth result is byte swapped. Having just performed one 2161fcf5ef2aSThomas Huth 64-bit bswap, we need now to swap the writebacks. */ 2162c03a0fd1SRichard Henderson if ((da->memop & MO_BSWAP) == MO_TE) { 2163a76779eeSRichard Henderson tcg_gen_extr_i64_tl(lo, hi, tmp); 2164fcf5ef2aSThomas Huth } else { 2165a76779eeSRichard Henderson tcg_gen_extr_i64_tl(hi, lo, tmp); 2166fcf5ef2aSThomas Huth } 2167fcf5ef2aSThomas Huth } 2168fcf5ef2aSThomas Huth break; 2169fcf5ef2aSThomas Huth 21702786a3f8SRichard Henderson case GET_ASI_CODE: 21712786a3f8SRichard Henderson #if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64) 21722786a3f8SRichard Henderson { 21732786a3f8SRichard Henderson MemOpIdx oi = make_memop_idx(da->memop, da->mem_idx); 21742786a3f8SRichard Henderson TCGv_i64 tmp = tcg_temp_new_i64(); 21752786a3f8SRichard Henderson 21762786a3f8SRichard Henderson gen_helper_ld_code(tmp, tcg_env, addr, tcg_constant_i32(oi)); 21772786a3f8SRichard Henderson 21782786a3f8SRichard Henderson /* See above. */ 21792786a3f8SRichard Henderson if ((da->memop & MO_BSWAP) == MO_TE) { 21802786a3f8SRichard Henderson tcg_gen_extr_i64_tl(lo, hi, tmp); 21812786a3f8SRichard Henderson } else { 21822786a3f8SRichard Henderson tcg_gen_extr_i64_tl(hi, lo, tmp); 21832786a3f8SRichard Henderson } 21842786a3f8SRichard Henderson } 21852786a3f8SRichard Henderson break; 21862786a3f8SRichard Henderson #else 21872786a3f8SRichard Henderson g_assert_not_reached(); 21882786a3f8SRichard Henderson #endif 21892786a3f8SRichard Henderson 2190fcf5ef2aSThomas Huth default: 2191fcf5ef2aSThomas Huth /* ??? In theory we've handled all of the ASIs that are valid 2192fcf5ef2aSThomas Huth for ldda, and this should raise DAE_invalid_asi. However, 2193fcf5ef2aSThomas Huth real hardware allows others. This can be seen with e.g. 2194fcf5ef2aSThomas Huth FreeBSD 10.3 wrt ASI_IC_TAG. */ 2195fcf5ef2aSThomas Huth { 2196c03a0fd1SRichard Henderson TCGv_i32 r_asi = tcg_constant_i32(da->asi); 2197c03a0fd1SRichard Henderson TCGv_i32 r_mop = tcg_constant_i32(da->memop); 2198fcf5ef2aSThomas Huth TCGv_i64 tmp = tcg_temp_new_i64(); 2199fcf5ef2aSThomas Huth 2200fcf5ef2aSThomas Huth save_state(dc); 2201ad75a51eSRichard Henderson gen_helper_ld_asi(tmp, tcg_env, addr, r_asi, r_mop); 2202fcf5ef2aSThomas Huth 2203fcf5ef2aSThomas Huth /* See above. */ 2204c03a0fd1SRichard Henderson if ((da->memop & MO_BSWAP) == MO_TE) { 2205a76779eeSRichard Henderson tcg_gen_extr_i64_tl(lo, hi, tmp); 2206fcf5ef2aSThomas Huth } else { 2207a76779eeSRichard Henderson tcg_gen_extr_i64_tl(hi, lo, tmp); 2208fcf5ef2aSThomas Huth } 2209fcf5ef2aSThomas Huth } 2210fcf5ef2aSThomas Huth break; 2211fcf5ef2aSThomas Huth } 2212fcf5ef2aSThomas Huth 2213fcf5ef2aSThomas Huth gen_store_gpr(dc, rd, hi); 2214fcf5ef2aSThomas Huth gen_store_gpr(dc, rd + 1, lo); 2215fcf5ef2aSThomas Huth } 2216fcf5ef2aSThomas Huth 221742071fc1SRichard Henderson static void gen_stda_asi(DisasContext *dc, DisasASI *da, TCGv addr, int rd) 2218c03a0fd1SRichard Henderson { 2219c03a0fd1SRichard Henderson TCGv hi = gen_load_gpr(dc, rd); 2220fcf5ef2aSThomas Huth TCGv lo = gen_load_gpr(dc, rd + 1); 2221fcf5ef2aSThomas Huth 2222c03a0fd1SRichard Henderson switch (da->type) { 2223fcf5ef2aSThomas Huth case GET_ASI_EXCP: 2224fcf5ef2aSThomas Huth break; 2225fcf5ef2aSThomas Huth 2226fcf5ef2aSThomas Huth case GET_ASI_DTWINX: 2227ebbbec92SRichard Henderson #ifdef TARGET_SPARC64 2228ebbbec92SRichard Henderson { 2229ebbbec92SRichard Henderson MemOp mop = (da->memop & MO_BSWAP) | MO_128 | MO_ALIGN_16; 2230ebbbec92SRichard Henderson TCGv_i128 t = tcg_temp_new_i128(); 2231ebbbec92SRichard Henderson 2232ebbbec92SRichard Henderson /* 2233ebbbec92SRichard Henderson * Note that LE twinx acts as if each 64-bit register result is 2234ebbbec92SRichard Henderson * byte swapped. We perform one 128-bit LE store, so must swap 2235ebbbec92SRichard Henderson * the order of the construction. 2236ebbbec92SRichard Henderson */ 2237ebbbec92SRichard Henderson if ((mop & MO_BSWAP) == MO_TE) { 2238ebbbec92SRichard Henderson tcg_gen_concat_i64_i128(t, lo, hi); 2239ebbbec92SRichard Henderson } else { 2240ebbbec92SRichard Henderson tcg_gen_concat_i64_i128(t, hi, lo); 2241ebbbec92SRichard Henderson } 2242ebbbec92SRichard Henderson tcg_gen_qemu_st_i128(t, addr, da->mem_idx, mop); 2243ebbbec92SRichard Henderson } 2244fcf5ef2aSThomas Huth break; 2245ebbbec92SRichard Henderson #else 2246ebbbec92SRichard Henderson g_assert_not_reached(); 2247ebbbec92SRichard Henderson #endif 2248fcf5ef2aSThomas Huth 2249fcf5ef2aSThomas Huth case GET_ASI_DIRECT: 2250fcf5ef2aSThomas Huth { 2251fcf5ef2aSThomas Huth TCGv_i64 t64 = tcg_temp_new_i64(); 2252fcf5ef2aSThomas Huth 2253fcf5ef2aSThomas Huth /* Note that LE stda acts as if each 32-bit register result is 2254fcf5ef2aSThomas Huth byte swapped. We will perform one 64-bit LE store, so now 2255fcf5ef2aSThomas Huth we must swap the order of the construction. */ 2256c03a0fd1SRichard Henderson if ((da->memop & MO_BSWAP) == MO_TE) { 2257a76779eeSRichard Henderson tcg_gen_concat_tl_i64(t64, lo, hi); 2258fcf5ef2aSThomas Huth } else { 2259a76779eeSRichard Henderson tcg_gen_concat_tl_i64(t64, hi, lo); 2260fcf5ef2aSThomas Huth } 2261c03a0fd1SRichard Henderson tcg_gen_qemu_st_i64(t64, addr, da->mem_idx, da->memop | MO_ALIGN); 2262fcf5ef2aSThomas Huth } 2263fcf5ef2aSThomas Huth break; 2264fcf5ef2aSThomas Huth 2265a76779eeSRichard Henderson case GET_ASI_BFILL: 2266a76779eeSRichard Henderson assert(TARGET_LONG_BITS == 32); 226754c3e953SRichard Henderson /* 226854c3e953SRichard Henderson * Store 32 bytes of [rd:rd+1] to ADDR. 226954c3e953SRichard Henderson * See comments for GET_ASI_COPY above. 227054c3e953SRichard Henderson */ 2271a76779eeSRichard Henderson { 227254c3e953SRichard Henderson MemOp mop = MO_TE | MO_128 | MO_ATOM_IFALIGN_PAIR; 227354c3e953SRichard Henderson TCGv_i64 t8 = tcg_temp_new_i64(); 227454c3e953SRichard Henderson TCGv_i128 t16 = tcg_temp_new_i128(); 227554c3e953SRichard Henderson TCGv daddr = tcg_temp_new(); 2276a76779eeSRichard Henderson 227754c3e953SRichard Henderson tcg_gen_concat_tl_i64(t8, lo, hi); 227854c3e953SRichard Henderson tcg_gen_concat_i64_i128(t16, t8, t8); 227954c3e953SRichard Henderson tcg_gen_andi_tl(daddr, addr, -32); 228054c3e953SRichard Henderson tcg_gen_qemu_st_i128(t16, daddr, da->mem_idx, mop); 228154c3e953SRichard Henderson tcg_gen_addi_tl(daddr, daddr, 16); 228254c3e953SRichard Henderson tcg_gen_qemu_st_i128(t16, daddr, da->mem_idx, mop); 2283a76779eeSRichard Henderson } 2284a76779eeSRichard Henderson break; 2285a76779eeSRichard Henderson 2286fcf5ef2aSThomas Huth default: 2287fcf5ef2aSThomas Huth /* ??? In theory we've handled all of the ASIs that are valid 2288fcf5ef2aSThomas Huth for stda, and this should raise DAE_invalid_asi. */ 2289fcf5ef2aSThomas Huth { 2290c03a0fd1SRichard Henderson TCGv_i32 r_asi = tcg_constant_i32(da->asi); 2291c03a0fd1SRichard Henderson TCGv_i32 r_mop = tcg_constant_i32(da->memop); 2292fcf5ef2aSThomas Huth TCGv_i64 t64 = tcg_temp_new_i64(); 2293fcf5ef2aSThomas Huth 2294fcf5ef2aSThomas Huth /* See above. */ 2295c03a0fd1SRichard Henderson if ((da->memop & MO_BSWAP) == MO_TE) { 2296a76779eeSRichard Henderson tcg_gen_concat_tl_i64(t64, lo, hi); 2297fcf5ef2aSThomas Huth } else { 2298a76779eeSRichard Henderson tcg_gen_concat_tl_i64(t64, hi, lo); 2299fcf5ef2aSThomas Huth } 2300fcf5ef2aSThomas Huth 2301fcf5ef2aSThomas Huth save_state(dc); 2302ad75a51eSRichard Henderson gen_helper_st_asi(tcg_env, addr, t64, r_asi, r_mop); 2303fcf5ef2aSThomas Huth } 2304fcf5ef2aSThomas Huth break; 2305fcf5ef2aSThomas Huth } 2306fcf5ef2aSThomas Huth } 2307fcf5ef2aSThomas Huth 2308fcf5ef2aSThomas Huth static void gen_fmovs(DisasContext *dc, DisasCompare *cmp, int rd, int rs) 2309fcf5ef2aSThomas Huth { 2310f7ec8155SRichard Henderson #ifdef TARGET_SPARC64 2311fcf5ef2aSThomas Huth TCGv_i32 c32, zero, dst, s1, s2; 2312dd7dbfccSRichard Henderson TCGv_i64 c64 = tcg_temp_new_i64(); 2313fcf5ef2aSThomas Huth 2314fcf5ef2aSThomas Huth /* We have two choices here: extend the 32 bit data and use movcond_i64, 2315fcf5ef2aSThomas Huth or fold the comparison down to 32 bits and use movcond_i32. Choose 2316fcf5ef2aSThomas Huth the later. */ 2317fcf5ef2aSThomas Huth c32 = tcg_temp_new_i32(); 2318c8507ebfSRichard Henderson tcg_gen_setcondi_i64(cmp->cond, c64, cmp->c1, cmp->c2); 2319fcf5ef2aSThomas Huth tcg_gen_extrl_i64_i32(c32, c64); 2320fcf5ef2aSThomas Huth 2321fcf5ef2aSThomas Huth s1 = gen_load_fpr_F(dc, rs); 2322fcf5ef2aSThomas Huth s2 = gen_load_fpr_F(dc, rd); 2323388a6465SRichard Henderson dst = tcg_temp_new_i32(); 232400ab7e61SRichard Henderson zero = tcg_constant_i32(0); 2325fcf5ef2aSThomas Huth 2326fcf5ef2aSThomas Huth tcg_gen_movcond_i32(TCG_COND_NE, dst, c32, zero, s1, s2); 2327fcf5ef2aSThomas Huth 2328fcf5ef2aSThomas Huth gen_store_fpr_F(dc, rd, dst); 2329f7ec8155SRichard Henderson #else 2330f7ec8155SRichard Henderson qemu_build_not_reached(); 2331f7ec8155SRichard Henderson #endif 2332fcf5ef2aSThomas Huth } 2333fcf5ef2aSThomas Huth 2334fcf5ef2aSThomas Huth static void gen_fmovd(DisasContext *dc, DisasCompare *cmp, int rd, int rs) 2335fcf5ef2aSThomas Huth { 2336f7ec8155SRichard Henderson #ifdef TARGET_SPARC64 233752f46d46SRichard Henderson TCGv_i64 dst = tcg_temp_new_i64(); 2338c8507ebfSRichard Henderson tcg_gen_movcond_i64(cmp->cond, dst, cmp->c1, tcg_constant_tl(cmp->c2), 2339fcf5ef2aSThomas Huth gen_load_fpr_D(dc, rs), 2340fcf5ef2aSThomas Huth gen_load_fpr_D(dc, rd)); 2341fcf5ef2aSThomas Huth gen_store_fpr_D(dc, rd, dst); 2342f7ec8155SRichard Henderson #else 2343f7ec8155SRichard Henderson qemu_build_not_reached(); 2344f7ec8155SRichard Henderson #endif 2345fcf5ef2aSThomas Huth } 2346fcf5ef2aSThomas Huth 2347fcf5ef2aSThomas Huth static void gen_fmovq(DisasContext *dc, DisasCompare *cmp, int rd, int rs) 2348fcf5ef2aSThomas Huth { 2349f7ec8155SRichard Henderson #ifdef TARGET_SPARC64 2350c8507ebfSRichard Henderson TCGv c2 = tcg_constant_tl(cmp->c2); 23511210a036SRichard Henderson TCGv_i64 h = tcg_temp_new_i64(); 23521210a036SRichard Henderson TCGv_i64 l = tcg_temp_new_i64(); 2353fcf5ef2aSThomas Huth 23541210a036SRichard Henderson tcg_gen_movcond_i64(cmp->cond, h, cmp->c1, c2, 23551210a036SRichard Henderson gen_load_fpr_D(dc, rs), 23561210a036SRichard Henderson gen_load_fpr_D(dc, rd)); 23571210a036SRichard Henderson tcg_gen_movcond_i64(cmp->cond, l, cmp->c1, c2, 23581210a036SRichard Henderson gen_load_fpr_D(dc, rs + 2), 23591210a036SRichard Henderson gen_load_fpr_D(dc, rd + 2)); 23601210a036SRichard Henderson gen_store_fpr_D(dc, rd, h); 23611210a036SRichard Henderson gen_store_fpr_D(dc, rd + 2, l); 2362f7ec8155SRichard Henderson #else 2363f7ec8155SRichard Henderson qemu_build_not_reached(); 2364f7ec8155SRichard Henderson #endif 2365fcf5ef2aSThomas Huth } 2366fcf5ef2aSThomas Huth 2367f7ec8155SRichard Henderson #ifdef TARGET_SPARC64 23685d617bfbSRichard Henderson static void gen_load_trap_state_at_tl(TCGv_ptr r_tsptr) 2369fcf5ef2aSThomas Huth { 2370fcf5ef2aSThomas Huth TCGv_i32 r_tl = tcg_temp_new_i32(); 2371fcf5ef2aSThomas Huth 2372fcf5ef2aSThomas Huth /* load env->tl into r_tl */ 2373ad75a51eSRichard Henderson tcg_gen_ld_i32(r_tl, tcg_env, offsetof(CPUSPARCState, tl)); 2374fcf5ef2aSThomas Huth 2375fcf5ef2aSThomas Huth /* tl = [0 ... MAXTL_MASK] where MAXTL_MASK must be power of 2 */ 2376fcf5ef2aSThomas Huth tcg_gen_andi_i32(r_tl, r_tl, MAXTL_MASK); 2377fcf5ef2aSThomas Huth 2378fcf5ef2aSThomas Huth /* calculate offset to current trap state from env->ts, reuse r_tl */ 2379fcf5ef2aSThomas Huth tcg_gen_muli_i32(r_tl, r_tl, sizeof (trap_state)); 2380ad75a51eSRichard Henderson tcg_gen_addi_ptr(r_tsptr, tcg_env, offsetof(CPUSPARCState, ts)); 2381fcf5ef2aSThomas Huth 2382fcf5ef2aSThomas Huth /* tsptr = env->ts[env->tl & MAXTL_MASK] */ 2383fcf5ef2aSThomas Huth { 2384fcf5ef2aSThomas Huth TCGv_ptr r_tl_tmp = tcg_temp_new_ptr(); 2385fcf5ef2aSThomas Huth tcg_gen_ext_i32_ptr(r_tl_tmp, r_tl); 2386fcf5ef2aSThomas Huth tcg_gen_add_ptr(r_tsptr, r_tsptr, r_tl_tmp); 2387fcf5ef2aSThomas Huth } 2388fcf5ef2aSThomas Huth } 2389fcf5ef2aSThomas Huth #endif 2390fcf5ef2aSThomas Huth 239106c060d9SRichard Henderson static int extract_dfpreg(DisasContext *dc, int x) 239206c060d9SRichard Henderson { 23930bba7572SRichard Henderson int r = x & 0x1e; 23940bba7572SRichard Henderson #ifdef TARGET_SPARC64 23950bba7572SRichard Henderson r |= (x & 1) << 5; 23960bba7572SRichard Henderson #endif 23970bba7572SRichard Henderson return r; 239806c060d9SRichard Henderson } 239906c060d9SRichard Henderson 240006c060d9SRichard Henderson static int extract_qfpreg(DisasContext *dc, int x) 240106c060d9SRichard Henderson { 24020bba7572SRichard Henderson int r = x & 0x1c; 24030bba7572SRichard Henderson #ifdef TARGET_SPARC64 24040bba7572SRichard Henderson r |= (x & 1) << 5; 24050bba7572SRichard Henderson #endif 24060bba7572SRichard Henderson return r; 240706c060d9SRichard Henderson } 240806c060d9SRichard Henderson 2409878cc677SRichard Henderson /* Include the auto-generated decoder. */ 2410878cc677SRichard Henderson #include "decode-insns.c.inc" 2411878cc677SRichard Henderson 2412878cc677SRichard Henderson #define TRANS(NAME, AVAIL, FUNC, ...) \ 2413878cc677SRichard Henderson static bool trans_##NAME(DisasContext *dc, arg_##NAME *a) \ 2414878cc677SRichard Henderson { return avail_##AVAIL(dc) && FUNC(dc, __VA_ARGS__); } 2415878cc677SRichard Henderson 2416878cc677SRichard Henderson #define avail_ALL(C) true 2417878cc677SRichard Henderson #ifdef TARGET_SPARC64 2418878cc677SRichard Henderson # define avail_32(C) false 2419af25071cSRichard Henderson # define avail_ASR17(C) false 2420d0a11d25SRichard Henderson # define avail_CASA(C) true 2421c2636853SRichard Henderson # define avail_DIV(C) true 2422b5372650SRichard Henderson # define avail_MUL(C) true 24230faef01bSRichard Henderson # define avail_POWERDOWN(C) false 2424878cc677SRichard Henderson # define avail_64(C) true 24254fd71d19SRichard Henderson # define avail_FMAF(C) ((C)->def->features & CPU_FEATURE_FMAF) 24265d617bfbSRichard Henderson # define avail_GL(C) ((C)->def->features & CPU_FEATURE_GL) 2427af25071cSRichard Henderson # define avail_HYPV(C) ((C)->def->features & CPU_FEATURE_HYPV) 242868a414e9SRichard Henderson # define avail_IMA(C) ((C)->def->features & CPU_FEATURE_IMA) 2429b88ce6f2SRichard Henderson # define avail_VIS1(C) ((C)->def->features & CPU_FEATURE_VIS1) 2430b88ce6f2SRichard Henderson # define avail_VIS2(C) ((C)->def->features & CPU_FEATURE_VIS2) 24313335a048SRichard Henderson # define avail_VIS3(C) ((C)->def->features & CPU_FEATURE_VIS3) 24323335a048SRichard Henderson # define avail_VIS3B(C) avail_VIS3(C) 2433*90b1433dSRichard Henderson # define avail_VIS4(C) ((C)->def->features & CPU_FEATURE_VIS4) 2434878cc677SRichard Henderson #else 2435878cc677SRichard Henderson # define avail_32(C) true 2436af25071cSRichard Henderson # define avail_ASR17(C) ((C)->def->features & CPU_FEATURE_ASR17) 2437d0a11d25SRichard Henderson # define avail_CASA(C) ((C)->def->features & CPU_FEATURE_CASA) 2438c2636853SRichard Henderson # define avail_DIV(C) ((C)->def->features & CPU_FEATURE_DIV) 2439b5372650SRichard Henderson # define avail_MUL(C) ((C)->def->features & CPU_FEATURE_MUL) 24400faef01bSRichard Henderson # define avail_POWERDOWN(C) ((C)->def->features & CPU_FEATURE_POWERDOWN) 2441878cc677SRichard Henderson # define avail_64(C) false 24424fd71d19SRichard Henderson # define avail_FMAF(C) false 24435d617bfbSRichard Henderson # define avail_GL(C) false 2444af25071cSRichard Henderson # define avail_HYPV(C) false 244568a414e9SRichard Henderson # define avail_IMA(C) false 2446b88ce6f2SRichard Henderson # define avail_VIS1(C) false 2447b88ce6f2SRichard Henderson # define avail_VIS2(C) false 24483335a048SRichard Henderson # define avail_VIS3(C) false 24493335a048SRichard Henderson # define avail_VIS3B(C) false 2450*90b1433dSRichard Henderson # define avail_VIS4(C) false 2451878cc677SRichard Henderson #endif 2452878cc677SRichard Henderson 2453878cc677SRichard Henderson /* Default case for non jump instructions. */ 2454878cc677SRichard Henderson static bool advance_pc(DisasContext *dc) 2455878cc677SRichard Henderson { 24564a8d145dSRichard Henderson TCGLabel *l1; 24574a8d145dSRichard Henderson 245889527e3aSRichard Henderson finishing_insn(dc); 245989527e3aSRichard Henderson 2460878cc677SRichard Henderson if (dc->npc & 3) { 2461878cc677SRichard Henderson switch (dc->npc) { 2462878cc677SRichard Henderson case DYNAMIC_PC: 2463878cc677SRichard Henderson case DYNAMIC_PC_LOOKUP: 2464878cc677SRichard Henderson dc->pc = dc->npc; 2465444d8b30SRichard Henderson tcg_gen_mov_tl(cpu_pc, cpu_npc); 2466444d8b30SRichard Henderson tcg_gen_addi_tl(cpu_npc, cpu_npc, 4); 2467878cc677SRichard Henderson break; 24684a8d145dSRichard Henderson 2469878cc677SRichard Henderson case JUMP_PC: 2470878cc677SRichard Henderson /* we can do a static jump */ 24714a8d145dSRichard Henderson l1 = gen_new_label(); 2472533f042fSRichard Henderson tcg_gen_brcondi_tl(dc->jump.cond, dc->jump.c1, dc->jump.c2, l1); 24734a8d145dSRichard Henderson 24744a8d145dSRichard Henderson /* jump not taken */ 24754a8d145dSRichard Henderson gen_goto_tb(dc, 1, dc->jump_pc[1], dc->jump_pc[1] + 4); 24764a8d145dSRichard Henderson 24774a8d145dSRichard Henderson /* jump taken */ 24784a8d145dSRichard Henderson gen_set_label(l1); 24794a8d145dSRichard Henderson gen_goto_tb(dc, 0, dc->jump_pc[0], dc->jump_pc[0] + 4); 24804a8d145dSRichard Henderson 2481878cc677SRichard Henderson dc->base.is_jmp = DISAS_NORETURN; 2482878cc677SRichard Henderson break; 24834a8d145dSRichard Henderson 2484878cc677SRichard Henderson default: 2485878cc677SRichard Henderson g_assert_not_reached(); 2486878cc677SRichard Henderson } 2487878cc677SRichard Henderson } else { 2488878cc677SRichard Henderson dc->pc = dc->npc; 2489878cc677SRichard Henderson dc->npc = dc->npc + 4; 2490878cc677SRichard Henderson } 2491878cc677SRichard Henderson return true; 2492878cc677SRichard Henderson } 2493878cc677SRichard Henderson 24946d2a0768SRichard Henderson /* 24956d2a0768SRichard Henderson * Major opcodes 00 and 01 -- branches, call, and sethi 24966d2a0768SRichard Henderson */ 24976d2a0768SRichard Henderson 24989d4e2bc7SRichard Henderson static bool advance_jump_cond(DisasContext *dc, DisasCompare *cmp, 24993951b7a8SRichard Henderson bool annul, int disp) 2500276567aaSRichard Henderson { 25013951b7a8SRichard Henderson target_ulong dest = address_mask_i(dc, dc->pc + disp * 4); 2502c76c8045SRichard Henderson target_ulong npc; 2503c76c8045SRichard Henderson 250489527e3aSRichard Henderson finishing_insn(dc); 250589527e3aSRichard Henderson 25062d9bb237SRichard Henderson if (cmp->cond == TCG_COND_ALWAYS) { 25072d9bb237SRichard Henderson if (annul) { 25082d9bb237SRichard Henderson dc->pc = dest; 25092d9bb237SRichard Henderson dc->npc = dest + 4; 25102d9bb237SRichard Henderson } else { 25112d9bb237SRichard Henderson gen_mov_pc_npc(dc); 25122d9bb237SRichard Henderson dc->npc = dest; 25132d9bb237SRichard Henderson } 25142d9bb237SRichard Henderson return true; 25152d9bb237SRichard Henderson } 25162d9bb237SRichard Henderson 25172d9bb237SRichard Henderson if (cmp->cond == TCG_COND_NEVER) { 25182d9bb237SRichard Henderson npc = dc->npc; 25192d9bb237SRichard Henderson if (npc & 3) { 25202d9bb237SRichard Henderson gen_mov_pc_npc(dc); 25212d9bb237SRichard Henderson if (annul) { 25222d9bb237SRichard Henderson tcg_gen_addi_tl(cpu_pc, cpu_pc, 4); 25232d9bb237SRichard Henderson } 25242d9bb237SRichard Henderson tcg_gen_addi_tl(cpu_npc, cpu_pc, 4); 25252d9bb237SRichard Henderson } else { 25262d9bb237SRichard Henderson dc->pc = npc + (annul ? 4 : 0); 25272d9bb237SRichard Henderson dc->npc = dc->pc + 4; 25282d9bb237SRichard Henderson } 25292d9bb237SRichard Henderson return true; 25302d9bb237SRichard Henderson } 25312d9bb237SRichard Henderson 2532c76c8045SRichard Henderson flush_cond(dc); 2533c76c8045SRichard Henderson npc = dc->npc; 25346b3e4cc6SRichard Henderson 2535276567aaSRichard Henderson if (annul) { 25366b3e4cc6SRichard Henderson TCGLabel *l1 = gen_new_label(); 25376b3e4cc6SRichard Henderson 2538c8507ebfSRichard Henderson tcg_gen_brcondi_tl(tcg_invert_cond(cmp->cond), cmp->c1, cmp->c2, l1); 25396b3e4cc6SRichard Henderson gen_goto_tb(dc, 0, npc, dest); 25406b3e4cc6SRichard Henderson gen_set_label(l1); 25416b3e4cc6SRichard Henderson gen_goto_tb(dc, 1, npc + 4, npc + 8); 25426b3e4cc6SRichard Henderson 25436b3e4cc6SRichard Henderson dc->base.is_jmp = DISAS_NORETURN; 2544276567aaSRichard Henderson } else { 25456b3e4cc6SRichard Henderson if (npc & 3) { 25466b3e4cc6SRichard Henderson switch (npc) { 25476b3e4cc6SRichard Henderson case DYNAMIC_PC: 25486b3e4cc6SRichard Henderson case DYNAMIC_PC_LOOKUP: 25496b3e4cc6SRichard Henderson tcg_gen_mov_tl(cpu_pc, cpu_npc); 25506b3e4cc6SRichard Henderson tcg_gen_addi_tl(cpu_npc, cpu_npc, 4); 25519d4e2bc7SRichard Henderson tcg_gen_movcond_tl(cmp->cond, cpu_npc, 2552c8507ebfSRichard Henderson cmp->c1, tcg_constant_tl(cmp->c2), 25536b3e4cc6SRichard Henderson tcg_constant_tl(dest), cpu_npc); 25546b3e4cc6SRichard Henderson dc->pc = npc; 25556b3e4cc6SRichard Henderson break; 25566b3e4cc6SRichard Henderson default: 25576b3e4cc6SRichard Henderson g_assert_not_reached(); 25586b3e4cc6SRichard Henderson } 25596b3e4cc6SRichard Henderson } else { 25606b3e4cc6SRichard Henderson dc->pc = npc; 2561533f042fSRichard Henderson dc->npc = JUMP_PC; 2562533f042fSRichard Henderson dc->jump = *cmp; 25636b3e4cc6SRichard Henderson dc->jump_pc[0] = dest; 25646b3e4cc6SRichard Henderson dc->jump_pc[1] = npc + 4; 2565dd7dbfccSRichard Henderson 2566dd7dbfccSRichard Henderson /* The condition for cpu_cond is always NE -- normalize. */ 2567dd7dbfccSRichard Henderson if (cmp->cond == TCG_COND_NE) { 2568c8507ebfSRichard Henderson tcg_gen_xori_tl(cpu_cond, cmp->c1, cmp->c2); 25699d4e2bc7SRichard Henderson } else { 2570c8507ebfSRichard Henderson tcg_gen_setcondi_tl(cmp->cond, cpu_cond, cmp->c1, cmp->c2); 25719d4e2bc7SRichard Henderson } 257289527e3aSRichard Henderson dc->cpu_cond_live = true; 25736b3e4cc6SRichard Henderson } 2574276567aaSRichard Henderson } 2575276567aaSRichard Henderson return true; 2576276567aaSRichard Henderson } 2577276567aaSRichard Henderson 2578af25071cSRichard Henderson static bool raise_priv(DisasContext *dc) 2579af25071cSRichard Henderson { 2580af25071cSRichard Henderson gen_exception(dc, TT_PRIV_INSN); 2581af25071cSRichard Henderson return true; 2582af25071cSRichard Henderson } 2583af25071cSRichard Henderson 258406c060d9SRichard Henderson static bool raise_unimpfpop(DisasContext *dc) 258506c060d9SRichard Henderson { 258606c060d9SRichard Henderson gen_op_fpexception_im(dc, FSR_FTT_UNIMPFPOP); 258706c060d9SRichard Henderson return true; 258806c060d9SRichard Henderson } 258906c060d9SRichard Henderson 259006c060d9SRichard Henderson static bool gen_trap_float128(DisasContext *dc) 259106c060d9SRichard Henderson { 259206c060d9SRichard Henderson if (dc->def->features & CPU_FEATURE_FLOAT128) { 259306c060d9SRichard Henderson return false; 259406c060d9SRichard Henderson } 259506c060d9SRichard Henderson return raise_unimpfpop(dc); 259606c060d9SRichard Henderson } 259706c060d9SRichard Henderson 2598276567aaSRichard Henderson static bool do_bpcc(DisasContext *dc, arg_bcc *a) 2599276567aaSRichard Henderson { 26001ea9c62aSRichard Henderson DisasCompare cmp; 2601276567aaSRichard Henderson 26021ea9c62aSRichard Henderson gen_compare(&cmp, a->cc, a->cond, dc); 26033951b7a8SRichard Henderson return advance_jump_cond(dc, &cmp, a->a, a->i); 2604276567aaSRichard Henderson } 2605276567aaSRichard Henderson 2606276567aaSRichard Henderson TRANS(Bicc, ALL, do_bpcc, a) 2607276567aaSRichard Henderson TRANS(BPcc, 64, do_bpcc, a) 2608276567aaSRichard Henderson 260945196ea4SRichard Henderson static bool do_fbpfcc(DisasContext *dc, arg_bcc *a) 261045196ea4SRichard Henderson { 2611d5471936SRichard Henderson DisasCompare cmp; 261245196ea4SRichard Henderson 261345196ea4SRichard Henderson if (gen_trap_ifnofpu(dc)) { 261445196ea4SRichard Henderson return true; 261545196ea4SRichard Henderson } 2616d5471936SRichard Henderson gen_fcompare(&cmp, a->cc, a->cond); 26173951b7a8SRichard Henderson return advance_jump_cond(dc, &cmp, a->a, a->i); 261845196ea4SRichard Henderson } 261945196ea4SRichard Henderson 262045196ea4SRichard Henderson TRANS(FBPfcc, 64, do_fbpfcc, a) 262145196ea4SRichard Henderson TRANS(FBfcc, ALL, do_fbpfcc, a) 262245196ea4SRichard Henderson 2623ab9ffe98SRichard Henderson static bool trans_BPr(DisasContext *dc, arg_BPr *a) 2624ab9ffe98SRichard Henderson { 2625ab9ffe98SRichard Henderson DisasCompare cmp; 2626ab9ffe98SRichard Henderson 2627ab9ffe98SRichard Henderson if (!avail_64(dc)) { 2628ab9ffe98SRichard Henderson return false; 2629ab9ffe98SRichard Henderson } 26302c4f56c9SRichard Henderson if (!gen_compare_reg(&cmp, a->cond, gen_load_gpr(dc, a->rs1))) { 2631ab9ffe98SRichard Henderson return false; 2632ab9ffe98SRichard Henderson } 26333951b7a8SRichard Henderson return advance_jump_cond(dc, &cmp, a->a, a->i); 2634ab9ffe98SRichard Henderson } 2635ab9ffe98SRichard Henderson 263623ada1b1SRichard Henderson static bool trans_CALL(DisasContext *dc, arg_CALL *a) 263723ada1b1SRichard Henderson { 263823ada1b1SRichard Henderson target_long target = address_mask_i(dc, dc->pc + a->i * 4); 263923ada1b1SRichard Henderson 264023ada1b1SRichard Henderson gen_store_gpr(dc, 15, tcg_constant_tl(dc->pc)); 264123ada1b1SRichard Henderson gen_mov_pc_npc(dc); 264223ada1b1SRichard Henderson dc->npc = target; 264323ada1b1SRichard Henderson return true; 264423ada1b1SRichard Henderson } 264523ada1b1SRichard Henderson 264645196ea4SRichard Henderson static bool trans_NCP(DisasContext *dc, arg_NCP *a) 264745196ea4SRichard Henderson { 264845196ea4SRichard Henderson /* 264945196ea4SRichard Henderson * For sparc32, always generate the no-coprocessor exception. 265045196ea4SRichard Henderson * For sparc64, always generate illegal instruction. 265145196ea4SRichard Henderson */ 265245196ea4SRichard Henderson #ifdef TARGET_SPARC64 265345196ea4SRichard Henderson return false; 265445196ea4SRichard Henderson #else 265545196ea4SRichard Henderson gen_exception(dc, TT_NCP_INSN); 265645196ea4SRichard Henderson return true; 265745196ea4SRichard Henderson #endif 265845196ea4SRichard Henderson } 265945196ea4SRichard Henderson 26606d2a0768SRichard Henderson static bool trans_SETHI(DisasContext *dc, arg_SETHI *a) 26616d2a0768SRichard Henderson { 26626d2a0768SRichard Henderson /* Special-case %g0 because that's the canonical nop. */ 26636d2a0768SRichard Henderson if (a->rd) { 26646d2a0768SRichard Henderson gen_store_gpr(dc, a->rd, tcg_constant_tl((uint32_t)a->i << 10)); 26656d2a0768SRichard Henderson } 26666d2a0768SRichard Henderson return advance_pc(dc); 26676d2a0768SRichard Henderson } 26686d2a0768SRichard Henderson 26690faef01bSRichard Henderson /* 26700faef01bSRichard Henderson * Major Opcode 10 -- integer, floating-point, vis, and system insns. 26710faef01bSRichard Henderson */ 26720faef01bSRichard Henderson 267330376636SRichard Henderson static bool do_tcc(DisasContext *dc, int cond, int cc, 267430376636SRichard Henderson int rs1, bool imm, int rs2_or_imm) 267530376636SRichard Henderson { 267630376636SRichard Henderson int mask = ((dc->def->features & CPU_FEATURE_HYPV) && supervisor(dc) 267730376636SRichard Henderson ? UA2005_HTRAP_MASK : V8_TRAP_MASK); 267830376636SRichard Henderson DisasCompare cmp; 267930376636SRichard Henderson TCGLabel *lab; 268030376636SRichard Henderson TCGv_i32 trap; 268130376636SRichard Henderson 268230376636SRichard Henderson /* Trap never. */ 268330376636SRichard Henderson if (cond == 0) { 268430376636SRichard Henderson return advance_pc(dc); 268530376636SRichard Henderson } 268630376636SRichard Henderson 268730376636SRichard Henderson /* 268830376636SRichard Henderson * Immediate traps are the most common case. Since this value is 268930376636SRichard Henderson * live across the branch, it really pays to evaluate the constant. 269030376636SRichard Henderson */ 269130376636SRichard Henderson if (rs1 == 0 && (imm || rs2_or_imm == 0)) { 269230376636SRichard Henderson trap = tcg_constant_i32((rs2_or_imm & mask) + TT_TRAP); 269330376636SRichard Henderson } else { 269430376636SRichard Henderson trap = tcg_temp_new_i32(); 269530376636SRichard Henderson tcg_gen_trunc_tl_i32(trap, gen_load_gpr(dc, rs1)); 269630376636SRichard Henderson if (imm) { 269730376636SRichard Henderson tcg_gen_addi_i32(trap, trap, rs2_or_imm); 269830376636SRichard Henderson } else { 269930376636SRichard Henderson TCGv_i32 t2 = tcg_temp_new_i32(); 270030376636SRichard Henderson tcg_gen_trunc_tl_i32(t2, gen_load_gpr(dc, rs2_or_imm)); 270130376636SRichard Henderson tcg_gen_add_i32(trap, trap, t2); 270230376636SRichard Henderson } 270330376636SRichard Henderson tcg_gen_andi_i32(trap, trap, mask); 270430376636SRichard Henderson tcg_gen_addi_i32(trap, trap, TT_TRAP); 270530376636SRichard Henderson } 270630376636SRichard Henderson 270789527e3aSRichard Henderson finishing_insn(dc); 270889527e3aSRichard Henderson 270930376636SRichard Henderson /* Trap always. */ 271030376636SRichard Henderson if (cond == 8) { 271130376636SRichard Henderson save_state(dc); 271230376636SRichard Henderson gen_helper_raise_exception(tcg_env, trap); 271330376636SRichard Henderson dc->base.is_jmp = DISAS_NORETURN; 271430376636SRichard Henderson return true; 271530376636SRichard Henderson } 271630376636SRichard Henderson 271730376636SRichard Henderson /* Conditional trap. */ 271830376636SRichard Henderson flush_cond(dc); 271930376636SRichard Henderson lab = delay_exceptionv(dc, trap); 272030376636SRichard Henderson gen_compare(&cmp, cc, cond, dc); 2721c8507ebfSRichard Henderson tcg_gen_brcondi_tl(cmp.cond, cmp.c1, cmp.c2, lab); 272230376636SRichard Henderson 272330376636SRichard Henderson return advance_pc(dc); 272430376636SRichard Henderson } 272530376636SRichard Henderson 272630376636SRichard Henderson static bool trans_Tcc_r(DisasContext *dc, arg_Tcc_r *a) 272730376636SRichard Henderson { 272830376636SRichard Henderson if (avail_32(dc) && a->cc) { 272930376636SRichard Henderson return false; 273030376636SRichard Henderson } 273130376636SRichard Henderson return do_tcc(dc, a->cond, a->cc, a->rs1, false, a->rs2); 273230376636SRichard Henderson } 273330376636SRichard Henderson 273430376636SRichard Henderson static bool trans_Tcc_i_v7(DisasContext *dc, arg_Tcc_i_v7 *a) 273530376636SRichard Henderson { 273630376636SRichard Henderson if (avail_64(dc)) { 273730376636SRichard Henderson return false; 273830376636SRichard Henderson } 273930376636SRichard Henderson return do_tcc(dc, a->cond, 0, a->rs1, true, a->i); 274030376636SRichard Henderson } 274130376636SRichard Henderson 274230376636SRichard Henderson static bool trans_Tcc_i_v9(DisasContext *dc, arg_Tcc_i_v9 *a) 274330376636SRichard Henderson { 274430376636SRichard Henderson if (avail_32(dc)) { 274530376636SRichard Henderson return false; 274630376636SRichard Henderson } 274730376636SRichard Henderson return do_tcc(dc, a->cond, a->cc, a->rs1, true, a->i); 274830376636SRichard Henderson } 274930376636SRichard Henderson 2750af25071cSRichard Henderson static bool trans_STBAR(DisasContext *dc, arg_STBAR *a) 2751af25071cSRichard Henderson { 2752af25071cSRichard Henderson tcg_gen_mb(TCG_MO_ST_ST | TCG_BAR_SC); 2753af25071cSRichard Henderson return advance_pc(dc); 2754af25071cSRichard Henderson } 2755af25071cSRichard Henderson 2756af25071cSRichard Henderson static bool trans_MEMBAR(DisasContext *dc, arg_MEMBAR *a) 2757af25071cSRichard Henderson { 2758af25071cSRichard Henderson if (avail_32(dc)) { 2759af25071cSRichard Henderson return false; 2760af25071cSRichard Henderson } 2761af25071cSRichard Henderson if (a->mmask) { 2762af25071cSRichard Henderson /* Note TCG_MO_* was modeled on sparc64, so mmask matches. */ 2763af25071cSRichard Henderson tcg_gen_mb(a->mmask | TCG_BAR_SC); 2764af25071cSRichard Henderson } 2765af25071cSRichard Henderson if (a->cmask) { 2766af25071cSRichard Henderson /* For #Sync, etc, end the TB to recognize interrupts. */ 2767af25071cSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 2768af25071cSRichard Henderson } 2769af25071cSRichard Henderson return advance_pc(dc); 2770af25071cSRichard Henderson } 2771af25071cSRichard Henderson 2772af25071cSRichard Henderson static bool do_rd_special(DisasContext *dc, bool priv, int rd, 2773af25071cSRichard Henderson TCGv (*func)(DisasContext *, TCGv)) 2774af25071cSRichard Henderson { 2775af25071cSRichard Henderson if (!priv) { 2776af25071cSRichard Henderson return raise_priv(dc); 2777af25071cSRichard Henderson } 2778af25071cSRichard Henderson gen_store_gpr(dc, rd, func(dc, gen_dest_gpr(dc, rd))); 2779af25071cSRichard Henderson return advance_pc(dc); 2780af25071cSRichard Henderson } 2781af25071cSRichard Henderson 2782af25071cSRichard Henderson static TCGv do_rdy(DisasContext *dc, TCGv dst) 2783af25071cSRichard Henderson { 2784af25071cSRichard Henderson return cpu_y; 2785af25071cSRichard Henderson } 2786af25071cSRichard Henderson 2787af25071cSRichard Henderson static bool trans_RDY(DisasContext *dc, arg_RDY *a) 2788af25071cSRichard Henderson { 2789af25071cSRichard Henderson /* 2790af25071cSRichard Henderson * TODO: Need a feature bit for sparcv8. In the meantime, treat all 2791af25071cSRichard Henderson * 32-bit cpus like sparcv7, which ignores the rs1 field. 2792af25071cSRichard Henderson * This matches after all other ASR, so Leon3 Asr17 is handled first. 2793af25071cSRichard Henderson */ 2794af25071cSRichard Henderson if (avail_64(dc) && a->rs1 != 0) { 2795af25071cSRichard Henderson return false; 2796af25071cSRichard Henderson } 2797af25071cSRichard Henderson return do_rd_special(dc, true, a->rd, do_rdy); 2798af25071cSRichard Henderson } 2799af25071cSRichard Henderson 2800af25071cSRichard Henderson static TCGv do_rd_leon3_config(DisasContext *dc, TCGv dst) 2801af25071cSRichard Henderson { 2802c92948f2SClément Chigot gen_helper_rdasr17(dst, tcg_env); 2803c92948f2SClément Chigot return dst; 2804af25071cSRichard Henderson } 2805af25071cSRichard Henderson 2806af25071cSRichard Henderson TRANS(RDASR17, ASR17, do_rd_special, true, a->rd, do_rd_leon3_config) 2807af25071cSRichard Henderson 2808af25071cSRichard Henderson static TCGv do_rdccr(DisasContext *dc, TCGv dst) 2809af25071cSRichard Henderson { 2810af25071cSRichard Henderson gen_helper_rdccr(dst, tcg_env); 2811af25071cSRichard Henderson return dst; 2812af25071cSRichard Henderson } 2813af25071cSRichard Henderson 2814af25071cSRichard Henderson TRANS(RDCCR, 64, do_rd_special, true, a->rd, do_rdccr) 2815af25071cSRichard Henderson 2816af25071cSRichard Henderson static TCGv do_rdasi(DisasContext *dc, TCGv dst) 2817af25071cSRichard Henderson { 2818af25071cSRichard Henderson #ifdef TARGET_SPARC64 2819af25071cSRichard Henderson return tcg_constant_tl(dc->asi); 2820af25071cSRichard Henderson #else 2821af25071cSRichard Henderson qemu_build_not_reached(); 2822af25071cSRichard Henderson #endif 2823af25071cSRichard Henderson } 2824af25071cSRichard Henderson 2825af25071cSRichard Henderson TRANS(RDASI, 64, do_rd_special, true, a->rd, do_rdasi) 2826af25071cSRichard Henderson 2827af25071cSRichard Henderson static TCGv do_rdtick(DisasContext *dc, TCGv dst) 2828af25071cSRichard Henderson { 2829af25071cSRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr(); 2830af25071cSRichard Henderson 2831af25071cSRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(tick)); 2832af25071cSRichard Henderson if (translator_io_start(&dc->base)) { 2833af25071cSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 2834af25071cSRichard Henderson } 2835af25071cSRichard Henderson gen_helper_tick_get_count(dst, tcg_env, r_tickptr, 2836af25071cSRichard Henderson tcg_constant_i32(dc->mem_idx)); 2837af25071cSRichard Henderson return dst; 2838af25071cSRichard Henderson } 2839af25071cSRichard Henderson 2840af25071cSRichard Henderson /* TODO: non-priv access only allowed when enabled. */ 2841af25071cSRichard Henderson TRANS(RDTICK, 64, do_rd_special, true, a->rd, do_rdtick) 2842af25071cSRichard Henderson 2843af25071cSRichard Henderson static TCGv do_rdpc(DisasContext *dc, TCGv dst) 2844af25071cSRichard Henderson { 2845af25071cSRichard Henderson return tcg_constant_tl(address_mask_i(dc, dc->pc)); 2846af25071cSRichard Henderson } 2847af25071cSRichard Henderson 2848af25071cSRichard Henderson TRANS(RDPC, 64, do_rd_special, true, a->rd, do_rdpc) 2849af25071cSRichard Henderson 2850af25071cSRichard Henderson static TCGv do_rdfprs(DisasContext *dc, TCGv dst) 2851af25071cSRichard Henderson { 2852af25071cSRichard Henderson tcg_gen_ext_i32_tl(dst, cpu_fprs); 2853af25071cSRichard Henderson return dst; 2854af25071cSRichard Henderson } 2855af25071cSRichard Henderson 2856af25071cSRichard Henderson TRANS(RDFPRS, 64, do_rd_special, true, a->rd, do_rdfprs) 2857af25071cSRichard Henderson 2858af25071cSRichard Henderson static TCGv do_rdgsr(DisasContext *dc, TCGv dst) 2859af25071cSRichard Henderson { 2860af25071cSRichard Henderson gen_trap_ifnofpu(dc); 2861af25071cSRichard Henderson return cpu_gsr; 2862af25071cSRichard Henderson } 2863af25071cSRichard Henderson 2864af25071cSRichard Henderson TRANS(RDGSR, 64, do_rd_special, true, a->rd, do_rdgsr) 2865af25071cSRichard Henderson 2866af25071cSRichard Henderson static TCGv do_rdsoftint(DisasContext *dc, TCGv dst) 2867af25071cSRichard Henderson { 2868af25071cSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(softint)); 2869af25071cSRichard Henderson return dst; 2870af25071cSRichard Henderson } 2871af25071cSRichard Henderson 2872af25071cSRichard Henderson TRANS(RDSOFTINT, 64, do_rd_special, supervisor(dc), a->rd, do_rdsoftint) 2873af25071cSRichard Henderson 2874af25071cSRichard Henderson static TCGv do_rdtick_cmpr(DisasContext *dc, TCGv dst) 2875af25071cSRichard Henderson { 2876577efa45SRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(tick_cmpr)); 2877577efa45SRichard Henderson return dst; 2878af25071cSRichard Henderson } 2879af25071cSRichard Henderson 2880af25071cSRichard Henderson /* TODO: non-priv access only allowed when enabled. */ 2881af25071cSRichard Henderson TRANS(RDTICK_CMPR, 64, do_rd_special, true, a->rd, do_rdtick_cmpr) 2882af25071cSRichard Henderson 2883af25071cSRichard Henderson static TCGv do_rdstick(DisasContext *dc, TCGv dst) 2884af25071cSRichard Henderson { 2885af25071cSRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr(); 2886af25071cSRichard Henderson 2887af25071cSRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(stick)); 2888af25071cSRichard Henderson if (translator_io_start(&dc->base)) { 2889af25071cSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 2890af25071cSRichard Henderson } 2891af25071cSRichard Henderson gen_helper_tick_get_count(dst, tcg_env, r_tickptr, 2892af25071cSRichard Henderson tcg_constant_i32(dc->mem_idx)); 2893af25071cSRichard Henderson return dst; 2894af25071cSRichard Henderson } 2895af25071cSRichard Henderson 2896af25071cSRichard Henderson /* TODO: non-priv access only allowed when enabled. */ 2897af25071cSRichard Henderson TRANS(RDSTICK, 64, do_rd_special, true, a->rd, do_rdstick) 2898af25071cSRichard Henderson 2899af25071cSRichard Henderson static TCGv do_rdstick_cmpr(DisasContext *dc, TCGv dst) 2900af25071cSRichard Henderson { 2901577efa45SRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(stick_cmpr)); 2902577efa45SRichard Henderson return dst; 2903af25071cSRichard Henderson } 2904af25071cSRichard Henderson 2905af25071cSRichard Henderson /* TODO: supervisor access only allowed when enabled by hypervisor. */ 2906af25071cSRichard Henderson TRANS(RDSTICK_CMPR, 64, do_rd_special, supervisor(dc), a->rd, do_rdstick_cmpr) 2907af25071cSRichard Henderson 2908af25071cSRichard Henderson /* 2909af25071cSRichard Henderson * UltraSPARC-T1 Strand status. 2910af25071cSRichard Henderson * HYPV check maybe not enough, UA2005 & UA2007 describe 2911af25071cSRichard Henderson * this ASR as impl. dep 2912af25071cSRichard Henderson */ 2913af25071cSRichard Henderson static TCGv do_rdstrand_status(DisasContext *dc, TCGv dst) 2914af25071cSRichard Henderson { 2915af25071cSRichard Henderson return tcg_constant_tl(1); 2916af25071cSRichard Henderson } 2917af25071cSRichard Henderson 2918af25071cSRichard Henderson TRANS(RDSTRAND_STATUS, HYPV, do_rd_special, true, a->rd, do_rdstrand_status) 2919af25071cSRichard Henderson 2920668bb9b7SRichard Henderson static TCGv do_rdpsr(DisasContext *dc, TCGv dst) 2921668bb9b7SRichard Henderson { 2922668bb9b7SRichard Henderson gen_helper_rdpsr(dst, tcg_env); 2923668bb9b7SRichard Henderson return dst; 2924668bb9b7SRichard Henderson } 2925668bb9b7SRichard Henderson 2926668bb9b7SRichard Henderson TRANS(RDPSR, 32, do_rd_special, supervisor(dc), a->rd, do_rdpsr) 2927668bb9b7SRichard Henderson 2928668bb9b7SRichard Henderson static TCGv do_rdhpstate(DisasContext *dc, TCGv dst) 2929668bb9b7SRichard Henderson { 2930668bb9b7SRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hpstate)); 2931668bb9b7SRichard Henderson return dst; 2932668bb9b7SRichard Henderson } 2933668bb9b7SRichard Henderson 2934668bb9b7SRichard Henderson TRANS(RDHPR_hpstate, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhpstate) 2935668bb9b7SRichard Henderson 2936668bb9b7SRichard Henderson static TCGv do_rdhtstate(DisasContext *dc, TCGv dst) 2937668bb9b7SRichard Henderson { 2938668bb9b7SRichard Henderson TCGv_i32 tl = tcg_temp_new_i32(); 2939668bb9b7SRichard Henderson TCGv_ptr tp = tcg_temp_new_ptr(); 2940668bb9b7SRichard Henderson 2941668bb9b7SRichard Henderson tcg_gen_ld_i32(tl, tcg_env, env64_field_offsetof(tl)); 2942668bb9b7SRichard Henderson tcg_gen_andi_i32(tl, tl, MAXTL_MASK); 2943668bb9b7SRichard Henderson tcg_gen_shli_i32(tl, tl, 3); 2944668bb9b7SRichard Henderson tcg_gen_ext_i32_ptr(tp, tl); 2945668bb9b7SRichard Henderson tcg_gen_add_ptr(tp, tp, tcg_env); 2946668bb9b7SRichard Henderson 2947668bb9b7SRichard Henderson tcg_gen_ld_tl(dst, tp, env64_field_offsetof(htstate)); 2948668bb9b7SRichard Henderson return dst; 2949668bb9b7SRichard Henderson } 2950668bb9b7SRichard Henderson 2951668bb9b7SRichard Henderson TRANS(RDHPR_htstate, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhtstate) 2952668bb9b7SRichard Henderson 2953668bb9b7SRichard Henderson static TCGv do_rdhintp(DisasContext *dc, TCGv dst) 2954668bb9b7SRichard Henderson { 29552da789deSRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hintp)); 29562da789deSRichard Henderson return dst; 2957668bb9b7SRichard Henderson } 2958668bb9b7SRichard Henderson 2959668bb9b7SRichard Henderson TRANS(RDHPR_hintp, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhintp) 2960668bb9b7SRichard Henderson 2961668bb9b7SRichard Henderson static TCGv do_rdhtba(DisasContext *dc, TCGv dst) 2962668bb9b7SRichard Henderson { 29632da789deSRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(htba)); 29642da789deSRichard Henderson return dst; 2965668bb9b7SRichard Henderson } 2966668bb9b7SRichard Henderson 2967668bb9b7SRichard Henderson TRANS(RDHPR_htba, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhtba) 2968668bb9b7SRichard Henderson 2969668bb9b7SRichard Henderson static TCGv do_rdhver(DisasContext *dc, TCGv dst) 2970668bb9b7SRichard Henderson { 29712da789deSRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hver)); 29722da789deSRichard Henderson return dst; 2973668bb9b7SRichard Henderson } 2974668bb9b7SRichard Henderson 2975668bb9b7SRichard Henderson TRANS(RDHPR_hver, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhver) 2976668bb9b7SRichard Henderson 2977668bb9b7SRichard Henderson static TCGv do_rdhstick_cmpr(DisasContext *dc, TCGv dst) 2978668bb9b7SRichard Henderson { 2979577efa45SRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hstick_cmpr)); 2980577efa45SRichard Henderson return dst; 2981668bb9b7SRichard Henderson } 2982668bb9b7SRichard Henderson 2983668bb9b7SRichard Henderson TRANS(RDHPR_hstick_cmpr, HYPV, do_rd_special, hypervisor(dc), a->rd, 2984668bb9b7SRichard Henderson do_rdhstick_cmpr) 2985668bb9b7SRichard Henderson 29865d617bfbSRichard Henderson static TCGv do_rdwim(DisasContext *dc, TCGv dst) 29875d617bfbSRichard Henderson { 2988cd6269f7SRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env32_field_offsetof(wim)); 2989cd6269f7SRichard Henderson return dst; 29905d617bfbSRichard Henderson } 29915d617bfbSRichard Henderson 29925d617bfbSRichard Henderson TRANS(RDWIM, 32, do_rd_special, supervisor(dc), a->rd, do_rdwim) 29935d617bfbSRichard Henderson 29945d617bfbSRichard Henderson static TCGv do_rdtpc(DisasContext *dc, TCGv dst) 29955d617bfbSRichard Henderson { 29965d617bfbSRichard Henderson #ifdef TARGET_SPARC64 29975d617bfbSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 29985d617bfbSRichard Henderson 29995d617bfbSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 30005d617bfbSRichard Henderson tcg_gen_ld_tl(dst, r_tsptr, offsetof(trap_state, tpc)); 30015d617bfbSRichard Henderson return dst; 30025d617bfbSRichard Henderson #else 30035d617bfbSRichard Henderson qemu_build_not_reached(); 30045d617bfbSRichard Henderson #endif 30055d617bfbSRichard Henderson } 30065d617bfbSRichard Henderson 30075d617bfbSRichard Henderson TRANS(RDPR_tpc, 64, do_rd_special, supervisor(dc), a->rd, do_rdtpc) 30085d617bfbSRichard Henderson 30095d617bfbSRichard Henderson static TCGv do_rdtnpc(DisasContext *dc, TCGv dst) 30105d617bfbSRichard Henderson { 30115d617bfbSRichard Henderson #ifdef TARGET_SPARC64 30125d617bfbSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 30135d617bfbSRichard Henderson 30145d617bfbSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 30155d617bfbSRichard Henderson tcg_gen_ld_tl(dst, r_tsptr, offsetof(trap_state, tnpc)); 30165d617bfbSRichard Henderson return dst; 30175d617bfbSRichard Henderson #else 30185d617bfbSRichard Henderson qemu_build_not_reached(); 30195d617bfbSRichard Henderson #endif 30205d617bfbSRichard Henderson } 30215d617bfbSRichard Henderson 30225d617bfbSRichard Henderson TRANS(RDPR_tnpc, 64, do_rd_special, supervisor(dc), a->rd, do_rdtnpc) 30235d617bfbSRichard Henderson 30245d617bfbSRichard Henderson static TCGv do_rdtstate(DisasContext *dc, TCGv dst) 30255d617bfbSRichard Henderson { 30265d617bfbSRichard Henderson #ifdef TARGET_SPARC64 30275d617bfbSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 30285d617bfbSRichard Henderson 30295d617bfbSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 30305d617bfbSRichard Henderson tcg_gen_ld_tl(dst, r_tsptr, offsetof(trap_state, tstate)); 30315d617bfbSRichard Henderson return dst; 30325d617bfbSRichard Henderson #else 30335d617bfbSRichard Henderson qemu_build_not_reached(); 30345d617bfbSRichard Henderson #endif 30355d617bfbSRichard Henderson } 30365d617bfbSRichard Henderson 30375d617bfbSRichard Henderson TRANS(RDPR_tstate, 64, do_rd_special, supervisor(dc), a->rd, do_rdtstate) 30385d617bfbSRichard Henderson 30395d617bfbSRichard Henderson static TCGv do_rdtt(DisasContext *dc, TCGv dst) 30405d617bfbSRichard Henderson { 30415d617bfbSRichard Henderson #ifdef TARGET_SPARC64 30425d617bfbSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 30435d617bfbSRichard Henderson 30445d617bfbSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 30455d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, r_tsptr, offsetof(trap_state, tt)); 30465d617bfbSRichard Henderson return dst; 30475d617bfbSRichard Henderson #else 30485d617bfbSRichard Henderson qemu_build_not_reached(); 30495d617bfbSRichard Henderson #endif 30505d617bfbSRichard Henderson } 30515d617bfbSRichard Henderson 30525d617bfbSRichard Henderson TRANS(RDPR_tt, 64, do_rd_special, supervisor(dc), a->rd, do_rdtt) 30535d617bfbSRichard Henderson TRANS(RDPR_tick, 64, do_rd_special, supervisor(dc), a->rd, do_rdtick) 30545d617bfbSRichard Henderson 30555d617bfbSRichard Henderson static TCGv do_rdtba(DisasContext *dc, TCGv dst) 30565d617bfbSRichard Henderson { 30575d617bfbSRichard Henderson return cpu_tbr; 30585d617bfbSRichard Henderson } 30595d617bfbSRichard Henderson 3060e8325dc0SRichard Henderson TRANS(RDTBR, 32, do_rd_special, supervisor(dc), a->rd, do_rdtba) 30615d617bfbSRichard Henderson TRANS(RDPR_tba, 64, do_rd_special, supervisor(dc), a->rd, do_rdtba) 30625d617bfbSRichard Henderson 30635d617bfbSRichard Henderson static TCGv do_rdpstate(DisasContext *dc, TCGv dst) 30645d617bfbSRichard Henderson { 30655d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(pstate)); 30665d617bfbSRichard Henderson return dst; 30675d617bfbSRichard Henderson } 30685d617bfbSRichard Henderson 30695d617bfbSRichard Henderson TRANS(RDPR_pstate, 64, do_rd_special, supervisor(dc), a->rd, do_rdpstate) 30705d617bfbSRichard Henderson 30715d617bfbSRichard Henderson static TCGv do_rdtl(DisasContext *dc, TCGv dst) 30725d617bfbSRichard Henderson { 30735d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(tl)); 30745d617bfbSRichard Henderson return dst; 30755d617bfbSRichard Henderson } 30765d617bfbSRichard Henderson 30775d617bfbSRichard Henderson TRANS(RDPR_tl, 64, do_rd_special, supervisor(dc), a->rd, do_rdtl) 30785d617bfbSRichard Henderson 30795d617bfbSRichard Henderson static TCGv do_rdpil(DisasContext *dc, TCGv dst) 30805d617bfbSRichard Henderson { 30815d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env_field_offsetof(psrpil)); 30825d617bfbSRichard Henderson return dst; 30835d617bfbSRichard Henderson } 30845d617bfbSRichard Henderson 30855d617bfbSRichard Henderson TRANS(RDPR_pil, 64, do_rd_special, supervisor(dc), a->rd, do_rdpil) 30865d617bfbSRichard Henderson 30875d617bfbSRichard Henderson static TCGv do_rdcwp(DisasContext *dc, TCGv dst) 30885d617bfbSRichard Henderson { 30895d617bfbSRichard Henderson gen_helper_rdcwp(dst, tcg_env); 30905d617bfbSRichard Henderson return dst; 30915d617bfbSRichard Henderson } 30925d617bfbSRichard Henderson 30935d617bfbSRichard Henderson TRANS(RDPR_cwp, 64, do_rd_special, supervisor(dc), a->rd, do_rdcwp) 30945d617bfbSRichard Henderson 30955d617bfbSRichard Henderson static TCGv do_rdcansave(DisasContext *dc, TCGv dst) 30965d617bfbSRichard Henderson { 30975d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(cansave)); 30985d617bfbSRichard Henderson return dst; 30995d617bfbSRichard Henderson } 31005d617bfbSRichard Henderson 31015d617bfbSRichard Henderson TRANS(RDPR_cansave, 64, do_rd_special, supervisor(dc), a->rd, do_rdcansave) 31025d617bfbSRichard Henderson 31035d617bfbSRichard Henderson static TCGv do_rdcanrestore(DisasContext *dc, TCGv dst) 31045d617bfbSRichard Henderson { 31055d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(canrestore)); 31065d617bfbSRichard Henderson return dst; 31075d617bfbSRichard Henderson } 31085d617bfbSRichard Henderson 31095d617bfbSRichard Henderson TRANS(RDPR_canrestore, 64, do_rd_special, supervisor(dc), a->rd, 31105d617bfbSRichard Henderson do_rdcanrestore) 31115d617bfbSRichard Henderson 31125d617bfbSRichard Henderson static TCGv do_rdcleanwin(DisasContext *dc, TCGv dst) 31135d617bfbSRichard Henderson { 31145d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(cleanwin)); 31155d617bfbSRichard Henderson return dst; 31165d617bfbSRichard Henderson } 31175d617bfbSRichard Henderson 31185d617bfbSRichard Henderson TRANS(RDPR_cleanwin, 64, do_rd_special, supervisor(dc), a->rd, do_rdcleanwin) 31195d617bfbSRichard Henderson 31205d617bfbSRichard Henderson static TCGv do_rdotherwin(DisasContext *dc, TCGv dst) 31215d617bfbSRichard Henderson { 31225d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(otherwin)); 31235d617bfbSRichard Henderson return dst; 31245d617bfbSRichard Henderson } 31255d617bfbSRichard Henderson 31265d617bfbSRichard Henderson TRANS(RDPR_otherwin, 64, do_rd_special, supervisor(dc), a->rd, do_rdotherwin) 31275d617bfbSRichard Henderson 31285d617bfbSRichard Henderson static TCGv do_rdwstate(DisasContext *dc, TCGv dst) 31295d617bfbSRichard Henderson { 31305d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(wstate)); 31315d617bfbSRichard Henderson return dst; 31325d617bfbSRichard Henderson } 31335d617bfbSRichard Henderson 31345d617bfbSRichard Henderson TRANS(RDPR_wstate, 64, do_rd_special, supervisor(dc), a->rd, do_rdwstate) 31355d617bfbSRichard Henderson 31365d617bfbSRichard Henderson static TCGv do_rdgl(DisasContext *dc, TCGv dst) 31375d617bfbSRichard Henderson { 31385d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(gl)); 31395d617bfbSRichard Henderson return dst; 31405d617bfbSRichard Henderson } 31415d617bfbSRichard Henderson 31425d617bfbSRichard Henderson TRANS(RDPR_gl, GL, do_rd_special, supervisor(dc), a->rd, do_rdgl) 31435d617bfbSRichard Henderson 31445d617bfbSRichard Henderson /* UA2005 strand status */ 31455d617bfbSRichard Henderson static TCGv do_rdssr(DisasContext *dc, TCGv dst) 31465d617bfbSRichard Henderson { 31472da789deSRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(ssr)); 31482da789deSRichard Henderson return dst; 31495d617bfbSRichard Henderson } 31505d617bfbSRichard Henderson 31515d617bfbSRichard Henderson TRANS(RDPR_strand_status, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdssr) 31525d617bfbSRichard Henderson 31535d617bfbSRichard Henderson static TCGv do_rdver(DisasContext *dc, TCGv dst) 31545d617bfbSRichard Henderson { 31552da789deSRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(version)); 31562da789deSRichard Henderson return dst; 31575d617bfbSRichard Henderson } 31585d617bfbSRichard Henderson 31595d617bfbSRichard Henderson TRANS(RDPR_ver, 64, do_rd_special, supervisor(dc), a->rd, do_rdver) 31605d617bfbSRichard Henderson 3161e8325dc0SRichard Henderson static bool trans_FLUSHW(DisasContext *dc, arg_FLUSHW *a) 3162e8325dc0SRichard Henderson { 3163e8325dc0SRichard Henderson if (avail_64(dc)) { 3164e8325dc0SRichard Henderson gen_helper_flushw(tcg_env); 3165e8325dc0SRichard Henderson return advance_pc(dc); 3166e8325dc0SRichard Henderson } 3167e8325dc0SRichard Henderson return false; 3168e8325dc0SRichard Henderson } 3169e8325dc0SRichard Henderson 31700faef01bSRichard Henderson static bool do_wr_special(DisasContext *dc, arg_r_r_ri *a, bool priv, 31710faef01bSRichard Henderson void (*func)(DisasContext *, TCGv)) 31720faef01bSRichard Henderson { 31730faef01bSRichard Henderson TCGv src; 31740faef01bSRichard Henderson 31750faef01bSRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 31760faef01bSRichard Henderson if (!a->imm && (a->rs2_or_imm & ~0x1f)) { 31770faef01bSRichard Henderson return false; 31780faef01bSRichard Henderson } 31790faef01bSRichard Henderson if (!priv) { 31800faef01bSRichard Henderson return raise_priv(dc); 31810faef01bSRichard Henderson } 31820faef01bSRichard Henderson 31830faef01bSRichard Henderson if (a->rs1 == 0 && (a->imm || a->rs2_or_imm == 0)) { 31840faef01bSRichard Henderson src = tcg_constant_tl(a->rs2_or_imm); 31850faef01bSRichard Henderson } else { 31860faef01bSRichard Henderson TCGv src1 = gen_load_gpr(dc, a->rs1); 31870faef01bSRichard Henderson if (a->rs2_or_imm == 0) { 31880faef01bSRichard Henderson src = src1; 31890faef01bSRichard Henderson } else { 31900faef01bSRichard Henderson src = tcg_temp_new(); 31910faef01bSRichard Henderson if (a->imm) { 31920faef01bSRichard Henderson tcg_gen_xori_tl(src, src1, a->rs2_or_imm); 31930faef01bSRichard Henderson } else { 31940faef01bSRichard Henderson tcg_gen_xor_tl(src, src1, gen_load_gpr(dc, a->rs2_or_imm)); 31950faef01bSRichard Henderson } 31960faef01bSRichard Henderson } 31970faef01bSRichard Henderson } 31980faef01bSRichard Henderson func(dc, src); 31990faef01bSRichard Henderson return advance_pc(dc); 32000faef01bSRichard Henderson } 32010faef01bSRichard Henderson 32020faef01bSRichard Henderson static void do_wry(DisasContext *dc, TCGv src) 32030faef01bSRichard Henderson { 32040faef01bSRichard Henderson tcg_gen_ext32u_tl(cpu_y, src); 32050faef01bSRichard Henderson } 32060faef01bSRichard Henderson 32070faef01bSRichard Henderson TRANS(WRY, ALL, do_wr_special, a, true, do_wry) 32080faef01bSRichard Henderson 32090faef01bSRichard Henderson static void do_wrccr(DisasContext *dc, TCGv src) 32100faef01bSRichard Henderson { 32110faef01bSRichard Henderson gen_helper_wrccr(tcg_env, src); 32120faef01bSRichard Henderson } 32130faef01bSRichard Henderson 32140faef01bSRichard Henderson TRANS(WRCCR, 64, do_wr_special, a, true, do_wrccr) 32150faef01bSRichard Henderson 32160faef01bSRichard Henderson static void do_wrasi(DisasContext *dc, TCGv src) 32170faef01bSRichard Henderson { 32180faef01bSRichard Henderson TCGv tmp = tcg_temp_new(); 32190faef01bSRichard Henderson 32200faef01bSRichard Henderson tcg_gen_ext8u_tl(tmp, src); 32210faef01bSRichard Henderson tcg_gen_st32_tl(tmp, tcg_env, env64_field_offsetof(asi)); 32220faef01bSRichard Henderson /* End TB to notice changed ASI. */ 32230faef01bSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 32240faef01bSRichard Henderson } 32250faef01bSRichard Henderson 32260faef01bSRichard Henderson TRANS(WRASI, 64, do_wr_special, a, true, do_wrasi) 32270faef01bSRichard Henderson 32280faef01bSRichard Henderson static void do_wrfprs(DisasContext *dc, TCGv src) 32290faef01bSRichard Henderson { 32300faef01bSRichard Henderson #ifdef TARGET_SPARC64 32310faef01bSRichard Henderson tcg_gen_trunc_tl_i32(cpu_fprs, src); 32320faef01bSRichard Henderson dc->fprs_dirty = 0; 32330faef01bSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 32340faef01bSRichard Henderson #else 32350faef01bSRichard Henderson qemu_build_not_reached(); 32360faef01bSRichard Henderson #endif 32370faef01bSRichard Henderson } 32380faef01bSRichard Henderson 32390faef01bSRichard Henderson TRANS(WRFPRS, 64, do_wr_special, a, true, do_wrfprs) 32400faef01bSRichard Henderson 32410faef01bSRichard Henderson static void do_wrgsr(DisasContext *dc, TCGv src) 32420faef01bSRichard Henderson { 32430faef01bSRichard Henderson gen_trap_ifnofpu(dc); 32440faef01bSRichard Henderson tcg_gen_mov_tl(cpu_gsr, src); 32450faef01bSRichard Henderson } 32460faef01bSRichard Henderson 32470faef01bSRichard Henderson TRANS(WRGSR, 64, do_wr_special, a, true, do_wrgsr) 32480faef01bSRichard Henderson 32490faef01bSRichard Henderson static void do_wrsoftint_set(DisasContext *dc, TCGv src) 32500faef01bSRichard Henderson { 32510faef01bSRichard Henderson gen_helper_set_softint(tcg_env, src); 32520faef01bSRichard Henderson } 32530faef01bSRichard Henderson 32540faef01bSRichard Henderson TRANS(WRSOFTINT_SET, 64, do_wr_special, a, supervisor(dc), do_wrsoftint_set) 32550faef01bSRichard Henderson 32560faef01bSRichard Henderson static void do_wrsoftint_clr(DisasContext *dc, TCGv src) 32570faef01bSRichard Henderson { 32580faef01bSRichard Henderson gen_helper_clear_softint(tcg_env, src); 32590faef01bSRichard Henderson } 32600faef01bSRichard Henderson 32610faef01bSRichard Henderson TRANS(WRSOFTINT_CLR, 64, do_wr_special, a, supervisor(dc), do_wrsoftint_clr) 32620faef01bSRichard Henderson 32630faef01bSRichard Henderson static void do_wrsoftint(DisasContext *dc, TCGv src) 32640faef01bSRichard Henderson { 32650faef01bSRichard Henderson gen_helper_write_softint(tcg_env, src); 32660faef01bSRichard Henderson } 32670faef01bSRichard Henderson 32680faef01bSRichard Henderson TRANS(WRSOFTINT, 64, do_wr_special, a, supervisor(dc), do_wrsoftint) 32690faef01bSRichard Henderson 32700faef01bSRichard Henderson static void do_wrtick_cmpr(DisasContext *dc, TCGv src) 32710faef01bSRichard Henderson { 32720faef01bSRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr(); 32730faef01bSRichard Henderson 3274577efa45SRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(tick_cmpr)); 3275577efa45SRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(tick)); 32760faef01bSRichard Henderson translator_io_start(&dc->base); 3277577efa45SRichard Henderson gen_helper_tick_set_limit(r_tickptr, src); 32780faef01bSRichard Henderson /* End TB to handle timer interrupt */ 32790faef01bSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 32800faef01bSRichard Henderson } 32810faef01bSRichard Henderson 32820faef01bSRichard Henderson TRANS(WRTICK_CMPR, 64, do_wr_special, a, supervisor(dc), do_wrtick_cmpr) 32830faef01bSRichard Henderson 32840faef01bSRichard Henderson static void do_wrstick(DisasContext *dc, TCGv src) 32850faef01bSRichard Henderson { 32860faef01bSRichard Henderson #ifdef TARGET_SPARC64 32870faef01bSRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr(); 32880faef01bSRichard Henderson 32890faef01bSRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, offsetof(CPUSPARCState, stick)); 32900faef01bSRichard Henderson translator_io_start(&dc->base); 32910faef01bSRichard Henderson gen_helper_tick_set_count(r_tickptr, src); 32920faef01bSRichard Henderson /* End TB to handle timer interrupt */ 32930faef01bSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 32940faef01bSRichard Henderson #else 32950faef01bSRichard Henderson qemu_build_not_reached(); 32960faef01bSRichard Henderson #endif 32970faef01bSRichard Henderson } 32980faef01bSRichard Henderson 32990faef01bSRichard Henderson TRANS(WRSTICK, 64, do_wr_special, a, supervisor(dc), do_wrstick) 33000faef01bSRichard Henderson 33010faef01bSRichard Henderson static void do_wrstick_cmpr(DisasContext *dc, TCGv src) 33020faef01bSRichard Henderson { 33030faef01bSRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr(); 33040faef01bSRichard Henderson 3305577efa45SRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(stick_cmpr)); 3306577efa45SRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(stick)); 33070faef01bSRichard Henderson translator_io_start(&dc->base); 3308577efa45SRichard Henderson gen_helper_tick_set_limit(r_tickptr, src); 33090faef01bSRichard Henderson /* End TB to handle timer interrupt */ 33100faef01bSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 33110faef01bSRichard Henderson } 33120faef01bSRichard Henderson 33130faef01bSRichard Henderson TRANS(WRSTICK_CMPR, 64, do_wr_special, a, supervisor(dc), do_wrstick_cmpr) 33140faef01bSRichard Henderson 33150faef01bSRichard Henderson static void do_wrpowerdown(DisasContext *dc, TCGv src) 33160faef01bSRichard Henderson { 331789527e3aSRichard Henderson finishing_insn(dc); 33180faef01bSRichard Henderson save_state(dc); 33190faef01bSRichard Henderson gen_helper_power_down(tcg_env); 33200faef01bSRichard Henderson } 33210faef01bSRichard Henderson 33220faef01bSRichard Henderson TRANS(WRPOWERDOWN, POWERDOWN, do_wr_special, a, supervisor(dc), do_wrpowerdown) 33230faef01bSRichard Henderson 332425524734SRichard Henderson static void do_wrpsr(DisasContext *dc, TCGv src) 332525524734SRichard Henderson { 332625524734SRichard Henderson gen_helper_wrpsr(tcg_env, src); 332725524734SRichard Henderson dc->base.is_jmp = DISAS_EXIT; 332825524734SRichard Henderson } 332925524734SRichard Henderson 333025524734SRichard Henderson TRANS(WRPSR, 32, do_wr_special, a, supervisor(dc), do_wrpsr) 333125524734SRichard Henderson 33329422278eSRichard Henderson static void do_wrwim(DisasContext *dc, TCGv src) 33339422278eSRichard Henderson { 33349422278eSRichard Henderson target_ulong mask = MAKE_64BIT_MASK(0, dc->def->nwindows); 3335cd6269f7SRichard Henderson TCGv tmp = tcg_temp_new(); 3336cd6269f7SRichard Henderson 3337cd6269f7SRichard Henderson tcg_gen_andi_tl(tmp, src, mask); 3338cd6269f7SRichard Henderson tcg_gen_st_tl(tmp, tcg_env, env32_field_offsetof(wim)); 33399422278eSRichard Henderson } 33409422278eSRichard Henderson 33419422278eSRichard Henderson TRANS(WRWIM, 32, do_wr_special, a, supervisor(dc), do_wrwim) 33429422278eSRichard Henderson 33439422278eSRichard Henderson static void do_wrtpc(DisasContext *dc, TCGv src) 33449422278eSRichard Henderson { 33459422278eSRichard Henderson #ifdef TARGET_SPARC64 33469422278eSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 33479422278eSRichard Henderson 33489422278eSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 33499422278eSRichard Henderson tcg_gen_st_tl(src, r_tsptr, offsetof(trap_state, tpc)); 33509422278eSRichard Henderson #else 33519422278eSRichard Henderson qemu_build_not_reached(); 33529422278eSRichard Henderson #endif 33539422278eSRichard Henderson } 33549422278eSRichard Henderson 33559422278eSRichard Henderson TRANS(WRPR_tpc, 64, do_wr_special, a, supervisor(dc), do_wrtpc) 33569422278eSRichard Henderson 33579422278eSRichard Henderson static void do_wrtnpc(DisasContext *dc, TCGv src) 33589422278eSRichard Henderson { 33599422278eSRichard Henderson #ifdef TARGET_SPARC64 33609422278eSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 33619422278eSRichard Henderson 33629422278eSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 33639422278eSRichard Henderson tcg_gen_st_tl(src, r_tsptr, offsetof(trap_state, tnpc)); 33649422278eSRichard Henderson #else 33659422278eSRichard Henderson qemu_build_not_reached(); 33669422278eSRichard Henderson #endif 33679422278eSRichard Henderson } 33689422278eSRichard Henderson 33699422278eSRichard Henderson TRANS(WRPR_tnpc, 64, do_wr_special, a, supervisor(dc), do_wrtnpc) 33709422278eSRichard Henderson 33719422278eSRichard Henderson static void do_wrtstate(DisasContext *dc, TCGv src) 33729422278eSRichard Henderson { 33739422278eSRichard Henderson #ifdef TARGET_SPARC64 33749422278eSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 33759422278eSRichard Henderson 33769422278eSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 33779422278eSRichard Henderson tcg_gen_st_tl(src, r_tsptr, offsetof(trap_state, tstate)); 33789422278eSRichard Henderson #else 33799422278eSRichard Henderson qemu_build_not_reached(); 33809422278eSRichard Henderson #endif 33819422278eSRichard Henderson } 33829422278eSRichard Henderson 33839422278eSRichard Henderson TRANS(WRPR_tstate, 64, do_wr_special, a, supervisor(dc), do_wrtstate) 33849422278eSRichard Henderson 33859422278eSRichard Henderson static void do_wrtt(DisasContext *dc, TCGv src) 33869422278eSRichard Henderson { 33879422278eSRichard Henderson #ifdef TARGET_SPARC64 33889422278eSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 33899422278eSRichard Henderson 33909422278eSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 33919422278eSRichard Henderson tcg_gen_st32_tl(src, r_tsptr, offsetof(trap_state, tt)); 33929422278eSRichard Henderson #else 33939422278eSRichard Henderson qemu_build_not_reached(); 33949422278eSRichard Henderson #endif 33959422278eSRichard Henderson } 33969422278eSRichard Henderson 33979422278eSRichard Henderson TRANS(WRPR_tt, 64, do_wr_special, a, supervisor(dc), do_wrtt) 33989422278eSRichard Henderson 33999422278eSRichard Henderson static void do_wrtick(DisasContext *dc, TCGv src) 34009422278eSRichard Henderson { 34019422278eSRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr(); 34029422278eSRichard Henderson 34039422278eSRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(tick)); 34049422278eSRichard Henderson translator_io_start(&dc->base); 34059422278eSRichard Henderson gen_helper_tick_set_count(r_tickptr, src); 34069422278eSRichard Henderson /* End TB to handle timer interrupt */ 34079422278eSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 34089422278eSRichard Henderson } 34099422278eSRichard Henderson 34109422278eSRichard Henderson TRANS(WRPR_tick, 64, do_wr_special, a, supervisor(dc), do_wrtick) 34119422278eSRichard Henderson 34129422278eSRichard Henderson static void do_wrtba(DisasContext *dc, TCGv src) 34139422278eSRichard Henderson { 34149422278eSRichard Henderson tcg_gen_mov_tl(cpu_tbr, src); 34159422278eSRichard Henderson } 34169422278eSRichard Henderson 34179422278eSRichard Henderson TRANS(WRPR_tba, 64, do_wr_special, a, supervisor(dc), do_wrtba) 34189422278eSRichard Henderson 34199422278eSRichard Henderson static void do_wrpstate(DisasContext *dc, TCGv src) 34209422278eSRichard Henderson { 34219422278eSRichard Henderson save_state(dc); 34229422278eSRichard Henderson if (translator_io_start(&dc->base)) { 34239422278eSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 34249422278eSRichard Henderson } 34259422278eSRichard Henderson gen_helper_wrpstate(tcg_env, src); 34269422278eSRichard Henderson dc->npc = DYNAMIC_PC; 34279422278eSRichard Henderson } 34289422278eSRichard Henderson 34299422278eSRichard Henderson TRANS(WRPR_pstate, 64, do_wr_special, a, supervisor(dc), do_wrpstate) 34309422278eSRichard Henderson 34319422278eSRichard Henderson static void do_wrtl(DisasContext *dc, TCGv src) 34329422278eSRichard Henderson { 34339422278eSRichard Henderson save_state(dc); 34349422278eSRichard Henderson tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(tl)); 34359422278eSRichard Henderson dc->npc = DYNAMIC_PC; 34369422278eSRichard Henderson } 34379422278eSRichard Henderson 34389422278eSRichard Henderson TRANS(WRPR_tl, 64, do_wr_special, a, supervisor(dc), do_wrtl) 34399422278eSRichard Henderson 34409422278eSRichard Henderson static void do_wrpil(DisasContext *dc, TCGv src) 34419422278eSRichard Henderson { 34429422278eSRichard Henderson if (translator_io_start(&dc->base)) { 34439422278eSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 34449422278eSRichard Henderson } 34459422278eSRichard Henderson gen_helper_wrpil(tcg_env, src); 34469422278eSRichard Henderson } 34479422278eSRichard Henderson 34489422278eSRichard Henderson TRANS(WRPR_pil, 64, do_wr_special, a, supervisor(dc), do_wrpil) 34499422278eSRichard Henderson 34509422278eSRichard Henderson static void do_wrcwp(DisasContext *dc, TCGv src) 34519422278eSRichard Henderson { 34529422278eSRichard Henderson gen_helper_wrcwp(tcg_env, src); 34539422278eSRichard Henderson } 34549422278eSRichard Henderson 34559422278eSRichard Henderson TRANS(WRPR_cwp, 64, do_wr_special, a, supervisor(dc), do_wrcwp) 34569422278eSRichard Henderson 34579422278eSRichard Henderson static void do_wrcansave(DisasContext *dc, TCGv src) 34589422278eSRichard Henderson { 34599422278eSRichard Henderson tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(cansave)); 34609422278eSRichard Henderson } 34619422278eSRichard Henderson 34629422278eSRichard Henderson TRANS(WRPR_cansave, 64, do_wr_special, a, supervisor(dc), do_wrcansave) 34639422278eSRichard Henderson 34649422278eSRichard Henderson static void do_wrcanrestore(DisasContext *dc, TCGv src) 34659422278eSRichard Henderson { 34669422278eSRichard Henderson tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(canrestore)); 34679422278eSRichard Henderson } 34689422278eSRichard Henderson 34699422278eSRichard Henderson TRANS(WRPR_canrestore, 64, do_wr_special, a, supervisor(dc), do_wrcanrestore) 34709422278eSRichard Henderson 34719422278eSRichard Henderson static void do_wrcleanwin(DisasContext *dc, TCGv src) 34729422278eSRichard Henderson { 34739422278eSRichard Henderson tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(cleanwin)); 34749422278eSRichard Henderson } 34759422278eSRichard Henderson 34769422278eSRichard Henderson TRANS(WRPR_cleanwin, 64, do_wr_special, a, supervisor(dc), do_wrcleanwin) 34779422278eSRichard Henderson 34789422278eSRichard Henderson static void do_wrotherwin(DisasContext *dc, TCGv src) 34799422278eSRichard Henderson { 34809422278eSRichard Henderson tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(otherwin)); 34819422278eSRichard Henderson } 34829422278eSRichard Henderson 34839422278eSRichard Henderson TRANS(WRPR_otherwin, 64, do_wr_special, a, supervisor(dc), do_wrotherwin) 34849422278eSRichard Henderson 34859422278eSRichard Henderson static void do_wrwstate(DisasContext *dc, TCGv src) 34869422278eSRichard Henderson { 34879422278eSRichard Henderson tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(wstate)); 34889422278eSRichard Henderson } 34899422278eSRichard Henderson 34909422278eSRichard Henderson TRANS(WRPR_wstate, 64, do_wr_special, a, supervisor(dc), do_wrwstate) 34919422278eSRichard Henderson 34929422278eSRichard Henderson static void do_wrgl(DisasContext *dc, TCGv src) 34939422278eSRichard Henderson { 34949422278eSRichard Henderson gen_helper_wrgl(tcg_env, src); 34959422278eSRichard Henderson } 34969422278eSRichard Henderson 34979422278eSRichard Henderson TRANS(WRPR_gl, GL, do_wr_special, a, supervisor(dc), do_wrgl) 34989422278eSRichard Henderson 34999422278eSRichard Henderson /* UA2005 strand status */ 35009422278eSRichard Henderson static void do_wrssr(DisasContext *dc, TCGv src) 35019422278eSRichard Henderson { 35022da789deSRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(ssr)); 35039422278eSRichard Henderson } 35049422278eSRichard Henderson 35059422278eSRichard Henderson TRANS(WRPR_strand_status, HYPV, do_wr_special, a, hypervisor(dc), do_wrssr) 35069422278eSRichard Henderson 3507bb97f2f5SRichard Henderson TRANS(WRTBR, 32, do_wr_special, a, supervisor(dc), do_wrtba) 3508bb97f2f5SRichard Henderson 3509bb97f2f5SRichard Henderson static void do_wrhpstate(DisasContext *dc, TCGv src) 3510bb97f2f5SRichard Henderson { 3511bb97f2f5SRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(hpstate)); 3512bb97f2f5SRichard Henderson dc->base.is_jmp = DISAS_EXIT; 3513bb97f2f5SRichard Henderson } 3514bb97f2f5SRichard Henderson 3515bb97f2f5SRichard Henderson TRANS(WRHPR_hpstate, HYPV, do_wr_special, a, hypervisor(dc), do_wrhpstate) 3516bb97f2f5SRichard Henderson 3517bb97f2f5SRichard Henderson static void do_wrhtstate(DisasContext *dc, TCGv src) 3518bb97f2f5SRichard Henderson { 3519bb97f2f5SRichard Henderson TCGv_i32 tl = tcg_temp_new_i32(); 3520bb97f2f5SRichard Henderson TCGv_ptr tp = tcg_temp_new_ptr(); 3521bb97f2f5SRichard Henderson 3522bb97f2f5SRichard Henderson tcg_gen_ld_i32(tl, tcg_env, env64_field_offsetof(tl)); 3523bb97f2f5SRichard Henderson tcg_gen_andi_i32(tl, tl, MAXTL_MASK); 3524bb97f2f5SRichard Henderson tcg_gen_shli_i32(tl, tl, 3); 3525bb97f2f5SRichard Henderson tcg_gen_ext_i32_ptr(tp, tl); 3526bb97f2f5SRichard Henderson tcg_gen_add_ptr(tp, tp, tcg_env); 3527bb97f2f5SRichard Henderson 3528bb97f2f5SRichard Henderson tcg_gen_st_tl(src, tp, env64_field_offsetof(htstate)); 3529bb97f2f5SRichard Henderson } 3530bb97f2f5SRichard Henderson 3531bb97f2f5SRichard Henderson TRANS(WRHPR_htstate, HYPV, do_wr_special, a, hypervisor(dc), do_wrhtstate) 3532bb97f2f5SRichard Henderson 3533bb97f2f5SRichard Henderson static void do_wrhintp(DisasContext *dc, TCGv src) 3534bb97f2f5SRichard Henderson { 35352da789deSRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(hintp)); 3536bb97f2f5SRichard Henderson } 3537bb97f2f5SRichard Henderson 3538bb97f2f5SRichard Henderson TRANS(WRHPR_hintp, HYPV, do_wr_special, a, hypervisor(dc), do_wrhintp) 3539bb97f2f5SRichard Henderson 3540bb97f2f5SRichard Henderson static void do_wrhtba(DisasContext *dc, TCGv src) 3541bb97f2f5SRichard Henderson { 35422da789deSRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(htba)); 3543bb97f2f5SRichard Henderson } 3544bb97f2f5SRichard Henderson 3545bb97f2f5SRichard Henderson TRANS(WRHPR_htba, HYPV, do_wr_special, a, hypervisor(dc), do_wrhtba) 3546bb97f2f5SRichard Henderson 3547bb97f2f5SRichard Henderson static void do_wrhstick_cmpr(DisasContext *dc, TCGv src) 3548bb97f2f5SRichard Henderson { 3549bb97f2f5SRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr(); 3550bb97f2f5SRichard Henderson 3551577efa45SRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(hstick_cmpr)); 3552bb97f2f5SRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(hstick)); 3553bb97f2f5SRichard Henderson translator_io_start(&dc->base); 3554577efa45SRichard Henderson gen_helper_tick_set_limit(r_tickptr, src); 3555bb97f2f5SRichard Henderson /* End TB to handle timer interrupt */ 3556bb97f2f5SRichard Henderson dc->base.is_jmp = DISAS_EXIT; 3557bb97f2f5SRichard Henderson } 3558bb97f2f5SRichard Henderson 3559bb97f2f5SRichard Henderson TRANS(WRHPR_hstick_cmpr, HYPV, do_wr_special, a, hypervisor(dc), 3560bb97f2f5SRichard Henderson do_wrhstick_cmpr) 3561bb97f2f5SRichard Henderson 356225524734SRichard Henderson static bool do_saved_restored(DisasContext *dc, bool saved) 356325524734SRichard Henderson { 356425524734SRichard Henderson if (!supervisor(dc)) { 356525524734SRichard Henderson return raise_priv(dc); 356625524734SRichard Henderson } 356725524734SRichard Henderson if (saved) { 356825524734SRichard Henderson gen_helper_saved(tcg_env); 356925524734SRichard Henderson } else { 357025524734SRichard Henderson gen_helper_restored(tcg_env); 357125524734SRichard Henderson } 357225524734SRichard Henderson return advance_pc(dc); 357325524734SRichard Henderson } 357425524734SRichard Henderson 357525524734SRichard Henderson TRANS(SAVED, 64, do_saved_restored, true) 357625524734SRichard Henderson TRANS(RESTORED, 64, do_saved_restored, false) 357725524734SRichard Henderson 3578d3825800SRichard Henderson static bool trans_NOP(DisasContext *dc, arg_NOP *a) 3579d3825800SRichard Henderson { 3580d3825800SRichard Henderson return advance_pc(dc); 3581d3825800SRichard Henderson } 3582d3825800SRichard Henderson 35830faef01bSRichard Henderson /* 35840faef01bSRichard Henderson * TODO: Need a feature bit for sparcv8. 35850faef01bSRichard Henderson * In the meantime, treat all 32-bit cpus like sparcv7. 35860faef01bSRichard Henderson */ 35875458fd31SRichard Henderson TRANS(NOP_v7, 32, trans_NOP, a) 35885458fd31SRichard Henderson TRANS(NOP_v9, 64, trans_NOP, a) 35890faef01bSRichard Henderson 3590b597eedcSRichard Henderson static bool do_arith_int(DisasContext *dc, arg_r_r_ri_cc *a, 3591428881deSRichard Henderson void (*func)(TCGv, TCGv, TCGv), 35922a45b736SRichard Henderson void (*funci)(TCGv, TCGv, target_long), 35932a45b736SRichard Henderson bool logic_cc) 3594428881deSRichard Henderson { 3595428881deSRichard Henderson TCGv dst, src1; 3596428881deSRichard Henderson 3597428881deSRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 3598428881deSRichard Henderson if (!a->imm && a->rs2_or_imm & ~0x1f) { 3599428881deSRichard Henderson return false; 3600428881deSRichard Henderson } 3601428881deSRichard Henderson 36022a45b736SRichard Henderson if (logic_cc) { 36032a45b736SRichard Henderson dst = cpu_cc_N; 3604428881deSRichard Henderson } else { 3605428881deSRichard Henderson dst = gen_dest_gpr(dc, a->rd); 3606428881deSRichard Henderson } 3607428881deSRichard Henderson src1 = gen_load_gpr(dc, a->rs1); 3608428881deSRichard Henderson 3609428881deSRichard Henderson if (a->imm || a->rs2_or_imm == 0) { 3610428881deSRichard Henderson if (funci) { 3611428881deSRichard Henderson funci(dst, src1, a->rs2_or_imm); 3612428881deSRichard Henderson } else { 3613428881deSRichard Henderson func(dst, src1, tcg_constant_tl(a->rs2_or_imm)); 3614428881deSRichard Henderson } 3615428881deSRichard Henderson } else { 3616428881deSRichard Henderson func(dst, src1, cpu_regs[a->rs2_or_imm]); 3617428881deSRichard Henderson } 36182a45b736SRichard Henderson 36192a45b736SRichard Henderson if (logic_cc) { 36202a45b736SRichard Henderson if (TARGET_LONG_BITS == 64) { 36212a45b736SRichard Henderson tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N); 36222a45b736SRichard Henderson tcg_gen_movi_tl(cpu_icc_C, 0); 36232a45b736SRichard Henderson } 36242a45b736SRichard Henderson tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N); 36252a45b736SRichard Henderson tcg_gen_movi_tl(cpu_cc_C, 0); 36262a45b736SRichard Henderson tcg_gen_movi_tl(cpu_cc_V, 0); 36272a45b736SRichard Henderson } 36282a45b736SRichard Henderson 3629428881deSRichard Henderson gen_store_gpr(dc, a->rd, dst); 3630428881deSRichard Henderson return advance_pc(dc); 3631428881deSRichard Henderson } 3632428881deSRichard Henderson 3633b597eedcSRichard Henderson static bool do_arith(DisasContext *dc, arg_r_r_ri_cc *a, 3634428881deSRichard Henderson void (*func)(TCGv, TCGv, TCGv), 3635428881deSRichard Henderson void (*funci)(TCGv, TCGv, target_long), 3636428881deSRichard Henderson void (*func_cc)(TCGv, TCGv, TCGv)) 3637428881deSRichard Henderson { 3638428881deSRichard Henderson if (a->cc) { 3639b597eedcSRichard Henderson return do_arith_int(dc, a, func_cc, NULL, false); 3640428881deSRichard Henderson } 3641b597eedcSRichard Henderson return do_arith_int(dc, a, func, funci, false); 3642428881deSRichard Henderson } 3643428881deSRichard Henderson 3644428881deSRichard Henderson static bool do_logic(DisasContext *dc, arg_r_r_ri_cc *a, 3645428881deSRichard Henderson void (*func)(TCGv, TCGv, TCGv), 3646428881deSRichard Henderson void (*funci)(TCGv, TCGv, target_long)) 3647428881deSRichard Henderson { 3648b597eedcSRichard Henderson return do_arith_int(dc, a, func, funci, a->cc); 3649428881deSRichard Henderson } 3650428881deSRichard Henderson 3651b597eedcSRichard Henderson TRANS(ADD, ALL, do_arith, a, tcg_gen_add_tl, tcg_gen_addi_tl, gen_op_addcc) 3652b597eedcSRichard Henderson TRANS(SUB, ALL, do_arith, a, tcg_gen_sub_tl, tcg_gen_subi_tl, gen_op_subcc) 3653b597eedcSRichard Henderson TRANS(ADDC, ALL, do_arith, a, gen_op_addc, NULL, gen_op_addccc) 3654b597eedcSRichard Henderson TRANS(SUBC, ALL, do_arith, a, gen_op_subc, NULL, gen_op_subccc) 3655428881deSRichard Henderson 3656b597eedcSRichard Henderson TRANS(TADDcc, ALL, do_arith, a, NULL, NULL, gen_op_taddcc) 3657b597eedcSRichard Henderson TRANS(TSUBcc, ALL, do_arith, a, NULL, NULL, gen_op_tsubcc) 3658b597eedcSRichard Henderson TRANS(TADDccTV, ALL, do_arith, a, NULL, NULL, gen_op_taddcctv) 3659b597eedcSRichard Henderson TRANS(TSUBccTV, ALL, do_arith, a, NULL, NULL, gen_op_tsubcctv) 3660a9aba13dSRichard Henderson 3661428881deSRichard Henderson TRANS(AND, ALL, do_logic, a, tcg_gen_and_tl, tcg_gen_andi_tl) 3662428881deSRichard Henderson TRANS(XOR, ALL, do_logic, a, tcg_gen_xor_tl, tcg_gen_xori_tl) 3663428881deSRichard Henderson TRANS(ANDN, ALL, do_logic, a, tcg_gen_andc_tl, NULL) 3664428881deSRichard Henderson TRANS(ORN, ALL, do_logic, a, tcg_gen_orc_tl, NULL) 3665428881deSRichard Henderson TRANS(XORN, ALL, do_logic, a, tcg_gen_eqv_tl, NULL) 3666428881deSRichard Henderson 3667b597eedcSRichard Henderson TRANS(MULX, 64, do_arith, a, tcg_gen_mul_tl, tcg_gen_muli_tl, NULL) 3668b5372650SRichard Henderson TRANS(UMUL, MUL, do_logic, a, gen_op_umul, NULL) 3669b5372650SRichard Henderson TRANS(SMUL, MUL, do_logic, a, gen_op_smul, NULL) 3670b597eedcSRichard Henderson TRANS(MULScc, ALL, do_arith, a, NULL, NULL, gen_op_mulscc) 367122188d7dSRichard Henderson 36723a6b8de3SRichard Henderson TRANS(UDIVcc, DIV, do_arith, a, NULL, NULL, gen_op_udivcc) 3673b597eedcSRichard Henderson TRANS(SDIV, DIV, do_arith, a, gen_op_sdiv, NULL, gen_op_sdivcc) 36744ee85ea9SRichard Henderson 36759c6ec5bcSRichard Henderson /* TODO: Should have feature bit -- comes in with UltraSparc T2. */ 3676b597eedcSRichard Henderson TRANS(POPC, 64, do_arith, a, gen_op_popc, NULL, NULL) 36779c6ec5bcSRichard Henderson 3678428881deSRichard Henderson static bool trans_OR(DisasContext *dc, arg_r_r_ri_cc *a) 3679428881deSRichard Henderson { 3680428881deSRichard Henderson /* OR with %g0 is the canonical alias for MOV. */ 3681428881deSRichard Henderson if (!a->cc && a->rs1 == 0) { 3682428881deSRichard Henderson if (a->imm || a->rs2_or_imm == 0) { 3683428881deSRichard Henderson gen_store_gpr(dc, a->rd, tcg_constant_tl(a->rs2_or_imm)); 3684428881deSRichard Henderson } else if (a->rs2_or_imm & ~0x1f) { 3685428881deSRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 3686428881deSRichard Henderson return false; 3687428881deSRichard Henderson } else { 3688428881deSRichard Henderson gen_store_gpr(dc, a->rd, cpu_regs[a->rs2_or_imm]); 3689428881deSRichard Henderson } 3690428881deSRichard Henderson return advance_pc(dc); 3691428881deSRichard Henderson } 3692428881deSRichard Henderson return do_logic(dc, a, tcg_gen_or_tl, tcg_gen_ori_tl); 3693428881deSRichard Henderson } 3694428881deSRichard Henderson 36953a6b8de3SRichard Henderson static bool trans_UDIV(DisasContext *dc, arg_r_r_ri *a) 36963a6b8de3SRichard Henderson { 36973a6b8de3SRichard Henderson TCGv_i64 t1, t2; 36983a6b8de3SRichard Henderson TCGv dst; 36993a6b8de3SRichard Henderson 37003a6b8de3SRichard Henderson if (!avail_DIV(dc)) { 37013a6b8de3SRichard Henderson return false; 37023a6b8de3SRichard Henderson } 37033a6b8de3SRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 37043a6b8de3SRichard Henderson if (!a->imm && a->rs2_or_imm & ~0x1f) { 37053a6b8de3SRichard Henderson return false; 37063a6b8de3SRichard Henderson } 37073a6b8de3SRichard Henderson 37083a6b8de3SRichard Henderson if (unlikely(a->rs2_or_imm == 0)) { 37093a6b8de3SRichard Henderson gen_exception(dc, TT_DIV_ZERO); 37103a6b8de3SRichard Henderson return true; 37113a6b8de3SRichard Henderson } 37123a6b8de3SRichard Henderson 37133a6b8de3SRichard Henderson if (a->imm) { 37143a6b8de3SRichard Henderson t2 = tcg_constant_i64((uint32_t)a->rs2_or_imm); 37153a6b8de3SRichard Henderson } else { 37163a6b8de3SRichard Henderson TCGLabel *lab; 37173a6b8de3SRichard Henderson TCGv_i32 n2; 37183a6b8de3SRichard Henderson 37193a6b8de3SRichard Henderson finishing_insn(dc); 37203a6b8de3SRichard Henderson flush_cond(dc); 37213a6b8de3SRichard Henderson 37223a6b8de3SRichard Henderson n2 = tcg_temp_new_i32(); 37233a6b8de3SRichard Henderson tcg_gen_trunc_tl_i32(n2, cpu_regs[a->rs2_or_imm]); 37243a6b8de3SRichard Henderson 37253a6b8de3SRichard Henderson lab = delay_exception(dc, TT_DIV_ZERO); 37263a6b8de3SRichard Henderson tcg_gen_brcondi_i32(TCG_COND_EQ, n2, 0, lab); 37273a6b8de3SRichard Henderson 37283a6b8de3SRichard Henderson t2 = tcg_temp_new_i64(); 37293a6b8de3SRichard Henderson #ifdef TARGET_SPARC64 37303a6b8de3SRichard Henderson tcg_gen_ext32u_i64(t2, cpu_regs[a->rs2_or_imm]); 37313a6b8de3SRichard Henderson #else 37323a6b8de3SRichard Henderson tcg_gen_extu_i32_i64(t2, cpu_regs[a->rs2_or_imm]); 37333a6b8de3SRichard Henderson #endif 37343a6b8de3SRichard Henderson } 37353a6b8de3SRichard Henderson 37363a6b8de3SRichard Henderson t1 = tcg_temp_new_i64(); 37373a6b8de3SRichard Henderson tcg_gen_concat_tl_i64(t1, gen_load_gpr(dc, a->rs1), cpu_y); 37383a6b8de3SRichard Henderson 37393a6b8de3SRichard Henderson tcg_gen_divu_i64(t1, t1, t2); 37403a6b8de3SRichard Henderson tcg_gen_umin_i64(t1, t1, tcg_constant_i64(UINT32_MAX)); 37413a6b8de3SRichard Henderson 37423a6b8de3SRichard Henderson dst = gen_dest_gpr(dc, a->rd); 37433a6b8de3SRichard Henderson tcg_gen_trunc_i64_tl(dst, t1); 37443a6b8de3SRichard Henderson gen_store_gpr(dc, a->rd, dst); 37453a6b8de3SRichard Henderson return advance_pc(dc); 37463a6b8de3SRichard Henderson } 37473a6b8de3SRichard Henderson 3748f3141174SRichard Henderson static bool trans_UDIVX(DisasContext *dc, arg_r_r_ri *a) 3749f3141174SRichard Henderson { 3750f3141174SRichard Henderson TCGv dst, src1, src2; 3751f3141174SRichard Henderson 3752f3141174SRichard Henderson if (!avail_64(dc)) { 3753f3141174SRichard Henderson return false; 3754f3141174SRichard Henderson } 3755f3141174SRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 3756f3141174SRichard Henderson if (!a->imm && a->rs2_or_imm & ~0x1f) { 3757f3141174SRichard Henderson return false; 3758f3141174SRichard Henderson } 3759f3141174SRichard Henderson 3760f3141174SRichard Henderson if (unlikely(a->rs2_or_imm == 0)) { 3761f3141174SRichard Henderson gen_exception(dc, TT_DIV_ZERO); 3762f3141174SRichard Henderson return true; 3763f3141174SRichard Henderson } 3764f3141174SRichard Henderson 3765f3141174SRichard Henderson if (a->imm) { 3766f3141174SRichard Henderson src2 = tcg_constant_tl(a->rs2_or_imm); 3767f3141174SRichard Henderson } else { 3768f3141174SRichard Henderson TCGLabel *lab; 3769f3141174SRichard Henderson 3770f3141174SRichard Henderson finishing_insn(dc); 3771f3141174SRichard Henderson flush_cond(dc); 3772f3141174SRichard Henderson 3773f3141174SRichard Henderson lab = delay_exception(dc, TT_DIV_ZERO); 3774f3141174SRichard Henderson src2 = cpu_regs[a->rs2_or_imm]; 3775f3141174SRichard Henderson tcg_gen_brcondi_tl(TCG_COND_EQ, src2, 0, lab); 3776f3141174SRichard Henderson } 3777f3141174SRichard Henderson 3778f3141174SRichard Henderson dst = gen_dest_gpr(dc, a->rd); 3779f3141174SRichard Henderson src1 = gen_load_gpr(dc, a->rs1); 3780f3141174SRichard Henderson 3781f3141174SRichard Henderson tcg_gen_divu_tl(dst, src1, src2); 3782f3141174SRichard Henderson gen_store_gpr(dc, a->rd, dst); 3783f3141174SRichard Henderson return advance_pc(dc); 3784f3141174SRichard Henderson } 3785f3141174SRichard Henderson 3786f3141174SRichard Henderson static bool trans_SDIVX(DisasContext *dc, arg_r_r_ri *a) 3787f3141174SRichard Henderson { 3788f3141174SRichard Henderson TCGv dst, src1, src2; 3789f3141174SRichard Henderson 3790f3141174SRichard Henderson if (!avail_64(dc)) { 3791f3141174SRichard Henderson return false; 3792f3141174SRichard Henderson } 3793f3141174SRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 3794f3141174SRichard Henderson if (!a->imm && a->rs2_or_imm & ~0x1f) { 3795f3141174SRichard Henderson return false; 3796f3141174SRichard Henderson } 3797f3141174SRichard Henderson 3798f3141174SRichard Henderson if (unlikely(a->rs2_or_imm == 0)) { 3799f3141174SRichard Henderson gen_exception(dc, TT_DIV_ZERO); 3800f3141174SRichard Henderson return true; 3801f3141174SRichard Henderson } 3802f3141174SRichard Henderson 3803f3141174SRichard Henderson dst = gen_dest_gpr(dc, a->rd); 3804f3141174SRichard Henderson src1 = gen_load_gpr(dc, a->rs1); 3805f3141174SRichard Henderson 3806f3141174SRichard Henderson if (a->imm) { 3807f3141174SRichard Henderson if (unlikely(a->rs2_or_imm == -1)) { 3808f3141174SRichard Henderson tcg_gen_neg_tl(dst, src1); 3809f3141174SRichard Henderson gen_store_gpr(dc, a->rd, dst); 3810f3141174SRichard Henderson return advance_pc(dc); 3811f3141174SRichard Henderson } 3812f3141174SRichard Henderson src2 = tcg_constant_tl(a->rs2_or_imm); 3813f3141174SRichard Henderson } else { 3814f3141174SRichard Henderson TCGLabel *lab; 3815f3141174SRichard Henderson TCGv t1, t2; 3816f3141174SRichard Henderson 3817f3141174SRichard Henderson finishing_insn(dc); 3818f3141174SRichard Henderson flush_cond(dc); 3819f3141174SRichard Henderson 3820f3141174SRichard Henderson lab = delay_exception(dc, TT_DIV_ZERO); 3821f3141174SRichard Henderson src2 = cpu_regs[a->rs2_or_imm]; 3822f3141174SRichard Henderson tcg_gen_brcondi_tl(TCG_COND_EQ, src2, 0, lab); 3823f3141174SRichard Henderson 3824f3141174SRichard Henderson /* 3825f3141174SRichard Henderson * Need to avoid INT64_MIN / -1, which will trap on x86 host. 3826f3141174SRichard Henderson * Set SRC2 to 1 as a new divisor, to produce the correct result. 3827f3141174SRichard Henderson */ 3828f3141174SRichard Henderson t1 = tcg_temp_new(); 3829f3141174SRichard Henderson t2 = tcg_temp_new(); 3830f3141174SRichard Henderson tcg_gen_setcondi_tl(TCG_COND_EQ, t1, src1, (target_long)INT64_MIN); 3831f3141174SRichard Henderson tcg_gen_setcondi_tl(TCG_COND_EQ, t2, src2, -1); 3832f3141174SRichard Henderson tcg_gen_and_tl(t1, t1, t2); 3833f3141174SRichard Henderson tcg_gen_movcond_tl(TCG_COND_NE, t1, t1, tcg_constant_tl(0), 3834f3141174SRichard Henderson tcg_constant_tl(1), src2); 3835f3141174SRichard Henderson src2 = t1; 3836f3141174SRichard Henderson } 3837f3141174SRichard Henderson 3838f3141174SRichard Henderson tcg_gen_div_tl(dst, src1, src2); 3839f3141174SRichard Henderson gen_store_gpr(dc, a->rd, dst); 3840f3141174SRichard Henderson return advance_pc(dc); 3841f3141174SRichard Henderson } 3842f3141174SRichard Henderson 3843b88ce6f2SRichard Henderson static bool gen_edge(DisasContext *dc, arg_r_r_r *a, 384443db5838SRichard Henderson int width, bool cc, bool little_endian) 3845b88ce6f2SRichard Henderson { 384643db5838SRichard Henderson TCGv dst, s1, s2, l, r, t, m; 384743db5838SRichard Henderson uint64_t amask = address_mask_i(dc, -8); 3848b88ce6f2SRichard Henderson 3849b88ce6f2SRichard Henderson dst = gen_dest_gpr(dc, a->rd); 3850b88ce6f2SRichard Henderson s1 = gen_load_gpr(dc, a->rs1); 3851b88ce6f2SRichard Henderson s2 = gen_load_gpr(dc, a->rs2); 3852b88ce6f2SRichard Henderson 3853b88ce6f2SRichard Henderson if (cc) { 3854f828df74SRichard Henderson gen_op_subcc(cpu_cc_N, s1, s2); 3855b88ce6f2SRichard Henderson } 3856b88ce6f2SRichard Henderson 385743db5838SRichard Henderson l = tcg_temp_new(); 385843db5838SRichard Henderson r = tcg_temp_new(); 385943db5838SRichard Henderson t = tcg_temp_new(); 386043db5838SRichard Henderson 3861b88ce6f2SRichard Henderson switch (width) { 3862b88ce6f2SRichard Henderson case 8: 386343db5838SRichard Henderson tcg_gen_andi_tl(l, s1, 7); 386443db5838SRichard Henderson tcg_gen_andi_tl(r, s2, 7); 386543db5838SRichard Henderson tcg_gen_xori_tl(r, r, 7); 386643db5838SRichard Henderson m = tcg_constant_tl(0xff); 3867b88ce6f2SRichard Henderson break; 3868b88ce6f2SRichard Henderson case 16: 386943db5838SRichard Henderson tcg_gen_extract_tl(l, s1, 1, 2); 387043db5838SRichard Henderson tcg_gen_extract_tl(r, s2, 1, 2); 387143db5838SRichard Henderson tcg_gen_xori_tl(r, r, 3); 387243db5838SRichard Henderson m = tcg_constant_tl(0xf); 3873b88ce6f2SRichard Henderson break; 3874b88ce6f2SRichard Henderson case 32: 387543db5838SRichard Henderson tcg_gen_extract_tl(l, s1, 2, 1); 387643db5838SRichard Henderson tcg_gen_extract_tl(r, s2, 2, 1); 387743db5838SRichard Henderson tcg_gen_xori_tl(r, r, 1); 387843db5838SRichard Henderson m = tcg_constant_tl(0x3); 3879b88ce6f2SRichard Henderson break; 3880b88ce6f2SRichard Henderson default: 3881b88ce6f2SRichard Henderson abort(); 3882b88ce6f2SRichard Henderson } 3883b88ce6f2SRichard Henderson 388443db5838SRichard Henderson /* Compute Left Edge */ 388543db5838SRichard Henderson if (little_endian) { 388643db5838SRichard Henderson tcg_gen_shl_tl(l, m, l); 388743db5838SRichard Henderson tcg_gen_and_tl(l, l, m); 388843db5838SRichard Henderson } else { 388943db5838SRichard Henderson tcg_gen_shr_tl(l, m, l); 389043db5838SRichard Henderson } 389143db5838SRichard Henderson /* Compute Right Edge */ 389243db5838SRichard Henderson if (little_endian) { 389343db5838SRichard Henderson tcg_gen_shr_tl(r, m, r); 389443db5838SRichard Henderson } else { 389543db5838SRichard Henderson tcg_gen_shl_tl(r, m, r); 389643db5838SRichard Henderson tcg_gen_and_tl(r, r, m); 389743db5838SRichard Henderson } 3898b88ce6f2SRichard Henderson 389943db5838SRichard Henderson /* Compute dst = (s1 == s2 under amask ? l : l & r) */ 390043db5838SRichard Henderson tcg_gen_xor_tl(t, s1, s2); 390143db5838SRichard Henderson tcg_gen_and_tl(r, r, l); 390243db5838SRichard Henderson tcg_gen_movcond_tl(TCG_COND_TSTEQ, dst, t, tcg_constant_tl(amask), r, l); 3903b88ce6f2SRichard Henderson 3904b88ce6f2SRichard Henderson gen_store_gpr(dc, a->rd, dst); 3905b88ce6f2SRichard Henderson return advance_pc(dc); 3906b88ce6f2SRichard Henderson } 3907b88ce6f2SRichard Henderson 3908b88ce6f2SRichard Henderson TRANS(EDGE8cc, VIS1, gen_edge, a, 8, 1, 0) 3909b88ce6f2SRichard Henderson TRANS(EDGE8Lcc, VIS1, gen_edge, a, 8, 1, 1) 3910b88ce6f2SRichard Henderson TRANS(EDGE16cc, VIS1, gen_edge, a, 16, 1, 0) 3911b88ce6f2SRichard Henderson TRANS(EDGE16Lcc, VIS1, gen_edge, a, 16, 1, 1) 3912b88ce6f2SRichard Henderson TRANS(EDGE32cc, VIS1, gen_edge, a, 32, 1, 0) 3913b88ce6f2SRichard Henderson TRANS(EDGE32Lcc, VIS1, gen_edge, a, 32, 1, 1) 3914b88ce6f2SRichard Henderson 3915b88ce6f2SRichard Henderson TRANS(EDGE8N, VIS2, gen_edge, a, 8, 0, 0) 3916b88ce6f2SRichard Henderson TRANS(EDGE8LN, VIS2, gen_edge, a, 8, 0, 1) 3917b88ce6f2SRichard Henderson TRANS(EDGE16N, VIS2, gen_edge, a, 16, 0, 0) 3918b88ce6f2SRichard Henderson TRANS(EDGE16LN, VIS2, gen_edge, a, 16, 0, 1) 3919b88ce6f2SRichard Henderson TRANS(EDGE32N, VIS2, gen_edge, a, 32, 0, 0) 3920b88ce6f2SRichard Henderson TRANS(EDGE32LN, VIS2, gen_edge, a, 32, 0, 1) 3921b88ce6f2SRichard Henderson 3922875ce392SRichard Henderson static bool do_rr(DisasContext *dc, arg_r_r *a, 3923875ce392SRichard Henderson void (*func)(TCGv, TCGv)) 3924875ce392SRichard Henderson { 3925875ce392SRichard Henderson TCGv dst = gen_dest_gpr(dc, a->rd); 3926875ce392SRichard Henderson TCGv src = gen_load_gpr(dc, a->rs); 3927875ce392SRichard Henderson 3928875ce392SRichard Henderson func(dst, src); 3929875ce392SRichard Henderson gen_store_gpr(dc, a->rd, dst); 3930875ce392SRichard Henderson return advance_pc(dc); 3931875ce392SRichard Henderson } 3932875ce392SRichard Henderson 3933875ce392SRichard Henderson TRANS(LZCNT, VIS3, do_rr, a, gen_op_lzcnt) 3934875ce392SRichard Henderson 393545bfed3bSRichard Henderson static bool do_rrr(DisasContext *dc, arg_r_r_r *a, 393645bfed3bSRichard Henderson void (*func)(TCGv, TCGv, TCGv)) 393745bfed3bSRichard Henderson { 393845bfed3bSRichard Henderson TCGv dst = gen_dest_gpr(dc, a->rd); 393945bfed3bSRichard Henderson TCGv src1 = gen_load_gpr(dc, a->rs1); 394045bfed3bSRichard Henderson TCGv src2 = gen_load_gpr(dc, a->rs2); 394145bfed3bSRichard Henderson 394245bfed3bSRichard Henderson func(dst, src1, src2); 394345bfed3bSRichard Henderson gen_store_gpr(dc, a->rd, dst); 394445bfed3bSRichard Henderson return advance_pc(dc); 394545bfed3bSRichard Henderson } 394645bfed3bSRichard Henderson 394745bfed3bSRichard Henderson TRANS(ARRAY8, VIS1, do_rrr, a, gen_helper_array8) 394845bfed3bSRichard Henderson TRANS(ARRAY16, VIS1, do_rrr, a, gen_op_array16) 394945bfed3bSRichard Henderson TRANS(ARRAY32, VIS1, do_rrr, a, gen_op_array32) 395045bfed3bSRichard Henderson 3951015fc6fcSRichard Henderson TRANS(ADDXC, VIS3, do_rrr, a, gen_op_addxc) 3952015fc6fcSRichard Henderson TRANS(ADDXCcc, VIS3, do_rrr, a, gen_op_addxccc) 3953015fc6fcSRichard Henderson 3954680af1b4SRichard Henderson TRANS(UMULXHI, VIS3, do_rrr, a, gen_op_umulxhi) 3955680af1b4SRichard Henderson 39569e20ca94SRichard Henderson static void gen_op_alignaddr(TCGv dst, TCGv s1, TCGv s2) 39579e20ca94SRichard Henderson { 39589e20ca94SRichard Henderson #ifdef TARGET_SPARC64 39599e20ca94SRichard Henderson TCGv tmp = tcg_temp_new(); 39609e20ca94SRichard Henderson 39619e20ca94SRichard Henderson tcg_gen_add_tl(tmp, s1, s2); 39629e20ca94SRichard Henderson tcg_gen_andi_tl(dst, tmp, -8); 39639e20ca94SRichard Henderson tcg_gen_deposit_tl(cpu_gsr, cpu_gsr, tmp, 0, 3); 39649e20ca94SRichard Henderson #else 39659e20ca94SRichard Henderson g_assert_not_reached(); 39669e20ca94SRichard Henderson #endif 39679e20ca94SRichard Henderson } 39689e20ca94SRichard Henderson 39699e20ca94SRichard Henderson static void gen_op_alignaddrl(TCGv dst, TCGv s1, TCGv s2) 39709e20ca94SRichard Henderson { 39719e20ca94SRichard Henderson #ifdef TARGET_SPARC64 39729e20ca94SRichard Henderson TCGv tmp = tcg_temp_new(); 39739e20ca94SRichard Henderson 39749e20ca94SRichard Henderson tcg_gen_add_tl(tmp, s1, s2); 39759e20ca94SRichard Henderson tcg_gen_andi_tl(dst, tmp, -8); 39769e20ca94SRichard Henderson tcg_gen_neg_tl(tmp, tmp); 39779e20ca94SRichard Henderson tcg_gen_deposit_tl(cpu_gsr, cpu_gsr, tmp, 0, 3); 39789e20ca94SRichard Henderson #else 39799e20ca94SRichard Henderson g_assert_not_reached(); 39809e20ca94SRichard Henderson #endif 39819e20ca94SRichard Henderson } 39829e20ca94SRichard Henderson 39839e20ca94SRichard Henderson TRANS(ALIGNADDR, VIS1, do_rrr, a, gen_op_alignaddr) 39849e20ca94SRichard Henderson TRANS(ALIGNADDRL, VIS1, do_rrr, a, gen_op_alignaddrl) 39859e20ca94SRichard Henderson 398639ca3490SRichard Henderson static void gen_op_bmask(TCGv dst, TCGv s1, TCGv s2) 398739ca3490SRichard Henderson { 398839ca3490SRichard Henderson #ifdef TARGET_SPARC64 398939ca3490SRichard Henderson tcg_gen_add_tl(dst, s1, s2); 399039ca3490SRichard Henderson tcg_gen_deposit_tl(cpu_gsr, cpu_gsr, dst, 32, 32); 399139ca3490SRichard Henderson #else 399239ca3490SRichard Henderson g_assert_not_reached(); 399339ca3490SRichard Henderson #endif 399439ca3490SRichard Henderson } 399539ca3490SRichard Henderson 399639ca3490SRichard Henderson TRANS(BMASK, VIS2, do_rrr, a, gen_op_bmask) 399739ca3490SRichard Henderson 3998c973b4e8SRichard Henderson static bool do_cmask(DisasContext *dc, int rs2, void (*func)(TCGv, TCGv, TCGv)) 3999c973b4e8SRichard Henderson { 4000c973b4e8SRichard Henderson func(cpu_gsr, cpu_gsr, gen_load_gpr(dc, rs2)); 4001c973b4e8SRichard Henderson return true; 4002c973b4e8SRichard Henderson } 4003c973b4e8SRichard Henderson 4004c973b4e8SRichard Henderson TRANS(CMASK8, VIS3, do_cmask, a->rs2, gen_helper_cmask8) 4005c973b4e8SRichard Henderson TRANS(CMASK16, VIS3, do_cmask, a->rs2, gen_helper_cmask16) 4006c973b4e8SRichard Henderson TRANS(CMASK32, VIS3, do_cmask, a->rs2, gen_helper_cmask32) 4007c973b4e8SRichard Henderson 40085fc546eeSRichard Henderson static bool do_shift_r(DisasContext *dc, arg_shiftr *a, bool l, bool u) 40095fc546eeSRichard Henderson { 40105fc546eeSRichard Henderson TCGv dst, src1, src2; 40115fc546eeSRichard Henderson 40125fc546eeSRichard Henderson /* Reject 64-bit shifts for sparc32. */ 40135fc546eeSRichard Henderson if (avail_32(dc) && a->x) { 40145fc546eeSRichard Henderson return false; 40155fc546eeSRichard Henderson } 40165fc546eeSRichard Henderson 40175fc546eeSRichard Henderson src2 = tcg_temp_new(); 40185fc546eeSRichard Henderson tcg_gen_andi_tl(src2, gen_load_gpr(dc, a->rs2), a->x ? 63 : 31); 40195fc546eeSRichard Henderson src1 = gen_load_gpr(dc, a->rs1); 40205fc546eeSRichard Henderson dst = gen_dest_gpr(dc, a->rd); 40215fc546eeSRichard Henderson 40225fc546eeSRichard Henderson if (l) { 40235fc546eeSRichard Henderson tcg_gen_shl_tl(dst, src1, src2); 40245fc546eeSRichard Henderson if (!a->x) { 40255fc546eeSRichard Henderson tcg_gen_ext32u_tl(dst, dst); 40265fc546eeSRichard Henderson } 40275fc546eeSRichard Henderson } else if (u) { 40285fc546eeSRichard Henderson if (!a->x) { 40295fc546eeSRichard Henderson tcg_gen_ext32u_tl(dst, src1); 40305fc546eeSRichard Henderson src1 = dst; 40315fc546eeSRichard Henderson } 40325fc546eeSRichard Henderson tcg_gen_shr_tl(dst, src1, src2); 40335fc546eeSRichard Henderson } else { 40345fc546eeSRichard Henderson if (!a->x) { 40355fc546eeSRichard Henderson tcg_gen_ext32s_tl(dst, src1); 40365fc546eeSRichard Henderson src1 = dst; 40375fc546eeSRichard Henderson } 40385fc546eeSRichard Henderson tcg_gen_sar_tl(dst, src1, src2); 40395fc546eeSRichard Henderson } 40405fc546eeSRichard Henderson gen_store_gpr(dc, a->rd, dst); 40415fc546eeSRichard Henderson return advance_pc(dc); 40425fc546eeSRichard Henderson } 40435fc546eeSRichard Henderson 40445fc546eeSRichard Henderson TRANS(SLL_r, ALL, do_shift_r, a, true, true) 40455fc546eeSRichard Henderson TRANS(SRL_r, ALL, do_shift_r, a, false, true) 40465fc546eeSRichard Henderson TRANS(SRA_r, ALL, do_shift_r, a, false, false) 40475fc546eeSRichard Henderson 40485fc546eeSRichard Henderson static bool do_shift_i(DisasContext *dc, arg_shifti *a, bool l, bool u) 40495fc546eeSRichard Henderson { 40505fc546eeSRichard Henderson TCGv dst, src1; 40515fc546eeSRichard Henderson 40525fc546eeSRichard Henderson /* Reject 64-bit shifts for sparc32. */ 40535fc546eeSRichard Henderson if (avail_32(dc) && (a->x || a->i >= 32)) { 40545fc546eeSRichard Henderson return false; 40555fc546eeSRichard Henderson } 40565fc546eeSRichard Henderson 40575fc546eeSRichard Henderson src1 = gen_load_gpr(dc, a->rs1); 40585fc546eeSRichard Henderson dst = gen_dest_gpr(dc, a->rd); 40595fc546eeSRichard Henderson 40605fc546eeSRichard Henderson if (avail_32(dc) || a->x) { 40615fc546eeSRichard Henderson if (l) { 40625fc546eeSRichard Henderson tcg_gen_shli_tl(dst, src1, a->i); 40635fc546eeSRichard Henderson } else if (u) { 40645fc546eeSRichard Henderson tcg_gen_shri_tl(dst, src1, a->i); 40655fc546eeSRichard Henderson } else { 40665fc546eeSRichard Henderson tcg_gen_sari_tl(dst, src1, a->i); 40675fc546eeSRichard Henderson } 40685fc546eeSRichard Henderson } else { 40695fc546eeSRichard Henderson if (l) { 40705fc546eeSRichard Henderson tcg_gen_deposit_z_tl(dst, src1, a->i, 32 - a->i); 40715fc546eeSRichard Henderson } else if (u) { 40725fc546eeSRichard Henderson tcg_gen_extract_tl(dst, src1, a->i, 32 - a->i); 40735fc546eeSRichard Henderson } else { 40745fc546eeSRichard Henderson tcg_gen_sextract_tl(dst, src1, a->i, 32 - a->i); 40755fc546eeSRichard Henderson } 40765fc546eeSRichard Henderson } 40775fc546eeSRichard Henderson gen_store_gpr(dc, a->rd, dst); 40785fc546eeSRichard Henderson return advance_pc(dc); 40795fc546eeSRichard Henderson } 40805fc546eeSRichard Henderson 40815fc546eeSRichard Henderson TRANS(SLL_i, ALL, do_shift_i, a, true, true) 40825fc546eeSRichard Henderson TRANS(SRL_i, ALL, do_shift_i, a, false, true) 40835fc546eeSRichard Henderson TRANS(SRA_i, ALL, do_shift_i, a, false, false) 40845fc546eeSRichard Henderson 4085fb4ed7aaSRichard Henderson static TCGv gen_rs2_or_imm(DisasContext *dc, bool imm, int rs2_or_imm) 4086fb4ed7aaSRichard Henderson { 4087fb4ed7aaSRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 4088fb4ed7aaSRichard Henderson if (!imm && rs2_or_imm & ~0x1f) { 4089fb4ed7aaSRichard Henderson return NULL; 4090fb4ed7aaSRichard Henderson } 4091fb4ed7aaSRichard Henderson if (imm || rs2_or_imm == 0) { 4092fb4ed7aaSRichard Henderson return tcg_constant_tl(rs2_or_imm); 4093fb4ed7aaSRichard Henderson } else { 4094fb4ed7aaSRichard Henderson return cpu_regs[rs2_or_imm]; 4095fb4ed7aaSRichard Henderson } 4096fb4ed7aaSRichard Henderson } 4097fb4ed7aaSRichard Henderson 4098fb4ed7aaSRichard Henderson static bool do_mov_cond(DisasContext *dc, DisasCompare *cmp, int rd, TCGv src2) 4099fb4ed7aaSRichard Henderson { 4100fb4ed7aaSRichard Henderson TCGv dst = gen_load_gpr(dc, rd); 4101c8507ebfSRichard Henderson TCGv c2 = tcg_constant_tl(cmp->c2); 4102fb4ed7aaSRichard Henderson 4103c8507ebfSRichard Henderson tcg_gen_movcond_tl(cmp->cond, dst, cmp->c1, c2, src2, dst); 4104fb4ed7aaSRichard Henderson gen_store_gpr(dc, rd, dst); 4105fb4ed7aaSRichard Henderson return advance_pc(dc); 4106fb4ed7aaSRichard Henderson } 4107fb4ed7aaSRichard Henderson 4108fb4ed7aaSRichard Henderson static bool trans_MOVcc(DisasContext *dc, arg_MOVcc *a) 4109fb4ed7aaSRichard Henderson { 4110fb4ed7aaSRichard Henderson TCGv src2 = gen_rs2_or_imm(dc, a->imm, a->rs2_or_imm); 4111fb4ed7aaSRichard Henderson DisasCompare cmp; 4112fb4ed7aaSRichard Henderson 4113fb4ed7aaSRichard Henderson if (src2 == NULL) { 4114fb4ed7aaSRichard Henderson return false; 4115fb4ed7aaSRichard Henderson } 4116fb4ed7aaSRichard Henderson gen_compare(&cmp, a->cc, a->cond, dc); 4117fb4ed7aaSRichard Henderson return do_mov_cond(dc, &cmp, a->rd, src2); 4118fb4ed7aaSRichard Henderson } 4119fb4ed7aaSRichard Henderson 4120fb4ed7aaSRichard Henderson static bool trans_MOVfcc(DisasContext *dc, arg_MOVfcc *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_fcompare(&cmp, a->cc, a->cond); 4129fb4ed7aaSRichard Henderson return do_mov_cond(dc, &cmp, a->rd, src2); 4130fb4ed7aaSRichard Henderson } 4131fb4ed7aaSRichard Henderson 4132fb4ed7aaSRichard Henderson static bool trans_MOVR(DisasContext *dc, arg_MOVR *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 } 41402c4f56c9SRichard Henderson if (!gen_compare_reg(&cmp, a->cond, gen_load_gpr(dc, a->rs1))) { 41412c4f56c9SRichard Henderson return false; 41422c4f56c9SRichard Henderson } 4143fb4ed7aaSRichard Henderson return do_mov_cond(dc, &cmp, a->rd, src2); 4144fb4ed7aaSRichard Henderson } 4145fb4ed7aaSRichard Henderson 414686b82fe0SRichard Henderson static bool do_add_special(DisasContext *dc, arg_r_r_ri *a, 414786b82fe0SRichard Henderson bool (*func)(DisasContext *dc, int rd, TCGv src)) 414886b82fe0SRichard Henderson { 414986b82fe0SRichard Henderson TCGv src1, sum; 415086b82fe0SRichard Henderson 415186b82fe0SRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 415286b82fe0SRichard Henderson if (!a->imm && a->rs2_or_imm & ~0x1f) { 415386b82fe0SRichard Henderson return false; 415486b82fe0SRichard Henderson } 415586b82fe0SRichard Henderson 415686b82fe0SRichard Henderson /* 415786b82fe0SRichard Henderson * Always load the sum into a new temporary. 415886b82fe0SRichard Henderson * This is required to capture the value across a window change, 415986b82fe0SRichard Henderson * e.g. SAVE and RESTORE, and may be optimized away otherwise. 416086b82fe0SRichard Henderson */ 416186b82fe0SRichard Henderson sum = tcg_temp_new(); 416286b82fe0SRichard Henderson src1 = gen_load_gpr(dc, a->rs1); 416386b82fe0SRichard Henderson if (a->imm || a->rs2_or_imm == 0) { 416486b82fe0SRichard Henderson tcg_gen_addi_tl(sum, src1, a->rs2_or_imm); 416586b82fe0SRichard Henderson } else { 416686b82fe0SRichard Henderson tcg_gen_add_tl(sum, src1, cpu_regs[a->rs2_or_imm]); 416786b82fe0SRichard Henderson } 416886b82fe0SRichard Henderson return func(dc, a->rd, sum); 416986b82fe0SRichard Henderson } 417086b82fe0SRichard Henderson 417186b82fe0SRichard Henderson static bool do_jmpl(DisasContext *dc, int rd, TCGv src) 417286b82fe0SRichard Henderson { 417386b82fe0SRichard Henderson /* 417486b82fe0SRichard Henderson * Preserve pc across advance, so that we can delay 417586b82fe0SRichard Henderson * the writeback to rd until after src is consumed. 417686b82fe0SRichard Henderson */ 417786b82fe0SRichard Henderson target_ulong cur_pc = dc->pc; 417886b82fe0SRichard Henderson 417986b82fe0SRichard Henderson gen_check_align(dc, src, 3); 418086b82fe0SRichard Henderson 418186b82fe0SRichard Henderson gen_mov_pc_npc(dc); 418286b82fe0SRichard Henderson tcg_gen_mov_tl(cpu_npc, src); 418386b82fe0SRichard Henderson gen_address_mask(dc, cpu_npc); 418486b82fe0SRichard Henderson gen_store_gpr(dc, rd, tcg_constant_tl(cur_pc)); 418586b82fe0SRichard Henderson 418686b82fe0SRichard Henderson dc->npc = DYNAMIC_PC_LOOKUP; 418786b82fe0SRichard Henderson return true; 418886b82fe0SRichard Henderson } 418986b82fe0SRichard Henderson 419086b82fe0SRichard Henderson TRANS(JMPL, ALL, do_add_special, a, do_jmpl) 419186b82fe0SRichard Henderson 419286b82fe0SRichard Henderson static bool do_rett(DisasContext *dc, int rd, TCGv src) 419386b82fe0SRichard Henderson { 419486b82fe0SRichard Henderson if (!supervisor(dc)) { 419586b82fe0SRichard Henderson return raise_priv(dc); 419686b82fe0SRichard Henderson } 419786b82fe0SRichard Henderson 419886b82fe0SRichard Henderson gen_check_align(dc, src, 3); 419986b82fe0SRichard Henderson 420086b82fe0SRichard Henderson gen_mov_pc_npc(dc); 420186b82fe0SRichard Henderson tcg_gen_mov_tl(cpu_npc, src); 420286b82fe0SRichard Henderson gen_helper_rett(tcg_env); 420386b82fe0SRichard Henderson 420486b82fe0SRichard Henderson dc->npc = DYNAMIC_PC; 420586b82fe0SRichard Henderson return true; 420686b82fe0SRichard Henderson } 420786b82fe0SRichard Henderson 420886b82fe0SRichard Henderson TRANS(RETT, 32, do_add_special, a, do_rett) 420986b82fe0SRichard Henderson 421086b82fe0SRichard Henderson static bool do_return(DisasContext *dc, int rd, TCGv src) 421186b82fe0SRichard Henderson { 421286b82fe0SRichard Henderson gen_check_align(dc, src, 3); 42130dfae4f9SRichard Henderson gen_helper_restore(tcg_env); 421486b82fe0SRichard Henderson 421586b82fe0SRichard Henderson gen_mov_pc_npc(dc); 421686b82fe0SRichard Henderson tcg_gen_mov_tl(cpu_npc, src); 421786b82fe0SRichard Henderson gen_address_mask(dc, cpu_npc); 421886b82fe0SRichard Henderson 421986b82fe0SRichard Henderson dc->npc = DYNAMIC_PC_LOOKUP; 422086b82fe0SRichard Henderson return true; 422186b82fe0SRichard Henderson } 422286b82fe0SRichard Henderson 422386b82fe0SRichard Henderson TRANS(RETURN, 64, do_add_special, a, do_return) 422486b82fe0SRichard Henderson 4225d3825800SRichard Henderson static bool do_save(DisasContext *dc, int rd, TCGv src) 4226d3825800SRichard Henderson { 4227d3825800SRichard Henderson gen_helper_save(tcg_env); 4228d3825800SRichard Henderson gen_store_gpr(dc, rd, src); 4229d3825800SRichard Henderson return advance_pc(dc); 4230d3825800SRichard Henderson } 4231d3825800SRichard Henderson 4232d3825800SRichard Henderson TRANS(SAVE, ALL, do_add_special, a, do_save) 4233d3825800SRichard Henderson 4234d3825800SRichard Henderson static bool do_restore(DisasContext *dc, int rd, TCGv src) 4235d3825800SRichard Henderson { 4236d3825800SRichard Henderson gen_helper_restore(tcg_env); 4237d3825800SRichard Henderson gen_store_gpr(dc, rd, src); 4238d3825800SRichard Henderson return advance_pc(dc); 4239d3825800SRichard Henderson } 4240d3825800SRichard Henderson 4241d3825800SRichard Henderson TRANS(RESTORE, ALL, do_add_special, a, do_restore) 4242d3825800SRichard Henderson 42438f75b8a4SRichard Henderson static bool do_done_retry(DisasContext *dc, bool done) 42448f75b8a4SRichard Henderson { 42458f75b8a4SRichard Henderson if (!supervisor(dc)) { 42468f75b8a4SRichard Henderson return raise_priv(dc); 42478f75b8a4SRichard Henderson } 42488f75b8a4SRichard Henderson dc->npc = DYNAMIC_PC; 42498f75b8a4SRichard Henderson dc->pc = DYNAMIC_PC; 42508f75b8a4SRichard Henderson translator_io_start(&dc->base); 42518f75b8a4SRichard Henderson if (done) { 42528f75b8a4SRichard Henderson gen_helper_done(tcg_env); 42538f75b8a4SRichard Henderson } else { 42548f75b8a4SRichard Henderson gen_helper_retry(tcg_env); 42558f75b8a4SRichard Henderson } 42568f75b8a4SRichard Henderson return true; 42578f75b8a4SRichard Henderson } 42588f75b8a4SRichard Henderson 42598f75b8a4SRichard Henderson TRANS(DONE, 64, do_done_retry, true) 42608f75b8a4SRichard Henderson TRANS(RETRY, 64, do_done_retry, false) 42618f75b8a4SRichard Henderson 42620880d20bSRichard Henderson /* 42630880d20bSRichard Henderson * Major opcode 11 -- load and store instructions 42640880d20bSRichard Henderson */ 42650880d20bSRichard Henderson 42660880d20bSRichard Henderson static TCGv gen_ldst_addr(DisasContext *dc, int rs1, bool imm, int rs2_or_imm) 42670880d20bSRichard Henderson { 42680880d20bSRichard Henderson TCGv addr, tmp = NULL; 42690880d20bSRichard Henderson 42700880d20bSRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 42710880d20bSRichard Henderson if (!imm && rs2_or_imm & ~0x1f) { 42720880d20bSRichard Henderson return NULL; 42730880d20bSRichard Henderson } 42740880d20bSRichard Henderson 42750880d20bSRichard Henderson addr = gen_load_gpr(dc, rs1); 42760880d20bSRichard Henderson if (rs2_or_imm) { 42770880d20bSRichard Henderson tmp = tcg_temp_new(); 42780880d20bSRichard Henderson if (imm) { 42790880d20bSRichard Henderson tcg_gen_addi_tl(tmp, addr, rs2_or_imm); 42800880d20bSRichard Henderson } else { 42810880d20bSRichard Henderson tcg_gen_add_tl(tmp, addr, cpu_regs[rs2_or_imm]); 42820880d20bSRichard Henderson } 42830880d20bSRichard Henderson addr = tmp; 42840880d20bSRichard Henderson } 42850880d20bSRichard Henderson if (AM_CHECK(dc)) { 42860880d20bSRichard Henderson if (!tmp) { 42870880d20bSRichard Henderson tmp = tcg_temp_new(); 42880880d20bSRichard Henderson } 42890880d20bSRichard Henderson tcg_gen_ext32u_tl(tmp, addr); 42900880d20bSRichard Henderson addr = tmp; 42910880d20bSRichard Henderson } 42920880d20bSRichard Henderson return addr; 42930880d20bSRichard Henderson } 42940880d20bSRichard Henderson 42950880d20bSRichard Henderson static bool do_ld_gpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp mop) 42960880d20bSRichard Henderson { 42970880d20bSRichard Henderson TCGv reg, addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 42980880d20bSRichard Henderson DisasASI da; 42990880d20bSRichard Henderson 43000880d20bSRichard Henderson if (addr == NULL) { 43010880d20bSRichard Henderson return false; 43020880d20bSRichard Henderson } 43030880d20bSRichard Henderson da = resolve_asi(dc, a->asi, mop); 43040880d20bSRichard Henderson 43050880d20bSRichard Henderson reg = gen_dest_gpr(dc, a->rd); 430642071fc1SRichard Henderson gen_ld_asi(dc, &da, reg, addr); 43070880d20bSRichard Henderson gen_store_gpr(dc, a->rd, reg); 43080880d20bSRichard Henderson return advance_pc(dc); 43090880d20bSRichard Henderson } 43100880d20bSRichard Henderson 43110880d20bSRichard Henderson TRANS(LDUW, ALL, do_ld_gpr, a, MO_TEUL) 43120880d20bSRichard Henderson TRANS(LDUB, ALL, do_ld_gpr, a, MO_UB) 43130880d20bSRichard Henderson TRANS(LDUH, ALL, do_ld_gpr, a, MO_TEUW) 43140880d20bSRichard Henderson TRANS(LDSB, ALL, do_ld_gpr, a, MO_SB) 43150880d20bSRichard Henderson TRANS(LDSH, ALL, do_ld_gpr, a, MO_TESW) 43160880d20bSRichard Henderson TRANS(LDSW, 64, do_ld_gpr, a, MO_TESL) 43170880d20bSRichard Henderson TRANS(LDX, 64, do_ld_gpr, a, MO_TEUQ) 43180880d20bSRichard Henderson 43190880d20bSRichard Henderson static bool do_st_gpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp mop) 43200880d20bSRichard Henderson { 43210880d20bSRichard Henderson TCGv reg, addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 43220880d20bSRichard Henderson DisasASI da; 43230880d20bSRichard Henderson 43240880d20bSRichard Henderson if (addr == NULL) { 43250880d20bSRichard Henderson return false; 43260880d20bSRichard Henderson } 43270880d20bSRichard Henderson da = resolve_asi(dc, a->asi, mop); 43280880d20bSRichard Henderson 43290880d20bSRichard Henderson reg = gen_load_gpr(dc, a->rd); 433042071fc1SRichard Henderson gen_st_asi(dc, &da, reg, addr); 43310880d20bSRichard Henderson return advance_pc(dc); 43320880d20bSRichard Henderson } 43330880d20bSRichard Henderson 43340880d20bSRichard Henderson TRANS(STW, ALL, do_st_gpr, a, MO_TEUL) 43350880d20bSRichard Henderson TRANS(STB, ALL, do_st_gpr, a, MO_UB) 43360880d20bSRichard Henderson TRANS(STH, ALL, do_st_gpr, a, MO_TEUW) 43370880d20bSRichard Henderson TRANS(STX, 64, do_st_gpr, a, MO_TEUQ) 43380880d20bSRichard Henderson 43390880d20bSRichard Henderson static bool trans_LDD(DisasContext *dc, arg_r_r_ri_asi *a) 43400880d20bSRichard Henderson { 43410880d20bSRichard Henderson TCGv addr; 43420880d20bSRichard Henderson DisasASI da; 43430880d20bSRichard Henderson 43440880d20bSRichard Henderson if (a->rd & 1) { 43450880d20bSRichard Henderson return false; 43460880d20bSRichard Henderson } 43470880d20bSRichard Henderson addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 43480880d20bSRichard Henderson if (addr == NULL) { 43490880d20bSRichard Henderson return false; 43500880d20bSRichard Henderson } 43510880d20bSRichard Henderson da = resolve_asi(dc, a->asi, MO_TEUQ); 435242071fc1SRichard Henderson gen_ldda_asi(dc, &da, addr, a->rd); 43530880d20bSRichard Henderson return advance_pc(dc); 43540880d20bSRichard Henderson } 43550880d20bSRichard Henderson 43560880d20bSRichard Henderson static bool trans_STD(DisasContext *dc, arg_r_r_ri_asi *a) 43570880d20bSRichard Henderson { 43580880d20bSRichard Henderson TCGv addr; 43590880d20bSRichard Henderson DisasASI da; 43600880d20bSRichard Henderson 43610880d20bSRichard Henderson if (a->rd & 1) { 43620880d20bSRichard Henderson return false; 43630880d20bSRichard Henderson } 43640880d20bSRichard Henderson addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 43650880d20bSRichard Henderson if (addr == NULL) { 43660880d20bSRichard Henderson return false; 43670880d20bSRichard Henderson } 43680880d20bSRichard Henderson da = resolve_asi(dc, a->asi, MO_TEUQ); 436942071fc1SRichard Henderson gen_stda_asi(dc, &da, addr, a->rd); 43700880d20bSRichard Henderson return advance_pc(dc); 43710880d20bSRichard Henderson } 43720880d20bSRichard Henderson 4373cf07cd1eSRichard Henderson static bool trans_LDSTUB(DisasContext *dc, arg_r_r_ri_asi *a) 4374cf07cd1eSRichard Henderson { 4375cf07cd1eSRichard Henderson TCGv addr, reg; 4376cf07cd1eSRichard Henderson DisasASI da; 4377cf07cd1eSRichard Henderson 4378cf07cd1eSRichard Henderson addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 4379cf07cd1eSRichard Henderson if (addr == NULL) { 4380cf07cd1eSRichard Henderson return false; 4381cf07cd1eSRichard Henderson } 4382cf07cd1eSRichard Henderson da = resolve_asi(dc, a->asi, MO_UB); 4383cf07cd1eSRichard Henderson 4384cf07cd1eSRichard Henderson reg = gen_dest_gpr(dc, a->rd); 4385cf07cd1eSRichard Henderson gen_ldstub_asi(dc, &da, reg, addr); 4386cf07cd1eSRichard Henderson gen_store_gpr(dc, a->rd, reg); 4387cf07cd1eSRichard Henderson return advance_pc(dc); 4388cf07cd1eSRichard Henderson } 4389cf07cd1eSRichard Henderson 4390dca544b9SRichard Henderson static bool trans_SWAP(DisasContext *dc, arg_r_r_ri_asi *a) 4391dca544b9SRichard Henderson { 4392dca544b9SRichard Henderson TCGv addr, dst, src; 4393dca544b9SRichard Henderson DisasASI da; 4394dca544b9SRichard Henderson 4395dca544b9SRichard Henderson addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 4396dca544b9SRichard Henderson if (addr == NULL) { 4397dca544b9SRichard Henderson return false; 4398dca544b9SRichard Henderson } 4399dca544b9SRichard Henderson da = resolve_asi(dc, a->asi, MO_TEUL); 4400dca544b9SRichard Henderson 4401dca544b9SRichard Henderson dst = gen_dest_gpr(dc, a->rd); 4402dca544b9SRichard Henderson src = gen_load_gpr(dc, a->rd); 4403dca544b9SRichard Henderson gen_swap_asi(dc, &da, dst, src, addr); 4404dca544b9SRichard Henderson gen_store_gpr(dc, a->rd, dst); 4405dca544b9SRichard Henderson return advance_pc(dc); 4406dca544b9SRichard Henderson } 4407dca544b9SRichard Henderson 4408d0a11d25SRichard Henderson static bool do_casa(DisasContext *dc, arg_r_r_ri_asi *a, MemOp mop) 4409d0a11d25SRichard Henderson { 4410d0a11d25SRichard Henderson TCGv addr, o, n, c; 4411d0a11d25SRichard Henderson DisasASI da; 4412d0a11d25SRichard Henderson 4413d0a11d25SRichard Henderson addr = gen_ldst_addr(dc, a->rs1, true, 0); 4414d0a11d25SRichard Henderson if (addr == NULL) { 4415d0a11d25SRichard Henderson return false; 4416d0a11d25SRichard Henderson } 4417d0a11d25SRichard Henderson da = resolve_asi(dc, a->asi, mop); 4418d0a11d25SRichard Henderson 4419d0a11d25SRichard Henderson o = gen_dest_gpr(dc, a->rd); 4420d0a11d25SRichard Henderson n = gen_load_gpr(dc, a->rd); 4421d0a11d25SRichard Henderson c = gen_load_gpr(dc, a->rs2_or_imm); 4422d0a11d25SRichard Henderson gen_cas_asi(dc, &da, o, n, c, addr); 4423d0a11d25SRichard Henderson gen_store_gpr(dc, a->rd, o); 4424d0a11d25SRichard Henderson return advance_pc(dc); 4425d0a11d25SRichard Henderson } 4426d0a11d25SRichard Henderson 4427d0a11d25SRichard Henderson TRANS(CASA, CASA, do_casa, a, MO_TEUL) 4428d0a11d25SRichard Henderson TRANS(CASXA, 64, do_casa, a, MO_TEUQ) 4429d0a11d25SRichard Henderson 443006c060d9SRichard Henderson static bool do_ld_fpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp sz) 443106c060d9SRichard Henderson { 443206c060d9SRichard Henderson TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 443306c060d9SRichard Henderson DisasASI da; 443406c060d9SRichard Henderson 443506c060d9SRichard Henderson if (addr == NULL) { 443606c060d9SRichard Henderson return false; 443706c060d9SRichard Henderson } 443806c060d9SRichard Henderson if (gen_trap_ifnofpu(dc)) { 443906c060d9SRichard Henderson return true; 444006c060d9SRichard Henderson } 444106c060d9SRichard Henderson if (sz == MO_128 && gen_trap_float128(dc)) { 444206c060d9SRichard Henderson return true; 444306c060d9SRichard Henderson } 444406c060d9SRichard Henderson da = resolve_asi(dc, a->asi, MO_TE | sz); 4445287b1152SRichard Henderson gen_ldf_asi(dc, &da, sz, addr, a->rd); 444606c060d9SRichard Henderson gen_update_fprs_dirty(dc, a->rd); 444706c060d9SRichard Henderson return advance_pc(dc); 444806c060d9SRichard Henderson } 444906c060d9SRichard Henderson 445006c060d9SRichard Henderson TRANS(LDF, ALL, do_ld_fpr, a, MO_32) 445106c060d9SRichard Henderson TRANS(LDDF, ALL, do_ld_fpr, a, MO_64) 445206c060d9SRichard Henderson TRANS(LDQF, ALL, do_ld_fpr, a, MO_128) 445306c060d9SRichard Henderson 4454287b1152SRichard Henderson TRANS(LDFA, 64, do_ld_fpr, a, MO_32) 4455287b1152SRichard Henderson TRANS(LDDFA, 64, do_ld_fpr, a, MO_64) 4456287b1152SRichard Henderson TRANS(LDQFA, 64, do_ld_fpr, a, MO_128) 4457287b1152SRichard Henderson 445806c060d9SRichard Henderson static bool do_st_fpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp sz) 445906c060d9SRichard Henderson { 446006c060d9SRichard Henderson TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 446106c060d9SRichard Henderson DisasASI da; 446206c060d9SRichard Henderson 446306c060d9SRichard Henderson if (addr == NULL) { 446406c060d9SRichard Henderson return false; 446506c060d9SRichard Henderson } 446606c060d9SRichard Henderson if (gen_trap_ifnofpu(dc)) { 446706c060d9SRichard Henderson return true; 446806c060d9SRichard Henderson } 446906c060d9SRichard Henderson if (sz == MO_128 && gen_trap_float128(dc)) { 447006c060d9SRichard Henderson return true; 447106c060d9SRichard Henderson } 447206c060d9SRichard Henderson da = resolve_asi(dc, a->asi, MO_TE | sz); 4473287b1152SRichard Henderson gen_stf_asi(dc, &da, sz, addr, a->rd); 447406c060d9SRichard Henderson return advance_pc(dc); 447506c060d9SRichard Henderson } 447606c060d9SRichard Henderson 447706c060d9SRichard Henderson TRANS(STF, ALL, do_st_fpr, a, MO_32) 447806c060d9SRichard Henderson TRANS(STDF, ALL, do_st_fpr, a, MO_64) 447906c060d9SRichard Henderson TRANS(STQF, ALL, do_st_fpr, a, MO_128) 448006c060d9SRichard Henderson 4481287b1152SRichard Henderson TRANS(STFA, 64, do_st_fpr, a, MO_32) 4482287b1152SRichard Henderson TRANS(STDFA, 64, do_st_fpr, a, MO_64) 4483287b1152SRichard Henderson TRANS(STQFA, 64, do_st_fpr, a, MO_128) 4484287b1152SRichard Henderson 448506c060d9SRichard Henderson static bool trans_STDFQ(DisasContext *dc, arg_STDFQ *a) 448606c060d9SRichard Henderson { 448706c060d9SRichard Henderson if (!avail_32(dc)) { 448806c060d9SRichard Henderson return false; 448906c060d9SRichard Henderson } 449006c060d9SRichard Henderson if (!supervisor(dc)) { 449106c060d9SRichard Henderson return raise_priv(dc); 449206c060d9SRichard Henderson } 449306c060d9SRichard Henderson if (gen_trap_ifnofpu(dc)) { 449406c060d9SRichard Henderson return true; 449506c060d9SRichard Henderson } 449606c060d9SRichard Henderson gen_op_fpexception_im(dc, FSR_FTT_SEQ_ERROR); 449706c060d9SRichard Henderson return true; 449806c060d9SRichard Henderson } 449906c060d9SRichard Henderson 4500d8c5b92fSRichard Henderson static bool trans_LDFSR(DisasContext *dc, arg_r_r_ri *a) 45013d3c0673SRichard Henderson { 45023590f01eSRichard Henderson TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 4503d8c5b92fSRichard Henderson TCGv_i32 tmp; 45043590f01eSRichard Henderson 45053d3c0673SRichard Henderson if (addr == NULL) { 45063d3c0673SRichard Henderson return false; 45073d3c0673SRichard Henderson } 45083d3c0673SRichard Henderson if (gen_trap_ifnofpu(dc)) { 45093d3c0673SRichard Henderson return true; 45103d3c0673SRichard Henderson } 4511d8c5b92fSRichard Henderson 4512d8c5b92fSRichard Henderson tmp = tcg_temp_new_i32(); 4513d8c5b92fSRichard Henderson tcg_gen_qemu_ld_i32(tmp, addr, dc->mem_idx, MO_TEUL | MO_ALIGN); 4514d8c5b92fSRichard Henderson 4515d8c5b92fSRichard Henderson tcg_gen_extract_i32(cpu_fcc[0], tmp, FSR_FCC0_SHIFT, 2); 4516d8c5b92fSRichard Henderson /* LDFSR does not change FCC[1-3]. */ 4517d8c5b92fSRichard Henderson 4518d8c5b92fSRichard Henderson gen_helper_set_fsr_nofcc_noftt(tcg_env, tmp); 45193d3c0673SRichard Henderson return advance_pc(dc); 45203d3c0673SRichard Henderson } 45213d3c0673SRichard Henderson 4522298c52f7SRichard Henderson static bool do_ldxfsr(DisasContext *dc, arg_r_r_ri *a, bool entire) 4523d8c5b92fSRichard Henderson { 4524d8c5b92fSRichard Henderson #ifdef TARGET_SPARC64 4525d8c5b92fSRichard Henderson TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 4526d8c5b92fSRichard Henderson TCGv_i64 t64; 4527d8c5b92fSRichard Henderson TCGv_i32 lo, hi; 4528d8c5b92fSRichard Henderson 4529d8c5b92fSRichard Henderson if (addr == NULL) { 4530d8c5b92fSRichard Henderson return false; 4531d8c5b92fSRichard Henderson } 4532d8c5b92fSRichard Henderson if (gen_trap_ifnofpu(dc)) { 4533d8c5b92fSRichard Henderson return true; 4534d8c5b92fSRichard Henderson } 4535d8c5b92fSRichard Henderson 4536d8c5b92fSRichard Henderson t64 = tcg_temp_new_i64(); 4537d8c5b92fSRichard Henderson tcg_gen_qemu_ld_i64(t64, addr, dc->mem_idx, MO_TEUQ | MO_ALIGN); 4538d8c5b92fSRichard Henderson 4539d8c5b92fSRichard Henderson lo = tcg_temp_new_i32(); 4540d8c5b92fSRichard Henderson hi = cpu_fcc[3]; 4541d8c5b92fSRichard Henderson tcg_gen_extr_i64_i32(lo, hi, t64); 4542d8c5b92fSRichard Henderson tcg_gen_extract_i32(cpu_fcc[0], lo, FSR_FCC0_SHIFT, 2); 4543d8c5b92fSRichard Henderson tcg_gen_extract_i32(cpu_fcc[1], hi, FSR_FCC1_SHIFT - 32, 2); 4544d8c5b92fSRichard Henderson tcg_gen_extract_i32(cpu_fcc[2], hi, FSR_FCC2_SHIFT - 32, 2); 4545d8c5b92fSRichard Henderson tcg_gen_extract_i32(cpu_fcc[3], hi, FSR_FCC3_SHIFT - 32, 2); 4546d8c5b92fSRichard Henderson 4547298c52f7SRichard Henderson if (entire) { 4548298c52f7SRichard Henderson gen_helper_set_fsr_nofcc(tcg_env, lo); 4549298c52f7SRichard Henderson } else { 4550d8c5b92fSRichard Henderson gen_helper_set_fsr_nofcc_noftt(tcg_env, lo); 4551298c52f7SRichard Henderson } 4552d8c5b92fSRichard Henderson return advance_pc(dc); 4553d8c5b92fSRichard Henderson #else 4554d8c5b92fSRichard Henderson return false; 4555d8c5b92fSRichard Henderson #endif 4556d8c5b92fSRichard Henderson } 45573d3c0673SRichard Henderson 4558298c52f7SRichard Henderson TRANS(LDXFSR, 64, do_ldxfsr, a, false) 4559298c52f7SRichard Henderson TRANS(LDXEFSR, VIS3B, do_ldxfsr, a, true) 4560298c52f7SRichard Henderson 45613d3c0673SRichard Henderson static bool do_stfsr(DisasContext *dc, arg_r_r_ri *a, MemOp mop) 45623d3c0673SRichard Henderson { 45633d3c0673SRichard Henderson TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 45641ccd6e13SRichard Henderson TCGv fsr; 45651ccd6e13SRichard Henderson 45663d3c0673SRichard Henderson if (addr == NULL) { 45673d3c0673SRichard Henderson return false; 45683d3c0673SRichard Henderson } 45693d3c0673SRichard Henderson if (gen_trap_ifnofpu(dc)) { 45703d3c0673SRichard Henderson return true; 45713d3c0673SRichard Henderson } 45721ccd6e13SRichard Henderson 45731ccd6e13SRichard Henderson fsr = tcg_temp_new(); 45741ccd6e13SRichard Henderson gen_helper_get_fsr(fsr, tcg_env); 45751ccd6e13SRichard Henderson tcg_gen_qemu_st_tl(fsr, addr, dc->mem_idx, mop | MO_ALIGN); 45763d3c0673SRichard Henderson return advance_pc(dc); 45773d3c0673SRichard Henderson } 45783d3c0673SRichard Henderson 45793d3c0673SRichard Henderson TRANS(STFSR, ALL, do_stfsr, a, MO_TEUL) 45803d3c0673SRichard Henderson TRANS(STXFSR, 64, do_stfsr, a, MO_TEUQ) 45813d3c0673SRichard Henderson 45821210a036SRichard Henderson static bool do_fc(DisasContext *dc, int rd, int32_t c) 45833a38260eSRichard Henderson { 45843a38260eSRichard Henderson if (gen_trap_ifnofpu(dc)) { 45853a38260eSRichard Henderson return true; 45863a38260eSRichard Henderson } 45871210a036SRichard Henderson gen_store_fpr_F(dc, rd, tcg_constant_i32(c)); 45883a38260eSRichard Henderson return advance_pc(dc); 45893a38260eSRichard Henderson } 45903a38260eSRichard Henderson 45913a38260eSRichard Henderson TRANS(FZEROs, VIS1, do_fc, a->rd, 0) 45921210a036SRichard Henderson TRANS(FONEs, VIS1, do_fc, a->rd, -1) 45933a38260eSRichard Henderson 45943a38260eSRichard Henderson static bool do_dc(DisasContext *dc, int rd, int64_t c) 45953a38260eSRichard Henderson { 45963a38260eSRichard Henderson if (gen_trap_ifnofpu(dc)) { 45973a38260eSRichard Henderson return true; 45983a38260eSRichard Henderson } 45991210a036SRichard Henderson gen_store_fpr_D(dc, rd, tcg_constant_i64(c)); 46003a38260eSRichard Henderson return advance_pc(dc); 46013a38260eSRichard Henderson } 46023a38260eSRichard Henderson 46033a38260eSRichard Henderson TRANS(FZEROd, VIS1, do_dc, a->rd, 0) 46043a38260eSRichard Henderson TRANS(FONEd, VIS1, do_dc, a->rd, -1) 46053a38260eSRichard Henderson 4606baf3dbf2SRichard Henderson static bool do_ff(DisasContext *dc, arg_r_r *a, 4607baf3dbf2SRichard Henderson void (*func)(TCGv_i32, TCGv_i32)) 4608baf3dbf2SRichard Henderson { 4609baf3dbf2SRichard Henderson TCGv_i32 tmp; 4610baf3dbf2SRichard Henderson 4611baf3dbf2SRichard Henderson if (gen_trap_ifnofpu(dc)) { 4612baf3dbf2SRichard Henderson return true; 4613baf3dbf2SRichard Henderson } 4614baf3dbf2SRichard Henderson 4615baf3dbf2SRichard Henderson tmp = gen_load_fpr_F(dc, a->rs); 4616baf3dbf2SRichard Henderson func(tmp, tmp); 4617baf3dbf2SRichard Henderson gen_store_fpr_F(dc, a->rd, tmp); 4618baf3dbf2SRichard Henderson return advance_pc(dc); 4619baf3dbf2SRichard Henderson } 4620baf3dbf2SRichard Henderson 4621baf3dbf2SRichard Henderson TRANS(FMOVs, ALL, do_ff, a, gen_op_fmovs) 4622baf3dbf2SRichard Henderson TRANS(FNEGs, ALL, do_ff, a, gen_op_fnegs) 4623baf3dbf2SRichard Henderson TRANS(FABSs, ALL, do_ff, a, gen_op_fabss) 4624baf3dbf2SRichard Henderson TRANS(FSRCs, VIS1, do_ff, a, tcg_gen_mov_i32) 4625baf3dbf2SRichard Henderson TRANS(FNOTs, VIS1, do_ff, a, tcg_gen_not_i32) 4626baf3dbf2SRichard Henderson 46272f722641SRichard Henderson static bool do_fd(DisasContext *dc, arg_r_r *a, 46282f722641SRichard Henderson void (*func)(TCGv_i32, TCGv_i64)) 46292f722641SRichard Henderson { 46302f722641SRichard Henderson TCGv_i32 dst; 46312f722641SRichard Henderson TCGv_i64 src; 46322f722641SRichard Henderson 46332f722641SRichard Henderson if (gen_trap_ifnofpu(dc)) { 46342f722641SRichard Henderson return true; 46352f722641SRichard Henderson } 46362f722641SRichard Henderson 4637388a6465SRichard Henderson dst = tcg_temp_new_i32(); 46382f722641SRichard Henderson src = gen_load_fpr_D(dc, a->rs); 46392f722641SRichard Henderson func(dst, src); 46402f722641SRichard Henderson gen_store_fpr_F(dc, a->rd, dst); 46412f722641SRichard Henderson return advance_pc(dc); 46422f722641SRichard Henderson } 46432f722641SRichard Henderson 46442f722641SRichard Henderson TRANS(FPACK16, VIS1, do_fd, a, gen_op_fpack16) 46452f722641SRichard Henderson TRANS(FPACKFIX, VIS1, do_fd, a, gen_op_fpackfix) 46462f722641SRichard Henderson 4647119cb94fSRichard Henderson static bool do_env_ff(DisasContext *dc, arg_r_r *a, 4648119cb94fSRichard Henderson void (*func)(TCGv_i32, TCGv_env, TCGv_i32)) 4649119cb94fSRichard Henderson { 4650119cb94fSRichard Henderson TCGv_i32 tmp; 4651119cb94fSRichard Henderson 4652119cb94fSRichard Henderson if (gen_trap_ifnofpu(dc)) { 4653119cb94fSRichard Henderson return true; 4654119cb94fSRichard Henderson } 4655119cb94fSRichard Henderson 4656119cb94fSRichard Henderson tmp = gen_load_fpr_F(dc, a->rs); 4657119cb94fSRichard Henderson func(tmp, tcg_env, tmp); 4658119cb94fSRichard Henderson gen_store_fpr_F(dc, a->rd, tmp); 4659119cb94fSRichard Henderson return advance_pc(dc); 4660119cb94fSRichard Henderson } 4661119cb94fSRichard Henderson 4662119cb94fSRichard Henderson TRANS(FSQRTs, ALL, do_env_ff, a, gen_helper_fsqrts) 4663119cb94fSRichard Henderson TRANS(FiTOs, ALL, do_env_ff, a, gen_helper_fitos) 4664119cb94fSRichard Henderson TRANS(FsTOi, ALL, do_env_ff, a, gen_helper_fstoi) 4665119cb94fSRichard Henderson 46668c94bcd8SRichard Henderson static bool do_env_fd(DisasContext *dc, arg_r_r *a, 46678c94bcd8SRichard Henderson void (*func)(TCGv_i32, TCGv_env, TCGv_i64)) 46688c94bcd8SRichard Henderson { 46698c94bcd8SRichard Henderson TCGv_i32 dst; 46708c94bcd8SRichard Henderson TCGv_i64 src; 46718c94bcd8SRichard Henderson 46728c94bcd8SRichard Henderson if (gen_trap_ifnofpu(dc)) { 46738c94bcd8SRichard Henderson return true; 46748c94bcd8SRichard Henderson } 46758c94bcd8SRichard Henderson 4676388a6465SRichard Henderson dst = tcg_temp_new_i32(); 46778c94bcd8SRichard Henderson src = gen_load_fpr_D(dc, a->rs); 46788c94bcd8SRichard Henderson func(dst, tcg_env, src); 46798c94bcd8SRichard Henderson gen_store_fpr_F(dc, a->rd, dst); 46808c94bcd8SRichard Henderson return advance_pc(dc); 46818c94bcd8SRichard Henderson } 46828c94bcd8SRichard Henderson 46838c94bcd8SRichard Henderson TRANS(FdTOs, ALL, do_env_fd, a, gen_helper_fdtos) 46848c94bcd8SRichard Henderson TRANS(FdTOi, ALL, do_env_fd, a, gen_helper_fdtoi) 46858c94bcd8SRichard Henderson TRANS(FxTOs, 64, do_env_fd, a, gen_helper_fxtos) 46868c94bcd8SRichard Henderson 4687c6d83e4fSRichard Henderson static bool do_dd(DisasContext *dc, arg_r_r *a, 4688c6d83e4fSRichard Henderson void (*func)(TCGv_i64, TCGv_i64)) 4689c6d83e4fSRichard Henderson { 4690c6d83e4fSRichard Henderson TCGv_i64 dst, src; 4691c6d83e4fSRichard Henderson 4692c6d83e4fSRichard Henderson if (gen_trap_ifnofpu(dc)) { 4693c6d83e4fSRichard Henderson return true; 4694c6d83e4fSRichard Henderson } 4695c6d83e4fSRichard Henderson 469652f46d46SRichard Henderson dst = tcg_temp_new_i64(); 4697c6d83e4fSRichard Henderson src = gen_load_fpr_D(dc, a->rs); 4698c6d83e4fSRichard Henderson func(dst, src); 4699c6d83e4fSRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 4700c6d83e4fSRichard Henderson return advance_pc(dc); 4701c6d83e4fSRichard Henderson } 4702c6d83e4fSRichard Henderson 4703c6d83e4fSRichard Henderson TRANS(FMOVd, 64, do_dd, a, gen_op_fmovd) 4704c6d83e4fSRichard Henderson TRANS(FNEGd, 64, do_dd, a, gen_op_fnegd) 4705c6d83e4fSRichard Henderson TRANS(FABSd, 64, do_dd, a, gen_op_fabsd) 4706c6d83e4fSRichard Henderson TRANS(FSRCd, VIS1, do_dd, a, tcg_gen_mov_i64) 4707c6d83e4fSRichard Henderson TRANS(FNOTd, VIS1, do_dd, a, tcg_gen_not_i64) 4708c6d83e4fSRichard Henderson 47098aa418b3SRichard Henderson static bool do_env_dd(DisasContext *dc, arg_r_r *a, 47108aa418b3SRichard Henderson void (*func)(TCGv_i64, TCGv_env, TCGv_i64)) 47118aa418b3SRichard Henderson { 47128aa418b3SRichard Henderson TCGv_i64 dst, src; 47138aa418b3SRichard Henderson 47148aa418b3SRichard Henderson if (gen_trap_ifnofpu(dc)) { 47158aa418b3SRichard Henderson return true; 47168aa418b3SRichard Henderson } 47178aa418b3SRichard Henderson 471852f46d46SRichard Henderson dst = tcg_temp_new_i64(); 47198aa418b3SRichard Henderson src = gen_load_fpr_D(dc, a->rs); 47208aa418b3SRichard Henderson func(dst, tcg_env, src); 47218aa418b3SRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 47228aa418b3SRichard Henderson return advance_pc(dc); 47238aa418b3SRichard Henderson } 47248aa418b3SRichard Henderson 47258aa418b3SRichard Henderson TRANS(FSQRTd, ALL, do_env_dd, a, gen_helper_fsqrtd) 47268aa418b3SRichard Henderson TRANS(FxTOd, 64, do_env_dd, a, gen_helper_fxtod) 47278aa418b3SRichard Henderson TRANS(FdTOx, 64, do_env_dd, a, gen_helper_fdtox) 47288aa418b3SRichard Henderson 47297b616f36SRichard Henderson static bool do_df(DisasContext *dc, arg_r_r *a, 47307b616f36SRichard Henderson void (*func)(TCGv_i64, TCGv_i32)) 47317b616f36SRichard Henderson { 47327b616f36SRichard Henderson TCGv_i64 dst; 47337b616f36SRichard Henderson TCGv_i32 src; 47347b616f36SRichard Henderson 47357b616f36SRichard Henderson if (gen_trap_ifnofpu(dc)) { 47367b616f36SRichard Henderson return true; 47377b616f36SRichard Henderson } 47387b616f36SRichard Henderson 47397b616f36SRichard Henderson dst = tcg_temp_new_i64(); 47407b616f36SRichard Henderson src = gen_load_fpr_F(dc, a->rs); 47417b616f36SRichard Henderson func(dst, src); 47427b616f36SRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 47437b616f36SRichard Henderson return advance_pc(dc); 47447b616f36SRichard Henderson } 47457b616f36SRichard Henderson 47467b616f36SRichard Henderson TRANS(FEXPAND, VIS1, do_df, a, gen_helper_fexpand) 47477b616f36SRichard Henderson 4748199d43efSRichard Henderson static bool do_env_df(DisasContext *dc, arg_r_r *a, 4749199d43efSRichard Henderson void (*func)(TCGv_i64, TCGv_env, TCGv_i32)) 4750199d43efSRichard Henderson { 4751199d43efSRichard Henderson TCGv_i64 dst; 4752199d43efSRichard Henderson TCGv_i32 src; 4753199d43efSRichard Henderson 4754199d43efSRichard Henderson if (gen_trap_ifnofpu(dc)) { 4755199d43efSRichard Henderson return true; 4756199d43efSRichard Henderson } 4757199d43efSRichard Henderson 475852f46d46SRichard Henderson dst = tcg_temp_new_i64(); 4759199d43efSRichard Henderson src = gen_load_fpr_F(dc, a->rs); 4760199d43efSRichard Henderson func(dst, tcg_env, src); 4761199d43efSRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 4762199d43efSRichard Henderson return advance_pc(dc); 4763199d43efSRichard Henderson } 4764199d43efSRichard Henderson 4765199d43efSRichard Henderson TRANS(FiTOd, ALL, do_env_df, a, gen_helper_fitod) 4766199d43efSRichard Henderson TRANS(FsTOd, ALL, do_env_df, a, gen_helper_fstod) 4767199d43efSRichard Henderson TRANS(FsTOx, 64, do_env_df, a, gen_helper_fstox) 4768199d43efSRichard Henderson 4769daf457d4SRichard Henderson static bool do_qq(DisasContext *dc, arg_r_r *a, 4770daf457d4SRichard Henderson void (*func)(TCGv_i128, TCGv_i128)) 4771f4e18df5SRichard Henderson { 477233ec4245SRichard Henderson TCGv_i128 t; 4773f4e18df5SRichard Henderson 4774f4e18df5SRichard Henderson if (gen_trap_ifnofpu(dc)) { 4775f4e18df5SRichard Henderson return true; 4776f4e18df5SRichard Henderson } 4777f4e18df5SRichard Henderson if (gen_trap_float128(dc)) { 4778f4e18df5SRichard Henderson return true; 4779f4e18df5SRichard Henderson } 4780f4e18df5SRichard Henderson 4781f4e18df5SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 478233ec4245SRichard Henderson t = gen_load_fpr_Q(dc, a->rs); 4783daf457d4SRichard Henderson func(t, t); 478433ec4245SRichard Henderson gen_store_fpr_Q(dc, a->rd, t); 4785f4e18df5SRichard Henderson return advance_pc(dc); 4786f4e18df5SRichard Henderson } 4787f4e18df5SRichard Henderson 4788daf457d4SRichard Henderson TRANS(FMOVq, 64, do_qq, a, tcg_gen_mov_i128) 4789daf457d4SRichard Henderson TRANS(FNEGq, 64, do_qq, a, gen_op_fnegq) 4790daf457d4SRichard Henderson TRANS(FABSq, 64, do_qq, a, gen_op_fabsq) 4791f4e18df5SRichard Henderson 4792c995216bSRichard Henderson static bool do_env_qq(DisasContext *dc, arg_r_r *a, 4793e41716beSRichard Henderson void (*func)(TCGv_i128, TCGv_env, TCGv_i128)) 4794c995216bSRichard Henderson { 4795e41716beSRichard Henderson TCGv_i128 t; 4796e41716beSRichard Henderson 4797c995216bSRichard Henderson if (gen_trap_ifnofpu(dc)) { 4798c995216bSRichard Henderson return true; 4799c995216bSRichard Henderson } 4800c995216bSRichard Henderson if (gen_trap_float128(dc)) { 4801c995216bSRichard Henderson return true; 4802c995216bSRichard Henderson } 4803c995216bSRichard Henderson 4804e41716beSRichard Henderson t = gen_load_fpr_Q(dc, a->rs); 4805e41716beSRichard Henderson func(t, tcg_env, t); 4806e41716beSRichard Henderson gen_store_fpr_Q(dc, a->rd, t); 4807c995216bSRichard Henderson return advance_pc(dc); 4808c995216bSRichard Henderson } 4809c995216bSRichard Henderson 4810c995216bSRichard Henderson TRANS(FSQRTq, ALL, do_env_qq, a, gen_helper_fsqrtq) 4811c995216bSRichard Henderson 4812bd9c5c42SRichard Henderson static bool do_env_fq(DisasContext *dc, arg_r_r *a, 4813d81e3efeSRichard Henderson void (*func)(TCGv_i32, TCGv_env, TCGv_i128)) 4814bd9c5c42SRichard Henderson { 4815d81e3efeSRichard Henderson TCGv_i128 src; 4816bd9c5c42SRichard Henderson TCGv_i32 dst; 4817bd9c5c42SRichard Henderson 4818bd9c5c42SRichard Henderson if (gen_trap_ifnofpu(dc)) { 4819bd9c5c42SRichard Henderson return true; 4820bd9c5c42SRichard Henderson } 4821bd9c5c42SRichard Henderson if (gen_trap_float128(dc)) { 4822bd9c5c42SRichard Henderson return true; 4823bd9c5c42SRichard Henderson } 4824bd9c5c42SRichard Henderson 4825d81e3efeSRichard Henderson src = gen_load_fpr_Q(dc, a->rs); 4826388a6465SRichard Henderson dst = tcg_temp_new_i32(); 4827d81e3efeSRichard Henderson func(dst, tcg_env, src); 4828bd9c5c42SRichard Henderson gen_store_fpr_F(dc, a->rd, dst); 4829bd9c5c42SRichard Henderson return advance_pc(dc); 4830bd9c5c42SRichard Henderson } 4831bd9c5c42SRichard Henderson 4832bd9c5c42SRichard Henderson TRANS(FqTOs, ALL, do_env_fq, a, gen_helper_fqtos) 4833bd9c5c42SRichard Henderson TRANS(FqTOi, ALL, do_env_fq, a, gen_helper_fqtoi) 4834bd9c5c42SRichard Henderson 48351617586fSRichard Henderson static bool do_env_dq(DisasContext *dc, arg_r_r *a, 483625a5769eSRichard Henderson void (*func)(TCGv_i64, TCGv_env, TCGv_i128)) 48371617586fSRichard Henderson { 483825a5769eSRichard Henderson TCGv_i128 src; 48391617586fSRichard Henderson TCGv_i64 dst; 48401617586fSRichard Henderson 48411617586fSRichard Henderson if (gen_trap_ifnofpu(dc)) { 48421617586fSRichard Henderson return true; 48431617586fSRichard Henderson } 48441617586fSRichard Henderson if (gen_trap_float128(dc)) { 48451617586fSRichard Henderson return true; 48461617586fSRichard Henderson } 48471617586fSRichard Henderson 484825a5769eSRichard Henderson src = gen_load_fpr_Q(dc, a->rs); 484952f46d46SRichard Henderson dst = tcg_temp_new_i64(); 485025a5769eSRichard Henderson func(dst, tcg_env, src); 48511617586fSRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 48521617586fSRichard Henderson return advance_pc(dc); 48531617586fSRichard Henderson } 48541617586fSRichard Henderson 48551617586fSRichard Henderson TRANS(FqTOd, ALL, do_env_dq, a, gen_helper_fqtod) 48561617586fSRichard Henderson TRANS(FqTOx, 64, do_env_dq, a, gen_helper_fqtox) 48571617586fSRichard Henderson 485813ebcc77SRichard Henderson static bool do_env_qf(DisasContext *dc, arg_r_r *a, 48590b2a61ccSRichard Henderson void (*func)(TCGv_i128, TCGv_env, TCGv_i32)) 486013ebcc77SRichard Henderson { 486113ebcc77SRichard Henderson TCGv_i32 src; 48620b2a61ccSRichard Henderson TCGv_i128 dst; 486313ebcc77SRichard Henderson 486413ebcc77SRichard Henderson if (gen_trap_ifnofpu(dc)) { 486513ebcc77SRichard Henderson return true; 486613ebcc77SRichard Henderson } 486713ebcc77SRichard Henderson if (gen_trap_float128(dc)) { 486813ebcc77SRichard Henderson return true; 486913ebcc77SRichard Henderson } 487013ebcc77SRichard Henderson 487113ebcc77SRichard Henderson src = gen_load_fpr_F(dc, a->rs); 48720b2a61ccSRichard Henderson dst = tcg_temp_new_i128(); 48730b2a61ccSRichard Henderson func(dst, tcg_env, src); 48740b2a61ccSRichard Henderson gen_store_fpr_Q(dc, a->rd, dst); 487513ebcc77SRichard Henderson return advance_pc(dc); 487613ebcc77SRichard Henderson } 487713ebcc77SRichard Henderson 487813ebcc77SRichard Henderson TRANS(FiTOq, ALL, do_env_qf, a, gen_helper_fitoq) 487913ebcc77SRichard Henderson TRANS(FsTOq, ALL, do_env_qf, a, gen_helper_fstoq) 488013ebcc77SRichard Henderson 48817b8e3e1aSRichard Henderson static bool do_env_qd(DisasContext *dc, arg_r_r *a, 4882fdc50716SRichard Henderson void (*func)(TCGv_i128, TCGv_env, TCGv_i64)) 48837b8e3e1aSRichard Henderson { 48847b8e3e1aSRichard Henderson TCGv_i64 src; 4885fdc50716SRichard Henderson TCGv_i128 dst; 48867b8e3e1aSRichard Henderson 48877b8e3e1aSRichard Henderson if (gen_trap_ifnofpu(dc)) { 48887b8e3e1aSRichard Henderson return true; 48897b8e3e1aSRichard Henderson } 48907b8e3e1aSRichard Henderson if (gen_trap_float128(dc)) { 48917b8e3e1aSRichard Henderson return true; 48927b8e3e1aSRichard Henderson } 48937b8e3e1aSRichard Henderson 48947b8e3e1aSRichard Henderson src = gen_load_fpr_D(dc, a->rs); 4895fdc50716SRichard Henderson dst = tcg_temp_new_i128(); 4896fdc50716SRichard Henderson func(dst, tcg_env, src); 4897fdc50716SRichard Henderson gen_store_fpr_Q(dc, a->rd, dst); 48987b8e3e1aSRichard Henderson return advance_pc(dc); 48997b8e3e1aSRichard Henderson } 49007b8e3e1aSRichard Henderson 49017b8e3e1aSRichard Henderson TRANS(FdTOq, ALL, do_env_qd, a, gen_helper_fdtoq) 49027b8e3e1aSRichard Henderson TRANS(FxTOq, 64, do_env_qd, a, gen_helper_fxtoq) 49037b8e3e1aSRichard Henderson 49047f10b52fSRichard Henderson static bool do_fff(DisasContext *dc, arg_r_r_r *a, 49057f10b52fSRichard Henderson void (*func)(TCGv_i32, TCGv_i32, TCGv_i32)) 49067f10b52fSRichard Henderson { 49077f10b52fSRichard Henderson TCGv_i32 src1, src2; 49087f10b52fSRichard Henderson 49097f10b52fSRichard Henderson if (gen_trap_ifnofpu(dc)) { 49107f10b52fSRichard Henderson return true; 49117f10b52fSRichard Henderson } 49127f10b52fSRichard Henderson 49137f10b52fSRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1); 49147f10b52fSRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2); 49157f10b52fSRichard Henderson func(src1, src1, src2); 49167f10b52fSRichard Henderson gen_store_fpr_F(dc, a->rd, src1); 49177f10b52fSRichard Henderson return advance_pc(dc); 49187f10b52fSRichard Henderson } 49197f10b52fSRichard Henderson 49207f10b52fSRichard Henderson TRANS(FPADD16s, VIS1, do_fff, a, tcg_gen_vec_add16_i32) 49217f10b52fSRichard Henderson TRANS(FPADD32s, VIS1, do_fff, a, tcg_gen_add_i32) 49227f10b52fSRichard Henderson TRANS(FPSUB16s, VIS1, do_fff, a, tcg_gen_vec_sub16_i32) 49237f10b52fSRichard Henderson TRANS(FPSUB32s, VIS1, do_fff, a, tcg_gen_sub_i32) 49247f10b52fSRichard Henderson TRANS(FNORs, VIS1, do_fff, a, tcg_gen_nor_i32) 49257f10b52fSRichard Henderson TRANS(FANDNOTs, VIS1, do_fff, a, tcg_gen_andc_i32) 49267f10b52fSRichard Henderson TRANS(FXORs, VIS1, do_fff, a, tcg_gen_xor_i32) 49277f10b52fSRichard Henderson TRANS(FNANDs, VIS1, do_fff, a, tcg_gen_nand_i32) 49287f10b52fSRichard Henderson TRANS(FANDs, VIS1, do_fff, a, tcg_gen_and_i32) 49297f10b52fSRichard Henderson TRANS(FXNORs, VIS1, do_fff, a, tcg_gen_eqv_i32) 49307f10b52fSRichard Henderson TRANS(FORNOTs, VIS1, do_fff, a, tcg_gen_orc_i32) 49317f10b52fSRichard Henderson TRANS(FORs, VIS1, do_fff, a, tcg_gen_or_i32) 49327f10b52fSRichard Henderson 49333d50b728SRichard Henderson TRANS(FHADDs, VIS3, do_fff, a, gen_op_fhadds) 49343d50b728SRichard Henderson TRANS(FHSUBs, VIS3, do_fff, a, gen_op_fhsubs) 49353d50b728SRichard Henderson TRANS(FNHADDs, VIS3, do_fff, a, gen_op_fnhadds) 49363d50b728SRichard Henderson 49370d1d3aafSRichard Henderson TRANS(FPADDS16s, VIS3, do_fff, a, gen_op_fpadds16s) 49380d1d3aafSRichard Henderson TRANS(FPSUBS16s, VIS3, do_fff, a, gen_op_fpsubs16s) 49390d1d3aafSRichard Henderson TRANS(FPADDS32s, VIS3, do_fff, a, gen_op_fpadds32s) 49400d1d3aafSRichard Henderson TRANS(FPSUBS32s, VIS3, do_fff, a, gen_op_fpsubs32s) 49410d1d3aafSRichard Henderson 4942c1514961SRichard Henderson static bool do_env_fff(DisasContext *dc, arg_r_r_r *a, 4943c1514961SRichard Henderson void (*func)(TCGv_i32, TCGv_env, TCGv_i32, TCGv_i32)) 4944c1514961SRichard Henderson { 4945c1514961SRichard Henderson TCGv_i32 src1, src2; 4946c1514961SRichard Henderson 4947c1514961SRichard Henderson if (gen_trap_ifnofpu(dc)) { 4948c1514961SRichard Henderson return true; 4949c1514961SRichard Henderson } 4950c1514961SRichard Henderson 4951c1514961SRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1); 4952c1514961SRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2); 4953c1514961SRichard Henderson func(src1, tcg_env, src1, src2); 4954c1514961SRichard Henderson gen_store_fpr_F(dc, a->rd, src1); 4955c1514961SRichard Henderson return advance_pc(dc); 4956c1514961SRichard Henderson } 4957c1514961SRichard Henderson 4958c1514961SRichard Henderson TRANS(FADDs, ALL, do_env_fff, a, gen_helper_fadds) 4959c1514961SRichard Henderson TRANS(FSUBs, ALL, do_env_fff, a, gen_helper_fsubs) 4960c1514961SRichard Henderson TRANS(FMULs, ALL, do_env_fff, a, gen_helper_fmuls) 4961c1514961SRichard Henderson TRANS(FDIVs, ALL, do_env_fff, a, gen_helper_fdivs) 49623d50b728SRichard Henderson TRANS(FNADDs, VIS3, do_env_fff, a, gen_helper_fnadds) 49633d50b728SRichard Henderson TRANS(FNMULs, VIS3, do_env_fff, a, gen_helper_fnmuls) 4964c1514961SRichard Henderson 4965a859602cSRichard Henderson static bool do_dff(DisasContext *dc, arg_r_r_r *a, 4966a859602cSRichard Henderson void (*func)(TCGv_i64, TCGv_i32, TCGv_i32)) 4967a859602cSRichard Henderson { 4968a859602cSRichard Henderson TCGv_i64 dst; 4969a859602cSRichard Henderson TCGv_i32 src1, src2; 4970a859602cSRichard Henderson 4971a859602cSRichard Henderson if (gen_trap_ifnofpu(dc)) { 4972a859602cSRichard Henderson return true; 4973a859602cSRichard Henderson } 4974a859602cSRichard Henderson 497552f46d46SRichard Henderson dst = tcg_temp_new_i64(); 4976a859602cSRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1); 4977a859602cSRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2); 4978a859602cSRichard Henderson func(dst, src1, src2); 4979a859602cSRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 4980a859602cSRichard Henderson return advance_pc(dc); 4981a859602cSRichard Henderson } 4982a859602cSRichard Henderson 4983a859602cSRichard Henderson TRANS(FMUL8x16AU, VIS1, do_dff, a, gen_op_fmul8x16au) 4984a859602cSRichard Henderson TRANS(FMUL8x16AL, VIS1, do_dff, a, gen_op_fmul8x16al) 4985be8998e0SRichard Henderson TRANS(FMULD8SUx16, VIS1, do_dff, a, gen_op_fmuld8sux16) 4986be8998e0SRichard Henderson TRANS(FMULD8ULx16, VIS1, do_dff, a, gen_op_fmuld8ulx16) 4987d3ef26afSRichard Henderson TRANS(FPMERGE, VIS1, do_dff, a, gen_helper_fpmerge) 4988a859602cSRichard Henderson 49899157dcccSRichard Henderson static bool do_dfd(DisasContext *dc, arg_r_r_r *a, 49909157dcccSRichard Henderson void (*func)(TCGv_i64, TCGv_i32, TCGv_i64)) 49919157dcccSRichard Henderson { 49929157dcccSRichard Henderson TCGv_i64 dst, src2; 49939157dcccSRichard Henderson TCGv_i32 src1; 49949157dcccSRichard Henderson 49959157dcccSRichard Henderson if (gen_trap_ifnofpu(dc)) { 49969157dcccSRichard Henderson return true; 49979157dcccSRichard Henderson } 49989157dcccSRichard Henderson 499952f46d46SRichard Henderson dst = tcg_temp_new_i64(); 50009157dcccSRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1); 50019157dcccSRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2); 50029157dcccSRichard Henderson func(dst, src1, src2); 50039157dcccSRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 50049157dcccSRichard Henderson return advance_pc(dc); 50059157dcccSRichard Henderson } 50069157dcccSRichard Henderson 50079157dcccSRichard Henderson TRANS(FMUL8x16, VIS1, do_dfd, a, gen_helper_fmul8x16) 50089157dcccSRichard Henderson 500928c131a3SRichard Henderson static bool do_gvec_ddd(DisasContext *dc, arg_r_r_r *a, MemOp vece, 501028c131a3SRichard Henderson void (*func)(unsigned, uint32_t, uint32_t, 501128c131a3SRichard Henderson uint32_t, uint32_t, uint32_t)) 501228c131a3SRichard Henderson { 501328c131a3SRichard Henderson if (gen_trap_ifnofpu(dc)) { 501428c131a3SRichard Henderson return true; 501528c131a3SRichard Henderson } 501628c131a3SRichard Henderson 501728c131a3SRichard Henderson func(vece, gen_offset_fpr_D(a->rd), gen_offset_fpr_D(a->rs1), 501828c131a3SRichard Henderson gen_offset_fpr_D(a->rs2), 8, 8); 501928c131a3SRichard Henderson return advance_pc(dc); 502028c131a3SRichard Henderson } 502128c131a3SRichard Henderson 502228c131a3SRichard Henderson TRANS(FPADD16, VIS1, do_gvec_ddd, a, MO_16, tcg_gen_gvec_add) 502328c131a3SRichard Henderson TRANS(FPADD32, VIS1, do_gvec_ddd, a, MO_32, tcg_gen_gvec_add) 502428c131a3SRichard Henderson TRANS(FPSUB16, VIS1, do_gvec_ddd, a, MO_16, tcg_gen_gvec_sub) 502528c131a3SRichard Henderson TRANS(FPSUB32, VIS1, do_gvec_ddd, a, MO_32, tcg_gen_gvec_sub) 50267837185eSRichard Henderson TRANS(FCHKSM16, VIS3, do_gvec_ddd, a, MO_16, gen_op_fchksm16) 5027d6ff1ccbSRichard Henderson TRANS(FMEAN16, VIS3, do_gvec_ddd, a, MO_16, gen_op_fmean16) 502828c131a3SRichard Henderson 50290d1d3aafSRichard Henderson TRANS(FPADDS16, VIS3, do_gvec_ddd, a, MO_16, tcg_gen_gvec_ssadd) 50300d1d3aafSRichard Henderson TRANS(FPADDS32, VIS3, do_gvec_ddd, a, MO_32, tcg_gen_gvec_ssadd) 50310d1d3aafSRichard Henderson TRANS(FPSUBS16, VIS3, do_gvec_ddd, a, MO_16, tcg_gen_gvec_sssub) 50320d1d3aafSRichard Henderson TRANS(FPSUBS32, VIS3, do_gvec_ddd, a, MO_32, tcg_gen_gvec_sssub) 50330d1d3aafSRichard Henderson 5034fbc5c8d4SRichard Henderson TRANS(FSLL16, VIS3, do_gvec_ddd, a, MO_16, tcg_gen_gvec_shlv) 5035fbc5c8d4SRichard Henderson TRANS(FSLL32, VIS3, do_gvec_ddd, a, MO_32, tcg_gen_gvec_shlv) 5036fbc5c8d4SRichard Henderson TRANS(FSRL16, VIS3, do_gvec_ddd, a, MO_16, tcg_gen_gvec_shrv) 5037fbc5c8d4SRichard Henderson TRANS(FSRL32, VIS3, do_gvec_ddd, a, MO_32, tcg_gen_gvec_shrv) 5038fbc5c8d4SRichard Henderson TRANS(FSRA16, VIS3, do_gvec_ddd, a, MO_16, tcg_gen_gvec_sarv) 5039fbc5c8d4SRichard Henderson TRANS(FSRA32, VIS3, do_gvec_ddd, a, MO_32, tcg_gen_gvec_sarv) 5040fbc5c8d4SRichard Henderson 5041e06c9f83SRichard Henderson static bool do_ddd(DisasContext *dc, arg_r_r_r *a, 5042e06c9f83SRichard Henderson void (*func)(TCGv_i64, TCGv_i64, TCGv_i64)) 5043e06c9f83SRichard Henderson { 5044e06c9f83SRichard Henderson TCGv_i64 dst, src1, src2; 5045e06c9f83SRichard Henderson 5046e06c9f83SRichard Henderson if (gen_trap_ifnofpu(dc)) { 5047e06c9f83SRichard Henderson return true; 5048e06c9f83SRichard Henderson } 5049e06c9f83SRichard Henderson 505052f46d46SRichard Henderson dst = tcg_temp_new_i64(); 5051e06c9f83SRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1); 5052e06c9f83SRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2); 5053e06c9f83SRichard Henderson func(dst, src1, src2); 5054e06c9f83SRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 5055e06c9f83SRichard Henderson return advance_pc(dc); 5056e06c9f83SRichard Henderson } 5057e06c9f83SRichard Henderson 5058e06c9f83SRichard Henderson TRANS(FMUL8SUx16, VIS1, do_ddd, a, gen_helper_fmul8sux16) 5059e06c9f83SRichard Henderson TRANS(FMUL8ULx16, VIS1, do_ddd, a, gen_helper_fmul8ulx16) 5060e06c9f83SRichard Henderson 5061e06c9f83SRichard Henderson TRANS(FNORd, VIS1, do_ddd, a, tcg_gen_nor_i64) 5062e06c9f83SRichard Henderson TRANS(FANDNOTd, VIS1, do_ddd, a, tcg_gen_andc_i64) 5063e06c9f83SRichard Henderson TRANS(FXORd, VIS1, do_ddd, a, tcg_gen_xor_i64) 5064e06c9f83SRichard Henderson TRANS(FNANDd, VIS1, do_ddd, a, tcg_gen_nand_i64) 5065e06c9f83SRichard Henderson TRANS(FANDd, VIS1, do_ddd, a, tcg_gen_and_i64) 5066e06c9f83SRichard Henderson TRANS(FXNORd, VIS1, do_ddd, a, tcg_gen_eqv_i64) 5067e06c9f83SRichard Henderson TRANS(FORNOTd, VIS1, do_ddd, a, tcg_gen_orc_i64) 5068e06c9f83SRichard Henderson TRANS(FORd, VIS1, do_ddd, a, tcg_gen_or_i64) 5069e06c9f83SRichard Henderson 50704b6edc0aSRichard Henderson TRANS(FPACK32, VIS1, do_ddd, a, gen_op_fpack32) 50714b6edc0aSRichard Henderson TRANS(FALIGNDATAg, VIS1, do_ddd, a, gen_op_faligndata) 50724b6edc0aSRichard Henderson TRANS(BSHUFFLE, VIS2, do_ddd, a, gen_op_bshuffle) 50734b6edc0aSRichard Henderson 50743d50b728SRichard Henderson TRANS(FHADDd, VIS3, do_ddd, a, gen_op_fhaddd) 50753d50b728SRichard Henderson TRANS(FHSUBd, VIS3, do_ddd, a, gen_op_fhsubd) 50763d50b728SRichard Henderson TRANS(FNHADDd, VIS3, do_ddd, a, gen_op_fnhaddd) 50773d50b728SRichard Henderson 5078bc3f14a9SRichard Henderson TRANS(FPADD64, VIS3B, do_ddd, a, tcg_gen_add_i64) 5079bc3f14a9SRichard Henderson TRANS(FPSUB64, VIS3B, do_ddd, a, tcg_gen_sub_i64) 5080fbc5c8d4SRichard Henderson TRANS(FSLAS16, VIS3, do_ddd, a, gen_helper_fslas16) 5081fbc5c8d4SRichard Henderson TRANS(FSLAS32, VIS3, do_ddd, a, gen_helper_fslas32) 5082bc3f14a9SRichard Henderson 5083e2fa6bd1SRichard Henderson static bool do_rdd(DisasContext *dc, arg_r_r_r *a, 5084e2fa6bd1SRichard Henderson void (*func)(TCGv, TCGv_i64, TCGv_i64)) 5085e2fa6bd1SRichard Henderson { 5086e2fa6bd1SRichard Henderson TCGv_i64 src1, src2; 5087e2fa6bd1SRichard Henderson TCGv dst; 5088e2fa6bd1SRichard Henderson 5089e2fa6bd1SRichard Henderson if (gen_trap_ifnofpu(dc)) { 5090e2fa6bd1SRichard Henderson return true; 5091e2fa6bd1SRichard Henderson } 5092e2fa6bd1SRichard Henderson 5093e2fa6bd1SRichard Henderson dst = gen_dest_gpr(dc, a->rd); 5094e2fa6bd1SRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1); 5095e2fa6bd1SRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2); 5096e2fa6bd1SRichard Henderson func(dst, src1, src2); 5097e2fa6bd1SRichard Henderson gen_store_gpr(dc, a->rd, dst); 5098e2fa6bd1SRichard Henderson return advance_pc(dc); 5099e2fa6bd1SRichard Henderson } 5100e2fa6bd1SRichard Henderson 5101e2fa6bd1SRichard Henderson TRANS(FPCMPLE16, VIS1, do_rdd, a, gen_helper_fcmple16) 5102e2fa6bd1SRichard Henderson TRANS(FPCMPNE16, VIS1, do_rdd, a, gen_helper_fcmpne16) 5103e2fa6bd1SRichard Henderson TRANS(FPCMPGT16, VIS1, do_rdd, a, gen_helper_fcmpgt16) 5104e2fa6bd1SRichard Henderson TRANS(FPCMPEQ16, VIS1, do_rdd, a, gen_helper_fcmpeq16) 5105e2fa6bd1SRichard Henderson 5106e2fa6bd1SRichard Henderson TRANS(FPCMPLE32, VIS1, do_rdd, a, gen_helper_fcmple32) 5107e2fa6bd1SRichard Henderson TRANS(FPCMPNE32, VIS1, do_rdd, a, gen_helper_fcmpne32) 5108e2fa6bd1SRichard Henderson TRANS(FPCMPGT32, VIS1, do_rdd, a, gen_helper_fcmpgt32) 5109e2fa6bd1SRichard Henderson TRANS(FPCMPEQ32, VIS1, do_rdd, a, gen_helper_fcmpeq32) 5110e2fa6bd1SRichard Henderson 5111669e0774SRichard Henderson TRANS(FPCMPEQ8, VIS3B, do_rdd, a, gen_helper_fcmpeq8) 5112669e0774SRichard Henderson TRANS(FPCMPNE8, VIS3B, do_rdd, a, gen_helper_fcmpne8) 5113669e0774SRichard Henderson TRANS(FPCMPULE8, VIS3B, do_rdd, a, gen_helper_fcmpule8) 5114669e0774SRichard Henderson TRANS(FPCMPUGT8, VIS3B, do_rdd, a, gen_helper_fcmpugt8) 5115669e0774SRichard Henderson 51167d5ebd8fSRichard Henderson TRANS(PDISTN, VIS3, do_rdd, a, gen_op_pdistn) 5117029b0283SRichard Henderson TRANS(XMULX, VIS3, do_rrr, a, gen_helper_xmulx) 5118029b0283SRichard Henderson TRANS(XMULXHI, VIS3, do_rrr, a, gen_helper_xmulxhi) 51197d5ebd8fSRichard Henderson 5120f2a59b0aSRichard Henderson static bool do_env_ddd(DisasContext *dc, arg_r_r_r *a, 5121f2a59b0aSRichard Henderson void (*func)(TCGv_i64, TCGv_env, TCGv_i64, TCGv_i64)) 5122f2a59b0aSRichard Henderson { 5123f2a59b0aSRichard Henderson TCGv_i64 dst, src1, src2; 5124f2a59b0aSRichard Henderson 5125f2a59b0aSRichard Henderson if (gen_trap_ifnofpu(dc)) { 5126f2a59b0aSRichard Henderson return true; 5127f2a59b0aSRichard Henderson } 5128f2a59b0aSRichard Henderson 512952f46d46SRichard Henderson dst = tcg_temp_new_i64(); 5130f2a59b0aSRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1); 5131f2a59b0aSRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2); 5132f2a59b0aSRichard Henderson func(dst, tcg_env, src1, src2); 5133f2a59b0aSRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 5134f2a59b0aSRichard Henderson return advance_pc(dc); 5135f2a59b0aSRichard Henderson } 5136f2a59b0aSRichard Henderson 5137f2a59b0aSRichard Henderson TRANS(FADDd, ALL, do_env_ddd, a, gen_helper_faddd) 5138f2a59b0aSRichard Henderson TRANS(FSUBd, ALL, do_env_ddd, a, gen_helper_fsubd) 5139f2a59b0aSRichard Henderson TRANS(FMULd, ALL, do_env_ddd, a, gen_helper_fmuld) 5140f2a59b0aSRichard Henderson TRANS(FDIVd, ALL, do_env_ddd, a, gen_helper_fdivd) 51413d50b728SRichard Henderson TRANS(FNADDd, VIS3, do_env_ddd, a, gen_helper_fnaddd) 51423d50b728SRichard Henderson TRANS(FNMULd, VIS3, do_env_ddd, a, gen_helper_fnmuld) 5143f2a59b0aSRichard Henderson 5144ff4c711bSRichard Henderson static bool trans_FsMULd(DisasContext *dc, arg_r_r_r *a) 5145ff4c711bSRichard Henderson { 5146ff4c711bSRichard Henderson TCGv_i64 dst; 5147ff4c711bSRichard Henderson TCGv_i32 src1, src2; 5148ff4c711bSRichard Henderson 5149ff4c711bSRichard Henderson if (gen_trap_ifnofpu(dc)) { 5150ff4c711bSRichard Henderson return true; 5151ff4c711bSRichard Henderson } 5152ff4c711bSRichard Henderson if (!(dc->def->features & CPU_FEATURE_FSMULD)) { 5153ff4c711bSRichard Henderson return raise_unimpfpop(dc); 5154ff4c711bSRichard Henderson } 5155ff4c711bSRichard Henderson 515652f46d46SRichard Henderson dst = tcg_temp_new_i64(); 5157ff4c711bSRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1); 5158ff4c711bSRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2); 5159ff4c711bSRichard Henderson gen_helper_fsmuld(dst, tcg_env, src1, src2); 5160ff4c711bSRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 5161ff4c711bSRichard Henderson return advance_pc(dc); 5162ff4c711bSRichard Henderson } 5163ff4c711bSRichard Henderson 51643d50b728SRichard Henderson static bool trans_FNsMULd(DisasContext *dc, arg_r_r_r *a) 51653d50b728SRichard Henderson { 51663d50b728SRichard Henderson TCGv_i64 dst; 51673d50b728SRichard Henderson TCGv_i32 src1, src2; 51683d50b728SRichard Henderson 51693d50b728SRichard Henderson if (!avail_VIS3(dc)) { 51703d50b728SRichard Henderson return false; 51713d50b728SRichard Henderson } 51723d50b728SRichard Henderson if (gen_trap_ifnofpu(dc)) { 51733d50b728SRichard Henderson return true; 51743d50b728SRichard Henderson } 51753d50b728SRichard Henderson dst = tcg_temp_new_i64(); 51763d50b728SRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1); 51773d50b728SRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2); 51783d50b728SRichard Henderson gen_helper_fnsmuld(dst, tcg_env, src1, src2); 51793d50b728SRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 51803d50b728SRichard Henderson return advance_pc(dc); 51813d50b728SRichard Henderson } 51823d50b728SRichard Henderson 51834fd71d19SRichard Henderson static bool do_ffff(DisasContext *dc, arg_r_r_r_r *a, 51844fd71d19SRichard Henderson void (*func)(TCGv_i32, TCGv_i32, TCGv_i32, TCGv_i32)) 51854fd71d19SRichard Henderson { 51864fd71d19SRichard Henderson TCGv_i32 dst, src1, src2, src3; 51874fd71d19SRichard Henderson 51884fd71d19SRichard Henderson if (gen_trap_ifnofpu(dc)) { 51894fd71d19SRichard Henderson return true; 51904fd71d19SRichard Henderson } 51914fd71d19SRichard Henderson 51924fd71d19SRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1); 51934fd71d19SRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2); 51944fd71d19SRichard Henderson src3 = gen_load_fpr_F(dc, a->rs3); 51954fd71d19SRichard Henderson dst = tcg_temp_new_i32(); 51964fd71d19SRichard Henderson func(dst, src1, src2, src3); 51974fd71d19SRichard Henderson gen_store_fpr_F(dc, a->rd, dst); 51984fd71d19SRichard Henderson return advance_pc(dc); 51994fd71d19SRichard Henderson } 52004fd71d19SRichard Henderson 52014fd71d19SRichard Henderson TRANS(FMADDs, FMAF, do_ffff, a, gen_op_fmadds) 52024fd71d19SRichard Henderson TRANS(FMSUBs, FMAF, do_ffff, a, gen_op_fmsubs) 52034fd71d19SRichard Henderson TRANS(FNMSUBs, FMAF, do_ffff, a, gen_op_fnmsubs) 52044fd71d19SRichard Henderson TRANS(FNMADDs, FMAF, do_ffff, a, gen_op_fnmadds) 52054fd71d19SRichard Henderson 52064fd71d19SRichard Henderson static bool do_dddd(DisasContext *dc, arg_r_r_r_r *a, 5207afb04344SRichard Henderson void (*func)(TCGv_i64, TCGv_i64, TCGv_i64, TCGv_i64)) 5208afb04344SRichard Henderson { 52094fd71d19SRichard Henderson TCGv_i64 dst, src1, src2, src3; 5210afb04344SRichard Henderson 5211afb04344SRichard Henderson if (gen_trap_ifnofpu(dc)) { 5212afb04344SRichard Henderson return true; 5213afb04344SRichard Henderson } 5214afb04344SRichard Henderson 521552f46d46SRichard Henderson dst = tcg_temp_new_i64(); 5216afb04344SRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1); 5217afb04344SRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2); 52184fd71d19SRichard Henderson src3 = gen_load_fpr_D(dc, a->rs3); 52194fd71d19SRichard Henderson func(dst, src1, src2, src3); 5220afb04344SRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 5221afb04344SRichard Henderson return advance_pc(dc); 5222afb04344SRichard Henderson } 5223afb04344SRichard Henderson 5224afb04344SRichard Henderson TRANS(PDIST, VIS1, do_dddd, a, gen_helper_pdist) 52254fd71d19SRichard Henderson TRANS(FMADDd, FMAF, do_dddd, a, gen_op_fmaddd) 52264fd71d19SRichard Henderson TRANS(FMSUBd, FMAF, do_dddd, a, gen_op_fmsubd) 52274fd71d19SRichard Henderson TRANS(FNMSUBd, FMAF, do_dddd, a, gen_op_fnmsubd) 52284fd71d19SRichard Henderson TRANS(FNMADDd, FMAF, do_dddd, a, gen_op_fnmaddd) 522968a414e9SRichard Henderson TRANS(FPMADDX, IMA, do_dddd, a, gen_op_fpmaddx) 523068a414e9SRichard Henderson TRANS(FPMADDXHI, IMA, do_dddd, a, gen_op_fpmaddxhi) 5231afb04344SRichard Henderson 5232a4056239SRichard Henderson static bool do_env_qqq(DisasContext *dc, arg_r_r_r *a, 523316bedf89SRichard Henderson void (*func)(TCGv_i128, TCGv_env, TCGv_i128, TCGv_i128)) 5234a4056239SRichard Henderson { 523516bedf89SRichard Henderson TCGv_i128 src1, src2; 523616bedf89SRichard Henderson 5237a4056239SRichard Henderson if (gen_trap_ifnofpu(dc)) { 5238a4056239SRichard Henderson return true; 5239a4056239SRichard Henderson } 5240a4056239SRichard Henderson if (gen_trap_float128(dc)) { 5241a4056239SRichard Henderson return true; 5242a4056239SRichard Henderson } 5243a4056239SRichard Henderson 524416bedf89SRichard Henderson src1 = gen_load_fpr_Q(dc, a->rs1); 524516bedf89SRichard Henderson src2 = gen_load_fpr_Q(dc, a->rs2); 524616bedf89SRichard Henderson func(src1, tcg_env, src1, src2); 524716bedf89SRichard Henderson gen_store_fpr_Q(dc, a->rd, src1); 5248a4056239SRichard Henderson return advance_pc(dc); 5249a4056239SRichard Henderson } 5250a4056239SRichard Henderson 5251a4056239SRichard Henderson TRANS(FADDq, ALL, do_env_qqq, a, gen_helper_faddq) 5252a4056239SRichard Henderson TRANS(FSUBq, ALL, do_env_qqq, a, gen_helper_fsubq) 5253a4056239SRichard Henderson TRANS(FMULq, ALL, do_env_qqq, a, gen_helper_fmulq) 5254a4056239SRichard Henderson TRANS(FDIVq, ALL, do_env_qqq, a, gen_helper_fdivq) 5255a4056239SRichard Henderson 52565e3b17bbSRichard Henderson static bool trans_FdMULq(DisasContext *dc, arg_r_r_r *a) 52575e3b17bbSRichard Henderson { 52585e3b17bbSRichard Henderson TCGv_i64 src1, src2; 5259ba21dc99SRichard Henderson TCGv_i128 dst; 52605e3b17bbSRichard Henderson 52615e3b17bbSRichard Henderson if (gen_trap_ifnofpu(dc)) { 52625e3b17bbSRichard Henderson return true; 52635e3b17bbSRichard Henderson } 52645e3b17bbSRichard Henderson if (gen_trap_float128(dc)) { 52655e3b17bbSRichard Henderson return true; 52665e3b17bbSRichard Henderson } 52675e3b17bbSRichard Henderson 52685e3b17bbSRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1); 52695e3b17bbSRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2); 5270ba21dc99SRichard Henderson dst = tcg_temp_new_i128(); 5271ba21dc99SRichard Henderson gen_helper_fdmulq(dst, tcg_env, src1, src2); 5272ba21dc99SRichard Henderson gen_store_fpr_Q(dc, a->rd, dst); 52735e3b17bbSRichard Henderson return advance_pc(dc); 52745e3b17bbSRichard Henderson } 52755e3b17bbSRichard Henderson 5276f7ec8155SRichard Henderson static bool do_fmovr(DisasContext *dc, arg_FMOVRs *a, bool is_128, 5277f7ec8155SRichard Henderson void (*func)(DisasContext *, DisasCompare *, int, int)) 5278f7ec8155SRichard Henderson { 5279f7ec8155SRichard Henderson DisasCompare cmp; 5280f7ec8155SRichard Henderson 52812c4f56c9SRichard Henderson if (!gen_compare_reg(&cmp, a->cond, gen_load_gpr(dc, a->rs1))) { 52822c4f56c9SRichard Henderson return false; 52832c4f56c9SRichard Henderson } 5284f7ec8155SRichard Henderson if (gen_trap_ifnofpu(dc)) { 5285f7ec8155SRichard Henderson return true; 5286f7ec8155SRichard Henderson } 5287f7ec8155SRichard Henderson if (is_128 && gen_trap_float128(dc)) { 5288f7ec8155SRichard Henderson return true; 5289f7ec8155SRichard Henderson } 5290f7ec8155SRichard Henderson 5291f7ec8155SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 5292f7ec8155SRichard Henderson func(dc, &cmp, a->rd, a->rs2); 5293f7ec8155SRichard Henderson return advance_pc(dc); 5294f7ec8155SRichard Henderson } 5295f7ec8155SRichard Henderson 5296f7ec8155SRichard Henderson TRANS(FMOVRs, 64, do_fmovr, a, false, gen_fmovs) 5297f7ec8155SRichard Henderson TRANS(FMOVRd, 64, do_fmovr, a, false, gen_fmovd) 5298f7ec8155SRichard Henderson TRANS(FMOVRq, 64, do_fmovr, a, true, gen_fmovq) 5299f7ec8155SRichard Henderson 5300f7ec8155SRichard Henderson static bool do_fmovcc(DisasContext *dc, arg_FMOVscc *a, bool is_128, 5301f7ec8155SRichard Henderson void (*func)(DisasContext *, DisasCompare *, int, int)) 5302f7ec8155SRichard Henderson { 5303f7ec8155SRichard Henderson DisasCompare cmp; 5304f7ec8155SRichard Henderson 5305f7ec8155SRichard Henderson if (gen_trap_ifnofpu(dc)) { 5306f7ec8155SRichard Henderson return true; 5307f7ec8155SRichard Henderson } 5308f7ec8155SRichard Henderson if (is_128 && gen_trap_float128(dc)) { 5309f7ec8155SRichard Henderson return true; 5310f7ec8155SRichard Henderson } 5311f7ec8155SRichard Henderson 5312f7ec8155SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 5313f7ec8155SRichard Henderson gen_compare(&cmp, a->cc, a->cond, dc); 5314f7ec8155SRichard Henderson func(dc, &cmp, a->rd, a->rs2); 5315f7ec8155SRichard Henderson return advance_pc(dc); 5316f7ec8155SRichard Henderson } 5317f7ec8155SRichard Henderson 5318f7ec8155SRichard Henderson TRANS(FMOVscc, 64, do_fmovcc, a, false, gen_fmovs) 5319f7ec8155SRichard Henderson TRANS(FMOVdcc, 64, do_fmovcc, a, false, gen_fmovd) 5320f7ec8155SRichard Henderson TRANS(FMOVqcc, 64, do_fmovcc, a, true, gen_fmovq) 5321f7ec8155SRichard Henderson 5322f7ec8155SRichard Henderson static bool do_fmovfcc(DisasContext *dc, arg_FMOVsfcc *a, bool is_128, 5323f7ec8155SRichard Henderson void (*func)(DisasContext *, DisasCompare *, int, int)) 5324f7ec8155SRichard Henderson { 5325f7ec8155SRichard Henderson DisasCompare cmp; 5326f7ec8155SRichard Henderson 5327f7ec8155SRichard Henderson if (gen_trap_ifnofpu(dc)) { 5328f7ec8155SRichard Henderson return true; 5329f7ec8155SRichard Henderson } 5330f7ec8155SRichard Henderson if (is_128 && gen_trap_float128(dc)) { 5331f7ec8155SRichard Henderson return true; 5332f7ec8155SRichard Henderson } 5333f7ec8155SRichard Henderson 5334f7ec8155SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 5335f7ec8155SRichard Henderson gen_fcompare(&cmp, a->cc, a->cond); 5336f7ec8155SRichard Henderson func(dc, &cmp, a->rd, a->rs2); 5337f7ec8155SRichard Henderson return advance_pc(dc); 5338f7ec8155SRichard Henderson } 5339f7ec8155SRichard Henderson 5340f7ec8155SRichard Henderson TRANS(FMOVsfcc, 64, do_fmovfcc, a, false, gen_fmovs) 5341f7ec8155SRichard Henderson TRANS(FMOVdfcc, 64, do_fmovfcc, a, false, gen_fmovd) 5342f7ec8155SRichard Henderson TRANS(FMOVqfcc, 64, do_fmovfcc, a, true, gen_fmovq) 5343f7ec8155SRichard Henderson 534440f9ad21SRichard Henderson static bool do_fcmps(DisasContext *dc, arg_FCMPs *a, bool e) 534540f9ad21SRichard Henderson { 534640f9ad21SRichard Henderson TCGv_i32 src1, src2; 534740f9ad21SRichard Henderson 534840f9ad21SRichard Henderson if (avail_32(dc) && a->cc != 0) { 534940f9ad21SRichard Henderson return false; 535040f9ad21SRichard Henderson } 535140f9ad21SRichard Henderson if (gen_trap_ifnofpu(dc)) { 535240f9ad21SRichard Henderson return true; 535340f9ad21SRichard Henderson } 535440f9ad21SRichard Henderson 535540f9ad21SRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1); 535640f9ad21SRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2); 535740f9ad21SRichard Henderson if (e) { 5358d8c5b92fSRichard Henderson gen_helper_fcmpes(cpu_fcc[a->cc], tcg_env, src1, src2); 535940f9ad21SRichard Henderson } else { 5360d8c5b92fSRichard Henderson gen_helper_fcmps(cpu_fcc[a->cc], tcg_env, src1, src2); 536140f9ad21SRichard Henderson } 536240f9ad21SRichard Henderson return advance_pc(dc); 536340f9ad21SRichard Henderson } 536440f9ad21SRichard Henderson 536540f9ad21SRichard Henderson TRANS(FCMPs, ALL, do_fcmps, a, false) 536640f9ad21SRichard Henderson TRANS(FCMPEs, ALL, do_fcmps, a, true) 536740f9ad21SRichard Henderson 536840f9ad21SRichard Henderson static bool do_fcmpd(DisasContext *dc, arg_FCMPd *a, bool e) 536940f9ad21SRichard Henderson { 537040f9ad21SRichard Henderson TCGv_i64 src1, src2; 537140f9ad21SRichard Henderson 537240f9ad21SRichard Henderson if (avail_32(dc) && a->cc != 0) { 537340f9ad21SRichard Henderson return false; 537440f9ad21SRichard Henderson } 537540f9ad21SRichard Henderson if (gen_trap_ifnofpu(dc)) { 537640f9ad21SRichard Henderson return true; 537740f9ad21SRichard Henderson } 537840f9ad21SRichard Henderson 537940f9ad21SRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1); 538040f9ad21SRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2); 538140f9ad21SRichard Henderson if (e) { 5382d8c5b92fSRichard Henderson gen_helper_fcmped(cpu_fcc[a->cc], tcg_env, src1, src2); 538340f9ad21SRichard Henderson } else { 5384d8c5b92fSRichard Henderson gen_helper_fcmpd(cpu_fcc[a->cc], tcg_env, src1, src2); 538540f9ad21SRichard Henderson } 538640f9ad21SRichard Henderson return advance_pc(dc); 538740f9ad21SRichard Henderson } 538840f9ad21SRichard Henderson 538940f9ad21SRichard Henderson TRANS(FCMPd, ALL, do_fcmpd, a, false) 539040f9ad21SRichard Henderson TRANS(FCMPEd, ALL, do_fcmpd, a, true) 539140f9ad21SRichard Henderson 539240f9ad21SRichard Henderson static bool do_fcmpq(DisasContext *dc, arg_FCMPq *a, bool e) 539340f9ad21SRichard Henderson { 5394f3ceafadSRichard Henderson TCGv_i128 src1, src2; 5395f3ceafadSRichard Henderson 539640f9ad21SRichard Henderson if (avail_32(dc) && a->cc != 0) { 539740f9ad21SRichard Henderson return false; 539840f9ad21SRichard Henderson } 539940f9ad21SRichard Henderson if (gen_trap_ifnofpu(dc)) { 540040f9ad21SRichard Henderson return true; 540140f9ad21SRichard Henderson } 540240f9ad21SRichard Henderson if (gen_trap_float128(dc)) { 540340f9ad21SRichard Henderson return true; 540440f9ad21SRichard Henderson } 540540f9ad21SRichard Henderson 5406f3ceafadSRichard Henderson src1 = gen_load_fpr_Q(dc, a->rs1); 5407f3ceafadSRichard Henderson src2 = gen_load_fpr_Q(dc, a->rs2); 540840f9ad21SRichard Henderson if (e) { 5409d8c5b92fSRichard Henderson gen_helper_fcmpeq(cpu_fcc[a->cc], tcg_env, src1, src2); 541040f9ad21SRichard Henderson } else { 5411d8c5b92fSRichard Henderson gen_helper_fcmpq(cpu_fcc[a->cc], tcg_env, src1, src2); 541240f9ad21SRichard Henderson } 541340f9ad21SRichard Henderson return advance_pc(dc); 541440f9ad21SRichard Henderson } 541540f9ad21SRichard Henderson 541640f9ad21SRichard Henderson TRANS(FCMPq, ALL, do_fcmpq, a, false) 541740f9ad21SRichard Henderson TRANS(FCMPEq, ALL, do_fcmpq, a, true) 541840f9ad21SRichard Henderson 54191d3ed3d7SRichard Henderson static bool trans_FLCMPs(DisasContext *dc, arg_FLCMPs *a) 54201d3ed3d7SRichard Henderson { 54211d3ed3d7SRichard Henderson TCGv_i32 src1, src2; 54221d3ed3d7SRichard Henderson 54231d3ed3d7SRichard Henderson if (!avail_VIS3(dc)) { 54241d3ed3d7SRichard Henderson return false; 54251d3ed3d7SRichard Henderson } 54261d3ed3d7SRichard Henderson if (gen_trap_ifnofpu(dc)) { 54271d3ed3d7SRichard Henderson return true; 54281d3ed3d7SRichard Henderson } 54291d3ed3d7SRichard Henderson 54301d3ed3d7SRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1); 54311d3ed3d7SRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2); 54321d3ed3d7SRichard Henderson gen_helper_flcmps(cpu_fcc[a->cc], src1, src2); 54331d3ed3d7SRichard Henderson return advance_pc(dc); 54341d3ed3d7SRichard Henderson } 54351d3ed3d7SRichard Henderson 54361d3ed3d7SRichard Henderson static bool trans_FLCMPd(DisasContext *dc, arg_FLCMPd *a) 54371d3ed3d7SRichard Henderson { 54381d3ed3d7SRichard Henderson TCGv_i64 src1, src2; 54391d3ed3d7SRichard Henderson 54401d3ed3d7SRichard Henderson if (!avail_VIS3(dc)) { 54411d3ed3d7SRichard Henderson return false; 54421d3ed3d7SRichard Henderson } 54431d3ed3d7SRichard Henderson if (gen_trap_ifnofpu(dc)) { 54441d3ed3d7SRichard Henderson return true; 54451d3ed3d7SRichard Henderson } 54461d3ed3d7SRichard Henderson 54471d3ed3d7SRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1); 54481d3ed3d7SRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2); 54491d3ed3d7SRichard Henderson gen_helper_flcmpd(cpu_fcc[a->cc], src1, src2); 54501d3ed3d7SRichard Henderson return advance_pc(dc); 54511d3ed3d7SRichard Henderson } 54521d3ed3d7SRichard Henderson 545309b157e6SRichard Henderson static bool do_movf2r(DisasContext *dc, arg_r_r *a, 545409b157e6SRichard Henderson int (*offset)(unsigned int), 545509b157e6SRichard Henderson void (*load)(TCGv, TCGv_ptr, tcg_target_long)) 545609b157e6SRichard Henderson { 545709b157e6SRichard Henderson TCGv dst; 545809b157e6SRichard Henderson 545909b157e6SRichard Henderson if (gen_trap_ifnofpu(dc)) { 546009b157e6SRichard Henderson return true; 546109b157e6SRichard Henderson } 546209b157e6SRichard Henderson dst = gen_dest_gpr(dc, a->rd); 546309b157e6SRichard Henderson load(dst, tcg_env, offset(a->rs)); 546409b157e6SRichard Henderson gen_store_gpr(dc, a->rd, dst); 546509b157e6SRichard Henderson return advance_pc(dc); 546609b157e6SRichard Henderson } 546709b157e6SRichard Henderson 546809b157e6SRichard Henderson TRANS(MOVsTOsw, VIS3B, do_movf2r, a, gen_offset_fpr_F, tcg_gen_ld32s_tl) 546909b157e6SRichard Henderson TRANS(MOVsTOuw, VIS3B, do_movf2r, a, gen_offset_fpr_F, tcg_gen_ld32u_tl) 547009b157e6SRichard Henderson TRANS(MOVdTOx, VIS3B, do_movf2r, a, gen_offset_fpr_D, tcg_gen_ld_tl) 547109b157e6SRichard Henderson 547209b157e6SRichard Henderson static bool do_movr2f(DisasContext *dc, arg_r_r *a, 547309b157e6SRichard Henderson int (*offset)(unsigned int), 547409b157e6SRichard Henderson void (*store)(TCGv, TCGv_ptr, tcg_target_long)) 547509b157e6SRichard Henderson { 547609b157e6SRichard Henderson TCGv src; 547709b157e6SRichard Henderson 547809b157e6SRichard Henderson if (gen_trap_ifnofpu(dc)) { 547909b157e6SRichard Henderson return true; 548009b157e6SRichard Henderson } 548109b157e6SRichard Henderson src = gen_load_gpr(dc, a->rs); 548209b157e6SRichard Henderson store(src, tcg_env, offset(a->rd)); 548309b157e6SRichard Henderson return advance_pc(dc); 548409b157e6SRichard Henderson } 548509b157e6SRichard Henderson 548609b157e6SRichard Henderson TRANS(MOVwTOs, VIS3B, do_movr2f, a, gen_offset_fpr_F, tcg_gen_st32_tl) 548709b157e6SRichard Henderson TRANS(MOVxTOd, VIS3B, do_movr2f, a, gen_offset_fpr_D, tcg_gen_st_tl) 548809b157e6SRichard Henderson 54896e61bc94SEmilio G. Cota static void sparc_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) 5490fcf5ef2aSThomas Huth { 54916e61bc94SEmilio G. Cota DisasContext *dc = container_of(dcbase, DisasContext, base); 54926e61bc94SEmilio G. Cota int bound; 5493af00be49SEmilio G. Cota 5494af00be49SEmilio G. Cota dc->pc = dc->base.pc_first; 54956e61bc94SEmilio G. Cota dc->npc = (target_ulong)dc->base.tb->cs_base; 54966e61bc94SEmilio G. Cota dc->mem_idx = dc->base.tb->flags & TB_FLAG_MMU_MASK; 549777976769SPhilippe Mathieu-Daudé dc->def = &cpu_env(cs)->def; 54986e61bc94SEmilio G. Cota dc->fpu_enabled = tb_fpu_enabled(dc->base.tb->flags); 54996e61bc94SEmilio G. Cota dc->address_mask_32bit = tb_am_enabled(dc->base.tb->flags); 5500c9b459aaSArtyom Tarasenko #ifndef CONFIG_USER_ONLY 55016e61bc94SEmilio G. Cota dc->supervisor = (dc->base.tb->flags & TB_FLAG_SUPER) != 0; 5502c9b459aaSArtyom Tarasenko #endif 5503fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64 5504fcf5ef2aSThomas Huth dc->fprs_dirty = 0; 55056e61bc94SEmilio G. Cota dc->asi = (dc->base.tb->flags >> TB_FLAG_ASI_SHIFT) & 0xff; 5506c9b459aaSArtyom Tarasenko #ifndef CONFIG_USER_ONLY 55076e61bc94SEmilio G. Cota dc->hypervisor = (dc->base.tb->flags & TB_FLAG_HYPER) != 0; 5508c9b459aaSArtyom Tarasenko #endif 5509fcf5ef2aSThomas Huth #endif 55106e61bc94SEmilio G. Cota /* 55116e61bc94SEmilio G. Cota * if we reach a page boundary, we stop generation so that the 55126e61bc94SEmilio G. Cota * PC of a TT_TFAULT exception is always in the right page 55136e61bc94SEmilio G. Cota */ 55146e61bc94SEmilio G. Cota bound = -(dc->base.pc_first | TARGET_PAGE_MASK) / 4; 55156e61bc94SEmilio G. Cota dc->base.max_insns = MIN(dc->base.max_insns, bound); 5516af00be49SEmilio G. Cota } 5517fcf5ef2aSThomas Huth 55186e61bc94SEmilio G. Cota static void sparc_tr_tb_start(DisasContextBase *db, CPUState *cs) 55196e61bc94SEmilio G. Cota { 55206e61bc94SEmilio G. Cota } 55216e61bc94SEmilio G. Cota 55226e61bc94SEmilio G. Cota static void sparc_tr_insn_start(DisasContextBase *dcbase, CPUState *cs) 55236e61bc94SEmilio G. Cota { 55246e61bc94SEmilio G. Cota DisasContext *dc = container_of(dcbase, DisasContext, base); 5525633c4283SRichard Henderson target_ulong npc = dc->npc; 55266e61bc94SEmilio G. Cota 5527633c4283SRichard Henderson if (npc & 3) { 5528633c4283SRichard Henderson switch (npc) { 5529633c4283SRichard Henderson case JUMP_PC: 5530fcf5ef2aSThomas Huth assert(dc->jump_pc[1] == dc->pc + 4); 5531633c4283SRichard Henderson npc = dc->jump_pc[0] | JUMP_PC; 5532633c4283SRichard Henderson break; 5533633c4283SRichard Henderson case DYNAMIC_PC: 5534633c4283SRichard Henderson case DYNAMIC_PC_LOOKUP: 5535633c4283SRichard Henderson npc = DYNAMIC_PC; 5536633c4283SRichard Henderson break; 5537633c4283SRichard Henderson default: 5538633c4283SRichard Henderson g_assert_not_reached(); 5539fcf5ef2aSThomas Huth } 55406e61bc94SEmilio G. Cota } 5541633c4283SRichard Henderson tcg_gen_insn_start(dc->pc, npc); 5542633c4283SRichard Henderson } 5543fcf5ef2aSThomas Huth 55446e61bc94SEmilio G. Cota static void sparc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) 55456e61bc94SEmilio G. Cota { 55466e61bc94SEmilio G. Cota DisasContext *dc = container_of(dcbase, DisasContext, base); 55476e61bc94SEmilio G. Cota unsigned int insn; 5548fcf5ef2aSThomas Huth 554977976769SPhilippe Mathieu-Daudé insn = translator_ldl(cpu_env(cs), &dc->base, dc->pc); 5550af00be49SEmilio G. Cota dc->base.pc_next += 4; 5551878cc677SRichard Henderson 5552878cc677SRichard Henderson if (!decode(dc, insn)) { 5553ba9c09b4SRichard Henderson gen_exception(dc, TT_ILL_INSN); 5554878cc677SRichard Henderson } 5555fcf5ef2aSThomas Huth 5556af00be49SEmilio G. Cota if (dc->base.is_jmp == DISAS_NORETURN) { 55576e61bc94SEmilio G. Cota return; 5558c5e6ccdfSEmilio G. Cota } 5559af00be49SEmilio G. Cota if (dc->pc != dc->base.pc_next) { 55606e61bc94SEmilio G. Cota dc->base.is_jmp = DISAS_TOO_MANY; 5561af00be49SEmilio G. Cota } 55626e61bc94SEmilio G. Cota } 5563fcf5ef2aSThomas Huth 55646e61bc94SEmilio G. Cota static void sparc_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs) 55656e61bc94SEmilio G. Cota { 55666e61bc94SEmilio G. Cota DisasContext *dc = container_of(dcbase, DisasContext, base); 5567186e7890SRichard Henderson DisasDelayException *e, *e_next; 5568633c4283SRichard Henderson bool may_lookup; 55696e61bc94SEmilio G. Cota 557089527e3aSRichard Henderson finishing_insn(dc); 557189527e3aSRichard Henderson 557246bb0137SMark Cave-Ayland switch (dc->base.is_jmp) { 557346bb0137SMark Cave-Ayland case DISAS_NEXT: 557446bb0137SMark Cave-Ayland case DISAS_TOO_MANY: 5575633c4283SRichard Henderson if (((dc->pc | dc->npc) & 3) == 0) { 5576fcf5ef2aSThomas Huth /* static PC and NPC: we can use direct chaining */ 5577fcf5ef2aSThomas Huth gen_goto_tb(dc, 0, dc->pc, dc->npc); 5578633c4283SRichard Henderson break; 5579fcf5ef2aSThomas Huth } 5580633c4283SRichard Henderson 5581930f1865SRichard Henderson may_lookup = true; 5582633c4283SRichard Henderson if (dc->pc & 3) { 5583633c4283SRichard Henderson switch (dc->pc) { 5584633c4283SRichard Henderson case DYNAMIC_PC_LOOKUP: 5585633c4283SRichard Henderson break; 5586633c4283SRichard Henderson case DYNAMIC_PC: 5587633c4283SRichard Henderson may_lookup = false; 5588633c4283SRichard Henderson break; 5589633c4283SRichard Henderson default: 5590633c4283SRichard Henderson g_assert_not_reached(); 5591633c4283SRichard Henderson } 5592633c4283SRichard Henderson } else { 5593633c4283SRichard Henderson tcg_gen_movi_tl(cpu_pc, dc->pc); 5594633c4283SRichard Henderson } 5595633c4283SRichard Henderson 5596930f1865SRichard Henderson if (dc->npc & 3) { 5597930f1865SRichard Henderson switch (dc->npc) { 5598930f1865SRichard Henderson case JUMP_PC: 5599930f1865SRichard Henderson gen_generic_branch(dc); 5600930f1865SRichard Henderson break; 5601930f1865SRichard Henderson case DYNAMIC_PC: 5602930f1865SRichard Henderson may_lookup = false; 5603930f1865SRichard Henderson break; 5604930f1865SRichard Henderson case DYNAMIC_PC_LOOKUP: 5605930f1865SRichard Henderson break; 5606930f1865SRichard Henderson default: 5607930f1865SRichard Henderson g_assert_not_reached(); 5608930f1865SRichard Henderson } 5609930f1865SRichard Henderson } else { 5610930f1865SRichard Henderson tcg_gen_movi_tl(cpu_npc, dc->npc); 5611930f1865SRichard Henderson } 5612633c4283SRichard Henderson if (may_lookup) { 5613633c4283SRichard Henderson tcg_gen_lookup_and_goto_ptr(); 5614633c4283SRichard Henderson } else { 561507ea28b4SRichard Henderson tcg_gen_exit_tb(NULL, 0); 5616fcf5ef2aSThomas Huth } 561746bb0137SMark Cave-Ayland break; 561846bb0137SMark Cave-Ayland 561946bb0137SMark Cave-Ayland case DISAS_NORETURN: 562046bb0137SMark Cave-Ayland break; 562146bb0137SMark Cave-Ayland 562246bb0137SMark Cave-Ayland case DISAS_EXIT: 562346bb0137SMark Cave-Ayland /* Exit TB */ 562446bb0137SMark Cave-Ayland save_state(dc); 562546bb0137SMark Cave-Ayland tcg_gen_exit_tb(NULL, 0); 562646bb0137SMark Cave-Ayland break; 562746bb0137SMark Cave-Ayland 562846bb0137SMark Cave-Ayland default: 562946bb0137SMark Cave-Ayland g_assert_not_reached(); 5630fcf5ef2aSThomas Huth } 5631186e7890SRichard Henderson 5632186e7890SRichard Henderson for (e = dc->delay_excp_list; e ; e = e_next) { 5633186e7890SRichard Henderson gen_set_label(e->lab); 5634186e7890SRichard Henderson 5635186e7890SRichard Henderson tcg_gen_movi_tl(cpu_pc, e->pc); 5636186e7890SRichard Henderson if (e->npc % 4 == 0) { 5637186e7890SRichard Henderson tcg_gen_movi_tl(cpu_npc, e->npc); 5638186e7890SRichard Henderson } 5639186e7890SRichard Henderson gen_helper_raise_exception(tcg_env, e->excp); 5640186e7890SRichard Henderson 5641186e7890SRichard Henderson e_next = e->next; 5642186e7890SRichard Henderson g_free(e); 5643186e7890SRichard Henderson } 5644fcf5ef2aSThomas Huth } 56456e61bc94SEmilio G. Cota 56466e61bc94SEmilio G. Cota static const TranslatorOps sparc_tr_ops = { 56476e61bc94SEmilio G. Cota .init_disas_context = sparc_tr_init_disas_context, 56486e61bc94SEmilio G. Cota .tb_start = sparc_tr_tb_start, 56496e61bc94SEmilio G. Cota .insn_start = sparc_tr_insn_start, 56506e61bc94SEmilio G. Cota .translate_insn = sparc_tr_translate_insn, 56516e61bc94SEmilio G. Cota .tb_stop = sparc_tr_tb_stop, 56526e61bc94SEmilio G. Cota }; 56536e61bc94SEmilio G. Cota 5654597f9b2dSRichard Henderson void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int *max_insns, 565532f0c394SAnton Johansson vaddr pc, void *host_pc) 56566e61bc94SEmilio G. Cota { 56576e61bc94SEmilio G. Cota DisasContext dc = {}; 56586e61bc94SEmilio G. Cota 5659306c8721SRichard Henderson translator_loop(cs, tb, max_insns, pc, host_pc, &sparc_tr_ops, &dc.base); 5660fcf5ef2aSThomas Huth } 5661fcf5ef2aSThomas Huth 566255c3ceefSRichard Henderson void sparc_tcg_init(void) 5663fcf5ef2aSThomas Huth { 5664fcf5ef2aSThomas Huth static const char gregnames[32][4] = { 5665fcf5ef2aSThomas Huth "g0", "g1", "g2", "g3", "g4", "g5", "g6", "g7", 5666fcf5ef2aSThomas Huth "o0", "o1", "o2", "o3", "o4", "o5", "o6", "o7", 5667fcf5ef2aSThomas Huth "l0", "l1", "l2", "l3", "l4", "l5", "l6", "l7", 5668fcf5ef2aSThomas Huth "i0", "i1", "i2", "i3", "i4", "i5", "i6", "i7", 5669fcf5ef2aSThomas Huth }; 5670fcf5ef2aSThomas Huth 5671d8c5b92fSRichard Henderson static const struct { TCGv_i32 *ptr; int off; const char *name; } r32[] = { 5672d8c5b92fSRichard Henderson #ifdef TARGET_SPARC64 5673d8c5b92fSRichard Henderson { &cpu_fprs, offsetof(CPUSPARCState, fprs), "fprs" }, 5674d8c5b92fSRichard Henderson { &cpu_fcc[0], offsetof(CPUSPARCState, fcc[0]), "fcc0" }, 5675d8c5b92fSRichard Henderson { &cpu_fcc[1], offsetof(CPUSPARCState, fcc[1]), "fcc1" }, 5676d8c5b92fSRichard Henderson { &cpu_fcc[2], offsetof(CPUSPARCState, fcc[2]), "fcc2" }, 5677d8c5b92fSRichard Henderson { &cpu_fcc[3], offsetof(CPUSPARCState, fcc[3]), "fcc3" }, 5678d8c5b92fSRichard Henderson #else 5679d8c5b92fSRichard Henderson { &cpu_fcc[0], offsetof(CPUSPARCState, fcc[0]), "fcc" }, 5680d8c5b92fSRichard Henderson #endif 5681d8c5b92fSRichard Henderson }; 5682d8c5b92fSRichard Henderson 5683fcf5ef2aSThomas Huth static const struct { TCGv *ptr; int off; const char *name; } rtl[] = { 5684fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64 5685fcf5ef2aSThomas Huth { &cpu_gsr, offsetof(CPUSPARCState, gsr), "gsr" }, 56862a1905c7SRichard Henderson { &cpu_xcc_Z, offsetof(CPUSPARCState, xcc_Z), "xcc_Z" }, 56872a1905c7SRichard Henderson { &cpu_xcc_C, offsetof(CPUSPARCState, xcc_C), "xcc_C" }, 5688fcf5ef2aSThomas Huth #endif 56892a1905c7SRichard Henderson { &cpu_cc_N, offsetof(CPUSPARCState, cc_N), "cc_N" }, 56902a1905c7SRichard Henderson { &cpu_cc_V, offsetof(CPUSPARCState, cc_V), "cc_V" }, 56912a1905c7SRichard Henderson { &cpu_icc_Z, offsetof(CPUSPARCState, icc_Z), "icc_Z" }, 56922a1905c7SRichard Henderson { &cpu_icc_C, offsetof(CPUSPARCState, icc_C), "icc_C" }, 5693fcf5ef2aSThomas Huth { &cpu_cond, offsetof(CPUSPARCState, cond), "cond" }, 5694fcf5ef2aSThomas Huth { &cpu_pc, offsetof(CPUSPARCState, pc), "pc" }, 5695fcf5ef2aSThomas Huth { &cpu_npc, offsetof(CPUSPARCState, npc), "npc" }, 5696fcf5ef2aSThomas Huth { &cpu_y, offsetof(CPUSPARCState, y), "y" }, 5697fcf5ef2aSThomas Huth { &cpu_tbr, offsetof(CPUSPARCState, tbr), "tbr" }, 5698fcf5ef2aSThomas Huth }; 5699fcf5ef2aSThomas Huth 5700fcf5ef2aSThomas Huth unsigned int i; 5701fcf5ef2aSThomas Huth 5702ad75a51eSRichard Henderson cpu_regwptr = tcg_global_mem_new_ptr(tcg_env, 5703fcf5ef2aSThomas Huth offsetof(CPUSPARCState, regwptr), 5704fcf5ef2aSThomas Huth "regwptr"); 5705fcf5ef2aSThomas Huth 5706d8c5b92fSRichard Henderson for (i = 0; i < ARRAY_SIZE(r32); ++i) { 5707d8c5b92fSRichard Henderson *r32[i].ptr = tcg_global_mem_new_i32(tcg_env, r32[i].off, r32[i].name); 5708d8c5b92fSRichard Henderson } 5709d8c5b92fSRichard Henderson 5710fcf5ef2aSThomas Huth for (i = 0; i < ARRAY_SIZE(rtl); ++i) { 5711ad75a51eSRichard Henderson *rtl[i].ptr = tcg_global_mem_new(tcg_env, rtl[i].off, rtl[i].name); 5712fcf5ef2aSThomas Huth } 5713fcf5ef2aSThomas Huth 5714f764718dSRichard Henderson cpu_regs[0] = NULL; 5715fcf5ef2aSThomas Huth for (i = 1; i < 8; ++i) { 5716ad75a51eSRichard Henderson cpu_regs[i] = tcg_global_mem_new(tcg_env, 5717fcf5ef2aSThomas Huth offsetof(CPUSPARCState, gregs[i]), 5718fcf5ef2aSThomas Huth gregnames[i]); 5719fcf5ef2aSThomas Huth } 5720fcf5ef2aSThomas Huth 5721fcf5ef2aSThomas Huth for (i = 8; i < 32; ++i) { 5722fcf5ef2aSThomas Huth cpu_regs[i] = tcg_global_mem_new(cpu_regwptr, 5723fcf5ef2aSThomas Huth (i - 8) * sizeof(target_ulong), 5724fcf5ef2aSThomas Huth gregnames[i]); 5725fcf5ef2aSThomas Huth } 5726fcf5ef2aSThomas Huth } 5727fcf5ef2aSThomas Huth 5728f36aaa53SRichard Henderson void sparc_restore_state_to_opc(CPUState *cs, 5729f36aaa53SRichard Henderson const TranslationBlock *tb, 5730f36aaa53SRichard Henderson const uint64_t *data) 5731fcf5ef2aSThomas Huth { 573277976769SPhilippe Mathieu-Daudé CPUSPARCState *env = cpu_env(cs); 5733fcf5ef2aSThomas Huth target_ulong pc = data[0]; 5734fcf5ef2aSThomas Huth target_ulong npc = data[1]; 5735fcf5ef2aSThomas Huth 5736fcf5ef2aSThomas Huth env->pc = pc; 5737fcf5ef2aSThomas Huth if (npc == DYNAMIC_PC) { 5738fcf5ef2aSThomas Huth /* dynamic NPC: already stored */ 5739fcf5ef2aSThomas Huth } else if (npc & JUMP_PC) { 5740fcf5ef2aSThomas Huth /* jump PC: use 'cond' and the jump targets of the translation */ 5741fcf5ef2aSThomas Huth if (env->cond) { 5742fcf5ef2aSThomas Huth env->npc = npc & ~3; 5743fcf5ef2aSThomas Huth } else { 5744fcf5ef2aSThomas Huth env->npc = pc + 4; 5745fcf5ef2aSThomas Huth } 5746fcf5ef2aSThomas Huth } else { 5747fcf5ef2aSThomas Huth env->npc = npc; 5748fcf5ef2aSThomas Huth } 5749fcf5ef2aSThomas Huth } 5750