xref: /openbmc/qemu/target/sparc/translate.c (revision d6ff1ccb45f9b228e20f74f6e6c801c88a2885b2)
1fcf5ef2aSThomas Huth /*
2fcf5ef2aSThomas Huth    SPARC translation
3fcf5ef2aSThomas Huth 
4fcf5ef2aSThomas Huth    Copyright (C) 2003 Thomas M. Ogrisegg <tom@fnord.at>
5fcf5ef2aSThomas Huth    Copyright (C) 2003-2005 Fabrice Bellard
6fcf5ef2aSThomas Huth 
7fcf5ef2aSThomas Huth    This library is free software; you can redistribute it and/or
8fcf5ef2aSThomas Huth    modify it under the terms of the GNU Lesser General Public
9fcf5ef2aSThomas Huth    License as published by the Free Software Foundation; either
105650b549SChetan Pant    version 2.1 of the License, or (at your option) any later version.
11fcf5ef2aSThomas Huth 
12fcf5ef2aSThomas Huth    This library is distributed in the hope that it will be useful,
13fcf5ef2aSThomas Huth    but WITHOUT ANY WARRANTY; without even the implied warranty of
14fcf5ef2aSThomas Huth    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15fcf5ef2aSThomas Huth    Lesser General Public License for more details.
16fcf5ef2aSThomas Huth 
17fcf5ef2aSThomas Huth    You should have received a copy of the GNU Lesser General Public
18fcf5ef2aSThomas Huth    License along with this library; if not, see <http://www.gnu.org/licenses/>.
19fcf5ef2aSThomas Huth  */
20fcf5ef2aSThomas Huth 
21fcf5ef2aSThomas Huth #include "qemu/osdep.h"
22fcf5ef2aSThomas Huth 
23fcf5ef2aSThomas Huth #include "cpu.h"
24fcf5ef2aSThomas Huth #include "exec/helper-proto.h"
25fcf5ef2aSThomas Huth #include "exec/exec-all.h"
26dcb32f1dSPhilippe Mathieu-Daudé #include "tcg/tcg-op.h"
27fafba1bbSRichard Henderson #include "tcg/tcg-op-gvec.h"
28fcf5ef2aSThomas Huth #include "exec/helper-gen.h"
29c5e6ccdfSEmilio G. Cota #include "exec/translator.h"
30fcf5ef2aSThomas Huth #include "exec/log.h"
314fd71d19SRichard Henderson #include "fpu/softfloat.h"
32fcf5ef2aSThomas Huth #include "asi.h"
33fcf5ef2aSThomas Huth 
34d53106c9SRichard Henderson #define HELPER_H "helper.h"
35d53106c9SRichard Henderson #include "exec/helper-info.c.inc"
36d53106c9SRichard Henderson #undef  HELPER_H
37fcf5ef2aSThomas Huth 
38668bb9b7SRichard Henderson #ifdef TARGET_SPARC64
39668bb9b7SRichard Henderson # define gen_helper_rdpsr(D, E)                 qemu_build_not_reached()
40c92948f2SClément Chigot # define gen_helper_rdasr17(D, E)               qemu_build_not_reached()
4186b82fe0SRichard Henderson # define gen_helper_rett(E)                     qemu_build_not_reached()
420faef01bSRichard Henderson # define gen_helper_power_down(E)               qemu_build_not_reached()
4325524734SRichard Henderson # define gen_helper_wrpsr(E, S)                 qemu_build_not_reached()
44668bb9b7SRichard Henderson #else
450faef01bSRichard Henderson # define gen_helper_clear_softint(E, S)         qemu_build_not_reached()
468f75b8a4SRichard Henderson # define gen_helper_done(E)                     qemu_build_not_reached()
47e8325dc0SRichard Henderson # define gen_helper_flushw(E)                   qemu_build_not_reached()
48a859602cSRichard Henderson # define gen_helper_fmul8x16a(D, S1, S2)        qemu_build_not_reached()
49af25071cSRichard Henderson # define gen_helper_rdccr(D, E)                 qemu_build_not_reached()
505d617bfbSRichard Henderson # define gen_helper_rdcwp(D, E)                 qemu_build_not_reached()
5125524734SRichard Henderson # define gen_helper_restored(E)                 qemu_build_not_reached()
528f75b8a4SRichard Henderson # define gen_helper_retry(E)                    qemu_build_not_reached()
5325524734SRichard Henderson # define gen_helper_saved(E)                    qemu_build_not_reached()
540faef01bSRichard Henderson # define gen_helper_set_softint(E, S)           qemu_build_not_reached()
55af25071cSRichard Henderson # define gen_helper_tick_get_count(D, E, T, C)  qemu_build_not_reached()
569422278eSRichard Henderson # define gen_helper_tick_set_count(P, S)        qemu_build_not_reached()
57bb97f2f5SRichard Henderson # define gen_helper_tick_set_limit(P, S)        qemu_build_not_reached()
580faef01bSRichard Henderson # define gen_helper_wrccr(E, S)                 qemu_build_not_reached()
599422278eSRichard Henderson # define gen_helper_wrcwp(E, S)                 qemu_build_not_reached()
609422278eSRichard Henderson # define gen_helper_wrgl(E, S)                  qemu_build_not_reached()
610faef01bSRichard Henderson # define gen_helper_write_softint(E, S)         qemu_build_not_reached()
629422278eSRichard Henderson # define gen_helper_wrpil(E, S)                 qemu_build_not_reached()
639422278eSRichard Henderson # define gen_helper_wrpstate(E, S)              qemu_build_not_reached()
64c973b4e8SRichard Henderson # define gen_helper_cmask8               ({ qemu_build_not_reached(); NULL; })
65c973b4e8SRichard Henderson # define gen_helper_cmask16              ({ qemu_build_not_reached(); NULL; })
66c973b4e8SRichard Henderson # define gen_helper_cmask32              ({ qemu_build_not_reached(); NULL; })
67e2fa6bd1SRichard Henderson # define gen_helper_fcmpeq16             ({ qemu_build_not_reached(); NULL; })
68e2fa6bd1SRichard Henderson # define gen_helper_fcmpeq32             ({ qemu_build_not_reached(); NULL; })
69e2fa6bd1SRichard Henderson # define gen_helper_fcmpgt16             ({ qemu_build_not_reached(); NULL; })
70e2fa6bd1SRichard Henderson # define gen_helper_fcmpgt32             ({ qemu_build_not_reached(); NULL; })
71e2fa6bd1SRichard Henderson # define gen_helper_fcmple16             ({ qemu_build_not_reached(); NULL; })
72e2fa6bd1SRichard Henderson # define gen_helper_fcmple32             ({ qemu_build_not_reached(); NULL; })
73e2fa6bd1SRichard Henderson # define gen_helper_fcmpne16             ({ qemu_build_not_reached(); NULL; })
74e2fa6bd1SRichard Henderson # define gen_helper_fcmpne32             ({ qemu_build_not_reached(); NULL; })
758aa418b3SRichard Henderson # define gen_helper_fdtox                ({ qemu_build_not_reached(); NULL; })
76e06c9f83SRichard Henderson # define gen_helper_fexpand              ({ qemu_build_not_reached(); NULL; })
77e06c9f83SRichard Henderson # define gen_helper_fmul8sux16           ({ qemu_build_not_reached(); NULL; })
78e06c9f83SRichard Henderson # define gen_helper_fmul8ulx16           ({ qemu_build_not_reached(); NULL; })
79e06c9f83SRichard Henderson # define gen_helper_fmul8x16             ({ qemu_build_not_reached(); NULL; })
80e06c9f83SRichard Henderson # define gen_helper_fpmerge              ({ qemu_build_not_reached(); NULL; })
811617586fSRichard Henderson # define gen_helper_fqtox                ({ qemu_build_not_reached(); NULL; })
82199d43efSRichard Henderson # define gen_helper_fstox                ({ qemu_build_not_reached(); NULL; })
838aa418b3SRichard Henderson # define gen_helper_fxtod                ({ qemu_build_not_reached(); NULL; })
847b8e3e1aSRichard Henderson # define gen_helper_fxtoq                ({ qemu_build_not_reached(); NULL; })
85f4e18df5SRichard Henderson # define gen_helper_fxtos                ({ qemu_build_not_reached(); NULL; })
86afb04344SRichard Henderson # define gen_helper_pdist                ({ qemu_build_not_reached(); NULL; })
87668bb9b7SRichard Henderson # define MAXTL_MASK                             0
88af25071cSRichard Henderson #endif
89af25071cSRichard Henderson 
90633c4283SRichard Henderson /* Dynamic PC, must exit to main loop. */
91633c4283SRichard Henderson #define DYNAMIC_PC         1
92633c4283SRichard Henderson /* Dynamic PC, one of two values according to jump_pc[T2]. */
93633c4283SRichard Henderson #define JUMP_PC            2
94633c4283SRichard Henderson /* Dynamic PC, may lookup next TB. */
95633c4283SRichard Henderson #define DYNAMIC_PC_LOOKUP  3
96fcf5ef2aSThomas Huth 
9746bb0137SMark Cave-Ayland #define DISAS_EXIT  DISAS_TARGET_0
9846bb0137SMark Cave-Ayland 
99fcf5ef2aSThomas Huth /* global register indexes */
100fcf5ef2aSThomas Huth static TCGv_ptr cpu_regwptr;
101c9fa8e58SRichard Henderson static TCGv cpu_pc, cpu_npc;
102fcf5ef2aSThomas Huth static TCGv cpu_regs[32];
103fcf5ef2aSThomas Huth static TCGv cpu_y;
104fcf5ef2aSThomas Huth static TCGv cpu_tbr;
105fcf5ef2aSThomas Huth static TCGv cpu_cond;
1062a1905c7SRichard Henderson static TCGv cpu_cc_N;
1072a1905c7SRichard Henderson static TCGv cpu_cc_V;
1082a1905c7SRichard Henderson static TCGv cpu_icc_Z;
1092a1905c7SRichard Henderson static TCGv cpu_icc_C;
110fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
1112a1905c7SRichard Henderson static TCGv cpu_xcc_Z;
1122a1905c7SRichard Henderson static TCGv cpu_xcc_C;
1132a1905c7SRichard Henderson static TCGv_i32 cpu_fprs;
114fcf5ef2aSThomas Huth static TCGv cpu_gsr;
115fcf5ef2aSThomas Huth #else
116af25071cSRichard Henderson # define cpu_fprs               ({ qemu_build_not_reached(); (TCGv)NULL; })
117af25071cSRichard Henderson # define cpu_gsr                ({ qemu_build_not_reached(); (TCGv)NULL; })
118fcf5ef2aSThomas Huth #endif
1192a1905c7SRichard Henderson 
1202a1905c7SRichard Henderson #ifdef TARGET_SPARC64
1212a1905c7SRichard Henderson #define cpu_cc_Z  cpu_xcc_Z
1222a1905c7SRichard Henderson #define cpu_cc_C  cpu_xcc_C
1232a1905c7SRichard Henderson #else
1242a1905c7SRichard Henderson #define cpu_cc_Z  cpu_icc_Z
1252a1905c7SRichard Henderson #define cpu_cc_C  cpu_icc_C
1262a1905c7SRichard Henderson #define cpu_xcc_Z ({ qemu_build_not_reached(); NULL; })
1272a1905c7SRichard Henderson #define cpu_xcc_C ({ qemu_build_not_reached(); NULL; })
1282a1905c7SRichard Henderson #endif
1292a1905c7SRichard Henderson 
1301210a036SRichard Henderson /* Floating point comparison registers */
131d8c5b92fSRichard Henderson static TCGv_i32 cpu_fcc[TARGET_FCCREGS];
132fcf5ef2aSThomas Huth 
133af25071cSRichard Henderson #define env_field_offsetof(X)     offsetof(CPUSPARCState, X)
134af25071cSRichard Henderson #ifdef TARGET_SPARC64
135cd6269f7SRichard Henderson # define env32_field_offsetof(X)  ({ qemu_build_not_reached(); 0; })
136af25071cSRichard Henderson # define env64_field_offsetof(X)  env_field_offsetof(X)
137af25071cSRichard Henderson #else
138cd6269f7SRichard Henderson # define env32_field_offsetof(X)  env_field_offsetof(X)
139af25071cSRichard Henderson # define env64_field_offsetof(X)  ({ qemu_build_not_reached(); 0; })
140af25071cSRichard Henderson #endif
141af25071cSRichard Henderson 
142533f042fSRichard Henderson typedef struct DisasCompare {
143533f042fSRichard Henderson     TCGCond cond;
144533f042fSRichard Henderson     TCGv c1;
145533f042fSRichard Henderson     int c2;
146533f042fSRichard Henderson } DisasCompare;
147533f042fSRichard Henderson 
148186e7890SRichard Henderson typedef struct DisasDelayException {
149186e7890SRichard Henderson     struct DisasDelayException *next;
150186e7890SRichard Henderson     TCGLabel *lab;
151186e7890SRichard Henderson     TCGv_i32 excp;
152186e7890SRichard Henderson     /* Saved state at parent insn. */
153186e7890SRichard Henderson     target_ulong pc;
154186e7890SRichard Henderson     target_ulong npc;
155186e7890SRichard Henderson } DisasDelayException;
156186e7890SRichard Henderson 
157fcf5ef2aSThomas Huth typedef struct DisasContext {
158af00be49SEmilio G. Cota     DisasContextBase base;
159fcf5ef2aSThomas Huth     target_ulong pc;    /* current Program Counter: integer or DYNAMIC_PC */
160fcf5ef2aSThomas Huth     target_ulong npc;   /* next PC: integer or DYNAMIC_PC or JUMP_PC */
161533f042fSRichard Henderson 
162533f042fSRichard Henderson     /* Used when JUMP_PC value is used. */
163533f042fSRichard Henderson     DisasCompare jump;
164533f042fSRichard Henderson     target_ulong jump_pc[2];
165533f042fSRichard Henderson 
166fcf5ef2aSThomas Huth     int mem_idx;
16789527e3aSRichard Henderson     bool cpu_cond_live;
168c9b459aaSArtyom Tarasenko     bool fpu_enabled;
169c9b459aaSArtyom Tarasenko     bool address_mask_32bit;
170c9b459aaSArtyom Tarasenko #ifndef CONFIG_USER_ONLY
171c9b459aaSArtyom Tarasenko     bool supervisor;
172c9b459aaSArtyom Tarasenko #ifdef TARGET_SPARC64
173c9b459aaSArtyom Tarasenko     bool hypervisor;
174c9b459aaSArtyom Tarasenko #endif
175c9b459aaSArtyom Tarasenko #endif
176c9b459aaSArtyom Tarasenko 
177fcf5ef2aSThomas Huth     sparc_def_t *def;
178fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
179fcf5ef2aSThomas Huth     int fprs_dirty;
180fcf5ef2aSThomas Huth     int asi;
181fcf5ef2aSThomas Huth #endif
182186e7890SRichard Henderson     DisasDelayException *delay_excp_list;
183fcf5ef2aSThomas Huth } DisasContext;
184fcf5ef2aSThomas Huth 
185fcf5ef2aSThomas Huth // This function uses non-native bit order
186fcf5ef2aSThomas Huth #define GET_FIELD(X, FROM, TO)                                  \
187fcf5ef2aSThomas Huth     ((X) >> (31 - (TO)) & ((1 << ((TO) - (FROM) + 1)) - 1))
188fcf5ef2aSThomas Huth 
189fcf5ef2aSThomas Huth // This function uses the order in the manuals, i.e. bit 0 is 2^0
190fcf5ef2aSThomas Huth #define GET_FIELD_SP(X, FROM, TO)               \
191fcf5ef2aSThomas Huth     GET_FIELD(X, 31 - (TO), 31 - (FROM))
192fcf5ef2aSThomas Huth 
193fcf5ef2aSThomas Huth #define GET_FIELDs(x,a,b) sign_extend (GET_FIELD(x,a,b), (b) - (a) + 1)
194fcf5ef2aSThomas Huth #define GET_FIELD_SPs(x,a,b) sign_extend (GET_FIELD_SP(x,a,b), ((b) - (a) + 1))
195fcf5ef2aSThomas Huth 
196fcf5ef2aSThomas Huth #define UA2005_HTRAP_MASK 0xff
197fcf5ef2aSThomas Huth #define V8_TRAP_MASK 0x7f
198fcf5ef2aSThomas Huth 
199fcf5ef2aSThomas Huth #define IS_IMM (insn & (1<<13))
200fcf5ef2aSThomas Huth 
2010c2e96c1SRichard Henderson static void gen_update_fprs_dirty(DisasContext *dc, int rd)
202fcf5ef2aSThomas Huth {
203fcf5ef2aSThomas Huth #if defined(TARGET_SPARC64)
204fcf5ef2aSThomas Huth     int bit = (rd < 32) ? 1 : 2;
205fcf5ef2aSThomas Huth     /* If we know we've already set this bit within the TB,
206fcf5ef2aSThomas Huth        we can avoid setting it again.  */
207fcf5ef2aSThomas Huth     if (!(dc->fprs_dirty & bit)) {
208fcf5ef2aSThomas Huth         dc->fprs_dirty |= bit;
209fcf5ef2aSThomas Huth         tcg_gen_ori_i32(cpu_fprs, cpu_fprs, bit);
210fcf5ef2aSThomas Huth     }
211fcf5ef2aSThomas Huth #endif
212fcf5ef2aSThomas Huth }
213fcf5ef2aSThomas Huth 
214fcf5ef2aSThomas Huth /* floating point registers moves */
2151210a036SRichard Henderson 
2161210a036SRichard Henderson static int gen_offset_fpr_F(unsigned int reg)
2171210a036SRichard Henderson {
2181210a036SRichard Henderson     int ret;
2191210a036SRichard Henderson 
2201210a036SRichard Henderson     tcg_debug_assert(reg < 32);
2211210a036SRichard Henderson     ret= offsetof(CPUSPARCState, fpr[reg / 2]);
2221210a036SRichard Henderson     if (reg & 1) {
2231210a036SRichard Henderson         ret += offsetof(CPU_DoubleU, l.lower);
2241210a036SRichard Henderson     } else {
2251210a036SRichard Henderson         ret += offsetof(CPU_DoubleU, l.upper);
2261210a036SRichard Henderson     }
2271210a036SRichard Henderson     return ret;
2281210a036SRichard Henderson }
2291210a036SRichard Henderson 
230fcf5ef2aSThomas Huth static TCGv_i32 gen_load_fpr_F(DisasContext *dc, unsigned int src)
231fcf5ef2aSThomas Huth {
23236ab4623SRichard Henderson     TCGv_i32 ret = tcg_temp_new_i32();
2331210a036SRichard Henderson     tcg_gen_ld_i32(ret, tcg_env, gen_offset_fpr_F(src));
234dc41aa7dSRichard Henderson     return ret;
235fcf5ef2aSThomas Huth }
236fcf5ef2aSThomas Huth 
237fcf5ef2aSThomas Huth static void gen_store_fpr_F(DisasContext *dc, unsigned int dst, TCGv_i32 v)
238fcf5ef2aSThomas Huth {
2391210a036SRichard Henderson     tcg_gen_st_i32(v, tcg_env, gen_offset_fpr_F(dst));
240fcf5ef2aSThomas Huth     gen_update_fprs_dirty(dc, dst);
241fcf5ef2aSThomas Huth }
242fcf5ef2aSThomas Huth 
2431210a036SRichard Henderson static int gen_offset_fpr_D(unsigned int reg)
2441210a036SRichard Henderson {
2451210a036SRichard Henderson     tcg_debug_assert(reg < 64);
2461210a036SRichard Henderson     tcg_debug_assert(reg % 2 == 0);
2471210a036SRichard Henderson     return offsetof(CPUSPARCState, fpr[reg / 2]);
2481210a036SRichard Henderson }
2491210a036SRichard Henderson 
250fcf5ef2aSThomas Huth static TCGv_i64 gen_load_fpr_D(DisasContext *dc, unsigned int src)
251fcf5ef2aSThomas Huth {
2521210a036SRichard Henderson     TCGv_i64 ret = tcg_temp_new_i64();
2531210a036SRichard Henderson     tcg_gen_ld_i64(ret, tcg_env, gen_offset_fpr_D(src));
2541210a036SRichard Henderson     return ret;
255fcf5ef2aSThomas Huth }
256fcf5ef2aSThomas Huth 
257fcf5ef2aSThomas Huth static void gen_store_fpr_D(DisasContext *dc, unsigned int dst, TCGv_i64 v)
258fcf5ef2aSThomas Huth {
2591210a036SRichard Henderson     tcg_gen_st_i64(v, tcg_env, gen_offset_fpr_D(dst));
260fcf5ef2aSThomas Huth     gen_update_fprs_dirty(dc, dst);
261fcf5ef2aSThomas Huth }
262fcf5ef2aSThomas Huth 
26333ec4245SRichard Henderson static TCGv_i128 gen_load_fpr_Q(DisasContext *dc, unsigned int src)
26433ec4245SRichard Henderson {
26533ec4245SRichard Henderson     TCGv_i128 ret = tcg_temp_new_i128();
2661210a036SRichard Henderson     TCGv_i64 h = gen_load_fpr_D(dc, src);
2671210a036SRichard Henderson     TCGv_i64 l = gen_load_fpr_D(dc, src + 2);
26833ec4245SRichard Henderson 
2691210a036SRichard Henderson     tcg_gen_concat_i64_i128(ret, l, h);
27033ec4245SRichard Henderson     return ret;
27133ec4245SRichard Henderson }
27233ec4245SRichard Henderson 
27333ec4245SRichard Henderson static void gen_store_fpr_Q(DisasContext *dc, unsigned int dst, TCGv_i128 v)
27433ec4245SRichard Henderson {
2751210a036SRichard Henderson     TCGv_i64 h = tcg_temp_new_i64();
2761210a036SRichard Henderson     TCGv_i64 l = tcg_temp_new_i64();
2771210a036SRichard Henderson 
2781210a036SRichard Henderson     tcg_gen_extr_i128_i64(l, h, v);
2791210a036SRichard Henderson     gen_store_fpr_D(dc, dst, h);
2801210a036SRichard Henderson     gen_store_fpr_D(dc, dst + 2, l);
28133ec4245SRichard Henderson }
28233ec4245SRichard Henderson 
283fcf5ef2aSThomas Huth /* moves */
284fcf5ef2aSThomas Huth #ifdef CONFIG_USER_ONLY
285fcf5ef2aSThomas Huth #define supervisor(dc) 0
286fcf5ef2aSThomas Huth #define hypervisor(dc) 0
287fcf5ef2aSThomas Huth #else
288fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
289c9b459aaSArtyom Tarasenko #define hypervisor(dc) (dc->hypervisor)
290c9b459aaSArtyom Tarasenko #define supervisor(dc) (dc->supervisor | dc->hypervisor)
291fcf5ef2aSThomas Huth #else
292c9b459aaSArtyom Tarasenko #define supervisor(dc) (dc->supervisor)
293668bb9b7SRichard Henderson #define hypervisor(dc) 0
294fcf5ef2aSThomas Huth #endif
295fcf5ef2aSThomas Huth #endif
296fcf5ef2aSThomas Huth 
297b1bc09eaSRichard Henderson #if !defined(TARGET_SPARC64)
298b1bc09eaSRichard Henderson # define AM_CHECK(dc)  false
299b1bc09eaSRichard Henderson #elif defined(TARGET_ABI32)
300b1bc09eaSRichard Henderson # define AM_CHECK(dc)  true
301b1bc09eaSRichard Henderson #elif defined(CONFIG_USER_ONLY)
302b1bc09eaSRichard Henderson # define AM_CHECK(dc)  false
303fcf5ef2aSThomas Huth #else
304b1bc09eaSRichard Henderson # define AM_CHECK(dc)  ((dc)->address_mask_32bit)
305fcf5ef2aSThomas Huth #endif
306fcf5ef2aSThomas Huth 
3070c2e96c1SRichard Henderson static void gen_address_mask(DisasContext *dc, TCGv addr)
308fcf5ef2aSThomas Huth {
309b1bc09eaSRichard Henderson     if (AM_CHECK(dc)) {
310fcf5ef2aSThomas Huth         tcg_gen_andi_tl(addr, addr, 0xffffffffULL);
311b1bc09eaSRichard Henderson     }
312fcf5ef2aSThomas Huth }
313fcf5ef2aSThomas Huth 
31423ada1b1SRichard Henderson static target_ulong address_mask_i(DisasContext *dc, target_ulong addr)
31523ada1b1SRichard Henderson {
31623ada1b1SRichard Henderson     return AM_CHECK(dc) ? (uint32_t)addr : addr;
31723ada1b1SRichard Henderson }
31823ada1b1SRichard Henderson 
3190c2e96c1SRichard Henderson static TCGv gen_load_gpr(DisasContext *dc, int reg)
320fcf5ef2aSThomas Huth {
321fcf5ef2aSThomas Huth     if (reg > 0) {
322fcf5ef2aSThomas Huth         assert(reg < 32);
323fcf5ef2aSThomas Huth         return cpu_regs[reg];
324fcf5ef2aSThomas Huth     } else {
32552123f14SRichard Henderson         TCGv t = tcg_temp_new();
326fcf5ef2aSThomas Huth         tcg_gen_movi_tl(t, 0);
327fcf5ef2aSThomas Huth         return t;
328fcf5ef2aSThomas Huth     }
329fcf5ef2aSThomas Huth }
330fcf5ef2aSThomas Huth 
3310c2e96c1SRichard Henderson static void gen_store_gpr(DisasContext *dc, int reg, TCGv v)
332fcf5ef2aSThomas Huth {
333fcf5ef2aSThomas Huth     if (reg > 0) {
334fcf5ef2aSThomas Huth         assert(reg < 32);
335fcf5ef2aSThomas Huth         tcg_gen_mov_tl(cpu_regs[reg], v);
336fcf5ef2aSThomas Huth     }
337fcf5ef2aSThomas Huth }
338fcf5ef2aSThomas Huth 
3390c2e96c1SRichard Henderson static TCGv gen_dest_gpr(DisasContext *dc, int reg)
340fcf5ef2aSThomas Huth {
341fcf5ef2aSThomas Huth     if (reg > 0) {
342fcf5ef2aSThomas Huth         assert(reg < 32);
343fcf5ef2aSThomas Huth         return cpu_regs[reg];
344fcf5ef2aSThomas Huth     } else {
34552123f14SRichard Henderson         return tcg_temp_new();
346fcf5ef2aSThomas Huth     }
347fcf5ef2aSThomas Huth }
348fcf5ef2aSThomas Huth 
3495645aa2eSRichard Henderson static bool use_goto_tb(DisasContext *s, target_ulong pc, target_ulong npc)
350fcf5ef2aSThomas Huth {
3515645aa2eSRichard Henderson     return translator_use_goto_tb(&s->base, pc) &&
3525645aa2eSRichard Henderson            translator_use_goto_tb(&s->base, npc);
353fcf5ef2aSThomas Huth }
354fcf5ef2aSThomas Huth 
3555645aa2eSRichard Henderson static void gen_goto_tb(DisasContext *s, int tb_num,
356fcf5ef2aSThomas Huth                         target_ulong pc, target_ulong npc)
357fcf5ef2aSThomas Huth {
358fcf5ef2aSThomas Huth     if (use_goto_tb(s, pc, npc))  {
359fcf5ef2aSThomas Huth         /* jump to same page: we can use a direct jump */
360fcf5ef2aSThomas Huth         tcg_gen_goto_tb(tb_num);
361fcf5ef2aSThomas Huth         tcg_gen_movi_tl(cpu_pc, pc);
362fcf5ef2aSThomas Huth         tcg_gen_movi_tl(cpu_npc, npc);
36307ea28b4SRichard Henderson         tcg_gen_exit_tb(s->base.tb, tb_num);
364fcf5ef2aSThomas Huth     } else {
365f67ccb2fSRichard Henderson         /* jump to another page: we can use an indirect jump */
366fcf5ef2aSThomas Huth         tcg_gen_movi_tl(cpu_pc, pc);
367fcf5ef2aSThomas Huth         tcg_gen_movi_tl(cpu_npc, npc);
368f67ccb2fSRichard Henderson         tcg_gen_lookup_and_goto_ptr();
369fcf5ef2aSThomas Huth     }
370fcf5ef2aSThomas Huth }
371fcf5ef2aSThomas Huth 
372b989ce73SRichard Henderson static TCGv gen_carry32(void)
373fcf5ef2aSThomas Huth {
374b989ce73SRichard Henderson     if (TARGET_LONG_BITS == 64) {
375b989ce73SRichard Henderson         TCGv t = tcg_temp_new();
376b989ce73SRichard Henderson         tcg_gen_extract_tl(t, cpu_icc_C, 32, 1);
377b989ce73SRichard Henderson         return t;
378b989ce73SRichard Henderson     }
379b989ce73SRichard Henderson     return cpu_icc_C;
380fcf5ef2aSThomas Huth }
381fcf5ef2aSThomas Huth 
382b989ce73SRichard Henderson static void gen_op_addcc_int(TCGv dst, TCGv src1, TCGv src2, TCGv cin)
383fcf5ef2aSThomas Huth {
384b989ce73SRichard Henderson     TCGv z = tcg_constant_tl(0);
385fcf5ef2aSThomas Huth 
386b989ce73SRichard Henderson     if (cin) {
387b989ce73SRichard Henderson         tcg_gen_add2_tl(cpu_cc_N, cpu_cc_C, src1, z, cin, z);
388b989ce73SRichard Henderson         tcg_gen_add2_tl(cpu_cc_N, cpu_cc_C, cpu_cc_N, cpu_cc_C, src2, z);
389b989ce73SRichard Henderson     } else {
390b989ce73SRichard Henderson         tcg_gen_add2_tl(cpu_cc_N, cpu_cc_C, src1, z, src2, z);
391b989ce73SRichard Henderson     }
392b989ce73SRichard Henderson     tcg_gen_xor_tl(cpu_cc_Z, src1, src2);
393b989ce73SRichard Henderson     tcg_gen_xor_tl(cpu_cc_V, cpu_cc_N, src2);
394b989ce73SRichard Henderson     tcg_gen_andc_tl(cpu_cc_V, cpu_cc_V, cpu_cc_Z);
395b989ce73SRichard Henderson     if (TARGET_LONG_BITS == 64) {
396b989ce73SRichard Henderson         /*
397b989ce73SRichard Henderson          * Carry-in to bit 32 is result ^ src1 ^ src2.
398b989ce73SRichard Henderson          * We already have the src xor term in Z, from computation of V.
399b989ce73SRichard Henderson          */
400b989ce73SRichard Henderson         tcg_gen_xor_tl(cpu_icc_C, cpu_cc_Z, cpu_cc_N);
401b989ce73SRichard Henderson         tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N);
402b989ce73SRichard Henderson     }
403b989ce73SRichard Henderson     tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N);
404b989ce73SRichard Henderson     tcg_gen_mov_tl(dst, cpu_cc_N);
405b989ce73SRichard Henderson }
406fcf5ef2aSThomas Huth 
407b989ce73SRichard Henderson static void gen_op_addcc(TCGv dst, TCGv src1, TCGv src2)
408b989ce73SRichard Henderson {
409b989ce73SRichard Henderson     gen_op_addcc_int(dst, src1, src2, NULL);
410b989ce73SRichard Henderson }
411fcf5ef2aSThomas Huth 
412b989ce73SRichard Henderson static void gen_op_taddcc(TCGv dst, TCGv src1, TCGv src2)
413b989ce73SRichard Henderson {
414b989ce73SRichard Henderson     TCGv t = tcg_temp_new();
415b989ce73SRichard Henderson 
416b989ce73SRichard Henderson     /* Save the tag bits around modification of dst. */
417b989ce73SRichard Henderson     tcg_gen_or_tl(t, src1, src2);
418b989ce73SRichard Henderson 
419b989ce73SRichard Henderson     gen_op_addcc(dst, src1, src2);
420b989ce73SRichard Henderson 
421b989ce73SRichard Henderson     /* Incorprate tag bits into icc.V */
422b989ce73SRichard Henderson     tcg_gen_andi_tl(t, t, 3);
423b989ce73SRichard Henderson     tcg_gen_neg_tl(t, t);
424b989ce73SRichard Henderson     tcg_gen_ext32u_tl(t, t);
425b989ce73SRichard Henderson     tcg_gen_or_tl(cpu_cc_V, cpu_cc_V, t);
426b989ce73SRichard Henderson }
427b989ce73SRichard Henderson 
428b989ce73SRichard Henderson static void gen_op_addc(TCGv dst, TCGv src1, TCGv src2)
429b989ce73SRichard Henderson {
430b989ce73SRichard Henderson     tcg_gen_add_tl(dst, src1, src2);
431b989ce73SRichard Henderson     tcg_gen_add_tl(dst, dst, gen_carry32());
432b989ce73SRichard Henderson }
433b989ce73SRichard Henderson 
434b989ce73SRichard Henderson static void gen_op_addccc(TCGv dst, TCGv src1, TCGv src2)
435b989ce73SRichard Henderson {
436b989ce73SRichard Henderson     gen_op_addcc_int(dst, src1, src2, gen_carry32());
437fcf5ef2aSThomas Huth }
438fcf5ef2aSThomas Huth 
439015fc6fcSRichard Henderson static void gen_op_addxc(TCGv dst, TCGv src1, TCGv src2)
440015fc6fcSRichard Henderson {
441015fc6fcSRichard Henderson     tcg_gen_add_tl(dst, src1, src2);
442015fc6fcSRichard Henderson     tcg_gen_add_tl(dst, dst, cpu_cc_C);
443015fc6fcSRichard Henderson }
444015fc6fcSRichard Henderson 
445015fc6fcSRichard Henderson static void gen_op_addxccc(TCGv dst, TCGv src1, TCGv src2)
446015fc6fcSRichard Henderson {
447015fc6fcSRichard Henderson     gen_op_addcc_int(dst, src1, src2, cpu_cc_C);
448015fc6fcSRichard Henderson }
449015fc6fcSRichard Henderson 
450f828df74SRichard Henderson static void gen_op_subcc_int(TCGv dst, TCGv src1, TCGv src2, TCGv cin)
451fcf5ef2aSThomas Huth {
452f828df74SRichard Henderson     TCGv z = tcg_constant_tl(0);
453fcf5ef2aSThomas Huth 
454f828df74SRichard Henderson     if (cin) {
455f828df74SRichard Henderson         tcg_gen_sub2_tl(cpu_cc_N, cpu_cc_C, src1, z, cin, z);
456f828df74SRichard Henderson         tcg_gen_sub2_tl(cpu_cc_N, cpu_cc_C, cpu_cc_N, cpu_cc_C, src2, z);
457f828df74SRichard Henderson     } else {
458f828df74SRichard Henderson         tcg_gen_sub2_tl(cpu_cc_N, cpu_cc_C, src1, z, src2, z);
459f828df74SRichard Henderson     }
460f828df74SRichard Henderson     tcg_gen_neg_tl(cpu_cc_C, cpu_cc_C);
461f828df74SRichard Henderson     tcg_gen_xor_tl(cpu_cc_Z, src1, src2);
462f828df74SRichard Henderson     tcg_gen_xor_tl(cpu_cc_V, cpu_cc_N, src1);
463f828df74SRichard Henderson     tcg_gen_and_tl(cpu_cc_V, cpu_cc_V, cpu_cc_Z);
464f828df74SRichard Henderson #ifdef TARGET_SPARC64
465f828df74SRichard Henderson     tcg_gen_xor_tl(cpu_icc_C, cpu_cc_Z, cpu_cc_N);
466f828df74SRichard Henderson     tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N);
467fcf5ef2aSThomas Huth #endif
468f828df74SRichard Henderson     tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N);
469f828df74SRichard Henderson     tcg_gen_mov_tl(dst, cpu_cc_N);
470fcf5ef2aSThomas Huth }
471fcf5ef2aSThomas Huth 
472f828df74SRichard Henderson static void gen_op_subcc(TCGv dst, TCGv src1, TCGv src2)
473fcf5ef2aSThomas Huth {
474f828df74SRichard Henderson     gen_op_subcc_int(dst, src1, src2, NULL);
475fcf5ef2aSThomas Huth }
476fcf5ef2aSThomas Huth 
477f828df74SRichard Henderson static void gen_op_tsubcc(TCGv dst, TCGv src1, TCGv src2)
478fcf5ef2aSThomas Huth {
479f828df74SRichard Henderson     TCGv t = tcg_temp_new();
480fcf5ef2aSThomas Huth 
481f828df74SRichard Henderson     /* Save the tag bits around modification of dst. */
482f828df74SRichard Henderson     tcg_gen_or_tl(t, src1, src2);
483fcf5ef2aSThomas Huth 
484f828df74SRichard Henderson     gen_op_subcc(dst, src1, src2);
485f828df74SRichard Henderson 
486f828df74SRichard Henderson     /* Incorprate tag bits into icc.V */
487f828df74SRichard Henderson     tcg_gen_andi_tl(t, t, 3);
488f828df74SRichard Henderson     tcg_gen_neg_tl(t, t);
489f828df74SRichard Henderson     tcg_gen_ext32u_tl(t, t);
490f828df74SRichard Henderson     tcg_gen_or_tl(cpu_cc_V, cpu_cc_V, t);
491f828df74SRichard Henderson }
492f828df74SRichard Henderson 
493f828df74SRichard Henderson static void gen_op_subc(TCGv dst, TCGv src1, TCGv src2)
494f828df74SRichard Henderson {
495fcf5ef2aSThomas Huth     tcg_gen_sub_tl(dst, src1, src2);
496f828df74SRichard Henderson     tcg_gen_sub_tl(dst, dst, gen_carry32());
497fcf5ef2aSThomas Huth }
498fcf5ef2aSThomas Huth 
499f828df74SRichard Henderson static void gen_op_subccc(TCGv dst, TCGv src1, TCGv src2)
500dfebb950SRichard Henderson {
501f828df74SRichard Henderson     gen_op_subcc_int(dst, src1, src2, gen_carry32());
502dfebb950SRichard Henderson }
503dfebb950SRichard Henderson 
5040c2e96c1SRichard Henderson static void gen_op_mulscc(TCGv dst, TCGv src1, TCGv src2)
505fcf5ef2aSThomas Huth {
506b989ce73SRichard Henderson     TCGv zero = tcg_constant_tl(0);
50750280618SRichard Henderson     TCGv one = tcg_constant_tl(1);
508b989ce73SRichard Henderson     TCGv t_src1 = tcg_temp_new();
509b989ce73SRichard Henderson     TCGv t_src2 = tcg_temp_new();
510b989ce73SRichard Henderson     TCGv t0 = tcg_temp_new();
511fcf5ef2aSThomas Huth 
512b989ce73SRichard Henderson     tcg_gen_ext32u_tl(t_src1, src1);
513b989ce73SRichard Henderson     tcg_gen_ext32u_tl(t_src2, src2);
514fcf5ef2aSThomas Huth 
515b989ce73SRichard Henderson     /*
516b989ce73SRichard Henderson      * if (!(env->y & 1))
517b989ce73SRichard Henderson      *   src2 = 0;
518fcf5ef2aSThomas Huth      */
51950280618SRichard Henderson     tcg_gen_movcond_tl(TCG_COND_TSTEQ, t_src2, cpu_y, one, zero, t_src2);
520fcf5ef2aSThomas Huth 
521b989ce73SRichard Henderson     /*
522b989ce73SRichard Henderson      * b2 = src1 & 1;
523b989ce73SRichard Henderson      * y = (b2 << 31) | (y >> 1);
524b989ce73SRichard Henderson      */
5250b1183e3SPhilippe Mathieu-Daudé     tcg_gen_extract_tl(t0, cpu_y, 1, 31);
526b989ce73SRichard Henderson     tcg_gen_deposit_tl(cpu_y, t0, src1, 31, 1);
527fcf5ef2aSThomas Huth 
528fcf5ef2aSThomas Huth     // b1 = N ^ V;
5292a1905c7SRichard Henderson     tcg_gen_xor_tl(t0, cpu_cc_N, cpu_cc_V);
530fcf5ef2aSThomas Huth 
531b989ce73SRichard Henderson     /*
532b989ce73SRichard Henderson      * src1 = (b1 << 31) | (src1 >> 1)
533b989ce73SRichard Henderson      */
5342a1905c7SRichard Henderson     tcg_gen_andi_tl(t0, t0, 1u << 31);
535b989ce73SRichard Henderson     tcg_gen_shri_tl(t_src1, t_src1, 1);
536b989ce73SRichard Henderson     tcg_gen_or_tl(t_src1, t_src1, t0);
537fcf5ef2aSThomas Huth 
538b989ce73SRichard Henderson     gen_op_addcc(dst, t_src1, t_src2);
539fcf5ef2aSThomas Huth }
540fcf5ef2aSThomas Huth 
5410c2e96c1SRichard Henderson static void gen_op_multiply(TCGv dst, TCGv src1, TCGv src2, int sign_ext)
542fcf5ef2aSThomas Huth {
543fcf5ef2aSThomas Huth #if TARGET_LONG_BITS == 32
544fcf5ef2aSThomas Huth     if (sign_ext) {
545fcf5ef2aSThomas Huth         tcg_gen_muls2_tl(dst, cpu_y, src1, src2);
546fcf5ef2aSThomas Huth     } else {
547fcf5ef2aSThomas Huth         tcg_gen_mulu2_tl(dst, cpu_y, src1, src2);
548fcf5ef2aSThomas Huth     }
549fcf5ef2aSThomas Huth #else
550fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new_i64();
551fcf5ef2aSThomas Huth     TCGv t1 = tcg_temp_new_i64();
552fcf5ef2aSThomas Huth 
553fcf5ef2aSThomas Huth     if (sign_ext) {
554fcf5ef2aSThomas Huth         tcg_gen_ext32s_i64(t0, src1);
555fcf5ef2aSThomas Huth         tcg_gen_ext32s_i64(t1, src2);
556fcf5ef2aSThomas Huth     } else {
557fcf5ef2aSThomas Huth         tcg_gen_ext32u_i64(t0, src1);
558fcf5ef2aSThomas Huth         tcg_gen_ext32u_i64(t1, src2);
559fcf5ef2aSThomas Huth     }
560fcf5ef2aSThomas Huth 
561fcf5ef2aSThomas Huth     tcg_gen_mul_i64(dst, t0, t1);
562fcf5ef2aSThomas Huth     tcg_gen_shri_i64(cpu_y, dst, 32);
563fcf5ef2aSThomas Huth #endif
564fcf5ef2aSThomas Huth }
565fcf5ef2aSThomas Huth 
5660c2e96c1SRichard Henderson static void gen_op_umul(TCGv dst, TCGv src1, TCGv src2)
567fcf5ef2aSThomas Huth {
568fcf5ef2aSThomas Huth     /* zero-extend truncated operands before multiplication */
569fcf5ef2aSThomas Huth     gen_op_multiply(dst, src1, src2, 0);
570fcf5ef2aSThomas Huth }
571fcf5ef2aSThomas Huth 
5720c2e96c1SRichard Henderson static void gen_op_smul(TCGv dst, TCGv src1, TCGv src2)
573fcf5ef2aSThomas Huth {
574fcf5ef2aSThomas Huth     /* sign-extend truncated operands before multiplication */
575fcf5ef2aSThomas Huth     gen_op_multiply(dst, src1, src2, 1);
576fcf5ef2aSThomas Huth }
577fcf5ef2aSThomas Huth 
578c2636853SRichard Henderson static void gen_op_sdiv(TCGv dst, TCGv src1, TCGv src2)
579c2636853SRichard Henderson {
58013260103SRichard Henderson #ifdef TARGET_SPARC64
581c2636853SRichard Henderson     gen_helper_sdiv(dst, tcg_env, src1, src2);
58213260103SRichard Henderson     tcg_gen_ext32s_tl(dst, dst);
58313260103SRichard Henderson #else
58413260103SRichard Henderson     TCGv_i64 t64 = tcg_temp_new_i64();
58513260103SRichard Henderson     gen_helper_sdiv(t64, tcg_env, src1, src2);
58613260103SRichard Henderson     tcg_gen_trunc_i64_tl(dst, t64);
58713260103SRichard Henderson #endif
588c2636853SRichard Henderson }
589c2636853SRichard Henderson 
590c2636853SRichard Henderson static void gen_op_udivcc(TCGv dst, TCGv src1, TCGv src2)
591c2636853SRichard Henderson {
59213260103SRichard Henderson     TCGv_i64 t64;
59313260103SRichard Henderson 
59413260103SRichard Henderson #ifdef TARGET_SPARC64
59513260103SRichard Henderson     t64 = cpu_cc_V;
59613260103SRichard Henderson #else
59713260103SRichard Henderson     t64 = tcg_temp_new_i64();
59813260103SRichard Henderson #endif
59913260103SRichard Henderson 
60013260103SRichard Henderson     gen_helper_udiv(t64, tcg_env, src1, src2);
60113260103SRichard Henderson 
60213260103SRichard Henderson #ifdef TARGET_SPARC64
60313260103SRichard Henderson     tcg_gen_ext32u_tl(cpu_cc_N, t64);
60413260103SRichard Henderson     tcg_gen_shri_tl(cpu_cc_V, t64, 32);
60513260103SRichard Henderson     tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N);
60613260103SRichard Henderson     tcg_gen_movi_tl(cpu_icc_C, 0);
60713260103SRichard Henderson #else
60813260103SRichard Henderson     tcg_gen_extr_i64_tl(cpu_cc_N, cpu_cc_V, t64);
60913260103SRichard Henderson #endif
61013260103SRichard Henderson     tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N);
61113260103SRichard Henderson     tcg_gen_movi_tl(cpu_cc_C, 0);
61213260103SRichard Henderson     tcg_gen_mov_tl(dst, cpu_cc_N);
613c2636853SRichard Henderson }
614c2636853SRichard Henderson 
615c2636853SRichard Henderson static void gen_op_sdivcc(TCGv dst, TCGv src1, TCGv src2)
616c2636853SRichard Henderson {
61713260103SRichard Henderson     TCGv_i64 t64;
61813260103SRichard Henderson 
61913260103SRichard Henderson #ifdef TARGET_SPARC64
62013260103SRichard Henderson     t64 = cpu_cc_V;
62113260103SRichard Henderson #else
62213260103SRichard Henderson     t64 = tcg_temp_new_i64();
62313260103SRichard Henderson #endif
62413260103SRichard Henderson 
62513260103SRichard Henderson     gen_helper_sdiv(t64, tcg_env, src1, src2);
62613260103SRichard Henderson 
62713260103SRichard Henderson #ifdef TARGET_SPARC64
62813260103SRichard Henderson     tcg_gen_ext32s_tl(cpu_cc_N, t64);
62913260103SRichard Henderson     tcg_gen_shri_tl(cpu_cc_V, t64, 32);
63013260103SRichard Henderson     tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N);
63113260103SRichard Henderson     tcg_gen_movi_tl(cpu_icc_C, 0);
63213260103SRichard Henderson #else
63313260103SRichard Henderson     tcg_gen_extr_i64_tl(cpu_cc_N, cpu_cc_V, t64);
63413260103SRichard Henderson #endif
63513260103SRichard Henderson     tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N);
63613260103SRichard Henderson     tcg_gen_movi_tl(cpu_cc_C, 0);
63713260103SRichard Henderson     tcg_gen_mov_tl(dst, cpu_cc_N);
638c2636853SRichard Henderson }
639c2636853SRichard Henderson 
640a9aba13dSRichard Henderson static void gen_op_taddcctv(TCGv dst, TCGv src1, TCGv src2)
641a9aba13dSRichard Henderson {
642a9aba13dSRichard Henderson     gen_helper_taddcctv(dst, tcg_env, src1, src2);
643a9aba13dSRichard Henderson }
644a9aba13dSRichard Henderson 
645a9aba13dSRichard Henderson static void gen_op_tsubcctv(TCGv dst, TCGv src1, TCGv src2)
646a9aba13dSRichard Henderson {
647a9aba13dSRichard Henderson     gen_helper_tsubcctv(dst, tcg_env, src1, src2);
648a9aba13dSRichard Henderson }
649a9aba13dSRichard Henderson 
6509c6ec5bcSRichard Henderson static void gen_op_popc(TCGv dst, TCGv src1, TCGv src2)
6519c6ec5bcSRichard Henderson {
6529c6ec5bcSRichard Henderson     tcg_gen_ctpop_tl(dst, src2);
6539c6ec5bcSRichard Henderson }
6549c6ec5bcSRichard Henderson 
65545bfed3bSRichard Henderson #ifndef TARGET_SPARC64
65645bfed3bSRichard Henderson static void gen_helper_array8(TCGv dst, TCGv src1, TCGv src2)
65745bfed3bSRichard Henderson {
65845bfed3bSRichard Henderson     g_assert_not_reached();
65945bfed3bSRichard Henderson }
66045bfed3bSRichard Henderson #endif
66145bfed3bSRichard Henderson 
66245bfed3bSRichard Henderson static void gen_op_array16(TCGv dst, TCGv src1, TCGv src2)
66345bfed3bSRichard Henderson {
66445bfed3bSRichard Henderson     gen_helper_array8(dst, src1, src2);
66545bfed3bSRichard Henderson     tcg_gen_shli_tl(dst, dst, 1);
66645bfed3bSRichard Henderson }
66745bfed3bSRichard Henderson 
66845bfed3bSRichard Henderson static void gen_op_array32(TCGv dst, TCGv src1, TCGv src2)
66945bfed3bSRichard Henderson {
67045bfed3bSRichard Henderson     gen_helper_array8(dst, src1, src2);
67145bfed3bSRichard Henderson     tcg_gen_shli_tl(dst, dst, 2);
67245bfed3bSRichard Henderson }
67345bfed3bSRichard Henderson 
6742f722641SRichard Henderson static void gen_op_fpack16(TCGv_i32 dst, TCGv_i64 src)
6752f722641SRichard Henderson {
6762f722641SRichard Henderson #ifdef TARGET_SPARC64
6772f722641SRichard Henderson     gen_helper_fpack16(dst, cpu_gsr, src);
6782f722641SRichard Henderson #else
6792f722641SRichard Henderson     g_assert_not_reached();
6802f722641SRichard Henderson #endif
6812f722641SRichard Henderson }
6822f722641SRichard Henderson 
6832f722641SRichard Henderson static void gen_op_fpackfix(TCGv_i32 dst, TCGv_i64 src)
6842f722641SRichard Henderson {
6852f722641SRichard Henderson #ifdef TARGET_SPARC64
6862f722641SRichard Henderson     gen_helper_fpackfix(dst, cpu_gsr, src);
6872f722641SRichard Henderson #else
6882f722641SRichard Henderson     g_assert_not_reached();
6892f722641SRichard Henderson #endif
6902f722641SRichard Henderson }
6912f722641SRichard Henderson 
6924b6edc0aSRichard Henderson static void gen_op_fpack32(TCGv_i64 dst, TCGv_i64 src1, TCGv_i64 src2)
6934b6edc0aSRichard Henderson {
6944b6edc0aSRichard Henderson #ifdef TARGET_SPARC64
6954b6edc0aSRichard Henderson     gen_helper_fpack32(dst, cpu_gsr, src1, src2);
6964b6edc0aSRichard Henderson #else
6974b6edc0aSRichard Henderson     g_assert_not_reached();
6984b6edc0aSRichard Henderson #endif
6994b6edc0aSRichard Henderson }
7004b6edc0aSRichard Henderson 
7014b6edc0aSRichard Henderson static void gen_op_faligndata(TCGv_i64 dst, TCGv_i64 s1, TCGv_i64 s2)
7024b6edc0aSRichard Henderson {
7034b6edc0aSRichard Henderson #ifdef TARGET_SPARC64
7044b6edc0aSRichard Henderson     TCGv t1, t2, shift;
7054b6edc0aSRichard Henderson 
7064b6edc0aSRichard Henderson     t1 = tcg_temp_new();
7074b6edc0aSRichard Henderson     t2 = tcg_temp_new();
7084b6edc0aSRichard Henderson     shift = tcg_temp_new();
7094b6edc0aSRichard Henderson 
7104b6edc0aSRichard Henderson     tcg_gen_andi_tl(shift, cpu_gsr, 7);
7114b6edc0aSRichard Henderson     tcg_gen_shli_tl(shift, shift, 3);
7124b6edc0aSRichard Henderson     tcg_gen_shl_tl(t1, s1, shift);
7134b6edc0aSRichard Henderson 
7144b6edc0aSRichard Henderson     /*
7154b6edc0aSRichard Henderson      * A shift of 64 does not produce 0 in TCG.  Divide this into a
7164b6edc0aSRichard Henderson      * shift of (up to 63) followed by a constant shift of 1.
7174b6edc0aSRichard Henderson      */
7184b6edc0aSRichard Henderson     tcg_gen_xori_tl(shift, shift, 63);
7194b6edc0aSRichard Henderson     tcg_gen_shr_tl(t2, s2, shift);
7204b6edc0aSRichard Henderson     tcg_gen_shri_tl(t2, t2, 1);
7214b6edc0aSRichard Henderson 
7224b6edc0aSRichard Henderson     tcg_gen_or_tl(dst, t1, t2);
7234b6edc0aSRichard Henderson #else
7244b6edc0aSRichard Henderson     g_assert_not_reached();
7254b6edc0aSRichard Henderson #endif
7264b6edc0aSRichard Henderson }
7274b6edc0aSRichard Henderson 
7284b6edc0aSRichard Henderson static void gen_op_bshuffle(TCGv_i64 dst, TCGv_i64 src1, TCGv_i64 src2)
7294b6edc0aSRichard Henderson {
7304b6edc0aSRichard Henderson #ifdef TARGET_SPARC64
7314b6edc0aSRichard Henderson     gen_helper_bshuffle(dst, cpu_gsr, src1, src2);
7324b6edc0aSRichard Henderson #else
7334b6edc0aSRichard Henderson     g_assert_not_reached();
7344b6edc0aSRichard Henderson #endif
7354b6edc0aSRichard Henderson }
7364b6edc0aSRichard Henderson 
737a859602cSRichard Henderson static void gen_op_fmul8x16al(TCGv_i64 dst, TCGv_i32 src1, TCGv_i32 src2)
738a859602cSRichard Henderson {
739a859602cSRichard Henderson     tcg_gen_ext16s_i32(src2, src2);
740a859602cSRichard Henderson     gen_helper_fmul8x16a(dst, src1, src2);
741a859602cSRichard Henderson }
742a859602cSRichard Henderson 
743a859602cSRichard Henderson static void gen_op_fmul8x16au(TCGv_i64 dst, TCGv_i32 src1, TCGv_i32 src2)
744a859602cSRichard Henderson {
745a859602cSRichard Henderson     tcg_gen_sari_i32(src2, src2, 16);
746a859602cSRichard Henderson     gen_helper_fmul8x16a(dst, src1, src2);
747a859602cSRichard Henderson }
748a859602cSRichard Henderson 
749be8998e0SRichard Henderson static void gen_op_fmuld8ulx16(TCGv_i64 dst, TCGv_i32 src1, TCGv_i32 src2)
750be8998e0SRichard Henderson {
751be8998e0SRichard Henderson     TCGv_i32 t0 = tcg_temp_new_i32();
752be8998e0SRichard Henderson     TCGv_i32 t1 = tcg_temp_new_i32();
753be8998e0SRichard Henderson     TCGv_i32 t2 = tcg_temp_new_i32();
754be8998e0SRichard Henderson 
755be8998e0SRichard Henderson     tcg_gen_ext8u_i32(t0, src1);
756be8998e0SRichard Henderson     tcg_gen_ext16s_i32(t1, src2);
757be8998e0SRichard Henderson     tcg_gen_mul_i32(t0, t0, t1);
758be8998e0SRichard Henderson 
759be8998e0SRichard Henderson     tcg_gen_extract_i32(t1, src1, 16, 8);
760be8998e0SRichard Henderson     tcg_gen_sextract_i32(t2, src2, 16, 16);
761be8998e0SRichard Henderson     tcg_gen_mul_i32(t1, t1, t2);
762be8998e0SRichard Henderson 
763be8998e0SRichard Henderson     tcg_gen_concat_i32_i64(dst, t0, t1);
764be8998e0SRichard Henderson }
765be8998e0SRichard Henderson 
766be8998e0SRichard Henderson static void gen_op_fmuld8sux16(TCGv_i64 dst, TCGv_i32 src1, TCGv_i32 src2)
767be8998e0SRichard Henderson {
768be8998e0SRichard Henderson     TCGv_i32 t0 = tcg_temp_new_i32();
769be8998e0SRichard Henderson     TCGv_i32 t1 = tcg_temp_new_i32();
770be8998e0SRichard Henderson     TCGv_i32 t2 = tcg_temp_new_i32();
771be8998e0SRichard Henderson 
772be8998e0SRichard Henderson     /*
773be8998e0SRichard Henderson      * The insn description talks about extracting the upper 8 bits
774be8998e0SRichard Henderson      * of the signed 16-bit input rs1, performing the multiply, then
775be8998e0SRichard Henderson      * shifting left by 8 bits.  Instead, zap the lower 8 bits of
776be8998e0SRichard Henderson      * the rs1 input, which avoids the need for two shifts.
777be8998e0SRichard Henderson      */
778be8998e0SRichard Henderson     tcg_gen_ext16s_i32(t0, src1);
779be8998e0SRichard Henderson     tcg_gen_andi_i32(t0, t0, ~0xff);
780be8998e0SRichard Henderson     tcg_gen_ext16s_i32(t1, src2);
781be8998e0SRichard Henderson     tcg_gen_mul_i32(t0, t0, t1);
782be8998e0SRichard Henderson 
783be8998e0SRichard Henderson     tcg_gen_sextract_i32(t1, src1, 16, 16);
784be8998e0SRichard Henderson     tcg_gen_andi_i32(t1, t1, ~0xff);
785be8998e0SRichard Henderson     tcg_gen_sextract_i32(t2, src2, 16, 16);
786be8998e0SRichard Henderson     tcg_gen_mul_i32(t1, t1, t2);
787be8998e0SRichard Henderson 
788be8998e0SRichard Henderson     tcg_gen_concat_i32_i64(dst, t0, t1);
789be8998e0SRichard Henderson }
790be8998e0SRichard Henderson 
7917837185eSRichard Henderson #ifdef TARGET_SPARC64
7927837185eSRichard Henderson static void gen_vec_fchksm16(unsigned vece, TCGv_vec dst,
7937837185eSRichard Henderson                              TCGv_vec src1, TCGv_vec src2)
7947837185eSRichard Henderson {
7957837185eSRichard Henderson     TCGv_vec a = tcg_temp_new_vec_matching(dst);
7967837185eSRichard Henderson     TCGv_vec c = tcg_temp_new_vec_matching(dst);
7977837185eSRichard Henderson 
7987837185eSRichard Henderson     tcg_gen_add_vec(vece, a, src1, src2);
7997837185eSRichard Henderson     tcg_gen_cmp_vec(TCG_COND_LTU, vece, c, a, src1);
8007837185eSRichard Henderson     /* Vector cmp produces -1 for true, so subtract to add carry. */
8017837185eSRichard Henderson     tcg_gen_sub_vec(vece, dst, a, c);
8027837185eSRichard Henderson }
8037837185eSRichard Henderson 
8047837185eSRichard Henderson static void gen_op_fchksm16(unsigned vece, uint32_t dofs, uint32_t aofs,
8057837185eSRichard Henderson                             uint32_t bofs, uint32_t oprsz, uint32_t maxsz)
8067837185eSRichard Henderson {
8077837185eSRichard Henderson     static const TCGOpcode vecop_list[] = {
8087837185eSRichard Henderson         INDEX_op_cmp_vec, INDEX_op_add_vec, INDEX_op_sub_vec,
8097837185eSRichard Henderson     };
8107837185eSRichard Henderson     static const GVecGen3 op = {
8117837185eSRichard Henderson         .fni8 = gen_helper_fchksm16,
8127837185eSRichard Henderson         .fniv = gen_vec_fchksm16,
8137837185eSRichard Henderson         .opt_opc = vecop_list,
8147837185eSRichard Henderson         .vece = MO_16,
8157837185eSRichard Henderson     };
8167837185eSRichard Henderson     tcg_gen_gvec_3(dofs, aofs, bofs, oprsz, maxsz, &op);
8177837185eSRichard Henderson }
818*d6ff1ccbSRichard Henderson 
819*d6ff1ccbSRichard Henderson static void gen_vec_fmean16(unsigned vece, TCGv_vec dst,
820*d6ff1ccbSRichard Henderson                             TCGv_vec src1, TCGv_vec src2)
821*d6ff1ccbSRichard Henderson {
822*d6ff1ccbSRichard Henderson     TCGv_vec t = tcg_temp_new_vec_matching(dst);
823*d6ff1ccbSRichard Henderson 
824*d6ff1ccbSRichard Henderson     tcg_gen_or_vec(vece, t, src1, src2);
825*d6ff1ccbSRichard Henderson     tcg_gen_and_vec(vece, t, t, tcg_constant_vec_matching(dst, vece, 1));
826*d6ff1ccbSRichard Henderson     tcg_gen_sari_vec(vece, src1, src1, 1);
827*d6ff1ccbSRichard Henderson     tcg_gen_sari_vec(vece, src2, src2, 1);
828*d6ff1ccbSRichard Henderson     tcg_gen_add_vec(vece, dst, src1, src2);
829*d6ff1ccbSRichard Henderson     tcg_gen_add_vec(vece, dst, dst, t);
830*d6ff1ccbSRichard Henderson }
831*d6ff1ccbSRichard Henderson 
832*d6ff1ccbSRichard Henderson static void gen_op_fmean16(unsigned vece, uint32_t dofs, uint32_t aofs,
833*d6ff1ccbSRichard Henderson                            uint32_t bofs, uint32_t oprsz, uint32_t maxsz)
834*d6ff1ccbSRichard Henderson {
835*d6ff1ccbSRichard Henderson     static const TCGOpcode vecop_list[] = {
836*d6ff1ccbSRichard Henderson         INDEX_op_add_vec, INDEX_op_sari_vec,
837*d6ff1ccbSRichard Henderson     };
838*d6ff1ccbSRichard Henderson     static const GVecGen3 op = {
839*d6ff1ccbSRichard Henderson         .fni8 = gen_helper_fmean16,
840*d6ff1ccbSRichard Henderson         .fniv = gen_vec_fmean16,
841*d6ff1ccbSRichard Henderson         .opt_opc = vecop_list,
842*d6ff1ccbSRichard Henderson         .vece = MO_16,
843*d6ff1ccbSRichard Henderson     };
844*d6ff1ccbSRichard Henderson     tcg_gen_gvec_3(dofs, aofs, bofs, oprsz, maxsz, &op);
845*d6ff1ccbSRichard Henderson }
8467837185eSRichard Henderson #else
8477837185eSRichard Henderson #define gen_op_fchksm16   ({ qemu_build_not_reached(); NULL; })
848*d6ff1ccbSRichard Henderson #define gen_op_fmean16    ({ qemu_build_not_reached(); NULL; })
8497837185eSRichard Henderson #endif
8507837185eSRichard Henderson 
85189527e3aSRichard Henderson static void finishing_insn(DisasContext *dc)
85289527e3aSRichard Henderson {
85389527e3aSRichard Henderson     /*
85489527e3aSRichard Henderson      * From here, there is no future path through an unwinding exception.
85589527e3aSRichard Henderson      * If the current insn cannot raise an exception, the computation of
85689527e3aSRichard Henderson      * cpu_cond may be able to be elided.
85789527e3aSRichard Henderson      */
85889527e3aSRichard Henderson     if (dc->cpu_cond_live) {
85989527e3aSRichard Henderson         tcg_gen_discard_tl(cpu_cond);
86089527e3aSRichard Henderson         dc->cpu_cond_live = false;
86189527e3aSRichard Henderson     }
86289527e3aSRichard Henderson }
86389527e3aSRichard Henderson 
8640c2e96c1SRichard Henderson static void gen_generic_branch(DisasContext *dc)
865fcf5ef2aSThomas Huth {
86600ab7e61SRichard Henderson     TCGv npc0 = tcg_constant_tl(dc->jump_pc[0]);
86700ab7e61SRichard Henderson     TCGv npc1 = tcg_constant_tl(dc->jump_pc[1]);
868533f042fSRichard Henderson     TCGv c2 = tcg_constant_tl(dc->jump.c2);
869fcf5ef2aSThomas Huth 
870533f042fSRichard Henderson     tcg_gen_movcond_tl(dc->jump.cond, cpu_npc, dc->jump.c1, c2, npc0, npc1);
871fcf5ef2aSThomas Huth }
872fcf5ef2aSThomas Huth 
873fcf5ef2aSThomas Huth /* call this function before using the condition register as it may
874fcf5ef2aSThomas Huth    have been set for a jump */
8750c2e96c1SRichard Henderson static void flush_cond(DisasContext *dc)
876fcf5ef2aSThomas Huth {
877fcf5ef2aSThomas Huth     if (dc->npc == JUMP_PC) {
878fcf5ef2aSThomas Huth         gen_generic_branch(dc);
87999c82c47SRichard Henderson         dc->npc = DYNAMIC_PC_LOOKUP;
880fcf5ef2aSThomas Huth     }
881fcf5ef2aSThomas Huth }
882fcf5ef2aSThomas Huth 
8830c2e96c1SRichard Henderson static void save_npc(DisasContext *dc)
884fcf5ef2aSThomas Huth {
885633c4283SRichard Henderson     if (dc->npc & 3) {
886633c4283SRichard Henderson         switch (dc->npc) {
887633c4283SRichard Henderson         case JUMP_PC:
888fcf5ef2aSThomas Huth             gen_generic_branch(dc);
88999c82c47SRichard Henderson             dc->npc = DYNAMIC_PC_LOOKUP;
890633c4283SRichard Henderson             break;
891633c4283SRichard Henderson         case DYNAMIC_PC:
892633c4283SRichard Henderson         case DYNAMIC_PC_LOOKUP:
893633c4283SRichard Henderson             break;
894633c4283SRichard Henderson         default:
895633c4283SRichard Henderson             g_assert_not_reached();
896633c4283SRichard Henderson         }
897633c4283SRichard Henderson     } else {
898fcf5ef2aSThomas Huth         tcg_gen_movi_tl(cpu_npc, dc->npc);
899fcf5ef2aSThomas Huth     }
900fcf5ef2aSThomas Huth }
901fcf5ef2aSThomas Huth 
9020c2e96c1SRichard Henderson static void save_state(DisasContext *dc)
903fcf5ef2aSThomas Huth {
904fcf5ef2aSThomas Huth     tcg_gen_movi_tl(cpu_pc, dc->pc);
905fcf5ef2aSThomas Huth     save_npc(dc);
906fcf5ef2aSThomas Huth }
907fcf5ef2aSThomas Huth 
908fcf5ef2aSThomas Huth static void gen_exception(DisasContext *dc, int which)
909fcf5ef2aSThomas Huth {
91089527e3aSRichard Henderson     finishing_insn(dc);
911fcf5ef2aSThomas Huth     save_state(dc);
912ad75a51eSRichard Henderson     gen_helper_raise_exception(tcg_env, tcg_constant_i32(which));
913af00be49SEmilio G. Cota     dc->base.is_jmp = DISAS_NORETURN;
914fcf5ef2aSThomas Huth }
915fcf5ef2aSThomas Huth 
916186e7890SRichard Henderson static TCGLabel *delay_exceptionv(DisasContext *dc, TCGv_i32 excp)
917fcf5ef2aSThomas Huth {
918186e7890SRichard Henderson     DisasDelayException *e = g_new0(DisasDelayException, 1);
919186e7890SRichard Henderson 
920186e7890SRichard Henderson     e->next = dc->delay_excp_list;
921186e7890SRichard Henderson     dc->delay_excp_list = e;
922186e7890SRichard Henderson 
923186e7890SRichard Henderson     e->lab = gen_new_label();
924186e7890SRichard Henderson     e->excp = excp;
925186e7890SRichard Henderson     e->pc = dc->pc;
926186e7890SRichard Henderson     /* Caller must have used flush_cond before branch. */
927186e7890SRichard Henderson     assert(e->npc != JUMP_PC);
928186e7890SRichard Henderson     e->npc = dc->npc;
929186e7890SRichard Henderson 
930186e7890SRichard Henderson     return e->lab;
931186e7890SRichard Henderson }
932186e7890SRichard Henderson 
933186e7890SRichard Henderson static TCGLabel *delay_exception(DisasContext *dc, int excp)
934186e7890SRichard Henderson {
935186e7890SRichard Henderson     return delay_exceptionv(dc, tcg_constant_i32(excp));
936186e7890SRichard Henderson }
937186e7890SRichard Henderson 
938186e7890SRichard Henderson static void gen_check_align(DisasContext *dc, TCGv addr, int mask)
939186e7890SRichard Henderson {
940186e7890SRichard Henderson     TCGv t = tcg_temp_new();
941186e7890SRichard Henderson     TCGLabel *lab;
942186e7890SRichard Henderson 
943186e7890SRichard Henderson     tcg_gen_andi_tl(t, addr, mask);
944186e7890SRichard Henderson 
945186e7890SRichard Henderson     flush_cond(dc);
946186e7890SRichard Henderson     lab = delay_exception(dc, TT_UNALIGNED);
947186e7890SRichard Henderson     tcg_gen_brcondi_tl(TCG_COND_NE, t, 0, lab);
948fcf5ef2aSThomas Huth }
949fcf5ef2aSThomas Huth 
9500c2e96c1SRichard Henderson static void gen_mov_pc_npc(DisasContext *dc)
951fcf5ef2aSThomas Huth {
95289527e3aSRichard Henderson     finishing_insn(dc);
95389527e3aSRichard Henderson 
954633c4283SRichard Henderson     if (dc->npc & 3) {
955633c4283SRichard Henderson         switch (dc->npc) {
956633c4283SRichard Henderson         case JUMP_PC:
957fcf5ef2aSThomas Huth             gen_generic_branch(dc);
958fcf5ef2aSThomas Huth             tcg_gen_mov_tl(cpu_pc, cpu_npc);
95999c82c47SRichard Henderson             dc->pc = DYNAMIC_PC_LOOKUP;
960633c4283SRichard Henderson             break;
961633c4283SRichard Henderson         case DYNAMIC_PC:
962633c4283SRichard Henderson         case DYNAMIC_PC_LOOKUP:
963fcf5ef2aSThomas Huth             tcg_gen_mov_tl(cpu_pc, cpu_npc);
964633c4283SRichard Henderson             dc->pc = dc->npc;
965633c4283SRichard Henderson             break;
966633c4283SRichard Henderson         default:
967633c4283SRichard Henderson             g_assert_not_reached();
968633c4283SRichard Henderson         }
969fcf5ef2aSThomas Huth     } else {
970fcf5ef2aSThomas Huth         dc->pc = dc->npc;
971fcf5ef2aSThomas Huth     }
972fcf5ef2aSThomas Huth }
973fcf5ef2aSThomas Huth 
974fcf5ef2aSThomas Huth static void gen_compare(DisasCompare *cmp, bool xcc, unsigned int cond,
975fcf5ef2aSThomas Huth                         DisasContext *dc)
976fcf5ef2aSThomas Huth {
977b597eedcSRichard Henderson     TCGv t1;
978fcf5ef2aSThomas Huth 
9792a1905c7SRichard Henderson     cmp->c1 = t1 = tcg_temp_new();
980c8507ebfSRichard Henderson     cmp->c2 = 0;
9812a1905c7SRichard Henderson 
9822a1905c7SRichard Henderson     switch (cond & 7) {
9832a1905c7SRichard Henderson     case 0x0: /* never */
9842a1905c7SRichard Henderson         cmp->cond = TCG_COND_NEVER;
985c8507ebfSRichard Henderson         cmp->c1 = tcg_constant_tl(0);
986fcf5ef2aSThomas Huth         break;
9872a1905c7SRichard Henderson 
9882a1905c7SRichard Henderson     case 0x1: /* eq: Z */
9892a1905c7SRichard Henderson         cmp->cond = TCG_COND_EQ;
9902a1905c7SRichard Henderson         if (TARGET_LONG_BITS == 32 || xcc) {
9912a1905c7SRichard Henderson             tcg_gen_mov_tl(t1, cpu_cc_Z);
9922a1905c7SRichard Henderson         } else {
9932a1905c7SRichard Henderson             tcg_gen_ext32u_tl(t1, cpu_icc_Z);
9942a1905c7SRichard Henderson         }
9952a1905c7SRichard Henderson         break;
9962a1905c7SRichard Henderson 
9972a1905c7SRichard Henderson     case 0x2: /* le: Z | (N ^ V) */
9982a1905c7SRichard Henderson         /*
9992a1905c7SRichard Henderson          * Simplify:
10002a1905c7SRichard Henderson          *   cc_Z || (N ^ V) < 0        NE
10012a1905c7SRichard Henderson          *   cc_Z && !((N ^ V) < 0)     EQ
10022a1905c7SRichard Henderson          *   cc_Z & ~((N ^ V) >> TLB)   EQ
10032a1905c7SRichard Henderson          */
10042a1905c7SRichard Henderson         cmp->cond = TCG_COND_EQ;
10052a1905c7SRichard Henderson         tcg_gen_xor_tl(t1, cpu_cc_N, cpu_cc_V);
10062a1905c7SRichard Henderson         tcg_gen_sextract_tl(t1, t1, xcc ? 63 : 31, 1);
10072a1905c7SRichard Henderson         tcg_gen_andc_tl(t1, xcc ? cpu_cc_Z : cpu_icc_Z, t1);
10082a1905c7SRichard Henderson         if (TARGET_LONG_BITS == 64 && !xcc) {
10092a1905c7SRichard Henderson             tcg_gen_ext32u_tl(t1, t1);
10102a1905c7SRichard Henderson         }
10112a1905c7SRichard Henderson         break;
10122a1905c7SRichard Henderson 
10132a1905c7SRichard Henderson     case 0x3: /* lt: N ^ V */
10142a1905c7SRichard Henderson         cmp->cond = TCG_COND_LT;
10152a1905c7SRichard Henderson         tcg_gen_xor_tl(t1, cpu_cc_N, cpu_cc_V);
10162a1905c7SRichard Henderson         if (TARGET_LONG_BITS == 64 && !xcc) {
10172a1905c7SRichard Henderson             tcg_gen_ext32s_tl(t1, t1);
10182a1905c7SRichard Henderson         }
10192a1905c7SRichard Henderson         break;
10202a1905c7SRichard Henderson 
10212a1905c7SRichard Henderson     case 0x4: /* leu: Z | C */
10222a1905c7SRichard Henderson         /*
10232a1905c7SRichard Henderson          * Simplify:
10242a1905c7SRichard Henderson          *   cc_Z == 0 || cc_C != 0     NE
10252a1905c7SRichard Henderson          *   cc_Z != 0 && cc_C == 0     EQ
10262a1905c7SRichard Henderson          *   cc_Z & (cc_C ? 0 : -1)     EQ
10272a1905c7SRichard Henderson          *   cc_Z & (cc_C - 1)          EQ
10282a1905c7SRichard Henderson          */
10292a1905c7SRichard Henderson         cmp->cond = TCG_COND_EQ;
10302a1905c7SRichard Henderson         if (TARGET_LONG_BITS == 32 || xcc) {
10312a1905c7SRichard Henderson             tcg_gen_subi_tl(t1, cpu_cc_C, 1);
10322a1905c7SRichard Henderson             tcg_gen_and_tl(t1, t1, cpu_cc_Z);
10332a1905c7SRichard Henderson         } else {
10342a1905c7SRichard Henderson             tcg_gen_extract_tl(t1, cpu_icc_C, 32, 1);
10352a1905c7SRichard Henderson             tcg_gen_subi_tl(t1, t1, 1);
10362a1905c7SRichard Henderson             tcg_gen_and_tl(t1, t1, cpu_icc_Z);
10372a1905c7SRichard Henderson             tcg_gen_ext32u_tl(t1, t1);
10382a1905c7SRichard Henderson         }
10392a1905c7SRichard Henderson         break;
10402a1905c7SRichard Henderson 
10412a1905c7SRichard Henderson     case 0x5: /* ltu: C */
10422a1905c7SRichard Henderson         cmp->cond = TCG_COND_NE;
10432a1905c7SRichard Henderson         if (TARGET_LONG_BITS == 32 || xcc) {
10442a1905c7SRichard Henderson             tcg_gen_mov_tl(t1, cpu_cc_C);
10452a1905c7SRichard Henderson         } else {
10462a1905c7SRichard Henderson             tcg_gen_extract_tl(t1, cpu_icc_C, 32, 1);
10472a1905c7SRichard Henderson         }
10482a1905c7SRichard Henderson         break;
10492a1905c7SRichard Henderson 
10502a1905c7SRichard Henderson     case 0x6: /* neg: N */
10512a1905c7SRichard Henderson         cmp->cond = TCG_COND_LT;
10522a1905c7SRichard Henderson         if (TARGET_LONG_BITS == 32 || xcc) {
10532a1905c7SRichard Henderson             tcg_gen_mov_tl(t1, cpu_cc_N);
10542a1905c7SRichard Henderson         } else {
10552a1905c7SRichard Henderson             tcg_gen_ext32s_tl(t1, cpu_cc_N);
10562a1905c7SRichard Henderson         }
10572a1905c7SRichard Henderson         break;
10582a1905c7SRichard Henderson 
10592a1905c7SRichard Henderson     case 0x7: /* vs: V */
10602a1905c7SRichard Henderson         cmp->cond = TCG_COND_LT;
10612a1905c7SRichard Henderson         if (TARGET_LONG_BITS == 32 || xcc) {
10622a1905c7SRichard Henderson             tcg_gen_mov_tl(t1, cpu_cc_V);
10632a1905c7SRichard Henderson         } else {
10642a1905c7SRichard Henderson             tcg_gen_ext32s_tl(t1, cpu_cc_V);
10652a1905c7SRichard Henderson         }
10662a1905c7SRichard Henderson         break;
10672a1905c7SRichard Henderson     }
10682a1905c7SRichard Henderson     if (cond & 8) {
10692a1905c7SRichard Henderson         cmp->cond = tcg_invert_cond(cmp->cond);
1070fcf5ef2aSThomas Huth     }
1071fcf5ef2aSThomas Huth }
1072fcf5ef2aSThomas Huth 
1073fcf5ef2aSThomas Huth static void gen_fcompare(DisasCompare *cmp, unsigned int cc, unsigned int cond)
1074fcf5ef2aSThomas Huth {
1075d8c5b92fSRichard Henderson     TCGv_i32 fcc = cpu_fcc[cc];
1076d8c5b92fSRichard Henderson     TCGv_i32 c1 = fcc;
1077d8c5b92fSRichard Henderson     int c2 = 0;
1078d8c5b92fSRichard Henderson     TCGCond tcond;
1079fcf5ef2aSThomas Huth 
1080d8c5b92fSRichard Henderson     /*
1081d8c5b92fSRichard Henderson      * FCC values:
1082d8c5b92fSRichard Henderson      * 0 =
1083d8c5b92fSRichard Henderson      * 1 <
1084d8c5b92fSRichard Henderson      * 2 >
1085d8c5b92fSRichard Henderson      * 3 unordered
1086d8c5b92fSRichard Henderson      */
1087d8c5b92fSRichard Henderson     switch (cond & 7) {
1088d8c5b92fSRichard Henderson     case 0x0: /* fbn */
1089d8c5b92fSRichard Henderson         tcond = TCG_COND_NEVER;
1090fcf5ef2aSThomas Huth         break;
1091d8c5b92fSRichard Henderson     case 0x1: /* fbne : !0 */
1092d8c5b92fSRichard Henderson         tcond = TCG_COND_NE;
1093fcf5ef2aSThomas Huth         break;
1094d8c5b92fSRichard Henderson     case 0x2: /* fblg : 1 or 2 */
1095d8c5b92fSRichard Henderson         /* fcc in {1,2} - 1 -> fcc in {0,1} */
1096d8c5b92fSRichard Henderson         c1 = tcg_temp_new_i32();
1097d8c5b92fSRichard Henderson         tcg_gen_addi_i32(c1, fcc, -1);
1098d8c5b92fSRichard Henderson         c2 = 1;
1099d8c5b92fSRichard Henderson         tcond = TCG_COND_LEU;
1100fcf5ef2aSThomas Huth         break;
1101d8c5b92fSRichard Henderson     case 0x3: /* fbul : 1 or 3 */
1102d8c5b92fSRichard Henderson         c1 = tcg_temp_new_i32();
1103d8c5b92fSRichard Henderson         tcg_gen_andi_i32(c1, fcc, 1);
1104d8c5b92fSRichard Henderson         tcond = TCG_COND_NE;
1105d8c5b92fSRichard Henderson         break;
1106d8c5b92fSRichard Henderson     case 0x4: /* fbl  : 1 */
1107d8c5b92fSRichard Henderson         c2 = 1;
1108d8c5b92fSRichard Henderson         tcond = TCG_COND_EQ;
1109d8c5b92fSRichard Henderson         break;
1110d8c5b92fSRichard Henderson     case 0x5: /* fbug : 2 or 3 */
1111d8c5b92fSRichard Henderson         c2 = 2;
1112d8c5b92fSRichard Henderson         tcond = TCG_COND_GEU;
1113d8c5b92fSRichard Henderson         break;
1114d8c5b92fSRichard Henderson     case 0x6: /* fbg  : 2 */
1115d8c5b92fSRichard Henderson         c2 = 2;
1116d8c5b92fSRichard Henderson         tcond = TCG_COND_EQ;
1117d8c5b92fSRichard Henderson         break;
1118d8c5b92fSRichard Henderson     case 0x7: /* fbu  : 3 */
1119d8c5b92fSRichard Henderson         c2 = 3;
1120d8c5b92fSRichard Henderson         tcond = TCG_COND_EQ;
1121fcf5ef2aSThomas Huth         break;
1122fcf5ef2aSThomas Huth     }
1123d8c5b92fSRichard Henderson     if (cond & 8) {
1124d8c5b92fSRichard Henderson         tcond = tcg_invert_cond(tcond);
1125fcf5ef2aSThomas Huth     }
1126d8c5b92fSRichard Henderson 
1127d8c5b92fSRichard Henderson     cmp->cond = tcond;
1128d8c5b92fSRichard Henderson     cmp->c2 = c2;
1129d8c5b92fSRichard Henderson     cmp->c1 = tcg_temp_new();
1130d8c5b92fSRichard Henderson     tcg_gen_extu_i32_tl(cmp->c1, c1);
1131fcf5ef2aSThomas Huth }
1132fcf5ef2aSThomas Huth 
11332c4f56c9SRichard Henderson static bool gen_compare_reg(DisasCompare *cmp, int cond, TCGv r_src)
11342c4f56c9SRichard Henderson {
11352c4f56c9SRichard Henderson     static const TCGCond cond_reg[4] = {
1136ab9ffe98SRichard Henderson         TCG_COND_NEVER,  /* reserved */
1137fcf5ef2aSThomas Huth         TCG_COND_EQ,
1138fcf5ef2aSThomas Huth         TCG_COND_LE,
1139fcf5ef2aSThomas Huth         TCG_COND_LT,
1140fcf5ef2aSThomas Huth     };
11412c4f56c9SRichard Henderson     TCGCond tcond;
1142fcf5ef2aSThomas Huth 
11432c4f56c9SRichard Henderson     if ((cond & 3) == 0) {
11442c4f56c9SRichard Henderson         return false;
11452c4f56c9SRichard Henderson     }
11462c4f56c9SRichard Henderson     tcond = cond_reg[cond & 3];
11472c4f56c9SRichard Henderson     if (cond & 4) {
11482c4f56c9SRichard Henderson         tcond = tcg_invert_cond(tcond);
11492c4f56c9SRichard Henderson     }
11502c4f56c9SRichard Henderson 
11512c4f56c9SRichard Henderson     cmp->cond = tcond;
1152816f89b7SRichard Henderson     cmp->c1 = tcg_temp_new();
1153c8507ebfSRichard Henderson     cmp->c2 = 0;
1154816f89b7SRichard Henderson     tcg_gen_mov_tl(cmp->c1, r_src);
11552c4f56c9SRichard Henderson     return true;
1156fcf5ef2aSThomas Huth }
1157fcf5ef2aSThomas Huth 
1158baf3dbf2SRichard Henderson static void gen_op_clear_ieee_excp_and_FTT(void)
1159baf3dbf2SRichard Henderson {
11603590f01eSRichard Henderson     tcg_gen_st_i32(tcg_constant_i32(0), tcg_env,
11613590f01eSRichard Henderson                    offsetof(CPUSPARCState, fsr_cexc_ftt));
1162baf3dbf2SRichard Henderson }
1163baf3dbf2SRichard Henderson 
1164baf3dbf2SRichard Henderson static void gen_op_fmovs(TCGv_i32 dst, TCGv_i32 src)
1165baf3dbf2SRichard Henderson {
1166baf3dbf2SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
1167baf3dbf2SRichard Henderson     tcg_gen_mov_i32(dst, src);
1168baf3dbf2SRichard Henderson }
1169baf3dbf2SRichard Henderson 
1170baf3dbf2SRichard Henderson static void gen_op_fnegs(TCGv_i32 dst, TCGv_i32 src)
1171baf3dbf2SRichard Henderson {
1172baf3dbf2SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
1173daf457d4SRichard Henderson     tcg_gen_xori_i32(dst, src, 1u << 31);
1174baf3dbf2SRichard Henderson }
1175baf3dbf2SRichard Henderson 
1176baf3dbf2SRichard Henderson static void gen_op_fabss(TCGv_i32 dst, TCGv_i32 src)
1177baf3dbf2SRichard Henderson {
1178baf3dbf2SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
1179daf457d4SRichard Henderson     tcg_gen_andi_i32(dst, src, ~(1u << 31));
1180baf3dbf2SRichard Henderson }
1181baf3dbf2SRichard Henderson 
1182c6d83e4fSRichard Henderson static void gen_op_fmovd(TCGv_i64 dst, TCGv_i64 src)
1183c6d83e4fSRichard Henderson {
1184c6d83e4fSRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
1185c6d83e4fSRichard Henderson     tcg_gen_mov_i64(dst, src);
1186c6d83e4fSRichard Henderson }
1187c6d83e4fSRichard Henderson 
1188c6d83e4fSRichard Henderson static void gen_op_fnegd(TCGv_i64 dst, TCGv_i64 src)
1189c6d83e4fSRichard Henderson {
1190c6d83e4fSRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
1191daf457d4SRichard Henderson     tcg_gen_xori_i64(dst, src, 1ull << 63);
1192c6d83e4fSRichard Henderson }
1193c6d83e4fSRichard Henderson 
1194c6d83e4fSRichard Henderson static void gen_op_fabsd(TCGv_i64 dst, TCGv_i64 src)
1195c6d83e4fSRichard Henderson {
1196c6d83e4fSRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
1197daf457d4SRichard Henderson     tcg_gen_andi_i64(dst, src, ~(1ull << 63));
1198daf457d4SRichard Henderson }
1199daf457d4SRichard Henderson 
1200daf457d4SRichard Henderson static void gen_op_fnegq(TCGv_i128 dst, TCGv_i128 src)
1201daf457d4SRichard Henderson {
1202daf457d4SRichard Henderson     TCGv_i64 l = tcg_temp_new_i64();
1203daf457d4SRichard Henderson     TCGv_i64 h = tcg_temp_new_i64();
1204daf457d4SRichard Henderson 
1205daf457d4SRichard Henderson     tcg_gen_extr_i128_i64(l, h, src);
1206daf457d4SRichard Henderson     tcg_gen_xori_i64(h, h, 1ull << 63);
1207daf457d4SRichard Henderson     tcg_gen_concat_i64_i128(dst, l, h);
1208daf457d4SRichard Henderson }
1209daf457d4SRichard Henderson 
1210daf457d4SRichard Henderson static void gen_op_fabsq(TCGv_i128 dst, TCGv_i128 src)
1211daf457d4SRichard Henderson {
1212daf457d4SRichard Henderson     TCGv_i64 l = tcg_temp_new_i64();
1213daf457d4SRichard Henderson     TCGv_i64 h = tcg_temp_new_i64();
1214daf457d4SRichard Henderson 
1215daf457d4SRichard Henderson     tcg_gen_extr_i128_i64(l, h, src);
1216daf457d4SRichard Henderson     tcg_gen_andi_i64(h, h, ~(1ull << 63));
1217daf457d4SRichard Henderson     tcg_gen_concat_i64_i128(dst, l, h);
1218c6d83e4fSRichard Henderson }
1219c6d83e4fSRichard Henderson 
12204fd71d19SRichard Henderson static void gen_op_fmadds(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2, TCGv_i32 s3)
12214fd71d19SRichard Henderson {
12224fd71d19SRichard Henderson     gen_helper_fmadds(d, tcg_env, s1, s2, s3, tcg_constant_i32(0));
12234fd71d19SRichard Henderson }
12244fd71d19SRichard Henderson 
12254fd71d19SRichard Henderson static void gen_op_fmaddd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2, TCGv_i64 s3)
12264fd71d19SRichard Henderson {
12274fd71d19SRichard Henderson     gen_helper_fmaddd(d, tcg_env, s1, s2, s3, tcg_constant_i32(0));
12284fd71d19SRichard Henderson }
12294fd71d19SRichard Henderson 
12304fd71d19SRichard Henderson static void gen_op_fmsubs(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2, TCGv_i32 s3)
12314fd71d19SRichard Henderson {
12324fd71d19SRichard Henderson     int op = float_muladd_negate_c;
12334fd71d19SRichard Henderson     gen_helper_fmadds(d, tcg_env, s1, s2, s3, tcg_constant_i32(op));
12344fd71d19SRichard Henderson }
12354fd71d19SRichard Henderson 
12364fd71d19SRichard Henderson static void gen_op_fmsubd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2, TCGv_i64 s3)
12374fd71d19SRichard Henderson {
12384fd71d19SRichard Henderson     int op = float_muladd_negate_c;
12394fd71d19SRichard Henderson     gen_helper_fmaddd(d, tcg_env, s1, s2, s3, tcg_constant_i32(op));
12404fd71d19SRichard Henderson }
12414fd71d19SRichard Henderson 
12424fd71d19SRichard Henderson static void gen_op_fnmsubs(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2, TCGv_i32 s3)
12434fd71d19SRichard Henderson {
12444fd71d19SRichard Henderson     int op = float_muladd_negate_c | float_muladd_negate_result;
12454fd71d19SRichard Henderson     gen_helper_fmadds(d, tcg_env, s1, s2, s3, tcg_constant_i32(op));
12464fd71d19SRichard Henderson }
12474fd71d19SRichard Henderson 
12484fd71d19SRichard Henderson static void gen_op_fnmsubd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2, TCGv_i64 s3)
12494fd71d19SRichard Henderson {
12504fd71d19SRichard Henderson     int op = float_muladd_negate_c | float_muladd_negate_result;
12514fd71d19SRichard Henderson     gen_helper_fmaddd(d, tcg_env, s1, s2, s3, tcg_constant_i32(op));
12524fd71d19SRichard Henderson }
12534fd71d19SRichard Henderson 
12544fd71d19SRichard Henderson static void gen_op_fnmadds(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2, TCGv_i32 s3)
12554fd71d19SRichard Henderson {
12564fd71d19SRichard Henderson     int op = float_muladd_negate_result;
12574fd71d19SRichard Henderson     gen_helper_fmadds(d, tcg_env, s1, s2, s3, tcg_constant_i32(op));
12584fd71d19SRichard Henderson }
12594fd71d19SRichard Henderson 
12604fd71d19SRichard Henderson static void gen_op_fnmaddd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2, TCGv_i64 s3)
12614fd71d19SRichard Henderson {
12624fd71d19SRichard Henderson     int op = float_muladd_negate_result;
12634fd71d19SRichard Henderson     gen_helper_fmaddd(d, tcg_env, s1, s2, s3, tcg_constant_i32(op));
12644fd71d19SRichard Henderson }
12654fd71d19SRichard Henderson 
12663d50b728SRichard Henderson /* Use muladd to compute (1 * src1) + src2 / 2 with one rounding. */
12673d50b728SRichard Henderson static void gen_op_fhadds(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2)
12683d50b728SRichard Henderson {
12693d50b728SRichard Henderson     TCGv_i32 one = tcg_constant_i32(float32_one);
12703d50b728SRichard Henderson     int op = float_muladd_halve_result;
12713d50b728SRichard Henderson     gen_helper_fmadds(d, tcg_env, one, s1, s2, tcg_constant_i32(op));
12723d50b728SRichard Henderson }
12733d50b728SRichard Henderson 
12743d50b728SRichard Henderson static void gen_op_fhaddd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2)
12753d50b728SRichard Henderson {
12763d50b728SRichard Henderson     TCGv_i64 one = tcg_constant_i64(float64_one);
12773d50b728SRichard Henderson     int op = float_muladd_halve_result;
12783d50b728SRichard Henderson     gen_helper_fmaddd(d, tcg_env, one, s1, s2, tcg_constant_i32(op));
12793d50b728SRichard Henderson }
12803d50b728SRichard Henderson 
12813d50b728SRichard Henderson /* Use muladd to compute (1 * src1) - src2 / 2 with one rounding. */
12823d50b728SRichard Henderson static void gen_op_fhsubs(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2)
12833d50b728SRichard Henderson {
12843d50b728SRichard Henderson     TCGv_i32 one = tcg_constant_i32(float32_one);
12853d50b728SRichard Henderson     int op = float_muladd_negate_c | float_muladd_halve_result;
12863d50b728SRichard Henderson     gen_helper_fmadds(d, tcg_env, one, s1, s2, tcg_constant_i32(op));
12873d50b728SRichard Henderson }
12883d50b728SRichard Henderson 
12893d50b728SRichard Henderson static void gen_op_fhsubd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2)
12903d50b728SRichard Henderson {
12913d50b728SRichard Henderson     TCGv_i64 one = tcg_constant_i64(float64_one);
12923d50b728SRichard Henderson     int op = float_muladd_negate_c | float_muladd_halve_result;
12933d50b728SRichard Henderson     gen_helper_fmaddd(d, tcg_env, one, s1, s2, tcg_constant_i32(op));
12943d50b728SRichard Henderson }
12953d50b728SRichard Henderson 
12963d50b728SRichard Henderson /* Use muladd to compute -((1 * src1) + src2 / 2) with one rounding. */
12973d50b728SRichard Henderson static void gen_op_fnhadds(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2)
12983d50b728SRichard Henderson {
12993d50b728SRichard Henderson     TCGv_i32 one = tcg_constant_i32(float32_one);
13003d50b728SRichard Henderson     int op = float_muladd_negate_result | float_muladd_halve_result;
13013d50b728SRichard Henderson     gen_helper_fmadds(d, tcg_env, one, s1, s2, tcg_constant_i32(op));
13023d50b728SRichard Henderson }
13033d50b728SRichard Henderson 
13043d50b728SRichard Henderson static void gen_op_fnhaddd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2)
13053d50b728SRichard Henderson {
13063d50b728SRichard Henderson     TCGv_i64 one = tcg_constant_i64(float64_one);
13073d50b728SRichard Henderson     int op = float_muladd_negate_result | float_muladd_halve_result;
13083d50b728SRichard Henderson     gen_helper_fmaddd(d, tcg_env, one, s1, s2, tcg_constant_i32(op));
13093d50b728SRichard Henderson }
13103d50b728SRichard Henderson 
13113590f01eSRichard Henderson static void gen_op_fpexception_im(DisasContext *dc, int ftt)
1312fcf5ef2aSThomas Huth {
13133590f01eSRichard Henderson     /*
13143590f01eSRichard Henderson      * CEXC is only set when succesfully completing an FPop,
13153590f01eSRichard Henderson      * or when raising FSR_FTT_IEEE_EXCP, i.e. check_ieee_exception.
13163590f01eSRichard Henderson      * Thus we can simply store FTT into this field.
13173590f01eSRichard Henderson      */
13183590f01eSRichard Henderson     tcg_gen_st_i32(tcg_constant_i32(ftt), tcg_env,
13193590f01eSRichard Henderson                    offsetof(CPUSPARCState, fsr_cexc_ftt));
1320fcf5ef2aSThomas Huth     gen_exception(dc, TT_FP_EXCP);
1321fcf5ef2aSThomas Huth }
1322fcf5ef2aSThomas Huth 
1323fcf5ef2aSThomas Huth static int gen_trap_ifnofpu(DisasContext *dc)
1324fcf5ef2aSThomas Huth {
1325fcf5ef2aSThomas Huth #if !defined(CONFIG_USER_ONLY)
1326fcf5ef2aSThomas Huth     if (!dc->fpu_enabled) {
1327fcf5ef2aSThomas Huth         gen_exception(dc, TT_NFPU_INSN);
1328fcf5ef2aSThomas Huth         return 1;
1329fcf5ef2aSThomas Huth     }
1330fcf5ef2aSThomas Huth #endif
1331fcf5ef2aSThomas Huth     return 0;
1332fcf5ef2aSThomas Huth }
1333fcf5ef2aSThomas Huth 
1334fcf5ef2aSThomas Huth /* asi moves */
1335fcf5ef2aSThomas Huth typedef enum {
1336fcf5ef2aSThomas Huth     GET_ASI_HELPER,
1337fcf5ef2aSThomas Huth     GET_ASI_EXCP,
1338fcf5ef2aSThomas Huth     GET_ASI_DIRECT,
1339fcf5ef2aSThomas Huth     GET_ASI_DTWINX,
13402786a3f8SRichard Henderson     GET_ASI_CODE,
1341fcf5ef2aSThomas Huth     GET_ASI_BLOCK,
1342fcf5ef2aSThomas Huth     GET_ASI_SHORT,
1343fcf5ef2aSThomas Huth     GET_ASI_BCOPY,
1344fcf5ef2aSThomas Huth     GET_ASI_BFILL,
1345fcf5ef2aSThomas Huth } ASIType;
1346fcf5ef2aSThomas Huth 
1347fcf5ef2aSThomas Huth typedef struct {
1348fcf5ef2aSThomas Huth     ASIType type;
1349fcf5ef2aSThomas Huth     int asi;
1350fcf5ef2aSThomas Huth     int mem_idx;
135114776ab5STony Nguyen     MemOp memop;
1352fcf5ef2aSThomas Huth } DisasASI;
1353fcf5ef2aSThomas Huth 
1354811cc0b0SRichard Henderson /*
1355811cc0b0SRichard Henderson  * Build DisasASI.
1356811cc0b0SRichard Henderson  * For asi == -1, treat as non-asi.
1357811cc0b0SRichard Henderson  * For ask == -2, treat as immediate offset (v8 error, v9 %asi).
1358811cc0b0SRichard Henderson  */
1359811cc0b0SRichard Henderson static DisasASI resolve_asi(DisasContext *dc, int asi, MemOp memop)
1360fcf5ef2aSThomas Huth {
1361fcf5ef2aSThomas Huth     ASIType type = GET_ASI_HELPER;
1362fcf5ef2aSThomas Huth     int mem_idx = dc->mem_idx;
1363fcf5ef2aSThomas Huth 
1364811cc0b0SRichard Henderson     if (asi == -1) {
1365811cc0b0SRichard Henderson         /* Artificial "non-asi" case. */
1366811cc0b0SRichard Henderson         type = GET_ASI_DIRECT;
1367811cc0b0SRichard Henderson         goto done;
1368811cc0b0SRichard Henderson     }
1369811cc0b0SRichard Henderson 
1370fcf5ef2aSThomas Huth #ifndef TARGET_SPARC64
1371fcf5ef2aSThomas Huth     /* Before v9, all asis are immediate and privileged.  */
1372811cc0b0SRichard Henderson     if (asi < 0) {
1373fcf5ef2aSThomas Huth         gen_exception(dc, TT_ILL_INSN);
1374fcf5ef2aSThomas Huth         type = GET_ASI_EXCP;
1375fcf5ef2aSThomas Huth     } else if (supervisor(dc)
1376fcf5ef2aSThomas Huth                /* Note that LEON accepts ASI_USERDATA in user mode, for
1377fcf5ef2aSThomas Huth                   use with CASA.  Also note that previous versions of
1378fcf5ef2aSThomas Huth                   QEMU allowed (and old versions of gcc emitted) ASI_P
1379fcf5ef2aSThomas Huth                   for LEON, which is incorrect.  */
1380fcf5ef2aSThomas Huth                || (asi == ASI_USERDATA
1381fcf5ef2aSThomas Huth                    && (dc->def->features & CPU_FEATURE_CASA))) {
1382fcf5ef2aSThomas Huth         switch (asi) {
1383fcf5ef2aSThomas Huth         case ASI_USERDATA:    /* User data access */
1384fcf5ef2aSThomas Huth             mem_idx = MMU_USER_IDX;
1385fcf5ef2aSThomas Huth             type = GET_ASI_DIRECT;
1386fcf5ef2aSThomas Huth             break;
1387fcf5ef2aSThomas Huth         case ASI_KERNELDATA:  /* Supervisor data access */
1388fcf5ef2aSThomas Huth             mem_idx = MMU_KERNEL_IDX;
1389fcf5ef2aSThomas Huth             type = GET_ASI_DIRECT;
1390fcf5ef2aSThomas Huth             break;
13912786a3f8SRichard Henderson         case ASI_USERTXT:     /* User text access */
13922786a3f8SRichard Henderson             mem_idx = MMU_USER_IDX;
13932786a3f8SRichard Henderson             type = GET_ASI_CODE;
13942786a3f8SRichard Henderson             break;
13952786a3f8SRichard Henderson         case ASI_KERNELTXT:   /* Supervisor text access */
13962786a3f8SRichard Henderson             mem_idx = MMU_KERNEL_IDX;
13972786a3f8SRichard Henderson             type = GET_ASI_CODE;
13982786a3f8SRichard Henderson             break;
1399fcf5ef2aSThomas Huth         case ASI_M_BYPASS:    /* MMU passthrough */
1400fcf5ef2aSThomas Huth         case ASI_LEON_BYPASS: /* LEON MMU passthrough */
1401fcf5ef2aSThomas Huth             mem_idx = MMU_PHYS_IDX;
1402fcf5ef2aSThomas Huth             type = GET_ASI_DIRECT;
1403fcf5ef2aSThomas Huth             break;
1404fcf5ef2aSThomas Huth         case ASI_M_BCOPY: /* Block copy, sta access */
1405fcf5ef2aSThomas Huth             mem_idx = MMU_KERNEL_IDX;
1406fcf5ef2aSThomas Huth             type = GET_ASI_BCOPY;
1407fcf5ef2aSThomas Huth             break;
1408fcf5ef2aSThomas Huth         case ASI_M_BFILL: /* Block fill, stda access */
1409fcf5ef2aSThomas Huth             mem_idx = MMU_KERNEL_IDX;
1410fcf5ef2aSThomas Huth             type = GET_ASI_BFILL;
1411fcf5ef2aSThomas Huth             break;
1412fcf5ef2aSThomas Huth         }
14136e10f37cSKONRAD Frederic 
14146e10f37cSKONRAD Frederic         /* MMU_PHYS_IDX is used when the MMU is disabled to passthrough the
14156e10f37cSKONRAD Frederic          * permissions check in get_physical_address(..).
14166e10f37cSKONRAD Frederic          */
14176e10f37cSKONRAD Frederic         mem_idx = (dc->mem_idx == MMU_PHYS_IDX) ? MMU_PHYS_IDX : mem_idx;
1418fcf5ef2aSThomas Huth     } else {
1419fcf5ef2aSThomas Huth         gen_exception(dc, TT_PRIV_INSN);
1420fcf5ef2aSThomas Huth         type = GET_ASI_EXCP;
1421fcf5ef2aSThomas Huth     }
1422fcf5ef2aSThomas Huth #else
1423811cc0b0SRichard Henderson     if (asi < 0) {
1424fcf5ef2aSThomas Huth         asi = dc->asi;
1425fcf5ef2aSThomas Huth     }
1426fcf5ef2aSThomas Huth     /* With v9, all asis below 0x80 are privileged.  */
1427fcf5ef2aSThomas Huth     /* ??? We ought to check cpu_has_hypervisor, but we didn't copy
1428fcf5ef2aSThomas Huth        down that bit into DisasContext.  For the moment that's ok,
1429fcf5ef2aSThomas Huth        since the direct implementations below doesn't have any ASIs
1430fcf5ef2aSThomas Huth        in the restricted [0x30, 0x7f] range, and the check will be
1431fcf5ef2aSThomas Huth        done properly in the helper.  */
1432fcf5ef2aSThomas Huth     if (!supervisor(dc) && asi < 0x80) {
1433fcf5ef2aSThomas Huth         gen_exception(dc, TT_PRIV_ACT);
1434fcf5ef2aSThomas Huth         type = GET_ASI_EXCP;
1435fcf5ef2aSThomas Huth     } else {
1436fcf5ef2aSThomas Huth         switch (asi) {
1437fcf5ef2aSThomas Huth         case ASI_REAL:      /* Bypass */
1438fcf5ef2aSThomas Huth         case ASI_REAL_IO:   /* Bypass, non-cacheable */
1439fcf5ef2aSThomas Huth         case ASI_REAL_L:    /* Bypass LE */
1440fcf5ef2aSThomas Huth         case ASI_REAL_IO_L: /* Bypass, non-cacheable LE */
1441fcf5ef2aSThomas Huth         case ASI_TWINX_REAL:   /* Real address, twinx */
1442fcf5ef2aSThomas Huth         case ASI_TWINX_REAL_L: /* Real address, twinx, LE */
1443fcf5ef2aSThomas Huth         case ASI_QUAD_LDD_PHYS:
1444fcf5ef2aSThomas Huth         case ASI_QUAD_LDD_PHYS_L:
1445fcf5ef2aSThomas Huth             mem_idx = MMU_PHYS_IDX;
1446fcf5ef2aSThomas Huth             break;
1447fcf5ef2aSThomas Huth         case ASI_N:  /* Nucleus */
1448fcf5ef2aSThomas Huth         case ASI_NL: /* Nucleus LE */
1449fcf5ef2aSThomas Huth         case ASI_TWINX_N:
1450fcf5ef2aSThomas Huth         case ASI_TWINX_NL:
1451fcf5ef2aSThomas Huth         case ASI_NUCLEUS_QUAD_LDD:
1452fcf5ef2aSThomas Huth         case ASI_NUCLEUS_QUAD_LDD_L:
14539a10756dSArtyom Tarasenko             if (hypervisor(dc)) {
145484f8f587SArtyom Tarasenko                 mem_idx = MMU_PHYS_IDX;
14559a10756dSArtyom Tarasenko             } else {
1456fcf5ef2aSThomas Huth                 mem_idx = MMU_NUCLEUS_IDX;
14579a10756dSArtyom Tarasenko             }
1458fcf5ef2aSThomas Huth             break;
1459fcf5ef2aSThomas Huth         case ASI_AIUP:  /* As if user primary */
1460fcf5ef2aSThomas Huth         case ASI_AIUPL: /* As if user primary LE */
1461fcf5ef2aSThomas Huth         case ASI_TWINX_AIUP:
1462fcf5ef2aSThomas Huth         case ASI_TWINX_AIUP_L:
1463fcf5ef2aSThomas Huth         case ASI_BLK_AIUP_4V:
1464fcf5ef2aSThomas Huth         case ASI_BLK_AIUP_L_4V:
1465fcf5ef2aSThomas Huth         case ASI_BLK_AIUP:
1466fcf5ef2aSThomas Huth         case ASI_BLK_AIUPL:
1467fcf5ef2aSThomas Huth             mem_idx = MMU_USER_IDX;
1468fcf5ef2aSThomas Huth             break;
1469fcf5ef2aSThomas Huth         case ASI_AIUS:  /* As if user secondary */
1470fcf5ef2aSThomas Huth         case ASI_AIUSL: /* As if user secondary LE */
1471fcf5ef2aSThomas Huth         case ASI_TWINX_AIUS:
1472fcf5ef2aSThomas Huth         case ASI_TWINX_AIUS_L:
1473fcf5ef2aSThomas Huth         case ASI_BLK_AIUS_4V:
1474fcf5ef2aSThomas Huth         case ASI_BLK_AIUS_L_4V:
1475fcf5ef2aSThomas Huth         case ASI_BLK_AIUS:
1476fcf5ef2aSThomas Huth         case ASI_BLK_AIUSL:
1477fcf5ef2aSThomas Huth             mem_idx = MMU_USER_SECONDARY_IDX;
1478fcf5ef2aSThomas Huth             break;
1479fcf5ef2aSThomas Huth         case ASI_S:  /* Secondary */
1480fcf5ef2aSThomas Huth         case ASI_SL: /* Secondary LE */
1481fcf5ef2aSThomas Huth         case ASI_TWINX_S:
1482fcf5ef2aSThomas Huth         case ASI_TWINX_SL:
1483fcf5ef2aSThomas Huth         case ASI_BLK_COMMIT_S:
1484fcf5ef2aSThomas Huth         case ASI_BLK_S:
1485fcf5ef2aSThomas Huth         case ASI_BLK_SL:
1486fcf5ef2aSThomas Huth         case ASI_FL8_S:
1487fcf5ef2aSThomas Huth         case ASI_FL8_SL:
1488fcf5ef2aSThomas Huth         case ASI_FL16_S:
1489fcf5ef2aSThomas Huth         case ASI_FL16_SL:
1490fcf5ef2aSThomas Huth             if (mem_idx == MMU_USER_IDX) {
1491fcf5ef2aSThomas Huth                 mem_idx = MMU_USER_SECONDARY_IDX;
1492fcf5ef2aSThomas Huth             } else if (mem_idx == MMU_KERNEL_IDX) {
1493fcf5ef2aSThomas Huth                 mem_idx = MMU_KERNEL_SECONDARY_IDX;
1494fcf5ef2aSThomas Huth             }
1495fcf5ef2aSThomas Huth             break;
1496fcf5ef2aSThomas Huth         case ASI_P:  /* Primary */
1497fcf5ef2aSThomas Huth         case ASI_PL: /* Primary LE */
1498fcf5ef2aSThomas Huth         case ASI_TWINX_P:
1499fcf5ef2aSThomas Huth         case ASI_TWINX_PL:
1500fcf5ef2aSThomas Huth         case ASI_BLK_COMMIT_P:
1501fcf5ef2aSThomas Huth         case ASI_BLK_P:
1502fcf5ef2aSThomas Huth         case ASI_BLK_PL:
1503fcf5ef2aSThomas Huth         case ASI_FL8_P:
1504fcf5ef2aSThomas Huth         case ASI_FL8_PL:
1505fcf5ef2aSThomas Huth         case ASI_FL16_P:
1506fcf5ef2aSThomas Huth         case ASI_FL16_PL:
1507fcf5ef2aSThomas Huth             break;
1508fcf5ef2aSThomas Huth         }
1509fcf5ef2aSThomas Huth         switch (asi) {
1510fcf5ef2aSThomas Huth         case ASI_REAL:
1511fcf5ef2aSThomas Huth         case ASI_REAL_IO:
1512fcf5ef2aSThomas Huth         case ASI_REAL_L:
1513fcf5ef2aSThomas Huth         case ASI_REAL_IO_L:
1514fcf5ef2aSThomas Huth         case ASI_N:
1515fcf5ef2aSThomas Huth         case ASI_NL:
1516fcf5ef2aSThomas Huth         case ASI_AIUP:
1517fcf5ef2aSThomas Huth         case ASI_AIUPL:
1518fcf5ef2aSThomas Huth         case ASI_AIUS:
1519fcf5ef2aSThomas Huth         case ASI_AIUSL:
1520fcf5ef2aSThomas Huth         case ASI_S:
1521fcf5ef2aSThomas Huth         case ASI_SL:
1522fcf5ef2aSThomas Huth         case ASI_P:
1523fcf5ef2aSThomas Huth         case ASI_PL:
1524fcf5ef2aSThomas Huth             type = GET_ASI_DIRECT;
1525fcf5ef2aSThomas Huth             break;
1526fcf5ef2aSThomas Huth         case ASI_TWINX_REAL:
1527fcf5ef2aSThomas Huth         case ASI_TWINX_REAL_L:
1528fcf5ef2aSThomas Huth         case ASI_TWINX_N:
1529fcf5ef2aSThomas Huth         case ASI_TWINX_NL:
1530fcf5ef2aSThomas Huth         case ASI_TWINX_AIUP:
1531fcf5ef2aSThomas Huth         case ASI_TWINX_AIUP_L:
1532fcf5ef2aSThomas Huth         case ASI_TWINX_AIUS:
1533fcf5ef2aSThomas Huth         case ASI_TWINX_AIUS_L:
1534fcf5ef2aSThomas Huth         case ASI_TWINX_P:
1535fcf5ef2aSThomas Huth         case ASI_TWINX_PL:
1536fcf5ef2aSThomas Huth         case ASI_TWINX_S:
1537fcf5ef2aSThomas Huth         case ASI_TWINX_SL:
1538fcf5ef2aSThomas Huth         case ASI_QUAD_LDD_PHYS:
1539fcf5ef2aSThomas Huth         case ASI_QUAD_LDD_PHYS_L:
1540fcf5ef2aSThomas Huth         case ASI_NUCLEUS_QUAD_LDD:
1541fcf5ef2aSThomas Huth         case ASI_NUCLEUS_QUAD_LDD_L:
1542fcf5ef2aSThomas Huth             type = GET_ASI_DTWINX;
1543fcf5ef2aSThomas Huth             break;
1544fcf5ef2aSThomas Huth         case ASI_BLK_COMMIT_P:
1545fcf5ef2aSThomas Huth         case ASI_BLK_COMMIT_S:
1546fcf5ef2aSThomas Huth         case ASI_BLK_AIUP_4V:
1547fcf5ef2aSThomas Huth         case ASI_BLK_AIUP_L_4V:
1548fcf5ef2aSThomas Huth         case ASI_BLK_AIUP:
1549fcf5ef2aSThomas Huth         case ASI_BLK_AIUPL:
1550fcf5ef2aSThomas Huth         case ASI_BLK_AIUS_4V:
1551fcf5ef2aSThomas Huth         case ASI_BLK_AIUS_L_4V:
1552fcf5ef2aSThomas Huth         case ASI_BLK_AIUS:
1553fcf5ef2aSThomas Huth         case ASI_BLK_AIUSL:
1554fcf5ef2aSThomas Huth         case ASI_BLK_S:
1555fcf5ef2aSThomas Huth         case ASI_BLK_SL:
1556fcf5ef2aSThomas Huth         case ASI_BLK_P:
1557fcf5ef2aSThomas Huth         case ASI_BLK_PL:
1558fcf5ef2aSThomas Huth             type = GET_ASI_BLOCK;
1559fcf5ef2aSThomas Huth             break;
1560fcf5ef2aSThomas Huth         case ASI_FL8_S:
1561fcf5ef2aSThomas Huth         case ASI_FL8_SL:
1562fcf5ef2aSThomas Huth         case ASI_FL8_P:
1563fcf5ef2aSThomas Huth         case ASI_FL8_PL:
1564fcf5ef2aSThomas Huth             memop = MO_UB;
1565fcf5ef2aSThomas Huth             type = GET_ASI_SHORT;
1566fcf5ef2aSThomas Huth             break;
1567fcf5ef2aSThomas Huth         case ASI_FL16_S:
1568fcf5ef2aSThomas Huth         case ASI_FL16_SL:
1569fcf5ef2aSThomas Huth         case ASI_FL16_P:
1570fcf5ef2aSThomas Huth         case ASI_FL16_PL:
1571fcf5ef2aSThomas Huth             memop = MO_TEUW;
1572fcf5ef2aSThomas Huth             type = GET_ASI_SHORT;
1573fcf5ef2aSThomas Huth             break;
1574fcf5ef2aSThomas Huth         }
1575fcf5ef2aSThomas Huth         /* The little-endian asis all have bit 3 set.  */
1576fcf5ef2aSThomas Huth         if (asi & 8) {
1577fcf5ef2aSThomas Huth             memop ^= MO_BSWAP;
1578fcf5ef2aSThomas Huth         }
1579fcf5ef2aSThomas Huth     }
1580fcf5ef2aSThomas Huth #endif
1581fcf5ef2aSThomas Huth 
1582811cc0b0SRichard Henderson  done:
1583fcf5ef2aSThomas Huth     return (DisasASI){ type, asi, mem_idx, memop };
1584fcf5ef2aSThomas Huth }
1585fcf5ef2aSThomas Huth 
1586a76779eeSRichard Henderson #if defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
1587a76779eeSRichard Henderson static void gen_helper_ld_asi(TCGv_i64 r, TCGv_env e, TCGv a,
1588a76779eeSRichard Henderson                               TCGv_i32 asi, TCGv_i32 mop)
1589a76779eeSRichard Henderson {
1590a76779eeSRichard Henderson     g_assert_not_reached();
1591a76779eeSRichard Henderson }
1592a76779eeSRichard Henderson 
1593a76779eeSRichard Henderson static void gen_helper_st_asi(TCGv_env e, TCGv a, TCGv_i64 r,
1594a76779eeSRichard Henderson                               TCGv_i32 asi, TCGv_i32 mop)
1595a76779eeSRichard Henderson {
1596a76779eeSRichard Henderson     g_assert_not_reached();
1597a76779eeSRichard Henderson }
1598a76779eeSRichard Henderson #endif
1599a76779eeSRichard Henderson 
160042071fc1SRichard Henderson static void gen_ld_asi(DisasContext *dc, DisasASI *da, TCGv dst, TCGv addr)
1601fcf5ef2aSThomas Huth {
1602c03a0fd1SRichard Henderson     switch (da->type) {
1603fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
1604fcf5ef2aSThomas Huth         break;
1605fcf5ef2aSThomas Huth     case GET_ASI_DTWINX: /* Reserved for ldda.  */
1606fcf5ef2aSThomas Huth         gen_exception(dc, TT_ILL_INSN);
1607fcf5ef2aSThomas Huth         break;
1608fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
1609c03a0fd1SRichard Henderson         tcg_gen_qemu_ld_tl(dst, addr, da->mem_idx, da->memop | MO_ALIGN);
1610fcf5ef2aSThomas Huth         break;
16112786a3f8SRichard Henderson 
16122786a3f8SRichard Henderson     case GET_ASI_CODE:
16132786a3f8SRichard Henderson #if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
16142786a3f8SRichard Henderson         {
16152786a3f8SRichard Henderson             MemOpIdx oi = make_memop_idx(da->memop, da->mem_idx);
16162786a3f8SRichard Henderson             TCGv_i64 t64 = tcg_temp_new_i64();
16172786a3f8SRichard Henderson 
16182786a3f8SRichard Henderson             gen_helper_ld_code(t64, tcg_env, addr, tcg_constant_i32(oi));
16192786a3f8SRichard Henderson             tcg_gen_trunc_i64_tl(dst, t64);
16202786a3f8SRichard Henderson         }
16212786a3f8SRichard Henderson         break;
16222786a3f8SRichard Henderson #else
16232786a3f8SRichard Henderson         g_assert_not_reached();
16242786a3f8SRichard Henderson #endif
16252786a3f8SRichard Henderson 
1626fcf5ef2aSThomas Huth     default:
1627fcf5ef2aSThomas Huth         {
1628c03a0fd1SRichard Henderson             TCGv_i32 r_asi = tcg_constant_i32(da->asi);
1629c03a0fd1SRichard Henderson             TCGv_i32 r_mop = tcg_constant_i32(da->memop | MO_ALIGN);
1630fcf5ef2aSThomas Huth 
1631fcf5ef2aSThomas Huth             save_state(dc);
1632fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
1633ad75a51eSRichard Henderson             gen_helper_ld_asi(dst, tcg_env, addr, r_asi, r_mop);
1634fcf5ef2aSThomas Huth #else
1635fcf5ef2aSThomas Huth             {
1636fcf5ef2aSThomas Huth                 TCGv_i64 t64 = tcg_temp_new_i64();
1637ad75a51eSRichard Henderson                 gen_helper_ld_asi(t64, tcg_env, addr, r_asi, r_mop);
1638fcf5ef2aSThomas Huth                 tcg_gen_trunc_i64_tl(dst, t64);
1639fcf5ef2aSThomas Huth             }
1640fcf5ef2aSThomas Huth #endif
1641fcf5ef2aSThomas Huth         }
1642fcf5ef2aSThomas Huth         break;
1643fcf5ef2aSThomas Huth     }
1644fcf5ef2aSThomas Huth }
1645fcf5ef2aSThomas Huth 
164642071fc1SRichard Henderson static void gen_st_asi(DisasContext *dc, DisasASI *da, TCGv src, TCGv addr)
1647c03a0fd1SRichard Henderson {
1648c03a0fd1SRichard Henderson     switch (da->type) {
1649fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
1650fcf5ef2aSThomas Huth         break;
1651c03a0fd1SRichard Henderson 
1652fcf5ef2aSThomas Huth     case GET_ASI_DTWINX: /* Reserved for stda.  */
1653c03a0fd1SRichard Henderson         if (TARGET_LONG_BITS == 32) {
1654fcf5ef2aSThomas Huth             gen_exception(dc, TT_ILL_INSN);
1655fcf5ef2aSThomas Huth             break;
1656c03a0fd1SRichard Henderson         } else if (!(dc->def->features & CPU_FEATURE_HYPV)) {
16573390537bSArtyom Tarasenko             /* Pre OpenSPARC CPUs don't have these */
16583390537bSArtyom Tarasenko             gen_exception(dc, TT_ILL_INSN);
1659fcf5ef2aSThomas Huth             break;
1660c03a0fd1SRichard Henderson         }
1661c03a0fd1SRichard Henderson         /* In OpenSPARC T1+ CPUs TWINX ASIs in store are ST_BLKINIT_ ASIs */
1662c03a0fd1SRichard Henderson         /* fall through */
1663c03a0fd1SRichard Henderson 
1664c03a0fd1SRichard Henderson     case GET_ASI_DIRECT:
1665c03a0fd1SRichard Henderson         tcg_gen_qemu_st_tl(src, addr, da->mem_idx, da->memop | MO_ALIGN);
1666c03a0fd1SRichard Henderson         break;
1667c03a0fd1SRichard Henderson 
1668fcf5ef2aSThomas Huth     case GET_ASI_BCOPY:
1669c03a0fd1SRichard Henderson         assert(TARGET_LONG_BITS == 32);
167098271007SRichard Henderson         /*
167198271007SRichard Henderson          * Copy 32 bytes from the address in SRC to ADDR.
167298271007SRichard Henderson          *
167398271007SRichard Henderson          * From Ross RT625 hyperSPARC manual, section 4.6:
167498271007SRichard Henderson          * "Block Copy and Block Fill will work only on cache line boundaries."
167598271007SRichard Henderson          *
167698271007SRichard Henderson          * It does not specify if an unaliged address is truncated or trapped.
167798271007SRichard Henderson          * Previous qemu behaviour was to truncate to 4 byte alignment, which
167898271007SRichard Henderson          * is obviously wrong.  The only place I can see this used is in the
167998271007SRichard Henderson          * Linux kernel which begins with page alignment, advancing by 32,
168098271007SRichard Henderson          * so is always aligned.  Assume truncation as the simpler option.
168198271007SRichard Henderson          *
168298271007SRichard Henderson          * Since the loads and stores are paired, allow the copy to happen
168398271007SRichard Henderson          * in the host endianness.  The copy need not be atomic.
168498271007SRichard Henderson          */
1685fcf5ef2aSThomas Huth         {
168698271007SRichard Henderson             MemOp mop = MO_128 | MO_ATOM_IFALIGN_PAIR;
1687fcf5ef2aSThomas Huth             TCGv saddr = tcg_temp_new();
1688fcf5ef2aSThomas Huth             TCGv daddr = tcg_temp_new();
168998271007SRichard Henderson             TCGv_i128 tmp = tcg_temp_new_i128();
1690fcf5ef2aSThomas Huth 
169198271007SRichard Henderson             tcg_gen_andi_tl(saddr, src, -32);
169298271007SRichard Henderson             tcg_gen_andi_tl(daddr, addr, -32);
169398271007SRichard Henderson             tcg_gen_qemu_ld_i128(tmp, saddr, da->mem_idx, mop);
169498271007SRichard Henderson             tcg_gen_qemu_st_i128(tmp, daddr, da->mem_idx, mop);
169598271007SRichard Henderson             tcg_gen_addi_tl(saddr, saddr, 16);
169698271007SRichard Henderson             tcg_gen_addi_tl(daddr, daddr, 16);
169798271007SRichard Henderson             tcg_gen_qemu_ld_i128(tmp, saddr, da->mem_idx, mop);
169898271007SRichard Henderson             tcg_gen_qemu_st_i128(tmp, daddr, da->mem_idx, mop);
1699fcf5ef2aSThomas Huth         }
1700fcf5ef2aSThomas Huth         break;
1701c03a0fd1SRichard Henderson 
1702fcf5ef2aSThomas Huth     default:
1703fcf5ef2aSThomas Huth         {
1704c03a0fd1SRichard Henderson             TCGv_i32 r_asi = tcg_constant_i32(da->asi);
1705c03a0fd1SRichard Henderson             TCGv_i32 r_mop = tcg_constant_i32(da->memop | MO_ALIGN);
1706fcf5ef2aSThomas Huth 
1707fcf5ef2aSThomas Huth             save_state(dc);
1708fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
1709ad75a51eSRichard Henderson             gen_helper_st_asi(tcg_env, addr, src, r_asi, r_mop);
1710fcf5ef2aSThomas Huth #else
1711fcf5ef2aSThomas Huth             {
1712fcf5ef2aSThomas Huth                 TCGv_i64 t64 = tcg_temp_new_i64();
1713fcf5ef2aSThomas Huth                 tcg_gen_extu_tl_i64(t64, src);
1714ad75a51eSRichard Henderson                 gen_helper_st_asi(tcg_env, addr, t64, r_asi, r_mop);
1715fcf5ef2aSThomas Huth             }
1716fcf5ef2aSThomas Huth #endif
1717fcf5ef2aSThomas Huth 
1718fcf5ef2aSThomas Huth             /* A write to a TLB register may alter page maps.  End the TB. */
1719fcf5ef2aSThomas Huth             dc->npc = DYNAMIC_PC;
1720fcf5ef2aSThomas Huth         }
1721fcf5ef2aSThomas Huth         break;
1722fcf5ef2aSThomas Huth     }
1723fcf5ef2aSThomas Huth }
1724fcf5ef2aSThomas Huth 
1725dca544b9SRichard Henderson static void gen_swap_asi(DisasContext *dc, DisasASI *da,
1726c03a0fd1SRichard Henderson                          TCGv dst, TCGv src, TCGv addr)
1727c03a0fd1SRichard Henderson {
1728c03a0fd1SRichard Henderson     switch (da->type) {
1729c03a0fd1SRichard Henderson     case GET_ASI_EXCP:
1730c03a0fd1SRichard Henderson         break;
1731c03a0fd1SRichard Henderson     case GET_ASI_DIRECT:
1732dca544b9SRichard Henderson         tcg_gen_atomic_xchg_tl(dst, addr, src,
1733dca544b9SRichard Henderson                                da->mem_idx, da->memop | MO_ALIGN);
1734c03a0fd1SRichard Henderson         break;
1735c03a0fd1SRichard Henderson     default:
1736c03a0fd1SRichard Henderson         /* ??? Should be DAE_invalid_asi.  */
1737c03a0fd1SRichard Henderson         gen_exception(dc, TT_DATA_ACCESS);
1738c03a0fd1SRichard Henderson         break;
1739c03a0fd1SRichard Henderson     }
1740c03a0fd1SRichard Henderson }
1741c03a0fd1SRichard Henderson 
1742d0a11d25SRichard Henderson static void gen_cas_asi(DisasContext *dc, DisasASI *da,
1743c03a0fd1SRichard Henderson                         TCGv oldv, TCGv newv, TCGv cmpv, TCGv addr)
1744c03a0fd1SRichard Henderson {
1745c03a0fd1SRichard Henderson     switch (da->type) {
1746fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
1747c03a0fd1SRichard Henderson         return;
1748fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
1749c03a0fd1SRichard Henderson         tcg_gen_atomic_cmpxchg_tl(oldv, addr, cmpv, newv,
1750c03a0fd1SRichard Henderson                                   da->mem_idx, da->memop | MO_ALIGN);
1751fcf5ef2aSThomas Huth         break;
1752fcf5ef2aSThomas Huth     default:
1753fcf5ef2aSThomas Huth         /* ??? Should be DAE_invalid_asi.  */
1754fcf5ef2aSThomas Huth         gen_exception(dc, TT_DATA_ACCESS);
1755fcf5ef2aSThomas Huth         break;
1756fcf5ef2aSThomas Huth     }
1757fcf5ef2aSThomas Huth }
1758fcf5ef2aSThomas Huth 
1759cf07cd1eSRichard Henderson static void gen_ldstub_asi(DisasContext *dc, DisasASI *da, TCGv dst, TCGv addr)
1760c03a0fd1SRichard Henderson {
1761c03a0fd1SRichard Henderson     switch (da->type) {
1762fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
1763fcf5ef2aSThomas Huth         break;
1764fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
1765cf07cd1eSRichard Henderson         tcg_gen_atomic_xchg_tl(dst, addr, tcg_constant_tl(0xff),
1766cf07cd1eSRichard Henderson                                da->mem_idx, MO_UB);
1767fcf5ef2aSThomas Huth         break;
1768fcf5ef2aSThomas Huth     default:
17693db010c3SRichard Henderson         /* ??? In theory, this should be raise DAE_invalid_asi.
17703db010c3SRichard Henderson            But the SS-20 roms do ldstuba [%l0] #ASI_M_CTL, %o1.  */
1771af00be49SEmilio G. Cota         if (tb_cflags(dc->base.tb) & CF_PARALLEL) {
1772ad75a51eSRichard Henderson             gen_helper_exit_atomic(tcg_env);
17733db010c3SRichard Henderson         } else {
1774c03a0fd1SRichard Henderson             TCGv_i32 r_asi = tcg_constant_i32(da->asi);
177500ab7e61SRichard Henderson             TCGv_i32 r_mop = tcg_constant_i32(MO_UB);
17763db010c3SRichard Henderson             TCGv_i64 s64, t64;
17773db010c3SRichard Henderson 
17783db010c3SRichard Henderson             save_state(dc);
17793db010c3SRichard Henderson             t64 = tcg_temp_new_i64();
1780ad75a51eSRichard Henderson             gen_helper_ld_asi(t64, tcg_env, addr, r_asi, r_mop);
17813db010c3SRichard Henderson 
178200ab7e61SRichard Henderson             s64 = tcg_constant_i64(0xff);
1783ad75a51eSRichard Henderson             gen_helper_st_asi(tcg_env, addr, s64, r_asi, r_mop);
17843db010c3SRichard Henderson 
17853db010c3SRichard Henderson             tcg_gen_trunc_i64_tl(dst, t64);
17863db010c3SRichard Henderson 
17873db010c3SRichard Henderson             /* End the TB.  */
17883db010c3SRichard Henderson             dc->npc = DYNAMIC_PC;
17893db010c3SRichard Henderson         }
1790fcf5ef2aSThomas Huth         break;
1791fcf5ef2aSThomas Huth     }
1792fcf5ef2aSThomas Huth }
1793fcf5ef2aSThomas Huth 
1794287b1152SRichard Henderson static void gen_ldf_asi(DisasContext *dc, DisasASI *da, MemOp orig_size,
17953259b9e2SRichard Henderson                         TCGv addr, int rd)
1796fcf5ef2aSThomas Huth {
17973259b9e2SRichard Henderson     MemOp memop = da->memop;
17983259b9e2SRichard Henderson     MemOp size = memop & MO_SIZE;
1799fcf5ef2aSThomas Huth     TCGv_i32 d32;
18001210a036SRichard Henderson     TCGv_i64 d64, l64;
1801287b1152SRichard Henderson     TCGv addr_tmp;
1802fcf5ef2aSThomas Huth 
18033259b9e2SRichard Henderson     /* TODO: Use 128-bit load/store below. */
18043259b9e2SRichard Henderson     if (size == MO_128) {
18053259b9e2SRichard Henderson         memop = (memop & ~MO_SIZE) | MO_64;
18063259b9e2SRichard Henderson     }
18073259b9e2SRichard Henderson 
18083259b9e2SRichard Henderson     switch (da->type) {
1809fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
1810fcf5ef2aSThomas Huth         break;
1811fcf5ef2aSThomas Huth 
1812fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
18133259b9e2SRichard Henderson         memop |= MO_ALIGN_4;
1814fcf5ef2aSThomas Huth         switch (size) {
18153259b9e2SRichard Henderson         case MO_32:
1816388a6465SRichard Henderson             d32 = tcg_temp_new_i32();
18173259b9e2SRichard Henderson             tcg_gen_qemu_ld_i32(d32, addr, da->mem_idx, memop);
1818fcf5ef2aSThomas Huth             gen_store_fpr_F(dc, rd, d32);
1819fcf5ef2aSThomas Huth             break;
18203259b9e2SRichard Henderson 
18213259b9e2SRichard Henderson         case MO_64:
18221210a036SRichard Henderson             d64 = tcg_temp_new_i64();
18231210a036SRichard Henderson             tcg_gen_qemu_ld_i64(d64, addr, da->mem_idx, memop);
18241210a036SRichard Henderson             gen_store_fpr_D(dc, rd, d64);
1825fcf5ef2aSThomas Huth             break;
18263259b9e2SRichard Henderson 
18273259b9e2SRichard Henderson         case MO_128:
1828fcf5ef2aSThomas Huth             d64 = tcg_temp_new_i64();
18291210a036SRichard Henderson             l64 = tcg_temp_new_i64();
18303259b9e2SRichard Henderson             tcg_gen_qemu_ld_i64(d64, addr, da->mem_idx, memop);
1831287b1152SRichard Henderson             addr_tmp = tcg_temp_new();
1832287b1152SRichard Henderson             tcg_gen_addi_tl(addr_tmp, addr, 8);
18331210a036SRichard Henderson             tcg_gen_qemu_ld_i64(l64, addr_tmp, da->mem_idx, memop);
18341210a036SRichard Henderson             gen_store_fpr_D(dc, rd, d64);
18351210a036SRichard Henderson             gen_store_fpr_D(dc, rd + 2, l64);
1836fcf5ef2aSThomas Huth             break;
1837fcf5ef2aSThomas Huth         default:
1838fcf5ef2aSThomas Huth             g_assert_not_reached();
1839fcf5ef2aSThomas Huth         }
1840fcf5ef2aSThomas Huth         break;
1841fcf5ef2aSThomas Huth 
1842fcf5ef2aSThomas Huth     case GET_ASI_BLOCK:
1843fcf5ef2aSThomas Huth         /* Valid for lddfa on aligned registers only.  */
18443259b9e2SRichard Henderson         if (orig_size == MO_64 && (rd & 7) == 0) {
1845fcf5ef2aSThomas Huth             /* The first operation checks required alignment.  */
1846287b1152SRichard Henderson             addr_tmp = tcg_temp_new();
18471210a036SRichard Henderson             d64 = tcg_temp_new_i64();
1848287b1152SRichard Henderson             for (int i = 0; ; ++i) {
18491210a036SRichard Henderson                 tcg_gen_qemu_ld_i64(d64, addr, da->mem_idx,
18503259b9e2SRichard Henderson                                     memop | (i == 0 ? MO_ALIGN_64 : 0));
18511210a036SRichard Henderson                 gen_store_fpr_D(dc, rd + 2 * i, d64);
1852fcf5ef2aSThomas Huth                 if (i == 7) {
1853fcf5ef2aSThomas Huth                     break;
1854fcf5ef2aSThomas Huth                 }
1855287b1152SRichard Henderson                 tcg_gen_addi_tl(addr_tmp, addr, 8);
1856287b1152SRichard Henderson                 addr = addr_tmp;
1857fcf5ef2aSThomas Huth             }
1858fcf5ef2aSThomas Huth         } else {
1859fcf5ef2aSThomas Huth             gen_exception(dc, TT_ILL_INSN);
1860fcf5ef2aSThomas Huth         }
1861fcf5ef2aSThomas Huth         break;
1862fcf5ef2aSThomas Huth 
1863fcf5ef2aSThomas Huth     case GET_ASI_SHORT:
1864fcf5ef2aSThomas Huth         /* Valid for lddfa only.  */
18653259b9e2SRichard Henderson         if (orig_size == MO_64) {
18661210a036SRichard Henderson             d64 = tcg_temp_new_i64();
18671210a036SRichard Henderson             tcg_gen_qemu_ld_i64(d64, addr, da->mem_idx, memop | MO_ALIGN);
18681210a036SRichard Henderson             gen_store_fpr_D(dc, rd, d64);
1869fcf5ef2aSThomas Huth         } else {
1870fcf5ef2aSThomas Huth             gen_exception(dc, TT_ILL_INSN);
1871fcf5ef2aSThomas Huth         }
1872fcf5ef2aSThomas Huth         break;
1873fcf5ef2aSThomas Huth 
1874fcf5ef2aSThomas Huth     default:
1875fcf5ef2aSThomas Huth         {
18763259b9e2SRichard Henderson             TCGv_i32 r_asi = tcg_constant_i32(da->asi);
18773259b9e2SRichard Henderson             TCGv_i32 r_mop = tcg_constant_i32(memop | MO_ALIGN);
1878fcf5ef2aSThomas Huth 
1879fcf5ef2aSThomas Huth             save_state(dc);
1880fcf5ef2aSThomas Huth             /* According to the table in the UA2011 manual, the only
1881fcf5ef2aSThomas Huth                other asis that are valid for ldfa/lddfa/ldqfa are
1882fcf5ef2aSThomas Huth                the NO_FAULT asis.  We still need a helper for these,
1883fcf5ef2aSThomas Huth                but we can just use the integer asi helper for them.  */
1884fcf5ef2aSThomas Huth             switch (size) {
18853259b9e2SRichard Henderson             case MO_32:
1886fcf5ef2aSThomas Huth                 d64 = tcg_temp_new_i64();
1887ad75a51eSRichard Henderson                 gen_helper_ld_asi(d64, tcg_env, addr, r_asi, r_mop);
1888388a6465SRichard Henderson                 d32 = tcg_temp_new_i32();
1889fcf5ef2aSThomas Huth                 tcg_gen_extrl_i64_i32(d32, d64);
1890fcf5ef2aSThomas Huth                 gen_store_fpr_F(dc, rd, d32);
1891fcf5ef2aSThomas Huth                 break;
18923259b9e2SRichard Henderson             case MO_64:
18931210a036SRichard Henderson                 d64 = tcg_temp_new_i64();
18941210a036SRichard Henderson                 gen_helper_ld_asi(d64, tcg_env, addr, r_asi, r_mop);
18951210a036SRichard Henderson                 gen_store_fpr_D(dc, rd, d64);
1896fcf5ef2aSThomas Huth                 break;
18973259b9e2SRichard Henderson             case MO_128:
1898fcf5ef2aSThomas Huth                 d64 = tcg_temp_new_i64();
18991210a036SRichard Henderson                 l64 = tcg_temp_new_i64();
1900ad75a51eSRichard Henderson                 gen_helper_ld_asi(d64, tcg_env, addr, r_asi, r_mop);
1901287b1152SRichard Henderson                 addr_tmp = tcg_temp_new();
1902287b1152SRichard Henderson                 tcg_gen_addi_tl(addr_tmp, addr, 8);
19031210a036SRichard Henderson                 gen_helper_ld_asi(l64, tcg_env, addr_tmp, r_asi, r_mop);
19041210a036SRichard Henderson                 gen_store_fpr_D(dc, rd, d64);
19051210a036SRichard Henderson                 gen_store_fpr_D(dc, rd + 2, l64);
1906fcf5ef2aSThomas Huth                 break;
1907fcf5ef2aSThomas Huth             default:
1908fcf5ef2aSThomas Huth                 g_assert_not_reached();
1909fcf5ef2aSThomas Huth             }
1910fcf5ef2aSThomas Huth         }
1911fcf5ef2aSThomas Huth         break;
1912fcf5ef2aSThomas Huth     }
1913fcf5ef2aSThomas Huth }
1914fcf5ef2aSThomas Huth 
1915287b1152SRichard Henderson static void gen_stf_asi(DisasContext *dc, DisasASI *da, MemOp orig_size,
19163259b9e2SRichard Henderson                         TCGv addr, int rd)
19173259b9e2SRichard Henderson {
19183259b9e2SRichard Henderson     MemOp memop = da->memop;
19193259b9e2SRichard Henderson     MemOp size = memop & MO_SIZE;
1920fcf5ef2aSThomas Huth     TCGv_i32 d32;
19211210a036SRichard Henderson     TCGv_i64 d64;
1922287b1152SRichard Henderson     TCGv addr_tmp;
1923fcf5ef2aSThomas Huth 
19243259b9e2SRichard Henderson     /* TODO: Use 128-bit load/store below. */
19253259b9e2SRichard Henderson     if (size == MO_128) {
19263259b9e2SRichard Henderson         memop = (memop & ~MO_SIZE) | MO_64;
19273259b9e2SRichard Henderson     }
19283259b9e2SRichard Henderson 
19293259b9e2SRichard Henderson     switch (da->type) {
1930fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
1931fcf5ef2aSThomas Huth         break;
1932fcf5ef2aSThomas Huth 
1933fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
19343259b9e2SRichard Henderson         memop |= MO_ALIGN_4;
1935fcf5ef2aSThomas Huth         switch (size) {
19363259b9e2SRichard Henderson         case MO_32:
1937fcf5ef2aSThomas Huth             d32 = gen_load_fpr_F(dc, rd);
19383259b9e2SRichard Henderson             tcg_gen_qemu_st_i32(d32, addr, da->mem_idx, memop | MO_ALIGN);
1939fcf5ef2aSThomas Huth             break;
19403259b9e2SRichard Henderson         case MO_64:
19411210a036SRichard Henderson             d64 = gen_load_fpr_D(dc, rd);
19421210a036SRichard Henderson             tcg_gen_qemu_st_i64(d64, addr, da->mem_idx, memop | MO_ALIGN_4);
1943fcf5ef2aSThomas Huth             break;
19443259b9e2SRichard Henderson         case MO_128:
1945fcf5ef2aSThomas Huth             /* Only 4-byte alignment required.  However, it is legal for the
1946fcf5ef2aSThomas Huth                cpu to signal the alignment fault, and the OS trap handler is
1947fcf5ef2aSThomas Huth                required to fix it up.  Requiring 16-byte alignment here avoids
1948fcf5ef2aSThomas Huth                having to probe the second page before performing the first
1949fcf5ef2aSThomas Huth                write.  */
19501210a036SRichard Henderson             d64 = gen_load_fpr_D(dc, rd);
19511210a036SRichard Henderson             tcg_gen_qemu_st_i64(d64, addr, da->mem_idx, memop | MO_ALIGN_16);
1952287b1152SRichard Henderson             addr_tmp = tcg_temp_new();
1953287b1152SRichard Henderson             tcg_gen_addi_tl(addr_tmp, addr, 8);
19541210a036SRichard Henderson             d64 = gen_load_fpr_D(dc, rd + 2);
19551210a036SRichard Henderson             tcg_gen_qemu_st_i64(d64, addr_tmp, da->mem_idx, memop);
1956fcf5ef2aSThomas Huth             break;
1957fcf5ef2aSThomas Huth         default:
1958fcf5ef2aSThomas Huth             g_assert_not_reached();
1959fcf5ef2aSThomas Huth         }
1960fcf5ef2aSThomas Huth         break;
1961fcf5ef2aSThomas Huth 
1962fcf5ef2aSThomas Huth     case GET_ASI_BLOCK:
1963fcf5ef2aSThomas Huth         /* Valid for stdfa on aligned registers only.  */
19643259b9e2SRichard Henderson         if (orig_size == MO_64 && (rd & 7) == 0) {
1965fcf5ef2aSThomas Huth             /* The first operation checks required alignment.  */
1966287b1152SRichard Henderson             addr_tmp = tcg_temp_new();
1967287b1152SRichard Henderson             for (int i = 0; ; ++i) {
19681210a036SRichard Henderson                 d64 = gen_load_fpr_D(dc, rd + 2 * i);
19691210a036SRichard Henderson                 tcg_gen_qemu_st_i64(d64, addr, da->mem_idx,
19703259b9e2SRichard Henderson                                     memop | (i == 0 ? MO_ALIGN_64 : 0));
1971fcf5ef2aSThomas Huth                 if (i == 7) {
1972fcf5ef2aSThomas Huth                     break;
1973fcf5ef2aSThomas Huth                 }
1974287b1152SRichard Henderson                 tcg_gen_addi_tl(addr_tmp, addr, 8);
1975287b1152SRichard Henderson                 addr = addr_tmp;
1976fcf5ef2aSThomas Huth             }
1977fcf5ef2aSThomas Huth         } else {
1978fcf5ef2aSThomas Huth             gen_exception(dc, TT_ILL_INSN);
1979fcf5ef2aSThomas Huth         }
1980fcf5ef2aSThomas Huth         break;
1981fcf5ef2aSThomas Huth 
1982fcf5ef2aSThomas Huth     case GET_ASI_SHORT:
1983fcf5ef2aSThomas Huth         /* Valid for stdfa only.  */
19843259b9e2SRichard Henderson         if (orig_size == MO_64) {
19851210a036SRichard Henderson             d64 = gen_load_fpr_D(dc, rd);
19861210a036SRichard Henderson             tcg_gen_qemu_st_i64(d64, addr, da->mem_idx, memop | MO_ALIGN);
1987fcf5ef2aSThomas Huth         } else {
1988fcf5ef2aSThomas Huth             gen_exception(dc, TT_ILL_INSN);
1989fcf5ef2aSThomas Huth         }
1990fcf5ef2aSThomas Huth         break;
1991fcf5ef2aSThomas Huth 
1992fcf5ef2aSThomas Huth     default:
1993fcf5ef2aSThomas Huth         /* According to the table in the UA2011 manual, the only
1994fcf5ef2aSThomas Huth            other asis that are valid for ldfa/lddfa/ldqfa are
1995fcf5ef2aSThomas Huth            the PST* asis, which aren't currently handled.  */
1996fcf5ef2aSThomas Huth         gen_exception(dc, TT_ILL_INSN);
1997fcf5ef2aSThomas Huth         break;
1998fcf5ef2aSThomas Huth     }
1999fcf5ef2aSThomas Huth }
2000fcf5ef2aSThomas Huth 
200142071fc1SRichard Henderson static void gen_ldda_asi(DisasContext *dc, DisasASI *da, TCGv addr, int rd)
2002fcf5ef2aSThomas Huth {
2003a76779eeSRichard Henderson     TCGv hi = gen_dest_gpr(dc, rd);
2004a76779eeSRichard Henderson     TCGv lo = gen_dest_gpr(dc, rd + 1);
2005fcf5ef2aSThomas Huth 
2006c03a0fd1SRichard Henderson     switch (da->type) {
2007fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
2008fcf5ef2aSThomas Huth         return;
2009fcf5ef2aSThomas Huth 
2010fcf5ef2aSThomas Huth     case GET_ASI_DTWINX:
2011ebbbec92SRichard Henderson #ifdef TARGET_SPARC64
2012ebbbec92SRichard Henderson         {
2013ebbbec92SRichard Henderson             MemOp mop = (da->memop & MO_BSWAP) | MO_128 | MO_ALIGN_16;
2014ebbbec92SRichard Henderson             TCGv_i128 t = tcg_temp_new_i128();
2015ebbbec92SRichard Henderson 
2016ebbbec92SRichard Henderson             tcg_gen_qemu_ld_i128(t, addr, da->mem_idx, mop);
2017ebbbec92SRichard Henderson             /*
2018ebbbec92SRichard Henderson              * Note that LE twinx acts as if each 64-bit register result is
2019ebbbec92SRichard Henderson              * byte swapped.  We perform one 128-bit LE load, so must swap
2020ebbbec92SRichard Henderson              * the order of the writebacks.
2021ebbbec92SRichard Henderson              */
2022ebbbec92SRichard Henderson             if ((mop & MO_BSWAP) == MO_TE) {
2023ebbbec92SRichard Henderson                 tcg_gen_extr_i128_i64(lo, hi, t);
2024ebbbec92SRichard Henderson             } else {
2025ebbbec92SRichard Henderson                 tcg_gen_extr_i128_i64(hi, lo, t);
2026ebbbec92SRichard Henderson             }
2027ebbbec92SRichard Henderson         }
2028fcf5ef2aSThomas Huth         break;
2029ebbbec92SRichard Henderson #else
2030ebbbec92SRichard Henderson         g_assert_not_reached();
2031ebbbec92SRichard Henderson #endif
2032fcf5ef2aSThomas Huth 
2033fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
2034fcf5ef2aSThomas Huth         {
2035fcf5ef2aSThomas Huth             TCGv_i64 tmp = tcg_temp_new_i64();
2036fcf5ef2aSThomas Huth 
2037c03a0fd1SRichard Henderson             tcg_gen_qemu_ld_i64(tmp, addr, da->mem_idx, da->memop | MO_ALIGN);
2038fcf5ef2aSThomas Huth 
2039fcf5ef2aSThomas Huth             /* Note that LE ldda acts as if each 32-bit register
2040fcf5ef2aSThomas Huth                result is byte swapped.  Having just performed one
2041fcf5ef2aSThomas Huth                64-bit bswap, we need now to swap the writebacks.  */
2042c03a0fd1SRichard Henderson             if ((da->memop & MO_BSWAP) == MO_TE) {
2043a76779eeSRichard Henderson                 tcg_gen_extr_i64_tl(lo, hi, tmp);
2044fcf5ef2aSThomas Huth             } else {
2045a76779eeSRichard Henderson                 tcg_gen_extr_i64_tl(hi, lo, tmp);
2046fcf5ef2aSThomas Huth             }
2047fcf5ef2aSThomas Huth         }
2048fcf5ef2aSThomas Huth         break;
2049fcf5ef2aSThomas Huth 
20502786a3f8SRichard Henderson     case GET_ASI_CODE:
20512786a3f8SRichard Henderson #if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
20522786a3f8SRichard Henderson         {
20532786a3f8SRichard Henderson             MemOpIdx oi = make_memop_idx(da->memop, da->mem_idx);
20542786a3f8SRichard Henderson             TCGv_i64 tmp = tcg_temp_new_i64();
20552786a3f8SRichard Henderson 
20562786a3f8SRichard Henderson             gen_helper_ld_code(tmp, tcg_env, addr, tcg_constant_i32(oi));
20572786a3f8SRichard Henderson 
20582786a3f8SRichard Henderson             /* See above.  */
20592786a3f8SRichard Henderson             if ((da->memop & MO_BSWAP) == MO_TE) {
20602786a3f8SRichard Henderson                 tcg_gen_extr_i64_tl(lo, hi, tmp);
20612786a3f8SRichard Henderson             } else {
20622786a3f8SRichard Henderson                 tcg_gen_extr_i64_tl(hi, lo, tmp);
20632786a3f8SRichard Henderson             }
20642786a3f8SRichard Henderson         }
20652786a3f8SRichard Henderson         break;
20662786a3f8SRichard Henderson #else
20672786a3f8SRichard Henderson         g_assert_not_reached();
20682786a3f8SRichard Henderson #endif
20692786a3f8SRichard Henderson 
2070fcf5ef2aSThomas Huth     default:
2071fcf5ef2aSThomas Huth         /* ??? In theory we've handled all of the ASIs that are valid
2072fcf5ef2aSThomas Huth            for ldda, and this should raise DAE_invalid_asi.  However,
2073fcf5ef2aSThomas Huth            real hardware allows others.  This can be seen with e.g.
2074fcf5ef2aSThomas Huth            FreeBSD 10.3 wrt ASI_IC_TAG.  */
2075fcf5ef2aSThomas Huth         {
2076c03a0fd1SRichard Henderson             TCGv_i32 r_asi = tcg_constant_i32(da->asi);
2077c03a0fd1SRichard Henderson             TCGv_i32 r_mop = tcg_constant_i32(da->memop);
2078fcf5ef2aSThomas Huth             TCGv_i64 tmp = tcg_temp_new_i64();
2079fcf5ef2aSThomas Huth 
2080fcf5ef2aSThomas Huth             save_state(dc);
2081ad75a51eSRichard Henderson             gen_helper_ld_asi(tmp, tcg_env, addr, r_asi, r_mop);
2082fcf5ef2aSThomas Huth 
2083fcf5ef2aSThomas Huth             /* See above.  */
2084c03a0fd1SRichard Henderson             if ((da->memop & MO_BSWAP) == MO_TE) {
2085a76779eeSRichard Henderson                 tcg_gen_extr_i64_tl(lo, hi, tmp);
2086fcf5ef2aSThomas Huth             } else {
2087a76779eeSRichard Henderson                 tcg_gen_extr_i64_tl(hi, lo, tmp);
2088fcf5ef2aSThomas Huth             }
2089fcf5ef2aSThomas Huth         }
2090fcf5ef2aSThomas Huth         break;
2091fcf5ef2aSThomas Huth     }
2092fcf5ef2aSThomas Huth 
2093fcf5ef2aSThomas Huth     gen_store_gpr(dc, rd, hi);
2094fcf5ef2aSThomas Huth     gen_store_gpr(dc, rd + 1, lo);
2095fcf5ef2aSThomas Huth }
2096fcf5ef2aSThomas Huth 
209742071fc1SRichard Henderson static void gen_stda_asi(DisasContext *dc, DisasASI *da, TCGv addr, int rd)
2098c03a0fd1SRichard Henderson {
2099c03a0fd1SRichard Henderson     TCGv hi = gen_load_gpr(dc, rd);
2100fcf5ef2aSThomas Huth     TCGv lo = gen_load_gpr(dc, rd + 1);
2101fcf5ef2aSThomas Huth 
2102c03a0fd1SRichard Henderson     switch (da->type) {
2103fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
2104fcf5ef2aSThomas Huth         break;
2105fcf5ef2aSThomas Huth 
2106fcf5ef2aSThomas Huth     case GET_ASI_DTWINX:
2107ebbbec92SRichard Henderson #ifdef TARGET_SPARC64
2108ebbbec92SRichard Henderson         {
2109ebbbec92SRichard Henderson             MemOp mop = (da->memop & MO_BSWAP) | MO_128 | MO_ALIGN_16;
2110ebbbec92SRichard Henderson             TCGv_i128 t = tcg_temp_new_i128();
2111ebbbec92SRichard Henderson 
2112ebbbec92SRichard Henderson             /*
2113ebbbec92SRichard Henderson              * Note that LE twinx acts as if each 64-bit register result is
2114ebbbec92SRichard Henderson              * byte swapped.  We perform one 128-bit LE store, so must swap
2115ebbbec92SRichard Henderson              * the order of the construction.
2116ebbbec92SRichard Henderson              */
2117ebbbec92SRichard Henderson             if ((mop & MO_BSWAP) == MO_TE) {
2118ebbbec92SRichard Henderson                 tcg_gen_concat_i64_i128(t, lo, hi);
2119ebbbec92SRichard Henderson             } else {
2120ebbbec92SRichard Henderson                 tcg_gen_concat_i64_i128(t, hi, lo);
2121ebbbec92SRichard Henderson             }
2122ebbbec92SRichard Henderson             tcg_gen_qemu_st_i128(t, addr, da->mem_idx, mop);
2123ebbbec92SRichard Henderson         }
2124fcf5ef2aSThomas Huth         break;
2125ebbbec92SRichard Henderson #else
2126ebbbec92SRichard Henderson         g_assert_not_reached();
2127ebbbec92SRichard Henderson #endif
2128fcf5ef2aSThomas Huth 
2129fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
2130fcf5ef2aSThomas Huth         {
2131fcf5ef2aSThomas Huth             TCGv_i64 t64 = tcg_temp_new_i64();
2132fcf5ef2aSThomas Huth 
2133fcf5ef2aSThomas Huth             /* Note that LE stda acts as if each 32-bit register result is
2134fcf5ef2aSThomas Huth                byte swapped.  We will perform one 64-bit LE store, so now
2135fcf5ef2aSThomas Huth                we must swap the order of the construction.  */
2136c03a0fd1SRichard Henderson             if ((da->memop & MO_BSWAP) == MO_TE) {
2137a76779eeSRichard Henderson                 tcg_gen_concat_tl_i64(t64, lo, hi);
2138fcf5ef2aSThomas Huth             } else {
2139a76779eeSRichard Henderson                 tcg_gen_concat_tl_i64(t64, hi, lo);
2140fcf5ef2aSThomas Huth             }
2141c03a0fd1SRichard Henderson             tcg_gen_qemu_st_i64(t64, addr, da->mem_idx, da->memop | MO_ALIGN);
2142fcf5ef2aSThomas Huth         }
2143fcf5ef2aSThomas Huth         break;
2144fcf5ef2aSThomas Huth 
2145a76779eeSRichard Henderson     case GET_ASI_BFILL:
2146a76779eeSRichard Henderson         assert(TARGET_LONG_BITS == 32);
214754c3e953SRichard Henderson         /*
214854c3e953SRichard Henderson          * Store 32 bytes of [rd:rd+1] to ADDR.
214954c3e953SRichard Henderson          * See comments for GET_ASI_COPY above.
215054c3e953SRichard Henderson          */
2151a76779eeSRichard Henderson         {
215254c3e953SRichard Henderson             MemOp mop = MO_TE | MO_128 | MO_ATOM_IFALIGN_PAIR;
215354c3e953SRichard Henderson             TCGv_i64 t8 = tcg_temp_new_i64();
215454c3e953SRichard Henderson             TCGv_i128 t16 = tcg_temp_new_i128();
215554c3e953SRichard Henderson             TCGv daddr = tcg_temp_new();
2156a76779eeSRichard Henderson 
215754c3e953SRichard Henderson             tcg_gen_concat_tl_i64(t8, lo, hi);
215854c3e953SRichard Henderson             tcg_gen_concat_i64_i128(t16, t8, t8);
215954c3e953SRichard Henderson             tcg_gen_andi_tl(daddr, addr, -32);
216054c3e953SRichard Henderson             tcg_gen_qemu_st_i128(t16, daddr, da->mem_idx, mop);
216154c3e953SRichard Henderson             tcg_gen_addi_tl(daddr, daddr, 16);
216254c3e953SRichard Henderson             tcg_gen_qemu_st_i128(t16, daddr, da->mem_idx, mop);
2163a76779eeSRichard Henderson         }
2164a76779eeSRichard Henderson         break;
2165a76779eeSRichard Henderson 
2166fcf5ef2aSThomas Huth     default:
2167fcf5ef2aSThomas Huth         /* ??? In theory we've handled all of the ASIs that are valid
2168fcf5ef2aSThomas Huth            for stda, and this should raise DAE_invalid_asi.  */
2169fcf5ef2aSThomas Huth         {
2170c03a0fd1SRichard Henderson             TCGv_i32 r_asi = tcg_constant_i32(da->asi);
2171c03a0fd1SRichard Henderson             TCGv_i32 r_mop = tcg_constant_i32(da->memop);
2172fcf5ef2aSThomas Huth             TCGv_i64 t64 = tcg_temp_new_i64();
2173fcf5ef2aSThomas Huth 
2174fcf5ef2aSThomas Huth             /* See above.  */
2175c03a0fd1SRichard Henderson             if ((da->memop & MO_BSWAP) == MO_TE) {
2176a76779eeSRichard Henderson                 tcg_gen_concat_tl_i64(t64, lo, hi);
2177fcf5ef2aSThomas Huth             } else {
2178a76779eeSRichard Henderson                 tcg_gen_concat_tl_i64(t64, hi, lo);
2179fcf5ef2aSThomas Huth             }
2180fcf5ef2aSThomas Huth 
2181fcf5ef2aSThomas Huth             save_state(dc);
2182ad75a51eSRichard Henderson             gen_helper_st_asi(tcg_env, addr, t64, r_asi, r_mop);
2183fcf5ef2aSThomas Huth         }
2184fcf5ef2aSThomas Huth         break;
2185fcf5ef2aSThomas Huth     }
2186fcf5ef2aSThomas Huth }
2187fcf5ef2aSThomas Huth 
2188fcf5ef2aSThomas Huth static void gen_fmovs(DisasContext *dc, DisasCompare *cmp, int rd, int rs)
2189fcf5ef2aSThomas Huth {
2190f7ec8155SRichard Henderson #ifdef TARGET_SPARC64
2191fcf5ef2aSThomas Huth     TCGv_i32 c32, zero, dst, s1, s2;
2192dd7dbfccSRichard Henderson     TCGv_i64 c64 = tcg_temp_new_i64();
2193fcf5ef2aSThomas Huth 
2194fcf5ef2aSThomas Huth     /* We have two choices here: extend the 32 bit data and use movcond_i64,
2195fcf5ef2aSThomas Huth        or fold the comparison down to 32 bits and use movcond_i32.  Choose
2196fcf5ef2aSThomas Huth        the later.  */
2197fcf5ef2aSThomas Huth     c32 = tcg_temp_new_i32();
2198c8507ebfSRichard Henderson     tcg_gen_setcondi_i64(cmp->cond, c64, cmp->c1, cmp->c2);
2199fcf5ef2aSThomas Huth     tcg_gen_extrl_i64_i32(c32, c64);
2200fcf5ef2aSThomas Huth 
2201fcf5ef2aSThomas Huth     s1 = gen_load_fpr_F(dc, rs);
2202fcf5ef2aSThomas Huth     s2 = gen_load_fpr_F(dc, rd);
2203388a6465SRichard Henderson     dst = tcg_temp_new_i32();
220400ab7e61SRichard Henderson     zero = tcg_constant_i32(0);
2205fcf5ef2aSThomas Huth 
2206fcf5ef2aSThomas Huth     tcg_gen_movcond_i32(TCG_COND_NE, dst, c32, zero, s1, s2);
2207fcf5ef2aSThomas Huth 
2208fcf5ef2aSThomas Huth     gen_store_fpr_F(dc, rd, dst);
2209f7ec8155SRichard Henderson #else
2210f7ec8155SRichard Henderson     qemu_build_not_reached();
2211f7ec8155SRichard Henderson #endif
2212fcf5ef2aSThomas Huth }
2213fcf5ef2aSThomas Huth 
2214fcf5ef2aSThomas Huth static void gen_fmovd(DisasContext *dc, DisasCompare *cmp, int rd, int rs)
2215fcf5ef2aSThomas Huth {
2216f7ec8155SRichard Henderson #ifdef TARGET_SPARC64
221752f46d46SRichard Henderson     TCGv_i64 dst = tcg_temp_new_i64();
2218c8507ebfSRichard Henderson     tcg_gen_movcond_i64(cmp->cond, dst, cmp->c1, tcg_constant_tl(cmp->c2),
2219fcf5ef2aSThomas Huth                         gen_load_fpr_D(dc, rs),
2220fcf5ef2aSThomas Huth                         gen_load_fpr_D(dc, rd));
2221fcf5ef2aSThomas Huth     gen_store_fpr_D(dc, rd, dst);
2222f7ec8155SRichard Henderson #else
2223f7ec8155SRichard Henderson     qemu_build_not_reached();
2224f7ec8155SRichard Henderson #endif
2225fcf5ef2aSThomas Huth }
2226fcf5ef2aSThomas Huth 
2227fcf5ef2aSThomas Huth static void gen_fmovq(DisasContext *dc, DisasCompare *cmp, int rd, int rs)
2228fcf5ef2aSThomas Huth {
2229f7ec8155SRichard Henderson #ifdef TARGET_SPARC64
2230c8507ebfSRichard Henderson     TCGv c2 = tcg_constant_tl(cmp->c2);
22311210a036SRichard Henderson     TCGv_i64 h = tcg_temp_new_i64();
22321210a036SRichard Henderson     TCGv_i64 l = tcg_temp_new_i64();
2233fcf5ef2aSThomas Huth 
22341210a036SRichard Henderson     tcg_gen_movcond_i64(cmp->cond, h, cmp->c1, c2,
22351210a036SRichard Henderson                         gen_load_fpr_D(dc, rs),
22361210a036SRichard Henderson                         gen_load_fpr_D(dc, rd));
22371210a036SRichard Henderson     tcg_gen_movcond_i64(cmp->cond, l, cmp->c1, c2,
22381210a036SRichard Henderson                         gen_load_fpr_D(dc, rs + 2),
22391210a036SRichard Henderson                         gen_load_fpr_D(dc, rd + 2));
22401210a036SRichard Henderson     gen_store_fpr_D(dc, rd, h);
22411210a036SRichard Henderson     gen_store_fpr_D(dc, rd + 2, l);
2242f7ec8155SRichard Henderson #else
2243f7ec8155SRichard Henderson     qemu_build_not_reached();
2244f7ec8155SRichard Henderson #endif
2245fcf5ef2aSThomas Huth }
2246fcf5ef2aSThomas Huth 
2247f7ec8155SRichard Henderson #ifdef TARGET_SPARC64
22485d617bfbSRichard Henderson static void gen_load_trap_state_at_tl(TCGv_ptr r_tsptr)
2249fcf5ef2aSThomas Huth {
2250fcf5ef2aSThomas Huth     TCGv_i32 r_tl = tcg_temp_new_i32();
2251fcf5ef2aSThomas Huth 
2252fcf5ef2aSThomas Huth     /* load env->tl into r_tl */
2253ad75a51eSRichard Henderson     tcg_gen_ld_i32(r_tl, tcg_env, offsetof(CPUSPARCState, tl));
2254fcf5ef2aSThomas Huth 
2255fcf5ef2aSThomas Huth     /* tl = [0 ... MAXTL_MASK] where MAXTL_MASK must be power of 2 */
2256fcf5ef2aSThomas Huth     tcg_gen_andi_i32(r_tl, r_tl, MAXTL_MASK);
2257fcf5ef2aSThomas Huth 
2258fcf5ef2aSThomas Huth     /* calculate offset to current trap state from env->ts, reuse r_tl */
2259fcf5ef2aSThomas Huth     tcg_gen_muli_i32(r_tl, r_tl, sizeof (trap_state));
2260ad75a51eSRichard Henderson     tcg_gen_addi_ptr(r_tsptr, tcg_env, offsetof(CPUSPARCState, ts));
2261fcf5ef2aSThomas Huth 
2262fcf5ef2aSThomas Huth     /* tsptr = env->ts[env->tl & MAXTL_MASK] */
2263fcf5ef2aSThomas Huth     {
2264fcf5ef2aSThomas Huth         TCGv_ptr r_tl_tmp = tcg_temp_new_ptr();
2265fcf5ef2aSThomas Huth         tcg_gen_ext_i32_ptr(r_tl_tmp, r_tl);
2266fcf5ef2aSThomas Huth         tcg_gen_add_ptr(r_tsptr, r_tsptr, r_tl_tmp);
2267fcf5ef2aSThomas Huth     }
2268fcf5ef2aSThomas Huth }
2269fcf5ef2aSThomas Huth #endif
2270fcf5ef2aSThomas Huth 
227106c060d9SRichard Henderson static int extract_dfpreg(DisasContext *dc, int x)
227206c060d9SRichard Henderson {
22730bba7572SRichard Henderson     int r = x & 0x1e;
22740bba7572SRichard Henderson #ifdef TARGET_SPARC64
22750bba7572SRichard Henderson     r |= (x & 1) << 5;
22760bba7572SRichard Henderson #endif
22770bba7572SRichard Henderson     return r;
227806c060d9SRichard Henderson }
227906c060d9SRichard Henderson 
228006c060d9SRichard Henderson static int extract_qfpreg(DisasContext *dc, int x)
228106c060d9SRichard Henderson {
22820bba7572SRichard Henderson     int r = x & 0x1c;
22830bba7572SRichard Henderson #ifdef TARGET_SPARC64
22840bba7572SRichard Henderson     r |= (x & 1) << 5;
22850bba7572SRichard Henderson #endif
22860bba7572SRichard Henderson     return r;
228706c060d9SRichard Henderson }
228806c060d9SRichard Henderson 
2289878cc677SRichard Henderson /* Include the auto-generated decoder.  */
2290878cc677SRichard Henderson #include "decode-insns.c.inc"
2291878cc677SRichard Henderson 
2292878cc677SRichard Henderson #define TRANS(NAME, AVAIL, FUNC, ...) \
2293878cc677SRichard Henderson     static bool trans_##NAME(DisasContext *dc, arg_##NAME *a) \
2294878cc677SRichard Henderson     { return avail_##AVAIL(dc) && FUNC(dc, __VA_ARGS__); }
2295878cc677SRichard Henderson 
2296878cc677SRichard Henderson #define avail_ALL(C)      true
2297878cc677SRichard Henderson #ifdef TARGET_SPARC64
2298878cc677SRichard Henderson # define avail_32(C)      false
2299af25071cSRichard Henderson # define avail_ASR17(C)   false
2300d0a11d25SRichard Henderson # define avail_CASA(C)    true
2301c2636853SRichard Henderson # define avail_DIV(C)     true
2302b5372650SRichard Henderson # define avail_MUL(C)     true
23030faef01bSRichard Henderson # define avail_POWERDOWN(C) false
2304878cc677SRichard Henderson # define avail_64(C)      true
23054fd71d19SRichard Henderson # define avail_FMAF(C)    ((C)->def->features & CPU_FEATURE_FMAF)
23065d617bfbSRichard Henderson # define avail_GL(C)      ((C)->def->features & CPU_FEATURE_GL)
2307af25071cSRichard Henderson # define avail_HYPV(C)    ((C)->def->features & CPU_FEATURE_HYPV)
2308b88ce6f2SRichard Henderson # define avail_VIS1(C)    ((C)->def->features & CPU_FEATURE_VIS1)
2309b88ce6f2SRichard Henderson # define avail_VIS2(C)    ((C)->def->features & CPU_FEATURE_VIS2)
23103335a048SRichard Henderson # define avail_VIS3(C)    ((C)->def->features & CPU_FEATURE_VIS3)
23113335a048SRichard Henderson # define avail_VIS3B(C)   avail_VIS3(C)
2312878cc677SRichard Henderson #else
2313878cc677SRichard Henderson # define avail_32(C)      true
2314af25071cSRichard Henderson # define avail_ASR17(C)   ((C)->def->features & CPU_FEATURE_ASR17)
2315d0a11d25SRichard Henderson # define avail_CASA(C)    ((C)->def->features & CPU_FEATURE_CASA)
2316c2636853SRichard Henderson # define avail_DIV(C)     ((C)->def->features & CPU_FEATURE_DIV)
2317b5372650SRichard Henderson # define avail_MUL(C)     ((C)->def->features & CPU_FEATURE_MUL)
23180faef01bSRichard Henderson # define avail_POWERDOWN(C) ((C)->def->features & CPU_FEATURE_POWERDOWN)
2319878cc677SRichard Henderson # define avail_64(C)      false
23204fd71d19SRichard Henderson # define avail_FMAF(C)    false
23215d617bfbSRichard Henderson # define avail_GL(C)      false
2322af25071cSRichard Henderson # define avail_HYPV(C)    false
2323b88ce6f2SRichard Henderson # define avail_VIS1(C)    false
2324b88ce6f2SRichard Henderson # define avail_VIS2(C)    false
23253335a048SRichard Henderson # define avail_VIS3(C)    false
23263335a048SRichard Henderson # define avail_VIS3B(C)   false
2327878cc677SRichard Henderson #endif
2328878cc677SRichard Henderson 
2329878cc677SRichard Henderson /* Default case for non jump instructions. */
2330878cc677SRichard Henderson static bool advance_pc(DisasContext *dc)
2331878cc677SRichard Henderson {
23324a8d145dSRichard Henderson     TCGLabel *l1;
23334a8d145dSRichard Henderson 
233489527e3aSRichard Henderson     finishing_insn(dc);
233589527e3aSRichard Henderson 
2336878cc677SRichard Henderson     if (dc->npc & 3) {
2337878cc677SRichard Henderson         switch (dc->npc) {
2338878cc677SRichard Henderson         case DYNAMIC_PC:
2339878cc677SRichard Henderson         case DYNAMIC_PC_LOOKUP:
2340878cc677SRichard Henderson             dc->pc = dc->npc;
2341444d8b30SRichard Henderson             tcg_gen_mov_tl(cpu_pc, cpu_npc);
2342444d8b30SRichard Henderson             tcg_gen_addi_tl(cpu_npc, cpu_npc, 4);
2343878cc677SRichard Henderson             break;
23444a8d145dSRichard Henderson 
2345878cc677SRichard Henderson         case JUMP_PC:
2346878cc677SRichard Henderson             /* we can do a static jump */
23474a8d145dSRichard Henderson             l1 = gen_new_label();
2348533f042fSRichard Henderson             tcg_gen_brcondi_tl(dc->jump.cond, dc->jump.c1, dc->jump.c2, l1);
23494a8d145dSRichard Henderson 
23504a8d145dSRichard Henderson             /* jump not taken */
23514a8d145dSRichard Henderson             gen_goto_tb(dc, 1, dc->jump_pc[1], dc->jump_pc[1] + 4);
23524a8d145dSRichard Henderson 
23534a8d145dSRichard Henderson             /* jump taken */
23544a8d145dSRichard Henderson             gen_set_label(l1);
23554a8d145dSRichard Henderson             gen_goto_tb(dc, 0, dc->jump_pc[0], dc->jump_pc[0] + 4);
23564a8d145dSRichard Henderson 
2357878cc677SRichard Henderson             dc->base.is_jmp = DISAS_NORETURN;
2358878cc677SRichard Henderson             break;
23594a8d145dSRichard Henderson 
2360878cc677SRichard Henderson         default:
2361878cc677SRichard Henderson             g_assert_not_reached();
2362878cc677SRichard Henderson         }
2363878cc677SRichard Henderson     } else {
2364878cc677SRichard Henderson         dc->pc = dc->npc;
2365878cc677SRichard Henderson         dc->npc = dc->npc + 4;
2366878cc677SRichard Henderson     }
2367878cc677SRichard Henderson     return true;
2368878cc677SRichard Henderson }
2369878cc677SRichard Henderson 
23706d2a0768SRichard Henderson /*
23716d2a0768SRichard Henderson  * Major opcodes 00 and 01 -- branches, call, and sethi
23726d2a0768SRichard Henderson  */
23736d2a0768SRichard Henderson 
23749d4e2bc7SRichard Henderson static bool advance_jump_cond(DisasContext *dc, DisasCompare *cmp,
23753951b7a8SRichard Henderson                               bool annul, int disp)
2376276567aaSRichard Henderson {
23773951b7a8SRichard Henderson     target_ulong dest = address_mask_i(dc, dc->pc + disp * 4);
2378c76c8045SRichard Henderson     target_ulong npc;
2379c76c8045SRichard Henderson 
238089527e3aSRichard Henderson     finishing_insn(dc);
238189527e3aSRichard Henderson 
23822d9bb237SRichard Henderson     if (cmp->cond == TCG_COND_ALWAYS) {
23832d9bb237SRichard Henderson         if (annul) {
23842d9bb237SRichard Henderson             dc->pc = dest;
23852d9bb237SRichard Henderson             dc->npc = dest + 4;
23862d9bb237SRichard Henderson         } else {
23872d9bb237SRichard Henderson             gen_mov_pc_npc(dc);
23882d9bb237SRichard Henderson             dc->npc = dest;
23892d9bb237SRichard Henderson         }
23902d9bb237SRichard Henderson         return true;
23912d9bb237SRichard Henderson     }
23922d9bb237SRichard Henderson 
23932d9bb237SRichard Henderson     if (cmp->cond == TCG_COND_NEVER) {
23942d9bb237SRichard Henderson         npc = dc->npc;
23952d9bb237SRichard Henderson         if (npc & 3) {
23962d9bb237SRichard Henderson             gen_mov_pc_npc(dc);
23972d9bb237SRichard Henderson             if (annul) {
23982d9bb237SRichard Henderson                 tcg_gen_addi_tl(cpu_pc, cpu_pc, 4);
23992d9bb237SRichard Henderson             }
24002d9bb237SRichard Henderson             tcg_gen_addi_tl(cpu_npc, cpu_pc, 4);
24012d9bb237SRichard Henderson         } else {
24022d9bb237SRichard Henderson             dc->pc = npc + (annul ? 4 : 0);
24032d9bb237SRichard Henderson             dc->npc = dc->pc + 4;
24042d9bb237SRichard Henderson         }
24052d9bb237SRichard Henderson         return true;
24062d9bb237SRichard Henderson     }
24072d9bb237SRichard Henderson 
2408c76c8045SRichard Henderson     flush_cond(dc);
2409c76c8045SRichard Henderson     npc = dc->npc;
24106b3e4cc6SRichard Henderson 
2411276567aaSRichard Henderson     if (annul) {
24126b3e4cc6SRichard Henderson         TCGLabel *l1 = gen_new_label();
24136b3e4cc6SRichard Henderson 
2414c8507ebfSRichard Henderson         tcg_gen_brcondi_tl(tcg_invert_cond(cmp->cond), cmp->c1, cmp->c2, l1);
24156b3e4cc6SRichard Henderson         gen_goto_tb(dc, 0, npc, dest);
24166b3e4cc6SRichard Henderson         gen_set_label(l1);
24176b3e4cc6SRichard Henderson         gen_goto_tb(dc, 1, npc + 4, npc + 8);
24186b3e4cc6SRichard Henderson 
24196b3e4cc6SRichard Henderson         dc->base.is_jmp = DISAS_NORETURN;
2420276567aaSRichard Henderson     } else {
24216b3e4cc6SRichard Henderson         if (npc & 3) {
24226b3e4cc6SRichard Henderson             switch (npc) {
24236b3e4cc6SRichard Henderson             case DYNAMIC_PC:
24246b3e4cc6SRichard Henderson             case DYNAMIC_PC_LOOKUP:
24256b3e4cc6SRichard Henderson                 tcg_gen_mov_tl(cpu_pc, cpu_npc);
24266b3e4cc6SRichard Henderson                 tcg_gen_addi_tl(cpu_npc, cpu_npc, 4);
24279d4e2bc7SRichard Henderson                 tcg_gen_movcond_tl(cmp->cond, cpu_npc,
2428c8507ebfSRichard Henderson                                    cmp->c1, tcg_constant_tl(cmp->c2),
24296b3e4cc6SRichard Henderson                                    tcg_constant_tl(dest), cpu_npc);
24306b3e4cc6SRichard Henderson                 dc->pc = npc;
24316b3e4cc6SRichard Henderson                 break;
24326b3e4cc6SRichard Henderson             default:
24336b3e4cc6SRichard Henderson                 g_assert_not_reached();
24346b3e4cc6SRichard Henderson             }
24356b3e4cc6SRichard Henderson         } else {
24366b3e4cc6SRichard Henderson             dc->pc = npc;
2437533f042fSRichard Henderson             dc->npc = JUMP_PC;
2438533f042fSRichard Henderson             dc->jump = *cmp;
24396b3e4cc6SRichard Henderson             dc->jump_pc[0] = dest;
24406b3e4cc6SRichard Henderson             dc->jump_pc[1] = npc + 4;
2441dd7dbfccSRichard Henderson 
2442dd7dbfccSRichard Henderson             /* The condition for cpu_cond is always NE -- normalize. */
2443dd7dbfccSRichard Henderson             if (cmp->cond == TCG_COND_NE) {
2444c8507ebfSRichard Henderson                 tcg_gen_xori_tl(cpu_cond, cmp->c1, cmp->c2);
24459d4e2bc7SRichard Henderson             } else {
2446c8507ebfSRichard Henderson                 tcg_gen_setcondi_tl(cmp->cond, cpu_cond, cmp->c1, cmp->c2);
24479d4e2bc7SRichard Henderson             }
244889527e3aSRichard Henderson             dc->cpu_cond_live = true;
24496b3e4cc6SRichard Henderson         }
2450276567aaSRichard Henderson     }
2451276567aaSRichard Henderson     return true;
2452276567aaSRichard Henderson }
2453276567aaSRichard Henderson 
2454af25071cSRichard Henderson static bool raise_priv(DisasContext *dc)
2455af25071cSRichard Henderson {
2456af25071cSRichard Henderson     gen_exception(dc, TT_PRIV_INSN);
2457af25071cSRichard Henderson     return true;
2458af25071cSRichard Henderson }
2459af25071cSRichard Henderson 
246006c060d9SRichard Henderson static bool raise_unimpfpop(DisasContext *dc)
246106c060d9SRichard Henderson {
246206c060d9SRichard Henderson     gen_op_fpexception_im(dc, FSR_FTT_UNIMPFPOP);
246306c060d9SRichard Henderson     return true;
246406c060d9SRichard Henderson }
246506c060d9SRichard Henderson 
246606c060d9SRichard Henderson static bool gen_trap_float128(DisasContext *dc)
246706c060d9SRichard Henderson {
246806c060d9SRichard Henderson     if (dc->def->features & CPU_FEATURE_FLOAT128) {
246906c060d9SRichard Henderson         return false;
247006c060d9SRichard Henderson     }
247106c060d9SRichard Henderson     return raise_unimpfpop(dc);
247206c060d9SRichard Henderson }
247306c060d9SRichard Henderson 
2474276567aaSRichard Henderson static bool do_bpcc(DisasContext *dc, arg_bcc *a)
2475276567aaSRichard Henderson {
24761ea9c62aSRichard Henderson     DisasCompare cmp;
2477276567aaSRichard Henderson 
24781ea9c62aSRichard Henderson     gen_compare(&cmp, a->cc, a->cond, dc);
24793951b7a8SRichard Henderson     return advance_jump_cond(dc, &cmp, a->a, a->i);
2480276567aaSRichard Henderson }
2481276567aaSRichard Henderson 
2482276567aaSRichard Henderson TRANS(Bicc, ALL, do_bpcc, a)
2483276567aaSRichard Henderson TRANS(BPcc,  64, do_bpcc, a)
2484276567aaSRichard Henderson 
248545196ea4SRichard Henderson static bool do_fbpfcc(DisasContext *dc, arg_bcc *a)
248645196ea4SRichard Henderson {
2487d5471936SRichard Henderson     DisasCompare cmp;
248845196ea4SRichard Henderson 
248945196ea4SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
249045196ea4SRichard Henderson         return true;
249145196ea4SRichard Henderson     }
2492d5471936SRichard Henderson     gen_fcompare(&cmp, a->cc, a->cond);
24933951b7a8SRichard Henderson     return advance_jump_cond(dc, &cmp, a->a, a->i);
249445196ea4SRichard Henderson }
249545196ea4SRichard Henderson 
249645196ea4SRichard Henderson TRANS(FBPfcc,  64, do_fbpfcc, a)
249745196ea4SRichard Henderson TRANS(FBfcc,  ALL, do_fbpfcc, a)
249845196ea4SRichard Henderson 
2499ab9ffe98SRichard Henderson static bool trans_BPr(DisasContext *dc, arg_BPr *a)
2500ab9ffe98SRichard Henderson {
2501ab9ffe98SRichard Henderson     DisasCompare cmp;
2502ab9ffe98SRichard Henderson 
2503ab9ffe98SRichard Henderson     if (!avail_64(dc)) {
2504ab9ffe98SRichard Henderson         return false;
2505ab9ffe98SRichard Henderson     }
25062c4f56c9SRichard Henderson     if (!gen_compare_reg(&cmp, a->cond, gen_load_gpr(dc, a->rs1))) {
2507ab9ffe98SRichard Henderson         return false;
2508ab9ffe98SRichard Henderson     }
25093951b7a8SRichard Henderson     return advance_jump_cond(dc, &cmp, a->a, a->i);
2510ab9ffe98SRichard Henderson }
2511ab9ffe98SRichard Henderson 
251223ada1b1SRichard Henderson static bool trans_CALL(DisasContext *dc, arg_CALL *a)
251323ada1b1SRichard Henderson {
251423ada1b1SRichard Henderson     target_long target = address_mask_i(dc, dc->pc + a->i * 4);
251523ada1b1SRichard Henderson 
251623ada1b1SRichard Henderson     gen_store_gpr(dc, 15, tcg_constant_tl(dc->pc));
251723ada1b1SRichard Henderson     gen_mov_pc_npc(dc);
251823ada1b1SRichard Henderson     dc->npc = target;
251923ada1b1SRichard Henderson     return true;
252023ada1b1SRichard Henderson }
252123ada1b1SRichard Henderson 
252245196ea4SRichard Henderson static bool trans_NCP(DisasContext *dc, arg_NCP *a)
252345196ea4SRichard Henderson {
252445196ea4SRichard Henderson     /*
252545196ea4SRichard Henderson      * For sparc32, always generate the no-coprocessor exception.
252645196ea4SRichard Henderson      * For sparc64, always generate illegal instruction.
252745196ea4SRichard Henderson      */
252845196ea4SRichard Henderson #ifdef TARGET_SPARC64
252945196ea4SRichard Henderson     return false;
253045196ea4SRichard Henderson #else
253145196ea4SRichard Henderson     gen_exception(dc, TT_NCP_INSN);
253245196ea4SRichard Henderson     return true;
253345196ea4SRichard Henderson #endif
253445196ea4SRichard Henderson }
253545196ea4SRichard Henderson 
25366d2a0768SRichard Henderson static bool trans_SETHI(DisasContext *dc, arg_SETHI *a)
25376d2a0768SRichard Henderson {
25386d2a0768SRichard Henderson     /* Special-case %g0 because that's the canonical nop.  */
25396d2a0768SRichard Henderson     if (a->rd) {
25406d2a0768SRichard Henderson         gen_store_gpr(dc, a->rd, tcg_constant_tl((uint32_t)a->i << 10));
25416d2a0768SRichard Henderson     }
25426d2a0768SRichard Henderson     return advance_pc(dc);
25436d2a0768SRichard Henderson }
25446d2a0768SRichard Henderson 
25450faef01bSRichard Henderson /*
25460faef01bSRichard Henderson  * Major Opcode 10 -- integer, floating-point, vis, and system insns.
25470faef01bSRichard Henderson  */
25480faef01bSRichard Henderson 
254930376636SRichard Henderson static bool do_tcc(DisasContext *dc, int cond, int cc,
255030376636SRichard Henderson                    int rs1, bool imm, int rs2_or_imm)
255130376636SRichard Henderson {
255230376636SRichard Henderson     int mask = ((dc->def->features & CPU_FEATURE_HYPV) && supervisor(dc)
255330376636SRichard Henderson                 ? UA2005_HTRAP_MASK : V8_TRAP_MASK);
255430376636SRichard Henderson     DisasCompare cmp;
255530376636SRichard Henderson     TCGLabel *lab;
255630376636SRichard Henderson     TCGv_i32 trap;
255730376636SRichard Henderson 
255830376636SRichard Henderson     /* Trap never.  */
255930376636SRichard Henderson     if (cond == 0) {
256030376636SRichard Henderson         return advance_pc(dc);
256130376636SRichard Henderson     }
256230376636SRichard Henderson 
256330376636SRichard Henderson     /*
256430376636SRichard Henderson      * Immediate traps are the most common case.  Since this value is
256530376636SRichard Henderson      * live across the branch, it really pays to evaluate the constant.
256630376636SRichard Henderson      */
256730376636SRichard Henderson     if (rs1 == 0 && (imm || rs2_or_imm == 0)) {
256830376636SRichard Henderson         trap = tcg_constant_i32((rs2_or_imm & mask) + TT_TRAP);
256930376636SRichard Henderson     } else {
257030376636SRichard Henderson         trap = tcg_temp_new_i32();
257130376636SRichard Henderson         tcg_gen_trunc_tl_i32(trap, gen_load_gpr(dc, rs1));
257230376636SRichard Henderson         if (imm) {
257330376636SRichard Henderson             tcg_gen_addi_i32(trap, trap, rs2_or_imm);
257430376636SRichard Henderson         } else {
257530376636SRichard Henderson             TCGv_i32 t2 = tcg_temp_new_i32();
257630376636SRichard Henderson             tcg_gen_trunc_tl_i32(t2, gen_load_gpr(dc, rs2_or_imm));
257730376636SRichard Henderson             tcg_gen_add_i32(trap, trap, t2);
257830376636SRichard Henderson         }
257930376636SRichard Henderson         tcg_gen_andi_i32(trap, trap, mask);
258030376636SRichard Henderson         tcg_gen_addi_i32(trap, trap, TT_TRAP);
258130376636SRichard Henderson     }
258230376636SRichard Henderson 
258389527e3aSRichard Henderson     finishing_insn(dc);
258489527e3aSRichard Henderson 
258530376636SRichard Henderson     /* Trap always.  */
258630376636SRichard Henderson     if (cond == 8) {
258730376636SRichard Henderson         save_state(dc);
258830376636SRichard Henderson         gen_helper_raise_exception(tcg_env, trap);
258930376636SRichard Henderson         dc->base.is_jmp = DISAS_NORETURN;
259030376636SRichard Henderson         return true;
259130376636SRichard Henderson     }
259230376636SRichard Henderson 
259330376636SRichard Henderson     /* Conditional trap.  */
259430376636SRichard Henderson     flush_cond(dc);
259530376636SRichard Henderson     lab = delay_exceptionv(dc, trap);
259630376636SRichard Henderson     gen_compare(&cmp, cc, cond, dc);
2597c8507ebfSRichard Henderson     tcg_gen_brcondi_tl(cmp.cond, cmp.c1, cmp.c2, lab);
259830376636SRichard Henderson 
259930376636SRichard Henderson     return advance_pc(dc);
260030376636SRichard Henderson }
260130376636SRichard Henderson 
260230376636SRichard Henderson static bool trans_Tcc_r(DisasContext *dc, arg_Tcc_r *a)
260330376636SRichard Henderson {
260430376636SRichard Henderson     if (avail_32(dc) && a->cc) {
260530376636SRichard Henderson         return false;
260630376636SRichard Henderson     }
260730376636SRichard Henderson     return do_tcc(dc, a->cond, a->cc, a->rs1, false, a->rs2);
260830376636SRichard Henderson }
260930376636SRichard Henderson 
261030376636SRichard Henderson static bool trans_Tcc_i_v7(DisasContext *dc, arg_Tcc_i_v7 *a)
261130376636SRichard Henderson {
261230376636SRichard Henderson     if (avail_64(dc)) {
261330376636SRichard Henderson         return false;
261430376636SRichard Henderson     }
261530376636SRichard Henderson     return do_tcc(dc, a->cond, 0, a->rs1, true, a->i);
261630376636SRichard Henderson }
261730376636SRichard Henderson 
261830376636SRichard Henderson static bool trans_Tcc_i_v9(DisasContext *dc, arg_Tcc_i_v9 *a)
261930376636SRichard Henderson {
262030376636SRichard Henderson     if (avail_32(dc)) {
262130376636SRichard Henderson         return false;
262230376636SRichard Henderson     }
262330376636SRichard Henderson     return do_tcc(dc, a->cond, a->cc, a->rs1, true, a->i);
262430376636SRichard Henderson }
262530376636SRichard Henderson 
2626af25071cSRichard Henderson static bool trans_STBAR(DisasContext *dc, arg_STBAR *a)
2627af25071cSRichard Henderson {
2628af25071cSRichard Henderson     tcg_gen_mb(TCG_MO_ST_ST | TCG_BAR_SC);
2629af25071cSRichard Henderson     return advance_pc(dc);
2630af25071cSRichard Henderson }
2631af25071cSRichard Henderson 
2632af25071cSRichard Henderson static bool trans_MEMBAR(DisasContext *dc, arg_MEMBAR *a)
2633af25071cSRichard Henderson {
2634af25071cSRichard Henderson     if (avail_32(dc)) {
2635af25071cSRichard Henderson         return false;
2636af25071cSRichard Henderson     }
2637af25071cSRichard Henderson     if (a->mmask) {
2638af25071cSRichard Henderson         /* Note TCG_MO_* was modeled on sparc64, so mmask matches. */
2639af25071cSRichard Henderson         tcg_gen_mb(a->mmask | TCG_BAR_SC);
2640af25071cSRichard Henderson     }
2641af25071cSRichard Henderson     if (a->cmask) {
2642af25071cSRichard Henderson         /* For #Sync, etc, end the TB to recognize interrupts. */
2643af25071cSRichard Henderson         dc->base.is_jmp = DISAS_EXIT;
2644af25071cSRichard Henderson     }
2645af25071cSRichard Henderson     return advance_pc(dc);
2646af25071cSRichard Henderson }
2647af25071cSRichard Henderson 
2648af25071cSRichard Henderson static bool do_rd_special(DisasContext *dc, bool priv, int rd,
2649af25071cSRichard Henderson                           TCGv (*func)(DisasContext *, TCGv))
2650af25071cSRichard Henderson {
2651af25071cSRichard Henderson     if (!priv) {
2652af25071cSRichard Henderson         return raise_priv(dc);
2653af25071cSRichard Henderson     }
2654af25071cSRichard Henderson     gen_store_gpr(dc, rd, func(dc, gen_dest_gpr(dc, rd)));
2655af25071cSRichard Henderson     return advance_pc(dc);
2656af25071cSRichard Henderson }
2657af25071cSRichard Henderson 
2658af25071cSRichard Henderson static TCGv do_rdy(DisasContext *dc, TCGv dst)
2659af25071cSRichard Henderson {
2660af25071cSRichard Henderson     return cpu_y;
2661af25071cSRichard Henderson }
2662af25071cSRichard Henderson 
2663af25071cSRichard Henderson static bool trans_RDY(DisasContext *dc, arg_RDY *a)
2664af25071cSRichard Henderson {
2665af25071cSRichard Henderson     /*
2666af25071cSRichard Henderson      * TODO: Need a feature bit for sparcv8.  In the meantime, treat all
2667af25071cSRichard Henderson      * 32-bit cpus like sparcv7, which ignores the rs1 field.
2668af25071cSRichard Henderson      * This matches after all other ASR, so Leon3 Asr17 is handled first.
2669af25071cSRichard Henderson      */
2670af25071cSRichard Henderson     if (avail_64(dc) && a->rs1 != 0) {
2671af25071cSRichard Henderson         return false;
2672af25071cSRichard Henderson     }
2673af25071cSRichard Henderson     return do_rd_special(dc, true, a->rd, do_rdy);
2674af25071cSRichard Henderson }
2675af25071cSRichard Henderson 
2676af25071cSRichard Henderson static TCGv do_rd_leon3_config(DisasContext *dc, TCGv dst)
2677af25071cSRichard Henderson {
2678c92948f2SClément Chigot     gen_helper_rdasr17(dst, tcg_env);
2679c92948f2SClément Chigot     return dst;
2680af25071cSRichard Henderson }
2681af25071cSRichard Henderson 
2682af25071cSRichard Henderson TRANS(RDASR17, ASR17, do_rd_special, true, a->rd, do_rd_leon3_config)
2683af25071cSRichard Henderson 
2684af25071cSRichard Henderson static TCGv do_rdccr(DisasContext *dc, TCGv dst)
2685af25071cSRichard Henderson {
2686af25071cSRichard Henderson     gen_helper_rdccr(dst, tcg_env);
2687af25071cSRichard Henderson     return dst;
2688af25071cSRichard Henderson }
2689af25071cSRichard Henderson 
2690af25071cSRichard Henderson TRANS(RDCCR, 64, do_rd_special, true, a->rd, do_rdccr)
2691af25071cSRichard Henderson 
2692af25071cSRichard Henderson static TCGv do_rdasi(DisasContext *dc, TCGv dst)
2693af25071cSRichard Henderson {
2694af25071cSRichard Henderson #ifdef TARGET_SPARC64
2695af25071cSRichard Henderson     return tcg_constant_tl(dc->asi);
2696af25071cSRichard Henderson #else
2697af25071cSRichard Henderson     qemu_build_not_reached();
2698af25071cSRichard Henderson #endif
2699af25071cSRichard Henderson }
2700af25071cSRichard Henderson 
2701af25071cSRichard Henderson TRANS(RDASI, 64, do_rd_special, true, a->rd, do_rdasi)
2702af25071cSRichard Henderson 
2703af25071cSRichard Henderson static TCGv do_rdtick(DisasContext *dc, TCGv dst)
2704af25071cSRichard Henderson {
2705af25071cSRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
2706af25071cSRichard Henderson 
2707af25071cSRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(tick));
2708af25071cSRichard Henderson     if (translator_io_start(&dc->base)) {
2709af25071cSRichard Henderson         dc->base.is_jmp = DISAS_EXIT;
2710af25071cSRichard Henderson     }
2711af25071cSRichard Henderson     gen_helper_tick_get_count(dst, tcg_env, r_tickptr,
2712af25071cSRichard Henderson                               tcg_constant_i32(dc->mem_idx));
2713af25071cSRichard Henderson     return dst;
2714af25071cSRichard Henderson }
2715af25071cSRichard Henderson 
2716af25071cSRichard Henderson /* TODO: non-priv access only allowed when enabled. */
2717af25071cSRichard Henderson TRANS(RDTICK, 64, do_rd_special, true, a->rd, do_rdtick)
2718af25071cSRichard Henderson 
2719af25071cSRichard Henderson static TCGv do_rdpc(DisasContext *dc, TCGv dst)
2720af25071cSRichard Henderson {
2721af25071cSRichard Henderson     return tcg_constant_tl(address_mask_i(dc, dc->pc));
2722af25071cSRichard Henderson }
2723af25071cSRichard Henderson 
2724af25071cSRichard Henderson TRANS(RDPC, 64, do_rd_special, true, a->rd, do_rdpc)
2725af25071cSRichard Henderson 
2726af25071cSRichard Henderson static TCGv do_rdfprs(DisasContext *dc, TCGv dst)
2727af25071cSRichard Henderson {
2728af25071cSRichard Henderson     tcg_gen_ext_i32_tl(dst, cpu_fprs);
2729af25071cSRichard Henderson     return dst;
2730af25071cSRichard Henderson }
2731af25071cSRichard Henderson 
2732af25071cSRichard Henderson TRANS(RDFPRS, 64, do_rd_special, true, a->rd, do_rdfprs)
2733af25071cSRichard Henderson 
2734af25071cSRichard Henderson static TCGv do_rdgsr(DisasContext *dc, TCGv dst)
2735af25071cSRichard Henderson {
2736af25071cSRichard Henderson     gen_trap_ifnofpu(dc);
2737af25071cSRichard Henderson     return cpu_gsr;
2738af25071cSRichard Henderson }
2739af25071cSRichard Henderson 
2740af25071cSRichard Henderson TRANS(RDGSR, 64, do_rd_special, true, a->rd, do_rdgsr)
2741af25071cSRichard Henderson 
2742af25071cSRichard Henderson static TCGv do_rdsoftint(DisasContext *dc, TCGv dst)
2743af25071cSRichard Henderson {
2744af25071cSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(softint));
2745af25071cSRichard Henderson     return dst;
2746af25071cSRichard Henderson }
2747af25071cSRichard Henderson 
2748af25071cSRichard Henderson TRANS(RDSOFTINT, 64, do_rd_special, supervisor(dc), a->rd, do_rdsoftint)
2749af25071cSRichard Henderson 
2750af25071cSRichard Henderson static TCGv do_rdtick_cmpr(DisasContext *dc, TCGv dst)
2751af25071cSRichard Henderson {
2752577efa45SRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(tick_cmpr));
2753577efa45SRichard Henderson     return dst;
2754af25071cSRichard Henderson }
2755af25071cSRichard Henderson 
2756af25071cSRichard Henderson /* TODO: non-priv access only allowed when enabled. */
2757af25071cSRichard Henderson TRANS(RDTICK_CMPR, 64, do_rd_special, true, a->rd, do_rdtick_cmpr)
2758af25071cSRichard Henderson 
2759af25071cSRichard Henderson static TCGv do_rdstick(DisasContext *dc, TCGv dst)
2760af25071cSRichard Henderson {
2761af25071cSRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
2762af25071cSRichard Henderson 
2763af25071cSRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(stick));
2764af25071cSRichard Henderson     if (translator_io_start(&dc->base)) {
2765af25071cSRichard Henderson         dc->base.is_jmp = DISAS_EXIT;
2766af25071cSRichard Henderson     }
2767af25071cSRichard Henderson     gen_helper_tick_get_count(dst, tcg_env, r_tickptr,
2768af25071cSRichard Henderson                               tcg_constant_i32(dc->mem_idx));
2769af25071cSRichard Henderson     return dst;
2770af25071cSRichard Henderson }
2771af25071cSRichard Henderson 
2772af25071cSRichard Henderson /* TODO: non-priv access only allowed when enabled. */
2773af25071cSRichard Henderson TRANS(RDSTICK, 64, do_rd_special, true, a->rd, do_rdstick)
2774af25071cSRichard Henderson 
2775af25071cSRichard Henderson static TCGv do_rdstick_cmpr(DisasContext *dc, TCGv dst)
2776af25071cSRichard Henderson {
2777577efa45SRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(stick_cmpr));
2778577efa45SRichard Henderson     return dst;
2779af25071cSRichard Henderson }
2780af25071cSRichard Henderson 
2781af25071cSRichard Henderson /* TODO: supervisor access only allowed when enabled by hypervisor. */
2782af25071cSRichard Henderson TRANS(RDSTICK_CMPR, 64, do_rd_special, supervisor(dc), a->rd, do_rdstick_cmpr)
2783af25071cSRichard Henderson 
2784af25071cSRichard Henderson /*
2785af25071cSRichard Henderson  * UltraSPARC-T1 Strand status.
2786af25071cSRichard Henderson  * HYPV check maybe not enough, UA2005 & UA2007 describe
2787af25071cSRichard Henderson  * this ASR as impl. dep
2788af25071cSRichard Henderson  */
2789af25071cSRichard Henderson static TCGv do_rdstrand_status(DisasContext *dc, TCGv dst)
2790af25071cSRichard Henderson {
2791af25071cSRichard Henderson     return tcg_constant_tl(1);
2792af25071cSRichard Henderson }
2793af25071cSRichard Henderson 
2794af25071cSRichard Henderson TRANS(RDSTRAND_STATUS, HYPV, do_rd_special, true, a->rd, do_rdstrand_status)
2795af25071cSRichard Henderson 
2796668bb9b7SRichard Henderson static TCGv do_rdpsr(DisasContext *dc, TCGv dst)
2797668bb9b7SRichard Henderson {
2798668bb9b7SRichard Henderson     gen_helper_rdpsr(dst, tcg_env);
2799668bb9b7SRichard Henderson     return dst;
2800668bb9b7SRichard Henderson }
2801668bb9b7SRichard Henderson 
2802668bb9b7SRichard Henderson TRANS(RDPSR, 32, do_rd_special, supervisor(dc), a->rd, do_rdpsr)
2803668bb9b7SRichard Henderson 
2804668bb9b7SRichard Henderson static TCGv do_rdhpstate(DisasContext *dc, TCGv dst)
2805668bb9b7SRichard Henderson {
2806668bb9b7SRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hpstate));
2807668bb9b7SRichard Henderson     return dst;
2808668bb9b7SRichard Henderson }
2809668bb9b7SRichard Henderson 
2810668bb9b7SRichard Henderson TRANS(RDHPR_hpstate, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhpstate)
2811668bb9b7SRichard Henderson 
2812668bb9b7SRichard Henderson static TCGv do_rdhtstate(DisasContext *dc, TCGv dst)
2813668bb9b7SRichard Henderson {
2814668bb9b7SRichard Henderson     TCGv_i32 tl = tcg_temp_new_i32();
2815668bb9b7SRichard Henderson     TCGv_ptr tp = tcg_temp_new_ptr();
2816668bb9b7SRichard Henderson 
2817668bb9b7SRichard Henderson     tcg_gen_ld_i32(tl, tcg_env, env64_field_offsetof(tl));
2818668bb9b7SRichard Henderson     tcg_gen_andi_i32(tl, tl, MAXTL_MASK);
2819668bb9b7SRichard Henderson     tcg_gen_shli_i32(tl, tl, 3);
2820668bb9b7SRichard Henderson     tcg_gen_ext_i32_ptr(tp, tl);
2821668bb9b7SRichard Henderson     tcg_gen_add_ptr(tp, tp, tcg_env);
2822668bb9b7SRichard Henderson 
2823668bb9b7SRichard Henderson     tcg_gen_ld_tl(dst, tp, env64_field_offsetof(htstate));
2824668bb9b7SRichard Henderson     return dst;
2825668bb9b7SRichard Henderson }
2826668bb9b7SRichard Henderson 
2827668bb9b7SRichard Henderson TRANS(RDHPR_htstate, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhtstate)
2828668bb9b7SRichard Henderson 
2829668bb9b7SRichard Henderson static TCGv do_rdhintp(DisasContext *dc, TCGv dst)
2830668bb9b7SRichard Henderson {
28312da789deSRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hintp));
28322da789deSRichard Henderson     return dst;
2833668bb9b7SRichard Henderson }
2834668bb9b7SRichard Henderson 
2835668bb9b7SRichard Henderson TRANS(RDHPR_hintp, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhintp)
2836668bb9b7SRichard Henderson 
2837668bb9b7SRichard Henderson static TCGv do_rdhtba(DisasContext *dc, TCGv dst)
2838668bb9b7SRichard Henderson {
28392da789deSRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(htba));
28402da789deSRichard Henderson     return dst;
2841668bb9b7SRichard Henderson }
2842668bb9b7SRichard Henderson 
2843668bb9b7SRichard Henderson TRANS(RDHPR_htba, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhtba)
2844668bb9b7SRichard Henderson 
2845668bb9b7SRichard Henderson static TCGv do_rdhver(DisasContext *dc, TCGv dst)
2846668bb9b7SRichard Henderson {
28472da789deSRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hver));
28482da789deSRichard Henderson     return dst;
2849668bb9b7SRichard Henderson }
2850668bb9b7SRichard Henderson 
2851668bb9b7SRichard Henderson TRANS(RDHPR_hver, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhver)
2852668bb9b7SRichard Henderson 
2853668bb9b7SRichard Henderson static TCGv do_rdhstick_cmpr(DisasContext *dc, TCGv dst)
2854668bb9b7SRichard Henderson {
2855577efa45SRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hstick_cmpr));
2856577efa45SRichard Henderson     return dst;
2857668bb9b7SRichard Henderson }
2858668bb9b7SRichard Henderson 
2859668bb9b7SRichard Henderson TRANS(RDHPR_hstick_cmpr, HYPV, do_rd_special, hypervisor(dc), a->rd,
2860668bb9b7SRichard Henderson       do_rdhstick_cmpr)
2861668bb9b7SRichard Henderson 
28625d617bfbSRichard Henderson static TCGv do_rdwim(DisasContext *dc, TCGv dst)
28635d617bfbSRichard Henderson {
2864cd6269f7SRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env32_field_offsetof(wim));
2865cd6269f7SRichard Henderson     return dst;
28665d617bfbSRichard Henderson }
28675d617bfbSRichard Henderson 
28685d617bfbSRichard Henderson TRANS(RDWIM, 32, do_rd_special, supervisor(dc), a->rd, do_rdwim)
28695d617bfbSRichard Henderson 
28705d617bfbSRichard Henderson static TCGv do_rdtpc(DisasContext *dc, TCGv dst)
28715d617bfbSRichard Henderson {
28725d617bfbSRichard Henderson #ifdef TARGET_SPARC64
28735d617bfbSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
28745d617bfbSRichard Henderson 
28755d617bfbSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
28765d617bfbSRichard Henderson     tcg_gen_ld_tl(dst, r_tsptr, offsetof(trap_state, tpc));
28775d617bfbSRichard Henderson     return dst;
28785d617bfbSRichard Henderson #else
28795d617bfbSRichard Henderson     qemu_build_not_reached();
28805d617bfbSRichard Henderson #endif
28815d617bfbSRichard Henderson }
28825d617bfbSRichard Henderson 
28835d617bfbSRichard Henderson TRANS(RDPR_tpc, 64, do_rd_special, supervisor(dc), a->rd, do_rdtpc)
28845d617bfbSRichard Henderson 
28855d617bfbSRichard Henderson static TCGv do_rdtnpc(DisasContext *dc, TCGv dst)
28865d617bfbSRichard Henderson {
28875d617bfbSRichard Henderson #ifdef TARGET_SPARC64
28885d617bfbSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
28895d617bfbSRichard Henderson 
28905d617bfbSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
28915d617bfbSRichard Henderson     tcg_gen_ld_tl(dst, r_tsptr, offsetof(trap_state, tnpc));
28925d617bfbSRichard Henderson     return dst;
28935d617bfbSRichard Henderson #else
28945d617bfbSRichard Henderson     qemu_build_not_reached();
28955d617bfbSRichard Henderson #endif
28965d617bfbSRichard Henderson }
28975d617bfbSRichard Henderson 
28985d617bfbSRichard Henderson TRANS(RDPR_tnpc, 64, do_rd_special, supervisor(dc), a->rd, do_rdtnpc)
28995d617bfbSRichard Henderson 
29005d617bfbSRichard Henderson static TCGv do_rdtstate(DisasContext *dc, TCGv dst)
29015d617bfbSRichard Henderson {
29025d617bfbSRichard Henderson #ifdef TARGET_SPARC64
29035d617bfbSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
29045d617bfbSRichard Henderson 
29055d617bfbSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
29065d617bfbSRichard Henderson     tcg_gen_ld_tl(dst, r_tsptr, offsetof(trap_state, tstate));
29075d617bfbSRichard Henderson     return dst;
29085d617bfbSRichard Henderson #else
29095d617bfbSRichard Henderson     qemu_build_not_reached();
29105d617bfbSRichard Henderson #endif
29115d617bfbSRichard Henderson }
29125d617bfbSRichard Henderson 
29135d617bfbSRichard Henderson TRANS(RDPR_tstate, 64, do_rd_special, supervisor(dc), a->rd, do_rdtstate)
29145d617bfbSRichard Henderson 
29155d617bfbSRichard Henderson static TCGv do_rdtt(DisasContext *dc, TCGv dst)
29165d617bfbSRichard Henderson {
29175d617bfbSRichard Henderson #ifdef TARGET_SPARC64
29185d617bfbSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
29195d617bfbSRichard Henderson 
29205d617bfbSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
29215d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, r_tsptr, offsetof(trap_state, tt));
29225d617bfbSRichard Henderson     return dst;
29235d617bfbSRichard Henderson #else
29245d617bfbSRichard Henderson     qemu_build_not_reached();
29255d617bfbSRichard Henderson #endif
29265d617bfbSRichard Henderson }
29275d617bfbSRichard Henderson 
29285d617bfbSRichard Henderson TRANS(RDPR_tt, 64, do_rd_special, supervisor(dc), a->rd, do_rdtt)
29295d617bfbSRichard Henderson TRANS(RDPR_tick, 64, do_rd_special, supervisor(dc), a->rd, do_rdtick)
29305d617bfbSRichard Henderson 
29315d617bfbSRichard Henderson static TCGv do_rdtba(DisasContext *dc, TCGv dst)
29325d617bfbSRichard Henderson {
29335d617bfbSRichard Henderson     return cpu_tbr;
29345d617bfbSRichard Henderson }
29355d617bfbSRichard Henderson 
2936e8325dc0SRichard Henderson TRANS(RDTBR, 32, do_rd_special, supervisor(dc), a->rd, do_rdtba)
29375d617bfbSRichard Henderson TRANS(RDPR_tba, 64, do_rd_special, supervisor(dc), a->rd, do_rdtba)
29385d617bfbSRichard Henderson 
29395d617bfbSRichard Henderson static TCGv do_rdpstate(DisasContext *dc, TCGv dst)
29405d617bfbSRichard Henderson {
29415d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(pstate));
29425d617bfbSRichard Henderson     return dst;
29435d617bfbSRichard Henderson }
29445d617bfbSRichard Henderson 
29455d617bfbSRichard Henderson TRANS(RDPR_pstate, 64, do_rd_special, supervisor(dc), a->rd, do_rdpstate)
29465d617bfbSRichard Henderson 
29475d617bfbSRichard Henderson static TCGv do_rdtl(DisasContext *dc, TCGv dst)
29485d617bfbSRichard Henderson {
29495d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(tl));
29505d617bfbSRichard Henderson     return dst;
29515d617bfbSRichard Henderson }
29525d617bfbSRichard Henderson 
29535d617bfbSRichard Henderson TRANS(RDPR_tl, 64, do_rd_special, supervisor(dc), a->rd, do_rdtl)
29545d617bfbSRichard Henderson 
29555d617bfbSRichard Henderson static TCGv do_rdpil(DisasContext *dc, TCGv dst)
29565d617bfbSRichard Henderson {
29575d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env_field_offsetof(psrpil));
29585d617bfbSRichard Henderson     return dst;
29595d617bfbSRichard Henderson }
29605d617bfbSRichard Henderson 
29615d617bfbSRichard Henderson TRANS(RDPR_pil, 64, do_rd_special, supervisor(dc), a->rd, do_rdpil)
29625d617bfbSRichard Henderson 
29635d617bfbSRichard Henderson static TCGv do_rdcwp(DisasContext *dc, TCGv dst)
29645d617bfbSRichard Henderson {
29655d617bfbSRichard Henderson     gen_helper_rdcwp(dst, tcg_env);
29665d617bfbSRichard Henderson     return dst;
29675d617bfbSRichard Henderson }
29685d617bfbSRichard Henderson 
29695d617bfbSRichard Henderson TRANS(RDPR_cwp, 64, do_rd_special, supervisor(dc), a->rd, do_rdcwp)
29705d617bfbSRichard Henderson 
29715d617bfbSRichard Henderson static TCGv do_rdcansave(DisasContext *dc, TCGv dst)
29725d617bfbSRichard Henderson {
29735d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(cansave));
29745d617bfbSRichard Henderson     return dst;
29755d617bfbSRichard Henderson }
29765d617bfbSRichard Henderson 
29775d617bfbSRichard Henderson TRANS(RDPR_cansave, 64, do_rd_special, supervisor(dc), a->rd, do_rdcansave)
29785d617bfbSRichard Henderson 
29795d617bfbSRichard Henderson static TCGv do_rdcanrestore(DisasContext *dc, TCGv dst)
29805d617bfbSRichard Henderson {
29815d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(canrestore));
29825d617bfbSRichard Henderson     return dst;
29835d617bfbSRichard Henderson }
29845d617bfbSRichard Henderson 
29855d617bfbSRichard Henderson TRANS(RDPR_canrestore, 64, do_rd_special, supervisor(dc), a->rd,
29865d617bfbSRichard Henderson       do_rdcanrestore)
29875d617bfbSRichard Henderson 
29885d617bfbSRichard Henderson static TCGv do_rdcleanwin(DisasContext *dc, TCGv dst)
29895d617bfbSRichard Henderson {
29905d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(cleanwin));
29915d617bfbSRichard Henderson     return dst;
29925d617bfbSRichard Henderson }
29935d617bfbSRichard Henderson 
29945d617bfbSRichard Henderson TRANS(RDPR_cleanwin, 64, do_rd_special, supervisor(dc), a->rd, do_rdcleanwin)
29955d617bfbSRichard Henderson 
29965d617bfbSRichard Henderson static TCGv do_rdotherwin(DisasContext *dc, TCGv dst)
29975d617bfbSRichard Henderson {
29985d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(otherwin));
29995d617bfbSRichard Henderson     return dst;
30005d617bfbSRichard Henderson }
30015d617bfbSRichard Henderson 
30025d617bfbSRichard Henderson TRANS(RDPR_otherwin, 64, do_rd_special, supervisor(dc), a->rd, do_rdotherwin)
30035d617bfbSRichard Henderson 
30045d617bfbSRichard Henderson static TCGv do_rdwstate(DisasContext *dc, TCGv dst)
30055d617bfbSRichard Henderson {
30065d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(wstate));
30075d617bfbSRichard Henderson     return dst;
30085d617bfbSRichard Henderson }
30095d617bfbSRichard Henderson 
30105d617bfbSRichard Henderson TRANS(RDPR_wstate, 64, do_rd_special, supervisor(dc), a->rd, do_rdwstate)
30115d617bfbSRichard Henderson 
30125d617bfbSRichard Henderson static TCGv do_rdgl(DisasContext *dc, TCGv dst)
30135d617bfbSRichard Henderson {
30145d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(gl));
30155d617bfbSRichard Henderson     return dst;
30165d617bfbSRichard Henderson }
30175d617bfbSRichard Henderson 
30185d617bfbSRichard Henderson TRANS(RDPR_gl, GL, do_rd_special, supervisor(dc), a->rd, do_rdgl)
30195d617bfbSRichard Henderson 
30205d617bfbSRichard Henderson /* UA2005 strand status */
30215d617bfbSRichard Henderson static TCGv do_rdssr(DisasContext *dc, TCGv dst)
30225d617bfbSRichard Henderson {
30232da789deSRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(ssr));
30242da789deSRichard Henderson     return dst;
30255d617bfbSRichard Henderson }
30265d617bfbSRichard Henderson 
30275d617bfbSRichard Henderson TRANS(RDPR_strand_status, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdssr)
30285d617bfbSRichard Henderson 
30295d617bfbSRichard Henderson static TCGv do_rdver(DisasContext *dc, TCGv dst)
30305d617bfbSRichard Henderson {
30312da789deSRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(version));
30322da789deSRichard Henderson     return dst;
30335d617bfbSRichard Henderson }
30345d617bfbSRichard Henderson 
30355d617bfbSRichard Henderson TRANS(RDPR_ver, 64, do_rd_special, supervisor(dc), a->rd, do_rdver)
30365d617bfbSRichard Henderson 
3037e8325dc0SRichard Henderson static bool trans_FLUSHW(DisasContext *dc, arg_FLUSHW *a)
3038e8325dc0SRichard Henderson {
3039e8325dc0SRichard Henderson     if (avail_64(dc)) {
3040e8325dc0SRichard Henderson         gen_helper_flushw(tcg_env);
3041e8325dc0SRichard Henderson         return advance_pc(dc);
3042e8325dc0SRichard Henderson     }
3043e8325dc0SRichard Henderson     return false;
3044e8325dc0SRichard Henderson }
3045e8325dc0SRichard Henderson 
30460faef01bSRichard Henderson static bool do_wr_special(DisasContext *dc, arg_r_r_ri *a, bool priv,
30470faef01bSRichard Henderson                           void (*func)(DisasContext *, TCGv))
30480faef01bSRichard Henderson {
30490faef01bSRichard Henderson     TCGv src;
30500faef01bSRichard Henderson 
30510faef01bSRichard Henderson     /* For simplicity, we under-decoded the rs2 form. */
30520faef01bSRichard Henderson     if (!a->imm && (a->rs2_or_imm & ~0x1f)) {
30530faef01bSRichard Henderson         return false;
30540faef01bSRichard Henderson     }
30550faef01bSRichard Henderson     if (!priv) {
30560faef01bSRichard Henderson         return raise_priv(dc);
30570faef01bSRichard Henderson     }
30580faef01bSRichard Henderson 
30590faef01bSRichard Henderson     if (a->rs1 == 0 && (a->imm || a->rs2_or_imm == 0)) {
30600faef01bSRichard Henderson         src = tcg_constant_tl(a->rs2_or_imm);
30610faef01bSRichard Henderson     } else {
30620faef01bSRichard Henderson         TCGv src1 = gen_load_gpr(dc, a->rs1);
30630faef01bSRichard Henderson         if (a->rs2_or_imm == 0) {
30640faef01bSRichard Henderson             src = src1;
30650faef01bSRichard Henderson         } else {
30660faef01bSRichard Henderson             src = tcg_temp_new();
30670faef01bSRichard Henderson             if (a->imm) {
30680faef01bSRichard Henderson                 tcg_gen_xori_tl(src, src1, a->rs2_or_imm);
30690faef01bSRichard Henderson             } else {
30700faef01bSRichard Henderson                 tcg_gen_xor_tl(src, src1, gen_load_gpr(dc, a->rs2_or_imm));
30710faef01bSRichard Henderson             }
30720faef01bSRichard Henderson         }
30730faef01bSRichard Henderson     }
30740faef01bSRichard Henderson     func(dc, src);
30750faef01bSRichard Henderson     return advance_pc(dc);
30760faef01bSRichard Henderson }
30770faef01bSRichard Henderson 
30780faef01bSRichard Henderson static void do_wry(DisasContext *dc, TCGv src)
30790faef01bSRichard Henderson {
30800faef01bSRichard Henderson     tcg_gen_ext32u_tl(cpu_y, src);
30810faef01bSRichard Henderson }
30820faef01bSRichard Henderson 
30830faef01bSRichard Henderson TRANS(WRY, ALL, do_wr_special, a, true, do_wry)
30840faef01bSRichard Henderson 
30850faef01bSRichard Henderson static void do_wrccr(DisasContext *dc, TCGv src)
30860faef01bSRichard Henderson {
30870faef01bSRichard Henderson     gen_helper_wrccr(tcg_env, src);
30880faef01bSRichard Henderson }
30890faef01bSRichard Henderson 
30900faef01bSRichard Henderson TRANS(WRCCR, 64, do_wr_special, a, true, do_wrccr)
30910faef01bSRichard Henderson 
30920faef01bSRichard Henderson static void do_wrasi(DisasContext *dc, TCGv src)
30930faef01bSRichard Henderson {
30940faef01bSRichard Henderson     TCGv tmp = tcg_temp_new();
30950faef01bSRichard Henderson 
30960faef01bSRichard Henderson     tcg_gen_ext8u_tl(tmp, src);
30970faef01bSRichard Henderson     tcg_gen_st32_tl(tmp, tcg_env, env64_field_offsetof(asi));
30980faef01bSRichard Henderson     /* End TB to notice changed ASI. */
30990faef01bSRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
31000faef01bSRichard Henderson }
31010faef01bSRichard Henderson 
31020faef01bSRichard Henderson TRANS(WRASI, 64, do_wr_special, a, true, do_wrasi)
31030faef01bSRichard Henderson 
31040faef01bSRichard Henderson static void do_wrfprs(DisasContext *dc, TCGv src)
31050faef01bSRichard Henderson {
31060faef01bSRichard Henderson #ifdef TARGET_SPARC64
31070faef01bSRichard Henderson     tcg_gen_trunc_tl_i32(cpu_fprs, src);
31080faef01bSRichard Henderson     dc->fprs_dirty = 0;
31090faef01bSRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
31100faef01bSRichard Henderson #else
31110faef01bSRichard Henderson     qemu_build_not_reached();
31120faef01bSRichard Henderson #endif
31130faef01bSRichard Henderson }
31140faef01bSRichard Henderson 
31150faef01bSRichard Henderson TRANS(WRFPRS, 64, do_wr_special, a, true, do_wrfprs)
31160faef01bSRichard Henderson 
31170faef01bSRichard Henderson static void do_wrgsr(DisasContext *dc, TCGv src)
31180faef01bSRichard Henderson {
31190faef01bSRichard Henderson     gen_trap_ifnofpu(dc);
31200faef01bSRichard Henderson     tcg_gen_mov_tl(cpu_gsr, src);
31210faef01bSRichard Henderson }
31220faef01bSRichard Henderson 
31230faef01bSRichard Henderson TRANS(WRGSR, 64, do_wr_special, a, true, do_wrgsr)
31240faef01bSRichard Henderson 
31250faef01bSRichard Henderson static void do_wrsoftint_set(DisasContext *dc, TCGv src)
31260faef01bSRichard Henderson {
31270faef01bSRichard Henderson     gen_helper_set_softint(tcg_env, src);
31280faef01bSRichard Henderson }
31290faef01bSRichard Henderson 
31300faef01bSRichard Henderson TRANS(WRSOFTINT_SET, 64, do_wr_special, a, supervisor(dc), do_wrsoftint_set)
31310faef01bSRichard Henderson 
31320faef01bSRichard Henderson static void do_wrsoftint_clr(DisasContext *dc, TCGv src)
31330faef01bSRichard Henderson {
31340faef01bSRichard Henderson     gen_helper_clear_softint(tcg_env, src);
31350faef01bSRichard Henderson }
31360faef01bSRichard Henderson 
31370faef01bSRichard Henderson TRANS(WRSOFTINT_CLR, 64, do_wr_special, a, supervisor(dc), do_wrsoftint_clr)
31380faef01bSRichard Henderson 
31390faef01bSRichard Henderson static void do_wrsoftint(DisasContext *dc, TCGv src)
31400faef01bSRichard Henderson {
31410faef01bSRichard Henderson     gen_helper_write_softint(tcg_env, src);
31420faef01bSRichard Henderson }
31430faef01bSRichard Henderson 
31440faef01bSRichard Henderson TRANS(WRSOFTINT, 64, do_wr_special, a, supervisor(dc), do_wrsoftint)
31450faef01bSRichard Henderson 
31460faef01bSRichard Henderson static void do_wrtick_cmpr(DisasContext *dc, TCGv src)
31470faef01bSRichard Henderson {
31480faef01bSRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
31490faef01bSRichard Henderson 
3150577efa45SRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(tick_cmpr));
3151577efa45SRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(tick));
31520faef01bSRichard Henderson     translator_io_start(&dc->base);
3153577efa45SRichard Henderson     gen_helper_tick_set_limit(r_tickptr, src);
31540faef01bSRichard Henderson     /* End TB to handle timer interrupt */
31550faef01bSRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
31560faef01bSRichard Henderson }
31570faef01bSRichard Henderson 
31580faef01bSRichard Henderson TRANS(WRTICK_CMPR, 64, do_wr_special, a, supervisor(dc), do_wrtick_cmpr)
31590faef01bSRichard Henderson 
31600faef01bSRichard Henderson static void do_wrstick(DisasContext *dc, TCGv src)
31610faef01bSRichard Henderson {
31620faef01bSRichard Henderson #ifdef TARGET_SPARC64
31630faef01bSRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
31640faef01bSRichard Henderson 
31650faef01bSRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, offsetof(CPUSPARCState, stick));
31660faef01bSRichard Henderson     translator_io_start(&dc->base);
31670faef01bSRichard Henderson     gen_helper_tick_set_count(r_tickptr, src);
31680faef01bSRichard Henderson     /* End TB to handle timer interrupt */
31690faef01bSRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
31700faef01bSRichard Henderson #else
31710faef01bSRichard Henderson     qemu_build_not_reached();
31720faef01bSRichard Henderson #endif
31730faef01bSRichard Henderson }
31740faef01bSRichard Henderson 
31750faef01bSRichard Henderson TRANS(WRSTICK, 64, do_wr_special, a, supervisor(dc), do_wrstick)
31760faef01bSRichard Henderson 
31770faef01bSRichard Henderson static void do_wrstick_cmpr(DisasContext *dc, TCGv src)
31780faef01bSRichard Henderson {
31790faef01bSRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
31800faef01bSRichard Henderson 
3181577efa45SRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(stick_cmpr));
3182577efa45SRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(stick));
31830faef01bSRichard Henderson     translator_io_start(&dc->base);
3184577efa45SRichard Henderson     gen_helper_tick_set_limit(r_tickptr, src);
31850faef01bSRichard Henderson     /* End TB to handle timer interrupt */
31860faef01bSRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
31870faef01bSRichard Henderson }
31880faef01bSRichard Henderson 
31890faef01bSRichard Henderson TRANS(WRSTICK_CMPR, 64, do_wr_special, a, supervisor(dc), do_wrstick_cmpr)
31900faef01bSRichard Henderson 
31910faef01bSRichard Henderson static void do_wrpowerdown(DisasContext *dc, TCGv src)
31920faef01bSRichard Henderson {
319389527e3aSRichard Henderson     finishing_insn(dc);
31940faef01bSRichard Henderson     save_state(dc);
31950faef01bSRichard Henderson     gen_helper_power_down(tcg_env);
31960faef01bSRichard Henderson }
31970faef01bSRichard Henderson 
31980faef01bSRichard Henderson TRANS(WRPOWERDOWN, POWERDOWN, do_wr_special, a, supervisor(dc), do_wrpowerdown)
31990faef01bSRichard Henderson 
320025524734SRichard Henderson static void do_wrpsr(DisasContext *dc, TCGv src)
320125524734SRichard Henderson {
320225524734SRichard Henderson     gen_helper_wrpsr(tcg_env, src);
320325524734SRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
320425524734SRichard Henderson }
320525524734SRichard Henderson 
320625524734SRichard Henderson TRANS(WRPSR, 32, do_wr_special, a, supervisor(dc), do_wrpsr)
320725524734SRichard Henderson 
32089422278eSRichard Henderson static void do_wrwim(DisasContext *dc, TCGv src)
32099422278eSRichard Henderson {
32109422278eSRichard Henderson     target_ulong mask = MAKE_64BIT_MASK(0, dc->def->nwindows);
3211cd6269f7SRichard Henderson     TCGv tmp = tcg_temp_new();
3212cd6269f7SRichard Henderson 
3213cd6269f7SRichard Henderson     tcg_gen_andi_tl(tmp, src, mask);
3214cd6269f7SRichard Henderson     tcg_gen_st_tl(tmp, tcg_env, env32_field_offsetof(wim));
32159422278eSRichard Henderson }
32169422278eSRichard Henderson 
32179422278eSRichard Henderson TRANS(WRWIM, 32, do_wr_special, a, supervisor(dc), do_wrwim)
32189422278eSRichard Henderson 
32199422278eSRichard Henderson static void do_wrtpc(DisasContext *dc, TCGv src)
32209422278eSRichard Henderson {
32219422278eSRichard Henderson #ifdef TARGET_SPARC64
32229422278eSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
32239422278eSRichard Henderson 
32249422278eSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
32259422278eSRichard Henderson     tcg_gen_st_tl(src, r_tsptr, offsetof(trap_state, tpc));
32269422278eSRichard Henderson #else
32279422278eSRichard Henderson     qemu_build_not_reached();
32289422278eSRichard Henderson #endif
32299422278eSRichard Henderson }
32309422278eSRichard Henderson 
32319422278eSRichard Henderson TRANS(WRPR_tpc, 64, do_wr_special, a, supervisor(dc), do_wrtpc)
32329422278eSRichard Henderson 
32339422278eSRichard Henderson static void do_wrtnpc(DisasContext *dc, TCGv src)
32349422278eSRichard Henderson {
32359422278eSRichard Henderson #ifdef TARGET_SPARC64
32369422278eSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
32379422278eSRichard Henderson 
32389422278eSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
32399422278eSRichard Henderson     tcg_gen_st_tl(src, r_tsptr, offsetof(trap_state, tnpc));
32409422278eSRichard Henderson #else
32419422278eSRichard Henderson     qemu_build_not_reached();
32429422278eSRichard Henderson #endif
32439422278eSRichard Henderson }
32449422278eSRichard Henderson 
32459422278eSRichard Henderson TRANS(WRPR_tnpc, 64, do_wr_special, a, supervisor(dc), do_wrtnpc)
32469422278eSRichard Henderson 
32479422278eSRichard Henderson static void do_wrtstate(DisasContext *dc, TCGv src)
32489422278eSRichard Henderson {
32499422278eSRichard Henderson #ifdef TARGET_SPARC64
32509422278eSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
32519422278eSRichard Henderson 
32529422278eSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
32539422278eSRichard Henderson     tcg_gen_st_tl(src, r_tsptr, offsetof(trap_state, tstate));
32549422278eSRichard Henderson #else
32559422278eSRichard Henderson     qemu_build_not_reached();
32569422278eSRichard Henderson #endif
32579422278eSRichard Henderson }
32589422278eSRichard Henderson 
32599422278eSRichard Henderson TRANS(WRPR_tstate, 64, do_wr_special, a, supervisor(dc), do_wrtstate)
32609422278eSRichard Henderson 
32619422278eSRichard Henderson static void do_wrtt(DisasContext *dc, TCGv src)
32629422278eSRichard Henderson {
32639422278eSRichard Henderson #ifdef TARGET_SPARC64
32649422278eSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
32659422278eSRichard Henderson 
32669422278eSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
32679422278eSRichard Henderson     tcg_gen_st32_tl(src, r_tsptr, offsetof(trap_state, tt));
32689422278eSRichard Henderson #else
32699422278eSRichard Henderson     qemu_build_not_reached();
32709422278eSRichard Henderson #endif
32719422278eSRichard Henderson }
32729422278eSRichard Henderson 
32739422278eSRichard Henderson TRANS(WRPR_tt, 64, do_wr_special, a, supervisor(dc), do_wrtt)
32749422278eSRichard Henderson 
32759422278eSRichard Henderson static void do_wrtick(DisasContext *dc, TCGv src)
32769422278eSRichard Henderson {
32779422278eSRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
32789422278eSRichard Henderson 
32799422278eSRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(tick));
32809422278eSRichard Henderson     translator_io_start(&dc->base);
32819422278eSRichard Henderson     gen_helper_tick_set_count(r_tickptr, src);
32829422278eSRichard Henderson     /* End TB to handle timer interrupt */
32839422278eSRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
32849422278eSRichard Henderson }
32859422278eSRichard Henderson 
32869422278eSRichard Henderson TRANS(WRPR_tick, 64, do_wr_special, a, supervisor(dc), do_wrtick)
32879422278eSRichard Henderson 
32889422278eSRichard Henderson static void do_wrtba(DisasContext *dc, TCGv src)
32899422278eSRichard Henderson {
32909422278eSRichard Henderson     tcg_gen_mov_tl(cpu_tbr, src);
32919422278eSRichard Henderson }
32929422278eSRichard Henderson 
32939422278eSRichard Henderson TRANS(WRPR_tba, 64, do_wr_special, a, supervisor(dc), do_wrtba)
32949422278eSRichard Henderson 
32959422278eSRichard Henderson static void do_wrpstate(DisasContext *dc, TCGv src)
32969422278eSRichard Henderson {
32979422278eSRichard Henderson     save_state(dc);
32989422278eSRichard Henderson     if (translator_io_start(&dc->base)) {
32999422278eSRichard Henderson         dc->base.is_jmp = DISAS_EXIT;
33009422278eSRichard Henderson     }
33019422278eSRichard Henderson     gen_helper_wrpstate(tcg_env, src);
33029422278eSRichard Henderson     dc->npc = DYNAMIC_PC;
33039422278eSRichard Henderson }
33049422278eSRichard Henderson 
33059422278eSRichard Henderson TRANS(WRPR_pstate, 64, do_wr_special, a, supervisor(dc), do_wrpstate)
33069422278eSRichard Henderson 
33079422278eSRichard Henderson static void do_wrtl(DisasContext *dc, TCGv src)
33089422278eSRichard Henderson {
33099422278eSRichard Henderson     save_state(dc);
33109422278eSRichard Henderson     tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(tl));
33119422278eSRichard Henderson     dc->npc = DYNAMIC_PC;
33129422278eSRichard Henderson }
33139422278eSRichard Henderson 
33149422278eSRichard Henderson TRANS(WRPR_tl, 64, do_wr_special, a, supervisor(dc), do_wrtl)
33159422278eSRichard Henderson 
33169422278eSRichard Henderson static void do_wrpil(DisasContext *dc, TCGv src)
33179422278eSRichard Henderson {
33189422278eSRichard Henderson     if (translator_io_start(&dc->base)) {
33199422278eSRichard Henderson         dc->base.is_jmp = DISAS_EXIT;
33209422278eSRichard Henderson     }
33219422278eSRichard Henderson     gen_helper_wrpil(tcg_env, src);
33229422278eSRichard Henderson }
33239422278eSRichard Henderson 
33249422278eSRichard Henderson TRANS(WRPR_pil, 64, do_wr_special, a, supervisor(dc), do_wrpil)
33259422278eSRichard Henderson 
33269422278eSRichard Henderson static void do_wrcwp(DisasContext *dc, TCGv src)
33279422278eSRichard Henderson {
33289422278eSRichard Henderson     gen_helper_wrcwp(tcg_env, src);
33299422278eSRichard Henderson }
33309422278eSRichard Henderson 
33319422278eSRichard Henderson TRANS(WRPR_cwp, 64, do_wr_special, a, supervisor(dc), do_wrcwp)
33329422278eSRichard Henderson 
33339422278eSRichard Henderson static void do_wrcansave(DisasContext *dc, TCGv src)
33349422278eSRichard Henderson {
33359422278eSRichard Henderson     tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(cansave));
33369422278eSRichard Henderson }
33379422278eSRichard Henderson 
33389422278eSRichard Henderson TRANS(WRPR_cansave, 64, do_wr_special, a, supervisor(dc), do_wrcansave)
33399422278eSRichard Henderson 
33409422278eSRichard Henderson static void do_wrcanrestore(DisasContext *dc, TCGv src)
33419422278eSRichard Henderson {
33429422278eSRichard Henderson     tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(canrestore));
33439422278eSRichard Henderson }
33449422278eSRichard Henderson 
33459422278eSRichard Henderson TRANS(WRPR_canrestore, 64, do_wr_special, a, supervisor(dc), do_wrcanrestore)
33469422278eSRichard Henderson 
33479422278eSRichard Henderson static void do_wrcleanwin(DisasContext *dc, TCGv src)
33489422278eSRichard Henderson {
33499422278eSRichard Henderson     tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(cleanwin));
33509422278eSRichard Henderson }
33519422278eSRichard Henderson 
33529422278eSRichard Henderson TRANS(WRPR_cleanwin, 64, do_wr_special, a, supervisor(dc), do_wrcleanwin)
33539422278eSRichard Henderson 
33549422278eSRichard Henderson static void do_wrotherwin(DisasContext *dc, TCGv src)
33559422278eSRichard Henderson {
33569422278eSRichard Henderson     tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(otherwin));
33579422278eSRichard Henderson }
33589422278eSRichard Henderson 
33599422278eSRichard Henderson TRANS(WRPR_otherwin, 64, do_wr_special, a, supervisor(dc), do_wrotherwin)
33609422278eSRichard Henderson 
33619422278eSRichard Henderson static void do_wrwstate(DisasContext *dc, TCGv src)
33629422278eSRichard Henderson {
33639422278eSRichard Henderson     tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(wstate));
33649422278eSRichard Henderson }
33659422278eSRichard Henderson 
33669422278eSRichard Henderson TRANS(WRPR_wstate, 64, do_wr_special, a, supervisor(dc), do_wrwstate)
33679422278eSRichard Henderson 
33689422278eSRichard Henderson static void do_wrgl(DisasContext *dc, TCGv src)
33699422278eSRichard Henderson {
33709422278eSRichard Henderson     gen_helper_wrgl(tcg_env, src);
33719422278eSRichard Henderson }
33729422278eSRichard Henderson 
33739422278eSRichard Henderson TRANS(WRPR_gl, GL, do_wr_special, a, supervisor(dc), do_wrgl)
33749422278eSRichard Henderson 
33759422278eSRichard Henderson /* UA2005 strand status */
33769422278eSRichard Henderson static void do_wrssr(DisasContext *dc, TCGv src)
33779422278eSRichard Henderson {
33782da789deSRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(ssr));
33799422278eSRichard Henderson }
33809422278eSRichard Henderson 
33819422278eSRichard Henderson TRANS(WRPR_strand_status, HYPV, do_wr_special, a, hypervisor(dc), do_wrssr)
33829422278eSRichard Henderson 
3383bb97f2f5SRichard Henderson TRANS(WRTBR, 32, do_wr_special, a, supervisor(dc), do_wrtba)
3384bb97f2f5SRichard Henderson 
3385bb97f2f5SRichard Henderson static void do_wrhpstate(DisasContext *dc, TCGv src)
3386bb97f2f5SRichard Henderson {
3387bb97f2f5SRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(hpstate));
3388bb97f2f5SRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
3389bb97f2f5SRichard Henderson }
3390bb97f2f5SRichard Henderson 
3391bb97f2f5SRichard Henderson TRANS(WRHPR_hpstate, HYPV, do_wr_special, a, hypervisor(dc), do_wrhpstate)
3392bb97f2f5SRichard Henderson 
3393bb97f2f5SRichard Henderson static void do_wrhtstate(DisasContext *dc, TCGv src)
3394bb97f2f5SRichard Henderson {
3395bb97f2f5SRichard Henderson     TCGv_i32 tl = tcg_temp_new_i32();
3396bb97f2f5SRichard Henderson     TCGv_ptr tp = tcg_temp_new_ptr();
3397bb97f2f5SRichard Henderson 
3398bb97f2f5SRichard Henderson     tcg_gen_ld_i32(tl, tcg_env, env64_field_offsetof(tl));
3399bb97f2f5SRichard Henderson     tcg_gen_andi_i32(tl, tl, MAXTL_MASK);
3400bb97f2f5SRichard Henderson     tcg_gen_shli_i32(tl, tl, 3);
3401bb97f2f5SRichard Henderson     tcg_gen_ext_i32_ptr(tp, tl);
3402bb97f2f5SRichard Henderson     tcg_gen_add_ptr(tp, tp, tcg_env);
3403bb97f2f5SRichard Henderson 
3404bb97f2f5SRichard Henderson     tcg_gen_st_tl(src, tp, env64_field_offsetof(htstate));
3405bb97f2f5SRichard Henderson }
3406bb97f2f5SRichard Henderson 
3407bb97f2f5SRichard Henderson TRANS(WRHPR_htstate, HYPV, do_wr_special, a, hypervisor(dc), do_wrhtstate)
3408bb97f2f5SRichard Henderson 
3409bb97f2f5SRichard Henderson static void do_wrhintp(DisasContext *dc, TCGv src)
3410bb97f2f5SRichard Henderson {
34112da789deSRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(hintp));
3412bb97f2f5SRichard Henderson }
3413bb97f2f5SRichard Henderson 
3414bb97f2f5SRichard Henderson TRANS(WRHPR_hintp, HYPV, do_wr_special, a, hypervisor(dc), do_wrhintp)
3415bb97f2f5SRichard Henderson 
3416bb97f2f5SRichard Henderson static void do_wrhtba(DisasContext *dc, TCGv src)
3417bb97f2f5SRichard Henderson {
34182da789deSRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(htba));
3419bb97f2f5SRichard Henderson }
3420bb97f2f5SRichard Henderson 
3421bb97f2f5SRichard Henderson TRANS(WRHPR_htba, HYPV, do_wr_special, a, hypervisor(dc), do_wrhtba)
3422bb97f2f5SRichard Henderson 
3423bb97f2f5SRichard Henderson static void do_wrhstick_cmpr(DisasContext *dc, TCGv src)
3424bb97f2f5SRichard Henderson {
3425bb97f2f5SRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
3426bb97f2f5SRichard Henderson 
3427577efa45SRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(hstick_cmpr));
3428bb97f2f5SRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(hstick));
3429bb97f2f5SRichard Henderson     translator_io_start(&dc->base);
3430577efa45SRichard Henderson     gen_helper_tick_set_limit(r_tickptr, src);
3431bb97f2f5SRichard Henderson     /* End TB to handle timer interrupt */
3432bb97f2f5SRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
3433bb97f2f5SRichard Henderson }
3434bb97f2f5SRichard Henderson 
3435bb97f2f5SRichard Henderson TRANS(WRHPR_hstick_cmpr, HYPV, do_wr_special, a, hypervisor(dc),
3436bb97f2f5SRichard Henderson       do_wrhstick_cmpr)
3437bb97f2f5SRichard Henderson 
343825524734SRichard Henderson static bool do_saved_restored(DisasContext *dc, bool saved)
343925524734SRichard Henderson {
344025524734SRichard Henderson     if (!supervisor(dc)) {
344125524734SRichard Henderson         return raise_priv(dc);
344225524734SRichard Henderson     }
344325524734SRichard Henderson     if (saved) {
344425524734SRichard Henderson         gen_helper_saved(tcg_env);
344525524734SRichard Henderson     } else {
344625524734SRichard Henderson         gen_helper_restored(tcg_env);
344725524734SRichard Henderson     }
344825524734SRichard Henderson     return advance_pc(dc);
344925524734SRichard Henderson }
345025524734SRichard Henderson 
345125524734SRichard Henderson TRANS(SAVED, 64, do_saved_restored, true)
345225524734SRichard Henderson TRANS(RESTORED, 64, do_saved_restored, false)
345325524734SRichard Henderson 
3454d3825800SRichard Henderson static bool trans_NOP(DisasContext *dc, arg_NOP *a)
3455d3825800SRichard Henderson {
3456d3825800SRichard Henderson     return advance_pc(dc);
3457d3825800SRichard Henderson }
3458d3825800SRichard Henderson 
34590faef01bSRichard Henderson /*
34600faef01bSRichard Henderson  * TODO: Need a feature bit for sparcv8.
34610faef01bSRichard Henderson  * In the meantime, treat all 32-bit cpus like sparcv7.
34620faef01bSRichard Henderson  */
34635458fd31SRichard Henderson TRANS(NOP_v7, 32, trans_NOP, a)
34645458fd31SRichard Henderson TRANS(NOP_v9, 64, trans_NOP, a)
34650faef01bSRichard Henderson 
3466b597eedcSRichard Henderson static bool do_arith_int(DisasContext *dc, arg_r_r_ri_cc *a,
3467428881deSRichard Henderson                          void (*func)(TCGv, TCGv, TCGv),
34682a45b736SRichard Henderson                          void (*funci)(TCGv, TCGv, target_long),
34692a45b736SRichard Henderson                          bool logic_cc)
3470428881deSRichard Henderson {
3471428881deSRichard Henderson     TCGv dst, src1;
3472428881deSRichard Henderson 
3473428881deSRichard Henderson     /* For simplicity, we under-decoded the rs2 form. */
3474428881deSRichard Henderson     if (!a->imm && a->rs2_or_imm & ~0x1f) {
3475428881deSRichard Henderson         return false;
3476428881deSRichard Henderson     }
3477428881deSRichard Henderson 
34782a45b736SRichard Henderson     if (logic_cc) {
34792a45b736SRichard Henderson         dst = cpu_cc_N;
3480428881deSRichard Henderson     } else {
3481428881deSRichard Henderson         dst = gen_dest_gpr(dc, a->rd);
3482428881deSRichard Henderson     }
3483428881deSRichard Henderson     src1 = gen_load_gpr(dc, a->rs1);
3484428881deSRichard Henderson 
3485428881deSRichard Henderson     if (a->imm || a->rs2_or_imm == 0) {
3486428881deSRichard Henderson         if (funci) {
3487428881deSRichard Henderson             funci(dst, src1, a->rs2_or_imm);
3488428881deSRichard Henderson         } else {
3489428881deSRichard Henderson             func(dst, src1, tcg_constant_tl(a->rs2_or_imm));
3490428881deSRichard Henderson         }
3491428881deSRichard Henderson     } else {
3492428881deSRichard Henderson         func(dst, src1, cpu_regs[a->rs2_or_imm]);
3493428881deSRichard Henderson     }
34942a45b736SRichard Henderson 
34952a45b736SRichard Henderson     if (logic_cc) {
34962a45b736SRichard Henderson         if (TARGET_LONG_BITS == 64) {
34972a45b736SRichard Henderson             tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N);
34982a45b736SRichard Henderson             tcg_gen_movi_tl(cpu_icc_C, 0);
34992a45b736SRichard Henderson         }
35002a45b736SRichard Henderson         tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N);
35012a45b736SRichard Henderson         tcg_gen_movi_tl(cpu_cc_C, 0);
35022a45b736SRichard Henderson         tcg_gen_movi_tl(cpu_cc_V, 0);
35032a45b736SRichard Henderson     }
35042a45b736SRichard Henderson 
3505428881deSRichard Henderson     gen_store_gpr(dc, a->rd, dst);
3506428881deSRichard Henderson     return advance_pc(dc);
3507428881deSRichard Henderson }
3508428881deSRichard Henderson 
3509b597eedcSRichard Henderson static bool do_arith(DisasContext *dc, arg_r_r_ri_cc *a,
3510428881deSRichard Henderson                      void (*func)(TCGv, TCGv, TCGv),
3511428881deSRichard Henderson                      void (*funci)(TCGv, TCGv, target_long),
3512428881deSRichard Henderson                      void (*func_cc)(TCGv, TCGv, TCGv))
3513428881deSRichard Henderson {
3514428881deSRichard Henderson     if (a->cc) {
3515b597eedcSRichard Henderson         return do_arith_int(dc, a, func_cc, NULL, false);
3516428881deSRichard Henderson     }
3517b597eedcSRichard Henderson     return do_arith_int(dc, a, func, funci, false);
3518428881deSRichard Henderson }
3519428881deSRichard Henderson 
3520428881deSRichard Henderson static bool do_logic(DisasContext *dc, arg_r_r_ri_cc *a,
3521428881deSRichard Henderson                      void (*func)(TCGv, TCGv, TCGv),
3522428881deSRichard Henderson                      void (*funci)(TCGv, TCGv, target_long))
3523428881deSRichard Henderson {
3524b597eedcSRichard Henderson     return do_arith_int(dc, a, func, funci, a->cc);
3525428881deSRichard Henderson }
3526428881deSRichard Henderson 
3527b597eedcSRichard Henderson TRANS(ADD, ALL, do_arith, a, tcg_gen_add_tl, tcg_gen_addi_tl, gen_op_addcc)
3528b597eedcSRichard Henderson TRANS(SUB, ALL, do_arith, a, tcg_gen_sub_tl, tcg_gen_subi_tl, gen_op_subcc)
3529b597eedcSRichard Henderson TRANS(ADDC, ALL, do_arith, a, gen_op_addc, NULL, gen_op_addccc)
3530b597eedcSRichard Henderson TRANS(SUBC, ALL, do_arith, a, gen_op_subc, NULL, gen_op_subccc)
3531428881deSRichard Henderson 
3532b597eedcSRichard Henderson TRANS(TADDcc, ALL, do_arith, a, NULL, NULL, gen_op_taddcc)
3533b597eedcSRichard Henderson TRANS(TSUBcc, ALL, do_arith, a, NULL, NULL, gen_op_tsubcc)
3534b597eedcSRichard Henderson TRANS(TADDccTV, ALL, do_arith, a, NULL, NULL, gen_op_taddcctv)
3535b597eedcSRichard Henderson TRANS(TSUBccTV, ALL, do_arith, a, NULL, NULL, gen_op_tsubcctv)
3536a9aba13dSRichard Henderson 
3537428881deSRichard Henderson TRANS(AND, ALL, do_logic, a, tcg_gen_and_tl, tcg_gen_andi_tl)
3538428881deSRichard Henderson TRANS(XOR, ALL, do_logic, a, tcg_gen_xor_tl, tcg_gen_xori_tl)
3539428881deSRichard Henderson TRANS(ANDN, ALL, do_logic, a, tcg_gen_andc_tl, NULL)
3540428881deSRichard Henderson TRANS(ORN, ALL, do_logic, a, tcg_gen_orc_tl, NULL)
3541428881deSRichard Henderson TRANS(XORN, ALL, do_logic, a, tcg_gen_eqv_tl, NULL)
3542428881deSRichard Henderson 
3543b597eedcSRichard Henderson TRANS(MULX, 64, do_arith, a, tcg_gen_mul_tl, tcg_gen_muli_tl, NULL)
3544b5372650SRichard Henderson TRANS(UMUL, MUL, do_logic, a, gen_op_umul, NULL)
3545b5372650SRichard Henderson TRANS(SMUL, MUL, do_logic, a, gen_op_smul, NULL)
3546b597eedcSRichard Henderson TRANS(MULScc, ALL, do_arith, a, NULL, NULL, gen_op_mulscc)
354722188d7dSRichard Henderson 
35483a6b8de3SRichard Henderson TRANS(UDIVcc, DIV, do_arith, a, NULL, NULL, gen_op_udivcc)
3549b597eedcSRichard Henderson TRANS(SDIV, DIV, do_arith, a, gen_op_sdiv, NULL, gen_op_sdivcc)
35504ee85ea9SRichard Henderson 
35519c6ec5bcSRichard Henderson /* TODO: Should have feature bit -- comes in with UltraSparc T2. */
3552b597eedcSRichard Henderson TRANS(POPC, 64, do_arith, a, gen_op_popc, NULL, NULL)
35539c6ec5bcSRichard Henderson 
3554428881deSRichard Henderson static bool trans_OR(DisasContext *dc, arg_r_r_ri_cc *a)
3555428881deSRichard Henderson {
3556428881deSRichard Henderson     /* OR with %g0 is the canonical alias for MOV. */
3557428881deSRichard Henderson     if (!a->cc && a->rs1 == 0) {
3558428881deSRichard Henderson         if (a->imm || a->rs2_or_imm == 0) {
3559428881deSRichard Henderson             gen_store_gpr(dc, a->rd, tcg_constant_tl(a->rs2_or_imm));
3560428881deSRichard Henderson         } else if (a->rs2_or_imm & ~0x1f) {
3561428881deSRichard Henderson             /* For simplicity, we under-decoded the rs2 form. */
3562428881deSRichard Henderson             return false;
3563428881deSRichard Henderson         } else {
3564428881deSRichard Henderson             gen_store_gpr(dc, a->rd, cpu_regs[a->rs2_or_imm]);
3565428881deSRichard Henderson         }
3566428881deSRichard Henderson         return advance_pc(dc);
3567428881deSRichard Henderson     }
3568428881deSRichard Henderson     return do_logic(dc, a, tcg_gen_or_tl, tcg_gen_ori_tl);
3569428881deSRichard Henderson }
3570428881deSRichard Henderson 
35713a6b8de3SRichard Henderson static bool trans_UDIV(DisasContext *dc, arg_r_r_ri *a)
35723a6b8de3SRichard Henderson {
35733a6b8de3SRichard Henderson     TCGv_i64 t1, t2;
35743a6b8de3SRichard Henderson     TCGv dst;
35753a6b8de3SRichard Henderson 
35763a6b8de3SRichard Henderson     if (!avail_DIV(dc)) {
35773a6b8de3SRichard Henderson         return false;
35783a6b8de3SRichard Henderson     }
35793a6b8de3SRichard Henderson     /* For simplicity, we under-decoded the rs2 form. */
35803a6b8de3SRichard Henderson     if (!a->imm && a->rs2_or_imm & ~0x1f) {
35813a6b8de3SRichard Henderson         return false;
35823a6b8de3SRichard Henderson     }
35833a6b8de3SRichard Henderson 
35843a6b8de3SRichard Henderson     if (unlikely(a->rs2_or_imm == 0)) {
35853a6b8de3SRichard Henderson         gen_exception(dc, TT_DIV_ZERO);
35863a6b8de3SRichard Henderson         return true;
35873a6b8de3SRichard Henderson     }
35883a6b8de3SRichard Henderson 
35893a6b8de3SRichard Henderson     if (a->imm) {
35903a6b8de3SRichard Henderson         t2 = tcg_constant_i64((uint32_t)a->rs2_or_imm);
35913a6b8de3SRichard Henderson     } else {
35923a6b8de3SRichard Henderson         TCGLabel *lab;
35933a6b8de3SRichard Henderson         TCGv_i32 n2;
35943a6b8de3SRichard Henderson 
35953a6b8de3SRichard Henderson         finishing_insn(dc);
35963a6b8de3SRichard Henderson         flush_cond(dc);
35973a6b8de3SRichard Henderson 
35983a6b8de3SRichard Henderson         n2 = tcg_temp_new_i32();
35993a6b8de3SRichard Henderson         tcg_gen_trunc_tl_i32(n2, cpu_regs[a->rs2_or_imm]);
36003a6b8de3SRichard Henderson 
36013a6b8de3SRichard Henderson         lab = delay_exception(dc, TT_DIV_ZERO);
36023a6b8de3SRichard Henderson         tcg_gen_brcondi_i32(TCG_COND_EQ, n2, 0, lab);
36033a6b8de3SRichard Henderson 
36043a6b8de3SRichard Henderson         t2 = tcg_temp_new_i64();
36053a6b8de3SRichard Henderson #ifdef TARGET_SPARC64
36063a6b8de3SRichard Henderson         tcg_gen_ext32u_i64(t2, cpu_regs[a->rs2_or_imm]);
36073a6b8de3SRichard Henderson #else
36083a6b8de3SRichard Henderson         tcg_gen_extu_i32_i64(t2, cpu_regs[a->rs2_or_imm]);
36093a6b8de3SRichard Henderson #endif
36103a6b8de3SRichard Henderson     }
36113a6b8de3SRichard Henderson 
36123a6b8de3SRichard Henderson     t1 = tcg_temp_new_i64();
36133a6b8de3SRichard Henderson     tcg_gen_concat_tl_i64(t1, gen_load_gpr(dc, a->rs1), cpu_y);
36143a6b8de3SRichard Henderson 
36153a6b8de3SRichard Henderson     tcg_gen_divu_i64(t1, t1, t2);
36163a6b8de3SRichard Henderson     tcg_gen_umin_i64(t1, t1, tcg_constant_i64(UINT32_MAX));
36173a6b8de3SRichard Henderson 
36183a6b8de3SRichard Henderson     dst = gen_dest_gpr(dc, a->rd);
36193a6b8de3SRichard Henderson     tcg_gen_trunc_i64_tl(dst, t1);
36203a6b8de3SRichard Henderson     gen_store_gpr(dc, a->rd, dst);
36213a6b8de3SRichard Henderson     return advance_pc(dc);
36223a6b8de3SRichard Henderson }
36233a6b8de3SRichard Henderson 
3624f3141174SRichard Henderson static bool trans_UDIVX(DisasContext *dc, arg_r_r_ri *a)
3625f3141174SRichard Henderson {
3626f3141174SRichard Henderson     TCGv dst, src1, src2;
3627f3141174SRichard Henderson 
3628f3141174SRichard Henderson     if (!avail_64(dc)) {
3629f3141174SRichard Henderson         return false;
3630f3141174SRichard Henderson     }
3631f3141174SRichard Henderson     /* For simplicity, we under-decoded the rs2 form. */
3632f3141174SRichard Henderson     if (!a->imm && a->rs2_or_imm & ~0x1f) {
3633f3141174SRichard Henderson         return false;
3634f3141174SRichard Henderson     }
3635f3141174SRichard Henderson 
3636f3141174SRichard Henderson     if (unlikely(a->rs2_or_imm == 0)) {
3637f3141174SRichard Henderson         gen_exception(dc, TT_DIV_ZERO);
3638f3141174SRichard Henderson         return true;
3639f3141174SRichard Henderson     }
3640f3141174SRichard Henderson 
3641f3141174SRichard Henderson     if (a->imm) {
3642f3141174SRichard Henderson         src2 = tcg_constant_tl(a->rs2_or_imm);
3643f3141174SRichard Henderson     } else {
3644f3141174SRichard Henderson         TCGLabel *lab;
3645f3141174SRichard Henderson 
3646f3141174SRichard Henderson         finishing_insn(dc);
3647f3141174SRichard Henderson         flush_cond(dc);
3648f3141174SRichard Henderson 
3649f3141174SRichard Henderson         lab = delay_exception(dc, TT_DIV_ZERO);
3650f3141174SRichard Henderson         src2 = cpu_regs[a->rs2_or_imm];
3651f3141174SRichard Henderson         tcg_gen_brcondi_tl(TCG_COND_EQ, src2, 0, lab);
3652f3141174SRichard Henderson     }
3653f3141174SRichard Henderson 
3654f3141174SRichard Henderson     dst = gen_dest_gpr(dc, a->rd);
3655f3141174SRichard Henderson     src1 = gen_load_gpr(dc, a->rs1);
3656f3141174SRichard Henderson 
3657f3141174SRichard Henderson     tcg_gen_divu_tl(dst, src1, src2);
3658f3141174SRichard Henderson     gen_store_gpr(dc, a->rd, dst);
3659f3141174SRichard Henderson     return advance_pc(dc);
3660f3141174SRichard Henderson }
3661f3141174SRichard Henderson 
3662f3141174SRichard Henderson static bool trans_SDIVX(DisasContext *dc, arg_r_r_ri *a)
3663f3141174SRichard Henderson {
3664f3141174SRichard Henderson     TCGv dst, src1, src2;
3665f3141174SRichard Henderson 
3666f3141174SRichard Henderson     if (!avail_64(dc)) {
3667f3141174SRichard Henderson         return false;
3668f3141174SRichard Henderson     }
3669f3141174SRichard Henderson     /* For simplicity, we under-decoded the rs2 form. */
3670f3141174SRichard Henderson     if (!a->imm && a->rs2_or_imm & ~0x1f) {
3671f3141174SRichard Henderson         return false;
3672f3141174SRichard Henderson     }
3673f3141174SRichard Henderson 
3674f3141174SRichard Henderson     if (unlikely(a->rs2_or_imm == 0)) {
3675f3141174SRichard Henderson         gen_exception(dc, TT_DIV_ZERO);
3676f3141174SRichard Henderson         return true;
3677f3141174SRichard Henderson     }
3678f3141174SRichard Henderson 
3679f3141174SRichard Henderson     dst = gen_dest_gpr(dc, a->rd);
3680f3141174SRichard Henderson     src1 = gen_load_gpr(dc, a->rs1);
3681f3141174SRichard Henderson 
3682f3141174SRichard Henderson     if (a->imm) {
3683f3141174SRichard Henderson         if (unlikely(a->rs2_or_imm == -1)) {
3684f3141174SRichard Henderson             tcg_gen_neg_tl(dst, src1);
3685f3141174SRichard Henderson             gen_store_gpr(dc, a->rd, dst);
3686f3141174SRichard Henderson             return advance_pc(dc);
3687f3141174SRichard Henderson         }
3688f3141174SRichard Henderson         src2 = tcg_constant_tl(a->rs2_or_imm);
3689f3141174SRichard Henderson     } else {
3690f3141174SRichard Henderson         TCGLabel *lab;
3691f3141174SRichard Henderson         TCGv t1, t2;
3692f3141174SRichard Henderson 
3693f3141174SRichard Henderson         finishing_insn(dc);
3694f3141174SRichard Henderson         flush_cond(dc);
3695f3141174SRichard Henderson 
3696f3141174SRichard Henderson         lab = delay_exception(dc, TT_DIV_ZERO);
3697f3141174SRichard Henderson         src2 = cpu_regs[a->rs2_or_imm];
3698f3141174SRichard Henderson         tcg_gen_brcondi_tl(TCG_COND_EQ, src2, 0, lab);
3699f3141174SRichard Henderson 
3700f3141174SRichard Henderson         /*
3701f3141174SRichard Henderson          * Need to avoid INT64_MIN / -1, which will trap on x86 host.
3702f3141174SRichard Henderson          * Set SRC2 to 1 as a new divisor, to produce the correct result.
3703f3141174SRichard Henderson          */
3704f3141174SRichard Henderson         t1 = tcg_temp_new();
3705f3141174SRichard Henderson         t2 = tcg_temp_new();
3706f3141174SRichard Henderson         tcg_gen_setcondi_tl(TCG_COND_EQ, t1, src1, (target_long)INT64_MIN);
3707f3141174SRichard Henderson         tcg_gen_setcondi_tl(TCG_COND_EQ, t2, src2, -1);
3708f3141174SRichard Henderson         tcg_gen_and_tl(t1, t1, t2);
3709f3141174SRichard Henderson         tcg_gen_movcond_tl(TCG_COND_NE, t1, t1, tcg_constant_tl(0),
3710f3141174SRichard Henderson                            tcg_constant_tl(1), src2);
3711f3141174SRichard Henderson         src2 = t1;
3712f3141174SRichard Henderson     }
3713f3141174SRichard Henderson 
3714f3141174SRichard Henderson     tcg_gen_div_tl(dst, src1, src2);
3715f3141174SRichard Henderson     gen_store_gpr(dc, a->rd, dst);
3716f3141174SRichard Henderson     return advance_pc(dc);
3717f3141174SRichard Henderson }
3718f3141174SRichard Henderson 
3719b88ce6f2SRichard Henderson static bool gen_edge(DisasContext *dc, arg_r_r_r *a,
372043db5838SRichard Henderson                      int width, bool cc, bool little_endian)
3721b88ce6f2SRichard Henderson {
372243db5838SRichard Henderson     TCGv dst, s1, s2, l, r, t, m;
372343db5838SRichard Henderson     uint64_t amask = address_mask_i(dc, -8);
3724b88ce6f2SRichard Henderson 
3725b88ce6f2SRichard Henderson     dst = gen_dest_gpr(dc, a->rd);
3726b88ce6f2SRichard Henderson     s1 = gen_load_gpr(dc, a->rs1);
3727b88ce6f2SRichard Henderson     s2 = gen_load_gpr(dc, a->rs2);
3728b88ce6f2SRichard Henderson 
3729b88ce6f2SRichard Henderson     if (cc) {
3730f828df74SRichard Henderson         gen_op_subcc(cpu_cc_N, s1, s2);
3731b88ce6f2SRichard Henderson     }
3732b88ce6f2SRichard Henderson 
373343db5838SRichard Henderson     l = tcg_temp_new();
373443db5838SRichard Henderson     r = tcg_temp_new();
373543db5838SRichard Henderson     t = tcg_temp_new();
373643db5838SRichard Henderson 
3737b88ce6f2SRichard Henderson     switch (width) {
3738b88ce6f2SRichard Henderson     case 8:
373943db5838SRichard Henderson         tcg_gen_andi_tl(l, s1, 7);
374043db5838SRichard Henderson         tcg_gen_andi_tl(r, s2, 7);
374143db5838SRichard Henderson         tcg_gen_xori_tl(r, r, 7);
374243db5838SRichard Henderson         m = tcg_constant_tl(0xff);
3743b88ce6f2SRichard Henderson         break;
3744b88ce6f2SRichard Henderson     case 16:
374543db5838SRichard Henderson         tcg_gen_extract_tl(l, s1, 1, 2);
374643db5838SRichard Henderson         tcg_gen_extract_tl(r, s2, 1, 2);
374743db5838SRichard Henderson         tcg_gen_xori_tl(r, r, 3);
374843db5838SRichard Henderson         m = tcg_constant_tl(0xf);
3749b88ce6f2SRichard Henderson         break;
3750b88ce6f2SRichard Henderson     case 32:
375143db5838SRichard Henderson         tcg_gen_extract_tl(l, s1, 2, 1);
375243db5838SRichard Henderson         tcg_gen_extract_tl(r, s2, 2, 1);
375343db5838SRichard Henderson         tcg_gen_xori_tl(r, r, 1);
375443db5838SRichard Henderson         m = tcg_constant_tl(0x3);
3755b88ce6f2SRichard Henderson         break;
3756b88ce6f2SRichard Henderson     default:
3757b88ce6f2SRichard Henderson         abort();
3758b88ce6f2SRichard Henderson     }
3759b88ce6f2SRichard Henderson 
376043db5838SRichard Henderson     /* Compute Left Edge */
376143db5838SRichard Henderson     if (little_endian) {
376243db5838SRichard Henderson         tcg_gen_shl_tl(l, m, l);
376343db5838SRichard Henderson         tcg_gen_and_tl(l, l, m);
376443db5838SRichard Henderson     } else {
376543db5838SRichard Henderson         tcg_gen_shr_tl(l, m, l);
376643db5838SRichard Henderson     }
376743db5838SRichard Henderson     /* Compute Right Edge */
376843db5838SRichard Henderson     if (little_endian) {
376943db5838SRichard Henderson         tcg_gen_shr_tl(r, m, r);
377043db5838SRichard Henderson     } else {
377143db5838SRichard Henderson         tcg_gen_shl_tl(r, m, r);
377243db5838SRichard Henderson         tcg_gen_and_tl(r, r, m);
377343db5838SRichard Henderson     }
3774b88ce6f2SRichard Henderson 
377543db5838SRichard Henderson     /* Compute dst = (s1 == s2 under amask ? l : l & r) */
377643db5838SRichard Henderson     tcg_gen_xor_tl(t, s1, s2);
377743db5838SRichard Henderson     tcg_gen_and_tl(r, r, l);
377843db5838SRichard Henderson     tcg_gen_movcond_tl(TCG_COND_TSTEQ, dst, t, tcg_constant_tl(amask), r, l);
3779b88ce6f2SRichard Henderson 
3780b88ce6f2SRichard Henderson     gen_store_gpr(dc, a->rd, dst);
3781b88ce6f2SRichard Henderson     return advance_pc(dc);
3782b88ce6f2SRichard Henderson }
3783b88ce6f2SRichard Henderson 
3784b88ce6f2SRichard Henderson TRANS(EDGE8cc, VIS1, gen_edge, a, 8, 1, 0)
3785b88ce6f2SRichard Henderson TRANS(EDGE8Lcc, VIS1, gen_edge, a, 8, 1, 1)
3786b88ce6f2SRichard Henderson TRANS(EDGE16cc, VIS1, gen_edge, a, 16, 1, 0)
3787b88ce6f2SRichard Henderson TRANS(EDGE16Lcc, VIS1, gen_edge, a, 16, 1, 1)
3788b88ce6f2SRichard Henderson TRANS(EDGE32cc, VIS1, gen_edge, a, 32, 1, 0)
3789b88ce6f2SRichard Henderson TRANS(EDGE32Lcc, VIS1, gen_edge, a, 32, 1, 1)
3790b88ce6f2SRichard Henderson 
3791b88ce6f2SRichard Henderson TRANS(EDGE8N, VIS2, gen_edge, a, 8, 0, 0)
3792b88ce6f2SRichard Henderson TRANS(EDGE8LN, VIS2, gen_edge, a, 8, 0, 1)
3793b88ce6f2SRichard Henderson TRANS(EDGE16N, VIS2, gen_edge, a, 16, 0, 0)
3794b88ce6f2SRichard Henderson TRANS(EDGE16LN, VIS2, gen_edge, a, 16, 0, 1)
3795b88ce6f2SRichard Henderson TRANS(EDGE32N, VIS2, gen_edge, a, 32, 0, 0)
3796b88ce6f2SRichard Henderson TRANS(EDGE32LN, VIS2, gen_edge, a, 32, 0, 1)
3797b88ce6f2SRichard Henderson 
379845bfed3bSRichard Henderson static bool do_rrr(DisasContext *dc, arg_r_r_r *a,
379945bfed3bSRichard Henderson                    void (*func)(TCGv, TCGv, TCGv))
380045bfed3bSRichard Henderson {
380145bfed3bSRichard Henderson     TCGv dst = gen_dest_gpr(dc, a->rd);
380245bfed3bSRichard Henderson     TCGv src1 = gen_load_gpr(dc, a->rs1);
380345bfed3bSRichard Henderson     TCGv src2 = gen_load_gpr(dc, a->rs2);
380445bfed3bSRichard Henderson 
380545bfed3bSRichard Henderson     func(dst, src1, src2);
380645bfed3bSRichard Henderson     gen_store_gpr(dc, a->rd, dst);
380745bfed3bSRichard Henderson     return advance_pc(dc);
380845bfed3bSRichard Henderson }
380945bfed3bSRichard Henderson 
381045bfed3bSRichard Henderson TRANS(ARRAY8, VIS1, do_rrr, a, gen_helper_array8)
381145bfed3bSRichard Henderson TRANS(ARRAY16, VIS1, do_rrr, a, gen_op_array16)
381245bfed3bSRichard Henderson TRANS(ARRAY32, VIS1, do_rrr, a, gen_op_array32)
381345bfed3bSRichard Henderson 
3814015fc6fcSRichard Henderson TRANS(ADDXC, VIS3, do_rrr, a, gen_op_addxc)
3815015fc6fcSRichard Henderson TRANS(ADDXCcc, VIS3, do_rrr, a, gen_op_addxccc)
3816015fc6fcSRichard Henderson 
38179e20ca94SRichard Henderson static void gen_op_alignaddr(TCGv dst, TCGv s1, TCGv s2)
38189e20ca94SRichard Henderson {
38199e20ca94SRichard Henderson #ifdef TARGET_SPARC64
38209e20ca94SRichard Henderson     TCGv tmp = tcg_temp_new();
38219e20ca94SRichard Henderson 
38229e20ca94SRichard Henderson     tcg_gen_add_tl(tmp, s1, s2);
38239e20ca94SRichard Henderson     tcg_gen_andi_tl(dst, tmp, -8);
38249e20ca94SRichard Henderson     tcg_gen_deposit_tl(cpu_gsr, cpu_gsr, tmp, 0, 3);
38259e20ca94SRichard Henderson #else
38269e20ca94SRichard Henderson     g_assert_not_reached();
38279e20ca94SRichard Henderson #endif
38289e20ca94SRichard Henderson }
38299e20ca94SRichard Henderson 
38309e20ca94SRichard Henderson static void gen_op_alignaddrl(TCGv dst, TCGv s1, TCGv s2)
38319e20ca94SRichard Henderson {
38329e20ca94SRichard Henderson #ifdef TARGET_SPARC64
38339e20ca94SRichard Henderson     TCGv tmp = tcg_temp_new();
38349e20ca94SRichard Henderson 
38359e20ca94SRichard Henderson     tcg_gen_add_tl(tmp, s1, s2);
38369e20ca94SRichard Henderson     tcg_gen_andi_tl(dst, tmp, -8);
38379e20ca94SRichard Henderson     tcg_gen_neg_tl(tmp, tmp);
38389e20ca94SRichard Henderson     tcg_gen_deposit_tl(cpu_gsr, cpu_gsr, tmp, 0, 3);
38399e20ca94SRichard Henderson #else
38409e20ca94SRichard Henderson     g_assert_not_reached();
38419e20ca94SRichard Henderson #endif
38429e20ca94SRichard Henderson }
38439e20ca94SRichard Henderson 
38449e20ca94SRichard Henderson TRANS(ALIGNADDR, VIS1, do_rrr, a, gen_op_alignaddr)
38459e20ca94SRichard Henderson TRANS(ALIGNADDRL, VIS1, do_rrr, a, gen_op_alignaddrl)
38469e20ca94SRichard Henderson 
384739ca3490SRichard Henderson static void gen_op_bmask(TCGv dst, TCGv s1, TCGv s2)
384839ca3490SRichard Henderson {
384939ca3490SRichard Henderson #ifdef TARGET_SPARC64
385039ca3490SRichard Henderson     tcg_gen_add_tl(dst, s1, s2);
385139ca3490SRichard Henderson     tcg_gen_deposit_tl(cpu_gsr, cpu_gsr, dst, 32, 32);
385239ca3490SRichard Henderson #else
385339ca3490SRichard Henderson     g_assert_not_reached();
385439ca3490SRichard Henderson #endif
385539ca3490SRichard Henderson }
385639ca3490SRichard Henderson 
385739ca3490SRichard Henderson TRANS(BMASK, VIS2, do_rrr, a, gen_op_bmask)
385839ca3490SRichard Henderson 
3859c973b4e8SRichard Henderson static bool do_cmask(DisasContext *dc, int rs2, void (*func)(TCGv, TCGv, TCGv))
3860c973b4e8SRichard Henderson {
3861c973b4e8SRichard Henderson     func(cpu_gsr, cpu_gsr, gen_load_gpr(dc, rs2));
3862c973b4e8SRichard Henderson     return true;
3863c973b4e8SRichard Henderson }
3864c973b4e8SRichard Henderson 
3865c973b4e8SRichard Henderson TRANS(CMASK8, VIS3, do_cmask, a->rs2, gen_helper_cmask8)
3866c973b4e8SRichard Henderson TRANS(CMASK16, VIS3, do_cmask, a->rs2, gen_helper_cmask16)
3867c973b4e8SRichard Henderson TRANS(CMASK32, VIS3, do_cmask, a->rs2, gen_helper_cmask32)
3868c973b4e8SRichard Henderson 
38695fc546eeSRichard Henderson static bool do_shift_r(DisasContext *dc, arg_shiftr *a, bool l, bool u)
38705fc546eeSRichard Henderson {
38715fc546eeSRichard Henderson     TCGv dst, src1, src2;
38725fc546eeSRichard Henderson 
38735fc546eeSRichard Henderson     /* Reject 64-bit shifts for sparc32. */
38745fc546eeSRichard Henderson     if (avail_32(dc) && a->x) {
38755fc546eeSRichard Henderson         return false;
38765fc546eeSRichard Henderson     }
38775fc546eeSRichard Henderson 
38785fc546eeSRichard Henderson     src2 = tcg_temp_new();
38795fc546eeSRichard Henderson     tcg_gen_andi_tl(src2, gen_load_gpr(dc, a->rs2), a->x ? 63 : 31);
38805fc546eeSRichard Henderson     src1 = gen_load_gpr(dc, a->rs1);
38815fc546eeSRichard Henderson     dst = gen_dest_gpr(dc, a->rd);
38825fc546eeSRichard Henderson 
38835fc546eeSRichard Henderson     if (l) {
38845fc546eeSRichard Henderson         tcg_gen_shl_tl(dst, src1, src2);
38855fc546eeSRichard Henderson         if (!a->x) {
38865fc546eeSRichard Henderson             tcg_gen_ext32u_tl(dst, dst);
38875fc546eeSRichard Henderson         }
38885fc546eeSRichard Henderson     } else if (u) {
38895fc546eeSRichard Henderson         if (!a->x) {
38905fc546eeSRichard Henderson             tcg_gen_ext32u_tl(dst, src1);
38915fc546eeSRichard Henderson             src1 = dst;
38925fc546eeSRichard Henderson         }
38935fc546eeSRichard Henderson         tcg_gen_shr_tl(dst, src1, src2);
38945fc546eeSRichard Henderson     } else {
38955fc546eeSRichard Henderson         if (!a->x) {
38965fc546eeSRichard Henderson             tcg_gen_ext32s_tl(dst, src1);
38975fc546eeSRichard Henderson             src1 = dst;
38985fc546eeSRichard Henderson         }
38995fc546eeSRichard Henderson         tcg_gen_sar_tl(dst, src1, src2);
39005fc546eeSRichard Henderson     }
39015fc546eeSRichard Henderson     gen_store_gpr(dc, a->rd, dst);
39025fc546eeSRichard Henderson     return advance_pc(dc);
39035fc546eeSRichard Henderson }
39045fc546eeSRichard Henderson 
39055fc546eeSRichard Henderson TRANS(SLL_r, ALL, do_shift_r, a, true, true)
39065fc546eeSRichard Henderson TRANS(SRL_r, ALL, do_shift_r, a, false, true)
39075fc546eeSRichard Henderson TRANS(SRA_r, ALL, do_shift_r, a, false, false)
39085fc546eeSRichard Henderson 
39095fc546eeSRichard Henderson static bool do_shift_i(DisasContext *dc, arg_shifti *a, bool l, bool u)
39105fc546eeSRichard Henderson {
39115fc546eeSRichard Henderson     TCGv dst, src1;
39125fc546eeSRichard Henderson 
39135fc546eeSRichard Henderson     /* Reject 64-bit shifts for sparc32. */
39145fc546eeSRichard Henderson     if (avail_32(dc) && (a->x || a->i >= 32)) {
39155fc546eeSRichard Henderson         return false;
39165fc546eeSRichard Henderson     }
39175fc546eeSRichard Henderson 
39185fc546eeSRichard Henderson     src1 = gen_load_gpr(dc, a->rs1);
39195fc546eeSRichard Henderson     dst = gen_dest_gpr(dc, a->rd);
39205fc546eeSRichard Henderson 
39215fc546eeSRichard Henderson     if (avail_32(dc) || a->x) {
39225fc546eeSRichard Henderson         if (l) {
39235fc546eeSRichard Henderson             tcg_gen_shli_tl(dst, src1, a->i);
39245fc546eeSRichard Henderson         } else if (u) {
39255fc546eeSRichard Henderson             tcg_gen_shri_tl(dst, src1, a->i);
39265fc546eeSRichard Henderson         } else {
39275fc546eeSRichard Henderson             tcg_gen_sari_tl(dst, src1, a->i);
39285fc546eeSRichard Henderson         }
39295fc546eeSRichard Henderson     } else {
39305fc546eeSRichard Henderson         if (l) {
39315fc546eeSRichard Henderson             tcg_gen_deposit_z_tl(dst, src1, a->i, 32 - a->i);
39325fc546eeSRichard Henderson         } else if (u) {
39335fc546eeSRichard Henderson             tcg_gen_extract_tl(dst, src1, a->i, 32 - a->i);
39345fc546eeSRichard Henderson         } else {
39355fc546eeSRichard Henderson             tcg_gen_sextract_tl(dst, src1, a->i, 32 - a->i);
39365fc546eeSRichard Henderson         }
39375fc546eeSRichard Henderson     }
39385fc546eeSRichard Henderson     gen_store_gpr(dc, a->rd, dst);
39395fc546eeSRichard Henderson     return advance_pc(dc);
39405fc546eeSRichard Henderson }
39415fc546eeSRichard Henderson 
39425fc546eeSRichard Henderson TRANS(SLL_i, ALL, do_shift_i, a, true, true)
39435fc546eeSRichard Henderson TRANS(SRL_i, ALL, do_shift_i, a, false, true)
39445fc546eeSRichard Henderson TRANS(SRA_i, ALL, do_shift_i, a, false, false)
39455fc546eeSRichard Henderson 
3946fb4ed7aaSRichard Henderson static TCGv gen_rs2_or_imm(DisasContext *dc, bool imm, int rs2_or_imm)
3947fb4ed7aaSRichard Henderson {
3948fb4ed7aaSRichard Henderson     /* For simplicity, we under-decoded the rs2 form. */
3949fb4ed7aaSRichard Henderson     if (!imm && rs2_or_imm & ~0x1f) {
3950fb4ed7aaSRichard Henderson         return NULL;
3951fb4ed7aaSRichard Henderson     }
3952fb4ed7aaSRichard Henderson     if (imm || rs2_or_imm == 0) {
3953fb4ed7aaSRichard Henderson         return tcg_constant_tl(rs2_or_imm);
3954fb4ed7aaSRichard Henderson     } else {
3955fb4ed7aaSRichard Henderson         return cpu_regs[rs2_or_imm];
3956fb4ed7aaSRichard Henderson     }
3957fb4ed7aaSRichard Henderson }
3958fb4ed7aaSRichard Henderson 
3959fb4ed7aaSRichard Henderson static bool do_mov_cond(DisasContext *dc, DisasCompare *cmp, int rd, TCGv src2)
3960fb4ed7aaSRichard Henderson {
3961fb4ed7aaSRichard Henderson     TCGv dst = gen_load_gpr(dc, rd);
3962c8507ebfSRichard Henderson     TCGv c2 = tcg_constant_tl(cmp->c2);
3963fb4ed7aaSRichard Henderson 
3964c8507ebfSRichard Henderson     tcg_gen_movcond_tl(cmp->cond, dst, cmp->c1, c2, src2, dst);
3965fb4ed7aaSRichard Henderson     gen_store_gpr(dc, rd, dst);
3966fb4ed7aaSRichard Henderson     return advance_pc(dc);
3967fb4ed7aaSRichard Henderson }
3968fb4ed7aaSRichard Henderson 
3969fb4ed7aaSRichard Henderson static bool trans_MOVcc(DisasContext *dc, arg_MOVcc *a)
3970fb4ed7aaSRichard Henderson {
3971fb4ed7aaSRichard Henderson     TCGv src2 = gen_rs2_or_imm(dc, a->imm, a->rs2_or_imm);
3972fb4ed7aaSRichard Henderson     DisasCompare cmp;
3973fb4ed7aaSRichard Henderson 
3974fb4ed7aaSRichard Henderson     if (src2 == NULL) {
3975fb4ed7aaSRichard Henderson         return false;
3976fb4ed7aaSRichard Henderson     }
3977fb4ed7aaSRichard Henderson     gen_compare(&cmp, a->cc, a->cond, dc);
3978fb4ed7aaSRichard Henderson     return do_mov_cond(dc, &cmp, a->rd, src2);
3979fb4ed7aaSRichard Henderson }
3980fb4ed7aaSRichard Henderson 
3981fb4ed7aaSRichard Henderson static bool trans_MOVfcc(DisasContext *dc, arg_MOVfcc *a)
3982fb4ed7aaSRichard Henderson {
3983fb4ed7aaSRichard Henderson     TCGv src2 = gen_rs2_or_imm(dc, a->imm, a->rs2_or_imm);
3984fb4ed7aaSRichard Henderson     DisasCompare cmp;
3985fb4ed7aaSRichard Henderson 
3986fb4ed7aaSRichard Henderson     if (src2 == NULL) {
3987fb4ed7aaSRichard Henderson         return false;
3988fb4ed7aaSRichard Henderson     }
3989fb4ed7aaSRichard Henderson     gen_fcompare(&cmp, a->cc, a->cond);
3990fb4ed7aaSRichard Henderson     return do_mov_cond(dc, &cmp, a->rd, src2);
3991fb4ed7aaSRichard Henderson }
3992fb4ed7aaSRichard Henderson 
3993fb4ed7aaSRichard Henderson static bool trans_MOVR(DisasContext *dc, arg_MOVR *a)
3994fb4ed7aaSRichard Henderson {
3995fb4ed7aaSRichard Henderson     TCGv src2 = gen_rs2_or_imm(dc, a->imm, a->rs2_or_imm);
3996fb4ed7aaSRichard Henderson     DisasCompare cmp;
3997fb4ed7aaSRichard Henderson 
3998fb4ed7aaSRichard Henderson     if (src2 == NULL) {
3999fb4ed7aaSRichard Henderson         return false;
4000fb4ed7aaSRichard Henderson     }
40012c4f56c9SRichard Henderson     if (!gen_compare_reg(&cmp, a->cond, gen_load_gpr(dc, a->rs1))) {
40022c4f56c9SRichard Henderson         return false;
40032c4f56c9SRichard Henderson     }
4004fb4ed7aaSRichard Henderson     return do_mov_cond(dc, &cmp, a->rd, src2);
4005fb4ed7aaSRichard Henderson }
4006fb4ed7aaSRichard Henderson 
400786b82fe0SRichard Henderson static bool do_add_special(DisasContext *dc, arg_r_r_ri *a,
400886b82fe0SRichard Henderson                            bool (*func)(DisasContext *dc, int rd, TCGv src))
400986b82fe0SRichard Henderson {
401086b82fe0SRichard Henderson     TCGv src1, sum;
401186b82fe0SRichard Henderson 
401286b82fe0SRichard Henderson     /* For simplicity, we under-decoded the rs2 form. */
401386b82fe0SRichard Henderson     if (!a->imm && a->rs2_or_imm & ~0x1f) {
401486b82fe0SRichard Henderson         return false;
401586b82fe0SRichard Henderson     }
401686b82fe0SRichard Henderson 
401786b82fe0SRichard Henderson     /*
401886b82fe0SRichard Henderson      * Always load the sum into a new temporary.
401986b82fe0SRichard Henderson      * This is required to capture the value across a window change,
402086b82fe0SRichard Henderson      * e.g. SAVE and RESTORE, and may be optimized away otherwise.
402186b82fe0SRichard Henderson      */
402286b82fe0SRichard Henderson     sum = tcg_temp_new();
402386b82fe0SRichard Henderson     src1 = gen_load_gpr(dc, a->rs1);
402486b82fe0SRichard Henderson     if (a->imm || a->rs2_or_imm == 0) {
402586b82fe0SRichard Henderson         tcg_gen_addi_tl(sum, src1, a->rs2_or_imm);
402686b82fe0SRichard Henderson     } else {
402786b82fe0SRichard Henderson         tcg_gen_add_tl(sum, src1, cpu_regs[a->rs2_or_imm]);
402886b82fe0SRichard Henderson     }
402986b82fe0SRichard Henderson     return func(dc, a->rd, sum);
403086b82fe0SRichard Henderson }
403186b82fe0SRichard Henderson 
403286b82fe0SRichard Henderson static bool do_jmpl(DisasContext *dc, int rd, TCGv src)
403386b82fe0SRichard Henderson {
403486b82fe0SRichard Henderson     /*
403586b82fe0SRichard Henderson      * Preserve pc across advance, so that we can delay
403686b82fe0SRichard Henderson      * the writeback to rd until after src is consumed.
403786b82fe0SRichard Henderson      */
403886b82fe0SRichard Henderson     target_ulong cur_pc = dc->pc;
403986b82fe0SRichard Henderson 
404086b82fe0SRichard Henderson     gen_check_align(dc, src, 3);
404186b82fe0SRichard Henderson 
404286b82fe0SRichard Henderson     gen_mov_pc_npc(dc);
404386b82fe0SRichard Henderson     tcg_gen_mov_tl(cpu_npc, src);
404486b82fe0SRichard Henderson     gen_address_mask(dc, cpu_npc);
404586b82fe0SRichard Henderson     gen_store_gpr(dc, rd, tcg_constant_tl(cur_pc));
404686b82fe0SRichard Henderson 
404786b82fe0SRichard Henderson     dc->npc = DYNAMIC_PC_LOOKUP;
404886b82fe0SRichard Henderson     return true;
404986b82fe0SRichard Henderson }
405086b82fe0SRichard Henderson 
405186b82fe0SRichard Henderson TRANS(JMPL, ALL, do_add_special, a, do_jmpl)
405286b82fe0SRichard Henderson 
405386b82fe0SRichard Henderson static bool do_rett(DisasContext *dc, int rd, TCGv src)
405486b82fe0SRichard Henderson {
405586b82fe0SRichard Henderson     if (!supervisor(dc)) {
405686b82fe0SRichard Henderson         return raise_priv(dc);
405786b82fe0SRichard Henderson     }
405886b82fe0SRichard Henderson 
405986b82fe0SRichard Henderson     gen_check_align(dc, src, 3);
406086b82fe0SRichard Henderson 
406186b82fe0SRichard Henderson     gen_mov_pc_npc(dc);
406286b82fe0SRichard Henderson     tcg_gen_mov_tl(cpu_npc, src);
406386b82fe0SRichard Henderson     gen_helper_rett(tcg_env);
406486b82fe0SRichard Henderson 
406586b82fe0SRichard Henderson     dc->npc = DYNAMIC_PC;
406686b82fe0SRichard Henderson     return true;
406786b82fe0SRichard Henderson }
406886b82fe0SRichard Henderson 
406986b82fe0SRichard Henderson TRANS(RETT, 32, do_add_special, a, do_rett)
407086b82fe0SRichard Henderson 
407186b82fe0SRichard Henderson static bool do_return(DisasContext *dc, int rd, TCGv src)
407286b82fe0SRichard Henderson {
407386b82fe0SRichard Henderson     gen_check_align(dc, src, 3);
40740dfae4f9SRichard Henderson     gen_helper_restore(tcg_env);
407586b82fe0SRichard Henderson 
407686b82fe0SRichard Henderson     gen_mov_pc_npc(dc);
407786b82fe0SRichard Henderson     tcg_gen_mov_tl(cpu_npc, src);
407886b82fe0SRichard Henderson     gen_address_mask(dc, cpu_npc);
407986b82fe0SRichard Henderson 
408086b82fe0SRichard Henderson     dc->npc = DYNAMIC_PC_LOOKUP;
408186b82fe0SRichard Henderson     return true;
408286b82fe0SRichard Henderson }
408386b82fe0SRichard Henderson 
408486b82fe0SRichard Henderson TRANS(RETURN, 64, do_add_special, a, do_return)
408586b82fe0SRichard Henderson 
4086d3825800SRichard Henderson static bool do_save(DisasContext *dc, int rd, TCGv src)
4087d3825800SRichard Henderson {
4088d3825800SRichard Henderson     gen_helper_save(tcg_env);
4089d3825800SRichard Henderson     gen_store_gpr(dc, rd, src);
4090d3825800SRichard Henderson     return advance_pc(dc);
4091d3825800SRichard Henderson }
4092d3825800SRichard Henderson 
4093d3825800SRichard Henderson TRANS(SAVE, ALL, do_add_special, a, do_save)
4094d3825800SRichard Henderson 
4095d3825800SRichard Henderson static bool do_restore(DisasContext *dc, int rd, TCGv src)
4096d3825800SRichard Henderson {
4097d3825800SRichard Henderson     gen_helper_restore(tcg_env);
4098d3825800SRichard Henderson     gen_store_gpr(dc, rd, src);
4099d3825800SRichard Henderson     return advance_pc(dc);
4100d3825800SRichard Henderson }
4101d3825800SRichard Henderson 
4102d3825800SRichard Henderson TRANS(RESTORE, ALL, do_add_special, a, do_restore)
4103d3825800SRichard Henderson 
41048f75b8a4SRichard Henderson static bool do_done_retry(DisasContext *dc, bool done)
41058f75b8a4SRichard Henderson {
41068f75b8a4SRichard Henderson     if (!supervisor(dc)) {
41078f75b8a4SRichard Henderson         return raise_priv(dc);
41088f75b8a4SRichard Henderson     }
41098f75b8a4SRichard Henderson     dc->npc = DYNAMIC_PC;
41108f75b8a4SRichard Henderson     dc->pc = DYNAMIC_PC;
41118f75b8a4SRichard Henderson     translator_io_start(&dc->base);
41128f75b8a4SRichard Henderson     if (done) {
41138f75b8a4SRichard Henderson         gen_helper_done(tcg_env);
41148f75b8a4SRichard Henderson     } else {
41158f75b8a4SRichard Henderson         gen_helper_retry(tcg_env);
41168f75b8a4SRichard Henderson     }
41178f75b8a4SRichard Henderson     return true;
41188f75b8a4SRichard Henderson }
41198f75b8a4SRichard Henderson 
41208f75b8a4SRichard Henderson TRANS(DONE, 64, do_done_retry, true)
41218f75b8a4SRichard Henderson TRANS(RETRY, 64, do_done_retry, false)
41228f75b8a4SRichard Henderson 
41230880d20bSRichard Henderson /*
41240880d20bSRichard Henderson  * Major opcode 11 -- load and store instructions
41250880d20bSRichard Henderson  */
41260880d20bSRichard Henderson 
41270880d20bSRichard Henderson static TCGv gen_ldst_addr(DisasContext *dc, int rs1, bool imm, int rs2_or_imm)
41280880d20bSRichard Henderson {
41290880d20bSRichard Henderson     TCGv addr, tmp = NULL;
41300880d20bSRichard Henderson 
41310880d20bSRichard Henderson     /* For simplicity, we under-decoded the rs2 form. */
41320880d20bSRichard Henderson     if (!imm && rs2_or_imm & ~0x1f) {
41330880d20bSRichard Henderson         return NULL;
41340880d20bSRichard Henderson     }
41350880d20bSRichard Henderson 
41360880d20bSRichard Henderson     addr = gen_load_gpr(dc, rs1);
41370880d20bSRichard Henderson     if (rs2_or_imm) {
41380880d20bSRichard Henderson         tmp = tcg_temp_new();
41390880d20bSRichard Henderson         if (imm) {
41400880d20bSRichard Henderson             tcg_gen_addi_tl(tmp, addr, rs2_or_imm);
41410880d20bSRichard Henderson         } else {
41420880d20bSRichard Henderson             tcg_gen_add_tl(tmp, addr, cpu_regs[rs2_or_imm]);
41430880d20bSRichard Henderson         }
41440880d20bSRichard Henderson         addr = tmp;
41450880d20bSRichard Henderson     }
41460880d20bSRichard Henderson     if (AM_CHECK(dc)) {
41470880d20bSRichard Henderson         if (!tmp) {
41480880d20bSRichard Henderson             tmp = tcg_temp_new();
41490880d20bSRichard Henderson         }
41500880d20bSRichard Henderson         tcg_gen_ext32u_tl(tmp, addr);
41510880d20bSRichard Henderson         addr = tmp;
41520880d20bSRichard Henderson     }
41530880d20bSRichard Henderson     return addr;
41540880d20bSRichard Henderson }
41550880d20bSRichard Henderson 
41560880d20bSRichard Henderson static bool do_ld_gpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp mop)
41570880d20bSRichard Henderson {
41580880d20bSRichard Henderson     TCGv reg, addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
41590880d20bSRichard Henderson     DisasASI da;
41600880d20bSRichard Henderson 
41610880d20bSRichard Henderson     if (addr == NULL) {
41620880d20bSRichard Henderson         return false;
41630880d20bSRichard Henderson     }
41640880d20bSRichard Henderson     da = resolve_asi(dc, a->asi, mop);
41650880d20bSRichard Henderson 
41660880d20bSRichard Henderson     reg = gen_dest_gpr(dc, a->rd);
416742071fc1SRichard Henderson     gen_ld_asi(dc, &da, reg, addr);
41680880d20bSRichard Henderson     gen_store_gpr(dc, a->rd, reg);
41690880d20bSRichard Henderson     return advance_pc(dc);
41700880d20bSRichard Henderson }
41710880d20bSRichard Henderson 
41720880d20bSRichard Henderson TRANS(LDUW, ALL, do_ld_gpr, a, MO_TEUL)
41730880d20bSRichard Henderson TRANS(LDUB, ALL, do_ld_gpr, a, MO_UB)
41740880d20bSRichard Henderson TRANS(LDUH, ALL, do_ld_gpr, a, MO_TEUW)
41750880d20bSRichard Henderson TRANS(LDSB, ALL, do_ld_gpr, a, MO_SB)
41760880d20bSRichard Henderson TRANS(LDSH, ALL, do_ld_gpr, a, MO_TESW)
41770880d20bSRichard Henderson TRANS(LDSW, 64, do_ld_gpr, a, MO_TESL)
41780880d20bSRichard Henderson TRANS(LDX, 64, do_ld_gpr, a, MO_TEUQ)
41790880d20bSRichard Henderson 
41800880d20bSRichard Henderson static bool do_st_gpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp mop)
41810880d20bSRichard Henderson {
41820880d20bSRichard Henderson     TCGv reg, addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
41830880d20bSRichard Henderson     DisasASI da;
41840880d20bSRichard Henderson 
41850880d20bSRichard Henderson     if (addr == NULL) {
41860880d20bSRichard Henderson         return false;
41870880d20bSRichard Henderson     }
41880880d20bSRichard Henderson     da = resolve_asi(dc, a->asi, mop);
41890880d20bSRichard Henderson 
41900880d20bSRichard Henderson     reg = gen_load_gpr(dc, a->rd);
419142071fc1SRichard Henderson     gen_st_asi(dc, &da, reg, addr);
41920880d20bSRichard Henderson     return advance_pc(dc);
41930880d20bSRichard Henderson }
41940880d20bSRichard Henderson 
41950880d20bSRichard Henderson TRANS(STW, ALL, do_st_gpr, a, MO_TEUL)
41960880d20bSRichard Henderson TRANS(STB, ALL, do_st_gpr, a, MO_UB)
41970880d20bSRichard Henderson TRANS(STH, ALL, do_st_gpr, a, MO_TEUW)
41980880d20bSRichard Henderson TRANS(STX, 64, do_st_gpr, a, MO_TEUQ)
41990880d20bSRichard Henderson 
42000880d20bSRichard Henderson static bool trans_LDD(DisasContext *dc, arg_r_r_ri_asi *a)
42010880d20bSRichard Henderson {
42020880d20bSRichard Henderson     TCGv addr;
42030880d20bSRichard Henderson     DisasASI da;
42040880d20bSRichard Henderson 
42050880d20bSRichard Henderson     if (a->rd & 1) {
42060880d20bSRichard Henderson         return false;
42070880d20bSRichard Henderson     }
42080880d20bSRichard Henderson     addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
42090880d20bSRichard Henderson     if (addr == NULL) {
42100880d20bSRichard Henderson         return false;
42110880d20bSRichard Henderson     }
42120880d20bSRichard Henderson     da = resolve_asi(dc, a->asi, MO_TEUQ);
421342071fc1SRichard Henderson     gen_ldda_asi(dc, &da, addr, a->rd);
42140880d20bSRichard Henderson     return advance_pc(dc);
42150880d20bSRichard Henderson }
42160880d20bSRichard Henderson 
42170880d20bSRichard Henderson static bool trans_STD(DisasContext *dc, arg_r_r_ri_asi *a)
42180880d20bSRichard Henderson {
42190880d20bSRichard Henderson     TCGv addr;
42200880d20bSRichard Henderson     DisasASI da;
42210880d20bSRichard Henderson 
42220880d20bSRichard Henderson     if (a->rd & 1) {
42230880d20bSRichard Henderson         return false;
42240880d20bSRichard Henderson     }
42250880d20bSRichard Henderson     addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
42260880d20bSRichard Henderson     if (addr == NULL) {
42270880d20bSRichard Henderson         return false;
42280880d20bSRichard Henderson     }
42290880d20bSRichard Henderson     da = resolve_asi(dc, a->asi, MO_TEUQ);
423042071fc1SRichard Henderson     gen_stda_asi(dc, &da, addr, a->rd);
42310880d20bSRichard Henderson     return advance_pc(dc);
42320880d20bSRichard Henderson }
42330880d20bSRichard Henderson 
4234cf07cd1eSRichard Henderson static bool trans_LDSTUB(DisasContext *dc, arg_r_r_ri_asi *a)
4235cf07cd1eSRichard Henderson {
4236cf07cd1eSRichard Henderson     TCGv addr, reg;
4237cf07cd1eSRichard Henderson     DisasASI da;
4238cf07cd1eSRichard Henderson 
4239cf07cd1eSRichard Henderson     addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
4240cf07cd1eSRichard Henderson     if (addr == NULL) {
4241cf07cd1eSRichard Henderson         return false;
4242cf07cd1eSRichard Henderson     }
4243cf07cd1eSRichard Henderson     da = resolve_asi(dc, a->asi, MO_UB);
4244cf07cd1eSRichard Henderson 
4245cf07cd1eSRichard Henderson     reg = gen_dest_gpr(dc, a->rd);
4246cf07cd1eSRichard Henderson     gen_ldstub_asi(dc, &da, reg, addr);
4247cf07cd1eSRichard Henderson     gen_store_gpr(dc, a->rd, reg);
4248cf07cd1eSRichard Henderson     return advance_pc(dc);
4249cf07cd1eSRichard Henderson }
4250cf07cd1eSRichard Henderson 
4251dca544b9SRichard Henderson static bool trans_SWAP(DisasContext *dc, arg_r_r_ri_asi *a)
4252dca544b9SRichard Henderson {
4253dca544b9SRichard Henderson     TCGv addr, dst, src;
4254dca544b9SRichard Henderson     DisasASI da;
4255dca544b9SRichard Henderson 
4256dca544b9SRichard Henderson     addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
4257dca544b9SRichard Henderson     if (addr == NULL) {
4258dca544b9SRichard Henderson         return false;
4259dca544b9SRichard Henderson     }
4260dca544b9SRichard Henderson     da = resolve_asi(dc, a->asi, MO_TEUL);
4261dca544b9SRichard Henderson 
4262dca544b9SRichard Henderson     dst = gen_dest_gpr(dc, a->rd);
4263dca544b9SRichard Henderson     src = gen_load_gpr(dc, a->rd);
4264dca544b9SRichard Henderson     gen_swap_asi(dc, &da, dst, src, addr);
4265dca544b9SRichard Henderson     gen_store_gpr(dc, a->rd, dst);
4266dca544b9SRichard Henderson     return advance_pc(dc);
4267dca544b9SRichard Henderson }
4268dca544b9SRichard Henderson 
4269d0a11d25SRichard Henderson static bool do_casa(DisasContext *dc, arg_r_r_ri_asi *a, MemOp mop)
4270d0a11d25SRichard Henderson {
4271d0a11d25SRichard Henderson     TCGv addr, o, n, c;
4272d0a11d25SRichard Henderson     DisasASI da;
4273d0a11d25SRichard Henderson 
4274d0a11d25SRichard Henderson     addr = gen_ldst_addr(dc, a->rs1, true, 0);
4275d0a11d25SRichard Henderson     if (addr == NULL) {
4276d0a11d25SRichard Henderson         return false;
4277d0a11d25SRichard Henderson     }
4278d0a11d25SRichard Henderson     da = resolve_asi(dc, a->asi, mop);
4279d0a11d25SRichard Henderson 
4280d0a11d25SRichard Henderson     o = gen_dest_gpr(dc, a->rd);
4281d0a11d25SRichard Henderson     n = gen_load_gpr(dc, a->rd);
4282d0a11d25SRichard Henderson     c = gen_load_gpr(dc, a->rs2_or_imm);
4283d0a11d25SRichard Henderson     gen_cas_asi(dc, &da, o, n, c, addr);
4284d0a11d25SRichard Henderson     gen_store_gpr(dc, a->rd, o);
4285d0a11d25SRichard Henderson     return advance_pc(dc);
4286d0a11d25SRichard Henderson }
4287d0a11d25SRichard Henderson 
4288d0a11d25SRichard Henderson TRANS(CASA, CASA, do_casa, a, MO_TEUL)
4289d0a11d25SRichard Henderson TRANS(CASXA, 64, do_casa, a, MO_TEUQ)
4290d0a11d25SRichard Henderson 
429106c060d9SRichard Henderson static bool do_ld_fpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp sz)
429206c060d9SRichard Henderson {
429306c060d9SRichard Henderson     TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
429406c060d9SRichard Henderson     DisasASI da;
429506c060d9SRichard Henderson 
429606c060d9SRichard Henderson     if (addr == NULL) {
429706c060d9SRichard Henderson         return false;
429806c060d9SRichard Henderson     }
429906c060d9SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
430006c060d9SRichard Henderson         return true;
430106c060d9SRichard Henderson     }
430206c060d9SRichard Henderson     if (sz == MO_128 && gen_trap_float128(dc)) {
430306c060d9SRichard Henderson         return true;
430406c060d9SRichard Henderson     }
430506c060d9SRichard Henderson     da = resolve_asi(dc, a->asi, MO_TE | sz);
4306287b1152SRichard Henderson     gen_ldf_asi(dc, &da, sz, addr, a->rd);
430706c060d9SRichard Henderson     gen_update_fprs_dirty(dc, a->rd);
430806c060d9SRichard Henderson     return advance_pc(dc);
430906c060d9SRichard Henderson }
431006c060d9SRichard Henderson 
431106c060d9SRichard Henderson TRANS(LDF, ALL, do_ld_fpr, a, MO_32)
431206c060d9SRichard Henderson TRANS(LDDF, ALL, do_ld_fpr, a, MO_64)
431306c060d9SRichard Henderson TRANS(LDQF, ALL, do_ld_fpr, a, MO_128)
431406c060d9SRichard Henderson 
4315287b1152SRichard Henderson TRANS(LDFA, 64, do_ld_fpr, a, MO_32)
4316287b1152SRichard Henderson TRANS(LDDFA, 64, do_ld_fpr, a, MO_64)
4317287b1152SRichard Henderson TRANS(LDQFA, 64, do_ld_fpr, a, MO_128)
4318287b1152SRichard Henderson 
431906c060d9SRichard Henderson static bool do_st_fpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp sz)
432006c060d9SRichard Henderson {
432106c060d9SRichard Henderson     TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
432206c060d9SRichard Henderson     DisasASI da;
432306c060d9SRichard Henderson 
432406c060d9SRichard Henderson     if (addr == NULL) {
432506c060d9SRichard Henderson         return false;
432606c060d9SRichard Henderson     }
432706c060d9SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
432806c060d9SRichard Henderson         return true;
432906c060d9SRichard Henderson     }
433006c060d9SRichard Henderson     if (sz == MO_128 && gen_trap_float128(dc)) {
433106c060d9SRichard Henderson         return true;
433206c060d9SRichard Henderson     }
433306c060d9SRichard Henderson     da = resolve_asi(dc, a->asi, MO_TE | sz);
4334287b1152SRichard Henderson     gen_stf_asi(dc, &da, sz, addr, a->rd);
433506c060d9SRichard Henderson     return advance_pc(dc);
433606c060d9SRichard Henderson }
433706c060d9SRichard Henderson 
433806c060d9SRichard Henderson TRANS(STF, ALL, do_st_fpr, a, MO_32)
433906c060d9SRichard Henderson TRANS(STDF, ALL, do_st_fpr, a, MO_64)
434006c060d9SRichard Henderson TRANS(STQF, ALL, do_st_fpr, a, MO_128)
434106c060d9SRichard Henderson 
4342287b1152SRichard Henderson TRANS(STFA, 64, do_st_fpr, a, MO_32)
4343287b1152SRichard Henderson TRANS(STDFA, 64, do_st_fpr, a, MO_64)
4344287b1152SRichard Henderson TRANS(STQFA, 64, do_st_fpr, a, MO_128)
4345287b1152SRichard Henderson 
434606c060d9SRichard Henderson static bool trans_STDFQ(DisasContext *dc, arg_STDFQ *a)
434706c060d9SRichard Henderson {
434806c060d9SRichard Henderson     if (!avail_32(dc)) {
434906c060d9SRichard Henderson         return false;
435006c060d9SRichard Henderson     }
435106c060d9SRichard Henderson     if (!supervisor(dc)) {
435206c060d9SRichard Henderson         return raise_priv(dc);
435306c060d9SRichard Henderson     }
435406c060d9SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
435506c060d9SRichard Henderson         return true;
435606c060d9SRichard Henderson     }
435706c060d9SRichard Henderson     gen_op_fpexception_im(dc, FSR_FTT_SEQ_ERROR);
435806c060d9SRichard Henderson     return true;
435906c060d9SRichard Henderson }
436006c060d9SRichard Henderson 
4361d8c5b92fSRichard Henderson static bool trans_LDFSR(DisasContext *dc, arg_r_r_ri *a)
43623d3c0673SRichard Henderson {
43633590f01eSRichard Henderson     TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
4364d8c5b92fSRichard Henderson     TCGv_i32 tmp;
43653590f01eSRichard Henderson 
43663d3c0673SRichard Henderson     if (addr == NULL) {
43673d3c0673SRichard Henderson         return false;
43683d3c0673SRichard Henderson     }
43693d3c0673SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
43703d3c0673SRichard Henderson         return true;
43713d3c0673SRichard Henderson     }
4372d8c5b92fSRichard Henderson 
4373d8c5b92fSRichard Henderson     tmp = tcg_temp_new_i32();
4374d8c5b92fSRichard Henderson     tcg_gen_qemu_ld_i32(tmp, addr, dc->mem_idx, MO_TEUL | MO_ALIGN);
4375d8c5b92fSRichard Henderson 
4376d8c5b92fSRichard Henderson     tcg_gen_extract_i32(cpu_fcc[0], tmp, FSR_FCC0_SHIFT, 2);
4377d8c5b92fSRichard Henderson     /* LDFSR does not change FCC[1-3]. */
4378d8c5b92fSRichard Henderson 
4379d8c5b92fSRichard Henderson     gen_helper_set_fsr_nofcc_noftt(tcg_env, tmp);
43803d3c0673SRichard Henderson     return advance_pc(dc);
43813d3c0673SRichard Henderson }
43823d3c0673SRichard Henderson 
4383d8c5b92fSRichard Henderson static bool trans_LDXFSR(DisasContext *dc, arg_r_r_ri *a)
4384d8c5b92fSRichard Henderson {
4385d8c5b92fSRichard Henderson #ifdef TARGET_SPARC64
4386d8c5b92fSRichard Henderson     TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
4387d8c5b92fSRichard Henderson     TCGv_i64 t64;
4388d8c5b92fSRichard Henderson     TCGv_i32 lo, hi;
4389d8c5b92fSRichard Henderson 
4390d8c5b92fSRichard Henderson     if (addr == NULL) {
4391d8c5b92fSRichard Henderson         return false;
4392d8c5b92fSRichard Henderson     }
4393d8c5b92fSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4394d8c5b92fSRichard Henderson         return true;
4395d8c5b92fSRichard Henderson     }
4396d8c5b92fSRichard Henderson 
4397d8c5b92fSRichard Henderson     t64 = tcg_temp_new_i64();
4398d8c5b92fSRichard Henderson     tcg_gen_qemu_ld_i64(t64, addr, dc->mem_idx, MO_TEUQ | MO_ALIGN);
4399d8c5b92fSRichard Henderson 
4400d8c5b92fSRichard Henderson     lo = tcg_temp_new_i32();
4401d8c5b92fSRichard Henderson     hi = cpu_fcc[3];
4402d8c5b92fSRichard Henderson     tcg_gen_extr_i64_i32(lo, hi, t64);
4403d8c5b92fSRichard Henderson     tcg_gen_extract_i32(cpu_fcc[0], lo, FSR_FCC0_SHIFT, 2);
4404d8c5b92fSRichard Henderson     tcg_gen_extract_i32(cpu_fcc[1], hi, FSR_FCC1_SHIFT - 32, 2);
4405d8c5b92fSRichard Henderson     tcg_gen_extract_i32(cpu_fcc[2], hi, FSR_FCC2_SHIFT - 32, 2);
4406d8c5b92fSRichard Henderson     tcg_gen_extract_i32(cpu_fcc[3], hi, FSR_FCC3_SHIFT - 32, 2);
4407d8c5b92fSRichard Henderson 
4408d8c5b92fSRichard Henderson     gen_helper_set_fsr_nofcc_noftt(tcg_env, lo);
4409d8c5b92fSRichard Henderson     return advance_pc(dc);
4410d8c5b92fSRichard Henderson #else
4411d8c5b92fSRichard Henderson     return false;
4412d8c5b92fSRichard Henderson #endif
4413d8c5b92fSRichard Henderson }
44143d3c0673SRichard Henderson 
44153d3c0673SRichard Henderson static bool do_stfsr(DisasContext *dc, arg_r_r_ri *a, MemOp mop)
44163d3c0673SRichard Henderson {
44173d3c0673SRichard Henderson     TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
44181ccd6e13SRichard Henderson     TCGv fsr;
44191ccd6e13SRichard Henderson 
44203d3c0673SRichard Henderson     if (addr == NULL) {
44213d3c0673SRichard Henderson         return false;
44223d3c0673SRichard Henderson     }
44233d3c0673SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
44243d3c0673SRichard Henderson         return true;
44253d3c0673SRichard Henderson     }
44261ccd6e13SRichard Henderson 
44271ccd6e13SRichard Henderson     fsr = tcg_temp_new();
44281ccd6e13SRichard Henderson     gen_helper_get_fsr(fsr, tcg_env);
44291ccd6e13SRichard Henderson     tcg_gen_qemu_st_tl(fsr, addr, dc->mem_idx, mop | MO_ALIGN);
44303d3c0673SRichard Henderson     return advance_pc(dc);
44313d3c0673SRichard Henderson }
44323d3c0673SRichard Henderson 
44333d3c0673SRichard Henderson TRANS(STFSR, ALL, do_stfsr, a, MO_TEUL)
44343d3c0673SRichard Henderson TRANS(STXFSR, 64, do_stfsr, a, MO_TEUQ)
44353d3c0673SRichard Henderson 
44361210a036SRichard Henderson static bool do_fc(DisasContext *dc, int rd, int32_t c)
44373a38260eSRichard Henderson {
44383a38260eSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
44393a38260eSRichard Henderson         return true;
44403a38260eSRichard Henderson     }
44411210a036SRichard Henderson     gen_store_fpr_F(dc, rd, tcg_constant_i32(c));
44423a38260eSRichard Henderson     return advance_pc(dc);
44433a38260eSRichard Henderson }
44443a38260eSRichard Henderson 
44453a38260eSRichard Henderson TRANS(FZEROs, VIS1, do_fc, a->rd, 0)
44461210a036SRichard Henderson TRANS(FONEs, VIS1, do_fc, a->rd, -1)
44473a38260eSRichard Henderson 
44483a38260eSRichard Henderson static bool do_dc(DisasContext *dc, int rd, int64_t c)
44493a38260eSRichard Henderson {
44503a38260eSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
44513a38260eSRichard Henderson         return true;
44523a38260eSRichard Henderson     }
44531210a036SRichard Henderson     gen_store_fpr_D(dc, rd, tcg_constant_i64(c));
44543a38260eSRichard Henderson     return advance_pc(dc);
44553a38260eSRichard Henderson }
44563a38260eSRichard Henderson 
44573a38260eSRichard Henderson TRANS(FZEROd, VIS1, do_dc, a->rd, 0)
44583a38260eSRichard Henderson TRANS(FONEd, VIS1, do_dc, a->rd, -1)
44593a38260eSRichard Henderson 
4460baf3dbf2SRichard Henderson static bool do_ff(DisasContext *dc, arg_r_r *a,
4461baf3dbf2SRichard Henderson                   void (*func)(TCGv_i32, TCGv_i32))
4462baf3dbf2SRichard Henderson {
4463baf3dbf2SRichard Henderson     TCGv_i32 tmp;
4464baf3dbf2SRichard Henderson 
4465baf3dbf2SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4466baf3dbf2SRichard Henderson         return true;
4467baf3dbf2SRichard Henderson     }
4468baf3dbf2SRichard Henderson 
4469baf3dbf2SRichard Henderson     tmp = gen_load_fpr_F(dc, a->rs);
4470baf3dbf2SRichard Henderson     func(tmp, tmp);
4471baf3dbf2SRichard Henderson     gen_store_fpr_F(dc, a->rd, tmp);
4472baf3dbf2SRichard Henderson     return advance_pc(dc);
4473baf3dbf2SRichard Henderson }
4474baf3dbf2SRichard Henderson 
4475baf3dbf2SRichard Henderson TRANS(FMOVs, ALL, do_ff, a, gen_op_fmovs)
4476baf3dbf2SRichard Henderson TRANS(FNEGs, ALL, do_ff, a, gen_op_fnegs)
4477baf3dbf2SRichard Henderson TRANS(FABSs, ALL, do_ff, a, gen_op_fabss)
4478baf3dbf2SRichard Henderson TRANS(FSRCs, VIS1, do_ff, a, tcg_gen_mov_i32)
4479baf3dbf2SRichard Henderson TRANS(FNOTs, VIS1, do_ff, a, tcg_gen_not_i32)
4480baf3dbf2SRichard Henderson 
44812f722641SRichard Henderson static bool do_fd(DisasContext *dc, arg_r_r *a,
44822f722641SRichard Henderson                   void (*func)(TCGv_i32, TCGv_i64))
44832f722641SRichard Henderson {
44842f722641SRichard Henderson     TCGv_i32 dst;
44852f722641SRichard Henderson     TCGv_i64 src;
44862f722641SRichard Henderson 
44872f722641SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
44882f722641SRichard Henderson         return true;
44892f722641SRichard Henderson     }
44902f722641SRichard Henderson 
4491388a6465SRichard Henderson     dst = tcg_temp_new_i32();
44922f722641SRichard Henderson     src = gen_load_fpr_D(dc, a->rs);
44932f722641SRichard Henderson     func(dst, src);
44942f722641SRichard Henderson     gen_store_fpr_F(dc, a->rd, dst);
44952f722641SRichard Henderson     return advance_pc(dc);
44962f722641SRichard Henderson }
44972f722641SRichard Henderson 
44982f722641SRichard Henderson TRANS(FPACK16, VIS1, do_fd, a, gen_op_fpack16)
44992f722641SRichard Henderson TRANS(FPACKFIX, VIS1, do_fd, a, gen_op_fpackfix)
45002f722641SRichard Henderson 
4501119cb94fSRichard Henderson static bool do_env_ff(DisasContext *dc, arg_r_r *a,
4502119cb94fSRichard Henderson                       void (*func)(TCGv_i32, TCGv_env, TCGv_i32))
4503119cb94fSRichard Henderson {
4504119cb94fSRichard Henderson     TCGv_i32 tmp;
4505119cb94fSRichard Henderson 
4506119cb94fSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4507119cb94fSRichard Henderson         return true;
4508119cb94fSRichard Henderson     }
4509119cb94fSRichard Henderson 
4510119cb94fSRichard Henderson     tmp = gen_load_fpr_F(dc, a->rs);
4511119cb94fSRichard Henderson     func(tmp, tcg_env, tmp);
4512119cb94fSRichard Henderson     gen_store_fpr_F(dc, a->rd, tmp);
4513119cb94fSRichard Henderson     return advance_pc(dc);
4514119cb94fSRichard Henderson }
4515119cb94fSRichard Henderson 
4516119cb94fSRichard Henderson TRANS(FSQRTs, ALL, do_env_ff, a, gen_helper_fsqrts)
4517119cb94fSRichard Henderson TRANS(FiTOs, ALL, do_env_ff, a, gen_helper_fitos)
4518119cb94fSRichard Henderson TRANS(FsTOi, ALL, do_env_ff, a, gen_helper_fstoi)
4519119cb94fSRichard Henderson 
45208c94bcd8SRichard Henderson static bool do_env_fd(DisasContext *dc, arg_r_r *a,
45218c94bcd8SRichard Henderson                       void (*func)(TCGv_i32, TCGv_env, TCGv_i64))
45228c94bcd8SRichard Henderson {
45238c94bcd8SRichard Henderson     TCGv_i32 dst;
45248c94bcd8SRichard Henderson     TCGv_i64 src;
45258c94bcd8SRichard Henderson 
45268c94bcd8SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
45278c94bcd8SRichard Henderson         return true;
45288c94bcd8SRichard Henderson     }
45298c94bcd8SRichard Henderson 
4530388a6465SRichard Henderson     dst = tcg_temp_new_i32();
45318c94bcd8SRichard Henderson     src = gen_load_fpr_D(dc, a->rs);
45328c94bcd8SRichard Henderson     func(dst, tcg_env, src);
45338c94bcd8SRichard Henderson     gen_store_fpr_F(dc, a->rd, dst);
45348c94bcd8SRichard Henderson     return advance_pc(dc);
45358c94bcd8SRichard Henderson }
45368c94bcd8SRichard Henderson 
45378c94bcd8SRichard Henderson TRANS(FdTOs, ALL, do_env_fd, a, gen_helper_fdtos)
45388c94bcd8SRichard Henderson TRANS(FdTOi, ALL, do_env_fd, a, gen_helper_fdtoi)
45398c94bcd8SRichard Henderson TRANS(FxTOs, 64, do_env_fd, a, gen_helper_fxtos)
45408c94bcd8SRichard Henderson 
4541c6d83e4fSRichard Henderson static bool do_dd(DisasContext *dc, arg_r_r *a,
4542c6d83e4fSRichard Henderson                   void (*func)(TCGv_i64, TCGv_i64))
4543c6d83e4fSRichard Henderson {
4544c6d83e4fSRichard Henderson     TCGv_i64 dst, src;
4545c6d83e4fSRichard Henderson 
4546c6d83e4fSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4547c6d83e4fSRichard Henderson         return true;
4548c6d83e4fSRichard Henderson     }
4549c6d83e4fSRichard Henderson 
455052f46d46SRichard Henderson     dst = tcg_temp_new_i64();
4551c6d83e4fSRichard Henderson     src = gen_load_fpr_D(dc, a->rs);
4552c6d83e4fSRichard Henderson     func(dst, src);
4553c6d83e4fSRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
4554c6d83e4fSRichard Henderson     return advance_pc(dc);
4555c6d83e4fSRichard Henderson }
4556c6d83e4fSRichard Henderson 
4557c6d83e4fSRichard Henderson TRANS(FMOVd, 64, do_dd, a, gen_op_fmovd)
4558c6d83e4fSRichard Henderson TRANS(FNEGd, 64, do_dd, a, gen_op_fnegd)
4559c6d83e4fSRichard Henderson TRANS(FABSd, 64, do_dd, a, gen_op_fabsd)
4560c6d83e4fSRichard Henderson TRANS(FSRCd, VIS1, do_dd, a, tcg_gen_mov_i64)
4561c6d83e4fSRichard Henderson TRANS(FNOTd, VIS1, do_dd, a, tcg_gen_not_i64)
4562c6d83e4fSRichard Henderson 
45638aa418b3SRichard Henderson static bool do_env_dd(DisasContext *dc, arg_r_r *a,
45648aa418b3SRichard Henderson                       void (*func)(TCGv_i64, TCGv_env, TCGv_i64))
45658aa418b3SRichard Henderson {
45668aa418b3SRichard Henderson     TCGv_i64 dst, src;
45678aa418b3SRichard Henderson 
45688aa418b3SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
45698aa418b3SRichard Henderson         return true;
45708aa418b3SRichard Henderson     }
45718aa418b3SRichard Henderson 
457252f46d46SRichard Henderson     dst = tcg_temp_new_i64();
45738aa418b3SRichard Henderson     src = gen_load_fpr_D(dc, a->rs);
45748aa418b3SRichard Henderson     func(dst, tcg_env, src);
45758aa418b3SRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
45768aa418b3SRichard Henderson     return advance_pc(dc);
45778aa418b3SRichard Henderson }
45788aa418b3SRichard Henderson 
45798aa418b3SRichard Henderson TRANS(FSQRTd, ALL, do_env_dd, a, gen_helper_fsqrtd)
45808aa418b3SRichard Henderson TRANS(FxTOd, 64, do_env_dd, a, gen_helper_fxtod)
45818aa418b3SRichard Henderson TRANS(FdTOx, 64, do_env_dd, a, gen_helper_fdtox)
45828aa418b3SRichard Henderson 
45837b616f36SRichard Henderson static bool do_df(DisasContext *dc, arg_r_r *a,
45847b616f36SRichard Henderson                   void (*func)(TCGv_i64, TCGv_i32))
45857b616f36SRichard Henderson {
45867b616f36SRichard Henderson     TCGv_i64 dst;
45877b616f36SRichard Henderson     TCGv_i32 src;
45887b616f36SRichard Henderson 
45897b616f36SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
45907b616f36SRichard Henderson         return true;
45917b616f36SRichard Henderson     }
45927b616f36SRichard Henderson 
45937b616f36SRichard Henderson     dst = tcg_temp_new_i64();
45947b616f36SRichard Henderson     src = gen_load_fpr_F(dc, a->rs);
45957b616f36SRichard Henderson     func(dst, src);
45967b616f36SRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
45977b616f36SRichard Henderson     return advance_pc(dc);
45987b616f36SRichard Henderson }
45997b616f36SRichard Henderson 
46007b616f36SRichard Henderson TRANS(FEXPAND, VIS1, do_df, a, gen_helper_fexpand)
46017b616f36SRichard Henderson 
4602199d43efSRichard Henderson static bool do_env_df(DisasContext *dc, arg_r_r *a,
4603199d43efSRichard Henderson                       void (*func)(TCGv_i64, TCGv_env, TCGv_i32))
4604199d43efSRichard Henderson {
4605199d43efSRichard Henderson     TCGv_i64 dst;
4606199d43efSRichard Henderson     TCGv_i32 src;
4607199d43efSRichard Henderson 
4608199d43efSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4609199d43efSRichard Henderson         return true;
4610199d43efSRichard Henderson     }
4611199d43efSRichard Henderson 
461252f46d46SRichard Henderson     dst = tcg_temp_new_i64();
4613199d43efSRichard Henderson     src = gen_load_fpr_F(dc, a->rs);
4614199d43efSRichard Henderson     func(dst, tcg_env, src);
4615199d43efSRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
4616199d43efSRichard Henderson     return advance_pc(dc);
4617199d43efSRichard Henderson }
4618199d43efSRichard Henderson 
4619199d43efSRichard Henderson TRANS(FiTOd, ALL, do_env_df, a, gen_helper_fitod)
4620199d43efSRichard Henderson TRANS(FsTOd, ALL, do_env_df, a, gen_helper_fstod)
4621199d43efSRichard Henderson TRANS(FsTOx, 64, do_env_df, a, gen_helper_fstox)
4622199d43efSRichard Henderson 
4623daf457d4SRichard Henderson static bool do_qq(DisasContext *dc, arg_r_r *a,
4624daf457d4SRichard Henderson                   void (*func)(TCGv_i128, TCGv_i128))
4625f4e18df5SRichard Henderson {
462633ec4245SRichard Henderson     TCGv_i128 t;
4627f4e18df5SRichard Henderson 
4628f4e18df5SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4629f4e18df5SRichard Henderson         return true;
4630f4e18df5SRichard Henderson     }
4631f4e18df5SRichard Henderson     if (gen_trap_float128(dc)) {
4632f4e18df5SRichard Henderson         return true;
4633f4e18df5SRichard Henderson     }
4634f4e18df5SRichard Henderson 
4635f4e18df5SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
463633ec4245SRichard Henderson     t = gen_load_fpr_Q(dc, a->rs);
4637daf457d4SRichard Henderson     func(t, t);
463833ec4245SRichard Henderson     gen_store_fpr_Q(dc, a->rd, t);
4639f4e18df5SRichard Henderson     return advance_pc(dc);
4640f4e18df5SRichard Henderson }
4641f4e18df5SRichard Henderson 
4642daf457d4SRichard Henderson TRANS(FMOVq, 64, do_qq, a, tcg_gen_mov_i128)
4643daf457d4SRichard Henderson TRANS(FNEGq, 64, do_qq, a, gen_op_fnegq)
4644daf457d4SRichard Henderson TRANS(FABSq, 64, do_qq, a, gen_op_fabsq)
4645f4e18df5SRichard Henderson 
4646c995216bSRichard Henderson static bool do_env_qq(DisasContext *dc, arg_r_r *a,
4647e41716beSRichard Henderson                       void (*func)(TCGv_i128, TCGv_env, TCGv_i128))
4648c995216bSRichard Henderson {
4649e41716beSRichard Henderson     TCGv_i128 t;
4650e41716beSRichard Henderson 
4651c995216bSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4652c995216bSRichard Henderson         return true;
4653c995216bSRichard Henderson     }
4654c995216bSRichard Henderson     if (gen_trap_float128(dc)) {
4655c995216bSRichard Henderson         return true;
4656c995216bSRichard Henderson     }
4657c995216bSRichard Henderson 
4658e41716beSRichard Henderson     t = gen_load_fpr_Q(dc, a->rs);
4659e41716beSRichard Henderson     func(t, tcg_env, t);
4660e41716beSRichard Henderson     gen_store_fpr_Q(dc, a->rd, t);
4661c995216bSRichard Henderson     return advance_pc(dc);
4662c995216bSRichard Henderson }
4663c995216bSRichard Henderson 
4664c995216bSRichard Henderson TRANS(FSQRTq, ALL, do_env_qq, a, gen_helper_fsqrtq)
4665c995216bSRichard Henderson 
4666bd9c5c42SRichard Henderson static bool do_env_fq(DisasContext *dc, arg_r_r *a,
4667d81e3efeSRichard Henderson                       void (*func)(TCGv_i32, TCGv_env, TCGv_i128))
4668bd9c5c42SRichard Henderson {
4669d81e3efeSRichard Henderson     TCGv_i128 src;
4670bd9c5c42SRichard Henderson     TCGv_i32 dst;
4671bd9c5c42SRichard Henderson 
4672bd9c5c42SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4673bd9c5c42SRichard Henderson         return true;
4674bd9c5c42SRichard Henderson     }
4675bd9c5c42SRichard Henderson     if (gen_trap_float128(dc)) {
4676bd9c5c42SRichard Henderson         return true;
4677bd9c5c42SRichard Henderson     }
4678bd9c5c42SRichard Henderson 
4679d81e3efeSRichard Henderson     src = gen_load_fpr_Q(dc, a->rs);
4680388a6465SRichard Henderson     dst = tcg_temp_new_i32();
4681d81e3efeSRichard Henderson     func(dst, tcg_env, src);
4682bd9c5c42SRichard Henderson     gen_store_fpr_F(dc, a->rd, dst);
4683bd9c5c42SRichard Henderson     return advance_pc(dc);
4684bd9c5c42SRichard Henderson }
4685bd9c5c42SRichard Henderson 
4686bd9c5c42SRichard Henderson TRANS(FqTOs, ALL, do_env_fq, a, gen_helper_fqtos)
4687bd9c5c42SRichard Henderson TRANS(FqTOi, ALL, do_env_fq, a, gen_helper_fqtoi)
4688bd9c5c42SRichard Henderson 
46891617586fSRichard Henderson static bool do_env_dq(DisasContext *dc, arg_r_r *a,
469025a5769eSRichard Henderson                       void (*func)(TCGv_i64, TCGv_env, TCGv_i128))
46911617586fSRichard Henderson {
469225a5769eSRichard Henderson     TCGv_i128 src;
46931617586fSRichard Henderson     TCGv_i64 dst;
46941617586fSRichard Henderson 
46951617586fSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
46961617586fSRichard Henderson         return true;
46971617586fSRichard Henderson     }
46981617586fSRichard Henderson     if (gen_trap_float128(dc)) {
46991617586fSRichard Henderson         return true;
47001617586fSRichard Henderson     }
47011617586fSRichard Henderson 
470225a5769eSRichard Henderson     src = gen_load_fpr_Q(dc, a->rs);
470352f46d46SRichard Henderson     dst = tcg_temp_new_i64();
470425a5769eSRichard Henderson     func(dst, tcg_env, src);
47051617586fSRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
47061617586fSRichard Henderson     return advance_pc(dc);
47071617586fSRichard Henderson }
47081617586fSRichard Henderson 
47091617586fSRichard Henderson TRANS(FqTOd, ALL, do_env_dq, a, gen_helper_fqtod)
47101617586fSRichard Henderson TRANS(FqTOx, 64, do_env_dq, a, gen_helper_fqtox)
47111617586fSRichard Henderson 
471213ebcc77SRichard Henderson static bool do_env_qf(DisasContext *dc, arg_r_r *a,
47130b2a61ccSRichard Henderson                       void (*func)(TCGv_i128, TCGv_env, TCGv_i32))
471413ebcc77SRichard Henderson {
471513ebcc77SRichard Henderson     TCGv_i32 src;
47160b2a61ccSRichard Henderson     TCGv_i128 dst;
471713ebcc77SRichard Henderson 
471813ebcc77SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
471913ebcc77SRichard Henderson         return true;
472013ebcc77SRichard Henderson     }
472113ebcc77SRichard Henderson     if (gen_trap_float128(dc)) {
472213ebcc77SRichard Henderson         return true;
472313ebcc77SRichard Henderson     }
472413ebcc77SRichard Henderson 
472513ebcc77SRichard Henderson     src = gen_load_fpr_F(dc, a->rs);
47260b2a61ccSRichard Henderson     dst = tcg_temp_new_i128();
47270b2a61ccSRichard Henderson     func(dst, tcg_env, src);
47280b2a61ccSRichard Henderson     gen_store_fpr_Q(dc, a->rd, dst);
472913ebcc77SRichard Henderson     return advance_pc(dc);
473013ebcc77SRichard Henderson }
473113ebcc77SRichard Henderson 
473213ebcc77SRichard Henderson TRANS(FiTOq, ALL, do_env_qf, a, gen_helper_fitoq)
473313ebcc77SRichard Henderson TRANS(FsTOq, ALL, do_env_qf, a, gen_helper_fstoq)
473413ebcc77SRichard Henderson 
47357b8e3e1aSRichard Henderson static bool do_env_qd(DisasContext *dc, arg_r_r *a,
4736fdc50716SRichard Henderson                       void (*func)(TCGv_i128, TCGv_env, TCGv_i64))
47377b8e3e1aSRichard Henderson {
47387b8e3e1aSRichard Henderson     TCGv_i64 src;
4739fdc50716SRichard Henderson     TCGv_i128 dst;
47407b8e3e1aSRichard Henderson 
47417b8e3e1aSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
47427b8e3e1aSRichard Henderson         return true;
47437b8e3e1aSRichard Henderson     }
47447b8e3e1aSRichard Henderson     if (gen_trap_float128(dc)) {
47457b8e3e1aSRichard Henderson         return true;
47467b8e3e1aSRichard Henderson     }
47477b8e3e1aSRichard Henderson 
47487b8e3e1aSRichard Henderson     src = gen_load_fpr_D(dc, a->rs);
4749fdc50716SRichard Henderson     dst = tcg_temp_new_i128();
4750fdc50716SRichard Henderson     func(dst, tcg_env, src);
4751fdc50716SRichard Henderson     gen_store_fpr_Q(dc, a->rd, dst);
47527b8e3e1aSRichard Henderson     return advance_pc(dc);
47537b8e3e1aSRichard Henderson }
47547b8e3e1aSRichard Henderson 
47557b8e3e1aSRichard Henderson TRANS(FdTOq, ALL, do_env_qd, a, gen_helper_fdtoq)
47567b8e3e1aSRichard Henderson TRANS(FxTOq, 64, do_env_qd, a, gen_helper_fxtoq)
47577b8e3e1aSRichard Henderson 
47587f10b52fSRichard Henderson static bool do_fff(DisasContext *dc, arg_r_r_r *a,
47597f10b52fSRichard Henderson                    void (*func)(TCGv_i32, TCGv_i32, TCGv_i32))
47607f10b52fSRichard Henderson {
47617f10b52fSRichard Henderson     TCGv_i32 src1, src2;
47627f10b52fSRichard Henderson 
47637f10b52fSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
47647f10b52fSRichard Henderson         return true;
47657f10b52fSRichard Henderson     }
47667f10b52fSRichard Henderson 
47677f10b52fSRichard Henderson     src1 = gen_load_fpr_F(dc, a->rs1);
47687f10b52fSRichard Henderson     src2 = gen_load_fpr_F(dc, a->rs2);
47697f10b52fSRichard Henderson     func(src1, src1, src2);
47707f10b52fSRichard Henderson     gen_store_fpr_F(dc, a->rd, src1);
47717f10b52fSRichard Henderson     return advance_pc(dc);
47727f10b52fSRichard Henderson }
47737f10b52fSRichard Henderson 
47747f10b52fSRichard Henderson TRANS(FPADD16s, VIS1, do_fff, a, tcg_gen_vec_add16_i32)
47757f10b52fSRichard Henderson TRANS(FPADD32s, VIS1, do_fff, a, tcg_gen_add_i32)
47767f10b52fSRichard Henderson TRANS(FPSUB16s, VIS1, do_fff, a, tcg_gen_vec_sub16_i32)
47777f10b52fSRichard Henderson TRANS(FPSUB32s, VIS1, do_fff, a, tcg_gen_sub_i32)
47787f10b52fSRichard Henderson TRANS(FNORs, VIS1, do_fff, a, tcg_gen_nor_i32)
47797f10b52fSRichard Henderson TRANS(FANDNOTs, VIS1, do_fff, a, tcg_gen_andc_i32)
47807f10b52fSRichard Henderson TRANS(FXORs, VIS1, do_fff, a, tcg_gen_xor_i32)
47817f10b52fSRichard Henderson TRANS(FNANDs, VIS1, do_fff, a, tcg_gen_nand_i32)
47827f10b52fSRichard Henderson TRANS(FANDs, VIS1, do_fff, a, tcg_gen_and_i32)
47837f10b52fSRichard Henderson TRANS(FXNORs, VIS1, do_fff, a, tcg_gen_eqv_i32)
47847f10b52fSRichard Henderson TRANS(FORNOTs, VIS1, do_fff, a, tcg_gen_orc_i32)
47857f10b52fSRichard Henderson TRANS(FORs, VIS1, do_fff, a, tcg_gen_or_i32)
47867f10b52fSRichard Henderson 
47873d50b728SRichard Henderson TRANS(FHADDs, VIS3, do_fff, a, gen_op_fhadds)
47883d50b728SRichard Henderson TRANS(FHSUBs, VIS3, do_fff, a, gen_op_fhsubs)
47893d50b728SRichard Henderson TRANS(FNHADDs, VIS3, do_fff, a, gen_op_fnhadds)
47903d50b728SRichard Henderson 
4791c1514961SRichard Henderson static bool do_env_fff(DisasContext *dc, arg_r_r_r *a,
4792c1514961SRichard Henderson                        void (*func)(TCGv_i32, TCGv_env, TCGv_i32, TCGv_i32))
4793c1514961SRichard Henderson {
4794c1514961SRichard Henderson     TCGv_i32 src1, src2;
4795c1514961SRichard Henderson 
4796c1514961SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4797c1514961SRichard Henderson         return true;
4798c1514961SRichard Henderson     }
4799c1514961SRichard Henderson 
4800c1514961SRichard Henderson     src1 = gen_load_fpr_F(dc, a->rs1);
4801c1514961SRichard Henderson     src2 = gen_load_fpr_F(dc, a->rs2);
4802c1514961SRichard Henderson     func(src1, tcg_env, src1, src2);
4803c1514961SRichard Henderson     gen_store_fpr_F(dc, a->rd, src1);
4804c1514961SRichard Henderson     return advance_pc(dc);
4805c1514961SRichard Henderson }
4806c1514961SRichard Henderson 
4807c1514961SRichard Henderson TRANS(FADDs, ALL, do_env_fff, a, gen_helper_fadds)
4808c1514961SRichard Henderson TRANS(FSUBs, ALL, do_env_fff, a, gen_helper_fsubs)
4809c1514961SRichard Henderson TRANS(FMULs, ALL, do_env_fff, a, gen_helper_fmuls)
4810c1514961SRichard Henderson TRANS(FDIVs, ALL, do_env_fff, a, gen_helper_fdivs)
48113d50b728SRichard Henderson TRANS(FNADDs, VIS3, do_env_fff, a, gen_helper_fnadds)
48123d50b728SRichard Henderson TRANS(FNMULs, VIS3, do_env_fff, a, gen_helper_fnmuls)
4813c1514961SRichard Henderson 
4814a859602cSRichard Henderson static bool do_dff(DisasContext *dc, arg_r_r_r *a,
4815a859602cSRichard Henderson                    void (*func)(TCGv_i64, TCGv_i32, TCGv_i32))
4816a859602cSRichard Henderson {
4817a859602cSRichard Henderson     TCGv_i64 dst;
4818a859602cSRichard Henderson     TCGv_i32 src1, src2;
4819a859602cSRichard Henderson 
4820a859602cSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4821a859602cSRichard Henderson         return true;
4822a859602cSRichard Henderson     }
4823a859602cSRichard Henderson 
482452f46d46SRichard Henderson     dst = tcg_temp_new_i64();
4825a859602cSRichard Henderson     src1 = gen_load_fpr_F(dc, a->rs1);
4826a859602cSRichard Henderson     src2 = gen_load_fpr_F(dc, a->rs2);
4827a859602cSRichard Henderson     func(dst, src1, src2);
4828a859602cSRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
4829a859602cSRichard Henderson     return advance_pc(dc);
4830a859602cSRichard Henderson }
4831a859602cSRichard Henderson 
4832a859602cSRichard Henderson TRANS(FMUL8x16AU, VIS1, do_dff, a, gen_op_fmul8x16au)
4833a859602cSRichard Henderson TRANS(FMUL8x16AL, VIS1, do_dff, a, gen_op_fmul8x16al)
4834be8998e0SRichard Henderson TRANS(FMULD8SUx16, VIS1, do_dff, a, gen_op_fmuld8sux16)
4835be8998e0SRichard Henderson TRANS(FMULD8ULx16, VIS1, do_dff, a, gen_op_fmuld8ulx16)
4836d3ef26afSRichard Henderson TRANS(FPMERGE, VIS1, do_dff, a, gen_helper_fpmerge)
4837a859602cSRichard Henderson 
48389157dcccSRichard Henderson static bool do_dfd(DisasContext *dc, arg_r_r_r *a,
48399157dcccSRichard Henderson                    void (*func)(TCGv_i64, TCGv_i32, TCGv_i64))
48409157dcccSRichard Henderson {
48419157dcccSRichard Henderson     TCGv_i64 dst, src2;
48429157dcccSRichard Henderson     TCGv_i32 src1;
48439157dcccSRichard Henderson 
48449157dcccSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
48459157dcccSRichard Henderson         return true;
48469157dcccSRichard Henderson     }
48479157dcccSRichard Henderson 
484852f46d46SRichard Henderson     dst = tcg_temp_new_i64();
48499157dcccSRichard Henderson     src1 = gen_load_fpr_F(dc, a->rs1);
48509157dcccSRichard Henderson     src2 = gen_load_fpr_D(dc, a->rs2);
48519157dcccSRichard Henderson     func(dst, src1, src2);
48529157dcccSRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
48539157dcccSRichard Henderson     return advance_pc(dc);
48549157dcccSRichard Henderson }
48559157dcccSRichard Henderson 
48569157dcccSRichard Henderson TRANS(FMUL8x16, VIS1, do_dfd, a, gen_helper_fmul8x16)
48579157dcccSRichard Henderson 
485828c131a3SRichard Henderson static bool do_gvec_ddd(DisasContext *dc, arg_r_r_r *a, MemOp vece,
485928c131a3SRichard Henderson                         void (*func)(unsigned, uint32_t, uint32_t,
486028c131a3SRichard Henderson                                      uint32_t, uint32_t, uint32_t))
486128c131a3SRichard Henderson {
486228c131a3SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
486328c131a3SRichard Henderson         return true;
486428c131a3SRichard Henderson     }
486528c131a3SRichard Henderson 
486628c131a3SRichard Henderson     func(vece, gen_offset_fpr_D(a->rd), gen_offset_fpr_D(a->rs1),
486728c131a3SRichard Henderson          gen_offset_fpr_D(a->rs2), 8, 8);
486828c131a3SRichard Henderson     return advance_pc(dc);
486928c131a3SRichard Henderson }
487028c131a3SRichard Henderson 
487128c131a3SRichard Henderson TRANS(FPADD16, VIS1, do_gvec_ddd, a, MO_16, tcg_gen_gvec_add)
487228c131a3SRichard Henderson TRANS(FPADD32, VIS1, do_gvec_ddd, a, MO_32, tcg_gen_gvec_add)
487328c131a3SRichard Henderson TRANS(FPSUB16, VIS1, do_gvec_ddd, a, MO_16, tcg_gen_gvec_sub)
487428c131a3SRichard Henderson TRANS(FPSUB32, VIS1, do_gvec_ddd, a, MO_32, tcg_gen_gvec_sub)
48757837185eSRichard Henderson TRANS(FCHKSM16, VIS3, do_gvec_ddd, a, MO_16, gen_op_fchksm16)
4876*d6ff1ccbSRichard Henderson TRANS(FMEAN16, VIS3, do_gvec_ddd, a, MO_16, gen_op_fmean16)
487728c131a3SRichard Henderson 
4878e06c9f83SRichard Henderson static bool do_ddd(DisasContext *dc, arg_r_r_r *a,
4879e06c9f83SRichard Henderson                    void (*func)(TCGv_i64, TCGv_i64, TCGv_i64))
4880e06c9f83SRichard Henderson {
4881e06c9f83SRichard Henderson     TCGv_i64 dst, src1, src2;
4882e06c9f83SRichard Henderson 
4883e06c9f83SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4884e06c9f83SRichard Henderson         return true;
4885e06c9f83SRichard Henderson     }
4886e06c9f83SRichard Henderson 
488752f46d46SRichard Henderson     dst = tcg_temp_new_i64();
4888e06c9f83SRichard Henderson     src1 = gen_load_fpr_D(dc, a->rs1);
4889e06c9f83SRichard Henderson     src2 = gen_load_fpr_D(dc, a->rs2);
4890e06c9f83SRichard Henderson     func(dst, src1, src2);
4891e06c9f83SRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
4892e06c9f83SRichard Henderson     return advance_pc(dc);
4893e06c9f83SRichard Henderson }
4894e06c9f83SRichard Henderson 
4895e06c9f83SRichard Henderson TRANS(FMUL8SUx16, VIS1, do_ddd, a, gen_helper_fmul8sux16)
4896e06c9f83SRichard Henderson TRANS(FMUL8ULx16, VIS1, do_ddd, a, gen_helper_fmul8ulx16)
4897e06c9f83SRichard Henderson 
4898e06c9f83SRichard Henderson TRANS(FNORd, VIS1, do_ddd, a, tcg_gen_nor_i64)
4899e06c9f83SRichard Henderson TRANS(FANDNOTd, VIS1, do_ddd, a, tcg_gen_andc_i64)
4900e06c9f83SRichard Henderson TRANS(FXORd, VIS1, do_ddd, a, tcg_gen_xor_i64)
4901e06c9f83SRichard Henderson TRANS(FNANDd, VIS1, do_ddd, a, tcg_gen_nand_i64)
4902e06c9f83SRichard Henderson TRANS(FANDd, VIS1, do_ddd, a, tcg_gen_and_i64)
4903e06c9f83SRichard Henderson TRANS(FXNORd, VIS1, do_ddd, a, tcg_gen_eqv_i64)
4904e06c9f83SRichard Henderson TRANS(FORNOTd, VIS1, do_ddd, a, tcg_gen_orc_i64)
4905e06c9f83SRichard Henderson TRANS(FORd, VIS1, do_ddd, a, tcg_gen_or_i64)
4906e06c9f83SRichard Henderson 
49074b6edc0aSRichard Henderson TRANS(FPACK32, VIS1, do_ddd, a, gen_op_fpack32)
49084b6edc0aSRichard Henderson TRANS(FALIGNDATAg, VIS1, do_ddd, a, gen_op_faligndata)
49094b6edc0aSRichard Henderson TRANS(BSHUFFLE, VIS2, do_ddd, a, gen_op_bshuffle)
49104b6edc0aSRichard Henderson 
49113d50b728SRichard Henderson TRANS(FHADDd, VIS3, do_ddd, a, gen_op_fhaddd)
49123d50b728SRichard Henderson TRANS(FHSUBd, VIS3, do_ddd, a, gen_op_fhsubd)
49133d50b728SRichard Henderson TRANS(FNHADDd, VIS3, do_ddd, a, gen_op_fnhaddd)
49143d50b728SRichard Henderson 
4915e2fa6bd1SRichard Henderson static bool do_rdd(DisasContext *dc, arg_r_r_r *a,
4916e2fa6bd1SRichard Henderson                    void (*func)(TCGv, TCGv_i64, TCGv_i64))
4917e2fa6bd1SRichard Henderson {
4918e2fa6bd1SRichard Henderson     TCGv_i64 src1, src2;
4919e2fa6bd1SRichard Henderson     TCGv dst;
4920e2fa6bd1SRichard Henderson 
4921e2fa6bd1SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4922e2fa6bd1SRichard Henderson         return true;
4923e2fa6bd1SRichard Henderson     }
4924e2fa6bd1SRichard Henderson 
4925e2fa6bd1SRichard Henderson     dst = gen_dest_gpr(dc, a->rd);
4926e2fa6bd1SRichard Henderson     src1 = gen_load_fpr_D(dc, a->rs1);
4927e2fa6bd1SRichard Henderson     src2 = gen_load_fpr_D(dc, a->rs2);
4928e2fa6bd1SRichard Henderson     func(dst, src1, src2);
4929e2fa6bd1SRichard Henderson     gen_store_gpr(dc, a->rd, dst);
4930e2fa6bd1SRichard Henderson     return advance_pc(dc);
4931e2fa6bd1SRichard Henderson }
4932e2fa6bd1SRichard Henderson 
4933e2fa6bd1SRichard Henderson TRANS(FPCMPLE16, VIS1, do_rdd, a, gen_helper_fcmple16)
4934e2fa6bd1SRichard Henderson TRANS(FPCMPNE16, VIS1, do_rdd, a, gen_helper_fcmpne16)
4935e2fa6bd1SRichard Henderson TRANS(FPCMPGT16, VIS1, do_rdd, a, gen_helper_fcmpgt16)
4936e2fa6bd1SRichard Henderson TRANS(FPCMPEQ16, VIS1, do_rdd, a, gen_helper_fcmpeq16)
4937e2fa6bd1SRichard Henderson 
4938e2fa6bd1SRichard Henderson TRANS(FPCMPLE32, VIS1, do_rdd, a, gen_helper_fcmple32)
4939e2fa6bd1SRichard Henderson TRANS(FPCMPNE32, VIS1, do_rdd, a, gen_helper_fcmpne32)
4940e2fa6bd1SRichard Henderson TRANS(FPCMPGT32, VIS1, do_rdd, a, gen_helper_fcmpgt32)
4941e2fa6bd1SRichard Henderson TRANS(FPCMPEQ32, VIS1, do_rdd, a, gen_helper_fcmpeq32)
4942e2fa6bd1SRichard Henderson 
4943f2a59b0aSRichard Henderson static bool do_env_ddd(DisasContext *dc, arg_r_r_r *a,
4944f2a59b0aSRichard Henderson                        void (*func)(TCGv_i64, TCGv_env, TCGv_i64, TCGv_i64))
4945f2a59b0aSRichard Henderson {
4946f2a59b0aSRichard Henderson     TCGv_i64 dst, src1, src2;
4947f2a59b0aSRichard Henderson 
4948f2a59b0aSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4949f2a59b0aSRichard Henderson         return true;
4950f2a59b0aSRichard Henderson     }
4951f2a59b0aSRichard Henderson 
495252f46d46SRichard Henderson     dst = tcg_temp_new_i64();
4953f2a59b0aSRichard Henderson     src1 = gen_load_fpr_D(dc, a->rs1);
4954f2a59b0aSRichard Henderson     src2 = gen_load_fpr_D(dc, a->rs2);
4955f2a59b0aSRichard Henderson     func(dst, tcg_env, src1, src2);
4956f2a59b0aSRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
4957f2a59b0aSRichard Henderson     return advance_pc(dc);
4958f2a59b0aSRichard Henderson }
4959f2a59b0aSRichard Henderson 
4960f2a59b0aSRichard Henderson TRANS(FADDd, ALL, do_env_ddd, a, gen_helper_faddd)
4961f2a59b0aSRichard Henderson TRANS(FSUBd, ALL, do_env_ddd, a, gen_helper_fsubd)
4962f2a59b0aSRichard Henderson TRANS(FMULd, ALL, do_env_ddd, a, gen_helper_fmuld)
4963f2a59b0aSRichard Henderson TRANS(FDIVd, ALL, do_env_ddd, a, gen_helper_fdivd)
49643d50b728SRichard Henderson TRANS(FNADDd, VIS3, do_env_ddd, a, gen_helper_fnaddd)
49653d50b728SRichard Henderson TRANS(FNMULd, VIS3, do_env_ddd, a, gen_helper_fnmuld)
4966f2a59b0aSRichard Henderson 
4967ff4c711bSRichard Henderson static bool trans_FsMULd(DisasContext *dc, arg_r_r_r *a)
4968ff4c711bSRichard Henderson {
4969ff4c711bSRichard Henderson     TCGv_i64 dst;
4970ff4c711bSRichard Henderson     TCGv_i32 src1, src2;
4971ff4c711bSRichard Henderson 
4972ff4c711bSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4973ff4c711bSRichard Henderson         return true;
4974ff4c711bSRichard Henderson     }
4975ff4c711bSRichard Henderson     if (!(dc->def->features & CPU_FEATURE_FSMULD)) {
4976ff4c711bSRichard Henderson         return raise_unimpfpop(dc);
4977ff4c711bSRichard Henderson     }
4978ff4c711bSRichard Henderson 
497952f46d46SRichard Henderson     dst = tcg_temp_new_i64();
4980ff4c711bSRichard Henderson     src1 = gen_load_fpr_F(dc, a->rs1);
4981ff4c711bSRichard Henderson     src2 = gen_load_fpr_F(dc, a->rs2);
4982ff4c711bSRichard Henderson     gen_helper_fsmuld(dst, tcg_env, src1, src2);
4983ff4c711bSRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
4984ff4c711bSRichard Henderson     return advance_pc(dc);
4985ff4c711bSRichard Henderson }
4986ff4c711bSRichard Henderson 
49873d50b728SRichard Henderson static bool trans_FNsMULd(DisasContext *dc, arg_r_r_r *a)
49883d50b728SRichard Henderson {
49893d50b728SRichard Henderson     TCGv_i64 dst;
49903d50b728SRichard Henderson     TCGv_i32 src1, src2;
49913d50b728SRichard Henderson 
49923d50b728SRichard Henderson     if (!avail_VIS3(dc)) {
49933d50b728SRichard Henderson         return false;
49943d50b728SRichard Henderson     }
49953d50b728SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
49963d50b728SRichard Henderson         return true;
49973d50b728SRichard Henderson     }
49983d50b728SRichard Henderson     dst = tcg_temp_new_i64();
49993d50b728SRichard Henderson     src1 = gen_load_fpr_F(dc, a->rs1);
50003d50b728SRichard Henderson     src2 = gen_load_fpr_F(dc, a->rs2);
50013d50b728SRichard Henderson     gen_helper_fnsmuld(dst, tcg_env, src1, src2);
50023d50b728SRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
50033d50b728SRichard Henderson     return advance_pc(dc);
50043d50b728SRichard Henderson }
50053d50b728SRichard Henderson 
50064fd71d19SRichard Henderson static bool do_ffff(DisasContext *dc, arg_r_r_r_r *a,
50074fd71d19SRichard Henderson                     void (*func)(TCGv_i32, TCGv_i32, TCGv_i32, TCGv_i32))
50084fd71d19SRichard Henderson {
50094fd71d19SRichard Henderson     TCGv_i32 dst, src1, src2, src3;
50104fd71d19SRichard Henderson 
50114fd71d19SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
50124fd71d19SRichard Henderson         return true;
50134fd71d19SRichard Henderson     }
50144fd71d19SRichard Henderson 
50154fd71d19SRichard Henderson     src1 = gen_load_fpr_F(dc, a->rs1);
50164fd71d19SRichard Henderson     src2 = gen_load_fpr_F(dc, a->rs2);
50174fd71d19SRichard Henderson     src3 = gen_load_fpr_F(dc, a->rs3);
50184fd71d19SRichard Henderson     dst = tcg_temp_new_i32();
50194fd71d19SRichard Henderson     func(dst, src1, src2, src3);
50204fd71d19SRichard Henderson     gen_store_fpr_F(dc, a->rd, dst);
50214fd71d19SRichard Henderson     return advance_pc(dc);
50224fd71d19SRichard Henderson }
50234fd71d19SRichard Henderson 
50244fd71d19SRichard Henderson TRANS(FMADDs, FMAF, do_ffff, a, gen_op_fmadds)
50254fd71d19SRichard Henderson TRANS(FMSUBs, FMAF, do_ffff, a, gen_op_fmsubs)
50264fd71d19SRichard Henderson TRANS(FNMSUBs, FMAF, do_ffff, a, gen_op_fnmsubs)
50274fd71d19SRichard Henderson TRANS(FNMADDs, FMAF, do_ffff, a, gen_op_fnmadds)
50284fd71d19SRichard Henderson 
50294fd71d19SRichard Henderson static bool do_dddd(DisasContext *dc, arg_r_r_r_r *a,
5030afb04344SRichard Henderson                     void (*func)(TCGv_i64, TCGv_i64, TCGv_i64, TCGv_i64))
5031afb04344SRichard Henderson {
50324fd71d19SRichard Henderson     TCGv_i64 dst, src1, src2, src3;
5033afb04344SRichard Henderson 
5034afb04344SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
5035afb04344SRichard Henderson         return true;
5036afb04344SRichard Henderson     }
5037afb04344SRichard Henderson 
503852f46d46SRichard Henderson     dst  = tcg_temp_new_i64();
5039afb04344SRichard Henderson     src1 = gen_load_fpr_D(dc, a->rs1);
5040afb04344SRichard Henderson     src2 = gen_load_fpr_D(dc, a->rs2);
50414fd71d19SRichard Henderson     src3 = gen_load_fpr_D(dc, a->rs3);
50424fd71d19SRichard Henderson     func(dst, src1, src2, src3);
5043afb04344SRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
5044afb04344SRichard Henderson     return advance_pc(dc);
5045afb04344SRichard Henderson }
5046afb04344SRichard Henderson 
5047afb04344SRichard Henderson TRANS(PDIST, VIS1, do_dddd, a, gen_helper_pdist)
50484fd71d19SRichard Henderson TRANS(FMADDd, FMAF, do_dddd, a, gen_op_fmaddd)
50494fd71d19SRichard Henderson TRANS(FMSUBd, FMAF, do_dddd, a, gen_op_fmsubd)
50504fd71d19SRichard Henderson TRANS(FNMSUBd, FMAF, do_dddd, a, gen_op_fnmsubd)
50514fd71d19SRichard Henderson TRANS(FNMADDd, FMAF, do_dddd, a, gen_op_fnmaddd)
5052afb04344SRichard Henderson 
5053a4056239SRichard Henderson static bool do_env_qqq(DisasContext *dc, arg_r_r_r *a,
505416bedf89SRichard Henderson                        void (*func)(TCGv_i128, TCGv_env, TCGv_i128, TCGv_i128))
5055a4056239SRichard Henderson {
505616bedf89SRichard Henderson     TCGv_i128 src1, src2;
505716bedf89SRichard Henderson 
5058a4056239SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
5059a4056239SRichard Henderson         return true;
5060a4056239SRichard Henderson     }
5061a4056239SRichard Henderson     if (gen_trap_float128(dc)) {
5062a4056239SRichard Henderson         return true;
5063a4056239SRichard Henderson     }
5064a4056239SRichard Henderson 
506516bedf89SRichard Henderson     src1 = gen_load_fpr_Q(dc, a->rs1);
506616bedf89SRichard Henderson     src2 = gen_load_fpr_Q(dc, a->rs2);
506716bedf89SRichard Henderson     func(src1, tcg_env, src1, src2);
506816bedf89SRichard Henderson     gen_store_fpr_Q(dc, a->rd, src1);
5069a4056239SRichard Henderson     return advance_pc(dc);
5070a4056239SRichard Henderson }
5071a4056239SRichard Henderson 
5072a4056239SRichard Henderson TRANS(FADDq, ALL, do_env_qqq, a, gen_helper_faddq)
5073a4056239SRichard Henderson TRANS(FSUBq, ALL, do_env_qqq, a, gen_helper_fsubq)
5074a4056239SRichard Henderson TRANS(FMULq, ALL, do_env_qqq, a, gen_helper_fmulq)
5075a4056239SRichard Henderson TRANS(FDIVq, ALL, do_env_qqq, a, gen_helper_fdivq)
5076a4056239SRichard Henderson 
50775e3b17bbSRichard Henderson static bool trans_FdMULq(DisasContext *dc, arg_r_r_r *a)
50785e3b17bbSRichard Henderson {
50795e3b17bbSRichard Henderson     TCGv_i64 src1, src2;
5080ba21dc99SRichard Henderson     TCGv_i128 dst;
50815e3b17bbSRichard Henderson 
50825e3b17bbSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
50835e3b17bbSRichard Henderson         return true;
50845e3b17bbSRichard Henderson     }
50855e3b17bbSRichard Henderson     if (gen_trap_float128(dc)) {
50865e3b17bbSRichard Henderson         return true;
50875e3b17bbSRichard Henderson     }
50885e3b17bbSRichard Henderson 
50895e3b17bbSRichard Henderson     src1 = gen_load_fpr_D(dc, a->rs1);
50905e3b17bbSRichard Henderson     src2 = gen_load_fpr_D(dc, a->rs2);
5091ba21dc99SRichard Henderson     dst = tcg_temp_new_i128();
5092ba21dc99SRichard Henderson     gen_helper_fdmulq(dst, tcg_env, src1, src2);
5093ba21dc99SRichard Henderson     gen_store_fpr_Q(dc, a->rd, dst);
50945e3b17bbSRichard Henderson     return advance_pc(dc);
50955e3b17bbSRichard Henderson }
50965e3b17bbSRichard Henderson 
5097f7ec8155SRichard Henderson static bool do_fmovr(DisasContext *dc, arg_FMOVRs *a, bool is_128,
5098f7ec8155SRichard Henderson                      void (*func)(DisasContext *, DisasCompare *, int, int))
5099f7ec8155SRichard Henderson {
5100f7ec8155SRichard Henderson     DisasCompare cmp;
5101f7ec8155SRichard Henderson 
51022c4f56c9SRichard Henderson     if (!gen_compare_reg(&cmp, a->cond, gen_load_gpr(dc, a->rs1))) {
51032c4f56c9SRichard Henderson         return false;
51042c4f56c9SRichard Henderson     }
5105f7ec8155SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
5106f7ec8155SRichard Henderson         return true;
5107f7ec8155SRichard Henderson     }
5108f7ec8155SRichard Henderson     if (is_128 && gen_trap_float128(dc)) {
5109f7ec8155SRichard Henderson         return true;
5110f7ec8155SRichard Henderson     }
5111f7ec8155SRichard Henderson 
5112f7ec8155SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
5113f7ec8155SRichard Henderson     func(dc, &cmp, a->rd, a->rs2);
5114f7ec8155SRichard Henderson     return advance_pc(dc);
5115f7ec8155SRichard Henderson }
5116f7ec8155SRichard Henderson 
5117f7ec8155SRichard Henderson TRANS(FMOVRs, 64, do_fmovr, a, false, gen_fmovs)
5118f7ec8155SRichard Henderson TRANS(FMOVRd, 64, do_fmovr, a, false, gen_fmovd)
5119f7ec8155SRichard Henderson TRANS(FMOVRq, 64, do_fmovr, a, true, gen_fmovq)
5120f7ec8155SRichard Henderson 
5121f7ec8155SRichard Henderson static bool do_fmovcc(DisasContext *dc, arg_FMOVscc *a, bool is_128,
5122f7ec8155SRichard Henderson                       void (*func)(DisasContext *, DisasCompare *, int, int))
5123f7ec8155SRichard Henderson {
5124f7ec8155SRichard Henderson     DisasCompare cmp;
5125f7ec8155SRichard Henderson 
5126f7ec8155SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
5127f7ec8155SRichard Henderson         return true;
5128f7ec8155SRichard Henderson     }
5129f7ec8155SRichard Henderson     if (is_128 && gen_trap_float128(dc)) {
5130f7ec8155SRichard Henderson         return true;
5131f7ec8155SRichard Henderson     }
5132f7ec8155SRichard Henderson 
5133f7ec8155SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
5134f7ec8155SRichard Henderson     gen_compare(&cmp, a->cc, a->cond, dc);
5135f7ec8155SRichard Henderson     func(dc, &cmp, a->rd, a->rs2);
5136f7ec8155SRichard Henderson     return advance_pc(dc);
5137f7ec8155SRichard Henderson }
5138f7ec8155SRichard Henderson 
5139f7ec8155SRichard Henderson TRANS(FMOVscc, 64, do_fmovcc, a, false, gen_fmovs)
5140f7ec8155SRichard Henderson TRANS(FMOVdcc, 64, do_fmovcc, a, false, gen_fmovd)
5141f7ec8155SRichard Henderson TRANS(FMOVqcc, 64, do_fmovcc, a, true, gen_fmovq)
5142f7ec8155SRichard Henderson 
5143f7ec8155SRichard Henderson static bool do_fmovfcc(DisasContext *dc, arg_FMOVsfcc *a, bool is_128,
5144f7ec8155SRichard Henderson                        void (*func)(DisasContext *, DisasCompare *, int, int))
5145f7ec8155SRichard Henderson {
5146f7ec8155SRichard Henderson     DisasCompare cmp;
5147f7ec8155SRichard Henderson 
5148f7ec8155SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
5149f7ec8155SRichard Henderson         return true;
5150f7ec8155SRichard Henderson     }
5151f7ec8155SRichard Henderson     if (is_128 && gen_trap_float128(dc)) {
5152f7ec8155SRichard Henderson         return true;
5153f7ec8155SRichard Henderson     }
5154f7ec8155SRichard Henderson 
5155f7ec8155SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
5156f7ec8155SRichard Henderson     gen_fcompare(&cmp, a->cc, a->cond);
5157f7ec8155SRichard Henderson     func(dc, &cmp, a->rd, a->rs2);
5158f7ec8155SRichard Henderson     return advance_pc(dc);
5159f7ec8155SRichard Henderson }
5160f7ec8155SRichard Henderson 
5161f7ec8155SRichard Henderson TRANS(FMOVsfcc, 64, do_fmovfcc, a, false, gen_fmovs)
5162f7ec8155SRichard Henderson TRANS(FMOVdfcc, 64, do_fmovfcc, a, false, gen_fmovd)
5163f7ec8155SRichard Henderson TRANS(FMOVqfcc, 64, do_fmovfcc, a, true, gen_fmovq)
5164f7ec8155SRichard Henderson 
516540f9ad21SRichard Henderson static bool do_fcmps(DisasContext *dc, arg_FCMPs *a, bool e)
516640f9ad21SRichard Henderson {
516740f9ad21SRichard Henderson     TCGv_i32 src1, src2;
516840f9ad21SRichard Henderson 
516940f9ad21SRichard Henderson     if (avail_32(dc) && a->cc != 0) {
517040f9ad21SRichard Henderson         return false;
517140f9ad21SRichard Henderson     }
517240f9ad21SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
517340f9ad21SRichard Henderson         return true;
517440f9ad21SRichard Henderson     }
517540f9ad21SRichard Henderson 
517640f9ad21SRichard Henderson     src1 = gen_load_fpr_F(dc, a->rs1);
517740f9ad21SRichard Henderson     src2 = gen_load_fpr_F(dc, a->rs2);
517840f9ad21SRichard Henderson     if (e) {
5179d8c5b92fSRichard Henderson         gen_helper_fcmpes(cpu_fcc[a->cc], tcg_env, src1, src2);
518040f9ad21SRichard Henderson     } else {
5181d8c5b92fSRichard Henderson         gen_helper_fcmps(cpu_fcc[a->cc], tcg_env, src1, src2);
518240f9ad21SRichard Henderson     }
518340f9ad21SRichard Henderson     return advance_pc(dc);
518440f9ad21SRichard Henderson }
518540f9ad21SRichard Henderson 
518640f9ad21SRichard Henderson TRANS(FCMPs, ALL, do_fcmps, a, false)
518740f9ad21SRichard Henderson TRANS(FCMPEs, ALL, do_fcmps, a, true)
518840f9ad21SRichard Henderson 
518940f9ad21SRichard Henderson static bool do_fcmpd(DisasContext *dc, arg_FCMPd *a, bool e)
519040f9ad21SRichard Henderson {
519140f9ad21SRichard Henderson     TCGv_i64 src1, src2;
519240f9ad21SRichard Henderson 
519340f9ad21SRichard Henderson     if (avail_32(dc) && a->cc != 0) {
519440f9ad21SRichard Henderson         return false;
519540f9ad21SRichard Henderson     }
519640f9ad21SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
519740f9ad21SRichard Henderson         return true;
519840f9ad21SRichard Henderson     }
519940f9ad21SRichard Henderson 
520040f9ad21SRichard Henderson     src1 = gen_load_fpr_D(dc, a->rs1);
520140f9ad21SRichard Henderson     src2 = gen_load_fpr_D(dc, a->rs2);
520240f9ad21SRichard Henderson     if (e) {
5203d8c5b92fSRichard Henderson         gen_helper_fcmped(cpu_fcc[a->cc], tcg_env, src1, src2);
520440f9ad21SRichard Henderson     } else {
5205d8c5b92fSRichard Henderson         gen_helper_fcmpd(cpu_fcc[a->cc], tcg_env, src1, src2);
520640f9ad21SRichard Henderson     }
520740f9ad21SRichard Henderson     return advance_pc(dc);
520840f9ad21SRichard Henderson }
520940f9ad21SRichard Henderson 
521040f9ad21SRichard Henderson TRANS(FCMPd, ALL, do_fcmpd, a, false)
521140f9ad21SRichard Henderson TRANS(FCMPEd, ALL, do_fcmpd, a, true)
521240f9ad21SRichard Henderson 
521340f9ad21SRichard Henderson static bool do_fcmpq(DisasContext *dc, arg_FCMPq *a, bool e)
521440f9ad21SRichard Henderson {
5215f3ceafadSRichard Henderson     TCGv_i128 src1, src2;
5216f3ceafadSRichard Henderson 
521740f9ad21SRichard Henderson     if (avail_32(dc) && a->cc != 0) {
521840f9ad21SRichard Henderson         return false;
521940f9ad21SRichard Henderson     }
522040f9ad21SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
522140f9ad21SRichard Henderson         return true;
522240f9ad21SRichard Henderson     }
522340f9ad21SRichard Henderson     if (gen_trap_float128(dc)) {
522440f9ad21SRichard Henderson         return true;
522540f9ad21SRichard Henderson     }
522640f9ad21SRichard Henderson 
5227f3ceafadSRichard Henderson     src1 = gen_load_fpr_Q(dc, a->rs1);
5228f3ceafadSRichard Henderson     src2 = gen_load_fpr_Q(dc, a->rs2);
522940f9ad21SRichard Henderson     if (e) {
5230d8c5b92fSRichard Henderson         gen_helper_fcmpeq(cpu_fcc[a->cc], tcg_env, src1, src2);
523140f9ad21SRichard Henderson     } else {
5232d8c5b92fSRichard Henderson         gen_helper_fcmpq(cpu_fcc[a->cc], tcg_env, src1, src2);
523340f9ad21SRichard Henderson     }
523440f9ad21SRichard Henderson     return advance_pc(dc);
523540f9ad21SRichard Henderson }
523640f9ad21SRichard Henderson 
523740f9ad21SRichard Henderson TRANS(FCMPq, ALL, do_fcmpq, a, false)
523840f9ad21SRichard Henderson TRANS(FCMPEq, ALL, do_fcmpq, a, true)
523940f9ad21SRichard Henderson 
52401d3ed3d7SRichard Henderson static bool trans_FLCMPs(DisasContext *dc, arg_FLCMPs *a)
52411d3ed3d7SRichard Henderson {
52421d3ed3d7SRichard Henderson     TCGv_i32 src1, src2;
52431d3ed3d7SRichard Henderson 
52441d3ed3d7SRichard Henderson     if (!avail_VIS3(dc)) {
52451d3ed3d7SRichard Henderson         return false;
52461d3ed3d7SRichard Henderson     }
52471d3ed3d7SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
52481d3ed3d7SRichard Henderson         return true;
52491d3ed3d7SRichard Henderson     }
52501d3ed3d7SRichard Henderson 
52511d3ed3d7SRichard Henderson     src1 = gen_load_fpr_F(dc, a->rs1);
52521d3ed3d7SRichard Henderson     src2 = gen_load_fpr_F(dc, a->rs2);
52531d3ed3d7SRichard Henderson     gen_helper_flcmps(cpu_fcc[a->cc], src1, src2);
52541d3ed3d7SRichard Henderson     return advance_pc(dc);
52551d3ed3d7SRichard Henderson }
52561d3ed3d7SRichard Henderson 
52571d3ed3d7SRichard Henderson static bool trans_FLCMPd(DisasContext *dc, arg_FLCMPd *a)
52581d3ed3d7SRichard Henderson {
52591d3ed3d7SRichard Henderson     TCGv_i64 src1, src2;
52601d3ed3d7SRichard Henderson 
52611d3ed3d7SRichard Henderson     if (!avail_VIS3(dc)) {
52621d3ed3d7SRichard Henderson         return false;
52631d3ed3d7SRichard Henderson     }
52641d3ed3d7SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
52651d3ed3d7SRichard Henderson         return true;
52661d3ed3d7SRichard Henderson     }
52671d3ed3d7SRichard Henderson 
52681d3ed3d7SRichard Henderson     src1 = gen_load_fpr_D(dc, a->rs1);
52691d3ed3d7SRichard Henderson     src2 = gen_load_fpr_D(dc, a->rs2);
52701d3ed3d7SRichard Henderson     gen_helper_flcmpd(cpu_fcc[a->cc], src1, src2);
52711d3ed3d7SRichard Henderson     return advance_pc(dc);
52721d3ed3d7SRichard Henderson }
52731d3ed3d7SRichard Henderson 
52746e61bc94SEmilio G. Cota static void sparc_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
5275fcf5ef2aSThomas Huth {
52766e61bc94SEmilio G. Cota     DisasContext *dc = container_of(dcbase, DisasContext, base);
52776e61bc94SEmilio G. Cota     int bound;
5278af00be49SEmilio G. Cota 
5279af00be49SEmilio G. Cota     dc->pc = dc->base.pc_first;
52806e61bc94SEmilio G. Cota     dc->npc = (target_ulong)dc->base.tb->cs_base;
52816e61bc94SEmilio G. Cota     dc->mem_idx = dc->base.tb->flags & TB_FLAG_MMU_MASK;
528277976769SPhilippe Mathieu-Daudé     dc->def = &cpu_env(cs)->def;
52836e61bc94SEmilio G. Cota     dc->fpu_enabled = tb_fpu_enabled(dc->base.tb->flags);
52846e61bc94SEmilio G. Cota     dc->address_mask_32bit = tb_am_enabled(dc->base.tb->flags);
5285c9b459aaSArtyom Tarasenko #ifndef CONFIG_USER_ONLY
52866e61bc94SEmilio G. Cota     dc->supervisor = (dc->base.tb->flags & TB_FLAG_SUPER) != 0;
5287c9b459aaSArtyom Tarasenko #endif
5288fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
5289fcf5ef2aSThomas Huth     dc->fprs_dirty = 0;
52906e61bc94SEmilio G. Cota     dc->asi = (dc->base.tb->flags >> TB_FLAG_ASI_SHIFT) & 0xff;
5291c9b459aaSArtyom Tarasenko #ifndef CONFIG_USER_ONLY
52926e61bc94SEmilio G. Cota     dc->hypervisor = (dc->base.tb->flags & TB_FLAG_HYPER) != 0;
5293c9b459aaSArtyom Tarasenko #endif
5294fcf5ef2aSThomas Huth #endif
52956e61bc94SEmilio G. Cota     /*
52966e61bc94SEmilio G. Cota      * if we reach a page boundary, we stop generation so that the
52976e61bc94SEmilio G. Cota      * PC of a TT_TFAULT exception is always in the right page
52986e61bc94SEmilio G. Cota      */
52996e61bc94SEmilio G. Cota     bound = -(dc->base.pc_first | TARGET_PAGE_MASK) / 4;
53006e61bc94SEmilio G. Cota     dc->base.max_insns = MIN(dc->base.max_insns, bound);
5301af00be49SEmilio G. Cota }
5302fcf5ef2aSThomas Huth 
53036e61bc94SEmilio G. Cota static void sparc_tr_tb_start(DisasContextBase *db, CPUState *cs)
53046e61bc94SEmilio G. Cota {
53056e61bc94SEmilio G. Cota }
53066e61bc94SEmilio G. Cota 
53076e61bc94SEmilio G. Cota static void sparc_tr_insn_start(DisasContextBase *dcbase, CPUState *cs)
53086e61bc94SEmilio G. Cota {
53096e61bc94SEmilio G. Cota     DisasContext *dc = container_of(dcbase, DisasContext, base);
5310633c4283SRichard Henderson     target_ulong npc = dc->npc;
53116e61bc94SEmilio G. Cota 
5312633c4283SRichard Henderson     if (npc & 3) {
5313633c4283SRichard Henderson         switch (npc) {
5314633c4283SRichard Henderson         case JUMP_PC:
5315fcf5ef2aSThomas Huth             assert(dc->jump_pc[1] == dc->pc + 4);
5316633c4283SRichard Henderson             npc = dc->jump_pc[0] | JUMP_PC;
5317633c4283SRichard Henderson             break;
5318633c4283SRichard Henderson         case DYNAMIC_PC:
5319633c4283SRichard Henderson         case DYNAMIC_PC_LOOKUP:
5320633c4283SRichard Henderson             npc = DYNAMIC_PC;
5321633c4283SRichard Henderson             break;
5322633c4283SRichard Henderson         default:
5323633c4283SRichard Henderson             g_assert_not_reached();
5324fcf5ef2aSThomas Huth         }
53256e61bc94SEmilio G. Cota     }
5326633c4283SRichard Henderson     tcg_gen_insn_start(dc->pc, npc);
5327633c4283SRichard Henderson }
5328fcf5ef2aSThomas Huth 
53296e61bc94SEmilio G. Cota static void sparc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs)
53306e61bc94SEmilio G. Cota {
53316e61bc94SEmilio G. Cota     DisasContext *dc = container_of(dcbase, DisasContext, base);
53326e61bc94SEmilio G. Cota     unsigned int insn;
5333fcf5ef2aSThomas Huth 
533477976769SPhilippe Mathieu-Daudé     insn = translator_ldl(cpu_env(cs), &dc->base, dc->pc);
5335af00be49SEmilio G. Cota     dc->base.pc_next += 4;
5336878cc677SRichard Henderson 
5337878cc677SRichard Henderson     if (!decode(dc, insn)) {
5338ba9c09b4SRichard Henderson         gen_exception(dc, TT_ILL_INSN);
5339878cc677SRichard Henderson     }
5340fcf5ef2aSThomas Huth 
5341af00be49SEmilio G. Cota     if (dc->base.is_jmp == DISAS_NORETURN) {
53426e61bc94SEmilio G. Cota         return;
5343c5e6ccdfSEmilio G. Cota     }
5344af00be49SEmilio G. Cota     if (dc->pc != dc->base.pc_next) {
53456e61bc94SEmilio G. Cota         dc->base.is_jmp = DISAS_TOO_MANY;
5346af00be49SEmilio G. Cota     }
53476e61bc94SEmilio G. Cota }
5348fcf5ef2aSThomas Huth 
53496e61bc94SEmilio G. Cota static void sparc_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)
53506e61bc94SEmilio G. Cota {
53516e61bc94SEmilio G. Cota     DisasContext *dc = container_of(dcbase, DisasContext, base);
5352186e7890SRichard Henderson     DisasDelayException *e, *e_next;
5353633c4283SRichard Henderson     bool may_lookup;
53546e61bc94SEmilio G. Cota 
535589527e3aSRichard Henderson     finishing_insn(dc);
535689527e3aSRichard Henderson 
535746bb0137SMark Cave-Ayland     switch (dc->base.is_jmp) {
535846bb0137SMark Cave-Ayland     case DISAS_NEXT:
535946bb0137SMark Cave-Ayland     case DISAS_TOO_MANY:
5360633c4283SRichard Henderson         if (((dc->pc | dc->npc) & 3) == 0) {
5361fcf5ef2aSThomas Huth             /* static PC and NPC: we can use direct chaining */
5362fcf5ef2aSThomas Huth             gen_goto_tb(dc, 0, dc->pc, dc->npc);
5363633c4283SRichard Henderson             break;
5364fcf5ef2aSThomas Huth         }
5365633c4283SRichard Henderson 
5366930f1865SRichard Henderson         may_lookup = true;
5367633c4283SRichard Henderson         if (dc->pc & 3) {
5368633c4283SRichard Henderson             switch (dc->pc) {
5369633c4283SRichard Henderson             case DYNAMIC_PC_LOOKUP:
5370633c4283SRichard Henderson                 break;
5371633c4283SRichard Henderson             case DYNAMIC_PC:
5372633c4283SRichard Henderson                 may_lookup = false;
5373633c4283SRichard Henderson                 break;
5374633c4283SRichard Henderson             default:
5375633c4283SRichard Henderson                 g_assert_not_reached();
5376633c4283SRichard Henderson             }
5377633c4283SRichard Henderson         } else {
5378633c4283SRichard Henderson             tcg_gen_movi_tl(cpu_pc, dc->pc);
5379633c4283SRichard Henderson         }
5380633c4283SRichard Henderson 
5381930f1865SRichard Henderson         if (dc->npc & 3) {
5382930f1865SRichard Henderson             switch (dc->npc) {
5383930f1865SRichard Henderson             case JUMP_PC:
5384930f1865SRichard Henderson                 gen_generic_branch(dc);
5385930f1865SRichard Henderson                 break;
5386930f1865SRichard Henderson             case DYNAMIC_PC:
5387930f1865SRichard Henderson                 may_lookup = false;
5388930f1865SRichard Henderson                 break;
5389930f1865SRichard Henderson             case DYNAMIC_PC_LOOKUP:
5390930f1865SRichard Henderson                 break;
5391930f1865SRichard Henderson             default:
5392930f1865SRichard Henderson                 g_assert_not_reached();
5393930f1865SRichard Henderson             }
5394930f1865SRichard Henderson         } else {
5395930f1865SRichard Henderson             tcg_gen_movi_tl(cpu_npc, dc->npc);
5396930f1865SRichard Henderson         }
5397633c4283SRichard Henderson         if (may_lookup) {
5398633c4283SRichard Henderson             tcg_gen_lookup_and_goto_ptr();
5399633c4283SRichard Henderson         } else {
540007ea28b4SRichard Henderson             tcg_gen_exit_tb(NULL, 0);
5401fcf5ef2aSThomas Huth         }
540246bb0137SMark Cave-Ayland         break;
540346bb0137SMark Cave-Ayland 
540446bb0137SMark Cave-Ayland     case DISAS_NORETURN:
540546bb0137SMark Cave-Ayland        break;
540646bb0137SMark Cave-Ayland 
540746bb0137SMark Cave-Ayland     case DISAS_EXIT:
540846bb0137SMark Cave-Ayland         /* Exit TB */
540946bb0137SMark Cave-Ayland         save_state(dc);
541046bb0137SMark Cave-Ayland         tcg_gen_exit_tb(NULL, 0);
541146bb0137SMark Cave-Ayland         break;
541246bb0137SMark Cave-Ayland 
541346bb0137SMark Cave-Ayland     default:
541446bb0137SMark Cave-Ayland         g_assert_not_reached();
5415fcf5ef2aSThomas Huth     }
5416186e7890SRichard Henderson 
5417186e7890SRichard Henderson     for (e = dc->delay_excp_list; e ; e = e_next) {
5418186e7890SRichard Henderson         gen_set_label(e->lab);
5419186e7890SRichard Henderson 
5420186e7890SRichard Henderson         tcg_gen_movi_tl(cpu_pc, e->pc);
5421186e7890SRichard Henderson         if (e->npc % 4 == 0) {
5422186e7890SRichard Henderson             tcg_gen_movi_tl(cpu_npc, e->npc);
5423186e7890SRichard Henderson         }
5424186e7890SRichard Henderson         gen_helper_raise_exception(tcg_env, e->excp);
5425186e7890SRichard Henderson 
5426186e7890SRichard Henderson         e_next = e->next;
5427186e7890SRichard Henderson         g_free(e);
5428186e7890SRichard Henderson     }
5429fcf5ef2aSThomas Huth }
54306e61bc94SEmilio G. Cota 
54316e61bc94SEmilio G. Cota static const TranslatorOps sparc_tr_ops = {
54326e61bc94SEmilio G. Cota     .init_disas_context = sparc_tr_init_disas_context,
54336e61bc94SEmilio G. Cota     .tb_start           = sparc_tr_tb_start,
54346e61bc94SEmilio G. Cota     .insn_start         = sparc_tr_insn_start,
54356e61bc94SEmilio G. Cota     .translate_insn     = sparc_tr_translate_insn,
54366e61bc94SEmilio G. Cota     .tb_stop            = sparc_tr_tb_stop,
54376e61bc94SEmilio G. Cota };
54386e61bc94SEmilio G. Cota 
5439597f9b2dSRichard Henderson void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int *max_insns,
544032f0c394SAnton Johansson                            vaddr pc, void *host_pc)
54416e61bc94SEmilio G. Cota {
54426e61bc94SEmilio G. Cota     DisasContext dc = {};
54436e61bc94SEmilio G. Cota 
5444306c8721SRichard Henderson     translator_loop(cs, tb, max_insns, pc, host_pc, &sparc_tr_ops, &dc.base);
5445fcf5ef2aSThomas Huth }
5446fcf5ef2aSThomas Huth 
544755c3ceefSRichard Henderson void sparc_tcg_init(void)
5448fcf5ef2aSThomas Huth {
5449fcf5ef2aSThomas Huth     static const char gregnames[32][4] = {
5450fcf5ef2aSThomas Huth         "g0", "g1", "g2", "g3", "g4", "g5", "g6", "g7",
5451fcf5ef2aSThomas Huth         "o0", "o1", "o2", "o3", "o4", "o5", "o6", "o7",
5452fcf5ef2aSThomas Huth         "l0", "l1", "l2", "l3", "l4", "l5", "l6", "l7",
5453fcf5ef2aSThomas Huth         "i0", "i1", "i2", "i3", "i4", "i5", "i6", "i7",
5454fcf5ef2aSThomas Huth     };
5455fcf5ef2aSThomas Huth 
5456d8c5b92fSRichard Henderson     static const struct { TCGv_i32 *ptr; int off; const char *name; } r32[] = {
5457d8c5b92fSRichard Henderson #ifdef TARGET_SPARC64
5458d8c5b92fSRichard Henderson         { &cpu_fprs, offsetof(CPUSPARCState, fprs), "fprs" },
5459d8c5b92fSRichard Henderson         { &cpu_fcc[0], offsetof(CPUSPARCState, fcc[0]), "fcc0" },
5460d8c5b92fSRichard Henderson         { &cpu_fcc[1], offsetof(CPUSPARCState, fcc[1]), "fcc1" },
5461d8c5b92fSRichard Henderson         { &cpu_fcc[2], offsetof(CPUSPARCState, fcc[2]), "fcc2" },
5462d8c5b92fSRichard Henderson         { &cpu_fcc[3], offsetof(CPUSPARCState, fcc[3]), "fcc3" },
5463d8c5b92fSRichard Henderson #else
5464d8c5b92fSRichard Henderson         { &cpu_fcc[0], offsetof(CPUSPARCState, fcc[0]), "fcc" },
5465d8c5b92fSRichard Henderson #endif
5466d8c5b92fSRichard Henderson     };
5467d8c5b92fSRichard Henderson 
5468fcf5ef2aSThomas Huth     static const struct { TCGv *ptr; int off; const char *name; } rtl[] = {
5469fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
5470fcf5ef2aSThomas Huth         { &cpu_gsr, offsetof(CPUSPARCState, gsr), "gsr" },
54712a1905c7SRichard Henderson         { &cpu_xcc_Z, offsetof(CPUSPARCState, xcc_Z), "xcc_Z" },
54722a1905c7SRichard Henderson         { &cpu_xcc_C, offsetof(CPUSPARCState, xcc_C), "xcc_C" },
5473fcf5ef2aSThomas Huth #endif
54742a1905c7SRichard Henderson         { &cpu_cc_N, offsetof(CPUSPARCState, cc_N), "cc_N" },
54752a1905c7SRichard Henderson         { &cpu_cc_V, offsetof(CPUSPARCState, cc_V), "cc_V" },
54762a1905c7SRichard Henderson         { &cpu_icc_Z, offsetof(CPUSPARCState, icc_Z), "icc_Z" },
54772a1905c7SRichard Henderson         { &cpu_icc_C, offsetof(CPUSPARCState, icc_C), "icc_C" },
5478fcf5ef2aSThomas Huth         { &cpu_cond, offsetof(CPUSPARCState, cond), "cond" },
5479fcf5ef2aSThomas Huth         { &cpu_pc, offsetof(CPUSPARCState, pc), "pc" },
5480fcf5ef2aSThomas Huth         { &cpu_npc, offsetof(CPUSPARCState, npc), "npc" },
5481fcf5ef2aSThomas Huth         { &cpu_y, offsetof(CPUSPARCState, y), "y" },
5482fcf5ef2aSThomas Huth         { &cpu_tbr, offsetof(CPUSPARCState, tbr), "tbr" },
5483fcf5ef2aSThomas Huth     };
5484fcf5ef2aSThomas Huth 
5485fcf5ef2aSThomas Huth     unsigned int i;
5486fcf5ef2aSThomas Huth 
5487ad75a51eSRichard Henderson     cpu_regwptr = tcg_global_mem_new_ptr(tcg_env,
5488fcf5ef2aSThomas Huth                                          offsetof(CPUSPARCState, regwptr),
5489fcf5ef2aSThomas Huth                                          "regwptr");
5490fcf5ef2aSThomas Huth 
5491d8c5b92fSRichard Henderson     for (i = 0; i < ARRAY_SIZE(r32); ++i) {
5492d8c5b92fSRichard Henderson         *r32[i].ptr = tcg_global_mem_new_i32(tcg_env, r32[i].off, r32[i].name);
5493d8c5b92fSRichard Henderson     }
5494d8c5b92fSRichard Henderson 
5495fcf5ef2aSThomas Huth     for (i = 0; i < ARRAY_SIZE(rtl); ++i) {
5496ad75a51eSRichard Henderson         *rtl[i].ptr = tcg_global_mem_new(tcg_env, rtl[i].off, rtl[i].name);
5497fcf5ef2aSThomas Huth     }
5498fcf5ef2aSThomas Huth 
5499f764718dSRichard Henderson     cpu_regs[0] = NULL;
5500fcf5ef2aSThomas Huth     for (i = 1; i < 8; ++i) {
5501ad75a51eSRichard Henderson         cpu_regs[i] = tcg_global_mem_new(tcg_env,
5502fcf5ef2aSThomas Huth                                          offsetof(CPUSPARCState, gregs[i]),
5503fcf5ef2aSThomas Huth                                          gregnames[i]);
5504fcf5ef2aSThomas Huth     }
5505fcf5ef2aSThomas Huth 
5506fcf5ef2aSThomas Huth     for (i = 8; i < 32; ++i) {
5507fcf5ef2aSThomas Huth         cpu_regs[i] = tcg_global_mem_new(cpu_regwptr,
5508fcf5ef2aSThomas Huth                                          (i - 8) * sizeof(target_ulong),
5509fcf5ef2aSThomas Huth                                          gregnames[i]);
5510fcf5ef2aSThomas Huth     }
5511fcf5ef2aSThomas Huth }
5512fcf5ef2aSThomas Huth 
5513f36aaa53SRichard Henderson void sparc_restore_state_to_opc(CPUState *cs,
5514f36aaa53SRichard Henderson                                 const TranslationBlock *tb,
5515f36aaa53SRichard Henderson                                 const uint64_t *data)
5516fcf5ef2aSThomas Huth {
551777976769SPhilippe Mathieu-Daudé     CPUSPARCState *env = cpu_env(cs);
5518fcf5ef2aSThomas Huth     target_ulong pc = data[0];
5519fcf5ef2aSThomas Huth     target_ulong npc = data[1];
5520fcf5ef2aSThomas Huth 
5521fcf5ef2aSThomas Huth     env->pc = pc;
5522fcf5ef2aSThomas Huth     if (npc == DYNAMIC_PC) {
5523fcf5ef2aSThomas Huth         /* dynamic NPC: already stored */
5524fcf5ef2aSThomas Huth     } else if (npc & JUMP_PC) {
5525fcf5ef2aSThomas Huth         /* jump PC: use 'cond' and the jump targets of the translation */
5526fcf5ef2aSThomas Huth         if (env->cond) {
5527fcf5ef2aSThomas Huth             env->npc = npc & ~3;
5528fcf5ef2aSThomas Huth         } else {
5529fcf5ef2aSThomas Huth             env->npc = pc + 4;
5530fcf5ef2aSThomas Huth         }
5531fcf5ef2aSThomas Huth     } else {
5532fcf5ef2aSThomas Huth         env->npc = npc;
5533fcf5ef2aSThomas Huth     }
5534fcf5ef2aSThomas Huth }
5535