xref: /openbmc/qemu/target/sparc/translate.c (revision ff4c711b8d01608c4589cead0e2f650588d4b804)
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()
668aa418b3SRichard Henderson # define gen_helper_fdtox                ({ qemu_build_not_reached(); NULL; })
67e06c9f83SRichard Henderson # define gen_helper_fexpand              ({ qemu_build_not_reached(); NULL; })
68e06c9f83SRichard Henderson # define gen_helper_fmul8sux16           ({ qemu_build_not_reached(); NULL; })
69e06c9f83SRichard Henderson # define gen_helper_fmul8ulx16           ({ qemu_build_not_reached(); NULL; })
70e06c9f83SRichard Henderson # define gen_helper_fmul8x16al           ({ qemu_build_not_reached(); NULL; })
71e06c9f83SRichard Henderson # define gen_helper_fmul8x16au           ({ qemu_build_not_reached(); NULL; })
72e06c9f83SRichard Henderson # define gen_helper_fmul8x16             ({ qemu_build_not_reached(); NULL; })
73e06c9f83SRichard Henderson # define gen_helper_fmuld8sux16          ({ qemu_build_not_reached(); NULL; })
74e06c9f83SRichard Henderson # define gen_helper_fmuld8ulx16          ({ qemu_build_not_reached(); NULL; })
75e06c9f83SRichard Henderson # define gen_helper_fpmerge              ({ qemu_build_not_reached(); NULL; })
768aa418b3SRichard Henderson # define gen_helper_fxtod                ({ qemu_build_not_reached(); NULL; })
77afb04344SRichard Henderson # define gen_helper_pdist                ({ qemu_build_not_reached(); NULL; })
78da681406SRichard Henderson # define FSR_LDXFSR_MASK                        0
79da681406SRichard Henderson # define FSR_LDXFSR_OLDMASK                     0
80668bb9b7SRichard Henderson # define MAXTL_MASK                             0
81af25071cSRichard Henderson #endif
82af25071cSRichard Henderson 
83633c4283SRichard Henderson /* Dynamic PC, must exit to main loop. */
84633c4283SRichard Henderson #define DYNAMIC_PC         1
85633c4283SRichard Henderson /* Dynamic PC, one of two values according to jump_pc[T2]. */
86633c4283SRichard Henderson #define JUMP_PC            2
87633c4283SRichard Henderson /* Dynamic PC, may lookup next TB. */
88633c4283SRichard Henderson #define DYNAMIC_PC_LOOKUP  3
89fcf5ef2aSThomas Huth 
9046bb0137SMark Cave-Ayland #define DISAS_EXIT  DISAS_TARGET_0
9146bb0137SMark Cave-Ayland 
92fcf5ef2aSThomas Huth /* global register indexes */
93fcf5ef2aSThomas Huth static TCGv_ptr cpu_regwptr;
94fcf5ef2aSThomas Huth static TCGv cpu_cc_src, cpu_cc_src2, cpu_cc_dst;
95fcf5ef2aSThomas Huth static TCGv_i32 cpu_cc_op;
96fcf5ef2aSThomas Huth static TCGv_i32 cpu_psr;
97fcf5ef2aSThomas Huth static TCGv cpu_fsr, cpu_pc, cpu_npc;
98fcf5ef2aSThomas Huth static TCGv cpu_regs[32];
99fcf5ef2aSThomas Huth static TCGv cpu_y;
100fcf5ef2aSThomas Huth static TCGv cpu_tbr;
101fcf5ef2aSThomas Huth static TCGv cpu_cond;
102fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
103fcf5ef2aSThomas Huth static TCGv_i32 cpu_xcc, cpu_fprs;
104fcf5ef2aSThomas Huth static TCGv cpu_gsr;
105fcf5ef2aSThomas Huth #else
106af25071cSRichard Henderson # define cpu_fprs               ({ qemu_build_not_reached(); (TCGv)NULL; })
107af25071cSRichard Henderson # define cpu_gsr                ({ qemu_build_not_reached(); (TCGv)NULL; })
108fcf5ef2aSThomas Huth #endif
109fcf5ef2aSThomas Huth /* Floating point registers */
110fcf5ef2aSThomas Huth static TCGv_i64 cpu_fpr[TARGET_DPREGS];
111fcf5ef2aSThomas Huth 
112af25071cSRichard Henderson #define env_field_offsetof(X)     offsetof(CPUSPARCState, X)
113af25071cSRichard Henderson #ifdef TARGET_SPARC64
114cd6269f7SRichard Henderson # define env32_field_offsetof(X)  ({ qemu_build_not_reached(); 0; })
115af25071cSRichard Henderson # define env64_field_offsetof(X)  env_field_offsetof(X)
116af25071cSRichard Henderson #else
117cd6269f7SRichard Henderson # define env32_field_offsetof(X)  env_field_offsetof(X)
118af25071cSRichard Henderson # define env64_field_offsetof(X)  ({ qemu_build_not_reached(); 0; })
119af25071cSRichard Henderson #endif
120af25071cSRichard Henderson 
121186e7890SRichard Henderson typedef struct DisasDelayException {
122186e7890SRichard Henderson     struct DisasDelayException *next;
123186e7890SRichard Henderson     TCGLabel *lab;
124186e7890SRichard Henderson     TCGv_i32 excp;
125186e7890SRichard Henderson     /* Saved state at parent insn. */
126186e7890SRichard Henderson     target_ulong pc;
127186e7890SRichard Henderson     target_ulong npc;
128186e7890SRichard Henderson } DisasDelayException;
129186e7890SRichard Henderson 
130fcf5ef2aSThomas Huth typedef struct DisasContext {
131af00be49SEmilio G. Cota     DisasContextBase base;
132fcf5ef2aSThomas Huth     target_ulong pc;    /* current Program Counter: integer or DYNAMIC_PC */
133fcf5ef2aSThomas Huth     target_ulong npc;   /* next PC: integer or DYNAMIC_PC or JUMP_PC */
134fcf5ef2aSThomas Huth     target_ulong jump_pc[2]; /* used when JUMP_PC pc value is used */
135fcf5ef2aSThomas Huth     int mem_idx;
136c9b459aaSArtyom Tarasenko     bool fpu_enabled;
137c9b459aaSArtyom Tarasenko     bool address_mask_32bit;
138c9b459aaSArtyom Tarasenko #ifndef CONFIG_USER_ONLY
139c9b459aaSArtyom Tarasenko     bool supervisor;
140c9b459aaSArtyom Tarasenko #ifdef TARGET_SPARC64
141c9b459aaSArtyom Tarasenko     bool hypervisor;
142c9b459aaSArtyom Tarasenko #endif
143c9b459aaSArtyom Tarasenko #endif
144c9b459aaSArtyom Tarasenko 
145fcf5ef2aSThomas Huth     uint32_t cc_op;  /* current CC operation */
146fcf5ef2aSThomas Huth     sparc_def_t *def;
147fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
148fcf5ef2aSThomas Huth     int fprs_dirty;
149fcf5ef2aSThomas Huth     int asi;
150fcf5ef2aSThomas Huth #endif
151186e7890SRichard Henderson     DisasDelayException *delay_excp_list;
152fcf5ef2aSThomas Huth } DisasContext;
153fcf5ef2aSThomas Huth 
154fcf5ef2aSThomas Huth typedef struct {
155fcf5ef2aSThomas Huth     TCGCond cond;
156fcf5ef2aSThomas Huth     bool is_bool;
157fcf5ef2aSThomas Huth     TCGv c1, c2;
158fcf5ef2aSThomas Huth } DisasCompare;
159fcf5ef2aSThomas Huth 
160fcf5ef2aSThomas Huth // This function uses non-native bit order
161fcf5ef2aSThomas Huth #define GET_FIELD(X, FROM, TO)                                  \
162fcf5ef2aSThomas Huth     ((X) >> (31 - (TO)) & ((1 << ((TO) - (FROM) + 1)) - 1))
163fcf5ef2aSThomas Huth 
164fcf5ef2aSThomas Huth // This function uses the order in the manuals, i.e. bit 0 is 2^0
165fcf5ef2aSThomas Huth #define GET_FIELD_SP(X, FROM, TO)               \
166fcf5ef2aSThomas Huth     GET_FIELD(X, 31 - (TO), 31 - (FROM))
167fcf5ef2aSThomas Huth 
168fcf5ef2aSThomas Huth #define GET_FIELDs(x,a,b) sign_extend (GET_FIELD(x,a,b), (b) - (a) + 1)
169fcf5ef2aSThomas Huth #define GET_FIELD_SPs(x,a,b) sign_extend (GET_FIELD_SP(x,a,b), ((b) - (a) + 1))
170fcf5ef2aSThomas Huth 
171fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
172fcf5ef2aSThomas Huth #define DFPREG(r) (((r & 1) << 5) | (r & 0x1e))
173fcf5ef2aSThomas Huth #define QFPREG(r) (((r & 1) << 5) | (r & 0x1c))
174fcf5ef2aSThomas Huth #else
175fcf5ef2aSThomas Huth #define DFPREG(r) (r & 0x1e)
176fcf5ef2aSThomas Huth #define QFPREG(r) (r & 0x1c)
177fcf5ef2aSThomas Huth #endif
178fcf5ef2aSThomas Huth 
179fcf5ef2aSThomas Huth #define UA2005_HTRAP_MASK 0xff
180fcf5ef2aSThomas Huth #define V8_TRAP_MASK 0x7f
181fcf5ef2aSThomas Huth 
182fcf5ef2aSThomas Huth #define IS_IMM (insn & (1<<13))
183fcf5ef2aSThomas Huth 
1840c2e96c1SRichard Henderson static void gen_update_fprs_dirty(DisasContext *dc, int rd)
185fcf5ef2aSThomas Huth {
186fcf5ef2aSThomas Huth #if defined(TARGET_SPARC64)
187fcf5ef2aSThomas Huth     int bit = (rd < 32) ? 1 : 2;
188fcf5ef2aSThomas Huth     /* If we know we've already set this bit within the TB,
189fcf5ef2aSThomas Huth        we can avoid setting it again.  */
190fcf5ef2aSThomas Huth     if (!(dc->fprs_dirty & bit)) {
191fcf5ef2aSThomas Huth         dc->fprs_dirty |= bit;
192fcf5ef2aSThomas Huth         tcg_gen_ori_i32(cpu_fprs, cpu_fprs, bit);
193fcf5ef2aSThomas Huth     }
194fcf5ef2aSThomas Huth #endif
195fcf5ef2aSThomas Huth }
196fcf5ef2aSThomas Huth 
197fcf5ef2aSThomas Huth /* floating point registers moves */
198fcf5ef2aSThomas Huth static TCGv_i32 gen_load_fpr_F(DisasContext *dc, unsigned int src)
199fcf5ef2aSThomas Huth {
20036ab4623SRichard Henderson     TCGv_i32 ret = tcg_temp_new_i32();
201dc41aa7dSRichard Henderson     if (src & 1) {
202dc41aa7dSRichard Henderson         tcg_gen_extrl_i64_i32(ret, cpu_fpr[src / 2]);
203dc41aa7dSRichard Henderson     } else {
204dc41aa7dSRichard Henderson         tcg_gen_extrh_i64_i32(ret, cpu_fpr[src / 2]);
205fcf5ef2aSThomas Huth     }
206dc41aa7dSRichard Henderson     return ret;
207fcf5ef2aSThomas Huth }
208fcf5ef2aSThomas Huth 
209fcf5ef2aSThomas Huth static void gen_store_fpr_F(DisasContext *dc, unsigned int dst, TCGv_i32 v)
210fcf5ef2aSThomas Huth {
2118e7bbc75SRichard Henderson     TCGv_i64 t = tcg_temp_new_i64();
2128e7bbc75SRichard Henderson 
2138e7bbc75SRichard Henderson     tcg_gen_extu_i32_i64(t, v);
214fcf5ef2aSThomas Huth     tcg_gen_deposit_i64(cpu_fpr[dst / 2], cpu_fpr[dst / 2], t,
215fcf5ef2aSThomas Huth                         (dst & 1 ? 0 : 32), 32);
216fcf5ef2aSThomas Huth     gen_update_fprs_dirty(dc, dst);
217fcf5ef2aSThomas Huth }
218fcf5ef2aSThomas Huth 
219fcf5ef2aSThomas Huth static TCGv_i32 gen_dest_fpr_F(DisasContext *dc)
220fcf5ef2aSThomas Huth {
22136ab4623SRichard Henderson     return tcg_temp_new_i32();
222fcf5ef2aSThomas Huth }
223fcf5ef2aSThomas Huth 
224fcf5ef2aSThomas Huth static TCGv_i64 gen_load_fpr_D(DisasContext *dc, unsigned int src)
225fcf5ef2aSThomas Huth {
226fcf5ef2aSThomas Huth     src = DFPREG(src);
227fcf5ef2aSThomas Huth     return cpu_fpr[src / 2];
228fcf5ef2aSThomas Huth }
229fcf5ef2aSThomas Huth 
230fcf5ef2aSThomas Huth static void gen_store_fpr_D(DisasContext *dc, unsigned int dst, TCGv_i64 v)
231fcf5ef2aSThomas Huth {
232fcf5ef2aSThomas Huth     dst = DFPREG(dst);
233fcf5ef2aSThomas Huth     tcg_gen_mov_i64(cpu_fpr[dst / 2], v);
234fcf5ef2aSThomas Huth     gen_update_fprs_dirty(dc, dst);
235fcf5ef2aSThomas Huth }
236fcf5ef2aSThomas Huth 
237fcf5ef2aSThomas Huth static TCGv_i64 gen_dest_fpr_D(DisasContext *dc, unsigned int dst)
238fcf5ef2aSThomas Huth {
239fcf5ef2aSThomas Huth     return cpu_fpr[DFPREG(dst) / 2];
240fcf5ef2aSThomas Huth }
241fcf5ef2aSThomas Huth 
242fcf5ef2aSThomas Huth static void gen_op_load_fpr_QT0(unsigned int src)
243fcf5ef2aSThomas Huth {
244ad75a51eSRichard Henderson     tcg_gen_st_i64(cpu_fpr[src / 2], tcg_env, offsetof(CPUSPARCState, qt0) +
245fcf5ef2aSThomas Huth                    offsetof(CPU_QuadU, ll.upper));
246ad75a51eSRichard Henderson     tcg_gen_st_i64(cpu_fpr[src/2 + 1], tcg_env, offsetof(CPUSPARCState, qt0) +
247fcf5ef2aSThomas Huth                    offsetof(CPU_QuadU, ll.lower));
248fcf5ef2aSThomas Huth }
249fcf5ef2aSThomas Huth 
250fcf5ef2aSThomas Huth static void gen_op_load_fpr_QT1(unsigned int src)
251fcf5ef2aSThomas Huth {
252ad75a51eSRichard Henderson     tcg_gen_st_i64(cpu_fpr[src / 2], tcg_env, offsetof(CPUSPARCState, qt1) +
253fcf5ef2aSThomas Huth                    offsetof(CPU_QuadU, ll.upper));
254ad75a51eSRichard Henderson     tcg_gen_st_i64(cpu_fpr[src/2 + 1], tcg_env, offsetof(CPUSPARCState, qt1) +
255fcf5ef2aSThomas Huth                    offsetof(CPU_QuadU, ll.lower));
256fcf5ef2aSThomas Huth }
257fcf5ef2aSThomas Huth 
258fcf5ef2aSThomas Huth static void gen_op_store_QT0_fpr(unsigned int dst)
259fcf5ef2aSThomas Huth {
260ad75a51eSRichard Henderson     tcg_gen_ld_i64(cpu_fpr[dst / 2], tcg_env, offsetof(CPUSPARCState, qt0) +
261fcf5ef2aSThomas Huth                    offsetof(CPU_QuadU, ll.upper));
262ad75a51eSRichard Henderson     tcg_gen_ld_i64(cpu_fpr[dst/2 + 1], tcg_env, offsetof(CPUSPARCState, qt0) +
263fcf5ef2aSThomas Huth                    offsetof(CPU_QuadU, ll.lower));
264fcf5ef2aSThomas Huth }
265fcf5ef2aSThomas Huth 
266fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
267fcf5ef2aSThomas Huth static void gen_move_Q(DisasContext *dc, unsigned int rd, unsigned int rs)
268fcf5ef2aSThomas Huth {
269fcf5ef2aSThomas Huth     rd = QFPREG(rd);
270fcf5ef2aSThomas Huth     rs = QFPREG(rs);
271fcf5ef2aSThomas Huth 
272fcf5ef2aSThomas Huth     tcg_gen_mov_i64(cpu_fpr[rd / 2], cpu_fpr[rs / 2]);
273fcf5ef2aSThomas Huth     tcg_gen_mov_i64(cpu_fpr[rd / 2 + 1], cpu_fpr[rs / 2 + 1]);
274fcf5ef2aSThomas Huth     gen_update_fprs_dirty(dc, rd);
275fcf5ef2aSThomas Huth }
276fcf5ef2aSThomas Huth #endif
277fcf5ef2aSThomas Huth 
278fcf5ef2aSThomas Huth /* moves */
279fcf5ef2aSThomas Huth #ifdef CONFIG_USER_ONLY
280fcf5ef2aSThomas Huth #define supervisor(dc) 0
281fcf5ef2aSThomas Huth #define hypervisor(dc) 0
282fcf5ef2aSThomas Huth #else
283fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
284c9b459aaSArtyom Tarasenko #define hypervisor(dc) (dc->hypervisor)
285c9b459aaSArtyom Tarasenko #define supervisor(dc) (dc->supervisor | dc->hypervisor)
286fcf5ef2aSThomas Huth #else
287c9b459aaSArtyom Tarasenko #define supervisor(dc) (dc->supervisor)
288668bb9b7SRichard Henderson #define hypervisor(dc) 0
289fcf5ef2aSThomas Huth #endif
290fcf5ef2aSThomas Huth #endif
291fcf5ef2aSThomas Huth 
292b1bc09eaSRichard Henderson #if !defined(TARGET_SPARC64)
293b1bc09eaSRichard Henderson # define AM_CHECK(dc)  false
294b1bc09eaSRichard Henderson #elif defined(TARGET_ABI32)
295b1bc09eaSRichard Henderson # define AM_CHECK(dc)  true
296b1bc09eaSRichard Henderson #elif defined(CONFIG_USER_ONLY)
297b1bc09eaSRichard Henderson # define AM_CHECK(dc)  false
298fcf5ef2aSThomas Huth #else
299b1bc09eaSRichard Henderson # define AM_CHECK(dc)  ((dc)->address_mask_32bit)
300fcf5ef2aSThomas Huth #endif
301fcf5ef2aSThomas Huth 
3020c2e96c1SRichard Henderson static void gen_address_mask(DisasContext *dc, TCGv addr)
303fcf5ef2aSThomas Huth {
304b1bc09eaSRichard Henderson     if (AM_CHECK(dc)) {
305fcf5ef2aSThomas Huth         tcg_gen_andi_tl(addr, addr, 0xffffffffULL);
306b1bc09eaSRichard Henderson     }
307fcf5ef2aSThomas Huth }
308fcf5ef2aSThomas Huth 
30923ada1b1SRichard Henderson static target_ulong address_mask_i(DisasContext *dc, target_ulong addr)
31023ada1b1SRichard Henderson {
31123ada1b1SRichard Henderson     return AM_CHECK(dc) ? (uint32_t)addr : addr;
31223ada1b1SRichard Henderson }
31323ada1b1SRichard Henderson 
3140c2e96c1SRichard Henderson static TCGv gen_load_gpr(DisasContext *dc, int reg)
315fcf5ef2aSThomas Huth {
316fcf5ef2aSThomas Huth     if (reg > 0) {
317fcf5ef2aSThomas Huth         assert(reg < 32);
318fcf5ef2aSThomas Huth         return cpu_regs[reg];
319fcf5ef2aSThomas Huth     } else {
32052123f14SRichard Henderson         TCGv t = tcg_temp_new();
321fcf5ef2aSThomas Huth         tcg_gen_movi_tl(t, 0);
322fcf5ef2aSThomas Huth         return t;
323fcf5ef2aSThomas Huth     }
324fcf5ef2aSThomas Huth }
325fcf5ef2aSThomas Huth 
3260c2e96c1SRichard Henderson static void gen_store_gpr(DisasContext *dc, int reg, TCGv v)
327fcf5ef2aSThomas Huth {
328fcf5ef2aSThomas Huth     if (reg > 0) {
329fcf5ef2aSThomas Huth         assert(reg < 32);
330fcf5ef2aSThomas Huth         tcg_gen_mov_tl(cpu_regs[reg], v);
331fcf5ef2aSThomas Huth     }
332fcf5ef2aSThomas Huth }
333fcf5ef2aSThomas Huth 
3340c2e96c1SRichard Henderson static TCGv gen_dest_gpr(DisasContext *dc, int reg)
335fcf5ef2aSThomas Huth {
336fcf5ef2aSThomas Huth     if (reg > 0) {
337fcf5ef2aSThomas Huth         assert(reg < 32);
338fcf5ef2aSThomas Huth         return cpu_regs[reg];
339fcf5ef2aSThomas Huth     } else {
34052123f14SRichard Henderson         return tcg_temp_new();
341fcf5ef2aSThomas Huth     }
342fcf5ef2aSThomas Huth }
343fcf5ef2aSThomas Huth 
3445645aa2eSRichard Henderson static bool use_goto_tb(DisasContext *s, target_ulong pc, target_ulong npc)
345fcf5ef2aSThomas Huth {
3465645aa2eSRichard Henderson     return translator_use_goto_tb(&s->base, pc) &&
3475645aa2eSRichard Henderson            translator_use_goto_tb(&s->base, npc);
348fcf5ef2aSThomas Huth }
349fcf5ef2aSThomas Huth 
3505645aa2eSRichard Henderson static void gen_goto_tb(DisasContext *s, int tb_num,
351fcf5ef2aSThomas Huth                         target_ulong pc, target_ulong npc)
352fcf5ef2aSThomas Huth {
353fcf5ef2aSThomas Huth     if (use_goto_tb(s, pc, npc))  {
354fcf5ef2aSThomas Huth         /* jump to same page: we can use a direct jump */
355fcf5ef2aSThomas Huth         tcg_gen_goto_tb(tb_num);
356fcf5ef2aSThomas Huth         tcg_gen_movi_tl(cpu_pc, pc);
357fcf5ef2aSThomas Huth         tcg_gen_movi_tl(cpu_npc, npc);
35807ea28b4SRichard Henderson         tcg_gen_exit_tb(s->base.tb, tb_num);
359fcf5ef2aSThomas Huth     } else {
360f67ccb2fSRichard Henderson         /* jump to another page: we can use an indirect jump */
361fcf5ef2aSThomas Huth         tcg_gen_movi_tl(cpu_pc, pc);
362fcf5ef2aSThomas Huth         tcg_gen_movi_tl(cpu_npc, npc);
363f67ccb2fSRichard Henderson         tcg_gen_lookup_and_goto_ptr();
364fcf5ef2aSThomas Huth     }
365fcf5ef2aSThomas Huth }
366fcf5ef2aSThomas Huth 
367fcf5ef2aSThomas Huth // XXX suboptimal
3680c2e96c1SRichard Henderson static void gen_mov_reg_N(TCGv reg, TCGv_i32 src)
369fcf5ef2aSThomas Huth {
370fcf5ef2aSThomas Huth     tcg_gen_extu_i32_tl(reg, src);
3710b1183e3SPhilippe Mathieu-Daudé     tcg_gen_extract_tl(reg, reg, PSR_NEG_SHIFT, 1);
372fcf5ef2aSThomas Huth }
373fcf5ef2aSThomas Huth 
3740c2e96c1SRichard Henderson static void gen_mov_reg_Z(TCGv reg, TCGv_i32 src)
375fcf5ef2aSThomas Huth {
376fcf5ef2aSThomas Huth     tcg_gen_extu_i32_tl(reg, src);
3770b1183e3SPhilippe Mathieu-Daudé     tcg_gen_extract_tl(reg, reg, PSR_ZERO_SHIFT, 1);
378fcf5ef2aSThomas Huth }
379fcf5ef2aSThomas Huth 
3800c2e96c1SRichard Henderson static void gen_mov_reg_V(TCGv reg, TCGv_i32 src)
381fcf5ef2aSThomas Huth {
382fcf5ef2aSThomas Huth     tcg_gen_extu_i32_tl(reg, src);
3830b1183e3SPhilippe Mathieu-Daudé     tcg_gen_extract_tl(reg, reg, PSR_OVF_SHIFT, 1);
384fcf5ef2aSThomas Huth }
385fcf5ef2aSThomas Huth 
3860c2e96c1SRichard Henderson static void gen_mov_reg_C(TCGv reg, TCGv_i32 src)
387fcf5ef2aSThomas Huth {
388fcf5ef2aSThomas Huth     tcg_gen_extu_i32_tl(reg, src);
3890b1183e3SPhilippe Mathieu-Daudé     tcg_gen_extract_tl(reg, reg, PSR_CARRY_SHIFT, 1);
390fcf5ef2aSThomas Huth }
391fcf5ef2aSThomas Huth 
3920c2e96c1SRichard Henderson static void gen_op_add_cc(TCGv dst, TCGv src1, TCGv src2)
393fcf5ef2aSThomas Huth {
394fcf5ef2aSThomas Huth     tcg_gen_mov_tl(cpu_cc_src, src1);
395fcf5ef2aSThomas Huth     tcg_gen_mov_tl(cpu_cc_src2, src2);
396fcf5ef2aSThomas Huth     tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
397fcf5ef2aSThomas Huth     tcg_gen_mov_tl(dst, cpu_cc_dst);
398fcf5ef2aSThomas Huth }
399fcf5ef2aSThomas Huth 
400fcf5ef2aSThomas Huth static TCGv_i32 gen_add32_carry32(void)
401fcf5ef2aSThomas Huth {
402fcf5ef2aSThomas Huth     TCGv_i32 carry_32, cc_src1_32, cc_src2_32;
403fcf5ef2aSThomas Huth 
404fcf5ef2aSThomas Huth     /* Carry is computed from a previous add: (dst < src)  */
405fcf5ef2aSThomas Huth #if TARGET_LONG_BITS == 64
406fcf5ef2aSThomas Huth     cc_src1_32 = tcg_temp_new_i32();
407fcf5ef2aSThomas Huth     cc_src2_32 = tcg_temp_new_i32();
408fcf5ef2aSThomas Huth     tcg_gen_extrl_i64_i32(cc_src1_32, cpu_cc_dst);
409fcf5ef2aSThomas Huth     tcg_gen_extrl_i64_i32(cc_src2_32, cpu_cc_src);
410fcf5ef2aSThomas Huth #else
411fcf5ef2aSThomas Huth     cc_src1_32 = cpu_cc_dst;
412fcf5ef2aSThomas Huth     cc_src2_32 = cpu_cc_src;
413fcf5ef2aSThomas Huth #endif
414fcf5ef2aSThomas Huth 
415fcf5ef2aSThomas Huth     carry_32 = tcg_temp_new_i32();
416fcf5ef2aSThomas Huth     tcg_gen_setcond_i32(TCG_COND_LTU, carry_32, cc_src1_32, cc_src2_32);
417fcf5ef2aSThomas Huth 
418fcf5ef2aSThomas Huth     return carry_32;
419fcf5ef2aSThomas Huth }
420fcf5ef2aSThomas Huth 
421fcf5ef2aSThomas Huth static TCGv_i32 gen_sub32_carry32(void)
422fcf5ef2aSThomas Huth {
423fcf5ef2aSThomas Huth     TCGv_i32 carry_32, cc_src1_32, cc_src2_32;
424fcf5ef2aSThomas Huth 
425fcf5ef2aSThomas Huth     /* Carry is computed from a previous borrow: (src1 < src2)  */
426fcf5ef2aSThomas Huth #if TARGET_LONG_BITS == 64
427fcf5ef2aSThomas Huth     cc_src1_32 = tcg_temp_new_i32();
428fcf5ef2aSThomas Huth     cc_src2_32 = tcg_temp_new_i32();
429fcf5ef2aSThomas Huth     tcg_gen_extrl_i64_i32(cc_src1_32, cpu_cc_src);
430fcf5ef2aSThomas Huth     tcg_gen_extrl_i64_i32(cc_src2_32, cpu_cc_src2);
431fcf5ef2aSThomas Huth #else
432fcf5ef2aSThomas Huth     cc_src1_32 = cpu_cc_src;
433fcf5ef2aSThomas Huth     cc_src2_32 = cpu_cc_src2;
434fcf5ef2aSThomas Huth #endif
435fcf5ef2aSThomas Huth 
436fcf5ef2aSThomas Huth     carry_32 = tcg_temp_new_i32();
437fcf5ef2aSThomas Huth     tcg_gen_setcond_i32(TCG_COND_LTU, carry_32, cc_src1_32, cc_src2_32);
438fcf5ef2aSThomas Huth 
439fcf5ef2aSThomas Huth     return carry_32;
440fcf5ef2aSThomas Huth }
441fcf5ef2aSThomas Huth 
442420a187dSRichard Henderson static void gen_op_addc_int(TCGv dst, TCGv src1, TCGv src2,
443420a187dSRichard Henderson                             TCGv_i32 carry_32, bool update_cc)
444fcf5ef2aSThomas Huth {
445fcf5ef2aSThomas Huth     tcg_gen_add_tl(dst, src1, src2);
446fcf5ef2aSThomas Huth 
447420a187dSRichard Henderson #ifdef TARGET_SPARC64
448420a187dSRichard Henderson     TCGv carry = tcg_temp_new();
449420a187dSRichard Henderson     tcg_gen_extu_i32_tl(carry, carry_32);
450420a187dSRichard Henderson     tcg_gen_add_tl(dst, dst, carry);
451fcf5ef2aSThomas Huth #else
452420a187dSRichard Henderson     tcg_gen_add_i32(dst, dst, carry_32);
453fcf5ef2aSThomas Huth #endif
454fcf5ef2aSThomas Huth 
455fcf5ef2aSThomas Huth     if (update_cc) {
456420a187dSRichard Henderson         tcg_debug_assert(dst == cpu_cc_dst);
457fcf5ef2aSThomas Huth         tcg_gen_mov_tl(cpu_cc_src, src1);
458fcf5ef2aSThomas Huth         tcg_gen_mov_tl(cpu_cc_src2, src2);
459fcf5ef2aSThomas Huth     }
460fcf5ef2aSThomas Huth }
461fcf5ef2aSThomas Huth 
462420a187dSRichard Henderson static void gen_op_addc_int_add(TCGv dst, TCGv src1, TCGv src2, bool update_cc)
463420a187dSRichard Henderson {
464420a187dSRichard Henderson     TCGv discard;
465420a187dSRichard Henderson 
466420a187dSRichard Henderson     if (TARGET_LONG_BITS == 64) {
467420a187dSRichard Henderson         gen_op_addc_int(dst, src1, src2, gen_add32_carry32(), update_cc);
468420a187dSRichard Henderson         return;
469420a187dSRichard Henderson     }
470420a187dSRichard Henderson 
471420a187dSRichard Henderson     /*
472420a187dSRichard Henderson      * We can re-use the host's hardware carry generation by using
473420a187dSRichard Henderson      * an ADD2 opcode.  We discard the low part of the output.
474420a187dSRichard Henderson      * Ideally we'd combine this operation with the add that
475420a187dSRichard Henderson      * generated the carry in the first place.
476420a187dSRichard Henderson      */
477420a187dSRichard Henderson     discard = tcg_temp_new();
478420a187dSRichard Henderson     tcg_gen_add2_tl(discard, dst, cpu_cc_src, src1, cpu_cc_src2, src2);
479420a187dSRichard Henderson 
480420a187dSRichard Henderson     if (update_cc) {
481420a187dSRichard Henderson         tcg_debug_assert(dst == cpu_cc_dst);
482420a187dSRichard Henderson         tcg_gen_mov_tl(cpu_cc_src, src1);
483420a187dSRichard Henderson         tcg_gen_mov_tl(cpu_cc_src2, src2);
484420a187dSRichard Henderson     }
485420a187dSRichard Henderson }
486420a187dSRichard Henderson 
487420a187dSRichard Henderson static void gen_op_addc_add(TCGv dst, TCGv src1, TCGv src2)
488420a187dSRichard Henderson {
489420a187dSRichard Henderson     gen_op_addc_int_add(dst, src1, src2, false);
490420a187dSRichard Henderson }
491420a187dSRichard Henderson 
492420a187dSRichard Henderson static void gen_op_addccc_add(TCGv dst, TCGv src1, TCGv src2)
493420a187dSRichard Henderson {
494420a187dSRichard Henderson     gen_op_addc_int_add(dst, src1, src2, true);
495420a187dSRichard Henderson }
496420a187dSRichard Henderson 
497420a187dSRichard Henderson static void gen_op_addc_sub(TCGv dst, TCGv src1, TCGv src2)
498420a187dSRichard Henderson {
499420a187dSRichard Henderson     gen_op_addc_int(dst, src1, src2, gen_sub32_carry32(), false);
500420a187dSRichard Henderson }
501420a187dSRichard Henderson 
502420a187dSRichard Henderson static void gen_op_addccc_sub(TCGv dst, TCGv src1, TCGv src2)
503420a187dSRichard Henderson {
504420a187dSRichard Henderson     gen_op_addc_int(dst, src1, src2, gen_sub32_carry32(), true);
505420a187dSRichard Henderson }
506420a187dSRichard Henderson 
507420a187dSRichard Henderson static void gen_op_addc_int_generic(TCGv dst, TCGv src1, TCGv src2,
508420a187dSRichard Henderson                                     bool update_cc)
509420a187dSRichard Henderson {
510420a187dSRichard Henderson     TCGv_i32 carry_32 = tcg_temp_new_i32();
511420a187dSRichard Henderson     gen_helper_compute_C_icc(carry_32, tcg_env);
512420a187dSRichard Henderson     gen_op_addc_int(dst, src1, src2, carry_32, update_cc);
513420a187dSRichard Henderson }
514420a187dSRichard Henderson 
515420a187dSRichard Henderson static void gen_op_addc_generic(TCGv dst, TCGv src1, TCGv src2)
516420a187dSRichard Henderson {
517420a187dSRichard Henderson     gen_op_addc_int_generic(dst, src1, src2, false);
518420a187dSRichard Henderson }
519420a187dSRichard Henderson 
520420a187dSRichard Henderson static void gen_op_addccc_generic(TCGv dst, TCGv src1, TCGv src2)
521420a187dSRichard Henderson {
522420a187dSRichard Henderson     gen_op_addc_int_generic(dst, src1, src2, true);
523420a187dSRichard Henderson }
524420a187dSRichard Henderson 
5250c2e96c1SRichard Henderson static void gen_op_sub_cc(TCGv dst, TCGv src1, TCGv src2)
526fcf5ef2aSThomas Huth {
527fcf5ef2aSThomas Huth     tcg_gen_mov_tl(cpu_cc_src, src1);
528fcf5ef2aSThomas Huth     tcg_gen_mov_tl(cpu_cc_src2, src2);
529fcf5ef2aSThomas Huth     tcg_gen_sub_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
530fcf5ef2aSThomas Huth     tcg_gen_mov_tl(dst, cpu_cc_dst);
531fcf5ef2aSThomas Huth }
532fcf5ef2aSThomas Huth 
533dfebb950SRichard Henderson static void gen_op_subc_int(TCGv dst, TCGv src1, TCGv src2,
534dfebb950SRichard Henderson                             TCGv_i32 carry_32, bool update_cc)
535fcf5ef2aSThomas Huth {
536fcf5ef2aSThomas Huth     TCGv carry;
537fcf5ef2aSThomas Huth 
538fcf5ef2aSThomas Huth #if TARGET_LONG_BITS == 64
539fcf5ef2aSThomas Huth     carry = tcg_temp_new();
540fcf5ef2aSThomas Huth     tcg_gen_extu_i32_i64(carry, carry_32);
541fcf5ef2aSThomas Huth #else
542fcf5ef2aSThomas Huth     carry = carry_32;
543fcf5ef2aSThomas Huth #endif
544fcf5ef2aSThomas Huth 
545fcf5ef2aSThomas Huth     tcg_gen_sub_tl(dst, src1, src2);
546fcf5ef2aSThomas Huth     tcg_gen_sub_tl(dst, dst, carry);
547fcf5ef2aSThomas Huth 
548fcf5ef2aSThomas Huth     if (update_cc) {
549dfebb950SRichard Henderson         tcg_debug_assert(dst == cpu_cc_dst);
550fcf5ef2aSThomas Huth         tcg_gen_mov_tl(cpu_cc_src, src1);
551fcf5ef2aSThomas Huth         tcg_gen_mov_tl(cpu_cc_src2, src2);
552fcf5ef2aSThomas Huth     }
553fcf5ef2aSThomas Huth }
554fcf5ef2aSThomas Huth 
555dfebb950SRichard Henderson static void gen_op_subc_add(TCGv dst, TCGv src1, TCGv src2)
556dfebb950SRichard Henderson {
557dfebb950SRichard Henderson     gen_op_subc_int(dst, src1, src2, gen_add32_carry32(), false);
558dfebb950SRichard Henderson }
559dfebb950SRichard Henderson 
560dfebb950SRichard Henderson static void gen_op_subccc_add(TCGv dst, TCGv src1, TCGv src2)
561dfebb950SRichard Henderson {
562dfebb950SRichard Henderson     gen_op_subc_int(dst, src1, src2, gen_add32_carry32(), true);
563dfebb950SRichard Henderson }
564dfebb950SRichard Henderson 
565dfebb950SRichard Henderson static void gen_op_subc_int_sub(TCGv dst, TCGv src1, TCGv src2, bool update_cc)
566dfebb950SRichard Henderson {
567dfebb950SRichard Henderson     TCGv discard;
568dfebb950SRichard Henderson 
569dfebb950SRichard Henderson     if (TARGET_LONG_BITS == 64) {
570dfebb950SRichard Henderson         gen_op_subc_int(dst, src1, src2, gen_sub32_carry32(), update_cc);
571dfebb950SRichard Henderson         return;
572dfebb950SRichard Henderson     }
573dfebb950SRichard Henderson 
574dfebb950SRichard Henderson     /*
575dfebb950SRichard Henderson      * We can re-use the host's hardware carry generation by using
576dfebb950SRichard Henderson      * a SUB2 opcode.  We discard the low part of the output.
577dfebb950SRichard Henderson      */
578dfebb950SRichard Henderson     discard = tcg_temp_new();
579dfebb950SRichard Henderson     tcg_gen_sub2_tl(discard, dst, cpu_cc_src, src1, cpu_cc_src2, src2);
580dfebb950SRichard Henderson 
581dfebb950SRichard Henderson     if (update_cc) {
582dfebb950SRichard Henderson         tcg_debug_assert(dst == cpu_cc_dst);
583dfebb950SRichard Henderson         tcg_gen_mov_tl(cpu_cc_src, src1);
584dfebb950SRichard Henderson         tcg_gen_mov_tl(cpu_cc_src2, src2);
585dfebb950SRichard Henderson     }
586dfebb950SRichard Henderson }
587dfebb950SRichard Henderson 
588dfebb950SRichard Henderson static void gen_op_subc_sub(TCGv dst, TCGv src1, TCGv src2)
589dfebb950SRichard Henderson {
590dfebb950SRichard Henderson     gen_op_subc_int_sub(dst, src1, src2, false);
591dfebb950SRichard Henderson }
592dfebb950SRichard Henderson 
593dfebb950SRichard Henderson static void gen_op_subccc_sub(TCGv dst, TCGv src1, TCGv src2)
594dfebb950SRichard Henderson {
595dfebb950SRichard Henderson     gen_op_subc_int_sub(dst, src1, src2, true);
596dfebb950SRichard Henderson }
597dfebb950SRichard Henderson 
598dfebb950SRichard Henderson static void gen_op_subc_int_generic(TCGv dst, TCGv src1, TCGv src2,
599dfebb950SRichard Henderson                                     bool update_cc)
600dfebb950SRichard Henderson {
601dfebb950SRichard Henderson     TCGv_i32 carry_32 = tcg_temp_new_i32();
602dfebb950SRichard Henderson 
603dfebb950SRichard Henderson     gen_helper_compute_C_icc(carry_32, tcg_env);
604dfebb950SRichard Henderson     gen_op_subc_int(dst, src1, src2, carry_32, update_cc);
605dfebb950SRichard Henderson }
606dfebb950SRichard Henderson 
607dfebb950SRichard Henderson static void gen_op_subc_generic(TCGv dst, TCGv src1, TCGv src2)
608dfebb950SRichard Henderson {
609dfebb950SRichard Henderson     gen_op_subc_int_generic(dst, src1, src2, false);
610dfebb950SRichard Henderson }
611dfebb950SRichard Henderson 
612dfebb950SRichard Henderson static void gen_op_subccc_generic(TCGv dst, TCGv src1, TCGv src2)
613dfebb950SRichard Henderson {
614dfebb950SRichard Henderson     gen_op_subc_int_generic(dst, src1, src2, true);
615dfebb950SRichard Henderson }
616dfebb950SRichard Henderson 
6170c2e96c1SRichard Henderson static void gen_op_mulscc(TCGv dst, TCGv src1, TCGv src2)
618fcf5ef2aSThomas Huth {
619fcf5ef2aSThomas Huth     TCGv r_temp, zero, t0;
620fcf5ef2aSThomas Huth 
621fcf5ef2aSThomas Huth     r_temp = tcg_temp_new();
622fcf5ef2aSThomas Huth     t0 = tcg_temp_new();
623fcf5ef2aSThomas Huth 
624fcf5ef2aSThomas Huth     /* old op:
625fcf5ef2aSThomas Huth     if (!(env->y & 1))
626fcf5ef2aSThomas Huth         T1 = 0;
627fcf5ef2aSThomas Huth     */
62800ab7e61SRichard Henderson     zero = tcg_constant_tl(0);
629fcf5ef2aSThomas Huth     tcg_gen_andi_tl(cpu_cc_src, src1, 0xffffffff);
630fcf5ef2aSThomas Huth     tcg_gen_andi_tl(r_temp, cpu_y, 0x1);
631fcf5ef2aSThomas Huth     tcg_gen_andi_tl(cpu_cc_src2, src2, 0xffffffff);
632fcf5ef2aSThomas Huth     tcg_gen_movcond_tl(TCG_COND_EQ, cpu_cc_src2, r_temp, zero,
633fcf5ef2aSThomas Huth                        zero, cpu_cc_src2);
634fcf5ef2aSThomas Huth 
635fcf5ef2aSThomas Huth     // b2 = T0 & 1;
636fcf5ef2aSThomas Huth     // env->y = (b2 << 31) | (env->y >> 1);
6370b1183e3SPhilippe Mathieu-Daudé     tcg_gen_extract_tl(t0, cpu_y, 1, 31);
63808d64e0dSPhilippe Mathieu-Daudé     tcg_gen_deposit_tl(cpu_y, t0, cpu_cc_src, 31, 1);
639fcf5ef2aSThomas Huth 
640fcf5ef2aSThomas Huth     // b1 = N ^ V;
641fcf5ef2aSThomas Huth     gen_mov_reg_N(t0, cpu_psr);
642fcf5ef2aSThomas Huth     gen_mov_reg_V(r_temp, cpu_psr);
643fcf5ef2aSThomas Huth     tcg_gen_xor_tl(t0, t0, r_temp);
644fcf5ef2aSThomas Huth 
645fcf5ef2aSThomas Huth     // T0 = (b1 << 31) | (T0 >> 1);
646fcf5ef2aSThomas Huth     // src1 = T0;
647fcf5ef2aSThomas Huth     tcg_gen_shli_tl(t0, t0, 31);
648fcf5ef2aSThomas Huth     tcg_gen_shri_tl(cpu_cc_src, cpu_cc_src, 1);
649fcf5ef2aSThomas Huth     tcg_gen_or_tl(cpu_cc_src, cpu_cc_src, t0);
650fcf5ef2aSThomas Huth 
651fcf5ef2aSThomas Huth     tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
652fcf5ef2aSThomas Huth 
653fcf5ef2aSThomas Huth     tcg_gen_mov_tl(dst, cpu_cc_dst);
654fcf5ef2aSThomas Huth }
655fcf5ef2aSThomas Huth 
6560c2e96c1SRichard Henderson static void gen_op_multiply(TCGv dst, TCGv src1, TCGv src2, int sign_ext)
657fcf5ef2aSThomas Huth {
658fcf5ef2aSThomas Huth #if TARGET_LONG_BITS == 32
659fcf5ef2aSThomas Huth     if (sign_ext) {
660fcf5ef2aSThomas Huth         tcg_gen_muls2_tl(dst, cpu_y, src1, src2);
661fcf5ef2aSThomas Huth     } else {
662fcf5ef2aSThomas Huth         tcg_gen_mulu2_tl(dst, cpu_y, src1, src2);
663fcf5ef2aSThomas Huth     }
664fcf5ef2aSThomas Huth #else
665fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new_i64();
666fcf5ef2aSThomas Huth     TCGv t1 = tcg_temp_new_i64();
667fcf5ef2aSThomas Huth 
668fcf5ef2aSThomas Huth     if (sign_ext) {
669fcf5ef2aSThomas Huth         tcg_gen_ext32s_i64(t0, src1);
670fcf5ef2aSThomas Huth         tcg_gen_ext32s_i64(t1, src2);
671fcf5ef2aSThomas Huth     } else {
672fcf5ef2aSThomas Huth         tcg_gen_ext32u_i64(t0, src1);
673fcf5ef2aSThomas Huth         tcg_gen_ext32u_i64(t1, src2);
674fcf5ef2aSThomas Huth     }
675fcf5ef2aSThomas Huth 
676fcf5ef2aSThomas Huth     tcg_gen_mul_i64(dst, t0, t1);
677fcf5ef2aSThomas Huth     tcg_gen_shri_i64(cpu_y, dst, 32);
678fcf5ef2aSThomas Huth #endif
679fcf5ef2aSThomas Huth }
680fcf5ef2aSThomas Huth 
6810c2e96c1SRichard Henderson static void gen_op_umul(TCGv dst, TCGv src1, TCGv src2)
682fcf5ef2aSThomas Huth {
683fcf5ef2aSThomas Huth     /* zero-extend truncated operands before multiplication */
684fcf5ef2aSThomas Huth     gen_op_multiply(dst, src1, src2, 0);
685fcf5ef2aSThomas Huth }
686fcf5ef2aSThomas Huth 
6870c2e96c1SRichard Henderson static void gen_op_smul(TCGv dst, TCGv src1, TCGv src2)
688fcf5ef2aSThomas Huth {
689fcf5ef2aSThomas Huth     /* sign-extend truncated operands before multiplication */
690fcf5ef2aSThomas Huth     gen_op_multiply(dst, src1, src2, 1);
691fcf5ef2aSThomas Huth }
692fcf5ef2aSThomas Huth 
6934ee85ea9SRichard Henderson static void gen_op_udivx(TCGv dst, TCGv src1, TCGv src2)
6944ee85ea9SRichard Henderson {
6954ee85ea9SRichard Henderson     gen_helper_udivx(dst, tcg_env, src1, src2);
6964ee85ea9SRichard Henderson }
6974ee85ea9SRichard Henderson 
6984ee85ea9SRichard Henderson static void gen_op_sdivx(TCGv dst, TCGv src1, TCGv src2)
6994ee85ea9SRichard Henderson {
7004ee85ea9SRichard Henderson     gen_helper_sdivx(dst, tcg_env, src1, src2);
7014ee85ea9SRichard Henderson }
7024ee85ea9SRichard Henderson 
703c2636853SRichard Henderson static void gen_op_udiv(TCGv dst, TCGv src1, TCGv src2)
704c2636853SRichard Henderson {
705c2636853SRichard Henderson     gen_helper_udiv(dst, tcg_env, src1, src2);
706c2636853SRichard Henderson }
707c2636853SRichard Henderson 
708c2636853SRichard Henderson static void gen_op_sdiv(TCGv dst, TCGv src1, TCGv src2)
709c2636853SRichard Henderson {
710c2636853SRichard Henderson     gen_helper_sdiv(dst, tcg_env, src1, src2);
711c2636853SRichard Henderson }
712c2636853SRichard Henderson 
713c2636853SRichard Henderson static void gen_op_udivcc(TCGv dst, TCGv src1, TCGv src2)
714c2636853SRichard Henderson {
715c2636853SRichard Henderson     gen_helper_udiv_cc(dst, tcg_env, src1, src2);
716c2636853SRichard Henderson }
717c2636853SRichard Henderson 
718c2636853SRichard Henderson static void gen_op_sdivcc(TCGv dst, TCGv src1, TCGv src2)
719c2636853SRichard Henderson {
720c2636853SRichard Henderson     gen_helper_sdiv_cc(dst, tcg_env, src1, src2);
721c2636853SRichard Henderson }
722c2636853SRichard Henderson 
723a9aba13dSRichard Henderson static void gen_op_taddcctv(TCGv dst, TCGv src1, TCGv src2)
724a9aba13dSRichard Henderson {
725a9aba13dSRichard Henderson     gen_helper_taddcctv(dst, tcg_env, src1, src2);
726a9aba13dSRichard Henderson }
727a9aba13dSRichard Henderson 
728a9aba13dSRichard Henderson static void gen_op_tsubcctv(TCGv dst, TCGv src1, TCGv src2)
729a9aba13dSRichard Henderson {
730a9aba13dSRichard Henderson     gen_helper_tsubcctv(dst, tcg_env, src1, src2);
731a9aba13dSRichard Henderson }
732a9aba13dSRichard Henderson 
7339c6ec5bcSRichard Henderson static void gen_op_popc(TCGv dst, TCGv src1, TCGv src2)
7349c6ec5bcSRichard Henderson {
7359c6ec5bcSRichard Henderson     tcg_gen_ctpop_tl(dst, src2);
7369c6ec5bcSRichard Henderson }
7379c6ec5bcSRichard Henderson 
73845bfed3bSRichard Henderson #ifndef TARGET_SPARC64
73945bfed3bSRichard Henderson static void gen_helper_array8(TCGv dst, TCGv src1, TCGv src2)
74045bfed3bSRichard Henderson {
74145bfed3bSRichard Henderson     g_assert_not_reached();
74245bfed3bSRichard Henderson }
74345bfed3bSRichard Henderson #endif
74445bfed3bSRichard Henderson 
74545bfed3bSRichard Henderson static void gen_op_array16(TCGv dst, TCGv src1, TCGv src2)
74645bfed3bSRichard Henderson {
74745bfed3bSRichard Henderson     gen_helper_array8(dst, src1, src2);
74845bfed3bSRichard Henderson     tcg_gen_shli_tl(dst, dst, 1);
74945bfed3bSRichard Henderson }
75045bfed3bSRichard Henderson 
75145bfed3bSRichard Henderson static void gen_op_array32(TCGv dst, TCGv src1, TCGv src2)
75245bfed3bSRichard Henderson {
75345bfed3bSRichard Henderson     gen_helper_array8(dst, src1, src2);
75445bfed3bSRichard Henderson     tcg_gen_shli_tl(dst, dst, 2);
75545bfed3bSRichard Henderson }
75645bfed3bSRichard Henderson 
7574b6edc0aSRichard Henderson static void gen_op_fpack32(TCGv_i64 dst, TCGv_i64 src1, TCGv_i64 src2)
7584b6edc0aSRichard Henderson {
7594b6edc0aSRichard Henderson #ifdef TARGET_SPARC64
7604b6edc0aSRichard Henderson     gen_helper_fpack32(dst, cpu_gsr, src1, src2);
7614b6edc0aSRichard Henderson #else
7624b6edc0aSRichard Henderson     g_assert_not_reached();
7634b6edc0aSRichard Henderson #endif
7644b6edc0aSRichard Henderson }
7654b6edc0aSRichard Henderson 
7664b6edc0aSRichard Henderson static void gen_op_faligndata(TCGv_i64 dst, TCGv_i64 s1, TCGv_i64 s2)
7674b6edc0aSRichard Henderson {
7684b6edc0aSRichard Henderson #ifdef TARGET_SPARC64
7694b6edc0aSRichard Henderson     TCGv t1, t2, shift;
7704b6edc0aSRichard Henderson 
7714b6edc0aSRichard Henderson     t1 = tcg_temp_new();
7724b6edc0aSRichard Henderson     t2 = tcg_temp_new();
7734b6edc0aSRichard Henderson     shift = tcg_temp_new();
7744b6edc0aSRichard Henderson 
7754b6edc0aSRichard Henderson     tcg_gen_andi_tl(shift, cpu_gsr, 7);
7764b6edc0aSRichard Henderson     tcg_gen_shli_tl(shift, shift, 3);
7774b6edc0aSRichard Henderson     tcg_gen_shl_tl(t1, s1, shift);
7784b6edc0aSRichard Henderson 
7794b6edc0aSRichard Henderson     /*
7804b6edc0aSRichard Henderson      * A shift of 64 does not produce 0 in TCG.  Divide this into a
7814b6edc0aSRichard Henderson      * shift of (up to 63) followed by a constant shift of 1.
7824b6edc0aSRichard Henderson      */
7834b6edc0aSRichard Henderson     tcg_gen_xori_tl(shift, shift, 63);
7844b6edc0aSRichard Henderson     tcg_gen_shr_tl(t2, s2, shift);
7854b6edc0aSRichard Henderson     tcg_gen_shri_tl(t2, t2, 1);
7864b6edc0aSRichard Henderson 
7874b6edc0aSRichard Henderson     tcg_gen_or_tl(dst, t1, t2);
7884b6edc0aSRichard Henderson #else
7894b6edc0aSRichard Henderson     g_assert_not_reached();
7904b6edc0aSRichard Henderson #endif
7914b6edc0aSRichard Henderson }
7924b6edc0aSRichard Henderson 
7934b6edc0aSRichard Henderson static void gen_op_bshuffle(TCGv_i64 dst, TCGv_i64 src1, TCGv_i64 src2)
7944b6edc0aSRichard Henderson {
7954b6edc0aSRichard Henderson #ifdef TARGET_SPARC64
7964b6edc0aSRichard Henderson     gen_helper_bshuffle(dst, cpu_gsr, src1, src2);
7974b6edc0aSRichard Henderson #else
7984b6edc0aSRichard Henderson     g_assert_not_reached();
7994b6edc0aSRichard Henderson #endif
8004b6edc0aSRichard Henderson }
8014b6edc0aSRichard Henderson 
802fcf5ef2aSThomas Huth // 1
8030c2e96c1SRichard Henderson static void gen_op_eval_ba(TCGv dst)
804fcf5ef2aSThomas Huth {
805fcf5ef2aSThomas Huth     tcg_gen_movi_tl(dst, 1);
806fcf5ef2aSThomas Huth }
807fcf5ef2aSThomas Huth 
808fcf5ef2aSThomas Huth // Z
8090c2e96c1SRichard Henderson static void gen_op_eval_be(TCGv dst, TCGv_i32 src)
810fcf5ef2aSThomas Huth {
811fcf5ef2aSThomas Huth     gen_mov_reg_Z(dst, src);
812fcf5ef2aSThomas Huth }
813fcf5ef2aSThomas Huth 
814fcf5ef2aSThomas Huth // Z | (N ^ V)
8150c2e96c1SRichard Henderson static void gen_op_eval_ble(TCGv dst, TCGv_i32 src)
816fcf5ef2aSThomas Huth {
817fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
818fcf5ef2aSThomas Huth     gen_mov_reg_N(t0, src);
819fcf5ef2aSThomas Huth     gen_mov_reg_V(dst, src);
820fcf5ef2aSThomas Huth     tcg_gen_xor_tl(dst, dst, t0);
821fcf5ef2aSThomas Huth     gen_mov_reg_Z(t0, src);
822fcf5ef2aSThomas Huth     tcg_gen_or_tl(dst, dst, t0);
823fcf5ef2aSThomas Huth }
824fcf5ef2aSThomas Huth 
825fcf5ef2aSThomas Huth // N ^ V
8260c2e96c1SRichard Henderson static void gen_op_eval_bl(TCGv dst, TCGv_i32 src)
827fcf5ef2aSThomas Huth {
828fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
829fcf5ef2aSThomas Huth     gen_mov_reg_V(t0, src);
830fcf5ef2aSThomas Huth     gen_mov_reg_N(dst, src);
831fcf5ef2aSThomas Huth     tcg_gen_xor_tl(dst, dst, t0);
832fcf5ef2aSThomas Huth }
833fcf5ef2aSThomas Huth 
834fcf5ef2aSThomas Huth // C | Z
8350c2e96c1SRichard Henderson static void gen_op_eval_bleu(TCGv dst, TCGv_i32 src)
836fcf5ef2aSThomas Huth {
837fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
838fcf5ef2aSThomas Huth     gen_mov_reg_Z(t0, src);
839fcf5ef2aSThomas Huth     gen_mov_reg_C(dst, src);
840fcf5ef2aSThomas Huth     tcg_gen_or_tl(dst, dst, t0);
841fcf5ef2aSThomas Huth }
842fcf5ef2aSThomas Huth 
843fcf5ef2aSThomas Huth // C
8440c2e96c1SRichard Henderson static void gen_op_eval_bcs(TCGv dst, TCGv_i32 src)
845fcf5ef2aSThomas Huth {
846fcf5ef2aSThomas Huth     gen_mov_reg_C(dst, src);
847fcf5ef2aSThomas Huth }
848fcf5ef2aSThomas Huth 
849fcf5ef2aSThomas Huth // V
8500c2e96c1SRichard Henderson static void gen_op_eval_bvs(TCGv dst, TCGv_i32 src)
851fcf5ef2aSThomas Huth {
852fcf5ef2aSThomas Huth     gen_mov_reg_V(dst, src);
853fcf5ef2aSThomas Huth }
854fcf5ef2aSThomas Huth 
855fcf5ef2aSThomas Huth // 0
8560c2e96c1SRichard Henderson static void gen_op_eval_bn(TCGv dst)
857fcf5ef2aSThomas Huth {
858fcf5ef2aSThomas Huth     tcg_gen_movi_tl(dst, 0);
859fcf5ef2aSThomas Huth }
860fcf5ef2aSThomas Huth 
861fcf5ef2aSThomas Huth // N
8620c2e96c1SRichard Henderson static void gen_op_eval_bneg(TCGv dst, TCGv_i32 src)
863fcf5ef2aSThomas Huth {
864fcf5ef2aSThomas Huth     gen_mov_reg_N(dst, src);
865fcf5ef2aSThomas Huth }
866fcf5ef2aSThomas Huth 
867fcf5ef2aSThomas Huth // !Z
8680c2e96c1SRichard Henderson static void gen_op_eval_bne(TCGv dst, TCGv_i32 src)
869fcf5ef2aSThomas Huth {
870fcf5ef2aSThomas Huth     gen_mov_reg_Z(dst, src);
871fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
872fcf5ef2aSThomas Huth }
873fcf5ef2aSThomas Huth 
874fcf5ef2aSThomas Huth // !(Z | (N ^ V))
8750c2e96c1SRichard Henderson static void gen_op_eval_bg(TCGv dst, TCGv_i32 src)
876fcf5ef2aSThomas Huth {
877fcf5ef2aSThomas Huth     gen_op_eval_ble(dst, src);
878fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
879fcf5ef2aSThomas Huth }
880fcf5ef2aSThomas Huth 
881fcf5ef2aSThomas Huth // !(N ^ V)
8820c2e96c1SRichard Henderson static void gen_op_eval_bge(TCGv dst, TCGv_i32 src)
883fcf5ef2aSThomas Huth {
884fcf5ef2aSThomas Huth     gen_op_eval_bl(dst, src);
885fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
886fcf5ef2aSThomas Huth }
887fcf5ef2aSThomas Huth 
888fcf5ef2aSThomas Huth // !(C | Z)
8890c2e96c1SRichard Henderson static void gen_op_eval_bgu(TCGv dst, TCGv_i32 src)
890fcf5ef2aSThomas Huth {
891fcf5ef2aSThomas Huth     gen_op_eval_bleu(dst, src);
892fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
893fcf5ef2aSThomas Huth }
894fcf5ef2aSThomas Huth 
895fcf5ef2aSThomas Huth // !C
8960c2e96c1SRichard Henderson static void gen_op_eval_bcc(TCGv dst, TCGv_i32 src)
897fcf5ef2aSThomas Huth {
898fcf5ef2aSThomas Huth     gen_mov_reg_C(dst, src);
899fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
900fcf5ef2aSThomas Huth }
901fcf5ef2aSThomas Huth 
902fcf5ef2aSThomas Huth // !N
9030c2e96c1SRichard Henderson static void gen_op_eval_bpos(TCGv dst, TCGv_i32 src)
904fcf5ef2aSThomas Huth {
905fcf5ef2aSThomas Huth     gen_mov_reg_N(dst, src);
906fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
907fcf5ef2aSThomas Huth }
908fcf5ef2aSThomas Huth 
909fcf5ef2aSThomas Huth // !V
9100c2e96c1SRichard Henderson static void gen_op_eval_bvc(TCGv dst, TCGv_i32 src)
911fcf5ef2aSThomas Huth {
912fcf5ef2aSThomas Huth     gen_mov_reg_V(dst, src);
913fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
914fcf5ef2aSThomas Huth }
915fcf5ef2aSThomas Huth 
916fcf5ef2aSThomas Huth /*
917fcf5ef2aSThomas Huth   FPSR bit field FCC1 | FCC0:
918fcf5ef2aSThomas Huth    0 =
919fcf5ef2aSThomas Huth    1 <
920fcf5ef2aSThomas Huth    2 >
921fcf5ef2aSThomas Huth    3 unordered
922fcf5ef2aSThomas Huth */
9230c2e96c1SRichard Henderson static void gen_mov_reg_FCC0(TCGv reg, TCGv src,
924fcf5ef2aSThomas Huth                                     unsigned int fcc_offset)
925fcf5ef2aSThomas Huth {
926fcf5ef2aSThomas Huth     tcg_gen_shri_tl(reg, src, FSR_FCC0_SHIFT + fcc_offset);
927fcf5ef2aSThomas Huth     tcg_gen_andi_tl(reg, reg, 0x1);
928fcf5ef2aSThomas Huth }
929fcf5ef2aSThomas Huth 
9300c2e96c1SRichard Henderson static void gen_mov_reg_FCC1(TCGv reg, TCGv src, unsigned int fcc_offset)
931fcf5ef2aSThomas Huth {
932fcf5ef2aSThomas Huth     tcg_gen_shri_tl(reg, src, FSR_FCC1_SHIFT + fcc_offset);
933fcf5ef2aSThomas Huth     tcg_gen_andi_tl(reg, reg, 0x1);
934fcf5ef2aSThomas Huth }
935fcf5ef2aSThomas Huth 
936fcf5ef2aSThomas Huth // !0: FCC0 | FCC1
9370c2e96c1SRichard Henderson static void gen_op_eval_fbne(TCGv dst, TCGv src, unsigned int fcc_offset)
938fcf5ef2aSThomas Huth {
939fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
940fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
941fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(t0, src, fcc_offset);
942fcf5ef2aSThomas Huth     tcg_gen_or_tl(dst, dst, t0);
943fcf5ef2aSThomas Huth }
944fcf5ef2aSThomas Huth 
945fcf5ef2aSThomas Huth // 1 or 2: FCC0 ^ FCC1
9460c2e96c1SRichard Henderson static void gen_op_eval_fblg(TCGv dst, TCGv src, unsigned int fcc_offset)
947fcf5ef2aSThomas Huth {
948fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
949fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
950fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(t0, src, fcc_offset);
951fcf5ef2aSThomas Huth     tcg_gen_xor_tl(dst, dst, t0);
952fcf5ef2aSThomas Huth }
953fcf5ef2aSThomas Huth 
954fcf5ef2aSThomas Huth // 1 or 3: FCC0
9550c2e96c1SRichard Henderson static void gen_op_eval_fbul(TCGv dst, TCGv src, unsigned int fcc_offset)
956fcf5ef2aSThomas Huth {
957fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
958fcf5ef2aSThomas Huth }
959fcf5ef2aSThomas Huth 
960fcf5ef2aSThomas Huth // 1: FCC0 & !FCC1
9610c2e96c1SRichard Henderson static void gen_op_eval_fbl(TCGv dst, TCGv src, unsigned int fcc_offset)
962fcf5ef2aSThomas Huth {
963fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
964fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
965fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(t0, src, fcc_offset);
966fcf5ef2aSThomas Huth     tcg_gen_andc_tl(dst, dst, t0);
967fcf5ef2aSThomas Huth }
968fcf5ef2aSThomas Huth 
969fcf5ef2aSThomas Huth // 2 or 3: FCC1
9700c2e96c1SRichard Henderson static void gen_op_eval_fbug(TCGv dst, TCGv src, unsigned int fcc_offset)
971fcf5ef2aSThomas Huth {
972fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(dst, src, fcc_offset);
973fcf5ef2aSThomas Huth }
974fcf5ef2aSThomas Huth 
975fcf5ef2aSThomas Huth // 2: !FCC0 & FCC1
9760c2e96c1SRichard Henderson static void gen_op_eval_fbg(TCGv dst, TCGv src, unsigned int fcc_offset)
977fcf5ef2aSThomas Huth {
978fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
979fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
980fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(t0, src, fcc_offset);
981fcf5ef2aSThomas Huth     tcg_gen_andc_tl(dst, t0, dst);
982fcf5ef2aSThomas Huth }
983fcf5ef2aSThomas Huth 
984fcf5ef2aSThomas Huth // 3: FCC0 & FCC1
9850c2e96c1SRichard Henderson static void gen_op_eval_fbu(TCGv dst, TCGv src, unsigned int fcc_offset)
986fcf5ef2aSThomas Huth {
987fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
988fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
989fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(t0, src, fcc_offset);
990fcf5ef2aSThomas Huth     tcg_gen_and_tl(dst, dst, t0);
991fcf5ef2aSThomas Huth }
992fcf5ef2aSThomas Huth 
993fcf5ef2aSThomas Huth // 0: !(FCC0 | FCC1)
9940c2e96c1SRichard Henderson static void gen_op_eval_fbe(TCGv dst, TCGv src, unsigned int fcc_offset)
995fcf5ef2aSThomas Huth {
996fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
997fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
998fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(t0, src, fcc_offset);
999fcf5ef2aSThomas Huth     tcg_gen_or_tl(dst, dst, t0);
1000fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
1001fcf5ef2aSThomas Huth }
1002fcf5ef2aSThomas Huth 
1003fcf5ef2aSThomas Huth // 0 or 3: !(FCC0 ^ FCC1)
10040c2e96c1SRichard Henderson static void gen_op_eval_fbue(TCGv dst, TCGv src, unsigned int fcc_offset)
1005fcf5ef2aSThomas Huth {
1006fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
1007fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
1008fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(t0, src, fcc_offset);
1009fcf5ef2aSThomas Huth     tcg_gen_xor_tl(dst, dst, t0);
1010fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
1011fcf5ef2aSThomas Huth }
1012fcf5ef2aSThomas Huth 
1013fcf5ef2aSThomas Huth // 0 or 2: !FCC0
10140c2e96c1SRichard Henderson static void gen_op_eval_fbge(TCGv dst, TCGv src, unsigned int fcc_offset)
1015fcf5ef2aSThomas Huth {
1016fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
1017fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
1018fcf5ef2aSThomas Huth }
1019fcf5ef2aSThomas Huth 
1020fcf5ef2aSThomas Huth // !1: !(FCC0 & !FCC1)
10210c2e96c1SRichard Henderson static void gen_op_eval_fbuge(TCGv dst, TCGv src, unsigned int fcc_offset)
1022fcf5ef2aSThomas Huth {
1023fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
1024fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
1025fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(t0, src, fcc_offset);
1026fcf5ef2aSThomas Huth     tcg_gen_andc_tl(dst, dst, t0);
1027fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
1028fcf5ef2aSThomas Huth }
1029fcf5ef2aSThomas Huth 
1030fcf5ef2aSThomas Huth // 0 or 1: !FCC1
10310c2e96c1SRichard Henderson static void gen_op_eval_fble(TCGv dst, TCGv src, unsigned int fcc_offset)
1032fcf5ef2aSThomas Huth {
1033fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(dst, src, fcc_offset);
1034fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
1035fcf5ef2aSThomas Huth }
1036fcf5ef2aSThomas Huth 
1037fcf5ef2aSThomas Huth // !2: !(!FCC0 & FCC1)
10380c2e96c1SRichard Henderson static void gen_op_eval_fbule(TCGv dst, TCGv src, unsigned int fcc_offset)
1039fcf5ef2aSThomas Huth {
1040fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
1041fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
1042fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(t0, src, fcc_offset);
1043fcf5ef2aSThomas Huth     tcg_gen_andc_tl(dst, t0, dst);
1044fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
1045fcf5ef2aSThomas Huth }
1046fcf5ef2aSThomas Huth 
1047fcf5ef2aSThomas Huth // !3: !(FCC0 & FCC1)
10480c2e96c1SRichard Henderson static void gen_op_eval_fbo(TCGv dst, TCGv src, unsigned int fcc_offset)
1049fcf5ef2aSThomas Huth {
1050fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
1051fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
1052fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(t0, src, fcc_offset);
1053fcf5ef2aSThomas Huth     tcg_gen_and_tl(dst, dst, t0);
1054fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
1055fcf5ef2aSThomas Huth }
1056fcf5ef2aSThomas Huth 
10570c2e96c1SRichard Henderson static void gen_branch2(DisasContext *dc, target_ulong pc1,
1058fcf5ef2aSThomas Huth                         target_ulong pc2, TCGv r_cond)
1059fcf5ef2aSThomas Huth {
1060fcf5ef2aSThomas Huth     TCGLabel *l1 = gen_new_label();
1061fcf5ef2aSThomas Huth 
1062fcf5ef2aSThomas Huth     tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, 0, l1);
1063fcf5ef2aSThomas Huth 
1064fcf5ef2aSThomas Huth     gen_goto_tb(dc, 0, pc1, pc1 + 4);
1065fcf5ef2aSThomas Huth 
1066fcf5ef2aSThomas Huth     gen_set_label(l1);
1067fcf5ef2aSThomas Huth     gen_goto_tb(dc, 1, pc2, pc2 + 4);
1068fcf5ef2aSThomas Huth }
1069fcf5ef2aSThomas Huth 
10700c2e96c1SRichard Henderson static void gen_generic_branch(DisasContext *dc)
1071fcf5ef2aSThomas Huth {
107200ab7e61SRichard Henderson     TCGv npc0 = tcg_constant_tl(dc->jump_pc[0]);
107300ab7e61SRichard Henderson     TCGv npc1 = tcg_constant_tl(dc->jump_pc[1]);
107400ab7e61SRichard Henderson     TCGv zero = tcg_constant_tl(0);
1075fcf5ef2aSThomas Huth 
1076fcf5ef2aSThomas Huth     tcg_gen_movcond_tl(TCG_COND_NE, cpu_npc, cpu_cond, zero, npc0, npc1);
1077fcf5ef2aSThomas Huth }
1078fcf5ef2aSThomas Huth 
1079fcf5ef2aSThomas Huth /* call this function before using the condition register as it may
1080fcf5ef2aSThomas Huth    have been set for a jump */
10810c2e96c1SRichard Henderson static void flush_cond(DisasContext *dc)
1082fcf5ef2aSThomas Huth {
1083fcf5ef2aSThomas Huth     if (dc->npc == JUMP_PC) {
1084fcf5ef2aSThomas Huth         gen_generic_branch(dc);
108599c82c47SRichard Henderson         dc->npc = DYNAMIC_PC_LOOKUP;
1086fcf5ef2aSThomas Huth     }
1087fcf5ef2aSThomas Huth }
1088fcf5ef2aSThomas Huth 
10890c2e96c1SRichard Henderson static void save_npc(DisasContext *dc)
1090fcf5ef2aSThomas Huth {
1091633c4283SRichard Henderson     if (dc->npc & 3) {
1092633c4283SRichard Henderson         switch (dc->npc) {
1093633c4283SRichard Henderson         case JUMP_PC:
1094fcf5ef2aSThomas Huth             gen_generic_branch(dc);
109599c82c47SRichard Henderson             dc->npc = DYNAMIC_PC_LOOKUP;
1096633c4283SRichard Henderson             break;
1097633c4283SRichard Henderson         case DYNAMIC_PC:
1098633c4283SRichard Henderson         case DYNAMIC_PC_LOOKUP:
1099633c4283SRichard Henderson             break;
1100633c4283SRichard Henderson         default:
1101633c4283SRichard Henderson             g_assert_not_reached();
1102633c4283SRichard Henderson         }
1103633c4283SRichard Henderson     } else {
1104fcf5ef2aSThomas Huth         tcg_gen_movi_tl(cpu_npc, dc->npc);
1105fcf5ef2aSThomas Huth     }
1106fcf5ef2aSThomas Huth }
1107fcf5ef2aSThomas Huth 
11080c2e96c1SRichard Henderson static void update_psr(DisasContext *dc)
1109fcf5ef2aSThomas Huth {
1110fcf5ef2aSThomas Huth     if (dc->cc_op != CC_OP_FLAGS) {
1111fcf5ef2aSThomas Huth         dc->cc_op = CC_OP_FLAGS;
1112ad75a51eSRichard Henderson         gen_helper_compute_psr(tcg_env);
1113fcf5ef2aSThomas Huth     }
1114fcf5ef2aSThomas Huth }
1115fcf5ef2aSThomas Huth 
11160c2e96c1SRichard Henderson static void save_state(DisasContext *dc)
1117fcf5ef2aSThomas Huth {
1118fcf5ef2aSThomas Huth     tcg_gen_movi_tl(cpu_pc, dc->pc);
1119fcf5ef2aSThomas Huth     save_npc(dc);
1120fcf5ef2aSThomas Huth }
1121fcf5ef2aSThomas Huth 
1122fcf5ef2aSThomas Huth static void gen_exception(DisasContext *dc, int which)
1123fcf5ef2aSThomas Huth {
1124fcf5ef2aSThomas Huth     save_state(dc);
1125ad75a51eSRichard Henderson     gen_helper_raise_exception(tcg_env, tcg_constant_i32(which));
1126af00be49SEmilio G. Cota     dc->base.is_jmp = DISAS_NORETURN;
1127fcf5ef2aSThomas Huth }
1128fcf5ef2aSThomas Huth 
1129186e7890SRichard Henderson static TCGLabel *delay_exceptionv(DisasContext *dc, TCGv_i32 excp)
1130fcf5ef2aSThomas Huth {
1131186e7890SRichard Henderson     DisasDelayException *e = g_new0(DisasDelayException, 1);
1132186e7890SRichard Henderson 
1133186e7890SRichard Henderson     e->next = dc->delay_excp_list;
1134186e7890SRichard Henderson     dc->delay_excp_list = e;
1135186e7890SRichard Henderson 
1136186e7890SRichard Henderson     e->lab = gen_new_label();
1137186e7890SRichard Henderson     e->excp = excp;
1138186e7890SRichard Henderson     e->pc = dc->pc;
1139186e7890SRichard Henderson     /* Caller must have used flush_cond before branch. */
1140186e7890SRichard Henderson     assert(e->npc != JUMP_PC);
1141186e7890SRichard Henderson     e->npc = dc->npc;
1142186e7890SRichard Henderson 
1143186e7890SRichard Henderson     return e->lab;
1144186e7890SRichard Henderson }
1145186e7890SRichard Henderson 
1146186e7890SRichard Henderson static TCGLabel *delay_exception(DisasContext *dc, int excp)
1147186e7890SRichard Henderson {
1148186e7890SRichard Henderson     return delay_exceptionv(dc, tcg_constant_i32(excp));
1149186e7890SRichard Henderson }
1150186e7890SRichard Henderson 
1151186e7890SRichard Henderson static void gen_check_align(DisasContext *dc, TCGv addr, int mask)
1152186e7890SRichard Henderson {
1153186e7890SRichard Henderson     TCGv t = tcg_temp_new();
1154186e7890SRichard Henderson     TCGLabel *lab;
1155186e7890SRichard Henderson 
1156186e7890SRichard Henderson     tcg_gen_andi_tl(t, addr, mask);
1157186e7890SRichard Henderson 
1158186e7890SRichard Henderson     flush_cond(dc);
1159186e7890SRichard Henderson     lab = delay_exception(dc, TT_UNALIGNED);
1160186e7890SRichard Henderson     tcg_gen_brcondi_tl(TCG_COND_NE, t, 0, lab);
1161fcf5ef2aSThomas Huth }
1162fcf5ef2aSThomas Huth 
11630c2e96c1SRichard Henderson static void gen_mov_pc_npc(DisasContext *dc)
1164fcf5ef2aSThomas Huth {
1165633c4283SRichard Henderson     if (dc->npc & 3) {
1166633c4283SRichard Henderson         switch (dc->npc) {
1167633c4283SRichard Henderson         case JUMP_PC:
1168fcf5ef2aSThomas Huth             gen_generic_branch(dc);
1169fcf5ef2aSThomas Huth             tcg_gen_mov_tl(cpu_pc, cpu_npc);
117099c82c47SRichard Henderson             dc->pc = DYNAMIC_PC_LOOKUP;
1171633c4283SRichard Henderson             break;
1172633c4283SRichard Henderson         case DYNAMIC_PC:
1173633c4283SRichard Henderson         case DYNAMIC_PC_LOOKUP:
1174fcf5ef2aSThomas Huth             tcg_gen_mov_tl(cpu_pc, cpu_npc);
1175633c4283SRichard Henderson             dc->pc = dc->npc;
1176633c4283SRichard Henderson             break;
1177633c4283SRichard Henderson         default:
1178633c4283SRichard Henderson             g_assert_not_reached();
1179633c4283SRichard Henderson         }
1180fcf5ef2aSThomas Huth     } else {
1181fcf5ef2aSThomas Huth         dc->pc = dc->npc;
1182fcf5ef2aSThomas Huth     }
1183fcf5ef2aSThomas Huth }
1184fcf5ef2aSThomas Huth 
11850c2e96c1SRichard Henderson static void gen_op_next_insn(void)
1186fcf5ef2aSThomas Huth {
1187fcf5ef2aSThomas Huth     tcg_gen_mov_tl(cpu_pc, cpu_npc);
1188fcf5ef2aSThomas Huth     tcg_gen_addi_tl(cpu_npc, cpu_npc, 4);
1189fcf5ef2aSThomas Huth }
1190fcf5ef2aSThomas Huth 
1191fcf5ef2aSThomas Huth static void gen_compare(DisasCompare *cmp, bool xcc, unsigned int cond,
1192fcf5ef2aSThomas Huth                         DisasContext *dc)
1193fcf5ef2aSThomas Huth {
1194fcf5ef2aSThomas Huth     static int subcc_cond[16] = {
1195fcf5ef2aSThomas Huth         TCG_COND_NEVER,
1196fcf5ef2aSThomas Huth         TCG_COND_EQ,
1197fcf5ef2aSThomas Huth         TCG_COND_LE,
1198fcf5ef2aSThomas Huth         TCG_COND_LT,
1199fcf5ef2aSThomas Huth         TCG_COND_LEU,
1200fcf5ef2aSThomas Huth         TCG_COND_LTU,
1201fcf5ef2aSThomas Huth         -1, /* neg */
1202fcf5ef2aSThomas Huth         -1, /* overflow */
1203fcf5ef2aSThomas Huth         TCG_COND_ALWAYS,
1204fcf5ef2aSThomas Huth         TCG_COND_NE,
1205fcf5ef2aSThomas Huth         TCG_COND_GT,
1206fcf5ef2aSThomas Huth         TCG_COND_GE,
1207fcf5ef2aSThomas Huth         TCG_COND_GTU,
1208fcf5ef2aSThomas Huth         TCG_COND_GEU,
1209fcf5ef2aSThomas Huth         -1, /* pos */
1210fcf5ef2aSThomas Huth         -1, /* no overflow */
1211fcf5ef2aSThomas Huth     };
1212fcf5ef2aSThomas Huth 
1213fcf5ef2aSThomas Huth     static int logic_cond[16] = {
1214fcf5ef2aSThomas Huth         TCG_COND_NEVER,
1215fcf5ef2aSThomas Huth         TCG_COND_EQ,     /* eq:  Z */
1216fcf5ef2aSThomas Huth         TCG_COND_LE,     /* le:  Z | (N ^ V) -> Z | N */
1217fcf5ef2aSThomas Huth         TCG_COND_LT,     /* lt:  N ^ V -> N */
1218fcf5ef2aSThomas Huth         TCG_COND_EQ,     /* leu: C | Z -> Z */
1219fcf5ef2aSThomas Huth         TCG_COND_NEVER,  /* ltu: C -> 0 */
1220fcf5ef2aSThomas Huth         TCG_COND_LT,     /* neg: N */
1221fcf5ef2aSThomas Huth         TCG_COND_NEVER,  /* vs:  V -> 0 */
1222fcf5ef2aSThomas Huth         TCG_COND_ALWAYS,
1223fcf5ef2aSThomas Huth         TCG_COND_NE,     /* ne:  !Z */
1224fcf5ef2aSThomas Huth         TCG_COND_GT,     /* gt:  !(Z | (N ^ V)) -> !(Z | N) */
1225fcf5ef2aSThomas Huth         TCG_COND_GE,     /* ge:  !(N ^ V) -> !N */
1226fcf5ef2aSThomas Huth         TCG_COND_NE,     /* gtu: !(C | Z) -> !Z */
1227fcf5ef2aSThomas Huth         TCG_COND_ALWAYS, /* geu: !C -> 1 */
1228fcf5ef2aSThomas Huth         TCG_COND_GE,     /* pos: !N */
1229fcf5ef2aSThomas Huth         TCG_COND_ALWAYS, /* vc:  !V -> 1 */
1230fcf5ef2aSThomas Huth     };
1231fcf5ef2aSThomas Huth 
1232fcf5ef2aSThomas Huth     TCGv_i32 r_src;
1233fcf5ef2aSThomas Huth     TCGv r_dst;
1234fcf5ef2aSThomas Huth 
1235fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
1236fcf5ef2aSThomas Huth     if (xcc) {
1237fcf5ef2aSThomas Huth         r_src = cpu_xcc;
1238fcf5ef2aSThomas Huth     } else {
1239fcf5ef2aSThomas Huth         r_src = cpu_psr;
1240fcf5ef2aSThomas Huth     }
1241fcf5ef2aSThomas Huth #else
1242fcf5ef2aSThomas Huth     r_src = cpu_psr;
1243fcf5ef2aSThomas Huth #endif
1244fcf5ef2aSThomas Huth 
1245fcf5ef2aSThomas Huth     switch (dc->cc_op) {
1246fcf5ef2aSThomas Huth     case CC_OP_LOGIC:
1247fcf5ef2aSThomas Huth         cmp->cond = logic_cond[cond];
1248fcf5ef2aSThomas Huth     do_compare_dst_0:
1249fcf5ef2aSThomas Huth         cmp->is_bool = false;
125000ab7e61SRichard Henderson         cmp->c2 = tcg_constant_tl(0);
1251fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
1252fcf5ef2aSThomas Huth         if (!xcc) {
1253fcf5ef2aSThomas Huth             cmp->c1 = tcg_temp_new();
1254fcf5ef2aSThomas Huth             tcg_gen_ext32s_tl(cmp->c1, cpu_cc_dst);
1255fcf5ef2aSThomas Huth             break;
1256fcf5ef2aSThomas Huth         }
1257fcf5ef2aSThomas Huth #endif
1258fcf5ef2aSThomas Huth         cmp->c1 = cpu_cc_dst;
1259fcf5ef2aSThomas Huth         break;
1260fcf5ef2aSThomas Huth 
1261fcf5ef2aSThomas Huth     case CC_OP_SUB:
1262fcf5ef2aSThomas Huth         switch (cond) {
1263fcf5ef2aSThomas Huth         case 6:  /* neg */
1264fcf5ef2aSThomas Huth         case 14: /* pos */
1265fcf5ef2aSThomas Huth             cmp->cond = (cond == 6 ? TCG_COND_LT : TCG_COND_GE);
1266fcf5ef2aSThomas Huth             goto do_compare_dst_0;
1267fcf5ef2aSThomas Huth 
1268fcf5ef2aSThomas Huth         case 7: /* overflow */
1269fcf5ef2aSThomas Huth         case 15: /* !overflow */
1270fcf5ef2aSThomas Huth             goto do_dynamic;
1271fcf5ef2aSThomas Huth 
1272fcf5ef2aSThomas Huth         default:
1273fcf5ef2aSThomas Huth             cmp->cond = subcc_cond[cond];
1274fcf5ef2aSThomas Huth             cmp->is_bool = false;
1275fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
1276fcf5ef2aSThomas Huth             if (!xcc) {
1277fcf5ef2aSThomas Huth                 /* Note that sign-extension works for unsigned compares as
1278fcf5ef2aSThomas Huth                    long as both operands are sign-extended.  */
1279fcf5ef2aSThomas Huth                 cmp->c1 = tcg_temp_new();
1280fcf5ef2aSThomas Huth                 cmp->c2 = tcg_temp_new();
1281fcf5ef2aSThomas Huth                 tcg_gen_ext32s_tl(cmp->c1, cpu_cc_src);
1282fcf5ef2aSThomas Huth                 tcg_gen_ext32s_tl(cmp->c2, cpu_cc_src2);
1283fcf5ef2aSThomas Huth                 break;
1284fcf5ef2aSThomas Huth             }
1285fcf5ef2aSThomas Huth #endif
1286fcf5ef2aSThomas Huth             cmp->c1 = cpu_cc_src;
1287fcf5ef2aSThomas Huth             cmp->c2 = cpu_cc_src2;
1288fcf5ef2aSThomas Huth             break;
1289fcf5ef2aSThomas Huth         }
1290fcf5ef2aSThomas Huth         break;
1291fcf5ef2aSThomas Huth 
1292fcf5ef2aSThomas Huth     default:
1293fcf5ef2aSThomas Huth     do_dynamic:
1294ad75a51eSRichard Henderson         gen_helper_compute_psr(tcg_env);
1295fcf5ef2aSThomas Huth         dc->cc_op = CC_OP_FLAGS;
1296fcf5ef2aSThomas Huth         /* FALLTHRU */
1297fcf5ef2aSThomas Huth 
1298fcf5ef2aSThomas Huth     case CC_OP_FLAGS:
1299fcf5ef2aSThomas Huth         /* We're going to generate a boolean result.  */
1300fcf5ef2aSThomas Huth         cmp->cond = TCG_COND_NE;
1301fcf5ef2aSThomas Huth         cmp->is_bool = true;
1302fcf5ef2aSThomas Huth         cmp->c1 = r_dst = tcg_temp_new();
130300ab7e61SRichard Henderson         cmp->c2 = tcg_constant_tl(0);
1304fcf5ef2aSThomas Huth 
1305fcf5ef2aSThomas Huth         switch (cond) {
1306fcf5ef2aSThomas Huth         case 0x0:
1307fcf5ef2aSThomas Huth             gen_op_eval_bn(r_dst);
1308fcf5ef2aSThomas Huth             break;
1309fcf5ef2aSThomas Huth         case 0x1:
1310fcf5ef2aSThomas Huth             gen_op_eval_be(r_dst, r_src);
1311fcf5ef2aSThomas Huth             break;
1312fcf5ef2aSThomas Huth         case 0x2:
1313fcf5ef2aSThomas Huth             gen_op_eval_ble(r_dst, r_src);
1314fcf5ef2aSThomas Huth             break;
1315fcf5ef2aSThomas Huth         case 0x3:
1316fcf5ef2aSThomas Huth             gen_op_eval_bl(r_dst, r_src);
1317fcf5ef2aSThomas Huth             break;
1318fcf5ef2aSThomas Huth         case 0x4:
1319fcf5ef2aSThomas Huth             gen_op_eval_bleu(r_dst, r_src);
1320fcf5ef2aSThomas Huth             break;
1321fcf5ef2aSThomas Huth         case 0x5:
1322fcf5ef2aSThomas Huth             gen_op_eval_bcs(r_dst, r_src);
1323fcf5ef2aSThomas Huth             break;
1324fcf5ef2aSThomas Huth         case 0x6:
1325fcf5ef2aSThomas Huth             gen_op_eval_bneg(r_dst, r_src);
1326fcf5ef2aSThomas Huth             break;
1327fcf5ef2aSThomas Huth         case 0x7:
1328fcf5ef2aSThomas Huth             gen_op_eval_bvs(r_dst, r_src);
1329fcf5ef2aSThomas Huth             break;
1330fcf5ef2aSThomas Huth         case 0x8:
1331fcf5ef2aSThomas Huth             gen_op_eval_ba(r_dst);
1332fcf5ef2aSThomas Huth             break;
1333fcf5ef2aSThomas Huth         case 0x9:
1334fcf5ef2aSThomas Huth             gen_op_eval_bne(r_dst, r_src);
1335fcf5ef2aSThomas Huth             break;
1336fcf5ef2aSThomas Huth         case 0xa:
1337fcf5ef2aSThomas Huth             gen_op_eval_bg(r_dst, r_src);
1338fcf5ef2aSThomas Huth             break;
1339fcf5ef2aSThomas Huth         case 0xb:
1340fcf5ef2aSThomas Huth             gen_op_eval_bge(r_dst, r_src);
1341fcf5ef2aSThomas Huth             break;
1342fcf5ef2aSThomas Huth         case 0xc:
1343fcf5ef2aSThomas Huth             gen_op_eval_bgu(r_dst, r_src);
1344fcf5ef2aSThomas Huth             break;
1345fcf5ef2aSThomas Huth         case 0xd:
1346fcf5ef2aSThomas Huth             gen_op_eval_bcc(r_dst, r_src);
1347fcf5ef2aSThomas Huth             break;
1348fcf5ef2aSThomas Huth         case 0xe:
1349fcf5ef2aSThomas Huth             gen_op_eval_bpos(r_dst, r_src);
1350fcf5ef2aSThomas Huth             break;
1351fcf5ef2aSThomas Huth         case 0xf:
1352fcf5ef2aSThomas Huth             gen_op_eval_bvc(r_dst, r_src);
1353fcf5ef2aSThomas Huth             break;
1354fcf5ef2aSThomas Huth         }
1355fcf5ef2aSThomas Huth         break;
1356fcf5ef2aSThomas Huth     }
1357fcf5ef2aSThomas Huth }
1358fcf5ef2aSThomas Huth 
1359fcf5ef2aSThomas Huth static void gen_fcompare(DisasCompare *cmp, unsigned int cc, unsigned int cond)
1360fcf5ef2aSThomas Huth {
1361fcf5ef2aSThomas Huth     unsigned int offset;
1362fcf5ef2aSThomas Huth     TCGv r_dst;
1363fcf5ef2aSThomas Huth 
1364fcf5ef2aSThomas Huth     /* For now we still generate a straight boolean result.  */
1365fcf5ef2aSThomas Huth     cmp->cond = TCG_COND_NE;
1366fcf5ef2aSThomas Huth     cmp->is_bool = true;
1367fcf5ef2aSThomas Huth     cmp->c1 = r_dst = tcg_temp_new();
136800ab7e61SRichard Henderson     cmp->c2 = tcg_constant_tl(0);
1369fcf5ef2aSThomas Huth 
1370fcf5ef2aSThomas Huth     switch (cc) {
1371fcf5ef2aSThomas Huth     default:
1372fcf5ef2aSThomas Huth     case 0x0:
1373fcf5ef2aSThomas Huth         offset = 0;
1374fcf5ef2aSThomas Huth         break;
1375fcf5ef2aSThomas Huth     case 0x1:
1376fcf5ef2aSThomas Huth         offset = 32 - 10;
1377fcf5ef2aSThomas Huth         break;
1378fcf5ef2aSThomas Huth     case 0x2:
1379fcf5ef2aSThomas Huth         offset = 34 - 10;
1380fcf5ef2aSThomas Huth         break;
1381fcf5ef2aSThomas Huth     case 0x3:
1382fcf5ef2aSThomas Huth         offset = 36 - 10;
1383fcf5ef2aSThomas Huth         break;
1384fcf5ef2aSThomas Huth     }
1385fcf5ef2aSThomas Huth 
1386fcf5ef2aSThomas Huth     switch (cond) {
1387fcf5ef2aSThomas Huth     case 0x0:
1388fcf5ef2aSThomas Huth         gen_op_eval_bn(r_dst);
1389fcf5ef2aSThomas Huth         break;
1390fcf5ef2aSThomas Huth     case 0x1:
1391fcf5ef2aSThomas Huth         gen_op_eval_fbne(r_dst, cpu_fsr, offset);
1392fcf5ef2aSThomas Huth         break;
1393fcf5ef2aSThomas Huth     case 0x2:
1394fcf5ef2aSThomas Huth         gen_op_eval_fblg(r_dst, cpu_fsr, offset);
1395fcf5ef2aSThomas Huth         break;
1396fcf5ef2aSThomas Huth     case 0x3:
1397fcf5ef2aSThomas Huth         gen_op_eval_fbul(r_dst, cpu_fsr, offset);
1398fcf5ef2aSThomas Huth         break;
1399fcf5ef2aSThomas Huth     case 0x4:
1400fcf5ef2aSThomas Huth         gen_op_eval_fbl(r_dst, cpu_fsr, offset);
1401fcf5ef2aSThomas Huth         break;
1402fcf5ef2aSThomas Huth     case 0x5:
1403fcf5ef2aSThomas Huth         gen_op_eval_fbug(r_dst, cpu_fsr, offset);
1404fcf5ef2aSThomas Huth         break;
1405fcf5ef2aSThomas Huth     case 0x6:
1406fcf5ef2aSThomas Huth         gen_op_eval_fbg(r_dst, cpu_fsr, offset);
1407fcf5ef2aSThomas Huth         break;
1408fcf5ef2aSThomas Huth     case 0x7:
1409fcf5ef2aSThomas Huth         gen_op_eval_fbu(r_dst, cpu_fsr, offset);
1410fcf5ef2aSThomas Huth         break;
1411fcf5ef2aSThomas Huth     case 0x8:
1412fcf5ef2aSThomas Huth         gen_op_eval_ba(r_dst);
1413fcf5ef2aSThomas Huth         break;
1414fcf5ef2aSThomas Huth     case 0x9:
1415fcf5ef2aSThomas Huth         gen_op_eval_fbe(r_dst, cpu_fsr, offset);
1416fcf5ef2aSThomas Huth         break;
1417fcf5ef2aSThomas Huth     case 0xa:
1418fcf5ef2aSThomas Huth         gen_op_eval_fbue(r_dst, cpu_fsr, offset);
1419fcf5ef2aSThomas Huth         break;
1420fcf5ef2aSThomas Huth     case 0xb:
1421fcf5ef2aSThomas Huth         gen_op_eval_fbge(r_dst, cpu_fsr, offset);
1422fcf5ef2aSThomas Huth         break;
1423fcf5ef2aSThomas Huth     case 0xc:
1424fcf5ef2aSThomas Huth         gen_op_eval_fbuge(r_dst, cpu_fsr, offset);
1425fcf5ef2aSThomas Huth         break;
1426fcf5ef2aSThomas Huth     case 0xd:
1427fcf5ef2aSThomas Huth         gen_op_eval_fble(r_dst, cpu_fsr, offset);
1428fcf5ef2aSThomas Huth         break;
1429fcf5ef2aSThomas Huth     case 0xe:
1430fcf5ef2aSThomas Huth         gen_op_eval_fbule(r_dst, cpu_fsr, offset);
1431fcf5ef2aSThomas Huth         break;
1432fcf5ef2aSThomas Huth     case 0xf:
1433fcf5ef2aSThomas Huth         gen_op_eval_fbo(r_dst, cpu_fsr, offset);
1434fcf5ef2aSThomas Huth         break;
1435fcf5ef2aSThomas Huth     }
1436fcf5ef2aSThomas Huth }
1437fcf5ef2aSThomas Huth 
1438fcf5ef2aSThomas Huth // Inverted logic
1439ab9ffe98SRichard Henderson static const TCGCond gen_tcg_cond_reg[8] = {
1440ab9ffe98SRichard Henderson     TCG_COND_NEVER,  /* reserved */
1441fcf5ef2aSThomas Huth     TCG_COND_NE,
1442fcf5ef2aSThomas Huth     TCG_COND_GT,
1443fcf5ef2aSThomas Huth     TCG_COND_GE,
1444ab9ffe98SRichard Henderson     TCG_COND_NEVER,  /* reserved */
1445fcf5ef2aSThomas Huth     TCG_COND_EQ,
1446fcf5ef2aSThomas Huth     TCG_COND_LE,
1447fcf5ef2aSThomas Huth     TCG_COND_LT,
1448fcf5ef2aSThomas Huth };
1449fcf5ef2aSThomas Huth 
1450fcf5ef2aSThomas Huth static void gen_compare_reg(DisasCompare *cmp, int cond, TCGv r_src)
1451fcf5ef2aSThomas Huth {
1452fcf5ef2aSThomas Huth     cmp->cond = tcg_invert_cond(gen_tcg_cond_reg[cond]);
1453fcf5ef2aSThomas Huth     cmp->is_bool = false;
1454fcf5ef2aSThomas Huth     cmp->c1 = r_src;
145500ab7e61SRichard Henderson     cmp->c2 = tcg_constant_tl(0);
1456fcf5ef2aSThomas Huth }
1457fcf5ef2aSThomas Huth 
1458baf3dbf2SRichard Henderson static void gen_op_clear_ieee_excp_and_FTT(void)
1459baf3dbf2SRichard Henderson {
1460baf3dbf2SRichard Henderson     tcg_gen_andi_tl(cpu_fsr, cpu_fsr, FSR_FTT_CEXC_NMASK);
1461baf3dbf2SRichard Henderson }
1462baf3dbf2SRichard Henderson 
1463baf3dbf2SRichard Henderson static void gen_op_fmovs(TCGv_i32 dst, TCGv_i32 src)
1464baf3dbf2SRichard Henderson {
1465baf3dbf2SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
1466baf3dbf2SRichard Henderson     tcg_gen_mov_i32(dst, src);
1467baf3dbf2SRichard Henderson }
1468baf3dbf2SRichard Henderson 
1469baf3dbf2SRichard Henderson static void gen_op_fnegs(TCGv_i32 dst, TCGv_i32 src)
1470baf3dbf2SRichard Henderson {
1471baf3dbf2SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
1472baf3dbf2SRichard Henderson     gen_helper_fnegs(dst, src);
1473baf3dbf2SRichard Henderson }
1474baf3dbf2SRichard Henderson 
1475baf3dbf2SRichard Henderson static void gen_op_fabss(TCGv_i32 dst, TCGv_i32 src)
1476baf3dbf2SRichard Henderson {
1477baf3dbf2SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
1478baf3dbf2SRichard Henderson     gen_helper_fabss(dst, src);
1479baf3dbf2SRichard Henderson }
1480baf3dbf2SRichard Henderson 
1481c6d83e4fSRichard Henderson static void gen_op_fmovd(TCGv_i64 dst, TCGv_i64 src)
1482c6d83e4fSRichard Henderson {
1483c6d83e4fSRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
1484c6d83e4fSRichard Henderson     tcg_gen_mov_i64(dst, src);
1485c6d83e4fSRichard Henderson }
1486c6d83e4fSRichard Henderson 
1487c6d83e4fSRichard Henderson static void gen_op_fnegd(TCGv_i64 dst, TCGv_i64 src)
1488c6d83e4fSRichard Henderson {
1489c6d83e4fSRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
1490c6d83e4fSRichard Henderson     gen_helper_fnegd(dst, src);
1491c6d83e4fSRichard Henderson }
1492c6d83e4fSRichard Henderson 
1493c6d83e4fSRichard Henderson static void gen_op_fabsd(TCGv_i64 dst, TCGv_i64 src)
1494c6d83e4fSRichard Henderson {
1495c6d83e4fSRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
1496c6d83e4fSRichard Henderson     gen_helper_fabsd(dst, src);
1497c6d83e4fSRichard Henderson }
1498c6d83e4fSRichard Henderson 
1499fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
15000c2e96c1SRichard Henderson static void gen_op_fcmps(int fccno, TCGv_i32 r_rs1, TCGv_i32 r_rs2)
1501fcf5ef2aSThomas Huth {
1502fcf5ef2aSThomas Huth     switch (fccno) {
1503fcf5ef2aSThomas Huth     case 0:
1504ad75a51eSRichard Henderson         gen_helper_fcmps(cpu_fsr, tcg_env, r_rs1, r_rs2);
1505fcf5ef2aSThomas Huth         break;
1506fcf5ef2aSThomas Huth     case 1:
1507ad75a51eSRichard Henderson         gen_helper_fcmps_fcc1(cpu_fsr, tcg_env, r_rs1, r_rs2);
1508fcf5ef2aSThomas Huth         break;
1509fcf5ef2aSThomas Huth     case 2:
1510ad75a51eSRichard Henderson         gen_helper_fcmps_fcc2(cpu_fsr, tcg_env, r_rs1, r_rs2);
1511fcf5ef2aSThomas Huth         break;
1512fcf5ef2aSThomas Huth     case 3:
1513ad75a51eSRichard Henderson         gen_helper_fcmps_fcc3(cpu_fsr, tcg_env, r_rs1, r_rs2);
1514fcf5ef2aSThomas Huth         break;
1515fcf5ef2aSThomas Huth     }
1516fcf5ef2aSThomas Huth }
1517fcf5ef2aSThomas Huth 
15180c2e96c1SRichard Henderson static void gen_op_fcmpd(int fccno, TCGv_i64 r_rs1, TCGv_i64 r_rs2)
1519fcf5ef2aSThomas Huth {
1520fcf5ef2aSThomas Huth     switch (fccno) {
1521fcf5ef2aSThomas Huth     case 0:
1522ad75a51eSRichard Henderson         gen_helper_fcmpd(cpu_fsr, tcg_env, r_rs1, r_rs2);
1523fcf5ef2aSThomas Huth         break;
1524fcf5ef2aSThomas Huth     case 1:
1525ad75a51eSRichard Henderson         gen_helper_fcmpd_fcc1(cpu_fsr, tcg_env, r_rs1, r_rs2);
1526fcf5ef2aSThomas Huth         break;
1527fcf5ef2aSThomas Huth     case 2:
1528ad75a51eSRichard Henderson         gen_helper_fcmpd_fcc2(cpu_fsr, tcg_env, r_rs1, r_rs2);
1529fcf5ef2aSThomas Huth         break;
1530fcf5ef2aSThomas Huth     case 3:
1531ad75a51eSRichard Henderson         gen_helper_fcmpd_fcc3(cpu_fsr, tcg_env, r_rs1, r_rs2);
1532fcf5ef2aSThomas Huth         break;
1533fcf5ef2aSThomas Huth     }
1534fcf5ef2aSThomas Huth }
1535fcf5ef2aSThomas Huth 
15360c2e96c1SRichard Henderson static void gen_op_fcmpq(int fccno)
1537fcf5ef2aSThomas Huth {
1538fcf5ef2aSThomas Huth     switch (fccno) {
1539fcf5ef2aSThomas Huth     case 0:
1540ad75a51eSRichard Henderson         gen_helper_fcmpq(cpu_fsr, tcg_env);
1541fcf5ef2aSThomas Huth         break;
1542fcf5ef2aSThomas Huth     case 1:
1543ad75a51eSRichard Henderson         gen_helper_fcmpq_fcc1(cpu_fsr, tcg_env);
1544fcf5ef2aSThomas Huth         break;
1545fcf5ef2aSThomas Huth     case 2:
1546ad75a51eSRichard Henderson         gen_helper_fcmpq_fcc2(cpu_fsr, tcg_env);
1547fcf5ef2aSThomas Huth         break;
1548fcf5ef2aSThomas Huth     case 3:
1549ad75a51eSRichard Henderson         gen_helper_fcmpq_fcc3(cpu_fsr, tcg_env);
1550fcf5ef2aSThomas Huth         break;
1551fcf5ef2aSThomas Huth     }
1552fcf5ef2aSThomas Huth }
1553fcf5ef2aSThomas Huth 
15540c2e96c1SRichard Henderson static void gen_op_fcmpes(int fccno, TCGv_i32 r_rs1, TCGv_i32 r_rs2)
1555fcf5ef2aSThomas Huth {
1556fcf5ef2aSThomas Huth     switch (fccno) {
1557fcf5ef2aSThomas Huth     case 0:
1558ad75a51eSRichard Henderson         gen_helper_fcmpes(cpu_fsr, tcg_env, r_rs1, r_rs2);
1559fcf5ef2aSThomas Huth         break;
1560fcf5ef2aSThomas Huth     case 1:
1561ad75a51eSRichard Henderson         gen_helper_fcmpes_fcc1(cpu_fsr, tcg_env, r_rs1, r_rs2);
1562fcf5ef2aSThomas Huth         break;
1563fcf5ef2aSThomas Huth     case 2:
1564ad75a51eSRichard Henderson         gen_helper_fcmpes_fcc2(cpu_fsr, tcg_env, r_rs1, r_rs2);
1565fcf5ef2aSThomas Huth         break;
1566fcf5ef2aSThomas Huth     case 3:
1567ad75a51eSRichard Henderson         gen_helper_fcmpes_fcc3(cpu_fsr, tcg_env, r_rs1, r_rs2);
1568fcf5ef2aSThomas Huth         break;
1569fcf5ef2aSThomas Huth     }
1570fcf5ef2aSThomas Huth }
1571fcf5ef2aSThomas Huth 
15720c2e96c1SRichard Henderson static void gen_op_fcmped(int fccno, TCGv_i64 r_rs1, TCGv_i64 r_rs2)
1573fcf5ef2aSThomas Huth {
1574fcf5ef2aSThomas Huth     switch (fccno) {
1575fcf5ef2aSThomas Huth     case 0:
1576ad75a51eSRichard Henderson         gen_helper_fcmped(cpu_fsr, tcg_env, r_rs1, r_rs2);
1577fcf5ef2aSThomas Huth         break;
1578fcf5ef2aSThomas Huth     case 1:
1579ad75a51eSRichard Henderson         gen_helper_fcmped_fcc1(cpu_fsr, tcg_env, r_rs1, r_rs2);
1580fcf5ef2aSThomas Huth         break;
1581fcf5ef2aSThomas Huth     case 2:
1582ad75a51eSRichard Henderson         gen_helper_fcmped_fcc2(cpu_fsr, tcg_env, r_rs1, r_rs2);
1583fcf5ef2aSThomas Huth         break;
1584fcf5ef2aSThomas Huth     case 3:
1585ad75a51eSRichard Henderson         gen_helper_fcmped_fcc3(cpu_fsr, tcg_env, r_rs1, r_rs2);
1586fcf5ef2aSThomas Huth         break;
1587fcf5ef2aSThomas Huth     }
1588fcf5ef2aSThomas Huth }
1589fcf5ef2aSThomas Huth 
15900c2e96c1SRichard Henderson static void gen_op_fcmpeq(int fccno)
1591fcf5ef2aSThomas Huth {
1592fcf5ef2aSThomas Huth     switch (fccno) {
1593fcf5ef2aSThomas Huth     case 0:
1594ad75a51eSRichard Henderson         gen_helper_fcmpeq(cpu_fsr, tcg_env);
1595fcf5ef2aSThomas Huth         break;
1596fcf5ef2aSThomas Huth     case 1:
1597ad75a51eSRichard Henderson         gen_helper_fcmpeq_fcc1(cpu_fsr, tcg_env);
1598fcf5ef2aSThomas Huth         break;
1599fcf5ef2aSThomas Huth     case 2:
1600ad75a51eSRichard Henderson         gen_helper_fcmpeq_fcc2(cpu_fsr, tcg_env);
1601fcf5ef2aSThomas Huth         break;
1602fcf5ef2aSThomas Huth     case 3:
1603ad75a51eSRichard Henderson         gen_helper_fcmpeq_fcc3(cpu_fsr, tcg_env);
1604fcf5ef2aSThomas Huth         break;
1605fcf5ef2aSThomas Huth     }
1606fcf5ef2aSThomas Huth }
1607fcf5ef2aSThomas Huth 
1608fcf5ef2aSThomas Huth #else
1609fcf5ef2aSThomas Huth 
16100c2e96c1SRichard Henderson static void gen_op_fcmps(int fccno, TCGv r_rs1, TCGv r_rs2)
1611fcf5ef2aSThomas Huth {
1612ad75a51eSRichard Henderson     gen_helper_fcmps(cpu_fsr, tcg_env, r_rs1, r_rs2);
1613fcf5ef2aSThomas Huth }
1614fcf5ef2aSThomas Huth 
16150c2e96c1SRichard Henderson static void gen_op_fcmpd(int fccno, TCGv_i64 r_rs1, TCGv_i64 r_rs2)
1616fcf5ef2aSThomas Huth {
1617ad75a51eSRichard Henderson     gen_helper_fcmpd(cpu_fsr, tcg_env, r_rs1, r_rs2);
1618fcf5ef2aSThomas Huth }
1619fcf5ef2aSThomas Huth 
16200c2e96c1SRichard Henderson static void gen_op_fcmpq(int fccno)
1621fcf5ef2aSThomas Huth {
1622ad75a51eSRichard Henderson     gen_helper_fcmpq(cpu_fsr, tcg_env);
1623fcf5ef2aSThomas Huth }
1624fcf5ef2aSThomas Huth 
16250c2e96c1SRichard Henderson static void gen_op_fcmpes(int fccno, TCGv r_rs1, TCGv r_rs2)
1626fcf5ef2aSThomas Huth {
1627ad75a51eSRichard Henderson     gen_helper_fcmpes(cpu_fsr, tcg_env, r_rs1, r_rs2);
1628fcf5ef2aSThomas Huth }
1629fcf5ef2aSThomas Huth 
16300c2e96c1SRichard Henderson static void gen_op_fcmped(int fccno, TCGv_i64 r_rs1, TCGv_i64 r_rs2)
1631fcf5ef2aSThomas Huth {
1632ad75a51eSRichard Henderson     gen_helper_fcmped(cpu_fsr, tcg_env, r_rs1, r_rs2);
1633fcf5ef2aSThomas Huth }
1634fcf5ef2aSThomas Huth 
16350c2e96c1SRichard Henderson static void gen_op_fcmpeq(int fccno)
1636fcf5ef2aSThomas Huth {
1637ad75a51eSRichard Henderson     gen_helper_fcmpeq(cpu_fsr, tcg_env);
1638fcf5ef2aSThomas Huth }
1639fcf5ef2aSThomas Huth #endif
1640fcf5ef2aSThomas Huth 
1641fcf5ef2aSThomas Huth static void gen_op_fpexception_im(DisasContext *dc, int fsr_flags)
1642fcf5ef2aSThomas Huth {
1643fcf5ef2aSThomas Huth     tcg_gen_andi_tl(cpu_fsr, cpu_fsr, FSR_FTT_NMASK);
1644fcf5ef2aSThomas Huth     tcg_gen_ori_tl(cpu_fsr, cpu_fsr, fsr_flags);
1645fcf5ef2aSThomas Huth     gen_exception(dc, TT_FP_EXCP);
1646fcf5ef2aSThomas Huth }
1647fcf5ef2aSThomas Huth 
1648fcf5ef2aSThomas Huth static int gen_trap_ifnofpu(DisasContext *dc)
1649fcf5ef2aSThomas Huth {
1650fcf5ef2aSThomas Huth #if !defined(CONFIG_USER_ONLY)
1651fcf5ef2aSThomas Huth     if (!dc->fpu_enabled) {
1652fcf5ef2aSThomas Huth         gen_exception(dc, TT_NFPU_INSN);
1653fcf5ef2aSThomas Huth         return 1;
1654fcf5ef2aSThomas Huth     }
1655fcf5ef2aSThomas Huth #endif
1656fcf5ef2aSThomas Huth     return 0;
1657fcf5ef2aSThomas Huth }
1658fcf5ef2aSThomas Huth 
1659fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
16600c2e96c1SRichard Henderson static void gen_ne_fop_QQ(DisasContext *dc, int rd, int rs,
1661fcf5ef2aSThomas Huth                           void (*gen)(TCGv_ptr))
1662fcf5ef2aSThomas Huth {
1663fcf5ef2aSThomas Huth     gen_op_load_fpr_QT1(QFPREG(rs));
1664fcf5ef2aSThomas Huth 
1665ad75a51eSRichard Henderson     gen(tcg_env);
1666fcf5ef2aSThomas Huth 
1667fcf5ef2aSThomas Huth     gen_op_store_QT0_fpr(QFPREG(rd));
1668fcf5ef2aSThomas Huth     gen_update_fprs_dirty(dc, QFPREG(rd));
1669fcf5ef2aSThomas Huth }
1670fcf5ef2aSThomas Huth #endif
1671fcf5ef2aSThomas Huth 
16720c2e96c1SRichard Henderson static void gen_fop_QDD(DisasContext *dc, int rd, int rs1, int rs2,
1673fcf5ef2aSThomas Huth                         void (*gen)(TCGv_ptr, TCGv_i64, TCGv_i64))
1674fcf5ef2aSThomas Huth {
1675fcf5ef2aSThomas Huth     TCGv_i64 src1, src2;
1676fcf5ef2aSThomas Huth 
1677fcf5ef2aSThomas Huth     src1 = gen_load_fpr_D(dc, rs1);
1678fcf5ef2aSThomas Huth     src2 = gen_load_fpr_D(dc, rs2);
1679fcf5ef2aSThomas Huth 
1680ad75a51eSRichard Henderson     gen(tcg_env, src1, src2);
1681ad75a51eSRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
1682fcf5ef2aSThomas Huth 
1683fcf5ef2aSThomas Huth     gen_op_store_QT0_fpr(QFPREG(rd));
1684fcf5ef2aSThomas Huth     gen_update_fprs_dirty(dc, QFPREG(rd));
1685fcf5ef2aSThomas Huth }
1686fcf5ef2aSThomas Huth 
1687fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
16880c2e96c1SRichard Henderson static void gen_fop_DF(DisasContext *dc, int rd, int rs,
1689fcf5ef2aSThomas Huth                        void (*gen)(TCGv_i64, TCGv_ptr, TCGv_i32))
1690fcf5ef2aSThomas Huth {
1691fcf5ef2aSThomas Huth     TCGv_i64 dst;
1692fcf5ef2aSThomas Huth     TCGv_i32 src;
1693fcf5ef2aSThomas Huth 
1694fcf5ef2aSThomas Huth     src = gen_load_fpr_F(dc, rs);
1695fcf5ef2aSThomas Huth     dst = gen_dest_fpr_D(dc, rd);
1696fcf5ef2aSThomas Huth 
1697ad75a51eSRichard Henderson     gen(dst, tcg_env, src);
1698ad75a51eSRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
1699fcf5ef2aSThomas Huth 
1700fcf5ef2aSThomas Huth     gen_store_fpr_D(dc, rd, dst);
1701fcf5ef2aSThomas Huth }
1702fcf5ef2aSThomas Huth #endif
1703fcf5ef2aSThomas Huth 
17040c2e96c1SRichard Henderson static void gen_ne_fop_DF(DisasContext *dc, int rd, int rs,
1705fcf5ef2aSThomas Huth                           void (*gen)(TCGv_i64, TCGv_ptr, TCGv_i32))
1706fcf5ef2aSThomas Huth {
1707fcf5ef2aSThomas Huth     TCGv_i64 dst;
1708fcf5ef2aSThomas Huth     TCGv_i32 src;
1709fcf5ef2aSThomas Huth 
1710fcf5ef2aSThomas Huth     src = gen_load_fpr_F(dc, rs);
1711fcf5ef2aSThomas Huth     dst = gen_dest_fpr_D(dc, rd);
1712fcf5ef2aSThomas Huth 
1713ad75a51eSRichard Henderson     gen(dst, tcg_env, src);
1714fcf5ef2aSThomas Huth 
1715fcf5ef2aSThomas Huth     gen_store_fpr_D(dc, rd, dst);
1716fcf5ef2aSThomas Huth }
1717fcf5ef2aSThomas Huth 
17180c2e96c1SRichard Henderson static void gen_fop_FD(DisasContext *dc, int rd, int rs,
1719fcf5ef2aSThomas Huth                        void (*gen)(TCGv_i32, TCGv_ptr, TCGv_i64))
1720fcf5ef2aSThomas Huth {
1721fcf5ef2aSThomas Huth     TCGv_i32 dst;
1722fcf5ef2aSThomas Huth     TCGv_i64 src;
1723fcf5ef2aSThomas Huth 
1724fcf5ef2aSThomas Huth     src = gen_load_fpr_D(dc, rs);
1725fcf5ef2aSThomas Huth     dst = gen_dest_fpr_F(dc);
1726fcf5ef2aSThomas Huth 
1727ad75a51eSRichard Henderson     gen(dst, tcg_env, src);
1728ad75a51eSRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
1729fcf5ef2aSThomas Huth 
1730fcf5ef2aSThomas Huth     gen_store_fpr_F(dc, rd, dst);
1731fcf5ef2aSThomas Huth }
1732fcf5ef2aSThomas Huth 
17330c2e96c1SRichard Henderson static void gen_fop_FQ(DisasContext *dc, int rd, int rs,
1734fcf5ef2aSThomas Huth                        void (*gen)(TCGv_i32, TCGv_ptr))
1735fcf5ef2aSThomas Huth {
1736fcf5ef2aSThomas Huth     TCGv_i32 dst;
1737fcf5ef2aSThomas Huth 
1738fcf5ef2aSThomas Huth     gen_op_load_fpr_QT1(QFPREG(rs));
1739fcf5ef2aSThomas Huth     dst = gen_dest_fpr_F(dc);
1740fcf5ef2aSThomas Huth 
1741ad75a51eSRichard Henderson     gen(dst, tcg_env);
1742ad75a51eSRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
1743fcf5ef2aSThomas Huth 
1744fcf5ef2aSThomas Huth     gen_store_fpr_F(dc, rd, dst);
1745fcf5ef2aSThomas Huth }
1746fcf5ef2aSThomas Huth 
17470c2e96c1SRichard Henderson static void gen_fop_DQ(DisasContext *dc, int rd, int rs,
1748fcf5ef2aSThomas Huth                        void (*gen)(TCGv_i64, TCGv_ptr))
1749fcf5ef2aSThomas Huth {
1750fcf5ef2aSThomas Huth     TCGv_i64 dst;
1751fcf5ef2aSThomas Huth 
1752fcf5ef2aSThomas Huth     gen_op_load_fpr_QT1(QFPREG(rs));
1753fcf5ef2aSThomas Huth     dst = gen_dest_fpr_D(dc, rd);
1754fcf5ef2aSThomas Huth 
1755ad75a51eSRichard Henderson     gen(dst, tcg_env);
1756ad75a51eSRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
1757fcf5ef2aSThomas Huth 
1758fcf5ef2aSThomas Huth     gen_store_fpr_D(dc, rd, dst);
1759fcf5ef2aSThomas Huth }
1760fcf5ef2aSThomas Huth 
17610c2e96c1SRichard Henderson static void gen_ne_fop_QF(DisasContext *dc, int rd, int rs,
1762fcf5ef2aSThomas Huth                           void (*gen)(TCGv_ptr, TCGv_i32))
1763fcf5ef2aSThomas Huth {
1764fcf5ef2aSThomas Huth     TCGv_i32 src;
1765fcf5ef2aSThomas Huth 
1766fcf5ef2aSThomas Huth     src = gen_load_fpr_F(dc, rs);
1767fcf5ef2aSThomas Huth 
1768ad75a51eSRichard Henderson     gen(tcg_env, src);
1769fcf5ef2aSThomas Huth 
1770fcf5ef2aSThomas Huth     gen_op_store_QT0_fpr(QFPREG(rd));
1771fcf5ef2aSThomas Huth     gen_update_fprs_dirty(dc, QFPREG(rd));
1772fcf5ef2aSThomas Huth }
1773fcf5ef2aSThomas Huth 
17740c2e96c1SRichard Henderson static void gen_ne_fop_QD(DisasContext *dc, int rd, int rs,
1775fcf5ef2aSThomas Huth                           void (*gen)(TCGv_ptr, TCGv_i64))
1776fcf5ef2aSThomas Huth {
1777fcf5ef2aSThomas Huth     TCGv_i64 src;
1778fcf5ef2aSThomas Huth 
1779fcf5ef2aSThomas Huth     src = gen_load_fpr_D(dc, rs);
1780fcf5ef2aSThomas Huth 
1781ad75a51eSRichard Henderson     gen(tcg_env, src);
1782fcf5ef2aSThomas Huth 
1783fcf5ef2aSThomas Huth     gen_op_store_QT0_fpr(QFPREG(rd));
1784fcf5ef2aSThomas Huth     gen_update_fprs_dirty(dc, QFPREG(rd));
1785fcf5ef2aSThomas Huth }
1786fcf5ef2aSThomas Huth 
1787fcf5ef2aSThomas Huth /* asi moves */
1788fcf5ef2aSThomas Huth typedef enum {
1789fcf5ef2aSThomas Huth     GET_ASI_HELPER,
1790fcf5ef2aSThomas Huth     GET_ASI_EXCP,
1791fcf5ef2aSThomas Huth     GET_ASI_DIRECT,
1792fcf5ef2aSThomas Huth     GET_ASI_DTWINX,
1793fcf5ef2aSThomas Huth     GET_ASI_BLOCK,
1794fcf5ef2aSThomas Huth     GET_ASI_SHORT,
1795fcf5ef2aSThomas Huth     GET_ASI_BCOPY,
1796fcf5ef2aSThomas Huth     GET_ASI_BFILL,
1797fcf5ef2aSThomas Huth } ASIType;
1798fcf5ef2aSThomas Huth 
1799fcf5ef2aSThomas Huth typedef struct {
1800fcf5ef2aSThomas Huth     ASIType type;
1801fcf5ef2aSThomas Huth     int asi;
1802fcf5ef2aSThomas Huth     int mem_idx;
180314776ab5STony Nguyen     MemOp memop;
1804fcf5ef2aSThomas Huth } DisasASI;
1805fcf5ef2aSThomas Huth 
1806811cc0b0SRichard Henderson /*
1807811cc0b0SRichard Henderson  * Build DisasASI.
1808811cc0b0SRichard Henderson  * For asi == -1, treat as non-asi.
1809811cc0b0SRichard Henderson  * For ask == -2, treat as immediate offset (v8 error, v9 %asi).
1810811cc0b0SRichard Henderson  */
1811811cc0b0SRichard Henderson static DisasASI resolve_asi(DisasContext *dc, int asi, MemOp memop)
1812fcf5ef2aSThomas Huth {
1813fcf5ef2aSThomas Huth     ASIType type = GET_ASI_HELPER;
1814fcf5ef2aSThomas Huth     int mem_idx = dc->mem_idx;
1815fcf5ef2aSThomas Huth 
1816811cc0b0SRichard Henderson     if (asi == -1) {
1817811cc0b0SRichard Henderson         /* Artificial "non-asi" case. */
1818811cc0b0SRichard Henderson         type = GET_ASI_DIRECT;
1819811cc0b0SRichard Henderson         goto done;
1820811cc0b0SRichard Henderson     }
1821811cc0b0SRichard Henderson 
1822fcf5ef2aSThomas Huth #ifndef TARGET_SPARC64
1823fcf5ef2aSThomas Huth     /* Before v9, all asis are immediate and privileged.  */
1824811cc0b0SRichard Henderson     if (asi < 0) {
1825fcf5ef2aSThomas Huth         gen_exception(dc, TT_ILL_INSN);
1826fcf5ef2aSThomas Huth         type = GET_ASI_EXCP;
1827fcf5ef2aSThomas Huth     } else if (supervisor(dc)
1828fcf5ef2aSThomas Huth                /* Note that LEON accepts ASI_USERDATA in user mode, for
1829fcf5ef2aSThomas Huth                   use with CASA.  Also note that previous versions of
1830fcf5ef2aSThomas Huth                   QEMU allowed (and old versions of gcc emitted) ASI_P
1831fcf5ef2aSThomas Huth                   for LEON, which is incorrect.  */
1832fcf5ef2aSThomas Huth                || (asi == ASI_USERDATA
1833fcf5ef2aSThomas Huth                    && (dc->def->features & CPU_FEATURE_CASA))) {
1834fcf5ef2aSThomas Huth         switch (asi) {
1835fcf5ef2aSThomas Huth         case ASI_USERDATA:   /* User data access */
1836fcf5ef2aSThomas Huth             mem_idx = MMU_USER_IDX;
1837fcf5ef2aSThomas Huth             type = GET_ASI_DIRECT;
1838fcf5ef2aSThomas Huth             break;
1839fcf5ef2aSThomas Huth         case ASI_KERNELDATA: /* Supervisor data access */
1840fcf5ef2aSThomas Huth             mem_idx = MMU_KERNEL_IDX;
1841fcf5ef2aSThomas Huth             type = GET_ASI_DIRECT;
1842fcf5ef2aSThomas Huth             break;
1843fcf5ef2aSThomas Huth         case ASI_M_BYPASS:    /* MMU passthrough */
1844fcf5ef2aSThomas Huth         case ASI_LEON_BYPASS: /* LEON MMU passthrough */
1845fcf5ef2aSThomas Huth             mem_idx = MMU_PHYS_IDX;
1846fcf5ef2aSThomas Huth             type = GET_ASI_DIRECT;
1847fcf5ef2aSThomas Huth             break;
1848fcf5ef2aSThomas Huth         case ASI_M_BCOPY: /* Block copy, sta access */
1849fcf5ef2aSThomas Huth             mem_idx = MMU_KERNEL_IDX;
1850fcf5ef2aSThomas Huth             type = GET_ASI_BCOPY;
1851fcf5ef2aSThomas Huth             break;
1852fcf5ef2aSThomas Huth         case ASI_M_BFILL: /* Block fill, stda access */
1853fcf5ef2aSThomas Huth             mem_idx = MMU_KERNEL_IDX;
1854fcf5ef2aSThomas Huth             type = GET_ASI_BFILL;
1855fcf5ef2aSThomas Huth             break;
1856fcf5ef2aSThomas Huth         }
18576e10f37cSKONRAD Frederic 
18586e10f37cSKONRAD Frederic         /* MMU_PHYS_IDX is used when the MMU is disabled to passthrough the
18596e10f37cSKONRAD Frederic          * permissions check in get_physical_address(..).
18606e10f37cSKONRAD Frederic          */
18616e10f37cSKONRAD Frederic         mem_idx = (dc->mem_idx == MMU_PHYS_IDX) ? MMU_PHYS_IDX : mem_idx;
1862fcf5ef2aSThomas Huth     } else {
1863fcf5ef2aSThomas Huth         gen_exception(dc, TT_PRIV_INSN);
1864fcf5ef2aSThomas Huth         type = GET_ASI_EXCP;
1865fcf5ef2aSThomas Huth     }
1866fcf5ef2aSThomas Huth #else
1867811cc0b0SRichard Henderson     if (asi < 0) {
1868fcf5ef2aSThomas Huth         asi = dc->asi;
1869fcf5ef2aSThomas Huth     }
1870fcf5ef2aSThomas Huth     /* With v9, all asis below 0x80 are privileged.  */
1871fcf5ef2aSThomas Huth     /* ??? We ought to check cpu_has_hypervisor, but we didn't copy
1872fcf5ef2aSThomas Huth        down that bit into DisasContext.  For the moment that's ok,
1873fcf5ef2aSThomas Huth        since the direct implementations below doesn't have any ASIs
1874fcf5ef2aSThomas Huth        in the restricted [0x30, 0x7f] range, and the check will be
1875fcf5ef2aSThomas Huth        done properly in the helper.  */
1876fcf5ef2aSThomas Huth     if (!supervisor(dc) && asi < 0x80) {
1877fcf5ef2aSThomas Huth         gen_exception(dc, TT_PRIV_ACT);
1878fcf5ef2aSThomas Huth         type = GET_ASI_EXCP;
1879fcf5ef2aSThomas Huth     } else {
1880fcf5ef2aSThomas Huth         switch (asi) {
1881fcf5ef2aSThomas Huth         case ASI_REAL:      /* Bypass */
1882fcf5ef2aSThomas Huth         case ASI_REAL_IO:   /* Bypass, non-cacheable */
1883fcf5ef2aSThomas Huth         case ASI_REAL_L:    /* Bypass LE */
1884fcf5ef2aSThomas Huth         case ASI_REAL_IO_L: /* Bypass, non-cacheable LE */
1885fcf5ef2aSThomas Huth         case ASI_TWINX_REAL:   /* Real address, twinx */
1886fcf5ef2aSThomas Huth         case ASI_TWINX_REAL_L: /* Real address, twinx, LE */
1887fcf5ef2aSThomas Huth         case ASI_QUAD_LDD_PHYS:
1888fcf5ef2aSThomas Huth         case ASI_QUAD_LDD_PHYS_L:
1889fcf5ef2aSThomas Huth             mem_idx = MMU_PHYS_IDX;
1890fcf5ef2aSThomas Huth             break;
1891fcf5ef2aSThomas Huth         case ASI_N:  /* Nucleus */
1892fcf5ef2aSThomas Huth         case ASI_NL: /* Nucleus LE */
1893fcf5ef2aSThomas Huth         case ASI_TWINX_N:
1894fcf5ef2aSThomas Huth         case ASI_TWINX_NL:
1895fcf5ef2aSThomas Huth         case ASI_NUCLEUS_QUAD_LDD:
1896fcf5ef2aSThomas Huth         case ASI_NUCLEUS_QUAD_LDD_L:
18979a10756dSArtyom Tarasenko             if (hypervisor(dc)) {
189884f8f587SArtyom Tarasenko                 mem_idx = MMU_PHYS_IDX;
18999a10756dSArtyom Tarasenko             } else {
1900fcf5ef2aSThomas Huth                 mem_idx = MMU_NUCLEUS_IDX;
19019a10756dSArtyom Tarasenko             }
1902fcf5ef2aSThomas Huth             break;
1903fcf5ef2aSThomas Huth         case ASI_AIUP:  /* As if user primary */
1904fcf5ef2aSThomas Huth         case ASI_AIUPL: /* As if user primary LE */
1905fcf5ef2aSThomas Huth         case ASI_TWINX_AIUP:
1906fcf5ef2aSThomas Huth         case ASI_TWINX_AIUP_L:
1907fcf5ef2aSThomas Huth         case ASI_BLK_AIUP_4V:
1908fcf5ef2aSThomas Huth         case ASI_BLK_AIUP_L_4V:
1909fcf5ef2aSThomas Huth         case ASI_BLK_AIUP:
1910fcf5ef2aSThomas Huth         case ASI_BLK_AIUPL:
1911fcf5ef2aSThomas Huth             mem_idx = MMU_USER_IDX;
1912fcf5ef2aSThomas Huth             break;
1913fcf5ef2aSThomas Huth         case ASI_AIUS:  /* As if user secondary */
1914fcf5ef2aSThomas Huth         case ASI_AIUSL: /* As if user secondary LE */
1915fcf5ef2aSThomas Huth         case ASI_TWINX_AIUS:
1916fcf5ef2aSThomas Huth         case ASI_TWINX_AIUS_L:
1917fcf5ef2aSThomas Huth         case ASI_BLK_AIUS_4V:
1918fcf5ef2aSThomas Huth         case ASI_BLK_AIUS_L_4V:
1919fcf5ef2aSThomas Huth         case ASI_BLK_AIUS:
1920fcf5ef2aSThomas Huth         case ASI_BLK_AIUSL:
1921fcf5ef2aSThomas Huth             mem_idx = MMU_USER_SECONDARY_IDX;
1922fcf5ef2aSThomas Huth             break;
1923fcf5ef2aSThomas Huth         case ASI_S:  /* Secondary */
1924fcf5ef2aSThomas Huth         case ASI_SL: /* Secondary LE */
1925fcf5ef2aSThomas Huth         case ASI_TWINX_S:
1926fcf5ef2aSThomas Huth         case ASI_TWINX_SL:
1927fcf5ef2aSThomas Huth         case ASI_BLK_COMMIT_S:
1928fcf5ef2aSThomas Huth         case ASI_BLK_S:
1929fcf5ef2aSThomas Huth         case ASI_BLK_SL:
1930fcf5ef2aSThomas Huth         case ASI_FL8_S:
1931fcf5ef2aSThomas Huth         case ASI_FL8_SL:
1932fcf5ef2aSThomas Huth         case ASI_FL16_S:
1933fcf5ef2aSThomas Huth         case ASI_FL16_SL:
1934fcf5ef2aSThomas Huth             if (mem_idx == MMU_USER_IDX) {
1935fcf5ef2aSThomas Huth                 mem_idx = MMU_USER_SECONDARY_IDX;
1936fcf5ef2aSThomas Huth             } else if (mem_idx == MMU_KERNEL_IDX) {
1937fcf5ef2aSThomas Huth                 mem_idx = MMU_KERNEL_SECONDARY_IDX;
1938fcf5ef2aSThomas Huth             }
1939fcf5ef2aSThomas Huth             break;
1940fcf5ef2aSThomas Huth         case ASI_P:  /* Primary */
1941fcf5ef2aSThomas Huth         case ASI_PL: /* Primary LE */
1942fcf5ef2aSThomas Huth         case ASI_TWINX_P:
1943fcf5ef2aSThomas Huth         case ASI_TWINX_PL:
1944fcf5ef2aSThomas Huth         case ASI_BLK_COMMIT_P:
1945fcf5ef2aSThomas Huth         case ASI_BLK_P:
1946fcf5ef2aSThomas Huth         case ASI_BLK_PL:
1947fcf5ef2aSThomas Huth         case ASI_FL8_P:
1948fcf5ef2aSThomas Huth         case ASI_FL8_PL:
1949fcf5ef2aSThomas Huth         case ASI_FL16_P:
1950fcf5ef2aSThomas Huth         case ASI_FL16_PL:
1951fcf5ef2aSThomas Huth             break;
1952fcf5ef2aSThomas Huth         }
1953fcf5ef2aSThomas Huth         switch (asi) {
1954fcf5ef2aSThomas Huth         case ASI_REAL:
1955fcf5ef2aSThomas Huth         case ASI_REAL_IO:
1956fcf5ef2aSThomas Huth         case ASI_REAL_L:
1957fcf5ef2aSThomas Huth         case ASI_REAL_IO_L:
1958fcf5ef2aSThomas Huth         case ASI_N:
1959fcf5ef2aSThomas Huth         case ASI_NL:
1960fcf5ef2aSThomas Huth         case ASI_AIUP:
1961fcf5ef2aSThomas Huth         case ASI_AIUPL:
1962fcf5ef2aSThomas Huth         case ASI_AIUS:
1963fcf5ef2aSThomas Huth         case ASI_AIUSL:
1964fcf5ef2aSThomas Huth         case ASI_S:
1965fcf5ef2aSThomas Huth         case ASI_SL:
1966fcf5ef2aSThomas Huth         case ASI_P:
1967fcf5ef2aSThomas Huth         case ASI_PL:
1968fcf5ef2aSThomas Huth             type = GET_ASI_DIRECT;
1969fcf5ef2aSThomas Huth             break;
1970fcf5ef2aSThomas Huth         case ASI_TWINX_REAL:
1971fcf5ef2aSThomas Huth         case ASI_TWINX_REAL_L:
1972fcf5ef2aSThomas Huth         case ASI_TWINX_N:
1973fcf5ef2aSThomas Huth         case ASI_TWINX_NL:
1974fcf5ef2aSThomas Huth         case ASI_TWINX_AIUP:
1975fcf5ef2aSThomas Huth         case ASI_TWINX_AIUP_L:
1976fcf5ef2aSThomas Huth         case ASI_TWINX_AIUS:
1977fcf5ef2aSThomas Huth         case ASI_TWINX_AIUS_L:
1978fcf5ef2aSThomas Huth         case ASI_TWINX_P:
1979fcf5ef2aSThomas Huth         case ASI_TWINX_PL:
1980fcf5ef2aSThomas Huth         case ASI_TWINX_S:
1981fcf5ef2aSThomas Huth         case ASI_TWINX_SL:
1982fcf5ef2aSThomas Huth         case ASI_QUAD_LDD_PHYS:
1983fcf5ef2aSThomas Huth         case ASI_QUAD_LDD_PHYS_L:
1984fcf5ef2aSThomas Huth         case ASI_NUCLEUS_QUAD_LDD:
1985fcf5ef2aSThomas Huth         case ASI_NUCLEUS_QUAD_LDD_L:
1986fcf5ef2aSThomas Huth             type = GET_ASI_DTWINX;
1987fcf5ef2aSThomas Huth             break;
1988fcf5ef2aSThomas Huth         case ASI_BLK_COMMIT_P:
1989fcf5ef2aSThomas Huth         case ASI_BLK_COMMIT_S:
1990fcf5ef2aSThomas Huth         case ASI_BLK_AIUP_4V:
1991fcf5ef2aSThomas Huth         case ASI_BLK_AIUP_L_4V:
1992fcf5ef2aSThomas Huth         case ASI_BLK_AIUP:
1993fcf5ef2aSThomas Huth         case ASI_BLK_AIUPL:
1994fcf5ef2aSThomas Huth         case ASI_BLK_AIUS_4V:
1995fcf5ef2aSThomas Huth         case ASI_BLK_AIUS_L_4V:
1996fcf5ef2aSThomas Huth         case ASI_BLK_AIUS:
1997fcf5ef2aSThomas Huth         case ASI_BLK_AIUSL:
1998fcf5ef2aSThomas Huth         case ASI_BLK_S:
1999fcf5ef2aSThomas Huth         case ASI_BLK_SL:
2000fcf5ef2aSThomas Huth         case ASI_BLK_P:
2001fcf5ef2aSThomas Huth         case ASI_BLK_PL:
2002fcf5ef2aSThomas Huth             type = GET_ASI_BLOCK;
2003fcf5ef2aSThomas Huth             break;
2004fcf5ef2aSThomas Huth         case ASI_FL8_S:
2005fcf5ef2aSThomas Huth         case ASI_FL8_SL:
2006fcf5ef2aSThomas Huth         case ASI_FL8_P:
2007fcf5ef2aSThomas Huth         case ASI_FL8_PL:
2008fcf5ef2aSThomas Huth             memop = MO_UB;
2009fcf5ef2aSThomas Huth             type = GET_ASI_SHORT;
2010fcf5ef2aSThomas Huth             break;
2011fcf5ef2aSThomas Huth         case ASI_FL16_S:
2012fcf5ef2aSThomas Huth         case ASI_FL16_SL:
2013fcf5ef2aSThomas Huth         case ASI_FL16_P:
2014fcf5ef2aSThomas Huth         case ASI_FL16_PL:
2015fcf5ef2aSThomas Huth             memop = MO_TEUW;
2016fcf5ef2aSThomas Huth             type = GET_ASI_SHORT;
2017fcf5ef2aSThomas Huth             break;
2018fcf5ef2aSThomas Huth         }
2019fcf5ef2aSThomas Huth         /* The little-endian asis all have bit 3 set.  */
2020fcf5ef2aSThomas Huth         if (asi & 8) {
2021fcf5ef2aSThomas Huth             memop ^= MO_BSWAP;
2022fcf5ef2aSThomas Huth         }
2023fcf5ef2aSThomas Huth     }
2024fcf5ef2aSThomas Huth #endif
2025fcf5ef2aSThomas Huth 
2026811cc0b0SRichard Henderson  done:
2027fcf5ef2aSThomas Huth     return (DisasASI){ type, asi, mem_idx, memop };
2028fcf5ef2aSThomas Huth }
2029fcf5ef2aSThomas Huth 
2030a76779eeSRichard Henderson #if defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
2031a76779eeSRichard Henderson static void gen_helper_ld_asi(TCGv_i64 r, TCGv_env e, TCGv a,
2032a76779eeSRichard Henderson                               TCGv_i32 asi, TCGv_i32 mop)
2033a76779eeSRichard Henderson {
2034a76779eeSRichard Henderson     g_assert_not_reached();
2035a76779eeSRichard Henderson }
2036a76779eeSRichard Henderson 
2037a76779eeSRichard Henderson static void gen_helper_st_asi(TCGv_env e, TCGv a, TCGv_i64 r,
2038a76779eeSRichard Henderson                               TCGv_i32 asi, TCGv_i32 mop)
2039a76779eeSRichard Henderson {
2040a76779eeSRichard Henderson     g_assert_not_reached();
2041a76779eeSRichard Henderson }
2042a76779eeSRichard Henderson #endif
2043a76779eeSRichard Henderson 
204442071fc1SRichard Henderson static void gen_ld_asi(DisasContext *dc, DisasASI *da, TCGv dst, TCGv addr)
2045fcf5ef2aSThomas Huth {
2046c03a0fd1SRichard Henderson     switch (da->type) {
2047fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
2048fcf5ef2aSThomas Huth         break;
2049fcf5ef2aSThomas Huth     case GET_ASI_DTWINX: /* Reserved for ldda.  */
2050fcf5ef2aSThomas Huth         gen_exception(dc, TT_ILL_INSN);
2051fcf5ef2aSThomas Huth         break;
2052fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
2053c03a0fd1SRichard Henderson         tcg_gen_qemu_ld_tl(dst, addr, da->mem_idx, da->memop | MO_ALIGN);
2054fcf5ef2aSThomas Huth         break;
2055fcf5ef2aSThomas Huth     default:
2056fcf5ef2aSThomas Huth         {
2057c03a0fd1SRichard Henderson             TCGv_i32 r_asi = tcg_constant_i32(da->asi);
2058c03a0fd1SRichard Henderson             TCGv_i32 r_mop = tcg_constant_i32(da->memop | MO_ALIGN);
2059fcf5ef2aSThomas Huth 
2060fcf5ef2aSThomas Huth             save_state(dc);
2061fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
2062ad75a51eSRichard Henderson             gen_helper_ld_asi(dst, tcg_env, addr, r_asi, r_mop);
2063fcf5ef2aSThomas Huth #else
2064fcf5ef2aSThomas Huth             {
2065fcf5ef2aSThomas Huth                 TCGv_i64 t64 = tcg_temp_new_i64();
2066ad75a51eSRichard Henderson                 gen_helper_ld_asi(t64, tcg_env, addr, r_asi, r_mop);
2067fcf5ef2aSThomas Huth                 tcg_gen_trunc_i64_tl(dst, t64);
2068fcf5ef2aSThomas Huth             }
2069fcf5ef2aSThomas Huth #endif
2070fcf5ef2aSThomas Huth         }
2071fcf5ef2aSThomas Huth         break;
2072fcf5ef2aSThomas Huth     }
2073fcf5ef2aSThomas Huth }
2074fcf5ef2aSThomas Huth 
207542071fc1SRichard Henderson static void gen_st_asi(DisasContext *dc, DisasASI *da, TCGv src, TCGv addr)
2076c03a0fd1SRichard Henderson {
2077c03a0fd1SRichard Henderson     switch (da->type) {
2078fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
2079fcf5ef2aSThomas Huth         break;
2080c03a0fd1SRichard Henderson 
2081fcf5ef2aSThomas Huth     case GET_ASI_DTWINX: /* Reserved for stda.  */
2082c03a0fd1SRichard Henderson         if (TARGET_LONG_BITS == 32) {
2083fcf5ef2aSThomas Huth             gen_exception(dc, TT_ILL_INSN);
2084fcf5ef2aSThomas Huth             break;
2085c03a0fd1SRichard Henderson         } else if (!(dc->def->features & CPU_FEATURE_HYPV)) {
20863390537bSArtyom Tarasenko             /* Pre OpenSPARC CPUs don't have these */
20873390537bSArtyom Tarasenko             gen_exception(dc, TT_ILL_INSN);
2088fcf5ef2aSThomas Huth             break;
2089c03a0fd1SRichard Henderson         }
2090c03a0fd1SRichard Henderson         /* In OpenSPARC T1+ CPUs TWINX ASIs in store are ST_BLKINIT_ ASIs */
2091c03a0fd1SRichard Henderson         /* fall through */
2092c03a0fd1SRichard Henderson 
2093c03a0fd1SRichard Henderson     case GET_ASI_DIRECT:
2094c03a0fd1SRichard Henderson         tcg_gen_qemu_st_tl(src, addr, da->mem_idx, da->memop | MO_ALIGN);
2095c03a0fd1SRichard Henderson         break;
2096c03a0fd1SRichard Henderson 
2097fcf5ef2aSThomas Huth     case GET_ASI_BCOPY:
2098c03a0fd1SRichard Henderson         assert(TARGET_LONG_BITS == 32);
2099fcf5ef2aSThomas Huth         /* Copy 32 bytes from the address in SRC to ADDR.  */
2100fcf5ef2aSThomas Huth         /* ??? The original qemu code suggests 4-byte alignment, dropping
2101fcf5ef2aSThomas Huth            the low bits, but the only place I can see this used is in the
2102fcf5ef2aSThomas Huth            Linux kernel with 32 byte alignment, which would make more sense
2103fcf5ef2aSThomas Huth            as a cacheline-style operation.  */
2104fcf5ef2aSThomas Huth         {
2105fcf5ef2aSThomas Huth             TCGv saddr = tcg_temp_new();
2106fcf5ef2aSThomas Huth             TCGv daddr = tcg_temp_new();
210700ab7e61SRichard Henderson             TCGv four = tcg_constant_tl(4);
2108fcf5ef2aSThomas Huth             TCGv_i32 tmp = tcg_temp_new_i32();
2109fcf5ef2aSThomas Huth             int i;
2110fcf5ef2aSThomas Huth 
2111fcf5ef2aSThomas Huth             tcg_gen_andi_tl(saddr, src, -4);
2112fcf5ef2aSThomas Huth             tcg_gen_andi_tl(daddr, addr, -4);
2113fcf5ef2aSThomas Huth             for (i = 0; i < 32; i += 4) {
2114fcf5ef2aSThomas Huth                 /* Since the loads and stores are paired, allow the
2115fcf5ef2aSThomas Huth                    copy to happen in the host endianness.  */
2116c03a0fd1SRichard Henderson                 tcg_gen_qemu_ld_i32(tmp, saddr, da->mem_idx, MO_UL);
2117c03a0fd1SRichard Henderson                 tcg_gen_qemu_st_i32(tmp, daddr, da->mem_idx, MO_UL);
2118fcf5ef2aSThomas Huth                 tcg_gen_add_tl(saddr, saddr, four);
2119fcf5ef2aSThomas Huth                 tcg_gen_add_tl(daddr, daddr, four);
2120fcf5ef2aSThomas Huth             }
2121fcf5ef2aSThomas Huth         }
2122fcf5ef2aSThomas Huth         break;
2123c03a0fd1SRichard Henderson 
2124fcf5ef2aSThomas Huth     default:
2125fcf5ef2aSThomas Huth         {
2126c03a0fd1SRichard Henderson             TCGv_i32 r_asi = tcg_constant_i32(da->asi);
2127c03a0fd1SRichard Henderson             TCGv_i32 r_mop = tcg_constant_i32(da->memop | MO_ALIGN);
2128fcf5ef2aSThomas Huth 
2129fcf5ef2aSThomas Huth             save_state(dc);
2130fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
2131ad75a51eSRichard Henderson             gen_helper_st_asi(tcg_env, addr, src, r_asi, r_mop);
2132fcf5ef2aSThomas Huth #else
2133fcf5ef2aSThomas Huth             {
2134fcf5ef2aSThomas Huth                 TCGv_i64 t64 = tcg_temp_new_i64();
2135fcf5ef2aSThomas Huth                 tcg_gen_extu_tl_i64(t64, src);
2136ad75a51eSRichard Henderson                 gen_helper_st_asi(tcg_env, addr, t64, r_asi, r_mop);
2137fcf5ef2aSThomas Huth             }
2138fcf5ef2aSThomas Huth #endif
2139fcf5ef2aSThomas Huth 
2140fcf5ef2aSThomas Huth             /* A write to a TLB register may alter page maps.  End the TB. */
2141fcf5ef2aSThomas Huth             dc->npc = DYNAMIC_PC;
2142fcf5ef2aSThomas Huth         }
2143fcf5ef2aSThomas Huth         break;
2144fcf5ef2aSThomas Huth     }
2145fcf5ef2aSThomas Huth }
2146fcf5ef2aSThomas Huth 
2147dca544b9SRichard Henderson static void gen_swap_asi(DisasContext *dc, DisasASI *da,
2148c03a0fd1SRichard Henderson                          TCGv dst, TCGv src, TCGv addr)
2149c03a0fd1SRichard Henderson {
2150c03a0fd1SRichard Henderson     switch (da->type) {
2151c03a0fd1SRichard Henderson     case GET_ASI_EXCP:
2152c03a0fd1SRichard Henderson         break;
2153c03a0fd1SRichard Henderson     case GET_ASI_DIRECT:
2154dca544b9SRichard Henderson         tcg_gen_atomic_xchg_tl(dst, addr, src,
2155dca544b9SRichard Henderson                                da->mem_idx, da->memop | MO_ALIGN);
2156c03a0fd1SRichard Henderson         break;
2157c03a0fd1SRichard Henderson     default:
2158c03a0fd1SRichard Henderson         /* ??? Should be DAE_invalid_asi.  */
2159c03a0fd1SRichard Henderson         gen_exception(dc, TT_DATA_ACCESS);
2160c03a0fd1SRichard Henderson         break;
2161c03a0fd1SRichard Henderson     }
2162c03a0fd1SRichard Henderson }
2163c03a0fd1SRichard Henderson 
2164d0a11d25SRichard Henderson static void gen_cas_asi(DisasContext *dc, DisasASI *da,
2165c03a0fd1SRichard Henderson                         TCGv oldv, TCGv newv, TCGv cmpv, TCGv addr)
2166c03a0fd1SRichard Henderson {
2167c03a0fd1SRichard Henderson     switch (da->type) {
2168fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
2169c03a0fd1SRichard Henderson         return;
2170fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
2171c03a0fd1SRichard Henderson         tcg_gen_atomic_cmpxchg_tl(oldv, addr, cmpv, newv,
2172c03a0fd1SRichard Henderson                                   da->mem_idx, da->memop | MO_ALIGN);
2173fcf5ef2aSThomas Huth         break;
2174fcf5ef2aSThomas Huth     default:
2175fcf5ef2aSThomas Huth         /* ??? Should be DAE_invalid_asi.  */
2176fcf5ef2aSThomas Huth         gen_exception(dc, TT_DATA_ACCESS);
2177fcf5ef2aSThomas Huth         break;
2178fcf5ef2aSThomas Huth     }
2179fcf5ef2aSThomas Huth }
2180fcf5ef2aSThomas Huth 
2181cf07cd1eSRichard Henderson static void gen_ldstub_asi(DisasContext *dc, DisasASI *da, TCGv dst, TCGv addr)
2182c03a0fd1SRichard Henderson {
2183c03a0fd1SRichard Henderson     switch (da->type) {
2184fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
2185fcf5ef2aSThomas Huth         break;
2186fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
2187cf07cd1eSRichard Henderson         tcg_gen_atomic_xchg_tl(dst, addr, tcg_constant_tl(0xff),
2188cf07cd1eSRichard Henderson                                da->mem_idx, MO_UB);
2189fcf5ef2aSThomas Huth         break;
2190fcf5ef2aSThomas Huth     default:
21913db010c3SRichard Henderson         /* ??? In theory, this should be raise DAE_invalid_asi.
21923db010c3SRichard Henderson            But the SS-20 roms do ldstuba [%l0] #ASI_M_CTL, %o1.  */
2193af00be49SEmilio G. Cota         if (tb_cflags(dc->base.tb) & CF_PARALLEL) {
2194ad75a51eSRichard Henderson             gen_helper_exit_atomic(tcg_env);
21953db010c3SRichard Henderson         } else {
2196c03a0fd1SRichard Henderson             TCGv_i32 r_asi = tcg_constant_i32(da->asi);
219700ab7e61SRichard Henderson             TCGv_i32 r_mop = tcg_constant_i32(MO_UB);
21983db010c3SRichard Henderson             TCGv_i64 s64, t64;
21993db010c3SRichard Henderson 
22003db010c3SRichard Henderson             save_state(dc);
22013db010c3SRichard Henderson             t64 = tcg_temp_new_i64();
2202ad75a51eSRichard Henderson             gen_helper_ld_asi(t64, tcg_env, addr, r_asi, r_mop);
22033db010c3SRichard Henderson 
220400ab7e61SRichard Henderson             s64 = tcg_constant_i64(0xff);
2205ad75a51eSRichard Henderson             gen_helper_st_asi(tcg_env, addr, s64, r_asi, r_mop);
22063db010c3SRichard Henderson 
22073db010c3SRichard Henderson             tcg_gen_trunc_i64_tl(dst, t64);
22083db010c3SRichard Henderson 
22093db010c3SRichard Henderson             /* End the TB.  */
22103db010c3SRichard Henderson             dc->npc = DYNAMIC_PC;
22113db010c3SRichard Henderson         }
2212fcf5ef2aSThomas Huth         break;
2213fcf5ef2aSThomas Huth     }
2214fcf5ef2aSThomas Huth }
2215fcf5ef2aSThomas Huth 
2216287b1152SRichard Henderson static void gen_ldf_asi(DisasContext *dc, DisasASI *da, MemOp orig_size,
22173259b9e2SRichard Henderson                         TCGv addr, int rd)
2218fcf5ef2aSThomas Huth {
22193259b9e2SRichard Henderson     MemOp memop = da->memop;
22203259b9e2SRichard Henderson     MemOp size = memop & MO_SIZE;
2221fcf5ef2aSThomas Huth     TCGv_i32 d32;
2222fcf5ef2aSThomas Huth     TCGv_i64 d64;
2223287b1152SRichard Henderson     TCGv addr_tmp;
2224fcf5ef2aSThomas Huth 
22253259b9e2SRichard Henderson     /* TODO: Use 128-bit load/store below. */
22263259b9e2SRichard Henderson     if (size == MO_128) {
22273259b9e2SRichard Henderson         memop = (memop & ~MO_SIZE) | MO_64;
22283259b9e2SRichard Henderson     }
22293259b9e2SRichard Henderson 
22303259b9e2SRichard Henderson     switch (da->type) {
2231fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
2232fcf5ef2aSThomas Huth         break;
2233fcf5ef2aSThomas Huth 
2234fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
22353259b9e2SRichard Henderson         memop |= MO_ALIGN_4;
2236fcf5ef2aSThomas Huth         switch (size) {
22373259b9e2SRichard Henderson         case MO_32:
2238fcf5ef2aSThomas Huth             d32 = gen_dest_fpr_F(dc);
22393259b9e2SRichard Henderson             tcg_gen_qemu_ld_i32(d32, addr, da->mem_idx, memop);
2240fcf5ef2aSThomas Huth             gen_store_fpr_F(dc, rd, d32);
2241fcf5ef2aSThomas Huth             break;
22423259b9e2SRichard Henderson 
22433259b9e2SRichard Henderson         case MO_64:
22443259b9e2SRichard Henderson             tcg_gen_qemu_ld_i64(cpu_fpr[rd / 2], addr, da->mem_idx, memop);
2245fcf5ef2aSThomas Huth             break;
22463259b9e2SRichard Henderson 
22473259b9e2SRichard Henderson         case MO_128:
2248fcf5ef2aSThomas Huth             d64 = tcg_temp_new_i64();
22493259b9e2SRichard Henderson             tcg_gen_qemu_ld_i64(d64, addr, da->mem_idx, memop);
2250287b1152SRichard Henderson             addr_tmp = tcg_temp_new();
2251287b1152SRichard Henderson             tcg_gen_addi_tl(addr_tmp, addr, 8);
2252287b1152SRichard Henderson             tcg_gen_qemu_ld_i64(cpu_fpr[rd / 2 + 1], addr_tmp, da->mem_idx, memop);
2253fcf5ef2aSThomas Huth             tcg_gen_mov_i64(cpu_fpr[rd / 2], d64);
2254fcf5ef2aSThomas Huth             break;
2255fcf5ef2aSThomas Huth         default:
2256fcf5ef2aSThomas Huth             g_assert_not_reached();
2257fcf5ef2aSThomas Huth         }
2258fcf5ef2aSThomas Huth         break;
2259fcf5ef2aSThomas Huth 
2260fcf5ef2aSThomas Huth     case GET_ASI_BLOCK:
2261fcf5ef2aSThomas Huth         /* Valid for lddfa on aligned registers only.  */
22623259b9e2SRichard Henderson         if (orig_size == MO_64 && (rd & 7) == 0) {
2263fcf5ef2aSThomas Huth             /* The first operation checks required alignment.  */
2264287b1152SRichard Henderson             addr_tmp = tcg_temp_new();
2265287b1152SRichard Henderson             for (int i = 0; ; ++i) {
22663259b9e2SRichard Henderson                 tcg_gen_qemu_ld_i64(cpu_fpr[rd / 2 + i], addr, da->mem_idx,
22673259b9e2SRichard Henderson                                     memop | (i == 0 ? MO_ALIGN_64 : 0));
2268fcf5ef2aSThomas Huth                 if (i == 7) {
2269fcf5ef2aSThomas Huth                     break;
2270fcf5ef2aSThomas Huth                 }
2271287b1152SRichard Henderson                 tcg_gen_addi_tl(addr_tmp, addr, 8);
2272287b1152SRichard Henderson                 addr = addr_tmp;
2273fcf5ef2aSThomas Huth             }
2274fcf5ef2aSThomas Huth         } else {
2275fcf5ef2aSThomas Huth             gen_exception(dc, TT_ILL_INSN);
2276fcf5ef2aSThomas Huth         }
2277fcf5ef2aSThomas Huth         break;
2278fcf5ef2aSThomas Huth 
2279fcf5ef2aSThomas Huth     case GET_ASI_SHORT:
2280fcf5ef2aSThomas Huth         /* Valid for lddfa only.  */
22813259b9e2SRichard Henderson         if (orig_size == MO_64) {
22823259b9e2SRichard Henderson             tcg_gen_qemu_ld_i64(cpu_fpr[rd / 2], addr, da->mem_idx,
22833259b9e2SRichard Henderson                                 memop | MO_ALIGN);
2284fcf5ef2aSThomas Huth         } else {
2285fcf5ef2aSThomas Huth             gen_exception(dc, TT_ILL_INSN);
2286fcf5ef2aSThomas Huth         }
2287fcf5ef2aSThomas Huth         break;
2288fcf5ef2aSThomas Huth 
2289fcf5ef2aSThomas Huth     default:
2290fcf5ef2aSThomas Huth         {
22913259b9e2SRichard Henderson             TCGv_i32 r_asi = tcg_constant_i32(da->asi);
22923259b9e2SRichard Henderson             TCGv_i32 r_mop = tcg_constant_i32(memop | MO_ALIGN);
2293fcf5ef2aSThomas Huth 
2294fcf5ef2aSThomas Huth             save_state(dc);
2295fcf5ef2aSThomas Huth             /* According to the table in the UA2011 manual, the only
2296fcf5ef2aSThomas Huth                other asis that are valid for ldfa/lddfa/ldqfa are
2297fcf5ef2aSThomas Huth                the NO_FAULT asis.  We still need a helper for these,
2298fcf5ef2aSThomas Huth                but we can just use the integer asi helper for them.  */
2299fcf5ef2aSThomas Huth             switch (size) {
23003259b9e2SRichard Henderson             case MO_32:
2301fcf5ef2aSThomas Huth                 d64 = tcg_temp_new_i64();
2302ad75a51eSRichard Henderson                 gen_helper_ld_asi(d64, tcg_env, addr, r_asi, r_mop);
2303fcf5ef2aSThomas Huth                 d32 = gen_dest_fpr_F(dc);
2304fcf5ef2aSThomas Huth                 tcg_gen_extrl_i64_i32(d32, d64);
2305fcf5ef2aSThomas Huth                 gen_store_fpr_F(dc, rd, d32);
2306fcf5ef2aSThomas Huth                 break;
23073259b9e2SRichard Henderson             case MO_64:
23083259b9e2SRichard Henderson                 gen_helper_ld_asi(cpu_fpr[rd / 2], tcg_env, addr,
23093259b9e2SRichard Henderson                                   r_asi, r_mop);
2310fcf5ef2aSThomas Huth                 break;
23113259b9e2SRichard Henderson             case MO_128:
2312fcf5ef2aSThomas Huth                 d64 = tcg_temp_new_i64();
2313ad75a51eSRichard Henderson                 gen_helper_ld_asi(d64, tcg_env, addr, r_asi, r_mop);
2314287b1152SRichard Henderson                 addr_tmp = tcg_temp_new();
2315287b1152SRichard Henderson                 tcg_gen_addi_tl(addr_tmp, addr, 8);
2316287b1152SRichard Henderson                 gen_helper_ld_asi(cpu_fpr[rd / 2 + 1], tcg_env, addr_tmp,
23173259b9e2SRichard Henderson                                   r_asi, r_mop);
2318fcf5ef2aSThomas Huth                 tcg_gen_mov_i64(cpu_fpr[rd / 2], d64);
2319fcf5ef2aSThomas Huth                 break;
2320fcf5ef2aSThomas Huth             default:
2321fcf5ef2aSThomas Huth                 g_assert_not_reached();
2322fcf5ef2aSThomas Huth             }
2323fcf5ef2aSThomas Huth         }
2324fcf5ef2aSThomas Huth         break;
2325fcf5ef2aSThomas Huth     }
2326fcf5ef2aSThomas Huth }
2327fcf5ef2aSThomas Huth 
2328287b1152SRichard Henderson static void gen_stf_asi(DisasContext *dc, DisasASI *da, MemOp orig_size,
23293259b9e2SRichard Henderson                         TCGv addr, int rd)
23303259b9e2SRichard Henderson {
23313259b9e2SRichard Henderson     MemOp memop = da->memop;
23323259b9e2SRichard Henderson     MemOp size = memop & MO_SIZE;
2333fcf5ef2aSThomas Huth     TCGv_i32 d32;
2334287b1152SRichard Henderson     TCGv addr_tmp;
2335fcf5ef2aSThomas Huth 
23363259b9e2SRichard Henderson     /* TODO: Use 128-bit load/store below. */
23373259b9e2SRichard Henderson     if (size == MO_128) {
23383259b9e2SRichard Henderson         memop = (memop & ~MO_SIZE) | MO_64;
23393259b9e2SRichard Henderson     }
23403259b9e2SRichard Henderson 
23413259b9e2SRichard Henderson     switch (da->type) {
2342fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
2343fcf5ef2aSThomas Huth         break;
2344fcf5ef2aSThomas Huth 
2345fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
23463259b9e2SRichard Henderson         memop |= MO_ALIGN_4;
2347fcf5ef2aSThomas Huth         switch (size) {
23483259b9e2SRichard Henderson         case MO_32:
2349fcf5ef2aSThomas Huth             d32 = gen_load_fpr_F(dc, rd);
23503259b9e2SRichard Henderson             tcg_gen_qemu_st_i32(d32, addr, da->mem_idx, memop | MO_ALIGN);
2351fcf5ef2aSThomas Huth             break;
23523259b9e2SRichard Henderson         case MO_64:
23533259b9e2SRichard Henderson             tcg_gen_qemu_st_i64(cpu_fpr[rd / 2], addr, da->mem_idx,
23543259b9e2SRichard Henderson                                 memop | MO_ALIGN_4);
2355fcf5ef2aSThomas Huth             break;
23563259b9e2SRichard Henderson         case MO_128:
2357fcf5ef2aSThomas Huth             /* Only 4-byte alignment required.  However, it is legal for the
2358fcf5ef2aSThomas Huth                cpu to signal the alignment fault, and the OS trap handler is
2359fcf5ef2aSThomas Huth                required to fix it up.  Requiring 16-byte alignment here avoids
2360fcf5ef2aSThomas Huth                having to probe the second page before performing the first
2361fcf5ef2aSThomas Huth                write.  */
23623259b9e2SRichard Henderson             tcg_gen_qemu_st_i64(cpu_fpr[rd / 2], addr, da->mem_idx,
23633259b9e2SRichard Henderson                                 memop | MO_ALIGN_16);
2364287b1152SRichard Henderson             addr_tmp = tcg_temp_new();
2365287b1152SRichard Henderson             tcg_gen_addi_tl(addr_tmp, addr, 8);
2366287b1152SRichard Henderson             tcg_gen_qemu_st_i64(cpu_fpr[rd / 2 + 1], addr_tmp, da->mem_idx, memop);
2367fcf5ef2aSThomas Huth             break;
2368fcf5ef2aSThomas Huth         default:
2369fcf5ef2aSThomas Huth             g_assert_not_reached();
2370fcf5ef2aSThomas Huth         }
2371fcf5ef2aSThomas Huth         break;
2372fcf5ef2aSThomas Huth 
2373fcf5ef2aSThomas Huth     case GET_ASI_BLOCK:
2374fcf5ef2aSThomas Huth         /* Valid for stdfa on aligned registers only.  */
23753259b9e2SRichard Henderson         if (orig_size == MO_64 && (rd & 7) == 0) {
2376fcf5ef2aSThomas Huth             /* The first operation checks required alignment.  */
2377287b1152SRichard Henderson             addr_tmp = tcg_temp_new();
2378287b1152SRichard Henderson             for (int i = 0; ; ++i) {
23793259b9e2SRichard Henderson                 tcg_gen_qemu_st_i64(cpu_fpr[rd / 2 + i], addr, da->mem_idx,
23803259b9e2SRichard Henderson                                     memop | (i == 0 ? MO_ALIGN_64 : 0));
2381fcf5ef2aSThomas Huth                 if (i == 7) {
2382fcf5ef2aSThomas Huth                     break;
2383fcf5ef2aSThomas Huth                 }
2384287b1152SRichard Henderson                 tcg_gen_addi_tl(addr_tmp, addr, 8);
2385287b1152SRichard Henderson                 addr = addr_tmp;
2386fcf5ef2aSThomas Huth             }
2387fcf5ef2aSThomas Huth         } else {
2388fcf5ef2aSThomas Huth             gen_exception(dc, TT_ILL_INSN);
2389fcf5ef2aSThomas Huth         }
2390fcf5ef2aSThomas Huth         break;
2391fcf5ef2aSThomas Huth 
2392fcf5ef2aSThomas Huth     case GET_ASI_SHORT:
2393fcf5ef2aSThomas Huth         /* Valid for stdfa only.  */
23943259b9e2SRichard Henderson         if (orig_size == MO_64) {
23953259b9e2SRichard Henderson             tcg_gen_qemu_st_i64(cpu_fpr[rd / 2], addr, da->mem_idx,
23963259b9e2SRichard Henderson                                 memop | MO_ALIGN);
2397fcf5ef2aSThomas Huth         } else {
2398fcf5ef2aSThomas Huth             gen_exception(dc, TT_ILL_INSN);
2399fcf5ef2aSThomas Huth         }
2400fcf5ef2aSThomas Huth         break;
2401fcf5ef2aSThomas Huth 
2402fcf5ef2aSThomas Huth     default:
2403fcf5ef2aSThomas Huth         /* According to the table in the UA2011 manual, the only
2404fcf5ef2aSThomas Huth            other asis that are valid for ldfa/lddfa/ldqfa are
2405fcf5ef2aSThomas Huth            the PST* asis, which aren't currently handled.  */
2406fcf5ef2aSThomas Huth         gen_exception(dc, TT_ILL_INSN);
2407fcf5ef2aSThomas Huth         break;
2408fcf5ef2aSThomas Huth     }
2409fcf5ef2aSThomas Huth }
2410fcf5ef2aSThomas Huth 
241142071fc1SRichard Henderson static void gen_ldda_asi(DisasContext *dc, DisasASI *da, TCGv addr, int rd)
2412fcf5ef2aSThomas Huth {
2413a76779eeSRichard Henderson     TCGv hi = gen_dest_gpr(dc, rd);
2414a76779eeSRichard Henderson     TCGv lo = gen_dest_gpr(dc, rd + 1);
2415fcf5ef2aSThomas Huth 
2416c03a0fd1SRichard Henderson     switch (da->type) {
2417fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
2418fcf5ef2aSThomas Huth         return;
2419fcf5ef2aSThomas Huth 
2420fcf5ef2aSThomas Huth     case GET_ASI_DTWINX:
2421ebbbec92SRichard Henderson #ifdef TARGET_SPARC64
2422ebbbec92SRichard Henderson         {
2423ebbbec92SRichard Henderson             MemOp mop = (da->memop & MO_BSWAP) | MO_128 | MO_ALIGN_16;
2424ebbbec92SRichard Henderson             TCGv_i128 t = tcg_temp_new_i128();
2425ebbbec92SRichard Henderson 
2426ebbbec92SRichard Henderson             tcg_gen_qemu_ld_i128(t, addr, da->mem_idx, mop);
2427ebbbec92SRichard Henderson             /*
2428ebbbec92SRichard Henderson              * Note that LE twinx acts as if each 64-bit register result is
2429ebbbec92SRichard Henderson              * byte swapped.  We perform one 128-bit LE load, so must swap
2430ebbbec92SRichard Henderson              * the order of the writebacks.
2431ebbbec92SRichard Henderson              */
2432ebbbec92SRichard Henderson             if ((mop & MO_BSWAP) == MO_TE) {
2433ebbbec92SRichard Henderson                 tcg_gen_extr_i128_i64(lo, hi, t);
2434ebbbec92SRichard Henderson             } else {
2435ebbbec92SRichard Henderson                 tcg_gen_extr_i128_i64(hi, lo, t);
2436ebbbec92SRichard Henderson             }
2437ebbbec92SRichard Henderson         }
2438fcf5ef2aSThomas Huth         break;
2439ebbbec92SRichard Henderson #else
2440ebbbec92SRichard Henderson         g_assert_not_reached();
2441ebbbec92SRichard Henderson #endif
2442fcf5ef2aSThomas Huth 
2443fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
2444fcf5ef2aSThomas Huth         {
2445fcf5ef2aSThomas Huth             TCGv_i64 tmp = tcg_temp_new_i64();
2446fcf5ef2aSThomas Huth 
2447c03a0fd1SRichard Henderson             tcg_gen_qemu_ld_i64(tmp, addr, da->mem_idx, da->memop | MO_ALIGN);
2448fcf5ef2aSThomas Huth 
2449fcf5ef2aSThomas Huth             /* Note that LE ldda acts as if each 32-bit register
2450fcf5ef2aSThomas Huth                result is byte swapped.  Having just performed one
2451fcf5ef2aSThomas Huth                64-bit bswap, we need now to swap the writebacks.  */
2452c03a0fd1SRichard Henderson             if ((da->memop & MO_BSWAP) == MO_TE) {
2453a76779eeSRichard Henderson                 tcg_gen_extr_i64_tl(lo, hi, tmp);
2454fcf5ef2aSThomas Huth             } else {
2455a76779eeSRichard Henderson                 tcg_gen_extr_i64_tl(hi, lo, tmp);
2456fcf5ef2aSThomas Huth             }
2457fcf5ef2aSThomas Huth         }
2458fcf5ef2aSThomas Huth         break;
2459fcf5ef2aSThomas Huth 
2460fcf5ef2aSThomas Huth     default:
2461fcf5ef2aSThomas Huth         /* ??? In theory we've handled all of the ASIs that are valid
2462fcf5ef2aSThomas Huth            for ldda, and this should raise DAE_invalid_asi.  However,
2463fcf5ef2aSThomas Huth            real hardware allows others.  This can be seen with e.g.
2464fcf5ef2aSThomas Huth            FreeBSD 10.3 wrt ASI_IC_TAG.  */
2465fcf5ef2aSThomas Huth         {
2466c03a0fd1SRichard Henderson             TCGv_i32 r_asi = tcg_constant_i32(da->asi);
2467c03a0fd1SRichard Henderson             TCGv_i32 r_mop = tcg_constant_i32(da->memop);
2468fcf5ef2aSThomas Huth             TCGv_i64 tmp = tcg_temp_new_i64();
2469fcf5ef2aSThomas Huth 
2470fcf5ef2aSThomas Huth             save_state(dc);
2471ad75a51eSRichard Henderson             gen_helper_ld_asi(tmp, tcg_env, addr, r_asi, r_mop);
2472fcf5ef2aSThomas Huth 
2473fcf5ef2aSThomas Huth             /* See above.  */
2474c03a0fd1SRichard Henderson             if ((da->memop & MO_BSWAP) == MO_TE) {
2475a76779eeSRichard Henderson                 tcg_gen_extr_i64_tl(lo, hi, tmp);
2476fcf5ef2aSThomas Huth             } else {
2477a76779eeSRichard Henderson                 tcg_gen_extr_i64_tl(hi, lo, tmp);
2478fcf5ef2aSThomas Huth             }
2479fcf5ef2aSThomas Huth         }
2480fcf5ef2aSThomas Huth         break;
2481fcf5ef2aSThomas Huth     }
2482fcf5ef2aSThomas Huth 
2483fcf5ef2aSThomas Huth     gen_store_gpr(dc, rd, hi);
2484fcf5ef2aSThomas Huth     gen_store_gpr(dc, rd + 1, lo);
2485fcf5ef2aSThomas Huth }
2486fcf5ef2aSThomas Huth 
248742071fc1SRichard Henderson static void gen_stda_asi(DisasContext *dc, DisasASI *da, TCGv addr, int rd)
2488c03a0fd1SRichard Henderson {
2489c03a0fd1SRichard Henderson     TCGv hi = gen_load_gpr(dc, rd);
2490fcf5ef2aSThomas Huth     TCGv lo = gen_load_gpr(dc, rd + 1);
2491fcf5ef2aSThomas Huth 
2492c03a0fd1SRichard Henderson     switch (da->type) {
2493fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
2494fcf5ef2aSThomas Huth         break;
2495fcf5ef2aSThomas Huth 
2496fcf5ef2aSThomas Huth     case GET_ASI_DTWINX:
2497ebbbec92SRichard Henderson #ifdef TARGET_SPARC64
2498ebbbec92SRichard Henderson         {
2499ebbbec92SRichard Henderson             MemOp mop = (da->memop & MO_BSWAP) | MO_128 | MO_ALIGN_16;
2500ebbbec92SRichard Henderson             TCGv_i128 t = tcg_temp_new_i128();
2501ebbbec92SRichard Henderson 
2502ebbbec92SRichard Henderson             /*
2503ebbbec92SRichard Henderson              * Note that LE twinx acts as if each 64-bit register result is
2504ebbbec92SRichard Henderson              * byte swapped.  We perform one 128-bit LE store, so must swap
2505ebbbec92SRichard Henderson              * the order of the construction.
2506ebbbec92SRichard Henderson              */
2507ebbbec92SRichard Henderson             if ((mop & MO_BSWAP) == MO_TE) {
2508ebbbec92SRichard Henderson                 tcg_gen_concat_i64_i128(t, lo, hi);
2509ebbbec92SRichard Henderson             } else {
2510ebbbec92SRichard Henderson                 tcg_gen_concat_i64_i128(t, hi, lo);
2511ebbbec92SRichard Henderson             }
2512ebbbec92SRichard Henderson             tcg_gen_qemu_st_i128(t, addr, da->mem_idx, mop);
2513ebbbec92SRichard Henderson         }
2514fcf5ef2aSThomas Huth         break;
2515ebbbec92SRichard Henderson #else
2516ebbbec92SRichard Henderson         g_assert_not_reached();
2517ebbbec92SRichard Henderson #endif
2518fcf5ef2aSThomas Huth 
2519fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
2520fcf5ef2aSThomas Huth         {
2521fcf5ef2aSThomas Huth             TCGv_i64 t64 = tcg_temp_new_i64();
2522fcf5ef2aSThomas Huth 
2523fcf5ef2aSThomas Huth             /* Note that LE stda acts as if each 32-bit register result is
2524fcf5ef2aSThomas Huth                byte swapped.  We will perform one 64-bit LE store, so now
2525fcf5ef2aSThomas Huth                we must swap the order of the construction.  */
2526c03a0fd1SRichard Henderson             if ((da->memop & MO_BSWAP) == MO_TE) {
2527a76779eeSRichard Henderson                 tcg_gen_concat_tl_i64(t64, lo, hi);
2528fcf5ef2aSThomas Huth             } else {
2529a76779eeSRichard Henderson                 tcg_gen_concat_tl_i64(t64, hi, lo);
2530fcf5ef2aSThomas Huth             }
2531c03a0fd1SRichard Henderson             tcg_gen_qemu_st_i64(t64, addr, da->mem_idx, da->memop | MO_ALIGN);
2532fcf5ef2aSThomas Huth         }
2533fcf5ef2aSThomas Huth         break;
2534fcf5ef2aSThomas Huth 
2535a76779eeSRichard Henderson     case GET_ASI_BFILL:
2536a76779eeSRichard Henderson         assert(TARGET_LONG_BITS == 32);
2537a76779eeSRichard Henderson         /* Store 32 bytes of T64 to ADDR.  */
2538a76779eeSRichard Henderson         /* ??? The original qemu code suggests 8-byte alignment, dropping
2539a76779eeSRichard Henderson            the low bits, but the only place I can see this used is in the
2540a76779eeSRichard Henderson            Linux kernel with 32 byte alignment, which would make more sense
2541a76779eeSRichard Henderson            as a cacheline-style operation.  */
2542a76779eeSRichard Henderson         {
2543a76779eeSRichard Henderson             TCGv_i64 t64 = tcg_temp_new_i64();
2544a76779eeSRichard Henderson             TCGv d_addr = tcg_temp_new();
2545a76779eeSRichard Henderson             TCGv eight = tcg_constant_tl(8);
2546a76779eeSRichard Henderson             int i;
2547a76779eeSRichard Henderson 
2548a76779eeSRichard Henderson             tcg_gen_concat_tl_i64(t64, lo, hi);
2549a76779eeSRichard Henderson             tcg_gen_andi_tl(d_addr, addr, -8);
2550a76779eeSRichard Henderson             for (i = 0; i < 32; i += 8) {
2551c03a0fd1SRichard Henderson                 tcg_gen_qemu_st_i64(t64, d_addr, da->mem_idx, da->memop);
2552a76779eeSRichard Henderson                 tcg_gen_add_tl(d_addr, d_addr, eight);
2553a76779eeSRichard Henderson             }
2554a76779eeSRichard Henderson         }
2555a76779eeSRichard Henderson         break;
2556a76779eeSRichard Henderson 
2557fcf5ef2aSThomas Huth     default:
2558fcf5ef2aSThomas Huth         /* ??? In theory we've handled all of the ASIs that are valid
2559fcf5ef2aSThomas Huth            for stda, and this should raise DAE_invalid_asi.  */
2560fcf5ef2aSThomas Huth         {
2561c03a0fd1SRichard Henderson             TCGv_i32 r_asi = tcg_constant_i32(da->asi);
2562c03a0fd1SRichard Henderson             TCGv_i32 r_mop = tcg_constant_i32(da->memop);
2563fcf5ef2aSThomas Huth             TCGv_i64 t64 = tcg_temp_new_i64();
2564fcf5ef2aSThomas Huth 
2565fcf5ef2aSThomas Huth             /* See above.  */
2566c03a0fd1SRichard Henderson             if ((da->memop & MO_BSWAP) == MO_TE) {
2567a76779eeSRichard Henderson                 tcg_gen_concat_tl_i64(t64, lo, hi);
2568fcf5ef2aSThomas Huth             } else {
2569a76779eeSRichard Henderson                 tcg_gen_concat_tl_i64(t64, hi, lo);
2570fcf5ef2aSThomas Huth             }
2571fcf5ef2aSThomas Huth 
2572fcf5ef2aSThomas Huth             save_state(dc);
2573ad75a51eSRichard Henderson             gen_helper_st_asi(tcg_env, addr, t64, r_asi, r_mop);
2574fcf5ef2aSThomas Huth         }
2575fcf5ef2aSThomas Huth         break;
2576fcf5ef2aSThomas Huth     }
2577fcf5ef2aSThomas Huth }
2578fcf5ef2aSThomas Huth 
25793d3c0673SRichard Henderson #ifdef TARGET_SPARC64
2580fcf5ef2aSThomas Huth static TCGv get_src1(DisasContext *dc, unsigned int insn)
2581fcf5ef2aSThomas Huth {
2582fcf5ef2aSThomas Huth     unsigned int rs1 = GET_FIELD(insn, 13, 17);
2583fcf5ef2aSThomas Huth     return gen_load_gpr(dc, rs1);
2584fcf5ef2aSThomas Huth }
2585fcf5ef2aSThomas Huth 
2586fcf5ef2aSThomas Huth static void gen_fmovs(DisasContext *dc, DisasCompare *cmp, int rd, int rs)
2587fcf5ef2aSThomas Huth {
2588fcf5ef2aSThomas Huth     TCGv_i32 c32, zero, dst, s1, s2;
2589fcf5ef2aSThomas Huth 
2590fcf5ef2aSThomas Huth     /* We have two choices here: extend the 32 bit data and use movcond_i64,
2591fcf5ef2aSThomas Huth        or fold the comparison down to 32 bits and use movcond_i32.  Choose
2592fcf5ef2aSThomas Huth        the later.  */
2593fcf5ef2aSThomas Huth     c32 = tcg_temp_new_i32();
2594fcf5ef2aSThomas Huth     if (cmp->is_bool) {
2595fcf5ef2aSThomas Huth         tcg_gen_extrl_i64_i32(c32, cmp->c1);
2596fcf5ef2aSThomas Huth     } else {
2597fcf5ef2aSThomas Huth         TCGv_i64 c64 = tcg_temp_new_i64();
2598fcf5ef2aSThomas Huth         tcg_gen_setcond_i64(cmp->cond, c64, cmp->c1, cmp->c2);
2599fcf5ef2aSThomas Huth         tcg_gen_extrl_i64_i32(c32, c64);
2600fcf5ef2aSThomas Huth     }
2601fcf5ef2aSThomas Huth 
2602fcf5ef2aSThomas Huth     s1 = gen_load_fpr_F(dc, rs);
2603fcf5ef2aSThomas Huth     s2 = gen_load_fpr_F(dc, rd);
2604fcf5ef2aSThomas Huth     dst = gen_dest_fpr_F(dc);
260500ab7e61SRichard Henderson     zero = tcg_constant_i32(0);
2606fcf5ef2aSThomas Huth 
2607fcf5ef2aSThomas Huth     tcg_gen_movcond_i32(TCG_COND_NE, dst, c32, zero, s1, s2);
2608fcf5ef2aSThomas Huth 
2609fcf5ef2aSThomas Huth     gen_store_fpr_F(dc, rd, dst);
2610fcf5ef2aSThomas Huth }
2611fcf5ef2aSThomas Huth 
2612fcf5ef2aSThomas Huth static void gen_fmovd(DisasContext *dc, DisasCompare *cmp, int rd, int rs)
2613fcf5ef2aSThomas Huth {
2614fcf5ef2aSThomas Huth     TCGv_i64 dst = gen_dest_fpr_D(dc, rd);
2615fcf5ef2aSThomas Huth     tcg_gen_movcond_i64(cmp->cond, dst, cmp->c1, cmp->c2,
2616fcf5ef2aSThomas Huth                         gen_load_fpr_D(dc, rs),
2617fcf5ef2aSThomas Huth                         gen_load_fpr_D(dc, rd));
2618fcf5ef2aSThomas Huth     gen_store_fpr_D(dc, rd, dst);
2619fcf5ef2aSThomas Huth }
2620fcf5ef2aSThomas Huth 
2621fcf5ef2aSThomas Huth static void gen_fmovq(DisasContext *dc, DisasCompare *cmp, int rd, int rs)
2622fcf5ef2aSThomas Huth {
2623fcf5ef2aSThomas Huth     int qd = QFPREG(rd);
2624fcf5ef2aSThomas Huth     int qs = QFPREG(rs);
2625fcf5ef2aSThomas Huth 
2626fcf5ef2aSThomas Huth     tcg_gen_movcond_i64(cmp->cond, cpu_fpr[qd / 2], cmp->c1, cmp->c2,
2627fcf5ef2aSThomas Huth                         cpu_fpr[qs / 2], cpu_fpr[qd / 2]);
2628fcf5ef2aSThomas Huth     tcg_gen_movcond_i64(cmp->cond, cpu_fpr[qd / 2 + 1], cmp->c1, cmp->c2,
2629fcf5ef2aSThomas Huth                         cpu_fpr[qs / 2 + 1], cpu_fpr[qd / 2 + 1]);
2630fcf5ef2aSThomas Huth 
2631fcf5ef2aSThomas Huth     gen_update_fprs_dirty(dc, qd);
2632fcf5ef2aSThomas Huth }
2633fcf5ef2aSThomas Huth 
26345d617bfbSRichard Henderson static void gen_load_trap_state_at_tl(TCGv_ptr r_tsptr)
2635fcf5ef2aSThomas Huth {
2636fcf5ef2aSThomas Huth     TCGv_i32 r_tl = tcg_temp_new_i32();
2637fcf5ef2aSThomas Huth 
2638fcf5ef2aSThomas Huth     /* load env->tl into r_tl */
2639ad75a51eSRichard Henderson     tcg_gen_ld_i32(r_tl, tcg_env, offsetof(CPUSPARCState, tl));
2640fcf5ef2aSThomas Huth 
2641fcf5ef2aSThomas Huth     /* tl = [0 ... MAXTL_MASK] where MAXTL_MASK must be power of 2 */
2642fcf5ef2aSThomas Huth     tcg_gen_andi_i32(r_tl, r_tl, MAXTL_MASK);
2643fcf5ef2aSThomas Huth 
2644fcf5ef2aSThomas Huth     /* calculate offset to current trap state from env->ts, reuse r_tl */
2645fcf5ef2aSThomas Huth     tcg_gen_muli_i32(r_tl, r_tl, sizeof (trap_state));
2646ad75a51eSRichard Henderson     tcg_gen_addi_ptr(r_tsptr, tcg_env, offsetof(CPUSPARCState, ts));
2647fcf5ef2aSThomas Huth 
2648fcf5ef2aSThomas Huth     /* tsptr = env->ts[env->tl & MAXTL_MASK] */
2649fcf5ef2aSThomas Huth     {
2650fcf5ef2aSThomas Huth         TCGv_ptr r_tl_tmp = tcg_temp_new_ptr();
2651fcf5ef2aSThomas Huth         tcg_gen_ext_i32_ptr(r_tl_tmp, r_tl);
2652fcf5ef2aSThomas Huth         tcg_gen_add_ptr(r_tsptr, r_tsptr, r_tl_tmp);
2653fcf5ef2aSThomas Huth     }
2654fcf5ef2aSThomas Huth }
2655fcf5ef2aSThomas Huth #endif
2656fcf5ef2aSThomas Huth 
265706c060d9SRichard Henderson static int extract_dfpreg(DisasContext *dc, int x)
265806c060d9SRichard Henderson {
265906c060d9SRichard Henderson     return DFPREG(x);
266006c060d9SRichard Henderson }
266106c060d9SRichard Henderson 
266206c060d9SRichard Henderson static int extract_qfpreg(DisasContext *dc, int x)
266306c060d9SRichard Henderson {
266406c060d9SRichard Henderson     return QFPREG(x);
266506c060d9SRichard Henderson }
266606c060d9SRichard Henderson 
2667878cc677SRichard Henderson /* Include the auto-generated decoder.  */
2668878cc677SRichard Henderson #include "decode-insns.c.inc"
2669878cc677SRichard Henderson 
2670878cc677SRichard Henderson #define TRANS(NAME, AVAIL, FUNC, ...) \
2671878cc677SRichard Henderson     static bool trans_##NAME(DisasContext *dc, arg_##NAME *a) \
2672878cc677SRichard Henderson     { return avail_##AVAIL(dc) && FUNC(dc, __VA_ARGS__); }
2673878cc677SRichard Henderson 
2674878cc677SRichard Henderson #define avail_ALL(C)      true
2675878cc677SRichard Henderson #ifdef TARGET_SPARC64
2676878cc677SRichard Henderson # define avail_32(C)      false
2677af25071cSRichard Henderson # define avail_ASR17(C)   false
2678d0a11d25SRichard Henderson # define avail_CASA(C)    true
2679c2636853SRichard Henderson # define avail_DIV(C)     true
2680b5372650SRichard Henderson # define avail_MUL(C)     true
26810faef01bSRichard Henderson # define avail_POWERDOWN(C) false
2682878cc677SRichard Henderson # define avail_64(C)      true
26835d617bfbSRichard Henderson # define avail_GL(C)      ((C)->def->features & CPU_FEATURE_GL)
2684af25071cSRichard Henderson # define avail_HYPV(C)    ((C)->def->features & CPU_FEATURE_HYPV)
2685b88ce6f2SRichard Henderson # define avail_VIS1(C)    ((C)->def->features & CPU_FEATURE_VIS1)
2686b88ce6f2SRichard Henderson # define avail_VIS2(C)    ((C)->def->features & CPU_FEATURE_VIS2)
2687878cc677SRichard Henderson #else
2688878cc677SRichard Henderson # define avail_32(C)      true
2689af25071cSRichard Henderson # define avail_ASR17(C)   ((C)->def->features & CPU_FEATURE_ASR17)
2690d0a11d25SRichard Henderson # define avail_CASA(C)    ((C)->def->features & CPU_FEATURE_CASA)
2691c2636853SRichard Henderson # define avail_DIV(C)     ((C)->def->features & CPU_FEATURE_DIV)
2692b5372650SRichard Henderson # define avail_MUL(C)     ((C)->def->features & CPU_FEATURE_MUL)
26930faef01bSRichard Henderson # define avail_POWERDOWN(C) ((C)->def->features & CPU_FEATURE_POWERDOWN)
2694878cc677SRichard Henderson # define avail_64(C)      false
26955d617bfbSRichard Henderson # define avail_GL(C)      false
2696af25071cSRichard Henderson # define avail_HYPV(C)    false
2697b88ce6f2SRichard Henderson # define avail_VIS1(C)    false
2698b88ce6f2SRichard Henderson # define avail_VIS2(C)    false
2699878cc677SRichard Henderson #endif
2700878cc677SRichard Henderson 
2701878cc677SRichard Henderson /* Default case for non jump instructions. */
2702878cc677SRichard Henderson static bool advance_pc(DisasContext *dc)
2703878cc677SRichard Henderson {
2704878cc677SRichard Henderson     if (dc->npc & 3) {
2705878cc677SRichard Henderson         switch (dc->npc) {
2706878cc677SRichard Henderson         case DYNAMIC_PC:
2707878cc677SRichard Henderson         case DYNAMIC_PC_LOOKUP:
2708878cc677SRichard Henderson             dc->pc = dc->npc;
2709878cc677SRichard Henderson             gen_op_next_insn();
2710878cc677SRichard Henderson             break;
2711878cc677SRichard Henderson         case JUMP_PC:
2712878cc677SRichard Henderson             /* we can do a static jump */
2713878cc677SRichard Henderson             gen_branch2(dc, dc->jump_pc[0], dc->jump_pc[1], cpu_cond);
2714878cc677SRichard Henderson             dc->base.is_jmp = DISAS_NORETURN;
2715878cc677SRichard Henderson             break;
2716878cc677SRichard Henderson         default:
2717878cc677SRichard Henderson             g_assert_not_reached();
2718878cc677SRichard Henderson         }
2719878cc677SRichard Henderson     } else {
2720878cc677SRichard Henderson         dc->pc = dc->npc;
2721878cc677SRichard Henderson         dc->npc = dc->npc + 4;
2722878cc677SRichard Henderson     }
2723878cc677SRichard Henderson     return true;
2724878cc677SRichard Henderson }
2725878cc677SRichard Henderson 
27266d2a0768SRichard Henderson /*
27276d2a0768SRichard Henderson  * Major opcodes 00 and 01 -- branches, call, and sethi
27286d2a0768SRichard Henderson  */
27296d2a0768SRichard Henderson 
2730276567aaSRichard Henderson static bool advance_jump_uncond_never(DisasContext *dc, bool annul)
2731276567aaSRichard Henderson {
2732276567aaSRichard Henderson     if (annul) {
2733276567aaSRichard Henderson         dc->pc = dc->npc + 4;
2734276567aaSRichard Henderson         dc->npc = dc->pc + 4;
2735276567aaSRichard Henderson     } else {
2736276567aaSRichard Henderson         dc->pc = dc->npc;
2737276567aaSRichard Henderson         dc->npc = dc->pc + 4;
2738276567aaSRichard Henderson     }
2739276567aaSRichard Henderson     return true;
2740276567aaSRichard Henderson }
2741276567aaSRichard Henderson 
2742276567aaSRichard Henderson static bool advance_jump_uncond_always(DisasContext *dc, bool annul,
2743276567aaSRichard Henderson                                        target_ulong dest)
2744276567aaSRichard Henderson {
2745276567aaSRichard Henderson     if (annul) {
2746276567aaSRichard Henderson         dc->pc = dest;
2747276567aaSRichard Henderson         dc->npc = dest + 4;
2748276567aaSRichard Henderson     } else {
2749276567aaSRichard Henderson         dc->pc = dc->npc;
2750276567aaSRichard Henderson         dc->npc = dest;
2751276567aaSRichard Henderson         tcg_gen_mov_tl(cpu_pc, cpu_npc);
2752276567aaSRichard Henderson     }
2753276567aaSRichard Henderson     return true;
2754276567aaSRichard Henderson }
2755276567aaSRichard Henderson 
27569d4e2bc7SRichard Henderson static bool advance_jump_cond(DisasContext *dc, DisasCompare *cmp,
27579d4e2bc7SRichard Henderson                               bool annul, target_ulong dest)
2758276567aaSRichard Henderson {
27596b3e4cc6SRichard Henderson     target_ulong npc = dc->npc;
27606b3e4cc6SRichard Henderson 
2761276567aaSRichard Henderson     if (annul) {
27626b3e4cc6SRichard Henderson         TCGLabel *l1 = gen_new_label();
27636b3e4cc6SRichard Henderson 
27649d4e2bc7SRichard Henderson         tcg_gen_brcond_tl(tcg_invert_cond(cmp->cond), cmp->c1, cmp->c2, l1);
27656b3e4cc6SRichard Henderson         gen_goto_tb(dc, 0, npc, dest);
27666b3e4cc6SRichard Henderson         gen_set_label(l1);
27676b3e4cc6SRichard Henderson         gen_goto_tb(dc, 1, npc + 4, npc + 8);
27686b3e4cc6SRichard Henderson 
27696b3e4cc6SRichard Henderson         dc->base.is_jmp = DISAS_NORETURN;
2770276567aaSRichard Henderson     } else {
27716b3e4cc6SRichard Henderson         if (npc & 3) {
27726b3e4cc6SRichard Henderson             switch (npc) {
27736b3e4cc6SRichard Henderson             case DYNAMIC_PC:
27746b3e4cc6SRichard Henderson             case DYNAMIC_PC_LOOKUP:
27756b3e4cc6SRichard Henderson                 tcg_gen_mov_tl(cpu_pc, cpu_npc);
27766b3e4cc6SRichard Henderson                 tcg_gen_addi_tl(cpu_npc, cpu_npc, 4);
27779d4e2bc7SRichard Henderson                 tcg_gen_movcond_tl(cmp->cond, cpu_npc,
27789d4e2bc7SRichard Henderson                                    cmp->c1, cmp->c2,
27796b3e4cc6SRichard Henderson                                    tcg_constant_tl(dest), cpu_npc);
27806b3e4cc6SRichard Henderson                 dc->pc = npc;
27816b3e4cc6SRichard Henderson                 break;
27826b3e4cc6SRichard Henderson             default:
27836b3e4cc6SRichard Henderson                 g_assert_not_reached();
27846b3e4cc6SRichard Henderson             }
27856b3e4cc6SRichard Henderson         } else {
27866b3e4cc6SRichard Henderson             dc->pc = npc;
27876b3e4cc6SRichard Henderson             dc->jump_pc[0] = dest;
27886b3e4cc6SRichard Henderson             dc->jump_pc[1] = npc + 4;
27896b3e4cc6SRichard Henderson             dc->npc = JUMP_PC;
27909d4e2bc7SRichard Henderson             if (cmp->is_bool) {
27919d4e2bc7SRichard Henderson                 tcg_gen_mov_tl(cpu_cond, cmp->c1);
27929d4e2bc7SRichard Henderson             } else {
27939d4e2bc7SRichard Henderson                 tcg_gen_setcond_tl(cmp->cond, cpu_cond, cmp->c1, cmp->c2);
27949d4e2bc7SRichard Henderson             }
27956b3e4cc6SRichard Henderson         }
2796276567aaSRichard Henderson     }
2797276567aaSRichard Henderson     return true;
2798276567aaSRichard Henderson }
2799276567aaSRichard Henderson 
2800af25071cSRichard Henderson static bool raise_priv(DisasContext *dc)
2801af25071cSRichard Henderson {
2802af25071cSRichard Henderson     gen_exception(dc, TT_PRIV_INSN);
2803af25071cSRichard Henderson     return true;
2804af25071cSRichard Henderson }
2805af25071cSRichard Henderson 
280606c060d9SRichard Henderson static bool raise_unimpfpop(DisasContext *dc)
280706c060d9SRichard Henderson {
280806c060d9SRichard Henderson     gen_op_fpexception_im(dc, FSR_FTT_UNIMPFPOP);
280906c060d9SRichard Henderson     return true;
281006c060d9SRichard Henderson }
281106c060d9SRichard Henderson 
281206c060d9SRichard Henderson static bool gen_trap_float128(DisasContext *dc)
281306c060d9SRichard Henderson {
281406c060d9SRichard Henderson     if (dc->def->features & CPU_FEATURE_FLOAT128) {
281506c060d9SRichard Henderson         return false;
281606c060d9SRichard Henderson     }
281706c060d9SRichard Henderson     return raise_unimpfpop(dc);
281806c060d9SRichard Henderson }
281906c060d9SRichard Henderson 
2820276567aaSRichard Henderson static bool do_bpcc(DisasContext *dc, arg_bcc *a)
2821276567aaSRichard Henderson {
2822276567aaSRichard Henderson     target_long target = address_mask_i(dc, dc->pc + a->i * 4);
28231ea9c62aSRichard Henderson     DisasCompare cmp;
2824276567aaSRichard Henderson 
2825276567aaSRichard Henderson     switch (a->cond) {
2826276567aaSRichard Henderson     case 0x0:
2827276567aaSRichard Henderson         return advance_jump_uncond_never(dc, a->a);
2828276567aaSRichard Henderson     case 0x8:
2829276567aaSRichard Henderson         return advance_jump_uncond_always(dc, a->a, target);
2830276567aaSRichard Henderson     default:
2831276567aaSRichard Henderson         flush_cond(dc);
28321ea9c62aSRichard Henderson 
28331ea9c62aSRichard Henderson         gen_compare(&cmp, a->cc, a->cond, dc);
28349d4e2bc7SRichard Henderson         return advance_jump_cond(dc, &cmp, a->a, target);
2835276567aaSRichard Henderson     }
2836276567aaSRichard Henderson }
2837276567aaSRichard Henderson 
2838276567aaSRichard Henderson TRANS(Bicc, ALL, do_bpcc, a)
2839276567aaSRichard Henderson TRANS(BPcc,  64, do_bpcc, a)
2840276567aaSRichard Henderson 
284145196ea4SRichard Henderson static bool do_fbpfcc(DisasContext *dc, arg_bcc *a)
284245196ea4SRichard Henderson {
284345196ea4SRichard Henderson     target_long target = address_mask_i(dc, dc->pc + a->i * 4);
2844d5471936SRichard Henderson     DisasCompare cmp;
284545196ea4SRichard Henderson 
284645196ea4SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
284745196ea4SRichard Henderson         return true;
284845196ea4SRichard Henderson     }
284945196ea4SRichard Henderson     switch (a->cond) {
285045196ea4SRichard Henderson     case 0x0:
285145196ea4SRichard Henderson         return advance_jump_uncond_never(dc, a->a);
285245196ea4SRichard Henderson     case 0x8:
285345196ea4SRichard Henderson         return advance_jump_uncond_always(dc, a->a, target);
285445196ea4SRichard Henderson     default:
285545196ea4SRichard Henderson         flush_cond(dc);
2856d5471936SRichard Henderson 
2857d5471936SRichard Henderson         gen_fcompare(&cmp, a->cc, a->cond);
28589d4e2bc7SRichard Henderson         return advance_jump_cond(dc, &cmp, a->a, target);
285945196ea4SRichard Henderson     }
286045196ea4SRichard Henderson }
286145196ea4SRichard Henderson 
286245196ea4SRichard Henderson TRANS(FBPfcc,  64, do_fbpfcc, a)
286345196ea4SRichard Henderson TRANS(FBfcc,  ALL, do_fbpfcc, a)
286445196ea4SRichard Henderson 
2865ab9ffe98SRichard Henderson static bool trans_BPr(DisasContext *dc, arg_BPr *a)
2866ab9ffe98SRichard Henderson {
2867ab9ffe98SRichard Henderson     target_long target = address_mask_i(dc, dc->pc + a->i * 4);
2868ab9ffe98SRichard Henderson     DisasCompare cmp;
2869ab9ffe98SRichard Henderson 
2870ab9ffe98SRichard Henderson     if (!avail_64(dc)) {
2871ab9ffe98SRichard Henderson         return false;
2872ab9ffe98SRichard Henderson     }
2873ab9ffe98SRichard Henderson     if (gen_tcg_cond_reg[a->cond] == TCG_COND_NEVER) {
2874ab9ffe98SRichard Henderson         return false;
2875ab9ffe98SRichard Henderson     }
2876ab9ffe98SRichard Henderson 
2877ab9ffe98SRichard Henderson     flush_cond(dc);
2878ab9ffe98SRichard Henderson     gen_compare_reg(&cmp, a->cond, gen_load_gpr(dc, a->rs1));
28799d4e2bc7SRichard Henderson     return advance_jump_cond(dc, &cmp, a->a, target);
2880ab9ffe98SRichard Henderson }
2881ab9ffe98SRichard Henderson 
288223ada1b1SRichard Henderson static bool trans_CALL(DisasContext *dc, arg_CALL *a)
288323ada1b1SRichard Henderson {
288423ada1b1SRichard Henderson     target_long target = address_mask_i(dc, dc->pc + a->i * 4);
288523ada1b1SRichard Henderson 
288623ada1b1SRichard Henderson     gen_store_gpr(dc, 15, tcg_constant_tl(dc->pc));
288723ada1b1SRichard Henderson     gen_mov_pc_npc(dc);
288823ada1b1SRichard Henderson     dc->npc = target;
288923ada1b1SRichard Henderson     return true;
289023ada1b1SRichard Henderson }
289123ada1b1SRichard Henderson 
289245196ea4SRichard Henderson static bool trans_NCP(DisasContext *dc, arg_NCP *a)
289345196ea4SRichard Henderson {
289445196ea4SRichard Henderson     /*
289545196ea4SRichard Henderson      * For sparc32, always generate the no-coprocessor exception.
289645196ea4SRichard Henderson      * For sparc64, always generate illegal instruction.
289745196ea4SRichard Henderson      */
289845196ea4SRichard Henderson #ifdef TARGET_SPARC64
289945196ea4SRichard Henderson     return false;
290045196ea4SRichard Henderson #else
290145196ea4SRichard Henderson     gen_exception(dc, TT_NCP_INSN);
290245196ea4SRichard Henderson     return true;
290345196ea4SRichard Henderson #endif
290445196ea4SRichard Henderson }
290545196ea4SRichard Henderson 
29066d2a0768SRichard Henderson static bool trans_SETHI(DisasContext *dc, arg_SETHI *a)
29076d2a0768SRichard Henderson {
29086d2a0768SRichard Henderson     /* Special-case %g0 because that's the canonical nop.  */
29096d2a0768SRichard Henderson     if (a->rd) {
29106d2a0768SRichard Henderson         gen_store_gpr(dc, a->rd, tcg_constant_tl((uint32_t)a->i << 10));
29116d2a0768SRichard Henderson     }
29126d2a0768SRichard Henderson     return advance_pc(dc);
29136d2a0768SRichard Henderson }
29146d2a0768SRichard Henderson 
29150faef01bSRichard Henderson /*
29160faef01bSRichard Henderson  * Major Opcode 10 -- integer, floating-point, vis, and system insns.
29170faef01bSRichard Henderson  */
29180faef01bSRichard Henderson 
291930376636SRichard Henderson static bool do_tcc(DisasContext *dc, int cond, int cc,
292030376636SRichard Henderson                    int rs1, bool imm, int rs2_or_imm)
292130376636SRichard Henderson {
292230376636SRichard Henderson     int mask = ((dc->def->features & CPU_FEATURE_HYPV) && supervisor(dc)
292330376636SRichard Henderson                 ? UA2005_HTRAP_MASK : V8_TRAP_MASK);
292430376636SRichard Henderson     DisasCompare cmp;
292530376636SRichard Henderson     TCGLabel *lab;
292630376636SRichard Henderson     TCGv_i32 trap;
292730376636SRichard Henderson 
292830376636SRichard Henderson     /* Trap never.  */
292930376636SRichard Henderson     if (cond == 0) {
293030376636SRichard Henderson         return advance_pc(dc);
293130376636SRichard Henderson     }
293230376636SRichard Henderson 
293330376636SRichard Henderson     /*
293430376636SRichard Henderson      * Immediate traps are the most common case.  Since this value is
293530376636SRichard Henderson      * live across the branch, it really pays to evaluate the constant.
293630376636SRichard Henderson      */
293730376636SRichard Henderson     if (rs1 == 0 && (imm || rs2_or_imm == 0)) {
293830376636SRichard Henderson         trap = tcg_constant_i32((rs2_or_imm & mask) + TT_TRAP);
293930376636SRichard Henderson     } else {
294030376636SRichard Henderson         trap = tcg_temp_new_i32();
294130376636SRichard Henderson         tcg_gen_trunc_tl_i32(trap, gen_load_gpr(dc, rs1));
294230376636SRichard Henderson         if (imm) {
294330376636SRichard Henderson             tcg_gen_addi_i32(trap, trap, rs2_or_imm);
294430376636SRichard Henderson         } else {
294530376636SRichard Henderson             TCGv_i32 t2 = tcg_temp_new_i32();
294630376636SRichard Henderson             tcg_gen_trunc_tl_i32(t2, gen_load_gpr(dc, rs2_or_imm));
294730376636SRichard Henderson             tcg_gen_add_i32(trap, trap, t2);
294830376636SRichard Henderson         }
294930376636SRichard Henderson         tcg_gen_andi_i32(trap, trap, mask);
295030376636SRichard Henderson         tcg_gen_addi_i32(trap, trap, TT_TRAP);
295130376636SRichard Henderson     }
295230376636SRichard Henderson 
295330376636SRichard Henderson     /* Trap always.  */
295430376636SRichard Henderson     if (cond == 8) {
295530376636SRichard Henderson         save_state(dc);
295630376636SRichard Henderson         gen_helper_raise_exception(tcg_env, trap);
295730376636SRichard Henderson         dc->base.is_jmp = DISAS_NORETURN;
295830376636SRichard Henderson         return true;
295930376636SRichard Henderson     }
296030376636SRichard Henderson 
296130376636SRichard Henderson     /* Conditional trap.  */
296230376636SRichard Henderson     flush_cond(dc);
296330376636SRichard Henderson     lab = delay_exceptionv(dc, trap);
296430376636SRichard Henderson     gen_compare(&cmp, cc, cond, dc);
296530376636SRichard Henderson     tcg_gen_brcond_tl(cmp.cond, cmp.c1, cmp.c2, lab);
296630376636SRichard Henderson 
296730376636SRichard Henderson     return advance_pc(dc);
296830376636SRichard Henderson }
296930376636SRichard Henderson 
297030376636SRichard Henderson static bool trans_Tcc_r(DisasContext *dc, arg_Tcc_r *a)
297130376636SRichard Henderson {
297230376636SRichard Henderson     if (avail_32(dc) && a->cc) {
297330376636SRichard Henderson         return false;
297430376636SRichard Henderson     }
297530376636SRichard Henderson     return do_tcc(dc, a->cond, a->cc, a->rs1, false, a->rs2);
297630376636SRichard Henderson }
297730376636SRichard Henderson 
297830376636SRichard Henderson static bool trans_Tcc_i_v7(DisasContext *dc, arg_Tcc_i_v7 *a)
297930376636SRichard Henderson {
298030376636SRichard Henderson     if (avail_64(dc)) {
298130376636SRichard Henderson         return false;
298230376636SRichard Henderson     }
298330376636SRichard Henderson     return do_tcc(dc, a->cond, 0, a->rs1, true, a->i);
298430376636SRichard Henderson }
298530376636SRichard Henderson 
298630376636SRichard Henderson static bool trans_Tcc_i_v9(DisasContext *dc, arg_Tcc_i_v9 *a)
298730376636SRichard Henderson {
298830376636SRichard Henderson     if (avail_32(dc)) {
298930376636SRichard Henderson         return false;
299030376636SRichard Henderson     }
299130376636SRichard Henderson     return do_tcc(dc, a->cond, a->cc, a->rs1, true, a->i);
299230376636SRichard Henderson }
299330376636SRichard Henderson 
2994af25071cSRichard Henderson static bool trans_STBAR(DisasContext *dc, arg_STBAR *a)
2995af25071cSRichard Henderson {
2996af25071cSRichard Henderson     tcg_gen_mb(TCG_MO_ST_ST | TCG_BAR_SC);
2997af25071cSRichard Henderson     return advance_pc(dc);
2998af25071cSRichard Henderson }
2999af25071cSRichard Henderson 
3000af25071cSRichard Henderson static bool trans_MEMBAR(DisasContext *dc, arg_MEMBAR *a)
3001af25071cSRichard Henderson {
3002af25071cSRichard Henderson     if (avail_32(dc)) {
3003af25071cSRichard Henderson         return false;
3004af25071cSRichard Henderson     }
3005af25071cSRichard Henderson     if (a->mmask) {
3006af25071cSRichard Henderson         /* Note TCG_MO_* was modeled on sparc64, so mmask matches. */
3007af25071cSRichard Henderson         tcg_gen_mb(a->mmask | TCG_BAR_SC);
3008af25071cSRichard Henderson     }
3009af25071cSRichard Henderson     if (a->cmask) {
3010af25071cSRichard Henderson         /* For #Sync, etc, end the TB to recognize interrupts. */
3011af25071cSRichard Henderson         dc->base.is_jmp = DISAS_EXIT;
3012af25071cSRichard Henderson     }
3013af25071cSRichard Henderson     return advance_pc(dc);
3014af25071cSRichard Henderson }
3015af25071cSRichard Henderson 
3016af25071cSRichard Henderson static bool do_rd_special(DisasContext *dc, bool priv, int rd,
3017af25071cSRichard Henderson                           TCGv (*func)(DisasContext *, TCGv))
3018af25071cSRichard Henderson {
3019af25071cSRichard Henderson     if (!priv) {
3020af25071cSRichard Henderson         return raise_priv(dc);
3021af25071cSRichard Henderson     }
3022af25071cSRichard Henderson     gen_store_gpr(dc, rd, func(dc, gen_dest_gpr(dc, rd)));
3023af25071cSRichard Henderson     return advance_pc(dc);
3024af25071cSRichard Henderson }
3025af25071cSRichard Henderson 
3026af25071cSRichard Henderson static TCGv do_rdy(DisasContext *dc, TCGv dst)
3027af25071cSRichard Henderson {
3028af25071cSRichard Henderson     return cpu_y;
3029af25071cSRichard Henderson }
3030af25071cSRichard Henderson 
3031af25071cSRichard Henderson static bool trans_RDY(DisasContext *dc, arg_RDY *a)
3032af25071cSRichard Henderson {
3033af25071cSRichard Henderson     /*
3034af25071cSRichard Henderson      * TODO: Need a feature bit for sparcv8.  In the meantime, treat all
3035af25071cSRichard Henderson      * 32-bit cpus like sparcv7, which ignores the rs1 field.
3036af25071cSRichard Henderson      * This matches after all other ASR, so Leon3 Asr17 is handled first.
3037af25071cSRichard Henderson      */
3038af25071cSRichard Henderson     if (avail_64(dc) && a->rs1 != 0) {
3039af25071cSRichard Henderson         return false;
3040af25071cSRichard Henderson     }
3041af25071cSRichard Henderson     return do_rd_special(dc, true, a->rd, do_rdy);
3042af25071cSRichard Henderson }
3043af25071cSRichard Henderson 
3044af25071cSRichard Henderson static TCGv do_rd_leon3_config(DisasContext *dc, TCGv dst)
3045af25071cSRichard Henderson {
3046af25071cSRichard Henderson     uint32_t val;
3047af25071cSRichard Henderson 
3048af25071cSRichard Henderson     /*
3049af25071cSRichard Henderson      * TODO: There are many more fields to be filled,
3050af25071cSRichard Henderson      * some of which are writable.
3051af25071cSRichard Henderson      */
3052af25071cSRichard Henderson     val = dc->def->nwindows - 1;   /* [4:0] NWIN */
3053af25071cSRichard Henderson     val |= 1 << 8;                 /* [8]   V8   */
3054af25071cSRichard Henderson 
3055af25071cSRichard Henderson     return tcg_constant_tl(val);
3056af25071cSRichard Henderson }
3057af25071cSRichard Henderson 
3058af25071cSRichard Henderson TRANS(RDASR17, ASR17, do_rd_special, true, a->rd, do_rd_leon3_config)
3059af25071cSRichard Henderson 
3060af25071cSRichard Henderson static TCGv do_rdccr(DisasContext *dc, TCGv dst)
3061af25071cSRichard Henderson {
3062af25071cSRichard Henderson     update_psr(dc);
3063af25071cSRichard Henderson     gen_helper_rdccr(dst, tcg_env);
3064af25071cSRichard Henderson     return dst;
3065af25071cSRichard Henderson }
3066af25071cSRichard Henderson 
3067af25071cSRichard Henderson TRANS(RDCCR, 64, do_rd_special, true, a->rd, do_rdccr)
3068af25071cSRichard Henderson 
3069af25071cSRichard Henderson static TCGv do_rdasi(DisasContext *dc, TCGv dst)
3070af25071cSRichard Henderson {
3071af25071cSRichard Henderson #ifdef TARGET_SPARC64
3072af25071cSRichard Henderson     return tcg_constant_tl(dc->asi);
3073af25071cSRichard Henderson #else
3074af25071cSRichard Henderson     qemu_build_not_reached();
3075af25071cSRichard Henderson #endif
3076af25071cSRichard Henderson }
3077af25071cSRichard Henderson 
3078af25071cSRichard Henderson TRANS(RDASI, 64, do_rd_special, true, a->rd, do_rdasi)
3079af25071cSRichard Henderson 
3080af25071cSRichard Henderson static TCGv do_rdtick(DisasContext *dc, TCGv dst)
3081af25071cSRichard Henderson {
3082af25071cSRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
3083af25071cSRichard Henderson 
3084af25071cSRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(tick));
3085af25071cSRichard Henderson     if (translator_io_start(&dc->base)) {
3086af25071cSRichard Henderson         dc->base.is_jmp = DISAS_EXIT;
3087af25071cSRichard Henderson     }
3088af25071cSRichard Henderson     gen_helper_tick_get_count(dst, tcg_env, r_tickptr,
3089af25071cSRichard Henderson                               tcg_constant_i32(dc->mem_idx));
3090af25071cSRichard Henderson     return dst;
3091af25071cSRichard Henderson }
3092af25071cSRichard Henderson 
3093af25071cSRichard Henderson /* TODO: non-priv access only allowed when enabled. */
3094af25071cSRichard Henderson TRANS(RDTICK, 64, do_rd_special, true, a->rd, do_rdtick)
3095af25071cSRichard Henderson 
3096af25071cSRichard Henderson static TCGv do_rdpc(DisasContext *dc, TCGv dst)
3097af25071cSRichard Henderson {
3098af25071cSRichard Henderson     return tcg_constant_tl(address_mask_i(dc, dc->pc));
3099af25071cSRichard Henderson }
3100af25071cSRichard Henderson 
3101af25071cSRichard Henderson TRANS(RDPC, 64, do_rd_special, true, a->rd, do_rdpc)
3102af25071cSRichard Henderson 
3103af25071cSRichard Henderson static TCGv do_rdfprs(DisasContext *dc, TCGv dst)
3104af25071cSRichard Henderson {
3105af25071cSRichard Henderson     tcg_gen_ext_i32_tl(dst, cpu_fprs);
3106af25071cSRichard Henderson     return dst;
3107af25071cSRichard Henderson }
3108af25071cSRichard Henderson 
3109af25071cSRichard Henderson TRANS(RDFPRS, 64, do_rd_special, true, a->rd, do_rdfprs)
3110af25071cSRichard Henderson 
3111af25071cSRichard Henderson static TCGv do_rdgsr(DisasContext *dc, TCGv dst)
3112af25071cSRichard Henderson {
3113af25071cSRichard Henderson     gen_trap_ifnofpu(dc);
3114af25071cSRichard Henderson     return cpu_gsr;
3115af25071cSRichard Henderson }
3116af25071cSRichard Henderson 
3117af25071cSRichard Henderson TRANS(RDGSR, 64, do_rd_special, true, a->rd, do_rdgsr)
3118af25071cSRichard Henderson 
3119af25071cSRichard Henderson static TCGv do_rdsoftint(DisasContext *dc, TCGv dst)
3120af25071cSRichard Henderson {
3121af25071cSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(softint));
3122af25071cSRichard Henderson     return dst;
3123af25071cSRichard Henderson }
3124af25071cSRichard Henderson 
3125af25071cSRichard Henderson TRANS(RDSOFTINT, 64, do_rd_special, supervisor(dc), a->rd, do_rdsoftint)
3126af25071cSRichard Henderson 
3127af25071cSRichard Henderson static TCGv do_rdtick_cmpr(DisasContext *dc, TCGv dst)
3128af25071cSRichard Henderson {
3129577efa45SRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(tick_cmpr));
3130577efa45SRichard Henderson     return dst;
3131af25071cSRichard Henderson }
3132af25071cSRichard Henderson 
3133af25071cSRichard Henderson /* TODO: non-priv access only allowed when enabled. */
3134af25071cSRichard Henderson TRANS(RDTICK_CMPR, 64, do_rd_special, true, a->rd, do_rdtick_cmpr)
3135af25071cSRichard Henderson 
3136af25071cSRichard Henderson static TCGv do_rdstick(DisasContext *dc, TCGv dst)
3137af25071cSRichard Henderson {
3138af25071cSRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
3139af25071cSRichard Henderson 
3140af25071cSRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(stick));
3141af25071cSRichard Henderson     if (translator_io_start(&dc->base)) {
3142af25071cSRichard Henderson         dc->base.is_jmp = DISAS_EXIT;
3143af25071cSRichard Henderson     }
3144af25071cSRichard Henderson     gen_helper_tick_get_count(dst, tcg_env, r_tickptr,
3145af25071cSRichard Henderson                               tcg_constant_i32(dc->mem_idx));
3146af25071cSRichard Henderson     return dst;
3147af25071cSRichard Henderson }
3148af25071cSRichard Henderson 
3149af25071cSRichard Henderson /* TODO: non-priv access only allowed when enabled. */
3150af25071cSRichard Henderson TRANS(RDSTICK, 64, do_rd_special, true, a->rd, do_rdstick)
3151af25071cSRichard Henderson 
3152af25071cSRichard Henderson static TCGv do_rdstick_cmpr(DisasContext *dc, TCGv dst)
3153af25071cSRichard Henderson {
3154577efa45SRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(stick_cmpr));
3155577efa45SRichard Henderson     return dst;
3156af25071cSRichard Henderson }
3157af25071cSRichard Henderson 
3158af25071cSRichard Henderson /* TODO: supervisor access only allowed when enabled by hypervisor. */
3159af25071cSRichard Henderson TRANS(RDSTICK_CMPR, 64, do_rd_special, supervisor(dc), a->rd, do_rdstick_cmpr)
3160af25071cSRichard Henderson 
3161af25071cSRichard Henderson /*
3162af25071cSRichard Henderson  * UltraSPARC-T1 Strand status.
3163af25071cSRichard Henderson  * HYPV check maybe not enough, UA2005 & UA2007 describe
3164af25071cSRichard Henderson  * this ASR as impl. dep
3165af25071cSRichard Henderson  */
3166af25071cSRichard Henderson static TCGv do_rdstrand_status(DisasContext *dc, TCGv dst)
3167af25071cSRichard Henderson {
3168af25071cSRichard Henderson     return tcg_constant_tl(1);
3169af25071cSRichard Henderson }
3170af25071cSRichard Henderson 
3171af25071cSRichard Henderson TRANS(RDSTRAND_STATUS, HYPV, do_rd_special, true, a->rd, do_rdstrand_status)
3172af25071cSRichard Henderson 
3173668bb9b7SRichard Henderson static TCGv do_rdpsr(DisasContext *dc, TCGv dst)
3174668bb9b7SRichard Henderson {
3175668bb9b7SRichard Henderson     update_psr(dc);
3176668bb9b7SRichard Henderson     gen_helper_rdpsr(dst, tcg_env);
3177668bb9b7SRichard Henderson     return dst;
3178668bb9b7SRichard Henderson }
3179668bb9b7SRichard Henderson 
3180668bb9b7SRichard Henderson TRANS(RDPSR, 32, do_rd_special, supervisor(dc), a->rd, do_rdpsr)
3181668bb9b7SRichard Henderson 
3182668bb9b7SRichard Henderson static TCGv do_rdhpstate(DisasContext *dc, TCGv dst)
3183668bb9b7SRichard Henderson {
3184668bb9b7SRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hpstate));
3185668bb9b7SRichard Henderson     return dst;
3186668bb9b7SRichard Henderson }
3187668bb9b7SRichard Henderson 
3188668bb9b7SRichard Henderson TRANS(RDHPR_hpstate, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhpstate)
3189668bb9b7SRichard Henderson 
3190668bb9b7SRichard Henderson static TCGv do_rdhtstate(DisasContext *dc, TCGv dst)
3191668bb9b7SRichard Henderson {
3192668bb9b7SRichard Henderson     TCGv_i32 tl = tcg_temp_new_i32();
3193668bb9b7SRichard Henderson     TCGv_ptr tp = tcg_temp_new_ptr();
3194668bb9b7SRichard Henderson 
3195668bb9b7SRichard Henderson     tcg_gen_ld_i32(tl, tcg_env, env64_field_offsetof(tl));
3196668bb9b7SRichard Henderson     tcg_gen_andi_i32(tl, tl, MAXTL_MASK);
3197668bb9b7SRichard Henderson     tcg_gen_shli_i32(tl, tl, 3);
3198668bb9b7SRichard Henderson     tcg_gen_ext_i32_ptr(tp, tl);
3199668bb9b7SRichard Henderson     tcg_gen_add_ptr(tp, tp, tcg_env);
3200668bb9b7SRichard Henderson 
3201668bb9b7SRichard Henderson     tcg_gen_ld_tl(dst, tp, env64_field_offsetof(htstate));
3202668bb9b7SRichard Henderson     return dst;
3203668bb9b7SRichard Henderson }
3204668bb9b7SRichard Henderson 
3205668bb9b7SRichard Henderson TRANS(RDHPR_htstate, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhtstate)
3206668bb9b7SRichard Henderson 
3207668bb9b7SRichard Henderson static TCGv do_rdhintp(DisasContext *dc, TCGv dst)
3208668bb9b7SRichard Henderson {
32092da789deSRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hintp));
32102da789deSRichard Henderson     return dst;
3211668bb9b7SRichard Henderson }
3212668bb9b7SRichard Henderson 
3213668bb9b7SRichard Henderson TRANS(RDHPR_hintp, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhintp)
3214668bb9b7SRichard Henderson 
3215668bb9b7SRichard Henderson static TCGv do_rdhtba(DisasContext *dc, TCGv dst)
3216668bb9b7SRichard Henderson {
32172da789deSRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(htba));
32182da789deSRichard Henderson     return dst;
3219668bb9b7SRichard Henderson }
3220668bb9b7SRichard Henderson 
3221668bb9b7SRichard Henderson TRANS(RDHPR_htba, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhtba)
3222668bb9b7SRichard Henderson 
3223668bb9b7SRichard Henderson static TCGv do_rdhver(DisasContext *dc, TCGv dst)
3224668bb9b7SRichard Henderson {
32252da789deSRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hver));
32262da789deSRichard Henderson     return dst;
3227668bb9b7SRichard Henderson }
3228668bb9b7SRichard Henderson 
3229668bb9b7SRichard Henderson TRANS(RDHPR_hver, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhver)
3230668bb9b7SRichard Henderson 
3231668bb9b7SRichard Henderson static TCGv do_rdhstick_cmpr(DisasContext *dc, TCGv dst)
3232668bb9b7SRichard Henderson {
3233577efa45SRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hstick_cmpr));
3234577efa45SRichard Henderson     return dst;
3235668bb9b7SRichard Henderson }
3236668bb9b7SRichard Henderson 
3237668bb9b7SRichard Henderson TRANS(RDHPR_hstick_cmpr, HYPV, do_rd_special, hypervisor(dc), a->rd,
3238668bb9b7SRichard Henderson       do_rdhstick_cmpr)
3239668bb9b7SRichard Henderson 
32405d617bfbSRichard Henderson static TCGv do_rdwim(DisasContext *dc, TCGv dst)
32415d617bfbSRichard Henderson {
3242cd6269f7SRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env32_field_offsetof(wim));
3243cd6269f7SRichard Henderson     return dst;
32445d617bfbSRichard Henderson }
32455d617bfbSRichard Henderson 
32465d617bfbSRichard Henderson TRANS(RDWIM, 32, do_rd_special, supervisor(dc), a->rd, do_rdwim)
32475d617bfbSRichard Henderson 
32485d617bfbSRichard Henderson static TCGv do_rdtpc(DisasContext *dc, TCGv dst)
32495d617bfbSRichard Henderson {
32505d617bfbSRichard Henderson #ifdef TARGET_SPARC64
32515d617bfbSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
32525d617bfbSRichard Henderson 
32535d617bfbSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
32545d617bfbSRichard Henderson     tcg_gen_ld_tl(dst, r_tsptr, offsetof(trap_state, tpc));
32555d617bfbSRichard Henderson     return dst;
32565d617bfbSRichard Henderson #else
32575d617bfbSRichard Henderson     qemu_build_not_reached();
32585d617bfbSRichard Henderson #endif
32595d617bfbSRichard Henderson }
32605d617bfbSRichard Henderson 
32615d617bfbSRichard Henderson TRANS(RDPR_tpc, 64, do_rd_special, supervisor(dc), a->rd, do_rdtpc)
32625d617bfbSRichard Henderson 
32635d617bfbSRichard Henderson static TCGv do_rdtnpc(DisasContext *dc, TCGv dst)
32645d617bfbSRichard Henderson {
32655d617bfbSRichard Henderson #ifdef TARGET_SPARC64
32665d617bfbSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
32675d617bfbSRichard Henderson 
32685d617bfbSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
32695d617bfbSRichard Henderson     tcg_gen_ld_tl(dst, r_tsptr, offsetof(trap_state, tnpc));
32705d617bfbSRichard Henderson     return dst;
32715d617bfbSRichard Henderson #else
32725d617bfbSRichard Henderson     qemu_build_not_reached();
32735d617bfbSRichard Henderson #endif
32745d617bfbSRichard Henderson }
32755d617bfbSRichard Henderson 
32765d617bfbSRichard Henderson TRANS(RDPR_tnpc, 64, do_rd_special, supervisor(dc), a->rd, do_rdtnpc)
32775d617bfbSRichard Henderson 
32785d617bfbSRichard Henderson static TCGv do_rdtstate(DisasContext *dc, TCGv dst)
32795d617bfbSRichard Henderson {
32805d617bfbSRichard Henderson #ifdef TARGET_SPARC64
32815d617bfbSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
32825d617bfbSRichard Henderson 
32835d617bfbSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
32845d617bfbSRichard Henderson     tcg_gen_ld_tl(dst, r_tsptr, offsetof(trap_state, tstate));
32855d617bfbSRichard Henderson     return dst;
32865d617bfbSRichard Henderson #else
32875d617bfbSRichard Henderson     qemu_build_not_reached();
32885d617bfbSRichard Henderson #endif
32895d617bfbSRichard Henderson }
32905d617bfbSRichard Henderson 
32915d617bfbSRichard Henderson TRANS(RDPR_tstate, 64, do_rd_special, supervisor(dc), a->rd, do_rdtstate)
32925d617bfbSRichard Henderson 
32935d617bfbSRichard Henderson static TCGv do_rdtt(DisasContext *dc, TCGv dst)
32945d617bfbSRichard Henderson {
32955d617bfbSRichard Henderson #ifdef TARGET_SPARC64
32965d617bfbSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
32975d617bfbSRichard Henderson 
32985d617bfbSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
32995d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, r_tsptr, offsetof(trap_state, tt));
33005d617bfbSRichard Henderson     return dst;
33015d617bfbSRichard Henderson #else
33025d617bfbSRichard Henderson     qemu_build_not_reached();
33035d617bfbSRichard Henderson #endif
33045d617bfbSRichard Henderson }
33055d617bfbSRichard Henderson 
33065d617bfbSRichard Henderson TRANS(RDPR_tt, 64, do_rd_special, supervisor(dc), a->rd, do_rdtt)
33075d617bfbSRichard Henderson TRANS(RDPR_tick, 64, do_rd_special, supervisor(dc), a->rd, do_rdtick)
33085d617bfbSRichard Henderson 
33095d617bfbSRichard Henderson static TCGv do_rdtba(DisasContext *dc, TCGv dst)
33105d617bfbSRichard Henderson {
33115d617bfbSRichard Henderson     return cpu_tbr;
33125d617bfbSRichard Henderson }
33135d617bfbSRichard Henderson 
3314e8325dc0SRichard Henderson TRANS(RDTBR, 32, do_rd_special, supervisor(dc), a->rd, do_rdtba)
33155d617bfbSRichard Henderson TRANS(RDPR_tba, 64, do_rd_special, supervisor(dc), a->rd, do_rdtba)
33165d617bfbSRichard Henderson 
33175d617bfbSRichard Henderson static TCGv do_rdpstate(DisasContext *dc, TCGv dst)
33185d617bfbSRichard Henderson {
33195d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(pstate));
33205d617bfbSRichard Henderson     return dst;
33215d617bfbSRichard Henderson }
33225d617bfbSRichard Henderson 
33235d617bfbSRichard Henderson TRANS(RDPR_pstate, 64, do_rd_special, supervisor(dc), a->rd, do_rdpstate)
33245d617bfbSRichard Henderson 
33255d617bfbSRichard Henderson static TCGv do_rdtl(DisasContext *dc, TCGv dst)
33265d617bfbSRichard Henderson {
33275d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(tl));
33285d617bfbSRichard Henderson     return dst;
33295d617bfbSRichard Henderson }
33305d617bfbSRichard Henderson 
33315d617bfbSRichard Henderson TRANS(RDPR_tl, 64, do_rd_special, supervisor(dc), a->rd, do_rdtl)
33325d617bfbSRichard Henderson 
33335d617bfbSRichard Henderson static TCGv do_rdpil(DisasContext *dc, TCGv dst)
33345d617bfbSRichard Henderson {
33355d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env_field_offsetof(psrpil));
33365d617bfbSRichard Henderson     return dst;
33375d617bfbSRichard Henderson }
33385d617bfbSRichard Henderson 
33395d617bfbSRichard Henderson TRANS(RDPR_pil, 64, do_rd_special, supervisor(dc), a->rd, do_rdpil)
33405d617bfbSRichard Henderson 
33415d617bfbSRichard Henderson static TCGv do_rdcwp(DisasContext *dc, TCGv dst)
33425d617bfbSRichard Henderson {
33435d617bfbSRichard Henderson     gen_helper_rdcwp(dst, tcg_env);
33445d617bfbSRichard Henderson     return dst;
33455d617bfbSRichard Henderson }
33465d617bfbSRichard Henderson 
33475d617bfbSRichard Henderson TRANS(RDPR_cwp, 64, do_rd_special, supervisor(dc), a->rd, do_rdcwp)
33485d617bfbSRichard Henderson 
33495d617bfbSRichard Henderson static TCGv do_rdcansave(DisasContext *dc, TCGv dst)
33505d617bfbSRichard Henderson {
33515d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(cansave));
33525d617bfbSRichard Henderson     return dst;
33535d617bfbSRichard Henderson }
33545d617bfbSRichard Henderson 
33555d617bfbSRichard Henderson TRANS(RDPR_cansave, 64, do_rd_special, supervisor(dc), a->rd, do_rdcansave)
33565d617bfbSRichard Henderson 
33575d617bfbSRichard Henderson static TCGv do_rdcanrestore(DisasContext *dc, TCGv dst)
33585d617bfbSRichard Henderson {
33595d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(canrestore));
33605d617bfbSRichard Henderson     return dst;
33615d617bfbSRichard Henderson }
33625d617bfbSRichard Henderson 
33635d617bfbSRichard Henderson TRANS(RDPR_canrestore, 64, do_rd_special, supervisor(dc), a->rd,
33645d617bfbSRichard Henderson       do_rdcanrestore)
33655d617bfbSRichard Henderson 
33665d617bfbSRichard Henderson static TCGv do_rdcleanwin(DisasContext *dc, TCGv dst)
33675d617bfbSRichard Henderson {
33685d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(cleanwin));
33695d617bfbSRichard Henderson     return dst;
33705d617bfbSRichard Henderson }
33715d617bfbSRichard Henderson 
33725d617bfbSRichard Henderson TRANS(RDPR_cleanwin, 64, do_rd_special, supervisor(dc), a->rd, do_rdcleanwin)
33735d617bfbSRichard Henderson 
33745d617bfbSRichard Henderson static TCGv do_rdotherwin(DisasContext *dc, TCGv dst)
33755d617bfbSRichard Henderson {
33765d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(otherwin));
33775d617bfbSRichard Henderson     return dst;
33785d617bfbSRichard Henderson }
33795d617bfbSRichard Henderson 
33805d617bfbSRichard Henderson TRANS(RDPR_otherwin, 64, do_rd_special, supervisor(dc), a->rd, do_rdotherwin)
33815d617bfbSRichard Henderson 
33825d617bfbSRichard Henderson static TCGv do_rdwstate(DisasContext *dc, TCGv dst)
33835d617bfbSRichard Henderson {
33845d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(wstate));
33855d617bfbSRichard Henderson     return dst;
33865d617bfbSRichard Henderson }
33875d617bfbSRichard Henderson 
33885d617bfbSRichard Henderson TRANS(RDPR_wstate, 64, do_rd_special, supervisor(dc), a->rd, do_rdwstate)
33895d617bfbSRichard Henderson 
33905d617bfbSRichard Henderson static TCGv do_rdgl(DisasContext *dc, TCGv dst)
33915d617bfbSRichard Henderson {
33925d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(gl));
33935d617bfbSRichard Henderson     return dst;
33945d617bfbSRichard Henderson }
33955d617bfbSRichard Henderson 
33965d617bfbSRichard Henderson TRANS(RDPR_gl, GL, do_rd_special, supervisor(dc), a->rd, do_rdgl)
33975d617bfbSRichard Henderson 
33985d617bfbSRichard Henderson /* UA2005 strand status */
33995d617bfbSRichard Henderson static TCGv do_rdssr(DisasContext *dc, TCGv dst)
34005d617bfbSRichard Henderson {
34012da789deSRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(ssr));
34022da789deSRichard Henderson     return dst;
34035d617bfbSRichard Henderson }
34045d617bfbSRichard Henderson 
34055d617bfbSRichard Henderson TRANS(RDPR_strand_status, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdssr)
34065d617bfbSRichard Henderson 
34075d617bfbSRichard Henderson static TCGv do_rdver(DisasContext *dc, TCGv dst)
34085d617bfbSRichard Henderson {
34092da789deSRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(version));
34102da789deSRichard Henderson     return dst;
34115d617bfbSRichard Henderson }
34125d617bfbSRichard Henderson 
34135d617bfbSRichard Henderson TRANS(RDPR_ver, 64, do_rd_special, supervisor(dc), a->rd, do_rdver)
34145d617bfbSRichard Henderson 
3415e8325dc0SRichard Henderson static bool trans_FLUSHW(DisasContext *dc, arg_FLUSHW *a)
3416e8325dc0SRichard Henderson {
3417e8325dc0SRichard Henderson     if (avail_64(dc)) {
3418e8325dc0SRichard Henderson         gen_helper_flushw(tcg_env);
3419e8325dc0SRichard Henderson         return advance_pc(dc);
3420e8325dc0SRichard Henderson     }
3421e8325dc0SRichard Henderson     return false;
3422e8325dc0SRichard Henderson }
3423e8325dc0SRichard Henderson 
34240faef01bSRichard Henderson static bool do_wr_special(DisasContext *dc, arg_r_r_ri *a, bool priv,
34250faef01bSRichard Henderson                           void (*func)(DisasContext *, TCGv))
34260faef01bSRichard Henderson {
34270faef01bSRichard Henderson     TCGv src;
34280faef01bSRichard Henderson 
34290faef01bSRichard Henderson     /* For simplicity, we under-decoded the rs2 form. */
34300faef01bSRichard Henderson     if (!a->imm && (a->rs2_or_imm & ~0x1f)) {
34310faef01bSRichard Henderson         return false;
34320faef01bSRichard Henderson     }
34330faef01bSRichard Henderson     if (!priv) {
34340faef01bSRichard Henderson         return raise_priv(dc);
34350faef01bSRichard Henderson     }
34360faef01bSRichard Henderson 
34370faef01bSRichard Henderson     if (a->rs1 == 0 && (a->imm || a->rs2_or_imm == 0)) {
34380faef01bSRichard Henderson         src = tcg_constant_tl(a->rs2_or_imm);
34390faef01bSRichard Henderson     } else {
34400faef01bSRichard Henderson         TCGv src1 = gen_load_gpr(dc, a->rs1);
34410faef01bSRichard Henderson         if (a->rs2_or_imm == 0) {
34420faef01bSRichard Henderson             src = src1;
34430faef01bSRichard Henderson         } else {
34440faef01bSRichard Henderson             src = tcg_temp_new();
34450faef01bSRichard Henderson             if (a->imm) {
34460faef01bSRichard Henderson                 tcg_gen_xori_tl(src, src1, a->rs2_or_imm);
34470faef01bSRichard Henderson             } else {
34480faef01bSRichard Henderson                 tcg_gen_xor_tl(src, src1, gen_load_gpr(dc, a->rs2_or_imm));
34490faef01bSRichard Henderson             }
34500faef01bSRichard Henderson         }
34510faef01bSRichard Henderson     }
34520faef01bSRichard Henderson     func(dc, src);
34530faef01bSRichard Henderson     return advance_pc(dc);
34540faef01bSRichard Henderson }
34550faef01bSRichard Henderson 
34560faef01bSRichard Henderson static void do_wry(DisasContext *dc, TCGv src)
34570faef01bSRichard Henderson {
34580faef01bSRichard Henderson     tcg_gen_ext32u_tl(cpu_y, src);
34590faef01bSRichard Henderson }
34600faef01bSRichard Henderson 
34610faef01bSRichard Henderson TRANS(WRY, ALL, do_wr_special, a, true, do_wry)
34620faef01bSRichard Henderson 
34630faef01bSRichard Henderson static void do_wrccr(DisasContext *dc, TCGv src)
34640faef01bSRichard Henderson {
34650faef01bSRichard Henderson     gen_helper_wrccr(tcg_env, src);
34660faef01bSRichard Henderson }
34670faef01bSRichard Henderson 
34680faef01bSRichard Henderson TRANS(WRCCR, 64, do_wr_special, a, true, do_wrccr)
34690faef01bSRichard Henderson 
34700faef01bSRichard Henderson static void do_wrasi(DisasContext *dc, TCGv src)
34710faef01bSRichard Henderson {
34720faef01bSRichard Henderson     TCGv tmp = tcg_temp_new();
34730faef01bSRichard Henderson 
34740faef01bSRichard Henderson     tcg_gen_ext8u_tl(tmp, src);
34750faef01bSRichard Henderson     tcg_gen_st32_tl(tmp, tcg_env, env64_field_offsetof(asi));
34760faef01bSRichard Henderson     /* End TB to notice changed ASI. */
34770faef01bSRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
34780faef01bSRichard Henderson }
34790faef01bSRichard Henderson 
34800faef01bSRichard Henderson TRANS(WRASI, 64, do_wr_special, a, true, do_wrasi)
34810faef01bSRichard Henderson 
34820faef01bSRichard Henderson static void do_wrfprs(DisasContext *dc, TCGv src)
34830faef01bSRichard Henderson {
34840faef01bSRichard Henderson #ifdef TARGET_SPARC64
34850faef01bSRichard Henderson     tcg_gen_trunc_tl_i32(cpu_fprs, src);
34860faef01bSRichard Henderson     dc->fprs_dirty = 0;
34870faef01bSRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
34880faef01bSRichard Henderson #else
34890faef01bSRichard Henderson     qemu_build_not_reached();
34900faef01bSRichard Henderson #endif
34910faef01bSRichard Henderson }
34920faef01bSRichard Henderson 
34930faef01bSRichard Henderson TRANS(WRFPRS, 64, do_wr_special, a, true, do_wrfprs)
34940faef01bSRichard Henderson 
34950faef01bSRichard Henderson static void do_wrgsr(DisasContext *dc, TCGv src)
34960faef01bSRichard Henderson {
34970faef01bSRichard Henderson     gen_trap_ifnofpu(dc);
34980faef01bSRichard Henderson     tcg_gen_mov_tl(cpu_gsr, src);
34990faef01bSRichard Henderson }
35000faef01bSRichard Henderson 
35010faef01bSRichard Henderson TRANS(WRGSR, 64, do_wr_special, a, true, do_wrgsr)
35020faef01bSRichard Henderson 
35030faef01bSRichard Henderson static void do_wrsoftint_set(DisasContext *dc, TCGv src)
35040faef01bSRichard Henderson {
35050faef01bSRichard Henderson     gen_helper_set_softint(tcg_env, src);
35060faef01bSRichard Henderson }
35070faef01bSRichard Henderson 
35080faef01bSRichard Henderson TRANS(WRSOFTINT_SET, 64, do_wr_special, a, supervisor(dc), do_wrsoftint_set)
35090faef01bSRichard Henderson 
35100faef01bSRichard Henderson static void do_wrsoftint_clr(DisasContext *dc, TCGv src)
35110faef01bSRichard Henderson {
35120faef01bSRichard Henderson     gen_helper_clear_softint(tcg_env, src);
35130faef01bSRichard Henderson }
35140faef01bSRichard Henderson 
35150faef01bSRichard Henderson TRANS(WRSOFTINT_CLR, 64, do_wr_special, a, supervisor(dc), do_wrsoftint_clr)
35160faef01bSRichard Henderson 
35170faef01bSRichard Henderson static void do_wrsoftint(DisasContext *dc, TCGv src)
35180faef01bSRichard Henderson {
35190faef01bSRichard Henderson     gen_helper_write_softint(tcg_env, src);
35200faef01bSRichard Henderson }
35210faef01bSRichard Henderson 
35220faef01bSRichard Henderson TRANS(WRSOFTINT, 64, do_wr_special, a, supervisor(dc), do_wrsoftint)
35230faef01bSRichard Henderson 
35240faef01bSRichard Henderson static void do_wrtick_cmpr(DisasContext *dc, TCGv src)
35250faef01bSRichard Henderson {
35260faef01bSRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
35270faef01bSRichard Henderson 
3528577efa45SRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(tick_cmpr));
3529577efa45SRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(tick));
35300faef01bSRichard Henderson     translator_io_start(&dc->base);
3531577efa45SRichard Henderson     gen_helper_tick_set_limit(r_tickptr, src);
35320faef01bSRichard Henderson     /* End TB to handle timer interrupt */
35330faef01bSRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
35340faef01bSRichard Henderson }
35350faef01bSRichard Henderson 
35360faef01bSRichard Henderson TRANS(WRTICK_CMPR, 64, do_wr_special, a, supervisor(dc), do_wrtick_cmpr)
35370faef01bSRichard Henderson 
35380faef01bSRichard Henderson static void do_wrstick(DisasContext *dc, TCGv src)
35390faef01bSRichard Henderson {
35400faef01bSRichard Henderson #ifdef TARGET_SPARC64
35410faef01bSRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
35420faef01bSRichard Henderson 
35430faef01bSRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, offsetof(CPUSPARCState, stick));
35440faef01bSRichard Henderson     translator_io_start(&dc->base);
35450faef01bSRichard Henderson     gen_helper_tick_set_count(r_tickptr, src);
35460faef01bSRichard Henderson     /* End TB to handle timer interrupt */
35470faef01bSRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
35480faef01bSRichard Henderson #else
35490faef01bSRichard Henderson     qemu_build_not_reached();
35500faef01bSRichard Henderson #endif
35510faef01bSRichard Henderson }
35520faef01bSRichard Henderson 
35530faef01bSRichard Henderson TRANS(WRSTICK, 64, do_wr_special, a, supervisor(dc), do_wrstick)
35540faef01bSRichard Henderson 
35550faef01bSRichard Henderson static void do_wrstick_cmpr(DisasContext *dc, TCGv src)
35560faef01bSRichard Henderson {
35570faef01bSRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
35580faef01bSRichard Henderson 
3559577efa45SRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(stick_cmpr));
3560577efa45SRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(stick));
35610faef01bSRichard Henderson     translator_io_start(&dc->base);
3562577efa45SRichard Henderson     gen_helper_tick_set_limit(r_tickptr, src);
35630faef01bSRichard Henderson     /* End TB to handle timer interrupt */
35640faef01bSRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
35650faef01bSRichard Henderson }
35660faef01bSRichard Henderson 
35670faef01bSRichard Henderson TRANS(WRSTICK_CMPR, 64, do_wr_special, a, supervisor(dc), do_wrstick_cmpr)
35680faef01bSRichard Henderson 
35690faef01bSRichard Henderson static void do_wrpowerdown(DisasContext *dc, TCGv src)
35700faef01bSRichard Henderson {
35710faef01bSRichard Henderson     save_state(dc);
35720faef01bSRichard Henderson     gen_helper_power_down(tcg_env);
35730faef01bSRichard Henderson }
35740faef01bSRichard Henderson 
35750faef01bSRichard Henderson TRANS(WRPOWERDOWN, POWERDOWN, do_wr_special, a, supervisor(dc), do_wrpowerdown)
35760faef01bSRichard Henderson 
357725524734SRichard Henderson static void do_wrpsr(DisasContext *dc, TCGv src)
357825524734SRichard Henderson {
357925524734SRichard Henderson     gen_helper_wrpsr(tcg_env, src);
358025524734SRichard Henderson     tcg_gen_movi_i32(cpu_cc_op, CC_OP_FLAGS);
358125524734SRichard Henderson     dc->cc_op = CC_OP_FLAGS;
358225524734SRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
358325524734SRichard Henderson }
358425524734SRichard Henderson 
358525524734SRichard Henderson TRANS(WRPSR, 32, do_wr_special, a, supervisor(dc), do_wrpsr)
358625524734SRichard Henderson 
35879422278eSRichard Henderson static void do_wrwim(DisasContext *dc, TCGv src)
35889422278eSRichard Henderson {
35899422278eSRichard Henderson     target_ulong mask = MAKE_64BIT_MASK(0, dc->def->nwindows);
3590cd6269f7SRichard Henderson     TCGv tmp = tcg_temp_new();
3591cd6269f7SRichard Henderson 
3592cd6269f7SRichard Henderson     tcg_gen_andi_tl(tmp, src, mask);
3593cd6269f7SRichard Henderson     tcg_gen_st_tl(tmp, tcg_env, env32_field_offsetof(wim));
35949422278eSRichard Henderson }
35959422278eSRichard Henderson 
35969422278eSRichard Henderson TRANS(WRWIM, 32, do_wr_special, a, supervisor(dc), do_wrwim)
35979422278eSRichard Henderson 
35989422278eSRichard Henderson static void do_wrtpc(DisasContext *dc, TCGv src)
35999422278eSRichard Henderson {
36009422278eSRichard Henderson #ifdef TARGET_SPARC64
36019422278eSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
36029422278eSRichard Henderson 
36039422278eSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
36049422278eSRichard Henderson     tcg_gen_st_tl(src, r_tsptr, offsetof(trap_state, tpc));
36059422278eSRichard Henderson #else
36069422278eSRichard Henderson     qemu_build_not_reached();
36079422278eSRichard Henderson #endif
36089422278eSRichard Henderson }
36099422278eSRichard Henderson 
36109422278eSRichard Henderson TRANS(WRPR_tpc, 64, do_wr_special, a, supervisor(dc), do_wrtpc)
36119422278eSRichard Henderson 
36129422278eSRichard Henderson static void do_wrtnpc(DisasContext *dc, TCGv src)
36139422278eSRichard Henderson {
36149422278eSRichard Henderson #ifdef TARGET_SPARC64
36159422278eSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
36169422278eSRichard Henderson 
36179422278eSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
36189422278eSRichard Henderson     tcg_gen_st_tl(src, r_tsptr, offsetof(trap_state, tnpc));
36199422278eSRichard Henderson #else
36209422278eSRichard Henderson     qemu_build_not_reached();
36219422278eSRichard Henderson #endif
36229422278eSRichard Henderson }
36239422278eSRichard Henderson 
36249422278eSRichard Henderson TRANS(WRPR_tnpc, 64, do_wr_special, a, supervisor(dc), do_wrtnpc)
36259422278eSRichard Henderson 
36269422278eSRichard Henderson static void do_wrtstate(DisasContext *dc, TCGv src)
36279422278eSRichard Henderson {
36289422278eSRichard Henderson #ifdef TARGET_SPARC64
36299422278eSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
36309422278eSRichard Henderson 
36319422278eSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
36329422278eSRichard Henderson     tcg_gen_st_tl(src, r_tsptr, offsetof(trap_state, tstate));
36339422278eSRichard Henderson #else
36349422278eSRichard Henderson     qemu_build_not_reached();
36359422278eSRichard Henderson #endif
36369422278eSRichard Henderson }
36379422278eSRichard Henderson 
36389422278eSRichard Henderson TRANS(WRPR_tstate, 64, do_wr_special, a, supervisor(dc), do_wrtstate)
36399422278eSRichard Henderson 
36409422278eSRichard Henderson static void do_wrtt(DisasContext *dc, TCGv src)
36419422278eSRichard Henderson {
36429422278eSRichard Henderson #ifdef TARGET_SPARC64
36439422278eSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
36449422278eSRichard Henderson 
36459422278eSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
36469422278eSRichard Henderson     tcg_gen_st32_tl(src, r_tsptr, offsetof(trap_state, tt));
36479422278eSRichard Henderson #else
36489422278eSRichard Henderson     qemu_build_not_reached();
36499422278eSRichard Henderson #endif
36509422278eSRichard Henderson }
36519422278eSRichard Henderson 
36529422278eSRichard Henderson TRANS(WRPR_tt, 64, do_wr_special, a, supervisor(dc), do_wrtt)
36539422278eSRichard Henderson 
36549422278eSRichard Henderson static void do_wrtick(DisasContext *dc, TCGv src)
36559422278eSRichard Henderson {
36569422278eSRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
36579422278eSRichard Henderson 
36589422278eSRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(tick));
36599422278eSRichard Henderson     translator_io_start(&dc->base);
36609422278eSRichard Henderson     gen_helper_tick_set_count(r_tickptr, src);
36619422278eSRichard Henderson     /* End TB to handle timer interrupt */
36629422278eSRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
36639422278eSRichard Henderson }
36649422278eSRichard Henderson 
36659422278eSRichard Henderson TRANS(WRPR_tick, 64, do_wr_special, a, supervisor(dc), do_wrtick)
36669422278eSRichard Henderson 
36679422278eSRichard Henderson static void do_wrtba(DisasContext *dc, TCGv src)
36689422278eSRichard Henderson {
36699422278eSRichard Henderson     tcg_gen_mov_tl(cpu_tbr, src);
36709422278eSRichard Henderson }
36719422278eSRichard Henderson 
36729422278eSRichard Henderson TRANS(WRPR_tba, 64, do_wr_special, a, supervisor(dc), do_wrtba)
36739422278eSRichard Henderson 
36749422278eSRichard Henderson static void do_wrpstate(DisasContext *dc, TCGv src)
36759422278eSRichard Henderson {
36769422278eSRichard Henderson     save_state(dc);
36779422278eSRichard Henderson     if (translator_io_start(&dc->base)) {
36789422278eSRichard Henderson         dc->base.is_jmp = DISAS_EXIT;
36799422278eSRichard Henderson     }
36809422278eSRichard Henderson     gen_helper_wrpstate(tcg_env, src);
36819422278eSRichard Henderson     dc->npc = DYNAMIC_PC;
36829422278eSRichard Henderson }
36839422278eSRichard Henderson 
36849422278eSRichard Henderson TRANS(WRPR_pstate, 64, do_wr_special, a, supervisor(dc), do_wrpstate)
36859422278eSRichard Henderson 
36869422278eSRichard Henderson static void do_wrtl(DisasContext *dc, TCGv src)
36879422278eSRichard Henderson {
36889422278eSRichard Henderson     save_state(dc);
36899422278eSRichard Henderson     tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(tl));
36909422278eSRichard Henderson     dc->npc = DYNAMIC_PC;
36919422278eSRichard Henderson }
36929422278eSRichard Henderson 
36939422278eSRichard Henderson TRANS(WRPR_tl, 64, do_wr_special, a, supervisor(dc), do_wrtl)
36949422278eSRichard Henderson 
36959422278eSRichard Henderson static void do_wrpil(DisasContext *dc, TCGv src)
36969422278eSRichard Henderson {
36979422278eSRichard Henderson     if (translator_io_start(&dc->base)) {
36989422278eSRichard Henderson         dc->base.is_jmp = DISAS_EXIT;
36999422278eSRichard Henderson     }
37009422278eSRichard Henderson     gen_helper_wrpil(tcg_env, src);
37019422278eSRichard Henderson }
37029422278eSRichard Henderson 
37039422278eSRichard Henderson TRANS(WRPR_pil, 64, do_wr_special, a, supervisor(dc), do_wrpil)
37049422278eSRichard Henderson 
37059422278eSRichard Henderson static void do_wrcwp(DisasContext *dc, TCGv src)
37069422278eSRichard Henderson {
37079422278eSRichard Henderson     gen_helper_wrcwp(tcg_env, src);
37089422278eSRichard Henderson }
37099422278eSRichard Henderson 
37109422278eSRichard Henderson TRANS(WRPR_cwp, 64, do_wr_special, a, supervisor(dc), do_wrcwp)
37119422278eSRichard Henderson 
37129422278eSRichard Henderson static void do_wrcansave(DisasContext *dc, TCGv src)
37139422278eSRichard Henderson {
37149422278eSRichard Henderson     tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(cansave));
37159422278eSRichard Henderson }
37169422278eSRichard Henderson 
37179422278eSRichard Henderson TRANS(WRPR_cansave, 64, do_wr_special, a, supervisor(dc), do_wrcansave)
37189422278eSRichard Henderson 
37199422278eSRichard Henderson static void do_wrcanrestore(DisasContext *dc, TCGv src)
37209422278eSRichard Henderson {
37219422278eSRichard Henderson     tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(canrestore));
37229422278eSRichard Henderson }
37239422278eSRichard Henderson 
37249422278eSRichard Henderson TRANS(WRPR_canrestore, 64, do_wr_special, a, supervisor(dc), do_wrcanrestore)
37259422278eSRichard Henderson 
37269422278eSRichard Henderson static void do_wrcleanwin(DisasContext *dc, TCGv src)
37279422278eSRichard Henderson {
37289422278eSRichard Henderson     tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(cleanwin));
37299422278eSRichard Henderson }
37309422278eSRichard Henderson 
37319422278eSRichard Henderson TRANS(WRPR_cleanwin, 64, do_wr_special, a, supervisor(dc), do_wrcleanwin)
37329422278eSRichard Henderson 
37339422278eSRichard Henderson static void do_wrotherwin(DisasContext *dc, TCGv src)
37349422278eSRichard Henderson {
37359422278eSRichard Henderson     tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(otherwin));
37369422278eSRichard Henderson }
37379422278eSRichard Henderson 
37389422278eSRichard Henderson TRANS(WRPR_otherwin, 64, do_wr_special, a, supervisor(dc), do_wrotherwin)
37399422278eSRichard Henderson 
37409422278eSRichard Henderson static void do_wrwstate(DisasContext *dc, TCGv src)
37419422278eSRichard Henderson {
37429422278eSRichard Henderson     tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(wstate));
37439422278eSRichard Henderson }
37449422278eSRichard Henderson 
37459422278eSRichard Henderson TRANS(WRPR_wstate, 64, do_wr_special, a, supervisor(dc), do_wrwstate)
37469422278eSRichard Henderson 
37479422278eSRichard Henderson static void do_wrgl(DisasContext *dc, TCGv src)
37489422278eSRichard Henderson {
37499422278eSRichard Henderson     gen_helper_wrgl(tcg_env, src);
37509422278eSRichard Henderson }
37519422278eSRichard Henderson 
37529422278eSRichard Henderson TRANS(WRPR_gl, GL, do_wr_special, a, supervisor(dc), do_wrgl)
37539422278eSRichard Henderson 
37549422278eSRichard Henderson /* UA2005 strand status */
37559422278eSRichard Henderson static void do_wrssr(DisasContext *dc, TCGv src)
37569422278eSRichard Henderson {
37572da789deSRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(ssr));
37589422278eSRichard Henderson }
37599422278eSRichard Henderson 
37609422278eSRichard Henderson TRANS(WRPR_strand_status, HYPV, do_wr_special, a, hypervisor(dc), do_wrssr)
37619422278eSRichard Henderson 
3762bb97f2f5SRichard Henderson TRANS(WRTBR, 32, do_wr_special, a, supervisor(dc), do_wrtba)
3763bb97f2f5SRichard Henderson 
3764bb97f2f5SRichard Henderson static void do_wrhpstate(DisasContext *dc, TCGv src)
3765bb97f2f5SRichard Henderson {
3766bb97f2f5SRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(hpstate));
3767bb97f2f5SRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
3768bb97f2f5SRichard Henderson }
3769bb97f2f5SRichard Henderson 
3770bb97f2f5SRichard Henderson TRANS(WRHPR_hpstate, HYPV, do_wr_special, a, hypervisor(dc), do_wrhpstate)
3771bb97f2f5SRichard Henderson 
3772bb97f2f5SRichard Henderson static void do_wrhtstate(DisasContext *dc, TCGv src)
3773bb97f2f5SRichard Henderson {
3774bb97f2f5SRichard Henderson     TCGv_i32 tl = tcg_temp_new_i32();
3775bb97f2f5SRichard Henderson     TCGv_ptr tp = tcg_temp_new_ptr();
3776bb97f2f5SRichard Henderson 
3777bb97f2f5SRichard Henderson     tcg_gen_ld_i32(tl, tcg_env, env64_field_offsetof(tl));
3778bb97f2f5SRichard Henderson     tcg_gen_andi_i32(tl, tl, MAXTL_MASK);
3779bb97f2f5SRichard Henderson     tcg_gen_shli_i32(tl, tl, 3);
3780bb97f2f5SRichard Henderson     tcg_gen_ext_i32_ptr(tp, tl);
3781bb97f2f5SRichard Henderson     tcg_gen_add_ptr(tp, tp, tcg_env);
3782bb97f2f5SRichard Henderson 
3783bb97f2f5SRichard Henderson     tcg_gen_st_tl(src, tp, env64_field_offsetof(htstate));
3784bb97f2f5SRichard Henderson }
3785bb97f2f5SRichard Henderson 
3786bb97f2f5SRichard Henderson TRANS(WRHPR_htstate, HYPV, do_wr_special, a, hypervisor(dc), do_wrhtstate)
3787bb97f2f5SRichard Henderson 
3788bb97f2f5SRichard Henderson static void do_wrhintp(DisasContext *dc, TCGv src)
3789bb97f2f5SRichard Henderson {
37902da789deSRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(hintp));
3791bb97f2f5SRichard Henderson }
3792bb97f2f5SRichard Henderson 
3793bb97f2f5SRichard Henderson TRANS(WRHPR_hintp, HYPV, do_wr_special, a, hypervisor(dc), do_wrhintp)
3794bb97f2f5SRichard Henderson 
3795bb97f2f5SRichard Henderson static void do_wrhtba(DisasContext *dc, TCGv src)
3796bb97f2f5SRichard Henderson {
37972da789deSRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(htba));
3798bb97f2f5SRichard Henderson }
3799bb97f2f5SRichard Henderson 
3800bb97f2f5SRichard Henderson TRANS(WRHPR_htba, HYPV, do_wr_special, a, hypervisor(dc), do_wrhtba)
3801bb97f2f5SRichard Henderson 
3802bb97f2f5SRichard Henderson static void do_wrhstick_cmpr(DisasContext *dc, TCGv src)
3803bb97f2f5SRichard Henderson {
3804bb97f2f5SRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
3805bb97f2f5SRichard Henderson 
3806577efa45SRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(hstick_cmpr));
3807bb97f2f5SRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(hstick));
3808bb97f2f5SRichard Henderson     translator_io_start(&dc->base);
3809577efa45SRichard Henderson     gen_helper_tick_set_limit(r_tickptr, src);
3810bb97f2f5SRichard Henderson     /* End TB to handle timer interrupt */
3811bb97f2f5SRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
3812bb97f2f5SRichard Henderson }
3813bb97f2f5SRichard Henderson 
3814bb97f2f5SRichard Henderson TRANS(WRHPR_hstick_cmpr, HYPV, do_wr_special, a, hypervisor(dc),
3815bb97f2f5SRichard Henderson       do_wrhstick_cmpr)
3816bb97f2f5SRichard Henderson 
381725524734SRichard Henderson static bool do_saved_restored(DisasContext *dc, bool saved)
381825524734SRichard Henderson {
381925524734SRichard Henderson     if (!supervisor(dc)) {
382025524734SRichard Henderson         return raise_priv(dc);
382125524734SRichard Henderson     }
382225524734SRichard Henderson     if (saved) {
382325524734SRichard Henderson         gen_helper_saved(tcg_env);
382425524734SRichard Henderson     } else {
382525524734SRichard Henderson         gen_helper_restored(tcg_env);
382625524734SRichard Henderson     }
382725524734SRichard Henderson     return advance_pc(dc);
382825524734SRichard Henderson }
382925524734SRichard Henderson 
383025524734SRichard Henderson TRANS(SAVED, 64, do_saved_restored, true)
383125524734SRichard Henderson TRANS(RESTORED, 64, do_saved_restored, false)
383225524734SRichard Henderson 
3833d3825800SRichard Henderson static bool trans_NOP(DisasContext *dc, arg_NOP *a)
3834d3825800SRichard Henderson {
3835d3825800SRichard Henderson     return advance_pc(dc);
3836d3825800SRichard Henderson }
3837d3825800SRichard Henderson 
38380faef01bSRichard Henderson /*
38390faef01bSRichard Henderson  * TODO: Need a feature bit for sparcv8.
38400faef01bSRichard Henderson  * In the meantime, treat all 32-bit cpus like sparcv7.
38410faef01bSRichard Henderson  */
38425458fd31SRichard Henderson TRANS(NOP_v7, 32, trans_NOP, a)
38435458fd31SRichard Henderson TRANS(NOP_v9, 64, trans_NOP, a)
38440faef01bSRichard Henderson 
3845428881deSRichard Henderson static bool do_arith_int(DisasContext *dc, arg_r_r_ri_cc *a, int cc_op,
3846428881deSRichard Henderson                          void (*func)(TCGv, TCGv, TCGv),
3847428881deSRichard Henderson                          void (*funci)(TCGv, TCGv, target_long))
3848428881deSRichard Henderson {
3849428881deSRichard Henderson     TCGv dst, src1;
3850428881deSRichard Henderson 
3851428881deSRichard Henderson     /* For simplicity, we under-decoded the rs2 form. */
3852428881deSRichard Henderson     if (!a->imm && a->rs2_or_imm & ~0x1f) {
3853428881deSRichard Henderson         return false;
3854428881deSRichard Henderson     }
3855428881deSRichard Henderson 
3856428881deSRichard Henderson     if (a->cc) {
3857428881deSRichard Henderson         dst = cpu_cc_dst;
3858428881deSRichard Henderson     } else {
3859428881deSRichard Henderson         dst = gen_dest_gpr(dc, a->rd);
3860428881deSRichard Henderson     }
3861428881deSRichard Henderson     src1 = gen_load_gpr(dc, a->rs1);
3862428881deSRichard Henderson 
3863428881deSRichard Henderson     if (a->imm || a->rs2_or_imm == 0) {
3864428881deSRichard Henderson         if (funci) {
3865428881deSRichard Henderson             funci(dst, src1, a->rs2_or_imm);
3866428881deSRichard Henderson         } else {
3867428881deSRichard Henderson             func(dst, src1, tcg_constant_tl(a->rs2_or_imm));
3868428881deSRichard Henderson         }
3869428881deSRichard Henderson     } else {
3870428881deSRichard Henderson         func(dst, src1, cpu_regs[a->rs2_or_imm]);
3871428881deSRichard Henderson     }
3872428881deSRichard Henderson     gen_store_gpr(dc, a->rd, dst);
3873428881deSRichard Henderson 
3874428881deSRichard Henderson     if (a->cc) {
3875428881deSRichard Henderson         tcg_gen_movi_i32(cpu_cc_op, cc_op);
3876428881deSRichard Henderson         dc->cc_op = cc_op;
3877428881deSRichard Henderson     }
3878428881deSRichard Henderson     return advance_pc(dc);
3879428881deSRichard Henderson }
3880428881deSRichard Henderson 
3881428881deSRichard Henderson static bool do_arith(DisasContext *dc, arg_r_r_ri_cc *a, int cc_op,
3882428881deSRichard Henderson                      void (*func)(TCGv, TCGv, TCGv),
3883428881deSRichard Henderson                      void (*funci)(TCGv, TCGv, target_long),
3884428881deSRichard Henderson                      void (*func_cc)(TCGv, TCGv, TCGv))
3885428881deSRichard Henderson {
3886428881deSRichard Henderson     if (a->cc) {
388722188d7dSRichard Henderson         assert(cc_op >= 0);
3888428881deSRichard Henderson         return do_arith_int(dc, a, cc_op, func_cc, NULL);
3889428881deSRichard Henderson     }
3890428881deSRichard Henderson     return do_arith_int(dc, a, cc_op, func, funci);
3891428881deSRichard Henderson }
3892428881deSRichard Henderson 
3893428881deSRichard Henderson static bool do_logic(DisasContext *dc, arg_r_r_ri_cc *a,
3894428881deSRichard Henderson                      void (*func)(TCGv, TCGv, TCGv),
3895428881deSRichard Henderson                      void (*funci)(TCGv, TCGv, target_long))
3896428881deSRichard Henderson {
3897428881deSRichard Henderson     return do_arith_int(dc, a, CC_OP_LOGIC, func, funci);
3898428881deSRichard Henderson }
3899428881deSRichard Henderson 
3900428881deSRichard Henderson TRANS(ADD, ALL, do_arith, a, CC_OP_ADD,
3901428881deSRichard Henderson       tcg_gen_add_tl, tcg_gen_addi_tl, gen_op_add_cc)
3902428881deSRichard Henderson TRANS(SUB, ALL, do_arith, a, CC_OP_SUB,
3903428881deSRichard Henderson       tcg_gen_sub_tl, tcg_gen_subi_tl, gen_op_sub_cc)
3904428881deSRichard Henderson 
3905a9aba13dSRichard Henderson TRANS(TADDcc, ALL, do_arith, a, CC_OP_TADD, NULL, NULL, gen_op_add_cc)
3906a9aba13dSRichard Henderson TRANS(TSUBcc, ALL, do_arith, a, CC_OP_TSUB, NULL, NULL, gen_op_sub_cc)
3907a9aba13dSRichard Henderson TRANS(TADDccTV, ALL, do_arith, a, CC_OP_TADDTV, NULL, NULL, gen_op_taddcctv)
3908a9aba13dSRichard Henderson TRANS(TSUBccTV, ALL, do_arith, a, CC_OP_TSUBTV, NULL, NULL, gen_op_tsubcctv)
3909a9aba13dSRichard Henderson 
3910428881deSRichard Henderson TRANS(AND, ALL, do_logic, a, tcg_gen_and_tl, tcg_gen_andi_tl)
3911428881deSRichard Henderson TRANS(XOR, ALL, do_logic, a, tcg_gen_xor_tl, tcg_gen_xori_tl)
3912428881deSRichard Henderson TRANS(ANDN, ALL, do_logic, a, tcg_gen_andc_tl, NULL)
3913428881deSRichard Henderson TRANS(ORN, ALL, do_logic, a, tcg_gen_orc_tl, NULL)
3914428881deSRichard Henderson TRANS(XORN, ALL, do_logic, a, tcg_gen_eqv_tl, NULL)
3915428881deSRichard Henderson 
391622188d7dSRichard Henderson TRANS(MULX, 64, do_arith, a, -1, tcg_gen_mul_tl, tcg_gen_muli_tl, NULL)
3917b5372650SRichard Henderson TRANS(UMUL, MUL, do_logic, a, gen_op_umul, NULL)
3918b5372650SRichard Henderson TRANS(SMUL, MUL, do_logic, a, gen_op_smul, NULL)
391922188d7dSRichard Henderson 
39204ee85ea9SRichard Henderson TRANS(UDIVX, 64, do_arith, a, -1, gen_op_udivx, NULL, NULL)
39214ee85ea9SRichard Henderson TRANS(SDIVX, 64, do_arith, a, -1, gen_op_sdivx, NULL, NULL)
3922c2636853SRichard Henderson TRANS(UDIV, DIV, do_arith, a, CC_OP_DIV, gen_op_udiv, NULL, gen_op_udivcc)
3923c2636853SRichard Henderson TRANS(SDIV, DIV, do_arith, a, CC_OP_DIV, gen_op_sdiv, NULL, gen_op_sdivcc)
39244ee85ea9SRichard Henderson 
39259c6ec5bcSRichard Henderson /* TODO: Should have feature bit -- comes in with UltraSparc T2. */
39269c6ec5bcSRichard Henderson TRANS(POPC, 64, do_arith, a, -1, gen_op_popc, NULL, NULL)
39279c6ec5bcSRichard Henderson 
3928428881deSRichard Henderson static bool trans_OR(DisasContext *dc, arg_r_r_ri_cc *a)
3929428881deSRichard Henderson {
3930428881deSRichard Henderson     /* OR with %g0 is the canonical alias for MOV. */
3931428881deSRichard Henderson     if (!a->cc && a->rs1 == 0) {
3932428881deSRichard Henderson         if (a->imm || a->rs2_or_imm == 0) {
3933428881deSRichard Henderson             gen_store_gpr(dc, a->rd, tcg_constant_tl(a->rs2_or_imm));
3934428881deSRichard Henderson         } else if (a->rs2_or_imm & ~0x1f) {
3935428881deSRichard Henderson             /* For simplicity, we under-decoded the rs2 form. */
3936428881deSRichard Henderson             return false;
3937428881deSRichard Henderson         } else {
3938428881deSRichard Henderson             gen_store_gpr(dc, a->rd, cpu_regs[a->rs2_or_imm]);
3939428881deSRichard Henderson         }
3940428881deSRichard Henderson         return advance_pc(dc);
3941428881deSRichard Henderson     }
3942428881deSRichard Henderson     return do_logic(dc, a, tcg_gen_or_tl, tcg_gen_ori_tl);
3943428881deSRichard Henderson }
3944428881deSRichard Henderson 
3945420a187dSRichard Henderson static bool trans_ADDC(DisasContext *dc, arg_r_r_ri_cc *a)
3946420a187dSRichard Henderson {
3947420a187dSRichard Henderson     switch (dc->cc_op) {
3948420a187dSRichard Henderson     case CC_OP_DIV:
3949420a187dSRichard Henderson     case CC_OP_LOGIC:
3950420a187dSRichard Henderson         /* Carry is known to be zero.  Fall back to plain ADD.  */
3951420a187dSRichard Henderson         return do_arith(dc, a, CC_OP_ADD,
3952420a187dSRichard Henderson                         tcg_gen_add_tl, tcg_gen_addi_tl, gen_op_add_cc);
3953420a187dSRichard Henderson     case CC_OP_ADD:
3954420a187dSRichard Henderson     case CC_OP_TADD:
3955420a187dSRichard Henderson     case CC_OP_TADDTV:
3956420a187dSRichard Henderson         return do_arith(dc, a, CC_OP_ADDX,
3957420a187dSRichard Henderson                         gen_op_addc_add, NULL, gen_op_addccc_add);
3958420a187dSRichard Henderson     case CC_OP_SUB:
3959420a187dSRichard Henderson     case CC_OP_TSUB:
3960420a187dSRichard Henderson     case CC_OP_TSUBTV:
3961420a187dSRichard Henderson         return do_arith(dc, a, CC_OP_ADDX,
3962420a187dSRichard Henderson                         gen_op_addc_sub, NULL, gen_op_addccc_sub);
3963420a187dSRichard Henderson     default:
3964420a187dSRichard Henderson         return do_arith(dc, a, CC_OP_ADDX,
3965420a187dSRichard Henderson                         gen_op_addc_generic, NULL, gen_op_addccc_generic);
3966420a187dSRichard Henderson     }
3967420a187dSRichard Henderson }
3968420a187dSRichard Henderson 
3969dfebb950SRichard Henderson static bool trans_SUBC(DisasContext *dc, arg_r_r_ri_cc *a)
3970dfebb950SRichard Henderson {
3971dfebb950SRichard Henderson     switch (dc->cc_op) {
3972dfebb950SRichard Henderson     case CC_OP_DIV:
3973dfebb950SRichard Henderson     case CC_OP_LOGIC:
3974dfebb950SRichard Henderson         /* Carry is known to be zero.  Fall back to plain SUB.  */
3975dfebb950SRichard Henderson         return do_arith(dc, a, CC_OP_SUB,
3976dfebb950SRichard Henderson                         tcg_gen_sub_tl, tcg_gen_subi_tl, gen_op_sub_cc);
3977dfebb950SRichard Henderson     case CC_OP_ADD:
3978dfebb950SRichard Henderson     case CC_OP_TADD:
3979dfebb950SRichard Henderson     case CC_OP_TADDTV:
3980dfebb950SRichard Henderson         return do_arith(dc, a, CC_OP_SUBX,
3981dfebb950SRichard Henderson                         gen_op_subc_add, NULL, gen_op_subccc_add);
3982dfebb950SRichard Henderson     case CC_OP_SUB:
3983dfebb950SRichard Henderson     case CC_OP_TSUB:
3984dfebb950SRichard Henderson     case CC_OP_TSUBTV:
3985dfebb950SRichard Henderson         return do_arith(dc, a, CC_OP_SUBX,
3986dfebb950SRichard Henderson                         gen_op_subc_sub, NULL, gen_op_subccc_sub);
3987dfebb950SRichard Henderson     default:
3988dfebb950SRichard Henderson         return do_arith(dc, a, CC_OP_SUBX,
3989dfebb950SRichard Henderson                         gen_op_subc_generic, NULL, gen_op_subccc_generic);
3990dfebb950SRichard Henderson     }
3991dfebb950SRichard Henderson }
3992dfebb950SRichard Henderson 
3993a9aba13dSRichard Henderson static bool trans_MULScc(DisasContext *dc, arg_r_r_ri_cc *a)
3994a9aba13dSRichard Henderson {
3995a9aba13dSRichard Henderson     update_psr(dc);
3996a9aba13dSRichard Henderson     return do_arith(dc, a, CC_OP_ADD, NULL, NULL, gen_op_mulscc);
3997a9aba13dSRichard Henderson }
3998a9aba13dSRichard Henderson 
3999b88ce6f2SRichard Henderson static bool gen_edge(DisasContext *dc, arg_r_r_r *a,
4000b88ce6f2SRichard Henderson                      int width, bool cc, bool left)
4001b88ce6f2SRichard Henderson {
4002b88ce6f2SRichard Henderson     TCGv dst, s1, s2, lo1, lo2;
4003b88ce6f2SRichard Henderson     uint64_t amask, tabl, tabr;
4004b88ce6f2SRichard Henderson     int shift, imask, omask;
4005b88ce6f2SRichard Henderson 
4006b88ce6f2SRichard Henderson     dst = gen_dest_gpr(dc, a->rd);
4007b88ce6f2SRichard Henderson     s1 = gen_load_gpr(dc, a->rs1);
4008b88ce6f2SRichard Henderson     s2 = gen_load_gpr(dc, a->rs2);
4009b88ce6f2SRichard Henderson 
4010b88ce6f2SRichard Henderson     if (cc) {
4011b88ce6f2SRichard Henderson         tcg_gen_mov_tl(cpu_cc_src, s1);
4012b88ce6f2SRichard Henderson         tcg_gen_mov_tl(cpu_cc_src2, s2);
4013b88ce6f2SRichard Henderson         tcg_gen_sub_tl(cpu_cc_dst, s1, s2);
4014b88ce6f2SRichard Henderson         tcg_gen_movi_i32(cpu_cc_op, CC_OP_SUB);
4015b88ce6f2SRichard Henderson         dc->cc_op = CC_OP_SUB;
4016b88ce6f2SRichard Henderson     }
4017b88ce6f2SRichard Henderson 
4018b88ce6f2SRichard Henderson     /*
4019b88ce6f2SRichard Henderson      * Theory of operation: there are two tables, left and right (not to
4020b88ce6f2SRichard Henderson      * be confused with the left and right versions of the opcode).  These
4021b88ce6f2SRichard Henderson      * are indexed by the low 3 bits of the inputs.  To make things "easy",
4022b88ce6f2SRichard Henderson      * these tables are loaded into two constants, TABL and TABR below.
4023b88ce6f2SRichard Henderson      * The operation index = (input & imask) << shift calculates the index
4024b88ce6f2SRichard Henderson      * into the constant, while val = (table >> index) & omask calculates
4025b88ce6f2SRichard Henderson      * the value we're looking for.
4026b88ce6f2SRichard Henderson      */
4027b88ce6f2SRichard Henderson     switch (width) {
4028b88ce6f2SRichard Henderson     case 8:
4029b88ce6f2SRichard Henderson         imask = 0x7;
4030b88ce6f2SRichard Henderson         shift = 3;
4031b88ce6f2SRichard Henderson         omask = 0xff;
4032b88ce6f2SRichard Henderson         if (left) {
4033b88ce6f2SRichard Henderson             tabl = 0x80c0e0f0f8fcfeffULL;
4034b88ce6f2SRichard Henderson             tabr = 0xff7f3f1f0f070301ULL;
4035b88ce6f2SRichard Henderson         } else {
4036b88ce6f2SRichard Henderson             tabl = 0x0103070f1f3f7fffULL;
4037b88ce6f2SRichard Henderson             tabr = 0xfffefcf8f0e0c080ULL;
4038b88ce6f2SRichard Henderson         }
4039b88ce6f2SRichard Henderson         break;
4040b88ce6f2SRichard Henderson     case 16:
4041b88ce6f2SRichard Henderson         imask = 0x6;
4042b88ce6f2SRichard Henderson         shift = 1;
4043b88ce6f2SRichard Henderson         omask = 0xf;
4044b88ce6f2SRichard Henderson         if (left) {
4045b88ce6f2SRichard Henderson             tabl = 0x8cef;
4046b88ce6f2SRichard Henderson             tabr = 0xf731;
4047b88ce6f2SRichard Henderson         } else {
4048b88ce6f2SRichard Henderson             tabl = 0x137f;
4049b88ce6f2SRichard Henderson             tabr = 0xfec8;
4050b88ce6f2SRichard Henderson         }
4051b88ce6f2SRichard Henderson         break;
4052b88ce6f2SRichard Henderson     case 32:
4053b88ce6f2SRichard Henderson         imask = 0x4;
4054b88ce6f2SRichard Henderson         shift = 0;
4055b88ce6f2SRichard Henderson         omask = 0x3;
4056b88ce6f2SRichard Henderson         if (left) {
4057b88ce6f2SRichard Henderson             tabl = (2 << 2) | 3;
4058b88ce6f2SRichard Henderson             tabr = (3 << 2) | 1;
4059b88ce6f2SRichard Henderson         } else {
4060b88ce6f2SRichard Henderson             tabl = (1 << 2) | 3;
4061b88ce6f2SRichard Henderson             tabr = (3 << 2) | 2;
4062b88ce6f2SRichard Henderson         }
4063b88ce6f2SRichard Henderson         break;
4064b88ce6f2SRichard Henderson     default:
4065b88ce6f2SRichard Henderson         abort();
4066b88ce6f2SRichard Henderson     }
4067b88ce6f2SRichard Henderson 
4068b88ce6f2SRichard Henderson     lo1 = tcg_temp_new();
4069b88ce6f2SRichard Henderson     lo2 = tcg_temp_new();
4070b88ce6f2SRichard Henderson     tcg_gen_andi_tl(lo1, s1, imask);
4071b88ce6f2SRichard Henderson     tcg_gen_andi_tl(lo2, s2, imask);
4072b88ce6f2SRichard Henderson     tcg_gen_shli_tl(lo1, lo1, shift);
4073b88ce6f2SRichard Henderson     tcg_gen_shli_tl(lo2, lo2, shift);
4074b88ce6f2SRichard Henderson 
4075b88ce6f2SRichard Henderson     tcg_gen_shr_tl(lo1, tcg_constant_tl(tabl), lo1);
4076b88ce6f2SRichard Henderson     tcg_gen_shr_tl(lo2, tcg_constant_tl(tabr), lo2);
4077b88ce6f2SRichard Henderson     tcg_gen_andi_tl(lo1, lo1, omask);
4078b88ce6f2SRichard Henderson     tcg_gen_andi_tl(lo2, lo2, omask);
4079b88ce6f2SRichard Henderson 
4080b88ce6f2SRichard Henderson     amask = address_mask_i(dc, -8);
4081b88ce6f2SRichard Henderson     tcg_gen_andi_tl(s1, s1, amask);
4082b88ce6f2SRichard Henderson     tcg_gen_andi_tl(s2, s2, amask);
4083b88ce6f2SRichard Henderson 
4084b88ce6f2SRichard Henderson     /* Compute dst = (s1 == s2 ? lo1 : lo1 & lo2). */
4085b88ce6f2SRichard Henderson     tcg_gen_and_tl(lo2, lo2, lo1);
4086b88ce6f2SRichard Henderson     tcg_gen_movcond_tl(TCG_COND_EQ, dst, s1, s2, lo1, lo2);
4087b88ce6f2SRichard Henderson 
4088b88ce6f2SRichard Henderson     gen_store_gpr(dc, a->rd, dst);
4089b88ce6f2SRichard Henderson     return advance_pc(dc);
4090b88ce6f2SRichard Henderson }
4091b88ce6f2SRichard Henderson 
4092b88ce6f2SRichard Henderson TRANS(EDGE8cc, VIS1, gen_edge, a, 8, 1, 0)
4093b88ce6f2SRichard Henderson TRANS(EDGE8Lcc, VIS1, gen_edge, a, 8, 1, 1)
4094b88ce6f2SRichard Henderson TRANS(EDGE16cc, VIS1, gen_edge, a, 16, 1, 0)
4095b88ce6f2SRichard Henderson TRANS(EDGE16Lcc, VIS1, gen_edge, a, 16, 1, 1)
4096b88ce6f2SRichard Henderson TRANS(EDGE32cc, VIS1, gen_edge, a, 32, 1, 0)
4097b88ce6f2SRichard Henderson TRANS(EDGE32Lcc, VIS1, gen_edge, a, 32, 1, 1)
4098b88ce6f2SRichard Henderson 
4099b88ce6f2SRichard Henderson TRANS(EDGE8N, VIS2, gen_edge, a, 8, 0, 0)
4100b88ce6f2SRichard Henderson TRANS(EDGE8LN, VIS2, gen_edge, a, 8, 0, 1)
4101b88ce6f2SRichard Henderson TRANS(EDGE16N, VIS2, gen_edge, a, 16, 0, 0)
4102b88ce6f2SRichard Henderson TRANS(EDGE16LN, VIS2, gen_edge, a, 16, 0, 1)
4103b88ce6f2SRichard Henderson TRANS(EDGE32N, VIS2, gen_edge, a, 32, 0, 0)
4104b88ce6f2SRichard Henderson TRANS(EDGE32LN, VIS2, gen_edge, a, 32, 0, 1)
4105b88ce6f2SRichard Henderson 
410645bfed3bSRichard Henderson static bool do_rrr(DisasContext *dc, arg_r_r_r *a,
410745bfed3bSRichard Henderson                    void (*func)(TCGv, TCGv, TCGv))
410845bfed3bSRichard Henderson {
410945bfed3bSRichard Henderson     TCGv dst = gen_dest_gpr(dc, a->rd);
411045bfed3bSRichard Henderson     TCGv src1 = gen_load_gpr(dc, a->rs1);
411145bfed3bSRichard Henderson     TCGv src2 = gen_load_gpr(dc, a->rs2);
411245bfed3bSRichard Henderson 
411345bfed3bSRichard Henderson     func(dst, src1, src2);
411445bfed3bSRichard Henderson     gen_store_gpr(dc, a->rd, dst);
411545bfed3bSRichard Henderson     return advance_pc(dc);
411645bfed3bSRichard Henderson }
411745bfed3bSRichard Henderson 
411845bfed3bSRichard Henderson TRANS(ARRAY8, VIS1, do_rrr, a, gen_helper_array8)
411945bfed3bSRichard Henderson TRANS(ARRAY16, VIS1, do_rrr, a, gen_op_array16)
412045bfed3bSRichard Henderson TRANS(ARRAY32, VIS1, do_rrr, a, gen_op_array32)
412145bfed3bSRichard Henderson 
41229e20ca94SRichard Henderson static void gen_op_alignaddr(TCGv dst, TCGv s1, TCGv s2)
41239e20ca94SRichard Henderson {
41249e20ca94SRichard Henderson #ifdef TARGET_SPARC64
41259e20ca94SRichard Henderson     TCGv tmp = tcg_temp_new();
41269e20ca94SRichard Henderson 
41279e20ca94SRichard Henderson     tcg_gen_add_tl(tmp, s1, s2);
41289e20ca94SRichard Henderson     tcg_gen_andi_tl(dst, tmp, -8);
41299e20ca94SRichard Henderson     tcg_gen_deposit_tl(cpu_gsr, cpu_gsr, tmp, 0, 3);
41309e20ca94SRichard Henderson #else
41319e20ca94SRichard Henderson     g_assert_not_reached();
41329e20ca94SRichard Henderson #endif
41339e20ca94SRichard Henderson }
41349e20ca94SRichard Henderson 
41359e20ca94SRichard Henderson static void gen_op_alignaddrl(TCGv dst, TCGv s1, TCGv s2)
41369e20ca94SRichard Henderson {
41379e20ca94SRichard Henderson #ifdef TARGET_SPARC64
41389e20ca94SRichard Henderson     TCGv tmp = tcg_temp_new();
41399e20ca94SRichard Henderson 
41409e20ca94SRichard Henderson     tcg_gen_add_tl(tmp, s1, s2);
41419e20ca94SRichard Henderson     tcg_gen_andi_tl(dst, tmp, -8);
41429e20ca94SRichard Henderson     tcg_gen_neg_tl(tmp, tmp);
41439e20ca94SRichard Henderson     tcg_gen_deposit_tl(cpu_gsr, cpu_gsr, tmp, 0, 3);
41449e20ca94SRichard Henderson #else
41459e20ca94SRichard Henderson     g_assert_not_reached();
41469e20ca94SRichard Henderson #endif
41479e20ca94SRichard Henderson }
41489e20ca94SRichard Henderson 
41499e20ca94SRichard Henderson TRANS(ALIGNADDR, VIS1, do_rrr, a, gen_op_alignaddr)
41509e20ca94SRichard Henderson TRANS(ALIGNADDRL, VIS1, do_rrr, a, gen_op_alignaddrl)
41519e20ca94SRichard Henderson 
415239ca3490SRichard Henderson static void gen_op_bmask(TCGv dst, TCGv s1, TCGv s2)
415339ca3490SRichard Henderson {
415439ca3490SRichard Henderson #ifdef TARGET_SPARC64
415539ca3490SRichard Henderson     tcg_gen_add_tl(dst, s1, s2);
415639ca3490SRichard Henderson     tcg_gen_deposit_tl(cpu_gsr, cpu_gsr, dst, 32, 32);
415739ca3490SRichard Henderson #else
415839ca3490SRichard Henderson     g_assert_not_reached();
415939ca3490SRichard Henderson #endif
416039ca3490SRichard Henderson }
416139ca3490SRichard Henderson 
416239ca3490SRichard Henderson TRANS(BMASK, VIS2, do_rrr, a, gen_op_bmask)
416339ca3490SRichard Henderson 
41645fc546eeSRichard Henderson static bool do_shift_r(DisasContext *dc, arg_shiftr *a, bool l, bool u)
41655fc546eeSRichard Henderson {
41665fc546eeSRichard Henderson     TCGv dst, src1, src2;
41675fc546eeSRichard Henderson 
41685fc546eeSRichard Henderson     /* Reject 64-bit shifts for sparc32. */
41695fc546eeSRichard Henderson     if (avail_32(dc) && a->x) {
41705fc546eeSRichard Henderson         return false;
41715fc546eeSRichard Henderson     }
41725fc546eeSRichard Henderson 
41735fc546eeSRichard Henderson     src2 = tcg_temp_new();
41745fc546eeSRichard Henderson     tcg_gen_andi_tl(src2, gen_load_gpr(dc, a->rs2), a->x ? 63 : 31);
41755fc546eeSRichard Henderson     src1 = gen_load_gpr(dc, a->rs1);
41765fc546eeSRichard Henderson     dst = gen_dest_gpr(dc, a->rd);
41775fc546eeSRichard Henderson 
41785fc546eeSRichard Henderson     if (l) {
41795fc546eeSRichard Henderson         tcg_gen_shl_tl(dst, src1, src2);
41805fc546eeSRichard Henderson         if (!a->x) {
41815fc546eeSRichard Henderson             tcg_gen_ext32u_tl(dst, dst);
41825fc546eeSRichard Henderson         }
41835fc546eeSRichard Henderson     } else if (u) {
41845fc546eeSRichard Henderson         if (!a->x) {
41855fc546eeSRichard Henderson             tcg_gen_ext32u_tl(dst, src1);
41865fc546eeSRichard Henderson             src1 = dst;
41875fc546eeSRichard Henderson         }
41885fc546eeSRichard Henderson         tcg_gen_shr_tl(dst, src1, src2);
41895fc546eeSRichard Henderson     } else {
41905fc546eeSRichard Henderson         if (!a->x) {
41915fc546eeSRichard Henderson             tcg_gen_ext32s_tl(dst, src1);
41925fc546eeSRichard Henderson             src1 = dst;
41935fc546eeSRichard Henderson         }
41945fc546eeSRichard Henderson         tcg_gen_sar_tl(dst, src1, src2);
41955fc546eeSRichard Henderson     }
41965fc546eeSRichard Henderson     gen_store_gpr(dc, a->rd, dst);
41975fc546eeSRichard Henderson     return advance_pc(dc);
41985fc546eeSRichard Henderson }
41995fc546eeSRichard Henderson 
42005fc546eeSRichard Henderson TRANS(SLL_r, ALL, do_shift_r, a, true, true)
42015fc546eeSRichard Henderson TRANS(SRL_r, ALL, do_shift_r, a, false, true)
42025fc546eeSRichard Henderson TRANS(SRA_r, ALL, do_shift_r, a, false, false)
42035fc546eeSRichard Henderson 
42045fc546eeSRichard Henderson static bool do_shift_i(DisasContext *dc, arg_shifti *a, bool l, bool u)
42055fc546eeSRichard Henderson {
42065fc546eeSRichard Henderson     TCGv dst, src1;
42075fc546eeSRichard Henderson 
42085fc546eeSRichard Henderson     /* Reject 64-bit shifts for sparc32. */
42095fc546eeSRichard Henderson     if (avail_32(dc) && (a->x || a->i >= 32)) {
42105fc546eeSRichard Henderson         return false;
42115fc546eeSRichard Henderson     }
42125fc546eeSRichard Henderson 
42135fc546eeSRichard Henderson     src1 = gen_load_gpr(dc, a->rs1);
42145fc546eeSRichard Henderson     dst = gen_dest_gpr(dc, a->rd);
42155fc546eeSRichard Henderson 
42165fc546eeSRichard Henderson     if (avail_32(dc) || a->x) {
42175fc546eeSRichard Henderson         if (l) {
42185fc546eeSRichard Henderson             tcg_gen_shli_tl(dst, src1, a->i);
42195fc546eeSRichard Henderson         } else if (u) {
42205fc546eeSRichard Henderson             tcg_gen_shri_tl(dst, src1, a->i);
42215fc546eeSRichard Henderson         } else {
42225fc546eeSRichard Henderson             tcg_gen_sari_tl(dst, src1, a->i);
42235fc546eeSRichard Henderson         }
42245fc546eeSRichard Henderson     } else {
42255fc546eeSRichard Henderson         if (l) {
42265fc546eeSRichard Henderson             tcg_gen_deposit_z_tl(dst, src1, a->i, 32 - a->i);
42275fc546eeSRichard Henderson         } else if (u) {
42285fc546eeSRichard Henderson             tcg_gen_extract_tl(dst, src1, a->i, 32 - a->i);
42295fc546eeSRichard Henderson         } else {
42305fc546eeSRichard Henderson             tcg_gen_sextract_tl(dst, src1, a->i, 32 - a->i);
42315fc546eeSRichard Henderson         }
42325fc546eeSRichard Henderson     }
42335fc546eeSRichard Henderson     gen_store_gpr(dc, a->rd, dst);
42345fc546eeSRichard Henderson     return advance_pc(dc);
42355fc546eeSRichard Henderson }
42365fc546eeSRichard Henderson 
42375fc546eeSRichard Henderson TRANS(SLL_i, ALL, do_shift_i, a, true, true)
42385fc546eeSRichard Henderson TRANS(SRL_i, ALL, do_shift_i, a, false, true)
42395fc546eeSRichard Henderson TRANS(SRA_i, ALL, do_shift_i, a, false, false)
42405fc546eeSRichard Henderson 
4241fb4ed7aaSRichard Henderson static TCGv gen_rs2_or_imm(DisasContext *dc, bool imm, int rs2_or_imm)
4242fb4ed7aaSRichard Henderson {
4243fb4ed7aaSRichard Henderson     /* For simplicity, we under-decoded the rs2 form. */
4244fb4ed7aaSRichard Henderson     if (!imm && rs2_or_imm & ~0x1f) {
4245fb4ed7aaSRichard Henderson         return NULL;
4246fb4ed7aaSRichard Henderson     }
4247fb4ed7aaSRichard Henderson     if (imm || rs2_or_imm == 0) {
4248fb4ed7aaSRichard Henderson         return tcg_constant_tl(rs2_or_imm);
4249fb4ed7aaSRichard Henderson     } else {
4250fb4ed7aaSRichard Henderson         return cpu_regs[rs2_or_imm];
4251fb4ed7aaSRichard Henderson     }
4252fb4ed7aaSRichard Henderson }
4253fb4ed7aaSRichard Henderson 
4254fb4ed7aaSRichard Henderson static bool do_mov_cond(DisasContext *dc, DisasCompare *cmp, int rd, TCGv src2)
4255fb4ed7aaSRichard Henderson {
4256fb4ed7aaSRichard Henderson     TCGv dst = gen_load_gpr(dc, rd);
4257fb4ed7aaSRichard Henderson 
4258fb4ed7aaSRichard Henderson     tcg_gen_movcond_tl(cmp->cond, dst, cmp->c1, cmp->c2, src2, dst);
4259fb4ed7aaSRichard Henderson     gen_store_gpr(dc, rd, dst);
4260fb4ed7aaSRichard Henderson     return advance_pc(dc);
4261fb4ed7aaSRichard Henderson }
4262fb4ed7aaSRichard Henderson 
4263fb4ed7aaSRichard Henderson static bool trans_MOVcc(DisasContext *dc, arg_MOVcc *a)
4264fb4ed7aaSRichard Henderson {
4265fb4ed7aaSRichard Henderson     TCGv src2 = gen_rs2_or_imm(dc, a->imm, a->rs2_or_imm);
4266fb4ed7aaSRichard Henderson     DisasCompare cmp;
4267fb4ed7aaSRichard Henderson 
4268fb4ed7aaSRichard Henderson     if (src2 == NULL) {
4269fb4ed7aaSRichard Henderson         return false;
4270fb4ed7aaSRichard Henderson     }
4271fb4ed7aaSRichard Henderson     gen_compare(&cmp, a->cc, a->cond, dc);
4272fb4ed7aaSRichard Henderson     return do_mov_cond(dc, &cmp, a->rd, src2);
4273fb4ed7aaSRichard Henderson }
4274fb4ed7aaSRichard Henderson 
4275fb4ed7aaSRichard Henderson static bool trans_MOVfcc(DisasContext *dc, arg_MOVfcc *a)
4276fb4ed7aaSRichard Henderson {
4277fb4ed7aaSRichard Henderson     TCGv src2 = gen_rs2_or_imm(dc, a->imm, a->rs2_or_imm);
4278fb4ed7aaSRichard Henderson     DisasCompare cmp;
4279fb4ed7aaSRichard Henderson 
4280fb4ed7aaSRichard Henderson     if (src2 == NULL) {
4281fb4ed7aaSRichard Henderson         return false;
4282fb4ed7aaSRichard Henderson     }
4283fb4ed7aaSRichard Henderson     gen_fcompare(&cmp, a->cc, a->cond);
4284fb4ed7aaSRichard Henderson     return do_mov_cond(dc, &cmp, a->rd, src2);
4285fb4ed7aaSRichard Henderson }
4286fb4ed7aaSRichard Henderson 
4287fb4ed7aaSRichard Henderson static bool trans_MOVR(DisasContext *dc, arg_MOVR *a)
4288fb4ed7aaSRichard Henderson {
4289fb4ed7aaSRichard Henderson     TCGv src2 = gen_rs2_or_imm(dc, a->imm, a->rs2_or_imm);
4290fb4ed7aaSRichard Henderson     DisasCompare cmp;
4291fb4ed7aaSRichard Henderson 
4292fb4ed7aaSRichard Henderson     if (src2 == NULL) {
4293fb4ed7aaSRichard Henderson         return false;
4294fb4ed7aaSRichard Henderson     }
4295fb4ed7aaSRichard Henderson     gen_compare_reg(&cmp, a->cond, gen_load_gpr(dc, a->rs1));
4296fb4ed7aaSRichard Henderson     return do_mov_cond(dc, &cmp, a->rd, src2);
4297fb4ed7aaSRichard Henderson }
4298fb4ed7aaSRichard Henderson 
429986b82fe0SRichard Henderson static bool do_add_special(DisasContext *dc, arg_r_r_ri *a,
430086b82fe0SRichard Henderson                            bool (*func)(DisasContext *dc, int rd, TCGv src))
430186b82fe0SRichard Henderson {
430286b82fe0SRichard Henderson     TCGv src1, sum;
430386b82fe0SRichard Henderson 
430486b82fe0SRichard Henderson     /* For simplicity, we under-decoded the rs2 form. */
430586b82fe0SRichard Henderson     if (!a->imm && a->rs2_or_imm & ~0x1f) {
430686b82fe0SRichard Henderson         return false;
430786b82fe0SRichard Henderson     }
430886b82fe0SRichard Henderson 
430986b82fe0SRichard Henderson     /*
431086b82fe0SRichard Henderson      * Always load the sum into a new temporary.
431186b82fe0SRichard Henderson      * This is required to capture the value across a window change,
431286b82fe0SRichard Henderson      * e.g. SAVE and RESTORE, and may be optimized away otherwise.
431386b82fe0SRichard Henderson      */
431486b82fe0SRichard Henderson     sum = tcg_temp_new();
431586b82fe0SRichard Henderson     src1 = gen_load_gpr(dc, a->rs1);
431686b82fe0SRichard Henderson     if (a->imm || a->rs2_or_imm == 0) {
431786b82fe0SRichard Henderson         tcg_gen_addi_tl(sum, src1, a->rs2_or_imm);
431886b82fe0SRichard Henderson     } else {
431986b82fe0SRichard Henderson         tcg_gen_add_tl(sum, src1, cpu_regs[a->rs2_or_imm]);
432086b82fe0SRichard Henderson     }
432186b82fe0SRichard Henderson     return func(dc, a->rd, sum);
432286b82fe0SRichard Henderson }
432386b82fe0SRichard Henderson 
432486b82fe0SRichard Henderson static bool do_jmpl(DisasContext *dc, int rd, TCGv src)
432586b82fe0SRichard Henderson {
432686b82fe0SRichard Henderson     /*
432786b82fe0SRichard Henderson      * Preserve pc across advance, so that we can delay
432886b82fe0SRichard Henderson      * the writeback to rd until after src is consumed.
432986b82fe0SRichard Henderson      */
433086b82fe0SRichard Henderson     target_ulong cur_pc = dc->pc;
433186b82fe0SRichard Henderson 
433286b82fe0SRichard Henderson     gen_check_align(dc, src, 3);
433386b82fe0SRichard Henderson 
433486b82fe0SRichard Henderson     gen_mov_pc_npc(dc);
433586b82fe0SRichard Henderson     tcg_gen_mov_tl(cpu_npc, src);
433686b82fe0SRichard Henderson     gen_address_mask(dc, cpu_npc);
433786b82fe0SRichard Henderson     gen_store_gpr(dc, rd, tcg_constant_tl(cur_pc));
433886b82fe0SRichard Henderson 
433986b82fe0SRichard Henderson     dc->npc = DYNAMIC_PC_LOOKUP;
434086b82fe0SRichard Henderson     return true;
434186b82fe0SRichard Henderson }
434286b82fe0SRichard Henderson 
434386b82fe0SRichard Henderson TRANS(JMPL, ALL, do_add_special, a, do_jmpl)
434486b82fe0SRichard Henderson 
434586b82fe0SRichard Henderson static bool do_rett(DisasContext *dc, int rd, TCGv src)
434686b82fe0SRichard Henderson {
434786b82fe0SRichard Henderson     if (!supervisor(dc)) {
434886b82fe0SRichard Henderson         return raise_priv(dc);
434986b82fe0SRichard Henderson     }
435086b82fe0SRichard Henderson 
435186b82fe0SRichard Henderson     gen_check_align(dc, src, 3);
435286b82fe0SRichard Henderson 
435386b82fe0SRichard Henderson     gen_mov_pc_npc(dc);
435486b82fe0SRichard Henderson     tcg_gen_mov_tl(cpu_npc, src);
435586b82fe0SRichard Henderson     gen_helper_rett(tcg_env);
435686b82fe0SRichard Henderson 
435786b82fe0SRichard Henderson     dc->npc = DYNAMIC_PC;
435886b82fe0SRichard Henderson     return true;
435986b82fe0SRichard Henderson }
436086b82fe0SRichard Henderson 
436186b82fe0SRichard Henderson TRANS(RETT, 32, do_add_special, a, do_rett)
436286b82fe0SRichard Henderson 
436386b82fe0SRichard Henderson static bool do_return(DisasContext *dc, int rd, TCGv src)
436486b82fe0SRichard Henderson {
436586b82fe0SRichard Henderson     gen_check_align(dc, src, 3);
436686b82fe0SRichard Henderson 
436786b82fe0SRichard Henderson     gen_mov_pc_npc(dc);
436886b82fe0SRichard Henderson     tcg_gen_mov_tl(cpu_npc, src);
436986b82fe0SRichard Henderson     gen_address_mask(dc, cpu_npc);
437086b82fe0SRichard Henderson 
437186b82fe0SRichard Henderson     gen_helper_restore(tcg_env);
437286b82fe0SRichard Henderson     dc->npc = DYNAMIC_PC_LOOKUP;
437386b82fe0SRichard Henderson     return true;
437486b82fe0SRichard Henderson }
437586b82fe0SRichard Henderson 
437686b82fe0SRichard Henderson TRANS(RETURN, 64, do_add_special, a, do_return)
437786b82fe0SRichard Henderson 
4378d3825800SRichard Henderson static bool do_save(DisasContext *dc, int rd, TCGv src)
4379d3825800SRichard Henderson {
4380d3825800SRichard Henderson     gen_helper_save(tcg_env);
4381d3825800SRichard Henderson     gen_store_gpr(dc, rd, src);
4382d3825800SRichard Henderson     return advance_pc(dc);
4383d3825800SRichard Henderson }
4384d3825800SRichard Henderson 
4385d3825800SRichard Henderson TRANS(SAVE, ALL, do_add_special, a, do_save)
4386d3825800SRichard Henderson 
4387d3825800SRichard Henderson static bool do_restore(DisasContext *dc, int rd, TCGv src)
4388d3825800SRichard Henderson {
4389d3825800SRichard Henderson     gen_helper_restore(tcg_env);
4390d3825800SRichard Henderson     gen_store_gpr(dc, rd, src);
4391d3825800SRichard Henderson     return advance_pc(dc);
4392d3825800SRichard Henderson }
4393d3825800SRichard Henderson 
4394d3825800SRichard Henderson TRANS(RESTORE, ALL, do_add_special, a, do_restore)
4395d3825800SRichard Henderson 
43968f75b8a4SRichard Henderson static bool do_done_retry(DisasContext *dc, bool done)
43978f75b8a4SRichard Henderson {
43988f75b8a4SRichard Henderson     if (!supervisor(dc)) {
43998f75b8a4SRichard Henderson         return raise_priv(dc);
44008f75b8a4SRichard Henderson     }
44018f75b8a4SRichard Henderson     dc->npc = DYNAMIC_PC;
44028f75b8a4SRichard Henderson     dc->pc = DYNAMIC_PC;
44038f75b8a4SRichard Henderson     translator_io_start(&dc->base);
44048f75b8a4SRichard Henderson     if (done) {
44058f75b8a4SRichard Henderson         gen_helper_done(tcg_env);
44068f75b8a4SRichard Henderson     } else {
44078f75b8a4SRichard Henderson         gen_helper_retry(tcg_env);
44088f75b8a4SRichard Henderson     }
44098f75b8a4SRichard Henderson     return true;
44108f75b8a4SRichard Henderson }
44118f75b8a4SRichard Henderson 
44128f75b8a4SRichard Henderson TRANS(DONE, 64, do_done_retry, true)
44138f75b8a4SRichard Henderson TRANS(RETRY, 64, do_done_retry, false)
44148f75b8a4SRichard Henderson 
44150880d20bSRichard Henderson /*
44160880d20bSRichard Henderson  * Major opcode 11 -- load and store instructions
44170880d20bSRichard Henderson  */
44180880d20bSRichard Henderson 
44190880d20bSRichard Henderson static TCGv gen_ldst_addr(DisasContext *dc, int rs1, bool imm, int rs2_or_imm)
44200880d20bSRichard Henderson {
44210880d20bSRichard Henderson     TCGv addr, tmp = NULL;
44220880d20bSRichard Henderson 
44230880d20bSRichard Henderson     /* For simplicity, we under-decoded the rs2 form. */
44240880d20bSRichard Henderson     if (!imm && rs2_or_imm & ~0x1f) {
44250880d20bSRichard Henderson         return NULL;
44260880d20bSRichard Henderson     }
44270880d20bSRichard Henderson 
44280880d20bSRichard Henderson     addr = gen_load_gpr(dc, rs1);
44290880d20bSRichard Henderson     if (rs2_or_imm) {
44300880d20bSRichard Henderson         tmp = tcg_temp_new();
44310880d20bSRichard Henderson         if (imm) {
44320880d20bSRichard Henderson             tcg_gen_addi_tl(tmp, addr, rs2_or_imm);
44330880d20bSRichard Henderson         } else {
44340880d20bSRichard Henderson             tcg_gen_add_tl(tmp, addr, cpu_regs[rs2_or_imm]);
44350880d20bSRichard Henderson         }
44360880d20bSRichard Henderson         addr = tmp;
44370880d20bSRichard Henderson     }
44380880d20bSRichard Henderson     if (AM_CHECK(dc)) {
44390880d20bSRichard Henderson         if (!tmp) {
44400880d20bSRichard Henderson             tmp = tcg_temp_new();
44410880d20bSRichard Henderson         }
44420880d20bSRichard Henderson         tcg_gen_ext32u_tl(tmp, addr);
44430880d20bSRichard Henderson         addr = tmp;
44440880d20bSRichard Henderson     }
44450880d20bSRichard Henderson     return addr;
44460880d20bSRichard Henderson }
44470880d20bSRichard Henderson 
44480880d20bSRichard Henderson static bool do_ld_gpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp mop)
44490880d20bSRichard Henderson {
44500880d20bSRichard Henderson     TCGv reg, addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
44510880d20bSRichard Henderson     DisasASI da;
44520880d20bSRichard Henderson 
44530880d20bSRichard Henderson     if (addr == NULL) {
44540880d20bSRichard Henderson         return false;
44550880d20bSRichard Henderson     }
44560880d20bSRichard Henderson     da = resolve_asi(dc, a->asi, mop);
44570880d20bSRichard Henderson 
44580880d20bSRichard Henderson     reg = gen_dest_gpr(dc, a->rd);
445942071fc1SRichard Henderson     gen_ld_asi(dc, &da, reg, addr);
44600880d20bSRichard Henderson     gen_store_gpr(dc, a->rd, reg);
44610880d20bSRichard Henderson     return advance_pc(dc);
44620880d20bSRichard Henderson }
44630880d20bSRichard Henderson 
44640880d20bSRichard Henderson TRANS(LDUW, ALL, do_ld_gpr, a, MO_TEUL)
44650880d20bSRichard Henderson TRANS(LDUB, ALL, do_ld_gpr, a, MO_UB)
44660880d20bSRichard Henderson TRANS(LDUH, ALL, do_ld_gpr, a, MO_TEUW)
44670880d20bSRichard Henderson TRANS(LDSB, ALL, do_ld_gpr, a, MO_SB)
44680880d20bSRichard Henderson TRANS(LDSH, ALL, do_ld_gpr, a, MO_TESW)
44690880d20bSRichard Henderson TRANS(LDSW, 64, do_ld_gpr, a, MO_TESL)
44700880d20bSRichard Henderson TRANS(LDX, 64, do_ld_gpr, a, MO_TEUQ)
44710880d20bSRichard Henderson 
44720880d20bSRichard Henderson static bool do_st_gpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp mop)
44730880d20bSRichard Henderson {
44740880d20bSRichard Henderson     TCGv reg, addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
44750880d20bSRichard Henderson     DisasASI da;
44760880d20bSRichard Henderson 
44770880d20bSRichard Henderson     if (addr == NULL) {
44780880d20bSRichard Henderson         return false;
44790880d20bSRichard Henderson     }
44800880d20bSRichard Henderson     da = resolve_asi(dc, a->asi, mop);
44810880d20bSRichard Henderson 
44820880d20bSRichard Henderson     reg = gen_load_gpr(dc, a->rd);
448342071fc1SRichard Henderson     gen_st_asi(dc, &da, reg, addr);
44840880d20bSRichard Henderson     return advance_pc(dc);
44850880d20bSRichard Henderson }
44860880d20bSRichard Henderson 
44870880d20bSRichard Henderson TRANS(STW, ALL, do_st_gpr, a, MO_TEUL)
44880880d20bSRichard Henderson TRANS(STB, ALL, do_st_gpr, a, MO_UB)
44890880d20bSRichard Henderson TRANS(STH, ALL, do_st_gpr, a, MO_TEUW)
44900880d20bSRichard Henderson TRANS(STX, 64, do_st_gpr, a, MO_TEUQ)
44910880d20bSRichard Henderson 
44920880d20bSRichard Henderson static bool trans_LDD(DisasContext *dc, arg_r_r_ri_asi *a)
44930880d20bSRichard Henderson {
44940880d20bSRichard Henderson     TCGv addr;
44950880d20bSRichard Henderson     DisasASI da;
44960880d20bSRichard Henderson 
44970880d20bSRichard Henderson     if (a->rd & 1) {
44980880d20bSRichard Henderson         return false;
44990880d20bSRichard Henderson     }
45000880d20bSRichard Henderson     addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
45010880d20bSRichard Henderson     if (addr == NULL) {
45020880d20bSRichard Henderson         return false;
45030880d20bSRichard Henderson     }
45040880d20bSRichard Henderson     da = resolve_asi(dc, a->asi, MO_TEUQ);
450542071fc1SRichard Henderson     gen_ldda_asi(dc, &da, addr, a->rd);
45060880d20bSRichard Henderson     return advance_pc(dc);
45070880d20bSRichard Henderson }
45080880d20bSRichard Henderson 
45090880d20bSRichard Henderson static bool trans_STD(DisasContext *dc, arg_r_r_ri_asi *a)
45100880d20bSRichard Henderson {
45110880d20bSRichard Henderson     TCGv addr;
45120880d20bSRichard Henderson     DisasASI da;
45130880d20bSRichard Henderson 
45140880d20bSRichard Henderson     if (a->rd & 1) {
45150880d20bSRichard Henderson         return false;
45160880d20bSRichard Henderson     }
45170880d20bSRichard Henderson     addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
45180880d20bSRichard Henderson     if (addr == NULL) {
45190880d20bSRichard Henderson         return false;
45200880d20bSRichard Henderson     }
45210880d20bSRichard Henderson     da = resolve_asi(dc, a->asi, MO_TEUQ);
452242071fc1SRichard Henderson     gen_stda_asi(dc, &da, addr, a->rd);
45230880d20bSRichard Henderson     return advance_pc(dc);
45240880d20bSRichard Henderson }
45250880d20bSRichard Henderson 
4526cf07cd1eSRichard Henderson static bool trans_LDSTUB(DisasContext *dc, arg_r_r_ri_asi *a)
4527cf07cd1eSRichard Henderson {
4528cf07cd1eSRichard Henderson     TCGv addr, reg;
4529cf07cd1eSRichard Henderson     DisasASI da;
4530cf07cd1eSRichard Henderson 
4531cf07cd1eSRichard Henderson     addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
4532cf07cd1eSRichard Henderson     if (addr == NULL) {
4533cf07cd1eSRichard Henderson         return false;
4534cf07cd1eSRichard Henderson     }
4535cf07cd1eSRichard Henderson     da = resolve_asi(dc, a->asi, MO_UB);
4536cf07cd1eSRichard Henderson 
4537cf07cd1eSRichard Henderson     reg = gen_dest_gpr(dc, a->rd);
4538cf07cd1eSRichard Henderson     gen_ldstub_asi(dc, &da, reg, addr);
4539cf07cd1eSRichard Henderson     gen_store_gpr(dc, a->rd, reg);
4540cf07cd1eSRichard Henderson     return advance_pc(dc);
4541cf07cd1eSRichard Henderson }
4542cf07cd1eSRichard Henderson 
4543dca544b9SRichard Henderson static bool trans_SWAP(DisasContext *dc, arg_r_r_ri_asi *a)
4544dca544b9SRichard Henderson {
4545dca544b9SRichard Henderson     TCGv addr, dst, src;
4546dca544b9SRichard Henderson     DisasASI da;
4547dca544b9SRichard Henderson 
4548dca544b9SRichard Henderson     addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
4549dca544b9SRichard Henderson     if (addr == NULL) {
4550dca544b9SRichard Henderson         return false;
4551dca544b9SRichard Henderson     }
4552dca544b9SRichard Henderson     da = resolve_asi(dc, a->asi, MO_TEUL);
4553dca544b9SRichard Henderson 
4554dca544b9SRichard Henderson     dst = gen_dest_gpr(dc, a->rd);
4555dca544b9SRichard Henderson     src = gen_load_gpr(dc, a->rd);
4556dca544b9SRichard Henderson     gen_swap_asi(dc, &da, dst, src, addr);
4557dca544b9SRichard Henderson     gen_store_gpr(dc, a->rd, dst);
4558dca544b9SRichard Henderson     return advance_pc(dc);
4559dca544b9SRichard Henderson }
4560dca544b9SRichard Henderson 
4561d0a11d25SRichard Henderson static bool do_casa(DisasContext *dc, arg_r_r_ri_asi *a, MemOp mop)
4562d0a11d25SRichard Henderson {
4563d0a11d25SRichard Henderson     TCGv addr, o, n, c;
4564d0a11d25SRichard Henderson     DisasASI da;
4565d0a11d25SRichard Henderson 
4566d0a11d25SRichard Henderson     addr = gen_ldst_addr(dc, a->rs1, true, 0);
4567d0a11d25SRichard Henderson     if (addr == NULL) {
4568d0a11d25SRichard Henderson         return false;
4569d0a11d25SRichard Henderson     }
4570d0a11d25SRichard Henderson     da = resolve_asi(dc, a->asi, mop);
4571d0a11d25SRichard Henderson 
4572d0a11d25SRichard Henderson     o = gen_dest_gpr(dc, a->rd);
4573d0a11d25SRichard Henderson     n = gen_load_gpr(dc, a->rd);
4574d0a11d25SRichard Henderson     c = gen_load_gpr(dc, a->rs2_or_imm);
4575d0a11d25SRichard Henderson     gen_cas_asi(dc, &da, o, n, c, addr);
4576d0a11d25SRichard Henderson     gen_store_gpr(dc, a->rd, o);
4577d0a11d25SRichard Henderson     return advance_pc(dc);
4578d0a11d25SRichard Henderson }
4579d0a11d25SRichard Henderson 
4580d0a11d25SRichard Henderson TRANS(CASA, CASA, do_casa, a, MO_TEUL)
4581d0a11d25SRichard Henderson TRANS(CASXA, 64, do_casa, a, MO_TEUQ)
4582d0a11d25SRichard Henderson 
458306c060d9SRichard Henderson static bool do_ld_fpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp sz)
458406c060d9SRichard Henderson {
458506c060d9SRichard Henderson     TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
458606c060d9SRichard Henderson     DisasASI da;
458706c060d9SRichard Henderson 
458806c060d9SRichard Henderson     if (addr == NULL) {
458906c060d9SRichard Henderson         return false;
459006c060d9SRichard Henderson     }
459106c060d9SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
459206c060d9SRichard Henderson         return true;
459306c060d9SRichard Henderson     }
459406c060d9SRichard Henderson     if (sz == MO_128 && gen_trap_float128(dc)) {
459506c060d9SRichard Henderson         return true;
459606c060d9SRichard Henderson     }
459706c060d9SRichard Henderson     da = resolve_asi(dc, a->asi, MO_TE | sz);
4598287b1152SRichard Henderson     gen_ldf_asi(dc, &da, sz, addr, a->rd);
459906c060d9SRichard Henderson     gen_update_fprs_dirty(dc, a->rd);
460006c060d9SRichard Henderson     return advance_pc(dc);
460106c060d9SRichard Henderson }
460206c060d9SRichard Henderson 
460306c060d9SRichard Henderson TRANS(LDF, ALL, do_ld_fpr, a, MO_32)
460406c060d9SRichard Henderson TRANS(LDDF, ALL, do_ld_fpr, a, MO_64)
460506c060d9SRichard Henderson TRANS(LDQF, ALL, do_ld_fpr, a, MO_128)
460606c060d9SRichard Henderson 
4607287b1152SRichard Henderson TRANS(LDFA, 64, do_ld_fpr, a, MO_32)
4608287b1152SRichard Henderson TRANS(LDDFA, 64, do_ld_fpr, a, MO_64)
4609287b1152SRichard Henderson TRANS(LDQFA, 64, do_ld_fpr, a, MO_128)
4610287b1152SRichard Henderson 
461106c060d9SRichard Henderson static bool do_st_fpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp sz)
461206c060d9SRichard Henderson {
461306c060d9SRichard Henderson     TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
461406c060d9SRichard Henderson     DisasASI da;
461506c060d9SRichard Henderson 
461606c060d9SRichard Henderson     if (addr == NULL) {
461706c060d9SRichard Henderson         return false;
461806c060d9SRichard Henderson     }
461906c060d9SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
462006c060d9SRichard Henderson         return true;
462106c060d9SRichard Henderson     }
462206c060d9SRichard Henderson     if (sz == MO_128 && gen_trap_float128(dc)) {
462306c060d9SRichard Henderson         return true;
462406c060d9SRichard Henderson     }
462506c060d9SRichard Henderson     da = resolve_asi(dc, a->asi, MO_TE | sz);
4626287b1152SRichard Henderson     gen_stf_asi(dc, &da, sz, addr, a->rd);
462706c060d9SRichard Henderson     return advance_pc(dc);
462806c060d9SRichard Henderson }
462906c060d9SRichard Henderson 
463006c060d9SRichard Henderson TRANS(STF, ALL, do_st_fpr, a, MO_32)
463106c060d9SRichard Henderson TRANS(STDF, ALL, do_st_fpr, a, MO_64)
463206c060d9SRichard Henderson TRANS(STQF, ALL, do_st_fpr, a, MO_128)
463306c060d9SRichard Henderson 
4634287b1152SRichard Henderson TRANS(STFA, 64, do_st_fpr, a, MO_32)
4635287b1152SRichard Henderson TRANS(STDFA, 64, do_st_fpr, a, MO_64)
4636287b1152SRichard Henderson TRANS(STQFA, 64, do_st_fpr, a, MO_128)
4637287b1152SRichard Henderson 
463806c060d9SRichard Henderson static bool trans_STDFQ(DisasContext *dc, arg_STDFQ *a)
463906c060d9SRichard Henderson {
464006c060d9SRichard Henderson     if (!avail_32(dc)) {
464106c060d9SRichard Henderson         return false;
464206c060d9SRichard Henderson     }
464306c060d9SRichard Henderson     if (!supervisor(dc)) {
464406c060d9SRichard Henderson         return raise_priv(dc);
464506c060d9SRichard Henderson     }
464606c060d9SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
464706c060d9SRichard Henderson         return true;
464806c060d9SRichard Henderson     }
464906c060d9SRichard Henderson     gen_op_fpexception_im(dc, FSR_FTT_SEQ_ERROR);
465006c060d9SRichard Henderson     return true;
465106c060d9SRichard Henderson }
465206c060d9SRichard Henderson 
4653da681406SRichard Henderson static bool do_ldfsr(DisasContext *dc, arg_r_r_ri *a, MemOp mop,
4654da681406SRichard Henderson                      target_ulong new_mask, target_ulong old_mask)
46553d3c0673SRichard Henderson {
4656da681406SRichard Henderson     TCGv tmp, addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
46573d3c0673SRichard Henderson     if (addr == NULL) {
46583d3c0673SRichard Henderson         return false;
46593d3c0673SRichard Henderson     }
46603d3c0673SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
46613d3c0673SRichard Henderson         return true;
46623d3c0673SRichard Henderson     }
4663da681406SRichard Henderson     tmp = tcg_temp_new();
4664da681406SRichard Henderson     tcg_gen_qemu_ld_tl(tmp, addr, dc->mem_idx, mop | MO_ALIGN);
4665da681406SRichard Henderson     tcg_gen_andi_tl(tmp, tmp, new_mask);
4666da681406SRichard Henderson     tcg_gen_andi_tl(cpu_fsr, cpu_fsr, old_mask);
4667da681406SRichard Henderson     tcg_gen_or_tl(cpu_fsr, cpu_fsr, tmp);
4668da681406SRichard Henderson     gen_helper_set_fsr(tcg_env, cpu_fsr);
46693d3c0673SRichard Henderson     return advance_pc(dc);
46703d3c0673SRichard Henderson }
46713d3c0673SRichard Henderson 
4672da681406SRichard Henderson TRANS(LDFSR, ALL, do_ldfsr, a, MO_TEUL, FSR_LDFSR_MASK, FSR_LDFSR_OLDMASK)
4673da681406SRichard Henderson TRANS(LDXFSR, 64, do_ldfsr, a, MO_TEUQ, FSR_LDXFSR_MASK, FSR_LDXFSR_OLDMASK)
46743d3c0673SRichard Henderson 
46753d3c0673SRichard Henderson static bool do_stfsr(DisasContext *dc, arg_r_r_ri *a, MemOp mop)
46763d3c0673SRichard Henderson {
46773d3c0673SRichard Henderson     TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
46783d3c0673SRichard Henderson     if (addr == NULL) {
46793d3c0673SRichard Henderson         return false;
46803d3c0673SRichard Henderson     }
46813d3c0673SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
46823d3c0673SRichard Henderson         return true;
46833d3c0673SRichard Henderson     }
46843d3c0673SRichard Henderson     tcg_gen_qemu_st_tl(cpu_fsr, addr, dc->mem_idx, mop | MO_ALIGN);
46853d3c0673SRichard Henderson     return advance_pc(dc);
46863d3c0673SRichard Henderson }
46873d3c0673SRichard Henderson 
46883d3c0673SRichard Henderson TRANS(STFSR, ALL, do_stfsr, a, MO_TEUL)
46893d3c0673SRichard Henderson TRANS(STXFSR, 64, do_stfsr, a, MO_TEUQ)
46903d3c0673SRichard Henderson 
4691baf3dbf2SRichard Henderson static bool do_ff(DisasContext *dc, arg_r_r *a,
4692baf3dbf2SRichard Henderson                   void (*func)(TCGv_i32, TCGv_i32))
4693baf3dbf2SRichard Henderson {
4694baf3dbf2SRichard Henderson     TCGv_i32 tmp;
4695baf3dbf2SRichard Henderson 
4696baf3dbf2SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4697baf3dbf2SRichard Henderson         return true;
4698baf3dbf2SRichard Henderson     }
4699baf3dbf2SRichard Henderson 
4700baf3dbf2SRichard Henderson     tmp = gen_load_fpr_F(dc, a->rs);
4701baf3dbf2SRichard Henderson     func(tmp, tmp);
4702baf3dbf2SRichard Henderson     gen_store_fpr_F(dc, a->rd, tmp);
4703baf3dbf2SRichard Henderson     return advance_pc(dc);
4704baf3dbf2SRichard Henderson }
4705baf3dbf2SRichard Henderson 
4706baf3dbf2SRichard Henderson TRANS(FMOVs, ALL, do_ff, a, gen_op_fmovs)
4707baf3dbf2SRichard Henderson TRANS(FNEGs, ALL, do_ff, a, gen_op_fnegs)
4708baf3dbf2SRichard Henderson TRANS(FABSs, ALL, do_ff, a, gen_op_fabss)
4709baf3dbf2SRichard Henderson TRANS(FSRCs, VIS1, do_ff, a, tcg_gen_mov_i32)
4710baf3dbf2SRichard Henderson TRANS(FNOTs, VIS1, do_ff, a, tcg_gen_not_i32)
4711baf3dbf2SRichard Henderson 
4712119cb94fSRichard Henderson static bool do_env_ff(DisasContext *dc, arg_r_r *a,
4713119cb94fSRichard Henderson                       void (*func)(TCGv_i32, TCGv_env, TCGv_i32))
4714119cb94fSRichard Henderson {
4715119cb94fSRichard Henderson     TCGv_i32 tmp;
4716119cb94fSRichard Henderson 
4717119cb94fSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4718119cb94fSRichard Henderson         return true;
4719119cb94fSRichard Henderson     }
4720119cb94fSRichard Henderson 
4721119cb94fSRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
4722119cb94fSRichard Henderson     tmp = gen_load_fpr_F(dc, a->rs);
4723119cb94fSRichard Henderson     func(tmp, tcg_env, tmp);
4724119cb94fSRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
4725119cb94fSRichard Henderson     gen_store_fpr_F(dc, a->rd, tmp);
4726119cb94fSRichard Henderson     return advance_pc(dc);
4727119cb94fSRichard Henderson }
4728119cb94fSRichard Henderson 
4729119cb94fSRichard Henderson TRANS(FSQRTs, ALL, do_env_ff, a, gen_helper_fsqrts)
4730119cb94fSRichard Henderson TRANS(FiTOs, ALL, do_env_ff, a, gen_helper_fitos)
4731119cb94fSRichard Henderson TRANS(FsTOi, ALL, do_env_ff, a, gen_helper_fstoi)
4732119cb94fSRichard Henderson 
4733c6d83e4fSRichard Henderson static bool do_dd(DisasContext *dc, arg_r_r *a,
4734c6d83e4fSRichard Henderson                   void (*func)(TCGv_i64, TCGv_i64))
4735c6d83e4fSRichard Henderson {
4736c6d83e4fSRichard Henderson     TCGv_i64 dst, src;
4737c6d83e4fSRichard Henderson 
4738c6d83e4fSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4739c6d83e4fSRichard Henderson         return true;
4740c6d83e4fSRichard Henderson     }
4741c6d83e4fSRichard Henderson 
4742c6d83e4fSRichard Henderson     dst = gen_dest_fpr_D(dc, a->rd);
4743c6d83e4fSRichard Henderson     src = gen_load_fpr_D(dc, a->rs);
4744c6d83e4fSRichard Henderson     func(dst, src);
4745c6d83e4fSRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
4746c6d83e4fSRichard Henderson     return advance_pc(dc);
4747c6d83e4fSRichard Henderson }
4748c6d83e4fSRichard Henderson 
4749c6d83e4fSRichard Henderson TRANS(FMOVd, 64, do_dd, a, gen_op_fmovd)
4750c6d83e4fSRichard Henderson TRANS(FNEGd, 64, do_dd, a, gen_op_fnegd)
4751c6d83e4fSRichard Henderson TRANS(FABSd, 64, do_dd, a, gen_op_fabsd)
4752c6d83e4fSRichard Henderson TRANS(FSRCd, VIS1, do_dd, a, tcg_gen_mov_i64)
4753c6d83e4fSRichard Henderson TRANS(FNOTd, VIS1, do_dd, a, tcg_gen_not_i64)
4754c6d83e4fSRichard Henderson 
47558aa418b3SRichard Henderson static bool do_env_dd(DisasContext *dc, arg_r_r *a,
47568aa418b3SRichard Henderson                       void (*func)(TCGv_i64, TCGv_env, TCGv_i64))
47578aa418b3SRichard Henderson {
47588aa418b3SRichard Henderson     TCGv_i64 dst, src;
47598aa418b3SRichard Henderson 
47608aa418b3SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
47618aa418b3SRichard Henderson         return true;
47628aa418b3SRichard Henderson     }
47638aa418b3SRichard Henderson 
47648aa418b3SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
47658aa418b3SRichard Henderson     dst = gen_dest_fpr_D(dc, a->rd);
47668aa418b3SRichard Henderson     src = gen_load_fpr_D(dc, a->rs);
47678aa418b3SRichard Henderson     func(dst, tcg_env, src);
47688aa418b3SRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
47698aa418b3SRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
47708aa418b3SRichard Henderson     return advance_pc(dc);
47718aa418b3SRichard Henderson }
47728aa418b3SRichard Henderson 
47738aa418b3SRichard Henderson TRANS(FSQRTd, ALL, do_env_dd, a, gen_helper_fsqrtd)
47748aa418b3SRichard Henderson TRANS(FxTOd, 64, do_env_dd, a, gen_helper_fxtod)
47758aa418b3SRichard Henderson TRANS(FdTOx, 64, do_env_dd, a, gen_helper_fdtox)
47768aa418b3SRichard Henderson 
4777c995216bSRichard Henderson static bool do_env_qq(DisasContext *dc, arg_r_r *a,
4778c995216bSRichard Henderson                        void (*func)(TCGv_env))
4779c995216bSRichard Henderson {
4780c995216bSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4781c995216bSRichard Henderson         return true;
4782c995216bSRichard Henderson     }
4783c995216bSRichard Henderson     if (gen_trap_float128(dc)) {
4784c995216bSRichard Henderson         return true;
4785c995216bSRichard Henderson     }
4786c995216bSRichard Henderson 
4787c995216bSRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
4788c995216bSRichard Henderson     gen_op_load_fpr_QT1(QFPREG(a->rs));
4789c995216bSRichard Henderson     func(tcg_env);
4790c995216bSRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
4791c995216bSRichard Henderson     gen_op_store_QT0_fpr(QFPREG(a->rd));
4792c995216bSRichard Henderson     gen_update_fprs_dirty(dc, QFPREG(a->rd));
4793c995216bSRichard Henderson     return advance_pc(dc);
4794c995216bSRichard Henderson }
4795c995216bSRichard Henderson 
4796c995216bSRichard Henderson TRANS(FSQRTq, ALL, do_env_qq, a, gen_helper_fsqrtq)
4797c995216bSRichard Henderson 
47987f10b52fSRichard Henderson static bool do_fff(DisasContext *dc, arg_r_r_r *a,
47997f10b52fSRichard Henderson                    void (*func)(TCGv_i32, TCGv_i32, TCGv_i32))
48007f10b52fSRichard Henderson {
48017f10b52fSRichard Henderson     TCGv_i32 src1, src2;
48027f10b52fSRichard Henderson 
48037f10b52fSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
48047f10b52fSRichard Henderson         return true;
48057f10b52fSRichard Henderson     }
48067f10b52fSRichard Henderson 
48077f10b52fSRichard Henderson     src1 = gen_load_fpr_F(dc, a->rs1);
48087f10b52fSRichard Henderson     src2 = gen_load_fpr_F(dc, a->rs2);
48097f10b52fSRichard Henderson     func(src1, src1, src2);
48107f10b52fSRichard Henderson     gen_store_fpr_F(dc, a->rd, src1);
48117f10b52fSRichard Henderson     return advance_pc(dc);
48127f10b52fSRichard Henderson }
48137f10b52fSRichard Henderson 
48147f10b52fSRichard Henderson TRANS(FPADD16s, VIS1, do_fff, a, tcg_gen_vec_add16_i32)
48157f10b52fSRichard Henderson TRANS(FPADD32s, VIS1, do_fff, a, tcg_gen_add_i32)
48167f10b52fSRichard Henderson TRANS(FPSUB16s, VIS1, do_fff, a, tcg_gen_vec_sub16_i32)
48177f10b52fSRichard Henderson TRANS(FPSUB32s, VIS1, do_fff, a, tcg_gen_sub_i32)
48187f10b52fSRichard Henderson TRANS(FNORs, VIS1, do_fff, a, tcg_gen_nor_i32)
48197f10b52fSRichard Henderson TRANS(FANDNOTs, VIS1, do_fff, a, tcg_gen_andc_i32)
48207f10b52fSRichard Henderson TRANS(FXORs, VIS1, do_fff, a, tcg_gen_xor_i32)
48217f10b52fSRichard Henderson TRANS(FNANDs, VIS1, do_fff, a, tcg_gen_nand_i32)
48227f10b52fSRichard Henderson TRANS(FANDs, VIS1, do_fff, a, tcg_gen_and_i32)
48237f10b52fSRichard Henderson TRANS(FXNORs, VIS1, do_fff, a, tcg_gen_eqv_i32)
48247f10b52fSRichard Henderson TRANS(FORNOTs, VIS1, do_fff, a, tcg_gen_orc_i32)
48257f10b52fSRichard Henderson TRANS(FORs, VIS1, do_fff, a, tcg_gen_or_i32)
48267f10b52fSRichard Henderson 
4827c1514961SRichard Henderson static bool do_env_fff(DisasContext *dc, arg_r_r_r *a,
4828c1514961SRichard Henderson                        void (*func)(TCGv_i32, TCGv_env, TCGv_i32, TCGv_i32))
4829c1514961SRichard Henderson {
4830c1514961SRichard Henderson     TCGv_i32 src1, src2;
4831c1514961SRichard Henderson 
4832c1514961SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4833c1514961SRichard Henderson         return true;
4834c1514961SRichard Henderson     }
4835c1514961SRichard Henderson 
4836c1514961SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
4837c1514961SRichard Henderson     src1 = gen_load_fpr_F(dc, a->rs1);
4838c1514961SRichard Henderson     src2 = gen_load_fpr_F(dc, a->rs2);
4839c1514961SRichard Henderson     func(src1, tcg_env, src1, src2);
4840c1514961SRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
4841c1514961SRichard Henderson     gen_store_fpr_F(dc, a->rd, src1);
4842c1514961SRichard Henderson     return advance_pc(dc);
4843c1514961SRichard Henderson }
4844c1514961SRichard Henderson 
4845c1514961SRichard Henderson TRANS(FADDs, ALL, do_env_fff, a, gen_helper_fadds)
4846c1514961SRichard Henderson TRANS(FSUBs, ALL, do_env_fff, a, gen_helper_fsubs)
4847c1514961SRichard Henderson TRANS(FMULs, ALL, do_env_fff, a, gen_helper_fmuls)
4848c1514961SRichard Henderson TRANS(FDIVs, ALL, do_env_fff, a, gen_helper_fdivs)
4849c1514961SRichard Henderson 
4850e06c9f83SRichard Henderson static bool do_ddd(DisasContext *dc, arg_r_r_r *a,
4851e06c9f83SRichard Henderson                    void (*func)(TCGv_i64, TCGv_i64, TCGv_i64))
4852e06c9f83SRichard Henderson {
4853e06c9f83SRichard Henderson     TCGv_i64 dst, src1, src2;
4854e06c9f83SRichard Henderson 
4855e06c9f83SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4856e06c9f83SRichard Henderson         return true;
4857e06c9f83SRichard Henderson     }
4858e06c9f83SRichard Henderson 
4859e06c9f83SRichard Henderson     dst = gen_dest_fpr_D(dc, a->rd);
4860e06c9f83SRichard Henderson     src1 = gen_load_fpr_D(dc, a->rs1);
4861e06c9f83SRichard Henderson     src2 = gen_load_fpr_D(dc, a->rs2);
4862e06c9f83SRichard Henderson     func(dst, src1, src2);
4863e06c9f83SRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
4864e06c9f83SRichard Henderson     return advance_pc(dc);
4865e06c9f83SRichard Henderson }
4866e06c9f83SRichard Henderson 
4867e06c9f83SRichard Henderson TRANS(FMUL8x16, VIS1, do_ddd, a, gen_helper_fmul8x16)
4868e06c9f83SRichard Henderson TRANS(FMUL8x16AU, VIS1, do_ddd, a, gen_helper_fmul8x16au)
4869e06c9f83SRichard Henderson TRANS(FMUL8x16AL, VIS1, do_ddd, a, gen_helper_fmul8x16al)
4870e06c9f83SRichard Henderson TRANS(FMUL8SUx16, VIS1, do_ddd, a, gen_helper_fmul8sux16)
4871e06c9f83SRichard Henderson TRANS(FMUL8ULx16, VIS1, do_ddd, a, gen_helper_fmul8ulx16)
4872e06c9f83SRichard Henderson TRANS(FMULD8SUx16, VIS1, do_ddd, a, gen_helper_fmuld8sux16)
4873e06c9f83SRichard Henderson TRANS(FMULD8ULx16, VIS1, do_ddd, a, gen_helper_fmuld8ulx16)
4874e06c9f83SRichard Henderson TRANS(FPMERGE, VIS1, do_ddd, a, gen_helper_fpmerge)
4875e06c9f83SRichard Henderson TRANS(FEXPAND, VIS1, do_ddd, a, gen_helper_fexpand)
4876e06c9f83SRichard Henderson 
4877e06c9f83SRichard Henderson TRANS(FPADD16, VIS1, do_ddd, a, tcg_gen_vec_add16_i64)
4878e06c9f83SRichard Henderson TRANS(FPADD32, VIS1, do_ddd, a, tcg_gen_vec_add32_i64)
4879e06c9f83SRichard Henderson TRANS(FPSUB16, VIS1, do_ddd, a, tcg_gen_vec_sub16_i64)
4880e06c9f83SRichard Henderson TRANS(FPSUB32, VIS1, do_ddd, a, tcg_gen_vec_sub32_i64)
4881e06c9f83SRichard Henderson TRANS(FNORd, VIS1, do_ddd, a, tcg_gen_nor_i64)
4882e06c9f83SRichard Henderson TRANS(FANDNOTd, VIS1, do_ddd, a, tcg_gen_andc_i64)
4883e06c9f83SRichard Henderson TRANS(FXORd, VIS1, do_ddd, a, tcg_gen_xor_i64)
4884e06c9f83SRichard Henderson TRANS(FNANDd, VIS1, do_ddd, a, tcg_gen_nand_i64)
4885e06c9f83SRichard Henderson TRANS(FANDd, VIS1, do_ddd, a, tcg_gen_and_i64)
4886e06c9f83SRichard Henderson TRANS(FXNORd, VIS1, do_ddd, a, tcg_gen_eqv_i64)
4887e06c9f83SRichard Henderson TRANS(FORNOTd, VIS1, do_ddd, a, tcg_gen_orc_i64)
4888e06c9f83SRichard Henderson TRANS(FORd, VIS1, do_ddd, a, tcg_gen_or_i64)
4889e06c9f83SRichard Henderson 
48904b6edc0aSRichard Henderson TRANS(FPACK32, VIS1, do_ddd, a, gen_op_fpack32)
48914b6edc0aSRichard Henderson TRANS(FALIGNDATAg, VIS1, do_ddd, a, gen_op_faligndata)
48924b6edc0aSRichard Henderson TRANS(BSHUFFLE, VIS2, do_ddd, a, gen_op_bshuffle)
48934b6edc0aSRichard Henderson 
4894f2a59b0aSRichard Henderson static bool do_env_ddd(DisasContext *dc, arg_r_r_r *a,
4895f2a59b0aSRichard Henderson                        void (*func)(TCGv_i64, TCGv_env, TCGv_i64, TCGv_i64))
4896f2a59b0aSRichard Henderson {
4897f2a59b0aSRichard Henderson     TCGv_i64 dst, src1, src2;
4898f2a59b0aSRichard Henderson 
4899f2a59b0aSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4900f2a59b0aSRichard Henderson         return true;
4901f2a59b0aSRichard Henderson     }
4902f2a59b0aSRichard Henderson 
4903f2a59b0aSRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
4904f2a59b0aSRichard Henderson     dst = gen_dest_fpr_D(dc, a->rd);
4905f2a59b0aSRichard Henderson     src1 = gen_load_fpr_D(dc, a->rs1);
4906f2a59b0aSRichard Henderson     src2 = gen_load_fpr_D(dc, a->rs2);
4907f2a59b0aSRichard Henderson     func(dst, tcg_env, src1, src2);
4908f2a59b0aSRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
4909f2a59b0aSRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
4910f2a59b0aSRichard Henderson     return advance_pc(dc);
4911f2a59b0aSRichard Henderson }
4912f2a59b0aSRichard Henderson 
4913f2a59b0aSRichard Henderson TRANS(FADDd, ALL, do_env_ddd, a, gen_helper_faddd)
4914f2a59b0aSRichard Henderson TRANS(FSUBd, ALL, do_env_ddd, a, gen_helper_fsubd)
4915f2a59b0aSRichard Henderson TRANS(FMULd, ALL, do_env_ddd, a, gen_helper_fmuld)
4916f2a59b0aSRichard Henderson TRANS(FDIVd, ALL, do_env_ddd, a, gen_helper_fdivd)
4917f2a59b0aSRichard Henderson 
4918*ff4c711bSRichard Henderson static bool trans_FsMULd(DisasContext *dc, arg_r_r_r *a)
4919*ff4c711bSRichard Henderson {
4920*ff4c711bSRichard Henderson     TCGv_i64 dst;
4921*ff4c711bSRichard Henderson     TCGv_i32 src1, src2;
4922*ff4c711bSRichard Henderson 
4923*ff4c711bSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4924*ff4c711bSRichard Henderson         return true;
4925*ff4c711bSRichard Henderson     }
4926*ff4c711bSRichard Henderson     if (!(dc->def->features & CPU_FEATURE_FSMULD)) {
4927*ff4c711bSRichard Henderson         return raise_unimpfpop(dc);
4928*ff4c711bSRichard Henderson     }
4929*ff4c711bSRichard Henderson 
4930*ff4c711bSRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
4931*ff4c711bSRichard Henderson     dst = gen_dest_fpr_D(dc, a->rd);
4932*ff4c711bSRichard Henderson     src1 = gen_load_fpr_F(dc, a->rs1);
4933*ff4c711bSRichard Henderson     src2 = gen_load_fpr_F(dc, a->rs2);
4934*ff4c711bSRichard Henderson     gen_helper_fsmuld(dst, tcg_env, src1, src2);
4935*ff4c711bSRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
4936*ff4c711bSRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
4937*ff4c711bSRichard Henderson     return advance_pc(dc);
4938*ff4c711bSRichard Henderson }
4939*ff4c711bSRichard Henderson 
4940afb04344SRichard Henderson static bool do_dddd(DisasContext *dc, arg_r_r_r *a,
4941afb04344SRichard Henderson                     void (*func)(TCGv_i64, TCGv_i64, TCGv_i64, TCGv_i64))
4942afb04344SRichard Henderson {
4943afb04344SRichard Henderson     TCGv_i64 dst, src0, src1, src2;
4944afb04344SRichard Henderson 
4945afb04344SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4946afb04344SRichard Henderson         return true;
4947afb04344SRichard Henderson     }
4948afb04344SRichard Henderson 
4949afb04344SRichard Henderson     dst  = gen_dest_fpr_D(dc, a->rd);
4950afb04344SRichard Henderson     src0 = gen_load_fpr_D(dc, a->rd);
4951afb04344SRichard Henderson     src1 = gen_load_fpr_D(dc, a->rs1);
4952afb04344SRichard Henderson     src2 = gen_load_fpr_D(dc, a->rs2);
4953afb04344SRichard Henderson     func(dst, src0, src1, src2);
4954afb04344SRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
4955afb04344SRichard Henderson     return advance_pc(dc);
4956afb04344SRichard Henderson }
4957afb04344SRichard Henderson 
4958afb04344SRichard Henderson TRANS(PDIST, VIS1, do_dddd, a, gen_helper_pdist)
4959afb04344SRichard Henderson 
4960a4056239SRichard Henderson static bool do_env_qqq(DisasContext *dc, arg_r_r_r *a,
4961a4056239SRichard Henderson                        void (*func)(TCGv_env))
4962a4056239SRichard Henderson {
4963a4056239SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4964a4056239SRichard Henderson         return true;
4965a4056239SRichard Henderson     }
4966a4056239SRichard Henderson     if (gen_trap_float128(dc)) {
4967a4056239SRichard Henderson         return true;
4968a4056239SRichard Henderson     }
4969a4056239SRichard Henderson 
4970a4056239SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
4971a4056239SRichard Henderson     gen_op_load_fpr_QT0(QFPREG(a->rs1));
4972a4056239SRichard Henderson     gen_op_load_fpr_QT1(QFPREG(a->rs2));
4973a4056239SRichard Henderson     func(tcg_env);
4974a4056239SRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
4975a4056239SRichard Henderson     gen_op_store_QT0_fpr(QFPREG(a->rd));
4976a4056239SRichard Henderson     gen_update_fprs_dirty(dc, QFPREG(a->rd));
4977a4056239SRichard Henderson     return advance_pc(dc);
4978a4056239SRichard Henderson }
4979a4056239SRichard Henderson 
4980a4056239SRichard Henderson TRANS(FADDq, ALL, do_env_qqq, a, gen_helper_faddq)
4981a4056239SRichard Henderson TRANS(FSUBq, ALL, do_env_qqq, a, gen_helper_fsubq)
4982a4056239SRichard Henderson TRANS(FMULq, ALL, do_env_qqq, a, gen_helper_fmulq)
4983a4056239SRichard Henderson TRANS(FDIVq, ALL, do_env_qqq, a, gen_helper_fdivq)
4984a4056239SRichard Henderson 
4985fcf5ef2aSThomas Huth #define CHECK_IU_FEATURE(dc, FEATURE)                      \
4986fcf5ef2aSThomas Huth     if (!((dc)->def->features & CPU_FEATURE_ ## FEATURE))  \
4987fcf5ef2aSThomas Huth         goto illegal_insn;
4988fcf5ef2aSThomas Huth #define CHECK_FPU_FEATURE(dc, FEATURE)                     \
4989fcf5ef2aSThomas Huth     if (!((dc)->def->features & CPU_FEATURE_ ## FEATURE))  \
4990fcf5ef2aSThomas Huth         goto nfpu_insn;
4991fcf5ef2aSThomas Huth 
4992fcf5ef2aSThomas Huth /* before an instruction, dc->pc must be static */
4993878cc677SRichard Henderson static void disas_sparc_legacy(DisasContext *dc, unsigned int insn)
4994fcf5ef2aSThomas Huth {
4995fcf5ef2aSThomas Huth     unsigned int opc, rs1, rs2, rd;
4996dca544b9SRichard Henderson     TCGv cpu_src1 __attribute__((unused));
49973d3c0673SRichard Henderson     TCGv_i32 cpu_src1_32, cpu_src2_32;
499806c060d9SRichard Henderson     TCGv_i64 cpu_src1_64, cpu_src2_64;
49993d3c0673SRichard Henderson     TCGv_i32 cpu_dst_32 __attribute__((unused));
500006c060d9SRichard Henderson     TCGv_i64 cpu_dst_64 __attribute__((unused));
5001fcf5ef2aSThomas Huth 
5002fcf5ef2aSThomas Huth     opc = GET_FIELD(insn, 0, 1);
5003fcf5ef2aSThomas Huth     rd = GET_FIELD(insn, 2, 6);
5004fcf5ef2aSThomas Huth 
5005fcf5ef2aSThomas Huth     switch (opc) {
50066d2a0768SRichard Henderson     case 0:
50076d2a0768SRichard Henderson         goto illegal_insn; /* in decodetree */
500823ada1b1SRichard Henderson     case 1:
500923ada1b1SRichard Henderson         g_assert_not_reached(); /* in decodetree */
5010fcf5ef2aSThomas Huth     case 2:                     /* FPU & Logical Operations */
5011fcf5ef2aSThomas Huth         {
50128f75b8a4SRichard Henderson             unsigned int xop = GET_FIELD(insn, 7, 12);
5013af25071cSRichard Henderson             TCGv cpu_dst __attribute__((unused)) = tcg_temp_new();
5014fcf5ef2aSThomas Huth 
5015af25071cSRichard Henderson             if (xop == 0x34) {   /* FPU Operations */
5016fcf5ef2aSThomas Huth                 if (gen_trap_ifnofpu(dc)) {
5017fcf5ef2aSThomas Huth                     goto jmp_insn;
5018fcf5ef2aSThomas Huth                 }
5019fcf5ef2aSThomas Huth                 gen_op_clear_ieee_excp_and_FTT();
5020fcf5ef2aSThomas Huth                 rs1 = GET_FIELD(insn, 13, 17);
5021fcf5ef2aSThomas Huth                 rs2 = GET_FIELD(insn, 27, 31);
5022fcf5ef2aSThomas Huth                 xop = GET_FIELD(insn, 18, 26);
5023fcf5ef2aSThomas Huth 
5024fcf5ef2aSThomas Huth                 switch (xop) {
5025fcf5ef2aSThomas Huth                 case 0x1: /* fmovs */
5026fcf5ef2aSThomas Huth                 case 0x5: /* fnegs */
5027fcf5ef2aSThomas Huth                 case 0x9: /* fabss */
5028c6d83e4fSRichard Henderson                 case 0x2: /* V9 fmovd */
5029c6d83e4fSRichard Henderson                 case 0x6: /* V9 fnegd */
5030c6d83e4fSRichard Henderson                 case 0xa: /* V9 fabsd */
5031fcf5ef2aSThomas Huth                 case 0x29: /* fsqrts */
5032119cb94fSRichard Henderson                 case 0xc4: /* fitos */
5033119cb94fSRichard Henderson                 case 0xd1: /* fstoi */
5034fcf5ef2aSThomas Huth                 case 0x2a: /* fsqrtd */
50358aa418b3SRichard Henderson                 case 0x82: /* V9 fdtox */
50368aa418b3SRichard Henderson                 case 0x88: /* V9 fxtod */
5037fcf5ef2aSThomas Huth                 case 0x2b: /* fsqrtq */
5038fcf5ef2aSThomas Huth                 case 0x41: /* fadds */
5039c1514961SRichard Henderson                 case 0x45: /* fsubs */
5040c1514961SRichard Henderson                 case 0x49: /* fmuls */
5041c1514961SRichard Henderson                 case 0x4d: /* fdivs */
5042fcf5ef2aSThomas Huth                 case 0x42: /* faddd */
5043f2a59b0aSRichard Henderson                 case 0x46: /* fsubd */
5044f2a59b0aSRichard Henderson                 case 0x4a: /* fmuld */
5045f2a59b0aSRichard Henderson                 case 0x4e: /* fdivd */
5046fcf5ef2aSThomas Huth                 case 0x43: /* faddq */
5047fcf5ef2aSThomas Huth                 case 0x47: /* fsubq */
5048fcf5ef2aSThomas Huth                 case 0x4b: /* fmulq */
5049fcf5ef2aSThomas Huth                 case 0x4f: /* fdivq */
5050fcf5ef2aSThomas Huth                 case 0x69: /* fsmuld */
5051*ff4c711bSRichard Henderson                     g_assert_not_reached(); /* in decodetree */
5052fcf5ef2aSThomas Huth                 case 0x6e: /* fdmulq */
5053fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, FLOAT128);
5054fcf5ef2aSThomas Huth                     gen_fop_QDD(dc, rd, rs1, rs2, gen_helper_fdmulq);
5055fcf5ef2aSThomas Huth                     break;
5056fcf5ef2aSThomas Huth                 case 0xc6: /* fdtos */
5057fcf5ef2aSThomas Huth                     gen_fop_FD(dc, rd, rs2, gen_helper_fdtos);
5058fcf5ef2aSThomas Huth                     break;
5059fcf5ef2aSThomas Huth                 case 0xc7: /* fqtos */
5060fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, FLOAT128);
5061fcf5ef2aSThomas Huth                     gen_fop_FQ(dc, rd, rs2, gen_helper_fqtos);
5062fcf5ef2aSThomas Huth                     break;
5063fcf5ef2aSThomas Huth                 case 0xc8: /* fitod */
5064fcf5ef2aSThomas Huth                     gen_ne_fop_DF(dc, rd, rs2, gen_helper_fitod);
5065fcf5ef2aSThomas Huth                     break;
5066fcf5ef2aSThomas Huth                 case 0xc9: /* fstod */
5067fcf5ef2aSThomas Huth                     gen_ne_fop_DF(dc, rd, rs2, gen_helper_fstod);
5068fcf5ef2aSThomas Huth                     break;
5069fcf5ef2aSThomas Huth                 case 0xcb: /* fqtod */
5070fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, FLOAT128);
5071fcf5ef2aSThomas Huth                     gen_fop_DQ(dc, rd, rs2, gen_helper_fqtod);
5072fcf5ef2aSThomas Huth                     break;
5073fcf5ef2aSThomas Huth                 case 0xcc: /* fitoq */
5074fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, FLOAT128);
5075fcf5ef2aSThomas Huth                     gen_ne_fop_QF(dc, rd, rs2, gen_helper_fitoq);
5076fcf5ef2aSThomas Huth                     break;
5077fcf5ef2aSThomas Huth                 case 0xcd: /* fstoq */
5078fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, FLOAT128);
5079fcf5ef2aSThomas Huth                     gen_ne_fop_QF(dc, rd, rs2, gen_helper_fstoq);
5080fcf5ef2aSThomas Huth                     break;
5081fcf5ef2aSThomas Huth                 case 0xce: /* fdtoq */
5082fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, FLOAT128);
5083fcf5ef2aSThomas Huth                     gen_ne_fop_QD(dc, rd, rs2, gen_helper_fdtoq);
5084fcf5ef2aSThomas Huth                     break;
5085fcf5ef2aSThomas Huth                 case 0xd2: /* fdtoi */
5086fcf5ef2aSThomas Huth                     gen_fop_FD(dc, rd, rs2, gen_helper_fdtoi);
5087fcf5ef2aSThomas Huth                     break;
5088fcf5ef2aSThomas Huth                 case 0xd3: /* fqtoi */
5089fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, FLOAT128);
5090fcf5ef2aSThomas Huth                     gen_fop_FQ(dc, rd, rs2, gen_helper_fqtoi);
5091fcf5ef2aSThomas Huth                     break;
5092fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
5093fcf5ef2aSThomas Huth                 case 0x3: /* V9 fmovq */
5094fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, FLOAT128);
5095fcf5ef2aSThomas Huth                     gen_move_Q(dc, rd, rs2);
5096fcf5ef2aSThomas Huth                     break;
5097fcf5ef2aSThomas Huth                 case 0x7: /* V9 fnegq */
5098fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, FLOAT128);
5099fcf5ef2aSThomas Huth                     gen_ne_fop_QQ(dc, rd, rs2, gen_helper_fnegq);
5100fcf5ef2aSThomas Huth                     break;
5101fcf5ef2aSThomas Huth                 case 0xb: /* V9 fabsq */
5102fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, FLOAT128);
5103fcf5ef2aSThomas Huth                     gen_ne_fop_QQ(dc, rd, rs2, gen_helper_fabsq);
5104fcf5ef2aSThomas Huth                     break;
5105fcf5ef2aSThomas Huth                 case 0x81: /* V9 fstox */
5106fcf5ef2aSThomas Huth                     gen_fop_DF(dc, rd, rs2, gen_helper_fstox);
5107fcf5ef2aSThomas Huth                     break;
5108fcf5ef2aSThomas Huth                 case 0x83: /* V9 fqtox */
5109fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, FLOAT128);
5110fcf5ef2aSThomas Huth                     gen_fop_DQ(dc, rd, rs2, gen_helper_fqtox);
5111fcf5ef2aSThomas Huth                     break;
5112fcf5ef2aSThomas Huth                 case 0x84: /* V9 fxtos */
5113fcf5ef2aSThomas Huth                     gen_fop_FD(dc, rd, rs2, gen_helper_fxtos);
5114fcf5ef2aSThomas Huth                     break;
5115fcf5ef2aSThomas Huth                 case 0x8c: /* V9 fxtoq */
5116fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, FLOAT128);
5117fcf5ef2aSThomas Huth                     gen_ne_fop_QD(dc, rd, rs2, gen_helper_fxtoq);
5118fcf5ef2aSThomas Huth                     break;
5119fcf5ef2aSThomas Huth #endif
5120fcf5ef2aSThomas Huth                 default:
5121fcf5ef2aSThomas Huth                     goto illegal_insn;
5122fcf5ef2aSThomas Huth                 }
5123fcf5ef2aSThomas Huth             } else if (xop == 0x35) {   /* FPU Operations */
5124fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
5125fcf5ef2aSThomas Huth                 int cond;
5126fcf5ef2aSThomas Huth #endif
5127fcf5ef2aSThomas Huth                 if (gen_trap_ifnofpu(dc)) {
5128fcf5ef2aSThomas Huth                     goto jmp_insn;
5129fcf5ef2aSThomas Huth                 }
5130fcf5ef2aSThomas Huth                 gen_op_clear_ieee_excp_and_FTT();
5131fcf5ef2aSThomas Huth                 rs1 = GET_FIELD(insn, 13, 17);
5132fcf5ef2aSThomas Huth                 rs2 = GET_FIELD(insn, 27, 31);
5133fcf5ef2aSThomas Huth                 xop = GET_FIELD(insn, 18, 26);
5134fcf5ef2aSThomas Huth 
5135fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
5136fcf5ef2aSThomas Huth #define FMOVR(sz)                                                  \
5137fcf5ef2aSThomas Huth                 do {                                               \
5138fcf5ef2aSThomas Huth                     DisasCompare cmp;                              \
5139fcf5ef2aSThomas Huth                     cond = GET_FIELD_SP(insn, 10, 12);             \
5140fcf5ef2aSThomas Huth                     cpu_src1 = get_src1(dc, insn);                 \
5141fcf5ef2aSThomas Huth                     gen_compare_reg(&cmp, cond, cpu_src1);         \
5142fcf5ef2aSThomas Huth                     gen_fmov##sz(dc, &cmp, rd, rs2);               \
5143fcf5ef2aSThomas Huth                 } while (0)
5144fcf5ef2aSThomas Huth 
5145fcf5ef2aSThomas Huth                 if ((xop & 0x11f) == 0x005) { /* V9 fmovsr */
5146fcf5ef2aSThomas Huth                     FMOVR(s);
5147fcf5ef2aSThomas Huth                     break;
5148fcf5ef2aSThomas Huth                 } else if ((xop & 0x11f) == 0x006) { // V9 fmovdr
5149fcf5ef2aSThomas Huth                     FMOVR(d);
5150fcf5ef2aSThomas Huth                     break;
5151fcf5ef2aSThomas Huth                 } else if ((xop & 0x11f) == 0x007) { // V9 fmovqr
5152fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, FLOAT128);
5153fcf5ef2aSThomas Huth                     FMOVR(q);
5154fcf5ef2aSThomas Huth                     break;
5155fcf5ef2aSThomas Huth                 }
5156fcf5ef2aSThomas Huth #undef FMOVR
5157fcf5ef2aSThomas Huth #endif
5158fcf5ef2aSThomas Huth                 switch (xop) {
5159fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
5160fcf5ef2aSThomas Huth #define FMOVCC(fcc, sz)                                                 \
5161fcf5ef2aSThomas Huth                     do {                                                \
5162fcf5ef2aSThomas Huth                         DisasCompare cmp;                               \
5163fcf5ef2aSThomas Huth                         cond = GET_FIELD_SP(insn, 14, 17);              \
5164fcf5ef2aSThomas Huth                         gen_fcompare(&cmp, fcc, cond);                  \
5165fcf5ef2aSThomas Huth                         gen_fmov##sz(dc, &cmp, rd, rs2);                \
5166fcf5ef2aSThomas Huth                     } while (0)
5167fcf5ef2aSThomas Huth 
5168fcf5ef2aSThomas Huth                     case 0x001: /* V9 fmovscc %fcc0 */
5169fcf5ef2aSThomas Huth                         FMOVCC(0, s);
5170fcf5ef2aSThomas Huth                         break;
5171fcf5ef2aSThomas Huth                     case 0x002: /* V9 fmovdcc %fcc0 */
5172fcf5ef2aSThomas Huth                         FMOVCC(0, d);
5173fcf5ef2aSThomas Huth                         break;
5174fcf5ef2aSThomas Huth                     case 0x003: /* V9 fmovqcc %fcc0 */
5175fcf5ef2aSThomas Huth                         CHECK_FPU_FEATURE(dc, FLOAT128);
5176fcf5ef2aSThomas Huth                         FMOVCC(0, q);
5177fcf5ef2aSThomas Huth                         break;
5178fcf5ef2aSThomas Huth                     case 0x041: /* V9 fmovscc %fcc1 */
5179fcf5ef2aSThomas Huth                         FMOVCC(1, s);
5180fcf5ef2aSThomas Huth                         break;
5181fcf5ef2aSThomas Huth                     case 0x042: /* V9 fmovdcc %fcc1 */
5182fcf5ef2aSThomas Huth                         FMOVCC(1, d);
5183fcf5ef2aSThomas Huth                         break;
5184fcf5ef2aSThomas Huth                     case 0x043: /* V9 fmovqcc %fcc1 */
5185fcf5ef2aSThomas Huth                         CHECK_FPU_FEATURE(dc, FLOAT128);
5186fcf5ef2aSThomas Huth                         FMOVCC(1, q);
5187fcf5ef2aSThomas Huth                         break;
5188fcf5ef2aSThomas Huth                     case 0x081: /* V9 fmovscc %fcc2 */
5189fcf5ef2aSThomas Huth                         FMOVCC(2, s);
5190fcf5ef2aSThomas Huth                         break;
5191fcf5ef2aSThomas Huth                     case 0x082: /* V9 fmovdcc %fcc2 */
5192fcf5ef2aSThomas Huth                         FMOVCC(2, d);
5193fcf5ef2aSThomas Huth                         break;
5194fcf5ef2aSThomas Huth                     case 0x083: /* V9 fmovqcc %fcc2 */
5195fcf5ef2aSThomas Huth                         CHECK_FPU_FEATURE(dc, FLOAT128);
5196fcf5ef2aSThomas Huth                         FMOVCC(2, q);
5197fcf5ef2aSThomas Huth                         break;
5198fcf5ef2aSThomas Huth                     case 0x0c1: /* V9 fmovscc %fcc3 */
5199fcf5ef2aSThomas Huth                         FMOVCC(3, s);
5200fcf5ef2aSThomas Huth                         break;
5201fcf5ef2aSThomas Huth                     case 0x0c2: /* V9 fmovdcc %fcc3 */
5202fcf5ef2aSThomas Huth                         FMOVCC(3, d);
5203fcf5ef2aSThomas Huth                         break;
5204fcf5ef2aSThomas Huth                     case 0x0c3: /* V9 fmovqcc %fcc3 */
5205fcf5ef2aSThomas Huth                         CHECK_FPU_FEATURE(dc, FLOAT128);
5206fcf5ef2aSThomas Huth                         FMOVCC(3, q);
5207fcf5ef2aSThomas Huth                         break;
5208fcf5ef2aSThomas Huth #undef FMOVCC
5209fcf5ef2aSThomas Huth #define FMOVCC(xcc, sz)                                                 \
5210fcf5ef2aSThomas Huth                     do {                                                \
5211fcf5ef2aSThomas Huth                         DisasCompare cmp;                               \
5212fcf5ef2aSThomas Huth                         cond = GET_FIELD_SP(insn, 14, 17);              \
5213fcf5ef2aSThomas Huth                         gen_compare(&cmp, xcc, cond, dc);               \
5214fcf5ef2aSThomas Huth                         gen_fmov##sz(dc, &cmp, rd, rs2);                \
5215fcf5ef2aSThomas Huth                     } while (0)
5216fcf5ef2aSThomas Huth 
5217fcf5ef2aSThomas Huth                     case 0x101: /* V9 fmovscc %icc */
5218fcf5ef2aSThomas Huth                         FMOVCC(0, s);
5219fcf5ef2aSThomas Huth                         break;
5220fcf5ef2aSThomas Huth                     case 0x102: /* V9 fmovdcc %icc */
5221fcf5ef2aSThomas Huth                         FMOVCC(0, d);
5222fcf5ef2aSThomas Huth                         break;
5223fcf5ef2aSThomas Huth                     case 0x103: /* V9 fmovqcc %icc */
5224fcf5ef2aSThomas Huth                         CHECK_FPU_FEATURE(dc, FLOAT128);
5225fcf5ef2aSThomas Huth                         FMOVCC(0, q);
5226fcf5ef2aSThomas Huth                         break;
5227fcf5ef2aSThomas Huth                     case 0x181: /* V9 fmovscc %xcc */
5228fcf5ef2aSThomas Huth                         FMOVCC(1, s);
5229fcf5ef2aSThomas Huth                         break;
5230fcf5ef2aSThomas Huth                     case 0x182: /* V9 fmovdcc %xcc */
5231fcf5ef2aSThomas Huth                         FMOVCC(1, d);
5232fcf5ef2aSThomas Huth                         break;
5233fcf5ef2aSThomas Huth                     case 0x183: /* V9 fmovqcc %xcc */
5234fcf5ef2aSThomas Huth                         CHECK_FPU_FEATURE(dc, FLOAT128);
5235fcf5ef2aSThomas Huth                         FMOVCC(1, q);
5236fcf5ef2aSThomas Huth                         break;
5237fcf5ef2aSThomas Huth #undef FMOVCC
5238fcf5ef2aSThomas Huth #endif
5239fcf5ef2aSThomas Huth                     case 0x51: /* fcmps, V9 %fcc */
5240fcf5ef2aSThomas Huth                         cpu_src1_32 = gen_load_fpr_F(dc, rs1);
5241fcf5ef2aSThomas Huth                         cpu_src2_32 = gen_load_fpr_F(dc, rs2);
5242fcf5ef2aSThomas Huth                         gen_op_fcmps(rd & 3, cpu_src1_32, cpu_src2_32);
5243fcf5ef2aSThomas Huth                         break;
5244fcf5ef2aSThomas Huth                     case 0x52: /* fcmpd, V9 %fcc */
5245fcf5ef2aSThomas Huth                         cpu_src1_64 = gen_load_fpr_D(dc, rs1);
5246fcf5ef2aSThomas Huth                         cpu_src2_64 = gen_load_fpr_D(dc, rs2);
5247fcf5ef2aSThomas Huth                         gen_op_fcmpd(rd & 3, cpu_src1_64, cpu_src2_64);
5248fcf5ef2aSThomas Huth                         break;
5249fcf5ef2aSThomas Huth                     case 0x53: /* fcmpq, V9 %fcc */
5250fcf5ef2aSThomas Huth                         CHECK_FPU_FEATURE(dc, FLOAT128);
5251fcf5ef2aSThomas Huth                         gen_op_load_fpr_QT0(QFPREG(rs1));
5252fcf5ef2aSThomas Huth                         gen_op_load_fpr_QT1(QFPREG(rs2));
5253fcf5ef2aSThomas Huth                         gen_op_fcmpq(rd & 3);
5254fcf5ef2aSThomas Huth                         break;
5255fcf5ef2aSThomas Huth                     case 0x55: /* fcmpes, V9 %fcc */
5256fcf5ef2aSThomas Huth                         cpu_src1_32 = gen_load_fpr_F(dc, rs1);
5257fcf5ef2aSThomas Huth                         cpu_src2_32 = gen_load_fpr_F(dc, rs2);
5258fcf5ef2aSThomas Huth                         gen_op_fcmpes(rd & 3, cpu_src1_32, cpu_src2_32);
5259fcf5ef2aSThomas Huth                         break;
5260fcf5ef2aSThomas Huth                     case 0x56: /* fcmped, V9 %fcc */
5261fcf5ef2aSThomas Huth                         cpu_src1_64 = gen_load_fpr_D(dc, rs1);
5262fcf5ef2aSThomas Huth                         cpu_src2_64 = gen_load_fpr_D(dc, rs2);
5263fcf5ef2aSThomas Huth                         gen_op_fcmped(rd & 3, cpu_src1_64, cpu_src2_64);
5264fcf5ef2aSThomas Huth                         break;
5265fcf5ef2aSThomas Huth                     case 0x57: /* fcmpeq, V9 %fcc */
5266fcf5ef2aSThomas Huth                         CHECK_FPU_FEATURE(dc, FLOAT128);
5267fcf5ef2aSThomas Huth                         gen_op_load_fpr_QT0(QFPREG(rs1));
5268fcf5ef2aSThomas Huth                         gen_op_load_fpr_QT1(QFPREG(rs2));
5269fcf5ef2aSThomas Huth                         gen_op_fcmpeq(rd & 3);
5270fcf5ef2aSThomas Huth                         break;
5271fcf5ef2aSThomas Huth                     default:
5272fcf5ef2aSThomas Huth                         goto illegal_insn;
5273fcf5ef2aSThomas Huth                 }
5274d3c7e8adSRichard Henderson             } else if (xop == 0x36) {
5275fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
5276d3c7e8adSRichard Henderson                 /* VIS */
5277fcf5ef2aSThomas Huth                 int opf = GET_FIELD_SP(insn, 5, 13);
5278fcf5ef2aSThomas Huth                 rs1 = GET_FIELD(insn, 13, 17);
5279fcf5ef2aSThomas Huth                 rs2 = GET_FIELD(insn, 27, 31);
5280fcf5ef2aSThomas Huth                 if (gen_trap_ifnofpu(dc)) {
5281fcf5ef2aSThomas Huth                     goto jmp_insn;
5282fcf5ef2aSThomas Huth                 }
5283fcf5ef2aSThomas Huth 
5284fcf5ef2aSThomas Huth                 switch (opf) {
5285fcf5ef2aSThomas Huth                 case 0x000: /* VIS I edge8cc */
5286fcf5ef2aSThomas Huth                 case 0x001: /* VIS II edge8n */
5287fcf5ef2aSThomas Huth                 case 0x002: /* VIS I edge8lcc */
5288fcf5ef2aSThomas Huth                 case 0x003: /* VIS II edge8ln */
5289fcf5ef2aSThomas Huth                 case 0x004: /* VIS I edge16cc */
5290fcf5ef2aSThomas Huth                 case 0x005: /* VIS II edge16n */
5291fcf5ef2aSThomas Huth                 case 0x006: /* VIS I edge16lcc */
5292fcf5ef2aSThomas Huth                 case 0x007: /* VIS II edge16ln */
5293fcf5ef2aSThomas Huth                 case 0x008: /* VIS I edge32cc */
5294fcf5ef2aSThomas Huth                 case 0x009: /* VIS II edge32n */
5295fcf5ef2aSThomas Huth                 case 0x00a: /* VIS I edge32lcc */
5296fcf5ef2aSThomas Huth                 case 0x00b: /* VIS II edge32ln */
5297fcf5ef2aSThomas Huth                 case 0x010: /* VIS I array8 */
5298fcf5ef2aSThomas Huth                 case 0x012: /* VIS I array16 */
5299fcf5ef2aSThomas Huth                 case 0x014: /* VIS I array32 */
5300fcf5ef2aSThomas Huth                 case 0x018: /* VIS I alignaddr */
5301fcf5ef2aSThomas Huth                 case 0x01a: /* VIS I alignaddrl */
5302fcf5ef2aSThomas Huth                 case 0x019: /* VIS II bmask */
5303baf3dbf2SRichard Henderson                 case 0x067: /* VIS I fnot2s */
5304baf3dbf2SRichard Henderson                 case 0x06b: /* VIS I fnot1s */
5305baf3dbf2SRichard Henderson                 case 0x075: /* VIS I fsrc1s */
5306baf3dbf2SRichard Henderson                 case 0x079: /* VIS I fsrc2s */
5307c6d83e4fSRichard Henderson                 case 0x066: /* VIS I fnot2 */
5308c6d83e4fSRichard Henderson                 case 0x06a: /* VIS I fnot1 */
5309c6d83e4fSRichard Henderson                 case 0x074: /* VIS I fsrc1 */
5310c6d83e4fSRichard Henderson                 case 0x078: /* VIS I fsrc2 */
53117f10b52fSRichard Henderson                 case 0x051: /* VIS I fpadd16s */
53127f10b52fSRichard Henderson                 case 0x053: /* VIS I fpadd32s */
53137f10b52fSRichard Henderson                 case 0x055: /* VIS I fpsub16s */
53147f10b52fSRichard Henderson                 case 0x057: /* VIS I fpsub32s */
53157f10b52fSRichard Henderson                 case 0x063: /* VIS I fnors */
53167f10b52fSRichard Henderson                 case 0x065: /* VIS I fandnot2s */
53177f10b52fSRichard Henderson                 case 0x069: /* VIS I fandnot1s */
53187f10b52fSRichard Henderson                 case 0x06d: /* VIS I fxors */
53197f10b52fSRichard Henderson                 case 0x06f: /* VIS I fnands */
53207f10b52fSRichard Henderson                 case 0x071: /* VIS I fands */
53217f10b52fSRichard Henderson                 case 0x073: /* VIS I fxnors */
53227f10b52fSRichard Henderson                 case 0x077: /* VIS I fornot2s */
53237f10b52fSRichard Henderson                 case 0x07b: /* VIS I fornot1s */
53247f10b52fSRichard Henderson                 case 0x07d: /* VIS I fors */
5325e06c9f83SRichard Henderson                 case 0x050: /* VIS I fpadd16 */
5326e06c9f83SRichard Henderson                 case 0x052: /* VIS I fpadd32 */
5327e06c9f83SRichard Henderson                 case 0x054: /* VIS I fpsub16 */
5328e06c9f83SRichard Henderson                 case 0x056: /* VIS I fpsub32 */
5329e06c9f83SRichard Henderson                 case 0x062: /* VIS I fnor */
5330e06c9f83SRichard Henderson                 case 0x064: /* VIS I fandnot2 */
5331e06c9f83SRichard Henderson                 case 0x068: /* VIS I fandnot1 */
5332e06c9f83SRichard Henderson                 case 0x06c: /* VIS I fxor */
5333e06c9f83SRichard Henderson                 case 0x06e: /* VIS I fnand */
5334e06c9f83SRichard Henderson                 case 0x070: /* VIS I fand */
5335e06c9f83SRichard Henderson                 case 0x072: /* VIS I fxnor */
5336e06c9f83SRichard Henderson                 case 0x076: /* VIS I fornot2 */
5337e06c9f83SRichard Henderson                 case 0x07a: /* VIS I fornot1 */
5338e06c9f83SRichard Henderson                 case 0x07c: /* VIS I for */
5339e06c9f83SRichard Henderson                 case 0x031: /* VIS I fmul8x16 */
5340e06c9f83SRichard Henderson                 case 0x033: /* VIS I fmul8x16au */
5341e06c9f83SRichard Henderson                 case 0x035: /* VIS I fmul8x16al */
5342e06c9f83SRichard Henderson                 case 0x036: /* VIS I fmul8sux16 */
5343e06c9f83SRichard Henderson                 case 0x037: /* VIS I fmul8ulx16 */
5344e06c9f83SRichard Henderson                 case 0x038: /* VIS I fmuld8sux16 */
5345e06c9f83SRichard Henderson                 case 0x039: /* VIS I fmuld8ulx16 */
5346e06c9f83SRichard Henderson                 case 0x04b: /* VIS I fpmerge */
5347e06c9f83SRichard Henderson                 case 0x04d: /* VIS I fexpand */
5348afb04344SRichard Henderson                 case 0x03e: /* VIS I pdist */
53494b6edc0aSRichard Henderson                 case 0x03a: /* VIS I fpack32 */
53504b6edc0aSRichard Henderson                 case 0x048: /* VIS I faligndata */
53514b6edc0aSRichard Henderson                 case 0x04c: /* VIS II bshuffle */
535239ca3490SRichard Henderson                     g_assert_not_reached();  /* in decodetree */
5353fcf5ef2aSThomas Huth                 case 0x020: /* VIS I fcmple16 */
5354fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5355fcf5ef2aSThomas Huth                     cpu_src1_64 = gen_load_fpr_D(dc, rs1);
5356fcf5ef2aSThomas Huth                     cpu_src2_64 = gen_load_fpr_D(dc, rs2);
5357fcf5ef2aSThomas Huth                     gen_helper_fcmple16(cpu_dst, cpu_src1_64, cpu_src2_64);
5358fcf5ef2aSThomas Huth                     gen_store_gpr(dc, rd, cpu_dst);
5359fcf5ef2aSThomas Huth                     break;
5360fcf5ef2aSThomas Huth                 case 0x022: /* VIS I fcmpne16 */
5361fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5362fcf5ef2aSThomas Huth                     cpu_src1_64 = gen_load_fpr_D(dc, rs1);
5363fcf5ef2aSThomas Huth                     cpu_src2_64 = gen_load_fpr_D(dc, rs2);
5364fcf5ef2aSThomas Huth                     gen_helper_fcmpne16(cpu_dst, cpu_src1_64, cpu_src2_64);
5365fcf5ef2aSThomas Huth                     gen_store_gpr(dc, rd, cpu_dst);
5366fcf5ef2aSThomas Huth                     break;
5367fcf5ef2aSThomas Huth                 case 0x024: /* VIS I fcmple32 */
5368fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5369fcf5ef2aSThomas Huth                     cpu_src1_64 = gen_load_fpr_D(dc, rs1);
5370fcf5ef2aSThomas Huth                     cpu_src2_64 = gen_load_fpr_D(dc, rs2);
5371fcf5ef2aSThomas Huth                     gen_helper_fcmple32(cpu_dst, cpu_src1_64, cpu_src2_64);
5372fcf5ef2aSThomas Huth                     gen_store_gpr(dc, rd, cpu_dst);
5373fcf5ef2aSThomas Huth                     break;
5374fcf5ef2aSThomas Huth                 case 0x026: /* VIS I fcmpne32 */
5375fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5376fcf5ef2aSThomas Huth                     cpu_src1_64 = gen_load_fpr_D(dc, rs1);
5377fcf5ef2aSThomas Huth                     cpu_src2_64 = gen_load_fpr_D(dc, rs2);
5378fcf5ef2aSThomas Huth                     gen_helper_fcmpne32(cpu_dst, cpu_src1_64, cpu_src2_64);
5379fcf5ef2aSThomas Huth                     gen_store_gpr(dc, rd, cpu_dst);
5380fcf5ef2aSThomas Huth                     break;
5381fcf5ef2aSThomas Huth                 case 0x028: /* VIS I fcmpgt16 */
5382fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5383fcf5ef2aSThomas Huth                     cpu_src1_64 = gen_load_fpr_D(dc, rs1);
5384fcf5ef2aSThomas Huth                     cpu_src2_64 = gen_load_fpr_D(dc, rs2);
5385fcf5ef2aSThomas Huth                     gen_helper_fcmpgt16(cpu_dst, cpu_src1_64, cpu_src2_64);
5386fcf5ef2aSThomas Huth                     gen_store_gpr(dc, rd, cpu_dst);
5387fcf5ef2aSThomas Huth                     break;
5388fcf5ef2aSThomas Huth                 case 0x02a: /* VIS I fcmpeq16 */
5389fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5390fcf5ef2aSThomas Huth                     cpu_src1_64 = gen_load_fpr_D(dc, rs1);
5391fcf5ef2aSThomas Huth                     cpu_src2_64 = gen_load_fpr_D(dc, rs2);
5392fcf5ef2aSThomas Huth                     gen_helper_fcmpeq16(cpu_dst, cpu_src1_64, cpu_src2_64);
5393fcf5ef2aSThomas Huth                     gen_store_gpr(dc, rd, cpu_dst);
5394fcf5ef2aSThomas Huth                     break;
5395fcf5ef2aSThomas Huth                 case 0x02c: /* VIS I fcmpgt32 */
5396fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5397fcf5ef2aSThomas Huth                     cpu_src1_64 = gen_load_fpr_D(dc, rs1);
5398fcf5ef2aSThomas Huth                     cpu_src2_64 = gen_load_fpr_D(dc, rs2);
5399fcf5ef2aSThomas Huth                     gen_helper_fcmpgt32(cpu_dst, cpu_src1_64, cpu_src2_64);
5400fcf5ef2aSThomas Huth                     gen_store_gpr(dc, rd, cpu_dst);
5401fcf5ef2aSThomas Huth                     break;
5402fcf5ef2aSThomas Huth                 case 0x02e: /* VIS I fcmpeq32 */
5403fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5404fcf5ef2aSThomas Huth                     cpu_src1_64 = gen_load_fpr_D(dc, rs1);
5405fcf5ef2aSThomas Huth                     cpu_src2_64 = gen_load_fpr_D(dc, rs2);
5406fcf5ef2aSThomas Huth                     gen_helper_fcmpeq32(cpu_dst, cpu_src1_64, cpu_src2_64);
5407fcf5ef2aSThomas Huth                     gen_store_gpr(dc, rd, cpu_dst);
5408fcf5ef2aSThomas Huth                     break;
5409fcf5ef2aSThomas Huth                 case 0x03b: /* VIS I fpack16 */
5410fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5411fcf5ef2aSThomas Huth                     cpu_src1_64 = gen_load_fpr_D(dc, rs2);
5412fcf5ef2aSThomas Huth                     cpu_dst_32 = gen_dest_fpr_F(dc);
5413fcf5ef2aSThomas Huth                     gen_helper_fpack16(cpu_dst_32, cpu_gsr, cpu_src1_64);
5414fcf5ef2aSThomas Huth                     gen_store_fpr_F(dc, rd, cpu_dst_32);
5415fcf5ef2aSThomas Huth                     break;
5416fcf5ef2aSThomas Huth                 case 0x03d: /* VIS I fpackfix */
5417fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5418fcf5ef2aSThomas Huth                     cpu_src1_64 = gen_load_fpr_D(dc, rs2);
5419fcf5ef2aSThomas Huth                     cpu_dst_32 = gen_dest_fpr_F(dc);
5420fcf5ef2aSThomas Huth                     gen_helper_fpackfix(cpu_dst_32, cpu_gsr, cpu_src1_64);
5421fcf5ef2aSThomas Huth                     gen_store_fpr_F(dc, rd, cpu_dst_32);
5422fcf5ef2aSThomas Huth                     break;
5423fcf5ef2aSThomas Huth                 case 0x060: /* VIS I fzero */
5424fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5425fcf5ef2aSThomas Huth                     cpu_dst_64 = gen_dest_fpr_D(dc, rd);
5426fcf5ef2aSThomas Huth                     tcg_gen_movi_i64(cpu_dst_64, 0);
5427fcf5ef2aSThomas Huth                     gen_store_fpr_D(dc, rd, cpu_dst_64);
5428fcf5ef2aSThomas Huth                     break;
5429fcf5ef2aSThomas Huth                 case 0x061: /* VIS I fzeros */
5430fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5431fcf5ef2aSThomas Huth                     cpu_dst_32 = gen_dest_fpr_F(dc);
5432fcf5ef2aSThomas Huth                     tcg_gen_movi_i32(cpu_dst_32, 0);
5433fcf5ef2aSThomas Huth                     gen_store_fpr_F(dc, rd, cpu_dst_32);
5434fcf5ef2aSThomas Huth                     break;
5435fcf5ef2aSThomas Huth                 case 0x07e: /* VIS I fone */
5436fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5437fcf5ef2aSThomas Huth                     cpu_dst_64 = gen_dest_fpr_D(dc, rd);
5438fcf5ef2aSThomas Huth                     tcg_gen_movi_i64(cpu_dst_64, -1);
5439fcf5ef2aSThomas Huth                     gen_store_fpr_D(dc, rd, cpu_dst_64);
5440fcf5ef2aSThomas Huth                     break;
5441fcf5ef2aSThomas Huth                 case 0x07f: /* VIS I fones */
5442fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5443fcf5ef2aSThomas Huth                     cpu_dst_32 = gen_dest_fpr_F(dc);
5444fcf5ef2aSThomas Huth                     tcg_gen_movi_i32(cpu_dst_32, -1);
5445fcf5ef2aSThomas Huth                     gen_store_fpr_F(dc, rd, cpu_dst_32);
5446fcf5ef2aSThomas Huth                     break;
5447fcf5ef2aSThomas Huth                 case 0x080: /* VIS I shutdown */
5448fcf5ef2aSThomas Huth                 case 0x081: /* VIS II siam */
5449fcf5ef2aSThomas Huth                     // XXX
5450fcf5ef2aSThomas Huth                     goto illegal_insn;
5451fcf5ef2aSThomas Huth                 default:
5452fcf5ef2aSThomas Huth                     goto illegal_insn;
5453fcf5ef2aSThomas Huth                 }
5454fcf5ef2aSThomas Huth #endif
54558f75b8a4SRichard Henderson             } else {
5456d3c7e8adSRichard Henderson                 goto illegal_insn; /* in decodetree */
5457fcf5ef2aSThomas Huth             }
5458fcf5ef2aSThomas Huth         }
5459fcf5ef2aSThomas Huth         break;
5460fcf5ef2aSThomas Huth     case 3:                     /* load/store instructions */
54610880d20bSRichard Henderson         goto illegal_insn; /* in decodetree */
5462fcf5ef2aSThomas Huth     }
5463878cc677SRichard Henderson     advance_pc(dc);
5464fcf5ef2aSThomas Huth  jmp_insn:
5465a6ca81cbSRichard Henderson     return;
5466fcf5ef2aSThomas Huth  illegal_insn:
5467fcf5ef2aSThomas Huth     gen_exception(dc, TT_ILL_INSN);
5468a6ca81cbSRichard Henderson     return;
5469fcf5ef2aSThomas Huth  nfpu_insn:
5470fcf5ef2aSThomas Huth     gen_op_fpexception_im(dc, FSR_FTT_UNIMPFPOP);
5471a6ca81cbSRichard Henderson     return;
5472fcf5ef2aSThomas Huth }
5473fcf5ef2aSThomas Huth 
54746e61bc94SEmilio G. Cota static void sparc_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
5475fcf5ef2aSThomas Huth {
54766e61bc94SEmilio G. Cota     DisasContext *dc = container_of(dcbase, DisasContext, base);
5477b77af26eSRichard Henderson     CPUSPARCState *env = cpu_env(cs);
54786e61bc94SEmilio G. Cota     int bound;
5479af00be49SEmilio G. Cota 
5480af00be49SEmilio G. Cota     dc->pc = dc->base.pc_first;
54816e61bc94SEmilio G. Cota     dc->npc = (target_ulong)dc->base.tb->cs_base;
5482fcf5ef2aSThomas Huth     dc->cc_op = CC_OP_DYNAMIC;
54836e61bc94SEmilio G. Cota     dc->mem_idx = dc->base.tb->flags & TB_FLAG_MMU_MASK;
5484576e1c4cSIgor Mammedov     dc->def = &env->def;
54856e61bc94SEmilio G. Cota     dc->fpu_enabled = tb_fpu_enabled(dc->base.tb->flags);
54866e61bc94SEmilio G. Cota     dc->address_mask_32bit = tb_am_enabled(dc->base.tb->flags);
5487c9b459aaSArtyom Tarasenko #ifndef CONFIG_USER_ONLY
54886e61bc94SEmilio G. Cota     dc->supervisor = (dc->base.tb->flags & TB_FLAG_SUPER) != 0;
5489c9b459aaSArtyom Tarasenko #endif
5490fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
5491fcf5ef2aSThomas Huth     dc->fprs_dirty = 0;
54926e61bc94SEmilio G. Cota     dc->asi = (dc->base.tb->flags >> TB_FLAG_ASI_SHIFT) & 0xff;
5493c9b459aaSArtyom Tarasenko #ifndef CONFIG_USER_ONLY
54946e61bc94SEmilio G. Cota     dc->hypervisor = (dc->base.tb->flags & TB_FLAG_HYPER) != 0;
5495c9b459aaSArtyom Tarasenko #endif
5496fcf5ef2aSThomas Huth #endif
54976e61bc94SEmilio G. Cota     /*
54986e61bc94SEmilio G. Cota      * if we reach a page boundary, we stop generation so that the
54996e61bc94SEmilio G. Cota      * PC of a TT_TFAULT exception is always in the right page
55006e61bc94SEmilio G. Cota      */
55016e61bc94SEmilio G. Cota     bound = -(dc->base.pc_first | TARGET_PAGE_MASK) / 4;
55026e61bc94SEmilio G. Cota     dc->base.max_insns = MIN(dc->base.max_insns, bound);
5503af00be49SEmilio G. Cota }
5504fcf5ef2aSThomas Huth 
55056e61bc94SEmilio G. Cota static void sparc_tr_tb_start(DisasContextBase *db, CPUState *cs)
55066e61bc94SEmilio G. Cota {
55076e61bc94SEmilio G. Cota }
55086e61bc94SEmilio G. Cota 
55096e61bc94SEmilio G. Cota static void sparc_tr_insn_start(DisasContextBase *dcbase, CPUState *cs)
55106e61bc94SEmilio G. Cota {
55116e61bc94SEmilio G. Cota     DisasContext *dc = container_of(dcbase, DisasContext, base);
5512633c4283SRichard Henderson     target_ulong npc = dc->npc;
55136e61bc94SEmilio G. Cota 
5514633c4283SRichard Henderson     if (npc & 3) {
5515633c4283SRichard Henderson         switch (npc) {
5516633c4283SRichard Henderson         case JUMP_PC:
5517fcf5ef2aSThomas Huth             assert(dc->jump_pc[1] == dc->pc + 4);
5518633c4283SRichard Henderson             npc = dc->jump_pc[0] | JUMP_PC;
5519633c4283SRichard Henderson             break;
5520633c4283SRichard Henderson         case DYNAMIC_PC:
5521633c4283SRichard Henderson         case DYNAMIC_PC_LOOKUP:
5522633c4283SRichard Henderson             npc = DYNAMIC_PC;
5523633c4283SRichard Henderson             break;
5524633c4283SRichard Henderson         default:
5525633c4283SRichard Henderson             g_assert_not_reached();
5526fcf5ef2aSThomas Huth         }
55276e61bc94SEmilio G. Cota     }
5528633c4283SRichard Henderson     tcg_gen_insn_start(dc->pc, npc);
5529633c4283SRichard Henderson }
5530fcf5ef2aSThomas Huth 
55316e61bc94SEmilio G. Cota static void sparc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs)
55326e61bc94SEmilio G. Cota {
55336e61bc94SEmilio G. Cota     DisasContext *dc = container_of(dcbase, DisasContext, base);
5534b77af26eSRichard Henderson     CPUSPARCState *env = cpu_env(cs);
55356e61bc94SEmilio G. Cota     unsigned int insn;
5536fcf5ef2aSThomas Huth 
55374e116893SIlya Leoshkevich     insn = translator_ldl(env, &dc->base, dc->pc);
5538af00be49SEmilio G. Cota     dc->base.pc_next += 4;
5539878cc677SRichard Henderson 
5540878cc677SRichard Henderson     if (!decode(dc, insn)) {
5541878cc677SRichard Henderson         disas_sparc_legacy(dc, insn);
5542878cc677SRichard Henderson     }
5543fcf5ef2aSThomas Huth 
5544af00be49SEmilio G. Cota     if (dc->base.is_jmp == DISAS_NORETURN) {
55456e61bc94SEmilio G. Cota         return;
5546c5e6ccdfSEmilio G. Cota     }
5547af00be49SEmilio G. Cota     if (dc->pc != dc->base.pc_next) {
55486e61bc94SEmilio G. Cota         dc->base.is_jmp = DISAS_TOO_MANY;
5549af00be49SEmilio G. Cota     }
55506e61bc94SEmilio G. Cota }
5551fcf5ef2aSThomas Huth 
55526e61bc94SEmilio G. Cota static void sparc_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)
55536e61bc94SEmilio G. Cota {
55546e61bc94SEmilio G. Cota     DisasContext *dc = container_of(dcbase, DisasContext, base);
5555186e7890SRichard Henderson     DisasDelayException *e, *e_next;
5556633c4283SRichard Henderson     bool may_lookup;
55576e61bc94SEmilio G. Cota 
555846bb0137SMark Cave-Ayland     switch (dc->base.is_jmp) {
555946bb0137SMark Cave-Ayland     case DISAS_NEXT:
556046bb0137SMark Cave-Ayland     case DISAS_TOO_MANY:
5561633c4283SRichard Henderson         if (((dc->pc | dc->npc) & 3) == 0) {
5562fcf5ef2aSThomas Huth             /* static PC and NPC: we can use direct chaining */
5563fcf5ef2aSThomas Huth             gen_goto_tb(dc, 0, dc->pc, dc->npc);
5564633c4283SRichard Henderson             break;
5565fcf5ef2aSThomas Huth         }
5566633c4283SRichard Henderson 
5567930f1865SRichard Henderson         may_lookup = true;
5568633c4283SRichard Henderson         if (dc->pc & 3) {
5569633c4283SRichard Henderson             switch (dc->pc) {
5570633c4283SRichard Henderson             case DYNAMIC_PC_LOOKUP:
5571633c4283SRichard Henderson                 break;
5572633c4283SRichard Henderson             case DYNAMIC_PC:
5573633c4283SRichard Henderson                 may_lookup = false;
5574633c4283SRichard Henderson                 break;
5575633c4283SRichard Henderson             default:
5576633c4283SRichard Henderson                 g_assert_not_reached();
5577633c4283SRichard Henderson             }
5578633c4283SRichard Henderson         } else {
5579633c4283SRichard Henderson             tcg_gen_movi_tl(cpu_pc, dc->pc);
5580633c4283SRichard Henderson         }
5581633c4283SRichard Henderson 
5582930f1865SRichard Henderson         if (dc->npc & 3) {
5583930f1865SRichard Henderson             switch (dc->npc) {
5584930f1865SRichard Henderson             case JUMP_PC:
5585930f1865SRichard Henderson                 gen_generic_branch(dc);
5586930f1865SRichard Henderson                 break;
5587930f1865SRichard Henderson             case DYNAMIC_PC:
5588930f1865SRichard Henderson                 may_lookup = false;
5589930f1865SRichard Henderson                 break;
5590930f1865SRichard Henderson             case DYNAMIC_PC_LOOKUP:
5591930f1865SRichard Henderson                 break;
5592930f1865SRichard Henderson             default:
5593930f1865SRichard Henderson                 g_assert_not_reached();
5594930f1865SRichard Henderson             }
5595930f1865SRichard Henderson         } else {
5596930f1865SRichard Henderson             tcg_gen_movi_tl(cpu_npc, dc->npc);
5597930f1865SRichard Henderson         }
5598633c4283SRichard Henderson         if (may_lookup) {
5599633c4283SRichard Henderson             tcg_gen_lookup_and_goto_ptr();
5600633c4283SRichard Henderson         } else {
560107ea28b4SRichard Henderson             tcg_gen_exit_tb(NULL, 0);
5602fcf5ef2aSThomas Huth         }
560346bb0137SMark Cave-Ayland         break;
560446bb0137SMark Cave-Ayland 
560546bb0137SMark Cave-Ayland     case DISAS_NORETURN:
560646bb0137SMark Cave-Ayland        break;
560746bb0137SMark Cave-Ayland 
560846bb0137SMark Cave-Ayland     case DISAS_EXIT:
560946bb0137SMark Cave-Ayland         /* Exit TB */
561046bb0137SMark Cave-Ayland         save_state(dc);
561146bb0137SMark Cave-Ayland         tcg_gen_exit_tb(NULL, 0);
561246bb0137SMark Cave-Ayland         break;
561346bb0137SMark Cave-Ayland 
561446bb0137SMark Cave-Ayland     default:
561546bb0137SMark Cave-Ayland         g_assert_not_reached();
5616fcf5ef2aSThomas Huth     }
5617186e7890SRichard Henderson 
5618186e7890SRichard Henderson     for (e = dc->delay_excp_list; e ; e = e_next) {
5619186e7890SRichard Henderson         gen_set_label(e->lab);
5620186e7890SRichard Henderson 
5621186e7890SRichard Henderson         tcg_gen_movi_tl(cpu_pc, e->pc);
5622186e7890SRichard Henderson         if (e->npc % 4 == 0) {
5623186e7890SRichard Henderson             tcg_gen_movi_tl(cpu_npc, e->npc);
5624186e7890SRichard Henderson         }
5625186e7890SRichard Henderson         gen_helper_raise_exception(tcg_env, e->excp);
5626186e7890SRichard Henderson 
5627186e7890SRichard Henderson         e_next = e->next;
5628186e7890SRichard Henderson         g_free(e);
5629186e7890SRichard Henderson     }
5630fcf5ef2aSThomas Huth }
56316e61bc94SEmilio G. Cota 
56328eb806a7SRichard Henderson static void sparc_tr_disas_log(const DisasContextBase *dcbase,
56338eb806a7SRichard Henderson                                CPUState *cpu, FILE *logfile)
56346e61bc94SEmilio G. Cota {
56358eb806a7SRichard Henderson     fprintf(logfile, "IN: %s\n", lookup_symbol(dcbase->pc_first));
56368eb806a7SRichard Henderson     target_disas(logfile, cpu, dcbase->pc_first, dcbase->tb->size);
56376e61bc94SEmilio G. Cota }
56386e61bc94SEmilio G. Cota 
56396e61bc94SEmilio G. Cota static const TranslatorOps sparc_tr_ops = {
56406e61bc94SEmilio G. Cota     .init_disas_context = sparc_tr_init_disas_context,
56416e61bc94SEmilio G. Cota     .tb_start           = sparc_tr_tb_start,
56426e61bc94SEmilio G. Cota     .insn_start         = sparc_tr_insn_start,
56436e61bc94SEmilio G. Cota     .translate_insn     = sparc_tr_translate_insn,
56446e61bc94SEmilio G. Cota     .tb_stop            = sparc_tr_tb_stop,
56456e61bc94SEmilio G. Cota     .disas_log          = sparc_tr_disas_log,
56466e61bc94SEmilio G. Cota };
56476e61bc94SEmilio G. Cota 
5648597f9b2dSRichard Henderson void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int *max_insns,
5649306c8721SRichard Henderson                            target_ulong pc, void *host_pc)
56506e61bc94SEmilio G. Cota {
56516e61bc94SEmilio G. Cota     DisasContext dc = {};
56526e61bc94SEmilio G. Cota 
5653306c8721SRichard Henderson     translator_loop(cs, tb, max_insns, pc, host_pc, &sparc_tr_ops, &dc.base);
5654fcf5ef2aSThomas Huth }
5655fcf5ef2aSThomas Huth 
565655c3ceefSRichard Henderson void sparc_tcg_init(void)
5657fcf5ef2aSThomas Huth {
5658fcf5ef2aSThomas Huth     static const char gregnames[32][4] = {
5659fcf5ef2aSThomas Huth         "g0", "g1", "g2", "g3", "g4", "g5", "g6", "g7",
5660fcf5ef2aSThomas Huth         "o0", "o1", "o2", "o3", "o4", "o5", "o6", "o7",
5661fcf5ef2aSThomas Huth         "l0", "l1", "l2", "l3", "l4", "l5", "l6", "l7",
5662fcf5ef2aSThomas Huth         "i0", "i1", "i2", "i3", "i4", "i5", "i6", "i7",
5663fcf5ef2aSThomas Huth     };
5664fcf5ef2aSThomas Huth     static const char fregnames[32][4] = {
5665fcf5ef2aSThomas Huth         "f0", "f2", "f4", "f6", "f8", "f10", "f12", "f14",
5666fcf5ef2aSThomas Huth         "f16", "f18", "f20", "f22", "f24", "f26", "f28", "f30",
5667fcf5ef2aSThomas Huth         "f32", "f34", "f36", "f38", "f40", "f42", "f44", "f46",
5668fcf5ef2aSThomas Huth         "f48", "f50", "f52", "f54", "f56", "f58", "f60", "f62",
5669fcf5ef2aSThomas Huth     };
5670fcf5ef2aSThomas Huth 
5671fcf5ef2aSThomas Huth     static const struct { TCGv_i32 *ptr; int off; const char *name; } r32[] = {
5672fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
5673fcf5ef2aSThomas Huth         { &cpu_xcc, offsetof(CPUSPARCState, xcc), "xcc" },
5674fcf5ef2aSThomas Huth         { &cpu_fprs, offsetof(CPUSPARCState, fprs), "fprs" },
5675fcf5ef2aSThomas Huth #endif
5676fcf5ef2aSThomas Huth         { &cpu_cc_op, offsetof(CPUSPARCState, cc_op), "cc_op" },
5677fcf5ef2aSThomas Huth         { &cpu_psr, offsetof(CPUSPARCState, psr), "psr" },
5678fcf5ef2aSThomas Huth     };
5679fcf5ef2aSThomas Huth 
5680fcf5ef2aSThomas Huth     static const struct { TCGv *ptr; int off; const char *name; } rtl[] = {
5681fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
5682fcf5ef2aSThomas Huth         { &cpu_gsr, offsetof(CPUSPARCState, gsr), "gsr" },
5683fcf5ef2aSThomas Huth #endif
5684fcf5ef2aSThomas Huth         { &cpu_cond, offsetof(CPUSPARCState, cond), "cond" },
5685fcf5ef2aSThomas Huth         { &cpu_cc_src, offsetof(CPUSPARCState, cc_src), "cc_src" },
5686fcf5ef2aSThomas Huth         { &cpu_cc_src2, offsetof(CPUSPARCState, cc_src2), "cc_src2" },
5687fcf5ef2aSThomas Huth         { &cpu_cc_dst, offsetof(CPUSPARCState, cc_dst), "cc_dst" },
5688fcf5ef2aSThomas Huth         { &cpu_fsr, offsetof(CPUSPARCState, fsr), "fsr" },
5689fcf5ef2aSThomas Huth         { &cpu_pc, offsetof(CPUSPARCState, pc), "pc" },
5690fcf5ef2aSThomas Huth         { &cpu_npc, offsetof(CPUSPARCState, npc), "npc" },
5691fcf5ef2aSThomas Huth         { &cpu_y, offsetof(CPUSPARCState, y), "y" },
5692fcf5ef2aSThomas Huth         { &cpu_tbr, offsetof(CPUSPARCState, tbr), "tbr" },
5693fcf5ef2aSThomas Huth     };
5694fcf5ef2aSThomas Huth 
5695fcf5ef2aSThomas Huth     unsigned int i;
5696fcf5ef2aSThomas Huth 
5697ad75a51eSRichard Henderson     cpu_regwptr = tcg_global_mem_new_ptr(tcg_env,
5698fcf5ef2aSThomas Huth                                          offsetof(CPUSPARCState, regwptr),
5699fcf5ef2aSThomas Huth                                          "regwptr");
5700fcf5ef2aSThomas Huth 
5701fcf5ef2aSThomas Huth     for (i = 0; i < ARRAY_SIZE(r32); ++i) {
5702ad75a51eSRichard Henderson         *r32[i].ptr = tcg_global_mem_new_i32(tcg_env, r32[i].off, r32[i].name);
5703fcf5ef2aSThomas Huth     }
5704fcf5ef2aSThomas Huth 
5705fcf5ef2aSThomas Huth     for (i = 0; i < ARRAY_SIZE(rtl); ++i) {
5706ad75a51eSRichard Henderson         *rtl[i].ptr = tcg_global_mem_new(tcg_env, rtl[i].off, rtl[i].name);
5707fcf5ef2aSThomas Huth     }
5708fcf5ef2aSThomas Huth 
5709f764718dSRichard Henderson     cpu_regs[0] = NULL;
5710fcf5ef2aSThomas Huth     for (i = 1; i < 8; ++i) {
5711ad75a51eSRichard Henderson         cpu_regs[i] = tcg_global_mem_new(tcg_env,
5712fcf5ef2aSThomas Huth                                          offsetof(CPUSPARCState, gregs[i]),
5713fcf5ef2aSThomas Huth                                          gregnames[i]);
5714fcf5ef2aSThomas Huth     }
5715fcf5ef2aSThomas Huth 
5716fcf5ef2aSThomas Huth     for (i = 8; i < 32; ++i) {
5717fcf5ef2aSThomas Huth         cpu_regs[i] = tcg_global_mem_new(cpu_regwptr,
5718fcf5ef2aSThomas Huth                                          (i - 8) * sizeof(target_ulong),
5719fcf5ef2aSThomas Huth                                          gregnames[i]);
5720fcf5ef2aSThomas Huth     }
5721fcf5ef2aSThomas Huth 
5722fcf5ef2aSThomas Huth     for (i = 0; i < TARGET_DPREGS; i++) {
5723ad75a51eSRichard Henderson         cpu_fpr[i] = tcg_global_mem_new_i64(tcg_env,
5724fcf5ef2aSThomas Huth                                             offsetof(CPUSPARCState, fpr[i]),
5725fcf5ef2aSThomas Huth                                             fregnames[i]);
5726fcf5ef2aSThomas Huth     }
5727fcf5ef2aSThomas Huth }
5728fcf5ef2aSThomas Huth 
5729f36aaa53SRichard Henderson void sparc_restore_state_to_opc(CPUState *cs,
5730f36aaa53SRichard Henderson                                 const TranslationBlock *tb,
5731f36aaa53SRichard Henderson                                 const uint64_t *data)
5732fcf5ef2aSThomas Huth {
5733f36aaa53SRichard Henderson     SPARCCPU *cpu = SPARC_CPU(cs);
5734f36aaa53SRichard Henderson     CPUSPARCState *env = &cpu->env;
5735fcf5ef2aSThomas Huth     target_ulong pc = data[0];
5736fcf5ef2aSThomas Huth     target_ulong npc = data[1];
5737fcf5ef2aSThomas Huth 
5738fcf5ef2aSThomas Huth     env->pc = pc;
5739fcf5ef2aSThomas Huth     if (npc == DYNAMIC_PC) {
5740fcf5ef2aSThomas Huth         /* dynamic NPC: already stored */
5741fcf5ef2aSThomas Huth     } else if (npc & JUMP_PC) {
5742fcf5ef2aSThomas Huth         /* jump PC: use 'cond' and the jump targets of the translation */
5743fcf5ef2aSThomas Huth         if (env->cond) {
5744fcf5ef2aSThomas Huth             env->npc = npc & ~3;
5745fcf5ef2aSThomas Huth         } else {
5746fcf5ef2aSThomas Huth             env->npc = pc + 4;
5747fcf5ef2aSThomas Huth         }
5748fcf5ef2aSThomas Huth     } else {
5749fcf5ef2aSThomas Huth         env->npc = npc;
5750fcf5ef2aSThomas Huth     }
5751fcf5ef2aSThomas Huth }
5752