xref: /openbmc/qemu/target/sparc/translate.c (revision dd7dbfcc00dc4cc349fc8f4588cecc88dd149ca5)
1fcf5ef2aSThomas Huth /*
2fcf5ef2aSThomas Huth    SPARC translation
3fcf5ef2aSThomas Huth 
4fcf5ef2aSThomas Huth    Copyright (C) 2003 Thomas M. Ogrisegg <tom@fnord.at>
5fcf5ef2aSThomas Huth    Copyright (C) 2003-2005 Fabrice Bellard
6fcf5ef2aSThomas Huth 
7fcf5ef2aSThomas Huth    This library is free software; you can redistribute it and/or
8fcf5ef2aSThomas Huth    modify it under the terms of the GNU Lesser General Public
9fcf5ef2aSThomas Huth    License as published by the Free Software Foundation; either
105650b549SChetan Pant    version 2.1 of the License, or (at your option) any later version.
11fcf5ef2aSThomas Huth 
12fcf5ef2aSThomas Huth    This library is distributed in the hope that it will be useful,
13fcf5ef2aSThomas Huth    but WITHOUT ANY WARRANTY; without even the implied warranty of
14fcf5ef2aSThomas Huth    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15fcf5ef2aSThomas Huth    Lesser General Public License for more details.
16fcf5ef2aSThomas Huth 
17fcf5ef2aSThomas Huth    You should have received a copy of the GNU Lesser General Public
18fcf5ef2aSThomas Huth    License along with this library; if not, see <http://www.gnu.org/licenses/>.
19fcf5ef2aSThomas Huth  */
20fcf5ef2aSThomas Huth 
21fcf5ef2aSThomas Huth #include "qemu/osdep.h"
22fcf5ef2aSThomas Huth 
23fcf5ef2aSThomas Huth #include "cpu.h"
24fcf5ef2aSThomas Huth #include "disas/disas.h"
25fcf5ef2aSThomas Huth #include "exec/helper-proto.h"
26fcf5ef2aSThomas Huth #include "exec/exec-all.h"
27dcb32f1dSPhilippe Mathieu-Daudé #include "tcg/tcg-op.h"
28fafba1bbSRichard Henderson #include "tcg/tcg-op-gvec.h"
29fcf5ef2aSThomas Huth #include "exec/helper-gen.h"
30c5e6ccdfSEmilio G. Cota #include "exec/translator.h"
31fcf5ef2aSThomas Huth #include "exec/log.h"
32fcf5ef2aSThomas Huth #include "asi.h"
33fcf5ef2aSThomas Huth 
34d53106c9SRichard Henderson #define HELPER_H "helper.h"
35d53106c9SRichard Henderson #include "exec/helper-info.c.inc"
36d53106c9SRichard Henderson #undef  HELPER_H
37fcf5ef2aSThomas Huth 
38668bb9b7SRichard Henderson #ifdef TARGET_SPARC64
39668bb9b7SRichard Henderson # define gen_helper_rdpsr(D, E)                 qemu_build_not_reached()
4086b82fe0SRichard Henderson # define gen_helper_rett(E)                     qemu_build_not_reached()
410faef01bSRichard Henderson # define gen_helper_power_down(E)               qemu_build_not_reached()
4225524734SRichard Henderson # define gen_helper_wrpsr(E, S)                 qemu_build_not_reached()
43668bb9b7SRichard Henderson #else
440faef01bSRichard Henderson # define gen_helper_clear_softint(E, S)         qemu_build_not_reached()
458f75b8a4SRichard Henderson # define gen_helper_done(E)                     qemu_build_not_reached()
46c6d83e4fSRichard Henderson # define gen_helper_fabsd(D, S)                 qemu_build_not_reached()
47e8325dc0SRichard Henderson # define gen_helper_flushw(E)                   qemu_build_not_reached()
48c6d83e4fSRichard Henderson # define gen_helper_fnegd(D, S)                 qemu_build_not_reached()
49af25071cSRichard Henderson # define gen_helper_rdccr(D, E)                 qemu_build_not_reached()
505d617bfbSRichard Henderson # define gen_helper_rdcwp(D, E)                 qemu_build_not_reached()
5125524734SRichard Henderson # define gen_helper_restored(E)                 qemu_build_not_reached()
528f75b8a4SRichard Henderson # define gen_helper_retry(E)                    qemu_build_not_reached()
5325524734SRichard Henderson # define gen_helper_saved(E)                    qemu_build_not_reached()
544ee85ea9SRichard Henderson # define gen_helper_sdivx(D, E, A, B)           qemu_build_not_reached()
550faef01bSRichard Henderson # define gen_helper_set_softint(E, S)           qemu_build_not_reached()
56af25071cSRichard Henderson # define gen_helper_tick_get_count(D, E, T, C)  qemu_build_not_reached()
579422278eSRichard Henderson # define gen_helper_tick_set_count(P, S)        qemu_build_not_reached()
58bb97f2f5SRichard Henderson # define gen_helper_tick_set_limit(P, S)        qemu_build_not_reached()
594ee85ea9SRichard Henderson # define gen_helper_udivx(D, E, A, B)           qemu_build_not_reached()
600faef01bSRichard Henderson # define gen_helper_wrccr(E, S)                 qemu_build_not_reached()
619422278eSRichard Henderson # define gen_helper_wrcwp(E, S)                 qemu_build_not_reached()
629422278eSRichard Henderson # define gen_helper_wrgl(E, S)                  qemu_build_not_reached()
630faef01bSRichard Henderson # define gen_helper_write_softint(E, S)         qemu_build_not_reached()
649422278eSRichard Henderson # define gen_helper_wrpil(E, S)                 qemu_build_not_reached()
659422278eSRichard Henderson # define gen_helper_wrpstate(E, S)              qemu_build_not_reached()
66f4e18df5SRichard Henderson # define gen_helper_fabsq                ({ qemu_build_not_reached(); NULL; })
67e2fa6bd1SRichard Henderson # define gen_helper_fcmpeq16             ({ qemu_build_not_reached(); NULL; })
68e2fa6bd1SRichard Henderson # define gen_helper_fcmpeq32             ({ qemu_build_not_reached(); NULL; })
69e2fa6bd1SRichard Henderson # define gen_helper_fcmpgt16             ({ qemu_build_not_reached(); NULL; })
70e2fa6bd1SRichard Henderson # define gen_helper_fcmpgt32             ({ qemu_build_not_reached(); NULL; })
71e2fa6bd1SRichard Henderson # define gen_helper_fcmple16             ({ qemu_build_not_reached(); NULL; })
72e2fa6bd1SRichard Henderson # define gen_helper_fcmple32             ({ qemu_build_not_reached(); NULL; })
73e2fa6bd1SRichard Henderson # define gen_helper_fcmpne16             ({ qemu_build_not_reached(); NULL; })
74e2fa6bd1SRichard Henderson # define gen_helper_fcmpne32             ({ qemu_build_not_reached(); NULL; })
758aa418b3SRichard Henderson # define gen_helper_fdtox                ({ qemu_build_not_reached(); NULL; })
76e06c9f83SRichard Henderson # define gen_helper_fexpand              ({ qemu_build_not_reached(); NULL; })
77e06c9f83SRichard Henderson # define gen_helper_fmul8sux16           ({ qemu_build_not_reached(); NULL; })
78e06c9f83SRichard Henderson # define gen_helper_fmul8ulx16           ({ qemu_build_not_reached(); NULL; })
79e06c9f83SRichard Henderson # define gen_helper_fmul8x16al           ({ qemu_build_not_reached(); NULL; })
80e06c9f83SRichard Henderson # define gen_helper_fmul8x16au           ({ qemu_build_not_reached(); NULL; })
81e06c9f83SRichard Henderson # define gen_helper_fmul8x16             ({ qemu_build_not_reached(); NULL; })
82e06c9f83SRichard Henderson # define gen_helper_fmuld8sux16          ({ qemu_build_not_reached(); NULL; })
83e06c9f83SRichard Henderson # define gen_helper_fmuld8ulx16          ({ qemu_build_not_reached(); NULL; })
84f4e18df5SRichard Henderson # define gen_helper_fnegq                ({ qemu_build_not_reached(); NULL; })
85e06c9f83SRichard Henderson # define gen_helper_fpmerge              ({ qemu_build_not_reached(); NULL; })
861617586fSRichard Henderson # define gen_helper_fqtox                ({ qemu_build_not_reached(); NULL; })
87199d43efSRichard Henderson # define gen_helper_fstox                ({ qemu_build_not_reached(); NULL; })
888aa418b3SRichard Henderson # define gen_helper_fxtod                ({ qemu_build_not_reached(); NULL; })
897b8e3e1aSRichard Henderson # define gen_helper_fxtoq                ({ qemu_build_not_reached(); NULL; })
90f4e18df5SRichard Henderson # define gen_helper_fxtos                ({ qemu_build_not_reached(); NULL; })
91afb04344SRichard Henderson # define gen_helper_pdist                ({ qemu_build_not_reached(); NULL; })
92da681406SRichard Henderson # define FSR_LDXFSR_MASK                        0
93da681406SRichard Henderson # define FSR_LDXFSR_OLDMASK                     0
94668bb9b7SRichard Henderson # define MAXTL_MASK                             0
95af25071cSRichard Henderson #endif
96af25071cSRichard Henderson 
97633c4283SRichard Henderson /* Dynamic PC, must exit to main loop. */
98633c4283SRichard Henderson #define DYNAMIC_PC         1
99633c4283SRichard Henderson /* Dynamic PC, one of two values according to jump_pc[T2]. */
100633c4283SRichard Henderson #define JUMP_PC            2
101633c4283SRichard Henderson /* Dynamic PC, may lookup next TB. */
102633c4283SRichard Henderson #define DYNAMIC_PC_LOOKUP  3
103fcf5ef2aSThomas Huth 
10446bb0137SMark Cave-Ayland #define DISAS_EXIT  DISAS_TARGET_0
10546bb0137SMark Cave-Ayland 
106fcf5ef2aSThomas Huth /* global register indexes */
107fcf5ef2aSThomas Huth static TCGv_ptr cpu_regwptr;
108fcf5ef2aSThomas Huth static TCGv cpu_fsr, cpu_pc, cpu_npc;
109fcf5ef2aSThomas Huth static TCGv cpu_regs[32];
110fcf5ef2aSThomas Huth static TCGv cpu_y;
111fcf5ef2aSThomas Huth static TCGv cpu_tbr;
112fcf5ef2aSThomas Huth static TCGv cpu_cond;
1132a1905c7SRichard Henderson static TCGv cpu_cc_N;
1142a1905c7SRichard Henderson static TCGv cpu_cc_V;
1152a1905c7SRichard Henderson static TCGv cpu_icc_Z;
1162a1905c7SRichard Henderson static TCGv cpu_icc_C;
117fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
1182a1905c7SRichard Henderson static TCGv cpu_xcc_Z;
1192a1905c7SRichard Henderson static TCGv cpu_xcc_C;
1202a1905c7SRichard Henderson static TCGv_i32 cpu_fprs;
121fcf5ef2aSThomas Huth static TCGv cpu_gsr;
122fcf5ef2aSThomas Huth #else
123af25071cSRichard Henderson # define cpu_fprs               ({ qemu_build_not_reached(); (TCGv)NULL; })
124af25071cSRichard Henderson # define cpu_gsr                ({ qemu_build_not_reached(); (TCGv)NULL; })
125fcf5ef2aSThomas Huth #endif
1262a1905c7SRichard Henderson 
1272a1905c7SRichard Henderson #ifdef TARGET_SPARC64
1282a1905c7SRichard Henderson #define cpu_cc_Z  cpu_xcc_Z
1292a1905c7SRichard Henderson #define cpu_cc_C  cpu_xcc_C
1302a1905c7SRichard Henderson #else
1312a1905c7SRichard Henderson #define cpu_cc_Z  cpu_icc_Z
1322a1905c7SRichard Henderson #define cpu_cc_C  cpu_icc_C
1332a1905c7SRichard Henderson #define cpu_xcc_Z ({ qemu_build_not_reached(); NULL; })
1342a1905c7SRichard Henderson #define cpu_xcc_C ({ qemu_build_not_reached(); NULL; })
1352a1905c7SRichard Henderson #endif
1362a1905c7SRichard Henderson 
137fcf5ef2aSThomas Huth /* Floating point registers */
138fcf5ef2aSThomas Huth static TCGv_i64 cpu_fpr[TARGET_DPREGS];
139fcf5ef2aSThomas Huth 
140af25071cSRichard Henderson #define env_field_offsetof(X)     offsetof(CPUSPARCState, X)
141af25071cSRichard Henderson #ifdef TARGET_SPARC64
142cd6269f7SRichard Henderson # define env32_field_offsetof(X)  ({ qemu_build_not_reached(); 0; })
143af25071cSRichard Henderson # define env64_field_offsetof(X)  env_field_offsetof(X)
144af25071cSRichard Henderson #else
145cd6269f7SRichard Henderson # define env32_field_offsetof(X)  env_field_offsetof(X)
146af25071cSRichard Henderson # define env64_field_offsetof(X)  ({ qemu_build_not_reached(); 0; })
147af25071cSRichard Henderson #endif
148af25071cSRichard Henderson 
149186e7890SRichard Henderson typedef struct DisasDelayException {
150186e7890SRichard Henderson     struct DisasDelayException *next;
151186e7890SRichard Henderson     TCGLabel *lab;
152186e7890SRichard Henderson     TCGv_i32 excp;
153186e7890SRichard Henderson     /* Saved state at parent insn. */
154186e7890SRichard Henderson     target_ulong pc;
155186e7890SRichard Henderson     target_ulong npc;
156186e7890SRichard Henderson } DisasDelayException;
157186e7890SRichard Henderson 
158fcf5ef2aSThomas Huth typedef struct DisasContext {
159af00be49SEmilio G. Cota     DisasContextBase base;
160fcf5ef2aSThomas Huth     target_ulong pc;    /* current Program Counter: integer or DYNAMIC_PC */
161fcf5ef2aSThomas Huth     target_ulong npc;   /* next PC: integer or DYNAMIC_PC or JUMP_PC */
162fcf5ef2aSThomas Huth     target_ulong jump_pc[2]; /* used when JUMP_PC pc value is used */
163fcf5ef2aSThomas Huth     int mem_idx;
164c9b459aaSArtyom Tarasenko     bool fpu_enabled;
165c9b459aaSArtyom Tarasenko     bool address_mask_32bit;
166c9b459aaSArtyom Tarasenko #ifndef CONFIG_USER_ONLY
167c9b459aaSArtyom Tarasenko     bool supervisor;
168c9b459aaSArtyom Tarasenko #ifdef TARGET_SPARC64
169c9b459aaSArtyom Tarasenko     bool hypervisor;
170c9b459aaSArtyom Tarasenko #endif
171c9b459aaSArtyom Tarasenko #endif
172c9b459aaSArtyom Tarasenko 
173fcf5ef2aSThomas Huth     sparc_def_t *def;
174fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
175fcf5ef2aSThomas Huth     int fprs_dirty;
176fcf5ef2aSThomas Huth     int asi;
177fcf5ef2aSThomas Huth #endif
178186e7890SRichard Henderson     DisasDelayException *delay_excp_list;
179fcf5ef2aSThomas Huth } DisasContext;
180fcf5ef2aSThomas Huth 
181fcf5ef2aSThomas Huth typedef struct {
182fcf5ef2aSThomas Huth     TCGCond cond;
183fcf5ef2aSThomas Huth     TCGv c1, c2;
184fcf5ef2aSThomas Huth } DisasCompare;
185fcf5ef2aSThomas Huth 
186fcf5ef2aSThomas Huth // This function uses non-native bit order
187fcf5ef2aSThomas Huth #define GET_FIELD(X, FROM, TO)                                  \
188fcf5ef2aSThomas Huth     ((X) >> (31 - (TO)) & ((1 << ((TO) - (FROM) + 1)) - 1))
189fcf5ef2aSThomas Huth 
190fcf5ef2aSThomas Huth // This function uses the order in the manuals, i.e. bit 0 is 2^0
191fcf5ef2aSThomas Huth #define GET_FIELD_SP(X, FROM, TO)               \
192fcf5ef2aSThomas Huth     GET_FIELD(X, 31 - (TO), 31 - (FROM))
193fcf5ef2aSThomas Huth 
194fcf5ef2aSThomas Huth #define GET_FIELDs(x,a,b) sign_extend (GET_FIELD(x,a,b), (b) - (a) + 1)
195fcf5ef2aSThomas Huth #define GET_FIELD_SPs(x,a,b) sign_extend (GET_FIELD_SP(x,a,b), ((b) - (a) + 1))
196fcf5ef2aSThomas Huth 
197fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
198fcf5ef2aSThomas Huth #define DFPREG(r) (((r & 1) << 5) | (r & 0x1e))
199fcf5ef2aSThomas Huth #define QFPREG(r) (((r & 1) << 5) | (r & 0x1c))
200fcf5ef2aSThomas Huth #else
201fcf5ef2aSThomas Huth #define DFPREG(r) (r & 0x1e)
202fcf5ef2aSThomas Huth #define QFPREG(r) (r & 0x1c)
203fcf5ef2aSThomas Huth #endif
204fcf5ef2aSThomas Huth 
205fcf5ef2aSThomas Huth #define UA2005_HTRAP_MASK 0xff
206fcf5ef2aSThomas Huth #define V8_TRAP_MASK 0x7f
207fcf5ef2aSThomas Huth 
208fcf5ef2aSThomas Huth #define IS_IMM (insn & (1<<13))
209fcf5ef2aSThomas Huth 
2100c2e96c1SRichard Henderson static void gen_update_fprs_dirty(DisasContext *dc, int rd)
211fcf5ef2aSThomas Huth {
212fcf5ef2aSThomas Huth #if defined(TARGET_SPARC64)
213fcf5ef2aSThomas Huth     int bit = (rd < 32) ? 1 : 2;
214fcf5ef2aSThomas Huth     /* If we know we've already set this bit within the TB,
215fcf5ef2aSThomas Huth        we can avoid setting it again.  */
216fcf5ef2aSThomas Huth     if (!(dc->fprs_dirty & bit)) {
217fcf5ef2aSThomas Huth         dc->fprs_dirty |= bit;
218fcf5ef2aSThomas Huth         tcg_gen_ori_i32(cpu_fprs, cpu_fprs, bit);
219fcf5ef2aSThomas Huth     }
220fcf5ef2aSThomas Huth #endif
221fcf5ef2aSThomas Huth }
222fcf5ef2aSThomas Huth 
223fcf5ef2aSThomas Huth /* floating point registers moves */
224fcf5ef2aSThomas Huth static TCGv_i32 gen_load_fpr_F(DisasContext *dc, unsigned int src)
225fcf5ef2aSThomas Huth {
22636ab4623SRichard Henderson     TCGv_i32 ret = tcg_temp_new_i32();
227dc41aa7dSRichard Henderson     if (src & 1) {
228dc41aa7dSRichard Henderson         tcg_gen_extrl_i64_i32(ret, cpu_fpr[src / 2]);
229dc41aa7dSRichard Henderson     } else {
230dc41aa7dSRichard Henderson         tcg_gen_extrh_i64_i32(ret, cpu_fpr[src / 2]);
231fcf5ef2aSThomas Huth     }
232dc41aa7dSRichard Henderson     return ret;
233fcf5ef2aSThomas Huth }
234fcf5ef2aSThomas Huth 
235fcf5ef2aSThomas Huth static void gen_store_fpr_F(DisasContext *dc, unsigned int dst, TCGv_i32 v)
236fcf5ef2aSThomas Huth {
2378e7bbc75SRichard Henderson     TCGv_i64 t = tcg_temp_new_i64();
2388e7bbc75SRichard Henderson 
2398e7bbc75SRichard Henderson     tcg_gen_extu_i32_i64(t, v);
240fcf5ef2aSThomas Huth     tcg_gen_deposit_i64(cpu_fpr[dst / 2], cpu_fpr[dst / 2], t,
241fcf5ef2aSThomas Huth                         (dst & 1 ? 0 : 32), 32);
242fcf5ef2aSThomas Huth     gen_update_fprs_dirty(dc, dst);
243fcf5ef2aSThomas Huth }
244fcf5ef2aSThomas Huth 
245fcf5ef2aSThomas Huth static TCGv_i32 gen_dest_fpr_F(DisasContext *dc)
246fcf5ef2aSThomas Huth {
24736ab4623SRichard Henderson     return tcg_temp_new_i32();
248fcf5ef2aSThomas Huth }
249fcf5ef2aSThomas Huth 
250fcf5ef2aSThomas Huth static TCGv_i64 gen_load_fpr_D(DisasContext *dc, unsigned int src)
251fcf5ef2aSThomas Huth {
252fcf5ef2aSThomas Huth     src = DFPREG(src);
253fcf5ef2aSThomas Huth     return cpu_fpr[src / 2];
254fcf5ef2aSThomas Huth }
255fcf5ef2aSThomas Huth 
256fcf5ef2aSThomas Huth static void gen_store_fpr_D(DisasContext *dc, unsigned int dst, TCGv_i64 v)
257fcf5ef2aSThomas Huth {
258fcf5ef2aSThomas Huth     dst = DFPREG(dst);
259fcf5ef2aSThomas Huth     tcg_gen_mov_i64(cpu_fpr[dst / 2], v);
260fcf5ef2aSThomas Huth     gen_update_fprs_dirty(dc, dst);
261fcf5ef2aSThomas Huth }
262fcf5ef2aSThomas Huth 
263fcf5ef2aSThomas Huth static TCGv_i64 gen_dest_fpr_D(DisasContext *dc, unsigned int dst)
264fcf5ef2aSThomas Huth {
265fcf5ef2aSThomas Huth     return cpu_fpr[DFPREG(dst) / 2];
266fcf5ef2aSThomas Huth }
267fcf5ef2aSThomas Huth 
268fcf5ef2aSThomas Huth static void gen_op_load_fpr_QT0(unsigned int src)
269fcf5ef2aSThomas Huth {
270ad75a51eSRichard Henderson     tcg_gen_st_i64(cpu_fpr[src / 2], tcg_env, offsetof(CPUSPARCState, qt0) +
271fcf5ef2aSThomas Huth                    offsetof(CPU_QuadU, ll.upper));
272ad75a51eSRichard Henderson     tcg_gen_st_i64(cpu_fpr[src/2 + 1], tcg_env, offsetof(CPUSPARCState, qt0) +
273fcf5ef2aSThomas Huth                    offsetof(CPU_QuadU, ll.lower));
274fcf5ef2aSThomas Huth }
275fcf5ef2aSThomas Huth 
276fcf5ef2aSThomas Huth static void gen_op_load_fpr_QT1(unsigned int src)
277fcf5ef2aSThomas Huth {
278ad75a51eSRichard Henderson     tcg_gen_st_i64(cpu_fpr[src / 2], tcg_env, offsetof(CPUSPARCState, qt1) +
279fcf5ef2aSThomas Huth                    offsetof(CPU_QuadU, ll.upper));
280ad75a51eSRichard Henderson     tcg_gen_st_i64(cpu_fpr[src/2 + 1], tcg_env, offsetof(CPUSPARCState, qt1) +
281fcf5ef2aSThomas Huth                    offsetof(CPU_QuadU, ll.lower));
282fcf5ef2aSThomas Huth }
283fcf5ef2aSThomas Huth 
284fcf5ef2aSThomas Huth static void gen_op_store_QT0_fpr(unsigned int dst)
285fcf5ef2aSThomas Huth {
286ad75a51eSRichard Henderson     tcg_gen_ld_i64(cpu_fpr[dst / 2], tcg_env, offsetof(CPUSPARCState, qt0) +
287fcf5ef2aSThomas Huth                    offsetof(CPU_QuadU, ll.upper));
288ad75a51eSRichard Henderson     tcg_gen_ld_i64(cpu_fpr[dst/2 + 1], tcg_env, offsetof(CPUSPARCState, qt0) +
289fcf5ef2aSThomas Huth                    offsetof(CPU_QuadU, ll.lower));
290fcf5ef2aSThomas Huth }
291fcf5ef2aSThomas Huth 
292fcf5ef2aSThomas Huth /* moves */
293fcf5ef2aSThomas Huth #ifdef CONFIG_USER_ONLY
294fcf5ef2aSThomas Huth #define supervisor(dc) 0
295fcf5ef2aSThomas Huth #define hypervisor(dc) 0
296fcf5ef2aSThomas Huth #else
297fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
298c9b459aaSArtyom Tarasenko #define hypervisor(dc) (dc->hypervisor)
299c9b459aaSArtyom Tarasenko #define supervisor(dc) (dc->supervisor | dc->hypervisor)
300fcf5ef2aSThomas Huth #else
301c9b459aaSArtyom Tarasenko #define supervisor(dc) (dc->supervisor)
302668bb9b7SRichard Henderson #define hypervisor(dc) 0
303fcf5ef2aSThomas Huth #endif
304fcf5ef2aSThomas Huth #endif
305fcf5ef2aSThomas Huth 
306b1bc09eaSRichard Henderson #if !defined(TARGET_SPARC64)
307b1bc09eaSRichard Henderson # define AM_CHECK(dc)  false
308b1bc09eaSRichard Henderson #elif defined(TARGET_ABI32)
309b1bc09eaSRichard Henderson # define AM_CHECK(dc)  true
310b1bc09eaSRichard Henderson #elif defined(CONFIG_USER_ONLY)
311b1bc09eaSRichard Henderson # define AM_CHECK(dc)  false
312fcf5ef2aSThomas Huth #else
313b1bc09eaSRichard Henderson # define AM_CHECK(dc)  ((dc)->address_mask_32bit)
314fcf5ef2aSThomas Huth #endif
315fcf5ef2aSThomas Huth 
3160c2e96c1SRichard Henderson static void gen_address_mask(DisasContext *dc, TCGv addr)
317fcf5ef2aSThomas Huth {
318b1bc09eaSRichard Henderson     if (AM_CHECK(dc)) {
319fcf5ef2aSThomas Huth         tcg_gen_andi_tl(addr, addr, 0xffffffffULL);
320b1bc09eaSRichard Henderson     }
321fcf5ef2aSThomas Huth }
322fcf5ef2aSThomas Huth 
32323ada1b1SRichard Henderson static target_ulong address_mask_i(DisasContext *dc, target_ulong addr)
32423ada1b1SRichard Henderson {
32523ada1b1SRichard Henderson     return AM_CHECK(dc) ? (uint32_t)addr : addr;
32623ada1b1SRichard Henderson }
32723ada1b1SRichard Henderson 
3280c2e96c1SRichard Henderson static TCGv gen_load_gpr(DisasContext *dc, int reg)
329fcf5ef2aSThomas Huth {
330fcf5ef2aSThomas Huth     if (reg > 0) {
331fcf5ef2aSThomas Huth         assert(reg < 32);
332fcf5ef2aSThomas Huth         return cpu_regs[reg];
333fcf5ef2aSThomas Huth     } else {
33452123f14SRichard Henderson         TCGv t = tcg_temp_new();
335fcf5ef2aSThomas Huth         tcg_gen_movi_tl(t, 0);
336fcf5ef2aSThomas Huth         return t;
337fcf5ef2aSThomas Huth     }
338fcf5ef2aSThomas Huth }
339fcf5ef2aSThomas Huth 
3400c2e96c1SRichard Henderson static void gen_store_gpr(DisasContext *dc, int reg, TCGv v)
341fcf5ef2aSThomas Huth {
342fcf5ef2aSThomas Huth     if (reg > 0) {
343fcf5ef2aSThomas Huth         assert(reg < 32);
344fcf5ef2aSThomas Huth         tcg_gen_mov_tl(cpu_regs[reg], v);
345fcf5ef2aSThomas Huth     }
346fcf5ef2aSThomas Huth }
347fcf5ef2aSThomas Huth 
3480c2e96c1SRichard Henderson static TCGv gen_dest_gpr(DisasContext *dc, int reg)
349fcf5ef2aSThomas Huth {
350fcf5ef2aSThomas Huth     if (reg > 0) {
351fcf5ef2aSThomas Huth         assert(reg < 32);
352fcf5ef2aSThomas Huth         return cpu_regs[reg];
353fcf5ef2aSThomas Huth     } else {
35452123f14SRichard Henderson         return tcg_temp_new();
355fcf5ef2aSThomas Huth     }
356fcf5ef2aSThomas Huth }
357fcf5ef2aSThomas Huth 
3585645aa2eSRichard Henderson static bool use_goto_tb(DisasContext *s, target_ulong pc, target_ulong npc)
359fcf5ef2aSThomas Huth {
3605645aa2eSRichard Henderson     return translator_use_goto_tb(&s->base, pc) &&
3615645aa2eSRichard Henderson            translator_use_goto_tb(&s->base, npc);
362fcf5ef2aSThomas Huth }
363fcf5ef2aSThomas Huth 
3645645aa2eSRichard Henderson static void gen_goto_tb(DisasContext *s, int tb_num,
365fcf5ef2aSThomas Huth                         target_ulong pc, target_ulong npc)
366fcf5ef2aSThomas Huth {
367fcf5ef2aSThomas Huth     if (use_goto_tb(s, pc, npc))  {
368fcf5ef2aSThomas Huth         /* jump to same page: we can use a direct jump */
369fcf5ef2aSThomas Huth         tcg_gen_goto_tb(tb_num);
370fcf5ef2aSThomas Huth         tcg_gen_movi_tl(cpu_pc, pc);
371fcf5ef2aSThomas Huth         tcg_gen_movi_tl(cpu_npc, npc);
37207ea28b4SRichard Henderson         tcg_gen_exit_tb(s->base.tb, tb_num);
373fcf5ef2aSThomas Huth     } else {
374f67ccb2fSRichard Henderson         /* jump to another page: we can use an indirect jump */
375fcf5ef2aSThomas Huth         tcg_gen_movi_tl(cpu_pc, pc);
376fcf5ef2aSThomas Huth         tcg_gen_movi_tl(cpu_npc, npc);
377f67ccb2fSRichard Henderson         tcg_gen_lookup_and_goto_ptr();
378fcf5ef2aSThomas Huth     }
379fcf5ef2aSThomas Huth }
380fcf5ef2aSThomas Huth 
381b989ce73SRichard Henderson static TCGv gen_carry32(void)
382fcf5ef2aSThomas Huth {
383b989ce73SRichard Henderson     if (TARGET_LONG_BITS == 64) {
384b989ce73SRichard Henderson         TCGv t = tcg_temp_new();
385b989ce73SRichard Henderson         tcg_gen_extract_tl(t, cpu_icc_C, 32, 1);
386b989ce73SRichard Henderson         return t;
387b989ce73SRichard Henderson     }
388b989ce73SRichard Henderson     return cpu_icc_C;
389fcf5ef2aSThomas Huth }
390fcf5ef2aSThomas Huth 
391b989ce73SRichard Henderson static void gen_op_addcc_int(TCGv dst, TCGv src1, TCGv src2, TCGv cin)
392fcf5ef2aSThomas Huth {
393b989ce73SRichard Henderson     TCGv z = tcg_constant_tl(0);
394fcf5ef2aSThomas Huth 
395b989ce73SRichard Henderson     if (cin) {
396b989ce73SRichard Henderson         tcg_gen_add2_tl(cpu_cc_N, cpu_cc_C, src1, z, cin, z);
397b989ce73SRichard Henderson         tcg_gen_add2_tl(cpu_cc_N, cpu_cc_C, cpu_cc_N, cpu_cc_C, src2, z);
398b989ce73SRichard Henderson     } else {
399b989ce73SRichard Henderson         tcg_gen_add2_tl(cpu_cc_N, cpu_cc_C, src1, z, src2, z);
400b989ce73SRichard Henderson     }
401b989ce73SRichard Henderson     tcg_gen_xor_tl(cpu_cc_Z, src1, src2);
402b989ce73SRichard Henderson     tcg_gen_xor_tl(cpu_cc_V, cpu_cc_N, src2);
403b989ce73SRichard Henderson     tcg_gen_andc_tl(cpu_cc_V, cpu_cc_V, cpu_cc_Z);
404b989ce73SRichard Henderson     if (TARGET_LONG_BITS == 64) {
405b989ce73SRichard Henderson         /*
406b989ce73SRichard Henderson          * Carry-in to bit 32 is result ^ src1 ^ src2.
407b989ce73SRichard Henderson          * We already have the src xor term in Z, from computation of V.
408b989ce73SRichard Henderson          */
409b989ce73SRichard Henderson         tcg_gen_xor_tl(cpu_icc_C, cpu_cc_Z, cpu_cc_N);
410b989ce73SRichard Henderson         tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N);
411b989ce73SRichard Henderson     }
412b989ce73SRichard Henderson     tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N);
413b989ce73SRichard Henderson     tcg_gen_mov_tl(dst, cpu_cc_N);
414b989ce73SRichard Henderson }
415fcf5ef2aSThomas Huth 
416b989ce73SRichard Henderson static void gen_op_addcc(TCGv dst, TCGv src1, TCGv src2)
417b989ce73SRichard Henderson {
418b989ce73SRichard Henderson     gen_op_addcc_int(dst, src1, src2, NULL);
419b989ce73SRichard Henderson }
420fcf5ef2aSThomas Huth 
421b989ce73SRichard Henderson static void gen_op_taddcc(TCGv dst, TCGv src1, TCGv src2)
422b989ce73SRichard Henderson {
423b989ce73SRichard Henderson     TCGv t = tcg_temp_new();
424b989ce73SRichard Henderson 
425b989ce73SRichard Henderson     /* Save the tag bits around modification of dst. */
426b989ce73SRichard Henderson     tcg_gen_or_tl(t, src1, src2);
427b989ce73SRichard Henderson 
428b989ce73SRichard Henderson     gen_op_addcc(dst, src1, src2);
429b989ce73SRichard Henderson 
430b989ce73SRichard Henderson     /* Incorprate tag bits into icc.V */
431b989ce73SRichard Henderson     tcg_gen_andi_tl(t, t, 3);
432b989ce73SRichard Henderson     tcg_gen_neg_tl(t, t);
433b989ce73SRichard Henderson     tcg_gen_ext32u_tl(t, t);
434b989ce73SRichard Henderson     tcg_gen_or_tl(cpu_cc_V, cpu_cc_V, t);
435b989ce73SRichard Henderson }
436b989ce73SRichard Henderson 
437b989ce73SRichard Henderson static void gen_op_addc(TCGv dst, TCGv src1, TCGv src2)
438b989ce73SRichard Henderson {
439b989ce73SRichard Henderson     tcg_gen_add_tl(dst, src1, src2);
440b989ce73SRichard Henderson     tcg_gen_add_tl(dst, dst, gen_carry32());
441b989ce73SRichard Henderson }
442b989ce73SRichard Henderson 
443b989ce73SRichard Henderson static void gen_op_addccc(TCGv dst, TCGv src1, TCGv src2)
444b989ce73SRichard Henderson {
445b989ce73SRichard Henderson     gen_op_addcc_int(dst, src1, src2, gen_carry32());
446fcf5ef2aSThomas Huth }
447fcf5ef2aSThomas Huth 
448f828df74SRichard Henderson static void gen_op_subcc_int(TCGv dst, TCGv src1, TCGv src2, TCGv cin)
449fcf5ef2aSThomas Huth {
450f828df74SRichard Henderson     TCGv z = tcg_constant_tl(0);
451fcf5ef2aSThomas Huth 
452f828df74SRichard Henderson     if (cin) {
453f828df74SRichard Henderson         tcg_gen_sub2_tl(cpu_cc_N, cpu_cc_C, src1, z, cin, z);
454f828df74SRichard Henderson         tcg_gen_sub2_tl(cpu_cc_N, cpu_cc_C, cpu_cc_N, cpu_cc_C, src2, z);
455f828df74SRichard Henderson     } else {
456f828df74SRichard Henderson         tcg_gen_sub2_tl(cpu_cc_N, cpu_cc_C, src1, z, src2, z);
457f828df74SRichard Henderson     }
458f828df74SRichard Henderson     tcg_gen_neg_tl(cpu_cc_C, cpu_cc_C);
459f828df74SRichard Henderson     tcg_gen_xor_tl(cpu_cc_Z, src1, src2);
460f828df74SRichard Henderson     tcg_gen_xor_tl(cpu_cc_V, cpu_cc_N, src1);
461f828df74SRichard Henderson     tcg_gen_and_tl(cpu_cc_V, cpu_cc_V, cpu_cc_Z);
462f828df74SRichard Henderson #ifdef TARGET_SPARC64
463f828df74SRichard Henderson     tcg_gen_xor_tl(cpu_icc_C, cpu_cc_Z, cpu_cc_N);
464f828df74SRichard Henderson     tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N);
465fcf5ef2aSThomas Huth #endif
466f828df74SRichard Henderson     tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N);
467f828df74SRichard Henderson     tcg_gen_mov_tl(dst, cpu_cc_N);
468fcf5ef2aSThomas Huth }
469fcf5ef2aSThomas Huth 
470f828df74SRichard Henderson static void gen_op_subcc(TCGv dst, TCGv src1, TCGv src2)
471fcf5ef2aSThomas Huth {
472f828df74SRichard Henderson     gen_op_subcc_int(dst, src1, src2, NULL);
473fcf5ef2aSThomas Huth }
474fcf5ef2aSThomas Huth 
475f828df74SRichard Henderson static void gen_op_tsubcc(TCGv dst, TCGv src1, TCGv src2)
476fcf5ef2aSThomas Huth {
477f828df74SRichard Henderson     TCGv t = tcg_temp_new();
478fcf5ef2aSThomas Huth 
479f828df74SRichard Henderson     /* Save the tag bits around modification of dst. */
480f828df74SRichard Henderson     tcg_gen_or_tl(t, src1, src2);
481fcf5ef2aSThomas Huth 
482f828df74SRichard Henderson     gen_op_subcc(dst, src1, src2);
483f828df74SRichard Henderson 
484f828df74SRichard Henderson     /* Incorprate tag bits into icc.V */
485f828df74SRichard Henderson     tcg_gen_andi_tl(t, t, 3);
486f828df74SRichard Henderson     tcg_gen_neg_tl(t, t);
487f828df74SRichard Henderson     tcg_gen_ext32u_tl(t, t);
488f828df74SRichard Henderson     tcg_gen_or_tl(cpu_cc_V, cpu_cc_V, t);
489f828df74SRichard Henderson }
490f828df74SRichard Henderson 
491f828df74SRichard Henderson static void gen_op_subc(TCGv dst, TCGv src1, TCGv src2)
492f828df74SRichard Henderson {
493fcf5ef2aSThomas Huth     tcg_gen_sub_tl(dst, src1, src2);
494f828df74SRichard Henderson     tcg_gen_sub_tl(dst, dst, gen_carry32());
495fcf5ef2aSThomas Huth }
496fcf5ef2aSThomas Huth 
497f828df74SRichard Henderson static void gen_op_subccc(TCGv dst, TCGv src1, TCGv src2)
498dfebb950SRichard Henderson {
499f828df74SRichard Henderson     gen_op_subcc_int(dst, src1, src2, gen_carry32());
500dfebb950SRichard Henderson }
501dfebb950SRichard Henderson 
5020c2e96c1SRichard Henderson static void gen_op_mulscc(TCGv dst, TCGv src1, TCGv src2)
503fcf5ef2aSThomas Huth {
504b989ce73SRichard Henderson     TCGv zero = tcg_constant_tl(0);
505b989ce73SRichard Henderson     TCGv t_src1 = tcg_temp_new();
506b989ce73SRichard Henderson     TCGv t_src2 = tcg_temp_new();
507b989ce73SRichard Henderson     TCGv t0 = tcg_temp_new();
508fcf5ef2aSThomas Huth 
509b989ce73SRichard Henderson     tcg_gen_ext32u_tl(t_src1, src1);
510b989ce73SRichard Henderson     tcg_gen_ext32u_tl(t_src2, src2);
511fcf5ef2aSThomas Huth 
512b989ce73SRichard Henderson     /*
513b989ce73SRichard Henderson      * if (!(env->y & 1))
514b989ce73SRichard Henderson      *   src2 = 0;
515fcf5ef2aSThomas Huth      */
516b989ce73SRichard Henderson     tcg_gen_andi_tl(t0, cpu_y, 0x1);
517b989ce73SRichard Henderson     tcg_gen_movcond_tl(TCG_COND_EQ, t_src2, t0, zero, zero, t_src2);
518fcf5ef2aSThomas Huth 
519b989ce73SRichard Henderson     /*
520b989ce73SRichard Henderson      * b2 = src1 & 1;
521b989ce73SRichard Henderson      * y = (b2 << 31) | (y >> 1);
522b989ce73SRichard Henderson      */
5230b1183e3SPhilippe Mathieu-Daudé     tcg_gen_extract_tl(t0, cpu_y, 1, 31);
524b989ce73SRichard Henderson     tcg_gen_deposit_tl(cpu_y, t0, src1, 31, 1);
525fcf5ef2aSThomas Huth 
526fcf5ef2aSThomas Huth     // b1 = N ^ V;
5272a1905c7SRichard Henderson     tcg_gen_xor_tl(t0, cpu_cc_N, cpu_cc_V);
528fcf5ef2aSThomas Huth 
529b989ce73SRichard Henderson     /*
530b989ce73SRichard Henderson      * src1 = (b1 << 31) | (src1 >> 1)
531b989ce73SRichard Henderson      */
5322a1905c7SRichard Henderson     tcg_gen_andi_tl(t0, t0, 1u << 31);
533b989ce73SRichard Henderson     tcg_gen_shri_tl(t_src1, t_src1, 1);
534b989ce73SRichard Henderson     tcg_gen_or_tl(t_src1, t_src1, t0);
535fcf5ef2aSThomas Huth 
536b989ce73SRichard Henderson     gen_op_addcc(dst, t_src1, t_src2);
537fcf5ef2aSThomas Huth }
538fcf5ef2aSThomas Huth 
5390c2e96c1SRichard Henderson static void gen_op_multiply(TCGv dst, TCGv src1, TCGv src2, int sign_ext)
540fcf5ef2aSThomas Huth {
541fcf5ef2aSThomas Huth #if TARGET_LONG_BITS == 32
542fcf5ef2aSThomas Huth     if (sign_ext) {
543fcf5ef2aSThomas Huth         tcg_gen_muls2_tl(dst, cpu_y, src1, src2);
544fcf5ef2aSThomas Huth     } else {
545fcf5ef2aSThomas Huth         tcg_gen_mulu2_tl(dst, cpu_y, src1, src2);
546fcf5ef2aSThomas Huth     }
547fcf5ef2aSThomas Huth #else
548fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new_i64();
549fcf5ef2aSThomas Huth     TCGv t1 = tcg_temp_new_i64();
550fcf5ef2aSThomas Huth 
551fcf5ef2aSThomas Huth     if (sign_ext) {
552fcf5ef2aSThomas Huth         tcg_gen_ext32s_i64(t0, src1);
553fcf5ef2aSThomas Huth         tcg_gen_ext32s_i64(t1, src2);
554fcf5ef2aSThomas Huth     } else {
555fcf5ef2aSThomas Huth         tcg_gen_ext32u_i64(t0, src1);
556fcf5ef2aSThomas Huth         tcg_gen_ext32u_i64(t1, src2);
557fcf5ef2aSThomas Huth     }
558fcf5ef2aSThomas Huth 
559fcf5ef2aSThomas Huth     tcg_gen_mul_i64(dst, t0, t1);
560fcf5ef2aSThomas Huth     tcg_gen_shri_i64(cpu_y, dst, 32);
561fcf5ef2aSThomas Huth #endif
562fcf5ef2aSThomas Huth }
563fcf5ef2aSThomas Huth 
5640c2e96c1SRichard Henderson static void gen_op_umul(TCGv dst, TCGv src1, TCGv src2)
565fcf5ef2aSThomas Huth {
566fcf5ef2aSThomas Huth     /* zero-extend truncated operands before multiplication */
567fcf5ef2aSThomas Huth     gen_op_multiply(dst, src1, src2, 0);
568fcf5ef2aSThomas Huth }
569fcf5ef2aSThomas Huth 
5700c2e96c1SRichard Henderson static void gen_op_smul(TCGv dst, TCGv src1, TCGv src2)
571fcf5ef2aSThomas Huth {
572fcf5ef2aSThomas Huth     /* sign-extend truncated operands before multiplication */
573fcf5ef2aSThomas Huth     gen_op_multiply(dst, src1, src2, 1);
574fcf5ef2aSThomas Huth }
575fcf5ef2aSThomas Huth 
5764ee85ea9SRichard Henderson static void gen_op_udivx(TCGv dst, TCGv src1, TCGv src2)
5774ee85ea9SRichard Henderson {
5784ee85ea9SRichard Henderson     gen_helper_udivx(dst, tcg_env, src1, src2);
5794ee85ea9SRichard Henderson }
5804ee85ea9SRichard Henderson 
5814ee85ea9SRichard Henderson static void gen_op_sdivx(TCGv dst, TCGv src1, TCGv src2)
5824ee85ea9SRichard Henderson {
5834ee85ea9SRichard Henderson     gen_helper_sdivx(dst, tcg_env, src1, src2);
5844ee85ea9SRichard Henderson }
5854ee85ea9SRichard Henderson 
586c2636853SRichard Henderson static void gen_op_udiv(TCGv dst, TCGv src1, TCGv src2)
587c2636853SRichard Henderson {
58813260103SRichard Henderson #ifdef TARGET_SPARC64
589c2636853SRichard Henderson     gen_helper_udiv(dst, tcg_env, src1, src2);
59013260103SRichard Henderson     tcg_gen_ext32u_tl(dst, dst);
59113260103SRichard Henderson #else
59213260103SRichard Henderson     TCGv_i64 t64 = tcg_temp_new_i64();
59313260103SRichard Henderson     gen_helper_udiv(t64, tcg_env, src1, src2);
59413260103SRichard Henderson     tcg_gen_trunc_i64_tl(dst, t64);
59513260103SRichard Henderson #endif
596c2636853SRichard Henderson }
597c2636853SRichard Henderson 
598c2636853SRichard Henderson static void gen_op_sdiv(TCGv dst, TCGv src1, TCGv src2)
599c2636853SRichard Henderson {
60013260103SRichard Henderson #ifdef TARGET_SPARC64
601c2636853SRichard Henderson     gen_helper_sdiv(dst, tcg_env, src1, src2);
60213260103SRichard Henderson     tcg_gen_ext32s_tl(dst, dst);
60313260103SRichard Henderson #else
60413260103SRichard Henderson     TCGv_i64 t64 = tcg_temp_new_i64();
60513260103SRichard Henderson     gen_helper_sdiv(t64, tcg_env, src1, src2);
60613260103SRichard Henderson     tcg_gen_trunc_i64_tl(dst, t64);
60713260103SRichard Henderson #endif
608c2636853SRichard Henderson }
609c2636853SRichard Henderson 
610c2636853SRichard Henderson static void gen_op_udivcc(TCGv dst, TCGv src1, TCGv src2)
611c2636853SRichard Henderson {
61213260103SRichard Henderson     TCGv_i64 t64;
61313260103SRichard Henderson 
61413260103SRichard Henderson #ifdef TARGET_SPARC64
61513260103SRichard Henderson     t64 = cpu_cc_V;
61613260103SRichard Henderson #else
61713260103SRichard Henderson     t64 = tcg_temp_new_i64();
61813260103SRichard Henderson #endif
61913260103SRichard Henderson 
62013260103SRichard Henderson     gen_helper_udiv(t64, tcg_env, src1, src2);
62113260103SRichard Henderson 
62213260103SRichard Henderson #ifdef TARGET_SPARC64
62313260103SRichard Henderson     tcg_gen_ext32u_tl(cpu_cc_N, t64);
62413260103SRichard Henderson     tcg_gen_shri_tl(cpu_cc_V, t64, 32);
62513260103SRichard Henderson     tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N);
62613260103SRichard Henderson     tcg_gen_movi_tl(cpu_icc_C, 0);
62713260103SRichard Henderson #else
62813260103SRichard Henderson     tcg_gen_extr_i64_tl(cpu_cc_N, cpu_cc_V, t64);
62913260103SRichard Henderson #endif
63013260103SRichard Henderson     tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N);
63113260103SRichard Henderson     tcg_gen_movi_tl(cpu_cc_C, 0);
63213260103SRichard Henderson     tcg_gen_mov_tl(dst, cpu_cc_N);
633c2636853SRichard Henderson }
634c2636853SRichard Henderson 
635c2636853SRichard Henderson static void gen_op_sdivcc(TCGv dst, TCGv src1, TCGv src2)
636c2636853SRichard Henderson {
63713260103SRichard Henderson     TCGv_i64 t64;
63813260103SRichard Henderson 
63913260103SRichard Henderson #ifdef TARGET_SPARC64
64013260103SRichard Henderson     t64 = cpu_cc_V;
64113260103SRichard Henderson #else
64213260103SRichard Henderson     t64 = tcg_temp_new_i64();
64313260103SRichard Henderson #endif
64413260103SRichard Henderson 
64513260103SRichard Henderson     gen_helper_sdiv(t64, tcg_env, src1, src2);
64613260103SRichard Henderson 
64713260103SRichard Henderson #ifdef TARGET_SPARC64
64813260103SRichard Henderson     tcg_gen_ext32s_tl(cpu_cc_N, t64);
64913260103SRichard Henderson     tcg_gen_shri_tl(cpu_cc_V, t64, 32);
65013260103SRichard Henderson     tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N);
65113260103SRichard Henderson     tcg_gen_movi_tl(cpu_icc_C, 0);
65213260103SRichard Henderson #else
65313260103SRichard Henderson     tcg_gen_extr_i64_tl(cpu_cc_N, cpu_cc_V, t64);
65413260103SRichard Henderson #endif
65513260103SRichard Henderson     tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N);
65613260103SRichard Henderson     tcg_gen_movi_tl(cpu_cc_C, 0);
65713260103SRichard Henderson     tcg_gen_mov_tl(dst, cpu_cc_N);
658c2636853SRichard Henderson }
659c2636853SRichard Henderson 
660a9aba13dSRichard Henderson static void gen_op_taddcctv(TCGv dst, TCGv src1, TCGv src2)
661a9aba13dSRichard Henderson {
662a9aba13dSRichard Henderson     gen_helper_taddcctv(dst, tcg_env, src1, src2);
663a9aba13dSRichard Henderson }
664a9aba13dSRichard Henderson 
665a9aba13dSRichard Henderson static void gen_op_tsubcctv(TCGv dst, TCGv src1, TCGv src2)
666a9aba13dSRichard Henderson {
667a9aba13dSRichard Henderson     gen_helper_tsubcctv(dst, tcg_env, src1, src2);
668a9aba13dSRichard Henderson }
669a9aba13dSRichard Henderson 
6709c6ec5bcSRichard Henderson static void gen_op_popc(TCGv dst, TCGv src1, TCGv src2)
6719c6ec5bcSRichard Henderson {
6729c6ec5bcSRichard Henderson     tcg_gen_ctpop_tl(dst, src2);
6739c6ec5bcSRichard Henderson }
6749c6ec5bcSRichard Henderson 
67545bfed3bSRichard Henderson #ifndef TARGET_SPARC64
67645bfed3bSRichard Henderson static void gen_helper_array8(TCGv dst, TCGv src1, TCGv src2)
67745bfed3bSRichard Henderson {
67845bfed3bSRichard Henderson     g_assert_not_reached();
67945bfed3bSRichard Henderson }
68045bfed3bSRichard Henderson #endif
68145bfed3bSRichard Henderson 
68245bfed3bSRichard Henderson static void gen_op_array16(TCGv dst, TCGv src1, TCGv src2)
68345bfed3bSRichard Henderson {
68445bfed3bSRichard Henderson     gen_helper_array8(dst, src1, src2);
68545bfed3bSRichard Henderson     tcg_gen_shli_tl(dst, dst, 1);
68645bfed3bSRichard Henderson }
68745bfed3bSRichard Henderson 
68845bfed3bSRichard Henderson static void gen_op_array32(TCGv dst, TCGv src1, TCGv src2)
68945bfed3bSRichard Henderson {
69045bfed3bSRichard Henderson     gen_helper_array8(dst, src1, src2);
69145bfed3bSRichard Henderson     tcg_gen_shli_tl(dst, dst, 2);
69245bfed3bSRichard Henderson }
69345bfed3bSRichard Henderson 
6942f722641SRichard Henderson static void gen_op_fpack16(TCGv_i32 dst, TCGv_i64 src)
6952f722641SRichard Henderson {
6962f722641SRichard Henderson #ifdef TARGET_SPARC64
6972f722641SRichard Henderson     gen_helper_fpack16(dst, cpu_gsr, src);
6982f722641SRichard Henderson #else
6992f722641SRichard Henderson     g_assert_not_reached();
7002f722641SRichard Henderson #endif
7012f722641SRichard Henderson }
7022f722641SRichard Henderson 
7032f722641SRichard Henderson static void gen_op_fpackfix(TCGv_i32 dst, TCGv_i64 src)
7042f722641SRichard Henderson {
7052f722641SRichard Henderson #ifdef TARGET_SPARC64
7062f722641SRichard Henderson     gen_helper_fpackfix(dst, cpu_gsr, src);
7072f722641SRichard Henderson #else
7082f722641SRichard Henderson     g_assert_not_reached();
7092f722641SRichard Henderson #endif
7102f722641SRichard Henderson }
7112f722641SRichard Henderson 
7124b6edc0aSRichard Henderson static void gen_op_fpack32(TCGv_i64 dst, TCGv_i64 src1, TCGv_i64 src2)
7134b6edc0aSRichard Henderson {
7144b6edc0aSRichard Henderson #ifdef TARGET_SPARC64
7154b6edc0aSRichard Henderson     gen_helper_fpack32(dst, cpu_gsr, src1, src2);
7164b6edc0aSRichard Henderson #else
7174b6edc0aSRichard Henderson     g_assert_not_reached();
7184b6edc0aSRichard Henderson #endif
7194b6edc0aSRichard Henderson }
7204b6edc0aSRichard Henderson 
7214b6edc0aSRichard Henderson static void gen_op_faligndata(TCGv_i64 dst, TCGv_i64 s1, TCGv_i64 s2)
7224b6edc0aSRichard Henderson {
7234b6edc0aSRichard Henderson #ifdef TARGET_SPARC64
7244b6edc0aSRichard Henderson     TCGv t1, t2, shift;
7254b6edc0aSRichard Henderson 
7264b6edc0aSRichard Henderson     t1 = tcg_temp_new();
7274b6edc0aSRichard Henderson     t2 = tcg_temp_new();
7284b6edc0aSRichard Henderson     shift = tcg_temp_new();
7294b6edc0aSRichard Henderson 
7304b6edc0aSRichard Henderson     tcg_gen_andi_tl(shift, cpu_gsr, 7);
7314b6edc0aSRichard Henderson     tcg_gen_shli_tl(shift, shift, 3);
7324b6edc0aSRichard Henderson     tcg_gen_shl_tl(t1, s1, shift);
7334b6edc0aSRichard Henderson 
7344b6edc0aSRichard Henderson     /*
7354b6edc0aSRichard Henderson      * A shift of 64 does not produce 0 in TCG.  Divide this into a
7364b6edc0aSRichard Henderson      * shift of (up to 63) followed by a constant shift of 1.
7374b6edc0aSRichard Henderson      */
7384b6edc0aSRichard Henderson     tcg_gen_xori_tl(shift, shift, 63);
7394b6edc0aSRichard Henderson     tcg_gen_shr_tl(t2, s2, shift);
7404b6edc0aSRichard Henderson     tcg_gen_shri_tl(t2, t2, 1);
7414b6edc0aSRichard Henderson 
7424b6edc0aSRichard Henderson     tcg_gen_or_tl(dst, t1, t2);
7434b6edc0aSRichard Henderson #else
7444b6edc0aSRichard Henderson     g_assert_not_reached();
7454b6edc0aSRichard Henderson #endif
7464b6edc0aSRichard Henderson }
7474b6edc0aSRichard Henderson 
7484b6edc0aSRichard Henderson static void gen_op_bshuffle(TCGv_i64 dst, TCGv_i64 src1, TCGv_i64 src2)
7494b6edc0aSRichard Henderson {
7504b6edc0aSRichard Henderson #ifdef TARGET_SPARC64
7514b6edc0aSRichard Henderson     gen_helper_bshuffle(dst, cpu_gsr, src1, src2);
7524b6edc0aSRichard Henderson #else
7534b6edc0aSRichard Henderson     g_assert_not_reached();
7544b6edc0aSRichard Henderson #endif
7554b6edc0aSRichard Henderson }
7564b6edc0aSRichard Henderson 
757fcf5ef2aSThomas Huth // 1
7580c2e96c1SRichard Henderson static void gen_op_eval_ba(TCGv dst)
759fcf5ef2aSThomas Huth {
760fcf5ef2aSThomas Huth     tcg_gen_movi_tl(dst, 1);
761fcf5ef2aSThomas Huth }
762fcf5ef2aSThomas Huth 
763fcf5ef2aSThomas Huth // 0
7640c2e96c1SRichard Henderson static void gen_op_eval_bn(TCGv dst)
765fcf5ef2aSThomas Huth {
766fcf5ef2aSThomas Huth     tcg_gen_movi_tl(dst, 0);
767fcf5ef2aSThomas Huth }
768fcf5ef2aSThomas Huth 
769fcf5ef2aSThomas Huth /*
770fcf5ef2aSThomas Huth   FPSR bit field FCC1 | FCC0:
771fcf5ef2aSThomas Huth    0 =
772fcf5ef2aSThomas Huth    1 <
773fcf5ef2aSThomas Huth    2 >
774fcf5ef2aSThomas Huth    3 unordered
775fcf5ef2aSThomas Huth */
7760c2e96c1SRichard Henderson static void gen_mov_reg_FCC0(TCGv reg, TCGv src,
777fcf5ef2aSThomas Huth                                     unsigned int fcc_offset)
778fcf5ef2aSThomas Huth {
779fcf5ef2aSThomas Huth     tcg_gen_shri_tl(reg, src, FSR_FCC0_SHIFT + fcc_offset);
780fcf5ef2aSThomas Huth     tcg_gen_andi_tl(reg, reg, 0x1);
781fcf5ef2aSThomas Huth }
782fcf5ef2aSThomas Huth 
7830c2e96c1SRichard Henderson static void gen_mov_reg_FCC1(TCGv reg, TCGv src, unsigned int fcc_offset)
784fcf5ef2aSThomas Huth {
785fcf5ef2aSThomas Huth     tcg_gen_shri_tl(reg, src, FSR_FCC1_SHIFT + fcc_offset);
786fcf5ef2aSThomas Huth     tcg_gen_andi_tl(reg, reg, 0x1);
787fcf5ef2aSThomas Huth }
788fcf5ef2aSThomas Huth 
789fcf5ef2aSThomas Huth // !0: FCC0 | FCC1
7900c2e96c1SRichard Henderson static void gen_op_eval_fbne(TCGv dst, TCGv src, unsigned int fcc_offset)
791fcf5ef2aSThomas Huth {
792fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
793fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
794fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(t0, src, fcc_offset);
795fcf5ef2aSThomas Huth     tcg_gen_or_tl(dst, dst, t0);
796fcf5ef2aSThomas Huth }
797fcf5ef2aSThomas Huth 
798fcf5ef2aSThomas Huth // 1 or 2: FCC0 ^ FCC1
7990c2e96c1SRichard Henderson static void gen_op_eval_fblg(TCGv dst, TCGv src, unsigned int fcc_offset)
800fcf5ef2aSThomas Huth {
801fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
802fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
803fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(t0, src, fcc_offset);
804fcf5ef2aSThomas Huth     tcg_gen_xor_tl(dst, dst, t0);
805fcf5ef2aSThomas Huth }
806fcf5ef2aSThomas Huth 
807fcf5ef2aSThomas Huth // 1 or 3: FCC0
8080c2e96c1SRichard Henderson static void gen_op_eval_fbul(TCGv dst, TCGv src, unsigned int fcc_offset)
809fcf5ef2aSThomas Huth {
810fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
811fcf5ef2aSThomas Huth }
812fcf5ef2aSThomas Huth 
813fcf5ef2aSThomas Huth // 1: FCC0 & !FCC1
8140c2e96c1SRichard Henderson static void gen_op_eval_fbl(TCGv dst, TCGv src, unsigned int fcc_offset)
815fcf5ef2aSThomas Huth {
816fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
817fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
818fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(t0, src, fcc_offset);
819fcf5ef2aSThomas Huth     tcg_gen_andc_tl(dst, dst, t0);
820fcf5ef2aSThomas Huth }
821fcf5ef2aSThomas Huth 
822fcf5ef2aSThomas Huth // 2 or 3: FCC1
8230c2e96c1SRichard Henderson static void gen_op_eval_fbug(TCGv dst, TCGv src, unsigned int fcc_offset)
824fcf5ef2aSThomas Huth {
825fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(dst, src, fcc_offset);
826fcf5ef2aSThomas Huth }
827fcf5ef2aSThomas Huth 
828fcf5ef2aSThomas Huth // 2: !FCC0 & FCC1
8290c2e96c1SRichard Henderson static void gen_op_eval_fbg(TCGv dst, TCGv src, unsigned int fcc_offset)
830fcf5ef2aSThomas Huth {
831fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
832fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
833fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(t0, src, fcc_offset);
834fcf5ef2aSThomas Huth     tcg_gen_andc_tl(dst, t0, dst);
835fcf5ef2aSThomas Huth }
836fcf5ef2aSThomas Huth 
837fcf5ef2aSThomas Huth // 3: FCC0 & FCC1
8380c2e96c1SRichard Henderson static void gen_op_eval_fbu(TCGv dst, TCGv src, unsigned int fcc_offset)
839fcf5ef2aSThomas Huth {
840fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
841fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
842fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(t0, src, fcc_offset);
843fcf5ef2aSThomas Huth     tcg_gen_and_tl(dst, dst, t0);
844fcf5ef2aSThomas Huth }
845fcf5ef2aSThomas Huth 
846fcf5ef2aSThomas Huth // 0: !(FCC0 | FCC1)
8470c2e96c1SRichard Henderson static void gen_op_eval_fbe(TCGv dst, TCGv src, unsigned int fcc_offset)
848fcf5ef2aSThomas Huth {
849fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
850fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
851fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(t0, src, fcc_offset);
852fcf5ef2aSThomas Huth     tcg_gen_or_tl(dst, dst, t0);
853fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
854fcf5ef2aSThomas Huth }
855fcf5ef2aSThomas Huth 
856fcf5ef2aSThomas Huth // 0 or 3: !(FCC0 ^ FCC1)
8570c2e96c1SRichard Henderson static void gen_op_eval_fbue(TCGv dst, TCGv src, unsigned int fcc_offset)
858fcf5ef2aSThomas Huth {
859fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
860fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
861fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(t0, src, fcc_offset);
862fcf5ef2aSThomas Huth     tcg_gen_xor_tl(dst, dst, t0);
863fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
864fcf5ef2aSThomas Huth }
865fcf5ef2aSThomas Huth 
866fcf5ef2aSThomas Huth // 0 or 2: !FCC0
8670c2e96c1SRichard Henderson static void gen_op_eval_fbge(TCGv dst, TCGv src, unsigned int fcc_offset)
868fcf5ef2aSThomas Huth {
869fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
870fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
871fcf5ef2aSThomas Huth }
872fcf5ef2aSThomas Huth 
873fcf5ef2aSThomas Huth // !1: !(FCC0 & !FCC1)
8740c2e96c1SRichard Henderson static void gen_op_eval_fbuge(TCGv dst, TCGv src, unsigned int fcc_offset)
875fcf5ef2aSThomas Huth {
876fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
877fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
878fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(t0, src, fcc_offset);
879fcf5ef2aSThomas Huth     tcg_gen_andc_tl(dst, dst, t0);
880fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
881fcf5ef2aSThomas Huth }
882fcf5ef2aSThomas Huth 
883fcf5ef2aSThomas Huth // 0 or 1: !FCC1
8840c2e96c1SRichard Henderson static void gen_op_eval_fble(TCGv dst, TCGv src, unsigned int fcc_offset)
885fcf5ef2aSThomas Huth {
886fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(dst, src, fcc_offset);
887fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
888fcf5ef2aSThomas Huth }
889fcf5ef2aSThomas Huth 
890fcf5ef2aSThomas Huth // !2: !(!FCC0 & FCC1)
8910c2e96c1SRichard Henderson static void gen_op_eval_fbule(TCGv dst, TCGv src, unsigned int fcc_offset)
892fcf5ef2aSThomas Huth {
893fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
894fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
895fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(t0, src, fcc_offset);
896fcf5ef2aSThomas Huth     tcg_gen_andc_tl(dst, t0, dst);
897fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
898fcf5ef2aSThomas Huth }
899fcf5ef2aSThomas Huth 
900fcf5ef2aSThomas Huth // !3: !(FCC0 & FCC1)
9010c2e96c1SRichard Henderson static void gen_op_eval_fbo(TCGv dst, TCGv src, unsigned int fcc_offset)
902fcf5ef2aSThomas Huth {
903fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
904fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
905fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(t0, src, fcc_offset);
906fcf5ef2aSThomas Huth     tcg_gen_and_tl(dst, dst, t0);
907fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
908fcf5ef2aSThomas Huth }
909fcf5ef2aSThomas Huth 
9100c2e96c1SRichard Henderson static void gen_branch2(DisasContext *dc, target_ulong pc1,
911fcf5ef2aSThomas Huth                         target_ulong pc2, TCGv r_cond)
912fcf5ef2aSThomas Huth {
913fcf5ef2aSThomas Huth     TCGLabel *l1 = gen_new_label();
914fcf5ef2aSThomas Huth 
915fcf5ef2aSThomas Huth     tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, 0, l1);
916fcf5ef2aSThomas Huth 
917fcf5ef2aSThomas Huth     gen_goto_tb(dc, 0, pc1, pc1 + 4);
918fcf5ef2aSThomas Huth 
919fcf5ef2aSThomas Huth     gen_set_label(l1);
920fcf5ef2aSThomas Huth     gen_goto_tb(dc, 1, pc2, pc2 + 4);
921fcf5ef2aSThomas Huth }
922fcf5ef2aSThomas Huth 
9230c2e96c1SRichard Henderson static void gen_generic_branch(DisasContext *dc)
924fcf5ef2aSThomas Huth {
92500ab7e61SRichard Henderson     TCGv npc0 = tcg_constant_tl(dc->jump_pc[0]);
92600ab7e61SRichard Henderson     TCGv npc1 = tcg_constant_tl(dc->jump_pc[1]);
92700ab7e61SRichard Henderson     TCGv zero = tcg_constant_tl(0);
928fcf5ef2aSThomas Huth 
929fcf5ef2aSThomas Huth     tcg_gen_movcond_tl(TCG_COND_NE, cpu_npc, cpu_cond, zero, npc0, npc1);
930fcf5ef2aSThomas Huth }
931fcf5ef2aSThomas Huth 
932fcf5ef2aSThomas Huth /* call this function before using the condition register as it may
933fcf5ef2aSThomas Huth    have been set for a jump */
9340c2e96c1SRichard Henderson static void flush_cond(DisasContext *dc)
935fcf5ef2aSThomas Huth {
936fcf5ef2aSThomas Huth     if (dc->npc == JUMP_PC) {
937fcf5ef2aSThomas Huth         gen_generic_branch(dc);
93899c82c47SRichard Henderson         dc->npc = DYNAMIC_PC_LOOKUP;
939fcf5ef2aSThomas Huth     }
940fcf5ef2aSThomas Huth }
941fcf5ef2aSThomas Huth 
9420c2e96c1SRichard Henderson static void save_npc(DisasContext *dc)
943fcf5ef2aSThomas Huth {
944633c4283SRichard Henderson     if (dc->npc & 3) {
945633c4283SRichard Henderson         switch (dc->npc) {
946633c4283SRichard Henderson         case JUMP_PC:
947fcf5ef2aSThomas Huth             gen_generic_branch(dc);
94899c82c47SRichard Henderson             dc->npc = DYNAMIC_PC_LOOKUP;
949633c4283SRichard Henderson             break;
950633c4283SRichard Henderson         case DYNAMIC_PC:
951633c4283SRichard Henderson         case DYNAMIC_PC_LOOKUP:
952633c4283SRichard Henderson             break;
953633c4283SRichard Henderson         default:
954633c4283SRichard Henderson             g_assert_not_reached();
955633c4283SRichard Henderson         }
956633c4283SRichard Henderson     } else {
957fcf5ef2aSThomas Huth         tcg_gen_movi_tl(cpu_npc, dc->npc);
958fcf5ef2aSThomas Huth     }
959fcf5ef2aSThomas Huth }
960fcf5ef2aSThomas Huth 
9610c2e96c1SRichard Henderson static void save_state(DisasContext *dc)
962fcf5ef2aSThomas Huth {
963fcf5ef2aSThomas Huth     tcg_gen_movi_tl(cpu_pc, dc->pc);
964fcf5ef2aSThomas Huth     save_npc(dc);
965fcf5ef2aSThomas Huth }
966fcf5ef2aSThomas Huth 
967fcf5ef2aSThomas Huth static void gen_exception(DisasContext *dc, int which)
968fcf5ef2aSThomas Huth {
969fcf5ef2aSThomas Huth     save_state(dc);
970ad75a51eSRichard Henderson     gen_helper_raise_exception(tcg_env, tcg_constant_i32(which));
971af00be49SEmilio G. Cota     dc->base.is_jmp = DISAS_NORETURN;
972fcf5ef2aSThomas Huth }
973fcf5ef2aSThomas Huth 
974186e7890SRichard Henderson static TCGLabel *delay_exceptionv(DisasContext *dc, TCGv_i32 excp)
975fcf5ef2aSThomas Huth {
976186e7890SRichard Henderson     DisasDelayException *e = g_new0(DisasDelayException, 1);
977186e7890SRichard Henderson 
978186e7890SRichard Henderson     e->next = dc->delay_excp_list;
979186e7890SRichard Henderson     dc->delay_excp_list = e;
980186e7890SRichard Henderson 
981186e7890SRichard Henderson     e->lab = gen_new_label();
982186e7890SRichard Henderson     e->excp = excp;
983186e7890SRichard Henderson     e->pc = dc->pc;
984186e7890SRichard Henderson     /* Caller must have used flush_cond before branch. */
985186e7890SRichard Henderson     assert(e->npc != JUMP_PC);
986186e7890SRichard Henderson     e->npc = dc->npc;
987186e7890SRichard Henderson 
988186e7890SRichard Henderson     return e->lab;
989186e7890SRichard Henderson }
990186e7890SRichard Henderson 
991186e7890SRichard Henderson static TCGLabel *delay_exception(DisasContext *dc, int excp)
992186e7890SRichard Henderson {
993186e7890SRichard Henderson     return delay_exceptionv(dc, tcg_constant_i32(excp));
994186e7890SRichard Henderson }
995186e7890SRichard Henderson 
996186e7890SRichard Henderson static void gen_check_align(DisasContext *dc, TCGv addr, int mask)
997186e7890SRichard Henderson {
998186e7890SRichard Henderson     TCGv t = tcg_temp_new();
999186e7890SRichard Henderson     TCGLabel *lab;
1000186e7890SRichard Henderson 
1001186e7890SRichard Henderson     tcg_gen_andi_tl(t, addr, mask);
1002186e7890SRichard Henderson 
1003186e7890SRichard Henderson     flush_cond(dc);
1004186e7890SRichard Henderson     lab = delay_exception(dc, TT_UNALIGNED);
1005186e7890SRichard Henderson     tcg_gen_brcondi_tl(TCG_COND_NE, t, 0, lab);
1006fcf5ef2aSThomas Huth }
1007fcf5ef2aSThomas Huth 
10080c2e96c1SRichard Henderson static void gen_mov_pc_npc(DisasContext *dc)
1009fcf5ef2aSThomas Huth {
1010633c4283SRichard Henderson     if (dc->npc & 3) {
1011633c4283SRichard Henderson         switch (dc->npc) {
1012633c4283SRichard Henderson         case JUMP_PC:
1013fcf5ef2aSThomas Huth             gen_generic_branch(dc);
1014fcf5ef2aSThomas Huth             tcg_gen_mov_tl(cpu_pc, cpu_npc);
101599c82c47SRichard Henderson             dc->pc = DYNAMIC_PC_LOOKUP;
1016633c4283SRichard Henderson             break;
1017633c4283SRichard Henderson         case DYNAMIC_PC:
1018633c4283SRichard Henderson         case DYNAMIC_PC_LOOKUP:
1019fcf5ef2aSThomas Huth             tcg_gen_mov_tl(cpu_pc, cpu_npc);
1020633c4283SRichard Henderson             dc->pc = dc->npc;
1021633c4283SRichard Henderson             break;
1022633c4283SRichard Henderson         default:
1023633c4283SRichard Henderson             g_assert_not_reached();
1024633c4283SRichard Henderson         }
1025fcf5ef2aSThomas Huth     } else {
1026fcf5ef2aSThomas Huth         dc->pc = dc->npc;
1027fcf5ef2aSThomas Huth     }
1028fcf5ef2aSThomas Huth }
1029fcf5ef2aSThomas Huth 
10300c2e96c1SRichard Henderson static void gen_op_next_insn(void)
1031fcf5ef2aSThomas Huth {
1032fcf5ef2aSThomas Huth     tcg_gen_mov_tl(cpu_pc, cpu_npc);
1033fcf5ef2aSThomas Huth     tcg_gen_addi_tl(cpu_npc, cpu_npc, 4);
1034fcf5ef2aSThomas Huth }
1035fcf5ef2aSThomas Huth 
1036fcf5ef2aSThomas Huth static void gen_compare(DisasCompare *cmp, bool xcc, unsigned int cond,
1037fcf5ef2aSThomas Huth                         DisasContext *dc)
1038fcf5ef2aSThomas Huth {
1039b597eedcSRichard Henderson     TCGv t1;
1040fcf5ef2aSThomas Huth 
10412a1905c7SRichard Henderson     cmp->c1 = t1 = tcg_temp_new();
10422a1905c7SRichard Henderson     cmp->c2 = tcg_constant_tl(0);
10432a1905c7SRichard Henderson 
10442a1905c7SRichard Henderson     switch (cond & 7) {
10452a1905c7SRichard Henderson     case 0x0: /* never */
10462a1905c7SRichard Henderson         cmp->cond = TCG_COND_NEVER;
10472a1905c7SRichard Henderson         cmp->c1 = cmp->c2;
1048fcf5ef2aSThomas Huth         break;
10492a1905c7SRichard Henderson 
10502a1905c7SRichard Henderson     case 0x1: /* eq: Z */
10512a1905c7SRichard Henderson         cmp->cond = TCG_COND_EQ;
10522a1905c7SRichard Henderson         if (TARGET_LONG_BITS == 32 || xcc) {
10532a1905c7SRichard Henderson             tcg_gen_mov_tl(t1, cpu_cc_Z);
10542a1905c7SRichard Henderson         } else {
10552a1905c7SRichard Henderson             tcg_gen_ext32u_tl(t1, cpu_icc_Z);
10562a1905c7SRichard Henderson         }
10572a1905c7SRichard Henderson         break;
10582a1905c7SRichard Henderson 
10592a1905c7SRichard Henderson     case 0x2: /* le: Z | (N ^ V) */
10602a1905c7SRichard Henderson         /*
10612a1905c7SRichard Henderson          * Simplify:
10622a1905c7SRichard Henderson          *   cc_Z || (N ^ V) < 0        NE
10632a1905c7SRichard Henderson          *   cc_Z && !((N ^ V) < 0)     EQ
10642a1905c7SRichard Henderson          *   cc_Z & ~((N ^ V) >> TLB)   EQ
10652a1905c7SRichard Henderson          */
10662a1905c7SRichard Henderson         cmp->cond = TCG_COND_EQ;
10672a1905c7SRichard Henderson         tcg_gen_xor_tl(t1, cpu_cc_N, cpu_cc_V);
10682a1905c7SRichard Henderson         tcg_gen_sextract_tl(t1, t1, xcc ? 63 : 31, 1);
10692a1905c7SRichard Henderson         tcg_gen_andc_tl(t1, xcc ? cpu_cc_Z : cpu_icc_Z, t1);
10702a1905c7SRichard Henderson         if (TARGET_LONG_BITS == 64 && !xcc) {
10712a1905c7SRichard Henderson             tcg_gen_ext32u_tl(t1, t1);
10722a1905c7SRichard Henderson         }
10732a1905c7SRichard Henderson         break;
10742a1905c7SRichard Henderson 
10752a1905c7SRichard Henderson     case 0x3: /* lt: N ^ V */
10762a1905c7SRichard Henderson         cmp->cond = TCG_COND_LT;
10772a1905c7SRichard Henderson         tcg_gen_xor_tl(t1, cpu_cc_N, cpu_cc_V);
10782a1905c7SRichard Henderson         if (TARGET_LONG_BITS == 64 && !xcc) {
10792a1905c7SRichard Henderson             tcg_gen_ext32s_tl(t1, t1);
10802a1905c7SRichard Henderson         }
10812a1905c7SRichard Henderson         break;
10822a1905c7SRichard Henderson 
10832a1905c7SRichard Henderson     case 0x4: /* leu: Z | C */
10842a1905c7SRichard Henderson         /*
10852a1905c7SRichard Henderson          * Simplify:
10862a1905c7SRichard Henderson          *   cc_Z == 0 || cc_C != 0     NE
10872a1905c7SRichard Henderson          *   cc_Z != 0 && cc_C == 0     EQ
10882a1905c7SRichard Henderson          *   cc_Z & (cc_C ? 0 : -1)     EQ
10892a1905c7SRichard Henderson          *   cc_Z & (cc_C - 1)          EQ
10902a1905c7SRichard Henderson          */
10912a1905c7SRichard Henderson         cmp->cond = TCG_COND_EQ;
10922a1905c7SRichard Henderson         if (TARGET_LONG_BITS == 32 || xcc) {
10932a1905c7SRichard Henderson             tcg_gen_subi_tl(t1, cpu_cc_C, 1);
10942a1905c7SRichard Henderson             tcg_gen_and_tl(t1, t1, cpu_cc_Z);
10952a1905c7SRichard Henderson         } else {
10962a1905c7SRichard Henderson             tcg_gen_extract_tl(t1, cpu_icc_C, 32, 1);
10972a1905c7SRichard Henderson             tcg_gen_subi_tl(t1, t1, 1);
10982a1905c7SRichard Henderson             tcg_gen_and_tl(t1, t1, cpu_icc_Z);
10992a1905c7SRichard Henderson             tcg_gen_ext32u_tl(t1, t1);
11002a1905c7SRichard Henderson         }
11012a1905c7SRichard Henderson         break;
11022a1905c7SRichard Henderson 
11032a1905c7SRichard Henderson     case 0x5: /* ltu: C */
11042a1905c7SRichard Henderson         cmp->cond = TCG_COND_NE;
11052a1905c7SRichard Henderson         if (TARGET_LONG_BITS == 32 || xcc) {
11062a1905c7SRichard Henderson             tcg_gen_mov_tl(t1, cpu_cc_C);
11072a1905c7SRichard Henderson         } else {
11082a1905c7SRichard Henderson             tcg_gen_extract_tl(t1, cpu_icc_C, 32, 1);
11092a1905c7SRichard Henderson         }
11102a1905c7SRichard Henderson         break;
11112a1905c7SRichard Henderson 
11122a1905c7SRichard Henderson     case 0x6: /* neg: N */
11132a1905c7SRichard Henderson         cmp->cond = TCG_COND_LT;
11142a1905c7SRichard Henderson         if (TARGET_LONG_BITS == 32 || xcc) {
11152a1905c7SRichard Henderson             tcg_gen_mov_tl(t1, cpu_cc_N);
11162a1905c7SRichard Henderson         } else {
11172a1905c7SRichard Henderson             tcg_gen_ext32s_tl(t1, cpu_cc_N);
11182a1905c7SRichard Henderson         }
11192a1905c7SRichard Henderson         break;
11202a1905c7SRichard Henderson 
11212a1905c7SRichard Henderson     case 0x7: /* vs: V */
11222a1905c7SRichard Henderson         cmp->cond = TCG_COND_LT;
11232a1905c7SRichard Henderson         if (TARGET_LONG_BITS == 32 || xcc) {
11242a1905c7SRichard Henderson             tcg_gen_mov_tl(t1, cpu_cc_V);
11252a1905c7SRichard Henderson         } else {
11262a1905c7SRichard Henderson             tcg_gen_ext32s_tl(t1, cpu_cc_V);
11272a1905c7SRichard Henderson         }
11282a1905c7SRichard Henderson         break;
11292a1905c7SRichard Henderson     }
11302a1905c7SRichard Henderson     if (cond & 8) {
11312a1905c7SRichard Henderson         cmp->cond = tcg_invert_cond(cmp->cond);
1132fcf5ef2aSThomas Huth     }
1133fcf5ef2aSThomas Huth }
1134fcf5ef2aSThomas Huth 
1135fcf5ef2aSThomas Huth static void gen_fcompare(DisasCompare *cmp, unsigned int cc, unsigned int cond)
1136fcf5ef2aSThomas Huth {
1137fcf5ef2aSThomas Huth     unsigned int offset;
1138fcf5ef2aSThomas Huth     TCGv r_dst;
1139fcf5ef2aSThomas Huth 
1140fcf5ef2aSThomas Huth     /* For now we still generate a straight boolean result.  */
1141fcf5ef2aSThomas Huth     cmp->cond = TCG_COND_NE;
1142fcf5ef2aSThomas Huth     cmp->c1 = r_dst = tcg_temp_new();
114300ab7e61SRichard Henderson     cmp->c2 = tcg_constant_tl(0);
1144fcf5ef2aSThomas Huth 
1145fcf5ef2aSThomas Huth     switch (cc) {
1146fcf5ef2aSThomas Huth     default:
1147fcf5ef2aSThomas Huth     case 0x0:
1148fcf5ef2aSThomas Huth         offset = 0;
1149fcf5ef2aSThomas Huth         break;
1150fcf5ef2aSThomas Huth     case 0x1:
1151fcf5ef2aSThomas Huth         offset = 32 - 10;
1152fcf5ef2aSThomas Huth         break;
1153fcf5ef2aSThomas Huth     case 0x2:
1154fcf5ef2aSThomas Huth         offset = 34 - 10;
1155fcf5ef2aSThomas Huth         break;
1156fcf5ef2aSThomas Huth     case 0x3:
1157fcf5ef2aSThomas Huth         offset = 36 - 10;
1158fcf5ef2aSThomas Huth         break;
1159fcf5ef2aSThomas Huth     }
1160fcf5ef2aSThomas Huth 
1161fcf5ef2aSThomas Huth     switch (cond) {
1162fcf5ef2aSThomas Huth     case 0x0:
1163fcf5ef2aSThomas Huth         gen_op_eval_bn(r_dst);
1164fcf5ef2aSThomas Huth         break;
1165fcf5ef2aSThomas Huth     case 0x1:
1166fcf5ef2aSThomas Huth         gen_op_eval_fbne(r_dst, cpu_fsr, offset);
1167fcf5ef2aSThomas Huth         break;
1168fcf5ef2aSThomas Huth     case 0x2:
1169fcf5ef2aSThomas Huth         gen_op_eval_fblg(r_dst, cpu_fsr, offset);
1170fcf5ef2aSThomas Huth         break;
1171fcf5ef2aSThomas Huth     case 0x3:
1172fcf5ef2aSThomas Huth         gen_op_eval_fbul(r_dst, cpu_fsr, offset);
1173fcf5ef2aSThomas Huth         break;
1174fcf5ef2aSThomas Huth     case 0x4:
1175fcf5ef2aSThomas Huth         gen_op_eval_fbl(r_dst, cpu_fsr, offset);
1176fcf5ef2aSThomas Huth         break;
1177fcf5ef2aSThomas Huth     case 0x5:
1178fcf5ef2aSThomas Huth         gen_op_eval_fbug(r_dst, cpu_fsr, offset);
1179fcf5ef2aSThomas Huth         break;
1180fcf5ef2aSThomas Huth     case 0x6:
1181fcf5ef2aSThomas Huth         gen_op_eval_fbg(r_dst, cpu_fsr, offset);
1182fcf5ef2aSThomas Huth         break;
1183fcf5ef2aSThomas Huth     case 0x7:
1184fcf5ef2aSThomas Huth         gen_op_eval_fbu(r_dst, cpu_fsr, offset);
1185fcf5ef2aSThomas Huth         break;
1186fcf5ef2aSThomas Huth     case 0x8:
1187fcf5ef2aSThomas Huth         gen_op_eval_ba(r_dst);
1188fcf5ef2aSThomas Huth         break;
1189fcf5ef2aSThomas Huth     case 0x9:
1190fcf5ef2aSThomas Huth         gen_op_eval_fbe(r_dst, cpu_fsr, offset);
1191fcf5ef2aSThomas Huth         break;
1192fcf5ef2aSThomas Huth     case 0xa:
1193fcf5ef2aSThomas Huth         gen_op_eval_fbue(r_dst, cpu_fsr, offset);
1194fcf5ef2aSThomas Huth         break;
1195fcf5ef2aSThomas Huth     case 0xb:
1196fcf5ef2aSThomas Huth         gen_op_eval_fbge(r_dst, cpu_fsr, offset);
1197fcf5ef2aSThomas Huth         break;
1198fcf5ef2aSThomas Huth     case 0xc:
1199fcf5ef2aSThomas Huth         gen_op_eval_fbuge(r_dst, cpu_fsr, offset);
1200fcf5ef2aSThomas Huth         break;
1201fcf5ef2aSThomas Huth     case 0xd:
1202fcf5ef2aSThomas Huth         gen_op_eval_fble(r_dst, cpu_fsr, offset);
1203fcf5ef2aSThomas Huth         break;
1204fcf5ef2aSThomas Huth     case 0xe:
1205fcf5ef2aSThomas Huth         gen_op_eval_fbule(r_dst, cpu_fsr, offset);
1206fcf5ef2aSThomas Huth         break;
1207fcf5ef2aSThomas Huth     case 0xf:
1208fcf5ef2aSThomas Huth         gen_op_eval_fbo(r_dst, cpu_fsr, offset);
1209fcf5ef2aSThomas Huth         break;
1210fcf5ef2aSThomas Huth     }
1211fcf5ef2aSThomas Huth }
1212fcf5ef2aSThomas Huth 
1213fcf5ef2aSThomas Huth // Inverted logic
1214ab9ffe98SRichard Henderson static const TCGCond gen_tcg_cond_reg[8] = {
1215ab9ffe98SRichard Henderson     TCG_COND_NEVER,  /* reserved */
1216fcf5ef2aSThomas Huth     TCG_COND_NE,
1217fcf5ef2aSThomas Huth     TCG_COND_GT,
1218fcf5ef2aSThomas Huth     TCG_COND_GE,
1219ab9ffe98SRichard Henderson     TCG_COND_NEVER,  /* reserved */
1220fcf5ef2aSThomas Huth     TCG_COND_EQ,
1221fcf5ef2aSThomas Huth     TCG_COND_LE,
1222fcf5ef2aSThomas Huth     TCG_COND_LT,
1223fcf5ef2aSThomas Huth };
1224fcf5ef2aSThomas Huth 
1225fcf5ef2aSThomas Huth static void gen_compare_reg(DisasCompare *cmp, int cond, TCGv r_src)
1226fcf5ef2aSThomas Huth {
1227fcf5ef2aSThomas Huth     cmp->cond = tcg_invert_cond(gen_tcg_cond_reg[cond]);
1228fcf5ef2aSThomas Huth     cmp->c1 = r_src;
122900ab7e61SRichard Henderson     cmp->c2 = tcg_constant_tl(0);
1230fcf5ef2aSThomas Huth }
1231fcf5ef2aSThomas Huth 
1232baf3dbf2SRichard Henderson static void gen_op_clear_ieee_excp_and_FTT(void)
1233baf3dbf2SRichard Henderson {
1234baf3dbf2SRichard Henderson     tcg_gen_andi_tl(cpu_fsr, cpu_fsr, FSR_FTT_CEXC_NMASK);
1235baf3dbf2SRichard Henderson }
1236baf3dbf2SRichard Henderson 
1237baf3dbf2SRichard Henderson static void gen_op_fmovs(TCGv_i32 dst, TCGv_i32 src)
1238baf3dbf2SRichard Henderson {
1239baf3dbf2SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
1240baf3dbf2SRichard Henderson     tcg_gen_mov_i32(dst, src);
1241baf3dbf2SRichard Henderson }
1242baf3dbf2SRichard Henderson 
1243baf3dbf2SRichard Henderson static void gen_op_fnegs(TCGv_i32 dst, TCGv_i32 src)
1244baf3dbf2SRichard Henderson {
1245baf3dbf2SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
1246baf3dbf2SRichard Henderson     gen_helper_fnegs(dst, src);
1247baf3dbf2SRichard Henderson }
1248baf3dbf2SRichard Henderson 
1249baf3dbf2SRichard Henderson static void gen_op_fabss(TCGv_i32 dst, TCGv_i32 src)
1250baf3dbf2SRichard Henderson {
1251baf3dbf2SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
1252baf3dbf2SRichard Henderson     gen_helper_fabss(dst, src);
1253baf3dbf2SRichard Henderson }
1254baf3dbf2SRichard Henderson 
1255c6d83e4fSRichard Henderson static void gen_op_fmovd(TCGv_i64 dst, TCGv_i64 src)
1256c6d83e4fSRichard Henderson {
1257c6d83e4fSRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
1258c6d83e4fSRichard Henderson     tcg_gen_mov_i64(dst, src);
1259c6d83e4fSRichard Henderson }
1260c6d83e4fSRichard Henderson 
1261c6d83e4fSRichard Henderson static void gen_op_fnegd(TCGv_i64 dst, TCGv_i64 src)
1262c6d83e4fSRichard Henderson {
1263c6d83e4fSRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
1264c6d83e4fSRichard Henderson     gen_helper_fnegd(dst, src);
1265c6d83e4fSRichard Henderson }
1266c6d83e4fSRichard Henderson 
1267c6d83e4fSRichard Henderson static void gen_op_fabsd(TCGv_i64 dst, TCGv_i64 src)
1268c6d83e4fSRichard Henderson {
1269c6d83e4fSRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
1270c6d83e4fSRichard Henderson     gen_helper_fabsd(dst, src);
1271c6d83e4fSRichard Henderson }
1272c6d83e4fSRichard Henderson 
1273fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
12740c2e96c1SRichard Henderson static void gen_op_fcmps(int fccno, TCGv_i32 r_rs1, TCGv_i32 r_rs2)
1275fcf5ef2aSThomas Huth {
1276fcf5ef2aSThomas Huth     switch (fccno) {
1277fcf5ef2aSThomas Huth     case 0:
1278ad75a51eSRichard Henderson         gen_helper_fcmps(cpu_fsr, tcg_env, r_rs1, r_rs2);
1279fcf5ef2aSThomas Huth         break;
1280fcf5ef2aSThomas Huth     case 1:
1281ad75a51eSRichard Henderson         gen_helper_fcmps_fcc1(cpu_fsr, tcg_env, r_rs1, r_rs2);
1282fcf5ef2aSThomas Huth         break;
1283fcf5ef2aSThomas Huth     case 2:
1284ad75a51eSRichard Henderson         gen_helper_fcmps_fcc2(cpu_fsr, tcg_env, r_rs1, r_rs2);
1285fcf5ef2aSThomas Huth         break;
1286fcf5ef2aSThomas Huth     case 3:
1287ad75a51eSRichard Henderson         gen_helper_fcmps_fcc3(cpu_fsr, tcg_env, r_rs1, r_rs2);
1288fcf5ef2aSThomas Huth         break;
1289fcf5ef2aSThomas Huth     }
1290fcf5ef2aSThomas Huth }
1291fcf5ef2aSThomas Huth 
12920c2e96c1SRichard Henderson static void gen_op_fcmpd(int fccno, TCGv_i64 r_rs1, TCGv_i64 r_rs2)
1293fcf5ef2aSThomas Huth {
1294fcf5ef2aSThomas Huth     switch (fccno) {
1295fcf5ef2aSThomas Huth     case 0:
1296ad75a51eSRichard Henderson         gen_helper_fcmpd(cpu_fsr, tcg_env, r_rs1, r_rs2);
1297fcf5ef2aSThomas Huth         break;
1298fcf5ef2aSThomas Huth     case 1:
1299ad75a51eSRichard Henderson         gen_helper_fcmpd_fcc1(cpu_fsr, tcg_env, r_rs1, r_rs2);
1300fcf5ef2aSThomas Huth         break;
1301fcf5ef2aSThomas Huth     case 2:
1302ad75a51eSRichard Henderson         gen_helper_fcmpd_fcc2(cpu_fsr, tcg_env, r_rs1, r_rs2);
1303fcf5ef2aSThomas Huth         break;
1304fcf5ef2aSThomas Huth     case 3:
1305ad75a51eSRichard Henderson         gen_helper_fcmpd_fcc3(cpu_fsr, tcg_env, r_rs1, r_rs2);
1306fcf5ef2aSThomas Huth         break;
1307fcf5ef2aSThomas Huth     }
1308fcf5ef2aSThomas Huth }
1309fcf5ef2aSThomas Huth 
13100c2e96c1SRichard Henderson static void gen_op_fcmpq(int fccno)
1311fcf5ef2aSThomas Huth {
1312fcf5ef2aSThomas Huth     switch (fccno) {
1313fcf5ef2aSThomas Huth     case 0:
1314ad75a51eSRichard Henderson         gen_helper_fcmpq(cpu_fsr, tcg_env);
1315fcf5ef2aSThomas Huth         break;
1316fcf5ef2aSThomas Huth     case 1:
1317ad75a51eSRichard Henderson         gen_helper_fcmpq_fcc1(cpu_fsr, tcg_env);
1318fcf5ef2aSThomas Huth         break;
1319fcf5ef2aSThomas Huth     case 2:
1320ad75a51eSRichard Henderson         gen_helper_fcmpq_fcc2(cpu_fsr, tcg_env);
1321fcf5ef2aSThomas Huth         break;
1322fcf5ef2aSThomas Huth     case 3:
1323ad75a51eSRichard Henderson         gen_helper_fcmpq_fcc3(cpu_fsr, tcg_env);
1324fcf5ef2aSThomas Huth         break;
1325fcf5ef2aSThomas Huth     }
1326fcf5ef2aSThomas Huth }
1327fcf5ef2aSThomas Huth 
13280c2e96c1SRichard Henderson static void gen_op_fcmpes(int fccno, TCGv_i32 r_rs1, TCGv_i32 r_rs2)
1329fcf5ef2aSThomas Huth {
1330fcf5ef2aSThomas Huth     switch (fccno) {
1331fcf5ef2aSThomas Huth     case 0:
1332ad75a51eSRichard Henderson         gen_helper_fcmpes(cpu_fsr, tcg_env, r_rs1, r_rs2);
1333fcf5ef2aSThomas Huth         break;
1334fcf5ef2aSThomas Huth     case 1:
1335ad75a51eSRichard Henderson         gen_helper_fcmpes_fcc1(cpu_fsr, tcg_env, r_rs1, r_rs2);
1336fcf5ef2aSThomas Huth         break;
1337fcf5ef2aSThomas Huth     case 2:
1338ad75a51eSRichard Henderson         gen_helper_fcmpes_fcc2(cpu_fsr, tcg_env, r_rs1, r_rs2);
1339fcf5ef2aSThomas Huth         break;
1340fcf5ef2aSThomas Huth     case 3:
1341ad75a51eSRichard Henderson         gen_helper_fcmpes_fcc3(cpu_fsr, tcg_env, r_rs1, r_rs2);
1342fcf5ef2aSThomas Huth         break;
1343fcf5ef2aSThomas Huth     }
1344fcf5ef2aSThomas Huth }
1345fcf5ef2aSThomas Huth 
13460c2e96c1SRichard Henderson static void gen_op_fcmped(int fccno, TCGv_i64 r_rs1, TCGv_i64 r_rs2)
1347fcf5ef2aSThomas Huth {
1348fcf5ef2aSThomas Huth     switch (fccno) {
1349fcf5ef2aSThomas Huth     case 0:
1350ad75a51eSRichard Henderson         gen_helper_fcmped(cpu_fsr, tcg_env, r_rs1, r_rs2);
1351fcf5ef2aSThomas Huth         break;
1352fcf5ef2aSThomas Huth     case 1:
1353ad75a51eSRichard Henderson         gen_helper_fcmped_fcc1(cpu_fsr, tcg_env, r_rs1, r_rs2);
1354fcf5ef2aSThomas Huth         break;
1355fcf5ef2aSThomas Huth     case 2:
1356ad75a51eSRichard Henderson         gen_helper_fcmped_fcc2(cpu_fsr, tcg_env, r_rs1, r_rs2);
1357fcf5ef2aSThomas Huth         break;
1358fcf5ef2aSThomas Huth     case 3:
1359ad75a51eSRichard Henderson         gen_helper_fcmped_fcc3(cpu_fsr, tcg_env, r_rs1, r_rs2);
1360fcf5ef2aSThomas Huth         break;
1361fcf5ef2aSThomas Huth     }
1362fcf5ef2aSThomas Huth }
1363fcf5ef2aSThomas Huth 
13640c2e96c1SRichard Henderson static void gen_op_fcmpeq(int fccno)
1365fcf5ef2aSThomas Huth {
1366fcf5ef2aSThomas Huth     switch (fccno) {
1367fcf5ef2aSThomas Huth     case 0:
1368ad75a51eSRichard Henderson         gen_helper_fcmpeq(cpu_fsr, tcg_env);
1369fcf5ef2aSThomas Huth         break;
1370fcf5ef2aSThomas Huth     case 1:
1371ad75a51eSRichard Henderson         gen_helper_fcmpeq_fcc1(cpu_fsr, tcg_env);
1372fcf5ef2aSThomas Huth         break;
1373fcf5ef2aSThomas Huth     case 2:
1374ad75a51eSRichard Henderson         gen_helper_fcmpeq_fcc2(cpu_fsr, tcg_env);
1375fcf5ef2aSThomas Huth         break;
1376fcf5ef2aSThomas Huth     case 3:
1377ad75a51eSRichard Henderson         gen_helper_fcmpeq_fcc3(cpu_fsr, tcg_env);
1378fcf5ef2aSThomas Huth         break;
1379fcf5ef2aSThomas Huth     }
1380fcf5ef2aSThomas Huth }
1381fcf5ef2aSThomas Huth 
1382fcf5ef2aSThomas Huth #else
1383fcf5ef2aSThomas Huth 
13840c2e96c1SRichard Henderson static void gen_op_fcmps(int fccno, TCGv r_rs1, TCGv r_rs2)
1385fcf5ef2aSThomas Huth {
1386ad75a51eSRichard Henderson     gen_helper_fcmps(cpu_fsr, tcg_env, r_rs1, r_rs2);
1387fcf5ef2aSThomas Huth }
1388fcf5ef2aSThomas Huth 
13890c2e96c1SRichard Henderson static void gen_op_fcmpd(int fccno, TCGv_i64 r_rs1, TCGv_i64 r_rs2)
1390fcf5ef2aSThomas Huth {
1391ad75a51eSRichard Henderson     gen_helper_fcmpd(cpu_fsr, tcg_env, r_rs1, r_rs2);
1392fcf5ef2aSThomas Huth }
1393fcf5ef2aSThomas Huth 
13940c2e96c1SRichard Henderson static void gen_op_fcmpq(int fccno)
1395fcf5ef2aSThomas Huth {
1396ad75a51eSRichard Henderson     gen_helper_fcmpq(cpu_fsr, tcg_env);
1397fcf5ef2aSThomas Huth }
1398fcf5ef2aSThomas Huth 
13990c2e96c1SRichard Henderson static void gen_op_fcmpes(int fccno, TCGv r_rs1, TCGv r_rs2)
1400fcf5ef2aSThomas Huth {
1401ad75a51eSRichard Henderson     gen_helper_fcmpes(cpu_fsr, tcg_env, r_rs1, r_rs2);
1402fcf5ef2aSThomas Huth }
1403fcf5ef2aSThomas Huth 
14040c2e96c1SRichard Henderson static void gen_op_fcmped(int fccno, TCGv_i64 r_rs1, TCGv_i64 r_rs2)
1405fcf5ef2aSThomas Huth {
1406ad75a51eSRichard Henderson     gen_helper_fcmped(cpu_fsr, tcg_env, r_rs1, r_rs2);
1407fcf5ef2aSThomas Huth }
1408fcf5ef2aSThomas Huth 
14090c2e96c1SRichard Henderson static void gen_op_fcmpeq(int fccno)
1410fcf5ef2aSThomas Huth {
1411ad75a51eSRichard Henderson     gen_helper_fcmpeq(cpu_fsr, tcg_env);
1412fcf5ef2aSThomas Huth }
1413fcf5ef2aSThomas Huth #endif
1414fcf5ef2aSThomas Huth 
1415fcf5ef2aSThomas Huth static void gen_op_fpexception_im(DisasContext *dc, int fsr_flags)
1416fcf5ef2aSThomas Huth {
1417fcf5ef2aSThomas Huth     tcg_gen_andi_tl(cpu_fsr, cpu_fsr, FSR_FTT_NMASK);
1418fcf5ef2aSThomas Huth     tcg_gen_ori_tl(cpu_fsr, cpu_fsr, fsr_flags);
1419fcf5ef2aSThomas Huth     gen_exception(dc, TT_FP_EXCP);
1420fcf5ef2aSThomas Huth }
1421fcf5ef2aSThomas Huth 
1422fcf5ef2aSThomas Huth static int gen_trap_ifnofpu(DisasContext *dc)
1423fcf5ef2aSThomas Huth {
1424fcf5ef2aSThomas Huth #if !defined(CONFIG_USER_ONLY)
1425fcf5ef2aSThomas Huth     if (!dc->fpu_enabled) {
1426fcf5ef2aSThomas Huth         gen_exception(dc, TT_NFPU_INSN);
1427fcf5ef2aSThomas Huth         return 1;
1428fcf5ef2aSThomas Huth     }
1429fcf5ef2aSThomas Huth #endif
1430fcf5ef2aSThomas Huth     return 0;
1431fcf5ef2aSThomas Huth }
1432fcf5ef2aSThomas Huth 
1433fcf5ef2aSThomas Huth /* asi moves */
1434fcf5ef2aSThomas Huth typedef enum {
1435fcf5ef2aSThomas Huth     GET_ASI_HELPER,
1436fcf5ef2aSThomas Huth     GET_ASI_EXCP,
1437fcf5ef2aSThomas Huth     GET_ASI_DIRECT,
1438fcf5ef2aSThomas Huth     GET_ASI_DTWINX,
1439fcf5ef2aSThomas Huth     GET_ASI_BLOCK,
1440fcf5ef2aSThomas Huth     GET_ASI_SHORT,
1441fcf5ef2aSThomas Huth     GET_ASI_BCOPY,
1442fcf5ef2aSThomas Huth     GET_ASI_BFILL,
1443fcf5ef2aSThomas Huth } ASIType;
1444fcf5ef2aSThomas Huth 
1445fcf5ef2aSThomas Huth typedef struct {
1446fcf5ef2aSThomas Huth     ASIType type;
1447fcf5ef2aSThomas Huth     int asi;
1448fcf5ef2aSThomas Huth     int mem_idx;
144914776ab5STony Nguyen     MemOp memop;
1450fcf5ef2aSThomas Huth } DisasASI;
1451fcf5ef2aSThomas Huth 
1452811cc0b0SRichard Henderson /*
1453811cc0b0SRichard Henderson  * Build DisasASI.
1454811cc0b0SRichard Henderson  * For asi == -1, treat as non-asi.
1455811cc0b0SRichard Henderson  * For ask == -2, treat as immediate offset (v8 error, v9 %asi).
1456811cc0b0SRichard Henderson  */
1457811cc0b0SRichard Henderson static DisasASI resolve_asi(DisasContext *dc, int asi, MemOp memop)
1458fcf5ef2aSThomas Huth {
1459fcf5ef2aSThomas Huth     ASIType type = GET_ASI_HELPER;
1460fcf5ef2aSThomas Huth     int mem_idx = dc->mem_idx;
1461fcf5ef2aSThomas Huth 
1462811cc0b0SRichard Henderson     if (asi == -1) {
1463811cc0b0SRichard Henderson         /* Artificial "non-asi" case. */
1464811cc0b0SRichard Henderson         type = GET_ASI_DIRECT;
1465811cc0b0SRichard Henderson         goto done;
1466811cc0b0SRichard Henderson     }
1467811cc0b0SRichard Henderson 
1468fcf5ef2aSThomas Huth #ifndef TARGET_SPARC64
1469fcf5ef2aSThomas Huth     /* Before v9, all asis are immediate and privileged.  */
1470811cc0b0SRichard Henderson     if (asi < 0) {
1471fcf5ef2aSThomas Huth         gen_exception(dc, TT_ILL_INSN);
1472fcf5ef2aSThomas Huth         type = GET_ASI_EXCP;
1473fcf5ef2aSThomas Huth     } else if (supervisor(dc)
1474fcf5ef2aSThomas Huth                /* Note that LEON accepts ASI_USERDATA in user mode, for
1475fcf5ef2aSThomas Huth                   use with CASA.  Also note that previous versions of
1476fcf5ef2aSThomas Huth                   QEMU allowed (and old versions of gcc emitted) ASI_P
1477fcf5ef2aSThomas Huth                   for LEON, which is incorrect.  */
1478fcf5ef2aSThomas Huth                || (asi == ASI_USERDATA
1479fcf5ef2aSThomas Huth                    && (dc->def->features & CPU_FEATURE_CASA))) {
1480fcf5ef2aSThomas Huth         switch (asi) {
1481fcf5ef2aSThomas Huth         case ASI_USERDATA:   /* User data access */
1482fcf5ef2aSThomas Huth             mem_idx = MMU_USER_IDX;
1483fcf5ef2aSThomas Huth             type = GET_ASI_DIRECT;
1484fcf5ef2aSThomas Huth             break;
1485fcf5ef2aSThomas Huth         case ASI_KERNELDATA: /* Supervisor data access */
1486fcf5ef2aSThomas Huth             mem_idx = MMU_KERNEL_IDX;
1487fcf5ef2aSThomas Huth             type = GET_ASI_DIRECT;
1488fcf5ef2aSThomas Huth             break;
1489fcf5ef2aSThomas Huth         case ASI_M_BYPASS:    /* MMU passthrough */
1490fcf5ef2aSThomas Huth         case ASI_LEON_BYPASS: /* LEON MMU passthrough */
1491fcf5ef2aSThomas Huth             mem_idx = MMU_PHYS_IDX;
1492fcf5ef2aSThomas Huth             type = GET_ASI_DIRECT;
1493fcf5ef2aSThomas Huth             break;
1494fcf5ef2aSThomas Huth         case ASI_M_BCOPY: /* Block copy, sta access */
1495fcf5ef2aSThomas Huth             mem_idx = MMU_KERNEL_IDX;
1496fcf5ef2aSThomas Huth             type = GET_ASI_BCOPY;
1497fcf5ef2aSThomas Huth             break;
1498fcf5ef2aSThomas Huth         case ASI_M_BFILL: /* Block fill, stda access */
1499fcf5ef2aSThomas Huth             mem_idx = MMU_KERNEL_IDX;
1500fcf5ef2aSThomas Huth             type = GET_ASI_BFILL;
1501fcf5ef2aSThomas Huth             break;
1502fcf5ef2aSThomas Huth         }
15036e10f37cSKONRAD Frederic 
15046e10f37cSKONRAD Frederic         /* MMU_PHYS_IDX is used when the MMU is disabled to passthrough the
15056e10f37cSKONRAD Frederic          * permissions check in get_physical_address(..).
15066e10f37cSKONRAD Frederic          */
15076e10f37cSKONRAD Frederic         mem_idx = (dc->mem_idx == MMU_PHYS_IDX) ? MMU_PHYS_IDX : mem_idx;
1508fcf5ef2aSThomas Huth     } else {
1509fcf5ef2aSThomas Huth         gen_exception(dc, TT_PRIV_INSN);
1510fcf5ef2aSThomas Huth         type = GET_ASI_EXCP;
1511fcf5ef2aSThomas Huth     }
1512fcf5ef2aSThomas Huth #else
1513811cc0b0SRichard Henderson     if (asi < 0) {
1514fcf5ef2aSThomas Huth         asi = dc->asi;
1515fcf5ef2aSThomas Huth     }
1516fcf5ef2aSThomas Huth     /* With v9, all asis below 0x80 are privileged.  */
1517fcf5ef2aSThomas Huth     /* ??? We ought to check cpu_has_hypervisor, but we didn't copy
1518fcf5ef2aSThomas Huth        down that bit into DisasContext.  For the moment that's ok,
1519fcf5ef2aSThomas Huth        since the direct implementations below doesn't have any ASIs
1520fcf5ef2aSThomas Huth        in the restricted [0x30, 0x7f] range, and the check will be
1521fcf5ef2aSThomas Huth        done properly in the helper.  */
1522fcf5ef2aSThomas Huth     if (!supervisor(dc) && asi < 0x80) {
1523fcf5ef2aSThomas Huth         gen_exception(dc, TT_PRIV_ACT);
1524fcf5ef2aSThomas Huth         type = GET_ASI_EXCP;
1525fcf5ef2aSThomas Huth     } else {
1526fcf5ef2aSThomas Huth         switch (asi) {
1527fcf5ef2aSThomas Huth         case ASI_REAL:      /* Bypass */
1528fcf5ef2aSThomas Huth         case ASI_REAL_IO:   /* Bypass, non-cacheable */
1529fcf5ef2aSThomas Huth         case ASI_REAL_L:    /* Bypass LE */
1530fcf5ef2aSThomas Huth         case ASI_REAL_IO_L: /* Bypass, non-cacheable LE */
1531fcf5ef2aSThomas Huth         case ASI_TWINX_REAL:   /* Real address, twinx */
1532fcf5ef2aSThomas Huth         case ASI_TWINX_REAL_L: /* Real address, twinx, LE */
1533fcf5ef2aSThomas Huth         case ASI_QUAD_LDD_PHYS:
1534fcf5ef2aSThomas Huth         case ASI_QUAD_LDD_PHYS_L:
1535fcf5ef2aSThomas Huth             mem_idx = MMU_PHYS_IDX;
1536fcf5ef2aSThomas Huth             break;
1537fcf5ef2aSThomas Huth         case ASI_N:  /* Nucleus */
1538fcf5ef2aSThomas Huth         case ASI_NL: /* Nucleus LE */
1539fcf5ef2aSThomas Huth         case ASI_TWINX_N:
1540fcf5ef2aSThomas Huth         case ASI_TWINX_NL:
1541fcf5ef2aSThomas Huth         case ASI_NUCLEUS_QUAD_LDD:
1542fcf5ef2aSThomas Huth         case ASI_NUCLEUS_QUAD_LDD_L:
15439a10756dSArtyom Tarasenko             if (hypervisor(dc)) {
154484f8f587SArtyom Tarasenko                 mem_idx = MMU_PHYS_IDX;
15459a10756dSArtyom Tarasenko             } else {
1546fcf5ef2aSThomas Huth                 mem_idx = MMU_NUCLEUS_IDX;
15479a10756dSArtyom Tarasenko             }
1548fcf5ef2aSThomas Huth             break;
1549fcf5ef2aSThomas Huth         case ASI_AIUP:  /* As if user primary */
1550fcf5ef2aSThomas Huth         case ASI_AIUPL: /* As if user primary LE */
1551fcf5ef2aSThomas Huth         case ASI_TWINX_AIUP:
1552fcf5ef2aSThomas Huth         case ASI_TWINX_AIUP_L:
1553fcf5ef2aSThomas Huth         case ASI_BLK_AIUP_4V:
1554fcf5ef2aSThomas Huth         case ASI_BLK_AIUP_L_4V:
1555fcf5ef2aSThomas Huth         case ASI_BLK_AIUP:
1556fcf5ef2aSThomas Huth         case ASI_BLK_AIUPL:
1557fcf5ef2aSThomas Huth             mem_idx = MMU_USER_IDX;
1558fcf5ef2aSThomas Huth             break;
1559fcf5ef2aSThomas Huth         case ASI_AIUS:  /* As if user secondary */
1560fcf5ef2aSThomas Huth         case ASI_AIUSL: /* As if user secondary LE */
1561fcf5ef2aSThomas Huth         case ASI_TWINX_AIUS:
1562fcf5ef2aSThomas Huth         case ASI_TWINX_AIUS_L:
1563fcf5ef2aSThomas Huth         case ASI_BLK_AIUS_4V:
1564fcf5ef2aSThomas Huth         case ASI_BLK_AIUS_L_4V:
1565fcf5ef2aSThomas Huth         case ASI_BLK_AIUS:
1566fcf5ef2aSThomas Huth         case ASI_BLK_AIUSL:
1567fcf5ef2aSThomas Huth             mem_idx = MMU_USER_SECONDARY_IDX;
1568fcf5ef2aSThomas Huth             break;
1569fcf5ef2aSThomas Huth         case ASI_S:  /* Secondary */
1570fcf5ef2aSThomas Huth         case ASI_SL: /* Secondary LE */
1571fcf5ef2aSThomas Huth         case ASI_TWINX_S:
1572fcf5ef2aSThomas Huth         case ASI_TWINX_SL:
1573fcf5ef2aSThomas Huth         case ASI_BLK_COMMIT_S:
1574fcf5ef2aSThomas Huth         case ASI_BLK_S:
1575fcf5ef2aSThomas Huth         case ASI_BLK_SL:
1576fcf5ef2aSThomas Huth         case ASI_FL8_S:
1577fcf5ef2aSThomas Huth         case ASI_FL8_SL:
1578fcf5ef2aSThomas Huth         case ASI_FL16_S:
1579fcf5ef2aSThomas Huth         case ASI_FL16_SL:
1580fcf5ef2aSThomas Huth             if (mem_idx == MMU_USER_IDX) {
1581fcf5ef2aSThomas Huth                 mem_idx = MMU_USER_SECONDARY_IDX;
1582fcf5ef2aSThomas Huth             } else if (mem_idx == MMU_KERNEL_IDX) {
1583fcf5ef2aSThomas Huth                 mem_idx = MMU_KERNEL_SECONDARY_IDX;
1584fcf5ef2aSThomas Huth             }
1585fcf5ef2aSThomas Huth             break;
1586fcf5ef2aSThomas Huth         case ASI_P:  /* Primary */
1587fcf5ef2aSThomas Huth         case ASI_PL: /* Primary LE */
1588fcf5ef2aSThomas Huth         case ASI_TWINX_P:
1589fcf5ef2aSThomas Huth         case ASI_TWINX_PL:
1590fcf5ef2aSThomas Huth         case ASI_BLK_COMMIT_P:
1591fcf5ef2aSThomas Huth         case ASI_BLK_P:
1592fcf5ef2aSThomas Huth         case ASI_BLK_PL:
1593fcf5ef2aSThomas Huth         case ASI_FL8_P:
1594fcf5ef2aSThomas Huth         case ASI_FL8_PL:
1595fcf5ef2aSThomas Huth         case ASI_FL16_P:
1596fcf5ef2aSThomas Huth         case ASI_FL16_PL:
1597fcf5ef2aSThomas Huth             break;
1598fcf5ef2aSThomas Huth         }
1599fcf5ef2aSThomas Huth         switch (asi) {
1600fcf5ef2aSThomas Huth         case ASI_REAL:
1601fcf5ef2aSThomas Huth         case ASI_REAL_IO:
1602fcf5ef2aSThomas Huth         case ASI_REAL_L:
1603fcf5ef2aSThomas Huth         case ASI_REAL_IO_L:
1604fcf5ef2aSThomas Huth         case ASI_N:
1605fcf5ef2aSThomas Huth         case ASI_NL:
1606fcf5ef2aSThomas Huth         case ASI_AIUP:
1607fcf5ef2aSThomas Huth         case ASI_AIUPL:
1608fcf5ef2aSThomas Huth         case ASI_AIUS:
1609fcf5ef2aSThomas Huth         case ASI_AIUSL:
1610fcf5ef2aSThomas Huth         case ASI_S:
1611fcf5ef2aSThomas Huth         case ASI_SL:
1612fcf5ef2aSThomas Huth         case ASI_P:
1613fcf5ef2aSThomas Huth         case ASI_PL:
1614fcf5ef2aSThomas Huth             type = GET_ASI_DIRECT;
1615fcf5ef2aSThomas Huth             break;
1616fcf5ef2aSThomas Huth         case ASI_TWINX_REAL:
1617fcf5ef2aSThomas Huth         case ASI_TWINX_REAL_L:
1618fcf5ef2aSThomas Huth         case ASI_TWINX_N:
1619fcf5ef2aSThomas Huth         case ASI_TWINX_NL:
1620fcf5ef2aSThomas Huth         case ASI_TWINX_AIUP:
1621fcf5ef2aSThomas Huth         case ASI_TWINX_AIUP_L:
1622fcf5ef2aSThomas Huth         case ASI_TWINX_AIUS:
1623fcf5ef2aSThomas Huth         case ASI_TWINX_AIUS_L:
1624fcf5ef2aSThomas Huth         case ASI_TWINX_P:
1625fcf5ef2aSThomas Huth         case ASI_TWINX_PL:
1626fcf5ef2aSThomas Huth         case ASI_TWINX_S:
1627fcf5ef2aSThomas Huth         case ASI_TWINX_SL:
1628fcf5ef2aSThomas Huth         case ASI_QUAD_LDD_PHYS:
1629fcf5ef2aSThomas Huth         case ASI_QUAD_LDD_PHYS_L:
1630fcf5ef2aSThomas Huth         case ASI_NUCLEUS_QUAD_LDD:
1631fcf5ef2aSThomas Huth         case ASI_NUCLEUS_QUAD_LDD_L:
1632fcf5ef2aSThomas Huth             type = GET_ASI_DTWINX;
1633fcf5ef2aSThomas Huth             break;
1634fcf5ef2aSThomas Huth         case ASI_BLK_COMMIT_P:
1635fcf5ef2aSThomas Huth         case ASI_BLK_COMMIT_S:
1636fcf5ef2aSThomas Huth         case ASI_BLK_AIUP_4V:
1637fcf5ef2aSThomas Huth         case ASI_BLK_AIUP_L_4V:
1638fcf5ef2aSThomas Huth         case ASI_BLK_AIUP:
1639fcf5ef2aSThomas Huth         case ASI_BLK_AIUPL:
1640fcf5ef2aSThomas Huth         case ASI_BLK_AIUS_4V:
1641fcf5ef2aSThomas Huth         case ASI_BLK_AIUS_L_4V:
1642fcf5ef2aSThomas Huth         case ASI_BLK_AIUS:
1643fcf5ef2aSThomas Huth         case ASI_BLK_AIUSL:
1644fcf5ef2aSThomas Huth         case ASI_BLK_S:
1645fcf5ef2aSThomas Huth         case ASI_BLK_SL:
1646fcf5ef2aSThomas Huth         case ASI_BLK_P:
1647fcf5ef2aSThomas Huth         case ASI_BLK_PL:
1648fcf5ef2aSThomas Huth             type = GET_ASI_BLOCK;
1649fcf5ef2aSThomas Huth             break;
1650fcf5ef2aSThomas Huth         case ASI_FL8_S:
1651fcf5ef2aSThomas Huth         case ASI_FL8_SL:
1652fcf5ef2aSThomas Huth         case ASI_FL8_P:
1653fcf5ef2aSThomas Huth         case ASI_FL8_PL:
1654fcf5ef2aSThomas Huth             memop = MO_UB;
1655fcf5ef2aSThomas Huth             type = GET_ASI_SHORT;
1656fcf5ef2aSThomas Huth             break;
1657fcf5ef2aSThomas Huth         case ASI_FL16_S:
1658fcf5ef2aSThomas Huth         case ASI_FL16_SL:
1659fcf5ef2aSThomas Huth         case ASI_FL16_P:
1660fcf5ef2aSThomas Huth         case ASI_FL16_PL:
1661fcf5ef2aSThomas Huth             memop = MO_TEUW;
1662fcf5ef2aSThomas Huth             type = GET_ASI_SHORT;
1663fcf5ef2aSThomas Huth             break;
1664fcf5ef2aSThomas Huth         }
1665fcf5ef2aSThomas Huth         /* The little-endian asis all have bit 3 set.  */
1666fcf5ef2aSThomas Huth         if (asi & 8) {
1667fcf5ef2aSThomas Huth             memop ^= MO_BSWAP;
1668fcf5ef2aSThomas Huth         }
1669fcf5ef2aSThomas Huth     }
1670fcf5ef2aSThomas Huth #endif
1671fcf5ef2aSThomas Huth 
1672811cc0b0SRichard Henderson  done:
1673fcf5ef2aSThomas Huth     return (DisasASI){ type, asi, mem_idx, memop };
1674fcf5ef2aSThomas Huth }
1675fcf5ef2aSThomas Huth 
1676a76779eeSRichard Henderson #if defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
1677a76779eeSRichard Henderson static void gen_helper_ld_asi(TCGv_i64 r, TCGv_env e, TCGv a,
1678a76779eeSRichard Henderson                               TCGv_i32 asi, TCGv_i32 mop)
1679a76779eeSRichard Henderson {
1680a76779eeSRichard Henderson     g_assert_not_reached();
1681a76779eeSRichard Henderson }
1682a76779eeSRichard Henderson 
1683a76779eeSRichard Henderson static void gen_helper_st_asi(TCGv_env e, TCGv a, TCGv_i64 r,
1684a76779eeSRichard Henderson                               TCGv_i32 asi, TCGv_i32 mop)
1685a76779eeSRichard Henderson {
1686a76779eeSRichard Henderson     g_assert_not_reached();
1687a76779eeSRichard Henderson }
1688a76779eeSRichard Henderson #endif
1689a76779eeSRichard Henderson 
169042071fc1SRichard Henderson static void gen_ld_asi(DisasContext *dc, DisasASI *da, TCGv dst, TCGv addr)
1691fcf5ef2aSThomas Huth {
1692c03a0fd1SRichard Henderson     switch (da->type) {
1693fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
1694fcf5ef2aSThomas Huth         break;
1695fcf5ef2aSThomas Huth     case GET_ASI_DTWINX: /* Reserved for ldda.  */
1696fcf5ef2aSThomas Huth         gen_exception(dc, TT_ILL_INSN);
1697fcf5ef2aSThomas Huth         break;
1698fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
1699c03a0fd1SRichard Henderson         tcg_gen_qemu_ld_tl(dst, addr, da->mem_idx, da->memop | MO_ALIGN);
1700fcf5ef2aSThomas Huth         break;
1701fcf5ef2aSThomas Huth     default:
1702fcf5ef2aSThomas Huth         {
1703c03a0fd1SRichard Henderson             TCGv_i32 r_asi = tcg_constant_i32(da->asi);
1704c03a0fd1SRichard Henderson             TCGv_i32 r_mop = tcg_constant_i32(da->memop | MO_ALIGN);
1705fcf5ef2aSThomas Huth 
1706fcf5ef2aSThomas Huth             save_state(dc);
1707fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
1708ad75a51eSRichard Henderson             gen_helper_ld_asi(dst, tcg_env, addr, r_asi, r_mop);
1709fcf5ef2aSThomas Huth #else
1710fcf5ef2aSThomas Huth             {
1711fcf5ef2aSThomas Huth                 TCGv_i64 t64 = tcg_temp_new_i64();
1712ad75a51eSRichard Henderson                 gen_helper_ld_asi(t64, tcg_env, addr, r_asi, r_mop);
1713fcf5ef2aSThomas Huth                 tcg_gen_trunc_i64_tl(dst, t64);
1714fcf5ef2aSThomas Huth             }
1715fcf5ef2aSThomas Huth #endif
1716fcf5ef2aSThomas Huth         }
1717fcf5ef2aSThomas Huth         break;
1718fcf5ef2aSThomas Huth     }
1719fcf5ef2aSThomas Huth }
1720fcf5ef2aSThomas Huth 
172142071fc1SRichard Henderson static void gen_st_asi(DisasContext *dc, DisasASI *da, TCGv src, TCGv addr)
1722c03a0fd1SRichard Henderson {
1723c03a0fd1SRichard Henderson     switch (da->type) {
1724fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
1725fcf5ef2aSThomas Huth         break;
1726c03a0fd1SRichard Henderson 
1727fcf5ef2aSThomas Huth     case GET_ASI_DTWINX: /* Reserved for stda.  */
1728c03a0fd1SRichard Henderson         if (TARGET_LONG_BITS == 32) {
1729fcf5ef2aSThomas Huth             gen_exception(dc, TT_ILL_INSN);
1730fcf5ef2aSThomas Huth             break;
1731c03a0fd1SRichard Henderson         } else if (!(dc->def->features & CPU_FEATURE_HYPV)) {
17323390537bSArtyom Tarasenko             /* Pre OpenSPARC CPUs don't have these */
17333390537bSArtyom Tarasenko             gen_exception(dc, TT_ILL_INSN);
1734fcf5ef2aSThomas Huth             break;
1735c03a0fd1SRichard Henderson         }
1736c03a0fd1SRichard Henderson         /* In OpenSPARC T1+ CPUs TWINX ASIs in store are ST_BLKINIT_ ASIs */
1737c03a0fd1SRichard Henderson         /* fall through */
1738c03a0fd1SRichard Henderson 
1739c03a0fd1SRichard Henderson     case GET_ASI_DIRECT:
1740c03a0fd1SRichard Henderson         tcg_gen_qemu_st_tl(src, addr, da->mem_idx, da->memop | MO_ALIGN);
1741c03a0fd1SRichard Henderson         break;
1742c03a0fd1SRichard Henderson 
1743fcf5ef2aSThomas Huth     case GET_ASI_BCOPY:
1744c03a0fd1SRichard Henderson         assert(TARGET_LONG_BITS == 32);
1745fcf5ef2aSThomas Huth         /* Copy 32 bytes from the address in SRC to ADDR.  */
1746fcf5ef2aSThomas Huth         /* ??? The original qemu code suggests 4-byte alignment, dropping
1747fcf5ef2aSThomas Huth            the low bits, but the only place I can see this used is in the
1748fcf5ef2aSThomas Huth            Linux kernel with 32 byte alignment, which would make more sense
1749fcf5ef2aSThomas Huth            as a cacheline-style operation.  */
1750fcf5ef2aSThomas Huth         {
1751fcf5ef2aSThomas Huth             TCGv saddr = tcg_temp_new();
1752fcf5ef2aSThomas Huth             TCGv daddr = tcg_temp_new();
175300ab7e61SRichard Henderson             TCGv four = tcg_constant_tl(4);
1754fcf5ef2aSThomas Huth             TCGv_i32 tmp = tcg_temp_new_i32();
1755fcf5ef2aSThomas Huth             int i;
1756fcf5ef2aSThomas Huth 
1757fcf5ef2aSThomas Huth             tcg_gen_andi_tl(saddr, src, -4);
1758fcf5ef2aSThomas Huth             tcg_gen_andi_tl(daddr, addr, -4);
1759fcf5ef2aSThomas Huth             for (i = 0; i < 32; i += 4) {
1760fcf5ef2aSThomas Huth                 /* Since the loads and stores are paired, allow the
1761fcf5ef2aSThomas Huth                    copy to happen in the host endianness.  */
1762c03a0fd1SRichard Henderson                 tcg_gen_qemu_ld_i32(tmp, saddr, da->mem_idx, MO_UL);
1763c03a0fd1SRichard Henderson                 tcg_gen_qemu_st_i32(tmp, daddr, da->mem_idx, MO_UL);
1764fcf5ef2aSThomas Huth                 tcg_gen_add_tl(saddr, saddr, four);
1765fcf5ef2aSThomas Huth                 tcg_gen_add_tl(daddr, daddr, four);
1766fcf5ef2aSThomas Huth             }
1767fcf5ef2aSThomas Huth         }
1768fcf5ef2aSThomas Huth         break;
1769c03a0fd1SRichard Henderson 
1770fcf5ef2aSThomas Huth     default:
1771fcf5ef2aSThomas Huth         {
1772c03a0fd1SRichard Henderson             TCGv_i32 r_asi = tcg_constant_i32(da->asi);
1773c03a0fd1SRichard Henderson             TCGv_i32 r_mop = tcg_constant_i32(da->memop | MO_ALIGN);
1774fcf5ef2aSThomas Huth 
1775fcf5ef2aSThomas Huth             save_state(dc);
1776fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
1777ad75a51eSRichard Henderson             gen_helper_st_asi(tcg_env, addr, src, r_asi, r_mop);
1778fcf5ef2aSThomas Huth #else
1779fcf5ef2aSThomas Huth             {
1780fcf5ef2aSThomas Huth                 TCGv_i64 t64 = tcg_temp_new_i64();
1781fcf5ef2aSThomas Huth                 tcg_gen_extu_tl_i64(t64, src);
1782ad75a51eSRichard Henderson                 gen_helper_st_asi(tcg_env, addr, t64, r_asi, r_mop);
1783fcf5ef2aSThomas Huth             }
1784fcf5ef2aSThomas Huth #endif
1785fcf5ef2aSThomas Huth 
1786fcf5ef2aSThomas Huth             /* A write to a TLB register may alter page maps.  End the TB. */
1787fcf5ef2aSThomas Huth             dc->npc = DYNAMIC_PC;
1788fcf5ef2aSThomas Huth         }
1789fcf5ef2aSThomas Huth         break;
1790fcf5ef2aSThomas Huth     }
1791fcf5ef2aSThomas Huth }
1792fcf5ef2aSThomas Huth 
1793dca544b9SRichard Henderson static void gen_swap_asi(DisasContext *dc, DisasASI *da,
1794c03a0fd1SRichard Henderson                          TCGv dst, TCGv src, TCGv addr)
1795c03a0fd1SRichard Henderson {
1796c03a0fd1SRichard Henderson     switch (da->type) {
1797c03a0fd1SRichard Henderson     case GET_ASI_EXCP:
1798c03a0fd1SRichard Henderson         break;
1799c03a0fd1SRichard Henderson     case GET_ASI_DIRECT:
1800dca544b9SRichard Henderson         tcg_gen_atomic_xchg_tl(dst, addr, src,
1801dca544b9SRichard Henderson                                da->mem_idx, da->memop | MO_ALIGN);
1802c03a0fd1SRichard Henderson         break;
1803c03a0fd1SRichard Henderson     default:
1804c03a0fd1SRichard Henderson         /* ??? Should be DAE_invalid_asi.  */
1805c03a0fd1SRichard Henderson         gen_exception(dc, TT_DATA_ACCESS);
1806c03a0fd1SRichard Henderson         break;
1807c03a0fd1SRichard Henderson     }
1808c03a0fd1SRichard Henderson }
1809c03a0fd1SRichard Henderson 
1810d0a11d25SRichard Henderson static void gen_cas_asi(DisasContext *dc, DisasASI *da,
1811c03a0fd1SRichard Henderson                         TCGv oldv, TCGv newv, TCGv cmpv, TCGv addr)
1812c03a0fd1SRichard Henderson {
1813c03a0fd1SRichard Henderson     switch (da->type) {
1814fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
1815c03a0fd1SRichard Henderson         return;
1816fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
1817c03a0fd1SRichard Henderson         tcg_gen_atomic_cmpxchg_tl(oldv, addr, cmpv, newv,
1818c03a0fd1SRichard Henderson                                   da->mem_idx, da->memop | MO_ALIGN);
1819fcf5ef2aSThomas Huth         break;
1820fcf5ef2aSThomas Huth     default:
1821fcf5ef2aSThomas Huth         /* ??? Should be DAE_invalid_asi.  */
1822fcf5ef2aSThomas Huth         gen_exception(dc, TT_DATA_ACCESS);
1823fcf5ef2aSThomas Huth         break;
1824fcf5ef2aSThomas Huth     }
1825fcf5ef2aSThomas Huth }
1826fcf5ef2aSThomas Huth 
1827cf07cd1eSRichard Henderson static void gen_ldstub_asi(DisasContext *dc, DisasASI *da, TCGv dst, TCGv addr)
1828c03a0fd1SRichard Henderson {
1829c03a0fd1SRichard Henderson     switch (da->type) {
1830fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
1831fcf5ef2aSThomas Huth         break;
1832fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
1833cf07cd1eSRichard Henderson         tcg_gen_atomic_xchg_tl(dst, addr, tcg_constant_tl(0xff),
1834cf07cd1eSRichard Henderson                                da->mem_idx, MO_UB);
1835fcf5ef2aSThomas Huth         break;
1836fcf5ef2aSThomas Huth     default:
18373db010c3SRichard Henderson         /* ??? In theory, this should be raise DAE_invalid_asi.
18383db010c3SRichard Henderson            But the SS-20 roms do ldstuba [%l0] #ASI_M_CTL, %o1.  */
1839af00be49SEmilio G. Cota         if (tb_cflags(dc->base.tb) & CF_PARALLEL) {
1840ad75a51eSRichard Henderson             gen_helper_exit_atomic(tcg_env);
18413db010c3SRichard Henderson         } else {
1842c03a0fd1SRichard Henderson             TCGv_i32 r_asi = tcg_constant_i32(da->asi);
184300ab7e61SRichard Henderson             TCGv_i32 r_mop = tcg_constant_i32(MO_UB);
18443db010c3SRichard Henderson             TCGv_i64 s64, t64;
18453db010c3SRichard Henderson 
18463db010c3SRichard Henderson             save_state(dc);
18473db010c3SRichard Henderson             t64 = tcg_temp_new_i64();
1848ad75a51eSRichard Henderson             gen_helper_ld_asi(t64, tcg_env, addr, r_asi, r_mop);
18493db010c3SRichard Henderson 
185000ab7e61SRichard Henderson             s64 = tcg_constant_i64(0xff);
1851ad75a51eSRichard Henderson             gen_helper_st_asi(tcg_env, addr, s64, r_asi, r_mop);
18523db010c3SRichard Henderson 
18533db010c3SRichard Henderson             tcg_gen_trunc_i64_tl(dst, t64);
18543db010c3SRichard Henderson 
18553db010c3SRichard Henderson             /* End the TB.  */
18563db010c3SRichard Henderson             dc->npc = DYNAMIC_PC;
18573db010c3SRichard Henderson         }
1858fcf5ef2aSThomas Huth         break;
1859fcf5ef2aSThomas Huth     }
1860fcf5ef2aSThomas Huth }
1861fcf5ef2aSThomas Huth 
1862287b1152SRichard Henderson static void gen_ldf_asi(DisasContext *dc, DisasASI *da, MemOp orig_size,
18633259b9e2SRichard Henderson                         TCGv addr, int rd)
1864fcf5ef2aSThomas Huth {
18653259b9e2SRichard Henderson     MemOp memop = da->memop;
18663259b9e2SRichard Henderson     MemOp size = memop & MO_SIZE;
1867fcf5ef2aSThomas Huth     TCGv_i32 d32;
1868fcf5ef2aSThomas Huth     TCGv_i64 d64;
1869287b1152SRichard Henderson     TCGv addr_tmp;
1870fcf5ef2aSThomas Huth 
18713259b9e2SRichard Henderson     /* TODO: Use 128-bit load/store below. */
18723259b9e2SRichard Henderson     if (size == MO_128) {
18733259b9e2SRichard Henderson         memop = (memop & ~MO_SIZE) | MO_64;
18743259b9e2SRichard Henderson     }
18753259b9e2SRichard Henderson 
18763259b9e2SRichard Henderson     switch (da->type) {
1877fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
1878fcf5ef2aSThomas Huth         break;
1879fcf5ef2aSThomas Huth 
1880fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
18813259b9e2SRichard Henderson         memop |= MO_ALIGN_4;
1882fcf5ef2aSThomas Huth         switch (size) {
18833259b9e2SRichard Henderson         case MO_32:
1884fcf5ef2aSThomas Huth             d32 = gen_dest_fpr_F(dc);
18853259b9e2SRichard Henderson             tcg_gen_qemu_ld_i32(d32, addr, da->mem_idx, memop);
1886fcf5ef2aSThomas Huth             gen_store_fpr_F(dc, rd, d32);
1887fcf5ef2aSThomas Huth             break;
18883259b9e2SRichard Henderson 
18893259b9e2SRichard Henderson         case MO_64:
18903259b9e2SRichard Henderson             tcg_gen_qemu_ld_i64(cpu_fpr[rd / 2], addr, da->mem_idx, memop);
1891fcf5ef2aSThomas Huth             break;
18923259b9e2SRichard Henderson 
18933259b9e2SRichard Henderson         case MO_128:
1894fcf5ef2aSThomas Huth             d64 = tcg_temp_new_i64();
18953259b9e2SRichard Henderson             tcg_gen_qemu_ld_i64(d64, addr, da->mem_idx, memop);
1896287b1152SRichard Henderson             addr_tmp = tcg_temp_new();
1897287b1152SRichard Henderson             tcg_gen_addi_tl(addr_tmp, addr, 8);
1898287b1152SRichard Henderson             tcg_gen_qemu_ld_i64(cpu_fpr[rd / 2 + 1], addr_tmp, da->mem_idx, memop);
1899fcf5ef2aSThomas Huth             tcg_gen_mov_i64(cpu_fpr[rd / 2], d64);
1900fcf5ef2aSThomas Huth             break;
1901fcf5ef2aSThomas Huth         default:
1902fcf5ef2aSThomas Huth             g_assert_not_reached();
1903fcf5ef2aSThomas Huth         }
1904fcf5ef2aSThomas Huth         break;
1905fcf5ef2aSThomas Huth 
1906fcf5ef2aSThomas Huth     case GET_ASI_BLOCK:
1907fcf5ef2aSThomas Huth         /* Valid for lddfa on aligned registers only.  */
19083259b9e2SRichard Henderson         if (orig_size == MO_64 && (rd & 7) == 0) {
1909fcf5ef2aSThomas Huth             /* The first operation checks required alignment.  */
1910287b1152SRichard Henderson             addr_tmp = tcg_temp_new();
1911287b1152SRichard Henderson             for (int i = 0; ; ++i) {
19123259b9e2SRichard Henderson                 tcg_gen_qemu_ld_i64(cpu_fpr[rd / 2 + i], addr, da->mem_idx,
19133259b9e2SRichard Henderson                                     memop | (i == 0 ? MO_ALIGN_64 : 0));
1914fcf5ef2aSThomas Huth                 if (i == 7) {
1915fcf5ef2aSThomas Huth                     break;
1916fcf5ef2aSThomas Huth                 }
1917287b1152SRichard Henderson                 tcg_gen_addi_tl(addr_tmp, addr, 8);
1918287b1152SRichard Henderson                 addr = addr_tmp;
1919fcf5ef2aSThomas Huth             }
1920fcf5ef2aSThomas Huth         } else {
1921fcf5ef2aSThomas Huth             gen_exception(dc, TT_ILL_INSN);
1922fcf5ef2aSThomas Huth         }
1923fcf5ef2aSThomas Huth         break;
1924fcf5ef2aSThomas Huth 
1925fcf5ef2aSThomas Huth     case GET_ASI_SHORT:
1926fcf5ef2aSThomas Huth         /* Valid for lddfa only.  */
19273259b9e2SRichard Henderson         if (orig_size == MO_64) {
19283259b9e2SRichard Henderson             tcg_gen_qemu_ld_i64(cpu_fpr[rd / 2], addr, da->mem_idx,
19293259b9e2SRichard Henderson                                 memop | MO_ALIGN);
1930fcf5ef2aSThomas Huth         } else {
1931fcf5ef2aSThomas Huth             gen_exception(dc, TT_ILL_INSN);
1932fcf5ef2aSThomas Huth         }
1933fcf5ef2aSThomas Huth         break;
1934fcf5ef2aSThomas Huth 
1935fcf5ef2aSThomas Huth     default:
1936fcf5ef2aSThomas Huth         {
19373259b9e2SRichard Henderson             TCGv_i32 r_asi = tcg_constant_i32(da->asi);
19383259b9e2SRichard Henderson             TCGv_i32 r_mop = tcg_constant_i32(memop | MO_ALIGN);
1939fcf5ef2aSThomas Huth 
1940fcf5ef2aSThomas Huth             save_state(dc);
1941fcf5ef2aSThomas Huth             /* According to the table in the UA2011 manual, the only
1942fcf5ef2aSThomas Huth                other asis that are valid for ldfa/lddfa/ldqfa are
1943fcf5ef2aSThomas Huth                the NO_FAULT asis.  We still need a helper for these,
1944fcf5ef2aSThomas Huth                but we can just use the integer asi helper for them.  */
1945fcf5ef2aSThomas Huth             switch (size) {
19463259b9e2SRichard Henderson             case MO_32:
1947fcf5ef2aSThomas Huth                 d64 = tcg_temp_new_i64();
1948ad75a51eSRichard Henderson                 gen_helper_ld_asi(d64, tcg_env, addr, r_asi, r_mop);
1949fcf5ef2aSThomas Huth                 d32 = gen_dest_fpr_F(dc);
1950fcf5ef2aSThomas Huth                 tcg_gen_extrl_i64_i32(d32, d64);
1951fcf5ef2aSThomas Huth                 gen_store_fpr_F(dc, rd, d32);
1952fcf5ef2aSThomas Huth                 break;
19533259b9e2SRichard Henderson             case MO_64:
19543259b9e2SRichard Henderson                 gen_helper_ld_asi(cpu_fpr[rd / 2], tcg_env, addr,
19553259b9e2SRichard Henderson                                   r_asi, r_mop);
1956fcf5ef2aSThomas Huth                 break;
19573259b9e2SRichard Henderson             case MO_128:
1958fcf5ef2aSThomas Huth                 d64 = tcg_temp_new_i64();
1959ad75a51eSRichard Henderson                 gen_helper_ld_asi(d64, tcg_env, addr, r_asi, r_mop);
1960287b1152SRichard Henderson                 addr_tmp = tcg_temp_new();
1961287b1152SRichard Henderson                 tcg_gen_addi_tl(addr_tmp, addr, 8);
1962287b1152SRichard Henderson                 gen_helper_ld_asi(cpu_fpr[rd / 2 + 1], tcg_env, addr_tmp,
19633259b9e2SRichard Henderson                                   r_asi, r_mop);
1964fcf5ef2aSThomas Huth                 tcg_gen_mov_i64(cpu_fpr[rd / 2], d64);
1965fcf5ef2aSThomas Huth                 break;
1966fcf5ef2aSThomas Huth             default:
1967fcf5ef2aSThomas Huth                 g_assert_not_reached();
1968fcf5ef2aSThomas Huth             }
1969fcf5ef2aSThomas Huth         }
1970fcf5ef2aSThomas Huth         break;
1971fcf5ef2aSThomas Huth     }
1972fcf5ef2aSThomas Huth }
1973fcf5ef2aSThomas Huth 
1974287b1152SRichard Henderson static void gen_stf_asi(DisasContext *dc, DisasASI *da, MemOp orig_size,
19753259b9e2SRichard Henderson                         TCGv addr, int rd)
19763259b9e2SRichard Henderson {
19773259b9e2SRichard Henderson     MemOp memop = da->memop;
19783259b9e2SRichard Henderson     MemOp size = memop & MO_SIZE;
1979fcf5ef2aSThomas Huth     TCGv_i32 d32;
1980287b1152SRichard Henderson     TCGv addr_tmp;
1981fcf5ef2aSThomas Huth 
19823259b9e2SRichard Henderson     /* TODO: Use 128-bit load/store below. */
19833259b9e2SRichard Henderson     if (size == MO_128) {
19843259b9e2SRichard Henderson         memop = (memop & ~MO_SIZE) | MO_64;
19853259b9e2SRichard Henderson     }
19863259b9e2SRichard Henderson 
19873259b9e2SRichard Henderson     switch (da->type) {
1988fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
1989fcf5ef2aSThomas Huth         break;
1990fcf5ef2aSThomas Huth 
1991fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
19923259b9e2SRichard Henderson         memop |= MO_ALIGN_4;
1993fcf5ef2aSThomas Huth         switch (size) {
19943259b9e2SRichard Henderson         case MO_32:
1995fcf5ef2aSThomas Huth             d32 = gen_load_fpr_F(dc, rd);
19963259b9e2SRichard Henderson             tcg_gen_qemu_st_i32(d32, addr, da->mem_idx, memop | MO_ALIGN);
1997fcf5ef2aSThomas Huth             break;
19983259b9e2SRichard Henderson         case MO_64:
19993259b9e2SRichard Henderson             tcg_gen_qemu_st_i64(cpu_fpr[rd / 2], addr, da->mem_idx,
20003259b9e2SRichard Henderson                                 memop | MO_ALIGN_4);
2001fcf5ef2aSThomas Huth             break;
20023259b9e2SRichard Henderson         case MO_128:
2003fcf5ef2aSThomas Huth             /* Only 4-byte alignment required.  However, it is legal for the
2004fcf5ef2aSThomas Huth                cpu to signal the alignment fault, and the OS trap handler is
2005fcf5ef2aSThomas Huth                required to fix it up.  Requiring 16-byte alignment here avoids
2006fcf5ef2aSThomas Huth                having to probe the second page before performing the first
2007fcf5ef2aSThomas Huth                write.  */
20083259b9e2SRichard Henderson             tcg_gen_qemu_st_i64(cpu_fpr[rd / 2], addr, da->mem_idx,
20093259b9e2SRichard Henderson                                 memop | MO_ALIGN_16);
2010287b1152SRichard Henderson             addr_tmp = tcg_temp_new();
2011287b1152SRichard Henderson             tcg_gen_addi_tl(addr_tmp, addr, 8);
2012287b1152SRichard Henderson             tcg_gen_qemu_st_i64(cpu_fpr[rd / 2 + 1], addr_tmp, da->mem_idx, memop);
2013fcf5ef2aSThomas Huth             break;
2014fcf5ef2aSThomas Huth         default:
2015fcf5ef2aSThomas Huth             g_assert_not_reached();
2016fcf5ef2aSThomas Huth         }
2017fcf5ef2aSThomas Huth         break;
2018fcf5ef2aSThomas Huth 
2019fcf5ef2aSThomas Huth     case GET_ASI_BLOCK:
2020fcf5ef2aSThomas Huth         /* Valid for stdfa on aligned registers only.  */
20213259b9e2SRichard Henderson         if (orig_size == MO_64 && (rd & 7) == 0) {
2022fcf5ef2aSThomas Huth             /* The first operation checks required alignment.  */
2023287b1152SRichard Henderson             addr_tmp = tcg_temp_new();
2024287b1152SRichard Henderson             for (int i = 0; ; ++i) {
20253259b9e2SRichard Henderson                 tcg_gen_qemu_st_i64(cpu_fpr[rd / 2 + i], addr, da->mem_idx,
20263259b9e2SRichard Henderson                                     memop | (i == 0 ? MO_ALIGN_64 : 0));
2027fcf5ef2aSThomas Huth                 if (i == 7) {
2028fcf5ef2aSThomas Huth                     break;
2029fcf5ef2aSThomas Huth                 }
2030287b1152SRichard Henderson                 tcg_gen_addi_tl(addr_tmp, addr, 8);
2031287b1152SRichard Henderson                 addr = addr_tmp;
2032fcf5ef2aSThomas Huth             }
2033fcf5ef2aSThomas Huth         } else {
2034fcf5ef2aSThomas Huth             gen_exception(dc, TT_ILL_INSN);
2035fcf5ef2aSThomas Huth         }
2036fcf5ef2aSThomas Huth         break;
2037fcf5ef2aSThomas Huth 
2038fcf5ef2aSThomas Huth     case GET_ASI_SHORT:
2039fcf5ef2aSThomas Huth         /* Valid for stdfa only.  */
20403259b9e2SRichard Henderson         if (orig_size == MO_64) {
20413259b9e2SRichard Henderson             tcg_gen_qemu_st_i64(cpu_fpr[rd / 2], addr, da->mem_idx,
20423259b9e2SRichard Henderson                                 memop | MO_ALIGN);
2043fcf5ef2aSThomas Huth         } else {
2044fcf5ef2aSThomas Huth             gen_exception(dc, TT_ILL_INSN);
2045fcf5ef2aSThomas Huth         }
2046fcf5ef2aSThomas Huth         break;
2047fcf5ef2aSThomas Huth 
2048fcf5ef2aSThomas Huth     default:
2049fcf5ef2aSThomas Huth         /* According to the table in the UA2011 manual, the only
2050fcf5ef2aSThomas Huth            other asis that are valid for ldfa/lddfa/ldqfa are
2051fcf5ef2aSThomas Huth            the PST* asis, which aren't currently handled.  */
2052fcf5ef2aSThomas Huth         gen_exception(dc, TT_ILL_INSN);
2053fcf5ef2aSThomas Huth         break;
2054fcf5ef2aSThomas Huth     }
2055fcf5ef2aSThomas Huth }
2056fcf5ef2aSThomas Huth 
205742071fc1SRichard Henderson static void gen_ldda_asi(DisasContext *dc, DisasASI *da, TCGv addr, int rd)
2058fcf5ef2aSThomas Huth {
2059a76779eeSRichard Henderson     TCGv hi = gen_dest_gpr(dc, rd);
2060a76779eeSRichard Henderson     TCGv lo = gen_dest_gpr(dc, rd + 1);
2061fcf5ef2aSThomas Huth 
2062c03a0fd1SRichard Henderson     switch (da->type) {
2063fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
2064fcf5ef2aSThomas Huth         return;
2065fcf5ef2aSThomas Huth 
2066fcf5ef2aSThomas Huth     case GET_ASI_DTWINX:
2067ebbbec92SRichard Henderson #ifdef TARGET_SPARC64
2068ebbbec92SRichard Henderson         {
2069ebbbec92SRichard Henderson             MemOp mop = (da->memop & MO_BSWAP) | MO_128 | MO_ALIGN_16;
2070ebbbec92SRichard Henderson             TCGv_i128 t = tcg_temp_new_i128();
2071ebbbec92SRichard Henderson 
2072ebbbec92SRichard Henderson             tcg_gen_qemu_ld_i128(t, addr, da->mem_idx, mop);
2073ebbbec92SRichard Henderson             /*
2074ebbbec92SRichard Henderson              * Note that LE twinx acts as if each 64-bit register result is
2075ebbbec92SRichard Henderson              * byte swapped.  We perform one 128-bit LE load, so must swap
2076ebbbec92SRichard Henderson              * the order of the writebacks.
2077ebbbec92SRichard Henderson              */
2078ebbbec92SRichard Henderson             if ((mop & MO_BSWAP) == MO_TE) {
2079ebbbec92SRichard Henderson                 tcg_gen_extr_i128_i64(lo, hi, t);
2080ebbbec92SRichard Henderson             } else {
2081ebbbec92SRichard Henderson                 tcg_gen_extr_i128_i64(hi, lo, t);
2082ebbbec92SRichard Henderson             }
2083ebbbec92SRichard Henderson         }
2084fcf5ef2aSThomas Huth         break;
2085ebbbec92SRichard Henderson #else
2086ebbbec92SRichard Henderson         g_assert_not_reached();
2087ebbbec92SRichard Henderson #endif
2088fcf5ef2aSThomas Huth 
2089fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
2090fcf5ef2aSThomas Huth         {
2091fcf5ef2aSThomas Huth             TCGv_i64 tmp = tcg_temp_new_i64();
2092fcf5ef2aSThomas Huth 
2093c03a0fd1SRichard Henderson             tcg_gen_qemu_ld_i64(tmp, addr, da->mem_idx, da->memop | MO_ALIGN);
2094fcf5ef2aSThomas Huth 
2095fcf5ef2aSThomas Huth             /* Note that LE ldda acts as if each 32-bit register
2096fcf5ef2aSThomas Huth                result is byte swapped.  Having just performed one
2097fcf5ef2aSThomas Huth                64-bit bswap, we need now to swap the writebacks.  */
2098c03a0fd1SRichard Henderson             if ((da->memop & MO_BSWAP) == MO_TE) {
2099a76779eeSRichard Henderson                 tcg_gen_extr_i64_tl(lo, hi, tmp);
2100fcf5ef2aSThomas Huth             } else {
2101a76779eeSRichard Henderson                 tcg_gen_extr_i64_tl(hi, lo, tmp);
2102fcf5ef2aSThomas Huth             }
2103fcf5ef2aSThomas Huth         }
2104fcf5ef2aSThomas Huth         break;
2105fcf5ef2aSThomas Huth 
2106fcf5ef2aSThomas Huth     default:
2107fcf5ef2aSThomas Huth         /* ??? In theory we've handled all of the ASIs that are valid
2108fcf5ef2aSThomas Huth            for ldda, and this should raise DAE_invalid_asi.  However,
2109fcf5ef2aSThomas Huth            real hardware allows others.  This can be seen with e.g.
2110fcf5ef2aSThomas Huth            FreeBSD 10.3 wrt ASI_IC_TAG.  */
2111fcf5ef2aSThomas Huth         {
2112c03a0fd1SRichard Henderson             TCGv_i32 r_asi = tcg_constant_i32(da->asi);
2113c03a0fd1SRichard Henderson             TCGv_i32 r_mop = tcg_constant_i32(da->memop);
2114fcf5ef2aSThomas Huth             TCGv_i64 tmp = tcg_temp_new_i64();
2115fcf5ef2aSThomas Huth 
2116fcf5ef2aSThomas Huth             save_state(dc);
2117ad75a51eSRichard Henderson             gen_helper_ld_asi(tmp, tcg_env, addr, r_asi, r_mop);
2118fcf5ef2aSThomas Huth 
2119fcf5ef2aSThomas Huth             /* See above.  */
2120c03a0fd1SRichard Henderson             if ((da->memop & MO_BSWAP) == MO_TE) {
2121a76779eeSRichard Henderson                 tcg_gen_extr_i64_tl(lo, hi, tmp);
2122fcf5ef2aSThomas Huth             } else {
2123a76779eeSRichard Henderson                 tcg_gen_extr_i64_tl(hi, lo, tmp);
2124fcf5ef2aSThomas Huth             }
2125fcf5ef2aSThomas Huth         }
2126fcf5ef2aSThomas Huth         break;
2127fcf5ef2aSThomas Huth     }
2128fcf5ef2aSThomas Huth 
2129fcf5ef2aSThomas Huth     gen_store_gpr(dc, rd, hi);
2130fcf5ef2aSThomas Huth     gen_store_gpr(dc, rd + 1, lo);
2131fcf5ef2aSThomas Huth }
2132fcf5ef2aSThomas Huth 
213342071fc1SRichard Henderson static void gen_stda_asi(DisasContext *dc, DisasASI *da, TCGv addr, int rd)
2134c03a0fd1SRichard Henderson {
2135c03a0fd1SRichard Henderson     TCGv hi = gen_load_gpr(dc, rd);
2136fcf5ef2aSThomas Huth     TCGv lo = gen_load_gpr(dc, rd + 1);
2137fcf5ef2aSThomas Huth 
2138c03a0fd1SRichard Henderson     switch (da->type) {
2139fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
2140fcf5ef2aSThomas Huth         break;
2141fcf5ef2aSThomas Huth 
2142fcf5ef2aSThomas Huth     case GET_ASI_DTWINX:
2143ebbbec92SRichard Henderson #ifdef TARGET_SPARC64
2144ebbbec92SRichard Henderson         {
2145ebbbec92SRichard Henderson             MemOp mop = (da->memop & MO_BSWAP) | MO_128 | MO_ALIGN_16;
2146ebbbec92SRichard Henderson             TCGv_i128 t = tcg_temp_new_i128();
2147ebbbec92SRichard Henderson 
2148ebbbec92SRichard Henderson             /*
2149ebbbec92SRichard Henderson              * Note that LE twinx acts as if each 64-bit register result is
2150ebbbec92SRichard Henderson              * byte swapped.  We perform one 128-bit LE store, so must swap
2151ebbbec92SRichard Henderson              * the order of the construction.
2152ebbbec92SRichard Henderson              */
2153ebbbec92SRichard Henderson             if ((mop & MO_BSWAP) == MO_TE) {
2154ebbbec92SRichard Henderson                 tcg_gen_concat_i64_i128(t, lo, hi);
2155ebbbec92SRichard Henderson             } else {
2156ebbbec92SRichard Henderson                 tcg_gen_concat_i64_i128(t, hi, lo);
2157ebbbec92SRichard Henderson             }
2158ebbbec92SRichard Henderson             tcg_gen_qemu_st_i128(t, addr, da->mem_idx, mop);
2159ebbbec92SRichard Henderson         }
2160fcf5ef2aSThomas Huth         break;
2161ebbbec92SRichard Henderson #else
2162ebbbec92SRichard Henderson         g_assert_not_reached();
2163ebbbec92SRichard Henderson #endif
2164fcf5ef2aSThomas Huth 
2165fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
2166fcf5ef2aSThomas Huth         {
2167fcf5ef2aSThomas Huth             TCGv_i64 t64 = tcg_temp_new_i64();
2168fcf5ef2aSThomas Huth 
2169fcf5ef2aSThomas Huth             /* Note that LE stda acts as if each 32-bit register result is
2170fcf5ef2aSThomas Huth                byte swapped.  We will perform one 64-bit LE store, so now
2171fcf5ef2aSThomas Huth                we must swap the order of the construction.  */
2172c03a0fd1SRichard Henderson             if ((da->memop & MO_BSWAP) == MO_TE) {
2173a76779eeSRichard Henderson                 tcg_gen_concat_tl_i64(t64, lo, hi);
2174fcf5ef2aSThomas Huth             } else {
2175a76779eeSRichard Henderson                 tcg_gen_concat_tl_i64(t64, hi, lo);
2176fcf5ef2aSThomas Huth             }
2177c03a0fd1SRichard Henderson             tcg_gen_qemu_st_i64(t64, addr, da->mem_idx, da->memop | MO_ALIGN);
2178fcf5ef2aSThomas Huth         }
2179fcf5ef2aSThomas Huth         break;
2180fcf5ef2aSThomas Huth 
2181a76779eeSRichard Henderson     case GET_ASI_BFILL:
2182a76779eeSRichard Henderson         assert(TARGET_LONG_BITS == 32);
2183a76779eeSRichard Henderson         /* Store 32 bytes of T64 to ADDR.  */
2184a76779eeSRichard Henderson         /* ??? The original qemu code suggests 8-byte alignment, dropping
2185a76779eeSRichard Henderson            the low bits, but the only place I can see this used is in the
2186a76779eeSRichard Henderson            Linux kernel with 32 byte alignment, which would make more sense
2187a76779eeSRichard Henderson            as a cacheline-style operation.  */
2188a76779eeSRichard Henderson         {
2189a76779eeSRichard Henderson             TCGv_i64 t64 = tcg_temp_new_i64();
2190a76779eeSRichard Henderson             TCGv d_addr = tcg_temp_new();
2191a76779eeSRichard Henderson             TCGv eight = tcg_constant_tl(8);
2192a76779eeSRichard Henderson             int i;
2193a76779eeSRichard Henderson 
2194a76779eeSRichard Henderson             tcg_gen_concat_tl_i64(t64, lo, hi);
2195a76779eeSRichard Henderson             tcg_gen_andi_tl(d_addr, addr, -8);
2196a76779eeSRichard Henderson             for (i = 0; i < 32; i += 8) {
2197c03a0fd1SRichard Henderson                 tcg_gen_qemu_st_i64(t64, d_addr, da->mem_idx, da->memop);
2198a76779eeSRichard Henderson                 tcg_gen_add_tl(d_addr, d_addr, eight);
2199a76779eeSRichard Henderson             }
2200a76779eeSRichard Henderson         }
2201a76779eeSRichard Henderson         break;
2202a76779eeSRichard Henderson 
2203fcf5ef2aSThomas Huth     default:
2204fcf5ef2aSThomas Huth         /* ??? In theory we've handled all of the ASIs that are valid
2205fcf5ef2aSThomas Huth            for stda, and this should raise DAE_invalid_asi.  */
2206fcf5ef2aSThomas Huth         {
2207c03a0fd1SRichard Henderson             TCGv_i32 r_asi = tcg_constant_i32(da->asi);
2208c03a0fd1SRichard Henderson             TCGv_i32 r_mop = tcg_constant_i32(da->memop);
2209fcf5ef2aSThomas Huth             TCGv_i64 t64 = tcg_temp_new_i64();
2210fcf5ef2aSThomas Huth 
2211fcf5ef2aSThomas Huth             /* See above.  */
2212c03a0fd1SRichard Henderson             if ((da->memop & MO_BSWAP) == MO_TE) {
2213a76779eeSRichard Henderson                 tcg_gen_concat_tl_i64(t64, lo, hi);
2214fcf5ef2aSThomas Huth             } else {
2215a76779eeSRichard Henderson                 tcg_gen_concat_tl_i64(t64, hi, lo);
2216fcf5ef2aSThomas Huth             }
2217fcf5ef2aSThomas Huth 
2218fcf5ef2aSThomas Huth             save_state(dc);
2219ad75a51eSRichard Henderson             gen_helper_st_asi(tcg_env, addr, t64, r_asi, r_mop);
2220fcf5ef2aSThomas Huth         }
2221fcf5ef2aSThomas Huth         break;
2222fcf5ef2aSThomas Huth     }
2223fcf5ef2aSThomas Huth }
2224fcf5ef2aSThomas Huth 
2225fcf5ef2aSThomas Huth static void gen_fmovs(DisasContext *dc, DisasCompare *cmp, int rd, int rs)
2226fcf5ef2aSThomas Huth {
2227f7ec8155SRichard Henderson #ifdef TARGET_SPARC64
2228fcf5ef2aSThomas Huth     TCGv_i32 c32, zero, dst, s1, s2;
2229*dd7dbfccSRichard Henderson     TCGv_i64 c64 = tcg_temp_new_i64();
2230fcf5ef2aSThomas Huth 
2231fcf5ef2aSThomas Huth     /* We have two choices here: extend the 32 bit data and use movcond_i64,
2232fcf5ef2aSThomas Huth        or fold the comparison down to 32 bits and use movcond_i32.  Choose
2233fcf5ef2aSThomas Huth        the later.  */
2234fcf5ef2aSThomas Huth     c32 = tcg_temp_new_i32();
2235fcf5ef2aSThomas Huth     tcg_gen_setcond_i64(cmp->cond, c64, cmp->c1, cmp->c2);
2236fcf5ef2aSThomas Huth     tcg_gen_extrl_i64_i32(c32, c64);
2237fcf5ef2aSThomas Huth 
2238fcf5ef2aSThomas Huth     s1 = gen_load_fpr_F(dc, rs);
2239fcf5ef2aSThomas Huth     s2 = gen_load_fpr_F(dc, rd);
2240fcf5ef2aSThomas Huth     dst = gen_dest_fpr_F(dc);
224100ab7e61SRichard Henderson     zero = tcg_constant_i32(0);
2242fcf5ef2aSThomas Huth 
2243fcf5ef2aSThomas Huth     tcg_gen_movcond_i32(TCG_COND_NE, dst, c32, zero, s1, s2);
2244fcf5ef2aSThomas Huth 
2245fcf5ef2aSThomas Huth     gen_store_fpr_F(dc, rd, dst);
2246f7ec8155SRichard Henderson #else
2247f7ec8155SRichard Henderson     qemu_build_not_reached();
2248f7ec8155SRichard Henderson #endif
2249fcf5ef2aSThomas Huth }
2250fcf5ef2aSThomas Huth 
2251fcf5ef2aSThomas Huth static void gen_fmovd(DisasContext *dc, DisasCompare *cmp, int rd, int rs)
2252fcf5ef2aSThomas Huth {
2253f7ec8155SRichard Henderson #ifdef TARGET_SPARC64
2254fcf5ef2aSThomas Huth     TCGv_i64 dst = gen_dest_fpr_D(dc, rd);
2255fcf5ef2aSThomas Huth     tcg_gen_movcond_i64(cmp->cond, dst, cmp->c1, cmp->c2,
2256fcf5ef2aSThomas Huth                         gen_load_fpr_D(dc, rs),
2257fcf5ef2aSThomas Huth                         gen_load_fpr_D(dc, rd));
2258fcf5ef2aSThomas Huth     gen_store_fpr_D(dc, rd, dst);
2259f7ec8155SRichard Henderson #else
2260f7ec8155SRichard Henderson     qemu_build_not_reached();
2261f7ec8155SRichard Henderson #endif
2262fcf5ef2aSThomas Huth }
2263fcf5ef2aSThomas Huth 
2264fcf5ef2aSThomas Huth static void gen_fmovq(DisasContext *dc, DisasCompare *cmp, int rd, int rs)
2265fcf5ef2aSThomas Huth {
2266f7ec8155SRichard Henderson #ifdef TARGET_SPARC64
2267fcf5ef2aSThomas Huth     int qd = QFPREG(rd);
2268fcf5ef2aSThomas Huth     int qs = QFPREG(rs);
2269fcf5ef2aSThomas Huth 
2270fcf5ef2aSThomas Huth     tcg_gen_movcond_i64(cmp->cond, cpu_fpr[qd / 2], cmp->c1, cmp->c2,
2271fcf5ef2aSThomas Huth                         cpu_fpr[qs / 2], cpu_fpr[qd / 2]);
2272fcf5ef2aSThomas Huth     tcg_gen_movcond_i64(cmp->cond, cpu_fpr[qd / 2 + 1], cmp->c1, cmp->c2,
2273fcf5ef2aSThomas Huth                         cpu_fpr[qs / 2 + 1], cpu_fpr[qd / 2 + 1]);
2274fcf5ef2aSThomas Huth 
2275fcf5ef2aSThomas Huth     gen_update_fprs_dirty(dc, qd);
2276f7ec8155SRichard Henderson #else
2277f7ec8155SRichard Henderson     qemu_build_not_reached();
2278f7ec8155SRichard Henderson #endif
2279fcf5ef2aSThomas Huth }
2280fcf5ef2aSThomas Huth 
2281f7ec8155SRichard Henderson #ifdef TARGET_SPARC64
22825d617bfbSRichard Henderson static void gen_load_trap_state_at_tl(TCGv_ptr r_tsptr)
2283fcf5ef2aSThomas Huth {
2284fcf5ef2aSThomas Huth     TCGv_i32 r_tl = tcg_temp_new_i32();
2285fcf5ef2aSThomas Huth 
2286fcf5ef2aSThomas Huth     /* load env->tl into r_tl */
2287ad75a51eSRichard Henderson     tcg_gen_ld_i32(r_tl, tcg_env, offsetof(CPUSPARCState, tl));
2288fcf5ef2aSThomas Huth 
2289fcf5ef2aSThomas Huth     /* tl = [0 ... MAXTL_MASK] where MAXTL_MASK must be power of 2 */
2290fcf5ef2aSThomas Huth     tcg_gen_andi_i32(r_tl, r_tl, MAXTL_MASK);
2291fcf5ef2aSThomas Huth 
2292fcf5ef2aSThomas Huth     /* calculate offset to current trap state from env->ts, reuse r_tl */
2293fcf5ef2aSThomas Huth     tcg_gen_muli_i32(r_tl, r_tl, sizeof (trap_state));
2294ad75a51eSRichard Henderson     tcg_gen_addi_ptr(r_tsptr, tcg_env, offsetof(CPUSPARCState, ts));
2295fcf5ef2aSThomas Huth 
2296fcf5ef2aSThomas Huth     /* tsptr = env->ts[env->tl & MAXTL_MASK] */
2297fcf5ef2aSThomas Huth     {
2298fcf5ef2aSThomas Huth         TCGv_ptr r_tl_tmp = tcg_temp_new_ptr();
2299fcf5ef2aSThomas Huth         tcg_gen_ext_i32_ptr(r_tl_tmp, r_tl);
2300fcf5ef2aSThomas Huth         tcg_gen_add_ptr(r_tsptr, r_tsptr, r_tl_tmp);
2301fcf5ef2aSThomas Huth     }
2302fcf5ef2aSThomas Huth }
2303fcf5ef2aSThomas Huth #endif
2304fcf5ef2aSThomas Huth 
230506c060d9SRichard Henderson static int extract_dfpreg(DisasContext *dc, int x)
230606c060d9SRichard Henderson {
230706c060d9SRichard Henderson     return DFPREG(x);
230806c060d9SRichard Henderson }
230906c060d9SRichard Henderson 
231006c060d9SRichard Henderson static int extract_qfpreg(DisasContext *dc, int x)
231106c060d9SRichard Henderson {
231206c060d9SRichard Henderson     return QFPREG(x);
231306c060d9SRichard Henderson }
231406c060d9SRichard Henderson 
2315878cc677SRichard Henderson /* Include the auto-generated decoder.  */
2316878cc677SRichard Henderson #include "decode-insns.c.inc"
2317878cc677SRichard Henderson 
2318878cc677SRichard Henderson #define TRANS(NAME, AVAIL, FUNC, ...) \
2319878cc677SRichard Henderson     static bool trans_##NAME(DisasContext *dc, arg_##NAME *a) \
2320878cc677SRichard Henderson     { return avail_##AVAIL(dc) && FUNC(dc, __VA_ARGS__); }
2321878cc677SRichard Henderson 
2322878cc677SRichard Henderson #define avail_ALL(C)      true
2323878cc677SRichard Henderson #ifdef TARGET_SPARC64
2324878cc677SRichard Henderson # define avail_32(C)      false
2325af25071cSRichard Henderson # define avail_ASR17(C)   false
2326d0a11d25SRichard Henderson # define avail_CASA(C)    true
2327c2636853SRichard Henderson # define avail_DIV(C)     true
2328b5372650SRichard Henderson # define avail_MUL(C)     true
23290faef01bSRichard Henderson # define avail_POWERDOWN(C) false
2330878cc677SRichard Henderson # define avail_64(C)      true
23315d617bfbSRichard Henderson # define avail_GL(C)      ((C)->def->features & CPU_FEATURE_GL)
2332af25071cSRichard Henderson # define avail_HYPV(C)    ((C)->def->features & CPU_FEATURE_HYPV)
2333b88ce6f2SRichard Henderson # define avail_VIS1(C)    ((C)->def->features & CPU_FEATURE_VIS1)
2334b88ce6f2SRichard Henderson # define avail_VIS2(C)    ((C)->def->features & CPU_FEATURE_VIS2)
2335878cc677SRichard Henderson #else
2336878cc677SRichard Henderson # define avail_32(C)      true
2337af25071cSRichard Henderson # define avail_ASR17(C)   ((C)->def->features & CPU_FEATURE_ASR17)
2338d0a11d25SRichard Henderson # define avail_CASA(C)    ((C)->def->features & CPU_FEATURE_CASA)
2339c2636853SRichard Henderson # define avail_DIV(C)     ((C)->def->features & CPU_FEATURE_DIV)
2340b5372650SRichard Henderson # define avail_MUL(C)     ((C)->def->features & CPU_FEATURE_MUL)
23410faef01bSRichard Henderson # define avail_POWERDOWN(C) ((C)->def->features & CPU_FEATURE_POWERDOWN)
2342878cc677SRichard Henderson # define avail_64(C)      false
23435d617bfbSRichard Henderson # define avail_GL(C)      false
2344af25071cSRichard Henderson # define avail_HYPV(C)    false
2345b88ce6f2SRichard Henderson # define avail_VIS1(C)    false
2346b88ce6f2SRichard Henderson # define avail_VIS2(C)    false
2347878cc677SRichard Henderson #endif
2348878cc677SRichard Henderson 
2349878cc677SRichard Henderson /* Default case for non jump instructions. */
2350878cc677SRichard Henderson static bool advance_pc(DisasContext *dc)
2351878cc677SRichard Henderson {
2352878cc677SRichard Henderson     if (dc->npc & 3) {
2353878cc677SRichard Henderson         switch (dc->npc) {
2354878cc677SRichard Henderson         case DYNAMIC_PC:
2355878cc677SRichard Henderson         case DYNAMIC_PC_LOOKUP:
2356878cc677SRichard Henderson             dc->pc = dc->npc;
2357878cc677SRichard Henderson             gen_op_next_insn();
2358878cc677SRichard Henderson             break;
2359878cc677SRichard Henderson         case JUMP_PC:
2360878cc677SRichard Henderson             /* we can do a static jump */
2361878cc677SRichard Henderson             gen_branch2(dc, dc->jump_pc[0], dc->jump_pc[1], cpu_cond);
2362878cc677SRichard Henderson             dc->base.is_jmp = DISAS_NORETURN;
2363878cc677SRichard Henderson             break;
2364878cc677SRichard Henderson         default:
2365878cc677SRichard Henderson             g_assert_not_reached();
2366878cc677SRichard Henderson         }
2367878cc677SRichard Henderson     } else {
2368878cc677SRichard Henderson         dc->pc = dc->npc;
2369878cc677SRichard Henderson         dc->npc = dc->npc + 4;
2370878cc677SRichard Henderson     }
2371878cc677SRichard Henderson     return true;
2372878cc677SRichard Henderson }
2373878cc677SRichard Henderson 
23746d2a0768SRichard Henderson /*
23756d2a0768SRichard Henderson  * Major opcodes 00 and 01 -- branches, call, and sethi
23766d2a0768SRichard Henderson  */
23776d2a0768SRichard Henderson 
2378276567aaSRichard Henderson static bool advance_jump_uncond_never(DisasContext *dc, bool annul)
2379276567aaSRichard Henderson {
2380276567aaSRichard Henderson     if (annul) {
2381276567aaSRichard Henderson         dc->pc = dc->npc + 4;
2382276567aaSRichard Henderson         dc->npc = dc->pc + 4;
2383276567aaSRichard Henderson     } else {
2384276567aaSRichard Henderson         dc->pc = dc->npc;
2385276567aaSRichard Henderson         dc->npc = dc->pc + 4;
2386276567aaSRichard Henderson     }
2387276567aaSRichard Henderson     return true;
2388276567aaSRichard Henderson }
2389276567aaSRichard Henderson 
2390276567aaSRichard Henderson static bool advance_jump_uncond_always(DisasContext *dc, bool annul,
2391276567aaSRichard Henderson                                        target_ulong dest)
2392276567aaSRichard Henderson {
2393276567aaSRichard Henderson     if (annul) {
2394276567aaSRichard Henderson         dc->pc = dest;
2395276567aaSRichard Henderson         dc->npc = dest + 4;
2396276567aaSRichard Henderson     } else {
2397276567aaSRichard Henderson         dc->pc = dc->npc;
2398276567aaSRichard Henderson         dc->npc = dest;
2399276567aaSRichard Henderson         tcg_gen_mov_tl(cpu_pc, cpu_npc);
2400276567aaSRichard Henderson     }
2401276567aaSRichard Henderson     return true;
2402276567aaSRichard Henderson }
2403276567aaSRichard Henderson 
24049d4e2bc7SRichard Henderson static bool advance_jump_cond(DisasContext *dc, DisasCompare *cmp,
24059d4e2bc7SRichard Henderson                               bool annul, target_ulong dest)
2406276567aaSRichard Henderson {
24076b3e4cc6SRichard Henderson     target_ulong npc = dc->npc;
24086b3e4cc6SRichard Henderson 
2409276567aaSRichard Henderson     if (annul) {
24106b3e4cc6SRichard Henderson         TCGLabel *l1 = gen_new_label();
24116b3e4cc6SRichard Henderson 
24129d4e2bc7SRichard Henderson         tcg_gen_brcond_tl(tcg_invert_cond(cmp->cond), cmp->c1, cmp->c2, l1);
24136b3e4cc6SRichard Henderson         gen_goto_tb(dc, 0, npc, dest);
24146b3e4cc6SRichard Henderson         gen_set_label(l1);
24156b3e4cc6SRichard Henderson         gen_goto_tb(dc, 1, npc + 4, npc + 8);
24166b3e4cc6SRichard Henderson 
24176b3e4cc6SRichard Henderson         dc->base.is_jmp = DISAS_NORETURN;
2418276567aaSRichard Henderson     } else {
24196b3e4cc6SRichard Henderson         if (npc & 3) {
24206b3e4cc6SRichard Henderson             switch (npc) {
24216b3e4cc6SRichard Henderson             case DYNAMIC_PC:
24226b3e4cc6SRichard Henderson             case DYNAMIC_PC_LOOKUP:
24236b3e4cc6SRichard Henderson                 tcg_gen_mov_tl(cpu_pc, cpu_npc);
24246b3e4cc6SRichard Henderson                 tcg_gen_addi_tl(cpu_npc, cpu_npc, 4);
24259d4e2bc7SRichard Henderson                 tcg_gen_movcond_tl(cmp->cond, cpu_npc,
24269d4e2bc7SRichard Henderson                                    cmp->c1, cmp->c2,
24276b3e4cc6SRichard Henderson                                    tcg_constant_tl(dest), cpu_npc);
24286b3e4cc6SRichard Henderson                 dc->pc = npc;
24296b3e4cc6SRichard Henderson                 break;
24306b3e4cc6SRichard Henderson             default:
24316b3e4cc6SRichard Henderson                 g_assert_not_reached();
24326b3e4cc6SRichard Henderson             }
24336b3e4cc6SRichard Henderson         } else {
24346b3e4cc6SRichard Henderson             dc->pc = npc;
24356b3e4cc6SRichard Henderson             dc->jump_pc[0] = dest;
24366b3e4cc6SRichard Henderson             dc->jump_pc[1] = npc + 4;
24376b3e4cc6SRichard Henderson             dc->npc = JUMP_PC;
2438*dd7dbfccSRichard Henderson 
2439*dd7dbfccSRichard Henderson             /* The condition for cpu_cond is always NE -- normalize. */
2440*dd7dbfccSRichard Henderson             if (cmp->cond == TCG_COND_NE) {
2441*dd7dbfccSRichard Henderson                 tcg_gen_xor_tl(cpu_cond, cmp->c1, cmp->c2);
24429d4e2bc7SRichard Henderson             } else {
24439d4e2bc7SRichard Henderson                 tcg_gen_setcond_tl(cmp->cond, cpu_cond, cmp->c1, cmp->c2);
24449d4e2bc7SRichard Henderson             }
24456b3e4cc6SRichard Henderson         }
2446276567aaSRichard Henderson     }
2447276567aaSRichard Henderson     return true;
2448276567aaSRichard Henderson }
2449276567aaSRichard Henderson 
2450af25071cSRichard Henderson static bool raise_priv(DisasContext *dc)
2451af25071cSRichard Henderson {
2452af25071cSRichard Henderson     gen_exception(dc, TT_PRIV_INSN);
2453af25071cSRichard Henderson     return true;
2454af25071cSRichard Henderson }
2455af25071cSRichard Henderson 
245606c060d9SRichard Henderson static bool raise_unimpfpop(DisasContext *dc)
245706c060d9SRichard Henderson {
245806c060d9SRichard Henderson     gen_op_fpexception_im(dc, FSR_FTT_UNIMPFPOP);
245906c060d9SRichard Henderson     return true;
246006c060d9SRichard Henderson }
246106c060d9SRichard Henderson 
246206c060d9SRichard Henderson static bool gen_trap_float128(DisasContext *dc)
246306c060d9SRichard Henderson {
246406c060d9SRichard Henderson     if (dc->def->features & CPU_FEATURE_FLOAT128) {
246506c060d9SRichard Henderson         return false;
246606c060d9SRichard Henderson     }
246706c060d9SRichard Henderson     return raise_unimpfpop(dc);
246806c060d9SRichard Henderson }
246906c060d9SRichard Henderson 
2470276567aaSRichard Henderson static bool do_bpcc(DisasContext *dc, arg_bcc *a)
2471276567aaSRichard Henderson {
2472276567aaSRichard Henderson     target_long target = address_mask_i(dc, dc->pc + a->i * 4);
24731ea9c62aSRichard Henderson     DisasCompare cmp;
2474276567aaSRichard Henderson 
2475276567aaSRichard Henderson     switch (a->cond) {
2476276567aaSRichard Henderson     case 0x0:
2477276567aaSRichard Henderson         return advance_jump_uncond_never(dc, a->a);
2478276567aaSRichard Henderson     case 0x8:
2479276567aaSRichard Henderson         return advance_jump_uncond_always(dc, a->a, target);
2480276567aaSRichard Henderson     default:
2481276567aaSRichard Henderson         flush_cond(dc);
24821ea9c62aSRichard Henderson 
24831ea9c62aSRichard Henderson         gen_compare(&cmp, a->cc, a->cond, dc);
24849d4e2bc7SRichard Henderson         return advance_jump_cond(dc, &cmp, a->a, target);
2485276567aaSRichard Henderson     }
2486276567aaSRichard Henderson }
2487276567aaSRichard Henderson 
2488276567aaSRichard Henderson TRANS(Bicc, ALL, do_bpcc, a)
2489276567aaSRichard Henderson TRANS(BPcc,  64, do_bpcc, a)
2490276567aaSRichard Henderson 
249145196ea4SRichard Henderson static bool do_fbpfcc(DisasContext *dc, arg_bcc *a)
249245196ea4SRichard Henderson {
249345196ea4SRichard Henderson     target_long target = address_mask_i(dc, dc->pc + a->i * 4);
2494d5471936SRichard Henderson     DisasCompare cmp;
249545196ea4SRichard Henderson 
249645196ea4SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
249745196ea4SRichard Henderson         return true;
249845196ea4SRichard Henderson     }
249945196ea4SRichard Henderson     switch (a->cond) {
250045196ea4SRichard Henderson     case 0x0:
250145196ea4SRichard Henderson         return advance_jump_uncond_never(dc, a->a);
250245196ea4SRichard Henderson     case 0x8:
250345196ea4SRichard Henderson         return advance_jump_uncond_always(dc, a->a, target);
250445196ea4SRichard Henderson     default:
250545196ea4SRichard Henderson         flush_cond(dc);
2506d5471936SRichard Henderson 
2507d5471936SRichard Henderson         gen_fcompare(&cmp, a->cc, a->cond);
25089d4e2bc7SRichard Henderson         return advance_jump_cond(dc, &cmp, a->a, target);
250945196ea4SRichard Henderson     }
251045196ea4SRichard Henderson }
251145196ea4SRichard Henderson 
251245196ea4SRichard Henderson TRANS(FBPfcc,  64, do_fbpfcc, a)
251345196ea4SRichard Henderson TRANS(FBfcc,  ALL, do_fbpfcc, a)
251445196ea4SRichard Henderson 
2515ab9ffe98SRichard Henderson static bool trans_BPr(DisasContext *dc, arg_BPr *a)
2516ab9ffe98SRichard Henderson {
2517ab9ffe98SRichard Henderson     target_long target = address_mask_i(dc, dc->pc + a->i * 4);
2518ab9ffe98SRichard Henderson     DisasCompare cmp;
2519ab9ffe98SRichard Henderson 
2520ab9ffe98SRichard Henderson     if (!avail_64(dc)) {
2521ab9ffe98SRichard Henderson         return false;
2522ab9ffe98SRichard Henderson     }
2523ab9ffe98SRichard Henderson     if (gen_tcg_cond_reg[a->cond] == TCG_COND_NEVER) {
2524ab9ffe98SRichard Henderson         return false;
2525ab9ffe98SRichard Henderson     }
2526ab9ffe98SRichard Henderson 
2527ab9ffe98SRichard Henderson     flush_cond(dc);
2528ab9ffe98SRichard Henderson     gen_compare_reg(&cmp, a->cond, gen_load_gpr(dc, a->rs1));
25299d4e2bc7SRichard Henderson     return advance_jump_cond(dc, &cmp, a->a, target);
2530ab9ffe98SRichard Henderson }
2531ab9ffe98SRichard Henderson 
253223ada1b1SRichard Henderson static bool trans_CALL(DisasContext *dc, arg_CALL *a)
253323ada1b1SRichard Henderson {
253423ada1b1SRichard Henderson     target_long target = address_mask_i(dc, dc->pc + a->i * 4);
253523ada1b1SRichard Henderson 
253623ada1b1SRichard Henderson     gen_store_gpr(dc, 15, tcg_constant_tl(dc->pc));
253723ada1b1SRichard Henderson     gen_mov_pc_npc(dc);
253823ada1b1SRichard Henderson     dc->npc = target;
253923ada1b1SRichard Henderson     return true;
254023ada1b1SRichard Henderson }
254123ada1b1SRichard Henderson 
254245196ea4SRichard Henderson static bool trans_NCP(DisasContext *dc, arg_NCP *a)
254345196ea4SRichard Henderson {
254445196ea4SRichard Henderson     /*
254545196ea4SRichard Henderson      * For sparc32, always generate the no-coprocessor exception.
254645196ea4SRichard Henderson      * For sparc64, always generate illegal instruction.
254745196ea4SRichard Henderson      */
254845196ea4SRichard Henderson #ifdef TARGET_SPARC64
254945196ea4SRichard Henderson     return false;
255045196ea4SRichard Henderson #else
255145196ea4SRichard Henderson     gen_exception(dc, TT_NCP_INSN);
255245196ea4SRichard Henderson     return true;
255345196ea4SRichard Henderson #endif
255445196ea4SRichard Henderson }
255545196ea4SRichard Henderson 
25566d2a0768SRichard Henderson static bool trans_SETHI(DisasContext *dc, arg_SETHI *a)
25576d2a0768SRichard Henderson {
25586d2a0768SRichard Henderson     /* Special-case %g0 because that's the canonical nop.  */
25596d2a0768SRichard Henderson     if (a->rd) {
25606d2a0768SRichard Henderson         gen_store_gpr(dc, a->rd, tcg_constant_tl((uint32_t)a->i << 10));
25616d2a0768SRichard Henderson     }
25626d2a0768SRichard Henderson     return advance_pc(dc);
25636d2a0768SRichard Henderson }
25646d2a0768SRichard Henderson 
25650faef01bSRichard Henderson /*
25660faef01bSRichard Henderson  * Major Opcode 10 -- integer, floating-point, vis, and system insns.
25670faef01bSRichard Henderson  */
25680faef01bSRichard Henderson 
256930376636SRichard Henderson static bool do_tcc(DisasContext *dc, int cond, int cc,
257030376636SRichard Henderson                    int rs1, bool imm, int rs2_or_imm)
257130376636SRichard Henderson {
257230376636SRichard Henderson     int mask = ((dc->def->features & CPU_FEATURE_HYPV) && supervisor(dc)
257330376636SRichard Henderson                 ? UA2005_HTRAP_MASK : V8_TRAP_MASK);
257430376636SRichard Henderson     DisasCompare cmp;
257530376636SRichard Henderson     TCGLabel *lab;
257630376636SRichard Henderson     TCGv_i32 trap;
257730376636SRichard Henderson 
257830376636SRichard Henderson     /* Trap never.  */
257930376636SRichard Henderson     if (cond == 0) {
258030376636SRichard Henderson         return advance_pc(dc);
258130376636SRichard Henderson     }
258230376636SRichard Henderson 
258330376636SRichard Henderson     /*
258430376636SRichard Henderson      * Immediate traps are the most common case.  Since this value is
258530376636SRichard Henderson      * live across the branch, it really pays to evaluate the constant.
258630376636SRichard Henderson      */
258730376636SRichard Henderson     if (rs1 == 0 && (imm || rs2_or_imm == 0)) {
258830376636SRichard Henderson         trap = tcg_constant_i32((rs2_or_imm & mask) + TT_TRAP);
258930376636SRichard Henderson     } else {
259030376636SRichard Henderson         trap = tcg_temp_new_i32();
259130376636SRichard Henderson         tcg_gen_trunc_tl_i32(trap, gen_load_gpr(dc, rs1));
259230376636SRichard Henderson         if (imm) {
259330376636SRichard Henderson             tcg_gen_addi_i32(trap, trap, rs2_or_imm);
259430376636SRichard Henderson         } else {
259530376636SRichard Henderson             TCGv_i32 t2 = tcg_temp_new_i32();
259630376636SRichard Henderson             tcg_gen_trunc_tl_i32(t2, gen_load_gpr(dc, rs2_or_imm));
259730376636SRichard Henderson             tcg_gen_add_i32(trap, trap, t2);
259830376636SRichard Henderson         }
259930376636SRichard Henderson         tcg_gen_andi_i32(trap, trap, mask);
260030376636SRichard Henderson         tcg_gen_addi_i32(trap, trap, TT_TRAP);
260130376636SRichard Henderson     }
260230376636SRichard Henderson 
260330376636SRichard Henderson     /* Trap always.  */
260430376636SRichard Henderson     if (cond == 8) {
260530376636SRichard Henderson         save_state(dc);
260630376636SRichard Henderson         gen_helper_raise_exception(tcg_env, trap);
260730376636SRichard Henderson         dc->base.is_jmp = DISAS_NORETURN;
260830376636SRichard Henderson         return true;
260930376636SRichard Henderson     }
261030376636SRichard Henderson 
261130376636SRichard Henderson     /* Conditional trap.  */
261230376636SRichard Henderson     flush_cond(dc);
261330376636SRichard Henderson     lab = delay_exceptionv(dc, trap);
261430376636SRichard Henderson     gen_compare(&cmp, cc, cond, dc);
261530376636SRichard Henderson     tcg_gen_brcond_tl(cmp.cond, cmp.c1, cmp.c2, lab);
261630376636SRichard Henderson 
261730376636SRichard Henderson     return advance_pc(dc);
261830376636SRichard Henderson }
261930376636SRichard Henderson 
262030376636SRichard Henderson static bool trans_Tcc_r(DisasContext *dc, arg_Tcc_r *a)
262130376636SRichard Henderson {
262230376636SRichard Henderson     if (avail_32(dc) && a->cc) {
262330376636SRichard Henderson         return false;
262430376636SRichard Henderson     }
262530376636SRichard Henderson     return do_tcc(dc, a->cond, a->cc, a->rs1, false, a->rs2);
262630376636SRichard Henderson }
262730376636SRichard Henderson 
262830376636SRichard Henderson static bool trans_Tcc_i_v7(DisasContext *dc, arg_Tcc_i_v7 *a)
262930376636SRichard Henderson {
263030376636SRichard Henderson     if (avail_64(dc)) {
263130376636SRichard Henderson         return false;
263230376636SRichard Henderson     }
263330376636SRichard Henderson     return do_tcc(dc, a->cond, 0, a->rs1, true, a->i);
263430376636SRichard Henderson }
263530376636SRichard Henderson 
263630376636SRichard Henderson static bool trans_Tcc_i_v9(DisasContext *dc, arg_Tcc_i_v9 *a)
263730376636SRichard Henderson {
263830376636SRichard Henderson     if (avail_32(dc)) {
263930376636SRichard Henderson         return false;
264030376636SRichard Henderson     }
264130376636SRichard Henderson     return do_tcc(dc, a->cond, a->cc, a->rs1, true, a->i);
264230376636SRichard Henderson }
264330376636SRichard Henderson 
2644af25071cSRichard Henderson static bool trans_STBAR(DisasContext *dc, arg_STBAR *a)
2645af25071cSRichard Henderson {
2646af25071cSRichard Henderson     tcg_gen_mb(TCG_MO_ST_ST | TCG_BAR_SC);
2647af25071cSRichard Henderson     return advance_pc(dc);
2648af25071cSRichard Henderson }
2649af25071cSRichard Henderson 
2650af25071cSRichard Henderson static bool trans_MEMBAR(DisasContext *dc, arg_MEMBAR *a)
2651af25071cSRichard Henderson {
2652af25071cSRichard Henderson     if (avail_32(dc)) {
2653af25071cSRichard Henderson         return false;
2654af25071cSRichard Henderson     }
2655af25071cSRichard Henderson     if (a->mmask) {
2656af25071cSRichard Henderson         /* Note TCG_MO_* was modeled on sparc64, so mmask matches. */
2657af25071cSRichard Henderson         tcg_gen_mb(a->mmask | TCG_BAR_SC);
2658af25071cSRichard Henderson     }
2659af25071cSRichard Henderson     if (a->cmask) {
2660af25071cSRichard Henderson         /* For #Sync, etc, end the TB to recognize interrupts. */
2661af25071cSRichard Henderson         dc->base.is_jmp = DISAS_EXIT;
2662af25071cSRichard Henderson     }
2663af25071cSRichard Henderson     return advance_pc(dc);
2664af25071cSRichard Henderson }
2665af25071cSRichard Henderson 
2666af25071cSRichard Henderson static bool do_rd_special(DisasContext *dc, bool priv, int rd,
2667af25071cSRichard Henderson                           TCGv (*func)(DisasContext *, TCGv))
2668af25071cSRichard Henderson {
2669af25071cSRichard Henderson     if (!priv) {
2670af25071cSRichard Henderson         return raise_priv(dc);
2671af25071cSRichard Henderson     }
2672af25071cSRichard Henderson     gen_store_gpr(dc, rd, func(dc, gen_dest_gpr(dc, rd)));
2673af25071cSRichard Henderson     return advance_pc(dc);
2674af25071cSRichard Henderson }
2675af25071cSRichard Henderson 
2676af25071cSRichard Henderson static TCGv do_rdy(DisasContext *dc, TCGv dst)
2677af25071cSRichard Henderson {
2678af25071cSRichard Henderson     return cpu_y;
2679af25071cSRichard Henderson }
2680af25071cSRichard Henderson 
2681af25071cSRichard Henderson static bool trans_RDY(DisasContext *dc, arg_RDY *a)
2682af25071cSRichard Henderson {
2683af25071cSRichard Henderson     /*
2684af25071cSRichard Henderson      * TODO: Need a feature bit for sparcv8.  In the meantime, treat all
2685af25071cSRichard Henderson      * 32-bit cpus like sparcv7, which ignores the rs1 field.
2686af25071cSRichard Henderson      * This matches after all other ASR, so Leon3 Asr17 is handled first.
2687af25071cSRichard Henderson      */
2688af25071cSRichard Henderson     if (avail_64(dc) && a->rs1 != 0) {
2689af25071cSRichard Henderson         return false;
2690af25071cSRichard Henderson     }
2691af25071cSRichard Henderson     return do_rd_special(dc, true, a->rd, do_rdy);
2692af25071cSRichard Henderson }
2693af25071cSRichard Henderson 
2694af25071cSRichard Henderson static TCGv do_rd_leon3_config(DisasContext *dc, TCGv dst)
2695af25071cSRichard Henderson {
2696af25071cSRichard Henderson     uint32_t val;
2697af25071cSRichard Henderson 
2698af25071cSRichard Henderson     /*
2699af25071cSRichard Henderson      * TODO: There are many more fields to be filled,
2700af25071cSRichard Henderson      * some of which are writable.
2701af25071cSRichard Henderson      */
2702af25071cSRichard Henderson     val = dc->def->nwindows - 1;   /* [4:0] NWIN */
2703af25071cSRichard Henderson     val |= 1 << 8;                 /* [8]   V8   */
2704af25071cSRichard Henderson 
2705af25071cSRichard Henderson     return tcg_constant_tl(val);
2706af25071cSRichard Henderson }
2707af25071cSRichard Henderson 
2708af25071cSRichard Henderson TRANS(RDASR17, ASR17, do_rd_special, true, a->rd, do_rd_leon3_config)
2709af25071cSRichard Henderson 
2710af25071cSRichard Henderson static TCGv do_rdccr(DisasContext *dc, TCGv dst)
2711af25071cSRichard Henderson {
2712af25071cSRichard Henderson     gen_helper_rdccr(dst, tcg_env);
2713af25071cSRichard Henderson     return dst;
2714af25071cSRichard Henderson }
2715af25071cSRichard Henderson 
2716af25071cSRichard Henderson TRANS(RDCCR, 64, do_rd_special, true, a->rd, do_rdccr)
2717af25071cSRichard Henderson 
2718af25071cSRichard Henderson static TCGv do_rdasi(DisasContext *dc, TCGv dst)
2719af25071cSRichard Henderson {
2720af25071cSRichard Henderson #ifdef TARGET_SPARC64
2721af25071cSRichard Henderson     return tcg_constant_tl(dc->asi);
2722af25071cSRichard Henderson #else
2723af25071cSRichard Henderson     qemu_build_not_reached();
2724af25071cSRichard Henderson #endif
2725af25071cSRichard Henderson }
2726af25071cSRichard Henderson 
2727af25071cSRichard Henderson TRANS(RDASI, 64, do_rd_special, true, a->rd, do_rdasi)
2728af25071cSRichard Henderson 
2729af25071cSRichard Henderson static TCGv do_rdtick(DisasContext *dc, TCGv dst)
2730af25071cSRichard Henderson {
2731af25071cSRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
2732af25071cSRichard Henderson 
2733af25071cSRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(tick));
2734af25071cSRichard Henderson     if (translator_io_start(&dc->base)) {
2735af25071cSRichard Henderson         dc->base.is_jmp = DISAS_EXIT;
2736af25071cSRichard Henderson     }
2737af25071cSRichard Henderson     gen_helper_tick_get_count(dst, tcg_env, r_tickptr,
2738af25071cSRichard Henderson                               tcg_constant_i32(dc->mem_idx));
2739af25071cSRichard Henderson     return dst;
2740af25071cSRichard Henderson }
2741af25071cSRichard Henderson 
2742af25071cSRichard Henderson /* TODO: non-priv access only allowed when enabled. */
2743af25071cSRichard Henderson TRANS(RDTICK, 64, do_rd_special, true, a->rd, do_rdtick)
2744af25071cSRichard Henderson 
2745af25071cSRichard Henderson static TCGv do_rdpc(DisasContext *dc, TCGv dst)
2746af25071cSRichard Henderson {
2747af25071cSRichard Henderson     return tcg_constant_tl(address_mask_i(dc, dc->pc));
2748af25071cSRichard Henderson }
2749af25071cSRichard Henderson 
2750af25071cSRichard Henderson TRANS(RDPC, 64, do_rd_special, true, a->rd, do_rdpc)
2751af25071cSRichard Henderson 
2752af25071cSRichard Henderson static TCGv do_rdfprs(DisasContext *dc, TCGv dst)
2753af25071cSRichard Henderson {
2754af25071cSRichard Henderson     tcg_gen_ext_i32_tl(dst, cpu_fprs);
2755af25071cSRichard Henderson     return dst;
2756af25071cSRichard Henderson }
2757af25071cSRichard Henderson 
2758af25071cSRichard Henderson TRANS(RDFPRS, 64, do_rd_special, true, a->rd, do_rdfprs)
2759af25071cSRichard Henderson 
2760af25071cSRichard Henderson static TCGv do_rdgsr(DisasContext *dc, TCGv dst)
2761af25071cSRichard Henderson {
2762af25071cSRichard Henderson     gen_trap_ifnofpu(dc);
2763af25071cSRichard Henderson     return cpu_gsr;
2764af25071cSRichard Henderson }
2765af25071cSRichard Henderson 
2766af25071cSRichard Henderson TRANS(RDGSR, 64, do_rd_special, true, a->rd, do_rdgsr)
2767af25071cSRichard Henderson 
2768af25071cSRichard Henderson static TCGv do_rdsoftint(DisasContext *dc, TCGv dst)
2769af25071cSRichard Henderson {
2770af25071cSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(softint));
2771af25071cSRichard Henderson     return dst;
2772af25071cSRichard Henderson }
2773af25071cSRichard Henderson 
2774af25071cSRichard Henderson TRANS(RDSOFTINT, 64, do_rd_special, supervisor(dc), a->rd, do_rdsoftint)
2775af25071cSRichard Henderson 
2776af25071cSRichard Henderson static TCGv do_rdtick_cmpr(DisasContext *dc, TCGv dst)
2777af25071cSRichard Henderson {
2778577efa45SRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(tick_cmpr));
2779577efa45SRichard Henderson     return dst;
2780af25071cSRichard Henderson }
2781af25071cSRichard Henderson 
2782af25071cSRichard Henderson /* TODO: non-priv access only allowed when enabled. */
2783af25071cSRichard Henderson TRANS(RDTICK_CMPR, 64, do_rd_special, true, a->rd, do_rdtick_cmpr)
2784af25071cSRichard Henderson 
2785af25071cSRichard Henderson static TCGv do_rdstick(DisasContext *dc, TCGv dst)
2786af25071cSRichard Henderson {
2787af25071cSRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
2788af25071cSRichard Henderson 
2789af25071cSRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(stick));
2790af25071cSRichard Henderson     if (translator_io_start(&dc->base)) {
2791af25071cSRichard Henderson         dc->base.is_jmp = DISAS_EXIT;
2792af25071cSRichard Henderson     }
2793af25071cSRichard Henderson     gen_helper_tick_get_count(dst, tcg_env, r_tickptr,
2794af25071cSRichard Henderson                               tcg_constant_i32(dc->mem_idx));
2795af25071cSRichard Henderson     return dst;
2796af25071cSRichard Henderson }
2797af25071cSRichard Henderson 
2798af25071cSRichard Henderson /* TODO: non-priv access only allowed when enabled. */
2799af25071cSRichard Henderson TRANS(RDSTICK, 64, do_rd_special, true, a->rd, do_rdstick)
2800af25071cSRichard Henderson 
2801af25071cSRichard Henderson static TCGv do_rdstick_cmpr(DisasContext *dc, TCGv dst)
2802af25071cSRichard Henderson {
2803577efa45SRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(stick_cmpr));
2804577efa45SRichard Henderson     return dst;
2805af25071cSRichard Henderson }
2806af25071cSRichard Henderson 
2807af25071cSRichard Henderson /* TODO: supervisor access only allowed when enabled by hypervisor. */
2808af25071cSRichard Henderson TRANS(RDSTICK_CMPR, 64, do_rd_special, supervisor(dc), a->rd, do_rdstick_cmpr)
2809af25071cSRichard Henderson 
2810af25071cSRichard Henderson /*
2811af25071cSRichard Henderson  * UltraSPARC-T1 Strand status.
2812af25071cSRichard Henderson  * HYPV check maybe not enough, UA2005 & UA2007 describe
2813af25071cSRichard Henderson  * this ASR as impl. dep
2814af25071cSRichard Henderson  */
2815af25071cSRichard Henderson static TCGv do_rdstrand_status(DisasContext *dc, TCGv dst)
2816af25071cSRichard Henderson {
2817af25071cSRichard Henderson     return tcg_constant_tl(1);
2818af25071cSRichard Henderson }
2819af25071cSRichard Henderson 
2820af25071cSRichard Henderson TRANS(RDSTRAND_STATUS, HYPV, do_rd_special, true, a->rd, do_rdstrand_status)
2821af25071cSRichard Henderson 
2822668bb9b7SRichard Henderson static TCGv do_rdpsr(DisasContext *dc, TCGv dst)
2823668bb9b7SRichard Henderson {
2824668bb9b7SRichard Henderson     gen_helper_rdpsr(dst, tcg_env);
2825668bb9b7SRichard Henderson     return dst;
2826668bb9b7SRichard Henderson }
2827668bb9b7SRichard Henderson 
2828668bb9b7SRichard Henderson TRANS(RDPSR, 32, do_rd_special, supervisor(dc), a->rd, do_rdpsr)
2829668bb9b7SRichard Henderson 
2830668bb9b7SRichard Henderson static TCGv do_rdhpstate(DisasContext *dc, TCGv dst)
2831668bb9b7SRichard Henderson {
2832668bb9b7SRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hpstate));
2833668bb9b7SRichard Henderson     return dst;
2834668bb9b7SRichard Henderson }
2835668bb9b7SRichard Henderson 
2836668bb9b7SRichard Henderson TRANS(RDHPR_hpstate, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhpstate)
2837668bb9b7SRichard Henderson 
2838668bb9b7SRichard Henderson static TCGv do_rdhtstate(DisasContext *dc, TCGv dst)
2839668bb9b7SRichard Henderson {
2840668bb9b7SRichard Henderson     TCGv_i32 tl = tcg_temp_new_i32();
2841668bb9b7SRichard Henderson     TCGv_ptr tp = tcg_temp_new_ptr();
2842668bb9b7SRichard Henderson 
2843668bb9b7SRichard Henderson     tcg_gen_ld_i32(tl, tcg_env, env64_field_offsetof(tl));
2844668bb9b7SRichard Henderson     tcg_gen_andi_i32(tl, tl, MAXTL_MASK);
2845668bb9b7SRichard Henderson     tcg_gen_shli_i32(tl, tl, 3);
2846668bb9b7SRichard Henderson     tcg_gen_ext_i32_ptr(tp, tl);
2847668bb9b7SRichard Henderson     tcg_gen_add_ptr(tp, tp, tcg_env);
2848668bb9b7SRichard Henderson 
2849668bb9b7SRichard Henderson     tcg_gen_ld_tl(dst, tp, env64_field_offsetof(htstate));
2850668bb9b7SRichard Henderson     return dst;
2851668bb9b7SRichard Henderson }
2852668bb9b7SRichard Henderson 
2853668bb9b7SRichard Henderson TRANS(RDHPR_htstate, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhtstate)
2854668bb9b7SRichard Henderson 
2855668bb9b7SRichard Henderson static TCGv do_rdhintp(DisasContext *dc, TCGv dst)
2856668bb9b7SRichard Henderson {
28572da789deSRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hintp));
28582da789deSRichard Henderson     return dst;
2859668bb9b7SRichard Henderson }
2860668bb9b7SRichard Henderson 
2861668bb9b7SRichard Henderson TRANS(RDHPR_hintp, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhintp)
2862668bb9b7SRichard Henderson 
2863668bb9b7SRichard Henderson static TCGv do_rdhtba(DisasContext *dc, TCGv dst)
2864668bb9b7SRichard Henderson {
28652da789deSRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(htba));
28662da789deSRichard Henderson     return dst;
2867668bb9b7SRichard Henderson }
2868668bb9b7SRichard Henderson 
2869668bb9b7SRichard Henderson TRANS(RDHPR_htba, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhtba)
2870668bb9b7SRichard Henderson 
2871668bb9b7SRichard Henderson static TCGv do_rdhver(DisasContext *dc, TCGv dst)
2872668bb9b7SRichard Henderson {
28732da789deSRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hver));
28742da789deSRichard Henderson     return dst;
2875668bb9b7SRichard Henderson }
2876668bb9b7SRichard Henderson 
2877668bb9b7SRichard Henderson TRANS(RDHPR_hver, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhver)
2878668bb9b7SRichard Henderson 
2879668bb9b7SRichard Henderson static TCGv do_rdhstick_cmpr(DisasContext *dc, TCGv dst)
2880668bb9b7SRichard Henderson {
2881577efa45SRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hstick_cmpr));
2882577efa45SRichard Henderson     return dst;
2883668bb9b7SRichard Henderson }
2884668bb9b7SRichard Henderson 
2885668bb9b7SRichard Henderson TRANS(RDHPR_hstick_cmpr, HYPV, do_rd_special, hypervisor(dc), a->rd,
2886668bb9b7SRichard Henderson       do_rdhstick_cmpr)
2887668bb9b7SRichard Henderson 
28885d617bfbSRichard Henderson static TCGv do_rdwim(DisasContext *dc, TCGv dst)
28895d617bfbSRichard Henderson {
2890cd6269f7SRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env32_field_offsetof(wim));
2891cd6269f7SRichard Henderson     return dst;
28925d617bfbSRichard Henderson }
28935d617bfbSRichard Henderson 
28945d617bfbSRichard Henderson TRANS(RDWIM, 32, do_rd_special, supervisor(dc), a->rd, do_rdwim)
28955d617bfbSRichard Henderson 
28965d617bfbSRichard Henderson static TCGv do_rdtpc(DisasContext *dc, TCGv dst)
28975d617bfbSRichard Henderson {
28985d617bfbSRichard Henderson #ifdef TARGET_SPARC64
28995d617bfbSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
29005d617bfbSRichard Henderson 
29015d617bfbSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
29025d617bfbSRichard Henderson     tcg_gen_ld_tl(dst, r_tsptr, offsetof(trap_state, tpc));
29035d617bfbSRichard Henderson     return dst;
29045d617bfbSRichard Henderson #else
29055d617bfbSRichard Henderson     qemu_build_not_reached();
29065d617bfbSRichard Henderson #endif
29075d617bfbSRichard Henderson }
29085d617bfbSRichard Henderson 
29095d617bfbSRichard Henderson TRANS(RDPR_tpc, 64, do_rd_special, supervisor(dc), a->rd, do_rdtpc)
29105d617bfbSRichard Henderson 
29115d617bfbSRichard Henderson static TCGv do_rdtnpc(DisasContext *dc, TCGv dst)
29125d617bfbSRichard Henderson {
29135d617bfbSRichard Henderson #ifdef TARGET_SPARC64
29145d617bfbSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
29155d617bfbSRichard Henderson 
29165d617bfbSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
29175d617bfbSRichard Henderson     tcg_gen_ld_tl(dst, r_tsptr, offsetof(trap_state, tnpc));
29185d617bfbSRichard Henderson     return dst;
29195d617bfbSRichard Henderson #else
29205d617bfbSRichard Henderson     qemu_build_not_reached();
29215d617bfbSRichard Henderson #endif
29225d617bfbSRichard Henderson }
29235d617bfbSRichard Henderson 
29245d617bfbSRichard Henderson TRANS(RDPR_tnpc, 64, do_rd_special, supervisor(dc), a->rd, do_rdtnpc)
29255d617bfbSRichard Henderson 
29265d617bfbSRichard Henderson static TCGv do_rdtstate(DisasContext *dc, TCGv dst)
29275d617bfbSRichard Henderson {
29285d617bfbSRichard Henderson #ifdef TARGET_SPARC64
29295d617bfbSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
29305d617bfbSRichard Henderson 
29315d617bfbSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
29325d617bfbSRichard Henderson     tcg_gen_ld_tl(dst, r_tsptr, offsetof(trap_state, tstate));
29335d617bfbSRichard Henderson     return dst;
29345d617bfbSRichard Henderson #else
29355d617bfbSRichard Henderson     qemu_build_not_reached();
29365d617bfbSRichard Henderson #endif
29375d617bfbSRichard Henderson }
29385d617bfbSRichard Henderson 
29395d617bfbSRichard Henderson TRANS(RDPR_tstate, 64, do_rd_special, supervisor(dc), a->rd, do_rdtstate)
29405d617bfbSRichard Henderson 
29415d617bfbSRichard Henderson static TCGv do_rdtt(DisasContext *dc, TCGv dst)
29425d617bfbSRichard Henderson {
29435d617bfbSRichard Henderson #ifdef TARGET_SPARC64
29445d617bfbSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
29455d617bfbSRichard Henderson 
29465d617bfbSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
29475d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, r_tsptr, offsetof(trap_state, tt));
29485d617bfbSRichard Henderson     return dst;
29495d617bfbSRichard Henderson #else
29505d617bfbSRichard Henderson     qemu_build_not_reached();
29515d617bfbSRichard Henderson #endif
29525d617bfbSRichard Henderson }
29535d617bfbSRichard Henderson 
29545d617bfbSRichard Henderson TRANS(RDPR_tt, 64, do_rd_special, supervisor(dc), a->rd, do_rdtt)
29555d617bfbSRichard Henderson TRANS(RDPR_tick, 64, do_rd_special, supervisor(dc), a->rd, do_rdtick)
29565d617bfbSRichard Henderson 
29575d617bfbSRichard Henderson static TCGv do_rdtba(DisasContext *dc, TCGv dst)
29585d617bfbSRichard Henderson {
29595d617bfbSRichard Henderson     return cpu_tbr;
29605d617bfbSRichard Henderson }
29615d617bfbSRichard Henderson 
2962e8325dc0SRichard Henderson TRANS(RDTBR, 32, do_rd_special, supervisor(dc), a->rd, do_rdtba)
29635d617bfbSRichard Henderson TRANS(RDPR_tba, 64, do_rd_special, supervisor(dc), a->rd, do_rdtba)
29645d617bfbSRichard Henderson 
29655d617bfbSRichard Henderson static TCGv do_rdpstate(DisasContext *dc, TCGv dst)
29665d617bfbSRichard Henderson {
29675d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(pstate));
29685d617bfbSRichard Henderson     return dst;
29695d617bfbSRichard Henderson }
29705d617bfbSRichard Henderson 
29715d617bfbSRichard Henderson TRANS(RDPR_pstate, 64, do_rd_special, supervisor(dc), a->rd, do_rdpstate)
29725d617bfbSRichard Henderson 
29735d617bfbSRichard Henderson static TCGv do_rdtl(DisasContext *dc, TCGv dst)
29745d617bfbSRichard Henderson {
29755d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(tl));
29765d617bfbSRichard Henderson     return dst;
29775d617bfbSRichard Henderson }
29785d617bfbSRichard Henderson 
29795d617bfbSRichard Henderson TRANS(RDPR_tl, 64, do_rd_special, supervisor(dc), a->rd, do_rdtl)
29805d617bfbSRichard Henderson 
29815d617bfbSRichard Henderson static TCGv do_rdpil(DisasContext *dc, TCGv dst)
29825d617bfbSRichard Henderson {
29835d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env_field_offsetof(psrpil));
29845d617bfbSRichard Henderson     return dst;
29855d617bfbSRichard Henderson }
29865d617bfbSRichard Henderson 
29875d617bfbSRichard Henderson TRANS(RDPR_pil, 64, do_rd_special, supervisor(dc), a->rd, do_rdpil)
29885d617bfbSRichard Henderson 
29895d617bfbSRichard Henderson static TCGv do_rdcwp(DisasContext *dc, TCGv dst)
29905d617bfbSRichard Henderson {
29915d617bfbSRichard Henderson     gen_helper_rdcwp(dst, tcg_env);
29925d617bfbSRichard Henderson     return dst;
29935d617bfbSRichard Henderson }
29945d617bfbSRichard Henderson 
29955d617bfbSRichard Henderson TRANS(RDPR_cwp, 64, do_rd_special, supervisor(dc), a->rd, do_rdcwp)
29965d617bfbSRichard Henderson 
29975d617bfbSRichard Henderson static TCGv do_rdcansave(DisasContext *dc, TCGv dst)
29985d617bfbSRichard Henderson {
29995d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(cansave));
30005d617bfbSRichard Henderson     return dst;
30015d617bfbSRichard Henderson }
30025d617bfbSRichard Henderson 
30035d617bfbSRichard Henderson TRANS(RDPR_cansave, 64, do_rd_special, supervisor(dc), a->rd, do_rdcansave)
30045d617bfbSRichard Henderson 
30055d617bfbSRichard Henderson static TCGv do_rdcanrestore(DisasContext *dc, TCGv dst)
30065d617bfbSRichard Henderson {
30075d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(canrestore));
30085d617bfbSRichard Henderson     return dst;
30095d617bfbSRichard Henderson }
30105d617bfbSRichard Henderson 
30115d617bfbSRichard Henderson TRANS(RDPR_canrestore, 64, do_rd_special, supervisor(dc), a->rd,
30125d617bfbSRichard Henderson       do_rdcanrestore)
30135d617bfbSRichard Henderson 
30145d617bfbSRichard Henderson static TCGv do_rdcleanwin(DisasContext *dc, TCGv dst)
30155d617bfbSRichard Henderson {
30165d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(cleanwin));
30175d617bfbSRichard Henderson     return dst;
30185d617bfbSRichard Henderson }
30195d617bfbSRichard Henderson 
30205d617bfbSRichard Henderson TRANS(RDPR_cleanwin, 64, do_rd_special, supervisor(dc), a->rd, do_rdcleanwin)
30215d617bfbSRichard Henderson 
30225d617bfbSRichard Henderson static TCGv do_rdotherwin(DisasContext *dc, TCGv dst)
30235d617bfbSRichard Henderson {
30245d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(otherwin));
30255d617bfbSRichard Henderson     return dst;
30265d617bfbSRichard Henderson }
30275d617bfbSRichard Henderson 
30285d617bfbSRichard Henderson TRANS(RDPR_otherwin, 64, do_rd_special, supervisor(dc), a->rd, do_rdotherwin)
30295d617bfbSRichard Henderson 
30305d617bfbSRichard Henderson static TCGv do_rdwstate(DisasContext *dc, TCGv dst)
30315d617bfbSRichard Henderson {
30325d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(wstate));
30335d617bfbSRichard Henderson     return dst;
30345d617bfbSRichard Henderson }
30355d617bfbSRichard Henderson 
30365d617bfbSRichard Henderson TRANS(RDPR_wstate, 64, do_rd_special, supervisor(dc), a->rd, do_rdwstate)
30375d617bfbSRichard Henderson 
30385d617bfbSRichard Henderson static TCGv do_rdgl(DisasContext *dc, TCGv dst)
30395d617bfbSRichard Henderson {
30405d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(gl));
30415d617bfbSRichard Henderson     return dst;
30425d617bfbSRichard Henderson }
30435d617bfbSRichard Henderson 
30445d617bfbSRichard Henderson TRANS(RDPR_gl, GL, do_rd_special, supervisor(dc), a->rd, do_rdgl)
30455d617bfbSRichard Henderson 
30465d617bfbSRichard Henderson /* UA2005 strand status */
30475d617bfbSRichard Henderson static TCGv do_rdssr(DisasContext *dc, TCGv dst)
30485d617bfbSRichard Henderson {
30492da789deSRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(ssr));
30502da789deSRichard Henderson     return dst;
30515d617bfbSRichard Henderson }
30525d617bfbSRichard Henderson 
30535d617bfbSRichard Henderson TRANS(RDPR_strand_status, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdssr)
30545d617bfbSRichard Henderson 
30555d617bfbSRichard Henderson static TCGv do_rdver(DisasContext *dc, TCGv dst)
30565d617bfbSRichard Henderson {
30572da789deSRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(version));
30582da789deSRichard Henderson     return dst;
30595d617bfbSRichard Henderson }
30605d617bfbSRichard Henderson 
30615d617bfbSRichard Henderson TRANS(RDPR_ver, 64, do_rd_special, supervisor(dc), a->rd, do_rdver)
30625d617bfbSRichard Henderson 
3063e8325dc0SRichard Henderson static bool trans_FLUSHW(DisasContext *dc, arg_FLUSHW *a)
3064e8325dc0SRichard Henderson {
3065e8325dc0SRichard Henderson     if (avail_64(dc)) {
3066e8325dc0SRichard Henderson         gen_helper_flushw(tcg_env);
3067e8325dc0SRichard Henderson         return advance_pc(dc);
3068e8325dc0SRichard Henderson     }
3069e8325dc0SRichard Henderson     return false;
3070e8325dc0SRichard Henderson }
3071e8325dc0SRichard Henderson 
30720faef01bSRichard Henderson static bool do_wr_special(DisasContext *dc, arg_r_r_ri *a, bool priv,
30730faef01bSRichard Henderson                           void (*func)(DisasContext *, TCGv))
30740faef01bSRichard Henderson {
30750faef01bSRichard Henderson     TCGv src;
30760faef01bSRichard Henderson 
30770faef01bSRichard Henderson     /* For simplicity, we under-decoded the rs2 form. */
30780faef01bSRichard Henderson     if (!a->imm && (a->rs2_or_imm & ~0x1f)) {
30790faef01bSRichard Henderson         return false;
30800faef01bSRichard Henderson     }
30810faef01bSRichard Henderson     if (!priv) {
30820faef01bSRichard Henderson         return raise_priv(dc);
30830faef01bSRichard Henderson     }
30840faef01bSRichard Henderson 
30850faef01bSRichard Henderson     if (a->rs1 == 0 && (a->imm || a->rs2_or_imm == 0)) {
30860faef01bSRichard Henderson         src = tcg_constant_tl(a->rs2_or_imm);
30870faef01bSRichard Henderson     } else {
30880faef01bSRichard Henderson         TCGv src1 = gen_load_gpr(dc, a->rs1);
30890faef01bSRichard Henderson         if (a->rs2_or_imm == 0) {
30900faef01bSRichard Henderson             src = src1;
30910faef01bSRichard Henderson         } else {
30920faef01bSRichard Henderson             src = tcg_temp_new();
30930faef01bSRichard Henderson             if (a->imm) {
30940faef01bSRichard Henderson                 tcg_gen_xori_tl(src, src1, a->rs2_or_imm);
30950faef01bSRichard Henderson             } else {
30960faef01bSRichard Henderson                 tcg_gen_xor_tl(src, src1, gen_load_gpr(dc, a->rs2_or_imm));
30970faef01bSRichard Henderson             }
30980faef01bSRichard Henderson         }
30990faef01bSRichard Henderson     }
31000faef01bSRichard Henderson     func(dc, src);
31010faef01bSRichard Henderson     return advance_pc(dc);
31020faef01bSRichard Henderson }
31030faef01bSRichard Henderson 
31040faef01bSRichard Henderson static void do_wry(DisasContext *dc, TCGv src)
31050faef01bSRichard Henderson {
31060faef01bSRichard Henderson     tcg_gen_ext32u_tl(cpu_y, src);
31070faef01bSRichard Henderson }
31080faef01bSRichard Henderson 
31090faef01bSRichard Henderson TRANS(WRY, ALL, do_wr_special, a, true, do_wry)
31100faef01bSRichard Henderson 
31110faef01bSRichard Henderson static void do_wrccr(DisasContext *dc, TCGv src)
31120faef01bSRichard Henderson {
31130faef01bSRichard Henderson     gen_helper_wrccr(tcg_env, src);
31140faef01bSRichard Henderson }
31150faef01bSRichard Henderson 
31160faef01bSRichard Henderson TRANS(WRCCR, 64, do_wr_special, a, true, do_wrccr)
31170faef01bSRichard Henderson 
31180faef01bSRichard Henderson static void do_wrasi(DisasContext *dc, TCGv src)
31190faef01bSRichard Henderson {
31200faef01bSRichard Henderson     TCGv tmp = tcg_temp_new();
31210faef01bSRichard Henderson 
31220faef01bSRichard Henderson     tcg_gen_ext8u_tl(tmp, src);
31230faef01bSRichard Henderson     tcg_gen_st32_tl(tmp, tcg_env, env64_field_offsetof(asi));
31240faef01bSRichard Henderson     /* End TB to notice changed ASI. */
31250faef01bSRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
31260faef01bSRichard Henderson }
31270faef01bSRichard Henderson 
31280faef01bSRichard Henderson TRANS(WRASI, 64, do_wr_special, a, true, do_wrasi)
31290faef01bSRichard Henderson 
31300faef01bSRichard Henderson static void do_wrfprs(DisasContext *dc, TCGv src)
31310faef01bSRichard Henderson {
31320faef01bSRichard Henderson #ifdef TARGET_SPARC64
31330faef01bSRichard Henderson     tcg_gen_trunc_tl_i32(cpu_fprs, src);
31340faef01bSRichard Henderson     dc->fprs_dirty = 0;
31350faef01bSRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
31360faef01bSRichard Henderson #else
31370faef01bSRichard Henderson     qemu_build_not_reached();
31380faef01bSRichard Henderson #endif
31390faef01bSRichard Henderson }
31400faef01bSRichard Henderson 
31410faef01bSRichard Henderson TRANS(WRFPRS, 64, do_wr_special, a, true, do_wrfprs)
31420faef01bSRichard Henderson 
31430faef01bSRichard Henderson static void do_wrgsr(DisasContext *dc, TCGv src)
31440faef01bSRichard Henderson {
31450faef01bSRichard Henderson     gen_trap_ifnofpu(dc);
31460faef01bSRichard Henderson     tcg_gen_mov_tl(cpu_gsr, src);
31470faef01bSRichard Henderson }
31480faef01bSRichard Henderson 
31490faef01bSRichard Henderson TRANS(WRGSR, 64, do_wr_special, a, true, do_wrgsr)
31500faef01bSRichard Henderson 
31510faef01bSRichard Henderson static void do_wrsoftint_set(DisasContext *dc, TCGv src)
31520faef01bSRichard Henderson {
31530faef01bSRichard Henderson     gen_helper_set_softint(tcg_env, src);
31540faef01bSRichard Henderson }
31550faef01bSRichard Henderson 
31560faef01bSRichard Henderson TRANS(WRSOFTINT_SET, 64, do_wr_special, a, supervisor(dc), do_wrsoftint_set)
31570faef01bSRichard Henderson 
31580faef01bSRichard Henderson static void do_wrsoftint_clr(DisasContext *dc, TCGv src)
31590faef01bSRichard Henderson {
31600faef01bSRichard Henderson     gen_helper_clear_softint(tcg_env, src);
31610faef01bSRichard Henderson }
31620faef01bSRichard Henderson 
31630faef01bSRichard Henderson TRANS(WRSOFTINT_CLR, 64, do_wr_special, a, supervisor(dc), do_wrsoftint_clr)
31640faef01bSRichard Henderson 
31650faef01bSRichard Henderson static void do_wrsoftint(DisasContext *dc, TCGv src)
31660faef01bSRichard Henderson {
31670faef01bSRichard Henderson     gen_helper_write_softint(tcg_env, src);
31680faef01bSRichard Henderson }
31690faef01bSRichard Henderson 
31700faef01bSRichard Henderson TRANS(WRSOFTINT, 64, do_wr_special, a, supervisor(dc), do_wrsoftint)
31710faef01bSRichard Henderson 
31720faef01bSRichard Henderson static void do_wrtick_cmpr(DisasContext *dc, TCGv src)
31730faef01bSRichard Henderson {
31740faef01bSRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
31750faef01bSRichard Henderson 
3176577efa45SRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(tick_cmpr));
3177577efa45SRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(tick));
31780faef01bSRichard Henderson     translator_io_start(&dc->base);
3179577efa45SRichard Henderson     gen_helper_tick_set_limit(r_tickptr, src);
31800faef01bSRichard Henderson     /* End TB to handle timer interrupt */
31810faef01bSRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
31820faef01bSRichard Henderson }
31830faef01bSRichard Henderson 
31840faef01bSRichard Henderson TRANS(WRTICK_CMPR, 64, do_wr_special, a, supervisor(dc), do_wrtick_cmpr)
31850faef01bSRichard Henderson 
31860faef01bSRichard Henderson static void do_wrstick(DisasContext *dc, TCGv src)
31870faef01bSRichard Henderson {
31880faef01bSRichard Henderson #ifdef TARGET_SPARC64
31890faef01bSRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
31900faef01bSRichard Henderson 
31910faef01bSRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, offsetof(CPUSPARCState, stick));
31920faef01bSRichard Henderson     translator_io_start(&dc->base);
31930faef01bSRichard Henderson     gen_helper_tick_set_count(r_tickptr, src);
31940faef01bSRichard Henderson     /* End TB to handle timer interrupt */
31950faef01bSRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
31960faef01bSRichard Henderson #else
31970faef01bSRichard Henderson     qemu_build_not_reached();
31980faef01bSRichard Henderson #endif
31990faef01bSRichard Henderson }
32000faef01bSRichard Henderson 
32010faef01bSRichard Henderson TRANS(WRSTICK, 64, do_wr_special, a, supervisor(dc), do_wrstick)
32020faef01bSRichard Henderson 
32030faef01bSRichard Henderson static void do_wrstick_cmpr(DisasContext *dc, TCGv src)
32040faef01bSRichard Henderson {
32050faef01bSRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
32060faef01bSRichard Henderson 
3207577efa45SRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(stick_cmpr));
3208577efa45SRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(stick));
32090faef01bSRichard Henderson     translator_io_start(&dc->base);
3210577efa45SRichard Henderson     gen_helper_tick_set_limit(r_tickptr, src);
32110faef01bSRichard Henderson     /* End TB to handle timer interrupt */
32120faef01bSRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
32130faef01bSRichard Henderson }
32140faef01bSRichard Henderson 
32150faef01bSRichard Henderson TRANS(WRSTICK_CMPR, 64, do_wr_special, a, supervisor(dc), do_wrstick_cmpr)
32160faef01bSRichard Henderson 
32170faef01bSRichard Henderson static void do_wrpowerdown(DisasContext *dc, TCGv src)
32180faef01bSRichard Henderson {
32190faef01bSRichard Henderson     save_state(dc);
32200faef01bSRichard Henderson     gen_helper_power_down(tcg_env);
32210faef01bSRichard Henderson }
32220faef01bSRichard Henderson 
32230faef01bSRichard Henderson TRANS(WRPOWERDOWN, POWERDOWN, do_wr_special, a, supervisor(dc), do_wrpowerdown)
32240faef01bSRichard Henderson 
322525524734SRichard Henderson static void do_wrpsr(DisasContext *dc, TCGv src)
322625524734SRichard Henderson {
322725524734SRichard Henderson     gen_helper_wrpsr(tcg_env, src);
322825524734SRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
322925524734SRichard Henderson }
323025524734SRichard Henderson 
323125524734SRichard Henderson TRANS(WRPSR, 32, do_wr_special, a, supervisor(dc), do_wrpsr)
323225524734SRichard Henderson 
32339422278eSRichard Henderson static void do_wrwim(DisasContext *dc, TCGv src)
32349422278eSRichard Henderson {
32359422278eSRichard Henderson     target_ulong mask = MAKE_64BIT_MASK(0, dc->def->nwindows);
3236cd6269f7SRichard Henderson     TCGv tmp = tcg_temp_new();
3237cd6269f7SRichard Henderson 
3238cd6269f7SRichard Henderson     tcg_gen_andi_tl(tmp, src, mask);
3239cd6269f7SRichard Henderson     tcg_gen_st_tl(tmp, tcg_env, env32_field_offsetof(wim));
32409422278eSRichard Henderson }
32419422278eSRichard Henderson 
32429422278eSRichard Henderson TRANS(WRWIM, 32, do_wr_special, a, supervisor(dc), do_wrwim)
32439422278eSRichard Henderson 
32449422278eSRichard Henderson static void do_wrtpc(DisasContext *dc, TCGv src)
32459422278eSRichard Henderson {
32469422278eSRichard Henderson #ifdef TARGET_SPARC64
32479422278eSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
32489422278eSRichard Henderson 
32499422278eSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
32509422278eSRichard Henderson     tcg_gen_st_tl(src, r_tsptr, offsetof(trap_state, tpc));
32519422278eSRichard Henderson #else
32529422278eSRichard Henderson     qemu_build_not_reached();
32539422278eSRichard Henderson #endif
32549422278eSRichard Henderson }
32559422278eSRichard Henderson 
32569422278eSRichard Henderson TRANS(WRPR_tpc, 64, do_wr_special, a, supervisor(dc), do_wrtpc)
32579422278eSRichard Henderson 
32589422278eSRichard Henderson static void do_wrtnpc(DisasContext *dc, TCGv src)
32599422278eSRichard Henderson {
32609422278eSRichard Henderson #ifdef TARGET_SPARC64
32619422278eSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
32629422278eSRichard Henderson 
32639422278eSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
32649422278eSRichard Henderson     tcg_gen_st_tl(src, r_tsptr, offsetof(trap_state, tnpc));
32659422278eSRichard Henderson #else
32669422278eSRichard Henderson     qemu_build_not_reached();
32679422278eSRichard Henderson #endif
32689422278eSRichard Henderson }
32699422278eSRichard Henderson 
32709422278eSRichard Henderson TRANS(WRPR_tnpc, 64, do_wr_special, a, supervisor(dc), do_wrtnpc)
32719422278eSRichard Henderson 
32729422278eSRichard Henderson static void do_wrtstate(DisasContext *dc, TCGv src)
32739422278eSRichard Henderson {
32749422278eSRichard Henderson #ifdef TARGET_SPARC64
32759422278eSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
32769422278eSRichard Henderson 
32779422278eSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
32789422278eSRichard Henderson     tcg_gen_st_tl(src, r_tsptr, offsetof(trap_state, tstate));
32799422278eSRichard Henderson #else
32809422278eSRichard Henderson     qemu_build_not_reached();
32819422278eSRichard Henderson #endif
32829422278eSRichard Henderson }
32839422278eSRichard Henderson 
32849422278eSRichard Henderson TRANS(WRPR_tstate, 64, do_wr_special, a, supervisor(dc), do_wrtstate)
32859422278eSRichard Henderson 
32869422278eSRichard Henderson static void do_wrtt(DisasContext *dc, TCGv src)
32879422278eSRichard Henderson {
32889422278eSRichard Henderson #ifdef TARGET_SPARC64
32899422278eSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
32909422278eSRichard Henderson 
32919422278eSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
32929422278eSRichard Henderson     tcg_gen_st32_tl(src, r_tsptr, offsetof(trap_state, tt));
32939422278eSRichard Henderson #else
32949422278eSRichard Henderson     qemu_build_not_reached();
32959422278eSRichard Henderson #endif
32969422278eSRichard Henderson }
32979422278eSRichard Henderson 
32989422278eSRichard Henderson TRANS(WRPR_tt, 64, do_wr_special, a, supervisor(dc), do_wrtt)
32999422278eSRichard Henderson 
33009422278eSRichard Henderson static void do_wrtick(DisasContext *dc, TCGv src)
33019422278eSRichard Henderson {
33029422278eSRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
33039422278eSRichard Henderson 
33049422278eSRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(tick));
33059422278eSRichard Henderson     translator_io_start(&dc->base);
33069422278eSRichard Henderson     gen_helper_tick_set_count(r_tickptr, src);
33079422278eSRichard Henderson     /* End TB to handle timer interrupt */
33089422278eSRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
33099422278eSRichard Henderson }
33109422278eSRichard Henderson 
33119422278eSRichard Henderson TRANS(WRPR_tick, 64, do_wr_special, a, supervisor(dc), do_wrtick)
33129422278eSRichard Henderson 
33139422278eSRichard Henderson static void do_wrtba(DisasContext *dc, TCGv src)
33149422278eSRichard Henderson {
33159422278eSRichard Henderson     tcg_gen_mov_tl(cpu_tbr, src);
33169422278eSRichard Henderson }
33179422278eSRichard Henderson 
33189422278eSRichard Henderson TRANS(WRPR_tba, 64, do_wr_special, a, supervisor(dc), do_wrtba)
33199422278eSRichard Henderson 
33209422278eSRichard Henderson static void do_wrpstate(DisasContext *dc, TCGv src)
33219422278eSRichard Henderson {
33229422278eSRichard Henderson     save_state(dc);
33239422278eSRichard Henderson     if (translator_io_start(&dc->base)) {
33249422278eSRichard Henderson         dc->base.is_jmp = DISAS_EXIT;
33259422278eSRichard Henderson     }
33269422278eSRichard Henderson     gen_helper_wrpstate(tcg_env, src);
33279422278eSRichard Henderson     dc->npc = DYNAMIC_PC;
33289422278eSRichard Henderson }
33299422278eSRichard Henderson 
33309422278eSRichard Henderson TRANS(WRPR_pstate, 64, do_wr_special, a, supervisor(dc), do_wrpstate)
33319422278eSRichard Henderson 
33329422278eSRichard Henderson static void do_wrtl(DisasContext *dc, TCGv src)
33339422278eSRichard Henderson {
33349422278eSRichard Henderson     save_state(dc);
33359422278eSRichard Henderson     tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(tl));
33369422278eSRichard Henderson     dc->npc = DYNAMIC_PC;
33379422278eSRichard Henderson }
33389422278eSRichard Henderson 
33399422278eSRichard Henderson TRANS(WRPR_tl, 64, do_wr_special, a, supervisor(dc), do_wrtl)
33409422278eSRichard Henderson 
33419422278eSRichard Henderson static void do_wrpil(DisasContext *dc, TCGv src)
33429422278eSRichard Henderson {
33439422278eSRichard Henderson     if (translator_io_start(&dc->base)) {
33449422278eSRichard Henderson         dc->base.is_jmp = DISAS_EXIT;
33459422278eSRichard Henderson     }
33469422278eSRichard Henderson     gen_helper_wrpil(tcg_env, src);
33479422278eSRichard Henderson }
33489422278eSRichard Henderson 
33499422278eSRichard Henderson TRANS(WRPR_pil, 64, do_wr_special, a, supervisor(dc), do_wrpil)
33509422278eSRichard Henderson 
33519422278eSRichard Henderson static void do_wrcwp(DisasContext *dc, TCGv src)
33529422278eSRichard Henderson {
33539422278eSRichard Henderson     gen_helper_wrcwp(tcg_env, src);
33549422278eSRichard Henderson }
33559422278eSRichard Henderson 
33569422278eSRichard Henderson TRANS(WRPR_cwp, 64, do_wr_special, a, supervisor(dc), do_wrcwp)
33579422278eSRichard Henderson 
33589422278eSRichard Henderson static void do_wrcansave(DisasContext *dc, TCGv src)
33599422278eSRichard Henderson {
33609422278eSRichard Henderson     tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(cansave));
33619422278eSRichard Henderson }
33629422278eSRichard Henderson 
33639422278eSRichard Henderson TRANS(WRPR_cansave, 64, do_wr_special, a, supervisor(dc), do_wrcansave)
33649422278eSRichard Henderson 
33659422278eSRichard Henderson static void do_wrcanrestore(DisasContext *dc, TCGv src)
33669422278eSRichard Henderson {
33679422278eSRichard Henderson     tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(canrestore));
33689422278eSRichard Henderson }
33699422278eSRichard Henderson 
33709422278eSRichard Henderson TRANS(WRPR_canrestore, 64, do_wr_special, a, supervisor(dc), do_wrcanrestore)
33719422278eSRichard Henderson 
33729422278eSRichard Henderson static void do_wrcleanwin(DisasContext *dc, TCGv src)
33739422278eSRichard Henderson {
33749422278eSRichard Henderson     tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(cleanwin));
33759422278eSRichard Henderson }
33769422278eSRichard Henderson 
33779422278eSRichard Henderson TRANS(WRPR_cleanwin, 64, do_wr_special, a, supervisor(dc), do_wrcleanwin)
33789422278eSRichard Henderson 
33799422278eSRichard Henderson static void do_wrotherwin(DisasContext *dc, TCGv src)
33809422278eSRichard Henderson {
33819422278eSRichard Henderson     tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(otherwin));
33829422278eSRichard Henderson }
33839422278eSRichard Henderson 
33849422278eSRichard Henderson TRANS(WRPR_otherwin, 64, do_wr_special, a, supervisor(dc), do_wrotherwin)
33859422278eSRichard Henderson 
33869422278eSRichard Henderson static void do_wrwstate(DisasContext *dc, TCGv src)
33879422278eSRichard Henderson {
33889422278eSRichard Henderson     tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(wstate));
33899422278eSRichard Henderson }
33909422278eSRichard Henderson 
33919422278eSRichard Henderson TRANS(WRPR_wstate, 64, do_wr_special, a, supervisor(dc), do_wrwstate)
33929422278eSRichard Henderson 
33939422278eSRichard Henderson static void do_wrgl(DisasContext *dc, TCGv src)
33949422278eSRichard Henderson {
33959422278eSRichard Henderson     gen_helper_wrgl(tcg_env, src);
33969422278eSRichard Henderson }
33979422278eSRichard Henderson 
33989422278eSRichard Henderson TRANS(WRPR_gl, GL, do_wr_special, a, supervisor(dc), do_wrgl)
33999422278eSRichard Henderson 
34009422278eSRichard Henderson /* UA2005 strand status */
34019422278eSRichard Henderson static void do_wrssr(DisasContext *dc, TCGv src)
34029422278eSRichard Henderson {
34032da789deSRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(ssr));
34049422278eSRichard Henderson }
34059422278eSRichard Henderson 
34069422278eSRichard Henderson TRANS(WRPR_strand_status, HYPV, do_wr_special, a, hypervisor(dc), do_wrssr)
34079422278eSRichard Henderson 
3408bb97f2f5SRichard Henderson TRANS(WRTBR, 32, do_wr_special, a, supervisor(dc), do_wrtba)
3409bb97f2f5SRichard Henderson 
3410bb97f2f5SRichard Henderson static void do_wrhpstate(DisasContext *dc, TCGv src)
3411bb97f2f5SRichard Henderson {
3412bb97f2f5SRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(hpstate));
3413bb97f2f5SRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
3414bb97f2f5SRichard Henderson }
3415bb97f2f5SRichard Henderson 
3416bb97f2f5SRichard Henderson TRANS(WRHPR_hpstate, HYPV, do_wr_special, a, hypervisor(dc), do_wrhpstate)
3417bb97f2f5SRichard Henderson 
3418bb97f2f5SRichard Henderson static void do_wrhtstate(DisasContext *dc, TCGv src)
3419bb97f2f5SRichard Henderson {
3420bb97f2f5SRichard Henderson     TCGv_i32 tl = tcg_temp_new_i32();
3421bb97f2f5SRichard Henderson     TCGv_ptr tp = tcg_temp_new_ptr();
3422bb97f2f5SRichard Henderson 
3423bb97f2f5SRichard Henderson     tcg_gen_ld_i32(tl, tcg_env, env64_field_offsetof(tl));
3424bb97f2f5SRichard Henderson     tcg_gen_andi_i32(tl, tl, MAXTL_MASK);
3425bb97f2f5SRichard Henderson     tcg_gen_shli_i32(tl, tl, 3);
3426bb97f2f5SRichard Henderson     tcg_gen_ext_i32_ptr(tp, tl);
3427bb97f2f5SRichard Henderson     tcg_gen_add_ptr(tp, tp, tcg_env);
3428bb97f2f5SRichard Henderson 
3429bb97f2f5SRichard Henderson     tcg_gen_st_tl(src, tp, env64_field_offsetof(htstate));
3430bb97f2f5SRichard Henderson }
3431bb97f2f5SRichard Henderson 
3432bb97f2f5SRichard Henderson TRANS(WRHPR_htstate, HYPV, do_wr_special, a, hypervisor(dc), do_wrhtstate)
3433bb97f2f5SRichard Henderson 
3434bb97f2f5SRichard Henderson static void do_wrhintp(DisasContext *dc, TCGv src)
3435bb97f2f5SRichard Henderson {
34362da789deSRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(hintp));
3437bb97f2f5SRichard Henderson }
3438bb97f2f5SRichard Henderson 
3439bb97f2f5SRichard Henderson TRANS(WRHPR_hintp, HYPV, do_wr_special, a, hypervisor(dc), do_wrhintp)
3440bb97f2f5SRichard Henderson 
3441bb97f2f5SRichard Henderson static void do_wrhtba(DisasContext *dc, TCGv src)
3442bb97f2f5SRichard Henderson {
34432da789deSRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(htba));
3444bb97f2f5SRichard Henderson }
3445bb97f2f5SRichard Henderson 
3446bb97f2f5SRichard Henderson TRANS(WRHPR_htba, HYPV, do_wr_special, a, hypervisor(dc), do_wrhtba)
3447bb97f2f5SRichard Henderson 
3448bb97f2f5SRichard Henderson static void do_wrhstick_cmpr(DisasContext *dc, TCGv src)
3449bb97f2f5SRichard Henderson {
3450bb97f2f5SRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
3451bb97f2f5SRichard Henderson 
3452577efa45SRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(hstick_cmpr));
3453bb97f2f5SRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(hstick));
3454bb97f2f5SRichard Henderson     translator_io_start(&dc->base);
3455577efa45SRichard Henderson     gen_helper_tick_set_limit(r_tickptr, src);
3456bb97f2f5SRichard Henderson     /* End TB to handle timer interrupt */
3457bb97f2f5SRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
3458bb97f2f5SRichard Henderson }
3459bb97f2f5SRichard Henderson 
3460bb97f2f5SRichard Henderson TRANS(WRHPR_hstick_cmpr, HYPV, do_wr_special, a, hypervisor(dc),
3461bb97f2f5SRichard Henderson       do_wrhstick_cmpr)
3462bb97f2f5SRichard Henderson 
346325524734SRichard Henderson static bool do_saved_restored(DisasContext *dc, bool saved)
346425524734SRichard Henderson {
346525524734SRichard Henderson     if (!supervisor(dc)) {
346625524734SRichard Henderson         return raise_priv(dc);
346725524734SRichard Henderson     }
346825524734SRichard Henderson     if (saved) {
346925524734SRichard Henderson         gen_helper_saved(tcg_env);
347025524734SRichard Henderson     } else {
347125524734SRichard Henderson         gen_helper_restored(tcg_env);
347225524734SRichard Henderson     }
347325524734SRichard Henderson     return advance_pc(dc);
347425524734SRichard Henderson }
347525524734SRichard Henderson 
347625524734SRichard Henderson TRANS(SAVED, 64, do_saved_restored, true)
347725524734SRichard Henderson TRANS(RESTORED, 64, do_saved_restored, false)
347825524734SRichard Henderson 
3479d3825800SRichard Henderson static bool trans_NOP(DisasContext *dc, arg_NOP *a)
3480d3825800SRichard Henderson {
3481d3825800SRichard Henderson     return advance_pc(dc);
3482d3825800SRichard Henderson }
3483d3825800SRichard Henderson 
34840faef01bSRichard Henderson /*
34850faef01bSRichard Henderson  * TODO: Need a feature bit for sparcv8.
34860faef01bSRichard Henderson  * In the meantime, treat all 32-bit cpus like sparcv7.
34870faef01bSRichard Henderson  */
34885458fd31SRichard Henderson TRANS(NOP_v7, 32, trans_NOP, a)
34895458fd31SRichard Henderson TRANS(NOP_v9, 64, trans_NOP, a)
34900faef01bSRichard Henderson 
3491b597eedcSRichard Henderson static bool do_arith_int(DisasContext *dc, arg_r_r_ri_cc *a,
3492428881deSRichard Henderson                          void (*func)(TCGv, TCGv, TCGv),
34932a45b736SRichard Henderson                          void (*funci)(TCGv, TCGv, target_long),
34942a45b736SRichard Henderson                          bool logic_cc)
3495428881deSRichard Henderson {
3496428881deSRichard Henderson     TCGv dst, src1;
3497428881deSRichard Henderson 
3498428881deSRichard Henderson     /* For simplicity, we under-decoded the rs2 form. */
3499428881deSRichard Henderson     if (!a->imm && a->rs2_or_imm & ~0x1f) {
3500428881deSRichard Henderson         return false;
3501428881deSRichard Henderson     }
3502428881deSRichard Henderson 
35032a45b736SRichard Henderson     if (logic_cc) {
35042a45b736SRichard Henderson         dst = cpu_cc_N;
3505428881deSRichard Henderson     } else {
3506428881deSRichard Henderson         dst = gen_dest_gpr(dc, a->rd);
3507428881deSRichard Henderson     }
3508428881deSRichard Henderson     src1 = gen_load_gpr(dc, a->rs1);
3509428881deSRichard Henderson 
3510428881deSRichard Henderson     if (a->imm || a->rs2_or_imm == 0) {
3511428881deSRichard Henderson         if (funci) {
3512428881deSRichard Henderson             funci(dst, src1, a->rs2_or_imm);
3513428881deSRichard Henderson         } else {
3514428881deSRichard Henderson             func(dst, src1, tcg_constant_tl(a->rs2_or_imm));
3515428881deSRichard Henderson         }
3516428881deSRichard Henderson     } else {
3517428881deSRichard Henderson         func(dst, src1, cpu_regs[a->rs2_or_imm]);
3518428881deSRichard Henderson     }
35192a45b736SRichard Henderson 
35202a45b736SRichard Henderson     if (logic_cc) {
35212a45b736SRichard Henderson         if (TARGET_LONG_BITS == 64) {
35222a45b736SRichard Henderson             tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N);
35232a45b736SRichard Henderson             tcg_gen_movi_tl(cpu_icc_C, 0);
35242a45b736SRichard Henderson         }
35252a45b736SRichard Henderson         tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N);
35262a45b736SRichard Henderson         tcg_gen_movi_tl(cpu_cc_C, 0);
35272a45b736SRichard Henderson         tcg_gen_movi_tl(cpu_cc_V, 0);
35282a45b736SRichard Henderson     }
35292a45b736SRichard Henderson 
3530428881deSRichard Henderson     gen_store_gpr(dc, a->rd, dst);
3531428881deSRichard Henderson     return advance_pc(dc);
3532428881deSRichard Henderson }
3533428881deSRichard Henderson 
3534b597eedcSRichard Henderson static bool do_arith(DisasContext *dc, arg_r_r_ri_cc *a,
3535428881deSRichard Henderson                      void (*func)(TCGv, TCGv, TCGv),
3536428881deSRichard Henderson                      void (*funci)(TCGv, TCGv, target_long),
3537428881deSRichard Henderson                      void (*func_cc)(TCGv, TCGv, TCGv))
3538428881deSRichard Henderson {
3539428881deSRichard Henderson     if (a->cc) {
3540b597eedcSRichard Henderson         return do_arith_int(dc, a, func_cc, NULL, false);
3541428881deSRichard Henderson     }
3542b597eedcSRichard Henderson     return do_arith_int(dc, a, func, funci, false);
3543428881deSRichard Henderson }
3544428881deSRichard Henderson 
3545428881deSRichard Henderson static bool do_logic(DisasContext *dc, arg_r_r_ri_cc *a,
3546428881deSRichard Henderson                      void (*func)(TCGv, TCGv, TCGv),
3547428881deSRichard Henderson                      void (*funci)(TCGv, TCGv, target_long))
3548428881deSRichard Henderson {
3549b597eedcSRichard Henderson     return do_arith_int(dc, a, func, funci, a->cc);
3550428881deSRichard Henderson }
3551428881deSRichard Henderson 
3552b597eedcSRichard Henderson TRANS(ADD, ALL, do_arith, a, tcg_gen_add_tl, tcg_gen_addi_tl, gen_op_addcc)
3553b597eedcSRichard Henderson TRANS(SUB, ALL, do_arith, a, tcg_gen_sub_tl, tcg_gen_subi_tl, gen_op_subcc)
3554b597eedcSRichard Henderson TRANS(ADDC, ALL, do_arith, a, gen_op_addc, NULL, gen_op_addccc)
3555b597eedcSRichard Henderson TRANS(SUBC, ALL, do_arith, a, gen_op_subc, NULL, gen_op_subccc)
3556428881deSRichard Henderson 
3557b597eedcSRichard Henderson TRANS(TADDcc, ALL, do_arith, a, NULL, NULL, gen_op_taddcc)
3558b597eedcSRichard Henderson TRANS(TSUBcc, ALL, do_arith, a, NULL, NULL, gen_op_tsubcc)
3559b597eedcSRichard Henderson TRANS(TADDccTV, ALL, do_arith, a, NULL, NULL, gen_op_taddcctv)
3560b597eedcSRichard Henderson TRANS(TSUBccTV, ALL, do_arith, a, NULL, NULL, gen_op_tsubcctv)
3561a9aba13dSRichard Henderson 
3562428881deSRichard Henderson TRANS(AND, ALL, do_logic, a, tcg_gen_and_tl, tcg_gen_andi_tl)
3563428881deSRichard Henderson TRANS(XOR, ALL, do_logic, a, tcg_gen_xor_tl, tcg_gen_xori_tl)
3564428881deSRichard Henderson TRANS(ANDN, ALL, do_logic, a, tcg_gen_andc_tl, NULL)
3565428881deSRichard Henderson TRANS(ORN, ALL, do_logic, a, tcg_gen_orc_tl, NULL)
3566428881deSRichard Henderson TRANS(XORN, ALL, do_logic, a, tcg_gen_eqv_tl, NULL)
3567428881deSRichard Henderson 
3568b597eedcSRichard Henderson TRANS(MULX, 64, do_arith, a, tcg_gen_mul_tl, tcg_gen_muli_tl, NULL)
3569b5372650SRichard Henderson TRANS(UMUL, MUL, do_logic, a, gen_op_umul, NULL)
3570b5372650SRichard Henderson TRANS(SMUL, MUL, do_logic, a, gen_op_smul, NULL)
3571b597eedcSRichard Henderson TRANS(MULScc, ALL, do_arith, a, NULL, NULL, gen_op_mulscc)
357222188d7dSRichard Henderson 
3573b597eedcSRichard Henderson TRANS(UDIVX, 64, do_arith, a, gen_op_udivx, NULL, NULL)
3574b597eedcSRichard Henderson TRANS(SDIVX, 64, do_arith, a, gen_op_sdivx, NULL, NULL)
3575b597eedcSRichard Henderson TRANS(UDIV, DIV, do_arith, a, gen_op_udiv, NULL, gen_op_udivcc)
3576b597eedcSRichard Henderson TRANS(SDIV, DIV, do_arith, a, gen_op_sdiv, NULL, gen_op_sdivcc)
35774ee85ea9SRichard Henderson 
35789c6ec5bcSRichard Henderson /* TODO: Should have feature bit -- comes in with UltraSparc T2. */
3579b597eedcSRichard Henderson TRANS(POPC, 64, do_arith, a, gen_op_popc, NULL, NULL)
35809c6ec5bcSRichard Henderson 
3581428881deSRichard Henderson static bool trans_OR(DisasContext *dc, arg_r_r_ri_cc *a)
3582428881deSRichard Henderson {
3583428881deSRichard Henderson     /* OR with %g0 is the canonical alias for MOV. */
3584428881deSRichard Henderson     if (!a->cc && a->rs1 == 0) {
3585428881deSRichard Henderson         if (a->imm || a->rs2_or_imm == 0) {
3586428881deSRichard Henderson             gen_store_gpr(dc, a->rd, tcg_constant_tl(a->rs2_or_imm));
3587428881deSRichard Henderson         } else if (a->rs2_or_imm & ~0x1f) {
3588428881deSRichard Henderson             /* For simplicity, we under-decoded the rs2 form. */
3589428881deSRichard Henderson             return false;
3590428881deSRichard Henderson         } else {
3591428881deSRichard Henderson             gen_store_gpr(dc, a->rd, cpu_regs[a->rs2_or_imm]);
3592428881deSRichard Henderson         }
3593428881deSRichard Henderson         return advance_pc(dc);
3594428881deSRichard Henderson     }
3595428881deSRichard Henderson     return do_logic(dc, a, tcg_gen_or_tl, tcg_gen_ori_tl);
3596428881deSRichard Henderson }
3597428881deSRichard Henderson 
3598b88ce6f2SRichard Henderson static bool gen_edge(DisasContext *dc, arg_r_r_r *a,
3599b88ce6f2SRichard Henderson                      int width, bool cc, bool left)
3600b88ce6f2SRichard Henderson {
3601b88ce6f2SRichard Henderson     TCGv dst, s1, s2, lo1, lo2;
3602b88ce6f2SRichard Henderson     uint64_t amask, tabl, tabr;
3603b88ce6f2SRichard Henderson     int shift, imask, omask;
3604b88ce6f2SRichard Henderson 
3605b88ce6f2SRichard Henderson     dst = gen_dest_gpr(dc, a->rd);
3606b88ce6f2SRichard Henderson     s1 = gen_load_gpr(dc, a->rs1);
3607b88ce6f2SRichard Henderson     s2 = gen_load_gpr(dc, a->rs2);
3608b88ce6f2SRichard Henderson 
3609b88ce6f2SRichard Henderson     if (cc) {
3610f828df74SRichard Henderson         gen_op_subcc(cpu_cc_N, s1, s2);
3611b88ce6f2SRichard Henderson     }
3612b88ce6f2SRichard Henderson 
3613b88ce6f2SRichard Henderson     /*
3614b88ce6f2SRichard Henderson      * Theory of operation: there are two tables, left and right (not to
3615b88ce6f2SRichard Henderson      * be confused with the left and right versions of the opcode).  These
3616b88ce6f2SRichard Henderson      * are indexed by the low 3 bits of the inputs.  To make things "easy",
3617b88ce6f2SRichard Henderson      * these tables are loaded into two constants, TABL and TABR below.
3618b88ce6f2SRichard Henderson      * The operation index = (input & imask) << shift calculates the index
3619b88ce6f2SRichard Henderson      * into the constant, while val = (table >> index) & omask calculates
3620b88ce6f2SRichard Henderson      * the value we're looking for.
3621b88ce6f2SRichard Henderson      */
3622b88ce6f2SRichard Henderson     switch (width) {
3623b88ce6f2SRichard Henderson     case 8:
3624b88ce6f2SRichard Henderson         imask = 0x7;
3625b88ce6f2SRichard Henderson         shift = 3;
3626b88ce6f2SRichard Henderson         omask = 0xff;
3627b88ce6f2SRichard Henderson         if (left) {
3628b88ce6f2SRichard Henderson             tabl = 0x80c0e0f0f8fcfeffULL;
3629b88ce6f2SRichard Henderson             tabr = 0xff7f3f1f0f070301ULL;
3630b88ce6f2SRichard Henderson         } else {
3631b88ce6f2SRichard Henderson             tabl = 0x0103070f1f3f7fffULL;
3632b88ce6f2SRichard Henderson             tabr = 0xfffefcf8f0e0c080ULL;
3633b88ce6f2SRichard Henderson         }
3634b88ce6f2SRichard Henderson         break;
3635b88ce6f2SRichard Henderson     case 16:
3636b88ce6f2SRichard Henderson         imask = 0x6;
3637b88ce6f2SRichard Henderson         shift = 1;
3638b88ce6f2SRichard Henderson         omask = 0xf;
3639b88ce6f2SRichard Henderson         if (left) {
3640b88ce6f2SRichard Henderson             tabl = 0x8cef;
3641b88ce6f2SRichard Henderson             tabr = 0xf731;
3642b88ce6f2SRichard Henderson         } else {
3643b88ce6f2SRichard Henderson             tabl = 0x137f;
3644b88ce6f2SRichard Henderson             tabr = 0xfec8;
3645b88ce6f2SRichard Henderson         }
3646b88ce6f2SRichard Henderson         break;
3647b88ce6f2SRichard Henderson     case 32:
3648b88ce6f2SRichard Henderson         imask = 0x4;
3649b88ce6f2SRichard Henderson         shift = 0;
3650b88ce6f2SRichard Henderson         omask = 0x3;
3651b88ce6f2SRichard Henderson         if (left) {
3652b88ce6f2SRichard Henderson             tabl = (2 << 2) | 3;
3653b88ce6f2SRichard Henderson             tabr = (3 << 2) | 1;
3654b88ce6f2SRichard Henderson         } else {
3655b88ce6f2SRichard Henderson             tabl = (1 << 2) | 3;
3656b88ce6f2SRichard Henderson             tabr = (3 << 2) | 2;
3657b88ce6f2SRichard Henderson         }
3658b88ce6f2SRichard Henderson         break;
3659b88ce6f2SRichard Henderson     default:
3660b88ce6f2SRichard Henderson         abort();
3661b88ce6f2SRichard Henderson     }
3662b88ce6f2SRichard Henderson 
3663b88ce6f2SRichard Henderson     lo1 = tcg_temp_new();
3664b88ce6f2SRichard Henderson     lo2 = tcg_temp_new();
3665b88ce6f2SRichard Henderson     tcg_gen_andi_tl(lo1, s1, imask);
3666b88ce6f2SRichard Henderson     tcg_gen_andi_tl(lo2, s2, imask);
3667b88ce6f2SRichard Henderson     tcg_gen_shli_tl(lo1, lo1, shift);
3668b88ce6f2SRichard Henderson     tcg_gen_shli_tl(lo2, lo2, shift);
3669b88ce6f2SRichard Henderson 
3670b88ce6f2SRichard Henderson     tcg_gen_shr_tl(lo1, tcg_constant_tl(tabl), lo1);
3671b88ce6f2SRichard Henderson     tcg_gen_shr_tl(lo2, tcg_constant_tl(tabr), lo2);
3672b88ce6f2SRichard Henderson     tcg_gen_andi_tl(lo1, lo1, omask);
3673b88ce6f2SRichard Henderson     tcg_gen_andi_tl(lo2, lo2, omask);
3674b88ce6f2SRichard Henderson 
3675b88ce6f2SRichard Henderson     amask = address_mask_i(dc, -8);
3676b88ce6f2SRichard Henderson     tcg_gen_andi_tl(s1, s1, amask);
3677b88ce6f2SRichard Henderson     tcg_gen_andi_tl(s2, s2, amask);
3678b88ce6f2SRichard Henderson 
3679b88ce6f2SRichard Henderson     /* Compute dst = (s1 == s2 ? lo1 : lo1 & lo2). */
3680b88ce6f2SRichard Henderson     tcg_gen_and_tl(lo2, lo2, lo1);
3681b88ce6f2SRichard Henderson     tcg_gen_movcond_tl(TCG_COND_EQ, dst, s1, s2, lo1, lo2);
3682b88ce6f2SRichard Henderson 
3683b88ce6f2SRichard Henderson     gen_store_gpr(dc, a->rd, dst);
3684b88ce6f2SRichard Henderson     return advance_pc(dc);
3685b88ce6f2SRichard Henderson }
3686b88ce6f2SRichard Henderson 
3687b88ce6f2SRichard Henderson TRANS(EDGE8cc, VIS1, gen_edge, a, 8, 1, 0)
3688b88ce6f2SRichard Henderson TRANS(EDGE8Lcc, VIS1, gen_edge, a, 8, 1, 1)
3689b88ce6f2SRichard Henderson TRANS(EDGE16cc, VIS1, gen_edge, a, 16, 1, 0)
3690b88ce6f2SRichard Henderson TRANS(EDGE16Lcc, VIS1, gen_edge, a, 16, 1, 1)
3691b88ce6f2SRichard Henderson TRANS(EDGE32cc, VIS1, gen_edge, a, 32, 1, 0)
3692b88ce6f2SRichard Henderson TRANS(EDGE32Lcc, VIS1, gen_edge, a, 32, 1, 1)
3693b88ce6f2SRichard Henderson 
3694b88ce6f2SRichard Henderson TRANS(EDGE8N, VIS2, gen_edge, a, 8, 0, 0)
3695b88ce6f2SRichard Henderson TRANS(EDGE8LN, VIS2, gen_edge, a, 8, 0, 1)
3696b88ce6f2SRichard Henderson TRANS(EDGE16N, VIS2, gen_edge, a, 16, 0, 0)
3697b88ce6f2SRichard Henderson TRANS(EDGE16LN, VIS2, gen_edge, a, 16, 0, 1)
3698b88ce6f2SRichard Henderson TRANS(EDGE32N, VIS2, gen_edge, a, 32, 0, 0)
3699b88ce6f2SRichard Henderson TRANS(EDGE32LN, VIS2, gen_edge, a, 32, 0, 1)
3700b88ce6f2SRichard Henderson 
370145bfed3bSRichard Henderson static bool do_rrr(DisasContext *dc, arg_r_r_r *a,
370245bfed3bSRichard Henderson                    void (*func)(TCGv, TCGv, TCGv))
370345bfed3bSRichard Henderson {
370445bfed3bSRichard Henderson     TCGv dst = gen_dest_gpr(dc, a->rd);
370545bfed3bSRichard Henderson     TCGv src1 = gen_load_gpr(dc, a->rs1);
370645bfed3bSRichard Henderson     TCGv src2 = gen_load_gpr(dc, a->rs2);
370745bfed3bSRichard Henderson 
370845bfed3bSRichard Henderson     func(dst, src1, src2);
370945bfed3bSRichard Henderson     gen_store_gpr(dc, a->rd, dst);
371045bfed3bSRichard Henderson     return advance_pc(dc);
371145bfed3bSRichard Henderson }
371245bfed3bSRichard Henderson 
371345bfed3bSRichard Henderson TRANS(ARRAY8, VIS1, do_rrr, a, gen_helper_array8)
371445bfed3bSRichard Henderson TRANS(ARRAY16, VIS1, do_rrr, a, gen_op_array16)
371545bfed3bSRichard Henderson TRANS(ARRAY32, VIS1, do_rrr, a, gen_op_array32)
371645bfed3bSRichard Henderson 
37179e20ca94SRichard Henderson static void gen_op_alignaddr(TCGv dst, TCGv s1, TCGv s2)
37189e20ca94SRichard Henderson {
37199e20ca94SRichard Henderson #ifdef TARGET_SPARC64
37209e20ca94SRichard Henderson     TCGv tmp = tcg_temp_new();
37219e20ca94SRichard Henderson 
37229e20ca94SRichard Henderson     tcg_gen_add_tl(tmp, s1, s2);
37239e20ca94SRichard Henderson     tcg_gen_andi_tl(dst, tmp, -8);
37249e20ca94SRichard Henderson     tcg_gen_deposit_tl(cpu_gsr, cpu_gsr, tmp, 0, 3);
37259e20ca94SRichard Henderson #else
37269e20ca94SRichard Henderson     g_assert_not_reached();
37279e20ca94SRichard Henderson #endif
37289e20ca94SRichard Henderson }
37299e20ca94SRichard Henderson 
37309e20ca94SRichard Henderson static void gen_op_alignaddrl(TCGv dst, TCGv s1, TCGv s2)
37319e20ca94SRichard Henderson {
37329e20ca94SRichard Henderson #ifdef TARGET_SPARC64
37339e20ca94SRichard Henderson     TCGv tmp = tcg_temp_new();
37349e20ca94SRichard Henderson 
37359e20ca94SRichard Henderson     tcg_gen_add_tl(tmp, s1, s2);
37369e20ca94SRichard Henderson     tcg_gen_andi_tl(dst, tmp, -8);
37379e20ca94SRichard Henderson     tcg_gen_neg_tl(tmp, tmp);
37389e20ca94SRichard Henderson     tcg_gen_deposit_tl(cpu_gsr, cpu_gsr, tmp, 0, 3);
37399e20ca94SRichard Henderson #else
37409e20ca94SRichard Henderson     g_assert_not_reached();
37419e20ca94SRichard Henderson #endif
37429e20ca94SRichard Henderson }
37439e20ca94SRichard Henderson 
37449e20ca94SRichard Henderson TRANS(ALIGNADDR, VIS1, do_rrr, a, gen_op_alignaddr)
37459e20ca94SRichard Henderson TRANS(ALIGNADDRL, VIS1, do_rrr, a, gen_op_alignaddrl)
37469e20ca94SRichard Henderson 
374739ca3490SRichard Henderson static void gen_op_bmask(TCGv dst, TCGv s1, TCGv s2)
374839ca3490SRichard Henderson {
374939ca3490SRichard Henderson #ifdef TARGET_SPARC64
375039ca3490SRichard Henderson     tcg_gen_add_tl(dst, s1, s2);
375139ca3490SRichard Henderson     tcg_gen_deposit_tl(cpu_gsr, cpu_gsr, dst, 32, 32);
375239ca3490SRichard Henderson #else
375339ca3490SRichard Henderson     g_assert_not_reached();
375439ca3490SRichard Henderson #endif
375539ca3490SRichard Henderson }
375639ca3490SRichard Henderson 
375739ca3490SRichard Henderson TRANS(BMASK, VIS2, do_rrr, a, gen_op_bmask)
375839ca3490SRichard Henderson 
37595fc546eeSRichard Henderson static bool do_shift_r(DisasContext *dc, arg_shiftr *a, bool l, bool u)
37605fc546eeSRichard Henderson {
37615fc546eeSRichard Henderson     TCGv dst, src1, src2;
37625fc546eeSRichard Henderson 
37635fc546eeSRichard Henderson     /* Reject 64-bit shifts for sparc32. */
37645fc546eeSRichard Henderson     if (avail_32(dc) && a->x) {
37655fc546eeSRichard Henderson         return false;
37665fc546eeSRichard Henderson     }
37675fc546eeSRichard Henderson 
37685fc546eeSRichard Henderson     src2 = tcg_temp_new();
37695fc546eeSRichard Henderson     tcg_gen_andi_tl(src2, gen_load_gpr(dc, a->rs2), a->x ? 63 : 31);
37705fc546eeSRichard Henderson     src1 = gen_load_gpr(dc, a->rs1);
37715fc546eeSRichard Henderson     dst = gen_dest_gpr(dc, a->rd);
37725fc546eeSRichard Henderson 
37735fc546eeSRichard Henderson     if (l) {
37745fc546eeSRichard Henderson         tcg_gen_shl_tl(dst, src1, src2);
37755fc546eeSRichard Henderson         if (!a->x) {
37765fc546eeSRichard Henderson             tcg_gen_ext32u_tl(dst, dst);
37775fc546eeSRichard Henderson         }
37785fc546eeSRichard Henderson     } else if (u) {
37795fc546eeSRichard Henderson         if (!a->x) {
37805fc546eeSRichard Henderson             tcg_gen_ext32u_tl(dst, src1);
37815fc546eeSRichard Henderson             src1 = dst;
37825fc546eeSRichard Henderson         }
37835fc546eeSRichard Henderson         tcg_gen_shr_tl(dst, src1, src2);
37845fc546eeSRichard Henderson     } else {
37855fc546eeSRichard Henderson         if (!a->x) {
37865fc546eeSRichard Henderson             tcg_gen_ext32s_tl(dst, src1);
37875fc546eeSRichard Henderson             src1 = dst;
37885fc546eeSRichard Henderson         }
37895fc546eeSRichard Henderson         tcg_gen_sar_tl(dst, src1, src2);
37905fc546eeSRichard Henderson     }
37915fc546eeSRichard Henderson     gen_store_gpr(dc, a->rd, dst);
37925fc546eeSRichard Henderson     return advance_pc(dc);
37935fc546eeSRichard Henderson }
37945fc546eeSRichard Henderson 
37955fc546eeSRichard Henderson TRANS(SLL_r, ALL, do_shift_r, a, true, true)
37965fc546eeSRichard Henderson TRANS(SRL_r, ALL, do_shift_r, a, false, true)
37975fc546eeSRichard Henderson TRANS(SRA_r, ALL, do_shift_r, a, false, false)
37985fc546eeSRichard Henderson 
37995fc546eeSRichard Henderson static bool do_shift_i(DisasContext *dc, arg_shifti *a, bool l, bool u)
38005fc546eeSRichard Henderson {
38015fc546eeSRichard Henderson     TCGv dst, src1;
38025fc546eeSRichard Henderson 
38035fc546eeSRichard Henderson     /* Reject 64-bit shifts for sparc32. */
38045fc546eeSRichard Henderson     if (avail_32(dc) && (a->x || a->i >= 32)) {
38055fc546eeSRichard Henderson         return false;
38065fc546eeSRichard Henderson     }
38075fc546eeSRichard Henderson 
38085fc546eeSRichard Henderson     src1 = gen_load_gpr(dc, a->rs1);
38095fc546eeSRichard Henderson     dst = gen_dest_gpr(dc, a->rd);
38105fc546eeSRichard Henderson 
38115fc546eeSRichard Henderson     if (avail_32(dc) || a->x) {
38125fc546eeSRichard Henderson         if (l) {
38135fc546eeSRichard Henderson             tcg_gen_shli_tl(dst, src1, a->i);
38145fc546eeSRichard Henderson         } else if (u) {
38155fc546eeSRichard Henderson             tcg_gen_shri_tl(dst, src1, a->i);
38165fc546eeSRichard Henderson         } else {
38175fc546eeSRichard Henderson             tcg_gen_sari_tl(dst, src1, a->i);
38185fc546eeSRichard Henderson         }
38195fc546eeSRichard Henderson     } else {
38205fc546eeSRichard Henderson         if (l) {
38215fc546eeSRichard Henderson             tcg_gen_deposit_z_tl(dst, src1, a->i, 32 - a->i);
38225fc546eeSRichard Henderson         } else if (u) {
38235fc546eeSRichard Henderson             tcg_gen_extract_tl(dst, src1, a->i, 32 - a->i);
38245fc546eeSRichard Henderson         } else {
38255fc546eeSRichard Henderson             tcg_gen_sextract_tl(dst, src1, a->i, 32 - a->i);
38265fc546eeSRichard Henderson         }
38275fc546eeSRichard Henderson     }
38285fc546eeSRichard Henderson     gen_store_gpr(dc, a->rd, dst);
38295fc546eeSRichard Henderson     return advance_pc(dc);
38305fc546eeSRichard Henderson }
38315fc546eeSRichard Henderson 
38325fc546eeSRichard Henderson TRANS(SLL_i, ALL, do_shift_i, a, true, true)
38335fc546eeSRichard Henderson TRANS(SRL_i, ALL, do_shift_i, a, false, true)
38345fc546eeSRichard Henderson TRANS(SRA_i, ALL, do_shift_i, a, false, false)
38355fc546eeSRichard Henderson 
3836fb4ed7aaSRichard Henderson static TCGv gen_rs2_or_imm(DisasContext *dc, bool imm, int rs2_or_imm)
3837fb4ed7aaSRichard Henderson {
3838fb4ed7aaSRichard Henderson     /* For simplicity, we under-decoded the rs2 form. */
3839fb4ed7aaSRichard Henderson     if (!imm && rs2_or_imm & ~0x1f) {
3840fb4ed7aaSRichard Henderson         return NULL;
3841fb4ed7aaSRichard Henderson     }
3842fb4ed7aaSRichard Henderson     if (imm || rs2_or_imm == 0) {
3843fb4ed7aaSRichard Henderson         return tcg_constant_tl(rs2_or_imm);
3844fb4ed7aaSRichard Henderson     } else {
3845fb4ed7aaSRichard Henderson         return cpu_regs[rs2_or_imm];
3846fb4ed7aaSRichard Henderson     }
3847fb4ed7aaSRichard Henderson }
3848fb4ed7aaSRichard Henderson 
3849fb4ed7aaSRichard Henderson static bool do_mov_cond(DisasContext *dc, DisasCompare *cmp, int rd, TCGv src2)
3850fb4ed7aaSRichard Henderson {
3851fb4ed7aaSRichard Henderson     TCGv dst = gen_load_gpr(dc, rd);
3852fb4ed7aaSRichard Henderson 
3853fb4ed7aaSRichard Henderson     tcg_gen_movcond_tl(cmp->cond, dst, cmp->c1, cmp->c2, src2, dst);
3854fb4ed7aaSRichard Henderson     gen_store_gpr(dc, rd, dst);
3855fb4ed7aaSRichard Henderson     return advance_pc(dc);
3856fb4ed7aaSRichard Henderson }
3857fb4ed7aaSRichard Henderson 
3858fb4ed7aaSRichard Henderson static bool trans_MOVcc(DisasContext *dc, arg_MOVcc *a)
3859fb4ed7aaSRichard Henderson {
3860fb4ed7aaSRichard Henderson     TCGv src2 = gen_rs2_or_imm(dc, a->imm, a->rs2_or_imm);
3861fb4ed7aaSRichard Henderson     DisasCompare cmp;
3862fb4ed7aaSRichard Henderson 
3863fb4ed7aaSRichard Henderson     if (src2 == NULL) {
3864fb4ed7aaSRichard Henderson         return false;
3865fb4ed7aaSRichard Henderson     }
3866fb4ed7aaSRichard Henderson     gen_compare(&cmp, a->cc, a->cond, dc);
3867fb4ed7aaSRichard Henderson     return do_mov_cond(dc, &cmp, a->rd, src2);
3868fb4ed7aaSRichard Henderson }
3869fb4ed7aaSRichard Henderson 
3870fb4ed7aaSRichard Henderson static bool trans_MOVfcc(DisasContext *dc, arg_MOVfcc *a)
3871fb4ed7aaSRichard Henderson {
3872fb4ed7aaSRichard Henderson     TCGv src2 = gen_rs2_or_imm(dc, a->imm, a->rs2_or_imm);
3873fb4ed7aaSRichard Henderson     DisasCompare cmp;
3874fb4ed7aaSRichard Henderson 
3875fb4ed7aaSRichard Henderson     if (src2 == NULL) {
3876fb4ed7aaSRichard Henderson         return false;
3877fb4ed7aaSRichard Henderson     }
3878fb4ed7aaSRichard Henderson     gen_fcompare(&cmp, a->cc, a->cond);
3879fb4ed7aaSRichard Henderson     return do_mov_cond(dc, &cmp, a->rd, src2);
3880fb4ed7aaSRichard Henderson }
3881fb4ed7aaSRichard Henderson 
3882fb4ed7aaSRichard Henderson static bool trans_MOVR(DisasContext *dc, arg_MOVR *a)
3883fb4ed7aaSRichard Henderson {
3884fb4ed7aaSRichard Henderson     TCGv src2 = gen_rs2_or_imm(dc, a->imm, a->rs2_or_imm);
3885fb4ed7aaSRichard Henderson     DisasCompare cmp;
3886fb4ed7aaSRichard Henderson 
3887fb4ed7aaSRichard Henderson     if (src2 == NULL) {
3888fb4ed7aaSRichard Henderson         return false;
3889fb4ed7aaSRichard Henderson     }
3890fb4ed7aaSRichard Henderson     gen_compare_reg(&cmp, a->cond, gen_load_gpr(dc, a->rs1));
3891fb4ed7aaSRichard Henderson     return do_mov_cond(dc, &cmp, a->rd, src2);
3892fb4ed7aaSRichard Henderson }
3893fb4ed7aaSRichard Henderson 
389486b82fe0SRichard Henderson static bool do_add_special(DisasContext *dc, arg_r_r_ri *a,
389586b82fe0SRichard Henderson                            bool (*func)(DisasContext *dc, int rd, TCGv src))
389686b82fe0SRichard Henderson {
389786b82fe0SRichard Henderson     TCGv src1, sum;
389886b82fe0SRichard Henderson 
389986b82fe0SRichard Henderson     /* For simplicity, we under-decoded the rs2 form. */
390086b82fe0SRichard Henderson     if (!a->imm && a->rs2_or_imm & ~0x1f) {
390186b82fe0SRichard Henderson         return false;
390286b82fe0SRichard Henderson     }
390386b82fe0SRichard Henderson 
390486b82fe0SRichard Henderson     /*
390586b82fe0SRichard Henderson      * Always load the sum into a new temporary.
390686b82fe0SRichard Henderson      * This is required to capture the value across a window change,
390786b82fe0SRichard Henderson      * e.g. SAVE and RESTORE, and may be optimized away otherwise.
390886b82fe0SRichard Henderson      */
390986b82fe0SRichard Henderson     sum = tcg_temp_new();
391086b82fe0SRichard Henderson     src1 = gen_load_gpr(dc, a->rs1);
391186b82fe0SRichard Henderson     if (a->imm || a->rs2_or_imm == 0) {
391286b82fe0SRichard Henderson         tcg_gen_addi_tl(sum, src1, a->rs2_or_imm);
391386b82fe0SRichard Henderson     } else {
391486b82fe0SRichard Henderson         tcg_gen_add_tl(sum, src1, cpu_regs[a->rs2_or_imm]);
391586b82fe0SRichard Henderson     }
391686b82fe0SRichard Henderson     return func(dc, a->rd, sum);
391786b82fe0SRichard Henderson }
391886b82fe0SRichard Henderson 
391986b82fe0SRichard Henderson static bool do_jmpl(DisasContext *dc, int rd, TCGv src)
392086b82fe0SRichard Henderson {
392186b82fe0SRichard Henderson     /*
392286b82fe0SRichard Henderson      * Preserve pc across advance, so that we can delay
392386b82fe0SRichard Henderson      * the writeback to rd until after src is consumed.
392486b82fe0SRichard Henderson      */
392586b82fe0SRichard Henderson     target_ulong cur_pc = dc->pc;
392686b82fe0SRichard Henderson 
392786b82fe0SRichard Henderson     gen_check_align(dc, src, 3);
392886b82fe0SRichard Henderson 
392986b82fe0SRichard Henderson     gen_mov_pc_npc(dc);
393086b82fe0SRichard Henderson     tcg_gen_mov_tl(cpu_npc, src);
393186b82fe0SRichard Henderson     gen_address_mask(dc, cpu_npc);
393286b82fe0SRichard Henderson     gen_store_gpr(dc, rd, tcg_constant_tl(cur_pc));
393386b82fe0SRichard Henderson 
393486b82fe0SRichard Henderson     dc->npc = DYNAMIC_PC_LOOKUP;
393586b82fe0SRichard Henderson     return true;
393686b82fe0SRichard Henderson }
393786b82fe0SRichard Henderson 
393886b82fe0SRichard Henderson TRANS(JMPL, ALL, do_add_special, a, do_jmpl)
393986b82fe0SRichard Henderson 
394086b82fe0SRichard Henderson static bool do_rett(DisasContext *dc, int rd, TCGv src)
394186b82fe0SRichard Henderson {
394286b82fe0SRichard Henderson     if (!supervisor(dc)) {
394386b82fe0SRichard Henderson         return raise_priv(dc);
394486b82fe0SRichard Henderson     }
394586b82fe0SRichard Henderson 
394686b82fe0SRichard Henderson     gen_check_align(dc, src, 3);
394786b82fe0SRichard Henderson 
394886b82fe0SRichard Henderson     gen_mov_pc_npc(dc);
394986b82fe0SRichard Henderson     tcg_gen_mov_tl(cpu_npc, src);
395086b82fe0SRichard Henderson     gen_helper_rett(tcg_env);
395186b82fe0SRichard Henderson 
395286b82fe0SRichard Henderson     dc->npc = DYNAMIC_PC;
395386b82fe0SRichard Henderson     return true;
395486b82fe0SRichard Henderson }
395586b82fe0SRichard Henderson 
395686b82fe0SRichard Henderson TRANS(RETT, 32, do_add_special, a, do_rett)
395786b82fe0SRichard Henderson 
395886b82fe0SRichard Henderson static bool do_return(DisasContext *dc, int rd, TCGv src)
395986b82fe0SRichard Henderson {
396086b82fe0SRichard Henderson     gen_check_align(dc, src, 3);
396186b82fe0SRichard Henderson 
396286b82fe0SRichard Henderson     gen_mov_pc_npc(dc);
396386b82fe0SRichard Henderson     tcg_gen_mov_tl(cpu_npc, src);
396486b82fe0SRichard Henderson     gen_address_mask(dc, cpu_npc);
396586b82fe0SRichard Henderson 
396686b82fe0SRichard Henderson     gen_helper_restore(tcg_env);
396786b82fe0SRichard Henderson     dc->npc = DYNAMIC_PC_LOOKUP;
396886b82fe0SRichard Henderson     return true;
396986b82fe0SRichard Henderson }
397086b82fe0SRichard Henderson 
397186b82fe0SRichard Henderson TRANS(RETURN, 64, do_add_special, a, do_return)
397286b82fe0SRichard Henderson 
3973d3825800SRichard Henderson static bool do_save(DisasContext *dc, int rd, TCGv src)
3974d3825800SRichard Henderson {
3975d3825800SRichard Henderson     gen_helper_save(tcg_env);
3976d3825800SRichard Henderson     gen_store_gpr(dc, rd, src);
3977d3825800SRichard Henderson     return advance_pc(dc);
3978d3825800SRichard Henderson }
3979d3825800SRichard Henderson 
3980d3825800SRichard Henderson TRANS(SAVE, ALL, do_add_special, a, do_save)
3981d3825800SRichard Henderson 
3982d3825800SRichard Henderson static bool do_restore(DisasContext *dc, int rd, TCGv src)
3983d3825800SRichard Henderson {
3984d3825800SRichard Henderson     gen_helper_restore(tcg_env);
3985d3825800SRichard Henderson     gen_store_gpr(dc, rd, src);
3986d3825800SRichard Henderson     return advance_pc(dc);
3987d3825800SRichard Henderson }
3988d3825800SRichard Henderson 
3989d3825800SRichard Henderson TRANS(RESTORE, ALL, do_add_special, a, do_restore)
3990d3825800SRichard Henderson 
39918f75b8a4SRichard Henderson static bool do_done_retry(DisasContext *dc, bool done)
39928f75b8a4SRichard Henderson {
39938f75b8a4SRichard Henderson     if (!supervisor(dc)) {
39948f75b8a4SRichard Henderson         return raise_priv(dc);
39958f75b8a4SRichard Henderson     }
39968f75b8a4SRichard Henderson     dc->npc = DYNAMIC_PC;
39978f75b8a4SRichard Henderson     dc->pc = DYNAMIC_PC;
39988f75b8a4SRichard Henderson     translator_io_start(&dc->base);
39998f75b8a4SRichard Henderson     if (done) {
40008f75b8a4SRichard Henderson         gen_helper_done(tcg_env);
40018f75b8a4SRichard Henderson     } else {
40028f75b8a4SRichard Henderson         gen_helper_retry(tcg_env);
40038f75b8a4SRichard Henderson     }
40048f75b8a4SRichard Henderson     return true;
40058f75b8a4SRichard Henderson }
40068f75b8a4SRichard Henderson 
40078f75b8a4SRichard Henderson TRANS(DONE, 64, do_done_retry, true)
40088f75b8a4SRichard Henderson TRANS(RETRY, 64, do_done_retry, false)
40098f75b8a4SRichard Henderson 
40100880d20bSRichard Henderson /*
40110880d20bSRichard Henderson  * Major opcode 11 -- load and store instructions
40120880d20bSRichard Henderson  */
40130880d20bSRichard Henderson 
40140880d20bSRichard Henderson static TCGv gen_ldst_addr(DisasContext *dc, int rs1, bool imm, int rs2_or_imm)
40150880d20bSRichard Henderson {
40160880d20bSRichard Henderson     TCGv addr, tmp = NULL;
40170880d20bSRichard Henderson 
40180880d20bSRichard Henderson     /* For simplicity, we under-decoded the rs2 form. */
40190880d20bSRichard Henderson     if (!imm && rs2_or_imm & ~0x1f) {
40200880d20bSRichard Henderson         return NULL;
40210880d20bSRichard Henderson     }
40220880d20bSRichard Henderson 
40230880d20bSRichard Henderson     addr = gen_load_gpr(dc, rs1);
40240880d20bSRichard Henderson     if (rs2_or_imm) {
40250880d20bSRichard Henderson         tmp = tcg_temp_new();
40260880d20bSRichard Henderson         if (imm) {
40270880d20bSRichard Henderson             tcg_gen_addi_tl(tmp, addr, rs2_or_imm);
40280880d20bSRichard Henderson         } else {
40290880d20bSRichard Henderson             tcg_gen_add_tl(tmp, addr, cpu_regs[rs2_or_imm]);
40300880d20bSRichard Henderson         }
40310880d20bSRichard Henderson         addr = tmp;
40320880d20bSRichard Henderson     }
40330880d20bSRichard Henderson     if (AM_CHECK(dc)) {
40340880d20bSRichard Henderson         if (!tmp) {
40350880d20bSRichard Henderson             tmp = tcg_temp_new();
40360880d20bSRichard Henderson         }
40370880d20bSRichard Henderson         tcg_gen_ext32u_tl(tmp, addr);
40380880d20bSRichard Henderson         addr = tmp;
40390880d20bSRichard Henderson     }
40400880d20bSRichard Henderson     return addr;
40410880d20bSRichard Henderson }
40420880d20bSRichard Henderson 
40430880d20bSRichard Henderson static bool do_ld_gpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp mop)
40440880d20bSRichard Henderson {
40450880d20bSRichard Henderson     TCGv reg, addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
40460880d20bSRichard Henderson     DisasASI da;
40470880d20bSRichard Henderson 
40480880d20bSRichard Henderson     if (addr == NULL) {
40490880d20bSRichard Henderson         return false;
40500880d20bSRichard Henderson     }
40510880d20bSRichard Henderson     da = resolve_asi(dc, a->asi, mop);
40520880d20bSRichard Henderson 
40530880d20bSRichard Henderson     reg = gen_dest_gpr(dc, a->rd);
405442071fc1SRichard Henderson     gen_ld_asi(dc, &da, reg, addr);
40550880d20bSRichard Henderson     gen_store_gpr(dc, a->rd, reg);
40560880d20bSRichard Henderson     return advance_pc(dc);
40570880d20bSRichard Henderson }
40580880d20bSRichard Henderson 
40590880d20bSRichard Henderson TRANS(LDUW, ALL, do_ld_gpr, a, MO_TEUL)
40600880d20bSRichard Henderson TRANS(LDUB, ALL, do_ld_gpr, a, MO_UB)
40610880d20bSRichard Henderson TRANS(LDUH, ALL, do_ld_gpr, a, MO_TEUW)
40620880d20bSRichard Henderson TRANS(LDSB, ALL, do_ld_gpr, a, MO_SB)
40630880d20bSRichard Henderson TRANS(LDSH, ALL, do_ld_gpr, a, MO_TESW)
40640880d20bSRichard Henderson TRANS(LDSW, 64, do_ld_gpr, a, MO_TESL)
40650880d20bSRichard Henderson TRANS(LDX, 64, do_ld_gpr, a, MO_TEUQ)
40660880d20bSRichard Henderson 
40670880d20bSRichard Henderson static bool do_st_gpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp mop)
40680880d20bSRichard Henderson {
40690880d20bSRichard Henderson     TCGv reg, addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
40700880d20bSRichard Henderson     DisasASI da;
40710880d20bSRichard Henderson 
40720880d20bSRichard Henderson     if (addr == NULL) {
40730880d20bSRichard Henderson         return false;
40740880d20bSRichard Henderson     }
40750880d20bSRichard Henderson     da = resolve_asi(dc, a->asi, mop);
40760880d20bSRichard Henderson 
40770880d20bSRichard Henderson     reg = gen_load_gpr(dc, a->rd);
407842071fc1SRichard Henderson     gen_st_asi(dc, &da, reg, addr);
40790880d20bSRichard Henderson     return advance_pc(dc);
40800880d20bSRichard Henderson }
40810880d20bSRichard Henderson 
40820880d20bSRichard Henderson TRANS(STW, ALL, do_st_gpr, a, MO_TEUL)
40830880d20bSRichard Henderson TRANS(STB, ALL, do_st_gpr, a, MO_UB)
40840880d20bSRichard Henderson TRANS(STH, ALL, do_st_gpr, a, MO_TEUW)
40850880d20bSRichard Henderson TRANS(STX, 64, do_st_gpr, a, MO_TEUQ)
40860880d20bSRichard Henderson 
40870880d20bSRichard Henderson static bool trans_LDD(DisasContext *dc, arg_r_r_ri_asi *a)
40880880d20bSRichard Henderson {
40890880d20bSRichard Henderson     TCGv addr;
40900880d20bSRichard Henderson     DisasASI da;
40910880d20bSRichard Henderson 
40920880d20bSRichard Henderson     if (a->rd & 1) {
40930880d20bSRichard Henderson         return false;
40940880d20bSRichard Henderson     }
40950880d20bSRichard Henderson     addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
40960880d20bSRichard Henderson     if (addr == NULL) {
40970880d20bSRichard Henderson         return false;
40980880d20bSRichard Henderson     }
40990880d20bSRichard Henderson     da = resolve_asi(dc, a->asi, MO_TEUQ);
410042071fc1SRichard Henderson     gen_ldda_asi(dc, &da, addr, a->rd);
41010880d20bSRichard Henderson     return advance_pc(dc);
41020880d20bSRichard Henderson }
41030880d20bSRichard Henderson 
41040880d20bSRichard Henderson static bool trans_STD(DisasContext *dc, arg_r_r_ri_asi *a)
41050880d20bSRichard Henderson {
41060880d20bSRichard Henderson     TCGv addr;
41070880d20bSRichard Henderson     DisasASI da;
41080880d20bSRichard Henderson 
41090880d20bSRichard Henderson     if (a->rd & 1) {
41100880d20bSRichard Henderson         return false;
41110880d20bSRichard Henderson     }
41120880d20bSRichard Henderson     addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
41130880d20bSRichard Henderson     if (addr == NULL) {
41140880d20bSRichard Henderson         return false;
41150880d20bSRichard Henderson     }
41160880d20bSRichard Henderson     da = resolve_asi(dc, a->asi, MO_TEUQ);
411742071fc1SRichard Henderson     gen_stda_asi(dc, &da, addr, a->rd);
41180880d20bSRichard Henderson     return advance_pc(dc);
41190880d20bSRichard Henderson }
41200880d20bSRichard Henderson 
4121cf07cd1eSRichard Henderson static bool trans_LDSTUB(DisasContext *dc, arg_r_r_ri_asi *a)
4122cf07cd1eSRichard Henderson {
4123cf07cd1eSRichard Henderson     TCGv addr, reg;
4124cf07cd1eSRichard Henderson     DisasASI da;
4125cf07cd1eSRichard Henderson 
4126cf07cd1eSRichard Henderson     addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
4127cf07cd1eSRichard Henderson     if (addr == NULL) {
4128cf07cd1eSRichard Henderson         return false;
4129cf07cd1eSRichard Henderson     }
4130cf07cd1eSRichard Henderson     da = resolve_asi(dc, a->asi, MO_UB);
4131cf07cd1eSRichard Henderson 
4132cf07cd1eSRichard Henderson     reg = gen_dest_gpr(dc, a->rd);
4133cf07cd1eSRichard Henderson     gen_ldstub_asi(dc, &da, reg, addr);
4134cf07cd1eSRichard Henderson     gen_store_gpr(dc, a->rd, reg);
4135cf07cd1eSRichard Henderson     return advance_pc(dc);
4136cf07cd1eSRichard Henderson }
4137cf07cd1eSRichard Henderson 
4138dca544b9SRichard Henderson static bool trans_SWAP(DisasContext *dc, arg_r_r_ri_asi *a)
4139dca544b9SRichard Henderson {
4140dca544b9SRichard Henderson     TCGv addr, dst, src;
4141dca544b9SRichard Henderson     DisasASI da;
4142dca544b9SRichard Henderson 
4143dca544b9SRichard Henderson     addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
4144dca544b9SRichard Henderson     if (addr == NULL) {
4145dca544b9SRichard Henderson         return false;
4146dca544b9SRichard Henderson     }
4147dca544b9SRichard Henderson     da = resolve_asi(dc, a->asi, MO_TEUL);
4148dca544b9SRichard Henderson 
4149dca544b9SRichard Henderson     dst = gen_dest_gpr(dc, a->rd);
4150dca544b9SRichard Henderson     src = gen_load_gpr(dc, a->rd);
4151dca544b9SRichard Henderson     gen_swap_asi(dc, &da, dst, src, addr);
4152dca544b9SRichard Henderson     gen_store_gpr(dc, a->rd, dst);
4153dca544b9SRichard Henderson     return advance_pc(dc);
4154dca544b9SRichard Henderson }
4155dca544b9SRichard Henderson 
4156d0a11d25SRichard Henderson static bool do_casa(DisasContext *dc, arg_r_r_ri_asi *a, MemOp mop)
4157d0a11d25SRichard Henderson {
4158d0a11d25SRichard Henderson     TCGv addr, o, n, c;
4159d0a11d25SRichard Henderson     DisasASI da;
4160d0a11d25SRichard Henderson 
4161d0a11d25SRichard Henderson     addr = gen_ldst_addr(dc, a->rs1, true, 0);
4162d0a11d25SRichard Henderson     if (addr == NULL) {
4163d0a11d25SRichard Henderson         return false;
4164d0a11d25SRichard Henderson     }
4165d0a11d25SRichard Henderson     da = resolve_asi(dc, a->asi, mop);
4166d0a11d25SRichard Henderson 
4167d0a11d25SRichard Henderson     o = gen_dest_gpr(dc, a->rd);
4168d0a11d25SRichard Henderson     n = gen_load_gpr(dc, a->rd);
4169d0a11d25SRichard Henderson     c = gen_load_gpr(dc, a->rs2_or_imm);
4170d0a11d25SRichard Henderson     gen_cas_asi(dc, &da, o, n, c, addr);
4171d0a11d25SRichard Henderson     gen_store_gpr(dc, a->rd, o);
4172d0a11d25SRichard Henderson     return advance_pc(dc);
4173d0a11d25SRichard Henderson }
4174d0a11d25SRichard Henderson 
4175d0a11d25SRichard Henderson TRANS(CASA, CASA, do_casa, a, MO_TEUL)
4176d0a11d25SRichard Henderson TRANS(CASXA, 64, do_casa, a, MO_TEUQ)
4177d0a11d25SRichard Henderson 
417806c060d9SRichard Henderson static bool do_ld_fpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp sz)
417906c060d9SRichard Henderson {
418006c060d9SRichard Henderson     TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
418106c060d9SRichard Henderson     DisasASI da;
418206c060d9SRichard Henderson 
418306c060d9SRichard Henderson     if (addr == NULL) {
418406c060d9SRichard Henderson         return false;
418506c060d9SRichard Henderson     }
418606c060d9SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
418706c060d9SRichard Henderson         return true;
418806c060d9SRichard Henderson     }
418906c060d9SRichard Henderson     if (sz == MO_128 && gen_trap_float128(dc)) {
419006c060d9SRichard Henderson         return true;
419106c060d9SRichard Henderson     }
419206c060d9SRichard Henderson     da = resolve_asi(dc, a->asi, MO_TE | sz);
4193287b1152SRichard Henderson     gen_ldf_asi(dc, &da, sz, addr, a->rd);
419406c060d9SRichard Henderson     gen_update_fprs_dirty(dc, a->rd);
419506c060d9SRichard Henderson     return advance_pc(dc);
419606c060d9SRichard Henderson }
419706c060d9SRichard Henderson 
419806c060d9SRichard Henderson TRANS(LDF, ALL, do_ld_fpr, a, MO_32)
419906c060d9SRichard Henderson TRANS(LDDF, ALL, do_ld_fpr, a, MO_64)
420006c060d9SRichard Henderson TRANS(LDQF, ALL, do_ld_fpr, a, MO_128)
420106c060d9SRichard Henderson 
4202287b1152SRichard Henderson TRANS(LDFA, 64, do_ld_fpr, a, MO_32)
4203287b1152SRichard Henderson TRANS(LDDFA, 64, do_ld_fpr, a, MO_64)
4204287b1152SRichard Henderson TRANS(LDQFA, 64, do_ld_fpr, a, MO_128)
4205287b1152SRichard Henderson 
420606c060d9SRichard Henderson static bool do_st_fpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp sz)
420706c060d9SRichard Henderson {
420806c060d9SRichard Henderson     TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
420906c060d9SRichard Henderson     DisasASI da;
421006c060d9SRichard Henderson 
421106c060d9SRichard Henderson     if (addr == NULL) {
421206c060d9SRichard Henderson         return false;
421306c060d9SRichard Henderson     }
421406c060d9SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
421506c060d9SRichard Henderson         return true;
421606c060d9SRichard Henderson     }
421706c060d9SRichard Henderson     if (sz == MO_128 && gen_trap_float128(dc)) {
421806c060d9SRichard Henderson         return true;
421906c060d9SRichard Henderson     }
422006c060d9SRichard Henderson     da = resolve_asi(dc, a->asi, MO_TE | sz);
4221287b1152SRichard Henderson     gen_stf_asi(dc, &da, sz, addr, a->rd);
422206c060d9SRichard Henderson     return advance_pc(dc);
422306c060d9SRichard Henderson }
422406c060d9SRichard Henderson 
422506c060d9SRichard Henderson TRANS(STF, ALL, do_st_fpr, a, MO_32)
422606c060d9SRichard Henderson TRANS(STDF, ALL, do_st_fpr, a, MO_64)
422706c060d9SRichard Henderson TRANS(STQF, ALL, do_st_fpr, a, MO_128)
422806c060d9SRichard Henderson 
4229287b1152SRichard Henderson TRANS(STFA, 64, do_st_fpr, a, MO_32)
4230287b1152SRichard Henderson TRANS(STDFA, 64, do_st_fpr, a, MO_64)
4231287b1152SRichard Henderson TRANS(STQFA, 64, do_st_fpr, a, MO_128)
4232287b1152SRichard Henderson 
423306c060d9SRichard Henderson static bool trans_STDFQ(DisasContext *dc, arg_STDFQ *a)
423406c060d9SRichard Henderson {
423506c060d9SRichard Henderson     if (!avail_32(dc)) {
423606c060d9SRichard Henderson         return false;
423706c060d9SRichard Henderson     }
423806c060d9SRichard Henderson     if (!supervisor(dc)) {
423906c060d9SRichard Henderson         return raise_priv(dc);
424006c060d9SRichard Henderson     }
424106c060d9SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
424206c060d9SRichard Henderson         return true;
424306c060d9SRichard Henderson     }
424406c060d9SRichard Henderson     gen_op_fpexception_im(dc, FSR_FTT_SEQ_ERROR);
424506c060d9SRichard Henderson     return true;
424606c060d9SRichard Henderson }
424706c060d9SRichard Henderson 
4248da681406SRichard Henderson static bool do_ldfsr(DisasContext *dc, arg_r_r_ri *a, MemOp mop,
4249da681406SRichard Henderson                      target_ulong new_mask, target_ulong old_mask)
42503d3c0673SRichard Henderson {
4251da681406SRichard Henderson     TCGv tmp, addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
42523d3c0673SRichard Henderson     if (addr == NULL) {
42533d3c0673SRichard Henderson         return false;
42543d3c0673SRichard Henderson     }
42553d3c0673SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
42563d3c0673SRichard Henderson         return true;
42573d3c0673SRichard Henderson     }
4258da681406SRichard Henderson     tmp = tcg_temp_new();
4259da681406SRichard Henderson     tcg_gen_qemu_ld_tl(tmp, addr, dc->mem_idx, mop | MO_ALIGN);
4260da681406SRichard Henderson     tcg_gen_andi_tl(tmp, tmp, new_mask);
4261da681406SRichard Henderson     tcg_gen_andi_tl(cpu_fsr, cpu_fsr, old_mask);
4262da681406SRichard Henderson     tcg_gen_or_tl(cpu_fsr, cpu_fsr, tmp);
4263da681406SRichard Henderson     gen_helper_set_fsr(tcg_env, cpu_fsr);
42643d3c0673SRichard Henderson     return advance_pc(dc);
42653d3c0673SRichard Henderson }
42663d3c0673SRichard Henderson 
4267da681406SRichard Henderson TRANS(LDFSR, ALL, do_ldfsr, a, MO_TEUL, FSR_LDFSR_MASK, FSR_LDFSR_OLDMASK)
4268da681406SRichard Henderson TRANS(LDXFSR, 64, do_ldfsr, a, MO_TEUQ, FSR_LDXFSR_MASK, FSR_LDXFSR_OLDMASK)
42693d3c0673SRichard Henderson 
42703d3c0673SRichard Henderson static bool do_stfsr(DisasContext *dc, arg_r_r_ri *a, MemOp mop)
42713d3c0673SRichard Henderson {
42723d3c0673SRichard Henderson     TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
42733d3c0673SRichard Henderson     if (addr == NULL) {
42743d3c0673SRichard Henderson         return false;
42753d3c0673SRichard Henderson     }
42763d3c0673SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
42773d3c0673SRichard Henderson         return true;
42783d3c0673SRichard Henderson     }
42793d3c0673SRichard Henderson     tcg_gen_qemu_st_tl(cpu_fsr, addr, dc->mem_idx, mop | MO_ALIGN);
42803d3c0673SRichard Henderson     return advance_pc(dc);
42813d3c0673SRichard Henderson }
42823d3c0673SRichard Henderson 
42833d3c0673SRichard Henderson TRANS(STFSR, ALL, do_stfsr, a, MO_TEUL)
42843d3c0673SRichard Henderson TRANS(STXFSR, 64, do_stfsr, a, MO_TEUQ)
42853d3c0673SRichard Henderson 
42863a38260eSRichard Henderson static bool do_fc(DisasContext *dc, int rd, bool c)
42873a38260eSRichard Henderson {
42883a38260eSRichard Henderson     uint64_t mask;
42893a38260eSRichard Henderson 
42903a38260eSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
42913a38260eSRichard Henderson         return true;
42923a38260eSRichard Henderson     }
42933a38260eSRichard Henderson 
42943a38260eSRichard Henderson     if (rd & 1) {
42953a38260eSRichard Henderson         mask = MAKE_64BIT_MASK(0, 32);
42963a38260eSRichard Henderson     } else {
42973a38260eSRichard Henderson         mask = MAKE_64BIT_MASK(32, 32);
42983a38260eSRichard Henderson     }
42993a38260eSRichard Henderson     if (c) {
43003a38260eSRichard Henderson         tcg_gen_ori_i64(cpu_fpr[rd / 2], cpu_fpr[rd / 2], mask);
43013a38260eSRichard Henderson     } else {
43023a38260eSRichard Henderson         tcg_gen_andi_i64(cpu_fpr[rd / 2], cpu_fpr[rd / 2], ~mask);
43033a38260eSRichard Henderson     }
43043a38260eSRichard Henderson     gen_update_fprs_dirty(dc, rd);
43053a38260eSRichard Henderson     return advance_pc(dc);
43063a38260eSRichard Henderson }
43073a38260eSRichard Henderson 
43083a38260eSRichard Henderson TRANS(FZEROs, VIS1, do_fc, a->rd, 0)
43093a38260eSRichard Henderson TRANS(FONEs, VIS1, do_fc, a->rd, 1)
43103a38260eSRichard Henderson 
43113a38260eSRichard Henderson static bool do_dc(DisasContext *dc, int rd, int64_t c)
43123a38260eSRichard Henderson {
43133a38260eSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
43143a38260eSRichard Henderson         return true;
43153a38260eSRichard Henderson     }
43163a38260eSRichard Henderson 
43173a38260eSRichard Henderson     tcg_gen_movi_i64(cpu_fpr[rd / 2], c);
43183a38260eSRichard Henderson     gen_update_fprs_dirty(dc, rd);
43193a38260eSRichard Henderson     return advance_pc(dc);
43203a38260eSRichard Henderson }
43213a38260eSRichard Henderson 
43223a38260eSRichard Henderson TRANS(FZEROd, VIS1, do_dc, a->rd, 0)
43233a38260eSRichard Henderson TRANS(FONEd, VIS1, do_dc, a->rd, -1)
43243a38260eSRichard Henderson 
4325baf3dbf2SRichard Henderson static bool do_ff(DisasContext *dc, arg_r_r *a,
4326baf3dbf2SRichard Henderson                   void (*func)(TCGv_i32, TCGv_i32))
4327baf3dbf2SRichard Henderson {
4328baf3dbf2SRichard Henderson     TCGv_i32 tmp;
4329baf3dbf2SRichard Henderson 
4330baf3dbf2SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4331baf3dbf2SRichard Henderson         return true;
4332baf3dbf2SRichard Henderson     }
4333baf3dbf2SRichard Henderson 
4334baf3dbf2SRichard Henderson     tmp = gen_load_fpr_F(dc, a->rs);
4335baf3dbf2SRichard Henderson     func(tmp, tmp);
4336baf3dbf2SRichard Henderson     gen_store_fpr_F(dc, a->rd, tmp);
4337baf3dbf2SRichard Henderson     return advance_pc(dc);
4338baf3dbf2SRichard Henderson }
4339baf3dbf2SRichard Henderson 
4340baf3dbf2SRichard Henderson TRANS(FMOVs, ALL, do_ff, a, gen_op_fmovs)
4341baf3dbf2SRichard Henderson TRANS(FNEGs, ALL, do_ff, a, gen_op_fnegs)
4342baf3dbf2SRichard Henderson TRANS(FABSs, ALL, do_ff, a, gen_op_fabss)
4343baf3dbf2SRichard Henderson TRANS(FSRCs, VIS1, do_ff, a, tcg_gen_mov_i32)
4344baf3dbf2SRichard Henderson TRANS(FNOTs, VIS1, do_ff, a, tcg_gen_not_i32)
4345baf3dbf2SRichard Henderson 
43462f722641SRichard Henderson static bool do_fd(DisasContext *dc, arg_r_r *a,
43472f722641SRichard Henderson                   void (*func)(TCGv_i32, TCGv_i64))
43482f722641SRichard Henderson {
43492f722641SRichard Henderson     TCGv_i32 dst;
43502f722641SRichard Henderson     TCGv_i64 src;
43512f722641SRichard Henderson 
43522f722641SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
43532f722641SRichard Henderson         return true;
43542f722641SRichard Henderson     }
43552f722641SRichard Henderson 
43562f722641SRichard Henderson     dst = gen_dest_fpr_F(dc);
43572f722641SRichard Henderson     src = gen_load_fpr_D(dc, a->rs);
43582f722641SRichard Henderson     func(dst, src);
43592f722641SRichard Henderson     gen_store_fpr_F(dc, a->rd, dst);
43602f722641SRichard Henderson     return advance_pc(dc);
43612f722641SRichard Henderson }
43622f722641SRichard Henderson 
43632f722641SRichard Henderson TRANS(FPACK16, VIS1, do_fd, a, gen_op_fpack16)
43642f722641SRichard Henderson TRANS(FPACKFIX, VIS1, do_fd, a, gen_op_fpackfix)
43652f722641SRichard Henderson 
4366119cb94fSRichard Henderson static bool do_env_ff(DisasContext *dc, arg_r_r *a,
4367119cb94fSRichard Henderson                       void (*func)(TCGv_i32, TCGv_env, TCGv_i32))
4368119cb94fSRichard Henderson {
4369119cb94fSRichard Henderson     TCGv_i32 tmp;
4370119cb94fSRichard Henderson 
4371119cb94fSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4372119cb94fSRichard Henderson         return true;
4373119cb94fSRichard Henderson     }
4374119cb94fSRichard Henderson 
4375119cb94fSRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
4376119cb94fSRichard Henderson     tmp = gen_load_fpr_F(dc, a->rs);
4377119cb94fSRichard Henderson     func(tmp, tcg_env, tmp);
4378119cb94fSRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
4379119cb94fSRichard Henderson     gen_store_fpr_F(dc, a->rd, tmp);
4380119cb94fSRichard Henderson     return advance_pc(dc);
4381119cb94fSRichard Henderson }
4382119cb94fSRichard Henderson 
4383119cb94fSRichard Henderson TRANS(FSQRTs, ALL, do_env_ff, a, gen_helper_fsqrts)
4384119cb94fSRichard Henderson TRANS(FiTOs, ALL, do_env_ff, a, gen_helper_fitos)
4385119cb94fSRichard Henderson TRANS(FsTOi, ALL, do_env_ff, a, gen_helper_fstoi)
4386119cb94fSRichard Henderson 
43878c94bcd8SRichard Henderson static bool do_env_fd(DisasContext *dc, arg_r_r *a,
43888c94bcd8SRichard Henderson                       void (*func)(TCGv_i32, TCGv_env, TCGv_i64))
43898c94bcd8SRichard Henderson {
43908c94bcd8SRichard Henderson     TCGv_i32 dst;
43918c94bcd8SRichard Henderson     TCGv_i64 src;
43928c94bcd8SRichard Henderson 
43938c94bcd8SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
43948c94bcd8SRichard Henderson         return true;
43958c94bcd8SRichard Henderson     }
43968c94bcd8SRichard Henderson 
43978c94bcd8SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
43988c94bcd8SRichard Henderson     dst = gen_dest_fpr_F(dc);
43998c94bcd8SRichard Henderson     src = gen_load_fpr_D(dc, a->rs);
44008c94bcd8SRichard Henderson     func(dst, tcg_env, src);
44018c94bcd8SRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
44028c94bcd8SRichard Henderson     gen_store_fpr_F(dc, a->rd, dst);
44038c94bcd8SRichard Henderson     return advance_pc(dc);
44048c94bcd8SRichard Henderson }
44058c94bcd8SRichard Henderson 
44068c94bcd8SRichard Henderson TRANS(FdTOs, ALL, do_env_fd, a, gen_helper_fdtos)
44078c94bcd8SRichard Henderson TRANS(FdTOi, ALL, do_env_fd, a, gen_helper_fdtoi)
44088c94bcd8SRichard Henderson TRANS(FxTOs, 64, do_env_fd, a, gen_helper_fxtos)
44098c94bcd8SRichard Henderson 
4410c6d83e4fSRichard Henderson static bool do_dd(DisasContext *dc, arg_r_r *a,
4411c6d83e4fSRichard Henderson                   void (*func)(TCGv_i64, TCGv_i64))
4412c6d83e4fSRichard Henderson {
4413c6d83e4fSRichard Henderson     TCGv_i64 dst, src;
4414c6d83e4fSRichard Henderson 
4415c6d83e4fSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4416c6d83e4fSRichard Henderson         return true;
4417c6d83e4fSRichard Henderson     }
4418c6d83e4fSRichard Henderson 
4419c6d83e4fSRichard Henderson     dst = gen_dest_fpr_D(dc, a->rd);
4420c6d83e4fSRichard Henderson     src = gen_load_fpr_D(dc, a->rs);
4421c6d83e4fSRichard Henderson     func(dst, src);
4422c6d83e4fSRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
4423c6d83e4fSRichard Henderson     return advance_pc(dc);
4424c6d83e4fSRichard Henderson }
4425c6d83e4fSRichard Henderson 
4426c6d83e4fSRichard Henderson TRANS(FMOVd, 64, do_dd, a, gen_op_fmovd)
4427c6d83e4fSRichard Henderson TRANS(FNEGd, 64, do_dd, a, gen_op_fnegd)
4428c6d83e4fSRichard Henderson TRANS(FABSd, 64, do_dd, a, gen_op_fabsd)
4429c6d83e4fSRichard Henderson TRANS(FSRCd, VIS1, do_dd, a, tcg_gen_mov_i64)
4430c6d83e4fSRichard Henderson TRANS(FNOTd, VIS1, do_dd, a, tcg_gen_not_i64)
4431c6d83e4fSRichard Henderson 
44328aa418b3SRichard Henderson static bool do_env_dd(DisasContext *dc, arg_r_r *a,
44338aa418b3SRichard Henderson                       void (*func)(TCGv_i64, TCGv_env, TCGv_i64))
44348aa418b3SRichard Henderson {
44358aa418b3SRichard Henderson     TCGv_i64 dst, src;
44368aa418b3SRichard Henderson 
44378aa418b3SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
44388aa418b3SRichard Henderson         return true;
44398aa418b3SRichard Henderson     }
44408aa418b3SRichard Henderson 
44418aa418b3SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
44428aa418b3SRichard Henderson     dst = gen_dest_fpr_D(dc, a->rd);
44438aa418b3SRichard Henderson     src = gen_load_fpr_D(dc, a->rs);
44448aa418b3SRichard Henderson     func(dst, tcg_env, src);
44458aa418b3SRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
44468aa418b3SRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
44478aa418b3SRichard Henderson     return advance_pc(dc);
44488aa418b3SRichard Henderson }
44498aa418b3SRichard Henderson 
44508aa418b3SRichard Henderson TRANS(FSQRTd, ALL, do_env_dd, a, gen_helper_fsqrtd)
44518aa418b3SRichard Henderson TRANS(FxTOd, 64, do_env_dd, a, gen_helper_fxtod)
44528aa418b3SRichard Henderson TRANS(FdTOx, 64, do_env_dd, a, gen_helper_fdtox)
44538aa418b3SRichard Henderson 
4454199d43efSRichard Henderson static bool do_env_df(DisasContext *dc, arg_r_r *a,
4455199d43efSRichard Henderson                       void (*func)(TCGv_i64, TCGv_env, TCGv_i32))
4456199d43efSRichard Henderson {
4457199d43efSRichard Henderson     TCGv_i64 dst;
4458199d43efSRichard Henderson     TCGv_i32 src;
4459199d43efSRichard Henderson 
4460199d43efSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4461199d43efSRichard Henderson         return true;
4462199d43efSRichard Henderson     }
4463199d43efSRichard Henderson 
4464199d43efSRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
4465199d43efSRichard Henderson     dst = gen_dest_fpr_D(dc, a->rd);
4466199d43efSRichard Henderson     src = gen_load_fpr_F(dc, a->rs);
4467199d43efSRichard Henderson     func(dst, tcg_env, src);
4468199d43efSRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
4469199d43efSRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
4470199d43efSRichard Henderson     return advance_pc(dc);
4471199d43efSRichard Henderson }
4472199d43efSRichard Henderson 
4473199d43efSRichard Henderson TRANS(FiTOd, ALL, do_env_df, a, gen_helper_fitod)
4474199d43efSRichard Henderson TRANS(FsTOd, ALL, do_env_df, a, gen_helper_fstod)
4475199d43efSRichard Henderson TRANS(FsTOx, 64, do_env_df, a, gen_helper_fstox)
4476199d43efSRichard Henderson 
4477f4e18df5SRichard Henderson static bool trans_FMOVq(DisasContext *dc, arg_FMOVq *a)
4478f4e18df5SRichard Henderson {
4479f4e18df5SRichard Henderson     int rd, rs;
4480f4e18df5SRichard Henderson 
4481f4e18df5SRichard Henderson     if (!avail_64(dc)) {
4482f4e18df5SRichard Henderson         return false;
4483f4e18df5SRichard Henderson     }
4484f4e18df5SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4485f4e18df5SRichard Henderson         return true;
4486f4e18df5SRichard Henderson     }
4487f4e18df5SRichard Henderson     if (gen_trap_float128(dc)) {
4488f4e18df5SRichard Henderson         return true;
4489f4e18df5SRichard Henderson     }
4490f4e18df5SRichard Henderson 
4491f4e18df5SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
4492f4e18df5SRichard Henderson     rd = QFPREG(a->rd);
4493f4e18df5SRichard Henderson     rs = QFPREG(a->rs);
4494f4e18df5SRichard Henderson     tcg_gen_mov_i64(cpu_fpr[rd / 2], cpu_fpr[rs / 2]);
4495f4e18df5SRichard Henderson     tcg_gen_mov_i64(cpu_fpr[rd / 2 + 1], cpu_fpr[rs / 2 + 1]);
4496f4e18df5SRichard Henderson     gen_update_fprs_dirty(dc, rd);
4497f4e18df5SRichard Henderson     return advance_pc(dc);
4498f4e18df5SRichard Henderson }
4499f4e18df5SRichard Henderson 
4500f4e18df5SRichard Henderson static bool do_qq(DisasContext *dc, arg_r_r *a,
4501f4e18df5SRichard Henderson                   void (*func)(TCGv_env))
4502f4e18df5SRichard Henderson {
4503f4e18df5SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4504f4e18df5SRichard Henderson         return true;
4505f4e18df5SRichard Henderson     }
4506f4e18df5SRichard Henderson     if (gen_trap_float128(dc)) {
4507f4e18df5SRichard Henderson         return true;
4508f4e18df5SRichard Henderson     }
4509f4e18df5SRichard Henderson 
4510f4e18df5SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
4511f4e18df5SRichard Henderson     gen_op_load_fpr_QT1(QFPREG(a->rs));
4512f4e18df5SRichard Henderson     func(tcg_env);
4513f4e18df5SRichard Henderson     gen_op_store_QT0_fpr(QFPREG(a->rd));
4514f4e18df5SRichard Henderson     gen_update_fprs_dirty(dc, QFPREG(a->rd));
4515f4e18df5SRichard Henderson     return advance_pc(dc);
4516f4e18df5SRichard Henderson }
4517f4e18df5SRichard Henderson 
4518f4e18df5SRichard Henderson TRANS(FNEGq, 64, do_qq, a, gen_helper_fnegq)
4519f4e18df5SRichard Henderson TRANS(FABSq, 64, do_qq, a, gen_helper_fabsq)
4520f4e18df5SRichard Henderson 
4521c995216bSRichard Henderson static bool do_env_qq(DisasContext *dc, arg_r_r *a,
4522c995216bSRichard Henderson                        void (*func)(TCGv_env))
4523c995216bSRichard Henderson {
4524c995216bSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4525c995216bSRichard Henderson         return true;
4526c995216bSRichard Henderson     }
4527c995216bSRichard Henderson     if (gen_trap_float128(dc)) {
4528c995216bSRichard Henderson         return true;
4529c995216bSRichard Henderson     }
4530c995216bSRichard Henderson 
4531c995216bSRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
4532c995216bSRichard Henderson     gen_op_load_fpr_QT1(QFPREG(a->rs));
4533c995216bSRichard Henderson     func(tcg_env);
4534c995216bSRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
4535c995216bSRichard Henderson     gen_op_store_QT0_fpr(QFPREG(a->rd));
4536c995216bSRichard Henderson     gen_update_fprs_dirty(dc, QFPREG(a->rd));
4537c995216bSRichard Henderson     return advance_pc(dc);
4538c995216bSRichard Henderson }
4539c995216bSRichard Henderson 
4540c995216bSRichard Henderson TRANS(FSQRTq, ALL, do_env_qq, a, gen_helper_fsqrtq)
4541c995216bSRichard Henderson 
4542bd9c5c42SRichard Henderson static bool do_env_fq(DisasContext *dc, arg_r_r *a,
4543bd9c5c42SRichard Henderson                       void (*func)(TCGv_i32, TCGv_env))
4544bd9c5c42SRichard Henderson {
4545bd9c5c42SRichard Henderson     TCGv_i32 dst;
4546bd9c5c42SRichard Henderson 
4547bd9c5c42SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4548bd9c5c42SRichard Henderson         return true;
4549bd9c5c42SRichard Henderson     }
4550bd9c5c42SRichard Henderson     if (gen_trap_float128(dc)) {
4551bd9c5c42SRichard Henderson         return true;
4552bd9c5c42SRichard Henderson     }
4553bd9c5c42SRichard Henderson 
4554bd9c5c42SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
4555bd9c5c42SRichard Henderson     gen_op_load_fpr_QT1(QFPREG(a->rs));
4556bd9c5c42SRichard Henderson     dst = gen_dest_fpr_F(dc);
4557bd9c5c42SRichard Henderson     func(dst, tcg_env);
4558bd9c5c42SRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
4559bd9c5c42SRichard Henderson     gen_store_fpr_F(dc, a->rd, dst);
4560bd9c5c42SRichard Henderson     return advance_pc(dc);
4561bd9c5c42SRichard Henderson }
4562bd9c5c42SRichard Henderson 
4563bd9c5c42SRichard Henderson TRANS(FqTOs, ALL, do_env_fq, a, gen_helper_fqtos)
4564bd9c5c42SRichard Henderson TRANS(FqTOi, ALL, do_env_fq, a, gen_helper_fqtoi)
4565bd9c5c42SRichard Henderson 
45661617586fSRichard Henderson static bool do_env_dq(DisasContext *dc, arg_r_r *a,
45671617586fSRichard Henderson                       void (*func)(TCGv_i64, TCGv_env))
45681617586fSRichard Henderson {
45691617586fSRichard Henderson     TCGv_i64 dst;
45701617586fSRichard Henderson 
45711617586fSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
45721617586fSRichard Henderson         return true;
45731617586fSRichard Henderson     }
45741617586fSRichard Henderson     if (gen_trap_float128(dc)) {
45751617586fSRichard Henderson         return true;
45761617586fSRichard Henderson     }
45771617586fSRichard Henderson 
45781617586fSRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
45791617586fSRichard Henderson     gen_op_load_fpr_QT1(QFPREG(a->rs));
45801617586fSRichard Henderson     dst = gen_dest_fpr_D(dc, a->rd);
45811617586fSRichard Henderson     func(dst, tcg_env);
45821617586fSRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
45831617586fSRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
45841617586fSRichard Henderson     return advance_pc(dc);
45851617586fSRichard Henderson }
45861617586fSRichard Henderson 
45871617586fSRichard Henderson TRANS(FqTOd, ALL, do_env_dq, a, gen_helper_fqtod)
45881617586fSRichard Henderson TRANS(FqTOx, 64, do_env_dq, a, gen_helper_fqtox)
45891617586fSRichard Henderson 
459013ebcc77SRichard Henderson static bool do_env_qf(DisasContext *dc, arg_r_r *a,
459113ebcc77SRichard Henderson                       void (*func)(TCGv_env, TCGv_i32))
459213ebcc77SRichard Henderson {
459313ebcc77SRichard Henderson     TCGv_i32 src;
459413ebcc77SRichard Henderson 
459513ebcc77SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
459613ebcc77SRichard Henderson         return true;
459713ebcc77SRichard Henderson     }
459813ebcc77SRichard Henderson     if (gen_trap_float128(dc)) {
459913ebcc77SRichard Henderson         return true;
460013ebcc77SRichard Henderson     }
460113ebcc77SRichard Henderson 
460213ebcc77SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
460313ebcc77SRichard Henderson     src = gen_load_fpr_F(dc, a->rs);
460413ebcc77SRichard Henderson     func(tcg_env, src);
460513ebcc77SRichard Henderson     gen_op_store_QT0_fpr(QFPREG(a->rd));
460613ebcc77SRichard Henderson     gen_update_fprs_dirty(dc, QFPREG(a->rd));
460713ebcc77SRichard Henderson     return advance_pc(dc);
460813ebcc77SRichard Henderson }
460913ebcc77SRichard Henderson 
461013ebcc77SRichard Henderson TRANS(FiTOq, ALL, do_env_qf, a, gen_helper_fitoq)
461113ebcc77SRichard Henderson TRANS(FsTOq, ALL, do_env_qf, a, gen_helper_fstoq)
461213ebcc77SRichard Henderson 
46137b8e3e1aSRichard Henderson static bool do_env_qd(DisasContext *dc, arg_r_r *a,
46147b8e3e1aSRichard Henderson                       void (*func)(TCGv_env, TCGv_i64))
46157b8e3e1aSRichard Henderson {
46167b8e3e1aSRichard Henderson     TCGv_i64 src;
46177b8e3e1aSRichard Henderson 
46187b8e3e1aSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
46197b8e3e1aSRichard Henderson         return true;
46207b8e3e1aSRichard Henderson     }
46217b8e3e1aSRichard Henderson     if (gen_trap_float128(dc)) {
46227b8e3e1aSRichard Henderson         return true;
46237b8e3e1aSRichard Henderson     }
46247b8e3e1aSRichard Henderson 
46257b8e3e1aSRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
46267b8e3e1aSRichard Henderson     src = gen_load_fpr_D(dc, a->rs);
46277b8e3e1aSRichard Henderson     func(tcg_env, src);
46287b8e3e1aSRichard Henderson     gen_op_store_QT0_fpr(QFPREG(a->rd));
46297b8e3e1aSRichard Henderson     gen_update_fprs_dirty(dc, QFPREG(a->rd));
46307b8e3e1aSRichard Henderson     return advance_pc(dc);
46317b8e3e1aSRichard Henderson }
46327b8e3e1aSRichard Henderson 
46337b8e3e1aSRichard Henderson TRANS(FdTOq, ALL, do_env_qd, a, gen_helper_fdtoq)
46347b8e3e1aSRichard Henderson TRANS(FxTOq, 64, do_env_qd, a, gen_helper_fxtoq)
46357b8e3e1aSRichard Henderson 
46367f10b52fSRichard Henderson static bool do_fff(DisasContext *dc, arg_r_r_r *a,
46377f10b52fSRichard Henderson                    void (*func)(TCGv_i32, TCGv_i32, TCGv_i32))
46387f10b52fSRichard Henderson {
46397f10b52fSRichard Henderson     TCGv_i32 src1, src2;
46407f10b52fSRichard Henderson 
46417f10b52fSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
46427f10b52fSRichard Henderson         return true;
46437f10b52fSRichard Henderson     }
46447f10b52fSRichard Henderson 
46457f10b52fSRichard Henderson     src1 = gen_load_fpr_F(dc, a->rs1);
46467f10b52fSRichard Henderson     src2 = gen_load_fpr_F(dc, a->rs2);
46477f10b52fSRichard Henderson     func(src1, src1, src2);
46487f10b52fSRichard Henderson     gen_store_fpr_F(dc, a->rd, src1);
46497f10b52fSRichard Henderson     return advance_pc(dc);
46507f10b52fSRichard Henderson }
46517f10b52fSRichard Henderson 
46527f10b52fSRichard Henderson TRANS(FPADD16s, VIS1, do_fff, a, tcg_gen_vec_add16_i32)
46537f10b52fSRichard Henderson TRANS(FPADD32s, VIS1, do_fff, a, tcg_gen_add_i32)
46547f10b52fSRichard Henderson TRANS(FPSUB16s, VIS1, do_fff, a, tcg_gen_vec_sub16_i32)
46557f10b52fSRichard Henderson TRANS(FPSUB32s, VIS1, do_fff, a, tcg_gen_sub_i32)
46567f10b52fSRichard Henderson TRANS(FNORs, VIS1, do_fff, a, tcg_gen_nor_i32)
46577f10b52fSRichard Henderson TRANS(FANDNOTs, VIS1, do_fff, a, tcg_gen_andc_i32)
46587f10b52fSRichard Henderson TRANS(FXORs, VIS1, do_fff, a, tcg_gen_xor_i32)
46597f10b52fSRichard Henderson TRANS(FNANDs, VIS1, do_fff, a, tcg_gen_nand_i32)
46607f10b52fSRichard Henderson TRANS(FANDs, VIS1, do_fff, a, tcg_gen_and_i32)
46617f10b52fSRichard Henderson TRANS(FXNORs, VIS1, do_fff, a, tcg_gen_eqv_i32)
46627f10b52fSRichard Henderson TRANS(FORNOTs, VIS1, do_fff, a, tcg_gen_orc_i32)
46637f10b52fSRichard Henderson TRANS(FORs, VIS1, do_fff, a, tcg_gen_or_i32)
46647f10b52fSRichard Henderson 
4665c1514961SRichard Henderson static bool do_env_fff(DisasContext *dc, arg_r_r_r *a,
4666c1514961SRichard Henderson                        void (*func)(TCGv_i32, TCGv_env, TCGv_i32, TCGv_i32))
4667c1514961SRichard Henderson {
4668c1514961SRichard Henderson     TCGv_i32 src1, src2;
4669c1514961SRichard Henderson 
4670c1514961SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4671c1514961SRichard Henderson         return true;
4672c1514961SRichard Henderson     }
4673c1514961SRichard Henderson 
4674c1514961SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
4675c1514961SRichard Henderson     src1 = gen_load_fpr_F(dc, a->rs1);
4676c1514961SRichard Henderson     src2 = gen_load_fpr_F(dc, a->rs2);
4677c1514961SRichard Henderson     func(src1, tcg_env, src1, src2);
4678c1514961SRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
4679c1514961SRichard Henderson     gen_store_fpr_F(dc, a->rd, src1);
4680c1514961SRichard Henderson     return advance_pc(dc);
4681c1514961SRichard Henderson }
4682c1514961SRichard Henderson 
4683c1514961SRichard Henderson TRANS(FADDs, ALL, do_env_fff, a, gen_helper_fadds)
4684c1514961SRichard Henderson TRANS(FSUBs, ALL, do_env_fff, a, gen_helper_fsubs)
4685c1514961SRichard Henderson TRANS(FMULs, ALL, do_env_fff, a, gen_helper_fmuls)
4686c1514961SRichard Henderson TRANS(FDIVs, ALL, do_env_fff, a, gen_helper_fdivs)
4687c1514961SRichard Henderson 
4688e06c9f83SRichard Henderson static bool do_ddd(DisasContext *dc, arg_r_r_r *a,
4689e06c9f83SRichard Henderson                    void (*func)(TCGv_i64, TCGv_i64, TCGv_i64))
4690e06c9f83SRichard Henderson {
4691e06c9f83SRichard Henderson     TCGv_i64 dst, src1, src2;
4692e06c9f83SRichard Henderson 
4693e06c9f83SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4694e06c9f83SRichard Henderson         return true;
4695e06c9f83SRichard Henderson     }
4696e06c9f83SRichard Henderson 
4697e06c9f83SRichard Henderson     dst = gen_dest_fpr_D(dc, a->rd);
4698e06c9f83SRichard Henderson     src1 = gen_load_fpr_D(dc, a->rs1);
4699e06c9f83SRichard Henderson     src2 = gen_load_fpr_D(dc, a->rs2);
4700e06c9f83SRichard Henderson     func(dst, src1, src2);
4701e06c9f83SRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
4702e06c9f83SRichard Henderson     return advance_pc(dc);
4703e06c9f83SRichard Henderson }
4704e06c9f83SRichard Henderson 
4705e06c9f83SRichard Henderson TRANS(FMUL8x16, VIS1, do_ddd, a, gen_helper_fmul8x16)
4706e06c9f83SRichard Henderson TRANS(FMUL8x16AU, VIS1, do_ddd, a, gen_helper_fmul8x16au)
4707e06c9f83SRichard Henderson TRANS(FMUL8x16AL, VIS1, do_ddd, a, gen_helper_fmul8x16al)
4708e06c9f83SRichard Henderson TRANS(FMUL8SUx16, VIS1, do_ddd, a, gen_helper_fmul8sux16)
4709e06c9f83SRichard Henderson TRANS(FMUL8ULx16, VIS1, do_ddd, a, gen_helper_fmul8ulx16)
4710e06c9f83SRichard Henderson TRANS(FMULD8SUx16, VIS1, do_ddd, a, gen_helper_fmuld8sux16)
4711e06c9f83SRichard Henderson TRANS(FMULD8ULx16, VIS1, do_ddd, a, gen_helper_fmuld8ulx16)
4712e06c9f83SRichard Henderson TRANS(FPMERGE, VIS1, do_ddd, a, gen_helper_fpmerge)
4713e06c9f83SRichard Henderson TRANS(FEXPAND, VIS1, do_ddd, a, gen_helper_fexpand)
4714e06c9f83SRichard Henderson 
4715e06c9f83SRichard Henderson TRANS(FPADD16, VIS1, do_ddd, a, tcg_gen_vec_add16_i64)
4716e06c9f83SRichard Henderson TRANS(FPADD32, VIS1, do_ddd, a, tcg_gen_vec_add32_i64)
4717e06c9f83SRichard Henderson TRANS(FPSUB16, VIS1, do_ddd, a, tcg_gen_vec_sub16_i64)
4718e06c9f83SRichard Henderson TRANS(FPSUB32, VIS1, do_ddd, a, tcg_gen_vec_sub32_i64)
4719e06c9f83SRichard Henderson TRANS(FNORd, VIS1, do_ddd, a, tcg_gen_nor_i64)
4720e06c9f83SRichard Henderson TRANS(FANDNOTd, VIS1, do_ddd, a, tcg_gen_andc_i64)
4721e06c9f83SRichard Henderson TRANS(FXORd, VIS1, do_ddd, a, tcg_gen_xor_i64)
4722e06c9f83SRichard Henderson TRANS(FNANDd, VIS1, do_ddd, a, tcg_gen_nand_i64)
4723e06c9f83SRichard Henderson TRANS(FANDd, VIS1, do_ddd, a, tcg_gen_and_i64)
4724e06c9f83SRichard Henderson TRANS(FXNORd, VIS1, do_ddd, a, tcg_gen_eqv_i64)
4725e06c9f83SRichard Henderson TRANS(FORNOTd, VIS1, do_ddd, a, tcg_gen_orc_i64)
4726e06c9f83SRichard Henderson TRANS(FORd, VIS1, do_ddd, a, tcg_gen_or_i64)
4727e06c9f83SRichard Henderson 
47284b6edc0aSRichard Henderson TRANS(FPACK32, VIS1, do_ddd, a, gen_op_fpack32)
47294b6edc0aSRichard Henderson TRANS(FALIGNDATAg, VIS1, do_ddd, a, gen_op_faligndata)
47304b6edc0aSRichard Henderson TRANS(BSHUFFLE, VIS2, do_ddd, a, gen_op_bshuffle)
47314b6edc0aSRichard Henderson 
4732e2fa6bd1SRichard Henderson static bool do_rdd(DisasContext *dc, arg_r_r_r *a,
4733e2fa6bd1SRichard Henderson                    void (*func)(TCGv, TCGv_i64, TCGv_i64))
4734e2fa6bd1SRichard Henderson {
4735e2fa6bd1SRichard Henderson     TCGv_i64 src1, src2;
4736e2fa6bd1SRichard Henderson     TCGv dst;
4737e2fa6bd1SRichard Henderson 
4738e2fa6bd1SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4739e2fa6bd1SRichard Henderson         return true;
4740e2fa6bd1SRichard Henderson     }
4741e2fa6bd1SRichard Henderson 
4742e2fa6bd1SRichard Henderson     dst = gen_dest_gpr(dc, a->rd);
4743e2fa6bd1SRichard Henderson     src1 = gen_load_fpr_D(dc, a->rs1);
4744e2fa6bd1SRichard Henderson     src2 = gen_load_fpr_D(dc, a->rs2);
4745e2fa6bd1SRichard Henderson     func(dst, src1, src2);
4746e2fa6bd1SRichard Henderson     gen_store_gpr(dc, a->rd, dst);
4747e2fa6bd1SRichard Henderson     return advance_pc(dc);
4748e2fa6bd1SRichard Henderson }
4749e2fa6bd1SRichard Henderson 
4750e2fa6bd1SRichard Henderson TRANS(FPCMPLE16, VIS1, do_rdd, a, gen_helper_fcmple16)
4751e2fa6bd1SRichard Henderson TRANS(FPCMPNE16, VIS1, do_rdd, a, gen_helper_fcmpne16)
4752e2fa6bd1SRichard Henderson TRANS(FPCMPGT16, VIS1, do_rdd, a, gen_helper_fcmpgt16)
4753e2fa6bd1SRichard Henderson TRANS(FPCMPEQ16, VIS1, do_rdd, a, gen_helper_fcmpeq16)
4754e2fa6bd1SRichard Henderson 
4755e2fa6bd1SRichard Henderson TRANS(FPCMPLE32, VIS1, do_rdd, a, gen_helper_fcmple32)
4756e2fa6bd1SRichard Henderson TRANS(FPCMPNE32, VIS1, do_rdd, a, gen_helper_fcmpne32)
4757e2fa6bd1SRichard Henderson TRANS(FPCMPGT32, VIS1, do_rdd, a, gen_helper_fcmpgt32)
4758e2fa6bd1SRichard Henderson TRANS(FPCMPEQ32, VIS1, do_rdd, a, gen_helper_fcmpeq32)
4759e2fa6bd1SRichard Henderson 
4760f2a59b0aSRichard Henderson static bool do_env_ddd(DisasContext *dc, arg_r_r_r *a,
4761f2a59b0aSRichard Henderson                        void (*func)(TCGv_i64, TCGv_env, TCGv_i64, TCGv_i64))
4762f2a59b0aSRichard Henderson {
4763f2a59b0aSRichard Henderson     TCGv_i64 dst, src1, src2;
4764f2a59b0aSRichard Henderson 
4765f2a59b0aSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4766f2a59b0aSRichard Henderson         return true;
4767f2a59b0aSRichard Henderson     }
4768f2a59b0aSRichard Henderson 
4769f2a59b0aSRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
4770f2a59b0aSRichard Henderson     dst = gen_dest_fpr_D(dc, a->rd);
4771f2a59b0aSRichard Henderson     src1 = gen_load_fpr_D(dc, a->rs1);
4772f2a59b0aSRichard Henderson     src2 = gen_load_fpr_D(dc, a->rs2);
4773f2a59b0aSRichard Henderson     func(dst, tcg_env, src1, src2);
4774f2a59b0aSRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
4775f2a59b0aSRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
4776f2a59b0aSRichard Henderson     return advance_pc(dc);
4777f2a59b0aSRichard Henderson }
4778f2a59b0aSRichard Henderson 
4779f2a59b0aSRichard Henderson TRANS(FADDd, ALL, do_env_ddd, a, gen_helper_faddd)
4780f2a59b0aSRichard Henderson TRANS(FSUBd, ALL, do_env_ddd, a, gen_helper_fsubd)
4781f2a59b0aSRichard Henderson TRANS(FMULd, ALL, do_env_ddd, a, gen_helper_fmuld)
4782f2a59b0aSRichard Henderson TRANS(FDIVd, ALL, do_env_ddd, a, gen_helper_fdivd)
4783f2a59b0aSRichard Henderson 
4784ff4c711bSRichard Henderson static bool trans_FsMULd(DisasContext *dc, arg_r_r_r *a)
4785ff4c711bSRichard Henderson {
4786ff4c711bSRichard Henderson     TCGv_i64 dst;
4787ff4c711bSRichard Henderson     TCGv_i32 src1, src2;
4788ff4c711bSRichard Henderson 
4789ff4c711bSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4790ff4c711bSRichard Henderson         return true;
4791ff4c711bSRichard Henderson     }
4792ff4c711bSRichard Henderson     if (!(dc->def->features & CPU_FEATURE_FSMULD)) {
4793ff4c711bSRichard Henderson         return raise_unimpfpop(dc);
4794ff4c711bSRichard Henderson     }
4795ff4c711bSRichard Henderson 
4796ff4c711bSRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
4797ff4c711bSRichard Henderson     dst = gen_dest_fpr_D(dc, a->rd);
4798ff4c711bSRichard Henderson     src1 = gen_load_fpr_F(dc, a->rs1);
4799ff4c711bSRichard Henderson     src2 = gen_load_fpr_F(dc, a->rs2);
4800ff4c711bSRichard Henderson     gen_helper_fsmuld(dst, tcg_env, src1, src2);
4801ff4c711bSRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
4802ff4c711bSRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
4803ff4c711bSRichard Henderson     return advance_pc(dc);
4804ff4c711bSRichard Henderson }
4805ff4c711bSRichard Henderson 
4806afb04344SRichard Henderson static bool do_dddd(DisasContext *dc, arg_r_r_r *a,
4807afb04344SRichard Henderson                     void (*func)(TCGv_i64, TCGv_i64, TCGv_i64, TCGv_i64))
4808afb04344SRichard Henderson {
4809afb04344SRichard Henderson     TCGv_i64 dst, src0, src1, src2;
4810afb04344SRichard Henderson 
4811afb04344SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4812afb04344SRichard Henderson         return true;
4813afb04344SRichard Henderson     }
4814afb04344SRichard Henderson 
4815afb04344SRichard Henderson     dst  = gen_dest_fpr_D(dc, a->rd);
4816afb04344SRichard Henderson     src0 = gen_load_fpr_D(dc, a->rd);
4817afb04344SRichard Henderson     src1 = gen_load_fpr_D(dc, a->rs1);
4818afb04344SRichard Henderson     src2 = gen_load_fpr_D(dc, a->rs2);
4819afb04344SRichard Henderson     func(dst, src0, src1, src2);
4820afb04344SRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
4821afb04344SRichard Henderson     return advance_pc(dc);
4822afb04344SRichard Henderson }
4823afb04344SRichard Henderson 
4824afb04344SRichard Henderson TRANS(PDIST, VIS1, do_dddd, a, gen_helper_pdist)
4825afb04344SRichard Henderson 
4826a4056239SRichard Henderson static bool do_env_qqq(DisasContext *dc, arg_r_r_r *a,
4827a4056239SRichard Henderson                        void (*func)(TCGv_env))
4828a4056239SRichard Henderson {
4829a4056239SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4830a4056239SRichard Henderson         return true;
4831a4056239SRichard Henderson     }
4832a4056239SRichard Henderson     if (gen_trap_float128(dc)) {
4833a4056239SRichard Henderson         return true;
4834a4056239SRichard Henderson     }
4835a4056239SRichard Henderson 
4836a4056239SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
4837a4056239SRichard Henderson     gen_op_load_fpr_QT0(QFPREG(a->rs1));
4838a4056239SRichard Henderson     gen_op_load_fpr_QT1(QFPREG(a->rs2));
4839a4056239SRichard Henderson     func(tcg_env);
4840a4056239SRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
4841a4056239SRichard Henderson     gen_op_store_QT0_fpr(QFPREG(a->rd));
4842a4056239SRichard Henderson     gen_update_fprs_dirty(dc, QFPREG(a->rd));
4843a4056239SRichard Henderson     return advance_pc(dc);
4844a4056239SRichard Henderson }
4845a4056239SRichard Henderson 
4846a4056239SRichard Henderson TRANS(FADDq, ALL, do_env_qqq, a, gen_helper_faddq)
4847a4056239SRichard Henderson TRANS(FSUBq, ALL, do_env_qqq, a, gen_helper_fsubq)
4848a4056239SRichard Henderson TRANS(FMULq, ALL, do_env_qqq, a, gen_helper_fmulq)
4849a4056239SRichard Henderson TRANS(FDIVq, ALL, do_env_qqq, a, gen_helper_fdivq)
4850a4056239SRichard Henderson 
48515e3b17bbSRichard Henderson static bool trans_FdMULq(DisasContext *dc, arg_r_r_r *a)
48525e3b17bbSRichard Henderson {
48535e3b17bbSRichard Henderson     TCGv_i64 src1, src2;
48545e3b17bbSRichard Henderson 
48555e3b17bbSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
48565e3b17bbSRichard Henderson         return true;
48575e3b17bbSRichard Henderson     }
48585e3b17bbSRichard Henderson     if (gen_trap_float128(dc)) {
48595e3b17bbSRichard Henderson         return true;
48605e3b17bbSRichard Henderson     }
48615e3b17bbSRichard Henderson 
48625e3b17bbSRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
48635e3b17bbSRichard Henderson     src1 = gen_load_fpr_D(dc, a->rs1);
48645e3b17bbSRichard Henderson     src2 = gen_load_fpr_D(dc, a->rs2);
48655e3b17bbSRichard Henderson     gen_helper_fdmulq(tcg_env, src1, src2);
48665e3b17bbSRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
48675e3b17bbSRichard Henderson     gen_op_store_QT0_fpr(QFPREG(a->rd));
48685e3b17bbSRichard Henderson     gen_update_fprs_dirty(dc, QFPREG(a->rd));
48695e3b17bbSRichard Henderson     return advance_pc(dc);
48705e3b17bbSRichard Henderson }
48715e3b17bbSRichard Henderson 
4872f7ec8155SRichard Henderson static bool do_fmovr(DisasContext *dc, arg_FMOVRs *a, bool is_128,
4873f7ec8155SRichard Henderson                      void (*func)(DisasContext *, DisasCompare *, int, int))
4874f7ec8155SRichard Henderson {
4875f7ec8155SRichard Henderson     DisasCompare cmp;
4876f7ec8155SRichard Henderson 
4877f7ec8155SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4878f7ec8155SRichard Henderson         return true;
4879f7ec8155SRichard Henderson     }
4880f7ec8155SRichard Henderson     if (is_128 && gen_trap_float128(dc)) {
4881f7ec8155SRichard Henderson         return true;
4882f7ec8155SRichard Henderson     }
4883f7ec8155SRichard Henderson 
4884f7ec8155SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
4885f7ec8155SRichard Henderson     gen_compare_reg(&cmp, a->cond, gen_load_gpr(dc, a->rs1));
4886f7ec8155SRichard Henderson     func(dc, &cmp, a->rd, a->rs2);
4887f7ec8155SRichard Henderson     return advance_pc(dc);
4888f7ec8155SRichard Henderson }
4889f7ec8155SRichard Henderson 
4890f7ec8155SRichard Henderson TRANS(FMOVRs, 64, do_fmovr, a, false, gen_fmovs)
4891f7ec8155SRichard Henderson TRANS(FMOVRd, 64, do_fmovr, a, false, gen_fmovd)
4892f7ec8155SRichard Henderson TRANS(FMOVRq, 64, do_fmovr, a, true, gen_fmovq)
4893f7ec8155SRichard Henderson 
4894f7ec8155SRichard Henderson static bool do_fmovcc(DisasContext *dc, arg_FMOVscc *a, bool is_128,
4895f7ec8155SRichard Henderson                       void (*func)(DisasContext *, DisasCompare *, int, int))
4896f7ec8155SRichard Henderson {
4897f7ec8155SRichard Henderson     DisasCompare cmp;
4898f7ec8155SRichard Henderson 
4899f7ec8155SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4900f7ec8155SRichard Henderson         return true;
4901f7ec8155SRichard Henderson     }
4902f7ec8155SRichard Henderson     if (is_128 && gen_trap_float128(dc)) {
4903f7ec8155SRichard Henderson         return true;
4904f7ec8155SRichard Henderson     }
4905f7ec8155SRichard Henderson 
4906f7ec8155SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
4907f7ec8155SRichard Henderson     gen_compare(&cmp, a->cc, a->cond, dc);
4908f7ec8155SRichard Henderson     func(dc, &cmp, a->rd, a->rs2);
4909f7ec8155SRichard Henderson     return advance_pc(dc);
4910f7ec8155SRichard Henderson }
4911f7ec8155SRichard Henderson 
4912f7ec8155SRichard Henderson TRANS(FMOVscc, 64, do_fmovcc, a, false, gen_fmovs)
4913f7ec8155SRichard Henderson TRANS(FMOVdcc, 64, do_fmovcc, a, false, gen_fmovd)
4914f7ec8155SRichard Henderson TRANS(FMOVqcc, 64, do_fmovcc, a, true, gen_fmovq)
4915f7ec8155SRichard Henderson 
4916f7ec8155SRichard Henderson static bool do_fmovfcc(DisasContext *dc, arg_FMOVsfcc *a, bool is_128,
4917f7ec8155SRichard Henderson                        void (*func)(DisasContext *, DisasCompare *, int, int))
4918f7ec8155SRichard Henderson {
4919f7ec8155SRichard Henderson     DisasCompare cmp;
4920f7ec8155SRichard Henderson 
4921f7ec8155SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4922f7ec8155SRichard Henderson         return true;
4923f7ec8155SRichard Henderson     }
4924f7ec8155SRichard Henderson     if (is_128 && gen_trap_float128(dc)) {
4925f7ec8155SRichard Henderson         return true;
4926f7ec8155SRichard Henderson     }
4927f7ec8155SRichard Henderson 
4928f7ec8155SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
4929f7ec8155SRichard Henderson     gen_fcompare(&cmp, a->cc, a->cond);
4930f7ec8155SRichard Henderson     func(dc, &cmp, a->rd, a->rs2);
4931f7ec8155SRichard Henderson     return advance_pc(dc);
4932f7ec8155SRichard Henderson }
4933f7ec8155SRichard Henderson 
4934f7ec8155SRichard Henderson TRANS(FMOVsfcc, 64, do_fmovfcc, a, false, gen_fmovs)
4935f7ec8155SRichard Henderson TRANS(FMOVdfcc, 64, do_fmovfcc, a, false, gen_fmovd)
4936f7ec8155SRichard Henderson TRANS(FMOVqfcc, 64, do_fmovfcc, a, true, gen_fmovq)
4937f7ec8155SRichard Henderson 
493840f9ad21SRichard Henderson static bool do_fcmps(DisasContext *dc, arg_FCMPs *a, bool e)
493940f9ad21SRichard Henderson {
494040f9ad21SRichard Henderson     TCGv_i32 src1, src2;
494140f9ad21SRichard Henderson 
494240f9ad21SRichard Henderson     if (avail_32(dc) && a->cc != 0) {
494340f9ad21SRichard Henderson         return false;
494440f9ad21SRichard Henderson     }
494540f9ad21SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
494640f9ad21SRichard Henderson         return true;
494740f9ad21SRichard Henderson     }
494840f9ad21SRichard Henderson 
494940f9ad21SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
495040f9ad21SRichard Henderson     src1 = gen_load_fpr_F(dc, a->rs1);
495140f9ad21SRichard Henderson     src2 = gen_load_fpr_F(dc, a->rs2);
495240f9ad21SRichard Henderson     if (e) {
495340f9ad21SRichard Henderson         gen_op_fcmpes(a->cc, src1, src2);
495440f9ad21SRichard Henderson     } else {
495540f9ad21SRichard Henderson         gen_op_fcmps(a->cc, src1, src2);
495640f9ad21SRichard Henderson     }
495740f9ad21SRichard Henderson     return advance_pc(dc);
495840f9ad21SRichard Henderson }
495940f9ad21SRichard Henderson 
496040f9ad21SRichard Henderson TRANS(FCMPs, ALL, do_fcmps, a, false)
496140f9ad21SRichard Henderson TRANS(FCMPEs, ALL, do_fcmps, a, true)
496240f9ad21SRichard Henderson 
496340f9ad21SRichard Henderson static bool do_fcmpd(DisasContext *dc, arg_FCMPd *a, bool e)
496440f9ad21SRichard Henderson {
496540f9ad21SRichard Henderson     TCGv_i64 src1, src2;
496640f9ad21SRichard Henderson 
496740f9ad21SRichard Henderson     if (avail_32(dc) && a->cc != 0) {
496840f9ad21SRichard Henderson         return false;
496940f9ad21SRichard Henderson     }
497040f9ad21SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
497140f9ad21SRichard Henderson         return true;
497240f9ad21SRichard Henderson     }
497340f9ad21SRichard Henderson 
497440f9ad21SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
497540f9ad21SRichard Henderson     src1 = gen_load_fpr_D(dc, a->rs1);
497640f9ad21SRichard Henderson     src2 = gen_load_fpr_D(dc, a->rs2);
497740f9ad21SRichard Henderson     if (e) {
497840f9ad21SRichard Henderson         gen_op_fcmped(a->cc, src1, src2);
497940f9ad21SRichard Henderson     } else {
498040f9ad21SRichard Henderson         gen_op_fcmpd(a->cc, src1, src2);
498140f9ad21SRichard Henderson     }
498240f9ad21SRichard Henderson     return advance_pc(dc);
498340f9ad21SRichard Henderson }
498440f9ad21SRichard Henderson 
498540f9ad21SRichard Henderson TRANS(FCMPd, ALL, do_fcmpd, a, false)
498640f9ad21SRichard Henderson TRANS(FCMPEd, ALL, do_fcmpd, a, true)
498740f9ad21SRichard Henderson 
498840f9ad21SRichard Henderson static bool do_fcmpq(DisasContext *dc, arg_FCMPq *a, bool e)
498940f9ad21SRichard Henderson {
499040f9ad21SRichard Henderson     if (avail_32(dc) && a->cc != 0) {
499140f9ad21SRichard Henderson         return false;
499240f9ad21SRichard Henderson     }
499340f9ad21SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
499440f9ad21SRichard Henderson         return true;
499540f9ad21SRichard Henderson     }
499640f9ad21SRichard Henderson     if (gen_trap_float128(dc)) {
499740f9ad21SRichard Henderson         return true;
499840f9ad21SRichard Henderson     }
499940f9ad21SRichard Henderson 
500040f9ad21SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
500140f9ad21SRichard Henderson     gen_op_load_fpr_QT0(QFPREG(a->rs1));
500240f9ad21SRichard Henderson     gen_op_load_fpr_QT1(QFPREG(a->rs2));
500340f9ad21SRichard Henderson     if (e) {
500440f9ad21SRichard Henderson         gen_op_fcmpeq(a->cc);
500540f9ad21SRichard Henderson     } else {
500640f9ad21SRichard Henderson         gen_op_fcmpq(a->cc);
500740f9ad21SRichard Henderson     }
500840f9ad21SRichard Henderson     return advance_pc(dc);
500940f9ad21SRichard Henderson }
501040f9ad21SRichard Henderson 
501140f9ad21SRichard Henderson TRANS(FCMPq, ALL, do_fcmpq, a, false)
501240f9ad21SRichard Henderson TRANS(FCMPEq, ALL, do_fcmpq, a, true)
501340f9ad21SRichard Henderson 
50146e61bc94SEmilio G. Cota static void sparc_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
5015fcf5ef2aSThomas Huth {
50166e61bc94SEmilio G. Cota     DisasContext *dc = container_of(dcbase, DisasContext, base);
5017b77af26eSRichard Henderson     CPUSPARCState *env = cpu_env(cs);
50186e61bc94SEmilio G. Cota     int bound;
5019af00be49SEmilio G. Cota 
5020af00be49SEmilio G. Cota     dc->pc = dc->base.pc_first;
50216e61bc94SEmilio G. Cota     dc->npc = (target_ulong)dc->base.tb->cs_base;
50226e61bc94SEmilio G. Cota     dc->mem_idx = dc->base.tb->flags & TB_FLAG_MMU_MASK;
5023576e1c4cSIgor Mammedov     dc->def = &env->def;
50246e61bc94SEmilio G. Cota     dc->fpu_enabled = tb_fpu_enabled(dc->base.tb->flags);
50256e61bc94SEmilio G. Cota     dc->address_mask_32bit = tb_am_enabled(dc->base.tb->flags);
5026c9b459aaSArtyom Tarasenko #ifndef CONFIG_USER_ONLY
50276e61bc94SEmilio G. Cota     dc->supervisor = (dc->base.tb->flags & TB_FLAG_SUPER) != 0;
5028c9b459aaSArtyom Tarasenko #endif
5029fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
5030fcf5ef2aSThomas Huth     dc->fprs_dirty = 0;
50316e61bc94SEmilio G. Cota     dc->asi = (dc->base.tb->flags >> TB_FLAG_ASI_SHIFT) & 0xff;
5032c9b459aaSArtyom Tarasenko #ifndef CONFIG_USER_ONLY
50336e61bc94SEmilio G. Cota     dc->hypervisor = (dc->base.tb->flags & TB_FLAG_HYPER) != 0;
5034c9b459aaSArtyom Tarasenko #endif
5035fcf5ef2aSThomas Huth #endif
50366e61bc94SEmilio G. Cota     /*
50376e61bc94SEmilio G. Cota      * if we reach a page boundary, we stop generation so that the
50386e61bc94SEmilio G. Cota      * PC of a TT_TFAULT exception is always in the right page
50396e61bc94SEmilio G. Cota      */
50406e61bc94SEmilio G. Cota     bound = -(dc->base.pc_first | TARGET_PAGE_MASK) / 4;
50416e61bc94SEmilio G. Cota     dc->base.max_insns = MIN(dc->base.max_insns, bound);
5042af00be49SEmilio G. Cota }
5043fcf5ef2aSThomas Huth 
50446e61bc94SEmilio G. Cota static void sparc_tr_tb_start(DisasContextBase *db, CPUState *cs)
50456e61bc94SEmilio G. Cota {
50466e61bc94SEmilio G. Cota }
50476e61bc94SEmilio G. Cota 
50486e61bc94SEmilio G. Cota static void sparc_tr_insn_start(DisasContextBase *dcbase, CPUState *cs)
50496e61bc94SEmilio G. Cota {
50506e61bc94SEmilio G. Cota     DisasContext *dc = container_of(dcbase, DisasContext, base);
5051633c4283SRichard Henderson     target_ulong npc = dc->npc;
50526e61bc94SEmilio G. Cota 
5053633c4283SRichard Henderson     if (npc & 3) {
5054633c4283SRichard Henderson         switch (npc) {
5055633c4283SRichard Henderson         case JUMP_PC:
5056fcf5ef2aSThomas Huth             assert(dc->jump_pc[1] == dc->pc + 4);
5057633c4283SRichard Henderson             npc = dc->jump_pc[0] | JUMP_PC;
5058633c4283SRichard Henderson             break;
5059633c4283SRichard Henderson         case DYNAMIC_PC:
5060633c4283SRichard Henderson         case DYNAMIC_PC_LOOKUP:
5061633c4283SRichard Henderson             npc = DYNAMIC_PC;
5062633c4283SRichard Henderson             break;
5063633c4283SRichard Henderson         default:
5064633c4283SRichard Henderson             g_assert_not_reached();
5065fcf5ef2aSThomas Huth         }
50666e61bc94SEmilio G. Cota     }
5067633c4283SRichard Henderson     tcg_gen_insn_start(dc->pc, npc);
5068633c4283SRichard Henderson }
5069fcf5ef2aSThomas Huth 
50706e61bc94SEmilio G. Cota static void sparc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs)
50716e61bc94SEmilio G. Cota {
50726e61bc94SEmilio G. Cota     DisasContext *dc = container_of(dcbase, DisasContext, base);
5073b77af26eSRichard Henderson     CPUSPARCState *env = cpu_env(cs);
50746e61bc94SEmilio G. Cota     unsigned int insn;
5075fcf5ef2aSThomas Huth 
50764e116893SIlya Leoshkevich     insn = translator_ldl(env, &dc->base, dc->pc);
5077af00be49SEmilio G. Cota     dc->base.pc_next += 4;
5078878cc677SRichard Henderson 
5079878cc677SRichard Henderson     if (!decode(dc, insn)) {
5080ba9c09b4SRichard Henderson         gen_exception(dc, TT_ILL_INSN);
5081878cc677SRichard Henderson     }
5082fcf5ef2aSThomas Huth 
5083af00be49SEmilio G. Cota     if (dc->base.is_jmp == DISAS_NORETURN) {
50846e61bc94SEmilio G. Cota         return;
5085c5e6ccdfSEmilio G. Cota     }
5086af00be49SEmilio G. Cota     if (dc->pc != dc->base.pc_next) {
50876e61bc94SEmilio G. Cota         dc->base.is_jmp = DISAS_TOO_MANY;
5088af00be49SEmilio G. Cota     }
50896e61bc94SEmilio G. Cota }
5090fcf5ef2aSThomas Huth 
50916e61bc94SEmilio G. Cota static void sparc_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)
50926e61bc94SEmilio G. Cota {
50936e61bc94SEmilio G. Cota     DisasContext *dc = container_of(dcbase, DisasContext, base);
5094186e7890SRichard Henderson     DisasDelayException *e, *e_next;
5095633c4283SRichard Henderson     bool may_lookup;
50966e61bc94SEmilio G. Cota 
509746bb0137SMark Cave-Ayland     switch (dc->base.is_jmp) {
509846bb0137SMark Cave-Ayland     case DISAS_NEXT:
509946bb0137SMark Cave-Ayland     case DISAS_TOO_MANY:
5100633c4283SRichard Henderson         if (((dc->pc | dc->npc) & 3) == 0) {
5101fcf5ef2aSThomas Huth             /* static PC and NPC: we can use direct chaining */
5102fcf5ef2aSThomas Huth             gen_goto_tb(dc, 0, dc->pc, dc->npc);
5103633c4283SRichard Henderson             break;
5104fcf5ef2aSThomas Huth         }
5105633c4283SRichard Henderson 
5106930f1865SRichard Henderson         may_lookup = true;
5107633c4283SRichard Henderson         if (dc->pc & 3) {
5108633c4283SRichard Henderson             switch (dc->pc) {
5109633c4283SRichard Henderson             case DYNAMIC_PC_LOOKUP:
5110633c4283SRichard Henderson                 break;
5111633c4283SRichard Henderson             case DYNAMIC_PC:
5112633c4283SRichard Henderson                 may_lookup = false;
5113633c4283SRichard Henderson                 break;
5114633c4283SRichard Henderson             default:
5115633c4283SRichard Henderson                 g_assert_not_reached();
5116633c4283SRichard Henderson             }
5117633c4283SRichard Henderson         } else {
5118633c4283SRichard Henderson             tcg_gen_movi_tl(cpu_pc, dc->pc);
5119633c4283SRichard Henderson         }
5120633c4283SRichard Henderson 
5121930f1865SRichard Henderson         if (dc->npc & 3) {
5122930f1865SRichard Henderson             switch (dc->npc) {
5123930f1865SRichard Henderson             case JUMP_PC:
5124930f1865SRichard Henderson                 gen_generic_branch(dc);
5125930f1865SRichard Henderson                 break;
5126930f1865SRichard Henderson             case DYNAMIC_PC:
5127930f1865SRichard Henderson                 may_lookup = false;
5128930f1865SRichard Henderson                 break;
5129930f1865SRichard Henderson             case DYNAMIC_PC_LOOKUP:
5130930f1865SRichard Henderson                 break;
5131930f1865SRichard Henderson             default:
5132930f1865SRichard Henderson                 g_assert_not_reached();
5133930f1865SRichard Henderson             }
5134930f1865SRichard Henderson         } else {
5135930f1865SRichard Henderson             tcg_gen_movi_tl(cpu_npc, dc->npc);
5136930f1865SRichard Henderson         }
5137633c4283SRichard Henderson         if (may_lookup) {
5138633c4283SRichard Henderson             tcg_gen_lookup_and_goto_ptr();
5139633c4283SRichard Henderson         } else {
514007ea28b4SRichard Henderson             tcg_gen_exit_tb(NULL, 0);
5141fcf5ef2aSThomas Huth         }
514246bb0137SMark Cave-Ayland         break;
514346bb0137SMark Cave-Ayland 
514446bb0137SMark Cave-Ayland     case DISAS_NORETURN:
514546bb0137SMark Cave-Ayland        break;
514646bb0137SMark Cave-Ayland 
514746bb0137SMark Cave-Ayland     case DISAS_EXIT:
514846bb0137SMark Cave-Ayland         /* Exit TB */
514946bb0137SMark Cave-Ayland         save_state(dc);
515046bb0137SMark Cave-Ayland         tcg_gen_exit_tb(NULL, 0);
515146bb0137SMark Cave-Ayland         break;
515246bb0137SMark Cave-Ayland 
515346bb0137SMark Cave-Ayland     default:
515446bb0137SMark Cave-Ayland         g_assert_not_reached();
5155fcf5ef2aSThomas Huth     }
5156186e7890SRichard Henderson 
5157186e7890SRichard Henderson     for (e = dc->delay_excp_list; e ; e = e_next) {
5158186e7890SRichard Henderson         gen_set_label(e->lab);
5159186e7890SRichard Henderson 
5160186e7890SRichard Henderson         tcg_gen_movi_tl(cpu_pc, e->pc);
5161186e7890SRichard Henderson         if (e->npc % 4 == 0) {
5162186e7890SRichard Henderson             tcg_gen_movi_tl(cpu_npc, e->npc);
5163186e7890SRichard Henderson         }
5164186e7890SRichard Henderson         gen_helper_raise_exception(tcg_env, e->excp);
5165186e7890SRichard Henderson 
5166186e7890SRichard Henderson         e_next = e->next;
5167186e7890SRichard Henderson         g_free(e);
5168186e7890SRichard Henderson     }
5169fcf5ef2aSThomas Huth }
51706e61bc94SEmilio G. Cota 
51718eb806a7SRichard Henderson static void sparc_tr_disas_log(const DisasContextBase *dcbase,
51728eb806a7SRichard Henderson                                CPUState *cpu, FILE *logfile)
51736e61bc94SEmilio G. Cota {
51748eb806a7SRichard Henderson     fprintf(logfile, "IN: %s\n", lookup_symbol(dcbase->pc_first));
51758eb806a7SRichard Henderson     target_disas(logfile, cpu, dcbase->pc_first, dcbase->tb->size);
51766e61bc94SEmilio G. Cota }
51776e61bc94SEmilio G. Cota 
51786e61bc94SEmilio G. Cota static const TranslatorOps sparc_tr_ops = {
51796e61bc94SEmilio G. Cota     .init_disas_context = sparc_tr_init_disas_context,
51806e61bc94SEmilio G. Cota     .tb_start           = sparc_tr_tb_start,
51816e61bc94SEmilio G. Cota     .insn_start         = sparc_tr_insn_start,
51826e61bc94SEmilio G. Cota     .translate_insn     = sparc_tr_translate_insn,
51836e61bc94SEmilio G. Cota     .tb_stop            = sparc_tr_tb_stop,
51846e61bc94SEmilio G. Cota     .disas_log          = sparc_tr_disas_log,
51856e61bc94SEmilio G. Cota };
51866e61bc94SEmilio G. Cota 
5187597f9b2dSRichard Henderson void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int *max_insns,
5188306c8721SRichard Henderson                            target_ulong pc, void *host_pc)
51896e61bc94SEmilio G. Cota {
51906e61bc94SEmilio G. Cota     DisasContext dc = {};
51916e61bc94SEmilio G. Cota 
5192306c8721SRichard Henderson     translator_loop(cs, tb, max_insns, pc, host_pc, &sparc_tr_ops, &dc.base);
5193fcf5ef2aSThomas Huth }
5194fcf5ef2aSThomas Huth 
519555c3ceefSRichard Henderson void sparc_tcg_init(void)
5196fcf5ef2aSThomas Huth {
5197fcf5ef2aSThomas Huth     static const char gregnames[32][4] = {
5198fcf5ef2aSThomas Huth         "g0", "g1", "g2", "g3", "g4", "g5", "g6", "g7",
5199fcf5ef2aSThomas Huth         "o0", "o1", "o2", "o3", "o4", "o5", "o6", "o7",
5200fcf5ef2aSThomas Huth         "l0", "l1", "l2", "l3", "l4", "l5", "l6", "l7",
5201fcf5ef2aSThomas Huth         "i0", "i1", "i2", "i3", "i4", "i5", "i6", "i7",
5202fcf5ef2aSThomas Huth     };
5203fcf5ef2aSThomas Huth     static const char fregnames[32][4] = {
5204fcf5ef2aSThomas Huth         "f0", "f2", "f4", "f6", "f8", "f10", "f12", "f14",
5205fcf5ef2aSThomas Huth         "f16", "f18", "f20", "f22", "f24", "f26", "f28", "f30",
5206fcf5ef2aSThomas Huth         "f32", "f34", "f36", "f38", "f40", "f42", "f44", "f46",
5207fcf5ef2aSThomas Huth         "f48", "f50", "f52", "f54", "f56", "f58", "f60", "f62",
5208fcf5ef2aSThomas Huth     };
5209fcf5ef2aSThomas Huth 
5210fcf5ef2aSThomas Huth     static const struct { TCGv *ptr; int off; const char *name; } rtl[] = {
5211fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
5212fcf5ef2aSThomas Huth         { &cpu_gsr, offsetof(CPUSPARCState, gsr), "gsr" },
52132a1905c7SRichard Henderson         { &cpu_xcc_Z, offsetof(CPUSPARCState, xcc_Z), "xcc_Z" },
52142a1905c7SRichard Henderson         { &cpu_xcc_C, offsetof(CPUSPARCState, xcc_C), "xcc_C" },
5215fcf5ef2aSThomas Huth #endif
52162a1905c7SRichard Henderson         { &cpu_cc_N, offsetof(CPUSPARCState, cc_N), "cc_N" },
52172a1905c7SRichard Henderson         { &cpu_cc_V, offsetof(CPUSPARCState, cc_V), "cc_V" },
52182a1905c7SRichard Henderson         { &cpu_icc_Z, offsetof(CPUSPARCState, icc_Z), "icc_Z" },
52192a1905c7SRichard Henderson         { &cpu_icc_C, offsetof(CPUSPARCState, icc_C), "icc_C" },
5220fcf5ef2aSThomas Huth         { &cpu_cond, offsetof(CPUSPARCState, cond), "cond" },
5221fcf5ef2aSThomas Huth         { &cpu_fsr, offsetof(CPUSPARCState, fsr), "fsr" },
5222fcf5ef2aSThomas Huth         { &cpu_pc, offsetof(CPUSPARCState, pc), "pc" },
5223fcf5ef2aSThomas Huth         { &cpu_npc, offsetof(CPUSPARCState, npc), "npc" },
5224fcf5ef2aSThomas Huth         { &cpu_y, offsetof(CPUSPARCState, y), "y" },
5225fcf5ef2aSThomas Huth         { &cpu_tbr, offsetof(CPUSPARCState, tbr), "tbr" },
5226fcf5ef2aSThomas Huth     };
5227fcf5ef2aSThomas Huth 
5228fcf5ef2aSThomas Huth     unsigned int i;
5229fcf5ef2aSThomas Huth 
5230ad75a51eSRichard Henderson     cpu_regwptr = tcg_global_mem_new_ptr(tcg_env,
5231fcf5ef2aSThomas Huth                                          offsetof(CPUSPARCState, regwptr),
5232fcf5ef2aSThomas Huth                                          "regwptr");
5233fcf5ef2aSThomas Huth 
5234fcf5ef2aSThomas Huth     for (i = 0; i < ARRAY_SIZE(rtl); ++i) {
5235ad75a51eSRichard Henderson         *rtl[i].ptr = tcg_global_mem_new(tcg_env, rtl[i].off, rtl[i].name);
5236fcf5ef2aSThomas Huth     }
5237fcf5ef2aSThomas Huth 
5238f764718dSRichard Henderson     cpu_regs[0] = NULL;
5239fcf5ef2aSThomas Huth     for (i = 1; i < 8; ++i) {
5240ad75a51eSRichard Henderson         cpu_regs[i] = tcg_global_mem_new(tcg_env,
5241fcf5ef2aSThomas Huth                                          offsetof(CPUSPARCState, gregs[i]),
5242fcf5ef2aSThomas Huth                                          gregnames[i]);
5243fcf5ef2aSThomas Huth     }
5244fcf5ef2aSThomas Huth 
5245fcf5ef2aSThomas Huth     for (i = 8; i < 32; ++i) {
5246fcf5ef2aSThomas Huth         cpu_regs[i] = tcg_global_mem_new(cpu_regwptr,
5247fcf5ef2aSThomas Huth                                          (i - 8) * sizeof(target_ulong),
5248fcf5ef2aSThomas Huth                                          gregnames[i]);
5249fcf5ef2aSThomas Huth     }
5250fcf5ef2aSThomas Huth 
5251fcf5ef2aSThomas Huth     for (i = 0; i < TARGET_DPREGS; i++) {
5252ad75a51eSRichard Henderson         cpu_fpr[i] = tcg_global_mem_new_i64(tcg_env,
5253fcf5ef2aSThomas Huth                                             offsetof(CPUSPARCState, fpr[i]),
5254fcf5ef2aSThomas Huth                                             fregnames[i]);
5255fcf5ef2aSThomas Huth     }
5256b597eedcSRichard Henderson 
5257b597eedcSRichard Henderson #ifdef TARGET_SPARC64
5258b597eedcSRichard Henderson     cpu_fprs = tcg_global_mem_new_i32(tcg_env,
5259b597eedcSRichard Henderson                                       offsetof(CPUSPARCState, fprs), "fprs");
5260b597eedcSRichard Henderson #endif
5261fcf5ef2aSThomas Huth }
5262fcf5ef2aSThomas Huth 
5263f36aaa53SRichard Henderson void sparc_restore_state_to_opc(CPUState *cs,
5264f36aaa53SRichard Henderson                                 const TranslationBlock *tb,
5265f36aaa53SRichard Henderson                                 const uint64_t *data)
5266fcf5ef2aSThomas Huth {
5267f36aaa53SRichard Henderson     SPARCCPU *cpu = SPARC_CPU(cs);
5268f36aaa53SRichard Henderson     CPUSPARCState *env = &cpu->env;
5269fcf5ef2aSThomas Huth     target_ulong pc = data[0];
5270fcf5ef2aSThomas Huth     target_ulong npc = data[1];
5271fcf5ef2aSThomas Huth 
5272fcf5ef2aSThomas Huth     env->pc = pc;
5273fcf5ef2aSThomas Huth     if (npc == DYNAMIC_PC) {
5274fcf5ef2aSThomas Huth         /* dynamic NPC: already stored */
5275fcf5ef2aSThomas Huth     } else if (npc & JUMP_PC) {
5276fcf5ef2aSThomas Huth         /* jump PC: use 'cond' and the jump targets of the translation */
5277fcf5ef2aSThomas Huth         if (env->cond) {
5278fcf5ef2aSThomas Huth             env->npc = npc & ~3;
5279fcf5ef2aSThomas Huth         } else {
5280fcf5ef2aSThomas Huth             env->npc = pc + 4;
5281fcf5ef2aSThomas Huth         }
5282fcf5ef2aSThomas Huth     } else {
5283fcf5ef2aSThomas Huth         env->npc = npc;
5284fcf5ef2aSThomas Huth     }
5285fcf5ef2aSThomas Huth }
5286