1fcf5ef2aSThomas Huth /* 2fcf5ef2aSThomas Huth SPARC translation 3fcf5ef2aSThomas Huth 4fcf5ef2aSThomas Huth Copyright (C) 2003 Thomas M. Ogrisegg <tom@fnord.at> 5fcf5ef2aSThomas Huth Copyright (C) 2003-2005 Fabrice Bellard 6fcf5ef2aSThomas Huth 7fcf5ef2aSThomas Huth This library is free software; you can redistribute it and/or 8fcf5ef2aSThomas Huth modify it under the terms of the GNU Lesser General Public 9fcf5ef2aSThomas Huth License as published by the Free Software Foundation; either 105650b549SChetan Pant version 2.1 of the License, or (at your option) any later version. 11fcf5ef2aSThomas Huth 12fcf5ef2aSThomas Huth This library is distributed in the hope that it will be useful, 13fcf5ef2aSThomas Huth but WITHOUT ANY WARRANTY; without even the implied warranty of 14fcf5ef2aSThomas Huth MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15fcf5ef2aSThomas Huth Lesser General Public License for more details. 16fcf5ef2aSThomas Huth 17fcf5ef2aSThomas Huth You should have received a copy of the GNU Lesser General Public 18fcf5ef2aSThomas Huth License along with this library; if not, see <http://www.gnu.org/licenses/>. 19fcf5ef2aSThomas Huth */ 20fcf5ef2aSThomas Huth 21fcf5ef2aSThomas Huth #include "qemu/osdep.h" 22fcf5ef2aSThomas Huth 23fcf5ef2aSThomas Huth #include "cpu.h" 24fcf5ef2aSThomas Huth #include "disas/disas.h" 25fcf5ef2aSThomas Huth #include "exec/helper-proto.h" 26fcf5ef2aSThomas Huth #include "exec/exec-all.h" 27dcb32f1dSPhilippe Mathieu-Daudé #include "tcg/tcg-op.h" 28fafba1bbSRichard Henderson #include "tcg/tcg-op-gvec.h" 29fcf5ef2aSThomas Huth #include "exec/helper-gen.h" 30c5e6ccdfSEmilio G. Cota #include "exec/translator.h" 31fcf5ef2aSThomas Huth #include "exec/log.h" 32fcf5ef2aSThomas Huth #include "asi.h" 33fcf5ef2aSThomas Huth 34d53106c9SRichard Henderson #define HELPER_H "helper.h" 35d53106c9SRichard Henderson #include "exec/helper-info.c.inc" 36d53106c9SRichard Henderson #undef HELPER_H 37fcf5ef2aSThomas Huth 38668bb9b7SRichard Henderson #ifdef TARGET_SPARC64 39668bb9b7SRichard Henderson # define gen_helper_rdpsr(D, E) qemu_build_not_reached() 4086b82fe0SRichard Henderson # define gen_helper_rett(E) qemu_build_not_reached() 410faef01bSRichard Henderson # define gen_helper_power_down(E) qemu_build_not_reached() 4225524734SRichard Henderson # define gen_helper_wrpsr(E, S) qemu_build_not_reached() 43668bb9b7SRichard Henderson #else 440faef01bSRichard Henderson # define gen_helper_clear_softint(E, S) qemu_build_not_reached() 458f75b8a4SRichard Henderson # define gen_helper_done(E) qemu_build_not_reached() 46c6d83e4fSRichard Henderson # define gen_helper_fabsd(D, S) qemu_build_not_reached() 47e8325dc0SRichard Henderson # define gen_helper_flushw(E) qemu_build_not_reached() 48c6d83e4fSRichard Henderson # define gen_helper_fnegd(D, S) 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() 544ee85ea9SRichard Henderson # define gen_helper_sdivx(D, E, A, B) qemu_build_not_reached() 550faef01bSRichard Henderson # define gen_helper_set_softint(E, S) qemu_build_not_reached() 56af25071cSRichard Henderson # define gen_helper_tick_get_count(D, E, T, C) qemu_build_not_reached() 579422278eSRichard Henderson # define gen_helper_tick_set_count(P, S) qemu_build_not_reached() 58bb97f2f5SRichard Henderson # define gen_helper_tick_set_limit(P, S) qemu_build_not_reached() 594ee85ea9SRichard Henderson # define gen_helper_udivx(D, E, A, B) qemu_build_not_reached() 600faef01bSRichard Henderson # define gen_helper_wrccr(E, S) qemu_build_not_reached() 619422278eSRichard Henderson # define gen_helper_wrcwp(E, S) qemu_build_not_reached() 629422278eSRichard Henderson # define gen_helper_wrgl(E, S) qemu_build_not_reached() 630faef01bSRichard Henderson # define gen_helper_write_softint(E, S) qemu_build_not_reached() 649422278eSRichard Henderson # define gen_helper_wrpil(E, S) qemu_build_not_reached() 659422278eSRichard Henderson # define gen_helper_wrpstate(E, S) qemu_build_not_reached() 66f4e18df5SRichard Henderson # define gen_helper_fabsq ({ qemu_build_not_reached(); NULL; }) 67e2fa6bd1SRichard Henderson # define gen_helper_fcmpeq16 ({ qemu_build_not_reached(); NULL; }) 68e2fa6bd1SRichard Henderson # define gen_helper_fcmpeq32 ({ qemu_build_not_reached(); NULL; }) 69e2fa6bd1SRichard Henderson # define gen_helper_fcmpgt16 ({ qemu_build_not_reached(); NULL; }) 70e2fa6bd1SRichard Henderson # define gen_helper_fcmpgt32 ({ qemu_build_not_reached(); NULL; }) 71e2fa6bd1SRichard Henderson # define gen_helper_fcmple16 ({ qemu_build_not_reached(); NULL; }) 72e2fa6bd1SRichard Henderson # define gen_helper_fcmple32 ({ qemu_build_not_reached(); NULL; }) 73e2fa6bd1SRichard Henderson # define gen_helper_fcmpne16 ({ qemu_build_not_reached(); NULL; }) 74e2fa6bd1SRichard Henderson # define gen_helper_fcmpne32 ({ qemu_build_not_reached(); NULL; }) 758aa418b3SRichard Henderson # define gen_helper_fdtox ({ qemu_build_not_reached(); NULL; }) 76e06c9f83SRichard Henderson # define gen_helper_fexpand ({ qemu_build_not_reached(); NULL; }) 77e06c9f83SRichard Henderson # define gen_helper_fmul8sux16 ({ qemu_build_not_reached(); NULL; }) 78e06c9f83SRichard Henderson # define gen_helper_fmul8ulx16 ({ qemu_build_not_reached(); NULL; }) 79e06c9f83SRichard Henderson # define gen_helper_fmul8x16al ({ qemu_build_not_reached(); NULL; }) 80e06c9f83SRichard Henderson # define gen_helper_fmul8x16au ({ qemu_build_not_reached(); NULL; }) 81e06c9f83SRichard Henderson # define gen_helper_fmul8x16 ({ qemu_build_not_reached(); NULL; }) 82e06c9f83SRichard Henderson # define gen_helper_fmuld8sux16 ({ qemu_build_not_reached(); NULL; }) 83e06c9f83SRichard Henderson # define gen_helper_fmuld8ulx16 ({ qemu_build_not_reached(); NULL; }) 84f4e18df5SRichard Henderson # define gen_helper_fnegq ({ qemu_build_not_reached(); NULL; }) 85e06c9f83SRichard Henderson # define gen_helper_fpmerge ({ qemu_build_not_reached(); NULL; }) 861617586fSRichard Henderson # define gen_helper_fqtox ({ qemu_build_not_reached(); NULL; }) 87199d43efSRichard Henderson # define gen_helper_fstox ({ qemu_build_not_reached(); NULL; }) 888aa418b3SRichard Henderson # define gen_helper_fxtod ({ qemu_build_not_reached(); NULL; }) 897b8e3e1aSRichard Henderson # define gen_helper_fxtoq ({ qemu_build_not_reached(); NULL; }) 90f4e18df5SRichard Henderson # define gen_helper_fxtos ({ qemu_build_not_reached(); NULL; }) 91afb04344SRichard Henderson # define gen_helper_pdist ({ qemu_build_not_reached(); NULL; }) 92da681406SRichard Henderson # define FSR_LDXFSR_MASK 0 93da681406SRichard Henderson # define FSR_LDXFSR_OLDMASK 0 94668bb9b7SRichard Henderson # define MAXTL_MASK 0 95af25071cSRichard Henderson #endif 96af25071cSRichard Henderson 97633c4283SRichard Henderson /* Dynamic PC, must exit to main loop. */ 98633c4283SRichard Henderson #define DYNAMIC_PC 1 99633c4283SRichard Henderson /* Dynamic PC, one of two values according to jump_pc[T2]. */ 100633c4283SRichard Henderson #define JUMP_PC 2 101633c4283SRichard Henderson /* Dynamic PC, may lookup next TB. */ 102633c4283SRichard Henderson #define DYNAMIC_PC_LOOKUP 3 103fcf5ef2aSThomas Huth 10446bb0137SMark Cave-Ayland #define DISAS_EXIT DISAS_TARGET_0 10546bb0137SMark Cave-Ayland 106fcf5ef2aSThomas Huth /* global register indexes */ 107fcf5ef2aSThomas Huth static TCGv_ptr cpu_regwptr; 108fcf5ef2aSThomas Huth static TCGv cpu_fsr, cpu_pc, cpu_npc; 109fcf5ef2aSThomas Huth static TCGv cpu_regs[32]; 110fcf5ef2aSThomas Huth static TCGv cpu_y; 111fcf5ef2aSThomas Huth static TCGv cpu_tbr; 112fcf5ef2aSThomas Huth static TCGv cpu_cond; 1132a1905c7SRichard Henderson static TCGv cpu_cc_N; 1142a1905c7SRichard Henderson static TCGv cpu_cc_V; 1152a1905c7SRichard Henderson static TCGv cpu_icc_Z; 1162a1905c7SRichard Henderson static TCGv cpu_icc_C; 117fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64 1182a1905c7SRichard Henderson static TCGv cpu_xcc_Z; 1192a1905c7SRichard Henderson static TCGv cpu_xcc_C; 1202a1905c7SRichard Henderson static TCGv_i32 cpu_fprs; 121fcf5ef2aSThomas Huth static TCGv cpu_gsr; 122fcf5ef2aSThomas Huth #else 123af25071cSRichard Henderson # define cpu_fprs ({ qemu_build_not_reached(); (TCGv)NULL; }) 124af25071cSRichard Henderson # define cpu_gsr ({ qemu_build_not_reached(); (TCGv)NULL; }) 125fcf5ef2aSThomas Huth #endif 1262a1905c7SRichard Henderson 1272a1905c7SRichard Henderson #ifdef TARGET_SPARC64 1282a1905c7SRichard Henderson #define cpu_cc_Z cpu_xcc_Z 1292a1905c7SRichard Henderson #define cpu_cc_C cpu_xcc_C 1302a1905c7SRichard Henderson #else 1312a1905c7SRichard Henderson #define cpu_cc_Z cpu_icc_Z 1322a1905c7SRichard Henderson #define cpu_cc_C cpu_icc_C 1332a1905c7SRichard Henderson #define cpu_xcc_Z ({ qemu_build_not_reached(); NULL; }) 1342a1905c7SRichard Henderson #define cpu_xcc_C ({ qemu_build_not_reached(); NULL; }) 1352a1905c7SRichard Henderson #endif 1362a1905c7SRichard Henderson 137fcf5ef2aSThomas Huth /* Floating point registers */ 138fcf5ef2aSThomas Huth static TCGv_i64 cpu_fpr[TARGET_DPREGS]; 139fcf5ef2aSThomas Huth 140af25071cSRichard Henderson #define env_field_offsetof(X) offsetof(CPUSPARCState, X) 141af25071cSRichard Henderson #ifdef TARGET_SPARC64 142cd6269f7SRichard Henderson # define env32_field_offsetof(X) ({ qemu_build_not_reached(); 0; }) 143af25071cSRichard Henderson # define env64_field_offsetof(X) env_field_offsetof(X) 144af25071cSRichard Henderson #else 145cd6269f7SRichard Henderson # define env32_field_offsetof(X) env_field_offsetof(X) 146af25071cSRichard Henderson # define env64_field_offsetof(X) ({ qemu_build_not_reached(); 0; }) 147af25071cSRichard Henderson #endif 148af25071cSRichard Henderson 149186e7890SRichard Henderson typedef struct DisasDelayException { 150186e7890SRichard Henderson struct DisasDelayException *next; 151186e7890SRichard Henderson TCGLabel *lab; 152186e7890SRichard Henderson TCGv_i32 excp; 153186e7890SRichard Henderson /* Saved state at parent insn. */ 154186e7890SRichard Henderson target_ulong pc; 155186e7890SRichard Henderson target_ulong npc; 156186e7890SRichard Henderson } DisasDelayException; 157186e7890SRichard Henderson 158fcf5ef2aSThomas Huth typedef struct DisasContext { 159af00be49SEmilio G. Cota DisasContextBase base; 160fcf5ef2aSThomas Huth target_ulong pc; /* current Program Counter: integer or DYNAMIC_PC */ 161fcf5ef2aSThomas Huth target_ulong npc; /* next PC: integer or DYNAMIC_PC or JUMP_PC */ 162fcf5ef2aSThomas Huth target_ulong jump_pc[2]; /* used when JUMP_PC pc value is used */ 163fcf5ef2aSThomas Huth int mem_idx; 164c9b459aaSArtyom Tarasenko bool fpu_enabled; 165c9b459aaSArtyom Tarasenko bool address_mask_32bit; 166c9b459aaSArtyom Tarasenko #ifndef CONFIG_USER_ONLY 167c9b459aaSArtyom Tarasenko bool supervisor; 168c9b459aaSArtyom Tarasenko #ifdef TARGET_SPARC64 169c9b459aaSArtyom Tarasenko bool hypervisor; 170c9b459aaSArtyom Tarasenko #endif 171c9b459aaSArtyom Tarasenko #endif 172c9b459aaSArtyom Tarasenko 173fcf5ef2aSThomas Huth sparc_def_t *def; 174fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64 175fcf5ef2aSThomas Huth int fprs_dirty; 176fcf5ef2aSThomas Huth int asi; 177fcf5ef2aSThomas Huth #endif 178186e7890SRichard Henderson DisasDelayException *delay_excp_list; 179fcf5ef2aSThomas Huth } DisasContext; 180fcf5ef2aSThomas Huth 181fcf5ef2aSThomas Huth typedef struct { 182fcf5ef2aSThomas Huth TCGCond cond; 183c8507ebfSRichard Henderson TCGv c1; 184c8507ebfSRichard Henderson int c2; 185fcf5ef2aSThomas Huth } DisasCompare; 186fcf5ef2aSThomas Huth 187fcf5ef2aSThomas Huth // This function uses non-native bit order 188fcf5ef2aSThomas Huth #define GET_FIELD(X, FROM, TO) \ 189fcf5ef2aSThomas Huth ((X) >> (31 - (TO)) & ((1 << ((TO) - (FROM) + 1)) - 1)) 190fcf5ef2aSThomas Huth 191fcf5ef2aSThomas Huth // This function uses the order in the manuals, i.e. bit 0 is 2^0 192fcf5ef2aSThomas Huth #define GET_FIELD_SP(X, FROM, TO) \ 193fcf5ef2aSThomas Huth GET_FIELD(X, 31 - (TO), 31 - (FROM)) 194fcf5ef2aSThomas Huth 195fcf5ef2aSThomas Huth #define GET_FIELDs(x,a,b) sign_extend (GET_FIELD(x,a,b), (b) - (a) + 1) 196fcf5ef2aSThomas Huth #define GET_FIELD_SPs(x,a,b) sign_extend (GET_FIELD_SP(x,a,b), ((b) - (a) + 1)) 197fcf5ef2aSThomas Huth 198fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64 199fcf5ef2aSThomas Huth #define DFPREG(r) (((r & 1) << 5) | (r & 0x1e)) 200fcf5ef2aSThomas Huth #define QFPREG(r) (((r & 1) << 5) | (r & 0x1c)) 201fcf5ef2aSThomas Huth #else 202fcf5ef2aSThomas Huth #define DFPREG(r) (r & 0x1e) 203fcf5ef2aSThomas Huth #define QFPREG(r) (r & 0x1c) 204fcf5ef2aSThomas Huth #endif 205fcf5ef2aSThomas Huth 206fcf5ef2aSThomas Huth #define UA2005_HTRAP_MASK 0xff 207fcf5ef2aSThomas Huth #define V8_TRAP_MASK 0x7f 208fcf5ef2aSThomas Huth 209fcf5ef2aSThomas Huth #define IS_IMM (insn & (1<<13)) 210fcf5ef2aSThomas Huth 2110c2e96c1SRichard Henderson static void gen_update_fprs_dirty(DisasContext *dc, int rd) 212fcf5ef2aSThomas Huth { 213fcf5ef2aSThomas Huth #if defined(TARGET_SPARC64) 214fcf5ef2aSThomas Huth int bit = (rd < 32) ? 1 : 2; 215fcf5ef2aSThomas Huth /* If we know we've already set this bit within the TB, 216fcf5ef2aSThomas Huth we can avoid setting it again. */ 217fcf5ef2aSThomas Huth if (!(dc->fprs_dirty & bit)) { 218fcf5ef2aSThomas Huth dc->fprs_dirty |= bit; 219fcf5ef2aSThomas Huth tcg_gen_ori_i32(cpu_fprs, cpu_fprs, bit); 220fcf5ef2aSThomas Huth } 221fcf5ef2aSThomas Huth #endif 222fcf5ef2aSThomas Huth } 223fcf5ef2aSThomas Huth 224fcf5ef2aSThomas Huth /* floating point registers moves */ 225fcf5ef2aSThomas Huth static TCGv_i32 gen_load_fpr_F(DisasContext *dc, unsigned int src) 226fcf5ef2aSThomas Huth { 22736ab4623SRichard Henderson TCGv_i32 ret = tcg_temp_new_i32(); 228dc41aa7dSRichard Henderson if (src & 1) { 229dc41aa7dSRichard Henderson tcg_gen_extrl_i64_i32(ret, cpu_fpr[src / 2]); 230dc41aa7dSRichard Henderson } else { 231dc41aa7dSRichard Henderson tcg_gen_extrh_i64_i32(ret, cpu_fpr[src / 2]); 232fcf5ef2aSThomas Huth } 233dc41aa7dSRichard Henderson return ret; 234fcf5ef2aSThomas Huth } 235fcf5ef2aSThomas Huth 236fcf5ef2aSThomas Huth static void gen_store_fpr_F(DisasContext *dc, unsigned int dst, TCGv_i32 v) 237fcf5ef2aSThomas Huth { 2388e7bbc75SRichard Henderson TCGv_i64 t = tcg_temp_new_i64(); 2398e7bbc75SRichard Henderson 2408e7bbc75SRichard Henderson tcg_gen_extu_i32_i64(t, v); 241fcf5ef2aSThomas Huth tcg_gen_deposit_i64(cpu_fpr[dst / 2], cpu_fpr[dst / 2], t, 242fcf5ef2aSThomas Huth (dst & 1 ? 0 : 32), 32); 243fcf5ef2aSThomas Huth gen_update_fprs_dirty(dc, dst); 244fcf5ef2aSThomas Huth } 245fcf5ef2aSThomas Huth 246fcf5ef2aSThomas Huth static TCGv_i32 gen_dest_fpr_F(DisasContext *dc) 247fcf5ef2aSThomas Huth { 24836ab4623SRichard Henderson return tcg_temp_new_i32(); 249fcf5ef2aSThomas Huth } 250fcf5ef2aSThomas Huth 251fcf5ef2aSThomas Huth static TCGv_i64 gen_load_fpr_D(DisasContext *dc, unsigned int src) 252fcf5ef2aSThomas Huth { 253fcf5ef2aSThomas Huth src = DFPREG(src); 254fcf5ef2aSThomas Huth return cpu_fpr[src / 2]; 255fcf5ef2aSThomas Huth } 256fcf5ef2aSThomas Huth 257fcf5ef2aSThomas Huth static void gen_store_fpr_D(DisasContext *dc, unsigned int dst, TCGv_i64 v) 258fcf5ef2aSThomas Huth { 259fcf5ef2aSThomas Huth dst = DFPREG(dst); 260fcf5ef2aSThomas Huth tcg_gen_mov_i64(cpu_fpr[dst / 2], v); 261fcf5ef2aSThomas Huth gen_update_fprs_dirty(dc, dst); 262fcf5ef2aSThomas Huth } 263fcf5ef2aSThomas Huth 264fcf5ef2aSThomas Huth static TCGv_i64 gen_dest_fpr_D(DisasContext *dc, unsigned int dst) 265fcf5ef2aSThomas Huth { 266fcf5ef2aSThomas Huth return cpu_fpr[DFPREG(dst) / 2]; 267fcf5ef2aSThomas Huth } 268fcf5ef2aSThomas Huth 269fcf5ef2aSThomas Huth static void gen_op_load_fpr_QT0(unsigned int src) 270fcf5ef2aSThomas Huth { 271ad75a51eSRichard Henderson tcg_gen_st_i64(cpu_fpr[src / 2], tcg_env, offsetof(CPUSPARCState, qt0) + 272fcf5ef2aSThomas Huth offsetof(CPU_QuadU, ll.upper)); 273ad75a51eSRichard Henderson tcg_gen_st_i64(cpu_fpr[src/2 + 1], tcg_env, offsetof(CPUSPARCState, qt0) + 274fcf5ef2aSThomas Huth offsetof(CPU_QuadU, ll.lower)); 275fcf5ef2aSThomas Huth } 276fcf5ef2aSThomas Huth 277fcf5ef2aSThomas Huth static void gen_op_load_fpr_QT1(unsigned int src) 278fcf5ef2aSThomas Huth { 279ad75a51eSRichard Henderson tcg_gen_st_i64(cpu_fpr[src / 2], tcg_env, offsetof(CPUSPARCState, qt1) + 280fcf5ef2aSThomas Huth offsetof(CPU_QuadU, ll.upper)); 281ad75a51eSRichard Henderson tcg_gen_st_i64(cpu_fpr[src/2 + 1], tcg_env, offsetof(CPUSPARCState, qt1) + 282fcf5ef2aSThomas Huth offsetof(CPU_QuadU, ll.lower)); 283fcf5ef2aSThomas Huth } 284fcf5ef2aSThomas Huth 285fcf5ef2aSThomas Huth static void gen_op_store_QT0_fpr(unsigned int dst) 286fcf5ef2aSThomas Huth { 287ad75a51eSRichard Henderson tcg_gen_ld_i64(cpu_fpr[dst / 2], tcg_env, offsetof(CPUSPARCState, qt0) + 288fcf5ef2aSThomas Huth offsetof(CPU_QuadU, ll.upper)); 289ad75a51eSRichard Henderson tcg_gen_ld_i64(cpu_fpr[dst/2 + 1], tcg_env, offsetof(CPUSPARCState, qt0) + 290fcf5ef2aSThomas Huth offsetof(CPU_QuadU, ll.lower)); 291fcf5ef2aSThomas Huth } 292fcf5ef2aSThomas Huth 293fcf5ef2aSThomas Huth /* moves */ 294fcf5ef2aSThomas Huth #ifdef CONFIG_USER_ONLY 295fcf5ef2aSThomas Huth #define supervisor(dc) 0 296fcf5ef2aSThomas Huth #define hypervisor(dc) 0 297fcf5ef2aSThomas Huth #else 298fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64 299c9b459aaSArtyom Tarasenko #define hypervisor(dc) (dc->hypervisor) 300c9b459aaSArtyom Tarasenko #define supervisor(dc) (dc->supervisor | dc->hypervisor) 301fcf5ef2aSThomas Huth #else 302c9b459aaSArtyom Tarasenko #define supervisor(dc) (dc->supervisor) 303668bb9b7SRichard Henderson #define hypervisor(dc) 0 304fcf5ef2aSThomas Huth #endif 305fcf5ef2aSThomas Huth #endif 306fcf5ef2aSThomas Huth 307b1bc09eaSRichard Henderson #if !defined(TARGET_SPARC64) 308b1bc09eaSRichard Henderson # define AM_CHECK(dc) false 309b1bc09eaSRichard Henderson #elif defined(TARGET_ABI32) 310b1bc09eaSRichard Henderson # define AM_CHECK(dc) true 311b1bc09eaSRichard Henderson #elif defined(CONFIG_USER_ONLY) 312b1bc09eaSRichard Henderson # define AM_CHECK(dc) false 313fcf5ef2aSThomas Huth #else 314b1bc09eaSRichard Henderson # define AM_CHECK(dc) ((dc)->address_mask_32bit) 315fcf5ef2aSThomas Huth #endif 316fcf5ef2aSThomas Huth 3170c2e96c1SRichard Henderson static void gen_address_mask(DisasContext *dc, TCGv addr) 318fcf5ef2aSThomas Huth { 319b1bc09eaSRichard Henderson if (AM_CHECK(dc)) { 320fcf5ef2aSThomas Huth tcg_gen_andi_tl(addr, addr, 0xffffffffULL); 321b1bc09eaSRichard Henderson } 322fcf5ef2aSThomas Huth } 323fcf5ef2aSThomas Huth 32423ada1b1SRichard Henderson static target_ulong address_mask_i(DisasContext *dc, target_ulong addr) 32523ada1b1SRichard Henderson { 32623ada1b1SRichard Henderson return AM_CHECK(dc) ? (uint32_t)addr : addr; 32723ada1b1SRichard Henderson } 32823ada1b1SRichard Henderson 3290c2e96c1SRichard Henderson static TCGv gen_load_gpr(DisasContext *dc, int reg) 330fcf5ef2aSThomas Huth { 331fcf5ef2aSThomas Huth if (reg > 0) { 332fcf5ef2aSThomas Huth assert(reg < 32); 333fcf5ef2aSThomas Huth return cpu_regs[reg]; 334fcf5ef2aSThomas Huth } else { 33552123f14SRichard Henderson TCGv t = tcg_temp_new(); 336fcf5ef2aSThomas Huth tcg_gen_movi_tl(t, 0); 337fcf5ef2aSThomas Huth return t; 338fcf5ef2aSThomas Huth } 339fcf5ef2aSThomas Huth } 340fcf5ef2aSThomas Huth 3410c2e96c1SRichard Henderson static void gen_store_gpr(DisasContext *dc, int reg, TCGv v) 342fcf5ef2aSThomas Huth { 343fcf5ef2aSThomas Huth if (reg > 0) { 344fcf5ef2aSThomas Huth assert(reg < 32); 345fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_regs[reg], v); 346fcf5ef2aSThomas Huth } 347fcf5ef2aSThomas Huth } 348fcf5ef2aSThomas Huth 3490c2e96c1SRichard Henderson static TCGv gen_dest_gpr(DisasContext *dc, int reg) 350fcf5ef2aSThomas Huth { 351fcf5ef2aSThomas Huth if (reg > 0) { 352fcf5ef2aSThomas Huth assert(reg < 32); 353fcf5ef2aSThomas Huth return cpu_regs[reg]; 354fcf5ef2aSThomas Huth } else { 35552123f14SRichard Henderson return tcg_temp_new(); 356fcf5ef2aSThomas Huth } 357fcf5ef2aSThomas Huth } 358fcf5ef2aSThomas Huth 3595645aa2eSRichard Henderson static bool use_goto_tb(DisasContext *s, target_ulong pc, target_ulong npc) 360fcf5ef2aSThomas Huth { 3615645aa2eSRichard Henderson return translator_use_goto_tb(&s->base, pc) && 3625645aa2eSRichard Henderson translator_use_goto_tb(&s->base, npc); 363fcf5ef2aSThomas Huth } 364fcf5ef2aSThomas Huth 3655645aa2eSRichard Henderson static void gen_goto_tb(DisasContext *s, int tb_num, 366fcf5ef2aSThomas Huth target_ulong pc, target_ulong npc) 367fcf5ef2aSThomas Huth { 368fcf5ef2aSThomas Huth if (use_goto_tb(s, pc, npc)) { 369fcf5ef2aSThomas Huth /* jump to same page: we can use a direct jump */ 370fcf5ef2aSThomas Huth tcg_gen_goto_tb(tb_num); 371fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_pc, pc); 372fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_npc, npc); 37307ea28b4SRichard Henderson tcg_gen_exit_tb(s->base.tb, tb_num); 374fcf5ef2aSThomas Huth } else { 375f67ccb2fSRichard Henderson /* jump to another page: we can use an indirect jump */ 376fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_pc, pc); 377fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_npc, npc); 378f67ccb2fSRichard Henderson tcg_gen_lookup_and_goto_ptr(); 379fcf5ef2aSThomas Huth } 380fcf5ef2aSThomas Huth } 381fcf5ef2aSThomas Huth 382b989ce73SRichard Henderson static TCGv gen_carry32(void) 383fcf5ef2aSThomas Huth { 384b989ce73SRichard Henderson if (TARGET_LONG_BITS == 64) { 385b989ce73SRichard Henderson TCGv t = tcg_temp_new(); 386b989ce73SRichard Henderson tcg_gen_extract_tl(t, cpu_icc_C, 32, 1); 387b989ce73SRichard Henderson return t; 388b989ce73SRichard Henderson } 389b989ce73SRichard Henderson return cpu_icc_C; 390fcf5ef2aSThomas Huth } 391fcf5ef2aSThomas Huth 392b989ce73SRichard Henderson static void gen_op_addcc_int(TCGv dst, TCGv src1, TCGv src2, TCGv cin) 393fcf5ef2aSThomas Huth { 394b989ce73SRichard Henderson TCGv z = tcg_constant_tl(0); 395fcf5ef2aSThomas Huth 396b989ce73SRichard Henderson if (cin) { 397b989ce73SRichard Henderson tcg_gen_add2_tl(cpu_cc_N, cpu_cc_C, src1, z, cin, z); 398b989ce73SRichard Henderson tcg_gen_add2_tl(cpu_cc_N, cpu_cc_C, cpu_cc_N, cpu_cc_C, src2, z); 399b989ce73SRichard Henderson } else { 400b989ce73SRichard Henderson tcg_gen_add2_tl(cpu_cc_N, cpu_cc_C, src1, z, src2, z); 401b989ce73SRichard Henderson } 402b989ce73SRichard Henderson tcg_gen_xor_tl(cpu_cc_Z, src1, src2); 403b989ce73SRichard Henderson tcg_gen_xor_tl(cpu_cc_V, cpu_cc_N, src2); 404b989ce73SRichard Henderson tcg_gen_andc_tl(cpu_cc_V, cpu_cc_V, cpu_cc_Z); 405b989ce73SRichard Henderson if (TARGET_LONG_BITS == 64) { 406b989ce73SRichard Henderson /* 407b989ce73SRichard Henderson * Carry-in to bit 32 is result ^ src1 ^ src2. 408b989ce73SRichard Henderson * We already have the src xor term in Z, from computation of V. 409b989ce73SRichard Henderson */ 410b989ce73SRichard Henderson tcg_gen_xor_tl(cpu_icc_C, cpu_cc_Z, cpu_cc_N); 411b989ce73SRichard Henderson tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N); 412b989ce73SRichard Henderson } 413b989ce73SRichard Henderson tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N); 414b989ce73SRichard Henderson tcg_gen_mov_tl(dst, cpu_cc_N); 415b989ce73SRichard Henderson } 416fcf5ef2aSThomas Huth 417b989ce73SRichard Henderson static void gen_op_addcc(TCGv dst, TCGv src1, TCGv src2) 418b989ce73SRichard Henderson { 419b989ce73SRichard Henderson gen_op_addcc_int(dst, src1, src2, NULL); 420b989ce73SRichard Henderson } 421fcf5ef2aSThomas Huth 422b989ce73SRichard Henderson static void gen_op_taddcc(TCGv dst, TCGv src1, TCGv src2) 423b989ce73SRichard Henderson { 424b989ce73SRichard Henderson TCGv t = tcg_temp_new(); 425b989ce73SRichard Henderson 426b989ce73SRichard Henderson /* Save the tag bits around modification of dst. */ 427b989ce73SRichard Henderson tcg_gen_or_tl(t, src1, src2); 428b989ce73SRichard Henderson 429b989ce73SRichard Henderson gen_op_addcc(dst, src1, src2); 430b989ce73SRichard Henderson 431b989ce73SRichard Henderson /* Incorprate tag bits into icc.V */ 432b989ce73SRichard Henderson tcg_gen_andi_tl(t, t, 3); 433b989ce73SRichard Henderson tcg_gen_neg_tl(t, t); 434b989ce73SRichard Henderson tcg_gen_ext32u_tl(t, t); 435b989ce73SRichard Henderson tcg_gen_or_tl(cpu_cc_V, cpu_cc_V, t); 436b989ce73SRichard Henderson } 437b989ce73SRichard Henderson 438b989ce73SRichard Henderson static void gen_op_addc(TCGv dst, TCGv src1, TCGv src2) 439b989ce73SRichard Henderson { 440b989ce73SRichard Henderson tcg_gen_add_tl(dst, src1, src2); 441b989ce73SRichard Henderson tcg_gen_add_tl(dst, dst, gen_carry32()); 442b989ce73SRichard Henderson } 443b989ce73SRichard Henderson 444b989ce73SRichard Henderson static void gen_op_addccc(TCGv dst, TCGv src1, TCGv src2) 445b989ce73SRichard Henderson { 446b989ce73SRichard Henderson gen_op_addcc_int(dst, src1, src2, gen_carry32()); 447fcf5ef2aSThomas Huth } 448fcf5ef2aSThomas Huth 449f828df74SRichard Henderson static void gen_op_subcc_int(TCGv dst, TCGv src1, TCGv src2, TCGv cin) 450fcf5ef2aSThomas Huth { 451f828df74SRichard Henderson TCGv z = tcg_constant_tl(0); 452fcf5ef2aSThomas Huth 453f828df74SRichard Henderson if (cin) { 454f828df74SRichard Henderson tcg_gen_sub2_tl(cpu_cc_N, cpu_cc_C, src1, z, cin, z); 455f828df74SRichard Henderson tcg_gen_sub2_tl(cpu_cc_N, cpu_cc_C, cpu_cc_N, cpu_cc_C, src2, z); 456f828df74SRichard Henderson } else { 457f828df74SRichard Henderson tcg_gen_sub2_tl(cpu_cc_N, cpu_cc_C, src1, z, src2, z); 458f828df74SRichard Henderson } 459f828df74SRichard Henderson tcg_gen_neg_tl(cpu_cc_C, cpu_cc_C); 460f828df74SRichard Henderson tcg_gen_xor_tl(cpu_cc_Z, src1, src2); 461f828df74SRichard Henderson tcg_gen_xor_tl(cpu_cc_V, cpu_cc_N, src1); 462f828df74SRichard Henderson tcg_gen_and_tl(cpu_cc_V, cpu_cc_V, cpu_cc_Z); 463f828df74SRichard Henderson #ifdef TARGET_SPARC64 464f828df74SRichard Henderson tcg_gen_xor_tl(cpu_icc_C, cpu_cc_Z, cpu_cc_N); 465f828df74SRichard Henderson tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N); 466fcf5ef2aSThomas Huth #endif 467f828df74SRichard Henderson tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N); 468f828df74SRichard Henderson tcg_gen_mov_tl(dst, cpu_cc_N); 469fcf5ef2aSThomas Huth } 470fcf5ef2aSThomas Huth 471f828df74SRichard Henderson static void gen_op_subcc(TCGv dst, TCGv src1, TCGv src2) 472fcf5ef2aSThomas Huth { 473f828df74SRichard Henderson gen_op_subcc_int(dst, src1, src2, NULL); 474fcf5ef2aSThomas Huth } 475fcf5ef2aSThomas Huth 476f828df74SRichard Henderson static void gen_op_tsubcc(TCGv dst, TCGv src1, TCGv src2) 477fcf5ef2aSThomas Huth { 478f828df74SRichard Henderson TCGv t = tcg_temp_new(); 479fcf5ef2aSThomas Huth 480f828df74SRichard Henderson /* Save the tag bits around modification of dst. */ 481f828df74SRichard Henderson tcg_gen_or_tl(t, src1, src2); 482fcf5ef2aSThomas Huth 483f828df74SRichard Henderson gen_op_subcc(dst, src1, src2); 484f828df74SRichard Henderson 485f828df74SRichard Henderson /* Incorprate tag bits into icc.V */ 486f828df74SRichard Henderson tcg_gen_andi_tl(t, t, 3); 487f828df74SRichard Henderson tcg_gen_neg_tl(t, t); 488f828df74SRichard Henderson tcg_gen_ext32u_tl(t, t); 489f828df74SRichard Henderson tcg_gen_or_tl(cpu_cc_V, cpu_cc_V, t); 490f828df74SRichard Henderson } 491f828df74SRichard Henderson 492f828df74SRichard Henderson static void gen_op_subc(TCGv dst, TCGv src1, TCGv src2) 493f828df74SRichard Henderson { 494fcf5ef2aSThomas Huth tcg_gen_sub_tl(dst, src1, src2); 495f828df74SRichard Henderson tcg_gen_sub_tl(dst, dst, gen_carry32()); 496fcf5ef2aSThomas Huth } 497fcf5ef2aSThomas Huth 498f828df74SRichard Henderson static void gen_op_subccc(TCGv dst, TCGv src1, TCGv src2) 499dfebb950SRichard Henderson { 500f828df74SRichard Henderson gen_op_subcc_int(dst, src1, src2, gen_carry32()); 501dfebb950SRichard Henderson } 502dfebb950SRichard Henderson 5030c2e96c1SRichard Henderson static void gen_op_mulscc(TCGv dst, TCGv src1, TCGv src2) 504fcf5ef2aSThomas Huth { 505b989ce73SRichard Henderson TCGv zero = tcg_constant_tl(0); 506b989ce73SRichard Henderson TCGv t_src1 = tcg_temp_new(); 507b989ce73SRichard Henderson TCGv t_src2 = tcg_temp_new(); 508b989ce73SRichard Henderson TCGv t0 = tcg_temp_new(); 509fcf5ef2aSThomas Huth 510b989ce73SRichard Henderson tcg_gen_ext32u_tl(t_src1, src1); 511b989ce73SRichard Henderson tcg_gen_ext32u_tl(t_src2, src2); 512fcf5ef2aSThomas Huth 513b989ce73SRichard Henderson /* 514b989ce73SRichard Henderson * if (!(env->y & 1)) 515b989ce73SRichard Henderson * src2 = 0; 516fcf5ef2aSThomas Huth */ 517b989ce73SRichard Henderson tcg_gen_andi_tl(t0, cpu_y, 0x1); 518b989ce73SRichard Henderson tcg_gen_movcond_tl(TCG_COND_EQ, t_src2, t0, zero, zero, t_src2); 519fcf5ef2aSThomas Huth 520b989ce73SRichard Henderson /* 521b989ce73SRichard Henderson * b2 = src1 & 1; 522b989ce73SRichard Henderson * y = (b2 << 31) | (y >> 1); 523b989ce73SRichard Henderson */ 5240b1183e3SPhilippe Mathieu-Daudé tcg_gen_extract_tl(t0, cpu_y, 1, 31); 525b989ce73SRichard Henderson tcg_gen_deposit_tl(cpu_y, t0, src1, 31, 1); 526fcf5ef2aSThomas Huth 527fcf5ef2aSThomas Huth // b1 = N ^ V; 5282a1905c7SRichard Henderson tcg_gen_xor_tl(t0, cpu_cc_N, cpu_cc_V); 529fcf5ef2aSThomas Huth 530b989ce73SRichard Henderson /* 531b989ce73SRichard Henderson * src1 = (b1 << 31) | (src1 >> 1) 532b989ce73SRichard Henderson */ 5332a1905c7SRichard Henderson tcg_gen_andi_tl(t0, t0, 1u << 31); 534b989ce73SRichard Henderson tcg_gen_shri_tl(t_src1, t_src1, 1); 535b989ce73SRichard Henderson tcg_gen_or_tl(t_src1, t_src1, t0); 536fcf5ef2aSThomas Huth 537b989ce73SRichard Henderson gen_op_addcc(dst, t_src1, t_src2); 538fcf5ef2aSThomas Huth } 539fcf5ef2aSThomas Huth 5400c2e96c1SRichard Henderson static void gen_op_multiply(TCGv dst, TCGv src1, TCGv src2, int sign_ext) 541fcf5ef2aSThomas Huth { 542fcf5ef2aSThomas Huth #if TARGET_LONG_BITS == 32 543fcf5ef2aSThomas Huth if (sign_ext) { 544fcf5ef2aSThomas Huth tcg_gen_muls2_tl(dst, cpu_y, src1, src2); 545fcf5ef2aSThomas Huth } else { 546fcf5ef2aSThomas Huth tcg_gen_mulu2_tl(dst, cpu_y, src1, src2); 547fcf5ef2aSThomas Huth } 548fcf5ef2aSThomas Huth #else 549fcf5ef2aSThomas Huth TCGv t0 = tcg_temp_new_i64(); 550fcf5ef2aSThomas Huth TCGv t1 = tcg_temp_new_i64(); 551fcf5ef2aSThomas Huth 552fcf5ef2aSThomas Huth if (sign_ext) { 553fcf5ef2aSThomas Huth tcg_gen_ext32s_i64(t0, src1); 554fcf5ef2aSThomas Huth tcg_gen_ext32s_i64(t1, src2); 555fcf5ef2aSThomas Huth } else { 556fcf5ef2aSThomas Huth tcg_gen_ext32u_i64(t0, src1); 557fcf5ef2aSThomas Huth tcg_gen_ext32u_i64(t1, src2); 558fcf5ef2aSThomas Huth } 559fcf5ef2aSThomas Huth 560fcf5ef2aSThomas Huth tcg_gen_mul_i64(dst, t0, t1); 561fcf5ef2aSThomas Huth tcg_gen_shri_i64(cpu_y, dst, 32); 562fcf5ef2aSThomas Huth #endif 563fcf5ef2aSThomas Huth } 564fcf5ef2aSThomas Huth 5650c2e96c1SRichard Henderson static void gen_op_umul(TCGv dst, TCGv src1, TCGv src2) 566fcf5ef2aSThomas Huth { 567fcf5ef2aSThomas Huth /* zero-extend truncated operands before multiplication */ 568fcf5ef2aSThomas Huth gen_op_multiply(dst, src1, src2, 0); 569fcf5ef2aSThomas Huth } 570fcf5ef2aSThomas Huth 5710c2e96c1SRichard Henderson static void gen_op_smul(TCGv dst, TCGv src1, TCGv src2) 572fcf5ef2aSThomas Huth { 573fcf5ef2aSThomas Huth /* sign-extend truncated operands before multiplication */ 574fcf5ef2aSThomas Huth gen_op_multiply(dst, src1, src2, 1); 575fcf5ef2aSThomas Huth } 576fcf5ef2aSThomas Huth 5774ee85ea9SRichard Henderson static void gen_op_udivx(TCGv dst, TCGv src1, TCGv src2) 5784ee85ea9SRichard Henderson { 5794ee85ea9SRichard Henderson gen_helper_udivx(dst, tcg_env, src1, src2); 5804ee85ea9SRichard Henderson } 5814ee85ea9SRichard Henderson 5824ee85ea9SRichard Henderson static void gen_op_sdivx(TCGv dst, TCGv src1, TCGv src2) 5834ee85ea9SRichard Henderson { 5844ee85ea9SRichard Henderson gen_helper_sdivx(dst, tcg_env, src1, src2); 5854ee85ea9SRichard Henderson } 5864ee85ea9SRichard Henderson 587c2636853SRichard Henderson static void gen_op_udiv(TCGv dst, TCGv src1, TCGv src2) 588c2636853SRichard Henderson { 58913260103SRichard Henderson #ifdef TARGET_SPARC64 590c2636853SRichard Henderson gen_helper_udiv(dst, tcg_env, src1, src2); 59113260103SRichard Henderson tcg_gen_ext32u_tl(dst, dst); 59213260103SRichard Henderson #else 59313260103SRichard Henderson TCGv_i64 t64 = tcg_temp_new_i64(); 59413260103SRichard Henderson gen_helper_udiv(t64, tcg_env, src1, src2); 59513260103SRichard Henderson tcg_gen_trunc_i64_tl(dst, t64); 59613260103SRichard Henderson #endif 597c2636853SRichard Henderson } 598c2636853SRichard Henderson 599c2636853SRichard Henderson static void gen_op_sdiv(TCGv dst, TCGv src1, TCGv src2) 600c2636853SRichard Henderson { 60113260103SRichard Henderson #ifdef TARGET_SPARC64 602c2636853SRichard Henderson gen_helper_sdiv(dst, tcg_env, src1, src2); 60313260103SRichard Henderson tcg_gen_ext32s_tl(dst, dst); 60413260103SRichard Henderson #else 60513260103SRichard Henderson TCGv_i64 t64 = tcg_temp_new_i64(); 60613260103SRichard Henderson gen_helper_sdiv(t64, tcg_env, src1, src2); 60713260103SRichard Henderson tcg_gen_trunc_i64_tl(dst, t64); 60813260103SRichard Henderson #endif 609c2636853SRichard Henderson } 610c2636853SRichard Henderson 611c2636853SRichard Henderson static void gen_op_udivcc(TCGv dst, TCGv src1, TCGv src2) 612c2636853SRichard Henderson { 61313260103SRichard Henderson TCGv_i64 t64; 61413260103SRichard Henderson 61513260103SRichard Henderson #ifdef TARGET_SPARC64 61613260103SRichard Henderson t64 = cpu_cc_V; 61713260103SRichard Henderson #else 61813260103SRichard Henderson t64 = tcg_temp_new_i64(); 61913260103SRichard Henderson #endif 62013260103SRichard Henderson 62113260103SRichard Henderson gen_helper_udiv(t64, tcg_env, src1, src2); 62213260103SRichard Henderson 62313260103SRichard Henderson #ifdef TARGET_SPARC64 62413260103SRichard Henderson tcg_gen_ext32u_tl(cpu_cc_N, t64); 62513260103SRichard Henderson tcg_gen_shri_tl(cpu_cc_V, t64, 32); 62613260103SRichard Henderson tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N); 62713260103SRichard Henderson tcg_gen_movi_tl(cpu_icc_C, 0); 62813260103SRichard Henderson #else 62913260103SRichard Henderson tcg_gen_extr_i64_tl(cpu_cc_N, cpu_cc_V, t64); 63013260103SRichard Henderson #endif 63113260103SRichard Henderson tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N); 63213260103SRichard Henderson tcg_gen_movi_tl(cpu_cc_C, 0); 63313260103SRichard Henderson tcg_gen_mov_tl(dst, cpu_cc_N); 634c2636853SRichard Henderson } 635c2636853SRichard Henderson 636c2636853SRichard Henderson static void gen_op_sdivcc(TCGv dst, TCGv src1, TCGv src2) 637c2636853SRichard Henderson { 63813260103SRichard Henderson TCGv_i64 t64; 63913260103SRichard Henderson 64013260103SRichard Henderson #ifdef TARGET_SPARC64 64113260103SRichard Henderson t64 = cpu_cc_V; 64213260103SRichard Henderson #else 64313260103SRichard Henderson t64 = tcg_temp_new_i64(); 64413260103SRichard Henderson #endif 64513260103SRichard Henderson 64613260103SRichard Henderson gen_helper_sdiv(t64, tcg_env, src1, src2); 64713260103SRichard Henderson 64813260103SRichard Henderson #ifdef TARGET_SPARC64 64913260103SRichard Henderson tcg_gen_ext32s_tl(cpu_cc_N, t64); 65013260103SRichard Henderson tcg_gen_shri_tl(cpu_cc_V, t64, 32); 65113260103SRichard Henderson tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N); 65213260103SRichard Henderson tcg_gen_movi_tl(cpu_icc_C, 0); 65313260103SRichard Henderson #else 65413260103SRichard Henderson tcg_gen_extr_i64_tl(cpu_cc_N, cpu_cc_V, t64); 65513260103SRichard Henderson #endif 65613260103SRichard Henderson tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N); 65713260103SRichard Henderson tcg_gen_movi_tl(cpu_cc_C, 0); 65813260103SRichard Henderson tcg_gen_mov_tl(dst, cpu_cc_N); 659c2636853SRichard Henderson } 660c2636853SRichard Henderson 661a9aba13dSRichard Henderson static void gen_op_taddcctv(TCGv dst, TCGv src1, TCGv src2) 662a9aba13dSRichard Henderson { 663a9aba13dSRichard Henderson gen_helper_taddcctv(dst, tcg_env, src1, src2); 664a9aba13dSRichard Henderson } 665a9aba13dSRichard Henderson 666a9aba13dSRichard Henderson static void gen_op_tsubcctv(TCGv dst, TCGv src1, TCGv src2) 667a9aba13dSRichard Henderson { 668a9aba13dSRichard Henderson gen_helper_tsubcctv(dst, tcg_env, src1, src2); 669a9aba13dSRichard Henderson } 670a9aba13dSRichard Henderson 6719c6ec5bcSRichard Henderson static void gen_op_popc(TCGv dst, TCGv src1, TCGv src2) 6729c6ec5bcSRichard Henderson { 6739c6ec5bcSRichard Henderson tcg_gen_ctpop_tl(dst, src2); 6749c6ec5bcSRichard Henderson } 6759c6ec5bcSRichard Henderson 67645bfed3bSRichard Henderson #ifndef TARGET_SPARC64 67745bfed3bSRichard Henderson static void gen_helper_array8(TCGv dst, TCGv src1, TCGv src2) 67845bfed3bSRichard Henderson { 67945bfed3bSRichard Henderson g_assert_not_reached(); 68045bfed3bSRichard Henderson } 68145bfed3bSRichard Henderson #endif 68245bfed3bSRichard Henderson 68345bfed3bSRichard Henderson static void gen_op_array16(TCGv dst, TCGv src1, TCGv src2) 68445bfed3bSRichard Henderson { 68545bfed3bSRichard Henderson gen_helper_array8(dst, src1, src2); 68645bfed3bSRichard Henderson tcg_gen_shli_tl(dst, dst, 1); 68745bfed3bSRichard Henderson } 68845bfed3bSRichard Henderson 68945bfed3bSRichard Henderson static void gen_op_array32(TCGv dst, TCGv src1, TCGv src2) 69045bfed3bSRichard Henderson { 69145bfed3bSRichard Henderson gen_helper_array8(dst, src1, src2); 69245bfed3bSRichard Henderson tcg_gen_shli_tl(dst, dst, 2); 69345bfed3bSRichard Henderson } 69445bfed3bSRichard Henderson 6952f722641SRichard Henderson static void gen_op_fpack16(TCGv_i32 dst, TCGv_i64 src) 6962f722641SRichard Henderson { 6972f722641SRichard Henderson #ifdef TARGET_SPARC64 6982f722641SRichard Henderson gen_helper_fpack16(dst, cpu_gsr, src); 6992f722641SRichard Henderson #else 7002f722641SRichard Henderson g_assert_not_reached(); 7012f722641SRichard Henderson #endif 7022f722641SRichard Henderson } 7032f722641SRichard Henderson 7042f722641SRichard Henderson static void gen_op_fpackfix(TCGv_i32 dst, TCGv_i64 src) 7052f722641SRichard Henderson { 7062f722641SRichard Henderson #ifdef TARGET_SPARC64 7072f722641SRichard Henderson gen_helper_fpackfix(dst, cpu_gsr, src); 7082f722641SRichard Henderson #else 7092f722641SRichard Henderson g_assert_not_reached(); 7102f722641SRichard Henderson #endif 7112f722641SRichard Henderson } 7122f722641SRichard Henderson 7134b6edc0aSRichard Henderson static void gen_op_fpack32(TCGv_i64 dst, TCGv_i64 src1, TCGv_i64 src2) 7144b6edc0aSRichard Henderson { 7154b6edc0aSRichard Henderson #ifdef TARGET_SPARC64 7164b6edc0aSRichard Henderson gen_helper_fpack32(dst, cpu_gsr, src1, src2); 7174b6edc0aSRichard Henderson #else 7184b6edc0aSRichard Henderson g_assert_not_reached(); 7194b6edc0aSRichard Henderson #endif 7204b6edc0aSRichard Henderson } 7214b6edc0aSRichard Henderson 7224b6edc0aSRichard Henderson static void gen_op_faligndata(TCGv_i64 dst, TCGv_i64 s1, TCGv_i64 s2) 7234b6edc0aSRichard Henderson { 7244b6edc0aSRichard Henderson #ifdef TARGET_SPARC64 7254b6edc0aSRichard Henderson TCGv t1, t2, shift; 7264b6edc0aSRichard Henderson 7274b6edc0aSRichard Henderson t1 = tcg_temp_new(); 7284b6edc0aSRichard Henderson t2 = tcg_temp_new(); 7294b6edc0aSRichard Henderson shift = tcg_temp_new(); 7304b6edc0aSRichard Henderson 7314b6edc0aSRichard Henderson tcg_gen_andi_tl(shift, cpu_gsr, 7); 7324b6edc0aSRichard Henderson tcg_gen_shli_tl(shift, shift, 3); 7334b6edc0aSRichard Henderson tcg_gen_shl_tl(t1, s1, shift); 7344b6edc0aSRichard Henderson 7354b6edc0aSRichard Henderson /* 7364b6edc0aSRichard Henderson * A shift of 64 does not produce 0 in TCG. Divide this into a 7374b6edc0aSRichard Henderson * shift of (up to 63) followed by a constant shift of 1. 7384b6edc0aSRichard Henderson */ 7394b6edc0aSRichard Henderson tcg_gen_xori_tl(shift, shift, 63); 7404b6edc0aSRichard Henderson tcg_gen_shr_tl(t2, s2, shift); 7414b6edc0aSRichard Henderson tcg_gen_shri_tl(t2, t2, 1); 7424b6edc0aSRichard Henderson 7434b6edc0aSRichard Henderson tcg_gen_or_tl(dst, t1, t2); 7444b6edc0aSRichard Henderson #else 7454b6edc0aSRichard Henderson g_assert_not_reached(); 7464b6edc0aSRichard Henderson #endif 7474b6edc0aSRichard Henderson } 7484b6edc0aSRichard Henderson 7494b6edc0aSRichard Henderson static void gen_op_bshuffle(TCGv_i64 dst, TCGv_i64 src1, TCGv_i64 src2) 7504b6edc0aSRichard Henderson { 7514b6edc0aSRichard Henderson #ifdef TARGET_SPARC64 7524b6edc0aSRichard Henderson gen_helper_bshuffle(dst, cpu_gsr, src1, src2); 7534b6edc0aSRichard Henderson #else 7544b6edc0aSRichard Henderson g_assert_not_reached(); 7554b6edc0aSRichard Henderson #endif 7564b6edc0aSRichard Henderson } 7574b6edc0aSRichard Henderson 758fcf5ef2aSThomas Huth // 1 7590c2e96c1SRichard Henderson static void gen_op_eval_ba(TCGv dst) 760fcf5ef2aSThomas Huth { 761fcf5ef2aSThomas Huth tcg_gen_movi_tl(dst, 1); 762fcf5ef2aSThomas Huth } 763fcf5ef2aSThomas Huth 764fcf5ef2aSThomas Huth // 0 7650c2e96c1SRichard Henderson static void gen_op_eval_bn(TCGv dst) 766fcf5ef2aSThomas Huth { 767fcf5ef2aSThomas Huth tcg_gen_movi_tl(dst, 0); 768fcf5ef2aSThomas Huth } 769fcf5ef2aSThomas Huth 770fcf5ef2aSThomas Huth /* 771fcf5ef2aSThomas Huth FPSR bit field FCC1 | FCC0: 772fcf5ef2aSThomas Huth 0 = 773fcf5ef2aSThomas Huth 1 < 774fcf5ef2aSThomas Huth 2 > 775fcf5ef2aSThomas Huth 3 unordered 776fcf5ef2aSThomas Huth */ 7770c2e96c1SRichard Henderson static void gen_mov_reg_FCC0(TCGv reg, TCGv src, 778fcf5ef2aSThomas Huth unsigned int fcc_offset) 779fcf5ef2aSThomas Huth { 780fcf5ef2aSThomas Huth tcg_gen_shri_tl(reg, src, FSR_FCC0_SHIFT + fcc_offset); 781fcf5ef2aSThomas Huth tcg_gen_andi_tl(reg, reg, 0x1); 782fcf5ef2aSThomas Huth } 783fcf5ef2aSThomas Huth 7840c2e96c1SRichard Henderson static void gen_mov_reg_FCC1(TCGv reg, TCGv src, unsigned int fcc_offset) 785fcf5ef2aSThomas Huth { 786fcf5ef2aSThomas Huth tcg_gen_shri_tl(reg, src, FSR_FCC1_SHIFT + fcc_offset); 787fcf5ef2aSThomas Huth tcg_gen_andi_tl(reg, reg, 0x1); 788fcf5ef2aSThomas Huth } 789fcf5ef2aSThomas Huth 790fcf5ef2aSThomas Huth // !0: FCC0 | FCC1 7910c2e96c1SRichard Henderson static void gen_op_eval_fbne(TCGv dst, TCGv src, unsigned int fcc_offset) 792fcf5ef2aSThomas Huth { 793fcf5ef2aSThomas Huth TCGv t0 = tcg_temp_new(); 794fcf5ef2aSThomas Huth gen_mov_reg_FCC0(dst, src, fcc_offset); 795fcf5ef2aSThomas Huth gen_mov_reg_FCC1(t0, src, fcc_offset); 796fcf5ef2aSThomas Huth tcg_gen_or_tl(dst, dst, t0); 797fcf5ef2aSThomas Huth } 798fcf5ef2aSThomas Huth 799fcf5ef2aSThomas Huth // 1 or 2: FCC0 ^ FCC1 8000c2e96c1SRichard Henderson static void gen_op_eval_fblg(TCGv dst, TCGv src, unsigned int fcc_offset) 801fcf5ef2aSThomas Huth { 802fcf5ef2aSThomas Huth TCGv t0 = tcg_temp_new(); 803fcf5ef2aSThomas Huth gen_mov_reg_FCC0(dst, src, fcc_offset); 804fcf5ef2aSThomas Huth gen_mov_reg_FCC1(t0, src, fcc_offset); 805fcf5ef2aSThomas Huth tcg_gen_xor_tl(dst, dst, t0); 806fcf5ef2aSThomas Huth } 807fcf5ef2aSThomas Huth 808fcf5ef2aSThomas Huth // 1 or 3: FCC0 8090c2e96c1SRichard Henderson static void gen_op_eval_fbul(TCGv dst, TCGv src, unsigned int fcc_offset) 810fcf5ef2aSThomas Huth { 811fcf5ef2aSThomas Huth gen_mov_reg_FCC0(dst, src, fcc_offset); 812fcf5ef2aSThomas Huth } 813fcf5ef2aSThomas Huth 814fcf5ef2aSThomas Huth // 1: FCC0 & !FCC1 8150c2e96c1SRichard Henderson static void gen_op_eval_fbl(TCGv dst, TCGv src, unsigned int fcc_offset) 816fcf5ef2aSThomas Huth { 817fcf5ef2aSThomas Huth TCGv t0 = tcg_temp_new(); 818fcf5ef2aSThomas Huth gen_mov_reg_FCC0(dst, src, fcc_offset); 819fcf5ef2aSThomas Huth gen_mov_reg_FCC1(t0, src, fcc_offset); 820fcf5ef2aSThomas Huth tcg_gen_andc_tl(dst, dst, t0); 821fcf5ef2aSThomas Huth } 822fcf5ef2aSThomas Huth 823fcf5ef2aSThomas Huth // 2 or 3: FCC1 8240c2e96c1SRichard Henderson static void gen_op_eval_fbug(TCGv dst, TCGv src, unsigned int fcc_offset) 825fcf5ef2aSThomas Huth { 826fcf5ef2aSThomas Huth gen_mov_reg_FCC1(dst, src, fcc_offset); 827fcf5ef2aSThomas Huth } 828fcf5ef2aSThomas Huth 829fcf5ef2aSThomas Huth // 2: !FCC0 & FCC1 8300c2e96c1SRichard Henderson static void gen_op_eval_fbg(TCGv dst, TCGv src, unsigned int fcc_offset) 831fcf5ef2aSThomas Huth { 832fcf5ef2aSThomas Huth TCGv t0 = tcg_temp_new(); 833fcf5ef2aSThomas Huth gen_mov_reg_FCC0(dst, src, fcc_offset); 834fcf5ef2aSThomas Huth gen_mov_reg_FCC1(t0, src, fcc_offset); 835fcf5ef2aSThomas Huth tcg_gen_andc_tl(dst, t0, dst); 836fcf5ef2aSThomas Huth } 837fcf5ef2aSThomas Huth 838fcf5ef2aSThomas Huth // 3: FCC0 & FCC1 8390c2e96c1SRichard Henderson static void gen_op_eval_fbu(TCGv dst, TCGv src, unsigned int fcc_offset) 840fcf5ef2aSThomas Huth { 841fcf5ef2aSThomas Huth TCGv t0 = tcg_temp_new(); 842fcf5ef2aSThomas Huth gen_mov_reg_FCC0(dst, src, fcc_offset); 843fcf5ef2aSThomas Huth gen_mov_reg_FCC1(t0, src, fcc_offset); 844fcf5ef2aSThomas Huth tcg_gen_and_tl(dst, dst, t0); 845fcf5ef2aSThomas Huth } 846fcf5ef2aSThomas Huth 847fcf5ef2aSThomas Huth // 0: !(FCC0 | FCC1) 8480c2e96c1SRichard Henderson static void gen_op_eval_fbe(TCGv dst, TCGv src, unsigned int fcc_offset) 849fcf5ef2aSThomas Huth { 850fcf5ef2aSThomas Huth TCGv t0 = tcg_temp_new(); 851fcf5ef2aSThomas Huth gen_mov_reg_FCC0(dst, src, fcc_offset); 852fcf5ef2aSThomas Huth gen_mov_reg_FCC1(t0, src, fcc_offset); 853fcf5ef2aSThomas Huth tcg_gen_or_tl(dst, dst, t0); 854fcf5ef2aSThomas Huth tcg_gen_xori_tl(dst, dst, 0x1); 855fcf5ef2aSThomas Huth } 856fcf5ef2aSThomas Huth 857fcf5ef2aSThomas Huth // 0 or 3: !(FCC0 ^ FCC1) 8580c2e96c1SRichard Henderson static void gen_op_eval_fbue(TCGv dst, TCGv src, unsigned int fcc_offset) 859fcf5ef2aSThomas Huth { 860fcf5ef2aSThomas Huth TCGv t0 = tcg_temp_new(); 861fcf5ef2aSThomas Huth gen_mov_reg_FCC0(dst, src, fcc_offset); 862fcf5ef2aSThomas Huth gen_mov_reg_FCC1(t0, src, fcc_offset); 863fcf5ef2aSThomas Huth tcg_gen_xor_tl(dst, dst, t0); 864fcf5ef2aSThomas Huth tcg_gen_xori_tl(dst, dst, 0x1); 865fcf5ef2aSThomas Huth } 866fcf5ef2aSThomas Huth 867fcf5ef2aSThomas Huth // 0 or 2: !FCC0 8680c2e96c1SRichard Henderson static void gen_op_eval_fbge(TCGv dst, TCGv src, unsigned int fcc_offset) 869fcf5ef2aSThomas Huth { 870fcf5ef2aSThomas Huth gen_mov_reg_FCC0(dst, src, fcc_offset); 871fcf5ef2aSThomas Huth tcg_gen_xori_tl(dst, dst, 0x1); 872fcf5ef2aSThomas Huth } 873fcf5ef2aSThomas Huth 874fcf5ef2aSThomas Huth // !1: !(FCC0 & !FCC1) 8750c2e96c1SRichard Henderson static void gen_op_eval_fbuge(TCGv dst, TCGv src, unsigned int fcc_offset) 876fcf5ef2aSThomas Huth { 877fcf5ef2aSThomas Huth TCGv t0 = tcg_temp_new(); 878fcf5ef2aSThomas Huth gen_mov_reg_FCC0(dst, src, fcc_offset); 879fcf5ef2aSThomas Huth gen_mov_reg_FCC1(t0, src, fcc_offset); 880fcf5ef2aSThomas Huth tcg_gen_andc_tl(dst, dst, t0); 881fcf5ef2aSThomas Huth tcg_gen_xori_tl(dst, dst, 0x1); 882fcf5ef2aSThomas Huth } 883fcf5ef2aSThomas Huth 884fcf5ef2aSThomas Huth // 0 or 1: !FCC1 8850c2e96c1SRichard Henderson static void gen_op_eval_fble(TCGv dst, TCGv src, unsigned int fcc_offset) 886fcf5ef2aSThomas Huth { 887fcf5ef2aSThomas Huth gen_mov_reg_FCC1(dst, src, fcc_offset); 888fcf5ef2aSThomas Huth tcg_gen_xori_tl(dst, dst, 0x1); 889fcf5ef2aSThomas Huth } 890fcf5ef2aSThomas Huth 891fcf5ef2aSThomas Huth // !2: !(!FCC0 & FCC1) 8920c2e96c1SRichard Henderson static void gen_op_eval_fbule(TCGv dst, TCGv src, unsigned int fcc_offset) 893fcf5ef2aSThomas Huth { 894fcf5ef2aSThomas Huth TCGv t0 = tcg_temp_new(); 895fcf5ef2aSThomas Huth gen_mov_reg_FCC0(dst, src, fcc_offset); 896fcf5ef2aSThomas Huth gen_mov_reg_FCC1(t0, src, fcc_offset); 897fcf5ef2aSThomas Huth tcg_gen_andc_tl(dst, t0, dst); 898fcf5ef2aSThomas Huth tcg_gen_xori_tl(dst, dst, 0x1); 899fcf5ef2aSThomas Huth } 900fcf5ef2aSThomas Huth 901fcf5ef2aSThomas Huth // !3: !(FCC0 & FCC1) 9020c2e96c1SRichard Henderson static void gen_op_eval_fbo(TCGv dst, TCGv src, unsigned int fcc_offset) 903fcf5ef2aSThomas Huth { 904fcf5ef2aSThomas Huth TCGv t0 = tcg_temp_new(); 905fcf5ef2aSThomas Huth gen_mov_reg_FCC0(dst, src, fcc_offset); 906fcf5ef2aSThomas Huth gen_mov_reg_FCC1(t0, src, fcc_offset); 907fcf5ef2aSThomas Huth tcg_gen_and_tl(dst, dst, t0); 908fcf5ef2aSThomas Huth tcg_gen_xori_tl(dst, dst, 0x1); 909fcf5ef2aSThomas Huth } 910fcf5ef2aSThomas Huth 9110c2e96c1SRichard Henderson static void gen_generic_branch(DisasContext *dc) 912fcf5ef2aSThomas Huth { 91300ab7e61SRichard Henderson TCGv npc0 = tcg_constant_tl(dc->jump_pc[0]); 91400ab7e61SRichard Henderson TCGv npc1 = tcg_constant_tl(dc->jump_pc[1]); 91500ab7e61SRichard Henderson TCGv zero = tcg_constant_tl(0); 916fcf5ef2aSThomas Huth 917fcf5ef2aSThomas Huth tcg_gen_movcond_tl(TCG_COND_NE, cpu_npc, cpu_cond, zero, npc0, npc1); 918fcf5ef2aSThomas Huth } 919fcf5ef2aSThomas Huth 920fcf5ef2aSThomas Huth /* call this function before using the condition register as it may 921fcf5ef2aSThomas Huth have been set for a jump */ 9220c2e96c1SRichard Henderson static void flush_cond(DisasContext *dc) 923fcf5ef2aSThomas Huth { 924fcf5ef2aSThomas Huth if (dc->npc == JUMP_PC) { 925fcf5ef2aSThomas Huth gen_generic_branch(dc); 92699c82c47SRichard Henderson dc->npc = DYNAMIC_PC_LOOKUP; 927fcf5ef2aSThomas Huth } 928fcf5ef2aSThomas Huth } 929fcf5ef2aSThomas Huth 9300c2e96c1SRichard Henderson static void save_npc(DisasContext *dc) 931fcf5ef2aSThomas Huth { 932633c4283SRichard Henderson if (dc->npc & 3) { 933633c4283SRichard Henderson switch (dc->npc) { 934633c4283SRichard Henderson case JUMP_PC: 935fcf5ef2aSThomas Huth gen_generic_branch(dc); 93699c82c47SRichard Henderson dc->npc = DYNAMIC_PC_LOOKUP; 937633c4283SRichard Henderson break; 938633c4283SRichard Henderson case DYNAMIC_PC: 939633c4283SRichard Henderson case DYNAMIC_PC_LOOKUP: 940633c4283SRichard Henderson break; 941633c4283SRichard Henderson default: 942633c4283SRichard Henderson g_assert_not_reached(); 943633c4283SRichard Henderson } 944633c4283SRichard Henderson } else { 945fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_npc, dc->npc); 946fcf5ef2aSThomas Huth } 947fcf5ef2aSThomas Huth } 948fcf5ef2aSThomas Huth 9490c2e96c1SRichard Henderson static void save_state(DisasContext *dc) 950fcf5ef2aSThomas Huth { 951fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_pc, dc->pc); 952fcf5ef2aSThomas Huth save_npc(dc); 953fcf5ef2aSThomas Huth } 954fcf5ef2aSThomas Huth 955fcf5ef2aSThomas Huth static void gen_exception(DisasContext *dc, int which) 956fcf5ef2aSThomas Huth { 957fcf5ef2aSThomas Huth save_state(dc); 958ad75a51eSRichard Henderson gen_helper_raise_exception(tcg_env, tcg_constant_i32(which)); 959af00be49SEmilio G. Cota dc->base.is_jmp = DISAS_NORETURN; 960fcf5ef2aSThomas Huth } 961fcf5ef2aSThomas Huth 962186e7890SRichard Henderson static TCGLabel *delay_exceptionv(DisasContext *dc, TCGv_i32 excp) 963fcf5ef2aSThomas Huth { 964186e7890SRichard Henderson DisasDelayException *e = g_new0(DisasDelayException, 1); 965186e7890SRichard Henderson 966186e7890SRichard Henderson e->next = dc->delay_excp_list; 967186e7890SRichard Henderson dc->delay_excp_list = e; 968186e7890SRichard Henderson 969186e7890SRichard Henderson e->lab = gen_new_label(); 970186e7890SRichard Henderson e->excp = excp; 971186e7890SRichard Henderson e->pc = dc->pc; 972186e7890SRichard Henderson /* Caller must have used flush_cond before branch. */ 973186e7890SRichard Henderson assert(e->npc != JUMP_PC); 974186e7890SRichard Henderson e->npc = dc->npc; 975186e7890SRichard Henderson 976186e7890SRichard Henderson return e->lab; 977186e7890SRichard Henderson } 978186e7890SRichard Henderson 979186e7890SRichard Henderson static TCGLabel *delay_exception(DisasContext *dc, int excp) 980186e7890SRichard Henderson { 981186e7890SRichard Henderson return delay_exceptionv(dc, tcg_constant_i32(excp)); 982186e7890SRichard Henderson } 983186e7890SRichard Henderson 984186e7890SRichard Henderson static void gen_check_align(DisasContext *dc, TCGv addr, int mask) 985186e7890SRichard Henderson { 986186e7890SRichard Henderson TCGv t = tcg_temp_new(); 987186e7890SRichard Henderson TCGLabel *lab; 988186e7890SRichard Henderson 989186e7890SRichard Henderson tcg_gen_andi_tl(t, addr, mask); 990186e7890SRichard Henderson 991186e7890SRichard Henderson flush_cond(dc); 992186e7890SRichard Henderson lab = delay_exception(dc, TT_UNALIGNED); 993186e7890SRichard Henderson tcg_gen_brcondi_tl(TCG_COND_NE, t, 0, lab); 994fcf5ef2aSThomas Huth } 995fcf5ef2aSThomas Huth 9960c2e96c1SRichard Henderson static void gen_mov_pc_npc(DisasContext *dc) 997fcf5ef2aSThomas Huth { 998633c4283SRichard Henderson if (dc->npc & 3) { 999633c4283SRichard Henderson switch (dc->npc) { 1000633c4283SRichard Henderson case JUMP_PC: 1001fcf5ef2aSThomas Huth gen_generic_branch(dc); 1002fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_pc, cpu_npc); 100399c82c47SRichard Henderson dc->pc = DYNAMIC_PC_LOOKUP; 1004633c4283SRichard Henderson break; 1005633c4283SRichard Henderson case DYNAMIC_PC: 1006633c4283SRichard Henderson case DYNAMIC_PC_LOOKUP: 1007fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_pc, cpu_npc); 1008633c4283SRichard Henderson dc->pc = dc->npc; 1009633c4283SRichard Henderson break; 1010633c4283SRichard Henderson default: 1011633c4283SRichard Henderson g_assert_not_reached(); 1012633c4283SRichard Henderson } 1013fcf5ef2aSThomas Huth } else { 1014fcf5ef2aSThomas Huth dc->pc = dc->npc; 1015fcf5ef2aSThomas Huth } 1016fcf5ef2aSThomas Huth } 1017fcf5ef2aSThomas Huth 10180c2e96c1SRichard Henderson static void gen_op_next_insn(void) 1019fcf5ef2aSThomas Huth { 1020fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_pc, cpu_npc); 1021fcf5ef2aSThomas Huth tcg_gen_addi_tl(cpu_npc, cpu_npc, 4); 1022fcf5ef2aSThomas Huth } 1023fcf5ef2aSThomas Huth 1024fcf5ef2aSThomas Huth static void gen_compare(DisasCompare *cmp, bool xcc, unsigned int cond, 1025fcf5ef2aSThomas Huth DisasContext *dc) 1026fcf5ef2aSThomas Huth { 1027b597eedcSRichard Henderson TCGv t1; 1028fcf5ef2aSThomas Huth 10292a1905c7SRichard Henderson cmp->c1 = t1 = tcg_temp_new(); 1030c8507ebfSRichard Henderson cmp->c2 = 0; 10312a1905c7SRichard Henderson 10322a1905c7SRichard Henderson switch (cond & 7) { 10332a1905c7SRichard Henderson case 0x0: /* never */ 10342a1905c7SRichard Henderson cmp->cond = TCG_COND_NEVER; 1035c8507ebfSRichard Henderson cmp->c1 = tcg_constant_tl(0); 1036fcf5ef2aSThomas Huth break; 10372a1905c7SRichard Henderson 10382a1905c7SRichard Henderson case 0x1: /* eq: Z */ 10392a1905c7SRichard Henderson cmp->cond = TCG_COND_EQ; 10402a1905c7SRichard Henderson if (TARGET_LONG_BITS == 32 || xcc) { 10412a1905c7SRichard Henderson tcg_gen_mov_tl(t1, cpu_cc_Z); 10422a1905c7SRichard Henderson } else { 10432a1905c7SRichard Henderson tcg_gen_ext32u_tl(t1, cpu_icc_Z); 10442a1905c7SRichard Henderson } 10452a1905c7SRichard Henderson break; 10462a1905c7SRichard Henderson 10472a1905c7SRichard Henderson case 0x2: /* le: Z | (N ^ V) */ 10482a1905c7SRichard Henderson /* 10492a1905c7SRichard Henderson * Simplify: 10502a1905c7SRichard Henderson * cc_Z || (N ^ V) < 0 NE 10512a1905c7SRichard Henderson * cc_Z && !((N ^ V) < 0) EQ 10522a1905c7SRichard Henderson * cc_Z & ~((N ^ V) >> TLB) EQ 10532a1905c7SRichard Henderson */ 10542a1905c7SRichard Henderson cmp->cond = TCG_COND_EQ; 10552a1905c7SRichard Henderson tcg_gen_xor_tl(t1, cpu_cc_N, cpu_cc_V); 10562a1905c7SRichard Henderson tcg_gen_sextract_tl(t1, t1, xcc ? 63 : 31, 1); 10572a1905c7SRichard Henderson tcg_gen_andc_tl(t1, xcc ? cpu_cc_Z : cpu_icc_Z, t1); 10582a1905c7SRichard Henderson if (TARGET_LONG_BITS == 64 && !xcc) { 10592a1905c7SRichard Henderson tcg_gen_ext32u_tl(t1, t1); 10602a1905c7SRichard Henderson } 10612a1905c7SRichard Henderson break; 10622a1905c7SRichard Henderson 10632a1905c7SRichard Henderson case 0x3: /* lt: N ^ V */ 10642a1905c7SRichard Henderson cmp->cond = TCG_COND_LT; 10652a1905c7SRichard Henderson tcg_gen_xor_tl(t1, cpu_cc_N, cpu_cc_V); 10662a1905c7SRichard Henderson if (TARGET_LONG_BITS == 64 && !xcc) { 10672a1905c7SRichard Henderson tcg_gen_ext32s_tl(t1, t1); 10682a1905c7SRichard Henderson } 10692a1905c7SRichard Henderson break; 10702a1905c7SRichard Henderson 10712a1905c7SRichard Henderson case 0x4: /* leu: Z | C */ 10722a1905c7SRichard Henderson /* 10732a1905c7SRichard Henderson * Simplify: 10742a1905c7SRichard Henderson * cc_Z == 0 || cc_C != 0 NE 10752a1905c7SRichard Henderson * cc_Z != 0 && cc_C == 0 EQ 10762a1905c7SRichard Henderson * cc_Z & (cc_C ? 0 : -1) EQ 10772a1905c7SRichard Henderson * cc_Z & (cc_C - 1) EQ 10782a1905c7SRichard Henderson */ 10792a1905c7SRichard Henderson cmp->cond = TCG_COND_EQ; 10802a1905c7SRichard Henderson if (TARGET_LONG_BITS == 32 || xcc) { 10812a1905c7SRichard Henderson tcg_gen_subi_tl(t1, cpu_cc_C, 1); 10822a1905c7SRichard Henderson tcg_gen_and_tl(t1, t1, cpu_cc_Z); 10832a1905c7SRichard Henderson } else { 10842a1905c7SRichard Henderson tcg_gen_extract_tl(t1, cpu_icc_C, 32, 1); 10852a1905c7SRichard Henderson tcg_gen_subi_tl(t1, t1, 1); 10862a1905c7SRichard Henderson tcg_gen_and_tl(t1, t1, cpu_icc_Z); 10872a1905c7SRichard Henderson tcg_gen_ext32u_tl(t1, t1); 10882a1905c7SRichard Henderson } 10892a1905c7SRichard Henderson break; 10902a1905c7SRichard Henderson 10912a1905c7SRichard Henderson case 0x5: /* ltu: C */ 10922a1905c7SRichard Henderson cmp->cond = TCG_COND_NE; 10932a1905c7SRichard Henderson if (TARGET_LONG_BITS == 32 || xcc) { 10942a1905c7SRichard Henderson tcg_gen_mov_tl(t1, cpu_cc_C); 10952a1905c7SRichard Henderson } else { 10962a1905c7SRichard Henderson tcg_gen_extract_tl(t1, cpu_icc_C, 32, 1); 10972a1905c7SRichard Henderson } 10982a1905c7SRichard Henderson break; 10992a1905c7SRichard Henderson 11002a1905c7SRichard Henderson case 0x6: /* neg: N */ 11012a1905c7SRichard Henderson cmp->cond = TCG_COND_LT; 11022a1905c7SRichard Henderson if (TARGET_LONG_BITS == 32 || xcc) { 11032a1905c7SRichard Henderson tcg_gen_mov_tl(t1, cpu_cc_N); 11042a1905c7SRichard Henderson } else { 11052a1905c7SRichard Henderson tcg_gen_ext32s_tl(t1, cpu_cc_N); 11062a1905c7SRichard Henderson } 11072a1905c7SRichard Henderson break; 11082a1905c7SRichard Henderson 11092a1905c7SRichard Henderson case 0x7: /* vs: V */ 11102a1905c7SRichard Henderson cmp->cond = TCG_COND_LT; 11112a1905c7SRichard Henderson if (TARGET_LONG_BITS == 32 || xcc) { 11122a1905c7SRichard Henderson tcg_gen_mov_tl(t1, cpu_cc_V); 11132a1905c7SRichard Henderson } else { 11142a1905c7SRichard Henderson tcg_gen_ext32s_tl(t1, cpu_cc_V); 11152a1905c7SRichard Henderson } 11162a1905c7SRichard Henderson break; 11172a1905c7SRichard Henderson } 11182a1905c7SRichard Henderson if (cond & 8) { 11192a1905c7SRichard Henderson cmp->cond = tcg_invert_cond(cmp->cond); 1120fcf5ef2aSThomas Huth } 1121fcf5ef2aSThomas Huth } 1122fcf5ef2aSThomas Huth 1123fcf5ef2aSThomas Huth static void gen_fcompare(DisasCompare *cmp, unsigned int cc, unsigned int cond) 1124fcf5ef2aSThomas Huth { 1125fcf5ef2aSThomas Huth unsigned int offset; 1126fcf5ef2aSThomas Huth TCGv r_dst; 1127fcf5ef2aSThomas Huth 1128fcf5ef2aSThomas Huth /* For now we still generate a straight boolean result. */ 1129fcf5ef2aSThomas Huth cmp->cond = TCG_COND_NE; 1130fcf5ef2aSThomas Huth cmp->c1 = r_dst = tcg_temp_new(); 1131c8507ebfSRichard Henderson cmp->c2 = 0; 1132fcf5ef2aSThomas Huth 1133fcf5ef2aSThomas Huth switch (cc) { 1134fcf5ef2aSThomas Huth default: 1135fcf5ef2aSThomas Huth case 0x0: 1136fcf5ef2aSThomas Huth offset = 0; 1137fcf5ef2aSThomas Huth break; 1138fcf5ef2aSThomas Huth case 0x1: 1139fcf5ef2aSThomas Huth offset = 32 - 10; 1140fcf5ef2aSThomas Huth break; 1141fcf5ef2aSThomas Huth case 0x2: 1142fcf5ef2aSThomas Huth offset = 34 - 10; 1143fcf5ef2aSThomas Huth break; 1144fcf5ef2aSThomas Huth case 0x3: 1145fcf5ef2aSThomas Huth offset = 36 - 10; 1146fcf5ef2aSThomas Huth break; 1147fcf5ef2aSThomas Huth } 1148fcf5ef2aSThomas Huth 1149fcf5ef2aSThomas Huth switch (cond) { 1150fcf5ef2aSThomas Huth case 0x0: 1151fcf5ef2aSThomas Huth gen_op_eval_bn(r_dst); 1152fcf5ef2aSThomas Huth break; 1153fcf5ef2aSThomas Huth case 0x1: 1154fcf5ef2aSThomas Huth gen_op_eval_fbne(r_dst, cpu_fsr, offset); 1155fcf5ef2aSThomas Huth break; 1156fcf5ef2aSThomas Huth case 0x2: 1157fcf5ef2aSThomas Huth gen_op_eval_fblg(r_dst, cpu_fsr, offset); 1158fcf5ef2aSThomas Huth break; 1159fcf5ef2aSThomas Huth case 0x3: 1160fcf5ef2aSThomas Huth gen_op_eval_fbul(r_dst, cpu_fsr, offset); 1161fcf5ef2aSThomas Huth break; 1162fcf5ef2aSThomas Huth case 0x4: 1163fcf5ef2aSThomas Huth gen_op_eval_fbl(r_dst, cpu_fsr, offset); 1164fcf5ef2aSThomas Huth break; 1165fcf5ef2aSThomas Huth case 0x5: 1166fcf5ef2aSThomas Huth gen_op_eval_fbug(r_dst, cpu_fsr, offset); 1167fcf5ef2aSThomas Huth break; 1168fcf5ef2aSThomas Huth case 0x6: 1169fcf5ef2aSThomas Huth gen_op_eval_fbg(r_dst, cpu_fsr, offset); 1170fcf5ef2aSThomas Huth break; 1171fcf5ef2aSThomas Huth case 0x7: 1172fcf5ef2aSThomas Huth gen_op_eval_fbu(r_dst, cpu_fsr, offset); 1173fcf5ef2aSThomas Huth break; 1174fcf5ef2aSThomas Huth case 0x8: 1175fcf5ef2aSThomas Huth gen_op_eval_ba(r_dst); 1176fcf5ef2aSThomas Huth break; 1177fcf5ef2aSThomas Huth case 0x9: 1178fcf5ef2aSThomas Huth gen_op_eval_fbe(r_dst, cpu_fsr, offset); 1179fcf5ef2aSThomas Huth break; 1180fcf5ef2aSThomas Huth case 0xa: 1181fcf5ef2aSThomas Huth gen_op_eval_fbue(r_dst, cpu_fsr, offset); 1182fcf5ef2aSThomas Huth break; 1183fcf5ef2aSThomas Huth case 0xb: 1184fcf5ef2aSThomas Huth gen_op_eval_fbge(r_dst, cpu_fsr, offset); 1185fcf5ef2aSThomas Huth break; 1186fcf5ef2aSThomas Huth case 0xc: 1187fcf5ef2aSThomas Huth gen_op_eval_fbuge(r_dst, cpu_fsr, offset); 1188fcf5ef2aSThomas Huth break; 1189fcf5ef2aSThomas Huth case 0xd: 1190fcf5ef2aSThomas Huth gen_op_eval_fble(r_dst, cpu_fsr, offset); 1191fcf5ef2aSThomas Huth break; 1192fcf5ef2aSThomas Huth case 0xe: 1193fcf5ef2aSThomas Huth gen_op_eval_fbule(r_dst, cpu_fsr, offset); 1194fcf5ef2aSThomas Huth break; 1195fcf5ef2aSThomas Huth case 0xf: 1196fcf5ef2aSThomas Huth gen_op_eval_fbo(r_dst, cpu_fsr, offset); 1197fcf5ef2aSThomas Huth break; 1198fcf5ef2aSThomas Huth } 1199fcf5ef2aSThomas Huth } 1200fcf5ef2aSThomas Huth 1201fcf5ef2aSThomas Huth // Inverted logic 1202ab9ffe98SRichard Henderson static const TCGCond gen_tcg_cond_reg[8] = { 1203ab9ffe98SRichard Henderson TCG_COND_NEVER, /* reserved */ 1204fcf5ef2aSThomas Huth TCG_COND_NE, 1205fcf5ef2aSThomas Huth TCG_COND_GT, 1206fcf5ef2aSThomas Huth TCG_COND_GE, 1207ab9ffe98SRichard Henderson TCG_COND_NEVER, /* reserved */ 1208fcf5ef2aSThomas Huth TCG_COND_EQ, 1209fcf5ef2aSThomas Huth TCG_COND_LE, 1210fcf5ef2aSThomas Huth TCG_COND_LT, 1211fcf5ef2aSThomas Huth }; 1212fcf5ef2aSThomas Huth 1213fcf5ef2aSThomas Huth static void gen_compare_reg(DisasCompare *cmp, int cond, TCGv r_src) 1214fcf5ef2aSThomas Huth { 1215fcf5ef2aSThomas Huth cmp->cond = tcg_invert_cond(gen_tcg_cond_reg[cond]); 1216816f89b7SRichard Henderson cmp->c1 = tcg_temp_new(); 1217c8507ebfSRichard Henderson cmp->c2 = 0; 1218816f89b7SRichard Henderson tcg_gen_mov_tl(cmp->c1, r_src); 1219fcf5ef2aSThomas Huth } 1220fcf5ef2aSThomas Huth 1221baf3dbf2SRichard Henderson static void gen_op_clear_ieee_excp_and_FTT(void) 1222baf3dbf2SRichard Henderson { 1223baf3dbf2SRichard Henderson tcg_gen_andi_tl(cpu_fsr, cpu_fsr, FSR_FTT_CEXC_NMASK); 1224baf3dbf2SRichard Henderson } 1225baf3dbf2SRichard Henderson 1226baf3dbf2SRichard Henderson static void gen_op_fmovs(TCGv_i32 dst, TCGv_i32 src) 1227baf3dbf2SRichard Henderson { 1228baf3dbf2SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 1229baf3dbf2SRichard Henderson tcg_gen_mov_i32(dst, src); 1230baf3dbf2SRichard Henderson } 1231baf3dbf2SRichard Henderson 1232baf3dbf2SRichard Henderson static void gen_op_fnegs(TCGv_i32 dst, TCGv_i32 src) 1233baf3dbf2SRichard Henderson { 1234baf3dbf2SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 1235baf3dbf2SRichard Henderson gen_helper_fnegs(dst, src); 1236baf3dbf2SRichard Henderson } 1237baf3dbf2SRichard Henderson 1238baf3dbf2SRichard Henderson static void gen_op_fabss(TCGv_i32 dst, TCGv_i32 src) 1239baf3dbf2SRichard Henderson { 1240baf3dbf2SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 1241baf3dbf2SRichard Henderson gen_helper_fabss(dst, src); 1242baf3dbf2SRichard Henderson } 1243baf3dbf2SRichard Henderson 1244c6d83e4fSRichard Henderson static void gen_op_fmovd(TCGv_i64 dst, TCGv_i64 src) 1245c6d83e4fSRichard Henderson { 1246c6d83e4fSRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 1247c6d83e4fSRichard Henderson tcg_gen_mov_i64(dst, src); 1248c6d83e4fSRichard Henderson } 1249c6d83e4fSRichard Henderson 1250c6d83e4fSRichard Henderson static void gen_op_fnegd(TCGv_i64 dst, TCGv_i64 src) 1251c6d83e4fSRichard Henderson { 1252c6d83e4fSRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 1253c6d83e4fSRichard Henderson gen_helper_fnegd(dst, src); 1254c6d83e4fSRichard Henderson } 1255c6d83e4fSRichard Henderson 1256c6d83e4fSRichard Henderson static void gen_op_fabsd(TCGv_i64 dst, TCGv_i64 src) 1257c6d83e4fSRichard Henderson { 1258c6d83e4fSRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 1259c6d83e4fSRichard Henderson gen_helper_fabsd(dst, src); 1260c6d83e4fSRichard Henderson } 1261c6d83e4fSRichard Henderson 1262fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64 12630c2e96c1SRichard Henderson static void gen_op_fcmps(int fccno, TCGv_i32 r_rs1, TCGv_i32 r_rs2) 1264fcf5ef2aSThomas Huth { 1265fcf5ef2aSThomas Huth switch (fccno) { 1266fcf5ef2aSThomas Huth case 0: 1267ad75a51eSRichard Henderson gen_helper_fcmps(cpu_fsr, tcg_env, r_rs1, r_rs2); 1268fcf5ef2aSThomas Huth break; 1269fcf5ef2aSThomas Huth case 1: 1270ad75a51eSRichard Henderson gen_helper_fcmps_fcc1(cpu_fsr, tcg_env, r_rs1, r_rs2); 1271fcf5ef2aSThomas Huth break; 1272fcf5ef2aSThomas Huth case 2: 1273ad75a51eSRichard Henderson gen_helper_fcmps_fcc2(cpu_fsr, tcg_env, r_rs1, r_rs2); 1274fcf5ef2aSThomas Huth break; 1275fcf5ef2aSThomas Huth case 3: 1276ad75a51eSRichard Henderson gen_helper_fcmps_fcc3(cpu_fsr, tcg_env, r_rs1, r_rs2); 1277fcf5ef2aSThomas Huth break; 1278fcf5ef2aSThomas Huth } 1279fcf5ef2aSThomas Huth } 1280fcf5ef2aSThomas Huth 12810c2e96c1SRichard Henderson static void gen_op_fcmpd(int fccno, TCGv_i64 r_rs1, TCGv_i64 r_rs2) 1282fcf5ef2aSThomas Huth { 1283fcf5ef2aSThomas Huth switch (fccno) { 1284fcf5ef2aSThomas Huth case 0: 1285ad75a51eSRichard Henderson gen_helper_fcmpd(cpu_fsr, tcg_env, r_rs1, r_rs2); 1286fcf5ef2aSThomas Huth break; 1287fcf5ef2aSThomas Huth case 1: 1288ad75a51eSRichard Henderson gen_helper_fcmpd_fcc1(cpu_fsr, tcg_env, r_rs1, r_rs2); 1289fcf5ef2aSThomas Huth break; 1290fcf5ef2aSThomas Huth case 2: 1291ad75a51eSRichard Henderson gen_helper_fcmpd_fcc2(cpu_fsr, tcg_env, r_rs1, r_rs2); 1292fcf5ef2aSThomas Huth break; 1293fcf5ef2aSThomas Huth case 3: 1294ad75a51eSRichard Henderson gen_helper_fcmpd_fcc3(cpu_fsr, tcg_env, r_rs1, r_rs2); 1295fcf5ef2aSThomas Huth break; 1296fcf5ef2aSThomas Huth } 1297fcf5ef2aSThomas Huth } 1298fcf5ef2aSThomas Huth 12990c2e96c1SRichard Henderson static void gen_op_fcmpq(int fccno) 1300fcf5ef2aSThomas Huth { 1301fcf5ef2aSThomas Huth switch (fccno) { 1302fcf5ef2aSThomas Huth case 0: 1303ad75a51eSRichard Henderson gen_helper_fcmpq(cpu_fsr, tcg_env); 1304fcf5ef2aSThomas Huth break; 1305fcf5ef2aSThomas Huth case 1: 1306ad75a51eSRichard Henderson gen_helper_fcmpq_fcc1(cpu_fsr, tcg_env); 1307fcf5ef2aSThomas Huth break; 1308fcf5ef2aSThomas Huth case 2: 1309ad75a51eSRichard Henderson gen_helper_fcmpq_fcc2(cpu_fsr, tcg_env); 1310fcf5ef2aSThomas Huth break; 1311fcf5ef2aSThomas Huth case 3: 1312ad75a51eSRichard Henderson gen_helper_fcmpq_fcc3(cpu_fsr, tcg_env); 1313fcf5ef2aSThomas Huth break; 1314fcf5ef2aSThomas Huth } 1315fcf5ef2aSThomas Huth } 1316fcf5ef2aSThomas Huth 13170c2e96c1SRichard Henderson static void gen_op_fcmpes(int fccno, TCGv_i32 r_rs1, TCGv_i32 r_rs2) 1318fcf5ef2aSThomas Huth { 1319fcf5ef2aSThomas Huth switch (fccno) { 1320fcf5ef2aSThomas Huth case 0: 1321ad75a51eSRichard Henderson gen_helper_fcmpes(cpu_fsr, tcg_env, r_rs1, r_rs2); 1322fcf5ef2aSThomas Huth break; 1323fcf5ef2aSThomas Huth case 1: 1324ad75a51eSRichard Henderson gen_helper_fcmpes_fcc1(cpu_fsr, tcg_env, r_rs1, r_rs2); 1325fcf5ef2aSThomas Huth break; 1326fcf5ef2aSThomas Huth case 2: 1327ad75a51eSRichard Henderson gen_helper_fcmpes_fcc2(cpu_fsr, tcg_env, r_rs1, r_rs2); 1328fcf5ef2aSThomas Huth break; 1329fcf5ef2aSThomas Huth case 3: 1330ad75a51eSRichard Henderson gen_helper_fcmpes_fcc3(cpu_fsr, tcg_env, r_rs1, r_rs2); 1331fcf5ef2aSThomas Huth break; 1332fcf5ef2aSThomas Huth } 1333fcf5ef2aSThomas Huth } 1334fcf5ef2aSThomas Huth 13350c2e96c1SRichard Henderson static void gen_op_fcmped(int fccno, TCGv_i64 r_rs1, TCGv_i64 r_rs2) 1336fcf5ef2aSThomas Huth { 1337fcf5ef2aSThomas Huth switch (fccno) { 1338fcf5ef2aSThomas Huth case 0: 1339ad75a51eSRichard Henderson gen_helper_fcmped(cpu_fsr, tcg_env, r_rs1, r_rs2); 1340fcf5ef2aSThomas Huth break; 1341fcf5ef2aSThomas Huth case 1: 1342ad75a51eSRichard Henderson gen_helper_fcmped_fcc1(cpu_fsr, tcg_env, r_rs1, r_rs2); 1343fcf5ef2aSThomas Huth break; 1344fcf5ef2aSThomas Huth case 2: 1345ad75a51eSRichard Henderson gen_helper_fcmped_fcc2(cpu_fsr, tcg_env, r_rs1, r_rs2); 1346fcf5ef2aSThomas Huth break; 1347fcf5ef2aSThomas Huth case 3: 1348ad75a51eSRichard Henderson gen_helper_fcmped_fcc3(cpu_fsr, tcg_env, r_rs1, r_rs2); 1349fcf5ef2aSThomas Huth break; 1350fcf5ef2aSThomas Huth } 1351fcf5ef2aSThomas Huth } 1352fcf5ef2aSThomas Huth 13530c2e96c1SRichard Henderson static void gen_op_fcmpeq(int fccno) 1354fcf5ef2aSThomas Huth { 1355fcf5ef2aSThomas Huth switch (fccno) { 1356fcf5ef2aSThomas Huth case 0: 1357ad75a51eSRichard Henderson gen_helper_fcmpeq(cpu_fsr, tcg_env); 1358fcf5ef2aSThomas Huth break; 1359fcf5ef2aSThomas Huth case 1: 1360ad75a51eSRichard Henderson gen_helper_fcmpeq_fcc1(cpu_fsr, tcg_env); 1361fcf5ef2aSThomas Huth break; 1362fcf5ef2aSThomas Huth case 2: 1363ad75a51eSRichard Henderson gen_helper_fcmpeq_fcc2(cpu_fsr, tcg_env); 1364fcf5ef2aSThomas Huth break; 1365fcf5ef2aSThomas Huth case 3: 1366ad75a51eSRichard Henderson gen_helper_fcmpeq_fcc3(cpu_fsr, tcg_env); 1367fcf5ef2aSThomas Huth break; 1368fcf5ef2aSThomas Huth } 1369fcf5ef2aSThomas Huth } 1370fcf5ef2aSThomas Huth 1371fcf5ef2aSThomas Huth #else 1372fcf5ef2aSThomas Huth 13730c2e96c1SRichard Henderson static void gen_op_fcmps(int fccno, TCGv r_rs1, TCGv r_rs2) 1374fcf5ef2aSThomas Huth { 1375ad75a51eSRichard Henderson gen_helper_fcmps(cpu_fsr, tcg_env, r_rs1, r_rs2); 1376fcf5ef2aSThomas Huth } 1377fcf5ef2aSThomas Huth 13780c2e96c1SRichard Henderson static void gen_op_fcmpd(int fccno, TCGv_i64 r_rs1, TCGv_i64 r_rs2) 1379fcf5ef2aSThomas Huth { 1380ad75a51eSRichard Henderson gen_helper_fcmpd(cpu_fsr, tcg_env, r_rs1, r_rs2); 1381fcf5ef2aSThomas Huth } 1382fcf5ef2aSThomas Huth 13830c2e96c1SRichard Henderson static void gen_op_fcmpq(int fccno) 1384fcf5ef2aSThomas Huth { 1385ad75a51eSRichard Henderson gen_helper_fcmpq(cpu_fsr, tcg_env); 1386fcf5ef2aSThomas Huth } 1387fcf5ef2aSThomas Huth 13880c2e96c1SRichard Henderson static void gen_op_fcmpes(int fccno, TCGv r_rs1, TCGv r_rs2) 1389fcf5ef2aSThomas Huth { 1390ad75a51eSRichard Henderson gen_helper_fcmpes(cpu_fsr, tcg_env, r_rs1, r_rs2); 1391fcf5ef2aSThomas Huth } 1392fcf5ef2aSThomas Huth 13930c2e96c1SRichard Henderson static void gen_op_fcmped(int fccno, TCGv_i64 r_rs1, TCGv_i64 r_rs2) 1394fcf5ef2aSThomas Huth { 1395ad75a51eSRichard Henderson gen_helper_fcmped(cpu_fsr, tcg_env, r_rs1, r_rs2); 1396fcf5ef2aSThomas Huth } 1397fcf5ef2aSThomas Huth 13980c2e96c1SRichard Henderson static void gen_op_fcmpeq(int fccno) 1399fcf5ef2aSThomas Huth { 1400ad75a51eSRichard Henderson gen_helper_fcmpeq(cpu_fsr, tcg_env); 1401fcf5ef2aSThomas Huth } 1402fcf5ef2aSThomas Huth #endif 1403fcf5ef2aSThomas Huth 1404fcf5ef2aSThomas Huth static void gen_op_fpexception_im(DisasContext *dc, int fsr_flags) 1405fcf5ef2aSThomas Huth { 1406fcf5ef2aSThomas Huth tcg_gen_andi_tl(cpu_fsr, cpu_fsr, FSR_FTT_NMASK); 1407fcf5ef2aSThomas Huth tcg_gen_ori_tl(cpu_fsr, cpu_fsr, fsr_flags); 1408fcf5ef2aSThomas Huth gen_exception(dc, TT_FP_EXCP); 1409fcf5ef2aSThomas Huth } 1410fcf5ef2aSThomas Huth 1411fcf5ef2aSThomas Huth static int gen_trap_ifnofpu(DisasContext *dc) 1412fcf5ef2aSThomas Huth { 1413fcf5ef2aSThomas Huth #if !defined(CONFIG_USER_ONLY) 1414fcf5ef2aSThomas Huth if (!dc->fpu_enabled) { 1415fcf5ef2aSThomas Huth gen_exception(dc, TT_NFPU_INSN); 1416fcf5ef2aSThomas Huth return 1; 1417fcf5ef2aSThomas Huth } 1418fcf5ef2aSThomas Huth #endif 1419fcf5ef2aSThomas Huth return 0; 1420fcf5ef2aSThomas Huth } 1421fcf5ef2aSThomas Huth 1422fcf5ef2aSThomas Huth /* asi moves */ 1423fcf5ef2aSThomas Huth typedef enum { 1424fcf5ef2aSThomas Huth GET_ASI_HELPER, 1425fcf5ef2aSThomas Huth GET_ASI_EXCP, 1426fcf5ef2aSThomas Huth GET_ASI_DIRECT, 1427fcf5ef2aSThomas Huth GET_ASI_DTWINX, 1428fcf5ef2aSThomas Huth GET_ASI_BLOCK, 1429fcf5ef2aSThomas Huth GET_ASI_SHORT, 1430fcf5ef2aSThomas Huth GET_ASI_BCOPY, 1431fcf5ef2aSThomas Huth GET_ASI_BFILL, 1432fcf5ef2aSThomas Huth } ASIType; 1433fcf5ef2aSThomas Huth 1434fcf5ef2aSThomas Huth typedef struct { 1435fcf5ef2aSThomas Huth ASIType type; 1436fcf5ef2aSThomas Huth int asi; 1437fcf5ef2aSThomas Huth int mem_idx; 143814776ab5STony Nguyen MemOp memop; 1439fcf5ef2aSThomas Huth } DisasASI; 1440fcf5ef2aSThomas Huth 1441811cc0b0SRichard Henderson /* 1442811cc0b0SRichard Henderson * Build DisasASI. 1443811cc0b0SRichard Henderson * For asi == -1, treat as non-asi. 1444811cc0b0SRichard Henderson * For ask == -2, treat as immediate offset (v8 error, v9 %asi). 1445811cc0b0SRichard Henderson */ 1446811cc0b0SRichard Henderson static DisasASI resolve_asi(DisasContext *dc, int asi, MemOp memop) 1447fcf5ef2aSThomas Huth { 1448fcf5ef2aSThomas Huth ASIType type = GET_ASI_HELPER; 1449fcf5ef2aSThomas Huth int mem_idx = dc->mem_idx; 1450fcf5ef2aSThomas Huth 1451811cc0b0SRichard Henderson if (asi == -1) { 1452811cc0b0SRichard Henderson /* Artificial "non-asi" case. */ 1453811cc0b0SRichard Henderson type = GET_ASI_DIRECT; 1454811cc0b0SRichard Henderson goto done; 1455811cc0b0SRichard Henderson } 1456811cc0b0SRichard Henderson 1457fcf5ef2aSThomas Huth #ifndef TARGET_SPARC64 1458fcf5ef2aSThomas Huth /* Before v9, all asis are immediate and privileged. */ 1459811cc0b0SRichard Henderson if (asi < 0) { 1460fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 1461fcf5ef2aSThomas Huth type = GET_ASI_EXCP; 1462fcf5ef2aSThomas Huth } else if (supervisor(dc) 1463fcf5ef2aSThomas Huth /* Note that LEON accepts ASI_USERDATA in user mode, for 1464fcf5ef2aSThomas Huth use with CASA. Also note that previous versions of 1465fcf5ef2aSThomas Huth QEMU allowed (and old versions of gcc emitted) ASI_P 1466fcf5ef2aSThomas Huth for LEON, which is incorrect. */ 1467fcf5ef2aSThomas Huth || (asi == ASI_USERDATA 1468fcf5ef2aSThomas Huth && (dc->def->features & CPU_FEATURE_CASA))) { 1469fcf5ef2aSThomas Huth switch (asi) { 1470fcf5ef2aSThomas Huth case ASI_USERDATA: /* User data access */ 1471fcf5ef2aSThomas Huth mem_idx = MMU_USER_IDX; 1472fcf5ef2aSThomas Huth type = GET_ASI_DIRECT; 1473fcf5ef2aSThomas Huth break; 1474fcf5ef2aSThomas Huth case ASI_KERNELDATA: /* Supervisor data access */ 1475fcf5ef2aSThomas Huth mem_idx = MMU_KERNEL_IDX; 1476fcf5ef2aSThomas Huth type = GET_ASI_DIRECT; 1477fcf5ef2aSThomas Huth break; 1478fcf5ef2aSThomas Huth case ASI_M_BYPASS: /* MMU passthrough */ 1479fcf5ef2aSThomas Huth case ASI_LEON_BYPASS: /* LEON MMU passthrough */ 1480fcf5ef2aSThomas Huth mem_idx = MMU_PHYS_IDX; 1481fcf5ef2aSThomas Huth type = GET_ASI_DIRECT; 1482fcf5ef2aSThomas Huth break; 1483fcf5ef2aSThomas Huth case ASI_M_BCOPY: /* Block copy, sta access */ 1484fcf5ef2aSThomas Huth mem_idx = MMU_KERNEL_IDX; 1485fcf5ef2aSThomas Huth type = GET_ASI_BCOPY; 1486fcf5ef2aSThomas Huth break; 1487fcf5ef2aSThomas Huth case ASI_M_BFILL: /* Block fill, stda access */ 1488fcf5ef2aSThomas Huth mem_idx = MMU_KERNEL_IDX; 1489fcf5ef2aSThomas Huth type = GET_ASI_BFILL; 1490fcf5ef2aSThomas Huth break; 1491fcf5ef2aSThomas Huth } 14926e10f37cSKONRAD Frederic 14936e10f37cSKONRAD Frederic /* MMU_PHYS_IDX is used when the MMU is disabled to passthrough the 14946e10f37cSKONRAD Frederic * permissions check in get_physical_address(..). 14956e10f37cSKONRAD Frederic */ 14966e10f37cSKONRAD Frederic mem_idx = (dc->mem_idx == MMU_PHYS_IDX) ? MMU_PHYS_IDX : mem_idx; 1497fcf5ef2aSThomas Huth } else { 1498fcf5ef2aSThomas Huth gen_exception(dc, TT_PRIV_INSN); 1499fcf5ef2aSThomas Huth type = GET_ASI_EXCP; 1500fcf5ef2aSThomas Huth } 1501fcf5ef2aSThomas Huth #else 1502811cc0b0SRichard Henderson if (asi < 0) { 1503fcf5ef2aSThomas Huth asi = dc->asi; 1504fcf5ef2aSThomas Huth } 1505fcf5ef2aSThomas Huth /* With v9, all asis below 0x80 are privileged. */ 1506fcf5ef2aSThomas Huth /* ??? We ought to check cpu_has_hypervisor, but we didn't copy 1507fcf5ef2aSThomas Huth down that bit into DisasContext. For the moment that's ok, 1508fcf5ef2aSThomas Huth since the direct implementations below doesn't have any ASIs 1509fcf5ef2aSThomas Huth in the restricted [0x30, 0x7f] range, and the check will be 1510fcf5ef2aSThomas Huth done properly in the helper. */ 1511fcf5ef2aSThomas Huth if (!supervisor(dc) && asi < 0x80) { 1512fcf5ef2aSThomas Huth gen_exception(dc, TT_PRIV_ACT); 1513fcf5ef2aSThomas Huth type = GET_ASI_EXCP; 1514fcf5ef2aSThomas Huth } else { 1515fcf5ef2aSThomas Huth switch (asi) { 1516fcf5ef2aSThomas Huth case ASI_REAL: /* Bypass */ 1517fcf5ef2aSThomas Huth case ASI_REAL_IO: /* Bypass, non-cacheable */ 1518fcf5ef2aSThomas Huth case ASI_REAL_L: /* Bypass LE */ 1519fcf5ef2aSThomas Huth case ASI_REAL_IO_L: /* Bypass, non-cacheable LE */ 1520fcf5ef2aSThomas Huth case ASI_TWINX_REAL: /* Real address, twinx */ 1521fcf5ef2aSThomas Huth case ASI_TWINX_REAL_L: /* Real address, twinx, LE */ 1522fcf5ef2aSThomas Huth case ASI_QUAD_LDD_PHYS: 1523fcf5ef2aSThomas Huth case ASI_QUAD_LDD_PHYS_L: 1524fcf5ef2aSThomas Huth mem_idx = MMU_PHYS_IDX; 1525fcf5ef2aSThomas Huth break; 1526fcf5ef2aSThomas Huth case ASI_N: /* Nucleus */ 1527fcf5ef2aSThomas Huth case ASI_NL: /* Nucleus LE */ 1528fcf5ef2aSThomas Huth case ASI_TWINX_N: 1529fcf5ef2aSThomas Huth case ASI_TWINX_NL: 1530fcf5ef2aSThomas Huth case ASI_NUCLEUS_QUAD_LDD: 1531fcf5ef2aSThomas Huth case ASI_NUCLEUS_QUAD_LDD_L: 15329a10756dSArtyom Tarasenko if (hypervisor(dc)) { 153384f8f587SArtyom Tarasenko mem_idx = MMU_PHYS_IDX; 15349a10756dSArtyom Tarasenko } else { 1535fcf5ef2aSThomas Huth mem_idx = MMU_NUCLEUS_IDX; 15369a10756dSArtyom Tarasenko } 1537fcf5ef2aSThomas Huth break; 1538fcf5ef2aSThomas Huth case ASI_AIUP: /* As if user primary */ 1539fcf5ef2aSThomas Huth case ASI_AIUPL: /* As if user primary LE */ 1540fcf5ef2aSThomas Huth case ASI_TWINX_AIUP: 1541fcf5ef2aSThomas Huth case ASI_TWINX_AIUP_L: 1542fcf5ef2aSThomas Huth case ASI_BLK_AIUP_4V: 1543fcf5ef2aSThomas Huth case ASI_BLK_AIUP_L_4V: 1544fcf5ef2aSThomas Huth case ASI_BLK_AIUP: 1545fcf5ef2aSThomas Huth case ASI_BLK_AIUPL: 1546fcf5ef2aSThomas Huth mem_idx = MMU_USER_IDX; 1547fcf5ef2aSThomas Huth break; 1548fcf5ef2aSThomas Huth case ASI_AIUS: /* As if user secondary */ 1549fcf5ef2aSThomas Huth case ASI_AIUSL: /* As if user secondary LE */ 1550fcf5ef2aSThomas Huth case ASI_TWINX_AIUS: 1551fcf5ef2aSThomas Huth case ASI_TWINX_AIUS_L: 1552fcf5ef2aSThomas Huth case ASI_BLK_AIUS_4V: 1553fcf5ef2aSThomas Huth case ASI_BLK_AIUS_L_4V: 1554fcf5ef2aSThomas Huth case ASI_BLK_AIUS: 1555fcf5ef2aSThomas Huth case ASI_BLK_AIUSL: 1556fcf5ef2aSThomas Huth mem_idx = MMU_USER_SECONDARY_IDX; 1557fcf5ef2aSThomas Huth break; 1558fcf5ef2aSThomas Huth case ASI_S: /* Secondary */ 1559fcf5ef2aSThomas Huth case ASI_SL: /* Secondary LE */ 1560fcf5ef2aSThomas Huth case ASI_TWINX_S: 1561fcf5ef2aSThomas Huth case ASI_TWINX_SL: 1562fcf5ef2aSThomas Huth case ASI_BLK_COMMIT_S: 1563fcf5ef2aSThomas Huth case ASI_BLK_S: 1564fcf5ef2aSThomas Huth case ASI_BLK_SL: 1565fcf5ef2aSThomas Huth case ASI_FL8_S: 1566fcf5ef2aSThomas Huth case ASI_FL8_SL: 1567fcf5ef2aSThomas Huth case ASI_FL16_S: 1568fcf5ef2aSThomas Huth case ASI_FL16_SL: 1569fcf5ef2aSThomas Huth if (mem_idx == MMU_USER_IDX) { 1570fcf5ef2aSThomas Huth mem_idx = MMU_USER_SECONDARY_IDX; 1571fcf5ef2aSThomas Huth } else if (mem_idx == MMU_KERNEL_IDX) { 1572fcf5ef2aSThomas Huth mem_idx = MMU_KERNEL_SECONDARY_IDX; 1573fcf5ef2aSThomas Huth } 1574fcf5ef2aSThomas Huth break; 1575fcf5ef2aSThomas Huth case ASI_P: /* Primary */ 1576fcf5ef2aSThomas Huth case ASI_PL: /* Primary LE */ 1577fcf5ef2aSThomas Huth case ASI_TWINX_P: 1578fcf5ef2aSThomas Huth case ASI_TWINX_PL: 1579fcf5ef2aSThomas Huth case ASI_BLK_COMMIT_P: 1580fcf5ef2aSThomas Huth case ASI_BLK_P: 1581fcf5ef2aSThomas Huth case ASI_BLK_PL: 1582fcf5ef2aSThomas Huth case ASI_FL8_P: 1583fcf5ef2aSThomas Huth case ASI_FL8_PL: 1584fcf5ef2aSThomas Huth case ASI_FL16_P: 1585fcf5ef2aSThomas Huth case ASI_FL16_PL: 1586fcf5ef2aSThomas Huth break; 1587fcf5ef2aSThomas Huth } 1588fcf5ef2aSThomas Huth switch (asi) { 1589fcf5ef2aSThomas Huth case ASI_REAL: 1590fcf5ef2aSThomas Huth case ASI_REAL_IO: 1591fcf5ef2aSThomas Huth case ASI_REAL_L: 1592fcf5ef2aSThomas Huth case ASI_REAL_IO_L: 1593fcf5ef2aSThomas Huth case ASI_N: 1594fcf5ef2aSThomas Huth case ASI_NL: 1595fcf5ef2aSThomas Huth case ASI_AIUP: 1596fcf5ef2aSThomas Huth case ASI_AIUPL: 1597fcf5ef2aSThomas Huth case ASI_AIUS: 1598fcf5ef2aSThomas Huth case ASI_AIUSL: 1599fcf5ef2aSThomas Huth case ASI_S: 1600fcf5ef2aSThomas Huth case ASI_SL: 1601fcf5ef2aSThomas Huth case ASI_P: 1602fcf5ef2aSThomas Huth case ASI_PL: 1603fcf5ef2aSThomas Huth type = GET_ASI_DIRECT; 1604fcf5ef2aSThomas Huth break; 1605fcf5ef2aSThomas Huth case ASI_TWINX_REAL: 1606fcf5ef2aSThomas Huth case ASI_TWINX_REAL_L: 1607fcf5ef2aSThomas Huth case ASI_TWINX_N: 1608fcf5ef2aSThomas Huth case ASI_TWINX_NL: 1609fcf5ef2aSThomas Huth case ASI_TWINX_AIUP: 1610fcf5ef2aSThomas Huth case ASI_TWINX_AIUP_L: 1611fcf5ef2aSThomas Huth case ASI_TWINX_AIUS: 1612fcf5ef2aSThomas Huth case ASI_TWINX_AIUS_L: 1613fcf5ef2aSThomas Huth case ASI_TWINX_P: 1614fcf5ef2aSThomas Huth case ASI_TWINX_PL: 1615fcf5ef2aSThomas Huth case ASI_TWINX_S: 1616fcf5ef2aSThomas Huth case ASI_TWINX_SL: 1617fcf5ef2aSThomas Huth case ASI_QUAD_LDD_PHYS: 1618fcf5ef2aSThomas Huth case ASI_QUAD_LDD_PHYS_L: 1619fcf5ef2aSThomas Huth case ASI_NUCLEUS_QUAD_LDD: 1620fcf5ef2aSThomas Huth case ASI_NUCLEUS_QUAD_LDD_L: 1621fcf5ef2aSThomas Huth type = GET_ASI_DTWINX; 1622fcf5ef2aSThomas Huth break; 1623fcf5ef2aSThomas Huth case ASI_BLK_COMMIT_P: 1624fcf5ef2aSThomas Huth case ASI_BLK_COMMIT_S: 1625fcf5ef2aSThomas Huth case ASI_BLK_AIUP_4V: 1626fcf5ef2aSThomas Huth case ASI_BLK_AIUP_L_4V: 1627fcf5ef2aSThomas Huth case ASI_BLK_AIUP: 1628fcf5ef2aSThomas Huth case ASI_BLK_AIUPL: 1629fcf5ef2aSThomas Huth case ASI_BLK_AIUS_4V: 1630fcf5ef2aSThomas Huth case ASI_BLK_AIUS_L_4V: 1631fcf5ef2aSThomas Huth case ASI_BLK_AIUS: 1632fcf5ef2aSThomas Huth case ASI_BLK_AIUSL: 1633fcf5ef2aSThomas Huth case ASI_BLK_S: 1634fcf5ef2aSThomas Huth case ASI_BLK_SL: 1635fcf5ef2aSThomas Huth case ASI_BLK_P: 1636fcf5ef2aSThomas Huth case ASI_BLK_PL: 1637fcf5ef2aSThomas Huth type = GET_ASI_BLOCK; 1638fcf5ef2aSThomas Huth break; 1639fcf5ef2aSThomas Huth case ASI_FL8_S: 1640fcf5ef2aSThomas Huth case ASI_FL8_SL: 1641fcf5ef2aSThomas Huth case ASI_FL8_P: 1642fcf5ef2aSThomas Huth case ASI_FL8_PL: 1643fcf5ef2aSThomas Huth memop = MO_UB; 1644fcf5ef2aSThomas Huth type = GET_ASI_SHORT; 1645fcf5ef2aSThomas Huth break; 1646fcf5ef2aSThomas Huth case ASI_FL16_S: 1647fcf5ef2aSThomas Huth case ASI_FL16_SL: 1648fcf5ef2aSThomas Huth case ASI_FL16_P: 1649fcf5ef2aSThomas Huth case ASI_FL16_PL: 1650fcf5ef2aSThomas Huth memop = MO_TEUW; 1651fcf5ef2aSThomas Huth type = GET_ASI_SHORT; 1652fcf5ef2aSThomas Huth break; 1653fcf5ef2aSThomas Huth } 1654fcf5ef2aSThomas Huth /* The little-endian asis all have bit 3 set. */ 1655fcf5ef2aSThomas Huth if (asi & 8) { 1656fcf5ef2aSThomas Huth memop ^= MO_BSWAP; 1657fcf5ef2aSThomas Huth } 1658fcf5ef2aSThomas Huth } 1659fcf5ef2aSThomas Huth #endif 1660fcf5ef2aSThomas Huth 1661811cc0b0SRichard Henderson done: 1662fcf5ef2aSThomas Huth return (DisasASI){ type, asi, mem_idx, memop }; 1663fcf5ef2aSThomas Huth } 1664fcf5ef2aSThomas Huth 1665a76779eeSRichard Henderson #if defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64) 1666a76779eeSRichard Henderson static void gen_helper_ld_asi(TCGv_i64 r, TCGv_env e, TCGv a, 1667a76779eeSRichard Henderson TCGv_i32 asi, TCGv_i32 mop) 1668a76779eeSRichard Henderson { 1669a76779eeSRichard Henderson g_assert_not_reached(); 1670a76779eeSRichard Henderson } 1671a76779eeSRichard Henderson 1672a76779eeSRichard Henderson static void gen_helper_st_asi(TCGv_env e, TCGv a, TCGv_i64 r, 1673a76779eeSRichard Henderson TCGv_i32 asi, TCGv_i32 mop) 1674a76779eeSRichard Henderson { 1675a76779eeSRichard Henderson g_assert_not_reached(); 1676a76779eeSRichard Henderson } 1677a76779eeSRichard Henderson #endif 1678a76779eeSRichard Henderson 167942071fc1SRichard Henderson static void gen_ld_asi(DisasContext *dc, DisasASI *da, TCGv dst, TCGv addr) 1680fcf5ef2aSThomas Huth { 1681c03a0fd1SRichard Henderson switch (da->type) { 1682fcf5ef2aSThomas Huth case GET_ASI_EXCP: 1683fcf5ef2aSThomas Huth break; 1684fcf5ef2aSThomas Huth case GET_ASI_DTWINX: /* Reserved for ldda. */ 1685fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 1686fcf5ef2aSThomas Huth break; 1687fcf5ef2aSThomas Huth case GET_ASI_DIRECT: 1688c03a0fd1SRichard Henderson tcg_gen_qemu_ld_tl(dst, addr, da->mem_idx, da->memop | MO_ALIGN); 1689fcf5ef2aSThomas Huth break; 1690fcf5ef2aSThomas Huth default: 1691fcf5ef2aSThomas Huth { 1692c03a0fd1SRichard Henderson TCGv_i32 r_asi = tcg_constant_i32(da->asi); 1693c03a0fd1SRichard Henderson TCGv_i32 r_mop = tcg_constant_i32(da->memop | MO_ALIGN); 1694fcf5ef2aSThomas Huth 1695fcf5ef2aSThomas Huth save_state(dc); 1696fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64 1697ad75a51eSRichard Henderson gen_helper_ld_asi(dst, tcg_env, addr, r_asi, r_mop); 1698fcf5ef2aSThomas Huth #else 1699fcf5ef2aSThomas Huth { 1700fcf5ef2aSThomas Huth TCGv_i64 t64 = tcg_temp_new_i64(); 1701ad75a51eSRichard Henderson gen_helper_ld_asi(t64, tcg_env, addr, r_asi, r_mop); 1702fcf5ef2aSThomas Huth tcg_gen_trunc_i64_tl(dst, t64); 1703fcf5ef2aSThomas Huth } 1704fcf5ef2aSThomas Huth #endif 1705fcf5ef2aSThomas Huth } 1706fcf5ef2aSThomas Huth break; 1707fcf5ef2aSThomas Huth } 1708fcf5ef2aSThomas Huth } 1709fcf5ef2aSThomas Huth 171042071fc1SRichard Henderson static void gen_st_asi(DisasContext *dc, DisasASI *da, TCGv src, TCGv addr) 1711c03a0fd1SRichard Henderson { 1712c03a0fd1SRichard Henderson switch (da->type) { 1713fcf5ef2aSThomas Huth case GET_ASI_EXCP: 1714fcf5ef2aSThomas Huth break; 1715c03a0fd1SRichard Henderson 1716fcf5ef2aSThomas Huth case GET_ASI_DTWINX: /* Reserved for stda. */ 1717c03a0fd1SRichard Henderson if (TARGET_LONG_BITS == 32) { 1718fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 1719fcf5ef2aSThomas Huth break; 1720c03a0fd1SRichard Henderson } else if (!(dc->def->features & CPU_FEATURE_HYPV)) { 17213390537bSArtyom Tarasenko /* Pre OpenSPARC CPUs don't have these */ 17223390537bSArtyom Tarasenko gen_exception(dc, TT_ILL_INSN); 1723fcf5ef2aSThomas Huth break; 1724c03a0fd1SRichard Henderson } 1725c03a0fd1SRichard Henderson /* In OpenSPARC T1+ CPUs TWINX ASIs in store are ST_BLKINIT_ ASIs */ 1726c03a0fd1SRichard Henderson /* fall through */ 1727c03a0fd1SRichard Henderson 1728c03a0fd1SRichard Henderson case GET_ASI_DIRECT: 1729c03a0fd1SRichard Henderson tcg_gen_qemu_st_tl(src, addr, da->mem_idx, da->memop | MO_ALIGN); 1730c03a0fd1SRichard Henderson break; 1731c03a0fd1SRichard Henderson 1732fcf5ef2aSThomas Huth case GET_ASI_BCOPY: 1733c03a0fd1SRichard Henderson assert(TARGET_LONG_BITS == 32); 1734fcf5ef2aSThomas Huth /* Copy 32 bytes from the address in SRC to ADDR. */ 1735fcf5ef2aSThomas Huth /* ??? The original qemu code suggests 4-byte alignment, dropping 1736fcf5ef2aSThomas Huth the low bits, but the only place I can see this used is in the 1737fcf5ef2aSThomas Huth Linux kernel with 32 byte alignment, which would make more sense 1738fcf5ef2aSThomas Huth as a cacheline-style operation. */ 1739fcf5ef2aSThomas Huth { 1740fcf5ef2aSThomas Huth TCGv saddr = tcg_temp_new(); 1741fcf5ef2aSThomas Huth TCGv daddr = tcg_temp_new(); 174200ab7e61SRichard Henderson TCGv four = tcg_constant_tl(4); 1743fcf5ef2aSThomas Huth TCGv_i32 tmp = tcg_temp_new_i32(); 1744fcf5ef2aSThomas Huth int i; 1745fcf5ef2aSThomas Huth 1746fcf5ef2aSThomas Huth tcg_gen_andi_tl(saddr, src, -4); 1747fcf5ef2aSThomas Huth tcg_gen_andi_tl(daddr, addr, -4); 1748fcf5ef2aSThomas Huth for (i = 0; i < 32; i += 4) { 1749fcf5ef2aSThomas Huth /* Since the loads and stores are paired, allow the 1750fcf5ef2aSThomas Huth copy to happen in the host endianness. */ 1751c03a0fd1SRichard Henderson tcg_gen_qemu_ld_i32(tmp, saddr, da->mem_idx, MO_UL); 1752c03a0fd1SRichard Henderson tcg_gen_qemu_st_i32(tmp, daddr, da->mem_idx, MO_UL); 1753fcf5ef2aSThomas Huth tcg_gen_add_tl(saddr, saddr, four); 1754fcf5ef2aSThomas Huth tcg_gen_add_tl(daddr, daddr, four); 1755fcf5ef2aSThomas Huth } 1756fcf5ef2aSThomas Huth } 1757fcf5ef2aSThomas Huth break; 1758c03a0fd1SRichard Henderson 1759fcf5ef2aSThomas Huth default: 1760fcf5ef2aSThomas Huth { 1761c03a0fd1SRichard Henderson TCGv_i32 r_asi = tcg_constant_i32(da->asi); 1762c03a0fd1SRichard Henderson TCGv_i32 r_mop = tcg_constant_i32(da->memop | MO_ALIGN); 1763fcf5ef2aSThomas Huth 1764fcf5ef2aSThomas Huth save_state(dc); 1765fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64 1766ad75a51eSRichard Henderson gen_helper_st_asi(tcg_env, addr, src, r_asi, r_mop); 1767fcf5ef2aSThomas Huth #else 1768fcf5ef2aSThomas Huth { 1769fcf5ef2aSThomas Huth TCGv_i64 t64 = tcg_temp_new_i64(); 1770fcf5ef2aSThomas Huth tcg_gen_extu_tl_i64(t64, src); 1771ad75a51eSRichard Henderson gen_helper_st_asi(tcg_env, addr, t64, r_asi, r_mop); 1772fcf5ef2aSThomas Huth } 1773fcf5ef2aSThomas Huth #endif 1774fcf5ef2aSThomas Huth 1775fcf5ef2aSThomas Huth /* A write to a TLB register may alter page maps. End the TB. */ 1776fcf5ef2aSThomas Huth dc->npc = DYNAMIC_PC; 1777fcf5ef2aSThomas Huth } 1778fcf5ef2aSThomas Huth break; 1779fcf5ef2aSThomas Huth } 1780fcf5ef2aSThomas Huth } 1781fcf5ef2aSThomas Huth 1782dca544b9SRichard Henderson static void gen_swap_asi(DisasContext *dc, DisasASI *da, 1783c03a0fd1SRichard Henderson TCGv dst, TCGv src, TCGv addr) 1784c03a0fd1SRichard Henderson { 1785c03a0fd1SRichard Henderson switch (da->type) { 1786c03a0fd1SRichard Henderson case GET_ASI_EXCP: 1787c03a0fd1SRichard Henderson break; 1788c03a0fd1SRichard Henderson case GET_ASI_DIRECT: 1789dca544b9SRichard Henderson tcg_gen_atomic_xchg_tl(dst, addr, src, 1790dca544b9SRichard Henderson da->mem_idx, da->memop | MO_ALIGN); 1791c03a0fd1SRichard Henderson break; 1792c03a0fd1SRichard Henderson default: 1793c03a0fd1SRichard Henderson /* ??? Should be DAE_invalid_asi. */ 1794c03a0fd1SRichard Henderson gen_exception(dc, TT_DATA_ACCESS); 1795c03a0fd1SRichard Henderson break; 1796c03a0fd1SRichard Henderson } 1797c03a0fd1SRichard Henderson } 1798c03a0fd1SRichard Henderson 1799d0a11d25SRichard Henderson static void gen_cas_asi(DisasContext *dc, DisasASI *da, 1800c03a0fd1SRichard Henderson TCGv oldv, TCGv newv, TCGv cmpv, TCGv addr) 1801c03a0fd1SRichard Henderson { 1802c03a0fd1SRichard Henderson switch (da->type) { 1803fcf5ef2aSThomas Huth case GET_ASI_EXCP: 1804c03a0fd1SRichard Henderson return; 1805fcf5ef2aSThomas Huth case GET_ASI_DIRECT: 1806c03a0fd1SRichard Henderson tcg_gen_atomic_cmpxchg_tl(oldv, addr, cmpv, newv, 1807c03a0fd1SRichard Henderson da->mem_idx, da->memop | MO_ALIGN); 1808fcf5ef2aSThomas Huth break; 1809fcf5ef2aSThomas Huth default: 1810fcf5ef2aSThomas Huth /* ??? Should be DAE_invalid_asi. */ 1811fcf5ef2aSThomas Huth gen_exception(dc, TT_DATA_ACCESS); 1812fcf5ef2aSThomas Huth break; 1813fcf5ef2aSThomas Huth } 1814fcf5ef2aSThomas Huth } 1815fcf5ef2aSThomas Huth 1816cf07cd1eSRichard Henderson static void gen_ldstub_asi(DisasContext *dc, DisasASI *da, TCGv dst, TCGv addr) 1817c03a0fd1SRichard Henderson { 1818c03a0fd1SRichard Henderson switch (da->type) { 1819fcf5ef2aSThomas Huth case GET_ASI_EXCP: 1820fcf5ef2aSThomas Huth break; 1821fcf5ef2aSThomas Huth case GET_ASI_DIRECT: 1822cf07cd1eSRichard Henderson tcg_gen_atomic_xchg_tl(dst, addr, tcg_constant_tl(0xff), 1823cf07cd1eSRichard Henderson da->mem_idx, MO_UB); 1824fcf5ef2aSThomas Huth break; 1825fcf5ef2aSThomas Huth default: 18263db010c3SRichard Henderson /* ??? In theory, this should be raise DAE_invalid_asi. 18273db010c3SRichard Henderson But the SS-20 roms do ldstuba [%l0] #ASI_M_CTL, %o1. */ 1828af00be49SEmilio G. Cota if (tb_cflags(dc->base.tb) & CF_PARALLEL) { 1829ad75a51eSRichard Henderson gen_helper_exit_atomic(tcg_env); 18303db010c3SRichard Henderson } else { 1831c03a0fd1SRichard Henderson TCGv_i32 r_asi = tcg_constant_i32(da->asi); 183200ab7e61SRichard Henderson TCGv_i32 r_mop = tcg_constant_i32(MO_UB); 18333db010c3SRichard Henderson TCGv_i64 s64, t64; 18343db010c3SRichard Henderson 18353db010c3SRichard Henderson save_state(dc); 18363db010c3SRichard Henderson t64 = tcg_temp_new_i64(); 1837ad75a51eSRichard Henderson gen_helper_ld_asi(t64, tcg_env, addr, r_asi, r_mop); 18383db010c3SRichard Henderson 183900ab7e61SRichard Henderson s64 = tcg_constant_i64(0xff); 1840ad75a51eSRichard Henderson gen_helper_st_asi(tcg_env, addr, s64, r_asi, r_mop); 18413db010c3SRichard Henderson 18423db010c3SRichard Henderson tcg_gen_trunc_i64_tl(dst, t64); 18433db010c3SRichard Henderson 18443db010c3SRichard Henderson /* End the TB. */ 18453db010c3SRichard Henderson dc->npc = DYNAMIC_PC; 18463db010c3SRichard Henderson } 1847fcf5ef2aSThomas Huth break; 1848fcf5ef2aSThomas Huth } 1849fcf5ef2aSThomas Huth } 1850fcf5ef2aSThomas Huth 1851287b1152SRichard Henderson static void gen_ldf_asi(DisasContext *dc, DisasASI *da, MemOp orig_size, 18523259b9e2SRichard Henderson TCGv addr, int rd) 1853fcf5ef2aSThomas Huth { 18543259b9e2SRichard Henderson MemOp memop = da->memop; 18553259b9e2SRichard Henderson MemOp size = memop & MO_SIZE; 1856fcf5ef2aSThomas Huth TCGv_i32 d32; 1857fcf5ef2aSThomas Huth TCGv_i64 d64; 1858287b1152SRichard Henderson TCGv addr_tmp; 1859fcf5ef2aSThomas Huth 18603259b9e2SRichard Henderson /* TODO: Use 128-bit load/store below. */ 18613259b9e2SRichard Henderson if (size == MO_128) { 18623259b9e2SRichard Henderson memop = (memop & ~MO_SIZE) | MO_64; 18633259b9e2SRichard Henderson } 18643259b9e2SRichard Henderson 18653259b9e2SRichard Henderson switch (da->type) { 1866fcf5ef2aSThomas Huth case GET_ASI_EXCP: 1867fcf5ef2aSThomas Huth break; 1868fcf5ef2aSThomas Huth 1869fcf5ef2aSThomas Huth case GET_ASI_DIRECT: 18703259b9e2SRichard Henderson memop |= MO_ALIGN_4; 1871fcf5ef2aSThomas Huth switch (size) { 18723259b9e2SRichard Henderson case MO_32: 1873fcf5ef2aSThomas Huth d32 = gen_dest_fpr_F(dc); 18743259b9e2SRichard Henderson tcg_gen_qemu_ld_i32(d32, addr, da->mem_idx, memop); 1875fcf5ef2aSThomas Huth gen_store_fpr_F(dc, rd, d32); 1876fcf5ef2aSThomas Huth break; 18773259b9e2SRichard Henderson 18783259b9e2SRichard Henderson case MO_64: 18793259b9e2SRichard Henderson tcg_gen_qemu_ld_i64(cpu_fpr[rd / 2], addr, da->mem_idx, memop); 1880fcf5ef2aSThomas Huth break; 18813259b9e2SRichard Henderson 18823259b9e2SRichard Henderson case MO_128: 1883fcf5ef2aSThomas Huth d64 = tcg_temp_new_i64(); 18843259b9e2SRichard Henderson tcg_gen_qemu_ld_i64(d64, addr, da->mem_idx, memop); 1885287b1152SRichard Henderson addr_tmp = tcg_temp_new(); 1886287b1152SRichard Henderson tcg_gen_addi_tl(addr_tmp, addr, 8); 1887287b1152SRichard Henderson tcg_gen_qemu_ld_i64(cpu_fpr[rd / 2 + 1], addr_tmp, da->mem_idx, memop); 1888fcf5ef2aSThomas Huth tcg_gen_mov_i64(cpu_fpr[rd / 2], d64); 1889fcf5ef2aSThomas Huth break; 1890fcf5ef2aSThomas Huth default: 1891fcf5ef2aSThomas Huth g_assert_not_reached(); 1892fcf5ef2aSThomas Huth } 1893fcf5ef2aSThomas Huth break; 1894fcf5ef2aSThomas Huth 1895fcf5ef2aSThomas Huth case GET_ASI_BLOCK: 1896fcf5ef2aSThomas Huth /* Valid for lddfa on aligned registers only. */ 18973259b9e2SRichard Henderson if (orig_size == MO_64 && (rd & 7) == 0) { 1898fcf5ef2aSThomas Huth /* The first operation checks required alignment. */ 1899287b1152SRichard Henderson addr_tmp = tcg_temp_new(); 1900287b1152SRichard Henderson for (int i = 0; ; ++i) { 19013259b9e2SRichard Henderson tcg_gen_qemu_ld_i64(cpu_fpr[rd / 2 + i], addr, da->mem_idx, 19023259b9e2SRichard Henderson memop | (i == 0 ? MO_ALIGN_64 : 0)); 1903fcf5ef2aSThomas Huth if (i == 7) { 1904fcf5ef2aSThomas Huth break; 1905fcf5ef2aSThomas Huth } 1906287b1152SRichard Henderson tcg_gen_addi_tl(addr_tmp, addr, 8); 1907287b1152SRichard Henderson addr = addr_tmp; 1908fcf5ef2aSThomas Huth } 1909fcf5ef2aSThomas Huth } else { 1910fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 1911fcf5ef2aSThomas Huth } 1912fcf5ef2aSThomas Huth break; 1913fcf5ef2aSThomas Huth 1914fcf5ef2aSThomas Huth case GET_ASI_SHORT: 1915fcf5ef2aSThomas Huth /* Valid for lddfa only. */ 19163259b9e2SRichard Henderson if (orig_size == MO_64) { 19173259b9e2SRichard Henderson tcg_gen_qemu_ld_i64(cpu_fpr[rd / 2], addr, da->mem_idx, 19183259b9e2SRichard Henderson memop | MO_ALIGN); 1919fcf5ef2aSThomas Huth } else { 1920fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 1921fcf5ef2aSThomas Huth } 1922fcf5ef2aSThomas Huth break; 1923fcf5ef2aSThomas Huth 1924fcf5ef2aSThomas Huth default: 1925fcf5ef2aSThomas Huth { 19263259b9e2SRichard Henderson TCGv_i32 r_asi = tcg_constant_i32(da->asi); 19273259b9e2SRichard Henderson TCGv_i32 r_mop = tcg_constant_i32(memop | MO_ALIGN); 1928fcf5ef2aSThomas Huth 1929fcf5ef2aSThomas Huth save_state(dc); 1930fcf5ef2aSThomas Huth /* According to the table in the UA2011 manual, the only 1931fcf5ef2aSThomas Huth other asis that are valid for ldfa/lddfa/ldqfa are 1932fcf5ef2aSThomas Huth the NO_FAULT asis. We still need a helper for these, 1933fcf5ef2aSThomas Huth but we can just use the integer asi helper for them. */ 1934fcf5ef2aSThomas Huth switch (size) { 19353259b9e2SRichard Henderson case MO_32: 1936fcf5ef2aSThomas Huth d64 = tcg_temp_new_i64(); 1937ad75a51eSRichard Henderson gen_helper_ld_asi(d64, tcg_env, addr, r_asi, r_mop); 1938fcf5ef2aSThomas Huth d32 = gen_dest_fpr_F(dc); 1939fcf5ef2aSThomas Huth tcg_gen_extrl_i64_i32(d32, d64); 1940fcf5ef2aSThomas Huth gen_store_fpr_F(dc, rd, d32); 1941fcf5ef2aSThomas Huth break; 19423259b9e2SRichard Henderson case MO_64: 19433259b9e2SRichard Henderson gen_helper_ld_asi(cpu_fpr[rd / 2], tcg_env, addr, 19443259b9e2SRichard Henderson r_asi, r_mop); 1945fcf5ef2aSThomas Huth break; 19463259b9e2SRichard Henderson case MO_128: 1947fcf5ef2aSThomas Huth d64 = tcg_temp_new_i64(); 1948ad75a51eSRichard Henderson gen_helper_ld_asi(d64, tcg_env, addr, r_asi, r_mop); 1949287b1152SRichard Henderson addr_tmp = tcg_temp_new(); 1950287b1152SRichard Henderson tcg_gen_addi_tl(addr_tmp, addr, 8); 1951287b1152SRichard Henderson gen_helper_ld_asi(cpu_fpr[rd / 2 + 1], tcg_env, addr_tmp, 19523259b9e2SRichard Henderson r_asi, r_mop); 1953fcf5ef2aSThomas Huth tcg_gen_mov_i64(cpu_fpr[rd / 2], d64); 1954fcf5ef2aSThomas Huth break; 1955fcf5ef2aSThomas Huth default: 1956fcf5ef2aSThomas Huth g_assert_not_reached(); 1957fcf5ef2aSThomas Huth } 1958fcf5ef2aSThomas Huth } 1959fcf5ef2aSThomas Huth break; 1960fcf5ef2aSThomas Huth } 1961fcf5ef2aSThomas Huth } 1962fcf5ef2aSThomas Huth 1963287b1152SRichard Henderson static void gen_stf_asi(DisasContext *dc, DisasASI *da, MemOp orig_size, 19643259b9e2SRichard Henderson TCGv addr, int rd) 19653259b9e2SRichard Henderson { 19663259b9e2SRichard Henderson MemOp memop = da->memop; 19673259b9e2SRichard Henderson MemOp size = memop & MO_SIZE; 1968fcf5ef2aSThomas Huth TCGv_i32 d32; 1969287b1152SRichard Henderson TCGv addr_tmp; 1970fcf5ef2aSThomas Huth 19713259b9e2SRichard Henderson /* TODO: Use 128-bit load/store below. */ 19723259b9e2SRichard Henderson if (size == MO_128) { 19733259b9e2SRichard Henderson memop = (memop & ~MO_SIZE) | MO_64; 19743259b9e2SRichard Henderson } 19753259b9e2SRichard Henderson 19763259b9e2SRichard Henderson switch (da->type) { 1977fcf5ef2aSThomas Huth case GET_ASI_EXCP: 1978fcf5ef2aSThomas Huth break; 1979fcf5ef2aSThomas Huth 1980fcf5ef2aSThomas Huth case GET_ASI_DIRECT: 19813259b9e2SRichard Henderson memop |= MO_ALIGN_4; 1982fcf5ef2aSThomas Huth switch (size) { 19833259b9e2SRichard Henderson case MO_32: 1984fcf5ef2aSThomas Huth d32 = gen_load_fpr_F(dc, rd); 19853259b9e2SRichard Henderson tcg_gen_qemu_st_i32(d32, addr, da->mem_idx, memop | MO_ALIGN); 1986fcf5ef2aSThomas Huth break; 19873259b9e2SRichard Henderson case MO_64: 19883259b9e2SRichard Henderson tcg_gen_qemu_st_i64(cpu_fpr[rd / 2], addr, da->mem_idx, 19893259b9e2SRichard Henderson memop | MO_ALIGN_4); 1990fcf5ef2aSThomas Huth break; 19913259b9e2SRichard Henderson case MO_128: 1992fcf5ef2aSThomas Huth /* Only 4-byte alignment required. However, it is legal for the 1993fcf5ef2aSThomas Huth cpu to signal the alignment fault, and the OS trap handler is 1994fcf5ef2aSThomas Huth required to fix it up. Requiring 16-byte alignment here avoids 1995fcf5ef2aSThomas Huth having to probe the second page before performing the first 1996fcf5ef2aSThomas Huth write. */ 19973259b9e2SRichard Henderson tcg_gen_qemu_st_i64(cpu_fpr[rd / 2], addr, da->mem_idx, 19983259b9e2SRichard Henderson memop | MO_ALIGN_16); 1999287b1152SRichard Henderson addr_tmp = tcg_temp_new(); 2000287b1152SRichard Henderson tcg_gen_addi_tl(addr_tmp, addr, 8); 2001287b1152SRichard Henderson tcg_gen_qemu_st_i64(cpu_fpr[rd / 2 + 1], addr_tmp, da->mem_idx, memop); 2002fcf5ef2aSThomas Huth break; 2003fcf5ef2aSThomas Huth default: 2004fcf5ef2aSThomas Huth g_assert_not_reached(); 2005fcf5ef2aSThomas Huth } 2006fcf5ef2aSThomas Huth break; 2007fcf5ef2aSThomas Huth 2008fcf5ef2aSThomas Huth case GET_ASI_BLOCK: 2009fcf5ef2aSThomas Huth /* Valid for stdfa on aligned registers only. */ 20103259b9e2SRichard Henderson if (orig_size == MO_64 && (rd & 7) == 0) { 2011fcf5ef2aSThomas Huth /* The first operation checks required alignment. */ 2012287b1152SRichard Henderson addr_tmp = tcg_temp_new(); 2013287b1152SRichard Henderson for (int i = 0; ; ++i) { 20143259b9e2SRichard Henderson tcg_gen_qemu_st_i64(cpu_fpr[rd / 2 + i], addr, da->mem_idx, 20153259b9e2SRichard Henderson memop | (i == 0 ? MO_ALIGN_64 : 0)); 2016fcf5ef2aSThomas Huth if (i == 7) { 2017fcf5ef2aSThomas Huth break; 2018fcf5ef2aSThomas Huth } 2019287b1152SRichard Henderson tcg_gen_addi_tl(addr_tmp, addr, 8); 2020287b1152SRichard Henderson addr = addr_tmp; 2021fcf5ef2aSThomas Huth } 2022fcf5ef2aSThomas Huth } else { 2023fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 2024fcf5ef2aSThomas Huth } 2025fcf5ef2aSThomas Huth break; 2026fcf5ef2aSThomas Huth 2027fcf5ef2aSThomas Huth case GET_ASI_SHORT: 2028fcf5ef2aSThomas Huth /* Valid for stdfa only. */ 20293259b9e2SRichard Henderson if (orig_size == MO_64) { 20303259b9e2SRichard Henderson tcg_gen_qemu_st_i64(cpu_fpr[rd / 2], addr, da->mem_idx, 20313259b9e2SRichard Henderson memop | MO_ALIGN); 2032fcf5ef2aSThomas Huth } else { 2033fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 2034fcf5ef2aSThomas Huth } 2035fcf5ef2aSThomas Huth break; 2036fcf5ef2aSThomas Huth 2037fcf5ef2aSThomas Huth default: 2038fcf5ef2aSThomas Huth /* According to the table in the UA2011 manual, the only 2039fcf5ef2aSThomas Huth other asis that are valid for ldfa/lddfa/ldqfa are 2040fcf5ef2aSThomas Huth the PST* asis, which aren't currently handled. */ 2041fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN); 2042fcf5ef2aSThomas Huth break; 2043fcf5ef2aSThomas Huth } 2044fcf5ef2aSThomas Huth } 2045fcf5ef2aSThomas Huth 204642071fc1SRichard Henderson static void gen_ldda_asi(DisasContext *dc, DisasASI *da, TCGv addr, int rd) 2047fcf5ef2aSThomas Huth { 2048a76779eeSRichard Henderson TCGv hi = gen_dest_gpr(dc, rd); 2049a76779eeSRichard Henderson TCGv lo = gen_dest_gpr(dc, rd + 1); 2050fcf5ef2aSThomas Huth 2051c03a0fd1SRichard Henderson switch (da->type) { 2052fcf5ef2aSThomas Huth case GET_ASI_EXCP: 2053fcf5ef2aSThomas Huth return; 2054fcf5ef2aSThomas Huth 2055fcf5ef2aSThomas Huth case GET_ASI_DTWINX: 2056ebbbec92SRichard Henderson #ifdef TARGET_SPARC64 2057ebbbec92SRichard Henderson { 2058ebbbec92SRichard Henderson MemOp mop = (da->memop & MO_BSWAP) | MO_128 | MO_ALIGN_16; 2059ebbbec92SRichard Henderson TCGv_i128 t = tcg_temp_new_i128(); 2060ebbbec92SRichard Henderson 2061ebbbec92SRichard Henderson tcg_gen_qemu_ld_i128(t, addr, da->mem_idx, mop); 2062ebbbec92SRichard Henderson /* 2063ebbbec92SRichard Henderson * Note that LE twinx acts as if each 64-bit register result is 2064ebbbec92SRichard Henderson * byte swapped. We perform one 128-bit LE load, so must swap 2065ebbbec92SRichard Henderson * the order of the writebacks. 2066ebbbec92SRichard Henderson */ 2067ebbbec92SRichard Henderson if ((mop & MO_BSWAP) == MO_TE) { 2068ebbbec92SRichard Henderson tcg_gen_extr_i128_i64(lo, hi, t); 2069ebbbec92SRichard Henderson } else { 2070ebbbec92SRichard Henderson tcg_gen_extr_i128_i64(hi, lo, t); 2071ebbbec92SRichard Henderson } 2072ebbbec92SRichard Henderson } 2073fcf5ef2aSThomas Huth break; 2074ebbbec92SRichard Henderson #else 2075ebbbec92SRichard Henderson g_assert_not_reached(); 2076ebbbec92SRichard Henderson #endif 2077fcf5ef2aSThomas Huth 2078fcf5ef2aSThomas Huth case GET_ASI_DIRECT: 2079fcf5ef2aSThomas Huth { 2080fcf5ef2aSThomas Huth TCGv_i64 tmp = tcg_temp_new_i64(); 2081fcf5ef2aSThomas Huth 2082c03a0fd1SRichard Henderson tcg_gen_qemu_ld_i64(tmp, addr, da->mem_idx, da->memop | MO_ALIGN); 2083fcf5ef2aSThomas Huth 2084fcf5ef2aSThomas Huth /* Note that LE ldda acts as if each 32-bit register 2085fcf5ef2aSThomas Huth result is byte swapped. Having just performed one 2086fcf5ef2aSThomas Huth 64-bit bswap, we need now to swap the writebacks. */ 2087c03a0fd1SRichard Henderson if ((da->memop & MO_BSWAP) == MO_TE) { 2088a76779eeSRichard Henderson tcg_gen_extr_i64_tl(lo, hi, tmp); 2089fcf5ef2aSThomas Huth } else { 2090a76779eeSRichard Henderson tcg_gen_extr_i64_tl(hi, lo, tmp); 2091fcf5ef2aSThomas Huth } 2092fcf5ef2aSThomas Huth } 2093fcf5ef2aSThomas Huth break; 2094fcf5ef2aSThomas Huth 2095fcf5ef2aSThomas Huth default: 2096fcf5ef2aSThomas Huth /* ??? In theory we've handled all of the ASIs that are valid 2097fcf5ef2aSThomas Huth for ldda, and this should raise DAE_invalid_asi. However, 2098fcf5ef2aSThomas Huth real hardware allows others. This can be seen with e.g. 2099fcf5ef2aSThomas Huth FreeBSD 10.3 wrt ASI_IC_TAG. */ 2100fcf5ef2aSThomas Huth { 2101c03a0fd1SRichard Henderson TCGv_i32 r_asi = tcg_constant_i32(da->asi); 2102c03a0fd1SRichard Henderson TCGv_i32 r_mop = tcg_constant_i32(da->memop); 2103fcf5ef2aSThomas Huth TCGv_i64 tmp = tcg_temp_new_i64(); 2104fcf5ef2aSThomas Huth 2105fcf5ef2aSThomas Huth save_state(dc); 2106ad75a51eSRichard Henderson gen_helper_ld_asi(tmp, tcg_env, addr, r_asi, r_mop); 2107fcf5ef2aSThomas Huth 2108fcf5ef2aSThomas Huth /* See above. */ 2109c03a0fd1SRichard Henderson if ((da->memop & MO_BSWAP) == MO_TE) { 2110a76779eeSRichard Henderson tcg_gen_extr_i64_tl(lo, hi, tmp); 2111fcf5ef2aSThomas Huth } else { 2112a76779eeSRichard Henderson tcg_gen_extr_i64_tl(hi, lo, tmp); 2113fcf5ef2aSThomas Huth } 2114fcf5ef2aSThomas Huth } 2115fcf5ef2aSThomas Huth break; 2116fcf5ef2aSThomas Huth } 2117fcf5ef2aSThomas Huth 2118fcf5ef2aSThomas Huth gen_store_gpr(dc, rd, hi); 2119fcf5ef2aSThomas Huth gen_store_gpr(dc, rd + 1, lo); 2120fcf5ef2aSThomas Huth } 2121fcf5ef2aSThomas Huth 212242071fc1SRichard Henderson static void gen_stda_asi(DisasContext *dc, DisasASI *da, TCGv addr, int rd) 2123c03a0fd1SRichard Henderson { 2124c03a0fd1SRichard Henderson TCGv hi = gen_load_gpr(dc, rd); 2125fcf5ef2aSThomas Huth TCGv lo = gen_load_gpr(dc, rd + 1); 2126fcf5ef2aSThomas Huth 2127c03a0fd1SRichard Henderson switch (da->type) { 2128fcf5ef2aSThomas Huth case GET_ASI_EXCP: 2129fcf5ef2aSThomas Huth break; 2130fcf5ef2aSThomas Huth 2131fcf5ef2aSThomas Huth case GET_ASI_DTWINX: 2132ebbbec92SRichard Henderson #ifdef TARGET_SPARC64 2133ebbbec92SRichard Henderson { 2134ebbbec92SRichard Henderson MemOp mop = (da->memop & MO_BSWAP) | MO_128 | MO_ALIGN_16; 2135ebbbec92SRichard Henderson TCGv_i128 t = tcg_temp_new_i128(); 2136ebbbec92SRichard Henderson 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 store, so must swap 2140ebbbec92SRichard Henderson * the order of the construction. 2141ebbbec92SRichard Henderson */ 2142ebbbec92SRichard Henderson if ((mop & MO_BSWAP) == MO_TE) { 2143ebbbec92SRichard Henderson tcg_gen_concat_i64_i128(t, lo, hi); 2144ebbbec92SRichard Henderson } else { 2145ebbbec92SRichard Henderson tcg_gen_concat_i64_i128(t, hi, lo); 2146ebbbec92SRichard Henderson } 2147ebbbec92SRichard Henderson tcg_gen_qemu_st_i128(t, addr, da->mem_idx, mop); 2148ebbbec92SRichard Henderson } 2149fcf5ef2aSThomas Huth break; 2150ebbbec92SRichard Henderson #else 2151ebbbec92SRichard Henderson g_assert_not_reached(); 2152ebbbec92SRichard Henderson #endif 2153fcf5ef2aSThomas Huth 2154fcf5ef2aSThomas Huth case GET_ASI_DIRECT: 2155fcf5ef2aSThomas Huth { 2156fcf5ef2aSThomas Huth TCGv_i64 t64 = tcg_temp_new_i64(); 2157fcf5ef2aSThomas Huth 2158fcf5ef2aSThomas Huth /* Note that LE stda acts as if each 32-bit register result is 2159fcf5ef2aSThomas Huth byte swapped. We will perform one 64-bit LE store, so now 2160fcf5ef2aSThomas Huth we must swap the order of the construction. */ 2161c03a0fd1SRichard Henderson if ((da->memop & MO_BSWAP) == MO_TE) { 2162a76779eeSRichard Henderson tcg_gen_concat_tl_i64(t64, lo, hi); 2163fcf5ef2aSThomas Huth } else { 2164a76779eeSRichard Henderson tcg_gen_concat_tl_i64(t64, hi, lo); 2165fcf5ef2aSThomas Huth } 2166c03a0fd1SRichard Henderson tcg_gen_qemu_st_i64(t64, addr, da->mem_idx, da->memop | MO_ALIGN); 2167fcf5ef2aSThomas Huth } 2168fcf5ef2aSThomas Huth break; 2169fcf5ef2aSThomas Huth 2170a76779eeSRichard Henderson case GET_ASI_BFILL: 2171a76779eeSRichard Henderson assert(TARGET_LONG_BITS == 32); 2172a76779eeSRichard Henderson /* Store 32 bytes of T64 to ADDR. */ 2173a76779eeSRichard Henderson /* ??? The original qemu code suggests 8-byte alignment, dropping 2174a76779eeSRichard Henderson the low bits, but the only place I can see this used is in the 2175a76779eeSRichard Henderson Linux kernel with 32 byte alignment, which would make more sense 2176a76779eeSRichard Henderson as a cacheline-style operation. */ 2177a76779eeSRichard Henderson { 2178a76779eeSRichard Henderson TCGv_i64 t64 = tcg_temp_new_i64(); 2179a76779eeSRichard Henderson TCGv d_addr = tcg_temp_new(); 2180a76779eeSRichard Henderson TCGv eight = tcg_constant_tl(8); 2181a76779eeSRichard Henderson int i; 2182a76779eeSRichard Henderson 2183a76779eeSRichard Henderson tcg_gen_concat_tl_i64(t64, lo, hi); 2184a76779eeSRichard Henderson tcg_gen_andi_tl(d_addr, addr, -8); 2185a76779eeSRichard Henderson for (i = 0; i < 32; i += 8) { 2186c03a0fd1SRichard Henderson tcg_gen_qemu_st_i64(t64, d_addr, da->mem_idx, da->memop); 2187a76779eeSRichard Henderson tcg_gen_add_tl(d_addr, d_addr, eight); 2188a76779eeSRichard Henderson } 2189a76779eeSRichard Henderson } 2190a76779eeSRichard Henderson break; 2191a76779eeSRichard Henderson 2192fcf5ef2aSThomas Huth default: 2193fcf5ef2aSThomas Huth /* ??? In theory we've handled all of the ASIs that are valid 2194fcf5ef2aSThomas Huth for stda, and this should raise DAE_invalid_asi. */ 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 t64 = tcg_temp_new_i64(); 2199fcf5ef2aSThomas Huth 2200fcf5ef2aSThomas Huth /* See above. */ 2201c03a0fd1SRichard Henderson if ((da->memop & MO_BSWAP) == MO_TE) { 2202a76779eeSRichard Henderson tcg_gen_concat_tl_i64(t64, lo, hi); 2203fcf5ef2aSThomas Huth } else { 2204a76779eeSRichard Henderson tcg_gen_concat_tl_i64(t64, hi, lo); 2205fcf5ef2aSThomas Huth } 2206fcf5ef2aSThomas Huth 2207fcf5ef2aSThomas Huth save_state(dc); 2208ad75a51eSRichard Henderson gen_helper_st_asi(tcg_env, addr, t64, r_asi, r_mop); 2209fcf5ef2aSThomas Huth } 2210fcf5ef2aSThomas Huth break; 2211fcf5ef2aSThomas Huth } 2212fcf5ef2aSThomas Huth } 2213fcf5ef2aSThomas Huth 2214fcf5ef2aSThomas Huth static void gen_fmovs(DisasContext *dc, DisasCompare *cmp, int rd, int rs) 2215fcf5ef2aSThomas Huth { 2216f7ec8155SRichard Henderson #ifdef TARGET_SPARC64 2217fcf5ef2aSThomas Huth TCGv_i32 c32, zero, dst, s1, s2; 2218dd7dbfccSRichard Henderson TCGv_i64 c64 = tcg_temp_new_i64(); 2219fcf5ef2aSThomas Huth 2220fcf5ef2aSThomas Huth /* We have two choices here: extend the 32 bit data and use movcond_i64, 2221fcf5ef2aSThomas Huth or fold the comparison down to 32 bits and use movcond_i32. Choose 2222fcf5ef2aSThomas Huth the later. */ 2223fcf5ef2aSThomas Huth c32 = tcg_temp_new_i32(); 2224c8507ebfSRichard Henderson tcg_gen_setcondi_i64(cmp->cond, c64, cmp->c1, cmp->c2); 2225fcf5ef2aSThomas Huth tcg_gen_extrl_i64_i32(c32, c64); 2226fcf5ef2aSThomas Huth 2227fcf5ef2aSThomas Huth s1 = gen_load_fpr_F(dc, rs); 2228fcf5ef2aSThomas Huth s2 = gen_load_fpr_F(dc, rd); 2229fcf5ef2aSThomas Huth dst = gen_dest_fpr_F(dc); 223000ab7e61SRichard Henderson zero = tcg_constant_i32(0); 2231fcf5ef2aSThomas Huth 2232fcf5ef2aSThomas Huth tcg_gen_movcond_i32(TCG_COND_NE, dst, c32, zero, s1, s2); 2233fcf5ef2aSThomas Huth 2234fcf5ef2aSThomas Huth gen_store_fpr_F(dc, rd, dst); 2235f7ec8155SRichard Henderson #else 2236f7ec8155SRichard Henderson qemu_build_not_reached(); 2237f7ec8155SRichard Henderson #endif 2238fcf5ef2aSThomas Huth } 2239fcf5ef2aSThomas Huth 2240fcf5ef2aSThomas Huth static void gen_fmovd(DisasContext *dc, DisasCompare *cmp, int rd, int rs) 2241fcf5ef2aSThomas Huth { 2242f7ec8155SRichard Henderson #ifdef TARGET_SPARC64 2243fcf5ef2aSThomas Huth TCGv_i64 dst = gen_dest_fpr_D(dc, rd); 2244c8507ebfSRichard Henderson tcg_gen_movcond_i64(cmp->cond, dst, cmp->c1, tcg_constant_tl(cmp->c2), 2245fcf5ef2aSThomas Huth gen_load_fpr_D(dc, rs), 2246fcf5ef2aSThomas Huth gen_load_fpr_D(dc, rd)); 2247fcf5ef2aSThomas Huth gen_store_fpr_D(dc, rd, dst); 2248f7ec8155SRichard Henderson #else 2249f7ec8155SRichard Henderson qemu_build_not_reached(); 2250f7ec8155SRichard Henderson #endif 2251fcf5ef2aSThomas Huth } 2252fcf5ef2aSThomas Huth 2253fcf5ef2aSThomas Huth static void gen_fmovq(DisasContext *dc, DisasCompare *cmp, int rd, int rs) 2254fcf5ef2aSThomas Huth { 2255f7ec8155SRichard Henderson #ifdef TARGET_SPARC64 2256fcf5ef2aSThomas Huth int qd = QFPREG(rd); 2257fcf5ef2aSThomas Huth int qs = QFPREG(rs); 2258c8507ebfSRichard Henderson TCGv c2 = tcg_constant_tl(cmp->c2); 2259fcf5ef2aSThomas Huth 2260c8507ebfSRichard Henderson tcg_gen_movcond_i64(cmp->cond, cpu_fpr[qd / 2], cmp->c1, c2, 2261fcf5ef2aSThomas Huth cpu_fpr[qs / 2], cpu_fpr[qd / 2]); 2262c8507ebfSRichard Henderson tcg_gen_movcond_i64(cmp->cond, cpu_fpr[qd / 2 + 1], cmp->c1, c2, 2263fcf5ef2aSThomas Huth cpu_fpr[qs / 2 + 1], cpu_fpr[qd / 2 + 1]); 2264fcf5ef2aSThomas Huth 2265fcf5ef2aSThomas Huth gen_update_fprs_dirty(dc, qd); 2266f7ec8155SRichard Henderson #else 2267f7ec8155SRichard Henderson qemu_build_not_reached(); 2268f7ec8155SRichard Henderson #endif 2269fcf5ef2aSThomas Huth } 2270fcf5ef2aSThomas Huth 2271f7ec8155SRichard Henderson #ifdef TARGET_SPARC64 22725d617bfbSRichard Henderson static void gen_load_trap_state_at_tl(TCGv_ptr r_tsptr) 2273fcf5ef2aSThomas Huth { 2274fcf5ef2aSThomas Huth TCGv_i32 r_tl = tcg_temp_new_i32(); 2275fcf5ef2aSThomas Huth 2276fcf5ef2aSThomas Huth /* load env->tl into r_tl */ 2277ad75a51eSRichard Henderson tcg_gen_ld_i32(r_tl, tcg_env, offsetof(CPUSPARCState, tl)); 2278fcf5ef2aSThomas Huth 2279fcf5ef2aSThomas Huth /* tl = [0 ... MAXTL_MASK] where MAXTL_MASK must be power of 2 */ 2280fcf5ef2aSThomas Huth tcg_gen_andi_i32(r_tl, r_tl, MAXTL_MASK); 2281fcf5ef2aSThomas Huth 2282fcf5ef2aSThomas Huth /* calculate offset to current trap state from env->ts, reuse r_tl */ 2283fcf5ef2aSThomas Huth tcg_gen_muli_i32(r_tl, r_tl, sizeof (trap_state)); 2284ad75a51eSRichard Henderson tcg_gen_addi_ptr(r_tsptr, tcg_env, offsetof(CPUSPARCState, ts)); 2285fcf5ef2aSThomas Huth 2286fcf5ef2aSThomas Huth /* tsptr = env->ts[env->tl & MAXTL_MASK] */ 2287fcf5ef2aSThomas Huth { 2288fcf5ef2aSThomas Huth TCGv_ptr r_tl_tmp = tcg_temp_new_ptr(); 2289fcf5ef2aSThomas Huth tcg_gen_ext_i32_ptr(r_tl_tmp, r_tl); 2290fcf5ef2aSThomas Huth tcg_gen_add_ptr(r_tsptr, r_tsptr, r_tl_tmp); 2291fcf5ef2aSThomas Huth } 2292fcf5ef2aSThomas Huth } 2293fcf5ef2aSThomas Huth #endif 2294fcf5ef2aSThomas Huth 229506c060d9SRichard Henderson static int extract_dfpreg(DisasContext *dc, int x) 229606c060d9SRichard Henderson { 229706c060d9SRichard Henderson return DFPREG(x); 229806c060d9SRichard Henderson } 229906c060d9SRichard Henderson 230006c060d9SRichard Henderson static int extract_qfpreg(DisasContext *dc, int x) 230106c060d9SRichard Henderson { 230206c060d9SRichard Henderson return QFPREG(x); 230306c060d9SRichard Henderson } 230406c060d9SRichard Henderson 2305878cc677SRichard Henderson /* Include the auto-generated decoder. */ 2306878cc677SRichard Henderson #include "decode-insns.c.inc" 2307878cc677SRichard Henderson 2308878cc677SRichard Henderson #define TRANS(NAME, AVAIL, FUNC, ...) \ 2309878cc677SRichard Henderson static bool trans_##NAME(DisasContext *dc, arg_##NAME *a) \ 2310878cc677SRichard Henderson { return avail_##AVAIL(dc) && FUNC(dc, __VA_ARGS__); } 2311878cc677SRichard Henderson 2312878cc677SRichard Henderson #define avail_ALL(C) true 2313878cc677SRichard Henderson #ifdef TARGET_SPARC64 2314878cc677SRichard Henderson # define avail_32(C) false 2315af25071cSRichard Henderson # define avail_ASR17(C) false 2316d0a11d25SRichard Henderson # define avail_CASA(C) true 2317c2636853SRichard Henderson # define avail_DIV(C) true 2318b5372650SRichard Henderson # define avail_MUL(C) true 23190faef01bSRichard Henderson # define avail_POWERDOWN(C) false 2320878cc677SRichard Henderson # define avail_64(C) true 23215d617bfbSRichard Henderson # define avail_GL(C) ((C)->def->features & CPU_FEATURE_GL) 2322af25071cSRichard Henderson # define avail_HYPV(C) ((C)->def->features & CPU_FEATURE_HYPV) 2323b88ce6f2SRichard Henderson # define avail_VIS1(C) ((C)->def->features & CPU_FEATURE_VIS1) 2324b88ce6f2SRichard Henderson # define avail_VIS2(C) ((C)->def->features & CPU_FEATURE_VIS2) 2325878cc677SRichard Henderson #else 2326878cc677SRichard Henderson # define avail_32(C) true 2327af25071cSRichard Henderson # define avail_ASR17(C) ((C)->def->features & CPU_FEATURE_ASR17) 2328d0a11d25SRichard Henderson # define avail_CASA(C) ((C)->def->features & CPU_FEATURE_CASA) 2329c2636853SRichard Henderson # define avail_DIV(C) ((C)->def->features & CPU_FEATURE_DIV) 2330b5372650SRichard Henderson # define avail_MUL(C) ((C)->def->features & CPU_FEATURE_MUL) 23310faef01bSRichard Henderson # define avail_POWERDOWN(C) ((C)->def->features & CPU_FEATURE_POWERDOWN) 2332878cc677SRichard Henderson # define avail_64(C) false 23335d617bfbSRichard Henderson # define avail_GL(C) false 2334af25071cSRichard Henderson # define avail_HYPV(C) false 2335b88ce6f2SRichard Henderson # define avail_VIS1(C) false 2336b88ce6f2SRichard Henderson # define avail_VIS2(C) false 2337878cc677SRichard Henderson #endif 2338878cc677SRichard Henderson 2339878cc677SRichard Henderson /* Default case for non jump instructions. */ 2340878cc677SRichard Henderson static bool advance_pc(DisasContext *dc) 2341878cc677SRichard Henderson { 23424a8d145dSRichard Henderson TCGLabel *l1; 23434a8d145dSRichard Henderson 2344878cc677SRichard Henderson if (dc->npc & 3) { 2345878cc677SRichard Henderson switch (dc->npc) { 2346878cc677SRichard Henderson case DYNAMIC_PC: 2347878cc677SRichard Henderson case DYNAMIC_PC_LOOKUP: 2348878cc677SRichard Henderson dc->pc = dc->npc; 2349878cc677SRichard Henderson gen_op_next_insn(); 2350878cc677SRichard Henderson break; 23514a8d145dSRichard Henderson 2352878cc677SRichard Henderson case JUMP_PC: 2353878cc677SRichard Henderson /* we can do a static jump */ 23544a8d145dSRichard Henderson l1 = gen_new_label(); 23554a8d145dSRichard Henderson tcg_gen_brcondi_tl(TCG_COND_NE, cpu_cond, 0, l1); 23564a8d145dSRichard Henderson 23574a8d145dSRichard Henderson /* jump not taken */ 23584a8d145dSRichard Henderson gen_goto_tb(dc, 1, dc->jump_pc[1], dc->jump_pc[1] + 4); 23594a8d145dSRichard Henderson 23604a8d145dSRichard Henderson /* jump taken */ 23614a8d145dSRichard Henderson gen_set_label(l1); 23624a8d145dSRichard Henderson gen_goto_tb(dc, 0, dc->jump_pc[0], dc->jump_pc[0] + 4); 23634a8d145dSRichard Henderson 2364878cc677SRichard Henderson dc->base.is_jmp = DISAS_NORETURN; 2365878cc677SRichard Henderson break; 23664a8d145dSRichard Henderson 2367878cc677SRichard Henderson default: 2368878cc677SRichard Henderson g_assert_not_reached(); 2369878cc677SRichard Henderson } 2370878cc677SRichard Henderson } else { 2371878cc677SRichard Henderson dc->pc = dc->npc; 2372878cc677SRichard Henderson dc->npc = dc->npc + 4; 2373878cc677SRichard Henderson } 2374878cc677SRichard Henderson return true; 2375878cc677SRichard Henderson } 2376878cc677SRichard Henderson 23776d2a0768SRichard Henderson /* 23786d2a0768SRichard Henderson * Major opcodes 00 and 01 -- branches, call, and sethi 23796d2a0768SRichard Henderson */ 23806d2a0768SRichard Henderson 23819d4e2bc7SRichard Henderson static bool advance_jump_cond(DisasContext *dc, DisasCompare *cmp, 2382*3951b7a8SRichard Henderson bool annul, int disp) 2383276567aaSRichard Henderson { 2384*3951b7a8SRichard Henderson target_ulong dest = address_mask_i(dc, dc->pc + disp * 4); 2385c76c8045SRichard Henderson target_ulong npc; 2386c76c8045SRichard Henderson 23872d9bb237SRichard Henderson if (cmp->cond == TCG_COND_ALWAYS) { 23882d9bb237SRichard Henderson if (annul) { 23892d9bb237SRichard Henderson dc->pc = dest; 23902d9bb237SRichard Henderson dc->npc = dest + 4; 23912d9bb237SRichard Henderson } else { 23922d9bb237SRichard Henderson gen_mov_pc_npc(dc); 23932d9bb237SRichard Henderson dc->npc = dest; 23942d9bb237SRichard Henderson } 23952d9bb237SRichard Henderson return true; 23962d9bb237SRichard Henderson } 23972d9bb237SRichard Henderson 23982d9bb237SRichard Henderson if (cmp->cond == TCG_COND_NEVER) { 23992d9bb237SRichard Henderson npc = dc->npc; 24002d9bb237SRichard Henderson if (npc & 3) { 24012d9bb237SRichard Henderson gen_mov_pc_npc(dc); 24022d9bb237SRichard Henderson if (annul) { 24032d9bb237SRichard Henderson tcg_gen_addi_tl(cpu_pc, cpu_pc, 4); 24042d9bb237SRichard Henderson } 24052d9bb237SRichard Henderson tcg_gen_addi_tl(cpu_npc, cpu_pc, 4); 24062d9bb237SRichard Henderson } else { 24072d9bb237SRichard Henderson dc->pc = npc + (annul ? 4 : 0); 24082d9bb237SRichard Henderson dc->npc = dc->pc + 4; 24092d9bb237SRichard Henderson } 24102d9bb237SRichard Henderson return true; 24112d9bb237SRichard Henderson } 24122d9bb237SRichard Henderson 2413c76c8045SRichard Henderson flush_cond(dc); 2414c76c8045SRichard Henderson npc = dc->npc; 24156b3e4cc6SRichard Henderson 2416276567aaSRichard Henderson if (annul) { 24176b3e4cc6SRichard Henderson TCGLabel *l1 = gen_new_label(); 24186b3e4cc6SRichard Henderson 2419c8507ebfSRichard Henderson tcg_gen_brcondi_tl(tcg_invert_cond(cmp->cond), cmp->c1, cmp->c2, l1); 24206b3e4cc6SRichard Henderson gen_goto_tb(dc, 0, npc, dest); 24216b3e4cc6SRichard Henderson gen_set_label(l1); 24226b3e4cc6SRichard Henderson gen_goto_tb(dc, 1, npc + 4, npc + 8); 24236b3e4cc6SRichard Henderson 24246b3e4cc6SRichard Henderson dc->base.is_jmp = DISAS_NORETURN; 2425276567aaSRichard Henderson } else { 24266b3e4cc6SRichard Henderson if (npc & 3) { 24276b3e4cc6SRichard Henderson switch (npc) { 24286b3e4cc6SRichard Henderson case DYNAMIC_PC: 24296b3e4cc6SRichard Henderson case DYNAMIC_PC_LOOKUP: 24306b3e4cc6SRichard Henderson tcg_gen_mov_tl(cpu_pc, cpu_npc); 24316b3e4cc6SRichard Henderson tcg_gen_addi_tl(cpu_npc, cpu_npc, 4); 24329d4e2bc7SRichard Henderson tcg_gen_movcond_tl(cmp->cond, cpu_npc, 2433c8507ebfSRichard Henderson cmp->c1, tcg_constant_tl(cmp->c2), 24346b3e4cc6SRichard Henderson tcg_constant_tl(dest), cpu_npc); 24356b3e4cc6SRichard Henderson dc->pc = npc; 24366b3e4cc6SRichard Henderson break; 24376b3e4cc6SRichard Henderson default: 24386b3e4cc6SRichard Henderson g_assert_not_reached(); 24396b3e4cc6SRichard Henderson } 24406b3e4cc6SRichard Henderson } else { 24416b3e4cc6SRichard Henderson dc->pc = npc; 24426b3e4cc6SRichard Henderson dc->jump_pc[0] = dest; 24436b3e4cc6SRichard Henderson dc->jump_pc[1] = npc + 4; 24446b3e4cc6SRichard Henderson dc->npc = JUMP_PC; 2445dd7dbfccSRichard Henderson 2446dd7dbfccSRichard Henderson /* The condition for cpu_cond is always NE -- normalize. */ 2447dd7dbfccSRichard Henderson if (cmp->cond == TCG_COND_NE) { 2448c8507ebfSRichard Henderson tcg_gen_xori_tl(cpu_cond, cmp->c1, cmp->c2); 24499d4e2bc7SRichard Henderson } else { 2450c8507ebfSRichard Henderson tcg_gen_setcondi_tl(cmp->cond, cpu_cond, cmp->c1, cmp->c2); 24519d4e2bc7SRichard Henderson } 24526b3e4cc6SRichard Henderson } 2453276567aaSRichard Henderson } 2454276567aaSRichard Henderson return true; 2455276567aaSRichard Henderson } 2456276567aaSRichard Henderson 2457af25071cSRichard Henderson static bool raise_priv(DisasContext *dc) 2458af25071cSRichard Henderson { 2459af25071cSRichard Henderson gen_exception(dc, TT_PRIV_INSN); 2460af25071cSRichard Henderson return true; 2461af25071cSRichard Henderson } 2462af25071cSRichard Henderson 246306c060d9SRichard Henderson static bool raise_unimpfpop(DisasContext *dc) 246406c060d9SRichard Henderson { 246506c060d9SRichard Henderson gen_op_fpexception_im(dc, FSR_FTT_UNIMPFPOP); 246606c060d9SRichard Henderson return true; 246706c060d9SRichard Henderson } 246806c060d9SRichard Henderson 246906c060d9SRichard Henderson static bool gen_trap_float128(DisasContext *dc) 247006c060d9SRichard Henderson { 247106c060d9SRichard Henderson if (dc->def->features & CPU_FEATURE_FLOAT128) { 247206c060d9SRichard Henderson return false; 247306c060d9SRichard Henderson } 247406c060d9SRichard Henderson return raise_unimpfpop(dc); 247506c060d9SRichard Henderson } 247606c060d9SRichard Henderson 2477276567aaSRichard Henderson static bool do_bpcc(DisasContext *dc, arg_bcc *a) 2478276567aaSRichard Henderson { 24791ea9c62aSRichard Henderson DisasCompare cmp; 2480276567aaSRichard Henderson 24811ea9c62aSRichard Henderson gen_compare(&cmp, a->cc, a->cond, dc); 2482*3951b7a8SRichard Henderson return advance_jump_cond(dc, &cmp, a->a, a->i); 2483276567aaSRichard Henderson } 2484276567aaSRichard Henderson 2485276567aaSRichard Henderson TRANS(Bicc, ALL, do_bpcc, a) 2486276567aaSRichard Henderson TRANS(BPcc, 64, do_bpcc, a) 2487276567aaSRichard Henderson 248845196ea4SRichard Henderson static bool do_fbpfcc(DisasContext *dc, arg_bcc *a) 248945196ea4SRichard Henderson { 2490d5471936SRichard Henderson DisasCompare cmp; 249145196ea4SRichard Henderson 249245196ea4SRichard Henderson if (gen_trap_ifnofpu(dc)) { 249345196ea4SRichard Henderson return true; 249445196ea4SRichard Henderson } 2495d5471936SRichard Henderson gen_fcompare(&cmp, a->cc, a->cond); 2496*3951b7a8SRichard Henderson return advance_jump_cond(dc, &cmp, a->a, a->i); 249745196ea4SRichard Henderson } 249845196ea4SRichard Henderson 249945196ea4SRichard Henderson TRANS(FBPfcc, 64, do_fbpfcc, a) 250045196ea4SRichard Henderson TRANS(FBfcc, ALL, do_fbpfcc, a) 250145196ea4SRichard Henderson 2502ab9ffe98SRichard Henderson static bool trans_BPr(DisasContext *dc, arg_BPr *a) 2503ab9ffe98SRichard Henderson { 2504ab9ffe98SRichard Henderson DisasCompare cmp; 2505ab9ffe98SRichard Henderson 2506ab9ffe98SRichard Henderson if (!avail_64(dc)) { 2507ab9ffe98SRichard Henderson return false; 2508ab9ffe98SRichard Henderson } 2509ab9ffe98SRichard Henderson if (gen_tcg_cond_reg[a->cond] == TCG_COND_NEVER) { 2510ab9ffe98SRichard Henderson return false; 2511ab9ffe98SRichard Henderson } 2512ab9ffe98SRichard Henderson 2513ab9ffe98SRichard Henderson gen_compare_reg(&cmp, a->cond, gen_load_gpr(dc, a->rs1)); 2514*3951b7a8SRichard Henderson return advance_jump_cond(dc, &cmp, a->a, a->i); 2515ab9ffe98SRichard Henderson } 2516ab9ffe98SRichard Henderson 251723ada1b1SRichard Henderson static bool trans_CALL(DisasContext *dc, arg_CALL *a) 251823ada1b1SRichard Henderson { 251923ada1b1SRichard Henderson target_long target = address_mask_i(dc, dc->pc + a->i * 4); 252023ada1b1SRichard Henderson 252123ada1b1SRichard Henderson gen_store_gpr(dc, 15, tcg_constant_tl(dc->pc)); 252223ada1b1SRichard Henderson gen_mov_pc_npc(dc); 252323ada1b1SRichard Henderson dc->npc = target; 252423ada1b1SRichard Henderson return true; 252523ada1b1SRichard Henderson } 252623ada1b1SRichard Henderson 252745196ea4SRichard Henderson static bool trans_NCP(DisasContext *dc, arg_NCP *a) 252845196ea4SRichard Henderson { 252945196ea4SRichard Henderson /* 253045196ea4SRichard Henderson * For sparc32, always generate the no-coprocessor exception. 253145196ea4SRichard Henderson * For sparc64, always generate illegal instruction. 253245196ea4SRichard Henderson */ 253345196ea4SRichard Henderson #ifdef TARGET_SPARC64 253445196ea4SRichard Henderson return false; 253545196ea4SRichard Henderson #else 253645196ea4SRichard Henderson gen_exception(dc, TT_NCP_INSN); 253745196ea4SRichard Henderson return true; 253845196ea4SRichard Henderson #endif 253945196ea4SRichard Henderson } 254045196ea4SRichard Henderson 25416d2a0768SRichard Henderson static bool trans_SETHI(DisasContext *dc, arg_SETHI *a) 25426d2a0768SRichard Henderson { 25436d2a0768SRichard Henderson /* Special-case %g0 because that's the canonical nop. */ 25446d2a0768SRichard Henderson if (a->rd) { 25456d2a0768SRichard Henderson gen_store_gpr(dc, a->rd, tcg_constant_tl((uint32_t)a->i << 10)); 25466d2a0768SRichard Henderson } 25476d2a0768SRichard Henderson return advance_pc(dc); 25486d2a0768SRichard Henderson } 25496d2a0768SRichard Henderson 25500faef01bSRichard Henderson /* 25510faef01bSRichard Henderson * Major Opcode 10 -- integer, floating-point, vis, and system insns. 25520faef01bSRichard Henderson */ 25530faef01bSRichard Henderson 255430376636SRichard Henderson static bool do_tcc(DisasContext *dc, int cond, int cc, 255530376636SRichard Henderson int rs1, bool imm, int rs2_or_imm) 255630376636SRichard Henderson { 255730376636SRichard Henderson int mask = ((dc->def->features & CPU_FEATURE_HYPV) && supervisor(dc) 255830376636SRichard Henderson ? UA2005_HTRAP_MASK : V8_TRAP_MASK); 255930376636SRichard Henderson DisasCompare cmp; 256030376636SRichard Henderson TCGLabel *lab; 256130376636SRichard Henderson TCGv_i32 trap; 256230376636SRichard Henderson 256330376636SRichard Henderson /* Trap never. */ 256430376636SRichard Henderson if (cond == 0) { 256530376636SRichard Henderson return advance_pc(dc); 256630376636SRichard Henderson } 256730376636SRichard Henderson 256830376636SRichard Henderson /* 256930376636SRichard Henderson * Immediate traps are the most common case. Since this value is 257030376636SRichard Henderson * live across the branch, it really pays to evaluate the constant. 257130376636SRichard Henderson */ 257230376636SRichard Henderson if (rs1 == 0 && (imm || rs2_or_imm == 0)) { 257330376636SRichard Henderson trap = tcg_constant_i32((rs2_or_imm & mask) + TT_TRAP); 257430376636SRichard Henderson } else { 257530376636SRichard Henderson trap = tcg_temp_new_i32(); 257630376636SRichard Henderson tcg_gen_trunc_tl_i32(trap, gen_load_gpr(dc, rs1)); 257730376636SRichard Henderson if (imm) { 257830376636SRichard Henderson tcg_gen_addi_i32(trap, trap, rs2_or_imm); 257930376636SRichard Henderson } else { 258030376636SRichard Henderson TCGv_i32 t2 = tcg_temp_new_i32(); 258130376636SRichard Henderson tcg_gen_trunc_tl_i32(t2, gen_load_gpr(dc, rs2_or_imm)); 258230376636SRichard Henderson tcg_gen_add_i32(trap, trap, t2); 258330376636SRichard Henderson } 258430376636SRichard Henderson tcg_gen_andi_i32(trap, trap, mask); 258530376636SRichard Henderson tcg_gen_addi_i32(trap, trap, TT_TRAP); 258630376636SRichard Henderson } 258730376636SRichard Henderson 258830376636SRichard Henderson /* Trap always. */ 258930376636SRichard Henderson if (cond == 8) { 259030376636SRichard Henderson save_state(dc); 259130376636SRichard Henderson gen_helper_raise_exception(tcg_env, trap); 259230376636SRichard Henderson dc->base.is_jmp = DISAS_NORETURN; 259330376636SRichard Henderson return true; 259430376636SRichard Henderson } 259530376636SRichard Henderson 259630376636SRichard Henderson /* Conditional trap. */ 259730376636SRichard Henderson flush_cond(dc); 259830376636SRichard Henderson lab = delay_exceptionv(dc, trap); 259930376636SRichard Henderson gen_compare(&cmp, cc, cond, dc); 2600c8507ebfSRichard Henderson tcg_gen_brcondi_tl(cmp.cond, cmp.c1, cmp.c2, lab); 260130376636SRichard Henderson 260230376636SRichard Henderson return advance_pc(dc); 260330376636SRichard Henderson } 260430376636SRichard Henderson 260530376636SRichard Henderson static bool trans_Tcc_r(DisasContext *dc, arg_Tcc_r *a) 260630376636SRichard Henderson { 260730376636SRichard Henderson if (avail_32(dc) && a->cc) { 260830376636SRichard Henderson return false; 260930376636SRichard Henderson } 261030376636SRichard Henderson return do_tcc(dc, a->cond, a->cc, a->rs1, false, a->rs2); 261130376636SRichard Henderson } 261230376636SRichard Henderson 261330376636SRichard Henderson static bool trans_Tcc_i_v7(DisasContext *dc, arg_Tcc_i_v7 *a) 261430376636SRichard Henderson { 261530376636SRichard Henderson if (avail_64(dc)) { 261630376636SRichard Henderson return false; 261730376636SRichard Henderson } 261830376636SRichard Henderson return do_tcc(dc, a->cond, 0, a->rs1, true, a->i); 261930376636SRichard Henderson } 262030376636SRichard Henderson 262130376636SRichard Henderson static bool trans_Tcc_i_v9(DisasContext *dc, arg_Tcc_i_v9 *a) 262230376636SRichard Henderson { 262330376636SRichard Henderson if (avail_32(dc)) { 262430376636SRichard Henderson return false; 262530376636SRichard Henderson } 262630376636SRichard Henderson return do_tcc(dc, a->cond, a->cc, a->rs1, true, a->i); 262730376636SRichard Henderson } 262830376636SRichard Henderson 2629af25071cSRichard Henderson static bool trans_STBAR(DisasContext *dc, arg_STBAR *a) 2630af25071cSRichard Henderson { 2631af25071cSRichard Henderson tcg_gen_mb(TCG_MO_ST_ST | TCG_BAR_SC); 2632af25071cSRichard Henderson return advance_pc(dc); 2633af25071cSRichard Henderson } 2634af25071cSRichard Henderson 2635af25071cSRichard Henderson static bool trans_MEMBAR(DisasContext *dc, arg_MEMBAR *a) 2636af25071cSRichard Henderson { 2637af25071cSRichard Henderson if (avail_32(dc)) { 2638af25071cSRichard Henderson return false; 2639af25071cSRichard Henderson } 2640af25071cSRichard Henderson if (a->mmask) { 2641af25071cSRichard Henderson /* Note TCG_MO_* was modeled on sparc64, so mmask matches. */ 2642af25071cSRichard Henderson tcg_gen_mb(a->mmask | TCG_BAR_SC); 2643af25071cSRichard Henderson } 2644af25071cSRichard Henderson if (a->cmask) { 2645af25071cSRichard Henderson /* For #Sync, etc, end the TB to recognize interrupts. */ 2646af25071cSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 2647af25071cSRichard Henderson } 2648af25071cSRichard Henderson return advance_pc(dc); 2649af25071cSRichard Henderson } 2650af25071cSRichard Henderson 2651af25071cSRichard Henderson static bool do_rd_special(DisasContext *dc, bool priv, int rd, 2652af25071cSRichard Henderson TCGv (*func)(DisasContext *, TCGv)) 2653af25071cSRichard Henderson { 2654af25071cSRichard Henderson if (!priv) { 2655af25071cSRichard Henderson return raise_priv(dc); 2656af25071cSRichard Henderson } 2657af25071cSRichard Henderson gen_store_gpr(dc, rd, func(dc, gen_dest_gpr(dc, rd))); 2658af25071cSRichard Henderson return advance_pc(dc); 2659af25071cSRichard Henderson } 2660af25071cSRichard Henderson 2661af25071cSRichard Henderson static TCGv do_rdy(DisasContext *dc, TCGv dst) 2662af25071cSRichard Henderson { 2663af25071cSRichard Henderson return cpu_y; 2664af25071cSRichard Henderson } 2665af25071cSRichard Henderson 2666af25071cSRichard Henderson static bool trans_RDY(DisasContext *dc, arg_RDY *a) 2667af25071cSRichard Henderson { 2668af25071cSRichard Henderson /* 2669af25071cSRichard Henderson * TODO: Need a feature bit for sparcv8. In the meantime, treat all 2670af25071cSRichard Henderson * 32-bit cpus like sparcv7, which ignores the rs1 field. 2671af25071cSRichard Henderson * This matches after all other ASR, so Leon3 Asr17 is handled first. 2672af25071cSRichard Henderson */ 2673af25071cSRichard Henderson if (avail_64(dc) && a->rs1 != 0) { 2674af25071cSRichard Henderson return false; 2675af25071cSRichard Henderson } 2676af25071cSRichard Henderson return do_rd_special(dc, true, a->rd, do_rdy); 2677af25071cSRichard Henderson } 2678af25071cSRichard Henderson 2679af25071cSRichard Henderson static TCGv do_rd_leon3_config(DisasContext *dc, TCGv dst) 2680af25071cSRichard Henderson { 2681af25071cSRichard Henderson uint32_t val; 2682af25071cSRichard Henderson 2683af25071cSRichard Henderson /* 2684af25071cSRichard Henderson * TODO: There are many more fields to be filled, 2685af25071cSRichard Henderson * some of which are writable. 2686af25071cSRichard Henderson */ 2687af25071cSRichard Henderson val = dc->def->nwindows - 1; /* [4:0] NWIN */ 2688af25071cSRichard Henderson val |= 1 << 8; /* [8] V8 */ 2689af25071cSRichard Henderson 2690af25071cSRichard Henderson return tcg_constant_tl(val); 2691af25071cSRichard Henderson } 2692af25071cSRichard Henderson 2693af25071cSRichard Henderson TRANS(RDASR17, ASR17, do_rd_special, true, a->rd, do_rd_leon3_config) 2694af25071cSRichard Henderson 2695af25071cSRichard Henderson static TCGv do_rdccr(DisasContext *dc, TCGv dst) 2696af25071cSRichard Henderson { 2697af25071cSRichard Henderson gen_helper_rdccr(dst, tcg_env); 2698af25071cSRichard Henderson return dst; 2699af25071cSRichard Henderson } 2700af25071cSRichard Henderson 2701af25071cSRichard Henderson TRANS(RDCCR, 64, do_rd_special, true, a->rd, do_rdccr) 2702af25071cSRichard Henderson 2703af25071cSRichard Henderson static TCGv do_rdasi(DisasContext *dc, TCGv dst) 2704af25071cSRichard Henderson { 2705af25071cSRichard Henderson #ifdef TARGET_SPARC64 2706af25071cSRichard Henderson return tcg_constant_tl(dc->asi); 2707af25071cSRichard Henderson #else 2708af25071cSRichard Henderson qemu_build_not_reached(); 2709af25071cSRichard Henderson #endif 2710af25071cSRichard Henderson } 2711af25071cSRichard Henderson 2712af25071cSRichard Henderson TRANS(RDASI, 64, do_rd_special, true, a->rd, do_rdasi) 2713af25071cSRichard Henderson 2714af25071cSRichard Henderson static TCGv do_rdtick(DisasContext *dc, TCGv dst) 2715af25071cSRichard Henderson { 2716af25071cSRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr(); 2717af25071cSRichard Henderson 2718af25071cSRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(tick)); 2719af25071cSRichard Henderson if (translator_io_start(&dc->base)) { 2720af25071cSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 2721af25071cSRichard Henderson } 2722af25071cSRichard Henderson gen_helper_tick_get_count(dst, tcg_env, r_tickptr, 2723af25071cSRichard Henderson tcg_constant_i32(dc->mem_idx)); 2724af25071cSRichard Henderson return dst; 2725af25071cSRichard Henderson } 2726af25071cSRichard Henderson 2727af25071cSRichard Henderson /* TODO: non-priv access only allowed when enabled. */ 2728af25071cSRichard Henderson TRANS(RDTICK, 64, do_rd_special, true, a->rd, do_rdtick) 2729af25071cSRichard Henderson 2730af25071cSRichard Henderson static TCGv do_rdpc(DisasContext *dc, TCGv dst) 2731af25071cSRichard Henderson { 2732af25071cSRichard Henderson return tcg_constant_tl(address_mask_i(dc, dc->pc)); 2733af25071cSRichard Henderson } 2734af25071cSRichard Henderson 2735af25071cSRichard Henderson TRANS(RDPC, 64, do_rd_special, true, a->rd, do_rdpc) 2736af25071cSRichard Henderson 2737af25071cSRichard Henderson static TCGv do_rdfprs(DisasContext *dc, TCGv dst) 2738af25071cSRichard Henderson { 2739af25071cSRichard Henderson tcg_gen_ext_i32_tl(dst, cpu_fprs); 2740af25071cSRichard Henderson return dst; 2741af25071cSRichard Henderson } 2742af25071cSRichard Henderson 2743af25071cSRichard Henderson TRANS(RDFPRS, 64, do_rd_special, true, a->rd, do_rdfprs) 2744af25071cSRichard Henderson 2745af25071cSRichard Henderson static TCGv do_rdgsr(DisasContext *dc, TCGv dst) 2746af25071cSRichard Henderson { 2747af25071cSRichard Henderson gen_trap_ifnofpu(dc); 2748af25071cSRichard Henderson return cpu_gsr; 2749af25071cSRichard Henderson } 2750af25071cSRichard Henderson 2751af25071cSRichard Henderson TRANS(RDGSR, 64, do_rd_special, true, a->rd, do_rdgsr) 2752af25071cSRichard Henderson 2753af25071cSRichard Henderson static TCGv do_rdsoftint(DisasContext *dc, TCGv dst) 2754af25071cSRichard Henderson { 2755af25071cSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(softint)); 2756af25071cSRichard Henderson return dst; 2757af25071cSRichard Henderson } 2758af25071cSRichard Henderson 2759af25071cSRichard Henderson TRANS(RDSOFTINT, 64, do_rd_special, supervisor(dc), a->rd, do_rdsoftint) 2760af25071cSRichard Henderson 2761af25071cSRichard Henderson static TCGv do_rdtick_cmpr(DisasContext *dc, TCGv dst) 2762af25071cSRichard Henderson { 2763577efa45SRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(tick_cmpr)); 2764577efa45SRichard Henderson return dst; 2765af25071cSRichard Henderson } 2766af25071cSRichard Henderson 2767af25071cSRichard Henderson /* TODO: non-priv access only allowed when enabled. */ 2768af25071cSRichard Henderson TRANS(RDTICK_CMPR, 64, do_rd_special, true, a->rd, do_rdtick_cmpr) 2769af25071cSRichard Henderson 2770af25071cSRichard Henderson static TCGv do_rdstick(DisasContext *dc, TCGv dst) 2771af25071cSRichard Henderson { 2772af25071cSRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr(); 2773af25071cSRichard Henderson 2774af25071cSRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(stick)); 2775af25071cSRichard Henderson if (translator_io_start(&dc->base)) { 2776af25071cSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 2777af25071cSRichard Henderson } 2778af25071cSRichard Henderson gen_helper_tick_get_count(dst, tcg_env, r_tickptr, 2779af25071cSRichard Henderson tcg_constant_i32(dc->mem_idx)); 2780af25071cSRichard Henderson return dst; 2781af25071cSRichard Henderson } 2782af25071cSRichard Henderson 2783af25071cSRichard Henderson /* TODO: non-priv access only allowed when enabled. */ 2784af25071cSRichard Henderson TRANS(RDSTICK, 64, do_rd_special, true, a->rd, do_rdstick) 2785af25071cSRichard Henderson 2786af25071cSRichard Henderson static TCGv do_rdstick_cmpr(DisasContext *dc, TCGv dst) 2787af25071cSRichard Henderson { 2788577efa45SRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(stick_cmpr)); 2789577efa45SRichard Henderson return dst; 2790af25071cSRichard Henderson } 2791af25071cSRichard Henderson 2792af25071cSRichard Henderson /* TODO: supervisor access only allowed when enabled by hypervisor. */ 2793af25071cSRichard Henderson TRANS(RDSTICK_CMPR, 64, do_rd_special, supervisor(dc), a->rd, do_rdstick_cmpr) 2794af25071cSRichard Henderson 2795af25071cSRichard Henderson /* 2796af25071cSRichard Henderson * UltraSPARC-T1 Strand status. 2797af25071cSRichard Henderson * HYPV check maybe not enough, UA2005 & UA2007 describe 2798af25071cSRichard Henderson * this ASR as impl. dep 2799af25071cSRichard Henderson */ 2800af25071cSRichard Henderson static TCGv do_rdstrand_status(DisasContext *dc, TCGv dst) 2801af25071cSRichard Henderson { 2802af25071cSRichard Henderson return tcg_constant_tl(1); 2803af25071cSRichard Henderson } 2804af25071cSRichard Henderson 2805af25071cSRichard Henderson TRANS(RDSTRAND_STATUS, HYPV, do_rd_special, true, a->rd, do_rdstrand_status) 2806af25071cSRichard Henderson 2807668bb9b7SRichard Henderson static TCGv do_rdpsr(DisasContext *dc, TCGv dst) 2808668bb9b7SRichard Henderson { 2809668bb9b7SRichard Henderson gen_helper_rdpsr(dst, tcg_env); 2810668bb9b7SRichard Henderson return dst; 2811668bb9b7SRichard Henderson } 2812668bb9b7SRichard Henderson 2813668bb9b7SRichard Henderson TRANS(RDPSR, 32, do_rd_special, supervisor(dc), a->rd, do_rdpsr) 2814668bb9b7SRichard Henderson 2815668bb9b7SRichard Henderson static TCGv do_rdhpstate(DisasContext *dc, TCGv dst) 2816668bb9b7SRichard Henderson { 2817668bb9b7SRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hpstate)); 2818668bb9b7SRichard Henderson return dst; 2819668bb9b7SRichard Henderson } 2820668bb9b7SRichard Henderson 2821668bb9b7SRichard Henderson TRANS(RDHPR_hpstate, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhpstate) 2822668bb9b7SRichard Henderson 2823668bb9b7SRichard Henderson static TCGv do_rdhtstate(DisasContext *dc, TCGv dst) 2824668bb9b7SRichard Henderson { 2825668bb9b7SRichard Henderson TCGv_i32 tl = tcg_temp_new_i32(); 2826668bb9b7SRichard Henderson TCGv_ptr tp = tcg_temp_new_ptr(); 2827668bb9b7SRichard Henderson 2828668bb9b7SRichard Henderson tcg_gen_ld_i32(tl, tcg_env, env64_field_offsetof(tl)); 2829668bb9b7SRichard Henderson tcg_gen_andi_i32(tl, tl, MAXTL_MASK); 2830668bb9b7SRichard Henderson tcg_gen_shli_i32(tl, tl, 3); 2831668bb9b7SRichard Henderson tcg_gen_ext_i32_ptr(tp, tl); 2832668bb9b7SRichard Henderson tcg_gen_add_ptr(tp, tp, tcg_env); 2833668bb9b7SRichard Henderson 2834668bb9b7SRichard Henderson tcg_gen_ld_tl(dst, tp, env64_field_offsetof(htstate)); 2835668bb9b7SRichard Henderson return dst; 2836668bb9b7SRichard Henderson } 2837668bb9b7SRichard Henderson 2838668bb9b7SRichard Henderson TRANS(RDHPR_htstate, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhtstate) 2839668bb9b7SRichard Henderson 2840668bb9b7SRichard Henderson static TCGv do_rdhintp(DisasContext *dc, TCGv dst) 2841668bb9b7SRichard Henderson { 28422da789deSRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hintp)); 28432da789deSRichard Henderson return dst; 2844668bb9b7SRichard Henderson } 2845668bb9b7SRichard Henderson 2846668bb9b7SRichard Henderson TRANS(RDHPR_hintp, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhintp) 2847668bb9b7SRichard Henderson 2848668bb9b7SRichard Henderson static TCGv do_rdhtba(DisasContext *dc, TCGv dst) 2849668bb9b7SRichard Henderson { 28502da789deSRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(htba)); 28512da789deSRichard Henderson return dst; 2852668bb9b7SRichard Henderson } 2853668bb9b7SRichard Henderson 2854668bb9b7SRichard Henderson TRANS(RDHPR_htba, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhtba) 2855668bb9b7SRichard Henderson 2856668bb9b7SRichard Henderson static TCGv do_rdhver(DisasContext *dc, TCGv dst) 2857668bb9b7SRichard Henderson { 28582da789deSRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hver)); 28592da789deSRichard Henderson return dst; 2860668bb9b7SRichard Henderson } 2861668bb9b7SRichard Henderson 2862668bb9b7SRichard Henderson TRANS(RDHPR_hver, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhver) 2863668bb9b7SRichard Henderson 2864668bb9b7SRichard Henderson static TCGv do_rdhstick_cmpr(DisasContext *dc, TCGv dst) 2865668bb9b7SRichard Henderson { 2866577efa45SRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hstick_cmpr)); 2867577efa45SRichard Henderson return dst; 2868668bb9b7SRichard Henderson } 2869668bb9b7SRichard Henderson 2870668bb9b7SRichard Henderson TRANS(RDHPR_hstick_cmpr, HYPV, do_rd_special, hypervisor(dc), a->rd, 2871668bb9b7SRichard Henderson do_rdhstick_cmpr) 2872668bb9b7SRichard Henderson 28735d617bfbSRichard Henderson static TCGv do_rdwim(DisasContext *dc, TCGv dst) 28745d617bfbSRichard Henderson { 2875cd6269f7SRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env32_field_offsetof(wim)); 2876cd6269f7SRichard Henderson return dst; 28775d617bfbSRichard Henderson } 28785d617bfbSRichard Henderson 28795d617bfbSRichard Henderson TRANS(RDWIM, 32, do_rd_special, supervisor(dc), a->rd, do_rdwim) 28805d617bfbSRichard Henderson 28815d617bfbSRichard Henderson static TCGv do_rdtpc(DisasContext *dc, TCGv dst) 28825d617bfbSRichard Henderson { 28835d617bfbSRichard Henderson #ifdef TARGET_SPARC64 28845d617bfbSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 28855d617bfbSRichard Henderson 28865d617bfbSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 28875d617bfbSRichard Henderson tcg_gen_ld_tl(dst, r_tsptr, offsetof(trap_state, tpc)); 28885d617bfbSRichard Henderson return dst; 28895d617bfbSRichard Henderson #else 28905d617bfbSRichard Henderson qemu_build_not_reached(); 28915d617bfbSRichard Henderson #endif 28925d617bfbSRichard Henderson } 28935d617bfbSRichard Henderson 28945d617bfbSRichard Henderson TRANS(RDPR_tpc, 64, do_rd_special, supervisor(dc), a->rd, do_rdtpc) 28955d617bfbSRichard Henderson 28965d617bfbSRichard Henderson static TCGv do_rdtnpc(DisasContext *dc, TCGv dst) 28975d617bfbSRichard Henderson { 28985d617bfbSRichard Henderson #ifdef TARGET_SPARC64 28995d617bfbSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 29005d617bfbSRichard Henderson 29015d617bfbSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 29025d617bfbSRichard Henderson tcg_gen_ld_tl(dst, r_tsptr, offsetof(trap_state, tnpc)); 29035d617bfbSRichard Henderson return dst; 29045d617bfbSRichard Henderson #else 29055d617bfbSRichard Henderson qemu_build_not_reached(); 29065d617bfbSRichard Henderson #endif 29075d617bfbSRichard Henderson } 29085d617bfbSRichard Henderson 29095d617bfbSRichard Henderson TRANS(RDPR_tnpc, 64, do_rd_special, supervisor(dc), a->rd, do_rdtnpc) 29105d617bfbSRichard Henderson 29115d617bfbSRichard Henderson static TCGv do_rdtstate(DisasContext *dc, TCGv dst) 29125d617bfbSRichard Henderson { 29135d617bfbSRichard Henderson #ifdef TARGET_SPARC64 29145d617bfbSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 29155d617bfbSRichard Henderson 29165d617bfbSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 29175d617bfbSRichard Henderson tcg_gen_ld_tl(dst, r_tsptr, offsetof(trap_state, tstate)); 29185d617bfbSRichard Henderson return dst; 29195d617bfbSRichard Henderson #else 29205d617bfbSRichard Henderson qemu_build_not_reached(); 29215d617bfbSRichard Henderson #endif 29225d617bfbSRichard Henderson } 29235d617bfbSRichard Henderson 29245d617bfbSRichard Henderson TRANS(RDPR_tstate, 64, do_rd_special, supervisor(dc), a->rd, do_rdtstate) 29255d617bfbSRichard Henderson 29265d617bfbSRichard Henderson static TCGv do_rdtt(DisasContext *dc, TCGv dst) 29275d617bfbSRichard Henderson { 29285d617bfbSRichard Henderson #ifdef TARGET_SPARC64 29295d617bfbSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 29305d617bfbSRichard Henderson 29315d617bfbSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 29325d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, r_tsptr, offsetof(trap_state, tt)); 29335d617bfbSRichard Henderson return dst; 29345d617bfbSRichard Henderson #else 29355d617bfbSRichard Henderson qemu_build_not_reached(); 29365d617bfbSRichard Henderson #endif 29375d617bfbSRichard Henderson } 29385d617bfbSRichard Henderson 29395d617bfbSRichard Henderson TRANS(RDPR_tt, 64, do_rd_special, supervisor(dc), a->rd, do_rdtt) 29405d617bfbSRichard Henderson TRANS(RDPR_tick, 64, do_rd_special, supervisor(dc), a->rd, do_rdtick) 29415d617bfbSRichard Henderson 29425d617bfbSRichard Henderson static TCGv do_rdtba(DisasContext *dc, TCGv dst) 29435d617bfbSRichard Henderson { 29445d617bfbSRichard Henderson return cpu_tbr; 29455d617bfbSRichard Henderson } 29465d617bfbSRichard Henderson 2947e8325dc0SRichard Henderson TRANS(RDTBR, 32, do_rd_special, supervisor(dc), a->rd, do_rdtba) 29485d617bfbSRichard Henderson TRANS(RDPR_tba, 64, do_rd_special, supervisor(dc), a->rd, do_rdtba) 29495d617bfbSRichard Henderson 29505d617bfbSRichard Henderson static TCGv do_rdpstate(DisasContext *dc, TCGv dst) 29515d617bfbSRichard Henderson { 29525d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(pstate)); 29535d617bfbSRichard Henderson return dst; 29545d617bfbSRichard Henderson } 29555d617bfbSRichard Henderson 29565d617bfbSRichard Henderson TRANS(RDPR_pstate, 64, do_rd_special, supervisor(dc), a->rd, do_rdpstate) 29575d617bfbSRichard Henderson 29585d617bfbSRichard Henderson static TCGv do_rdtl(DisasContext *dc, TCGv dst) 29595d617bfbSRichard Henderson { 29605d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(tl)); 29615d617bfbSRichard Henderson return dst; 29625d617bfbSRichard Henderson } 29635d617bfbSRichard Henderson 29645d617bfbSRichard Henderson TRANS(RDPR_tl, 64, do_rd_special, supervisor(dc), a->rd, do_rdtl) 29655d617bfbSRichard Henderson 29665d617bfbSRichard Henderson static TCGv do_rdpil(DisasContext *dc, TCGv dst) 29675d617bfbSRichard Henderson { 29685d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env_field_offsetof(psrpil)); 29695d617bfbSRichard Henderson return dst; 29705d617bfbSRichard Henderson } 29715d617bfbSRichard Henderson 29725d617bfbSRichard Henderson TRANS(RDPR_pil, 64, do_rd_special, supervisor(dc), a->rd, do_rdpil) 29735d617bfbSRichard Henderson 29745d617bfbSRichard Henderson static TCGv do_rdcwp(DisasContext *dc, TCGv dst) 29755d617bfbSRichard Henderson { 29765d617bfbSRichard Henderson gen_helper_rdcwp(dst, tcg_env); 29775d617bfbSRichard Henderson return dst; 29785d617bfbSRichard Henderson } 29795d617bfbSRichard Henderson 29805d617bfbSRichard Henderson TRANS(RDPR_cwp, 64, do_rd_special, supervisor(dc), a->rd, do_rdcwp) 29815d617bfbSRichard Henderson 29825d617bfbSRichard Henderson static TCGv do_rdcansave(DisasContext *dc, TCGv dst) 29835d617bfbSRichard Henderson { 29845d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(cansave)); 29855d617bfbSRichard Henderson return dst; 29865d617bfbSRichard Henderson } 29875d617bfbSRichard Henderson 29885d617bfbSRichard Henderson TRANS(RDPR_cansave, 64, do_rd_special, supervisor(dc), a->rd, do_rdcansave) 29895d617bfbSRichard Henderson 29905d617bfbSRichard Henderson static TCGv do_rdcanrestore(DisasContext *dc, TCGv dst) 29915d617bfbSRichard Henderson { 29925d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(canrestore)); 29935d617bfbSRichard Henderson return dst; 29945d617bfbSRichard Henderson } 29955d617bfbSRichard Henderson 29965d617bfbSRichard Henderson TRANS(RDPR_canrestore, 64, do_rd_special, supervisor(dc), a->rd, 29975d617bfbSRichard Henderson do_rdcanrestore) 29985d617bfbSRichard Henderson 29995d617bfbSRichard Henderson static TCGv do_rdcleanwin(DisasContext *dc, TCGv dst) 30005d617bfbSRichard Henderson { 30015d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(cleanwin)); 30025d617bfbSRichard Henderson return dst; 30035d617bfbSRichard Henderson } 30045d617bfbSRichard Henderson 30055d617bfbSRichard Henderson TRANS(RDPR_cleanwin, 64, do_rd_special, supervisor(dc), a->rd, do_rdcleanwin) 30065d617bfbSRichard Henderson 30075d617bfbSRichard Henderson static TCGv do_rdotherwin(DisasContext *dc, TCGv dst) 30085d617bfbSRichard Henderson { 30095d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(otherwin)); 30105d617bfbSRichard Henderson return dst; 30115d617bfbSRichard Henderson } 30125d617bfbSRichard Henderson 30135d617bfbSRichard Henderson TRANS(RDPR_otherwin, 64, do_rd_special, supervisor(dc), a->rd, do_rdotherwin) 30145d617bfbSRichard Henderson 30155d617bfbSRichard Henderson static TCGv do_rdwstate(DisasContext *dc, TCGv dst) 30165d617bfbSRichard Henderson { 30175d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(wstate)); 30185d617bfbSRichard Henderson return dst; 30195d617bfbSRichard Henderson } 30205d617bfbSRichard Henderson 30215d617bfbSRichard Henderson TRANS(RDPR_wstate, 64, do_rd_special, supervisor(dc), a->rd, do_rdwstate) 30225d617bfbSRichard Henderson 30235d617bfbSRichard Henderson static TCGv do_rdgl(DisasContext *dc, TCGv dst) 30245d617bfbSRichard Henderson { 30255d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(gl)); 30265d617bfbSRichard Henderson return dst; 30275d617bfbSRichard Henderson } 30285d617bfbSRichard Henderson 30295d617bfbSRichard Henderson TRANS(RDPR_gl, GL, do_rd_special, supervisor(dc), a->rd, do_rdgl) 30305d617bfbSRichard Henderson 30315d617bfbSRichard Henderson /* UA2005 strand status */ 30325d617bfbSRichard Henderson static TCGv do_rdssr(DisasContext *dc, TCGv dst) 30335d617bfbSRichard Henderson { 30342da789deSRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(ssr)); 30352da789deSRichard Henderson return dst; 30365d617bfbSRichard Henderson } 30375d617bfbSRichard Henderson 30385d617bfbSRichard Henderson TRANS(RDPR_strand_status, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdssr) 30395d617bfbSRichard Henderson 30405d617bfbSRichard Henderson static TCGv do_rdver(DisasContext *dc, TCGv dst) 30415d617bfbSRichard Henderson { 30422da789deSRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(version)); 30432da789deSRichard Henderson return dst; 30445d617bfbSRichard Henderson } 30455d617bfbSRichard Henderson 30465d617bfbSRichard Henderson TRANS(RDPR_ver, 64, do_rd_special, supervisor(dc), a->rd, do_rdver) 30475d617bfbSRichard Henderson 3048e8325dc0SRichard Henderson static bool trans_FLUSHW(DisasContext *dc, arg_FLUSHW *a) 3049e8325dc0SRichard Henderson { 3050e8325dc0SRichard Henderson if (avail_64(dc)) { 3051e8325dc0SRichard Henderson gen_helper_flushw(tcg_env); 3052e8325dc0SRichard Henderson return advance_pc(dc); 3053e8325dc0SRichard Henderson } 3054e8325dc0SRichard Henderson return false; 3055e8325dc0SRichard Henderson } 3056e8325dc0SRichard Henderson 30570faef01bSRichard Henderson static bool do_wr_special(DisasContext *dc, arg_r_r_ri *a, bool priv, 30580faef01bSRichard Henderson void (*func)(DisasContext *, TCGv)) 30590faef01bSRichard Henderson { 30600faef01bSRichard Henderson TCGv src; 30610faef01bSRichard Henderson 30620faef01bSRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 30630faef01bSRichard Henderson if (!a->imm && (a->rs2_or_imm & ~0x1f)) { 30640faef01bSRichard Henderson return false; 30650faef01bSRichard Henderson } 30660faef01bSRichard Henderson if (!priv) { 30670faef01bSRichard Henderson return raise_priv(dc); 30680faef01bSRichard Henderson } 30690faef01bSRichard Henderson 30700faef01bSRichard Henderson if (a->rs1 == 0 && (a->imm || a->rs2_or_imm == 0)) { 30710faef01bSRichard Henderson src = tcg_constant_tl(a->rs2_or_imm); 30720faef01bSRichard Henderson } else { 30730faef01bSRichard Henderson TCGv src1 = gen_load_gpr(dc, a->rs1); 30740faef01bSRichard Henderson if (a->rs2_or_imm == 0) { 30750faef01bSRichard Henderson src = src1; 30760faef01bSRichard Henderson } else { 30770faef01bSRichard Henderson src = tcg_temp_new(); 30780faef01bSRichard Henderson if (a->imm) { 30790faef01bSRichard Henderson tcg_gen_xori_tl(src, src1, a->rs2_or_imm); 30800faef01bSRichard Henderson } else { 30810faef01bSRichard Henderson tcg_gen_xor_tl(src, src1, gen_load_gpr(dc, a->rs2_or_imm)); 30820faef01bSRichard Henderson } 30830faef01bSRichard Henderson } 30840faef01bSRichard Henderson } 30850faef01bSRichard Henderson func(dc, src); 30860faef01bSRichard Henderson return advance_pc(dc); 30870faef01bSRichard Henderson } 30880faef01bSRichard Henderson 30890faef01bSRichard Henderson static void do_wry(DisasContext *dc, TCGv src) 30900faef01bSRichard Henderson { 30910faef01bSRichard Henderson tcg_gen_ext32u_tl(cpu_y, src); 30920faef01bSRichard Henderson } 30930faef01bSRichard Henderson 30940faef01bSRichard Henderson TRANS(WRY, ALL, do_wr_special, a, true, do_wry) 30950faef01bSRichard Henderson 30960faef01bSRichard Henderson static void do_wrccr(DisasContext *dc, TCGv src) 30970faef01bSRichard Henderson { 30980faef01bSRichard Henderson gen_helper_wrccr(tcg_env, src); 30990faef01bSRichard Henderson } 31000faef01bSRichard Henderson 31010faef01bSRichard Henderson TRANS(WRCCR, 64, do_wr_special, a, true, do_wrccr) 31020faef01bSRichard Henderson 31030faef01bSRichard Henderson static void do_wrasi(DisasContext *dc, TCGv src) 31040faef01bSRichard Henderson { 31050faef01bSRichard Henderson TCGv tmp = tcg_temp_new(); 31060faef01bSRichard Henderson 31070faef01bSRichard Henderson tcg_gen_ext8u_tl(tmp, src); 31080faef01bSRichard Henderson tcg_gen_st32_tl(tmp, tcg_env, env64_field_offsetof(asi)); 31090faef01bSRichard Henderson /* End TB to notice changed ASI. */ 31100faef01bSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 31110faef01bSRichard Henderson } 31120faef01bSRichard Henderson 31130faef01bSRichard Henderson TRANS(WRASI, 64, do_wr_special, a, true, do_wrasi) 31140faef01bSRichard Henderson 31150faef01bSRichard Henderson static void do_wrfprs(DisasContext *dc, TCGv src) 31160faef01bSRichard Henderson { 31170faef01bSRichard Henderson #ifdef TARGET_SPARC64 31180faef01bSRichard Henderson tcg_gen_trunc_tl_i32(cpu_fprs, src); 31190faef01bSRichard Henderson dc->fprs_dirty = 0; 31200faef01bSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 31210faef01bSRichard Henderson #else 31220faef01bSRichard Henderson qemu_build_not_reached(); 31230faef01bSRichard Henderson #endif 31240faef01bSRichard Henderson } 31250faef01bSRichard Henderson 31260faef01bSRichard Henderson TRANS(WRFPRS, 64, do_wr_special, a, true, do_wrfprs) 31270faef01bSRichard Henderson 31280faef01bSRichard Henderson static void do_wrgsr(DisasContext *dc, TCGv src) 31290faef01bSRichard Henderson { 31300faef01bSRichard Henderson gen_trap_ifnofpu(dc); 31310faef01bSRichard Henderson tcg_gen_mov_tl(cpu_gsr, src); 31320faef01bSRichard Henderson } 31330faef01bSRichard Henderson 31340faef01bSRichard Henderson TRANS(WRGSR, 64, do_wr_special, a, true, do_wrgsr) 31350faef01bSRichard Henderson 31360faef01bSRichard Henderson static void do_wrsoftint_set(DisasContext *dc, TCGv src) 31370faef01bSRichard Henderson { 31380faef01bSRichard Henderson gen_helper_set_softint(tcg_env, src); 31390faef01bSRichard Henderson } 31400faef01bSRichard Henderson 31410faef01bSRichard Henderson TRANS(WRSOFTINT_SET, 64, do_wr_special, a, supervisor(dc), do_wrsoftint_set) 31420faef01bSRichard Henderson 31430faef01bSRichard Henderson static void do_wrsoftint_clr(DisasContext *dc, TCGv src) 31440faef01bSRichard Henderson { 31450faef01bSRichard Henderson gen_helper_clear_softint(tcg_env, src); 31460faef01bSRichard Henderson } 31470faef01bSRichard Henderson 31480faef01bSRichard Henderson TRANS(WRSOFTINT_CLR, 64, do_wr_special, a, supervisor(dc), do_wrsoftint_clr) 31490faef01bSRichard Henderson 31500faef01bSRichard Henderson static void do_wrsoftint(DisasContext *dc, TCGv src) 31510faef01bSRichard Henderson { 31520faef01bSRichard Henderson gen_helper_write_softint(tcg_env, src); 31530faef01bSRichard Henderson } 31540faef01bSRichard Henderson 31550faef01bSRichard Henderson TRANS(WRSOFTINT, 64, do_wr_special, a, supervisor(dc), do_wrsoftint) 31560faef01bSRichard Henderson 31570faef01bSRichard Henderson static void do_wrtick_cmpr(DisasContext *dc, TCGv src) 31580faef01bSRichard Henderson { 31590faef01bSRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr(); 31600faef01bSRichard Henderson 3161577efa45SRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(tick_cmpr)); 3162577efa45SRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(tick)); 31630faef01bSRichard Henderson translator_io_start(&dc->base); 3164577efa45SRichard Henderson gen_helper_tick_set_limit(r_tickptr, src); 31650faef01bSRichard Henderson /* End TB to handle timer interrupt */ 31660faef01bSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 31670faef01bSRichard Henderson } 31680faef01bSRichard Henderson 31690faef01bSRichard Henderson TRANS(WRTICK_CMPR, 64, do_wr_special, a, supervisor(dc), do_wrtick_cmpr) 31700faef01bSRichard Henderson 31710faef01bSRichard Henderson static void do_wrstick(DisasContext *dc, TCGv src) 31720faef01bSRichard Henderson { 31730faef01bSRichard Henderson #ifdef TARGET_SPARC64 31740faef01bSRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr(); 31750faef01bSRichard Henderson 31760faef01bSRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, offsetof(CPUSPARCState, stick)); 31770faef01bSRichard Henderson translator_io_start(&dc->base); 31780faef01bSRichard Henderson gen_helper_tick_set_count(r_tickptr, src); 31790faef01bSRichard Henderson /* End TB to handle timer interrupt */ 31800faef01bSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 31810faef01bSRichard Henderson #else 31820faef01bSRichard Henderson qemu_build_not_reached(); 31830faef01bSRichard Henderson #endif 31840faef01bSRichard Henderson } 31850faef01bSRichard Henderson 31860faef01bSRichard Henderson TRANS(WRSTICK, 64, do_wr_special, a, supervisor(dc), do_wrstick) 31870faef01bSRichard Henderson 31880faef01bSRichard Henderson static void do_wrstick_cmpr(DisasContext *dc, TCGv src) 31890faef01bSRichard Henderson { 31900faef01bSRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr(); 31910faef01bSRichard Henderson 3192577efa45SRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(stick_cmpr)); 3193577efa45SRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(stick)); 31940faef01bSRichard Henderson translator_io_start(&dc->base); 3195577efa45SRichard Henderson gen_helper_tick_set_limit(r_tickptr, src); 31960faef01bSRichard Henderson /* End TB to handle timer interrupt */ 31970faef01bSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 31980faef01bSRichard Henderson } 31990faef01bSRichard Henderson 32000faef01bSRichard Henderson TRANS(WRSTICK_CMPR, 64, do_wr_special, a, supervisor(dc), do_wrstick_cmpr) 32010faef01bSRichard Henderson 32020faef01bSRichard Henderson static void do_wrpowerdown(DisasContext *dc, TCGv src) 32030faef01bSRichard Henderson { 32040faef01bSRichard Henderson save_state(dc); 32050faef01bSRichard Henderson gen_helper_power_down(tcg_env); 32060faef01bSRichard Henderson } 32070faef01bSRichard Henderson 32080faef01bSRichard Henderson TRANS(WRPOWERDOWN, POWERDOWN, do_wr_special, a, supervisor(dc), do_wrpowerdown) 32090faef01bSRichard Henderson 321025524734SRichard Henderson static void do_wrpsr(DisasContext *dc, TCGv src) 321125524734SRichard Henderson { 321225524734SRichard Henderson gen_helper_wrpsr(tcg_env, src); 321325524734SRichard Henderson dc->base.is_jmp = DISAS_EXIT; 321425524734SRichard Henderson } 321525524734SRichard Henderson 321625524734SRichard Henderson TRANS(WRPSR, 32, do_wr_special, a, supervisor(dc), do_wrpsr) 321725524734SRichard Henderson 32189422278eSRichard Henderson static void do_wrwim(DisasContext *dc, TCGv src) 32199422278eSRichard Henderson { 32209422278eSRichard Henderson target_ulong mask = MAKE_64BIT_MASK(0, dc->def->nwindows); 3221cd6269f7SRichard Henderson TCGv tmp = tcg_temp_new(); 3222cd6269f7SRichard Henderson 3223cd6269f7SRichard Henderson tcg_gen_andi_tl(tmp, src, mask); 3224cd6269f7SRichard Henderson tcg_gen_st_tl(tmp, tcg_env, env32_field_offsetof(wim)); 32259422278eSRichard Henderson } 32269422278eSRichard Henderson 32279422278eSRichard Henderson TRANS(WRWIM, 32, do_wr_special, a, supervisor(dc), do_wrwim) 32289422278eSRichard Henderson 32299422278eSRichard Henderson static void do_wrtpc(DisasContext *dc, TCGv src) 32309422278eSRichard Henderson { 32319422278eSRichard Henderson #ifdef TARGET_SPARC64 32329422278eSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 32339422278eSRichard Henderson 32349422278eSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 32359422278eSRichard Henderson tcg_gen_st_tl(src, r_tsptr, offsetof(trap_state, tpc)); 32369422278eSRichard Henderson #else 32379422278eSRichard Henderson qemu_build_not_reached(); 32389422278eSRichard Henderson #endif 32399422278eSRichard Henderson } 32409422278eSRichard Henderson 32419422278eSRichard Henderson TRANS(WRPR_tpc, 64, do_wr_special, a, supervisor(dc), do_wrtpc) 32429422278eSRichard Henderson 32439422278eSRichard Henderson static void do_wrtnpc(DisasContext *dc, TCGv src) 32449422278eSRichard Henderson { 32459422278eSRichard Henderson #ifdef TARGET_SPARC64 32469422278eSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 32479422278eSRichard Henderson 32489422278eSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 32499422278eSRichard Henderson tcg_gen_st_tl(src, r_tsptr, offsetof(trap_state, tnpc)); 32509422278eSRichard Henderson #else 32519422278eSRichard Henderson qemu_build_not_reached(); 32529422278eSRichard Henderson #endif 32539422278eSRichard Henderson } 32549422278eSRichard Henderson 32559422278eSRichard Henderson TRANS(WRPR_tnpc, 64, do_wr_special, a, supervisor(dc), do_wrtnpc) 32569422278eSRichard Henderson 32579422278eSRichard Henderson static void do_wrtstate(DisasContext *dc, TCGv src) 32589422278eSRichard Henderson { 32599422278eSRichard Henderson #ifdef TARGET_SPARC64 32609422278eSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 32619422278eSRichard Henderson 32629422278eSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 32639422278eSRichard Henderson tcg_gen_st_tl(src, r_tsptr, offsetof(trap_state, tstate)); 32649422278eSRichard Henderson #else 32659422278eSRichard Henderson qemu_build_not_reached(); 32669422278eSRichard Henderson #endif 32679422278eSRichard Henderson } 32689422278eSRichard Henderson 32699422278eSRichard Henderson TRANS(WRPR_tstate, 64, do_wr_special, a, supervisor(dc), do_wrtstate) 32709422278eSRichard Henderson 32719422278eSRichard Henderson static void do_wrtt(DisasContext *dc, TCGv src) 32729422278eSRichard Henderson { 32739422278eSRichard Henderson #ifdef TARGET_SPARC64 32749422278eSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr(); 32759422278eSRichard Henderson 32769422278eSRichard Henderson gen_load_trap_state_at_tl(r_tsptr); 32779422278eSRichard Henderson tcg_gen_st32_tl(src, r_tsptr, offsetof(trap_state, tt)); 32789422278eSRichard Henderson #else 32799422278eSRichard Henderson qemu_build_not_reached(); 32809422278eSRichard Henderson #endif 32819422278eSRichard Henderson } 32829422278eSRichard Henderson 32839422278eSRichard Henderson TRANS(WRPR_tt, 64, do_wr_special, a, supervisor(dc), do_wrtt) 32849422278eSRichard Henderson 32859422278eSRichard Henderson static void do_wrtick(DisasContext *dc, TCGv src) 32869422278eSRichard Henderson { 32879422278eSRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr(); 32889422278eSRichard Henderson 32899422278eSRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(tick)); 32909422278eSRichard Henderson translator_io_start(&dc->base); 32919422278eSRichard Henderson gen_helper_tick_set_count(r_tickptr, src); 32929422278eSRichard Henderson /* End TB to handle timer interrupt */ 32939422278eSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 32949422278eSRichard Henderson } 32959422278eSRichard Henderson 32969422278eSRichard Henderson TRANS(WRPR_tick, 64, do_wr_special, a, supervisor(dc), do_wrtick) 32979422278eSRichard Henderson 32989422278eSRichard Henderson static void do_wrtba(DisasContext *dc, TCGv src) 32999422278eSRichard Henderson { 33009422278eSRichard Henderson tcg_gen_mov_tl(cpu_tbr, src); 33019422278eSRichard Henderson } 33029422278eSRichard Henderson 33039422278eSRichard Henderson TRANS(WRPR_tba, 64, do_wr_special, a, supervisor(dc), do_wrtba) 33049422278eSRichard Henderson 33059422278eSRichard Henderson static void do_wrpstate(DisasContext *dc, TCGv src) 33069422278eSRichard Henderson { 33079422278eSRichard Henderson save_state(dc); 33089422278eSRichard Henderson if (translator_io_start(&dc->base)) { 33099422278eSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 33109422278eSRichard Henderson } 33119422278eSRichard Henderson gen_helper_wrpstate(tcg_env, src); 33129422278eSRichard Henderson dc->npc = DYNAMIC_PC; 33139422278eSRichard Henderson } 33149422278eSRichard Henderson 33159422278eSRichard Henderson TRANS(WRPR_pstate, 64, do_wr_special, a, supervisor(dc), do_wrpstate) 33169422278eSRichard Henderson 33179422278eSRichard Henderson static void do_wrtl(DisasContext *dc, TCGv src) 33189422278eSRichard Henderson { 33199422278eSRichard Henderson save_state(dc); 33209422278eSRichard Henderson tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(tl)); 33219422278eSRichard Henderson dc->npc = DYNAMIC_PC; 33229422278eSRichard Henderson } 33239422278eSRichard Henderson 33249422278eSRichard Henderson TRANS(WRPR_tl, 64, do_wr_special, a, supervisor(dc), do_wrtl) 33259422278eSRichard Henderson 33269422278eSRichard Henderson static void do_wrpil(DisasContext *dc, TCGv src) 33279422278eSRichard Henderson { 33289422278eSRichard Henderson if (translator_io_start(&dc->base)) { 33299422278eSRichard Henderson dc->base.is_jmp = DISAS_EXIT; 33309422278eSRichard Henderson } 33319422278eSRichard Henderson gen_helper_wrpil(tcg_env, src); 33329422278eSRichard Henderson } 33339422278eSRichard Henderson 33349422278eSRichard Henderson TRANS(WRPR_pil, 64, do_wr_special, a, supervisor(dc), do_wrpil) 33359422278eSRichard Henderson 33369422278eSRichard Henderson static void do_wrcwp(DisasContext *dc, TCGv src) 33379422278eSRichard Henderson { 33389422278eSRichard Henderson gen_helper_wrcwp(tcg_env, src); 33399422278eSRichard Henderson } 33409422278eSRichard Henderson 33419422278eSRichard Henderson TRANS(WRPR_cwp, 64, do_wr_special, a, supervisor(dc), do_wrcwp) 33429422278eSRichard Henderson 33439422278eSRichard Henderson static void do_wrcansave(DisasContext *dc, TCGv src) 33449422278eSRichard Henderson { 33459422278eSRichard Henderson tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(cansave)); 33469422278eSRichard Henderson } 33479422278eSRichard Henderson 33489422278eSRichard Henderson TRANS(WRPR_cansave, 64, do_wr_special, a, supervisor(dc), do_wrcansave) 33499422278eSRichard Henderson 33509422278eSRichard Henderson static void do_wrcanrestore(DisasContext *dc, TCGv src) 33519422278eSRichard Henderson { 33529422278eSRichard Henderson tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(canrestore)); 33539422278eSRichard Henderson } 33549422278eSRichard Henderson 33559422278eSRichard Henderson TRANS(WRPR_canrestore, 64, do_wr_special, a, supervisor(dc), do_wrcanrestore) 33569422278eSRichard Henderson 33579422278eSRichard Henderson static void do_wrcleanwin(DisasContext *dc, TCGv src) 33589422278eSRichard Henderson { 33599422278eSRichard Henderson tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(cleanwin)); 33609422278eSRichard Henderson } 33619422278eSRichard Henderson 33629422278eSRichard Henderson TRANS(WRPR_cleanwin, 64, do_wr_special, a, supervisor(dc), do_wrcleanwin) 33639422278eSRichard Henderson 33649422278eSRichard Henderson static void do_wrotherwin(DisasContext *dc, TCGv src) 33659422278eSRichard Henderson { 33669422278eSRichard Henderson tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(otherwin)); 33679422278eSRichard Henderson } 33689422278eSRichard Henderson 33699422278eSRichard Henderson TRANS(WRPR_otherwin, 64, do_wr_special, a, supervisor(dc), do_wrotherwin) 33709422278eSRichard Henderson 33719422278eSRichard Henderson static void do_wrwstate(DisasContext *dc, TCGv src) 33729422278eSRichard Henderson { 33739422278eSRichard Henderson tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(wstate)); 33749422278eSRichard Henderson } 33759422278eSRichard Henderson 33769422278eSRichard Henderson TRANS(WRPR_wstate, 64, do_wr_special, a, supervisor(dc), do_wrwstate) 33779422278eSRichard Henderson 33789422278eSRichard Henderson static void do_wrgl(DisasContext *dc, TCGv src) 33799422278eSRichard Henderson { 33809422278eSRichard Henderson gen_helper_wrgl(tcg_env, src); 33819422278eSRichard Henderson } 33829422278eSRichard Henderson 33839422278eSRichard Henderson TRANS(WRPR_gl, GL, do_wr_special, a, supervisor(dc), do_wrgl) 33849422278eSRichard Henderson 33859422278eSRichard Henderson /* UA2005 strand status */ 33869422278eSRichard Henderson static void do_wrssr(DisasContext *dc, TCGv src) 33879422278eSRichard Henderson { 33882da789deSRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(ssr)); 33899422278eSRichard Henderson } 33909422278eSRichard Henderson 33919422278eSRichard Henderson TRANS(WRPR_strand_status, HYPV, do_wr_special, a, hypervisor(dc), do_wrssr) 33929422278eSRichard Henderson 3393bb97f2f5SRichard Henderson TRANS(WRTBR, 32, do_wr_special, a, supervisor(dc), do_wrtba) 3394bb97f2f5SRichard Henderson 3395bb97f2f5SRichard Henderson static void do_wrhpstate(DisasContext *dc, TCGv src) 3396bb97f2f5SRichard Henderson { 3397bb97f2f5SRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(hpstate)); 3398bb97f2f5SRichard Henderson dc->base.is_jmp = DISAS_EXIT; 3399bb97f2f5SRichard Henderson } 3400bb97f2f5SRichard Henderson 3401bb97f2f5SRichard Henderson TRANS(WRHPR_hpstate, HYPV, do_wr_special, a, hypervisor(dc), do_wrhpstate) 3402bb97f2f5SRichard Henderson 3403bb97f2f5SRichard Henderson static void do_wrhtstate(DisasContext *dc, TCGv src) 3404bb97f2f5SRichard Henderson { 3405bb97f2f5SRichard Henderson TCGv_i32 tl = tcg_temp_new_i32(); 3406bb97f2f5SRichard Henderson TCGv_ptr tp = tcg_temp_new_ptr(); 3407bb97f2f5SRichard Henderson 3408bb97f2f5SRichard Henderson tcg_gen_ld_i32(tl, tcg_env, env64_field_offsetof(tl)); 3409bb97f2f5SRichard Henderson tcg_gen_andi_i32(tl, tl, MAXTL_MASK); 3410bb97f2f5SRichard Henderson tcg_gen_shli_i32(tl, tl, 3); 3411bb97f2f5SRichard Henderson tcg_gen_ext_i32_ptr(tp, tl); 3412bb97f2f5SRichard Henderson tcg_gen_add_ptr(tp, tp, tcg_env); 3413bb97f2f5SRichard Henderson 3414bb97f2f5SRichard Henderson tcg_gen_st_tl(src, tp, env64_field_offsetof(htstate)); 3415bb97f2f5SRichard Henderson } 3416bb97f2f5SRichard Henderson 3417bb97f2f5SRichard Henderson TRANS(WRHPR_htstate, HYPV, do_wr_special, a, hypervisor(dc), do_wrhtstate) 3418bb97f2f5SRichard Henderson 3419bb97f2f5SRichard Henderson static void do_wrhintp(DisasContext *dc, TCGv src) 3420bb97f2f5SRichard Henderson { 34212da789deSRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(hintp)); 3422bb97f2f5SRichard Henderson } 3423bb97f2f5SRichard Henderson 3424bb97f2f5SRichard Henderson TRANS(WRHPR_hintp, HYPV, do_wr_special, a, hypervisor(dc), do_wrhintp) 3425bb97f2f5SRichard Henderson 3426bb97f2f5SRichard Henderson static void do_wrhtba(DisasContext *dc, TCGv src) 3427bb97f2f5SRichard Henderson { 34282da789deSRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(htba)); 3429bb97f2f5SRichard Henderson } 3430bb97f2f5SRichard Henderson 3431bb97f2f5SRichard Henderson TRANS(WRHPR_htba, HYPV, do_wr_special, a, hypervisor(dc), do_wrhtba) 3432bb97f2f5SRichard Henderson 3433bb97f2f5SRichard Henderson static void do_wrhstick_cmpr(DisasContext *dc, TCGv src) 3434bb97f2f5SRichard Henderson { 3435bb97f2f5SRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr(); 3436bb97f2f5SRichard Henderson 3437577efa45SRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(hstick_cmpr)); 3438bb97f2f5SRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(hstick)); 3439bb97f2f5SRichard Henderson translator_io_start(&dc->base); 3440577efa45SRichard Henderson gen_helper_tick_set_limit(r_tickptr, src); 3441bb97f2f5SRichard Henderson /* End TB to handle timer interrupt */ 3442bb97f2f5SRichard Henderson dc->base.is_jmp = DISAS_EXIT; 3443bb97f2f5SRichard Henderson } 3444bb97f2f5SRichard Henderson 3445bb97f2f5SRichard Henderson TRANS(WRHPR_hstick_cmpr, HYPV, do_wr_special, a, hypervisor(dc), 3446bb97f2f5SRichard Henderson do_wrhstick_cmpr) 3447bb97f2f5SRichard Henderson 344825524734SRichard Henderson static bool do_saved_restored(DisasContext *dc, bool saved) 344925524734SRichard Henderson { 345025524734SRichard Henderson if (!supervisor(dc)) { 345125524734SRichard Henderson return raise_priv(dc); 345225524734SRichard Henderson } 345325524734SRichard Henderson if (saved) { 345425524734SRichard Henderson gen_helper_saved(tcg_env); 345525524734SRichard Henderson } else { 345625524734SRichard Henderson gen_helper_restored(tcg_env); 345725524734SRichard Henderson } 345825524734SRichard Henderson return advance_pc(dc); 345925524734SRichard Henderson } 346025524734SRichard Henderson 346125524734SRichard Henderson TRANS(SAVED, 64, do_saved_restored, true) 346225524734SRichard Henderson TRANS(RESTORED, 64, do_saved_restored, false) 346325524734SRichard Henderson 3464d3825800SRichard Henderson static bool trans_NOP(DisasContext *dc, arg_NOP *a) 3465d3825800SRichard Henderson { 3466d3825800SRichard Henderson return advance_pc(dc); 3467d3825800SRichard Henderson } 3468d3825800SRichard Henderson 34690faef01bSRichard Henderson /* 34700faef01bSRichard Henderson * TODO: Need a feature bit for sparcv8. 34710faef01bSRichard Henderson * In the meantime, treat all 32-bit cpus like sparcv7. 34720faef01bSRichard Henderson */ 34735458fd31SRichard Henderson TRANS(NOP_v7, 32, trans_NOP, a) 34745458fd31SRichard Henderson TRANS(NOP_v9, 64, trans_NOP, a) 34750faef01bSRichard Henderson 3476b597eedcSRichard Henderson static bool do_arith_int(DisasContext *dc, arg_r_r_ri_cc *a, 3477428881deSRichard Henderson void (*func)(TCGv, TCGv, TCGv), 34782a45b736SRichard Henderson void (*funci)(TCGv, TCGv, target_long), 34792a45b736SRichard Henderson bool logic_cc) 3480428881deSRichard Henderson { 3481428881deSRichard Henderson TCGv dst, src1; 3482428881deSRichard Henderson 3483428881deSRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 3484428881deSRichard Henderson if (!a->imm && a->rs2_or_imm & ~0x1f) { 3485428881deSRichard Henderson return false; 3486428881deSRichard Henderson } 3487428881deSRichard Henderson 34882a45b736SRichard Henderson if (logic_cc) { 34892a45b736SRichard Henderson dst = cpu_cc_N; 3490428881deSRichard Henderson } else { 3491428881deSRichard Henderson dst = gen_dest_gpr(dc, a->rd); 3492428881deSRichard Henderson } 3493428881deSRichard Henderson src1 = gen_load_gpr(dc, a->rs1); 3494428881deSRichard Henderson 3495428881deSRichard Henderson if (a->imm || a->rs2_or_imm == 0) { 3496428881deSRichard Henderson if (funci) { 3497428881deSRichard Henderson funci(dst, src1, a->rs2_or_imm); 3498428881deSRichard Henderson } else { 3499428881deSRichard Henderson func(dst, src1, tcg_constant_tl(a->rs2_or_imm)); 3500428881deSRichard Henderson } 3501428881deSRichard Henderson } else { 3502428881deSRichard Henderson func(dst, src1, cpu_regs[a->rs2_or_imm]); 3503428881deSRichard Henderson } 35042a45b736SRichard Henderson 35052a45b736SRichard Henderson if (logic_cc) { 35062a45b736SRichard Henderson if (TARGET_LONG_BITS == 64) { 35072a45b736SRichard Henderson tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N); 35082a45b736SRichard Henderson tcg_gen_movi_tl(cpu_icc_C, 0); 35092a45b736SRichard Henderson } 35102a45b736SRichard Henderson tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N); 35112a45b736SRichard Henderson tcg_gen_movi_tl(cpu_cc_C, 0); 35122a45b736SRichard Henderson tcg_gen_movi_tl(cpu_cc_V, 0); 35132a45b736SRichard Henderson } 35142a45b736SRichard Henderson 3515428881deSRichard Henderson gen_store_gpr(dc, a->rd, dst); 3516428881deSRichard Henderson return advance_pc(dc); 3517428881deSRichard Henderson } 3518428881deSRichard Henderson 3519b597eedcSRichard Henderson static bool do_arith(DisasContext *dc, arg_r_r_ri_cc *a, 3520428881deSRichard Henderson void (*func)(TCGv, TCGv, TCGv), 3521428881deSRichard Henderson void (*funci)(TCGv, TCGv, target_long), 3522428881deSRichard Henderson void (*func_cc)(TCGv, TCGv, TCGv)) 3523428881deSRichard Henderson { 3524428881deSRichard Henderson if (a->cc) { 3525b597eedcSRichard Henderson return do_arith_int(dc, a, func_cc, NULL, false); 3526428881deSRichard Henderson } 3527b597eedcSRichard Henderson return do_arith_int(dc, a, func, funci, false); 3528428881deSRichard Henderson } 3529428881deSRichard Henderson 3530428881deSRichard Henderson static bool do_logic(DisasContext *dc, arg_r_r_ri_cc *a, 3531428881deSRichard Henderson void (*func)(TCGv, TCGv, TCGv), 3532428881deSRichard Henderson void (*funci)(TCGv, TCGv, target_long)) 3533428881deSRichard Henderson { 3534b597eedcSRichard Henderson return do_arith_int(dc, a, func, funci, a->cc); 3535428881deSRichard Henderson } 3536428881deSRichard Henderson 3537b597eedcSRichard Henderson TRANS(ADD, ALL, do_arith, a, tcg_gen_add_tl, tcg_gen_addi_tl, gen_op_addcc) 3538b597eedcSRichard Henderson TRANS(SUB, ALL, do_arith, a, tcg_gen_sub_tl, tcg_gen_subi_tl, gen_op_subcc) 3539b597eedcSRichard Henderson TRANS(ADDC, ALL, do_arith, a, gen_op_addc, NULL, gen_op_addccc) 3540b597eedcSRichard Henderson TRANS(SUBC, ALL, do_arith, a, gen_op_subc, NULL, gen_op_subccc) 3541428881deSRichard Henderson 3542b597eedcSRichard Henderson TRANS(TADDcc, ALL, do_arith, a, NULL, NULL, gen_op_taddcc) 3543b597eedcSRichard Henderson TRANS(TSUBcc, ALL, do_arith, a, NULL, NULL, gen_op_tsubcc) 3544b597eedcSRichard Henderson TRANS(TADDccTV, ALL, do_arith, a, NULL, NULL, gen_op_taddcctv) 3545b597eedcSRichard Henderson TRANS(TSUBccTV, ALL, do_arith, a, NULL, NULL, gen_op_tsubcctv) 3546a9aba13dSRichard Henderson 3547428881deSRichard Henderson TRANS(AND, ALL, do_logic, a, tcg_gen_and_tl, tcg_gen_andi_tl) 3548428881deSRichard Henderson TRANS(XOR, ALL, do_logic, a, tcg_gen_xor_tl, tcg_gen_xori_tl) 3549428881deSRichard Henderson TRANS(ANDN, ALL, do_logic, a, tcg_gen_andc_tl, NULL) 3550428881deSRichard Henderson TRANS(ORN, ALL, do_logic, a, tcg_gen_orc_tl, NULL) 3551428881deSRichard Henderson TRANS(XORN, ALL, do_logic, a, tcg_gen_eqv_tl, NULL) 3552428881deSRichard Henderson 3553b597eedcSRichard Henderson TRANS(MULX, 64, do_arith, a, tcg_gen_mul_tl, tcg_gen_muli_tl, NULL) 3554b5372650SRichard Henderson TRANS(UMUL, MUL, do_logic, a, gen_op_umul, NULL) 3555b5372650SRichard Henderson TRANS(SMUL, MUL, do_logic, a, gen_op_smul, NULL) 3556b597eedcSRichard Henderson TRANS(MULScc, ALL, do_arith, a, NULL, NULL, gen_op_mulscc) 355722188d7dSRichard Henderson 3558b597eedcSRichard Henderson TRANS(UDIVX, 64, do_arith, a, gen_op_udivx, NULL, NULL) 3559b597eedcSRichard Henderson TRANS(SDIVX, 64, do_arith, a, gen_op_sdivx, NULL, NULL) 3560b597eedcSRichard Henderson TRANS(UDIV, DIV, do_arith, a, gen_op_udiv, NULL, gen_op_udivcc) 3561b597eedcSRichard Henderson TRANS(SDIV, DIV, do_arith, a, gen_op_sdiv, NULL, gen_op_sdivcc) 35624ee85ea9SRichard Henderson 35639c6ec5bcSRichard Henderson /* TODO: Should have feature bit -- comes in with UltraSparc T2. */ 3564b597eedcSRichard Henderson TRANS(POPC, 64, do_arith, a, gen_op_popc, NULL, NULL) 35659c6ec5bcSRichard Henderson 3566428881deSRichard Henderson static bool trans_OR(DisasContext *dc, arg_r_r_ri_cc *a) 3567428881deSRichard Henderson { 3568428881deSRichard Henderson /* OR with %g0 is the canonical alias for MOV. */ 3569428881deSRichard Henderson if (!a->cc && a->rs1 == 0) { 3570428881deSRichard Henderson if (a->imm || a->rs2_or_imm == 0) { 3571428881deSRichard Henderson gen_store_gpr(dc, a->rd, tcg_constant_tl(a->rs2_or_imm)); 3572428881deSRichard Henderson } else if (a->rs2_or_imm & ~0x1f) { 3573428881deSRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 3574428881deSRichard Henderson return false; 3575428881deSRichard Henderson } else { 3576428881deSRichard Henderson gen_store_gpr(dc, a->rd, cpu_regs[a->rs2_or_imm]); 3577428881deSRichard Henderson } 3578428881deSRichard Henderson return advance_pc(dc); 3579428881deSRichard Henderson } 3580428881deSRichard Henderson return do_logic(dc, a, tcg_gen_or_tl, tcg_gen_ori_tl); 3581428881deSRichard Henderson } 3582428881deSRichard Henderson 3583b88ce6f2SRichard Henderson static bool gen_edge(DisasContext *dc, arg_r_r_r *a, 3584b88ce6f2SRichard Henderson int width, bool cc, bool left) 3585b88ce6f2SRichard Henderson { 3586b88ce6f2SRichard Henderson TCGv dst, s1, s2, lo1, lo2; 3587b88ce6f2SRichard Henderson uint64_t amask, tabl, tabr; 3588b88ce6f2SRichard Henderson int shift, imask, omask; 3589b88ce6f2SRichard Henderson 3590b88ce6f2SRichard Henderson dst = gen_dest_gpr(dc, a->rd); 3591b88ce6f2SRichard Henderson s1 = gen_load_gpr(dc, a->rs1); 3592b88ce6f2SRichard Henderson s2 = gen_load_gpr(dc, a->rs2); 3593b88ce6f2SRichard Henderson 3594b88ce6f2SRichard Henderson if (cc) { 3595f828df74SRichard Henderson gen_op_subcc(cpu_cc_N, s1, s2); 3596b88ce6f2SRichard Henderson } 3597b88ce6f2SRichard Henderson 3598b88ce6f2SRichard Henderson /* 3599b88ce6f2SRichard Henderson * Theory of operation: there are two tables, left and right (not to 3600b88ce6f2SRichard Henderson * be confused with the left and right versions of the opcode). These 3601b88ce6f2SRichard Henderson * are indexed by the low 3 bits of the inputs. To make things "easy", 3602b88ce6f2SRichard Henderson * these tables are loaded into two constants, TABL and TABR below. 3603b88ce6f2SRichard Henderson * The operation index = (input & imask) << shift calculates the index 3604b88ce6f2SRichard Henderson * into the constant, while val = (table >> index) & omask calculates 3605b88ce6f2SRichard Henderson * the value we're looking for. 3606b88ce6f2SRichard Henderson */ 3607b88ce6f2SRichard Henderson switch (width) { 3608b88ce6f2SRichard Henderson case 8: 3609b88ce6f2SRichard Henderson imask = 0x7; 3610b88ce6f2SRichard Henderson shift = 3; 3611b88ce6f2SRichard Henderson omask = 0xff; 3612b88ce6f2SRichard Henderson if (left) { 3613b88ce6f2SRichard Henderson tabl = 0x80c0e0f0f8fcfeffULL; 3614b88ce6f2SRichard Henderson tabr = 0xff7f3f1f0f070301ULL; 3615b88ce6f2SRichard Henderson } else { 3616b88ce6f2SRichard Henderson tabl = 0x0103070f1f3f7fffULL; 3617b88ce6f2SRichard Henderson tabr = 0xfffefcf8f0e0c080ULL; 3618b88ce6f2SRichard Henderson } 3619b88ce6f2SRichard Henderson break; 3620b88ce6f2SRichard Henderson case 16: 3621b88ce6f2SRichard Henderson imask = 0x6; 3622b88ce6f2SRichard Henderson shift = 1; 3623b88ce6f2SRichard Henderson omask = 0xf; 3624b88ce6f2SRichard Henderson if (left) { 3625b88ce6f2SRichard Henderson tabl = 0x8cef; 3626b88ce6f2SRichard Henderson tabr = 0xf731; 3627b88ce6f2SRichard Henderson } else { 3628b88ce6f2SRichard Henderson tabl = 0x137f; 3629b88ce6f2SRichard Henderson tabr = 0xfec8; 3630b88ce6f2SRichard Henderson } 3631b88ce6f2SRichard Henderson break; 3632b88ce6f2SRichard Henderson case 32: 3633b88ce6f2SRichard Henderson imask = 0x4; 3634b88ce6f2SRichard Henderson shift = 0; 3635b88ce6f2SRichard Henderson omask = 0x3; 3636b88ce6f2SRichard Henderson if (left) { 3637b88ce6f2SRichard Henderson tabl = (2 << 2) | 3; 3638b88ce6f2SRichard Henderson tabr = (3 << 2) | 1; 3639b88ce6f2SRichard Henderson } else { 3640b88ce6f2SRichard Henderson tabl = (1 << 2) | 3; 3641b88ce6f2SRichard Henderson tabr = (3 << 2) | 2; 3642b88ce6f2SRichard Henderson } 3643b88ce6f2SRichard Henderson break; 3644b88ce6f2SRichard Henderson default: 3645b88ce6f2SRichard Henderson abort(); 3646b88ce6f2SRichard Henderson } 3647b88ce6f2SRichard Henderson 3648b88ce6f2SRichard Henderson lo1 = tcg_temp_new(); 3649b88ce6f2SRichard Henderson lo2 = tcg_temp_new(); 3650b88ce6f2SRichard Henderson tcg_gen_andi_tl(lo1, s1, imask); 3651b88ce6f2SRichard Henderson tcg_gen_andi_tl(lo2, s2, imask); 3652b88ce6f2SRichard Henderson tcg_gen_shli_tl(lo1, lo1, shift); 3653b88ce6f2SRichard Henderson tcg_gen_shli_tl(lo2, lo2, shift); 3654b88ce6f2SRichard Henderson 3655b88ce6f2SRichard Henderson tcg_gen_shr_tl(lo1, tcg_constant_tl(tabl), lo1); 3656b88ce6f2SRichard Henderson tcg_gen_shr_tl(lo2, tcg_constant_tl(tabr), lo2); 3657b88ce6f2SRichard Henderson tcg_gen_andi_tl(lo1, lo1, omask); 3658b88ce6f2SRichard Henderson tcg_gen_andi_tl(lo2, lo2, omask); 3659b88ce6f2SRichard Henderson 3660b88ce6f2SRichard Henderson amask = address_mask_i(dc, -8); 3661b88ce6f2SRichard Henderson tcg_gen_andi_tl(s1, s1, amask); 3662b88ce6f2SRichard Henderson tcg_gen_andi_tl(s2, s2, amask); 3663b88ce6f2SRichard Henderson 3664b88ce6f2SRichard Henderson /* Compute dst = (s1 == s2 ? lo1 : lo1 & lo2). */ 3665b88ce6f2SRichard Henderson tcg_gen_and_tl(lo2, lo2, lo1); 3666b88ce6f2SRichard Henderson tcg_gen_movcond_tl(TCG_COND_EQ, dst, s1, s2, lo1, lo2); 3667b88ce6f2SRichard Henderson 3668b88ce6f2SRichard Henderson gen_store_gpr(dc, a->rd, dst); 3669b88ce6f2SRichard Henderson return advance_pc(dc); 3670b88ce6f2SRichard Henderson } 3671b88ce6f2SRichard Henderson 3672b88ce6f2SRichard Henderson TRANS(EDGE8cc, VIS1, gen_edge, a, 8, 1, 0) 3673b88ce6f2SRichard Henderson TRANS(EDGE8Lcc, VIS1, gen_edge, a, 8, 1, 1) 3674b88ce6f2SRichard Henderson TRANS(EDGE16cc, VIS1, gen_edge, a, 16, 1, 0) 3675b88ce6f2SRichard Henderson TRANS(EDGE16Lcc, VIS1, gen_edge, a, 16, 1, 1) 3676b88ce6f2SRichard Henderson TRANS(EDGE32cc, VIS1, gen_edge, a, 32, 1, 0) 3677b88ce6f2SRichard Henderson TRANS(EDGE32Lcc, VIS1, gen_edge, a, 32, 1, 1) 3678b88ce6f2SRichard Henderson 3679b88ce6f2SRichard Henderson TRANS(EDGE8N, VIS2, gen_edge, a, 8, 0, 0) 3680b88ce6f2SRichard Henderson TRANS(EDGE8LN, VIS2, gen_edge, a, 8, 0, 1) 3681b88ce6f2SRichard Henderson TRANS(EDGE16N, VIS2, gen_edge, a, 16, 0, 0) 3682b88ce6f2SRichard Henderson TRANS(EDGE16LN, VIS2, gen_edge, a, 16, 0, 1) 3683b88ce6f2SRichard Henderson TRANS(EDGE32N, VIS2, gen_edge, a, 32, 0, 0) 3684b88ce6f2SRichard Henderson TRANS(EDGE32LN, VIS2, gen_edge, a, 32, 0, 1) 3685b88ce6f2SRichard Henderson 368645bfed3bSRichard Henderson static bool do_rrr(DisasContext *dc, arg_r_r_r *a, 368745bfed3bSRichard Henderson void (*func)(TCGv, TCGv, TCGv)) 368845bfed3bSRichard Henderson { 368945bfed3bSRichard Henderson TCGv dst = gen_dest_gpr(dc, a->rd); 369045bfed3bSRichard Henderson TCGv src1 = gen_load_gpr(dc, a->rs1); 369145bfed3bSRichard Henderson TCGv src2 = gen_load_gpr(dc, a->rs2); 369245bfed3bSRichard Henderson 369345bfed3bSRichard Henderson func(dst, src1, src2); 369445bfed3bSRichard Henderson gen_store_gpr(dc, a->rd, dst); 369545bfed3bSRichard Henderson return advance_pc(dc); 369645bfed3bSRichard Henderson } 369745bfed3bSRichard Henderson 369845bfed3bSRichard Henderson TRANS(ARRAY8, VIS1, do_rrr, a, gen_helper_array8) 369945bfed3bSRichard Henderson TRANS(ARRAY16, VIS1, do_rrr, a, gen_op_array16) 370045bfed3bSRichard Henderson TRANS(ARRAY32, VIS1, do_rrr, a, gen_op_array32) 370145bfed3bSRichard Henderson 37029e20ca94SRichard Henderson static void gen_op_alignaddr(TCGv dst, TCGv s1, TCGv s2) 37039e20ca94SRichard Henderson { 37049e20ca94SRichard Henderson #ifdef TARGET_SPARC64 37059e20ca94SRichard Henderson TCGv tmp = tcg_temp_new(); 37069e20ca94SRichard Henderson 37079e20ca94SRichard Henderson tcg_gen_add_tl(tmp, s1, s2); 37089e20ca94SRichard Henderson tcg_gen_andi_tl(dst, tmp, -8); 37099e20ca94SRichard Henderson tcg_gen_deposit_tl(cpu_gsr, cpu_gsr, tmp, 0, 3); 37109e20ca94SRichard Henderson #else 37119e20ca94SRichard Henderson g_assert_not_reached(); 37129e20ca94SRichard Henderson #endif 37139e20ca94SRichard Henderson } 37149e20ca94SRichard Henderson 37159e20ca94SRichard Henderson static void gen_op_alignaddrl(TCGv dst, TCGv s1, TCGv s2) 37169e20ca94SRichard Henderson { 37179e20ca94SRichard Henderson #ifdef TARGET_SPARC64 37189e20ca94SRichard Henderson TCGv tmp = tcg_temp_new(); 37199e20ca94SRichard Henderson 37209e20ca94SRichard Henderson tcg_gen_add_tl(tmp, s1, s2); 37219e20ca94SRichard Henderson tcg_gen_andi_tl(dst, tmp, -8); 37229e20ca94SRichard Henderson tcg_gen_neg_tl(tmp, tmp); 37239e20ca94SRichard Henderson tcg_gen_deposit_tl(cpu_gsr, cpu_gsr, tmp, 0, 3); 37249e20ca94SRichard Henderson #else 37259e20ca94SRichard Henderson g_assert_not_reached(); 37269e20ca94SRichard Henderson #endif 37279e20ca94SRichard Henderson } 37289e20ca94SRichard Henderson 37299e20ca94SRichard Henderson TRANS(ALIGNADDR, VIS1, do_rrr, a, gen_op_alignaddr) 37309e20ca94SRichard Henderson TRANS(ALIGNADDRL, VIS1, do_rrr, a, gen_op_alignaddrl) 37319e20ca94SRichard Henderson 373239ca3490SRichard Henderson static void gen_op_bmask(TCGv dst, TCGv s1, TCGv s2) 373339ca3490SRichard Henderson { 373439ca3490SRichard Henderson #ifdef TARGET_SPARC64 373539ca3490SRichard Henderson tcg_gen_add_tl(dst, s1, s2); 373639ca3490SRichard Henderson tcg_gen_deposit_tl(cpu_gsr, cpu_gsr, dst, 32, 32); 373739ca3490SRichard Henderson #else 373839ca3490SRichard Henderson g_assert_not_reached(); 373939ca3490SRichard Henderson #endif 374039ca3490SRichard Henderson } 374139ca3490SRichard Henderson 374239ca3490SRichard Henderson TRANS(BMASK, VIS2, do_rrr, a, gen_op_bmask) 374339ca3490SRichard Henderson 37445fc546eeSRichard Henderson static bool do_shift_r(DisasContext *dc, arg_shiftr *a, bool l, bool u) 37455fc546eeSRichard Henderson { 37465fc546eeSRichard Henderson TCGv dst, src1, src2; 37475fc546eeSRichard Henderson 37485fc546eeSRichard Henderson /* Reject 64-bit shifts for sparc32. */ 37495fc546eeSRichard Henderson if (avail_32(dc) && a->x) { 37505fc546eeSRichard Henderson return false; 37515fc546eeSRichard Henderson } 37525fc546eeSRichard Henderson 37535fc546eeSRichard Henderson src2 = tcg_temp_new(); 37545fc546eeSRichard Henderson tcg_gen_andi_tl(src2, gen_load_gpr(dc, a->rs2), a->x ? 63 : 31); 37555fc546eeSRichard Henderson src1 = gen_load_gpr(dc, a->rs1); 37565fc546eeSRichard Henderson dst = gen_dest_gpr(dc, a->rd); 37575fc546eeSRichard Henderson 37585fc546eeSRichard Henderson if (l) { 37595fc546eeSRichard Henderson tcg_gen_shl_tl(dst, src1, src2); 37605fc546eeSRichard Henderson if (!a->x) { 37615fc546eeSRichard Henderson tcg_gen_ext32u_tl(dst, dst); 37625fc546eeSRichard Henderson } 37635fc546eeSRichard Henderson } else if (u) { 37645fc546eeSRichard Henderson if (!a->x) { 37655fc546eeSRichard Henderson tcg_gen_ext32u_tl(dst, src1); 37665fc546eeSRichard Henderson src1 = dst; 37675fc546eeSRichard Henderson } 37685fc546eeSRichard Henderson tcg_gen_shr_tl(dst, src1, src2); 37695fc546eeSRichard Henderson } else { 37705fc546eeSRichard Henderson if (!a->x) { 37715fc546eeSRichard Henderson tcg_gen_ext32s_tl(dst, src1); 37725fc546eeSRichard Henderson src1 = dst; 37735fc546eeSRichard Henderson } 37745fc546eeSRichard Henderson tcg_gen_sar_tl(dst, src1, src2); 37755fc546eeSRichard Henderson } 37765fc546eeSRichard Henderson gen_store_gpr(dc, a->rd, dst); 37775fc546eeSRichard Henderson return advance_pc(dc); 37785fc546eeSRichard Henderson } 37795fc546eeSRichard Henderson 37805fc546eeSRichard Henderson TRANS(SLL_r, ALL, do_shift_r, a, true, true) 37815fc546eeSRichard Henderson TRANS(SRL_r, ALL, do_shift_r, a, false, true) 37825fc546eeSRichard Henderson TRANS(SRA_r, ALL, do_shift_r, a, false, false) 37835fc546eeSRichard Henderson 37845fc546eeSRichard Henderson static bool do_shift_i(DisasContext *dc, arg_shifti *a, bool l, bool u) 37855fc546eeSRichard Henderson { 37865fc546eeSRichard Henderson TCGv dst, src1; 37875fc546eeSRichard Henderson 37885fc546eeSRichard Henderson /* Reject 64-bit shifts for sparc32. */ 37895fc546eeSRichard Henderson if (avail_32(dc) && (a->x || a->i >= 32)) { 37905fc546eeSRichard Henderson return false; 37915fc546eeSRichard Henderson } 37925fc546eeSRichard Henderson 37935fc546eeSRichard Henderson src1 = gen_load_gpr(dc, a->rs1); 37945fc546eeSRichard Henderson dst = gen_dest_gpr(dc, a->rd); 37955fc546eeSRichard Henderson 37965fc546eeSRichard Henderson if (avail_32(dc) || a->x) { 37975fc546eeSRichard Henderson if (l) { 37985fc546eeSRichard Henderson tcg_gen_shli_tl(dst, src1, a->i); 37995fc546eeSRichard Henderson } else if (u) { 38005fc546eeSRichard Henderson tcg_gen_shri_tl(dst, src1, a->i); 38015fc546eeSRichard Henderson } else { 38025fc546eeSRichard Henderson tcg_gen_sari_tl(dst, src1, a->i); 38035fc546eeSRichard Henderson } 38045fc546eeSRichard Henderson } else { 38055fc546eeSRichard Henderson if (l) { 38065fc546eeSRichard Henderson tcg_gen_deposit_z_tl(dst, src1, a->i, 32 - a->i); 38075fc546eeSRichard Henderson } else if (u) { 38085fc546eeSRichard Henderson tcg_gen_extract_tl(dst, src1, a->i, 32 - a->i); 38095fc546eeSRichard Henderson } else { 38105fc546eeSRichard Henderson tcg_gen_sextract_tl(dst, src1, a->i, 32 - a->i); 38115fc546eeSRichard Henderson } 38125fc546eeSRichard Henderson } 38135fc546eeSRichard Henderson gen_store_gpr(dc, a->rd, dst); 38145fc546eeSRichard Henderson return advance_pc(dc); 38155fc546eeSRichard Henderson } 38165fc546eeSRichard Henderson 38175fc546eeSRichard Henderson TRANS(SLL_i, ALL, do_shift_i, a, true, true) 38185fc546eeSRichard Henderson TRANS(SRL_i, ALL, do_shift_i, a, false, true) 38195fc546eeSRichard Henderson TRANS(SRA_i, ALL, do_shift_i, a, false, false) 38205fc546eeSRichard Henderson 3821fb4ed7aaSRichard Henderson static TCGv gen_rs2_or_imm(DisasContext *dc, bool imm, int rs2_or_imm) 3822fb4ed7aaSRichard Henderson { 3823fb4ed7aaSRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 3824fb4ed7aaSRichard Henderson if (!imm && rs2_or_imm & ~0x1f) { 3825fb4ed7aaSRichard Henderson return NULL; 3826fb4ed7aaSRichard Henderson } 3827fb4ed7aaSRichard Henderson if (imm || rs2_or_imm == 0) { 3828fb4ed7aaSRichard Henderson return tcg_constant_tl(rs2_or_imm); 3829fb4ed7aaSRichard Henderson } else { 3830fb4ed7aaSRichard Henderson return cpu_regs[rs2_or_imm]; 3831fb4ed7aaSRichard Henderson } 3832fb4ed7aaSRichard Henderson } 3833fb4ed7aaSRichard Henderson 3834fb4ed7aaSRichard Henderson static bool do_mov_cond(DisasContext *dc, DisasCompare *cmp, int rd, TCGv src2) 3835fb4ed7aaSRichard Henderson { 3836fb4ed7aaSRichard Henderson TCGv dst = gen_load_gpr(dc, rd); 3837c8507ebfSRichard Henderson TCGv c2 = tcg_constant_tl(cmp->c2); 3838fb4ed7aaSRichard Henderson 3839c8507ebfSRichard Henderson tcg_gen_movcond_tl(cmp->cond, dst, cmp->c1, c2, src2, dst); 3840fb4ed7aaSRichard Henderson gen_store_gpr(dc, rd, dst); 3841fb4ed7aaSRichard Henderson return advance_pc(dc); 3842fb4ed7aaSRichard Henderson } 3843fb4ed7aaSRichard Henderson 3844fb4ed7aaSRichard Henderson static bool trans_MOVcc(DisasContext *dc, arg_MOVcc *a) 3845fb4ed7aaSRichard Henderson { 3846fb4ed7aaSRichard Henderson TCGv src2 = gen_rs2_or_imm(dc, a->imm, a->rs2_or_imm); 3847fb4ed7aaSRichard Henderson DisasCompare cmp; 3848fb4ed7aaSRichard Henderson 3849fb4ed7aaSRichard Henderson if (src2 == NULL) { 3850fb4ed7aaSRichard Henderson return false; 3851fb4ed7aaSRichard Henderson } 3852fb4ed7aaSRichard Henderson gen_compare(&cmp, a->cc, a->cond, dc); 3853fb4ed7aaSRichard Henderson return do_mov_cond(dc, &cmp, a->rd, src2); 3854fb4ed7aaSRichard Henderson } 3855fb4ed7aaSRichard Henderson 3856fb4ed7aaSRichard Henderson static bool trans_MOVfcc(DisasContext *dc, arg_MOVfcc *a) 3857fb4ed7aaSRichard Henderson { 3858fb4ed7aaSRichard Henderson TCGv src2 = gen_rs2_or_imm(dc, a->imm, a->rs2_or_imm); 3859fb4ed7aaSRichard Henderson DisasCompare cmp; 3860fb4ed7aaSRichard Henderson 3861fb4ed7aaSRichard Henderson if (src2 == NULL) { 3862fb4ed7aaSRichard Henderson return false; 3863fb4ed7aaSRichard Henderson } 3864fb4ed7aaSRichard Henderson gen_fcompare(&cmp, a->cc, a->cond); 3865fb4ed7aaSRichard Henderson return do_mov_cond(dc, &cmp, a->rd, src2); 3866fb4ed7aaSRichard Henderson } 3867fb4ed7aaSRichard Henderson 3868fb4ed7aaSRichard Henderson static bool trans_MOVR(DisasContext *dc, arg_MOVR *a) 3869fb4ed7aaSRichard Henderson { 3870fb4ed7aaSRichard Henderson TCGv src2 = gen_rs2_or_imm(dc, a->imm, a->rs2_or_imm); 3871fb4ed7aaSRichard Henderson DisasCompare cmp; 3872fb4ed7aaSRichard Henderson 3873fb4ed7aaSRichard Henderson if (src2 == NULL) { 3874fb4ed7aaSRichard Henderson return false; 3875fb4ed7aaSRichard Henderson } 3876fb4ed7aaSRichard Henderson gen_compare_reg(&cmp, a->cond, gen_load_gpr(dc, a->rs1)); 3877fb4ed7aaSRichard Henderson return do_mov_cond(dc, &cmp, a->rd, src2); 3878fb4ed7aaSRichard Henderson } 3879fb4ed7aaSRichard Henderson 388086b82fe0SRichard Henderson static bool do_add_special(DisasContext *dc, arg_r_r_ri *a, 388186b82fe0SRichard Henderson bool (*func)(DisasContext *dc, int rd, TCGv src)) 388286b82fe0SRichard Henderson { 388386b82fe0SRichard Henderson TCGv src1, sum; 388486b82fe0SRichard Henderson 388586b82fe0SRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 388686b82fe0SRichard Henderson if (!a->imm && a->rs2_or_imm & ~0x1f) { 388786b82fe0SRichard Henderson return false; 388886b82fe0SRichard Henderson } 388986b82fe0SRichard Henderson 389086b82fe0SRichard Henderson /* 389186b82fe0SRichard Henderson * Always load the sum into a new temporary. 389286b82fe0SRichard Henderson * This is required to capture the value across a window change, 389386b82fe0SRichard Henderson * e.g. SAVE and RESTORE, and may be optimized away otherwise. 389486b82fe0SRichard Henderson */ 389586b82fe0SRichard Henderson sum = tcg_temp_new(); 389686b82fe0SRichard Henderson src1 = gen_load_gpr(dc, a->rs1); 389786b82fe0SRichard Henderson if (a->imm || a->rs2_or_imm == 0) { 389886b82fe0SRichard Henderson tcg_gen_addi_tl(sum, src1, a->rs2_or_imm); 389986b82fe0SRichard Henderson } else { 390086b82fe0SRichard Henderson tcg_gen_add_tl(sum, src1, cpu_regs[a->rs2_or_imm]); 390186b82fe0SRichard Henderson } 390286b82fe0SRichard Henderson return func(dc, a->rd, sum); 390386b82fe0SRichard Henderson } 390486b82fe0SRichard Henderson 390586b82fe0SRichard Henderson static bool do_jmpl(DisasContext *dc, int rd, TCGv src) 390686b82fe0SRichard Henderson { 390786b82fe0SRichard Henderson /* 390886b82fe0SRichard Henderson * Preserve pc across advance, so that we can delay 390986b82fe0SRichard Henderson * the writeback to rd until after src is consumed. 391086b82fe0SRichard Henderson */ 391186b82fe0SRichard Henderson target_ulong cur_pc = dc->pc; 391286b82fe0SRichard Henderson 391386b82fe0SRichard Henderson gen_check_align(dc, src, 3); 391486b82fe0SRichard Henderson 391586b82fe0SRichard Henderson gen_mov_pc_npc(dc); 391686b82fe0SRichard Henderson tcg_gen_mov_tl(cpu_npc, src); 391786b82fe0SRichard Henderson gen_address_mask(dc, cpu_npc); 391886b82fe0SRichard Henderson gen_store_gpr(dc, rd, tcg_constant_tl(cur_pc)); 391986b82fe0SRichard Henderson 392086b82fe0SRichard Henderson dc->npc = DYNAMIC_PC_LOOKUP; 392186b82fe0SRichard Henderson return true; 392286b82fe0SRichard Henderson } 392386b82fe0SRichard Henderson 392486b82fe0SRichard Henderson TRANS(JMPL, ALL, do_add_special, a, do_jmpl) 392586b82fe0SRichard Henderson 392686b82fe0SRichard Henderson static bool do_rett(DisasContext *dc, int rd, TCGv src) 392786b82fe0SRichard Henderson { 392886b82fe0SRichard Henderson if (!supervisor(dc)) { 392986b82fe0SRichard Henderson return raise_priv(dc); 393086b82fe0SRichard Henderson } 393186b82fe0SRichard Henderson 393286b82fe0SRichard Henderson gen_check_align(dc, src, 3); 393386b82fe0SRichard Henderson 393486b82fe0SRichard Henderson gen_mov_pc_npc(dc); 393586b82fe0SRichard Henderson tcg_gen_mov_tl(cpu_npc, src); 393686b82fe0SRichard Henderson gen_helper_rett(tcg_env); 393786b82fe0SRichard Henderson 393886b82fe0SRichard Henderson dc->npc = DYNAMIC_PC; 393986b82fe0SRichard Henderson return true; 394086b82fe0SRichard Henderson } 394186b82fe0SRichard Henderson 394286b82fe0SRichard Henderson TRANS(RETT, 32, do_add_special, a, do_rett) 394386b82fe0SRichard Henderson 394486b82fe0SRichard Henderson static bool do_return(DisasContext *dc, int rd, TCGv src) 394586b82fe0SRichard Henderson { 394686b82fe0SRichard Henderson gen_check_align(dc, src, 3); 394786b82fe0SRichard Henderson 394886b82fe0SRichard Henderson gen_mov_pc_npc(dc); 394986b82fe0SRichard Henderson tcg_gen_mov_tl(cpu_npc, src); 395086b82fe0SRichard Henderson gen_address_mask(dc, cpu_npc); 395186b82fe0SRichard Henderson 395286b82fe0SRichard Henderson gen_helper_restore(tcg_env); 395386b82fe0SRichard Henderson dc->npc = DYNAMIC_PC_LOOKUP; 395486b82fe0SRichard Henderson return true; 395586b82fe0SRichard Henderson } 395686b82fe0SRichard Henderson 395786b82fe0SRichard Henderson TRANS(RETURN, 64, do_add_special, a, do_return) 395886b82fe0SRichard Henderson 3959d3825800SRichard Henderson static bool do_save(DisasContext *dc, int rd, TCGv src) 3960d3825800SRichard Henderson { 3961d3825800SRichard Henderson gen_helper_save(tcg_env); 3962d3825800SRichard Henderson gen_store_gpr(dc, rd, src); 3963d3825800SRichard Henderson return advance_pc(dc); 3964d3825800SRichard Henderson } 3965d3825800SRichard Henderson 3966d3825800SRichard Henderson TRANS(SAVE, ALL, do_add_special, a, do_save) 3967d3825800SRichard Henderson 3968d3825800SRichard Henderson static bool do_restore(DisasContext *dc, int rd, TCGv src) 3969d3825800SRichard Henderson { 3970d3825800SRichard Henderson gen_helper_restore(tcg_env); 3971d3825800SRichard Henderson gen_store_gpr(dc, rd, src); 3972d3825800SRichard Henderson return advance_pc(dc); 3973d3825800SRichard Henderson } 3974d3825800SRichard Henderson 3975d3825800SRichard Henderson TRANS(RESTORE, ALL, do_add_special, a, do_restore) 3976d3825800SRichard Henderson 39778f75b8a4SRichard Henderson static bool do_done_retry(DisasContext *dc, bool done) 39788f75b8a4SRichard Henderson { 39798f75b8a4SRichard Henderson if (!supervisor(dc)) { 39808f75b8a4SRichard Henderson return raise_priv(dc); 39818f75b8a4SRichard Henderson } 39828f75b8a4SRichard Henderson dc->npc = DYNAMIC_PC; 39838f75b8a4SRichard Henderson dc->pc = DYNAMIC_PC; 39848f75b8a4SRichard Henderson translator_io_start(&dc->base); 39858f75b8a4SRichard Henderson if (done) { 39868f75b8a4SRichard Henderson gen_helper_done(tcg_env); 39878f75b8a4SRichard Henderson } else { 39888f75b8a4SRichard Henderson gen_helper_retry(tcg_env); 39898f75b8a4SRichard Henderson } 39908f75b8a4SRichard Henderson return true; 39918f75b8a4SRichard Henderson } 39928f75b8a4SRichard Henderson 39938f75b8a4SRichard Henderson TRANS(DONE, 64, do_done_retry, true) 39948f75b8a4SRichard Henderson TRANS(RETRY, 64, do_done_retry, false) 39958f75b8a4SRichard Henderson 39960880d20bSRichard Henderson /* 39970880d20bSRichard Henderson * Major opcode 11 -- load and store instructions 39980880d20bSRichard Henderson */ 39990880d20bSRichard Henderson 40000880d20bSRichard Henderson static TCGv gen_ldst_addr(DisasContext *dc, int rs1, bool imm, int rs2_or_imm) 40010880d20bSRichard Henderson { 40020880d20bSRichard Henderson TCGv addr, tmp = NULL; 40030880d20bSRichard Henderson 40040880d20bSRichard Henderson /* For simplicity, we under-decoded the rs2 form. */ 40050880d20bSRichard Henderson if (!imm && rs2_or_imm & ~0x1f) { 40060880d20bSRichard Henderson return NULL; 40070880d20bSRichard Henderson } 40080880d20bSRichard Henderson 40090880d20bSRichard Henderson addr = gen_load_gpr(dc, rs1); 40100880d20bSRichard Henderson if (rs2_or_imm) { 40110880d20bSRichard Henderson tmp = tcg_temp_new(); 40120880d20bSRichard Henderson if (imm) { 40130880d20bSRichard Henderson tcg_gen_addi_tl(tmp, addr, rs2_or_imm); 40140880d20bSRichard Henderson } else { 40150880d20bSRichard Henderson tcg_gen_add_tl(tmp, addr, cpu_regs[rs2_or_imm]); 40160880d20bSRichard Henderson } 40170880d20bSRichard Henderson addr = tmp; 40180880d20bSRichard Henderson } 40190880d20bSRichard Henderson if (AM_CHECK(dc)) { 40200880d20bSRichard Henderson if (!tmp) { 40210880d20bSRichard Henderson tmp = tcg_temp_new(); 40220880d20bSRichard Henderson } 40230880d20bSRichard Henderson tcg_gen_ext32u_tl(tmp, addr); 40240880d20bSRichard Henderson addr = tmp; 40250880d20bSRichard Henderson } 40260880d20bSRichard Henderson return addr; 40270880d20bSRichard Henderson } 40280880d20bSRichard Henderson 40290880d20bSRichard Henderson static bool do_ld_gpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp mop) 40300880d20bSRichard Henderson { 40310880d20bSRichard Henderson TCGv reg, addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 40320880d20bSRichard Henderson DisasASI da; 40330880d20bSRichard Henderson 40340880d20bSRichard Henderson if (addr == NULL) { 40350880d20bSRichard Henderson return false; 40360880d20bSRichard Henderson } 40370880d20bSRichard Henderson da = resolve_asi(dc, a->asi, mop); 40380880d20bSRichard Henderson 40390880d20bSRichard Henderson reg = gen_dest_gpr(dc, a->rd); 404042071fc1SRichard Henderson gen_ld_asi(dc, &da, reg, addr); 40410880d20bSRichard Henderson gen_store_gpr(dc, a->rd, reg); 40420880d20bSRichard Henderson return advance_pc(dc); 40430880d20bSRichard Henderson } 40440880d20bSRichard Henderson 40450880d20bSRichard Henderson TRANS(LDUW, ALL, do_ld_gpr, a, MO_TEUL) 40460880d20bSRichard Henderson TRANS(LDUB, ALL, do_ld_gpr, a, MO_UB) 40470880d20bSRichard Henderson TRANS(LDUH, ALL, do_ld_gpr, a, MO_TEUW) 40480880d20bSRichard Henderson TRANS(LDSB, ALL, do_ld_gpr, a, MO_SB) 40490880d20bSRichard Henderson TRANS(LDSH, ALL, do_ld_gpr, a, MO_TESW) 40500880d20bSRichard Henderson TRANS(LDSW, 64, do_ld_gpr, a, MO_TESL) 40510880d20bSRichard Henderson TRANS(LDX, 64, do_ld_gpr, a, MO_TEUQ) 40520880d20bSRichard Henderson 40530880d20bSRichard Henderson static bool do_st_gpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp mop) 40540880d20bSRichard Henderson { 40550880d20bSRichard Henderson TCGv reg, addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 40560880d20bSRichard Henderson DisasASI da; 40570880d20bSRichard Henderson 40580880d20bSRichard Henderson if (addr == NULL) { 40590880d20bSRichard Henderson return false; 40600880d20bSRichard Henderson } 40610880d20bSRichard Henderson da = resolve_asi(dc, a->asi, mop); 40620880d20bSRichard Henderson 40630880d20bSRichard Henderson reg = gen_load_gpr(dc, a->rd); 406442071fc1SRichard Henderson gen_st_asi(dc, &da, reg, addr); 40650880d20bSRichard Henderson return advance_pc(dc); 40660880d20bSRichard Henderson } 40670880d20bSRichard Henderson 40680880d20bSRichard Henderson TRANS(STW, ALL, do_st_gpr, a, MO_TEUL) 40690880d20bSRichard Henderson TRANS(STB, ALL, do_st_gpr, a, MO_UB) 40700880d20bSRichard Henderson TRANS(STH, ALL, do_st_gpr, a, MO_TEUW) 40710880d20bSRichard Henderson TRANS(STX, 64, do_st_gpr, a, MO_TEUQ) 40720880d20bSRichard Henderson 40730880d20bSRichard Henderson static bool trans_LDD(DisasContext *dc, arg_r_r_ri_asi *a) 40740880d20bSRichard Henderson { 40750880d20bSRichard Henderson TCGv addr; 40760880d20bSRichard Henderson DisasASI da; 40770880d20bSRichard Henderson 40780880d20bSRichard Henderson if (a->rd & 1) { 40790880d20bSRichard Henderson return false; 40800880d20bSRichard Henderson } 40810880d20bSRichard Henderson addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 40820880d20bSRichard Henderson if (addr == NULL) { 40830880d20bSRichard Henderson return false; 40840880d20bSRichard Henderson } 40850880d20bSRichard Henderson da = resolve_asi(dc, a->asi, MO_TEUQ); 408642071fc1SRichard Henderson gen_ldda_asi(dc, &da, addr, a->rd); 40870880d20bSRichard Henderson return advance_pc(dc); 40880880d20bSRichard Henderson } 40890880d20bSRichard Henderson 40900880d20bSRichard Henderson static bool trans_STD(DisasContext *dc, arg_r_r_ri_asi *a) 40910880d20bSRichard Henderson { 40920880d20bSRichard Henderson TCGv addr; 40930880d20bSRichard Henderson DisasASI da; 40940880d20bSRichard Henderson 40950880d20bSRichard Henderson if (a->rd & 1) { 40960880d20bSRichard Henderson return false; 40970880d20bSRichard Henderson } 40980880d20bSRichard Henderson addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 40990880d20bSRichard Henderson if (addr == NULL) { 41000880d20bSRichard Henderson return false; 41010880d20bSRichard Henderson } 41020880d20bSRichard Henderson da = resolve_asi(dc, a->asi, MO_TEUQ); 410342071fc1SRichard Henderson gen_stda_asi(dc, &da, addr, a->rd); 41040880d20bSRichard Henderson return advance_pc(dc); 41050880d20bSRichard Henderson } 41060880d20bSRichard Henderson 4107cf07cd1eSRichard Henderson static bool trans_LDSTUB(DisasContext *dc, arg_r_r_ri_asi *a) 4108cf07cd1eSRichard Henderson { 4109cf07cd1eSRichard Henderson TCGv addr, reg; 4110cf07cd1eSRichard Henderson DisasASI da; 4111cf07cd1eSRichard Henderson 4112cf07cd1eSRichard Henderson addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 4113cf07cd1eSRichard Henderson if (addr == NULL) { 4114cf07cd1eSRichard Henderson return false; 4115cf07cd1eSRichard Henderson } 4116cf07cd1eSRichard Henderson da = resolve_asi(dc, a->asi, MO_UB); 4117cf07cd1eSRichard Henderson 4118cf07cd1eSRichard Henderson reg = gen_dest_gpr(dc, a->rd); 4119cf07cd1eSRichard Henderson gen_ldstub_asi(dc, &da, reg, addr); 4120cf07cd1eSRichard Henderson gen_store_gpr(dc, a->rd, reg); 4121cf07cd1eSRichard Henderson return advance_pc(dc); 4122cf07cd1eSRichard Henderson } 4123cf07cd1eSRichard Henderson 4124dca544b9SRichard Henderson static bool trans_SWAP(DisasContext *dc, arg_r_r_ri_asi *a) 4125dca544b9SRichard Henderson { 4126dca544b9SRichard Henderson TCGv addr, dst, src; 4127dca544b9SRichard Henderson DisasASI da; 4128dca544b9SRichard Henderson 4129dca544b9SRichard Henderson addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 4130dca544b9SRichard Henderson if (addr == NULL) { 4131dca544b9SRichard Henderson return false; 4132dca544b9SRichard Henderson } 4133dca544b9SRichard Henderson da = resolve_asi(dc, a->asi, MO_TEUL); 4134dca544b9SRichard Henderson 4135dca544b9SRichard Henderson dst = gen_dest_gpr(dc, a->rd); 4136dca544b9SRichard Henderson src = gen_load_gpr(dc, a->rd); 4137dca544b9SRichard Henderson gen_swap_asi(dc, &da, dst, src, addr); 4138dca544b9SRichard Henderson gen_store_gpr(dc, a->rd, dst); 4139dca544b9SRichard Henderson return advance_pc(dc); 4140dca544b9SRichard Henderson } 4141dca544b9SRichard Henderson 4142d0a11d25SRichard Henderson static bool do_casa(DisasContext *dc, arg_r_r_ri_asi *a, MemOp mop) 4143d0a11d25SRichard Henderson { 4144d0a11d25SRichard Henderson TCGv addr, o, n, c; 4145d0a11d25SRichard Henderson DisasASI da; 4146d0a11d25SRichard Henderson 4147d0a11d25SRichard Henderson addr = gen_ldst_addr(dc, a->rs1, true, 0); 4148d0a11d25SRichard Henderson if (addr == NULL) { 4149d0a11d25SRichard Henderson return false; 4150d0a11d25SRichard Henderson } 4151d0a11d25SRichard Henderson da = resolve_asi(dc, a->asi, mop); 4152d0a11d25SRichard Henderson 4153d0a11d25SRichard Henderson o = gen_dest_gpr(dc, a->rd); 4154d0a11d25SRichard Henderson n = gen_load_gpr(dc, a->rd); 4155d0a11d25SRichard Henderson c = gen_load_gpr(dc, a->rs2_or_imm); 4156d0a11d25SRichard Henderson gen_cas_asi(dc, &da, o, n, c, addr); 4157d0a11d25SRichard Henderson gen_store_gpr(dc, a->rd, o); 4158d0a11d25SRichard Henderson return advance_pc(dc); 4159d0a11d25SRichard Henderson } 4160d0a11d25SRichard Henderson 4161d0a11d25SRichard Henderson TRANS(CASA, CASA, do_casa, a, MO_TEUL) 4162d0a11d25SRichard Henderson TRANS(CASXA, 64, do_casa, a, MO_TEUQ) 4163d0a11d25SRichard Henderson 416406c060d9SRichard Henderson static bool do_ld_fpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp sz) 416506c060d9SRichard Henderson { 416606c060d9SRichard Henderson TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 416706c060d9SRichard Henderson DisasASI da; 416806c060d9SRichard Henderson 416906c060d9SRichard Henderson if (addr == NULL) { 417006c060d9SRichard Henderson return false; 417106c060d9SRichard Henderson } 417206c060d9SRichard Henderson if (gen_trap_ifnofpu(dc)) { 417306c060d9SRichard Henderson return true; 417406c060d9SRichard Henderson } 417506c060d9SRichard Henderson if (sz == MO_128 && gen_trap_float128(dc)) { 417606c060d9SRichard Henderson return true; 417706c060d9SRichard Henderson } 417806c060d9SRichard Henderson da = resolve_asi(dc, a->asi, MO_TE | sz); 4179287b1152SRichard Henderson gen_ldf_asi(dc, &da, sz, addr, a->rd); 418006c060d9SRichard Henderson gen_update_fprs_dirty(dc, a->rd); 418106c060d9SRichard Henderson return advance_pc(dc); 418206c060d9SRichard Henderson } 418306c060d9SRichard Henderson 418406c060d9SRichard Henderson TRANS(LDF, ALL, do_ld_fpr, a, MO_32) 418506c060d9SRichard Henderson TRANS(LDDF, ALL, do_ld_fpr, a, MO_64) 418606c060d9SRichard Henderson TRANS(LDQF, ALL, do_ld_fpr, a, MO_128) 418706c060d9SRichard Henderson 4188287b1152SRichard Henderson TRANS(LDFA, 64, do_ld_fpr, a, MO_32) 4189287b1152SRichard Henderson TRANS(LDDFA, 64, do_ld_fpr, a, MO_64) 4190287b1152SRichard Henderson TRANS(LDQFA, 64, do_ld_fpr, a, MO_128) 4191287b1152SRichard Henderson 419206c060d9SRichard Henderson static bool do_st_fpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp sz) 419306c060d9SRichard Henderson { 419406c060d9SRichard Henderson TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 419506c060d9SRichard Henderson DisasASI da; 419606c060d9SRichard Henderson 419706c060d9SRichard Henderson if (addr == NULL) { 419806c060d9SRichard Henderson return false; 419906c060d9SRichard Henderson } 420006c060d9SRichard Henderson if (gen_trap_ifnofpu(dc)) { 420106c060d9SRichard Henderson return true; 420206c060d9SRichard Henderson } 420306c060d9SRichard Henderson if (sz == MO_128 && gen_trap_float128(dc)) { 420406c060d9SRichard Henderson return true; 420506c060d9SRichard Henderson } 420606c060d9SRichard Henderson da = resolve_asi(dc, a->asi, MO_TE | sz); 4207287b1152SRichard Henderson gen_stf_asi(dc, &da, sz, addr, a->rd); 420806c060d9SRichard Henderson return advance_pc(dc); 420906c060d9SRichard Henderson } 421006c060d9SRichard Henderson 421106c060d9SRichard Henderson TRANS(STF, ALL, do_st_fpr, a, MO_32) 421206c060d9SRichard Henderson TRANS(STDF, ALL, do_st_fpr, a, MO_64) 421306c060d9SRichard Henderson TRANS(STQF, ALL, do_st_fpr, a, MO_128) 421406c060d9SRichard Henderson 4215287b1152SRichard Henderson TRANS(STFA, 64, do_st_fpr, a, MO_32) 4216287b1152SRichard Henderson TRANS(STDFA, 64, do_st_fpr, a, MO_64) 4217287b1152SRichard Henderson TRANS(STQFA, 64, do_st_fpr, a, MO_128) 4218287b1152SRichard Henderson 421906c060d9SRichard Henderson static bool trans_STDFQ(DisasContext *dc, arg_STDFQ *a) 422006c060d9SRichard Henderson { 422106c060d9SRichard Henderson if (!avail_32(dc)) { 422206c060d9SRichard Henderson return false; 422306c060d9SRichard Henderson } 422406c060d9SRichard Henderson if (!supervisor(dc)) { 422506c060d9SRichard Henderson return raise_priv(dc); 422606c060d9SRichard Henderson } 422706c060d9SRichard Henderson if (gen_trap_ifnofpu(dc)) { 422806c060d9SRichard Henderson return true; 422906c060d9SRichard Henderson } 423006c060d9SRichard Henderson gen_op_fpexception_im(dc, FSR_FTT_SEQ_ERROR); 423106c060d9SRichard Henderson return true; 423206c060d9SRichard Henderson } 423306c060d9SRichard Henderson 4234da681406SRichard Henderson static bool do_ldfsr(DisasContext *dc, arg_r_r_ri *a, MemOp mop, 4235da681406SRichard Henderson target_ulong new_mask, target_ulong old_mask) 42363d3c0673SRichard Henderson { 4237da681406SRichard Henderson TCGv tmp, addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 42383d3c0673SRichard Henderson if (addr == NULL) { 42393d3c0673SRichard Henderson return false; 42403d3c0673SRichard Henderson } 42413d3c0673SRichard Henderson if (gen_trap_ifnofpu(dc)) { 42423d3c0673SRichard Henderson return true; 42433d3c0673SRichard Henderson } 4244da681406SRichard Henderson tmp = tcg_temp_new(); 4245da681406SRichard Henderson tcg_gen_qemu_ld_tl(tmp, addr, dc->mem_idx, mop | MO_ALIGN); 4246da681406SRichard Henderson tcg_gen_andi_tl(tmp, tmp, new_mask); 4247da681406SRichard Henderson tcg_gen_andi_tl(cpu_fsr, cpu_fsr, old_mask); 4248da681406SRichard Henderson tcg_gen_or_tl(cpu_fsr, cpu_fsr, tmp); 4249da681406SRichard Henderson gen_helper_set_fsr(tcg_env, cpu_fsr); 42503d3c0673SRichard Henderson return advance_pc(dc); 42513d3c0673SRichard Henderson } 42523d3c0673SRichard Henderson 4253da681406SRichard Henderson TRANS(LDFSR, ALL, do_ldfsr, a, MO_TEUL, FSR_LDFSR_MASK, FSR_LDFSR_OLDMASK) 4254da681406SRichard Henderson TRANS(LDXFSR, 64, do_ldfsr, a, MO_TEUQ, FSR_LDXFSR_MASK, FSR_LDXFSR_OLDMASK) 42553d3c0673SRichard Henderson 42563d3c0673SRichard Henderson static bool do_stfsr(DisasContext *dc, arg_r_r_ri *a, MemOp mop) 42573d3c0673SRichard Henderson { 42583d3c0673SRichard Henderson TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm); 42593d3c0673SRichard Henderson if (addr == NULL) { 42603d3c0673SRichard Henderson return false; 42613d3c0673SRichard Henderson } 42623d3c0673SRichard Henderson if (gen_trap_ifnofpu(dc)) { 42633d3c0673SRichard Henderson return true; 42643d3c0673SRichard Henderson } 42653d3c0673SRichard Henderson tcg_gen_qemu_st_tl(cpu_fsr, addr, dc->mem_idx, mop | MO_ALIGN); 42663d3c0673SRichard Henderson return advance_pc(dc); 42673d3c0673SRichard Henderson } 42683d3c0673SRichard Henderson 42693d3c0673SRichard Henderson TRANS(STFSR, ALL, do_stfsr, a, MO_TEUL) 42703d3c0673SRichard Henderson TRANS(STXFSR, 64, do_stfsr, a, MO_TEUQ) 42713d3c0673SRichard Henderson 42723a38260eSRichard Henderson static bool do_fc(DisasContext *dc, int rd, bool c) 42733a38260eSRichard Henderson { 42743a38260eSRichard Henderson uint64_t mask; 42753a38260eSRichard Henderson 42763a38260eSRichard Henderson if (gen_trap_ifnofpu(dc)) { 42773a38260eSRichard Henderson return true; 42783a38260eSRichard Henderson } 42793a38260eSRichard Henderson 42803a38260eSRichard Henderson if (rd & 1) { 42813a38260eSRichard Henderson mask = MAKE_64BIT_MASK(0, 32); 42823a38260eSRichard Henderson } else { 42833a38260eSRichard Henderson mask = MAKE_64BIT_MASK(32, 32); 42843a38260eSRichard Henderson } 42853a38260eSRichard Henderson if (c) { 42863a38260eSRichard Henderson tcg_gen_ori_i64(cpu_fpr[rd / 2], cpu_fpr[rd / 2], mask); 42873a38260eSRichard Henderson } else { 42883a38260eSRichard Henderson tcg_gen_andi_i64(cpu_fpr[rd / 2], cpu_fpr[rd / 2], ~mask); 42893a38260eSRichard Henderson } 42903a38260eSRichard Henderson gen_update_fprs_dirty(dc, rd); 42913a38260eSRichard Henderson return advance_pc(dc); 42923a38260eSRichard Henderson } 42933a38260eSRichard Henderson 42943a38260eSRichard Henderson TRANS(FZEROs, VIS1, do_fc, a->rd, 0) 42953a38260eSRichard Henderson TRANS(FONEs, VIS1, do_fc, a->rd, 1) 42963a38260eSRichard Henderson 42973a38260eSRichard Henderson static bool do_dc(DisasContext *dc, int rd, int64_t c) 42983a38260eSRichard Henderson { 42993a38260eSRichard Henderson if (gen_trap_ifnofpu(dc)) { 43003a38260eSRichard Henderson return true; 43013a38260eSRichard Henderson } 43023a38260eSRichard Henderson 43033a38260eSRichard Henderson tcg_gen_movi_i64(cpu_fpr[rd / 2], c); 43043a38260eSRichard Henderson gen_update_fprs_dirty(dc, rd); 43053a38260eSRichard Henderson return advance_pc(dc); 43063a38260eSRichard Henderson } 43073a38260eSRichard Henderson 43083a38260eSRichard Henderson TRANS(FZEROd, VIS1, do_dc, a->rd, 0) 43093a38260eSRichard Henderson TRANS(FONEd, VIS1, do_dc, a->rd, -1) 43103a38260eSRichard Henderson 4311baf3dbf2SRichard Henderson static bool do_ff(DisasContext *dc, arg_r_r *a, 4312baf3dbf2SRichard Henderson void (*func)(TCGv_i32, TCGv_i32)) 4313baf3dbf2SRichard Henderson { 4314baf3dbf2SRichard Henderson TCGv_i32 tmp; 4315baf3dbf2SRichard Henderson 4316baf3dbf2SRichard Henderson if (gen_trap_ifnofpu(dc)) { 4317baf3dbf2SRichard Henderson return true; 4318baf3dbf2SRichard Henderson } 4319baf3dbf2SRichard Henderson 4320baf3dbf2SRichard Henderson tmp = gen_load_fpr_F(dc, a->rs); 4321baf3dbf2SRichard Henderson func(tmp, tmp); 4322baf3dbf2SRichard Henderson gen_store_fpr_F(dc, a->rd, tmp); 4323baf3dbf2SRichard Henderson return advance_pc(dc); 4324baf3dbf2SRichard Henderson } 4325baf3dbf2SRichard Henderson 4326baf3dbf2SRichard Henderson TRANS(FMOVs, ALL, do_ff, a, gen_op_fmovs) 4327baf3dbf2SRichard Henderson TRANS(FNEGs, ALL, do_ff, a, gen_op_fnegs) 4328baf3dbf2SRichard Henderson TRANS(FABSs, ALL, do_ff, a, gen_op_fabss) 4329baf3dbf2SRichard Henderson TRANS(FSRCs, VIS1, do_ff, a, tcg_gen_mov_i32) 4330baf3dbf2SRichard Henderson TRANS(FNOTs, VIS1, do_ff, a, tcg_gen_not_i32) 4331baf3dbf2SRichard Henderson 43322f722641SRichard Henderson static bool do_fd(DisasContext *dc, arg_r_r *a, 43332f722641SRichard Henderson void (*func)(TCGv_i32, TCGv_i64)) 43342f722641SRichard Henderson { 43352f722641SRichard Henderson TCGv_i32 dst; 43362f722641SRichard Henderson TCGv_i64 src; 43372f722641SRichard Henderson 43382f722641SRichard Henderson if (gen_trap_ifnofpu(dc)) { 43392f722641SRichard Henderson return true; 43402f722641SRichard Henderson } 43412f722641SRichard Henderson 43422f722641SRichard Henderson dst = gen_dest_fpr_F(dc); 43432f722641SRichard Henderson src = gen_load_fpr_D(dc, a->rs); 43442f722641SRichard Henderson func(dst, src); 43452f722641SRichard Henderson gen_store_fpr_F(dc, a->rd, dst); 43462f722641SRichard Henderson return advance_pc(dc); 43472f722641SRichard Henderson } 43482f722641SRichard Henderson 43492f722641SRichard Henderson TRANS(FPACK16, VIS1, do_fd, a, gen_op_fpack16) 43502f722641SRichard Henderson TRANS(FPACKFIX, VIS1, do_fd, a, gen_op_fpackfix) 43512f722641SRichard Henderson 4352119cb94fSRichard Henderson static bool do_env_ff(DisasContext *dc, arg_r_r *a, 4353119cb94fSRichard Henderson void (*func)(TCGv_i32, TCGv_env, TCGv_i32)) 4354119cb94fSRichard Henderson { 4355119cb94fSRichard Henderson TCGv_i32 tmp; 4356119cb94fSRichard Henderson 4357119cb94fSRichard Henderson if (gen_trap_ifnofpu(dc)) { 4358119cb94fSRichard Henderson return true; 4359119cb94fSRichard Henderson } 4360119cb94fSRichard Henderson 4361119cb94fSRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 4362119cb94fSRichard Henderson tmp = gen_load_fpr_F(dc, a->rs); 4363119cb94fSRichard Henderson func(tmp, tcg_env, tmp); 4364119cb94fSRichard Henderson gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env); 4365119cb94fSRichard Henderson gen_store_fpr_F(dc, a->rd, tmp); 4366119cb94fSRichard Henderson return advance_pc(dc); 4367119cb94fSRichard Henderson } 4368119cb94fSRichard Henderson 4369119cb94fSRichard Henderson TRANS(FSQRTs, ALL, do_env_ff, a, gen_helper_fsqrts) 4370119cb94fSRichard Henderson TRANS(FiTOs, ALL, do_env_ff, a, gen_helper_fitos) 4371119cb94fSRichard Henderson TRANS(FsTOi, ALL, do_env_ff, a, gen_helper_fstoi) 4372119cb94fSRichard Henderson 43738c94bcd8SRichard Henderson static bool do_env_fd(DisasContext *dc, arg_r_r *a, 43748c94bcd8SRichard Henderson void (*func)(TCGv_i32, TCGv_env, TCGv_i64)) 43758c94bcd8SRichard Henderson { 43768c94bcd8SRichard Henderson TCGv_i32 dst; 43778c94bcd8SRichard Henderson TCGv_i64 src; 43788c94bcd8SRichard Henderson 43798c94bcd8SRichard Henderson if (gen_trap_ifnofpu(dc)) { 43808c94bcd8SRichard Henderson return true; 43818c94bcd8SRichard Henderson } 43828c94bcd8SRichard Henderson 43838c94bcd8SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 43848c94bcd8SRichard Henderson dst = gen_dest_fpr_F(dc); 43858c94bcd8SRichard Henderson src = gen_load_fpr_D(dc, a->rs); 43868c94bcd8SRichard Henderson func(dst, tcg_env, src); 43878c94bcd8SRichard Henderson gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env); 43888c94bcd8SRichard Henderson gen_store_fpr_F(dc, a->rd, dst); 43898c94bcd8SRichard Henderson return advance_pc(dc); 43908c94bcd8SRichard Henderson } 43918c94bcd8SRichard Henderson 43928c94bcd8SRichard Henderson TRANS(FdTOs, ALL, do_env_fd, a, gen_helper_fdtos) 43938c94bcd8SRichard Henderson TRANS(FdTOi, ALL, do_env_fd, a, gen_helper_fdtoi) 43948c94bcd8SRichard Henderson TRANS(FxTOs, 64, do_env_fd, a, gen_helper_fxtos) 43958c94bcd8SRichard Henderson 4396c6d83e4fSRichard Henderson static bool do_dd(DisasContext *dc, arg_r_r *a, 4397c6d83e4fSRichard Henderson void (*func)(TCGv_i64, TCGv_i64)) 4398c6d83e4fSRichard Henderson { 4399c6d83e4fSRichard Henderson TCGv_i64 dst, src; 4400c6d83e4fSRichard Henderson 4401c6d83e4fSRichard Henderson if (gen_trap_ifnofpu(dc)) { 4402c6d83e4fSRichard Henderson return true; 4403c6d83e4fSRichard Henderson } 4404c6d83e4fSRichard Henderson 4405c6d83e4fSRichard Henderson dst = gen_dest_fpr_D(dc, a->rd); 4406c6d83e4fSRichard Henderson src = gen_load_fpr_D(dc, a->rs); 4407c6d83e4fSRichard Henderson func(dst, src); 4408c6d83e4fSRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 4409c6d83e4fSRichard Henderson return advance_pc(dc); 4410c6d83e4fSRichard Henderson } 4411c6d83e4fSRichard Henderson 4412c6d83e4fSRichard Henderson TRANS(FMOVd, 64, do_dd, a, gen_op_fmovd) 4413c6d83e4fSRichard Henderson TRANS(FNEGd, 64, do_dd, a, gen_op_fnegd) 4414c6d83e4fSRichard Henderson TRANS(FABSd, 64, do_dd, a, gen_op_fabsd) 4415c6d83e4fSRichard Henderson TRANS(FSRCd, VIS1, do_dd, a, tcg_gen_mov_i64) 4416c6d83e4fSRichard Henderson TRANS(FNOTd, VIS1, do_dd, a, tcg_gen_not_i64) 4417c6d83e4fSRichard Henderson 44188aa418b3SRichard Henderson static bool do_env_dd(DisasContext *dc, arg_r_r *a, 44198aa418b3SRichard Henderson void (*func)(TCGv_i64, TCGv_env, TCGv_i64)) 44208aa418b3SRichard Henderson { 44218aa418b3SRichard Henderson TCGv_i64 dst, src; 44228aa418b3SRichard Henderson 44238aa418b3SRichard Henderson if (gen_trap_ifnofpu(dc)) { 44248aa418b3SRichard Henderson return true; 44258aa418b3SRichard Henderson } 44268aa418b3SRichard Henderson 44278aa418b3SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 44288aa418b3SRichard Henderson dst = gen_dest_fpr_D(dc, a->rd); 44298aa418b3SRichard Henderson src = gen_load_fpr_D(dc, a->rs); 44308aa418b3SRichard Henderson func(dst, tcg_env, src); 44318aa418b3SRichard Henderson gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env); 44328aa418b3SRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 44338aa418b3SRichard Henderson return advance_pc(dc); 44348aa418b3SRichard Henderson } 44358aa418b3SRichard Henderson 44368aa418b3SRichard Henderson TRANS(FSQRTd, ALL, do_env_dd, a, gen_helper_fsqrtd) 44378aa418b3SRichard Henderson TRANS(FxTOd, 64, do_env_dd, a, gen_helper_fxtod) 44388aa418b3SRichard Henderson TRANS(FdTOx, 64, do_env_dd, a, gen_helper_fdtox) 44398aa418b3SRichard Henderson 4440199d43efSRichard Henderson static bool do_env_df(DisasContext *dc, arg_r_r *a, 4441199d43efSRichard Henderson void (*func)(TCGv_i64, TCGv_env, TCGv_i32)) 4442199d43efSRichard Henderson { 4443199d43efSRichard Henderson TCGv_i64 dst; 4444199d43efSRichard Henderson TCGv_i32 src; 4445199d43efSRichard Henderson 4446199d43efSRichard Henderson if (gen_trap_ifnofpu(dc)) { 4447199d43efSRichard Henderson return true; 4448199d43efSRichard Henderson } 4449199d43efSRichard Henderson 4450199d43efSRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 4451199d43efSRichard Henderson dst = gen_dest_fpr_D(dc, a->rd); 4452199d43efSRichard Henderson src = gen_load_fpr_F(dc, a->rs); 4453199d43efSRichard Henderson func(dst, tcg_env, src); 4454199d43efSRichard Henderson gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env); 4455199d43efSRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 4456199d43efSRichard Henderson return advance_pc(dc); 4457199d43efSRichard Henderson } 4458199d43efSRichard Henderson 4459199d43efSRichard Henderson TRANS(FiTOd, ALL, do_env_df, a, gen_helper_fitod) 4460199d43efSRichard Henderson TRANS(FsTOd, ALL, do_env_df, a, gen_helper_fstod) 4461199d43efSRichard Henderson TRANS(FsTOx, 64, do_env_df, a, gen_helper_fstox) 4462199d43efSRichard Henderson 4463f4e18df5SRichard Henderson static bool trans_FMOVq(DisasContext *dc, arg_FMOVq *a) 4464f4e18df5SRichard Henderson { 4465f4e18df5SRichard Henderson int rd, rs; 4466f4e18df5SRichard Henderson 4467f4e18df5SRichard Henderson if (!avail_64(dc)) { 4468f4e18df5SRichard Henderson return false; 4469f4e18df5SRichard Henderson } 4470f4e18df5SRichard Henderson if (gen_trap_ifnofpu(dc)) { 4471f4e18df5SRichard Henderson return true; 4472f4e18df5SRichard Henderson } 4473f4e18df5SRichard Henderson if (gen_trap_float128(dc)) { 4474f4e18df5SRichard Henderson return true; 4475f4e18df5SRichard Henderson } 4476f4e18df5SRichard Henderson 4477f4e18df5SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 4478f4e18df5SRichard Henderson rd = QFPREG(a->rd); 4479f4e18df5SRichard Henderson rs = QFPREG(a->rs); 4480f4e18df5SRichard Henderson tcg_gen_mov_i64(cpu_fpr[rd / 2], cpu_fpr[rs / 2]); 4481f4e18df5SRichard Henderson tcg_gen_mov_i64(cpu_fpr[rd / 2 + 1], cpu_fpr[rs / 2 + 1]); 4482f4e18df5SRichard Henderson gen_update_fprs_dirty(dc, rd); 4483f4e18df5SRichard Henderson return advance_pc(dc); 4484f4e18df5SRichard Henderson } 4485f4e18df5SRichard Henderson 4486f4e18df5SRichard Henderson static bool do_qq(DisasContext *dc, arg_r_r *a, 4487f4e18df5SRichard Henderson void (*func)(TCGv_env)) 4488f4e18df5SRichard Henderson { 4489f4e18df5SRichard Henderson if (gen_trap_ifnofpu(dc)) { 4490f4e18df5SRichard Henderson return true; 4491f4e18df5SRichard Henderson } 4492f4e18df5SRichard Henderson if (gen_trap_float128(dc)) { 4493f4e18df5SRichard Henderson return true; 4494f4e18df5SRichard Henderson } 4495f4e18df5SRichard Henderson 4496f4e18df5SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 4497f4e18df5SRichard Henderson gen_op_load_fpr_QT1(QFPREG(a->rs)); 4498f4e18df5SRichard Henderson func(tcg_env); 4499f4e18df5SRichard Henderson gen_op_store_QT0_fpr(QFPREG(a->rd)); 4500f4e18df5SRichard Henderson gen_update_fprs_dirty(dc, QFPREG(a->rd)); 4501f4e18df5SRichard Henderson return advance_pc(dc); 4502f4e18df5SRichard Henderson } 4503f4e18df5SRichard Henderson 4504f4e18df5SRichard Henderson TRANS(FNEGq, 64, do_qq, a, gen_helper_fnegq) 4505f4e18df5SRichard Henderson TRANS(FABSq, 64, do_qq, a, gen_helper_fabsq) 4506f4e18df5SRichard Henderson 4507c995216bSRichard Henderson static bool do_env_qq(DisasContext *dc, arg_r_r *a, 4508c995216bSRichard Henderson void (*func)(TCGv_env)) 4509c995216bSRichard Henderson { 4510c995216bSRichard Henderson if (gen_trap_ifnofpu(dc)) { 4511c995216bSRichard Henderson return true; 4512c995216bSRichard Henderson } 4513c995216bSRichard Henderson if (gen_trap_float128(dc)) { 4514c995216bSRichard Henderson return true; 4515c995216bSRichard Henderson } 4516c995216bSRichard Henderson 4517c995216bSRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 4518c995216bSRichard Henderson gen_op_load_fpr_QT1(QFPREG(a->rs)); 4519c995216bSRichard Henderson func(tcg_env); 4520c995216bSRichard Henderson gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env); 4521c995216bSRichard Henderson gen_op_store_QT0_fpr(QFPREG(a->rd)); 4522c995216bSRichard Henderson gen_update_fprs_dirty(dc, QFPREG(a->rd)); 4523c995216bSRichard Henderson return advance_pc(dc); 4524c995216bSRichard Henderson } 4525c995216bSRichard Henderson 4526c995216bSRichard Henderson TRANS(FSQRTq, ALL, do_env_qq, a, gen_helper_fsqrtq) 4527c995216bSRichard Henderson 4528bd9c5c42SRichard Henderson static bool do_env_fq(DisasContext *dc, arg_r_r *a, 4529bd9c5c42SRichard Henderson void (*func)(TCGv_i32, TCGv_env)) 4530bd9c5c42SRichard Henderson { 4531bd9c5c42SRichard Henderson TCGv_i32 dst; 4532bd9c5c42SRichard Henderson 4533bd9c5c42SRichard Henderson if (gen_trap_ifnofpu(dc)) { 4534bd9c5c42SRichard Henderson return true; 4535bd9c5c42SRichard Henderson } 4536bd9c5c42SRichard Henderson if (gen_trap_float128(dc)) { 4537bd9c5c42SRichard Henderson return true; 4538bd9c5c42SRichard Henderson } 4539bd9c5c42SRichard Henderson 4540bd9c5c42SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 4541bd9c5c42SRichard Henderson gen_op_load_fpr_QT1(QFPREG(a->rs)); 4542bd9c5c42SRichard Henderson dst = gen_dest_fpr_F(dc); 4543bd9c5c42SRichard Henderson func(dst, tcg_env); 4544bd9c5c42SRichard Henderson gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env); 4545bd9c5c42SRichard Henderson gen_store_fpr_F(dc, a->rd, dst); 4546bd9c5c42SRichard Henderson return advance_pc(dc); 4547bd9c5c42SRichard Henderson } 4548bd9c5c42SRichard Henderson 4549bd9c5c42SRichard Henderson TRANS(FqTOs, ALL, do_env_fq, a, gen_helper_fqtos) 4550bd9c5c42SRichard Henderson TRANS(FqTOi, ALL, do_env_fq, a, gen_helper_fqtoi) 4551bd9c5c42SRichard Henderson 45521617586fSRichard Henderson static bool do_env_dq(DisasContext *dc, arg_r_r *a, 45531617586fSRichard Henderson void (*func)(TCGv_i64, TCGv_env)) 45541617586fSRichard Henderson { 45551617586fSRichard Henderson TCGv_i64 dst; 45561617586fSRichard Henderson 45571617586fSRichard Henderson if (gen_trap_ifnofpu(dc)) { 45581617586fSRichard Henderson return true; 45591617586fSRichard Henderson } 45601617586fSRichard Henderson if (gen_trap_float128(dc)) { 45611617586fSRichard Henderson return true; 45621617586fSRichard Henderson } 45631617586fSRichard Henderson 45641617586fSRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 45651617586fSRichard Henderson gen_op_load_fpr_QT1(QFPREG(a->rs)); 45661617586fSRichard Henderson dst = gen_dest_fpr_D(dc, a->rd); 45671617586fSRichard Henderson func(dst, tcg_env); 45681617586fSRichard Henderson gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env); 45691617586fSRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 45701617586fSRichard Henderson return advance_pc(dc); 45711617586fSRichard Henderson } 45721617586fSRichard Henderson 45731617586fSRichard Henderson TRANS(FqTOd, ALL, do_env_dq, a, gen_helper_fqtod) 45741617586fSRichard Henderson TRANS(FqTOx, 64, do_env_dq, a, gen_helper_fqtox) 45751617586fSRichard Henderson 457613ebcc77SRichard Henderson static bool do_env_qf(DisasContext *dc, arg_r_r *a, 457713ebcc77SRichard Henderson void (*func)(TCGv_env, TCGv_i32)) 457813ebcc77SRichard Henderson { 457913ebcc77SRichard Henderson TCGv_i32 src; 458013ebcc77SRichard Henderson 458113ebcc77SRichard Henderson if (gen_trap_ifnofpu(dc)) { 458213ebcc77SRichard Henderson return true; 458313ebcc77SRichard Henderson } 458413ebcc77SRichard Henderson if (gen_trap_float128(dc)) { 458513ebcc77SRichard Henderson return true; 458613ebcc77SRichard Henderson } 458713ebcc77SRichard Henderson 458813ebcc77SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 458913ebcc77SRichard Henderson src = gen_load_fpr_F(dc, a->rs); 459013ebcc77SRichard Henderson func(tcg_env, src); 459113ebcc77SRichard Henderson gen_op_store_QT0_fpr(QFPREG(a->rd)); 459213ebcc77SRichard Henderson gen_update_fprs_dirty(dc, QFPREG(a->rd)); 459313ebcc77SRichard Henderson return advance_pc(dc); 459413ebcc77SRichard Henderson } 459513ebcc77SRichard Henderson 459613ebcc77SRichard Henderson TRANS(FiTOq, ALL, do_env_qf, a, gen_helper_fitoq) 459713ebcc77SRichard Henderson TRANS(FsTOq, ALL, do_env_qf, a, gen_helper_fstoq) 459813ebcc77SRichard Henderson 45997b8e3e1aSRichard Henderson static bool do_env_qd(DisasContext *dc, arg_r_r *a, 46007b8e3e1aSRichard Henderson void (*func)(TCGv_env, TCGv_i64)) 46017b8e3e1aSRichard Henderson { 46027b8e3e1aSRichard Henderson TCGv_i64 src; 46037b8e3e1aSRichard Henderson 46047b8e3e1aSRichard Henderson if (gen_trap_ifnofpu(dc)) { 46057b8e3e1aSRichard Henderson return true; 46067b8e3e1aSRichard Henderson } 46077b8e3e1aSRichard Henderson if (gen_trap_float128(dc)) { 46087b8e3e1aSRichard Henderson return true; 46097b8e3e1aSRichard Henderson } 46107b8e3e1aSRichard Henderson 46117b8e3e1aSRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 46127b8e3e1aSRichard Henderson src = gen_load_fpr_D(dc, a->rs); 46137b8e3e1aSRichard Henderson func(tcg_env, src); 46147b8e3e1aSRichard Henderson gen_op_store_QT0_fpr(QFPREG(a->rd)); 46157b8e3e1aSRichard Henderson gen_update_fprs_dirty(dc, QFPREG(a->rd)); 46167b8e3e1aSRichard Henderson return advance_pc(dc); 46177b8e3e1aSRichard Henderson } 46187b8e3e1aSRichard Henderson 46197b8e3e1aSRichard Henderson TRANS(FdTOq, ALL, do_env_qd, a, gen_helper_fdtoq) 46207b8e3e1aSRichard Henderson TRANS(FxTOq, 64, do_env_qd, a, gen_helper_fxtoq) 46217b8e3e1aSRichard Henderson 46227f10b52fSRichard Henderson static bool do_fff(DisasContext *dc, arg_r_r_r *a, 46237f10b52fSRichard Henderson void (*func)(TCGv_i32, TCGv_i32, TCGv_i32)) 46247f10b52fSRichard Henderson { 46257f10b52fSRichard Henderson TCGv_i32 src1, src2; 46267f10b52fSRichard Henderson 46277f10b52fSRichard Henderson if (gen_trap_ifnofpu(dc)) { 46287f10b52fSRichard Henderson return true; 46297f10b52fSRichard Henderson } 46307f10b52fSRichard Henderson 46317f10b52fSRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1); 46327f10b52fSRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2); 46337f10b52fSRichard Henderson func(src1, src1, src2); 46347f10b52fSRichard Henderson gen_store_fpr_F(dc, a->rd, src1); 46357f10b52fSRichard Henderson return advance_pc(dc); 46367f10b52fSRichard Henderson } 46377f10b52fSRichard Henderson 46387f10b52fSRichard Henderson TRANS(FPADD16s, VIS1, do_fff, a, tcg_gen_vec_add16_i32) 46397f10b52fSRichard Henderson TRANS(FPADD32s, VIS1, do_fff, a, tcg_gen_add_i32) 46407f10b52fSRichard Henderson TRANS(FPSUB16s, VIS1, do_fff, a, tcg_gen_vec_sub16_i32) 46417f10b52fSRichard Henderson TRANS(FPSUB32s, VIS1, do_fff, a, tcg_gen_sub_i32) 46427f10b52fSRichard Henderson TRANS(FNORs, VIS1, do_fff, a, tcg_gen_nor_i32) 46437f10b52fSRichard Henderson TRANS(FANDNOTs, VIS1, do_fff, a, tcg_gen_andc_i32) 46447f10b52fSRichard Henderson TRANS(FXORs, VIS1, do_fff, a, tcg_gen_xor_i32) 46457f10b52fSRichard Henderson TRANS(FNANDs, VIS1, do_fff, a, tcg_gen_nand_i32) 46467f10b52fSRichard Henderson TRANS(FANDs, VIS1, do_fff, a, tcg_gen_and_i32) 46477f10b52fSRichard Henderson TRANS(FXNORs, VIS1, do_fff, a, tcg_gen_eqv_i32) 46487f10b52fSRichard Henderson TRANS(FORNOTs, VIS1, do_fff, a, tcg_gen_orc_i32) 46497f10b52fSRichard Henderson TRANS(FORs, VIS1, do_fff, a, tcg_gen_or_i32) 46507f10b52fSRichard Henderson 4651c1514961SRichard Henderson static bool do_env_fff(DisasContext *dc, arg_r_r_r *a, 4652c1514961SRichard Henderson void (*func)(TCGv_i32, TCGv_env, TCGv_i32, TCGv_i32)) 4653c1514961SRichard Henderson { 4654c1514961SRichard Henderson TCGv_i32 src1, src2; 4655c1514961SRichard Henderson 4656c1514961SRichard Henderson if (gen_trap_ifnofpu(dc)) { 4657c1514961SRichard Henderson return true; 4658c1514961SRichard Henderson } 4659c1514961SRichard Henderson 4660c1514961SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 4661c1514961SRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1); 4662c1514961SRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2); 4663c1514961SRichard Henderson func(src1, tcg_env, src1, src2); 4664c1514961SRichard Henderson gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env); 4665c1514961SRichard Henderson gen_store_fpr_F(dc, a->rd, src1); 4666c1514961SRichard Henderson return advance_pc(dc); 4667c1514961SRichard Henderson } 4668c1514961SRichard Henderson 4669c1514961SRichard Henderson TRANS(FADDs, ALL, do_env_fff, a, gen_helper_fadds) 4670c1514961SRichard Henderson TRANS(FSUBs, ALL, do_env_fff, a, gen_helper_fsubs) 4671c1514961SRichard Henderson TRANS(FMULs, ALL, do_env_fff, a, gen_helper_fmuls) 4672c1514961SRichard Henderson TRANS(FDIVs, ALL, do_env_fff, a, gen_helper_fdivs) 4673c1514961SRichard Henderson 4674e06c9f83SRichard Henderson static bool do_ddd(DisasContext *dc, arg_r_r_r *a, 4675e06c9f83SRichard Henderson void (*func)(TCGv_i64, TCGv_i64, TCGv_i64)) 4676e06c9f83SRichard Henderson { 4677e06c9f83SRichard Henderson TCGv_i64 dst, src1, src2; 4678e06c9f83SRichard Henderson 4679e06c9f83SRichard Henderson if (gen_trap_ifnofpu(dc)) { 4680e06c9f83SRichard Henderson return true; 4681e06c9f83SRichard Henderson } 4682e06c9f83SRichard Henderson 4683e06c9f83SRichard Henderson dst = gen_dest_fpr_D(dc, a->rd); 4684e06c9f83SRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1); 4685e06c9f83SRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2); 4686e06c9f83SRichard Henderson func(dst, src1, src2); 4687e06c9f83SRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 4688e06c9f83SRichard Henderson return advance_pc(dc); 4689e06c9f83SRichard Henderson } 4690e06c9f83SRichard Henderson 4691e06c9f83SRichard Henderson TRANS(FMUL8x16, VIS1, do_ddd, a, gen_helper_fmul8x16) 4692e06c9f83SRichard Henderson TRANS(FMUL8x16AU, VIS1, do_ddd, a, gen_helper_fmul8x16au) 4693e06c9f83SRichard Henderson TRANS(FMUL8x16AL, VIS1, do_ddd, a, gen_helper_fmul8x16al) 4694e06c9f83SRichard Henderson TRANS(FMUL8SUx16, VIS1, do_ddd, a, gen_helper_fmul8sux16) 4695e06c9f83SRichard Henderson TRANS(FMUL8ULx16, VIS1, do_ddd, a, gen_helper_fmul8ulx16) 4696e06c9f83SRichard Henderson TRANS(FMULD8SUx16, VIS1, do_ddd, a, gen_helper_fmuld8sux16) 4697e06c9f83SRichard Henderson TRANS(FMULD8ULx16, VIS1, do_ddd, a, gen_helper_fmuld8ulx16) 4698e06c9f83SRichard Henderson TRANS(FPMERGE, VIS1, do_ddd, a, gen_helper_fpmerge) 4699e06c9f83SRichard Henderson TRANS(FEXPAND, VIS1, do_ddd, a, gen_helper_fexpand) 4700e06c9f83SRichard Henderson 4701e06c9f83SRichard Henderson TRANS(FPADD16, VIS1, do_ddd, a, tcg_gen_vec_add16_i64) 4702e06c9f83SRichard Henderson TRANS(FPADD32, VIS1, do_ddd, a, tcg_gen_vec_add32_i64) 4703e06c9f83SRichard Henderson TRANS(FPSUB16, VIS1, do_ddd, a, tcg_gen_vec_sub16_i64) 4704e06c9f83SRichard Henderson TRANS(FPSUB32, VIS1, do_ddd, a, tcg_gen_vec_sub32_i64) 4705e06c9f83SRichard Henderson TRANS(FNORd, VIS1, do_ddd, a, tcg_gen_nor_i64) 4706e06c9f83SRichard Henderson TRANS(FANDNOTd, VIS1, do_ddd, a, tcg_gen_andc_i64) 4707e06c9f83SRichard Henderson TRANS(FXORd, VIS1, do_ddd, a, tcg_gen_xor_i64) 4708e06c9f83SRichard Henderson TRANS(FNANDd, VIS1, do_ddd, a, tcg_gen_nand_i64) 4709e06c9f83SRichard Henderson TRANS(FANDd, VIS1, do_ddd, a, tcg_gen_and_i64) 4710e06c9f83SRichard Henderson TRANS(FXNORd, VIS1, do_ddd, a, tcg_gen_eqv_i64) 4711e06c9f83SRichard Henderson TRANS(FORNOTd, VIS1, do_ddd, a, tcg_gen_orc_i64) 4712e06c9f83SRichard Henderson TRANS(FORd, VIS1, do_ddd, a, tcg_gen_or_i64) 4713e06c9f83SRichard Henderson 47144b6edc0aSRichard Henderson TRANS(FPACK32, VIS1, do_ddd, a, gen_op_fpack32) 47154b6edc0aSRichard Henderson TRANS(FALIGNDATAg, VIS1, do_ddd, a, gen_op_faligndata) 47164b6edc0aSRichard Henderson TRANS(BSHUFFLE, VIS2, do_ddd, a, gen_op_bshuffle) 47174b6edc0aSRichard Henderson 4718e2fa6bd1SRichard Henderson static bool do_rdd(DisasContext *dc, arg_r_r_r *a, 4719e2fa6bd1SRichard Henderson void (*func)(TCGv, TCGv_i64, TCGv_i64)) 4720e2fa6bd1SRichard Henderson { 4721e2fa6bd1SRichard Henderson TCGv_i64 src1, src2; 4722e2fa6bd1SRichard Henderson TCGv dst; 4723e2fa6bd1SRichard Henderson 4724e2fa6bd1SRichard Henderson if (gen_trap_ifnofpu(dc)) { 4725e2fa6bd1SRichard Henderson return true; 4726e2fa6bd1SRichard Henderson } 4727e2fa6bd1SRichard Henderson 4728e2fa6bd1SRichard Henderson dst = gen_dest_gpr(dc, a->rd); 4729e2fa6bd1SRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1); 4730e2fa6bd1SRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2); 4731e2fa6bd1SRichard Henderson func(dst, src1, src2); 4732e2fa6bd1SRichard Henderson gen_store_gpr(dc, a->rd, dst); 4733e2fa6bd1SRichard Henderson return advance_pc(dc); 4734e2fa6bd1SRichard Henderson } 4735e2fa6bd1SRichard Henderson 4736e2fa6bd1SRichard Henderson TRANS(FPCMPLE16, VIS1, do_rdd, a, gen_helper_fcmple16) 4737e2fa6bd1SRichard Henderson TRANS(FPCMPNE16, VIS1, do_rdd, a, gen_helper_fcmpne16) 4738e2fa6bd1SRichard Henderson TRANS(FPCMPGT16, VIS1, do_rdd, a, gen_helper_fcmpgt16) 4739e2fa6bd1SRichard Henderson TRANS(FPCMPEQ16, VIS1, do_rdd, a, gen_helper_fcmpeq16) 4740e2fa6bd1SRichard Henderson 4741e2fa6bd1SRichard Henderson TRANS(FPCMPLE32, VIS1, do_rdd, a, gen_helper_fcmple32) 4742e2fa6bd1SRichard Henderson TRANS(FPCMPNE32, VIS1, do_rdd, a, gen_helper_fcmpne32) 4743e2fa6bd1SRichard Henderson TRANS(FPCMPGT32, VIS1, do_rdd, a, gen_helper_fcmpgt32) 4744e2fa6bd1SRichard Henderson TRANS(FPCMPEQ32, VIS1, do_rdd, a, gen_helper_fcmpeq32) 4745e2fa6bd1SRichard Henderson 4746f2a59b0aSRichard Henderson static bool do_env_ddd(DisasContext *dc, arg_r_r_r *a, 4747f2a59b0aSRichard Henderson void (*func)(TCGv_i64, TCGv_env, TCGv_i64, TCGv_i64)) 4748f2a59b0aSRichard Henderson { 4749f2a59b0aSRichard Henderson TCGv_i64 dst, src1, src2; 4750f2a59b0aSRichard Henderson 4751f2a59b0aSRichard Henderson if (gen_trap_ifnofpu(dc)) { 4752f2a59b0aSRichard Henderson return true; 4753f2a59b0aSRichard Henderson } 4754f2a59b0aSRichard Henderson 4755f2a59b0aSRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 4756f2a59b0aSRichard Henderson dst = gen_dest_fpr_D(dc, a->rd); 4757f2a59b0aSRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1); 4758f2a59b0aSRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2); 4759f2a59b0aSRichard Henderson func(dst, tcg_env, src1, src2); 4760f2a59b0aSRichard Henderson gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env); 4761f2a59b0aSRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 4762f2a59b0aSRichard Henderson return advance_pc(dc); 4763f2a59b0aSRichard Henderson } 4764f2a59b0aSRichard Henderson 4765f2a59b0aSRichard Henderson TRANS(FADDd, ALL, do_env_ddd, a, gen_helper_faddd) 4766f2a59b0aSRichard Henderson TRANS(FSUBd, ALL, do_env_ddd, a, gen_helper_fsubd) 4767f2a59b0aSRichard Henderson TRANS(FMULd, ALL, do_env_ddd, a, gen_helper_fmuld) 4768f2a59b0aSRichard Henderson TRANS(FDIVd, ALL, do_env_ddd, a, gen_helper_fdivd) 4769f2a59b0aSRichard Henderson 4770ff4c711bSRichard Henderson static bool trans_FsMULd(DisasContext *dc, arg_r_r_r *a) 4771ff4c711bSRichard Henderson { 4772ff4c711bSRichard Henderson TCGv_i64 dst; 4773ff4c711bSRichard Henderson TCGv_i32 src1, src2; 4774ff4c711bSRichard Henderson 4775ff4c711bSRichard Henderson if (gen_trap_ifnofpu(dc)) { 4776ff4c711bSRichard Henderson return true; 4777ff4c711bSRichard Henderson } 4778ff4c711bSRichard Henderson if (!(dc->def->features & CPU_FEATURE_FSMULD)) { 4779ff4c711bSRichard Henderson return raise_unimpfpop(dc); 4780ff4c711bSRichard Henderson } 4781ff4c711bSRichard Henderson 4782ff4c711bSRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 4783ff4c711bSRichard Henderson dst = gen_dest_fpr_D(dc, a->rd); 4784ff4c711bSRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1); 4785ff4c711bSRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2); 4786ff4c711bSRichard Henderson gen_helper_fsmuld(dst, tcg_env, src1, src2); 4787ff4c711bSRichard Henderson gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env); 4788ff4c711bSRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 4789ff4c711bSRichard Henderson return advance_pc(dc); 4790ff4c711bSRichard Henderson } 4791ff4c711bSRichard Henderson 4792afb04344SRichard Henderson static bool do_dddd(DisasContext *dc, arg_r_r_r *a, 4793afb04344SRichard Henderson void (*func)(TCGv_i64, TCGv_i64, TCGv_i64, TCGv_i64)) 4794afb04344SRichard Henderson { 4795afb04344SRichard Henderson TCGv_i64 dst, src0, src1, src2; 4796afb04344SRichard Henderson 4797afb04344SRichard Henderson if (gen_trap_ifnofpu(dc)) { 4798afb04344SRichard Henderson return true; 4799afb04344SRichard Henderson } 4800afb04344SRichard Henderson 4801afb04344SRichard Henderson dst = gen_dest_fpr_D(dc, a->rd); 4802afb04344SRichard Henderson src0 = gen_load_fpr_D(dc, a->rd); 4803afb04344SRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1); 4804afb04344SRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2); 4805afb04344SRichard Henderson func(dst, src0, src1, src2); 4806afb04344SRichard Henderson gen_store_fpr_D(dc, a->rd, dst); 4807afb04344SRichard Henderson return advance_pc(dc); 4808afb04344SRichard Henderson } 4809afb04344SRichard Henderson 4810afb04344SRichard Henderson TRANS(PDIST, VIS1, do_dddd, a, gen_helper_pdist) 4811afb04344SRichard Henderson 4812a4056239SRichard Henderson static bool do_env_qqq(DisasContext *dc, arg_r_r_r *a, 4813a4056239SRichard Henderson void (*func)(TCGv_env)) 4814a4056239SRichard Henderson { 4815a4056239SRichard Henderson if (gen_trap_ifnofpu(dc)) { 4816a4056239SRichard Henderson return true; 4817a4056239SRichard Henderson } 4818a4056239SRichard Henderson if (gen_trap_float128(dc)) { 4819a4056239SRichard Henderson return true; 4820a4056239SRichard Henderson } 4821a4056239SRichard Henderson 4822a4056239SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 4823a4056239SRichard Henderson gen_op_load_fpr_QT0(QFPREG(a->rs1)); 4824a4056239SRichard Henderson gen_op_load_fpr_QT1(QFPREG(a->rs2)); 4825a4056239SRichard Henderson func(tcg_env); 4826a4056239SRichard Henderson gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env); 4827a4056239SRichard Henderson gen_op_store_QT0_fpr(QFPREG(a->rd)); 4828a4056239SRichard Henderson gen_update_fprs_dirty(dc, QFPREG(a->rd)); 4829a4056239SRichard Henderson return advance_pc(dc); 4830a4056239SRichard Henderson } 4831a4056239SRichard Henderson 4832a4056239SRichard Henderson TRANS(FADDq, ALL, do_env_qqq, a, gen_helper_faddq) 4833a4056239SRichard Henderson TRANS(FSUBq, ALL, do_env_qqq, a, gen_helper_fsubq) 4834a4056239SRichard Henderson TRANS(FMULq, ALL, do_env_qqq, a, gen_helper_fmulq) 4835a4056239SRichard Henderson TRANS(FDIVq, ALL, do_env_qqq, a, gen_helper_fdivq) 4836a4056239SRichard Henderson 48375e3b17bbSRichard Henderson static bool trans_FdMULq(DisasContext *dc, arg_r_r_r *a) 48385e3b17bbSRichard Henderson { 48395e3b17bbSRichard Henderson TCGv_i64 src1, src2; 48405e3b17bbSRichard Henderson 48415e3b17bbSRichard Henderson if (gen_trap_ifnofpu(dc)) { 48425e3b17bbSRichard Henderson return true; 48435e3b17bbSRichard Henderson } 48445e3b17bbSRichard Henderson if (gen_trap_float128(dc)) { 48455e3b17bbSRichard Henderson return true; 48465e3b17bbSRichard Henderson } 48475e3b17bbSRichard Henderson 48485e3b17bbSRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 48495e3b17bbSRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1); 48505e3b17bbSRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2); 48515e3b17bbSRichard Henderson gen_helper_fdmulq(tcg_env, src1, src2); 48525e3b17bbSRichard Henderson gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env); 48535e3b17bbSRichard Henderson gen_op_store_QT0_fpr(QFPREG(a->rd)); 48545e3b17bbSRichard Henderson gen_update_fprs_dirty(dc, QFPREG(a->rd)); 48555e3b17bbSRichard Henderson return advance_pc(dc); 48565e3b17bbSRichard Henderson } 48575e3b17bbSRichard Henderson 4858f7ec8155SRichard Henderson static bool do_fmovr(DisasContext *dc, arg_FMOVRs *a, bool is_128, 4859f7ec8155SRichard Henderson void (*func)(DisasContext *, DisasCompare *, int, int)) 4860f7ec8155SRichard Henderson { 4861f7ec8155SRichard Henderson DisasCompare cmp; 4862f7ec8155SRichard Henderson 4863f7ec8155SRichard Henderson if (gen_trap_ifnofpu(dc)) { 4864f7ec8155SRichard Henderson return true; 4865f7ec8155SRichard Henderson } 4866f7ec8155SRichard Henderson if (is_128 && gen_trap_float128(dc)) { 4867f7ec8155SRichard Henderson return true; 4868f7ec8155SRichard Henderson } 4869f7ec8155SRichard Henderson 4870f7ec8155SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 4871f7ec8155SRichard Henderson gen_compare_reg(&cmp, a->cond, gen_load_gpr(dc, a->rs1)); 4872f7ec8155SRichard Henderson func(dc, &cmp, a->rd, a->rs2); 4873f7ec8155SRichard Henderson return advance_pc(dc); 4874f7ec8155SRichard Henderson } 4875f7ec8155SRichard Henderson 4876f7ec8155SRichard Henderson TRANS(FMOVRs, 64, do_fmovr, a, false, gen_fmovs) 4877f7ec8155SRichard Henderson TRANS(FMOVRd, 64, do_fmovr, a, false, gen_fmovd) 4878f7ec8155SRichard Henderson TRANS(FMOVRq, 64, do_fmovr, a, true, gen_fmovq) 4879f7ec8155SRichard Henderson 4880f7ec8155SRichard Henderson static bool do_fmovcc(DisasContext *dc, arg_FMOVscc *a, bool is_128, 4881f7ec8155SRichard Henderson void (*func)(DisasContext *, DisasCompare *, int, int)) 4882f7ec8155SRichard Henderson { 4883f7ec8155SRichard Henderson DisasCompare cmp; 4884f7ec8155SRichard Henderson 4885f7ec8155SRichard Henderson if (gen_trap_ifnofpu(dc)) { 4886f7ec8155SRichard Henderson return true; 4887f7ec8155SRichard Henderson } 4888f7ec8155SRichard Henderson if (is_128 && gen_trap_float128(dc)) { 4889f7ec8155SRichard Henderson return true; 4890f7ec8155SRichard Henderson } 4891f7ec8155SRichard Henderson 4892f7ec8155SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 4893f7ec8155SRichard Henderson gen_compare(&cmp, a->cc, a->cond, dc); 4894f7ec8155SRichard Henderson func(dc, &cmp, a->rd, a->rs2); 4895f7ec8155SRichard Henderson return advance_pc(dc); 4896f7ec8155SRichard Henderson } 4897f7ec8155SRichard Henderson 4898f7ec8155SRichard Henderson TRANS(FMOVscc, 64, do_fmovcc, a, false, gen_fmovs) 4899f7ec8155SRichard Henderson TRANS(FMOVdcc, 64, do_fmovcc, a, false, gen_fmovd) 4900f7ec8155SRichard Henderson TRANS(FMOVqcc, 64, do_fmovcc, a, true, gen_fmovq) 4901f7ec8155SRichard Henderson 4902f7ec8155SRichard Henderson static bool do_fmovfcc(DisasContext *dc, arg_FMOVsfcc *a, bool is_128, 4903f7ec8155SRichard Henderson void (*func)(DisasContext *, DisasCompare *, int, int)) 4904f7ec8155SRichard Henderson { 4905f7ec8155SRichard Henderson DisasCompare cmp; 4906f7ec8155SRichard Henderson 4907f7ec8155SRichard Henderson if (gen_trap_ifnofpu(dc)) { 4908f7ec8155SRichard Henderson return true; 4909f7ec8155SRichard Henderson } 4910f7ec8155SRichard Henderson if (is_128 && gen_trap_float128(dc)) { 4911f7ec8155SRichard Henderson return true; 4912f7ec8155SRichard Henderson } 4913f7ec8155SRichard Henderson 4914f7ec8155SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 4915f7ec8155SRichard Henderson gen_fcompare(&cmp, a->cc, a->cond); 4916f7ec8155SRichard Henderson func(dc, &cmp, a->rd, a->rs2); 4917f7ec8155SRichard Henderson return advance_pc(dc); 4918f7ec8155SRichard Henderson } 4919f7ec8155SRichard Henderson 4920f7ec8155SRichard Henderson TRANS(FMOVsfcc, 64, do_fmovfcc, a, false, gen_fmovs) 4921f7ec8155SRichard Henderson TRANS(FMOVdfcc, 64, do_fmovfcc, a, false, gen_fmovd) 4922f7ec8155SRichard Henderson TRANS(FMOVqfcc, 64, do_fmovfcc, a, true, gen_fmovq) 4923f7ec8155SRichard Henderson 492440f9ad21SRichard Henderson static bool do_fcmps(DisasContext *dc, arg_FCMPs *a, bool e) 492540f9ad21SRichard Henderson { 492640f9ad21SRichard Henderson TCGv_i32 src1, src2; 492740f9ad21SRichard Henderson 492840f9ad21SRichard Henderson if (avail_32(dc) && a->cc != 0) { 492940f9ad21SRichard Henderson return false; 493040f9ad21SRichard Henderson } 493140f9ad21SRichard Henderson if (gen_trap_ifnofpu(dc)) { 493240f9ad21SRichard Henderson return true; 493340f9ad21SRichard Henderson } 493440f9ad21SRichard Henderson 493540f9ad21SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 493640f9ad21SRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1); 493740f9ad21SRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2); 493840f9ad21SRichard Henderson if (e) { 493940f9ad21SRichard Henderson gen_op_fcmpes(a->cc, src1, src2); 494040f9ad21SRichard Henderson } else { 494140f9ad21SRichard Henderson gen_op_fcmps(a->cc, src1, src2); 494240f9ad21SRichard Henderson } 494340f9ad21SRichard Henderson return advance_pc(dc); 494440f9ad21SRichard Henderson } 494540f9ad21SRichard Henderson 494640f9ad21SRichard Henderson TRANS(FCMPs, ALL, do_fcmps, a, false) 494740f9ad21SRichard Henderson TRANS(FCMPEs, ALL, do_fcmps, a, true) 494840f9ad21SRichard Henderson 494940f9ad21SRichard Henderson static bool do_fcmpd(DisasContext *dc, arg_FCMPd *a, bool e) 495040f9ad21SRichard Henderson { 495140f9ad21SRichard Henderson TCGv_i64 src1, src2; 495240f9ad21SRichard Henderson 495340f9ad21SRichard Henderson if (avail_32(dc) && a->cc != 0) { 495440f9ad21SRichard Henderson return false; 495540f9ad21SRichard Henderson } 495640f9ad21SRichard Henderson if (gen_trap_ifnofpu(dc)) { 495740f9ad21SRichard Henderson return true; 495840f9ad21SRichard Henderson } 495940f9ad21SRichard Henderson 496040f9ad21SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 496140f9ad21SRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1); 496240f9ad21SRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2); 496340f9ad21SRichard Henderson if (e) { 496440f9ad21SRichard Henderson gen_op_fcmped(a->cc, src1, src2); 496540f9ad21SRichard Henderson } else { 496640f9ad21SRichard Henderson gen_op_fcmpd(a->cc, src1, src2); 496740f9ad21SRichard Henderson } 496840f9ad21SRichard Henderson return advance_pc(dc); 496940f9ad21SRichard Henderson } 497040f9ad21SRichard Henderson 497140f9ad21SRichard Henderson TRANS(FCMPd, ALL, do_fcmpd, a, false) 497240f9ad21SRichard Henderson TRANS(FCMPEd, ALL, do_fcmpd, a, true) 497340f9ad21SRichard Henderson 497440f9ad21SRichard Henderson static bool do_fcmpq(DisasContext *dc, arg_FCMPq *a, bool e) 497540f9ad21SRichard Henderson { 497640f9ad21SRichard Henderson if (avail_32(dc) && a->cc != 0) { 497740f9ad21SRichard Henderson return false; 497840f9ad21SRichard Henderson } 497940f9ad21SRichard Henderson if (gen_trap_ifnofpu(dc)) { 498040f9ad21SRichard Henderson return true; 498140f9ad21SRichard Henderson } 498240f9ad21SRichard Henderson if (gen_trap_float128(dc)) { 498340f9ad21SRichard Henderson return true; 498440f9ad21SRichard Henderson } 498540f9ad21SRichard Henderson 498640f9ad21SRichard Henderson gen_op_clear_ieee_excp_and_FTT(); 498740f9ad21SRichard Henderson gen_op_load_fpr_QT0(QFPREG(a->rs1)); 498840f9ad21SRichard Henderson gen_op_load_fpr_QT1(QFPREG(a->rs2)); 498940f9ad21SRichard Henderson if (e) { 499040f9ad21SRichard Henderson gen_op_fcmpeq(a->cc); 499140f9ad21SRichard Henderson } else { 499240f9ad21SRichard Henderson gen_op_fcmpq(a->cc); 499340f9ad21SRichard Henderson } 499440f9ad21SRichard Henderson return advance_pc(dc); 499540f9ad21SRichard Henderson } 499640f9ad21SRichard Henderson 499740f9ad21SRichard Henderson TRANS(FCMPq, ALL, do_fcmpq, a, false) 499840f9ad21SRichard Henderson TRANS(FCMPEq, ALL, do_fcmpq, a, true) 499940f9ad21SRichard Henderson 50006e61bc94SEmilio G. Cota static void sparc_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) 5001fcf5ef2aSThomas Huth { 50026e61bc94SEmilio G. Cota DisasContext *dc = container_of(dcbase, DisasContext, base); 5003b77af26eSRichard Henderson CPUSPARCState *env = cpu_env(cs); 50046e61bc94SEmilio G. Cota int bound; 5005af00be49SEmilio G. Cota 5006af00be49SEmilio G. Cota dc->pc = dc->base.pc_first; 50076e61bc94SEmilio G. Cota dc->npc = (target_ulong)dc->base.tb->cs_base; 50086e61bc94SEmilio G. Cota dc->mem_idx = dc->base.tb->flags & TB_FLAG_MMU_MASK; 5009576e1c4cSIgor Mammedov dc->def = &env->def; 50106e61bc94SEmilio G. Cota dc->fpu_enabled = tb_fpu_enabled(dc->base.tb->flags); 50116e61bc94SEmilio G. Cota dc->address_mask_32bit = tb_am_enabled(dc->base.tb->flags); 5012c9b459aaSArtyom Tarasenko #ifndef CONFIG_USER_ONLY 50136e61bc94SEmilio G. Cota dc->supervisor = (dc->base.tb->flags & TB_FLAG_SUPER) != 0; 5014c9b459aaSArtyom Tarasenko #endif 5015fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64 5016fcf5ef2aSThomas Huth dc->fprs_dirty = 0; 50176e61bc94SEmilio G. Cota dc->asi = (dc->base.tb->flags >> TB_FLAG_ASI_SHIFT) & 0xff; 5018c9b459aaSArtyom Tarasenko #ifndef CONFIG_USER_ONLY 50196e61bc94SEmilio G. Cota dc->hypervisor = (dc->base.tb->flags & TB_FLAG_HYPER) != 0; 5020c9b459aaSArtyom Tarasenko #endif 5021fcf5ef2aSThomas Huth #endif 50226e61bc94SEmilio G. Cota /* 50236e61bc94SEmilio G. Cota * if we reach a page boundary, we stop generation so that the 50246e61bc94SEmilio G. Cota * PC of a TT_TFAULT exception is always in the right page 50256e61bc94SEmilio G. Cota */ 50266e61bc94SEmilio G. Cota bound = -(dc->base.pc_first | TARGET_PAGE_MASK) / 4; 50276e61bc94SEmilio G. Cota dc->base.max_insns = MIN(dc->base.max_insns, bound); 5028af00be49SEmilio G. Cota } 5029fcf5ef2aSThomas Huth 50306e61bc94SEmilio G. Cota static void sparc_tr_tb_start(DisasContextBase *db, CPUState *cs) 50316e61bc94SEmilio G. Cota { 50326e61bc94SEmilio G. Cota } 50336e61bc94SEmilio G. Cota 50346e61bc94SEmilio G. Cota static void sparc_tr_insn_start(DisasContextBase *dcbase, CPUState *cs) 50356e61bc94SEmilio G. Cota { 50366e61bc94SEmilio G. Cota DisasContext *dc = container_of(dcbase, DisasContext, base); 5037633c4283SRichard Henderson target_ulong npc = dc->npc; 50386e61bc94SEmilio G. Cota 5039633c4283SRichard Henderson if (npc & 3) { 5040633c4283SRichard Henderson switch (npc) { 5041633c4283SRichard Henderson case JUMP_PC: 5042fcf5ef2aSThomas Huth assert(dc->jump_pc[1] == dc->pc + 4); 5043633c4283SRichard Henderson npc = dc->jump_pc[0] | JUMP_PC; 5044633c4283SRichard Henderson break; 5045633c4283SRichard Henderson case DYNAMIC_PC: 5046633c4283SRichard Henderson case DYNAMIC_PC_LOOKUP: 5047633c4283SRichard Henderson npc = DYNAMIC_PC; 5048633c4283SRichard Henderson break; 5049633c4283SRichard Henderson default: 5050633c4283SRichard Henderson g_assert_not_reached(); 5051fcf5ef2aSThomas Huth } 50526e61bc94SEmilio G. Cota } 5053633c4283SRichard Henderson tcg_gen_insn_start(dc->pc, npc); 5054633c4283SRichard Henderson } 5055fcf5ef2aSThomas Huth 50566e61bc94SEmilio G. Cota static void sparc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) 50576e61bc94SEmilio G. Cota { 50586e61bc94SEmilio G. Cota DisasContext *dc = container_of(dcbase, DisasContext, base); 5059b77af26eSRichard Henderson CPUSPARCState *env = cpu_env(cs); 50606e61bc94SEmilio G. Cota unsigned int insn; 5061fcf5ef2aSThomas Huth 50624e116893SIlya Leoshkevich insn = translator_ldl(env, &dc->base, dc->pc); 5063af00be49SEmilio G. Cota dc->base.pc_next += 4; 5064878cc677SRichard Henderson 5065878cc677SRichard Henderson if (!decode(dc, insn)) { 5066ba9c09b4SRichard Henderson gen_exception(dc, TT_ILL_INSN); 5067878cc677SRichard Henderson } 5068fcf5ef2aSThomas Huth 5069af00be49SEmilio G. Cota if (dc->base.is_jmp == DISAS_NORETURN) { 50706e61bc94SEmilio G. Cota return; 5071c5e6ccdfSEmilio G. Cota } 5072af00be49SEmilio G. Cota if (dc->pc != dc->base.pc_next) { 50736e61bc94SEmilio G. Cota dc->base.is_jmp = DISAS_TOO_MANY; 5074af00be49SEmilio G. Cota } 50756e61bc94SEmilio G. Cota } 5076fcf5ef2aSThomas Huth 50776e61bc94SEmilio G. Cota static void sparc_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs) 50786e61bc94SEmilio G. Cota { 50796e61bc94SEmilio G. Cota DisasContext *dc = container_of(dcbase, DisasContext, base); 5080186e7890SRichard Henderson DisasDelayException *e, *e_next; 5081633c4283SRichard Henderson bool may_lookup; 50826e61bc94SEmilio G. Cota 508346bb0137SMark Cave-Ayland switch (dc->base.is_jmp) { 508446bb0137SMark Cave-Ayland case DISAS_NEXT: 508546bb0137SMark Cave-Ayland case DISAS_TOO_MANY: 5086633c4283SRichard Henderson if (((dc->pc | dc->npc) & 3) == 0) { 5087fcf5ef2aSThomas Huth /* static PC and NPC: we can use direct chaining */ 5088fcf5ef2aSThomas Huth gen_goto_tb(dc, 0, dc->pc, dc->npc); 5089633c4283SRichard Henderson break; 5090fcf5ef2aSThomas Huth } 5091633c4283SRichard Henderson 5092930f1865SRichard Henderson may_lookup = true; 5093633c4283SRichard Henderson if (dc->pc & 3) { 5094633c4283SRichard Henderson switch (dc->pc) { 5095633c4283SRichard Henderson case DYNAMIC_PC_LOOKUP: 5096633c4283SRichard Henderson break; 5097633c4283SRichard Henderson case DYNAMIC_PC: 5098633c4283SRichard Henderson may_lookup = false; 5099633c4283SRichard Henderson break; 5100633c4283SRichard Henderson default: 5101633c4283SRichard Henderson g_assert_not_reached(); 5102633c4283SRichard Henderson } 5103633c4283SRichard Henderson } else { 5104633c4283SRichard Henderson tcg_gen_movi_tl(cpu_pc, dc->pc); 5105633c4283SRichard Henderson } 5106633c4283SRichard Henderson 5107930f1865SRichard Henderson if (dc->npc & 3) { 5108930f1865SRichard Henderson switch (dc->npc) { 5109930f1865SRichard Henderson case JUMP_PC: 5110930f1865SRichard Henderson gen_generic_branch(dc); 5111930f1865SRichard Henderson break; 5112930f1865SRichard Henderson case DYNAMIC_PC: 5113930f1865SRichard Henderson may_lookup = false; 5114930f1865SRichard Henderson break; 5115930f1865SRichard Henderson case DYNAMIC_PC_LOOKUP: 5116930f1865SRichard Henderson break; 5117930f1865SRichard Henderson default: 5118930f1865SRichard Henderson g_assert_not_reached(); 5119930f1865SRichard Henderson } 5120930f1865SRichard Henderson } else { 5121930f1865SRichard Henderson tcg_gen_movi_tl(cpu_npc, dc->npc); 5122930f1865SRichard Henderson } 5123633c4283SRichard Henderson if (may_lookup) { 5124633c4283SRichard Henderson tcg_gen_lookup_and_goto_ptr(); 5125633c4283SRichard Henderson } else { 512607ea28b4SRichard Henderson tcg_gen_exit_tb(NULL, 0); 5127fcf5ef2aSThomas Huth } 512846bb0137SMark Cave-Ayland break; 512946bb0137SMark Cave-Ayland 513046bb0137SMark Cave-Ayland case DISAS_NORETURN: 513146bb0137SMark Cave-Ayland break; 513246bb0137SMark Cave-Ayland 513346bb0137SMark Cave-Ayland case DISAS_EXIT: 513446bb0137SMark Cave-Ayland /* Exit TB */ 513546bb0137SMark Cave-Ayland save_state(dc); 513646bb0137SMark Cave-Ayland tcg_gen_exit_tb(NULL, 0); 513746bb0137SMark Cave-Ayland break; 513846bb0137SMark Cave-Ayland 513946bb0137SMark Cave-Ayland default: 514046bb0137SMark Cave-Ayland g_assert_not_reached(); 5141fcf5ef2aSThomas Huth } 5142186e7890SRichard Henderson 5143186e7890SRichard Henderson for (e = dc->delay_excp_list; e ; e = e_next) { 5144186e7890SRichard Henderson gen_set_label(e->lab); 5145186e7890SRichard Henderson 5146186e7890SRichard Henderson tcg_gen_movi_tl(cpu_pc, e->pc); 5147186e7890SRichard Henderson if (e->npc % 4 == 0) { 5148186e7890SRichard Henderson tcg_gen_movi_tl(cpu_npc, e->npc); 5149186e7890SRichard Henderson } 5150186e7890SRichard Henderson gen_helper_raise_exception(tcg_env, e->excp); 5151186e7890SRichard Henderson 5152186e7890SRichard Henderson e_next = e->next; 5153186e7890SRichard Henderson g_free(e); 5154186e7890SRichard Henderson } 5155fcf5ef2aSThomas Huth } 51566e61bc94SEmilio G. Cota 51578eb806a7SRichard Henderson static void sparc_tr_disas_log(const DisasContextBase *dcbase, 51588eb806a7SRichard Henderson CPUState *cpu, FILE *logfile) 51596e61bc94SEmilio G. Cota { 51608eb806a7SRichard Henderson fprintf(logfile, "IN: %s\n", lookup_symbol(dcbase->pc_first)); 51618eb806a7SRichard Henderson target_disas(logfile, cpu, dcbase->pc_first, dcbase->tb->size); 51626e61bc94SEmilio G. Cota } 51636e61bc94SEmilio G. Cota 51646e61bc94SEmilio G. Cota static const TranslatorOps sparc_tr_ops = { 51656e61bc94SEmilio G. Cota .init_disas_context = sparc_tr_init_disas_context, 51666e61bc94SEmilio G. Cota .tb_start = sparc_tr_tb_start, 51676e61bc94SEmilio G. Cota .insn_start = sparc_tr_insn_start, 51686e61bc94SEmilio G. Cota .translate_insn = sparc_tr_translate_insn, 51696e61bc94SEmilio G. Cota .tb_stop = sparc_tr_tb_stop, 51706e61bc94SEmilio G. Cota .disas_log = sparc_tr_disas_log, 51716e61bc94SEmilio G. Cota }; 51726e61bc94SEmilio G. Cota 5173597f9b2dSRichard Henderson void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int *max_insns, 5174306c8721SRichard Henderson target_ulong pc, void *host_pc) 51756e61bc94SEmilio G. Cota { 51766e61bc94SEmilio G. Cota DisasContext dc = {}; 51776e61bc94SEmilio G. Cota 5178306c8721SRichard Henderson translator_loop(cs, tb, max_insns, pc, host_pc, &sparc_tr_ops, &dc.base); 5179fcf5ef2aSThomas Huth } 5180fcf5ef2aSThomas Huth 518155c3ceefSRichard Henderson void sparc_tcg_init(void) 5182fcf5ef2aSThomas Huth { 5183fcf5ef2aSThomas Huth static const char gregnames[32][4] = { 5184fcf5ef2aSThomas Huth "g0", "g1", "g2", "g3", "g4", "g5", "g6", "g7", 5185fcf5ef2aSThomas Huth "o0", "o1", "o2", "o3", "o4", "o5", "o6", "o7", 5186fcf5ef2aSThomas Huth "l0", "l1", "l2", "l3", "l4", "l5", "l6", "l7", 5187fcf5ef2aSThomas Huth "i0", "i1", "i2", "i3", "i4", "i5", "i6", "i7", 5188fcf5ef2aSThomas Huth }; 5189fcf5ef2aSThomas Huth static const char fregnames[32][4] = { 5190fcf5ef2aSThomas Huth "f0", "f2", "f4", "f6", "f8", "f10", "f12", "f14", 5191fcf5ef2aSThomas Huth "f16", "f18", "f20", "f22", "f24", "f26", "f28", "f30", 5192fcf5ef2aSThomas Huth "f32", "f34", "f36", "f38", "f40", "f42", "f44", "f46", 5193fcf5ef2aSThomas Huth "f48", "f50", "f52", "f54", "f56", "f58", "f60", "f62", 5194fcf5ef2aSThomas Huth }; 5195fcf5ef2aSThomas Huth 5196fcf5ef2aSThomas Huth static const struct { TCGv *ptr; int off; const char *name; } rtl[] = { 5197fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64 5198fcf5ef2aSThomas Huth { &cpu_gsr, offsetof(CPUSPARCState, gsr), "gsr" }, 51992a1905c7SRichard Henderson { &cpu_xcc_Z, offsetof(CPUSPARCState, xcc_Z), "xcc_Z" }, 52002a1905c7SRichard Henderson { &cpu_xcc_C, offsetof(CPUSPARCState, xcc_C), "xcc_C" }, 5201fcf5ef2aSThomas Huth #endif 52022a1905c7SRichard Henderson { &cpu_cc_N, offsetof(CPUSPARCState, cc_N), "cc_N" }, 52032a1905c7SRichard Henderson { &cpu_cc_V, offsetof(CPUSPARCState, cc_V), "cc_V" }, 52042a1905c7SRichard Henderson { &cpu_icc_Z, offsetof(CPUSPARCState, icc_Z), "icc_Z" }, 52052a1905c7SRichard Henderson { &cpu_icc_C, offsetof(CPUSPARCState, icc_C), "icc_C" }, 5206fcf5ef2aSThomas Huth { &cpu_cond, offsetof(CPUSPARCState, cond), "cond" }, 5207fcf5ef2aSThomas Huth { &cpu_fsr, offsetof(CPUSPARCState, fsr), "fsr" }, 5208fcf5ef2aSThomas Huth { &cpu_pc, offsetof(CPUSPARCState, pc), "pc" }, 5209fcf5ef2aSThomas Huth { &cpu_npc, offsetof(CPUSPARCState, npc), "npc" }, 5210fcf5ef2aSThomas Huth { &cpu_y, offsetof(CPUSPARCState, y), "y" }, 5211fcf5ef2aSThomas Huth { &cpu_tbr, offsetof(CPUSPARCState, tbr), "tbr" }, 5212fcf5ef2aSThomas Huth }; 5213fcf5ef2aSThomas Huth 5214fcf5ef2aSThomas Huth unsigned int i; 5215fcf5ef2aSThomas Huth 5216ad75a51eSRichard Henderson cpu_regwptr = tcg_global_mem_new_ptr(tcg_env, 5217fcf5ef2aSThomas Huth offsetof(CPUSPARCState, regwptr), 5218fcf5ef2aSThomas Huth "regwptr"); 5219fcf5ef2aSThomas Huth 5220fcf5ef2aSThomas Huth for (i = 0; i < ARRAY_SIZE(rtl); ++i) { 5221ad75a51eSRichard Henderson *rtl[i].ptr = tcg_global_mem_new(tcg_env, rtl[i].off, rtl[i].name); 5222fcf5ef2aSThomas Huth } 5223fcf5ef2aSThomas Huth 5224f764718dSRichard Henderson cpu_regs[0] = NULL; 5225fcf5ef2aSThomas Huth for (i = 1; i < 8; ++i) { 5226ad75a51eSRichard Henderson cpu_regs[i] = tcg_global_mem_new(tcg_env, 5227fcf5ef2aSThomas Huth offsetof(CPUSPARCState, gregs[i]), 5228fcf5ef2aSThomas Huth gregnames[i]); 5229fcf5ef2aSThomas Huth } 5230fcf5ef2aSThomas Huth 5231fcf5ef2aSThomas Huth for (i = 8; i < 32; ++i) { 5232fcf5ef2aSThomas Huth cpu_regs[i] = tcg_global_mem_new(cpu_regwptr, 5233fcf5ef2aSThomas Huth (i - 8) * sizeof(target_ulong), 5234fcf5ef2aSThomas Huth gregnames[i]); 5235fcf5ef2aSThomas Huth } 5236fcf5ef2aSThomas Huth 5237fcf5ef2aSThomas Huth for (i = 0; i < TARGET_DPREGS; i++) { 5238ad75a51eSRichard Henderson cpu_fpr[i] = tcg_global_mem_new_i64(tcg_env, 5239fcf5ef2aSThomas Huth offsetof(CPUSPARCState, fpr[i]), 5240fcf5ef2aSThomas Huth fregnames[i]); 5241fcf5ef2aSThomas Huth } 5242b597eedcSRichard Henderson 5243b597eedcSRichard Henderson #ifdef TARGET_SPARC64 5244b597eedcSRichard Henderson cpu_fprs = tcg_global_mem_new_i32(tcg_env, 5245b597eedcSRichard Henderson offsetof(CPUSPARCState, fprs), "fprs"); 5246b597eedcSRichard Henderson #endif 5247fcf5ef2aSThomas Huth } 5248fcf5ef2aSThomas Huth 5249f36aaa53SRichard Henderson void sparc_restore_state_to_opc(CPUState *cs, 5250f36aaa53SRichard Henderson const TranslationBlock *tb, 5251f36aaa53SRichard Henderson const uint64_t *data) 5252fcf5ef2aSThomas Huth { 5253f36aaa53SRichard Henderson SPARCCPU *cpu = SPARC_CPU(cs); 5254f36aaa53SRichard Henderson CPUSPARCState *env = &cpu->env; 5255fcf5ef2aSThomas Huth target_ulong pc = data[0]; 5256fcf5ef2aSThomas Huth target_ulong npc = data[1]; 5257fcf5ef2aSThomas Huth 5258fcf5ef2aSThomas Huth env->pc = pc; 5259fcf5ef2aSThomas Huth if (npc == DYNAMIC_PC) { 5260fcf5ef2aSThomas Huth /* dynamic NPC: already stored */ 5261fcf5ef2aSThomas Huth } else if (npc & JUMP_PC) { 5262fcf5ef2aSThomas Huth /* jump PC: use 'cond' and the jump targets of the translation */ 5263fcf5ef2aSThomas Huth if (env->cond) { 5264fcf5ef2aSThomas Huth env->npc = npc & ~3; 5265fcf5ef2aSThomas Huth } else { 5266fcf5ef2aSThomas Huth env->npc = pc + 4; 5267fcf5ef2aSThomas Huth } 5268fcf5ef2aSThomas Huth } else { 5269fcf5ef2aSThomas Huth env->npc = npc; 5270fcf5ef2aSThomas Huth } 5271fcf5ef2aSThomas Huth } 5272