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; })
67669e0774SRichard Henderson # define gen_helper_fcmpeq8 ({ qemu_build_not_reached(); NULL; })
68e2fa6bd1SRichard Henderson # define gen_helper_fcmpeq16 ({ qemu_build_not_reached(); NULL; })
69e2fa6bd1SRichard Henderson # define gen_helper_fcmpeq32 ({ qemu_build_not_reached(); NULL; })
70b3c934ddSRichard Henderson # define gen_helper_fcmpgt8 ({ qemu_build_not_reached(); NULL; })
71e2fa6bd1SRichard Henderson # define gen_helper_fcmpgt16 ({ qemu_build_not_reached(); NULL; })
72e2fa6bd1SRichard Henderson # define gen_helper_fcmpgt32 ({ qemu_build_not_reached(); NULL; })
73b3c934ddSRichard Henderson # define gen_helper_fcmple8 ({ qemu_build_not_reached(); NULL; })
74e2fa6bd1SRichard Henderson # define gen_helper_fcmple16 ({ qemu_build_not_reached(); NULL; })
75e2fa6bd1SRichard Henderson # define gen_helper_fcmple32 ({ qemu_build_not_reached(); NULL; })
76669e0774SRichard Henderson # define gen_helper_fcmpne8 ({ qemu_build_not_reached(); NULL; })
77e2fa6bd1SRichard Henderson # define gen_helper_fcmpne16 ({ qemu_build_not_reached(); NULL; })
78e2fa6bd1SRichard Henderson # define gen_helper_fcmpne32 ({ qemu_build_not_reached(); NULL; })
79669e0774SRichard Henderson # define gen_helper_fcmpule8 ({ qemu_build_not_reached(); NULL; })
80b3c934ddSRichard Henderson # define gen_helper_fcmpule16 ({ qemu_build_not_reached(); NULL; })
81b3c934ddSRichard Henderson # define gen_helper_fcmpule32 ({ qemu_build_not_reached(); NULL; })
82669e0774SRichard Henderson # define gen_helper_fcmpugt8 ({ qemu_build_not_reached(); NULL; })
83b3c934ddSRichard Henderson # define gen_helper_fcmpugt16 ({ qemu_build_not_reached(); NULL; })
84b3c934ddSRichard Henderson # define gen_helper_fcmpugt32 ({ qemu_build_not_reached(); NULL; })
858aa418b3SRichard Henderson # define gen_helper_fdtox ({ qemu_build_not_reached(); NULL; })
86e06c9f83SRichard Henderson # define gen_helper_fexpand ({ qemu_build_not_reached(); NULL; })
87e06c9f83SRichard Henderson # define gen_helper_fmul8sux16 ({ qemu_build_not_reached(); NULL; })
88e06c9f83SRichard Henderson # define gen_helper_fmul8ulx16 ({ qemu_build_not_reached(); NULL; })
89e06c9f83SRichard Henderson # define gen_helper_fmul8x16 ({ qemu_build_not_reached(); NULL; })
90e06c9f83SRichard Henderson # define gen_helper_fpmerge ({ qemu_build_not_reached(); NULL; })
911617586fSRichard Henderson # define gen_helper_fqtox ({ qemu_build_not_reached(); NULL; })
92fbc5c8d4SRichard Henderson # define gen_helper_fslas16 ({ qemu_build_not_reached(); NULL; })
93fbc5c8d4SRichard Henderson # define gen_helper_fslas32 ({ qemu_build_not_reached(); NULL; })
94199d43efSRichard Henderson # define gen_helper_fstox ({ qemu_build_not_reached(); NULL; })
958aa418b3SRichard Henderson # define gen_helper_fxtod ({ qemu_build_not_reached(); NULL; })
967b8e3e1aSRichard Henderson # define gen_helper_fxtoq ({ qemu_build_not_reached(); NULL; })
97f4e18df5SRichard Henderson # define gen_helper_fxtos ({ qemu_build_not_reached(); NULL; })
98afb04344SRichard Henderson # define gen_helper_pdist ({ qemu_build_not_reached(); NULL; })
99029b0283SRichard Henderson # define gen_helper_xmulx ({ qemu_build_not_reached(); NULL; })
100029b0283SRichard Henderson # define gen_helper_xmulxhi ({ qemu_build_not_reached(); NULL; })
101668bb9b7SRichard Henderson # define MAXTL_MASK 0
102af25071cSRichard Henderson #endif
103af25071cSRichard Henderson
104633c4283SRichard Henderson /* Dynamic PC, must exit to main loop. */
105633c4283SRichard Henderson #define DYNAMIC_PC 1
106633c4283SRichard Henderson /* Dynamic PC, one of two values according to jump_pc[T2]. */
107633c4283SRichard Henderson #define JUMP_PC 2
108633c4283SRichard Henderson /* Dynamic PC, may lookup next TB. */
109633c4283SRichard Henderson #define DYNAMIC_PC_LOOKUP 3
110fcf5ef2aSThomas Huth
11146bb0137SMark Cave-Ayland #define DISAS_EXIT DISAS_TARGET_0
11246bb0137SMark Cave-Ayland
113fcf5ef2aSThomas Huth /* global register indexes */
114fcf5ef2aSThomas Huth static TCGv_ptr cpu_regwptr;
115c9fa8e58SRichard Henderson static TCGv cpu_pc, cpu_npc;
116fcf5ef2aSThomas Huth static TCGv cpu_regs[32];
117fcf5ef2aSThomas Huth static TCGv cpu_y;
118fcf5ef2aSThomas Huth static TCGv cpu_tbr;
119fcf5ef2aSThomas Huth static TCGv cpu_cond;
1202a1905c7SRichard Henderson static TCGv cpu_cc_N;
1212a1905c7SRichard Henderson static TCGv cpu_cc_V;
1222a1905c7SRichard Henderson static TCGv cpu_icc_Z;
1232a1905c7SRichard Henderson static TCGv cpu_icc_C;
124fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
1252a1905c7SRichard Henderson static TCGv cpu_xcc_Z;
1262a1905c7SRichard Henderson static TCGv cpu_xcc_C;
1272a1905c7SRichard Henderson static TCGv_i32 cpu_fprs;
128fcf5ef2aSThomas Huth static TCGv cpu_gsr;
129fcf5ef2aSThomas Huth #else
130af25071cSRichard Henderson # define cpu_fprs ({ qemu_build_not_reached(); (TCGv)NULL; })
131af25071cSRichard Henderson # define cpu_gsr ({ qemu_build_not_reached(); (TCGv)NULL; })
132fcf5ef2aSThomas Huth #endif
1332a1905c7SRichard Henderson
1342a1905c7SRichard Henderson #ifdef TARGET_SPARC64
1352a1905c7SRichard Henderson #define cpu_cc_Z cpu_xcc_Z
1362a1905c7SRichard Henderson #define cpu_cc_C cpu_xcc_C
1372a1905c7SRichard Henderson #else
1382a1905c7SRichard Henderson #define cpu_cc_Z cpu_icc_Z
1392a1905c7SRichard Henderson #define cpu_cc_C cpu_icc_C
1402a1905c7SRichard Henderson #define cpu_xcc_Z ({ qemu_build_not_reached(); NULL; })
1412a1905c7SRichard Henderson #define cpu_xcc_C ({ qemu_build_not_reached(); NULL; })
1422a1905c7SRichard Henderson #endif
1432a1905c7SRichard Henderson
1441210a036SRichard Henderson /* Floating point comparison registers */
145d8c5b92fSRichard Henderson static TCGv_i32 cpu_fcc[TARGET_FCCREGS];
146fcf5ef2aSThomas Huth
147af25071cSRichard Henderson #define env_field_offsetof(X) offsetof(CPUSPARCState, X)
148af25071cSRichard Henderson #ifdef TARGET_SPARC64
149cd6269f7SRichard Henderson # define env32_field_offsetof(X) ({ qemu_build_not_reached(); 0; })
150af25071cSRichard Henderson # define env64_field_offsetof(X) env_field_offsetof(X)
151af25071cSRichard Henderson #else
152cd6269f7SRichard Henderson # define env32_field_offsetof(X) env_field_offsetof(X)
153af25071cSRichard Henderson # define env64_field_offsetof(X) ({ qemu_build_not_reached(); 0; })
154af25071cSRichard Henderson #endif
155af25071cSRichard Henderson
156533f042fSRichard Henderson typedef struct DisasCompare {
157533f042fSRichard Henderson TCGCond cond;
158533f042fSRichard Henderson TCGv c1;
159533f042fSRichard Henderson int c2;
160533f042fSRichard Henderson } DisasCompare;
161533f042fSRichard Henderson
162186e7890SRichard Henderson typedef struct DisasDelayException {
163186e7890SRichard Henderson struct DisasDelayException *next;
164186e7890SRichard Henderson TCGLabel *lab;
165186e7890SRichard Henderson TCGv_i32 excp;
166186e7890SRichard Henderson /* Saved state at parent insn. */
167186e7890SRichard Henderson target_ulong pc;
168186e7890SRichard Henderson target_ulong npc;
169186e7890SRichard Henderson } DisasDelayException;
170186e7890SRichard Henderson
171fcf5ef2aSThomas Huth typedef struct DisasContext {
172af00be49SEmilio G. Cota DisasContextBase base;
173fcf5ef2aSThomas Huth target_ulong pc; /* current Program Counter: integer or DYNAMIC_PC */
174fcf5ef2aSThomas Huth target_ulong npc; /* next PC: integer or DYNAMIC_PC or JUMP_PC */
175533f042fSRichard Henderson
176533f042fSRichard Henderson /* Used when JUMP_PC value is used. */
177533f042fSRichard Henderson DisasCompare jump;
178533f042fSRichard Henderson target_ulong jump_pc[2];
179533f042fSRichard Henderson
180fcf5ef2aSThomas Huth int mem_idx;
18189527e3aSRichard Henderson bool cpu_cond_live;
182c9b459aaSArtyom Tarasenko bool fpu_enabled;
183c9b459aaSArtyom Tarasenko bool address_mask_32bit;
184c9b459aaSArtyom Tarasenko #ifndef CONFIG_USER_ONLY
185c9b459aaSArtyom Tarasenko bool supervisor;
186c9b459aaSArtyom Tarasenko #ifdef TARGET_SPARC64
187c9b459aaSArtyom Tarasenko bool hypervisor;
1885a165e26SRichard Henderson #else
1895a165e26SRichard Henderson bool fsr_qne;
190c9b459aaSArtyom Tarasenko #endif
191c9b459aaSArtyom Tarasenko #endif
192c9b459aaSArtyom Tarasenko
193fcf5ef2aSThomas Huth sparc_def_t *def;
194fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
195fcf5ef2aSThomas Huth int fprs_dirty;
196fcf5ef2aSThomas Huth int asi;
197fcf5ef2aSThomas Huth #endif
198186e7890SRichard Henderson DisasDelayException *delay_excp_list;
199fcf5ef2aSThomas Huth } DisasContext;
200fcf5ef2aSThomas Huth
201fcf5ef2aSThomas Huth // This function uses non-native bit order
202fcf5ef2aSThomas Huth #define GET_FIELD(X, FROM, TO) \
203fcf5ef2aSThomas Huth ((X) >> (31 - (TO)) & ((1 << ((TO) - (FROM) + 1)) - 1))
204fcf5ef2aSThomas Huth
205fcf5ef2aSThomas Huth // This function uses the order in the manuals, i.e. bit 0 is 2^0
206fcf5ef2aSThomas Huth #define GET_FIELD_SP(X, FROM, TO) \
207fcf5ef2aSThomas Huth GET_FIELD(X, 31 - (TO), 31 - (FROM))
208fcf5ef2aSThomas Huth
209fcf5ef2aSThomas Huth #define GET_FIELDs(x,a,b) sign_extend (GET_FIELD(x,a,b), (b) - (a) + 1)
210fcf5ef2aSThomas Huth #define GET_FIELD_SPs(x,a,b) sign_extend (GET_FIELD_SP(x,a,b), ((b) - (a) + 1))
211fcf5ef2aSThomas Huth
212fcf5ef2aSThomas Huth #define UA2005_HTRAP_MASK 0xff
213fcf5ef2aSThomas Huth #define V8_TRAP_MASK 0x7f
214fcf5ef2aSThomas Huth
215fcf5ef2aSThomas Huth #define IS_IMM (insn & (1<<13))
216fcf5ef2aSThomas Huth
gen_update_fprs_dirty(DisasContext * dc,int rd)2170c2e96c1SRichard Henderson static void gen_update_fprs_dirty(DisasContext *dc, int rd)
218fcf5ef2aSThomas Huth {
219fcf5ef2aSThomas Huth #if defined(TARGET_SPARC64)
220fcf5ef2aSThomas Huth int bit = (rd < 32) ? 1 : 2;
221fcf5ef2aSThomas Huth /* If we know we've already set this bit within the TB,
222fcf5ef2aSThomas Huth we can avoid setting it again. */
223fcf5ef2aSThomas Huth if (!(dc->fprs_dirty & bit)) {
224fcf5ef2aSThomas Huth dc->fprs_dirty |= bit;
225fcf5ef2aSThomas Huth tcg_gen_ori_i32(cpu_fprs, cpu_fprs, bit);
226fcf5ef2aSThomas Huth }
227fcf5ef2aSThomas Huth #endif
228fcf5ef2aSThomas Huth }
229fcf5ef2aSThomas Huth
230fcf5ef2aSThomas Huth /* floating point registers moves */
2311210a036SRichard Henderson
gen_offset_fpr_F(unsigned int reg)2321210a036SRichard Henderson static int gen_offset_fpr_F(unsigned int reg)
2331210a036SRichard Henderson {
2341210a036SRichard Henderson int ret;
2351210a036SRichard Henderson
2361210a036SRichard Henderson tcg_debug_assert(reg < 32);
2371210a036SRichard Henderson ret= offsetof(CPUSPARCState, fpr[reg / 2]);
2381210a036SRichard Henderson if (reg & 1) {
2391210a036SRichard Henderson ret += offsetof(CPU_DoubleU, l.lower);
2401210a036SRichard Henderson } else {
2411210a036SRichard Henderson ret += offsetof(CPU_DoubleU, l.upper);
2421210a036SRichard Henderson }
2431210a036SRichard Henderson return ret;
2441210a036SRichard Henderson }
2451210a036SRichard Henderson
gen_load_fpr_F(DisasContext * dc,unsigned int src)246fcf5ef2aSThomas Huth static TCGv_i32 gen_load_fpr_F(DisasContext *dc, unsigned int src)
247fcf5ef2aSThomas Huth {
24836ab4623SRichard Henderson TCGv_i32 ret = tcg_temp_new_i32();
2491210a036SRichard Henderson tcg_gen_ld_i32(ret, tcg_env, gen_offset_fpr_F(src));
250dc41aa7dSRichard Henderson return ret;
251fcf5ef2aSThomas Huth }
252fcf5ef2aSThomas Huth
gen_store_fpr_F(DisasContext * dc,unsigned int dst,TCGv_i32 v)253fcf5ef2aSThomas Huth static void gen_store_fpr_F(DisasContext *dc, unsigned int dst, TCGv_i32 v)
254fcf5ef2aSThomas Huth {
2551210a036SRichard Henderson tcg_gen_st_i32(v, tcg_env, gen_offset_fpr_F(dst));
256fcf5ef2aSThomas Huth gen_update_fprs_dirty(dc, dst);
257fcf5ef2aSThomas Huth }
258fcf5ef2aSThomas Huth
gen_offset_fpr_D(unsigned int reg)2591210a036SRichard Henderson static int gen_offset_fpr_D(unsigned int reg)
2601210a036SRichard Henderson {
2611210a036SRichard Henderson tcg_debug_assert(reg < 64);
2621210a036SRichard Henderson tcg_debug_assert(reg % 2 == 0);
2631210a036SRichard Henderson return offsetof(CPUSPARCState, fpr[reg / 2]);
2641210a036SRichard Henderson }
2651210a036SRichard Henderson
gen_load_fpr_D(DisasContext * dc,unsigned int src)266fcf5ef2aSThomas Huth static TCGv_i64 gen_load_fpr_D(DisasContext *dc, unsigned int src)
267fcf5ef2aSThomas Huth {
2681210a036SRichard Henderson TCGv_i64 ret = tcg_temp_new_i64();
2691210a036SRichard Henderson tcg_gen_ld_i64(ret, tcg_env, gen_offset_fpr_D(src));
2701210a036SRichard Henderson return ret;
271fcf5ef2aSThomas Huth }
272fcf5ef2aSThomas Huth
gen_store_fpr_D(DisasContext * dc,unsigned int dst,TCGv_i64 v)273fcf5ef2aSThomas Huth static void gen_store_fpr_D(DisasContext *dc, unsigned int dst, TCGv_i64 v)
274fcf5ef2aSThomas Huth {
2751210a036SRichard Henderson tcg_gen_st_i64(v, tcg_env, gen_offset_fpr_D(dst));
276fcf5ef2aSThomas Huth gen_update_fprs_dirty(dc, dst);
277fcf5ef2aSThomas Huth }
278fcf5ef2aSThomas Huth
gen_load_fpr_Q(DisasContext * dc,unsigned int src)27933ec4245SRichard Henderson static TCGv_i128 gen_load_fpr_Q(DisasContext *dc, unsigned int src)
28033ec4245SRichard Henderson {
28133ec4245SRichard Henderson TCGv_i128 ret = tcg_temp_new_i128();
2821210a036SRichard Henderson TCGv_i64 h = gen_load_fpr_D(dc, src);
2831210a036SRichard Henderson TCGv_i64 l = gen_load_fpr_D(dc, src + 2);
28433ec4245SRichard Henderson
2851210a036SRichard Henderson tcg_gen_concat_i64_i128(ret, l, h);
28633ec4245SRichard Henderson return ret;
28733ec4245SRichard Henderson }
28833ec4245SRichard Henderson
gen_store_fpr_Q(DisasContext * dc,unsigned int dst,TCGv_i128 v)28933ec4245SRichard Henderson static void gen_store_fpr_Q(DisasContext *dc, unsigned int dst, TCGv_i128 v)
29033ec4245SRichard Henderson {
2911210a036SRichard Henderson TCGv_i64 h = tcg_temp_new_i64();
2921210a036SRichard Henderson TCGv_i64 l = tcg_temp_new_i64();
2931210a036SRichard Henderson
2941210a036SRichard Henderson tcg_gen_extr_i128_i64(l, h, v);
2951210a036SRichard Henderson gen_store_fpr_D(dc, dst, h);
2961210a036SRichard Henderson gen_store_fpr_D(dc, dst + 2, l);
29733ec4245SRichard Henderson }
29833ec4245SRichard Henderson
299fcf5ef2aSThomas Huth /* moves */
300fcf5ef2aSThomas Huth #ifdef CONFIG_USER_ONLY
301fcf5ef2aSThomas Huth #define supervisor(dc) 0
302fcf5ef2aSThomas Huth #define hypervisor(dc) 0
303fcf5ef2aSThomas Huth #else
304fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
305c9b459aaSArtyom Tarasenko #define hypervisor(dc) (dc->hypervisor)
306c9b459aaSArtyom Tarasenko #define supervisor(dc) (dc->supervisor | dc->hypervisor)
307fcf5ef2aSThomas Huth #else
308c9b459aaSArtyom Tarasenko #define supervisor(dc) (dc->supervisor)
309668bb9b7SRichard Henderson #define hypervisor(dc) 0
310fcf5ef2aSThomas Huth #endif
311fcf5ef2aSThomas Huth #endif
312fcf5ef2aSThomas Huth
313b1bc09eaSRichard Henderson #if !defined(TARGET_SPARC64)
314b1bc09eaSRichard Henderson # define AM_CHECK(dc) false
315b1bc09eaSRichard Henderson #elif defined(TARGET_ABI32)
316b1bc09eaSRichard Henderson # define AM_CHECK(dc) true
317b1bc09eaSRichard Henderson #elif defined(CONFIG_USER_ONLY)
318b1bc09eaSRichard Henderson # define AM_CHECK(dc) false
319fcf5ef2aSThomas Huth #else
320b1bc09eaSRichard Henderson # define AM_CHECK(dc) ((dc)->address_mask_32bit)
321fcf5ef2aSThomas Huth #endif
322fcf5ef2aSThomas Huth
gen_address_mask(DisasContext * dc,TCGv addr)3230c2e96c1SRichard Henderson static void gen_address_mask(DisasContext *dc, TCGv addr)
324fcf5ef2aSThomas Huth {
325b1bc09eaSRichard Henderson if (AM_CHECK(dc)) {
326fcf5ef2aSThomas Huth tcg_gen_andi_tl(addr, addr, 0xffffffffULL);
327b1bc09eaSRichard Henderson }
328fcf5ef2aSThomas Huth }
329fcf5ef2aSThomas Huth
address_mask_i(DisasContext * dc,target_ulong addr)33023ada1b1SRichard Henderson static target_ulong address_mask_i(DisasContext *dc, target_ulong addr)
33123ada1b1SRichard Henderson {
33223ada1b1SRichard Henderson return AM_CHECK(dc) ? (uint32_t)addr : addr;
33323ada1b1SRichard Henderson }
33423ada1b1SRichard Henderson
gen_load_gpr(DisasContext * dc,int reg)3350c2e96c1SRichard Henderson static TCGv gen_load_gpr(DisasContext *dc, int reg)
336fcf5ef2aSThomas Huth {
337fcf5ef2aSThomas Huth if (reg > 0) {
338fcf5ef2aSThomas Huth assert(reg < 32);
339fcf5ef2aSThomas Huth return cpu_regs[reg];
340fcf5ef2aSThomas Huth } else {
34152123f14SRichard Henderson TCGv t = tcg_temp_new();
342fcf5ef2aSThomas Huth tcg_gen_movi_tl(t, 0);
343fcf5ef2aSThomas Huth return t;
344fcf5ef2aSThomas Huth }
345fcf5ef2aSThomas Huth }
346fcf5ef2aSThomas Huth
gen_store_gpr(DisasContext * dc,int reg,TCGv v)3470c2e96c1SRichard Henderson static void gen_store_gpr(DisasContext *dc, int reg, TCGv v)
348fcf5ef2aSThomas Huth {
349fcf5ef2aSThomas Huth if (reg > 0) {
350fcf5ef2aSThomas Huth assert(reg < 32);
351fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_regs[reg], v);
352fcf5ef2aSThomas Huth }
353fcf5ef2aSThomas Huth }
354fcf5ef2aSThomas Huth
gen_dest_gpr(DisasContext * dc,int reg)3550c2e96c1SRichard Henderson static TCGv gen_dest_gpr(DisasContext *dc, int reg)
356fcf5ef2aSThomas Huth {
357fcf5ef2aSThomas Huth if (reg > 0) {
358fcf5ef2aSThomas Huth assert(reg < 32);
359fcf5ef2aSThomas Huth return cpu_regs[reg];
360fcf5ef2aSThomas Huth } else {
36152123f14SRichard Henderson return tcg_temp_new();
362fcf5ef2aSThomas Huth }
363fcf5ef2aSThomas Huth }
364fcf5ef2aSThomas Huth
use_goto_tb(DisasContext * s,target_ulong pc,target_ulong npc)3655645aa2eSRichard Henderson static bool use_goto_tb(DisasContext *s, target_ulong pc, target_ulong npc)
366fcf5ef2aSThomas Huth {
3675645aa2eSRichard Henderson return translator_use_goto_tb(&s->base, pc) &&
3685645aa2eSRichard Henderson translator_use_goto_tb(&s->base, npc);
369fcf5ef2aSThomas Huth }
370fcf5ef2aSThomas Huth
gen_goto_tb(DisasContext * s,int tb_num,target_ulong pc,target_ulong npc)3715645aa2eSRichard Henderson static void gen_goto_tb(DisasContext *s, int tb_num,
372fcf5ef2aSThomas Huth target_ulong pc, target_ulong npc)
373fcf5ef2aSThomas Huth {
374fcf5ef2aSThomas Huth if (use_goto_tb(s, pc, npc)) {
375fcf5ef2aSThomas Huth /* jump to same page: we can use a direct jump */
376fcf5ef2aSThomas Huth tcg_gen_goto_tb(tb_num);
377fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_pc, pc);
378fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_npc, npc);
37907ea28b4SRichard Henderson tcg_gen_exit_tb(s->base.tb, tb_num);
380fcf5ef2aSThomas Huth } else {
381f67ccb2fSRichard Henderson /* jump to another page: we can use an indirect jump */
382fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_pc, pc);
383fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_npc, npc);
384f67ccb2fSRichard Henderson tcg_gen_lookup_and_goto_ptr();
385fcf5ef2aSThomas Huth }
386fcf5ef2aSThomas Huth }
387fcf5ef2aSThomas Huth
gen_carry32(void)388b989ce73SRichard Henderson static TCGv gen_carry32(void)
389fcf5ef2aSThomas Huth {
390b989ce73SRichard Henderson if (TARGET_LONG_BITS == 64) {
391b989ce73SRichard Henderson TCGv t = tcg_temp_new();
392b989ce73SRichard Henderson tcg_gen_extract_tl(t, cpu_icc_C, 32, 1);
393b989ce73SRichard Henderson return t;
394b989ce73SRichard Henderson }
395b989ce73SRichard Henderson return cpu_icc_C;
396fcf5ef2aSThomas Huth }
397fcf5ef2aSThomas Huth
gen_op_addcc_int(TCGv dst,TCGv src1,TCGv src2,TCGv cin)398b989ce73SRichard Henderson static void gen_op_addcc_int(TCGv dst, TCGv src1, TCGv src2, TCGv cin)
399fcf5ef2aSThomas Huth {
400b989ce73SRichard Henderson TCGv z = tcg_constant_tl(0);
401fcf5ef2aSThomas Huth
402b989ce73SRichard Henderson if (cin) {
403b989ce73SRichard Henderson tcg_gen_add2_tl(cpu_cc_N, cpu_cc_C, src1, z, cin, z);
404b989ce73SRichard Henderson tcg_gen_add2_tl(cpu_cc_N, cpu_cc_C, cpu_cc_N, cpu_cc_C, src2, z);
405b989ce73SRichard Henderson } else {
406b989ce73SRichard Henderson tcg_gen_add2_tl(cpu_cc_N, cpu_cc_C, src1, z, src2, z);
407b989ce73SRichard Henderson }
408b989ce73SRichard Henderson tcg_gen_xor_tl(cpu_cc_Z, src1, src2);
409b989ce73SRichard Henderson tcg_gen_xor_tl(cpu_cc_V, cpu_cc_N, src2);
410b989ce73SRichard Henderson tcg_gen_andc_tl(cpu_cc_V, cpu_cc_V, cpu_cc_Z);
411b989ce73SRichard Henderson if (TARGET_LONG_BITS == 64) {
412b989ce73SRichard Henderson /*
413b989ce73SRichard Henderson * Carry-in to bit 32 is result ^ src1 ^ src2.
414b989ce73SRichard Henderson * We already have the src xor term in Z, from computation of V.
415b989ce73SRichard Henderson */
416b989ce73SRichard Henderson tcg_gen_xor_tl(cpu_icc_C, cpu_cc_Z, cpu_cc_N);
417b989ce73SRichard Henderson tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N);
418b989ce73SRichard Henderson }
419b989ce73SRichard Henderson tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N);
420b989ce73SRichard Henderson tcg_gen_mov_tl(dst, cpu_cc_N);
421b989ce73SRichard Henderson }
422fcf5ef2aSThomas Huth
gen_op_addcc(TCGv dst,TCGv src1,TCGv src2)423b989ce73SRichard Henderson static void gen_op_addcc(TCGv dst, TCGv src1, TCGv src2)
424b989ce73SRichard Henderson {
425b989ce73SRichard Henderson gen_op_addcc_int(dst, src1, src2, NULL);
426b989ce73SRichard Henderson }
427fcf5ef2aSThomas Huth
gen_op_taddcc(TCGv dst,TCGv src1,TCGv src2)428b989ce73SRichard Henderson static void gen_op_taddcc(TCGv dst, TCGv src1, TCGv src2)
429b989ce73SRichard Henderson {
430b989ce73SRichard Henderson TCGv t = tcg_temp_new();
431b989ce73SRichard Henderson
432b989ce73SRichard Henderson /* Save the tag bits around modification of dst. */
433b989ce73SRichard Henderson tcg_gen_or_tl(t, src1, src2);
434b989ce73SRichard Henderson
435b989ce73SRichard Henderson gen_op_addcc(dst, src1, src2);
436b989ce73SRichard Henderson
437b989ce73SRichard Henderson /* Incorprate tag bits into icc.V */
438b989ce73SRichard Henderson tcg_gen_andi_tl(t, t, 3);
439b989ce73SRichard Henderson tcg_gen_neg_tl(t, t);
440b989ce73SRichard Henderson tcg_gen_ext32u_tl(t, t);
441b989ce73SRichard Henderson tcg_gen_or_tl(cpu_cc_V, cpu_cc_V, t);
442b989ce73SRichard Henderson }
443b989ce73SRichard Henderson
gen_op_addc(TCGv dst,TCGv src1,TCGv src2)444b989ce73SRichard Henderson static void gen_op_addc(TCGv dst, TCGv src1, TCGv src2)
445b989ce73SRichard Henderson {
446b989ce73SRichard Henderson tcg_gen_add_tl(dst, src1, src2);
447b989ce73SRichard Henderson tcg_gen_add_tl(dst, dst, gen_carry32());
448b989ce73SRichard Henderson }
449b989ce73SRichard Henderson
gen_op_addccc(TCGv dst,TCGv src1,TCGv src2)450b989ce73SRichard Henderson static void gen_op_addccc(TCGv dst, TCGv src1, TCGv src2)
451b989ce73SRichard Henderson {
452b989ce73SRichard Henderson gen_op_addcc_int(dst, src1, src2, gen_carry32());
453fcf5ef2aSThomas Huth }
454fcf5ef2aSThomas Huth
gen_op_addxc(TCGv dst,TCGv src1,TCGv src2)455015fc6fcSRichard Henderson static void gen_op_addxc(TCGv dst, TCGv src1, TCGv src2)
456015fc6fcSRichard Henderson {
457015fc6fcSRichard Henderson tcg_gen_add_tl(dst, src1, src2);
458015fc6fcSRichard Henderson tcg_gen_add_tl(dst, dst, cpu_cc_C);
459015fc6fcSRichard Henderson }
460015fc6fcSRichard Henderson
gen_op_addxccc(TCGv dst,TCGv src1,TCGv src2)461015fc6fcSRichard Henderson static void gen_op_addxccc(TCGv dst, TCGv src1, TCGv src2)
462015fc6fcSRichard Henderson {
463015fc6fcSRichard Henderson gen_op_addcc_int(dst, src1, src2, cpu_cc_C);
464015fc6fcSRichard Henderson }
465015fc6fcSRichard Henderson
gen_op_subcc_int(TCGv dst,TCGv src1,TCGv src2,TCGv cin)466f828df74SRichard Henderson static void gen_op_subcc_int(TCGv dst, TCGv src1, TCGv src2, TCGv cin)
467fcf5ef2aSThomas Huth {
468f828df74SRichard Henderson TCGv z = tcg_constant_tl(0);
469fcf5ef2aSThomas Huth
470f828df74SRichard Henderson if (cin) {
471f828df74SRichard Henderson tcg_gen_sub2_tl(cpu_cc_N, cpu_cc_C, src1, z, cin, z);
472f828df74SRichard Henderson tcg_gen_sub2_tl(cpu_cc_N, cpu_cc_C, cpu_cc_N, cpu_cc_C, src2, z);
473f828df74SRichard Henderson } else {
474f828df74SRichard Henderson tcg_gen_sub2_tl(cpu_cc_N, cpu_cc_C, src1, z, src2, z);
475f828df74SRichard Henderson }
476f828df74SRichard Henderson tcg_gen_neg_tl(cpu_cc_C, cpu_cc_C);
477f828df74SRichard Henderson tcg_gen_xor_tl(cpu_cc_Z, src1, src2);
478f828df74SRichard Henderson tcg_gen_xor_tl(cpu_cc_V, cpu_cc_N, src1);
479f828df74SRichard Henderson tcg_gen_and_tl(cpu_cc_V, cpu_cc_V, cpu_cc_Z);
480f828df74SRichard Henderson #ifdef TARGET_SPARC64
481f828df74SRichard Henderson tcg_gen_xor_tl(cpu_icc_C, cpu_cc_Z, cpu_cc_N);
482f828df74SRichard Henderson tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N);
483fcf5ef2aSThomas Huth #endif
484f828df74SRichard Henderson tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N);
485f828df74SRichard Henderson tcg_gen_mov_tl(dst, cpu_cc_N);
486fcf5ef2aSThomas Huth }
487fcf5ef2aSThomas Huth
gen_op_subcc(TCGv dst,TCGv src1,TCGv src2)488f828df74SRichard Henderson static void gen_op_subcc(TCGv dst, TCGv src1, TCGv src2)
489fcf5ef2aSThomas Huth {
490f828df74SRichard Henderson gen_op_subcc_int(dst, src1, src2, NULL);
491fcf5ef2aSThomas Huth }
492fcf5ef2aSThomas Huth
gen_op_tsubcc(TCGv dst,TCGv src1,TCGv src2)493f828df74SRichard Henderson static void gen_op_tsubcc(TCGv dst, TCGv src1, TCGv src2)
494fcf5ef2aSThomas Huth {
495f828df74SRichard Henderson TCGv t = tcg_temp_new();
496fcf5ef2aSThomas Huth
497f828df74SRichard Henderson /* Save the tag bits around modification of dst. */
498f828df74SRichard Henderson tcg_gen_or_tl(t, src1, src2);
499fcf5ef2aSThomas Huth
500f828df74SRichard Henderson gen_op_subcc(dst, src1, src2);
501f828df74SRichard Henderson
502f828df74SRichard Henderson /* Incorprate tag bits into icc.V */
503f828df74SRichard Henderson tcg_gen_andi_tl(t, t, 3);
504f828df74SRichard Henderson tcg_gen_neg_tl(t, t);
505f828df74SRichard Henderson tcg_gen_ext32u_tl(t, t);
506f828df74SRichard Henderson tcg_gen_or_tl(cpu_cc_V, cpu_cc_V, t);
507f828df74SRichard Henderson }
508f828df74SRichard Henderson
gen_op_subc(TCGv dst,TCGv src1,TCGv src2)509f828df74SRichard Henderson static void gen_op_subc(TCGv dst, TCGv src1, TCGv src2)
510f828df74SRichard Henderson {
511fcf5ef2aSThomas Huth tcg_gen_sub_tl(dst, src1, src2);
512f828df74SRichard Henderson tcg_gen_sub_tl(dst, dst, gen_carry32());
513fcf5ef2aSThomas Huth }
514fcf5ef2aSThomas Huth
gen_op_subccc(TCGv dst,TCGv src1,TCGv src2)515f828df74SRichard Henderson static void gen_op_subccc(TCGv dst, TCGv src1, TCGv src2)
516dfebb950SRichard Henderson {
517f828df74SRichard Henderson gen_op_subcc_int(dst, src1, src2, gen_carry32());
518dfebb950SRichard Henderson }
519dfebb950SRichard Henderson
gen_op_subxc(TCGv dst,TCGv src1,TCGv src2)52056f2ef9cSRichard Henderson static void gen_op_subxc(TCGv dst, TCGv src1, TCGv src2)
52156f2ef9cSRichard Henderson {
52256f2ef9cSRichard Henderson tcg_gen_sub_tl(dst, src1, src2);
52356f2ef9cSRichard Henderson tcg_gen_sub_tl(dst, dst, cpu_cc_C);
52456f2ef9cSRichard Henderson }
52556f2ef9cSRichard Henderson
gen_op_subxccc(TCGv dst,TCGv src1,TCGv src2)52656f2ef9cSRichard Henderson static void gen_op_subxccc(TCGv dst, TCGv src1, TCGv src2)
52756f2ef9cSRichard Henderson {
52856f2ef9cSRichard Henderson gen_op_subcc_int(dst, src1, src2, cpu_cc_C);
52956f2ef9cSRichard Henderson }
53056f2ef9cSRichard Henderson
gen_op_mulscc(TCGv dst,TCGv src1,TCGv src2)5310c2e96c1SRichard Henderson static void gen_op_mulscc(TCGv dst, TCGv src1, TCGv src2)
532fcf5ef2aSThomas Huth {
533b989ce73SRichard Henderson TCGv zero = tcg_constant_tl(0);
53450280618SRichard Henderson TCGv one = tcg_constant_tl(1);
535b989ce73SRichard Henderson TCGv t_src1 = tcg_temp_new();
536b989ce73SRichard Henderson TCGv t_src2 = tcg_temp_new();
537b989ce73SRichard Henderson TCGv t0 = tcg_temp_new();
538fcf5ef2aSThomas Huth
539b989ce73SRichard Henderson tcg_gen_ext32u_tl(t_src1, src1);
540b989ce73SRichard Henderson tcg_gen_ext32u_tl(t_src2, src2);
541fcf5ef2aSThomas Huth
542b989ce73SRichard Henderson /*
543b989ce73SRichard Henderson * if (!(env->y & 1))
544b989ce73SRichard Henderson * src2 = 0;
545fcf5ef2aSThomas Huth */
54650280618SRichard Henderson tcg_gen_movcond_tl(TCG_COND_TSTEQ, t_src2, cpu_y, one, zero, t_src2);
547fcf5ef2aSThomas Huth
548b989ce73SRichard Henderson /*
549b989ce73SRichard Henderson * b2 = src1 & 1;
550b989ce73SRichard Henderson * y = (b2 << 31) | (y >> 1);
551b989ce73SRichard Henderson */
5520b1183e3SPhilippe Mathieu-Daudé tcg_gen_extract_tl(t0, cpu_y, 1, 31);
553b989ce73SRichard Henderson tcg_gen_deposit_tl(cpu_y, t0, src1, 31, 1);
554fcf5ef2aSThomas Huth
555fcf5ef2aSThomas Huth // b1 = N ^ V;
5562a1905c7SRichard Henderson tcg_gen_xor_tl(t0, cpu_cc_N, cpu_cc_V);
557fcf5ef2aSThomas Huth
558b989ce73SRichard Henderson /*
559b989ce73SRichard Henderson * src1 = (b1 << 31) | (src1 >> 1)
560b989ce73SRichard Henderson */
5612a1905c7SRichard Henderson tcg_gen_andi_tl(t0, t0, 1u << 31);
562b989ce73SRichard Henderson tcg_gen_shri_tl(t_src1, t_src1, 1);
563b989ce73SRichard Henderson tcg_gen_or_tl(t_src1, t_src1, t0);
564fcf5ef2aSThomas Huth
565b989ce73SRichard Henderson gen_op_addcc(dst, t_src1, t_src2);
566fcf5ef2aSThomas Huth }
567fcf5ef2aSThomas Huth
gen_op_multiply(TCGv dst,TCGv src1,TCGv src2,int sign_ext)5680c2e96c1SRichard Henderson static void gen_op_multiply(TCGv dst, TCGv src1, TCGv src2, int sign_ext)
569fcf5ef2aSThomas Huth {
570fcf5ef2aSThomas Huth #if TARGET_LONG_BITS == 32
571fcf5ef2aSThomas Huth if (sign_ext) {
572fcf5ef2aSThomas Huth tcg_gen_muls2_tl(dst, cpu_y, src1, src2);
573fcf5ef2aSThomas Huth } else {
574fcf5ef2aSThomas Huth tcg_gen_mulu2_tl(dst, cpu_y, src1, src2);
575fcf5ef2aSThomas Huth }
576fcf5ef2aSThomas Huth #else
577fcf5ef2aSThomas Huth TCGv t0 = tcg_temp_new_i64();
578fcf5ef2aSThomas Huth TCGv t1 = tcg_temp_new_i64();
579fcf5ef2aSThomas Huth
580fcf5ef2aSThomas Huth if (sign_ext) {
581fcf5ef2aSThomas Huth tcg_gen_ext32s_i64(t0, src1);
582fcf5ef2aSThomas Huth tcg_gen_ext32s_i64(t1, src2);
583fcf5ef2aSThomas Huth } else {
584fcf5ef2aSThomas Huth tcg_gen_ext32u_i64(t0, src1);
585fcf5ef2aSThomas Huth tcg_gen_ext32u_i64(t1, src2);
586fcf5ef2aSThomas Huth }
587fcf5ef2aSThomas Huth
588fcf5ef2aSThomas Huth tcg_gen_mul_i64(dst, t0, t1);
589fcf5ef2aSThomas Huth tcg_gen_shri_i64(cpu_y, dst, 32);
590fcf5ef2aSThomas Huth #endif
591fcf5ef2aSThomas Huth }
592fcf5ef2aSThomas Huth
gen_op_umul(TCGv dst,TCGv src1,TCGv src2)5930c2e96c1SRichard Henderson static void gen_op_umul(TCGv dst, TCGv src1, TCGv src2)
594fcf5ef2aSThomas Huth {
595fcf5ef2aSThomas Huth /* zero-extend truncated operands before multiplication */
596fcf5ef2aSThomas Huth gen_op_multiply(dst, src1, src2, 0);
597fcf5ef2aSThomas Huth }
598fcf5ef2aSThomas Huth
gen_op_smul(TCGv dst,TCGv src1,TCGv src2)5990c2e96c1SRichard Henderson static void gen_op_smul(TCGv dst, TCGv src1, TCGv src2)
600fcf5ef2aSThomas Huth {
601fcf5ef2aSThomas Huth /* sign-extend truncated operands before multiplication */
602fcf5ef2aSThomas Huth gen_op_multiply(dst, src1, src2, 1);
603fcf5ef2aSThomas Huth }
604fcf5ef2aSThomas Huth
gen_op_umulxhi(TCGv dst,TCGv src1,TCGv src2)605680af1b4SRichard Henderson static void gen_op_umulxhi(TCGv dst, TCGv src1, TCGv src2)
606680af1b4SRichard Henderson {
607680af1b4SRichard Henderson TCGv discard = tcg_temp_new();
608680af1b4SRichard Henderson tcg_gen_mulu2_tl(discard, dst, src1, src2);
609680af1b4SRichard Henderson }
610680af1b4SRichard Henderson
gen_op_fpmaddx(TCGv_i64 dst,TCGv_i64 src1,TCGv_i64 src2,TCGv_i64 src3)61168a414e9SRichard Henderson static void gen_op_fpmaddx(TCGv_i64 dst, TCGv_i64 src1,
61268a414e9SRichard Henderson TCGv_i64 src2, TCGv_i64 src3)
61368a414e9SRichard Henderson {
61468a414e9SRichard Henderson TCGv_i64 t = tcg_temp_new_i64();
61568a414e9SRichard Henderson
61668a414e9SRichard Henderson tcg_gen_mul_i64(t, src1, src2);
61768a414e9SRichard Henderson tcg_gen_add_i64(dst, src3, t);
61868a414e9SRichard Henderson }
61968a414e9SRichard Henderson
gen_op_fpmaddxhi(TCGv_i64 dst,TCGv_i64 src1,TCGv_i64 src2,TCGv_i64 src3)62068a414e9SRichard Henderson static void gen_op_fpmaddxhi(TCGv_i64 dst, TCGv_i64 src1,
62168a414e9SRichard Henderson TCGv_i64 src2, TCGv_i64 src3)
62268a414e9SRichard Henderson {
62368a414e9SRichard Henderson TCGv_i64 l = tcg_temp_new_i64();
62468a414e9SRichard Henderson TCGv_i64 h = tcg_temp_new_i64();
62568a414e9SRichard Henderson TCGv_i64 z = tcg_constant_i64(0);
62668a414e9SRichard Henderson
62768a414e9SRichard Henderson tcg_gen_mulu2_i64(l, h, src1, src2);
62868a414e9SRichard Henderson tcg_gen_add2_i64(l, dst, l, h, src3, z);
62968a414e9SRichard Henderson }
63068a414e9SRichard Henderson
gen_op_sdiv(TCGv dst,TCGv src1,TCGv src2)631c2636853SRichard Henderson static void gen_op_sdiv(TCGv dst, TCGv src1, TCGv src2)
632c2636853SRichard Henderson {
63313260103SRichard Henderson #ifdef TARGET_SPARC64
634c2636853SRichard Henderson gen_helper_sdiv(dst, tcg_env, src1, src2);
63513260103SRichard Henderson tcg_gen_ext32s_tl(dst, dst);
63613260103SRichard Henderson #else
63713260103SRichard Henderson TCGv_i64 t64 = tcg_temp_new_i64();
63813260103SRichard Henderson gen_helper_sdiv(t64, tcg_env, src1, src2);
63913260103SRichard Henderson tcg_gen_trunc_i64_tl(dst, t64);
64013260103SRichard Henderson #endif
641c2636853SRichard Henderson }
642c2636853SRichard Henderson
gen_op_udivcc(TCGv dst,TCGv src1,TCGv src2)643c2636853SRichard Henderson static void gen_op_udivcc(TCGv dst, TCGv src1, TCGv src2)
644c2636853SRichard Henderson {
64513260103SRichard Henderson TCGv_i64 t64;
64613260103SRichard Henderson
64713260103SRichard Henderson #ifdef TARGET_SPARC64
64813260103SRichard Henderson t64 = cpu_cc_V;
64913260103SRichard Henderson #else
65013260103SRichard Henderson t64 = tcg_temp_new_i64();
65113260103SRichard Henderson #endif
65213260103SRichard Henderson
65313260103SRichard Henderson gen_helper_udiv(t64, tcg_env, src1, src2);
65413260103SRichard Henderson
65513260103SRichard Henderson #ifdef TARGET_SPARC64
65613260103SRichard Henderson tcg_gen_ext32u_tl(cpu_cc_N, t64);
65713260103SRichard Henderson tcg_gen_shri_tl(cpu_cc_V, t64, 32);
65813260103SRichard Henderson tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N);
65913260103SRichard Henderson tcg_gen_movi_tl(cpu_icc_C, 0);
66013260103SRichard Henderson #else
66113260103SRichard Henderson tcg_gen_extr_i64_tl(cpu_cc_N, cpu_cc_V, t64);
66213260103SRichard Henderson #endif
66313260103SRichard Henderson tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N);
66413260103SRichard Henderson tcg_gen_movi_tl(cpu_cc_C, 0);
66513260103SRichard Henderson tcg_gen_mov_tl(dst, cpu_cc_N);
666c2636853SRichard Henderson }
667c2636853SRichard Henderson
gen_op_sdivcc(TCGv dst,TCGv src1,TCGv src2)668c2636853SRichard Henderson static void gen_op_sdivcc(TCGv dst, TCGv src1, TCGv src2)
669c2636853SRichard Henderson {
67013260103SRichard Henderson TCGv_i64 t64;
67113260103SRichard Henderson
67213260103SRichard Henderson #ifdef TARGET_SPARC64
67313260103SRichard Henderson t64 = cpu_cc_V;
67413260103SRichard Henderson #else
67513260103SRichard Henderson t64 = tcg_temp_new_i64();
67613260103SRichard Henderson #endif
67713260103SRichard Henderson
67813260103SRichard Henderson gen_helper_sdiv(t64, tcg_env, src1, src2);
67913260103SRichard Henderson
68013260103SRichard Henderson #ifdef TARGET_SPARC64
68113260103SRichard Henderson tcg_gen_ext32s_tl(cpu_cc_N, t64);
68213260103SRichard Henderson tcg_gen_shri_tl(cpu_cc_V, t64, 32);
68313260103SRichard Henderson tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N);
68413260103SRichard Henderson tcg_gen_movi_tl(cpu_icc_C, 0);
68513260103SRichard Henderson #else
68613260103SRichard Henderson tcg_gen_extr_i64_tl(cpu_cc_N, cpu_cc_V, t64);
68713260103SRichard Henderson #endif
68813260103SRichard Henderson tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N);
68913260103SRichard Henderson tcg_gen_movi_tl(cpu_cc_C, 0);
69013260103SRichard Henderson tcg_gen_mov_tl(dst, cpu_cc_N);
691c2636853SRichard Henderson }
692c2636853SRichard Henderson
gen_op_taddcctv(TCGv dst,TCGv src1,TCGv src2)693a9aba13dSRichard Henderson static void gen_op_taddcctv(TCGv dst, TCGv src1, TCGv src2)
694a9aba13dSRichard Henderson {
695a9aba13dSRichard Henderson gen_helper_taddcctv(dst, tcg_env, src1, src2);
696a9aba13dSRichard Henderson }
697a9aba13dSRichard Henderson
gen_op_tsubcctv(TCGv dst,TCGv src1,TCGv src2)698a9aba13dSRichard Henderson static void gen_op_tsubcctv(TCGv dst, TCGv src1, TCGv src2)
699a9aba13dSRichard Henderson {
700a9aba13dSRichard Henderson gen_helper_tsubcctv(dst, tcg_env, src1, src2);
701a9aba13dSRichard Henderson }
702a9aba13dSRichard Henderson
gen_op_popc(TCGv dst,TCGv src1,TCGv src2)7039c6ec5bcSRichard Henderson static void gen_op_popc(TCGv dst, TCGv src1, TCGv src2)
7049c6ec5bcSRichard Henderson {
7059c6ec5bcSRichard Henderson tcg_gen_ctpop_tl(dst, src2);
7069c6ec5bcSRichard Henderson }
7079c6ec5bcSRichard Henderson
gen_op_lzcnt(TCGv dst,TCGv src)708875ce392SRichard Henderson static void gen_op_lzcnt(TCGv dst, TCGv src)
709875ce392SRichard Henderson {
710875ce392SRichard Henderson tcg_gen_clzi_tl(dst, src, TARGET_LONG_BITS);
711875ce392SRichard Henderson }
712875ce392SRichard Henderson
71345bfed3bSRichard Henderson #ifndef TARGET_SPARC64
gen_helper_array8(TCGv dst,TCGv src1,TCGv src2)71445bfed3bSRichard Henderson static void gen_helper_array8(TCGv dst, TCGv src1, TCGv src2)
71545bfed3bSRichard Henderson {
71645bfed3bSRichard Henderson g_assert_not_reached();
71745bfed3bSRichard Henderson }
71845bfed3bSRichard Henderson #endif
71945bfed3bSRichard Henderson
gen_op_array16(TCGv dst,TCGv src1,TCGv src2)72045bfed3bSRichard Henderson static void gen_op_array16(TCGv dst, TCGv src1, TCGv src2)
72145bfed3bSRichard Henderson {
72245bfed3bSRichard Henderson gen_helper_array8(dst, src1, src2);
72345bfed3bSRichard Henderson tcg_gen_shli_tl(dst, dst, 1);
72445bfed3bSRichard Henderson }
72545bfed3bSRichard Henderson
gen_op_array32(TCGv dst,TCGv src1,TCGv src2)72645bfed3bSRichard Henderson static void gen_op_array32(TCGv dst, TCGv src1, TCGv src2)
72745bfed3bSRichard Henderson {
72845bfed3bSRichard Henderson gen_helper_array8(dst, src1, src2);
72945bfed3bSRichard Henderson tcg_gen_shli_tl(dst, dst, 2);
73045bfed3bSRichard Henderson }
73145bfed3bSRichard Henderson
gen_op_fpack16(TCGv_i32 dst,TCGv_i64 src)7322f722641SRichard Henderson static void gen_op_fpack16(TCGv_i32 dst, TCGv_i64 src)
7332f722641SRichard Henderson {
7342f722641SRichard Henderson #ifdef TARGET_SPARC64
7352f722641SRichard Henderson gen_helper_fpack16(dst, cpu_gsr, src);
7362f722641SRichard Henderson #else
7372f722641SRichard Henderson g_assert_not_reached();
7382f722641SRichard Henderson #endif
7392f722641SRichard Henderson }
7402f722641SRichard Henderson
gen_op_fpackfix(TCGv_i32 dst,TCGv_i64 src)7412f722641SRichard Henderson static void gen_op_fpackfix(TCGv_i32 dst, TCGv_i64 src)
7422f722641SRichard Henderson {
7432f722641SRichard Henderson #ifdef TARGET_SPARC64
7442f722641SRichard Henderson gen_helper_fpackfix(dst, cpu_gsr, src);
7452f722641SRichard Henderson #else
7462f722641SRichard Henderson g_assert_not_reached();
7472f722641SRichard Henderson #endif
7482f722641SRichard Henderson }
7492f722641SRichard Henderson
gen_op_fpack32(TCGv_i64 dst,TCGv_i64 src1,TCGv_i64 src2)7504b6edc0aSRichard Henderson static void gen_op_fpack32(TCGv_i64 dst, TCGv_i64 src1, TCGv_i64 src2)
7514b6edc0aSRichard Henderson {
7524b6edc0aSRichard Henderson #ifdef TARGET_SPARC64
7534b6edc0aSRichard Henderson gen_helper_fpack32(dst, cpu_gsr, src1, src2);
7544b6edc0aSRichard Henderson #else
7554b6edc0aSRichard Henderson g_assert_not_reached();
7564b6edc0aSRichard Henderson #endif
7574b6edc0aSRichard Henderson }
7584b6edc0aSRichard Henderson
gen_op_fpadds16s(TCGv_i32 d,TCGv_i32 src1,TCGv_i32 src2)7590d1d3aafSRichard Henderson static void gen_op_fpadds16s(TCGv_i32 d, TCGv_i32 src1, TCGv_i32 src2)
7600d1d3aafSRichard Henderson {
7610d1d3aafSRichard Henderson TCGv_i32 t[2];
7620d1d3aafSRichard Henderson
7630d1d3aafSRichard Henderson for (int i = 0; i < 2; i++) {
7640d1d3aafSRichard Henderson TCGv_i32 u = tcg_temp_new_i32();
7650d1d3aafSRichard Henderson TCGv_i32 v = tcg_temp_new_i32();
7660d1d3aafSRichard Henderson
7670d1d3aafSRichard Henderson tcg_gen_sextract_i32(u, src1, i * 16, 16);
7680d1d3aafSRichard Henderson tcg_gen_sextract_i32(v, src2, i * 16, 16);
7690d1d3aafSRichard Henderson tcg_gen_add_i32(u, u, v);
7700d1d3aafSRichard Henderson tcg_gen_smax_i32(u, u, tcg_constant_i32(INT16_MIN));
7710d1d3aafSRichard Henderson tcg_gen_smin_i32(u, u, tcg_constant_i32(INT16_MAX));
7720d1d3aafSRichard Henderson t[i] = u;
7730d1d3aafSRichard Henderson }
7740d1d3aafSRichard Henderson tcg_gen_deposit_i32(d, t[0], t[1], 16, 16);
7750d1d3aafSRichard Henderson }
7760d1d3aafSRichard Henderson
gen_op_fpsubs16s(TCGv_i32 d,TCGv_i32 src1,TCGv_i32 src2)7770d1d3aafSRichard Henderson static void gen_op_fpsubs16s(TCGv_i32 d, TCGv_i32 src1, TCGv_i32 src2)
7780d1d3aafSRichard Henderson {
7790d1d3aafSRichard Henderson TCGv_i32 t[2];
7800d1d3aafSRichard Henderson
7810d1d3aafSRichard Henderson for (int i = 0; i < 2; i++) {
7820d1d3aafSRichard Henderson TCGv_i32 u = tcg_temp_new_i32();
7830d1d3aafSRichard Henderson TCGv_i32 v = tcg_temp_new_i32();
7840d1d3aafSRichard Henderson
7850d1d3aafSRichard Henderson tcg_gen_sextract_i32(u, src1, i * 16, 16);
7860d1d3aafSRichard Henderson tcg_gen_sextract_i32(v, src2, i * 16, 16);
7870d1d3aafSRichard Henderson tcg_gen_sub_i32(u, u, v);
7880d1d3aafSRichard Henderson tcg_gen_smax_i32(u, u, tcg_constant_i32(INT16_MIN));
7890d1d3aafSRichard Henderson tcg_gen_smin_i32(u, u, tcg_constant_i32(INT16_MAX));
7900d1d3aafSRichard Henderson t[i] = u;
7910d1d3aafSRichard Henderson }
7920d1d3aafSRichard Henderson tcg_gen_deposit_i32(d, t[0], t[1], 16, 16);
7930d1d3aafSRichard Henderson }
7940d1d3aafSRichard Henderson
gen_op_fpadds32s(TCGv_i32 d,TCGv_i32 src1,TCGv_i32 src2)7950d1d3aafSRichard Henderson static void gen_op_fpadds32s(TCGv_i32 d, TCGv_i32 src1, TCGv_i32 src2)
7960d1d3aafSRichard Henderson {
7970d1d3aafSRichard Henderson TCGv_i32 r = tcg_temp_new_i32();
7980d1d3aafSRichard Henderson TCGv_i32 t = tcg_temp_new_i32();
7990d1d3aafSRichard Henderson TCGv_i32 v = tcg_temp_new_i32();
8000d1d3aafSRichard Henderson TCGv_i32 z = tcg_constant_i32(0);
8010d1d3aafSRichard Henderson
8020d1d3aafSRichard Henderson tcg_gen_add_i32(r, src1, src2);
8030d1d3aafSRichard Henderson tcg_gen_xor_i32(t, src1, src2);
8040d1d3aafSRichard Henderson tcg_gen_xor_i32(v, r, src2);
8050d1d3aafSRichard Henderson tcg_gen_andc_i32(v, v, t);
8060d1d3aafSRichard Henderson
8070d1d3aafSRichard Henderson tcg_gen_setcond_i32(TCG_COND_GE, t, r, z);
8080d1d3aafSRichard Henderson tcg_gen_addi_i32(t, t, INT32_MAX);
8090d1d3aafSRichard Henderson
8100d1d3aafSRichard Henderson tcg_gen_movcond_i32(TCG_COND_LT, d, v, z, t, r);
8110d1d3aafSRichard Henderson }
8120d1d3aafSRichard Henderson
gen_op_fpsubs32s(TCGv_i32 d,TCGv_i32 src1,TCGv_i32 src2)8130d1d3aafSRichard Henderson static void gen_op_fpsubs32s(TCGv_i32 d, TCGv_i32 src1, TCGv_i32 src2)
8140d1d3aafSRichard Henderson {
8150d1d3aafSRichard Henderson TCGv_i32 r = tcg_temp_new_i32();
8160d1d3aafSRichard Henderson TCGv_i32 t = tcg_temp_new_i32();
8170d1d3aafSRichard Henderson TCGv_i32 v = tcg_temp_new_i32();
8180d1d3aafSRichard Henderson TCGv_i32 z = tcg_constant_i32(0);
8190d1d3aafSRichard Henderson
8200d1d3aafSRichard Henderson tcg_gen_sub_i32(r, src1, src2);
8210d1d3aafSRichard Henderson tcg_gen_xor_i32(t, src1, src2);
8220d1d3aafSRichard Henderson tcg_gen_xor_i32(v, r, src1);
8230d1d3aafSRichard Henderson tcg_gen_and_i32(v, v, t);
8240d1d3aafSRichard Henderson
8250d1d3aafSRichard Henderson tcg_gen_setcond_i32(TCG_COND_GE, t, r, z);
8260d1d3aafSRichard Henderson tcg_gen_addi_i32(t, t, INT32_MAX);
8270d1d3aafSRichard Henderson
8280d1d3aafSRichard Henderson tcg_gen_movcond_i32(TCG_COND_LT, d, v, z, t, r);
8290d1d3aafSRichard Henderson }
8300d1d3aafSRichard Henderson
gen_op_faligndata_i(TCGv_i64 dst,TCGv_i64 s1,TCGv_i64 s2,TCGv gsr)831b2b48493SRichard Henderson static void gen_op_faligndata_i(TCGv_i64 dst, TCGv_i64 s1,
832b2b48493SRichard Henderson TCGv_i64 s2, TCGv gsr)
8334b6edc0aSRichard Henderson {
8344b6edc0aSRichard Henderson #ifdef TARGET_SPARC64
8354b6edc0aSRichard Henderson TCGv t1, t2, shift;
8364b6edc0aSRichard Henderson
8374b6edc0aSRichard Henderson t1 = tcg_temp_new();
8384b6edc0aSRichard Henderson t2 = tcg_temp_new();
8394b6edc0aSRichard Henderson shift = tcg_temp_new();
8404b6edc0aSRichard Henderson
841b2b48493SRichard Henderson tcg_gen_andi_tl(shift, gsr, 7);
8424b6edc0aSRichard Henderson tcg_gen_shli_tl(shift, shift, 3);
8434b6edc0aSRichard Henderson tcg_gen_shl_tl(t1, s1, shift);
8444b6edc0aSRichard Henderson
8454b6edc0aSRichard Henderson /*
8464b6edc0aSRichard Henderson * A shift of 64 does not produce 0 in TCG. Divide this into a
8474b6edc0aSRichard Henderson * shift of (up to 63) followed by a constant shift of 1.
8484b6edc0aSRichard Henderson */
8494b6edc0aSRichard Henderson tcg_gen_xori_tl(shift, shift, 63);
8504b6edc0aSRichard Henderson tcg_gen_shr_tl(t2, s2, shift);
8514b6edc0aSRichard Henderson tcg_gen_shri_tl(t2, t2, 1);
8524b6edc0aSRichard Henderson
8534b6edc0aSRichard Henderson tcg_gen_or_tl(dst, t1, t2);
8544b6edc0aSRichard Henderson #else
8554b6edc0aSRichard Henderson g_assert_not_reached();
8564b6edc0aSRichard Henderson #endif
8574b6edc0aSRichard Henderson }
8584b6edc0aSRichard Henderson
gen_op_faligndata_g(TCGv_i64 dst,TCGv_i64 s1,TCGv_i64 s2)859b2b48493SRichard Henderson static void gen_op_faligndata_g(TCGv_i64 dst, TCGv_i64 s1, TCGv_i64 s2)
860b2b48493SRichard Henderson {
861b2b48493SRichard Henderson gen_op_faligndata_i(dst, s1, s2, cpu_gsr);
862b2b48493SRichard Henderson }
863b2b48493SRichard Henderson
gen_op_bshuffle(TCGv_i64 dst,TCGv_i64 src1,TCGv_i64 src2)8644b6edc0aSRichard Henderson static void gen_op_bshuffle(TCGv_i64 dst, TCGv_i64 src1, TCGv_i64 src2)
8654b6edc0aSRichard Henderson {
8664b6edc0aSRichard Henderson #ifdef TARGET_SPARC64
8674b6edc0aSRichard Henderson gen_helper_bshuffle(dst, cpu_gsr, src1, src2);
8684b6edc0aSRichard Henderson #else
8694b6edc0aSRichard Henderson g_assert_not_reached();
8704b6edc0aSRichard Henderson #endif
8714b6edc0aSRichard Henderson }
8724b6edc0aSRichard Henderson
gen_op_pdistn(TCGv dst,TCGv_i64 src1,TCGv_i64 src2)8737d5ebd8fSRichard Henderson static void gen_op_pdistn(TCGv dst, TCGv_i64 src1, TCGv_i64 src2)
8747d5ebd8fSRichard Henderson {
8757d5ebd8fSRichard Henderson #ifdef TARGET_SPARC64
8767d5ebd8fSRichard Henderson gen_helper_pdist(dst, tcg_constant_i64(0), src1, src2);
8777d5ebd8fSRichard Henderson #else
8787d5ebd8fSRichard Henderson g_assert_not_reached();
8797d5ebd8fSRichard Henderson #endif
8807d5ebd8fSRichard Henderson }
8817d5ebd8fSRichard Henderson
gen_op_fmul8x16al(TCGv_i64 dst,TCGv_i32 src1,TCGv_i32 src2)882a859602cSRichard Henderson static void gen_op_fmul8x16al(TCGv_i64 dst, TCGv_i32 src1, TCGv_i32 src2)
883a859602cSRichard Henderson {
884a859602cSRichard Henderson tcg_gen_ext16s_i32(src2, src2);
885a859602cSRichard Henderson gen_helper_fmul8x16a(dst, src1, src2);
886a859602cSRichard Henderson }
887a859602cSRichard Henderson
gen_op_fmul8x16au(TCGv_i64 dst,TCGv_i32 src1,TCGv_i32 src2)888a859602cSRichard Henderson static void gen_op_fmul8x16au(TCGv_i64 dst, TCGv_i32 src1, TCGv_i32 src2)
889a859602cSRichard Henderson {
890a859602cSRichard Henderson tcg_gen_sari_i32(src2, src2, 16);
891a859602cSRichard Henderson gen_helper_fmul8x16a(dst, src1, src2);
892a859602cSRichard Henderson }
893a859602cSRichard Henderson
gen_op_fmuld8ulx16(TCGv_i64 dst,TCGv_i32 src1,TCGv_i32 src2)894be8998e0SRichard Henderson static void gen_op_fmuld8ulx16(TCGv_i64 dst, TCGv_i32 src1, TCGv_i32 src2)
895be8998e0SRichard Henderson {
896be8998e0SRichard Henderson TCGv_i32 t0 = tcg_temp_new_i32();
897be8998e0SRichard Henderson TCGv_i32 t1 = tcg_temp_new_i32();
898be8998e0SRichard Henderson TCGv_i32 t2 = tcg_temp_new_i32();
899be8998e0SRichard Henderson
900be8998e0SRichard Henderson tcg_gen_ext8u_i32(t0, src1);
901be8998e0SRichard Henderson tcg_gen_ext16s_i32(t1, src2);
902be8998e0SRichard Henderson tcg_gen_mul_i32(t0, t0, t1);
903be8998e0SRichard Henderson
904be8998e0SRichard Henderson tcg_gen_extract_i32(t1, src1, 16, 8);
905be8998e0SRichard Henderson tcg_gen_sextract_i32(t2, src2, 16, 16);
906be8998e0SRichard Henderson tcg_gen_mul_i32(t1, t1, t2);
907be8998e0SRichard Henderson
908be8998e0SRichard Henderson tcg_gen_concat_i32_i64(dst, t0, t1);
909be8998e0SRichard Henderson }
910be8998e0SRichard Henderson
gen_op_fmuld8sux16(TCGv_i64 dst,TCGv_i32 src1,TCGv_i32 src2)911be8998e0SRichard Henderson static void gen_op_fmuld8sux16(TCGv_i64 dst, TCGv_i32 src1, TCGv_i32 src2)
912be8998e0SRichard Henderson {
913be8998e0SRichard Henderson TCGv_i32 t0 = tcg_temp_new_i32();
914be8998e0SRichard Henderson TCGv_i32 t1 = tcg_temp_new_i32();
915be8998e0SRichard Henderson TCGv_i32 t2 = tcg_temp_new_i32();
916be8998e0SRichard Henderson
917be8998e0SRichard Henderson /*
918be8998e0SRichard Henderson * The insn description talks about extracting the upper 8 bits
919be8998e0SRichard Henderson * of the signed 16-bit input rs1, performing the multiply, then
920be8998e0SRichard Henderson * shifting left by 8 bits. Instead, zap the lower 8 bits of
921be8998e0SRichard Henderson * the rs1 input, which avoids the need for two shifts.
922be8998e0SRichard Henderson */
923be8998e0SRichard Henderson tcg_gen_ext16s_i32(t0, src1);
924be8998e0SRichard Henderson tcg_gen_andi_i32(t0, t0, ~0xff);
925be8998e0SRichard Henderson tcg_gen_ext16s_i32(t1, src2);
926be8998e0SRichard Henderson tcg_gen_mul_i32(t0, t0, t1);
927be8998e0SRichard Henderson
928be8998e0SRichard Henderson tcg_gen_sextract_i32(t1, src1, 16, 16);
929be8998e0SRichard Henderson tcg_gen_andi_i32(t1, t1, ~0xff);
930be8998e0SRichard Henderson tcg_gen_sextract_i32(t2, src2, 16, 16);
931be8998e0SRichard Henderson tcg_gen_mul_i32(t1, t1, t2);
932be8998e0SRichard Henderson
933be8998e0SRichard Henderson tcg_gen_concat_i32_i64(dst, t0, t1);
934be8998e0SRichard Henderson }
935be8998e0SRichard Henderson
9367837185eSRichard Henderson #ifdef TARGET_SPARC64
gen_vec_fchksm16(unsigned vece,TCGv_vec dst,TCGv_vec src1,TCGv_vec src2)9377837185eSRichard Henderson static void gen_vec_fchksm16(unsigned vece, TCGv_vec dst,
9387837185eSRichard Henderson TCGv_vec src1, TCGv_vec src2)
9397837185eSRichard Henderson {
9407837185eSRichard Henderson TCGv_vec a = tcg_temp_new_vec_matching(dst);
9417837185eSRichard Henderson TCGv_vec c = tcg_temp_new_vec_matching(dst);
9427837185eSRichard Henderson
9437837185eSRichard Henderson tcg_gen_add_vec(vece, a, src1, src2);
9447837185eSRichard Henderson tcg_gen_cmp_vec(TCG_COND_LTU, vece, c, a, src1);
9457837185eSRichard Henderson /* Vector cmp produces -1 for true, so subtract to add carry. */
9467837185eSRichard Henderson tcg_gen_sub_vec(vece, dst, a, c);
9477837185eSRichard Henderson }
9487837185eSRichard Henderson
gen_op_fchksm16(unsigned vece,uint32_t dofs,uint32_t aofs,uint32_t bofs,uint32_t oprsz,uint32_t maxsz)9497837185eSRichard Henderson static void gen_op_fchksm16(unsigned vece, uint32_t dofs, uint32_t aofs,
9507837185eSRichard Henderson uint32_t bofs, uint32_t oprsz, uint32_t maxsz)
9517837185eSRichard Henderson {
9527837185eSRichard Henderson static const TCGOpcode vecop_list[] = {
9537837185eSRichard Henderson INDEX_op_cmp_vec, INDEX_op_add_vec, INDEX_op_sub_vec,
9547837185eSRichard Henderson };
9557837185eSRichard Henderson static const GVecGen3 op = {
9567837185eSRichard Henderson .fni8 = gen_helper_fchksm16,
9577837185eSRichard Henderson .fniv = gen_vec_fchksm16,
9587837185eSRichard Henderson .opt_opc = vecop_list,
9597837185eSRichard Henderson .vece = MO_16,
9607837185eSRichard Henderson };
9617837185eSRichard Henderson tcg_gen_gvec_3(dofs, aofs, bofs, oprsz, maxsz, &op);
9627837185eSRichard Henderson }
963d6ff1ccbSRichard Henderson
gen_vec_fmean16(unsigned vece,TCGv_vec dst,TCGv_vec src1,TCGv_vec src2)964d6ff1ccbSRichard Henderson static void gen_vec_fmean16(unsigned vece, TCGv_vec dst,
965d6ff1ccbSRichard Henderson TCGv_vec src1, TCGv_vec src2)
966d6ff1ccbSRichard Henderson {
967d6ff1ccbSRichard Henderson TCGv_vec t = tcg_temp_new_vec_matching(dst);
968d6ff1ccbSRichard Henderson
969d6ff1ccbSRichard Henderson tcg_gen_or_vec(vece, t, src1, src2);
970d6ff1ccbSRichard Henderson tcg_gen_and_vec(vece, t, t, tcg_constant_vec_matching(dst, vece, 1));
971d6ff1ccbSRichard Henderson tcg_gen_sari_vec(vece, src1, src1, 1);
972d6ff1ccbSRichard Henderson tcg_gen_sari_vec(vece, src2, src2, 1);
973d6ff1ccbSRichard Henderson tcg_gen_add_vec(vece, dst, src1, src2);
974d6ff1ccbSRichard Henderson tcg_gen_add_vec(vece, dst, dst, t);
975d6ff1ccbSRichard Henderson }
976d6ff1ccbSRichard Henderson
gen_op_fmean16(unsigned vece,uint32_t dofs,uint32_t aofs,uint32_t bofs,uint32_t oprsz,uint32_t maxsz)977d6ff1ccbSRichard Henderson static void gen_op_fmean16(unsigned vece, uint32_t dofs, uint32_t aofs,
978d6ff1ccbSRichard Henderson uint32_t bofs, uint32_t oprsz, uint32_t maxsz)
979d6ff1ccbSRichard Henderson {
980d6ff1ccbSRichard Henderson static const TCGOpcode vecop_list[] = {
981d6ff1ccbSRichard Henderson INDEX_op_add_vec, INDEX_op_sari_vec,
982d6ff1ccbSRichard Henderson };
983d6ff1ccbSRichard Henderson static const GVecGen3 op = {
984d6ff1ccbSRichard Henderson .fni8 = gen_helper_fmean16,
985d6ff1ccbSRichard Henderson .fniv = gen_vec_fmean16,
986d6ff1ccbSRichard Henderson .opt_opc = vecop_list,
987d6ff1ccbSRichard Henderson .vece = MO_16,
988d6ff1ccbSRichard Henderson };
989d6ff1ccbSRichard Henderson tcg_gen_gvec_3(dofs, aofs, bofs, oprsz, maxsz, &op);
990d6ff1ccbSRichard Henderson }
9917837185eSRichard Henderson #else
9927837185eSRichard Henderson #define gen_op_fchksm16 ({ qemu_build_not_reached(); NULL; })
993d6ff1ccbSRichard Henderson #define gen_op_fmean16 ({ qemu_build_not_reached(); NULL; })
9947837185eSRichard Henderson #endif
9957837185eSRichard Henderson
finishing_insn(DisasContext * dc)99689527e3aSRichard Henderson static void finishing_insn(DisasContext *dc)
99789527e3aSRichard Henderson {
99889527e3aSRichard Henderson /*
99989527e3aSRichard Henderson * From here, there is no future path through an unwinding exception.
100089527e3aSRichard Henderson * If the current insn cannot raise an exception, the computation of
100189527e3aSRichard Henderson * cpu_cond may be able to be elided.
100289527e3aSRichard Henderson */
100389527e3aSRichard Henderson if (dc->cpu_cond_live) {
100489527e3aSRichard Henderson tcg_gen_discard_tl(cpu_cond);
100589527e3aSRichard Henderson dc->cpu_cond_live = false;
100689527e3aSRichard Henderson }
100789527e3aSRichard Henderson }
100889527e3aSRichard Henderson
gen_generic_branch(DisasContext * dc)10090c2e96c1SRichard Henderson static void gen_generic_branch(DisasContext *dc)
1010fcf5ef2aSThomas Huth {
101100ab7e61SRichard Henderson TCGv npc0 = tcg_constant_tl(dc->jump_pc[0]);
101200ab7e61SRichard Henderson TCGv npc1 = tcg_constant_tl(dc->jump_pc[1]);
1013533f042fSRichard Henderson TCGv c2 = tcg_constant_tl(dc->jump.c2);
1014fcf5ef2aSThomas Huth
1015533f042fSRichard Henderson tcg_gen_movcond_tl(dc->jump.cond, cpu_npc, dc->jump.c1, c2, npc0, npc1);
1016fcf5ef2aSThomas Huth }
1017fcf5ef2aSThomas Huth
1018fcf5ef2aSThomas Huth /* call this function before using the condition register as it may
1019fcf5ef2aSThomas Huth have been set for a jump */
flush_cond(DisasContext * dc)10200c2e96c1SRichard Henderson static void flush_cond(DisasContext *dc)
1021fcf5ef2aSThomas Huth {
1022fcf5ef2aSThomas Huth if (dc->npc == JUMP_PC) {
1023fcf5ef2aSThomas Huth gen_generic_branch(dc);
102499c82c47SRichard Henderson dc->npc = DYNAMIC_PC_LOOKUP;
1025fcf5ef2aSThomas Huth }
1026fcf5ef2aSThomas Huth }
1027fcf5ef2aSThomas Huth
save_npc(DisasContext * dc)10280c2e96c1SRichard Henderson static void save_npc(DisasContext *dc)
1029fcf5ef2aSThomas Huth {
1030633c4283SRichard Henderson if (dc->npc & 3) {
1031633c4283SRichard Henderson switch (dc->npc) {
1032633c4283SRichard Henderson case JUMP_PC:
1033fcf5ef2aSThomas Huth gen_generic_branch(dc);
103499c82c47SRichard Henderson dc->npc = DYNAMIC_PC_LOOKUP;
1035633c4283SRichard Henderson break;
1036633c4283SRichard Henderson case DYNAMIC_PC:
1037633c4283SRichard Henderson case DYNAMIC_PC_LOOKUP:
1038633c4283SRichard Henderson break;
1039633c4283SRichard Henderson default:
1040633c4283SRichard Henderson g_assert_not_reached();
1041633c4283SRichard Henderson }
1042633c4283SRichard Henderson } else {
1043fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_npc, dc->npc);
1044fcf5ef2aSThomas Huth }
1045fcf5ef2aSThomas Huth }
1046fcf5ef2aSThomas Huth
save_state(DisasContext * dc)10470c2e96c1SRichard Henderson static void save_state(DisasContext *dc)
1048fcf5ef2aSThomas Huth {
1049fcf5ef2aSThomas Huth tcg_gen_movi_tl(cpu_pc, dc->pc);
1050fcf5ef2aSThomas Huth save_npc(dc);
1051fcf5ef2aSThomas Huth }
1052fcf5ef2aSThomas Huth
gen_exception(DisasContext * dc,int which)1053fcf5ef2aSThomas Huth static void gen_exception(DisasContext *dc, int which)
1054fcf5ef2aSThomas Huth {
105589527e3aSRichard Henderson finishing_insn(dc);
1056fcf5ef2aSThomas Huth save_state(dc);
1057ad75a51eSRichard Henderson gen_helper_raise_exception(tcg_env, tcg_constant_i32(which));
1058af00be49SEmilio G. Cota dc->base.is_jmp = DISAS_NORETURN;
1059fcf5ef2aSThomas Huth }
1060fcf5ef2aSThomas Huth
delay_exceptionv(DisasContext * dc,TCGv_i32 excp)1061186e7890SRichard Henderson static TCGLabel *delay_exceptionv(DisasContext *dc, TCGv_i32 excp)
1062fcf5ef2aSThomas Huth {
1063186e7890SRichard Henderson DisasDelayException *e = g_new0(DisasDelayException, 1);
1064186e7890SRichard Henderson
1065186e7890SRichard Henderson e->next = dc->delay_excp_list;
1066186e7890SRichard Henderson dc->delay_excp_list = e;
1067186e7890SRichard Henderson
1068186e7890SRichard Henderson e->lab = gen_new_label();
1069186e7890SRichard Henderson e->excp = excp;
1070186e7890SRichard Henderson e->pc = dc->pc;
1071186e7890SRichard Henderson /* Caller must have used flush_cond before branch. */
1072186e7890SRichard Henderson assert(e->npc != JUMP_PC);
1073186e7890SRichard Henderson e->npc = dc->npc;
1074186e7890SRichard Henderson
1075186e7890SRichard Henderson return e->lab;
1076186e7890SRichard Henderson }
1077186e7890SRichard Henderson
delay_exception(DisasContext * dc,int excp)1078186e7890SRichard Henderson static TCGLabel *delay_exception(DisasContext *dc, int excp)
1079186e7890SRichard Henderson {
1080186e7890SRichard Henderson return delay_exceptionv(dc, tcg_constant_i32(excp));
1081186e7890SRichard Henderson }
1082186e7890SRichard Henderson
gen_check_align(DisasContext * dc,TCGv addr,int mask)1083186e7890SRichard Henderson static void gen_check_align(DisasContext *dc, TCGv addr, int mask)
1084186e7890SRichard Henderson {
1085186e7890SRichard Henderson TCGv t = tcg_temp_new();
1086186e7890SRichard Henderson TCGLabel *lab;
1087186e7890SRichard Henderson
1088186e7890SRichard Henderson tcg_gen_andi_tl(t, addr, mask);
1089186e7890SRichard Henderson
1090186e7890SRichard Henderson flush_cond(dc);
1091186e7890SRichard Henderson lab = delay_exception(dc, TT_UNALIGNED);
1092186e7890SRichard Henderson tcg_gen_brcondi_tl(TCG_COND_NE, t, 0, lab);
1093fcf5ef2aSThomas Huth }
1094fcf5ef2aSThomas Huth
gen_mov_pc_npc(DisasContext * dc)10950c2e96c1SRichard Henderson static void gen_mov_pc_npc(DisasContext *dc)
1096fcf5ef2aSThomas Huth {
109789527e3aSRichard Henderson finishing_insn(dc);
109889527e3aSRichard Henderson
1099633c4283SRichard Henderson if (dc->npc & 3) {
1100633c4283SRichard Henderson switch (dc->npc) {
1101633c4283SRichard Henderson case JUMP_PC:
1102fcf5ef2aSThomas Huth gen_generic_branch(dc);
1103fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_pc, cpu_npc);
110499c82c47SRichard Henderson dc->pc = DYNAMIC_PC_LOOKUP;
1105633c4283SRichard Henderson break;
1106633c4283SRichard Henderson case DYNAMIC_PC:
1107633c4283SRichard Henderson case DYNAMIC_PC_LOOKUP:
1108fcf5ef2aSThomas Huth tcg_gen_mov_tl(cpu_pc, cpu_npc);
1109633c4283SRichard Henderson dc->pc = dc->npc;
1110633c4283SRichard Henderson break;
1111633c4283SRichard Henderson default:
1112633c4283SRichard Henderson g_assert_not_reached();
1113633c4283SRichard Henderson }
1114fcf5ef2aSThomas Huth } else {
1115fcf5ef2aSThomas Huth dc->pc = dc->npc;
1116fcf5ef2aSThomas Huth }
1117fcf5ef2aSThomas Huth }
1118fcf5ef2aSThomas Huth
gen_compare(DisasCompare * cmp,bool xcc,unsigned int cond,DisasContext * dc)1119fcf5ef2aSThomas Huth static void gen_compare(DisasCompare *cmp, bool xcc, unsigned int cond,
1120fcf5ef2aSThomas Huth DisasContext *dc)
1121fcf5ef2aSThomas Huth {
1122b597eedcSRichard Henderson TCGv t1;
1123fcf5ef2aSThomas Huth
11242a1905c7SRichard Henderson cmp->c1 = t1 = tcg_temp_new();
1125c8507ebfSRichard Henderson cmp->c2 = 0;
11262a1905c7SRichard Henderson
11272a1905c7SRichard Henderson switch (cond & 7) {
11282a1905c7SRichard Henderson case 0x0: /* never */
11292a1905c7SRichard Henderson cmp->cond = TCG_COND_NEVER;
1130c8507ebfSRichard Henderson cmp->c1 = tcg_constant_tl(0);
1131fcf5ef2aSThomas Huth break;
11322a1905c7SRichard Henderson
11332a1905c7SRichard Henderson case 0x1: /* eq: Z */
11342a1905c7SRichard Henderson cmp->cond = TCG_COND_EQ;
11352a1905c7SRichard Henderson if (TARGET_LONG_BITS == 32 || xcc) {
11362a1905c7SRichard Henderson tcg_gen_mov_tl(t1, cpu_cc_Z);
11372a1905c7SRichard Henderson } else {
11382a1905c7SRichard Henderson tcg_gen_ext32u_tl(t1, cpu_icc_Z);
11392a1905c7SRichard Henderson }
11402a1905c7SRichard Henderson break;
11412a1905c7SRichard Henderson
11422a1905c7SRichard Henderson case 0x2: /* le: Z | (N ^ V) */
11432a1905c7SRichard Henderson /*
11442a1905c7SRichard Henderson * Simplify:
11452a1905c7SRichard Henderson * cc_Z || (N ^ V) < 0 NE
11462a1905c7SRichard Henderson * cc_Z && !((N ^ V) < 0) EQ
11472a1905c7SRichard Henderson * cc_Z & ~((N ^ V) >> TLB) EQ
11482a1905c7SRichard Henderson */
11492a1905c7SRichard Henderson cmp->cond = TCG_COND_EQ;
11502a1905c7SRichard Henderson tcg_gen_xor_tl(t1, cpu_cc_N, cpu_cc_V);
11512a1905c7SRichard Henderson tcg_gen_sextract_tl(t1, t1, xcc ? 63 : 31, 1);
11522a1905c7SRichard Henderson tcg_gen_andc_tl(t1, xcc ? cpu_cc_Z : cpu_icc_Z, t1);
11532a1905c7SRichard Henderson if (TARGET_LONG_BITS == 64 && !xcc) {
11542a1905c7SRichard Henderson tcg_gen_ext32u_tl(t1, t1);
11552a1905c7SRichard Henderson }
11562a1905c7SRichard Henderson break;
11572a1905c7SRichard Henderson
11582a1905c7SRichard Henderson case 0x3: /* lt: N ^ V */
11592a1905c7SRichard Henderson cmp->cond = TCG_COND_LT;
11602a1905c7SRichard Henderson tcg_gen_xor_tl(t1, cpu_cc_N, cpu_cc_V);
11612a1905c7SRichard Henderson if (TARGET_LONG_BITS == 64 && !xcc) {
11622a1905c7SRichard Henderson tcg_gen_ext32s_tl(t1, t1);
11632a1905c7SRichard Henderson }
11642a1905c7SRichard Henderson break;
11652a1905c7SRichard Henderson
11662a1905c7SRichard Henderson case 0x4: /* leu: Z | C */
11672a1905c7SRichard Henderson /*
11682a1905c7SRichard Henderson * Simplify:
11692a1905c7SRichard Henderson * cc_Z == 0 || cc_C != 0 NE
11702a1905c7SRichard Henderson * cc_Z != 0 && cc_C == 0 EQ
11712a1905c7SRichard Henderson * cc_Z & (cc_C ? 0 : -1) EQ
11722a1905c7SRichard Henderson * cc_Z & (cc_C - 1) EQ
11732a1905c7SRichard Henderson */
11742a1905c7SRichard Henderson cmp->cond = TCG_COND_EQ;
11752a1905c7SRichard Henderson if (TARGET_LONG_BITS == 32 || xcc) {
11762a1905c7SRichard Henderson tcg_gen_subi_tl(t1, cpu_cc_C, 1);
11772a1905c7SRichard Henderson tcg_gen_and_tl(t1, t1, cpu_cc_Z);
11782a1905c7SRichard Henderson } else {
11792a1905c7SRichard Henderson tcg_gen_extract_tl(t1, cpu_icc_C, 32, 1);
11802a1905c7SRichard Henderson tcg_gen_subi_tl(t1, t1, 1);
11812a1905c7SRichard Henderson tcg_gen_and_tl(t1, t1, cpu_icc_Z);
11822a1905c7SRichard Henderson tcg_gen_ext32u_tl(t1, t1);
11832a1905c7SRichard Henderson }
11842a1905c7SRichard Henderson break;
11852a1905c7SRichard Henderson
11862a1905c7SRichard Henderson case 0x5: /* ltu: C */
11872a1905c7SRichard Henderson cmp->cond = TCG_COND_NE;
11882a1905c7SRichard Henderson if (TARGET_LONG_BITS == 32 || xcc) {
11892a1905c7SRichard Henderson tcg_gen_mov_tl(t1, cpu_cc_C);
11902a1905c7SRichard Henderson } else {
11912a1905c7SRichard Henderson tcg_gen_extract_tl(t1, cpu_icc_C, 32, 1);
11922a1905c7SRichard Henderson }
11932a1905c7SRichard Henderson break;
11942a1905c7SRichard Henderson
11952a1905c7SRichard Henderson case 0x6: /* neg: N */
11962a1905c7SRichard Henderson cmp->cond = TCG_COND_LT;
11972a1905c7SRichard Henderson if (TARGET_LONG_BITS == 32 || xcc) {
11982a1905c7SRichard Henderson tcg_gen_mov_tl(t1, cpu_cc_N);
11992a1905c7SRichard Henderson } else {
12002a1905c7SRichard Henderson tcg_gen_ext32s_tl(t1, cpu_cc_N);
12012a1905c7SRichard Henderson }
12022a1905c7SRichard Henderson break;
12032a1905c7SRichard Henderson
12042a1905c7SRichard Henderson case 0x7: /* vs: V */
12052a1905c7SRichard Henderson cmp->cond = TCG_COND_LT;
12062a1905c7SRichard Henderson if (TARGET_LONG_BITS == 32 || xcc) {
12072a1905c7SRichard Henderson tcg_gen_mov_tl(t1, cpu_cc_V);
12082a1905c7SRichard Henderson } else {
12092a1905c7SRichard Henderson tcg_gen_ext32s_tl(t1, cpu_cc_V);
12102a1905c7SRichard Henderson }
12112a1905c7SRichard Henderson break;
12122a1905c7SRichard Henderson }
12132a1905c7SRichard Henderson if (cond & 8) {
12142a1905c7SRichard Henderson cmp->cond = tcg_invert_cond(cmp->cond);
1215fcf5ef2aSThomas Huth }
1216fcf5ef2aSThomas Huth }
1217fcf5ef2aSThomas Huth
gen_fcompare(DisasCompare * cmp,unsigned int cc,unsigned int cond)1218fcf5ef2aSThomas Huth static void gen_fcompare(DisasCompare *cmp, unsigned int cc, unsigned int cond)
1219fcf5ef2aSThomas Huth {
1220d8c5b92fSRichard Henderson TCGv_i32 fcc = cpu_fcc[cc];
1221d8c5b92fSRichard Henderson TCGv_i32 c1 = fcc;
1222d8c5b92fSRichard Henderson int c2 = 0;
1223d8c5b92fSRichard Henderson TCGCond tcond;
1224fcf5ef2aSThomas Huth
1225d8c5b92fSRichard Henderson /*
1226d8c5b92fSRichard Henderson * FCC values:
1227d8c5b92fSRichard Henderson * 0 =
1228d8c5b92fSRichard Henderson * 1 <
1229d8c5b92fSRichard Henderson * 2 >
1230d8c5b92fSRichard Henderson * 3 unordered
1231d8c5b92fSRichard Henderson */
1232d8c5b92fSRichard Henderson switch (cond & 7) {
1233d8c5b92fSRichard Henderson case 0x0: /* fbn */
1234d8c5b92fSRichard Henderson tcond = TCG_COND_NEVER;
1235fcf5ef2aSThomas Huth break;
1236d8c5b92fSRichard Henderson case 0x1: /* fbne : !0 */
1237d8c5b92fSRichard Henderson tcond = TCG_COND_NE;
1238fcf5ef2aSThomas Huth break;
1239d8c5b92fSRichard Henderson case 0x2: /* fblg : 1 or 2 */
1240d8c5b92fSRichard Henderson /* fcc in {1,2} - 1 -> fcc in {0,1} */
1241d8c5b92fSRichard Henderson c1 = tcg_temp_new_i32();
1242d8c5b92fSRichard Henderson tcg_gen_addi_i32(c1, fcc, -1);
1243d8c5b92fSRichard Henderson c2 = 1;
1244d8c5b92fSRichard Henderson tcond = TCG_COND_LEU;
1245fcf5ef2aSThomas Huth break;
1246d8c5b92fSRichard Henderson case 0x3: /* fbul : 1 or 3 */
1247d8c5b92fSRichard Henderson c1 = tcg_temp_new_i32();
1248d8c5b92fSRichard Henderson tcg_gen_andi_i32(c1, fcc, 1);
1249d8c5b92fSRichard Henderson tcond = TCG_COND_NE;
1250d8c5b92fSRichard Henderson break;
1251d8c5b92fSRichard Henderson case 0x4: /* fbl : 1 */
1252d8c5b92fSRichard Henderson c2 = 1;
1253d8c5b92fSRichard Henderson tcond = TCG_COND_EQ;
1254d8c5b92fSRichard Henderson break;
1255d8c5b92fSRichard Henderson case 0x5: /* fbug : 2 or 3 */
1256d8c5b92fSRichard Henderson c2 = 2;
1257d8c5b92fSRichard Henderson tcond = TCG_COND_GEU;
1258d8c5b92fSRichard Henderson break;
1259d8c5b92fSRichard Henderson case 0x6: /* fbg : 2 */
1260d8c5b92fSRichard Henderson c2 = 2;
1261d8c5b92fSRichard Henderson tcond = TCG_COND_EQ;
1262d8c5b92fSRichard Henderson break;
1263d8c5b92fSRichard Henderson case 0x7: /* fbu : 3 */
1264d8c5b92fSRichard Henderson c2 = 3;
1265d8c5b92fSRichard Henderson tcond = TCG_COND_EQ;
1266fcf5ef2aSThomas Huth break;
1267fcf5ef2aSThomas Huth }
1268d8c5b92fSRichard Henderson if (cond & 8) {
1269d8c5b92fSRichard Henderson tcond = tcg_invert_cond(tcond);
1270fcf5ef2aSThomas Huth }
1271d8c5b92fSRichard Henderson
1272d8c5b92fSRichard Henderson cmp->cond = tcond;
1273d8c5b92fSRichard Henderson cmp->c2 = c2;
1274d8c5b92fSRichard Henderson cmp->c1 = tcg_temp_new();
1275d8c5b92fSRichard Henderson tcg_gen_extu_i32_tl(cmp->c1, c1);
1276fcf5ef2aSThomas Huth }
1277fcf5ef2aSThomas Huth
gen_compare_reg(DisasCompare * cmp,int cond,TCGv r_src)12782c4f56c9SRichard Henderson static bool gen_compare_reg(DisasCompare *cmp, int cond, TCGv r_src)
12792c4f56c9SRichard Henderson {
12802c4f56c9SRichard Henderson static const TCGCond cond_reg[4] = {
1281ab9ffe98SRichard Henderson TCG_COND_NEVER, /* reserved */
1282fcf5ef2aSThomas Huth TCG_COND_EQ,
1283fcf5ef2aSThomas Huth TCG_COND_LE,
1284fcf5ef2aSThomas Huth TCG_COND_LT,
1285fcf5ef2aSThomas Huth };
12862c4f56c9SRichard Henderson TCGCond tcond;
1287fcf5ef2aSThomas Huth
12882c4f56c9SRichard Henderson if ((cond & 3) == 0) {
12892c4f56c9SRichard Henderson return false;
12902c4f56c9SRichard Henderson }
12912c4f56c9SRichard Henderson tcond = cond_reg[cond & 3];
12922c4f56c9SRichard Henderson if (cond & 4) {
12932c4f56c9SRichard Henderson tcond = tcg_invert_cond(tcond);
12942c4f56c9SRichard Henderson }
12952c4f56c9SRichard Henderson
12962c4f56c9SRichard Henderson cmp->cond = tcond;
1297816f89b7SRichard Henderson cmp->c1 = tcg_temp_new();
1298c8507ebfSRichard Henderson cmp->c2 = 0;
1299816f89b7SRichard Henderson tcg_gen_mov_tl(cmp->c1, r_src);
13002c4f56c9SRichard Henderson return true;
1301fcf5ef2aSThomas Huth }
1302fcf5ef2aSThomas Huth
gen_op_clear_ieee_excp_and_FTT(void)1303baf3dbf2SRichard Henderson static void gen_op_clear_ieee_excp_and_FTT(void)
1304baf3dbf2SRichard Henderson {
13053590f01eSRichard Henderson tcg_gen_st_i32(tcg_constant_i32(0), tcg_env,
13063590f01eSRichard Henderson offsetof(CPUSPARCState, fsr_cexc_ftt));
1307baf3dbf2SRichard Henderson }
1308baf3dbf2SRichard Henderson
gen_op_fmovs(TCGv_i32 dst,TCGv_i32 src)1309baf3dbf2SRichard Henderson static void gen_op_fmovs(TCGv_i32 dst, TCGv_i32 src)
1310baf3dbf2SRichard Henderson {
1311baf3dbf2SRichard Henderson gen_op_clear_ieee_excp_and_FTT();
1312baf3dbf2SRichard Henderson tcg_gen_mov_i32(dst, src);
1313baf3dbf2SRichard Henderson }
1314baf3dbf2SRichard Henderson
gen_op_fnegs(TCGv_i32 dst,TCGv_i32 src)1315baf3dbf2SRichard Henderson static void gen_op_fnegs(TCGv_i32 dst, TCGv_i32 src)
1316baf3dbf2SRichard Henderson {
1317baf3dbf2SRichard Henderson gen_op_clear_ieee_excp_and_FTT();
1318daf457d4SRichard Henderson tcg_gen_xori_i32(dst, src, 1u << 31);
1319baf3dbf2SRichard Henderson }
1320baf3dbf2SRichard Henderson
gen_op_fabss(TCGv_i32 dst,TCGv_i32 src)1321baf3dbf2SRichard Henderson static void gen_op_fabss(TCGv_i32 dst, TCGv_i32 src)
1322baf3dbf2SRichard Henderson {
1323baf3dbf2SRichard Henderson gen_op_clear_ieee_excp_and_FTT();
1324daf457d4SRichard Henderson tcg_gen_andi_i32(dst, src, ~(1u << 31));
1325baf3dbf2SRichard Henderson }
1326baf3dbf2SRichard Henderson
gen_op_fmovd(TCGv_i64 dst,TCGv_i64 src)1327c6d83e4fSRichard Henderson static void gen_op_fmovd(TCGv_i64 dst, TCGv_i64 src)
1328c6d83e4fSRichard Henderson {
1329c6d83e4fSRichard Henderson gen_op_clear_ieee_excp_and_FTT();
1330c6d83e4fSRichard Henderson tcg_gen_mov_i64(dst, src);
1331c6d83e4fSRichard Henderson }
1332c6d83e4fSRichard Henderson
gen_op_fnegd(TCGv_i64 dst,TCGv_i64 src)1333c6d83e4fSRichard Henderson static void gen_op_fnegd(TCGv_i64 dst, TCGv_i64 src)
1334c6d83e4fSRichard Henderson {
1335c6d83e4fSRichard Henderson gen_op_clear_ieee_excp_and_FTT();
1336daf457d4SRichard Henderson tcg_gen_xori_i64(dst, src, 1ull << 63);
1337c6d83e4fSRichard Henderson }
1338c6d83e4fSRichard Henderson
gen_op_fabsd(TCGv_i64 dst,TCGv_i64 src)1339c6d83e4fSRichard Henderson static void gen_op_fabsd(TCGv_i64 dst, TCGv_i64 src)
1340c6d83e4fSRichard Henderson {
1341c6d83e4fSRichard Henderson gen_op_clear_ieee_excp_and_FTT();
1342daf457d4SRichard Henderson tcg_gen_andi_i64(dst, src, ~(1ull << 63));
1343daf457d4SRichard Henderson }
1344daf457d4SRichard Henderson
gen_op_fnegq(TCGv_i128 dst,TCGv_i128 src)1345daf457d4SRichard Henderson static void gen_op_fnegq(TCGv_i128 dst, TCGv_i128 src)
1346daf457d4SRichard Henderson {
1347daf457d4SRichard Henderson TCGv_i64 l = tcg_temp_new_i64();
1348daf457d4SRichard Henderson TCGv_i64 h = tcg_temp_new_i64();
1349daf457d4SRichard Henderson
1350daf457d4SRichard Henderson tcg_gen_extr_i128_i64(l, h, src);
1351daf457d4SRichard Henderson tcg_gen_xori_i64(h, h, 1ull << 63);
1352daf457d4SRichard Henderson tcg_gen_concat_i64_i128(dst, l, h);
1353daf457d4SRichard Henderson }
1354daf457d4SRichard Henderson
gen_op_fabsq(TCGv_i128 dst,TCGv_i128 src)1355daf457d4SRichard Henderson static void gen_op_fabsq(TCGv_i128 dst, TCGv_i128 src)
1356daf457d4SRichard Henderson {
1357daf457d4SRichard Henderson TCGv_i64 l = tcg_temp_new_i64();
1358daf457d4SRichard Henderson TCGv_i64 h = tcg_temp_new_i64();
1359daf457d4SRichard Henderson
1360daf457d4SRichard Henderson tcg_gen_extr_i128_i64(l, h, src);
1361daf457d4SRichard Henderson tcg_gen_andi_i64(h, h, ~(1ull << 63));
1362daf457d4SRichard Henderson tcg_gen_concat_i64_i128(dst, l, h);
1363c6d83e4fSRichard Henderson }
1364c6d83e4fSRichard Henderson
gen_op_fmadds(TCGv_i32 d,TCGv_i32 s1,TCGv_i32 s2,TCGv_i32 s3)13654fd71d19SRichard Henderson static void gen_op_fmadds(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2, TCGv_i32 s3)
13664fd71d19SRichard Henderson {
13674fd71d19SRichard Henderson gen_helper_fmadds(d, tcg_env, s1, s2, s3, tcg_constant_i32(0));
13684fd71d19SRichard Henderson }
13694fd71d19SRichard Henderson
gen_op_fmaddd(TCGv_i64 d,TCGv_i64 s1,TCGv_i64 s2,TCGv_i64 s3)13704fd71d19SRichard Henderson static void gen_op_fmaddd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2, TCGv_i64 s3)
13714fd71d19SRichard Henderson {
13724fd71d19SRichard Henderson gen_helper_fmaddd(d, tcg_env, s1, s2, s3, tcg_constant_i32(0));
13734fd71d19SRichard Henderson }
13744fd71d19SRichard Henderson
gen_op_fmsubs(TCGv_i32 d,TCGv_i32 s1,TCGv_i32 s2,TCGv_i32 s3)13754fd71d19SRichard Henderson static void gen_op_fmsubs(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2, TCGv_i32 s3)
13764fd71d19SRichard Henderson {
13774fd71d19SRichard Henderson int op = float_muladd_negate_c;
13784fd71d19SRichard Henderson gen_helper_fmadds(d, tcg_env, s1, s2, s3, tcg_constant_i32(op));
13794fd71d19SRichard Henderson }
13804fd71d19SRichard Henderson
gen_op_fmsubd(TCGv_i64 d,TCGv_i64 s1,TCGv_i64 s2,TCGv_i64 s3)13814fd71d19SRichard Henderson static void gen_op_fmsubd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2, TCGv_i64 s3)
13824fd71d19SRichard Henderson {
13834fd71d19SRichard Henderson int op = float_muladd_negate_c;
13844fd71d19SRichard Henderson gen_helper_fmaddd(d, tcg_env, s1, s2, s3, tcg_constant_i32(op));
13854fd71d19SRichard Henderson }
13864fd71d19SRichard Henderson
gen_op_fnmsubs(TCGv_i32 d,TCGv_i32 s1,TCGv_i32 s2,TCGv_i32 s3)13874fd71d19SRichard Henderson static void gen_op_fnmsubs(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2, TCGv_i32 s3)
13884fd71d19SRichard Henderson {
13894fd71d19SRichard Henderson int op = float_muladd_negate_c | float_muladd_negate_result;
13904fd71d19SRichard Henderson gen_helper_fmadds(d, tcg_env, s1, s2, s3, tcg_constant_i32(op));
13914fd71d19SRichard Henderson }
13924fd71d19SRichard Henderson
gen_op_fnmsubd(TCGv_i64 d,TCGv_i64 s1,TCGv_i64 s2,TCGv_i64 s3)13934fd71d19SRichard Henderson static void gen_op_fnmsubd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2, TCGv_i64 s3)
13944fd71d19SRichard Henderson {
13954fd71d19SRichard Henderson int op = float_muladd_negate_c | float_muladd_negate_result;
13964fd71d19SRichard Henderson gen_helper_fmaddd(d, tcg_env, s1, s2, s3, tcg_constant_i32(op));
13974fd71d19SRichard Henderson }
13984fd71d19SRichard Henderson
gen_op_fnmadds(TCGv_i32 d,TCGv_i32 s1,TCGv_i32 s2,TCGv_i32 s3)13994fd71d19SRichard Henderson static void gen_op_fnmadds(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2, TCGv_i32 s3)
14004fd71d19SRichard Henderson {
14014fd71d19SRichard Henderson int op = float_muladd_negate_result;
14024fd71d19SRichard Henderson gen_helper_fmadds(d, tcg_env, s1, s2, s3, tcg_constant_i32(op));
14034fd71d19SRichard Henderson }
14044fd71d19SRichard Henderson
gen_op_fnmaddd(TCGv_i64 d,TCGv_i64 s1,TCGv_i64 s2,TCGv_i64 s3)14054fd71d19SRichard Henderson static void gen_op_fnmaddd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2, TCGv_i64 s3)
14064fd71d19SRichard Henderson {
14074fd71d19SRichard Henderson int op = float_muladd_negate_result;
14084fd71d19SRichard Henderson gen_helper_fmaddd(d, tcg_env, s1, s2, s3, tcg_constant_i32(op));
14094fd71d19SRichard Henderson }
14104fd71d19SRichard Henderson
14113d50b728SRichard Henderson /* Use muladd to compute (1 * src1) + src2 / 2 with one rounding. */
gen_op_fhadds(TCGv_i32 d,TCGv_i32 s1,TCGv_i32 s2)14123d50b728SRichard Henderson static void gen_op_fhadds(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2)
14133d50b728SRichard Henderson {
14143d50b728SRichard Henderson TCGv_i32 one = tcg_constant_i32(float32_one);
14153d50b728SRichard Henderson int op = float_muladd_halve_result;
14163d50b728SRichard Henderson gen_helper_fmadds(d, tcg_env, one, s1, s2, tcg_constant_i32(op));
14173d50b728SRichard Henderson }
14183d50b728SRichard Henderson
gen_op_fhaddd(TCGv_i64 d,TCGv_i64 s1,TCGv_i64 s2)14193d50b728SRichard Henderson static void gen_op_fhaddd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2)
14203d50b728SRichard Henderson {
14213d50b728SRichard Henderson TCGv_i64 one = tcg_constant_i64(float64_one);
14223d50b728SRichard Henderson int op = float_muladd_halve_result;
14233d50b728SRichard Henderson gen_helper_fmaddd(d, tcg_env, one, s1, s2, tcg_constant_i32(op));
14243d50b728SRichard Henderson }
14253d50b728SRichard Henderson
14263d50b728SRichard Henderson /* Use muladd to compute (1 * src1) - src2 / 2 with one rounding. */
gen_op_fhsubs(TCGv_i32 d,TCGv_i32 s1,TCGv_i32 s2)14273d50b728SRichard Henderson static void gen_op_fhsubs(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2)
14283d50b728SRichard Henderson {
14293d50b728SRichard Henderson TCGv_i32 one = tcg_constant_i32(float32_one);
14303d50b728SRichard Henderson int op = float_muladd_negate_c | float_muladd_halve_result;
14313d50b728SRichard Henderson gen_helper_fmadds(d, tcg_env, one, s1, s2, tcg_constant_i32(op));
14323d50b728SRichard Henderson }
14333d50b728SRichard Henderson
gen_op_fhsubd(TCGv_i64 d,TCGv_i64 s1,TCGv_i64 s2)14343d50b728SRichard Henderson static void gen_op_fhsubd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2)
14353d50b728SRichard Henderson {
14363d50b728SRichard Henderson TCGv_i64 one = tcg_constant_i64(float64_one);
14373d50b728SRichard Henderson int op = float_muladd_negate_c | float_muladd_halve_result;
14383d50b728SRichard Henderson gen_helper_fmaddd(d, tcg_env, one, s1, s2, tcg_constant_i32(op));
14393d50b728SRichard Henderson }
14403d50b728SRichard Henderson
14413d50b728SRichard Henderson /* Use muladd to compute -((1 * src1) + src2 / 2) with one rounding. */
gen_op_fnhadds(TCGv_i32 d,TCGv_i32 s1,TCGv_i32 s2)14423d50b728SRichard Henderson static void gen_op_fnhadds(TCGv_i32 d, TCGv_i32 s1, TCGv_i32 s2)
14433d50b728SRichard Henderson {
14443d50b728SRichard Henderson TCGv_i32 one = tcg_constant_i32(float32_one);
14453d50b728SRichard Henderson int op = float_muladd_negate_result | float_muladd_halve_result;
14463d50b728SRichard Henderson gen_helper_fmadds(d, tcg_env, one, s1, s2, tcg_constant_i32(op));
14473d50b728SRichard Henderson }
14483d50b728SRichard Henderson
gen_op_fnhaddd(TCGv_i64 d,TCGv_i64 s1,TCGv_i64 s2)14493d50b728SRichard Henderson static void gen_op_fnhaddd(TCGv_i64 d, TCGv_i64 s1, TCGv_i64 s2)
14503d50b728SRichard Henderson {
14513d50b728SRichard Henderson TCGv_i64 one = tcg_constant_i64(float64_one);
14523d50b728SRichard Henderson int op = float_muladd_negate_result | float_muladd_halve_result;
14533d50b728SRichard Henderson gen_helper_fmaddd(d, tcg_env, one, s1, s2, tcg_constant_i32(op));
14543d50b728SRichard Henderson }
14553d50b728SRichard Henderson
gen_op_fpexception_im(DisasContext * dc,int ftt)14563590f01eSRichard Henderson static void gen_op_fpexception_im(DisasContext *dc, int ftt)
1457fcf5ef2aSThomas Huth {
14583590f01eSRichard Henderson /*
14593590f01eSRichard Henderson * CEXC is only set when succesfully completing an FPop,
14603590f01eSRichard Henderson * or when raising FSR_FTT_IEEE_EXCP, i.e. check_ieee_exception.
14613590f01eSRichard Henderson * Thus we can simply store FTT into this field.
14623590f01eSRichard Henderson */
14633590f01eSRichard Henderson tcg_gen_st_i32(tcg_constant_i32(ftt), tcg_env,
14643590f01eSRichard Henderson offsetof(CPUSPARCState, fsr_cexc_ftt));
1465fcf5ef2aSThomas Huth gen_exception(dc, TT_FP_EXCP);
1466fcf5ef2aSThomas Huth }
1467fcf5ef2aSThomas Huth
gen_trap_ifnofpu(DisasContext * dc)1468*d2a0c3a7SRichard Henderson static bool gen_trap_ifnofpu(DisasContext *dc)
1469fcf5ef2aSThomas Huth {
1470fcf5ef2aSThomas Huth #if !defined(CONFIG_USER_ONLY)
1471fcf5ef2aSThomas Huth if (!dc->fpu_enabled) {
1472fcf5ef2aSThomas Huth gen_exception(dc, TT_NFPU_INSN);
1473*d2a0c3a7SRichard Henderson return true;
1474fcf5ef2aSThomas Huth }
1475fcf5ef2aSThomas Huth #endif
1476*d2a0c3a7SRichard Henderson return false;
1477*d2a0c3a7SRichard Henderson }
1478*d2a0c3a7SRichard Henderson
gen_trap_iffpexception(DisasContext * dc)1479*d2a0c3a7SRichard Henderson static bool gen_trap_iffpexception(DisasContext *dc)
1480*d2a0c3a7SRichard Henderson {
1481*d2a0c3a7SRichard Henderson #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY)
1482*d2a0c3a7SRichard Henderson /*
1483*d2a0c3a7SRichard Henderson * There are 3 states for the sparc32 fpu:
1484*d2a0c3a7SRichard Henderson * Normally the fpu is in fp_execute, and all insns are allowed.
1485*d2a0c3a7SRichard Henderson * When an exception is signaled, it moves to fp_exception_pending state.
1486*d2a0c3a7SRichard Henderson * Upon seeing the next FPop, the fpu moves to fp_exception state,
1487*d2a0c3a7SRichard Henderson * populates the FQ, and generates an fp_exception trap.
1488*d2a0c3a7SRichard Henderson * The fpu remains in fp_exception state until FQ becomes empty
1489*d2a0c3a7SRichard Henderson * after execution of a STDFQ instruction. While the fpu is in
1490*d2a0c3a7SRichard Henderson * fp_exception state, and FPop, fp load or fp branch insn will
1491*d2a0c3a7SRichard Henderson * return to fp_exception_pending state, set FSR.FTT to sequence_error,
1492*d2a0c3a7SRichard Henderson * and the insn will not be entered into the FQ.
1493*d2a0c3a7SRichard Henderson *
1494*d2a0c3a7SRichard Henderson * In QEMU, we do not model the fp_exception_pending state and
1495*d2a0c3a7SRichard Henderson * instead populate FQ and raise the exception immediately.
1496*d2a0c3a7SRichard Henderson * But we can still honor fp_exception state by noticing when
1497*d2a0c3a7SRichard Henderson * the FQ is not empty.
1498*d2a0c3a7SRichard Henderson */
1499*d2a0c3a7SRichard Henderson if (dc->fsr_qne) {
1500*d2a0c3a7SRichard Henderson gen_op_fpexception_im(dc, FSR_FTT_SEQ_ERROR);
1501*d2a0c3a7SRichard Henderson return true;
1502*d2a0c3a7SRichard Henderson }
1503*d2a0c3a7SRichard Henderson #endif
1504*d2a0c3a7SRichard Henderson return false;
1505*d2a0c3a7SRichard Henderson }
1506*d2a0c3a7SRichard Henderson
gen_trap_if_nofpu_fpexception(DisasContext * dc)1507*d2a0c3a7SRichard Henderson static bool gen_trap_if_nofpu_fpexception(DisasContext *dc)
1508*d2a0c3a7SRichard Henderson {
1509*d2a0c3a7SRichard Henderson return gen_trap_ifnofpu(dc) || gen_trap_iffpexception(dc);
1510fcf5ef2aSThomas Huth }
1511fcf5ef2aSThomas Huth
1512fcf5ef2aSThomas Huth /* asi moves */
1513fcf5ef2aSThomas Huth typedef enum {
1514fcf5ef2aSThomas Huth GET_ASI_HELPER,
1515fcf5ef2aSThomas Huth GET_ASI_EXCP,
1516fcf5ef2aSThomas Huth GET_ASI_DIRECT,
1517fcf5ef2aSThomas Huth GET_ASI_DTWINX,
15182786a3f8SRichard Henderson GET_ASI_CODE,
1519fcf5ef2aSThomas Huth GET_ASI_BLOCK,
1520fcf5ef2aSThomas Huth GET_ASI_SHORT,
1521fcf5ef2aSThomas Huth GET_ASI_BCOPY,
1522fcf5ef2aSThomas Huth GET_ASI_BFILL,
1523fcf5ef2aSThomas Huth } ASIType;
1524fcf5ef2aSThomas Huth
1525fcf5ef2aSThomas Huth typedef struct {
1526fcf5ef2aSThomas Huth ASIType type;
1527fcf5ef2aSThomas Huth int asi;
1528fcf5ef2aSThomas Huth int mem_idx;
152914776ab5STony Nguyen MemOp memop;
1530fcf5ef2aSThomas Huth } DisasASI;
1531fcf5ef2aSThomas Huth
1532811cc0b0SRichard Henderson /*
1533811cc0b0SRichard Henderson * Build DisasASI.
1534811cc0b0SRichard Henderson * For asi == -1, treat as non-asi.
1535811cc0b0SRichard Henderson * For ask == -2, treat as immediate offset (v8 error, v9 %asi).
1536811cc0b0SRichard Henderson */
resolve_asi(DisasContext * dc,int asi,MemOp memop)1537811cc0b0SRichard Henderson static DisasASI resolve_asi(DisasContext *dc, int asi, MemOp memop)
1538fcf5ef2aSThomas Huth {
1539fcf5ef2aSThomas Huth ASIType type = GET_ASI_HELPER;
1540fcf5ef2aSThomas Huth int mem_idx = dc->mem_idx;
1541fcf5ef2aSThomas Huth
1542811cc0b0SRichard Henderson if (asi == -1) {
1543811cc0b0SRichard Henderson /* Artificial "non-asi" case. */
1544811cc0b0SRichard Henderson type = GET_ASI_DIRECT;
1545811cc0b0SRichard Henderson goto done;
1546811cc0b0SRichard Henderson }
1547811cc0b0SRichard Henderson
1548fcf5ef2aSThomas Huth #ifndef TARGET_SPARC64
1549fcf5ef2aSThomas Huth /* Before v9, all asis are immediate and privileged. */
1550811cc0b0SRichard Henderson if (asi < 0) {
1551fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN);
1552fcf5ef2aSThomas Huth type = GET_ASI_EXCP;
1553fcf5ef2aSThomas Huth } else if (supervisor(dc)
1554fcf5ef2aSThomas Huth /* Note that LEON accepts ASI_USERDATA in user mode, for
1555fcf5ef2aSThomas Huth use with CASA. Also note that previous versions of
1556fcf5ef2aSThomas Huth QEMU allowed (and old versions of gcc emitted) ASI_P
1557fcf5ef2aSThomas Huth for LEON, which is incorrect. */
1558fcf5ef2aSThomas Huth || (asi == ASI_USERDATA
1559fcf5ef2aSThomas Huth && (dc->def->features & CPU_FEATURE_CASA))) {
1560fcf5ef2aSThomas Huth switch (asi) {
1561fcf5ef2aSThomas Huth case ASI_USERDATA: /* User data access */
1562fcf5ef2aSThomas Huth mem_idx = MMU_USER_IDX;
1563fcf5ef2aSThomas Huth type = GET_ASI_DIRECT;
1564fcf5ef2aSThomas Huth break;
1565fcf5ef2aSThomas Huth case ASI_KERNELDATA: /* Supervisor data access */
1566fcf5ef2aSThomas Huth mem_idx = MMU_KERNEL_IDX;
1567fcf5ef2aSThomas Huth type = GET_ASI_DIRECT;
1568fcf5ef2aSThomas Huth break;
15692786a3f8SRichard Henderson case ASI_USERTXT: /* User text access */
15702786a3f8SRichard Henderson mem_idx = MMU_USER_IDX;
15712786a3f8SRichard Henderson type = GET_ASI_CODE;
15722786a3f8SRichard Henderson break;
15732786a3f8SRichard Henderson case ASI_KERNELTXT: /* Supervisor text access */
15742786a3f8SRichard Henderson mem_idx = MMU_KERNEL_IDX;
15752786a3f8SRichard Henderson type = GET_ASI_CODE;
15762786a3f8SRichard Henderson break;
1577fcf5ef2aSThomas Huth case ASI_M_BYPASS: /* MMU passthrough */
1578fcf5ef2aSThomas Huth case ASI_LEON_BYPASS: /* LEON MMU passthrough */
1579fcf5ef2aSThomas Huth mem_idx = MMU_PHYS_IDX;
1580fcf5ef2aSThomas Huth type = GET_ASI_DIRECT;
1581fcf5ef2aSThomas Huth break;
1582fcf5ef2aSThomas Huth case ASI_M_BCOPY: /* Block copy, sta access */
1583fcf5ef2aSThomas Huth mem_idx = MMU_KERNEL_IDX;
1584fcf5ef2aSThomas Huth type = GET_ASI_BCOPY;
1585fcf5ef2aSThomas Huth break;
1586fcf5ef2aSThomas Huth case ASI_M_BFILL: /* Block fill, stda access */
1587fcf5ef2aSThomas Huth mem_idx = MMU_KERNEL_IDX;
1588fcf5ef2aSThomas Huth type = GET_ASI_BFILL;
1589fcf5ef2aSThomas Huth break;
1590fcf5ef2aSThomas Huth }
15916e10f37cSKONRAD Frederic
15926e10f37cSKONRAD Frederic /* MMU_PHYS_IDX is used when the MMU is disabled to passthrough the
15936e10f37cSKONRAD Frederic * permissions check in get_physical_address(..).
15946e10f37cSKONRAD Frederic */
15956e10f37cSKONRAD Frederic mem_idx = (dc->mem_idx == MMU_PHYS_IDX) ? MMU_PHYS_IDX : mem_idx;
1596fcf5ef2aSThomas Huth } else {
1597fcf5ef2aSThomas Huth gen_exception(dc, TT_PRIV_INSN);
1598fcf5ef2aSThomas Huth type = GET_ASI_EXCP;
1599fcf5ef2aSThomas Huth }
1600fcf5ef2aSThomas Huth #else
1601811cc0b0SRichard Henderson if (asi < 0) {
1602fcf5ef2aSThomas Huth asi = dc->asi;
1603fcf5ef2aSThomas Huth }
1604fcf5ef2aSThomas Huth /* With v9, all asis below 0x80 are privileged. */
1605fcf5ef2aSThomas Huth /* ??? We ought to check cpu_has_hypervisor, but we didn't copy
1606fcf5ef2aSThomas Huth down that bit into DisasContext. For the moment that's ok,
1607fcf5ef2aSThomas Huth since the direct implementations below doesn't have any ASIs
1608fcf5ef2aSThomas Huth in the restricted [0x30, 0x7f] range, and the check will be
1609fcf5ef2aSThomas Huth done properly in the helper. */
1610fcf5ef2aSThomas Huth if (!supervisor(dc) && asi < 0x80) {
1611fcf5ef2aSThomas Huth gen_exception(dc, TT_PRIV_ACT);
1612fcf5ef2aSThomas Huth type = GET_ASI_EXCP;
1613fcf5ef2aSThomas Huth } else {
1614fcf5ef2aSThomas Huth switch (asi) {
1615fcf5ef2aSThomas Huth case ASI_REAL: /* Bypass */
1616fcf5ef2aSThomas Huth case ASI_REAL_IO: /* Bypass, non-cacheable */
1617fcf5ef2aSThomas Huth case ASI_REAL_L: /* Bypass LE */
1618fcf5ef2aSThomas Huth case ASI_REAL_IO_L: /* Bypass, non-cacheable LE */
1619fcf5ef2aSThomas Huth case ASI_TWINX_REAL: /* Real address, twinx */
1620fcf5ef2aSThomas Huth case ASI_TWINX_REAL_L: /* Real address, twinx, LE */
1621fcf5ef2aSThomas Huth case ASI_QUAD_LDD_PHYS:
1622fcf5ef2aSThomas Huth case ASI_QUAD_LDD_PHYS_L:
1623fcf5ef2aSThomas Huth mem_idx = MMU_PHYS_IDX;
1624fcf5ef2aSThomas Huth break;
1625fcf5ef2aSThomas Huth case ASI_N: /* Nucleus */
1626fcf5ef2aSThomas Huth case ASI_NL: /* Nucleus LE */
1627fcf5ef2aSThomas Huth case ASI_TWINX_N:
1628fcf5ef2aSThomas Huth case ASI_TWINX_NL:
1629fcf5ef2aSThomas Huth case ASI_NUCLEUS_QUAD_LDD:
1630fcf5ef2aSThomas Huth case ASI_NUCLEUS_QUAD_LDD_L:
16319a10756dSArtyom Tarasenko if (hypervisor(dc)) {
163284f8f587SArtyom Tarasenko mem_idx = MMU_PHYS_IDX;
16339a10756dSArtyom Tarasenko } else {
1634fcf5ef2aSThomas Huth mem_idx = MMU_NUCLEUS_IDX;
16359a10756dSArtyom Tarasenko }
1636fcf5ef2aSThomas Huth break;
1637fcf5ef2aSThomas Huth case ASI_AIUP: /* As if user primary */
1638fcf5ef2aSThomas Huth case ASI_AIUPL: /* As if user primary LE */
1639fcf5ef2aSThomas Huth case ASI_TWINX_AIUP:
1640fcf5ef2aSThomas Huth case ASI_TWINX_AIUP_L:
1641fcf5ef2aSThomas Huth case ASI_BLK_AIUP_4V:
1642fcf5ef2aSThomas Huth case ASI_BLK_AIUP_L_4V:
1643fcf5ef2aSThomas Huth case ASI_BLK_AIUP:
1644fcf5ef2aSThomas Huth case ASI_BLK_AIUPL:
1645eeb3f592SRichard Henderson case ASI_MON_AIUP:
1646fcf5ef2aSThomas Huth mem_idx = MMU_USER_IDX;
1647fcf5ef2aSThomas Huth break;
1648fcf5ef2aSThomas Huth case ASI_AIUS: /* As if user secondary */
1649fcf5ef2aSThomas Huth case ASI_AIUSL: /* As if user secondary LE */
1650fcf5ef2aSThomas Huth case ASI_TWINX_AIUS:
1651fcf5ef2aSThomas Huth case ASI_TWINX_AIUS_L:
1652fcf5ef2aSThomas Huth case ASI_BLK_AIUS_4V:
1653fcf5ef2aSThomas Huth case ASI_BLK_AIUS_L_4V:
1654fcf5ef2aSThomas Huth case ASI_BLK_AIUS:
1655fcf5ef2aSThomas Huth case ASI_BLK_AIUSL:
1656eeb3f592SRichard Henderson case ASI_MON_AIUS:
1657fcf5ef2aSThomas Huth mem_idx = MMU_USER_SECONDARY_IDX;
1658fcf5ef2aSThomas Huth break;
1659fcf5ef2aSThomas Huth case ASI_S: /* Secondary */
1660fcf5ef2aSThomas Huth case ASI_SL: /* Secondary LE */
1661fcf5ef2aSThomas Huth case ASI_TWINX_S:
1662fcf5ef2aSThomas Huth case ASI_TWINX_SL:
1663fcf5ef2aSThomas Huth case ASI_BLK_COMMIT_S:
1664fcf5ef2aSThomas Huth case ASI_BLK_S:
1665fcf5ef2aSThomas Huth case ASI_BLK_SL:
1666fcf5ef2aSThomas Huth case ASI_FL8_S:
1667fcf5ef2aSThomas Huth case ASI_FL8_SL:
1668fcf5ef2aSThomas Huth case ASI_FL16_S:
1669fcf5ef2aSThomas Huth case ASI_FL16_SL:
1670eeb3f592SRichard Henderson case ASI_MON_S:
1671fcf5ef2aSThomas Huth if (mem_idx == MMU_USER_IDX) {
1672fcf5ef2aSThomas Huth mem_idx = MMU_USER_SECONDARY_IDX;
1673fcf5ef2aSThomas Huth } else if (mem_idx == MMU_KERNEL_IDX) {
1674fcf5ef2aSThomas Huth mem_idx = MMU_KERNEL_SECONDARY_IDX;
1675fcf5ef2aSThomas Huth }
1676fcf5ef2aSThomas Huth break;
1677fcf5ef2aSThomas Huth case ASI_P: /* Primary */
1678fcf5ef2aSThomas Huth case ASI_PL: /* Primary LE */
1679fcf5ef2aSThomas Huth case ASI_TWINX_P:
1680fcf5ef2aSThomas Huth case ASI_TWINX_PL:
1681fcf5ef2aSThomas Huth case ASI_BLK_COMMIT_P:
1682fcf5ef2aSThomas Huth case ASI_BLK_P:
1683fcf5ef2aSThomas Huth case ASI_BLK_PL:
1684fcf5ef2aSThomas Huth case ASI_FL8_P:
1685fcf5ef2aSThomas Huth case ASI_FL8_PL:
1686fcf5ef2aSThomas Huth case ASI_FL16_P:
1687fcf5ef2aSThomas Huth case ASI_FL16_PL:
1688eeb3f592SRichard Henderson case ASI_MON_P:
1689fcf5ef2aSThomas Huth break;
1690fcf5ef2aSThomas Huth }
1691fcf5ef2aSThomas Huth switch (asi) {
1692fcf5ef2aSThomas Huth case ASI_REAL:
1693fcf5ef2aSThomas Huth case ASI_REAL_IO:
1694fcf5ef2aSThomas Huth case ASI_REAL_L:
1695fcf5ef2aSThomas Huth case ASI_REAL_IO_L:
1696fcf5ef2aSThomas Huth case ASI_N:
1697fcf5ef2aSThomas Huth case ASI_NL:
1698fcf5ef2aSThomas Huth case ASI_AIUP:
1699fcf5ef2aSThomas Huth case ASI_AIUPL:
1700fcf5ef2aSThomas Huth case ASI_AIUS:
1701fcf5ef2aSThomas Huth case ASI_AIUSL:
1702fcf5ef2aSThomas Huth case ASI_S:
1703fcf5ef2aSThomas Huth case ASI_SL:
1704fcf5ef2aSThomas Huth case ASI_P:
1705fcf5ef2aSThomas Huth case ASI_PL:
1706eeb3f592SRichard Henderson case ASI_MON_P:
1707eeb3f592SRichard Henderson case ASI_MON_S:
1708eeb3f592SRichard Henderson case ASI_MON_AIUP:
1709eeb3f592SRichard Henderson case ASI_MON_AIUS:
1710fcf5ef2aSThomas Huth type = GET_ASI_DIRECT;
1711fcf5ef2aSThomas Huth break;
1712fcf5ef2aSThomas Huth case ASI_TWINX_REAL:
1713fcf5ef2aSThomas Huth case ASI_TWINX_REAL_L:
1714fcf5ef2aSThomas Huth case ASI_TWINX_N:
1715fcf5ef2aSThomas Huth case ASI_TWINX_NL:
1716fcf5ef2aSThomas Huth case ASI_TWINX_AIUP:
1717fcf5ef2aSThomas Huth case ASI_TWINX_AIUP_L:
1718fcf5ef2aSThomas Huth case ASI_TWINX_AIUS:
1719fcf5ef2aSThomas Huth case ASI_TWINX_AIUS_L:
1720fcf5ef2aSThomas Huth case ASI_TWINX_P:
1721fcf5ef2aSThomas Huth case ASI_TWINX_PL:
1722fcf5ef2aSThomas Huth case ASI_TWINX_S:
1723fcf5ef2aSThomas Huth case ASI_TWINX_SL:
1724fcf5ef2aSThomas Huth case ASI_QUAD_LDD_PHYS:
1725fcf5ef2aSThomas Huth case ASI_QUAD_LDD_PHYS_L:
1726fcf5ef2aSThomas Huth case ASI_NUCLEUS_QUAD_LDD:
1727fcf5ef2aSThomas Huth case ASI_NUCLEUS_QUAD_LDD_L:
1728fcf5ef2aSThomas Huth type = GET_ASI_DTWINX;
1729fcf5ef2aSThomas Huth break;
1730fcf5ef2aSThomas Huth case ASI_BLK_COMMIT_P:
1731fcf5ef2aSThomas Huth case ASI_BLK_COMMIT_S:
1732fcf5ef2aSThomas Huth case ASI_BLK_AIUP_4V:
1733fcf5ef2aSThomas Huth case ASI_BLK_AIUP_L_4V:
1734fcf5ef2aSThomas Huth case ASI_BLK_AIUP:
1735fcf5ef2aSThomas Huth case ASI_BLK_AIUPL:
1736fcf5ef2aSThomas Huth case ASI_BLK_AIUS_4V:
1737fcf5ef2aSThomas Huth case ASI_BLK_AIUS_L_4V:
1738fcf5ef2aSThomas Huth case ASI_BLK_AIUS:
1739fcf5ef2aSThomas Huth case ASI_BLK_AIUSL:
1740fcf5ef2aSThomas Huth case ASI_BLK_S:
1741fcf5ef2aSThomas Huth case ASI_BLK_SL:
1742fcf5ef2aSThomas Huth case ASI_BLK_P:
1743fcf5ef2aSThomas Huth case ASI_BLK_PL:
1744fcf5ef2aSThomas Huth type = GET_ASI_BLOCK;
1745fcf5ef2aSThomas Huth break;
1746fcf5ef2aSThomas Huth case ASI_FL8_S:
1747fcf5ef2aSThomas Huth case ASI_FL8_SL:
1748fcf5ef2aSThomas Huth case ASI_FL8_P:
1749fcf5ef2aSThomas Huth case ASI_FL8_PL:
1750fcf5ef2aSThomas Huth memop = MO_UB;
1751fcf5ef2aSThomas Huth type = GET_ASI_SHORT;
1752fcf5ef2aSThomas Huth break;
1753fcf5ef2aSThomas Huth case ASI_FL16_S:
1754fcf5ef2aSThomas Huth case ASI_FL16_SL:
1755fcf5ef2aSThomas Huth case ASI_FL16_P:
1756fcf5ef2aSThomas Huth case ASI_FL16_PL:
1757fcf5ef2aSThomas Huth memop = MO_TEUW;
1758fcf5ef2aSThomas Huth type = GET_ASI_SHORT;
1759fcf5ef2aSThomas Huth break;
1760fcf5ef2aSThomas Huth }
1761fcf5ef2aSThomas Huth /* The little-endian asis all have bit 3 set. */
1762fcf5ef2aSThomas Huth if (asi & 8) {
1763fcf5ef2aSThomas Huth memop ^= MO_BSWAP;
1764fcf5ef2aSThomas Huth }
1765fcf5ef2aSThomas Huth }
1766fcf5ef2aSThomas Huth #endif
1767fcf5ef2aSThomas Huth
1768811cc0b0SRichard Henderson done:
1769fcf5ef2aSThomas Huth return (DisasASI){ type, asi, mem_idx, memop };
1770fcf5ef2aSThomas Huth }
1771fcf5ef2aSThomas Huth
1772a76779eeSRichard Henderson #if defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
gen_helper_ld_asi(TCGv_i64 r,TCGv_env e,TCGv a,TCGv_i32 asi,TCGv_i32 mop)1773a76779eeSRichard Henderson static void gen_helper_ld_asi(TCGv_i64 r, TCGv_env e, TCGv a,
1774a76779eeSRichard Henderson TCGv_i32 asi, TCGv_i32 mop)
1775a76779eeSRichard Henderson {
1776a76779eeSRichard Henderson g_assert_not_reached();
1777a76779eeSRichard Henderson }
1778a76779eeSRichard Henderson
gen_helper_st_asi(TCGv_env e,TCGv a,TCGv_i64 r,TCGv_i32 asi,TCGv_i32 mop)1779a76779eeSRichard Henderson static void gen_helper_st_asi(TCGv_env e, TCGv a, TCGv_i64 r,
1780a76779eeSRichard Henderson TCGv_i32 asi, TCGv_i32 mop)
1781a76779eeSRichard Henderson {
1782a76779eeSRichard Henderson g_assert_not_reached();
1783a76779eeSRichard Henderson }
1784a76779eeSRichard Henderson #endif
1785a76779eeSRichard Henderson
gen_ld_asi(DisasContext * dc,DisasASI * da,TCGv dst,TCGv addr)178642071fc1SRichard Henderson static void gen_ld_asi(DisasContext *dc, DisasASI *da, TCGv dst, TCGv addr)
1787fcf5ef2aSThomas Huth {
1788c03a0fd1SRichard Henderson switch (da->type) {
1789fcf5ef2aSThomas Huth case GET_ASI_EXCP:
1790fcf5ef2aSThomas Huth break;
1791fcf5ef2aSThomas Huth case GET_ASI_DTWINX: /* Reserved for ldda. */
1792fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN);
1793fcf5ef2aSThomas Huth break;
1794fcf5ef2aSThomas Huth case GET_ASI_DIRECT:
1795c03a0fd1SRichard Henderson tcg_gen_qemu_ld_tl(dst, addr, da->mem_idx, da->memop | MO_ALIGN);
1796fcf5ef2aSThomas Huth break;
17972786a3f8SRichard Henderson
17982786a3f8SRichard Henderson case GET_ASI_CODE:
17992786a3f8SRichard Henderson #if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
18002786a3f8SRichard Henderson {
18012786a3f8SRichard Henderson MemOpIdx oi = make_memop_idx(da->memop, da->mem_idx);
18022786a3f8SRichard Henderson TCGv_i64 t64 = tcg_temp_new_i64();
18032786a3f8SRichard Henderson
18042786a3f8SRichard Henderson gen_helper_ld_code(t64, tcg_env, addr, tcg_constant_i32(oi));
18052786a3f8SRichard Henderson tcg_gen_trunc_i64_tl(dst, t64);
18062786a3f8SRichard Henderson }
18072786a3f8SRichard Henderson break;
18082786a3f8SRichard Henderson #else
18092786a3f8SRichard Henderson g_assert_not_reached();
18102786a3f8SRichard Henderson #endif
18112786a3f8SRichard Henderson
1812fcf5ef2aSThomas Huth default:
1813fcf5ef2aSThomas Huth {
1814c03a0fd1SRichard Henderson TCGv_i32 r_asi = tcg_constant_i32(da->asi);
1815c03a0fd1SRichard Henderson TCGv_i32 r_mop = tcg_constant_i32(da->memop | MO_ALIGN);
1816fcf5ef2aSThomas Huth
1817fcf5ef2aSThomas Huth save_state(dc);
1818fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
1819ad75a51eSRichard Henderson gen_helper_ld_asi(dst, tcg_env, addr, r_asi, r_mop);
1820fcf5ef2aSThomas Huth #else
1821fcf5ef2aSThomas Huth {
1822fcf5ef2aSThomas Huth TCGv_i64 t64 = tcg_temp_new_i64();
1823ad75a51eSRichard Henderson gen_helper_ld_asi(t64, tcg_env, addr, r_asi, r_mop);
1824fcf5ef2aSThomas Huth tcg_gen_trunc_i64_tl(dst, t64);
1825fcf5ef2aSThomas Huth }
1826fcf5ef2aSThomas Huth #endif
1827fcf5ef2aSThomas Huth }
1828fcf5ef2aSThomas Huth break;
1829fcf5ef2aSThomas Huth }
1830fcf5ef2aSThomas Huth }
1831fcf5ef2aSThomas Huth
gen_st_asi(DisasContext * dc,DisasASI * da,TCGv src,TCGv addr)183242071fc1SRichard Henderson static void gen_st_asi(DisasContext *dc, DisasASI *da, TCGv src, TCGv addr)
1833c03a0fd1SRichard Henderson {
1834c03a0fd1SRichard Henderson switch (da->type) {
1835fcf5ef2aSThomas Huth case GET_ASI_EXCP:
1836fcf5ef2aSThomas Huth break;
1837c03a0fd1SRichard Henderson
1838fcf5ef2aSThomas Huth case GET_ASI_DTWINX: /* Reserved for stda. */
1839c03a0fd1SRichard Henderson if (TARGET_LONG_BITS == 32) {
1840fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN);
1841fcf5ef2aSThomas Huth break;
1842c03a0fd1SRichard Henderson } else if (!(dc->def->features & CPU_FEATURE_HYPV)) {
18433390537bSArtyom Tarasenko /* Pre OpenSPARC CPUs don't have these */
18443390537bSArtyom Tarasenko gen_exception(dc, TT_ILL_INSN);
1845fcf5ef2aSThomas Huth break;
1846c03a0fd1SRichard Henderson }
1847c03a0fd1SRichard Henderson /* In OpenSPARC T1+ CPUs TWINX ASIs in store are ST_BLKINIT_ ASIs */
1848c03a0fd1SRichard Henderson /* fall through */
1849c03a0fd1SRichard Henderson
1850c03a0fd1SRichard Henderson case GET_ASI_DIRECT:
1851c03a0fd1SRichard Henderson tcg_gen_qemu_st_tl(src, addr, da->mem_idx, da->memop | MO_ALIGN);
1852c03a0fd1SRichard Henderson break;
1853c03a0fd1SRichard Henderson
1854fcf5ef2aSThomas Huth case GET_ASI_BCOPY:
1855c03a0fd1SRichard Henderson assert(TARGET_LONG_BITS == 32);
185698271007SRichard Henderson /*
185798271007SRichard Henderson * Copy 32 bytes from the address in SRC to ADDR.
185898271007SRichard Henderson *
185998271007SRichard Henderson * From Ross RT625 hyperSPARC manual, section 4.6:
186098271007SRichard Henderson * "Block Copy and Block Fill will work only on cache line boundaries."
186198271007SRichard Henderson *
186298271007SRichard Henderson * It does not specify if an unaliged address is truncated or trapped.
186398271007SRichard Henderson * Previous qemu behaviour was to truncate to 4 byte alignment, which
186498271007SRichard Henderson * is obviously wrong. The only place I can see this used is in the
186598271007SRichard Henderson * Linux kernel which begins with page alignment, advancing by 32,
186698271007SRichard Henderson * so is always aligned. Assume truncation as the simpler option.
186798271007SRichard Henderson *
186898271007SRichard Henderson * Since the loads and stores are paired, allow the copy to happen
186998271007SRichard Henderson * in the host endianness. The copy need not be atomic.
187098271007SRichard Henderson */
1871fcf5ef2aSThomas Huth {
187298271007SRichard Henderson MemOp mop = MO_128 | MO_ATOM_IFALIGN_PAIR;
1873fcf5ef2aSThomas Huth TCGv saddr = tcg_temp_new();
1874fcf5ef2aSThomas Huth TCGv daddr = tcg_temp_new();
187598271007SRichard Henderson TCGv_i128 tmp = tcg_temp_new_i128();
1876fcf5ef2aSThomas Huth
187798271007SRichard Henderson tcg_gen_andi_tl(saddr, src, -32);
187898271007SRichard Henderson tcg_gen_andi_tl(daddr, addr, -32);
187998271007SRichard Henderson tcg_gen_qemu_ld_i128(tmp, saddr, da->mem_idx, mop);
188098271007SRichard Henderson tcg_gen_qemu_st_i128(tmp, daddr, da->mem_idx, mop);
188198271007SRichard Henderson tcg_gen_addi_tl(saddr, saddr, 16);
188298271007SRichard Henderson tcg_gen_addi_tl(daddr, daddr, 16);
188398271007SRichard Henderson tcg_gen_qemu_ld_i128(tmp, saddr, da->mem_idx, mop);
188498271007SRichard Henderson tcg_gen_qemu_st_i128(tmp, daddr, da->mem_idx, mop);
1885fcf5ef2aSThomas Huth }
1886fcf5ef2aSThomas Huth break;
1887c03a0fd1SRichard Henderson
1888fcf5ef2aSThomas Huth default:
1889fcf5ef2aSThomas Huth {
1890c03a0fd1SRichard Henderson TCGv_i32 r_asi = tcg_constant_i32(da->asi);
1891c03a0fd1SRichard Henderson TCGv_i32 r_mop = tcg_constant_i32(da->memop | MO_ALIGN);
1892fcf5ef2aSThomas Huth
1893fcf5ef2aSThomas Huth save_state(dc);
1894fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
1895ad75a51eSRichard Henderson gen_helper_st_asi(tcg_env, addr, src, r_asi, r_mop);
1896fcf5ef2aSThomas Huth #else
1897fcf5ef2aSThomas Huth {
1898fcf5ef2aSThomas Huth TCGv_i64 t64 = tcg_temp_new_i64();
1899fcf5ef2aSThomas Huth tcg_gen_extu_tl_i64(t64, src);
1900ad75a51eSRichard Henderson gen_helper_st_asi(tcg_env, addr, t64, r_asi, r_mop);
1901fcf5ef2aSThomas Huth }
1902fcf5ef2aSThomas Huth #endif
1903fcf5ef2aSThomas Huth
1904fcf5ef2aSThomas Huth /* A write to a TLB register may alter page maps. End the TB. */
1905fcf5ef2aSThomas Huth dc->npc = DYNAMIC_PC;
1906fcf5ef2aSThomas Huth }
1907fcf5ef2aSThomas Huth break;
1908fcf5ef2aSThomas Huth }
1909fcf5ef2aSThomas Huth }
1910fcf5ef2aSThomas Huth
gen_swap_asi(DisasContext * dc,DisasASI * da,TCGv dst,TCGv src,TCGv addr)1911dca544b9SRichard Henderson static void gen_swap_asi(DisasContext *dc, DisasASI *da,
1912c03a0fd1SRichard Henderson TCGv dst, TCGv src, TCGv addr)
1913c03a0fd1SRichard Henderson {
1914c03a0fd1SRichard Henderson switch (da->type) {
1915c03a0fd1SRichard Henderson case GET_ASI_EXCP:
1916c03a0fd1SRichard Henderson break;
1917c03a0fd1SRichard Henderson case GET_ASI_DIRECT:
1918dca544b9SRichard Henderson tcg_gen_atomic_xchg_tl(dst, addr, src,
1919dca544b9SRichard Henderson da->mem_idx, da->memop | MO_ALIGN);
1920c03a0fd1SRichard Henderson break;
1921c03a0fd1SRichard Henderson default:
1922c03a0fd1SRichard Henderson /* ??? Should be DAE_invalid_asi. */
1923c03a0fd1SRichard Henderson gen_exception(dc, TT_DATA_ACCESS);
1924c03a0fd1SRichard Henderson break;
1925c03a0fd1SRichard Henderson }
1926c03a0fd1SRichard Henderson }
1927c03a0fd1SRichard Henderson
gen_cas_asi(DisasContext * dc,DisasASI * da,TCGv oldv,TCGv newv,TCGv cmpv,TCGv addr)1928d0a11d25SRichard Henderson static void gen_cas_asi(DisasContext *dc, DisasASI *da,
1929c03a0fd1SRichard Henderson TCGv oldv, TCGv newv, TCGv cmpv, TCGv addr)
1930c03a0fd1SRichard Henderson {
1931c03a0fd1SRichard Henderson switch (da->type) {
1932fcf5ef2aSThomas Huth case GET_ASI_EXCP:
1933c03a0fd1SRichard Henderson return;
1934fcf5ef2aSThomas Huth case GET_ASI_DIRECT:
1935c03a0fd1SRichard Henderson tcg_gen_atomic_cmpxchg_tl(oldv, addr, cmpv, newv,
1936c03a0fd1SRichard Henderson da->mem_idx, da->memop | MO_ALIGN);
1937fcf5ef2aSThomas Huth break;
1938fcf5ef2aSThomas Huth default:
1939fcf5ef2aSThomas Huth /* ??? Should be DAE_invalid_asi. */
1940fcf5ef2aSThomas Huth gen_exception(dc, TT_DATA_ACCESS);
1941fcf5ef2aSThomas Huth break;
1942fcf5ef2aSThomas Huth }
1943fcf5ef2aSThomas Huth }
1944fcf5ef2aSThomas Huth
gen_ldstub_asi(DisasContext * dc,DisasASI * da,TCGv dst,TCGv addr)1945cf07cd1eSRichard Henderson static void gen_ldstub_asi(DisasContext *dc, DisasASI *da, TCGv dst, TCGv addr)
1946c03a0fd1SRichard Henderson {
1947c03a0fd1SRichard Henderson switch (da->type) {
1948fcf5ef2aSThomas Huth case GET_ASI_EXCP:
1949fcf5ef2aSThomas Huth break;
1950fcf5ef2aSThomas Huth case GET_ASI_DIRECT:
1951cf07cd1eSRichard Henderson tcg_gen_atomic_xchg_tl(dst, addr, tcg_constant_tl(0xff),
1952cf07cd1eSRichard Henderson da->mem_idx, MO_UB);
1953fcf5ef2aSThomas Huth break;
1954fcf5ef2aSThomas Huth default:
19553db010c3SRichard Henderson /* ??? In theory, this should be raise DAE_invalid_asi.
19563db010c3SRichard Henderson But the SS-20 roms do ldstuba [%l0] #ASI_M_CTL, %o1. */
1957af00be49SEmilio G. Cota if (tb_cflags(dc->base.tb) & CF_PARALLEL) {
1958ad75a51eSRichard Henderson gen_helper_exit_atomic(tcg_env);
19593db010c3SRichard Henderson } else {
1960c03a0fd1SRichard Henderson TCGv_i32 r_asi = tcg_constant_i32(da->asi);
196100ab7e61SRichard Henderson TCGv_i32 r_mop = tcg_constant_i32(MO_UB);
19623db010c3SRichard Henderson TCGv_i64 s64, t64;
19633db010c3SRichard Henderson
19643db010c3SRichard Henderson save_state(dc);
19653db010c3SRichard Henderson t64 = tcg_temp_new_i64();
1966ad75a51eSRichard Henderson gen_helper_ld_asi(t64, tcg_env, addr, r_asi, r_mop);
19673db010c3SRichard Henderson
196800ab7e61SRichard Henderson s64 = tcg_constant_i64(0xff);
1969ad75a51eSRichard Henderson gen_helper_st_asi(tcg_env, addr, s64, r_asi, r_mop);
19703db010c3SRichard Henderson
19713db010c3SRichard Henderson tcg_gen_trunc_i64_tl(dst, t64);
19723db010c3SRichard Henderson
19733db010c3SRichard Henderson /* End the TB. */
19743db010c3SRichard Henderson dc->npc = DYNAMIC_PC;
19753db010c3SRichard Henderson }
1976fcf5ef2aSThomas Huth break;
1977fcf5ef2aSThomas Huth }
1978fcf5ef2aSThomas Huth }
1979fcf5ef2aSThomas Huth
gen_ldf_asi(DisasContext * dc,DisasASI * da,MemOp orig_size,TCGv addr,int rd)1980287b1152SRichard Henderson static void gen_ldf_asi(DisasContext *dc, DisasASI *da, MemOp orig_size,
19813259b9e2SRichard Henderson TCGv addr, int rd)
1982fcf5ef2aSThomas Huth {
19833259b9e2SRichard Henderson MemOp memop = da->memop;
19843259b9e2SRichard Henderson MemOp size = memop & MO_SIZE;
1985fcf5ef2aSThomas Huth TCGv_i32 d32;
19861210a036SRichard Henderson TCGv_i64 d64, l64;
1987287b1152SRichard Henderson TCGv addr_tmp;
1988fcf5ef2aSThomas Huth
19893259b9e2SRichard Henderson /* TODO: Use 128-bit load/store below. */
19903259b9e2SRichard Henderson if (size == MO_128) {
19913259b9e2SRichard Henderson memop = (memop & ~MO_SIZE) | MO_64;
19923259b9e2SRichard Henderson }
19933259b9e2SRichard Henderson
19943259b9e2SRichard Henderson switch (da->type) {
1995fcf5ef2aSThomas Huth case GET_ASI_EXCP:
1996fcf5ef2aSThomas Huth break;
1997fcf5ef2aSThomas Huth
1998fcf5ef2aSThomas Huth case GET_ASI_DIRECT:
19993259b9e2SRichard Henderson memop |= MO_ALIGN_4;
2000fcf5ef2aSThomas Huth switch (size) {
20013259b9e2SRichard Henderson case MO_32:
2002388a6465SRichard Henderson d32 = tcg_temp_new_i32();
20033259b9e2SRichard Henderson tcg_gen_qemu_ld_i32(d32, addr, da->mem_idx, memop);
2004fcf5ef2aSThomas Huth gen_store_fpr_F(dc, rd, d32);
2005fcf5ef2aSThomas Huth break;
20063259b9e2SRichard Henderson
20073259b9e2SRichard Henderson case MO_64:
20081210a036SRichard Henderson d64 = tcg_temp_new_i64();
20091210a036SRichard Henderson tcg_gen_qemu_ld_i64(d64, addr, da->mem_idx, memop);
20101210a036SRichard Henderson gen_store_fpr_D(dc, rd, d64);
2011fcf5ef2aSThomas Huth break;
20123259b9e2SRichard Henderson
20133259b9e2SRichard Henderson case MO_128:
2014fcf5ef2aSThomas Huth d64 = tcg_temp_new_i64();
20151210a036SRichard Henderson l64 = tcg_temp_new_i64();
20163259b9e2SRichard Henderson tcg_gen_qemu_ld_i64(d64, addr, da->mem_idx, memop);
2017287b1152SRichard Henderson addr_tmp = tcg_temp_new();
2018287b1152SRichard Henderson tcg_gen_addi_tl(addr_tmp, addr, 8);
20191210a036SRichard Henderson tcg_gen_qemu_ld_i64(l64, addr_tmp, da->mem_idx, memop);
20201210a036SRichard Henderson gen_store_fpr_D(dc, rd, d64);
20211210a036SRichard Henderson gen_store_fpr_D(dc, rd + 2, l64);
2022fcf5ef2aSThomas Huth break;
2023fcf5ef2aSThomas Huth default:
2024fcf5ef2aSThomas Huth g_assert_not_reached();
2025fcf5ef2aSThomas Huth }
2026fcf5ef2aSThomas Huth break;
2027fcf5ef2aSThomas Huth
2028fcf5ef2aSThomas Huth case GET_ASI_BLOCK:
2029fcf5ef2aSThomas Huth /* Valid for lddfa on aligned registers only. */
20303259b9e2SRichard Henderson if (orig_size == MO_64 && (rd & 7) == 0) {
2031fcf5ef2aSThomas Huth /* The first operation checks required alignment. */
2032287b1152SRichard Henderson addr_tmp = tcg_temp_new();
20331210a036SRichard Henderson d64 = tcg_temp_new_i64();
2034287b1152SRichard Henderson for (int i = 0; ; ++i) {
20351210a036SRichard Henderson tcg_gen_qemu_ld_i64(d64, addr, da->mem_idx,
20363259b9e2SRichard Henderson memop | (i == 0 ? MO_ALIGN_64 : 0));
20371210a036SRichard Henderson gen_store_fpr_D(dc, rd + 2 * i, d64);
2038fcf5ef2aSThomas Huth if (i == 7) {
2039fcf5ef2aSThomas Huth break;
2040fcf5ef2aSThomas Huth }
2041287b1152SRichard Henderson tcg_gen_addi_tl(addr_tmp, addr, 8);
2042287b1152SRichard Henderson addr = addr_tmp;
2043fcf5ef2aSThomas Huth }
2044fcf5ef2aSThomas Huth } else {
2045fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN);
2046fcf5ef2aSThomas Huth }
2047fcf5ef2aSThomas Huth break;
2048fcf5ef2aSThomas Huth
2049fcf5ef2aSThomas Huth case GET_ASI_SHORT:
2050fcf5ef2aSThomas Huth /* Valid for lddfa only. */
20513259b9e2SRichard Henderson if (orig_size == MO_64) {
20521210a036SRichard Henderson d64 = tcg_temp_new_i64();
20531210a036SRichard Henderson tcg_gen_qemu_ld_i64(d64, addr, da->mem_idx, memop | MO_ALIGN);
20541210a036SRichard Henderson gen_store_fpr_D(dc, rd, d64);
2055fcf5ef2aSThomas Huth } else {
2056fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN);
2057fcf5ef2aSThomas Huth }
2058fcf5ef2aSThomas Huth break;
2059fcf5ef2aSThomas Huth
2060fcf5ef2aSThomas Huth default:
2061fcf5ef2aSThomas Huth {
20623259b9e2SRichard Henderson TCGv_i32 r_asi = tcg_constant_i32(da->asi);
20633259b9e2SRichard Henderson TCGv_i32 r_mop = tcg_constant_i32(memop | MO_ALIGN);
2064fcf5ef2aSThomas Huth
2065fcf5ef2aSThomas Huth save_state(dc);
2066fcf5ef2aSThomas Huth /* According to the table in the UA2011 manual, the only
2067fcf5ef2aSThomas Huth other asis that are valid for ldfa/lddfa/ldqfa are
2068fcf5ef2aSThomas Huth the NO_FAULT asis. We still need a helper for these,
2069fcf5ef2aSThomas Huth but we can just use the integer asi helper for them. */
2070fcf5ef2aSThomas Huth switch (size) {
20713259b9e2SRichard Henderson case MO_32:
2072fcf5ef2aSThomas Huth d64 = tcg_temp_new_i64();
2073ad75a51eSRichard Henderson gen_helper_ld_asi(d64, tcg_env, addr, r_asi, r_mop);
2074388a6465SRichard Henderson d32 = tcg_temp_new_i32();
2075fcf5ef2aSThomas Huth tcg_gen_extrl_i64_i32(d32, d64);
2076fcf5ef2aSThomas Huth gen_store_fpr_F(dc, rd, d32);
2077fcf5ef2aSThomas Huth break;
20783259b9e2SRichard Henderson case MO_64:
20791210a036SRichard Henderson d64 = tcg_temp_new_i64();
20801210a036SRichard Henderson gen_helper_ld_asi(d64, tcg_env, addr, r_asi, r_mop);
20811210a036SRichard Henderson gen_store_fpr_D(dc, rd, d64);
2082fcf5ef2aSThomas Huth break;
20833259b9e2SRichard Henderson case MO_128:
2084fcf5ef2aSThomas Huth d64 = tcg_temp_new_i64();
20851210a036SRichard Henderson l64 = tcg_temp_new_i64();
2086ad75a51eSRichard Henderson gen_helper_ld_asi(d64, tcg_env, addr, r_asi, r_mop);
2087287b1152SRichard Henderson addr_tmp = tcg_temp_new();
2088287b1152SRichard Henderson tcg_gen_addi_tl(addr_tmp, addr, 8);
20891210a036SRichard Henderson gen_helper_ld_asi(l64, tcg_env, addr_tmp, r_asi, r_mop);
20901210a036SRichard Henderson gen_store_fpr_D(dc, rd, d64);
20911210a036SRichard Henderson gen_store_fpr_D(dc, rd + 2, l64);
2092fcf5ef2aSThomas Huth break;
2093fcf5ef2aSThomas Huth default:
2094fcf5ef2aSThomas Huth g_assert_not_reached();
2095fcf5ef2aSThomas Huth }
2096fcf5ef2aSThomas Huth }
2097fcf5ef2aSThomas Huth break;
2098fcf5ef2aSThomas Huth }
2099fcf5ef2aSThomas Huth }
2100fcf5ef2aSThomas Huth
gen_stf_asi(DisasContext * dc,DisasASI * da,MemOp orig_size,TCGv addr,int rd)2101287b1152SRichard Henderson static void gen_stf_asi(DisasContext *dc, DisasASI *da, MemOp orig_size,
21023259b9e2SRichard Henderson TCGv addr, int rd)
21033259b9e2SRichard Henderson {
21043259b9e2SRichard Henderson MemOp memop = da->memop;
21053259b9e2SRichard Henderson MemOp size = memop & MO_SIZE;
2106fcf5ef2aSThomas Huth TCGv_i32 d32;
21071210a036SRichard Henderson TCGv_i64 d64;
2108287b1152SRichard Henderson TCGv addr_tmp;
2109fcf5ef2aSThomas Huth
21103259b9e2SRichard Henderson /* TODO: Use 128-bit load/store below. */
21113259b9e2SRichard Henderson if (size == MO_128) {
21123259b9e2SRichard Henderson memop = (memop & ~MO_SIZE) | MO_64;
21133259b9e2SRichard Henderson }
21143259b9e2SRichard Henderson
21153259b9e2SRichard Henderson switch (da->type) {
2116fcf5ef2aSThomas Huth case GET_ASI_EXCP:
2117fcf5ef2aSThomas Huth break;
2118fcf5ef2aSThomas Huth
2119fcf5ef2aSThomas Huth case GET_ASI_DIRECT:
21203259b9e2SRichard Henderson memop |= MO_ALIGN_4;
2121fcf5ef2aSThomas Huth switch (size) {
21223259b9e2SRichard Henderson case MO_32:
2123fcf5ef2aSThomas Huth d32 = gen_load_fpr_F(dc, rd);
21243259b9e2SRichard Henderson tcg_gen_qemu_st_i32(d32, addr, da->mem_idx, memop | MO_ALIGN);
2125fcf5ef2aSThomas Huth break;
21263259b9e2SRichard Henderson case MO_64:
21271210a036SRichard Henderson d64 = gen_load_fpr_D(dc, rd);
21281210a036SRichard Henderson tcg_gen_qemu_st_i64(d64, addr, da->mem_idx, memop | MO_ALIGN_4);
2129fcf5ef2aSThomas Huth break;
21303259b9e2SRichard Henderson case MO_128:
2131fcf5ef2aSThomas Huth /* Only 4-byte alignment required. However, it is legal for the
2132fcf5ef2aSThomas Huth cpu to signal the alignment fault, and the OS trap handler is
2133fcf5ef2aSThomas Huth required to fix it up. Requiring 16-byte alignment here avoids
2134fcf5ef2aSThomas Huth having to probe the second page before performing the first
2135fcf5ef2aSThomas Huth write. */
21361210a036SRichard Henderson d64 = gen_load_fpr_D(dc, rd);
21371210a036SRichard Henderson tcg_gen_qemu_st_i64(d64, addr, da->mem_idx, memop | MO_ALIGN_16);
2138287b1152SRichard Henderson addr_tmp = tcg_temp_new();
2139287b1152SRichard Henderson tcg_gen_addi_tl(addr_tmp, addr, 8);
21401210a036SRichard Henderson d64 = gen_load_fpr_D(dc, rd + 2);
21411210a036SRichard Henderson tcg_gen_qemu_st_i64(d64, addr_tmp, da->mem_idx, memop);
2142fcf5ef2aSThomas Huth break;
2143fcf5ef2aSThomas Huth default:
2144fcf5ef2aSThomas Huth g_assert_not_reached();
2145fcf5ef2aSThomas Huth }
2146fcf5ef2aSThomas Huth break;
2147fcf5ef2aSThomas Huth
2148fcf5ef2aSThomas Huth case GET_ASI_BLOCK:
2149fcf5ef2aSThomas Huth /* Valid for stdfa on aligned registers only. */
21503259b9e2SRichard Henderson if (orig_size == MO_64 && (rd & 7) == 0) {
2151fcf5ef2aSThomas Huth /* The first operation checks required alignment. */
2152287b1152SRichard Henderson addr_tmp = tcg_temp_new();
2153287b1152SRichard Henderson for (int i = 0; ; ++i) {
21541210a036SRichard Henderson d64 = gen_load_fpr_D(dc, rd + 2 * i);
21551210a036SRichard Henderson tcg_gen_qemu_st_i64(d64, addr, da->mem_idx,
21563259b9e2SRichard Henderson memop | (i == 0 ? MO_ALIGN_64 : 0));
2157fcf5ef2aSThomas Huth if (i == 7) {
2158fcf5ef2aSThomas Huth break;
2159fcf5ef2aSThomas Huth }
2160287b1152SRichard Henderson tcg_gen_addi_tl(addr_tmp, addr, 8);
2161287b1152SRichard Henderson addr = addr_tmp;
2162fcf5ef2aSThomas Huth }
2163fcf5ef2aSThomas Huth } else {
2164fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN);
2165fcf5ef2aSThomas Huth }
2166fcf5ef2aSThomas Huth break;
2167fcf5ef2aSThomas Huth
2168fcf5ef2aSThomas Huth case GET_ASI_SHORT:
2169fcf5ef2aSThomas Huth /* Valid for stdfa only. */
21703259b9e2SRichard Henderson if (orig_size == MO_64) {
21711210a036SRichard Henderson d64 = gen_load_fpr_D(dc, rd);
21721210a036SRichard Henderson tcg_gen_qemu_st_i64(d64, addr, da->mem_idx, memop | MO_ALIGN);
2173fcf5ef2aSThomas Huth } else {
2174fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN);
2175fcf5ef2aSThomas Huth }
2176fcf5ef2aSThomas Huth break;
2177fcf5ef2aSThomas Huth
2178fcf5ef2aSThomas Huth default:
2179fcf5ef2aSThomas Huth /* According to the table in the UA2011 manual, the only
2180fcf5ef2aSThomas Huth other asis that are valid for ldfa/lddfa/ldqfa are
2181fcf5ef2aSThomas Huth the PST* asis, which aren't currently handled. */
2182fcf5ef2aSThomas Huth gen_exception(dc, TT_ILL_INSN);
2183fcf5ef2aSThomas Huth break;
2184fcf5ef2aSThomas Huth }
2185fcf5ef2aSThomas Huth }
2186fcf5ef2aSThomas Huth
gen_ldda_asi(DisasContext * dc,DisasASI * da,TCGv addr,int rd)218742071fc1SRichard Henderson static void gen_ldda_asi(DisasContext *dc, DisasASI *da, TCGv addr, int rd)
2188fcf5ef2aSThomas Huth {
2189a76779eeSRichard Henderson TCGv hi = gen_dest_gpr(dc, rd);
2190a76779eeSRichard Henderson TCGv lo = gen_dest_gpr(dc, rd + 1);
2191fcf5ef2aSThomas Huth
2192c03a0fd1SRichard Henderson switch (da->type) {
2193fcf5ef2aSThomas Huth case GET_ASI_EXCP:
2194fcf5ef2aSThomas Huth return;
2195fcf5ef2aSThomas Huth
2196fcf5ef2aSThomas Huth case GET_ASI_DTWINX:
2197ebbbec92SRichard Henderson #ifdef TARGET_SPARC64
2198ebbbec92SRichard Henderson {
2199ebbbec92SRichard Henderson MemOp mop = (da->memop & MO_BSWAP) | MO_128 | MO_ALIGN_16;
2200ebbbec92SRichard Henderson TCGv_i128 t = tcg_temp_new_i128();
2201ebbbec92SRichard Henderson
2202ebbbec92SRichard Henderson tcg_gen_qemu_ld_i128(t, addr, da->mem_idx, mop);
2203ebbbec92SRichard Henderson /*
2204ebbbec92SRichard Henderson * Note that LE twinx acts as if each 64-bit register result is
2205ebbbec92SRichard Henderson * byte swapped. We perform one 128-bit LE load, so must swap
2206ebbbec92SRichard Henderson * the order of the writebacks.
2207ebbbec92SRichard Henderson */
2208ebbbec92SRichard Henderson if ((mop & MO_BSWAP) == MO_TE) {
2209ebbbec92SRichard Henderson tcg_gen_extr_i128_i64(lo, hi, t);
2210ebbbec92SRichard Henderson } else {
2211ebbbec92SRichard Henderson tcg_gen_extr_i128_i64(hi, lo, t);
2212ebbbec92SRichard Henderson }
2213ebbbec92SRichard Henderson }
2214fcf5ef2aSThomas Huth break;
2215ebbbec92SRichard Henderson #else
2216ebbbec92SRichard Henderson g_assert_not_reached();
2217ebbbec92SRichard Henderson #endif
2218fcf5ef2aSThomas Huth
2219fcf5ef2aSThomas Huth case GET_ASI_DIRECT:
2220fcf5ef2aSThomas Huth {
2221fcf5ef2aSThomas Huth TCGv_i64 tmp = tcg_temp_new_i64();
2222fcf5ef2aSThomas Huth
2223c03a0fd1SRichard Henderson tcg_gen_qemu_ld_i64(tmp, addr, da->mem_idx, da->memop | MO_ALIGN);
2224fcf5ef2aSThomas Huth
2225fcf5ef2aSThomas Huth /* Note that LE ldda acts as if each 32-bit register
2226fcf5ef2aSThomas Huth result is byte swapped. Having just performed one
2227fcf5ef2aSThomas Huth 64-bit bswap, we need now to swap the writebacks. */
2228c03a0fd1SRichard Henderson if ((da->memop & MO_BSWAP) == MO_TE) {
2229a76779eeSRichard Henderson tcg_gen_extr_i64_tl(lo, hi, tmp);
2230fcf5ef2aSThomas Huth } else {
2231a76779eeSRichard Henderson tcg_gen_extr_i64_tl(hi, lo, tmp);
2232fcf5ef2aSThomas Huth }
2233fcf5ef2aSThomas Huth }
2234fcf5ef2aSThomas Huth break;
2235fcf5ef2aSThomas Huth
22362786a3f8SRichard Henderson case GET_ASI_CODE:
22372786a3f8SRichard Henderson #if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
22382786a3f8SRichard Henderson {
22392786a3f8SRichard Henderson MemOpIdx oi = make_memop_idx(da->memop, da->mem_idx);
22402786a3f8SRichard Henderson TCGv_i64 tmp = tcg_temp_new_i64();
22412786a3f8SRichard Henderson
22422786a3f8SRichard Henderson gen_helper_ld_code(tmp, tcg_env, addr, tcg_constant_i32(oi));
22432786a3f8SRichard Henderson
22442786a3f8SRichard Henderson /* See above. */
22452786a3f8SRichard Henderson if ((da->memop & MO_BSWAP) == MO_TE) {
22462786a3f8SRichard Henderson tcg_gen_extr_i64_tl(lo, hi, tmp);
22472786a3f8SRichard Henderson } else {
22482786a3f8SRichard Henderson tcg_gen_extr_i64_tl(hi, lo, tmp);
22492786a3f8SRichard Henderson }
22502786a3f8SRichard Henderson }
22512786a3f8SRichard Henderson break;
22522786a3f8SRichard Henderson #else
22532786a3f8SRichard Henderson g_assert_not_reached();
22542786a3f8SRichard Henderson #endif
22552786a3f8SRichard Henderson
2256fcf5ef2aSThomas Huth default:
2257fcf5ef2aSThomas Huth /* ??? In theory we've handled all of the ASIs that are valid
2258fcf5ef2aSThomas Huth for ldda, and this should raise DAE_invalid_asi. However,
2259fcf5ef2aSThomas Huth real hardware allows others. This can be seen with e.g.
2260fcf5ef2aSThomas Huth FreeBSD 10.3 wrt ASI_IC_TAG. */
2261fcf5ef2aSThomas Huth {
2262c03a0fd1SRichard Henderson TCGv_i32 r_asi = tcg_constant_i32(da->asi);
2263c03a0fd1SRichard Henderson TCGv_i32 r_mop = tcg_constant_i32(da->memop);
2264fcf5ef2aSThomas Huth TCGv_i64 tmp = tcg_temp_new_i64();
2265fcf5ef2aSThomas Huth
2266fcf5ef2aSThomas Huth save_state(dc);
2267ad75a51eSRichard Henderson gen_helper_ld_asi(tmp, tcg_env, addr, r_asi, r_mop);
2268fcf5ef2aSThomas Huth
2269fcf5ef2aSThomas Huth /* See above. */
2270c03a0fd1SRichard Henderson if ((da->memop & MO_BSWAP) == MO_TE) {
2271a76779eeSRichard Henderson tcg_gen_extr_i64_tl(lo, hi, tmp);
2272fcf5ef2aSThomas Huth } else {
2273a76779eeSRichard Henderson tcg_gen_extr_i64_tl(hi, lo, tmp);
2274fcf5ef2aSThomas Huth }
2275fcf5ef2aSThomas Huth }
2276fcf5ef2aSThomas Huth break;
2277fcf5ef2aSThomas Huth }
2278fcf5ef2aSThomas Huth
2279fcf5ef2aSThomas Huth gen_store_gpr(dc, rd, hi);
2280fcf5ef2aSThomas Huth gen_store_gpr(dc, rd + 1, lo);
2281fcf5ef2aSThomas Huth }
2282fcf5ef2aSThomas Huth
gen_stda_asi(DisasContext * dc,DisasASI * da,TCGv addr,int rd)228342071fc1SRichard Henderson static void gen_stda_asi(DisasContext *dc, DisasASI *da, TCGv addr, int rd)
2284c03a0fd1SRichard Henderson {
2285c03a0fd1SRichard Henderson TCGv hi = gen_load_gpr(dc, rd);
2286fcf5ef2aSThomas Huth TCGv lo = gen_load_gpr(dc, rd + 1);
2287fcf5ef2aSThomas Huth
2288c03a0fd1SRichard Henderson switch (da->type) {
2289fcf5ef2aSThomas Huth case GET_ASI_EXCP:
2290fcf5ef2aSThomas Huth break;
2291fcf5ef2aSThomas Huth
2292fcf5ef2aSThomas Huth case GET_ASI_DTWINX:
2293ebbbec92SRichard Henderson #ifdef TARGET_SPARC64
2294ebbbec92SRichard Henderson {
2295ebbbec92SRichard Henderson MemOp mop = (da->memop & MO_BSWAP) | MO_128 | MO_ALIGN_16;
2296ebbbec92SRichard Henderson TCGv_i128 t = tcg_temp_new_i128();
2297ebbbec92SRichard Henderson
2298ebbbec92SRichard Henderson /*
2299ebbbec92SRichard Henderson * Note that LE twinx acts as if each 64-bit register result is
2300ebbbec92SRichard Henderson * byte swapped. We perform one 128-bit LE store, so must swap
2301ebbbec92SRichard Henderson * the order of the construction.
2302ebbbec92SRichard Henderson */
2303ebbbec92SRichard Henderson if ((mop & MO_BSWAP) == MO_TE) {
2304ebbbec92SRichard Henderson tcg_gen_concat_i64_i128(t, lo, hi);
2305ebbbec92SRichard Henderson } else {
2306ebbbec92SRichard Henderson tcg_gen_concat_i64_i128(t, hi, lo);
2307ebbbec92SRichard Henderson }
2308ebbbec92SRichard Henderson tcg_gen_qemu_st_i128(t, addr, da->mem_idx, mop);
2309ebbbec92SRichard Henderson }
2310fcf5ef2aSThomas Huth break;
2311ebbbec92SRichard Henderson #else
2312ebbbec92SRichard Henderson g_assert_not_reached();
2313ebbbec92SRichard Henderson #endif
2314fcf5ef2aSThomas Huth
2315fcf5ef2aSThomas Huth case GET_ASI_DIRECT:
2316fcf5ef2aSThomas Huth {
2317fcf5ef2aSThomas Huth TCGv_i64 t64 = tcg_temp_new_i64();
2318fcf5ef2aSThomas Huth
2319fcf5ef2aSThomas Huth /* Note that LE stda acts as if each 32-bit register result is
2320fcf5ef2aSThomas Huth byte swapped. We will perform one 64-bit LE store, so now
2321fcf5ef2aSThomas Huth we must swap the order of the construction. */
2322c03a0fd1SRichard Henderson if ((da->memop & MO_BSWAP) == MO_TE) {
2323a76779eeSRichard Henderson tcg_gen_concat_tl_i64(t64, lo, hi);
2324fcf5ef2aSThomas Huth } else {
2325a76779eeSRichard Henderson tcg_gen_concat_tl_i64(t64, hi, lo);
2326fcf5ef2aSThomas Huth }
2327c03a0fd1SRichard Henderson tcg_gen_qemu_st_i64(t64, addr, da->mem_idx, da->memop | MO_ALIGN);
2328fcf5ef2aSThomas Huth }
2329fcf5ef2aSThomas Huth break;
2330fcf5ef2aSThomas Huth
2331a76779eeSRichard Henderson case GET_ASI_BFILL:
2332a76779eeSRichard Henderson assert(TARGET_LONG_BITS == 32);
233354c3e953SRichard Henderson /*
233454c3e953SRichard Henderson * Store 32 bytes of [rd:rd+1] to ADDR.
233554c3e953SRichard Henderson * See comments for GET_ASI_COPY above.
233654c3e953SRichard Henderson */
2337a76779eeSRichard Henderson {
233854c3e953SRichard Henderson MemOp mop = MO_TE | MO_128 | MO_ATOM_IFALIGN_PAIR;
233954c3e953SRichard Henderson TCGv_i64 t8 = tcg_temp_new_i64();
234054c3e953SRichard Henderson TCGv_i128 t16 = tcg_temp_new_i128();
234154c3e953SRichard Henderson TCGv daddr = tcg_temp_new();
2342a76779eeSRichard Henderson
234354c3e953SRichard Henderson tcg_gen_concat_tl_i64(t8, lo, hi);
234454c3e953SRichard Henderson tcg_gen_concat_i64_i128(t16, t8, t8);
234554c3e953SRichard Henderson tcg_gen_andi_tl(daddr, addr, -32);
234654c3e953SRichard Henderson tcg_gen_qemu_st_i128(t16, daddr, da->mem_idx, mop);
234754c3e953SRichard Henderson tcg_gen_addi_tl(daddr, daddr, 16);
234854c3e953SRichard Henderson tcg_gen_qemu_st_i128(t16, daddr, da->mem_idx, mop);
2349a76779eeSRichard Henderson }
2350a76779eeSRichard Henderson break;
2351a76779eeSRichard Henderson
2352fcf5ef2aSThomas Huth default:
2353fcf5ef2aSThomas Huth /* ??? In theory we've handled all of the ASIs that are valid
2354fcf5ef2aSThomas Huth for stda, and this should raise DAE_invalid_asi. */
2355fcf5ef2aSThomas Huth {
2356c03a0fd1SRichard Henderson TCGv_i32 r_asi = tcg_constant_i32(da->asi);
2357c03a0fd1SRichard Henderson TCGv_i32 r_mop = tcg_constant_i32(da->memop);
2358fcf5ef2aSThomas Huth TCGv_i64 t64 = tcg_temp_new_i64();
2359fcf5ef2aSThomas Huth
2360fcf5ef2aSThomas Huth /* See above. */
2361c03a0fd1SRichard Henderson if ((da->memop & MO_BSWAP) == MO_TE) {
2362a76779eeSRichard Henderson tcg_gen_concat_tl_i64(t64, lo, hi);
2363fcf5ef2aSThomas Huth } else {
2364a76779eeSRichard Henderson tcg_gen_concat_tl_i64(t64, hi, lo);
2365fcf5ef2aSThomas Huth }
2366fcf5ef2aSThomas Huth
2367fcf5ef2aSThomas Huth save_state(dc);
2368ad75a51eSRichard Henderson gen_helper_st_asi(tcg_env, addr, t64, r_asi, r_mop);
2369fcf5ef2aSThomas Huth }
2370fcf5ef2aSThomas Huth break;
2371fcf5ef2aSThomas Huth }
2372fcf5ef2aSThomas Huth }
2373fcf5ef2aSThomas Huth
gen_fmovs(DisasContext * dc,DisasCompare * cmp,int rd,int rs)2374fcf5ef2aSThomas Huth static void gen_fmovs(DisasContext *dc, DisasCompare *cmp, int rd, int rs)
2375fcf5ef2aSThomas Huth {
2376f7ec8155SRichard Henderson #ifdef TARGET_SPARC64
2377fcf5ef2aSThomas Huth TCGv_i32 c32, zero, dst, s1, s2;
2378dd7dbfccSRichard Henderson TCGv_i64 c64 = tcg_temp_new_i64();
2379fcf5ef2aSThomas Huth
2380fcf5ef2aSThomas Huth /* We have two choices here: extend the 32 bit data and use movcond_i64,
2381fcf5ef2aSThomas Huth or fold the comparison down to 32 bits and use movcond_i32. Choose
2382fcf5ef2aSThomas Huth the later. */
2383fcf5ef2aSThomas Huth c32 = tcg_temp_new_i32();
2384c8507ebfSRichard Henderson tcg_gen_setcondi_i64(cmp->cond, c64, cmp->c1, cmp->c2);
2385fcf5ef2aSThomas Huth tcg_gen_extrl_i64_i32(c32, c64);
2386fcf5ef2aSThomas Huth
2387fcf5ef2aSThomas Huth s1 = gen_load_fpr_F(dc, rs);
2388fcf5ef2aSThomas Huth s2 = gen_load_fpr_F(dc, rd);
2389388a6465SRichard Henderson dst = tcg_temp_new_i32();
239000ab7e61SRichard Henderson zero = tcg_constant_i32(0);
2391fcf5ef2aSThomas Huth
2392fcf5ef2aSThomas Huth tcg_gen_movcond_i32(TCG_COND_NE, dst, c32, zero, s1, s2);
2393fcf5ef2aSThomas Huth
2394fcf5ef2aSThomas Huth gen_store_fpr_F(dc, rd, dst);
2395f7ec8155SRichard Henderson #else
2396f7ec8155SRichard Henderson qemu_build_not_reached();
2397f7ec8155SRichard Henderson #endif
2398fcf5ef2aSThomas Huth }
2399fcf5ef2aSThomas Huth
gen_fmovd(DisasContext * dc,DisasCompare * cmp,int rd,int rs)2400fcf5ef2aSThomas Huth static void gen_fmovd(DisasContext *dc, DisasCompare *cmp, int rd, int rs)
2401fcf5ef2aSThomas Huth {
2402f7ec8155SRichard Henderson #ifdef TARGET_SPARC64
240352f46d46SRichard Henderson TCGv_i64 dst = tcg_temp_new_i64();
2404c8507ebfSRichard Henderson tcg_gen_movcond_i64(cmp->cond, dst, cmp->c1, tcg_constant_tl(cmp->c2),
2405fcf5ef2aSThomas Huth gen_load_fpr_D(dc, rs),
2406fcf5ef2aSThomas Huth gen_load_fpr_D(dc, rd));
2407fcf5ef2aSThomas Huth gen_store_fpr_D(dc, rd, dst);
2408f7ec8155SRichard Henderson #else
2409f7ec8155SRichard Henderson qemu_build_not_reached();
2410f7ec8155SRichard Henderson #endif
2411fcf5ef2aSThomas Huth }
2412fcf5ef2aSThomas Huth
gen_fmovq(DisasContext * dc,DisasCompare * cmp,int rd,int rs)2413fcf5ef2aSThomas Huth static void gen_fmovq(DisasContext *dc, DisasCompare *cmp, int rd, int rs)
2414fcf5ef2aSThomas Huth {
2415f7ec8155SRichard Henderson #ifdef TARGET_SPARC64
2416c8507ebfSRichard Henderson TCGv c2 = tcg_constant_tl(cmp->c2);
24171210a036SRichard Henderson TCGv_i64 h = tcg_temp_new_i64();
24181210a036SRichard Henderson TCGv_i64 l = tcg_temp_new_i64();
2419fcf5ef2aSThomas Huth
24201210a036SRichard Henderson tcg_gen_movcond_i64(cmp->cond, h, cmp->c1, c2,
24211210a036SRichard Henderson gen_load_fpr_D(dc, rs),
24221210a036SRichard Henderson gen_load_fpr_D(dc, rd));
24231210a036SRichard Henderson tcg_gen_movcond_i64(cmp->cond, l, cmp->c1, c2,
24241210a036SRichard Henderson gen_load_fpr_D(dc, rs + 2),
24251210a036SRichard Henderson gen_load_fpr_D(dc, rd + 2));
24261210a036SRichard Henderson gen_store_fpr_D(dc, rd, h);
24271210a036SRichard Henderson gen_store_fpr_D(dc, rd + 2, l);
2428f7ec8155SRichard Henderson #else
2429f7ec8155SRichard Henderson qemu_build_not_reached();
2430f7ec8155SRichard Henderson #endif
2431fcf5ef2aSThomas Huth }
2432fcf5ef2aSThomas Huth
2433f7ec8155SRichard Henderson #ifdef TARGET_SPARC64
gen_load_trap_state_at_tl(TCGv_ptr r_tsptr)24345d617bfbSRichard Henderson static void gen_load_trap_state_at_tl(TCGv_ptr r_tsptr)
2435fcf5ef2aSThomas Huth {
2436fcf5ef2aSThomas Huth TCGv_i32 r_tl = tcg_temp_new_i32();
2437fcf5ef2aSThomas Huth
2438fcf5ef2aSThomas Huth /* load env->tl into r_tl */
2439ad75a51eSRichard Henderson tcg_gen_ld_i32(r_tl, tcg_env, offsetof(CPUSPARCState, tl));
2440fcf5ef2aSThomas Huth
2441fcf5ef2aSThomas Huth /* tl = [0 ... MAXTL_MASK] where MAXTL_MASK must be power of 2 */
2442fcf5ef2aSThomas Huth tcg_gen_andi_i32(r_tl, r_tl, MAXTL_MASK);
2443fcf5ef2aSThomas Huth
2444fcf5ef2aSThomas Huth /* calculate offset to current trap state from env->ts, reuse r_tl */
2445fcf5ef2aSThomas Huth tcg_gen_muli_i32(r_tl, r_tl, sizeof (trap_state));
2446ad75a51eSRichard Henderson tcg_gen_addi_ptr(r_tsptr, tcg_env, offsetof(CPUSPARCState, ts));
2447fcf5ef2aSThomas Huth
2448fcf5ef2aSThomas Huth /* tsptr = env->ts[env->tl & MAXTL_MASK] */
2449fcf5ef2aSThomas Huth {
2450fcf5ef2aSThomas Huth TCGv_ptr r_tl_tmp = tcg_temp_new_ptr();
2451fcf5ef2aSThomas Huth tcg_gen_ext_i32_ptr(r_tl_tmp, r_tl);
2452fcf5ef2aSThomas Huth tcg_gen_add_ptr(r_tsptr, r_tsptr, r_tl_tmp);
2453fcf5ef2aSThomas Huth }
2454fcf5ef2aSThomas Huth }
2455fcf5ef2aSThomas Huth #endif
2456fcf5ef2aSThomas Huth
extract_dfpreg(DisasContext * dc,int x)245706c060d9SRichard Henderson static int extract_dfpreg(DisasContext *dc, int x)
245806c060d9SRichard Henderson {
24590bba7572SRichard Henderson int r = x & 0x1e;
24600bba7572SRichard Henderson #ifdef TARGET_SPARC64
24610bba7572SRichard Henderson r |= (x & 1) << 5;
24620bba7572SRichard Henderson #endif
24630bba7572SRichard Henderson return r;
246406c060d9SRichard Henderson }
246506c060d9SRichard Henderson
extract_qfpreg(DisasContext * dc,int x)246606c060d9SRichard Henderson static int extract_qfpreg(DisasContext *dc, int x)
246706c060d9SRichard Henderson {
24680bba7572SRichard Henderson int r = x & 0x1c;
24690bba7572SRichard Henderson #ifdef TARGET_SPARC64
24700bba7572SRichard Henderson r |= (x & 1) << 5;
24710bba7572SRichard Henderson #endif
24720bba7572SRichard Henderson return r;
247306c060d9SRichard Henderson }
247406c060d9SRichard Henderson
2475878cc677SRichard Henderson /* Include the auto-generated decoder. */
2476878cc677SRichard Henderson #include "decode-insns.c.inc"
2477878cc677SRichard Henderson
2478878cc677SRichard Henderson #define TRANS(NAME, AVAIL, FUNC, ...) \
2479878cc677SRichard Henderson static bool trans_##NAME(DisasContext *dc, arg_##NAME *a) \
2480878cc677SRichard Henderson { return avail_##AVAIL(dc) && FUNC(dc, __VA_ARGS__); }
2481878cc677SRichard Henderson
2482878cc677SRichard Henderson #define avail_ALL(C) true
2483878cc677SRichard Henderson #ifdef TARGET_SPARC64
2484878cc677SRichard Henderson # define avail_32(C) false
2485af25071cSRichard Henderson # define avail_ASR17(C) false
2486d0a11d25SRichard Henderson # define avail_CASA(C) true
2487c2636853SRichard Henderson # define avail_DIV(C) true
2488b5372650SRichard Henderson # define avail_MUL(C) true
24890faef01bSRichard Henderson # define avail_POWERDOWN(C) false
2490878cc677SRichard Henderson # define avail_64(C) true
24914fd71d19SRichard Henderson # define avail_FMAF(C) ((C)->def->features & CPU_FEATURE_FMAF)
24925d617bfbSRichard Henderson # define avail_GL(C) ((C)->def->features & CPU_FEATURE_GL)
2493af25071cSRichard Henderson # define avail_HYPV(C) ((C)->def->features & CPU_FEATURE_HYPV)
249468a414e9SRichard Henderson # define avail_IMA(C) ((C)->def->features & CPU_FEATURE_IMA)
2495b88ce6f2SRichard Henderson # define avail_VIS1(C) ((C)->def->features & CPU_FEATURE_VIS1)
2496b88ce6f2SRichard Henderson # define avail_VIS2(C) ((C)->def->features & CPU_FEATURE_VIS2)
24973335a048SRichard Henderson # define avail_VIS3(C) ((C)->def->features & CPU_FEATURE_VIS3)
24983335a048SRichard Henderson # define avail_VIS3B(C) avail_VIS3(C)
249990b1433dSRichard Henderson # define avail_VIS4(C) ((C)->def->features & CPU_FEATURE_VIS4)
2500878cc677SRichard Henderson #else
2501878cc677SRichard Henderson # define avail_32(C) true
2502af25071cSRichard Henderson # define avail_ASR17(C) ((C)->def->features & CPU_FEATURE_ASR17)
2503d0a11d25SRichard Henderson # define avail_CASA(C) ((C)->def->features & CPU_FEATURE_CASA)
2504c2636853SRichard Henderson # define avail_DIV(C) ((C)->def->features & CPU_FEATURE_DIV)
2505b5372650SRichard Henderson # define avail_MUL(C) ((C)->def->features & CPU_FEATURE_MUL)
25060faef01bSRichard Henderson # define avail_POWERDOWN(C) ((C)->def->features & CPU_FEATURE_POWERDOWN)
2507878cc677SRichard Henderson # define avail_64(C) false
25084fd71d19SRichard Henderson # define avail_FMAF(C) false
25095d617bfbSRichard Henderson # define avail_GL(C) false
2510af25071cSRichard Henderson # define avail_HYPV(C) false
251168a414e9SRichard Henderson # define avail_IMA(C) false
2512b88ce6f2SRichard Henderson # define avail_VIS1(C) false
2513b88ce6f2SRichard Henderson # define avail_VIS2(C) false
25143335a048SRichard Henderson # define avail_VIS3(C) false
25153335a048SRichard Henderson # define avail_VIS3B(C) false
251690b1433dSRichard Henderson # define avail_VIS4(C) false
2517878cc677SRichard Henderson #endif
2518878cc677SRichard Henderson
2519878cc677SRichard Henderson /* Default case for non jump instructions. */
advance_pc(DisasContext * dc)2520878cc677SRichard Henderson static bool advance_pc(DisasContext *dc)
2521878cc677SRichard Henderson {
25224a8d145dSRichard Henderson TCGLabel *l1;
25234a8d145dSRichard Henderson
252489527e3aSRichard Henderson finishing_insn(dc);
252589527e3aSRichard Henderson
2526878cc677SRichard Henderson if (dc->npc & 3) {
2527878cc677SRichard Henderson switch (dc->npc) {
2528878cc677SRichard Henderson case DYNAMIC_PC:
2529878cc677SRichard Henderson case DYNAMIC_PC_LOOKUP:
2530878cc677SRichard Henderson dc->pc = dc->npc;
2531444d8b30SRichard Henderson tcg_gen_mov_tl(cpu_pc, cpu_npc);
2532444d8b30SRichard Henderson tcg_gen_addi_tl(cpu_npc, cpu_npc, 4);
2533878cc677SRichard Henderson break;
25344a8d145dSRichard Henderson
2535878cc677SRichard Henderson case JUMP_PC:
2536878cc677SRichard Henderson /* we can do a static jump */
25374a8d145dSRichard Henderson l1 = gen_new_label();
2538533f042fSRichard Henderson tcg_gen_brcondi_tl(dc->jump.cond, dc->jump.c1, dc->jump.c2, l1);
25394a8d145dSRichard Henderson
25404a8d145dSRichard Henderson /* jump not taken */
25414a8d145dSRichard Henderson gen_goto_tb(dc, 1, dc->jump_pc[1], dc->jump_pc[1] + 4);
25424a8d145dSRichard Henderson
25434a8d145dSRichard Henderson /* jump taken */
25444a8d145dSRichard Henderson gen_set_label(l1);
25454a8d145dSRichard Henderson gen_goto_tb(dc, 0, dc->jump_pc[0], dc->jump_pc[0] + 4);
25464a8d145dSRichard Henderson
2547878cc677SRichard Henderson dc->base.is_jmp = DISAS_NORETURN;
2548878cc677SRichard Henderson break;
25494a8d145dSRichard Henderson
2550878cc677SRichard Henderson default:
2551878cc677SRichard Henderson g_assert_not_reached();
2552878cc677SRichard Henderson }
2553878cc677SRichard Henderson } else {
2554878cc677SRichard Henderson dc->pc = dc->npc;
2555878cc677SRichard Henderson dc->npc = dc->npc + 4;
2556878cc677SRichard Henderson }
2557878cc677SRichard Henderson return true;
2558878cc677SRichard Henderson }
2559878cc677SRichard Henderson
25606d2a0768SRichard Henderson /*
25616d2a0768SRichard Henderson * Major opcodes 00 and 01 -- branches, call, and sethi
25626d2a0768SRichard Henderson */
25636d2a0768SRichard Henderson
advance_jump_cond(DisasContext * dc,DisasCompare * cmp,bool annul,int disp)25649d4e2bc7SRichard Henderson static bool advance_jump_cond(DisasContext *dc, DisasCompare *cmp,
25653951b7a8SRichard Henderson bool annul, int disp)
2566276567aaSRichard Henderson {
25673951b7a8SRichard Henderson target_ulong dest = address_mask_i(dc, dc->pc + disp * 4);
2568c76c8045SRichard Henderson target_ulong npc;
2569c76c8045SRichard Henderson
257089527e3aSRichard Henderson finishing_insn(dc);
257189527e3aSRichard Henderson
25722d9bb237SRichard Henderson if (cmp->cond == TCG_COND_ALWAYS) {
25732d9bb237SRichard Henderson if (annul) {
25742d9bb237SRichard Henderson dc->pc = dest;
25752d9bb237SRichard Henderson dc->npc = dest + 4;
25762d9bb237SRichard Henderson } else {
25772d9bb237SRichard Henderson gen_mov_pc_npc(dc);
25782d9bb237SRichard Henderson dc->npc = dest;
25792d9bb237SRichard Henderson }
25802d9bb237SRichard Henderson return true;
25812d9bb237SRichard Henderson }
25822d9bb237SRichard Henderson
25832d9bb237SRichard Henderson if (cmp->cond == TCG_COND_NEVER) {
25842d9bb237SRichard Henderson npc = dc->npc;
25852d9bb237SRichard Henderson if (npc & 3) {
25862d9bb237SRichard Henderson gen_mov_pc_npc(dc);
25872d9bb237SRichard Henderson if (annul) {
25882d9bb237SRichard Henderson tcg_gen_addi_tl(cpu_pc, cpu_pc, 4);
25892d9bb237SRichard Henderson }
25902d9bb237SRichard Henderson tcg_gen_addi_tl(cpu_npc, cpu_pc, 4);
25912d9bb237SRichard Henderson } else {
25922d9bb237SRichard Henderson dc->pc = npc + (annul ? 4 : 0);
25932d9bb237SRichard Henderson dc->npc = dc->pc + 4;
25942d9bb237SRichard Henderson }
25952d9bb237SRichard Henderson return true;
25962d9bb237SRichard Henderson }
25972d9bb237SRichard Henderson
2598c76c8045SRichard Henderson flush_cond(dc);
2599c76c8045SRichard Henderson npc = dc->npc;
26006b3e4cc6SRichard Henderson
2601276567aaSRichard Henderson if (annul) {
26026b3e4cc6SRichard Henderson TCGLabel *l1 = gen_new_label();
26036b3e4cc6SRichard Henderson
2604c8507ebfSRichard Henderson tcg_gen_brcondi_tl(tcg_invert_cond(cmp->cond), cmp->c1, cmp->c2, l1);
26056b3e4cc6SRichard Henderson gen_goto_tb(dc, 0, npc, dest);
26066b3e4cc6SRichard Henderson gen_set_label(l1);
26076b3e4cc6SRichard Henderson gen_goto_tb(dc, 1, npc + 4, npc + 8);
26086b3e4cc6SRichard Henderson
26096b3e4cc6SRichard Henderson dc->base.is_jmp = DISAS_NORETURN;
2610276567aaSRichard Henderson } else {
26116b3e4cc6SRichard Henderson if (npc & 3) {
26126b3e4cc6SRichard Henderson switch (npc) {
26136b3e4cc6SRichard Henderson case DYNAMIC_PC:
26146b3e4cc6SRichard Henderson case DYNAMIC_PC_LOOKUP:
26156b3e4cc6SRichard Henderson tcg_gen_mov_tl(cpu_pc, cpu_npc);
26166b3e4cc6SRichard Henderson tcg_gen_addi_tl(cpu_npc, cpu_npc, 4);
26179d4e2bc7SRichard Henderson tcg_gen_movcond_tl(cmp->cond, cpu_npc,
2618c8507ebfSRichard Henderson cmp->c1, tcg_constant_tl(cmp->c2),
26196b3e4cc6SRichard Henderson tcg_constant_tl(dest), cpu_npc);
26206b3e4cc6SRichard Henderson dc->pc = npc;
26216b3e4cc6SRichard Henderson break;
26226b3e4cc6SRichard Henderson default:
26236b3e4cc6SRichard Henderson g_assert_not_reached();
26246b3e4cc6SRichard Henderson }
26256b3e4cc6SRichard Henderson } else {
26266b3e4cc6SRichard Henderson dc->pc = npc;
2627533f042fSRichard Henderson dc->npc = JUMP_PC;
2628533f042fSRichard Henderson dc->jump = *cmp;
26296b3e4cc6SRichard Henderson dc->jump_pc[0] = dest;
26306b3e4cc6SRichard Henderson dc->jump_pc[1] = npc + 4;
2631dd7dbfccSRichard Henderson
2632dd7dbfccSRichard Henderson /* The condition for cpu_cond is always NE -- normalize. */
2633dd7dbfccSRichard Henderson if (cmp->cond == TCG_COND_NE) {
2634c8507ebfSRichard Henderson tcg_gen_xori_tl(cpu_cond, cmp->c1, cmp->c2);
26359d4e2bc7SRichard Henderson } else {
2636c8507ebfSRichard Henderson tcg_gen_setcondi_tl(cmp->cond, cpu_cond, cmp->c1, cmp->c2);
26379d4e2bc7SRichard Henderson }
263889527e3aSRichard Henderson dc->cpu_cond_live = true;
26396b3e4cc6SRichard Henderson }
2640276567aaSRichard Henderson }
2641276567aaSRichard Henderson return true;
2642276567aaSRichard Henderson }
2643276567aaSRichard Henderson
raise_priv(DisasContext * dc)2644af25071cSRichard Henderson static bool raise_priv(DisasContext *dc)
2645af25071cSRichard Henderson {
2646af25071cSRichard Henderson gen_exception(dc, TT_PRIV_INSN);
2647af25071cSRichard Henderson return true;
2648af25071cSRichard Henderson }
2649af25071cSRichard Henderson
raise_unimpfpop(DisasContext * dc)265006c060d9SRichard Henderson static bool raise_unimpfpop(DisasContext *dc)
265106c060d9SRichard Henderson {
265206c060d9SRichard Henderson gen_op_fpexception_im(dc, FSR_FTT_UNIMPFPOP);
265306c060d9SRichard Henderson return true;
265406c060d9SRichard Henderson }
265506c060d9SRichard Henderson
gen_trap_float128(DisasContext * dc)265606c060d9SRichard Henderson static bool gen_trap_float128(DisasContext *dc)
265706c060d9SRichard Henderson {
265806c060d9SRichard Henderson if (dc->def->features & CPU_FEATURE_FLOAT128) {
265906c060d9SRichard Henderson return false;
266006c060d9SRichard Henderson }
266106c060d9SRichard Henderson return raise_unimpfpop(dc);
266206c060d9SRichard Henderson }
266306c060d9SRichard Henderson
do_bpcc(DisasContext * dc,arg_bcc * a)2664276567aaSRichard Henderson static bool do_bpcc(DisasContext *dc, arg_bcc *a)
2665276567aaSRichard Henderson {
26661ea9c62aSRichard Henderson DisasCompare cmp;
2667276567aaSRichard Henderson
26681ea9c62aSRichard Henderson gen_compare(&cmp, a->cc, a->cond, dc);
26693951b7a8SRichard Henderson return advance_jump_cond(dc, &cmp, a->a, a->i);
2670276567aaSRichard Henderson }
2671276567aaSRichard Henderson
TRANS(Bicc,ALL,do_bpcc,a)2672276567aaSRichard Henderson TRANS(Bicc, ALL, do_bpcc, a)
2673276567aaSRichard Henderson TRANS(BPcc, 64, do_bpcc, a)
2674276567aaSRichard Henderson
267545196ea4SRichard Henderson static bool do_fbpfcc(DisasContext *dc, arg_bcc *a)
267645196ea4SRichard Henderson {
2677d5471936SRichard Henderson DisasCompare cmp;
267845196ea4SRichard Henderson
2679*d2a0c3a7SRichard Henderson if (gen_trap_if_nofpu_fpexception(dc)) {
268045196ea4SRichard Henderson return true;
268145196ea4SRichard Henderson }
2682d5471936SRichard Henderson gen_fcompare(&cmp, a->cc, a->cond);
26833951b7a8SRichard Henderson return advance_jump_cond(dc, &cmp, a->a, a->i);
268445196ea4SRichard Henderson }
268545196ea4SRichard Henderson
268645196ea4SRichard Henderson TRANS(FBPfcc, 64, do_fbpfcc, a)
TRANS(FBfcc,ALL,do_fbpfcc,a)268745196ea4SRichard Henderson TRANS(FBfcc, ALL, do_fbpfcc, a)
268845196ea4SRichard Henderson
2689ab9ffe98SRichard Henderson static bool trans_BPr(DisasContext *dc, arg_BPr *a)
2690ab9ffe98SRichard Henderson {
2691ab9ffe98SRichard Henderson DisasCompare cmp;
2692ab9ffe98SRichard Henderson
2693ab9ffe98SRichard Henderson if (!avail_64(dc)) {
2694ab9ffe98SRichard Henderson return false;
2695ab9ffe98SRichard Henderson }
26962c4f56c9SRichard Henderson if (!gen_compare_reg(&cmp, a->cond, gen_load_gpr(dc, a->rs1))) {
2697ab9ffe98SRichard Henderson return false;
2698ab9ffe98SRichard Henderson }
26993951b7a8SRichard Henderson return advance_jump_cond(dc, &cmp, a->a, a->i);
2700ab9ffe98SRichard Henderson }
2701ab9ffe98SRichard Henderson
trans_CALL(DisasContext * dc,arg_CALL * a)270223ada1b1SRichard Henderson static bool trans_CALL(DisasContext *dc, arg_CALL *a)
270323ada1b1SRichard Henderson {
270423ada1b1SRichard Henderson target_long target = address_mask_i(dc, dc->pc + a->i * 4);
270523ada1b1SRichard Henderson
270623ada1b1SRichard Henderson gen_store_gpr(dc, 15, tcg_constant_tl(dc->pc));
270723ada1b1SRichard Henderson gen_mov_pc_npc(dc);
270823ada1b1SRichard Henderson dc->npc = target;
270923ada1b1SRichard Henderson return true;
271023ada1b1SRichard Henderson }
271123ada1b1SRichard Henderson
trans_NCP(DisasContext * dc,arg_NCP * a)271245196ea4SRichard Henderson static bool trans_NCP(DisasContext *dc, arg_NCP *a)
271345196ea4SRichard Henderson {
271445196ea4SRichard Henderson /*
271545196ea4SRichard Henderson * For sparc32, always generate the no-coprocessor exception.
271645196ea4SRichard Henderson * For sparc64, always generate illegal instruction.
271745196ea4SRichard Henderson */
271845196ea4SRichard Henderson #ifdef TARGET_SPARC64
271945196ea4SRichard Henderson return false;
272045196ea4SRichard Henderson #else
272145196ea4SRichard Henderson gen_exception(dc, TT_NCP_INSN);
272245196ea4SRichard Henderson return true;
272345196ea4SRichard Henderson #endif
272445196ea4SRichard Henderson }
272545196ea4SRichard Henderson
trans_SETHI(DisasContext * dc,arg_SETHI * a)27266d2a0768SRichard Henderson static bool trans_SETHI(DisasContext *dc, arg_SETHI *a)
27276d2a0768SRichard Henderson {
27286d2a0768SRichard Henderson /* Special-case %g0 because that's the canonical nop. */
27296d2a0768SRichard Henderson if (a->rd) {
27306d2a0768SRichard Henderson gen_store_gpr(dc, a->rd, tcg_constant_tl((uint32_t)a->i << 10));
27316d2a0768SRichard Henderson }
27326d2a0768SRichard Henderson return advance_pc(dc);
27336d2a0768SRichard Henderson }
27346d2a0768SRichard Henderson
27350faef01bSRichard Henderson /*
27360faef01bSRichard Henderson * Major Opcode 10 -- integer, floating-point, vis, and system insns.
27370faef01bSRichard Henderson */
27380faef01bSRichard Henderson
do_tcc(DisasContext * dc,int cond,int cc,int rs1,bool imm,int rs2_or_imm)273930376636SRichard Henderson static bool do_tcc(DisasContext *dc, int cond, int cc,
274030376636SRichard Henderson int rs1, bool imm, int rs2_or_imm)
274130376636SRichard Henderson {
274230376636SRichard Henderson int mask = ((dc->def->features & CPU_FEATURE_HYPV) && supervisor(dc)
274330376636SRichard Henderson ? UA2005_HTRAP_MASK : V8_TRAP_MASK);
274430376636SRichard Henderson DisasCompare cmp;
274530376636SRichard Henderson TCGLabel *lab;
274630376636SRichard Henderson TCGv_i32 trap;
274730376636SRichard Henderson
274830376636SRichard Henderson /* Trap never. */
274930376636SRichard Henderson if (cond == 0) {
275030376636SRichard Henderson return advance_pc(dc);
275130376636SRichard Henderson }
275230376636SRichard Henderson
275330376636SRichard Henderson /*
275430376636SRichard Henderson * Immediate traps are the most common case. Since this value is
275530376636SRichard Henderson * live across the branch, it really pays to evaluate the constant.
275630376636SRichard Henderson */
275730376636SRichard Henderson if (rs1 == 0 && (imm || rs2_or_imm == 0)) {
275830376636SRichard Henderson trap = tcg_constant_i32((rs2_or_imm & mask) + TT_TRAP);
275930376636SRichard Henderson } else {
276030376636SRichard Henderson trap = tcg_temp_new_i32();
276130376636SRichard Henderson tcg_gen_trunc_tl_i32(trap, gen_load_gpr(dc, rs1));
276230376636SRichard Henderson if (imm) {
276330376636SRichard Henderson tcg_gen_addi_i32(trap, trap, rs2_or_imm);
276430376636SRichard Henderson } else {
276530376636SRichard Henderson TCGv_i32 t2 = tcg_temp_new_i32();
276630376636SRichard Henderson tcg_gen_trunc_tl_i32(t2, gen_load_gpr(dc, rs2_or_imm));
276730376636SRichard Henderson tcg_gen_add_i32(trap, trap, t2);
276830376636SRichard Henderson }
276930376636SRichard Henderson tcg_gen_andi_i32(trap, trap, mask);
277030376636SRichard Henderson tcg_gen_addi_i32(trap, trap, TT_TRAP);
277130376636SRichard Henderson }
277230376636SRichard Henderson
277389527e3aSRichard Henderson finishing_insn(dc);
277489527e3aSRichard Henderson
277530376636SRichard Henderson /* Trap always. */
277630376636SRichard Henderson if (cond == 8) {
277730376636SRichard Henderson save_state(dc);
277830376636SRichard Henderson gen_helper_raise_exception(tcg_env, trap);
277930376636SRichard Henderson dc->base.is_jmp = DISAS_NORETURN;
278030376636SRichard Henderson return true;
278130376636SRichard Henderson }
278230376636SRichard Henderson
278330376636SRichard Henderson /* Conditional trap. */
278430376636SRichard Henderson flush_cond(dc);
278530376636SRichard Henderson lab = delay_exceptionv(dc, trap);
278630376636SRichard Henderson gen_compare(&cmp, cc, cond, dc);
2787c8507ebfSRichard Henderson tcg_gen_brcondi_tl(cmp.cond, cmp.c1, cmp.c2, lab);
278830376636SRichard Henderson
278930376636SRichard Henderson return advance_pc(dc);
279030376636SRichard Henderson }
279130376636SRichard Henderson
trans_Tcc_r(DisasContext * dc,arg_Tcc_r * a)279230376636SRichard Henderson static bool trans_Tcc_r(DisasContext *dc, arg_Tcc_r *a)
279330376636SRichard Henderson {
279430376636SRichard Henderson if (avail_32(dc) && a->cc) {
279530376636SRichard Henderson return false;
279630376636SRichard Henderson }
279730376636SRichard Henderson return do_tcc(dc, a->cond, a->cc, a->rs1, false, a->rs2);
279830376636SRichard Henderson }
279930376636SRichard Henderson
trans_Tcc_i_v7(DisasContext * dc,arg_Tcc_i_v7 * a)280030376636SRichard Henderson static bool trans_Tcc_i_v7(DisasContext *dc, arg_Tcc_i_v7 *a)
280130376636SRichard Henderson {
280230376636SRichard Henderson if (avail_64(dc)) {
280330376636SRichard Henderson return false;
280430376636SRichard Henderson }
280530376636SRichard Henderson return do_tcc(dc, a->cond, 0, a->rs1, true, a->i);
280630376636SRichard Henderson }
280730376636SRichard Henderson
trans_Tcc_i_v9(DisasContext * dc,arg_Tcc_i_v9 * a)280830376636SRichard Henderson static bool trans_Tcc_i_v9(DisasContext *dc, arg_Tcc_i_v9 *a)
280930376636SRichard Henderson {
281030376636SRichard Henderson if (avail_32(dc)) {
281130376636SRichard Henderson return false;
281230376636SRichard Henderson }
281330376636SRichard Henderson return do_tcc(dc, a->cond, a->cc, a->rs1, true, a->i);
281430376636SRichard Henderson }
281530376636SRichard Henderson
trans_STBAR(DisasContext * dc,arg_STBAR * a)2816af25071cSRichard Henderson static bool trans_STBAR(DisasContext *dc, arg_STBAR *a)
2817af25071cSRichard Henderson {
2818af25071cSRichard Henderson tcg_gen_mb(TCG_MO_ST_ST | TCG_BAR_SC);
2819af25071cSRichard Henderson return advance_pc(dc);
2820af25071cSRichard Henderson }
2821af25071cSRichard Henderson
trans_MEMBAR(DisasContext * dc,arg_MEMBAR * a)2822af25071cSRichard Henderson static bool trans_MEMBAR(DisasContext *dc, arg_MEMBAR *a)
2823af25071cSRichard Henderson {
2824af25071cSRichard Henderson if (avail_32(dc)) {
2825af25071cSRichard Henderson return false;
2826af25071cSRichard Henderson }
2827af25071cSRichard Henderson if (a->mmask) {
2828af25071cSRichard Henderson /* Note TCG_MO_* was modeled on sparc64, so mmask matches. */
2829af25071cSRichard Henderson tcg_gen_mb(a->mmask | TCG_BAR_SC);
2830af25071cSRichard Henderson }
2831af25071cSRichard Henderson if (a->cmask) {
2832af25071cSRichard Henderson /* For #Sync, etc, end the TB to recognize interrupts. */
2833af25071cSRichard Henderson dc->base.is_jmp = DISAS_EXIT;
2834af25071cSRichard Henderson }
2835af25071cSRichard Henderson return advance_pc(dc);
2836af25071cSRichard Henderson }
2837af25071cSRichard Henderson
do_rd_special(DisasContext * dc,bool priv,int rd,TCGv (* func)(DisasContext *,TCGv))2838af25071cSRichard Henderson static bool do_rd_special(DisasContext *dc, bool priv, int rd,
2839af25071cSRichard Henderson TCGv (*func)(DisasContext *, TCGv))
2840af25071cSRichard Henderson {
2841af25071cSRichard Henderson if (!priv) {
2842af25071cSRichard Henderson return raise_priv(dc);
2843af25071cSRichard Henderson }
2844af25071cSRichard Henderson gen_store_gpr(dc, rd, func(dc, gen_dest_gpr(dc, rd)));
2845af25071cSRichard Henderson return advance_pc(dc);
2846af25071cSRichard Henderson }
2847af25071cSRichard Henderson
do_rdy(DisasContext * dc,TCGv dst)2848af25071cSRichard Henderson static TCGv do_rdy(DisasContext *dc, TCGv dst)
2849af25071cSRichard Henderson {
2850af25071cSRichard Henderson return cpu_y;
2851af25071cSRichard Henderson }
2852af25071cSRichard Henderson
trans_RDY(DisasContext * dc,arg_RDY * a)2853af25071cSRichard Henderson static bool trans_RDY(DisasContext *dc, arg_RDY *a)
2854af25071cSRichard Henderson {
2855af25071cSRichard Henderson /*
2856af25071cSRichard Henderson * TODO: Need a feature bit for sparcv8. In the meantime, treat all
2857af25071cSRichard Henderson * 32-bit cpus like sparcv7, which ignores the rs1 field.
2858af25071cSRichard Henderson * This matches after all other ASR, so Leon3 Asr17 is handled first.
2859af25071cSRichard Henderson */
2860af25071cSRichard Henderson if (avail_64(dc) && a->rs1 != 0) {
2861af25071cSRichard Henderson return false;
2862af25071cSRichard Henderson }
2863af25071cSRichard Henderson return do_rd_special(dc, true, a->rd, do_rdy);
2864af25071cSRichard Henderson }
2865af25071cSRichard Henderson
do_rd_leon3_config(DisasContext * dc,TCGv dst)2866af25071cSRichard Henderson static TCGv do_rd_leon3_config(DisasContext *dc, TCGv dst)
2867af25071cSRichard Henderson {
2868c92948f2SClément Chigot gen_helper_rdasr17(dst, tcg_env);
2869c92948f2SClément Chigot return dst;
2870af25071cSRichard Henderson }
2871af25071cSRichard Henderson
2872af25071cSRichard Henderson TRANS(RDASR17, ASR17, do_rd_special, true, a->rd, do_rd_leon3_config)
2873af25071cSRichard Henderson
do_rdccr(DisasContext * dc,TCGv dst)2874af25071cSRichard Henderson static TCGv do_rdccr(DisasContext *dc, TCGv dst)
2875af25071cSRichard Henderson {
2876af25071cSRichard Henderson gen_helper_rdccr(dst, tcg_env);
2877af25071cSRichard Henderson return dst;
2878af25071cSRichard Henderson }
2879af25071cSRichard Henderson
2880af25071cSRichard Henderson TRANS(RDCCR, 64, do_rd_special, true, a->rd, do_rdccr)
2881af25071cSRichard Henderson
do_rdasi(DisasContext * dc,TCGv dst)2882af25071cSRichard Henderson static TCGv do_rdasi(DisasContext *dc, TCGv dst)
2883af25071cSRichard Henderson {
2884af25071cSRichard Henderson #ifdef TARGET_SPARC64
2885af25071cSRichard Henderson return tcg_constant_tl(dc->asi);
2886af25071cSRichard Henderson #else
2887af25071cSRichard Henderson qemu_build_not_reached();
2888af25071cSRichard Henderson #endif
2889af25071cSRichard Henderson }
2890af25071cSRichard Henderson
2891af25071cSRichard Henderson TRANS(RDASI, 64, do_rd_special, true, a->rd, do_rdasi)
2892af25071cSRichard Henderson
do_rdtick(DisasContext * dc,TCGv dst)2893af25071cSRichard Henderson static TCGv do_rdtick(DisasContext *dc, TCGv dst)
2894af25071cSRichard Henderson {
2895af25071cSRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr();
2896af25071cSRichard Henderson
2897af25071cSRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(tick));
2898af25071cSRichard Henderson if (translator_io_start(&dc->base)) {
2899af25071cSRichard Henderson dc->base.is_jmp = DISAS_EXIT;
2900af25071cSRichard Henderson }
2901af25071cSRichard Henderson gen_helper_tick_get_count(dst, tcg_env, r_tickptr,
2902af25071cSRichard Henderson tcg_constant_i32(dc->mem_idx));
2903af25071cSRichard Henderson return dst;
2904af25071cSRichard Henderson }
2905af25071cSRichard Henderson
2906af25071cSRichard Henderson /* TODO: non-priv access only allowed when enabled. */
2907af25071cSRichard Henderson TRANS(RDTICK, 64, do_rd_special, true, a->rd, do_rdtick)
2908af25071cSRichard Henderson
do_rdpc(DisasContext * dc,TCGv dst)2909af25071cSRichard Henderson static TCGv do_rdpc(DisasContext *dc, TCGv dst)
2910af25071cSRichard Henderson {
2911af25071cSRichard Henderson return tcg_constant_tl(address_mask_i(dc, dc->pc));
2912af25071cSRichard Henderson }
2913af25071cSRichard Henderson
2914af25071cSRichard Henderson TRANS(RDPC, 64, do_rd_special, true, a->rd, do_rdpc)
2915af25071cSRichard Henderson
do_rdfprs(DisasContext * dc,TCGv dst)2916af25071cSRichard Henderson static TCGv do_rdfprs(DisasContext *dc, TCGv dst)
2917af25071cSRichard Henderson {
2918af25071cSRichard Henderson tcg_gen_ext_i32_tl(dst, cpu_fprs);
2919af25071cSRichard Henderson return dst;
2920af25071cSRichard Henderson }
2921af25071cSRichard Henderson
2922af25071cSRichard Henderson TRANS(RDFPRS, 64, do_rd_special, true, a->rd, do_rdfprs)
2923af25071cSRichard Henderson
do_rdgsr(DisasContext * dc,TCGv dst)2924af25071cSRichard Henderson static TCGv do_rdgsr(DisasContext *dc, TCGv dst)
2925af25071cSRichard Henderson {
2926af25071cSRichard Henderson gen_trap_ifnofpu(dc);
2927af25071cSRichard Henderson return cpu_gsr;
2928af25071cSRichard Henderson }
2929af25071cSRichard Henderson
2930af25071cSRichard Henderson TRANS(RDGSR, 64, do_rd_special, true, a->rd, do_rdgsr)
2931af25071cSRichard Henderson
do_rdsoftint(DisasContext * dc,TCGv dst)2932af25071cSRichard Henderson static TCGv do_rdsoftint(DisasContext *dc, TCGv dst)
2933af25071cSRichard Henderson {
2934af25071cSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(softint));
2935af25071cSRichard Henderson return dst;
2936af25071cSRichard Henderson }
2937af25071cSRichard Henderson
2938af25071cSRichard Henderson TRANS(RDSOFTINT, 64, do_rd_special, supervisor(dc), a->rd, do_rdsoftint)
2939af25071cSRichard Henderson
do_rdtick_cmpr(DisasContext * dc,TCGv dst)2940af25071cSRichard Henderson static TCGv do_rdtick_cmpr(DisasContext *dc, TCGv dst)
2941af25071cSRichard Henderson {
2942577efa45SRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(tick_cmpr));
2943577efa45SRichard Henderson return dst;
2944af25071cSRichard Henderson }
2945af25071cSRichard Henderson
2946af25071cSRichard Henderson /* TODO: non-priv access only allowed when enabled. */
2947af25071cSRichard Henderson TRANS(RDTICK_CMPR, 64, do_rd_special, true, a->rd, do_rdtick_cmpr)
2948af25071cSRichard Henderson
do_rdstick(DisasContext * dc,TCGv dst)2949af25071cSRichard Henderson static TCGv do_rdstick(DisasContext *dc, TCGv dst)
2950af25071cSRichard Henderson {
2951af25071cSRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr();
2952af25071cSRichard Henderson
2953af25071cSRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(stick));
2954af25071cSRichard Henderson if (translator_io_start(&dc->base)) {
2955af25071cSRichard Henderson dc->base.is_jmp = DISAS_EXIT;
2956af25071cSRichard Henderson }
2957af25071cSRichard Henderson gen_helper_tick_get_count(dst, tcg_env, r_tickptr,
2958af25071cSRichard Henderson tcg_constant_i32(dc->mem_idx));
2959af25071cSRichard Henderson return dst;
2960af25071cSRichard Henderson }
2961af25071cSRichard Henderson
2962af25071cSRichard Henderson /* TODO: non-priv access only allowed when enabled. */
2963af25071cSRichard Henderson TRANS(RDSTICK, 64, do_rd_special, true, a->rd, do_rdstick)
2964af25071cSRichard Henderson
do_rdstick_cmpr(DisasContext * dc,TCGv dst)2965af25071cSRichard Henderson static TCGv do_rdstick_cmpr(DisasContext *dc, TCGv dst)
2966af25071cSRichard Henderson {
2967577efa45SRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(stick_cmpr));
2968577efa45SRichard Henderson return dst;
2969af25071cSRichard Henderson }
2970af25071cSRichard Henderson
2971af25071cSRichard Henderson /* TODO: supervisor access only allowed when enabled by hypervisor. */
2972af25071cSRichard Henderson TRANS(RDSTICK_CMPR, 64, do_rd_special, supervisor(dc), a->rd, do_rdstick_cmpr)
2973af25071cSRichard Henderson
2974af25071cSRichard Henderson /*
2975af25071cSRichard Henderson * UltraSPARC-T1 Strand status.
2976af25071cSRichard Henderson * HYPV check maybe not enough, UA2005 & UA2007 describe
2977af25071cSRichard Henderson * this ASR as impl. dep
2978af25071cSRichard Henderson */
do_rdstrand_status(DisasContext * dc,TCGv dst)2979af25071cSRichard Henderson static TCGv do_rdstrand_status(DisasContext *dc, TCGv dst)
2980af25071cSRichard Henderson {
2981af25071cSRichard Henderson return tcg_constant_tl(1);
2982af25071cSRichard Henderson }
2983af25071cSRichard Henderson
2984af25071cSRichard Henderson TRANS(RDSTRAND_STATUS, HYPV, do_rd_special, true, a->rd, do_rdstrand_status)
2985af25071cSRichard Henderson
do_rdpsr(DisasContext * dc,TCGv dst)2986668bb9b7SRichard Henderson static TCGv do_rdpsr(DisasContext *dc, TCGv dst)
2987668bb9b7SRichard Henderson {
2988668bb9b7SRichard Henderson gen_helper_rdpsr(dst, tcg_env);
2989668bb9b7SRichard Henderson return dst;
2990668bb9b7SRichard Henderson }
2991668bb9b7SRichard Henderson
2992668bb9b7SRichard Henderson TRANS(RDPSR, 32, do_rd_special, supervisor(dc), a->rd, do_rdpsr)
2993668bb9b7SRichard Henderson
do_rdhpstate(DisasContext * dc,TCGv dst)2994668bb9b7SRichard Henderson static TCGv do_rdhpstate(DisasContext *dc, TCGv dst)
2995668bb9b7SRichard Henderson {
2996668bb9b7SRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hpstate));
2997668bb9b7SRichard Henderson return dst;
2998668bb9b7SRichard Henderson }
2999668bb9b7SRichard Henderson
3000668bb9b7SRichard Henderson TRANS(RDHPR_hpstate, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhpstate)
3001668bb9b7SRichard Henderson
do_rdhtstate(DisasContext * dc,TCGv dst)3002668bb9b7SRichard Henderson static TCGv do_rdhtstate(DisasContext *dc, TCGv dst)
3003668bb9b7SRichard Henderson {
3004668bb9b7SRichard Henderson TCGv_i32 tl = tcg_temp_new_i32();
3005668bb9b7SRichard Henderson TCGv_ptr tp = tcg_temp_new_ptr();
3006668bb9b7SRichard Henderson
3007668bb9b7SRichard Henderson tcg_gen_ld_i32(tl, tcg_env, env64_field_offsetof(tl));
3008668bb9b7SRichard Henderson tcg_gen_andi_i32(tl, tl, MAXTL_MASK);
3009668bb9b7SRichard Henderson tcg_gen_shli_i32(tl, tl, 3);
3010668bb9b7SRichard Henderson tcg_gen_ext_i32_ptr(tp, tl);
3011668bb9b7SRichard Henderson tcg_gen_add_ptr(tp, tp, tcg_env);
3012668bb9b7SRichard Henderson
3013668bb9b7SRichard Henderson tcg_gen_ld_tl(dst, tp, env64_field_offsetof(htstate));
3014668bb9b7SRichard Henderson return dst;
3015668bb9b7SRichard Henderson }
3016668bb9b7SRichard Henderson
3017668bb9b7SRichard Henderson TRANS(RDHPR_htstate, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhtstate)
3018668bb9b7SRichard Henderson
do_rdhintp(DisasContext * dc,TCGv dst)3019668bb9b7SRichard Henderson static TCGv do_rdhintp(DisasContext *dc, TCGv dst)
3020668bb9b7SRichard Henderson {
30212da789deSRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hintp));
30222da789deSRichard Henderson return dst;
3023668bb9b7SRichard Henderson }
3024668bb9b7SRichard Henderson
3025668bb9b7SRichard Henderson TRANS(RDHPR_hintp, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhintp)
3026668bb9b7SRichard Henderson
do_rdhtba(DisasContext * dc,TCGv dst)3027668bb9b7SRichard Henderson static TCGv do_rdhtba(DisasContext *dc, TCGv dst)
3028668bb9b7SRichard Henderson {
30292da789deSRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(htba));
30302da789deSRichard Henderson return dst;
3031668bb9b7SRichard Henderson }
3032668bb9b7SRichard Henderson
3033668bb9b7SRichard Henderson TRANS(RDHPR_htba, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhtba)
3034668bb9b7SRichard Henderson
do_rdhver(DisasContext * dc,TCGv dst)3035668bb9b7SRichard Henderson static TCGv do_rdhver(DisasContext *dc, TCGv dst)
3036668bb9b7SRichard Henderson {
30372da789deSRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hver));
30382da789deSRichard Henderson return dst;
3039668bb9b7SRichard Henderson }
3040668bb9b7SRichard Henderson
3041668bb9b7SRichard Henderson TRANS(RDHPR_hver, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhver)
3042668bb9b7SRichard Henderson
do_rdhstick_cmpr(DisasContext * dc,TCGv dst)3043668bb9b7SRichard Henderson static TCGv do_rdhstick_cmpr(DisasContext *dc, TCGv dst)
3044668bb9b7SRichard Henderson {
3045577efa45SRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hstick_cmpr));
3046577efa45SRichard Henderson return dst;
3047668bb9b7SRichard Henderson }
3048668bb9b7SRichard Henderson
3049668bb9b7SRichard Henderson TRANS(RDHPR_hstick_cmpr, HYPV, do_rd_special, hypervisor(dc), a->rd,
3050668bb9b7SRichard Henderson do_rdhstick_cmpr)
3051668bb9b7SRichard Henderson
do_rdwim(DisasContext * dc,TCGv dst)30525d617bfbSRichard Henderson static TCGv do_rdwim(DisasContext *dc, TCGv dst)
30535d617bfbSRichard Henderson {
3054cd6269f7SRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env32_field_offsetof(wim));
3055cd6269f7SRichard Henderson return dst;
30565d617bfbSRichard Henderson }
30575d617bfbSRichard Henderson
30585d617bfbSRichard Henderson TRANS(RDWIM, 32, do_rd_special, supervisor(dc), a->rd, do_rdwim)
30595d617bfbSRichard Henderson
do_rdtpc(DisasContext * dc,TCGv dst)30605d617bfbSRichard Henderson static TCGv do_rdtpc(DisasContext *dc, TCGv dst)
30615d617bfbSRichard Henderson {
30625d617bfbSRichard Henderson #ifdef TARGET_SPARC64
30635d617bfbSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr();
30645d617bfbSRichard Henderson
30655d617bfbSRichard Henderson gen_load_trap_state_at_tl(r_tsptr);
30665d617bfbSRichard Henderson tcg_gen_ld_tl(dst, r_tsptr, offsetof(trap_state, tpc));
30675d617bfbSRichard Henderson return dst;
30685d617bfbSRichard Henderson #else
30695d617bfbSRichard Henderson qemu_build_not_reached();
30705d617bfbSRichard Henderson #endif
30715d617bfbSRichard Henderson }
30725d617bfbSRichard Henderson
30735d617bfbSRichard Henderson TRANS(RDPR_tpc, 64, do_rd_special, supervisor(dc), a->rd, do_rdtpc)
30745d617bfbSRichard Henderson
do_rdtnpc(DisasContext * dc,TCGv dst)30755d617bfbSRichard Henderson static TCGv do_rdtnpc(DisasContext *dc, TCGv dst)
30765d617bfbSRichard Henderson {
30775d617bfbSRichard Henderson #ifdef TARGET_SPARC64
30785d617bfbSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr();
30795d617bfbSRichard Henderson
30805d617bfbSRichard Henderson gen_load_trap_state_at_tl(r_tsptr);
30815d617bfbSRichard Henderson tcg_gen_ld_tl(dst, r_tsptr, offsetof(trap_state, tnpc));
30825d617bfbSRichard Henderson return dst;
30835d617bfbSRichard Henderson #else
30845d617bfbSRichard Henderson qemu_build_not_reached();
30855d617bfbSRichard Henderson #endif
30865d617bfbSRichard Henderson }
30875d617bfbSRichard Henderson
30885d617bfbSRichard Henderson TRANS(RDPR_tnpc, 64, do_rd_special, supervisor(dc), a->rd, do_rdtnpc)
30895d617bfbSRichard Henderson
do_rdtstate(DisasContext * dc,TCGv dst)30905d617bfbSRichard Henderson static TCGv do_rdtstate(DisasContext *dc, TCGv dst)
30915d617bfbSRichard Henderson {
30925d617bfbSRichard Henderson #ifdef TARGET_SPARC64
30935d617bfbSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr();
30945d617bfbSRichard Henderson
30955d617bfbSRichard Henderson gen_load_trap_state_at_tl(r_tsptr);
30965d617bfbSRichard Henderson tcg_gen_ld_tl(dst, r_tsptr, offsetof(trap_state, tstate));
30975d617bfbSRichard Henderson return dst;
30985d617bfbSRichard Henderson #else
30995d617bfbSRichard Henderson qemu_build_not_reached();
31005d617bfbSRichard Henderson #endif
31015d617bfbSRichard Henderson }
31025d617bfbSRichard Henderson
31035d617bfbSRichard Henderson TRANS(RDPR_tstate, 64, do_rd_special, supervisor(dc), a->rd, do_rdtstate)
31045d617bfbSRichard Henderson
do_rdtt(DisasContext * dc,TCGv dst)31055d617bfbSRichard Henderson static TCGv do_rdtt(DisasContext *dc, TCGv dst)
31065d617bfbSRichard Henderson {
31075d617bfbSRichard Henderson #ifdef TARGET_SPARC64
31085d617bfbSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr();
31095d617bfbSRichard Henderson
31105d617bfbSRichard Henderson gen_load_trap_state_at_tl(r_tsptr);
31115d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, r_tsptr, offsetof(trap_state, tt));
31125d617bfbSRichard Henderson return dst;
31135d617bfbSRichard Henderson #else
31145d617bfbSRichard Henderson qemu_build_not_reached();
31155d617bfbSRichard Henderson #endif
31165d617bfbSRichard Henderson }
31175d617bfbSRichard Henderson
31185d617bfbSRichard Henderson TRANS(RDPR_tt, 64, do_rd_special, supervisor(dc), a->rd, do_rdtt)
31195d617bfbSRichard Henderson TRANS(RDPR_tick, 64, do_rd_special, supervisor(dc), a->rd, do_rdtick)
31205d617bfbSRichard Henderson
do_rdtba(DisasContext * dc,TCGv dst)31215d617bfbSRichard Henderson static TCGv do_rdtba(DisasContext *dc, TCGv dst)
31225d617bfbSRichard Henderson {
31235d617bfbSRichard Henderson return cpu_tbr;
31245d617bfbSRichard Henderson }
31255d617bfbSRichard Henderson
3126e8325dc0SRichard Henderson TRANS(RDTBR, 32, do_rd_special, supervisor(dc), a->rd, do_rdtba)
31275d617bfbSRichard Henderson TRANS(RDPR_tba, 64, do_rd_special, supervisor(dc), a->rd, do_rdtba)
31285d617bfbSRichard Henderson
do_rdpstate(DisasContext * dc,TCGv dst)31295d617bfbSRichard Henderson static TCGv do_rdpstate(DisasContext *dc, TCGv dst)
31305d617bfbSRichard Henderson {
31315d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(pstate));
31325d617bfbSRichard Henderson return dst;
31335d617bfbSRichard Henderson }
31345d617bfbSRichard Henderson
31355d617bfbSRichard Henderson TRANS(RDPR_pstate, 64, do_rd_special, supervisor(dc), a->rd, do_rdpstate)
31365d617bfbSRichard Henderson
do_rdtl(DisasContext * dc,TCGv dst)31375d617bfbSRichard Henderson static TCGv do_rdtl(DisasContext *dc, TCGv dst)
31385d617bfbSRichard Henderson {
31395d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(tl));
31405d617bfbSRichard Henderson return dst;
31415d617bfbSRichard Henderson }
31425d617bfbSRichard Henderson
31435d617bfbSRichard Henderson TRANS(RDPR_tl, 64, do_rd_special, supervisor(dc), a->rd, do_rdtl)
31445d617bfbSRichard Henderson
do_rdpil(DisasContext * dc,TCGv dst)31455d617bfbSRichard Henderson static TCGv do_rdpil(DisasContext *dc, TCGv dst)
31465d617bfbSRichard Henderson {
31475d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env_field_offsetof(psrpil));
31485d617bfbSRichard Henderson return dst;
31495d617bfbSRichard Henderson }
31505d617bfbSRichard Henderson
31515d617bfbSRichard Henderson TRANS(RDPR_pil, 64, do_rd_special, supervisor(dc), a->rd, do_rdpil)
31525d617bfbSRichard Henderson
do_rdcwp(DisasContext * dc,TCGv dst)31535d617bfbSRichard Henderson static TCGv do_rdcwp(DisasContext *dc, TCGv dst)
31545d617bfbSRichard Henderson {
31555d617bfbSRichard Henderson gen_helper_rdcwp(dst, tcg_env);
31565d617bfbSRichard Henderson return dst;
31575d617bfbSRichard Henderson }
31585d617bfbSRichard Henderson
31595d617bfbSRichard Henderson TRANS(RDPR_cwp, 64, do_rd_special, supervisor(dc), a->rd, do_rdcwp)
31605d617bfbSRichard Henderson
do_rdcansave(DisasContext * dc,TCGv dst)31615d617bfbSRichard Henderson static TCGv do_rdcansave(DisasContext *dc, TCGv dst)
31625d617bfbSRichard Henderson {
31635d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(cansave));
31645d617bfbSRichard Henderson return dst;
31655d617bfbSRichard Henderson }
31665d617bfbSRichard Henderson
31675d617bfbSRichard Henderson TRANS(RDPR_cansave, 64, do_rd_special, supervisor(dc), a->rd, do_rdcansave)
31685d617bfbSRichard Henderson
do_rdcanrestore(DisasContext * dc,TCGv dst)31695d617bfbSRichard Henderson static TCGv do_rdcanrestore(DisasContext *dc, TCGv dst)
31705d617bfbSRichard Henderson {
31715d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(canrestore));
31725d617bfbSRichard Henderson return dst;
31735d617bfbSRichard Henderson }
31745d617bfbSRichard Henderson
31755d617bfbSRichard Henderson TRANS(RDPR_canrestore, 64, do_rd_special, supervisor(dc), a->rd,
31765d617bfbSRichard Henderson do_rdcanrestore)
31775d617bfbSRichard Henderson
do_rdcleanwin(DisasContext * dc,TCGv dst)31785d617bfbSRichard Henderson static TCGv do_rdcleanwin(DisasContext *dc, TCGv dst)
31795d617bfbSRichard Henderson {
31805d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(cleanwin));
31815d617bfbSRichard Henderson return dst;
31825d617bfbSRichard Henderson }
31835d617bfbSRichard Henderson
31845d617bfbSRichard Henderson TRANS(RDPR_cleanwin, 64, do_rd_special, supervisor(dc), a->rd, do_rdcleanwin)
31855d617bfbSRichard Henderson
do_rdotherwin(DisasContext * dc,TCGv dst)31865d617bfbSRichard Henderson static TCGv do_rdotherwin(DisasContext *dc, TCGv dst)
31875d617bfbSRichard Henderson {
31885d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(otherwin));
31895d617bfbSRichard Henderson return dst;
31905d617bfbSRichard Henderson }
31915d617bfbSRichard Henderson
31925d617bfbSRichard Henderson TRANS(RDPR_otherwin, 64, do_rd_special, supervisor(dc), a->rd, do_rdotherwin)
31935d617bfbSRichard Henderson
do_rdwstate(DisasContext * dc,TCGv dst)31945d617bfbSRichard Henderson static TCGv do_rdwstate(DisasContext *dc, TCGv dst)
31955d617bfbSRichard Henderson {
31965d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(wstate));
31975d617bfbSRichard Henderson return dst;
31985d617bfbSRichard Henderson }
31995d617bfbSRichard Henderson
32005d617bfbSRichard Henderson TRANS(RDPR_wstate, 64, do_rd_special, supervisor(dc), a->rd, do_rdwstate)
32015d617bfbSRichard Henderson
do_rdgl(DisasContext * dc,TCGv dst)32025d617bfbSRichard Henderson static TCGv do_rdgl(DisasContext *dc, TCGv dst)
32035d617bfbSRichard Henderson {
32045d617bfbSRichard Henderson tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(gl));
32055d617bfbSRichard Henderson return dst;
32065d617bfbSRichard Henderson }
32075d617bfbSRichard Henderson
32085d617bfbSRichard Henderson TRANS(RDPR_gl, GL, do_rd_special, supervisor(dc), a->rd, do_rdgl)
32095d617bfbSRichard Henderson
32105d617bfbSRichard Henderson /* UA2005 strand status */
do_rdssr(DisasContext * dc,TCGv dst)32115d617bfbSRichard Henderson static TCGv do_rdssr(DisasContext *dc, TCGv dst)
32125d617bfbSRichard Henderson {
32132da789deSRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(ssr));
32142da789deSRichard Henderson return dst;
32155d617bfbSRichard Henderson }
32165d617bfbSRichard Henderson
32175d617bfbSRichard Henderson TRANS(RDPR_strand_status, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdssr)
32185d617bfbSRichard Henderson
do_rdver(DisasContext * dc,TCGv dst)32195d617bfbSRichard Henderson static TCGv do_rdver(DisasContext *dc, TCGv dst)
32205d617bfbSRichard Henderson {
32212da789deSRichard Henderson tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(version));
32222da789deSRichard Henderson return dst;
32235d617bfbSRichard Henderson }
32245d617bfbSRichard Henderson
32255d617bfbSRichard Henderson TRANS(RDPR_ver, 64, do_rd_special, supervisor(dc), a->rd, do_rdver)
32265d617bfbSRichard Henderson
trans_FLUSHW(DisasContext * dc,arg_FLUSHW * a)3227e8325dc0SRichard Henderson static bool trans_FLUSHW(DisasContext *dc, arg_FLUSHW *a)
3228e8325dc0SRichard Henderson {
3229e8325dc0SRichard Henderson if (avail_64(dc)) {
3230e8325dc0SRichard Henderson gen_helper_flushw(tcg_env);
3231e8325dc0SRichard Henderson return advance_pc(dc);
3232e8325dc0SRichard Henderson }
3233e8325dc0SRichard Henderson return false;
3234e8325dc0SRichard Henderson }
3235e8325dc0SRichard Henderson
do_wr_special(DisasContext * dc,arg_r_r_ri * a,bool priv,void (* func)(DisasContext *,TCGv))32360faef01bSRichard Henderson static bool do_wr_special(DisasContext *dc, arg_r_r_ri *a, bool priv,
32370faef01bSRichard Henderson void (*func)(DisasContext *, TCGv))
32380faef01bSRichard Henderson {
32390faef01bSRichard Henderson TCGv src;
32400faef01bSRichard Henderson
32410faef01bSRichard Henderson /* For simplicity, we under-decoded the rs2 form. */
32420faef01bSRichard Henderson if (!a->imm && (a->rs2_or_imm & ~0x1f)) {
32430faef01bSRichard Henderson return false;
32440faef01bSRichard Henderson }
32450faef01bSRichard Henderson if (!priv) {
32460faef01bSRichard Henderson return raise_priv(dc);
32470faef01bSRichard Henderson }
32480faef01bSRichard Henderson
32490faef01bSRichard Henderson if (a->rs1 == 0 && (a->imm || a->rs2_or_imm == 0)) {
32500faef01bSRichard Henderson src = tcg_constant_tl(a->rs2_or_imm);
32510faef01bSRichard Henderson } else {
32520faef01bSRichard Henderson TCGv src1 = gen_load_gpr(dc, a->rs1);
32530faef01bSRichard Henderson if (a->rs2_or_imm == 0) {
32540faef01bSRichard Henderson src = src1;
32550faef01bSRichard Henderson } else {
32560faef01bSRichard Henderson src = tcg_temp_new();
32570faef01bSRichard Henderson if (a->imm) {
32580faef01bSRichard Henderson tcg_gen_xori_tl(src, src1, a->rs2_or_imm);
32590faef01bSRichard Henderson } else {
32600faef01bSRichard Henderson tcg_gen_xor_tl(src, src1, gen_load_gpr(dc, a->rs2_or_imm));
32610faef01bSRichard Henderson }
32620faef01bSRichard Henderson }
32630faef01bSRichard Henderson }
32640faef01bSRichard Henderson func(dc, src);
32650faef01bSRichard Henderson return advance_pc(dc);
32660faef01bSRichard Henderson }
32670faef01bSRichard Henderson
do_wry(DisasContext * dc,TCGv src)32680faef01bSRichard Henderson static void do_wry(DisasContext *dc, TCGv src)
32690faef01bSRichard Henderson {
32700faef01bSRichard Henderson tcg_gen_ext32u_tl(cpu_y, src);
32710faef01bSRichard Henderson }
32720faef01bSRichard Henderson
TRANS(WRY,ALL,do_wr_special,a,true,do_wry)32730faef01bSRichard Henderson TRANS(WRY, ALL, do_wr_special, a, true, do_wry)
32740faef01bSRichard Henderson
32750faef01bSRichard Henderson static void do_wrccr(DisasContext *dc, TCGv src)
32760faef01bSRichard Henderson {
32770faef01bSRichard Henderson gen_helper_wrccr(tcg_env, src);
32780faef01bSRichard Henderson }
32790faef01bSRichard Henderson
32800faef01bSRichard Henderson TRANS(WRCCR, 64, do_wr_special, a, true, do_wrccr)
32810faef01bSRichard Henderson
do_wrasi(DisasContext * dc,TCGv src)32820faef01bSRichard Henderson static void do_wrasi(DisasContext *dc, TCGv src)
32830faef01bSRichard Henderson {
32840faef01bSRichard Henderson TCGv tmp = tcg_temp_new();
32850faef01bSRichard Henderson
32860faef01bSRichard Henderson tcg_gen_ext8u_tl(tmp, src);
32870faef01bSRichard Henderson tcg_gen_st32_tl(tmp, tcg_env, env64_field_offsetof(asi));
32880faef01bSRichard Henderson /* End TB to notice changed ASI. */
32890faef01bSRichard Henderson dc->base.is_jmp = DISAS_EXIT;
32900faef01bSRichard Henderson }
32910faef01bSRichard Henderson
32920faef01bSRichard Henderson TRANS(WRASI, 64, do_wr_special, a, true, do_wrasi)
32930faef01bSRichard Henderson
do_wrfprs(DisasContext * dc,TCGv src)32940faef01bSRichard Henderson static void do_wrfprs(DisasContext *dc, TCGv src)
32950faef01bSRichard Henderson {
32960faef01bSRichard Henderson #ifdef TARGET_SPARC64
32970faef01bSRichard Henderson tcg_gen_trunc_tl_i32(cpu_fprs, src);
32980faef01bSRichard Henderson dc->fprs_dirty = 0;
32990faef01bSRichard Henderson dc->base.is_jmp = DISAS_EXIT;
33000faef01bSRichard Henderson #else
33010faef01bSRichard Henderson qemu_build_not_reached();
33020faef01bSRichard Henderson #endif
33030faef01bSRichard Henderson }
33040faef01bSRichard Henderson
33050faef01bSRichard Henderson TRANS(WRFPRS, 64, do_wr_special, a, true, do_wrfprs)
33060faef01bSRichard Henderson
do_wrgsr(DisasContext * dc,TCGv src)33070faef01bSRichard Henderson static void do_wrgsr(DisasContext *dc, TCGv src)
33080faef01bSRichard Henderson {
33090faef01bSRichard Henderson gen_trap_ifnofpu(dc);
33100faef01bSRichard Henderson tcg_gen_mov_tl(cpu_gsr, src);
33110faef01bSRichard Henderson }
33120faef01bSRichard Henderson
33130faef01bSRichard Henderson TRANS(WRGSR, 64, do_wr_special, a, true, do_wrgsr)
33140faef01bSRichard Henderson
do_wrsoftint_set(DisasContext * dc,TCGv src)33150faef01bSRichard Henderson static void do_wrsoftint_set(DisasContext *dc, TCGv src)
33160faef01bSRichard Henderson {
33170faef01bSRichard Henderson gen_helper_set_softint(tcg_env, src);
33180faef01bSRichard Henderson }
33190faef01bSRichard Henderson
33200faef01bSRichard Henderson TRANS(WRSOFTINT_SET, 64, do_wr_special, a, supervisor(dc), do_wrsoftint_set)
33210faef01bSRichard Henderson
do_wrsoftint_clr(DisasContext * dc,TCGv src)33220faef01bSRichard Henderson static void do_wrsoftint_clr(DisasContext *dc, TCGv src)
33230faef01bSRichard Henderson {
33240faef01bSRichard Henderson gen_helper_clear_softint(tcg_env, src);
33250faef01bSRichard Henderson }
33260faef01bSRichard Henderson
33270faef01bSRichard Henderson TRANS(WRSOFTINT_CLR, 64, do_wr_special, a, supervisor(dc), do_wrsoftint_clr)
33280faef01bSRichard Henderson
do_wrsoftint(DisasContext * dc,TCGv src)33290faef01bSRichard Henderson static void do_wrsoftint(DisasContext *dc, TCGv src)
33300faef01bSRichard Henderson {
33310faef01bSRichard Henderson gen_helper_write_softint(tcg_env, src);
33320faef01bSRichard Henderson }
33330faef01bSRichard Henderson
33340faef01bSRichard Henderson TRANS(WRSOFTINT, 64, do_wr_special, a, supervisor(dc), do_wrsoftint)
33350faef01bSRichard Henderson
do_wrtick_cmpr(DisasContext * dc,TCGv src)33360faef01bSRichard Henderson static void do_wrtick_cmpr(DisasContext *dc, TCGv src)
33370faef01bSRichard Henderson {
33380faef01bSRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr();
33390faef01bSRichard Henderson
3340577efa45SRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(tick_cmpr));
3341577efa45SRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(tick));
33420faef01bSRichard Henderson translator_io_start(&dc->base);
3343577efa45SRichard Henderson gen_helper_tick_set_limit(r_tickptr, src);
33440faef01bSRichard Henderson /* End TB to handle timer interrupt */
33450faef01bSRichard Henderson dc->base.is_jmp = DISAS_EXIT;
33460faef01bSRichard Henderson }
33470faef01bSRichard Henderson
33480faef01bSRichard Henderson TRANS(WRTICK_CMPR, 64, do_wr_special, a, supervisor(dc), do_wrtick_cmpr)
33490faef01bSRichard Henderson
do_wrstick(DisasContext * dc,TCGv src)33500faef01bSRichard Henderson static void do_wrstick(DisasContext *dc, TCGv src)
33510faef01bSRichard Henderson {
33520faef01bSRichard Henderson #ifdef TARGET_SPARC64
33530faef01bSRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr();
33540faef01bSRichard Henderson
33550faef01bSRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, offsetof(CPUSPARCState, stick));
33560faef01bSRichard Henderson translator_io_start(&dc->base);
33570faef01bSRichard Henderson gen_helper_tick_set_count(r_tickptr, src);
33580faef01bSRichard Henderson /* End TB to handle timer interrupt */
33590faef01bSRichard Henderson dc->base.is_jmp = DISAS_EXIT;
33600faef01bSRichard Henderson #else
33610faef01bSRichard Henderson qemu_build_not_reached();
33620faef01bSRichard Henderson #endif
33630faef01bSRichard Henderson }
33640faef01bSRichard Henderson
33650faef01bSRichard Henderson TRANS(WRSTICK, 64, do_wr_special, a, supervisor(dc), do_wrstick)
33660faef01bSRichard Henderson
do_wrstick_cmpr(DisasContext * dc,TCGv src)33670faef01bSRichard Henderson static void do_wrstick_cmpr(DisasContext *dc, TCGv src)
33680faef01bSRichard Henderson {
33690faef01bSRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr();
33700faef01bSRichard Henderson
3371577efa45SRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(stick_cmpr));
3372577efa45SRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(stick));
33730faef01bSRichard Henderson translator_io_start(&dc->base);
3374577efa45SRichard Henderson gen_helper_tick_set_limit(r_tickptr, src);
33750faef01bSRichard Henderson /* End TB to handle timer interrupt */
33760faef01bSRichard Henderson dc->base.is_jmp = DISAS_EXIT;
33770faef01bSRichard Henderson }
33780faef01bSRichard Henderson
33790faef01bSRichard Henderson TRANS(WRSTICK_CMPR, 64, do_wr_special, a, supervisor(dc), do_wrstick_cmpr)
33800faef01bSRichard Henderson
do_wrpowerdown(DisasContext * dc,TCGv src)33810faef01bSRichard Henderson static void do_wrpowerdown(DisasContext *dc, TCGv src)
33820faef01bSRichard Henderson {
338389527e3aSRichard Henderson finishing_insn(dc);
33840faef01bSRichard Henderson save_state(dc);
33850faef01bSRichard Henderson gen_helper_power_down(tcg_env);
33860faef01bSRichard Henderson }
33870faef01bSRichard Henderson
TRANS(WRPOWERDOWN,POWERDOWN,do_wr_special,a,supervisor (dc),do_wrpowerdown)33880faef01bSRichard Henderson TRANS(WRPOWERDOWN, POWERDOWN, do_wr_special, a, supervisor(dc), do_wrpowerdown)
33890faef01bSRichard Henderson
33906fbc032cSRichard Henderson static void do_wrmwait(DisasContext *dc, TCGv src)
33916fbc032cSRichard Henderson {
33926fbc032cSRichard Henderson /*
33936fbc032cSRichard Henderson * TODO: This is a stub version of mwait, which merely recognizes
33946fbc032cSRichard Henderson * interrupts immediately and does not wait.
33956fbc032cSRichard Henderson */
33966fbc032cSRichard Henderson dc->base.is_jmp = DISAS_EXIT;
33976fbc032cSRichard Henderson }
33986fbc032cSRichard Henderson
TRANS(WRMWAIT,VIS4,do_wr_special,a,true,do_wrmwait)33996fbc032cSRichard Henderson TRANS(WRMWAIT, VIS4, do_wr_special, a, true, do_wrmwait)
34006fbc032cSRichard Henderson
340125524734SRichard Henderson static void do_wrpsr(DisasContext *dc, TCGv src)
340225524734SRichard Henderson {
340325524734SRichard Henderson gen_helper_wrpsr(tcg_env, src);
340425524734SRichard Henderson dc->base.is_jmp = DISAS_EXIT;
340525524734SRichard Henderson }
340625524734SRichard Henderson
340725524734SRichard Henderson TRANS(WRPSR, 32, do_wr_special, a, supervisor(dc), do_wrpsr)
340825524734SRichard Henderson
do_wrwim(DisasContext * dc,TCGv src)34099422278eSRichard Henderson static void do_wrwim(DisasContext *dc, TCGv src)
34109422278eSRichard Henderson {
34119422278eSRichard Henderson target_ulong mask = MAKE_64BIT_MASK(0, dc->def->nwindows);
3412cd6269f7SRichard Henderson TCGv tmp = tcg_temp_new();
3413cd6269f7SRichard Henderson
3414cd6269f7SRichard Henderson tcg_gen_andi_tl(tmp, src, mask);
3415cd6269f7SRichard Henderson tcg_gen_st_tl(tmp, tcg_env, env32_field_offsetof(wim));
34169422278eSRichard Henderson }
34179422278eSRichard Henderson
34189422278eSRichard Henderson TRANS(WRWIM, 32, do_wr_special, a, supervisor(dc), do_wrwim)
34199422278eSRichard Henderson
do_wrtpc(DisasContext * dc,TCGv src)34209422278eSRichard Henderson static void do_wrtpc(DisasContext *dc, TCGv src)
34219422278eSRichard Henderson {
34229422278eSRichard Henderson #ifdef TARGET_SPARC64
34239422278eSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr();
34249422278eSRichard Henderson
34259422278eSRichard Henderson gen_load_trap_state_at_tl(r_tsptr);
34269422278eSRichard Henderson tcg_gen_st_tl(src, r_tsptr, offsetof(trap_state, tpc));
34279422278eSRichard Henderson #else
34289422278eSRichard Henderson qemu_build_not_reached();
34299422278eSRichard Henderson #endif
34309422278eSRichard Henderson }
34319422278eSRichard Henderson
34329422278eSRichard Henderson TRANS(WRPR_tpc, 64, do_wr_special, a, supervisor(dc), do_wrtpc)
34339422278eSRichard Henderson
do_wrtnpc(DisasContext * dc,TCGv src)34349422278eSRichard Henderson static void do_wrtnpc(DisasContext *dc, TCGv src)
34359422278eSRichard Henderson {
34369422278eSRichard Henderson #ifdef TARGET_SPARC64
34379422278eSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr();
34389422278eSRichard Henderson
34399422278eSRichard Henderson gen_load_trap_state_at_tl(r_tsptr);
34409422278eSRichard Henderson tcg_gen_st_tl(src, r_tsptr, offsetof(trap_state, tnpc));
34419422278eSRichard Henderson #else
34429422278eSRichard Henderson qemu_build_not_reached();
34439422278eSRichard Henderson #endif
34449422278eSRichard Henderson }
34459422278eSRichard Henderson
34469422278eSRichard Henderson TRANS(WRPR_tnpc, 64, do_wr_special, a, supervisor(dc), do_wrtnpc)
34479422278eSRichard Henderson
do_wrtstate(DisasContext * dc,TCGv src)34489422278eSRichard Henderson static void do_wrtstate(DisasContext *dc, TCGv src)
34499422278eSRichard Henderson {
34509422278eSRichard Henderson #ifdef TARGET_SPARC64
34519422278eSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr();
34529422278eSRichard Henderson
34539422278eSRichard Henderson gen_load_trap_state_at_tl(r_tsptr);
34549422278eSRichard Henderson tcg_gen_st_tl(src, r_tsptr, offsetof(trap_state, tstate));
34559422278eSRichard Henderson #else
34569422278eSRichard Henderson qemu_build_not_reached();
34579422278eSRichard Henderson #endif
34589422278eSRichard Henderson }
34599422278eSRichard Henderson
34609422278eSRichard Henderson TRANS(WRPR_tstate, 64, do_wr_special, a, supervisor(dc), do_wrtstate)
34619422278eSRichard Henderson
do_wrtt(DisasContext * dc,TCGv src)34629422278eSRichard Henderson static void do_wrtt(DisasContext *dc, TCGv src)
34639422278eSRichard Henderson {
34649422278eSRichard Henderson #ifdef TARGET_SPARC64
34659422278eSRichard Henderson TCGv_ptr r_tsptr = tcg_temp_new_ptr();
34669422278eSRichard Henderson
34679422278eSRichard Henderson gen_load_trap_state_at_tl(r_tsptr);
34689422278eSRichard Henderson tcg_gen_st32_tl(src, r_tsptr, offsetof(trap_state, tt));
34699422278eSRichard Henderson #else
34709422278eSRichard Henderson qemu_build_not_reached();
34719422278eSRichard Henderson #endif
34729422278eSRichard Henderson }
34739422278eSRichard Henderson
34749422278eSRichard Henderson TRANS(WRPR_tt, 64, do_wr_special, a, supervisor(dc), do_wrtt)
34759422278eSRichard Henderson
do_wrtick(DisasContext * dc,TCGv src)34769422278eSRichard Henderson static void do_wrtick(DisasContext *dc, TCGv src)
34779422278eSRichard Henderson {
34789422278eSRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr();
34799422278eSRichard Henderson
34809422278eSRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(tick));
34819422278eSRichard Henderson translator_io_start(&dc->base);
34829422278eSRichard Henderson gen_helper_tick_set_count(r_tickptr, src);
34839422278eSRichard Henderson /* End TB to handle timer interrupt */
34849422278eSRichard Henderson dc->base.is_jmp = DISAS_EXIT;
34859422278eSRichard Henderson }
34869422278eSRichard Henderson
34879422278eSRichard Henderson TRANS(WRPR_tick, 64, do_wr_special, a, supervisor(dc), do_wrtick)
34889422278eSRichard Henderson
do_wrtba(DisasContext * dc,TCGv src)34899422278eSRichard Henderson static void do_wrtba(DisasContext *dc, TCGv src)
34909422278eSRichard Henderson {
34919422278eSRichard Henderson tcg_gen_mov_tl(cpu_tbr, src);
34929422278eSRichard Henderson }
34939422278eSRichard Henderson
34949422278eSRichard Henderson TRANS(WRPR_tba, 64, do_wr_special, a, supervisor(dc), do_wrtba)
34959422278eSRichard Henderson
do_wrpstate(DisasContext * dc,TCGv src)34969422278eSRichard Henderson static void do_wrpstate(DisasContext *dc, TCGv src)
34979422278eSRichard Henderson {
34989422278eSRichard Henderson save_state(dc);
34999422278eSRichard Henderson if (translator_io_start(&dc->base)) {
35009422278eSRichard Henderson dc->base.is_jmp = DISAS_EXIT;
35019422278eSRichard Henderson }
35029422278eSRichard Henderson gen_helper_wrpstate(tcg_env, src);
35039422278eSRichard Henderson dc->npc = DYNAMIC_PC;
35049422278eSRichard Henderson }
35059422278eSRichard Henderson
35069422278eSRichard Henderson TRANS(WRPR_pstate, 64, do_wr_special, a, supervisor(dc), do_wrpstate)
35079422278eSRichard Henderson
do_wrtl(DisasContext * dc,TCGv src)35089422278eSRichard Henderson static void do_wrtl(DisasContext *dc, TCGv src)
35099422278eSRichard Henderson {
35109422278eSRichard Henderson save_state(dc);
35119422278eSRichard Henderson tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(tl));
35129422278eSRichard Henderson dc->npc = DYNAMIC_PC;
35139422278eSRichard Henderson }
35149422278eSRichard Henderson
35159422278eSRichard Henderson TRANS(WRPR_tl, 64, do_wr_special, a, supervisor(dc), do_wrtl)
35169422278eSRichard Henderson
do_wrpil(DisasContext * dc,TCGv src)35179422278eSRichard Henderson static void do_wrpil(DisasContext *dc, TCGv src)
35189422278eSRichard Henderson {
35199422278eSRichard Henderson if (translator_io_start(&dc->base)) {
35209422278eSRichard Henderson dc->base.is_jmp = DISAS_EXIT;
35219422278eSRichard Henderson }
35229422278eSRichard Henderson gen_helper_wrpil(tcg_env, src);
35239422278eSRichard Henderson }
35249422278eSRichard Henderson
35259422278eSRichard Henderson TRANS(WRPR_pil, 64, do_wr_special, a, supervisor(dc), do_wrpil)
35269422278eSRichard Henderson
do_wrcwp(DisasContext * dc,TCGv src)35279422278eSRichard Henderson static void do_wrcwp(DisasContext *dc, TCGv src)
35289422278eSRichard Henderson {
35299422278eSRichard Henderson gen_helper_wrcwp(tcg_env, src);
35309422278eSRichard Henderson }
35319422278eSRichard Henderson
35329422278eSRichard Henderson TRANS(WRPR_cwp, 64, do_wr_special, a, supervisor(dc), do_wrcwp)
35339422278eSRichard Henderson
do_wrcansave(DisasContext * dc,TCGv src)35349422278eSRichard Henderson static void do_wrcansave(DisasContext *dc, TCGv src)
35359422278eSRichard Henderson {
35369422278eSRichard Henderson tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(cansave));
35379422278eSRichard Henderson }
35389422278eSRichard Henderson
35399422278eSRichard Henderson TRANS(WRPR_cansave, 64, do_wr_special, a, supervisor(dc), do_wrcansave)
35409422278eSRichard Henderson
do_wrcanrestore(DisasContext * dc,TCGv src)35419422278eSRichard Henderson static void do_wrcanrestore(DisasContext *dc, TCGv src)
35429422278eSRichard Henderson {
35439422278eSRichard Henderson tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(canrestore));
35449422278eSRichard Henderson }
35459422278eSRichard Henderson
35469422278eSRichard Henderson TRANS(WRPR_canrestore, 64, do_wr_special, a, supervisor(dc), do_wrcanrestore)
35479422278eSRichard Henderson
do_wrcleanwin(DisasContext * dc,TCGv src)35489422278eSRichard Henderson static void do_wrcleanwin(DisasContext *dc, TCGv src)
35499422278eSRichard Henderson {
35509422278eSRichard Henderson tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(cleanwin));
35519422278eSRichard Henderson }
35529422278eSRichard Henderson
35539422278eSRichard Henderson TRANS(WRPR_cleanwin, 64, do_wr_special, a, supervisor(dc), do_wrcleanwin)
35549422278eSRichard Henderson
do_wrotherwin(DisasContext * dc,TCGv src)35559422278eSRichard Henderson static void do_wrotherwin(DisasContext *dc, TCGv src)
35569422278eSRichard Henderson {
35579422278eSRichard Henderson tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(otherwin));
35589422278eSRichard Henderson }
35599422278eSRichard Henderson
35609422278eSRichard Henderson TRANS(WRPR_otherwin, 64, do_wr_special, a, supervisor(dc), do_wrotherwin)
35619422278eSRichard Henderson
do_wrwstate(DisasContext * dc,TCGv src)35629422278eSRichard Henderson static void do_wrwstate(DisasContext *dc, TCGv src)
35639422278eSRichard Henderson {
35649422278eSRichard Henderson tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(wstate));
35659422278eSRichard Henderson }
35669422278eSRichard Henderson
35679422278eSRichard Henderson TRANS(WRPR_wstate, 64, do_wr_special, a, supervisor(dc), do_wrwstate)
35689422278eSRichard Henderson
do_wrgl(DisasContext * dc,TCGv src)35699422278eSRichard Henderson static void do_wrgl(DisasContext *dc, TCGv src)
35709422278eSRichard Henderson {
35719422278eSRichard Henderson gen_helper_wrgl(tcg_env, src);
35729422278eSRichard Henderson }
35739422278eSRichard Henderson
TRANS(WRPR_gl,GL,do_wr_special,a,supervisor (dc),do_wrgl)35749422278eSRichard Henderson TRANS(WRPR_gl, GL, do_wr_special, a, supervisor(dc), do_wrgl)
35759422278eSRichard Henderson
35769422278eSRichard Henderson /* UA2005 strand status */
35779422278eSRichard Henderson static void do_wrssr(DisasContext *dc, TCGv src)
35789422278eSRichard Henderson {
35792da789deSRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(ssr));
35809422278eSRichard Henderson }
35819422278eSRichard Henderson
TRANS(WRPR_strand_status,HYPV,do_wr_special,a,hypervisor (dc),do_wrssr)35829422278eSRichard Henderson TRANS(WRPR_strand_status, HYPV, do_wr_special, a, hypervisor(dc), do_wrssr)
35839422278eSRichard Henderson
3584bb97f2f5SRichard Henderson TRANS(WRTBR, 32, do_wr_special, a, supervisor(dc), do_wrtba)
3585bb97f2f5SRichard Henderson
3586bb97f2f5SRichard Henderson static void do_wrhpstate(DisasContext *dc, TCGv src)
3587bb97f2f5SRichard Henderson {
3588bb97f2f5SRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(hpstate));
3589bb97f2f5SRichard Henderson dc->base.is_jmp = DISAS_EXIT;
3590bb97f2f5SRichard Henderson }
3591bb97f2f5SRichard Henderson
TRANS(WRHPR_hpstate,HYPV,do_wr_special,a,hypervisor (dc),do_wrhpstate)3592bb97f2f5SRichard Henderson TRANS(WRHPR_hpstate, HYPV, do_wr_special, a, hypervisor(dc), do_wrhpstate)
3593bb97f2f5SRichard Henderson
3594bb97f2f5SRichard Henderson static void do_wrhtstate(DisasContext *dc, TCGv src)
3595bb97f2f5SRichard Henderson {
3596bb97f2f5SRichard Henderson TCGv_i32 tl = tcg_temp_new_i32();
3597bb97f2f5SRichard Henderson TCGv_ptr tp = tcg_temp_new_ptr();
3598bb97f2f5SRichard Henderson
3599bb97f2f5SRichard Henderson tcg_gen_ld_i32(tl, tcg_env, env64_field_offsetof(tl));
3600bb97f2f5SRichard Henderson tcg_gen_andi_i32(tl, tl, MAXTL_MASK);
3601bb97f2f5SRichard Henderson tcg_gen_shli_i32(tl, tl, 3);
3602bb97f2f5SRichard Henderson tcg_gen_ext_i32_ptr(tp, tl);
3603bb97f2f5SRichard Henderson tcg_gen_add_ptr(tp, tp, tcg_env);
3604bb97f2f5SRichard Henderson
3605bb97f2f5SRichard Henderson tcg_gen_st_tl(src, tp, env64_field_offsetof(htstate));
3606bb97f2f5SRichard Henderson }
3607bb97f2f5SRichard Henderson
TRANS(WRHPR_htstate,HYPV,do_wr_special,a,hypervisor (dc),do_wrhtstate)3608bb97f2f5SRichard Henderson TRANS(WRHPR_htstate, HYPV, do_wr_special, a, hypervisor(dc), do_wrhtstate)
3609bb97f2f5SRichard Henderson
3610bb97f2f5SRichard Henderson static void do_wrhintp(DisasContext *dc, TCGv src)
3611bb97f2f5SRichard Henderson {
36122da789deSRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(hintp));
3613bb97f2f5SRichard Henderson }
3614bb97f2f5SRichard Henderson
TRANS(WRHPR_hintp,HYPV,do_wr_special,a,hypervisor (dc),do_wrhintp)3615bb97f2f5SRichard Henderson TRANS(WRHPR_hintp, HYPV, do_wr_special, a, hypervisor(dc), do_wrhintp)
3616bb97f2f5SRichard Henderson
3617bb97f2f5SRichard Henderson static void do_wrhtba(DisasContext *dc, TCGv src)
3618bb97f2f5SRichard Henderson {
36192da789deSRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(htba));
3620bb97f2f5SRichard Henderson }
3621bb97f2f5SRichard Henderson
TRANS(WRHPR_htba,HYPV,do_wr_special,a,hypervisor (dc),do_wrhtba)3622bb97f2f5SRichard Henderson TRANS(WRHPR_htba, HYPV, do_wr_special, a, hypervisor(dc), do_wrhtba)
3623bb97f2f5SRichard Henderson
3624bb97f2f5SRichard Henderson static void do_wrhstick_cmpr(DisasContext *dc, TCGv src)
3625bb97f2f5SRichard Henderson {
3626bb97f2f5SRichard Henderson TCGv_ptr r_tickptr = tcg_temp_new_ptr();
3627bb97f2f5SRichard Henderson
3628577efa45SRichard Henderson tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(hstick_cmpr));
3629bb97f2f5SRichard Henderson tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(hstick));
3630bb97f2f5SRichard Henderson translator_io_start(&dc->base);
3631577efa45SRichard Henderson gen_helper_tick_set_limit(r_tickptr, src);
3632bb97f2f5SRichard Henderson /* End TB to handle timer interrupt */
3633bb97f2f5SRichard Henderson dc->base.is_jmp = DISAS_EXIT;
3634bb97f2f5SRichard Henderson }
3635bb97f2f5SRichard Henderson
TRANS(WRHPR_hstick_cmpr,HYPV,do_wr_special,a,hypervisor (dc),do_wrhstick_cmpr)3636bb97f2f5SRichard Henderson TRANS(WRHPR_hstick_cmpr, HYPV, do_wr_special, a, hypervisor(dc),
3637bb97f2f5SRichard Henderson do_wrhstick_cmpr)
3638bb97f2f5SRichard Henderson
363925524734SRichard Henderson static bool do_saved_restored(DisasContext *dc, bool saved)
364025524734SRichard Henderson {
364125524734SRichard Henderson if (!supervisor(dc)) {
364225524734SRichard Henderson return raise_priv(dc);
364325524734SRichard Henderson }
364425524734SRichard Henderson if (saved) {
364525524734SRichard Henderson gen_helper_saved(tcg_env);
364625524734SRichard Henderson } else {
364725524734SRichard Henderson gen_helper_restored(tcg_env);
364825524734SRichard Henderson }
364925524734SRichard Henderson return advance_pc(dc);
365025524734SRichard Henderson }
365125524734SRichard Henderson
365225524734SRichard Henderson TRANS(SAVED, 64, do_saved_restored, true)
365325524734SRichard Henderson TRANS(RESTORED, 64, do_saved_restored, false)
365425524734SRichard Henderson
trans_NOP(DisasContext * dc,arg_NOP * a)3655d3825800SRichard Henderson static bool trans_NOP(DisasContext *dc, arg_NOP *a)
3656d3825800SRichard Henderson {
3657d3825800SRichard Henderson return advance_pc(dc);
3658d3825800SRichard Henderson }
3659d3825800SRichard Henderson
36600faef01bSRichard Henderson /*
36610faef01bSRichard Henderson * TODO: Need a feature bit for sparcv8.
36620faef01bSRichard Henderson * In the meantime, treat all 32-bit cpus like sparcv7.
36630faef01bSRichard Henderson */
36645458fd31SRichard Henderson TRANS(NOP_v7, 32, trans_NOP, a)
36655458fd31SRichard Henderson TRANS(NOP_v9, 64, trans_NOP, a)
36660faef01bSRichard Henderson
do_arith_int(DisasContext * dc,arg_r_r_ri_cc * a,void (* func)(TCGv,TCGv,TCGv),void (* funci)(TCGv,TCGv,target_long),bool logic_cc)3667b597eedcSRichard Henderson static bool do_arith_int(DisasContext *dc, arg_r_r_ri_cc *a,
3668428881deSRichard Henderson void (*func)(TCGv, TCGv, TCGv),
36692a45b736SRichard Henderson void (*funci)(TCGv, TCGv, target_long),
36702a45b736SRichard Henderson bool logic_cc)
3671428881deSRichard Henderson {
3672428881deSRichard Henderson TCGv dst, src1;
3673428881deSRichard Henderson
3674428881deSRichard Henderson /* For simplicity, we under-decoded the rs2 form. */
3675428881deSRichard Henderson if (!a->imm && a->rs2_or_imm & ~0x1f) {
3676428881deSRichard Henderson return false;
3677428881deSRichard Henderson }
3678428881deSRichard Henderson
36792a45b736SRichard Henderson if (logic_cc) {
36802a45b736SRichard Henderson dst = cpu_cc_N;
3681428881deSRichard Henderson } else {
3682428881deSRichard Henderson dst = gen_dest_gpr(dc, a->rd);
3683428881deSRichard Henderson }
3684428881deSRichard Henderson src1 = gen_load_gpr(dc, a->rs1);
3685428881deSRichard Henderson
3686428881deSRichard Henderson if (a->imm || a->rs2_or_imm == 0) {
3687428881deSRichard Henderson if (funci) {
3688428881deSRichard Henderson funci(dst, src1, a->rs2_or_imm);
3689428881deSRichard Henderson } else {
3690428881deSRichard Henderson func(dst, src1, tcg_constant_tl(a->rs2_or_imm));
3691428881deSRichard Henderson }
3692428881deSRichard Henderson } else {
3693428881deSRichard Henderson func(dst, src1, cpu_regs[a->rs2_or_imm]);
3694428881deSRichard Henderson }
36952a45b736SRichard Henderson
36962a45b736SRichard Henderson if (logic_cc) {
36972a45b736SRichard Henderson if (TARGET_LONG_BITS == 64) {
36982a45b736SRichard Henderson tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N);
36992a45b736SRichard Henderson tcg_gen_movi_tl(cpu_icc_C, 0);
37002a45b736SRichard Henderson }
37012a45b736SRichard Henderson tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N);
37022a45b736SRichard Henderson tcg_gen_movi_tl(cpu_cc_C, 0);
37032a45b736SRichard Henderson tcg_gen_movi_tl(cpu_cc_V, 0);
37042a45b736SRichard Henderson }
37052a45b736SRichard Henderson
3706428881deSRichard Henderson gen_store_gpr(dc, a->rd, dst);
3707428881deSRichard Henderson return advance_pc(dc);
3708428881deSRichard Henderson }
3709428881deSRichard Henderson
do_arith(DisasContext * dc,arg_r_r_ri_cc * a,void (* func)(TCGv,TCGv,TCGv),void (* funci)(TCGv,TCGv,target_long),void (* func_cc)(TCGv,TCGv,TCGv))3710b597eedcSRichard Henderson static bool do_arith(DisasContext *dc, arg_r_r_ri_cc *a,
3711428881deSRichard Henderson void (*func)(TCGv, TCGv, TCGv),
3712428881deSRichard Henderson void (*funci)(TCGv, TCGv, target_long),
3713428881deSRichard Henderson void (*func_cc)(TCGv, TCGv, TCGv))
3714428881deSRichard Henderson {
3715428881deSRichard Henderson if (a->cc) {
3716b597eedcSRichard Henderson return do_arith_int(dc, a, func_cc, NULL, false);
3717428881deSRichard Henderson }
3718b597eedcSRichard Henderson return do_arith_int(dc, a, func, funci, false);
3719428881deSRichard Henderson }
3720428881deSRichard Henderson
do_logic(DisasContext * dc,arg_r_r_ri_cc * a,void (* func)(TCGv,TCGv,TCGv),void (* funci)(TCGv,TCGv,target_long))3721428881deSRichard Henderson static bool do_logic(DisasContext *dc, arg_r_r_ri_cc *a,
3722428881deSRichard Henderson void (*func)(TCGv, TCGv, TCGv),
3723428881deSRichard Henderson void (*funci)(TCGv, TCGv, target_long))
3724428881deSRichard Henderson {
3725b597eedcSRichard Henderson return do_arith_int(dc, a, func, funci, a->cc);
3726428881deSRichard Henderson }
3727428881deSRichard Henderson
TRANS(ADD,ALL,do_arith,a,tcg_gen_add_tl,tcg_gen_addi_tl,gen_op_addcc)3728b597eedcSRichard Henderson TRANS(ADD, ALL, do_arith, a, tcg_gen_add_tl, tcg_gen_addi_tl, gen_op_addcc)
3729b597eedcSRichard Henderson TRANS(SUB, ALL, do_arith, a, tcg_gen_sub_tl, tcg_gen_subi_tl, gen_op_subcc)
3730b597eedcSRichard Henderson TRANS(ADDC, ALL, do_arith, a, gen_op_addc, NULL, gen_op_addccc)
3731b597eedcSRichard Henderson TRANS(SUBC, ALL, do_arith, a, gen_op_subc, NULL, gen_op_subccc)
3732428881deSRichard Henderson
3733b597eedcSRichard Henderson TRANS(TADDcc, ALL, do_arith, a, NULL, NULL, gen_op_taddcc)
3734b597eedcSRichard Henderson TRANS(TSUBcc, ALL, do_arith, a, NULL, NULL, gen_op_tsubcc)
3735b597eedcSRichard Henderson TRANS(TADDccTV, ALL, do_arith, a, NULL, NULL, gen_op_taddcctv)
3736b597eedcSRichard Henderson TRANS(TSUBccTV, ALL, do_arith, a, NULL, NULL, gen_op_tsubcctv)
3737a9aba13dSRichard Henderson
3738428881deSRichard Henderson TRANS(AND, ALL, do_logic, a, tcg_gen_and_tl, tcg_gen_andi_tl)
3739428881deSRichard Henderson TRANS(XOR, ALL, do_logic, a, tcg_gen_xor_tl, tcg_gen_xori_tl)
3740428881deSRichard Henderson TRANS(ANDN, ALL, do_logic, a, tcg_gen_andc_tl, NULL)
3741428881deSRichard Henderson TRANS(ORN, ALL, do_logic, a, tcg_gen_orc_tl, NULL)
3742428881deSRichard Henderson TRANS(XORN, ALL, do_logic, a, tcg_gen_eqv_tl, NULL)
3743428881deSRichard Henderson
3744b597eedcSRichard Henderson TRANS(MULX, 64, do_arith, a, tcg_gen_mul_tl, tcg_gen_muli_tl, NULL)
3745b5372650SRichard Henderson TRANS(UMUL, MUL, do_logic, a, gen_op_umul, NULL)
3746b5372650SRichard Henderson TRANS(SMUL, MUL, do_logic, a, gen_op_smul, NULL)
3747b597eedcSRichard Henderson TRANS(MULScc, ALL, do_arith, a, NULL, NULL, gen_op_mulscc)
374822188d7dSRichard Henderson
37493a6b8de3SRichard Henderson TRANS(UDIVcc, DIV, do_arith, a, NULL, NULL, gen_op_udivcc)
3750b597eedcSRichard Henderson TRANS(SDIV, DIV, do_arith, a, gen_op_sdiv, NULL, gen_op_sdivcc)
37514ee85ea9SRichard Henderson
37529c6ec5bcSRichard Henderson /* TODO: Should have feature bit -- comes in with UltraSparc T2. */
3753b597eedcSRichard Henderson TRANS(POPC, 64, do_arith, a, gen_op_popc, NULL, NULL)
37549c6ec5bcSRichard Henderson
3755428881deSRichard Henderson static bool trans_OR(DisasContext *dc, arg_r_r_ri_cc *a)
3756428881deSRichard Henderson {
3757428881deSRichard Henderson /* OR with %g0 is the canonical alias for MOV. */
3758428881deSRichard Henderson if (!a->cc && a->rs1 == 0) {
3759428881deSRichard Henderson if (a->imm || a->rs2_or_imm == 0) {
3760428881deSRichard Henderson gen_store_gpr(dc, a->rd, tcg_constant_tl(a->rs2_or_imm));
3761428881deSRichard Henderson } else if (a->rs2_or_imm & ~0x1f) {
3762428881deSRichard Henderson /* For simplicity, we under-decoded the rs2 form. */
3763428881deSRichard Henderson return false;
3764428881deSRichard Henderson } else {
3765428881deSRichard Henderson gen_store_gpr(dc, a->rd, cpu_regs[a->rs2_or_imm]);
3766428881deSRichard Henderson }
3767428881deSRichard Henderson return advance_pc(dc);
3768428881deSRichard Henderson }
3769428881deSRichard Henderson return do_logic(dc, a, tcg_gen_or_tl, tcg_gen_ori_tl);
3770428881deSRichard Henderson }
3771428881deSRichard Henderson
trans_UDIV(DisasContext * dc,arg_r_r_ri * a)37723a6b8de3SRichard Henderson static bool trans_UDIV(DisasContext *dc, arg_r_r_ri *a)
37733a6b8de3SRichard Henderson {
37743a6b8de3SRichard Henderson TCGv_i64 t1, t2;
37753a6b8de3SRichard Henderson TCGv dst;
37763a6b8de3SRichard Henderson
37773a6b8de3SRichard Henderson if (!avail_DIV(dc)) {
37783a6b8de3SRichard Henderson return false;
37793a6b8de3SRichard Henderson }
37803a6b8de3SRichard Henderson /* For simplicity, we under-decoded the rs2 form. */
37813a6b8de3SRichard Henderson if (!a->imm && a->rs2_or_imm & ~0x1f) {
37823a6b8de3SRichard Henderson return false;
37833a6b8de3SRichard Henderson }
37843a6b8de3SRichard Henderson
37853a6b8de3SRichard Henderson if (unlikely(a->rs2_or_imm == 0)) {
37863a6b8de3SRichard Henderson gen_exception(dc, TT_DIV_ZERO);
37873a6b8de3SRichard Henderson return true;
37883a6b8de3SRichard Henderson }
37893a6b8de3SRichard Henderson
37903a6b8de3SRichard Henderson if (a->imm) {
37913a6b8de3SRichard Henderson t2 = tcg_constant_i64((uint32_t)a->rs2_or_imm);
37923a6b8de3SRichard Henderson } else {
37933a6b8de3SRichard Henderson TCGLabel *lab;
37943a6b8de3SRichard Henderson TCGv_i32 n2;
37953a6b8de3SRichard Henderson
37963a6b8de3SRichard Henderson finishing_insn(dc);
37973a6b8de3SRichard Henderson flush_cond(dc);
37983a6b8de3SRichard Henderson
37993a6b8de3SRichard Henderson n2 = tcg_temp_new_i32();
38003a6b8de3SRichard Henderson tcg_gen_trunc_tl_i32(n2, cpu_regs[a->rs2_or_imm]);
38013a6b8de3SRichard Henderson
38023a6b8de3SRichard Henderson lab = delay_exception(dc, TT_DIV_ZERO);
38033a6b8de3SRichard Henderson tcg_gen_brcondi_i32(TCG_COND_EQ, n2, 0, lab);
38043a6b8de3SRichard Henderson
38053a6b8de3SRichard Henderson t2 = tcg_temp_new_i64();
38063a6b8de3SRichard Henderson #ifdef TARGET_SPARC64
38073a6b8de3SRichard Henderson tcg_gen_ext32u_i64(t2, cpu_regs[a->rs2_or_imm]);
38083a6b8de3SRichard Henderson #else
38093a6b8de3SRichard Henderson tcg_gen_extu_i32_i64(t2, cpu_regs[a->rs2_or_imm]);
38103a6b8de3SRichard Henderson #endif
38113a6b8de3SRichard Henderson }
38123a6b8de3SRichard Henderson
38133a6b8de3SRichard Henderson t1 = tcg_temp_new_i64();
38143a6b8de3SRichard Henderson tcg_gen_concat_tl_i64(t1, gen_load_gpr(dc, a->rs1), cpu_y);
38153a6b8de3SRichard Henderson
38163a6b8de3SRichard Henderson tcg_gen_divu_i64(t1, t1, t2);
38173a6b8de3SRichard Henderson tcg_gen_umin_i64(t1, t1, tcg_constant_i64(UINT32_MAX));
38183a6b8de3SRichard Henderson
38193a6b8de3SRichard Henderson dst = gen_dest_gpr(dc, a->rd);
38203a6b8de3SRichard Henderson tcg_gen_trunc_i64_tl(dst, t1);
38213a6b8de3SRichard Henderson gen_store_gpr(dc, a->rd, dst);
38223a6b8de3SRichard Henderson return advance_pc(dc);
38233a6b8de3SRichard Henderson }
38243a6b8de3SRichard Henderson
trans_UDIVX(DisasContext * dc,arg_r_r_ri * a)3825f3141174SRichard Henderson static bool trans_UDIVX(DisasContext *dc, arg_r_r_ri *a)
3826f3141174SRichard Henderson {
3827f3141174SRichard Henderson TCGv dst, src1, src2;
3828f3141174SRichard Henderson
3829f3141174SRichard Henderson if (!avail_64(dc)) {
3830f3141174SRichard Henderson return false;
3831f3141174SRichard Henderson }
3832f3141174SRichard Henderson /* For simplicity, we under-decoded the rs2 form. */
3833f3141174SRichard Henderson if (!a->imm && a->rs2_or_imm & ~0x1f) {
3834f3141174SRichard Henderson return false;
3835f3141174SRichard Henderson }
3836f3141174SRichard Henderson
3837f3141174SRichard Henderson if (unlikely(a->rs2_or_imm == 0)) {
3838f3141174SRichard Henderson gen_exception(dc, TT_DIV_ZERO);
3839f3141174SRichard Henderson return true;
3840f3141174SRichard Henderson }
3841f3141174SRichard Henderson
3842f3141174SRichard Henderson if (a->imm) {
3843f3141174SRichard Henderson src2 = tcg_constant_tl(a->rs2_or_imm);
3844f3141174SRichard Henderson } else {
3845f3141174SRichard Henderson TCGLabel *lab;
3846f3141174SRichard Henderson
3847f3141174SRichard Henderson finishing_insn(dc);
3848f3141174SRichard Henderson flush_cond(dc);
3849f3141174SRichard Henderson
3850f3141174SRichard Henderson lab = delay_exception(dc, TT_DIV_ZERO);
3851f3141174SRichard Henderson src2 = cpu_regs[a->rs2_or_imm];
3852f3141174SRichard Henderson tcg_gen_brcondi_tl(TCG_COND_EQ, src2, 0, lab);
3853f3141174SRichard Henderson }
3854f3141174SRichard Henderson
3855f3141174SRichard Henderson dst = gen_dest_gpr(dc, a->rd);
3856f3141174SRichard Henderson src1 = gen_load_gpr(dc, a->rs1);
3857f3141174SRichard Henderson
3858f3141174SRichard Henderson tcg_gen_divu_tl(dst, src1, src2);
3859f3141174SRichard Henderson gen_store_gpr(dc, a->rd, dst);
3860f3141174SRichard Henderson return advance_pc(dc);
3861f3141174SRichard Henderson }
3862f3141174SRichard Henderson
trans_SDIVX(DisasContext * dc,arg_r_r_ri * a)3863f3141174SRichard Henderson static bool trans_SDIVX(DisasContext *dc, arg_r_r_ri *a)
3864f3141174SRichard Henderson {
3865f3141174SRichard Henderson TCGv dst, src1, src2;
3866f3141174SRichard Henderson
3867f3141174SRichard Henderson if (!avail_64(dc)) {
3868f3141174SRichard Henderson return false;
3869f3141174SRichard Henderson }
3870f3141174SRichard Henderson /* For simplicity, we under-decoded the rs2 form. */
3871f3141174SRichard Henderson if (!a->imm && a->rs2_or_imm & ~0x1f) {
3872f3141174SRichard Henderson return false;
3873f3141174SRichard Henderson }
3874f3141174SRichard Henderson
3875f3141174SRichard Henderson if (unlikely(a->rs2_or_imm == 0)) {
3876f3141174SRichard Henderson gen_exception(dc, TT_DIV_ZERO);
3877f3141174SRichard Henderson return true;
3878f3141174SRichard Henderson }
3879f3141174SRichard Henderson
3880f3141174SRichard Henderson dst = gen_dest_gpr(dc, a->rd);
3881f3141174SRichard Henderson src1 = gen_load_gpr(dc, a->rs1);
3882f3141174SRichard Henderson
3883f3141174SRichard Henderson if (a->imm) {
3884f3141174SRichard Henderson if (unlikely(a->rs2_or_imm == -1)) {
3885f3141174SRichard Henderson tcg_gen_neg_tl(dst, src1);
3886f3141174SRichard Henderson gen_store_gpr(dc, a->rd, dst);
3887f3141174SRichard Henderson return advance_pc(dc);
3888f3141174SRichard Henderson }
3889f3141174SRichard Henderson src2 = tcg_constant_tl(a->rs2_or_imm);
3890f3141174SRichard Henderson } else {
3891f3141174SRichard Henderson TCGLabel *lab;
3892f3141174SRichard Henderson TCGv t1, t2;
3893f3141174SRichard Henderson
3894f3141174SRichard Henderson finishing_insn(dc);
3895f3141174SRichard Henderson flush_cond(dc);
3896f3141174SRichard Henderson
3897f3141174SRichard Henderson lab = delay_exception(dc, TT_DIV_ZERO);
3898f3141174SRichard Henderson src2 = cpu_regs[a->rs2_or_imm];
3899f3141174SRichard Henderson tcg_gen_brcondi_tl(TCG_COND_EQ, src2, 0, lab);
3900f3141174SRichard Henderson
3901f3141174SRichard Henderson /*
3902f3141174SRichard Henderson * Need to avoid INT64_MIN / -1, which will trap on x86 host.
3903f3141174SRichard Henderson * Set SRC2 to 1 as a new divisor, to produce the correct result.
3904f3141174SRichard Henderson */
3905f3141174SRichard Henderson t1 = tcg_temp_new();
3906f3141174SRichard Henderson t2 = tcg_temp_new();
3907f3141174SRichard Henderson tcg_gen_setcondi_tl(TCG_COND_EQ, t1, src1, (target_long)INT64_MIN);
3908f3141174SRichard Henderson tcg_gen_setcondi_tl(TCG_COND_EQ, t2, src2, -1);
3909f3141174SRichard Henderson tcg_gen_and_tl(t1, t1, t2);
3910f3141174SRichard Henderson tcg_gen_movcond_tl(TCG_COND_NE, t1, t1, tcg_constant_tl(0),
3911f3141174SRichard Henderson tcg_constant_tl(1), src2);
3912f3141174SRichard Henderson src2 = t1;
3913f3141174SRichard Henderson }
3914f3141174SRichard Henderson
3915f3141174SRichard Henderson tcg_gen_div_tl(dst, src1, src2);
3916f3141174SRichard Henderson gen_store_gpr(dc, a->rd, dst);
3917f3141174SRichard Henderson return advance_pc(dc);
3918f3141174SRichard Henderson }
3919f3141174SRichard Henderson
gen_edge(DisasContext * dc,arg_r_r_r * a,int width,bool cc,bool little_endian)3920b88ce6f2SRichard Henderson static bool gen_edge(DisasContext *dc, arg_r_r_r *a,
392143db5838SRichard Henderson int width, bool cc, bool little_endian)
3922b88ce6f2SRichard Henderson {
392343db5838SRichard Henderson TCGv dst, s1, s2, l, r, t, m;
392443db5838SRichard Henderson uint64_t amask = address_mask_i(dc, -8);
3925b88ce6f2SRichard Henderson
3926b88ce6f2SRichard Henderson dst = gen_dest_gpr(dc, a->rd);
3927b88ce6f2SRichard Henderson s1 = gen_load_gpr(dc, a->rs1);
3928b88ce6f2SRichard Henderson s2 = gen_load_gpr(dc, a->rs2);
3929b88ce6f2SRichard Henderson
3930b88ce6f2SRichard Henderson if (cc) {
3931f828df74SRichard Henderson gen_op_subcc(cpu_cc_N, s1, s2);
3932b88ce6f2SRichard Henderson }
3933b88ce6f2SRichard Henderson
393443db5838SRichard Henderson l = tcg_temp_new();
393543db5838SRichard Henderson r = tcg_temp_new();
393643db5838SRichard Henderson t = tcg_temp_new();
393743db5838SRichard Henderson
3938b88ce6f2SRichard Henderson switch (width) {
3939b88ce6f2SRichard Henderson case 8:
394043db5838SRichard Henderson tcg_gen_andi_tl(l, s1, 7);
394143db5838SRichard Henderson tcg_gen_andi_tl(r, s2, 7);
394243db5838SRichard Henderson tcg_gen_xori_tl(r, r, 7);
394343db5838SRichard Henderson m = tcg_constant_tl(0xff);
3944b88ce6f2SRichard Henderson break;
3945b88ce6f2SRichard Henderson case 16:
394643db5838SRichard Henderson tcg_gen_extract_tl(l, s1, 1, 2);
394743db5838SRichard Henderson tcg_gen_extract_tl(r, s2, 1, 2);
394843db5838SRichard Henderson tcg_gen_xori_tl(r, r, 3);
394943db5838SRichard Henderson m = tcg_constant_tl(0xf);
3950b88ce6f2SRichard Henderson break;
3951b88ce6f2SRichard Henderson case 32:
395243db5838SRichard Henderson tcg_gen_extract_tl(l, s1, 2, 1);
395343db5838SRichard Henderson tcg_gen_extract_tl(r, s2, 2, 1);
395443db5838SRichard Henderson tcg_gen_xori_tl(r, r, 1);
395543db5838SRichard Henderson m = tcg_constant_tl(0x3);
3956b88ce6f2SRichard Henderson break;
3957b88ce6f2SRichard Henderson default:
3958b88ce6f2SRichard Henderson abort();
3959b88ce6f2SRichard Henderson }
3960b88ce6f2SRichard Henderson
396143db5838SRichard Henderson /* Compute Left Edge */
396243db5838SRichard Henderson if (little_endian) {
396343db5838SRichard Henderson tcg_gen_shl_tl(l, m, l);
396443db5838SRichard Henderson tcg_gen_and_tl(l, l, m);
396543db5838SRichard Henderson } else {
396643db5838SRichard Henderson tcg_gen_shr_tl(l, m, l);
396743db5838SRichard Henderson }
396843db5838SRichard Henderson /* Compute Right Edge */
396943db5838SRichard Henderson if (little_endian) {
397043db5838SRichard Henderson tcg_gen_shr_tl(r, m, r);
397143db5838SRichard Henderson } else {
397243db5838SRichard Henderson tcg_gen_shl_tl(r, m, r);
397343db5838SRichard Henderson tcg_gen_and_tl(r, r, m);
397443db5838SRichard Henderson }
3975b88ce6f2SRichard Henderson
397643db5838SRichard Henderson /* Compute dst = (s1 == s2 under amask ? l : l & r) */
397743db5838SRichard Henderson tcg_gen_xor_tl(t, s1, s2);
397843db5838SRichard Henderson tcg_gen_and_tl(r, r, l);
397943db5838SRichard Henderson tcg_gen_movcond_tl(TCG_COND_TSTEQ, dst, t, tcg_constant_tl(amask), r, l);
3980b88ce6f2SRichard Henderson
3981b88ce6f2SRichard Henderson gen_store_gpr(dc, a->rd, dst);
3982b88ce6f2SRichard Henderson return advance_pc(dc);
3983b88ce6f2SRichard Henderson }
3984b88ce6f2SRichard Henderson
3985b88ce6f2SRichard Henderson TRANS(EDGE8cc, VIS1, gen_edge, a, 8, 1, 0)
3986b88ce6f2SRichard Henderson TRANS(EDGE8Lcc, VIS1, gen_edge, a, 8, 1, 1)
3987b88ce6f2SRichard Henderson TRANS(EDGE16cc, VIS1, gen_edge, a, 16, 1, 0)
3988b88ce6f2SRichard Henderson TRANS(EDGE16Lcc, VIS1, gen_edge, a, 16, 1, 1)
3989b88ce6f2SRichard Henderson TRANS(EDGE32cc, VIS1, gen_edge, a, 32, 1, 0)
3990b88ce6f2SRichard Henderson TRANS(EDGE32Lcc, VIS1, gen_edge, a, 32, 1, 1)
3991b88ce6f2SRichard Henderson
3992b88ce6f2SRichard Henderson TRANS(EDGE8N, VIS2, gen_edge, a, 8, 0, 0)
3993b88ce6f2SRichard Henderson TRANS(EDGE8LN, VIS2, gen_edge, a, 8, 0, 1)
3994b88ce6f2SRichard Henderson TRANS(EDGE16N, VIS2, gen_edge, a, 16, 0, 0)
3995b88ce6f2SRichard Henderson TRANS(EDGE16LN, VIS2, gen_edge, a, 16, 0, 1)
3996b88ce6f2SRichard Henderson TRANS(EDGE32N, VIS2, gen_edge, a, 32, 0, 0)
3997b88ce6f2SRichard Henderson TRANS(EDGE32LN, VIS2, gen_edge, a, 32, 0, 1)
3998b88ce6f2SRichard Henderson
do_rr(DisasContext * dc,arg_r_r * a,void (* func)(TCGv,TCGv))3999875ce392SRichard Henderson static bool do_rr(DisasContext *dc, arg_r_r *a,
4000875ce392SRichard Henderson void (*func)(TCGv, TCGv))
4001875ce392SRichard Henderson {
4002875ce392SRichard Henderson TCGv dst = gen_dest_gpr(dc, a->rd);
4003875ce392SRichard Henderson TCGv src = gen_load_gpr(dc, a->rs);
4004875ce392SRichard Henderson
4005875ce392SRichard Henderson func(dst, src);
4006875ce392SRichard Henderson gen_store_gpr(dc, a->rd, dst);
4007875ce392SRichard Henderson return advance_pc(dc);
4008875ce392SRichard Henderson }
4009875ce392SRichard Henderson
TRANS(LZCNT,VIS3,do_rr,a,gen_op_lzcnt)4010875ce392SRichard Henderson TRANS(LZCNT, VIS3, do_rr, a, gen_op_lzcnt)
4011875ce392SRichard Henderson
401245bfed3bSRichard Henderson static bool do_rrr(DisasContext *dc, arg_r_r_r *a,
401345bfed3bSRichard Henderson void (*func)(TCGv, TCGv, TCGv))
401445bfed3bSRichard Henderson {
401545bfed3bSRichard Henderson TCGv dst = gen_dest_gpr(dc, a->rd);
401645bfed3bSRichard Henderson TCGv src1 = gen_load_gpr(dc, a->rs1);
401745bfed3bSRichard Henderson TCGv src2 = gen_load_gpr(dc, a->rs2);
401845bfed3bSRichard Henderson
401945bfed3bSRichard Henderson func(dst, src1, src2);
402045bfed3bSRichard Henderson gen_store_gpr(dc, a->rd, dst);
402145bfed3bSRichard Henderson return advance_pc(dc);
402245bfed3bSRichard Henderson }
402345bfed3bSRichard Henderson
TRANS(ARRAY8,VIS1,do_rrr,a,gen_helper_array8)402445bfed3bSRichard Henderson TRANS(ARRAY8, VIS1, do_rrr, a, gen_helper_array8)
402545bfed3bSRichard Henderson TRANS(ARRAY16, VIS1, do_rrr, a, gen_op_array16)
402645bfed3bSRichard Henderson TRANS(ARRAY32, VIS1, do_rrr, a, gen_op_array32)
402745bfed3bSRichard Henderson
4028015fc6fcSRichard Henderson TRANS(ADDXC, VIS3, do_rrr, a, gen_op_addxc)
4029015fc6fcSRichard Henderson TRANS(ADDXCcc, VIS3, do_rrr, a, gen_op_addxccc)
4030015fc6fcSRichard Henderson
403156f2ef9cSRichard Henderson TRANS(SUBXC, VIS4, do_rrr, a, gen_op_subxc)
403256f2ef9cSRichard Henderson TRANS(SUBXCcc, VIS4, do_rrr, a, gen_op_subxccc)
403356f2ef9cSRichard Henderson
4034680af1b4SRichard Henderson TRANS(UMULXHI, VIS3, do_rrr, a, gen_op_umulxhi)
4035680af1b4SRichard Henderson
40369e20ca94SRichard Henderson static void gen_op_alignaddr(TCGv dst, TCGv s1, TCGv s2)
40379e20ca94SRichard Henderson {
40389e20ca94SRichard Henderson #ifdef TARGET_SPARC64
40399e20ca94SRichard Henderson TCGv tmp = tcg_temp_new();
40409e20ca94SRichard Henderson
40419e20ca94SRichard Henderson tcg_gen_add_tl(tmp, s1, s2);
40429e20ca94SRichard Henderson tcg_gen_andi_tl(dst, tmp, -8);
40439e20ca94SRichard Henderson tcg_gen_deposit_tl(cpu_gsr, cpu_gsr, tmp, 0, 3);
40449e20ca94SRichard Henderson #else
40459e20ca94SRichard Henderson g_assert_not_reached();
40469e20ca94SRichard Henderson #endif
40479e20ca94SRichard Henderson }
40489e20ca94SRichard Henderson
gen_op_alignaddrl(TCGv dst,TCGv s1,TCGv s2)40499e20ca94SRichard Henderson static void gen_op_alignaddrl(TCGv dst, TCGv s1, TCGv s2)
40509e20ca94SRichard Henderson {
40519e20ca94SRichard Henderson #ifdef TARGET_SPARC64
40529e20ca94SRichard Henderson TCGv tmp = tcg_temp_new();
40539e20ca94SRichard Henderson
40549e20ca94SRichard Henderson tcg_gen_add_tl(tmp, s1, s2);
40559e20ca94SRichard Henderson tcg_gen_andi_tl(dst, tmp, -8);
40569e20ca94SRichard Henderson tcg_gen_neg_tl(tmp, tmp);
40579e20ca94SRichard Henderson tcg_gen_deposit_tl(cpu_gsr, cpu_gsr, tmp, 0, 3);
40589e20ca94SRichard Henderson #else
40599e20ca94SRichard Henderson g_assert_not_reached();
40609e20ca94SRichard Henderson #endif
40619e20ca94SRichard Henderson }
40629e20ca94SRichard Henderson
TRANS(ALIGNADDR,VIS1,do_rrr,a,gen_op_alignaddr)40639e20ca94SRichard Henderson TRANS(ALIGNADDR, VIS1, do_rrr, a, gen_op_alignaddr)
40649e20ca94SRichard Henderson TRANS(ALIGNADDRL, VIS1, do_rrr, a, gen_op_alignaddrl)
40659e20ca94SRichard Henderson
406639ca3490SRichard Henderson static void gen_op_bmask(TCGv dst, TCGv s1, TCGv s2)
406739ca3490SRichard Henderson {
406839ca3490SRichard Henderson #ifdef TARGET_SPARC64
406939ca3490SRichard Henderson tcg_gen_add_tl(dst, s1, s2);
407039ca3490SRichard Henderson tcg_gen_deposit_tl(cpu_gsr, cpu_gsr, dst, 32, 32);
407139ca3490SRichard Henderson #else
407239ca3490SRichard Henderson g_assert_not_reached();
407339ca3490SRichard Henderson #endif
407439ca3490SRichard Henderson }
407539ca3490SRichard Henderson
TRANS(BMASK,VIS2,do_rrr,a,gen_op_bmask)407639ca3490SRichard Henderson TRANS(BMASK, VIS2, do_rrr, a, gen_op_bmask)
407739ca3490SRichard Henderson
4078c973b4e8SRichard Henderson static bool do_cmask(DisasContext *dc, int rs2, void (*func)(TCGv, TCGv, TCGv))
4079c973b4e8SRichard Henderson {
4080c973b4e8SRichard Henderson func(cpu_gsr, cpu_gsr, gen_load_gpr(dc, rs2));
4081c973b4e8SRichard Henderson return true;
4082c973b4e8SRichard Henderson }
4083c973b4e8SRichard Henderson
4084c973b4e8SRichard Henderson TRANS(CMASK8, VIS3, do_cmask, a->rs2, gen_helper_cmask8)
4085c973b4e8SRichard Henderson TRANS(CMASK16, VIS3, do_cmask, a->rs2, gen_helper_cmask16)
4086c973b4e8SRichard Henderson TRANS(CMASK32, VIS3, do_cmask, a->rs2, gen_helper_cmask32)
4087c973b4e8SRichard Henderson
do_shift_r(DisasContext * dc,arg_shiftr * a,bool l,bool u)40885fc546eeSRichard Henderson static bool do_shift_r(DisasContext *dc, arg_shiftr *a, bool l, bool u)
40895fc546eeSRichard Henderson {
40905fc546eeSRichard Henderson TCGv dst, src1, src2;
40915fc546eeSRichard Henderson
40925fc546eeSRichard Henderson /* Reject 64-bit shifts for sparc32. */
40935fc546eeSRichard Henderson if (avail_32(dc) && a->x) {
40945fc546eeSRichard Henderson return false;
40955fc546eeSRichard Henderson }
40965fc546eeSRichard Henderson
40975fc546eeSRichard Henderson src2 = tcg_temp_new();
40985fc546eeSRichard Henderson tcg_gen_andi_tl(src2, gen_load_gpr(dc, a->rs2), a->x ? 63 : 31);
40995fc546eeSRichard Henderson src1 = gen_load_gpr(dc, a->rs1);
41005fc546eeSRichard Henderson dst = gen_dest_gpr(dc, a->rd);
41015fc546eeSRichard Henderson
41025fc546eeSRichard Henderson if (l) {
41035fc546eeSRichard Henderson tcg_gen_shl_tl(dst, src1, src2);
41045fc546eeSRichard Henderson if (!a->x) {
41055fc546eeSRichard Henderson tcg_gen_ext32u_tl(dst, dst);
41065fc546eeSRichard Henderson }
41075fc546eeSRichard Henderson } else if (u) {
41085fc546eeSRichard Henderson if (!a->x) {
41095fc546eeSRichard Henderson tcg_gen_ext32u_tl(dst, src1);
41105fc546eeSRichard Henderson src1 = dst;
41115fc546eeSRichard Henderson }
41125fc546eeSRichard Henderson tcg_gen_shr_tl(dst, src1, src2);
41135fc546eeSRichard Henderson } else {
41145fc546eeSRichard Henderson if (!a->x) {
41155fc546eeSRichard Henderson tcg_gen_ext32s_tl(dst, src1);
41165fc546eeSRichard Henderson src1 = dst;
41175fc546eeSRichard Henderson }
41185fc546eeSRichard Henderson tcg_gen_sar_tl(dst, src1, src2);
41195fc546eeSRichard Henderson }
41205fc546eeSRichard Henderson gen_store_gpr(dc, a->rd, dst);
41215fc546eeSRichard Henderson return advance_pc(dc);
41225fc546eeSRichard Henderson }
41235fc546eeSRichard Henderson
TRANS(SLL_r,ALL,do_shift_r,a,true,true)41245fc546eeSRichard Henderson TRANS(SLL_r, ALL, do_shift_r, a, true, true)
41255fc546eeSRichard Henderson TRANS(SRL_r, ALL, do_shift_r, a, false, true)
41265fc546eeSRichard Henderson TRANS(SRA_r, ALL, do_shift_r, a, false, false)
41275fc546eeSRichard Henderson
41285fc546eeSRichard Henderson static bool do_shift_i(DisasContext *dc, arg_shifti *a, bool l, bool u)
41295fc546eeSRichard Henderson {
41305fc546eeSRichard Henderson TCGv dst, src1;
41315fc546eeSRichard Henderson
41325fc546eeSRichard Henderson /* Reject 64-bit shifts for sparc32. */
41335fc546eeSRichard Henderson if (avail_32(dc) && (a->x || a->i >= 32)) {
41345fc546eeSRichard Henderson return false;
41355fc546eeSRichard Henderson }
41365fc546eeSRichard Henderson
41375fc546eeSRichard Henderson src1 = gen_load_gpr(dc, a->rs1);
41385fc546eeSRichard Henderson dst = gen_dest_gpr(dc, a->rd);
41395fc546eeSRichard Henderson
41405fc546eeSRichard Henderson if (avail_32(dc) || a->x) {
41415fc546eeSRichard Henderson if (l) {
41425fc546eeSRichard Henderson tcg_gen_shli_tl(dst, src1, a->i);
41435fc546eeSRichard Henderson } else if (u) {
41445fc546eeSRichard Henderson tcg_gen_shri_tl(dst, src1, a->i);
41455fc546eeSRichard Henderson } else {
41465fc546eeSRichard Henderson tcg_gen_sari_tl(dst, src1, a->i);
41475fc546eeSRichard Henderson }
41485fc546eeSRichard Henderson } else {
41495fc546eeSRichard Henderson if (l) {
41505fc546eeSRichard Henderson tcg_gen_deposit_z_tl(dst, src1, a->i, 32 - a->i);
41515fc546eeSRichard Henderson } else if (u) {
41525fc546eeSRichard Henderson tcg_gen_extract_tl(dst, src1, a->i, 32 - a->i);
41535fc546eeSRichard Henderson } else {
41545fc546eeSRichard Henderson tcg_gen_sextract_tl(dst, src1, a->i, 32 - a->i);
41555fc546eeSRichard Henderson }
41565fc546eeSRichard Henderson }
41575fc546eeSRichard Henderson gen_store_gpr(dc, a->rd, dst);
41585fc546eeSRichard Henderson return advance_pc(dc);
41595fc546eeSRichard Henderson }
41605fc546eeSRichard Henderson
TRANS(SLL_i,ALL,do_shift_i,a,true,true)41615fc546eeSRichard Henderson TRANS(SLL_i, ALL, do_shift_i, a, true, true)
41625fc546eeSRichard Henderson TRANS(SRL_i, ALL, do_shift_i, a, false, true)
41635fc546eeSRichard Henderson TRANS(SRA_i, ALL, do_shift_i, a, false, false)
41645fc546eeSRichard Henderson
4165fb4ed7aaSRichard Henderson static TCGv gen_rs2_or_imm(DisasContext *dc, bool imm, int rs2_or_imm)
4166fb4ed7aaSRichard Henderson {
4167fb4ed7aaSRichard Henderson /* For simplicity, we under-decoded the rs2 form. */
4168fb4ed7aaSRichard Henderson if (!imm && rs2_or_imm & ~0x1f) {
4169fb4ed7aaSRichard Henderson return NULL;
4170fb4ed7aaSRichard Henderson }
4171fb4ed7aaSRichard Henderson if (imm || rs2_or_imm == 0) {
4172fb4ed7aaSRichard Henderson return tcg_constant_tl(rs2_or_imm);
4173fb4ed7aaSRichard Henderson } else {
4174fb4ed7aaSRichard Henderson return cpu_regs[rs2_or_imm];
4175fb4ed7aaSRichard Henderson }
4176fb4ed7aaSRichard Henderson }
4177fb4ed7aaSRichard Henderson
do_mov_cond(DisasContext * dc,DisasCompare * cmp,int rd,TCGv src2)4178fb4ed7aaSRichard Henderson static bool do_mov_cond(DisasContext *dc, DisasCompare *cmp, int rd, TCGv src2)
4179fb4ed7aaSRichard Henderson {
4180fb4ed7aaSRichard Henderson TCGv dst = gen_load_gpr(dc, rd);
4181c8507ebfSRichard Henderson TCGv c2 = tcg_constant_tl(cmp->c2);
4182fb4ed7aaSRichard Henderson
4183c8507ebfSRichard Henderson tcg_gen_movcond_tl(cmp->cond, dst, cmp->c1, c2, src2, dst);
4184fb4ed7aaSRichard Henderson gen_store_gpr(dc, rd, dst);
4185fb4ed7aaSRichard Henderson return advance_pc(dc);
4186fb4ed7aaSRichard Henderson }
4187fb4ed7aaSRichard Henderson
trans_MOVcc(DisasContext * dc,arg_MOVcc * a)4188fb4ed7aaSRichard Henderson static bool trans_MOVcc(DisasContext *dc, arg_MOVcc *a)
4189fb4ed7aaSRichard Henderson {
4190fb4ed7aaSRichard Henderson TCGv src2 = gen_rs2_or_imm(dc, a->imm, a->rs2_or_imm);
4191fb4ed7aaSRichard Henderson DisasCompare cmp;
4192fb4ed7aaSRichard Henderson
4193fb4ed7aaSRichard Henderson if (src2 == NULL) {
4194fb4ed7aaSRichard Henderson return false;
4195fb4ed7aaSRichard Henderson }
4196fb4ed7aaSRichard Henderson gen_compare(&cmp, a->cc, a->cond, dc);
4197fb4ed7aaSRichard Henderson return do_mov_cond(dc, &cmp, a->rd, src2);
4198fb4ed7aaSRichard Henderson }
4199fb4ed7aaSRichard Henderson
trans_MOVfcc(DisasContext * dc,arg_MOVfcc * a)4200fb4ed7aaSRichard Henderson static bool trans_MOVfcc(DisasContext *dc, arg_MOVfcc *a)
4201fb4ed7aaSRichard Henderson {
4202fb4ed7aaSRichard Henderson TCGv src2 = gen_rs2_or_imm(dc, a->imm, a->rs2_or_imm);
4203fb4ed7aaSRichard Henderson DisasCompare cmp;
4204fb4ed7aaSRichard Henderson
4205fb4ed7aaSRichard Henderson if (src2 == NULL) {
4206fb4ed7aaSRichard Henderson return false;
4207fb4ed7aaSRichard Henderson }
4208fb4ed7aaSRichard Henderson gen_fcompare(&cmp, a->cc, a->cond);
4209fb4ed7aaSRichard Henderson return do_mov_cond(dc, &cmp, a->rd, src2);
4210fb4ed7aaSRichard Henderson }
4211fb4ed7aaSRichard Henderson
trans_MOVR(DisasContext * dc,arg_MOVR * a)4212fb4ed7aaSRichard Henderson static bool trans_MOVR(DisasContext *dc, arg_MOVR *a)
4213fb4ed7aaSRichard Henderson {
4214fb4ed7aaSRichard Henderson TCGv src2 = gen_rs2_or_imm(dc, a->imm, a->rs2_or_imm);
4215fb4ed7aaSRichard Henderson DisasCompare cmp;
4216fb4ed7aaSRichard Henderson
4217fb4ed7aaSRichard Henderson if (src2 == NULL) {
4218fb4ed7aaSRichard Henderson return false;
4219fb4ed7aaSRichard Henderson }
42202c4f56c9SRichard Henderson if (!gen_compare_reg(&cmp, a->cond, gen_load_gpr(dc, a->rs1))) {
42212c4f56c9SRichard Henderson return false;
42222c4f56c9SRichard Henderson }
4223fb4ed7aaSRichard Henderson return do_mov_cond(dc, &cmp, a->rd, src2);
4224fb4ed7aaSRichard Henderson }
4225fb4ed7aaSRichard Henderson
do_add_special(DisasContext * dc,arg_r_r_ri * a,bool (* func)(DisasContext * dc,int rd,TCGv src))422686b82fe0SRichard Henderson static bool do_add_special(DisasContext *dc, arg_r_r_ri *a,
422786b82fe0SRichard Henderson bool (*func)(DisasContext *dc, int rd, TCGv src))
422886b82fe0SRichard Henderson {
422986b82fe0SRichard Henderson TCGv src1, sum;
423086b82fe0SRichard Henderson
423186b82fe0SRichard Henderson /* For simplicity, we under-decoded the rs2 form. */
423286b82fe0SRichard Henderson if (!a->imm && a->rs2_or_imm & ~0x1f) {
423386b82fe0SRichard Henderson return false;
423486b82fe0SRichard Henderson }
423586b82fe0SRichard Henderson
423686b82fe0SRichard Henderson /*
423786b82fe0SRichard Henderson * Always load the sum into a new temporary.
423886b82fe0SRichard Henderson * This is required to capture the value across a window change,
423986b82fe0SRichard Henderson * e.g. SAVE and RESTORE, and may be optimized away otherwise.
424086b82fe0SRichard Henderson */
424186b82fe0SRichard Henderson sum = tcg_temp_new();
424286b82fe0SRichard Henderson src1 = gen_load_gpr(dc, a->rs1);
424386b82fe0SRichard Henderson if (a->imm || a->rs2_or_imm == 0) {
424486b82fe0SRichard Henderson tcg_gen_addi_tl(sum, src1, a->rs2_or_imm);
424586b82fe0SRichard Henderson } else {
424686b82fe0SRichard Henderson tcg_gen_add_tl(sum, src1, cpu_regs[a->rs2_or_imm]);
424786b82fe0SRichard Henderson }
424886b82fe0SRichard Henderson return func(dc, a->rd, sum);
424986b82fe0SRichard Henderson }
425086b82fe0SRichard Henderson
do_jmpl(DisasContext * dc,int rd,TCGv src)425186b82fe0SRichard Henderson static bool do_jmpl(DisasContext *dc, int rd, TCGv src)
425286b82fe0SRichard Henderson {
425386b82fe0SRichard Henderson /*
425486b82fe0SRichard Henderson * Preserve pc across advance, so that we can delay
425586b82fe0SRichard Henderson * the writeback to rd until after src is consumed.
425686b82fe0SRichard Henderson */
425786b82fe0SRichard Henderson target_ulong cur_pc = dc->pc;
425886b82fe0SRichard Henderson
425986b82fe0SRichard Henderson gen_check_align(dc, src, 3);
426086b82fe0SRichard Henderson
426186b82fe0SRichard Henderson gen_mov_pc_npc(dc);
426286b82fe0SRichard Henderson tcg_gen_mov_tl(cpu_npc, src);
426386b82fe0SRichard Henderson gen_address_mask(dc, cpu_npc);
426486b82fe0SRichard Henderson gen_store_gpr(dc, rd, tcg_constant_tl(cur_pc));
426586b82fe0SRichard Henderson
426686b82fe0SRichard Henderson dc->npc = DYNAMIC_PC_LOOKUP;
426786b82fe0SRichard Henderson return true;
426886b82fe0SRichard Henderson }
426986b82fe0SRichard Henderson
TRANS(JMPL,ALL,do_add_special,a,do_jmpl)427086b82fe0SRichard Henderson TRANS(JMPL, ALL, do_add_special, a, do_jmpl)
427186b82fe0SRichard Henderson
427286b82fe0SRichard Henderson static bool do_rett(DisasContext *dc, int rd, TCGv src)
427386b82fe0SRichard Henderson {
427486b82fe0SRichard Henderson if (!supervisor(dc)) {
427586b82fe0SRichard Henderson return raise_priv(dc);
427686b82fe0SRichard Henderson }
427786b82fe0SRichard Henderson
427886b82fe0SRichard Henderson gen_check_align(dc, src, 3);
427986b82fe0SRichard Henderson
428086b82fe0SRichard Henderson gen_mov_pc_npc(dc);
428186b82fe0SRichard Henderson tcg_gen_mov_tl(cpu_npc, src);
428286b82fe0SRichard Henderson gen_helper_rett(tcg_env);
428386b82fe0SRichard Henderson
428486b82fe0SRichard Henderson dc->npc = DYNAMIC_PC;
428586b82fe0SRichard Henderson return true;
428686b82fe0SRichard Henderson }
428786b82fe0SRichard Henderson
428886b82fe0SRichard Henderson TRANS(RETT, 32, do_add_special, a, do_rett)
428986b82fe0SRichard Henderson
do_return(DisasContext * dc,int rd,TCGv src)429086b82fe0SRichard Henderson static bool do_return(DisasContext *dc, int rd, TCGv src)
429186b82fe0SRichard Henderson {
429286b82fe0SRichard Henderson gen_check_align(dc, src, 3);
42930dfae4f9SRichard Henderson gen_helper_restore(tcg_env);
429486b82fe0SRichard Henderson
429586b82fe0SRichard Henderson gen_mov_pc_npc(dc);
429686b82fe0SRichard Henderson tcg_gen_mov_tl(cpu_npc, src);
429786b82fe0SRichard Henderson gen_address_mask(dc, cpu_npc);
429886b82fe0SRichard Henderson
429986b82fe0SRichard Henderson dc->npc = DYNAMIC_PC_LOOKUP;
430086b82fe0SRichard Henderson return true;
430186b82fe0SRichard Henderson }
430286b82fe0SRichard Henderson
430386b82fe0SRichard Henderson TRANS(RETURN, 64, do_add_special, a, do_return)
430486b82fe0SRichard Henderson
do_save(DisasContext * dc,int rd,TCGv src)4305d3825800SRichard Henderson static bool do_save(DisasContext *dc, int rd, TCGv src)
4306d3825800SRichard Henderson {
4307d3825800SRichard Henderson gen_helper_save(tcg_env);
4308d3825800SRichard Henderson gen_store_gpr(dc, rd, src);
4309d3825800SRichard Henderson return advance_pc(dc);
4310d3825800SRichard Henderson }
4311d3825800SRichard Henderson
TRANS(SAVE,ALL,do_add_special,a,do_save)4312d3825800SRichard Henderson TRANS(SAVE, ALL, do_add_special, a, do_save)
4313d3825800SRichard Henderson
4314d3825800SRichard Henderson static bool do_restore(DisasContext *dc, int rd, TCGv src)
4315d3825800SRichard Henderson {
4316d3825800SRichard Henderson gen_helper_restore(tcg_env);
4317d3825800SRichard Henderson gen_store_gpr(dc, rd, src);
4318d3825800SRichard Henderson return advance_pc(dc);
4319d3825800SRichard Henderson }
4320d3825800SRichard Henderson
TRANS(RESTORE,ALL,do_add_special,a,do_restore)4321d3825800SRichard Henderson TRANS(RESTORE, ALL, do_add_special, a, do_restore)
4322d3825800SRichard Henderson
43238f75b8a4SRichard Henderson static bool do_done_retry(DisasContext *dc, bool done)
43248f75b8a4SRichard Henderson {
43258f75b8a4SRichard Henderson if (!supervisor(dc)) {
43268f75b8a4SRichard Henderson return raise_priv(dc);
43278f75b8a4SRichard Henderson }
43288f75b8a4SRichard Henderson dc->npc = DYNAMIC_PC;
43298f75b8a4SRichard Henderson dc->pc = DYNAMIC_PC;
43308f75b8a4SRichard Henderson translator_io_start(&dc->base);
43318f75b8a4SRichard Henderson if (done) {
43328f75b8a4SRichard Henderson gen_helper_done(tcg_env);
43338f75b8a4SRichard Henderson } else {
43348f75b8a4SRichard Henderson gen_helper_retry(tcg_env);
43358f75b8a4SRichard Henderson }
43368f75b8a4SRichard Henderson return true;
43378f75b8a4SRichard Henderson }
43388f75b8a4SRichard Henderson
43398f75b8a4SRichard Henderson TRANS(DONE, 64, do_done_retry, true)
43408f75b8a4SRichard Henderson TRANS(RETRY, 64, do_done_retry, false)
43418f75b8a4SRichard Henderson
43420880d20bSRichard Henderson /*
43430880d20bSRichard Henderson * Major opcode 11 -- load and store instructions
43440880d20bSRichard Henderson */
43450880d20bSRichard Henderson
gen_ldst_addr(DisasContext * dc,int rs1,bool imm,int rs2_or_imm)43460880d20bSRichard Henderson static TCGv gen_ldst_addr(DisasContext *dc, int rs1, bool imm, int rs2_or_imm)
43470880d20bSRichard Henderson {
43480880d20bSRichard Henderson TCGv addr, tmp = NULL;
43490880d20bSRichard Henderson
43500880d20bSRichard Henderson /* For simplicity, we under-decoded the rs2 form. */
43510880d20bSRichard Henderson if (!imm && rs2_or_imm & ~0x1f) {
43520880d20bSRichard Henderson return NULL;
43530880d20bSRichard Henderson }
43540880d20bSRichard Henderson
43550880d20bSRichard Henderson addr = gen_load_gpr(dc, rs1);
43560880d20bSRichard Henderson if (rs2_or_imm) {
43570880d20bSRichard Henderson tmp = tcg_temp_new();
43580880d20bSRichard Henderson if (imm) {
43590880d20bSRichard Henderson tcg_gen_addi_tl(tmp, addr, rs2_or_imm);
43600880d20bSRichard Henderson } else {
43610880d20bSRichard Henderson tcg_gen_add_tl(tmp, addr, cpu_regs[rs2_or_imm]);
43620880d20bSRichard Henderson }
43630880d20bSRichard Henderson addr = tmp;
43640880d20bSRichard Henderson }
43650880d20bSRichard Henderson if (AM_CHECK(dc)) {
43660880d20bSRichard Henderson if (!tmp) {
43670880d20bSRichard Henderson tmp = tcg_temp_new();
43680880d20bSRichard Henderson }
43690880d20bSRichard Henderson tcg_gen_ext32u_tl(tmp, addr);
43700880d20bSRichard Henderson addr = tmp;
43710880d20bSRichard Henderson }
43720880d20bSRichard Henderson return addr;
43730880d20bSRichard Henderson }
43740880d20bSRichard Henderson
do_ld_gpr(DisasContext * dc,arg_r_r_ri_asi * a,MemOp mop)43750880d20bSRichard Henderson static bool do_ld_gpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp mop)
43760880d20bSRichard Henderson {
43770880d20bSRichard Henderson TCGv reg, addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
43780880d20bSRichard Henderson DisasASI da;
43790880d20bSRichard Henderson
43800880d20bSRichard Henderson if (addr == NULL) {
43810880d20bSRichard Henderson return false;
43820880d20bSRichard Henderson }
43830880d20bSRichard Henderson da = resolve_asi(dc, a->asi, mop);
43840880d20bSRichard Henderson
43850880d20bSRichard Henderson reg = gen_dest_gpr(dc, a->rd);
438642071fc1SRichard Henderson gen_ld_asi(dc, &da, reg, addr);
43870880d20bSRichard Henderson gen_store_gpr(dc, a->rd, reg);
43880880d20bSRichard Henderson return advance_pc(dc);
43890880d20bSRichard Henderson }
43900880d20bSRichard Henderson
TRANS(LDUW,ALL,do_ld_gpr,a,MO_TEUL)43910880d20bSRichard Henderson TRANS(LDUW, ALL, do_ld_gpr, a, MO_TEUL)
43920880d20bSRichard Henderson TRANS(LDUB, ALL, do_ld_gpr, a, MO_UB)
43930880d20bSRichard Henderson TRANS(LDUH, ALL, do_ld_gpr, a, MO_TEUW)
43940880d20bSRichard Henderson TRANS(LDSB, ALL, do_ld_gpr, a, MO_SB)
43950880d20bSRichard Henderson TRANS(LDSH, ALL, do_ld_gpr, a, MO_TESW)
43960880d20bSRichard Henderson TRANS(LDSW, 64, do_ld_gpr, a, MO_TESL)
43970880d20bSRichard Henderson TRANS(LDX, 64, do_ld_gpr, a, MO_TEUQ)
43980880d20bSRichard Henderson
43990880d20bSRichard Henderson static bool do_st_gpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp mop)
44000880d20bSRichard Henderson {
44010880d20bSRichard Henderson TCGv reg, addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
44020880d20bSRichard Henderson DisasASI da;
44030880d20bSRichard Henderson
44040880d20bSRichard Henderson if (addr == NULL) {
44050880d20bSRichard Henderson return false;
44060880d20bSRichard Henderson }
44070880d20bSRichard Henderson da = resolve_asi(dc, a->asi, mop);
44080880d20bSRichard Henderson
44090880d20bSRichard Henderson reg = gen_load_gpr(dc, a->rd);
441042071fc1SRichard Henderson gen_st_asi(dc, &da, reg, addr);
44110880d20bSRichard Henderson return advance_pc(dc);
44120880d20bSRichard Henderson }
44130880d20bSRichard Henderson
TRANS(STW,ALL,do_st_gpr,a,MO_TEUL)44140880d20bSRichard Henderson TRANS(STW, ALL, do_st_gpr, a, MO_TEUL)
44150880d20bSRichard Henderson TRANS(STB, ALL, do_st_gpr, a, MO_UB)
44160880d20bSRichard Henderson TRANS(STH, ALL, do_st_gpr, a, MO_TEUW)
44170880d20bSRichard Henderson TRANS(STX, 64, do_st_gpr, a, MO_TEUQ)
44180880d20bSRichard Henderson
44190880d20bSRichard Henderson static bool trans_LDD(DisasContext *dc, arg_r_r_ri_asi *a)
44200880d20bSRichard Henderson {
44210880d20bSRichard Henderson TCGv addr;
44220880d20bSRichard Henderson DisasASI da;
44230880d20bSRichard Henderson
44240880d20bSRichard Henderson if (a->rd & 1) {
44250880d20bSRichard Henderson return false;
44260880d20bSRichard Henderson }
44270880d20bSRichard Henderson addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
44280880d20bSRichard Henderson if (addr == NULL) {
44290880d20bSRichard Henderson return false;
44300880d20bSRichard Henderson }
44310880d20bSRichard Henderson da = resolve_asi(dc, a->asi, MO_TEUQ);
443242071fc1SRichard Henderson gen_ldda_asi(dc, &da, addr, a->rd);
44330880d20bSRichard Henderson return advance_pc(dc);
44340880d20bSRichard Henderson }
44350880d20bSRichard Henderson
trans_STD(DisasContext * dc,arg_r_r_ri_asi * a)44360880d20bSRichard Henderson static bool trans_STD(DisasContext *dc, arg_r_r_ri_asi *a)
44370880d20bSRichard Henderson {
44380880d20bSRichard Henderson TCGv addr;
44390880d20bSRichard Henderson DisasASI da;
44400880d20bSRichard Henderson
44410880d20bSRichard Henderson if (a->rd & 1) {
44420880d20bSRichard Henderson return false;
44430880d20bSRichard Henderson }
44440880d20bSRichard Henderson addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
44450880d20bSRichard Henderson if (addr == NULL) {
44460880d20bSRichard Henderson return false;
44470880d20bSRichard Henderson }
44480880d20bSRichard Henderson da = resolve_asi(dc, a->asi, MO_TEUQ);
444942071fc1SRichard Henderson gen_stda_asi(dc, &da, addr, a->rd);
44500880d20bSRichard Henderson return advance_pc(dc);
44510880d20bSRichard Henderson }
44520880d20bSRichard Henderson
trans_LDSTUB(DisasContext * dc,arg_r_r_ri_asi * a)4453cf07cd1eSRichard Henderson static bool trans_LDSTUB(DisasContext *dc, arg_r_r_ri_asi *a)
4454cf07cd1eSRichard Henderson {
4455cf07cd1eSRichard Henderson TCGv addr, reg;
4456cf07cd1eSRichard Henderson DisasASI da;
4457cf07cd1eSRichard Henderson
4458cf07cd1eSRichard Henderson addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
4459cf07cd1eSRichard Henderson if (addr == NULL) {
4460cf07cd1eSRichard Henderson return false;
4461cf07cd1eSRichard Henderson }
4462cf07cd1eSRichard Henderson da = resolve_asi(dc, a->asi, MO_UB);
4463cf07cd1eSRichard Henderson
4464cf07cd1eSRichard Henderson reg = gen_dest_gpr(dc, a->rd);
4465cf07cd1eSRichard Henderson gen_ldstub_asi(dc, &da, reg, addr);
4466cf07cd1eSRichard Henderson gen_store_gpr(dc, a->rd, reg);
4467cf07cd1eSRichard Henderson return advance_pc(dc);
4468cf07cd1eSRichard Henderson }
4469cf07cd1eSRichard Henderson
trans_SWAP(DisasContext * dc,arg_r_r_ri_asi * a)4470dca544b9SRichard Henderson static bool trans_SWAP(DisasContext *dc, arg_r_r_ri_asi *a)
4471dca544b9SRichard Henderson {
4472dca544b9SRichard Henderson TCGv addr, dst, src;
4473dca544b9SRichard Henderson DisasASI da;
4474dca544b9SRichard Henderson
4475dca544b9SRichard Henderson addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
4476dca544b9SRichard Henderson if (addr == NULL) {
4477dca544b9SRichard Henderson return false;
4478dca544b9SRichard Henderson }
4479dca544b9SRichard Henderson da = resolve_asi(dc, a->asi, MO_TEUL);
4480dca544b9SRichard Henderson
4481dca544b9SRichard Henderson dst = gen_dest_gpr(dc, a->rd);
4482dca544b9SRichard Henderson src = gen_load_gpr(dc, a->rd);
4483dca544b9SRichard Henderson gen_swap_asi(dc, &da, dst, src, addr);
4484dca544b9SRichard Henderson gen_store_gpr(dc, a->rd, dst);
4485dca544b9SRichard Henderson return advance_pc(dc);
4486dca544b9SRichard Henderson }
4487dca544b9SRichard Henderson
do_casa(DisasContext * dc,arg_r_r_ri_asi * a,MemOp mop)4488d0a11d25SRichard Henderson static bool do_casa(DisasContext *dc, arg_r_r_ri_asi *a, MemOp mop)
4489d0a11d25SRichard Henderson {
4490d0a11d25SRichard Henderson TCGv addr, o, n, c;
4491d0a11d25SRichard Henderson DisasASI da;
4492d0a11d25SRichard Henderson
4493d0a11d25SRichard Henderson addr = gen_ldst_addr(dc, a->rs1, true, 0);
4494d0a11d25SRichard Henderson if (addr == NULL) {
4495d0a11d25SRichard Henderson return false;
4496d0a11d25SRichard Henderson }
4497d0a11d25SRichard Henderson da = resolve_asi(dc, a->asi, mop);
4498d0a11d25SRichard Henderson
4499d0a11d25SRichard Henderson o = gen_dest_gpr(dc, a->rd);
4500d0a11d25SRichard Henderson n = gen_load_gpr(dc, a->rd);
4501d0a11d25SRichard Henderson c = gen_load_gpr(dc, a->rs2_or_imm);
4502d0a11d25SRichard Henderson gen_cas_asi(dc, &da, o, n, c, addr);
4503d0a11d25SRichard Henderson gen_store_gpr(dc, a->rd, o);
4504d0a11d25SRichard Henderson return advance_pc(dc);
4505d0a11d25SRichard Henderson }
4506d0a11d25SRichard Henderson
TRANS(CASA,CASA,do_casa,a,MO_TEUL)4507d0a11d25SRichard Henderson TRANS(CASA, CASA, do_casa, a, MO_TEUL)
4508d0a11d25SRichard Henderson TRANS(CASXA, 64, do_casa, a, MO_TEUQ)
4509d0a11d25SRichard Henderson
451006c060d9SRichard Henderson static bool do_ld_fpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp sz)
451106c060d9SRichard Henderson {
451206c060d9SRichard Henderson TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
451306c060d9SRichard Henderson DisasASI da;
451406c060d9SRichard Henderson
451506c060d9SRichard Henderson if (addr == NULL) {
451606c060d9SRichard Henderson return false;
451706c060d9SRichard Henderson }
4518*d2a0c3a7SRichard Henderson if (gen_trap_if_nofpu_fpexception(dc)) {
451906c060d9SRichard Henderson return true;
452006c060d9SRichard Henderson }
452106c060d9SRichard Henderson if (sz == MO_128 && gen_trap_float128(dc)) {
452206c060d9SRichard Henderson return true;
452306c060d9SRichard Henderson }
452406c060d9SRichard Henderson da = resolve_asi(dc, a->asi, MO_TE | sz);
4525287b1152SRichard Henderson gen_ldf_asi(dc, &da, sz, addr, a->rd);
452606c060d9SRichard Henderson gen_update_fprs_dirty(dc, a->rd);
452706c060d9SRichard Henderson return advance_pc(dc);
452806c060d9SRichard Henderson }
452906c060d9SRichard Henderson
TRANS(LDF,ALL,do_ld_fpr,a,MO_32)453006c060d9SRichard Henderson TRANS(LDF, ALL, do_ld_fpr, a, MO_32)
453106c060d9SRichard Henderson TRANS(LDDF, ALL, do_ld_fpr, a, MO_64)
453206c060d9SRichard Henderson TRANS(LDQF, ALL, do_ld_fpr, a, MO_128)
453306c060d9SRichard Henderson
4534287b1152SRichard Henderson TRANS(LDFA, 64, do_ld_fpr, a, MO_32)
4535287b1152SRichard Henderson TRANS(LDDFA, 64, do_ld_fpr, a, MO_64)
4536287b1152SRichard Henderson TRANS(LDQFA, 64, do_ld_fpr, a, MO_128)
4537287b1152SRichard Henderson
453806c060d9SRichard Henderson static bool do_st_fpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp sz)
453906c060d9SRichard Henderson {
454006c060d9SRichard Henderson TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
454106c060d9SRichard Henderson DisasASI da;
454206c060d9SRichard Henderson
454306c060d9SRichard Henderson if (addr == NULL) {
454406c060d9SRichard Henderson return false;
454506c060d9SRichard Henderson }
4546*d2a0c3a7SRichard Henderson /* Store insns are ok in fp_exception_pending state. */
454706c060d9SRichard Henderson if (gen_trap_ifnofpu(dc)) {
454806c060d9SRichard Henderson return true;
454906c060d9SRichard Henderson }
455006c060d9SRichard Henderson if (sz == MO_128 && gen_trap_float128(dc)) {
455106c060d9SRichard Henderson return true;
455206c060d9SRichard Henderson }
455306c060d9SRichard Henderson da = resolve_asi(dc, a->asi, MO_TE | sz);
4554287b1152SRichard Henderson gen_stf_asi(dc, &da, sz, addr, a->rd);
455506c060d9SRichard Henderson return advance_pc(dc);
455606c060d9SRichard Henderson }
455706c060d9SRichard Henderson
TRANS(STF,ALL,do_st_fpr,a,MO_32)455806c060d9SRichard Henderson TRANS(STF, ALL, do_st_fpr, a, MO_32)
455906c060d9SRichard Henderson TRANS(STDF, ALL, do_st_fpr, a, MO_64)
456012d36294SRichard Henderson TRANS(STQF, 64, do_st_fpr, a, MO_128)
456106c060d9SRichard Henderson
4562287b1152SRichard Henderson TRANS(STFA, 64, do_st_fpr, a, MO_32)
4563287b1152SRichard Henderson TRANS(STDFA, 64, do_st_fpr, a, MO_64)
4564287b1152SRichard Henderson TRANS(STQFA, 64, do_st_fpr, a, MO_128)
4565287b1152SRichard Henderson
456606c060d9SRichard Henderson static bool trans_STDFQ(DisasContext *dc, arg_STDFQ *a)
456706c060d9SRichard Henderson {
456829b99802SRichard Henderson TCGv addr;
456929b99802SRichard Henderson
457006c060d9SRichard Henderson if (!avail_32(dc)) {
457106c060d9SRichard Henderson return false;
457206c060d9SRichard Henderson }
457329b99802SRichard Henderson addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
457429b99802SRichard Henderson if (addr == NULL) {
457529b99802SRichard Henderson return false;
457629b99802SRichard Henderson }
457706c060d9SRichard Henderson if (!supervisor(dc)) {
457806c060d9SRichard Henderson return raise_priv(dc);
457906c060d9SRichard Henderson }
458029b99802SRichard Henderson #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY)
458106c060d9SRichard Henderson if (gen_trap_ifnofpu(dc)) {
458206c060d9SRichard Henderson return true;
458306c060d9SRichard Henderson }
458429b99802SRichard Henderson if (!dc->fsr_qne) {
458506c060d9SRichard Henderson gen_op_fpexception_im(dc, FSR_FTT_SEQ_ERROR);
458606c060d9SRichard Henderson return true;
458706c060d9SRichard Henderson }
458806c060d9SRichard Henderson
458929b99802SRichard Henderson /* Store the single element from the queue. */
459029b99802SRichard Henderson TCGv_i64 fq = tcg_temp_new_i64();
459129b99802SRichard Henderson tcg_gen_ld_i64(fq, tcg_env, offsetof(CPUSPARCState, fq.d));
459229b99802SRichard Henderson tcg_gen_qemu_st_i64(fq, addr, dc->mem_idx, MO_TEUQ | MO_ALIGN_4);
459329b99802SRichard Henderson
459429b99802SRichard Henderson /* Mark the queue empty, transitioning to fp_execute state. */
459529b99802SRichard Henderson tcg_gen_st_i32(tcg_constant_i32(0), tcg_env,
459629b99802SRichard Henderson offsetof(CPUSPARCState, fsr_qne));
459729b99802SRichard Henderson dc->fsr_qne = 0;
459829b99802SRichard Henderson
459929b99802SRichard Henderson return advance_pc(dc);
460029b99802SRichard Henderson #else
460129b99802SRichard Henderson qemu_build_not_reached();
460229b99802SRichard Henderson #endif
460329b99802SRichard Henderson }
460429b99802SRichard Henderson
trans_LDFSR(DisasContext * dc,arg_r_r_ri * a)4605d8c5b92fSRichard Henderson static bool trans_LDFSR(DisasContext *dc, arg_r_r_ri *a)
46063d3c0673SRichard Henderson {
46073590f01eSRichard Henderson TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
4608d8c5b92fSRichard Henderson TCGv_i32 tmp;
46093590f01eSRichard Henderson
46103d3c0673SRichard Henderson if (addr == NULL) {
46113d3c0673SRichard Henderson return false;
46123d3c0673SRichard Henderson }
4613*d2a0c3a7SRichard Henderson if (gen_trap_if_nofpu_fpexception(dc)) {
46143d3c0673SRichard Henderson return true;
46153d3c0673SRichard Henderson }
4616d8c5b92fSRichard Henderson
4617d8c5b92fSRichard Henderson tmp = tcg_temp_new_i32();
4618d8c5b92fSRichard Henderson tcg_gen_qemu_ld_i32(tmp, addr, dc->mem_idx, MO_TEUL | MO_ALIGN);
4619d8c5b92fSRichard Henderson
4620d8c5b92fSRichard Henderson tcg_gen_extract_i32(cpu_fcc[0], tmp, FSR_FCC0_SHIFT, 2);
4621d8c5b92fSRichard Henderson /* LDFSR does not change FCC[1-3]. */
4622d8c5b92fSRichard Henderson
4623d8c5b92fSRichard Henderson gen_helper_set_fsr_nofcc_noftt(tcg_env, tmp);
46243d3c0673SRichard Henderson return advance_pc(dc);
46253d3c0673SRichard Henderson }
46263d3c0673SRichard Henderson
do_ldxfsr(DisasContext * dc,arg_r_r_ri * a,bool entire)4627298c52f7SRichard Henderson static bool do_ldxfsr(DisasContext *dc, arg_r_r_ri *a, bool entire)
4628d8c5b92fSRichard Henderson {
4629d8c5b92fSRichard Henderson #ifdef TARGET_SPARC64
4630d8c5b92fSRichard Henderson TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
4631d8c5b92fSRichard Henderson TCGv_i64 t64;
4632d8c5b92fSRichard Henderson TCGv_i32 lo, hi;
4633d8c5b92fSRichard Henderson
4634d8c5b92fSRichard Henderson if (addr == NULL) {
4635d8c5b92fSRichard Henderson return false;
4636d8c5b92fSRichard Henderson }
4637*d2a0c3a7SRichard Henderson if (gen_trap_if_nofpu_fpexception(dc)) {
4638d8c5b92fSRichard Henderson return true;
4639d8c5b92fSRichard Henderson }
4640d8c5b92fSRichard Henderson
4641d8c5b92fSRichard Henderson t64 = tcg_temp_new_i64();
4642d8c5b92fSRichard Henderson tcg_gen_qemu_ld_i64(t64, addr, dc->mem_idx, MO_TEUQ | MO_ALIGN);
4643d8c5b92fSRichard Henderson
4644d8c5b92fSRichard Henderson lo = tcg_temp_new_i32();
4645d8c5b92fSRichard Henderson hi = cpu_fcc[3];
4646d8c5b92fSRichard Henderson tcg_gen_extr_i64_i32(lo, hi, t64);
4647d8c5b92fSRichard Henderson tcg_gen_extract_i32(cpu_fcc[0], lo, FSR_FCC0_SHIFT, 2);
4648d8c5b92fSRichard Henderson tcg_gen_extract_i32(cpu_fcc[1], hi, FSR_FCC1_SHIFT - 32, 2);
4649d8c5b92fSRichard Henderson tcg_gen_extract_i32(cpu_fcc[2], hi, FSR_FCC2_SHIFT - 32, 2);
4650d8c5b92fSRichard Henderson tcg_gen_extract_i32(cpu_fcc[3], hi, FSR_FCC3_SHIFT - 32, 2);
4651d8c5b92fSRichard Henderson
4652298c52f7SRichard Henderson if (entire) {
4653298c52f7SRichard Henderson gen_helper_set_fsr_nofcc(tcg_env, lo);
4654298c52f7SRichard Henderson } else {
4655d8c5b92fSRichard Henderson gen_helper_set_fsr_nofcc_noftt(tcg_env, lo);
4656298c52f7SRichard Henderson }
4657d8c5b92fSRichard Henderson return advance_pc(dc);
4658d8c5b92fSRichard Henderson #else
4659d8c5b92fSRichard Henderson return false;
4660d8c5b92fSRichard Henderson #endif
4661d8c5b92fSRichard Henderson }
46623d3c0673SRichard Henderson
4663298c52f7SRichard Henderson TRANS(LDXFSR, 64, do_ldxfsr, a, false)
TRANS(LDXEFSR,VIS3B,do_ldxfsr,a,true)4664298c52f7SRichard Henderson TRANS(LDXEFSR, VIS3B, do_ldxfsr, a, true)
4665298c52f7SRichard Henderson
46663d3c0673SRichard Henderson static bool do_stfsr(DisasContext *dc, arg_r_r_ri *a, MemOp mop)
46673d3c0673SRichard Henderson {
46683d3c0673SRichard Henderson TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
46691ccd6e13SRichard Henderson TCGv fsr;
46701ccd6e13SRichard Henderson
46713d3c0673SRichard Henderson if (addr == NULL) {
46723d3c0673SRichard Henderson return false;
46733d3c0673SRichard Henderson }
4674*d2a0c3a7SRichard Henderson /* Store insns are ok in fp_exception_pending state. */
46753d3c0673SRichard Henderson if (gen_trap_ifnofpu(dc)) {
46763d3c0673SRichard Henderson return true;
46773d3c0673SRichard Henderson }
46781ccd6e13SRichard Henderson
46791ccd6e13SRichard Henderson fsr = tcg_temp_new();
46801ccd6e13SRichard Henderson gen_helper_get_fsr(fsr, tcg_env);
46811ccd6e13SRichard Henderson tcg_gen_qemu_st_tl(fsr, addr, dc->mem_idx, mop | MO_ALIGN);
46823d3c0673SRichard Henderson return advance_pc(dc);
46833d3c0673SRichard Henderson }
46843d3c0673SRichard Henderson
TRANS(STFSR,ALL,do_stfsr,a,MO_TEUL)46853d3c0673SRichard Henderson TRANS(STFSR, ALL, do_stfsr, a, MO_TEUL)
46863d3c0673SRichard Henderson TRANS(STXFSR, 64, do_stfsr, a, MO_TEUQ)
46873d3c0673SRichard Henderson
46881210a036SRichard Henderson static bool do_fc(DisasContext *dc, int rd, int32_t c)
46893a38260eSRichard Henderson {
46903a38260eSRichard Henderson if (gen_trap_ifnofpu(dc)) {
46913a38260eSRichard Henderson return true;
46923a38260eSRichard Henderson }
46931210a036SRichard Henderson gen_store_fpr_F(dc, rd, tcg_constant_i32(c));
46943a38260eSRichard Henderson return advance_pc(dc);
46953a38260eSRichard Henderson }
46963a38260eSRichard Henderson
46973a38260eSRichard Henderson TRANS(FZEROs, VIS1, do_fc, a->rd, 0)
46981210a036SRichard Henderson TRANS(FONEs, VIS1, do_fc, a->rd, -1)
46993a38260eSRichard Henderson
do_dc(DisasContext * dc,int rd,int64_t c)47003a38260eSRichard Henderson static bool do_dc(DisasContext *dc, int rd, int64_t c)
47013a38260eSRichard Henderson {
47023a38260eSRichard Henderson if (gen_trap_ifnofpu(dc)) {
47033a38260eSRichard Henderson return true;
47043a38260eSRichard Henderson }
47051210a036SRichard Henderson gen_store_fpr_D(dc, rd, tcg_constant_i64(c));
47063a38260eSRichard Henderson return advance_pc(dc);
47073a38260eSRichard Henderson }
47083a38260eSRichard Henderson
47093a38260eSRichard Henderson TRANS(FZEROd, VIS1, do_dc, a->rd, 0)
47103a38260eSRichard Henderson TRANS(FONEd, VIS1, do_dc, a->rd, -1)
47113a38260eSRichard Henderson
do_ff(DisasContext * dc,arg_r_r * a,void (* func)(TCGv_i32,TCGv_i32))4712baf3dbf2SRichard Henderson static bool do_ff(DisasContext *dc, arg_r_r *a,
4713baf3dbf2SRichard Henderson void (*func)(TCGv_i32, TCGv_i32))
4714baf3dbf2SRichard Henderson {
4715baf3dbf2SRichard Henderson TCGv_i32 tmp;
4716baf3dbf2SRichard Henderson
4717*d2a0c3a7SRichard Henderson if (gen_trap_if_nofpu_fpexception(dc)) {
4718baf3dbf2SRichard Henderson return true;
4719baf3dbf2SRichard Henderson }
4720baf3dbf2SRichard Henderson
4721baf3dbf2SRichard Henderson tmp = gen_load_fpr_F(dc, a->rs);
4722baf3dbf2SRichard Henderson func(tmp, tmp);
4723baf3dbf2SRichard Henderson gen_store_fpr_F(dc, a->rd, tmp);
4724baf3dbf2SRichard Henderson return advance_pc(dc);
4725baf3dbf2SRichard Henderson }
4726baf3dbf2SRichard Henderson
TRANS(FMOVs,ALL,do_ff,a,gen_op_fmovs)4727baf3dbf2SRichard Henderson TRANS(FMOVs, ALL, do_ff, a, gen_op_fmovs)
4728baf3dbf2SRichard Henderson TRANS(FNEGs, ALL, do_ff, a, gen_op_fnegs)
4729baf3dbf2SRichard Henderson TRANS(FABSs, ALL, do_ff, a, gen_op_fabss)
4730baf3dbf2SRichard Henderson TRANS(FSRCs, VIS1, do_ff, a, tcg_gen_mov_i32)
4731baf3dbf2SRichard Henderson TRANS(FNOTs, VIS1, do_ff, a, tcg_gen_not_i32)
4732baf3dbf2SRichard Henderson
47332f722641SRichard Henderson static bool do_fd(DisasContext *dc, arg_r_r *a,
47342f722641SRichard Henderson void (*func)(TCGv_i32, TCGv_i64))
47352f722641SRichard Henderson {
47362f722641SRichard Henderson TCGv_i32 dst;
47372f722641SRichard Henderson TCGv_i64 src;
47382f722641SRichard Henderson
47392f722641SRichard Henderson if (gen_trap_ifnofpu(dc)) {
47402f722641SRichard Henderson return true;
47412f722641SRichard Henderson }
47422f722641SRichard Henderson
4743388a6465SRichard Henderson dst = tcg_temp_new_i32();
47442f722641SRichard Henderson src = gen_load_fpr_D(dc, a->rs);
47452f722641SRichard Henderson func(dst, src);
47462f722641SRichard Henderson gen_store_fpr_F(dc, a->rd, dst);
47472f722641SRichard Henderson return advance_pc(dc);
47482f722641SRichard Henderson }
47492f722641SRichard Henderson
TRANS(FPACK16,VIS1,do_fd,a,gen_op_fpack16)47502f722641SRichard Henderson TRANS(FPACK16, VIS1, do_fd, a, gen_op_fpack16)
47512f722641SRichard Henderson TRANS(FPACKFIX, VIS1, do_fd, a, gen_op_fpackfix)
47522f722641SRichard Henderson
4753119cb94fSRichard Henderson static bool do_env_ff(DisasContext *dc, arg_r_r *a,
4754119cb94fSRichard Henderson void (*func)(TCGv_i32, TCGv_env, TCGv_i32))
4755119cb94fSRichard Henderson {
4756119cb94fSRichard Henderson TCGv_i32 tmp;
4757119cb94fSRichard Henderson
4758*d2a0c3a7SRichard Henderson if (gen_trap_if_nofpu_fpexception(dc)) {
4759119cb94fSRichard Henderson return true;
4760119cb94fSRichard Henderson }
4761119cb94fSRichard Henderson
4762119cb94fSRichard Henderson tmp = gen_load_fpr_F(dc, a->rs);
4763119cb94fSRichard Henderson func(tmp, tcg_env, tmp);
4764119cb94fSRichard Henderson gen_store_fpr_F(dc, a->rd, tmp);
4765119cb94fSRichard Henderson return advance_pc(dc);
4766119cb94fSRichard Henderson }
4767119cb94fSRichard Henderson
TRANS(FSQRTs,ALL,do_env_ff,a,gen_helper_fsqrts)4768119cb94fSRichard Henderson TRANS(FSQRTs, ALL, do_env_ff, a, gen_helper_fsqrts)
4769119cb94fSRichard Henderson TRANS(FiTOs, ALL, do_env_ff, a, gen_helper_fitos)
4770119cb94fSRichard Henderson TRANS(FsTOi, ALL, do_env_ff, a, gen_helper_fstoi)
4771119cb94fSRichard Henderson
47728c94bcd8SRichard Henderson static bool do_env_fd(DisasContext *dc, arg_r_r *a,
47738c94bcd8SRichard Henderson void (*func)(TCGv_i32, TCGv_env, TCGv_i64))
47748c94bcd8SRichard Henderson {
47758c94bcd8SRichard Henderson TCGv_i32 dst;
47768c94bcd8SRichard Henderson TCGv_i64 src;
47778c94bcd8SRichard Henderson
4778*d2a0c3a7SRichard Henderson if (gen_trap_if_nofpu_fpexception(dc)) {
47798c94bcd8SRichard Henderson return true;
47808c94bcd8SRichard Henderson }
47818c94bcd8SRichard Henderson
4782388a6465SRichard Henderson dst = tcg_temp_new_i32();
47838c94bcd8SRichard Henderson src = gen_load_fpr_D(dc, a->rs);
47848c94bcd8SRichard Henderson func(dst, tcg_env, src);
47858c94bcd8SRichard Henderson gen_store_fpr_F(dc, a->rd, dst);
47868c94bcd8SRichard Henderson return advance_pc(dc);
47878c94bcd8SRichard Henderson }
47888c94bcd8SRichard Henderson
TRANS(FdTOs,ALL,do_env_fd,a,gen_helper_fdtos)47898c94bcd8SRichard Henderson TRANS(FdTOs, ALL, do_env_fd, a, gen_helper_fdtos)
47908c94bcd8SRichard Henderson TRANS(FdTOi, ALL, do_env_fd, a, gen_helper_fdtoi)
47918c94bcd8SRichard Henderson TRANS(FxTOs, 64, do_env_fd, a, gen_helper_fxtos)
47928c94bcd8SRichard Henderson
4793c6d83e4fSRichard Henderson static bool do_dd(DisasContext *dc, arg_r_r *a,
4794c6d83e4fSRichard Henderson void (*func)(TCGv_i64, TCGv_i64))
4795c6d83e4fSRichard Henderson {
4796c6d83e4fSRichard Henderson TCGv_i64 dst, src;
4797c6d83e4fSRichard Henderson
4798*d2a0c3a7SRichard Henderson if (gen_trap_if_nofpu_fpexception(dc)) {
4799c6d83e4fSRichard Henderson return true;
4800c6d83e4fSRichard Henderson }
4801c6d83e4fSRichard Henderson
480252f46d46SRichard Henderson dst = tcg_temp_new_i64();
4803c6d83e4fSRichard Henderson src = gen_load_fpr_D(dc, a->rs);
4804c6d83e4fSRichard Henderson func(dst, src);
4805c6d83e4fSRichard Henderson gen_store_fpr_D(dc, a->rd, dst);
4806c6d83e4fSRichard Henderson return advance_pc(dc);
4807c6d83e4fSRichard Henderson }
4808c6d83e4fSRichard Henderson
4809c6d83e4fSRichard Henderson TRANS(FMOVd, 64, do_dd, a, gen_op_fmovd)
4810c6d83e4fSRichard Henderson TRANS(FNEGd, 64, do_dd, a, gen_op_fnegd)
4811c6d83e4fSRichard Henderson TRANS(FABSd, 64, do_dd, a, gen_op_fabsd)
TRANS(FSRCd,VIS1,do_dd,a,tcg_gen_mov_i64)4812c6d83e4fSRichard Henderson TRANS(FSRCd, VIS1, do_dd, a, tcg_gen_mov_i64)
4813c6d83e4fSRichard Henderson TRANS(FNOTd, VIS1, do_dd, a, tcg_gen_not_i64)
4814c6d83e4fSRichard Henderson
48158aa418b3SRichard Henderson static bool do_env_dd(DisasContext *dc, arg_r_r *a,
48168aa418b3SRichard Henderson void (*func)(TCGv_i64, TCGv_env, TCGv_i64))
48178aa418b3SRichard Henderson {
48188aa418b3SRichard Henderson TCGv_i64 dst, src;
48198aa418b3SRichard Henderson
4820*d2a0c3a7SRichard Henderson if (gen_trap_if_nofpu_fpexception(dc)) {
48218aa418b3SRichard Henderson return true;
48228aa418b3SRichard Henderson }
48238aa418b3SRichard Henderson
482452f46d46SRichard Henderson dst = tcg_temp_new_i64();
48258aa418b3SRichard Henderson src = gen_load_fpr_D(dc, a->rs);
48268aa418b3SRichard Henderson func(dst, tcg_env, src);
48278aa418b3SRichard Henderson gen_store_fpr_D(dc, a->rd, dst);
48288aa418b3SRichard Henderson return advance_pc(dc);
48298aa418b3SRichard Henderson }
48308aa418b3SRichard Henderson
TRANS(FSQRTd,ALL,do_env_dd,a,gen_helper_fsqrtd)48318aa418b3SRichard Henderson TRANS(FSQRTd, ALL, do_env_dd, a, gen_helper_fsqrtd)
48328aa418b3SRichard Henderson TRANS(FxTOd, 64, do_env_dd, a, gen_helper_fxtod)
48338aa418b3SRichard Henderson TRANS(FdTOx, 64, do_env_dd, a, gen_helper_fdtox)
48348aa418b3SRichard Henderson
48357b616f36SRichard Henderson static bool do_df(DisasContext *dc, arg_r_r *a,
48367b616f36SRichard Henderson void (*func)(TCGv_i64, TCGv_i32))
48377b616f36SRichard Henderson {
48387b616f36SRichard Henderson TCGv_i64 dst;
48397b616f36SRichard Henderson TCGv_i32 src;
48407b616f36SRichard Henderson
48417b616f36SRichard Henderson if (gen_trap_ifnofpu(dc)) {
48427b616f36SRichard Henderson return true;
48437b616f36SRichard Henderson }
48447b616f36SRichard Henderson
48457b616f36SRichard Henderson dst = tcg_temp_new_i64();
48467b616f36SRichard Henderson src = gen_load_fpr_F(dc, a->rs);
48477b616f36SRichard Henderson func(dst, src);
48487b616f36SRichard Henderson gen_store_fpr_D(dc, a->rd, dst);
48497b616f36SRichard Henderson return advance_pc(dc);
48507b616f36SRichard Henderson }
48517b616f36SRichard Henderson
TRANS(FEXPAND,VIS1,do_df,a,gen_helper_fexpand)48527b616f36SRichard Henderson TRANS(FEXPAND, VIS1, do_df, a, gen_helper_fexpand)
48537b616f36SRichard Henderson
4854199d43efSRichard Henderson static bool do_env_df(DisasContext *dc, arg_r_r *a,
4855199d43efSRichard Henderson void (*func)(TCGv_i64, TCGv_env, TCGv_i32))
4856199d43efSRichard Henderson {
4857199d43efSRichard Henderson TCGv_i64 dst;
4858199d43efSRichard Henderson TCGv_i32 src;
4859199d43efSRichard Henderson
4860*d2a0c3a7SRichard Henderson if (gen_trap_if_nofpu_fpexception(dc)) {
4861199d43efSRichard Henderson return true;
4862199d43efSRichard Henderson }
4863199d43efSRichard Henderson
486452f46d46SRichard Henderson dst = tcg_temp_new_i64();
4865199d43efSRichard Henderson src = gen_load_fpr_F(dc, a->rs);
4866199d43efSRichard Henderson func(dst, tcg_env, src);
4867199d43efSRichard Henderson gen_store_fpr_D(dc, a->rd, dst);
4868199d43efSRichard Henderson return advance_pc(dc);
4869199d43efSRichard Henderson }
4870199d43efSRichard Henderson
TRANS(FiTOd,ALL,do_env_df,a,gen_helper_fitod)4871199d43efSRichard Henderson TRANS(FiTOd, ALL, do_env_df, a, gen_helper_fitod)
4872199d43efSRichard Henderson TRANS(FsTOd, ALL, do_env_df, a, gen_helper_fstod)
4873199d43efSRichard Henderson TRANS(FsTOx, 64, do_env_df, a, gen_helper_fstox)
4874199d43efSRichard Henderson
4875daf457d4SRichard Henderson static bool do_qq(DisasContext *dc, arg_r_r *a,
4876daf457d4SRichard Henderson void (*func)(TCGv_i128, TCGv_i128))
4877f4e18df5SRichard Henderson {
487833ec4245SRichard Henderson TCGv_i128 t;
4879f4e18df5SRichard Henderson
4880f4e18df5SRichard Henderson if (gen_trap_ifnofpu(dc)) {
4881f4e18df5SRichard Henderson return true;
4882f4e18df5SRichard Henderson }
4883f4e18df5SRichard Henderson if (gen_trap_float128(dc)) {
4884f4e18df5SRichard Henderson return true;
4885f4e18df5SRichard Henderson }
4886f4e18df5SRichard Henderson
4887f4e18df5SRichard Henderson gen_op_clear_ieee_excp_and_FTT();
488833ec4245SRichard Henderson t = gen_load_fpr_Q(dc, a->rs);
4889daf457d4SRichard Henderson func(t, t);
489033ec4245SRichard Henderson gen_store_fpr_Q(dc, a->rd, t);
4891f4e18df5SRichard Henderson return advance_pc(dc);
4892f4e18df5SRichard Henderson }
4893f4e18df5SRichard Henderson
4894daf457d4SRichard Henderson TRANS(FMOVq, 64, do_qq, a, tcg_gen_mov_i128)
4895daf457d4SRichard Henderson TRANS(FNEGq, 64, do_qq, a, gen_op_fnegq)
4896daf457d4SRichard Henderson TRANS(FABSq, 64, do_qq, a, gen_op_fabsq)
4897f4e18df5SRichard Henderson
do_env_qq(DisasContext * dc,arg_r_r * a,void (* func)(TCGv_i128,TCGv_env,TCGv_i128))4898c995216bSRichard Henderson static bool do_env_qq(DisasContext *dc, arg_r_r *a,
4899e41716beSRichard Henderson void (*func)(TCGv_i128, TCGv_env, TCGv_i128))
4900c995216bSRichard Henderson {
4901e41716beSRichard Henderson TCGv_i128 t;
4902e41716beSRichard Henderson
4903*d2a0c3a7SRichard Henderson if (gen_trap_if_nofpu_fpexception(dc)) {
4904c995216bSRichard Henderson return true;
4905c995216bSRichard Henderson }
4906c995216bSRichard Henderson if (gen_trap_float128(dc)) {
4907c995216bSRichard Henderson return true;
4908c995216bSRichard Henderson }
4909c995216bSRichard Henderson
4910e41716beSRichard Henderson t = gen_load_fpr_Q(dc, a->rs);
4911e41716beSRichard Henderson func(t, tcg_env, t);
4912e41716beSRichard Henderson gen_store_fpr_Q(dc, a->rd, t);
4913c995216bSRichard Henderson return advance_pc(dc);
4914c995216bSRichard Henderson }
4915c995216bSRichard Henderson
TRANS(FSQRTq,ALL,do_env_qq,a,gen_helper_fsqrtq)4916c995216bSRichard Henderson TRANS(FSQRTq, ALL, do_env_qq, a, gen_helper_fsqrtq)
4917c995216bSRichard Henderson
4918bd9c5c42SRichard Henderson static bool do_env_fq(DisasContext *dc, arg_r_r *a,
4919d81e3efeSRichard Henderson void (*func)(TCGv_i32, TCGv_env, TCGv_i128))
4920bd9c5c42SRichard Henderson {
4921d81e3efeSRichard Henderson TCGv_i128 src;
4922bd9c5c42SRichard Henderson TCGv_i32 dst;
4923bd9c5c42SRichard Henderson
4924*d2a0c3a7SRichard Henderson if (gen_trap_if_nofpu_fpexception(dc)) {
4925bd9c5c42SRichard Henderson return true;
4926bd9c5c42SRichard Henderson }
4927bd9c5c42SRichard Henderson if (gen_trap_float128(dc)) {
4928bd9c5c42SRichard Henderson return true;
4929bd9c5c42SRichard Henderson }
4930bd9c5c42SRichard Henderson
4931d81e3efeSRichard Henderson src = gen_load_fpr_Q(dc, a->rs);
4932388a6465SRichard Henderson dst = tcg_temp_new_i32();
4933d81e3efeSRichard Henderson func(dst, tcg_env, src);
4934bd9c5c42SRichard Henderson gen_store_fpr_F(dc, a->rd, dst);
4935bd9c5c42SRichard Henderson return advance_pc(dc);
4936bd9c5c42SRichard Henderson }
4937bd9c5c42SRichard Henderson
TRANS(FqTOs,ALL,do_env_fq,a,gen_helper_fqtos)4938bd9c5c42SRichard Henderson TRANS(FqTOs, ALL, do_env_fq, a, gen_helper_fqtos)
4939bd9c5c42SRichard Henderson TRANS(FqTOi, ALL, do_env_fq, a, gen_helper_fqtoi)
4940bd9c5c42SRichard Henderson
49411617586fSRichard Henderson static bool do_env_dq(DisasContext *dc, arg_r_r *a,
494225a5769eSRichard Henderson void (*func)(TCGv_i64, TCGv_env, TCGv_i128))
49431617586fSRichard Henderson {
494425a5769eSRichard Henderson TCGv_i128 src;
49451617586fSRichard Henderson TCGv_i64 dst;
49461617586fSRichard Henderson
4947*d2a0c3a7SRichard Henderson if (gen_trap_if_nofpu_fpexception(dc)) {
49481617586fSRichard Henderson return true;
49491617586fSRichard Henderson }
49501617586fSRichard Henderson if (gen_trap_float128(dc)) {
49511617586fSRichard Henderson return true;
49521617586fSRichard Henderson }
49531617586fSRichard Henderson
495425a5769eSRichard Henderson src = gen_load_fpr_Q(dc, a->rs);
495552f46d46SRichard Henderson dst = tcg_temp_new_i64();
495625a5769eSRichard Henderson func(dst, tcg_env, src);
49571617586fSRichard Henderson gen_store_fpr_D(dc, a->rd, dst);
49581617586fSRichard Henderson return advance_pc(dc);
49591617586fSRichard Henderson }
49601617586fSRichard Henderson
TRANS(FqTOd,ALL,do_env_dq,a,gen_helper_fqtod)49611617586fSRichard Henderson TRANS(FqTOd, ALL, do_env_dq, a, gen_helper_fqtod)
49621617586fSRichard Henderson TRANS(FqTOx, 64, do_env_dq, a, gen_helper_fqtox)
49631617586fSRichard Henderson
496413ebcc77SRichard Henderson static bool do_env_qf(DisasContext *dc, arg_r_r *a,
49650b2a61ccSRichard Henderson void (*func)(TCGv_i128, TCGv_env, TCGv_i32))
496613ebcc77SRichard Henderson {
496713ebcc77SRichard Henderson TCGv_i32 src;
49680b2a61ccSRichard Henderson TCGv_i128 dst;
496913ebcc77SRichard Henderson
4970*d2a0c3a7SRichard Henderson if (gen_trap_if_nofpu_fpexception(dc)) {
497113ebcc77SRichard Henderson return true;
497213ebcc77SRichard Henderson }
497313ebcc77SRichard Henderson if (gen_trap_float128(dc)) {
497413ebcc77SRichard Henderson return true;
497513ebcc77SRichard Henderson }
497613ebcc77SRichard Henderson
497713ebcc77SRichard Henderson src = gen_load_fpr_F(dc, a->rs);
49780b2a61ccSRichard Henderson dst = tcg_temp_new_i128();
49790b2a61ccSRichard Henderson func(dst, tcg_env, src);
49800b2a61ccSRichard Henderson gen_store_fpr_Q(dc, a->rd, dst);
498113ebcc77SRichard Henderson return advance_pc(dc);
498213ebcc77SRichard Henderson }
498313ebcc77SRichard Henderson
TRANS(FiTOq,ALL,do_env_qf,a,gen_helper_fitoq)498413ebcc77SRichard Henderson TRANS(FiTOq, ALL, do_env_qf, a, gen_helper_fitoq)
498513ebcc77SRichard Henderson TRANS(FsTOq, ALL, do_env_qf, a, gen_helper_fstoq)
498613ebcc77SRichard Henderson
49877b8e3e1aSRichard Henderson static bool do_env_qd(DisasContext *dc, arg_r_r *a,
4988fdc50716SRichard Henderson void (*func)(TCGv_i128, TCGv_env, TCGv_i64))
49897b8e3e1aSRichard Henderson {
49907b8e3e1aSRichard Henderson TCGv_i64 src;
4991fdc50716SRichard Henderson TCGv_i128 dst;
49927b8e3e1aSRichard Henderson
4993*d2a0c3a7SRichard Henderson if (gen_trap_if_nofpu_fpexception(dc)) {
49947b8e3e1aSRichard Henderson return true;
49957b8e3e1aSRichard Henderson }
49967b8e3e1aSRichard Henderson
49977b8e3e1aSRichard Henderson src = gen_load_fpr_D(dc, a->rs);
4998fdc50716SRichard Henderson dst = tcg_temp_new_i128();
4999fdc50716SRichard Henderson func(dst, tcg_env, src);
5000fdc50716SRichard Henderson gen_store_fpr_Q(dc, a->rd, dst);
50017b8e3e1aSRichard Henderson return advance_pc(dc);
50027b8e3e1aSRichard Henderson }
50037b8e3e1aSRichard Henderson
TRANS(FdTOq,ALL,do_env_qd,a,gen_helper_fdtoq)50047b8e3e1aSRichard Henderson TRANS(FdTOq, ALL, do_env_qd, a, gen_helper_fdtoq)
50057b8e3e1aSRichard Henderson TRANS(FxTOq, 64, do_env_qd, a, gen_helper_fxtoq)
50067b8e3e1aSRichard Henderson
50077f10b52fSRichard Henderson static bool do_fff(DisasContext *dc, arg_r_r_r *a,
50087f10b52fSRichard Henderson void (*func)(TCGv_i32, TCGv_i32, TCGv_i32))
50097f10b52fSRichard Henderson {
50107f10b52fSRichard Henderson TCGv_i32 src1, src2;
50117f10b52fSRichard Henderson
50127f10b52fSRichard Henderson if (gen_trap_ifnofpu(dc)) {
50137f10b52fSRichard Henderson return true;
50147f10b52fSRichard Henderson }
50157f10b52fSRichard Henderson
50167f10b52fSRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1);
50177f10b52fSRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2);
50187f10b52fSRichard Henderson func(src1, src1, src2);
50197f10b52fSRichard Henderson gen_store_fpr_F(dc, a->rd, src1);
50207f10b52fSRichard Henderson return advance_pc(dc);
50217f10b52fSRichard Henderson }
50227f10b52fSRichard Henderson
TRANS(FPADD16s,VIS1,do_fff,a,tcg_gen_vec_add16_i32)50237f10b52fSRichard Henderson TRANS(FPADD16s, VIS1, do_fff, a, tcg_gen_vec_add16_i32)
50247f10b52fSRichard Henderson TRANS(FPADD32s, VIS1, do_fff, a, tcg_gen_add_i32)
50257f10b52fSRichard Henderson TRANS(FPSUB16s, VIS1, do_fff, a, tcg_gen_vec_sub16_i32)
50267f10b52fSRichard Henderson TRANS(FPSUB32s, VIS1, do_fff, a, tcg_gen_sub_i32)
50277f10b52fSRichard Henderson TRANS(FNORs, VIS1, do_fff, a, tcg_gen_nor_i32)
50287f10b52fSRichard Henderson TRANS(FANDNOTs, VIS1, do_fff, a, tcg_gen_andc_i32)
50297f10b52fSRichard Henderson TRANS(FXORs, VIS1, do_fff, a, tcg_gen_xor_i32)
50307f10b52fSRichard Henderson TRANS(FNANDs, VIS1, do_fff, a, tcg_gen_nand_i32)
50317f10b52fSRichard Henderson TRANS(FANDs, VIS1, do_fff, a, tcg_gen_and_i32)
50327f10b52fSRichard Henderson TRANS(FXNORs, VIS1, do_fff, a, tcg_gen_eqv_i32)
50337f10b52fSRichard Henderson TRANS(FORNOTs, VIS1, do_fff, a, tcg_gen_orc_i32)
50347f10b52fSRichard Henderson TRANS(FORs, VIS1, do_fff, a, tcg_gen_or_i32)
50357f10b52fSRichard Henderson
50363d50b728SRichard Henderson TRANS(FHADDs, VIS3, do_fff, a, gen_op_fhadds)
50373d50b728SRichard Henderson TRANS(FHSUBs, VIS3, do_fff, a, gen_op_fhsubs)
50383d50b728SRichard Henderson TRANS(FNHADDs, VIS3, do_fff, a, gen_op_fnhadds)
50393d50b728SRichard Henderson
50400d1d3aafSRichard Henderson TRANS(FPADDS16s, VIS3, do_fff, a, gen_op_fpadds16s)
50410d1d3aafSRichard Henderson TRANS(FPSUBS16s, VIS3, do_fff, a, gen_op_fpsubs16s)
50420d1d3aafSRichard Henderson TRANS(FPADDS32s, VIS3, do_fff, a, gen_op_fpadds32s)
50430d1d3aafSRichard Henderson TRANS(FPSUBS32s, VIS3, do_fff, a, gen_op_fpsubs32s)
50440d1d3aafSRichard Henderson
5045c1514961SRichard Henderson static bool do_env_fff(DisasContext *dc, arg_r_r_r *a,
5046c1514961SRichard Henderson void (*func)(TCGv_i32, TCGv_env, TCGv_i32, TCGv_i32))
5047c1514961SRichard Henderson {
5048c1514961SRichard Henderson TCGv_i32 src1, src2;
5049c1514961SRichard Henderson
5050*d2a0c3a7SRichard Henderson if (gen_trap_if_nofpu_fpexception(dc)) {
5051c1514961SRichard Henderson return true;
5052c1514961SRichard Henderson }
5053c1514961SRichard Henderson
5054c1514961SRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1);
5055c1514961SRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2);
5056c1514961SRichard Henderson func(src1, tcg_env, src1, src2);
5057c1514961SRichard Henderson gen_store_fpr_F(dc, a->rd, src1);
5058c1514961SRichard Henderson return advance_pc(dc);
5059c1514961SRichard Henderson }
5060c1514961SRichard Henderson
TRANS(FADDs,ALL,do_env_fff,a,gen_helper_fadds)5061c1514961SRichard Henderson TRANS(FADDs, ALL, do_env_fff, a, gen_helper_fadds)
5062c1514961SRichard Henderson TRANS(FSUBs, ALL, do_env_fff, a, gen_helper_fsubs)
5063c1514961SRichard Henderson TRANS(FMULs, ALL, do_env_fff, a, gen_helper_fmuls)
5064c1514961SRichard Henderson TRANS(FDIVs, ALL, do_env_fff, a, gen_helper_fdivs)
50653d50b728SRichard Henderson TRANS(FNADDs, VIS3, do_env_fff, a, gen_helper_fnadds)
50663d50b728SRichard Henderson TRANS(FNMULs, VIS3, do_env_fff, a, gen_helper_fnmuls)
5067c1514961SRichard Henderson
5068a859602cSRichard Henderson static bool do_dff(DisasContext *dc, arg_r_r_r *a,
5069a859602cSRichard Henderson void (*func)(TCGv_i64, TCGv_i32, TCGv_i32))
5070a859602cSRichard Henderson {
5071a859602cSRichard Henderson TCGv_i64 dst;
5072a859602cSRichard Henderson TCGv_i32 src1, src2;
5073a859602cSRichard Henderson
5074a859602cSRichard Henderson if (gen_trap_ifnofpu(dc)) {
5075a859602cSRichard Henderson return true;
5076a859602cSRichard Henderson }
5077a859602cSRichard Henderson
507852f46d46SRichard Henderson dst = tcg_temp_new_i64();
5079a859602cSRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1);
5080a859602cSRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2);
5081a859602cSRichard Henderson func(dst, src1, src2);
5082a859602cSRichard Henderson gen_store_fpr_D(dc, a->rd, dst);
5083a859602cSRichard Henderson return advance_pc(dc);
5084a859602cSRichard Henderson }
5085a859602cSRichard Henderson
TRANS(FMUL8x16AU,VIS1,do_dff,a,gen_op_fmul8x16au)5086a859602cSRichard Henderson TRANS(FMUL8x16AU, VIS1, do_dff, a, gen_op_fmul8x16au)
5087a859602cSRichard Henderson TRANS(FMUL8x16AL, VIS1, do_dff, a, gen_op_fmul8x16al)
5088be8998e0SRichard Henderson TRANS(FMULD8SUx16, VIS1, do_dff, a, gen_op_fmuld8sux16)
5089be8998e0SRichard Henderson TRANS(FMULD8ULx16, VIS1, do_dff, a, gen_op_fmuld8ulx16)
5090d3ef26afSRichard Henderson TRANS(FPMERGE, VIS1, do_dff, a, gen_helper_fpmerge)
5091a859602cSRichard Henderson
50929157dcccSRichard Henderson static bool do_dfd(DisasContext *dc, arg_r_r_r *a,
50939157dcccSRichard Henderson void (*func)(TCGv_i64, TCGv_i32, TCGv_i64))
50949157dcccSRichard Henderson {
50959157dcccSRichard Henderson TCGv_i64 dst, src2;
50969157dcccSRichard Henderson TCGv_i32 src1;
50979157dcccSRichard Henderson
50989157dcccSRichard Henderson if (gen_trap_ifnofpu(dc)) {
50999157dcccSRichard Henderson return true;
51009157dcccSRichard Henderson }
51019157dcccSRichard Henderson
510252f46d46SRichard Henderson dst = tcg_temp_new_i64();
51039157dcccSRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1);
51049157dcccSRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2);
51059157dcccSRichard Henderson func(dst, src1, src2);
51069157dcccSRichard Henderson gen_store_fpr_D(dc, a->rd, dst);
51079157dcccSRichard Henderson return advance_pc(dc);
51089157dcccSRichard Henderson }
51099157dcccSRichard Henderson
TRANS(FMUL8x16,VIS1,do_dfd,a,gen_helper_fmul8x16)51109157dcccSRichard Henderson TRANS(FMUL8x16, VIS1, do_dfd, a, gen_helper_fmul8x16)
51119157dcccSRichard Henderson
511228c131a3SRichard Henderson static bool do_gvec_ddd(DisasContext *dc, arg_r_r_r *a, MemOp vece,
511328c131a3SRichard Henderson void (*func)(unsigned, uint32_t, uint32_t,
511428c131a3SRichard Henderson uint32_t, uint32_t, uint32_t))
511528c131a3SRichard Henderson {
511628c131a3SRichard Henderson if (gen_trap_ifnofpu(dc)) {
511728c131a3SRichard Henderson return true;
511828c131a3SRichard Henderson }
511928c131a3SRichard Henderson
512028c131a3SRichard Henderson func(vece, gen_offset_fpr_D(a->rd), gen_offset_fpr_D(a->rs1),
512128c131a3SRichard Henderson gen_offset_fpr_D(a->rs2), 8, 8);
512228c131a3SRichard Henderson return advance_pc(dc);
512328c131a3SRichard Henderson }
512428c131a3SRichard Henderson
TRANS(FPADD8,VIS4,do_gvec_ddd,a,MO_8,tcg_gen_gvec_add)5125b99c1bbdSRichard Henderson TRANS(FPADD8, VIS4, do_gvec_ddd, a, MO_8, tcg_gen_gvec_add)
512628c131a3SRichard Henderson TRANS(FPADD16, VIS1, do_gvec_ddd, a, MO_16, tcg_gen_gvec_add)
512728c131a3SRichard Henderson TRANS(FPADD32, VIS1, do_gvec_ddd, a, MO_32, tcg_gen_gvec_add)
5128b99c1bbdSRichard Henderson
5129b99c1bbdSRichard Henderson TRANS(FPSUB8, VIS4, do_gvec_ddd, a, MO_8, tcg_gen_gvec_sub)
513028c131a3SRichard Henderson TRANS(FPSUB16, VIS1, do_gvec_ddd, a, MO_16, tcg_gen_gvec_sub)
513128c131a3SRichard Henderson TRANS(FPSUB32, VIS1, do_gvec_ddd, a, MO_32, tcg_gen_gvec_sub)
5132b99c1bbdSRichard Henderson
51337837185eSRichard Henderson TRANS(FCHKSM16, VIS3, do_gvec_ddd, a, MO_16, gen_op_fchksm16)
5134d6ff1ccbSRichard Henderson TRANS(FMEAN16, VIS3, do_gvec_ddd, a, MO_16, gen_op_fmean16)
513528c131a3SRichard Henderson
5136b99c1bbdSRichard Henderson TRANS(FPADDS8, VIS4, do_gvec_ddd, a, MO_8, tcg_gen_gvec_ssadd)
51370d1d3aafSRichard Henderson TRANS(FPADDS16, VIS3, do_gvec_ddd, a, MO_16, tcg_gen_gvec_ssadd)
51380d1d3aafSRichard Henderson TRANS(FPADDS32, VIS3, do_gvec_ddd, a, MO_32, tcg_gen_gvec_ssadd)
5139b99c1bbdSRichard Henderson TRANS(FPADDUS8, VIS4, do_gvec_ddd, a, MO_8, tcg_gen_gvec_usadd)
5140b99c1bbdSRichard Henderson TRANS(FPADDUS16, VIS4, do_gvec_ddd, a, MO_16, tcg_gen_gvec_usadd)
5141b99c1bbdSRichard Henderson
5142b99c1bbdSRichard Henderson TRANS(FPSUBS8, VIS4, do_gvec_ddd, a, MO_8, tcg_gen_gvec_sssub)
51430d1d3aafSRichard Henderson TRANS(FPSUBS16, VIS3, do_gvec_ddd, a, MO_16, tcg_gen_gvec_sssub)
51440d1d3aafSRichard Henderson TRANS(FPSUBS32, VIS3, do_gvec_ddd, a, MO_32, tcg_gen_gvec_sssub)
5145b99c1bbdSRichard Henderson TRANS(FPSUBUS8, VIS4, do_gvec_ddd, a, MO_8, tcg_gen_gvec_ussub)
5146b99c1bbdSRichard Henderson TRANS(FPSUBUS16, VIS4, do_gvec_ddd, a, MO_16, tcg_gen_gvec_ussub)
51470d1d3aafSRichard Henderson
5148fbc5c8d4SRichard Henderson TRANS(FSLL16, VIS3, do_gvec_ddd, a, MO_16, tcg_gen_gvec_shlv)
5149fbc5c8d4SRichard Henderson TRANS(FSLL32, VIS3, do_gvec_ddd, a, MO_32, tcg_gen_gvec_shlv)
5150fbc5c8d4SRichard Henderson TRANS(FSRL16, VIS3, do_gvec_ddd, a, MO_16, tcg_gen_gvec_shrv)
5151fbc5c8d4SRichard Henderson TRANS(FSRL32, VIS3, do_gvec_ddd, a, MO_32, tcg_gen_gvec_shrv)
5152fbc5c8d4SRichard Henderson TRANS(FSRA16, VIS3, do_gvec_ddd, a, MO_16, tcg_gen_gvec_sarv)
5153fbc5c8d4SRichard Henderson TRANS(FSRA32, VIS3, do_gvec_ddd, a, MO_32, tcg_gen_gvec_sarv)
5154fbc5c8d4SRichard Henderson
5155db11dfeaSRichard Henderson TRANS(FPMIN8, VIS4, do_gvec_ddd, a, MO_8, tcg_gen_gvec_smin)
5156db11dfeaSRichard Henderson TRANS(FPMIN16, VIS4, do_gvec_ddd, a, MO_16, tcg_gen_gvec_smin)
5157db11dfeaSRichard Henderson TRANS(FPMIN32, VIS4, do_gvec_ddd, a, MO_32, tcg_gen_gvec_smin)
5158db11dfeaSRichard Henderson TRANS(FPMINU8, VIS4, do_gvec_ddd, a, MO_8, tcg_gen_gvec_umin)
5159db11dfeaSRichard Henderson TRANS(FPMINU16, VIS4, do_gvec_ddd, a, MO_16, tcg_gen_gvec_umin)
5160db11dfeaSRichard Henderson TRANS(FPMINU32, VIS4, do_gvec_ddd, a, MO_32, tcg_gen_gvec_umin)
5161db11dfeaSRichard Henderson
5162db11dfeaSRichard Henderson TRANS(FPMAX8, VIS4, do_gvec_ddd, a, MO_8, tcg_gen_gvec_smax)
5163db11dfeaSRichard Henderson TRANS(FPMAX16, VIS4, do_gvec_ddd, a, MO_16, tcg_gen_gvec_smax)
5164db11dfeaSRichard Henderson TRANS(FPMAX32, VIS4, do_gvec_ddd, a, MO_32, tcg_gen_gvec_smax)
5165db11dfeaSRichard Henderson TRANS(FPMAXU8, VIS4, do_gvec_ddd, a, MO_8, tcg_gen_gvec_umax)
5166db11dfeaSRichard Henderson TRANS(FPMAXU16, VIS4, do_gvec_ddd, a, MO_16, tcg_gen_gvec_umax)
5167db11dfeaSRichard Henderson TRANS(FPMAXU32, VIS4, do_gvec_ddd, a, MO_32, tcg_gen_gvec_umax)
5168db11dfeaSRichard Henderson
5169e06c9f83SRichard Henderson static bool do_ddd(DisasContext *dc, arg_r_r_r *a,
5170e06c9f83SRichard Henderson void (*func)(TCGv_i64, TCGv_i64, TCGv_i64))
5171e06c9f83SRichard Henderson {
5172e06c9f83SRichard Henderson TCGv_i64 dst, src1, src2;
5173e06c9f83SRichard Henderson
5174e06c9f83SRichard Henderson if (gen_trap_ifnofpu(dc)) {
5175e06c9f83SRichard Henderson return true;
5176e06c9f83SRichard Henderson }
5177e06c9f83SRichard Henderson
517852f46d46SRichard Henderson dst = tcg_temp_new_i64();
5179e06c9f83SRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1);
5180e06c9f83SRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2);
5181e06c9f83SRichard Henderson func(dst, src1, src2);
5182e06c9f83SRichard Henderson gen_store_fpr_D(dc, a->rd, dst);
5183e06c9f83SRichard Henderson return advance_pc(dc);
5184e06c9f83SRichard Henderson }
5185e06c9f83SRichard Henderson
TRANS(FMUL8SUx16,VIS1,do_ddd,a,gen_helper_fmul8sux16)5186e06c9f83SRichard Henderson TRANS(FMUL8SUx16, VIS1, do_ddd, a, gen_helper_fmul8sux16)
5187e06c9f83SRichard Henderson TRANS(FMUL8ULx16, VIS1, do_ddd, a, gen_helper_fmul8ulx16)
5188e06c9f83SRichard Henderson
5189e06c9f83SRichard Henderson TRANS(FNORd, VIS1, do_ddd, a, tcg_gen_nor_i64)
5190e06c9f83SRichard Henderson TRANS(FANDNOTd, VIS1, do_ddd, a, tcg_gen_andc_i64)
5191e06c9f83SRichard Henderson TRANS(FXORd, VIS1, do_ddd, a, tcg_gen_xor_i64)
5192e06c9f83SRichard Henderson TRANS(FNANDd, VIS1, do_ddd, a, tcg_gen_nand_i64)
5193e06c9f83SRichard Henderson TRANS(FANDd, VIS1, do_ddd, a, tcg_gen_and_i64)
5194e06c9f83SRichard Henderson TRANS(FXNORd, VIS1, do_ddd, a, tcg_gen_eqv_i64)
5195e06c9f83SRichard Henderson TRANS(FORNOTd, VIS1, do_ddd, a, tcg_gen_orc_i64)
5196e06c9f83SRichard Henderson TRANS(FORd, VIS1, do_ddd, a, tcg_gen_or_i64)
5197e06c9f83SRichard Henderson
51984b6edc0aSRichard Henderson TRANS(FPACK32, VIS1, do_ddd, a, gen_op_fpack32)
5199b2b48493SRichard Henderson TRANS(FALIGNDATAg, VIS1, do_ddd, a, gen_op_faligndata_g)
52004b6edc0aSRichard Henderson TRANS(BSHUFFLE, VIS2, do_ddd, a, gen_op_bshuffle)
52014b6edc0aSRichard Henderson
52023d50b728SRichard Henderson TRANS(FHADDd, VIS3, do_ddd, a, gen_op_fhaddd)
52033d50b728SRichard Henderson TRANS(FHSUBd, VIS3, do_ddd, a, gen_op_fhsubd)
52043d50b728SRichard Henderson TRANS(FNHADDd, VIS3, do_ddd, a, gen_op_fnhaddd)
52053d50b728SRichard Henderson
5206bc3f14a9SRichard Henderson TRANS(FPADD64, VIS3B, do_ddd, a, tcg_gen_add_i64)
5207bc3f14a9SRichard Henderson TRANS(FPSUB64, VIS3B, do_ddd, a, tcg_gen_sub_i64)
5208fbc5c8d4SRichard Henderson TRANS(FSLAS16, VIS3, do_ddd, a, gen_helper_fslas16)
5209fbc5c8d4SRichard Henderson TRANS(FSLAS32, VIS3, do_ddd, a, gen_helper_fslas32)
5210bc3f14a9SRichard Henderson
5211e2fa6bd1SRichard Henderson static bool do_rdd(DisasContext *dc, arg_r_r_r *a,
5212e2fa6bd1SRichard Henderson void (*func)(TCGv, TCGv_i64, TCGv_i64))
5213e2fa6bd1SRichard Henderson {
5214e2fa6bd1SRichard Henderson TCGv_i64 src1, src2;
5215e2fa6bd1SRichard Henderson TCGv dst;
5216e2fa6bd1SRichard Henderson
5217e2fa6bd1SRichard Henderson if (gen_trap_ifnofpu(dc)) {
5218e2fa6bd1SRichard Henderson return true;
5219e2fa6bd1SRichard Henderson }
5220e2fa6bd1SRichard Henderson
5221e2fa6bd1SRichard Henderson dst = gen_dest_gpr(dc, a->rd);
5222e2fa6bd1SRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1);
5223e2fa6bd1SRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2);
5224e2fa6bd1SRichard Henderson func(dst, src1, src2);
5225e2fa6bd1SRichard Henderson gen_store_gpr(dc, a->rd, dst);
5226e2fa6bd1SRichard Henderson return advance_pc(dc);
5227e2fa6bd1SRichard Henderson }
5228e2fa6bd1SRichard Henderson
TRANS(FPCMPLE16,VIS1,do_rdd,a,gen_helper_fcmple16)5229e2fa6bd1SRichard Henderson TRANS(FPCMPLE16, VIS1, do_rdd, a, gen_helper_fcmple16)
5230e2fa6bd1SRichard Henderson TRANS(FPCMPNE16, VIS1, do_rdd, a, gen_helper_fcmpne16)
5231e2fa6bd1SRichard Henderson TRANS(FPCMPGT16, VIS1, do_rdd, a, gen_helper_fcmpgt16)
5232e2fa6bd1SRichard Henderson TRANS(FPCMPEQ16, VIS1, do_rdd, a, gen_helper_fcmpeq16)
5233b3c934ddSRichard Henderson TRANS(FPCMPULE16, VIS4, do_rdd, a, gen_helper_fcmpule16)
5234b3c934ddSRichard Henderson TRANS(FPCMPUGT16, VIS4, do_rdd, a, gen_helper_fcmpugt16)
5235e2fa6bd1SRichard Henderson
5236e2fa6bd1SRichard Henderson TRANS(FPCMPLE32, VIS1, do_rdd, a, gen_helper_fcmple32)
5237e2fa6bd1SRichard Henderson TRANS(FPCMPNE32, VIS1, do_rdd, a, gen_helper_fcmpne32)
5238e2fa6bd1SRichard Henderson TRANS(FPCMPGT32, VIS1, do_rdd, a, gen_helper_fcmpgt32)
5239e2fa6bd1SRichard Henderson TRANS(FPCMPEQ32, VIS1, do_rdd, a, gen_helper_fcmpeq32)
5240b3c934ddSRichard Henderson TRANS(FPCMPULE32, VIS4, do_rdd, a, gen_helper_fcmpule32)
5241b3c934ddSRichard Henderson TRANS(FPCMPUGT32, VIS4, do_rdd, a, gen_helper_fcmpugt32)
5242e2fa6bd1SRichard Henderson
5243669e0774SRichard Henderson TRANS(FPCMPEQ8, VIS3B, do_rdd, a, gen_helper_fcmpeq8)
5244669e0774SRichard Henderson TRANS(FPCMPNE8, VIS3B, do_rdd, a, gen_helper_fcmpne8)
5245669e0774SRichard Henderson TRANS(FPCMPULE8, VIS3B, do_rdd, a, gen_helper_fcmpule8)
5246669e0774SRichard Henderson TRANS(FPCMPUGT8, VIS3B, do_rdd, a, gen_helper_fcmpugt8)
5247b3c934ddSRichard Henderson TRANS(FPCMPLE8, VIS4, do_rdd, a, gen_helper_fcmple8)
5248b3c934ddSRichard Henderson TRANS(FPCMPGT8, VIS4, do_rdd, a, gen_helper_fcmpgt8)
5249669e0774SRichard Henderson
52507d5ebd8fSRichard Henderson TRANS(PDISTN, VIS3, do_rdd, a, gen_op_pdistn)
5251029b0283SRichard Henderson TRANS(XMULX, VIS3, do_rrr, a, gen_helper_xmulx)
5252029b0283SRichard Henderson TRANS(XMULXHI, VIS3, do_rrr, a, gen_helper_xmulxhi)
52537d5ebd8fSRichard Henderson
5254f2a59b0aSRichard Henderson static bool do_env_ddd(DisasContext *dc, arg_r_r_r *a,
5255f2a59b0aSRichard Henderson void (*func)(TCGv_i64, TCGv_env, TCGv_i64, TCGv_i64))
5256f2a59b0aSRichard Henderson {
5257f2a59b0aSRichard Henderson TCGv_i64 dst, src1, src2;
5258f2a59b0aSRichard Henderson
5259*d2a0c3a7SRichard Henderson if (gen_trap_if_nofpu_fpexception(dc)) {
5260f2a59b0aSRichard Henderson return true;
5261f2a59b0aSRichard Henderson }
5262f2a59b0aSRichard Henderson
526352f46d46SRichard Henderson dst = tcg_temp_new_i64();
5264f2a59b0aSRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1);
5265f2a59b0aSRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2);
5266f2a59b0aSRichard Henderson func(dst, tcg_env, src1, src2);
5267f2a59b0aSRichard Henderson gen_store_fpr_D(dc, a->rd, dst);
5268f2a59b0aSRichard Henderson return advance_pc(dc);
5269f2a59b0aSRichard Henderson }
5270f2a59b0aSRichard Henderson
TRANS(FADDd,ALL,do_env_ddd,a,gen_helper_faddd)5271f2a59b0aSRichard Henderson TRANS(FADDd, ALL, do_env_ddd, a, gen_helper_faddd)
5272f2a59b0aSRichard Henderson TRANS(FSUBd, ALL, do_env_ddd, a, gen_helper_fsubd)
5273f2a59b0aSRichard Henderson TRANS(FMULd, ALL, do_env_ddd, a, gen_helper_fmuld)
5274f2a59b0aSRichard Henderson TRANS(FDIVd, ALL, do_env_ddd, a, gen_helper_fdivd)
52753d50b728SRichard Henderson TRANS(FNADDd, VIS3, do_env_ddd, a, gen_helper_fnaddd)
52763d50b728SRichard Henderson TRANS(FNMULd, VIS3, do_env_ddd, a, gen_helper_fnmuld)
5277f2a59b0aSRichard Henderson
5278ff4c711bSRichard Henderson static bool trans_FsMULd(DisasContext *dc, arg_r_r_r *a)
5279ff4c711bSRichard Henderson {
5280ff4c711bSRichard Henderson TCGv_i64 dst;
5281ff4c711bSRichard Henderson TCGv_i32 src1, src2;
5282ff4c711bSRichard Henderson
5283*d2a0c3a7SRichard Henderson if (gen_trap_if_nofpu_fpexception(dc)) {
5284ff4c711bSRichard Henderson return true;
5285ff4c711bSRichard Henderson }
5286ff4c711bSRichard Henderson if (!(dc->def->features & CPU_FEATURE_FSMULD)) {
5287ff4c711bSRichard Henderson return raise_unimpfpop(dc);
5288ff4c711bSRichard Henderson }
5289ff4c711bSRichard Henderson
529052f46d46SRichard Henderson dst = tcg_temp_new_i64();
5291ff4c711bSRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1);
5292ff4c711bSRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2);
5293ff4c711bSRichard Henderson gen_helper_fsmuld(dst, tcg_env, src1, src2);
5294ff4c711bSRichard Henderson gen_store_fpr_D(dc, a->rd, dst);
5295ff4c711bSRichard Henderson return advance_pc(dc);
5296ff4c711bSRichard Henderson }
5297ff4c711bSRichard Henderson
trans_FNsMULd(DisasContext * dc,arg_r_r_r * a)52983d50b728SRichard Henderson static bool trans_FNsMULd(DisasContext *dc, arg_r_r_r *a)
52993d50b728SRichard Henderson {
53003d50b728SRichard Henderson TCGv_i64 dst;
53013d50b728SRichard Henderson TCGv_i32 src1, src2;
53023d50b728SRichard Henderson
53033d50b728SRichard Henderson if (!avail_VIS3(dc)) {
53043d50b728SRichard Henderson return false;
53053d50b728SRichard Henderson }
53063d50b728SRichard Henderson if (gen_trap_ifnofpu(dc)) {
53073d50b728SRichard Henderson return true;
53083d50b728SRichard Henderson }
53093d50b728SRichard Henderson dst = tcg_temp_new_i64();
53103d50b728SRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1);
53113d50b728SRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2);
53123d50b728SRichard Henderson gen_helper_fnsmuld(dst, tcg_env, src1, src2);
53133d50b728SRichard Henderson gen_store_fpr_D(dc, a->rd, dst);
53143d50b728SRichard Henderson return advance_pc(dc);
53153d50b728SRichard Henderson }
53163d50b728SRichard Henderson
do_ffff(DisasContext * dc,arg_r_r_r_r * a,void (* func)(TCGv_i32,TCGv_i32,TCGv_i32,TCGv_i32))53174fd71d19SRichard Henderson static bool do_ffff(DisasContext *dc, arg_r_r_r_r *a,
53184fd71d19SRichard Henderson void (*func)(TCGv_i32, TCGv_i32, TCGv_i32, TCGv_i32))
53194fd71d19SRichard Henderson {
53204fd71d19SRichard Henderson TCGv_i32 dst, src1, src2, src3;
53214fd71d19SRichard Henderson
53224fd71d19SRichard Henderson if (gen_trap_ifnofpu(dc)) {
53234fd71d19SRichard Henderson return true;
53244fd71d19SRichard Henderson }
53254fd71d19SRichard Henderson
53264fd71d19SRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1);
53274fd71d19SRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2);
53284fd71d19SRichard Henderson src3 = gen_load_fpr_F(dc, a->rs3);
53294fd71d19SRichard Henderson dst = tcg_temp_new_i32();
53304fd71d19SRichard Henderson func(dst, src1, src2, src3);
53314fd71d19SRichard Henderson gen_store_fpr_F(dc, a->rd, dst);
53324fd71d19SRichard Henderson return advance_pc(dc);
53334fd71d19SRichard Henderson }
53344fd71d19SRichard Henderson
TRANS(FMADDs,FMAF,do_ffff,a,gen_op_fmadds)53354fd71d19SRichard Henderson TRANS(FMADDs, FMAF, do_ffff, a, gen_op_fmadds)
53364fd71d19SRichard Henderson TRANS(FMSUBs, FMAF, do_ffff, a, gen_op_fmsubs)
53374fd71d19SRichard Henderson TRANS(FNMSUBs, FMAF, do_ffff, a, gen_op_fnmsubs)
53384fd71d19SRichard Henderson TRANS(FNMADDs, FMAF, do_ffff, a, gen_op_fnmadds)
53394fd71d19SRichard Henderson
53404fd71d19SRichard Henderson static bool do_dddd(DisasContext *dc, arg_r_r_r_r *a,
5341afb04344SRichard Henderson void (*func)(TCGv_i64, TCGv_i64, TCGv_i64, TCGv_i64))
5342afb04344SRichard Henderson {
53434fd71d19SRichard Henderson TCGv_i64 dst, src1, src2, src3;
5344afb04344SRichard Henderson
5345afb04344SRichard Henderson if (gen_trap_ifnofpu(dc)) {
5346afb04344SRichard Henderson return true;
5347afb04344SRichard Henderson }
5348afb04344SRichard Henderson
534952f46d46SRichard Henderson dst = tcg_temp_new_i64();
5350afb04344SRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1);
5351afb04344SRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2);
53524fd71d19SRichard Henderson src3 = gen_load_fpr_D(dc, a->rs3);
53534fd71d19SRichard Henderson func(dst, src1, src2, src3);
5354afb04344SRichard Henderson gen_store_fpr_D(dc, a->rd, dst);
5355afb04344SRichard Henderson return advance_pc(dc);
5356afb04344SRichard Henderson }
5357afb04344SRichard Henderson
TRANS(PDIST,VIS1,do_dddd,a,gen_helper_pdist)5358afb04344SRichard Henderson TRANS(PDIST, VIS1, do_dddd, a, gen_helper_pdist)
53594fd71d19SRichard Henderson TRANS(FMADDd, FMAF, do_dddd, a, gen_op_fmaddd)
53604fd71d19SRichard Henderson TRANS(FMSUBd, FMAF, do_dddd, a, gen_op_fmsubd)
53614fd71d19SRichard Henderson TRANS(FNMSUBd, FMAF, do_dddd, a, gen_op_fnmsubd)
53624fd71d19SRichard Henderson TRANS(FNMADDd, FMAF, do_dddd, a, gen_op_fnmaddd)
536368a414e9SRichard Henderson TRANS(FPMADDX, IMA, do_dddd, a, gen_op_fpmaddx)
536468a414e9SRichard Henderson TRANS(FPMADDXHI, IMA, do_dddd, a, gen_op_fpmaddxhi)
5365afb04344SRichard Henderson
5366b2b48493SRichard Henderson static bool trans_FALIGNDATAi(DisasContext *dc, arg_r_r_r *a)
5367b2b48493SRichard Henderson {
5368b2b48493SRichard Henderson TCGv_i64 dst, src1, src2;
5369b2b48493SRichard Henderson TCGv src3;
5370b2b48493SRichard Henderson
5371b2b48493SRichard Henderson if (!avail_VIS4(dc)) {
5372b2b48493SRichard Henderson return false;
5373b2b48493SRichard Henderson }
5374b2b48493SRichard Henderson if (gen_trap_ifnofpu(dc)) {
5375b2b48493SRichard Henderson return true;
5376b2b48493SRichard Henderson }
5377b2b48493SRichard Henderson
5378b2b48493SRichard Henderson dst = tcg_temp_new_i64();
5379b2b48493SRichard Henderson src1 = gen_load_fpr_D(dc, a->rd);
5380b2b48493SRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2);
5381b2b48493SRichard Henderson src3 = gen_load_gpr(dc, a->rs1);
5382b2b48493SRichard Henderson gen_op_faligndata_i(dst, src1, src2, src3);
5383b2b48493SRichard Henderson gen_store_fpr_D(dc, a->rd, dst);
5384b2b48493SRichard Henderson return advance_pc(dc);
5385b2b48493SRichard Henderson }
5386b2b48493SRichard Henderson
do_env_qqq(DisasContext * dc,arg_r_r_r * a,void (* func)(TCGv_i128,TCGv_env,TCGv_i128,TCGv_i128))5387a4056239SRichard Henderson static bool do_env_qqq(DisasContext *dc, arg_r_r_r *a,
538816bedf89SRichard Henderson void (*func)(TCGv_i128, TCGv_env, TCGv_i128, TCGv_i128))
5389a4056239SRichard Henderson {
539016bedf89SRichard Henderson TCGv_i128 src1, src2;
539116bedf89SRichard Henderson
5392*d2a0c3a7SRichard Henderson if (gen_trap_if_nofpu_fpexception(dc)) {
5393a4056239SRichard Henderson return true;
5394a4056239SRichard Henderson }
5395a4056239SRichard Henderson if (gen_trap_float128(dc)) {
5396a4056239SRichard Henderson return true;
5397a4056239SRichard Henderson }
5398a4056239SRichard Henderson
539916bedf89SRichard Henderson src1 = gen_load_fpr_Q(dc, a->rs1);
540016bedf89SRichard Henderson src2 = gen_load_fpr_Q(dc, a->rs2);
540116bedf89SRichard Henderson func(src1, tcg_env, src1, src2);
540216bedf89SRichard Henderson gen_store_fpr_Q(dc, a->rd, src1);
5403a4056239SRichard Henderson return advance_pc(dc);
5404a4056239SRichard Henderson }
5405a4056239SRichard Henderson
TRANS(FADDq,ALL,do_env_qqq,a,gen_helper_faddq)5406a4056239SRichard Henderson TRANS(FADDq, ALL, do_env_qqq, a, gen_helper_faddq)
5407a4056239SRichard Henderson TRANS(FSUBq, ALL, do_env_qqq, a, gen_helper_fsubq)
5408a4056239SRichard Henderson TRANS(FMULq, ALL, do_env_qqq, a, gen_helper_fmulq)
5409a4056239SRichard Henderson TRANS(FDIVq, ALL, do_env_qqq, a, gen_helper_fdivq)
5410a4056239SRichard Henderson
54115e3b17bbSRichard Henderson static bool trans_FdMULq(DisasContext *dc, arg_r_r_r *a)
54125e3b17bbSRichard Henderson {
54135e3b17bbSRichard Henderson TCGv_i64 src1, src2;
5414ba21dc99SRichard Henderson TCGv_i128 dst;
54155e3b17bbSRichard Henderson
5416*d2a0c3a7SRichard Henderson if (gen_trap_if_nofpu_fpexception(dc)) {
54175e3b17bbSRichard Henderson return true;
54185e3b17bbSRichard Henderson }
54195e3b17bbSRichard Henderson if (gen_trap_float128(dc)) {
54205e3b17bbSRichard Henderson return true;
54215e3b17bbSRichard Henderson }
54225e3b17bbSRichard Henderson
54235e3b17bbSRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1);
54245e3b17bbSRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2);
5425ba21dc99SRichard Henderson dst = tcg_temp_new_i128();
5426ba21dc99SRichard Henderson gen_helper_fdmulq(dst, tcg_env, src1, src2);
5427ba21dc99SRichard Henderson gen_store_fpr_Q(dc, a->rd, dst);
54285e3b17bbSRichard Henderson return advance_pc(dc);
54295e3b17bbSRichard Henderson }
54305e3b17bbSRichard Henderson
do_fmovr(DisasContext * dc,arg_FMOVRs * a,bool is_128,void (* func)(DisasContext *,DisasCompare *,int,int))5431f7ec8155SRichard Henderson static bool do_fmovr(DisasContext *dc, arg_FMOVRs *a, bool is_128,
5432f7ec8155SRichard Henderson void (*func)(DisasContext *, DisasCompare *, int, int))
5433f7ec8155SRichard Henderson {
5434f7ec8155SRichard Henderson DisasCompare cmp;
5435f7ec8155SRichard Henderson
54362c4f56c9SRichard Henderson if (!gen_compare_reg(&cmp, a->cond, gen_load_gpr(dc, a->rs1))) {
54372c4f56c9SRichard Henderson return false;
54382c4f56c9SRichard Henderson }
5439f7ec8155SRichard Henderson if (gen_trap_ifnofpu(dc)) {
5440f7ec8155SRichard Henderson return true;
5441f7ec8155SRichard Henderson }
5442f7ec8155SRichard Henderson if (is_128 && gen_trap_float128(dc)) {
5443f7ec8155SRichard Henderson return true;
5444f7ec8155SRichard Henderson }
5445f7ec8155SRichard Henderson
5446f7ec8155SRichard Henderson gen_op_clear_ieee_excp_and_FTT();
5447f7ec8155SRichard Henderson func(dc, &cmp, a->rd, a->rs2);
5448f7ec8155SRichard Henderson return advance_pc(dc);
5449f7ec8155SRichard Henderson }
5450f7ec8155SRichard Henderson
5451f7ec8155SRichard Henderson TRANS(FMOVRs, 64, do_fmovr, a, false, gen_fmovs)
5452f7ec8155SRichard Henderson TRANS(FMOVRd, 64, do_fmovr, a, false, gen_fmovd)
5453f7ec8155SRichard Henderson TRANS(FMOVRq, 64, do_fmovr, a, true, gen_fmovq)
5454f7ec8155SRichard Henderson
do_fmovcc(DisasContext * dc,arg_FMOVscc * a,bool is_128,void (* func)(DisasContext *,DisasCompare *,int,int))5455f7ec8155SRichard Henderson static bool do_fmovcc(DisasContext *dc, arg_FMOVscc *a, bool is_128,
5456f7ec8155SRichard Henderson void (*func)(DisasContext *, DisasCompare *, int, int))
5457f7ec8155SRichard Henderson {
5458f7ec8155SRichard Henderson DisasCompare cmp;
5459f7ec8155SRichard Henderson
5460f7ec8155SRichard Henderson if (gen_trap_ifnofpu(dc)) {
5461f7ec8155SRichard Henderson return true;
5462f7ec8155SRichard Henderson }
5463f7ec8155SRichard Henderson if (is_128 && gen_trap_float128(dc)) {
5464f7ec8155SRichard Henderson return true;
5465f7ec8155SRichard Henderson }
5466f7ec8155SRichard Henderson
5467f7ec8155SRichard Henderson gen_op_clear_ieee_excp_and_FTT();
5468f7ec8155SRichard Henderson gen_compare(&cmp, a->cc, a->cond, dc);
5469f7ec8155SRichard Henderson func(dc, &cmp, a->rd, a->rs2);
5470f7ec8155SRichard Henderson return advance_pc(dc);
5471f7ec8155SRichard Henderson }
5472f7ec8155SRichard Henderson
5473f7ec8155SRichard Henderson TRANS(FMOVscc, 64, do_fmovcc, a, false, gen_fmovs)
5474f7ec8155SRichard Henderson TRANS(FMOVdcc, 64, do_fmovcc, a, false, gen_fmovd)
5475f7ec8155SRichard Henderson TRANS(FMOVqcc, 64, do_fmovcc, a, true, gen_fmovq)
5476f7ec8155SRichard Henderson
do_fmovfcc(DisasContext * dc,arg_FMOVsfcc * a,bool is_128,void (* func)(DisasContext *,DisasCompare *,int,int))5477f7ec8155SRichard Henderson static bool do_fmovfcc(DisasContext *dc, arg_FMOVsfcc *a, bool is_128,
5478f7ec8155SRichard Henderson void (*func)(DisasContext *, DisasCompare *, int, int))
5479f7ec8155SRichard Henderson {
5480f7ec8155SRichard Henderson DisasCompare cmp;
5481f7ec8155SRichard Henderson
5482f7ec8155SRichard Henderson if (gen_trap_ifnofpu(dc)) {
5483f7ec8155SRichard Henderson return true;
5484f7ec8155SRichard Henderson }
5485f7ec8155SRichard Henderson if (is_128 && gen_trap_float128(dc)) {
5486f7ec8155SRichard Henderson return true;
5487f7ec8155SRichard Henderson }
5488f7ec8155SRichard Henderson
5489f7ec8155SRichard Henderson gen_op_clear_ieee_excp_and_FTT();
5490f7ec8155SRichard Henderson gen_fcompare(&cmp, a->cc, a->cond);
5491f7ec8155SRichard Henderson func(dc, &cmp, a->rd, a->rs2);
5492f7ec8155SRichard Henderson return advance_pc(dc);
5493f7ec8155SRichard Henderson }
5494f7ec8155SRichard Henderson
5495f7ec8155SRichard Henderson TRANS(FMOVsfcc, 64, do_fmovfcc, a, false, gen_fmovs)
5496f7ec8155SRichard Henderson TRANS(FMOVdfcc, 64, do_fmovfcc, a, false, gen_fmovd)
5497f7ec8155SRichard Henderson TRANS(FMOVqfcc, 64, do_fmovfcc, a, true, gen_fmovq)
5498f7ec8155SRichard Henderson
do_fcmps(DisasContext * dc,arg_FCMPs * a,bool e)549940f9ad21SRichard Henderson static bool do_fcmps(DisasContext *dc, arg_FCMPs *a, bool e)
550040f9ad21SRichard Henderson {
550140f9ad21SRichard Henderson TCGv_i32 src1, src2;
550240f9ad21SRichard Henderson
550340f9ad21SRichard Henderson if (avail_32(dc) && a->cc != 0) {
550440f9ad21SRichard Henderson return false;
550540f9ad21SRichard Henderson }
5506*d2a0c3a7SRichard Henderson if (gen_trap_if_nofpu_fpexception(dc)) {
550740f9ad21SRichard Henderson return true;
550840f9ad21SRichard Henderson }
550940f9ad21SRichard Henderson
551040f9ad21SRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1);
551140f9ad21SRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2);
551240f9ad21SRichard Henderson if (e) {
5513d8c5b92fSRichard Henderson gen_helper_fcmpes(cpu_fcc[a->cc], tcg_env, src1, src2);
551440f9ad21SRichard Henderson } else {
5515d8c5b92fSRichard Henderson gen_helper_fcmps(cpu_fcc[a->cc], tcg_env, src1, src2);
551640f9ad21SRichard Henderson }
551740f9ad21SRichard Henderson return advance_pc(dc);
551840f9ad21SRichard Henderson }
551940f9ad21SRichard Henderson
TRANS(FCMPs,ALL,do_fcmps,a,false)552040f9ad21SRichard Henderson TRANS(FCMPs, ALL, do_fcmps, a, false)
552140f9ad21SRichard Henderson TRANS(FCMPEs, ALL, do_fcmps, a, true)
552240f9ad21SRichard Henderson
552340f9ad21SRichard Henderson static bool do_fcmpd(DisasContext *dc, arg_FCMPd *a, bool e)
552440f9ad21SRichard Henderson {
552540f9ad21SRichard Henderson TCGv_i64 src1, src2;
552640f9ad21SRichard Henderson
552740f9ad21SRichard Henderson if (avail_32(dc) && a->cc != 0) {
552840f9ad21SRichard Henderson return false;
552940f9ad21SRichard Henderson }
5530*d2a0c3a7SRichard Henderson if (gen_trap_if_nofpu_fpexception(dc)) {
553140f9ad21SRichard Henderson return true;
553240f9ad21SRichard Henderson }
553340f9ad21SRichard Henderson
553440f9ad21SRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1);
553540f9ad21SRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2);
553640f9ad21SRichard Henderson if (e) {
5537d8c5b92fSRichard Henderson gen_helper_fcmped(cpu_fcc[a->cc], tcg_env, src1, src2);
553840f9ad21SRichard Henderson } else {
5539d8c5b92fSRichard Henderson gen_helper_fcmpd(cpu_fcc[a->cc], tcg_env, src1, src2);
554040f9ad21SRichard Henderson }
554140f9ad21SRichard Henderson return advance_pc(dc);
554240f9ad21SRichard Henderson }
554340f9ad21SRichard Henderson
TRANS(FCMPd,ALL,do_fcmpd,a,false)554440f9ad21SRichard Henderson TRANS(FCMPd, ALL, do_fcmpd, a, false)
554540f9ad21SRichard Henderson TRANS(FCMPEd, ALL, do_fcmpd, a, true)
554640f9ad21SRichard Henderson
554740f9ad21SRichard Henderson static bool do_fcmpq(DisasContext *dc, arg_FCMPq *a, bool e)
554840f9ad21SRichard Henderson {
5549f3ceafadSRichard Henderson TCGv_i128 src1, src2;
5550f3ceafadSRichard Henderson
555140f9ad21SRichard Henderson if (avail_32(dc) && a->cc != 0) {
555240f9ad21SRichard Henderson return false;
555340f9ad21SRichard Henderson }
5554*d2a0c3a7SRichard Henderson if (gen_trap_if_nofpu_fpexception(dc)) {
555540f9ad21SRichard Henderson return true;
555640f9ad21SRichard Henderson }
555740f9ad21SRichard Henderson if (gen_trap_float128(dc)) {
555840f9ad21SRichard Henderson return true;
555940f9ad21SRichard Henderson }
556040f9ad21SRichard Henderson
5561f3ceafadSRichard Henderson src1 = gen_load_fpr_Q(dc, a->rs1);
5562f3ceafadSRichard Henderson src2 = gen_load_fpr_Q(dc, a->rs2);
556340f9ad21SRichard Henderson if (e) {
5564d8c5b92fSRichard Henderson gen_helper_fcmpeq(cpu_fcc[a->cc], tcg_env, src1, src2);
556540f9ad21SRichard Henderson } else {
5566d8c5b92fSRichard Henderson gen_helper_fcmpq(cpu_fcc[a->cc], tcg_env, src1, src2);
556740f9ad21SRichard Henderson }
556840f9ad21SRichard Henderson return advance_pc(dc);
556940f9ad21SRichard Henderson }
557040f9ad21SRichard Henderson
TRANS(FCMPq,ALL,do_fcmpq,a,false)557140f9ad21SRichard Henderson TRANS(FCMPq, ALL, do_fcmpq, a, false)
557240f9ad21SRichard Henderson TRANS(FCMPEq, ALL, do_fcmpq, a, true)
557340f9ad21SRichard Henderson
55741d3ed3d7SRichard Henderson static bool trans_FLCMPs(DisasContext *dc, arg_FLCMPs *a)
55751d3ed3d7SRichard Henderson {
55761d3ed3d7SRichard Henderson TCGv_i32 src1, src2;
55771d3ed3d7SRichard Henderson
55781d3ed3d7SRichard Henderson if (!avail_VIS3(dc)) {
55791d3ed3d7SRichard Henderson return false;
55801d3ed3d7SRichard Henderson }
55811d3ed3d7SRichard Henderson if (gen_trap_ifnofpu(dc)) {
55821d3ed3d7SRichard Henderson return true;
55831d3ed3d7SRichard Henderson }
55841d3ed3d7SRichard Henderson
55851d3ed3d7SRichard Henderson src1 = gen_load_fpr_F(dc, a->rs1);
55861d3ed3d7SRichard Henderson src2 = gen_load_fpr_F(dc, a->rs2);
55871d3ed3d7SRichard Henderson gen_helper_flcmps(cpu_fcc[a->cc], src1, src2);
55881d3ed3d7SRichard Henderson return advance_pc(dc);
55891d3ed3d7SRichard Henderson }
55901d3ed3d7SRichard Henderson
trans_FLCMPd(DisasContext * dc,arg_FLCMPd * a)55911d3ed3d7SRichard Henderson static bool trans_FLCMPd(DisasContext *dc, arg_FLCMPd *a)
55921d3ed3d7SRichard Henderson {
55931d3ed3d7SRichard Henderson TCGv_i64 src1, src2;
55941d3ed3d7SRichard Henderson
55951d3ed3d7SRichard Henderson if (!avail_VIS3(dc)) {
55961d3ed3d7SRichard Henderson return false;
55971d3ed3d7SRichard Henderson }
55981d3ed3d7SRichard Henderson if (gen_trap_ifnofpu(dc)) {
55991d3ed3d7SRichard Henderson return true;
56001d3ed3d7SRichard Henderson }
56011d3ed3d7SRichard Henderson
56021d3ed3d7SRichard Henderson src1 = gen_load_fpr_D(dc, a->rs1);
56031d3ed3d7SRichard Henderson src2 = gen_load_fpr_D(dc, a->rs2);
56041d3ed3d7SRichard Henderson gen_helper_flcmpd(cpu_fcc[a->cc], src1, src2);
56051d3ed3d7SRichard Henderson return advance_pc(dc);
56061d3ed3d7SRichard Henderson }
56071d3ed3d7SRichard Henderson
do_movf2r(DisasContext * dc,arg_r_r * a,int (* offset)(unsigned int),void (* load)(TCGv,TCGv_ptr,tcg_target_long))560809b157e6SRichard Henderson static bool do_movf2r(DisasContext *dc, arg_r_r *a,
560909b157e6SRichard Henderson int (*offset)(unsigned int),
561009b157e6SRichard Henderson void (*load)(TCGv, TCGv_ptr, tcg_target_long))
561109b157e6SRichard Henderson {
561209b157e6SRichard Henderson TCGv dst;
561309b157e6SRichard Henderson
561409b157e6SRichard Henderson if (gen_trap_ifnofpu(dc)) {
561509b157e6SRichard Henderson return true;
561609b157e6SRichard Henderson }
561709b157e6SRichard Henderson dst = gen_dest_gpr(dc, a->rd);
561809b157e6SRichard Henderson load(dst, tcg_env, offset(a->rs));
561909b157e6SRichard Henderson gen_store_gpr(dc, a->rd, dst);
562009b157e6SRichard Henderson return advance_pc(dc);
562109b157e6SRichard Henderson }
562209b157e6SRichard Henderson
TRANS(MOVsTOsw,VIS3B,do_movf2r,a,gen_offset_fpr_F,tcg_gen_ld32s_tl)562309b157e6SRichard Henderson TRANS(MOVsTOsw, VIS3B, do_movf2r, a, gen_offset_fpr_F, tcg_gen_ld32s_tl)
562409b157e6SRichard Henderson TRANS(MOVsTOuw, VIS3B, do_movf2r, a, gen_offset_fpr_F, tcg_gen_ld32u_tl)
562509b157e6SRichard Henderson TRANS(MOVdTOx, VIS3B, do_movf2r, a, gen_offset_fpr_D, tcg_gen_ld_tl)
562609b157e6SRichard Henderson
562709b157e6SRichard Henderson static bool do_movr2f(DisasContext *dc, arg_r_r *a,
562809b157e6SRichard Henderson int (*offset)(unsigned int),
562909b157e6SRichard Henderson void (*store)(TCGv, TCGv_ptr, tcg_target_long))
563009b157e6SRichard Henderson {
563109b157e6SRichard Henderson TCGv src;
563209b157e6SRichard Henderson
563309b157e6SRichard Henderson if (gen_trap_ifnofpu(dc)) {
563409b157e6SRichard Henderson return true;
563509b157e6SRichard Henderson }
563609b157e6SRichard Henderson src = gen_load_gpr(dc, a->rs);
563709b157e6SRichard Henderson store(src, tcg_env, offset(a->rd));
563809b157e6SRichard Henderson return advance_pc(dc);
563909b157e6SRichard Henderson }
564009b157e6SRichard Henderson
TRANS(MOVwTOs,VIS3B,do_movr2f,a,gen_offset_fpr_F,tcg_gen_st32_tl)564109b157e6SRichard Henderson TRANS(MOVwTOs, VIS3B, do_movr2f, a, gen_offset_fpr_F, tcg_gen_st32_tl)
564209b157e6SRichard Henderson TRANS(MOVxTOd, VIS3B, do_movr2f, a, gen_offset_fpr_D, tcg_gen_st_tl)
564309b157e6SRichard Henderson
56446e61bc94SEmilio G. Cota static void sparc_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
5645fcf5ef2aSThomas Huth {
56466e61bc94SEmilio G. Cota DisasContext *dc = container_of(dcbase, DisasContext, base);
56476e61bc94SEmilio G. Cota int bound;
5648af00be49SEmilio G. Cota
5649af00be49SEmilio G. Cota dc->pc = dc->base.pc_first;
56506e61bc94SEmilio G. Cota dc->npc = (target_ulong)dc->base.tb->cs_base;
56516e61bc94SEmilio G. Cota dc->mem_idx = dc->base.tb->flags & TB_FLAG_MMU_MASK;
565277976769SPhilippe Mathieu-Daudé dc->def = &cpu_env(cs)->def;
56536e61bc94SEmilio G. Cota dc->fpu_enabled = tb_fpu_enabled(dc->base.tb->flags);
56546e61bc94SEmilio G. Cota dc->address_mask_32bit = tb_am_enabled(dc->base.tb->flags);
5655c9b459aaSArtyom Tarasenko #ifndef CONFIG_USER_ONLY
56566e61bc94SEmilio G. Cota dc->supervisor = (dc->base.tb->flags & TB_FLAG_SUPER) != 0;
56575a165e26SRichard Henderson # ifdef TARGET_SPARC64
56585a165e26SRichard Henderson dc->hypervisor = (dc->base.tb->flags & TB_FLAG_HYPER) != 0;
56595a165e26SRichard Henderson # else
56605a165e26SRichard Henderson dc->fsr_qne = (dc->base.tb->flags & TB_FLAG_FSR_QNE) != 0;
56615a165e26SRichard Henderson # endif
5662c9b459aaSArtyom Tarasenko #endif
5663fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
5664fcf5ef2aSThomas Huth dc->fprs_dirty = 0;
56656e61bc94SEmilio G. Cota dc->asi = (dc->base.tb->flags >> TB_FLAG_ASI_SHIFT) & 0xff;
5666fcf5ef2aSThomas Huth #endif
56676e61bc94SEmilio G. Cota /*
56686e61bc94SEmilio G. Cota * if we reach a page boundary, we stop generation so that the
56696e61bc94SEmilio G. Cota * PC of a TT_TFAULT exception is always in the right page
56706e61bc94SEmilio G. Cota */
56716e61bc94SEmilio G. Cota bound = -(dc->base.pc_first | TARGET_PAGE_MASK) / 4;
56726e61bc94SEmilio G. Cota dc->base.max_insns = MIN(dc->base.max_insns, bound);
5673af00be49SEmilio G. Cota }
5674fcf5ef2aSThomas Huth
sparc_tr_tb_start(DisasContextBase * db,CPUState * cs)56756e61bc94SEmilio G. Cota static void sparc_tr_tb_start(DisasContextBase *db, CPUState *cs)
56766e61bc94SEmilio G. Cota {
56776e61bc94SEmilio G. Cota }
56786e61bc94SEmilio G. Cota
sparc_tr_insn_start(DisasContextBase * dcbase,CPUState * cs)56796e61bc94SEmilio G. Cota static void sparc_tr_insn_start(DisasContextBase *dcbase, CPUState *cs)
56806e61bc94SEmilio G. Cota {
56816e61bc94SEmilio G. Cota DisasContext *dc = container_of(dcbase, DisasContext, base);
5682633c4283SRichard Henderson target_ulong npc = dc->npc;
56836e61bc94SEmilio G. Cota
5684633c4283SRichard Henderson if (npc & 3) {
5685633c4283SRichard Henderson switch (npc) {
5686633c4283SRichard Henderson case JUMP_PC:
5687fcf5ef2aSThomas Huth assert(dc->jump_pc[1] == dc->pc + 4);
5688633c4283SRichard Henderson npc = dc->jump_pc[0] | JUMP_PC;
5689633c4283SRichard Henderson break;
5690633c4283SRichard Henderson case DYNAMIC_PC:
5691633c4283SRichard Henderson case DYNAMIC_PC_LOOKUP:
5692633c4283SRichard Henderson npc = DYNAMIC_PC;
5693633c4283SRichard Henderson break;
5694633c4283SRichard Henderson default:
5695633c4283SRichard Henderson g_assert_not_reached();
5696fcf5ef2aSThomas Huth }
56976e61bc94SEmilio G. Cota }
5698633c4283SRichard Henderson tcg_gen_insn_start(dc->pc, npc);
5699633c4283SRichard Henderson }
5700fcf5ef2aSThomas Huth
sparc_tr_translate_insn(DisasContextBase * dcbase,CPUState * cs)57016e61bc94SEmilio G. Cota static void sparc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs)
57026e61bc94SEmilio G. Cota {
57036e61bc94SEmilio G. Cota DisasContext *dc = container_of(dcbase, DisasContext, base);
57046e61bc94SEmilio G. Cota unsigned int insn;
5705fcf5ef2aSThomas Huth
570677976769SPhilippe Mathieu-Daudé insn = translator_ldl(cpu_env(cs), &dc->base, dc->pc);
5707af00be49SEmilio G. Cota dc->base.pc_next += 4;
5708878cc677SRichard Henderson
5709878cc677SRichard Henderson if (!decode(dc, insn)) {
5710ba9c09b4SRichard Henderson gen_exception(dc, TT_ILL_INSN);
5711878cc677SRichard Henderson }
5712fcf5ef2aSThomas Huth
5713af00be49SEmilio G. Cota if (dc->base.is_jmp == DISAS_NORETURN) {
57146e61bc94SEmilio G. Cota return;
5715c5e6ccdfSEmilio G. Cota }
5716af00be49SEmilio G. Cota if (dc->pc != dc->base.pc_next) {
57176e61bc94SEmilio G. Cota dc->base.is_jmp = DISAS_TOO_MANY;
5718af00be49SEmilio G. Cota }
57196e61bc94SEmilio G. Cota }
5720fcf5ef2aSThomas Huth
sparc_tr_tb_stop(DisasContextBase * dcbase,CPUState * cs)57216e61bc94SEmilio G. Cota static void sparc_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)
57226e61bc94SEmilio G. Cota {
57236e61bc94SEmilio G. Cota DisasContext *dc = container_of(dcbase, DisasContext, base);
5724186e7890SRichard Henderson DisasDelayException *e, *e_next;
5725633c4283SRichard Henderson bool may_lookup;
57266e61bc94SEmilio G. Cota
572789527e3aSRichard Henderson finishing_insn(dc);
572889527e3aSRichard Henderson
572946bb0137SMark Cave-Ayland switch (dc->base.is_jmp) {
573046bb0137SMark Cave-Ayland case DISAS_NEXT:
573146bb0137SMark Cave-Ayland case DISAS_TOO_MANY:
5732633c4283SRichard Henderson if (((dc->pc | dc->npc) & 3) == 0) {
5733fcf5ef2aSThomas Huth /* static PC and NPC: we can use direct chaining */
5734fcf5ef2aSThomas Huth gen_goto_tb(dc, 0, dc->pc, dc->npc);
5735633c4283SRichard Henderson break;
5736fcf5ef2aSThomas Huth }
5737633c4283SRichard Henderson
5738930f1865SRichard Henderson may_lookup = true;
5739633c4283SRichard Henderson if (dc->pc & 3) {
5740633c4283SRichard Henderson switch (dc->pc) {
5741633c4283SRichard Henderson case DYNAMIC_PC_LOOKUP:
5742633c4283SRichard Henderson break;
5743633c4283SRichard Henderson case DYNAMIC_PC:
5744633c4283SRichard Henderson may_lookup = false;
5745633c4283SRichard Henderson break;
5746633c4283SRichard Henderson default:
5747633c4283SRichard Henderson g_assert_not_reached();
5748633c4283SRichard Henderson }
5749633c4283SRichard Henderson } else {
5750633c4283SRichard Henderson tcg_gen_movi_tl(cpu_pc, dc->pc);
5751633c4283SRichard Henderson }
5752633c4283SRichard Henderson
5753930f1865SRichard Henderson if (dc->npc & 3) {
5754930f1865SRichard Henderson switch (dc->npc) {
5755930f1865SRichard Henderson case JUMP_PC:
5756930f1865SRichard Henderson gen_generic_branch(dc);
5757930f1865SRichard Henderson break;
5758930f1865SRichard Henderson case DYNAMIC_PC:
5759930f1865SRichard Henderson may_lookup = false;
5760930f1865SRichard Henderson break;
5761930f1865SRichard Henderson case DYNAMIC_PC_LOOKUP:
5762930f1865SRichard Henderson break;
5763930f1865SRichard Henderson default:
5764930f1865SRichard Henderson g_assert_not_reached();
5765930f1865SRichard Henderson }
5766930f1865SRichard Henderson } else {
5767930f1865SRichard Henderson tcg_gen_movi_tl(cpu_npc, dc->npc);
5768930f1865SRichard Henderson }
5769633c4283SRichard Henderson if (may_lookup) {
5770633c4283SRichard Henderson tcg_gen_lookup_and_goto_ptr();
5771633c4283SRichard Henderson } else {
577207ea28b4SRichard Henderson tcg_gen_exit_tb(NULL, 0);
5773fcf5ef2aSThomas Huth }
577446bb0137SMark Cave-Ayland break;
577546bb0137SMark Cave-Ayland
577646bb0137SMark Cave-Ayland case DISAS_NORETURN:
577746bb0137SMark Cave-Ayland break;
577846bb0137SMark Cave-Ayland
577946bb0137SMark Cave-Ayland case DISAS_EXIT:
578046bb0137SMark Cave-Ayland /* Exit TB */
578146bb0137SMark Cave-Ayland save_state(dc);
578246bb0137SMark Cave-Ayland tcg_gen_exit_tb(NULL, 0);
578346bb0137SMark Cave-Ayland break;
578446bb0137SMark Cave-Ayland
578546bb0137SMark Cave-Ayland default:
578646bb0137SMark Cave-Ayland g_assert_not_reached();
5787fcf5ef2aSThomas Huth }
5788186e7890SRichard Henderson
5789186e7890SRichard Henderson for (e = dc->delay_excp_list; e ; e = e_next) {
5790186e7890SRichard Henderson gen_set_label(e->lab);
5791186e7890SRichard Henderson
5792186e7890SRichard Henderson tcg_gen_movi_tl(cpu_pc, e->pc);
5793186e7890SRichard Henderson if (e->npc % 4 == 0) {
5794186e7890SRichard Henderson tcg_gen_movi_tl(cpu_npc, e->npc);
5795186e7890SRichard Henderson }
5796186e7890SRichard Henderson gen_helper_raise_exception(tcg_env, e->excp);
5797186e7890SRichard Henderson
5798186e7890SRichard Henderson e_next = e->next;
5799186e7890SRichard Henderson g_free(e);
5800186e7890SRichard Henderson }
5801fcf5ef2aSThomas Huth }
58026e61bc94SEmilio G. Cota
58036e61bc94SEmilio G. Cota static const TranslatorOps sparc_tr_ops = {
58046e61bc94SEmilio G. Cota .init_disas_context = sparc_tr_init_disas_context,
58056e61bc94SEmilio G. Cota .tb_start = sparc_tr_tb_start,
58066e61bc94SEmilio G. Cota .insn_start = sparc_tr_insn_start,
58076e61bc94SEmilio G. Cota .translate_insn = sparc_tr_translate_insn,
58086e61bc94SEmilio G. Cota .tb_stop = sparc_tr_tb_stop,
58096e61bc94SEmilio G. Cota };
58106e61bc94SEmilio G. Cota
gen_intermediate_code(CPUState * cs,TranslationBlock * tb,int * max_insns,vaddr pc,void * host_pc)5811597f9b2dSRichard Henderson void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int *max_insns,
581232f0c394SAnton Johansson vaddr pc, void *host_pc)
58136e61bc94SEmilio G. Cota {
58146e61bc94SEmilio G. Cota DisasContext dc = {};
58156e61bc94SEmilio G. Cota
5816306c8721SRichard Henderson translator_loop(cs, tb, max_insns, pc, host_pc, &sparc_tr_ops, &dc.base);
5817fcf5ef2aSThomas Huth }
5818fcf5ef2aSThomas Huth
sparc_tcg_init(void)581955c3ceefSRichard Henderson void sparc_tcg_init(void)
5820fcf5ef2aSThomas Huth {
5821fcf5ef2aSThomas Huth static const char gregnames[32][4] = {
5822fcf5ef2aSThomas Huth "g0", "g1", "g2", "g3", "g4", "g5", "g6", "g7",
5823fcf5ef2aSThomas Huth "o0", "o1", "o2", "o3", "o4", "o5", "o6", "o7",
5824fcf5ef2aSThomas Huth "l0", "l1", "l2", "l3", "l4", "l5", "l6", "l7",
5825fcf5ef2aSThomas Huth "i0", "i1", "i2", "i3", "i4", "i5", "i6", "i7",
5826fcf5ef2aSThomas Huth };
5827fcf5ef2aSThomas Huth
5828d8c5b92fSRichard Henderson static const struct { TCGv_i32 *ptr; int off; const char *name; } r32[] = {
5829d8c5b92fSRichard Henderson #ifdef TARGET_SPARC64
5830d8c5b92fSRichard Henderson { &cpu_fprs, offsetof(CPUSPARCState, fprs), "fprs" },
5831d8c5b92fSRichard Henderson { &cpu_fcc[0], offsetof(CPUSPARCState, fcc[0]), "fcc0" },
5832d8c5b92fSRichard Henderson { &cpu_fcc[1], offsetof(CPUSPARCState, fcc[1]), "fcc1" },
5833d8c5b92fSRichard Henderson { &cpu_fcc[2], offsetof(CPUSPARCState, fcc[2]), "fcc2" },
5834d8c5b92fSRichard Henderson { &cpu_fcc[3], offsetof(CPUSPARCState, fcc[3]), "fcc3" },
5835d8c5b92fSRichard Henderson #else
5836d8c5b92fSRichard Henderson { &cpu_fcc[0], offsetof(CPUSPARCState, fcc[0]), "fcc" },
5837d8c5b92fSRichard Henderson #endif
5838d8c5b92fSRichard Henderson };
5839d8c5b92fSRichard Henderson
5840fcf5ef2aSThomas Huth static const struct { TCGv *ptr; int off; const char *name; } rtl[] = {
5841fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
5842fcf5ef2aSThomas Huth { &cpu_gsr, offsetof(CPUSPARCState, gsr), "gsr" },
58432a1905c7SRichard Henderson { &cpu_xcc_Z, offsetof(CPUSPARCState, xcc_Z), "xcc_Z" },
58442a1905c7SRichard Henderson { &cpu_xcc_C, offsetof(CPUSPARCState, xcc_C), "xcc_C" },
5845fcf5ef2aSThomas Huth #endif
58462a1905c7SRichard Henderson { &cpu_cc_N, offsetof(CPUSPARCState, cc_N), "cc_N" },
58472a1905c7SRichard Henderson { &cpu_cc_V, offsetof(CPUSPARCState, cc_V), "cc_V" },
58482a1905c7SRichard Henderson { &cpu_icc_Z, offsetof(CPUSPARCState, icc_Z), "icc_Z" },
58492a1905c7SRichard Henderson { &cpu_icc_C, offsetof(CPUSPARCState, icc_C), "icc_C" },
5850fcf5ef2aSThomas Huth { &cpu_cond, offsetof(CPUSPARCState, cond), "cond" },
5851fcf5ef2aSThomas Huth { &cpu_pc, offsetof(CPUSPARCState, pc), "pc" },
5852fcf5ef2aSThomas Huth { &cpu_npc, offsetof(CPUSPARCState, npc), "npc" },
5853fcf5ef2aSThomas Huth { &cpu_y, offsetof(CPUSPARCState, y), "y" },
5854fcf5ef2aSThomas Huth { &cpu_tbr, offsetof(CPUSPARCState, tbr), "tbr" },
5855fcf5ef2aSThomas Huth };
5856fcf5ef2aSThomas Huth
5857fcf5ef2aSThomas Huth unsigned int i;
5858fcf5ef2aSThomas Huth
5859ad75a51eSRichard Henderson cpu_regwptr = tcg_global_mem_new_ptr(tcg_env,
5860fcf5ef2aSThomas Huth offsetof(CPUSPARCState, regwptr),
5861fcf5ef2aSThomas Huth "regwptr");
5862fcf5ef2aSThomas Huth
5863d8c5b92fSRichard Henderson for (i = 0; i < ARRAY_SIZE(r32); ++i) {
5864d8c5b92fSRichard Henderson *r32[i].ptr = tcg_global_mem_new_i32(tcg_env, r32[i].off, r32[i].name);
5865d8c5b92fSRichard Henderson }
5866d8c5b92fSRichard Henderson
5867fcf5ef2aSThomas Huth for (i = 0; i < ARRAY_SIZE(rtl); ++i) {
5868ad75a51eSRichard Henderson *rtl[i].ptr = tcg_global_mem_new(tcg_env, rtl[i].off, rtl[i].name);
5869fcf5ef2aSThomas Huth }
5870fcf5ef2aSThomas Huth
5871f764718dSRichard Henderson cpu_regs[0] = NULL;
5872fcf5ef2aSThomas Huth for (i = 1; i < 8; ++i) {
5873ad75a51eSRichard Henderson cpu_regs[i] = tcg_global_mem_new(tcg_env,
5874fcf5ef2aSThomas Huth offsetof(CPUSPARCState, gregs[i]),
5875fcf5ef2aSThomas Huth gregnames[i]);
5876fcf5ef2aSThomas Huth }
5877fcf5ef2aSThomas Huth
5878fcf5ef2aSThomas Huth for (i = 8; i < 32; ++i) {
5879fcf5ef2aSThomas Huth cpu_regs[i] = tcg_global_mem_new(cpu_regwptr,
5880fcf5ef2aSThomas Huth (i - 8) * sizeof(target_ulong),
5881fcf5ef2aSThomas Huth gregnames[i]);
5882fcf5ef2aSThomas Huth }
5883fcf5ef2aSThomas Huth }
5884fcf5ef2aSThomas Huth
sparc_restore_state_to_opc(CPUState * cs,const TranslationBlock * tb,const uint64_t * data)5885f36aaa53SRichard Henderson void sparc_restore_state_to_opc(CPUState *cs,
5886f36aaa53SRichard Henderson const TranslationBlock *tb,
5887f36aaa53SRichard Henderson const uint64_t *data)
5888fcf5ef2aSThomas Huth {
588977976769SPhilippe Mathieu-Daudé CPUSPARCState *env = cpu_env(cs);
5890fcf5ef2aSThomas Huth target_ulong pc = data[0];
5891fcf5ef2aSThomas Huth target_ulong npc = data[1];
5892fcf5ef2aSThomas Huth
5893fcf5ef2aSThomas Huth env->pc = pc;
5894fcf5ef2aSThomas Huth if (npc == DYNAMIC_PC) {
5895fcf5ef2aSThomas Huth /* dynamic NPC: already stored */
5896fcf5ef2aSThomas Huth } else if (npc & JUMP_PC) {
5897fcf5ef2aSThomas Huth /* jump PC: use 'cond' and the jump targets of the translation */
5898fcf5ef2aSThomas Huth if (env->cond) {
5899fcf5ef2aSThomas Huth env->npc = npc & ~3;
5900fcf5ef2aSThomas Huth } else {
5901fcf5ef2aSThomas Huth env->npc = pc + 4;
5902fcf5ef2aSThomas Huth }
5903fcf5ef2aSThomas Huth } else {
5904fcf5ef2aSThomas Huth env->npc = npc;
5905fcf5ef2aSThomas Huth }
5906fcf5ef2aSThomas Huth }
5907