xref: /openbmc/qemu/target/sparc/translate.c (revision 7f10b52f7b238d4ef1a6e5d4740604e07631a6c4)
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()
66da681406SRichard Henderson # define FSR_LDXFSR_MASK                        0
67da681406SRichard Henderson # define FSR_LDXFSR_OLDMASK                     0
68668bb9b7SRichard Henderson # define MAXTL_MASK                             0
69af25071cSRichard Henderson #endif
70af25071cSRichard Henderson 
71633c4283SRichard Henderson /* Dynamic PC, must exit to main loop. */
72633c4283SRichard Henderson #define DYNAMIC_PC         1
73633c4283SRichard Henderson /* Dynamic PC, one of two values according to jump_pc[T2]. */
74633c4283SRichard Henderson #define JUMP_PC            2
75633c4283SRichard Henderson /* Dynamic PC, may lookup next TB. */
76633c4283SRichard Henderson #define DYNAMIC_PC_LOOKUP  3
77fcf5ef2aSThomas Huth 
7846bb0137SMark Cave-Ayland #define DISAS_EXIT  DISAS_TARGET_0
7946bb0137SMark Cave-Ayland 
80fcf5ef2aSThomas Huth /* global register indexes */
81fcf5ef2aSThomas Huth static TCGv_ptr cpu_regwptr;
82fcf5ef2aSThomas Huth static TCGv cpu_cc_src, cpu_cc_src2, cpu_cc_dst;
83fcf5ef2aSThomas Huth static TCGv_i32 cpu_cc_op;
84fcf5ef2aSThomas Huth static TCGv_i32 cpu_psr;
85fcf5ef2aSThomas Huth static TCGv cpu_fsr, cpu_pc, cpu_npc;
86fcf5ef2aSThomas Huth static TCGv cpu_regs[32];
87fcf5ef2aSThomas Huth static TCGv cpu_y;
88fcf5ef2aSThomas Huth static TCGv cpu_tbr;
89fcf5ef2aSThomas Huth static TCGv cpu_cond;
90fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
91fcf5ef2aSThomas Huth static TCGv_i32 cpu_xcc, cpu_fprs;
92fcf5ef2aSThomas Huth static TCGv cpu_gsr;
93fcf5ef2aSThomas Huth #else
94af25071cSRichard Henderson # define cpu_fprs               ({ qemu_build_not_reached(); (TCGv)NULL; })
95af25071cSRichard Henderson # define cpu_gsr                ({ qemu_build_not_reached(); (TCGv)NULL; })
96fcf5ef2aSThomas Huth #endif
97fcf5ef2aSThomas Huth /* Floating point registers */
98fcf5ef2aSThomas Huth static TCGv_i64 cpu_fpr[TARGET_DPREGS];
99fcf5ef2aSThomas Huth 
100af25071cSRichard Henderson #define env_field_offsetof(X)     offsetof(CPUSPARCState, X)
101af25071cSRichard Henderson #ifdef TARGET_SPARC64
102cd6269f7SRichard Henderson # define env32_field_offsetof(X)  ({ qemu_build_not_reached(); 0; })
103af25071cSRichard Henderson # define env64_field_offsetof(X)  env_field_offsetof(X)
104af25071cSRichard Henderson #else
105cd6269f7SRichard Henderson # define env32_field_offsetof(X)  env_field_offsetof(X)
106af25071cSRichard Henderson # define env64_field_offsetof(X)  ({ qemu_build_not_reached(); 0; })
107af25071cSRichard Henderson #endif
108af25071cSRichard Henderson 
109186e7890SRichard Henderson typedef struct DisasDelayException {
110186e7890SRichard Henderson     struct DisasDelayException *next;
111186e7890SRichard Henderson     TCGLabel *lab;
112186e7890SRichard Henderson     TCGv_i32 excp;
113186e7890SRichard Henderson     /* Saved state at parent insn. */
114186e7890SRichard Henderson     target_ulong pc;
115186e7890SRichard Henderson     target_ulong npc;
116186e7890SRichard Henderson } DisasDelayException;
117186e7890SRichard Henderson 
118fcf5ef2aSThomas Huth typedef struct DisasContext {
119af00be49SEmilio G. Cota     DisasContextBase base;
120fcf5ef2aSThomas Huth     target_ulong pc;    /* current Program Counter: integer or DYNAMIC_PC */
121fcf5ef2aSThomas Huth     target_ulong npc;   /* next PC: integer or DYNAMIC_PC or JUMP_PC */
122fcf5ef2aSThomas Huth     target_ulong jump_pc[2]; /* used when JUMP_PC pc value is used */
123fcf5ef2aSThomas Huth     int mem_idx;
124c9b459aaSArtyom Tarasenko     bool fpu_enabled;
125c9b459aaSArtyom Tarasenko     bool address_mask_32bit;
126c9b459aaSArtyom Tarasenko #ifndef CONFIG_USER_ONLY
127c9b459aaSArtyom Tarasenko     bool supervisor;
128c9b459aaSArtyom Tarasenko #ifdef TARGET_SPARC64
129c9b459aaSArtyom Tarasenko     bool hypervisor;
130c9b459aaSArtyom Tarasenko #endif
131c9b459aaSArtyom Tarasenko #endif
132c9b459aaSArtyom Tarasenko 
133fcf5ef2aSThomas Huth     uint32_t cc_op;  /* current CC operation */
134fcf5ef2aSThomas Huth     sparc_def_t *def;
135fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
136fcf5ef2aSThomas Huth     int fprs_dirty;
137fcf5ef2aSThomas Huth     int asi;
138fcf5ef2aSThomas Huth #endif
139186e7890SRichard Henderson     DisasDelayException *delay_excp_list;
140fcf5ef2aSThomas Huth } DisasContext;
141fcf5ef2aSThomas Huth 
142fcf5ef2aSThomas Huth typedef struct {
143fcf5ef2aSThomas Huth     TCGCond cond;
144fcf5ef2aSThomas Huth     bool is_bool;
145fcf5ef2aSThomas Huth     TCGv c1, c2;
146fcf5ef2aSThomas Huth } DisasCompare;
147fcf5ef2aSThomas Huth 
148fcf5ef2aSThomas Huth // This function uses non-native bit order
149fcf5ef2aSThomas Huth #define GET_FIELD(X, FROM, TO)                                  \
150fcf5ef2aSThomas Huth     ((X) >> (31 - (TO)) & ((1 << ((TO) - (FROM) + 1)) - 1))
151fcf5ef2aSThomas Huth 
152fcf5ef2aSThomas Huth // This function uses the order in the manuals, i.e. bit 0 is 2^0
153fcf5ef2aSThomas Huth #define GET_FIELD_SP(X, FROM, TO)               \
154fcf5ef2aSThomas Huth     GET_FIELD(X, 31 - (TO), 31 - (FROM))
155fcf5ef2aSThomas Huth 
156fcf5ef2aSThomas Huth #define GET_FIELDs(x,a,b) sign_extend (GET_FIELD(x,a,b), (b) - (a) + 1)
157fcf5ef2aSThomas Huth #define GET_FIELD_SPs(x,a,b) sign_extend (GET_FIELD_SP(x,a,b), ((b) - (a) + 1))
158fcf5ef2aSThomas Huth 
159fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
160fcf5ef2aSThomas Huth #define DFPREG(r) (((r & 1) << 5) | (r & 0x1e))
161fcf5ef2aSThomas Huth #define QFPREG(r) (((r & 1) << 5) | (r & 0x1c))
162fcf5ef2aSThomas Huth #else
163fcf5ef2aSThomas Huth #define DFPREG(r) (r & 0x1e)
164fcf5ef2aSThomas Huth #define QFPREG(r) (r & 0x1c)
165fcf5ef2aSThomas Huth #endif
166fcf5ef2aSThomas Huth 
167fcf5ef2aSThomas Huth #define UA2005_HTRAP_MASK 0xff
168fcf5ef2aSThomas Huth #define V8_TRAP_MASK 0x7f
169fcf5ef2aSThomas Huth 
170fcf5ef2aSThomas Huth #define IS_IMM (insn & (1<<13))
171fcf5ef2aSThomas Huth 
1720c2e96c1SRichard Henderson static void gen_update_fprs_dirty(DisasContext *dc, int rd)
173fcf5ef2aSThomas Huth {
174fcf5ef2aSThomas Huth #if defined(TARGET_SPARC64)
175fcf5ef2aSThomas Huth     int bit = (rd < 32) ? 1 : 2;
176fcf5ef2aSThomas Huth     /* If we know we've already set this bit within the TB,
177fcf5ef2aSThomas Huth        we can avoid setting it again.  */
178fcf5ef2aSThomas Huth     if (!(dc->fprs_dirty & bit)) {
179fcf5ef2aSThomas Huth         dc->fprs_dirty |= bit;
180fcf5ef2aSThomas Huth         tcg_gen_ori_i32(cpu_fprs, cpu_fprs, bit);
181fcf5ef2aSThomas Huth     }
182fcf5ef2aSThomas Huth #endif
183fcf5ef2aSThomas Huth }
184fcf5ef2aSThomas Huth 
185fcf5ef2aSThomas Huth /* floating point registers moves */
186fcf5ef2aSThomas Huth static TCGv_i32 gen_load_fpr_F(DisasContext *dc, unsigned int src)
187fcf5ef2aSThomas Huth {
18836ab4623SRichard Henderson     TCGv_i32 ret = tcg_temp_new_i32();
189dc41aa7dSRichard Henderson     if (src & 1) {
190dc41aa7dSRichard Henderson         tcg_gen_extrl_i64_i32(ret, cpu_fpr[src / 2]);
191dc41aa7dSRichard Henderson     } else {
192dc41aa7dSRichard Henderson         tcg_gen_extrh_i64_i32(ret, cpu_fpr[src / 2]);
193fcf5ef2aSThomas Huth     }
194dc41aa7dSRichard Henderson     return ret;
195fcf5ef2aSThomas Huth }
196fcf5ef2aSThomas Huth 
197fcf5ef2aSThomas Huth static void gen_store_fpr_F(DisasContext *dc, unsigned int dst, TCGv_i32 v)
198fcf5ef2aSThomas Huth {
1998e7bbc75SRichard Henderson     TCGv_i64 t = tcg_temp_new_i64();
2008e7bbc75SRichard Henderson 
2018e7bbc75SRichard Henderson     tcg_gen_extu_i32_i64(t, v);
202fcf5ef2aSThomas Huth     tcg_gen_deposit_i64(cpu_fpr[dst / 2], cpu_fpr[dst / 2], t,
203fcf5ef2aSThomas Huth                         (dst & 1 ? 0 : 32), 32);
204fcf5ef2aSThomas Huth     gen_update_fprs_dirty(dc, dst);
205fcf5ef2aSThomas Huth }
206fcf5ef2aSThomas Huth 
207fcf5ef2aSThomas Huth static TCGv_i32 gen_dest_fpr_F(DisasContext *dc)
208fcf5ef2aSThomas Huth {
20936ab4623SRichard Henderson     return tcg_temp_new_i32();
210fcf5ef2aSThomas Huth }
211fcf5ef2aSThomas Huth 
212fcf5ef2aSThomas Huth static TCGv_i64 gen_load_fpr_D(DisasContext *dc, unsigned int src)
213fcf5ef2aSThomas Huth {
214fcf5ef2aSThomas Huth     src = DFPREG(src);
215fcf5ef2aSThomas Huth     return cpu_fpr[src / 2];
216fcf5ef2aSThomas Huth }
217fcf5ef2aSThomas Huth 
218fcf5ef2aSThomas Huth static void gen_store_fpr_D(DisasContext *dc, unsigned int dst, TCGv_i64 v)
219fcf5ef2aSThomas Huth {
220fcf5ef2aSThomas Huth     dst = DFPREG(dst);
221fcf5ef2aSThomas Huth     tcg_gen_mov_i64(cpu_fpr[dst / 2], v);
222fcf5ef2aSThomas Huth     gen_update_fprs_dirty(dc, dst);
223fcf5ef2aSThomas Huth }
224fcf5ef2aSThomas Huth 
225fcf5ef2aSThomas Huth static TCGv_i64 gen_dest_fpr_D(DisasContext *dc, unsigned int dst)
226fcf5ef2aSThomas Huth {
227fcf5ef2aSThomas Huth     return cpu_fpr[DFPREG(dst) / 2];
228fcf5ef2aSThomas Huth }
229fcf5ef2aSThomas Huth 
230fcf5ef2aSThomas Huth static void gen_op_load_fpr_QT0(unsigned int src)
231fcf5ef2aSThomas Huth {
232ad75a51eSRichard Henderson     tcg_gen_st_i64(cpu_fpr[src / 2], tcg_env, offsetof(CPUSPARCState, qt0) +
233fcf5ef2aSThomas Huth                    offsetof(CPU_QuadU, ll.upper));
234ad75a51eSRichard Henderson     tcg_gen_st_i64(cpu_fpr[src/2 + 1], tcg_env, offsetof(CPUSPARCState, qt0) +
235fcf5ef2aSThomas Huth                    offsetof(CPU_QuadU, ll.lower));
236fcf5ef2aSThomas Huth }
237fcf5ef2aSThomas Huth 
238fcf5ef2aSThomas Huth static void gen_op_load_fpr_QT1(unsigned int src)
239fcf5ef2aSThomas Huth {
240ad75a51eSRichard Henderson     tcg_gen_st_i64(cpu_fpr[src / 2], tcg_env, offsetof(CPUSPARCState, qt1) +
241fcf5ef2aSThomas Huth                    offsetof(CPU_QuadU, ll.upper));
242ad75a51eSRichard Henderson     tcg_gen_st_i64(cpu_fpr[src/2 + 1], tcg_env, offsetof(CPUSPARCState, qt1) +
243fcf5ef2aSThomas Huth                    offsetof(CPU_QuadU, ll.lower));
244fcf5ef2aSThomas Huth }
245fcf5ef2aSThomas Huth 
246fcf5ef2aSThomas Huth static void gen_op_store_QT0_fpr(unsigned int dst)
247fcf5ef2aSThomas Huth {
248ad75a51eSRichard Henderson     tcg_gen_ld_i64(cpu_fpr[dst / 2], tcg_env, offsetof(CPUSPARCState, qt0) +
249fcf5ef2aSThomas Huth                    offsetof(CPU_QuadU, ll.upper));
250ad75a51eSRichard Henderson     tcg_gen_ld_i64(cpu_fpr[dst/2 + 1], tcg_env, offsetof(CPUSPARCState, qt0) +
251fcf5ef2aSThomas Huth                    offsetof(CPU_QuadU, ll.lower));
252fcf5ef2aSThomas Huth }
253fcf5ef2aSThomas Huth 
254fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
255fcf5ef2aSThomas Huth static void gen_move_Q(DisasContext *dc, unsigned int rd, unsigned int rs)
256fcf5ef2aSThomas Huth {
257fcf5ef2aSThomas Huth     rd = QFPREG(rd);
258fcf5ef2aSThomas Huth     rs = QFPREG(rs);
259fcf5ef2aSThomas Huth 
260fcf5ef2aSThomas Huth     tcg_gen_mov_i64(cpu_fpr[rd / 2], cpu_fpr[rs / 2]);
261fcf5ef2aSThomas Huth     tcg_gen_mov_i64(cpu_fpr[rd / 2 + 1], cpu_fpr[rs / 2 + 1]);
262fcf5ef2aSThomas Huth     gen_update_fprs_dirty(dc, rd);
263fcf5ef2aSThomas Huth }
264fcf5ef2aSThomas Huth #endif
265fcf5ef2aSThomas Huth 
266fcf5ef2aSThomas Huth /* moves */
267fcf5ef2aSThomas Huth #ifdef CONFIG_USER_ONLY
268fcf5ef2aSThomas Huth #define supervisor(dc) 0
269fcf5ef2aSThomas Huth #define hypervisor(dc) 0
270fcf5ef2aSThomas Huth #else
271fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
272c9b459aaSArtyom Tarasenko #define hypervisor(dc) (dc->hypervisor)
273c9b459aaSArtyom Tarasenko #define supervisor(dc) (dc->supervisor | dc->hypervisor)
274fcf5ef2aSThomas Huth #else
275c9b459aaSArtyom Tarasenko #define supervisor(dc) (dc->supervisor)
276668bb9b7SRichard Henderson #define hypervisor(dc) 0
277fcf5ef2aSThomas Huth #endif
278fcf5ef2aSThomas Huth #endif
279fcf5ef2aSThomas Huth 
280b1bc09eaSRichard Henderson #if !defined(TARGET_SPARC64)
281b1bc09eaSRichard Henderson # define AM_CHECK(dc)  false
282b1bc09eaSRichard Henderson #elif defined(TARGET_ABI32)
283b1bc09eaSRichard Henderson # define AM_CHECK(dc)  true
284b1bc09eaSRichard Henderson #elif defined(CONFIG_USER_ONLY)
285b1bc09eaSRichard Henderson # define AM_CHECK(dc)  false
286fcf5ef2aSThomas Huth #else
287b1bc09eaSRichard Henderson # define AM_CHECK(dc)  ((dc)->address_mask_32bit)
288fcf5ef2aSThomas Huth #endif
289fcf5ef2aSThomas Huth 
2900c2e96c1SRichard Henderson static void gen_address_mask(DisasContext *dc, TCGv addr)
291fcf5ef2aSThomas Huth {
292b1bc09eaSRichard Henderson     if (AM_CHECK(dc)) {
293fcf5ef2aSThomas Huth         tcg_gen_andi_tl(addr, addr, 0xffffffffULL);
294b1bc09eaSRichard Henderson     }
295fcf5ef2aSThomas Huth }
296fcf5ef2aSThomas Huth 
29723ada1b1SRichard Henderson static target_ulong address_mask_i(DisasContext *dc, target_ulong addr)
29823ada1b1SRichard Henderson {
29923ada1b1SRichard Henderson     return AM_CHECK(dc) ? (uint32_t)addr : addr;
30023ada1b1SRichard Henderson }
30123ada1b1SRichard Henderson 
3020c2e96c1SRichard Henderson static TCGv gen_load_gpr(DisasContext *dc, int reg)
303fcf5ef2aSThomas Huth {
304fcf5ef2aSThomas Huth     if (reg > 0) {
305fcf5ef2aSThomas Huth         assert(reg < 32);
306fcf5ef2aSThomas Huth         return cpu_regs[reg];
307fcf5ef2aSThomas Huth     } else {
30852123f14SRichard Henderson         TCGv t = tcg_temp_new();
309fcf5ef2aSThomas Huth         tcg_gen_movi_tl(t, 0);
310fcf5ef2aSThomas Huth         return t;
311fcf5ef2aSThomas Huth     }
312fcf5ef2aSThomas Huth }
313fcf5ef2aSThomas Huth 
3140c2e96c1SRichard Henderson static void gen_store_gpr(DisasContext *dc, int reg, TCGv v)
315fcf5ef2aSThomas Huth {
316fcf5ef2aSThomas Huth     if (reg > 0) {
317fcf5ef2aSThomas Huth         assert(reg < 32);
318fcf5ef2aSThomas Huth         tcg_gen_mov_tl(cpu_regs[reg], v);
319fcf5ef2aSThomas Huth     }
320fcf5ef2aSThomas Huth }
321fcf5ef2aSThomas Huth 
3220c2e96c1SRichard Henderson static TCGv gen_dest_gpr(DisasContext *dc, int reg)
323fcf5ef2aSThomas Huth {
324fcf5ef2aSThomas Huth     if (reg > 0) {
325fcf5ef2aSThomas Huth         assert(reg < 32);
326fcf5ef2aSThomas Huth         return cpu_regs[reg];
327fcf5ef2aSThomas Huth     } else {
32852123f14SRichard Henderson         return tcg_temp_new();
329fcf5ef2aSThomas Huth     }
330fcf5ef2aSThomas Huth }
331fcf5ef2aSThomas Huth 
3325645aa2eSRichard Henderson static bool use_goto_tb(DisasContext *s, target_ulong pc, target_ulong npc)
333fcf5ef2aSThomas Huth {
3345645aa2eSRichard Henderson     return translator_use_goto_tb(&s->base, pc) &&
3355645aa2eSRichard Henderson            translator_use_goto_tb(&s->base, npc);
336fcf5ef2aSThomas Huth }
337fcf5ef2aSThomas Huth 
3385645aa2eSRichard Henderson static void gen_goto_tb(DisasContext *s, int tb_num,
339fcf5ef2aSThomas Huth                         target_ulong pc, target_ulong npc)
340fcf5ef2aSThomas Huth {
341fcf5ef2aSThomas Huth     if (use_goto_tb(s, pc, npc))  {
342fcf5ef2aSThomas Huth         /* jump to same page: we can use a direct jump */
343fcf5ef2aSThomas Huth         tcg_gen_goto_tb(tb_num);
344fcf5ef2aSThomas Huth         tcg_gen_movi_tl(cpu_pc, pc);
345fcf5ef2aSThomas Huth         tcg_gen_movi_tl(cpu_npc, npc);
34607ea28b4SRichard Henderson         tcg_gen_exit_tb(s->base.tb, tb_num);
347fcf5ef2aSThomas Huth     } else {
348f67ccb2fSRichard Henderson         /* jump to another page: we can use an indirect jump */
349fcf5ef2aSThomas Huth         tcg_gen_movi_tl(cpu_pc, pc);
350fcf5ef2aSThomas Huth         tcg_gen_movi_tl(cpu_npc, npc);
351f67ccb2fSRichard Henderson         tcg_gen_lookup_and_goto_ptr();
352fcf5ef2aSThomas Huth     }
353fcf5ef2aSThomas Huth }
354fcf5ef2aSThomas Huth 
355fcf5ef2aSThomas Huth // XXX suboptimal
3560c2e96c1SRichard Henderson static void gen_mov_reg_N(TCGv reg, TCGv_i32 src)
357fcf5ef2aSThomas Huth {
358fcf5ef2aSThomas Huth     tcg_gen_extu_i32_tl(reg, src);
3590b1183e3SPhilippe Mathieu-Daudé     tcg_gen_extract_tl(reg, reg, PSR_NEG_SHIFT, 1);
360fcf5ef2aSThomas Huth }
361fcf5ef2aSThomas Huth 
3620c2e96c1SRichard Henderson static void gen_mov_reg_Z(TCGv reg, TCGv_i32 src)
363fcf5ef2aSThomas Huth {
364fcf5ef2aSThomas Huth     tcg_gen_extu_i32_tl(reg, src);
3650b1183e3SPhilippe Mathieu-Daudé     tcg_gen_extract_tl(reg, reg, PSR_ZERO_SHIFT, 1);
366fcf5ef2aSThomas Huth }
367fcf5ef2aSThomas Huth 
3680c2e96c1SRichard Henderson static void gen_mov_reg_V(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_OVF_SHIFT, 1);
372fcf5ef2aSThomas Huth }
373fcf5ef2aSThomas Huth 
3740c2e96c1SRichard Henderson static void gen_mov_reg_C(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_CARRY_SHIFT, 1);
378fcf5ef2aSThomas Huth }
379fcf5ef2aSThomas Huth 
3800c2e96c1SRichard Henderson static void gen_op_add_cc(TCGv dst, TCGv src1, TCGv src2)
381fcf5ef2aSThomas Huth {
382fcf5ef2aSThomas Huth     tcg_gen_mov_tl(cpu_cc_src, src1);
383fcf5ef2aSThomas Huth     tcg_gen_mov_tl(cpu_cc_src2, src2);
384fcf5ef2aSThomas Huth     tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
385fcf5ef2aSThomas Huth     tcg_gen_mov_tl(dst, cpu_cc_dst);
386fcf5ef2aSThomas Huth }
387fcf5ef2aSThomas Huth 
388fcf5ef2aSThomas Huth static TCGv_i32 gen_add32_carry32(void)
389fcf5ef2aSThomas Huth {
390fcf5ef2aSThomas Huth     TCGv_i32 carry_32, cc_src1_32, cc_src2_32;
391fcf5ef2aSThomas Huth 
392fcf5ef2aSThomas Huth     /* Carry is computed from a previous add: (dst < src)  */
393fcf5ef2aSThomas Huth #if TARGET_LONG_BITS == 64
394fcf5ef2aSThomas Huth     cc_src1_32 = tcg_temp_new_i32();
395fcf5ef2aSThomas Huth     cc_src2_32 = tcg_temp_new_i32();
396fcf5ef2aSThomas Huth     tcg_gen_extrl_i64_i32(cc_src1_32, cpu_cc_dst);
397fcf5ef2aSThomas Huth     tcg_gen_extrl_i64_i32(cc_src2_32, cpu_cc_src);
398fcf5ef2aSThomas Huth #else
399fcf5ef2aSThomas Huth     cc_src1_32 = cpu_cc_dst;
400fcf5ef2aSThomas Huth     cc_src2_32 = cpu_cc_src;
401fcf5ef2aSThomas Huth #endif
402fcf5ef2aSThomas Huth 
403fcf5ef2aSThomas Huth     carry_32 = tcg_temp_new_i32();
404fcf5ef2aSThomas Huth     tcg_gen_setcond_i32(TCG_COND_LTU, carry_32, cc_src1_32, cc_src2_32);
405fcf5ef2aSThomas Huth 
406fcf5ef2aSThomas Huth     return carry_32;
407fcf5ef2aSThomas Huth }
408fcf5ef2aSThomas Huth 
409fcf5ef2aSThomas Huth static TCGv_i32 gen_sub32_carry32(void)
410fcf5ef2aSThomas Huth {
411fcf5ef2aSThomas Huth     TCGv_i32 carry_32, cc_src1_32, cc_src2_32;
412fcf5ef2aSThomas Huth 
413fcf5ef2aSThomas Huth     /* Carry is computed from a previous borrow: (src1 < src2)  */
414fcf5ef2aSThomas Huth #if TARGET_LONG_BITS == 64
415fcf5ef2aSThomas Huth     cc_src1_32 = tcg_temp_new_i32();
416fcf5ef2aSThomas Huth     cc_src2_32 = tcg_temp_new_i32();
417fcf5ef2aSThomas Huth     tcg_gen_extrl_i64_i32(cc_src1_32, cpu_cc_src);
418fcf5ef2aSThomas Huth     tcg_gen_extrl_i64_i32(cc_src2_32, cpu_cc_src2);
419fcf5ef2aSThomas Huth #else
420fcf5ef2aSThomas Huth     cc_src1_32 = cpu_cc_src;
421fcf5ef2aSThomas Huth     cc_src2_32 = cpu_cc_src2;
422fcf5ef2aSThomas Huth #endif
423fcf5ef2aSThomas Huth 
424fcf5ef2aSThomas Huth     carry_32 = tcg_temp_new_i32();
425fcf5ef2aSThomas Huth     tcg_gen_setcond_i32(TCG_COND_LTU, carry_32, cc_src1_32, cc_src2_32);
426fcf5ef2aSThomas Huth 
427fcf5ef2aSThomas Huth     return carry_32;
428fcf5ef2aSThomas Huth }
429fcf5ef2aSThomas Huth 
430420a187dSRichard Henderson static void gen_op_addc_int(TCGv dst, TCGv src1, TCGv src2,
431420a187dSRichard Henderson                             TCGv_i32 carry_32, bool update_cc)
432fcf5ef2aSThomas Huth {
433fcf5ef2aSThomas Huth     tcg_gen_add_tl(dst, src1, src2);
434fcf5ef2aSThomas Huth 
435420a187dSRichard Henderson #ifdef TARGET_SPARC64
436420a187dSRichard Henderson     TCGv carry = tcg_temp_new();
437420a187dSRichard Henderson     tcg_gen_extu_i32_tl(carry, carry_32);
438420a187dSRichard Henderson     tcg_gen_add_tl(dst, dst, carry);
439fcf5ef2aSThomas Huth #else
440420a187dSRichard Henderson     tcg_gen_add_i32(dst, dst, carry_32);
441fcf5ef2aSThomas Huth #endif
442fcf5ef2aSThomas Huth 
443fcf5ef2aSThomas Huth     if (update_cc) {
444420a187dSRichard Henderson         tcg_debug_assert(dst == cpu_cc_dst);
445fcf5ef2aSThomas Huth         tcg_gen_mov_tl(cpu_cc_src, src1);
446fcf5ef2aSThomas Huth         tcg_gen_mov_tl(cpu_cc_src2, src2);
447fcf5ef2aSThomas Huth     }
448fcf5ef2aSThomas Huth }
449fcf5ef2aSThomas Huth 
450420a187dSRichard Henderson static void gen_op_addc_int_add(TCGv dst, TCGv src1, TCGv src2, bool update_cc)
451420a187dSRichard Henderson {
452420a187dSRichard Henderson     TCGv discard;
453420a187dSRichard Henderson 
454420a187dSRichard Henderson     if (TARGET_LONG_BITS == 64) {
455420a187dSRichard Henderson         gen_op_addc_int(dst, src1, src2, gen_add32_carry32(), update_cc);
456420a187dSRichard Henderson         return;
457420a187dSRichard Henderson     }
458420a187dSRichard Henderson 
459420a187dSRichard Henderson     /*
460420a187dSRichard Henderson      * We can re-use the host's hardware carry generation by using
461420a187dSRichard Henderson      * an ADD2 opcode.  We discard the low part of the output.
462420a187dSRichard Henderson      * Ideally we'd combine this operation with the add that
463420a187dSRichard Henderson      * generated the carry in the first place.
464420a187dSRichard Henderson      */
465420a187dSRichard Henderson     discard = tcg_temp_new();
466420a187dSRichard Henderson     tcg_gen_add2_tl(discard, dst, cpu_cc_src, src1, cpu_cc_src2, src2);
467420a187dSRichard Henderson 
468420a187dSRichard Henderson     if (update_cc) {
469420a187dSRichard Henderson         tcg_debug_assert(dst == cpu_cc_dst);
470420a187dSRichard Henderson         tcg_gen_mov_tl(cpu_cc_src, src1);
471420a187dSRichard Henderson         tcg_gen_mov_tl(cpu_cc_src2, src2);
472420a187dSRichard Henderson     }
473420a187dSRichard Henderson }
474420a187dSRichard Henderson 
475420a187dSRichard Henderson static void gen_op_addc_add(TCGv dst, TCGv src1, TCGv src2)
476420a187dSRichard Henderson {
477420a187dSRichard Henderson     gen_op_addc_int_add(dst, src1, src2, false);
478420a187dSRichard Henderson }
479420a187dSRichard Henderson 
480420a187dSRichard Henderson static void gen_op_addccc_add(TCGv dst, TCGv src1, TCGv src2)
481420a187dSRichard Henderson {
482420a187dSRichard Henderson     gen_op_addc_int_add(dst, src1, src2, true);
483420a187dSRichard Henderson }
484420a187dSRichard Henderson 
485420a187dSRichard Henderson static void gen_op_addc_sub(TCGv dst, TCGv src1, TCGv src2)
486420a187dSRichard Henderson {
487420a187dSRichard Henderson     gen_op_addc_int(dst, src1, src2, gen_sub32_carry32(), false);
488420a187dSRichard Henderson }
489420a187dSRichard Henderson 
490420a187dSRichard Henderson static void gen_op_addccc_sub(TCGv dst, TCGv src1, TCGv src2)
491420a187dSRichard Henderson {
492420a187dSRichard Henderson     gen_op_addc_int(dst, src1, src2, gen_sub32_carry32(), true);
493420a187dSRichard Henderson }
494420a187dSRichard Henderson 
495420a187dSRichard Henderson static void gen_op_addc_int_generic(TCGv dst, TCGv src1, TCGv src2,
496420a187dSRichard Henderson                                     bool update_cc)
497420a187dSRichard Henderson {
498420a187dSRichard Henderson     TCGv_i32 carry_32 = tcg_temp_new_i32();
499420a187dSRichard Henderson     gen_helper_compute_C_icc(carry_32, tcg_env);
500420a187dSRichard Henderson     gen_op_addc_int(dst, src1, src2, carry_32, update_cc);
501420a187dSRichard Henderson }
502420a187dSRichard Henderson 
503420a187dSRichard Henderson static void gen_op_addc_generic(TCGv dst, TCGv src1, TCGv src2)
504420a187dSRichard Henderson {
505420a187dSRichard Henderson     gen_op_addc_int_generic(dst, src1, src2, false);
506420a187dSRichard Henderson }
507420a187dSRichard Henderson 
508420a187dSRichard Henderson static void gen_op_addccc_generic(TCGv dst, TCGv src1, TCGv src2)
509420a187dSRichard Henderson {
510420a187dSRichard Henderson     gen_op_addc_int_generic(dst, src1, src2, true);
511420a187dSRichard Henderson }
512420a187dSRichard Henderson 
5130c2e96c1SRichard Henderson static void gen_op_sub_cc(TCGv dst, TCGv src1, TCGv src2)
514fcf5ef2aSThomas Huth {
515fcf5ef2aSThomas Huth     tcg_gen_mov_tl(cpu_cc_src, src1);
516fcf5ef2aSThomas Huth     tcg_gen_mov_tl(cpu_cc_src2, src2);
517fcf5ef2aSThomas Huth     tcg_gen_sub_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
518fcf5ef2aSThomas Huth     tcg_gen_mov_tl(dst, cpu_cc_dst);
519fcf5ef2aSThomas Huth }
520fcf5ef2aSThomas Huth 
521dfebb950SRichard Henderson static void gen_op_subc_int(TCGv dst, TCGv src1, TCGv src2,
522dfebb950SRichard Henderson                             TCGv_i32 carry_32, bool update_cc)
523fcf5ef2aSThomas Huth {
524fcf5ef2aSThomas Huth     TCGv carry;
525fcf5ef2aSThomas Huth 
526fcf5ef2aSThomas Huth #if TARGET_LONG_BITS == 64
527fcf5ef2aSThomas Huth     carry = tcg_temp_new();
528fcf5ef2aSThomas Huth     tcg_gen_extu_i32_i64(carry, carry_32);
529fcf5ef2aSThomas Huth #else
530fcf5ef2aSThomas Huth     carry = carry_32;
531fcf5ef2aSThomas Huth #endif
532fcf5ef2aSThomas Huth 
533fcf5ef2aSThomas Huth     tcg_gen_sub_tl(dst, src1, src2);
534fcf5ef2aSThomas Huth     tcg_gen_sub_tl(dst, dst, carry);
535fcf5ef2aSThomas Huth 
536fcf5ef2aSThomas Huth     if (update_cc) {
537dfebb950SRichard Henderson         tcg_debug_assert(dst == cpu_cc_dst);
538fcf5ef2aSThomas Huth         tcg_gen_mov_tl(cpu_cc_src, src1);
539fcf5ef2aSThomas Huth         tcg_gen_mov_tl(cpu_cc_src2, src2);
540fcf5ef2aSThomas Huth     }
541fcf5ef2aSThomas Huth }
542fcf5ef2aSThomas Huth 
543dfebb950SRichard Henderson static void gen_op_subc_add(TCGv dst, TCGv src1, TCGv src2)
544dfebb950SRichard Henderson {
545dfebb950SRichard Henderson     gen_op_subc_int(dst, src1, src2, gen_add32_carry32(), false);
546dfebb950SRichard Henderson }
547dfebb950SRichard Henderson 
548dfebb950SRichard Henderson static void gen_op_subccc_add(TCGv dst, TCGv src1, TCGv src2)
549dfebb950SRichard Henderson {
550dfebb950SRichard Henderson     gen_op_subc_int(dst, src1, src2, gen_add32_carry32(), true);
551dfebb950SRichard Henderson }
552dfebb950SRichard Henderson 
553dfebb950SRichard Henderson static void gen_op_subc_int_sub(TCGv dst, TCGv src1, TCGv src2, bool update_cc)
554dfebb950SRichard Henderson {
555dfebb950SRichard Henderson     TCGv discard;
556dfebb950SRichard Henderson 
557dfebb950SRichard Henderson     if (TARGET_LONG_BITS == 64) {
558dfebb950SRichard Henderson         gen_op_subc_int(dst, src1, src2, gen_sub32_carry32(), update_cc);
559dfebb950SRichard Henderson         return;
560dfebb950SRichard Henderson     }
561dfebb950SRichard Henderson 
562dfebb950SRichard Henderson     /*
563dfebb950SRichard Henderson      * We can re-use the host's hardware carry generation by using
564dfebb950SRichard Henderson      * a SUB2 opcode.  We discard the low part of the output.
565dfebb950SRichard Henderson      */
566dfebb950SRichard Henderson     discard = tcg_temp_new();
567dfebb950SRichard Henderson     tcg_gen_sub2_tl(discard, dst, cpu_cc_src, src1, cpu_cc_src2, src2);
568dfebb950SRichard Henderson 
569dfebb950SRichard Henderson     if (update_cc) {
570dfebb950SRichard Henderson         tcg_debug_assert(dst == cpu_cc_dst);
571dfebb950SRichard Henderson         tcg_gen_mov_tl(cpu_cc_src, src1);
572dfebb950SRichard Henderson         tcg_gen_mov_tl(cpu_cc_src2, src2);
573dfebb950SRichard Henderson     }
574dfebb950SRichard Henderson }
575dfebb950SRichard Henderson 
576dfebb950SRichard Henderson static void gen_op_subc_sub(TCGv dst, TCGv src1, TCGv src2)
577dfebb950SRichard Henderson {
578dfebb950SRichard Henderson     gen_op_subc_int_sub(dst, src1, src2, false);
579dfebb950SRichard Henderson }
580dfebb950SRichard Henderson 
581dfebb950SRichard Henderson static void gen_op_subccc_sub(TCGv dst, TCGv src1, TCGv src2)
582dfebb950SRichard Henderson {
583dfebb950SRichard Henderson     gen_op_subc_int_sub(dst, src1, src2, true);
584dfebb950SRichard Henderson }
585dfebb950SRichard Henderson 
586dfebb950SRichard Henderson static void gen_op_subc_int_generic(TCGv dst, TCGv src1, TCGv src2,
587dfebb950SRichard Henderson                                     bool update_cc)
588dfebb950SRichard Henderson {
589dfebb950SRichard Henderson     TCGv_i32 carry_32 = tcg_temp_new_i32();
590dfebb950SRichard Henderson 
591dfebb950SRichard Henderson     gen_helper_compute_C_icc(carry_32, tcg_env);
592dfebb950SRichard Henderson     gen_op_subc_int(dst, src1, src2, carry_32, update_cc);
593dfebb950SRichard Henderson }
594dfebb950SRichard Henderson 
595dfebb950SRichard Henderson static void gen_op_subc_generic(TCGv dst, TCGv src1, TCGv src2)
596dfebb950SRichard Henderson {
597dfebb950SRichard Henderson     gen_op_subc_int_generic(dst, src1, src2, false);
598dfebb950SRichard Henderson }
599dfebb950SRichard Henderson 
600dfebb950SRichard Henderson static void gen_op_subccc_generic(TCGv dst, TCGv src1, TCGv src2)
601dfebb950SRichard Henderson {
602dfebb950SRichard Henderson     gen_op_subc_int_generic(dst, src1, src2, true);
603dfebb950SRichard Henderson }
604dfebb950SRichard Henderson 
6050c2e96c1SRichard Henderson static void gen_op_mulscc(TCGv dst, TCGv src1, TCGv src2)
606fcf5ef2aSThomas Huth {
607fcf5ef2aSThomas Huth     TCGv r_temp, zero, t0;
608fcf5ef2aSThomas Huth 
609fcf5ef2aSThomas Huth     r_temp = tcg_temp_new();
610fcf5ef2aSThomas Huth     t0 = tcg_temp_new();
611fcf5ef2aSThomas Huth 
612fcf5ef2aSThomas Huth     /* old op:
613fcf5ef2aSThomas Huth     if (!(env->y & 1))
614fcf5ef2aSThomas Huth         T1 = 0;
615fcf5ef2aSThomas Huth     */
61600ab7e61SRichard Henderson     zero = tcg_constant_tl(0);
617fcf5ef2aSThomas Huth     tcg_gen_andi_tl(cpu_cc_src, src1, 0xffffffff);
618fcf5ef2aSThomas Huth     tcg_gen_andi_tl(r_temp, cpu_y, 0x1);
619fcf5ef2aSThomas Huth     tcg_gen_andi_tl(cpu_cc_src2, src2, 0xffffffff);
620fcf5ef2aSThomas Huth     tcg_gen_movcond_tl(TCG_COND_EQ, cpu_cc_src2, r_temp, zero,
621fcf5ef2aSThomas Huth                        zero, cpu_cc_src2);
622fcf5ef2aSThomas Huth 
623fcf5ef2aSThomas Huth     // b2 = T0 & 1;
624fcf5ef2aSThomas Huth     // env->y = (b2 << 31) | (env->y >> 1);
6250b1183e3SPhilippe Mathieu-Daudé     tcg_gen_extract_tl(t0, cpu_y, 1, 31);
62608d64e0dSPhilippe Mathieu-Daudé     tcg_gen_deposit_tl(cpu_y, t0, cpu_cc_src, 31, 1);
627fcf5ef2aSThomas Huth 
628fcf5ef2aSThomas Huth     // b1 = N ^ V;
629fcf5ef2aSThomas Huth     gen_mov_reg_N(t0, cpu_psr);
630fcf5ef2aSThomas Huth     gen_mov_reg_V(r_temp, cpu_psr);
631fcf5ef2aSThomas Huth     tcg_gen_xor_tl(t0, t0, r_temp);
632fcf5ef2aSThomas Huth 
633fcf5ef2aSThomas Huth     // T0 = (b1 << 31) | (T0 >> 1);
634fcf5ef2aSThomas Huth     // src1 = T0;
635fcf5ef2aSThomas Huth     tcg_gen_shli_tl(t0, t0, 31);
636fcf5ef2aSThomas Huth     tcg_gen_shri_tl(cpu_cc_src, cpu_cc_src, 1);
637fcf5ef2aSThomas Huth     tcg_gen_or_tl(cpu_cc_src, cpu_cc_src, t0);
638fcf5ef2aSThomas Huth 
639fcf5ef2aSThomas Huth     tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
640fcf5ef2aSThomas Huth 
641fcf5ef2aSThomas Huth     tcg_gen_mov_tl(dst, cpu_cc_dst);
642fcf5ef2aSThomas Huth }
643fcf5ef2aSThomas Huth 
6440c2e96c1SRichard Henderson static void gen_op_multiply(TCGv dst, TCGv src1, TCGv src2, int sign_ext)
645fcf5ef2aSThomas Huth {
646fcf5ef2aSThomas Huth #if TARGET_LONG_BITS == 32
647fcf5ef2aSThomas Huth     if (sign_ext) {
648fcf5ef2aSThomas Huth         tcg_gen_muls2_tl(dst, cpu_y, src1, src2);
649fcf5ef2aSThomas Huth     } else {
650fcf5ef2aSThomas Huth         tcg_gen_mulu2_tl(dst, cpu_y, src1, src2);
651fcf5ef2aSThomas Huth     }
652fcf5ef2aSThomas Huth #else
653fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new_i64();
654fcf5ef2aSThomas Huth     TCGv t1 = tcg_temp_new_i64();
655fcf5ef2aSThomas Huth 
656fcf5ef2aSThomas Huth     if (sign_ext) {
657fcf5ef2aSThomas Huth         tcg_gen_ext32s_i64(t0, src1);
658fcf5ef2aSThomas Huth         tcg_gen_ext32s_i64(t1, src2);
659fcf5ef2aSThomas Huth     } else {
660fcf5ef2aSThomas Huth         tcg_gen_ext32u_i64(t0, src1);
661fcf5ef2aSThomas Huth         tcg_gen_ext32u_i64(t1, src2);
662fcf5ef2aSThomas Huth     }
663fcf5ef2aSThomas Huth 
664fcf5ef2aSThomas Huth     tcg_gen_mul_i64(dst, t0, t1);
665fcf5ef2aSThomas Huth     tcg_gen_shri_i64(cpu_y, dst, 32);
666fcf5ef2aSThomas Huth #endif
667fcf5ef2aSThomas Huth }
668fcf5ef2aSThomas Huth 
6690c2e96c1SRichard Henderson static void gen_op_umul(TCGv dst, TCGv src1, TCGv src2)
670fcf5ef2aSThomas Huth {
671fcf5ef2aSThomas Huth     /* zero-extend truncated operands before multiplication */
672fcf5ef2aSThomas Huth     gen_op_multiply(dst, src1, src2, 0);
673fcf5ef2aSThomas Huth }
674fcf5ef2aSThomas Huth 
6750c2e96c1SRichard Henderson static void gen_op_smul(TCGv dst, TCGv src1, TCGv src2)
676fcf5ef2aSThomas Huth {
677fcf5ef2aSThomas Huth     /* sign-extend truncated operands before multiplication */
678fcf5ef2aSThomas Huth     gen_op_multiply(dst, src1, src2, 1);
679fcf5ef2aSThomas Huth }
680fcf5ef2aSThomas Huth 
6814ee85ea9SRichard Henderson static void gen_op_udivx(TCGv dst, TCGv src1, TCGv src2)
6824ee85ea9SRichard Henderson {
6834ee85ea9SRichard Henderson     gen_helper_udivx(dst, tcg_env, src1, src2);
6844ee85ea9SRichard Henderson }
6854ee85ea9SRichard Henderson 
6864ee85ea9SRichard Henderson static void gen_op_sdivx(TCGv dst, TCGv src1, TCGv src2)
6874ee85ea9SRichard Henderson {
6884ee85ea9SRichard Henderson     gen_helper_sdivx(dst, tcg_env, src1, src2);
6894ee85ea9SRichard Henderson }
6904ee85ea9SRichard Henderson 
691c2636853SRichard Henderson static void gen_op_udiv(TCGv dst, TCGv src1, TCGv src2)
692c2636853SRichard Henderson {
693c2636853SRichard Henderson     gen_helper_udiv(dst, tcg_env, src1, src2);
694c2636853SRichard Henderson }
695c2636853SRichard Henderson 
696c2636853SRichard Henderson static void gen_op_sdiv(TCGv dst, TCGv src1, TCGv src2)
697c2636853SRichard Henderson {
698c2636853SRichard Henderson     gen_helper_sdiv(dst, tcg_env, src1, src2);
699c2636853SRichard Henderson }
700c2636853SRichard Henderson 
701c2636853SRichard Henderson static void gen_op_udivcc(TCGv dst, TCGv src1, TCGv src2)
702c2636853SRichard Henderson {
703c2636853SRichard Henderson     gen_helper_udiv_cc(dst, tcg_env, src1, src2);
704c2636853SRichard Henderson }
705c2636853SRichard Henderson 
706c2636853SRichard Henderson static void gen_op_sdivcc(TCGv dst, TCGv src1, TCGv src2)
707c2636853SRichard Henderson {
708c2636853SRichard Henderson     gen_helper_sdiv_cc(dst, tcg_env, src1, src2);
709c2636853SRichard Henderson }
710c2636853SRichard Henderson 
711a9aba13dSRichard Henderson static void gen_op_taddcctv(TCGv dst, TCGv src1, TCGv src2)
712a9aba13dSRichard Henderson {
713a9aba13dSRichard Henderson     gen_helper_taddcctv(dst, tcg_env, src1, src2);
714a9aba13dSRichard Henderson }
715a9aba13dSRichard Henderson 
716a9aba13dSRichard Henderson static void gen_op_tsubcctv(TCGv dst, TCGv src1, TCGv src2)
717a9aba13dSRichard Henderson {
718a9aba13dSRichard Henderson     gen_helper_tsubcctv(dst, tcg_env, src1, src2);
719a9aba13dSRichard Henderson }
720a9aba13dSRichard Henderson 
7219c6ec5bcSRichard Henderson static void gen_op_popc(TCGv dst, TCGv src1, TCGv src2)
7229c6ec5bcSRichard Henderson {
7239c6ec5bcSRichard Henderson     tcg_gen_ctpop_tl(dst, src2);
7249c6ec5bcSRichard Henderson }
7259c6ec5bcSRichard Henderson 
72645bfed3bSRichard Henderson #ifndef TARGET_SPARC64
72745bfed3bSRichard Henderson static void gen_helper_array8(TCGv dst, TCGv src1, TCGv src2)
72845bfed3bSRichard Henderson {
72945bfed3bSRichard Henderson     g_assert_not_reached();
73045bfed3bSRichard Henderson }
73145bfed3bSRichard Henderson #endif
73245bfed3bSRichard Henderson 
73345bfed3bSRichard Henderson static void gen_op_array16(TCGv dst, TCGv src1, TCGv src2)
73445bfed3bSRichard Henderson {
73545bfed3bSRichard Henderson     gen_helper_array8(dst, src1, src2);
73645bfed3bSRichard Henderson     tcg_gen_shli_tl(dst, dst, 1);
73745bfed3bSRichard Henderson }
73845bfed3bSRichard Henderson 
73945bfed3bSRichard Henderson static void gen_op_array32(TCGv dst, TCGv src1, TCGv src2)
74045bfed3bSRichard Henderson {
74145bfed3bSRichard Henderson     gen_helper_array8(dst, src1, src2);
74245bfed3bSRichard Henderson     tcg_gen_shli_tl(dst, dst, 2);
74345bfed3bSRichard Henderson }
74445bfed3bSRichard Henderson 
745fcf5ef2aSThomas Huth // 1
7460c2e96c1SRichard Henderson static void gen_op_eval_ba(TCGv dst)
747fcf5ef2aSThomas Huth {
748fcf5ef2aSThomas Huth     tcg_gen_movi_tl(dst, 1);
749fcf5ef2aSThomas Huth }
750fcf5ef2aSThomas Huth 
751fcf5ef2aSThomas Huth // Z
7520c2e96c1SRichard Henderson static void gen_op_eval_be(TCGv dst, TCGv_i32 src)
753fcf5ef2aSThomas Huth {
754fcf5ef2aSThomas Huth     gen_mov_reg_Z(dst, src);
755fcf5ef2aSThomas Huth }
756fcf5ef2aSThomas Huth 
757fcf5ef2aSThomas Huth // Z | (N ^ V)
7580c2e96c1SRichard Henderson static void gen_op_eval_ble(TCGv dst, TCGv_i32 src)
759fcf5ef2aSThomas Huth {
760fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
761fcf5ef2aSThomas Huth     gen_mov_reg_N(t0, src);
762fcf5ef2aSThomas Huth     gen_mov_reg_V(dst, src);
763fcf5ef2aSThomas Huth     tcg_gen_xor_tl(dst, dst, t0);
764fcf5ef2aSThomas Huth     gen_mov_reg_Z(t0, src);
765fcf5ef2aSThomas Huth     tcg_gen_or_tl(dst, dst, t0);
766fcf5ef2aSThomas Huth }
767fcf5ef2aSThomas Huth 
768fcf5ef2aSThomas Huth // N ^ V
7690c2e96c1SRichard Henderson static void gen_op_eval_bl(TCGv dst, TCGv_i32 src)
770fcf5ef2aSThomas Huth {
771fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
772fcf5ef2aSThomas Huth     gen_mov_reg_V(t0, src);
773fcf5ef2aSThomas Huth     gen_mov_reg_N(dst, src);
774fcf5ef2aSThomas Huth     tcg_gen_xor_tl(dst, dst, t0);
775fcf5ef2aSThomas Huth }
776fcf5ef2aSThomas Huth 
777fcf5ef2aSThomas Huth // C | Z
7780c2e96c1SRichard Henderson static void gen_op_eval_bleu(TCGv dst, TCGv_i32 src)
779fcf5ef2aSThomas Huth {
780fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
781fcf5ef2aSThomas Huth     gen_mov_reg_Z(t0, src);
782fcf5ef2aSThomas Huth     gen_mov_reg_C(dst, src);
783fcf5ef2aSThomas Huth     tcg_gen_or_tl(dst, dst, t0);
784fcf5ef2aSThomas Huth }
785fcf5ef2aSThomas Huth 
786fcf5ef2aSThomas Huth // C
7870c2e96c1SRichard Henderson static void gen_op_eval_bcs(TCGv dst, TCGv_i32 src)
788fcf5ef2aSThomas Huth {
789fcf5ef2aSThomas Huth     gen_mov_reg_C(dst, src);
790fcf5ef2aSThomas Huth }
791fcf5ef2aSThomas Huth 
792fcf5ef2aSThomas Huth // V
7930c2e96c1SRichard Henderson static void gen_op_eval_bvs(TCGv dst, TCGv_i32 src)
794fcf5ef2aSThomas Huth {
795fcf5ef2aSThomas Huth     gen_mov_reg_V(dst, src);
796fcf5ef2aSThomas Huth }
797fcf5ef2aSThomas Huth 
798fcf5ef2aSThomas Huth // 0
7990c2e96c1SRichard Henderson static void gen_op_eval_bn(TCGv dst)
800fcf5ef2aSThomas Huth {
801fcf5ef2aSThomas Huth     tcg_gen_movi_tl(dst, 0);
802fcf5ef2aSThomas Huth }
803fcf5ef2aSThomas Huth 
804fcf5ef2aSThomas Huth // N
8050c2e96c1SRichard Henderson static void gen_op_eval_bneg(TCGv dst, TCGv_i32 src)
806fcf5ef2aSThomas Huth {
807fcf5ef2aSThomas Huth     gen_mov_reg_N(dst, src);
808fcf5ef2aSThomas Huth }
809fcf5ef2aSThomas Huth 
810fcf5ef2aSThomas Huth // !Z
8110c2e96c1SRichard Henderson static void gen_op_eval_bne(TCGv dst, TCGv_i32 src)
812fcf5ef2aSThomas Huth {
813fcf5ef2aSThomas Huth     gen_mov_reg_Z(dst, src);
814fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
815fcf5ef2aSThomas Huth }
816fcf5ef2aSThomas Huth 
817fcf5ef2aSThomas Huth // !(Z | (N ^ V))
8180c2e96c1SRichard Henderson static void gen_op_eval_bg(TCGv dst, TCGv_i32 src)
819fcf5ef2aSThomas Huth {
820fcf5ef2aSThomas Huth     gen_op_eval_ble(dst, src);
821fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
822fcf5ef2aSThomas Huth }
823fcf5ef2aSThomas Huth 
824fcf5ef2aSThomas Huth // !(N ^ V)
8250c2e96c1SRichard Henderson static void gen_op_eval_bge(TCGv dst, TCGv_i32 src)
826fcf5ef2aSThomas Huth {
827fcf5ef2aSThomas Huth     gen_op_eval_bl(dst, src);
828fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
829fcf5ef2aSThomas Huth }
830fcf5ef2aSThomas Huth 
831fcf5ef2aSThomas Huth // !(C | Z)
8320c2e96c1SRichard Henderson static void gen_op_eval_bgu(TCGv dst, TCGv_i32 src)
833fcf5ef2aSThomas Huth {
834fcf5ef2aSThomas Huth     gen_op_eval_bleu(dst, src);
835fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
836fcf5ef2aSThomas Huth }
837fcf5ef2aSThomas Huth 
838fcf5ef2aSThomas Huth // !C
8390c2e96c1SRichard Henderson static void gen_op_eval_bcc(TCGv dst, TCGv_i32 src)
840fcf5ef2aSThomas Huth {
841fcf5ef2aSThomas Huth     gen_mov_reg_C(dst, src);
842fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
843fcf5ef2aSThomas Huth }
844fcf5ef2aSThomas Huth 
845fcf5ef2aSThomas Huth // !N
8460c2e96c1SRichard Henderson static void gen_op_eval_bpos(TCGv dst, TCGv_i32 src)
847fcf5ef2aSThomas Huth {
848fcf5ef2aSThomas Huth     gen_mov_reg_N(dst, src);
849fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
850fcf5ef2aSThomas Huth }
851fcf5ef2aSThomas Huth 
852fcf5ef2aSThomas Huth // !V
8530c2e96c1SRichard Henderson static void gen_op_eval_bvc(TCGv dst, TCGv_i32 src)
854fcf5ef2aSThomas Huth {
855fcf5ef2aSThomas Huth     gen_mov_reg_V(dst, src);
856fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
857fcf5ef2aSThomas Huth }
858fcf5ef2aSThomas Huth 
859fcf5ef2aSThomas Huth /*
860fcf5ef2aSThomas Huth   FPSR bit field FCC1 | FCC0:
861fcf5ef2aSThomas Huth    0 =
862fcf5ef2aSThomas Huth    1 <
863fcf5ef2aSThomas Huth    2 >
864fcf5ef2aSThomas Huth    3 unordered
865fcf5ef2aSThomas Huth */
8660c2e96c1SRichard Henderson static void gen_mov_reg_FCC0(TCGv reg, TCGv src,
867fcf5ef2aSThomas Huth                                     unsigned int fcc_offset)
868fcf5ef2aSThomas Huth {
869fcf5ef2aSThomas Huth     tcg_gen_shri_tl(reg, src, FSR_FCC0_SHIFT + fcc_offset);
870fcf5ef2aSThomas Huth     tcg_gen_andi_tl(reg, reg, 0x1);
871fcf5ef2aSThomas Huth }
872fcf5ef2aSThomas Huth 
8730c2e96c1SRichard Henderson static void gen_mov_reg_FCC1(TCGv reg, TCGv src, unsigned int fcc_offset)
874fcf5ef2aSThomas Huth {
875fcf5ef2aSThomas Huth     tcg_gen_shri_tl(reg, src, FSR_FCC1_SHIFT + fcc_offset);
876fcf5ef2aSThomas Huth     tcg_gen_andi_tl(reg, reg, 0x1);
877fcf5ef2aSThomas Huth }
878fcf5ef2aSThomas Huth 
879fcf5ef2aSThomas Huth // !0: FCC0 | FCC1
8800c2e96c1SRichard Henderson static void gen_op_eval_fbne(TCGv dst, TCGv src, unsigned int fcc_offset)
881fcf5ef2aSThomas Huth {
882fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
883fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
884fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(t0, src, fcc_offset);
885fcf5ef2aSThomas Huth     tcg_gen_or_tl(dst, dst, t0);
886fcf5ef2aSThomas Huth }
887fcf5ef2aSThomas Huth 
888fcf5ef2aSThomas Huth // 1 or 2: FCC0 ^ FCC1
8890c2e96c1SRichard Henderson static void gen_op_eval_fblg(TCGv dst, TCGv src, unsigned int fcc_offset)
890fcf5ef2aSThomas Huth {
891fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
892fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
893fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(t0, src, fcc_offset);
894fcf5ef2aSThomas Huth     tcg_gen_xor_tl(dst, dst, t0);
895fcf5ef2aSThomas Huth }
896fcf5ef2aSThomas Huth 
897fcf5ef2aSThomas Huth // 1 or 3: FCC0
8980c2e96c1SRichard Henderson static void gen_op_eval_fbul(TCGv dst, TCGv src, unsigned int fcc_offset)
899fcf5ef2aSThomas Huth {
900fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
901fcf5ef2aSThomas Huth }
902fcf5ef2aSThomas Huth 
903fcf5ef2aSThomas Huth // 1: FCC0 & !FCC1
9040c2e96c1SRichard Henderson static void gen_op_eval_fbl(TCGv dst, TCGv src, unsigned int fcc_offset)
905fcf5ef2aSThomas Huth {
906fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
907fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
908fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(t0, src, fcc_offset);
909fcf5ef2aSThomas Huth     tcg_gen_andc_tl(dst, dst, t0);
910fcf5ef2aSThomas Huth }
911fcf5ef2aSThomas Huth 
912fcf5ef2aSThomas Huth // 2 or 3: FCC1
9130c2e96c1SRichard Henderson static void gen_op_eval_fbug(TCGv dst, TCGv src, unsigned int fcc_offset)
914fcf5ef2aSThomas Huth {
915fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(dst, src, fcc_offset);
916fcf5ef2aSThomas Huth }
917fcf5ef2aSThomas Huth 
918fcf5ef2aSThomas Huth // 2: !FCC0 & FCC1
9190c2e96c1SRichard Henderson static void gen_op_eval_fbg(TCGv dst, TCGv src, unsigned int fcc_offset)
920fcf5ef2aSThomas Huth {
921fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
922fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
923fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(t0, src, fcc_offset);
924fcf5ef2aSThomas Huth     tcg_gen_andc_tl(dst, t0, dst);
925fcf5ef2aSThomas Huth }
926fcf5ef2aSThomas Huth 
927fcf5ef2aSThomas Huth // 3: FCC0 & FCC1
9280c2e96c1SRichard Henderson static void gen_op_eval_fbu(TCGv dst, TCGv src, unsigned int fcc_offset)
929fcf5ef2aSThomas Huth {
930fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
931fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
932fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(t0, src, fcc_offset);
933fcf5ef2aSThomas Huth     tcg_gen_and_tl(dst, dst, t0);
934fcf5ef2aSThomas Huth }
935fcf5ef2aSThomas Huth 
936fcf5ef2aSThomas Huth // 0: !(FCC0 | FCC1)
9370c2e96c1SRichard Henderson static void gen_op_eval_fbe(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     tcg_gen_xori_tl(dst, dst, 0x1);
944fcf5ef2aSThomas Huth }
945fcf5ef2aSThomas Huth 
946fcf5ef2aSThomas Huth // 0 or 3: !(FCC0 ^ FCC1)
9470c2e96c1SRichard Henderson static void gen_op_eval_fbue(TCGv dst, TCGv src, unsigned int fcc_offset)
948fcf5ef2aSThomas Huth {
949fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
950fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
951fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(t0, src, fcc_offset);
952fcf5ef2aSThomas Huth     tcg_gen_xor_tl(dst, dst, t0);
953fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
954fcf5ef2aSThomas Huth }
955fcf5ef2aSThomas Huth 
956fcf5ef2aSThomas Huth // 0 or 2: !FCC0
9570c2e96c1SRichard Henderson static void gen_op_eval_fbge(TCGv dst, TCGv src, unsigned int fcc_offset)
958fcf5ef2aSThomas Huth {
959fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
960fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
961fcf5ef2aSThomas Huth }
962fcf5ef2aSThomas Huth 
963fcf5ef2aSThomas Huth // !1: !(FCC0 & !FCC1)
9640c2e96c1SRichard Henderson static void gen_op_eval_fbuge(TCGv dst, TCGv src, unsigned int fcc_offset)
965fcf5ef2aSThomas Huth {
966fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
967fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
968fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(t0, src, fcc_offset);
969fcf5ef2aSThomas Huth     tcg_gen_andc_tl(dst, dst, t0);
970fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
971fcf5ef2aSThomas Huth }
972fcf5ef2aSThomas Huth 
973fcf5ef2aSThomas Huth // 0 or 1: !FCC1
9740c2e96c1SRichard Henderson static void gen_op_eval_fble(TCGv dst, TCGv src, unsigned int fcc_offset)
975fcf5ef2aSThomas Huth {
976fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(dst, src, fcc_offset);
977fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
978fcf5ef2aSThomas Huth }
979fcf5ef2aSThomas Huth 
980fcf5ef2aSThomas Huth // !2: !(!FCC0 & FCC1)
9810c2e96c1SRichard Henderson static void gen_op_eval_fbule(TCGv dst, TCGv src, unsigned int fcc_offset)
982fcf5ef2aSThomas Huth {
983fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
984fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
985fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(t0, src, fcc_offset);
986fcf5ef2aSThomas Huth     tcg_gen_andc_tl(dst, t0, dst);
987fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
988fcf5ef2aSThomas Huth }
989fcf5ef2aSThomas Huth 
990fcf5ef2aSThomas Huth // !3: !(FCC0 & FCC1)
9910c2e96c1SRichard Henderson static void gen_op_eval_fbo(TCGv dst, TCGv src, unsigned int fcc_offset)
992fcf5ef2aSThomas Huth {
993fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
994fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
995fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(t0, src, fcc_offset);
996fcf5ef2aSThomas Huth     tcg_gen_and_tl(dst, dst, t0);
997fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
998fcf5ef2aSThomas Huth }
999fcf5ef2aSThomas Huth 
10000c2e96c1SRichard Henderson static void gen_branch2(DisasContext *dc, target_ulong pc1,
1001fcf5ef2aSThomas Huth                         target_ulong pc2, TCGv r_cond)
1002fcf5ef2aSThomas Huth {
1003fcf5ef2aSThomas Huth     TCGLabel *l1 = gen_new_label();
1004fcf5ef2aSThomas Huth 
1005fcf5ef2aSThomas Huth     tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, 0, l1);
1006fcf5ef2aSThomas Huth 
1007fcf5ef2aSThomas Huth     gen_goto_tb(dc, 0, pc1, pc1 + 4);
1008fcf5ef2aSThomas Huth 
1009fcf5ef2aSThomas Huth     gen_set_label(l1);
1010fcf5ef2aSThomas Huth     gen_goto_tb(dc, 1, pc2, pc2 + 4);
1011fcf5ef2aSThomas Huth }
1012fcf5ef2aSThomas Huth 
10130c2e96c1SRichard Henderson static void gen_generic_branch(DisasContext *dc)
1014fcf5ef2aSThomas Huth {
101500ab7e61SRichard Henderson     TCGv npc0 = tcg_constant_tl(dc->jump_pc[0]);
101600ab7e61SRichard Henderson     TCGv npc1 = tcg_constant_tl(dc->jump_pc[1]);
101700ab7e61SRichard Henderson     TCGv zero = tcg_constant_tl(0);
1018fcf5ef2aSThomas Huth 
1019fcf5ef2aSThomas Huth     tcg_gen_movcond_tl(TCG_COND_NE, cpu_npc, cpu_cond, zero, npc0, npc1);
1020fcf5ef2aSThomas Huth }
1021fcf5ef2aSThomas Huth 
1022fcf5ef2aSThomas Huth /* call this function before using the condition register as it may
1023fcf5ef2aSThomas Huth    have been set for a jump */
10240c2e96c1SRichard Henderson static void flush_cond(DisasContext *dc)
1025fcf5ef2aSThomas Huth {
1026fcf5ef2aSThomas Huth     if (dc->npc == JUMP_PC) {
1027fcf5ef2aSThomas Huth         gen_generic_branch(dc);
102899c82c47SRichard Henderson         dc->npc = DYNAMIC_PC_LOOKUP;
1029fcf5ef2aSThomas Huth     }
1030fcf5ef2aSThomas Huth }
1031fcf5ef2aSThomas Huth 
10320c2e96c1SRichard Henderson static void save_npc(DisasContext *dc)
1033fcf5ef2aSThomas Huth {
1034633c4283SRichard Henderson     if (dc->npc & 3) {
1035633c4283SRichard Henderson         switch (dc->npc) {
1036633c4283SRichard Henderson         case JUMP_PC:
1037fcf5ef2aSThomas Huth             gen_generic_branch(dc);
103899c82c47SRichard Henderson             dc->npc = DYNAMIC_PC_LOOKUP;
1039633c4283SRichard Henderson             break;
1040633c4283SRichard Henderson         case DYNAMIC_PC:
1041633c4283SRichard Henderson         case DYNAMIC_PC_LOOKUP:
1042633c4283SRichard Henderson             break;
1043633c4283SRichard Henderson         default:
1044633c4283SRichard Henderson             g_assert_not_reached();
1045633c4283SRichard Henderson         }
1046633c4283SRichard Henderson     } else {
1047fcf5ef2aSThomas Huth         tcg_gen_movi_tl(cpu_npc, dc->npc);
1048fcf5ef2aSThomas Huth     }
1049fcf5ef2aSThomas Huth }
1050fcf5ef2aSThomas Huth 
10510c2e96c1SRichard Henderson static void update_psr(DisasContext *dc)
1052fcf5ef2aSThomas Huth {
1053fcf5ef2aSThomas Huth     if (dc->cc_op != CC_OP_FLAGS) {
1054fcf5ef2aSThomas Huth         dc->cc_op = CC_OP_FLAGS;
1055ad75a51eSRichard Henderson         gen_helper_compute_psr(tcg_env);
1056fcf5ef2aSThomas Huth     }
1057fcf5ef2aSThomas Huth }
1058fcf5ef2aSThomas Huth 
10590c2e96c1SRichard Henderson static void save_state(DisasContext *dc)
1060fcf5ef2aSThomas Huth {
1061fcf5ef2aSThomas Huth     tcg_gen_movi_tl(cpu_pc, dc->pc);
1062fcf5ef2aSThomas Huth     save_npc(dc);
1063fcf5ef2aSThomas Huth }
1064fcf5ef2aSThomas Huth 
1065fcf5ef2aSThomas Huth static void gen_exception(DisasContext *dc, int which)
1066fcf5ef2aSThomas Huth {
1067fcf5ef2aSThomas Huth     save_state(dc);
1068ad75a51eSRichard Henderson     gen_helper_raise_exception(tcg_env, tcg_constant_i32(which));
1069af00be49SEmilio G. Cota     dc->base.is_jmp = DISAS_NORETURN;
1070fcf5ef2aSThomas Huth }
1071fcf5ef2aSThomas Huth 
1072186e7890SRichard Henderson static TCGLabel *delay_exceptionv(DisasContext *dc, TCGv_i32 excp)
1073fcf5ef2aSThomas Huth {
1074186e7890SRichard Henderson     DisasDelayException *e = g_new0(DisasDelayException, 1);
1075186e7890SRichard Henderson 
1076186e7890SRichard Henderson     e->next = dc->delay_excp_list;
1077186e7890SRichard Henderson     dc->delay_excp_list = e;
1078186e7890SRichard Henderson 
1079186e7890SRichard Henderson     e->lab = gen_new_label();
1080186e7890SRichard Henderson     e->excp = excp;
1081186e7890SRichard Henderson     e->pc = dc->pc;
1082186e7890SRichard Henderson     /* Caller must have used flush_cond before branch. */
1083186e7890SRichard Henderson     assert(e->npc != JUMP_PC);
1084186e7890SRichard Henderson     e->npc = dc->npc;
1085186e7890SRichard Henderson 
1086186e7890SRichard Henderson     return e->lab;
1087186e7890SRichard Henderson }
1088186e7890SRichard Henderson 
1089186e7890SRichard Henderson static TCGLabel *delay_exception(DisasContext *dc, int excp)
1090186e7890SRichard Henderson {
1091186e7890SRichard Henderson     return delay_exceptionv(dc, tcg_constant_i32(excp));
1092186e7890SRichard Henderson }
1093186e7890SRichard Henderson 
1094186e7890SRichard Henderson static void gen_check_align(DisasContext *dc, TCGv addr, int mask)
1095186e7890SRichard Henderson {
1096186e7890SRichard Henderson     TCGv t = tcg_temp_new();
1097186e7890SRichard Henderson     TCGLabel *lab;
1098186e7890SRichard Henderson 
1099186e7890SRichard Henderson     tcg_gen_andi_tl(t, addr, mask);
1100186e7890SRichard Henderson 
1101186e7890SRichard Henderson     flush_cond(dc);
1102186e7890SRichard Henderson     lab = delay_exception(dc, TT_UNALIGNED);
1103186e7890SRichard Henderson     tcg_gen_brcondi_tl(TCG_COND_NE, t, 0, lab);
1104fcf5ef2aSThomas Huth }
1105fcf5ef2aSThomas Huth 
11060c2e96c1SRichard Henderson static void gen_mov_pc_npc(DisasContext *dc)
1107fcf5ef2aSThomas Huth {
1108633c4283SRichard Henderson     if (dc->npc & 3) {
1109633c4283SRichard Henderson         switch (dc->npc) {
1110633c4283SRichard Henderson         case JUMP_PC:
1111fcf5ef2aSThomas Huth             gen_generic_branch(dc);
1112fcf5ef2aSThomas Huth             tcg_gen_mov_tl(cpu_pc, cpu_npc);
111399c82c47SRichard Henderson             dc->pc = DYNAMIC_PC_LOOKUP;
1114633c4283SRichard Henderson             break;
1115633c4283SRichard Henderson         case DYNAMIC_PC:
1116633c4283SRichard Henderson         case DYNAMIC_PC_LOOKUP:
1117fcf5ef2aSThomas Huth             tcg_gen_mov_tl(cpu_pc, cpu_npc);
1118633c4283SRichard Henderson             dc->pc = dc->npc;
1119633c4283SRichard Henderson             break;
1120633c4283SRichard Henderson         default:
1121633c4283SRichard Henderson             g_assert_not_reached();
1122633c4283SRichard Henderson         }
1123fcf5ef2aSThomas Huth     } else {
1124fcf5ef2aSThomas Huth         dc->pc = dc->npc;
1125fcf5ef2aSThomas Huth     }
1126fcf5ef2aSThomas Huth }
1127fcf5ef2aSThomas Huth 
11280c2e96c1SRichard Henderson static void gen_op_next_insn(void)
1129fcf5ef2aSThomas Huth {
1130fcf5ef2aSThomas Huth     tcg_gen_mov_tl(cpu_pc, cpu_npc);
1131fcf5ef2aSThomas Huth     tcg_gen_addi_tl(cpu_npc, cpu_npc, 4);
1132fcf5ef2aSThomas Huth }
1133fcf5ef2aSThomas Huth 
1134fcf5ef2aSThomas Huth static void gen_compare(DisasCompare *cmp, bool xcc, unsigned int cond,
1135fcf5ef2aSThomas Huth                         DisasContext *dc)
1136fcf5ef2aSThomas Huth {
1137fcf5ef2aSThomas Huth     static int subcc_cond[16] = {
1138fcf5ef2aSThomas Huth         TCG_COND_NEVER,
1139fcf5ef2aSThomas Huth         TCG_COND_EQ,
1140fcf5ef2aSThomas Huth         TCG_COND_LE,
1141fcf5ef2aSThomas Huth         TCG_COND_LT,
1142fcf5ef2aSThomas Huth         TCG_COND_LEU,
1143fcf5ef2aSThomas Huth         TCG_COND_LTU,
1144fcf5ef2aSThomas Huth         -1, /* neg */
1145fcf5ef2aSThomas Huth         -1, /* overflow */
1146fcf5ef2aSThomas Huth         TCG_COND_ALWAYS,
1147fcf5ef2aSThomas Huth         TCG_COND_NE,
1148fcf5ef2aSThomas Huth         TCG_COND_GT,
1149fcf5ef2aSThomas Huth         TCG_COND_GE,
1150fcf5ef2aSThomas Huth         TCG_COND_GTU,
1151fcf5ef2aSThomas Huth         TCG_COND_GEU,
1152fcf5ef2aSThomas Huth         -1, /* pos */
1153fcf5ef2aSThomas Huth         -1, /* no overflow */
1154fcf5ef2aSThomas Huth     };
1155fcf5ef2aSThomas Huth 
1156fcf5ef2aSThomas Huth     static int logic_cond[16] = {
1157fcf5ef2aSThomas Huth         TCG_COND_NEVER,
1158fcf5ef2aSThomas Huth         TCG_COND_EQ,     /* eq:  Z */
1159fcf5ef2aSThomas Huth         TCG_COND_LE,     /* le:  Z | (N ^ V) -> Z | N */
1160fcf5ef2aSThomas Huth         TCG_COND_LT,     /* lt:  N ^ V -> N */
1161fcf5ef2aSThomas Huth         TCG_COND_EQ,     /* leu: C | Z -> Z */
1162fcf5ef2aSThomas Huth         TCG_COND_NEVER,  /* ltu: C -> 0 */
1163fcf5ef2aSThomas Huth         TCG_COND_LT,     /* neg: N */
1164fcf5ef2aSThomas Huth         TCG_COND_NEVER,  /* vs:  V -> 0 */
1165fcf5ef2aSThomas Huth         TCG_COND_ALWAYS,
1166fcf5ef2aSThomas Huth         TCG_COND_NE,     /* ne:  !Z */
1167fcf5ef2aSThomas Huth         TCG_COND_GT,     /* gt:  !(Z | (N ^ V)) -> !(Z | N) */
1168fcf5ef2aSThomas Huth         TCG_COND_GE,     /* ge:  !(N ^ V) -> !N */
1169fcf5ef2aSThomas Huth         TCG_COND_NE,     /* gtu: !(C | Z) -> !Z */
1170fcf5ef2aSThomas Huth         TCG_COND_ALWAYS, /* geu: !C -> 1 */
1171fcf5ef2aSThomas Huth         TCG_COND_GE,     /* pos: !N */
1172fcf5ef2aSThomas Huth         TCG_COND_ALWAYS, /* vc:  !V -> 1 */
1173fcf5ef2aSThomas Huth     };
1174fcf5ef2aSThomas Huth 
1175fcf5ef2aSThomas Huth     TCGv_i32 r_src;
1176fcf5ef2aSThomas Huth     TCGv r_dst;
1177fcf5ef2aSThomas Huth 
1178fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
1179fcf5ef2aSThomas Huth     if (xcc) {
1180fcf5ef2aSThomas Huth         r_src = cpu_xcc;
1181fcf5ef2aSThomas Huth     } else {
1182fcf5ef2aSThomas Huth         r_src = cpu_psr;
1183fcf5ef2aSThomas Huth     }
1184fcf5ef2aSThomas Huth #else
1185fcf5ef2aSThomas Huth     r_src = cpu_psr;
1186fcf5ef2aSThomas Huth #endif
1187fcf5ef2aSThomas Huth 
1188fcf5ef2aSThomas Huth     switch (dc->cc_op) {
1189fcf5ef2aSThomas Huth     case CC_OP_LOGIC:
1190fcf5ef2aSThomas Huth         cmp->cond = logic_cond[cond];
1191fcf5ef2aSThomas Huth     do_compare_dst_0:
1192fcf5ef2aSThomas Huth         cmp->is_bool = false;
119300ab7e61SRichard Henderson         cmp->c2 = tcg_constant_tl(0);
1194fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
1195fcf5ef2aSThomas Huth         if (!xcc) {
1196fcf5ef2aSThomas Huth             cmp->c1 = tcg_temp_new();
1197fcf5ef2aSThomas Huth             tcg_gen_ext32s_tl(cmp->c1, cpu_cc_dst);
1198fcf5ef2aSThomas Huth             break;
1199fcf5ef2aSThomas Huth         }
1200fcf5ef2aSThomas Huth #endif
1201fcf5ef2aSThomas Huth         cmp->c1 = cpu_cc_dst;
1202fcf5ef2aSThomas Huth         break;
1203fcf5ef2aSThomas Huth 
1204fcf5ef2aSThomas Huth     case CC_OP_SUB:
1205fcf5ef2aSThomas Huth         switch (cond) {
1206fcf5ef2aSThomas Huth         case 6:  /* neg */
1207fcf5ef2aSThomas Huth         case 14: /* pos */
1208fcf5ef2aSThomas Huth             cmp->cond = (cond == 6 ? TCG_COND_LT : TCG_COND_GE);
1209fcf5ef2aSThomas Huth             goto do_compare_dst_0;
1210fcf5ef2aSThomas Huth 
1211fcf5ef2aSThomas Huth         case 7: /* overflow */
1212fcf5ef2aSThomas Huth         case 15: /* !overflow */
1213fcf5ef2aSThomas Huth             goto do_dynamic;
1214fcf5ef2aSThomas Huth 
1215fcf5ef2aSThomas Huth         default:
1216fcf5ef2aSThomas Huth             cmp->cond = subcc_cond[cond];
1217fcf5ef2aSThomas Huth             cmp->is_bool = false;
1218fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
1219fcf5ef2aSThomas Huth             if (!xcc) {
1220fcf5ef2aSThomas Huth                 /* Note that sign-extension works for unsigned compares as
1221fcf5ef2aSThomas Huth                    long as both operands are sign-extended.  */
1222fcf5ef2aSThomas Huth                 cmp->c1 = tcg_temp_new();
1223fcf5ef2aSThomas Huth                 cmp->c2 = tcg_temp_new();
1224fcf5ef2aSThomas Huth                 tcg_gen_ext32s_tl(cmp->c1, cpu_cc_src);
1225fcf5ef2aSThomas Huth                 tcg_gen_ext32s_tl(cmp->c2, cpu_cc_src2);
1226fcf5ef2aSThomas Huth                 break;
1227fcf5ef2aSThomas Huth             }
1228fcf5ef2aSThomas Huth #endif
1229fcf5ef2aSThomas Huth             cmp->c1 = cpu_cc_src;
1230fcf5ef2aSThomas Huth             cmp->c2 = cpu_cc_src2;
1231fcf5ef2aSThomas Huth             break;
1232fcf5ef2aSThomas Huth         }
1233fcf5ef2aSThomas Huth         break;
1234fcf5ef2aSThomas Huth 
1235fcf5ef2aSThomas Huth     default:
1236fcf5ef2aSThomas Huth     do_dynamic:
1237ad75a51eSRichard Henderson         gen_helper_compute_psr(tcg_env);
1238fcf5ef2aSThomas Huth         dc->cc_op = CC_OP_FLAGS;
1239fcf5ef2aSThomas Huth         /* FALLTHRU */
1240fcf5ef2aSThomas Huth 
1241fcf5ef2aSThomas Huth     case CC_OP_FLAGS:
1242fcf5ef2aSThomas Huth         /* We're going to generate a boolean result.  */
1243fcf5ef2aSThomas Huth         cmp->cond = TCG_COND_NE;
1244fcf5ef2aSThomas Huth         cmp->is_bool = true;
1245fcf5ef2aSThomas Huth         cmp->c1 = r_dst = tcg_temp_new();
124600ab7e61SRichard Henderson         cmp->c2 = tcg_constant_tl(0);
1247fcf5ef2aSThomas Huth 
1248fcf5ef2aSThomas Huth         switch (cond) {
1249fcf5ef2aSThomas Huth         case 0x0:
1250fcf5ef2aSThomas Huth             gen_op_eval_bn(r_dst);
1251fcf5ef2aSThomas Huth             break;
1252fcf5ef2aSThomas Huth         case 0x1:
1253fcf5ef2aSThomas Huth             gen_op_eval_be(r_dst, r_src);
1254fcf5ef2aSThomas Huth             break;
1255fcf5ef2aSThomas Huth         case 0x2:
1256fcf5ef2aSThomas Huth             gen_op_eval_ble(r_dst, r_src);
1257fcf5ef2aSThomas Huth             break;
1258fcf5ef2aSThomas Huth         case 0x3:
1259fcf5ef2aSThomas Huth             gen_op_eval_bl(r_dst, r_src);
1260fcf5ef2aSThomas Huth             break;
1261fcf5ef2aSThomas Huth         case 0x4:
1262fcf5ef2aSThomas Huth             gen_op_eval_bleu(r_dst, r_src);
1263fcf5ef2aSThomas Huth             break;
1264fcf5ef2aSThomas Huth         case 0x5:
1265fcf5ef2aSThomas Huth             gen_op_eval_bcs(r_dst, r_src);
1266fcf5ef2aSThomas Huth             break;
1267fcf5ef2aSThomas Huth         case 0x6:
1268fcf5ef2aSThomas Huth             gen_op_eval_bneg(r_dst, r_src);
1269fcf5ef2aSThomas Huth             break;
1270fcf5ef2aSThomas Huth         case 0x7:
1271fcf5ef2aSThomas Huth             gen_op_eval_bvs(r_dst, r_src);
1272fcf5ef2aSThomas Huth             break;
1273fcf5ef2aSThomas Huth         case 0x8:
1274fcf5ef2aSThomas Huth             gen_op_eval_ba(r_dst);
1275fcf5ef2aSThomas Huth             break;
1276fcf5ef2aSThomas Huth         case 0x9:
1277fcf5ef2aSThomas Huth             gen_op_eval_bne(r_dst, r_src);
1278fcf5ef2aSThomas Huth             break;
1279fcf5ef2aSThomas Huth         case 0xa:
1280fcf5ef2aSThomas Huth             gen_op_eval_bg(r_dst, r_src);
1281fcf5ef2aSThomas Huth             break;
1282fcf5ef2aSThomas Huth         case 0xb:
1283fcf5ef2aSThomas Huth             gen_op_eval_bge(r_dst, r_src);
1284fcf5ef2aSThomas Huth             break;
1285fcf5ef2aSThomas Huth         case 0xc:
1286fcf5ef2aSThomas Huth             gen_op_eval_bgu(r_dst, r_src);
1287fcf5ef2aSThomas Huth             break;
1288fcf5ef2aSThomas Huth         case 0xd:
1289fcf5ef2aSThomas Huth             gen_op_eval_bcc(r_dst, r_src);
1290fcf5ef2aSThomas Huth             break;
1291fcf5ef2aSThomas Huth         case 0xe:
1292fcf5ef2aSThomas Huth             gen_op_eval_bpos(r_dst, r_src);
1293fcf5ef2aSThomas Huth             break;
1294fcf5ef2aSThomas Huth         case 0xf:
1295fcf5ef2aSThomas Huth             gen_op_eval_bvc(r_dst, r_src);
1296fcf5ef2aSThomas Huth             break;
1297fcf5ef2aSThomas Huth         }
1298fcf5ef2aSThomas Huth         break;
1299fcf5ef2aSThomas Huth     }
1300fcf5ef2aSThomas Huth }
1301fcf5ef2aSThomas Huth 
1302fcf5ef2aSThomas Huth static void gen_fcompare(DisasCompare *cmp, unsigned int cc, unsigned int cond)
1303fcf5ef2aSThomas Huth {
1304fcf5ef2aSThomas Huth     unsigned int offset;
1305fcf5ef2aSThomas Huth     TCGv r_dst;
1306fcf5ef2aSThomas Huth 
1307fcf5ef2aSThomas Huth     /* For now we still generate a straight boolean result.  */
1308fcf5ef2aSThomas Huth     cmp->cond = TCG_COND_NE;
1309fcf5ef2aSThomas Huth     cmp->is_bool = true;
1310fcf5ef2aSThomas Huth     cmp->c1 = r_dst = tcg_temp_new();
131100ab7e61SRichard Henderson     cmp->c2 = tcg_constant_tl(0);
1312fcf5ef2aSThomas Huth 
1313fcf5ef2aSThomas Huth     switch (cc) {
1314fcf5ef2aSThomas Huth     default:
1315fcf5ef2aSThomas Huth     case 0x0:
1316fcf5ef2aSThomas Huth         offset = 0;
1317fcf5ef2aSThomas Huth         break;
1318fcf5ef2aSThomas Huth     case 0x1:
1319fcf5ef2aSThomas Huth         offset = 32 - 10;
1320fcf5ef2aSThomas Huth         break;
1321fcf5ef2aSThomas Huth     case 0x2:
1322fcf5ef2aSThomas Huth         offset = 34 - 10;
1323fcf5ef2aSThomas Huth         break;
1324fcf5ef2aSThomas Huth     case 0x3:
1325fcf5ef2aSThomas Huth         offset = 36 - 10;
1326fcf5ef2aSThomas Huth         break;
1327fcf5ef2aSThomas Huth     }
1328fcf5ef2aSThomas Huth 
1329fcf5ef2aSThomas Huth     switch (cond) {
1330fcf5ef2aSThomas Huth     case 0x0:
1331fcf5ef2aSThomas Huth         gen_op_eval_bn(r_dst);
1332fcf5ef2aSThomas Huth         break;
1333fcf5ef2aSThomas Huth     case 0x1:
1334fcf5ef2aSThomas Huth         gen_op_eval_fbne(r_dst, cpu_fsr, offset);
1335fcf5ef2aSThomas Huth         break;
1336fcf5ef2aSThomas Huth     case 0x2:
1337fcf5ef2aSThomas Huth         gen_op_eval_fblg(r_dst, cpu_fsr, offset);
1338fcf5ef2aSThomas Huth         break;
1339fcf5ef2aSThomas Huth     case 0x3:
1340fcf5ef2aSThomas Huth         gen_op_eval_fbul(r_dst, cpu_fsr, offset);
1341fcf5ef2aSThomas Huth         break;
1342fcf5ef2aSThomas Huth     case 0x4:
1343fcf5ef2aSThomas Huth         gen_op_eval_fbl(r_dst, cpu_fsr, offset);
1344fcf5ef2aSThomas Huth         break;
1345fcf5ef2aSThomas Huth     case 0x5:
1346fcf5ef2aSThomas Huth         gen_op_eval_fbug(r_dst, cpu_fsr, offset);
1347fcf5ef2aSThomas Huth         break;
1348fcf5ef2aSThomas Huth     case 0x6:
1349fcf5ef2aSThomas Huth         gen_op_eval_fbg(r_dst, cpu_fsr, offset);
1350fcf5ef2aSThomas Huth         break;
1351fcf5ef2aSThomas Huth     case 0x7:
1352fcf5ef2aSThomas Huth         gen_op_eval_fbu(r_dst, cpu_fsr, offset);
1353fcf5ef2aSThomas Huth         break;
1354fcf5ef2aSThomas Huth     case 0x8:
1355fcf5ef2aSThomas Huth         gen_op_eval_ba(r_dst);
1356fcf5ef2aSThomas Huth         break;
1357fcf5ef2aSThomas Huth     case 0x9:
1358fcf5ef2aSThomas Huth         gen_op_eval_fbe(r_dst, cpu_fsr, offset);
1359fcf5ef2aSThomas Huth         break;
1360fcf5ef2aSThomas Huth     case 0xa:
1361fcf5ef2aSThomas Huth         gen_op_eval_fbue(r_dst, cpu_fsr, offset);
1362fcf5ef2aSThomas Huth         break;
1363fcf5ef2aSThomas Huth     case 0xb:
1364fcf5ef2aSThomas Huth         gen_op_eval_fbge(r_dst, cpu_fsr, offset);
1365fcf5ef2aSThomas Huth         break;
1366fcf5ef2aSThomas Huth     case 0xc:
1367fcf5ef2aSThomas Huth         gen_op_eval_fbuge(r_dst, cpu_fsr, offset);
1368fcf5ef2aSThomas Huth         break;
1369fcf5ef2aSThomas Huth     case 0xd:
1370fcf5ef2aSThomas Huth         gen_op_eval_fble(r_dst, cpu_fsr, offset);
1371fcf5ef2aSThomas Huth         break;
1372fcf5ef2aSThomas Huth     case 0xe:
1373fcf5ef2aSThomas Huth         gen_op_eval_fbule(r_dst, cpu_fsr, offset);
1374fcf5ef2aSThomas Huth         break;
1375fcf5ef2aSThomas Huth     case 0xf:
1376fcf5ef2aSThomas Huth         gen_op_eval_fbo(r_dst, cpu_fsr, offset);
1377fcf5ef2aSThomas Huth         break;
1378fcf5ef2aSThomas Huth     }
1379fcf5ef2aSThomas Huth }
1380fcf5ef2aSThomas Huth 
1381fcf5ef2aSThomas Huth // Inverted logic
1382ab9ffe98SRichard Henderson static const TCGCond gen_tcg_cond_reg[8] = {
1383ab9ffe98SRichard Henderson     TCG_COND_NEVER,  /* reserved */
1384fcf5ef2aSThomas Huth     TCG_COND_NE,
1385fcf5ef2aSThomas Huth     TCG_COND_GT,
1386fcf5ef2aSThomas Huth     TCG_COND_GE,
1387ab9ffe98SRichard Henderson     TCG_COND_NEVER,  /* reserved */
1388fcf5ef2aSThomas Huth     TCG_COND_EQ,
1389fcf5ef2aSThomas Huth     TCG_COND_LE,
1390fcf5ef2aSThomas Huth     TCG_COND_LT,
1391fcf5ef2aSThomas Huth };
1392fcf5ef2aSThomas Huth 
1393fcf5ef2aSThomas Huth static void gen_compare_reg(DisasCompare *cmp, int cond, TCGv r_src)
1394fcf5ef2aSThomas Huth {
1395fcf5ef2aSThomas Huth     cmp->cond = tcg_invert_cond(gen_tcg_cond_reg[cond]);
1396fcf5ef2aSThomas Huth     cmp->is_bool = false;
1397fcf5ef2aSThomas Huth     cmp->c1 = r_src;
139800ab7e61SRichard Henderson     cmp->c2 = tcg_constant_tl(0);
1399fcf5ef2aSThomas Huth }
1400fcf5ef2aSThomas Huth 
1401baf3dbf2SRichard Henderson static void gen_op_clear_ieee_excp_and_FTT(void)
1402baf3dbf2SRichard Henderson {
1403baf3dbf2SRichard Henderson     tcg_gen_andi_tl(cpu_fsr, cpu_fsr, FSR_FTT_CEXC_NMASK);
1404baf3dbf2SRichard Henderson }
1405baf3dbf2SRichard Henderson 
1406baf3dbf2SRichard Henderson static void gen_op_fmovs(TCGv_i32 dst, TCGv_i32 src)
1407baf3dbf2SRichard Henderson {
1408baf3dbf2SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
1409baf3dbf2SRichard Henderson     tcg_gen_mov_i32(dst, src);
1410baf3dbf2SRichard Henderson }
1411baf3dbf2SRichard Henderson 
1412baf3dbf2SRichard Henderson static void gen_op_fnegs(TCGv_i32 dst, TCGv_i32 src)
1413baf3dbf2SRichard Henderson {
1414baf3dbf2SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
1415baf3dbf2SRichard Henderson     gen_helper_fnegs(dst, src);
1416baf3dbf2SRichard Henderson }
1417baf3dbf2SRichard Henderson 
1418baf3dbf2SRichard Henderson static void gen_op_fabss(TCGv_i32 dst, TCGv_i32 src)
1419baf3dbf2SRichard Henderson {
1420baf3dbf2SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
1421baf3dbf2SRichard Henderson     gen_helper_fabss(dst, src);
1422baf3dbf2SRichard Henderson }
1423baf3dbf2SRichard Henderson 
1424c6d83e4fSRichard Henderson static void gen_op_fmovd(TCGv_i64 dst, TCGv_i64 src)
1425c6d83e4fSRichard Henderson {
1426c6d83e4fSRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
1427c6d83e4fSRichard Henderson     tcg_gen_mov_i64(dst, src);
1428c6d83e4fSRichard Henderson }
1429c6d83e4fSRichard Henderson 
1430c6d83e4fSRichard Henderson static void gen_op_fnegd(TCGv_i64 dst, TCGv_i64 src)
1431c6d83e4fSRichard Henderson {
1432c6d83e4fSRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
1433c6d83e4fSRichard Henderson     gen_helper_fnegd(dst, src);
1434c6d83e4fSRichard Henderson }
1435c6d83e4fSRichard Henderson 
1436c6d83e4fSRichard Henderson static void gen_op_fabsd(TCGv_i64 dst, TCGv_i64 src)
1437c6d83e4fSRichard Henderson {
1438c6d83e4fSRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
1439c6d83e4fSRichard Henderson     gen_helper_fabsd(dst, src);
1440c6d83e4fSRichard Henderson }
1441c6d83e4fSRichard Henderson 
1442fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
14430c2e96c1SRichard Henderson static void gen_op_fcmps(int fccno, TCGv_i32 r_rs1, TCGv_i32 r_rs2)
1444fcf5ef2aSThomas Huth {
1445fcf5ef2aSThomas Huth     switch (fccno) {
1446fcf5ef2aSThomas Huth     case 0:
1447ad75a51eSRichard Henderson         gen_helper_fcmps(cpu_fsr, tcg_env, r_rs1, r_rs2);
1448fcf5ef2aSThomas Huth         break;
1449fcf5ef2aSThomas Huth     case 1:
1450ad75a51eSRichard Henderson         gen_helper_fcmps_fcc1(cpu_fsr, tcg_env, r_rs1, r_rs2);
1451fcf5ef2aSThomas Huth         break;
1452fcf5ef2aSThomas Huth     case 2:
1453ad75a51eSRichard Henderson         gen_helper_fcmps_fcc2(cpu_fsr, tcg_env, r_rs1, r_rs2);
1454fcf5ef2aSThomas Huth         break;
1455fcf5ef2aSThomas Huth     case 3:
1456ad75a51eSRichard Henderson         gen_helper_fcmps_fcc3(cpu_fsr, tcg_env, r_rs1, r_rs2);
1457fcf5ef2aSThomas Huth         break;
1458fcf5ef2aSThomas Huth     }
1459fcf5ef2aSThomas Huth }
1460fcf5ef2aSThomas Huth 
14610c2e96c1SRichard Henderson static void gen_op_fcmpd(int fccno, TCGv_i64 r_rs1, TCGv_i64 r_rs2)
1462fcf5ef2aSThomas Huth {
1463fcf5ef2aSThomas Huth     switch (fccno) {
1464fcf5ef2aSThomas Huth     case 0:
1465ad75a51eSRichard Henderson         gen_helper_fcmpd(cpu_fsr, tcg_env, r_rs1, r_rs2);
1466fcf5ef2aSThomas Huth         break;
1467fcf5ef2aSThomas Huth     case 1:
1468ad75a51eSRichard Henderson         gen_helper_fcmpd_fcc1(cpu_fsr, tcg_env, r_rs1, r_rs2);
1469fcf5ef2aSThomas Huth         break;
1470fcf5ef2aSThomas Huth     case 2:
1471ad75a51eSRichard Henderson         gen_helper_fcmpd_fcc2(cpu_fsr, tcg_env, r_rs1, r_rs2);
1472fcf5ef2aSThomas Huth         break;
1473fcf5ef2aSThomas Huth     case 3:
1474ad75a51eSRichard Henderson         gen_helper_fcmpd_fcc3(cpu_fsr, tcg_env, r_rs1, r_rs2);
1475fcf5ef2aSThomas Huth         break;
1476fcf5ef2aSThomas Huth     }
1477fcf5ef2aSThomas Huth }
1478fcf5ef2aSThomas Huth 
14790c2e96c1SRichard Henderson static void gen_op_fcmpq(int fccno)
1480fcf5ef2aSThomas Huth {
1481fcf5ef2aSThomas Huth     switch (fccno) {
1482fcf5ef2aSThomas Huth     case 0:
1483ad75a51eSRichard Henderson         gen_helper_fcmpq(cpu_fsr, tcg_env);
1484fcf5ef2aSThomas Huth         break;
1485fcf5ef2aSThomas Huth     case 1:
1486ad75a51eSRichard Henderson         gen_helper_fcmpq_fcc1(cpu_fsr, tcg_env);
1487fcf5ef2aSThomas Huth         break;
1488fcf5ef2aSThomas Huth     case 2:
1489ad75a51eSRichard Henderson         gen_helper_fcmpq_fcc2(cpu_fsr, tcg_env);
1490fcf5ef2aSThomas Huth         break;
1491fcf5ef2aSThomas Huth     case 3:
1492ad75a51eSRichard Henderson         gen_helper_fcmpq_fcc3(cpu_fsr, tcg_env);
1493fcf5ef2aSThomas Huth         break;
1494fcf5ef2aSThomas Huth     }
1495fcf5ef2aSThomas Huth }
1496fcf5ef2aSThomas Huth 
14970c2e96c1SRichard Henderson static void gen_op_fcmpes(int fccno, TCGv_i32 r_rs1, TCGv_i32 r_rs2)
1498fcf5ef2aSThomas Huth {
1499fcf5ef2aSThomas Huth     switch (fccno) {
1500fcf5ef2aSThomas Huth     case 0:
1501ad75a51eSRichard Henderson         gen_helper_fcmpes(cpu_fsr, tcg_env, r_rs1, r_rs2);
1502fcf5ef2aSThomas Huth         break;
1503fcf5ef2aSThomas Huth     case 1:
1504ad75a51eSRichard Henderson         gen_helper_fcmpes_fcc1(cpu_fsr, tcg_env, r_rs1, r_rs2);
1505fcf5ef2aSThomas Huth         break;
1506fcf5ef2aSThomas Huth     case 2:
1507ad75a51eSRichard Henderson         gen_helper_fcmpes_fcc2(cpu_fsr, tcg_env, r_rs1, r_rs2);
1508fcf5ef2aSThomas Huth         break;
1509fcf5ef2aSThomas Huth     case 3:
1510ad75a51eSRichard Henderson         gen_helper_fcmpes_fcc3(cpu_fsr, tcg_env, r_rs1, r_rs2);
1511fcf5ef2aSThomas Huth         break;
1512fcf5ef2aSThomas Huth     }
1513fcf5ef2aSThomas Huth }
1514fcf5ef2aSThomas Huth 
15150c2e96c1SRichard Henderson static void gen_op_fcmped(int fccno, TCGv_i64 r_rs1, TCGv_i64 r_rs2)
1516fcf5ef2aSThomas Huth {
1517fcf5ef2aSThomas Huth     switch (fccno) {
1518fcf5ef2aSThomas Huth     case 0:
1519ad75a51eSRichard Henderson         gen_helper_fcmped(cpu_fsr, tcg_env, r_rs1, r_rs2);
1520fcf5ef2aSThomas Huth         break;
1521fcf5ef2aSThomas Huth     case 1:
1522ad75a51eSRichard Henderson         gen_helper_fcmped_fcc1(cpu_fsr, tcg_env, r_rs1, r_rs2);
1523fcf5ef2aSThomas Huth         break;
1524fcf5ef2aSThomas Huth     case 2:
1525ad75a51eSRichard Henderson         gen_helper_fcmped_fcc2(cpu_fsr, tcg_env, r_rs1, r_rs2);
1526fcf5ef2aSThomas Huth         break;
1527fcf5ef2aSThomas Huth     case 3:
1528ad75a51eSRichard Henderson         gen_helper_fcmped_fcc3(cpu_fsr, tcg_env, r_rs1, r_rs2);
1529fcf5ef2aSThomas Huth         break;
1530fcf5ef2aSThomas Huth     }
1531fcf5ef2aSThomas Huth }
1532fcf5ef2aSThomas Huth 
15330c2e96c1SRichard Henderson static void gen_op_fcmpeq(int fccno)
1534fcf5ef2aSThomas Huth {
1535fcf5ef2aSThomas Huth     switch (fccno) {
1536fcf5ef2aSThomas Huth     case 0:
1537ad75a51eSRichard Henderson         gen_helper_fcmpeq(cpu_fsr, tcg_env);
1538fcf5ef2aSThomas Huth         break;
1539fcf5ef2aSThomas Huth     case 1:
1540ad75a51eSRichard Henderson         gen_helper_fcmpeq_fcc1(cpu_fsr, tcg_env);
1541fcf5ef2aSThomas Huth         break;
1542fcf5ef2aSThomas Huth     case 2:
1543ad75a51eSRichard Henderson         gen_helper_fcmpeq_fcc2(cpu_fsr, tcg_env);
1544fcf5ef2aSThomas Huth         break;
1545fcf5ef2aSThomas Huth     case 3:
1546ad75a51eSRichard Henderson         gen_helper_fcmpeq_fcc3(cpu_fsr, tcg_env);
1547fcf5ef2aSThomas Huth         break;
1548fcf5ef2aSThomas Huth     }
1549fcf5ef2aSThomas Huth }
1550fcf5ef2aSThomas Huth 
1551fcf5ef2aSThomas Huth #else
1552fcf5ef2aSThomas Huth 
15530c2e96c1SRichard Henderson static void gen_op_fcmps(int fccno, TCGv r_rs1, TCGv r_rs2)
1554fcf5ef2aSThomas Huth {
1555ad75a51eSRichard Henderson     gen_helper_fcmps(cpu_fsr, tcg_env, r_rs1, r_rs2);
1556fcf5ef2aSThomas Huth }
1557fcf5ef2aSThomas Huth 
15580c2e96c1SRichard Henderson static void gen_op_fcmpd(int fccno, TCGv_i64 r_rs1, TCGv_i64 r_rs2)
1559fcf5ef2aSThomas Huth {
1560ad75a51eSRichard Henderson     gen_helper_fcmpd(cpu_fsr, tcg_env, r_rs1, r_rs2);
1561fcf5ef2aSThomas Huth }
1562fcf5ef2aSThomas Huth 
15630c2e96c1SRichard Henderson static void gen_op_fcmpq(int fccno)
1564fcf5ef2aSThomas Huth {
1565ad75a51eSRichard Henderson     gen_helper_fcmpq(cpu_fsr, tcg_env);
1566fcf5ef2aSThomas Huth }
1567fcf5ef2aSThomas Huth 
15680c2e96c1SRichard Henderson static void gen_op_fcmpes(int fccno, TCGv r_rs1, TCGv r_rs2)
1569fcf5ef2aSThomas Huth {
1570ad75a51eSRichard Henderson     gen_helper_fcmpes(cpu_fsr, tcg_env, r_rs1, r_rs2);
1571fcf5ef2aSThomas Huth }
1572fcf5ef2aSThomas Huth 
15730c2e96c1SRichard Henderson static void gen_op_fcmped(int fccno, TCGv_i64 r_rs1, TCGv_i64 r_rs2)
1574fcf5ef2aSThomas Huth {
1575ad75a51eSRichard Henderson     gen_helper_fcmped(cpu_fsr, tcg_env, r_rs1, r_rs2);
1576fcf5ef2aSThomas Huth }
1577fcf5ef2aSThomas Huth 
15780c2e96c1SRichard Henderson static void gen_op_fcmpeq(int fccno)
1579fcf5ef2aSThomas Huth {
1580ad75a51eSRichard Henderson     gen_helper_fcmpeq(cpu_fsr, tcg_env);
1581fcf5ef2aSThomas Huth }
1582fcf5ef2aSThomas Huth #endif
1583fcf5ef2aSThomas Huth 
1584fcf5ef2aSThomas Huth static void gen_op_fpexception_im(DisasContext *dc, int fsr_flags)
1585fcf5ef2aSThomas Huth {
1586fcf5ef2aSThomas Huth     tcg_gen_andi_tl(cpu_fsr, cpu_fsr, FSR_FTT_NMASK);
1587fcf5ef2aSThomas Huth     tcg_gen_ori_tl(cpu_fsr, cpu_fsr, fsr_flags);
1588fcf5ef2aSThomas Huth     gen_exception(dc, TT_FP_EXCP);
1589fcf5ef2aSThomas Huth }
1590fcf5ef2aSThomas Huth 
1591fcf5ef2aSThomas Huth static int gen_trap_ifnofpu(DisasContext *dc)
1592fcf5ef2aSThomas Huth {
1593fcf5ef2aSThomas Huth #if !defined(CONFIG_USER_ONLY)
1594fcf5ef2aSThomas Huth     if (!dc->fpu_enabled) {
1595fcf5ef2aSThomas Huth         gen_exception(dc, TT_NFPU_INSN);
1596fcf5ef2aSThomas Huth         return 1;
1597fcf5ef2aSThomas Huth     }
1598fcf5ef2aSThomas Huth #endif
1599fcf5ef2aSThomas Huth     return 0;
1600fcf5ef2aSThomas Huth }
1601fcf5ef2aSThomas Huth 
16020c2e96c1SRichard Henderson static void gen_fop_FF(DisasContext *dc, int rd, int rs,
1603fcf5ef2aSThomas Huth                               void (*gen)(TCGv_i32, TCGv_ptr, TCGv_i32))
1604fcf5ef2aSThomas Huth {
1605fcf5ef2aSThomas Huth     TCGv_i32 dst, src;
1606fcf5ef2aSThomas Huth 
1607fcf5ef2aSThomas Huth     src = gen_load_fpr_F(dc, rs);
1608fcf5ef2aSThomas Huth     dst = gen_dest_fpr_F(dc);
1609fcf5ef2aSThomas Huth 
1610ad75a51eSRichard Henderson     gen(dst, tcg_env, src);
1611ad75a51eSRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
1612fcf5ef2aSThomas Huth 
1613fcf5ef2aSThomas Huth     gen_store_fpr_F(dc, rd, dst);
1614fcf5ef2aSThomas Huth }
1615fcf5ef2aSThomas Huth 
16160c2e96c1SRichard Henderson static void gen_fop_FFF(DisasContext *dc, int rd, int rs1, int rs2,
1617fcf5ef2aSThomas Huth                         void (*gen)(TCGv_i32, TCGv_ptr, TCGv_i32, TCGv_i32))
1618fcf5ef2aSThomas Huth {
1619fcf5ef2aSThomas Huth     TCGv_i32 dst, src1, src2;
1620fcf5ef2aSThomas Huth 
1621fcf5ef2aSThomas Huth     src1 = gen_load_fpr_F(dc, rs1);
1622fcf5ef2aSThomas Huth     src2 = gen_load_fpr_F(dc, rs2);
1623fcf5ef2aSThomas Huth     dst = gen_dest_fpr_F(dc);
1624fcf5ef2aSThomas Huth 
1625ad75a51eSRichard Henderson     gen(dst, tcg_env, src1, src2);
1626ad75a51eSRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
1627fcf5ef2aSThomas Huth 
1628fcf5ef2aSThomas Huth     gen_store_fpr_F(dc, rd, dst);
1629fcf5ef2aSThomas Huth }
1630fcf5ef2aSThomas Huth 
16310c2e96c1SRichard Henderson static void gen_fop_DD(DisasContext *dc, int rd, int rs,
1632fcf5ef2aSThomas Huth                        void (*gen)(TCGv_i64, TCGv_ptr, TCGv_i64))
1633fcf5ef2aSThomas Huth {
1634fcf5ef2aSThomas Huth     TCGv_i64 dst, src;
1635fcf5ef2aSThomas Huth 
1636fcf5ef2aSThomas Huth     src = gen_load_fpr_D(dc, rs);
1637fcf5ef2aSThomas Huth     dst = gen_dest_fpr_D(dc, rd);
1638fcf5ef2aSThomas Huth 
1639ad75a51eSRichard Henderson     gen(dst, tcg_env, src);
1640ad75a51eSRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
1641fcf5ef2aSThomas Huth 
1642fcf5ef2aSThomas Huth     gen_store_fpr_D(dc, rd, dst);
1643fcf5ef2aSThomas Huth }
1644fcf5ef2aSThomas Huth 
16450c2e96c1SRichard Henderson static void gen_fop_DDD(DisasContext *dc, int rd, int rs1, int rs2,
1646fcf5ef2aSThomas Huth                         void (*gen)(TCGv_i64, TCGv_ptr, TCGv_i64, TCGv_i64))
1647fcf5ef2aSThomas Huth {
1648fcf5ef2aSThomas Huth     TCGv_i64 dst, src1, src2;
1649fcf5ef2aSThomas Huth 
1650fcf5ef2aSThomas Huth     src1 = gen_load_fpr_D(dc, rs1);
1651fcf5ef2aSThomas Huth     src2 = gen_load_fpr_D(dc, rs2);
1652fcf5ef2aSThomas Huth     dst = gen_dest_fpr_D(dc, rd);
1653fcf5ef2aSThomas Huth 
1654ad75a51eSRichard Henderson     gen(dst, tcg_env, src1, src2);
1655ad75a51eSRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
1656fcf5ef2aSThomas Huth 
1657fcf5ef2aSThomas Huth     gen_store_fpr_D(dc, rd, dst);
1658fcf5ef2aSThomas Huth }
1659fcf5ef2aSThomas Huth 
1660fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
16610c2e96c1SRichard Henderson static void gen_ne_fop_DDD(DisasContext *dc, int rd, int rs1, int rs2,
1662fcf5ef2aSThomas Huth                            void (*gen)(TCGv_i64, TCGv_i64, TCGv_i64))
1663fcf5ef2aSThomas Huth {
1664fcf5ef2aSThomas Huth     TCGv_i64 dst, src1, src2;
1665fcf5ef2aSThomas Huth 
1666fcf5ef2aSThomas Huth     src1 = gen_load_fpr_D(dc, rs1);
1667fcf5ef2aSThomas Huth     src2 = gen_load_fpr_D(dc, rs2);
1668fcf5ef2aSThomas Huth     dst = gen_dest_fpr_D(dc, rd);
1669fcf5ef2aSThomas Huth 
1670fcf5ef2aSThomas Huth     gen(dst, src1, src2);
1671fcf5ef2aSThomas Huth 
1672fcf5ef2aSThomas Huth     gen_store_fpr_D(dc, rd, dst);
1673fcf5ef2aSThomas Huth }
1674fcf5ef2aSThomas Huth 
16750c2e96c1SRichard Henderson static void gen_gsr_fop_DDD(DisasContext *dc, int rd, int rs1, int rs2,
1676fcf5ef2aSThomas Huth                             void (*gen)(TCGv_i64, TCGv_i64, TCGv_i64, TCGv_i64))
1677fcf5ef2aSThomas Huth {
1678fcf5ef2aSThomas Huth     TCGv_i64 dst, src1, src2;
1679fcf5ef2aSThomas Huth 
1680fcf5ef2aSThomas Huth     src1 = gen_load_fpr_D(dc, rs1);
1681fcf5ef2aSThomas Huth     src2 = gen_load_fpr_D(dc, rs2);
1682fcf5ef2aSThomas Huth     dst = gen_dest_fpr_D(dc, rd);
1683fcf5ef2aSThomas Huth 
1684fcf5ef2aSThomas Huth     gen(dst, cpu_gsr, src1, src2);
1685fcf5ef2aSThomas Huth 
1686fcf5ef2aSThomas Huth     gen_store_fpr_D(dc, rd, dst);
1687fcf5ef2aSThomas Huth }
1688fcf5ef2aSThomas Huth 
16890c2e96c1SRichard Henderson static void gen_ne_fop_DDDD(DisasContext *dc, int rd, int rs1, int rs2,
1690fcf5ef2aSThomas Huth                             void (*gen)(TCGv_i64, TCGv_i64, TCGv_i64, TCGv_i64))
1691fcf5ef2aSThomas Huth {
1692fcf5ef2aSThomas Huth     TCGv_i64 dst, src0, src1, src2;
1693fcf5ef2aSThomas Huth 
1694fcf5ef2aSThomas Huth     src1 = gen_load_fpr_D(dc, rs1);
1695fcf5ef2aSThomas Huth     src2 = gen_load_fpr_D(dc, rs2);
1696fcf5ef2aSThomas Huth     src0 = gen_load_fpr_D(dc, rd);
1697fcf5ef2aSThomas Huth     dst = gen_dest_fpr_D(dc, rd);
1698fcf5ef2aSThomas Huth 
1699fcf5ef2aSThomas Huth     gen(dst, src0, src1, src2);
1700fcf5ef2aSThomas Huth 
1701fcf5ef2aSThomas Huth     gen_store_fpr_D(dc, rd, dst);
1702fcf5ef2aSThomas Huth }
1703fcf5ef2aSThomas Huth #endif
1704fcf5ef2aSThomas Huth 
17050c2e96c1SRichard Henderson static void gen_fop_QQ(DisasContext *dc, int rd, int rs,
1706fcf5ef2aSThomas Huth                        void (*gen)(TCGv_ptr))
1707fcf5ef2aSThomas Huth {
1708fcf5ef2aSThomas Huth     gen_op_load_fpr_QT1(QFPREG(rs));
1709fcf5ef2aSThomas Huth 
1710ad75a51eSRichard Henderson     gen(tcg_env);
1711ad75a51eSRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
1712fcf5ef2aSThomas Huth 
1713fcf5ef2aSThomas Huth     gen_op_store_QT0_fpr(QFPREG(rd));
1714fcf5ef2aSThomas Huth     gen_update_fprs_dirty(dc, QFPREG(rd));
1715fcf5ef2aSThomas Huth }
1716fcf5ef2aSThomas Huth 
1717fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
17180c2e96c1SRichard Henderson static void gen_ne_fop_QQ(DisasContext *dc, int rd, int rs,
1719fcf5ef2aSThomas Huth                           void (*gen)(TCGv_ptr))
1720fcf5ef2aSThomas Huth {
1721fcf5ef2aSThomas Huth     gen_op_load_fpr_QT1(QFPREG(rs));
1722fcf5ef2aSThomas Huth 
1723ad75a51eSRichard Henderson     gen(tcg_env);
1724fcf5ef2aSThomas Huth 
1725fcf5ef2aSThomas Huth     gen_op_store_QT0_fpr(QFPREG(rd));
1726fcf5ef2aSThomas Huth     gen_update_fprs_dirty(dc, QFPREG(rd));
1727fcf5ef2aSThomas Huth }
1728fcf5ef2aSThomas Huth #endif
1729fcf5ef2aSThomas Huth 
17300c2e96c1SRichard Henderson static void gen_fop_QQQ(DisasContext *dc, int rd, int rs1, int rs2,
1731fcf5ef2aSThomas Huth                         void (*gen)(TCGv_ptr))
1732fcf5ef2aSThomas Huth {
1733fcf5ef2aSThomas Huth     gen_op_load_fpr_QT0(QFPREG(rs1));
1734fcf5ef2aSThomas Huth     gen_op_load_fpr_QT1(QFPREG(rs2));
1735fcf5ef2aSThomas Huth 
1736ad75a51eSRichard Henderson     gen(tcg_env);
1737ad75a51eSRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
1738fcf5ef2aSThomas Huth 
1739fcf5ef2aSThomas Huth     gen_op_store_QT0_fpr(QFPREG(rd));
1740fcf5ef2aSThomas Huth     gen_update_fprs_dirty(dc, QFPREG(rd));
1741fcf5ef2aSThomas Huth }
1742fcf5ef2aSThomas Huth 
17430c2e96c1SRichard Henderson static void gen_fop_DFF(DisasContext *dc, int rd, int rs1, int rs2,
1744fcf5ef2aSThomas Huth                         void (*gen)(TCGv_i64, TCGv_ptr, TCGv_i32, TCGv_i32))
1745fcf5ef2aSThomas Huth {
1746fcf5ef2aSThomas Huth     TCGv_i64 dst;
1747fcf5ef2aSThomas Huth     TCGv_i32 src1, src2;
1748fcf5ef2aSThomas Huth 
1749fcf5ef2aSThomas Huth     src1 = gen_load_fpr_F(dc, rs1);
1750fcf5ef2aSThomas Huth     src2 = gen_load_fpr_F(dc, rs2);
1751fcf5ef2aSThomas Huth     dst = gen_dest_fpr_D(dc, rd);
1752fcf5ef2aSThomas Huth 
1753ad75a51eSRichard Henderson     gen(dst, tcg_env, src1, src2);
1754ad75a51eSRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
1755fcf5ef2aSThomas Huth 
1756fcf5ef2aSThomas Huth     gen_store_fpr_D(dc, rd, dst);
1757fcf5ef2aSThomas Huth }
1758fcf5ef2aSThomas Huth 
17590c2e96c1SRichard Henderson static void gen_fop_QDD(DisasContext *dc, int rd, int rs1, int rs2,
1760fcf5ef2aSThomas Huth                         void (*gen)(TCGv_ptr, TCGv_i64, TCGv_i64))
1761fcf5ef2aSThomas Huth {
1762fcf5ef2aSThomas Huth     TCGv_i64 src1, src2;
1763fcf5ef2aSThomas Huth 
1764fcf5ef2aSThomas Huth     src1 = gen_load_fpr_D(dc, rs1);
1765fcf5ef2aSThomas Huth     src2 = gen_load_fpr_D(dc, rs2);
1766fcf5ef2aSThomas Huth 
1767ad75a51eSRichard Henderson     gen(tcg_env, src1, src2);
1768ad75a51eSRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
1769fcf5ef2aSThomas Huth 
1770fcf5ef2aSThomas Huth     gen_op_store_QT0_fpr(QFPREG(rd));
1771fcf5ef2aSThomas Huth     gen_update_fprs_dirty(dc, QFPREG(rd));
1772fcf5ef2aSThomas Huth }
1773fcf5ef2aSThomas Huth 
1774fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
17750c2e96c1SRichard Henderson static void gen_fop_DF(DisasContext *dc, int rd, int rs,
1776fcf5ef2aSThomas Huth                        void (*gen)(TCGv_i64, TCGv_ptr, TCGv_i32))
1777fcf5ef2aSThomas Huth {
1778fcf5ef2aSThomas Huth     TCGv_i64 dst;
1779fcf5ef2aSThomas Huth     TCGv_i32 src;
1780fcf5ef2aSThomas Huth 
1781fcf5ef2aSThomas Huth     src = gen_load_fpr_F(dc, rs);
1782fcf5ef2aSThomas Huth     dst = gen_dest_fpr_D(dc, rd);
1783fcf5ef2aSThomas Huth 
1784ad75a51eSRichard Henderson     gen(dst, tcg_env, src);
1785ad75a51eSRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
1786fcf5ef2aSThomas Huth 
1787fcf5ef2aSThomas Huth     gen_store_fpr_D(dc, rd, dst);
1788fcf5ef2aSThomas Huth }
1789fcf5ef2aSThomas Huth #endif
1790fcf5ef2aSThomas Huth 
17910c2e96c1SRichard Henderson static void gen_ne_fop_DF(DisasContext *dc, int rd, int rs,
1792fcf5ef2aSThomas Huth                           void (*gen)(TCGv_i64, TCGv_ptr, TCGv_i32))
1793fcf5ef2aSThomas Huth {
1794fcf5ef2aSThomas Huth     TCGv_i64 dst;
1795fcf5ef2aSThomas Huth     TCGv_i32 src;
1796fcf5ef2aSThomas Huth 
1797fcf5ef2aSThomas Huth     src = gen_load_fpr_F(dc, rs);
1798fcf5ef2aSThomas Huth     dst = gen_dest_fpr_D(dc, rd);
1799fcf5ef2aSThomas Huth 
1800ad75a51eSRichard Henderson     gen(dst, tcg_env, src);
1801fcf5ef2aSThomas Huth 
1802fcf5ef2aSThomas Huth     gen_store_fpr_D(dc, rd, dst);
1803fcf5ef2aSThomas Huth }
1804fcf5ef2aSThomas Huth 
18050c2e96c1SRichard Henderson static void gen_fop_FD(DisasContext *dc, int rd, int rs,
1806fcf5ef2aSThomas Huth                        void (*gen)(TCGv_i32, TCGv_ptr, TCGv_i64))
1807fcf5ef2aSThomas Huth {
1808fcf5ef2aSThomas Huth     TCGv_i32 dst;
1809fcf5ef2aSThomas Huth     TCGv_i64 src;
1810fcf5ef2aSThomas Huth 
1811fcf5ef2aSThomas Huth     src = gen_load_fpr_D(dc, rs);
1812fcf5ef2aSThomas Huth     dst = gen_dest_fpr_F(dc);
1813fcf5ef2aSThomas Huth 
1814ad75a51eSRichard Henderson     gen(dst, tcg_env, src);
1815ad75a51eSRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
1816fcf5ef2aSThomas Huth 
1817fcf5ef2aSThomas Huth     gen_store_fpr_F(dc, rd, dst);
1818fcf5ef2aSThomas Huth }
1819fcf5ef2aSThomas Huth 
18200c2e96c1SRichard Henderson static void gen_fop_FQ(DisasContext *dc, int rd, int rs,
1821fcf5ef2aSThomas Huth                        void (*gen)(TCGv_i32, TCGv_ptr))
1822fcf5ef2aSThomas Huth {
1823fcf5ef2aSThomas Huth     TCGv_i32 dst;
1824fcf5ef2aSThomas Huth 
1825fcf5ef2aSThomas Huth     gen_op_load_fpr_QT1(QFPREG(rs));
1826fcf5ef2aSThomas Huth     dst = gen_dest_fpr_F(dc);
1827fcf5ef2aSThomas Huth 
1828ad75a51eSRichard Henderson     gen(dst, tcg_env);
1829ad75a51eSRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
1830fcf5ef2aSThomas Huth 
1831fcf5ef2aSThomas Huth     gen_store_fpr_F(dc, rd, dst);
1832fcf5ef2aSThomas Huth }
1833fcf5ef2aSThomas Huth 
18340c2e96c1SRichard Henderson static void gen_fop_DQ(DisasContext *dc, int rd, int rs,
1835fcf5ef2aSThomas Huth                        void (*gen)(TCGv_i64, TCGv_ptr))
1836fcf5ef2aSThomas Huth {
1837fcf5ef2aSThomas Huth     TCGv_i64 dst;
1838fcf5ef2aSThomas Huth 
1839fcf5ef2aSThomas Huth     gen_op_load_fpr_QT1(QFPREG(rs));
1840fcf5ef2aSThomas Huth     dst = gen_dest_fpr_D(dc, rd);
1841fcf5ef2aSThomas Huth 
1842ad75a51eSRichard Henderson     gen(dst, tcg_env);
1843ad75a51eSRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
1844fcf5ef2aSThomas Huth 
1845fcf5ef2aSThomas Huth     gen_store_fpr_D(dc, rd, dst);
1846fcf5ef2aSThomas Huth }
1847fcf5ef2aSThomas Huth 
18480c2e96c1SRichard Henderson static void gen_ne_fop_QF(DisasContext *dc, int rd, int rs,
1849fcf5ef2aSThomas Huth                           void (*gen)(TCGv_ptr, TCGv_i32))
1850fcf5ef2aSThomas Huth {
1851fcf5ef2aSThomas Huth     TCGv_i32 src;
1852fcf5ef2aSThomas Huth 
1853fcf5ef2aSThomas Huth     src = gen_load_fpr_F(dc, rs);
1854fcf5ef2aSThomas Huth 
1855ad75a51eSRichard Henderson     gen(tcg_env, src);
1856fcf5ef2aSThomas Huth 
1857fcf5ef2aSThomas Huth     gen_op_store_QT0_fpr(QFPREG(rd));
1858fcf5ef2aSThomas Huth     gen_update_fprs_dirty(dc, QFPREG(rd));
1859fcf5ef2aSThomas Huth }
1860fcf5ef2aSThomas Huth 
18610c2e96c1SRichard Henderson static void gen_ne_fop_QD(DisasContext *dc, int rd, int rs,
1862fcf5ef2aSThomas Huth                           void (*gen)(TCGv_ptr, TCGv_i64))
1863fcf5ef2aSThomas Huth {
1864fcf5ef2aSThomas Huth     TCGv_i64 src;
1865fcf5ef2aSThomas Huth 
1866fcf5ef2aSThomas Huth     src = gen_load_fpr_D(dc, rs);
1867fcf5ef2aSThomas Huth 
1868ad75a51eSRichard Henderson     gen(tcg_env, src);
1869fcf5ef2aSThomas Huth 
1870fcf5ef2aSThomas Huth     gen_op_store_QT0_fpr(QFPREG(rd));
1871fcf5ef2aSThomas Huth     gen_update_fprs_dirty(dc, QFPREG(rd));
1872fcf5ef2aSThomas Huth }
1873fcf5ef2aSThomas Huth 
1874fcf5ef2aSThomas Huth /* asi moves */
1875fcf5ef2aSThomas Huth typedef enum {
1876fcf5ef2aSThomas Huth     GET_ASI_HELPER,
1877fcf5ef2aSThomas Huth     GET_ASI_EXCP,
1878fcf5ef2aSThomas Huth     GET_ASI_DIRECT,
1879fcf5ef2aSThomas Huth     GET_ASI_DTWINX,
1880fcf5ef2aSThomas Huth     GET_ASI_BLOCK,
1881fcf5ef2aSThomas Huth     GET_ASI_SHORT,
1882fcf5ef2aSThomas Huth     GET_ASI_BCOPY,
1883fcf5ef2aSThomas Huth     GET_ASI_BFILL,
1884fcf5ef2aSThomas Huth } ASIType;
1885fcf5ef2aSThomas Huth 
1886fcf5ef2aSThomas Huth typedef struct {
1887fcf5ef2aSThomas Huth     ASIType type;
1888fcf5ef2aSThomas Huth     int asi;
1889fcf5ef2aSThomas Huth     int mem_idx;
189014776ab5STony Nguyen     MemOp memop;
1891fcf5ef2aSThomas Huth } DisasASI;
1892fcf5ef2aSThomas Huth 
1893811cc0b0SRichard Henderson /*
1894811cc0b0SRichard Henderson  * Build DisasASI.
1895811cc0b0SRichard Henderson  * For asi == -1, treat as non-asi.
1896811cc0b0SRichard Henderson  * For ask == -2, treat as immediate offset (v8 error, v9 %asi).
1897811cc0b0SRichard Henderson  */
1898811cc0b0SRichard Henderson static DisasASI resolve_asi(DisasContext *dc, int asi, MemOp memop)
1899fcf5ef2aSThomas Huth {
1900fcf5ef2aSThomas Huth     ASIType type = GET_ASI_HELPER;
1901fcf5ef2aSThomas Huth     int mem_idx = dc->mem_idx;
1902fcf5ef2aSThomas Huth 
1903811cc0b0SRichard Henderson     if (asi == -1) {
1904811cc0b0SRichard Henderson         /* Artificial "non-asi" case. */
1905811cc0b0SRichard Henderson         type = GET_ASI_DIRECT;
1906811cc0b0SRichard Henderson         goto done;
1907811cc0b0SRichard Henderson     }
1908811cc0b0SRichard Henderson 
1909fcf5ef2aSThomas Huth #ifndef TARGET_SPARC64
1910fcf5ef2aSThomas Huth     /* Before v9, all asis are immediate and privileged.  */
1911811cc0b0SRichard Henderson     if (asi < 0) {
1912fcf5ef2aSThomas Huth         gen_exception(dc, TT_ILL_INSN);
1913fcf5ef2aSThomas Huth         type = GET_ASI_EXCP;
1914fcf5ef2aSThomas Huth     } else if (supervisor(dc)
1915fcf5ef2aSThomas Huth                /* Note that LEON accepts ASI_USERDATA in user mode, for
1916fcf5ef2aSThomas Huth                   use with CASA.  Also note that previous versions of
1917fcf5ef2aSThomas Huth                   QEMU allowed (and old versions of gcc emitted) ASI_P
1918fcf5ef2aSThomas Huth                   for LEON, which is incorrect.  */
1919fcf5ef2aSThomas Huth                || (asi == ASI_USERDATA
1920fcf5ef2aSThomas Huth                    && (dc->def->features & CPU_FEATURE_CASA))) {
1921fcf5ef2aSThomas Huth         switch (asi) {
1922fcf5ef2aSThomas Huth         case ASI_USERDATA:   /* User data access */
1923fcf5ef2aSThomas Huth             mem_idx = MMU_USER_IDX;
1924fcf5ef2aSThomas Huth             type = GET_ASI_DIRECT;
1925fcf5ef2aSThomas Huth             break;
1926fcf5ef2aSThomas Huth         case ASI_KERNELDATA: /* Supervisor data access */
1927fcf5ef2aSThomas Huth             mem_idx = MMU_KERNEL_IDX;
1928fcf5ef2aSThomas Huth             type = GET_ASI_DIRECT;
1929fcf5ef2aSThomas Huth             break;
1930fcf5ef2aSThomas Huth         case ASI_M_BYPASS:    /* MMU passthrough */
1931fcf5ef2aSThomas Huth         case ASI_LEON_BYPASS: /* LEON MMU passthrough */
1932fcf5ef2aSThomas Huth             mem_idx = MMU_PHYS_IDX;
1933fcf5ef2aSThomas Huth             type = GET_ASI_DIRECT;
1934fcf5ef2aSThomas Huth             break;
1935fcf5ef2aSThomas Huth         case ASI_M_BCOPY: /* Block copy, sta access */
1936fcf5ef2aSThomas Huth             mem_idx = MMU_KERNEL_IDX;
1937fcf5ef2aSThomas Huth             type = GET_ASI_BCOPY;
1938fcf5ef2aSThomas Huth             break;
1939fcf5ef2aSThomas Huth         case ASI_M_BFILL: /* Block fill, stda access */
1940fcf5ef2aSThomas Huth             mem_idx = MMU_KERNEL_IDX;
1941fcf5ef2aSThomas Huth             type = GET_ASI_BFILL;
1942fcf5ef2aSThomas Huth             break;
1943fcf5ef2aSThomas Huth         }
19446e10f37cSKONRAD Frederic 
19456e10f37cSKONRAD Frederic         /* MMU_PHYS_IDX is used when the MMU is disabled to passthrough the
19466e10f37cSKONRAD Frederic          * permissions check in get_physical_address(..).
19476e10f37cSKONRAD Frederic          */
19486e10f37cSKONRAD Frederic         mem_idx = (dc->mem_idx == MMU_PHYS_IDX) ? MMU_PHYS_IDX : mem_idx;
1949fcf5ef2aSThomas Huth     } else {
1950fcf5ef2aSThomas Huth         gen_exception(dc, TT_PRIV_INSN);
1951fcf5ef2aSThomas Huth         type = GET_ASI_EXCP;
1952fcf5ef2aSThomas Huth     }
1953fcf5ef2aSThomas Huth #else
1954811cc0b0SRichard Henderson     if (asi < 0) {
1955fcf5ef2aSThomas Huth         asi = dc->asi;
1956fcf5ef2aSThomas Huth     }
1957fcf5ef2aSThomas Huth     /* With v9, all asis below 0x80 are privileged.  */
1958fcf5ef2aSThomas Huth     /* ??? We ought to check cpu_has_hypervisor, but we didn't copy
1959fcf5ef2aSThomas Huth        down that bit into DisasContext.  For the moment that's ok,
1960fcf5ef2aSThomas Huth        since the direct implementations below doesn't have any ASIs
1961fcf5ef2aSThomas Huth        in the restricted [0x30, 0x7f] range, and the check will be
1962fcf5ef2aSThomas Huth        done properly in the helper.  */
1963fcf5ef2aSThomas Huth     if (!supervisor(dc) && asi < 0x80) {
1964fcf5ef2aSThomas Huth         gen_exception(dc, TT_PRIV_ACT);
1965fcf5ef2aSThomas Huth         type = GET_ASI_EXCP;
1966fcf5ef2aSThomas Huth     } else {
1967fcf5ef2aSThomas Huth         switch (asi) {
1968fcf5ef2aSThomas Huth         case ASI_REAL:      /* Bypass */
1969fcf5ef2aSThomas Huth         case ASI_REAL_IO:   /* Bypass, non-cacheable */
1970fcf5ef2aSThomas Huth         case ASI_REAL_L:    /* Bypass LE */
1971fcf5ef2aSThomas Huth         case ASI_REAL_IO_L: /* Bypass, non-cacheable LE */
1972fcf5ef2aSThomas Huth         case ASI_TWINX_REAL:   /* Real address, twinx */
1973fcf5ef2aSThomas Huth         case ASI_TWINX_REAL_L: /* Real address, twinx, LE */
1974fcf5ef2aSThomas Huth         case ASI_QUAD_LDD_PHYS:
1975fcf5ef2aSThomas Huth         case ASI_QUAD_LDD_PHYS_L:
1976fcf5ef2aSThomas Huth             mem_idx = MMU_PHYS_IDX;
1977fcf5ef2aSThomas Huth             break;
1978fcf5ef2aSThomas Huth         case ASI_N:  /* Nucleus */
1979fcf5ef2aSThomas Huth         case ASI_NL: /* Nucleus LE */
1980fcf5ef2aSThomas Huth         case ASI_TWINX_N:
1981fcf5ef2aSThomas Huth         case ASI_TWINX_NL:
1982fcf5ef2aSThomas Huth         case ASI_NUCLEUS_QUAD_LDD:
1983fcf5ef2aSThomas Huth         case ASI_NUCLEUS_QUAD_LDD_L:
19849a10756dSArtyom Tarasenko             if (hypervisor(dc)) {
198584f8f587SArtyom Tarasenko                 mem_idx = MMU_PHYS_IDX;
19869a10756dSArtyom Tarasenko             } else {
1987fcf5ef2aSThomas Huth                 mem_idx = MMU_NUCLEUS_IDX;
19889a10756dSArtyom Tarasenko             }
1989fcf5ef2aSThomas Huth             break;
1990fcf5ef2aSThomas Huth         case ASI_AIUP:  /* As if user primary */
1991fcf5ef2aSThomas Huth         case ASI_AIUPL: /* As if user primary LE */
1992fcf5ef2aSThomas Huth         case ASI_TWINX_AIUP:
1993fcf5ef2aSThomas Huth         case ASI_TWINX_AIUP_L:
1994fcf5ef2aSThomas Huth         case ASI_BLK_AIUP_4V:
1995fcf5ef2aSThomas Huth         case ASI_BLK_AIUP_L_4V:
1996fcf5ef2aSThomas Huth         case ASI_BLK_AIUP:
1997fcf5ef2aSThomas Huth         case ASI_BLK_AIUPL:
1998fcf5ef2aSThomas Huth             mem_idx = MMU_USER_IDX;
1999fcf5ef2aSThomas Huth             break;
2000fcf5ef2aSThomas Huth         case ASI_AIUS:  /* As if user secondary */
2001fcf5ef2aSThomas Huth         case ASI_AIUSL: /* As if user secondary LE */
2002fcf5ef2aSThomas Huth         case ASI_TWINX_AIUS:
2003fcf5ef2aSThomas Huth         case ASI_TWINX_AIUS_L:
2004fcf5ef2aSThomas Huth         case ASI_BLK_AIUS_4V:
2005fcf5ef2aSThomas Huth         case ASI_BLK_AIUS_L_4V:
2006fcf5ef2aSThomas Huth         case ASI_BLK_AIUS:
2007fcf5ef2aSThomas Huth         case ASI_BLK_AIUSL:
2008fcf5ef2aSThomas Huth             mem_idx = MMU_USER_SECONDARY_IDX;
2009fcf5ef2aSThomas Huth             break;
2010fcf5ef2aSThomas Huth         case ASI_S:  /* Secondary */
2011fcf5ef2aSThomas Huth         case ASI_SL: /* Secondary LE */
2012fcf5ef2aSThomas Huth         case ASI_TWINX_S:
2013fcf5ef2aSThomas Huth         case ASI_TWINX_SL:
2014fcf5ef2aSThomas Huth         case ASI_BLK_COMMIT_S:
2015fcf5ef2aSThomas Huth         case ASI_BLK_S:
2016fcf5ef2aSThomas Huth         case ASI_BLK_SL:
2017fcf5ef2aSThomas Huth         case ASI_FL8_S:
2018fcf5ef2aSThomas Huth         case ASI_FL8_SL:
2019fcf5ef2aSThomas Huth         case ASI_FL16_S:
2020fcf5ef2aSThomas Huth         case ASI_FL16_SL:
2021fcf5ef2aSThomas Huth             if (mem_idx == MMU_USER_IDX) {
2022fcf5ef2aSThomas Huth                 mem_idx = MMU_USER_SECONDARY_IDX;
2023fcf5ef2aSThomas Huth             } else if (mem_idx == MMU_KERNEL_IDX) {
2024fcf5ef2aSThomas Huth                 mem_idx = MMU_KERNEL_SECONDARY_IDX;
2025fcf5ef2aSThomas Huth             }
2026fcf5ef2aSThomas Huth             break;
2027fcf5ef2aSThomas Huth         case ASI_P:  /* Primary */
2028fcf5ef2aSThomas Huth         case ASI_PL: /* Primary LE */
2029fcf5ef2aSThomas Huth         case ASI_TWINX_P:
2030fcf5ef2aSThomas Huth         case ASI_TWINX_PL:
2031fcf5ef2aSThomas Huth         case ASI_BLK_COMMIT_P:
2032fcf5ef2aSThomas Huth         case ASI_BLK_P:
2033fcf5ef2aSThomas Huth         case ASI_BLK_PL:
2034fcf5ef2aSThomas Huth         case ASI_FL8_P:
2035fcf5ef2aSThomas Huth         case ASI_FL8_PL:
2036fcf5ef2aSThomas Huth         case ASI_FL16_P:
2037fcf5ef2aSThomas Huth         case ASI_FL16_PL:
2038fcf5ef2aSThomas Huth             break;
2039fcf5ef2aSThomas Huth         }
2040fcf5ef2aSThomas Huth         switch (asi) {
2041fcf5ef2aSThomas Huth         case ASI_REAL:
2042fcf5ef2aSThomas Huth         case ASI_REAL_IO:
2043fcf5ef2aSThomas Huth         case ASI_REAL_L:
2044fcf5ef2aSThomas Huth         case ASI_REAL_IO_L:
2045fcf5ef2aSThomas Huth         case ASI_N:
2046fcf5ef2aSThomas Huth         case ASI_NL:
2047fcf5ef2aSThomas Huth         case ASI_AIUP:
2048fcf5ef2aSThomas Huth         case ASI_AIUPL:
2049fcf5ef2aSThomas Huth         case ASI_AIUS:
2050fcf5ef2aSThomas Huth         case ASI_AIUSL:
2051fcf5ef2aSThomas Huth         case ASI_S:
2052fcf5ef2aSThomas Huth         case ASI_SL:
2053fcf5ef2aSThomas Huth         case ASI_P:
2054fcf5ef2aSThomas Huth         case ASI_PL:
2055fcf5ef2aSThomas Huth             type = GET_ASI_DIRECT;
2056fcf5ef2aSThomas Huth             break;
2057fcf5ef2aSThomas Huth         case ASI_TWINX_REAL:
2058fcf5ef2aSThomas Huth         case ASI_TWINX_REAL_L:
2059fcf5ef2aSThomas Huth         case ASI_TWINX_N:
2060fcf5ef2aSThomas Huth         case ASI_TWINX_NL:
2061fcf5ef2aSThomas Huth         case ASI_TWINX_AIUP:
2062fcf5ef2aSThomas Huth         case ASI_TWINX_AIUP_L:
2063fcf5ef2aSThomas Huth         case ASI_TWINX_AIUS:
2064fcf5ef2aSThomas Huth         case ASI_TWINX_AIUS_L:
2065fcf5ef2aSThomas Huth         case ASI_TWINX_P:
2066fcf5ef2aSThomas Huth         case ASI_TWINX_PL:
2067fcf5ef2aSThomas Huth         case ASI_TWINX_S:
2068fcf5ef2aSThomas Huth         case ASI_TWINX_SL:
2069fcf5ef2aSThomas Huth         case ASI_QUAD_LDD_PHYS:
2070fcf5ef2aSThomas Huth         case ASI_QUAD_LDD_PHYS_L:
2071fcf5ef2aSThomas Huth         case ASI_NUCLEUS_QUAD_LDD:
2072fcf5ef2aSThomas Huth         case ASI_NUCLEUS_QUAD_LDD_L:
2073fcf5ef2aSThomas Huth             type = GET_ASI_DTWINX;
2074fcf5ef2aSThomas Huth             break;
2075fcf5ef2aSThomas Huth         case ASI_BLK_COMMIT_P:
2076fcf5ef2aSThomas Huth         case ASI_BLK_COMMIT_S:
2077fcf5ef2aSThomas Huth         case ASI_BLK_AIUP_4V:
2078fcf5ef2aSThomas Huth         case ASI_BLK_AIUP_L_4V:
2079fcf5ef2aSThomas Huth         case ASI_BLK_AIUP:
2080fcf5ef2aSThomas Huth         case ASI_BLK_AIUPL:
2081fcf5ef2aSThomas Huth         case ASI_BLK_AIUS_4V:
2082fcf5ef2aSThomas Huth         case ASI_BLK_AIUS_L_4V:
2083fcf5ef2aSThomas Huth         case ASI_BLK_AIUS:
2084fcf5ef2aSThomas Huth         case ASI_BLK_AIUSL:
2085fcf5ef2aSThomas Huth         case ASI_BLK_S:
2086fcf5ef2aSThomas Huth         case ASI_BLK_SL:
2087fcf5ef2aSThomas Huth         case ASI_BLK_P:
2088fcf5ef2aSThomas Huth         case ASI_BLK_PL:
2089fcf5ef2aSThomas Huth             type = GET_ASI_BLOCK;
2090fcf5ef2aSThomas Huth             break;
2091fcf5ef2aSThomas Huth         case ASI_FL8_S:
2092fcf5ef2aSThomas Huth         case ASI_FL8_SL:
2093fcf5ef2aSThomas Huth         case ASI_FL8_P:
2094fcf5ef2aSThomas Huth         case ASI_FL8_PL:
2095fcf5ef2aSThomas Huth             memop = MO_UB;
2096fcf5ef2aSThomas Huth             type = GET_ASI_SHORT;
2097fcf5ef2aSThomas Huth             break;
2098fcf5ef2aSThomas Huth         case ASI_FL16_S:
2099fcf5ef2aSThomas Huth         case ASI_FL16_SL:
2100fcf5ef2aSThomas Huth         case ASI_FL16_P:
2101fcf5ef2aSThomas Huth         case ASI_FL16_PL:
2102fcf5ef2aSThomas Huth             memop = MO_TEUW;
2103fcf5ef2aSThomas Huth             type = GET_ASI_SHORT;
2104fcf5ef2aSThomas Huth             break;
2105fcf5ef2aSThomas Huth         }
2106fcf5ef2aSThomas Huth         /* The little-endian asis all have bit 3 set.  */
2107fcf5ef2aSThomas Huth         if (asi & 8) {
2108fcf5ef2aSThomas Huth             memop ^= MO_BSWAP;
2109fcf5ef2aSThomas Huth         }
2110fcf5ef2aSThomas Huth     }
2111fcf5ef2aSThomas Huth #endif
2112fcf5ef2aSThomas Huth 
2113811cc0b0SRichard Henderson  done:
2114fcf5ef2aSThomas Huth     return (DisasASI){ type, asi, mem_idx, memop };
2115fcf5ef2aSThomas Huth }
2116fcf5ef2aSThomas Huth 
2117a76779eeSRichard Henderson #if defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
2118a76779eeSRichard Henderson static void gen_helper_ld_asi(TCGv_i64 r, TCGv_env e, TCGv a,
2119a76779eeSRichard Henderson                               TCGv_i32 asi, TCGv_i32 mop)
2120a76779eeSRichard Henderson {
2121a76779eeSRichard Henderson     g_assert_not_reached();
2122a76779eeSRichard Henderson }
2123a76779eeSRichard Henderson 
2124a76779eeSRichard Henderson static void gen_helper_st_asi(TCGv_env e, TCGv a, TCGv_i64 r,
2125a76779eeSRichard Henderson                               TCGv_i32 asi, TCGv_i32 mop)
2126a76779eeSRichard Henderson {
2127a76779eeSRichard Henderson     g_assert_not_reached();
2128a76779eeSRichard Henderson }
2129a76779eeSRichard Henderson #endif
2130a76779eeSRichard Henderson 
213142071fc1SRichard Henderson static void gen_ld_asi(DisasContext *dc, DisasASI *da, TCGv dst, TCGv addr)
2132fcf5ef2aSThomas Huth {
2133c03a0fd1SRichard Henderson     switch (da->type) {
2134fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
2135fcf5ef2aSThomas Huth         break;
2136fcf5ef2aSThomas Huth     case GET_ASI_DTWINX: /* Reserved for ldda.  */
2137fcf5ef2aSThomas Huth         gen_exception(dc, TT_ILL_INSN);
2138fcf5ef2aSThomas Huth         break;
2139fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
2140c03a0fd1SRichard Henderson         tcg_gen_qemu_ld_tl(dst, addr, da->mem_idx, da->memop | MO_ALIGN);
2141fcf5ef2aSThomas Huth         break;
2142fcf5ef2aSThomas Huth     default:
2143fcf5ef2aSThomas Huth         {
2144c03a0fd1SRichard Henderson             TCGv_i32 r_asi = tcg_constant_i32(da->asi);
2145c03a0fd1SRichard Henderson             TCGv_i32 r_mop = tcg_constant_i32(da->memop | MO_ALIGN);
2146fcf5ef2aSThomas Huth 
2147fcf5ef2aSThomas Huth             save_state(dc);
2148fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
2149ad75a51eSRichard Henderson             gen_helper_ld_asi(dst, tcg_env, addr, r_asi, r_mop);
2150fcf5ef2aSThomas Huth #else
2151fcf5ef2aSThomas Huth             {
2152fcf5ef2aSThomas Huth                 TCGv_i64 t64 = tcg_temp_new_i64();
2153ad75a51eSRichard Henderson                 gen_helper_ld_asi(t64, tcg_env, addr, r_asi, r_mop);
2154fcf5ef2aSThomas Huth                 tcg_gen_trunc_i64_tl(dst, t64);
2155fcf5ef2aSThomas Huth             }
2156fcf5ef2aSThomas Huth #endif
2157fcf5ef2aSThomas Huth         }
2158fcf5ef2aSThomas Huth         break;
2159fcf5ef2aSThomas Huth     }
2160fcf5ef2aSThomas Huth }
2161fcf5ef2aSThomas Huth 
216242071fc1SRichard Henderson static void gen_st_asi(DisasContext *dc, DisasASI *da, TCGv src, TCGv addr)
2163c03a0fd1SRichard Henderson {
2164c03a0fd1SRichard Henderson     switch (da->type) {
2165fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
2166fcf5ef2aSThomas Huth         break;
2167c03a0fd1SRichard Henderson 
2168fcf5ef2aSThomas Huth     case GET_ASI_DTWINX: /* Reserved for stda.  */
2169c03a0fd1SRichard Henderson         if (TARGET_LONG_BITS == 32) {
2170fcf5ef2aSThomas Huth             gen_exception(dc, TT_ILL_INSN);
2171fcf5ef2aSThomas Huth             break;
2172c03a0fd1SRichard Henderson         } else if (!(dc->def->features & CPU_FEATURE_HYPV)) {
21733390537bSArtyom Tarasenko             /* Pre OpenSPARC CPUs don't have these */
21743390537bSArtyom Tarasenko             gen_exception(dc, TT_ILL_INSN);
2175fcf5ef2aSThomas Huth             break;
2176c03a0fd1SRichard Henderson         }
2177c03a0fd1SRichard Henderson         /* In OpenSPARC T1+ CPUs TWINX ASIs in store are ST_BLKINIT_ ASIs */
2178c03a0fd1SRichard Henderson         /* fall through */
2179c03a0fd1SRichard Henderson 
2180c03a0fd1SRichard Henderson     case GET_ASI_DIRECT:
2181c03a0fd1SRichard Henderson         tcg_gen_qemu_st_tl(src, addr, da->mem_idx, da->memop | MO_ALIGN);
2182c03a0fd1SRichard Henderson         break;
2183c03a0fd1SRichard Henderson 
2184fcf5ef2aSThomas Huth     case GET_ASI_BCOPY:
2185c03a0fd1SRichard Henderson         assert(TARGET_LONG_BITS == 32);
2186fcf5ef2aSThomas Huth         /* Copy 32 bytes from the address in SRC to ADDR.  */
2187fcf5ef2aSThomas Huth         /* ??? The original qemu code suggests 4-byte alignment, dropping
2188fcf5ef2aSThomas Huth            the low bits, but the only place I can see this used is in the
2189fcf5ef2aSThomas Huth            Linux kernel with 32 byte alignment, which would make more sense
2190fcf5ef2aSThomas Huth            as a cacheline-style operation.  */
2191fcf5ef2aSThomas Huth         {
2192fcf5ef2aSThomas Huth             TCGv saddr = tcg_temp_new();
2193fcf5ef2aSThomas Huth             TCGv daddr = tcg_temp_new();
219400ab7e61SRichard Henderson             TCGv four = tcg_constant_tl(4);
2195fcf5ef2aSThomas Huth             TCGv_i32 tmp = tcg_temp_new_i32();
2196fcf5ef2aSThomas Huth             int i;
2197fcf5ef2aSThomas Huth 
2198fcf5ef2aSThomas Huth             tcg_gen_andi_tl(saddr, src, -4);
2199fcf5ef2aSThomas Huth             tcg_gen_andi_tl(daddr, addr, -4);
2200fcf5ef2aSThomas Huth             for (i = 0; i < 32; i += 4) {
2201fcf5ef2aSThomas Huth                 /* Since the loads and stores are paired, allow the
2202fcf5ef2aSThomas Huth                    copy to happen in the host endianness.  */
2203c03a0fd1SRichard Henderson                 tcg_gen_qemu_ld_i32(tmp, saddr, da->mem_idx, MO_UL);
2204c03a0fd1SRichard Henderson                 tcg_gen_qemu_st_i32(tmp, daddr, da->mem_idx, MO_UL);
2205fcf5ef2aSThomas Huth                 tcg_gen_add_tl(saddr, saddr, four);
2206fcf5ef2aSThomas Huth                 tcg_gen_add_tl(daddr, daddr, four);
2207fcf5ef2aSThomas Huth             }
2208fcf5ef2aSThomas Huth         }
2209fcf5ef2aSThomas Huth         break;
2210c03a0fd1SRichard Henderson 
2211fcf5ef2aSThomas Huth     default:
2212fcf5ef2aSThomas Huth         {
2213c03a0fd1SRichard Henderson             TCGv_i32 r_asi = tcg_constant_i32(da->asi);
2214c03a0fd1SRichard Henderson             TCGv_i32 r_mop = tcg_constant_i32(da->memop | MO_ALIGN);
2215fcf5ef2aSThomas Huth 
2216fcf5ef2aSThomas Huth             save_state(dc);
2217fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
2218ad75a51eSRichard Henderson             gen_helper_st_asi(tcg_env, addr, src, r_asi, r_mop);
2219fcf5ef2aSThomas Huth #else
2220fcf5ef2aSThomas Huth             {
2221fcf5ef2aSThomas Huth                 TCGv_i64 t64 = tcg_temp_new_i64();
2222fcf5ef2aSThomas Huth                 tcg_gen_extu_tl_i64(t64, src);
2223ad75a51eSRichard Henderson                 gen_helper_st_asi(tcg_env, addr, t64, r_asi, r_mop);
2224fcf5ef2aSThomas Huth             }
2225fcf5ef2aSThomas Huth #endif
2226fcf5ef2aSThomas Huth 
2227fcf5ef2aSThomas Huth             /* A write to a TLB register may alter page maps.  End the TB. */
2228fcf5ef2aSThomas Huth             dc->npc = DYNAMIC_PC;
2229fcf5ef2aSThomas Huth         }
2230fcf5ef2aSThomas Huth         break;
2231fcf5ef2aSThomas Huth     }
2232fcf5ef2aSThomas Huth }
2233fcf5ef2aSThomas Huth 
2234dca544b9SRichard Henderson static void gen_swap_asi(DisasContext *dc, DisasASI *da,
2235c03a0fd1SRichard Henderson                          TCGv dst, TCGv src, TCGv addr)
2236c03a0fd1SRichard Henderson {
2237c03a0fd1SRichard Henderson     switch (da->type) {
2238c03a0fd1SRichard Henderson     case GET_ASI_EXCP:
2239c03a0fd1SRichard Henderson         break;
2240c03a0fd1SRichard Henderson     case GET_ASI_DIRECT:
2241dca544b9SRichard Henderson         tcg_gen_atomic_xchg_tl(dst, addr, src,
2242dca544b9SRichard Henderson                                da->mem_idx, da->memop | MO_ALIGN);
2243c03a0fd1SRichard Henderson         break;
2244c03a0fd1SRichard Henderson     default:
2245c03a0fd1SRichard Henderson         /* ??? Should be DAE_invalid_asi.  */
2246c03a0fd1SRichard Henderson         gen_exception(dc, TT_DATA_ACCESS);
2247c03a0fd1SRichard Henderson         break;
2248c03a0fd1SRichard Henderson     }
2249c03a0fd1SRichard Henderson }
2250c03a0fd1SRichard Henderson 
2251d0a11d25SRichard Henderson static void gen_cas_asi(DisasContext *dc, DisasASI *da,
2252c03a0fd1SRichard Henderson                         TCGv oldv, TCGv newv, TCGv cmpv, TCGv addr)
2253c03a0fd1SRichard Henderson {
2254c03a0fd1SRichard Henderson     switch (da->type) {
2255fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
2256c03a0fd1SRichard Henderson         return;
2257fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
2258c03a0fd1SRichard Henderson         tcg_gen_atomic_cmpxchg_tl(oldv, addr, cmpv, newv,
2259c03a0fd1SRichard Henderson                                   da->mem_idx, da->memop | MO_ALIGN);
2260fcf5ef2aSThomas Huth         break;
2261fcf5ef2aSThomas Huth     default:
2262fcf5ef2aSThomas Huth         /* ??? Should be DAE_invalid_asi.  */
2263fcf5ef2aSThomas Huth         gen_exception(dc, TT_DATA_ACCESS);
2264fcf5ef2aSThomas Huth         break;
2265fcf5ef2aSThomas Huth     }
2266fcf5ef2aSThomas Huth }
2267fcf5ef2aSThomas Huth 
2268cf07cd1eSRichard Henderson static void gen_ldstub_asi(DisasContext *dc, DisasASI *da, TCGv dst, TCGv addr)
2269c03a0fd1SRichard Henderson {
2270c03a0fd1SRichard Henderson     switch (da->type) {
2271fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
2272fcf5ef2aSThomas Huth         break;
2273fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
2274cf07cd1eSRichard Henderson         tcg_gen_atomic_xchg_tl(dst, addr, tcg_constant_tl(0xff),
2275cf07cd1eSRichard Henderson                                da->mem_idx, MO_UB);
2276fcf5ef2aSThomas Huth         break;
2277fcf5ef2aSThomas Huth     default:
22783db010c3SRichard Henderson         /* ??? In theory, this should be raise DAE_invalid_asi.
22793db010c3SRichard Henderson            But the SS-20 roms do ldstuba [%l0] #ASI_M_CTL, %o1.  */
2280af00be49SEmilio G. Cota         if (tb_cflags(dc->base.tb) & CF_PARALLEL) {
2281ad75a51eSRichard Henderson             gen_helper_exit_atomic(tcg_env);
22823db010c3SRichard Henderson         } else {
2283c03a0fd1SRichard Henderson             TCGv_i32 r_asi = tcg_constant_i32(da->asi);
228400ab7e61SRichard Henderson             TCGv_i32 r_mop = tcg_constant_i32(MO_UB);
22853db010c3SRichard Henderson             TCGv_i64 s64, t64;
22863db010c3SRichard Henderson 
22873db010c3SRichard Henderson             save_state(dc);
22883db010c3SRichard Henderson             t64 = tcg_temp_new_i64();
2289ad75a51eSRichard Henderson             gen_helper_ld_asi(t64, tcg_env, addr, r_asi, r_mop);
22903db010c3SRichard Henderson 
229100ab7e61SRichard Henderson             s64 = tcg_constant_i64(0xff);
2292ad75a51eSRichard Henderson             gen_helper_st_asi(tcg_env, addr, s64, r_asi, r_mop);
22933db010c3SRichard Henderson 
22943db010c3SRichard Henderson             tcg_gen_trunc_i64_tl(dst, t64);
22953db010c3SRichard Henderson 
22963db010c3SRichard Henderson             /* End the TB.  */
22973db010c3SRichard Henderson             dc->npc = DYNAMIC_PC;
22983db010c3SRichard Henderson         }
2299fcf5ef2aSThomas Huth         break;
2300fcf5ef2aSThomas Huth     }
2301fcf5ef2aSThomas Huth }
2302fcf5ef2aSThomas Huth 
2303287b1152SRichard Henderson static void gen_ldf_asi(DisasContext *dc, DisasASI *da, MemOp orig_size,
23043259b9e2SRichard Henderson                         TCGv addr, int rd)
2305fcf5ef2aSThomas Huth {
23063259b9e2SRichard Henderson     MemOp memop = da->memop;
23073259b9e2SRichard Henderson     MemOp size = memop & MO_SIZE;
2308fcf5ef2aSThomas Huth     TCGv_i32 d32;
2309fcf5ef2aSThomas Huth     TCGv_i64 d64;
2310287b1152SRichard Henderson     TCGv addr_tmp;
2311fcf5ef2aSThomas Huth 
23123259b9e2SRichard Henderson     /* TODO: Use 128-bit load/store below. */
23133259b9e2SRichard Henderson     if (size == MO_128) {
23143259b9e2SRichard Henderson         memop = (memop & ~MO_SIZE) | MO_64;
23153259b9e2SRichard Henderson     }
23163259b9e2SRichard Henderson 
23173259b9e2SRichard Henderson     switch (da->type) {
2318fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
2319fcf5ef2aSThomas Huth         break;
2320fcf5ef2aSThomas Huth 
2321fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
23223259b9e2SRichard Henderson         memop |= MO_ALIGN_4;
2323fcf5ef2aSThomas Huth         switch (size) {
23243259b9e2SRichard Henderson         case MO_32:
2325fcf5ef2aSThomas Huth             d32 = gen_dest_fpr_F(dc);
23263259b9e2SRichard Henderson             tcg_gen_qemu_ld_i32(d32, addr, da->mem_idx, memop);
2327fcf5ef2aSThomas Huth             gen_store_fpr_F(dc, rd, d32);
2328fcf5ef2aSThomas Huth             break;
23293259b9e2SRichard Henderson 
23303259b9e2SRichard Henderson         case MO_64:
23313259b9e2SRichard Henderson             tcg_gen_qemu_ld_i64(cpu_fpr[rd / 2], addr, da->mem_idx, memop);
2332fcf5ef2aSThomas Huth             break;
23333259b9e2SRichard Henderson 
23343259b9e2SRichard Henderson         case MO_128:
2335fcf5ef2aSThomas Huth             d64 = tcg_temp_new_i64();
23363259b9e2SRichard Henderson             tcg_gen_qemu_ld_i64(d64, addr, da->mem_idx, memop);
2337287b1152SRichard Henderson             addr_tmp = tcg_temp_new();
2338287b1152SRichard Henderson             tcg_gen_addi_tl(addr_tmp, addr, 8);
2339287b1152SRichard Henderson             tcg_gen_qemu_ld_i64(cpu_fpr[rd / 2 + 1], addr_tmp, da->mem_idx, memop);
2340fcf5ef2aSThomas Huth             tcg_gen_mov_i64(cpu_fpr[rd / 2], d64);
2341fcf5ef2aSThomas Huth             break;
2342fcf5ef2aSThomas Huth         default:
2343fcf5ef2aSThomas Huth             g_assert_not_reached();
2344fcf5ef2aSThomas Huth         }
2345fcf5ef2aSThomas Huth         break;
2346fcf5ef2aSThomas Huth 
2347fcf5ef2aSThomas Huth     case GET_ASI_BLOCK:
2348fcf5ef2aSThomas Huth         /* Valid for lddfa on aligned registers only.  */
23493259b9e2SRichard Henderson         if (orig_size == MO_64 && (rd & 7) == 0) {
2350fcf5ef2aSThomas Huth             /* The first operation checks required alignment.  */
2351287b1152SRichard Henderson             addr_tmp = tcg_temp_new();
2352287b1152SRichard Henderson             for (int i = 0; ; ++i) {
23533259b9e2SRichard Henderson                 tcg_gen_qemu_ld_i64(cpu_fpr[rd / 2 + i], addr, da->mem_idx,
23543259b9e2SRichard Henderson                                     memop | (i == 0 ? MO_ALIGN_64 : 0));
2355fcf5ef2aSThomas Huth                 if (i == 7) {
2356fcf5ef2aSThomas Huth                     break;
2357fcf5ef2aSThomas Huth                 }
2358287b1152SRichard Henderson                 tcg_gen_addi_tl(addr_tmp, addr, 8);
2359287b1152SRichard Henderson                 addr = addr_tmp;
2360fcf5ef2aSThomas Huth             }
2361fcf5ef2aSThomas Huth         } else {
2362fcf5ef2aSThomas Huth             gen_exception(dc, TT_ILL_INSN);
2363fcf5ef2aSThomas Huth         }
2364fcf5ef2aSThomas Huth         break;
2365fcf5ef2aSThomas Huth 
2366fcf5ef2aSThomas Huth     case GET_ASI_SHORT:
2367fcf5ef2aSThomas Huth         /* Valid for lddfa only.  */
23683259b9e2SRichard Henderson         if (orig_size == MO_64) {
23693259b9e2SRichard Henderson             tcg_gen_qemu_ld_i64(cpu_fpr[rd / 2], addr, da->mem_idx,
23703259b9e2SRichard Henderson                                 memop | MO_ALIGN);
2371fcf5ef2aSThomas Huth         } else {
2372fcf5ef2aSThomas Huth             gen_exception(dc, TT_ILL_INSN);
2373fcf5ef2aSThomas Huth         }
2374fcf5ef2aSThomas Huth         break;
2375fcf5ef2aSThomas Huth 
2376fcf5ef2aSThomas Huth     default:
2377fcf5ef2aSThomas Huth         {
23783259b9e2SRichard Henderson             TCGv_i32 r_asi = tcg_constant_i32(da->asi);
23793259b9e2SRichard Henderson             TCGv_i32 r_mop = tcg_constant_i32(memop | MO_ALIGN);
2380fcf5ef2aSThomas Huth 
2381fcf5ef2aSThomas Huth             save_state(dc);
2382fcf5ef2aSThomas Huth             /* According to the table in the UA2011 manual, the only
2383fcf5ef2aSThomas Huth                other asis that are valid for ldfa/lddfa/ldqfa are
2384fcf5ef2aSThomas Huth                the NO_FAULT asis.  We still need a helper for these,
2385fcf5ef2aSThomas Huth                but we can just use the integer asi helper for them.  */
2386fcf5ef2aSThomas Huth             switch (size) {
23873259b9e2SRichard Henderson             case MO_32:
2388fcf5ef2aSThomas Huth                 d64 = tcg_temp_new_i64();
2389ad75a51eSRichard Henderson                 gen_helper_ld_asi(d64, tcg_env, addr, r_asi, r_mop);
2390fcf5ef2aSThomas Huth                 d32 = gen_dest_fpr_F(dc);
2391fcf5ef2aSThomas Huth                 tcg_gen_extrl_i64_i32(d32, d64);
2392fcf5ef2aSThomas Huth                 gen_store_fpr_F(dc, rd, d32);
2393fcf5ef2aSThomas Huth                 break;
23943259b9e2SRichard Henderson             case MO_64:
23953259b9e2SRichard Henderson                 gen_helper_ld_asi(cpu_fpr[rd / 2], tcg_env, addr,
23963259b9e2SRichard Henderson                                   r_asi, r_mop);
2397fcf5ef2aSThomas Huth                 break;
23983259b9e2SRichard Henderson             case MO_128:
2399fcf5ef2aSThomas Huth                 d64 = tcg_temp_new_i64();
2400ad75a51eSRichard Henderson                 gen_helper_ld_asi(d64, tcg_env, addr, r_asi, r_mop);
2401287b1152SRichard Henderson                 addr_tmp = tcg_temp_new();
2402287b1152SRichard Henderson                 tcg_gen_addi_tl(addr_tmp, addr, 8);
2403287b1152SRichard Henderson                 gen_helper_ld_asi(cpu_fpr[rd / 2 + 1], tcg_env, addr_tmp,
24043259b9e2SRichard Henderson                                   r_asi, r_mop);
2405fcf5ef2aSThomas Huth                 tcg_gen_mov_i64(cpu_fpr[rd / 2], d64);
2406fcf5ef2aSThomas Huth                 break;
2407fcf5ef2aSThomas Huth             default:
2408fcf5ef2aSThomas Huth                 g_assert_not_reached();
2409fcf5ef2aSThomas Huth             }
2410fcf5ef2aSThomas Huth         }
2411fcf5ef2aSThomas Huth         break;
2412fcf5ef2aSThomas Huth     }
2413fcf5ef2aSThomas Huth }
2414fcf5ef2aSThomas Huth 
2415287b1152SRichard Henderson static void gen_stf_asi(DisasContext *dc, DisasASI *da, MemOp orig_size,
24163259b9e2SRichard Henderson                         TCGv addr, int rd)
24173259b9e2SRichard Henderson {
24183259b9e2SRichard Henderson     MemOp memop = da->memop;
24193259b9e2SRichard Henderson     MemOp size = memop & MO_SIZE;
2420fcf5ef2aSThomas Huth     TCGv_i32 d32;
2421287b1152SRichard Henderson     TCGv addr_tmp;
2422fcf5ef2aSThomas Huth 
24233259b9e2SRichard Henderson     /* TODO: Use 128-bit load/store below. */
24243259b9e2SRichard Henderson     if (size == MO_128) {
24253259b9e2SRichard Henderson         memop = (memop & ~MO_SIZE) | MO_64;
24263259b9e2SRichard Henderson     }
24273259b9e2SRichard Henderson 
24283259b9e2SRichard Henderson     switch (da->type) {
2429fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
2430fcf5ef2aSThomas Huth         break;
2431fcf5ef2aSThomas Huth 
2432fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
24333259b9e2SRichard Henderson         memop |= MO_ALIGN_4;
2434fcf5ef2aSThomas Huth         switch (size) {
24353259b9e2SRichard Henderson         case MO_32:
2436fcf5ef2aSThomas Huth             d32 = gen_load_fpr_F(dc, rd);
24373259b9e2SRichard Henderson             tcg_gen_qemu_st_i32(d32, addr, da->mem_idx, memop | MO_ALIGN);
2438fcf5ef2aSThomas Huth             break;
24393259b9e2SRichard Henderson         case MO_64:
24403259b9e2SRichard Henderson             tcg_gen_qemu_st_i64(cpu_fpr[rd / 2], addr, da->mem_idx,
24413259b9e2SRichard Henderson                                 memop | MO_ALIGN_4);
2442fcf5ef2aSThomas Huth             break;
24433259b9e2SRichard Henderson         case MO_128:
2444fcf5ef2aSThomas Huth             /* Only 4-byte alignment required.  However, it is legal for the
2445fcf5ef2aSThomas Huth                cpu to signal the alignment fault, and the OS trap handler is
2446fcf5ef2aSThomas Huth                required to fix it up.  Requiring 16-byte alignment here avoids
2447fcf5ef2aSThomas Huth                having to probe the second page before performing the first
2448fcf5ef2aSThomas Huth                write.  */
24493259b9e2SRichard Henderson             tcg_gen_qemu_st_i64(cpu_fpr[rd / 2], addr, da->mem_idx,
24503259b9e2SRichard Henderson                                 memop | MO_ALIGN_16);
2451287b1152SRichard Henderson             addr_tmp = tcg_temp_new();
2452287b1152SRichard Henderson             tcg_gen_addi_tl(addr_tmp, addr, 8);
2453287b1152SRichard Henderson             tcg_gen_qemu_st_i64(cpu_fpr[rd / 2 + 1], addr_tmp, da->mem_idx, memop);
2454fcf5ef2aSThomas Huth             break;
2455fcf5ef2aSThomas Huth         default:
2456fcf5ef2aSThomas Huth             g_assert_not_reached();
2457fcf5ef2aSThomas Huth         }
2458fcf5ef2aSThomas Huth         break;
2459fcf5ef2aSThomas Huth 
2460fcf5ef2aSThomas Huth     case GET_ASI_BLOCK:
2461fcf5ef2aSThomas Huth         /* Valid for stdfa on aligned registers only.  */
24623259b9e2SRichard Henderson         if (orig_size == MO_64 && (rd & 7) == 0) {
2463fcf5ef2aSThomas Huth             /* The first operation checks required alignment.  */
2464287b1152SRichard Henderson             addr_tmp = tcg_temp_new();
2465287b1152SRichard Henderson             for (int i = 0; ; ++i) {
24663259b9e2SRichard Henderson                 tcg_gen_qemu_st_i64(cpu_fpr[rd / 2 + i], addr, da->mem_idx,
24673259b9e2SRichard Henderson                                     memop | (i == 0 ? MO_ALIGN_64 : 0));
2468fcf5ef2aSThomas Huth                 if (i == 7) {
2469fcf5ef2aSThomas Huth                     break;
2470fcf5ef2aSThomas Huth                 }
2471287b1152SRichard Henderson                 tcg_gen_addi_tl(addr_tmp, addr, 8);
2472287b1152SRichard Henderson                 addr = addr_tmp;
2473fcf5ef2aSThomas Huth             }
2474fcf5ef2aSThomas Huth         } else {
2475fcf5ef2aSThomas Huth             gen_exception(dc, TT_ILL_INSN);
2476fcf5ef2aSThomas Huth         }
2477fcf5ef2aSThomas Huth         break;
2478fcf5ef2aSThomas Huth 
2479fcf5ef2aSThomas Huth     case GET_ASI_SHORT:
2480fcf5ef2aSThomas Huth         /* Valid for stdfa only.  */
24813259b9e2SRichard Henderson         if (orig_size == MO_64) {
24823259b9e2SRichard Henderson             tcg_gen_qemu_st_i64(cpu_fpr[rd / 2], addr, da->mem_idx,
24833259b9e2SRichard Henderson                                 memop | MO_ALIGN);
2484fcf5ef2aSThomas Huth         } else {
2485fcf5ef2aSThomas Huth             gen_exception(dc, TT_ILL_INSN);
2486fcf5ef2aSThomas Huth         }
2487fcf5ef2aSThomas Huth         break;
2488fcf5ef2aSThomas Huth 
2489fcf5ef2aSThomas Huth     default:
2490fcf5ef2aSThomas Huth         /* According to the table in the UA2011 manual, the only
2491fcf5ef2aSThomas Huth            other asis that are valid for ldfa/lddfa/ldqfa are
2492fcf5ef2aSThomas Huth            the PST* asis, which aren't currently handled.  */
2493fcf5ef2aSThomas Huth         gen_exception(dc, TT_ILL_INSN);
2494fcf5ef2aSThomas Huth         break;
2495fcf5ef2aSThomas Huth     }
2496fcf5ef2aSThomas Huth }
2497fcf5ef2aSThomas Huth 
249842071fc1SRichard Henderson static void gen_ldda_asi(DisasContext *dc, DisasASI *da, TCGv addr, int rd)
2499fcf5ef2aSThomas Huth {
2500a76779eeSRichard Henderson     TCGv hi = gen_dest_gpr(dc, rd);
2501a76779eeSRichard Henderson     TCGv lo = gen_dest_gpr(dc, rd + 1);
2502fcf5ef2aSThomas Huth 
2503c03a0fd1SRichard Henderson     switch (da->type) {
2504fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
2505fcf5ef2aSThomas Huth         return;
2506fcf5ef2aSThomas Huth 
2507fcf5ef2aSThomas Huth     case GET_ASI_DTWINX:
2508ebbbec92SRichard Henderson #ifdef TARGET_SPARC64
2509ebbbec92SRichard Henderson         {
2510ebbbec92SRichard Henderson             MemOp mop = (da->memop & MO_BSWAP) | MO_128 | MO_ALIGN_16;
2511ebbbec92SRichard Henderson             TCGv_i128 t = tcg_temp_new_i128();
2512ebbbec92SRichard Henderson 
2513ebbbec92SRichard Henderson             tcg_gen_qemu_ld_i128(t, addr, da->mem_idx, mop);
2514ebbbec92SRichard Henderson             /*
2515ebbbec92SRichard Henderson              * Note that LE twinx acts as if each 64-bit register result is
2516ebbbec92SRichard Henderson              * byte swapped.  We perform one 128-bit LE load, so must swap
2517ebbbec92SRichard Henderson              * the order of the writebacks.
2518ebbbec92SRichard Henderson              */
2519ebbbec92SRichard Henderson             if ((mop & MO_BSWAP) == MO_TE) {
2520ebbbec92SRichard Henderson                 tcg_gen_extr_i128_i64(lo, hi, t);
2521ebbbec92SRichard Henderson             } else {
2522ebbbec92SRichard Henderson                 tcg_gen_extr_i128_i64(hi, lo, t);
2523ebbbec92SRichard Henderson             }
2524ebbbec92SRichard Henderson         }
2525fcf5ef2aSThomas Huth         break;
2526ebbbec92SRichard Henderson #else
2527ebbbec92SRichard Henderson         g_assert_not_reached();
2528ebbbec92SRichard Henderson #endif
2529fcf5ef2aSThomas Huth 
2530fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
2531fcf5ef2aSThomas Huth         {
2532fcf5ef2aSThomas Huth             TCGv_i64 tmp = tcg_temp_new_i64();
2533fcf5ef2aSThomas Huth 
2534c03a0fd1SRichard Henderson             tcg_gen_qemu_ld_i64(tmp, addr, da->mem_idx, da->memop | MO_ALIGN);
2535fcf5ef2aSThomas Huth 
2536fcf5ef2aSThomas Huth             /* Note that LE ldda acts as if each 32-bit register
2537fcf5ef2aSThomas Huth                result is byte swapped.  Having just performed one
2538fcf5ef2aSThomas Huth                64-bit bswap, we need now to swap the writebacks.  */
2539c03a0fd1SRichard Henderson             if ((da->memop & MO_BSWAP) == MO_TE) {
2540a76779eeSRichard Henderson                 tcg_gen_extr_i64_tl(lo, hi, tmp);
2541fcf5ef2aSThomas Huth             } else {
2542a76779eeSRichard Henderson                 tcg_gen_extr_i64_tl(hi, lo, tmp);
2543fcf5ef2aSThomas Huth             }
2544fcf5ef2aSThomas Huth         }
2545fcf5ef2aSThomas Huth         break;
2546fcf5ef2aSThomas Huth 
2547fcf5ef2aSThomas Huth     default:
2548fcf5ef2aSThomas Huth         /* ??? In theory we've handled all of the ASIs that are valid
2549fcf5ef2aSThomas Huth            for ldda, and this should raise DAE_invalid_asi.  However,
2550fcf5ef2aSThomas Huth            real hardware allows others.  This can be seen with e.g.
2551fcf5ef2aSThomas Huth            FreeBSD 10.3 wrt ASI_IC_TAG.  */
2552fcf5ef2aSThomas Huth         {
2553c03a0fd1SRichard Henderson             TCGv_i32 r_asi = tcg_constant_i32(da->asi);
2554c03a0fd1SRichard Henderson             TCGv_i32 r_mop = tcg_constant_i32(da->memop);
2555fcf5ef2aSThomas Huth             TCGv_i64 tmp = tcg_temp_new_i64();
2556fcf5ef2aSThomas Huth 
2557fcf5ef2aSThomas Huth             save_state(dc);
2558ad75a51eSRichard Henderson             gen_helper_ld_asi(tmp, tcg_env, addr, r_asi, r_mop);
2559fcf5ef2aSThomas Huth 
2560fcf5ef2aSThomas Huth             /* See above.  */
2561c03a0fd1SRichard Henderson             if ((da->memop & MO_BSWAP) == MO_TE) {
2562a76779eeSRichard Henderson                 tcg_gen_extr_i64_tl(lo, hi, tmp);
2563fcf5ef2aSThomas Huth             } else {
2564a76779eeSRichard Henderson                 tcg_gen_extr_i64_tl(hi, lo, tmp);
2565fcf5ef2aSThomas Huth             }
2566fcf5ef2aSThomas Huth         }
2567fcf5ef2aSThomas Huth         break;
2568fcf5ef2aSThomas Huth     }
2569fcf5ef2aSThomas Huth 
2570fcf5ef2aSThomas Huth     gen_store_gpr(dc, rd, hi);
2571fcf5ef2aSThomas Huth     gen_store_gpr(dc, rd + 1, lo);
2572fcf5ef2aSThomas Huth }
2573fcf5ef2aSThomas Huth 
257442071fc1SRichard Henderson static void gen_stda_asi(DisasContext *dc, DisasASI *da, TCGv addr, int rd)
2575c03a0fd1SRichard Henderson {
2576c03a0fd1SRichard Henderson     TCGv hi = gen_load_gpr(dc, rd);
2577fcf5ef2aSThomas Huth     TCGv lo = gen_load_gpr(dc, rd + 1);
2578fcf5ef2aSThomas Huth 
2579c03a0fd1SRichard Henderson     switch (da->type) {
2580fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
2581fcf5ef2aSThomas Huth         break;
2582fcf5ef2aSThomas Huth 
2583fcf5ef2aSThomas Huth     case GET_ASI_DTWINX:
2584ebbbec92SRichard Henderson #ifdef TARGET_SPARC64
2585ebbbec92SRichard Henderson         {
2586ebbbec92SRichard Henderson             MemOp mop = (da->memop & MO_BSWAP) | MO_128 | MO_ALIGN_16;
2587ebbbec92SRichard Henderson             TCGv_i128 t = tcg_temp_new_i128();
2588ebbbec92SRichard Henderson 
2589ebbbec92SRichard Henderson             /*
2590ebbbec92SRichard Henderson              * Note that LE twinx acts as if each 64-bit register result is
2591ebbbec92SRichard Henderson              * byte swapped.  We perform one 128-bit LE store, so must swap
2592ebbbec92SRichard Henderson              * the order of the construction.
2593ebbbec92SRichard Henderson              */
2594ebbbec92SRichard Henderson             if ((mop & MO_BSWAP) == MO_TE) {
2595ebbbec92SRichard Henderson                 tcg_gen_concat_i64_i128(t, lo, hi);
2596ebbbec92SRichard Henderson             } else {
2597ebbbec92SRichard Henderson                 tcg_gen_concat_i64_i128(t, hi, lo);
2598ebbbec92SRichard Henderson             }
2599ebbbec92SRichard Henderson             tcg_gen_qemu_st_i128(t, addr, da->mem_idx, mop);
2600ebbbec92SRichard Henderson         }
2601fcf5ef2aSThomas Huth         break;
2602ebbbec92SRichard Henderson #else
2603ebbbec92SRichard Henderson         g_assert_not_reached();
2604ebbbec92SRichard Henderson #endif
2605fcf5ef2aSThomas Huth 
2606fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
2607fcf5ef2aSThomas Huth         {
2608fcf5ef2aSThomas Huth             TCGv_i64 t64 = tcg_temp_new_i64();
2609fcf5ef2aSThomas Huth 
2610fcf5ef2aSThomas Huth             /* Note that LE stda acts as if each 32-bit register result is
2611fcf5ef2aSThomas Huth                byte swapped.  We will perform one 64-bit LE store, so now
2612fcf5ef2aSThomas Huth                we must swap the order of the construction.  */
2613c03a0fd1SRichard Henderson             if ((da->memop & MO_BSWAP) == MO_TE) {
2614a76779eeSRichard Henderson                 tcg_gen_concat_tl_i64(t64, lo, hi);
2615fcf5ef2aSThomas Huth             } else {
2616a76779eeSRichard Henderson                 tcg_gen_concat_tl_i64(t64, hi, lo);
2617fcf5ef2aSThomas Huth             }
2618c03a0fd1SRichard Henderson             tcg_gen_qemu_st_i64(t64, addr, da->mem_idx, da->memop | MO_ALIGN);
2619fcf5ef2aSThomas Huth         }
2620fcf5ef2aSThomas Huth         break;
2621fcf5ef2aSThomas Huth 
2622a76779eeSRichard Henderson     case GET_ASI_BFILL:
2623a76779eeSRichard Henderson         assert(TARGET_LONG_BITS == 32);
2624a76779eeSRichard Henderson         /* Store 32 bytes of T64 to ADDR.  */
2625a76779eeSRichard Henderson         /* ??? The original qemu code suggests 8-byte alignment, dropping
2626a76779eeSRichard Henderson            the low bits, but the only place I can see this used is in the
2627a76779eeSRichard Henderson            Linux kernel with 32 byte alignment, which would make more sense
2628a76779eeSRichard Henderson            as a cacheline-style operation.  */
2629a76779eeSRichard Henderson         {
2630a76779eeSRichard Henderson             TCGv_i64 t64 = tcg_temp_new_i64();
2631a76779eeSRichard Henderson             TCGv d_addr = tcg_temp_new();
2632a76779eeSRichard Henderson             TCGv eight = tcg_constant_tl(8);
2633a76779eeSRichard Henderson             int i;
2634a76779eeSRichard Henderson 
2635a76779eeSRichard Henderson             tcg_gen_concat_tl_i64(t64, lo, hi);
2636a76779eeSRichard Henderson             tcg_gen_andi_tl(d_addr, addr, -8);
2637a76779eeSRichard Henderson             for (i = 0; i < 32; i += 8) {
2638c03a0fd1SRichard Henderson                 tcg_gen_qemu_st_i64(t64, d_addr, da->mem_idx, da->memop);
2639a76779eeSRichard Henderson                 tcg_gen_add_tl(d_addr, d_addr, eight);
2640a76779eeSRichard Henderson             }
2641a76779eeSRichard Henderson         }
2642a76779eeSRichard Henderson         break;
2643a76779eeSRichard Henderson 
2644fcf5ef2aSThomas Huth     default:
2645fcf5ef2aSThomas Huth         /* ??? In theory we've handled all of the ASIs that are valid
2646fcf5ef2aSThomas Huth            for stda, and this should raise DAE_invalid_asi.  */
2647fcf5ef2aSThomas Huth         {
2648c03a0fd1SRichard Henderson             TCGv_i32 r_asi = tcg_constant_i32(da->asi);
2649c03a0fd1SRichard Henderson             TCGv_i32 r_mop = tcg_constant_i32(da->memop);
2650fcf5ef2aSThomas Huth             TCGv_i64 t64 = tcg_temp_new_i64();
2651fcf5ef2aSThomas Huth 
2652fcf5ef2aSThomas Huth             /* See above.  */
2653c03a0fd1SRichard Henderson             if ((da->memop & MO_BSWAP) == MO_TE) {
2654a76779eeSRichard Henderson                 tcg_gen_concat_tl_i64(t64, lo, hi);
2655fcf5ef2aSThomas Huth             } else {
2656a76779eeSRichard Henderson                 tcg_gen_concat_tl_i64(t64, hi, lo);
2657fcf5ef2aSThomas Huth             }
2658fcf5ef2aSThomas Huth 
2659fcf5ef2aSThomas Huth             save_state(dc);
2660ad75a51eSRichard Henderson             gen_helper_st_asi(tcg_env, addr, t64, r_asi, r_mop);
2661fcf5ef2aSThomas Huth         }
2662fcf5ef2aSThomas Huth         break;
2663fcf5ef2aSThomas Huth     }
2664fcf5ef2aSThomas Huth }
2665fcf5ef2aSThomas Huth 
26663d3c0673SRichard Henderson #ifdef TARGET_SPARC64
2667fcf5ef2aSThomas Huth static TCGv get_src1(DisasContext *dc, unsigned int insn)
2668fcf5ef2aSThomas Huth {
2669fcf5ef2aSThomas Huth     unsigned int rs1 = GET_FIELD(insn, 13, 17);
2670fcf5ef2aSThomas Huth     return gen_load_gpr(dc, rs1);
2671fcf5ef2aSThomas Huth }
2672fcf5ef2aSThomas Huth 
2673fcf5ef2aSThomas Huth static void gen_fmovs(DisasContext *dc, DisasCompare *cmp, int rd, int rs)
2674fcf5ef2aSThomas Huth {
2675fcf5ef2aSThomas Huth     TCGv_i32 c32, zero, dst, s1, s2;
2676fcf5ef2aSThomas Huth 
2677fcf5ef2aSThomas Huth     /* We have two choices here: extend the 32 bit data and use movcond_i64,
2678fcf5ef2aSThomas Huth        or fold the comparison down to 32 bits and use movcond_i32.  Choose
2679fcf5ef2aSThomas Huth        the later.  */
2680fcf5ef2aSThomas Huth     c32 = tcg_temp_new_i32();
2681fcf5ef2aSThomas Huth     if (cmp->is_bool) {
2682fcf5ef2aSThomas Huth         tcg_gen_extrl_i64_i32(c32, cmp->c1);
2683fcf5ef2aSThomas Huth     } else {
2684fcf5ef2aSThomas Huth         TCGv_i64 c64 = tcg_temp_new_i64();
2685fcf5ef2aSThomas Huth         tcg_gen_setcond_i64(cmp->cond, c64, cmp->c1, cmp->c2);
2686fcf5ef2aSThomas Huth         tcg_gen_extrl_i64_i32(c32, c64);
2687fcf5ef2aSThomas Huth     }
2688fcf5ef2aSThomas Huth 
2689fcf5ef2aSThomas Huth     s1 = gen_load_fpr_F(dc, rs);
2690fcf5ef2aSThomas Huth     s2 = gen_load_fpr_F(dc, rd);
2691fcf5ef2aSThomas Huth     dst = gen_dest_fpr_F(dc);
269200ab7e61SRichard Henderson     zero = tcg_constant_i32(0);
2693fcf5ef2aSThomas Huth 
2694fcf5ef2aSThomas Huth     tcg_gen_movcond_i32(TCG_COND_NE, dst, c32, zero, s1, s2);
2695fcf5ef2aSThomas Huth 
2696fcf5ef2aSThomas Huth     gen_store_fpr_F(dc, rd, dst);
2697fcf5ef2aSThomas Huth }
2698fcf5ef2aSThomas Huth 
2699fcf5ef2aSThomas Huth static void gen_fmovd(DisasContext *dc, DisasCompare *cmp, int rd, int rs)
2700fcf5ef2aSThomas Huth {
2701fcf5ef2aSThomas Huth     TCGv_i64 dst = gen_dest_fpr_D(dc, rd);
2702fcf5ef2aSThomas Huth     tcg_gen_movcond_i64(cmp->cond, dst, cmp->c1, cmp->c2,
2703fcf5ef2aSThomas Huth                         gen_load_fpr_D(dc, rs),
2704fcf5ef2aSThomas Huth                         gen_load_fpr_D(dc, rd));
2705fcf5ef2aSThomas Huth     gen_store_fpr_D(dc, rd, dst);
2706fcf5ef2aSThomas Huth }
2707fcf5ef2aSThomas Huth 
2708fcf5ef2aSThomas Huth static void gen_fmovq(DisasContext *dc, DisasCompare *cmp, int rd, int rs)
2709fcf5ef2aSThomas Huth {
2710fcf5ef2aSThomas Huth     int qd = QFPREG(rd);
2711fcf5ef2aSThomas Huth     int qs = QFPREG(rs);
2712fcf5ef2aSThomas Huth 
2713fcf5ef2aSThomas Huth     tcg_gen_movcond_i64(cmp->cond, cpu_fpr[qd / 2], cmp->c1, cmp->c2,
2714fcf5ef2aSThomas Huth                         cpu_fpr[qs / 2], cpu_fpr[qd / 2]);
2715fcf5ef2aSThomas Huth     tcg_gen_movcond_i64(cmp->cond, cpu_fpr[qd / 2 + 1], cmp->c1, cmp->c2,
2716fcf5ef2aSThomas Huth                         cpu_fpr[qs / 2 + 1], cpu_fpr[qd / 2 + 1]);
2717fcf5ef2aSThomas Huth 
2718fcf5ef2aSThomas Huth     gen_update_fprs_dirty(dc, qd);
2719fcf5ef2aSThomas Huth }
2720fcf5ef2aSThomas Huth 
27215d617bfbSRichard Henderson static void gen_load_trap_state_at_tl(TCGv_ptr r_tsptr)
2722fcf5ef2aSThomas Huth {
2723fcf5ef2aSThomas Huth     TCGv_i32 r_tl = tcg_temp_new_i32();
2724fcf5ef2aSThomas Huth 
2725fcf5ef2aSThomas Huth     /* load env->tl into r_tl */
2726ad75a51eSRichard Henderson     tcg_gen_ld_i32(r_tl, tcg_env, offsetof(CPUSPARCState, tl));
2727fcf5ef2aSThomas Huth 
2728fcf5ef2aSThomas Huth     /* tl = [0 ... MAXTL_MASK] where MAXTL_MASK must be power of 2 */
2729fcf5ef2aSThomas Huth     tcg_gen_andi_i32(r_tl, r_tl, MAXTL_MASK);
2730fcf5ef2aSThomas Huth 
2731fcf5ef2aSThomas Huth     /* calculate offset to current trap state from env->ts, reuse r_tl */
2732fcf5ef2aSThomas Huth     tcg_gen_muli_i32(r_tl, r_tl, sizeof (trap_state));
2733ad75a51eSRichard Henderson     tcg_gen_addi_ptr(r_tsptr, tcg_env, offsetof(CPUSPARCState, ts));
2734fcf5ef2aSThomas Huth 
2735fcf5ef2aSThomas Huth     /* tsptr = env->ts[env->tl & MAXTL_MASK] */
2736fcf5ef2aSThomas Huth     {
2737fcf5ef2aSThomas Huth         TCGv_ptr r_tl_tmp = tcg_temp_new_ptr();
2738fcf5ef2aSThomas Huth         tcg_gen_ext_i32_ptr(r_tl_tmp, r_tl);
2739fcf5ef2aSThomas Huth         tcg_gen_add_ptr(r_tsptr, r_tsptr, r_tl_tmp);
2740fcf5ef2aSThomas Huth     }
2741fcf5ef2aSThomas Huth }
2742fcf5ef2aSThomas Huth 
2743fcf5ef2aSThomas Huth static void gen_faligndata(TCGv dst, TCGv gsr, TCGv s1, TCGv s2)
2744fcf5ef2aSThomas Huth {
2745fcf5ef2aSThomas Huth     TCGv t1, t2, shift;
2746fcf5ef2aSThomas Huth 
2747fcf5ef2aSThomas Huth     t1 = tcg_temp_new();
2748fcf5ef2aSThomas Huth     t2 = tcg_temp_new();
2749fcf5ef2aSThomas Huth     shift = tcg_temp_new();
2750fcf5ef2aSThomas Huth 
2751fcf5ef2aSThomas Huth     tcg_gen_andi_tl(shift, gsr, 7);
2752fcf5ef2aSThomas Huth     tcg_gen_shli_tl(shift, shift, 3);
2753fcf5ef2aSThomas Huth     tcg_gen_shl_tl(t1, s1, shift);
2754fcf5ef2aSThomas Huth 
2755fcf5ef2aSThomas Huth     /* A shift of 64 does not produce 0 in TCG.  Divide this into a
2756fcf5ef2aSThomas Huth        shift of (up to 63) followed by a constant shift of 1.  */
2757fcf5ef2aSThomas Huth     tcg_gen_xori_tl(shift, shift, 63);
2758fcf5ef2aSThomas Huth     tcg_gen_shr_tl(t2, s2, shift);
2759fcf5ef2aSThomas Huth     tcg_gen_shri_tl(t2, t2, 1);
2760fcf5ef2aSThomas Huth 
2761fcf5ef2aSThomas Huth     tcg_gen_or_tl(dst, t1, t2);
2762fcf5ef2aSThomas Huth }
2763fcf5ef2aSThomas Huth #endif
2764fcf5ef2aSThomas Huth 
276506c060d9SRichard Henderson static int extract_dfpreg(DisasContext *dc, int x)
276606c060d9SRichard Henderson {
276706c060d9SRichard Henderson     return DFPREG(x);
276806c060d9SRichard Henderson }
276906c060d9SRichard Henderson 
277006c060d9SRichard Henderson static int extract_qfpreg(DisasContext *dc, int x)
277106c060d9SRichard Henderson {
277206c060d9SRichard Henderson     return QFPREG(x);
277306c060d9SRichard Henderson }
277406c060d9SRichard Henderson 
2775878cc677SRichard Henderson /* Include the auto-generated decoder.  */
2776878cc677SRichard Henderson #include "decode-insns.c.inc"
2777878cc677SRichard Henderson 
2778878cc677SRichard Henderson #define TRANS(NAME, AVAIL, FUNC, ...) \
2779878cc677SRichard Henderson     static bool trans_##NAME(DisasContext *dc, arg_##NAME *a) \
2780878cc677SRichard Henderson     { return avail_##AVAIL(dc) && FUNC(dc, __VA_ARGS__); }
2781878cc677SRichard Henderson 
2782878cc677SRichard Henderson #define avail_ALL(C)      true
2783878cc677SRichard Henderson #ifdef TARGET_SPARC64
2784878cc677SRichard Henderson # define avail_32(C)      false
2785af25071cSRichard Henderson # define avail_ASR17(C)   false
2786d0a11d25SRichard Henderson # define avail_CASA(C)    true
2787c2636853SRichard Henderson # define avail_DIV(C)     true
2788b5372650SRichard Henderson # define avail_MUL(C)     true
27890faef01bSRichard Henderson # define avail_POWERDOWN(C) false
2790878cc677SRichard Henderson # define avail_64(C)      true
27915d617bfbSRichard Henderson # define avail_GL(C)      ((C)->def->features & CPU_FEATURE_GL)
2792af25071cSRichard Henderson # define avail_HYPV(C)    ((C)->def->features & CPU_FEATURE_HYPV)
2793b88ce6f2SRichard Henderson # define avail_VIS1(C)    ((C)->def->features & CPU_FEATURE_VIS1)
2794b88ce6f2SRichard Henderson # define avail_VIS2(C)    ((C)->def->features & CPU_FEATURE_VIS2)
2795878cc677SRichard Henderson #else
2796878cc677SRichard Henderson # define avail_32(C)      true
2797af25071cSRichard Henderson # define avail_ASR17(C)   ((C)->def->features & CPU_FEATURE_ASR17)
2798d0a11d25SRichard Henderson # define avail_CASA(C)    ((C)->def->features & CPU_FEATURE_CASA)
2799c2636853SRichard Henderson # define avail_DIV(C)     ((C)->def->features & CPU_FEATURE_DIV)
2800b5372650SRichard Henderson # define avail_MUL(C)     ((C)->def->features & CPU_FEATURE_MUL)
28010faef01bSRichard Henderson # define avail_POWERDOWN(C) ((C)->def->features & CPU_FEATURE_POWERDOWN)
2802878cc677SRichard Henderson # define avail_64(C)      false
28035d617bfbSRichard Henderson # define avail_GL(C)      false
2804af25071cSRichard Henderson # define avail_HYPV(C)    false
2805b88ce6f2SRichard Henderson # define avail_VIS1(C)    false
2806b88ce6f2SRichard Henderson # define avail_VIS2(C)    false
2807878cc677SRichard Henderson #endif
2808878cc677SRichard Henderson 
2809878cc677SRichard Henderson /* Default case for non jump instructions. */
2810878cc677SRichard Henderson static bool advance_pc(DisasContext *dc)
2811878cc677SRichard Henderson {
2812878cc677SRichard Henderson     if (dc->npc & 3) {
2813878cc677SRichard Henderson         switch (dc->npc) {
2814878cc677SRichard Henderson         case DYNAMIC_PC:
2815878cc677SRichard Henderson         case DYNAMIC_PC_LOOKUP:
2816878cc677SRichard Henderson             dc->pc = dc->npc;
2817878cc677SRichard Henderson             gen_op_next_insn();
2818878cc677SRichard Henderson             break;
2819878cc677SRichard Henderson         case JUMP_PC:
2820878cc677SRichard Henderson             /* we can do a static jump */
2821878cc677SRichard Henderson             gen_branch2(dc, dc->jump_pc[0], dc->jump_pc[1], cpu_cond);
2822878cc677SRichard Henderson             dc->base.is_jmp = DISAS_NORETURN;
2823878cc677SRichard Henderson             break;
2824878cc677SRichard Henderson         default:
2825878cc677SRichard Henderson             g_assert_not_reached();
2826878cc677SRichard Henderson         }
2827878cc677SRichard Henderson     } else {
2828878cc677SRichard Henderson         dc->pc = dc->npc;
2829878cc677SRichard Henderson         dc->npc = dc->npc + 4;
2830878cc677SRichard Henderson     }
2831878cc677SRichard Henderson     return true;
2832878cc677SRichard Henderson }
2833878cc677SRichard Henderson 
28346d2a0768SRichard Henderson /*
28356d2a0768SRichard Henderson  * Major opcodes 00 and 01 -- branches, call, and sethi
28366d2a0768SRichard Henderson  */
28376d2a0768SRichard Henderson 
2838276567aaSRichard Henderson static bool advance_jump_uncond_never(DisasContext *dc, bool annul)
2839276567aaSRichard Henderson {
2840276567aaSRichard Henderson     if (annul) {
2841276567aaSRichard Henderson         dc->pc = dc->npc + 4;
2842276567aaSRichard Henderson         dc->npc = dc->pc + 4;
2843276567aaSRichard Henderson     } else {
2844276567aaSRichard Henderson         dc->pc = dc->npc;
2845276567aaSRichard Henderson         dc->npc = dc->pc + 4;
2846276567aaSRichard Henderson     }
2847276567aaSRichard Henderson     return true;
2848276567aaSRichard Henderson }
2849276567aaSRichard Henderson 
2850276567aaSRichard Henderson static bool advance_jump_uncond_always(DisasContext *dc, bool annul,
2851276567aaSRichard Henderson                                        target_ulong dest)
2852276567aaSRichard Henderson {
2853276567aaSRichard Henderson     if (annul) {
2854276567aaSRichard Henderson         dc->pc = dest;
2855276567aaSRichard Henderson         dc->npc = dest + 4;
2856276567aaSRichard Henderson     } else {
2857276567aaSRichard Henderson         dc->pc = dc->npc;
2858276567aaSRichard Henderson         dc->npc = dest;
2859276567aaSRichard Henderson         tcg_gen_mov_tl(cpu_pc, cpu_npc);
2860276567aaSRichard Henderson     }
2861276567aaSRichard Henderson     return true;
2862276567aaSRichard Henderson }
2863276567aaSRichard Henderson 
28649d4e2bc7SRichard Henderson static bool advance_jump_cond(DisasContext *dc, DisasCompare *cmp,
28659d4e2bc7SRichard Henderson                               bool annul, target_ulong dest)
2866276567aaSRichard Henderson {
28676b3e4cc6SRichard Henderson     target_ulong npc = dc->npc;
28686b3e4cc6SRichard Henderson 
2869276567aaSRichard Henderson     if (annul) {
28706b3e4cc6SRichard Henderson         TCGLabel *l1 = gen_new_label();
28716b3e4cc6SRichard Henderson 
28729d4e2bc7SRichard Henderson         tcg_gen_brcond_tl(tcg_invert_cond(cmp->cond), cmp->c1, cmp->c2, l1);
28736b3e4cc6SRichard Henderson         gen_goto_tb(dc, 0, npc, dest);
28746b3e4cc6SRichard Henderson         gen_set_label(l1);
28756b3e4cc6SRichard Henderson         gen_goto_tb(dc, 1, npc + 4, npc + 8);
28766b3e4cc6SRichard Henderson 
28776b3e4cc6SRichard Henderson         dc->base.is_jmp = DISAS_NORETURN;
2878276567aaSRichard Henderson     } else {
28796b3e4cc6SRichard Henderson         if (npc & 3) {
28806b3e4cc6SRichard Henderson             switch (npc) {
28816b3e4cc6SRichard Henderson             case DYNAMIC_PC:
28826b3e4cc6SRichard Henderson             case DYNAMIC_PC_LOOKUP:
28836b3e4cc6SRichard Henderson                 tcg_gen_mov_tl(cpu_pc, cpu_npc);
28846b3e4cc6SRichard Henderson                 tcg_gen_addi_tl(cpu_npc, cpu_npc, 4);
28859d4e2bc7SRichard Henderson                 tcg_gen_movcond_tl(cmp->cond, cpu_npc,
28869d4e2bc7SRichard Henderson                                    cmp->c1, cmp->c2,
28876b3e4cc6SRichard Henderson                                    tcg_constant_tl(dest), cpu_npc);
28886b3e4cc6SRichard Henderson                 dc->pc = npc;
28896b3e4cc6SRichard Henderson                 break;
28906b3e4cc6SRichard Henderson             default:
28916b3e4cc6SRichard Henderson                 g_assert_not_reached();
28926b3e4cc6SRichard Henderson             }
28936b3e4cc6SRichard Henderson         } else {
28946b3e4cc6SRichard Henderson             dc->pc = npc;
28956b3e4cc6SRichard Henderson             dc->jump_pc[0] = dest;
28966b3e4cc6SRichard Henderson             dc->jump_pc[1] = npc + 4;
28976b3e4cc6SRichard Henderson             dc->npc = JUMP_PC;
28989d4e2bc7SRichard Henderson             if (cmp->is_bool) {
28999d4e2bc7SRichard Henderson                 tcg_gen_mov_tl(cpu_cond, cmp->c1);
29009d4e2bc7SRichard Henderson             } else {
29019d4e2bc7SRichard Henderson                 tcg_gen_setcond_tl(cmp->cond, cpu_cond, cmp->c1, cmp->c2);
29029d4e2bc7SRichard Henderson             }
29036b3e4cc6SRichard Henderson         }
2904276567aaSRichard Henderson     }
2905276567aaSRichard Henderson     return true;
2906276567aaSRichard Henderson }
2907276567aaSRichard Henderson 
2908af25071cSRichard Henderson static bool raise_priv(DisasContext *dc)
2909af25071cSRichard Henderson {
2910af25071cSRichard Henderson     gen_exception(dc, TT_PRIV_INSN);
2911af25071cSRichard Henderson     return true;
2912af25071cSRichard Henderson }
2913af25071cSRichard Henderson 
291406c060d9SRichard Henderson static bool raise_unimpfpop(DisasContext *dc)
291506c060d9SRichard Henderson {
291606c060d9SRichard Henderson     gen_op_fpexception_im(dc, FSR_FTT_UNIMPFPOP);
291706c060d9SRichard Henderson     return true;
291806c060d9SRichard Henderson }
291906c060d9SRichard Henderson 
292006c060d9SRichard Henderson static bool gen_trap_float128(DisasContext *dc)
292106c060d9SRichard Henderson {
292206c060d9SRichard Henderson     if (dc->def->features & CPU_FEATURE_FLOAT128) {
292306c060d9SRichard Henderson         return false;
292406c060d9SRichard Henderson     }
292506c060d9SRichard Henderson     return raise_unimpfpop(dc);
292606c060d9SRichard Henderson }
292706c060d9SRichard Henderson 
2928276567aaSRichard Henderson static bool do_bpcc(DisasContext *dc, arg_bcc *a)
2929276567aaSRichard Henderson {
2930276567aaSRichard Henderson     target_long target = address_mask_i(dc, dc->pc + a->i * 4);
29311ea9c62aSRichard Henderson     DisasCompare cmp;
2932276567aaSRichard Henderson 
2933276567aaSRichard Henderson     switch (a->cond) {
2934276567aaSRichard Henderson     case 0x0:
2935276567aaSRichard Henderson         return advance_jump_uncond_never(dc, a->a);
2936276567aaSRichard Henderson     case 0x8:
2937276567aaSRichard Henderson         return advance_jump_uncond_always(dc, a->a, target);
2938276567aaSRichard Henderson     default:
2939276567aaSRichard Henderson         flush_cond(dc);
29401ea9c62aSRichard Henderson 
29411ea9c62aSRichard Henderson         gen_compare(&cmp, a->cc, a->cond, dc);
29429d4e2bc7SRichard Henderson         return advance_jump_cond(dc, &cmp, a->a, target);
2943276567aaSRichard Henderson     }
2944276567aaSRichard Henderson }
2945276567aaSRichard Henderson 
2946276567aaSRichard Henderson TRANS(Bicc, ALL, do_bpcc, a)
2947276567aaSRichard Henderson TRANS(BPcc,  64, do_bpcc, a)
2948276567aaSRichard Henderson 
294945196ea4SRichard Henderson static bool do_fbpfcc(DisasContext *dc, arg_bcc *a)
295045196ea4SRichard Henderson {
295145196ea4SRichard Henderson     target_long target = address_mask_i(dc, dc->pc + a->i * 4);
2952d5471936SRichard Henderson     DisasCompare cmp;
295345196ea4SRichard Henderson 
295445196ea4SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
295545196ea4SRichard Henderson         return true;
295645196ea4SRichard Henderson     }
295745196ea4SRichard Henderson     switch (a->cond) {
295845196ea4SRichard Henderson     case 0x0:
295945196ea4SRichard Henderson         return advance_jump_uncond_never(dc, a->a);
296045196ea4SRichard Henderson     case 0x8:
296145196ea4SRichard Henderson         return advance_jump_uncond_always(dc, a->a, target);
296245196ea4SRichard Henderson     default:
296345196ea4SRichard Henderson         flush_cond(dc);
2964d5471936SRichard Henderson 
2965d5471936SRichard Henderson         gen_fcompare(&cmp, a->cc, a->cond);
29669d4e2bc7SRichard Henderson         return advance_jump_cond(dc, &cmp, a->a, target);
296745196ea4SRichard Henderson     }
296845196ea4SRichard Henderson }
296945196ea4SRichard Henderson 
297045196ea4SRichard Henderson TRANS(FBPfcc,  64, do_fbpfcc, a)
297145196ea4SRichard Henderson TRANS(FBfcc,  ALL, do_fbpfcc, a)
297245196ea4SRichard Henderson 
2973ab9ffe98SRichard Henderson static bool trans_BPr(DisasContext *dc, arg_BPr *a)
2974ab9ffe98SRichard Henderson {
2975ab9ffe98SRichard Henderson     target_long target = address_mask_i(dc, dc->pc + a->i * 4);
2976ab9ffe98SRichard Henderson     DisasCompare cmp;
2977ab9ffe98SRichard Henderson 
2978ab9ffe98SRichard Henderson     if (!avail_64(dc)) {
2979ab9ffe98SRichard Henderson         return false;
2980ab9ffe98SRichard Henderson     }
2981ab9ffe98SRichard Henderson     if (gen_tcg_cond_reg[a->cond] == TCG_COND_NEVER) {
2982ab9ffe98SRichard Henderson         return false;
2983ab9ffe98SRichard Henderson     }
2984ab9ffe98SRichard Henderson 
2985ab9ffe98SRichard Henderson     flush_cond(dc);
2986ab9ffe98SRichard Henderson     gen_compare_reg(&cmp, a->cond, gen_load_gpr(dc, a->rs1));
29879d4e2bc7SRichard Henderson     return advance_jump_cond(dc, &cmp, a->a, target);
2988ab9ffe98SRichard Henderson }
2989ab9ffe98SRichard Henderson 
299023ada1b1SRichard Henderson static bool trans_CALL(DisasContext *dc, arg_CALL *a)
299123ada1b1SRichard Henderson {
299223ada1b1SRichard Henderson     target_long target = address_mask_i(dc, dc->pc + a->i * 4);
299323ada1b1SRichard Henderson 
299423ada1b1SRichard Henderson     gen_store_gpr(dc, 15, tcg_constant_tl(dc->pc));
299523ada1b1SRichard Henderson     gen_mov_pc_npc(dc);
299623ada1b1SRichard Henderson     dc->npc = target;
299723ada1b1SRichard Henderson     return true;
299823ada1b1SRichard Henderson }
299923ada1b1SRichard Henderson 
300045196ea4SRichard Henderson static bool trans_NCP(DisasContext *dc, arg_NCP *a)
300145196ea4SRichard Henderson {
300245196ea4SRichard Henderson     /*
300345196ea4SRichard Henderson      * For sparc32, always generate the no-coprocessor exception.
300445196ea4SRichard Henderson      * For sparc64, always generate illegal instruction.
300545196ea4SRichard Henderson      */
300645196ea4SRichard Henderson #ifdef TARGET_SPARC64
300745196ea4SRichard Henderson     return false;
300845196ea4SRichard Henderson #else
300945196ea4SRichard Henderson     gen_exception(dc, TT_NCP_INSN);
301045196ea4SRichard Henderson     return true;
301145196ea4SRichard Henderson #endif
301245196ea4SRichard Henderson }
301345196ea4SRichard Henderson 
30146d2a0768SRichard Henderson static bool trans_SETHI(DisasContext *dc, arg_SETHI *a)
30156d2a0768SRichard Henderson {
30166d2a0768SRichard Henderson     /* Special-case %g0 because that's the canonical nop.  */
30176d2a0768SRichard Henderson     if (a->rd) {
30186d2a0768SRichard Henderson         gen_store_gpr(dc, a->rd, tcg_constant_tl((uint32_t)a->i << 10));
30196d2a0768SRichard Henderson     }
30206d2a0768SRichard Henderson     return advance_pc(dc);
30216d2a0768SRichard Henderson }
30226d2a0768SRichard Henderson 
30230faef01bSRichard Henderson /*
30240faef01bSRichard Henderson  * Major Opcode 10 -- integer, floating-point, vis, and system insns.
30250faef01bSRichard Henderson  */
30260faef01bSRichard Henderson 
302730376636SRichard Henderson static bool do_tcc(DisasContext *dc, int cond, int cc,
302830376636SRichard Henderson                    int rs1, bool imm, int rs2_or_imm)
302930376636SRichard Henderson {
303030376636SRichard Henderson     int mask = ((dc->def->features & CPU_FEATURE_HYPV) && supervisor(dc)
303130376636SRichard Henderson                 ? UA2005_HTRAP_MASK : V8_TRAP_MASK);
303230376636SRichard Henderson     DisasCompare cmp;
303330376636SRichard Henderson     TCGLabel *lab;
303430376636SRichard Henderson     TCGv_i32 trap;
303530376636SRichard Henderson 
303630376636SRichard Henderson     /* Trap never.  */
303730376636SRichard Henderson     if (cond == 0) {
303830376636SRichard Henderson         return advance_pc(dc);
303930376636SRichard Henderson     }
304030376636SRichard Henderson 
304130376636SRichard Henderson     /*
304230376636SRichard Henderson      * Immediate traps are the most common case.  Since this value is
304330376636SRichard Henderson      * live across the branch, it really pays to evaluate the constant.
304430376636SRichard Henderson      */
304530376636SRichard Henderson     if (rs1 == 0 && (imm || rs2_or_imm == 0)) {
304630376636SRichard Henderson         trap = tcg_constant_i32((rs2_or_imm & mask) + TT_TRAP);
304730376636SRichard Henderson     } else {
304830376636SRichard Henderson         trap = tcg_temp_new_i32();
304930376636SRichard Henderson         tcg_gen_trunc_tl_i32(trap, gen_load_gpr(dc, rs1));
305030376636SRichard Henderson         if (imm) {
305130376636SRichard Henderson             tcg_gen_addi_i32(trap, trap, rs2_or_imm);
305230376636SRichard Henderson         } else {
305330376636SRichard Henderson             TCGv_i32 t2 = tcg_temp_new_i32();
305430376636SRichard Henderson             tcg_gen_trunc_tl_i32(t2, gen_load_gpr(dc, rs2_or_imm));
305530376636SRichard Henderson             tcg_gen_add_i32(trap, trap, t2);
305630376636SRichard Henderson         }
305730376636SRichard Henderson         tcg_gen_andi_i32(trap, trap, mask);
305830376636SRichard Henderson         tcg_gen_addi_i32(trap, trap, TT_TRAP);
305930376636SRichard Henderson     }
306030376636SRichard Henderson 
306130376636SRichard Henderson     /* Trap always.  */
306230376636SRichard Henderson     if (cond == 8) {
306330376636SRichard Henderson         save_state(dc);
306430376636SRichard Henderson         gen_helper_raise_exception(tcg_env, trap);
306530376636SRichard Henderson         dc->base.is_jmp = DISAS_NORETURN;
306630376636SRichard Henderson         return true;
306730376636SRichard Henderson     }
306830376636SRichard Henderson 
306930376636SRichard Henderson     /* Conditional trap.  */
307030376636SRichard Henderson     flush_cond(dc);
307130376636SRichard Henderson     lab = delay_exceptionv(dc, trap);
307230376636SRichard Henderson     gen_compare(&cmp, cc, cond, dc);
307330376636SRichard Henderson     tcg_gen_brcond_tl(cmp.cond, cmp.c1, cmp.c2, lab);
307430376636SRichard Henderson 
307530376636SRichard Henderson     return advance_pc(dc);
307630376636SRichard Henderson }
307730376636SRichard Henderson 
307830376636SRichard Henderson static bool trans_Tcc_r(DisasContext *dc, arg_Tcc_r *a)
307930376636SRichard Henderson {
308030376636SRichard Henderson     if (avail_32(dc) && a->cc) {
308130376636SRichard Henderson         return false;
308230376636SRichard Henderson     }
308330376636SRichard Henderson     return do_tcc(dc, a->cond, a->cc, a->rs1, false, a->rs2);
308430376636SRichard Henderson }
308530376636SRichard Henderson 
308630376636SRichard Henderson static bool trans_Tcc_i_v7(DisasContext *dc, arg_Tcc_i_v7 *a)
308730376636SRichard Henderson {
308830376636SRichard Henderson     if (avail_64(dc)) {
308930376636SRichard Henderson         return false;
309030376636SRichard Henderson     }
309130376636SRichard Henderson     return do_tcc(dc, a->cond, 0, a->rs1, true, a->i);
309230376636SRichard Henderson }
309330376636SRichard Henderson 
309430376636SRichard Henderson static bool trans_Tcc_i_v9(DisasContext *dc, arg_Tcc_i_v9 *a)
309530376636SRichard Henderson {
309630376636SRichard Henderson     if (avail_32(dc)) {
309730376636SRichard Henderson         return false;
309830376636SRichard Henderson     }
309930376636SRichard Henderson     return do_tcc(dc, a->cond, a->cc, a->rs1, true, a->i);
310030376636SRichard Henderson }
310130376636SRichard Henderson 
3102af25071cSRichard Henderson static bool trans_STBAR(DisasContext *dc, arg_STBAR *a)
3103af25071cSRichard Henderson {
3104af25071cSRichard Henderson     tcg_gen_mb(TCG_MO_ST_ST | TCG_BAR_SC);
3105af25071cSRichard Henderson     return advance_pc(dc);
3106af25071cSRichard Henderson }
3107af25071cSRichard Henderson 
3108af25071cSRichard Henderson static bool trans_MEMBAR(DisasContext *dc, arg_MEMBAR *a)
3109af25071cSRichard Henderson {
3110af25071cSRichard Henderson     if (avail_32(dc)) {
3111af25071cSRichard Henderson         return false;
3112af25071cSRichard Henderson     }
3113af25071cSRichard Henderson     if (a->mmask) {
3114af25071cSRichard Henderson         /* Note TCG_MO_* was modeled on sparc64, so mmask matches. */
3115af25071cSRichard Henderson         tcg_gen_mb(a->mmask | TCG_BAR_SC);
3116af25071cSRichard Henderson     }
3117af25071cSRichard Henderson     if (a->cmask) {
3118af25071cSRichard Henderson         /* For #Sync, etc, end the TB to recognize interrupts. */
3119af25071cSRichard Henderson         dc->base.is_jmp = DISAS_EXIT;
3120af25071cSRichard Henderson     }
3121af25071cSRichard Henderson     return advance_pc(dc);
3122af25071cSRichard Henderson }
3123af25071cSRichard Henderson 
3124af25071cSRichard Henderson static bool do_rd_special(DisasContext *dc, bool priv, int rd,
3125af25071cSRichard Henderson                           TCGv (*func)(DisasContext *, TCGv))
3126af25071cSRichard Henderson {
3127af25071cSRichard Henderson     if (!priv) {
3128af25071cSRichard Henderson         return raise_priv(dc);
3129af25071cSRichard Henderson     }
3130af25071cSRichard Henderson     gen_store_gpr(dc, rd, func(dc, gen_dest_gpr(dc, rd)));
3131af25071cSRichard Henderson     return advance_pc(dc);
3132af25071cSRichard Henderson }
3133af25071cSRichard Henderson 
3134af25071cSRichard Henderson static TCGv do_rdy(DisasContext *dc, TCGv dst)
3135af25071cSRichard Henderson {
3136af25071cSRichard Henderson     return cpu_y;
3137af25071cSRichard Henderson }
3138af25071cSRichard Henderson 
3139af25071cSRichard Henderson static bool trans_RDY(DisasContext *dc, arg_RDY *a)
3140af25071cSRichard Henderson {
3141af25071cSRichard Henderson     /*
3142af25071cSRichard Henderson      * TODO: Need a feature bit for sparcv8.  In the meantime, treat all
3143af25071cSRichard Henderson      * 32-bit cpus like sparcv7, which ignores the rs1 field.
3144af25071cSRichard Henderson      * This matches after all other ASR, so Leon3 Asr17 is handled first.
3145af25071cSRichard Henderson      */
3146af25071cSRichard Henderson     if (avail_64(dc) && a->rs1 != 0) {
3147af25071cSRichard Henderson         return false;
3148af25071cSRichard Henderson     }
3149af25071cSRichard Henderson     return do_rd_special(dc, true, a->rd, do_rdy);
3150af25071cSRichard Henderson }
3151af25071cSRichard Henderson 
3152af25071cSRichard Henderson static TCGv do_rd_leon3_config(DisasContext *dc, TCGv dst)
3153af25071cSRichard Henderson {
3154af25071cSRichard Henderson     uint32_t val;
3155af25071cSRichard Henderson 
3156af25071cSRichard Henderson     /*
3157af25071cSRichard Henderson      * TODO: There are many more fields to be filled,
3158af25071cSRichard Henderson      * some of which are writable.
3159af25071cSRichard Henderson      */
3160af25071cSRichard Henderson     val = dc->def->nwindows - 1;   /* [4:0] NWIN */
3161af25071cSRichard Henderson     val |= 1 << 8;                 /* [8]   V8   */
3162af25071cSRichard Henderson 
3163af25071cSRichard Henderson     return tcg_constant_tl(val);
3164af25071cSRichard Henderson }
3165af25071cSRichard Henderson 
3166af25071cSRichard Henderson TRANS(RDASR17, ASR17, do_rd_special, true, a->rd, do_rd_leon3_config)
3167af25071cSRichard Henderson 
3168af25071cSRichard Henderson static TCGv do_rdccr(DisasContext *dc, TCGv dst)
3169af25071cSRichard Henderson {
3170af25071cSRichard Henderson     update_psr(dc);
3171af25071cSRichard Henderson     gen_helper_rdccr(dst, tcg_env);
3172af25071cSRichard Henderson     return dst;
3173af25071cSRichard Henderson }
3174af25071cSRichard Henderson 
3175af25071cSRichard Henderson TRANS(RDCCR, 64, do_rd_special, true, a->rd, do_rdccr)
3176af25071cSRichard Henderson 
3177af25071cSRichard Henderson static TCGv do_rdasi(DisasContext *dc, TCGv dst)
3178af25071cSRichard Henderson {
3179af25071cSRichard Henderson #ifdef TARGET_SPARC64
3180af25071cSRichard Henderson     return tcg_constant_tl(dc->asi);
3181af25071cSRichard Henderson #else
3182af25071cSRichard Henderson     qemu_build_not_reached();
3183af25071cSRichard Henderson #endif
3184af25071cSRichard Henderson }
3185af25071cSRichard Henderson 
3186af25071cSRichard Henderson TRANS(RDASI, 64, do_rd_special, true, a->rd, do_rdasi)
3187af25071cSRichard Henderson 
3188af25071cSRichard Henderson static TCGv do_rdtick(DisasContext *dc, TCGv dst)
3189af25071cSRichard Henderson {
3190af25071cSRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
3191af25071cSRichard Henderson 
3192af25071cSRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(tick));
3193af25071cSRichard Henderson     if (translator_io_start(&dc->base)) {
3194af25071cSRichard Henderson         dc->base.is_jmp = DISAS_EXIT;
3195af25071cSRichard Henderson     }
3196af25071cSRichard Henderson     gen_helper_tick_get_count(dst, tcg_env, r_tickptr,
3197af25071cSRichard Henderson                               tcg_constant_i32(dc->mem_idx));
3198af25071cSRichard Henderson     return dst;
3199af25071cSRichard Henderson }
3200af25071cSRichard Henderson 
3201af25071cSRichard Henderson /* TODO: non-priv access only allowed when enabled. */
3202af25071cSRichard Henderson TRANS(RDTICK, 64, do_rd_special, true, a->rd, do_rdtick)
3203af25071cSRichard Henderson 
3204af25071cSRichard Henderson static TCGv do_rdpc(DisasContext *dc, TCGv dst)
3205af25071cSRichard Henderson {
3206af25071cSRichard Henderson     return tcg_constant_tl(address_mask_i(dc, dc->pc));
3207af25071cSRichard Henderson }
3208af25071cSRichard Henderson 
3209af25071cSRichard Henderson TRANS(RDPC, 64, do_rd_special, true, a->rd, do_rdpc)
3210af25071cSRichard Henderson 
3211af25071cSRichard Henderson static TCGv do_rdfprs(DisasContext *dc, TCGv dst)
3212af25071cSRichard Henderson {
3213af25071cSRichard Henderson     tcg_gen_ext_i32_tl(dst, cpu_fprs);
3214af25071cSRichard Henderson     return dst;
3215af25071cSRichard Henderson }
3216af25071cSRichard Henderson 
3217af25071cSRichard Henderson TRANS(RDFPRS, 64, do_rd_special, true, a->rd, do_rdfprs)
3218af25071cSRichard Henderson 
3219af25071cSRichard Henderson static TCGv do_rdgsr(DisasContext *dc, TCGv dst)
3220af25071cSRichard Henderson {
3221af25071cSRichard Henderson     gen_trap_ifnofpu(dc);
3222af25071cSRichard Henderson     return cpu_gsr;
3223af25071cSRichard Henderson }
3224af25071cSRichard Henderson 
3225af25071cSRichard Henderson TRANS(RDGSR, 64, do_rd_special, true, a->rd, do_rdgsr)
3226af25071cSRichard Henderson 
3227af25071cSRichard Henderson static TCGv do_rdsoftint(DisasContext *dc, TCGv dst)
3228af25071cSRichard Henderson {
3229af25071cSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(softint));
3230af25071cSRichard Henderson     return dst;
3231af25071cSRichard Henderson }
3232af25071cSRichard Henderson 
3233af25071cSRichard Henderson TRANS(RDSOFTINT, 64, do_rd_special, supervisor(dc), a->rd, do_rdsoftint)
3234af25071cSRichard Henderson 
3235af25071cSRichard Henderson static TCGv do_rdtick_cmpr(DisasContext *dc, TCGv dst)
3236af25071cSRichard Henderson {
3237577efa45SRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(tick_cmpr));
3238577efa45SRichard Henderson     return dst;
3239af25071cSRichard Henderson }
3240af25071cSRichard Henderson 
3241af25071cSRichard Henderson /* TODO: non-priv access only allowed when enabled. */
3242af25071cSRichard Henderson TRANS(RDTICK_CMPR, 64, do_rd_special, true, a->rd, do_rdtick_cmpr)
3243af25071cSRichard Henderson 
3244af25071cSRichard Henderson static TCGv do_rdstick(DisasContext *dc, TCGv dst)
3245af25071cSRichard Henderson {
3246af25071cSRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
3247af25071cSRichard Henderson 
3248af25071cSRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(stick));
3249af25071cSRichard Henderson     if (translator_io_start(&dc->base)) {
3250af25071cSRichard Henderson         dc->base.is_jmp = DISAS_EXIT;
3251af25071cSRichard Henderson     }
3252af25071cSRichard Henderson     gen_helper_tick_get_count(dst, tcg_env, r_tickptr,
3253af25071cSRichard Henderson                               tcg_constant_i32(dc->mem_idx));
3254af25071cSRichard Henderson     return dst;
3255af25071cSRichard Henderson }
3256af25071cSRichard Henderson 
3257af25071cSRichard Henderson /* TODO: non-priv access only allowed when enabled. */
3258af25071cSRichard Henderson TRANS(RDSTICK, 64, do_rd_special, true, a->rd, do_rdstick)
3259af25071cSRichard Henderson 
3260af25071cSRichard Henderson static TCGv do_rdstick_cmpr(DisasContext *dc, TCGv dst)
3261af25071cSRichard Henderson {
3262577efa45SRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(stick_cmpr));
3263577efa45SRichard Henderson     return dst;
3264af25071cSRichard Henderson }
3265af25071cSRichard Henderson 
3266af25071cSRichard Henderson /* TODO: supervisor access only allowed when enabled by hypervisor. */
3267af25071cSRichard Henderson TRANS(RDSTICK_CMPR, 64, do_rd_special, supervisor(dc), a->rd, do_rdstick_cmpr)
3268af25071cSRichard Henderson 
3269af25071cSRichard Henderson /*
3270af25071cSRichard Henderson  * UltraSPARC-T1 Strand status.
3271af25071cSRichard Henderson  * HYPV check maybe not enough, UA2005 & UA2007 describe
3272af25071cSRichard Henderson  * this ASR as impl. dep
3273af25071cSRichard Henderson  */
3274af25071cSRichard Henderson static TCGv do_rdstrand_status(DisasContext *dc, TCGv dst)
3275af25071cSRichard Henderson {
3276af25071cSRichard Henderson     return tcg_constant_tl(1);
3277af25071cSRichard Henderson }
3278af25071cSRichard Henderson 
3279af25071cSRichard Henderson TRANS(RDSTRAND_STATUS, HYPV, do_rd_special, true, a->rd, do_rdstrand_status)
3280af25071cSRichard Henderson 
3281668bb9b7SRichard Henderson static TCGv do_rdpsr(DisasContext *dc, TCGv dst)
3282668bb9b7SRichard Henderson {
3283668bb9b7SRichard Henderson     update_psr(dc);
3284668bb9b7SRichard Henderson     gen_helper_rdpsr(dst, tcg_env);
3285668bb9b7SRichard Henderson     return dst;
3286668bb9b7SRichard Henderson }
3287668bb9b7SRichard Henderson 
3288668bb9b7SRichard Henderson TRANS(RDPSR, 32, do_rd_special, supervisor(dc), a->rd, do_rdpsr)
3289668bb9b7SRichard Henderson 
3290668bb9b7SRichard Henderson static TCGv do_rdhpstate(DisasContext *dc, TCGv dst)
3291668bb9b7SRichard Henderson {
3292668bb9b7SRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hpstate));
3293668bb9b7SRichard Henderson     return dst;
3294668bb9b7SRichard Henderson }
3295668bb9b7SRichard Henderson 
3296668bb9b7SRichard Henderson TRANS(RDHPR_hpstate, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhpstate)
3297668bb9b7SRichard Henderson 
3298668bb9b7SRichard Henderson static TCGv do_rdhtstate(DisasContext *dc, TCGv dst)
3299668bb9b7SRichard Henderson {
3300668bb9b7SRichard Henderson     TCGv_i32 tl = tcg_temp_new_i32();
3301668bb9b7SRichard Henderson     TCGv_ptr tp = tcg_temp_new_ptr();
3302668bb9b7SRichard Henderson 
3303668bb9b7SRichard Henderson     tcg_gen_ld_i32(tl, tcg_env, env64_field_offsetof(tl));
3304668bb9b7SRichard Henderson     tcg_gen_andi_i32(tl, tl, MAXTL_MASK);
3305668bb9b7SRichard Henderson     tcg_gen_shli_i32(tl, tl, 3);
3306668bb9b7SRichard Henderson     tcg_gen_ext_i32_ptr(tp, tl);
3307668bb9b7SRichard Henderson     tcg_gen_add_ptr(tp, tp, tcg_env);
3308668bb9b7SRichard Henderson 
3309668bb9b7SRichard Henderson     tcg_gen_ld_tl(dst, tp, env64_field_offsetof(htstate));
3310668bb9b7SRichard Henderson     return dst;
3311668bb9b7SRichard Henderson }
3312668bb9b7SRichard Henderson 
3313668bb9b7SRichard Henderson TRANS(RDHPR_htstate, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhtstate)
3314668bb9b7SRichard Henderson 
3315668bb9b7SRichard Henderson static TCGv do_rdhintp(DisasContext *dc, TCGv dst)
3316668bb9b7SRichard Henderson {
33172da789deSRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hintp));
33182da789deSRichard Henderson     return dst;
3319668bb9b7SRichard Henderson }
3320668bb9b7SRichard Henderson 
3321668bb9b7SRichard Henderson TRANS(RDHPR_hintp, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhintp)
3322668bb9b7SRichard Henderson 
3323668bb9b7SRichard Henderson static TCGv do_rdhtba(DisasContext *dc, TCGv dst)
3324668bb9b7SRichard Henderson {
33252da789deSRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(htba));
33262da789deSRichard Henderson     return dst;
3327668bb9b7SRichard Henderson }
3328668bb9b7SRichard Henderson 
3329668bb9b7SRichard Henderson TRANS(RDHPR_htba, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhtba)
3330668bb9b7SRichard Henderson 
3331668bb9b7SRichard Henderson static TCGv do_rdhver(DisasContext *dc, TCGv dst)
3332668bb9b7SRichard Henderson {
33332da789deSRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hver));
33342da789deSRichard Henderson     return dst;
3335668bb9b7SRichard Henderson }
3336668bb9b7SRichard Henderson 
3337668bb9b7SRichard Henderson TRANS(RDHPR_hver, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhver)
3338668bb9b7SRichard Henderson 
3339668bb9b7SRichard Henderson static TCGv do_rdhstick_cmpr(DisasContext *dc, TCGv dst)
3340668bb9b7SRichard Henderson {
3341577efa45SRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hstick_cmpr));
3342577efa45SRichard Henderson     return dst;
3343668bb9b7SRichard Henderson }
3344668bb9b7SRichard Henderson 
3345668bb9b7SRichard Henderson TRANS(RDHPR_hstick_cmpr, HYPV, do_rd_special, hypervisor(dc), a->rd,
3346668bb9b7SRichard Henderson       do_rdhstick_cmpr)
3347668bb9b7SRichard Henderson 
33485d617bfbSRichard Henderson static TCGv do_rdwim(DisasContext *dc, TCGv dst)
33495d617bfbSRichard Henderson {
3350cd6269f7SRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env32_field_offsetof(wim));
3351cd6269f7SRichard Henderson     return dst;
33525d617bfbSRichard Henderson }
33535d617bfbSRichard Henderson 
33545d617bfbSRichard Henderson TRANS(RDWIM, 32, do_rd_special, supervisor(dc), a->rd, do_rdwim)
33555d617bfbSRichard Henderson 
33565d617bfbSRichard Henderson static TCGv do_rdtpc(DisasContext *dc, TCGv dst)
33575d617bfbSRichard Henderson {
33585d617bfbSRichard Henderson #ifdef TARGET_SPARC64
33595d617bfbSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
33605d617bfbSRichard Henderson 
33615d617bfbSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
33625d617bfbSRichard Henderson     tcg_gen_ld_tl(dst, r_tsptr, offsetof(trap_state, tpc));
33635d617bfbSRichard Henderson     return dst;
33645d617bfbSRichard Henderson #else
33655d617bfbSRichard Henderson     qemu_build_not_reached();
33665d617bfbSRichard Henderson #endif
33675d617bfbSRichard Henderson }
33685d617bfbSRichard Henderson 
33695d617bfbSRichard Henderson TRANS(RDPR_tpc, 64, do_rd_special, supervisor(dc), a->rd, do_rdtpc)
33705d617bfbSRichard Henderson 
33715d617bfbSRichard Henderson static TCGv do_rdtnpc(DisasContext *dc, TCGv dst)
33725d617bfbSRichard Henderson {
33735d617bfbSRichard Henderson #ifdef TARGET_SPARC64
33745d617bfbSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
33755d617bfbSRichard Henderson 
33765d617bfbSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
33775d617bfbSRichard Henderson     tcg_gen_ld_tl(dst, r_tsptr, offsetof(trap_state, tnpc));
33785d617bfbSRichard Henderson     return dst;
33795d617bfbSRichard Henderson #else
33805d617bfbSRichard Henderson     qemu_build_not_reached();
33815d617bfbSRichard Henderson #endif
33825d617bfbSRichard Henderson }
33835d617bfbSRichard Henderson 
33845d617bfbSRichard Henderson TRANS(RDPR_tnpc, 64, do_rd_special, supervisor(dc), a->rd, do_rdtnpc)
33855d617bfbSRichard Henderson 
33865d617bfbSRichard Henderson static TCGv do_rdtstate(DisasContext *dc, TCGv dst)
33875d617bfbSRichard Henderson {
33885d617bfbSRichard Henderson #ifdef TARGET_SPARC64
33895d617bfbSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
33905d617bfbSRichard Henderson 
33915d617bfbSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
33925d617bfbSRichard Henderson     tcg_gen_ld_tl(dst, r_tsptr, offsetof(trap_state, tstate));
33935d617bfbSRichard Henderson     return dst;
33945d617bfbSRichard Henderson #else
33955d617bfbSRichard Henderson     qemu_build_not_reached();
33965d617bfbSRichard Henderson #endif
33975d617bfbSRichard Henderson }
33985d617bfbSRichard Henderson 
33995d617bfbSRichard Henderson TRANS(RDPR_tstate, 64, do_rd_special, supervisor(dc), a->rd, do_rdtstate)
34005d617bfbSRichard Henderson 
34015d617bfbSRichard Henderson static TCGv do_rdtt(DisasContext *dc, TCGv dst)
34025d617bfbSRichard Henderson {
34035d617bfbSRichard Henderson #ifdef TARGET_SPARC64
34045d617bfbSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
34055d617bfbSRichard Henderson 
34065d617bfbSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
34075d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, r_tsptr, offsetof(trap_state, tt));
34085d617bfbSRichard Henderson     return dst;
34095d617bfbSRichard Henderson #else
34105d617bfbSRichard Henderson     qemu_build_not_reached();
34115d617bfbSRichard Henderson #endif
34125d617bfbSRichard Henderson }
34135d617bfbSRichard Henderson 
34145d617bfbSRichard Henderson TRANS(RDPR_tt, 64, do_rd_special, supervisor(dc), a->rd, do_rdtt)
34155d617bfbSRichard Henderson TRANS(RDPR_tick, 64, do_rd_special, supervisor(dc), a->rd, do_rdtick)
34165d617bfbSRichard Henderson 
34175d617bfbSRichard Henderson static TCGv do_rdtba(DisasContext *dc, TCGv dst)
34185d617bfbSRichard Henderson {
34195d617bfbSRichard Henderson     return cpu_tbr;
34205d617bfbSRichard Henderson }
34215d617bfbSRichard Henderson 
3422e8325dc0SRichard Henderson TRANS(RDTBR, 32, do_rd_special, supervisor(dc), a->rd, do_rdtba)
34235d617bfbSRichard Henderson TRANS(RDPR_tba, 64, do_rd_special, supervisor(dc), a->rd, do_rdtba)
34245d617bfbSRichard Henderson 
34255d617bfbSRichard Henderson static TCGv do_rdpstate(DisasContext *dc, TCGv dst)
34265d617bfbSRichard Henderson {
34275d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(pstate));
34285d617bfbSRichard Henderson     return dst;
34295d617bfbSRichard Henderson }
34305d617bfbSRichard Henderson 
34315d617bfbSRichard Henderson TRANS(RDPR_pstate, 64, do_rd_special, supervisor(dc), a->rd, do_rdpstate)
34325d617bfbSRichard Henderson 
34335d617bfbSRichard Henderson static TCGv do_rdtl(DisasContext *dc, TCGv dst)
34345d617bfbSRichard Henderson {
34355d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(tl));
34365d617bfbSRichard Henderson     return dst;
34375d617bfbSRichard Henderson }
34385d617bfbSRichard Henderson 
34395d617bfbSRichard Henderson TRANS(RDPR_tl, 64, do_rd_special, supervisor(dc), a->rd, do_rdtl)
34405d617bfbSRichard Henderson 
34415d617bfbSRichard Henderson static TCGv do_rdpil(DisasContext *dc, TCGv dst)
34425d617bfbSRichard Henderson {
34435d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env_field_offsetof(psrpil));
34445d617bfbSRichard Henderson     return dst;
34455d617bfbSRichard Henderson }
34465d617bfbSRichard Henderson 
34475d617bfbSRichard Henderson TRANS(RDPR_pil, 64, do_rd_special, supervisor(dc), a->rd, do_rdpil)
34485d617bfbSRichard Henderson 
34495d617bfbSRichard Henderson static TCGv do_rdcwp(DisasContext *dc, TCGv dst)
34505d617bfbSRichard Henderson {
34515d617bfbSRichard Henderson     gen_helper_rdcwp(dst, tcg_env);
34525d617bfbSRichard Henderson     return dst;
34535d617bfbSRichard Henderson }
34545d617bfbSRichard Henderson 
34555d617bfbSRichard Henderson TRANS(RDPR_cwp, 64, do_rd_special, supervisor(dc), a->rd, do_rdcwp)
34565d617bfbSRichard Henderson 
34575d617bfbSRichard Henderson static TCGv do_rdcansave(DisasContext *dc, TCGv dst)
34585d617bfbSRichard Henderson {
34595d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(cansave));
34605d617bfbSRichard Henderson     return dst;
34615d617bfbSRichard Henderson }
34625d617bfbSRichard Henderson 
34635d617bfbSRichard Henderson TRANS(RDPR_cansave, 64, do_rd_special, supervisor(dc), a->rd, do_rdcansave)
34645d617bfbSRichard Henderson 
34655d617bfbSRichard Henderson static TCGv do_rdcanrestore(DisasContext *dc, TCGv dst)
34665d617bfbSRichard Henderson {
34675d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(canrestore));
34685d617bfbSRichard Henderson     return dst;
34695d617bfbSRichard Henderson }
34705d617bfbSRichard Henderson 
34715d617bfbSRichard Henderson TRANS(RDPR_canrestore, 64, do_rd_special, supervisor(dc), a->rd,
34725d617bfbSRichard Henderson       do_rdcanrestore)
34735d617bfbSRichard Henderson 
34745d617bfbSRichard Henderson static TCGv do_rdcleanwin(DisasContext *dc, TCGv dst)
34755d617bfbSRichard Henderson {
34765d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(cleanwin));
34775d617bfbSRichard Henderson     return dst;
34785d617bfbSRichard Henderson }
34795d617bfbSRichard Henderson 
34805d617bfbSRichard Henderson TRANS(RDPR_cleanwin, 64, do_rd_special, supervisor(dc), a->rd, do_rdcleanwin)
34815d617bfbSRichard Henderson 
34825d617bfbSRichard Henderson static TCGv do_rdotherwin(DisasContext *dc, TCGv dst)
34835d617bfbSRichard Henderson {
34845d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(otherwin));
34855d617bfbSRichard Henderson     return dst;
34865d617bfbSRichard Henderson }
34875d617bfbSRichard Henderson 
34885d617bfbSRichard Henderson TRANS(RDPR_otherwin, 64, do_rd_special, supervisor(dc), a->rd, do_rdotherwin)
34895d617bfbSRichard Henderson 
34905d617bfbSRichard Henderson static TCGv do_rdwstate(DisasContext *dc, TCGv dst)
34915d617bfbSRichard Henderson {
34925d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(wstate));
34935d617bfbSRichard Henderson     return dst;
34945d617bfbSRichard Henderson }
34955d617bfbSRichard Henderson 
34965d617bfbSRichard Henderson TRANS(RDPR_wstate, 64, do_rd_special, supervisor(dc), a->rd, do_rdwstate)
34975d617bfbSRichard Henderson 
34985d617bfbSRichard Henderson static TCGv do_rdgl(DisasContext *dc, TCGv dst)
34995d617bfbSRichard Henderson {
35005d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(gl));
35015d617bfbSRichard Henderson     return dst;
35025d617bfbSRichard Henderson }
35035d617bfbSRichard Henderson 
35045d617bfbSRichard Henderson TRANS(RDPR_gl, GL, do_rd_special, supervisor(dc), a->rd, do_rdgl)
35055d617bfbSRichard Henderson 
35065d617bfbSRichard Henderson /* UA2005 strand status */
35075d617bfbSRichard Henderson static TCGv do_rdssr(DisasContext *dc, TCGv dst)
35085d617bfbSRichard Henderson {
35092da789deSRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(ssr));
35102da789deSRichard Henderson     return dst;
35115d617bfbSRichard Henderson }
35125d617bfbSRichard Henderson 
35135d617bfbSRichard Henderson TRANS(RDPR_strand_status, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdssr)
35145d617bfbSRichard Henderson 
35155d617bfbSRichard Henderson static TCGv do_rdver(DisasContext *dc, TCGv dst)
35165d617bfbSRichard Henderson {
35172da789deSRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(version));
35182da789deSRichard Henderson     return dst;
35195d617bfbSRichard Henderson }
35205d617bfbSRichard Henderson 
35215d617bfbSRichard Henderson TRANS(RDPR_ver, 64, do_rd_special, supervisor(dc), a->rd, do_rdver)
35225d617bfbSRichard Henderson 
3523e8325dc0SRichard Henderson static bool trans_FLUSHW(DisasContext *dc, arg_FLUSHW *a)
3524e8325dc0SRichard Henderson {
3525e8325dc0SRichard Henderson     if (avail_64(dc)) {
3526e8325dc0SRichard Henderson         gen_helper_flushw(tcg_env);
3527e8325dc0SRichard Henderson         return advance_pc(dc);
3528e8325dc0SRichard Henderson     }
3529e8325dc0SRichard Henderson     return false;
3530e8325dc0SRichard Henderson }
3531e8325dc0SRichard Henderson 
35320faef01bSRichard Henderson static bool do_wr_special(DisasContext *dc, arg_r_r_ri *a, bool priv,
35330faef01bSRichard Henderson                           void (*func)(DisasContext *, TCGv))
35340faef01bSRichard Henderson {
35350faef01bSRichard Henderson     TCGv src;
35360faef01bSRichard Henderson 
35370faef01bSRichard Henderson     /* For simplicity, we under-decoded the rs2 form. */
35380faef01bSRichard Henderson     if (!a->imm && (a->rs2_or_imm & ~0x1f)) {
35390faef01bSRichard Henderson         return false;
35400faef01bSRichard Henderson     }
35410faef01bSRichard Henderson     if (!priv) {
35420faef01bSRichard Henderson         return raise_priv(dc);
35430faef01bSRichard Henderson     }
35440faef01bSRichard Henderson 
35450faef01bSRichard Henderson     if (a->rs1 == 0 && (a->imm || a->rs2_or_imm == 0)) {
35460faef01bSRichard Henderson         src = tcg_constant_tl(a->rs2_or_imm);
35470faef01bSRichard Henderson     } else {
35480faef01bSRichard Henderson         TCGv src1 = gen_load_gpr(dc, a->rs1);
35490faef01bSRichard Henderson         if (a->rs2_or_imm == 0) {
35500faef01bSRichard Henderson             src = src1;
35510faef01bSRichard Henderson         } else {
35520faef01bSRichard Henderson             src = tcg_temp_new();
35530faef01bSRichard Henderson             if (a->imm) {
35540faef01bSRichard Henderson                 tcg_gen_xori_tl(src, src1, a->rs2_or_imm);
35550faef01bSRichard Henderson             } else {
35560faef01bSRichard Henderson                 tcg_gen_xor_tl(src, src1, gen_load_gpr(dc, a->rs2_or_imm));
35570faef01bSRichard Henderson             }
35580faef01bSRichard Henderson         }
35590faef01bSRichard Henderson     }
35600faef01bSRichard Henderson     func(dc, src);
35610faef01bSRichard Henderson     return advance_pc(dc);
35620faef01bSRichard Henderson }
35630faef01bSRichard Henderson 
35640faef01bSRichard Henderson static void do_wry(DisasContext *dc, TCGv src)
35650faef01bSRichard Henderson {
35660faef01bSRichard Henderson     tcg_gen_ext32u_tl(cpu_y, src);
35670faef01bSRichard Henderson }
35680faef01bSRichard Henderson 
35690faef01bSRichard Henderson TRANS(WRY, ALL, do_wr_special, a, true, do_wry)
35700faef01bSRichard Henderson 
35710faef01bSRichard Henderson static void do_wrccr(DisasContext *dc, TCGv src)
35720faef01bSRichard Henderson {
35730faef01bSRichard Henderson     gen_helper_wrccr(tcg_env, src);
35740faef01bSRichard Henderson }
35750faef01bSRichard Henderson 
35760faef01bSRichard Henderson TRANS(WRCCR, 64, do_wr_special, a, true, do_wrccr)
35770faef01bSRichard Henderson 
35780faef01bSRichard Henderson static void do_wrasi(DisasContext *dc, TCGv src)
35790faef01bSRichard Henderson {
35800faef01bSRichard Henderson     TCGv tmp = tcg_temp_new();
35810faef01bSRichard Henderson 
35820faef01bSRichard Henderson     tcg_gen_ext8u_tl(tmp, src);
35830faef01bSRichard Henderson     tcg_gen_st32_tl(tmp, tcg_env, env64_field_offsetof(asi));
35840faef01bSRichard Henderson     /* End TB to notice changed ASI. */
35850faef01bSRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
35860faef01bSRichard Henderson }
35870faef01bSRichard Henderson 
35880faef01bSRichard Henderson TRANS(WRASI, 64, do_wr_special, a, true, do_wrasi)
35890faef01bSRichard Henderson 
35900faef01bSRichard Henderson static void do_wrfprs(DisasContext *dc, TCGv src)
35910faef01bSRichard Henderson {
35920faef01bSRichard Henderson #ifdef TARGET_SPARC64
35930faef01bSRichard Henderson     tcg_gen_trunc_tl_i32(cpu_fprs, src);
35940faef01bSRichard Henderson     dc->fprs_dirty = 0;
35950faef01bSRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
35960faef01bSRichard Henderson #else
35970faef01bSRichard Henderson     qemu_build_not_reached();
35980faef01bSRichard Henderson #endif
35990faef01bSRichard Henderson }
36000faef01bSRichard Henderson 
36010faef01bSRichard Henderson TRANS(WRFPRS, 64, do_wr_special, a, true, do_wrfprs)
36020faef01bSRichard Henderson 
36030faef01bSRichard Henderson static void do_wrgsr(DisasContext *dc, TCGv src)
36040faef01bSRichard Henderson {
36050faef01bSRichard Henderson     gen_trap_ifnofpu(dc);
36060faef01bSRichard Henderson     tcg_gen_mov_tl(cpu_gsr, src);
36070faef01bSRichard Henderson }
36080faef01bSRichard Henderson 
36090faef01bSRichard Henderson TRANS(WRGSR, 64, do_wr_special, a, true, do_wrgsr)
36100faef01bSRichard Henderson 
36110faef01bSRichard Henderson static void do_wrsoftint_set(DisasContext *dc, TCGv src)
36120faef01bSRichard Henderson {
36130faef01bSRichard Henderson     gen_helper_set_softint(tcg_env, src);
36140faef01bSRichard Henderson }
36150faef01bSRichard Henderson 
36160faef01bSRichard Henderson TRANS(WRSOFTINT_SET, 64, do_wr_special, a, supervisor(dc), do_wrsoftint_set)
36170faef01bSRichard Henderson 
36180faef01bSRichard Henderson static void do_wrsoftint_clr(DisasContext *dc, TCGv src)
36190faef01bSRichard Henderson {
36200faef01bSRichard Henderson     gen_helper_clear_softint(tcg_env, src);
36210faef01bSRichard Henderson }
36220faef01bSRichard Henderson 
36230faef01bSRichard Henderson TRANS(WRSOFTINT_CLR, 64, do_wr_special, a, supervisor(dc), do_wrsoftint_clr)
36240faef01bSRichard Henderson 
36250faef01bSRichard Henderson static void do_wrsoftint(DisasContext *dc, TCGv src)
36260faef01bSRichard Henderson {
36270faef01bSRichard Henderson     gen_helper_write_softint(tcg_env, src);
36280faef01bSRichard Henderson }
36290faef01bSRichard Henderson 
36300faef01bSRichard Henderson TRANS(WRSOFTINT, 64, do_wr_special, a, supervisor(dc), do_wrsoftint)
36310faef01bSRichard Henderson 
36320faef01bSRichard Henderson static void do_wrtick_cmpr(DisasContext *dc, TCGv src)
36330faef01bSRichard Henderson {
36340faef01bSRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
36350faef01bSRichard Henderson 
3636577efa45SRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(tick_cmpr));
3637577efa45SRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(tick));
36380faef01bSRichard Henderson     translator_io_start(&dc->base);
3639577efa45SRichard Henderson     gen_helper_tick_set_limit(r_tickptr, src);
36400faef01bSRichard Henderson     /* End TB to handle timer interrupt */
36410faef01bSRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
36420faef01bSRichard Henderson }
36430faef01bSRichard Henderson 
36440faef01bSRichard Henderson TRANS(WRTICK_CMPR, 64, do_wr_special, a, supervisor(dc), do_wrtick_cmpr)
36450faef01bSRichard Henderson 
36460faef01bSRichard Henderson static void do_wrstick(DisasContext *dc, TCGv src)
36470faef01bSRichard Henderson {
36480faef01bSRichard Henderson #ifdef TARGET_SPARC64
36490faef01bSRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
36500faef01bSRichard Henderson 
36510faef01bSRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, offsetof(CPUSPARCState, stick));
36520faef01bSRichard Henderson     translator_io_start(&dc->base);
36530faef01bSRichard Henderson     gen_helper_tick_set_count(r_tickptr, src);
36540faef01bSRichard Henderson     /* End TB to handle timer interrupt */
36550faef01bSRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
36560faef01bSRichard Henderson #else
36570faef01bSRichard Henderson     qemu_build_not_reached();
36580faef01bSRichard Henderson #endif
36590faef01bSRichard Henderson }
36600faef01bSRichard Henderson 
36610faef01bSRichard Henderson TRANS(WRSTICK, 64, do_wr_special, a, supervisor(dc), do_wrstick)
36620faef01bSRichard Henderson 
36630faef01bSRichard Henderson static void do_wrstick_cmpr(DisasContext *dc, TCGv src)
36640faef01bSRichard Henderson {
36650faef01bSRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
36660faef01bSRichard Henderson 
3667577efa45SRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(stick_cmpr));
3668577efa45SRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(stick));
36690faef01bSRichard Henderson     translator_io_start(&dc->base);
3670577efa45SRichard Henderson     gen_helper_tick_set_limit(r_tickptr, src);
36710faef01bSRichard Henderson     /* End TB to handle timer interrupt */
36720faef01bSRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
36730faef01bSRichard Henderson }
36740faef01bSRichard Henderson 
36750faef01bSRichard Henderson TRANS(WRSTICK_CMPR, 64, do_wr_special, a, supervisor(dc), do_wrstick_cmpr)
36760faef01bSRichard Henderson 
36770faef01bSRichard Henderson static void do_wrpowerdown(DisasContext *dc, TCGv src)
36780faef01bSRichard Henderson {
36790faef01bSRichard Henderson     save_state(dc);
36800faef01bSRichard Henderson     gen_helper_power_down(tcg_env);
36810faef01bSRichard Henderson }
36820faef01bSRichard Henderson 
36830faef01bSRichard Henderson TRANS(WRPOWERDOWN, POWERDOWN, do_wr_special, a, supervisor(dc), do_wrpowerdown)
36840faef01bSRichard Henderson 
368525524734SRichard Henderson static void do_wrpsr(DisasContext *dc, TCGv src)
368625524734SRichard Henderson {
368725524734SRichard Henderson     gen_helper_wrpsr(tcg_env, src);
368825524734SRichard Henderson     tcg_gen_movi_i32(cpu_cc_op, CC_OP_FLAGS);
368925524734SRichard Henderson     dc->cc_op = CC_OP_FLAGS;
369025524734SRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
369125524734SRichard Henderson }
369225524734SRichard Henderson 
369325524734SRichard Henderson TRANS(WRPSR, 32, do_wr_special, a, supervisor(dc), do_wrpsr)
369425524734SRichard Henderson 
36959422278eSRichard Henderson static void do_wrwim(DisasContext *dc, TCGv src)
36969422278eSRichard Henderson {
36979422278eSRichard Henderson     target_ulong mask = MAKE_64BIT_MASK(0, dc->def->nwindows);
3698cd6269f7SRichard Henderson     TCGv tmp = tcg_temp_new();
3699cd6269f7SRichard Henderson 
3700cd6269f7SRichard Henderson     tcg_gen_andi_tl(tmp, src, mask);
3701cd6269f7SRichard Henderson     tcg_gen_st_tl(tmp, tcg_env, env32_field_offsetof(wim));
37029422278eSRichard Henderson }
37039422278eSRichard Henderson 
37049422278eSRichard Henderson TRANS(WRWIM, 32, do_wr_special, a, supervisor(dc), do_wrwim)
37059422278eSRichard Henderson 
37069422278eSRichard Henderson static void do_wrtpc(DisasContext *dc, TCGv src)
37079422278eSRichard Henderson {
37089422278eSRichard Henderson #ifdef TARGET_SPARC64
37099422278eSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
37109422278eSRichard Henderson 
37119422278eSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
37129422278eSRichard Henderson     tcg_gen_st_tl(src, r_tsptr, offsetof(trap_state, tpc));
37139422278eSRichard Henderson #else
37149422278eSRichard Henderson     qemu_build_not_reached();
37159422278eSRichard Henderson #endif
37169422278eSRichard Henderson }
37179422278eSRichard Henderson 
37189422278eSRichard Henderson TRANS(WRPR_tpc, 64, do_wr_special, a, supervisor(dc), do_wrtpc)
37199422278eSRichard Henderson 
37209422278eSRichard Henderson static void do_wrtnpc(DisasContext *dc, TCGv src)
37219422278eSRichard Henderson {
37229422278eSRichard Henderson #ifdef TARGET_SPARC64
37239422278eSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
37249422278eSRichard Henderson 
37259422278eSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
37269422278eSRichard Henderson     tcg_gen_st_tl(src, r_tsptr, offsetof(trap_state, tnpc));
37279422278eSRichard Henderson #else
37289422278eSRichard Henderson     qemu_build_not_reached();
37299422278eSRichard Henderson #endif
37309422278eSRichard Henderson }
37319422278eSRichard Henderson 
37329422278eSRichard Henderson TRANS(WRPR_tnpc, 64, do_wr_special, a, supervisor(dc), do_wrtnpc)
37339422278eSRichard Henderson 
37349422278eSRichard Henderson static void do_wrtstate(DisasContext *dc, TCGv src)
37359422278eSRichard Henderson {
37369422278eSRichard Henderson #ifdef TARGET_SPARC64
37379422278eSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
37389422278eSRichard Henderson 
37399422278eSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
37409422278eSRichard Henderson     tcg_gen_st_tl(src, r_tsptr, offsetof(trap_state, tstate));
37419422278eSRichard Henderson #else
37429422278eSRichard Henderson     qemu_build_not_reached();
37439422278eSRichard Henderson #endif
37449422278eSRichard Henderson }
37459422278eSRichard Henderson 
37469422278eSRichard Henderson TRANS(WRPR_tstate, 64, do_wr_special, a, supervisor(dc), do_wrtstate)
37479422278eSRichard Henderson 
37489422278eSRichard Henderson static void do_wrtt(DisasContext *dc, TCGv src)
37499422278eSRichard Henderson {
37509422278eSRichard Henderson #ifdef TARGET_SPARC64
37519422278eSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
37529422278eSRichard Henderson 
37539422278eSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
37549422278eSRichard Henderson     tcg_gen_st32_tl(src, r_tsptr, offsetof(trap_state, tt));
37559422278eSRichard Henderson #else
37569422278eSRichard Henderson     qemu_build_not_reached();
37579422278eSRichard Henderson #endif
37589422278eSRichard Henderson }
37599422278eSRichard Henderson 
37609422278eSRichard Henderson TRANS(WRPR_tt, 64, do_wr_special, a, supervisor(dc), do_wrtt)
37619422278eSRichard Henderson 
37629422278eSRichard Henderson static void do_wrtick(DisasContext *dc, TCGv src)
37639422278eSRichard Henderson {
37649422278eSRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
37659422278eSRichard Henderson 
37669422278eSRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(tick));
37679422278eSRichard Henderson     translator_io_start(&dc->base);
37689422278eSRichard Henderson     gen_helper_tick_set_count(r_tickptr, src);
37699422278eSRichard Henderson     /* End TB to handle timer interrupt */
37709422278eSRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
37719422278eSRichard Henderson }
37729422278eSRichard Henderson 
37739422278eSRichard Henderson TRANS(WRPR_tick, 64, do_wr_special, a, supervisor(dc), do_wrtick)
37749422278eSRichard Henderson 
37759422278eSRichard Henderson static void do_wrtba(DisasContext *dc, TCGv src)
37769422278eSRichard Henderson {
37779422278eSRichard Henderson     tcg_gen_mov_tl(cpu_tbr, src);
37789422278eSRichard Henderson }
37799422278eSRichard Henderson 
37809422278eSRichard Henderson TRANS(WRPR_tba, 64, do_wr_special, a, supervisor(dc), do_wrtba)
37819422278eSRichard Henderson 
37829422278eSRichard Henderson static void do_wrpstate(DisasContext *dc, TCGv src)
37839422278eSRichard Henderson {
37849422278eSRichard Henderson     save_state(dc);
37859422278eSRichard Henderson     if (translator_io_start(&dc->base)) {
37869422278eSRichard Henderson         dc->base.is_jmp = DISAS_EXIT;
37879422278eSRichard Henderson     }
37889422278eSRichard Henderson     gen_helper_wrpstate(tcg_env, src);
37899422278eSRichard Henderson     dc->npc = DYNAMIC_PC;
37909422278eSRichard Henderson }
37919422278eSRichard Henderson 
37929422278eSRichard Henderson TRANS(WRPR_pstate, 64, do_wr_special, a, supervisor(dc), do_wrpstate)
37939422278eSRichard Henderson 
37949422278eSRichard Henderson static void do_wrtl(DisasContext *dc, TCGv src)
37959422278eSRichard Henderson {
37969422278eSRichard Henderson     save_state(dc);
37979422278eSRichard Henderson     tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(tl));
37989422278eSRichard Henderson     dc->npc = DYNAMIC_PC;
37999422278eSRichard Henderson }
38009422278eSRichard Henderson 
38019422278eSRichard Henderson TRANS(WRPR_tl, 64, do_wr_special, a, supervisor(dc), do_wrtl)
38029422278eSRichard Henderson 
38039422278eSRichard Henderson static void do_wrpil(DisasContext *dc, TCGv src)
38049422278eSRichard Henderson {
38059422278eSRichard Henderson     if (translator_io_start(&dc->base)) {
38069422278eSRichard Henderson         dc->base.is_jmp = DISAS_EXIT;
38079422278eSRichard Henderson     }
38089422278eSRichard Henderson     gen_helper_wrpil(tcg_env, src);
38099422278eSRichard Henderson }
38109422278eSRichard Henderson 
38119422278eSRichard Henderson TRANS(WRPR_pil, 64, do_wr_special, a, supervisor(dc), do_wrpil)
38129422278eSRichard Henderson 
38139422278eSRichard Henderson static void do_wrcwp(DisasContext *dc, TCGv src)
38149422278eSRichard Henderson {
38159422278eSRichard Henderson     gen_helper_wrcwp(tcg_env, src);
38169422278eSRichard Henderson }
38179422278eSRichard Henderson 
38189422278eSRichard Henderson TRANS(WRPR_cwp, 64, do_wr_special, a, supervisor(dc), do_wrcwp)
38199422278eSRichard Henderson 
38209422278eSRichard Henderson static void do_wrcansave(DisasContext *dc, TCGv src)
38219422278eSRichard Henderson {
38229422278eSRichard Henderson     tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(cansave));
38239422278eSRichard Henderson }
38249422278eSRichard Henderson 
38259422278eSRichard Henderson TRANS(WRPR_cansave, 64, do_wr_special, a, supervisor(dc), do_wrcansave)
38269422278eSRichard Henderson 
38279422278eSRichard Henderson static void do_wrcanrestore(DisasContext *dc, TCGv src)
38289422278eSRichard Henderson {
38299422278eSRichard Henderson     tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(canrestore));
38309422278eSRichard Henderson }
38319422278eSRichard Henderson 
38329422278eSRichard Henderson TRANS(WRPR_canrestore, 64, do_wr_special, a, supervisor(dc), do_wrcanrestore)
38339422278eSRichard Henderson 
38349422278eSRichard Henderson static void do_wrcleanwin(DisasContext *dc, TCGv src)
38359422278eSRichard Henderson {
38369422278eSRichard Henderson     tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(cleanwin));
38379422278eSRichard Henderson }
38389422278eSRichard Henderson 
38399422278eSRichard Henderson TRANS(WRPR_cleanwin, 64, do_wr_special, a, supervisor(dc), do_wrcleanwin)
38409422278eSRichard Henderson 
38419422278eSRichard Henderson static void do_wrotherwin(DisasContext *dc, TCGv src)
38429422278eSRichard Henderson {
38439422278eSRichard Henderson     tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(otherwin));
38449422278eSRichard Henderson }
38459422278eSRichard Henderson 
38469422278eSRichard Henderson TRANS(WRPR_otherwin, 64, do_wr_special, a, supervisor(dc), do_wrotherwin)
38479422278eSRichard Henderson 
38489422278eSRichard Henderson static void do_wrwstate(DisasContext *dc, TCGv src)
38499422278eSRichard Henderson {
38509422278eSRichard Henderson     tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(wstate));
38519422278eSRichard Henderson }
38529422278eSRichard Henderson 
38539422278eSRichard Henderson TRANS(WRPR_wstate, 64, do_wr_special, a, supervisor(dc), do_wrwstate)
38549422278eSRichard Henderson 
38559422278eSRichard Henderson static void do_wrgl(DisasContext *dc, TCGv src)
38569422278eSRichard Henderson {
38579422278eSRichard Henderson     gen_helper_wrgl(tcg_env, src);
38589422278eSRichard Henderson }
38599422278eSRichard Henderson 
38609422278eSRichard Henderson TRANS(WRPR_gl, GL, do_wr_special, a, supervisor(dc), do_wrgl)
38619422278eSRichard Henderson 
38629422278eSRichard Henderson /* UA2005 strand status */
38639422278eSRichard Henderson static void do_wrssr(DisasContext *dc, TCGv src)
38649422278eSRichard Henderson {
38652da789deSRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(ssr));
38669422278eSRichard Henderson }
38679422278eSRichard Henderson 
38689422278eSRichard Henderson TRANS(WRPR_strand_status, HYPV, do_wr_special, a, hypervisor(dc), do_wrssr)
38699422278eSRichard Henderson 
3870bb97f2f5SRichard Henderson TRANS(WRTBR, 32, do_wr_special, a, supervisor(dc), do_wrtba)
3871bb97f2f5SRichard Henderson 
3872bb97f2f5SRichard Henderson static void do_wrhpstate(DisasContext *dc, TCGv src)
3873bb97f2f5SRichard Henderson {
3874bb97f2f5SRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(hpstate));
3875bb97f2f5SRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
3876bb97f2f5SRichard Henderson }
3877bb97f2f5SRichard Henderson 
3878bb97f2f5SRichard Henderson TRANS(WRHPR_hpstate, HYPV, do_wr_special, a, hypervisor(dc), do_wrhpstate)
3879bb97f2f5SRichard Henderson 
3880bb97f2f5SRichard Henderson static void do_wrhtstate(DisasContext *dc, TCGv src)
3881bb97f2f5SRichard Henderson {
3882bb97f2f5SRichard Henderson     TCGv_i32 tl = tcg_temp_new_i32();
3883bb97f2f5SRichard Henderson     TCGv_ptr tp = tcg_temp_new_ptr();
3884bb97f2f5SRichard Henderson 
3885bb97f2f5SRichard Henderson     tcg_gen_ld_i32(tl, tcg_env, env64_field_offsetof(tl));
3886bb97f2f5SRichard Henderson     tcg_gen_andi_i32(tl, tl, MAXTL_MASK);
3887bb97f2f5SRichard Henderson     tcg_gen_shli_i32(tl, tl, 3);
3888bb97f2f5SRichard Henderson     tcg_gen_ext_i32_ptr(tp, tl);
3889bb97f2f5SRichard Henderson     tcg_gen_add_ptr(tp, tp, tcg_env);
3890bb97f2f5SRichard Henderson 
3891bb97f2f5SRichard Henderson     tcg_gen_st_tl(src, tp, env64_field_offsetof(htstate));
3892bb97f2f5SRichard Henderson }
3893bb97f2f5SRichard Henderson 
3894bb97f2f5SRichard Henderson TRANS(WRHPR_htstate, HYPV, do_wr_special, a, hypervisor(dc), do_wrhtstate)
3895bb97f2f5SRichard Henderson 
3896bb97f2f5SRichard Henderson static void do_wrhintp(DisasContext *dc, TCGv src)
3897bb97f2f5SRichard Henderson {
38982da789deSRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(hintp));
3899bb97f2f5SRichard Henderson }
3900bb97f2f5SRichard Henderson 
3901bb97f2f5SRichard Henderson TRANS(WRHPR_hintp, HYPV, do_wr_special, a, hypervisor(dc), do_wrhintp)
3902bb97f2f5SRichard Henderson 
3903bb97f2f5SRichard Henderson static void do_wrhtba(DisasContext *dc, TCGv src)
3904bb97f2f5SRichard Henderson {
39052da789deSRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(htba));
3906bb97f2f5SRichard Henderson }
3907bb97f2f5SRichard Henderson 
3908bb97f2f5SRichard Henderson TRANS(WRHPR_htba, HYPV, do_wr_special, a, hypervisor(dc), do_wrhtba)
3909bb97f2f5SRichard Henderson 
3910bb97f2f5SRichard Henderson static void do_wrhstick_cmpr(DisasContext *dc, TCGv src)
3911bb97f2f5SRichard Henderson {
3912bb97f2f5SRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
3913bb97f2f5SRichard Henderson 
3914577efa45SRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(hstick_cmpr));
3915bb97f2f5SRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(hstick));
3916bb97f2f5SRichard Henderson     translator_io_start(&dc->base);
3917577efa45SRichard Henderson     gen_helper_tick_set_limit(r_tickptr, src);
3918bb97f2f5SRichard Henderson     /* End TB to handle timer interrupt */
3919bb97f2f5SRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
3920bb97f2f5SRichard Henderson }
3921bb97f2f5SRichard Henderson 
3922bb97f2f5SRichard Henderson TRANS(WRHPR_hstick_cmpr, HYPV, do_wr_special, a, hypervisor(dc),
3923bb97f2f5SRichard Henderson       do_wrhstick_cmpr)
3924bb97f2f5SRichard Henderson 
392525524734SRichard Henderson static bool do_saved_restored(DisasContext *dc, bool saved)
392625524734SRichard Henderson {
392725524734SRichard Henderson     if (!supervisor(dc)) {
392825524734SRichard Henderson         return raise_priv(dc);
392925524734SRichard Henderson     }
393025524734SRichard Henderson     if (saved) {
393125524734SRichard Henderson         gen_helper_saved(tcg_env);
393225524734SRichard Henderson     } else {
393325524734SRichard Henderson         gen_helper_restored(tcg_env);
393425524734SRichard Henderson     }
393525524734SRichard Henderson     return advance_pc(dc);
393625524734SRichard Henderson }
393725524734SRichard Henderson 
393825524734SRichard Henderson TRANS(SAVED, 64, do_saved_restored, true)
393925524734SRichard Henderson TRANS(RESTORED, 64, do_saved_restored, false)
394025524734SRichard Henderson 
3941d3825800SRichard Henderson static bool trans_NOP(DisasContext *dc, arg_NOP *a)
3942d3825800SRichard Henderson {
3943d3825800SRichard Henderson     return advance_pc(dc);
3944d3825800SRichard Henderson }
3945d3825800SRichard Henderson 
39460faef01bSRichard Henderson /*
39470faef01bSRichard Henderson  * TODO: Need a feature bit for sparcv8.
39480faef01bSRichard Henderson  * In the meantime, treat all 32-bit cpus like sparcv7.
39490faef01bSRichard Henderson  */
39505458fd31SRichard Henderson TRANS(NOP_v7, 32, trans_NOP, a)
39515458fd31SRichard Henderson TRANS(NOP_v9, 64, trans_NOP, a)
39520faef01bSRichard Henderson 
3953428881deSRichard Henderson static bool do_arith_int(DisasContext *dc, arg_r_r_ri_cc *a, int cc_op,
3954428881deSRichard Henderson                          void (*func)(TCGv, TCGv, TCGv),
3955428881deSRichard Henderson                          void (*funci)(TCGv, TCGv, target_long))
3956428881deSRichard Henderson {
3957428881deSRichard Henderson     TCGv dst, src1;
3958428881deSRichard Henderson 
3959428881deSRichard Henderson     /* For simplicity, we under-decoded the rs2 form. */
3960428881deSRichard Henderson     if (!a->imm && a->rs2_or_imm & ~0x1f) {
3961428881deSRichard Henderson         return false;
3962428881deSRichard Henderson     }
3963428881deSRichard Henderson 
3964428881deSRichard Henderson     if (a->cc) {
3965428881deSRichard Henderson         dst = cpu_cc_dst;
3966428881deSRichard Henderson     } else {
3967428881deSRichard Henderson         dst = gen_dest_gpr(dc, a->rd);
3968428881deSRichard Henderson     }
3969428881deSRichard Henderson     src1 = gen_load_gpr(dc, a->rs1);
3970428881deSRichard Henderson 
3971428881deSRichard Henderson     if (a->imm || a->rs2_or_imm == 0) {
3972428881deSRichard Henderson         if (funci) {
3973428881deSRichard Henderson             funci(dst, src1, a->rs2_or_imm);
3974428881deSRichard Henderson         } else {
3975428881deSRichard Henderson             func(dst, src1, tcg_constant_tl(a->rs2_or_imm));
3976428881deSRichard Henderson         }
3977428881deSRichard Henderson     } else {
3978428881deSRichard Henderson         func(dst, src1, cpu_regs[a->rs2_or_imm]);
3979428881deSRichard Henderson     }
3980428881deSRichard Henderson     gen_store_gpr(dc, a->rd, dst);
3981428881deSRichard Henderson 
3982428881deSRichard Henderson     if (a->cc) {
3983428881deSRichard Henderson         tcg_gen_movi_i32(cpu_cc_op, cc_op);
3984428881deSRichard Henderson         dc->cc_op = cc_op;
3985428881deSRichard Henderson     }
3986428881deSRichard Henderson     return advance_pc(dc);
3987428881deSRichard Henderson }
3988428881deSRichard Henderson 
3989428881deSRichard Henderson static bool do_arith(DisasContext *dc, arg_r_r_ri_cc *a, int cc_op,
3990428881deSRichard Henderson                      void (*func)(TCGv, TCGv, TCGv),
3991428881deSRichard Henderson                      void (*funci)(TCGv, TCGv, target_long),
3992428881deSRichard Henderson                      void (*func_cc)(TCGv, TCGv, TCGv))
3993428881deSRichard Henderson {
3994428881deSRichard Henderson     if (a->cc) {
399522188d7dSRichard Henderson         assert(cc_op >= 0);
3996428881deSRichard Henderson         return do_arith_int(dc, a, cc_op, func_cc, NULL);
3997428881deSRichard Henderson     }
3998428881deSRichard Henderson     return do_arith_int(dc, a, cc_op, func, funci);
3999428881deSRichard Henderson }
4000428881deSRichard Henderson 
4001428881deSRichard Henderson static bool do_logic(DisasContext *dc, arg_r_r_ri_cc *a,
4002428881deSRichard Henderson                      void (*func)(TCGv, TCGv, TCGv),
4003428881deSRichard Henderson                      void (*funci)(TCGv, TCGv, target_long))
4004428881deSRichard Henderson {
4005428881deSRichard Henderson     return do_arith_int(dc, a, CC_OP_LOGIC, func, funci);
4006428881deSRichard Henderson }
4007428881deSRichard Henderson 
4008428881deSRichard Henderson TRANS(ADD, ALL, do_arith, a, CC_OP_ADD,
4009428881deSRichard Henderson       tcg_gen_add_tl, tcg_gen_addi_tl, gen_op_add_cc)
4010428881deSRichard Henderson TRANS(SUB, ALL, do_arith, a, CC_OP_SUB,
4011428881deSRichard Henderson       tcg_gen_sub_tl, tcg_gen_subi_tl, gen_op_sub_cc)
4012428881deSRichard Henderson 
4013a9aba13dSRichard Henderson TRANS(TADDcc, ALL, do_arith, a, CC_OP_TADD, NULL, NULL, gen_op_add_cc)
4014a9aba13dSRichard Henderson TRANS(TSUBcc, ALL, do_arith, a, CC_OP_TSUB, NULL, NULL, gen_op_sub_cc)
4015a9aba13dSRichard Henderson TRANS(TADDccTV, ALL, do_arith, a, CC_OP_TADDTV, NULL, NULL, gen_op_taddcctv)
4016a9aba13dSRichard Henderson TRANS(TSUBccTV, ALL, do_arith, a, CC_OP_TSUBTV, NULL, NULL, gen_op_tsubcctv)
4017a9aba13dSRichard Henderson 
4018428881deSRichard Henderson TRANS(AND, ALL, do_logic, a, tcg_gen_and_tl, tcg_gen_andi_tl)
4019428881deSRichard Henderson TRANS(XOR, ALL, do_logic, a, tcg_gen_xor_tl, tcg_gen_xori_tl)
4020428881deSRichard Henderson TRANS(ANDN, ALL, do_logic, a, tcg_gen_andc_tl, NULL)
4021428881deSRichard Henderson TRANS(ORN, ALL, do_logic, a, tcg_gen_orc_tl, NULL)
4022428881deSRichard Henderson TRANS(XORN, ALL, do_logic, a, tcg_gen_eqv_tl, NULL)
4023428881deSRichard Henderson 
402422188d7dSRichard Henderson TRANS(MULX, 64, do_arith, a, -1, tcg_gen_mul_tl, tcg_gen_muli_tl, NULL)
4025b5372650SRichard Henderson TRANS(UMUL, MUL, do_logic, a, gen_op_umul, NULL)
4026b5372650SRichard Henderson TRANS(SMUL, MUL, do_logic, a, gen_op_smul, NULL)
402722188d7dSRichard Henderson 
40284ee85ea9SRichard Henderson TRANS(UDIVX, 64, do_arith, a, -1, gen_op_udivx, NULL, NULL)
40294ee85ea9SRichard Henderson TRANS(SDIVX, 64, do_arith, a, -1, gen_op_sdivx, NULL, NULL)
4030c2636853SRichard Henderson TRANS(UDIV, DIV, do_arith, a, CC_OP_DIV, gen_op_udiv, NULL, gen_op_udivcc)
4031c2636853SRichard Henderson TRANS(SDIV, DIV, do_arith, a, CC_OP_DIV, gen_op_sdiv, NULL, gen_op_sdivcc)
40324ee85ea9SRichard Henderson 
40339c6ec5bcSRichard Henderson /* TODO: Should have feature bit -- comes in with UltraSparc T2. */
40349c6ec5bcSRichard Henderson TRANS(POPC, 64, do_arith, a, -1, gen_op_popc, NULL, NULL)
40359c6ec5bcSRichard Henderson 
4036428881deSRichard Henderson static bool trans_OR(DisasContext *dc, arg_r_r_ri_cc *a)
4037428881deSRichard Henderson {
4038428881deSRichard Henderson     /* OR with %g0 is the canonical alias for MOV. */
4039428881deSRichard Henderson     if (!a->cc && a->rs1 == 0) {
4040428881deSRichard Henderson         if (a->imm || a->rs2_or_imm == 0) {
4041428881deSRichard Henderson             gen_store_gpr(dc, a->rd, tcg_constant_tl(a->rs2_or_imm));
4042428881deSRichard Henderson         } else if (a->rs2_or_imm & ~0x1f) {
4043428881deSRichard Henderson             /* For simplicity, we under-decoded the rs2 form. */
4044428881deSRichard Henderson             return false;
4045428881deSRichard Henderson         } else {
4046428881deSRichard Henderson             gen_store_gpr(dc, a->rd, cpu_regs[a->rs2_or_imm]);
4047428881deSRichard Henderson         }
4048428881deSRichard Henderson         return advance_pc(dc);
4049428881deSRichard Henderson     }
4050428881deSRichard Henderson     return do_logic(dc, a, tcg_gen_or_tl, tcg_gen_ori_tl);
4051428881deSRichard Henderson }
4052428881deSRichard Henderson 
4053420a187dSRichard Henderson static bool trans_ADDC(DisasContext *dc, arg_r_r_ri_cc *a)
4054420a187dSRichard Henderson {
4055420a187dSRichard Henderson     switch (dc->cc_op) {
4056420a187dSRichard Henderson     case CC_OP_DIV:
4057420a187dSRichard Henderson     case CC_OP_LOGIC:
4058420a187dSRichard Henderson         /* Carry is known to be zero.  Fall back to plain ADD.  */
4059420a187dSRichard Henderson         return do_arith(dc, a, CC_OP_ADD,
4060420a187dSRichard Henderson                         tcg_gen_add_tl, tcg_gen_addi_tl, gen_op_add_cc);
4061420a187dSRichard Henderson     case CC_OP_ADD:
4062420a187dSRichard Henderson     case CC_OP_TADD:
4063420a187dSRichard Henderson     case CC_OP_TADDTV:
4064420a187dSRichard Henderson         return do_arith(dc, a, CC_OP_ADDX,
4065420a187dSRichard Henderson                         gen_op_addc_add, NULL, gen_op_addccc_add);
4066420a187dSRichard Henderson     case CC_OP_SUB:
4067420a187dSRichard Henderson     case CC_OP_TSUB:
4068420a187dSRichard Henderson     case CC_OP_TSUBTV:
4069420a187dSRichard Henderson         return do_arith(dc, a, CC_OP_ADDX,
4070420a187dSRichard Henderson                         gen_op_addc_sub, NULL, gen_op_addccc_sub);
4071420a187dSRichard Henderson     default:
4072420a187dSRichard Henderson         return do_arith(dc, a, CC_OP_ADDX,
4073420a187dSRichard Henderson                         gen_op_addc_generic, NULL, gen_op_addccc_generic);
4074420a187dSRichard Henderson     }
4075420a187dSRichard Henderson }
4076420a187dSRichard Henderson 
4077dfebb950SRichard Henderson static bool trans_SUBC(DisasContext *dc, arg_r_r_ri_cc *a)
4078dfebb950SRichard Henderson {
4079dfebb950SRichard Henderson     switch (dc->cc_op) {
4080dfebb950SRichard Henderson     case CC_OP_DIV:
4081dfebb950SRichard Henderson     case CC_OP_LOGIC:
4082dfebb950SRichard Henderson         /* Carry is known to be zero.  Fall back to plain SUB.  */
4083dfebb950SRichard Henderson         return do_arith(dc, a, CC_OP_SUB,
4084dfebb950SRichard Henderson                         tcg_gen_sub_tl, tcg_gen_subi_tl, gen_op_sub_cc);
4085dfebb950SRichard Henderson     case CC_OP_ADD:
4086dfebb950SRichard Henderson     case CC_OP_TADD:
4087dfebb950SRichard Henderson     case CC_OP_TADDTV:
4088dfebb950SRichard Henderson         return do_arith(dc, a, CC_OP_SUBX,
4089dfebb950SRichard Henderson                         gen_op_subc_add, NULL, gen_op_subccc_add);
4090dfebb950SRichard Henderson     case CC_OP_SUB:
4091dfebb950SRichard Henderson     case CC_OP_TSUB:
4092dfebb950SRichard Henderson     case CC_OP_TSUBTV:
4093dfebb950SRichard Henderson         return do_arith(dc, a, CC_OP_SUBX,
4094dfebb950SRichard Henderson                         gen_op_subc_sub, NULL, gen_op_subccc_sub);
4095dfebb950SRichard Henderson     default:
4096dfebb950SRichard Henderson         return do_arith(dc, a, CC_OP_SUBX,
4097dfebb950SRichard Henderson                         gen_op_subc_generic, NULL, gen_op_subccc_generic);
4098dfebb950SRichard Henderson     }
4099dfebb950SRichard Henderson }
4100dfebb950SRichard Henderson 
4101a9aba13dSRichard Henderson static bool trans_MULScc(DisasContext *dc, arg_r_r_ri_cc *a)
4102a9aba13dSRichard Henderson {
4103a9aba13dSRichard Henderson     update_psr(dc);
4104a9aba13dSRichard Henderson     return do_arith(dc, a, CC_OP_ADD, NULL, NULL, gen_op_mulscc);
4105a9aba13dSRichard Henderson }
4106a9aba13dSRichard Henderson 
4107b88ce6f2SRichard Henderson static bool gen_edge(DisasContext *dc, arg_r_r_r *a,
4108b88ce6f2SRichard Henderson                      int width, bool cc, bool left)
4109b88ce6f2SRichard Henderson {
4110b88ce6f2SRichard Henderson     TCGv dst, s1, s2, lo1, lo2;
4111b88ce6f2SRichard Henderson     uint64_t amask, tabl, tabr;
4112b88ce6f2SRichard Henderson     int shift, imask, omask;
4113b88ce6f2SRichard Henderson 
4114b88ce6f2SRichard Henderson     dst = gen_dest_gpr(dc, a->rd);
4115b88ce6f2SRichard Henderson     s1 = gen_load_gpr(dc, a->rs1);
4116b88ce6f2SRichard Henderson     s2 = gen_load_gpr(dc, a->rs2);
4117b88ce6f2SRichard Henderson 
4118b88ce6f2SRichard Henderson     if (cc) {
4119b88ce6f2SRichard Henderson         tcg_gen_mov_tl(cpu_cc_src, s1);
4120b88ce6f2SRichard Henderson         tcg_gen_mov_tl(cpu_cc_src2, s2);
4121b88ce6f2SRichard Henderson         tcg_gen_sub_tl(cpu_cc_dst, s1, s2);
4122b88ce6f2SRichard Henderson         tcg_gen_movi_i32(cpu_cc_op, CC_OP_SUB);
4123b88ce6f2SRichard Henderson         dc->cc_op = CC_OP_SUB;
4124b88ce6f2SRichard Henderson     }
4125b88ce6f2SRichard Henderson 
4126b88ce6f2SRichard Henderson     /*
4127b88ce6f2SRichard Henderson      * Theory of operation: there are two tables, left and right (not to
4128b88ce6f2SRichard Henderson      * be confused with the left and right versions of the opcode).  These
4129b88ce6f2SRichard Henderson      * are indexed by the low 3 bits of the inputs.  To make things "easy",
4130b88ce6f2SRichard Henderson      * these tables are loaded into two constants, TABL and TABR below.
4131b88ce6f2SRichard Henderson      * The operation index = (input & imask) << shift calculates the index
4132b88ce6f2SRichard Henderson      * into the constant, while val = (table >> index) & omask calculates
4133b88ce6f2SRichard Henderson      * the value we're looking for.
4134b88ce6f2SRichard Henderson      */
4135b88ce6f2SRichard Henderson     switch (width) {
4136b88ce6f2SRichard Henderson     case 8:
4137b88ce6f2SRichard Henderson         imask = 0x7;
4138b88ce6f2SRichard Henderson         shift = 3;
4139b88ce6f2SRichard Henderson         omask = 0xff;
4140b88ce6f2SRichard Henderson         if (left) {
4141b88ce6f2SRichard Henderson             tabl = 0x80c0e0f0f8fcfeffULL;
4142b88ce6f2SRichard Henderson             tabr = 0xff7f3f1f0f070301ULL;
4143b88ce6f2SRichard Henderson         } else {
4144b88ce6f2SRichard Henderson             tabl = 0x0103070f1f3f7fffULL;
4145b88ce6f2SRichard Henderson             tabr = 0xfffefcf8f0e0c080ULL;
4146b88ce6f2SRichard Henderson         }
4147b88ce6f2SRichard Henderson         break;
4148b88ce6f2SRichard Henderson     case 16:
4149b88ce6f2SRichard Henderson         imask = 0x6;
4150b88ce6f2SRichard Henderson         shift = 1;
4151b88ce6f2SRichard Henderson         omask = 0xf;
4152b88ce6f2SRichard Henderson         if (left) {
4153b88ce6f2SRichard Henderson             tabl = 0x8cef;
4154b88ce6f2SRichard Henderson             tabr = 0xf731;
4155b88ce6f2SRichard Henderson         } else {
4156b88ce6f2SRichard Henderson             tabl = 0x137f;
4157b88ce6f2SRichard Henderson             tabr = 0xfec8;
4158b88ce6f2SRichard Henderson         }
4159b88ce6f2SRichard Henderson         break;
4160b88ce6f2SRichard Henderson     case 32:
4161b88ce6f2SRichard Henderson         imask = 0x4;
4162b88ce6f2SRichard Henderson         shift = 0;
4163b88ce6f2SRichard Henderson         omask = 0x3;
4164b88ce6f2SRichard Henderson         if (left) {
4165b88ce6f2SRichard Henderson             tabl = (2 << 2) | 3;
4166b88ce6f2SRichard Henderson             tabr = (3 << 2) | 1;
4167b88ce6f2SRichard Henderson         } else {
4168b88ce6f2SRichard Henderson             tabl = (1 << 2) | 3;
4169b88ce6f2SRichard Henderson             tabr = (3 << 2) | 2;
4170b88ce6f2SRichard Henderson         }
4171b88ce6f2SRichard Henderson         break;
4172b88ce6f2SRichard Henderson     default:
4173b88ce6f2SRichard Henderson         abort();
4174b88ce6f2SRichard Henderson     }
4175b88ce6f2SRichard Henderson 
4176b88ce6f2SRichard Henderson     lo1 = tcg_temp_new();
4177b88ce6f2SRichard Henderson     lo2 = tcg_temp_new();
4178b88ce6f2SRichard Henderson     tcg_gen_andi_tl(lo1, s1, imask);
4179b88ce6f2SRichard Henderson     tcg_gen_andi_tl(lo2, s2, imask);
4180b88ce6f2SRichard Henderson     tcg_gen_shli_tl(lo1, lo1, shift);
4181b88ce6f2SRichard Henderson     tcg_gen_shli_tl(lo2, lo2, shift);
4182b88ce6f2SRichard Henderson 
4183b88ce6f2SRichard Henderson     tcg_gen_shr_tl(lo1, tcg_constant_tl(tabl), lo1);
4184b88ce6f2SRichard Henderson     tcg_gen_shr_tl(lo2, tcg_constant_tl(tabr), lo2);
4185b88ce6f2SRichard Henderson     tcg_gen_andi_tl(lo1, lo1, omask);
4186b88ce6f2SRichard Henderson     tcg_gen_andi_tl(lo2, lo2, omask);
4187b88ce6f2SRichard Henderson 
4188b88ce6f2SRichard Henderson     amask = address_mask_i(dc, -8);
4189b88ce6f2SRichard Henderson     tcg_gen_andi_tl(s1, s1, amask);
4190b88ce6f2SRichard Henderson     tcg_gen_andi_tl(s2, s2, amask);
4191b88ce6f2SRichard Henderson 
4192b88ce6f2SRichard Henderson     /* Compute dst = (s1 == s2 ? lo1 : lo1 & lo2). */
4193b88ce6f2SRichard Henderson     tcg_gen_and_tl(lo2, lo2, lo1);
4194b88ce6f2SRichard Henderson     tcg_gen_movcond_tl(TCG_COND_EQ, dst, s1, s2, lo1, lo2);
4195b88ce6f2SRichard Henderson 
4196b88ce6f2SRichard Henderson     gen_store_gpr(dc, a->rd, dst);
4197b88ce6f2SRichard Henderson     return advance_pc(dc);
4198b88ce6f2SRichard Henderson }
4199b88ce6f2SRichard Henderson 
4200b88ce6f2SRichard Henderson TRANS(EDGE8cc, VIS1, gen_edge, a, 8, 1, 0)
4201b88ce6f2SRichard Henderson TRANS(EDGE8Lcc, VIS1, gen_edge, a, 8, 1, 1)
4202b88ce6f2SRichard Henderson TRANS(EDGE16cc, VIS1, gen_edge, a, 16, 1, 0)
4203b88ce6f2SRichard Henderson TRANS(EDGE16Lcc, VIS1, gen_edge, a, 16, 1, 1)
4204b88ce6f2SRichard Henderson TRANS(EDGE32cc, VIS1, gen_edge, a, 32, 1, 0)
4205b88ce6f2SRichard Henderson TRANS(EDGE32Lcc, VIS1, gen_edge, a, 32, 1, 1)
4206b88ce6f2SRichard Henderson 
4207b88ce6f2SRichard Henderson TRANS(EDGE8N, VIS2, gen_edge, a, 8, 0, 0)
4208b88ce6f2SRichard Henderson TRANS(EDGE8LN, VIS2, gen_edge, a, 8, 0, 1)
4209b88ce6f2SRichard Henderson TRANS(EDGE16N, VIS2, gen_edge, a, 16, 0, 0)
4210b88ce6f2SRichard Henderson TRANS(EDGE16LN, VIS2, gen_edge, a, 16, 0, 1)
4211b88ce6f2SRichard Henderson TRANS(EDGE32N, VIS2, gen_edge, a, 32, 0, 0)
4212b88ce6f2SRichard Henderson TRANS(EDGE32LN, VIS2, gen_edge, a, 32, 0, 1)
4213b88ce6f2SRichard Henderson 
421445bfed3bSRichard Henderson static bool do_rrr(DisasContext *dc, arg_r_r_r *a,
421545bfed3bSRichard Henderson                    void (*func)(TCGv, TCGv, TCGv))
421645bfed3bSRichard Henderson {
421745bfed3bSRichard Henderson     TCGv dst = gen_dest_gpr(dc, a->rd);
421845bfed3bSRichard Henderson     TCGv src1 = gen_load_gpr(dc, a->rs1);
421945bfed3bSRichard Henderson     TCGv src2 = gen_load_gpr(dc, a->rs2);
422045bfed3bSRichard Henderson 
422145bfed3bSRichard Henderson     func(dst, src1, src2);
422245bfed3bSRichard Henderson     gen_store_gpr(dc, a->rd, dst);
422345bfed3bSRichard Henderson     return advance_pc(dc);
422445bfed3bSRichard Henderson }
422545bfed3bSRichard Henderson 
422645bfed3bSRichard Henderson TRANS(ARRAY8, VIS1, do_rrr, a, gen_helper_array8)
422745bfed3bSRichard Henderson TRANS(ARRAY16, VIS1, do_rrr, a, gen_op_array16)
422845bfed3bSRichard Henderson TRANS(ARRAY32, VIS1, do_rrr, a, gen_op_array32)
422945bfed3bSRichard Henderson 
42309e20ca94SRichard Henderson static void gen_op_alignaddr(TCGv dst, TCGv s1, TCGv s2)
42319e20ca94SRichard Henderson {
42329e20ca94SRichard Henderson #ifdef TARGET_SPARC64
42339e20ca94SRichard Henderson     TCGv tmp = tcg_temp_new();
42349e20ca94SRichard Henderson 
42359e20ca94SRichard Henderson     tcg_gen_add_tl(tmp, s1, s2);
42369e20ca94SRichard Henderson     tcg_gen_andi_tl(dst, tmp, -8);
42379e20ca94SRichard Henderson     tcg_gen_deposit_tl(cpu_gsr, cpu_gsr, tmp, 0, 3);
42389e20ca94SRichard Henderson #else
42399e20ca94SRichard Henderson     g_assert_not_reached();
42409e20ca94SRichard Henderson #endif
42419e20ca94SRichard Henderson }
42429e20ca94SRichard Henderson 
42439e20ca94SRichard Henderson static void gen_op_alignaddrl(TCGv dst, TCGv s1, TCGv s2)
42449e20ca94SRichard Henderson {
42459e20ca94SRichard Henderson #ifdef TARGET_SPARC64
42469e20ca94SRichard Henderson     TCGv tmp = tcg_temp_new();
42479e20ca94SRichard Henderson 
42489e20ca94SRichard Henderson     tcg_gen_add_tl(tmp, s1, s2);
42499e20ca94SRichard Henderson     tcg_gen_andi_tl(dst, tmp, -8);
42509e20ca94SRichard Henderson     tcg_gen_neg_tl(tmp, tmp);
42519e20ca94SRichard Henderson     tcg_gen_deposit_tl(cpu_gsr, cpu_gsr, tmp, 0, 3);
42529e20ca94SRichard Henderson #else
42539e20ca94SRichard Henderson     g_assert_not_reached();
42549e20ca94SRichard Henderson #endif
42559e20ca94SRichard Henderson }
42569e20ca94SRichard Henderson 
42579e20ca94SRichard Henderson TRANS(ALIGNADDR, VIS1, do_rrr, a, gen_op_alignaddr)
42589e20ca94SRichard Henderson TRANS(ALIGNADDRL, VIS1, do_rrr, a, gen_op_alignaddrl)
42599e20ca94SRichard Henderson 
426039ca3490SRichard Henderson static void gen_op_bmask(TCGv dst, TCGv s1, TCGv s2)
426139ca3490SRichard Henderson {
426239ca3490SRichard Henderson #ifdef TARGET_SPARC64
426339ca3490SRichard Henderson     tcg_gen_add_tl(dst, s1, s2);
426439ca3490SRichard Henderson     tcg_gen_deposit_tl(cpu_gsr, cpu_gsr, dst, 32, 32);
426539ca3490SRichard Henderson #else
426639ca3490SRichard Henderson     g_assert_not_reached();
426739ca3490SRichard Henderson #endif
426839ca3490SRichard Henderson }
426939ca3490SRichard Henderson 
427039ca3490SRichard Henderson TRANS(BMASK, VIS2, do_rrr, a, gen_op_bmask)
427139ca3490SRichard Henderson 
42725fc546eeSRichard Henderson static bool do_shift_r(DisasContext *dc, arg_shiftr *a, bool l, bool u)
42735fc546eeSRichard Henderson {
42745fc546eeSRichard Henderson     TCGv dst, src1, src2;
42755fc546eeSRichard Henderson 
42765fc546eeSRichard Henderson     /* Reject 64-bit shifts for sparc32. */
42775fc546eeSRichard Henderson     if (avail_32(dc) && a->x) {
42785fc546eeSRichard Henderson         return false;
42795fc546eeSRichard Henderson     }
42805fc546eeSRichard Henderson 
42815fc546eeSRichard Henderson     src2 = tcg_temp_new();
42825fc546eeSRichard Henderson     tcg_gen_andi_tl(src2, gen_load_gpr(dc, a->rs2), a->x ? 63 : 31);
42835fc546eeSRichard Henderson     src1 = gen_load_gpr(dc, a->rs1);
42845fc546eeSRichard Henderson     dst = gen_dest_gpr(dc, a->rd);
42855fc546eeSRichard Henderson 
42865fc546eeSRichard Henderson     if (l) {
42875fc546eeSRichard Henderson         tcg_gen_shl_tl(dst, src1, src2);
42885fc546eeSRichard Henderson         if (!a->x) {
42895fc546eeSRichard Henderson             tcg_gen_ext32u_tl(dst, dst);
42905fc546eeSRichard Henderson         }
42915fc546eeSRichard Henderson     } else if (u) {
42925fc546eeSRichard Henderson         if (!a->x) {
42935fc546eeSRichard Henderson             tcg_gen_ext32u_tl(dst, src1);
42945fc546eeSRichard Henderson             src1 = dst;
42955fc546eeSRichard Henderson         }
42965fc546eeSRichard Henderson         tcg_gen_shr_tl(dst, src1, src2);
42975fc546eeSRichard Henderson     } else {
42985fc546eeSRichard Henderson         if (!a->x) {
42995fc546eeSRichard Henderson             tcg_gen_ext32s_tl(dst, src1);
43005fc546eeSRichard Henderson             src1 = dst;
43015fc546eeSRichard Henderson         }
43025fc546eeSRichard Henderson         tcg_gen_sar_tl(dst, src1, src2);
43035fc546eeSRichard Henderson     }
43045fc546eeSRichard Henderson     gen_store_gpr(dc, a->rd, dst);
43055fc546eeSRichard Henderson     return advance_pc(dc);
43065fc546eeSRichard Henderson }
43075fc546eeSRichard Henderson 
43085fc546eeSRichard Henderson TRANS(SLL_r, ALL, do_shift_r, a, true, true)
43095fc546eeSRichard Henderson TRANS(SRL_r, ALL, do_shift_r, a, false, true)
43105fc546eeSRichard Henderson TRANS(SRA_r, ALL, do_shift_r, a, false, false)
43115fc546eeSRichard Henderson 
43125fc546eeSRichard Henderson static bool do_shift_i(DisasContext *dc, arg_shifti *a, bool l, bool u)
43135fc546eeSRichard Henderson {
43145fc546eeSRichard Henderson     TCGv dst, src1;
43155fc546eeSRichard Henderson 
43165fc546eeSRichard Henderson     /* Reject 64-bit shifts for sparc32. */
43175fc546eeSRichard Henderson     if (avail_32(dc) && (a->x || a->i >= 32)) {
43185fc546eeSRichard Henderson         return false;
43195fc546eeSRichard Henderson     }
43205fc546eeSRichard Henderson 
43215fc546eeSRichard Henderson     src1 = gen_load_gpr(dc, a->rs1);
43225fc546eeSRichard Henderson     dst = gen_dest_gpr(dc, a->rd);
43235fc546eeSRichard Henderson 
43245fc546eeSRichard Henderson     if (avail_32(dc) || a->x) {
43255fc546eeSRichard Henderson         if (l) {
43265fc546eeSRichard Henderson             tcg_gen_shli_tl(dst, src1, a->i);
43275fc546eeSRichard Henderson         } else if (u) {
43285fc546eeSRichard Henderson             tcg_gen_shri_tl(dst, src1, a->i);
43295fc546eeSRichard Henderson         } else {
43305fc546eeSRichard Henderson             tcg_gen_sari_tl(dst, src1, a->i);
43315fc546eeSRichard Henderson         }
43325fc546eeSRichard Henderson     } else {
43335fc546eeSRichard Henderson         if (l) {
43345fc546eeSRichard Henderson             tcg_gen_deposit_z_tl(dst, src1, a->i, 32 - a->i);
43355fc546eeSRichard Henderson         } else if (u) {
43365fc546eeSRichard Henderson             tcg_gen_extract_tl(dst, src1, a->i, 32 - a->i);
43375fc546eeSRichard Henderson         } else {
43385fc546eeSRichard Henderson             tcg_gen_sextract_tl(dst, src1, a->i, 32 - a->i);
43395fc546eeSRichard Henderson         }
43405fc546eeSRichard Henderson     }
43415fc546eeSRichard Henderson     gen_store_gpr(dc, a->rd, dst);
43425fc546eeSRichard Henderson     return advance_pc(dc);
43435fc546eeSRichard Henderson }
43445fc546eeSRichard Henderson 
43455fc546eeSRichard Henderson TRANS(SLL_i, ALL, do_shift_i, a, true, true)
43465fc546eeSRichard Henderson TRANS(SRL_i, ALL, do_shift_i, a, false, true)
43475fc546eeSRichard Henderson TRANS(SRA_i, ALL, do_shift_i, a, false, false)
43485fc546eeSRichard Henderson 
4349fb4ed7aaSRichard Henderson static TCGv gen_rs2_or_imm(DisasContext *dc, bool imm, int rs2_or_imm)
4350fb4ed7aaSRichard Henderson {
4351fb4ed7aaSRichard Henderson     /* For simplicity, we under-decoded the rs2 form. */
4352fb4ed7aaSRichard Henderson     if (!imm && rs2_or_imm & ~0x1f) {
4353fb4ed7aaSRichard Henderson         return NULL;
4354fb4ed7aaSRichard Henderson     }
4355fb4ed7aaSRichard Henderson     if (imm || rs2_or_imm == 0) {
4356fb4ed7aaSRichard Henderson         return tcg_constant_tl(rs2_or_imm);
4357fb4ed7aaSRichard Henderson     } else {
4358fb4ed7aaSRichard Henderson         return cpu_regs[rs2_or_imm];
4359fb4ed7aaSRichard Henderson     }
4360fb4ed7aaSRichard Henderson }
4361fb4ed7aaSRichard Henderson 
4362fb4ed7aaSRichard Henderson static bool do_mov_cond(DisasContext *dc, DisasCompare *cmp, int rd, TCGv src2)
4363fb4ed7aaSRichard Henderson {
4364fb4ed7aaSRichard Henderson     TCGv dst = gen_load_gpr(dc, rd);
4365fb4ed7aaSRichard Henderson 
4366fb4ed7aaSRichard Henderson     tcg_gen_movcond_tl(cmp->cond, dst, cmp->c1, cmp->c2, src2, dst);
4367fb4ed7aaSRichard Henderson     gen_store_gpr(dc, rd, dst);
4368fb4ed7aaSRichard Henderson     return advance_pc(dc);
4369fb4ed7aaSRichard Henderson }
4370fb4ed7aaSRichard Henderson 
4371fb4ed7aaSRichard Henderson static bool trans_MOVcc(DisasContext *dc, arg_MOVcc *a)
4372fb4ed7aaSRichard Henderson {
4373fb4ed7aaSRichard Henderson     TCGv src2 = gen_rs2_or_imm(dc, a->imm, a->rs2_or_imm);
4374fb4ed7aaSRichard Henderson     DisasCompare cmp;
4375fb4ed7aaSRichard Henderson 
4376fb4ed7aaSRichard Henderson     if (src2 == NULL) {
4377fb4ed7aaSRichard Henderson         return false;
4378fb4ed7aaSRichard Henderson     }
4379fb4ed7aaSRichard Henderson     gen_compare(&cmp, a->cc, a->cond, dc);
4380fb4ed7aaSRichard Henderson     return do_mov_cond(dc, &cmp, a->rd, src2);
4381fb4ed7aaSRichard Henderson }
4382fb4ed7aaSRichard Henderson 
4383fb4ed7aaSRichard Henderson static bool trans_MOVfcc(DisasContext *dc, arg_MOVfcc *a)
4384fb4ed7aaSRichard Henderson {
4385fb4ed7aaSRichard Henderson     TCGv src2 = gen_rs2_or_imm(dc, a->imm, a->rs2_or_imm);
4386fb4ed7aaSRichard Henderson     DisasCompare cmp;
4387fb4ed7aaSRichard Henderson 
4388fb4ed7aaSRichard Henderson     if (src2 == NULL) {
4389fb4ed7aaSRichard Henderson         return false;
4390fb4ed7aaSRichard Henderson     }
4391fb4ed7aaSRichard Henderson     gen_fcompare(&cmp, a->cc, a->cond);
4392fb4ed7aaSRichard Henderson     return do_mov_cond(dc, &cmp, a->rd, src2);
4393fb4ed7aaSRichard Henderson }
4394fb4ed7aaSRichard Henderson 
4395fb4ed7aaSRichard Henderson static bool trans_MOVR(DisasContext *dc, arg_MOVR *a)
4396fb4ed7aaSRichard Henderson {
4397fb4ed7aaSRichard Henderson     TCGv src2 = gen_rs2_or_imm(dc, a->imm, a->rs2_or_imm);
4398fb4ed7aaSRichard Henderson     DisasCompare cmp;
4399fb4ed7aaSRichard Henderson 
4400fb4ed7aaSRichard Henderson     if (src2 == NULL) {
4401fb4ed7aaSRichard Henderson         return false;
4402fb4ed7aaSRichard Henderson     }
4403fb4ed7aaSRichard Henderson     gen_compare_reg(&cmp, a->cond, gen_load_gpr(dc, a->rs1));
4404fb4ed7aaSRichard Henderson     return do_mov_cond(dc, &cmp, a->rd, src2);
4405fb4ed7aaSRichard Henderson }
4406fb4ed7aaSRichard Henderson 
440786b82fe0SRichard Henderson static bool do_add_special(DisasContext *dc, arg_r_r_ri *a,
440886b82fe0SRichard Henderson                            bool (*func)(DisasContext *dc, int rd, TCGv src))
440986b82fe0SRichard Henderson {
441086b82fe0SRichard Henderson     TCGv src1, sum;
441186b82fe0SRichard Henderson 
441286b82fe0SRichard Henderson     /* For simplicity, we under-decoded the rs2 form. */
441386b82fe0SRichard Henderson     if (!a->imm && a->rs2_or_imm & ~0x1f) {
441486b82fe0SRichard Henderson         return false;
441586b82fe0SRichard Henderson     }
441686b82fe0SRichard Henderson 
441786b82fe0SRichard Henderson     /*
441886b82fe0SRichard Henderson      * Always load the sum into a new temporary.
441986b82fe0SRichard Henderson      * This is required to capture the value across a window change,
442086b82fe0SRichard Henderson      * e.g. SAVE and RESTORE, and may be optimized away otherwise.
442186b82fe0SRichard Henderson      */
442286b82fe0SRichard Henderson     sum = tcg_temp_new();
442386b82fe0SRichard Henderson     src1 = gen_load_gpr(dc, a->rs1);
442486b82fe0SRichard Henderson     if (a->imm || a->rs2_or_imm == 0) {
442586b82fe0SRichard Henderson         tcg_gen_addi_tl(sum, src1, a->rs2_or_imm);
442686b82fe0SRichard Henderson     } else {
442786b82fe0SRichard Henderson         tcg_gen_add_tl(sum, src1, cpu_regs[a->rs2_or_imm]);
442886b82fe0SRichard Henderson     }
442986b82fe0SRichard Henderson     return func(dc, a->rd, sum);
443086b82fe0SRichard Henderson }
443186b82fe0SRichard Henderson 
443286b82fe0SRichard Henderson static bool do_jmpl(DisasContext *dc, int rd, TCGv src)
443386b82fe0SRichard Henderson {
443486b82fe0SRichard Henderson     /*
443586b82fe0SRichard Henderson      * Preserve pc across advance, so that we can delay
443686b82fe0SRichard Henderson      * the writeback to rd until after src is consumed.
443786b82fe0SRichard Henderson      */
443886b82fe0SRichard Henderson     target_ulong cur_pc = dc->pc;
443986b82fe0SRichard Henderson 
444086b82fe0SRichard Henderson     gen_check_align(dc, src, 3);
444186b82fe0SRichard Henderson 
444286b82fe0SRichard Henderson     gen_mov_pc_npc(dc);
444386b82fe0SRichard Henderson     tcg_gen_mov_tl(cpu_npc, src);
444486b82fe0SRichard Henderson     gen_address_mask(dc, cpu_npc);
444586b82fe0SRichard Henderson     gen_store_gpr(dc, rd, tcg_constant_tl(cur_pc));
444686b82fe0SRichard Henderson 
444786b82fe0SRichard Henderson     dc->npc = DYNAMIC_PC_LOOKUP;
444886b82fe0SRichard Henderson     return true;
444986b82fe0SRichard Henderson }
445086b82fe0SRichard Henderson 
445186b82fe0SRichard Henderson TRANS(JMPL, ALL, do_add_special, a, do_jmpl)
445286b82fe0SRichard Henderson 
445386b82fe0SRichard Henderson static bool do_rett(DisasContext *dc, int rd, TCGv src)
445486b82fe0SRichard Henderson {
445586b82fe0SRichard Henderson     if (!supervisor(dc)) {
445686b82fe0SRichard Henderson         return raise_priv(dc);
445786b82fe0SRichard Henderson     }
445886b82fe0SRichard Henderson 
445986b82fe0SRichard Henderson     gen_check_align(dc, src, 3);
446086b82fe0SRichard Henderson 
446186b82fe0SRichard Henderson     gen_mov_pc_npc(dc);
446286b82fe0SRichard Henderson     tcg_gen_mov_tl(cpu_npc, src);
446386b82fe0SRichard Henderson     gen_helper_rett(tcg_env);
446486b82fe0SRichard Henderson 
446586b82fe0SRichard Henderson     dc->npc = DYNAMIC_PC;
446686b82fe0SRichard Henderson     return true;
446786b82fe0SRichard Henderson }
446886b82fe0SRichard Henderson 
446986b82fe0SRichard Henderson TRANS(RETT, 32, do_add_special, a, do_rett)
447086b82fe0SRichard Henderson 
447186b82fe0SRichard Henderson static bool do_return(DisasContext *dc, int rd, TCGv src)
447286b82fe0SRichard Henderson {
447386b82fe0SRichard Henderson     gen_check_align(dc, src, 3);
447486b82fe0SRichard Henderson 
447586b82fe0SRichard Henderson     gen_mov_pc_npc(dc);
447686b82fe0SRichard Henderson     tcg_gen_mov_tl(cpu_npc, src);
447786b82fe0SRichard Henderson     gen_address_mask(dc, cpu_npc);
447886b82fe0SRichard Henderson 
447986b82fe0SRichard Henderson     gen_helper_restore(tcg_env);
448086b82fe0SRichard Henderson     dc->npc = DYNAMIC_PC_LOOKUP;
448186b82fe0SRichard Henderson     return true;
448286b82fe0SRichard Henderson }
448386b82fe0SRichard Henderson 
448486b82fe0SRichard Henderson TRANS(RETURN, 64, do_add_special, a, do_return)
448586b82fe0SRichard Henderson 
4486d3825800SRichard Henderson static bool do_save(DisasContext *dc, int rd, TCGv src)
4487d3825800SRichard Henderson {
4488d3825800SRichard Henderson     gen_helper_save(tcg_env);
4489d3825800SRichard Henderson     gen_store_gpr(dc, rd, src);
4490d3825800SRichard Henderson     return advance_pc(dc);
4491d3825800SRichard Henderson }
4492d3825800SRichard Henderson 
4493d3825800SRichard Henderson TRANS(SAVE, ALL, do_add_special, a, do_save)
4494d3825800SRichard Henderson 
4495d3825800SRichard Henderson static bool do_restore(DisasContext *dc, int rd, TCGv src)
4496d3825800SRichard Henderson {
4497d3825800SRichard Henderson     gen_helper_restore(tcg_env);
4498d3825800SRichard Henderson     gen_store_gpr(dc, rd, src);
4499d3825800SRichard Henderson     return advance_pc(dc);
4500d3825800SRichard Henderson }
4501d3825800SRichard Henderson 
4502d3825800SRichard Henderson TRANS(RESTORE, ALL, do_add_special, a, do_restore)
4503d3825800SRichard Henderson 
45048f75b8a4SRichard Henderson static bool do_done_retry(DisasContext *dc, bool done)
45058f75b8a4SRichard Henderson {
45068f75b8a4SRichard Henderson     if (!supervisor(dc)) {
45078f75b8a4SRichard Henderson         return raise_priv(dc);
45088f75b8a4SRichard Henderson     }
45098f75b8a4SRichard Henderson     dc->npc = DYNAMIC_PC;
45108f75b8a4SRichard Henderson     dc->pc = DYNAMIC_PC;
45118f75b8a4SRichard Henderson     translator_io_start(&dc->base);
45128f75b8a4SRichard Henderson     if (done) {
45138f75b8a4SRichard Henderson         gen_helper_done(tcg_env);
45148f75b8a4SRichard Henderson     } else {
45158f75b8a4SRichard Henderson         gen_helper_retry(tcg_env);
45168f75b8a4SRichard Henderson     }
45178f75b8a4SRichard Henderson     return true;
45188f75b8a4SRichard Henderson }
45198f75b8a4SRichard Henderson 
45208f75b8a4SRichard Henderson TRANS(DONE, 64, do_done_retry, true)
45218f75b8a4SRichard Henderson TRANS(RETRY, 64, do_done_retry, false)
45228f75b8a4SRichard Henderson 
45230880d20bSRichard Henderson /*
45240880d20bSRichard Henderson  * Major opcode 11 -- load and store instructions
45250880d20bSRichard Henderson  */
45260880d20bSRichard Henderson 
45270880d20bSRichard Henderson static TCGv gen_ldst_addr(DisasContext *dc, int rs1, bool imm, int rs2_or_imm)
45280880d20bSRichard Henderson {
45290880d20bSRichard Henderson     TCGv addr, tmp = NULL;
45300880d20bSRichard Henderson 
45310880d20bSRichard Henderson     /* For simplicity, we under-decoded the rs2 form. */
45320880d20bSRichard Henderson     if (!imm && rs2_or_imm & ~0x1f) {
45330880d20bSRichard Henderson         return NULL;
45340880d20bSRichard Henderson     }
45350880d20bSRichard Henderson 
45360880d20bSRichard Henderson     addr = gen_load_gpr(dc, rs1);
45370880d20bSRichard Henderson     if (rs2_or_imm) {
45380880d20bSRichard Henderson         tmp = tcg_temp_new();
45390880d20bSRichard Henderson         if (imm) {
45400880d20bSRichard Henderson             tcg_gen_addi_tl(tmp, addr, rs2_or_imm);
45410880d20bSRichard Henderson         } else {
45420880d20bSRichard Henderson             tcg_gen_add_tl(tmp, addr, cpu_regs[rs2_or_imm]);
45430880d20bSRichard Henderson         }
45440880d20bSRichard Henderson         addr = tmp;
45450880d20bSRichard Henderson     }
45460880d20bSRichard Henderson     if (AM_CHECK(dc)) {
45470880d20bSRichard Henderson         if (!tmp) {
45480880d20bSRichard Henderson             tmp = tcg_temp_new();
45490880d20bSRichard Henderson         }
45500880d20bSRichard Henderson         tcg_gen_ext32u_tl(tmp, addr);
45510880d20bSRichard Henderson         addr = tmp;
45520880d20bSRichard Henderson     }
45530880d20bSRichard Henderson     return addr;
45540880d20bSRichard Henderson }
45550880d20bSRichard Henderson 
45560880d20bSRichard Henderson static bool do_ld_gpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp mop)
45570880d20bSRichard Henderson {
45580880d20bSRichard Henderson     TCGv reg, addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
45590880d20bSRichard Henderson     DisasASI da;
45600880d20bSRichard Henderson 
45610880d20bSRichard Henderson     if (addr == NULL) {
45620880d20bSRichard Henderson         return false;
45630880d20bSRichard Henderson     }
45640880d20bSRichard Henderson     da = resolve_asi(dc, a->asi, mop);
45650880d20bSRichard Henderson 
45660880d20bSRichard Henderson     reg = gen_dest_gpr(dc, a->rd);
456742071fc1SRichard Henderson     gen_ld_asi(dc, &da, reg, addr);
45680880d20bSRichard Henderson     gen_store_gpr(dc, a->rd, reg);
45690880d20bSRichard Henderson     return advance_pc(dc);
45700880d20bSRichard Henderson }
45710880d20bSRichard Henderson 
45720880d20bSRichard Henderson TRANS(LDUW, ALL, do_ld_gpr, a, MO_TEUL)
45730880d20bSRichard Henderson TRANS(LDUB, ALL, do_ld_gpr, a, MO_UB)
45740880d20bSRichard Henderson TRANS(LDUH, ALL, do_ld_gpr, a, MO_TEUW)
45750880d20bSRichard Henderson TRANS(LDSB, ALL, do_ld_gpr, a, MO_SB)
45760880d20bSRichard Henderson TRANS(LDSH, ALL, do_ld_gpr, a, MO_TESW)
45770880d20bSRichard Henderson TRANS(LDSW, 64, do_ld_gpr, a, MO_TESL)
45780880d20bSRichard Henderson TRANS(LDX, 64, do_ld_gpr, a, MO_TEUQ)
45790880d20bSRichard Henderson 
45800880d20bSRichard Henderson static bool do_st_gpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp mop)
45810880d20bSRichard Henderson {
45820880d20bSRichard Henderson     TCGv reg, addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
45830880d20bSRichard Henderson     DisasASI da;
45840880d20bSRichard Henderson 
45850880d20bSRichard Henderson     if (addr == NULL) {
45860880d20bSRichard Henderson         return false;
45870880d20bSRichard Henderson     }
45880880d20bSRichard Henderson     da = resolve_asi(dc, a->asi, mop);
45890880d20bSRichard Henderson 
45900880d20bSRichard Henderson     reg = gen_load_gpr(dc, a->rd);
459142071fc1SRichard Henderson     gen_st_asi(dc, &da, reg, addr);
45920880d20bSRichard Henderson     return advance_pc(dc);
45930880d20bSRichard Henderson }
45940880d20bSRichard Henderson 
45950880d20bSRichard Henderson TRANS(STW, ALL, do_st_gpr, a, MO_TEUL)
45960880d20bSRichard Henderson TRANS(STB, ALL, do_st_gpr, a, MO_UB)
45970880d20bSRichard Henderson TRANS(STH, ALL, do_st_gpr, a, MO_TEUW)
45980880d20bSRichard Henderson TRANS(STX, 64, do_st_gpr, a, MO_TEUQ)
45990880d20bSRichard Henderson 
46000880d20bSRichard Henderson static bool trans_LDD(DisasContext *dc, arg_r_r_ri_asi *a)
46010880d20bSRichard Henderson {
46020880d20bSRichard Henderson     TCGv addr;
46030880d20bSRichard Henderson     DisasASI da;
46040880d20bSRichard Henderson 
46050880d20bSRichard Henderson     if (a->rd & 1) {
46060880d20bSRichard Henderson         return false;
46070880d20bSRichard Henderson     }
46080880d20bSRichard Henderson     addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
46090880d20bSRichard Henderson     if (addr == NULL) {
46100880d20bSRichard Henderson         return false;
46110880d20bSRichard Henderson     }
46120880d20bSRichard Henderson     da = resolve_asi(dc, a->asi, MO_TEUQ);
461342071fc1SRichard Henderson     gen_ldda_asi(dc, &da, addr, a->rd);
46140880d20bSRichard Henderson     return advance_pc(dc);
46150880d20bSRichard Henderson }
46160880d20bSRichard Henderson 
46170880d20bSRichard Henderson static bool trans_STD(DisasContext *dc, arg_r_r_ri_asi *a)
46180880d20bSRichard Henderson {
46190880d20bSRichard Henderson     TCGv addr;
46200880d20bSRichard Henderson     DisasASI da;
46210880d20bSRichard Henderson 
46220880d20bSRichard Henderson     if (a->rd & 1) {
46230880d20bSRichard Henderson         return false;
46240880d20bSRichard Henderson     }
46250880d20bSRichard Henderson     addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
46260880d20bSRichard Henderson     if (addr == NULL) {
46270880d20bSRichard Henderson         return false;
46280880d20bSRichard Henderson     }
46290880d20bSRichard Henderson     da = resolve_asi(dc, a->asi, MO_TEUQ);
463042071fc1SRichard Henderson     gen_stda_asi(dc, &da, addr, a->rd);
46310880d20bSRichard Henderson     return advance_pc(dc);
46320880d20bSRichard Henderson }
46330880d20bSRichard Henderson 
4634cf07cd1eSRichard Henderson static bool trans_LDSTUB(DisasContext *dc, arg_r_r_ri_asi *a)
4635cf07cd1eSRichard Henderson {
4636cf07cd1eSRichard Henderson     TCGv addr, reg;
4637cf07cd1eSRichard Henderson     DisasASI da;
4638cf07cd1eSRichard Henderson 
4639cf07cd1eSRichard Henderson     addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
4640cf07cd1eSRichard Henderson     if (addr == NULL) {
4641cf07cd1eSRichard Henderson         return false;
4642cf07cd1eSRichard Henderson     }
4643cf07cd1eSRichard Henderson     da = resolve_asi(dc, a->asi, MO_UB);
4644cf07cd1eSRichard Henderson 
4645cf07cd1eSRichard Henderson     reg = gen_dest_gpr(dc, a->rd);
4646cf07cd1eSRichard Henderson     gen_ldstub_asi(dc, &da, reg, addr);
4647cf07cd1eSRichard Henderson     gen_store_gpr(dc, a->rd, reg);
4648cf07cd1eSRichard Henderson     return advance_pc(dc);
4649cf07cd1eSRichard Henderson }
4650cf07cd1eSRichard Henderson 
4651dca544b9SRichard Henderson static bool trans_SWAP(DisasContext *dc, arg_r_r_ri_asi *a)
4652dca544b9SRichard Henderson {
4653dca544b9SRichard Henderson     TCGv addr, dst, src;
4654dca544b9SRichard Henderson     DisasASI da;
4655dca544b9SRichard Henderson 
4656dca544b9SRichard Henderson     addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
4657dca544b9SRichard Henderson     if (addr == NULL) {
4658dca544b9SRichard Henderson         return false;
4659dca544b9SRichard Henderson     }
4660dca544b9SRichard Henderson     da = resolve_asi(dc, a->asi, MO_TEUL);
4661dca544b9SRichard Henderson 
4662dca544b9SRichard Henderson     dst = gen_dest_gpr(dc, a->rd);
4663dca544b9SRichard Henderson     src = gen_load_gpr(dc, a->rd);
4664dca544b9SRichard Henderson     gen_swap_asi(dc, &da, dst, src, addr);
4665dca544b9SRichard Henderson     gen_store_gpr(dc, a->rd, dst);
4666dca544b9SRichard Henderson     return advance_pc(dc);
4667dca544b9SRichard Henderson }
4668dca544b9SRichard Henderson 
4669d0a11d25SRichard Henderson static bool do_casa(DisasContext *dc, arg_r_r_ri_asi *a, MemOp mop)
4670d0a11d25SRichard Henderson {
4671d0a11d25SRichard Henderson     TCGv addr, o, n, c;
4672d0a11d25SRichard Henderson     DisasASI da;
4673d0a11d25SRichard Henderson 
4674d0a11d25SRichard Henderson     addr = gen_ldst_addr(dc, a->rs1, true, 0);
4675d0a11d25SRichard Henderson     if (addr == NULL) {
4676d0a11d25SRichard Henderson         return false;
4677d0a11d25SRichard Henderson     }
4678d0a11d25SRichard Henderson     da = resolve_asi(dc, a->asi, mop);
4679d0a11d25SRichard Henderson 
4680d0a11d25SRichard Henderson     o = gen_dest_gpr(dc, a->rd);
4681d0a11d25SRichard Henderson     n = gen_load_gpr(dc, a->rd);
4682d0a11d25SRichard Henderson     c = gen_load_gpr(dc, a->rs2_or_imm);
4683d0a11d25SRichard Henderson     gen_cas_asi(dc, &da, o, n, c, addr);
4684d0a11d25SRichard Henderson     gen_store_gpr(dc, a->rd, o);
4685d0a11d25SRichard Henderson     return advance_pc(dc);
4686d0a11d25SRichard Henderson }
4687d0a11d25SRichard Henderson 
4688d0a11d25SRichard Henderson TRANS(CASA, CASA, do_casa, a, MO_TEUL)
4689d0a11d25SRichard Henderson TRANS(CASXA, 64, do_casa, a, MO_TEUQ)
4690d0a11d25SRichard Henderson 
469106c060d9SRichard Henderson static bool do_ld_fpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp sz)
469206c060d9SRichard Henderson {
469306c060d9SRichard Henderson     TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
469406c060d9SRichard Henderson     DisasASI da;
469506c060d9SRichard Henderson 
469606c060d9SRichard Henderson     if (addr == NULL) {
469706c060d9SRichard Henderson         return false;
469806c060d9SRichard Henderson     }
469906c060d9SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
470006c060d9SRichard Henderson         return true;
470106c060d9SRichard Henderson     }
470206c060d9SRichard Henderson     if (sz == MO_128 && gen_trap_float128(dc)) {
470306c060d9SRichard Henderson         return true;
470406c060d9SRichard Henderson     }
470506c060d9SRichard Henderson     da = resolve_asi(dc, a->asi, MO_TE | sz);
4706287b1152SRichard Henderson     gen_ldf_asi(dc, &da, sz, addr, a->rd);
470706c060d9SRichard Henderson     gen_update_fprs_dirty(dc, a->rd);
470806c060d9SRichard Henderson     return advance_pc(dc);
470906c060d9SRichard Henderson }
471006c060d9SRichard Henderson 
471106c060d9SRichard Henderson TRANS(LDF, ALL, do_ld_fpr, a, MO_32)
471206c060d9SRichard Henderson TRANS(LDDF, ALL, do_ld_fpr, a, MO_64)
471306c060d9SRichard Henderson TRANS(LDQF, ALL, do_ld_fpr, a, MO_128)
471406c060d9SRichard Henderson 
4715287b1152SRichard Henderson TRANS(LDFA, 64, do_ld_fpr, a, MO_32)
4716287b1152SRichard Henderson TRANS(LDDFA, 64, do_ld_fpr, a, MO_64)
4717287b1152SRichard Henderson TRANS(LDQFA, 64, do_ld_fpr, a, MO_128)
4718287b1152SRichard Henderson 
471906c060d9SRichard Henderson static bool do_st_fpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp sz)
472006c060d9SRichard Henderson {
472106c060d9SRichard Henderson     TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
472206c060d9SRichard Henderson     DisasASI da;
472306c060d9SRichard Henderson 
472406c060d9SRichard Henderson     if (addr == NULL) {
472506c060d9SRichard Henderson         return false;
472606c060d9SRichard Henderson     }
472706c060d9SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
472806c060d9SRichard Henderson         return true;
472906c060d9SRichard Henderson     }
473006c060d9SRichard Henderson     if (sz == MO_128 && gen_trap_float128(dc)) {
473106c060d9SRichard Henderson         return true;
473206c060d9SRichard Henderson     }
473306c060d9SRichard Henderson     da = resolve_asi(dc, a->asi, MO_TE | sz);
4734287b1152SRichard Henderson     gen_stf_asi(dc, &da, sz, addr, a->rd);
473506c060d9SRichard Henderson     return advance_pc(dc);
473606c060d9SRichard Henderson }
473706c060d9SRichard Henderson 
473806c060d9SRichard Henderson TRANS(STF, ALL, do_st_fpr, a, MO_32)
473906c060d9SRichard Henderson TRANS(STDF, ALL, do_st_fpr, a, MO_64)
474006c060d9SRichard Henderson TRANS(STQF, ALL, do_st_fpr, a, MO_128)
474106c060d9SRichard Henderson 
4742287b1152SRichard Henderson TRANS(STFA, 64, do_st_fpr, a, MO_32)
4743287b1152SRichard Henderson TRANS(STDFA, 64, do_st_fpr, a, MO_64)
4744287b1152SRichard Henderson TRANS(STQFA, 64, do_st_fpr, a, MO_128)
4745287b1152SRichard Henderson 
474606c060d9SRichard Henderson static bool trans_STDFQ(DisasContext *dc, arg_STDFQ *a)
474706c060d9SRichard Henderson {
474806c060d9SRichard Henderson     if (!avail_32(dc)) {
474906c060d9SRichard Henderson         return false;
475006c060d9SRichard Henderson     }
475106c060d9SRichard Henderson     if (!supervisor(dc)) {
475206c060d9SRichard Henderson         return raise_priv(dc);
475306c060d9SRichard Henderson     }
475406c060d9SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
475506c060d9SRichard Henderson         return true;
475606c060d9SRichard Henderson     }
475706c060d9SRichard Henderson     gen_op_fpexception_im(dc, FSR_FTT_SEQ_ERROR);
475806c060d9SRichard Henderson     return true;
475906c060d9SRichard Henderson }
476006c060d9SRichard Henderson 
4761da681406SRichard Henderson static bool do_ldfsr(DisasContext *dc, arg_r_r_ri *a, MemOp mop,
4762da681406SRichard Henderson                      target_ulong new_mask, target_ulong old_mask)
47633d3c0673SRichard Henderson {
4764da681406SRichard Henderson     TCGv tmp, addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
47653d3c0673SRichard Henderson     if (addr == NULL) {
47663d3c0673SRichard Henderson         return false;
47673d3c0673SRichard Henderson     }
47683d3c0673SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
47693d3c0673SRichard Henderson         return true;
47703d3c0673SRichard Henderson     }
4771da681406SRichard Henderson     tmp = tcg_temp_new();
4772da681406SRichard Henderson     tcg_gen_qemu_ld_tl(tmp, addr, dc->mem_idx, mop | MO_ALIGN);
4773da681406SRichard Henderson     tcg_gen_andi_tl(tmp, tmp, new_mask);
4774da681406SRichard Henderson     tcg_gen_andi_tl(cpu_fsr, cpu_fsr, old_mask);
4775da681406SRichard Henderson     tcg_gen_or_tl(cpu_fsr, cpu_fsr, tmp);
4776da681406SRichard Henderson     gen_helper_set_fsr(tcg_env, cpu_fsr);
47773d3c0673SRichard Henderson     return advance_pc(dc);
47783d3c0673SRichard Henderson }
47793d3c0673SRichard Henderson 
4780da681406SRichard Henderson TRANS(LDFSR, ALL, do_ldfsr, a, MO_TEUL, FSR_LDFSR_MASK, FSR_LDFSR_OLDMASK)
4781da681406SRichard Henderson TRANS(LDXFSR, 64, do_ldfsr, a, MO_TEUQ, FSR_LDXFSR_MASK, FSR_LDXFSR_OLDMASK)
47823d3c0673SRichard Henderson 
47833d3c0673SRichard Henderson static bool do_stfsr(DisasContext *dc, arg_r_r_ri *a, MemOp mop)
47843d3c0673SRichard Henderson {
47853d3c0673SRichard Henderson     TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
47863d3c0673SRichard Henderson     if (addr == NULL) {
47873d3c0673SRichard Henderson         return false;
47883d3c0673SRichard Henderson     }
47893d3c0673SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
47903d3c0673SRichard Henderson         return true;
47913d3c0673SRichard Henderson     }
47923d3c0673SRichard Henderson     tcg_gen_qemu_st_tl(cpu_fsr, addr, dc->mem_idx, mop | MO_ALIGN);
47933d3c0673SRichard Henderson     return advance_pc(dc);
47943d3c0673SRichard Henderson }
47953d3c0673SRichard Henderson 
47963d3c0673SRichard Henderson TRANS(STFSR, ALL, do_stfsr, a, MO_TEUL)
47973d3c0673SRichard Henderson TRANS(STXFSR, 64, do_stfsr, a, MO_TEUQ)
47983d3c0673SRichard Henderson 
4799baf3dbf2SRichard Henderson static bool do_ff(DisasContext *dc, arg_r_r *a,
4800baf3dbf2SRichard Henderson                   void (*func)(TCGv_i32, TCGv_i32))
4801baf3dbf2SRichard Henderson {
4802baf3dbf2SRichard Henderson     TCGv_i32 tmp;
4803baf3dbf2SRichard Henderson 
4804baf3dbf2SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4805baf3dbf2SRichard Henderson         return true;
4806baf3dbf2SRichard Henderson     }
4807baf3dbf2SRichard Henderson 
4808baf3dbf2SRichard Henderson     tmp = gen_load_fpr_F(dc, a->rs);
4809baf3dbf2SRichard Henderson     func(tmp, tmp);
4810baf3dbf2SRichard Henderson     gen_store_fpr_F(dc, a->rd, tmp);
4811baf3dbf2SRichard Henderson     return advance_pc(dc);
4812baf3dbf2SRichard Henderson }
4813baf3dbf2SRichard Henderson 
4814baf3dbf2SRichard Henderson TRANS(FMOVs, ALL, do_ff, a, gen_op_fmovs)
4815baf3dbf2SRichard Henderson TRANS(FNEGs, ALL, do_ff, a, gen_op_fnegs)
4816baf3dbf2SRichard Henderson TRANS(FABSs, ALL, do_ff, a, gen_op_fabss)
4817baf3dbf2SRichard Henderson TRANS(FSRCs, VIS1, do_ff, a, tcg_gen_mov_i32)
4818baf3dbf2SRichard Henderson TRANS(FNOTs, VIS1, do_ff, a, tcg_gen_not_i32)
4819baf3dbf2SRichard Henderson 
4820c6d83e4fSRichard Henderson static bool do_dd(DisasContext *dc, arg_r_r *a,
4821c6d83e4fSRichard Henderson                   void (*func)(TCGv_i64, TCGv_i64))
4822c6d83e4fSRichard Henderson {
4823c6d83e4fSRichard Henderson     TCGv_i64 dst, src;
4824c6d83e4fSRichard Henderson 
4825c6d83e4fSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4826c6d83e4fSRichard Henderson         return true;
4827c6d83e4fSRichard Henderson     }
4828c6d83e4fSRichard Henderson 
4829c6d83e4fSRichard Henderson     dst = gen_dest_fpr_D(dc, a->rd);
4830c6d83e4fSRichard Henderson     src = gen_load_fpr_D(dc, a->rs);
4831c6d83e4fSRichard Henderson     func(dst, src);
4832c6d83e4fSRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
4833c6d83e4fSRichard Henderson     return advance_pc(dc);
4834c6d83e4fSRichard Henderson }
4835c6d83e4fSRichard Henderson 
4836c6d83e4fSRichard Henderson TRANS(FMOVd, 64, do_dd, a, gen_op_fmovd)
4837c6d83e4fSRichard Henderson TRANS(FNEGd, 64, do_dd, a, gen_op_fnegd)
4838c6d83e4fSRichard Henderson TRANS(FABSd, 64, do_dd, a, gen_op_fabsd)
4839c6d83e4fSRichard Henderson TRANS(FSRCd, VIS1, do_dd, a, tcg_gen_mov_i64)
4840c6d83e4fSRichard Henderson TRANS(FNOTd, VIS1, do_dd, a, tcg_gen_not_i64)
4841c6d83e4fSRichard Henderson 
4842*7f10b52fSRichard Henderson static bool do_fff(DisasContext *dc, arg_r_r_r *a,
4843*7f10b52fSRichard Henderson                    void (*func)(TCGv_i32, TCGv_i32, TCGv_i32))
4844*7f10b52fSRichard Henderson {
4845*7f10b52fSRichard Henderson     TCGv_i32 src1, src2;
4846*7f10b52fSRichard Henderson 
4847*7f10b52fSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4848*7f10b52fSRichard Henderson         return true;
4849*7f10b52fSRichard Henderson     }
4850*7f10b52fSRichard Henderson 
4851*7f10b52fSRichard Henderson     src1 = gen_load_fpr_F(dc, a->rs1);
4852*7f10b52fSRichard Henderson     src2 = gen_load_fpr_F(dc, a->rs2);
4853*7f10b52fSRichard Henderson     func(src1, src1, src2);
4854*7f10b52fSRichard Henderson     gen_store_fpr_F(dc, a->rd, src1);
4855*7f10b52fSRichard Henderson     return advance_pc(dc);
4856*7f10b52fSRichard Henderson }
4857*7f10b52fSRichard Henderson 
4858*7f10b52fSRichard Henderson TRANS(FPADD16s, VIS1, do_fff, a, tcg_gen_vec_add16_i32)
4859*7f10b52fSRichard Henderson TRANS(FPADD32s, VIS1, do_fff, a, tcg_gen_add_i32)
4860*7f10b52fSRichard Henderson TRANS(FPSUB16s, VIS1, do_fff, a, tcg_gen_vec_sub16_i32)
4861*7f10b52fSRichard Henderson TRANS(FPSUB32s, VIS1, do_fff, a, tcg_gen_sub_i32)
4862*7f10b52fSRichard Henderson TRANS(FNORs, VIS1, do_fff, a, tcg_gen_nor_i32)
4863*7f10b52fSRichard Henderson TRANS(FANDNOTs, VIS1, do_fff, a, tcg_gen_andc_i32)
4864*7f10b52fSRichard Henderson TRANS(FXORs, VIS1, do_fff, a, tcg_gen_xor_i32)
4865*7f10b52fSRichard Henderson TRANS(FNANDs, VIS1, do_fff, a, tcg_gen_nand_i32)
4866*7f10b52fSRichard Henderson TRANS(FANDs, VIS1, do_fff, a, tcg_gen_and_i32)
4867*7f10b52fSRichard Henderson TRANS(FXNORs, VIS1, do_fff, a, tcg_gen_eqv_i32)
4868*7f10b52fSRichard Henderson TRANS(FORNOTs, VIS1, do_fff, a, tcg_gen_orc_i32)
4869*7f10b52fSRichard Henderson TRANS(FORs, VIS1, do_fff, a, tcg_gen_or_i32)
4870*7f10b52fSRichard Henderson 
4871fcf5ef2aSThomas Huth #define CHECK_IU_FEATURE(dc, FEATURE)                      \
4872fcf5ef2aSThomas Huth     if (!((dc)->def->features & CPU_FEATURE_ ## FEATURE))  \
4873fcf5ef2aSThomas Huth         goto illegal_insn;
4874fcf5ef2aSThomas Huth #define CHECK_FPU_FEATURE(dc, FEATURE)                     \
4875fcf5ef2aSThomas Huth     if (!((dc)->def->features & CPU_FEATURE_ ## FEATURE))  \
4876fcf5ef2aSThomas Huth         goto nfpu_insn;
4877fcf5ef2aSThomas Huth 
4878fcf5ef2aSThomas Huth /* before an instruction, dc->pc must be static */
4879878cc677SRichard Henderson static void disas_sparc_legacy(DisasContext *dc, unsigned int insn)
4880fcf5ef2aSThomas Huth {
4881fcf5ef2aSThomas Huth     unsigned int opc, rs1, rs2, rd;
4882dca544b9SRichard Henderson     TCGv cpu_src1 __attribute__((unused));
48833d3c0673SRichard Henderson     TCGv_i32 cpu_src1_32, cpu_src2_32;
488406c060d9SRichard Henderson     TCGv_i64 cpu_src1_64, cpu_src2_64;
48853d3c0673SRichard Henderson     TCGv_i32 cpu_dst_32 __attribute__((unused));
488606c060d9SRichard Henderson     TCGv_i64 cpu_dst_64 __attribute__((unused));
4887fcf5ef2aSThomas Huth 
4888fcf5ef2aSThomas Huth     opc = GET_FIELD(insn, 0, 1);
4889fcf5ef2aSThomas Huth     rd = GET_FIELD(insn, 2, 6);
4890fcf5ef2aSThomas Huth 
4891fcf5ef2aSThomas Huth     switch (opc) {
48926d2a0768SRichard Henderson     case 0:
48936d2a0768SRichard Henderson         goto illegal_insn; /* in decodetree */
489423ada1b1SRichard Henderson     case 1:
489523ada1b1SRichard Henderson         g_assert_not_reached(); /* in decodetree */
4896fcf5ef2aSThomas Huth     case 2:                     /* FPU & Logical Operations */
4897fcf5ef2aSThomas Huth         {
48988f75b8a4SRichard Henderson             unsigned int xop = GET_FIELD(insn, 7, 12);
4899af25071cSRichard Henderson             TCGv cpu_dst __attribute__((unused)) = tcg_temp_new();
4900fcf5ef2aSThomas Huth 
4901af25071cSRichard Henderson             if (xop == 0x34) {   /* FPU Operations */
4902fcf5ef2aSThomas Huth                 if (gen_trap_ifnofpu(dc)) {
4903fcf5ef2aSThomas Huth                     goto jmp_insn;
4904fcf5ef2aSThomas Huth                 }
4905fcf5ef2aSThomas Huth                 gen_op_clear_ieee_excp_and_FTT();
4906fcf5ef2aSThomas Huth                 rs1 = GET_FIELD(insn, 13, 17);
4907fcf5ef2aSThomas Huth                 rs2 = GET_FIELD(insn, 27, 31);
4908fcf5ef2aSThomas Huth                 xop = GET_FIELD(insn, 18, 26);
4909fcf5ef2aSThomas Huth 
4910fcf5ef2aSThomas Huth                 switch (xop) {
4911fcf5ef2aSThomas Huth                 case 0x1: /* fmovs */
4912fcf5ef2aSThomas Huth                 case 0x5: /* fnegs */
4913fcf5ef2aSThomas Huth                 case 0x9: /* fabss */
4914c6d83e4fSRichard Henderson                 case 0x2: /* V9 fmovd */
4915c6d83e4fSRichard Henderson                 case 0x6: /* V9 fnegd */
4916c6d83e4fSRichard Henderson                 case 0xa: /* V9 fabsd */
4917baf3dbf2SRichard Henderson                     g_assert_not_reached(); /* in decodetree */
4918fcf5ef2aSThomas Huth                 case 0x29: /* fsqrts */
4919fcf5ef2aSThomas Huth                     gen_fop_FF(dc, rd, rs2, gen_helper_fsqrts);
4920fcf5ef2aSThomas Huth                     break;
4921fcf5ef2aSThomas Huth                 case 0x2a: /* fsqrtd */
4922fcf5ef2aSThomas Huth                     gen_fop_DD(dc, rd, rs2, gen_helper_fsqrtd);
4923fcf5ef2aSThomas Huth                     break;
4924fcf5ef2aSThomas Huth                 case 0x2b: /* fsqrtq */
4925fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, FLOAT128);
4926fcf5ef2aSThomas Huth                     gen_fop_QQ(dc, rd, rs2, gen_helper_fsqrtq);
4927fcf5ef2aSThomas Huth                     break;
4928fcf5ef2aSThomas Huth                 case 0x41: /* fadds */
4929fcf5ef2aSThomas Huth                     gen_fop_FFF(dc, rd, rs1, rs2, gen_helper_fadds);
4930fcf5ef2aSThomas Huth                     break;
4931fcf5ef2aSThomas Huth                 case 0x42: /* faddd */
4932fcf5ef2aSThomas Huth                     gen_fop_DDD(dc, rd, rs1, rs2, gen_helper_faddd);
4933fcf5ef2aSThomas Huth                     break;
4934fcf5ef2aSThomas Huth                 case 0x43: /* faddq */
4935fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, FLOAT128);
4936fcf5ef2aSThomas Huth                     gen_fop_QQQ(dc, rd, rs1, rs2, gen_helper_faddq);
4937fcf5ef2aSThomas Huth                     break;
4938fcf5ef2aSThomas Huth                 case 0x45: /* fsubs */
4939fcf5ef2aSThomas Huth                     gen_fop_FFF(dc, rd, rs1, rs2, gen_helper_fsubs);
4940fcf5ef2aSThomas Huth                     break;
4941fcf5ef2aSThomas Huth                 case 0x46: /* fsubd */
4942fcf5ef2aSThomas Huth                     gen_fop_DDD(dc, rd, rs1, rs2, gen_helper_fsubd);
4943fcf5ef2aSThomas Huth                     break;
4944fcf5ef2aSThomas Huth                 case 0x47: /* fsubq */
4945fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, FLOAT128);
4946fcf5ef2aSThomas Huth                     gen_fop_QQQ(dc, rd, rs1, rs2, gen_helper_fsubq);
4947fcf5ef2aSThomas Huth                     break;
4948fcf5ef2aSThomas Huth                 case 0x49: /* fmuls */
4949fcf5ef2aSThomas Huth                     gen_fop_FFF(dc, rd, rs1, rs2, gen_helper_fmuls);
4950fcf5ef2aSThomas Huth                     break;
4951fcf5ef2aSThomas Huth                 case 0x4a: /* fmuld */
4952fcf5ef2aSThomas Huth                     gen_fop_DDD(dc, rd, rs1, rs2, gen_helper_fmuld);
4953fcf5ef2aSThomas Huth                     break;
4954fcf5ef2aSThomas Huth                 case 0x4b: /* fmulq */
4955fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, FLOAT128);
4956fcf5ef2aSThomas Huth                     gen_fop_QQQ(dc, rd, rs1, rs2, gen_helper_fmulq);
4957fcf5ef2aSThomas Huth                     break;
4958fcf5ef2aSThomas Huth                 case 0x4d: /* fdivs */
4959fcf5ef2aSThomas Huth                     gen_fop_FFF(dc, rd, rs1, rs2, gen_helper_fdivs);
4960fcf5ef2aSThomas Huth                     break;
4961fcf5ef2aSThomas Huth                 case 0x4e: /* fdivd */
4962fcf5ef2aSThomas Huth                     gen_fop_DDD(dc, rd, rs1, rs2, gen_helper_fdivd);
4963fcf5ef2aSThomas Huth                     break;
4964fcf5ef2aSThomas Huth                 case 0x4f: /* fdivq */
4965fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, FLOAT128);
4966fcf5ef2aSThomas Huth                     gen_fop_QQQ(dc, rd, rs1, rs2, gen_helper_fdivq);
4967fcf5ef2aSThomas Huth                     break;
4968fcf5ef2aSThomas Huth                 case 0x69: /* fsmuld */
4969fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, FSMULD);
4970fcf5ef2aSThomas Huth                     gen_fop_DFF(dc, rd, rs1, rs2, gen_helper_fsmuld);
4971fcf5ef2aSThomas Huth                     break;
4972fcf5ef2aSThomas Huth                 case 0x6e: /* fdmulq */
4973fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, FLOAT128);
4974fcf5ef2aSThomas Huth                     gen_fop_QDD(dc, rd, rs1, rs2, gen_helper_fdmulq);
4975fcf5ef2aSThomas Huth                     break;
4976fcf5ef2aSThomas Huth                 case 0xc4: /* fitos */
4977fcf5ef2aSThomas Huth                     gen_fop_FF(dc, rd, rs2, gen_helper_fitos);
4978fcf5ef2aSThomas Huth                     break;
4979fcf5ef2aSThomas Huth                 case 0xc6: /* fdtos */
4980fcf5ef2aSThomas Huth                     gen_fop_FD(dc, rd, rs2, gen_helper_fdtos);
4981fcf5ef2aSThomas Huth                     break;
4982fcf5ef2aSThomas Huth                 case 0xc7: /* fqtos */
4983fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, FLOAT128);
4984fcf5ef2aSThomas Huth                     gen_fop_FQ(dc, rd, rs2, gen_helper_fqtos);
4985fcf5ef2aSThomas Huth                     break;
4986fcf5ef2aSThomas Huth                 case 0xc8: /* fitod */
4987fcf5ef2aSThomas Huth                     gen_ne_fop_DF(dc, rd, rs2, gen_helper_fitod);
4988fcf5ef2aSThomas Huth                     break;
4989fcf5ef2aSThomas Huth                 case 0xc9: /* fstod */
4990fcf5ef2aSThomas Huth                     gen_ne_fop_DF(dc, rd, rs2, gen_helper_fstod);
4991fcf5ef2aSThomas Huth                     break;
4992fcf5ef2aSThomas Huth                 case 0xcb: /* fqtod */
4993fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, FLOAT128);
4994fcf5ef2aSThomas Huth                     gen_fop_DQ(dc, rd, rs2, gen_helper_fqtod);
4995fcf5ef2aSThomas Huth                     break;
4996fcf5ef2aSThomas Huth                 case 0xcc: /* fitoq */
4997fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, FLOAT128);
4998fcf5ef2aSThomas Huth                     gen_ne_fop_QF(dc, rd, rs2, gen_helper_fitoq);
4999fcf5ef2aSThomas Huth                     break;
5000fcf5ef2aSThomas Huth                 case 0xcd: /* fstoq */
5001fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, FLOAT128);
5002fcf5ef2aSThomas Huth                     gen_ne_fop_QF(dc, rd, rs2, gen_helper_fstoq);
5003fcf5ef2aSThomas Huth                     break;
5004fcf5ef2aSThomas Huth                 case 0xce: /* fdtoq */
5005fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, FLOAT128);
5006fcf5ef2aSThomas Huth                     gen_ne_fop_QD(dc, rd, rs2, gen_helper_fdtoq);
5007fcf5ef2aSThomas Huth                     break;
5008fcf5ef2aSThomas Huth                 case 0xd1: /* fstoi */
5009fcf5ef2aSThomas Huth                     gen_fop_FF(dc, rd, rs2, gen_helper_fstoi);
5010fcf5ef2aSThomas Huth                     break;
5011fcf5ef2aSThomas Huth                 case 0xd2: /* fdtoi */
5012fcf5ef2aSThomas Huth                     gen_fop_FD(dc, rd, rs2, gen_helper_fdtoi);
5013fcf5ef2aSThomas Huth                     break;
5014fcf5ef2aSThomas Huth                 case 0xd3: /* fqtoi */
5015fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, FLOAT128);
5016fcf5ef2aSThomas Huth                     gen_fop_FQ(dc, rd, rs2, gen_helper_fqtoi);
5017fcf5ef2aSThomas Huth                     break;
5018fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
5019fcf5ef2aSThomas Huth                 case 0x3: /* V9 fmovq */
5020fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, FLOAT128);
5021fcf5ef2aSThomas Huth                     gen_move_Q(dc, rd, rs2);
5022fcf5ef2aSThomas Huth                     break;
5023fcf5ef2aSThomas Huth                 case 0x7: /* V9 fnegq */
5024fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, FLOAT128);
5025fcf5ef2aSThomas Huth                     gen_ne_fop_QQ(dc, rd, rs2, gen_helper_fnegq);
5026fcf5ef2aSThomas Huth                     break;
5027fcf5ef2aSThomas Huth                 case 0xb: /* V9 fabsq */
5028fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, FLOAT128);
5029fcf5ef2aSThomas Huth                     gen_ne_fop_QQ(dc, rd, rs2, gen_helper_fabsq);
5030fcf5ef2aSThomas Huth                     break;
5031fcf5ef2aSThomas Huth                 case 0x81: /* V9 fstox */
5032fcf5ef2aSThomas Huth                     gen_fop_DF(dc, rd, rs2, gen_helper_fstox);
5033fcf5ef2aSThomas Huth                     break;
5034fcf5ef2aSThomas Huth                 case 0x82: /* V9 fdtox */
5035fcf5ef2aSThomas Huth                     gen_fop_DD(dc, rd, rs2, gen_helper_fdtox);
5036fcf5ef2aSThomas Huth                     break;
5037fcf5ef2aSThomas Huth                 case 0x83: /* V9 fqtox */
5038fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, FLOAT128);
5039fcf5ef2aSThomas Huth                     gen_fop_DQ(dc, rd, rs2, gen_helper_fqtox);
5040fcf5ef2aSThomas Huth                     break;
5041fcf5ef2aSThomas Huth                 case 0x84: /* V9 fxtos */
5042fcf5ef2aSThomas Huth                     gen_fop_FD(dc, rd, rs2, gen_helper_fxtos);
5043fcf5ef2aSThomas Huth                     break;
5044fcf5ef2aSThomas Huth                 case 0x88: /* V9 fxtod */
5045fcf5ef2aSThomas Huth                     gen_fop_DD(dc, rd, rs2, gen_helper_fxtod);
5046fcf5ef2aSThomas Huth                     break;
5047fcf5ef2aSThomas Huth                 case 0x8c: /* V9 fxtoq */
5048fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, FLOAT128);
5049fcf5ef2aSThomas Huth                     gen_ne_fop_QD(dc, rd, rs2, gen_helper_fxtoq);
5050fcf5ef2aSThomas Huth                     break;
5051fcf5ef2aSThomas Huth #endif
5052fcf5ef2aSThomas Huth                 default:
5053fcf5ef2aSThomas Huth                     goto illegal_insn;
5054fcf5ef2aSThomas Huth                 }
5055fcf5ef2aSThomas Huth             } else if (xop == 0x35) {   /* FPU Operations */
5056fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
5057fcf5ef2aSThomas Huth                 int cond;
5058fcf5ef2aSThomas Huth #endif
5059fcf5ef2aSThomas Huth                 if (gen_trap_ifnofpu(dc)) {
5060fcf5ef2aSThomas Huth                     goto jmp_insn;
5061fcf5ef2aSThomas Huth                 }
5062fcf5ef2aSThomas Huth                 gen_op_clear_ieee_excp_and_FTT();
5063fcf5ef2aSThomas Huth                 rs1 = GET_FIELD(insn, 13, 17);
5064fcf5ef2aSThomas Huth                 rs2 = GET_FIELD(insn, 27, 31);
5065fcf5ef2aSThomas Huth                 xop = GET_FIELD(insn, 18, 26);
5066fcf5ef2aSThomas Huth 
5067fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
5068fcf5ef2aSThomas Huth #define FMOVR(sz)                                                  \
5069fcf5ef2aSThomas Huth                 do {                                               \
5070fcf5ef2aSThomas Huth                     DisasCompare cmp;                              \
5071fcf5ef2aSThomas Huth                     cond = GET_FIELD_SP(insn, 10, 12);             \
5072fcf5ef2aSThomas Huth                     cpu_src1 = get_src1(dc, insn);                 \
5073fcf5ef2aSThomas Huth                     gen_compare_reg(&cmp, cond, cpu_src1);         \
5074fcf5ef2aSThomas Huth                     gen_fmov##sz(dc, &cmp, rd, rs2);               \
5075fcf5ef2aSThomas Huth                 } while (0)
5076fcf5ef2aSThomas Huth 
5077fcf5ef2aSThomas Huth                 if ((xop & 0x11f) == 0x005) { /* V9 fmovsr */
5078fcf5ef2aSThomas Huth                     FMOVR(s);
5079fcf5ef2aSThomas Huth                     break;
5080fcf5ef2aSThomas Huth                 } else if ((xop & 0x11f) == 0x006) { // V9 fmovdr
5081fcf5ef2aSThomas Huth                     FMOVR(d);
5082fcf5ef2aSThomas Huth                     break;
5083fcf5ef2aSThomas Huth                 } else if ((xop & 0x11f) == 0x007) { // V9 fmovqr
5084fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, FLOAT128);
5085fcf5ef2aSThomas Huth                     FMOVR(q);
5086fcf5ef2aSThomas Huth                     break;
5087fcf5ef2aSThomas Huth                 }
5088fcf5ef2aSThomas Huth #undef FMOVR
5089fcf5ef2aSThomas Huth #endif
5090fcf5ef2aSThomas Huth                 switch (xop) {
5091fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
5092fcf5ef2aSThomas Huth #define FMOVCC(fcc, sz)                                                 \
5093fcf5ef2aSThomas Huth                     do {                                                \
5094fcf5ef2aSThomas Huth                         DisasCompare cmp;                               \
5095fcf5ef2aSThomas Huth                         cond = GET_FIELD_SP(insn, 14, 17);              \
5096fcf5ef2aSThomas Huth                         gen_fcompare(&cmp, fcc, cond);                  \
5097fcf5ef2aSThomas Huth                         gen_fmov##sz(dc, &cmp, rd, rs2);                \
5098fcf5ef2aSThomas Huth                     } while (0)
5099fcf5ef2aSThomas Huth 
5100fcf5ef2aSThomas Huth                     case 0x001: /* V9 fmovscc %fcc0 */
5101fcf5ef2aSThomas Huth                         FMOVCC(0, s);
5102fcf5ef2aSThomas Huth                         break;
5103fcf5ef2aSThomas Huth                     case 0x002: /* V9 fmovdcc %fcc0 */
5104fcf5ef2aSThomas Huth                         FMOVCC(0, d);
5105fcf5ef2aSThomas Huth                         break;
5106fcf5ef2aSThomas Huth                     case 0x003: /* V9 fmovqcc %fcc0 */
5107fcf5ef2aSThomas Huth                         CHECK_FPU_FEATURE(dc, FLOAT128);
5108fcf5ef2aSThomas Huth                         FMOVCC(0, q);
5109fcf5ef2aSThomas Huth                         break;
5110fcf5ef2aSThomas Huth                     case 0x041: /* V9 fmovscc %fcc1 */
5111fcf5ef2aSThomas Huth                         FMOVCC(1, s);
5112fcf5ef2aSThomas Huth                         break;
5113fcf5ef2aSThomas Huth                     case 0x042: /* V9 fmovdcc %fcc1 */
5114fcf5ef2aSThomas Huth                         FMOVCC(1, d);
5115fcf5ef2aSThomas Huth                         break;
5116fcf5ef2aSThomas Huth                     case 0x043: /* V9 fmovqcc %fcc1 */
5117fcf5ef2aSThomas Huth                         CHECK_FPU_FEATURE(dc, FLOAT128);
5118fcf5ef2aSThomas Huth                         FMOVCC(1, q);
5119fcf5ef2aSThomas Huth                         break;
5120fcf5ef2aSThomas Huth                     case 0x081: /* V9 fmovscc %fcc2 */
5121fcf5ef2aSThomas Huth                         FMOVCC(2, s);
5122fcf5ef2aSThomas Huth                         break;
5123fcf5ef2aSThomas Huth                     case 0x082: /* V9 fmovdcc %fcc2 */
5124fcf5ef2aSThomas Huth                         FMOVCC(2, d);
5125fcf5ef2aSThomas Huth                         break;
5126fcf5ef2aSThomas Huth                     case 0x083: /* V9 fmovqcc %fcc2 */
5127fcf5ef2aSThomas Huth                         CHECK_FPU_FEATURE(dc, FLOAT128);
5128fcf5ef2aSThomas Huth                         FMOVCC(2, q);
5129fcf5ef2aSThomas Huth                         break;
5130fcf5ef2aSThomas Huth                     case 0x0c1: /* V9 fmovscc %fcc3 */
5131fcf5ef2aSThomas Huth                         FMOVCC(3, s);
5132fcf5ef2aSThomas Huth                         break;
5133fcf5ef2aSThomas Huth                     case 0x0c2: /* V9 fmovdcc %fcc3 */
5134fcf5ef2aSThomas Huth                         FMOVCC(3, d);
5135fcf5ef2aSThomas Huth                         break;
5136fcf5ef2aSThomas Huth                     case 0x0c3: /* V9 fmovqcc %fcc3 */
5137fcf5ef2aSThomas Huth                         CHECK_FPU_FEATURE(dc, FLOAT128);
5138fcf5ef2aSThomas Huth                         FMOVCC(3, q);
5139fcf5ef2aSThomas Huth                         break;
5140fcf5ef2aSThomas Huth #undef FMOVCC
5141fcf5ef2aSThomas Huth #define FMOVCC(xcc, sz)                                                 \
5142fcf5ef2aSThomas Huth                     do {                                                \
5143fcf5ef2aSThomas Huth                         DisasCompare cmp;                               \
5144fcf5ef2aSThomas Huth                         cond = GET_FIELD_SP(insn, 14, 17);              \
5145fcf5ef2aSThomas Huth                         gen_compare(&cmp, xcc, cond, dc);               \
5146fcf5ef2aSThomas Huth                         gen_fmov##sz(dc, &cmp, rd, rs2);                \
5147fcf5ef2aSThomas Huth                     } while (0)
5148fcf5ef2aSThomas Huth 
5149fcf5ef2aSThomas Huth                     case 0x101: /* V9 fmovscc %icc */
5150fcf5ef2aSThomas Huth                         FMOVCC(0, s);
5151fcf5ef2aSThomas Huth                         break;
5152fcf5ef2aSThomas Huth                     case 0x102: /* V9 fmovdcc %icc */
5153fcf5ef2aSThomas Huth                         FMOVCC(0, d);
5154fcf5ef2aSThomas Huth                         break;
5155fcf5ef2aSThomas Huth                     case 0x103: /* V9 fmovqcc %icc */
5156fcf5ef2aSThomas Huth                         CHECK_FPU_FEATURE(dc, FLOAT128);
5157fcf5ef2aSThomas Huth                         FMOVCC(0, q);
5158fcf5ef2aSThomas Huth                         break;
5159fcf5ef2aSThomas Huth                     case 0x181: /* V9 fmovscc %xcc */
5160fcf5ef2aSThomas Huth                         FMOVCC(1, s);
5161fcf5ef2aSThomas Huth                         break;
5162fcf5ef2aSThomas Huth                     case 0x182: /* V9 fmovdcc %xcc */
5163fcf5ef2aSThomas Huth                         FMOVCC(1, d);
5164fcf5ef2aSThomas Huth                         break;
5165fcf5ef2aSThomas Huth                     case 0x183: /* V9 fmovqcc %xcc */
5166fcf5ef2aSThomas Huth                         CHECK_FPU_FEATURE(dc, FLOAT128);
5167fcf5ef2aSThomas Huth                         FMOVCC(1, q);
5168fcf5ef2aSThomas Huth                         break;
5169fcf5ef2aSThomas Huth #undef FMOVCC
5170fcf5ef2aSThomas Huth #endif
5171fcf5ef2aSThomas Huth                     case 0x51: /* fcmps, V9 %fcc */
5172fcf5ef2aSThomas Huth                         cpu_src1_32 = gen_load_fpr_F(dc, rs1);
5173fcf5ef2aSThomas Huth                         cpu_src2_32 = gen_load_fpr_F(dc, rs2);
5174fcf5ef2aSThomas Huth                         gen_op_fcmps(rd & 3, cpu_src1_32, cpu_src2_32);
5175fcf5ef2aSThomas Huth                         break;
5176fcf5ef2aSThomas Huth                     case 0x52: /* fcmpd, V9 %fcc */
5177fcf5ef2aSThomas Huth                         cpu_src1_64 = gen_load_fpr_D(dc, rs1);
5178fcf5ef2aSThomas Huth                         cpu_src2_64 = gen_load_fpr_D(dc, rs2);
5179fcf5ef2aSThomas Huth                         gen_op_fcmpd(rd & 3, cpu_src1_64, cpu_src2_64);
5180fcf5ef2aSThomas Huth                         break;
5181fcf5ef2aSThomas Huth                     case 0x53: /* fcmpq, V9 %fcc */
5182fcf5ef2aSThomas Huth                         CHECK_FPU_FEATURE(dc, FLOAT128);
5183fcf5ef2aSThomas Huth                         gen_op_load_fpr_QT0(QFPREG(rs1));
5184fcf5ef2aSThomas Huth                         gen_op_load_fpr_QT1(QFPREG(rs2));
5185fcf5ef2aSThomas Huth                         gen_op_fcmpq(rd & 3);
5186fcf5ef2aSThomas Huth                         break;
5187fcf5ef2aSThomas Huth                     case 0x55: /* fcmpes, V9 %fcc */
5188fcf5ef2aSThomas Huth                         cpu_src1_32 = gen_load_fpr_F(dc, rs1);
5189fcf5ef2aSThomas Huth                         cpu_src2_32 = gen_load_fpr_F(dc, rs2);
5190fcf5ef2aSThomas Huth                         gen_op_fcmpes(rd & 3, cpu_src1_32, cpu_src2_32);
5191fcf5ef2aSThomas Huth                         break;
5192fcf5ef2aSThomas Huth                     case 0x56: /* fcmped, V9 %fcc */
5193fcf5ef2aSThomas Huth                         cpu_src1_64 = gen_load_fpr_D(dc, rs1);
5194fcf5ef2aSThomas Huth                         cpu_src2_64 = gen_load_fpr_D(dc, rs2);
5195fcf5ef2aSThomas Huth                         gen_op_fcmped(rd & 3, cpu_src1_64, cpu_src2_64);
5196fcf5ef2aSThomas Huth                         break;
5197fcf5ef2aSThomas Huth                     case 0x57: /* fcmpeq, V9 %fcc */
5198fcf5ef2aSThomas Huth                         CHECK_FPU_FEATURE(dc, FLOAT128);
5199fcf5ef2aSThomas Huth                         gen_op_load_fpr_QT0(QFPREG(rs1));
5200fcf5ef2aSThomas Huth                         gen_op_load_fpr_QT1(QFPREG(rs2));
5201fcf5ef2aSThomas Huth                         gen_op_fcmpeq(rd & 3);
5202fcf5ef2aSThomas Huth                         break;
5203fcf5ef2aSThomas Huth                     default:
5204fcf5ef2aSThomas Huth                         goto illegal_insn;
5205fcf5ef2aSThomas Huth                 }
5206d3c7e8adSRichard Henderson             } else if (xop == 0x36) {
5207fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
5208d3c7e8adSRichard Henderson                 /* VIS */
5209fcf5ef2aSThomas Huth                 int opf = GET_FIELD_SP(insn, 5, 13);
5210fcf5ef2aSThomas Huth                 rs1 = GET_FIELD(insn, 13, 17);
5211fcf5ef2aSThomas Huth                 rs2 = GET_FIELD(insn, 27, 31);
5212fcf5ef2aSThomas Huth                 if (gen_trap_ifnofpu(dc)) {
5213fcf5ef2aSThomas Huth                     goto jmp_insn;
5214fcf5ef2aSThomas Huth                 }
5215fcf5ef2aSThomas Huth 
5216fcf5ef2aSThomas Huth                 switch (opf) {
5217fcf5ef2aSThomas Huth                 case 0x000: /* VIS I edge8cc */
5218fcf5ef2aSThomas Huth                 case 0x001: /* VIS II edge8n */
5219fcf5ef2aSThomas Huth                 case 0x002: /* VIS I edge8lcc */
5220fcf5ef2aSThomas Huth                 case 0x003: /* VIS II edge8ln */
5221fcf5ef2aSThomas Huth                 case 0x004: /* VIS I edge16cc */
5222fcf5ef2aSThomas Huth                 case 0x005: /* VIS II edge16n */
5223fcf5ef2aSThomas Huth                 case 0x006: /* VIS I edge16lcc */
5224fcf5ef2aSThomas Huth                 case 0x007: /* VIS II edge16ln */
5225fcf5ef2aSThomas Huth                 case 0x008: /* VIS I edge32cc */
5226fcf5ef2aSThomas Huth                 case 0x009: /* VIS II edge32n */
5227fcf5ef2aSThomas Huth                 case 0x00a: /* VIS I edge32lcc */
5228fcf5ef2aSThomas Huth                 case 0x00b: /* VIS II edge32ln */
5229fcf5ef2aSThomas Huth                 case 0x010: /* VIS I array8 */
5230fcf5ef2aSThomas Huth                 case 0x012: /* VIS I array16 */
5231fcf5ef2aSThomas Huth                 case 0x014: /* VIS I array32 */
5232fcf5ef2aSThomas Huth                 case 0x018: /* VIS I alignaddr */
5233fcf5ef2aSThomas Huth                 case 0x01a: /* VIS I alignaddrl */
5234fcf5ef2aSThomas Huth                 case 0x019: /* VIS II bmask */
5235baf3dbf2SRichard Henderson                 case 0x067: /* VIS I fnot2s */
5236baf3dbf2SRichard Henderson                 case 0x06b: /* VIS I fnot1s */
5237baf3dbf2SRichard Henderson                 case 0x075: /* VIS I fsrc1s */
5238baf3dbf2SRichard Henderson                 case 0x079: /* VIS I fsrc2s */
5239c6d83e4fSRichard Henderson                 case 0x066: /* VIS I fnot2 */
5240c6d83e4fSRichard Henderson                 case 0x06a: /* VIS I fnot1 */
5241c6d83e4fSRichard Henderson                 case 0x074: /* VIS I fsrc1 */
5242c6d83e4fSRichard Henderson                 case 0x078: /* VIS I fsrc2 */
5243*7f10b52fSRichard Henderson                 case 0x051: /* VIS I fpadd16s */
5244*7f10b52fSRichard Henderson                 case 0x053: /* VIS I fpadd32s */
5245*7f10b52fSRichard Henderson                 case 0x055: /* VIS I fpsub16s */
5246*7f10b52fSRichard Henderson                 case 0x057: /* VIS I fpsub32s */
5247*7f10b52fSRichard Henderson                 case 0x063: /* VIS I fnors */
5248*7f10b52fSRichard Henderson                 case 0x065: /* VIS I fandnot2s */
5249*7f10b52fSRichard Henderson                 case 0x069: /* VIS I fandnot1s */
5250*7f10b52fSRichard Henderson                 case 0x06d: /* VIS I fxors */
5251*7f10b52fSRichard Henderson                 case 0x06f: /* VIS I fnands */
5252*7f10b52fSRichard Henderson                 case 0x071: /* VIS I fands */
5253*7f10b52fSRichard Henderson                 case 0x073: /* VIS I fxnors */
5254*7f10b52fSRichard Henderson                 case 0x077: /* VIS I fornot2s */
5255*7f10b52fSRichard Henderson                 case 0x07b: /* VIS I fornot1s */
5256*7f10b52fSRichard Henderson                 case 0x07d: /* VIS I fors */
525739ca3490SRichard Henderson                     g_assert_not_reached();  /* in decodetree */
5258fcf5ef2aSThomas Huth                 case 0x020: /* VIS I fcmple16 */
5259fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5260fcf5ef2aSThomas Huth                     cpu_src1_64 = gen_load_fpr_D(dc, rs1);
5261fcf5ef2aSThomas Huth                     cpu_src2_64 = gen_load_fpr_D(dc, rs2);
5262fcf5ef2aSThomas Huth                     gen_helper_fcmple16(cpu_dst, cpu_src1_64, cpu_src2_64);
5263fcf5ef2aSThomas Huth                     gen_store_gpr(dc, rd, cpu_dst);
5264fcf5ef2aSThomas Huth                     break;
5265fcf5ef2aSThomas Huth                 case 0x022: /* VIS I fcmpne16 */
5266fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5267fcf5ef2aSThomas Huth                     cpu_src1_64 = gen_load_fpr_D(dc, rs1);
5268fcf5ef2aSThomas Huth                     cpu_src2_64 = gen_load_fpr_D(dc, rs2);
5269fcf5ef2aSThomas Huth                     gen_helper_fcmpne16(cpu_dst, cpu_src1_64, cpu_src2_64);
5270fcf5ef2aSThomas Huth                     gen_store_gpr(dc, rd, cpu_dst);
5271fcf5ef2aSThomas Huth                     break;
5272fcf5ef2aSThomas Huth                 case 0x024: /* VIS I fcmple32 */
5273fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5274fcf5ef2aSThomas Huth                     cpu_src1_64 = gen_load_fpr_D(dc, rs1);
5275fcf5ef2aSThomas Huth                     cpu_src2_64 = gen_load_fpr_D(dc, rs2);
5276fcf5ef2aSThomas Huth                     gen_helper_fcmple32(cpu_dst, cpu_src1_64, cpu_src2_64);
5277fcf5ef2aSThomas Huth                     gen_store_gpr(dc, rd, cpu_dst);
5278fcf5ef2aSThomas Huth                     break;
5279fcf5ef2aSThomas Huth                 case 0x026: /* VIS I fcmpne32 */
5280fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5281fcf5ef2aSThomas Huth                     cpu_src1_64 = gen_load_fpr_D(dc, rs1);
5282fcf5ef2aSThomas Huth                     cpu_src2_64 = gen_load_fpr_D(dc, rs2);
5283fcf5ef2aSThomas Huth                     gen_helper_fcmpne32(cpu_dst, cpu_src1_64, cpu_src2_64);
5284fcf5ef2aSThomas Huth                     gen_store_gpr(dc, rd, cpu_dst);
5285fcf5ef2aSThomas Huth                     break;
5286fcf5ef2aSThomas Huth                 case 0x028: /* VIS I fcmpgt16 */
5287fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5288fcf5ef2aSThomas Huth                     cpu_src1_64 = gen_load_fpr_D(dc, rs1);
5289fcf5ef2aSThomas Huth                     cpu_src2_64 = gen_load_fpr_D(dc, rs2);
5290fcf5ef2aSThomas Huth                     gen_helper_fcmpgt16(cpu_dst, cpu_src1_64, cpu_src2_64);
5291fcf5ef2aSThomas Huth                     gen_store_gpr(dc, rd, cpu_dst);
5292fcf5ef2aSThomas Huth                     break;
5293fcf5ef2aSThomas Huth                 case 0x02a: /* VIS I fcmpeq16 */
5294fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5295fcf5ef2aSThomas Huth                     cpu_src1_64 = gen_load_fpr_D(dc, rs1);
5296fcf5ef2aSThomas Huth                     cpu_src2_64 = gen_load_fpr_D(dc, rs2);
5297fcf5ef2aSThomas Huth                     gen_helper_fcmpeq16(cpu_dst, cpu_src1_64, cpu_src2_64);
5298fcf5ef2aSThomas Huth                     gen_store_gpr(dc, rd, cpu_dst);
5299fcf5ef2aSThomas Huth                     break;
5300fcf5ef2aSThomas Huth                 case 0x02c: /* VIS I fcmpgt32 */
5301fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5302fcf5ef2aSThomas Huth                     cpu_src1_64 = gen_load_fpr_D(dc, rs1);
5303fcf5ef2aSThomas Huth                     cpu_src2_64 = gen_load_fpr_D(dc, rs2);
5304fcf5ef2aSThomas Huth                     gen_helper_fcmpgt32(cpu_dst, cpu_src1_64, cpu_src2_64);
5305fcf5ef2aSThomas Huth                     gen_store_gpr(dc, rd, cpu_dst);
5306fcf5ef2aSThomas Huth                     break;
5307fcf5ef2aSThomas Huth                 case 0x02e: /* VIS I fcmpeq32 */
5308fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5309fcf5ef2aSThomas Huth                     cpu_src1_64 = gen_load_fpr_D(dc, rs1);
5310fcf5ef2aSThomas Huth                     cpu_src2_64 = gen_load_fpr_D(dc, rs2);
5311fcf5ef2aSThomas Huth                     gen_helper_fcmpeq32(cpu_dst, cpu_src1_64, cpu_src2_64);
5312fcf5ef2aSThomas Huth                     gen_store_gpr(dc, rd, cpu_dst);
5313fcf5ef2aSThomas Huth                     break;
5314fcf5ef2aSThomas Huth                 case 0x031: /* VIS I fmul8x16 */
5315fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5316fcf5ef2aSThomas Huth                     gen_ne_fop_DDD(dc, rd, rs1, rs2, gen_helper_fmul8x16);
5317fcf5ef2aSThomas Huth                     break;
5318fcf5ef2aSThomas Huth                 case 0x033: /* VIS I fmul8x16au */
5319fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5320fcf5ef2aSThomas Huth                     gen_ne_fop_DDD(dc, rd, rs1, rs2, gen_helper_fmul8x16au);
5321fcf5ef2aSThomas Huth                     break;
5322fcf5ef2aSThomas Huth                 case 0x035: /* VIS I fmul8x16al */
5323fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5324fcf5ef2aSThomas Huth                     gen_ne_fop_DDD(dc, rd, rs1, rs2, gen_helper_fmul8x16al);
5325fcf5ef2aSThomas Huth                     break;
5326fcf5ef2aSThomas Huth                 case 0x036: /* VIS I fmul8sux16 */
5327fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5328fcf5ef2aSThomas Huth                     gen_ne_fop_DDD(dc, rd, rs1, rs2, gen_helper_fmul8sux16);
5329fcf5ef2aSThomas Huth                     break;
5330fcf5ef2aSThomas Huth                 case 0x037: /* VIS I fmul8ulx16 */
5331fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5332fcf5ef2aSThomas Huth                     gen_ne_fop_DDD(dc, rd, rs1, rs2, gen_helper_fmul8ulx16);
5333fcf5ef2aSThomas Huth                     break;
5334fcf5ef2aSThomas Huth                 case 0x038: /* VIS I fmuld8sux16 */
5335fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5336fcf5ef2aSThomas Huth                     gen_ne_fop_DDD(dc, rd, rs1, rs2, gen_helper_fmuld8sux16);
5337fcf5ef2aSThomas Huth                     break;
5338fcf5ef2aSThomas Huth                 case 0x039: /* VIS I fmuld8ulx16 */
5339fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5340fcf5ef2aSThomas Huth                     gen_ne_fop_DDD(dc, rd, rs1, rs2, gen_helper_fmuld8ulx16);
5341fcf5ef2aSThomas Huth                     break;
5342fcf5ef2aSThomas Huth                 case 0x03a: /* VIS I fpack32 */
5343fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5344fcf5ef2aSThomas Huth                     gen_gsr_fop_DDD(dc, rd, rs1, rs2, gen_helper_fpack32);
5345fcf5ef2aSThomas Huth                     break;
5346fcf5ef2aSThomas Huth                 case 0x03b: /* VIS I fpack16 */
5347fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5348fcf5ef2aSThomas Huth                     cpu_src1_64 = gen_load_fpr_D(dc, rs2);
5349fcf5ef2aSThomas Huth                     cpu_dst_32 = gen_dest_fpr_F(dc);
5350fcf5ef2aSThomas Huth                     gen_helper_fpack16(cpu_dst_32, cpu_gsr, cpu_src1_64);
5351fcf5ef2aSThomas Huth                     gen_store_fpr_F(dc, rd, cpu_dst_32);
5352fcf5ef2aSThomas Huth                     break;
5353fcf5ef2aSThomas Huth                 case 0x03d: /* VIS I fpackfix */
5354fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5355fcf5ef2aSThomas Huth                     cpu_src1_64 = gen_load_fpr_D(dc, rs2);
5356fcf5ef2aSThomas Huth                     cpu_dst_32 = gen_dest_fpr_F(dc);
5357fcf5ef2aSThomas Huth                     gen_helper_fpackfix(cpu_dst_32, cpu_gsr, cpu_src1_64);
5358fcf5ef2aSThomas Huth                     gen_store_fpr_F(dc, rd, cpu_dst_32);
5359fcf5ef2aSThomas Huth                     break;
5360fcf5ef2aSThomas Huth                 case 0x03e: /* VIS I pdist */
5361fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5362fcf5ef2aSThomas Huth                     gen_ne_fop_DDDD(dc, rd, rs1, rs2, gen_helper_pdist);
5363fcf5ef2aSThomas Huth                     break;
5364fcf5ef2aSThomas Huth                 case 0x048: /* VIS I faligndata */
5365fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5366fcf5ef2aSThomas Huth                     gen_gsr_fop_DDD(dc, rd, rs1, rs2, gen_faligndata);
5367fcf5ef2aSThomas Huth                     break;
5368fcf5ef2aSThomas Huth                 case 0x04b: /* VIS I fpmerge */
5369fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5370fcf5ef2aSThomas Huth                     gen_ne_fop_DDD(dc, rd, rs1, rs2, gen_helper_fpmerge);
5371fcf5ef2aSThomas Huth                     break;
5372fcf5ef2aSThomas Huth                 case 0x04c: /* VIS II bshuffle */
5373fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS2);
5374fcf5ef2aSThomas Huth                     gen_gsr_fop_DDD(dc, rd, rs1, rs2, gen_helper_bshuffle);
5375fcf5ef2aSThomas Huth                     break;
5376fcf5ef2aSThomas Huth                 case 0x04d: /* VIS I fexpand */
5377fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5378fcf5ef2aSThomas Huth                     gen_ne_fop_DDD(dc, rd, rs1, rs2, gen_helper_fexpand);
5379fcf5ef2aSThomas Huth                     break;
5380fcf5ef2aSThomas Huth                 case 0x050: /* VIS I fpadd16 */
5381fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5382fafba1bbSRichard Henderson                     gen_ne_fop_DDD(dc, rd, rs1, rs2, tcg_gen_vec_add16_i64);
5383fcf5ef2aSThomas Huth                     break;
5384fcf5ef2aSThomas Huth                 case 0x052: /* VIS I fpadd32 */
5385fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5386fafba1bbSRichard Henderson                     gen_ne_fop_DDD(dc, rd, rs1, rs2, tcg_gen_vec_add32_i64);
5387fcf5ef2aSThomas Huth                     break;
5388fcf5ef2aSThomas Huth                 case 0x054: /* VIS I fpsub16 */
5389fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5390fafba1bbSRichard Henderson                     gen_ne_fop_DDD(dc, rd, rs1, rs2, tcg_gen_vec_sub16_i64);
5391fcf5ef2aSThomas Huth                     break;
5392fcf5ef2aSThomas Huth                 case 0x056: /* VIS I fpsub32 */
5393fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5394fafba1bbSRichard Henderson                     gen_ne_fop_DDD(dc, rd, rs1, rs2, tcg_gen_vec_add32_i64);
5395fcf5ef2aSThomas Huth                     break;
5396fcf5ef2aSThomas Huth                 case 0x060: /* VIS I fzero */
5397fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5398fcf5ef2aSThomas Huth                     cpu_dst_64 = gen_dest_fpr_D(dc, rd);
5399fcf5ef2aSThomas Huth                     tcg_gen_movi_i64(cpu_dst_64, 0);
5400fcf5ef2aSThomas Huth                     gen_store_fpr_D(dc, rd, cpu_dst_64);
5401fcf5ef2aSThomas Huth                     break;
5402fcf5ef2aSThomas Huth                 case 0x061: /* VIS I fzeros */
5403fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5404fcf5ef2aSThomas Huth                     cpu_dst_32 = gen_dest_fpr_F(dc);
5405fcf5ef2aSThomas Huth                     tcg_gen_movi_i32(cpu_dst_32, 0);
5406fcf5ef2aSThomas Huth                     gen_store_fpr_F(dc, rd, cpu_dst_32);
5407fcf5ef2aSThomas Huth                     break;
5408fcf5ef2aSThomas Huth                 case 0x062: /* VIS I fnor */
5409fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5410fcf5ef2aSThomas Huth                     gen_ne_fop_DDD(dc, rd, rs1, rs2, tcg_gen_nor_i64);
5411fcf5ef2aSThomas Huth                     break;
5412fcf5ef2aSThomas Huth                 case 0x064: /* VIS I fandnot2 */
5413fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5414fcf5ef2aSThomas Huth                     gen_ne_fop_DDD(dc, rd, rs1, rs2, tcg_gen_andc_i64);
5415fcf5ef2aSThomas Huth                     break;
5416fcf5ef2aSThomas Huth                 case 0x068: /* VIS I fandnot1 */
5417fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5418fcf5ef2aSThomas Huth                     gen_ne_fop_DDD(dc, rd, rs2, rs1, tcg_gen_andc_i64);
5419fcf5ef2aSThomas Huth                     break;
5420fcf5ef2aSThomas Huth                 case 0x06c: /* VIS I fxor */
5421fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5422fcf5ef2aSThomas Huth                     gen_ne_fop_DDD(dc, rd, rs1, rs2, tcg_gen_xor_i64);
5423fcf5ef2aSThomas Huth                     break;
5424fcf5ef2aSThomas Huth                 case 0x06e: /* VIS I fnand */
5425fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5426fcf5ef2aSThomas Huth                     gen_ne_fop_DDD(dc, rd, rs1, rs2, tcg_gen_nand_i64);
5427fcf5ef2aSThomas Huth                     break;
5428fcf5ef2aSThomas Huth                 case 0x070: /* VIS I fand */
5429fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5430fcf5ef2aSThomas Huth                     gen_ne_fop_DDD(dc, rd, rs1, rs2, tcg_gen_and_i64);
5431fcf5ef2aSThomas Huth                     break;
5432fcf5ef2aSThomas Huth                 case 0x072: /* VIS I fxnor */
5433fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5434fcf5ef2aSThomas Huth                     gen_ne_fop_DDD(dc, rd, rs1, rs2, tcg_gen_eqv_i64);
5435fcf5ef2aSThomas Huth                     break;
5436fcf5ef2aSThomas Huth                 case 0x076: /* VIS I fornot2 */
5437fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5438fcf5ef2aSThomas Huth                     gen_ne_fop_DDD(dc, rd, rs1, rs2, tcg_gen_orc_i64);
5439fcf5ef2aSThomas Huth                     break;
5440fcf5ef2aSThomas Huth                 case 0x07a: /* VIS I fornot1 */
5441fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5442fcf5ef2aSThomas Huth                     gen_ne_fop_DDD(dc, rd, rs2, rs1, tcg_gen_orc_i64);
5443fcf5ef2aSThomas Huth                     break;
5444fcf5ef2aSThomas Huth                 case 0x07c: /* VIS I for */
5445fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5446fcf5ef2aSThomas Huth                     gen_ne_fop_DDD(dc, rd, rs1, rs2, tcg_gen_or_i64);
5447fcf5ef2aSThomas Huth                     break;
5448fcf5ef2aSThomas Huth                 case 0x07e: /* VIS I fone */
5449fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5450fcf5ef2aSThomas Huth                     cpu_dst_64 = gen_dest_fpr_D(dc, rd);
5451fcf5ef2aSThomas Huth                     tcg_gen_movi_i64(cpu_dst_64, -1);
5452fcf5ef2aSThomas Huth                     gen_store_fpr_D(dc, rd, cpu_dst_64);
5453fcf5ef2aSThomas Huth                     break;
5454fcf5ef2aSThomas Huth                 case 0x07f: /* VIS I fones */
5455fcf5ef2aSThomas Huth                     CHECK_FPU_FEATURE(dc, VIS1);
5456fcf5ef2aSThomas Huth                     cpu_dst_32 = gen_dest_fpr_F(dc);
5457fcf5ef2aSThomas Huth                     tcg_gen_movi_i32(cpu_dst_32, -1);
5458fcf5ef2aSThomas Huth                     gen_store_fpr_F(dc, rd, cpu_dst_32);
5459fcf5ef2aSThomas Huth                     break;
5460fcf5ef2aSThomas Huth                 case 0x080: /* VIS I shutdown */
5461fcf5ef2aSThomas Huth                 case 0x081: /* VIS II siam */
5462fcf5ef2aSThomas Huth                     // XXX
5463fcf5ef2aSThomas Huth                     goto illegal_insn;
5464fcf5ef2aSThomas Huth                 default:
5465fcf5ef2aSThomas Huth                     goto illegal_insn;
5466fcf5ef2aSThomas Huth                 }
5467fcf5ef2aSThomas Huth #endif
54688f75b8a4SRichard Henderson             } else {
5469d3c7e8adSRichard Henderson                 goto illegal_insn; /* in decodetree */
5470fcf5ef2aSThomas Huth             }
5471fcf5ef2aSThomas Huth         }
5472fcf5ef2aSThomas Huth         break;
5473fcf5ef2aSThomas Huth     case 3:                     /* load/store instructions */
54740880d20bSRichard Henderson         goto illegal_insn; /* in decodetree */
5475fcf5ef2aSThomas Huth     }
5476878cc677SRichard Henderson     advance_pc(dc);
5477fcf5ef2aSThomas Huth  jmp_insn:
5478a6ca81cbSRichard Henderson     return;
5479fcf5ef2aSThomas Huth  illegal_insn:
5480fcf5ef2aSThomas Huth     gen_exception(dc, TT_ILL_INSN);
5481a6ca81cbSRichard Henderson     return;
5482fcf5ef2aSThomas Huth  nfpu_insn:
5483fcf5ef2aSThomas Huth     gen_op_fpexception_im(dc, FSR_FTT_UNIMPFPOP);
5484a6ca81cbSRichard Henderson     return;
5485fcf5ef2aSThomas Huth }
5486fcf5ef2aSThomas Huth 
54876e61bc94SEmilio G. Cota static void sparc_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
5488fcf5ef2aSThomas Huth {
54896e61bc94SEmilio G. Cota     DisasContext *dc = container_of(dcbase, DisasContext, base);
5490b77af26eSRichard Henderson     CPUSPARCState *env = cpu_env(cs);
54916e61bc94SEmilio G. Cota     int bound;
5492af00be49SEmilio G. Cota 
5493af00be49SEmilio G. Cota     dc->pc = dc->base.pc_first;
54946e61bc94SEmilio G. Cota     dc->npc = (target_ulong)dc->base.tb->cs_base;
5495fcf5ef2aSThomas Huth     dc->cc_op = CC_OP_DYNAMIC;
54966e61bc94SEmilio G. Cota     dc->mem_idx = dc->base.tb->flags & TB_FLAG_MMU_MASK;
5497576e1c4cSIgor Mammedov     dc->def = &env->def;
54986e61bc94SEmilio G. Cota     dc->fpu_enabled = tb_fpu_enabled(dc->base.tb->flags);
54996e61bc94SEmilio G. Cota     dc->address_mask_32bit = tb_am_enabled(dc->base.tb->flags);
5500c9b459aaSArtyom Tarasenko #ifndef CONFIG_USER_ONLY
55016e61bc94SEmilio G. Cota     dc->supervisor = (dc->base.tb->flags & TB_FLAG_SUPER) != 0;
5502c9b459aaSArtyom Tarasenko #endif
5503fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
5504fcf5ef2aSThomas Huth     dc->fprs_dirty = 0;
55056e61bc94SEmilio G. Cota     dc->asi = (dc->base.tb->flags >> TB_FLAG_ASI_SHIFT) & 0xff;
5506c9b459aaSArtyom Tarasenko #ifndef CONFIG_USER_ONLY
55076e61bc94SEmilio G. Cota     dc->hypervisor = (dc->base.tb->flags & TB_FLAG_HYPER) != 0;
5508c9b459aaSArtyom Tarasenko #endif
5509fcf5ef2aSThomas Huth #endif
55106e61bc94SEmilio G. Cota     /*
55116e61bc94SEmilio G. Cota      * if we reach a page boundary, we stop generation so that the
55126e61bc94SEmilio G. Cota      * PC of a TT_TFAULT exception is always in the right page
55136e61bc94SEmilio G. Cota      */
55146e61bc94SEmilio G. Cota     bound = -(dc->base.pc_first | TARGET_PAGE_MASK) / 4;
55156e61bc94SEmilio G. Cota     dc->base.max_insns = MIN(dc->base.max_insns, bound);
5516af00be49SEmilio G. Cota }
5517fcf5ef2aSThomas Huth 
55186e61bc94SEmilio G. Cota static void sparc_tr_tb_start(DisasContextBase *db, CPUState *cs)
55196e61bc94SEmilio G. Cota {
55206e61bc94SEmilio G. Cota }
55216e61bc94SEmilio G. Cota 
55226e61bc94SEmilio G. Cota static void sparc_tr_insn_start(DisasContextBase *dcbase, CPUState *cs)
55236e61bc94SEmilio G. Cota {
55246e61bc94SEmilio G. Cota     DisasContext *dc = container_of(dcbase, DisasContext, base);
5525633c4283SRichard Henderson     target_ulong npc = dc->npc;
55266e61bc94SEmilio G. Cota 
5527633c4283SRichard Henderson     if (npc & 3) {
5528633c4283SRichard Henderson         switch (npc) {
5529633c4283SRichard Henderson         case JUMP_PC:
5530fcf5ef2aSThomas Huth             assert(dc->jump_pc[1] == dc->pc + 4);
5531633c4283SRichard Henderson             npc = dc->jump_pc[0] | JUMP_PC;
5532633c4283SRichard Henderson             break;
5533633c4283SRichard Henderson         case DYNAMIC_PC:
5534633c4283SRichard Henderson         case DYNAMIC_PC_LOOKUP:
5535633c4283SRichard Henderson             npc = DYNAMIC_PC;
5536633c4283SRichard Henderson             break;
5537633c4283SRichard Henderson         default:
5538633c4283SRichard Henderson             g_assert_not_reached();
5539fcf5ef2aSThomas Huth         }
55406e61bc94SEmilio G. Cota     }
5541633c4283SRichard Henderson     tcg_gen_insn_start(dc->pc, npc);
5542633c4283SRichard Henderson }
5543fcf5ef2aSThomas Huth 
55446e61bc94SEmilio G. Cota static void sparc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs)
55456e61bc94SEmilio G. Cota {
55466e61bc94SEmilio G. Cota     DisasContext *dc = container_of(dcbase, DisasContext, base);
5547b77af26eSRichard Henderson     CPUSPARCState *env = cpu_env(cs);
55486e61bc94SEmilio G. Cota     unsigned int insn;
5549fcf5ef2aSThomas Huth 
55504e116893SIlya Leoshkevich     insn = translator_ldl(env, &dc->base, dc->pc);
5551af00be49SEmilio G. Cota     dc->base.pc_next += 4;
5552878cc677SRichard Henderson 
5553878cc677SRichard Henderson     if (!decode(dc, insn)) {
5554878cc677SRichard Henderson         disas_sparc_legacy(dc, insn);
5555878cc677SRichard Henderson     }
5556fcf5ef2aSThomas Huth 
5557af00be49SEmilio G. Cota     if (dc->base.is_jmp == DISAS_NORETURN) {
55586e61bc94SEmilio G. Cota         return;
5559c5e6ccdfSEmilio G. Cota     }
5560af00be49SEmilio G. Cota     if (dc->pc != dc->base.pc_next) {
55616e61bc94SEmilio G. Cota         dc->base.is_jmp = DISAS_TOO_MANY;
5562af00be49SEmilio G. Cota     }
55636e61bc94SEmilio G. Cota }
5564fcf5ef2aSThomas Huth 
55656e61bc94SEmilio G. Cota static void sparc_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)
55666e61bc94SEmilio G. Cota {
55676e61bc94SEmilio G. Cota     DisasContext *dc = container_of(dcbase, DisasContext, base);
5568186e7890SRichard Henderson     DisasDelayException *e, *e_next;
5569633c4283SRichard Henderson     bool may_lookup;
55706e61bc94SEmilio G. Cota 
557146bb0137SMark Cave-Ayland     switch (dc->base.is_jmp) {
557246bb0137SMark Cave-Ayland     case DISAS_NEXT:
557346bb0137SMark Cave-Ayland     case DISAS_TOO_MANY:
5574633c4283SRichard Henderson         if (((dc->pc | dc->npc) & 3) == 0) {
5575fcf5ef2aSThomas Huth             /* static PC and NPC: we can use direct chaining */
5576fcf5ef2aSThomas Huth             gen_goto_tb(dc, 0, dc->pc, dc->npc);
5577633c4283SRichard Henderson             break;
5578fcf5ef2aSThomas Huth         }
5579633c4283SRichard Henderson 
5580930f1865SRichard Henderson         may_lookup = true;
5581633c4283SRichard Henderson         if (dc->pc & 3) {
5582633c4283SRichard Henderson             switch (dc->pc) {
5583633c4283SRichard Henderson             case DYNAMIC_PC_LOOKUP:
5584633c4283SRichard Henderson                 break;
5585633c4283SRichard Henderson             case DYNAMIC_PC:
5586633c4283SRichard Henderson                 may_lookup = false;
5587633c4283SRichard Henderson                 break;
5588633c4283SRichard Henderson             default:
5589633c4283SRichard Henderson                 g_assert_not_reached();
5590633c4283SRichard Henderson             }
5591633c4283SRichard Henderson         } else {
5592633c4283SRichard Henderson             tcg_gen_movi_tl(cpu_pc, dc->pc);
5593633c4283SRichard Henderson         }
5594633c4283SRichard Henderson 
5595930f1865SRichard Henderson         if (dc->npc & 3) {
5596930f1865SRichard Henderson             switch (dc->npc) {
5597930f1865SRichard Henderson             case JUMP_PC:
5598930f1865SRichard Henderson                 gen_generic_branch(dc);
5599930f1865SRichard Henderson                 break;
5600930f1865SRichard Henderson             case DYNAMIC_PC:
5601930f1865SRichard Henderson                 may_lookup = false;
5602930f1865SRichard Henderson                 break;
5603930f1865SRichard Henderson             case DYNAMIC_PC_LOOKUP:
5604930f1865SRichard Henderson                 break;
5605930f1865SRichard Henderson             default:
5606930f1865SRichard Henderson                 g_assert_not_reached();
5607930f1865SRichard Henderson             }
5608930f1865SRichard Henderson         } else {
5609930f1865SRichard Henderson             tcg_gen_movi_tl(cpu_npc, dc->npc);
5610930f1865SRichard Henderson         }
5611633c4283SRichard Henderson         if (may_lookup) {
5612633c4283SRichard Henderson             tcg_gen_lookup_and_goto_ptr();
5613633c4283SRichard Henderson         } else {
561407ea28b4SRichard Henderson             tcg_gen_exit_tb(NULL, 0);
5615fcf5ef2aSThomas Huth         }
561646bb0137SMark Cave-Ayland         break;
561746bb0137SMark Cave-Ayland 
561846bb0137SMark Cave-Ayland     case DISAS_NORETURN:
561946bb0137SMark Cave-Ayland        break;
562046bb0137SMark Cave-Ayland 
562146bb0137SMark Cave-Ayland     case DISAS_EXIT:
562246bb0137SMark Cave-Ayland         /* Exit TB */
562346bb0137SMark Cave-Ayland         save_state(dc);
562446bb0137SMark Cave-Ayland         tcg_gen_exit_tb(NULL, 0);
562546bb0137SMark Cave-Ayland         break;
562646bb0137SMark Cave-Ayland 
562746bb0137SMark Cave-Ayland     default:
562846bb0137SMark Cave-Ayland         g_assert_not_reached();
5629fcf5ef2aSThomas Huth     }
5630186e7890SRichard Henderson 
5631186e7890SRichard Henderson     for (e = dc->delay_excp_list; e ; e = e_next) {
5632186e7890SRichard Henderson         gen_set_label(e->lab);
5633186e7890SRichard Henderson 
5634186e7890SRichard Henderson         tcg_gen_movi_tl(cpu_pc, e->pc);
5635186e7890SRichard Henderson         if (e->npc % 4 == 0) {
5636186e7890SRichard Henderson             tcg_gen_movi_tl(cpu_npc, e->npc);
5637186e7890SRichard Henderson         }
5638186e7890SRichard Henderson         gen_helper_raise_exception(tcg_env, e->excp);
5639186e7890SRichard Henderson 
5640186e7890SRichard Henderson         e_next = e->next;
5641186e7890SRichard Henderson         g_free(e);
5642186e7890SRichard Henderson     }
5643fcf5ef2aSThomas Huth }
56446e61bc94SEmilio G. Cota 
56458eb806a7SRichard Henderson static void sparc_tr_disas_log(const DisasContextBase *dcbase,
56468eb806a7SRichard Henderson                                CPUState *cpu, FILE *logfile)
56476e61bc94SEmilio G. Cota {
56488eb806a7SRichard Henderson     fprintf(logfile, "IN: %s\n", lookup_symbol(dcbase->pc_first));
56498eb806a7SRichard Henderson     target_disas(logfile, cpu, dcbase->pc_first, dcbase->tb->size);
56506e61bc94SEmilio G. Cota }
56516e61bc94SEmilio G. Cota 
56526e61bc94SEmilio G. Cota static const TranslatorOps sparc_tr_ops = {
56536e61bc94SEmilio G. Cota     .init_disas_context = sparc_tr_init_disas_context,
56546e61bc94SEmilio G. Cota     .tb_start           = sparc_tr_tb_start,
56556e61bc94SEmilio G. Cota     .insn_start         = sparc_tr_insn_start,
56566e61bc94SEmilio G. Cota     .translate_insn     = sparc_tr_translate_insn,
56576e61bc94SEmilio G. Cota     .tb_stop            = sparc_tr_tb_stop,
56586e61bc94SEmilio G. Cota     .disas_log          = sparc_tr_disas_log,
56596e61bc94SEmilio G. Cota };
56606e61bc94SEmilio G. Cota 
5661597f9b2dSRichard Henderson void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int *max_insns,
5662306c8721SRichard Henderson                            target_ulong pc, void *host_pc)
56636e61bc94SEmilio G. Cota {
56646e61bc94SEmilio G. Cota     DisasContext dc = {};
56656e61bc94SEmilio G. Cota 
5666306c8721SRichard Henderson     translator_loop(cs, tb, max_insns, pc, host_pc, &sparc_tr_ops, &dc.base);
5667fcf5ef2aSThomas Huth }
5668fcf5ef2aSThomas Huth 
566955c3ceefSRichard Henderson void sparc_tcg_init(void)
5670fcf5ef2aSThomas Huth {
5671fcf5ef2aSThomas Huth     static const char gregnames[32][4] = {
5672fcf5ef2aSThomas Huth         "g0", "g1", "g2", "g3", "g4", "g5", "g6", "g7",
5673fcf5ef2aSThomas Huth         "o0", "o1", "o2", "o3", "o4", "o5", "o6", "o7",
5674fcf5ef2aSThomas Huth         "l0", "l1", "l2", "l3", "l4", "l5", "l6", "l7",
5675fcf5ef2aSThomas Huth         "i0", "i1", "i2", "i3", "i4", "i5", "i6", "i7",
5676fcf5ef2aSThomas Huth     };
5677fcf5ef2aSThomas Huth     static const char fregnames[32][4] = {
5678fcf5ef2aSThomas Huth         "f0", "f2", "f4", "f6", "f8", "f10", "f12", "f14",
5679fcf5ef2aSThomas Huth         "f16", "f18", "f20", "f22", "f24", "f26", "f28", "f30",
5680fcf5ef2aSThomas Huth         "f32", "f34", "f36", "f38", "f40", "f42", "f44", "f46",
5681fcf5ef2aSThomas Huth         "f48", "f50", "f52", "f54", "f56", "f58", "f60", "f62",
5682fcf5ef2aSThomas Huth     };
5683fcf5ef2aSThomas Huth 
5684fcf5ef2aSThomas Huth     static const struct { TCGv_i32 *ptr; int off; const char *name; } r32[] = {
5685fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
5686fcf5ef2aSThomas Huth         { &cpu_xcc, offsetof(CPUSPARCState, xcc), "xcc" },
5687fcf5ef2aSThomas Huth         { &cpu_fprs, offsetof(CPUSPARCState, fprs), "fprs" },
5688fcf5ef2aSThomas Huth #endif
5689fcf5ef2aSThomas Huth         { &cpu_cc_op, offsetof(CPUSPARCState, cc_op), "cc_op" },
5690fcf5ef2aSThomas Huth         { &cpu_psr, offsetof(CPUSPARCState, psr), "psr" },
5691fcf5ef2aSThomas Huth     };
5692fcf5ef2aSThomas Huth 
5693fcf5ef2aSThomas Huth     static const struct { TCGv *ptr; int off; const char *name; } rtl[] = {
5694fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
5695fcf5ef2aSThomas Huth         { &cpu_gsr, offsetof(CPUSPARCState, gsr), "gsr" },
5696fcf5ef2aSThomas Huth #endif
5697fcf5ef2aSThomas Huth         { &cpu_cond, offsetof(CPUSPARCState, cond), "cond" },
5698fcf5ef2aSThomas Huth         { &cpu_cc_src, offsetof(CPUSPARCState, cc_src), "cc_src" },
5699fcf5ef2aSThomas Huth         { &cpu_cc_src2, offsetof(CPUSPARCState, cc_src2), "cc_src2" },
5700fcf5ef2aSThomas Huth         { &cpu_cc_dst, offsetof(CPUSPARCState, cc_dst), "cc_dst" },
5701fcf5ef2aSThomas Huth         { &cpu_fsr, offsetof(CPUSPARCState, fsr), "fsr" },
5702fcf5ef2aSThomas Huth         { &cpu_pc, offsetof(CPUSPARCState, pc), "pc" },
5703fcf5ef2aSThomas Huth         { &cpu_npc, offsetof(CPUSPARCState, npc), "npc" },
5704fcf5ef2aSThomas Huth         { &cpu_y, offsetof(CPUSPARCState, y), "y" },
5705fcf5ef2aSThomas Huth         { &cpu_tbr, offsetof(CPUSPARCState, tbr), "tbr" },
5706fcf5ef2aSThomas Huth     };
5707fcf5ef2aSThomas Huth 
5708fcf5ef2aSThomas Huth     unsigned int i;
5709fcf5ef2aSThomas Huth 
5710ad75a51eSRichard Henderson     cpu_regwptr = tcg_global_mem_new_ptr(tcg_env,
5711fcf5ef2aSThomas Huth                                          offsetof(CPUSPARCState, regwptr),
5712fcf5ef2aSThomas Huth                                          "regwptr");
5713fcf5ef2aSThomas Huth 
5714fcf5ef2aSThomas Huth     for (i = 0; i < ARRAY_SIZE(r32); ++i) {
5715ad75a51eSRichard Henderson         *r32[i].ptr = tcg_global_mem_new_i32(tcg_env, r32[i].off, r32[i].name);
5716fcf5ef2aSThomas Huth     }
5717fcf5ef2aSThomas Huth 
5718fcf5ef2aSThomas Huth     for (i = 0; i < ARRAY_SIZE(rtl); ++i) {
5719ad75a51eSRichard Henderson         *rtl[i].ptr = tcg_global_mem_new(tcg_env, rtl[i].off, rtl[i].name);
5720fcf5ef2aSThomas Huth     }
5721fcf5ef2aSThomas Huth 
5722f764718dSRichard Henderson     cpu_regs[0] = NULL;
5723fcf5ef2aSThomas Huth     for (i = 1; i < 8; ++i) {
5724ad75a51eSRichard Henderson         cpu_regs[i] = tcg_global_mem_new(tcg_env,
5725fcf5ef2aSThomas Huth                                          offsetof(CPUSPARCState, gregs[i]),
5726fcf5ef2aSThomas Huth                                          gregnames[i]);
5727fcf5ef2aSThomas Huth     }
5728fcf5ef2aSThomas Huth 
5729fcf5ef2aSThomas Huth     for (i = 8; i < 32; ++i) {
5730fcf5ef2aSThomas Huth         cpu_regs[i] = tcg_global_mem_new(cpu_regwptr,
5731fcf5ef2aSThomas Huth                                          (i - 8) * sizeof(target_ulong),
5732fcf5ef2aSThomas Huth                                          gregnames[i]);
5733fcf5ef2aSThomas Huth     }
5734fcf5ef2aSThomas Huth 
5735fcf5ef2aSThomas Huth     for (i = 0; i < TARGET_DPREGS; i++) {
5736ad75a51eSRichard Henderson         cpu_fpr[i] = tcg_global_mem_new_i64(tcg_env,
5737fcf5ef2aSThomas Huth                                             offsetof(CPUSPARCState, fpr[i]),
5738fcf5ef2aSThomas Huth                                             fregnames[i]);
5739fcf5ef2aSThomas Huth     }
5740fcf5ef2aSThomas Huth }
5741fcf5ef2aSThomas Huth 
5742f36aaa53SRichard Henderson void sparc_restore_state_to_opc(CPUState *cs,
5743f36aaa53SRichard Henderson                                 const TranslationBlock *tb,
5744f36aaa53SRichard Henderson                                 const uint64_t *data)
5745fcf5ef2aSThomas Huth {
5746f36aaa53SRichard Henderson     SPARCCPU *cpu = SPARC_CPU(cs);
5747f36aaa53SRichard Henderson     CPUSPARCState *env = &cpu->env;
5748fcf5ef2aSThomas Huth     target_ulong pc = data[0];
5749fcf5ef2aSThomas Huth     target_ulong npc = data[1];
5750fcf5ef2aSThomas Huth 
5751fcf5ef2aSThomas Huth     env->pc = pc;
5752fcf5ef2aSThomas Huth     if (npc == DYNAMIC_PC) {
5753fcf5ef2aSThomas Huth         /* dynamic NPC: already stored */
5754fcf5ef2aSThomas Huth     } else if (npc & JUMP_PC) {
5755fcf5ef2aSThomas Huth         /* jump PC: use 'cond' and the jump targets of the translation */
5756fcf5ef2aSThomas Huth         if (env->cond) {
5757fcf5ef2aSThomas Huth             env->npc = npc & ~3;
5758fcf5ef2aSThomas Huth         } else {
5759fcf5ef2aSThomas Huth             env->npc = pc + 4;
5760fcf5ef2aSThomas Huth         }
5761fcf5ef2aSThomas Huth     } else {
5762fcf5ef2aSThomas Huth         env->npc = npc;
5763fcf5ef2aSThomas Huth     }
5764fcf5ef2aSThomas Huth }
5765