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