xref: /openbmc/qemu/target/sparc/translate.c (revision b2b48493362b9f77ca66fffb1464f7fc5a32c6e9)
1fcf5ef2aSThomas Huth /*
2fcf5ef2aSThomas Huth    SPARC translation
3fcf5ef2aSThomas Huth 
4fcf5ef2aSThomas Huth    Copyright (C) 2003 Thomas M. Ogrisegg <tom@fnord.at>
5fcf5ef2aSThomas Huth    Copyright (C) 2003-2005 Fabrice Bellard
6fcf5ef2aSThomas Huth 
7fcf5ef2aSThomas Huth    This library is free software; you can redistribute it and/or
8fcf5ef2aSThomas Huth    modify it under the terms of the GNU Lesser General Public
9fcf5ef2aSThomas Huth    License as published by the Free Software Foundation; either
105650b549SChetan Pant    version 2.1 of the License, or (at your option) any later version.
11fcf5ef2aSThomas Huth 
12fcf5ef2aSThomas Huth    This library is distributed in the hope that it will be useful,
13fcf5ef2aSThomas Huth    but WITHOUT ANY WARRANTY; without even the implied warranty of
14fcf5ef2aSThomas Huth    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15fcf5ef2aSThomas Huth    Lesser General Public License for more details.
16fcf5ef2aSThomas Huth 
17fcf5ef2aSThomas Huth    You should have received a copy of the GNU Lesser General Public
18fcf5ef2aSThomas Huth    License along with this library; if not, see <http://www.gnu.org/licenses/>.
19fcf5ef2aSThomas Huth  */
20fcf5ef2aSThomas Huth 
21fcf5ef2aSThomas Huth #include "qemu/osdep.h"
22fcf5ef2aSThomas Huth 
23fcf5ef2aSThomas Huth #include "cpu.h"
24fcf5ef2aSThomas Huth #include "exec/helper-proto.h"
25fcf5ef2aSThomas Huth #include "exec/exec-all.h"
26dcb32f1dSPhilippe Mathieu-Daudé #include "tcg/tcg-op.h"
27fafba1bbSRichard Henderson #include "tcg/tcg-op-gvec.h"
28fcf5ef2aSThomas Huth #include "exec/helper-gen.h"
29c5e6ccdfSEmilio G. Cota #include "exec/translator.h"
30fcf5ef2aSThomas Huth #include "exec/log.h"
314fd71d19SRichard Henderson #include "fpu/softfloat.h"
32fcf5ef2aSThomas Huth #include "asi.h"
33fcf5ef2aSThomas Huth 
34d53106c9SRichard Henderson #define HELPER_H "helper.h"
35d53106c9SRichard Henderson #include "exec/helper-info.c.inc"
36d53106c9SRichard Henderson #undef  HELPER_H
37fcf5ef2aSThomas Huth 
38668bb9b7SRichard Henderson #ifdef TARGET_SPARC64
39668bb9b7SRichard Henderson # define gen_helper_rdpsr(D, E)                 qemu_build_not_reached()
40c92948f2SClément Chigot # define gen_helper_rdasr17(D, E)               qemu_build_not_reached()
4186b82fe0SRichard Henderson # define gen_helper_rett(E)                     qemu_build_not_reached()
420faef01bSRichard Henderson # define gen_helper_power_down(E)               qemu_build_not_reached()
4325524734SRichard Henderson # define gen_helper_wrpsr(E, S)                 qemu_build_not_reached()
44668bb9b7SRichard Henderson #else
450faef01bSRichard Henderson # define gen_helper_clear_softint(E, S)         qemu_build_not_reached()
468f75b8a4SRichard Henderson # define gen_helper_done(E)                     qemu_build_not_reached()
47e8325dc0SRichard Henderson # define gen_helper_flushw(E)                   qemu_build_not_reached()
48a859602cSRichard Henderson # define gen_helper_fmul8x16a(D, S1, S2)        qemu_build_not_reached()
49af25071cSRichard Henderson # define gen_helper_rdccr(D, E)                 qemu_build_not_reached()
505d617bfbSRichard Henderson # define gen_helper_rdcwp(D, E)                 qemu_build_not_reached()
5125524734SRichard Henderson # define gen_helper_restored(E)                 qemu_build_not_reached()
528f75b8a4SRichard Henderson # define gen_helper_retry(E)                    qemu_build_not_reached()
5325524734SRichard Henderson # define gen_helper_saved(E)                    qemu_build_not_reached()
540faef01bSRichard Henderson # define gen_helper_set_softint(E, S)           qemu_build_not_reached()
55af25071cSRichard Henderson # define gen_helper_tick_get_count(D, E, T, C)  qemu_build_not_reached()
569422278eSRichard Henderson # define gen_helper_tick_set_count(P, S)        qemu_build_not_reached()
57bb97f2f5SRichard Henderson # define gen_helper_tick_set_limit(P, S)        qemu_build_not_reached()
580faef01bSRichard Henderson # define gen_helper_wrccr(E, S)                 qemu_build_not_reached()
599422278eSRichard Henderson # define gen_helper_wrcwp(E, S)                 qemu_build_not_reached()
609422278eSRichard Henderson # define gen_helper_wrgl(E, S)                  qemu_build_not_reached()
610faef01bSRichard Henderson # define gen_helper_write_softint(E, S)         qemu_build_not_reached()
629422278eSRichard Henderson # define gen_helper_wrpil(E, S)                 qemu_build_not_reached()
639422278eSRichard Henderson # define gen_helper_wrpstate(E, S)              qemu_build_not_reached()
64c973b4e8SRichard Henderson # define gen_helper_cmask8               ({ qemu_build_not_reached(); NULL; })
65c973b4e8SRichard Henderson # define gen_helper_cmask16              ({ qemu_build_not_reached(); NULL; })
66c973b4e8SRichard Henderson # define gen_helper_cmask32              ({ qemu_build_not_reached(); NULL; })
67669e0774SRichard Henderson # define gen_helper_fcmpeq8              ({ qemu_build_not_reached(); NULL; })
68e2fa6bd1SRichard Henderson # define gen_helper_fcmpeq16             ({ qemu_build_not_reached(); NULL; })
69e2fa6bd1SRichard Henderson # define gen_helper_fcmpeq32             ({ qemu_build_not_reached(); NULL; })
70e2fa6bd1SRichard Henderson # define gen_helper_fcmpgt16             ({ qemu_build_not_reached(); NULL; })
71e2fa6bd1SRichard Henderson # define gen_helper_fcmpgt32             ({ qemu_build_not_reached(); NULL; })
72e2fa6bd1SRichard Henderson # define gen_helper_fcmple16             ({ qemu_build_not_reached(); NULL; })
73e2fa6bd1SRichard Henderson # define gen_helper_fcmple32             ({ qemu_build_not_reached(); NULL; })
74669e0774SRichard Henderson # define gen_helper_fcmpne8              ({ qemu_build_not_reached(); NULL; })
75e2fa6bd1SRichard Henderson # define gen_helper_fcmpne16             ({ qemu_build_not_reached(); NULL; })
76e2fa6bd1SRichard Henderson # define gen_helper_fcmpne32             ({ qemu_build_not_reached(); NULL; })
77669e0774SRichard Henderson # define gen_helper_fcmpule8             ({ qemu_build_not_reached(); NULL; })
78669e0774SRichard Henderson # define gen_helper_fcmpugt8             ({ qemu_build_not_reached(); NULL; })
798aa418b3SRichard Henderson # define gen_helper_fdtox                ({ qemu_build_not_reached(); NULL; })
80e06c9f83SRichard Henderson # define gen_helper_fexpand              ({ qemu_build_not_reached(); NULL; })
81e06c9f83SRichard Henderson # define gen_helper_fmul8sux16           ({ qemu_build_not_reached(); NULL; })
82e06c9f83SRichard Henderson # define gen_helper_fmul8ulx16           ({ qemu_build_not_reached(); NULL; })
83e06c9f83SRichard Henderson # define gen_helper_fmul8x16             ({ qemu_build_not_reached(); NULL; })
84e06c9f83SRichard Henderson # define gen_helper_fpmerge              ({ qemu_build_not_reached(); NULL; })
851617586fSRichard Henderson # define gen_helper_fqtox                ({ qemu_build_not_reached(); NULL; })
86fbc5c8d4SRichard Henderson # define gen_helper_fslas16              ({ qemu_build_not_reached(); NULL; })
87fbc5c8d4SRichard Henderson # define gen_helper_fslas32              ({ qemu_build_not_reached(); NULL; })
88199d43efSRichard Henderson # define gen_helper_fstox                ({ qemu_build_not_reached(); NULL; })
898aa418b3SRichard Henderson # define gen_helper_fxtod                ({ qemu_build_not_reached(); NULL; })
907b8e3e1aSRichard Henderson # define gen_helper_fxtoq                ({ qemu_build_not_reached(); NULL; })
91f4e18df5SRichard Henderson # define gen_helper_fxtos                ({ qemu_build_not_reached(); NULL; })
92afb04344SRichard Henderson # define gen_helper_pdist                ({ qemu_build_not_reached(); NULL; })
93029b0283SRichard Henderson # define gen_helper_xmulx                ({ qemu_build_not_reached(); NULL; })
94029b0283SRichard Henderson # define gen_helper_xmulxhi              ({ qemu_build_not_reached(); NULL; })
95668bb9b7SRichard Henderson # define MAXTL_MASK                             0
96af25071cSRichard Henderson #endif
97af25071cSRichard Henderson 
98633c4283SRichard Henderson /* Dynamic PC, must exit to main loop. */
99633c4283SRichard Henderson #define DYNAMIC_PC         1
100633c4283SRichard Henderson /* Dynamic PC, one of two values according to jump_pc[T2]. */
101633c4283SRichard Henderson #define JUMP_PC            2
102633c4283SRichard Henderson /* Dynamic PC, may lookup next TB. */
103633c4283SRichard Henderson #define DYNAMIC_PC_LOOKUP  3
104fcf5ef2aSThomas Huth 
10546bb0137SMark Cave-Ayland #define DISAS_EXIT  DISAS_TARGET_0
10646bb0137SMark Cave-Ayland 
107fcf5ef2aSThomas Huth /* global register indexes */
108fcf5ef2aSThomas Huth static TCGv_ptr cpu_regwptr;
109c9fa8e58SRichard Henderson static TCGv cpu_pc, cpu_npc;
110fcf5ef2aSThomas Huth static TCGv cpu_regs[32];
111fcf5ef2aSThomas Huth static TCGv cpu_y;
112fcf5ef2aSThomas Huth static TCGv cpu_tbr;
113fcf5ef2aSThomas Huth static TCGv cpu_cond;
1142a1905c7SRichard Henderson static TCGv cpu_cc_N;
1152a1905c7SRichard Henderson static TCGv cpu_cc_V;
1162a1905c7SRichard Henderson static TCGv cpu_icc_Z;
1172a1905c7SRichard Henderson static TCGv cpu_icc_C;
118fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
1192a1905c7SRichard Henderson static TCGv cpu_xcc_Z;
1202a1905c7SRichard Henderson static TCGv cpu_xcc_C;
1212a1905c7SRichard Henderson static TCGv_i32 cpu_fprs;
122fcf5ef2aSThomas Huth static TCGv cpu_gsr;
123fcf5ef2aSThomas Huth #else
124af25071cSRichard Henderson # define cpu_fprs               ({ qemu_build_not_reached(); (TCGv)NULL; })
125af25071cSRichard Henderson # define cpu_gsr                ({ qemu_build_not_reached(); (TCGv)NULL; })
126fcf5ef2aSThomas Huth #endif
1272a1905c7SRichard Henderson 
1282a1905c7SRichard Henderson #ifdef TARGET_SPARC64
1292a1905c7SRichard Henderson #define cpu_cc_Z  cpu_xcc_Z
1302a1905c7SRichard Henderson #define cpu_cc_C  cpu_xcc_C
1312a1905c7SRichard Henderson #else
1322a1905c7SRichard Henderson #define cpu_cc_Z  cpu_icc_Z
1332a1905c7SRichard Henderson #define cpu_cc_C  cpu_icc_C
1342a1905c7SRichard Henderson #define cpu_xcc_Z ({ qemu_build_not_reached(); NULL; })
1352a1905c7SRichard Henderson #define cpu_xcc_C ({ qemu_build_not_reached(); NULL; })
1362a1905c7SRichard Henderson #endif
1372a1905c7SRichard Henderson 
1381210a036SRichard Henderson /* Floating point comparison registers */
139d8c5b92fSRichard Henderson static TCGv_i32 cpu_fcc[TARGET_FCCREGS];
140fcf5ef2aSThomas Huth 
141af25071cSRichard Henderson #define env_field_offsetof(X)     offsetof(CPUSPARCState, X)
142af25071cSRichard Henderson #ifdef TARGET_SPARC64
143cd6269f7SRichard Henderson # define env32_field_offsetof(X)  ({ qemu_build_not_reached(); 0; })
144af25071cSRichard Henderson # define env64_field_offsetof(X)  env_field_offsetof(X)
145af25071cSRichard Henderson #else
146cd6269f7SRichard Henderson # define env32_field_offsetof(X)  env_field_offsetof(X)
147af25071cSRichard Henderson # define env64_field_offsetof(X)  ({ qemu_build_not_reached(); 0; })
148af25071cSRichard Henderson #endif
149af25071cSRichard Henderson 
150533f042fSRichard Henderson typedef struct DisasCompare {
151533f042fSRichard Henderson     TCGCond cond;
152533f042fSRichard Henderson     TCGv c1;
153533f042fSRichard Henderson     int c2;
154533f042fSRichard Henderson } DisasCompare;
155533f042fSRichard Henderson 
156186e7890SRichard Henderson typedef struct DisasDelayException {
157186e7890SRichard Henderson     struct DisasDelayException *next;
158186e7890SRichard Henderson     TCGLabel *lab;
159186e7890SRichard Henderson     TCGv_i32 excp;
160186e7890SRichard Henderson     /* Saved state at parent insn. */
161186e7890SRichard Henderson     target_ulong pc;
162186e7890SRichard Henderson     target_ulong npc;
163186e7890SRichard Henderson } DisasDelayException;
164186e7890SRichard Henderson 
165fcf5ef2aSThomas Huth typedef struct DisasContext {
166af00be49SEmilio G. Cota     DisasContextBase base;
167fcf5ef2aSThomas Huth     target_ulong pc;    /* current Program Counter: integer or DYNAMIC_PC */
168fcf5ef2aSThomas Huth     target_ulong npc;   /* next PC: integer or DYNAMIC_PC or JUMP_PC */
169533f042fSRichard Henderson 
170533f042fSRichard Henderson     /* Used when JUMP_PC value is used. */
171533f042fSRichard Henderson     DisasCompare jump;
172533f042fSRichard Henderson     target_ulong jump_pc[2];
173533f042fSRichard Henderson 
174fcf5ef2aSThomas Huth     int mem_idx;
17589527e3aSRichard Henderson     bool cpu_cond_live;
176c9b459aaSArtyom Tarasenko     bool fpu_enabled;
177c9b459aaSArtyom Tarasenko     bool address_mask_32bit;
178c9b459aaSArtyom Tarasenko #ifndef CONFIG_USER_ONLY
179c9b459aaSArtyom Tarasenko     bool supervisor;
180c9b459aaSArtyom Tarasenko #ifdef TARGET_SPARC64
181c9b459aaSArtyom Tarasenko     bool hypervisor;
182c9b459aaSArtyom Tarasenko #endif
183c9b459aaSArtyom Tarasenko #endif
184c9b459aaSArtyom Tarasenko 
185fcf5ef2aSThomas Huth     sparc_def_t *def;
186fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
187fcf5ef2aSThomas Huth     int fprs_dirty;
188fcf5ef2aSThomas Huth     int asi;
189fcf5ef2aSThomas Huth #endif
190186e7890SRichard Henderson     DisasDelayException *delay_excp_list;
191fcf5ef2aSThomas Huth } DisasContext;
192fcf5ef2aSThomas Huth 
193fcf5ef2aSThomas Huth // This function uses non-native bit order
194fcf5ef2aSThomas Huth #define GET_FIELD(X, FROM, TO)                                  \
195fcf5ef2aSThomas Huth     ((X) >> (31 - (TO)) & ((1 << ((TO) - (FROM) + 1)) - 1))
196fcf5ef2aSThomas Huth 
197fcf5ef2aSThomas Huth // This function uses the order in the manuals, i.e. bit 0 is 2^0
198fcf5ef2aSThomas Huth #define GET_FIELD_SP(X, FROM, TO)               \
199fcf5ef2aSThomas Huth     GET_FIELD(X, 31 - (TO), 31 - (FROM))
200fcf5ef2aSThomas Huth 
201fcf5ef2aSThomas Huth #define GET_FIELDs(x,a,b) sign_extend (GET_FIELD(x,a,b), (b) - (a) + 1)
202fcf5ef2aSThomas Huth #define GET_FIELD_SPs(x,a,b) sign_extend (GET_FIELD_SP(x,a,b), ((b) - (a) + 1))
203fcf5ef2aSThomas Huth 
204fcf5ef2aSThomas Huth #define UA2005_HTRAP_MASK 0xff
205fcf5ef2aSThomas Huth #define V8_TRAP_MASK 0x7f
206fcf5ef2aSThomas Huth 
207fcf5ef2aSThomas Huth #define IS_IMM (insn & (1<<13))
208fcf5ef2aSThomas Huth 
2090c2e96c1SRichard Henderson static void gen_update_fprs_dirty(DisasContext *dc, int rd)
210fcf5ef2aSThomas Huth {
211fcf5ef2aSThomas Huth #if defined(TARGET_SPARC64)
212fcf5ef2aSThomas Huth     int bit = (rd < 32) ? 1 : 2;
213fcf5ef2aSThomas Huth     /* If we know we've already set this bit within the TB,
214fcf5ef2aSThomas Huth        we can avoid setting it again.  */
215fcf5ef2aSThomas Huth     if (!(dc->fprs_dirty & bit)) {
216fcf5ef2aSThomas Huth         dc->fprs_dirty |= bit;
217fcf5ef2aSThomas Huth         tcg_gen_ori_i32(cpu_fprs, cpu_fprs, bit);
218fcf5ef2aSThomas Huth     }
219fcf5ef2aSThomas Huth #endif
220fcf5ef2aSThomas Huth }
221fcf5ef2aSThomas Huth 
222fcf5ef2aSThomas Huth /* floating point registers moves */
2231210a036SRichard Henderson 
2241210a036SRichard Henderson static int gen_offset_fpr_F(unsigned int reg)
2251210a036SRichard Henderson {
2261210a036SRichard Henderson     int ret;
2271210a036SRichard Henderson 
2281210a036SRichard Henderson     tcg_debug_assert(reg < 32);
2291210a036SRichard Henderson     ret= offsetof(CPUSPARCState, fpr[reg / 2]);
2301210a036SRichard Henderson     if (reg & 1) {
2311210a036SRichard Henderson         ret += offsetof(CPU_DoubleU, l.lower);
2321210a036SRichard Henderson     } else {
2331210a036SRichard Henderson         ret += offsetof(CPU_DoubleU, l.upper);
2341210a036SRichard Henderson     }
2351210a036SRichard Henderson     return ret;
2361210a036SRichard Henderson }
2371210a036SRichard Henderson 
238fcf5ef2aSThomas Huth static TCGv_i32 gen_load_fpr_F(DisasContext *dc, unsigned int src)
239fcf5ef2aSThomas Huth {
24036ab4623SRichard Henderson     TCGv_i32 ret = tcg_temp_new_i32();
2411210a036SRichard Henderson     tcg_gen_ld_i32(ret, tcg_env, gen_offset_fpr_F(src));
242dc41aa7dSRichard Henderson     return ret;
243fcf5ef2aSThomas Huth }
244fcf5ef2aSThomas Huth 
245fcf5ef2aSThomas Huth static void gen_store_fpr_F(DisasContext *dc, unsigned int dst, TCGv_i32 v)
246fcf5ef2aSThomas Huth {
2471210a036SRichard Henderson     tcg_gen_st_i32(v, tcg_env, gen_offset_fpr_F(dst));
248fcf5ef2aSThomas Huth     gen_update_fprs_dirty(dc, dst);
249fcf5ef2aSThomas Huth }
250fcf5ef2aSThomas Huth 
2511210a036SRichard Henderson static int gen_offset_fpr_D(unsigned int reg)
2521210a036SRichard Henderson {
2531210a036SRichard Henderson     tcg_debug_assert(reg < 64);
2541210a036SRichard Henderson     tcg_debug_assert(reg % 2 == 0);
2551210a036SRichard Henderson     return offsetof(CPUSPARCState, fpr[reg / 2]);
2561210a036SRichard Henderson }
2571210a036SRichard Henderson 
258fcf5ef2aSThomas Huth static TCGv_i64 gen_load_fpr_D(DisasContext *dc, unsigned int src)
259fcf5ef2aSThomas Huth {
2601210a036SRichard Henderson     TCGv_i64 ret = tcg_temp_new_i64();
2611210a036SRichard Henderson     tcg_gen_ld_i64(ret, tcg_env, gen_offset_fpr_D(src));
2621210a036SRichard Henderson     return ret;
263fcf5ef2aSThomas Huth }
264fcf5ef2aSThomas Huth 
265fcf5ef2aSThomas Huth static void gen_store_fpr_D(DisasContext *dc, unsigned int dst, TCGv_i64 v)
266fcf5ef2aSThomas Huth {
2671210a036SRichard Henderson     tcg_gen_st_i64(v, tcg_env, gen_offset_fpr_D(dst));
268fcf5ef2aSThomas Huth     gen_update_fprs_dirty(dc, dst);
269fcf5ef2aSThomas Huth }
270fcf5ef2aSThomas Huth 
27133ec4245SRichard Henderson static TCGv_i128 gen_load_fpr_Q(DisasContext *dc, unsigned int src)
27233ec4245SRichard Henderson {
27333ec4245SRichard Henderson     TCGv_i128 ret = tcg_temp_new_i128();
2741210a036SRichard Henderson     TCGv_i64 h = gen_load_fpr_D(dc, src);
2751210a036SRichard Henderson     TCGv_i64 l = gen_load_fpr_D(dc, src + 2);
27633ec4245SRichard Henderson 
2771210a036SRichard Henderson     tcg_gen_concat_i64_i128(ret, l, h);
27833ec4245SRichard Henderson     return ret;
27933ec4245SRichard Henderson }
28033ec4245SRichard Henderson 
28133ec4245SRichard Henderson static void gen_store_fpr_Q(DisasContext *dc, unsigned int dst, TCGv_i128 v)
28233ec4245SRichard Henderson {
2831210a036SRichard Henderson     TCGv_i64 h = tcg_temp_new_i64();
2841210a036SRichard Henderson     TCGv_i64 l = tcg_temp_new_i64();
2851210a036SRichard Henderson 
2861210a036SRichard Henderson     tcg_gen_extr_i128_i64(l, h, v);
2871210a036SRichard Henderson     gen_store_fpr_D(dc, dst, h);
2881210a036SRichard Henderson     gen_store_fpr_D(dc, dst + 2, l);
28933ec4245SRichard Henderson }
29033ec4245SRichard Henderson 
291fcf5ef2aSThomas Huth /* moves */
292fcf5ef2aSThomas Huth #ifdef CONFIG_USER_ONLY
293fcf5ef2aSThomas Huth #define supervisor(dc) 0
294fcf5ef2aSThomas Huth #define hypervisor(dc) 0
295fcf5ef2aSThomas Huth #else
296fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
297c9b459aaSArtyom Tarasenko #define hypervisor(dc) (dc->hypervisor)
298c9b459aaSArtyom Tarasenko #define supervisor(dc) (dc->supervisor | dc->hypervisor)
299fcf5ef2aSThomas Huth #else
300c9b459aaSArtyom Tarasenko #define supervisor(dc) (dc->supervisor)
301668bb9b7SRichard Henderson #define hypervisor(dc) 0
302fcf5ef2aSThomas Huth #endif
303fcf5ef2aSThomas Huth #endif
304fcf5ef2aSThomas Huth 
305b1bc09eaSRichard Henderson #if !defined(TARGET_SPARC64)
306b1bc09eaSRichard Henderson # define AM_CHECK(dc)  false
307b1bc09eaSRichard Henderson #elif defined(TARGET_ABI32)
308b1bc09eaSRichard Henderson # define AM_CHECK(dc)  true
309b1bc09eaSRichard Henderson #elif defined(CONFIG_USER_ONLY)
310b1bc09eaSRichard Henderson # define AM_CHECK(dc)  false
311fcf5ef2aSThomas Huth #else
312b1bc09eaSRichard Henderson # define AM_CHECK(dc)  ((dc)->address_mask_32bit)
313fcf5ef2aSThomas Huth #endif
314fcf5ef2aSThomas Huth 
3150c2e96c1SRichard Henderson static void gen_address_mask(DisasContext *dc, TCGv addr)
316fcf5ef2aSThomas Huth {
317b1bc09eaSRichard Henderson     if (AM_CHECK(dc)) {
318fcf5ef2aSThomas Huth         tcg_gen_andi_tl(addr, addr, 0xffffffffULL);
319b1bc09eaSRichard Henderson     }
320fcf5ef2aSThomas Huth }
321fcf5ef2aSThomas Huth 
32223ada1b1SRichard Henderson static target_ulong address_mask_i(DisasContext *dc, target_ulong addr)
32323ada1b1SRichard Henderson {
32423ada1b1SRichard Henderson     return AM_CHECK(dc) ? (uint32_t)addr : addr;
32523ada1b1SRichard Henderson }
32623ada1b1SRichard Henderson 
3270c2e96c1SRichard Henderson static TCGv gen_load_gpr(DisasContext *dc, int reg)
328fcf5ef2aSThomas Huth {
329fcf5ef2aSThomas Huth     if (reg > 0) {
330fcf5ef2aSThomas Huth         assert(reg < 32);
331fcf5ef2aSThomas Huth         return cpu_regs[reg];
332fcf5ef2aSThomas Huth     } else {
33352123f14SRichard Henderson         TCGv t = tcg_temp_new();
334fcf5ef2aSThomas Huth         tcg_gen_movi_tl(t, 0);
335fcf5ef2aSThomas Huth         return t;
336fcf5ef2aSThomas Huth     }
337fcf5ef2aSThomas Huth }
338fcf5ef2aSThomas Huth 
3390c2e96c1SRichard Henderson static void gen_store_gpr(DisasContext *dc, int reg, TCGv v)
340fcf5ef2aSThomas Huth {
341fcf5ef2aSThomas Huth     if (reg > 0) {
342fcf5ef2aSThomas Huth         assert(reg < 32);
343fcf5ef2aSThomas Huth         tcg_gen_mov_tl(cpu_regs[reg], v);
344fcf5ef2aSThomas Huth     }
345fcf5ef2aSThomas Huth }
346fcf5ef2aSThomas Huth 
3470c2e96c1SRichard Henderson static TCGv gen_dest_gpr(DisasContext *dc, int reg)
348fcf5ef2aSThomas Huth {
349fcf5ef2aSThomas Huth     if (reg > 0) {
350fcf5ef2aSThomas Huth         assert(reg < 32);
351fcf5ef2aSThomas Huth         return cpu_regs[reg];
352fcf5ef2aSThomas Huth     } else {
35352123f14SRichard Henderson         return tcg_temp_new();
354fcf5ef2aSThomas Huth     }
355fcf5ef2aSThomas Huth }
356fcf5ef2aSThomas Huth 
3575645aa2eSRichard Henderson static bool use_goto_tb(DisasContext *s, target_ulong pc, target_ulong npc)
358fcf5ef2aSThomas Huth {
3595645aa2eSRichard Henderson     return translator_use_goto_tb(&s->base, pc) &&
3605645aa2eSRichard Henderson            translator_use_goto_tb(&s->base, npc);
361fcf5ef2aSThomas Huth }
362fcf5ef2aSThomas Huth 
3635645aa2eSRichard Henderson static void gen_goto_tb(DisasContext *s, int tb_num,
364fcf5ef2aSThomas Huth                         target_ulong pc, target_ulong npc)
365fcf5ef2aSThomas Huth {
366fcf5ef2aSThomas Huth     if (use_goto_tb(s, pc, npc))  {
367fcf5ef2aSThomas Huth         /* jump to same page: we can use a direct jump */
368fcf5ef2aSThomas Huth         tcg_gen_goto_tb(tb_num);
369fcf5ef2aSThomas Huth         tcg_gen_movi_tl(cpu_pc, pc);
370fcf5ef2aSThomas Huth         tcg_gen_movi_tl(cpu_npc, npc);
37107ea28b4SRichard Henderson         tcg_gen_exit_tb(s->base.tb, tb_num);
372fcf5ef2aSThomas Huth     } else {
373f67ccb2fSRichard Henderson         /* jump to another page: we can use an indirect jump */
374fcf5ef2aSThomas Huth         tcg_gen_movi_tl(cpu_pc, pc);
375fcf5ef2aSThomas Huth         tcg_gen_movi_tl(cpu_npc, npc);
376f67ccb2fSRichard Henderson         tcg_gen_lookup_and_goto_ptr();
377fcf5ef2aSThomas Huth     }
378fcf5ef2aSThomas Huth }
379fcf5ef2aSThomas Huth 
380b989ce73SRichard Henderson static TCGv gen_carry32(void)
381fcf5ef2aSThomas Huth {
382b989ce73SRichard Henderson     if (TARGET_LONG_BITS == 64) {
383b989ce73SRichard Henderson         TCGv t = tcg_temp_new();
384b989ce73SRichard Henderson         tcg_gen_extract_tl(t, cpu_icc_C, 32, 1);
385b989ce73SRichard Henderson         return t;
386b989ce73SRichard Henderson     }
387b989ce73SRichard Henderson     return cpu_icc_C;
388fcf5ef2aSThomas Huth }
389fcf5ef2aSThomas Huth 
390b989ce73SRichard Henderson static void gen_op_addcc_int(TCGv dst, TCGv src1, TCGv src2, TCGv cin)
391fcf5ef2aSThomas Huth {
392b989ce73SRichard Henderson     TCGv z = tcg_constant_tl(0);
393fcf5ef2aSThomas Huth 
394b989ce73SRichard Henderson     if (cin) {
395b989ce73SRichard Henderson         tcg_gen_add2_tl(cpu_cc_N, cpu_cc_C, src1, z, cin, z);
396b989ce73SRichard Henderson         tcg_gen_add2_tl(cpu_cc_N, cpu_cc_C, cpu_cc_N, cpu_cc_C, src2, z);
397b989ce73SRichard Henderson     } else {
398b989ce73SRichard Henderson         tcg_gen_add2_tl(cpu_cc_N, cpu_cc_C, src1, z, src2, z);
399b989ce73SRichard Henderson     }
400b989ce73SRichard Henderson     tcg_gen_xor_tl(cpu_cc_Z, src1, src2);
401b989ce73SRichard Henderson     tcg_gen_xor_tl(cpu_cc_V, cpu_cc_N, src2);
402b989ce73SRichard Henderson     tcg_gen_andc_tl(cpu_cc_V, cpu_cc_V, cpu_cc_Z);
403b989ce73SRichard Henderson     if (TARGET_LONG_BITS == 64) {
404b989ce73SRichard Henderson         /*
405b989ce73SRichard Henderson          * Carry-in to bit 32 is result ^ src1 ^ src2.
406b989ce73SRichard Henderson          * We already have the src xor term in Z, from computation of V.
407b989ce73SRichard Henderson          */
408b989ce73SRichard Henderson         tcg_gen_xor_tl(cpu_icc_C, cpu_cc_Z, cpu_cc_N);
409b989ce73SRichard Henderson         tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N);
410b989ce73SRichard Henderson     }
411b989ce73SRichard Henderson     tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N);
412b989ce73SRichard Henderson     tcg_gen_mov_tl(dst, cpu_cc_N);
413b989ce73SRichard Henderson }
414fcf5ef2aSThomas Huth 
415b989ce73SRichard Henderson static void gen_op_addcc(TCGv dst, TCGv src1, TCGv src2)
416b989ce73SRichard Henderson {
417b989ce73SRichard Henderson     gen_op_addcc_int(dst, src1, src2, NULL);
418b989ce73SRichard Henderson }
419fcf5ef2aSThomas Huth 
420b989ce73SRichard Henderson static void gen_op_taddcc(TCGv dst, TCGv src1, TCGv src2)
421b989ce73SRichard Henderson {
422b989ce73SRichard Henderson     TCGv t = tcg_temp_new();
423b989ce73SRichard Henderson 
424b989ce73SRichard Henderson     /* Save the tag bits around modification of dst. */
425b989ce73SRichard Henderson     tcg_gen_or_tl(t, src1, src2);
426b989ce73SRichard Henderson 
427b989ce73SRichard Henderson     gen_op_addcc(dst, src1, src2);
428b989ce73SRichard Henderson 
429b989ce73SRichard Henderson     /* Incorprate tag bits into icc.V */
430b989ce73SRichard Henderson     tcg_gen_andi_tl(t, t, 3);
431b989ce73SRichard Henderson     tcg_gen_neg_tl(t, t);
432b989ce73SRichard Henderson     tcg_gen_ext32u_tl(t, t);
433b989ce73SRichard Henderson     tcg_gen_or_tl(cpu_cc_V, cpu_cc_V, t);
434b989ce73SRichard Henderson }
435b989ce73SRichard Henderson 
436b989ce73SRichard Henderson static void gen_op_addc(TCGv dst, TCGv src1, TCGv src2)
437b989ce73SRichard Henderson {
438b989ce73SRichard Henderson     tcg_gen_add_tl(dst, src1, src2);
439b989ce73SRichard Henderson     tcg_gen_add_tl(dst, dst, gen_carry32());
440b989ce73SRichard Henderson }
441b989ce73SRichard Henderson 
442b989ce73SRichard Henderson static void gen_op_addccc(TCGv dst, TCGv src1, TCGv src2)
443b989ce73SRichard Henderson {
444b989ce73SRichard Henderson     gen_op_addcc_int(dst, src1, src2, gen_carry32());
445fcf5ef2aSThomas Huth }
446fcf5ef2aSThomas Huth 
447015fc6fcSRichard Henderson static void gen_op_addxc(TCGv dst, TCGv src1, TCGv src2)
448015fc6fcSRichard Henderson {
449015fc6fcSRichard Henderson     tcg_gen_add_tl(dst, src1, src2);
450015fc6fcSRichard Henderson     tcg_gen_add_tl(dst, dst, cpu_cc_C);
451015fc6fcSRichard Henderson }
452015fc6fcSRichard Henderson 
453015fc6fcSRichard Henderson static void gen_op_addxccc(TCGv dst, TCGv src1, TCGv src2)
454015fc6fcSRichard Henderson {
455015fc6fcSRichard Henderson     gen_op_addcc_int(dst, src1, src2, cpu_cc_C);
456015fc6fcSRichard Henderson }
457015fc6fcSRichard Henderson 
458f828df74SRichard Henderson static void gen_op_subcc_int(TCGv dst, TCGv src1, TCGv src2, TCGv cin)
459fcf5ef2aSThomas Huth {
460f828df74SRichard Henderson     TCGv z = tcg_constant_tl(0);
461fcf5ef2aSThomas Huth 
462f828df74SRichard Henderson     if (cin) {
463f828df74SRichard Henderson         tcg_gen_sub2_tl(cpu_cc_N, cpu_cc_C, src1, z, cin, z);
464f828df74SRichard Henderson         tcg_gen_sub2_tl(cpu_cc_N, cpu_cc_C, cpu_cc_N, cpu_cc_C, src2, z);
465f828df74SRichard Henderson     } else {
466f828df74SRichard Henderson         tcg_gen_sub2_tl(cpu_cc_N, cpu_cc_C, src1, z, src2, z);
467f828df74SRichard Henderson     }
468f828df74SRichard Henderson     tcg_gen_neg_tl(cpu_cc_C, cpu_cc_C);
469f828df74SRichard Henderson     tcg_gen_xor_tl(cpu_cc_Z, src1, src2);
470f828df74SRichard Henderson     tcg_gen_xor_tl(cpu_cc_V, cpu_cc_N, src1);
471f828df74SRichard Henderson     tcg_gen_and_tl(cpu_cc_V, cpu_cc_V, cpu_cc_Z);
472f828df74SRichard Henderson #ifdef TARGET_SPARC64
473f828df74SRichard Henderson     tcg_gen_xor_tl(cpu_icc_C, cpu_cc_Z, cpu_cc_N);
474f828df74SRichard Henderson     tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N);
475fcf5ef2aSThomas Huth #endif
476f828df74SRichard Henderson     tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N);
477f828df74SRichard Henderson     tcg_gen_mov_tl(dst, cpu_cc_N);
478fcf5ef2aSThomas Huth }
479fcf5ef2aSThomas Huth 
480f828df74SRichard Henderson static void gen_op_subcc(TCGv dst, TCGv src1, TCGv src2)
481fcf5ef2aSThomas Huth {
482f828df74SRichard Henderson     gen_op_subcc_int(dst, src1, src2, NULL);
483fcf5ef2aSThomas Huth }
484fcf5ef2aSThomas Huth 
485f828df74SRichard Henderson static void gen_op_tsubcc(TCGv dst, TCGv src1, TCGv src2)
486fcf5ef2aSThomas Huth {
487f828df74SRichard Henderson     TCGv t = tcg_temp_new();
488fcf5ef2aSThomas Huth 
489f828df74SRichard Henderson     /* Save the tag bits around modification of dst. */
490f828df74SRichard Henderson     tcg_gen_or_tl(t, src1, src2);
491fcf5ef2aSThomas Huth 
492f828df74SRichard Henderson     gen_op_subcc(dst, src1, src2);
493f828df74SRichard Henderson 
494f828df74SRichard Henderson     /* Incorprate tag bits into icc.V */
495f828df74SRichard Henderson     tcg_gen_andi_tl(t, t, 3);
496f828df74SRichard Henderson     tcg_gen_neg_tl(t, t);
497f828df74SRichard Henderson     tcg_gen_ext32u_tl(t, t);
498f828df74SRichard Henderson     tcg_gen_or_tl(cpu_cc_V, cpu_cc_V, t);
499f828df74SRichard Henderson }
500f828df74SRichard Henderson 
501f828df74SRichard Henderson static void gen_op_subc(TCGv dst, TCGv src1, TCGv src2)
502f828df74SRichard Henderson {
503fcf5ef2aSThomas Huth     tcg_gen_sub_tl(dst, src1, src2);
504f828df74SRichard Henderson     tcg_gen_sub_tl(dst, dst, gen_carry32());
505fcf5ef2aSThomas Huth }
506fcf5ef2aSThomas Huth 
507f828df74SRichard Henderson static void gen_op_subccc(TCGv dst, TCGv src1, TCGv src2)
508dfebb950SRichard Henderson {
509f828df74SRichard Henderson     gen_op_subcc_int(dst, src1, src2, gen_carry32());
510dfebb950SRichard Henderson }
511dfebb950SRichard Henderson 
5120c2e96c1SRichard Henderson static void gen_op_mulscc(TCGv dst, TCGv src1, TCGv src2)
513fcf5ef2aSThomas Huth {
514b989ce73SRichard Henderson     TCGv zero = tcg_constant_tl(0);
51550280618SRichard Henderson     TCGv one = tcg_constant_tl(1);
516b989ce73SRichard Henderson     TCGv t_src1 = tcg_temp_new();
517b989ce73SRichard Henderson     TCGv t_src2 = tcg_temp_new();
518b989ce73SRichard Henderson     TCGv t0 = tcg_temp_new();
519fcf5ef2aSThomas Huth 
520b989ce73SRichard Henderson     tcg_gen_ext32u_tl(t_src1, src1);
521b989ce73SRichard Henderson     tcg_gen_ext32u_tl(t_src2, src2);
522fcf5ef2aSThomas Huth 
523b989ce73SRichard Henderson     /*
524b989ce73SRichard Henderson      * if (!(env->y & 1))
525b989ce73SRichard Henderson      *   src2 = 0;
526fcf5ef2aSThomas Huth      */
52750280618SRichard Henderson     tcg_gen_movcond_tl(TCG_COND_TSTEQ, t_src2, cpu_y, one, zero, t_src2);
528fcf5ef2aSThomas Huth 
529b989ce73SRichard Henderson     /*
530b989ce73SRichard Henderson      * b2 = src1 & 1;
531b989ce73SRichard Henderson      * y = (b2 << 31) | (y >> 1);
532b989ce73SRichard Henderson      */
5330b1183e3SPhilippe Mathieu-Daudé     tcg_gen_extract_tl(t0, cpu_y, 1, 31);
534b989ce73SRichard Henderson     tcg_gen_deposit_tl(cpu_y, t0, src1, 31, 1);
535fcf5ef2aSThomas Huth 
536fcf5ef2aSThomas Huth     // b1 = N ^ V;
5372a1905c7SRichard Henderson     tcg_gen_xor_tl(t0, cpu_cc_N, cpu_cc_V);
538fcf5ef2aSThomas Huth 
539b989ce73SRichard Henderson     /*
540b989ce73SRichard Henderson      * src1 = (b1 << 31) | (src1 >> 1)
541b989ce73SRichard Henderson      */
5422a1905c7SRichard Henderson     tcg_gen_andi_tl(t0, t0, 1u << 31);
543b989ce73SRichard Henderson     tcg_gen_shri_tl(t_src1, t_src1, 1);
544b989ce73SRichard Henderson     tcg_gen_or_tl(t_src1, t_src1, t0);
545fcf5ef2aSThomas Huth 
546b989ce73SRichard Henderson     gen_op_addcc(dst, t_src1, t_src2);
547fcf5ef2aSThomas Huth }
548fcf5ef2aSThomas Huth 
5490c2e96c1SRichard Henderson static void gen_op_multiply(TCGv dst, TCGv src1, TCGv src2, int sign_ext)
550fcf5ef2aSThomas Huth {
551fcf5ef2aSThomas Huth #if TARGET_LONG_BITS == 32
552fcf5ef2aSThomas Huth     if (sign_ext) {
553fcf5ef2aSThomas Huth         tcg_gen_muls2_tl(dst, cpu_y, src1, src2);
554fcf5ef2aSThomas Huth     } else {
555fcf5ef2aSThomas Huth         tcg_gen_mulu2_tl(dst, cpu_y, src1, src2);
556fcf5ef2aSThomas Huth     }
557fcf5ef2aSThomas Huth #else
558fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new_i64();
559fcf5ef2aSThomas Huth     TCGv t1 = tcg_temp_new_i64();
560fcf5ef2aSThomas Huth 
561fcf5ef2aSThomas Huth     if (sign_ext) {
562fcf5ef2aSThomas Huth         tcg_gen_ext32s_i64(t0, src1);
563fcf5ef2aSThomas Huth         tcg_gen_ext32s_i64(t1, src2);
564fcf5ef2aSThomas Huth     } else {
565fcf5ef2aSThomas Huth         tcg_gen_ext32u_i64(t0, src1);
566fcf5ef2aSThomas Huth         tcg_gen_ext32u_i64(t1, src2);
567fcf5ef2aSThomas Huth     }
568fcf5ef2aSThomas Huth 
569fcf5ef2aSThomas Huth     tcg_gen_mul_i64(dst, t0, t1);
570fcf5ef2aSThomas Huth     tcg_gen_shri_i64(cpu_y, dst, 32);
571fcf5ef2aSThomas Huth #endif
572fcf5ef2aSThomas Huth }
573fcf5ef2aSThomas Huth 
5740c2e96c1SRichard Henderson static void gen_op_umul(TCGv dst, TCGv src1, TCGv src2)
575fcf5ef2aSThomas Huth {
576fcf5ef2aSThomas Huth     /* zero-extend truncated operands before multiplication */
577fcf5ef2aSThomas Huth     gen_op_multiply(dst, src1, src2, 0);
578fcf5ef2aSThomas Huth }
579fcf5ef2aSThomas Huth 
5800c2e96c1SRichard Henderson static void gen_op_smul(TCGv dst, TCGv src1, TCGv src2)
581fcf5ef2aSThomas Huth {
582fcf5ef2aSThomas Huth     /* sign-extend truncated operands before multiplication */
583fcf5ef2aSThomas Huth     gen_op_multiply(dst, src1, src2, 1);
584fcf5ef2aSThomas Huth }
585fcf5ef2aSThomas Huth 
586680af1b4SRichard Henderson static void gen_op_umulxhi(TCGv dst, TCGv src1, TCGv src2)
587680af1b4SRichard Henderson {
588680af1b4SRichard Henderson     TCGv discard = tcg_temp_new();
589680af1b4SRichard Henderson     tcg_gen_mulu2_tl(discard, dst, src1, src2);
590680af1b4SRichard Henderson }
591680af1b4SRichard Henderson 
59268a414e9SRichard Henderson static void gen_op_fpmaddx(TCGv_i64 dst, TCGv_i64 src1,
59368a414e9SRichard Henderson                            TCGv_i64 src2, TCGv_i64 src3)
59468a414e9SRichard Henderson {
59568a414e9SRichard Henderson     TCGv_i64 t = tcg_temp_new_i64();
59668a414e9SRichard Henderson 
59768a414e9SRichard Henderson     tcg_gen_mul_i64(t, src1, src2);
59868a414e9SRichard Henderson     tcg_gen_add_i64(dst, src3, t);
59968a414e9SRichard Henderson }
60068a414e9SRichard Henderson 
60168a414e9SRichard Henderson static void gen_op_fpmaddxhi(TCGv_i64 dst, TCGv_i64 src1,
60268a414e9SRichard Henderson                              TCGv_i64 src2, TCGv_i64 src3)
60368a414e9SRichard Henderson {
60468a414e9SRichard Henderson     TCGv_i64 l = tcg_temp_new_i64();
60568a414e9SRichard Henderson     TCGv_i64 h = tcg_temp_new_i64();
60668a414e9SRichard Henderson     TCGv_i64 z = tcg_constant_i64(0);
60768a414e9SRichard Henderson 
60868a414e9SRichard Henderson     tcg_gen_mulu2_i64(l, h, src1, src2);
60968a414e9SRichard Henderson     tcg_gen_add2_i64(l, dst, l, h, src3, z);
61068a414e9SRichard Henderson }
61168a414e9SRichard Henderson 
612c2636853SRichard Henderson static void gen_op_sdiv(TCGv dst, TCGv src1, TCGv src2)
613c2636853SRichard Henderson {
61413260103SRichard Henderson #ifdef TARGET_SPARC64
615c2636853SRichard Henderson     gen_helper_sdiv(dst, tcg_env, src1, src2);
61613260103SRichard Henderson     tcg_gen_ext32s_tl(dst, dst);
61713260103SRichard Henderson #else
61813260103SRichard Henderson     TCGv_i64 t64 = tcg_temp_new_i64();
61913260103SRichard Henderson     gen_helper_sdiv(t64, tcg_env, src1, src2);
62013260103SRichard Henderson     tcg_gen_trunc_i64_tl(dst, t64);
62113260103SRichard Henderson #endif
622c2636853SRichard Henderson }
623c2636853SRichard Henderson 
624c2636853SRichard Henderson static void gen_op_udivcc(TCGv dst, TCGv src1, TCGv src2)
625c2636853SRichard Henderson {
62613260103SRichard Henderson     TCGv_i64 t64;
62713260103SRichard Henderson 
62813260103SRichard Henderson #ifdef TARGET_SPARC64
62913260103SRichard Henderson     t64 = cpu_cc_V;
63013260103SRichard Henderson #else
63113260103SRichard Henderson     t64 = tcg_temp_new_i64();
63213260103SRichard Henderson #endif
63313260103SRichard Henderson 
63413260103SRichard Henderson     gen_helper_udiv(t64, tcg_env, src1, src2);
63513260103SRichard Henderson 
63613260103SRichard Henderson #ifdef TARGET_SPARC64
63713260103SRichard Henderson     tcg_gen_ext32u_tl(cpu_cc_N, t64);
63813260103SRichard Henderson     tcg_gen_shri_tl(cpu_cc_V, t64, 32);
63913260103SRichard Henderson     tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N);
64013260103SRichard Henderson     tcg_gen_movi_tl(cpu_icc_C, 0);
64113260103SRichard Henderson #else
64213260103SRichard Henderson     tcg_gen_extr_i64_tl(cpu_cc_N, cpu_cc_V, t64);
64313260103SRichard Henderson #endif
64413260103SRichard Henderson     tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N);
64513260103SRichard Henderson     tcg_gen_movi_tl(cpu_cc_C, 0);
64613260103SRichard Henderson     tcg_gen_mov_tl(dst, cpu_cc_N);
647c2636853SRichard Henderson }
648c2636853SRichard Henderson 
649c2636853SRichard Henderson static void gen_op_sdivcc(TCGv dst, TCGv src1, TCGv src2)
650c2636853SRichard Henderson {
65113260103SRichard Henderson     TCGv_i64 t64;
65213260103SRichard Henderson 
65313260103SRichard Henderson #ifdef TARGET_SPARC64
65413260103SRichard Henderson     t64 = cpu_cc_V;
65513260103SRichard Henderson #else
65613260103SRichard Henderson     t64 = tcg_temp_new_i64();
65713260103SRichard Henderson #endif
65813260103SRichard Henderson 
65913260103SRichard Henderson     gen_helper_sdiv(t64, tcg_env, src1, src2);
66013260103SRichard Henderson 
66113260103SRichard Henderson #ifdef TARGET_SPARC64
66213260103SRichard Henderson     tcg_gen_ext32s_tl(cpu_cc_N, t64);
66313260103SRichard Henderson     tcg_gen_shri_tl(cpu_cc_V, t64, 32);
66413260103SRichard Henderson     tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N);
66513260103SRichard Henderson     tcg_gen_movi_tl(cpu_icc_C, 0);
66613260103SRichard Henderson #else
66713260103SRichard Henderson     tcg_gen_extr_i64_tl(cpu_cc_N, cpu_cc_V, t64);
66813260103SRichard Henderson #endif
66913260103SRichard Henderson     tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N);
67013260103SRichard Henderson     tcg_gen_movi_tl(cpu_cc_C, 0);
67113260103SRichard Henderson     tcg_gen_mov_tl(dst, cpu_cc_N);
672c2636853SRichard Henderson }
673c2636853SRichard Henderson 
674a9aba13dSRichard Henderson static void gen_op_taddcctv(TCGv dst, TCGv src1, TCGv src2)
675a9aba13dSRichard Henderson {
676a9aba13dSRichard Henderson     gen_helper_taddcctv(dst, tcg_env, src1, src2);
677a9aba13dSRichard Henderson }
678a9aba13dSRichard Henderson 
679a9aba13dSRichard Henderson static void gen_op_tsubcctv(TCGv dst, TCGv src1, TCGv src2)
680a9aba13dSRichard Henderson {
681a9aba13dSRichard Henderson     gen_helper_tsubcctv(dst, tcg_env, src1, src2);
682a9aba13dSRichard Henderson }
683a9aba13dSRichard Henderson 
6849c6ec5bcSRichard Henderson static void gen_op_popc(TCGv dst, TCGv src1, TCGv src2)
6859c6ec5bcSRichard Henderson {
6869c6ec5bcSRichard Henderson     tcg_gen_ctpop_tl(dst, src2);
6879c6ec5bcSRichard Henderson }
6889c6ec5bcSRichard Henderson 
689875ce392SRichard Henderson static void gen_op_lzcnt(TCGv dst, TCGv src)
690875ce392SRichard Henderson {
691875ce392SRichard Henderson     tcg_gen_clzi_tl(dst, src, TARGET_LONG_BITS);
692875ce392SRichard Henderson }
693875ce392SRichard Henderson 
69445bfed3bSRichard Henderson #ifndef TARGET_SPARC64
69545bfed3bSRichard Henderson static void gen_helper_array8(TCGv dst, TCGv src1, TCGv src2)
69645bfed3bSRichard Henderson {
69745bfed3bSRichard Henderson     g_assert_not_reached();
69845bfed3bSRichard Henderson }
69945bfed3bSRichard Henderson #endif
70045bfed3bSRichard Henderson 
70145bfed3bSRichard Henderson static void gen_op_array16(TCGv dst, TCGv src1, TCGv src2)
70245bfed3bSRichard Henderson {
70345bfed3bSRichard Henderson     gen_helper_array8(dst, src1, src2);
70445bfed3bSRichard Henderson     tcg_gen_shli_tl(dst, dst, 1);
70545bfed3bSRichard Henderson }
70645bfed3bSRichard Henderson 
70745bfed3bSRichard Henderson static void gen_op_array32(TCGv dst, TCGv src1, TCGv src2)
70845bfed3bSRichard Henderson {
70945bfed3bSRichard Henderson     gen_helper_array8(dst, src1, src2);
71045bfed3bSRichard Henderson     tcg_gen_shli_tl(dst, dst, 2);
71145bfed3bSRichard Henderson }
71245bfed3bSRichard Henderson 
7132f722641SRichard Henderson static void gen_op_fpack16(TCGv_i32 dst, TCGv_i64 src)
7142f722641SRichard Henderson {
7152f722641SRichard Henderson #ifdef TARGET_SPARC64
7162f722641SRichard Henderson     gen_helper_fpack16(dst, cpu_gsr, src);
7172f722641SRichard Henderson #else
7182f722641SRichard Henderson     g_assert_not_reached();
7192f722641SRichard Henderson #endif
7202f722641SRichard Henderson }
7212f722641SRichard Henderson 
7222f722641SRichard Henderson static void gen_op_fpackfix(TCGv_i32 dst, TCGv_i64 src)
7232f722641SRichard Henderson {
7242f722641SRichard Henderson #ifdef TARGET_SPARC64
7252f722641SRichard Henderson     gen_helper_fpackfix(dst, cpu_gsr, src);
7262f722641SRichard Henderson #else
7272f722641SRichard Henderson     g_assert_not_reached();
7282f722641SRichard Henderson #endif
7292f722641SRichard Henderson }
7302f722641SRichard Henderson 
7314b6edc0aSRichard Henderson static void gen_op_fpack32(TCGv_i64 dst, TCGv_i64 src1, TCGv_i64 src2)
7324b6edc0aSRichard Henderson {
7334b6edc0aSRichard Henderson #ifdef TARGET_SPARC64
7344b6edc0aSRichard Henderson     gen_helper_fpack32(dst, cpu_gsr, src1, src2);
7354b6edc0aSRichard Henderson #else
7364b6edc0aSRichard Henderson     g_assert_not_reached();
7374b6edc0aSRichard Henderson #endif
7384b6edc0aSRichard Henderson }
7394b6edc0aSRichard Henderson 
7400d1d3aafSRichard Henderson static void gen_op_fpadds16s(TCGv_i32 d, TCGv_i32 src1, TCGv_i32 src2)
7410d1d3aafSRichard Henderson {
7420d1d3aafSRichard Henderson     TCGv_i32 t[2];
7430d1d3aafSRichard Henderson 
7440d1d3aafSRichard Henderson     for (int i = 0; i < 2; i++) {
7450d1d3aafSRichard Henderson         TCGv_i32 u = tcg_temp_new_i32();
7460d1d3aafSRichard Henderson         TCGv_i32 v = tcg_temp_new_i32();
7470d1d3aafSRichard Henderson 
7480d1d3aafSRichard Henderson         tcg_gen_sextract_i32(u, src1, i * 16, 16);
7490d1d3aafSRichard Henderson         tcg_gen_sextract_i32(v, src2, i * 16, 16);
7500d1d3aafSRichard Henderson         tcg_gen_add_i32(u, u, v);
7510d1d3aafSRichard Henderson         tcg_gen_smax_i32(u, u, tcg_constant_i32(INT16_MIN));
7520d1d3aafSRichard Henderson         tcg_gen_smin_i32(u, u, tcg_constant_i32(INT16_MAX));
7530d1d3aafSRichard Henderson         t[i] = u;
7540d1d3aafSRichard Henderson     }
7550d1d3aafSRichard Henderson     tcg_gen_deposit_i32(d, t[0], t[1], 16, 16);
7560d1d3aafSRichard Henderson }
7570d1d3aafSRichard Henderson 
7580d1d3aafSRichard Henderson static void gen_op_fpsubs16s(TCGv_i32 d, TCGv_i32 src1, TCGv_i32 src2)
7590d1d3aafSRichard Henderson {
7600d1d3aafSRichard Henderson     TCGv_i32 t[2];
7610d1d3aafSRichard Henderson 
7620d1d3aafSRichard Henderson     for (int i = 0; i < 2; i++) {
7630d1d3aafSRichard Henderson         TCGv_i32 u = tcg_temp_new_i32();
7640d1d3aafSRichard Henderson         TCGv_i32 v = tcg_temp_new_i32();
7650d1d3aafSRichard Henderson 
7660d1d3aafSRichard Henderson         tcg_gen_sextract_i32(u, src1, i * 16, 16);
7670d1d3aafSRichard Henderson         tcg_gen_sextract_i32(v, src2, i * 16, 16);
7680d1d3aafSRichard Henderson         tcg_gen_sub_i32(u, u, v);
7690d1d3aafSRichard Henderson         tcg_gen_smax_i32(u, u, tcg_constant_i32(INT16_MIN));
7700d1d3aafSRichard Henderson         tcg_gen_smin_i32(u, u, tcg_constant_i32(INT16_MAX));
7710d1d3aafSRichard Henderson         t[i] = u;
7720d1d3aafSRichard Henderson     }
7730d1d3aafSRichard Henderson     tcg_gen_deposit_i32(d, t[0], t[1], 16, 16);
7740d1d3aafSRichard Henderson }
7750d1d3aafSRichard Henderson 
7760d1d3aafSRichard Henderson static void gen_op_fpadds32s(TCGv_i32 d, TCGv_i32 src1, TCGv_i32 src2)
7770d1d3aafSRichard Henderson {
7780d1d3aafSRichard Henderson     TCGv_i32 r = tcg_temp_new_i32();
7790d1d3aafSRichard Henderson     TCGv_i32 t = tcg_temp_new_i32();
7800d1d3aafSRichard Henderson     TCGv_i32 v = tcg_temp_new_i32();
7810d1d3aafSRichard Henderson     TCGv_i32 z = tcg_constant_i32(0);
7820d1d3aafSRichard Henderson 
7830d1d3aafSRichard Henderson     tcg_gen_add_i32(r, src1, src2);
7840d1d3aafSRichard Henderson     tcg_gen_xor_i32(t, src1, src2);
7850d1d3aafSRichard Henderson     tcg_gen_xor_i32(v, r, src2);
7860d1d3aafSRichard Henderson     tcg_gen_andc_i32(v, v, t);
7870d1d3aafSRichard Henderson 
7880d1d3aafSRichard Henderson     tcg_gen_setcond_i32(TCG_COND_GE, t, r, z);
7890d1d3aafSRichard Henderson     tcg_gen_addi_i32(t, t, INT32_MAX);
7900d1d3aafSRichard Henderson 
7910d1d3aafSRichard Henderson     tcg_gen_movcond_i32(TCG_COND_LT, d, v, z, t, r);
7920d1d3aafSRichard Henderson }
7930d1d3aafSRichard Henderson 
7940d1d3aafSRichard Henderson static void gen_op_fpsubs32s(TCGv_i32 d, TCGv_i32 src1, TCGv_i32 src2)
7950d1d3aafSRichard Henderson {
7960d1d3aafSRichard Henderson     TCGv_i32 r = tcg_temp_new_i32();
7970d1d3aafSRichard Henderson     TCGv_i32 t = tcg_temp_new_i32();
7980d1d3aafSRichard Henderson     TCGv_i32 v = tcg_temp_new_i32();
7990d1d3aafSRichard Henderson     TCGv_i32 z = tcg_constant_i32(0);
8000d1d3aafSRichard Henderson 
8010d1d3aafSRichard Henderson     tcg_gen_sub_i32(r, src1, src2);
8020d1d3aafSRichard Henderson     tcg_gen_xor_i32(t, src1, src2);
8030d1d3aafSRichard Henderson     tcg_gen_xor_i32(v, r, src1);
8040d1d3aafSRichard Henderson     tcg_gen_and_i32(v, v, t);
8050d1d3aafSRichard Henderson 
8060d1d3aafSRichard Henderson     tcg_gen_setcond_i32(TCG_COND_GE, t, r, z);
8070d1d3aafSRichard Henderson     tcg_gen_addi_i32(t, t, INT32_MAX);
8080d1d3aafSRichard Henderson 
8090d1d3aafSRichard Henderson     tcg_gen_movcond_i32(TCG_COND_LT, d, v, z, t, r);
8100d1d3aafSRichard Henderson }
8110d1d3aafSRichard Henderson 
812*b2b48493SRichard Henderson static void gen_op_faligndata_i(TCGv_i64 dst, TCGv_i64 s1,
813*b2b48493SRichard Henderson                                 TCGv_i64 s2, TCGv gsr)
8144b6edc0aSRichard Henderson {
8154b6edc0aSRichard Henderson #ifdef TARGET_SPARC64
8164b6edc0aSRichard Henderson     TCGv t1, t2, shift;
8174b6edc0aSRichard Henderson 
8184b6edc0aSRichard Henderson     t1 = tcg_temp_new();
8194b6edc0aSRichard Henderson     t2 = tcg_temp_new();
8204b6edc0aSRichard Henderson     shift = tcg_temp_new();
8214b6edc0aSRichard Henderson 
822*b2b48493SRichard Henderson     tcg_gen_andi_tl(shift, gsr, 7);
8234b6edc0aSRichard Henderson     tcg_gen_shli_tl(shift, shift, 3);
8244b6edc0aSRichard Henderson     tcg_gen_shl_tl(t1, s1, shift);
8254b6edc0aSRichard Henderson 
8264b6edc0aSRichard Henderson     /*
8274b6edc0aSRichard Henderson      * A shift of 64 does not produce 0 in TCG.  Divide this into a
8284b6edc0aSRichard Henderson      * shift of (up to 63) followed by a constant shift of 1.
8294b6edc0aSRichard Henderson      */
8304b6edc0aSRichard Henderson     tcg_gen_xori_tl(shift, shift, 63);
8314b6edc0aSRichard Henderson     tcg_gen_shr_tl(t2, s2, shift);
8324b6edc0aSRichard Henderson     tcg_gen_shri_tl(t2, t2, 1);
8334b6edc0aSRichard Henderson 
8344b6edc0aSRichard Henderson     tcg_gen_or_tl(dst, t1, t2);
8354b6edc0aSRichard Henderson #else
8364b6edc0aSRichard Henderson     g_assert_not_reached();
8374b6edc0aSRichard Henderson #endif
8384b6edc0aSRichard Henderson }
8394b6edc0aSRichard Henderson 
840*b2b48493SRichard Henderson static void gen_op_faligndata_g(TCGv_i64 dst, TCGv_i64 s1, TCGv_i64 s2)
841*b2b48493SRichard Henderson {
842*b2b48493SRichard Henderson     gen_op_faligndata_i(dst, s1, s2, cpu_gsr);
843*b2b48493SRichard Henderson }
844*b2b48493SRichard Henderson 
8454b6edc0aSRichard Henderson static void gen_op_bshuffle(TCGv_i64 dst, TCGv_i64 src1, TCGv_i64 src2)
8464b6edc0aSRichard Henderson {
8474b6edc0aSRichard Henderson #ifdef TARGET_SPARC64
8484b6edc0aSRichard Henderson     gen_helper_bshuffle(dst, cpu_gsr, src1, src2);
8494b6edc0aSRichard Henderson #else
8504b6edc0aSRichard Henderson     g_assert_not_reached();
8514b6edc0aSRichard Henderson #endif
8524b6edc0aSRichard Henderson }
8534b6edc0aSRichard Henderson 
8547d5ebd8fSRichard Henderson static void gen_op_pdistn(TCGv dst, TCGv_i64 src1, TCGv_i64 src2)
8557d5ebd8fSRichard Henderson {
8567d5ebd8fSRichard Henderson #ifdef TARGET_SPARC64
8577d5ebd8fSRichard Henderson     gen_helper_pdist(dst, tcg_constant_i64(0), src1, src2);
8587d5ebd8fSRichard Henderson #else
8597d5ebd8fSRichard Henderson     g_assert_not_reached();
8607d5ebd8fSRichard Henderson #endif
8617d5ebd8fSRichard Henderson }
8627d5ebd8fSRichard Henderson 
863a859602cSRichard Henderson static void gen_op_fmul8x16al(TCGv_i64 dst, TCGv_i32 src1, TCGv_i32 src2)
864a859602cSRichard Henderson {
865a859602cSRichard Henderson     tcg_gen_ext16s_i32(src2, src2);
866a859602cSRichard Henderson     gen_helper_fmul8x16a(dst, src1, src2);
867a859602cSRichard Henderson }
868a859602cSRichard Henderson 
869a859602cSRichard Henderson static void gen_op_fmul8x16au(TCGv_i64 dst, TCGv_i32 src1, TCGv_i32 src2)
870a859602cSRichard Henderson {
871a859602cSRichard Henderson     tcg_gen_sari_i32(src2, src2, 16);
872a859602cSRichard Henderson     gen_helper_fmul8x16a(dst, src1, src2);
873a859602cSRichard Henderson }
874a859602cSRichard Henderson 
875be8998e0SRichard Henderson static void gen_op_fmuld8ulx16(TCGv_i64 dst, TCGv_i32 src1, TCGv_i32 src2)
876be8998e0SRichard Henderson {
877be8998e0SRichard Henderson     TCGv_i32 t0 = tcg_temp_new_i32();
878be8998e0SRichard Henderson     TCGv_i32 t1 = tcg_temp_new_i32();
879be8998e0SRichard Henderson     TCGv_i32 t2 = tcg_temp_new_i32();
880be8998e0SRichard Henderson 
881be8998e0SRichard Henderson     tcg_gen_ext8u_i32(t0, src1);
882be8998e0SRichard Henderson     tcg_gen_ext16s_i32(t1, src2);
883be8998e0SRichard Henderson     tcg_gen_mul_i32(t0, t0, t1);
884be8998e0SRichard Henderson 
885be8998e0SRichard Henderson     tcg_gen_extract_i32(t1, src1, 16, 8);
886be8998e0SRichard Henderson     tcg_gen_sextract_i32(t2, src2, 16, 16);
887be8998e0SRichard Henderson     tcg_gen_mul_i32(t1, t1, t2);
888be8998e0SRichard Henderson 
889be8998e0SRichard Henderson     tcg_gen_concat_i32_i64(dst, t0, t1);
890be8998e0SRichard Henderson }
891be8998e0SRichard Henderson 
892be8998e0SRichard Henderson static void gen_op_fmuld8sux16(TCGv_i64 dst, TCGv_i32 src1, TCGv_i32 src2)
893be8998e0SRichard Henderson {
894be8998e0SRichard Henderson     TCGv_i32 t0 = tcg_temp_new_i32();
895be8998e0SRichard Henderson     TCGv_i32 t1 = tcg_temp_new_i32();
896be8998e0SRichard Henderson     TCGv_i32 t2 = tcg_temp_new_i32();
897be8998e0SRichard Henderson 
898be8998e0SRichard Henderson     /*
899be8998e0SRichard Henderson      * The insn description talks about extracting the upper 8 bits
900be8998e0SRichard Henderson      * of the signed 16-bit input rs1, performing the multiply, then
901be8998e0SRichard Henderson      * shifting left by 8 bits.  Instead, zap the lower 8 bits of
902be8998e0SRichard Henderson      * the rs1 input, which avoids the need for two shifts.
903be8998e0SRichard Henderson      */
904be8998e0SRichard Henderson     tcg_gen_ext16s_i32(t0, src1);
905be8998e0SRichard Henderson     tcg_gen_andi_i32(t0, t0, ~0xff);
906be8998e0SRichard Henderson     tcg_gen_ext16s_i32(t1, src2);
907be8998e0SRichard Henderson     tcg_gen_mul_i32(t0, t0, t1);
908be8998e0SRichard Henderson 
909be8998e0SRichard Henderson     tcg_gen_sextract_i32(t1, src1, 16, 16);
910be8998e0SRichard Henderson     tcg_gen_andi_i32(t1, t1, ~0xff);
911be8998e0SRichard Henderson     tcg_gen_sextract_i32(t2, src2, 16, 16);
912be8998e0SRichard Henderson     tcg_gen_mul_i32(t1, t1, t2);
913be8998e0SRichard Henderson 
914be8998e0SRichard Henderson     tcg_gen_concat_i32_i64(dst, t0, t1);
915be8998e0SRichard Henderson }
916be8998e0SRichard Henderson 
9177837185eSRichard Henderson #ifdef TARGET_SPARC64
9187837185eSRichard Henderson static void gen_vec_fchksm16(unsigned vece, TCGv_vec dst,
9197837185eSRichard Henderson                              TCGv_vec src1, TCGv_vec src2)
9207837185eSRichard Henderson {
9217837185eSRichard Henderson     TCGv_vec a = tcg_temp_new_vec_matching(dst);
9227837185eSRichard Henderson     TCGv_vec c = tcg_temp_new_vec_matching(dst);
9237837185eSRichard Henderson 
9247837185eSRichard Henderson     tcg_gen_add_vec(vece, a, src1, src2);
9257837185eSRichard Henderson     tcg_gen_cmp_vec(TCG_COND_LTU, vece, c, a, src1);
9267837185eSRichard Henderson     /* Vector cmp produces -1 for true, so subtract to add carry. */
9277837185eSRichard Henderson     tcg_gen_sub_vec(vece, dst, a, c);
9287837185eSRichard Henderson }
9297837185eSRichard Henderson 
9307837185eSRichard Henderson static void gen_op_fchksm16(unsigned vece, uint32_t dofs, uint32_t aofs,
9317837185eSRichard Henderson                             uint32_t bofs, uint32_t oprsz, uint32_t maxsz)
9327837185eSRichard Henderson {
9337837185eSRichard Henderson     static const TCGOpcode vecop_list[] = {
9347837185eSRichard Henderson         INDEX_op_cmp_vec, INDEX_op_add_vec, INDEX_op_sub_vec,
9357837185eSRichard Henderson     };
9367837185eSRichard Henderson     static const GVecGen3 op = {
9377837185eSRichard Henderson         .fni8 = gen_helper_fchksm16,
9387837185eSRichard Henderson         .fniv = gen_vec_fchksm16,
9397837185eSRichard Henderson         .opt_opc = vecop_list,
9407837185eSRichard Henderson         .vece = MO_16,
9417837185eSRichard Henderson     };
9427837185eSRichard Henderson     tcg_gen_gvec_3(dofs, aofs, bofs, oprsz, maxsz, &op);
9437837185eSRichard Henderson }
944d6ff1ccbSRichard Henderson 
945d6ff1ccbSRichard Henderson static void gen_vec_fmean16(unsigned vece, TCGv_vec dst,
946d6ff1ccbSRichard Henderson                             TCGv_vec src1, TCGv_vec src2)
947d6ff1ccbSRichard Henderson {
948d6ff1ccbSRichard Henderson     TCGv_vec t = tcg_temp_new_vec_matching(dst);
949d6ff1ccbSRichard Henderson 
950d6ff1ccbSRichard Henderson     tcg_gen_or_vec(vece, t, src1, src2);
951d6ff1ccbSRichard Henderson     tcg_gen_and_vec(vece, t, t, tcg_constant_vec_matching(dst, vece, 1));
952d6ff1ccbSRichard Henderson     tcg_gen_sari_vec(vece, src1, src1, 1);
953d6ff1ccbSRichard Henderson     tcg_gen_sari_vec(vece, src2, src2, 1);
954d6ff1ccbSRichard Henderson     tcg_gen_add_vec(vece, dst, src1, src2);
955d6ff1ccbSRichard Henderson     tcg_gen_add_vec(vece, dst, dst, t);
956d6ff1ccbSRichard Henderson }
957d6ff1ccbSRichard Henderson 
958d6ff1ccbSRichard Henderson static void gen_op_fmean16(unsigned vece, uint32_t dofs, uint32_t aofs,
959d6ff1ccbSRichard Henderson                            uint32_t bofs, uint32_t oprsz, uint32_t maxsz)
960d6ff1ccbSRichard Henderson {
961d6ff1ccbSRichard Henderson     static const TCGOpcode vecop_list[] = {
962d6ff1ccbSRichard Henderson         INDEX_op_add_vec, INDEX_op_sari_vec,
963d6ff1ccbSRichard Henderson     };
964d6ff1ccbSRichard Henderson     static const GVecGen3 op = {
965d6ff1ccbSRichard Henderson         .fni8 = gen_helper_fmean16,
966d6ff1ccbSRichard Henderson         .fniv = gen_vec_fmean16,
967d6ff1ccbSRichard Henderson         .opt_opc = vecop_list,
968d6ff1ccbSRichard Henderson         .vece = MO_16,
969d6ff1ccbSRichard Henderson     };
970d6ff1ccbSRichard Henderson     tcg_gen_gvec_3(dofs, aofs, bofs, oprsz, maxsz, &op);
971d6ff1ccbSRichard Henderson }
9727837185eSRichard Henderson #else
9737837185eSRichard Henderson #define gen_op_fchksm16   ({ qemu_build_not_reached(); NULL; })
974d6ff1ccbSRichard Henderson #define gen_op_fmean16    ({ qemu_build_not_reached(); NULL; })
9757837185eSRichard Henderson #endif
9767837185eSRichard Henderson 
97789527e3aSRichard Henderson static void finishing_insn(DisasContext *dc)
97889527e3aSRichard Henderson {
97989527e3aSRichard Henderson     /*
98089527e3aSRichard Henderson      * From here, there is no future path through an unwinding exception.
98189527e3aSRichard Henderson      * If the current insn cannot raise an exception, the computation of
98289527e3aSRichard Henderson      * cpu_cond may be able to be elided.
98389527e3aSRichard Henderson      */
98489527e3aSRichard Henderson     if (dc->cpu_cond_live) {
98589527e3aSRichard Henderson         tcg_gen_discard_tl(cpu_cond);
98689527e3aSRichard Henderson         dc->cpu_cond_live = false;
98789527e3aSRichard Henderson     }
98889527e3aSRichard Henderson }
98989527e3aSRichard Henderson 
9900c2e96c1SRichard Henderson static void gen_generic_branch(DisasContext *dc)
991fcf5ef2aSThomas Huth {
99200ab7e61SRichard Henderson     TCGv npc0 = tcg_constant_tl(dc->jump_pc[0]);
99300ab7e61SRichard Henderson     TCGv npc1 = tcg_constant_tl(dc->jump_pc[1]);
994533f042fSRichard Henderson     TCGv c2 = tcg_constant_tl(dc->jump.c2);
995fcf5ef2aSThomas Huth 
996533f042fSRichard Henderson     tcg_gen_movcond_tl(dc->jump.cond, cpu_npc, dc->jump.c1, c2, npc0, npc1);
997fcf5ef2aSThomas Huth }
998fcf5ef2aSThomas Huth 
999fcf5ef2aSThomas Huth /* call this function before using the condition register as it may
1000fcf5ef2aSThomas Huth    have been set for a jump */
10010c2e96c1SRichard Henderson static void flush_cond(DisasContext *dc)
1002fcf5ef2aSThomas Huth {
1003fcf5ef2aSThomas Huth     if (dc->npc == JUMP_PC) {
1004fcf5ef2aSThomas Huth         gen_generic_branch(dc);
100599c82c47SRichard Henderson         dc->npc = DYNAMIC_PC_LOOKUP;
1006fcf5ef2aSThomas Huth     }
1007fcf5ef2aSThomas Huth }
1008fcf5ef2aSThomas Huth 
10090c2e96c1SRichard Henderson static void save_npc(DisasContext *dc)
1010fcf5ef2aSThomas Huth {
1011633c4283SRichard Henderson     if (dc->npc & 3) {
1012633c4283SRichard Henderson         switch (dc->npc) {
1013633c4283SRichard Henderson         case JUMP_PC:
1014fcf5ef2aSThomas Huth             gen_generic_branch(dc);
101599c82c47SRichard Henderson             dc->npc = DYNAMIC_PC_LOOKUP;
1016633c4283SRichard Henderson             break;
1017633c4283SRichard Henderson         case DYNAMIC_PC:
1018633c4283SRichard Henderson         case DYNAMIC_PC_LOOKUP:
1019633c4283SRichard Henderson             break;
1020633c4283SRichard Henderson         default:
1021633c4283SRichard Henderson             g_assert_not_reached();
1022633c4283SRichard Henderson         }
1023633c4283SRichard Henderson     } else {
1024fcf5ef2aSThomas Huth         tcg_gen_movi_tl(cpu_npc, dc->npc);
1025fcf5ef2aSThomas Huth     }
1026fcf5ef2aSThomas Huth }
1027fcf5ef2aSThomas Huth 
10280c2e96c1SRichard Henderson static void save_state(DisasContext *dc)
1029fcf5ef2aSThomas Huth {
1030fcf5ef2aSThomas Huth     tcg_gen_movi_tl(cpu_pc, dc->pc);
1031fcf5ef2aSThomas Huth     save_npc(dc);
1032fcf5ef2aSThomas Huth }
1033fcf5ef2aSThomas Huth 
1034fcf5ef2aSThomas Huth static void gen_exception(DisasContext *dc, int which)
1035fcf5ef2aSThomas Huth {
103689527e3aSRichard Henderson     finishing_insn(dc);
1037fcf5ef2aSThomas Huth     save_state(dc);
1038ad75a51eSRichard Henderson     gen_helper_raise_exception(tcg_env, tcg_constant_i32(which));
1039af00be49SEmilio G. Cota     dc->base.is_jmp = DISAS_NORETURN;
1040fcf5ef2aSThomas Huth }
1041fcf5ef2aSThomas Huth 
1042186e7890SRichard Henderson static TCGLabel *delay_exceptionv(DisasContext *dc, TCGv_i32 excp)
1043fcf5ef2aSThomas Huth {
1044186e7890SRichard Henderson     DisasDelayException *e = g_new0(DisasDelayException, 1);
1045186e7890SRichard Henderson 
1046186e7890SRichard Henderson     e->next = dc->delay_excp_list;
1047186e7890SRichard Henderson     dc->delay_excp_list = e;
1048186e7890SRichard Henderson 
1049186e7890SRichard Henderson     e->lab = gen_new_label();
1050186e7890SRichard Henderson     e->excp = excp;
1051186e7890SRichard Henderson     e->pc = dc->pc;
1052186e7890SRichard Henderson     /* Caller must have used flush_cond before branch. */
1053186e7890SRichard Henderson     assert(e->npc != JUMP_PC);
1054186e7890SRichard Henderson     e->npc = dc->npc;
1055186e7890SRichard Henderson 
1056186e7890SRichard Henderson     return e->lab;
1057186e7890SRichard Henderson }
1058186e7890SRichard Henderson 
1059186e7890SRichard Henderson static TCGLabel *delay_exception(DisasContext *dc, int excp)
1060186e7890SRichard Henderson {
1061186e7890SRichard Henderson     return delay_exceptionv(dc, tcg_constant_i32(excp));
1062186e7890SRichard Henderson }
1063186e7890SRichard Henderson 
1064186e7890SRichard Henderson static void gen_check_align(DisasContext *dc, TCGv addr, int mask)
1065186e7890SRichard Henderson {
1066186e7890SRichard Henderson     TCGv t = tcg_temp_new();
1067186e7890SRichard Henderson     TCGLabel *lab;
1068186e7890SRichard Henderson 
1069186e7890SRichard Henderson     tcg_gen_andi_tl(t, addr, mask);
1070186e7890SRichard Henderson 
1071186e7890SRichard Henderson     flush_cond(dc);
1072186e7890SRichard Henderson     lab = delay_exception(dc, TT_UNALIGNED);
1073186e7890SRichard Henderson     tcg_gen_brcondi_tl(TCG_COND_NE, t, 0, lab);
1074fcf5ef2aSThomas Huth }
1075fcf5ef2aSThomas Huth 
10760c2e96c1SRichard Henderson static void gen_mov_pc_npc(DisasContext *dc)
1077fcf5ef2aSThomas Huth {
107889527e3aSRichard Henderson     finishing_insn(dc);
107989527e3aSRichard Henderson 
1080633c4283SRichard Henderson     if (dc->npc & 3) {
1081633c4283SRichard Henderson         switch (dc->npc) {
1082633c4283SRichard Henderson         case JUMP_PC:
1083fcf5ef2aSThomas Huth             gen_generic_branch(dc);
1084fcf5ef2aSThomas Huth             tcg_gen_mov_tl(cpu_pc, cpu_npc);
108599c82c47SRichard Henderson             dc->pc = DYNAMIC_PC_LOOKUP;
1086633c4283SRichard Henderson             break;
1087633c4283SRichard Henderson         case DYNAMIC_PC:
1088633c4283SRichard Henderson         case DYNAMIC_PC_LOOKUP:
1089fcf5ef2aSThomas Huth             tcg_gen_mov_tl(cpu_pc, cpu_npc);
1090633c4283SRichard Henderson             dc->pc = dc->npc;
1091633c4283SRichard Henderson             break;
1092633c4283SRichard Henderson         default:
1093633c4283SRichard Henderson             g_assert_not_reached();
1094633c4283SRichard Henderson         }
1095fcf5ef2aSThomas Huth     } else {
1096fcf5ef2aSThomas Huth         dc->pc = dc->npc;
1097fcf5ef2aSThomas Huth     }
1098fcf5ef2aSThomas Huth }
1099fcf5ef2aSThomas Huth 
1100fcf5ef2aSThomas Huth static void gen_compare(DisasCompare *cmp, bool xcc, unsigned int cond,
1101fcf5ef2aSThomas Huth                         DisasContext *dc)
1102fcf5ef2aSThomas Huth {
1103b597eedcSRichard Henderson     TCGv t1;
1104fcf5ef2aSThomas Huth 
11052a1905c7SRichard Henderson     cmp->c1 = t1 = tcg_temp_new();
1106c8507ebfSRichard Henderson     cmp->c2 = 0;
11072a1905c7SRichard Henderson 
11082a1905c7SRichard Henderson     switch (cond & 7) {
11092a1905c7SRichard Henderson     case 0x0: /* never */
11102a1905c7SRichard Henderson         cmp->cond = TCG_COND_NEVER;
1111c8507ebfSRichard Henderson         cmp->c1 = tcg_constant_tl(0);
1112fcf5ef2aSThomas Huth         break;
11132a1905c7SRichard Henderson 
11142a1905c7SRichard Henderson     case 0x1: /* eq: Z */
11152a1905c7SRichard Henderson         cmp->cond = TCG_COND_EQ;
11162a1905c7SRichard Henderson         if (TARGET_LONG_BITS == 32 || xcc) {
11172a1905c7SRichard Henderson             tcg_gen_mov_tl(t1, cpu_cc_Z);
11182a1905c7SRichard Henderson         } else {
11192a1905c7SRichard Henderson             tcg_gen_ext32u_tl(t1, cpu_icc_Z);
11202a1905c7SRichard Henderson         }
11212a1905c7SRichard Henderson         break;
11222a1905c7SRichard Henderson 
11232a1905c7SRichard Henderson     case 0x2: /* le: Z | (N ^ V) */
11242a1905c7SRichard Henderson         /*
11252a1905c7SRichard Henderson          * Simplify:
11262a1905c7SRichard Henderson          *   cc_Z || (N ^ V) < 0        NE
11272a1905c7SRichard Henderson          *   cc_Z && !((N ^ V) < 0)     EQ
11282a1905c7SRichard Henderson          *   cc_Z & ~((N ^ V) >> TLB)   EQ
11292a1905c7SRichard Henderson          */
11302a1905c7SRichard Henderson         cmp->cond = TCG_COND_EQ;
11312a1905c7SRichard Henderson         tcg_gen_xor_tl(t1, cpu_cc_N, cpu_cc_V);
11322a1905c7SRichard Henderson         tcg_gen_sextract_tl(t1, t1, xcc ? 63 : 31, 1);
11332a1905c7SRichard Henderson         tcg_gen_andc_tl(t1, xcc ? cpu_cc_Z : cpu_icc_Z, t1);
11342a1905c7SRichard Henderson         if (TARGET_LONG_BITS == 64 && !xcc) {
11352a1905c7SRichard Henderson             tcg_gen_ext32u_tl(t1, t1);
11362a1905c7SRichard Henderson         }
11372a1905c7SRichard Henderson         break;
11382a1905c7SRichard Henderson 
11392a1905c7SRichard Henderson     case 0x3: /* lt: N ^ V */
11402a1905c7SRichard Henderson         cmp->cond = TCG_COND_LT;
11412a1905c7SRichard Henderson         tcg_gen_xor_tl(t1, cpu_cc_N, cpu_cc_V);
11422a1905c7SRichard Henderson         if (TARGET_LONG_BITS == 64 && !xcc) {
11432a1905c7SRichard Henderson             tcg_gen_ext32s_tl(t1, t1);
11442a1905c7SRichard Henderson         }
11452a1905c7SRichard Henderson         break;
11462a1905c7SRichard Henderson 
11472a1905c7SRichard Henderson     case 0x4: /* leu: Z | C */
11482a1905c7SRichard Henderson         /*
11492a1905c7SRichard Henderson          * Simplify:
11502a1905c7SRichard Henderson          *   cc_Z == 0 || cc_C != 0     NE
11512a1905c7SRichard Henderson          *   cc_Z != 0 && cc_C == 0     EQ
11522a1905c7SRichard Henderson          *   cc_Z & (cc_C ? 0 : -1)     EQ
11532a1905c7SRichard Henderson          *   cc_Z & (cc_C - 1)          EQ
11542a1905c7SRichard Henderson          */
11552a1905c7SRichard Henderson         cmp->cond = TCG_COND_EQ;
11562a1905c7SRichard Henderson         if (TARGET_LONG_BITS == 32 || xcc) {
11572a1905c7SRichard Henderson             tcg_gen_subi_tl(t1, cpu_cc_C, 1);
11582a1905c7SRichard Henderson             tcg_gen_and_tl(t1, t1, cpu_cc_Z);
11592a1905c7SRichard Henderson         } else {
11602a1905c7SRichard Henderson             tcg_gen_extract_tl(t1, cpu_icc_C, 32, 1);
11612a1905c7SRichard Henderson             tcg_gen_subi_tl(t1, t1, 1);
11622a1905c7SRichard Henderson             tcg_gen_and_tl(t1, t1, cpu_icc_Z);
11632a1905c7SRichard Henderson             tcg_gen_ext32u_tl(t1, t1);
11642a1905c7SRichard Henderson         }
11652a1905c7SRichard Henderson         break;
11662a1905c7SRichard Henderson 
11672a1905c7SRichard Henderson     case 0x5: /* ltu: C */
11682a1905c7SRichard Henderson         cmp->cond = TCG_COND_NE;
11692a1905c7SRichard Henderson         if (TARGET_LONG_BITS == 32 || xcc) {
11702a1905c7SRichard Henderson             tcg_gen_mov_tl(t1, cpu_cc_C);
11712a1905c7SRichard Henderson         } else {
11722a1905c7SRichard Henderson             tcg_gen_extract_tl(t1, cpu_icc_C, 32, 1);
11732a1905c7SRichard Henderson         }
11742a1905c7SRichard Henderson         break;
11752a1905c7SRichard Henderson 
11762a1905c7SRichard Henderson     case 0x6: /* neg: N */
11772a1905c7SRichard Henderson         cmp->cond = TCG_COND_LT;
11782a1905c7SRichard Henderson         if (TARGET_LONG_BITS == 32 || xcc) {
11792a1905c7SRichard Henderson             tcg_gen_mov_tl(t1, cpu_cc_N);
11802a1905c7SRichard Henderson         } else {
11812a1905c7SRichard Henderson             tcg_gen_ext32s_tl(t1, cpu_cc_N);
11822a1905c7SRichard Henderson         }
11832a1905c7SRichard Henderson         break;
11842a1905c7SRichard Henderson 
11852a1905c7SRichard Henderson     case 0x7: /* vs: V */
11862a1905c7SRichard Henderson         cmp->cond = TCG_COND_LT;
11872a1905c7SRichard Henderson         if (TARGET_LONG_BITS == 32 || xcc) {
11882a1905c7SRichard Henderson             tcg_gen_mov_tl(t1, cpu_cc_V);
11892a1905c7SRichard Henderson         } else {
11902a1905c7SRichard Henderson             tcg_gen_ext32s_tl(t1, cpu_cc_V);
11912a1905c7SRichard Henderson         }
11922a1905c7SRichard Henderson         break;
11932a1905c7SRichard Henderson     }
11942a1905c7SRichard Henderson     if (cond & 8) {
11952a1905c7SRichard Henderson         cmp->cond = tcg_invert_cond(cmp->cond);
1196fcf5ef2aSThomas Huth     }
1197fcf5ef2aSThomas Huth }
1198fcf5ef2aSThomas Huth 
1199fcf5ef2aSThomas Huth static void gen_fcompare(DisasCompare *cmp, unsigned int cc, unsigned int cond)
1200fcf5ef2aSThomas Huth {
1201d8c5b92fSRichard Henderson     TCGv_i32 fcc = cpu_fcc[cc];
1202d8c5b92fSRichard Henderson     TCGv_i32 c1 = fcc;
1203d8c5b92fSRichard Henderson     int c2 = 0;
1204d8c5b92fSRichard Henderson     TCGCond tcond;
1205fcf5ef2aSThomas Huth 
1206d8c5b92fSRichard Henderson     /*
1207d8c5b92fSRichard Henderson      * FCC values:
1208d8c5b92fSRichard Henderson      * 0 =
1209d8c5b92fSRichard Henderson      * 1 <
1210d8c5b92fSRichard Henderson      * 2 >
1211d8c5b92fSRichard Henderson      * 3 unordered
1212d8c5b92fSRichard Henderson      */
1213d8c5b92fSRichard Henderson     switch (cond & 7) {
1214d8c5b92fSRichard Henderson     case 0x0: /* fbn */
1215d8c5b92fSRichard Henderson         tcond = TCG_COND_NEVER;
1216fcf5ef2aSThomas Huth         break;
1217d8c5b92fSRichard Henderson     case 0x1: /* fbne : !0 */
1218d8c5b92fSRichard Henderson         tcond = TCG_COND_NE;
1219fcf5ef2aSThomas Huth         break;
1220d8c5b92fSRichard Henderson     case 0x2: /* fblg : 1 or 2 */
1221d8c5b92fSRichard Henderson         /* fcc in {1,2} - 1 -> fcc in {0,1} */
1222d8c5b92fSRichard Henderson         c1 = tcg_temp_new_i32();
1223d8c5b92fSRichard Henderson         tcg_gen_addi_i32(c1, fcc, -1);
1224d8c5b92fSRichard Henderson         c2 = 1;
1225d8c5b92fSRichard Henderson         tcond = TCG_COND_LEU;
1226fcf5ef2aSThomas Huth         break;
1227d8c5b92fSRichard Henderson     case 0x3: /* fbul : 1 or 3 */
1228d8c5b92fSRichard Henderson         c1 = tcg_temp_new_i32();
1229d8c5b92fSRichard Henderson         tcg_gen_andi_i32(c1, fcc, 1);
1230d8c5b92fSRichard Henderson         tcond = TCG_COND_NE;
1231d8c5b92fSRichard Henderson         break;
1232d8c5b92fSRichard Henderson     case 0x4: /* fbl  : 1 */
1233d8c5b92fSRichard Henderson         c2 = 1;
1234d8c5b92fSRichard Henderson         tcond = TCG_COND_EQ;
1235d8c5b92fSRichard Henderson         break;
1236d8c5b92fSRichard Henderson     case 0x5: /* fbug : 2 or 3 */
1237d8c5b92fSRichard Henderson         c2 = 2;
1238d8c5b92fSRichard Henderson         tcond = TCG_COND_GEU;
1239d8c5b92fSRichard Henderson         break;
1240d8c5b92fSRichard Henderson     case 0x6: /* fbg  : 2 */
1241d8c5b92fSRichard Henderson         c2 = 2;
1242d8c5b92fSRichard Henderson         tcond = TCG_COND_EQ;
1243d8c5b92fSRichard Henderson         break;
1244d8c5b92fSRichard Henderson     case 0x7: /* fbu  : 3 */
1245d8c5b92fSRichard Henderson         c2 = 3;
1246d8c5b92fSRichard Henderson         tcond = TCG_COND_EQ;
1247fcf5ef2aSThomas Huth         break;
1248fcf5ef2aSThomas Huth     }
1249d8c5b92fSRichard Henderson     if (cond & 8) {
1250d8c5b92fSRichard Henderson         tcond = tcg_invert_cond(tcond);
1251fcf5ef2aSThomas Huth     }
1252d8c5b92fSRichard Henderson 
1253d8c5b92fSRichard Henderson     cmp->cond = tcond;
1254d8c5b92fSRichard Henderson     cmp->c2 = c2;
1255d8c5b92fSRichard Henderson     cmp->c1 = tcg_temp_new();
1256d8c5b92fSRichard Henderson     tcg_gen_extu_i32_tl(cmp->c1, c1);
1257fcf5ef2aSThomas Huth }
1258fcf5ef2aSThomas Huth 
12592c4f56c9SRichard Henderson static bool gen_compare_reg(DisasCompare *cmp, int cond, TCGv r_src)
12602c4f56c9SRichard Henderson {
12612c4f56c9SRichard Henderson     static const TCGCond cond_reg[4] = {
1262ab9ffe98SRichard Henderson         TCG_COND_NEVER,  /* reserved */
1263fcf5ef2aSThomas Huth         TCG_COND_EQ,
1264fcf5ef2aSThomas Huth         TCG_COND_LE,
1265fcf5ef2aSThomas Huth         TCG_COND_LT,
1266fcf5ef2aSThomas Huth     };
12672c4f56c9SRichard Henderson     TCGCond tcond;
1268fcf5ef2aSThomas Huth 
12692c4f56c9SRichard Henderson     if ((cond & 3) == 0) {
12702c4f56c9SRichard Henderson         return false;
12712c4f56c9SRichard Henderson     }
12722c4f56c9SRichard Henderson     tcond = cond_reg[cond & 3];
12732c4f56c9SRichard Henderson     if (cond & 4) {
12742c4f56c9SRichard Henderson         tcond = tcg_invert_cond(tcond);
12752c4f56c9SRichard Henderson     }
12762c4f56c9SRichard Henderson 
12772c4f56c9SRichard Henderson     cmp->cond = tcond;
1278816f89b7SRichard Henderson     cmp->c1 = tcg_temp_new();
1279c8507ebfSRichard Henderson     cmp->c2 = 0;
1280816f89b7SRichard Henderson     tcg_gen_mov_tl(cmp->c1, r_src);
12812c4f56c9SRichard Henderson     return true;
1282fcf5ef2aSThomas Huth }
1283fcf5ef2aSThomas Huth 
1284baf3dbf2SRichard Henderson static void gen_op_clear_ieee_excp_and_FTT(void)
1285baf3dbf2SRichard Henderson {
12863590f01eSRichard Henderson     tcg_gen_st_i32(tcg_constant_i32(0), tcg_env,
12873590f01eSRichard Henderson                    offsetof(CPUSPARCState, fsr_cexc_ftt));
1288baf3dbf2SRichard Henderson }
1289baf3dbf2SRichard Henderson 
1290baf3dbf2SRichard Henderson static void gen_op_fmovs(TCGv_i32 dst, TCGv_i32 src)
1291baf3dbf2SRichard Henderson {
1292baf3dbf2SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
1293baf3dbf2SRichard Henderson     tcg_gen_mov_i32(dst, src);
1294baf3dbf2SRichard Henderson }
1295baf3dbf2SRichard Henderson 
1296baf3dbf2SRichard Henderson static void gen_op_fnegs(TCGv_i32 dst, TCGv_i32 src)
1297baf3dbf2SRichard Henderson {
1298baf3dbf2SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
1299daf457d4SRichard Henderson     tcg_gen_xori_i32(dst, src, 1u << 31);
1300baf3dbf2SRichard Henderson }
1301baf3dbf2SRichard Henderson 
1302baf3dbf2SRichard Henderson static void gen_op_fabss(TCGv_i32 dst, TCGv_i32 src)
1303baf3dbf2SRichard Henderson {
1304baf3dbf2SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
1305daf457d4SRichard Henderson     tcg_gen_andi_i32(dst, src, ~(1u << 31));
1306baf3dbf2SRichard Henderson }
1307baf3dbf2SRichard Henderson 
1308c6d83e4fSRichard Henderson static void gen_op_fmovd(TCGv_i64 dst, TCGv_i64 src)
1309c6d83e4fSRichard Henderson {
1310c6d83e4fSRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
1311c6d83e4fSRichard Henderson     tcg_gen_mov_i64(dst, src);
1312c6d83e4fSRichard Henderson }
1313c6d83e4fSRichard Henderson 
1314c6d83e4fSRichard Henderson static void gen_op_fnegd(TCGv_i64 dst, TCGv_i64 src)
1315c6d83e4fSRichard Henderson {
1316c6d83e4fSRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
1317daf457d4SRichard Henderson     tcg_gen_xori_i64(dst, src, 1ull << 63);
1318c6d83e4fSRichard Henderson }
1319c6d83e4fSRichard Henderson 
1320c6d83e4fSRichard Henderson static void gen_op_fabsd(TCGv_i64 dst, TCGv_i64 src)
1321c6d83e4fSRichard Henderson {
1322c6d83e4fSRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
1323daf457d4SRichard Henderson     tcg_gen_andi_i64(dst, src, ~(1ull << 63));
1324daf457d4SRichard Henderson }
1325daf457d4SRichard Henderson 
1326daf457d4SRichard Henderson static void gen_op_fnegq(TCGv_i128 dst, TCGv_i128 src)
1327daf457d4SRichard Henderson {
1328daf457d4SRichard Henderson     TCGv_i64 l = tcg_temp_new_i64();
1329daf457d4SRichard Henderson     TCGv_i64 h = tcg_temp_new_i64();
1330daf457d4SRichard Henderson 
1331daf457d4SRichard Henderson     tcg_gen_extr_i128_i64(l, h, src);
1332daf457d4SRichard Henderson     tcg_gen_xori_i64(h, h, 1ull << 63);
1333daf457d4SRichard Henderson     tcg_gen_concat_i64_i128(dst, l, h);
1334daf457d4SRichard Henderson }
1335daf457d4SRichard Henderson 
1336daf457d4SRichard Henderson static void gen_op_fabsq(TCGv_i128 dst, TCGv_i128 src)
1337daf457d4SRichard Henderson {
1338daf457d4SRichard Henderson     TCGv_i64 l = tcg_temp_new_i64();
1339daf457d4SRichard Henderson     TCGv_i64 h = tcg_temp_new_i64();
1340daf457d4SRichard Henderson 
1341daf457d4SRichard Henderson     tcg_gen_extr_i128_i64(l, h, src);
1342daf457d4SRichard Henderson     tcg_gen_andi_i64(h, h, ~(1ull << 63));
1343daf457d4SRichard Henderson     tcg_gen_concat_i64_i128(dst, l, h);
1344c6d83e4fSRichard Henderson }
1345c6d83e4fSRichard Henderson 
13464fd71d19SRichard Henderson static void gen_op_fmadds(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2, TCGv_i32 s3)
13474fd71d19SRichard Henderson {
13484fd71d19SRichard Henderson     gen_helper_fmadds(d, tcg_env, s1, s2, s3, tcg_constant_i32(0));
13494fd71d19SRichard Henderson }
13504fd71d19SRichard Henderson 
13514fd71d19SRichard Henderson static void gen_op_fmaddd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2, TCGv_i64 s3)
13524fd71d19SRichard Henderson {
13534fd71d19SRichard Henderson     gen_helper_fmaddd(d, tcg_env, s1, s2, s3, tcg_constant_i32(0));
13544fd71d19SRichard Henderson }
13554fd71d19SRichard Henderson 
13564fd71d19SRichard Henderson static void gen_op_fmsubs(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2, TCGv_i32 s3)
13574fd71d19SRichard Henderson {
13584fd71d19SRichard Henderson     int op = float_muladd_negate_c;
13594fd71d19SRichard Henderson     gen_helper_fmadds(d, tcg_env, s1, s2, s3, tcg_constant_i32(op));
13604fd71d19SRichard Henderson }
13614fd71d19SRichard Henderson 
13624fd71d19SRichard Henderson static void gen_op_fmsubd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2, TCGv_i64 s3)
13634fd71d19SRichard Henderson {
13644fd71d19SRichard Henderson     int op = float_muladd_negate_c;
13654fd71d19SRichard Henderson     gen_helper_fmaddd(d, tcg_env, s1, s2, s3, tcg_constant_i32(op));
13664fd71d19SRichard Henderson }
13674fd71d19SRichard Henderson 
13684fd71d19SRichard Henderson static void gen_op_fnmsubs(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2, TCGv_i32 s3)
13694fd71d19SRichard Henderson {
13704fd71d19SRichard Henderson     int op = float_muladd_negate_c | float_muladd_negate_result;
13714fd71d19SRichard Henderson     gen_helper_fmadds(d, tcg_env, s1, s2, s3, tcg_constant_i32(op));
13724fd71d19SRichard Henderson }
13734fd71d19SRichard Henderson 
13744fd71d19SRichard Henderson static void gen_op_fnmsubd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2, TCGv_i64 s3)
13754fd71d19SRichard Henderson {
13764fd71d19SRichard Henderson     int op = float_muladd_negate_c | float_muladd_negate_result;
13774fd71d19SRichard Henderson     gen_helper_fmaddd(d, tcg_env, s1, s2, s3, tcg_constant_i32(op));
13784fd71d19SRichard Henderson }
13794fd71d19SRichard Henderson 
13804fd71d19SRichard Henderson static void gen_op_fnmadds(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2, TCGv_i32 s3)
13814fd71d19SRichard Henderson {
13824fd71d19SRichard Henderson     int op = float_muladd_negate_result;
13834fd71d19SRichard Henderson     gen_helper_fmadds(d, tcg_env, s1, s2, s3, tcg_constant_i32(op));
13844fd71d19SRichard Henderson }
13854fd71d19SRichard Henderson 
13864fd71d19SRichard Henderson static void gen_op_fnmaddd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2, TCGv_i64 s3)
13874fd71d19SRichard Henderson {
13884fd71d19SRichard Henderson     int op = float_muladd_negate_result;
13894fd71d19SRichard Henderson     gen_helper_fmaddd(d, tcg_env, s1, s2, s3, tcg_constant_i32(op));
13904fd71d19SRichard Henderson }
13914fd71d19SRichard Henderson 
13923d50b728SRichard Henderson /* Use muladd to compute (1 * src1) + src2 / 2 with one rounding. */
13933d50b728SRichard Henderson static void gen_op_fhadds(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2)
13943d50b728SRichard Henderson {
13953d50b728SRichard Henderson     TCGv_i32 one = tcg_constant_i32(float32_one);
13963d50b728SRichard Henderson     int op = float_muladd_halve_result;
13973d50b728SRichard Henderson     gen_helper_fmadds(d, tcg_env, one, s1, s2, tcg_constant_i32(op));
13983d50b728SRichard Henderson }
13993d50b728SRichard Henderson 
14003d50b728SRichard Henderson static void gen_op_fhaddd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2)
14013d50b728SRichard Henderson {
14023d50b728SRichard Henderson     TCGv_i64 one = tcg_constant_i64(float64_one);
14033d50b728SRichard Henderson     int op = float_muladd_halve_result;
14043d50b728SRichard Henderson     gen_helper_fmaddd(d, tcg_env, one, s1, s2, tcg_constant_i32(op));
14053d50b728SRichard Henderson }
14063d50b728SRichard Henderson 
14073d50b728SRichard Henderson /* Use muladd to compute (1 * src1) - src2 / 2 with one rounding. */
14083d50b728SRichard Henderson static void gen_op_fhsubs(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2)
14093d50b728SRichard Henderson {
14103d50b728SRichard Henderson     TCGv_i32 one = tcg_constant_i32(float32_one);
14113d50b728SRichard Henderson     int op = float_muladd_negate_c | float_muladd_halve_result;
14123d50b728SRichard Henderson     gen_helper_fmadds(d, tcg_env, one, s1, s2, tcg_constant_i32(op));
14133d50b728SRichard Henderson }
14143d50b728SRichard Henderson 
14153d50b728SRichard Henderson static void gen_op_fhsubd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2)
14163d50b728SRichard Henderson {
14173d50b728SRichard Henderson     TCGv_i64 one = tcg_constant_i64(float64_one);
14183d50b728SRichard Henderson     int op = float_muladd_negate_c | float_muladd_halve_result;
14193d50b728SRichard Henderson     gen_helper_fmaddd(d, tcg_env, one, s1, s2, tcg_constant_i32(op));
14203d50b728SRichard Henderson }
14213d50b728SRichard Henderson 
14223d50b728SRichard Henderson /* Use muladd to compute -((1 * src1) + src2 / 2) with one rounding. */
14233d50b728SRichard Henderson static void gen_op_fnhadds(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2)
14243d50b728SRichard Henderson {
14253d50b728SRichard Henderson     TCGv_i32 one = tcg_constant_i32(float32_one);
14263d50b728SRichard Henderson     int op = float_muladd_negate_result | float_muladd_halve_result;
14273d50b728SRichard Henderson     gen_helper_fmadds(d, tcg_env, one, s1, s2, tcg_constant_i32(op));
14283d50b728SRichard Henderson }
14293d50b728SRichard Henderson 
14303d50b728SRichard Henderson static void gen_op_fnhaddd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2)
14313d50b728SRichard Henderson {
14323d50b728SRichard Henderson     TCGv_i64 one = tcg_constant_i64(float64_one);
14333d50b728SRichard Henderson     int op = float_muladd_negate_result | float_muladd_halve_result;
14343d50b728SRichard Henderson     gen_helper_fmaddd(d, tcg_env, one, s1, s2, tcg_constant_i32(op));
14353d50b728SRichard Henderson }
14363d50b728SRichard Henderson 
14373590f01eSRichard Henderson static void gen_op_fpexception_im(DisasContext *dc, int ftt)
1438fcf5ef2aSThomas Huth {
14393590f01eSRichard Henderson     /*
14403590f01eSRichard Henderson      * CEXC is only set when succesfully completing an FPop,
14413590f01eSRichard Henderson      * or when raising FSR_FTT_IEEE_EXCP, i.e. check_ieee_exception.
14423590f01eSRichard Henderson      * Thus we can simply store FTT into this field.
14433590f01eSRichard Henderson      */
14443590f01eSRichard Henderson     tcg_gen_st_i32(tcg_constant_i32(ftt), tcg_env,
14453590f01eSRichard Henderson                    offsetof(CPUSPARCState, fsr_cexc_ftt));
1446fcf5ef2aSThomas Huth     gen_exception(dc, TT_FP_EXCP);
1447fcf5ef2aSThomas Huth }
1448fcf5ef2aSThomas Huth 
1449fcf5ef2aSThomas Huth static int gen_trap_ifnofpu(DisasContext *dc)
1450fcf5ef2aSThomas Huth {
1451fcf5ef2aSThomas Huth #if !defined(CONFIG_USER_ONLY)
1452fcf5ef2aSThomas Huth     if (!dc->fpu_enabled) {
1453fcf5ef2aSThomas Huth         gen_exception(dc, TT_NFPU_INSN);
1454fcf5ef2aSThomas Huth         return 1;
1455fcf5ef2aSThomas Huth     }
1456fcf5ef2aSThomas Huth #endif
1457fcf5ef2aSThomas Huth     return 0;
1458fcf5ef2aSThomas Huth }
1459fcf5ef2aSThomas Huth 
1460fcf5ef2aSThomas Huth /* asi moves */
1461fcf5ef2aSThomas Huth typedef enum {
1462fcf5ef2aSThomas Huth     GET_ASI_HELPER,
1463fcf5ef2aSThomas Huth     GET_ASI_EXCP,
1464fcf5ef2aSThomas Huth     GET_ASI_DIRECT,
1465fcf5ef2aSThomas Huth     GET_ASI_DTWINX,
14662786a3f8SRichard Henderson     GET_ASI_CODE,
1467fcf5ef2aSThomas Huth     GET_ASI_BLOCK,
1468fcf5ef2aSThomas Huth     GET_ASI_SHORT,
1469fcf5ef2aSThomas Huth     GET_ASI_BCOPY,
1470fcf5ef2aSThomas Huth     GET_ASI_BFILL,
1471fcf5ef2aSThomas Huth } ASIType;
1472fcf5ef2aSThomas Huth 
1473fcf5ef2aSThomas Huth typedef struct {
1474fcf5ef2aSThomas Huth     ASIType type;
1475fcf5ef2aSThomas Huth     int asi;
1476fcf5ef2aSThomas Huth     int mem_idx;
147714776ab5STony Nguyen     MemOp memop;
1478fcf5ef2aSThomas Huth } DisasASI;
1479fcf5ef2aSThomas Huth 
1480811cc0b0SRichard Henderson /*
1481811cc0b0SRichard Henderson  * Build DisasASI.
1482811cc0b0SRichard Henderson  * For asi == -1, treat as non-asi.
1483811cc0b0SRichard Henderson  * For ask == -2, treat as immediate offset (v8 error, v9 %asi).
1484811cc0b0SRichard Henderson  */
1485811cc0b0SRichard Henderson static DisasASI resolve_asi(DisasContext *dc, int asi, MemOp memop)
1486fcf5ef2aSThomas Huth {
1487fcf5ef2aSThomas Huth     ASIType type = GET_ASI_HELPER;
1488fcf5ef2aSThomas Huth     int mem_idx = dc->mem_idx;
1489fcf5ef2aSThomas Huth 
1490811cc0b0SRichard Henderson     if (asi == -1) {
1491811cc0b0SRichard Henderson         /* Artificial "non-asi" case. */
1492811cc0b0SRichard Henderson         type = GET_ASI_DIRECT;
1493811cc0b0SRichard Henderson         goto done;
1494811cc0b0SRichard Henderson     }
1495811cc0b0SRichard Henderson 
1496fcf5ef2aSThomas Huth #ifndef TARGET_SPARC64
1497fcf5ef2aSThomas Huth     /* Before v9, all asis are immediate and privileged.  */
1498811cc0b0SRichard Henderson     if (asi < 0) {
1499fcf5ef2aSThomas Huth         gen_exception(dc, TT_ILL_INSN);
1500fcf5ef2aSThomas Huth         type = GET_ASI_EXCP;
1501fcf5ef2aSThomas Huth     } else if (supervisor(dc)
1502fcf5ef2aSThomas Huth                /* Note that LEON accepts ASI_USERDATA in user mode, for
1503fcf5ef2aSThomas Huth                   use with CASA.  Also note that previous versions of
1504fcf5ef2aSThomas Huth                   QEMU allowed (and old versions of gcc emitted) ASI_P
1505fcf5ef2aSThomas Huth                   for LEON, which is incorrect.  */
1506fcf5ef2aSThomas Huth                || (asi == ASI_USERDATA
1507fcf5ef2aSThomas Huth                    && (dc->def->features & CPU_FEATURE_CASA))) {
1508fcf5ef2aSThomas Huth         switch (asi) {
1509fcf5ef2aSThomas Huth         case ASI_USERDATA:    /* User data access */
1510fcf5ef2aSThomas Huth             mem_idx = MMU_USER_IDX;
1511fcf5ef2aSThomas Huth             type = GET_ASI_DIRECT;
1512fcf5ef2aSThomas Huth             break;
1513fcf5ef2aSThomas Huth         case ASI_KERNELDATA:  /* Supervisor data access */
1514fcf5ef2aSThomas Huth             mem_idx = MMU_KERNEL_IDX;
1515fcf5ef2aSThomas Huth             type = GET_ASI_DIRECT;
1516fcf5ef2aSThomas Huth             break;
15172786a3f8SRichard Henderson         case ASI_USERTXT:     /* User text access */
15182786a3f8SRichard Henderson             mem_idx = MMU_USER_IDX;
15192786a3f8SRichard Henderson             type = GET_ASI_CODE;
15202786a3f8SRichard Henderson             break;
15212786a3f8SRichard Henderson         case ASI_KERNELTXT:   /* Supervisor text access */
15222786a3f8SRichard Henderson             mem_idx = MMU_KERNEL_IDX;
15232786a3f8SRichard Henderson             type = GET_ASI_CODE;
15242786a3f8SRichard Henderson             break;
1525fcf5ef2aSThomas Huth         case ASI_M_BYPASS:    /* MMU passthrough */
1526fcf5ef2aSThomas Huth         case ASI_LEON_BYPASS: /* LEON MMU passthrough */
1527fcf5ef2aSThomas Huth             mem_idx = MMU_PHYS_IDX;
1528fcf5ef2aSThomas Huth             type = GET_ASI_DIRECT;
1529fcf5ef2aSThomas Huth             break;
1530fcf5ef2aSThomas Huth         case ASI_M_BCOPY: /* Block copy, sta access */
1531fcf5ef2aSThomas Huth             mem_idx = MMU_KERNEL_IDX;
1532fcf5ef2aSThomas Huth             type = GET_ASI_BCOPY;
1533fcf5ef2aSThomas Huth             break;
1534fcf5ef2aSThomas Huth         case ASI_M_BFILL: /* Block fill, stda access */
1535fcf5ef2aSThomas Huth             mem_idx = MMU_KERNEL_IDX;
1536fcf5ef2aSThomas Huth             type = GET_ASI_BFILL;
1537fcf5ef2aSThomas Huth             break;
1538fcf5ef2aSThomas Huth         }
15396e10f37cSKONRAD Frederic 
15406e10f37cSKONRAD Frederic         /* MMU_PHYS_IDX is used when the MMU is disabled to passthrough the
15416e10f37cSKONRAD Frederic          * permissions check in get_physical_address(..).
15426e10f37cSKONRAD Frederic          */
15436e10f37cSKONRAD Frederic         mem_idx = (dc->mem_idx == MMU_PHYS_IDX) ? MMU_PHYS_IDX : mem_idx;
1544fcf5ef2aSThomas Huth     } else {
1545fcf5ef2aSThomas Huth         gen_exception(dc, TT_PRIV_INSN);
1546fcf5ef2aSThomas Huth         type = GET_ASI_EXCP;
1547fcf5ef2aSThomas Huth     }
1548fcf5ef2aSThomas Huth #else
1549811cc0b0SRichard Henderson     if (asi < 0) {
1550fcf5ef2aSThomas Huth         asi = dc->asi;
1551fcf5ef2aSThomas Huth     }
1552fcf5ef2aSThomas Huth     /* With v9, all asis below 0x80 are privileged.  */
1553fcf5ef2aSThomas Huth     /* ??? We ought to check cpu_has_hypervisor, but we didn't copy
1554fcf5ef2aSThomas Huth        down that bit into DisasContext.  For the moment that's ok,
1555fcf5ef2aSThomas Huth        since the direct implementations below doesn't have any ASIs
1556fcf5ef2aSThomas Huth        in the restricted [0x30, 0x7f] range, and the check will be
1557fcf5ef2aSThomas Huth        done properly in the helper.  */
1558fcf5ef2aSThomas Huth     if (!supervisor(dc) && asi < 0x80) {
1559fcf5ef2aSThomas Huth         gen_exception(dc, TT_PRIV_ACT);
1560fcf5ef2aSThomas Huth         type = GET_ASI_EXCP;
1561fcf5ef2aSThomas Huth     } else {
1562fcf5ef2aSThomas Huth         switch (asi) {
1563fcf5ef2aSThomas Huth         case ASI_REAL:      /* Bypass */
1564fcf5ef2aSThomas Huth         case ASI_REAL_IO:   /* Bypass, non-cacheable */
1565fcf5ef2aSThomas Huth         case ASI_REAL_L:    /* Bypass LE */
1566fcf5ef2aSThomas Huth         case ASI_REAL_IO_L: /* Bypass, non-cacheable LE */
1567fcf5ef2aSThomas Huth         case ASI_TWINX_REAL:   /* Real address, twinx */
1568fcf5ef2aSThomas Huth         case ASI_TWINX_REAL_L: /* Real address, twinx, LE */
1569fcf5ef2aSThomas Huth         case ASI_QUAD_LDD_PHYS:
1570fcf5ef2aSThomas Huth         case ASI_QUAD_LDD_PHYS_L:
1571fcf5ef2aSThomas Huth             mem_idx = MMU_PHYS_IDX;
1572fcf5ef2aSThomas Huth             break;
1573fcf5ef2aSThomas Huth         case ASI_N:  /* Nucleus */
1574fcf5ef2aSThomas Huth         case ASI_NL: /* Nucleus LE */
1575fcf5ef2aSThomas Huth         case ASI_TWINX_N:
1576fcf5ef2aSThomas Huth         case ASI_TWINX_NL:
1577fcf5ef2aSThomas Huth         case ASI_NUCLEUS_QUAD_LDD:
1578fcf5ef2aSThomas Huth         case ASI_NUCLEUS_QUAD_LDD_L:
15799a10756dSArtyom Tarasenko             if (hypervisor(dc)) {
158084f8f587SArtyom Tarasenko                 mem_idx = MMU_PHYS_IDX;
15819a10756dSArtyom Tarasenko             } else {
1582fcf5ef2aSThomas Huth                 mem_idx = MMU_NUCLEUS_IDX;
15839a10756dSArtyom Tarasenko             }
1584fcf5ef2aSThomas Huth             break;
1585fcf5ef2aSThomas Huth         case ASI_AIUP:  /* As if user primary */
1586fcf5ef2aSThomas Huth         case ASI_AIUPL: /* As if user primary LE */
1587fcf5ef2aSThomas Huth         case ASI_TWINX_AIUP:
1588fcf5ef2aSThomas Huth         case ASI_TWINX_AIUP_L:
1589fcf5ef2aSThomas Huth         case ASI_BLK_AIUP_4V:
1590fcf5ef2aSThomas Huth         case ASI_BLK_AIUP_L_4V:
1591fcf5ef2aSThomas Huth         case ASI_BLK_AIUP:
1592fcf5ef2aSThomas Huth         case ASI_BLK_AIUPL:
1593fcf5ef2aSThomas Huth             mem_idx = MMU_USER_IDX;
1594fcf5ef2aSThomas Huth             break;
1595fcf5ef2aSThomas Huth         case ASI_AIUS:  /* As if user secondary */
1596fcf5ef2aSThomas Huth         case ASI_AIUSL: /* As if user secondary LE */
1597fcf5ef2aSThomas Huth         case ASI_TWINX_AIUS:
1598fcf5ef2aSThomas Huth         case ASI_TWINX_AIUS_L:
1599fcf5ef2aSThomas Huth         case ASI_BLK_AIUS_4V:
1600fcf5ef2aSThomas Huth         case ASI_BLK_AIUS_L_4V:
1601fcf5ef2aSThomas Huth         case ASI_BLK_AIUS:
1602fcf5ef2aSThomas Huth         case ASI_BLK_AIUSL:
1603fcf5ef2aSThomas Huth             mem_idx = MMU_USER_SECONDARY_IDX;
1604fcf5ef2aSThomas Huth             break;
1605fcf5ef2aSThomas Huth         case ASI_S:  /* Secondary */
1606fcf5ef2aSThomas Huth         case ASI_SL: /* Secondary LE */
1607fcf5ef2aSThomas Huth         case ASI_TWINX_S:
1608fcf5ef2aSThomas Huth         case ASI_TWINX_SL:
1609fcf5ef2aSThomas Huth         case ASI_BLK_COMMIT_S:
1610fcf5ef2aSThomas Huth         case ASI_BLK_S:
1611fcf5ef2aSThomas Huth         case ASI_BLK_SL:
1612fcf5ef2aSThomas Huth         case ASI_FL8_S:
1613fcf5ef2aSThomas Huth         case ASI_FL8_SL:
1614fcf5ef2aSThomas Huth         case ASI_FL16_S:
1615fcf5ef2aSThomas Huth         case ASI_FL16_SL:
1616fcf5ef2aSThomas Huth             if (mem_idx == MMU_USER_IDX) {
1617fcf5ef2aSThomas Huth                 mem_idx = MMU_USER_SECONDARY_IDX;
1618fcf5ef2aSThomas Huth             } else if (mem_idx == MMU_KERNEL_IDX) {
1619fcf5ef2aSThomas Huth                 mem_idx = MMU_KERNEL_SECONDARY_IDX;
1620fcf5ef2aSThomas Huth             }
1621fcf5ef2aSThomas Huth             break;
1622fcf5ef2aSThomas Huth         case ASI_P:  /* Primary */
1623fcf5ef2aSThomas Huth         case ASI_PL: /* Primary LE */
1624fcf5ef2aSThomas Huth         case ASI_TWINX_P:
1625fcf5ef2aSThomas Huth         case ASI_TWINX_PL:
1626fcf5ef2aSThomas Huth         case ASI_BLK_COMMIT_P:
1627fcf5ef2aSThomas Huth         case ASI_BLK_P:
1628fcf5ef2aSThomas Huth         case ASI_BLK_PL:
1629fcf5ef2aSThomas Huth         case ASI_FL8_P:
1630fcf5ef2aSThomas Huth         case ASI_FL8_PL:
1631fcf5ef2aSThomas Huth         case ASI_FL16_P:
1632fcf5ef2aSThomas Huth         case ASI_FL16_PL:
1633fcf5ef2aSThomas Huth             break;
1634fcf5ef2aSThomas Huth         }
1635fcf5ef2aSThomas Huth         switch (asi) {
1636fcf5ef2aSThomas Huth         case ASI_REAL:
1637fcf5ef2aSThomas Huth         case ASI_REAL_IO:
1638fcf5ef2aSThomas Huth         case ASI_REAL_L:
1639fcf5ef2aSThomas Huth         case ASI_REAL_IO_L:
1640fcf5ef2aSThomas Huth         case ASI_N:
1641fcf5ef2aSThomas Huth         case ASI_NL:
1642fcf5ef2aSThomas Huth         case ASI_AIUP:
1643fcf5ef2aSThomas Huth         case ASI_AIUPL:
1644fcf5ef2aSThomas Huth         case ASI_AIUS:
1645fcf5ef2aSThomas Huth         case ASI_AIUSL:
1646fcf5ef2aSThomas Huth         case ASI_S:
1647fcf5ef2aSThomas Huth         case ASI_SL:
1648fcf5ef2aSThomas Huth         case ASI_P:
1649fcf5ef2aSThomas Huth         case ASI_PL:
1650fcf5ef2aSThomas Huth             type = GET_ASI_DIRECT;
1651fcf5ef2aSThomas Huth             break;
1652fcf5ef2aSThomas Huth         case ASI_TWINX_REAL:
1653fcf5ef2aSThomas Huth         case ASI_TWINX_REAL_L:
1654fcf5ef2aSThomas Huth         case ASI_TWINX_N:
1655fcf5ef2aSThomas Huth         case ASI_TWINX_NL:
1656fcf5ef2aSThomas Huth         case ASI_TWINX_AIUP:
1657fcf5ef2aSThomas Huth         case ASI_TWINX_AIUP_L:
1658fcf5ef2aSThomas Huth         case ASI_TWINX_AIUS:
1659fcf5ef2aSThomas Huth         case ASI_TWINX_AIUS_L:
1660fcf5ef2aSThomas Huth         case ASI_TWINX_P:
1661fcf5ef2aSThomas Huth         case ASI_TWINX_PL:
1662fcf5ef2aSThomas Huth         case ASI_TWINX_S:
1663fcf5ef2aSThomas Huth         case ASI_TWINX_SL:
1664fcf5ef2aSThomas Huth         case ASI_QUAD_LDD_PHYS:
1665fcf5ef2aSThomas Huth         case ASI_QUAD_LDD_PHYS_L:
1666fcf5ef2aSThomas Huth         case ASI_NUCLEUS_QUAD_LDD:
1667fcf5ef2aSThomas Huth         case ASI_NUCLEUS_QUAD_LDD_L:
1668fcf5ef2aSThomas Huth             type = GET_ASI_DTWINX;
1669fcf5ef2aSThomas Huth             break;
1670fcf5ef2aSThomas Huth         case ASI_BLK_COMMIT_P:
1671fcf5ef2aSThomas Huth         case ASI_BLK_COMMIT_S:
1672fcf5ef2aSThomas Huth         case ASI_BLK_AIUP_4V:
1673fcf5ef2aSThomas Huth         case ASI_BLK_AIUP_L_4V:
1674fcf5ef2aSThomas Huth         case ASI_BLK_AIUP:
1675fcf5ef2aSThomas Huth         case ASI_BLK_AIUPL:
1676fcf5ef2aSThomas Huth         case ASI_BLK_AIUS_4V:
1677fcf5ef2aSThomas Huth         case ASI_BLK_AIUS_L_4V:
1678fcf5ef2aSThomas Huth         case ASI_BLK_AIUS:
1679fcf5ef2aSThomas Huth         case ASI_BLK_AIUSL:
1680fcf5ef2aSThomas Huth         case ASI_BLK_S:
1681fcf5ef2aSThomas Huth         case ASI_BLK_SL:
1682fcf5ef2aSThomas Huth         case ASI_BLK_P:
1683fcf5ef2aSThomas Huth         case ASI_BLK_PL:
1684fcf5ef2aSThomas Huth             type = GET_ASI_BLOCK;
1685fcf5ef2aSThomas Huth             break;
1686fcf5ef2aSThomas Huth         case ASI_FL8_S:
1687fcf5ef2aSThomas Huth         case ASI_FL8_SL:
1688fcf5ef2aSThomas Huth         case ASI_FL8_P:
1689fcf5ef2aSThomas Huth         case ASI_FL8_PL:
1690fcf5ef2aSThomas Huth             memop = MO_UB;
1691fcf5ef2aSThomas Huth             type = GET_ASI_SHORT;
1692fcf5ef2aSThomas Huth             break;
1693fcf5ef2aSThomas Huth         case ASI_FL16_S:
1694fcf5ef2aSThomas Huth         case ASI_FL16_SL:
1695fcf5ef2aSThomas Huth         case ASI_FL16_P:
1696fcf5ef2aSThomas Huth         case ASI_FL16_PL:
1697fcf5ef2aSThomas Huth             memop = MO_TEUW;
1698fcf5ef2aSThomas Huth             type = GET_ASI_SHORT;
1699fcf5ef2aSThomas Huth             break;
1700fcf5ef2aSThomas Huth         }
1701fcf5ef2aSThomas Huth         /* The little-endian asis all have bit 3 set.  */
1702fcf5ef2aSThomas Huth         if (asi & 8) {
1703fcf5ef2aSThomas Huth             memop ^= MO_BSWAP;
1704fcf5ef2aSThomas Huth         }
1705fcf5ef2aSThomas Huth     }
1706fcf5ef2aSThomas Huth #endif
1707fcf5ef2aSThomas Huth 
1708811cc0b0SRichard Henderson  done:
1709fcf5ef2aSThomas Huth     return (DisasASI){ type, asi, mem_idx, memop };
1710fcf5ef2aSThomas Huth }
1711fcf5ef2aSThomas Huth 
1712a76779eeSRichard Henderson #if defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
1713a76779eeSRichard Henderson static void gen_helper_ld_asi(TCGv_i64 r, TCGv_env e, TCGv a,
1714a76779eeSRichard Henderson                               TCGv_i32 asi, TCGv_i32 mop)
1715a76779eeSRichard Henderson {
1716a76779eeSRichard Henderson     g_assert_not_reached();
1717a76779eeSRichard Henderson }
1718a76779eeSRichard Henderson 
1719a76779eeSRichard Henderson static void gen_helper_st_asi(TCGv_env e, TCGv a, TCGv_i64 r,
1720a76779eeSRichard Henderson                               TCGv_i32 asi, TCGv_i32 mop)
1721a76779eeSRichard Henderson {
1722a76779eeSRichard Henderson     g_assert_not_reached();
1723a76779eeSRichard Henderson }
1724a76779eeSRichard Henderson #endif
1725a76779eeSRichard Henderson 
172642071fc1SRichard Henderson static void gen_ld_asi(DisasContext *dc, DisasASI *da, TCGv dst, TCGv addr)
1727fcf5ef2aSThomas Huth {
1728c03a0fd1SRichard Henderson     switch (da->type) {
1729fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
1730fcf5ef2aSThomas Huth         break;
1731fcf5ef2aSThomas Huth     case GET_ASI_DTWINX: /* Reserved for ldda.  */
1732fcf5ef2aSThomas Huth         gen_exception(dc, TT_ILL_INSN);
1733fcf5ef2aSThomas Huth         break;
1734fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
1735c03a0fd1SRichard Henderson         tcg_gen_qemu_ld_tl(dst, addr, da->mem_idx, da->memop | MO_ALIGN);
1736fcf5ef2aSThomas Huth         break;
17372786a3f8SRichard Henderson 
17382786a3f8SRichard Henderson     case GET_ASI_CODE:
17392786a3f8SRichard Henderson #if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
17402786a3f8SRichard Henderson         {
17412786a3f8SRichard Henderson             MemOpIdx oi = make_memop_idx(da->memop, da->mem_idx);
17422786a3f8SRichard Henderson             TCGv_i64 t64 = tcg_temp_new_i64();
17432786a3f8SRichard Henderson 
17442786a3f8SRichard Henderson             gen_helper_ld_code(t64, tcg_env, addr, tcg_constant_i32(oi));
17452786a3f8SRichard Henderson             tcg_gen_trunc_i64_tl(dst, t64);
17462786a3f8SRichard Henderson         }
17472786a3f8SRichard Henderson         break;
17482786a3f8SRichard Henderson #else
17492786a3f8SRichard Henderson         g_assert_not_reached();
17502786a3f8SRichard Henderson #endif
17512786a3f8SRichard Henderson 
1752fcf5ef2aSThomas Huth     default:
1753fcf5ef2aSThomas Huth         {
1754c03a0fd1SRichard Henderson             TCGv_i32 r_asi = tcg_constant_i32(da->asi);
1755c03a0fd1SRichard Henderson             TCGv_i32 r_mop = tcg_constant_i32(da->memop | MO_ALIGN);
1756fcf5ef2aSThomas Huth 
1757fcf5ef2aSThomas Huth             save_state(dc);
1758fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
1759ad75a51eSRichard Henderson             gen_helper_ld_asi(dst, tcg_env, addr, r_asi, r_mop);
1760fcf5ef2aSThomas Huth #else
1761fcf5ef2aSThomas Huth             {
1762fcf5ef2aSThomas Huth                 TCGv_i64 t64 = tcg_temp_new_i64();
1763ad75a51eSRichard Henderson                 gen_helper_ld_asi(t64, tcg_env, addr, r_asi, r_mop);
1764fcf5ef2aSThomas Huth                 tcg_gen_trunc_i64_tl(dst, t64);
1765fcf5ef2aSThomas Huth             }
1766fcf5ef2aSThomas Huth #endif
1767fcf5ef2aSThomas Huth         }
1768fcf5ef2aSThomas Huth         break;
1769fcf5ef2aSThomas Huth     }
1770fcf5ef2aSThomas Huth }
1771fcf5ef2aSThomas Huth 
177242071fc1SRichard Henderson static void gen_st_asi(DisasContext *dc, DisasASI *da, TCGv src, TCGv addr)
1773c03a0fd1SRichard Henderson {
1774c03a0fd1SRichard Henderson     switch (da->type) {
1775fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
1776fcf5ef2aSThomas Huth         break;
1777c03a0fd1SRichard Henderson 
1778fcf5ef2aSThomas Huth     case GET_ASI_DTWINX: /* Reserved for stda.  */
1779c03a0fd1SRichard Henderson         if (TARGET_LONG_BITS == 32) {
1780fcf5ef2aSThomas Huth             gen_exception(dc, TT_ILL_INSN);
1781fcf5ef2aSThomas Huth             break;
1782c03a0fd1SRichard Henderson         } else if (!(dc->def->features & CPU_FEATURE_HYPV)) {
17833390537bSArtyom Tarasenko             /* Pre OpenSPARC CPUs don't have these */
17843390537bSArtyom Tarasenko             gen_exception(dc, TT_ILL_INSN);
1785fcf5ef2aSThomas Huth             break;
1786c03a0fd1SRichard Henderson         }
1787c03a0fd1SRichard Henderson         /* In OpenSPARC T1+ CPUs TWINX ASIs in store are ST_BLKINIT_ ASIs */
1788c03a0fd1SRichard Henderson         /* fall through */
1789c03a0fd1SRichard Henderson 
1790c03a0fd1SRichard Henderson     case GET_ASI_DIRECT:
1791c03a0fd1SRichard Henderson         tcg_gen_qemu_st_tl(src, addr, da->mem_idx, da->memop | MO_ALIGN);
1792c03a0fd1SRichard Henderson         break;
1793c03a0fd1SRichard Henderson 
1794fcf5ef2aSThomas Huth     case GET_ASI_BCOPY:
1795c03a0fd1SRichard Henderson         assert(TARGET_LONG_BITS == 32);
179698271007SRichard Henderson         /*
179798271007SRichard Henderson          * Copy 32 bytes from the address in SRC to ADDR.
179898271007SRichard Henderson          *
179998271007SRichard Henderson          * From Ross RT625 hyperSPARC manual, section 4.6:
180098271007SRichard Henderson          * "Block Copy and Block Fill will work only on cache line boundaries."
180198271007SRichard Henderson          *
180298271007SRichard Henderson          * It does not specify if an unaliged address is truncated or trapped.
180398271007SRichard Henderson          * Previous qemu behaviour was to truncate to 4 byte alignment, which
180498271007SRichard Henderson          * is obviously wrong.  The only place I can see this used is in the
180598271007SRichard Henderson          * Linux kernel which begins with page alignment, advancing by 32,
180698271007SRichard Henderson          * so is always aligned.  Assume truncation as the simpler option.
180798271007SRichard Henderson          *
180898271007SRichard Henderson          * Since the loads and stores are paired, allow the copy to happen
180998271007SRichard Henderson          * in the host endianness.  The copy need not be atomic.
181098271007SRichard Henderson          */
1811fcf5ef2aSThomas Huth         {
181298271007SRichard Henderson             MemOp mop = MO_128 | MO_ATOM_IFALIGN_PAIR;
1813fcf5ef2aSThomas Huth             TCGv saddr = tcg_temp_new();
1814fcf5ef2aSThomas Huth             TCGv daddr = tcg_temp_new();
181598271007SRichard Henderson             TCGv_i128 tmp = tcg_temp_new_i128();
1816fcf5ef2aSThomas Huth 
181798271007SRichard Henderson             tcg_gen_andi_tl(saddr, src, -32);
181898271007SRichard Henderson             tcg_gen_andi_tl(daddr, addr, -32);
181998271007SRichard Henderson             tcg_gen_qemu_ld_i128(tmp, saddr, da->mem_idx, mop);
182098271007SRichard Henderson             tcg_gen_qemu_st_i128(tmp, daddr, da->mem_idx, mop);
182198271007SRichard Henderson             tcg_gen_addi_tl(saddr, saddr, 16);
182298271007SRichard Henderson             tcg_gen_addi_tl(daddr, daddr, 16);
182398271007SRichard Henderson             tcg_gen_qemu_ld_i128(tmp, saddr, da->mem_idx, mop);
182498271007SRichard Henderson             tcg_gen_qemu_st_i128(tmp, daddr, da->mem_idx, mop);
1825fcf5ef2aSThomas Huth         }
1826fcf5ef2aSThomas Huth         break;
1827c03a0fd1SRichard Henderson 
1828fcf5ef2aSThomas Huth     default:
1829fcf5ef2aSThomas Huth         {
1830c03a0fd1SRichard Henderson             TCGv_i32 r_asi = tcg_constant_i32(da->asi);
1831c03a0fd1SRichard Henderson             TCGv_i32 r_mop = tcg_constant_i32(da->memop | MO_ALIGN);
1832fcf5ef2aSThomas Huth 
1833fcf5ef2aSThomas Huth             save_state(dc);
1834fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
1835ad75a51eSRichard Henderson             gen_helper_st_asi(tcg_env, addr, src, r_asi, r_mop);
1836fcf5ef2aSThomas Huth #else
1837fcf5ef2aSThomas Huth             {
1838fcf5ef2aSThomas Huth                 TCGv_i64 t64 = tcg_temp_new_i64();
1839fcf5ef2aSThomas Huth                 tcg_gen_extu_tl_i64(t64, src);
1840ad75a51eSRichard Henderson                 gen_helper_st_asi(tcg_env, addr, t64, r_asi, r_mop);
1841fcf5ef2aSThomas Huth             }
1842fcf5ef2aSThomas Huth #endif
1843fcf5ef2aSThomas Huth 
1844fcf5ef2aSThomas Huth             /* A write to a TLB register may alter page maps.  End the TB. */
1845fcf5ef2aSThomas Huth             dc->npc = DYNAMIC_PC;
1846fcf5ef2aSThomas Huth         }
1847fcf5ef2aSThomas Huth         break;
1848fcf5ef2aSThomas Huth     }
1849fcf5ef2aSThomas Huth }
1850fcf5ef2aSThomas Huth 
1851dca544b9SRichard Henderson static void gen_swap_asi(DisasContext *dc, DisasASI *da,
1852c03a0fd1SRichard Henderson                          TCGv dst, TCGv src, TCGv addr)
1853c03a0fd1SRichard Henderson {
1854c03a0fd1SRichard Henderson     switch (da->type) {
1855c03a0fd1SRichard Henderson     case GET_ASI_EXCP:
1856c03a0fd1SRichard Henderson         break;
1857c03a0fd1SRichard Henderson     case GET_ASI_DIRECT:
1858dca544b9SRichard Henderson         tcg_gen_atomic_xchg_tl(dst, addr, src,
1859dca544b9SRichard Henderson                                da->mem_idx, da->memop | MO_ALIGN);
1860c03a0fd1SRichard Henderson         break;
1861c03a0fd1SRichard Henderson     default:
1862c03a0fd1SRichard Henderson         /* ??? Should be DAE_invalid_asi.  */
1863c03a0fd1SRichard Henderson         gen_exception(dc, TT_DATA_ACCESS);
1864c03a0fd1SRichard Henderson         break;
1865c03a0fd1SRichard Henderson     }
1866c03a0fd1SRichard Henderson }
1867c03a0fd1SRichard Henderson 
1868d0a11d25SRichard Henderson static void gen_cas_asi(DisasContext *dc, DisasASI *da,
1869c03a0fd1SRichard Henderson                         TCGv oldv, TCGv newv, TCGv cmpv, TCGv addr)
1870c03a0fd1SRichard Henderson {
1871c03a0fd1SRichard Henderson     switch (da->type) {
1872fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
1873c03a0fd1SRichard Henderson         return;
1874fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
1875c03a0fd1SRichard Henderson         tcg_gen_atomic_cmpxchg_tl(oldv, addr, cmpv, newv,
1876c03a0fd1SRichard Henderson                                   da->mem_idx, da->memop | MO_ALIGN);
1877fcf5ef2aSThomas Huth         break;
1878fcf5ef2aSThomas Huth     default:
1879fcf5ef2aSThomas Huth         /* ??? Should be DAE_invalid_asi.  */
1880fcf5ef2aSThomas Huth         gen_exception(dc, TT_DATA_ACCESS);
1881fcf5ef2aSThomas Huth         break;
1882fcf5ef2aSThomas Huth     }
1883fcf5ef2aSThomas Huth }
1884fcf5ef2aSThomas Huth 
1885cf07cd1eSRichard Henderson static void gen_ldstub_asi(DisasContext *dc, DisasASI *da, TCGv dst, TCGv addr)
1886c03a0fd1SRichard Henderson {
1887c03a0fd1SRichard Henderson     switch (da->type) {
1888fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
1889fcf5ef2aSThomas Huth         break;
1890fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
1891cf07cd1eSRichard Henderson         tcg_gen_atomic_xchg_tl(dst, addr, tcg_constant_tl(0xff),
1892cf07cd1eSRichard Henderson                                da->mem_idx, MO_UB);
1893fcf5ef2aSThomas Huth         break;
1894fcf5ef2aSThomas Huth     default:
18953db010c3SRichard Henderson         /* ??? In theory, this should be raise DAE_invalid_asi.
18963db010c3SRichard Henderson            But the SS-20 roms do ldstuba [%l0] #ASI_M_CTL, %o1.  */
1897af00be49SEmilio G. Cota         if (tb_cflags(dc->base.tb) & CF_PARALLEL) {
1898ad75a51eSRichard Henderson             gen_helper_exit_atomic(tcg_env);
18993db010c3SRichard Henderson         } else {
1900c03a0fd1SRichard Henderson             TCGv_i32 r_asi = tcg_constant_i32(da->asi);
190100ab7e61SRichard Henderson             TCGv_i32 r_mop = tcg_constant_i32(MO_UB);
19023db010c3SRichard Henderson             TCGv_i64 s64, t64;
19033db010c3SRichard Henderson 
19043db010c3SRichard Henderson             save_state(dc);
19053db010c3SRichard Henderson             t64 = tcg_temp_new_i64();
1906ad75a51eSRichard Henderson             gen_helper_ld_asi(t64, tcg_env, addr, r_asi, r_mop);
19073db010c3SRichard Henderson 
190800ab7e61SRichard Henderson             s64 = tcg_constant_i64(0xff);
1909ad75a51eSRichard Henderson             gen_helper_st_asi(tcg_env, addr, s64, r_asi, r_mop);
19103db010c3SRichard Henderson 
19113db010c3SRichard Henderson             tcg_gen_trunc_i64_tl(dst, t64);
19123db010c3SRichard Henderson 
19133db010c3SRichard Henderson             /* End the TB.  */
19143db010c3SRichard Henderson             dc->npc = DYNAMIC_PC;
19153db010c3SRichard Henderson         }
1916fcf5ef2aSThomas Huth         break;
1917fcf5ef2aSThomas Huth     }
1918fcf5ef2aSThomas Huth }
1919fcf5ef2aSThomas Huth 
1920287b1152SRichard Henderson static void gen_ldf_asi(DisasContext *dc, DisasASI *da, MemOp orig_size,
19213259b9e2SRichard Henderson                         TCGv addr, int rd)
1922fcf5ef2aSThomas Huth {
19233259b9e2SRichard Henderson     MemOp memop = da->memop;
19243259b9e2SRichard Henderson     MemOp size = memop & MO_SIZE;
1925fcf5ef2aSThomas Huth     TCGv_i32 d32;
19261210a036SRichard Henderson     TCGv_i64 d64, l64;
1927287b1152SRichard Henderson     TCGv addr_tmp;
1928fcf5ef2aSThomas Huth 
19293259b9e2SRichard Henderson     /* TODO: Use 128-bit load/store below. */
19303259b9e2SRichard Henderson     if (size == MO_128) {
19313259b9e2SRichard Henderson         memop = (memop & ~MO_SIZE) | MO_64;
19323259b9e2SRichard Henderson     }
19333259b9e2SRichard Henderson 
19343259b9e2SRichard Henderson     switch (da->type) {
1935fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
1936fcf5ef2aSThomas Huth         break;
1937fcf5ef2aSThomas Huth 
1938fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
19393259b9e2SRichard Henderson         memop |= MO_ALIGN_4;
1940fcf5ef2aSThomas Huth         switch (size) {
19413259b9e2SRichard Henderson         case MO_32:
1942388a6465SRichard Henderson             d32 = tcg_temp_new_i32();
19433259b9e2SRichard Henderson             tcg_gen_qemu_ld_i32(d32, addr, da->mem_idx, memop);
1944fcf5ef2aSThomas Huth             gen_store_fpr_F(dc, rd, d32);
1945fcf5ef2aSThomas Huth             break;
19463259b9e2SRichard Henderson 
19473259b9e2SRichard Henderson         case MO_64:
19481210a036SRichard Henderson             d64 = tcg_temp_new_i64();
19491210a036SRichard Henderson             tcg_gen_qemu_ld_i64(d64, addr, da->mem_idx, memop);
19501210a036SRichard Henderson             gen_store_fpr_D(dc, rd, d64);
1951fcf5ef2aSThomas Huth             break;
19523259b9e2SRichard Henderson 
19533259b9e2SRichard Henderson         case MO_128:
1954fcf5ef2aSThomas Huth             d64 = tcg_temp_new_i64();
19551210a036SRichard Henderson             l64 = tcg_temp_new_i64();
19563259b9e2SRichard Henderson             tcg_gen_qemu_ld_i64(d64, addr, da->mem_idx, memop);
1957287b1152SRichard Henderson             addr_tmp = tcg_temp_new();
1958287b1152SRichard Henderson             tcg_gen_addi_tl(addr_tmp, addr, 8);
19591210a036SRichard Henderson             tcg_gen_qemu_ld_i64(l64, addr_tmp, da->mem_idx, memop);
19601210a036SRichard Henderson             gen_store_fpr_D(dc, rd, d64);
19611210a036SRichard Henderson             gen_store_fpr_D(dc, rd + 2, l64);
1962fcf5ef2aSThomas Huth             break;
1963fcf5ef2aSThomas Huth         default:
1964fcf5ef2aSThomas Huth             g_assert_not_reached();
1965fcf5ef2aSThomas Huth         }
1966fcf5ef2aSThomas Huth         break;
1967fcf5ef2aSThomas Huth 
1968fcf5ef2aSThomas Huth     case GET_ASI_BLOCK:
1969fcf5ef2aSThomas Huth         /* Valid for lddfa on aligned registers only.  */
19703259b9e2SRichard Henderson         if (orig_size == MO_64 && (rd & 7) == 0) {
1971fcf5ef2aSThomas Huth             /* The first operation checks required alignment.  */
1972287b1152SRichard Henderson             addr_tmp = tcg_temp_new();
19731210a036SRichard Henderson             d64 = tcg_temp_new_i64();
1974287b1152SRichard Henderson             for (int i = 0; ; ++i) {
19751210a036SRichard Henderson                 tcg_gen_qemu_ld_i64(d64, addr, da->mem_idx,
19763259b9e2SRichard Henderson                                     memop | (i == 0 ? MO_ALIGN_64 : 0));
19771210a036SRichard Henderson                 gen_store_fpr_D(dc, rd + 2 * i, d64);
1978fcf5ef2aSThomas Huth                 if (i == 7) {
1979fcf5ef2aSThomas Huth                     break;
1980fcf5ef2aSThomas Huth                 }
1981287b1152SRichard Henderson                 tcg_gen_addi_tl(addr_tmp, addr, 8);
1982287b1152SRichard Henderson                 addr = addr_tmp;
1983fcf5ef2aSThomas Huth             }
1984fcf5ef2aSThomas Huth         } else {
1985fcf5ef2aSThomas Huth             gen_exception(dc, TT_ILL_INSN);
1986fcf5ef2aSThomas Huth         }
1987fcf5ef2aSThomas Huth         break;
1988fcf5ef2aSThomas Huth 
1989fcf5ef2aSThomas Huth     case GET_ASI_SHORT:
1990fcf5ef2aSThomas Huth         /* Valid for lddfa only.  */
19913259b9e2SRichard Henderson         if (orig_size == MO_64) {
19921210a036SRichard Henderson             d64 = tcg_temp_new_i64();
19931210a036SRichard Henderson             tcg_gen_qemu_ld_i64(d64, addr, da->mem_idx, memop | MO_ALIGN);
19941210a036SRichard Henderson             gen_store_fpr_D(dc, rd, d64);
1995fcf5ef2aSThomas Huth         } else {
1996fcf5ef2aSThomas Huth             gen_exception(dc, TT_ILL_INSN);
1997fcf5ef2aSThomas Huth         }
1998fcf5ef2aSThomas Huth         break;
1999fcf5ef2aSThomas Huth 
2000fcf5ef2aSThomas Huth     default:
2001fcf5ef2aSThomas Huth         {
20023259b9e2SRichard Henderson             TCGv_i32 r_asi = tcg_constant_i32(da->asi);
20033259b9e2SRichard Henderson             TCGv_i32 r_mop = tcg_constant_i32(memop | MO_ALIGN);
2004fcf5ef2aSThomas Huth 
2005fcf5ef2aSThomas Huth             save_state(dc);
2006fcf5ef2aSThomas Huth             /* According to the table in the UA2011 manual, the only
2007fcf5ef2aSThomas Huth                other asis that are valid for ldfa/lddfa/ldqfa are
2008fcf5ef2aSThomas Huth                the NO_FAULT asis.  We still need a helper for these,
2009fcf5ef2aSThomas Huth                but we can just use the integer asi helper for them.  */
2010fcf5ef2aSThomas Huth             switch (size) {
20113259b9e2SRichard Henderson             case MO_32:
2012fcf5ef2aSThomas Huth                 d64 = tcg_temp_new_i64();
2013ad75a51eSRichard Henderson                 gen_helper_ld_asi(d64, tcg_env, addr, r_asi, r_mop);
2014388a6465SRichard Henderson                 d32 = tcg_temp_new_i32();
2015fcf5ef2aSThomas Huth                 tcg_gen_extrl_i64_i32(d32, d64);
2016fcf5ef2aSThomas Huth                 gen_store_fpr_F(dc, rd, d32);
2017fcf5ef2aSThomas Huth                 break;
20183259b9e2SRichard Henderson             case MO_64:
20191210a036SRichard Henderson                 d64 = tcg_temp_new_i64();
20201210a036SRichard Henderson                 gen_helper_ld_asi(d64, tcg_env, addr, r_asi, r_mop);
20211210a036SRichard Henderson                 gen_store_fpr_D(dc, rd, d64);
2022fcf5ef2aSThomas Huth                 break;
20233259b9e2SRichard Henderson             case MO_128:
2024fcf5ef2aSThomas Huth                 d64 = tcg_temp_new_i64();
20251210a036SRichard Henderson                 l64 = tcg_temp_new_i64();
2026ad75a51eSRichard Henderson                 gen_helper_ld_asi(d64, tcg_env, addr, r_asi, r_mop);
2027287b1152SRichard Henderson                 addr_tmp = tcg_temp_new();
2028287b1152SRichard Henderson                 tcg_gen_addi_tl(addr_tmp, addr, 8);
20291210a036SRichard Henderson                 gen_helper_ld_asi(l64, tcg_env, addr_tmp, r_asi, r_mop);
20301210a036SRichard Henderson                 gen_store_fpr_D(dc, rd, d64);
20311210a036SRichard Henderson                 gen_store_fpr_D(dc, rd + 2, l64);
2032fcf5ef2aSThomas Huth                 break;
2033fcf5ef2aSThomas Huth             default:
2034fcf5ef2aSThomas Huth                 g_assert_not_reached();
2035fcf5ef2aSThomas Huth             }
2036fcf5ef2aSThomas Huth         }
2037fcf5ef2aSThomas Huth         break;
2038fcf5ef2aSThomas Huth     }
2039fcf5ef2aSThomas Huth }
2040fcf5ef2aSThomas Huth 
2041287b1152SRichard Henderson static void gen_stf_asi(DisasContext *dc, DisasASI *da, MemOp orig_size,
20423259b9e2SRichard Henderson                         TCGv addr, int rd)
20433259b9e2SRichard Henderson {
20443259b9e2SRichard Henderson     MemOp memop = da->memop;
20453259b9e2SRichard Henderson     MemOp size = memop & MO_SIZE;
2046fcf5ef2aSThomas Huth     TCGv_i32 d32;
20471210a036SRichard Henderson     TCGv_i64 d64;
2048287b1152SRichard Henderson     TCGv addr_tmp;
2049fcf5ef2aSThomas Huth 
20503259b9e2SRichard Henderson     /* TODO: Use 128-bit load/store below. */
20513259b9e2SRichard Henderson     if (size == MO_128) {
20523259b9e2SRichard Henderson         memop = (memop & ~MO_SIZE) | MO_64;
20533259b9e2SRichard Henderson     }
20543259b9e2SRichard Henderson 
20553259b9e2SRichard Henderson     switch (da->type) {
2056fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
2057fcf5ef2aSThomas Huth         break;
2058fcf5ef2aSThomas Huth 
2059fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
20603259b9e2SRichard Henderson         memop |= MO_ALIGN_4;
2061fcf5ef2aSThomas Huth         switch (size) {
20623259b9e2SRichard Henderson         case MO_32:
2063fcf5ef2aSThomas Huth             d32 = gen_load_fpr_F(dc, rd);
20643259b9e2SRichard Henderson             tcg_gen_qemu_st_i32(d32, addr, da->mem_idx, memop | MO_ALIGN);
2065fcf5ef2aSThomas Huth             break;
20663259b9e2SRichard Henderson         case MO_64:
20671210a036SRichard Henderson             d64 = gen_load_fpr_D(dc, rd);
20681210a036SRichard Henderson             tcg_gen_qemu_st_i64(d64, addr, da->mem_idx, memop | MO_ALIGN_4);
2069fcf5ef2aSThomas Huth             break;
20703259b9e2SRichard Henderson         case MO_128:
2071fcf5ef2aSThomas Huth             /* Only 4-byte alignment required.  However, it is legal for the
2072fcf5ef2aSThomas Huth                cpu to signal the alignment fault, and the OS trap handler is
2073fcf5ef2aSThomas Huth                required to fix it up.  Requiring 16-byte alignment here avoids
2074fcf5ef2aSThomas Huth                having to probe the second page before performing the first
2075fcf5ef2aSThomas Huth                write.  */
20761210a036SRichard Henderson             d64 = gen_load_fpr_D(dc, rd);
20771210a036SRichard Henderson             tcg_gen_qemu_st_i64(d64, addr, da->mem_idx, memop | MO_ALIGN_16);
2078287b1152SRichard Henderson             addr_tmp = tcg_temp_new();
2079287b1152SRichard Henderson             tcg_gen_addi_tl(addr_tmp, addr, 8);
20801210a036SRichard Henderson             d64 = gen_load_fpr_D(dc, rd + 2);
20811210a036SRichard Henderson             tcg_gen_qemu_st_i64(d64, addr_tmp, da->mem_idx, memop);
2082fcf5ef2aSThomas Huth             break;
2083fcf5ef2aSThomas Huth         default:
2084fcf5ef2aSThomas Huth             g_assert_not_reached();
2085fcf5ef2aSThomas Huth         }
2086fcf5ef2aSThomas Huth         break;
2087fcf5ef2aSThomas Huth 
2088fcf5ef2aSThomas Huth     case GET_ASI_BLOCK:
2089fcf5ef2aSThomas Huth         /* Valid for stdfa on aligned registers only.  */
20903259b9e2SRichard Henderson         if (orig_size == MO_64 && (rd & 7) == 0) {
2091fcf5ef2aSThomas Huth             /* The first operation checks required alignment.  */
2092287b1152SRichard Henderson             addr_tmp = tcg_temp_new();
2093287b1152SRichard Henderson             for (int i = 0; ; ++i) {
20941210a036SRichard Henderson                 d64 = gen_load_fpr_D(dc, rd + 2 * i);
20951210a036SRichard Henderson                 tcg_gen_qemu_st_i64(d64, addr, da->mem_idx,
20963259b9e2SRichard Henderson                                     memop | (i == 0 ? MO_ALIGN_64 : 0));
2097fcf5ef2aSThomas Huth                 if (i == 7) {
2098fcf5ef2aSThomas Huth                     break;
2099fcf5ef2aSThomas Huth                 }
2100287b1152SRichard Henderson                 tcg_gen_addi_tl(addr_tmp, addr, 8);
2101287b1152SRichard Henderson                 addr = addr_tmp;
2102fcf5ef2aSThomas Huth             }
2103fcf5ef2aSThomas Huth         } else {
2104fcf5ef2aSThomas Huth             gen_exception(dc, TT_ILL_INSN);
2105fcf5ef2aSThomas Huth         }
2106fcf5ef2aSThomas Huth         break;
2107fcf5ef2aSThomas Huth 
2108fcf5ef2aSThomas Huth     case GET_ASI_SHORT:
2109fcf5ef2aSThomas Huth         /* Valid for stdfa only.  */
21103259b9e2SRichard Henderson         if (orig_size == MO_64) {
21111210a036SRichard Henderson             d64 = gen_load_fpr_D(dc, rd);
21121210a036SRichard Henderson             tcg_gen_qemu_st_i64(d64, addr, da->mem_idx, memop | MO_ALIGN);
2113fcf5ef2aSThomas Huth         } else {
2114fcf5ef2aSThomas Huth             gen_exception(dc, TT_ILL_INSN);
2115fcf5ef2aSThomas Huth         }
2116fcf5ef2aSThomas Huth         break;
2117fcf5ef2aSThomas Huth 
2118fcf5ef2aSThomas Huth     default:
2119fcf5ef2aSThomas Huth         /* According to the table in the UA2011 manual, the only
2120fcf5ef2aSThomas Huth            other asis that are valid for ldfa/lddfa/ldqfa are
2121fcf5ef2aSThomas Huth            the PST* asis, which aren't currently handled.  */
2122fcf5ef2aSThomas Huth         gen_exception(dc, TT_ILL_INSN);
2123fcf5ef2aSThomas Huth         break;
2124fcf5ef2aSThomas Huth     }
2125fcf5ef2aSThomas Huth }
2126fcf5ef2aSThomas Huth 
212742071fc1SRichard Henderson static void gen_ldda_asi(DisasContext *dc, DisasASI *da, TCGv addr, int rd)
2128fcf5ef2aSThomas Huth {
2129a76779eeSRichard Henderson     TCGv hi = gen_dest_gpr(dc, rd);
2130a76779eeSRichard Henderson     TCGv lo = gen_dest_gpr(dc, rd + 1);
2131fcf5ef2aSThomas Huth 
2132c03a0fd1SRichard Henderson     switch (da->type) {
2133fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
2134fcf5ef2aSThomas Huth         return;
2135fcf5ef2aSThomas Huth 
2136fcf5ef2aSThomas Huth     case GET_ASI_DTWINX:
2137ebbbec92SRichard Henderson #ifdef TARGET_SPARC64
2138ebbbec92SRichard Henderson         {
2139ebbbec92SRichard Henderson             MemOp mop = (da->memop & MO_BSWAP) | MO_128 | MO_ALIGN_16;
2140ebbbec92SRichard Henderson             TCGv_i128 t = tcg_temp_new_i128();
2141ebbbec92SRichard Henderson 
2142ebbbec92SRichard Henderson             tcg_gen_qemu_ld_i128(t, addr, da->mem_idx, mop);
2143ebbbec92SRichard Henderson             /*
2144ebbbec92SRichard Henderson              * Note that LE twinx acts as if each 64-bit register result is
2145ebbbec92SRichard Henderson              * byte swapped.  We perform one 128-bit LE load, so must swap
2146ebbbec92SRichard Henderson              * the order of the writebacks.
2147ebbbec92SRichard Henderson              */
2148ebbbec92SRichard Henderson             if ((mop & MO_BSWAP) == MO_TE) {
2149ebbbec92SRichard Henderson                 tcg_gen_extr_i128_i64(lo, hi, t);
2150ebbbec92SRichard Henderson             } else {
2151ebbbec92SRichard Henderson                 tcg_gen_extr_i128_i64(hi, lo, t);
2152ebbbec92SRichard Henderson             }
2153ebbbec92SRichard Henderson         }
2154fcf5ef2aSThomas Huth         break;
2155ebbbec92SRichard Henderson #else
2156ebbbec92SRichard Henderson         g_assert_not_reached();
2157ebbbec92SRichard Henderson #endif
2158fcf5ef2aSThomas Huth 
2159fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
2160fcf5ef2aSThomas Huth         {
2161fcf5ef2aSThomas Huth             TCGv_i64 tmp = tcg_temp_new_i64();
2162fcf5ef2aSThomas Huth 
2163c03a0fd1SRichard Henderson             tcg_gen_qemu_ld_i64(tmp, addr, da->mem_idx, da->memop | MO_ALIGN);
2164fcf5ef2aSThomas Huth 
2165fcf5ef2aSThomas Huth             /* Note that LE ldda acts as if each 32-bit register
2166fcf5ef2aSThomas Huth                result is byte swapped.  Having just performed one
2167fcf5ef2aSThomas Huth                64-bit bswap, we need now to swap the writebacks.  */
2168c03a0fd1SRichard Henderson             if ((da->memop & MO_BSWAP) == MO_TE) {
2169a76779eeSRichard Henderson                 tcg_gen_extr_i64_tl(lo, hi, tmp);
2170fcf5ef2aSThomas Huth             } else {
2171a76779eeSRichard Henderson                 tcg_gen_extr_i64_tl(hi, lo, tmp);
2172fcf5ef2aSThomas Huth             }
2173fcf5ef2aSThomas Huth         }
2174fcf5ef2aSThomas Huth         break;
2175fcf5ef2aSThomas Huth 
21762786a3f8SRichard Henderson     case GET_ASI_CODE:
21772786a3f8SRichard Henderson #if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
21782786a3f8SRichard Henderson         {
21792786a3f8SRichard Henderson             MemOpIdx oi = make_memop_idx(da->memop, da->mem_idx);
21802786a3f8SRichard Henderson             TCGv_i64 tmp = tcg_temp_new_i64();
21812786a3f8SRichard Henderson 
21822786a3f8SRichard Henderson             gen_helper_ld_code(tmp, tcg_env, addr, tcg_constant_i32(oi));
21832786a3f8SRichard Henderson 
21842786a3f8SRichard Henderson             /* See above.  */
21852786a3f8SRichard Henderson             if ((da->memop & MO_BSWAP) == MO_TE) {
21862786a3f8SRichard Henderson                 tcg_gen_extr_i64_tl(lo, hi, tmp);
21872786a3f8SRichard Henderson             } else {
21882786a3f8SRichard Henderson                 tcg_gen_extr_i64_tl(hi, lo, tmp);
21892786a3f8SRichard Henderson             }
21902786a3f8SRichard Henderson         }
21912786a3f8SRichard Henderson         break;
21922786a3f8SRichard Henderson #else
21932786a3f8SRichard Henderson         g_assert_not_reached();
21942786a3f8SRichard Henderson #endif
21952786a3f8SRichard Henderson 
2196fcf5ef2aSThomas Huth     default:
2197fcf5ef2aSThomas Huth         /* ??? In theory we've handled all of the ASIs that are valid
2198fcf5ef2aSThomas Huth            for ldda, and this should raise DAE_invalid_asi.  However,
2199fcf5ef2aSThomas Huth            real hardware allows others.  This can be seen with e.g.
2200fcf5ef2aSThomas Huth            FreeBSD 10.3 wrt ASI_IC_TAG.  */
2201fcf5ef2aSThomas Huth         {
2202c03a0fd1SRichard Henderson             TCGv_i32 r_asi = tcg_constant_i32(da->asi);
2203c03a0fd1SRichard Henderson             TCGv_i32 r_mop = tcg_constant_i32(da->memop);
2204fcf5ef2aSThomas Huth             TCGv_i64 tmp = tcg_temp_new_i64();
2205fcf5ef2aSThomas Huth 
2206fcf5ef2aSThomas Huth             save_state(dc);
2207ad75a51eSRichard Henderson             gen_helper_ld_asi(tmp, tcg_env, addr, r_asi, r_mop);
2208fcf5ef2aSThomas Huth 
2209fcf5ef2aSThomas Huth             /* See above.  */
2210c03a0fd1SRichard Henderson             if ((da->memop & MO_BSWAP) == MO_TE) {
2211a76779eeSRichard Henderson                 tcg_gen_extr_i64_tl(lo, hi, tmp);
2212fcf5ef2aSThomas Huth             } else {
2213a76779eeSRichard Henderson                 tcg_gen_extr_i64_tl(hi, lo, tmp);
2214fcf5ef2aSThomas Huth             }
2215fcf5ef2aSThomas Huth         }
2216fcf5ef2aSThomas Huth         break;
2217fcf5ef2aSThomas Huth     }
2218fcf5ef2aSThomas Huth 
2219fcf5ef2aSThomas Huth     gen_store_gpr(dc, rd, hi);
2220fcf5ef2aSThomas Huth     gen_store_gpr(dc, rd + 1, lo);
2221fcf5ef2aSThomas Huth }
2222fcf5ef2aSThomas Huth 
222342071fc1SRichard Henderson static void gen_stda_asi(DisasContext *dc, DisasASI *da, TCGv addr, int rd)
2224c03a0fd1SRichard Henderson {
2225c03a0fd1SRichard Henderson     TCGv hi = gen_load_gpr(dc, rd);
2226fcf5ef2aSThomas Huth     TCGv lo = gen_load_gpr(dc, rd + 1);
2227fcf5ef2aSThomas Huth 
2228c03a0fd1SRichard Henderson     switch (da->type) {
2229fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
2230fcf5ef2aSThomas Huth         break;
2231fcf5ef2aSThomas Huth 
2232fcf5ef2aSThomas Huth     case GET_ASI_DTWINX:
2233ebbbec92SRichard Henderson #ifdef TARGET_SPARC64
2234ebbbec92SRichard Henderson         {
2235ebbbec92SRichard Henderson             MemOp mop = (da->memop & MO_BSWAP) | MO_128 | MO_ALIGN_16;
2236ebbbec92SRichard Henderson             TCGv_i128 t = tcg_temp_new_i128();
2237ebbbec92SRichard Henderson 
2238ebbbec92SRichard Henderson             /*
2239ebbbec92SRichard Henderson              * Note that LE twinx acts as if each 64-bit register result is
2240ebbbec92SRichard Henderson              * byte swapped.  We perform one 128-bit LE store, so must swap
2241ebbbec92SRichard Henderson              * the order of the construction.
2242ebbbec92SRichard Henderson              */
2243ebbbec92SRichard Henderson             if ((mop & MO_BSWAP) == MO_TE) {
2244ebbbec92SRichard Henderson                 tcg_gen_concat_i64_i128(t, lo, hi);
2245ebbbec92SRichard Henderson             } else {
2246ebbbec92SRichard Henderson                 tcg_gen_concat_i64_i128(t, hi, lo);
2247ebbbec92SRichard Henderson             }
2248ebbbec92SRichard Henderson             tcg_gen_qemu_st_i128(t, addr, da->mem_idx, mop);
2249ebbbec92SRichard Henderson         }
2250fcf5ef2aSThomas Huth         break;
2251ebbbec92SRichard Henderson #else
2252ebbbec92SRichard Henderson         g_assert_not_reached();
2253ebbbec92SRichard Henderson #endif
2254fcf5ef2aSThomas Huth 
2255fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
2256fcf5ef2aSThomas Huth         {
2257fcf5ef2aSThomas Huth             TCGv_i64 t64 = tcg_temp_new_i64();
2258fcf5ef2aSThomas Huth 
2259fcf5ef2aSThomas Huth             /* Note that LE stda acts as if each 32-bit register result is
2260fcf5ef2aSThomas Huth                byte swapped.  We will perform one 64-bit LE store, so now
2261fcf5ef2aSThomas Huth                we must swap the order of the construction.  */
2262c03a0fd1SRichard Henderson             if ((da->memop & MO_BSWAP) == MO_TE) {
2263a76779eeSRichard Henderson                 tcg_gen_concat_tl_i64(t64, lo, hi);
2264fcf5ef2aSThomas Huth             } else {
2265a76779eeSRichard Henderson                 tcg_gen_concat_tl_i64(t64, hi, lo);
2266fcf5ef2aSThomas Huth             }
2267c03a0fd1SRichard Henderson             tcg_gen_qemu_st_i64(t64, addr, da->mem_idx, da->memop | MO_ALIGN);
2268fcf5ef2aSThomas Huth         }
2269fcf5ef2aSThomas Huth         break;
2270fcf5ef2aSThomas Huth 
2271a76779eeSRichard Henderson     case GET_ASI_BFILL:
2272a76779eeSRichard Henderson         assert(TARGET_LONG_BITS == 32);
227354c3e953SRichard Henderson         /*
227454c3e953SRichard Henderson          * Store 32 bytes of [rd:rd+1] to ADDR.
227554c3e953SRichard Henderson          * See comments for GET_ASI_COPY above.
227654c3e953SRichard Henderson          */
2277a76779eeSRichard Henderson         {
227854c3e953SRichard Henderson             MemOp mop = MO_TE | MO_128 | MO_ATOM_IFALIGN_PAIR;
227954c3e953SRichard Henderson             TCGv_i64 t8 = tcg_temp_new_i64();
228054c3e953SRichard Henderson             TCGv_i128 t16 = tcg_temp_new_i128();
228154c3e953SRichard Henderson             TCGv daddr = tcg_temp_new();
2282a76779eeSRichard Henderson 
228354c3e953SRichard Henderson             tcg_gen_concat_tl_i64(t8, lo, hi);
228454c3e953SRichard Henderson             tcg_gen_concat_i64_i128(t16, t8, t8);
228554c3e953SRichard Henderson             tcg_gen_andi_tl(daddr, addr, -32);
228654c3e953SRichard Henderson             tcg_gen_qemu_st_i128(t16, daddr, da->mem_idx, mop);
228754c3e953SRichard Henderson             tcg_gen_addi_tl(daddr, daddr, 16);
228854c3e953SRichard Henderson             tcg_gen_qemu_st_i128(t16, daddr, da->mem_idx, mop);
2289a76779eeSRichard Henderson         }
2290a76779eeSRichard Henderson         break;
2291a76779eeSRichard Henderson 
2292fcf5ef2aSThomas Huth     default:
2293fcf5ef2aSThomas Huth         /* ??? In theory we've handled all of the ASIs that are valid
2294fcf5ef2aSThomas Huth            for stda, and this should raise DAE_invalid_asi.  */
2295fcf5ef2aSThomas Huth         {
2296c03a0fd1SRichard Henderson             TCGv_i32 r_asi = tcg_constant_i32(da->asi);
2297c03a0fd1SRichard Henderson             TCGv_i32 r_mop = tcg_constant_i32(da->memop);
2298fcf5ef2aSThomas Huth             TCGv_i64 t64 = tcg_temp_new_i64();
2299fcf5ef2aSThomas Huth 
2300fcf5ef2aSThomas Huth             /* See above.  */
2301c03a0fd1SRichard Henderson             if ((da->memop & MO_BSWAP) == MO_TE) {
2302a76779eeSRichard Henderson                 tcg_gen_concat_tl_i64(t64, lo, hi);
2303fcf5ef2aSThomas Huth             } else {
2304a76779eeSRichard Henderson                 tcg_gen_concat_tl_i64(t64, hi, lo);
2305fcf5ef2aSThomas Huth             }
2306fcf5ef2aSThomas Huth 
2307fcf5ef2aSThomas Huth             save_state(dc);
2308ad75a51eSRichard Henderson             gen_helper_st_asi(tcg_env, addr, t64, r_asi, r_mop);
2309fcf5ef2aSThomas Huth         }
2310fcf5ef2aSThomas Huth         break;
2311fcf5ef2aSThomas Huth     }
2312fcf5ef2aSThomas Huth }
2313fcf5ef2aSThomas Huth 
2314fcf5ef2aSThomas Huth static void gen_fmovs(DisasContext *dc, DisasCompare *cmp, int rd, int rs)
2315fcf5ef2aSThomas Huth {
2316f7ec8155SRichard Henderson #ifdef TARGET_SPARC64
2317fcf5ef2aSThomas Huth     TCGv_i32 c32, zero, dst, s1, s2;
2318dd7dbfccSRichard Henderson     TCGv_i64 c64 = tcg_temp_new_i64();
2319fcf5ef2aSThomas Huth 
2320fcf5ef2aSThomas Huth     /* We have two choices here: extend the 32 bit data and use movcond_i64,
2321fcf5ef2aSThomas Huth        or fold the comparison down to 32 bits and use movcond_i32.  Choose
2322fcf5ef2aSThomas Huth        the later.  */
2323fcf5ef2aSThomas Huth     c32 = tcg_temp_new_i32();
2324c8507ebfSRichard Henderson     tcg_gen_setcondi_i64(cmp->cond, c64, cmp->c1, cmp->c2);
2325fcf5ef2aSThomas Huth     tcg_gen_extrl_i64_i32(c32, c64);
2326fcf5ef2aSThomas Huth 
2327fcf5ef2aSThomas Huth     s1 = gen_load_fpr_F(dc, rs);
2328fcf5ef2aSThomas Huth     s2 = gen_load_fpr_F(dc, rd);
2329388a6465SRichard Henderson     dst = tcg_temp_new_i32();
233000ab7e61SRichard Henderson     zero = tcg_constant_i32(0);
2331fcf5ef2aSThomas Huth 
2332fcf5ef2aSThomas Huth     tcg_gen_movcond_i32(TCG_COND_NE, dst, c32, zero, s1, s2);
2333fcf5ef2aSThomas Huth 
2334fcf5ef2aSThomas Huth     gen_store_fpr_F(dc, rd, dst);
2335f7ec8155SRichard Henderson #else
2336f7ec8155SRichard Henderson     qemu_build_not_reached();
2337f7ec8155SRichard Henderson #endif
2338fcf5ef2aSThomas Huth }
2339fcf5ef2aSThomas Huth 
2340fcf5ef2aSThomas Huth static void gen_fmovd(DisasContext *dc, DisasCompare *cmp, int rd, int rs)
2341fcf5ef2aSThomas Huth {
2342f7ec8155SRichard Henderson #ifdef TARGET_SPARC64
234352f46d46SRichard Henderson     TCGv_i64 dst = tcg_temp_new_i64();
2344c8507ebfSRichard Henderson     tcg_gen_movcond_i64(cmp->cond, dst, cmp->c1, tcg_constant_tl(cmp->c2),
2345fcf5ef2aSThomas Huth                         gen_load_fpr_D(dc, rs),
2346fcf5ef2aSThomas Huth                         gen_load_fpr_D(dc, rd));
2347fcf5ef2aSThomas Huth     gen_store_fpr_D(dc, rd, dst);
2348f7ec8155SRichard Henderson #else
2349f7ec8155SRichard Henderson     qemu_build_not_reached();
2350f7ec8155SRichard Henderson #endif
2351fcf5ef2aSThomas Huth }
2352fcf5ef2aSThomas Huth 
2353fcf5ef2aSThomas Huth static void gen_fmovq(DisasContext *dc, DisasCompare *cmp, int rd, int rs)
2354fcf5ef2aSThomas Huth {
2355f7ec8155SRichard Henderson #ifdef TARGET_SPARC64
2356c8507ebfSRichard Henderson     TCGv c2 = tcg_constant_tl(cmp->c2);
23571210a036SRichard Henderson     TCGv_i64 h = tcg_temp_new_i64();
23581210a036SRichard Henderson     TCGv_i64 l = tcg_temp_new_i64();
2359fcf5ef2aSThomas Huth 
23601210a036SRichard Henderson     tcg_gen_movcond_i64(cmp->cond, h, cmp->c1, c2,
23611210a036SRichard Henderson                         gen_load_fpr_D(dc, rs),
23621210a036SRichard Henderson                         gen_load_fpr_D(dc, rd));
23631210a036SRichard Henderson     tcg_gen_movcond_i64(cmp->cond, l, cmp->c1, c2,
23641210a036SRichard Henderson                         gen_load_fpr_D(dc, rs + 2),
23651210a036SRichard Henderson                         gen_load_fpr_D(dc, rd + 2));
23661210a036SRichard Henderson     gen_store_fpr_D(dc, rd, h);
23671210a036SRichard Henderson     gen_store_fpr_D(dc, rd + 2, l);
2368f7ec8155SRichard Henderson #else
2369f7ec8155SRichard Henderson     qemu_build_not_reached();
2370f7ec8155SRichard Henderson #endif
2371fcf5ef2aSThomas Huth }
2372fcf5ef2aSThomas Huth 
2373f7ec8155SRichard Henderson #ifdef TARGET_SPARC64
23745d617bfbSRichard Henderson static void gen_load_trap_state_at_tl(TCGv_ptr r_tsptr)
2375fcf5ef2aSThomas Huth {
2376fcf5ef2aSThomas Huth     TCGv_i32 r_tl = tcg_temp_new_i32();
2377fcf5ef2aSThomas Huth 
2378fcf5ef2aSThomas Huth     /* load env->tl into r_tl */
2379ad75a51eSRichard Henderson     tcg_gen_ld_i32(r_tl, tcg_env, offsetof(CPUSPARCState, tl));
2380fcf5ef2aSThomas Huth 
2381fcf5ef2aSThomas Huth     /* tl = [0 ... MAXTL_MASK] where MAXTL_MASK must be power of 2 */
2382fcf5ef2aSThomas Huth     tcg_gen_andi_i32(r_tl, r_tl, MAXTL_MASK);
2383fcf5ef2aSThomas Huth 
2384fcf5ef2aSThomas Huth     /* calculate offset to current trap state from env->ts, reuse r_tl */
2385fcf5ef2aSThomas Huth     tcg_gen_muli_i32(r_tl, r_tl, sizeof (trap_state));
2386ad75a51eSRichard Henderson     tcg_gen_addi_ptr(r_tsptr, tcg_env, offsetof(CPUSPARCState, ts));
2387fcf5ef2aSThomas Huth 
2388fcf5ef2aSThomas Huth     /* tsptr = env->ts[env->tl & MAXTL_MASK] */
2389fcf5ef2aSThomas Huth     {
2390fcf5ef2aSThomas Huth         TCGv_ptr r_tl_tmp = tcg_temp_new_ptr();
2391fcf5ef2aSThomas Huth         tcg_gen_ext_i32_ptr(r_tl_tmp, r_tl);
2392fcf5ef2aSThomas Huth         tcg_gen_add_ptr(r_tsptr, r_tsptr, r_tl_tmp);
2393fcf5ef2aSThomas Huth     }
2394fcf5ef2aSThomas Huth }
2395fcf5ef2aSThomas Huth #endif
2396fcf5ef2aSThomas Huth 
239706c060d9SRichard Henderson static int extract_dfpreg(DisasContext *dc, int x)
239806c060d9SRichard Henderson {
23990bba7572SRichard Henderson     int r = x & 0x1e;
24000bba7572SRichard Henderson #ifdef TARGET_SPARC64
24010bba7572SRichard Henderson     r |= (x & 1) << 5;
24020bba7572SRichard Henderson #endif
24030bba7572SRichard Henderson     return r;
240406c060d9SRichard Henderson }
240506c060d9SRichard Henderson 
240606c060d9SRichard Henderson static int extract_qfpreg(DisasContext *dc, int x)
240706c060d9SRichard Henderson {
24080bba7572SRichard Henderson     int r = x & 0x1c;
24090bba7572SRichard Henderson #ifdef TARGET_SPARC64
24100bba7572SRichard Henderson     r |= (x & 1) << 5;
24110bba7572SRichard Henderson #endif
24120bba7572SRichard Henderson     return r;
241306c060d9SRichard Henderson }
241406c060d9SRichard Henderson 
2415878cc677SRichard Henderson /* Include the auto-generated decoder.  */
2416878cc677SRichard Henderson #include "decode-insns.c.inc"
2417878cc677SRichard Henderson 
2418878cc677SRichard Henderson #define TRANS(NAME, AVAIL, FUNC, ...) \
2419878cc677SRichard Henderson     static bool trans_##NAME(DisasContext *dc, arg_##NAME *a) \
2420878cc677SRichard Henderson     { return avail_##AVAIL(dc) && FUNC(dc, __VA_ARGS__); }
2421878cc677SRichard Henderson 
2422878cc677SRichard Henderson #define avail_ALL(C)      true
2423878cc677SRichard Henderson #ifdef TARGET_SPARC64
2424878cc677SRichard Henderson # define avail_32(C)      false
2425af25071cSRichard Henderson # define avail_ASR17(C)   false
2426d0a11d25SRichard Henderson # define avail_CASA(C)    true
2427c2636853SRichard Henderson # define avail_DIV(C)     true
2428b5372650SRichard Henderson # define avail_MUL(C)     true
24290faef01bSRichard Henderson # define avail_POWERDOWN(C) false
2430878cc677SRichard Henderson # define avail_64(C)      true
24314fd71d19SRichard Henderson # define avail_FMAF(C)    ((C)->def->features & CPU_FEATURE_FMAF)
24325d617bfbSRichard Henderson # define avail_GL(C)      ((C)->def->features & CPU_FEATURE_GL)
2433af25071cSRichard Henderson # define avail_HYPV(C)    ((C)->def->features & CPU_FEATURE_HYPV)
243468a414e9SRichard Henderson # define avail_IMA(C)     ((C)->def->features & CPU_FEATURE_IMA)
2435b88ce6f2SRichard Henderson # define avail_VIS1(C)    ((C)->def->features & CPU_FEATURE_VIS1)
2436b88ce6f2SRichard Henderson # define avail_VIS2(C)    ((C)->def->features & CPU_FEATURE_VIS2)
24373335a048SRichard Henderson # define avail_VIS3(C)    ((C)->def->features & CPU_FEATURE_VIS3)
24383335a048SRichard Henderson # define avail_VIS3B(C)   avail_VIS3(C)
243990b1433dSRichard Henderson # define avail_VIS4(C)    ((C)->def->features & CPU_FEATURE_VIS4)
2440878cc677SRichard Henderson #else
2441878cc677SRichard Henderson # define avail_32(C)      true
2442af25071cSRichard Henderson # define avail_ASR17(C)   ((C)->def->features & CPU_FEATURE_ASR17)
2443d0a11d25SRichard Henderson # define avail_CASA(C)    ((C)->def->features & CPU_FEATURE_CASA)
2444c2636853SRichard Henderson # define avail_DIV(C)     ((C)->def->features & CPU_FEATURE_DIV)
2445b5372650SRichard Henderson # define avail_MUL(C)     ((C)->def->features & CPU_FEATURE_MUL)
24460faef01bSRichard Henderson # define avail_POWERDOWN(C) ((C)->def->features & CPU_FEATURE_POWERDOWN)
2447878cc677SRichard Henderson # define avail_64(C)      false
24484fd71d19SRichard Henderson # define avail_FMAF(C)    false
24495d617bfbSRichard Henderson # define avail_GL(C)      false
2450af25071cSRichard Henderson # define avail_HYPV(C)    false
245168a414e9SRichard Henderson # define avail_IMA(C)     false
2452b88ce6f2SRichard Henderson # define avail_VIS1(C)    false
2453b88ce6f2SRichard Henderson # define avail_VIS2(C)    false
24543335a048SRichard Henderson # define avail_VIS3(C)    false
24553335a048SRichard Henderson # define avail_VIS3B(C)   false
245690b1433dSRichard Henderson # define avail_VIS4(C)    false
2457878cc677SRichard Henderson #endif
2458878cc677SRichard Henderson 
2459878cc677SRichard Henderson /* Default case for non jump instructions. */
2460878cc677SRichard Henderson static bool advance_pc(DisasContext *dc)
2461878cc677SRichard Henderson {
24624a8d145dSRichard Henderson     TCGLabel *l1;
24634a8d145dSRichard Henderson 
246489527e3aSRichard Henderson     finishing_insn(dc);
246589527e3aSRichard Henderson 
2466878cc677SRichard Henderson     if (dc->npc & 3) {
2467878cc677SRichard Henderson         switch (dc->npc) {
2468878cc677SRichard Henderson         case DYNAMIC_PC:
2469878cc677SRichard Henderson         case DYNAMIC_PC_LOOKUP:
2470878cc677SRichard Henderson             dc->pc = dc->npc;
2471444d8b30SRichard Henderson             tcg_gen_mov_tl(cpu_pc, cpu_npc);
2472444d8b30SRichard Henderson             tcg_gen_addi_tl(cpu_npc, cpu_npc, 4);
2473878cc677SRichard Henderson             break;
24744a8d145dSRichard Henderson 
2475878cc677SRichard Henderson         case JUMP_PC:
2476878cc677SRichard Henderson             /* we can do a static jump */
24774a8d145dSRichard Henderson             l1 = gen_new_label();
2478533f042fSRichard Henderson             tcg_gen_brcondi_tl(dc->jump.cond, dc->jump.c1, dc->jump.c2, l1);
24794a8d145dSRichard Henderson 
24804a8d145dSRichard Henderson             /* jump not taken */
24814a8d145dSRichard Henderson             gen_goto_tb(dc, 1, dc->jump_pc[1], dc->jump_pc[1] + 4);
24824a8d145dSRichard Henderson 
24834a8d145dSRichard Henderson             /* jump taken */
24844a8d145dSRichard Henderson             gen_set_label(l1);
24854a8d145dSRichard Henderson             gen_goto_tb(dc, 0, dc->jump_pc[0], dc->jump_pc[0] + 4);
24864a8d145dSRichard Henderson 
2487878cc677SRichard Henderson             dc->base.is_jmp = DISAS_NORETURN;
2488878cc677SRichard Henderson             break;
24894a8d145dSRichard Henderson 
2490878cc677SRichard Henderson         default:
2491878cc677SRichard Henderson             g_assert_not_reached();
2492878cc677SRichard Henderson         }
2493878cc677SRichard Henderson     } else {
2494878cc677SRichard Henderson         dc->pc = dc->npc;
2495878cc677SRichard Henderson         dc->npc = dc->npc + 4;
2496878cc677SRichard Henderson     }
2497878cc677SRichard Henderson     return true;
2498878cc677SRichard Henderson }
2499878cc677SRichard Henderson 
25006d2a0768SRichard Henderson /*
25016d2a0768SRichard Henderson  * Major opcodes 00 and 01 -- branches, call, and sethi
25026d2a0768SRichard Henderson  */
25036d2a0768SRichard Henderson 
25049d4e2bc7SRichard Henderson static bool advance_jump_cond(DisasContext *dc, DisasCompare *cmp,
25053951b7a8SRichard Henderson                               bool annul, int disp)
2506276567aaSRichard Henderson {
25073951b7a8SRichard Henderson     target_ulong dest = address_mask_i(dc, dc->pc + disp * 4);
2508c76c8045SRichard Henderson     target_ulong npc;
2509c76c8045SRichard Henderson 
251089527e3aSRichard Henderson     finishing_insn(dc);
251189527e3aSRichard Henderson 
25122d9bb237SRichard Henderson     if (cmp->cond == TCG_COND_ALWAYS) {
25132d9bb237SRichard Henderson         if (annul) {
25142d9bb237SRichard Henderson             dc->pc = dest;
25152d9bb237SRichard Henderson             dc->npc = dest + 4;
25162d9bb237SRichard Henderson         } else {
25172d9bb237SRichard Henderson             gen_mov_pc_npc(dc);
25182d9bb237SRichard Henderson             dc->npc = dest;
25192d9bb237SRichard Henderson         }
25202d9bb237SRichard Henderson         return true;
25212d9bb237SRichard Henderson     }
25222d9bb237SRichard Henderson 
25232d9bb237SRichard Henderson     if (cmp->cond == TCG_COND_NEVER) {
25242d9bb237SRichard Henderson         npc = dc->npc;
25252d9bb237SRichard Henderson         if (npc & 3) {
25262d9bb237SRichard Henderson             gen_mov_pc_npc(dc);
25272d9bb237SRichard Henderson             if (annul) {
25282d9bb237SRichard Henderson                 tcg_gen_addi_tl(cpu_pc, cpu_pc, 4);
25292d9bb237SRichard Henderson             }
25302d9bb237SRichard Henderson             tcg_gen_addi_tl(cpu_npc, cpu_pc, 4);
25312d9bb237SRichard Henderson         } else {
25322d9bb237SRichard Henderson             dc->pc = npc + (annul ? 4 : 0);
25332d9bb237SRichard Henderson             dc->npc = dc->pc + 4;
25342d9bb237SRichard Henderson         }
25352d9bb237SRichard Henderson         return true;
25362d9bb237SRichard Henderson     }
25372d9bb237SRichard Henderson 
2538c76c8045SRichard Henderson     flush_cond(dc);
2539c76c8045SRichard Henderson     npc = dc->npc;
25406b3e4cc6SRichard Henderson 
2541276567aaSRichard Henderson     if (annul) {
25426b3e4cc6SRichard Henderson         TCGLabel *l1 = gen_new_label();
25436b3e4cc6SRichard Henderson 
2544c8507ebfSRichard Henderson         tcg_gen_brcondi_tl(tcg_invert_cond(cmp->cond), cmp->c1, cmp->c2, l1);
25456b3e4cc6SRichard Henderson         gen_goto_tb(dc, 0, npc, dest);
25466b3e4cc6SRichard Henderson         gen_set_label(l1);
25476b3e4cc6SRichard Henderson         gen_goto_tb(dc, 1, npc + 4, npc + 8);
25486b3e4cc6SRichard Henderson 
25496b3e4cc6SRichard Henderson         dc->base.is_jmp = DISAS_NORETURN;
2550276567aaSRichard Henderson     } else {
25516b3e4cc6SRichard Henderson         if (npc & 3) {
25526b3e4cc6SRichard Henderson             switch (npc) {
25536b3e4cc6SRichard Henderson             case DYNAMIC_PC:
25546b3e4cc6SRichard Henderson             case DYNAMIC_PC_LOOKUP:
25556b3e4cc6SRichard Henderson                 tcg_gen_mov_tl(cpu_pc, cpu_npc);
25566b3e4cc6SRichard Henderson                 tcg_gen_addi_tl(cpu_npc, cpu_npc, 4);
25579d4e2bc7SRichard Henderson                 tcg_gen_movcond_tl(cmp->cond, cpu_npc,
2558c8507ebfSRichard Henderson                                    cmp->c1, tcg_constant_tl(cmp->c2),
25596b3e4cc6SRichard Henderson                                    tcg_constant_tl(dest), cpu_npc);
25606b3e4cc6SRichard Henderson                 dc->pc = npc;
25616b3e4cc6SRichard Henderson                 break;
25626b3e4cc6SRichard Henderson             default:
25636b3e4cc6SRichard Henderson                 g_assert_not_reached();
25646b3e4cc6SRichard Henderson             }
25656b3e4cc6SRichard Henderson         } else {
25666b3e4cc6SRichard Henderson             dc->pc = npc;
2567533f042fSRichard Henderson             dc->npc = JUMP_PC;
2568533f042fSRichard Henderson             dc->jump = *cmp;
25696b3e4cc6SRichard Henderson             dc->jump_pc[0] = dest;
25706b3e4cc6SRichard Henderson             dc->jump_pc[1] = npc + 4;
2571dd7dbfccSRichard Henderson 
2572dd7dbfccSRichard Henderson             /* The condition for cpu_cond is always NE -- normalize. */
2573dd7dbfccSRichard Henderson             if (cmp->cond == TCG_COND_NE) {
2574c8507ebfSRichard Henderson                 tcg_gen_xori_tl(cpu_cond, cmp->c1, cmp->c2);
25759d4e2bc7SRichard Henderson             } else {
2576c8507ebfSRichard Henderson                 tcg_gen_setcondi_tl(cmp->cond, cpu_cond, cmp->c1, cmp->c2);
25779d4e2bc7SRichard Henderson             }
257889527e3aSRichard Henderson             dc->cpu_cond_live = true;
25796b3e4cc6SRichard Henderson         }
2580276567aaSRichard Henderson     }
2581276567aaSRichard Henderson     return true;
2582276567aaSRichard Henderson }
2583276567aaSRichard Henderson 
2584af25071cSRichard Henderson static bool raise_priv(DisasContext *dc)
2585af25071cSRichard Henderson {
2586af25071cSRichard Henderson     gen_exception(dc, TT_PRIV_INSN);
2587af25071cSRichard Henderson     return true;
2588af25071cSRichard Henderson }
2589af25071cSRichard Henderson 
259006c060d9SRichard Henderson static bool raise_unimpfpop(DisasContext *dc)
259106c060d9SRichard Henderson {
259206c060d9SRichard Henderson     gen_op_fpexception_im(dc, FSR_FTT_UNIMPFPOP);
259306c060d9SRichard Henderson     return true;
259406c060d9SRichard Henderson }
259506c060d9SRichard Henderson 
259606c060d9SRichard Henderson static bool gen_trap_float128(DisasContext *dc)
259706c060d9SRichard Henderson {
259806c060d9SRichard Henderson     if (dc->def->features & CPU_FEATURE_FLOAT128) {
259906c060d9SRichard Henderson         return false;
260006c060d9SRichard Henderson     }
260106c060d9SRichard Henderson     return raise_unimpfpop(dc);
260206c060d9SRichard Henderson }
260306c060d9SRichard Henderson 
2604276567aaSRichard Henderson static bool do_bpcc(DisasContext *dc, arg_bcc *a)
2605276567aaSRichard Henderson {
26061ea9c62aSRichard Henderson     DisasCompare cmp;
2607276567aaSRichard Henderson 
26081ea9c62aSRichard Henderson     gen_compare(&cmp, a->cc, a->cond, dc);
26093951b7a8SRichard Henderson     return advance_jump_cond(dc, &cmp, a->a, a->i);
2610276567aaSRichard Henderson }
2611276567aaSRichard Henderson 
2612276567aaSRichard Henderson TRANS(Bicc, ALL, do_bpcc, a)
2613276567aaSRichard Henderson TRANS(BPcc,  64, do_bpcc, a)
2614276567aaSRichard Henderson 
261545196ea4SRichard Henderson static bool do_fbpfcc(DisasContext *dc, arg_bcc *a)
261645196ea4SRichard Henderson {
2617d5471936SRichard Henderson     DisasCompare cmp;
261845196ea4SRichard Henderson 
261945196ea4SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
262045196ea4SRichard Henderson         return true;
262145196ea4SRichard Henderson     }
2622d5471936SRichard Henderson     gen_fcompare(&cmp, a->cc, a->cond);
26233951b7a8SRichard Henderson     return advance_jump_cond(dc, &cmp, a->a, a->i);
262445196ea4SRichard Henderson }
262545196ea4SRichard Henderson 
262645196ea4SRichard Henderson TRANS(FBPfcc,  64, do_fbpfcc, a)
262745196ea4SRichard Henderson TRANS(FBfcc,  ALL, do_fbpfcc, a)
262845196ea4SRichard Henderson 
2629ab9ffe98SRichard Henderson static bool trans_BPr(DisasContext *dc, arg_BPr *a)
2630ab9ffe98SRichard Henderson {
2631ab9ffe98SRichard Henderson     DisasCompare cmp;
2632ab9ffe98SRichard Henderson 
2633ab9ffe98SRichard Henderson     if (!avail_64(dc)) {
2634ab9ffe98SRichard Henderson         return false;
2635ab9ffe98SRichard Henderson     }
26362c4f56c9SRichard Henderson     if (!gen_compare_reg(&cmp, a->cond, gen_load_gpr(dc, a->rs1))) {
2637ab9ffe98SRichard Henderson         return false;
2638ab9ffe98SRichard Henderson     }
26393951b7a8SRichard Henderson     return advance_jump_cond(dc, &cmp, a->a, a->i);
2640ab9ffe98SRichard Henderson }
2641ab9ffe98SRichard Henderson 
264223ada1b1SRichard Henderson static bool trans_CALL(DisasContext *dc, arg_CALL *a)
264323ada1b1SRichard Henderson {
264423ada1b1SRichard Henderson     target_long target = address_mask_i(dc, dc->pc + a->i * 4);
264523ada1b1SRichard Henderson 
264623ada1b1SRichard Henderson     gen_store_gpr(dc, 15, tcg_constant_tl(dc->pc));
264723ada1b1SRichard Henderson     gen_mov_pc_npc(dc);
264823ada1b1SRichard Henderson     dc->npc = target;
264923ada1b1SRichard Henderson     return true;
265023ada1b1SRichard Henderson }
265123ada1b1SRichard Henderson 
265245196ea4SRichard Henderson static bool trans_NCP(DisasContext *dc, arg_NCP *a)
265345196ea4SRichard Henderson {
265445196ea4SRichard Henderson     /*
265545196ea4SRichard Henderson      * For sparc32, always generate the no-coprocessor exception.
265645196ea4SRichard Henderson      * For sparc64, always generate illegal instruction.
265745196ea4SRichard Henderson      */
265845196ea4SRichard Henderson #ifdef TARGET_SPARC64
265945196ea4SRichard Henderson     return false;
266045196ea4SRichard Henderson #else
266145196ea4SRichard Henderson     gen_exception(dc, TT_NCP_INSN);
266245196ea4SRichard Henderson     return true;
266345196ea4SRichard Henderson #endif
266445196ea4SRichard Henderson }
266545196ea4SRichard Henderson 
26666d2a0768SRichard Henderson static bool trans_SETHI(DisasContext *dc, arg_SETHI *a)
26676d2a0768SRichard Henderson {
26686d2a0768SRichard Henderson     /* Special-case %g0 because that's the canonical nop.  */
26696d2a0768SRichard Henderson     if (a->rd) {
26706d2a0768SRichard Henderson         gen_store_gpr(dc, a->rd, tcg_constant_tl((uint32_t)a->i << 10));
26716d2a0768SRichard Henderson     }
26726d2a0768SRichard Henderson     return advance_pc(dc);
26736d2a0768SRichard Henderson }
26746d2a0768SRichard Henderson 
26750faef01bSRichard Henderson /*
26760faef01bSRichard Henderson  * Major Opcode 10 -- integer, floating-point, vis, and system insns.
26770faef01bSRichard Henderson  */
26780faef01bSRichard Henderson 
267930376636SRichard Henderson static bool do_tcc(DisasContext *dc, int cond, int cc,
268030376636SRichard Henderson                    int rs1, bool imm, int rs2_or_imm)
268130376636SRichard Henderson {
268230376636SRichard Henderson     int mask = ((dc->def->features & CPU_FEATURE_HYPV) && supervisor(dc)
268330376636SRichard Henderson                 ? UA2005_HTRAP_MASK : V8_TRAP_MASK);
268430376636SRichard Henderson     DisasCompare cmp;
268530376636SRichard Henderson     TCGLabel *lab;
268630376636SRichard Henderson     TCGv_i32 trap;
268730376636SRichard Henderson 
268830376636SRichard Henderson     /* Trap never.  */
268930376636SRichard Henderson     if (cond == 0) {
269030376636SRichard Henderson         return advance_pc(dc);
269130376636SRichard Henderson     }
269230376636SRichard Henderson 
269330376636SRichard Henderson     /*
269430376636SRichard Henderson      * Immediate traps are the most common case.  Since this value is
269530376636SRichard Henderson      * live across the branch, it really pays to evaluate the constant.
269630376636SRichard Henderson      */
269730376636SRichard Henderson     if (rs1 == 0 && (imm || rs2_or_imm == 0)) {
269830376636SRichard Henderson         trap = tcg_constant_i32((rs2_or_imm & mask) + TT_TRAP);
269930376636SRichard Henderson     } else {
270030376636SRichard Henderson         trap = tcg_temp_new_i32();
270130376636SRichard Henderson         tcg_gen_trunc_tl_i32(trap, gen_load_gpr(dc, rs1));
270230376636SRichard Henderson         if (imm) {
270330376636SRichard Henderson             tcg_gen_addi_i32(trap, trap, rs2_or_imm);
270430376636SRichard Henderson         } else {
270530376636SRichard Henderson             TCGv_i32 t2 = tcg_temp_new_i32();
270630376636SRichard Henderson             tcg_gen_trunc_tl_i32(t2, gen_load_gpr(dc, rs2_or_imm));
270730376636SRichard Henderson             tcg_gen_add_i32(trap, trap, t2);
270830376636SRichard Henderson         }
270930376636SRichard Henderson         tcg_gen_andi_i32(trap, trap, mask);
271030376636SRichard Henderson         tcg_gen_addi_i32(trap, trap, TT_TRAP);
271130376636SRichard Henderson     }
271230376636SRichard Henderson 
271389527e3aSRichard Henderson     finishing_insn(dc);
271489527e3aSRichard Henderson 
271530376636SRichard Henderson     /* Trap always.  */
271630376636SRichard Henderson     if (cond == 8) {
271730376636SRichard Henderson         save_state(dc);
271830376636SRichard Henderson         gen_helper_raise_exception(tcg_env, trap);
271930376636SRichard Henderson         dc->base.is_jmp = DISAS_NORETURN;
272030376636SRichard Henderson         return true;
272130376636SRichard Henderson     }
272230376636SRichard Henderson 
272330376636SRichard Henderson     /* Conditional trap.  */
272430376636SRichard Henderson     flush_cond(dc);
272530376636SRichard Henderson     lab = delay_exceptionv(dc, trap);
272630376636SRichard Henderson     gen_compare(&cmp, cc, cond, dc);
2727c8507ebfSRichard Henderson     tcg_gen_brcondi_tl(cmp.cond, cmp.c1, cmp.c2, lab);
272830376636SRichard Henderson 
272930376636SRichard Henderson     return advance_pc(dc);
273030376636SRichard Henderson }
273130376636SRichard Henderson 
273230376636SRichard Henderson static bool trans_Tcc_r(DisasContext *dc, arg_Tcc_r *a)
273330376636SRichard Henderson {
273430376636SRichard Henderson     if (avail_32(dc) && a->cc) {
273530376636SRichard Henderson         return false;
273630376636SRichard Henderson     }
273730376636SRichard Henderson     return do_tcc(dc, a->cond, a->cc, a->rs1, false, a->rs2);
273830376636SRichard Henderson }
273930376636SRichard Henderson 
274030376636SRichard Henderson static bool trans_Tcc_i_v7(DisasContext *dc, arg_Tcc_i_v7 *a)
274130376636SRichard Henderson {
274230376636SRichard Henderson     if (avail_64(dc)) {
274330376636SRichard Henderson         return false;
274430376636SRichard Henderson     }
274530376636SRichard Henderson     return do_tcc(dc, a->cond, 0, a->rs1, true, a->i);
274630376636SRichard Henderson }
274730376636SRichard Henderson 
274830376636SRichard Henderson static bool trans_Tcc_i_v9(DisasContext *dc, arg_Tcc_i_v9 *a)
274930376636SRichard Henderson {
275030376636SRichard Henderson     if (avail_32(dc)) {
275130376636SRichard Henderson         return false;
275230376636SRichard Henderson     }
275330376636SRichard Henderson     return do_tcc(dc, a->cond, a->cc, a->rs1, true, a->i);
275430376636SRichard Henderson }
275530376636SRichard Henderson 
2756af25071cSRichard Henderson static bool trans_STBAR(DisasContext *dc, arg_STBAR *a)
2757af25071cSRichard Henderson {
2758af25071cSRichard Henderson     tcg_gen_mb(TCG_MO_ST_ST | TCG_BAR_SC);
2759af25071cSRichard Henderson     return advance_pc(dc);
2760af25071cSRichard Henderson }
2761af25071cSRichard Henderson 
2762af25071cSRichard Henderson static bool trans_MEMBAR(DisasContext *dc, arg_MEMBAR *a)
2763af25071cSRichard Henderson {
2764af25071cSRichard Henderson     if (avail_32(dc)) {
2765af25071cSRichard Henderson         return false;
2766af25071cSRichard Henderson     }
2767af25071cSRichard Henderson     if (a->mmask) {
2768af25071cSRichard Henderson         /* Note TCG_MO_* was modeled on sparc64, so mmask matches. */
2769af25071cSRichard Henderson         tcg_gen_mb(a->mmask | TCG_BAR_SC);
2770af25071cSRichard Henderson     }
2771af25071cSRichard Henderson     if (a->cmask) {
2772af25071cSRichard Henderson         /* For #Sync, etc, end the TB to recognize interrupts. */
2773af25071cSRichard Henderson         dc->base.is_jmp = DISAS_EXIT;
2774af25071cSRichard Henderson     }
2775af25071cSRichard Henderson     return advance_pc(dc);
2776af25071cSRichard Henderson }
2777af25071cSRichard Henderson 
2778af25071cSRichard Henderson static bool do_rd_special(DisasContext *dc, bool priv, int rd,
2779af25071cSRichard Henderson                           TCGv (*func)(DisasContext *, TCGv))
2780af25071cSRichard Henderson {
2781af25071cSRichard Henderson     if (!priv) {
2782af25071cSRichard Henderson         return raise_priv(dc);
2783af25071cSRichard Henderson     }
2784af25071cSRichard Henderson     gen_store_gpr(dc, rd, func(dc, gen_dest_gpr(dc, rd)));
2785af25071cSRichard Henderson     return advance_pc(dc);
2786af25071cSRichard Henderson }
2787af25071cSRichard Henderson 
2788af25071cSRichard Henderson static TCGv do_rdy(DisasContext *dc, TCGv dst)
2789af25071cSRichard Henderson {
2790af25071cSRichard Henderson     return cpu_y;
2791af25071cSRichard Henderson }
2792af25071cSRichard Henderson 
2793af25071cSRichard Henderson static bool trans_RDY(DisasContext *dc, arg_RDY *a)
2794af25071cSRichard Henderson {
2795af25071cSRichard Henderson     /*
2796af25071cSRichard Henderson      * TODO: Need a feature bit for sparcv8.  In the meantime, treat all
2797af25071cSRichard Henderson      * 32-bit cpus like sparcv7, which ignores the rs1 field.
2798af25071cSRichard Henderson      * This matches after all other ASR, so Leon3 Asr17 is handled first.
2799af25071cSRichard Henderson      */
2800af25071cSRichard Henderson     if (avail_64(dc) && a->rs1 != 0) {
2801af25071cSRichard Henderson         return false;
2802af25071cSRichard Henderson     }
2803af25071cSRichard Henderson     return do_rd_special(dc, true, a->rd, do_rdy);
2804af25071cSRichard Henderson }
2805af25071cSRichard Henderson 
2806af25071cSRichard Henderson static TCGv do_rd_leon3_config(DisasContext *dc, TCGv dst)
2807af25071cSRichard Henderson {
2808c92948f2SClément Chigot     gen_helper_rdasr17(dst, tcg_env);
2809c92948f2SClément Chigot     return dst;
2810af25071cSRichard Henderson }
2811af25071cSRichard Henderson 
2812af25071cSRichard Henderson TRANS(RDASR17, ASR17, do_rd_special, true, a->rd, do_rd_leon3_config)
2813af25071cSRichard Henderson 
2814af25071cSRichard Henderson static TCGv do_rdccr(DisasContext *dc, TCGv dst)
2815af25071cSRichard Henderson {
2816af25071cSRichard Henderson     gen_helper_rdccr(dst, tcg_env);
2817af25071cSRichard Henderson     return dst;
2818af25071cSRichard Henderson }
2819af25071cSRichard Henderson 
2820af25071cSRichard Henderson TRANS(RDCCR, 64, do_rd_special, true, a->rd, do_rdccr)
2821af25071cSRichard Henderson 
2822af25071cSRichard Henderson static TCGv do_rdasi(DisasContext *dc, TCGv dst)
2823af25071cSRichard Henderson {
2824af25071cSRichard Henderson #ifdef TARGET_SPARC64
2825af25071cSRichard Henderson     return tcg_constant_tl(dc->asi);
2826af25071cSRichard Henderson #else
2827af25071cSRichard Henderson     qemu_build_not_reached();
2828af25071cSRichard Henderson #endif
2829af25071cSRichard Henderson }
2830af25071cSRichard Henderson 
2831af25071cSRichard Henderson TRANS(RDASI, 64, do_rd_special, true, a->rd, do_rdasi)
2832af25071cSRichard Henderson 
2833af25071cSRichard Henderson static TCGv do_rdtick(DisasContext *dc, TCGv dst)
2834af25071cSRichard Henderson {
2835af25071cSRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
2836af25071cSRichard Henderson 
2837af25071cSRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(tick));
2838af25071cSRichard Henderson     if (translator_io_start(&dc->base)) {
2839af25071cSRichard Henderson         dc->base.is_jmp = DISAS_EXIT;
2840af25071cSRichard Henderson     }
2841af25071cSRichard Henderson     gen_helper_tick_get_count(dst, tcg_env, r_tickptr,
2842af25071cSRichard Henderson                               tcg_constant_i32(dc->mem_idx));
2843af25071cSRichard Henderson     return dst;
2844af25071cSRichard Henderson }
2845af25071cSRichard Henderson 
2846af25071cSRichard Henderson /* TODO: non-priv access only allowed when enabled. */
2847af25071cSRichard Henderson TRANS(RDTICK, 64, do_rd_special, true, a->rd, do_rdtick)
2848af25071cSRichard Henderson 
2849af25071cSRichard Henderson static TCGv do_rdpc(DisasContext *dc, TCGv dst)
2850af25071cSRichard Henderson {
2851af25071cSRichard Henderson     return tcg_constant_tl(address_mask_i(dc, dc->pc));
2852af25071cSRichard Henderson }
2853af25071cSRichard Henderson 
2854af25071cSRichard Henderson TRANS(RDPC, 64, do_rd_special, true, a->rd, do_rdpc)
2855af25071cSRichard Henderson 
2856af25071cSRichard Henderson static TCGv do_rdfprs(DisasContext *dc, TCGv dst)
2857af25071cSRichard Henderson {
2858af25071cSRichard Henderson     tcg_gen_ext_i32_tl(dst, cpu_fprs);
2859af25071cSRichard Henderson     return dst;
2860af25071cSRichard Henderson }
2861af25071cSRichard Henderson 
2862af25071cSRichard Henderson TRANS(RDFPRS, 64, do_rd_special, true, a->rd, do_rdfprs)
2863af25071cSRichard Henderson 
2864af25071cSRichard Henderson static TCGv do_rdgsr(DisasContext *dc, TCGv dst)
2865af25071cSRichard Henderson {
2866af25071cSRichard Henderson     gen_trap_ifnofpu(dc);
2867af25071cSRichard Henderson     return cpu_gsr;
2868af25071cSRichard Henderson }
2869af25071cSRichard Henderson 
2870af25071cSRichard Henderson TRANS(RDGSR, 64, do_rd_special, true, a->rd, do_rdgsr)
2871af25071cSRichard Henderson 
2872af25071cSRichard Henderson static TCGv do_rdsoftint(DisasContext *dc, TCGv dst)
2873af25071cSRichard Henderson {
2874af25071cSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(softint));
2875af25071cSRichard Henderson     return dst;
2876af25071cSRichard Henderson }
2877af25071cSRichard Henderson 
2878af25071cSRichard Henderson TRANS(RDSOFTINT, 64, do_rd_special, supervisor(dc), a->rd, do_rdsoftint)
2879af25071cSRichard Henderson 
2880af25071cSRichard Henderson static TCGv do_rdtick_cmpr(DisasContext *dc, TCGv dst)
2881af25071cSRichard Henderson {
2882577efa45SRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(tick_cmpr));
2883577efa45SRichard Henderson     return dst;
2884af25071cSRichard Henderson }
2885af25071cSRichard Henderson 
2886af25071cSRichard Henderson /* TODO: non-priv access only allowed when enabled. */
2887af25071cSRichard Henderson TRANS(RDTICK_CMPR, 64, do_rd_special, true, a->rd, do_rdtick_cmpr)
2888af25071cSRichard Henderson 
2889af25071cSRichard Henderson static TCGv do_rdstick(DisasContext *dc, TCGv dst)
2890af25071cSRichard Henderson {
2891af25071cSRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
2892af25071cSRichard Henderson 
2893af25071cSRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(stick));
2894af25071cSRichard Henderson     if (translator_io_start(&dc->base)) {
2895af25071cSRichard Henderson         dc->base.is_jmp = DISAS_EXIT;
2896af25071cSRichard Henderson     }
2897af25071cSRichard Henderson     gen_helper_tick_get_count(dst, tcg_env, r_tickptr,
2898af25071cSRichard Henderson                               tcg_constant_i32(dc->mem_idx));
2899af25071cSRichard Henderson     return dst;
2900af25071cSRichard Henderson }
2901af25071cSRichard Henderson 
2902af25071cSRichard Henderson /* TODO: non-priv access only allowed when enabled. */
2903af25071cSRichard Henderson TRANS(RDSTICK, 64, do_rd_special, true, a->rd, do_rdstick)
2904af25071cSRichard Henderson 
2905af25071cSRichard Henderson static TCGv do_rdstick_cmpr(DisasContext *dc, TCGv dst)
2906af25071cSRichard Henderson {
2907577efa45SRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(stick_cmpr));
2908577efa45SRichard Henderson     return dst;
2909af25071cSRichard Henderson }
2910af25071cSRichard Henderson 
2911af25071cSRichard Henderson /* TODO: supervisor access only allowed when enabled by hypervisor. */
2912af25071cSRichard Henderson TRANS(RDSTICK_CMPR, 64, do_rd_special, supervisor(dc), a->rd, do_rdstick_cmpr)
2913af25071cSRichard Henderson 
2914af25071cSRichard Henderson /*
2915af25071cSRichard Henderson  * UltraSPARC-T1 Strand status.
2916af25071cSRichard Henderson  * HYPV check maybe not enough, UA2005 & UA2007 describe
2917af25071cSRichard Henderson  * this ASR as impl. dep
2918af25071cSRichard Henderson  */
2919af25071cSRichard Henderson static TCGv do_rdstrand_status(DisasContext *dc, TCGv dst)
2920af25071cSRichard Henderson {
2921af25071cSRichard Henderson     return tcg_constant_tl(1);
2922af25071cSRichard Henderson }
2923af25071cSRichard Henderson 
2924af25071cSRichard Henderson TRANS(RDSTRAND_STATUS, HYPV, do_rd_special, true, a->rd, do_rdstrand_status)
2925af25071cSRichard Henderson 
2926668bb9b7SRichard Henderson static TCGv do_rdpsr(DisasContext *dc, TCGv dst)
2927668bb9b7SRichard Henderson {
2928668bb9b7SRichard Henderson     gen_helper_rdpsr(dst, tcg_env);
2929668bb9b7SRichard Henderson     return dst;
2930668bb9b7SRichard Henderson }
2931668bb9b7SRichard Henderson 
2932668bb9b7SRichard Henderson TRANS(RDPSR, 32, do_rd_special, supervisor(dc), a->rd, do_rdpsr)
2933668bb9b7SRichard Henderson 
2934668bb9b7SRichard Henderson static TCGv do_rdhpstate(DisasContext *dc, TCGv dst)
2935668bb9b7SRichard Henderson {
2936668bb9b7SRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hpstate));
2937668bb9b7SRichard Henderson     return dst;
2938668bb9b7SRichard Henderson }
2939668bb9b7SRichard Henderson 
2940668bb9b7SRichard Henderson TRANS(RDHPR_hpstate, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhpstate)
2941668bb9b7SRichard Henderson 
2942668bb9b7SRichard Henderson static TCGv do_rdhtstate(DisasContext *dc, TCGv dst)
2943668bb9b7SRichard Henderson {
2944668bb9b7SRichard Henderson     TCGv_i32 tl = tcg_temp_new_i32();
2945668bb9b7SRichard Henderson     TCGv_ptr tp = tcg_temp_new_ptr();
2946668bb9b7SRichard Henderson 
2947668bb9b7SRichard Henderson     tcg_gen_ld_i32(tl, tcg_env, env64_field_offsetof(tl));
2948668bb9b7SRichard Henderson     tcg_gen_andi_i32(tl, tl, MAXTL_MASK);
2949668bb9b7SRichard Henderson     tcg_gen_shli_i32(tl, tl, 3);
2950668bb9b7SRichard Henderson     tcg_gen_ext_i32_ptr(tp, tl);
2951668bb9b7SRichard Henderson     tcg_gen_add_ptr(tp, tp, tcg_env);
2952668bb9b7SRichard Henderson 
2953668bb9b7SRichard Henderson     tcg_gen_ld_tl(dst, tp, env64_field_offsetof(htstate));
2954668bb9b7SRichard Henderson     return dst;
2955668bb9b7SRichard Henderson }
2956668bb9b7SRichard Henderson 
2957668bb9b7SRichard Henderson TRANS(RDHPR_htstate, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhtstate)
2958668bb9b7SRichard Henderson 
2959668bb9b7SRichard Henderson static TCGv do_rdhintp(DisasContext *dc, TCGv dst)
2960668bb9b7SRichard Henderson {
29612da789deSRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hintp));
29622da789deSRichard Henderson     return dst;
2963668bb9b7SRichard Henderson }
2964668bb9b7SRichard Henderson 
2965668bb9b7SRichard Henderson TRANS(RDHPR_hintp, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhintp)
2966668bb9b7SRichard Henderson 
2967668bb9b7SRichard Henderson static TCGv do_rdhtba(DisasContext *dc, TCGv dst)
2968668bb9b7SRichard Henderson {
29692da789deSRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(htba));
29702da789deSRichard Henderson     return dst;
2971668bb9b7SRichard Henderson }
2972668bb9b7SRichard Henderson 
2973668bb9b7SRichard Henderson TRANS(RDHPR_htba, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhtba)
2974668bb9b7SRichard Henderson 
2975668bb9b7SRichard Henderson static TCGv do_rdhver(DisasContext *dc, TCGv dst)
2976668bb9b7SRichard Henderson {
29772da789deSRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hver));
29782da789deSRichard Henderson     return dst;
2979668bb9b7SRichard Henderson }
2980668bb9b7SRichard Henderson 
2981668bb9b7SRichard Henderson TRANS(RDHPR_hver, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhver)
2982668bb9b7SRichard Henderson 
2983668bb9b7SRichard Henderson static TCGv do_rdhstick_cmpr(DisasContext *dc, TCGv dst)
2984668bb9b7SRichard Henderson {
2985577efa45SRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hstick_cmpr));
2986577efa45SRichard Henderson     return dst;
2987668bb9b7SRichard Henderson }
2988668bb9b7SRichard Henderson 
2989668bb9b7SRichard Henderson TRANS(RDHPR_hstick_cmpr, HYPV, do_rd_special, hypervisor(dc), a->rd,
2990668bb9b7SRichard Henderson       do_rdhstick_cmpr)
2991668bb9b7SRichard Henderson 
29925d617bfbSRichard Henderson static TCGv do_rdwim(DisasContext *dc, TCGv dst)
29935d617bfbSRichard Henderson {
2994cd6269f7SRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env32_field_offsetof(wim));
2995cd6269f7SRichard Henderson     return dst;
29965d617bfbSRichard Henderson }
29975d617bfbSRichard Henderson 
29985d617bfbSRichard Henderson TRANS(RDWIM, 32, do_rd_special, supervisor(dc), a->rd, do_rdwim)
29995d617bfbSRichard Henderson 
30005d617bfbSRichard Henderson static TCGv do_rdtpc(DisasContext *dc, TCGv dst)
30015d617bfbSRichard Henderson {
30025d617bfbSRichard Henderson #ifdef TARGET_SPARC64
30035d617bfbSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
30045d617bfbSRichard Henderson 
30055d617bfbSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
30065d617bfbSRichard Henderson     tcg_gen_ld_tl(dst, r_tsptr, offsetof(trap_state, tpc));
30075d617bfbSRichard Henderson     return dst;
30085d617bfbSRichard Henderson #else
30095d617bfbSRichard Henderson     qemu_build_not_reached();
30105d617bfbSRichard Henderson #endif
30115d617bfbSRichard Henderson }
30125d617bfbSRichard Henderson 
30135d617bfbSRichard Henderson TRANS(RDPR_tpc, 64, do_rd_special, supervisor(dc), a->rd, do_rdtpc)
30145d617bfbSRichard Henderson 
30155d617bfbSRichard Henderson static TCGv do_rdtnpc(DisasContext *dc, TCGv dst)
30165d617bfbSRichard Henderson {
30175d617bfbSRichard Henderson #ifdef TARGET_SPARC64
30185d617bfbSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
30195d617bfbSRichard Henderson 
30205d617bfbSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
30215d617bfbSRichard Henderson     tcg_gen_ld_tl(dst, r_tsptr, offsetof(trap_state, tnpc));
30225d617bfbSRichard Henderson     return dst;
30235d617bfbSRichard Henderson #else
30245d617bfbSRichard Henderson     qemu_build_not_reached();
30255d617bfbSRichard Henderson #endif
30265d617bfbSRichard Henderson }
30275d617bfbSRichard Henderson 
30285d617bfbSRichard Henderson TRANS(RDPR_tnpc, 64, do_rd_special, supervisor(dc), a->rd, do_rdtnpc)
30295d617bfbSRichard Henderson 
30305d617bfbSRichard Henderson static TCGv do_rdtstate(DisasContext *dc, TCGv dst)
30315d617bfbSRichard Henderson {
30325d617bfbSRichard Henderson #ifdef TARGET_SPARC64
30335d617bfbSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
30345d617bfbSRichard Henderson 
30355d617bfbSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
30365d617bfbSRichard Henderson     tcg_gen_ld_tl(dst, r_tsptr, offsetof(trap_state, tstate));
30375d617bfbSRichard Henderson     return dst;
30385d617bfbSRichard Henderson #else
30395d617bfbSRichard Henderson     qemu_build_not_reached();
30405d617bfbSRichard Henderson #endif
30415d617bfbSRichard Henderson }
30425d617bfbSRichard Henderson 
30435d617bfbSRichard Henderson TRANS(RDPR_tstate, 64, do_rd_special, supervisor(dc), a->rd, do_rdtstate)
30445d617bfbSRichard Henderson 
30455d617bfbSRichard Henderson static TCGv do_rdtt(DisasContext *dc, TCGv dst)
30465d617bfbSRichard Henderson {
30475d617bfbSRichard Henderson #ifdef TARGET_SPARC64
30485d617bfbSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
30495d617bfbSRichard Henderson 
30505d617bfbSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
30515d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, r_tsptr, offsetof(trap_state, tt));
30525d617bfbSRichard Henderson     return dst;
30535d617bfbSRichard Henderson #else
30545d617bfbSRichard Henderson     qemu_build_not_reached();
30555d617bfbSRichard Henderson #endif
30565d617bfbSRichard Henderson }
30575d617bfbSRichard Henderson 
30585d617bfbSRichard Henderson TRANS(RDPR_tt, 64, do_rd_special, supervisor(dc), a->rd, do_rdtt)
30595d617bfbSRichard Henderson TRANS(RDPR_tick, 64, do_rd_special, supervisor(dc), a->rd, do_rdtick)
30605d617bfbSRichard Henderson 
30615d617bfbSRichard Henderson static TCGv do_rdtba(DisasContext *dc, TCGv dst)
30625d617bfbSRichard Henderson {
30635d617bfbSRichard Henderson     return cpu_tbr;
30645d617bfbSRichard Henderson }
30655d617bfbSRichard Henderson 
3066e8325dc0SRichard Henderson TRANS(RDTBR, 32, do_rd_special, supervisor(dc), a->rd, do_rdtba)
30675d617bfbSRichard Henderson TRANS(RDPR_tba, 64, do_rd_special, supervisor(dc), a->rd, do_rdtba)
30685d617bfbSRichard Henderson 
30695d617bfbSRichard Henderson static TCGv do_rdpstate(DisasContext *dc, TCGv dst)
30705d617bfbSRichard Henderson {
30715d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(pstate));
30725d617bfbSRichard Henderson     return dst;
30735d617bfbSRichard Henderson }
30745d617bfbSRichard Henderson 
30755d617bfbSRichard Henderson TRANS(RDPR_pstate, 64, do_rd_special, supervisor(dc), a->rd, do_rdpstate)
30765d617bfbSRichard Henderson 
30775d617bfbSRichard Henderson static TCGv do_rdtl(DisasContext *dc, TCGv dst)
30785d617bfbSRichard Henderson {
30795d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(tl));
30805d617bfbSRichard Henderson     return dst;
30815d617bfbSRichard Henderson }
30825d617bfbSRichard Henderson 
30835d617bfbSRichard Henderson TRANS(RDPR_tl, 64, do_rd_special, supervisor(dc), a->rd, do_rdtl)
30845d617bfbSRichard Henderson 
30855d617bfbSRichard Henderson static TCGv do_rdpil(DisasContext *dc, TCGv dst)
30865d617bfbSRichard Henderson {
30875d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env_field_offsetof(psrpil));
30885d617bfbSRichard Henderson     return dst;
30895d617bfbSRichard Henderson }
30905d617bfbSRichard Henderson 
30915d617bfbSRichard Henderson TRANS(RDPR_pil, 64, do_rd_special, supervisor(dc), a->rd, do_rdpil)
30925d617bfbSRichard Henderson 
30935d617bfbSRichard Henderson static TCGv do_rdcwp(DisasContext *dc, TCGv dst)
30945d617bfbSRichard Henderson {
30955d617bfbSRichard Henderson     gen_helper_rdcwp(dst, tcg_env);
30965d617bfbSRichard Henderson     return dst;
30975d617bfbSRichard Henderson }
30985d617bfbSRichard Henderson 
30995d617bfbSRichard Henderson TRANS(RDPR_cwp, 64, do_rd_special, supervisor(dc), a->rd, do_rdcwp)
31005d617bfbSRichard Henderson 
31015d617bfbSRichard Henderson static TCGv do_rdcansave(DisasContext *dc, TCGv dst)
31025d617bfbSRichard Henderson {
31035d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(cansave));
31045d617bfbSRichard Henderson     return dst;
31055d617bfbSRichard Henderson }
31065d617bfbSRichard Henderson 
31075d617bfbSRichard Henderson TRANS(RDPR_cansave, 64, do_rd_special, supervisor(dc), a->rd, do_rdcansave)
31085d617bfbSRichard Henderson 
31095d617bfbSRichard Henderson static TCGv do_rdcanrestore(DisasContext *dc, TCGv dst)
31105d617bfbSRichard Henderson {
31115d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(canrestore));
31125d617bfbSRichard Henderson     return dst;
31135d617bfbSRichard Henderson }
31145d617bfbSRichard Henderson 
31155d617bfbSRichard Henderson TRANS(RDPR_canrestore, 64, do_rd_special, supervisor(dc), a->rd,
31165d617bfbSRichard Henderson       do_rdcanrestore)
31175d617bfbSRichard Henderson 
31185d617bfbSRichard Henderson static TCGv do_rdcleanwin(DisasContext *dc, TCGv dst)
31195d617bfbSRichard Henderson {
31205d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(cleanwin));
31215d617bfbSRichard Henderson     return dst;
31225d617bfbSRichard Henderson }
31235d617bfbSRichard Henderson 
31245d617bfbSRichard Henderson TRANS(RDPR_cleanwin, 64, do_rd_special, supervisor(dc), a->rd, do_rdcleanwin)
31255d617bfbSRichard Henderson 
31265d617bfbSRichard Henderson static TCGv do_rdotherwin(DisasContext *dc, TCGv dst)
31275d617bfbSRichard Henderson {
31285d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(otherwin));
31295d617bfbSRichard Henderson     return dst;
31305d617bfbSRichard Henderson }
31315d617bfbSRichard Henderson 
31325d617bfbSRichard Henderson TRANS(RDPR_otherwin, 64, do_rd_special, supervisor(dc), a->rd, do_rdotherwin)
31335d617bfbSRichard Henderson 
31345d617bfbSRichard Henderson static TCGv do_rdwstate(DisasContext *dc, TCGv dst)
31355d617bfbSRichard Henderson {
31365d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(wstate));
31375d617bfbSRichard Henderson     return dst;
31385d617bfbSRichard Henderson }
31395d617bfbSRichard Henderson 
31405d617bfbSRichard Henderson TRANS(RDPR_wstate, 64, do_rd_special, supervisor(dc), a->rd, do_rdwstate)
31415d617bfbSRichard Henderson 
31425d617bfbSRichard Henderson static TCGv do_rdgl(DisasContext *dc, TCGv dst)
31435d617bfbSRichard Henderson {
31445d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(gl));
31455d617bfbSRichard Henderson     return dst;
31465d617bfbSRichard Henderson }
31475d617bfbSRichard Henderson 
31485d617bfbSRichard Henderson TRANS(RDPR_gl, GL, do_rd_special, supervisor(dc), a->rd, do_rdgl)
31495d617bfbSRichard Henderson 
31505d617bfbSRichard Henderson /* UA2005 strand status */
31515d617bfbSRichard Henderson static TCGv do_rdssr(DisasContext *dc, TCGv dst)
31525d617bfbSRichard Henderson {
31532da789deSRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(ssr));
31542da789deSRichard Henderson     return dst;
31555d617bfbSRichard Henderson }
31565d617bfbSRichard Henderson 
31575d617bfbSRichard Henderson TRANS(RDPR_strand_status, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdssr)
31585d617bfbSRichard Henderson 
31595d617bfbSRichard Henderson static TCGv do_rdver(DisasContext *dc, TCGv dst)
31605d617bfbSRichard Henderson {
31612da789deSRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(version));
31622da789deSRichard Henderson     return dst;
31635d617bfbSRichard Henderson }
31645d617bfbSRichard Henderson 
31655d617bfbSRichard Henderson TRANS(RDPR_ver, 64, do_rd_special, supervisor(dc), a->rd, do_rdver)
31665d617bfbSRichard Henderson 
3167e8325dc0SRichard Henderson static bool trans_FLUSHW(DisasContext *dc, arg_FLUSHW *a)
3168e8325dc0SRichard Henderson {
3169e8325dc0SRichard Henderson     if (avail_64(dc)) {
3170e8325dc0SRichard Henderson         gen_helper_flushw(tcg_env);
3171e8325dc0SRichard Henderson         return advance_pc(dc);
3172e8325dc0SRichard Henderson     }
3173e8325dc0SRichard Henderson     return false;
3174e8325dc0SRichard Henderson }
3175e8325dc0SRichard Henderson 
31760faef01bSRichard Henderson static bool do_wr_special(DisasContext *dc, arg_r_r_ri *a, bool priv,
31770faef01bSRichard Henderson                           void (*func)(DisasContext *, TCGv))
31780faef01bSRichard Henderson {
31790faef01bSRichard Henderson     TCGv src;
31800faef01bSRichard Henderson 
31810faef01bSRichard Henderson     /* For simplicity, we under-decoded the rs2 form. */
31820faef01bSRichard Henderson     if (!a->imm && (a->rs2_or_imm & ~0x1f)) {
31830faef01bSRichard Henderson         return false;
31840faef01bSRichard Henderson     }
31850faef01bSRichard Henderson     if (!priv) {
31860faef01bSRichard Henderson         return raise_priv(dc);
31870faef01bSRichard Henderson     }
31880faef01bSRichard Henderson 
31890faef01bSRichard Henderson     if (a->rs1 == 0 && (a->imm || a->rs2_or_imm == 0)) {
31900faef01bSRichard Henderson         src = tcg_constant_tl(a->rs2_or_imm);
31910faef01bSRichard Henderson     } else {
31920faef01bSRichard Henderson         TCGv src1 = gen_load_gpr(dc, a->rs1);
31930faef01bSRichard Henderson         if (a->rs2_or_imm == 0) {
31940faef01bSRichard Henderson             src = src1;
31950faef01bSRichard Henderson         } else {
31960faef01bSRichard Henderson             src = tcg_temp_new();
31970faef01bSRichard Henderson             if (a->imm) {
31980faef01bSRichard Henderson                 tcg_gen_xori_tl(src, src1, a->rs2_or_imm);
31990faef01bSRichard Henderson             } else {
32000faef01bSRichard Henderson                 tcg_gen_xor_tl(src, src1, gen_load_gpr(dc, a->rs2_or_imm));
32010faef01bSRichard Henderson             }
32020faef01bSRichard Henderson         }
32030faef01bSRichard Henderson     }
32040faef01bSRichard Henderson     func(dc, src);
32050faef01bSRichard Henderson     return advance_pc(dc);
32060faef01bSRichard Henderson }
32070faef01bSRichard Henderson 
32080faef01bSRichard Henderson static void do_wry(DisasContext *dc, TCGv src)
32090faef01bSRichard Henderson {
32100faef01bSRichard Henderson     tcg_gen_ext32u_tl(cpu_y, src);
32110faef01bSRichard Henderson }
32120faef01bSRichard Henderson 
32130faef01bSRichard Henderson TRANS(WRY, ALL, do_wr_special, a, true, do_wry)
32140faef01bSRichard Henderson 
32150faef01bSRichard Henderson static void do_wrccr(DisasContext *dc, TCGv src)
32160faef01bSRichard Henderson {
32170faef01bSRichard Henderson     gen_helper_wrccr(tcg_env, src);
32180faef01bSRichard Henderson }
32190faef01bSRichard Henderson 
32200faef01bSRichard Henderson TRANS(WRCCR, 64, do_wr_special, a, true, do_wrccr)
32210faef01bSRichard Henderson 
32220faef01bSRichard Henderson static void do_wrasi(DisasContext *dc, TCGv src)
32230faef01bSRichard Henderson {
32240faef01bSRichard Henderson     TCGv tmp = tcg_temp_new();
32250faef01bSRichard Henderson 
32260faef01bSRichard Henderson     tcg_gen_ext8u_tl(tmp, src);
32270faef01bSRichard Henderson     tcg_gen_st32_tl(tmp, tcg_env, env64_field_offsetof(asi));
32280faef01bSRichard Henderson     /* End TB to notice changed ASI. */
32290faef01bSRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
32300faef01bSRichard Henderson }
32310faef01bSRichard Henderson 
32320faef01bSRichard Henderson TRANS(WRASI, 64, do_wr_special, a, true, do_wrasi)
32330faef01bSRichard Henderson 
32340faef01bSRichard Henderson static void do_wrfprs(DisasContext *dc, TCGv src)
32350faef01bSRichard Henderson {
32360faef01bSRichard Henderson #ifdef TARGET_SPARC64
32370faef01bSRichard Henderson     tcg_gen_trunc_tl_i32(cpu_fprs, src);
32380faef01bSRichard Henderson     dc->fprs_dirty = 0;
32390faef01bSRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
32400faef01bSRichard Henderson #else
32410faef01bSRichard Henderson     qemu_build_not_reached();
32420faef01bSRichard Henderson #endif
32430faef01bSRichard Henderson }
32440faef01bSRichard Henderson 
32450faef01bSRichard Henderson TRANS(WRFPRS, 64, do_wr_special, a, true, do_wrfprs)
32460faef01bSRichard Henderson 
32470faef01bSRichard Henderson static void do_wrgsr(DisasContext *dc, TCGv src)
32480faef01bSRichard Henderson {
32490faef01bSRichard Henderson     gen_trap_ifnofpu(dc);
32500faef01bSRichard Henderson     tcg_gen_mov_tl(cpu_gsr, src);
32510faef01bSRichard Henderson }
32520faef01bSRichard Henderson 
32530faef01bSRichard Henderson TRANS(WRGSR, 64, do_wr_special, a, true, do_wrgsr)
32540faef01bSRichard Henderson 
32550faef01bSRichard Henderson static void do_wrsoftint_set(DisasContext *dc, TCGv src)
32560faef01bSRichard Henderson {
32570faef01bSRichard Henderson     gen_helper_set_softint(tcg_env, src);
32580faef01bSRichard Henderson }
32590faef01bSRichard Henderson 
32600faef01bSRichard Henderson TRANS(WRSOFTINT_SET, 64, do_wr_special, a, supervisor(dc), do_wrsoftint_set)
32610faef01bSRichard Henderson 
32620faef01bSRichard Henderson static void do_wrsoftint_clr(DisasContext *dc, TCGv src)
32630faef01bSRichard Henderson {
32640faef01bSRichard Henderson     gen_helper_clear_softint(tcg_env, src);
32650faef01bSRichard Henderson }
32660faef01bSRichard Henderson 
32670faef01bSRichard Henderson TRANS(WRSOFTINT_CLR, 64, do_wr_special, a, supervisor(dc), do_wrsoftint_clr)
32680faef01bSRichard Henderson 
32690faef01bSRichard Henderson static void do_wrsoftint(DisasContext *dc, TCGv src)
32700faef01bSRichard Henderson {
32710faef01bSRichard Henderson     gen_helper_write_softint(tcg_env, src);
32720faef01bSRichard Henderson }
32730faef01bSRichard Henderson 
32740faef01bSRichard Henderson TRANS(WRSOFTINT, 64, do_wr_special, a, supervisor(dc), do_wrsoftint)
32750faef01bSRichard Henderson 
32760faef01bSRichard Henderson static void do_wrtick_cmpr(DisasContext *dc, TCGv src)
32770faef01bSRichard Henderson {
32780faef01bSRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
32790faef01bSRichard Henderson 
3280577efa45SRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(tick_cmpr));
3281577efa45SRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(tick));
32820faef01bSRichard Henderson     translator_io_start(&dc->base);
3283577efa45SRichard Henderson     gen_helper_tick_set_limit(r_tickptr, src);
32840faef01bSRichard Henderson     /* End TB to handle timer interrupt */
32850faef01bSRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
32860faef01bSRichard Henderson }
32870faef01bSRichard Henderson 
32880faef01bSRichard Henderson TRANS(WRTICK_CMPR, 64, do_wr_special, a, supervisor(dc), do_wrtick_cmpr)
32890faef01bSRichard Henderson 
32900faef01bSRichard Henderson static void do_wrstick(DisasContext *dc, TCGv src)
32910faef01bSRichard Henderson {
32920faef01bSRichard Henderson #ifdef TARGET_SPARC64
32930faef01bSRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
32940faef01bSRichard Henderson 
32950faef01bSRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, offsetof(CPUSPARCState, stick));
32960faef01bSRichard Henderson     translator_io_start(&dc->base);
32970faef01bSRichard Henderson     gen_helper_tick_set_count(r_tickptr, src);
32980faef01bSRichard Henderson     /* End TB to handle timer interrupt */
32990faef01bSRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
33000faef01bSRichard Henderson #else
33010faef01bSRichard Henderson     qemu_build_not_reached();
33020faef01bSRichard Henderson #endif
33030faef01bSRichard Henderson }
33040faef01bSRichard Henderson 
33050faef01bSRichard Henderson TRANS(WRSTICK, 64, do_wr_special, a, supervisor(dc), do_wrstick)
33060faef01bSRichard Henderson 
33070faef01bSRichard Henderson static void do_wrstick_cmpr(DisasContext *dc, TCGv src)
33080faef01bSRichard Henderson {
33090faef01bSRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
33100faef01bSRichard Henderson 
3311577efa45SRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(stick_cmpr));
3312577efa45SRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(stick));
33130faef01bSRichard Henderson     translator_io_start(&dc->base);
3314577efa45SRichard Henderson     gen_helper_tick_set_limit(r_tickptr, src);
33150faef01bSRichard Henderson     /* End TB to handle timer interrupt */
33160faef01bSRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
33170faef01bSRichard Henderson }
33180faef01bSRichard Henderson 
33190faef01bSRichard Henderson TRANS(WRSTICK_CMPR, 64, do_wr_special, a, supervisor(dc), do_wrstick_cmpr)
33200faef01bSRichard Henderson 
33210faef01bSRichard Henderson static void do_wrpowerdown(DisasContext *dc, TCGv src)
33220faef01bSRichard Henderson {
332389527e3aSRichard Henderson     finishing_insn(dc);
33240faef01bSRichard Henderson     save_state(dc);
33250faef01bSRichard Henderson     gen_helper_power_down(tcg_env);
33260faef01bSRichard Henderson }
33270faef01bSRichard Henderson 
33280faef01bSRichard Henderson TRANS(WRPOWERDOWN, POWERDOWN, do_wr_special, a, supervisor(dc), do_wrpowerdown)
33290faef01bSRichard Henderson 
333025524734SRichard Henderson static void do_wrpsr(DisasContext *dc, TCGv src)
333125524734SRichard Henderson {
333225524734SRichard Henderson     gen_helper_wrpsr(tcg_env, src);
333325524734SRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
333425524734SRichard Henderson }
333525524734SRichard Henderson 
333625524734SRichard Henderson TRANS(WRPSR, 32, do_wr_special, a, supervisor(dc), do_wrpsr)
333725524734SRichard Henderson 
33389422278eSRichard Henderson static void do_wrwim(DisasContext *dc, TCGv src)
33399422278eSRichard Henderson {
33409422278eSRichard Henderson     target_ulong mask = MAKE_64BIT_MASK(0, dc->def->nwindows);
3341cd6269f7SRichard Henderson     TCGv tmp = tcg_temp_new();
3342cd6269f7SRichard Henderson 
3343cd6269f7SRichard Henderson     tcg_gen_andi_tl(tmp, src, mask);
3344cd6269f7SRichard Henderson     tcg_gen_st_tl(tmp, tcg_env, env32_field_offsetof(wim));
33459422278eSRichard Henderson }
33469422278eSRichard Henderson 
33479422278eSRichard Henderson TRANS(WRWIM, 32, do_wr_special, a, supervisor(dc), do_wrwim)
33489422278eSRichard Henderson 
33499422278eSRichard Henderson static void do_wrtpc(DisasContext *dc, TCGv src)
33509422278eSRichard Henderson {
33519422278eSRichard Henderson #ifdef TARGET_SPARC64
33529422278eSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
33539422278eSRichard Henderson 
33549422278eSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
33559422278eSRichard Henderson     tcg_gen_st_tl(src, r_tsptr, offsetof(trap_state, tpc));
33569422278eSRichard Henderson #else
33579422278eSRichard Henderson     qemu_build_not_reached();
33589422278eSRichard Henderson #endif
33599422278eSRichard Henderson }
33609422278eSRichard Henderson 
33619422278eSRichard Henderson TRANS(WRPR_tpc, 64, do_wr_special, a, supervisor(dc), do_wrtpc)
33629422278eSRichard Henderson 
33639422278eSRichard Henderson static void do_wrtnpc(DisasContext *dc, TCGv src)
33649422278eSRichard Henderson {
33659422278eSRichard Henderson #ifdef TARGET_SPARC64
33669422278eSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
33679422278eSRichard Henderson 
33689422278eSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
33699422278eSRichard Henderson     tcg_gen_st_tl(src, r_tsptr, offsetof(trap_state, tnpc));
33709422278eSRichard Henderson #else
33719422278eSRichard Henderson     qemu_build_not_reached();
33729422278eSRichard Henderson #endif
33739422278eSRichard Henderson }
33749422278eSRichard Henderson 
33759422278eSRichard Henderson TRANS(WRPR_tnpc, 64, do_wr_special, a, supervisor(dc), do_wrtnpc)
33769422278eSRichard Henderson 
33779422278eSRichard Henderson static void do_wrtstate(DisasContext *dc, TCGv src)
33789422278eSRichard Henderson {
33799422278eSRichard Henderson #ifdef TARGET_SPARC64
33809422278eSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
33819422278eSRichard Henderson 
33829422278eSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
33839422278eSRichard Henderson     tcg_gen_st_tl(src, r_tsptr, offsetof(trap_state, tstate));
33849422278eSRichard Henderson #else
33859422278eSRichard Henderson     qemu_build_not_reached();
33869422278eSRichard Henderson #endif
33879422278eSRichard Henderson }
33889422278eSRichard Henderson 
33899422278eSRichard Henderson TRANS(WRPR_tstate, 64, do_wr_special, a, supervisor(dc), do_wrtstate)
33909422278eSRichard Henderson 
33919422278eSRichard Henderson static void do_wrtt(DisasContext *dc, TCGv src)
33929422278eSRichard Henderson {
33939422278eSRichard Henderson #ifdef TARGET_SPARC64
33949422278eSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
33959422278eSRichard Henderson 
33969422278eSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
33979422278eSRichard Henderson     tcg_gen_st32_tl(src, r_tsptr, offsetof(trap_state, tt));
33989422278eSRichard Henderson #else
33999422278eSRichard Henderson     qemu_build_not_reached();
34009422278eSRichard Henderson #endif
34019422278eSRichard Henderson }
34029422278eSRichard Henderson 
34039422278eSRichard Henderson TRANS(WRPR_tt, 64, do_wr_special, a, supervisor(dc), do_wrtt)
34049422278eSRichard Henderson 
34059422278eSRichard Henderson static void do_wrtick(DisasContext *dc, TCGv src)
34069422278eSRichard Henderson {
34079422278eSRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
34089422278eSRichard Henderson 
34099422278eSRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(tick));
34109422278eSRichard Henderson     translator_io_start(&dc->base);
34119422278eSRichard Henderson     gen_helper_tick_set_count(r_tickptr, src);
34129422278eSRichard Henderson     /* End TB to handle timer interrupt */
34139422278eSRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
34149422278eSRichard Henderson }
34159422278eSRichard Henderson 
34169422278eSRichard Henderson TRANS(WRPR_tick, 64, do_wr_special, a, supervisor(dc), do_wrtick)
34179422278eSRichard Henderson 
34189422278eSRichard Henderson static void do_wrtba(DisasContext *dc, TCGv src)
34199422278eSRichard Henderson {
34209422278eSRichard Henderson     tcg_gen_mov_tl(cpu_tbr, src);
34219422278eSRichard Henderson }
34229422278eSRichard Henderson 
34239422278eSRichard Henderson TRANS(WRPR_tba, 64, do_wr_special, a, supervisor(dc), do_wrtba)
34249422278eSRichard Henderson 
34259422278eSRichard Henderson static void do_wrpstate(DisasContext *dc, TCGv src)
34269422278eSRichard Henderson {
34279422278eSRichard Henderson     save_state(dc);
34289422278eSRichard Henderson     if (translator_io_start(&dc->base)) {
34299422278eSRichard Henderson         dc->base.is_jmp = DISAS_EXIT;
34309422278eSRichard Henderson     }
34319422278eSRichard Henderson     gen_helper_wrpstate(tcg_env, src);
34329422278eSRichard Henderson     dc->npc = DYNAMIC_PC;
34339422278eSRichard Henderson }
34349422278eSRichard Henderson 
34359422278eSRichard Henderson TRANS(WRPR_pstate, 64, do_wr_special, a, supervisor(dc), do_wrpstate)
34369422278eSRichard Henderson 
34379422278eSRichard Henderson static void do_wrtl(DisasContext *dc, TCGv src)
34389422278eSRichard Henderson {
34399422278eSRichard Henderson     save_state(dc);
34409422278eSRichard Henderson     tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(tl));
34419422278eSRichard Henderson     dc->npc = DYNAMIC_PC;
34429422278eSRichard Henderson }
34439422278eSRichard Henderson 
34449422278eSRichard Henderson TRANS(WRPR_tl, 64, do_wr_special, a, supervisor(dc), do_wrtl)
34459422278eSRichard Henderson 
34469422278eSRichard Henderson static void do_wrpil(DisasContext *dc, TCGv src)
34479422278eSRichard Henderson {
34489422278eSRichard Henderson     if (translator_io_start(&dc->base)) {
34499422278eSRichard Henderson         dc->base.is_jmp = DISAS_EXIT;
34509422278eSRichard Henderson     }
34519422278eSRichard Henderson     gen_helper_wrpil(tcg_env, src);
34529422278eSRichard Henderson }
34539422278eSRichard Henderson 
34549422278eSRichard Henderson TRANS(WRPR_pil, 64, do_wr_special, a, supervisor(dc), do_wrpil)
34559422278eSRichard Henderson 
34569422278eSRichard Henderson static void do_wrcwp(DisasContext *dc, TCGv src)
34579422278eSRichard Henderson {
34589422278eSRichard Henderson     gen_helper_wrcwp(tcg_env, src);
34599422278eSRichard Henderson }
34609422278eSRichard Henderson 
34619422278eSRichard Henderson TRANS(WRPR_cwp, 64, do_wr_special, a, supervisor(dc), do_wrcwp)
34629422278eSRichard Henderson 
34639422278eSRichard Henderson static void do_wrcansave(DisasContext *dc, TCGv src)
34649422278eSRichard Henderson {
34659422278eSRichard Henderson     tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(cansave));
34669422278eSRichard Henderson }
34679422278eSRichard Henderson 
34689422278eSRichard Henderson TRANS(WRPR_cansave, 64, do_wr_special, a, supervisor(dc), do_wrcansave)
34699422278eSRichard Henderson 
34709422278eSRichard Henderson static void do_wrcanrestore(DisasContext *dc, TCGv src)
34719422278eSRichard Henderson {
34729422278eSRichard Henderson     tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(canrestore));
34739422278eSRichard Henderson }
34749422278eSRichard Henderson 
34759422278eSRichard Henderson TRANS(WRPR_canrestore, 64, do_wr_special, a, supervisor(dc), do_wrcanrestore)
34769422278eSRichard Henderson 
34779422278eSRichard Henderson static void do_wrcleanwin(DisasContext *dc, TCGv src)
34789422278eSRichard Henderson {
34799422278eSRichard Henderson     tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(cleanwin));
34809422278eSRichard Henderson }
34819422278eSRichard Henderson 
34829422278eSRichard Henderson TRANS(WRPR_cleanwin, 64, do_wr_special, a, supervisor(dc), do_wrcleanwin)
34839422278eSRichard Henderson 
34849422278eSRichard Henderson static void do_wrotherwin(DisasContext *dc, TCGv src)
34859422278eSRichard Henderson {
34869422278eSRichard Henderson     tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(otherwin));
34879422278eSRichard Henderson }
34889422278eSRichard Henderson 
34899422278eSRichard Henderson TRANS(WRPR_otherwin, 64, do_wr_special, a, supervisor(dc), do_wrotherwin)
34909422278eSRichard Henderson 
34919422278eSRichard Henderson static void do_wrwstate(DisasContext *dc, TCGv src)
34929422278eSRichard Henderson {
34939422278eSRichard Henderson     tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(wstate));
34949422278eSRichard Henderson }
34959422278eSRichard Henderson 
34969422278eSRichard Henderson TRANS(WRPR_wstate, 64, do_wr_special, a, supervisor(dc), do_wrwstate)
34979422278eSRichard Henderson 
34989422278eSRichard Henderson static void do_wrgl(DisasContext *dc, TCGv src)
34999422278eSRichard Henderson {
35009422278eSRichard Henderson     gen_helper_wrgl(tcg_env, src);
35019422278eSRichard Henderson }
35029422278eSRichard Henderson 
35039422278eSRichard Henderson TRANS(WRPR_gl, GL, do_wr_special, a, supervisor(dc), do_wrgl)
35049422278eSRichard Henderson 
35059422278eSRichard Henderson /* UA2005 strand status */
35069422278eSRichard Henderson static void do_wrssr(DisasContext *dc, TCGv src)
35079422278eSRichard Henderson {
35082da789deSRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(ssr));
35099422278eSRichard Henderson }
35109422278eSRichard Henderson 
35119422278eSRichard Henderson TRANS(WRPR_strand_status, HYPV, do_wr_special, a, hypervisor(dc), do_wrssr)
35129422278eSRichard Henderson 
3513bb97f2f5SRichard Henderson TRANS(WRTBR, 32, do_wr_special, a, supervisor(dc), do_wrtba)
3514bb97f2f5SRichard Henderson 
3515bb97f2f5SRichard Henderson static void do_wrhpstate(DisasContext *dc, TCGv src)
3516bb97f2f5SRichard Henderson {
3517bb97f2f5SRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(hpstate));
3518bb97f2f5SRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
3519bb97f2f5SRichard Henderson }
3520bb97f2f5SRichard Henderson 
3521bb97f2f5SRichard Henderson TRANS(WRHPR_hpstate, HYPV, do_wr_special, a, hypervisor(dc), do_wrhpstate)
3522bb97f2f5SRichard Henderson 
3523bb97f2f5SRichard Henderson static void do_wrhtstate(DisasContext *dc, TCGv src)
3524bb97f2f5SRichard Henderson {
3525bb97f2f5SRichard Henderson     TCGv_i32 tl = tcg_temp_new_i32();
3526bb97f2f5SRichard Henderson     TCGv_ptr tp = tcg_temp_new_ptr();
3527bb97f2f5SRichard Henderson 
3528bb97f2f5SRichard Henderson     tcg_gen_ld_i32(tl, tcg_env, env64_field_offsetof(tl));
3529bb97f2f5SRichard Henderson     tcg_gen_andi_i32(tl, tl, MAXTL_MASK);
3530bb97f2f5SRichard Henderson     tcg_gen_shli_i32(tl, tl, 3);
3531bb97f2f5SRichard Henderson     tcg_gen_ext_i32_ptr(tp, tl);
3532bb97f2f5SRichard Henderson     tcg_gen_add_ptr(tp, tp, tcg_env);
3533bb97f2f5SRichard Henderson 
3534bb97f2f5SRichard Henderson     tcg_gen_st_tl(src, tp, env64_field_offsetof(htstate));
3535bb97f2f5SRichard Henderson }
3536bb97f2f5SRichard Henderson 
3537bb97f2f5SRichard Henderson TRANS(WRHPR_htstate, HYPV, do_wr_special, a, hypervisor(dc), do_wrhtstate)
3538bb97f2f5SRichard Henderson 
3539bb97f2f5SRichard Henderson static void do_wrhintp(DisasContext *dc, TCGv src)
3540bb97f2f5SRichard Henderson {
35412da789deSRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(hintp));
3542bb97f2f5SRichard Henderson }
3543bb97f2f5SRichard Henderson 
3544bb97f2f5SRichard Henderson TRANS(WRHPR_hintp, HYPV, do_wr_special, a, hypervisor(dc), do_wrhintp)
3545bb97f2f5SRichard Henderson 
3546bb97f2f5SRichard Henderson static void do_wrhtba(DisasContext *dc, TCGv src)
3547bb97f2f5SRichard Henderson {
35482da789deSRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(htba));
3549bb97f2f5SRichard Henderson }
3550bb97f2f5SRichard Henderson 
3551bb97f2f5SRichard Henderson TRANS(WRHPR_htba, HYPV, do_wr_special, a, hypervisor(dc), do_wrhtba)
3552bb97f2f5SRichard Henderson 
3553bb97f2f5SRichard Henderson static void do_wrhstick_cmpr(DisasContext *dc, TCGv src)
3554bb97f2f5SRichard Henderson {
3555bb97f2f5SRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
3556bb97f2f5SRichard Henderson 
3557577efa45SRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(hstick_cmpr));
3558bb97f2f5SRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(hstick));
3559bb97f2f5SRichard Henderson     translator_io_start(&dc->base);
3560577efa45SRichard Henderson     gen_helper_tick_set_limit(r_tickptr, src);
3561bb97f2f5SRichard Henderson     /* End TB to handle timer interrupt */
3562bb97f2f5SRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
3563bb97f2f5SRichard Henderson }
3564bb97f2f5SRichard Henderson 
3565bb97f2f5SRichard Henderson TRANS(WRHPR_hstick_cmpr, HYPV, do_wr_special, a, hypervisor(dc),
3566bb97f2f5SRichard Henderson       do_wrhstick_cmpr)
3567bb97f2f5SRichard Henderson 
356825524734SRichard Henderson static bool do_saved_restored(DisasContext *dc, bool saved)
356925524734SRichard Henderson {
357025524734SRichard Henderson     if (!supervisor(dc)) {
357125524734SRichard Henderson         return raise_priv(dc);
357225524734SRichard Henderson     }
357325524734SRichard Henderson     if (saved) {
357425524734SRichard Henderson         gen_helper_saved(tcg_env);
357525524734SRichard Henderson     } else {
357625524734SRichard Henderson         gen_helper_restored(tcg_env);
357725524734SRichard Henderson     }
357825524734SRichard Henderson     return advance_pc(dc);
357925524734SRichard Henderson }
358025524734SRichard Henderson 
358125524734SRichard Henderson TRANS(SAVED, 64, do_saved_restored, true)
358225524734SRichard Henderson TRANS(RESTORED, 64, do_saved_restored, false)
358325524734SRichard Henderson 
3584d3825800SRichard Henderson static bool trans_NOP(DisasContext *dc, arg_NOP *a)
3585d3825800SRichard Henderson {
3586d3825800SRichard Henderson     return advance_pc(dc);
3587d3825800SRichard Henderson }
3588d3825800SRichard Henderson 
35890faef01bSRichard Henderson /*
35900faef01bSRichard Henderson  * TODO: Need a feature bit for sparcv8.
35910faef01bSRichard Henderson  * In the meantime, treat all 32-bit cpus like sparcv7.
35920faef01bSRichard Henderson  */
35935458fd31SRichard Henderson TRANS(NOP_v7, 32, trans_NOP, a)
35945458fd31SRichard Henderson TRANS(NOP_v9, 64, trans_NOP, a)
35950faef01bSRichard Henderson 
3596b597eedcSRichard Henderson static bool do_arith_int(DisasContext *dc, arg_r_r_ri_cc *a,
3597428881deSRichard Henderson                          void (*func)(TCGv, TCGv, TCGv),
35982a45b736SRichard Henderson                          void (*funci)(TCGv, TCGv, target_long),
35992a45b736SRichard Henderson                          bool logic_cc)
3600428881deSRichard Henderson {
3601428881deSRichard Henderson     TCGv dst, src1;
3602428881deSRichard Henderson 
3603428881deSRichard Henderson     /* For simplicity, we under-decoded the rs2 form. */
3604428881deSRichard Henderson     if (!a->imm && a->rs2_or_imm & ~0x1f) {
3605428881deSRichard Henderson         return false;
3606428881deSRichard Henderson     }
3607428881deSRichard Henderson 
36082a45b736SRichard Henderson     if (logic_cc) {
36092a45b736SRichard Henderson         dst = cpu_cc_N;
3610428881deSRichard Henderson     } else {
3611428881deSRichard Henderson         dst = gen_dest_gpr(dc, a->rd);
3612428881deSRichard Henderson     }
3613428881deSRichard Henderson     src1 = gen_load_gpr(dc, a->rs1);
3614428881deSRichard Henderson 
3615428881deSRichard Henderson     if (a->imm || a->rs2_or_imm == 0) {
3616428881deSRichard Henderson         if (funci) {
3617428881deSRichard Henderson             funci(dst, src1, a->rs2_or_imm);
3618428881deSRichard Henderson         } else {
3619428881deSRichard Henderson             func(dst, src1, tcg_constant_tl(a->rs2_or_imm));
3620428881deSRichard Henderson         }
3621428881deSRichard Henderson     } else {
3622428881deSRichard Henderson         func(dst, src1, cpu_regs[a->rs2_or_imm]);
3623428881deSRichard Henderson     }
36242a45b736SRichard Henderson 
36252a45b736SRichard Henderson     if (logic_cc) {
36262a45b736SRichard Henderson         if (TARGET_LONG_BITS == 64) {
36272a45b736SRichard Henderson             tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N);
36282a45b736SRichard Henderson             tcg_gen_movi_tl(cpu_icc_C, 0);
36292a45b736SRichard Henderson         }
36302a45b736SRichard Henderson         tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N);
36312a45b736SRichard Henderson         tcg_gen_movi_tl(cpu_cc_C, 0);
36322a45b736SRichard Henderson         tcg_gen_movi_tl(cpu_cc_V, 0);
36332a45b736SRichard Henderson     }
36342a45b736SRichard Henderson 
3635428881deSRichard Henderson     gen_store_gpr(dc, a->rd, dst);
3636428881deSRichard Henderson     return advance_pc(dc);
3637428881deSRichard Henderson }
3638428881deSRichard Henderson 
3639b597eedcSRichard Henderson static bool do_arith(DisasContext *dc, arg_r_r_ri_cc *a,
3640428881deSRichard Henderson                      void (*func)(TCGv, TCGv, TCGv),
3641428881deSRichard Henderson                      void (*funci)(TCGv, TCGv, target_long),
3642428881deSRichard Henderson                      void (*func_cc)(TCGv, TCGv, TCGv))
3643428881deSRichard Henderson {
3644428881deSRichard Henderson     if (a->cc) {
3645b597eedcSRichard Henderson         return do_arith_int(dc, a, func_cc, NULL, false);
3646428881deSRichard Henderson     }
3647b597eedcSRichard Henderson     return do_arith_int(dc, a, func, funci, false);
3648428881deSRichard Henderson }
3649428881deSRichard Henderson 
3650428881deSRichard Henderson static bool do_logic(DisasContext *dc, arg_r_r_ri_cc *a,
3651428881deSRichard Henderson                      void (*func)(TCGv, TCGv, TCGv),
3652428881deSRichard Henderson                      void (*funci)(TCGv, TCGv, target_long))
3653428881deSRichard Henderson {
3654b597eedcSRichard Henderson     return do_arith_int(dc, a, func, funci, a->cc);
3655428881deSRichard Henderson }
3656428881deSRichard Henderson 
3657b597eedcSRichard Henderson TRANS(ADD, ALL, do_arith, a, tcg_gen_add_tl, tcg_gen_addi_tl, gen_op_addcc)
3658b597eedcSRichard Henderson TRANS(SUB, ALL, do_arith, a, tcg_gen_sub_tl, tcg_gen_subi_tl, gen_op_subcc)
3659b597eedcSRichard Henderson TRANS(ADDC, ALL, do_arith, a, gen_op_addc, NULL, gen_op_addccc)
3660b597eedcSRichard Henderson TRANS(SUBC, ALL, do_arith, a, gen_op_subc, NULL, gen_op_subccc)
3661428881deSRichard Henderson 
3662b597eedcSRichard Henderson TRANS(TADDcc, ALL, do_arith, a, NULL, NULL, gen_op_taddcc)
3663b597eedcSRichard Henderson TRANS(TSUBcc, ALL, do_arith, a, NULL, NULL, gen_op_tsubcc)
3664b597eedcSRichard Henderson TRANS(TADDccTV, ALL, do_arith, a, NULL, NULL, gen_op_taddcctv)
3665b597eedcSRichard Henderson TRANS(TSUBccTV, ALL, do_arith, a, NULL, NULL, gen_op_tsubcctv)
3666a9aba13dSRichard Henderson 
3667428881deSRichard Henderson TRANS(AND, ALL, do_logic, a, tcg_gen_and_tl, tcg_gen_andi_tl)
3668428881deSRichard Henderson TRANS(XOR, ALL, do_logic, a, tcg_gen_xor_tl, tcg_gen_xori_tl)
3669428881deSRichard Henderson TRANS(ANDN, ALL, do_logic, a, tcg_gen_andc_tl, NULL)
3670428881deSRichard Henderson TRANS(ORN, ALL, do_logic, a, tcg_gen_orc_tl, NULL)
3671428881deSRichard Henderson TRANS(XORN, ALL, do_logic, a, tcg_gen_eqv_tl, NULL)
3672428881deSRichard Henderson 
3673b597eedcSRichard Henderson TRANS(MULX, 64, do_arith, a, tcg_gen_mul_tl, tcg_gen_muli_tl, NULL)
3674b5372650SRichard Henderson TRANS(UMUL, MUL, do_logic, a, gen_op_umul, NULL)
3675b5372650SRichard Henderson TRANS(SMUL, MUL, do_logic, a, gen_op_smul, NULL)
3676b597eedcSRichard Henderson TRANS(MULScc, ALL, do_arith, a, NULL, NULL, gen_op_mulscc)
367722188d7dSRichard Henderson 
36783a6b8de3SRichard Henderson TRANS(UDIVcc, DIV, do_arith, a, NULL, NULL, gen_op_udivcc)
3679b597eedcSRichard Henderson TRANS(SDIV, DIV, do_arith, a, gen_op_sdiv, NULL, gen_op_sdivcc)
36804ee85ea9SRichard Henderson 
36819c6ec5bcSRichard Henderson /* TODO: Should have feature bit -- comes in with UltraSparc T2. */
3682b597eedcSRichard Henderson TRANS(POPC, 64, do_arith, a, gen_op_popc, NULL, NULL)
36839c6ec5bcSRichard Henderson 
3684428881deSRichard Henderson static bool trans_OR(DisasContext *dc, arg_r_r_ri_cc *a)
3685428881deSRichard Henderson {
3686428881deSRichard Henderson     /* OR with %g0 is the canonical alias for MOV. */
3687428881deSRichard Henderson     if (!a->cc && a->rs1 == 0) {
3688428881deSRichard Henderson         if (a->imm || a->rs2_or_imm == 0) {
3689428881deSRichard Henderson             gen_store_gpr(dc, a->rd, tcg_constant_tl(a->rs2_or_imm));
3690428881deSRichard Henderson         } else if (a->rs2_or_imm & ~0x1f) {
3691428881deSRichard Henderson             /* For simplicity, we under-decoded the rs2 form. */
3692428881deSRichard Henderson             return false;
3693428881deSRichard Henderson         } else {
3694428881deSRichard Henderson             gen_store_gpr(dc, a->rd, cpu_regs[a->rs2_or_imm]);
3695428881deSRichard Henderson         }
3696428881deSRichard Henderson         return advance_pc(dc);
3697428881deSRichard Henderson     }
3698428881deSRichard Henderson     return do_logic(dc, a, tcg_gen_or_tl, tcg_gen_ori_tl);
3699428881deSRichard Henderson }
3700428881deSRichard Henderson 
37013a6b8de3SRichard Henderson static bool trans_UDIV(DisasContext *dc, arg_r_r_ri *a)
37023a6b8de3SRichard Henderson {
37033a6b8de3SRichard Henderson     TCGv_i64 t1, t2;
37043a6b8de3SRichard Henderson     TCGv dst;
37053a6b8de3SRichard Henderson 
37063a6b8de3SRichard Henderson     if (!avail_DIV(dc)) {
37073a6b8de3SRichard Henderson         return false;
37083a6b8de3SRichard Henderson     }
37093a6b8de3SRichard Henderson     /* For simplicity, we under-decoded the rs2 form. */
37103a6b8de3SRichard Henderson     if (!a->imm && a->rs2_or_imm & ~0x1f) {
37113a6b8de3SRichard Henderson         return false;
37123a6b8de3SRichard Henderson     }
37133a6b8de3SRichard Henderson 
37143a6b8de3SRichard Henderson     if (unlikely(a->rs2_or_imm == 0)) {
37153a6b8de3SRichard Henderson         gen_exception(dc, TT_DIV_ZERO);
37163a6b8de3SRichard Henderson         return true;
37173a6b8de3SRichard Henderson     }
37183a6b8de3SRichard Henderson 
37193a6b8de3SRichard Henderson     if (a->imm) {
37203a6b8de3SRichard Henderson         t2 = tcg_constant_i64((uint32_t)a->rs2_or_imm);
37213a6b8de3SRichard Henderson     } else {
37223a6b8de3SRichard Henderson         TCGLabel *lab;
37233a6b8de3SRichard Henderson         TCGv_i32 n2;
37243a6b8de3SRichard Henderson 
37253a6b8de3SRichard Henderson         finishing_insn(dc);
37263a6b8de3SRichard Henderson         flush_cond(dc);
37273a6b8de3SRichard Henderson 
37283a6b8de3SRichard Henderson         n2 = tcg_temp_new_i32();
37293a6b8de3SRichard Henderson         tcg_gen_trunc_tl_i32(n2, cpu_regs[a->rs2_or_imm]);
37303a6b8de3SRichard Henderson 
37313a6b8de3SRichard Henderson         lab = delay_exception(dc, TT_DIV_ZERO);
37323a6b8de3SRichard Henderson         tcg_gen_brcondi_i32(TCG_COND_EQ, n2, 0, lab);
37333a6b8de3SRichard Henderson 
37343a6b8de3SRichard Henderson         t2 = tcg_temp_new_i64();
37353a6b8de3SRichard Henderson #ifdef TARGET_SPARC64
37363a6b8de3SRichard Henderson         tcg_gen_ext32u_i64(t2, cpu_regs[a->rs2_or_imm]);
37373a6b8de3SRichard Henderson #else
37383a6b8de3SRichard Henderson         tcg_gen_extu_i32_i64(t2, cpu_regs[a->rs2_or_imm]);
37393a6b8de3SRichard Henderson #endif
37403a6b8de3SRichard Henderson     }
37413a6b8de3SRichard Henderson 
37423a6b8de3SRichard Henderson     t1 = tcg_temp_new_i64();
37433a6b8de3SRichard Henderson     tcg_gen_concat_tl_i64(t1, gen_load_gpr(dc, a->rs1), cpu_y);
37443a6b8de3SRichard Henderson 
37453a6b8de3SRichard Henderson     tcg_gen_divu_i64(t1, t1, t2);
37463a6b8de3SRichard Henderson     tcg_gen_umin_i64(t1, t1, tcg_constant_i64(UINT32_MAX));
37473a6b8de3SRichard Henderson 
37483a6b8de3SRichard Henderson     dst = gen_dest_gpr(dc, a->rd);
37493a6b8de3SRichard Henderson     tcg_gen_trunc_i64_tl(dst, t1);
37503a6b8de3SRichard Henderson     gen_store_gpr(dc, a->rd, dst);
37513a6b8de3SRichard Henderson     return advance_pc(dc);
37523a6b8de3SRichard Henderson }
37533a6b8de3SRichard Henderson 
3754f3141174SRichard Henderson static bool trans_UDIVX(DisasContext *dc, arg_r_r_ri *a)
3755f3141174SRichard Henderson {
3756f3141174SRichard Henderson     TCGv dst, src1, src2;
3757f3141174SRichard Henderson 
3758f3141174SRichard Henderson     if (!avail_64(dc)) {
3759f3141174SRichard Henderson         return false;
3760f3141174SRichard Henderson     }
3761f3141174SRichard Henderson     /* For simplicity, we under-decoded the rs2 form. */
3762f3141174SRichard Henderson     if (!a->imm && a->rs2_or_imm & ~0x1f) {
3763f3141174SRichard Henderson         return false;
3764f3141174SRichard Henderson     }
3765f3141174SRichard Henderson 
3766f3141174SRichard Henderson     if (unlikely(a->rs2_or_imm == 0)) {
3767f3141174SRichard Henderson         gen_exception(dc, TT_DIV_ZERO);
3768f3141174SRichard Henderson         return true;
3769f3141174SRichard Henderson     }
3770f3141174SRichard Henderson 
3771f3141174SRichard Henderson     if (a->imm) {
3772f3141174SRichard Henderson         src2 = tcg_constant_tl(a->rs2_or_imm);
3773f3141174SRichard Henderson     } else {
3774f3141174SRichard Henderson         TCGLabel *lab;
3775f3141174SRichard Henderson 
3776f3141174SRichard Henderson         finishing_insn(dc);
3777f3141174SRichard Henderson         flush_cond(dc);
3778f3141174SRichard Henderson 
3779f3141174SRichard Henderson         lab = delay_exception(dc, TT_DIV_ZERO);
3780f3141174SRichard Henderson         src2 = cpu_regs[a->rs2_or_imm];
3781f3141174SRichard Henderson         tcg_gen_brcondi_tl(TCG_COND_EQ, src2, 0, lab);
3782f3141174SRichard Henderson     }
3783f3141174SRichard Henderson 
3784f3141174SRichard Henderson     dst = gen_dest_gpr(dc, a->rd);
3785f3141174SRichard Henderson     src1 = gen_load_gpr(dc, a->rs1);
3786f3141174SRichard Henderson 
3787f3141174SRichard Henderson     tcg_gen_divu_tl(dst, src1, src2);
3788f3141174SRichard Henderson     gen_store_gpr(dc, a->rd, dst);
3789f3141174SRichard Henderson     return advance_pc(dc);
3790f3141174SRichard Henderson }
3791f3141174SRichard Henderson 
3792f3141174SRichard Henderson static bool trans_SDIVX(DisasContext *dc, arg_r_r_ri *a)
3793f3141174SRichard Henderson {
3794f3141174SRichard Henderson     TCGv dst, src1, src2;
3795f3141174SRichard Henderson 
3796f3141174SRichard Henderson     if (!avail_64(dc)) {
3797f3141174SRichard Henderson         return false;
3798f3141174SRichard Henderson     }
3799f3141174SRichard Henderson     /* For simplicity, we under-decoded the rs2 form. */
3800f3141174SRichard Henderson     if (!a->imm && a->rs2_or_imm & ~0x1f) {
3801f3141174SRichard Henderson         return false;
3802f3141174SRichard Henderson     }
3803f3141174SRichard Henderson 
3804f3141174SRichard Henderson     if (unlikely(a->rs2_or_imm == 0)) {
3805f3141174SRichard Henderson         gen_exception(dc, TT_DIV_ZERO);
3806f3141174SRichard Henderson         return true;
3807f3141174SRichard Henderson     }
3808f3141174SRichard Henderson 
3809f3141174SRichard Henderson     dst = gen_dest_gpr(dc, a->rd);
3810f3141174SRichard Henderson     src1 = gen_load_gpr(dc, a->rs1);
3811f3141174SRichard Henderson 
3812f3141174SRichard Henderson     if (a->imm) {
3813f3141174SRichard Henderson         if (unlikely(a->rs2_or_imm == -1)) {
3814f3141174SRichard Henderson             tcg_gen_neg_tl(dst, src1);
3815f3141174SRichard Henderson             gen_store_gpr(dc, a->rd, dst);
3816f3141174SRichard Henderson             return advance_pc(dc);
3817f3141174SRichard Henderson         }
3818f3141174SRichard Henderson         src2 = tcg_constant_tl(a->rs2_or_imm);
3819f3141174SRichard Henderson     } else {
3820f3141174SRichard Henderson         TCGLabel *lab;
3821f3141174SRichard Henderson         TCGv t1, t2;
3822f3141174SRichard Henderson 
3823f3141174SRichard Henderson         finishing_insn(dc);
3824f3141174SRichard Henderson         flush_cond(dc);
3825f3141174SRichard Henderson 
3826f3141174SRichard Henderson         lab = delay_exception(dc, TT_DIV_ZERO);
3827f3141174SRichard Henderson         src2 = cpu_regs[a->rs2_or_imm];
3828f3141174SRichard Henderson         tcg_gen_brcondi_tl(TCG_COND_EQ, src2, 0, lab);
3829f3141174SRichard Henderson 
3830f3141174SRichard Henderson         /*
3831f3141174SRichard Henderson          * Need to avoid INT64_MIN / -1, which will trap on x86 host.
3832f3141174SRichard Henderson          * Set SRC2 to 1 as a new divisor, to produce the correct result.
3833f3141174SRichard Henderson          */
3834f3141174SRichard Henderson         t1 = tcg_temp_new();
3835f3141174SRichard Henderson         t2 = tcg_temp_new();
3836f3141174SRichard Henderson         tcg_gen_setcondi_tl(TCG_COND_EQ, t1, src1, (target_long)INT64_MIN);
3837f3141174SRichard Henderson         tcg_gen_setcondi_tl(TCG_COND_EQ, t2, src2, -1);
3838f3141174SRichard Henderson         tcg_gen_and_tl(t1, t1, t2);
3839f3141174SRichard Henderson         tcg_gen_movcond_tl(TCG_COND_NE, t1, t1, tcg_constant_tl(0),
3840f3141174SRichard Henderson                            tcg_constant_tl(1), src2);
3841f3141174SRichard Henderson         src2 = t1;
3842f3141174SRichard Henderson     }
3843f3141174SRichard Henderson 
3844f3141174SRichard Henderson     tcg_gen_div_tl(dst, src1, src2);
3845f3141174SRichard Henderson     gen_store_gpr(dc, a->rd, dst);
3846f3141174SRichard Henderson     return advance_pc(dc);
3847f3141174SRichard Henderson }
3848f3141174SRichard Henderson 
3849b88ce6f2SRichard Henderson static bool gen_edge(DisasContext *dc, arg_r_r_r *a,
385043db5838SRichard Henderson                      int width, bool cc, bool little_endian)
3851b88ce6f2SRichard Henderson {
385243db5838SRichard Henderson     TCGv dst, s1, s2, l, r, t, m;
385343db5838SRichard Henderson     uint64_t amask = address_mask_i(dc, -8);
3854b88ce6f2SRichard Henderson 
3855b88ce6f2SRichard Henderson     dst = gen_dest_gpr(dc, a->rd);
3856b88ce6f2SRichard Henderson     s1 = gen_load_gpr(dc, a->rs1);
3857b88ce6f2SRichard Henderson     s2 = gen_load_gpr(dc, a->rs2);
3858b88ce6f2SRichard Henderson 
3859b88ce6f2SRichard Henderson     if (cc) {
3860f828df74SRichard Henderson         gen_op_subcc(cpu_cc_N, s1, s2);
3861b88ce6f2SRichard Henderson     }
3862b88ce6f2SRichard Henderson 
386343db5838SRichard Henderson     l = tcg_temp_new();
386443db5838SRichard Henderson     r = tcg_temp_new();
386543db5838SRichard Henderson     t = tcg_temp_new();
386643db5838SRichard Henderson 
3867b88ce6f2SRichard Henderson     switch (width) {
3868b88ce6f2SRichard Henderson     case 8:
386943db5838SRichard Henderson         tcg_gen_andi_tl(l, s1, 7);
387043db5838SRichard Henderson         tcg_gen_andi_tl(r, s2, 7);
387143db5838SRichard Henderson         tcg_gen_xori_tl(r, r, 7);
387243db5838SRichard Henderson         m = tcg_constant_tl(0xff);
3873b88ce6f2SRichard Henderson         break;
3874b88ce6f2SRichard Henderson     case 16:
387543db5838SRichard Henderson         tcg_gen_extract_tl(l, s1, 1, 2);
387643db5838SRichard Henderson         tcg_gen_extract_tl(r, s2, 1, 2);
387743db5838SRichard Henderson         tcg_gen_xori_tl(r, r, 3);
387843db5838SRichard Henderson         m = tcg_constant_tl(0xf);
3879b88ce6f2SRichard Henderson         break;
3880b88ce6f2SRichard Henderson     case 32:
388143db5838SRichard Henderson         tcg_gen_extract_tl(l, s1, 2, 1);
388243db5838SRichard Henderson         tcg_gen_extract_tl(r, s2, 2, 1);
388343db5838SRichard Henderson         tcg_gen_xori_tl(r, r, 1);
388443db5838SRichard Henderson         m = tcg_constant_tl(0x3);
3885b88ce6f2SRichard Henderson         break;
3886b88ce6f2SRichard Henderson     default:
3887b88ce6f2SRichard Henderson         abort();
3888b88ce6f2SRichard Henderson     }
3889b88ce6f2SRichard Henderson 
389043db5838SRichard Henderson     /* Compute Left Edge */
389143db5838SRichard Henderson     if (little_endian) {
389243db5838SRichard Henderson         tcg_gen_shl_tl(l, m, l);
389343db5838SRichard Henderson         tcg_gen_and_tl(l, l, m);
389443db5838SRichard Henderson     } else {
389543db5838SRichard Henderson         tcg_gen_shr_tl(l, m, l);
389643db5838SRichard Henderson     }
389743db5838SRichard Henderson     /* Compute Right Edge */
389843db5838SRichard Henderson     if (little_endian) {
389943db5838SRichard Henderson         tcg_gen_shr_tl(r, m, r);
390043db5838SRichard Henderson     } else {
390143db5838SRichard Henderson         tcg_gen_shl_tl(r, m, r);
390243db5838SRichard Henderson         tcg_gen_and_tl(r, r, m);
390343db5838SRichard Henderson     }
3904b88ce6f2SRichard Henderson 
390543db5838SRichard Henderson     /* Compute dst = (s1 == s2 under amask ? l : l & r) */
390643db5838SRichard Henderson     tcg_gen_xor_tl(t, s1, s2);
390743db5838SRichard Henderson     tcg_gen_and_tl(r, r, l);
390843db5838SRichard Henderson     tcg_gen_movcond_tl(TCG_COND_TSTEQ, dst, t, tcg_constant_tl(amask), r, l);
3909b88ce6f2SRichard Henderson 
3910b88ce6f2SRichard Henderson     gen_store_gpr(dc, a->rd, dst);
3911b88ce6f2SRichard Henderson     return advance_pc(dc);
3912b88ce6f2SRichard Henderson }
3913b88ce6f2SRichard Henderson 
3914b88ce6f2SRichard Henderson TRANS(EDGE8cc, VIS1, gen_edge, a, 8, 1, 0)
3915b88ce6f2SRichard Henderson TRANS(EDGE8Lcc, VIS1, gen_edge, a, 8, 1, 1)
3916b88ce6f2SRichard Henderson TRANS(EDGE16cc, VIS1, gen_edge, a, 16, 1, 0)
3917b88ce6f2SRichard Henderson TRANS(EDGE16Lcc, VIS1, gen_edge, a, 16, 1, 1)
3918b88ce6f2SRichard Henderson TRANS(EDGE32cc, VIS1, gen_edge, a, 32, 1, 0)
3919b88ce6f2SRichard Henderson TRANS(EDGE32Lcc, VIS1, gen_edge, a, 32, 1, 1)
3920b88ce6f2SRichard Henderson 
3921b88ce6f2SRichard Henderson TRANS(EDGE8N, VIS2, gen_edge, a, 8, 0, 0)
3922b88ce6f2SRichard Henderson TRANS(EDGE8LN, VIS2, gen_edge, a, 8, 0, 1)
3923b88ce6f2SRichard Henderson TRANS(EDGE16N, VIS2, gen_edge, a, 16, 0, 0)
3924b88ce6f2SRichard Henderson TRANS(EDGE16LN, VIS2, gen_edge, a, 16, 0, 1)
3925b88ce6f2SRichard Henderson TRANS(EDGE32N, VIS2, gen_edge, a, 32, 0, 0)
3926b88ce6f2SRichard Henderson TRANS(EDGE32LN, VIS2, gen_edge, a, 32, 0, 1)
3927b88ce6f2SRichard Henderson 
3928875ce392SRichard Henderson static bool do_rr(DisasContext *dc, arg_r_r *a,
3929875ce392SRichard Henderson                   void (*func)(TCGv, TCGv))
3930875ce392SRichard Henderson {
3931875ce392SRichard Henderson     TCGv dst = gen_dest_gpr(dc, a->rd);
3932875ce392SRichard Henderson     TCGv src = gen_load_gpr(dc, a->rs);
3933875ce392SRichard Henderson 
3934875ce392SRichard Henderson     func(dst, src);
3935875ce392SRichard Henderson     gen_store_gpr(dc, a->rd, dst);
3936875ce392SRichard Henderson     return advance_pc(dc);
3937875ce392SRichard Henderson }
3938875ce392SRichard Henderson 
3939875ce392SRichard Henderson TRANS(LZCNT, VIS3, do_rr, a, gen_op_lzcnt)
3940875ce392SRichard Henderson 
394145bfed3bSRichard Henderson static bool do_rrr(DisasContext *dc, arg_r_r_r *a,
394245bfed3bSRichard Henderson                    void (*func)(TCGv, TCGv, TCGv))
394345bfed3bSRichard Henderson {
394445bfed3bSRichard Henderson     TCGv dst = gen_dest_gpr(dc, a->rd);
394545bfed3bSRichard Henderson     TCGv src1 = gen_load_gpr(dc, a->rs1);
394645bfed3bSRichard Henderson     TCGv src2 = gen_load_gpr(dc, a->rs2);
394745bfed3bSRichard Henderson 
394845bfed3bSRichard Henderson     func(dst, src1, src2);
394945bfed3bSRichard Henderson     gen_store_gpr(dc, a->rd, dst);
395045bfed3bSRichard Henderson     return advance_pc(dc);
395145bfed3bSRichard Henderson }
395245bfed3bSRichard Henderson 
395345bfed3bSRichard Henderson TRANS(ARRAY8, VIS1, do_rrr, a, gen_helper_array8)
395445bfed3bSRichard Henderson TRANS(ARRAY16, VIS1, do_rrr, a, gen_op_array16)
395545bfed3bSRichard Henderson TRANS(ARRAY32, VIS1, do_rrr, a, gen_op_array32)
395645bfed3bSRichard Henderson 
3957015fc6fcSRichard Henderson TRANS(ADDXC, VIS3, do_rrr, a, gen_op_addxc)
3958015fc6fcSRichard Henderson TRANS(ADDXCcc, VIS3, do_rrr, a, gen_op_addxccc)
3959015fc6fcSRichard Henderson 
3960680af1b4SRichard Henderson TRANS(UMULXHI, VIS3, do_rrr, a, gen_op_umulxhi)
3961680af1b4SRichard Henderson 
39629e20ca94SRichard Henderson static void gen_op_alignaddr(TCGv dst, TCGv s1, TCGv s2)
39639e20ca94SRichard Henderson {
39649e20ca94SRichard Henderson #ifdef TARGET_SPARC64
39659e20ca94SRichard Henderson     TCGv tmp = tcg_temp_new();
39669e20ca94SRichard Henderson 
39679e20ca94SRichard Henderson     tcg_gen_add_tl(tmp, s1, s2);
39689e20ca94SRichard Henderson     tcg_gen_andi_tl(dst, tmp, -8);
39699e20ca94SRichard Henderson     tcg_gen_deposit_tl(cpu_gsr, cpu_gsr, tmp, 0, 3);
39709e20ca94SRichard Henderson #else
39719e20ca94SRichard Henderson     g_assert_not_reached();
39729e20ca94SRichard Henderson #endif
39739e20ca94SRichard Henderson }
39749e20ca94SRichard Henderson 
39759e20ca94SRichard Henderson static void gen_op_alignaddrl(TCGv dst, TCGv s1, TCGv s2)
39769e20ca94SRichard Henderson {
39779e20ca94SRichard Henderson #ifdef TARGET_SPARC64
39789e20ca94SRichard Henderson     TCGv tmp = tcg_temp_new();
39799e20ca94SRichard Henderson 
39809e20ca94SRichard Henderson     tcg_gen_add_tl(tmp, s1, s2);
39819e20ca94SRichard Henderson     tcg_gen_andi_tl(dst, tmp, -8);
39829e20ca94SRichard Henderson     tcg_gen_neg_tl(tmp, tmp);
39839e20ca94SRichard Henderson     tcg_gen_deposit_tl(cpu_gsr, cpu_gsr, tmp, 0, 3);
39849e20ca94SRichard Henderson #else
39859e20ca94SRichard Henderson     g_assert_not_reached();
39869e20ca94SRichard Henderson #endif
39879e20ca94SRichard Henderson }
39889e20ca94SRichard Henderson 
39899e20ca94SRichard Henderson TRANS(ALIGNADDR, VIS1, do_rrr, a, gen_op_alignaddr)
39909e20ca94SRichard Henderson TRANS(ALIGNADDRL, VIS1, do_rrr, a, gen_op_alignaddrl)
39919e20ca94SRichard Henderson 
399239ca3490SRichard Henderson static void gen_op_bmask(TCGv dst, TCGv s1, TCGv s2)
399339ca3490SRichard Henderson {
399439ca3490SRichard Henderson #ifdef TARGET_SPARC64
399539ca3490SRichard Henderson     tcg_gen_add_tl(dst, s1, s2);
399639ca3490SRichard Henderson     tcg_gen_deposit_tl(cpu_gsr, cpu_gsr, dst, 32, 32);
399739ca3490SRichard Henderson #else
399839ca3490SRichard Henderson     g_assert_not_reached();
399939ca3490SRichard Henderson #endif
400039ca3490SRichard Henderson }
400139ca3490SRichard Henderson 
400239ca3490SRichard Henderson TRANS(BMASK, VIS2, do_rrr, a, gen_op_bmask)
400339ca3490SRichard Henderson 
4004c973b4e8SRichard Henderson static bool do_cmask(DisasContext *dc, int rs2, void (*func)(TCGv, TCGv, TCGv))
4005c973b4e8SRichard Henderson {
4006c973b4e8SRichard Henderson     func(cpu_gsr, cpu_gsr, gen_load_gpr(dc, rs2));
4007c973b4e8SRichard Henderson     return true;
4008c973b4e8SRichard Henderson }
4009c973b4e8SRichard Henderson 
4010c973b4e8SRichard Henderson TRANS(CMASK8, VIS3, do_cmask, a->rs2, gen_helper_cmask8)
4011c973b4e8SRichard Henderson TRANS(CMASK16, VIS3, do_cmask, a->rs2, gen_helper_cmask16)
4012c973b4e8SRichard Henderson TRANS(CMASK32, VIS3, do_cmask, a->rs2, gen_helper_cmask32)
4013c973b4e8SRichard Henderson 
40145fc546eeSRichard Henderson static bool do_shift_r(DisasContext *dc, arg_shiftr *a, bool l, bool u)
40155fc546eeSRichard Henderson {
40165fc546eeSRichard Henderson     TCGv dst, src1, src2;
40175fc546eeSRichard Henderson 
40185fc546eeSRichard Henderson     /* Reject 64-bit shifts for sparc32. */
40195fc546eeSRichard Henderson     if (avail_32(dc) && a->x) {
40205fc546eeSRichard Henderson         return false;
40215fc546eeSRichard Henderson     }
40225fc546eeSRichard Henderson 
40235fc546eeSRichard Henderson     src2 = tcg_temp_new();
40245fc546eeSRichard Henderson     tcg_gen_andi_tl(src2, gen_load_gpr(dc, a->rs2), a->x ? 63 : 31);
40255fc546eeSRichard Henderson     src1 = gen_load_gpr(dc, a->rs1);
40265fc546eeSRichard Henderson     dst = gen_dest_gpr(dc, a->rd);
40275fc546eeSRichard Henderson 
40285fc546eeSRichard Henderson     if (l) {
40295fc546eeSRichard Henderson         tcg_gen_shl_tl(dst, src1, src2);
40305fc546eeSRichard Henderson         if (!a->x) {
40315fc546eeSRichard Henderson             tcg_gen_ext32u_tl(dst, dst);
40325fc546eeSRichard Henderson         }
40335fc546eeSRichard Henderson     } else if (u) {
40345fc546eeSRichard Henderson         if (!a->x) {
40355fc546eeSRichard Henderson             tcg_gen_ext32u_tl(dst, src1);
40365fc546eeSRichard Henderson             src1 = dst;
40375fc546eeSRichard Henderson         }
40385fc546eeSRichard Henderson         tcg_gen_shr_tl(dst, src1, src2);
40395fc546eeSRichard Henderson     } else {
40405fc546eeSRichard Henderson         if (!a->x) {
40415fc546eeSRichard Henderson             tcg_gen_ext32s_tl(dst, src1);
40425fc546eeSRichard Henderson             src1 = dst;
40435fc546eeSRichard Henderson         }
40445fc546eeSRichard Henderson         tcg_gen_sar_tl(dst, src1, src2);
40455fc546eeSRichard Henderson     }
40465fc546eeSRichard Henderson     gen_store_gpr(dc, a->rd, dst);
40475fc546eeSRichard Henderson     return advance_pc(dc);
40485fc546eeSRichard Henderson }
40495fc546eeSRichard Henderson 
40505fc546eeSRichard Henderson TRANS(SLL_r, ALL, do_shift_r, a, true, true)
40515fc546eeSRichard Henderson TRANS(SRL_r, ALL, do_shift_r, a, false, true)
40525fc546eeSRichard Henderson TRANS(SRA_r, ALL, do_shift_r, a, false, false)
40535fc546eeSRichard Henderson 
40545fc546eeSRichard Henderson static bool do_shift_i(DisasContext *dc, arg_shifti *a, bool l, bool u)
40555fc546eeSRichard Henderson {
40565fc546eeSRichard Henderson     TCGv dst, src1;
40575fc546eeSRichard Henderson 
40585fc546eeSRichard Henderson     /* Reject 64-bit shifts for sparc32. */
40595fc546eeSRichard Henderson     if (avail_32(dc) && (a->x || a->i >= 32)) {
40605fc546eeSRichard Henderson         return false;
40615fc546eeSRichard Henderson     }
40625fc546eeSRichard Henderson 
40635fc546eeSRichard Henderson     src1 = gen_load_gpr(dc, a->rs1);
40645fc546eeSRichard Henderson     dst = gen_dest_gpr(dc, a->rd);
40655fc546eeSRichard Henderson 
40665fc546eeSRichard Henderson     if (avail_32(dc) || a->x) {
40675fc546eeSRichard Henderson         if (l) {
40685fc546eeSRichard Henderson             tcg_gen_shli_tl(dst, src1, a->i);
40695fc546eeSRichard Henderson         } else if (u) {
40705fc546eeSRichard Henderson             tcg_gen_shri_tl(dst, src1, a->i);
40715fc546eeSRichard Henderson         } else {
40725fc546eeSRichard Henderson             tcg_gen_sari_tl(dst, src1, a->i);
40735fc546eeSRichard Henderson         }
40745fc546eeSRichard Henderson     } else {
40755fc546eeSRichard Henderson         if (l) {
40765fc546eeSRichard Henderson             tcg_gen_deposit_z_tl(dst, src1, a->i, 32 - a->i);
40775fc546eeSRichard Henderson         } else if (u) {
40785fc546eeSRichard Henderson             tcg_gen_extract_tl(dst, src1, a->i, 32 - a->i);
40795fc546eeSRichard Henderson         } else {
40805fc546eeSRichard Henderson             tcg_gen_sextract_tl(dst, src1, a->i, 32 - a->i);
40815fc546eeSRichard Henderson         }
40825fc546eeSRichard Henderson     }
40835fc546eeSRichard Henderson     gen_store_gpr(dc, a->rd, dst);
40845fc546eeSRichard Henderson     return advance_pc(dc);
40855fc546eeSRichard Henderson }
40865fc546eeSRichard Henderson 
40875fc546eeSRichard Henderson TRANS(SLL_i, ALL, do_shift_i, a, true, true)
40885fc546eeSRichard Henderson TRANS(SRL_i, ALL, do_shift_i, a, false, true)
40895fc546eeSRichard Henderson TRANS(SRA_i, ALL, do_shift_i, a, false, false)
40905fc546eeSRichard Henderson 
4091fb4ed7aaSRichard Henderson static TCGv gen_rs2_or_imm(DisasContext *dc, bool imm, int rs2_or_imm)
4092fb4ed7aaSRichard Henderson {
4093fb4ed7aaSRichard Henderson     /* For simplicity, we under-decoded the rs2 form. */
4094fb4ed7aaSRichard Henderson     if (!imm && rs2_or_imm & ~0x1f) {
4095fb4ed7aaSRichard Henderson         return NULL;
4096fb4ed7aaSRichard Henderson     }
4097fb4ed7aaSRichard Henderson     if (imm || rs2_or_imm == 0) {
4098fb4ed7aaSRichard Henderson         return tcg_constant_tl(rs2_or_imm);
4099fb4ed7aaSRichard Henderson     } else {
4100fb4ed7aaSRichard Henderson         return cpu_regs[rs2_or_imm];
4101fb4ed7aaSRichard Henderson     }
4102fb4ed7aaSRichard Henderson }
4103fb4ed7aaSRichard Henderson 
4104fb4ed7aaSRichard Henderson static bool do_mov_cond(DisasContext *dc, DisasCompare *cmp, int rd, TCGv src2)
4105fb4ed7aaSRichard Henderson {
4106fb4ed7aaSRichard Henderson     TCGv dst = gen_load_gpr(dc, rd);
4107c8507ebfSRichard Henderson     TCGv c2 = tcg_constant_tl(cmp->c2);
4108fb4ed7aaSRichard Henderson 
4109c8507ebfSRichard Henderson     tcg_gen_movcond_tl(cmp->cond, dst, cmp->c1, c2, src2, dst);
4110fb4ed7aaSRichard Henderson     gen_store_gpr(dc, rd, dst);
4111fb4ed7aaSRichard Henderson     return advance_pc(dc);
4112fb4ed7aaSRichard Henderson }
4113fb4ed7aaSRichard Henderson 
4114fb4ed7aaSRichard Henderson static bool trans_MOVcc(DisasContext *dc, arg_MOVcc *a)
4115fb4ed7aaSRichard Henderson {
4116fb4ed7aaSRichard Henderson     TCGv src2 = gen_rs2_or_imm(dc, a->imm, a->rs2_or_imm);
4117fb4ed7aaSRichard Henderson     DisasCompare cmp;
4118fb4ed7aaSRichard Henderson 
4119fb4ed7aaSRichard Henderson     if (src2 == NULL) {
4120fb4ed7aaSRichard Henderson         return false;
4121fb4ed7aaSRichard Henderson     }
4122fb4ed7aaSRichard Henderson     gen_compare(&cmp, a->cc, a->cond, dc);
4123fb4ed7aaSRichard Henderson     return do_mov_cond(dc, &cmp, a->rd, src2);
4124fb4ed7aaSRichard Henderson }
4125fb4ed7aaSRichard Henderson 
4126fb4ed7aaSRichard Henderson static bool trans_MOVfcc(DisasContext *dc, arg_MOVfcc *a)
4127fb4ed7aaSRichard Henderson {
4128fb4ed7aaSRichard Henderson     TCGv src2 = gen_rs2_or_imm(dc, a->imm, a->rs2_or_imm);
4129fb4ed7aaSRichard Henderson     DisasCompare cmp;
4130fb4ed7aaSRichard Henderson 
4131fb4ed7aaSRichard Henderson     if (src2 == NULL) {
4132fb4ed7aaSRichard Henderson         return false;
4133fb4ed7aaSRichard Henderson     }
4134fb4ed7aaSRichard Henderson     gen_fcompare(&cmp, a->cc, a->cond);
4135fb4ed7aaSRichard Henderson     return do_mov_cond(dc, &cmp, a->rd, src2);
4136fb4ed7aaSRichard Henderson }
4137fb4ed7aaSRichard Henderson 
4138fb4ed7aaSRichard Henderson static bool trans_MOVR(DisasContext *dc, arg_MOVR *a)
4139fb4ed7aaSRichard Henderson {
4140fb4ed7aaSRichard Henderson     TCGv src2 = gen_rs2_or_imm(dc, a->imm, a->rs2_or_imm);
4141fb4ed7aaSRichard Henderson     DisasCompare cmp;
4142fb4ed7aaSRichard Henderson 
4143fb4ed7aaSRichard Henderson     if (src2 == NULL) {
4144fb4ed7aaSRichard Henderson         return false;
4145fb4ed7aaSRichard Henderson     }
41462c4f56c9SRichard Henderson     if (!gen_compare_reg(&cmp, a->cond, gen_load_gpr(dc, a->rs1))) {
41472c4f56c9SRichard Henderson         return false;
41482c4f56c9SRichard Henderson     }
4149fb4ed7aaSRichard Henderson     return do_mov_cond(dc, &cmp, a->rd, src2);
4150fb4ed7aaSRichard Henderson }
4151fb4ed7aaSRichard Henderson 
415286b82fe0SRichard Henderson static bool do_add_special(DisasContext *dc, arg_r_r_ri *a,
415386b82fe0SRichard Henderson                            bool (*func)(DisasContext *dc, int rd, TCGv src))
415486b82fe0SRichard Henderson {
415586b82fe0SRichard Henderson     TCGv src1, sum;
415686b82fe0SRichard Henderson 
415786b82fe0SRichard Henderson     /* For simplicity, we under-decoded the rs2 form. */
415886b82fe0SRichard Henderson     if (!a->imm && a->rs2_or_imm & ~0x1f) {
415986b82fe0SRichard Henderson         return false;
416086b82fe0SRichard Henderson     }
416186b82fe0SRichard Henderson 
416286b82fe0SRichard Henderson     /*
416386b82fe0SRichard Henderson      * Always load the sum into a new temporary.
416486b82fe0SRichard Henderson      * This is required to capture the value across a window change,
416586b82fe0SRichard Henderson      * e.g. SAVE and RESTORE, and may be optimized away otherwise.
416686b82fe0SRichard Henderson      */
416786b82fe0SRichard Henderson     sum = tcg_temp_new();
416886b82fe0SRichard Henderson     src1 = gen_load_gpr(dc, a->rs1);
416986b82fe0SRichard Henderson     if (a->imm || a->rs2_or_imm == 0) {
417086b82fe0SRichard Henderson         tcg_gen_addi_tl(sum, src1, a->rs2_or_imm);
417186b82fe0SRichard Henderson     } else {
417286b82fe0SRichard Henderson         tcg_gen_add_tl(sum, src1, cpu_regs[a->rs2_or_imm]);
417386b82fe0SRichard Henderson     }
417486b82fe0SRichard Henderson     return func(dc, a->rd, sum);
417586b82fe0SRichard Henderson }
417686b82fe0SRichard Henderson 
417786b82fe0SRichard Henderson static bool do_jmpl(DisasContext *dc, int rd, TCGv src)
417886b82fe0SRichard Henderson {
417986b82fe0SRichard Henderson     /*
418086b82fe0SRichard Henderson      * Preserve pc across advance, so that we can delay
418186b82fe0SRichard Henderson      * the writeback to rd until after src is consumed.
418286b82fe0SRichard Henderson      */
418386b82fe0SRichard Henderson     target_ulong cur_pc = dc->pc;
418486b82fe0SRichard Henderson 
418586b82fe0SRichard Henderson     gen_check_align(dc, src, 3);
418686b82fe0SRichard Henderson 
418786b82fe0SRichard Henderson     gen_mov_pc_npc(dc);
418886b82fe0SRichard Henderson     tcg_gen_mov_tl(cpu_npc, src);
418986b82fe0SRichard Henderson     gen_address_mask(dc, cpu_npc);
419086b82fe0SRichard Henderson     gen_store_gpr(dc, rd, tcg_constant_tl(cur_pc));
419186b82fe0SRichard Henderson 
419286b82fe0SRichard Henderson     dc->npc = DYNAMIC_PC_LOOKUP;
419386b82fe0SRichard Henderson     return true;
419486b82fe0SRichard Henderson }
419586b82fe0SRichard Henderson 
419686b82fe0SRichard Henderson TRANS(JMPL, ALL, do_add_special, a, do_jmpl)
419786b82fe0SRichard Henderson 
419886b82fe0SRichard Henderson static bool do_rett(DisasContext *dc, int rd, TCGv src)
419986b82fe0SRichard Henderson {
420086b82fe0SRichard Henderson     if (!supervisor(dc)) {
420186b82fe0SRichard Henderson         return raise_priv(dc);
420286b82fe0SRichard Henderson     }
420386b82fe0SRichard Henderson 
420486b82fe0SRichard Henderson     gen_check_align(dc, src, 3);
420586b82fe0SRichard Henderson 
420686b82fe0SRichard Henderson     gen_mov_pc_npc(dc);
420786b82fe0SRichard Henderson     tcg_gen_mov_tl(cpu_npc, src);
420886b82fe0SRichard Henderson     gen_helper_rett(tcg_env);
420986b82fe0SRichard Henderson 
421086b82fe0SRichard Henderson     dc->npc = DYNAMIC_PC;
421186b82fe0SRichard Henderson     return true;
421286b82fe0SRichard Henderson }
421386b82fe0SRichard Henderson 
421486b82fe0SRichard Henderson TRANS(RETT, 32, do_add_special, a, do_rett)
421586b82fe0SRichard Henderson 
421686b82fe0SRichard Henderson static bool do_return(DisasContext *dc, int rd, TCGv src)
421786b82fe0SRichard Henderson {
421886b82fe0SRichard Henderson     gen_check_align(dc, src, 3);
42190dfae4f9SRichard Henderson     gen_helper_restore(tcg_env);
422086b82fe0SRichard Henderson 
422186b82fe0SRichard Henderson     gen_mov_pc_npc(dc);
422286b82fe0SRichard Henderson     tcg_gen_mov_tl(cpu_npc, src);
422386b82fe0SRichard Henderson     gen_address_mask(dc, cpu_npc);
422486b82fe0SRichard Henderson 
422586b82fe0SRichard Henderson     dc->npc = DYNAMIC_PC_LOOKUP;
422686b82fe0SRichard Henderson     return true;
422786b82fe0SRichard Henderson }
422886b82fe0SRichard Henderson 
422986b82fe0SRichard Henderson TRANS(RETURN, 64, do_add_special, a, do_return)
423086b82fe0SRichard Henderson 
4231d3825800SRichard Henderson static bool do_save(DisasContext *dc, int rd, TCGv src)
4232d3825800SRichard Henderson {
4233d3825800SRichard Henderson     gen_helper_save(tcg_env);
4234d3825800SRichard Henderson     gen_store_gpr(dc, rd, src);
4235d3825800SRichard Henderson     return advance_pc(dc);
4236d3825800SRichard Henderson }
4237d3825800SRichard Henderson 
4238d3825800SRichard Henderson TRANS(SAVE, ALL, do_add_special, a, do_save)
4239d3825800SRichard Henderson 
4240d3825800SRichard Henderson static bool do_restore(DisasContext *dc, int rd, TCGv src)
4241d3825800SRichard Henderson {
4242d3825800SRichard Henderson     gen_helper_restore(tcg_env);
4243d3825800SRichard Henderson     gen_store_gpr(dc, rd, src);
4244d3825800SRichard Henderson     return advance_pc(dc);
4245d3825800SRichard Henderson }
4246d3825800SRichard Henderson 
4247d3825800SRichard Henderson TRANS(RESTORE, ALL, do_add_special, a, do_restore)
4248d3825800SRichard Henderson 
42498f75b8a4SRichard Henderson static bool do_done_retry(DisasContext *dc, bool done)
42508f75b8a4SRichard Henderson {
42518f75b8a4SRichard Henderson     if (!supervisor(dc)) {
42528f75b8a4SRichard Henderson         return raise_priv(dc);
42538f75b8a4SRichard Henderson     }
42548f75b8a4SRichard Henderson     dc->npc = DYNAMIC_PC;
42558f75b8a4SRichard Henderson     dc->pc = DYNAMIC_PC;
42568f75b8a4SRichard Henderson     translator_io_start(&dc->base);
42578f75b8a4SRichard Henderson     if (done) {
42588f75b8a4SRichard Henderson         gen_helper_done(tcg_env);
42598f75b8a4SRichard Henderson     } else {
42608f75b8a4SRichard Henderson         gen_helper_retry(tcg_env);
42618f75b8a4SRichard Henderson     }
42628f75b8a4SRichard Henderson     return true;
42638f75b8a4SRichard Henderson }
42648f75b8a4SRichard Henderson 
42658f75b8a4SRichard Henderson TRANS(DONE, 64, do_done_retry, true)
42668f75b8a4SRichard Henderson TRANS(RETRY, 64, do_done_retry, false)
42678f75b8a4SRichard Henderson 
42680880d20bSRichard Henderson /*
42690880d20bSRichard Henderson  * Major opcode 11 -- load and store instructions
42700880d20bSRichard Henderson  */
42710880d20bSRichard Henderson 
42720880d20bSRichard Henderson static TCGv gen_ldst_addr(DisasContext *dc, int rs1, bool imm, int rs2_or_imm)
42730880d20bSRichard Henderson {
42740880d20bSRichard Henderson     TCGv addr, tmp = NULL;
42750880d20bSRichard Henderson 
42760880d20bSRichard Henderson     /* For simplicity, we under-decoded the rs2 form. */
42770880d20bSRichard Henderson     if (!imm && rs2_or_imm & ~0x1f) {
42780880d20bSRichard Henderson         return NULL;
42790880d20bSRichard Henderson     }
42800880d20bSRichard Henderson 
42810880d20bSRichard Henderson     addr = gen_load_gpr(dc, rs1);
42820880d20bSRichard Henderson     if (rs2_or_imm) {
42830880d20bSRichard Henderson         tmp = tcg_temp_new();
42840880d20bSRichard Henderson         if (imm) {
42850880d20bSRichard Henderson             tcg_gen_addi_tl(tmp, addr, rs2_or_imm);
42860880d20bSRichard Henderson         } else {
42870880d20bSRichard Henderson             tcg_gen_add_tl(tmp, addr, cpu_regs[rs2_or_imm]);
42880880d20bSRichard Henderson         }
42890880d20bSRichard Henderson         addr = tmp;
42900880d20bSRichard Henderson     }
42910880d20bSRichard Henderson     if (AM_CHECK(dc)) {
42920880d20bSRichard Henderson         if (!tmp) {
42930880d20bSRichard Henderson             tmp = tcg_temp_new();
42940880d20bSRichard Henderson         }
42950880d20bSRichard Henderson         tcg_gen_ext32u_tl(tmp, addr);
42960880d20bSRichard Henderson         addr = tmp;
42970880d20bSRichard Henderson     }
42980880d20bSRichard Henderson     return addr;
42990880d20bSRichard Henderson }
43000880d20bSRichard Henderson 
43010880d20bSRichard Henderson static bool do_ld_gpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp mop)
43020880d20bSRichard Henderson {
43030880d20bSRichard Henderson     TCGv reg, addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
43040880d20bSRichard Henderson     DisasASI da;
43050880d20bSRichard Henderson 
43060880d20bSRichard Henderson     if (addr == NULL) {
43070880d20bSRichard Henderson         return false;
43080880d20bSRichard Henderson     }
43090880d20bSRichard Henderson     da = resolve_asi(dc, a->asi, mop);
43100880d20bSRichard Henderson 
43110880d20bSRichard Henderson     reg = gen_dest_gpr(dc, a->rd);
431242071fc1SRichard Henderson     gen_ld_asi(dc, &da, reg, addr);
43130880d20bSRichard Henderson     gen_store_gpr(dc, a->rd, reg);
43140880d20bSRichard Henderson     return advance_pc(dc);
43150880d20bSRichard Henderson }
43160880d20bSRichard Henderson 
43170880d20bSRichard Henderson TRANS(LDUW, ALL, do_ld_gpr, a, MO_TEUL)
43180880d20bSRichard Henderson TRANS(LDUB, ALL, do_ld_gpr, a, MO_UB)
43190880d20bSRichard Henderson TRANS(LDUH, ALL, do_ld_gpr, a, MO_TEUW)
43200880d20bSRichard Henderson TRANS(LDSB, ALL, do_ld_gpr, a, MO_SB)
43210880d20bSRichard Henderson TRANS(LDSH, ALL, do_ld_gpr, a, MO_TESW)
43220880d20bSRichard Henderson TRANS(LDSW, 64, do_ld_gpr, a, MO_TESL)
43230880d20bSRichard Henderson TRANS(LDX, 64, do_ld_gpr, a, MO_TEUQ)
43240880d20bSRichard Henderson 
43250880d20bSRichard Henderson static bool do_st_gpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp mop)
43260880d20bSRichard Henderson {
43270880d20bSRichard Henderson     TCGv reg, addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
43280880d20bSRichard Henderson     DisasASI da;
43290880d20bSRichard Henderson 
43300880d20bSRichard Henderson     if (addr == NULL) {
43310880d20bSRichard Henderson         return false;
43320880d20bSRichard Henderson     }
43330880d20bSRichard Henderson     da = resolve_asi(dc, a->asi, mop);
43340880d20bSRichard Henderson 
43350880d20bSRichard Henderson     reg = gen_load_gpr(dc, a->rd);
433642071fc1SRichard Henderson     gen_st_asi(dc, &da, reg, addr);
43370880d20bSRichard Henderson     return advance_pc(dc);
43380880d20bSRichard Henderson }
43390880d20bSRichard Henderson 
43400880d20bSRichard Henderson TRANS(STW, ALL, do_st_gpr, a, MO_TEUL)
43410880d20bSRichard Henderson TRANS(STB, ALL, do_st_gpr, a, MO_UB)
43420880d20bSRichard Henderson TRANS(STH, ALL, do_st_gpr, a, MO_TEUW)
43430880d20bSRichard Henderson TRANS(STX, 64, do_st_gpr, a, MO_TEUQ)
43440880d20bSRichard Henderson 
43450880d20bSRichard Henderson static bool trans_LDD(DisasContext *dc, arg_r_r_ri_asi *a)
43460880d20bSRichard Henderson {
43470880d20bSRichard Henderson     TCGv addr;
43480880d20bSRichard Henderson     DisasASI da;
43490880d20bSRichard Henderson 
43500880d20bSRichard Henderson     if (a->rd & 1) {
43510880d20bSRichard Henderson         return false;
43520880d20bSRichard Henderson     }
43530880d20bSRichard Henderson     addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
43540880d20bSRichard Henderson     if (addr == NULL) {
43550880d20bSRichard Henderson         return false;
43560880d20bSRichard Henderson     }
43570880d20bSRichard Henderson     da = resolve_asi(dc, a->asi, MO_TEUQ);
435842071fc1SRichard Henderson     gen_ldda_asi(dc, &da, addr, a->rd);
43590880d20bSRichard Henderson     return advance_pc(dc);
43600880d20bSRichard Henderson }
43610880d20bSRichard Henderson 
43620880d20bSRichard Henderson static bool trans_STD(DisasContext *dc, arg_r_r_ri_asi *a)
43630880d20bSRichard Henderson {
43640880d20bSRichard Henderson     TCGv addr;
43650880d20bSRichard Henderson     DisasASI da;
43660880d20bSRichard Henderson 
43670880d20bSRichard Henderson     if (a->rd & 1) {
43680880d20bSRichard Henderson         return false;
43690880d20bSRichard Henderson     }
43700880d20bSRichard Henderson     addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
43710880d20bSRichard Henderson     if (addr == NULL) {
43720880d20bSRichard Henderson         return false;
43730880d20bSRichard Henderson     }
43740880d20bSRichard Henderson     da = resolve_asi(dc, a->asi, MO_TEUQ);
437542071fc1SRichard Henderson     gen_stda_asi(dc, &da, addr, a->rd);
43760880d20bSRichard Henderson     return advance_pc(dc);
43770880d20bSRichard Henderson }
43780880d20bSRichard Henderson 
4379cf07cd1eSRichard Henderson static bool trans_LDSTUB(DisasContext *dc, arg_r_r_ri_asi *a)
4380cf07cd1eSRichard Henderson {
4381cf07cd1eSRichard Henderson     TCGv addr, reg;
4382cf07cd1eSRichard Henderson     DisasASI da;
4383cf07cd1eSRichard Henderson 
4384cf07cd1eSRichard Henderson     addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
4385cf07cd1eSRichard Henderson     if (addr == NULL) {
4386cf07cd1eSRichard Henderson         return false;
4387cf07cd1eSRichard Henderson     }
4388cf07cd1eSRichard Henderson     da = resolve_asi(dc, a->asi, MO_UB);
4389cf07cd1eSRichard Henderson 
4390cf07cd1eSRichard Henderson     reg = gen_dest_gpr(dc, a->rd);
4391cf07cd1eSRichard Henderson     gen_ldstub_asi(dc, &da, reg, addr);
4392cf07cd1eSRichard Henderson     gen_store_gpr(dc, a->rd, reg);
4393cf07cd1eSRichard Henderson     return advance_pc(dc);
4394cf07cd1eSRichard Henderson }
4395cf07cd1eSRichard Henderson 
4396dca544b9SRichard Henderson static bool trans_SWAP(DisasContext *dc, arg_r_r_ri_asi *a)
4397dca544b9SRichard Henderson {
4398dca544b9SRichard Henderson     TCGv addr, dst, src;
4399dca544b9SRichard Henderson     DisasASI da;
4400dca544b9SRichard Henderson 
4401dca544b9SRichard Henderson     addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
4402dca544b9SRichard Henderson     if (addr == NULL) {
4403dca544b9SRichard Henderson         return false;
4404dca544b9SRichard Henderson     }
4405dca544b9SRichard Henderson     da = resolve_asi(dc, a->asi, MO_TEUL);
4406dca544b9SRichard Henderson 
4407dca544b9SRichard Henderson     dst = gen_dest_gpr(dc, a->rd);
4408dca544b9SRichard Henderson     src = gen_load_gpr(dc, a->rd);
4409dca544b9SRichard Henderson     gen_swap_asi(dc, &da, dst, src, addr);
4410dca544b9SRichard Henderson     gen_store_gpr(dc, a->rd, dst);
4411dca544b9SRichard Henderson     return advance_pc(dc);
4412dca544b9SRichard Henderson }
4413dca544b9SRichard Henderson 
4414d0a11d25SRichard Henderson static bool do_casa(DisasContext *dc, arg_r_r_ri_asi *a, MemOp mop)
4415d0a11d25SRichard Henderson {
4416d0a11d25SRichard Henderson     TCGv addr, o, n, c;
4417d0a11d25SRichard Henderson     DisasASI da;
4418d0a11d25SRichard Henderson 
4419d0a11d25SRichard Henderson     addr = gen_ldst_addr(dc, a->rs1, true, 0);
4420d0a11d25SRichard Henderson     if (addr == NULL) {
4421d0a11d25SRichard Henderson         return false;
4422d0a11d25SRichard Henderson     }
4423d0a11d25SRichard Henderson     da = resolve_asi(dc, a->asi, mop);
4424d0a11d25SRichard Henderson 
4425d0a11d25SRichard Henderson     o = gen_dest_gpr(dc, a->rd);
4426d0a11d25SRichard Henderson     n = gen_load_gpr(dc, a->rd);
4427d0a11d25SRichard Henderson     c = gen_load_gpr(dc, a->rs2_or_imm);
4428d0a11d25SRichard Henderson     gen_cas_asi(dc, &da, o, n, c, addr);
4429d0a11d25SRichard Henderson     gen_store_gpr(dc, a->rd, o);
4430d0a11d25SRichard Henderson     return advance_pc(dc);
4431d0a11d25SRichard Henderson }
4432d0a11d25SRichard Henderson 
4433d0a11d25SRichard Henderson TRANS(CASA, CASA, do_casa, a, MO_TEUL)
4434d0a11d25SRichard Henderson TRANS(CASXA, 64, do_casa, a, MO_TEUQ)
4435d0a11d25SRichard Henderson 
443606c060d9SRichard Henderson static bool do_ld_fpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp sz)
443706c060d9SRichard Henderson {
443806c060d9SRichard Henderson     TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
443906c060d9SRichard Henderson     DisasASI da;
444006c060d9SRichard Henderson 
444106c060d9SRichard Henderson     if (addr == NULL) {
444206c060d9SRichard Henderson         return false;
444306c060d9SRichard Henderson     }
444406c060d9SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
444506c060d9SRichard Henderson         return true;
444606c060d9SRichard Henderson     }
444706c060d9SRichard Henderson     if (sz == MO_128 && gen_trap_float128(dc)) {
444806c060d9SRichard Henderson         return true;
444906c060d9SRichard Henderson     }
445006c060d9SRichard Henderson     da = resolve_asi(dc, a->asi, MO_TE | sz);
4451287b1152SRichard Henderson     gen_ldf_asi(dc, &da, sz, addr, a->rd);
445206c060d9SRichard Henderson     gen_update_fprs_dirty(dc, a->rd);
445306c060d9SRichard Henderson     return advance_pc(dc);
445406c060d9SRichard Henderson }
445506c060d9SRichard Henderson 
445606c060d9SRichard Henderson TRANS(LDF, ALL, do_ld_fpr, a, MO_32)
445706c060d9SRichard Henderson TRANS(LDDF, ALL, do_ld_fpr, a, MO_64)
445806c060d9SRichard Henderson TRANS(LDQF, ALL, do_ld_fpr, a, MO_128)
445906c060d9SRichard Henderson 
4460287b1152SRichard Henderson TRANS(LDFA, 64, do_ld_fpr, a, MO_32)
4461287b1152SRichard Henderson TRANS(LDDFA, 64, do_ld_fpr, a, MO_64)
4462287b1152SRichard Henderson TRANS(LDQFA, 64, do_ld_fpr, a, MO_128)
4463287b1152SRichard Henderson 
446406c060d9SRichard Henderson static bool do_st_fpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp sz)
446506c060d9SRichard Henderson {
446606c060d9SRichard Henderson     TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
446706c060d9SRichard Henderson     DisasASI da;
446806c060d9SRichard Henderson 
446906c060d9SRichard Henderson     if (addr == NULL) {
447006c060d9SRichard Henderson         return false;
447106c060d9SRichard Henderson     }
447206c060d9SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
447306c060d9SRichard Henderson         return true;
447406c060d9SRichard Henderson     }
447506c060d9SRichard Henderson     if (sz == MO_128 && gen_trap_float128(dc)) {
447606c060d9SRichard Henderson         return true;
447706c060d9SRichard Henderson     }
447806c060d9SRichard Henderson     da = resolve_asi(dc, a->asi, MO_TE | sz);
4479287b1152SRichard Henderson     gen_stf_asi(dc, &da, sz, addr, a->rd);
448006c060d9SRichard Henderson     return advance_pc(dc);
448106c060d9SRichard Henderson }
448206c060d9SRichard Henderson 
448306c060d9SRichard Henderson TRANS(STF, ALL, do_st_fpr, a, MO_32)
448406c060d9SRichard Henderson TRANS(STDF, ALL, do_st_fpr, a, MO_64)
448506c060d9SRichard Henderson TRANS(STQF, ALL, do_st_fpr, a, MO_128)
448606c060d9SRichard Henderson 
4487287b1152SRichard Henderson TRANS(STFA, 64, do_st_fpr, a, MO_32)
4488287b1152SRichard Henderson TRANS(STDFA, 64, do_st_fpr, a, MO_64)
4489287b1152SRichard Henderson TRANS(STQFA, 64, do_st_fpr, a, MO_128)
4490287b1152SRichard Henderson 
449106c060d9SRichard Henderson static bool trans_STDFQ(DisasContext *dc, arg_STDFQ *a)
449206c060d9SRichard Henderson {
449306c060d9SRichard Henderson     if (!avail_32(dc)) {
449406c060d9SRichard Henderson         return false;
449506c060d9SRichard Henderson     }
449606c060d9SRichard Henderson     if (!supervisor(dc)) {
449706c060d9SRichard Henderson         return raise_priv(dc);
449806c060d9SRichard Henderson     }
449906c060d9SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
450006c060d9SRichard Henderson         return true;
450106c060d9SRichard Henderson     }
450206c060d9SRichard Henderson     gen_op_fpexception_im(dc, FSR_FTT_SEQ_ERROR);
450306c060d9SRichard Henderson     return true;
450406c060d9SRichard Henderson }
450506c060d9SRichard Henderson 
4506d8c5b92fSRichard Henderson static bool trans_LDFSR(DisasContext *dc, arg_r_r_ri *a)
45073d3c0673SRichard Henderson {
45083590f01eSRichard Henderson     TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
4509d8c5b92fSRichard Henderson     TCGv_i32 tmp;
45103590f01eSRichard Henderson 
45113d3c0673SRichard Henderson     if (addr == NULL) {
45123d3c0673SRichard Henderson         return false;
45133d3c0673SRichard Henderson     }
45143d3c0673SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
45153d3c0673SRichard Henderson         return true;
45163d3c0673SRichard Henderson     }
4517d8c5b92fSRichard Henderson 
4518d8c5b92fSRichard Henderson     tmp = tcg_temp_new_i32();
4519d8c5b92fSRichard Henderson     tcg_gen_qemu_ld_i32(tmp, addr, dc->mem_idx, MO_TEUL | MO_ALIGN);
4520d8c5b92fSRichard Henderson 
4521d8c5b92fSRichard Henderson     tcg_gen_extract_i32(cpu_fcc[0], tmp, FSR_FCC0_SHIFT, 2);
4522d8c5b92fSRichard Henderson     /* LDFSR does not change FCC[1-3]. */
4523d8c5b92fSRichard Henderson 
4524d8c5b92fSRichard Henderson     gen_helper_set_fsr_nofcc_noftt(tcg_env, tmp);
45253d3c0673SRichard Henderson     return advance_pc(dc);
45263d3c0673SRichard Henderson }
45273d3c0673SRichard Henderson 
4528298c52f7SRichard Henderson static bool do_ldxfsr(DisasContext *dc, arg_r_r_ri *a, bool entire)
4529d8c5b92fSRichard Henderson {
4530d8c5b92fSRichard Henderson #ifdef TARGET_SPARC64
4531d8c5b92fSRichard Henderson     TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
4532d8c5b92fSRichard Henderson     TCGv_i64 t64;
4533d8c5b92fSRichard Henderson     TCGv_i32 lo, hi;
4534d8c5b92fSRichard Henderson 
4535d8c5b92fSRichard Henderson     if (addr == NULL) {
4536d8c5b92fSRichard Henderson         return false;
4537d8c5b92fSRichard Henderson     }
4538d8c5b92fSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4539d8c5b92fSRichard Henderson         return true;
4540d8c5b92fSRichard Henderson     }
4541d8c5b92fSRichard Henderson 
4542d8c5b92fSRichard Henderson     t64 = tcg_temp_new_i64();
4543d8c5b92fSRichard Henderson     tcg_gen_qemu_ld_i64(t64, addr, dc->mem_idx, MO_TEUQ | MO_ALIGN);
4544d8c5b92fSRichard Henderson 
4545d8c5b92fSRichard Henderson     lo = tcg_temp_new_i32();
4546d8c5b92fSRichard Henderson     hi = cpu_fcc[3];
4547d8c5b92fSRichard Henderson     tcg_gen_extr_i64_i32(lo, hi, t64);
4548d8c5b92fSRichard Henderson     tcg_gen_extract_i32(cpu_fcc[0], lo, FSR_FCC0_SHIFT, 2);
4549d8c5b92fSRichard Henderson     tcg_gen_extract_i32(cpu_fcc[1], hi, FSR_FCC1_SHIFT - 32, 2);
4550d8c5b92fSRichard Henderson     tcg_gen_extract_i32(cpu_fcc[2], hi, FSR_FCC2_SHIFT - 32, 2);
4551d8c5b92fSRichard Henderson     tcg_gen_extract_i32(cpu_fcc[3], hi, FSR_FCC3_SHIFT - 32, 2);
4552d8c5b92fSRichard Henderson 
4553298c52f7SRichard Henderson     if (entire) {
4554298c52f7SRichard Henderson         gen_helper_set_fsr_nofcc(tcg_env, lo);
4555298c52f7SRichard Henderson     } else {
4556d8c5b92fSRichard Henderson         gen_helper_set_fsr_nofcc_noftt(tcg_env, lo);
4557298c52f7SRichard Henderson     }
4558d8c5b92fSRichard Henderson     return advance_pc(dc);
4559d8c5b92fSRichard Henderson #else
4560d8c5b92fSRichard Henderson     return false;
4561d8c5b92fSRichard Henderson #endif
4562d8c5b92fSRichard Henderson }
45633d3c0673SRichard Henderson 
4564298c52f7SRichard Henderson TRANS(LDXFSR, 64, do_ldxfsr, a, false)
4565298c52f7SRichard Henderson TRANS(LDXEFSR, VIS3B, do_ldxfsr, a, true)
4566298c52f7SRichard Henderson 
45673d3c0673SRichard Henderson static bool do_stfsr(DisasContext *dc, arg_r_r_ri *a, MemOp mop)
45683d3c0673SRichard Henderson {
45693d3c0673SRichard Henderson     TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
45701ccd6e13SRichard Henderson     TCGv fsr;
45711ccd6e13SRichard Henderson 
45723d3c0673SRichard Henderson     if (addr == NULL) {
45733d3c0673SRichard Henderson         return false;
45743d3c0673SRichard Henderson     }
45753d3c0673SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
45763d3c0673SRichard Henderson         return true;
45773d3c0673SRichard Henderson     }
45781ccd6e13SRichard Henderson 
45791ccd6e13SRichard Henderson     fsr = tcg_temp_new();
45801ccd6e13SRichard Henderson     gen_helper_get_fsr(fsr, tcg_env);
45811ccd6e13SRichard Henderson     tcg_gen_qemu_st_tl(fsr, addr, dc->mem_idx, mop | MO_ALIGN);
45823d3c0673SRichard Henderson     return advance_pc(dc);
45833d3c0673SRichard Henderson }
45843d3c0673SRichard Henderson 
45853d3c0673SRichard Henderson TRANS(STFSR, ALL, do_stfsr, a, MO_TEUL)
45863d3c0673SRichard Henderson TRANS(STXFSR, 64, do_stfsr, a, MO_TEUQ)
45873d3c0673SRichard Henderson 
45881210a036SRichard Henderson static bool do_fc(DisasContext *dc, int rd, int32_t c)
45893a38260eSRichard Henderson {
45903a38260eSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
45913a38260eSRichard Henderson         return true;
45923a38260eSRichard Henderson     }
45931210a036SRichard Henderson     gen_store_fpr_F(dc, rd, tcg_constant_i32(c));
45943a38260eSRichard Henderson     return advance_pc(dc);
45953a38260eSRichard Henderson }
45963a38260eSRichard Henderson 
45973a38260eSRichard Henderson TRANS(FZEROs, VIS1, do_fc, a->rd, 0)
45981210a036SRichard Henderson TRANS(FONEs, VIS1, do_fc, a->rd, -1)
45993a38260eSRichard Henderson 
46003a38260eSRichard Henderson static bool do_dc(DisasContext *dc, int rd, int64_t c)
46013a38260eSRichard Henderson {
46023a38260eSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
46033a38260eSRichard Henderson         return true;
46043a38260eSRichard Henderson     }
46051210a036SRichard Henderson     gen_store_fpr_D(dc, rd, tcg_constant_i64(c));
46063a38260eSRichard Henderson     return advance_pc(dc);
46073a38260eSRichard Henderson }
46083a38260eSRichard Henderson 
46093a38260eSRichard Henderson TRANS(FZEROd, VIS1, do_dc, a->rd, 0)
46103a38260eSRichard Henderson TRANS(FONEd, VIS1, do_dc, a->rd, -1)
46113a38260eSRichard Henderson 
4612baf3dbf2SRichard Henderson static bool do_ff(DisasContext *dc, arg_r_r *a,
4613baf3dbf2SRichard Henderson                   void (*func)(TCGv_i32, TCGv_i32))
4614baf3dbf2SRichard Henderson {
4615baf3dbf2SRichard Henderson     TCGv_i32 tmp;
4616baf3dbf2SRichard Henderson 
4617baf3dbf2SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4618baf3dbf2SRichard Henderson         return true;
4619baf3dbf2SRichard Henderson     }
4620baf3dbf2SRichard Henderson 
4621baf3dbf2SRichard Henderson     tmp = gen_load_fpr_F(dc, a->rs);
4622baf3dbf2SRichard Henderson     func(tmp, tmp);
4623baf3dbf2SRichard Henderson     gen_store_fpr_F(dc, a->rd, tmp);
4624baf3dbf2SRichard Henderson     return advance_pc(dc);
4625baf3dbf2SRichard Henderson }
4626baf3dbf2SRichard Henderson 
4627baf3dbf2SRichard Henderson TRANS(FMOVs, ALL, do_ff, a, gen_op_fmovs)
4628baf3dbf2SRichard Henderson TRANS(FNEGs, ALL, do_ff, a, gen_op_fnegs)
4629baf3dbf2SRichard Henderson TRANS(FABSs, ALL, do_ff, a, gen_op_fabss)
4630baf3dbf2SRichard Henderson TRANS(FSRCs, VIS1, do_ff, a, tcg_gen_mov_i32)
4631baf3dbf2SRichard Henderson TRANS(FNOTs, VIS1, do_ff, a, tcg_gen_not_i32)
4632baf3dbf2SRichard Henderson 
46332f722641SRichard Henderson static bool do_fd(DisasContext *dc, arg_r_r *a,
46342f722641SRichard Henderson                   void (*func)(TCGv_i32, TCGv_i64))
46352f722641SRichard Henderson {
46362f722641SRichard Henderson     TCGv_i32 dst;
46372f722641SRichard Henderson     TCGv_i64 src;
46382f722641SRichard Henderson 
46392f722641SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
46402f722641SRichard Henderson         return true;
46412f722641SRichard Henderson     }
46422f722641SRichard Henderson 
4643388a6465SRichard Henderson     dst = tcg_temp_new_i32();
46442f722641SRichard Henderson     src = gen_load_fpr_D(dc, a->rs);
46452f722641SRichard Henderson     func(dst, src);
46462f722641SRichard Henderson     gen_store_fpr_F(dc, a->rd, dst);
46472f722641SRichard Henderson     return advance_pc(dc);
46482f722641SRichard Henderson }
46492f722641SRichard Henderson 
46502f722641SRichard Henderson TRANS(FPACK16, VIS1, do_fd, a, gen_op_fpack16)
46512f722641SRichard Henderson TRANS(FPACKFIX, VIS1, do_fd, a, gen_op_fpackfix)
46522f722641SRichard Henderson 
4653119cb94fSRichard Henderson static bool do_env_ff(DisasContext *dc, arg_r_r *a,
4654119cb94fSRichard Henderson                       void (*func)(TCGv_i32, TCGv_env, TCGv_i32))
4655119cb94fSRichard Henderson {
4656119cb94fSRichard Henderson     TCGv_i32 tmp;
4657119cb94fSRichard Henderson 
4658119cb94fSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4659119cb94fSRichard Henderson         return true;
4660119cb94fSRichard Henderson     }
4661119cb94fSRichard Henderson 
4662119cb94fSRichard Henderson     tmp = gen_load_fpr_F(dc, a->rs);
4663119cb94fSRichard Henderson     func(tmp, tcg_env, tmp);
4664119cb94fSRichard Henderson     gen_store_fpr_F(dc, a->rd, tmp);
4665119cb94fSRichard Henderson     return advance_pc(dc);
4666119cb94fSRichard Henderson }
4667119cb94fSRichard Henderson 
4668119cb94fSRichard Henderson TRANS(FSQRTs, ALL, do_env_ff, a, gen_helper_fsqrts)
4669119cb94fSRichard Henderson TRANS(FiTOs, ALL, do_env_ff, a, gen_helper_fitos)
4670119cb94fSRichard Henderson TRANS(FsTOi, ALL, do_env_ff, a, gen_helper_fstoi)
4671119cb94fSRichard Henderson 
46728c94bcd8SRichard Henderson static bool do_env_fd(DisasContext *dc, arg_r_r *a,
46738c94bcd8SRichard Henderson                       void (*func)(TCGv_i32, TCGv_env, TCGv_i64))
46748c94bcd8SRichard Henderson {
46758c94bcd8SRichard Henderson     TCGv_i32 dst;
46768c94bcd8SRichard Henderson     TCGv_i64 src;
46778c94bcd8SRichard Henderson 
46788c94bcd8SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
46798c94bcd8SRichard Henderson         return true;
46808c94bcd8SRichard Henderson     }
46818c94bcd8SRichard Henderson 
4682388a6465SRichard Henderson     dst = tcg_temp_new_i32();
46838c94bcd8SRichard Henderson     src = gen_load_fpr_D(dc, a->rs);
46848c94bcd8SRichard Henderson     func(dst, tcg_env, src);
46858c94bcd8SRichard Henderson     gen_store_fpr_F(dc, a->rd, dst);
46868c94bcd8SRichard Henderson     return advance_pc(dc);
46878c94bcd8SRichard Henderson }
46888c94bcd8SRichard Henderson 
46898c94bcd8SRichard Henderson TRANS(FdTOs, ALL, do_env_fd, a, gen_helper_fdtos)
46908c94bcd8SRichard Henderson TRANS(FdTOi, ALL, do_env_fd, a, gen_helper_fdtoi)
46918c94bcd8SRichard Henderson TRANS(FxTOs, 64, do_env_fd, a, gen_helper_fxtos)
46928c94bcd8SRichard Henderson 
4693c6d83e4fSRichard Henderson static bool do_dd(DisasContext *dc, arg_r_r *a,
4694c6d83e4fSRichard Henderson                   void (*func)(TCGv_i64, TCGv_i64))
4695c6d83e4fSRichard Henderson {
4696c6d83e4fSRichard Henderson     TCGv_i64 dst, src;
4697c6d83e4fSRichard Henderson 
4698c6d83e4fSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4699c6d83e4fSRichard Henderson         return true;
4700c6d83e4fSRichard Henderson     }
4701c6d83e4fSRichard Henderson 
470252f46d46SRichard Henderson     dst = tcg_temp_new_i64();
4703c6d83e4fSRichard Henderson     src = gen_load_fpr_D(dc, a->rs);
4704c6d83e4fSRichard Henderson     func(dst, src);
4705c6d83e4fSRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
4706c6d83e4fSRichard Henderson     return advance_pc(dc);
4707c6d83e4fSRichard Henderson }
4708c6d83e4fSRichard Henderson 
4709c6d83e4fSRichard Henderson TRANS(FMOVd, 64, do_dd, a, gen_op_fmovd)
4710c6d83e4fSRichard Henderson TRANS(FNEGd, 64, do_dd, a, gen_op_fnegd)
4711c6d83e4fSRichard Henderson TRANS(FABSd, 64, do_dd, a, gen_op_fabsd)
4712c6d83e4fSRichard Henderson TRANS(FSRCd, VIS1, do_dd, a, tcg_gen_mov_i64)
4713c6d83e4fSRichard Henderson TRANS(FNOTd, VIS1, do_dd, a, tcg_gen_not_i64)
4714c6d83e4fSRichard Henderson 
47158aa418b3SRichard Henderson static bool do_env_dd(DisasContext *dc, arg_r_r *a,
47168aa418b3SRichard Henderson                       void (*func)(TCGv_i64, TCGv_env, TCGv_i64))
47178aa418b3SRichard Henderson {
47188aa418b3SRichard Henderson     TCGv_i64 dst, src;
47198aa418b3SRichard Henderson 
47208aa418b3SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
47218aa418b3SRichard Henderson         return true;
47228aa418b3SRichard Henderson     }
47238aa418b3SRichard Henderson 
472452f46d46SRichard Henderson     dst = tcg_temp_new_i64();
47258aa418b3SRichard Henderson     src = gen_load_fpr_D(dc, a->rs);
47268aa418b3SRichard Henderson     func(dst, tcg_env, src);
47278aa418b3SRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
47288aa418b3SRichard Henderson     return advance_pc(dc);
47298aa418b3SRichard Henderson }
47308aa418b3SRichard Henderson 
47318aa418b3SRichard Henderson TRANS(FSQRTd, ALL, do_env_dd, a, gen_helper_fsqrtd)
47328aa418b3SRichard Henderson TRANS(FxTOd, 64, do_env_dd, a, gen_helper_fxtod)
47338aa418b3SRichard Henderson TRANS(FdTOx, 64, do_env_dd, a, gen_helper_fdtox)
47348aa418b3SRichard Henderson 
47357b616f36SRichard Henderson static bool do_df(DisasContext *dc, arg_r_r *a,
47367b616f36SRichard Henderson                   void (*func)(TCGv_i64, TCGv_i32))
47377b616f36SRichard Henderson {
47387b616f36SRichard Henderson     TCGv_i64 dst;
47397b616f36SRichard Henderson     TCGv_i32 src;
47407b616f36SRichard Henderson 
47417b616f36SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
47427b616f36SRichard Henderson         return true;
47437b616f36SRichard Henderson     }
47447b616f36SRichard Henderson 
47457b616f36SRichard Henderson     dst = tcg_temp_new_i64();
47467b616f36SRichard Henderson     src = gen_load_fpr_F(dc, a->rs);
47477b616f36SRichard Henderson     func(dst, src);
47487b616f36SRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
47497b616f36SRichard Henderson     return advance_pc(dc);
47507b616f36SRichard Henderson }
47517b616f36SRichard Henderson 
47527b616f36SRichard Henderson TRANS(FEXPAND, VIS1, do_df, a, gen_helper_fexpand)
47537b616f36SRichard Henderson 
4754199d43efSRichard Henderson static bool do_env_df(DisasContext *dc, arg_r_r *a,
4755199d43efSRichard Henderson                       void (*func)(TCGv_i64, TCGv_env, TCGv_i32))
4756199d43efSRichard Henderson {
4757199d43efSRichard Henderson     TCGv_i64 dst;
4758199d43efSRichard Henderson     TCGv_i32 src;
4759199d43efSRichard Henderson 
4760199d43efSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4761199d43efSRichard Henderson         return true;
4762199d43efSRichard Henderson     }
4763199d43efSRichard Henderson 
476452f46d46SRichard Henderson     dst = tcg_temp_new_i64();
4765199d43efSRichard Henderson     src = gen_load_fpr_F(dc, a->rs);
4766199d43efSRichard Henderson     func(dst, tcg_env, src);
4767199d43efSRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
4768199d43efSRichard Henderson     return advance_pc(dc);
4769199d43efSRichard Henderson }
4770199d43efSRichard Henderson 
4771199d43efSRichard Henderson TRANS(FiTOd, ALL, do_env_df, a, gen_helper_fitod)
4772199d43efSRichard Henderson TRANS(FsTOd, ALL, do_env_df, a, gen_helper_fstod)
4773199d43efSRichard Henderson TRANS(FsTOx, 64, do_env_df, a, gen_helper_fstox)
4774199d43efSRichard Henderson 
4775daf457d4SRichard Henderson static bool do_qq(DisasContext *dc, arg_r_r *a,
4776daf457d4SRichard Henderson                   void (*func)(TCGv_i128, TCGv_i128))
4777f4e18df5SRichard Henderson {
477833ec4245SRichard Henderson     TCGv_i128 t;
4779f4e18df5SRichard Henderson 
4780f4e18df5SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4781f4e18df5SRichard Henderson         return true;
4782f4e18df5SRichard Henderson     }
4783f4e18df5SRichard Henderson     if (gen_trap_float128(dc)) {
4784f4e18df5SRichard Henderson         return true;
4785f4e18df5SRichard Henderson     }
4786f4e18df5SRichard Henderson 
4787f4e18df5SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
478833ec4245SRichard Henderson     t = gen_load_fpr_Q(dc, a->rs);
4789daf457d4SRichard Henderson     func(t, t);
479033ec4245SRichard Henderson     gen_store_fpr_Q(dc, a->rd, t);
4791f4e18df5SRichard Henderson     return advance_pc(dc);
4792f4e18df5SRichard Henderson }
4793f4e18df5SRichard Henderson 
4794daf457d4SRichard Henderson TRANS(FMOVq, 64, do_qq, a, tcg_gen_mov_i128)
4795daf457d4SRichard Henderson TRANS(FNEGq, 64, do_qq, a, gen_op_fnegq)
4796daf457d4SRichard Henderson TRANS(FABSq, 64, do_qq, a, gen_op_fabsq)
4797f4e18df5SRichard Henderson 
4798c995216bSRichard Henderson static bool do_env_qq(DisasContext *dc, arg_r_r *a,
4799e41716beSRichard Henderson                       void (*func)(TCGv_i128, TCGv_env, TCGv_i128))
4800c995216bSRichard Henderson {
4801e41716beSRichard Henderson     TCGv_i128 t;
4802e41716beSRichard Henderson 
4803c995216bSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4804c995216bSRichard Henderson         return true;
4805c995216bSRichard Henderson     }
4806c995216bSRichard Henderson     if (gen_trap_float128(dc)) {
4807c995216bSRichard Henderson         return true;
4808c995216bSRichard Henderson     }
4809c995216bSRichard Henderson 
4810e41716beSRichard Henderson     t = gen_load_fpr_Q(dc, a->rs);
4811e41716beSRichard Henderson     func(t, tcg_env, t);
4812e41716beSRichard Henderson     gen_store_fpr_Q(dc, a->rd, t);
4813c995216bSRichard Henderson     return advance_pc(dc);
4814c995216bSRichard Henderson }
4815c995216bSRichard Henderson 
4816c995216bSRichard Henderson TRANS(FSQRTq, ALL, do_env_qq, a, gen_helper_fsqrtq)
4817c995216bSRichard Henderson 
4818bd9c5c42SRichard Henderson static bool do_env_fq(DisasContext *dc, arg_r_r *a,
4819d81e3efeSRichard Henderson                       void (*func)(TCGv_i32, TCGv_env, TCGv_i128))
4820bd9c5c42SRichard Henderson {
4821d81e3efeSRichard Henderson     TCGv_i128 src;
4822bd9c5c42SRichard Henderson     TCGv_i32 dst;
4823bd9c5c42SRichard Henderson 
4824bd9c5c42SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4825bd9c5c42SRichard Henderson         return true;
4826bd9c5c42SRichard Henderson     }
4827bd9c5c42SRichard Henderson     if (gen_trap_float128(dc)) {
4828bd9c5c42SRichard Henderson         return true;
4829bd9c5c42SRichard Henderson     }
4830bd9c5c42SRichard Henderson 
4831d81e3efeSRichard Henderson     src = gen_load_fpr_Q(dc, a->rs);
4832388a6465SRichard Henderson     dst = tcg_temp_new_i32();
4833d81e3efeSRichard Henderson     func(dst, tcg_env, src);
4834bd9c5c42SRichard Henderson     gen_store_fpr_F(dc, a->rd, dst);
4835bd9c5c42SRichard Henderson     return advance_pc(dc);
4836bd9c5c42SRichard Henderson }
4837bd9c5c42SRichard Henderson 
4838bd9c5c42SRichard Henderson TRANS(FqTOs, ALL, do_env_fq, a, gen_helper_fqtos)
4839bd9c5c42SRichard Henderson TRANS(FqTOi, ALL, do_env_fq, a, gen_helper_fqtoi)
4840bd9c5c42SRichard Henderson 
48411617586fSRichard Henderson static bool do_env_dq(DisasContext *dc, arg_r_r *a,
484225a5769eSRichard Henderson                       void (*func)(TCGv_i64, TCGv_env, TCGv_i128))
48431617586fSRichard Henderson {
484425a5769eSRichard Henderson     TCGv_i128 src;
48451617586fSRichard Henderson     TCGv_i64 dst;
48461617586fSRichard Henderson 
48471617586fSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
48481617586fSRichard Henderson         return true;
48491617586fSRichard Henderson     }
48501617586fSRichard Henderson     if (gen_trap_float128(dc)) {
48511617586fSRichard Henderson         return true;
48521617586fSRichard Henderson     }
48531617586fSRichard Henderson 
485425a5769eSRichard Henderson     src = gen_load_fpr_Q(dc, a->rs);
485552f46d46SRichard Henderson     dst = tcg_temp_new_i64();
485625a5769eSRichard Henderson     func(dst, tcg_env, src);
48571617586fSRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
48581617586fSRichard Henderson     return advance_pc(dc);
48591617586fSRichard Henderson }
48601617586fSRichard Henderson 
48611617586fSRichard Henderson TRANS(FqTOd, ALL, do_env_dq, a, gen_helper_fqtod)
48621617586fSRichard Henderson TRANS(FqTOx, 64, do_env_dq, a, gen_helper_fqtox)
48631617586fSRichard Henderson 
486413ebcc77SRichard Henderson static bool do_env_qf(DisasContext *dc, arg_r_r *a,
48650b2a61ccSRichard Henderson                       void (*func)(TCGv_i128, TCGv_env, TCGv_i32))
486613ebcc77SRichard Henderson {
486713ebcc77SRichard Henderson     TCGv_i32 src;
48680b2a61ccSRichard Henderson     TCGv_i128 dst;
486913ebcc77SRichard Henderson 
487013ebcc77SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
487113ebcc77SRichard Henderson         return true;
487213ebcc77SRichard Henderson     }
487313ebcc77SRichard Henderson     if (gen_trap_float128(dc)) {
487413ebcc77SRichard Henderson         return true;
487513ebcc77SRichard Henderson     }
487613ebcc77SRichard Henderson 
487713ebcc77SRichard Henderson     src = gen_load_fpr_F(dc, a->rs);
48780b2a61ccSRichard Henderson     dst = tcg_temp_new_i128();
48790b2a61ccSRichard Henderson     func(dst, tcg_env, src);
48800b2a61ccSRichard Henderson     gen_store_fpr_Q(dc, a->rd, dst);
488113ebcc77SRichard Henderson     return advance_pc(dc);
488213ebcc77SRichard Henderson }
488313ebcc77SRichard Henderson 
488413ebcc77SRichard Henderson TRANS(FiTOq, ALL, do_env_qf, a, gen_helper_fitoq)
488513ebcc77SRichard Henderson TRANS(FsTOq, ALL, do_env_qf, a, gen_helper_fstoq)
488613ebcc77SRichard Henderson 
48877b8e3e1aSRichard Henderson static bool do_env_qd(DisasContext *dc, arg_r_r *a,
4888fdc50716SRichard Henderson                       void (*func)(TCGv_i128, TCGv_env, TCGv_i64))
48897b8e3e1aSRichard Henderson {
48907b8e3e1aSRichard Henderson     TCGv_i64 src;
4891fdc50716SRichard Henderson     TCGv_i128 dst;
48927b8e3e1aSRichard Henderson 
48937b8e3e1aSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
48947b8e3e1aSRichard Henderson         return true;
48957b8e3e1aSRichard Henderson     }
48967b8e3e1aSRichard Henderson     if (gen_trap_float128(dc)) {
48977b8e3e1aSRichard Henderson         return true;
48987b8e3e1aSRichard Henderson     }
48997b8e3e1aSRichard Henderson 
49007b8e3e1aSRichard Henderson     src = gen_load_fpr_D(dc, a->rs);
4901fdc50716SRichard Henderson     dst = tcg_temp_new_i128();
4902fdc50716SRichard Henderson     func(dst, tcg_env, src);
4903fdc50716SRichard Henderson     gen_store_fpr_Q(dc, a->rd, dst);
49047b8e3e1aSRichard Henderson     return advance_pc(dc);
49057b8e3e1aSRichard Henderson }
49067b8e3e1aSRichard Henderson 
49077b8e3e1aSRichard Henderson TRANS(FdTOq, ALL, do_env_qd, a, gen_helper_fdtoq)
49087b8e3e1aSRichard Henderson TRANS(FxTOq, 64, do_env_qd, a, gen_helper_fxtoq)
49097b8e3e1aSRichard Henderson 
49107f10b52fSRichard Henderson static bool do_fff(DisasContext *dc, arg_r_r_r *a,
49117f10b52fSRichard Henderson                    void (*func)(TCGv_i32, TCGv_i32, TCGv_i32))
49127f10b52fSRichard Henderson {
49137f10b52fSRichard Henderson     TCGv_i32 src1, src2;
49147f10b52fSRichard Henderson 
49157f10b52fSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
49167f10b52fSRichard Henderson         return true;
49177f10b52fSRichard Henderson     }
49187f10b52fSRichard Henderson 
49197f10b52fSRichard Henderson     src1 = gen_load_fpr_F(dc, a->rs1);
49207f10b52fSRichard Henderson     src2 = gen_load_fpr_F(dc, a->rs2);
49217f10b52fSRichard Henderson     func(src1, src1, src2);
49227f10b52fSRichard Henderson     gen_store_fpr_F(dc, a->rd, src1);
49237f10b52fSRichard Henderson     return advance_pc(dc);
49247f10b52fSRichard Henderson }
49257f10b52fSRichard Henderson 
49267f10b52fSRichard Henderson TRANS(FPADD16s, VIS1, do_fff, a, tcg_gen_vec_add16_i32)
49277f10b52fSRichard Henderson TRANS(FPADD32s, VIS1, do_fff, a, tcg_gen_add_i32)
49287f10b52fSRichard Henderson TRANS(FPSUB16s, VIS1, do_fff, a, tcg_gen_vec_sub16_i32)
49297f10b52fSRichard Henderson TRANS(FPSUB32s, VIS1, do_fff, a, tcg_gen_sub_i32)
49307f10b52fSRichard Henderson TRANS(FNORs, VIS1, do_fff, a, tcg_gen_nor_i32)
49317f10b52fSRichard Henderson TRANS(FANDNOTs, VIS1, do_fff, a, tcg_gen_andc_i32)
49327f10b52fSRichard Henderson TRANS(FXORs, VIS1, do_fff, a, tcg_gen_xor_i32)
49337f10b52fSRichard Henderson TRANS(FNANDs, VIS1, do_fff, a, tcg_gen_nand_i32)
49347f10b52fSRichard Henderson TRANS(FANDs, VIS1, do_fff, a, tcg_gen_and_i32)
49357f10b52fSRichard Henderson TRANS(FXNORs, VIS1, do_fff, a, tcg_gen_eqv_i32)
49367f10b52fSRichard Henderson TRANS(FORNOTs, VIS1, do_fff, a, tcg_gen_orc_i32)
49377f10b52fSRichard Henderson TRANS(FORs, VIS1, do_fff, a, tcg_gen_or_i32)
49387f10b52fSRichard Henderson 
49393d50b728SRichard Henderson TRANS(FHADDs, VIS3, do_fff, a, gen_op_fhadds)
49403d50b728SRichard Henderson TRANS(FHSUBs, VIS3, do_fff, a, gen_op_fhsubs)
49413d50b728SRichard Henderson TRANS(FNHADDs, VIS3, do_fff, a, gen_op_fnhadds)
49423d50b728SRichard Henderson 
49430d1d3aafSRichard Henderson TRANS(FPADDS16s, VIS3, do_fff, a, gen_op_fpadds16s)
49440d1d3aafSRichard Henderson TRANS(FPSUBS16s, VIS3, do_fff, a, gen_op_fpsubs16s)
49450d1d3aafSRichard Henderson TRANS(FPADDS32s, VIS3, do_fff, a, gen_op_fpadds32s)
49460d1d3aafSRichard Henderson TRANS(FPSUBS32s, VIS3, do_fff, a, gen_op_fpsubs32s)
49470d1d3aafSRichard Henderson 
4948c1514961SRichard Henderson static bool do_env_fff(DisasContext *dc, arg_r_r_r *a,
4949c1514961SRichard Henderson                        void (*func)(TCGv_i32, TCGv_env, TCGv_i32, TCGv_i32))
4950c1514961SRichard Henderson {
4951c1514961SRichard Henderson     TCGv_i32 src1, src2;
4952c1514961SRichard Henderson 
4953c1514961SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4954c1514961SRichard Henderson         return true;
4955c1514961SRichard Henderson     }
4956c1514961SRichard Henderson 
4957c1514961SRichard Henderson     src1 = gen_load_fpr_F(dc, a->rs1);
4958c1514961SRichard Henderson     src2 = gen_load_fpr_F(dc, a->rs2);
4959c1514961SRichard Henderson     func(src1, tcg_env, src1, src2);
4960c1514961SRichard Henderson     gen_store_fpr_F(dc, a->rd, src1);
4961c1514961SRichard Henderson     return advance_pc(dc);
4962c1514961SRichard Henderson }
4963c1514961SRichard Henderson 
4964c1514961SRichard Henderson TRANS(FADDs, ALL, do_env_fff, a, gen_helper_fadds)
4965c1514961SRichard Henderson TRANS(FSUBs, ALL, do_env_fff, a, gen_helper_fsubs)
4966c1514961SRichard Henderson TRANS(FMULs, ALL, do_env_fff, a, gen_helper_fmuls)
4967c1514961SRichard Henderson TRANS(FDIVs, ALL, do_env_fff, a, gen_helper_fdivs)
49683d50b728SRichard Henderson TRANS(FNADDs, VIS3, do_env_fff, a, gen_helper_fnadds)
49693d50b728SRichard Henderson TRANS(FNMULs, VIS3, do_env_fff, a, gen_helper_fnmuls)
4970c1514961SRichard Henderson 
4971a859602cSRichard Henderson static bool do_dff(DisasContext *dc, arg_r_r_r *a,
4972a859602cSRichard Henderson                    void (*func)(TCGv_i64, TCGv_i32, TCGv_i32))
4973a859602cSRichard Henderson {
4974a859602cSRichard Henderson     TCGv_i64 dst;
4975a859602cSRichard Henderson     TCGv_i32 src1, src2;
4976a859602cSRichard Henderson 
4977a859602cSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4978a859602cSRichard Henderson         return true;
4979a859602cSRichard Henderson     }
4980a859602cSRichard Henderson 
498152f46d46SRichard Henderson     dst = tcg_temp_new_i64();
4982a859602cSRichard Henderson     src1 = gen_load_fpr_F(dc, a->rs1);
4983a859602cSRichard Henderson     src2 = gen_load_fpr_F(dc, a->rs2);
4984a859602cSRichard Henderson     func(dst, src1, src2);
4985a859602cSRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
4986a859602cSRichard Henderson     return advance_pc(dc);
4987a859602cSRichard Henderson }
4988a859602cSRichard Henderson 
4989a859602cSRichard Henderson TRANS(FMUL8x16AU, VIS1, do_dff, a, gen_op_fmul8x16au)
4990a859602cSRichard Henderson TRANS(FMUL8x16AL, VIS1, do_dff, a, gen_op_fmul8x16al)
4991be8998e0SRichard Henderson TRANS(FMULD8SUx16, VIS1, do_dff, a, gen_op_fmuld8sux16)
4992be8998e0SRichard Henderson TRANS(FMULD8ULx16, VIS1, do_dff, a, gen_op_fmuld8ulx16)
4993d3ef26afSRichard Henderson TRANS(FPMERGE, VIS1, do_dff, a, gen_helper_fpmerge)
4994a859602cSRichard Henderson 
49959157dcccSRichard Henderson static bool do_dfd(DisasContext *dc, arg_r_r_r *a,
49969157dcccSRichard Henderson                    void (*func)(TCGv_i64, TCGv_i32, TCGv_i64))
49979157dcccSRichard Henderson {
49989157dcccSRichard Henderson     TCGv_i64 dst, src2;
49999157dcccSRichard Henderson     TCGv_i32 src1;
50009157dcccSRichard Henderson 
50019157dcccSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
50029157dcccSRichard Henderson         return true;
50039157dcccSRichard Henderson     }
50049157dcccSRichard Henderson 
500552f46d46SRichard Henderson     dst = tcg_temp_new_i64();
50069157dcccSRichard Henderson     src1 = gen_load_fpr_F(dc, a->rs1);
50079157dcccSRichard Henderson     src2 = gen_load_fpr_D(dc, a->rs2);
50089157dcccSRichard Henderson     func(dst, src1, src2);
50099157dcccSRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
50109157dcccSRichard Henderson     return advance_pc(dc);
50119157dcccSRichard Henderson }
50129157dcccSRichard Henderson 
50139157dcccSRichard Henderson TRANS(FMUL8x16, VIS1, do_dfd, a, gen_helper_fmul8x16)
50149157dcccSRichard Henderson 
501528c131a3SRichard Henderson static bool do_gvec_ddd(DisasContext *dc, arg_r_r_r *a, MemOp vece,
501628c131a3SRichard Henderson                         void (*func)(unsigned, uint32_t, uint32_t,
501728c131a3SRichard Henderson                                      uint32_t, uint32_t, uint32_t))
501828c131a3SRichard Henderson {
501928c131a3SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
502028c131a3SRichard Henderson         return true;
502128c131a3SRichard Henderson     }
502228c131a3SRichard Henderson 
502328c131a3SRichard Henderson     func(vece, gen_offset_fpr_D(a->rd), gen_offset_fpr_D(a->rs1),
502428c131a3SRichard Henderson          gen_offset_fpr_D(a->rs2), 8, 8);
502528c131a3SRichard Henderson     return advance_pc(dc);
502628c131a3SRichard Henderson }
502728c131a3SRichard Henderson 
502828c131a3SRichard Henderson TRANS(FPADD16, VIS1, do_gvec_ddd, a, MO_16, tcg_gen_gvec_add)
502928c131a3SRichard Henderson TRANS(FPADD32, VIS1, do_gvec_ddd, a, MO_32, tcg_gen_gvec_add)
503028c131a3SRichard Henderson TRANS(FPSUB16, VIS1, do_gvec_ddd, a, MO_16, tcg_gen_gvec_sub)
503128c131a3SRichard Henderson TRANS(FPSUB32, VIS1, do_gvec_ddd, a, MO_32, tcg_gen_gvec_sub)
50327837185eSRichard Henderson TRANS(FCHKSM16, VIS3, do_gvec_ddd, a, MO_16, gen_op_fchksm16)
5033d6ff1ccbSRichard Henderson TRANS(FMEAN16, VIS3, do_gvec_ddd, a, MO_16, gen_op_fmean16)
503428c131a3SRichard Henderson 
50350d1d3aafSRichard Henderson TRANS(FPADDS16, VIS3, do_gvec_ddd, a, MO_16, tcg_gen_gvec_ssadd)
50360d1d3aafSRichard Henderson TRANS(FPADDS32, VIS3, do_gvec_ddd, a, MO_32, tcg_gen_gvec_ssadd)
50370d1d3aafSRichard Henderson TRANS(FPSUBS16, VIS3, do_gvec_ddd, a, MO_16, tcg_gen_gvec_sssub)
50380d1d3aafSRichard Henderson TRANS(FPSUBS32, VIS3, do_gvec_ddd, a, MO_32, tcg_gen_gvec_sssub)
50390d1d3aafSRichard Henderson 
5040fbc5c8d4SRichard Henderson TRANS(FSLL16, VIS3, do_gvec_ddd, a, MO_16, tcg_gen_gvec_shlv)
5041fbc5c8d4SRichard Henderson TRANS(FSLL32, VIS3, do_gvec_ddd, a, MO_32, tcg_gen_gvec_shlv)
5042fbc5c8d4SRichard Henderson TRANS(FSRL16, VIS3, do_gvec_ddd, a, MO_16, tcg_gen_gvec_shrv)
5043fbc5c8d4SRichard Henderson TRANS(FSRL32, VIS3, do_gvec_ddd, a, MO_32, tcg_gen_gvec_shrv)
5044fbc5c8d4SRichard Henderson TRANS(FSRA16, VIS3, do_gvec_ddd, a, MO_16, tcg_gen_gvec_sarv)
5045fbc5c8d4SRichard Henderson TRANS(FSRA32, VIS3, do_gvec_ddd, a, MO_32, tcg_gen_gvec_sarv)
5046fbc5c8d4SRichard Henderson 
5047e06c9f83SRichard Henderson static bool do_ddd(DisasContext *dc, arg_r_r_r *a,
5048e06c9f83SRichard Henderson                    void (*func)(TCGv_i64, TCGv_i64, TCGv_i64))
5049e06c9f83SRichard Henderson {
5050e06c9f83SRichard Henderson     TCGv_i64 dst, src1, src2;
5051e06c9f83SRichard Henderson 
5052e06c9f83SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
5053e06c9f83SRichard Henderson         return true;
5054e06c9f83SRichard Henderson     }
5055e06c9f83SRichard Henderson 
505652f46d46SRichard Henderson     dst = tcg_temp_new_i64();
5057e06c9f83SRichard Henderson     src1 = gen_load_fpr_D(dc, a->rs1);
5058e06c9f83SRichard Henderson     src2 = gen_load_fpr_D(dc, a->rs2);
5059e06c9f83SRichard Henderson     func(dst, src1, src2);
5060e06c9f83SRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
5061e06c9f83SRichard Henderson     return advance_pc(dc);
5062e06c9f83SRichard Henderson }
5063e06c9f83SRichard Henderson 
5064e06c9f83SRichard Henderson TRANS(FMUL8SUx16, VIS1, do_ddd, a, gen_helper_fmul8sux16)
5065e06c9f83SRichard Henderson TRANS(FMUL8ULx16, VIS1, do_ddd, a, gen_helper_fmul8ulx16)
5066e06c9f83SRichard Henderson 
5067e06c9f83SRichard Henderson TRANS(FNORd, VIS1, do_ddd, a, tcg_gen_nor_i64)
5068e06c9f83SRichard Henderson TRANS(FANDNOTd, VIS1, do_ddd, a, tcg_gen_andc_i64)
5069e06c9f83SRichard Henderson TRANS(FXORd, VIS1, do_ddd, a, tcg_gen_xor_i64)
5070e06c9f83SRichard Henderson TRANS(FNANDd, VIS1, do_ddd, a, tcg_gen_nand_i64)
5071e06c9f83SRichard Henderson TRANS(FANDd, VIS1, do_ddd, a, tcg_gen_and_i64)
5072e06c9f83SRichard Henderson TRANS(FXNORd, VIS1, do_ddd, a, tcg_gen_eqv_i64)
5073e06c9f83SRichard Henderson TRANS(FORNOTd, VIS1, do_ddd, a, tcg_gen_orc_i64)
5074e06c9f83SRichard Henderson TRANS(FORd, VIS1, do_ddd, a, tcg_gen_or_i64)
5075e06c9f83SRichard Henderson 
50764b6edc0aSRichard Henderson TRANS(FPACK32, VIS1, do_ddd, a, gen_op_fpack32)
5077*b2b48493SRichard Henderson TRANS(FALIGNDATAg, VIS1, do_ddd, a, gen_op_faligndata_g)
50784b6edc0aSRichard Henderson TRANS(BSHUFFLE, VIS2, do_ddd, a, gen_op_bshuffle)
50794b6edc0aSRichard Henderson 
50803d50b728SRichard Henderson TRANS(FHADDd, VIS3, do_ddd, a, gen_op_fhaddd)
50813d50b728SRichard Henderson TRANS(FHSUBd, VIS3, do_ddd, a, gen_op_fhsubd)
50823d50b728SRichard Henderson TRANS(FNHADDd, VIS3, do_ddd, a, gen_op_fnhaddd)
50833d50b728SRichard Henderson 
5084bc3f14a9SRichard Henderson TRANS(FPADD64, VIS3B, do_ddd, a, tcg_gen_add_i64)
5085bc3f14a9SRichard Henderson TRANS(FPSUB64, VIS3B, do_ddd, a, tcg_gen_sub_i64)
5086fbc5c8d4SRichard Henderson TRANS(FSLAS16, VIS3, do_ddd, a, gen_helper_fslas16)
5087fbc5c8d4SRichard Henderson TRANS(FSLAS32, VIS3, do_ddd, a, gen_helper_fslas32)
5088bc3f14a9SRichard Henderson 
5089e2fa6bd1SRichard Henderson static bool do_rdd(DisasContext *dc, arg_r_r_r *a,
5090e2fa6bd1SRichard Henderson                    void (*func)(TCGv, TCGv_i64, TCGv_i64))
5091e2fa6bd1SRichard Henderson {
5092e2fa6bd1SRichard Henderson     TCGv_i64 src1, src2;
5093e2fa6bd1SRichard Henderson     TCGv dst;
5094e2fa6bd1SRichard Henderson 
5095e2fa6bd1SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
5096e2fa6bd1SRichard Henderson         return true;
5097e2fa6bd1SRichard Henderson     }
5098e2fa6bd1SRichard Henderson 
5099e2fa6bd1SRichard Henderson     dst = gen_dest_gpr(dc, a->rd);
5100e2fa6bd1SRichard Henderson     src1 = gen_load_fpr_D(dc, a->rs1);
5101e2fa6bd1SRichard Henderson     src2 = gen_load_fpr_D(dc, a->rs2);
5102e2fa6bd1SRichard Henderson     func(dst, src1, src2);
5103e2fa6bd1SRichard Henderson     gen_store_gpr(dc, a->rd, dst);
5104e2fa6bd1SRichard Henderson     return advance_pc(dc);
5105e2fa6bd1SRichard Henderson }
5106e2fa6bd1SRichard Henderson 
5107e2fa6bd1SRichard Henderson TRANS(FPCMPLE16, VIS1, do_rdd, a, gen_helper_fcmple16)
5108e2fa6bd1SRichard Henderson TRANS(FPCMPNE16, VIS1, do_rdd, a, gen_helper_fcmpne16)
5109e2fa6bd1SRichard Henderson TRANS(FPCMPGT16, VIS1, do_rdd, a, gen_helper_fcmpgt16)
5110e2fa6bd1SRichard Henderson TRANS(FPCMPEQ16, VIS1, do_rdd, a, gen_helper_fcmpeq16)
5111e2fa6bd1SRichard Henderson 
5112e2fa6bd1SRichard Henderson TRANS(FPCMPLE32, VIS1, do_rdd, a, gen_helper_fcmple32)
5113e2fa6bd1SRichard Henderson TRANS(FPCMPNE32, VIS1, do_rdd, a, gen_helper_fcmpne32)
5114e2fa6bd1SRichard Henderson TRANS(FPCMPGT32, VIS1, do_rdd, a, gen_helper_fcmpgt32)
5115e2fa6bd1SRichard Henderson TRANS(FPCMPEQ32, VIS1, do_rdd, a, gen_helper_fcmpeq32)
5116e2fa6bd1SRichard Henderson 
5117669e0774SRichard Henderson TRANS(FPCMPEQ8, VIS3B, do_rdd, a, gen_helper_fcmpeq8)
5118669e0774SRichard Henderson TRANS(FPCMPNE8, VIS3B, do_rdd, a, gen_helper_fcmpne8)
5119669e0774SRichard Henderson TRANS(FPCMPULE8, VIS3B, do_rdd, a, gen_helper_fcmpule8)
5120669e0774SRichard Henderson TRANS(FPCMPUGT8, VIS3B, do_rdd, a, gen_helper_fcmpugt8)
5121669e0774SRichard Henderson 
51227d5ebd8fSRichard Henderson TRANS(PDISTN, VIS3, do_rdd, a, gen_op_pdistn)
5123029b0283SRichard Henderson TRANS(XMULX, VIS3, do_rrr, a, gen_helper_xmulx)
5124029b0283SRichard Henderson TRANS(XMULXHI, VIS3, do_rrr, a, gen_helper_xmulxhi)
51257d5ebd8fSRichard Henderson 
5126f2a59b0aSRichard Henderson static bool do_env_ddd(DisasContext *dc, arg_r_r_r *a,
5127f2a59b0aSRichard Henderson                        void (*func)(TCGv_i64, TCGv_env, TCGv_i64, TCGv_i64))
5128f2a59b0aSRichard Henderson {
5129f2a59b0aSRichard Henderson     TCGv_i64 dst, src1, src2;
5130f2a59b0aSRichard Henderson 
5131f2a59b0aSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
5132f2a59b0aSRichard Henderson         return true;
5133f2a59b0aSRichard Henderson     }
5134f2a59b0aSRichard Henderson 
513552f46d46SRichard Henderson     dst = tcg_temp_new_i64();
5136f2a59b0aSRichard Henderson     src1 = gen_load_fpr_D(dc, a->rs1);
5137f2a59b0aSRichard Henderson     src2 = gen_load_fpr_D(dc, a->rs2);
5138f2a59b0aSRichard Henderson     func(dst, tcg_env, src1, src2);
5139f2a59b0aSRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
5140f2a59b0aSRichard Henderson     return advance_pc(dc);
5141f2a59b0aSRichard Henderson }
5142f2a59b0aSRichard Henderson 
5143f2a59b0aSRichard Henderson TRANS(FADDd, ALL, do_env_ddd, a, gen_helper_faddd)
5144f2a59b0aSRichard Henderson TRANS(FSUBd, ALL, do_env_ddd, a, gen_helper_fsubd)
5145f2a59b0aSRichard Henderson TRANS(FMULd, ALL, do_env_ddd, a, gen_helper_fmuld)
5146f2a59b0aSRichard Henderson TRANS(FDIVd, ALL, do_env_ddd, a, gen_helper_fdivd)
51473d50b728SRichard Henderson TRANS(FNADDd, VIS3, do_env_ddd, a, gen_helper_fnaddd)
51483d50b728SRichard Henderson TRANS(FNMULd, VIS3, do_env_ddd, a, gen_helper_fnmuld)
5149f2a59b0aSRichard Henderson 
5150ff4c711bSRichard Henderson static bool trans_FsMULd(DisasContext *dc, arg_r_r_r *a)
5151ff4c711bSRichard Henderson {
5152ff4c711bSRichard Henderson     TCGv_i64 dst;
5153ff4c711bSRichard Henderson     TCGv_i32 src1, src2;
5154ff4c711bSRichard Henderson 
5155ff4c711bSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
5156ff4c711bSRichard Henderson         return true;
5157ff4c711bSRichard Henderson     }
5158ff4c711bSRichard Henderson     if (!(dc->def->features & CPU_FEATURE_FSMULD)) {
5159ff4c711bSRichard Henderson         return raise_unimpfpop(dc);
5160ff4c711bSRichard Henderson     }
5161ff4c711bSRichard Henderson 
516252f46d46SRichard Henderson     dst = tcg_temp_new_i64();
5163ff4c711bSRichard Henderson     src1 = gen_load_fpr_F(dc, a->rs1);
5164ff4c711bSRichard Henderson     src2 = gen_load_fpr_F(dc, a->rs2);
5165ff4c711bSRichard Henderson     gen_helper_fsmuld(dst, tcg_env, src1, src2);
5166ff4c711bSRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
5167ff4c711bSRichard Henderson     return advance_pc(dc);
5168ff4c711bSRichard Henderson }
5169ff4c711bSRichard Henderson 
51703d50b728SRichard Henderson static bool trans_FNsMULd(DisasContext *dc, arg_r_r_r *a)
51713d50b728SRichard Henderson {
51723d50b728SRichard Henderson     TCGv_i64 dst;
51733d50b728SRichard Henderson     TCGv_i32 src1, src2;
51743d50b728SRichard Henderson 
51753d50b728SRichard Henderson     if (!avail_VIS3(dc)) {
51763d50b728SRichard Henderson         return false;
51773d50b728SRichard Henderson     }
51783d50b728SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
51793d50b728SRichard Henderson         return true;
51803d50b728SRichard Henderson     }
51813d50b728SRichard Henderson     dst = tcg_temp_new_i64();
51823d50b728SRichard Henderson     src1 = gen_load_fpr_F(dc, a->rs1);
51833d50b728SRichard Henderson     src2 = gen_load_fpr_F(dc, a->rs2);
51843d50b728SRichard Henderson     gen_helper_fnsmuld(dst, tcg_env, src1, src2);
51853d50b728SRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
51863d50b728SRichard Henderson     return advance_pc(dc);
51873d50b728SRichard Henderson }
51883d50b728SRichard Henderson 
51894fd71d19SRichard Henderson static bool do_ffff(DisasContext *dc, arg_r_r_r_r *a,
51904fd71d19SRichard Henderson                     void (*func)(TCGv_i32, TCGv_i32, TCGv_i32, TCGv_i32))
51914fd71d19SRichard Henderson {
51924fd71d19SRichard Henderson     TCGv_i32 dst, src1, src2, src3;
51934fd71d19SRichard Henderson 
51944fd71d19SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
51954fd71d19SRichard Henderson         return true;
51964fd71d19SRichard Henderson     }
51974fd71d19SRichard Henderson 
51984fd71d19SRichard Henderson     src1 = gen_load_fpr_F(dc, a->rs1);
51994fd71d19SRichard Henderson     src2 = gen_load_fpr_F(dc, a->rs2);
52004fd71d19SRichard Henderson     src3 = gen_load_fpr_F(dc, a->rs3);
52014fd71d19SRichard Henderson     dst = tcg_temp_new_i32();
52024fd71d19SRichard Henderson     func(dst, src1, src2, src3);
52034fd71d19SRichard Henderson     gen_store_fpr_F(dc, a->rd, dst);
52044fd71d19SRichard Henderson     return advance_pc(dc);
52054fd71d19SRichard Henderson }
52064fd71d19SRichard Henderson 
52074fd71d19SRichard Henderson TRANS(FMADDs, FMAF, do_ffff, a, gen_op_fmadds)
52084fd71d19SRichard Henderson TRANS(FMSUBs, FMAF, do_ffff, a, gen_op_fmsubs)
52094fd71d19SRichard Henderson TRANS(FNMSUBs, FMAF, do_ffff, a, gen_op_fnmsubs)
52104fd71d19SRichard Henderson TRANS(FNMADDs, FMAF, do_ffff, a, gen_op_fnmadds)
52114fd71d19SRichard Henderson 
52124fd71d19SRichard Henderson static bool do_dddd(DisasContext *dc, arg_r_r_r_r *a,
5213afb04344SRichard Henderson                     void (*func)(TCGv_i64, TCGv_i64, TCGv_i64, TCGv_i64))
5214afb04344SRichard Henderson {
52154fd71d19SRichard Henderson     TCGv_i64 dst, src1, src2, src3;
5216afb04344SRichard Henderson 
5217afb04344SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
5218afb04344SRichard Henderson         return true;
5219afb04344SRichard Henderson     }
5220afb04344SRichard Henderson 
522152f46d46SRichard Henderson     dst  = tcg_temp_new_i64();
5222afb04344SRichard Henderson     src1 = gen_load_fpr_D(dc, a->rs1);
5223afb04344SRichard Henderson     src2 = gen_load_fpr_D(dc, a->rs2);
52244fd71d19SRichard Henderson     src3 = gen_load_fpr_D(dc, a->rs3);
52254fd71d19SRichard Henderson     func(dst, src1, src2, src3);
5226afb04344SRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
5227afb04344SRichard Henderson     return advance_pc(dc);
5228afb04344SRichard Henderson }
5229afb04344SRichard Henderson 
5230afb04344SRichard Henderson TRANS(PDIST, VIS1, do_dddd, a, gen_helper_pdist)
52314fd71d19SRichard Henderson TRANS(FMADDd, FMAF, do_dddd, a, gen_op_fmaddd)
52324fd71d19SRichard Henderson TRANS(FMSUBd, FMAF, do_dddd, a, gen_op_fmsubd)
52334fd71d19SRichard Henderson TRANS(FNMSUBd, FMAF, do_dddd, a, gen_op_fnmsubd)
52344fd71d19SRichard Henderson TRANS(FNMADDd, FMAF, do_dddd, a, gen_op_fnmaddd)
523568a414e9SRichard Henderson TRANS(FPMADDX, IMA, do_dddd, a, gen_op_fpmaddx)
523668a414e9SRichard Henderson TRANS(FPMADDXHI, IMA, do_dddd, a, gen_op_fpmaddxhi)
5237afb04344SRichard Henderson 
5238*b2b48493SRichard Henderson static bool trans_FALIGNDATAi(DisasContext *dc, arg_r_r_r *a)
5239*b2b48493SRichard Henderson {
5240*b2b48493SRichard Henderson     TCGv_i64 dst, src1, src2;
5241*b2b48493SRichard Henderson     TCGv src3;
5242*b2b48493SRichard Henderson 
5243*b2b48493SRichard Henderson     if (!avail_VIS4(dc)) {
5244*b2b48493SRichard Henderson         return false;
5245*b2b48493SRichard Henderson     }
5246*b2b48493SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
5247*b2b48493SRichard Henderson         return true;
5248*b2b48493SRichard Henderson     }
5249*b2b48493SRichard Henderson 
5250*b2b48493SRichard Henderson     dst  = tcg_temp_new_i64();
5251*b2b48493SRichard Henderson     src1 = gen_load_fpr_D(dc, a->rd);
5252*b2b48493SRichard Henderson     src2 = gen_load_fpr_D(dc, a->rs2);
5253*b2b48493SRichard Henderson     src3 = gen_load_gpr(dc, a->rs1);
5254*b2b48493SRichard Henderson     gen_op_faligndata_i(dst, src1, src2, src3);
5255*b2b48493SRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
5256*b2b48493SRichard Henderson     return advance_pc(dc);
5257*b2b48493SRichard Henderson }
5258*b2b48493SRichard Henderson 
5259a4056239SRichard Henderson static bool do_env_qqq(DisasContext *dc, arg_r_r_r *a,
526016bedf89SRichard Henderson                        void (*func)(TCGv_i128, TCGv_env, TCGv_i128, TCGv_i128))
5261a4056239SRichard Henderson {
526216bedf89SRichard Henderson     TCGv_i128 src1, src2;
526316bedf89SRichard Henderson 
5264a4056239SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
5265a4056239SRichard Henderson         return true;
5266a4056239SRichard Henderson     }
5267a4056239SRichard Henderson     if (gen_trap_float128(dc)) {
5268a4056239SRichard Henderson         return true;
5269a4056239SRichard Henderson     }
5270a4056239SRichard Henderson 
527116bedf89SRichard Henderson     src1 = gen_load_fpr_Q(dc, a->rs1);
527216bedf89SRichard Henderson     src2 = gen_load_fpr_Q(dc, a->rs2);
527316bedf89SRichard Henderson     func(src1, tcg_env, src1, src2);
527416bedf89SRichard Henderson     gen_store_fpr_Q(dc, a->rd, src1);
5275a4056239SRichard Henderson     return advance_pc(dc);
5276a4056239SRichard Henderson }
5277a4056239SRichard Henderson 
5278a4056239SRichard Henderson TRANS(FADDq, ALL, do_env_qqq, a, gen_helper_faddq)
5279a4056239SRichard Henderson TRANS(FSUBq, ALL, do_env_qqq, a, gen_helper_fsubq)
5280a4056239SRichard Henderson TRANS(FMULq, ALL, do_env_qqq, a, gen_helper_fmulq)
5281a4056239SRichard Henderson TRANS(FDIVq, ALL, do_env_qqq, a, gen_helper_fdivq)
5282a4056239SRichard Henderson 
52835e3b17bbSRichard Henderson static bool trans_FdMULq(DisasContext *dc, arg_r_r_r *a)
52845e3b17bbSRichard Henderson {
52855e3b17bbSRichard Henderson     TCGv_i64 src1, src2;
5286ba21dc99SRichard Henderson     TCGv_i128 dst;
52875e3b17bbSRichard Henderson 
52885e3b17bbSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
52895e3b17bbSRichard Henderson         return true;
52905e3b17bbSRichard Henderson     }
52915e3b17bbSRichard Henderson     if (gen_trap_float128(dc)) {
52925e3b17bbSRichard Henderson         return true;
52935e3b17bbSRichard Henderson     }
52945e3b17bbSRichard Henderson 
52955e3b17bbSRichard Henderson     src1 = gen_load_fpr_D(dc, a->rs1);
52965e3b17bbSRichard Henderson     src2 = gen_load_fpr_D(dc, a->rs2);
5297ba21dc99SRichard Henderson     dst = tcg_temp_new_i128();
5298ba21dc99SRichard Henderson     gen_helper_fdmulq(dst, tcg_env, src1, src2);
5299ba21dc99SRichard Henderson     gen_store_fpr_Q(dc, a->rd, dst);
53005e3b17bbSRichard Henderson     return advance_pc(dc);
53015e3b17bbSRichard Henderson }
53025e3b17bbSRichard Henderson 
5303f7ec8155SRichard Henderson static bool do_fmovr(DisasContext *dc, arg_FMOVRs *a, bool is_128,
5304f7ec8155SRichard Henderson                      void (*func)(DisasContext *, DisasCompare *, int, int))
5305f7ec8155SRichard Henderson {
5306f7ec8155SRichard Henderson     DisasCompare cmp;
5307f7ec8155SRichard Henderson 
53082c4f56c9SRichard Henderson     if (!gen_compare_reg(&cmp, a->cond, gen_load_gpr(dc, a->rs1))) {
53092c4f56c9SRichard Henderson         return false;
53102c4f56c9SRichard Henderson     }
5311f7ec8155SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
5312f7ec8155SRichard Henderson         return true;
5313f7ec8155SRichard Henderson     }
5314f7ec8155SRichard Henderson     if (is_128 && gen_trap_float128(dc)) {
5315f7ec8155SRichard Henderson         return true;
5316f7ec8155SRichard Henderson     }
5317f7ec8155SRichard Henderson 
5318f7ec8155SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
5319f7ec8155SRichard Henderson     func(dc, &cmp, a->rd, a->rs2);
5320f7ec8155SRichard Henderson     return advance_pc(dc);
5321f7ec8155SRichard Henderson }
5322f7ec8155SRichard Henderson 
5323f7ec8155SRichard Henderson TRANS(FMOVRs, 64, do_fmovr, a, false, gen_fmovs)
5324f7ec8155SRichard Henderson TRANS(FMOVRd, 64, do_fmovr, a, false, gen_fmovd)
5325f7ec8155SRichard Henderson TRANS(FMOVRq, 64, do_fmovr, a, true, gen_fmovq)
5326f7ec8155SRichard Henderson 
5327f7ec8155SRichard Henderson static bool do_fmovcc(DisasContext *dc, arg_FMOVscc *a, bool is_128,
5328f7ec8155SRichard Henderson                       void (*func)(DisasContext *, DisasCompare *, int, int))
5329f7ec8155SRichard Henderson {
5330f7ec8155SRichard Henderson     DisasCompare cmp;
5331f7ec8155SRichard Henderson 
5332f7ec8155SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
5333f7ec8155SRichard Henderson         return true;
5334f7ec8155SRichard Henderson     }
5335f7ec8155SRichard Henderson     if (is_128 && gen_trap_float128(dc)) {
5336f7ec8155SRichard Henderson         return true;
5337f7ec8155SRichard Henderson     }
5338f7ec8155SRichard Henderson 
5339f7ec8155SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
5340f7ec8155SRichard Henderson     gen_compare(&cmp, a->cc, a->cond, dc);
5341f7ec8155SRichard Henderson     func(dc, &cmp, a->rd, a->rs2);
5342f7ec8155SRichard Henderson     return advance_pc(dc);
5343f7ec8155SRichard Henderson }
5344f7ec8155SRichard Henderson 
5345f7ec8155SRichard Henderson TRANS(FMOVscc, 64, do_fmovcc, a, false, gen_fmovs)
5346f7ec8155SRichard Henderson TRANS(FMOVdcc, 64, do_fmovcc, a, false, gen_fmovd)
5347f7ec8155SRichard Henderson TRANS(FMOVqcc, 64, do_fmovcc, a, true, gen_fmovq)
5348f7ec8155SRichard Henderson 
5349f7ec8155SRichard Henderson static bool do_fmovfcc(DisasContext *dc, arg_FMOVsfcc *a, bool is_128,
5350f7ec8155SRichard Henderson                        void (*func)(DisasContext *, DisasCompare *, int, int))
5351f7ec8155SRichard Henderson {
5352f7ec8155SRichard Henderson     DisasCompare cmp;
5353f7ec8155SRichard Henderson 
5354f7ec8155SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
5355f7ec8155SRichard Henderson         return true;
5356f7ec8155SRichard Henderson     }
5357f7ec8155SRichard Henderson     if (is_128 && gen_trap_float128(dc)) {
5358f7ec8155SRichard Henderson         return true;
5359f7ec8155SRichard Henderson     }
5360f7ec8155SRichard Henderson 
5361f7ec8155SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
5362f7ec8155SRichard Henderson     gen_fcompare(&cmp, a->cc, a->cond);
5363f7ec8155SRichard Henderson     func(dc, &cmp, a->rd, a->rs2);
5364f7ec8155SRichard Henderson     return advance_pc(dc);
5365f7ec8155SRichard Henderson }
5366f7ec8155SRichard Henderson 
5367f7ec8155SRichard Henderson TRANS(FMOVsfcc, 64, do_fmovfcc, a, false, gen_fmovs)
5368f7ec8155SRichard Henderson TRANS(FMOVdfcc, 64, do_fmovfcc, a, false, gen_fmovd)
5369f7ec8155SRichard Henderson TRANS(FMOVqfcc, 64, do_fmovfcc, a, true, gen_fmovq)
5370f7ec8155SRichard Henderson 
537140f9ad21SRichard Henderson static bool do_fcmps(DisasContext *dc, arg_FCMPs *a, bool e)
537240f9ad21SRichard Henderson {
537340f9ad21SRichard Henderson     TCGv_i32 src1, src2;
537440f9ad21SRichard Henderson 
537540f9ad21SRichard Henderson     if (avail_32(dc) && a->cc != 0) {
537640f9ad21SRichard Henderson         return false;
537740f9ad21SRichard Henderson     }
537840f9ad21SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
537940f9ad21SRichard Henderson         return true;
538040f9ad21SRichard Henderson     }
538140f9ad21SRichard Henderson 
538240f9ad21SRichard Henderson     src1 = gen_load_fpr_F(dc, a->rs1);
538340f9ad21SRichard Henderson     src2 = gen_load_fpr_F(dc, a->rs2);
538440f9ad21SRichard Henderson     if (e) {
5385d8c5b92fSRichard Henderson         gen_helper_fcmpes(cpu_fcc[a->cc], tcg_env, src1, src2);
538640f9ad21SRichard Henderson     } else {
5387d8c5b92fSRichard Henderson         gen_helper_fcmps(cpu_fcc[a->cc], tcg_env, src1, src2);
538840f9ad21SRichard Henderson     }
538940f9ad21SRichard Henderson     return advance_pc(dc);
539040f9ad21SRichard Henderson }
539140f9ad21SRichard Henderson 
539240f9ad21SRichard Henderson TRANS(FCMPs, ALL, do_fcmps, a, false)
539340f9ad21SRichard Henderson TRANS(FCMPEs, ALL, do_fcmps, a, true)
539440f9ad21SRichard Henderson 
539540f9ad21SRichard Henderson static bool do_fcmpd(DisasContext *dc, arg_FCMPd *a, bool e)
539640f9ad21SRichard Henderson {
539740f9ad21SRichard Henderson     TCGv_i64 src1, src2;
539840f9ad21SRichard Henderson 
539940f9ad21SRichard Henderson     if (avail_32(dc) && a->cc != 0) {
540040f9ad21SRichard Henderson         return false;
540140f9ad21SRichard Henderson     }
540240f9ad21SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
540340f9ad21SRichard Henderson         return true;
540440f9ad21SRichard Henderson     }
540540f9ad21SRichard Henderson 
540640f9ad21SRichard Henderson     src1 = gen_load_fpr_D(dc, a->rs1);
540740f9ad21SRichard Henderson     src2 = gen_load_fpr_D(dc, a->rs2);
540840f9ad21SRichard Henderson     if (e) {
5409d8c5b92fSRichard Henderson         gen_helper_fcmped(cpu_fcc[a->cc], tcg_env, src1, src2);
541040f9ad21SRichard Henderson     } else {
5411d8c5b92fSRichard Henderson         gen_helper_fcmpd(cpu_fcc[a->cc], tcg_env, src1, src2);
541240f9ad21SRichard Henderson     }
541340f9ad21SRichard Henderson     return advance_pc(dc);
541440f9ad21SRichard Henderson }
541540f9ad21SRichard Henderson 
541640f9ad21SRichard Henderson TRANS(FCMPd, ALL, do_fcmpd, a, false)
541740f9ad21SRichard Henderson TRANS(FCMPEd, ALL, do_fcmpd, a, true)
541840f9ad21SRichard Henderson 
541940f9ad21SRichard Henderson static bool do_fcmpq(DisasContext *dc, arg_FCMPq *a, bool e)
542040f9ad21SRichard Henderson {
5421f3ceafadSRichard Henderson     TCGv_i128 src1, src2;
5422f3ceafadSRichard Henderson 
542340f9ad21SRichard Henderson     if (avail_32(dc) && a->cc != 0) {
542440f9ad21SRichard Henderson         return false;
542540f9ad21SRichard Henderson     }
542640f9ad21SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
542740f9ad21SRichard Henderson         return true;
542840f9ad21SRichard Henderson     }
542940f9ad21SRichard Henderson     if (gen_trap_float128(dc)) {
543040f9ad21SRichard Henderson         return true;
543140f9ad21SRichard Henderson     }
543240f9ad21SRichard Henderson 
5433f3ceafadSRichard Henderson     src1 = gen_load_fpr_Q(dc, a->rs1);
5434f3ceafadSRichard Henderson     src2 = gen_load_fpr_Q(dc, a->rs2);
543540f9ad21SRichard Henderson     if (e) {
5436d8c5b92fSRichard Henderson         gen_helper_fcmpeq(cpu_fcc[a->cc], tcg_env, src1, src2);
543740f9ad21SRichard Henderson     } else {
5438d8c5b92fSRichard Henderson         gen_helper_fcmpq(cpu_fcc[a->cc], tcg_env, src1, src2);
543940f9ad21SRichard Henderson     }
544040f9ad21SRichard Henderson     return advance_pc(dc);
544140f9ad21SRichard Henderson }
544240f9ad21SRichard Henderson 
544340f9ad21SRichard Henderson TRANS(FCMPq, ALL, do_fcmpq, a, false)
544440f9ad21SRichard Henderson TRANS(FCMPEq, ALL, do_fcmpq, a, true)
544540f9ad21SRichard Henderson 
54461d3ed3d7SRichard Henderson static bool trans_FLCMPs(DisasContext *dc, arg_FLCMPs *a)
54471d3ed3d7SRichard Henderson {
54481d3ed3d7SRichard Henderson     TCGv_i32 src1, src2;
54491d3ed3d7SRichard Henderson 
54501d3ed3d7SRichard Henderson     if (!avail_VIS3(dc)) {
54511d3ed3d7SRichard Henderson         return false;
54521d3ed3d7SRichard Henderson     }
54531d3ed3d7SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
54541d3ed3d7SRichard Henderson         return true;
54551d3ed3d7SRichard Henderson     }
54561d3ed3d7SRichard Henderson 
54571d3ed3d7SRichard Henderson     src1 = gen_load_fpr_F(dc, a->rs1);
54581d3ed3d7SRichard Henderson     src2 = gen_load_fpr_F(dc, a->rs2);
54591d3ed3d7SRichard Henderson     gen_helper_flcmps(cpu_fcc[a->cc], src1, src2);
54601d3ed3d7SRichard Henderson     return advance_pc(dc);
54611d3ed3d7SRichard Henderson }
54621d3ed3d7SRichard Henderson 
54631d3ed3d7SRichard Henderson static bool trans_FLCMPd(DisasContext *dc, arg_FLCMPd *a)
54641d3ed3d7SRichard Henderson {
54651d3ed3d7SRichard Henderson     TCGv_i64 src1, src2;
54661d3ed3d7SRichard Henderson 
54671d3ed3d7SRichard Henderson     if (!avail_VIS3(dc)) {
54681d3ed3d7SRichard Henderson         return false;
54691d3ed3d7SRichard Henderson     }
54701d3ed3d7SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
54711d3ed3d7SRichard Henderson         return true;
54721d3ed3d7SRichard Henderson     }
54731d3ed3d7SRichard Henderson 
54741d3ed3d7SRichard Henderson     src1 = gen_load_fpr_D(dc, a->rs1);
54751d3ed3d7SRichard Henderson     src2 = gen_load_fpr_D(dc, a->rs2);
54761d3ed3d7SRichard Henderson     gen_helper_flcmpd(cpu_fcc[a->cc], src1, src2);
54771d3ed3d7SRichard Henderson     return advance_pc(dc);
54781d3ed3d7SRichard Henderson }
54791d3ed3d7SRichard Henderson 
548009b157e6SRichard Henderson static bool do_movf2r(DisasContext *dc, arg_r_r *a,
548109b157e6SRichard Henderson                       int (*offset)(unsigned int),
548209b157e6SRichard Henderson                       void (*load)(TCGv, TCGv_ptr, tcg_target_long))
548309b157e6SRichard Henderson {
548409b157e6SRichard Henderson     TCGv dst;
548509b157e6SRichard Henderson 
548609b157e6SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
548709b157e6SRichard Henderson         return true;
548809b157e6SRichard Henderson     }
548909b157e6SRichard Henderson     dst = gen_dest_gpr(dc, a->rd);
549009b157e6SRichard Henderson     load(dst, tcg_env, offset(a->rs));
549109b157e6SRichard Henderson     gen_store_gpr(dc, a->rd, dst);
549209b157e6SRichard Henderson     return advance_pc(dc);
549309b157e6SRichard Henderson }
549409b157e6SRichard Henderson 
549509b157e6SRichard Henderson TRANS(MOVsTOsw, VIS3B, do_movf2r, a, gen_offset_fpr_F, tcg_gen_ld32s_tl)
549609b157e6SRichard Henderson TRANS(MOVsTOuw, VIS3B, do_movf2r, a, gen_offset_fpr_F, tcg_gen_ld32u_tl)
549709b157e6SRichard Henderson TRANS(MOVdTOx, VIS3B, do_movf2r, a, gen_offset_fpr_D, tcg_gen_ld_tl)
549809b157e6SRichard Henderson 
549909b157e6SRichard Henderson static bool do_movr2f(DisasContext *dc, arg_r_r *a,
550009b157e6SRichard Henderson                       int (*offset)(unsigned int),
550109b157e6SRichard Henderson                       void (*store)(TCGv, TCGv_ptr, tcg_target_long))
550209b157e6SRichard Henderson {
550309b157e6SRichard Henderson     TCGv src;
550409b157e6SRichard Henderson 
550509b157e6SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
550609b157e6SRichard Henderson         return true;
550709b157e6SRichard Henderson     }
550809b157e6SRichard Henderson     src = gen_load_gpr(dc, a->rs);
550909b157e6SRichard Henderson     store(src, tcg_env, offset(a->rd));
551009b157e6SRichard Henderson     return advance_pc(dc);
551109b157e6SRichard Henderson }
551209b157e6SRichard Henderson 
551309b157e6SRichard Henderson TRANS(MOVwTOs, VIS3B, do_movr2f, a, gen_offset_fpr_F, tcg_gen_st32_tl)
551409b157e6SRichard Henderson TRANS(MOVxTOd, VIS3B, do_movr2f, a, gen_offset_fpr_D, tcg_gen_st_tl)
551509b157e6SRichard Henderson 
55166e61bc94SEmilio G. Cota static void sparc_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
5517fcf5ef2aSThomas Huth {
55186e61bc94SEmilio G. Cota     DisasContext *dc = container_of(dcbase, DisasContext, base);
55196e61bc94SEmilio G. Cota     int bound;
5520af00be49SEmilio G. Cota 
5521af00be49SEmilio G. Cota     dc->pc = dc->base.pc_first;
55226e61bc94SEmilio G. Cota     dc->npc = (target_ulong)dc->base.tb->cs_base;
55236e61bc94SEmilio G. Cota     dc->mem_idx = dc->base.tb->flags & TB_FLAG_MMU_MASK;
552477976769SPhilippe Mathieu-Daudé     dc->def = &cpu_env(cs)->def;
55256e61bc94SEmilio G. Cota     dc->fpu_enabled = tb_fpu_enabled(dc->base.tb->flags);
55266e61bc94SEmilio G. Cota     dc->address_mask_32bit = tb_am_enabled(dc->base.tb->flags);
5527c9b459aaSArtyom Tarasenko #ifndef CONFIG_USER_ONLY
55286e61bc94SEmilio G. Cota     dc->supervisor = (dc->base.tb->flags & TB_FLAG_SUPER) != 0;
5529c9b459aaSArtyom Tarasenko #endif
5530fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
5531fcf5ef2aSThomas Huth     dc->fprs_dirty = 0;
55326e61bc94SEmilio G. Cota     dc->asi = (dc->base.tb->flags >> TB_FLAG_ASI_SHIFT) & 0xff;
5533c9b459aaSArtyom Tarasenko #ifndef CONFIG_USER_ONLY
55346e61bc94SEmilio G. Cota     dc->hypervisor = (dc->base.tb->flags & TB_FLAG_HYPER) != 0;
5535c9b459aaSArtyom Tarasenko #endif
5536fcf5ef2aSThomas Huth #endif
55376e61bc94SEmilio G. Cota     /*
55386e61bc94SEmilio G. Cota      * if we reach a page boundary, we stop generation so that the
55396e61bc94SEmilio G. Cota      * PC of a TT_TFAULT exception is always in the right page
55406e61bc94SEmilio G. Cota      */
55416e61bc94SEmilio G. Cota     bound = -(dc->base.pc_first | TARGET_PAGE_MASK) / 4;
55426e61bc94SEmilio G. Cota     dc->base.max_insns = MIN(dc->base.max_insns, bound);
5543af00be49SEmilio G. Cota }
5544fcf5ef2aSThomas Huth 
55456e61bc94SEmilio G. Cota static void sparc_tr_tb_start(DisasContextBase *db, CPUState *cs)
55466e61bc94SEmilio G. Cota {
55476e61bc94SEmilio G. Cota }
55486e61bc94SEmilio G. Cota 
55496e61bc94SEmilio G. Cota static void sparc_tr_insn_start(DisasContextBase *dcbase, CPUState *cs)
55506e61bc94SEmilio G. Cota {
55516e61bc94SEmilio G. Cota     DisasContext *dc = container_of(dcbase, DisasContext, base);
5552633c4283SRichard Henderson     target_ulong npc = dc->npc;
55536e61bc94SEmilio G. Cota 
5554633c4283SRichard Henderson     if (npc & 3) {
5555633c4283SRichard Henderson         switch (npc) {
5556633c4283SRichard Henderson         case JUMP_PC:
5557fcf5ef2aSThomas Huth             assert(dc->jump_pc[1] == dc->pc + 4);
5558633c4283SRichard Henderson             npc = dc->jump_pc[0] | JUMP_PC;
5559633c4283SRichard Henderson             break;
5560633c4283SRichard Henderson         case DYNAMIC_PC:
5561633c4283SRichard Henderson         case DYNAMIC_PC_LOOKUP:
5562633c4283SRichard Henderson             npc = DYNAMIC_PC;
5563633c4283SRichard Henderson             break;
5564633c4283SRichard Henderson         default:
5565633c4283SRichard Henderson             g_assert_not_reached();
5566fcf5ef2aSThomas Huth         }
55676e61bc94SEmilio G. Cota     }
5568633c4283SRichard Henderson     tcg_gen_insn_start(dc->pc, npc);
5569633c4283SRichard Henderson }
5570fcf5ef2aSThomas Huth 
55716e61bc94SEmilio G. Cota static void sparc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs)
55726e61bc94SEmilio G. Cota {
55736e61bc94SEmilio G. Cota     DisasContext *dc = container_of(dcbase, DisasContext, base);
55746e61bc94SEmilio G. Cota     unsigned int insn;
5575fcf5ef2aSThomas Huth 
557677976769SPhilippe Mathieu-Daudé     insn = translator_ldl(cpu_env(cs), &dc->base, dc->pc);
5577af00be49SEmilio G. Cota     dc->base.pc_next += 4;
5578878cc677SRichard Henderson 
5579878cc677SRichard Henderson     if (!decode(dc, insn)) {
5580ba9c09b4SRichard Henderson         gen_exception(dc, TT_ILL_INSN);
5581878cc677SRichard Henderson     }
5582fcf5ef2aSThomas Huth 
5583af00be49SEmilio G. Cota     if (dc->base.is_jmp == DISAS_NORETURN) {
55846e61bc94SEmilio G. Cota         return;
5585c5e6ccdfSEmilio G. Cota     }
5586af00be49SEmilio G. Cota     if (dc->pc != dc->base.pc_next) {
55876e61bc94SEmilio G. Cota         dc->base.is_jmp = DISAS_TOO_MANY;
5588af00be49SEmilio G. Cota     }
55896e61bc94SEmilio G. Cota }
5590fcf5ef2aSThomas Huth 
55916e61bc94SEmilio G. Cota static void sparc_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)
55926e61bc94SEmilio G. Cota {
55936e61bc94SEmilio G. Cota     DisasContext *dc = container_of(dcbase, DisasContext, base);
5594186e7890SRichard Henderson     DisasDelayException *e, *e_next;
5595633c4283SRichard Henderson     bool may_lookup;
55966e61bc94SEmilio G. Cota 
559789527e3aSRichard Henderson     finishing_insn(dc);
559889527e3aSRichard Henderson 
559946bb0137SMark Cave-Ayland     switch (dc->base.is_jmp) {
560046bb0137SMark Cave-Ayland     case DISAS_NEXT:
560146bb0137SMark Cave-Ayland     case DISAS_TOO_MANY:
5602633c4283SRichard Henderson         if (((dc->pc | dc->npc) & 3) == 0) {
5603fcf5ef2aSThomas Huth             /* static PC and NPC: we can use direct chaining */
5604fcf5ef2aSThomas Huth             gen_goto_tb(dc, 0, dc->pc, dc->npc);
5605633c4283SRichard Henderson             break;
5606fcf5ef2aSThomas Huth         }
5607633c4283SRichard Henderson 
5608930f1865SRichard Henderson         may_lookup = true;
5609633c4283SRichard Henderson         if (dc->pc & 3) {
5610633c4283SRichard Henderson             switch (dc->pc) {
5611633c4283SRichard Henderson             case DYNAMIC_PC_LOOKUP:
5612633c4283SRichard Henderson                 break;
5613633c4283SRichard Henderson             case DYNAMIC_PC:
5614633c4283SRichard Henderson                 may_lookup = false;
5615633c4283SRichard Henderson                 break;
5616633c4283SRichard Henderson             default:
5617633c4283SRichard Henderson                 g_assert_not_reached();
5618633c4283SRichard Henderson             }
5619633c4283SRichard Henderson         } else {
5620633c4283SRichard Henderson             tcg_gen_movi_tl(cpu_pc, dc->pc);
5621633c4283SRichard Henderson         }
5622633c4283SRichard Henderson 
5623930f1865SRichard Henderson         if (dc->npc & 3) {
5624930f1865SRichard Henderson             switch (dc->npc) {
5625930f1865SRichard Henderson             case JUMP_PC:
5626930f1865SRichard Henderson                 gen_generic_branch(dc);
5627930f1865SRichard Henderson                 break;
5628930f1865SRichard Henderson             case DYNAMIC_PC:
5629930f1865SRichard Henderson                 may_lookup = false;
5630930f1865SRichard Henderson                 break;
5631930f1865SRichard Henderson             case DYNAMIC_PC_LOOKUP:
5632930f1865SRichard Henderson                 break;
5633930f1865SRichard Henderson             default:
5634930f1865SRichard Henderson                 g_assert_not_reached();
5635930f1865SRichard Henderson             }
5636930f1865SRichard Henderson         } else {
5637930f1865SRichard Henderson             tcg_gen_movi_tl(cpu_npc, dc->npc);
5638930f1865SRichard Henderson         }
5639633c4283SRichard Henderson         if (may_lookup) {
5640633c4283SRichard Henderson             tcg_gen_lookup_and_goto_ptr();
5641633c4283SRichard Henderson         } else {
564207ea28b4SRichard Henderson             tcg_gen_exit_tb(NULL, 0);
5643fcf5ef2aSThomas Huth         }
564446bb0137SMark Cave-Ayland         break;
564546bb0137SMark Cave-Ayland 
564646bb0137SMark Cave-Ayland     case DISAS_NORETURN:
564746bb0137SMark Cave-Ayland        break;
564846bb0137SMark Cave-Ayland 
564946bb0137SMark Cave-Ayland     case DISAS_EXIT:
565046bb0137SMark Cave-Ayland         /* Exit TB */
565146bb0137SMark Cave-Ayland         save_state(dc);
565246bb0137SMark Cave-Ayland         tcg_gen_exit_tb(NULL, 0);
565346bb0137SMark Cave-Ayland         break;
565446bb0137SMark Cave-Ayland 
565546bb0137SMark Cave-Ayland     default:
565646bb0137SMark Cave-Ayland         g_assert_not_reached();
5657fcf5ef2aSThomas Huth     }
5658186e7890SRichard Henderson 
5659186e7890SRichard Henderson     for (e = dc->delay_excp_list; e ; e = e_next) {
5660186e7890SRichard Henderson         gen_set_label(e->lab);
5661186e7890SRichard Henderson 
5662186e7890SRichard Henderson         tcg_gen_movi_tl(cpu_pc, e->pc);
5663186e7890SRichard Henderson         if (e->npc % 4 == 0) {
5664186e7890SRichard Henderson             tcg_gen_movi_tl(cpu_npc, e->npc);
5665186e7890SRichard Henderson         }
5666186e7890SRichard Henderson         gen_helper_raise_exception(tcg_env, e->excp);
5667186e7890SRichard Henderson 
5668186e7890SRichard Henderson         e_next = e->next;
5669186e7890SRichard Henderson         g_free(e);
5670186e7890SRichard Henderson     }
5671fcf5ef2aSThomas Huth }
56726e61bc94SEmilio G. Cota 
56736e61bc94SEmilio G. Cota static const TranslatorOps sparc_tr_ops = {
56746e61bc94SEmilio G. Cota     .init_disas_context = sparc_tr_init_disas_context,
56756e61bc94SEmilio G. Cota     .tb_start           = sparc_tr_tb_start,
56766e61bc94SEmilio G. Cota     .insn_start         = sparc_tr_insn_start,
56776e61bc94SEmilio G. Cota     .translate_insn     = sparc_tr_translate_insn,
56786e61bc94SEmilio G. Cota     .tb_stop            = sparc_tr_tb_stop,
56796e61bc94SEmilio G. Cota };
56806e61bc94SEmilio G. Cota 
5681597f9b2dSRichard Henderson void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int *max_insns,
568232f0c394SAnton Johansson                            vaddr pc, void *host_pc)
56836e61bc94SEmilio G. Cota {
56846e61bc94SEmilio G. Cota     DisasContext dc = {};
56856e61bc94SEmilio G. Cota 
5686306c8721SRichard Henderson     translator_loop(cs, tb, max_insns, pc, host_pc, &sparc_tr_ops, &dc.base);
5687fcf5ef2aSThomas Huth }
5688fcf5ef2aSThomas Huth 
568955c3ceefSRichard Henderson void sparc_tcg_init(void)
5690fcf5ef2aSThomas Huth {
5691fcf5ef2aSThomas Huth     static const char gregnames[32][4] = {
5692fcf5ef2aSThomas Huth         "g0", "g1", "g2", "g3", "g4", "g5", "g6", "g7",
5693fcf5ef2aSThomas Huth         "o0", "o1", "o2", "o3", "o4", "o5", "o6", "o7",
5694fcf5ef2aSThomas Huth         "l0", "l1", "l2", "l3", "l4", "l5", "l6", "l7",
5695fcf5ef2aSThomas Huth         "i0", "i1", "i2", "i3", "i4", "i5", "i6", "i7",
5696fcf5ef2aSThomas Huth     };
5697fcf5ef2aSThomas Huth 
5698d8c5b92fSRichard Henderson     static const struct { TCGv_i32 *ptr; int off; const char *name; } r32[] = {
5699d8c5b92fSRichard Henderson #ifdef TARGET_SPARC64
5700d8c5b92fSRichard Henderson         { &cpu_fprs, offsetof(CPUSPARCState, fprs), "fprs" },
5701d8c5b92fSRichard Henderson         { &cpu_fcc[0], offsetof(CPUSPARCState, fcc[0]), "fcc0" },
5702d8c5b92fSRichard Henderson         { &cpu_fcc[1], offsetof(CPUSPARCState, fcc[1]), "fcc1" },
5703d8c5b92fSRichard Henderson         { &cpu_fcc[2], offsetof(CPUSPARCState, fcc[2]), "fcc2" },
5704d8c5b92fSRichard Henderson         { &cpu_fcc[3], offsetof(CPUSPARCState, fcc[3]), "fcc3" },
5705d8c5b92fSRichard Henderson #else
5706d8c5b92fSRichard Henderson         { &cpu_fcc[0], offsetof(CPUSPARCState, fcc[0]), "fcc" },
5707d8c5b92fSRichard Henderson #endif
5708d8c5b92fSRichard Henderson     };
5709d8c5b92fSRichard Henderson 
5710fcf5ef2aSThomas Huth     static const struct { TCGv *ptr; int off; const char *name; } rtl[] = {
5711fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
5712fcf5ef2aSThomas Huth         { &cpu_gsr, offsetof(CPUSPARCState, gsr), "gsr" },
57132a1905c7SRichard Henderson         { &cpu_xcc_Z, offsetof(CPUSPARCState, xcc_Z), "xcc_Z" },
57142a1905c7SRichard Henderson         { &cpu_xcc_C, offsetof(CPUSPARCState, xcc_C), "xcc_C" },
5715fcf5ef2aSThomas Huth #endif
57162a1905c7SRichard Henderson         { &cpu_cc_N, offsetof(CPUSPARCState, cc_N), "cc_N" },
57172a1905c7SRichard Henderson         { &cpu_cc_V, offsetof(CPUSPARCState, cc_V), "cc_V" },
57182a1905c7SRichard Henderson         { &cpu_icc_Z, offsetof(CPUSPARCState, icc_Z), "icc_Z" },
57192a1905c7SRichard Henderson         { &cpu_icc_C, offsetof(CPUSPARCState, icc_C), "icc_C" },
5720fcf5ef2aSThomas Huth         { &cpu_cond, offsetof(CPUSPARCState, cond), "cond" },
5721fcf5ef2aSThomas Huth         { &cpu_pc, offsetof(CPUSPARCState, pc), "pc" },
5722fcf5ef2aSThomas Huth         { &cpu_npc, offsetof(CPUSPARCState, npc), "npc" },
5723fcf5ef2aSThomas Huth         { &cpu_y, offsetof(CPUSPARCState, y), "y" },
5724fcf5ef2aSThomas Huth         { &cpu_tbr, offsetof(CPUSPARCState, tbr), "tbr" },
5725fcf5ef2aSThomas Huth     };
5726fcf5ef2aSThomas Huth 
5727fcf5ef2aSThomas Huth     unsigned int i;
5728fcf5ef2aSThomas Huth 
5729ad75a51eSRichard Henderson     cpu_regwptr = tcg_global_mem_new_ptr(tcg_env,
5730fcf5ef2aSThomas Huth                                          offsetof(CPUSPARCState, regwptr),
5731fcf5ef2aSThomas Huth                                          "regwptr");
5732fcf5ef2aSThomas Huth 
5733d8c5b92fSRichard Henderson     for (i = 0; i < ARRAY_SIZE(r32); ++i) {
5734d8c5b92fSRichard Henderson         *r32[i].ptr = tcg_global_mem_new_i32(tcg_env, r32[i].off, r32[i].name);
5735d8c5b92fSRichard Henderson     }
5736d8c5b92fSRichard Henderson 
5737fcf5ef2aSThomas Huth     for (i = 0; i < ARRAY_SIZE(rtl); ++i) {
5738ad75a51eSRichard Henderson         *rtl[i].ptr = tcg_global_mem_new(tcg_env, rtl[i].off, rtl[i].name);
5739fcf5ef2aSThomas Huth     }
5740fcf5ef2aSThomas Huth 
5741f764718dSRichard Henderson     cpu_regs[0] = NULL;
5742fcf5ef2aSThomas Huth     for (i = 1; i < 8; ++i) {
5743ad75a51eSRichard Henderson         cpu_regs[i] = tcg_global_mem_new(tcg_env,
5744fcf5ef2aSThomas Huth                                          offsetof(CPUSPARCState, gregs[i]),
5745fcf5ef2aSThomas Huth                                          gregnames[i]);
5746fcf5ef2aSThomas Huth     }
5747fcf5ef2aSThomas Huth 
5748fcf5ef2aSThomas Huth     for (i = 8; i < 32; ++i) {
5749fcf5ef2aSThomas Huth         cpu_regs[i] = tcg_global_mem_new(cpu_regwptr,
5750fcf5ef2aSThomas Huth                                          (i - 8) * sizeof(target_ulong),
5751fcf5ef2aSThomas Huth                                          gregnames[i]);
5752fcf5ef2aSThomas Huth     }
5753fcf5ef2aSThomas Huth }
5754fcf5ef2aSThomas Huth 
5755f36aaa53SRichard Henderson void sparc_restore_state_to_opc(CPUState *cs,
5756f36aaa53SRichard Henderson                                 const TranslationBlock *tb,
5757f36aaa53SRichard Henderson                                 const uint64_t *data)
5758fcf5ef2aSThomas Huth {
575977976769SPhilippe Mathieu-Daudé     CPUSPARCState *env = cpu_env(cs);
5760fcf5ef2aSThomas Huth     target_ulong pc = data[0];
5761fcf5ef2aSThomas Huth     target_ulong npc = data[1];
5762fcf5ef2aSThomas Huth 
5763fcf5ef2aSThomas Huth     env->pc = pc;
5764fcf5ef2aSThomas Huth     if (npc == DYNAMIC_PC) {
5765fcf5ef2aSThomas Huth         /* dynamic NPC: already stored */
5766fcf5ef2aSThomas Huth     } else if (npc & JUMP_PC) {
5767fcf5ef2aSThomas Huth         /* jump PC: use 'cond' and the jump targets of the translation */
5768fcf5ef2aSThomas Huth         if (env->cond) {
5769fcf5ef2aSThomas Huth             env->npc = npc & ~3;
5770fcf5ef2aSThomas Huth         } else {
5771fcf5ef2aSThomas Huth             env->npc = pc + 4;
5772fcf5ef2aSThomas Huth         }
5773fcf5ef2aSThomas Huth     } else {
5774fcf5ef2aSThomas Huth         env->npc = npc;
5775fcf5ef2aSThomas Huth     }
5776fcf5ef2aSThomas Huth }
5777