xref: /openbmc/qemu/target/sparc/translate.c (revision 388a6465957edea5759e727d5d54898fb4feba91)
1fcf5ef2aSThomas Huth /*
2fcf5ef2aSThomas Huth    SPARC translation
3fcf5ef2aSThomas Huth 
4fcf5ef2aSThomas Huth    Copyright (C) 2003 Thomas M. Ogrisegg <tom@fnord.at>
5fcf5ef2aSThomas Huth    Copyright (C) 2003-2005 Fabrice Bellard
6fcf5ef2aSThomas Huth 
7fcf5ef2aSThomas Huth    This library is free software; you can redistribute it and/or
8fcf5ef2aSThomas Huth    modify it under the terms of the GNU Lesser General Public
9fcf5ef2aSThomas Huth    License as published by the Free Software Foundation; either
105650b549SChetan Pant    version 2.1 of the License, or (at your option) any later version.
11fcf5ef2aSThomas Huth 
12fcf5ef2aSThomas Huth    This library is distributed in the hope that it will be useful,
13fcf5ef2aSThomas Huth    but WITHOUT ANY WARRANTY; without even the implied warranty of
14fcf5ef2aSThomas Huth    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15fcf5ef2aSThomas Huth    Lesser General Public License for more details.
16fcf5ef2aSThomas Huth 
17fcf5ef2aSThomas Huth    You should have received a copy of the GNU Lesser General Public
18fcf5ef2aSThomas Huth    License along with this library; if not, see <http://www.gnu.org/licenses/>.
19fcf5ef2aSThomas Huth  */
20fcf5ef2aSThomas Huth 
21fcf5ef2aSThomas Huth #include "qemu/osdep.h"
22fcf5ef2aSThomas Huth 
23fcf5ef2aSThomas Huth #include "cpu.h"
24fcf5ef2aSThomas Huth #include "disas/disas.h"
25fcf5ef2aSThomas Huth #include "exec/helper-proto.h"
26fcf5ef2aSThomas Huth #include "exec/exec-all.h"
27dcb32f1dSPhilippe Mathieu-Daudé #include "tcg/tcg-op.h"
28fafba1bbSRichard Henderson #include "tcg/tcg-op-gvec.h"
29fcf5ef2aSThomas Huth #include "exec/helper-gen.h"
30c5e6ccdfSEmilio G. Cota #include "exec/translator.h"
31fcf5ef2aSThomas Huth #include "exec/log.h"
32fcf5ef2aSThomas Huth #include "asi.h"
33fcf5ef2aSThomas Huth 
34d53106c9SRichard Henderson #define HELPER_H "helper.h"
35d53106c9SRichard Henderson #include "exec/helper-info.c.inc"
36d53106c9SRichard Henderson #undef  HELPER_H
37fcf5ef2aSThomas Huth 
38668bb9b7SRichard Henderson #ifdef TARGET_SPARC64
39668bb9b7SRichard Henderson # define gen_helper_rdpsr(D, E)                 qemu_build_not_reached()
4086b82fe0SRichard Henderson # define gen_helper_rett(E)                     qemu_build_not_reached()
410faef01bSRichard Henderson # define gen_helper_power_down(E)               qemu_build_not_reached()
4225524734SRichard Henderson # define gen_helper_wrpsr(E, S)                 qemu_build_not_reached()
43668bb9b7SRichard Henderson #else
440faef01bSRichard Henderson # define gen_helper_clear_softint(E, S)         qemu_build_not_reached()
458f75b8a4SRichard Henderson # define gen_helper_done(E)                     qemu_build_not_reached()
46c6d83e4fSRichard Henderson # define gen_helper_fabsd(D, S)                 qemu_build_not_reached()
47e8325dc0SRichard Henderson # define gen_helper_flushw(E)                   qemu_build_not_reached()
48c6d83e4fSRichard Henderson # define gen_helper_fnegd(D, S)                 qemu_build_not_reached()
49af25071cSRichard Henderson # define gen_helper_rdccr(D, E)                 qemu_build_not_reached()
505d617bfbSRichard Henderson # define gen_helper_rdcwp(D, E)                 qemu_build_not_reached()
5125524734SRichard Henderson # define gen_helper_restored(E)                 qemu_build_not_reached()
528f75b8a4SRichard Henderson # define gen_helper_retry(E)                    qemu_build_not_reached()
5325524734SRichard Henderson # define gen_helper_saved(E)                    qemu_build_not_reached()
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()
64f4e18df5SRichard Henderson # define gen_helper_fabsq                ({ qemu_build_not_reached(); NULL; })
65e2fa6bd1SRichard Henderson # define gen_helper_fcmpeq16             ({ qemu_build_not_reached(); NULL; })
66e2fa6bd1SRichard Henderson # define gen_helper_fcmpeq32             ({ qemu_build_not_reached(); NULL; })
67e2fa6bd1SRichard Henderson # define gen_helper_fcmpgt16             ({ qemu_build_not_reached(); NULL; })
68e2fa6bd1SRichard Henderson # define gen_helper_fcmpgt32             ({ qemu_build_not_reached(); NULL; })
69e2fa6bd1SRichard Henderson # define gen_helper_fcmple16             ({ qemu_build_not_reached(); NULL; })
70e2fa6bd1SRichard Henderson # define gen_helper_fcmple32             ({ qemu_build_not_reached(); NULL; })
71e2fa6bd1SRichard Henderson # define gen_helper_fcmpne16             ({ qemu_build_not_reached(); NULL; })
72e2fa6bd1SRichard Henderson # define gen_helper_fcmpne32             ({ qemu_build_not_reached(); NULL; })
738aa418b3SRichard Henderson # define gen_helper_fdtox                ({ qemu_build_not_reached(); NULL; })
74e06c9f83SRichard Henderson # define gen_helper_fexpand              ({ qemu_build_not_reached(); NULL; })
75e06c9f83SRichard Henderson # define gen_helper_fmul8sux16           ({ qemu_build_not_reached(); NULL; })
76e06c9f83SRichard Henderson # define gen_helper_fmul8ulx16           ({ qemu_build_not_reached(); NULL; })
77e06c9f83SRichard Henderson # define gen_helper_fmul8x16al           ({ qemu_build_not_reached(); NULL; })
78e06c9f83SRichard Henderson # define gen_helper_fmul8x16au           ({ qemu_build_not_reached(); NULL; })
79e06c9f83SRichard Henderson # define gen_helper_fmul8x16             ({ qemu_build_not_reached(); NULL; })
80e06c9f83SRichard Henderson # define gen_helper_fmuld8sux16          ({ qemu_build_not_reached(); NULL; })
81e06c9f83SRichard Henderson # define gen_helper_fmuld8ulx16          ({ qemu_build_not_reached(); NULL; })
82f4e18df5SRichard Henderson # define gen_helper_fnegq                ({ qemu_build_not_reached(); NULL; })
83e06c9f83SRichard Henderson # define gen_helper_fpmerge              ({ qemu_build_not_reached(); NULL; })
841617586fSRichard Henderson # define gen_helper_fqtox                ({ qemu_build_not_reached(); NULL; })
85199d43efSRichard Henderson # define gen_helper_fstox                ({ qemu_build_not_reached(); NULL; })
868aa418b3SRichard Henderson # define gen_helper_fxtod                ({ qemu_build_not_reached(); NULL; })
877b8e3e1aSRichard Henderson # define gen_helper_fxtoq                ({ qemu_build_not_reached(); NULL; })
88f4e18df5SRichard Henderson # define gen_helper_fxtos                ({ qemu_build_not_reached(); NULL; })
89afb04344SRichard Henderson # define gen_helper_pdist                ({ qemu_build_not_reached(); NULL; })
90da681406SRichard Henderson # define FSR_LDXFSR_MASK                        0
91da681406SRichard Henderson # define FSR_LDXFSR_OLDMASK                     0
92668bb9b7SRichard Henderson # define MAXTL_MASK                             0
93af25071cSRichard Henderson #endif
94af25071cSRichard Henderson 
95633c4283SRichard Henderson /* Dynamic PC, must exit to main loop. */
96633c4283SRichard Henderson #define DYNAMIC_PC         1
97633c4283SRichard Henderson /* Dynamic PC, one of two values according to jump_pc[T2]. */
98633c4283SRichard Henderson #define JUMP_PC            2
99633c4283SRichard Henderson /* Dynamic PC, may lookup next TB. */
100633c4283SRichard Henderson #define DYNAMIC_PC_LOOKUP  3
101fcf5ef2aSThomas Huth 
10246bb0137SMark Cave-Ayland #define DISAS_EXIT  DISAS_TARGET_0
10346bb0137SMark Cave-Ayland 
104fcf5ef2aSThomas Huth /* global register indexes */
105fcf5ef2aSThomas Huth static TCGv_ptr cpu_regwptr;
106fcf5ef2aSThomas Huth static TCGv cpu_fsr, cpu_pc, cpu_npc;
107fcf5ef2aSThomas Huth static TCGv cpu_regs[32];
108fcf5ef2aSThomas Huth static TCGv cpu_y;
109fcf5ef2aSThomas Huth static TCGv cpu_tbr;
110fcf5ef2aSThomas Huth static TCGv cpu_cond;
1112a1905c7SRichard Henderson static TCGv cpu_cc_N;
1122a1905c7SRichard Henderson static TCGv cpu_cc_V;
1132a1905c7SRichard Henderson static TCGv cpu_icc_Z;
1142a1905c7SRichard Henderson static TCGv cpu_icc_C;
115fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
1162a1905c7SRichard Henderson static TCGv cpu_xcc_Z;
1172a1905c7SRichard Henderson static TCGv cpu_xcc_C;
1182a1905c7SRichard Henderson static TCGv_i32 cpu_fprs;
119fcf5ef2aSThomas Huth static TCGv cpu_gsr;
120fcf5ef2aSThomas Huth #else
121af25071cSRichard Henderson # define cpu_fprs               ({ qemu_build_not_reached(); (TCGv)NULL; })
122af25071cSRichard Henderson # define cpu_gsr                ({ qemu_build_not_reached(); (TCGv)NULL; })
123fcf5ef2aSThomas Huth #endif
1242a1905c7SRichard Henderson 
1252a1905c7SRichard Henderson #ifdef TARGET_SPARC64
1262a1905c7SRichard Henderson #define cpu_cc_Z  cpu_xcc_Z
1272a1905c7SRichard Henderson #define cpu_cc_C  cpu_xcc_C
1282a1905c7SRichard Henderson #else
1292a1905c7SRichard Henderson #define cpu_cc_Z  cpu_icc_Z
1302a1905c7SRichard Henderson #define cpu_cc_C  cpu_icc_C
1312a1905c7SRichard Henderson #define cpu_xcc_Z ({ qemu_build_not_reached(); NULL; })
1322a1905c7SRichard Henderson #define cpu_xcc_C ({ qemu_build_not_reached(); NULL; })
1332a1905c7SRichard Henderson #endif
1342a1905c7SRichard Henderson 
135fcf5ef2aSThomas Huth /* Floating point registers */
136fcf5ef2aSThomas Huth static TCGv_i64 cpu_fpr[TARGET_DPREGS];
137fcf5ef2aSThomas Huth 
138af25071cSRichard Henderson #define env_field_offsetof(X)     offsetof(CPUSPARCState, X)
139af25071cSRichard Henderson #ifdef TARGET_SPARC64
140cd6269f7SRichard Henderson # define env32_field_offsetof(X)  ({ qemu_build_not_reached(); 0; })
141af25071cSRichard Henderson # define env64_field_offsetof(X)  env_field_offsetof(X)
142af25071cSRichard Henderson #else
143cd6269f7SRichard Henderson # define env32_field_offsetof(X)  env_field_offsetof(X)
144af25071cSRichard Henderson # define env64_field_offsetof(X)  ({ qemu_build_not_reached(); 0; })
145af25071cSRichard Henderson #endif
146af25071cSRichard Henderson 
147533f042fSRichard Henderson typedef struct DisasCompare {
148533f042fSRichard Henderson     TCGCond cond;
149533f042fSRichard Henderson     TCGv c1;
150533f042fSRichard Henderson     int c2;
151533f042fSRichard Henderson } DisasCompare;
152533f042fSRichard Henderson 
153186e7890SRichard Henderson typedef struct DisasDelayException {
154186e7890SRichard Henderson     struct DisasDelayException *next;
155186e7890SRichard Henderson     TCGLabel *lab;
156186e7890SRichard Henderson     TCGv_i32 excp;
157186e7890SRichard Henderson     /* Saved state at parent insn. */
158186e7890SRichard Henderson     target_ulong pc;
159186e7890SRichard Henderson     target_ulong npc;
160186e7890SRichard Henderson } DisasDelayException;
161186e7890SRichard Henderson 
162fcf5ef2aSThomas Huth typedef struct DisasContext {
163af00be49SEmilio G. Cota     DisasContextBase base;
164fcf5ef2aSThomas Huth     target_ulong pc;    /* current Program Counter: integer or DYNAMIC_PC */
165fcf5ef2aSThomas Huth     target_ulong npc;   /* next PC: integer or DYNAMIC_PC or JUMP_PC */
166533f042fSRichard Henderson 
167533f042fSRichard Henderson     /* Used when JUMP_PC value is used. */
168533f042fSRichard Henderson     DisasCompare jump;
169533f042fSRichard Henderson     target_ulong jump_pc[2];
170533f042fSRichard Henderson 
171fcf5ef2aSThomas Huth     int mem_idx;
17289527e3aSRichard Henderson     bool cpu_cond_live;
173c9b459aaSArtyom Tarasenko     bool fpu_enabled;
174c9b459aaSArtyom Tarasenko     bool address_mask_32bit;
175c9b459aaSArtyom Tarasenko #ifndef CONFIG_USER_ONLY
176c9b459aaSArtyom Tarasenko     bool supervisor;
177c9b459aaSArtyom Tarasenko #ifdef TARGET_SPARC64
178c9b459aaSArtyom Tarasenko     bool hypervisor;
179c9b459aaSArtyom Tarasenko #endif
180c9b459aaSArtyom Tarasenko #endif
181c9b459aaSArtyom Tarasenko 
182fcf5ef2aSThomas Huth     sparc_def_t *def;
183fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
184fcf5ef2aSThomas Huth     int fprs_dirty;
185fcf5ef2aSThomas Huth     int asi;
186fcf5ef2aSThomas Huth #endif
187186e7890SRichard Henderson     DisasDelayException *delay_excp_list;
188fcf5ef2aSThomas Huth } DisasContext;
189fcf5ef2aSThomas Huth 
190fcf5ef2aSThomas Huth // This function uses non-native bit order
191fcf5ef2aSThomas Huth #define GET_FIELD(X, FROM, TO)                                  \
192fcf5ef2aSThomas Huth     ((X) >> (31 - (TO)) & ((1 << ((TO) - (FROM) + 1)) - 1))
193fcf5ef2aSThomas Huth 
194fcf5ef2aSThomas Huth // This function uses the order in the manuals, i.e. bit 0 is 2^0
195fcf5ef2aSThomas Huth #define GET_FIELD_SP(X, FROM, TO)               \
196fcf5ef2aSThomas Huth     GET_FIELD(X, 31 - (TO), 31 - (FROM))
197fcf5ef2aSThomas Huth 
198fcf5ef2aSThomas Huth #define GET_FIELDs(x,a,b) sign_extend (GET_FIELD(x,a,b), (b) - (a) + 1)
199fcf5ef2aSThomas Huth #define GET_FIELD_SPs(x,a,b) sign_extend (GET_FIELD_SP(x,a,b), ((b) - (a) + 1))
200fcf5ef2aSThomas Huth 
201fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
202fcf5ef2aSThomas Huth #define DFPREG(r) (((r & 1) << 5) | (r & 0x1e))
203fcf5ef2aSThomas Huth #define QFPREG(r) (((r & 1) << 5) | (r & 0x1c))
204fcf5ef2aSThomas Huth #else
205fcf5ef2aSThomas Huth #define DFPREG(r) (r & 0x1e)
206fcf5ef2aSThomas Huth #define QFPREG(r) (r & 0x1c)
207fcf5ef2aSThomas Huth #endif
208fcf5ef2aSThomas Huth 
209fcf5ef2aSThomas Huth #define UA2005_HTRAP_MASK 0xff
210fcf5ef2aSThomas Huth #define V8_TRAP_MASK 0x7f
211fcf5ef2aSThomas Huth 
212fcf5ef2aSThomas Huth #define IS_IMM (insn & (1<<13))
213fcf5ef2aSThomas Huth 
2140c2e96c1SRichard Henderson static void gen_update_fprs_dirty(DisasContext *dc, int rd)
215fcf5ef2aSThomas Huth {
216fcf5ef2aSThomas Huth #if defined(TARGET_SPARC64)
217fcf5ef2aSThomas Huth     int bit = (rd < 32) ? 1 : 2;
218fcf5ef2aSThomas Huth     /* If we know we've already set this bit within the TB,
219fcf5ef2aSThomas Huth        we can avoid setting it again.  */
220fcf5ef2aSThomas Huth     if (!(dc->fprs_dirty & bit)) {
221fcf5ef2aSThomas Huth         dc->fprs_dirty |= bit;
222fcf5ef2aSThomas Huth         tcg_gen_ori_i32(cpu_fprs, cpu_fprs, bit);
223fcf5ef2aSThomas Huth     }
224fcf5ef2aSThomas Huth #endif
225fcf5ef2aSThomas Huth }
226fcf5ef2aSThomas Huth 
227fcf5ef2aSThomas Huth /* floating point registers moves */
228fcf5ef2aSThomas Huth static TCGv_i32 gen_load_fpr_F(DisasContext *dc, unsigned int src)
229fcf5ef2aSThomas Huth {
23036ab4623SRichard Henderson     TCGv_i32 ret = tcg_temp_new_i32();
231dc41aa7dSRichard Henderson     if (src & 1) {
232dc41aa7dSRichard Henderson         tcg_gen_extrl_i64_i32(ret, cpu_fpr[src / 2]);
233dc41aa7dSRichard Henderson     } else {
234dc41aa7dSRichard Henderson         tcg_gen_extrh_i64_i32(ret, cpu_fpr[src / 2]);
235fcf5ef2aSThomas Huth     }
236dc41aa7dSRichard Henderson     return ret;
237fcf5ef2aSThomas Huth }
238fcf5ef2aSThomas Huth 
239fcf5ef2aSThomas Huth static void gen_store_fpr_F(DisasContext *dc, unsigned int dst, TCGv_i32 v)
240fcf5ef2aSThomas Huth {
2418e7bbc75SRichard Henderson     TCGv_i64 t = tcg_temp_new_i64();
2428e7bbc75SRichard Henderson 
2438e7bbc75SRichard Henderson     tcg_gen_extu_i32_i64(t, v);
244fcf5ef2aSThomas Huth     tcg_gen_deposit_i64(cpu_fpr[dst / 2], cpu_fpr[dst / 2], t,
245fcf5ef2aSThomas Huth                         (dst & 1 ? 0 : 32), 32);
246fcf5ef2aSThomas Huth     gen_update_fprs_dirty(dc, dst);
247fcf5ef2aSThomas Huth }
248fcf5ef2aSThomas Huth 
249fcf5ef2aSThomas Huth static TCGv_i64 gen_load_fpr_D(DisasContext *dc, unsigned int src)
250fcf5ef2aSThomas Huth {
251fcf5ef2aSThomas Huth     src = DFPREG(src);
252fcf5ef2aSThomas Huth     return cpu_fpr[src / 2];
253fcf5ef2aSThomas Huth }
254fcf5ef2aSThomas Huth 
255fcf5ef2aSThomas Huth static void gen_store_fpr_D(DisasContext *dc, unsigned int dst, TCGv_i64 v)
256fcf5ef2aSThomas Huth {
257fcf5ef2aSThomas Huth     dst = DFPREG(dst);
258fcf5ef2aSThomas Huth     tcg_gen_mov_i64(cpu_fpr[dst / 2], v);
259fcf5ef2aSThomas Huth     gen_update_fprs_dirty(dc, dst);
260fcf5ef2aSThomas Huth }
261fcf5ef2aSThomas Huth 
262fcf5ef2aSThomas Huth static TCGv_i64 gen_dest_fpr_D(DisasContext *dc, unsigned int dst)
263fcf5ef2aSThomas Huth {
264fcf5ef2aSThomas Huth     return cpu_fpr[DFPREG(dst) / 2];
265fcf5ef2aSThomas Huth }
266fcf5ef2aSThomas Huth 
267fcf5ef2aSThomas Huth static void gen_op_load_fpr_QT0(unsigned int src)
268fcf5ef2aSThomas Huth {
269ad75a51eSRichard Henderson     tcg_gen_st_i64(cpu_fpr[src / 2], tcg_env, offsetof(CPUSPARCState, qt0) +
270fcf5ef2aSThomas Huth                    offsetof(CPU_QuadU, ll.upper));
271ad75a51eSRichard Henderson     tcg_gen_st_i64(cpu_fpr[src/2 + 1], tcg_env, offsetof(CPUSPARCState, qt0) +
272fcf5ef2aSThomas Huth                    offsetof(CPU_QuadU, ll.lower));
273fcf5ef2aSThomas Huth }
274fcf5ef2aSThomas Huth 
275fcf5ef2aSThomas Huth static void gen_op_load_fpr_QT1(unsigned int src)
276fcf5ef2aSThomas Huth {
277ad75a51eSRichard Henderson     tcg_gen_st_i64(cpu_fpr[src / 2], tcg_env, offsetof(CPUSPARCState, qt1) +
278fcf5ef2aSThomas Huth                    offsetof(CPU_QuadU, ll.upper));
279ad75a51eSRichard Henderson     tcg_gen_st_i64(cpu_fpr[src/2 + 1], tcg_env, offsetof(CPUSPARCState, qt1) +
280fcf5ef2aSThomas Huth                    offsetof(CPU_QuadU, ll.lower));
281fcf5ef2aSThomas Huth }
282fcf5ef2aSThomas Huth 
283fcf5ef2aSThomas Huth static void gen_op_store_QT0_fpr(unsigned int dst)
284fcf5ef2aSThomas Huth {
285ad75a51eSRichard Henderson     tcg_gen_ld_i64(cpu_fpr[dst / 2], tcg_env, offsetof(CPUSPARCState, qt0) +
286fcf5ef2aSThomas Huth                    offsetof(CPU_QuadU, ll.upper));
287ad75a51eSRichard Henderson     tcg_gen_ld_i64(cpu_fpr[dst/2 + 1], tcg_env, offsetof(CPUSPARCState, qt0) +
288fcf5ef2aSThomas Huth                    offsetof(CPU_QuadU, ll.lower));
289fcf5ef2aSThomas Huth }
290fcf5ef2aSThomas Huth 
291fcf5ef2aSThomas Huth /* moves */
292fcf5ef2aSThomas Huth #ifdef CONFIG_USER_ONLY
293fcf5ef2aSThomas Huth #define supervisor(dc) 0
294fcf5ef2aSThomas Huth #define hypervisor(dc) 0
295fcf5ef2aSThomas Huth #else
296fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
297c9b459aaSArtyom Tarasenko #define hypervisor(dc) (dc->hypervisor)
298c9b459aaSArtyom Tarasenko #define supervisor(dc) (dc->supervisor | dc->hypervisor)
299fcf5ef2aSThomas Huth #else
300c9b459aaSArtyom Tarasenko #define supervisor(dc) (dc->supervisor)
301668bb9b7SRichard Henderson #define hypervisor(dc) 0
302fcf5ef2aSThomas Huth #endif
303fcf5ef2aSThomas Huth #endif
304fcf5ef2aSThomas Huth 
305b1bc09eaSRichard Henderson #if !defined(TARGET_SPARC64)
306b1bc09eaSRichard Henderson # define AM_CHECK(dc)  false
307b1bc09eaSRichard Henderson #elif defined(TARGET_ABI32)
308b1bc09eaSRichard Henderson # define AM_CHECK(dc)  true
309b1bc09eaSRichard Henderson #elif defined(CONFIG_USER_ONLY)
310b1bc09eaSRichard Henderson # define AM_CHECK(dc)  false
311fcf5ef2aSThomas Huth #else
312b1bc09eaSRichard Henderson # define AM_CHECK(dc)  ((dc)->address_mask_32bit)
313fcf5ef2aSThomas Huth #endif
314fcf5ef2aSThomas Huth 
3150c2e96c1SRichard Henderson static void gen_address_mask(DisasContext *dc, TCGv addr)
316fcf5ef2aSThomas Huth {
317b1bc09eaSRichard Henderson     if (AM_CHECK(dc)) {
318fcf5ef2aSThomas Huth         tcg_gen_andi_tl(addr, addr, 0xffffffffULL);
319b1bc09eaSRichard Henderson     }
320fcf5ef2aSThomas Huth }
321fcf5ef2aSThomas Huth 
32223ada1b1SRichard Henderson static target_ulong address_mask_i(DisasContext *dc, target_ulong addr)
32323ada1b1SRichard Henderson {
32423ada1b1SRichard Henderson     return AM_CHECK(dc) ? (uint32_t)addr : addr;
32523ada1b1SRichard Henderson }
32623ada1b1SRichard Henderson 
3270c2e96c1SRichard Henderson static TCGv gen_load_gpr(DisasContext *dc, int reg)
328fcf5ef2aSThomas Huth {
329fcf5ef2aSThomas Huth     if (reg > 0) {
330fcf5ef2aSThomas Huth         assert(reg < 32);
331fcf5ef2aSThomas Huth         return cpu_regs[reg];
332fcf5ef2aSThomas Huth     } else {
33352123f14SRichard Henderson         TCGv t = tcg_temp_new();
334fcf5ef2aSThomas Huth         tcg_gen_movi_tl(t, 0);
335fcf5ef2aSThomas Huth         return t;
336fcf5ef2aSThomas Huth     }
337fcf5ef2aSThomas Huth }
338fcf5ef2aSThomas Huth 
3390c2e96c1SRichard Henderson static void gen_store_gpr(DisasContext *dc, int reg, TCGv v)
340fcf5ef2aSThomas Huth {
341fcf5ef2aSThomas Huth     if (reg > 0) {
342fcf5ef2aSThomas Huth         assert(reg < 32);
343fcf5ef2aSThomas Huth         tcg_gen_mov_tl(cpu_regs[reg], v);
344fcf5ef2aSThomas Huth     }
345fcf5ef2aSThomas Huth }
346fcf5ef2aSThomas Huth 
3470c2e96c1SRichard Henderson static TCGv gen_dest_gpr(DisasContext *dc, int reg)
348fcf5ef2aSThomas Huth {
349fcf5ef2aSThomas Huth     if (reg > 0) {
350fcf5ef2aSThomas Huth         assert(reg < 32);
351fcf5ef2aSThomas Huth         return cpu_regs[reg];
352fcf5ef2aSThomas Huth     } else {
35352123f14SRichard Henderson         return tcg_temp_new();
354fcf5ef2aSThomas Huth     }
355fcf5ef2aSThomas Huth }
356fcf5ef2aSThomas Huth 
3575645aa2eSRichard Henderson static bool use_goto_tb(DisasContext *s, target_ulong pc, target_ulong npc)
358fcf5ef2aSThomas Huth {
3595645aa2eSRichard Henderson     return translator_use_goto_tb(&s->base, pc) &&
3605645aa2eSRichard Henderson            translator_use_goto_tb(&s->base, npc);
361fcf5ef2aSThomas Huth }
362fcf5ef2aSThomas Huth 
3635645aa2eSRichard Henderson static void gen_goto_tb(DisasContext *s, int tb_num,
364fcf5ef2aSThomas Huth                         target_ulong pc, target_ulong npc)
365fcf5ef2aSThomas Huth {
366fcf5ef2aSThomas Huth     if (use_goto_tb(s, pc, npc))  {
367fcf5ef2aSThomas Huth         /* jump to same page: we can use a direct jump */
368fcf5ef2aSThomas Huth         tcg_gen_goto_tb(tb_num);
369fcf5ef2aSThomas Huth         tcg_gen_movi_tl(cpu_pc, pc);
370fcf5ef2aSThomas Huth         tcg_gen_movi_tl(cpu_npc, npc);
37107ea28b4SRichard Henderson         tcg_gen_exit_tb(s->base.tb, tb_num);
372fcf5ef2aSThomas Huth     } else {
373f67ccb2fSRichard Henderson         /* jump to another page: we can use an indirect jump */
374fcf5ef2aSThomas Huth         tcg_gen_movi_tl(cpu_pc, pc);
375fcf5ef2aSThomas Huth         tcg_gen_movi_tl(cpu_npc, npc);
376f67ccb2fSRichard Henderson         tcg_gen_lookup_and_goto_ptr();
377fcf5ef2aSThomas Huth     }
378fcf5ef2aSThomas Huth }
379fcf5ef2aSThomas Huth 
380b989ce73SRichard Henderson static TCGv gen_carry32(void)
381fcf5ef2aSThomas Huth {
382b989ce73SRichard Henderson     if (TARGET_LONG_BITS == 64) {
383b989ce73SRichard Henderson         TCGv t = tcg_temp_new();
384b989ce73SRichard Henderson         tcg_gen_extract_tl(t, cpu_icc_C, 32, 1);
385b989ce73SRichard Henderson         return t;
386b989ce73SRichard Henderson     }
387b989ce73SRichard Henderson     return cpu_icc_C;
388fcf5ef2aSThomas Huth }
389fcf5ef2aSThomas Huth 
390b989ce73SRichard Henderson static void gen_op_addcc_int(TCGv dst, TCGv src1, TCGv src2, TCGv cin)
391fcf5ef2aSThomas Huth {
392b989ce73SRichard Henderson     TCGv z = tcg_constant_tl(0);
393fcf5ef2aSThomas Huth 
394b989ce73SRichard Henderson     if (cin) {
395b989ce73SRichard Henderson         tcg_gen_add2_tl(cpu_cc_N, cpu_cc_C, src1, z, cin, z);
396b989ce73SRichard Henderson         tcg_gen_add2_tl(cpu_cc_N, cpu_cc_C, cpu_cc_N, cpu_cc_C, src2, z);
397b989ce73SRichard Henderson     } else {
398b989ce73SRichard Henderson         tcg_gen_add2_tl(cpu_cc_N, cpu_cc_C, src1, z, src2, z);
399b989ce73SRichard Henderson     }
400b989ce73SRichard Henderson     tcg_gen_xor_tl(cpu_cc_Z, src1, src2);
401b989ce73SRichard Henderson     tcg_gen_xor_tl(cpu_cc_V, cpu_cc_N, src2);
402b989ce73SRichard Henderson     tcg_gen_andc_tl(cpu_cc_V, cpu_cc_V, cpu_cc_Z);
403b989ce73SRichard Henderson     if (TARGET_LONG_BITS == 64) {
404b989ce73SRichard Henderson         /*
405b989ce73SRichard Henderson          * Carry-in to bit 32 is result ^ src1 ^ src2.
406b989ce73SRichard Henderson          * We already have the src xor term in Z, from computation of V.
407b989ce73SRichard Henderson          */
408b989ce73SRichard Henderson         tcg_gen_xor_tl(cpu_icc_C, cpu_cc_Z, cpu_cc_N);
409b989ce73SRichard Henderson         tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N);
410b989ce73SRichard Henderson     }
411b989ce73SRichard Henderson     tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N);
412b989ce73SRichard Henderson     tcg_gen_mov_tl(dst, cpu_cc_N);
413b989ce73SRichard Henderson }
414fcf5ef2aSThomas Huth 
415b989ce73SRichard Henderson static void gen_op_addcc(TCGv dst, TCGv src1, TCGv src2)
416b989ce73SRichard Henderson {
417b989ce73SRichard Henderson     gen_op_addcc_int(dst, src1, src2, NULL);
418b989ce73SRichard Henderson }
419fcf5ef2aSThomas Huth 
420b989ce73SRichard Henderson static void gen_op_taddcc(TCGv dst, TCGv src1, TCGv src2)
421b989ce73SRichard Henderson {
422b989ce73SRichard Henderson     TCGv t = tcg_temp_new();
423b989ce73SRichard Henderson 
424b989ce73SRichard Henderson     /* Save the tag bits around modification of dst. */
425b989ce73SRichard Henderson     tcg_gen_or_tl(t, src1, src2);
426b989ce73SRichard Henderson 
427b989ce73SRichard Henderson     gen_op_addcc(dst, src1, src2);
428b989ce73SRichard Henderson 
429b989ce73SRichard Henderson     /* Incorprate tag bits into icc.V */
430b989ce73SRichard Henderson     tcg_gen_andi_tl(t, t, 3);
431b989ce73SRichard Henderson     tcg_gen_neg_tl(t, t);
432b989ce73SRichard Henderson     tcg_gen_ext32u_tl(t, t);
433b989ce73SRichard Henderson     tcg_gen_or_tl(cpu_cc_V, cpu_cc_V, t);
434b989ce73SRichard Henderson }
435b989ce73SRichard Henderson 
436b989ce73SRichard Henderson static void gen_op_addc(TCGv dst, TCGv src1, TCGv src2)
437b989ce73SRichard Henderson {
438b989ce73SRichard Henderson     tcg_gen_add_tl(dst, src1, src2);
439b989ce73SRichard Henderson     tcg_gen_add_tl(dst, dst, gen_carry32());
440b989ce73SRichard Henderson }
441b989ce73SRichard Henderson 
442b989ce73SRichard Henderson static void gen_op_addccc(TCGv dst, TCGv src1, TCGv src2)
443b989ce73SRichard Henderson {
444b989ce73SRichard Henderson     gen_op_addcc_int(dst, src1, src2, gen_carry32());
445fcf5ef2aSThomas Huth }
446fcf5ef2aSThomas Huth 
447f828df74SRichard Henderson static void gen_op_subcc_int(TCGv dst, TCGv src1, TCGv src2, TCGv cin)
448fcf5ef2aSThomas Huth {
449f828df74SRichard Henderson     TCGv z = tcg_constant_tl(0);
450fcf5ef2aSThomas Huth 
451f828df74SRichard Henderson     if (cin) {
452f828df74SRichard Henderson         tcg_gen_sub2_tl(cpu_cc_N, cpu_cc_C, src1, z, cin, z);
453f828df74SRichard Henderson         tcg_gen_sub2_tl(cpu_cc_N, cpu_cc_C, cpu_cc_N, cpu_cc_C, src2, z);
454f828df74SRichard Henderson     } else {
455f828df74SRichard Henderson         tcg_gen_sub2_tl(cpu_cc_N, cpu_cc_C, src1, z, src2, z);
456f828df74SRichard Henderson     }
457f828df74SRichard Henderson     tcg_gen_neg_tl(cpu_cc_C, cpu_cc_C);
458f828df74SRichard Henderson     tcg_gen_xor_tl(cpu_cc_Z, src1, src2);
459f828df74SRichard Henderson     tcg_gen_xor_tl(cpu_cc_V, cpu_cc_N, src1);
460f828df74SRichard Henderson     tcg_gen_and_tl(cpu_cc_V, cpu_cc_V, cpu_cc_Z);
461f828df74SRichard Henderson #ifdef TARGET_SPARC64
462f828df74SRichard Henderson     tcg_gen_xor_tl(cpu_icc_C, cpu_cc_Z, cpu_cc_N);
463f828df74SRichard Henderson     tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N);
464fcf5ef2aSThomas Huth #endif
465f828df74SRichard Henderson     tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N);
466f828df74SRichard Henderson     tcg_gen_mov_tl(dst, cpu_cc_N);
467fcf5ef2aSThomas Huth }
468fcf5ef2aSThomas Huth 
469f828df74SRichard Henderson static void gen_op_subcc(TCGv dst, TCGv src1, TCGv src2)
470fcf5ef2aSThomas Huth {
471f828df74SRichard Henderson     gen_op_subcc_int(dst, src1, src2, NULL);
472fcf5ef2aSThomas Huth }
473fcf5ef2aSThomas Huth 
474f828df74SRichard Henderson static void gen_op_tsubcc(TCGv dst, TCGv src1, TCGv src2)
475fcf5ef2aSThomas Huth {
476f828df74SRichard Henderson     TCGv t = tcg_temp_new();
477fcf5ef2aSThomas Huth 
478f828df74SRichard Henderson     /* Save the tag bits around modification of dst. */
479f828df74SRichard Henderson     tcg_gen_or_tl(t, src1, src2);
480fcf5ef2aSThomas Huth 
481f828df74SRichard Henderson     gen_op_subcc(dst, src1, src2);
482f828df74SRichard Henderson 
483f828df74SRichard Henderson     /* Incorprate tag bits into icc.V */
484f828df74SRichard Henderson     tcg_gen_andi_tl(t, t, 3);
485f828df74SRichard Henderson     tcg_gen_neg_tl(t, t);
486f828df74SRichard Henderson     tcg_gen_ext32u_tl(t, t);
487f828df74SRichard Henderson     tcg_gen_or_tl(cpu_cc_V, cpu_cc_V, t);
488f828df74SRichard Henderson }
489f828df74SRichard Henderson 
490f828df74SRichard Henderson static void gen_op_subc(TCGv dst, TCGv src1, TCGv src2)
491f828df74SRichard Henderson {
492fcf5ef2aSThomas Huth     tcg_gen_sub_tl(dst, src1, src2);
493f828df74SRichard Henderson     tcg_gen_sub_tl(dst, dst, gen_carry32());
494fcf5ef2aSThomas Huth }
495fcf5ef2aSThomas Huth 
496f828df74SRichard Henderson static void gen_op_subccc(TCGv dst, TCGv src1, TCGv src2)
497dfebb950SRichard Henderson {
498f828df74SRichard Henderson     gen_op_subcc_int(dst, src1, src2, gen_carry32());
499dfebb950SRichard Henderson }
500dfebb950SRichard Henderson 
5010c2e96c1SRichard Henderson static void gen_op_mulscc(TCGv dst, TCGv src1, TCGv src2)
502fcf5ef2aSThomas Huth {
503b989ce73SRichard Henderson     TCGv zero = tcg_constant_tl(0);
504b989ce73SRichard Henderson     TCGv t_src1 = tcg_temp_new();
505b989ce73SRichard Henderson     TCGv t_src2 = tcg_temp_new();
506b989ce73SRichard Henderson     TCGv t0 = tcg_temp_new();
507fcf5ef2aSThomas Huth 
508b989ce73SRichard Henderson     tcg_gen_ext32u_tl(t_src1, src1);
509b989ce73SRichard Henderson     tcg_gen_ext32u_tl(t_src2, src2);
510fcf5ef2aSThomas Huth 
511b989ce73SRichard Henderson     /*
512b989ce73SRichard Henderson      * if (!(env->y & 1))
513b989ce73SRichard Henderson      *   src2 = 0;
514fcf5ef2aSThomas Huth      */
515b989ce73SRichard Henderson     tcg_gen_andi_tl(t0, cpu_y, 0x1);
516b989ce73SRichard Henderson     tcg_gen_movcond_tl(TCG_COND_EQ, t_src2, t0, zero, zero, t_src2);
517fcf5ef2aSThomas Huth 
518b989ce73SRichard Henderson     /*
519b989ce73SRichard Henderson      * b2 = src1 & 1;
520b989ce73SRichard Henderson      * y = (b2 << 31) | (y >> 1);
521b989ce73SRichard Henderson      */
5220b1183e3SPhilippe Mathieu-Daudé     tcg_gen_extract_tl(t0, cpu_y, 1, 31);
523b989ce73SRichard Henderson     tcg_gen_deposit_tl(cpu_y, t0, src1, 31, 1);
524fcf5ef2aSThomas Huth 
525fcf5ef2aSThomas Huth     // b1 = N ^ V;
5262a1905c7SRichard Henderson     tcg_gen_xor_tl(t0, cpu_cc_N, cpu_cc_V);
527fcf5ef2aSThomas Huth 
528b989ce73SRichard Henderson     /*
529b989ce73SRichard Henderson      * src1 = (b1 << 31) | (src1 >> 1)
530b989ce73SRichard Henderson      */
5312a1905c7SRichard Henderson     tcg_gen_andi_tl(t0, t0, 1u << 31);
532b989ce73SRichard Henderson     tcg_gen_shri_tl(t_src1, t_src1, 1);
533b989ce73SRichard Henderson     tcg_gen_or_tl(t_src1, t_src1, t0);
534fcf5ef2aSThomas Huth 
535b989ce73SRichard Henderson     gen_op_addcc(dst, t_src1, t_src2);
536fcf5ef2aSThomas Huth }
537fcf5ef2aSThomas Huth 
5380c2e96c1SRichard Henderson static void gen_op_multiply(TCGv dst, TCGv src1, TCGv src2, int sign_ext)
539fcf5ef2aSThomas Huth {
540fcf5ef2aSThomas Huth #if TARGET_LONG_BITS == 32
541fcf5ef2aSThomas Huth     if (sign_ext) {
542fcf5ef2aSThomas Huth         tcg_gen_muls2_tl(dst, cpu_y, src1, src2);
543fcf5ef2aSThomas Huth     } else {
544fcf5ef2aSThomas Huth         tcg_gen_mulu2_tl(dst, cpu_y, src1, src2);
545fcf5ef2aSThomas Huth     }
546fcf5ef2aSThomas Huth #else
547fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new_i64();
548fcf5ef2aSThomas Huth     TCGv t1 = tcg_temp_new_i64();
549fcf5ef2aSThomas Huth 
550fcf5ef2aSThomas Huth     if (sign_ext) {
551fcf5ef2aSThomas Huth         tcg_gen_ext32s_i64(t0, src1);
552fcf5ef2aSThomas Huth         tcg_gen_ext32s_i64(t1, src2);
553fcf5ef2aSThomas Huth     } else {
554fcf5ef2aSThomas Huth         tcg_gen_ext32u_i64(t0, src1);
555fcf5ef2aSThomas Huth         tcg_gen_ext32u_i64(t1, src2);
556fcf5ef2aSThomas Huth     }
557fcf5ef2aSThomas Huth 
558fcf5ef2aSThomas Huth     tcg_gen_mul_i64(dst, t0, t1);
559fcf5ef2aSThomas Huth     tcg_gen_shri_i64(cpu_y, dst, 32);
560fcf5ef2aSThomas Huth #endif
561fcf5ef2aSThomas Huth }
562fcf5ef2aSThomas Huth 
5630c2e96c1SRichard Henderson static void gen_op_umul(TCGv dst, TCGv src1, TCGv src2)
564fcf5ef2aSThomas Huth {
565fcf5ef2aSThomas Huth     /* zero-extend truncated operands before multiplication */
566fcf5ef2aSThomas Huth     gen_op_multiply(dst, src1, src2, 0);
567fcf5ef2aSThomas Huth }
568fcf5ef2aSThomas Huth 
5690c2e96c1SRichard Henderson static void gen_op_smul(TCGv dst, TCGv src1, TCGv src2)
570fcf5ef2aSThomas Huth {
571fcf5ef2aSThomas Huth     /* sign-extend truncated operands before multiplication */
572fcf5ef2aSThomas Huth     gen_op_multiply(dst, src1, src2, 1);
573fcf5ef2aSThomas Huth }
574fcf5ef2aSThomas Huth 
575c2636853SRichard Henderson static void gen_op_sdiv(TCGv dst, TCGv src1, TCGv src2)
576c2636853SRichard Henderson {
57713260103SRichard Henderson #ifdef TARGET_SPARC64
578c2636853SRichard Henderson     gen_helper_sdiv(dst, tcg_env, src1, src2);
57913260103SRichard Henderson     tcg_gen_ext32s_tl(dst, dst);
58013260103SRichard Henderson #else
58113260103SRichard Henderson     TCGv_i64 t64 = tcg_temp_new_i64();
58213260103SRichard Henderson     gen_helper_sdiv(t64, tcg_env, src1, src2);
58313260103SRichard Henderson     tcg_gen_trunc_i64_tl(dst, t64);
58413260103SRichard Henderson #endif
585c2636853SRichard Henderson }
586c2636853SRichard Henderson 
587c2636853SRichard Henderson static void gen_op_udivcc(TCGv dst, TCGv src1, TCGv src2)
588c2636853SRichard Henderson {
58913260103SRichard Henderson     TCGv_i64 t64;
59013260103SRichard Henderson 
59113260103SRichard Henderson #ifdef TARGET_SPARC64
59213260103SRichard Henderson     t64 = cpu_cc_V;
59313260103SRichard Henderson #else
59413260103SRichard Henderson     t64 = tcg_temp_new_i64();
59513260103SRichard Henderson #endif
59613260103SRichard Henderson 
59713260103SRichard Henderson     gen_helper_udiv(t64, tcg_env, src1, src2);
59813260103SRichard Henderson 
59913260103SRichard Henderson #ifdef TARGET_SPARC64
60013260103SRichard Henderson     tcg_gen_ext32u_tl(cpu_cc_N, t64);
60113260103SRichard Henderson     tcg_gen_shri_tl(cpu_cc_V, t64, 32);
60213260103SRichard Henderson     tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N);
60313260103SRichard Henderson     tcg_gen_movi_tl(cpu_icc_C, 0);
60413260103SRichard Henderson #else
60513260103SRichard Henderson     tcg_gen_extr_i64_tl(cpu_cc_N, cpu_cc_V, t64);
60613260103SRichard Henderson #endif
60713260103SRichard Henderson     tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N);
60813260103SRichard Henderson     tcg_gen_movi_tl(cpu_cc_C, 0);
60913260103SRichard Henderson     tcg_gen_mov_tl(dst, cpu_cc_N);
610c2636853SRichard Henderson }
611c2636853SRichard Henderson 
612c2636853SRichard Henderson static void gen_op_sdivcc(TCGv dst, TCGv src1, TCGv src2)
613c2636853SRichard Henderson {
61413260103SRichard Henderson     TCGv_i64 t64;
61513260103SRichard Henderson 
61613260103SRichard Henderson #ifdef TARGET_SPARC64
61713260103SRichard Henderson     t64 = cpu_cc_V;
61813260103SRichard Henderson #else
61913260103SRichard Henderson     t64 = tcg_temp_new_i64();
62013260103SRichard Henderson #endif
62113260103SRichard Henderson 
62213260103SRichard Henderson     gen_helper_sdiv(t64, tcg_env, src1, src2);
62313260103SRichard Henderson 
62413260103SRichard Henderson #ifdef TARGET_SPARC64
62513260103SRichard Henderson     tcg_gen_ext32s_tl(cpu_cc_N, t64);
62613260103SRichard Henderson     tcg_gen_shri_tl(cpu_cc_V, t64, 32);
62713260103SRichard Henderson     tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N);
62813260103SRichard Henderson     tcg_gen_movi_tl(cpu_icc_C, 0);
62913260103SRichard Henderson #else
63013260103SRichard Henderson     tcg_gen_extr_i64_tl(cpu_cc_N, cpu_cc_V, t64);
63113260103SRichard Henderson #endif
63213260103SRichard Henderson     tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N);
63313260103SRichard Henderson     tcg_gen_movi_tl(cpu_cc_C, 0);
63413260103SRichard Henderson     tcg_gen_mov_tl(dst, cpu_cc_N);
635c2636853SRichard Henderson }
636c2636853SRichard Henderson 
637a9aba13dSRichard Henderson static void gen_op_taddcctv(TCGv dst, TCGv src1, TCGv src2)
638a9aba13dSRichard Henderson {
639a9aba13dSRichard Henderson     gen_helper_taddcctv(dst, tcg_env, src1, src2);
640a9aba13dSRichard Henderson }
641a9aba13dSRichard Henderson 
642a9aba13dSRichard Henderson static void gen_op_tsubcctv(TCGv dst, TCGv src1, TCGv src2)
643a9aba13dSRichard Henderson {
644a9aba13dSRichard Henderson     gen_helper_tsubcctv(dst, tcg_env, src1, src2);
645a9aba13dSRichard Henderson }
646a9aba13dSRichard Henderson 
6479c6ec5bcSRichard Henderson static void gen_op_popc(TCGv dst, TCGv src1, TCGv src2)
6489c6ec5bcSRichard Henderson {
6499c6ec5bcSRichard Henderson     tcg_gen_ctpop_tl(dst, src2);
6509c6ec5bcSRichard Henderson }
6519c6ec5bcSRichard Henderson 
65245bfed3bSRichard Henderson #ifndef TARGET_SPARC64
65345bfed3bSRichard Henderson static void gen_helper_array8(TCGv dst, TCGv src1, TCGv src2)
65445bfed3bSRichard Henderson {
65545bfed3bSRichard Henderson     g_assert_not_reached();
65645bfed3bSRichard Henderson }
65745bfed3bSRichard Henderson #endif
65845bfed3bSRichard Henderson 
65945bfed3bSRichard Henderson static void gen_op_array16(TCGv dst, TCGv src1, TCGv src2)
66045bfed3bSRichard Henderson {
66145bfed3bSRichard Henderson     gen_helper_array8(dst, src1, src2);
66245bfed3bSRichard Henderson     tcg_gen_shli_tl(dst, dst, 1);
66345bfed3bSRichard Henderson }
66445bfed3bSRichard Henderson 
66545bfed3bSRichard Henderson static void gen_op_array32(TCGv dst, TCGv src1, TCGv src2)
66645bfed3bSRichard Henderson {
66745bfed3bSRichard Henderson     gen_helper_array8(dst, src1, src2);
66845bfed3bSRichard Henderson     tcg_gen_shli_tl(dst, dst, 2);
66945bfed3bSRichard Henderson }
67045bfed3bSRichard Henderson 
6712f722641SRichard Henderson static void gen_op_fpack16(TCGv_i32 dst, TCGv_i64 src)
6722f722641SRichard Henderson {
6732f722641SRichard Henderson #ifdef TARGET_SPARC64
6742f722641SRichard Henderson     gen_helper_fpack16(dst, cpu_gsr, src);
6752f722641SRichard Henderson #else
6762f722641SRichard Henderson     g_assert_not_reached();
6772f722641SRichard Henderson #endif
6782f722641SRichard Henderson }
6792f722641SRichard Henderson 
6802f722641SRichard Henderson static void gen_op_fpackfix(TCGv_i32 dst, TCGv_i64 src)
6812f722641SRichard Henderson {
6822f722641SRichard Henderson #ifdef TARGET_SPARC64
6832f722641SRichard Henderson     gen_helper_fpackfix(dst, cpu_gsr, src);
6842f722641SRichard Henderson #else
6852f722641SRichard Henderson     g_assert_not_reached();
6862f722641SRichard Henderson #endif
6872f722641SRichard Henderson }
6882f722641SRichard Henderson 
6894b6edc0aSRichard Henderson static void gen_op_fpack32(TCGv_i64 dst, TCGv_i64 src1, TCGv_i64 src2)
6904b6edc0aSRichard Henderson {
6914b6edc0aSRichard Henderson #ifdef TARGET_SPARC64
6924b6edc0aSRichard Henderson     gen_helper_fpack32(dst, cpu_gsr, src1, src2);
6934b6edc0aSRichard Henderson #else
6944b6edc0aSRichard Henderson     g_assert_not_reached();
6954b6edc0aSRichard Henderson #endif
6964b6edc0aSRichard Henderson }
6974b6edc0aSRichard Henderson 
6984b6edc0aSRichard Henderson static void gen_op_faligndata(TCGv_i64 dst, TCGv_i64 s1, TCGv_i64 s2)
6994b6edc0aSRichard Henderson {
7004b6edc0aSRichard Henderson #ifdef TARGET_SPARC64
7014b6edc0aSRichard Henderson     TCGv t1, t2, shift;
7024b6edc0aSRichard Henderson 
7034b6edc0aSRichard Henderson     t1 = tcg_temp_new();
7044b6edc0aSRichard Henderson     t2 = tcg_temp_new();
7054b6edc0aSRichard Henderson     shift = tcg_temp_new();
7064b6edc0aSRichard Henderson 
7074b6edc0aSRichard Henderson     tcg_gen_andi_tl(shift, cpu_gsr, 7);
7084b6edc0aSRichard Henderson     tcg_gen_shli_tl(shift, shift, 3);
7094b6edc0aSRichard Henderson     tcg_gen_shl_tl(t1, s1, shift);
7104b6edc0aSRichard Henderson 
7114b6edc0aSRichard Henderson     /*
7124b6edc0aSRichard Henderson      * A shift of 64 does not produce 0 in TCG.  Divide this into a
7134b6edc0aSRichard Henderson      * shift of (up to 63) followed by a constant shift of 1.
7144b6edc0aSRichard Henderson      */
7154b6edc0aSRichard Henderson     tcg_gen_xori_tl(shift, shift, 63);
7164b6edc0aSRichard Henderson     tcg_gen_shr_tl(t2, s2, shift);
7174b6edc0aSRichard Henderson     tcg_gen_shri_tl(t2, t2, 1);
7184b6edc0aSRichard Henderson 
7194b6edc0aSRichard Henderson     tcg_gen_or_tl(dst, t1, t2);
7204b6edc0aSRichard Henderson #else
7214b6edc0aSRichard Henderson     g_assert_not_reached();
7224b6edc0aSRichard Henderson #endif
7234b6edc0aSRichard Henderson }
7244b6edc0aSRichard Henderson 
7254b6edc0aSRichard Henderson static void gen_op_bshuffle(TCGv_i64 dst, TCGv_i64 src1, TCGv_i64 src2)
7264b6edc0aSRichard Henderson {
7274b6edc0aSRichard Henderson #ifdef TARGET_SPARC64
7284b6edc0aSRichard Henderson     gen_helper_bshuffle(dst, cpu_gsr, src1, src2);
7294b6edc0aSRichard Henderson #else
7304b6edc0aSRichard Henderson     g_assert_not_reached();
7314b6edc0aSRichard Henderson #endif
7324b6edc0aSRichard Henderson }
7334b6edc0aSRichard Henderson 
734fcf5ef2aSThomas Huth // 1
7350c2e96c1SRichard Henderson static void gen_op_eval_ba(TCGv dst)
736fcf5ef2aSThomas Huth {
737fcf5ef2aSThomas Huth     tcg_gen_movi_tl(dst, 1);
738fcf5ef2aSThomas Huth }
739fcf5ef2aSThomas Huth 
740fcf5ef2aSThomas Huth // 0
7410c2e96c1SRichard Henderson static void gen_op_eval_bn(TCGv dst)
742fcf5ef2aSThomas Huth {
743fcf5ef2aSThomas Huth     tcg_gen_movi_tl(dst, 0);
744fcf5ef2aSThomas Huth }
745fcf5ef2aSThomas Huth 
746fcf5ef2aSThomas Huth /*
747fcf5ef2aSThomas Huth   FPSR bit field FCC1 | FCC0:
748fcf5ef2aSThomas Huth    0 =
749fcf5ef2aSThomas Huth    1 <
750fcf5ef2aSThomas Huth    2 >
751fcf5ef2aSThomas Huth    3 unordered
752fcf5ef2aSThomas Huth */
7530c2e96c1SRichard Henderson static void gen_mov_reg_FCC0(TCGv reg, TCGv src,
754fcf5ef2aSThomas Huth                                     unsigned int fcc_offset)
755fcf5ef2aSThomas Huth {
756fcf5ef2aSThomas Huth     tcg_gen_shri_tl(reg, src, FSR_FCC0_SHIFT + fcc_offset);
757fcf5ef2aSThomas Huth     tcg_gen_andi_tl(reg, reg, 0x1);
758fcf5ef2aSThomas Huth }
759fcf5ef2aSThomas Huth 
7600c2e96c1SRichard Henderson static void gen_mov_reg_FCC1(TCGv reg, TCGv src, unsigned int fcc_offset)
761fcf5ef2aSThomas Huth {
762fcf5ef2aSThomas Huth     tcg_gen_shri_tl(reg, src, FSR_FCC1_SHIFT + fcc_offset);
763fcf5ef2aSThomas Huth     tcg_gen_andi_tl(reg, reg, 0x1);
764fcf5ef2aSThomas Huth }
765fcf5ef2aSThomas Huth 
766fcf5ef2aSThomas Huth // !0: FCC0 | FCC1
7670c2e96c1SRichard Henderson static void gen_op_eval_fbne(TCGv dst, TCGv src, unsigned int fcc_offset)
768fcf5ef2aSThomas Huth {
769fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
770fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
771fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(t0, src, fcc_offset);
772fcf5ef2aSThomas Huth     tcg_gen_or_tl(dst, dst, t0);
773fcf5ef2aSThomas Huth }
774fcf5ef2aSThomas Huth 
775fcf5ef2aSThomas Huth // 1 or 2: FCC0 ^ FCC1
7760c2e96c1SRichard Henderson static void gen_op_eval_fblg(TCGv dst, TCGv src, unsigned int fcc_offset)
777fcf5ef2aSThomas Huth {
778fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
779fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
780fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(t0, src, fcc_offset);
781fcf5ef2aSThomas Huth     tcg_gen_xor_tl(dst, dst, t0);
782fcf5ef2aSThomas Huth }
783fcf5ef2aSThomas Huth 
784fcf5ef2aSThomas Huth // 1 or 3: FCC0
7850c2e96c1SRichard Henderson static void gen_op_eval_fbul(TCGv dst, TCGv src, unsigned int fcc_offset)
786fcf5ef2aSThomas Huth {
787fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
788fcf5ef2aSThomas Huth }
789fcf5ef2aSThomas Huth 
790fcf5ef2aSThomas Huth // 1: FCC0 & !FCC1
7910c2e96c1SRichard Henderson static void gen_op_eval_fbl(TCGv dst, TCGv src, unsigned int fcc_offset)
792fcf5ef2aSThomas Huth {
793fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
794fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
795fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(t0, src, fcc_offset);
796fcf5ef2aSThomas Huth     tcg_gen_andc_tl(dst, dst, t0);
797fcf5ef2aSThomas Huth }
798fcf5ef2aSThomas Huth 
799fcf5ef2aSThomas Huth // 2 or 3: FCC1
8000c2e96c1SRichard Henderson static void gen_op_eval_fbug(TCGv dst, TCGv src, unsigned int fcc_offset)
801fcf5ef2aSThomas Huth {
802fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(dst, src, fcc_offset);
803fcf5ef2aSThomas Huth }
804fcf5ef2aSThomas Huth 
805fcf5ef2aSThomas Huth // 2: !FCC0 & FCC1
8060c2e96c1SRichard Henderson static void gen_op_eval_fbg(TCGv dst, TCGv src, unsigned int fcc_offset)
807fcf5ef2aSThomas Huth {
808fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
809fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
810fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(t0, src, fcc_offset);
811fcf5ef2aSThomas Huth     tcg_gen_andc_tl(dst, t0, dst);
812fcf5ef2aSThomas Huth }
813fcf5ef2aSThomas Huth 
814fcf5ef2aSThomas Huth // 3: FCC0 & FCC1
8150c2e96c1SRichard Henderson static void gen_op_eval_fbu(TCGv dst, TCGv src, unsigned int fcc_offset)
816fcf5ef2aSThomas Huth {
817fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
818fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
819fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(t0, src, fcc_offset);
820fcf5ef2aSThomas Huth     tcg_gen_and_tl(dst, dst, t0);
821fcf5ef2aSThomas Huth }
822fcf5ef2aSThomas Huth 
823fcf5ef2aSThomas Huth // 0: !(FCC0 | FCC1)
8240c2e96c1SRichard Henderson static void gen_op_eval_fbe(TCGv dst, TCGv src, unsigned int fcc_offset)
825fcf5ef2aSThomas Huth {
826fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
827fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
828fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(t0, src, fcc_offset);
829fcf5ef2aSThomas Huth     tcg_gen_or_tl(dst, dst, t0);
830fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
831fcf5ef2aSThomas Huth }
832fcf5ef2aSThomas Huth 
833fcf5ef2aSThomas Huth // 0 or 3: !(FCC0 ^ FCC1)
8340c2e96c1SRichard Henderson static void gen_op_eval_fbue(TCGv dst, TCGv src, unsigned int fcc_offset)
835fcf5ef2aSThomas Huth {
836fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
837fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
838fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(t0, src, fcc_offset);
839fcf5ef2aSThomas Huth     tcg_gen_xor_tl(dst, dst, t0);
840fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
841fcf5ef2aSThomas Huth }
842fcf5ef2aSThomas Huth 
843fcf5ef2aSThomas Huth // 0 or 2: !FCC0
8440c2e96c1SRichard Henderson static void gen_op_eval_fbge(TCGv dst, TCGv src, unsigned int fcc_offset)
845fcf5ef2aSThomas Huth {
846fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
847fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
848fcf5ef2aSThomas Huth }
849fcf5ef2aSThomas Huth 
850fcf5ef2aSThomas Huth // !1: !(FCC0 & !FCC1)
8510c2e96c1SRichard Henderson static void gen_op_eval_fbuge(TCGv dst, TCGv src, unsigned int fcc_offset)
852fcf5ef2aSThomas Huth {
853fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
854fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
855fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(t0, src, fcc_offset);
856fcf5ef2aSThomas Huth     tcg_gen_andc_tl(dst, dst, t0);
857fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
858fcf5ef2aSThomas Huth }
859fcf5ef2aSThomas Huth 
860fcf5ef2aSThomas Huth // 0 or 1: !FCC1
8610c2e96c1SRichard Henderson static void gen_op_eval_fble(TCGv dst, TCGv src, unsigned int fcc_offset)
862fcf5ef2aSThomas Huth {
863fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(dst, src, fcc_offset);
864fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
865fcf5ef2aSThomas Huth }
866fcf5ef2aSThomas Huth 
867fcf5ef2aSThomas Huth // !2: !(!FCC0 & FCC1)
8680c2e96c1SRichard Henderson static void gen_op_eval_fbule(TCGv dst, TCGv src, unsigned int fcc_offset)
869fcf5ef2aSThomas Huth {
870fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
871fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
872fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(t0, src, fcc_offset);
873fcf5ef2aSThomas Huth     tcg_gen_andc_tl(dst, t0, dst);
874fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
875fcf5ef2aSThomas Huth }
876fcf5ef2aSThomas Huth 
877fcf5ef2aSThomas Huth // !3: !(FCC0 & FCC1)
8780c2e96c1SRichard Henderson static void gen_op_eval_fbo(TCGv dst, TCGv src, unsigned int fcc_offset)
879fcf5ef2aSThomas Huth {
880fcf5ef2aSThomas Huth     TCGv t0 = tcg_temp_new();
881fcf5ef2aSThomas Huth     gen_mov_reg_FCC0(dst, src, fcc_offset);
882fcf5ef2aSThomas Huth     gen_mov_reg_FCC1(t0, src, fcc_offset);
883fcf5ef2aSThomas Huth     tcg_gen_and_tl(dst, dst, t0);
884fcf5ef2aSThomas Huth     tcg_gen_xori_tl(dst, dst, 0x1);
885fcf5ef2aSThomas Huth }
886fcf5ef2aSThomas Huth 
88789527e3aSRichard Henderson static void finishing_insn(DisasContext *dc)
88889527e3aSRichard Henderson {
88989527e3aSRichard Henderson     /*
89089527e3aSRichard Henderson      * From here, there is no future path through an unwinding exception.
89189527e3aSRichard Henderson      * If the current insn cannot raise an exception, the computation of
89289527e3aSRichard Henderson      * cpu_cond may be able to be elided.
89389527e3aSRichard Henderson      */
89489527e3aSRichard Henderson     if (dc->cpu_cond_live) {
89589527e3aSRichard Henderson         tcg_gen_discard_tl(cpu_cond);
89689527e3aSRichard Henderson         dc->cpu_cond_live = false;
89789527e3aSRichard Henderson     }
89889527e3aSRichard Henderson }
89989527e3aSRichard Henderson 
9000c2e96c1SRichard Henderson static void gen_generic_branch(DisasContext *dc)
901fcf5ef2aSThomas Huth {
90200ab7e61SRichard Henderson     TCGv npc0 = tcg_constant_tl(dc->jump_pc[0]);
90300ab7e61SRichard Henderson     TCGv npc1 = tcg_constant_tl(dc->jump_pc[1]);
904533f042fSRichard Henderson     TCGv c2 = tcg_constant_tl(dc->jump.c2);
905fcf5ef2aSThomas Huth 
906533f042fSRichard Henderson     tcg_gen_movcond_tl(dc->jump.cond, cpu_npc, dc->jump.c1, c2, npc0, npc1);
907fcf5ef2aSThomas Huth }
908fcf5ef2aSThomas Huth 
909fcf5ef2aSThomas Huth /* call this function before using the condition register as it may
910fcf5ef2aSThomas Huth    have been set for a jump */
9110c2e96c1SRichard Henderson static void flush_cond(DisasContext *dc)
912fcf5ef2aSThomas Huth {
913fcf5ef2aSThomas Huth     if (dc->npc == JUMP_PC) {
914fcf5ef2aSThomas Huth         gen_generic_branch(dc);
91599c82c47SRichard Henderson         dc->npc = DYNAMIC_PC_LOOKUP;
916fcf5ef2aSThomas Huth     }
917fcf5ef2aSThomas Huth }
918fcf5ef2aSThomas Huth 
9190c2e96c1SRichard Henderson static void save_npc(DisasContext *dc)
920fcf5ef2aSThomas Huth {
921633c4283SRichard Henderson     if (dc->npc & 3) {
922633c4283SRichard Henderson         switch (dc->npc) {
923633c4283SRichard Henderson         case JUMP_PC:
924fcf5ef2aSThomas Huth             gen_generic_branch(dc);
92599c82c47SRichard Henderson             dc->npc = DYNAMIC_PC_LOOKUP;
926633c4283SRichard Henderson             break;
927633c4283SRichard Henderson         case DYNAMIC_PC:
928633c4283SRichard Henderson         case DYNAMIC_PC_LOOKUP:
929633c4283SRichard Henderson             break;
930633c4283SRichard Henderson         default:
931633c4283SRichard Henderson             g_assert_not_reached();
932633c4283SRichard Henderson         }
933633c4283SRichard Henderson     } else {
934fcf5ef2aSThomas Huth         tcg_gen_movi_tl(cpu_npc, dc->npc);
935fcf5ef2aSThomas Huth     }
936fcf5ef2aSThomas Huth }
937fcf5ef2aSThomas Huth 
9380c2e96c1SRichard Henderson static void save_state(DisasContext *dc)
939fcf5ef2aSThomas Huth {
940fcf5ef2aSThomas Huth     tcg_gen_movi_tl(cpu_pc, dc->pc);
941fcf5ef2aSThomas Huth     save_npc(dc);
942fcf5ef2aSThomas Huth }
943fcf5ef2aSThomas Huth 
944fcf5ef2aSThomas Huth static void gen_exception(DisasContext *dc, int which)
945fcf5ef2aSThomas Huth {
94689527e3aSRichard Henderson     finishing_insn(dc);
947fcf5ef2aSThomas Huth     save_state(dc);
948ad75a51eSRichard Henderson     gen_helper_raise_exception(tcg_env, tcg_constant_i32(which));
949af00be49SEmilio G. Cota     dc->base.is_jmp = DISAS_NORETURN;
950fcf5ef2aSThomas Huth }
951fcf5ef2aSThomas Huth 
952186e7890SRichard Henderson static TCGLabel *delay_exceptionv(DisasContext *dc, TCGv_i32 excp)
953fcf5ef2aSThomas Huth {
954186e7890SRichard Henderson     DisasDelayException *e = g_new0(DisasDelayException, 1);
955186e7890SRichard Henderson 
956186e7890SRichard Henderson     e->next = dc->delay_excp_list;
957186e7890SRichard Henderson     dc->delay_excp_list = e;
958186e7890SRichard Henderson 
959186e7890SRichard Henderson     e->lab = gen_new_label();
960186e7890SRichard Henderson     e->excp = excp;
961186e7890SRichard Henderson     e->pc = dc->pc;
962186e7890SRichard Henderson     /* Caller must have used flush_cond before branch. */
963186e7890SRichard Henderson     assert(e->npc != JUMP_PC);
964186e7890SRichard Henderson     e->npc = dc->npc;
965186e7890SRichard Henderson 
966186e7890SRichard Henderson     return e->lab;
967186e7890SRichard Henderson }
968186e7890SRichard Henderson 
969186e7890SRichard Henderson static TCGLabel *delay_exception(DisasContext *dc, int excp)
970186e7890SRichard Henderson {
971186e7890SRichard Henderson     return delay_exceptionv(dc, tcg_constant_i32(excp));
972186e7890SRichard Henderson }
973186e7890SRichard Henderson 
974186e7890SRichard Henderson static void gen_check_align(DisasContext *dc, TCGv addr, int mask)
975186e7890SRichard Henderson {
976186e7890SRichard Henderson     TCGv t = tcg_temp_new();
977186e7890SRichard Henderson     TCGLabel *lab;
978186e7890SRichard Henderson 
979186e7890SRichard Henderson     tcg_gen_andi_tl(t, addr, mask);
980186e7890SRichard Henderson 
981186e7890SRichard Henderson     flush_cond(dc);
982186e7890SRichard Henderson     lab = delay_exception(dc, TT_UNALIGNED);
983186e7890SRichard Henderson     tcg_gen_brcondi_tl(TCG_COND_NE, t, 0, lab);
984fcf5ef2aSThomas Huth }
985fcf5ef2aSThomas Huth 
9860c2e96c1SRichard Henderson static void gen_mov_pc_npc(DisasContext *dc)
987fcf5ef2aSThomas Huth {
98889527e3aSRichard Henderson     finishing_insn(dc);
98989527e3aSRichard Henderson 
990633c4283SRichard Henderson     if (dc->npc & 3) {
991633c4283SRichard Henderson         switch (dc->npc) {
992633c4283SRichard Henderson         case JUMP_PC:
993fcf5ef2aSThomas Huth             gen_generic_branch(dc);
994fcf5ef2aSThomas Huth             tcg_gen_mov_tl(cpu_pc, cpu_npc);
99599c82c47SRichard Henderson             dc->pc = DYNAMIC_PC_LOOKUP;
996633c4283SRichard Henderson             break;
997633c4283SRichard Henderson         case DYNAMIC_PC:
998633c4283SRichard Henderson         case DYNAMIC_PC_LOOKUP:
999fcf5ef2aSThomas Huth             tcg_gen_mov_tl(cpu_pc, cpu_npc);
1000633c4283SRichard Henderson             dc->pc = dc->npc;
1001633c4283SRichard Henderson             break;
1002633c4283SRichard Henderson         default:
1003633c4283SRichard Henderson             g_assert_not_reached();
1004633c4283SRichard Henderson         }
1005fcf5ef2aSThomas Huth     } else {
1006fcf5ef2aSThomas Huth         dc->pc = dc->npc;
1007fcf5ef2aSThomas Huth     }
1008fcf5ef2aSThomas Huth }
1009fcf5ef2aSThomas Huth 
1010fcf5ef2aSThomas Huth static void gen_compare(DisasCompare *cmp, bool xcc, unsigned int cond,
1011fcf5ef2aSThomas Huth                         DisasContext *dc)
1012fcf5ef2aSThomas Huth {
1013b597eedcSRichard Henderson     TCGv t1;
1014fcf5ef2aSThomas Huth 
10152a1905c7SRichard Henderson     cmp->c1 = t1 = tcg_temp_new();
1016c8507ebfSRichard Henderson     cmp->c2 = 0;
10172a1905c7SRichard Henderson 
10182a1905c7SRichard Henderson     switch (cond & 7) {
10192a1905c7SRichard Henderson     case 0x0: /* never */
10202a1905c7SRichard Henderson         cmp->cond = TCG_COND_NEVER;
1021c8507ebfSRichard Henderson         cmp->c1 = tcg_constant_tl(0);
1022fcf5ef2aSThomas Huth         break;
10232a1905c7SRichard Henderson 
10242a1905c7SRichard Henderson     case 0x1: /* eq: Z */
10252a1905c7SRichard Henderson         cmp->cond = TCG_COND_EQ;
10262a1905c7SRichard Henderson         if (TARGET_LONG_BITS == 32 || xcc) {
10272a1905c7SRichard Henderson             tcg_gen_mov_tl(t1, cpu_cc_Z);
10282a1905c7SRichard Henderson         } else {
10292a1905c7SRichard Henderson             tcg_gen_ext32u_tl(t1, cpu_icc_Z);
10302a1905c7SRichard Henderson         }
10312a1905c7SRichard Henderson         break;
10322a1905c7SRichard Henderson 
10332a1905c7SRichard Henderson     case 0x2: /* le: Z | (N ^ V) */
10342a1905c7SRichard Henderson         /*
10352a1905c7SRichard Henderson          * Simplify:
10362a1905c7SRichard Henderson          *   cc_Z || (N ^ V) < 0        NE
10372a1905c7SRichard Henderson          *   cc_Z && !((N ^ V) < 0)     EQ
10382a1905c7SRichard Henderson          *   cc_Z & ~((N ^ V) >> TLB)   EQ
10392a1905c7SRichard Henderson          */
10402a1905c7SRichard Henderson         cmp->cond = TCG_COND_EQ;
10412a1905c7SRichard Henderson         tcg_gen_xor_tl(t1, cpu_cc_N, cpu_cc_V);
10422a1905c7SRichard Henderson         tcg_gen_sextract_tl(t1, t1, xcc ? 63 : 31, 1);
10432a1905c7SRichard Henderson         tcg_gen_andc_tl(t1, xcc ? cpu_cc_Z : cpu_icc_Z, t1);
10442a1905c7SRichard Henderson         if (TARGET_LONG_BITS == 64 && !xcc) {
10452a1905c7SRichard Henderson             tcg_gen_ext32u_tl(t1, t1);
10462a1905c7SRichard Henderson         }
10472a1905c7SRichard Henderson         break;
10482a1905c7SRichard Henderson 
10492a1905c7SRichard Henderson     case 0x3: /* lt: N ^ V */
10502a1905c7SRichard Henderson         cmp->cond = TCG_COND_LT;
10512a1905c7SRichard Henderson         tcg_gen_xor_tl(t1, cpu_cc_N, cpu_cc_V);
10522a1905c7SRichard Henderson         if (TARGET_LONG_BITS == 64 && !xcc) {
10532a1905c7SRichard Henderson             tcg_gen_ext32s_tl(t1, t1);
10542a1905c7SRichard Henderson         }
10552a1905c7SRichard Henderson         break;
10562a1905c7SRichard Henderson 
10572a1905c7SRichard Henderson     case 0x4: /* leu: Z | C */
10582a1905c7SRichard Henderson         /*
10592a1905c7SRichard Henderson          * Simplify:
10602a1905c7SRichard Henderson          *   cc_Z == 0 || cc_C != 0     NE
10612a1905c7SRichard Henderson          *   cc_Z != 0 && cc_C == 0     EQ
10622a1905c7SRichard Henderson          *   cc_Z & (cc_C ? 0 : -1)     EQ
10632a1905c7SRichard Henderson          *   cc_Z & (cc_C - 1)          EQ
10642a1905c7SRichard Henderson          */
10652a1905c7SRichard Henderson         cmp->cond = TCG_COND_EQ;
10662a1905c7SRichard Henderson         if (TARGET_LONG_BITS == 32 || xcc) {
10672a1905c7SRichard Henderson             tcg_gen_subi_tl(t1, cpu_cc_C, 1);
10682a1905c7SRichard Henderson             tcg_gen_and_tl(t1, t1, cpu_cc_Z);
10692a1905c7SRichard Henderson         } else {
10702a1905c7SRichard Henderson             tcg_gen_extract_tl(t1, cpu_icc_C, 32, 1);
10712a1905c7SRichard Henderson             tcg_gen_subi_tl(t1, t1, 1);
10722a1905c7SRichard Henderson             tcg_gen_and_tl(t1, t1, cpu_icc_Z);
10732a1905c7SRichard Henderson             tcg_gen_ext32u_tl(t1, t1);
10742a1905c7SRichard Henderson         }
10752a1905c7SRichard Henderson         break;
10762a1905c7SRichard Henderson 
10772a1905c7SRichard Henderson     case 0x5: /* ltu: C */
10782a1905c7SRichard Henderson         cmp->cond = TCG_COND_NE;
10792a1905c7SRichard Henderson         if (TARGET_LONG_BITS == 32 || xcc) {
10802a1905c7SRichard Henderson             tcg_gen_mov_tl(t1, cpu_cc_C);
10812a1905c7SRichard Henderson         } else {
10822a1905c7SRichard Henderson             tcg_gen_extract_tl(t1, cpu_icc_C, 32, 1);
10832a1905c7SRichard Henderson         }
10842a1905c7SRichard Henderson         break;
10852a1905c7SRichard Henderson 
10862a1905c7SRichard Henderson     case 0x6: /* neg: N */
10872a1905c7SRichard Henderson         cmp->cond = TCG_COND_LT;
10882a1905c7SRichard Henderson         if (TARGET_LONG_BITS == 32 || xcc) {
10892a1905c7SRichard Henderson             tcg_gen_mov_tl(t1, cpu_cc_N);
10902a1905c7SRichard Henderson         } else {
10912a1905c7SRichard Henderson             tcg_gen_ext32s_tl(t1, cpu_cc_N);
10922a1905c7SRichard Henderson         }
10932a1905c7SRichard Henderson         break;
10942a1905c7SRichard Henderson 
10952a1905c7SRichard Henderson     case 0x7: /* vs: V */
10962a1905c7SRichard Henderson         cmp->cond = TCG_COND_LT;
10972a1905c7SRichard Henderson         if (TARGET_LONG_BITS == 32 || xcc) {
10982a1905c7SRichard Henderson             tcg_gen_mov_tl(t1, cpu_cc_V);
10992a1905c7SRichard Henderson         } else {
11002a1905c7SRichard Henderson             tcg_gen_ext32s_tl(t1, cpu_cc_V);
11012a1905c7SRichard Henderson         }
11022a1905c7SRichard Henderson         break;
11032a1905c7SRichard Henderson     }
11042a1905c7SRichard Henderson     if (cond & 8) {
11052a1905c7SRichard Henderson         cmp->cond = tcg_invert_cond(cmp->cond);
1106fcf5ef2aSThomas Huth     }
1107fcf5ef2aSThomas Huth }
1108fcf5ef2aSThomas Huth 
1109fcf5ef2aSThomas Huth static void gen_fcompare(DisasCompare *cmp, unsigned int cc, unsigned int cond)
1110fcf5ef2aSThomas Huth {
1111fcf5ef2aSThomas Huth     unsigned int offset;
1112fcf5ef2aSThomas Huth     TCGv r_dst;
1113fcf5ef2aSThomas Huth 
1114fcf5ef2aSThomas Huth     /* For now we still generate a straight boolean result.  */
1115fcf5ef2aSThomas Huth     cmp->cond = TCG_COND_NE;
1116fcf5ef2aSThomas Huth     cmp->c1 = r_dst = tcg_temp_new();
1117c8507ebfSRichard Henderson     cmp->c2 = 0;
1118fcf5ef2aSThomas Huth 
1119fcf5ef2aSThomas Huth     switch (cc) {
1120fcf5ef2aSThomas Huth     default:
1121fcf5ef2aSThomas Huth     case 0x0:
1122fcf5ef2aSThomas Huth         offset = 0;
1123fcf5ef2aSThomas Huth         break;
1124fcf5ef2aSThomas Huth     case 0x1:
1125fcf5ef2aSThomas Huth         offset = 32 - 10;
1126fcf5ef2aSThomas Huth         break;
1127fcf5ef2aSThomas Huth     case 0x2:
1128fcf5ef2aSThomas Huth         offset = 34 - 10;
1129fcf5ef2aSThomas Huth         break;
1130fcf5ef2aSThomas Huth     case 0x3:
1131fcf5ef2aSThomas Huth         offset = 36 - 10;
1132fcf5ef2aSThomas Huth         break;
1133fcf5ef2aSThomas Huth     }
1134fcf5ef2aSThomas Huth 
1135fcf5ef2aSThomas Huth     switch (cond) {
1136fcf5ef2aSThomas Huth     case 0x0:
1137fcf5ef2aSThomas Huth         gen_op_eval_bn(r_dst);
1138fcf5ef2aSThomas Huth         break;
1139fcf5ef2aSThomas Huth     case 0x1:
1140fcf5ef2aSThomas Huth         gen_op_eval_fbne(r_dst, cpu_fsr, offset);
1141fcf5ef2aSThomas Huth         break;
1142fcf5ef2aSThomas Huth     case 0x2:
1143fcf5ef2aSThomas Huth         gen_op_eval_fblg(r_dst, cpu_fsr, offset);
1144fcf5ef2aSThomas Huth         break;
1145fcf5ef2aSThomas Huth     case 0x3:
1146fcf5ef2aSThomas Huth         gen_op_eval_fbul(r_dst, cpu_fsr, offset);
1147fcf5ef2aSThomas Huth         break;
1148fcf5ef2aSThomas Huth     case 0x4:
1149fcf5ef2aSThomas Huth         gen_op_eval_fbl(r_dst, cpu_fsr, offset);
1150fcf5ef2aSThomas Huth         break;
1151fcf5ef2aSThomas Huth     case 0x5:
1152fcf5ef2aSThomas Huth         gen_op_eval_fbug(r_dst, cpu_fsr, offset);
1153fcf5ef2aSThomas Huth         break;
1154fcf5ef2aSThomas Huth     case 0x6:
1155fcf5ef2aSThomas Huth         gen_op_eval_fbg(r_dst, cpu_fsr, offset);
1156fcf5ef2aSThomas Huth         break;
1157fcf5ef2aSThomas Huth     case 0x7:
1158fcf5ef2aSThomas Huth         gen_op_eval_fbu(r_dst, cpu_fsr, offset);
1159fcf5ef2aSThomas Huth         break;
1160fcf5ef2aSThomas Huth     case 0x8:
1161fcf5ef2aSThomas Huth         gen_op_eval_ba(r_dst);
1162fcf5ef2aSThomas Huth         break;
1163fcf5ef2aSThomas Huth     case 0x9:
1164fcf5ef2aSThomas Huth         gen_op_eval_fbe(r_dst, cpu_fsr, offset);
1165fcf5ef2aSThomas Huth         break;
1166fcf5ef2aSThomas Huth     case 0xa:
1167fcf5ef2aSThomas Huth         gen_op_eval_fbue(r_dst, cpu_fsr, offset);
1168fcf5ef2aSThomas Huth         break;
1169fcf5ef2aSThomas Huth     case 0xb:
1170fcf5ef2aSThomas Huth         gen_op_eval_fbge(r_dst, cpu_fsr, offset);
1171fcf5ef2aSThomas Huth         break;
1172fcf5ef2aSThomas Huth     case 0xc:
1173fcf5ef2aSThomas Huth         gen_op_eval_fbuge(r_dst, cpu_fsr, offset);
1174fcf5ef2aSThomas Huth         break;
1175fcf5ef2aSThomas Huth     case 0xd:
1176fcf5ef2aSThomas Huth         gen_op_eval_fble(r_dst, cpu_fsr, offset);
1177fcf5ef2aSThomas Huth         break;
1178fcf5ef2aSThomas Huth     case 0xe:
1179fcf5ef2aSThomas Huth         gen_op_eval_fbule(r_dst, cpu_fsr, offset);
1180fcf5ef2aSThomas Huth         break;
1181fcf5ef2aSThomas Huth     case 0xf:
1182fcf5ef2aSThomas Huth         gen_op_eval_fbo(r_dst, cpu_fsr, offset);
1183fcf5ef2aSThomas Huth         break;
1184fcf5ef2aSThomas Huth     }
1185fcf5ef2aSThomas Huth }
1186fcf5ef2aSThomas Huth 
11872c4f56c9SRichard Henderson static bool gen_compare_reg(DisasCompare *cmp, int cond, TCGv r_src)
11882c4f56c9SRichard Henderson {
11892c4f56c9SRichard Henderson     static const TCGCond cond_reg[4] = {
1190ab9ffe98SRichard Henderson         TCG_COND_NEVER,  /* reserved */
1191fcf5ef2aSThomas Huth         TCG_COND_EQ,
1192fcf5ef2aSThomas Huth         TCG_COND_LE,
1193fcf5ef2aSThomas Huth         TCG_COND_LT,
1194fcf5ef2aSThomas Huth     };
11952c4f56c9SRichard Henderson     TCGCond tcond;
1196fcf5ef2aSThomas Huth 
11972c4f56c9SRichard Henderson     if ((cond & 3) == 0) {
11982c4f56c9SRichard Henderson         return false;
11992c4f56c9SRichard Henderson     }
12002c4f56c9SRichard Henderson     tcond = cond_reg[cond & 3];
12012c4f56c9SRichard Henderson     if (cond & 4) {
12022c4f56c9SRichard Henderson         tcond = tcg_invert_cond(tcond);
12032c4f56c9SRichard Henderson     }
12042c4f56c9SRichard Henderson 
12052c4f56c9SRichard Henderson     cmp->cond = tcond;
1206816f89b7SRichard Henderson     cmp->c1 = tcg_temp_new();
1207c8507ebfSRichard Henderson     cmp->c2 = 0;
1208816f89b7SRichard Henderson     tcg_gen_mov_tl(cmp->c1, r_src);
12092c4f56c9SRichard Henderson     return true;
1210fcf5ef2aSThomas Huth }
1211fcf5ef2aSThomas Huth 
1212baf3dbf2SRichard Henderson static void gen_op_clear_ieee_excp_and_FTT(void)
1213baf3dbf2SRichard Henderson {
1214baf3dbf2SRichard Henderson     tcg_gen_andi_tl(cpu_fsr, cpu_fsr, FSR_FTT_CEXC_NMASK);
1215baf3dbf2SRichard Henderson }
1216baf3dbf2SRichard Henderson 
1217baf3dbf2SRichard Henderson static void gen_op_fmovs(TCGv_i32 dst, TCGv_i32 src)
1218baf3dbf2SRichard Henderson {
1219baf3dbf2SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
1220baf3dbf2SRichard Henderson     tcg_gen_mov_i32(dst, src);
1221baf3dbf2SRichard Henderson }
1222baf3dbf2SRichard Henderson 
1223baf3dbf2SRichard Henderson static void gen_op_fnegs(TCGv_i32 dst, TCGv_i32 src)
1224baf3dbf2SRichard Henderson {
1225baf3dbf2SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
1226baf3dbf2SRichard Henderson     gen_helper_fnegs(dst, src);
1227baf3dbf2SRichard Henderson }
1228baf3dbf2SRichard Henderson 
1229baf3dbf2SRichard Henderson static void gen_op_fabss(TCGv_i32 dst, TCGv_i32 src)
1230baf3dbf2SRichard Henderson {
1231baf3dbf2SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
1232baf3dbf2SRichard Henderson     gen_helper_fabss(dst, src);
1233baf3dbf2SRichard Henderson }
1234baf3dbf2SRichard Henderson 
1235c6d83e4fSRichard Henderson static void gen_op_fmovd(TCGv_i64 dst, TCGv_i64 src)
1236c6d83e4fSRichard Henderson {
1237c6d83e4fSRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
1238c6d83e4fSRichard Henderson     tcg_gen_mov_i64(dst, src);
1239c6d83e4fSRichard Henderson }
1240c6d83e4fSRichard Henderson 
1241c6d83e4fSRichard Henderson static void gen_op_fnegd(TCGv_i64 dst, TCGv_i64 src)
1242c6d83e4fSRichard Henderson {
1243c6d83e4fSRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
1244c6d83e4fSRichard Henderson     gen_helper_fnegd(dst, src);
1245c6d83e4fSRichard Henderson }
1246c6d83e4fSRichard Henderson 
1247c6d83e4fSRichard Henderson static void gen_op_fabsd(TCGv_i64 dst, TCGv_i64 src)
1248c6d83e4fSRichard Henderson {
1249c6d83e4fSRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
1250c6d83e4fSRichard Henderson     gen_helper_fabsd(dst, src);
1251c6d83e4fSRichard Henderson }
1252c6d83e4fSRichard Henderson 
1253fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
12540c2e96c1SRichard Henderson static void gen_op_fcmps(int fccno, TCGv_i32 r_rs1, TCGv_i32 r_rs2)
1255fcf5ef2aSThomas Huth {
1256fcf5ef2aSThomas Huth     switch (fccno) {
1257fcf5ef2aSThomas Huth     case 0:
1258ad75a51eSRichard Henderson         gen_helper_fcmps(cpu_fsr, tcg_env, r_rs1, r_rs2);
1259fcf5ef2aSThomas Huth         break;
1260fcf5ef2aSThomas Huth     case 1:
1261ad75a51eSRichard Henderson         gen_helper_fcmps_fcc1(cpu_fsr, tcg_env, r_rs1, r_rs2);
1262fcf5ef2aSThomas Huth         break;
1263fcf5ef2aSThomas Huth     case 2:
1264ad75a51eSRichard Henderson         gen_helper_fcmps_fcc2(cpu_fsr, tcg_env, r_rs1, r_rs2);
1265fcf5ef2aSThomas Huth         break;
1266fcf5ef2aSThomas Huth     case 3:
1267ad75a51eSRichard Henderson         gen_helper_fcmps_fcc3(cpu_fsr, tcg_env, r_rs1, r_rs2);
1268fcf5ef2aSThomas Huth         break;
1269fcf5ef2aSThomas Huth     }
1270fcf5ef2aSThomas Huth }
1271fcf5ef2aSThomas Huth 
12720c2e96c1SRichard Henderson static void gen_op_fcmpd(int fccno, TCGv_i64 r_rs1, TCGv_i64 r_rs2)
1273fcf5ef2aSThomas Huth {
1274fcf5ef2aSThomas Huth     switch (fccno) {
1275fcf5ef2aSThomas Huth     case 0:
1276ad75a51eSRichard Henderson         gen_helper_fcmpd(cpu_fsr, tcg_env, r_rs1, r_rs2);
1277fcf5ef2aSThomas Huth         break;
1278fcf5ef2aSThomas Huth     case 1:
1279ad75a51eSRichard Henderson         gen_helper_fcmpd_fcc1(cpu_fsr, tcg_env, r_rs1, r_rs2);
1280fcf5ef2aSThomas Huth         break;
1281fcf5ef2aSThomas Huth     case 2:
1282ad75a51eSRichard Henderson         gen_helper_fcmpd_fcc2(cpu_fsr, tcg_env, r_rs1, r_rs2);
1283fcf5ef2aSThomas Huth         break;
1284fcf5ef2aSThomas Huth     case 3:
1285ad75a51eSRichard Henderson         gen_helper_fcmpd_fcc3(cpu_fsr, tcg_env, r_rs1, r_rs2);
1286fcf5ef2aSThomas Huth         break;
1287fcf5ef2aSThomas Huth     }
1288fcf5ef2aSThomas Huth }
1289fcf5ef2aSThomas Huth 
12900c2e96c1SRichard Henderson static void gen_op_fcmpq(int fccno)
1291fcf5ef2aSThomas Huth {
1292fcf5ef2aSThomas Huth     switch (fccno) {
1293fcf5ef2aSThomas Huth     case 0:
1294ad75a51eSRichard Henderson         gen_helper_fcmpq(cpu_fsr, tcg_env);
1295fcf5ef2aSThomas Huth         break;
1296fcf5ef2aSThomas Huth     case 1:
1297ad75a51eSRichard Henderson         gen_helper_fcmpq_fcc1(cpu_fsr, tcg_env);
1298fcf5ef2aSThomas Huth         break;
1299fcf5ef2aSThomas Huth     case 2:
1300ad75a51eSRichard Henderson         gen_helper_fcmpq_fcc2(cpu_fsr, tcg_env);
1301fcf5ef2aSThomas Huth         break;
1302fcf5ef2aSThomas Huth     case 3:
1303ad75a51eSRichard Henderson         gen_helper_fcmpq_fcc3(cpu_fsr, tcg_env);
1304fcf5ef2aSThomas Huth         break;
1305fcf5ef2aSThomas Huth     }
1306fcf5ef2aSThomas Huth }
1307fcf5ef2aSThomas Huth 
13080c2e96c1SRichard Henderson static void gen_op_fcmpes(int fccno, TCGv_i32 r_rs1, TCGv_i32 r_rs2)
1309fcf5ef2aSThomas Huth {
1310fcf5ef2aSThomas Huth     switch (fccno) {
1311fcf5ef2aSThomas Huth     case 0:
1312ad75a51eSRichard Henderson         gen_helper_fcmpes(cpu_fsr, tcg_env, r_rs1, r_rs2);
1313fcf5ef2aSThomas Huth         break;
1314fcf5ef2aSThomas Huth     case 1:
1315ad75a51eSRichard Henderson         gen_helper_fcmpes_fcc1(cpu_fsr, tcg_env, r_rs1, r_rs2);
1316fcf5ef2aSThomas Huth         break;
1317fcf5ef2aSThomas Huth     case 2:
1318ad75a51eSRichard Henderson         gen_helper_fcmpes_fcc2(cpu_fsr, tcg_env, r_rs1, r_rs2);
1319fcf5ef2aSThomas Huth         break;
1320fcf5ef2aSThomas Huth     case 3:
1321ad75a51eSRichard Henderson         gen_helper_fcmpes_fcc3(cpu_fsr, tcg_env, r_rs1, r_rs2);
1322fcf5ef2aSThomas Huth         break;
1323fcf5ef2aSThomas Huth     }
1324fcf5ef2aSThomas Huth }
1325fcf5ef2aSThomas Huth 
13260c2e96c1SRichard Henderson static void gen_op_fcmped(int fccno, TCGv_i64 r_rs1, TCGv_i64 r_rs2)
1327fcf5ef2aSThomas Huth {
1328fcf5ef2aSThomas Huth     switch (fccno) {
1329fcf5ef2aSThomas Huth     case 0:
1330ad75a51eSRichard Henderson         gen_helper_fcmped(cpu_fsr, tcg_env, r_rs1, r_rs2);
1331fcf5ef2aSThomas Huth         break;
1332fcf5ef2aSThomas Huth     case 1:
1333ad75a51eSRichard Henderson         gen_helper_fcmped_fcc1(cpu_fsr, tcg_env, r_rs1, r_rs2);
1334fcf5ef2aSThomas Huth         break;
1335fcf5ef2aSThomas Huth     case 2:
1336ad75a51eSRichard Henderson         gen_helper_fcmped_fcc2(cpu_fsr, tcg_env, r_rs1, r_rs2);
1337fcf5ef2aSThomas Huth         break;
1338fcf5ef2aSThomas Huth     case 3:
1339ad75a51eSRichard Henderson         gen_helper_fcmped_fcc3(cpu_fsr, tcg_env, r_rs1, r_rs2);
1340fcf5ef2aSThomas Huth         break;
1341fcf5ef2aSThomas Huth     }
1342fcf5ef2aSThomas Huth }
1343fcf5ef2aSThomas Huth 
13440c2e96c1SRichard Henderson static void gen_op_fcmpeq(int fccno)
1345fcf5ef2aSThomas Huth {
1346fcf5ef2aSThomas Huth     switch (fccno) {
1347fcf5ef2aSThomas Huth     case 0:
1348ad75a51eSRichard Henderson         gen_helper_fcmpeq(cpu_fsr, tcg_env);
1349fcf5ef2aSThomas Huth         break;
1350fcf5ef2aSThomas Huth     case 1:
1351ad75a51eSRichard Henderson         gen_helper_fcmpeq_fcc1(cpu_fsr, tcg_env);
1352fcf5ef2aSThomas Huth         break;
1353fcf5ef2aSThomas Huth     case 2:
1354ad75a51eSRichard Henderson         gen_helper_fcmpeq_fcc2(cpu_fsr, tcg_env);
1355fcf5ef2aSThomas Huth         break;
1356fcf5ef2aSThomas Huth     case 3:
1357ad75a51eSRichard Henderson         gen_helper_fcmpeq_fcc3(cpu_fsr, tcg_env);
1358fcf5ef2aSThomas Huth         break;
1359fcf5ef2aSThomas Huth     }
1360fcf5ef2aSThomas Huth }
1361fcf5ef2aSThomas Huth 
1362fcf5ef2aSThomas Huth #else
1363fcf5ef2aSThomas Huth 
13640c2e96c1SRichard Henderson static void gen_op_fcmps(int fccno, TCGv r_rs1, TCGv r_rs2)
1365fcf5ef2aSThomas Huth {
1366ad75a51eSRichard Henderson     gen_helper_fcmps(cpu_fsr, tcg_env, r_rs1, r_rs2);
1367fcf5ef2aSThomas Huth }
1368fcf5ef2aSThomas Huth 
13690c2e96c1SRichard Henderson static void gen_op_fcmpd(int fccno, TCGv_i64 r_rs1, TCGv_i64 r_rs2)
1370fcf5ef2aSThomas Huth {
1371ad75a51eSRichard Henderson     gen_helper_fcmpd(cpu_fsr, tcg_env, r_rs1, r_rs2);
1372fcf5ef2aSThomas Huth }
1373fcf5ef2aSThomas Huth 
13740c2e96c1SRichard Henderson static void gen_op_fcmpq(int fccno)
1375fcf5ef2aSThomas Huth {
1376ad75a51eSRichard Henderson     gen_helper_fcmpq(cpu_fsr, tcg_env);
1377fcf5ef2aSThomas Huth }
1378fcf5ef2aSThomas Huth 
13790c2e96c1SRichard Henderson static void gen_op_fcmpes(int fccno, TCGv r_rs1, TCGv r_rs2)
1380fcf5ef2aSThomas Huth {
1381ad75a51eSRichard Henderson     gen_helper_fcmpes(cpu_fsr, tcg_env, r_rs1, r_rs2);
1382fcf5ef2aSThomas Huth }
1383fcf5ef2aSThomas Huth 
13840c2e96c1SRichard Henderson static void gen_op_fcmped(int fccno, TCGv_i64 r_rs1, TCGv_i64 r_rs2)
1385fcf5ef2aSThomas Huth {
1386ad75a51eSRichard Henderson     gen_helper_fcmped(cpu_fsr, tcg_env, r_rs1, r_rs2);
1387fcf5ef2aSThomas Huth }
1388fcf5ef2aSThomas Huth 
13890c2e96c1SRichard Henderson static void gen_op_fcmpeq(int fccno)
1390fcf5ef2aSThomas Huth {
1391ad75a51eSRichard Henderson     gen_helper_fcmpeq(cpu_fsr, tcg_env);
1392fcf5ef2aSThomas Huth }
1393fcf5ef2aSThomas Huth #endif
1394fcf5ef2aSThomas Huth 
1395fcf5ef2aSThomas Huth static void gen_op_fpexception_im(DisasContext *dc, int fsr_flags)
1396fcf5ef2aSThomas Huth {
1397fcf5ef2aSThomas Huth     tcg_gen_andi_tl(cpu_fsr, cpu_fsr, FSR_FTT_NMASK);
1398fcf5ef2aSThomas Huth     tcg_gen_ori_tl(cpu_fsr, cpu_fsr, fsr_flags);
1399fcf5ef2aSThomas Huth     gen_exception(dc, TT_FP_EXCP);
1400fcf5ef2aSThomas Huth }
1401fcf5ef2aSThomas Huth 
1402fcf5ef2aSThomas Huth static int gen_trap_ifnofpu(DisasContext *dc)
1403fcf5ef2aSThomas Huth {
1404fcf5ef2aSThomas Huth #if !defined(CONFIG_USER_ONLY)
1405fcf5ef2aSThomas Huth     if (!dc->fpu_enabled) {
1406fcf5ef2aSThomas Huth         gen_exception(dc, TT_NFPU_INSN);
1407fcf5ef2aSThomas Huth         return 1;
1408fcf5ef2aSThomas Huth     }
1409fcf5ef2aSThomas Huth #endif
1410fcf5ef2aSThomas Huth     return 0;
1411fcf5ef2aSThomas Huth }
1412fcf5ef2aSThomas Huth 
1413fcf5ef2aSThomas Huth /* asi moves */
1414fcf5ef2aSThomas Huth typedef enum {
1415fcf5ef2aSThomas Huth     GET_ASI_HELPER,
1416fcf5ef2aSThomas Huth     GET_ASI_EXCP,
1417fcf5ef2aSThomas Huth     GET_ASI_DIRECT,
1418fcf5ef2aSThomas Huth     GET_ASI_DTWINX,
1419fcf5ef2aSThomas Huth     GET_ASI_BLOCK,
1420fcf5ef2aSThomas Huth     GET_ASI_SHORT,
1421fcf5ef2aSThomas Huth     GET_ASI_BCOPY,
1422fcf5ef2aSThomas Huth     GET_ASI_BFILL,
1423fcf5ef2aSThomas Huth } ASIType;
1424fcf5ef2aSThomas Huth 
1425fcf5ef2aSThomas Huth typedef struct {
1426fcf5ef2aSThomas Huth     ASIType type;
1427fcf5ef2aSThomas Huth     int asi;
1428fcf5ef2aSThomas Huth     int mem_idx;
142914776ab5STony Nguyen     MemOp memop;
1430fcf5ef2aSThomas Huth } DisasASI;
1431fcf5ef2aSThomas Huth 
1432811cc0b0SRichard Henderson /*
1433811cc0b0SRichard Henderson  * Build DisasASI.
1434811cc0b0SRichard Henderson  * For asi == -1, treat as non-asi.
1435811cc0b0SRichard Henderson  * For ask == -2, treat as immediate offset (v8 error, v9 %asi).
1436811cc0b0SRichard Henderson  */
1437811cc0b0SRichard Henderson static DisasASI resolve_asi(DisasContext *dc, int asi, MemOp memop)
1438fcf5ef2aSThomas Huth {
1439fcf5ef2aSThomas Huth     ASIType type = GET_ASI_HELPER;
1440fcf5ef2aSThomas Huth     int mem_idx = dc->mem_idx;
1441fcf5ef2aSThomas Huth 
1442811cc0b0SRichard Henderson     if (asi == -1) {
1443811cc0b0SRichard Henderson         /* Artificial "non-asi" case. */
1444811cc0b0SRichard Henderson         type = GET_ASI_DIRECT;
1445811cc0b0SRichard Henderson         goto done;
1446811cc0b0SRichard Henderson     }
1447811cc0b0SRichard Henderson 
1448fcf5ef2aSThomas Huth #ifndef TARGET_SPARC64
1449fcf5ef2aSThomas Huth     /* Before v9, all asis are immediate and privileged.  */
1450811cc0b0SRichard Henderson     if (asi < 0) {
1451fcf5ef2aSThomas Huth         gen_exception(dc, TT_ILL_INSN);
1452fcf5ef2aSThomas Huth         type = GET_ASI_EXCP;
1453fcf5ef2aSThomas Huth     } else if (supervisor(dc)
1454fcf5ef2aSThomas Huth                /* Note that LEON accepts ASI_USERDATA in user mode, for
1455fcf5ef2aSThomas Huth                   use with CASA.  Also note that previous versions of
1456fcf5ef2aSThomas Huth                   QEMU allowed (and old versions of gcc emitted) ASI_P
1457fcf5ef2aSThomas Huth                   for LEON, which is incorrect.  */
1458fcf5ef2aSThomas Huth                || (asi == ASI_USERDATA
1459fcf5ef2aSThomas Huth                    && (dc->def->features & CPU_FEATURE_CASA))) {
1460fcf5ef2aSThomas Huth         switch (asi) {
1461fcf5ef2aSThomas Huth         case ASI_USERDATA:   /* User data access */
1462fcf5ef2aSThomas Huth             mem_idx = MMU_USER_IDX;
1463fcf5ef2aSThomas Huth             type = GET_ASI_DIRECT;
1464fcf5ef2aSThomas Huth             break;
1465fcf5ef2aSThomas Huth         case ASI_KERNELDATA: /* Supervisor data access */
1466fcf5ef2aSThomas Huth             mem_idx = MMU_KERNEL_IDX;
1467fcf5ef2aSThomas Huth             type = GET_ASI_DIRECT;
1468fcf5ef2aSThomas Huth             break;
1469fcf5ef2aSThomas Huth         case ASI_M_BYPASS:    /* MMU passthrough */
1470fcf5ef2aSThomas Huth         case ASI_LEON_BYPASS: /* LEON MMU passthrough */
1471fcf5ef2aSThomas Huth             mem_idx = MMU_PHYS_IDX;
1472fcf5ef2aSThomas Huth             type = GET_ASI_DIRECT;
1473fcf5ef2aSThomas Huth             break;
1474fcf5ef2aSThomas Huth         case ASI_M_BCOPY: /* Block copy, sta access */
1475fcf5ef2aSThomas Huth             mem_idx = MMU_KERNEL_IDX;
1476fcf5ef2aSThomas Huth             type = GET_ASI_BCOPY;
1477fcf5ef2aSThomas Huth             break;
1478fcf5ef2aSThomas Huth         case ASI_M_BFILL: /* Block fill, stda access */
1479fcf5ef2aSThomas Huth             mem_idx = MMU_KERNEL_IDX;
1480fcf5ef2aSThomas Huth             type = GET_ASI_BFILL;
1481fcf5ef2aSThomas Huth             break;
1482fcf5ef2aSThomas Huth         }
14836e10f37cSKONRAD Frederic 
14846e10f37cSKONRAD Frederic         /* MMU_PHYS_IDX is used when the MMU is disabled to passthrough the
14856e10f37cSKONRAD Frederic          * permissions check in get_physical_address(..).
14866e10f37cSKONRAD Frederic          */
14876e10f37cSKONRAD Frederic         mem_idx = (dc->mem_idx == MMU_PHYS_IDX) ? MMU_PHYS_IDX : mem_idx;
1488fcf5ef2aSThomas Huth     } else {
1489fcf5ef2aSThomas Huth         gen_exception(dc, TT_PRIV_INSN);
1490fcf5ef2aSThomas Huth         type = GET_ASI_EXCP;
1491fcf5ef2aSThomas Huth     }
1492fcf5ef2aSThomas Huth #else
1493811cc0b0SRichard Henderson     if (asi < 0) {
1494fcf5ef2aSThomas Huth         asi = dc->asi;
1495fcf5ef2aSThomas Huth     }
1496fcf5ef2aSThomas Huth     /* With v9, all asis below 0x80 are privileged.  */
1497fcf5ef2aSThomas Huth     /* ??? We ought to check cpu_has_hypervisor, but we didn't copy
1498fcf5ef2aSThomas Huth        down that bit into DisasContext.  For the moment that's ok,
1499fcf5ef2aSThomas Huth        since the direct implementations below doesn't have any ASIs
1500fcf5ef2aSThomas Huth        in the restricted [0x30, 0x7f] range, and the check will be
1501fcf5ef2aSThomas Huth        done properly in the helper.  */
1502fcf5ef2aSThomas Huth     if (!supervisor(dc) && asi < 0x80) {
1503fcf5ef2aSThomas Huth         gen_exception(dc, TT_PRIV_ACT);
1504fcf5ef2aSThomas Huth         type = GET_ASI_EXCP;
1505fcf5ef2aSThomas Huth     } else {
1506fcf5ef2aSThomas Huth         switch (asi) {
1507fcf5ef2aSThomas Huth         case ASI_REAL:      /* Bypass */
1508fcf5ef2aSThomas Huth         case ASI_REAL_IO:   /* Bypass, non-cacheable */
1509fcf5ef2aSThomas Huth         case ASI_REAL_L:    /* Bypass LE */
1510fcf5ef2aSThomas Huth         case ASI_REAL_IO_L: /* Bypass, non-cacheable LE */
1511fcf5ef2aSThomas Huth         case ASI_TWINX_REAL:   /* Real address, twinx */
1512fcf5ef2aSThomas Huth         case ASI_TWINX_REAL_L: /* Real address, twinx, LE */
1513fcf5ef2aSThomas Huth         case ASI_QUAD_LDD_PHYS:
1514fcf5ef2aSThomas Huth         case ASI_QUAD_LDD_PHYS_L:
1515fcf5ef2aSThomas Huth             mem_idx = MMU_PHYS_IDX;
1516fcf5ef2aSThomas Huth             break;
1517fcf5ef2aSThomas Huth         case ASI_N:  /* Nucleus */
1518fcf5ef2aSThomas Huth         case ASI_NL: /* Nucleus LE */
1519fcf5ef2aSThomas Huth         case ASI_TWINX_N:
1520fcf5ef2aSThomas Huth         case ASI_TWINX_NL:
1521fcf5ef2aSThomas Huth         case ASI_NUCLEUS_QUAD_LDD:
1522fcf5ef2aSThomas Huth         case ASI_NUCLEUS_QUAD_LDD_L:
15239a10756dSArtyom Tarasenko             if (hypervisor(dc)) {
152484f8f587SArtyom Tarasenko                 mem_idx = MMU_PHYS_IDX;
15259a10756dSArtyom Tarasenko             } else {
1526fcf5ef2aSThomas Huth                 mem_idx = MMU_NUCLEUS_IDX;
15279a10756dSArtyom Tarasenko             }
1528fcf5ef2aSThomas Huth             break;
1529fcf5ef2aSThomas Huth         case ASI_AIUP:  /* As if user primary */
1530fcf5ef2aSThomas Huth         case ASI_AIUPL: /* As if user primary LE */
1531fcf5ef2aSThomas Huth         case ASI_TWINX_AIUP:
1532fcf5ef2aSThomas Huth         case ASI_TWINX_AIUP_L:
1533fcf5ef2aSThomas Huth         case ASI_BLK_AIUP_4V:
1534fcf5ef2aSThomas Huth         case ASI_BLK_AIUP_L_4V:
1535fcf5ef2aSThomas Huth         case ASI_BLK_AIUP:
1536fcf5ef2aSThomas Huth         case ASI_BLK_AIUPL:
1537fcf5ef2aSThomas Huth             mem_idx = MMU_USER_IDX;
1538fcf5ef2aSThomas Huth             break;
1539fcf5ef2aSThomas Huth         case ASI_AIUS:  /* As if user secondary */
1540fcf5ef2aSThomas Huth         case ASI_AIUSL: /* As if user secondary LE */
1541fcf5ef2aSThomas Huth         case ASI_TWINX_AIUS:
1542fcf5ef2aSThomas Huth         case ASI_TWINX_AIUS_L:
1543fcf5ef2aSThomas Huth         case ASI_BLK_AIUS_4V:
1544fcf5ef2aSThomas Huth         case ASI_BLK_AIUS_L_4V:
1545fcf5ef2aSThomas Huth         case ASI_BLK_AIUS:
1546fcf5ef2aSThomas Huth         case ASI_BLK_AIUSL:
1547fcf5ef2aSThomas Huth             mem_idx = MMU_USER_SECONDARY_IDX;
1548fcf5ef2aSThomas Huth             break;
1549fcf5ef2aSThomas Huth         case ASI_S:  /* Secondary */
1550fcf5ef2aSThomas Huth         case ASI_SL: /* Secondary LE */
1551fcf5ef2aSThomas Huth         case ASI_TWINX_S:
1552fcf5ef2aSThomas Huth         case ASI_TWINX_SL:
1553fcf5ef2aSThomas Huth         case ASI_BLK_COMMIT_S:
1554fcf5ef2aSThomas Huth         case ASI_BLK_S:
1555fcf5ef2aSThomas Huth         case ASI_BLK_SL:
1556fcf5ef2aSThomas Huth         case ASI_FL8_S:
1557fcf5ef2aSThomas Huth         case ASI_FL8_SL:
1558fcf5ef2aSThomas Huth         case ASI_FL16_S:
1559fcf5ef2aSThomas Huth         case ASI_FL16_SL:
1560fcf5ef2aSThomas Huth             if (mem_idx == MMU_USER_IDX) {
1561fcf5ef2aSThomas Huth                 mem_idx = MMU_USER_SECONDARY_IDX;
1562fcf5ef2aSThomas Huth             } else if (mem_idx == MMU_KERNEL_IDX) {
1563fcf5ef2aSThomas Huth                 mem_idx = MMU_KERNEL_SECONDARY_IDX;
1564fcf5ef2aSThomas Huth             }
1565fcf5ef2aSThomas Huth             break;
1566fcf5ef2aSThomas Huth         case ASI_P:  /* Primary */
1567fcf5ef2aSThomas Huth         case ASI_PL: /* Primary LE */
1568fcf5ef2aSThomas Huth         case ASI_TWINX_P:
1569fcf5ef2aSThomas Huth         case ASI_TWINX_PL:
1570fcf5ef2aSThomas Huth         case ASI_BLK_COMMIT_P:
1571fcf5ef2aSThomas Huth         case ASI_BLK_P:
1572fcf5ef2aSThomas Huth         case ASI_BLK_PL:
1573fcf5ef2aSThomas Huth         case ASI_FL8_P:
1574fcf5ef2aSThomas Huth         case ASI_FL8_PL:
1575fcf5ef2aSThomas Huth         case ASI_FL16_P:
1576fcf5ef2aSThomas Huth         case ASI_FL16_PL:
1577fcf5ef2aSThomas Huth             break;
1578fcf5ef2aSThomas Huth         }
1579fcf5ef2aSThomas Huth         switch (asi) {
1580fcf5ef2aSThomas Huth         case ASI_REAL:
1581fcf5ef2aSThomas Huth         case ASI_REAL_IO:
1582fcf5ef2aSThomas Huth         case ASI_REAL_L:
1583fcf5ef2aSThomas Huth         case ASI_REAL_IO_L:
1584fcf5ef2aSThomas Huth         case ASI_N:
1585fcf5ef2aSThomas Huth         case ASI_NL:
1586fcf5ef2aSThomas Huth         case ASI_AIUP:
1587fcf5ef2aSThomas Huth         case ASI_AIUPL:
1588fcf5ef2aSThomas Huth         case ASI_AIUS:
1589fcf5ef2aSThomas Huth         case ASI_AIUSL:
1590fcf5ef2aSThomas Huth         case ASI_S:
1591fcf5ef2aSThomas Huth         case ASI_SL:
1592fcf5ef2aSThomas Huth         case ASI_P:
1593fcf5ef2aSThomas Huth         case ASI_PL:
1594fcf5ef2aSThomas Huth             type = GET_ASI_DIRECT;
1595fcf5ef2aSThomas Huth             break;
1596fcf5ef2aSThomas Huth         case ASI_TWINX_REAL:
1597fcf5ef2aSThomas Huth         case ASI_TWINX_REAL_L:
1598fcf5ef2aSThomas Huth         case ASI_TWINX_N:
1599fcf5ef2aSThomas Huth         case ASI_TWINX_NL:
1600fcf5ef2aSThomas Huth         case ASI_TWINX_AIUP:
1601fcf5ef2aSThomas Huth         case ASI_TWINX_AIUP_L:
1602fcf5ef2aSThomas Huth         case ASI_TWINX_AIUS:
1603fcf5ef2aSThomas Huth         case ASI_TWINX_AIUS_L:
1604fcf5ef2aSThomas Huth         case ASI_TWINX_P:
1605fcf5ef2aSThomas Huth         case ASI_TWINX_PL:
1606fcf5ef2aSThomas Huth         case ASI_TWINX_S:
1607fcf5ef2aSThomas Huth         case ASI_TWINX_SL:
1608fcf5ef2aSThomas Huth         case ASI_QUAD_LDD_PHYS:
1609fcf5ef2aSThomas Huth         case ASI_QUAD_LDD_PHYS_L:
1610fcf5ef2aSThomas Huth         case ASI_NUCLEUS_QUAD_LDD:
1611fcf5ef2aSThomas Huth         case ASI_NUCLEUS_QUAD_LDD_L:
1612fcf5ef2aSThomas Huth             type = GET_ASI_DTWINX;
1613fcf5ef2aSThomas Huth             break;
1614fcf5ef2aSThomas Huth         case ASI_BLK_COMMIT_P:
1615fcf5ef2aSThomas Huth         case ASI_BLK_COMMIT_S:
1616fcf5ef2aSThomas Huth         case ASI_BLK_AIUP_4V:
1617fcf5ef2aSThomas Huth         case ASI_BLK_AIUP_L_4V:
1618fcf5ef2aSThomas Huth         case ASI_BLK_AIUP:
1619fcf5ef2aSThomas Huth         case ASI_BLK_AIUPL:
1620fcf5ef2aSThomas Huth         case ASI_BLK_AIUS_4V:
1621fcf5ef2aSThomas Huth         case ASI_BLK_AIUS_L_4V:
1622fcf5ef2aSThomas Huth         case ASI_BLK_AIUS:
1623fcf5ef2aSThomas Huth         case ASI_BLK_AIUSL:
1624fcf5ef2aSThomas Huth         case ASI_BLK_S:
1625fcf5ef2aSThomas Huth         case ASI_BLK_SL:
1626fcf5ef2aSThomas Huth         case ASI_BLK_P:
1627fcf5ef2aSThomas Huth         case ASI_BLK_PL:
1628fcf5ef2aSThomas Huth             type = GET_ASI_BLOCK;
1629fcf5ef2aSThomas Huth             break;
1630fcf5ef2aSThomas Huth         case ASI_FL8_S:
1631fcf5ef2aSThomas Huth         case ASI_FL8_SL:
1632fcf5ef2aSThomas Huth         case ASI_FL8_P:
1633fcf5ef2aSThomas Huth         case ASI_FL8_PL:
1634fcf5ef2aSThomas Huth             memop = MO_UB;
1635fcf5ef2aSThomas Huth             type = GET_ASI_SHORT;
1636fcf5ef2aSThomas Huth             break;
1637fcf5ef2aSThomas Huth         case ASI_FL16_S:
1638fcf5ef2aSThomas Huth         case ASI_FL16_SL:
1639fcf5ef2aSThomas Huth         case ASI_FL16_P:
1640fcf5ef2aSThomas Huth         case ASI_FL16_PL:
1641fcf5ef2aSThomas Huth             memop = MO_TEUW;
1642fcf5ef2aSThomas Huth             type = GET_ASI_SHORT;
1643fcf5ef2aSThomas Huth             break;
1644fcf5ef2aSThomas Huth         }
1645fcf5ef2aSThomas Huth         /* The little-endian asis all have bit 3 set.  */
1646fcf5ef2aSThomas Huth         if (asi & 8) {
1647fcf5ef2aSThomas Huth             memop ^= MO_BSWAP;
1648fcf5ef2aSThomas Huth         }
1649fcf5ef2aSThomas Huth     }
1650fcf5ef2aSThomas Huth #endif
1651fcf5ef2aSThomas Huth 
1652811cc0b0SRichard Henderson  done:
1653fcf5ef2aSThomas Huth     return (DisasASI){ type, asi, mem_idx, memop };
1654fcf5ef2aSThomas Huth }
1655fcf5ef2aSThomas Huth 
1656a76779eeSRichard Henderson #if defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
1657a76779eeSRichard Henderson static void gen_helper_ld_asi(TCGv_i64 r, TCGv_env e, TCGv a,
1658a76779eeSRichard Henderson                               TCGv_i32 asi, TCGv_i32 mop)
1659a76779eeSRichard Henderson {
1660a76779eeSRichard Henderson     g_assert_not_reached();
1661a76779eeSRichard Henderson }
1662a76779eeSRichard Henderson 
1663a76779eeSRichard Henderson static void gen_helper_st_asi(TCGv_env e, TCGv a, TCGv_i64 r,
1664a76779eeSRichard Henderson                               TCGv_i32 asi, TCGv_i32 mop)
1665a76779eeSRichard Henderson {
1666a76779eeSRichard Henderson     g_assert_not_reached();
1667a76779eeSRichard Henderson }
1668a76779eeSRichard Henderson #endif
1669a76779eeSRichard Henderson 
167042071fc1SRichard Henderson static void gen_ld_asi(DisasContext *dc, DisasASI *da, TCGv dst, TCGv addr)
1671fcf5ef2aSThomas Huth {
1672c03a0fd1SRichard Henderson     switch (da->type) {
1673fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
1674fcf5ef2aSThomas Huth         break;
1675fcf5ef2aSThomas Huth     case GET_ASI_DTWINX: /* Reserved for ldda.  */
1676fcf5ef2aSThomas Huth         gen_exception(dc, TT_ILL_INSN);
1677fcf5ef2aSThomas Huth         break;
1678fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
1679c03a0fd1SRichard Henderson         tcg_gen_qemu_ld_tl(dst, addr, da->mem_idx, da->memop | MO_ALIGN);
1680fcf5ef2aSThomas Huth         break;
1681fcf5ef2aSThomas Huth     default:
1682fcf5ef2aSThomas Huth         {
1683c03a0fd1SRichard Henderson             TCGv_i32 r_asi = tcg_constant_i32(da->asi);
1684c03a0fd1SRichard Henderson             TCGv_i32 r_mop = tcg_constant_i32(da->memop | MO_ALIGN);
1685fcf5ef2aSThomas Huth 
1686fcf5ef2aSThomas Huth             save_state(dc);
1687fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
1688ad75a51eSRichard Henderson             gen_helper_ld_asi(dst, tcg_env, addr, r_asi, r_mop);
1689fcf5ef2aSThomas Huth #else
1690fcf5ef2aSThomas Huth             {
1691fcf5ef2aSThomas Huth                 TCGv_i64 t64 = tcg_temp_new_i64();
1692ad75a51eSRichard Henderson                 gen_helper_ld_asi(t64, tcg_env, addr, r_asi, r_mop);
1693fcf5ef2aSThomas Huth                 tcg_gen_trunc_i64_tl(dst, t64);
1694fcf5ef2aSThomas Huth             }
1695fcf5ef2aSThomas Huth #endif
1696fcf5ef2aSThomas Huth         }
1697fcf5ef2aSThomas Huth         break;
1698fcf5ef2aSThomas Huth     }
1699fcf5ef2aSThomas Huth }
1700fcf5ef2aSThomas Huth 
170142071fc1SRichard Henderson static void gen_st_asi(DisasContext *dc, DisasASI *da, TCGv src, TCGv addr)
1702c03a0fd1SRichard Henderson {
1703c03a0fd1SRichard Henderson     switch (da->type) {
1704fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
1705fcf5ef2aSThomas Huth         break;
1706c03a0fd1SRichard Henderson 
1707fcf5ef2aSThomas Huth     case GET_ASI_DTWINX: /* Reserved for stda.  */
1708c03a0fd1SRichard Henderson         if (TARGET_LONG_BITS == 32) {
1709fcf5ef2aSThomas Huth             gen_exception(dc, TT_ILL_INSN);
1710fcf5ef2aSThomas Huth             break;
1711c03a0fd1SRichard Henderson         } else if (!(dc->def->features & CPU_FEATURE_HYPV)) {
17123390537bSArtyom Tarasenko             /* Pre OpenSPARC CPUs don't have these */
17133390537bSArtyom Tarasenko             gen_exception(dc, TT_ILL_INSN);
1714fcf5ef2aSThomas Huth             break;
1715c03a0fd1SRichard Henderson         }
1716c03a0fd1SRichard Henderson         /* In OpenSPARC T1+ CPUs TWINX ASIs in store are ST_BLKINIT_ ASIs */
1717c03a0fd1SRichard Henderson         /* fall through */
1718c03a0fd1SRichard Henderson 
1719c03a0fd1SRichard Henderson     case GET_ASI_DIRECT:
1720c03a0fd1SRichard Henderson         tcg_gen_qemu_st_tl(src, addr, da->mem_idx, da->memop | MO_ALIGN);
1721c03a0fd1SRichard Henderson         break;
1722c03a0fd1SRichard Henderson 
1723fcf5ef2aSThomas Huth     case GET_ASI_BCOPY:
1724c03a0fd1SRichard Henderson         assert(TARGET_LONG_BITS == 32);
172598271007SRichard Henderson         /*
172698271007SRichard Henderson          * Copy 32 bytes from the address in SRC to ADDR.
172798271007SRichard Henderson          *
172898271007SRichard Henderson          * From Ross RT625 hyperSPARC manual, section 4.6:
172998271007SRichard Henderson          * "Block Copy and Block Fill will work only on cache line boundaries."
173098271007SRichard Henderson          *
173198271007SRichard Henderson          * It does not specify if an unaliged address is truncated or trapped.
173298271007SRichard Henderson          * Previous qemu behaviour was to truncate to 4 byte alignment, which
173398271007SRichard Henderson          * is obviously wrong.  The only place I can see this used is in the
173498271007SRichard Henderson          * Linux kernel which begins with page alignment, advancing by 32,
173598271007SRichard Henderson          * so is always aligned.  Assume truncation as the simpler option.
173698271007SRichard Henderson          *
173798271007SRichard Henderson          * Since the loads and stores are paired, allow the copy to happen
173898271007SRichard Henderson          * in the host endianness.  The copy need not be atomic.
173998271007SRichard Henderson          */
1740fcf5ef2aSThomas Huth         {
174198271007SRichard Henderson             MemOp mop = MO_128 | MO_ATOM_IFALIGN_PAIR;
1742fcf5ef2aSThomas Huth             TCGv saddr = tcg_temp_new();
1743fcf5ef2aSThomas Huth             TCGv daddr = tcg_temp_new();
174498271007SRichard Henderson             TCGv_i128 tmp = tcg_temp_new_i128();
1745fcf5ef2aSThomas Huth 
174698271007SRichard Henderson             tcg_gen_andi_tl(saddr, src, -32);
174798271007SRichard Henderson             tcg_gen_andi_tl(daddr, addr, -32);
174898271007SRichard Henderson             tcg_gen_qemu_ld_i128(tmp, saddr, da->mem_idx, mop);
174998271007SRichard Henderson             tcg_gen_qemu_st_i128(tmp, daddr, da->mem_idx, mop);
175098271007SRichard Henderson             tcg_gen_addi_tl(saddr, saddr, 16);
175198271007SRichard Henderson             tcg_gen_addi_tl(daddr, daddr, 16);
175298271007SRichard Henderson             tcg_gen_qemu_ld_i128(tmp, saddr, da->mem_idx, mop);
175398271007SRichard Henderson             tcg_gen_qemu_st_i128(tmp, daddr, da->mem_idx, mop);
1754fcf5ef2aSThomas Huth         }
1755fcf5ef2aSThomas Huth         break;
1756c03a0fd1SRichard Henderson 
1757fcf5ef2aSThomas Huth     default:
1758fcf5ef2aSThomas Huth         {
1759c03a0fd1SRichard Henderson             TCGv_i32 r_asi = tcg_constant_i32(da->asi);
1760c03a0fd1SRichard Henderson             TCGv_i32 r_mop = tcg_constant_i32(da->memop | MO_ALIGN);
1761fcf5ef2aSThomas Huth 
1762fcf5ef2aSThomas Huth             save_state(dc);
1763fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
1764ad75a51eSRichard Henderson             gen_helper_st_asi(tcg_env, addr, src, r_asi, r_mop);
1765fcf5ef2aSThomas Huth #else
1766fcf5ef2aSThomas Huth             {
1767fcf5ef2aSThomas Huth                 TCGv_i64 t64 = tcg_temp_new_i64();
1768fcf5ef2aSThomas Huth                 tcg_gen_extu_tl_i64(t64, src);
1769ad75a51eSRichard Henderson                 gen_helper_st_asi(tcg_env, addr, t64, r_asi, r_mop);
1770fcf5ef2aSThomas Huth             }
1771fcf5ef2aSThomas Huth #endif
1772fcf5ef2aSThomas Huth 
1773fcf5ef2aSThomas Huth             /* A write to a TLB register may alter page maps.  End the TB. */
1774fcf5ef2aSThomas Huth             dc->npc = DYNAMIC_PC;
1775fcf5ef2aSThomas Huth         }
1776fcf5ef2aSThomas Huth         break;
1777fcf5ef2aSThomas Huth     }
1778fcf5ef2aSThomas Huth }
1779fcf5ef2aSThomas Huth 
1780dca544b9SRichard Henderson static void gen_swap_asi(DisasContext *dc, DisasASI *da,
1781c03a0fd1SRichard Henderson                          TCGv dst, TCGv src, TCGv addr)
1782c03a0fd1SRichard Henderson {
1783c03a0fd1SRichard Henderson     switch (da->type) {
1784c03a0fd1SRichard Henderson     case GET_ASI_EXCP:
1785c03a0fd1SRichard Henderson         break;
1786c03a0fd1SRichard Henderson     case GET_ASI_DIRECT:
1787dca544b9SRichard Henderson         tcg_gen_atomic_xchg_tl(dst, addr, src,
1788dca544b9SRichard Henderson                                da->mem_idx, da->memop | MO_ALIGN);
1789c03a0fd1SRichard Henderson         break;
1790c03a0fd1SRichard Henderson     default:
1791c03a0fd1SRichard Henderson         /* ??? Should be DAE_invalid_asi.  */
1792c03a0fd1SRichard Henderson         gen_exception(dc, TT_DATA_ACCESS);
1793c03a0fd1SRichard Henderson         break;
1794c03a0fd1SRichard Henderson     }
1795c03a0fd1SRichard Henderson }
1796c03a0fd1SRichard Henderson 
1797d0a11d25SRichard Henderson static void gen_cas_asi(DisasContext *dc, DisasASI *da,
1798c03a0fd1SRichard Henderson                         TCGv oldv, TCGv newv, TCGv cmpv, TCGv addr)
1799c03a0fd1SRichard Henderson {
1800c03a0fd1SRichard Henderson     switch (da->type) {
1801fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
1802c03a0fd1SRichard Henderson         return;
1803fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
1804c03a0fd1SRichard Henderson         tcg_gen_atomic_cmpxchg_tl(oldv, addr, cmpv, newv,
1805c03a0fd1SRichard Henderson                                   da->mem_idx, da->memop | MO_ALIGN);
1806fcf5ef2aSThomas Huth         break;
1807fcf5ef2aSThomas Huth     default:
1808fcf5ef2aSThomas Huth         /* ??? Should be DAE_invalid_asi.  */
1809fcf5ef2aSThomas Huth         gen_exception(dc, TT_DATA_ACCESS);
1810fcf5ef2aSThomas Huth         break;
1811fcf5ef2aSThomas Huth     }
1812fcf5ef2aSThomas Huth }
1813fcf5ef2aSThomas Huth 
1814cf07cd1eSRichard Henderson static void gen_ldstub_asi(DisasContext *dc, DisasASI *da, TCGv dst, TCGv addr)
1815c03a0fd1SRichard Henderson {
1816c03a0fd1SRichard Henderson     switch (da->type) {
1817fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
1818fcf5ef2aSThomas Huth         break;
1819fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
1820cf07cd1eSRichard Henderson         tcg_gen_atomic_xchg_tl(dst, addr, tcg_constant_tl(0xff),
1821cf07cd1eSRichard Henderson                                da->mem_idx, MO_UB);
1822fcf5ef2aSThomas Huth         break;
1823fcf5ef2aSThomas Huth     default:
18243db010c3SRichard Henderson         /* ??? In theory, this should be raise DAE_invalid_asi.
18253db010c3SRichard Henderson            But the SS-20 roms do ldstuba [%l0] #ASI_M_CTL, %o1.  */
1826af00be49SEmilio G. Cota         if (tb_cflags(dc->base.tb) & CF_PARALLEL) {
1827ad75a51eSRichard Henderson             gen_helper_exit_atomic(tcg_env);
18283db010c3SRichard Henderson         } else {
1829c03a0fd1SRichard Henderson             TCGv_i32 r_asi = tcg_constant_i32(da->asi);
183000ab7e61SRichard Henderson             TCGv_i32 r_mop = tcg_constant_i32(MO_UB);
18313db010c3SRichard Henderson             TCGv_i64 s64, t64;
18323db010c3SRichard Henderson 
18333db010c3SRichard Henderson             save_state(dc);
18343db010c3SRichard Henderson             t64 = tcg_temp_new_i64();
1835ad75a51eSRichard Henderson             gen_helper_ld_asi(t64, tcg_env, addr, r_asi, r_mop);
18363db010c3SRichard Henderson 
183700ab7e61SRichard Henderson             s64 = tcg_constant_i64(0xff);
1838ad75a51eSRichard Henderson             gen_helper_st_asi(tcg_env, addr, s64, r_asi, r_mop);
18393db010c3SRichard Henderson 
18403db010c3SRichard Henderson             tcg_gen_trunc_i64_tl(dst, t64);
18413db010c3SRichard Henderson 
18423db010c3SRichard Henderson             /* End the TB.  */
18433db010c3SRichard Henderson             dc->npc = DYNAMIC_PC;
18443db010c3SRichard Henderson         }
1845fcf5ef2aSThomas Huth         break;
1846fcf5ef2aSThomas Huth     }
1847fcf5ef2aSThomas Huth }
1848fcf5ef2aSThomas Huth 
1849287b1152SRichard Henderson static void gen_ldf_asi(DisasContext *dc, DisasASI *da, MemOp orig_size,
18503259b9e2SRichard Henderson                         TCGv addr, int rd)
1851fcf5ef2aSThomas Huth {
18523259b9e2SRichard Henderson     MemOp memop = da->memop;
18533259b9e2SRichard Henderson     MemOp size = memop & MO_SIZE;
1854fcf5ef2aSThomas Huth     TCGv_i32 d32;
1855fcf5ef2aSThomas Huth     TCGv_i64 d64;
1856287b1152SRichard Henderson     TCGv addr_tmp;
1857fcf5ef2aSThomas Huth 
18583259b9e2SRichard Henderson     /* TODO: Use 128-bit load/store below. */
18593259b9e2SRichard Henderson     if (size == MO_128) {
18603259b9e2SRichard Henderson         memop = (memop & ~MO_SIZE) | MO_64;
18613259b9e2SRichard Henderson     }
18623259b9e2SRichard Henderson 
18633259b9e2SRichard Henderson     switch (da->type) {
1864fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
1865fcf5ef2aSThomas Huth         break;
1866fcf5ef2aSThomas Huth 
1867fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
18683259b9e2SRichard Henderson         memop |= MO_ALIGN_4;
1869fcf5ef2aSThomas Huth         switch (size) {
18703259b9e2SRichard Henderson         case MO_32:
1871*388a6465SRichard Henderson             d32 = tcg_temp_new_i32();
18723259b9e2SRichard Henderson             tcg_gen_qemu_ld_i32(d32, addr, da->mem_idx, memop);
1873fcf5ef2aSThomas Huth             gen_store_fpr_F(dc, rd, d32);
1874fcf5ef2aSThomas Huth             break;
18753259b9e2SRichard Henderson 
18763259b9e2SRichard Henderson         case MO_64:
18773259b9e2SRichard Henderson             tcg_gen_qemu_ld_i64(cpu_fpr[rd / 2], addr, da->mem_idx, memop);
1878fcf5ef2aSThomas Huth             break;
18793259b9e2SRichard Henderson 
18803259b9e2SRichard Henderson         case MO_128:
1881fcf5ef2aSThomas Huth             d64 = tcg_temp_new_i64();
18823259b9e2SRichard Henderson             tcg_gen_qemu_ld_i64(d64, addr, da->mem_idx, memop);
1883287b1152SRichard Henderson             addr_tmp = tcg_temp_new();
1884287b1152SRichard Henderson             tcg_gen_addi_tl(addr_tmp, addr, 8);
1885287b1152SRichard Henderson             tcg_gen_qemu_ld_i64(cpu_fpr[rd / 2 + 1], addr_tmp, da->mem_idx, memop);
1886fcf5ef2aSThomas Huth             tcg_gen_mov_i64(cpu_fpr[rd / 2], d64);
1887fcf5ef2aSThomas Huth             break;
1888fcf5ef2aSThomas Huth         default:
1889fcf5ef2aSThomas Huth             g_assert_not_reached();
1890fcf5ef2aSThomas Huth         }
1891fcf5ef2aSThomas Huth         break;
1892fcf5ef2aSThomas Huth 
1893fcf5ef2aSThomas Huth     case GET_ASI_BLOCK:
1894fcf5ef2aSThomas Huth         /* Valid for lddfa on aligned registers only.  */
18953259b9e2SRichard Henderson         if (orig_size == MO_64 && (rd & 7) == 0) {
1896fcf5ef2aSThomas Huth             /* The first operation checks required alignment.  */
1897287b1152SRichard Henderson             addr_tmp = tcg_temp_new();
1898287b1152SRichard Henderson             for (int i = 0; ; ++i) {
18993259b9e2SRichard Henderson                 tcg_gen_qemu_ld_i64(cpu_fpr[rd / 2 + i], addr, da->mem_idx,
19003259b9e2SRichard Henderson                                     memop | (i == 0 ? MO_ALIGN_64 : 0));
1901fcf5ef2aSThomas Huth                 if (i == 7) {
1902fcf5ef2aSThomas Huth                     break;
1903fcf5ef2aSThomas Huth                 }
1904287b1152SRichard Henderson                 tcg_gen_addi_tl(addr_tmp, addr, 8);
1905287b1152SRichard Henderson                 addr = addr_tmp;
1906fcf5ef2aSThomas Huth             }
1907fcf5ef2aSThomas Huth         } else {
1908fcf5ef2aSThomas Huth             gen_exception(dc, TT_ILL_INSN);
1909fcf5ef2aSThomas Huth         }
1910fcf5ef2aSThomas Huth         break;
1911fcf5ef2aSThomas Huth 
1912fcf5ef2aSThomas Huth     case GET_ASI_SHORT:
1913fcf5ef2aSThomas Huth         /* Valid for lddfa only.  */
19143259b9e2SRichard Henderson         if (orig_size == MO_64) {
19153259b9e2SRichard Henderson             tcg_gen_qemu_ld_i64(cpu_fpr[rd / 2], addr, da->mem_idx,
19163259b9e2SRichard Henderson                                 memop | MO_ALIGN);
1917fcf5ef2aSThomas Huth         } else {
1918fcf5ef2aSThomas Huth             gen_exception(dc, TT_ILL_INSN);
1919fcf5ef2aSThomas Huth         }
1920fcf5ef2aSThomas Huth         break;
1921fcf5ef2aSThomas Huth 
1922fcf5ef2aSThomas Huth     default:
1923fcf5ef2aSThomas Huth         {
19243259b9e2SRichard Henderson             TCGv_i32 r_asi = tcg_constant_i32(da->asi);
19253259b9e2SRichard Henderson             TCGv_i32 r_mop = tcg_constant_i32(memop | MO_ALIGN);
1926fcf5ef2aSThomas Huth 
1927fcf5ef2aSThomas Huth             save_state(dc);
1928fcf5ef2aSThomas Huth             /* According to the table in the UA2011 manual, the only
1929fcf5ef2aSThomas Huth                other asis that are valid for ldfa/lddfa/ldqfa are
1930fcf5ef2aSThomas Huth                the NO_FAULT asis.  We still need a helper for these,
1931fcf5ef2aSThomas Huth                but we can just use the integer asi helper for them.  */
1932fcf5ef2aSThomas Huth             switch (size) {
19333259b9e2SRichard Henderson             case MO_32:
1934fcf5ef2aSThomas Huth                 d64 = tcg_temp_new_i64();
1935ad75a51eSRichard Henderson                 gen_helper_ld_asi(d64, tcg_env, addr, r_asi, r_mop);
1936*388a6465SRichard Henderson                 d32 = tcg_temp_new_i32();
1937fcf5ef2aSThomas Huth                 tcg_gen_extrl_i64_i32(d32, d64);
1938fcf5ef2aSThomas Huth                 gen_store_fpr_F(dc, rd, d32);
1939fcf5ef2aSThomas Huth                 break;
19403259b9e2SRichard Henderson             case MO_64:
19413259b9e2SRichard Henderson                 gen_helper_ld_asi(cpu_fpr[rd / 2], tcg_env, addr,
19423259b9e2SRichard Henderson                                   r_asi, r_mop);
1943fcf5ef2aSThomas Huth                 break;
19443259b9e2SRichard Henderson             case MO_128:
1945fcf5ef2aSThomas Huth                 d64 = tcg_temp_new_i64();
1946ad75a51eSRichard Henderson                 gen_helper_ld_asi(d64, tcg_env, addr, r_asi, r_mop);
1947287b1152SRichard Henderson                 addr_tmp = tcg_temp_new();
1948287b1152SRichard Henderson                 tcg_gen_addi_tl(addr_tmp, addr, 8);
1949287b1152SRichard Henderson                 gen_helper_ld_asi(cpu_fpr[rd / 2 + 1], tcg_env, addr_tmp,
19503259b9e2SRichard Henderson                                   r_asi, r_mop);
1951fcf5ef2aSThomas Huth                 tcg_gen_mov_i64(cpu_fpr[rd / 2], d64);
1952fcf5ef2aSThomas Huth                 break;
1953fcf5ef2aSThomas Huth             default:
1954fcf5ef2aSThomas Huth                 g_assert_not_reached();
1955fcf5ef2aSThomas Huth             }
1956fcf5ef2aSThomas Huth         }
1957fcf5ef2aSThomas Huth         break;
1958fcf5ef2aSThomas Huth     }
1959fcf5ef2aSThomas Huth }
1960fcf5ef2aSThomas Huth 
1961287b1152SRichard Henderson static void gen_stf_asi(DisasContext *dc, DisasASI *da, MemOp orig_size,
19623259b9e2SRichard Henderson                         TCGv addr, int rd)
19633259b9e2SRichard Henderson {
19643259b9e2SRichard Henderson     MemOp memop = da->memop;
19653259b9e2SRichard Henderson     MemOp size = memop & MO_SIZE;
1966fcf5ef2aSThomas Huth     TCGv_i32 d32;
1967287b1152SRichard Henderson     TCGv addr_tmp;
1968fcf5ef2aSThomas Huth 
19693259b9e2SRichard Henderson     /* TODO: Use 128-bit load/store below. */
19703259b9e2SRichard Henderson     if (size == MO_128) {
19713259b9e2SRichard Henderson         memop = (memop & ~MO_SIZE) | MO_64;
19723259b9e2SRichard Henderson     }
19733259b9e2SRichard Henderson 
19743259b9e2SRichard Henderson     switch (da->type) {
1975fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
1976fcf5ef2aSThomas Huth         break;
1977fcf5ef2aSThomas Huth 
1978fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
19793259b9e2SRichard Henderson         memop |= MO_ALIGN_4;
1980fcf5ef2aSThomas Huth         switch (size) {
19813259b9e2SRichard Henderson         case MO_32:
1982fcf5ef2aSThomas Huth             d32 = gen_load_fpr_F(dc, rd);
19833259b9e2SRichard Henderson             tcg_gen_qemu_st_i32(d32, addr, da->mem_idx, memop | MO_ALIGN);
1984fcf5ef2aSThomas Huth             break;
19853259b9e2SRichard Henderson         case MO_64:
19863259b9e2SRichard Henderson             tcg_gen_qemu_st_i64(cpu_fpr[rd / 2], addr, da->mem_idx,
19873259b9e2SRichard Henderson                                 memop | MO_ALIGN_4);
1988fcf5ef2aSThomas Huth             break;
19893259b9e2SRichard Henderson         case MO_128:
1990fcf5ef2aSThomas Huth             /* Only 4-byte alignment required.  However, it is legal for the
1991fcf5ef2aSThomas Huth                cpu to signal the alignment fault, and the OS trap handler is
1992fcf5ef2aSThomas Huth                required to fix it up.  Requiring 16-byte alignment here avoids
1993fcf5ef2aSThomas Huth                having to probe the second page before performing the first
1994fcf5ef2aSThomas Huth                write.  */
19953259b9e2SRichard Henderson             tcg_gen_qemu_st_i64(cpu_fpr[rd / 2], addr, da->mem_idx,
19963259b9e2SRichard Henderson                                 memop | MO_ALIGN_16);
1997287b1152SRichard Henderson             addr_tmp = tcg_temp_new();
1998287b1152SRichard Henderson             tcg_gen_addi_tl(addr_tmp, addr, 8);
1999287b1152SRichard Henderson             tcg_gen_qemu_st_i64(cpu_fpr[rd / 2 + 1], addr_tmp, da->mem_idx, memop);
2000fcf5ef2aSThomas Huth             break;
2001fcf5ef2aSThomas Huth         default:
2002fcf5ef2aSThomas Huth             g_assert_not_reached();
2003fcf5ef2aSThomas Huth         }
2004fcf5ef2aSThomas Huth         break;
2005fcf5ef2aSThomas Huth 
2006fcf5ef2aSThomas Huth     case GET_ASI_BLOCK:
2007fcf5ef2aSThomas Huth         /* Valid for stdfa on aligned registers only.  */
20083259b9e2SRichard Henderson         if (orig_size == MO_64 && (rd & 7) == 0) {
2009fcf5ef2aSThomas Huth             /* The first operation checks required alignment.  */
2010287b1152SRichard Henderson             addr_tmp = tcg_temp_new();
2011287b1152SRichard Henderson             for (int i = 0; ; ++i) {
20123259b9e2SRichard Henderson                 tcg_gen_qemu_st_i64(cpu_fpr[rd / 2 + i], addr, da->mem_idx,
20133259b9e2SRichard Henderson                                     memop | (i == 0 ? MO_ALIGN_64 : 0));
2014fcf5ef2aSThomas Huth                 if (i == 7) {
2015fcf5ef2aSThomas Huth                     break;
2016fcf5ef2aSThomas Huth                 }
2017287b1152SRichard Henderson                 tcg_gen_addi_tl(addr_tmp, addr, 8);
2018287b1152SRichard Henderson                 addr = addr_tmp;
2019fcf5ef2aSThomas Huth             }
2020fcf5ef2aSThomas Huth         } else {
2021fcf5ef2aSThomas Huth             gen_exception(dc, TT_ILL_INSN);
2022fcf5ef2aSThomas Huth         }
2023fcf5ef2aSThomas Huth         break;
2024fcf5ef2aSThomas Huth 
2025fcf5ef2aSThomas Huth     case GET_ASI_SHORT:
2026fcf5ef2aSThomas Huth         /* Valid for stdfa only.  */
20273259b9e2SRichard Henderson         if (orig_size == MO_64) {
20283259b9e2SRichard Henderson             tcg_gen_qemu_st_i64(cpu_fpr[rd / 2], addr, da->mem_idx,
20293259b9e2SRichard Henderson                                 memop | MO_ALIGN);
2030fcf5ef2aSThomas Huth         } else {
2031fcf5ef2aSThomas Huth             gen_exception(dc, TT_ILL_INSN);
2032fcf5ef2aSThomas Huth         }
2033fcf5ef2aSThomas Huth         break;
2034fcf5ef2aSThomas Huth 
2035fcf5ef2aSThomas Huth     default:
2036fcf5ef2aSThomas Huth         /* According to the table in the UA2011 manual, the only
2037fcf5ef2aSThomas Huth            other asis that are valid for ldfa/lddfa/ldqfa are
2038fcf5ef2aSThomas Huth            the PST* asis, which aren't currently handled.  */
2039fcf5ef2aSThomas Huth         gen_exception(dc, TT_ILL_INSN);
2040fcf5ef2aSThomas Huth         break;
2041fcf5ef2aSThomas Huth     }
2042fcf5ef2aSThomas Huth }
2043fcf5ef2aSThomas Huth 
204442071fc1SRichard Henderson static void gen_ldda_asi(DisasContext *dc, DisasASI *da, TCGv addr, int rd)
2045fcf5ef2aSThomas Huth {
2046a76779eeSRichard Henderson     TCGv hi = gen_dest_gpr(dc, rd);
2047a76779eeSRichard Henderson     TCGv lo = gen_dest_gpr(dc, rd + 1);
2048fcf5ef2aSThomas Huth 
2049c03a0fd1SRichard Henderson     switch (da->type) {
2050fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
2051fcf5ef2aSThomas Huth         return;
2052fcf5ef2aSThomas Huth 
2053fcf5ef2aSThomas Huth     case GET_ASI_DTWINX:
2054ebbbec92SRichard Henderson #ifdef TARGET_SPARC64
2055ebbbec92SRichard Henderson         {
2056ebbbec92SRichard Henderson             MemOp mop = (da->memop & MO_BSWAP) | MO_128 | MO_ALIGN_16;
2057ebbbec92SRichard Henderson             TCGv_i128 t = tcg_temp_new_i128();
2058ebbbec92SRichard Henderson 
2059ebbbec92SRichard Henderson             tcg_gen_qemu_ld_i128(t, addr, da->mem_idx, mop);
2060ebbbec92SRichard Henderson             /*
2061ebbbec92SRichard Henderson              * Note that LE twinx acts as if each 64-bit register result is
2062ebbbec92SRichard Henderson              * byte swapped.  We perform one 128-bit LE load, so must swap
2063ebbbec92SRichard Henderson              * the order of the writebacks.
2064ebbbec92SRichard Henderson              */
2065ebbbec92SRichard Henderson             if ((mop & MO_BSWAP) == MO_TE) {
2066ebbbec92SRichard Henderson                 tcg_gen_extr_i128_i64(lo, hi, t);
2067ebbbec92SRichard Henderson             } else {
2068ebbbec92SRichard Henderson                 tcg_gen_extr_i128_i64(hi, lo, t);
2069ebbbec92SRichard Henderson             }
2070ebbbec92SRichard Henderson         }
2071fcf5ef2aSThomas Huth         break;
2072ebbbec92SRichard Henderson #else
2073ebbbec92SRichard Henderson         g_assert_not_reached();
2074ebbbec92SRichard Henderson #endif
2075fcf5ef2aSThomas Huth 
2076fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
2077fcf5ef2aSThomas Huth         {
2078fcf5ef2aSThomas Huth             TCGv_i64 tmp = tcg_temp_new_i64();
2079fcf5ef2aSThomas Huth 
2080c03a0fd1SRichard Henderson             tcg_gen_qemu_ld_i64(tmp, addr, da->mem_idx, da->memop | MO_ALIGN);
2081fcf5ef2aSThomas Huth 
2082fcf5ef2aSThomas Huth             /* Note that LE ldda acts as if each 32-bit register
2083fcf5ef2aSThomas Huth                result is byte swapped.  Having just performed one
2084fcf5ef2aSThomas Huth                64-bit bswap, we need now to swap the writebacks.  */
2085c03a0fd1SRichard Henderson             if ((da->memop & MO_BSWAP) == MO_TE) {
2086a76779eeSRichard Henderson                 tcg_gen_extr_i64_tl(lo, hi, tmp);
2087fcf5ef2aSThomas Huth             } else {
2088a76779eeSRichard Henderson                 tcg_gen_extr_i64_tl(hi, lo, tmp);
2089fcf5ef2aSThomas Huth             }
2090fcf5ef2aSThomas Huth         }
2091fcf5ef2aSThomas Huth         break;
2092fcf5ef2aSThomas Huth 
2093fcf5ef2aSThomas Huth     default:
2094fcf5ef2aSThomas Huth         /* ??? In theory we've handled all of the ASIs that are valid
2095fcf5ef2aSThomas Huth            for ldda, and this should raise DAE_invalid_asi.  However,
2096fcf5ef2aSThomas Huth            real hardware allows others.  This can be seen with e.g.
2097fcf5ef2aSThomas Huth            FreeBSD 10.3 wrt ASI_IC_TAG.  */
2098fcf5ef2aSThomas Huth         {
2099c03a0fd1SRichard Henderson             TCGv_i32 r_asi = tcg_constant_i32(da->asi);
2100c03a0fd1SRichard Henderson             TCGv_i32 r_mop = tcg_constant_i32(da->memop);
2101fcf5ef2aSThomas Huth             TCGv_i64 tmp = tcg_temp_new_i64();
2102fcf5ef2aSThomas Huth 
2103fcf5ef2aSThomas Huth             save_state(dc);
2104ad75a51eSRichard Henderson             gen_helper_ld_asi(tmp, tcg_env, addr, r_asi, r_mop);
2105fcf5ef2aSThomas Huth 
2106fcf5ef2aSThomas Huth             /* See above.  */
2107c03a0fd1SRichard Henderson             if ((da->memop & MO_BSWAP) == MO_TE) {
2108a76779eeSRichard Henderson                 tcg_gen_extr_i64_tl(lo, hi, tmp);
2109fcf5ef2aSThomas Huth             } else {
2110a76779eeSRichard Henderson                 tcg_gen_extr_i64_tl(hi, lo, tmp);
2111fcf5ef2aSThomas Huth             }
2112fcf5ef2aSThomas Huth         }
2113fcf5ef2aSThomas Huth         break;
2114fcf5ef2aSThomas Huth     }
2115fcf5ef2aSThomas Huth 
2116fcf5ef2aSThomas Huth     gen_store_gpr(dc, rd, hi);
2117fcf5ef2aSThomas Huth     gen_store_gpr(dc, rd + 1, lo);
2118fcf5ef2aSThomas Huth }
2119fcf5ef2aSThomas Huth 
212042071fc1SRichard Henderson static void gen_stda_asi(DisasContext *dc, DisasASI *da, TCGv addr, int rd)
2121c03a0fd1SRichard Henderson {
2122c03a0fd1SRichard Henderson     TCGv hi = gen_load_gpr(dc, rd);
2123fcf5ef2aSThomas Huth     TCGv lo = gen_load_gpr(dc, rd + 1);
2124fcf5ef2aSThomas Huth 
2125c03a0fd1SRichard Henderson     switch (da->type) {
2126fcf5ef2aSThomas Huth     case GET_ASI_EXCP:
2127fcf5ef2aSThomas Huth         break;
2128fcf5ef2aSThomas Huth 
2129fcf5ef2aSThomas Huth     case GET_ASI_DTWINX:
2130ebbbec92SRichard Henderson #ifdef TARGET_SPARC64
2131ebbbec92SRichard Henderson         {
2132ebbbec92SRichard Henderson             MemOp mop = (da->memop & MO_BSWAP) | MO_128 | MO_ALIGN_16;
2133ebbbec92SRichard Henderson             TCGv_i128 t = tcg_temp_new_i128();
2134ebbbec92SRichard Henderson 
2135ebbbec92SRichard Henderson             /*
2136ebbbec92SRichard Henderson              * Note that LE twinx acts as if each 64-bit register result is
2137ebbbec92SRichard Henderson              * byte swapped.  We perform one 128-bit LE store, so must swap
2138ebbbec92SRichard Henderson              * the order of the construction.
2139ebbbec92SRichard Henderson              */
2140ebbbec92SRichard Henderson             if ((mop & MO_BSWAP) == MO_TE) {
2141ebbbec92SRichard Henderson                 tcg_gen_concat_i64_i128(t, lo, hi);
2142ebbbec92SRichard Henderson             } else {
2143ebbbec92SRichard Henderson                 tcg_gen_concat_i64_i128(t, hi, lo);
2144ebbbec92SRichard Henderson             }
2145ebbbec92SRichard Henderson             tcg_gen_qemu_st_i128(t, addr, da->mem_idx, mop);
2146ebbbec92SRichard Henderson         }
2147fcf5ef2aSThomas Huth         break;
2148ebbbec92SRichard Henderson #else
2149ebbbec92SRichard Henderson         g_assert_not_reached();
2150ebbbec92SRichard Henderson #endif
2151fcf5ef2aSThomas Huth 
2152fcf5ef2aSThomas Huth     case GET_ASI_DIRECT:
2153fcf5ef2aSThomas Huth         {
2154fcf5ef2aSThomas Huth             TCGv_i64 t64 = tcg_temp_new_i64();
2155fcf5ef2aSThomas Huth 
2156fcf5ef2aSThomas Huth             /* Note that LE stda acts as if each 32-bit register result is
2157fcf5ef2aSThomas Huth                byte swapped.  We will perform one 64-bit LE store, so now
2158fcf5ef2aSThomas Huth                we must swap the order of the construction.  */
2159c03a0fd1SRichard Henderson             if ((da->memop & MO_BSWAP) == MO_TE) {
2160a76779eeSRichard Henderson                 tcg_gen_concat_tl_i64(t64, lo, hi);
2161fcf5ef2aSThomas Huth             } else {
2162a76779eeSRichard Henderson                 tcg_gen_concat_tl_i64(t64, hi, lo);
2163fcf5ef2aSThomas Huth             }
2164c03a0fd1SRichard Henderson             tcg_gen_qemu_st_i64(t64, addr, da->mem_idx, da->memop | MO_ALIGN);
2165fcf5ef2aSThomas Huth         }
2166fcf5ef2aSThomas Huth         break;
2167fcf5ef2aSThomas Huth 
2168a76779eeSRichard Henderson     case GET_ASI_BFILL:
2169a76779eeSRichard Henderson         assert(TARGET_LONG_BITS == 32);
217054c3e953SRichard Henderson         /*
217154c3e953SRichard Henderson          * Store 32 bytes of [rd:rd+1] to ADDR.
217254c3e953SRichard Henderson          * See comments for GET_ASI_COPY above.
217354c3e953SRichard Henderson          */
2174a76779eeSRichard Henderson         {
217554c3e953SRichard Henderson             MemOp mop = MO_TE | MO_128 | MO_ATOM_IFALIGN_PAIR;
217654c3e953SRichard Henderson             TCGv_i64 t8 = tcg_temp_new_i64();
217754c3e953SRichard Henderson             TCGv_i128 t16 = tcg_temp_new_i128();
217854c3e953SRichard Henderson             TCGv daddr = tcg_temp_new();
2179a76779eeSRichard Henderson 
218054c3e953SRichard Henderson             tcg_gen_concat_tl_i64(t8, lo, hi);
218154c3e953SRichard Henderson             tcg_gen_concat_i64_i128(t16, t8, t8);
218254c3e953SRichard Henderson             tcg_gen_andi_tl(daddr, addr, -32);
218354c3e953SRichard Henderson             tcg_gen_qemu_st_i128(t16, daddr, da->mem_idx, mop);
218454c3e953SRichard Henderson             tcg_gen_addi_tl(daddr, daddr, 16);
218554c3e953SRichard Henderson             tcg_gen_qemu_st_i128(t16, daddr, da->mem_idx, mop);
2186a76779eeSRichard Henderson         }
2187a76779eeSRichard Henderson         break;
2188a76779eeSRichard Henderson 
2189fcf5ef2aSThomas Huth     default:
2190fcf5ef2aSThomas Huth         /* ??? In theory we've handled all of the ASIs that are valid
2191fcf5ef2aSThomas Huth            for stda, and this should raise DAE_invalid_asi.  */
2192fcf5ef2aSThomas Huth         {
2193c03a0fd1SRichard Henderson             TCGv_i32 r_asi = tcg_constant_i32(da->asi);
2194c03a0fd1SRichard Henderson             TCGv_i32 r_mop = tcg_constant_i32(da->memop);
2195fcf5ef2aSThomas Huth             TCGv_i64 t64 = tcg_temp_new_i64();
2196fcf5ef2aSThomas Huth 
2197fcf5ef2aSThomas Huth             /* See above.  */
2198c03a0fd1SRichard Henderson             if ((da->memop & MO_BSWAP) == MO_TE) {
2199a76779eeSRichard Henderson                 tcg_gen_concat_tl_i64(t64, lo, hi);
2200fcf5ef2aSThomas Huth             } else {
2201a76779eeSRichard Henderson                 tcg_gen_concat_tl_i64(t64, hi, lo);
2202fcf5ef2aSThomas Huth             }
2203fcf5ef2aSThomas Huth 
2204fcf5ef2aSThomas Huth             save_state(dc);
2205ad75a51eSRichard Henderson             gen_helper_st_asi(tcg_env, addr, t64, r_asi, r_mop);
2206fcf5ef2aSThomas Huth         }
2207fcf5ef2aSThomas Huth         break;
2208fcf5ef2aSThomas Huth     }
2209fcf5ef2aSThomas Huth }
2210fcf5ef2aSThomas Huth 
2211fcf5ef2aSThomas Huth static void gen_fmovs(DisasContext *dc, DisasCompare *cmp, int rd, int rs)
2212fcf5ef2aSThomas Huth {
2213f7ec8155SRichard Henderson #ifdef TARGET_SPARC64
2214fcf5ef2aSThomas Huth     TCGv_i32 c32, zero, dst, s1, s2;
2215dd7dbfccSRichard Henderson     TCGv_i64 c64 = tcg_temp_new_i64();
2216fcf5ef2aSThomas Huth 
2217fcf5ef2aSThomas Huth     /* We have two choices here: extend the 32 bit data and use movcond_i64,
2218fcf5ef2aSThomas Huth        or fold the comparison down to 32 bits and use movcond_i32.  Choose
2219fcf5ef2aSThomas Huth        the later.  */
2220fcf5ef2aSThomas Huth     c32 = tcg_temp_new_i32();
2221c8507ebfSRichard Henderson     tcg_gen_setcondi_i64(cmp->cond, c64, cmp->c1, cmp->c2);
2222fcf5ef2aSThomas Huth     tcg_gen_extrl_i64_i32(c32, c64);
2223fcf5ef2aSThomas Huth 
2224fcf5ef2aSThomas Huth     s1 = gen_load_fpr_F(dc, rs);
2225fcf5ef2aSThomas Huth     s2 = gen_load_fpr_F(dc, rd);
2226*388a6465SRichard Henderson     dst = tcg_temp_new_i32();
222700ab7e61SRichard Henderson     zero = tcg_constant_i32(0);
2228fcf5ef2aSThomas Huth 
2229fcf5ef2aSThomas Huth     tcg_gen_movcond_i32(TCG_COND_NE, dst, c32, zero, s1, s2);
2230fcf5ef2aSThomas Huth 
2231fcf5ef2aSThomas Huth     gen_store_fpr_F(dc, rd, dst);
2232f7ec8155SRichard Henderson #else
2233f7ec8155SRichard Henderson     qemu_build_not_reached();
2234f7ec8155SRichard Henderson #endif
2235fcf5ef2aSThomas Huth }
2236fcf5ef2aSThomas Huth 
2237fcf5ef2aSThomas Huth static void gen_fmovd(DisasContext *dc, DisasCompare *cmp, int rd, int rs)
2238fcf5ef2aSThomas Huth {
2239f7ec8155SRichard Henderson #ifdef TARGET_SPARC64
2240fcf5ef2aSThomas Huth     TCGv_i64 dst = gen_dest_fpr_D(dc, rd);
2241c8507ebfSRichard Henderson     tcg_gen_movcond_i64(cmp->cond, dst, cmp->c1, tcg_constant_tl(cmp->c2),
2242fcf5ef2aSThomas Huth                         gen_load_fpr_D(dc, rs),
2243fcf5ef2aSThomas Huth                         gen_load_fpr_D(dc, rd));
2244fcf5ef2aSThomas Huth     gen_store_fpr_D(dc, rd, dst);
2245f7ec8155SRichard Henderson #else
2246f7ec8155SRichard Henderson     qemu_build_not_reached();
2247f7ec8155SRichard Henderson #endif
2248fcf5ef2aSThomas Huth }
2249fcf5ef2aSThomas Huth 
2250fcf5ef2aSThomas Huth static void gen_fmovq(DisasContext *dc, DisasCompare *cmp, int rd, int rs)
2251fcf5ef2aSThomas Huth {
2252f7ec8155SRichard Henderson #ifdef TARGET_SPARC64
2253fcf5ef2aSThomas Huth     int qd = QFPREG(rd);
2254fcf5ef2aSThomas Huth     int qs = QFPREG(rs);
2255c8507ebfSRichard Henderson     TCGv c2 = tcg_constant_tl(cmp->c2);
2256fcf5ef2aSThomas Huth 
2257c8507ebfSRichard Henderson     tcg_gen_movcond_i64(cmp->cond, cpu_fpr[qd / 2], cmp->c1, c2,
2258fcf5ef2aSThomas Huth                         cpu_fpr[qs / 2], cpu_fpr[qd / 2]);
2259c8507ebfSRichard Henderson     tcg_gen_movcond_i64(cmp->cond, cpu_fpr[qd / 2 + 1], cmp->c1, c2,
2260fcf5ef2aSThomas Huth                         cpu_fpr[qs / 2 + 1], cpu_fpr[qd / 2 + 1]);
2261fcf5ef2aSThomas Huth 
2262fcf5ef2aSThomas Huth     gen_update_fprs_dirty(dc, qd);
2263f7ec8155SRichard Henderson #else
2264f7ec8155SRichard Henderson     qemu_build_not_reached();
2265f7ec8155SRichard Henderson #endif
2266fcf5ef2aSThomas Huth }
2267fcf5ef2aSThomas Huth 
2268f7ec8155SRichard Henderson #ifdef TARGET_SPARC64
22695d617bfbSRichard Henderson static void gen_load_trap_state_at_tl(TCGv_ptr r_tsptr)
2270fcf5ef2aSThomas Huth {
2271fcf5ef2aSThomas Huth     TCGv_i32 r_tl = tcg_temp_new_i32();
2272fcf5ef2aSThomas Huth 
2273fcf5ef2aSThomas Huth     /* load env->tl into r_tl */
2274ad75a51eSRichard Henderson     tcg_gen_ld_i32(r_tl, tcg_env, offsetof(CPUSPARCState, tl));
2275fcf5ef2aSThomas Huth 
2276fcf5ef2aSThomas Huth     /* tl = [0 ... MAXTL_MASK] where MAXTL_MASK must be power of 2 */
2277fcf5ef2aSThomas Huth     tcg_gen_andi_i32(r_tl, r_tl, MAXTL_MASK);
2278fcf5ef2aSThomas Huth 
2279fcf5ef2aSThomas Huth     /* calculate offset to current trap state from env->ts, reuse r_tl */
2280fcf5ef2aSThomas Huth     tcg_gen_muli_i32(r_tl, r_tl, sizeof (trap_state));
2281ad75a51eSRichard Henderson     tcg_gen_addi_ptr(r_tsptr, tcg_env, offsetof(CPUSPARCState, ts));
2282fcf5ef2aSThomas Huth 
2283fcf5ef2aSThomas Huth     /* tsptr = env->ts[env->tl & MAXTL_MASK] */
2284fcf5ef2aSThomas Huth     {
2285fcf5ef2aSThomas Huth         TCGv_ptr r_tl_tmp = tcg_temp_new_ptr();
2286fcf5ef2aSThomas Huth         tcg_gen_ext_i32_ptr(r_tl_tmp, r_tl);
2287fcf5ef2aSThomas Huth         tcg_gen_add_ptr(r_tsptr, r_tsptr, r_tl_tmp);
2288fcf5ef2aSThomas Huth     }
2289fcf5ef2aSThomas Huth }
2290fcf5ef2aSThomas Huth #endif
2291fcf5ef2aSThomas Huth 
229206c060d9SRichard Henderson static int extract_dfpreg(DisasContext *dc, int x)
229306c060d9SRichard Henderson {
229406c060d9SRichard Henderson     return DFPREG(x);
229506c060d9SRichard Henderson }
229606c060d9SRichard Henderson 
229706c060d9SRichard Henderson static int extract_qfpreg(DisasContext *dc, int x)
229806c060d9SRichard Henderson {
229906c060d9SRichard Henderson     return QFPREG(x);
230006c060d9SRichard Henderson }
230106c060d9SRichard Henderson 
2302878cc677SRichard Henderson /* Include the auto-generated decoder.  */
2303878cc677SRichard Henderson #include "decode-insns.c.inc"
2304878cc677SRichard Henderson 
2305878cc677SRichard Henderson #define TRANS(NAME, AVAIL, FUNC, ...) \
2306878cc677SRichard Henderson     static bool trans_##NAME(DisasContext *dc, arg_##NAME *a) \
2307878cc677SRichard Henderson     { return avail_##AVAIL(dc) && FUNC(dc, __VA_ARGS__); }
2308878cc677SRichard Henderson 
2309878cc677SRichard Henderson #define avail_ALL(C)      true
2310878cc677SRichard Henderson #ifdef TARGET_SPARC64
2311878cc677SRichard Henderson # define avail_32(C)      false
2312af25071cSRichard Henderson # define avail_ASR17(C)   false
2313d0a11d25SRichard Henderson # define avail_CASA(C)    true
2314c2636853SRichard Henderson # define avail_DIV(C)     true
2315b5372650SRichard Henderson # define avail_MUL(C)     true
23160faef01bSRichard Henderson # define avail_POWERDOWN(C) false
2317878cc677SRichard Henderson # define avail_64(C)      true
23185d617bfbSRichard Henderson # define avail_GL(C)      ((C)->def->features & CPU_FEATURE_GL)
2319af25071cSRichard Henderson # define avail_HYPV(C)    ((C)->def->features & CPU_FEATURE_HYPV)
2320b88ce6f2SRichard Henderson # define avail_VIS1(C)    ((C)->def->features & CPU_FEATURE_VIS1)
2321b88ce6f2SRichard Henderson # define avail_VIS2(C)    ((C)->def->features & CPU_FEATURE_VIS2)
2322878cc677SRichard Henderson #else
2323878cc677SRichard Henderson # define avail_32(C)      true
2324af25071cSRichard Henderson # define avail_ASR17(C)   ((C)->def->features & CPU_FEATURE_ASR17)
2325d0a11d25SRichard Henderson # define avail_CASA(C)    ((C)->def->features & CPU_FEATURE_CASA)
2326c2636853SRichard Henderson # define avail_DIV(C)     ((C)->def->features & CPU_FEATURE_DIV)
2327b5372650SRichard Henderson # define avail_MUL(C)     ((C)->def->features & CPU_FEATURE_MUL)
23280faef01bSRichard Henderson # define avail_POWERDOWN(C) ((C)->def->features & CPU_FEATURE_POWERDOWN)
2329878cc677SRichard Henderson # define avail_64(C)      false
23305d617bfbSRichard Henderson # define avail_GL(C)      false
2331af25071cSRichard Henderson # define avail_HYPV(C)    false
2332b88ce6f2SRichard Henderson # define avail_VIS1(C)    false
2333b88ce6f2SRichard Henderson # define avail_VIS2(C)    false
2334878cc677SRichard Henderson #endif
2335878cc677SRichard Henderson 
2336878cc677SRichard Henderson /* Default case for non jump instructions. */
2337878cc677SRichard Henderson static bool advance_pc(DisasContext *dc)
2338878cc677SRichard Henderson {
23394a8d145dSRichard Henderson     TCGLabel *l1;
23404a8d145dSRichard Henderson 
234189527e3aSRichard Henderson     finishing_insn(dc);
234289527e3aSRichard Henderson 
2343878cc677SRichard Henderson     if (dc->npc & 3) {
2344878cc677SRichard Henderson         switch (dc->npc) {
2345878cc677SRichard Henderson         case DYNAMIC_PC:
2346878cc677SRichard Henderson         case DYNAMIC_PC_LOOKUP:
2347878cc677SRichard Henderson             dc->pc = dc->npc;
2348444d8b30SRichard Henderson             tcg_gen_mov_tl(cpu_pc, cpu_npc);
2349444d8b30SRichard Henderson             tcg_gen_addi_tl(cpu_npc, cpu_npc, 4);
2350878cc677SRichard Henderson             break;
23514a8d145dSRichard Henderson 
2352878cc677SRichard Henderson         case JUMP_PC:
2353878cc677SRichard Henderson             /* we can do a static jump */
23544a8d145dSRichard Henderson             l1 = gen_new_label();
2355533f042fSRichard Henderson             tcg_gen_brcondi_tl(dc->jump.cond, dc->jump.c1, dc->jump.c2, l1);
23564a8d145dSRichard Henderson 
23574a8d145dSRichard Henderson             /* jump not taken */
23584a8d145dSRichard Henderson             gen_goto_tb(dc, 1, dc->jump_pc[1], dc->jump_pc[1] + 4);
23594a8d145dSRichard Henderson 
23604a8d145dSRichard Henderson             /* jump taken */
23614a8d145dSRichard Henderson             gen_set_label(l1);
23624a8d145dSRichard Henderson             gen_goto_tb(dc, 0, dc->jump_pc[0], dc->jump_pc[0] + 4);
23634a8d145dSRichard Henderson 
2364878cc677SRichard Henderson             dc->base.is_jmp = DISAS_NORETURN;
2365878cc677SRichard Henderson             break;
23664a8d145dSRichard Henderson 
2367878cc677SRichard Henderson         default:
2368878cc677SRichard Henderson             g_assert_not_reached();
2369878cc677SRichard Henderson         }
2370878cc677SRichard Henderson     } else {
2371878cc677SRichard Henderson         dc->pc = dc->npc;
2372878cc677SRichard Henderson         dc->npc = dc->npc + 4;
2373878cc677SRichard Henderson     }
2374878cc677SRichard Henderson     return true;
2375878cc677SRichard Henderson }
2376878cc677SRichard Henderson 
23776d2a0768SRichard Henderson /*
23786d2a0768SRichard Henderson  * Major opcodes 00 and 01 -- branches, call, and sethi
23796d2a0768SRichard Henderson  */
23806d2a0768SRichard Henderson 
23819d4e2bc7SRichard Henderson static bool advance_jump_cond(DisasContext *dc, DisasCompare *cmp,
23823951b7a8SRichard Henderson                               bool annul, int disp)
2383276567aaSRichard Henderson {
23843951b7a8SRichard Henderson     target_ulong dest = address_mask_i(dc, dc->pc + disp * 4);
2385c76c8045SRichard Henderson     target_ulong npc;
2386c76c8045SRichard Henderson 
238789527e3aSRichard Henderson     finishing_insn(dc);
238889527e3aSRichard Henderson 
23892d9bb237SRichard Henderson     if (cmp->cond == TCG_COND_ALWAYS) {
23902d9bb237SRichard Henderson         if (annul) {
23912d9bb237SRichard Henderson             dc->pc = dest;
23922d9bb237SRichard Henderson             dc->npc = dest + 4;
23932d9bb237SRichard Henderson         } else {
23942d9bb237SRichard Henderson             gen_mov_pc_npc(dc);
23952d9bb237SRichard Henderson             dc->npc = dest;
23962d9bb237SRichard Henderson         }
23972d9bb237SRichard Henderson         return true;
23982d9bb237SRichard Henderson     }
23992d9bb237SRichard Henderson 
24002d9bb237SRichard Henderson     if (cmp->cond == TCG_COND_NEVER) {
24012d9bb237SRichard Henderson         npc = dc->npc;
24022d9bb237SRichard Henderson         if (npc & 3) {
24032d9bb237SRichard Henderson             gen_mov_pc_npc(dc);
24042d9bb237SRichard Henderson             if (annul) {
24052d9bb237SRichard Henderson                 tcg_gen_addi_tl(cpu_pc, cpu_pc, 4);
24062d9bb237SRichard Henderson             }
24072d9bb237SRichard Henderson             tcg_gen_addi_tl(cpu_npc, cpu_pc, 4);
24082d9bb237SRichard Henderson         } else {
24092d9bb237SRichard Henderson             dc->pc = npc + (annul ? 4 : 0);
24102d9bb237SRichard Henderson             dc->npc = dc->pc + 4;
24112d9bb237SRichard Henderson         }
24122d9bb237SRichard Henderson         return true;
24132d9bb237SRichard Henderson     }
24142d9bb237SRichard Henderson 
2415c76c8045SRichard Henderson     flush_cond(dc);
2416c76c8045SRichard Henderson     npc = dc->npc;
24176b3e4cc6SRichard Henderson 
2418276567aaSRichard Henderson     if (annul) {
24196b3e4cc6SRichard Henderson         TCGLabel *l1 = gen_new_label();
24206b3e4cc6SRichard Henderson 
2421c8507ebfSRichard Henderson         tcg_gen_brcondi_tl(tcg_invert_cond(cmp->cond), cmp->c1, cmp->c2, l1);
24226b3e4cc6SRichard Henderson         gen_goto_tb(dc, 0, npc, dest);
24236b3e4cc6SRichard Henderson         gen_set_label(l1);
24246b3e4cc6SRichard Henderson         gen_goto_tb(dc, 1, npc + 4, npc + 8);
24256b3e4cc6SRichard Henderson 
24266b3e4cc6SRichard Henderson         dc->base.is_jmp = DISAS_NORETURN;
2427276567aaSRichard Henderson     } else {
24286b3e4cc6SRichard Henderson         if (npc & 3) {
24296b3e4cc6SRichard Henderson             switch (npc) {
24306b3e4cc6SRichard Henderson             case DYNAMIC_PC:
24316b3e4cc6SRichard Henderson             case DYNAMIC_PC_LOOKUP:
24326b3e4cc6SRichard Henderson                 tcg_gen_mov_tl(cpu_pc, cpu_npc);
24336b3e4cc6SRichard Henderson                 tcg_gen_addi_tl(cpu_npc, cpu_npc, 4);
24349d4e2bc7SRichard Henderson                 tcg_gen_movcond_tl(cmp->cond, cpu_npc,
2435c8507ebfSRichard Henderson                                    cmp->c1, tcg_constant_tl(cmp->c2),
24366b3e4cc6SRichard Henderson                                    tcg_constant_tl(dest), cpu_npc);
24376b3e4cc6SRichard Henderson                 dc->pc = npc;
24386b3e4cc6SRichard Henderson                 break;
24396b3e4cc6SRichard Henderson             default:
24406b3e4cc6SRichard Henderson                 g_assert_not_reached();
24416b3e4cc6SRichard Henderson             }
24426b3e4cc6SRichard Henderson         } else {
24436b3e4cc6SRichard Henderson             dc->pc = npc;
2444533f042fSRichard Henderson             dc->npc = JUMP_PC;
2445533f042fSRichard Henderson             dc->jump = *cmp;
24466b3e4cc6SRichard Henderson             dc->jump_pc[0] = dest;
24476b3e4cc6SRichard Henderson             dc->jump_pc[1] = npc + 4;
2448dd7dbfccSRichard Henderson 
2449dd7dbfccSRichard Henderson             /* The condition for cpu_cond is always NE -- normalize. */
2450dd7dbfccSRichard Henderson             if (cmp->cond == TCG_COND_NE) {
2451c8507ebfSRichard Henderson                 tcg_gen_xori_tl(cpu_cond, cmp->c1, cmp->c2);
24529d4e2bc7SRichard Henderson             } else {
2453c8507ebfSRichard Henderson                 tcg_gen_setcondi_tl(cmp->cond, cpu_cond, cmp->c1, cmp->c2);
24549d4e2bc7SRichard Henderson             }
245589527e3aSRichard Henderson             dc->cpu_cond_live = true;
24566b3e4cc6SRichard Henderson         }
2457276567aaSRichard Henderson     }
2458276567aaSRichard Henderson     return true;
2459276567aaSRichard Henderson }
2460276567aaSRichard Henderson 
2461af25071cSRichard Henderson static bool raise_priv(DisasContext *dc)
2462af25071cSRichard Henderson {
2463af25071cSRichard Henderson     gen_exception(dc, TT_PRIV_INSN);
2464af25071cSRichard Henderson     return true;
2465af25071cSRichard Henderson }
2466af25071cSRichard Henderson 
246706c060d9SRichard Henderson static bool raise_unimpfpop(DisasContext *dc)
246806c060d9SRichard Henderson {
246906c060d9SRichard Henderson     gen_op_fpexception_im(dc, FSR_FTT_UNIMPFPOP);
247006c060d9SRichard Henderson     return true;
247106c060d9SRichard Henderson }
247206c060d9SRichard Henderson 
247306c060d9SRichard Henderson static bool gen_trap_float128(DisasContext *dc)
247406c060d9SRichard Henderson {
247506c060d9SRichard Henderson     if (dc->def->features & CPU_FEATURE_FLOAT128) {
247606c060d9SRichard Henderson         return false;
247706c060d9SRichard Henderson     }
247806c060d9SRichard Henderson     return raise_unimpfpop(dc);
247906c060d9SRichard Henderson }
248006c060d9SRichard Henderson 
2481276567aaSRichard Henderson static bool do_bpcc(DisasContext *dc, arg_bcc *a)
2482276567aaSRichard Henderson {
24831ea9c62aSRichard Henderson     DisasCompare cmp;
2484276567aaSRichard Henderson 
24851ea9c62aSRichard Henderson     gen_compare(&cmp, a->cc, a->cond, dc);
24863951b7a8SRichard Henderson     return advance_jump_cond(dc, &cmp, a->a, a->i);
2487276567aaSRichard Henderson }
2488276567aaSRichard Henderson 
2489276567aaSRichard Henderson TRANS(Bicc, ALL, do_bpcc, a)
2490276567aaSRichard Henderson TRANS(BPcc,  64, do_bpcc, a)
2491276567aaSRichard Henderson 
249245196ea4SRichard Henderson static bool do_fbpfcc(DisasContext *dc, arg_bcc *a)
249345196ea4SRichard Henderson {
2494d5471936SRichard Henderson     DisasCompare cmp;
249545196ea4SRichard Henderson 
249645196ea4SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
249745196ea4SRichard Henderson         return true;
249845196ea4SRichard Henderson     }
2499d5471936SRichard Henderson     gen_fcompare(&cmp, a->cc, a->cond);
25003951b7a8SRichard Henderson     return advance_jump_cond(dc, &cmp, a->a, a->i);
250145196ea4SRichard Henderson }
250245196ea4SRichard Henderson 
250345196ea4SRichard Henderson TRANS(FBPfcc,  64, do_fbpfcc, a)
250445196ea4SRichard Henderson TRANS(FBfcc,  ALL, do_fbpfcc, a)
250545196ea4SRichard Henderson 
2506ab9ffe98SRichard Henderson static bool trans_BPr(DisasContext *dc, arg_BPr *a)
2507ab9ffe98SRichard Henderson {
2508ab9ffe98SRichard Henderson     DisasCompare cmp;
2509ab9ffe98SRichard Henderson 
2510ab9ffe98SRichard Henderson     if (!avail_64(dc)) {
2511ab9ffe98SRichard Henderson         return false;
2512ab9ffe98SRichard Henderson     }
25132c4f56c9SRichard Henderson     if (!gen_compare_reg(&cmp, a->cond, gen_load_gpr(dc, a->rs1))) {
2514ab9ffe98SRichard Henderson         return false;
2515ab9ffe98SRichard Henderson     }
25163951b7a8SRichard Henderson     return advance_jump_cond(dc, &cmp, a->a, a->i);
2517ab9ffe98SRichard Henderson }
2518ab9ffe98SRichard Henderson 
251923ada1b1SRichard Henderson static bool trans_CALL(DisasContext *dc, arg_CALL *a)
252023ada1b1SRichard Henderson {
252123ada1b1SRichard Henderson     target_long target = address_mask_i(dc, dc->pc + a->i * 4);
252223ada1b1SRichard Henderson 
252323ada1b1SRichard Henderson     gen_store_gpr(dc, 15, tcg_constant_tl(dc->pc));
252423ada1b1SRichard Henderson     gen_mov_pc_npc(dc);
252523ada1b1SRichard Henderson     dc->npc = target;
252623ada1b1SRichard Henderson     return true;
252723ada1b1SRichard Henderson }
252823ada1b1SRichard Henderson 
252945196ea4SRichard Henderson static bool trans_NCP(DisasContext *dc, arg_NCP *a)
253045196ea4SRichard Henderson {
253145196ea4SRichard Henderson     /*
253245196ea4SRichard Henderson      * For sparc32, always generate the no-coprocessor exception.
253345196ea4SRichard Henderson      * For sparc64, always generate illegal instruction.
253445196ea4SRichard Henderson      */
253545196ea4SRichard Henderson #ifdef TARGET_SPARC64
253645196ea4SRichard Henderson     return false;
253745196ea4SRichard Henderson #else
253845196ea4SRichard Henderson     gen_exception(dc, TT_NCP_INSN);
253945196ea4SRichard Henderson     return true;
254045196ea4SRichard Henderson #endif
254145196ea4SRichard Henderson }
254245196ea4SRichard Henderson 
25436d2a0768SRichard Henderson static bool trans_SETHI(DisasContext *dc, arg_SETHI *a)
25446d2a0768SRichard Henderson {
25456d2a0768SRichard Henderson     /* Special-case %g0 because that's the canonical nop.  */
25466d2a0768SRichard Henderson     if (a->rd) {
25476d2a0768SRichard Henderson         gen_store_gpr(dc, a->rd, tcg_constant_tl((uint32_t)a->i << 10));
25486d2a0768SRichard Henderson     }
25496d2a0768SRichard Henderson     return advance_pc(dc);
25506d2a0768SRichard Henderson }
25516d2a0768SRichard Henderson 
25520faef01bSRichard Henderson /*
25530faef01bSRichard Henderson  * Major Opcode 10 -- integer, floating-point, vis, and system insns.
25540faef01bSRichard Henderson  */
25550faef01bSRichard Henderson 
255630376636SRichard Henderson static bool do_tcc(DisasContext *dc, int cond, int cc,
255730376636SRichard Henderson                    int rs1, bool imm, int rs2_or_imm)
255830376636SRichard Henderson {
255930376636SRichard Henderson     int mask = ((dc->def->features & CPU_FEATURE_HYPV) && supervisor(dc)
256030376636SRichard Henderson                 ? UA2005_HTRAP_MASK : V8_TRAP_MASK);
256130376636SRichard Henderson     DisasCompare cmp;
256230376636SRichard Henderson     TCGLabel *lab;
256330376636SRichard Henderson     TCGv_i32 trap;
256430376636SRichard Henderson 
256530376636SRichard Henderson     /* Trap never.  */
256630376636SRichard Henderson     if (cond == 0) {
256730376636SRichard Henderson         return advance_pc(dc);
256830376636SRichard Henderson     }
256930376636SRichard Henderson 
257030376636SRichard Henderson     /*
257130376636SRichard Henderson      * Immediate traps are the most common case.  Since this value is
257230376636SRichard Henderson      * live across the branch, it really pays to evaluate the constant.
257330376636SRichard Henderson      */
257430376636SRichard Henderson     if (rs1 == 0 && (imm || rs2_or_imm == 0)) {
257530376636SRichard Henderson         trap = tcg_constant_i32((rs2_or_imm & mask) + TT_TRAP);
257630376636SRichard Henderson     } else {
257730376636SRichard Henderson         trap = tcg_temp_new_i32();
257830376636SRichard Henderson         tcg_gen_trunc_tl_i32(trap, gen_load_gpr(dc, rs1));
257930376636SRichard Henderson         if (imm) {
258030376636SRichard Henderson             tcg_gen_addi_i32(trap, trap, rs2_or_imm);
258130376636SRichard Henderson         } else {
258230376636SRichard Henderson             TCGv_i32 t2 = tcg_temp_new_i32();
258330376636SRichard Henderson             tcg_gen_trunc_tl_i32(t2, gen_load_gpr(dc, rs2_or_imm));
258430376636SRichard Henderson             tcg_gen_add_i32(trap, trap, t2);
258530376636SRichard Henderson         }
258630376636SRichard Henderson         tcg_gen_andi_i32(trap, trap, mask);
258730376636SRichard Henderson         tcg_gen_addi_i32(trap, trap, TT_TRAP);
258830376636SRichard Henderson     }
258930376636SRichard Henderson 
259089527e3aSRichard Henderson     finishing_insn(dc);
259189527e3aSRichard Henderson 
259230376636SRichard Henderson     /* Trap always.  */
259330376636SRichard Henderson     if (cond == 8) {
259430376636SRichard Henderson         save_state(dc);
259530376636SRichard Henderson         gen_helper_raise_exception(tcg_env, trap);
259630376636SRichard Henderson         dc->base.is_jmp = DISAS_NORETURN;
259730376636SRichard Henderson         return true;
259830376636SRichard Henderson     }
259930376636SRichard Henderson 
260030376636SRichard Henderson     /* Conditional trap.  */
260130376636SRichard Henderson     flush_cond(dc);
260230376636SRichard Henderson     lab = delay_exceptionv(dc, trap);
260330376636SRichard Henderson     gen_compare(&cmp, cc, cond, dc);
2604c8507ebfSRichard Henderson     tcg_gen_brcondi_tl(cmp.cond, cmp.c1, cmp.c2, lab);
260530376636SRichard Henderson 
260630376636SRichard Henderson     return advance_pc(dc);
260730376636SRichard Henderson }
260830376636SRichard Henderson 
260930376636SRichard Henderson static bool trans_Tcc_r(DisasContext *dc, arg_Tcc_r *a)
261030376636SRichard Henderson {
261130376636SRichard Henderson     if (avail_32(dc) && a->cc) {
261230376636SRichard Henderson         return false;
261330376636SRichard Henderson     }
261430376636SRichard Henderson     return do_tcc(dc, a->cond, a->cc, a->rs1, false, a->rs2);
261530376636SRichard Henderson }
261630376636SRichard Henderson 
261730376636SRichard Henderson static bool trans_Tcc_i_v7(DisasContext *dc, arg_Tcc_i_v7 *a)
261830376636SRichard Henderson {
261930376636SRichard Henderson     if (avail_64(dc)) {
262030376636SRichard Henderson         return false;
262130376636SRichard Henderson     }
262230376636SRichard Henderson     return do_tcc(dc, a->cond, 0, a->rs1, true, a->i);
262330376636SRichard Henderson }
262430376636SRichard Henderson 
262530376636SRichard Henderson static bool trans_Tcc_i_v9(DisasContext *dc, arg_Tcc_i_v9 *a)
262630376636SRichard Henderson {
262730376636SRichard Henderson     if (avail_32(dc)) {
262830376636SRichard Henderson         return false;
262930376636SRichard Henderson     }
263030376636SRichard Henderson     return do_tcc(dc, a->cond, a->cc, a->rs1, true, a->i);
263130376636SRichard Henderson }
263230376636SRichard Henderson 
2633af25071cSRichard Henderson static bool trans_STBAR(DisasContext *dc, arg_STBAR *a)
2634af25071cSRichard Henderson {
2635af25071cSRichard Henderson     tcg_gen_mb(TCG_MO_ST_ST | TCG_BAR_SC);
2636af25071cSRichard Henderson     return advance_pc(dc);
2637af25071cSRichard Henderson }
2638af25071cSRichard Henderson 
2639af25071cSRichard Henderson static bool trans_MEMBAR(DisasContext *dc, arg_MEMBAR *a)
2640af25071cSRichard Henderson {
2641af25071cSRichard Henderson     if (avail_32(dc)) {
2642af25071cSRichard Henderson         return false;
2643af25071cSRichard Henderson     }
2644af25071cSRichard Henderson     if (a->mmask) {
2645af25071cSRichard Henderson         /* Note TCG_MO_* was modeled on sparc64, so mmask matches. */
2646af25071cSRichard Henderson         tcg_gen_mb(a->mmask | TCG_BAR_SC);
2647af25071cSRichard Henderson     }
2648af25071cSRichard Henderson     if (a->cmask) {
2649af25071cSRichard Henderson         /* For #Sync, etc, end the TB to recognize interrupts. */
2650af25071cSRichard Henderson         dc->base.is_jmp = DISAS_EXIT;
2651af25071cSRichard Henderson     }
2652af25071cSRichard Henderson     return advance_pc(dc);
2653af25071cSRichard Henderson }
2654af25071cSRichard Henderson 
2655af25071cSRichard Henderson static bool do_rd_special(DisasContext *dc, bool priv, int rd,
2656af25071cSRichard Henderson                           TCGv (*func)(DisasContext *, TCGv))
2657af25071cSRichard Henderson {
2658af25071cSRichard Henderson     if (!priv) {
2659af25071cSRichard Henderson         return raise_priv(dc);
2660af25071cSRichard Henderson     }
2661af25071cSRichard Henderson     gen_store_gpr(dc, rd, func(dc, gen_dest_gpr(dc, rd)));
2662af25071cSRichard Henderson     return advance_pc(dc);
2663af25071cSRichard Henderson }
2664af25071cSRichard Henderson 
2665af25071cSRichard Henderson static TCGv do_rdy(DisasContext *dc, TCGv dst)
2666af25071cSRichard Henderson {
2667af25071cSRichard Henderson     return cpu_y;
2668af25071cSRichard Henderson }
2669af25071cSRichard Henderson 
2670af25071cSRichard Henderson static bool trans_RDY(DisasContext *dc, arg_RDY *a)
2671af25071cSRichard Henderson {
2672af25071cSRichard Henderson     /*
2673af25071cSRichard Henderson      * TODO: Need a feature bit for sparcv8.  In the meantime, treat all
2674af25071cSRichard Henderson      * 32-bit cpus like sparcv7, which ignores the rs1 field.
2675af25071cSRichard Henderson      * This matches after all other ASR, so Leon3 Asr17 is handled first.
2676af25071cSRichard Henderson      */
2677af25071cSRichard Henderson     if (avail_64(dc) && a->rs1 != 0) {
2678af25071cSRichard Henderson         return false;
2679af25071cSRichard Henderson     }
2680af25071cSRichard Henderson     return do_rd_special(dc, true, a->rd, do_rdy);
2681af25071cSRichard Henderson }
2682af25071cSRichard Henderson 
2683af25071cSRichard Henderson static TCGv do_rd_leon3_config(DisasContext *dc, TCGv dst)
2684af25071cSRichard Henderson {
2685af25071cSRichard Henderson     uint32_t val;
2686af25071cSRichard Henderson 
2687af25071cSRichard Henderson     /*
2688af25071cSRichard Henderson      * TODO: There are many more fields to be filled,
2689af25071cSRichard Henderson      * some of which are writable.
2690af25071cSRichard Henderson      */
2691af25071cSRichard Henderson     val = dc->def->nwindows - 1;   /* [4:0] NWIN */
2692af25071cSRichard Henderson     val |= 1 << 8;                 /* [8]   V8   */
2693af25071cSRichard Henderson 
2694af25071cSRichard Henderson     return tcg_constant_tl(val);
2695af25071cSRichard Henderson }
2696af25071cSRichard Henderson 
2697af25071cSRichard Henderson TRANS(RDASR17, ASR17, do_rd_special, true, a->rd, do_rd_leon3_config)
2698af25071cSRichard Henderson 
2699af25071cSRichard Henderson static TCGv do_rdccr(DisasContext *dc, TCGv dst)
2700af25071cSRichard Henderson {
2701af25071cSRichard Henderson     gen_helper_rdccr(dst, tcg_env);
2702af25071cSRichard Henderson     return dst;
2703af25071cSRichard Henderson }
2704af25071cSRichard Henderson 
2705af25071cSRichard Henderson TRANS(RDCCR, 64, do_rd_special, true, a->rd, do_rdccr)
2706af25071cSRichard Henderson 
2707af25071cSRichard Henderson static TCGv do_rdasi(DisasContext *dc, TCGv dst)
2708af25071cSRichard Henderson {
2709af25071cSRichard Henderson #ifdef TARGET_SPARC64
2710af25071cSRichard Henderson     return tcg_constant_tl(dc->asi);
2711af25071cSRichard Henderson #else
2712af25071cSRichard Henderson     qemu_build_not_reached();
2713af25071cSRichard Henderson #endif
2714af25071cSRichard Henderson }
2715af25071cSRichard Henderson 
2716af25071cSRichard Henderson TRANS(RDASI, 64, do_rd_special, true, a->rd, do_rdasi)
2717af25071cSRichard Henderson 
2718af25071cSRichard Henderson static TCGv do_rdtick(DisasContext *dc, TCGv dst)
2719af25071cSRichard Henderson {
2720af25071cSRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
2721af25071cSRichard Henderson 
2722af25071cSRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(tick));
2723af25071cSRichard Henderson     if (translator_io_start(&dc->base)) {
2724af25071cSRichard Henderson         dc->base.is_jmp = DISAS_EXIT;
2725af25071cSRichard Henderson     }
2726af25071cSRichard Henderson     gen_helper_tick_get_count(dst, tcg_env, r_tickptr,
2727af25071cSRichard Henderson                               tcg_constant_i32(dc->mem_idx));
2728af25071cSRichard Henderson     return dst;
2729af25071cSRichard Henderson }
2730af25071cSRichard Henderson 
2731af25071cSRichard Henderson /* TODO: non-priv access only allowed when enabled. */
2732af25071cSRichard Henderson TRANS(RDTICK, 64, do_rd_special, true, a->rd, do_rdtick)
2733af25071cSRichard Henderson 
2734af25071cSRichard Henderson static TCGv do_rdpc(DisasContext *dc, TCGv dst)
2735af25071cSRichard Henderson {
2736af25071cSRichard Henderson     return tcg_constant_tl(address_mask_i(dc, dc->pc));
2737af25071cSRichard Henderson }
2738af25071cSRichard Henderson 
2739af25071cSRichard Henderson TRANS(RDPC, 64, do_rd_special, true, a->rd, do_rdpc)
2740af25071cSRichard Henderson 
2741af25071cSRichard Henderson static TCGv do_rdfprs(DisasContext *dc, TCGv dst)
2742af25071cSRichard Henderson {
2743af25071cSRichard Henderson     tcg_gen_ext_i32_tl(dst, cpu_fprs);
2744af25071cSRichard Henderson     return dst;
2745af25071cSRichard Henderson }
2746af25071cSRichard Henderson 
2747af25071cSRichard Henderson TRANS(RDFPRS, 64, do_rd_special, true, a->rd, do_rdfprs)
2748af25071cSRichard Henderson 
2749af25071cSRichard Henderson static TCGv do_rdgsr(DisasContext *dc, TCGv dst)
2750af25071cSRichard Henderson {
2751af25071cSRichard Henderson     gen_trap_ifnofpu(dc);
2752af25071cSRichard Henderson     return cpu_gsr;
2753af25071cSRichard Henderson }
2754af25071cSRichard Henderson 
2755af25071cSRichard Henderson TRANS(RDGSR, 64, do_rd_special, true, a->rd, do_rdgsr)
2756af25071cSRichard Henderson 
2757af25071cSRichard Henderson static TCGv do_rdsoftint(DisasContext *dc, TCGv dst)
2758af25071cSRichard Henderson {
2759af25071cSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(softint));
2760af25071cSRichard Henderson     return dst;
2761af25071cSRichard Henderson }
2762af25071cSRichard Henderson 
2763af25071cSRichard Henderson TRANS(RDSOFTINT, 64, do_rd_special, supervisor(dc), a->rd, do_rdsoftint)
2764af25071cSRichard Henderson 
2765af25071cSRichard Henderson static TCGv do_rdtick_cmpr(DisasContext *dc, TCGv dst)
2766af25071cSRichard Henderson {
2767577efa45SRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(tick_cmpr));
2768577efa45SRichard Henderson     return dst;
2769af25071cSRichard Henderson }
2770af25071cSRichard Henderson 
2771af25071cSRichard Henderson /* TODO: non-priv access only allowed when enabled. */
2772af25071cSRichard Henderson TRANS(RDTICK_CMPR, 64, do_rd_special, true, a->rd, do_rdtick_cmpr)
2773af25071cSRichard Henderson 
2774af25071cSRichard Henderson static TCGv do_rdstick(DisasContext *dc, TCGv dst)
2775af25071cSRichard Henderson {
2776af25071cSRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
2777af25071cSRichard Henderson 
2778af25071cSRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(stick));
2779af25071cSRichard Henderson     if (translator_io_start(&dc->base)) {
2780af25071cSRichard Henderson         dc->base.is_jmp = DISAS_EXIT;
2781af25071cSRichard Henderson     }
2782af25071cSRichard Henderson     gen_helper_tick_get_count(dst, tcg_env, r_tickptr,
2783af25071cSRichard Henderson                               tcg_constant_i32(dc->mem_idx));
2784af25071cSRichard Henderson     return dst;
2785af25071cSRichard Henderson }
2786af25071cSRichard Henderson 
2787af25071cSRichard Henderson /* TODO: non-priv access only allowed when enabled. */
2788af25071cSRichard Henderson TRANS(RDSTICK, 64, do_rd_special, true, a->rd, do_rdstick)
2789af25071cSRichard Henderson 
2790af25071cSRichard Henderson static TCGv do_rdstick_cmpr(DisasContext *dc, TCGv dst)
2791af25071cSRichard Henderson {
2792577efa45SRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(stick_cmpr));
2793577efa45SRichard Henderson     return dst;
2794af25071cSRichard Henderson }
2795af25071cSRichard Henderson 
2796af25071cSRichard Henderson /* TODO: supervisor access only allowed when enabled by hypervisor. */
2797af25071cSRichard Henderson TRANS(RDSTICK_CMPR, 64, do_rd_special, supervisor(dc), a->rd, do_rdstick_cmpr)
2798af25071cSRichard Henderson 
2799af25071cSRichard Henderson /*
2800af25071cSRichard Henderson  * UltraSPARC-T1 Strand status.
2801af25071cSRichard Henderson  * HYPV check maybe not enough, UA2005 & UA2007 describe
2802af25071cSRichard Henderson  * this ASR as impl. dep
2803af25071cSRichard Henderson  */
2804af25071cSRichard Henderson static TCGv do_rdstrand_status(DisasContext *dc, TCGv dst)
2805af25071cSRichard Henderson {
2806af25071cSRichard Henderson     return tcg_constant_tl(1);
2807af25071cSRichard Henderson }
2808af25071cSRichard Henderson 
2809af25071cSRichard Henderson TRANS(RDSTRAND_STATUS, HYPV, do_rd_special, true, a->rd, do_rdstrand_status)
2810af25071cSRichard Henderson 
2811668bb9b7SRichard Henderson static TCGv do_rdpsr(DisasContext *dc, TCGv dst)
2812668bb9b7SRichard Henderson {
2813668bb9b7SRichard Henderson     gen_helper_rdpsr(dst, tcg_env);
2814668bb9b7SRichard Henderson     return dst;
2815668bb9b7SRichard Henderson }
2816668bb9b7SRichard Henderson 
2817668bb9b7SRichard Henderson TRANS(RDPSR, 32, do_rd_special, supervisor(dc), a->rd, do_rdpsr)
2818668bb9b7SRichard Henderson 
2819668bb9b7SRichard Henderson static TCGv do_rdhpstate(DisasContext *dc, TCGv dst)
2820668bb9b7SRichard Henderson {
2821668bb9b7SRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hpstate));
2822668bb9b7SRichard Henderson     return dst;
2823668bb9b7SRichard Henderson }
2824668bb9b7SRichard Henderson 
2825668bb9b7SRichard Henderson TRANS(RDHPR_hpstate, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhpstate)
2826668bb9b7SRichard Henderson 
2827668bb9b7SRichard Henderson static TCGv do_rdhtstate(DisasContext *dc, TCGv dst)
2828668bb9b7SRichard Henderson {
2829668bb9b7SRichard Henderson     TCGv_i32 tl = tcg_temp_new_i32();
2830668bb9b7SRichard Henderson     TCGv_ptr tp = tcg_temp_new_ptr();
2831668bb9b7SRichard Henderson 
2832668bb9b7SRichard Henderson     tcg_gen_ld_i32(tl, tcg_env, env64_field_offsetof(tl));
2833668bb9b7SRichard Henderson     tcg_gen_andi_i32(tl, tl, MAXTL_MASK);
2834668bb9b7SRichard Henderson     tcg_gen_shli_i32(tl, tl, 3);
2835668bb9b7SRichard Henderson     tcg_gen_ext_i32_ptr(tp, tl);
2836668bb9b7SRichard Henderson     tcg_gen_add_ptr(tp, tp, tcg_env);
2837668bb9b7SRichard Henderson 
2838668bb9b7SRichard Henderson     tcg_gen_ld_tl(dst, tp, env64_field_offsetof(htstate));
2839668bb9b7SRichard Henderson     return dst;
2840668bb9b7SRichard Henderson }
2841668bb9b7SRichard Henderson 
2842668bb9b7SRichard Henderson TRANS(RDHPR_htstate, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhtstate)
2843668bb9b7SRichard Henderson 
2844668bb9b7SRichard Henderson static TCGv do_rdhintp(DisasContext *dc, TCGv dst)
2845668bb9b7SRichard Henderson {
28462da789deSRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hintp));
28472da789deSRichard Henderson     return dst;
2848668bb9b7SRichard Henderson }
2849668bb9b7SRichard Henderson 
2850668bb9b7SRichard Henderson TRANS(RDHPR_hintp, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhintp)
2851668bb9b7SRichard Henderson 
2852668bb9b7SRichard Henderson static TCGv do_rdhtba(DisasContext *dc, TCGv dst)
2853668bb9b7SRichard Henderson {
28542da789deSRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(htba));
28552da789deSRichard Henderson     return dst;
2856668bb9b7SRichard Henderson }
2857668bb9b7SRichard Henderson 
2858668bb9b7SRichard Henderson TRANS(RDHPR_htba, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhtba)
2859668bb9b7SRichard Henderson 
2860668bb9b7SRichard Henderson static TCGv do_rdhver(DisasContext *dc, TCGv dst)
2861668bb9b7SRichard Henderson {
28622da789deSRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hver));
28632da789deSRichard Henderson     return dst;
2864668bb9b7SRichard Henderson }
2865668bb9b7SRichard Henderson 
2866668bb9b7SRichard Henderson TRANS(RDHPR_hver, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdhver)
2867668bb9b7SRichard Henderson 
2868668bb9b7SRichard Henderson static TCGv do_rdhstick_cmpr(DisasContext *dc, TCGv dst)
2869668bb9b7SRichard Henderson {
2870577efa45SRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(hstick_cmpr));
2871577efa45SRichard Henderson     return dst;
2872668bb9b7SRichard Henderson }
2873668bb9b7SRichard Henderson 
2874668bb9b7SRichard Henderson TRANS(RDHPR_hstick_cmpr, HYPV, do_rd_special, hypervisor(dc), a->rd,
2875668bb9b7SRichard Henderson       do_rdhstick_cmpr)
2876668bb9b7SRichard Henderson 
28775d617bfbSRichard Henderson static TCGv do_rdwim(DisasContext *dc, TCGv dst)
28785d617bfbSRichard Henderson {
2879cd6269f7SRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env32_field_offsetof(wim));
2880cd6269f7SRichard Henderson     return dst;
28815d617bfbSRichard Henderson }
28825d617bfbSRichard Henderson 
28835d617bfbSRichard Henderson TRANS(RDWIM, 32, do_rd_special, supervisor(dc), a->rd, do_rdwim)
28845d617bfbSRichard Henderson 
28855d617bfbSRichard Henderson static TCGv do_rdtpc(DisasContext *dc, TCGv dst)
28865d617bfbSRichard Henderson {
28875d617bfbSRichard Henderson #ifdef TARGET_SPARC64
28885d617bfbSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
28895d617bfbSRichard Henderson 
28905d617bfbSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
28915d617bfbSRichard Henderson     tcg_gen_ld_tl(dst, r_tsptr, offsetof(trap_state, tpc));
28925d617bfbSRichard Henderson     return dst;
28935d617bfbSRichard Henderson #else
28945d617bfbSRichard Henderson     qemu_build_not_reached();
28955d617bfbSRichard Henderson #endif
28965d617bfbSRichard Henderson }
28975d617bfbSRichard Henderson 
28985d617bfbSRichard Henderson TRANS(RDPR_tpc, 64, do_rd_special, supervisor(dc), a->rd, do_rdtpc)
28995d617bfbSRichard Henderson 
29005d617bfbSRichard Henderson static TCGv do_rdtnpc(DisasContext *dc, TCGv dst)
29015d617bfbSRichard Henderson {
29025d617bfbSRichard Henderson #ifdef TARGET_SPARC64
29035d617bfbSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
29045d617bfbSRichard Henderson 
29055d617bfbSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
29065d617bfbSRichard Henderson     tcg_gen_ld_tl(dst, r_tsptr, offsetof(trap_state, tnpc));
29075d617bfbSRichard Henderson     return dst;
29085d617bfbSRichard Henderson #else
29095d617bfbSRichard Henderson     qemu_build_not_reached();
29105d617bfbSRichard Henderson #endif
29115d617bfbSRichard Henderson }
29125d617bfbSRichard Henderson 
29135d617bfbSRichard Henderson TRANS(RDPR_tnpc, 64, do_rd_special, supervisor(dc), a->rd, do_rdtnpc)
29145d617bfbSRichard Henderson 
29155d617bfbSRichard Henderson static TCGv do_rdtstate(DisasContext *dc, TCGv dst)
29165d617bfbSRichard Henderson {
29175d617bfbSRichard Henderson #ifdef TARGET_SPARC64
29185d617bfbSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
29195d617bfbSRichard Henderson 
29205d617bfbSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
29215d617bfbSRichard Henderson     tcg_gen_ld_tl(dst, r_tsptr, offsetof(trap_state, tstate));
29225d617bfbSRichard Henderson     return dst;
29235d617bfbSRichard Henderson #else
29245d617bfbSRichard Henderson     qemu_build_not_reached();
29255d617bfbSRichard Henderson #endif
29265d617bfbSRichard Henderson }
29275d617bfbSRichard Henderson 
29285d617bfbSRichard Henderson TRANS(RDPR_tstate, 64, do_rd_special, supervisor(dc), a->rd, do_rdtstate)
29295d617bfbSRichard Henderson 
29305d617bfbSRichard Henderson static TCGv do_rdtt(DisasContext *dc, TCGv dst)
29315d617bfbSRichard Henderson {
29325d617bfbSRichard Henderson #ifdef TARGET_SPARC64
29335d617bfbSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
29345d617bfbSRichard Henderson 
29355d617bfbSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
29365d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, r_tsptr, offsetof(trap_state, tt));
29375d617bfbSRichard Henderson     return dst;
29385d617bfbSRichard Henderson #else
29395d617bfbSRichard Henderson     qemu_build_not_reached();
29405d617bfbSRichard Henderson #endif
29415d617bfbSRichard Henderson }
29425d617bfbSRichard Henderson 
29435d617bfbSRichard Henderson TRANS(RDPR_tt, 64, do_rd_special, supervisor(dc), a->rd, do_rdtt)
29445d617bfbSRichard Henderson TRANS(RDPR_tick, 64, do_rd_special, supervisor(dc), a->rd, do_rdtick)
29455d617bfbSRichard Henderson 
29465d617bfbSRichard Henderson static TCGv do_rdtba(DisasContext *dc, TCGv dst)
29475d617bfbSRichard Henderson {
29485d617bfbSRichard Henderson     return cpu_tbr;
29495d617bfbSRichard Henderson }
29505d617bfbSRichard Henderson 
2951e8325dc0SRichard Henderson TRANS(RDTBR, 32, do_rd_special, supervisor(dc), a->rd, do_rdtba)
29525d617bfbSRichard Henderson TRANS(RDPR_tba, 64, do_rd_special, supervisor(dc), a->rd, do_rdtba)
29535d617bfbSRichard Henderson 
29545d617bfbSRichard Henderson static TCGv do_rdpstate(DisasContext *dc, TCGv dst)
29555d617bfbSRichard Henderson {
29565d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(pstate));
29575d617bfbSRichard Henderson     return dst;
29585d617bfbSRichard Henderson }
29595d617bfbSRichard Henderson 
29605d617bfbSRichard Henderson TRANS(RDPR_pstate, 64, do_rd_special, supervisor(dc), a->rd, do_rdpstate)
29615d617bfbSRichard Henderson 
29625d617bfbSRichard Henderson static TCGv do_rdtl(DisasContext *dc, TCGv dst)
29635d617bfbSRichard Henderson {
29645d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(tl));
29655d617bfbSRichard Henderson     return dst;
29665d617bfbSRichard Henderson }
29675d617bfbSRichard Henderson 
29685d617bfbSRichard Henderson TRANS(RDPR_tl, 64, do_rd_special, supervisor(dc), a->rd, do_rdtl)
29695d617bfbSRichard Henderson 
29705d617bfbSRichard Henderson static TCGv do_rdpil(DisasContext *dc, TCGv dst)
29715d617bfbSRichard Henderson {
29725d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env_field_offsetof(psrpil));
29735d617bfbSRichard Henderson     return dst;
29745d617bfbSRichard Henderson }
29755d617bfbSRichard Henderson 
29765d617bfbSRichard Henderson TRANS(RDPR_pil, 64, do_rd_special, supervisor(dc), a->rd, do_rdpil)
29775d617bfbSRichard Henderson 
29785d617bfbSRichard Henderson static TCGv do_rdcwp(DisasContext *dc, TCGv dst)
29795d617bfbSRichard Henderson {
29805d617bfbSRichard Henderson     gen_helper_rdcwp(dst, tcg_env);
29815d617bfbSRichard Henderson     return dst;
29825d617bfbSRichard Henderson }
29835d617bfbSRichard Henderson 
29845d617bfbSRichard Henderson TRANS(RDPR_cwp, 64, do_rd_special, supervisor(dc), a->rd, do_rdcwp)
29855d617bfbSRichard Henderson 
29865d617bfbSRichard Henderson static TCGv do_rdcansave(DisasContext *dc, TCGv dst)
29875d617bfbSRichard Henderson {
29885d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(cansave));
29895d617bfbSRichard Henderson     return dst;
29905d617bfbSRichard Henderson }
29915d617bfbSRichard Henderson 
29925d617bfbSRichard Henderson TRANS(RDPR_cansave, 64, do_rd_special, supervisor(dc), a->rd, do_rdcansave)
29935d617bfbSRichard Henderson 
29945d617bfbSRichard Henderson static TCGv do_rdcanrestore(DisasContext *dc, TCGv dst)
29955d617bfbSRichard Henderson {
29965d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(canrestore));
29975d617bfbSRichard Henderson     return dst;
29985d617bfbSRichard Henderson }
29995d617bfbSRichard Henderson 
30005d617bfbSRichard Henderson TRANS(RDPR_canrestore, 64, do_rd_special, supervisor(dc), a->rd,
30015d617bfbSRichard Henderson       do_rdcanrestore)
30025d617bfbSRichard Henderson 
30035d617bfbSRichard Henderson static TCGv do_rdcleanwin(DisasContext *dc, TCGv dst)
30045d617bfbSRichard Henderson {
30055d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(cleanwin));
30065d617bfbSRichard Henderson     return dst;
30075d617bfbSRichard Henderson }
30085d617bfbSRichard Henderson 
30095d617bfbSRichard Henderson TRANS(RDPR_cleanwin, 64, do_rd_special, supervisor(dc), a->rd, do_rdcleanwin)
30105d617bfbSRichard Henderson 
30115d617bfbSRichard Henderson static TCGv do_rdotherwin(DisasContext *dc, TCGv dst)
30125d617bfbSRichard Henderson {
30135d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(otherwin));
30145d617bfbSRichard Henderson     return dst;
30155d617bfbSRichard Henderson }
30165d617bfbSRichard Henderson 
30175d617bfbSRichard Henderson TRANS(RDPR_otherwin, 64, do_rd_special, supervisor(dc), a->rd, do_rdotherwin)
30185d617bfbSRichard Henderson 
30195d617bfbSRichard Henderson static TCGv do_rdwstate(DisasContext *dc, TCGv dst)
30205d617bfbSRichard Henderson {
30215d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(wstate));
30225d617bfbSRichard Henderson     return dst;
30235d617bfbSRichard Henderson }
30245d617bfbSRichard Henderson 
30255d617bfbSRichard Henderson TRANS(RDPR_wstate, 64, do_rd_special, supervisor(dc), a->rd, do_rdwstate)
30265d617bfbSRichard Henderson 
30275d617bfbSRichard Henderson static TCGv do_rdgl(DisasContext *dc, TCGv dst)
30285d617bfbSRichard Henderson {
30295d617bfbSRichard Henderson     tcg_gen_ld32s_tl(dst, tcg_env, env64_field_offsetof(gl));
30305d617bfbSRichard Henderson     return dst;
30315d617bfbSRichard Henderson }
30325d617bfbSRichard Henderson 
30335d617bfbSRichard Henderson TRANS(RDPR_gl, GL, do_rd_special, supervisor(dc), a->rd, do_rdgl)
30345d617bfbSRichard Henderson 
30355d617bfbSRichard Henderson /* UA2005 strand status */
30365d617bfbSRichard Henderson static TCGv do_rdssr(DisasContext *dc, TCGv dst)
30375d617bfbSRichard Henderson {
30382da789deSRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(ssr));
30392da789deSRichard Henderson     return dst;
30405d617bfbSRichard Henderson }
30415d617bfbSRichard Henderson 
30425d617bfbSRichard Henderson TRANS(RDPR_strand_status, HYPV, do_rd_special, hypervisor(dc), a->rd, do_rdssr)
30435d617bfbSRichard Henderson 
30445d617bfbSRichard Henderson static TCGv do_rdver(DisasContext *dc, TCGv dst)
30455d617bfbSRichard Henderson {
30462da789deSRichard Henderson     tcg_gen_ld_tl(dst, tcg_env, env64_field_offsetof(version));
30472da789deSRichard Henderson     return dst;
30485d617bfbSRichard Henderson }
30495d617bfbSRichard Henderson 
30505d617bfbSRichard Henderson TRANS(RDPR_ver, 64, do_rd_special, supervisor(dc), a->rd, do_rdver)
30515d617bfbSRichard Henderson 
3052e8325dc0SRichard Henderson static bool trans_FLUSHW(DisasContext *dc, arg_FLUSHW *a)
3053e8325dc0SRichard Henderson {
3054e8325dc0SRichard Henderson     if (avail_64(dc)) {
3055e8325dc0SRichard Henderson         gen_helper_flushw(tcg_env);
3056e8325dc0SRichard Henderson         return advance_pc(dc);
3057e8325dc0SRichard Henderson     }
3058e8325dc0SRichard Henderson     return false;
3059e8325dc0SRichard Henderson }
3060e8325dc0SRichard Henderson 
30610faef01bSRichard Henderson static bool do_wr_special(DisasContext *dc, arg_r_r_ri *a, bool priv,
30620faef01bSRichard Henderson                           void (*func)(DisasContext *, TCGv))
30630faef01bSRichard Henderson {
30640faef01bSRichard Henderson     TCGv src;
30650faef01bSRichard Henderson 
30660faef01bSRichard Henderson     /* For simplicity, we under-decoded the rs2 form. */
30670faef01bSRichard Henderson     if (!a->imm && (a->rs2_or_imm & ~0x1f)) {
30680faef01bSRichard Henderson         return false;
30690faef01bSRichard Henderson     }
30700faef01bSRichard Henderson     if (!priv) {
30710faef01bSRichard Henderson         return raise_priv(dc);
30720faef01bSRichard Henderson     }
30730faef01bSRichard Henderson 
30740faef01bSRichard Henderson     if (a->rs1 == 0 && (a->imm || a->rs2_or_imm == 0)) {
30750faef01bSRichard Henderson         src = tcg_constant_tl(a->rs2_or_imm);
30760faef01bSRichard Henderson     } else {
30770faef01bSRichard Henderson         TCGv src1 = gen_load_gpr(dc, a->rs1);
30780faef01bSRichard Henderson         if (a->rs2_or_imm == 0) {
30790faef01bSRichard Henderson             src = src1;
30800faef01bSRichard Henderson         } else {
30810faef01bSRichard Henderson             src = tcg_temp_new();
30820faef01bSRichard Henderson             if (a->imm) {
30830faef01bSRichard Henderson                 tcg_gen_xori_tl(src, src1, a->rs2_or_imm);
30840faef01bSRichard Henderson             } else {
30850faef01bSRichard Henderson                 tcg_gen_xor_tl(src, src1, gen_load_gpr(dc, a->rs2_or_imm));
30860faef01bSRichard Henderson             }
30870faef01bSRichard Henderson         }
30880faef01bSRichard Henderson     }
30890faef01bSRichard Henderson     func(dc, src);
30900faef01bSRichard Henderson     return advance_pc(dc);
30910faef01bSRichard Henderson }
30920faef01bSRichard Henderson 
30930faef01bSRichard Henderson static void do_wry(DisasContext *dc, TCGv src)
30940faef01bSRichard Henderson {
30950faef01bSRichard Henderson     tcg_gen_ext32u_tl(cpu_y, src);
30960faef01bSRichard Henderson }
30970faef01bSRichard Henderson 
30980faef01bSRichard Henderson TRANS(WRY, ALL, do_wr_special, a, true, do_wry)
30990faef01bSRichard Henderson 
31000faef01bSRichard Henderson static void do_wrccr(DisasContext *dc, TCGv src)
31010faef01bSRichard Henderson {
31020faef01bSRichard Henderson     gen_helper_wrccr(tcg_env, src);
31030faef01bSRichard Henderson }
31040faef01bSRichard Henderson 
31050faef01bSRichard Henderson TRANS(WRCCR, 64, do_wr_special, a, true, do_wrccr)
31060faef01bSRichard Henderson 
31070faef01bSRichard Henderson static void do_wrasi(DisasContext *dc, TCGv src)
31080faef01bSRichard Henderson {
31090faef01bSRichard Henderson     TCGv tmp = tcg_temp_new();
31100faef01bSRichard Henderson 
31110faef01bSRichard Henderson     tcg_gen_ext8u_tl(tmp, src);
31120faef01bSRichard Henderson     tcg_gen_st32_tl(tmp, tcg_env, env64_field_offsetof(asi));
31130faef01bSRichard Henderson     /* End TB to notice changed ASI. */
31140faef01bSRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
31150faef01bSRichard Henderson }
31160faef01bSRichard Henderson 
31170faef01bSRichard Henderson TRANS(WRASI, 64, do_wr_special, a, true, do_wrasi)
31180faef01bSRichard Henderson 
31190faef01bSRichard Henderson static void do_wrfprs(DisasContext *dc, TCGv src)
31200faef01bSRichard Henderson {
31210faef01bSRichard Henderson #ifdef TARGET_SPARC64
31220faef01bSRichard Henderson     tcg_gen_trunc_tl_i32(cpu_fprs, src);
31230faef01bSRichard Henderson     dc->fprs_dirty = 0;
31240faef01bSRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
31250faef01bSRichard Henderson #else
31260faef01bSRichard Henderson     qemu_build_not_reached();
31270faef01bSRichard Henderson #endif
31280faef01bSRichard Henderson }
31290faef01bSRichard Henderson 
31300faef01bSRichard Henderson TRANS(WRFPRS, 64, do_wr_special, a, true, do_wrfprs)
31310faef01bSRichard Henderson 
31320faef01bSRichard Henderson static void do_wrgsr(DisasContext *dc, TCGv src)
31330faef01bSRichard Henderson {
31340faef01bSRichard Henderson     gen_trap_ifnofpu(dc);
31350faef01bSRichard Henderson     tcg_gen_mov_tl(cpu_gsr, src);
31360faef01bSRichard Henderson }
31370faef01bSRichard Henderson 
31380faef01bSRichard Henderson TRANS(WRGSR, 64, do_wr_special, a, true, do_wrgsr)
31390faef01bSRichard Henderson 
31400faef01bSRichard Henderson static void do_wrsoftint_set(DisasContext *dc, TCGv src)
31410faef01bSRichard Henderson {
31420faef01bSRichard Henderson     gen_helper_set_softint(tcg_env, src);
31430faef01bSRichard Henderson }
31440faef01bSRichard Henderson 
31450faef01bSRichard Henderson TRANS(WRSOFTINT_SET, 64, do_wr_special, a, supervisor(dc), do_wrsoftint_set)
31460faef01bSRichard Henderson 
31470faef01bSRichard Henderson static void do_wrsoftint_clr(DisasContext *dc, TCGv src)
31480faef01bSRichard Henderson {
31490faef01bSRichard Henderson     gen_helper_clear_softint(tcg_env, src);
31500faef01bSRichard Henderson }
31510faef01bSRichard Henderson 
31520faef01bSRichard Henderson TRANS(WRSOFTINT_CLR, 64, do_wr_special, a, supervisor(dc), do_wrsoftint_clr)
31530faef01bSRichard Henderson 
31540faef01bSRichard Henderson static void do_wrsoftint(DisasContext *dc, TCGv src)
31550faef01bSRichard Henderson {
31560faef01bSRichard Henderson     gen_helper_write_softint(tcg_env, src);
31570faef01bSRichard Henderson }
31580faef01bSRichard Henderson 
31590faef01bSRichard Henderson TRANS(WRSOFTINT, 64, do_wr_special, a, supervisor(dc), do_wrsoftint)
31600faef01bSRichard Henderson 
31610faef01bSRichard Henderson static void do_wrtick_cmpr(DisasContext *dc, TCGv src)
31620faef01bSRichard Henderson {
31630faef01bSRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
31640faef01bSRichard Henderson 
3165577efa45SRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(tick_cmpr));
3166577efa45SRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(tick));
31670faef01bSRichard Henderson     translator_io_start(&dc->base);
3168577efa45SRichard Henderson     gen_helper_tick_set_limit(r_tickptr, src);
31690faef01bSRichard Henderson     /* End TB to handle timer interrupt */
31700faef01bSRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
31710faef01bSRichard Henderson }
31720faef01bSRichard Henderson 
31730faef01bSRichard Henderson TRANS(WRTICK_CMPR, 64, do_wr_special, a, supervisor(dc), do_wrtick_cmpr)
31740faef01bSRichard Henderson 
31750faef01bSRichard Henderson static void do_wrstick(DisasContext *dc, TCGv src)
31760faef01bSRichard Henderson {
31770faef01bSRichard Henderson #ifdef TARGET_SPARC64
31780faef01bSRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
31790faef01bSRichard Henderson 
31800faef01bSRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, offsetof(CPUSPARCState, stick));
31810faef01bSRichard Henderson     translator_io_start(&dc->base);
31820faef01bSRichard Henderson     gen_helper_tick_set_count(r_tickptr, src);
31830faef01bSRichard Henderson     /* End TB to handle timer interrupt */
31840faef01bSRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
31850faef01bSRichard Henderson #else
31860faef01bSRichard Henderson     qemu_build_not_reached();
31870faef01bSRichard Henderson #endif
31880faef01bSRichard Henderson }
31890faef01bSRichard Henderson 
31900faef01bSRichard Henderson TRANS(WRSTICK, 64, do_wr_special, a, supervisor(dc), do_wrstick)
31910faef01bSRichard Henderson 
31920faef01bSRichard Henderson static void do_wrstick_cmpr(DisasContext *dc, TCGv src)
31930faef01bSRichard Henderson {
31940faef01bSRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
31950faef01bSRichard Henderson 
3196577efa45SRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(stick_cmpr));
3197577efa45SRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(stick));
31980faef01bSRichard Henderson     translator_io_start(&dc->base);
3199577efa45SRichard Henderson     gen_helper_tick_set_limit(r_tickptr, src);
32000faef01bSRichard Henderson     /* End TB to handle timer interrupt */
32010faef01bSRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
32020faef01bSRichard Henderson }
32030faef01bSRichard Henderson 
32040faef01bSRichard Henderson TRANS(WRSTICK_CMPR, 64, do_wr_special, a, supervisor(dc), do_wrstick_cmpr)
32050faef01bSRichard Henderson 
32060faef01bSRichard Henderson static void do_wrpowerdown(DisasContext *dc, TCGv src)
32070faef01bSRichard Henderson {
320889527e3aSRichard Henderson     finishing_insn(dc);
32090faef01bSRichard Henderson     save_state(dc);
32100faef01bSRichard Henderson     gen_helper_power_down(tcg_env);
32110faef01bSRichard Henderson }
32120faef01bSRichard Henderson 
32130faef01bSRichard Henderson TRANS(WRPOWERDOWN, POWERDOWN, do_wr_special, a, supervisor(dc), do_wrpowerdown)
32140faef01bSRichard Henderson 
321525524734SRichard Henderson static void do_wrpsr(DisasContext *dc, TCGv src)
321625524734SRichard Henderson {
321725524734SRichard Henderson     gen_helper_wrpsr(tcg_env, src);
321825524734SRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
321925524734SRichard Henderson }
322025524734SRichard Henderson 
322125524734SRichard Henderson TRANS(WRPSR, 32, do_wr_special, a, supervisor(dc), do_wrpsr)
322225524734SRichard Henderson 
32239422278eSRichard Henderson static void do_wrwim(DisasContext *dc, TCGv src)
32249422278eSRichard Henderson {
32259422278eSRichard Henderson     target_ulong mask = MAKE_64BIT_MASK(0, dc->def->nwindows);
3226cd6269f7SRichard Henderson     TCGv tmp = tcg_temp_new();
3227cd6269f7SRichard Henderson 
3228cd6269f7SRichard Henderson     tcg_gen_andi_tl(tmp, src, mask);
3229cd6269f7SRichard Henderson     tcg_gen_st_tl(tmp, tcg_env, env32_field_offsetof(wim));
32309422278eSRichard Henderson }
32319422278eSRichard Henderson 
32329422278eSRichard Henderson TRANS(WRWIM, 32, do_wr_special, a, supervisor(dc), do_wrwim)
32339422278eSRichard Henderson 
32349422278eSRichard Henderson static void do_wrtpc(DisasContext *dc, TCGv src)
32359422278eSRichard Henderson {
32369422278eSRichard Henderson #ifdef TARGET_SPARC64
32379422278eSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
32389422278eSRichard Henderson 
32399422278eSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
32409422278eSRichard Henderson     tcg_gen_st_tl(src, r_tsptr, offsetof(trap_state, tpc));
32419422278eSRichard Henderson #else
32429422278eSRichard Henderson     qemu_build_not_reached();
32439422278eSRichard Henderson #endif
32449422278eSRichard Henderson }
32459422278eSRichard Henderson 
32469422278eSRichard Henderson TRANS(WRPR_tpc, 64, do_wr_special, a, supervisor(dc), do_wrtpc)
32479422278eSRichard Henderson 
32489422278eSRichard Henderson static void do_wrtnpc(DisasContext *dc, TCGv src)
32499422278eSRichard Henderson {
32509422278eSRichard Henderson #ifdef TARGET_SPARC64
32519422278eSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
32529422278eSRichard Henderson 
32539422278eSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
32549422278eSRichard Henderson     tcg_gen_st_tl(src, r_tsptr, offsetof(trap_state, tnpc));
32559422278eSRichard Henderson #else
32569422278eSRichard Henderson     qemu_build_not_reached();
32579422278eSRichard Henderson #endif
32589422278eSRichard Henderson }
32599422278eSRichard Henderson 
32609422278eSRichard Henderson TRANS(WRPR_tnpc, 64, do_wr_special, a, supervisor(dc), do_wrtnpc)
32619422278eSRichard Henderson 
32629422278eSRichard Henderson static void do_wrtstate(DisasContext *dc, TCGv src)
32639422278eSRichard Henderson {
32649422278eSRichard Henderson #ifdef TARGET_SPARC64
32659422278eSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
32669422278eSRichard Henderson 
32679422278eSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
32689422278eSRichard Henderson     tcg_gen_st_tl(src, r_tsptr, offsetof(trap_state, tstate));
32699422278eSRichard Henderson #else
32709422278eSRichard Henderson     qemu_build_not_reached();
32719422278eSRichard Henderson #endif
32729422278eSRichard Henderson }
32739422278eSRichard Henderson 
32749422278eSRichard Henderson TRANS(WRPR_tstate, 64, do_wr_special, a, supervisor(dc), do_wrtstate)
32759422278eSRichard Henderson 
32769422278eSRichard Henderson static void do_wrtt(DisasContext *dc, TCGv src)
32779422278eSRichard Henderson {
32789422278eSRichard Henderson #ifdef TARGET_SPARC64
32799422278eSRichard Henderson     TCGv_ptr r_tsptr = tcg_temp_new_ptr();
32809422278eSRichard Henderson 
32819422278eSRichard Henderson     gen_load_trap_state_at_tl(r_tsptr);
32829422278eSRichard Henderson     tcg_gen_st32_tl(src, r_tsptr, offsetof(trap_state, tt));
32839422278eSRichard Henderson #else
32849422278eSRichard Henderson     qemu_build_not_reached();
32859422278eSRichard Henderson #endif
32869422278eSRichard Henderson }
32879422278eSRichard Henderson 
32889422278eSRichard Henderson TRANS(WRPR_tt, 64, do_wr_special, a, supervisor(dc), do_wrtt)
32899422278eSRichard Henderson 
32909422278eSRichard Henderson static void do_wrtick(DisasContext *dc, TCGv src)
32919422278eSRichard Henderson {
32929422278eSRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
32939422278eSRichard Henderson 
32949422278eSRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(tick));
32959422278eSRichard Henderson     translator_io_start(&dc->base);
32969422278eSRichard Henderson     gen_helper_tick_set_count(r_tickptr, src);
32979422278eSRichard Henderson     /* End TB to handle timer interrupt */
32989422278eSRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
32999422278eSRichard Henderson }
33009422278eSRichard Henderson 
33019422278eSRichard Henderson TRANS(WRPR_tick, 64, do_wr_special, a, supervisor(dc), do_wrtick)
33029422278eSRichard Henderson 
33039422278eSRichard Henderson static void do_wrtba(DisasContext *dc, TCGv src)
33049422278eSRichard Henderson {
33059422278eSRichard Henderson     tcg_gen_mov_tl(cpu_tbr, src);
33069422278eSRichard Henderson }
33079422278eSRichard Henderson 
33089422278eSRichard Henderson TRANS(WRPR_tba, 64, do_wr_special, a, supervisor(dc), do_wrtba)
33099422278eSRichard Henderson 
33109422278eSRichard Henderson static void do_wrpstate(DisasContext *dc, TCGv src)
33119422278eSRichard Henderson {
33129422278eSRichard Henderson     save_state(dc);
33139422278eSRichard Henderson     if (translator_io_start(&dc->base)) {
33149422278eSRichard Henderson         dc->base.is_jmp = DISAS_EXIT;
33159422278eSRichard Henderson     }
33169422278eSRichard Henderson     gen_helper_wrpstate(tcg_env, src);
33179422278eSRichard Henderson     dc->npc = DYNAMIC_PC;
33189422278eSRichard Henderson }
33199422278eSRichard Henderson 
33209422278eSRichard Henderson TRANS(WRPR_pstate, 64, do_wr_special, a, supervisor(dc), do_wrpstate)
33219422278eSRichard Henderson 
33229422278eSRichard Henderson static void do_wrtl(DisasContext *dc, TCGv src)
33239422278eSRichard Henderson {
33249422278eSRichard Henderson     save_state(dc);
33259422278eSRichard Henderson     tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(tl));
33269422278eSRichard Henderson     dc->npc = DYNAMIC_PC;
33279422278eSRichard Henderson }
33289422278eSRichard Henderson 
33299422278eSRichard Henderson TRANS(WRPR_tl, 64, do_wr_special, a, supervisor(dc), do_wrtl)
33309422278eSRichard Henderson 
33319422278eSRichard Henderson static void do_wrpil(DisasContext *dc, TCGv src)
33329422278eSRichard Henderson {
33339422278eSRichard Henderson     if (translator_io_start(&dc->base)) {
33349422278eSRichard Henderson         dc->base.is_jmp = DISAS_EXIT;
33359422278eSRichard Henderson     }
33369422278eSRichard Henderson     gen_helper_wrpil(tcg_env, src);
33379422278eSRichard Henderson }
33389422278eSRichard Henderson 
33399422278eSRichard Henderson TRANS(WRPR_pil, 64, do_wr_special, a, supervisor(dc), do_wrpil)
33409422278eSRichard Henderson 
33419422278eSRichard Henderson static void do_wrcwp(DisasContext *dc, TCGv src)
33429422278eSRichard Henderson {
33439422278eSRichard Henderson     gen_helper_wrcwp(tcg_env, src);
33449422278eSRichard Henderson }
33459422278eSRichard Henderson 
33469422278eSRichard Henderson TRANS(WRPR_cwp, 64, do_wr_special, a, supervisor(dc), do_wrcwp)
33479422278eSRichard Henderson 
33489422278eSRichard Henderson static void do_wrcansave(DisasContext *dc, TCGv src)
33499422278eSRichard Henderson {
33509422278eSRichard Henderson     tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(cansave));
33519422278eSRichard Henderson }
33529422278eSRichard Henderson 
33539422278eSRichard Henderson TRANS(WRPR_cansave, 64, do_wr_special, a, supervisor(dc), do_wrcansave)
33549422278eSRichard Henderson 
33559422278eSRichard Henderson static void do_wrcanrestore(DisasContext *dc, TCGv src)
33569422278eSRichard Henderson {
33579422278eSRichard Henderson     tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(canrestore));
33589422278eSRichard Henderson }
33599422278eSRichard Henderson 
33609422278eSRichard Henderson TRANS(WRPR_canrestore, 64, do_wr_special, a, supervisor(dc), do_wrcanrestore)
33619422278eSRichard Henderson 
33629422278eSRichard Henderson static void do_wrcleanwin(DisasContext *dc, TCGv src)
33639422278eSRichard Henderson {
33649422278eSRichard Henderson     tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(cleanwin));
33659422278eSRichard Henderson }
33669422278eSRichard Henderson 
33679422278eSRichard Henderson TRANS(WRPR_cleanwin, 64, do_wr_special, a, supervisor(dc), do_wrcleanwin)
33689422278eSRichard Henderson 
33699422278eSRichard Henderson static void do_wrotherwin(DisasContext *dc, TCGv src)
33709422278eSRichard Henderson {
33719422278eSRichard Henderson     tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(otherwin));
33729422278eSRichard Henderson }
33739422278eSRichard Henderson 
33749422278eSRichard Henderson TRANS(WRPR_otherwin, 64, do_wr_special, a, supervisor(dc), do_wrotherwin)
33759422278eSRichard Henderson 
33769422278eSRichard Henderson static void do_wrwstate(DisasContext *dc, TCGv src)
33779422278eSRichard Henderson {
33789422278eSRichard Henderson     tcg_gen_st32_tl(src, tcg_env, env64_field_offsetof(wstate));
33799422278eSRichard Henderson }
33809422278eSRichard Henderson 
33819422278eSRichard Henderson TRANS(WRPR_wstate, 64, do_wr_special, a, supervisor(dc), do_wrwstate)
33829422278eSRichard Henderson 
33839422278eSRichard Henderson static void do_wrgl(DisasContext *dc, TCGv src)
33849422278eSRichard Henderson {
33859422278eSRichard Henderson     gen_helper_wrgl(tcg_env, src);
33869422278eSRichard Henderson }
33879422278eSRichard Henderson 
33889422278eSRichard Henderson TRANS(WRPR_gl, GL, do_wr_special, a, supervisor(dc), do_wrgl)
33899422278eSRichard Henderson 
33909422278eSRichard Henderson /* UA2005 strand status */
33919422278eSRichard Henderson static void do_wrssr(DisasContext *dc, TCGv src)
33929422278eSRichard Henderson {
33932da789deSRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(ssr));
33949422278eSRichard Henderson }
33959422278eSRichard Henderson 
33969422278eSRichard Henderson TRANS(WRPR_strand_status, HYPV, do_wr_special, a, hypervisor(dc), do_wrssr)
33979422278eSRichard Henderson 
3398bb97f2f5SRichard Henderson TRANS(WRTBR, 32, do_wr_special, a, supervisor(dc), do_wrtba)
3399bb97f2f5SRichard Henderson 
3400bb97f2f5SRichard Henderson static void do_wrhpstate(DisasContext *dc, TCGv src)
3401bb97f2f5SRichard Henderson {
3402bb97f2f5SRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(hpstate));
3403bb97f2f5SRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
3404bb97f2f5SRichard Henderson }
3405bb97f2f5SRichard Henderson 
3406bb97f2f5SRichard Henderson TRANS(WRHPR_hpstate, HYPV, do_wr_special, a, hypervisor(dc), do_wrhpstate)
3407bb97f2f5SRichard Henderson 
3408bb97f2f5SRichard Henderson static void do_wrhtstate(DisasContext *dc, TCGv src)
3409bb97f2f5SRichard Henderson {
3410bb97f2f5SRichard Henderson     TCGv_i32 tl = tcg_temp_new_i32();
3411bb97f2f5SRichard Henderson     TCGv_ptr tp = tcg_temp_new_ptr();
3412bb97f2f5SRichard Henderson 
3413bb97f2f5SRichard Henderson     tcg_gen_ld_i32(tl, tcg_env, env64_field_offsetof(tl));
3414bb97f2f5SRichard Henderson     tcg_gen_andi_i32(tl, tl, MAXTL_MASK);
3415bb97f2f5SRichard Henderson     tcg_gen_shli_i32(tl, tl, 3);
3416bb97f2f5SRichard Henderson     tcg_gen_ext_i32_ptr(tp, tl);
3417bb97f2f5SRichard Henderson     tcg_gen_add_ptr(tp, tp, tcg_env);
3418bb97f2f5SRichard Henderson 
3419bb97f2f5SRichard Henderson     tcg_gen_st_tl(src, tp, env64_field_offsetof(htstate));
3420bb97f2f5SRichard Henderson }
3421bb97f2f5SRichard Henderson 
3422bb97f2f5SRichard Henderson TRANS(WRHPR_htstate, HYPV, do_wr_special, a, hypervisor(dc), do_wrhtstate)
3423bb97f2f5SRichard Henderson 
3424bb97f2f5SRichard Henderson static void do_wrhintp(DisasContext *dc, TCGv src)
3425bb97f2f5SRichard Henderson {
34262da789deSRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(hintp));
3427bb97f2f5SRichard Henderson }
3428bb97f2f5SRichard Henderson 
3429bb97f2f5SRichard Henderson TRANS(WRHPR_hintp, HYPV, do_wr_special, a, hypervisor(dc), do_wrhintp)
3430bb97f2f5SRichard Henderson 
3431bb97f2f5SRichard Henderson static void do_wrhtba(DisasContext *dc, TCGv src)
3432bb97f2f5SRichard Henderson {
34332da789deSRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(htba));
3434bb97f2f5SRichard Henderson }
3435bb97f2f5SRichard Henderson 
3436bb97f2f5SRichard Henderson TRANS(WRHPR_htba, HYPV, do_wr_special, a, hypervisor(dc), do_wrhtba)
3437bb97f2f5SRichard Henderson 
3438bb97f2f5SRichard Henderson static void do_wrhstick_cmpr(DisasContext *dc, TCGv src)
3439bb97f2f5SRichard Henderson {
3440bb97f2f5SRichard Henderson     TCGv_ptr r_tickptr = tcg_temp_new_ptr();
3441bb97f2f5SRichard Henderson 
3442577efa45SRichard Henderson     tcg_gen_st_tl(src, tcg_env, env64_field_offsetof(hstick_cmpr));
3443bb97f2f5SRichard Henderson     tcg_gen_ld_ptr(r_tickptr, tcg_env, env64_field_offsetof(hstick));
3444bb97f2f5SRichard Henderson     translator_io_start(&dc->base);
3445577efa45SRichard Henderson     gen_helper_tick_set_limit(r_tickptr, src);
3446bb97f2f5SRichard Henderson     /* End TB to handle timer interrupt */
3447bb97f2f5SRichard Henderson     dc->base.is_jmp = DISAS_EXIT;
3448bb97f2f5SRichard Henderson }
3449bb97f2f5SRichard Henderson 
3450bb97f2f5SRichard Henderson TRANS(WRHPR_hstick_cmpr, HYPV, do_wr_special, a, hypervisor(dc),
3451bb97f2f5SRichard Henderson       do_wrhstick_cmpr)
3452bb97f2f5SRichard Henderson 
345325524734SRichard Henderson static bool do_saved_restored(DisasContext *dc, bool saved)
345425524734SRichard Henderson {
345525524734SRichard Henderson     if (!supervisor(dc)) {
345625524734SRichard Henderson         return raise_priv(dc);
345725524734SRichard Henderson     }
345825524734SRichard Henderson     if (saved) {
345925524734SRichard Henderson         gen_helper_saved(tcg_env);
346025524734SRichard Henderson     } else {
346125524734SRichard Henderson         gen_helper_restored(tcg_env);
346225524734SRichard Henderson     }
346325524734SRichard Henderson     return advance_pc(dc);
346425524734SRichard Henderson }
346525524734SRichard Henderson 
346625524734SRichard Henderson TRANS(SAVED, 64, do_saved_restored, true)
346725524734SRichard Henderson TRANS(RESTORED, 64, do_saved_restored, false)
346825524734SRichard Henderson 
3469d3825800SRichard Henderson static bool trans_NOP(DisasContext *dc, arg_NOP *a)
3470d3825800SRichard Henderson {
3471d3825800SRichard Henderson     return advance_pc(dc);
3472d3825800SRichard Henderson }
3473d3825800SRichard Henderson 
34740faef01bSRichard Henderson /*
34750faef01bSRichard Henderson  * TODO: Need a feature bit for sparcv8.
34760faef01bSRichard Henderson  * In the meantime, treat all 32-bit cpus like sparcv7.
34770faef01bSRichard Henderson  */
34785458fd31SRichard Henderson TRANS(NOP_v7, 32, trans_NOP, a)
34795458fd31SRichard Henderson TRANS(NOP_v9, 64, trans_NOP, a)
34800faef01bSRichard Henderson 
3481b597eedcSRichard Henderson static bool do_arith_int(DisasContext *dc, arg_r_r_ri_cc *a,
3482428881deSRichard Henderson                          void (*func)(TCGv, TCGv, TCGv),
34832a45b736SRichard Henderson                          void (*funci)(TCGv, TCGv, target_long),
34842a45b736SRichard Henderson                          bool logic_cc)
3485428881deSRichard Henderson {
3486428881deSRichard Henderson     TCGv dst, src1;
3487428881deSRichard Henderson 
3488428881deSRichard Henderson     /* For simplicity, we under-decoded the rs2 form. */
3489428881deSRichard Henderson     if (!a->imm && a->rs2_or_imm & ~0x1f) {
3490428881deSRichard Henderson         return false;
3491428881deSRichard Henderson     }
3492428881deSRichard Henderson 
34932a45b736SRichard Henderson     if (logic_cc) {
34942a45b736SRichard Henderson         dst = cpu_cc_N;
3495428881deSRichard Henderson     } else {
3496428881deSRichard Henderson         dst = gen_dest_gpr(dc, a->rd);
3497428881deSRichard Henderson     }
3498428881deSRichard Henderson     src1 = gen_load_gpr(dc, a->rs1);
3499428881deSRichard Henderson 
3500428881deSRichard Henderson     if (a->imm || a->rs2_or_imm == 0) {
3501428881deSRichard Henderson         if (funci) {
3502428881deSRichard Henderson             funci(dst, src1, a->rs2_or_imm);
3503428881deSRichard Henderson         } else {
3504428881deSRichard Henderson             func(dst, src1, tcg_constant_tl(a->rs2_or_imm));
3505428881deSRichard Henderson         }
3506428881deSRichard Henderson     } else {
3507428881deSRichard Henderson         func(dst, src1, cpu_regs[a->rs2_or_imm]);
3508428881deSRichard Henderson     }
35092a45b736SRichard Henderson 
35102a45b736SRichard Henderson     if (logic_cc) {
35112a45b736SRichard Henderson         if (TARGET_LONG_BITS == 64) {
35122a45b736SRichard Henderson             tcg_gen_mov_tl(cpu_icc_Z, cpu_cc_N);
35132a45b736SRichard Henderson             tcg_gen_movi_tl(cpu_icc_C, 0);
35142a45b736SRichard Henderson         }
35152a45b736SRichard Henderson         tcg_gen_mov_tl(cpu_cc_Z, cpu_cc_N);
35162a45b736SRichard Henderson         tcg_gen_movi_tl(cpu_cc_C, 0);
35172a45b736SRichard Henderson         tcg_gen_movi_tl(cpu_cc_V, 0);
35182a45b736SRichard Henderson     }
35192a45b736SRichard Henderson 
3520428881deSRichard Henderson     gen_store_gpr(dc, a->rd, dst);
3521428881deSRichard Henderson     return advance_pc(dc);
3522428881deSRichard Henderson }
3523428881deSRichard Henderson 
3524b597eedcSRichard Henderson static bool do_arith(DisasContext *dc, arg_r_r_ri_cc *a,
3525428881deSRichard Henderson                      void (*func)(TCGv, TCGv, TCGv),
3526428881deSRichard Henderson                      void (*funci)(TCGv, TCGv, target_long),
3527428881deSRichard Henderson                      void (*func_cc)(TCGv, TCGv, TCGv))
3528428881deSRichard Henderson {
3529428881deSRichard Henderson     if (a->cc) {
3530b597eedcSRichard Henderson         return do_arith_int(dc, a, func_cc, NULL, false);
3531428881deSRichard Henderson     }
3532b597eedcSRichard Henderson     return do_arith_int(dc, a, func, funci, false);
3533428881deSRichard Henderson }
3534428881deSRichard Henderson 
3535428881deSRichard Henderson static bool do_logic(DisasContext *dc, arg_r_r_ri_cc *a,
3536428881deSRichard Henderson                      void (*func)(TCGv, TCGv, TCGv),
3537428881deSRichard Henderson                      void (*funci)(TCGv, TCGv, target_long))
3538428881deSRichard Henderson {
3539b597eedcSRichard Henderson     return do_arith_int(dc, a, func, funci, a->cc);
3540428881deSRichard Henderson }
3541428881deSRichard Henderson 
3542b597eedcSRichard Henderson TRANS(ADD, ALL, do_arith, a, tcg_gen_add_tl, tcg_gen_addi_tl, gen_op_addcc)
3543b597eedcSRichard Henderson TRANS(SUB, ALL, do_arith, a, tcg_gen_sub_tl, tcg_gen_subi_tl, gen_op_subcc)
3544b597eedcSRichard Henderson TRANS(ADDC, ALL, do_arith, a, gen_op_addc, NULL, gen_op_addccc)
3545b597eedcSRichard Henderson TRANS(SUBC, ALL, do_arith, a, gen_op_subc, NULL, gen_op_subccc)
3546428881deSRichard Henderson 
3547b597eedcSRichard Henderson TRANS(TADDcc, ALL, do_arith, a, NULL, NULL, gen_op_taddcc)
3548b597eedcSRichard Henderson TRANS(TSUBcc, ALL, do_arith, a, NULL, NULL, gen_op_tsubcc)
3549b597eedcSRichard Henderson TRANS(TADDccTV, ALL, do_arith, a, NULL, NULL, gen_op_taddcctv)
3550b597eedcSRichard Henderson TRANS(TSUBccTV, ALL, do_arith, a, NULL, NULL, gen_op_tsubcctv)
3551a9aba13dSRichard Henderson 
3552428881deSRichard Henderson TRANS(AND, ALL, do_logic, a, tcg_gen_and_tl, tcg_gen_andi_tl)
3553428881deSRichard Henderson TRANS(XOR, ALL, do_logic, a, tcg_gen_xor_tl, tcg_gen_xori_tl)
3554428881deSRichard Henderson TRANS(ANDN, ALL, do_logic, a, tcg_gen_andc_tl, NULL)
3555428881deSRichard Henderson TRANS(ORN, ALL, do_logic, a, tcg_gen_orc_tl, NULL)
3556428881deSRichard Henderson TRANS(XORN, ALL, do_logic, a, tcg_gen_eqv_tl, NULL)
3557428881deSRichard Henderson 
3558b597eedcSRichard Henderson TRANS(MULX, 64, do_arith, a, tcg_gen_mul_tl, tcg_gen_muli_tl, NULL)
3559b5372650SRichard Henderson TRANS(UMUL, MUL, do_logic, a, gen_op_umul, NULL)
3560b5372650SRichard Henderson TRANS(SMUL, MUL, do_logic, a, gen_op_smul, NULL)
3561b597eedcSRichard Henderson TRANS(MULScc, ALL, do_arith, a, NULL, NULL, gen_op_mulscc)
356222188d7dSRichard Henderson 
35633a6b8de3SRichard Henderson TRANS(UDIVcc, DIV, do_arith, a, NULL, NULL, gen_op_udivcc)
3564b597eedcSRichard Henderson TRANS(SDIV, DIV, do_arith, a, gen_op_sdiv, NULL, gen_op_sdivcc)
35654ee85ea9SRichard Henderson 
35669c6ec5bcSRichard Henderson /* TODO: Should have feature bit -- comes in with UltraSparc T2. */
3567b597eedcSRichard Henderson TRANS(POPC, 64, do_arith, a, gen_op_popc, NULL, NULL)
35689c6ec5bcSRichard Henderson 
3569428881deSRichard Henderson static bool trans_OR(DisasContext *dc, arg_r_r_ri_cc *a)
3570428881deSRichard Henderson {
3571428881deSRichard Henderson     /* OR with %g0 is the canonical alias for MOV. */
3572428881deSRichard Henderson     if (!a->cc && a->rs1 == 0) {
3573428881deSRichard Henderson         if (a->imm || a->rs2_or_imm == 0) {
3574428881deSRichard Henderson             gen_store_gpr(dc, a->rd, tcg_constant_tl(a->rs2_or_imm));
3575428881deSRichard Henderson         } else if (a->rs2_or_imm & ~0x1f) {
3576428881deSRichard Henderson             /* For simplicity, we under-decoded the rs2 form. */
3577428881deSRichard Henderson             return false;
3578428881deSRichard Henderson         } else {
3579428881deSRichard Henderson             gen_store_gpr(dc, a->rd, cpu_regs[a->rs2_or_imm]);
3580428881deSRichard Henderson         }
3581428881deSRichard Henderson         return advance_pc(dc);
3582428881deSRichard Henderson     }
3583428881deSRichard Henderson     return do_logic(dc, a, tcg_gen_or_tl, tcg_gen_ori_tl);
3584428881deSRichard Henderson }
3585428881deSRichard Henderson 
35863a6b8de3SRichard Henderson static bool trans_UDIV(DisasContext *dc, arg_r_r_ri *a)
35873a6b8de3SRichard Henderson {
35883a6b8de3SRichard Henderson     TCGv_i64 t1, t2;
35893a6b8de3SRichard Henderson     TCGv dst;
35903a6b8de3SRichard Henderson 
35913a6b8de3SRichard Henderson     if (!avail_DIV(dc)) {
35923a6b8de3SRichard Henderson         return false;
35933a6b8de3SRichard Henderson     }
35943a6b8de3SRichard Henderson     /* For simplicity, we under-decoded the rs2 form. */
35953a6b8de3SRichard Henderson     if (!a->imm && a->rs2_or_imm & ~0x1f) {
35963a6b8de3SRichard Henderson         return false;
35973a6b8de3SRichard Henderson     }
35983a6b8de3SRichard Henderson 
35993a6b8de3SRichard Henderson     if (unlikely(a->rs2_or_imm == 0)) {
36003a6b8de3SRichard Henderson         gen_exception(dc, TT_DIV_ZERO);
36013a6b8de3SRichard Henderson         return true;
36023a6b8de3SRichard Henderson     }
36033a6b8de3SRichard Henderson 
36043a6b8de3SRichard Henderson     if (a->imm) {
36053a6b8de3SRichard Henderson         t2 = tcg_constant_i64((uint32_t)a->rs2_or_imm);
36063a6b8de3SRichard Henderson     } else {
36073a6b8de3SRichard Henderson         TCGLabel *lab;
36083a6b8de3SRichard Henderson         TCGv_i32 n2;
36093a6b8de3SRichard Henderson 
36103a6b8de3SRichard Henderson         finishing_insn(dc);
36113a6b8de3SRichard Henderson         flush_cond(dc);
36123a6b8de3SRichard Henderson 
36133a6b8de3SRichard Henderson         n2 = tcg_temp_new_i32();
36143a6b8de3SRichard Henderson         tcg_gen_trunc_tl_i32(n2, cpu_regs[a->rs2_or_imm]);
36153a6b8de3SRichard Henderson 
36163a6b8de3SRichard Henderson         lab = delay_exception(dc, TT_DIV_ZERO);
36173a6b8de3SRichard Henderson         tcg_gen_brcondi_i32(TCG_COND_EQ, n2, 0, lab);
36183a6b8de3SRichard Henderson 
36193a6b8de3SRichard Henderson         t2 = tcg_temp_new_i64();
36203a6b8de3SRichard Henderson #ifdef TARGET_SPARC64
36213a6b8de3SRichard Henderson         tcg_gen_ext32u_i64(t2, cpu_regs[a->rs2_or_imm]);
36223a6b8de3SRichard Henderson #else
36233a6b8de3SRichard Henderson         tcg_gen_extu_i32_i64(t2, cpu_regs[a->rs2_or_imm]);
36243a6b8de3SRichard Henderson #endif
36253a6b8de3SRichard Henderson     }
36263a6b8de3SRichard Henderson 
36273a6b8de3SRichard Henderson     t1 = tcg_temp_new_i64();
36283a6b8de3SRichard Henderson     tcg_gen_concat_tl_i64(t1, gen_load_gpr(dc, a->rs1), cpu_y);
36293a6b8de3SRichard Henderson 
36303a6b8de3SRichard Henderson     tcg_gen_divu_i64(t1, t1, t2);
36313a6b8de3SRichard Henderson     tcg_gen_umin_i64(t1, t1, tcg_constant_i64(UINT32_MAX));
36323a6b8de3SRichard Henderson 
36333a6b8de3SRichard Henderson     dst = gen_dest_gpr(dc, a->rd);
36343a6b8de3SRichard Henderson     tcg_gen_trunc_i64_tl(dst, t1);
36353a6b8de3SRichard Henderson     gen_store_gpr(dc, a->rd, dst);
36363a6b8de3SRichard Henderson     return advance_pc(dc);
36373a6b8de3SRichard Henderson }
36383a6b8de3SRichard Henderson 
3639f3141174SRichard Henderson static bool trans_UDIVX(DisasContext *dc, arg_r_r_ri *a)
3640f3141174SRichard Henderson {
3641f3141174SRichard Henderson     TCGv dst, src1, src2;
3642f3141174SRichard Henderson 
3643f3141174SRichard Henderson     if (!avail_64(dc)) {
3644f3141174SRichard Henderson         return false;
3645f3141174SRichard Henderson     }
3646f3141174SRichard Henderson     /* For simplicity, we under-decoded the rs2 form. */
3647f3141174SRichard Henderson     if (!a->imm && a->rs2_or_imm & ~0x1f) {
3648f3141174SRichard Henderson         return false;
3649f3141174SRichard Henderson     }
3650f3141174SRichard Henderson 
3651f3141174SRichard Henderson     if (unlikely(a->rs2_or_imm == 0)) {
3652f3141174SRichard Henderson         gen_exception(dc, TT_DIV_ZERO);
3653f3141174SRichard Henderson         return true;
3654f3141174SRichard Henderson     }
3655f3141174SRichard Henderson 
3656f3141174SRichard Henderson     if (a->imm) {
3657f3141174SRichard Henderson         src2 = tcg_constant_tl(a->rs2_or_imm);
3658f3141174SRichard Henderson     } else {
3659f3141174SRichard Henderson         TCGLabel *lab;
3660f3141174SRichard Henderson 
3661f3141174SRichard Henderson         finishing_insn(dc);
3662f3141174SRichard Henderson         flush_cond(dc);
3663f3141174SRichard Henderson 
3664f3141174SRichard Henderson         lab = delay_exception(dc, TT_DIV_ZERO);
3665f3141174SRichard Henderson         src2 = cpu_regs[a->rs2_or_imm];
3666f3141174SRichard Henderson         tcg_gen_brcondi_tl(TCG_COND_EQ, src2, 0, lab);
3667f3141174SRichard Henderson     }
3668f3141174SRichard Henderson 
3669f3141174SRichard Henderson     dst = gen_dest_gpr(dc, a->rd);
3670f3141174SRichard Henderson     src1 = gen_load_gpr(dc, a->rs1);
3671f3141174SRichard Henderson 
3672f3141174SRichard Henderson     tcg_gen_divu_tl(dst, src1, src2);
3673f3141174SRichard Henderson     gen_store_gpr(dc, a->rd, dst);
3674f3141174SRichard Henderson     return advance_pc(dc);
3675f3141174SRichard Henderson }
3676f3141174SRichard Henderson 
3677f3141174SRichard Henderson static bool trans_SDIVX(DisasContext *dc, arg_r_r_ri *a)
3678f3141174SRichard Henderson {
3679f3141174SRichard Henderson     TCGv dst, src1, src2;
3680f3141174SRichard Henderson 
3681f3141174SRichard Henderson     if (!avail_64(dc)) {
3682f3141174SRichard Henderson         return false;
3683f3141174SRichard Henderson     }
3684f3141174SRichard Henderson     /* For simplicity, we under-decoded the rs2 form. */
3685f3141174SRichard Henderson     if (!a->imm && a->rs2_or_imm & ~0x1f) {
3686f3141174SRichard Henderson         return false;
3687f3141174SRichard Henderson     }
3688f3141174SRichard Henderson 
3689f3141174SRichard Henderson     if (unlikely(a->rs2_or_imm == 0)) {
3690f3141174SRichard Henderson         gen_exception(dc, TT_DIV_ZERO);
3691f3141174SRichard Henderson         return true;
3692f3141174SRichard Henderson     }
3693f3141174SRichard Henderson 
3694f3141174SRichard Henderson     dst = gen_dest_gpr(dc, a->rd);
3695f3141174SRichard Henderson     src1 = gen_load_gpr(dc, a->rs1);
3696f3141174SRichard Henderson 
3697f3141174SRichard Henderson     if (a->imm) {
3698f3141174SRichard Henderson         if (unlikely(a->rs2_or_imm == -1)) {
3699f3141174SRichard Henderson             tcg_gen_neg_tl(dst, src1);
3700f3141174SRichard Henderson             gen_store_gpr(dc, a->rd, dst);
3701f3141174SRichard Henderson             return advance_pc(dc);
3702f3141174SRichard Henderson         }
3703f3141174SRichard Henderson         src2 = tcg_constant_tl(a->rs2_or_imm);
3704f3141174SRichard Henderson     } else {
3705f3141174SRichard Henderson         TCGLabel *lab;
3706f3141174SRichard Henderson         TCGv t1, t2;
3707f3141174SRichard Henderson 
3708f3141174SRichard Henderson         finishing_insn(dc);
3709f3141174SRichard Henderson         flush_cond(dc);
3710f3141174SRichard Henderson 
3711f3141174SRichard Henderson         lab = delay_exception(dc, TT_DIV_ZERO);
3712f3141174SRichard Henderson         src2 = cpu_regs[a->rs2_or_imm];
3713f3141174SRichard Henderson         tcg_gen_brcondi_tl(TCG_COND_EQ, src2, 0, lab);
3714f3141174SRichard Henderson 
3715f3141174SRichard Henderson         /*
3716f3141174SRichard Henderson          * Need to avoid INT64_MIN / -1, which will trap on x86 host.
3717f3141174SRichard Henderson          * Set SRC2 to 1 as a new divisor, to produce the correct result.
3718f3141174SRichard Henderson          */
3719f3141174SRichard Henderson         t1 = tcg_temp_new();
3720f3141174SRichard Henderson         t2 = tcg_temp_new();
3721f3141174SRichard Henderson         tcg_gen_setcondi_tl(TCG_COND_EQ, t1, src1, (target_long)INT64_MIN);
3722f3141174SRichard Henderson         tcg_gen_setcondi_tl(TCG_COND_EQ, t2, src2, -1);
3723f3141174SRichard Henderson         tcg_gen_and_tl(t1, t1, t2);
3724f3141174SRichard Henderson         tcg_gen_movcond_tl(TCG_COND_NE, t1, t1, tcg_constant_tl(0),
3725f3141174SRichard Henderson                            tcg_constant_tl(1), src2);
3726f3141174SRichard Henderson         src2 = t1;
3727f3141174SRichard Henderson     }
3728f3141174SRichard Henderson 
3729f3141174SRichard Henderson     tcg_gen_div_tl(dst, src1, src2);
3730f3141174SRichard Henderson     gen_store_gpr(dc, a->rd, dst);
3731f3141174SRichard Henderson     return advance_pc(dc);
3732f3141174SRichard Henderson }
3733f3141174SRichard Henderson 
3734b88ce6f2SRichard Henderson static bool gen_edge(DisasContext *dc, arg_r_r_r *a,
3735b88ce6f2SRichard Henderson                      int width, bool cc, bool left)
3736b88ce6f2SRichard Henderson {
3737b88ce6f2SRichard Henderson     TCGv dst, s1, s2, lo1, lo2;
3738b88ce6f2SRichard Henderson     uint64_t amask, tabl, tabr;
3739b88ce6f2SRichard Henderson     int shift, imask, omask;
3740b88ce6f2SRichard Henderson 
3741b88ce6f2SRichard Henderson     dst = gen_dest_gpr(dc, a->rd);
3742b88ce6f2SRichard Henderson     s1 = gen_load_gpr(dc, a->rs1);
3743b88ce6f2SRichard Henderson     s2 = gen_load_gpr(dc, a->rs2);
3744b88ce6f2SRichard Henderson 
3745b88ce6f2SRichard Henderson     if (cc) {
3746f828df74SRichard Henderson         gen_op_subcc(cpu_cc_N, s1, s2);
3747b88ce6f2SRichard Henderson     }
3748b88ce6f2SRichard Henderson 
3749b88ce6f2SRichard Henderson     /*
3750b88ce6f2SRichard Henderson      * Theory of operation: there are two tables, left and right (not to
3751b88ce6f2SRichard Henderson      * be confused with the left and right versions of the opcode).  These
3752b88ce6f2SRichard Henderson      * are indexed by the low 3 bits of the inputs.  To make things "easy",
3753b88ce6f2SRichard Henderson      * these tables are loaded into two constants, TABL and TABR below.
3754b88ce6f2SRichard Henderson      * The operation index = (input & imask) << shift calculates the index
3755b88ce6f2SRichard Henderson      * into the constant, while val = (table >> index) & omask calculates
3756b88ce6f2SRichard Henderson      * the value we're looking for.
3757b88ce6f2SRichard Henderson      */
3758b88ce6f2SRichard Henderson     switch (width) {
3759b88ce6f2SRichard Henderson     case 8:
3760b88ce6f2SRichard Henderson         imask = 0x7;
3761b88ce6f2SRichard Henderson         shift = 3;
3762b88ce6f2SRichard Henderson         omask = 0xff;
3763b88ce6f2SRichard Henderson         if (left) {
3764b88ce6f2SRichard Henderson             tabl = 0x80c0e0f0f8fcfeffULL;
3765b88ce6f2SRichard Henderson             tabr = 0xff7f3f1f0f070301ULL;
3766b88ce6f2SRichard Henderson         } else {
3767b88ce6f2SRichard Henderson             tabl = 0x0103070f1f3f7fffULL;
3768b88ce6f2SRichard Henderson             tabr = 0xfffefcf8f0e0c080ULL;
3769b88ce6f2SRichard Henderson         }
3770b88ce6f2SRichard Henderson         break;
3771b88ce6f2SRichard Henderson     case 16:
3772b88ce6f2SRichard Henderson         imask = 0x6;
3773b88ce6f2SRichard Henderson         shift = 1;
3774b88ce6f2SRichard Henderson         omask = 0xf;
3775b88ce6f2SRichard Henderson         if (left) {
3776b88ce6f2SRichard Henderson             tabl = 0x8cef;
3777b88ce6f2SRichard Henderson             tabr = 0xf731;
3778b88ce6f2SRichard Henderson         } else {
3779b88ce6f2SRichard Henderson             tabl = 0x137f;
3780b88ce6f2SRichard Henderson             tabr = 0xfec8;
3781b88ce6f2SRichard Henderson         }
3782b88ce6f2SRichard Henderson         break;
3783b88ce6f2SRichard Henderson     case 32:
3784b88ce6f2SRichard Henderson         imask = 0x4;
3785b88ce6f2SRichard Henderson         shift = 0;
3786b88ce6f2SRichard Henderson         omask = 0x3;
3787b88ce6f2SRichard Henderson         if (left) {
3788b88ce6f2SRichard Henderson             tabl = (2 << 2) | 3;
3789b88ce6f2SRichard Henderson             tabr = (3 << 2) | 1;
3790b88ce6f2SRichard Henderson         } else {
3791b88ce6f2SRichard Henderson             tabl = (1 << 2) | 3;
3792b88ce6f2SRichard Henderson             tabr = (3 << 2) | 2;
3793b88ce6f2SRichard Henderson         }
3794b88ce6f2SRichard Henderson         break;
3795b88ce6f2SRichard Henderson     default:
3796b88ce6f2SRichard Henderson         abort();
3797b88ce6f2SRichard Henderson     }
3798b88ce6f2SRichard Henderson 
3799b88ce6f2SRichard Henderson     lo1 = tcg_temp_new();
3800b88ce6f2SRichard Henderson     lo2 = tcg_temp_new();
3801b88ce6f2SRichard Henderson     tcg_gen_andi_tl(lo1, s1, imask);
3802b88ce6f2SRichard Henderson     tcg_gen_andi_tl(lo2, s2, imask);
3803b88ce6f2SRichard Henderson     tcg_gen_shli_tl(lo1, lo1, shift);
3804b88ce6f2SRichard Henderson     tcg_gen_shli_tl(lo2, lo2, shift);
3805b88ce6f2SRichard Henderson 
3806b88ce6f2SRichard Henderson     tcg_gen_shr_tl(lo1, tcg_constant_tl(tabl), lo1);
3807b88ce6f2SRichard Henderson     tcg_gen_shr_tl(lo2, tcg_constant_tl(tabr), lo2);
3808b88ce6f2SRichard Henderson     tcg_gen_andi_tl(lo1, lo1, omask);
3809b88ce6f2SRichard Henderson     tcg_gen_andi_tl(lo2, lo2, omask);
3810b88ce6f2SRichard Henderson 
3811b88ce6f2SRichard Henderson     amask = address_mask_i(dc, -8);
3812b88ce6f2SRichard Henderson     tcg_gen_andi_tl(s1, s1, amask);
3813b88ce6f2SRichard Henderson     tcg_gen_andi_tl(s2, s2, amask);
3814b88ce6f2SRichard Henderson 
3815b88ce6f2SRichard Henderson     /* Compute dst = (s1 == s2 ? lo1 : lo1 & lo2). */
3816b88ce6f2SRichard Henderson     tcg_gen_and_tl(lo2, lo2, lo1);
3817b88ce6f2SRichard Henderson     tcg_gen_movcond_tl(TCG_COND_EQ, dst, s1, s2, lo1, lo2);
3818b88ce6f2SRichard Henderson 
3819b88ce6f2SRichard Henderson     gen_store_gpr(dc, a->rd, dst);
3820b88ce6f2SRichard Henderson     return advance_pc(dc);
3821b88ce6f2SRichard Henderson }
3822b88ce6f2SRichard Henderson 
3823b88ce6f2SRichard Henderson TRANS(EDGE8cc, VIS1, gen_edge, a, 8, 1, 0)
3824b88ce6f2SRichard Henderson TRANS(EDGE8Lcc, VIS1, gen_edge, a, 8, 1, 1)
3825b88ce6f2SRichard Henderson TRANS(EDGE16cc, VIS1, gen_edge, a, 16, 1, 0)
3826b88ce6f2SRichard Henderson TRANS(EDGE16Lcc, VIS1, gen_edge, a, 16, 1, 1)
3827b88ce6f2SRichard Henderson TRANS(EDGE32cc, VIS1, gen_edge, a, 32, 1, 0)
3828b88ce6f2SRichard Henderson TRANS(EDGE32Lcc, VIS1, gen_edge, a, 32, 1, 1)
3829b88ce6f2SRichard Henderson 
3830b88ce6f2SRichard Henderson TRANS(EDGE8N, VIS2, gen_edge, a, 8, 0, 0)
3831b88ce6f2SRichard Henderson TRANS(EDGE8LN, VIS2, gen_edge, a, 8, 0, 1)
3832b88ce6f2SRichard Henderson TRANS(EDGE16N, VIS2, gen_edge, a, 16, 0, 0)
3833b88ce6f2SRichard Henderson TRANS(EDGE16LN, VIS2, gen_edge, a, 16, 0, 1)
3834b88ce6f2SRichard Henderson TRANS(EDGE32N, VIS2, gen_edge, a, 32, 0, 0)
3835b88ce6f2SRichard Henderson TRANS(EDGE32LN, VIS2, gen_edge, a, 32, 0, 1)
3836b88ce6f2SRichard Henderson 
383745bfed3bSRichard Henderson static bool do_rrr(DisasContext *dc, arg_r_r_r *a,
383845bfed3bSRichard Henderson                    void (*func)(TCGv, TCGv, TCGv))
383945bfed3bSRichard Henderson {
384045bfed3bSRichard Henderson     TCGv dst = gen_dest_gpr(dc, a->rd);
384145bfed3bSRichard Henderson     TCGv src1 = gen_load_gpr(dc, a->rs1);
384245bfed3bSRichard Henderson     TCGv src2 = gen_load_gpr(dc, a->rs2);
384345bfed3bSRichard Henderson 
384445bfed3bSRichard Henderson     func(dst, src1, src2);
384545bfed3bSRichard Henderson     gen_store_gpr(dc, a->rd, dst);
384645bfed3bSRichard Henderson     return advance_pc(dc);
384745bfed3bSRichard Henderson }
384845bfed3bSRichard Henderson 
384945bfed3bSRichard Henderson TRANS(ARRAY8, VIS1, do_rrr, a, gen_helper_array8)
385045bfed3bSRichard Henderson TRANS(ARRAY16, VIS1, do_rrr, a, gen_op_array16)
385145bfed3bSRichard Henderson TRANS(ARRAY32, VIS1, do_rrr, a, gen_op_array32)
385245bfed3bSRichard Henderson 
38539e20ca94SRichard Henderson static void gen_op_alignaddr(TCGv dst, TCGv s1, TCGv s2)
38549e20ca94SRichard Henderson {
38559e20ca94SRichard Henderson #ifdef TARGET_SPARC64
38569e20ca94SRichard Henderson     TCGv tmp = tcg_temp_new();
38579e20ca94SRichard Henderson 
38589e20ca94SRichard Henderson     tcg_gen_add_tl(tmp, s1, s2);
38599e20ca94SRichard Henderson     tcg_gen_andi_tl(dst, tmp, -8);
38609e20ca94SRichard Henderson     tcg_gen_deposit_tl(cpu_gsr, cpu_gsr, tmp, 0, 3);
38619e20ca94SRichard Henderson #else
38629e20ca94SRichard Henderson     g_assert_not_reached();
38639e20ca94SRichard Henderson #endif
38649e20ca94SRichard Henderson }
38659e20ca94SRichard Henderson 
38669e20ca94SRichard Henderson static void gen_op_alignaddrl(TCGv dst, TCGv s1, TCGv s2)
38679e20ca94SRichard Henderson {
38689e20ca94SRichard Henderson #ifdef TARGET_SPARC64
38699e20ca94SRichard Henderson     TCGv tmp = tcg_temp_new();
38709e20ca94SRichard Henderson 
38719e20ca94SRichard Henderson     tcg_gen_add_tl(tmp, s1, s2);
38729e20ca94SRichard Henderson     tcg_gen_andi_tl(dst, tmp, -8);
38739e20ca94SRichard Henderson     tcg_gen_neg_tl(tmp, tmp);
38749e20ca94SRichard Henderson     tcg_gen_deposit_tl(cpu_gsr, cpu_gsr, tmp, 0, 3);
38759e20ca94SRichard Henderson #else
38769e20ca94SRichard Henderson     g_assert_not_reached();
38779e20ca94SRichard Henderson #endif
38789e20ca94SRichard Henderson }
38799e20ca94SRichard Henderson 
38809e20ca94SRichard Henderson TRANS(ALIGNADDR, VIS1, do_rrr, a, gen_op_alignaddr)
38819e20ca94SRichard Henderson TRANS(ALIGNADDRL, VIS1, do_rrr, a, gen_op_alignaddrl)
38829e20ca94SRichard Henderson 
388339ca3490SRichard Henderson static void gen_op_bmask(TCGv dst, TCGv s1, TCGv s2)
388439ca3490SRichard Henderson {
388539ca3490SRichard Henderson #ifdef TARGET_SPARC64
388639ca3490SRichard Henderson     tcg_gen_add_tl(dst, s1, s2);
388739ca3490SRichard Henderson     tcg_gen_deposit_tl(cpu_gsr, cpu_gsr, dst, 32, 32);
388839ca3490SRichard Henderson #else
388939ca3490SRichard Henderson     g_assert_not_reached();
389039ca3490SRichard Henderson #endif
389139ca3490SRichard Henderson }
389239ca3490SRichard Henderson 
389339ca3490SRichard Henderson TRANS(BMASK, VIS2, do_rrr, a, gen_op_bmask)
389439ca3490SRichard Henderson 
38955fc546eeSRichard Henderson static bool do_shift_r(DisasContext *dc, arg_shiftr *a, bool l, bool u)
38965fc546eeSRichard Henderson {
38975fc546eeSRichard Henderson     TCGv dst, src1, src2;
38985fc546eeSRichard Henderson 
38995fc546eeSRichard Henderson     /* Reject 64-bit shifts for sparc32. */
39005fc546eeSRichard Henderson     if (avail_32(dc) && a->x) {
39015fc546eeSRichard Henderson         return false;
39025fc546eeSRichard Henderson     }
39035fc546eeSRichard Henderson 
39045fc546eeSRichard Henderson     src2 = tcg_temp_new();
39055fc546eeSRichard Henderson     tcg_gen_andi_tl(src2, gen_load_gpr(dc, a->rs2), a->x ? 63 : 31);
39065fc546eeSRichard Henderson     src1 = gen_load_gpr(dc, a->rs1);
39075fc546eeSRichard Henderson     dst = gen_dest_gpr(dc, a->rd);
39085fc546eeSRichard Henderson 
39095fc546eeSRichard Henderson     if (l) {
39105fc546eeSRichard Henderson         tcg_gen_shl_tl(dst, src1, src2);
39115fc546eeSRichard Henderson         if (!a->x) {
39125fc546eeSRichard Henderson             tcg_gen_ext32u_tl(dst, dst);
39135fc546eeSRichard Henderson         }
39145fc546eeSRichard Henderson     } else if (u) {
39155fc546eeSRichard Henderson         if (!a->x) {
39165fc546eeSRichard Henderson             tcg_gen_ext32u_tl(dst, src1);
39175fc546eeSRichard Henderson             src1 = dst;
39185fc546eeSRichard Henderson         }
39195fc546eeSRichard Henderson         tcg_gen_shr_tl(dst, src1, src2);
39205fc546eeSRichard Henderson     } else {
39215fc546eeSRichard Henderson         if (!a->x) {
39225fc546eeSRichard Henderson             tcg_gen_ext32s_tl(dst, src1);
39235fc546eeSRichard Henderson             src1 = dst;
39245fc546eeSRichard Henderson         }
39255fc546eeSRichard Henderson         tcg_gen_sar_tl(dst, src1, src2);
39265fc546eeSRichard Henderson     }
39275fc546eeSRichard Henderson     gen_store_gpr(dc, a->rd, dst);
39285fc546eeSRichard Henderson     return advance_pc(dc);
39295fc546eeSRichard Henderson }
39305fc546eeSRichard Henderson 
39315fc546eeSRichard Henderson TRANS(SLL_r, ALL, do_shift_r, a, true, true)
39325fc546eeSRichard Henderson TRANS(SRL_r, ALL, do_shift_r, a, false, true)
39335fc546eeSRichard Henderson TRANS(SRA_r, ALL, do_shift_r, a, false, false)
39345fc546eeSRichard Henderson 
39355fc546eeSRichard Henderson static bool do_shift_i(DisasContext *dc, arg_shifti *a, bool l, bool u)
39365fc546eeSRichard Henderson {
39375fc546eeSRichard Henderson     TCGv dst, src1;
39385fc546eeSRichard Henderson 
39395fc546eeSRichard Henderson     /* Reject 64-bit shifts for sparc32. */
39405fc546eeSRichard Henderson     if (avail_32(dc) && (a->x || a->i >= 32)) {
39415fc546eeSRichard Henderson         return false;
39425fc546eeSRichard Henderson     }
39435fc546eeSRichard Henderson 
39445fc546eeSRichard Henderson     src1 = gen_load_gpr(dc, a->rs1);
39455fc546eeSRichard Henderson     dst = gen_dest_gpr(dc, a->rd);
39465fc546eeSRichard Henderson 
39475fc546eeSRichard Henderson     if (avail_32(dc) || a->x) {
39485fc546eeSRichard Henderson         if (l) {
39495fc546eeSRichard Henderson             tcg_gen_shli_tl(dst, src1, a->i);
39505fc546eeSRichard Henderson         } else if (u) {
39515fc546eeSRichard Henderson             tcg_gen_shri_tl(dst, src1, a->i);
39525fc546eeSRichard Henderson         } else {
39535fc546eeSRichard Henderson             tcg_gen_sari_tl(dst, src1, a->i);
39545fc546eeSRichard Henderson         }
39555fc546eeSRichard Henderson     } else {
39565fc546eeSRichard Henderson         if (l) {
39575fc546eeSRichard Henderson             tcg_gen_deposit_z_tl(dst, src1, a->i, 32 - a->i);
39585fc546eeSRichard Henderson         } else if (u) {
39595fc546eeSRichard Henderson             tcg_gen_extract_tl(dst, src1, a->i, 32 - a->i);
39605fc546eeSRichard Henderson         } else {
39615fc546eeSRichard Henderson             tcg_gen_sextract_tl(dst, src1, a->i, 32 - a->i);
39625fc546eeSRichard Henderson         }
39635fc546eeSRichard Henderson     }
39645fc546eeSRichard Henderson     gen_store_gpr(dc, a->rd, dst);
39655fc546eeSRichard Henderson     return advance_pc(dc);
39665fc546eeSRichard Henderson }
39675fc546eeSRichard Henderson 
39685fc546eeSRichard Henderson TRANS(SLL_i, ALL, do_shift_i, a, true, true)
39695fc546eeSRichard Henderson TRANS(SRL_i, ALL, do_shift_i, a, false, true)
39705fc546eeSRichard Henderson TRANS(SRA_i, ALL, do_shift_i, a, false, false)
39715fc546eeSRichard Henderson 
3972fb4ed7aaSRichard Henderson static TCGv gen_rs2_or_imm(DisasContext *dc, bool imm, int rs2_or_imm)
3973fb4ed7aaSRichard Henderson {
3974fb4ed7aaSRichard Henderson     /* For simplicity, we under-decoded the rs2 form. */
3975fb4ed7aaSRichard Henderson     if (!imm && rs2_or_imm & ~0x1f) {
3976fb4ed7aaSRichard Henderson         return NULL;
3977fb4ed7aaSRichard Henderson     }
3978fb4ed7aaSRichard Henderson     if (imm || rs2_or_imm == 0) {
3979fb4ed7aaSRichard Henderson         return tcg_constant_tl(rs2_or_imm);
3980fb4ed7aaSRichard Henderson     } else {
3981fb4ed7aaSRichard Henderson         return cpu_regs[rs2_or_imm];
3982fb4ed7aaSRichard Henderson     }
3983fb4ed7aaSRichard Henderson }
3984fb4ed7aaSRichard Henderson 
3985fb4ed7aaSRichard Henderson static bool do_mov_cond(DisasContext *dc, DisasCompare *cmp, int rd, TCGv src2)
3986fb4ed7aaSRichard Henderson {
3987fb4ed7aaSRichard Henderson     TCGv dst = gen_load_gpr(dc, rd);
3988c8507ebfSRichard Henderson     TCGv c2 = tcg_constant_tl(cmp->c2);
3989fb4ed7aaSRichard Henderson 
3990c8507ebfSRichard Henderson     tcg_gen_movcond_tl(cmp->cond, dst, cmp->c1, c2, src2, dst);
3991fb4ed7aaSRichard Henderson     gen_store_gpr(dc, rd, dst);
3992fb4ed7aaSRichard Henderson     return advance_pc(dc);
3993fb4ed7aaSRichard Henderson }
3994fb4ed7aaSRichard Henderson 
3995fb4ed7aaSRichard Henderson static bool trans_MOVcc(DisasContext *dc, arg_MOVcc *a)
3996fb4ed7aaSRichard Henderson {
3997fb4ed7aaSRichard Henderson     TCGv src2 = gen_rs2_or_imm(dc, a->imm, a->rs2_or_imm);
3998fb4ed7aaSRichard Henderson     DisasCompare cmp;
3999fb4ed7aaSRichard Henderson 
4000fb4ed7aaSRichard Henderson     if (src2 == NULL) {
4001fb4ed7aaSRichard Henderson         return false;
4002fb4ed7aaSRichard Henderson     }
4003fb4ed7aaSRichard Henderson     gen_compare(&cmp, a->cc, a->cond, dc);
4004fb4ed7aaSRichard Henderson     return do_mov_cond(dc, &cmp, a->rd, src2);
4005fb4ed7aaSRichard Henderson }
4006fb4ed7aaSRichard Henderson 
4007fb4ed7aaSRichard Henderson static bool trans_MOVfcc(DisasContext *dc, arg_MOVfcc *a)
4008fb4ed7aaSRichard Henderson {
4009fb4ed7aaSRichard Henderson     TCGv src2 = gen_rs2_or_imm(dc, a->imm, a->rs2_or_imm);
4010fb4ed7aaSRichard Henderson     DisasCompare cmp;
4011fb4ed7aaSRichard Henderson 
4012fb4ed7aaSRichard Henderson     if (src2 == NULL) {
4013fb4ed7aaSRichard Henderson         return false;
4014fb4ed7aaSRichard Henderson     }
4015fb4ed7aaSRichard Henderson     gen_fcompare(&cmp, a->cc, a->cond);
4016fb4ed7aaSRichard Henderson     return do_mov_cond(dc, &cmp, a->rd, src2);
4017fb4ed7aaSRichard Henderson }
4018fb4ed7aaSRichard Henderson 
4019fb4ed7aaSRichard Henderson static bool trans_MOVR(DisasContext *dc, arg_MOVR *a)
4020fb4ed7aaSRichard Henderson {
4021fb4ed7aaSRichard Henderson     TCGv src2 = gen_rs2_or_imm(dc, a->imm, a->rs2_or_imm);
4022fb4ed7aaSRichard Henderson     DisasCompare cmp;
4023fb4ed7aaSRichard Henderson 
4024fb4ed7aaSRichard Henderson     if (src2 == NULL) {
4025fb4ed7aaSRichard Henderson         return false;
4026fb4ed7aaSRichard Henderson     }
40272c4f56c9SRichard Henderson     if (!gen_compare_reg(&cmp, a->cond, gen_load_gpr(dc, a->rs1))) {
40282c4f56c9SRichard Henderson         return false;
40292c4f56c9SRichard Henderson     }
4030fb4ed7aaSRichard Henderson     return do_mov_cond(dc, &cmp, a->rd, src2);
4031fb4ed7aaSRichard Henderson }
4032fb4ed7aaSRichard Henderson 
403386b82fe0SRichard Henderson static bool do_add_special(DisasContext *dc, arg_r_r_ri *a,
403486b82fe0SRichard Henderson                            bool (*func)(DisasContext *dc, int rd, TCGv src))
403586b82fe0SRichard Henderson {
403686b82fe0SRichard Henderson     TCGv src1, sum;
403786b82fe0SRichard Henderson 
403886b82fe0SRichard Henderson     /* For simplicity, we under-decoded the rs2 form. */
403986b82fe0SRichard Henderson     if (!a->imm && a->rs2_or_imm & ~0x1f) {
404086b82fe0SRichard Henderson         return false;
404186b82fe0SRichard Henderson     }
404286b82fe0SRichard Henderson 
404386b82fe0SRichard Henderson     /*
404486b82fe0SRichard Henderson      * Always load the sum into a new temporary.
404586b82fe0SRichard Henderson      * This is required to capture the value across a window change,
404686b82fe0SRichard Henderson      * e.g. SAVE and RESTORE, and may be optimized away otherwise.
404786b82fe0SRichard Henderson      */
404886b82fe0SRichard Henderson     sum = tcg_temp_new();
404986b82fe0SRichard Henderson     src1 = gen_load_gpr(dc, a->rs1);
405086b82fe0SRichard Henderson     if (a->imm || a->rs2_or_imm == 0) {
405186b82fe0SRichard Henderson         tcg_gen_addi_tl(sum, src1, a->rs2_or_imm);
405286b82fe0SRichard Henderson     } else {
405386b82fe0SRichard Henderson         tcg_gen_add_tl(sum, src1, cpu_regs[a->rs2_or_imm]);
405486b82fe0SRichard Henderson     }
405586b82fe0SRichard Henderson     return func(dc, a->rd, sum);
405686b82fe0SRichard Henderson }
405786b82fe0SRichard Henderson 
405886b82fe0SRichard Henderson static bool do_jmpl(DisasContext *dc, int rd, TCGv src)
405986b82fe0SRichard Henderson {
406086b82fe0SRichard Henderson     /*
406186b82fe0SRichard Henderson      * Preserve pc across advance, so that we can delay
406286b82fe0SRichard Henderson      * the writeback to rd until after src is consumed.
406386b82fe0SRichard Henderson      */
406486b82fe0SRichard Henderson     target_ulong cur_pc = dc->pc;
406586b82fe0SRichard Henderson 
406686b82fe0SRichard Henderson     gen_check_align(dc, src, 3);
406786b82fe0SRichard Henderson 
406886b82fe0SRichard Henderson     gen_mov_pc_npc(dc);
406986b82fe0SRichard Henderson     tcg_gen_mov_tl(cpu_npc, src);
407086b82fe0SRichard Henderson     gen_address_mask(dc, cpu_npc);
407186b82fe0SRichard Henderson     gen_store_gpr(dc, rd, tcg_constant_tl(cur_pc));
407286b82fe0SRichard Henderson 
407386b82fe0SRichard Henderson     dc->npc = DYNAMIC_PC_LOOKUP;
407486b82fe0SRichard Henderson     return true;
407586b82fe0SRichard Henderson }
407686b82fe0SRichard Henderson 
407786b82fe0SRichard Henderson TRANS(JMPL, ALL, do_add_special, a, do_jmpl)
407886b82fe0SRichard Henderson 
407986b82fe0SRichard Henderson static bool do_rett(DisasContext *dc, int rd, TCGv src)
408086b82fe0SRichard Henderson {
408186b82fe0SRichard Henderson     if (!supervisor(dc)) {
408286b82fe0SRichard Henderson         return raise_priv(dc);
408386b82fe0SRichard Henderson     }
408486b82fe0SRichard Henderson 
408586b82fe0SRichard Henderson     gen_check_align(dc, src, 3);
408686b82fe0SRichard Henderson 
408786b82fe0SRichard Henderson     gen_mov_pc_npc(dc);
408886b82fe0SRichard Henderson     tcg_gen_mov_tl(cpu_npc, src);
408986b82fe0SRichard Henderson     gen_helper_rett(tcg_env);
409086b82fe0SRichard Henderson 
409186b82fe0SRichard Henderson     dc->npc = DYNAMIC_PC;
409286b82fe0SRichard Henderson     return true;
409386b82fe0SRichard Henderson }
409486b82fe0SRichard Henderson 
409586b82fe0SRichard Henderson TRANS(RETT, 32, do_add_special, a, do_rett)
409686b82fe0SRichard Henderson 
409786b82fe0SRichard Henderson static bool do_return(DisasContext *dc, int rd, TCGv src)
409886b82fe0SRichard Henderson {
409986b82fe0SRichard Henderson     gen_check_align(dc, src, 3);
41000dfae4f9SRichard Henderson     gen_helper_restore(tcg_env);
410186b82fe0SRichard Henderson 
410286b82fe0SRichard Henderson     gen_mov_pc_npc(dc);
410386b82fe0SRichard Henderson     tcg_gen_mov_tl(cpu_npc, src);
410486b82fe0SRichard Henderson     gen_address_mask(dc, cpu_npc);
410586b82fe0SRichard Henderson 
410686b82fe0SRichard Henderson     dc->npc = DYNAMIC_PC_LOOKUP;
410786b82fe0SRichard Henderson     return true;
410886b82fe0SRichard Henderson }
410986b82fe0SRichard Henderson 
411086b82fe0SRichard Henderson TRANS(RETURN, 64, do_add_special, a, do_return)
411186b82fe0SRichard Henderson 
4112d3825800SRichard Henderson static bool do_save(DisasContext *dc, int rd, TCGv src)
4113d3825800SRichard Henderson {
4114d3825800SRichard Henderson     gen_helper_save(tcg_env);
4115d3825800SRichard Henderson     gen_store_gpr(dc, rd, src);
4116d3825800SRichard Henderson     return advance_pc(dc);
4117d3825800SRichard Henderson }
4118d3825800SRichard Henderson 
4119d3825800SRichard Henderson TRANS(SAVE, ALL, do_add_special, a, do_save)
4120d3825800SRichard Henderson 
4121d3825800SRichard Henderson static bool do_restore(DisasContext *dc, int rd, TCGv src)
4122d3825800SRichard Henderson {
4123d3825800SRichard Henderson     gen_helper_restore(tcg_env);
4124d3825800SRichard Henderson     gen_store_gpr(dc, rd, src);
4125d3825800SRichard Henderson     return advance_pc(dc);
4126d3825800SRichard Henderson }
4127d3825800SRichard Henderson 
4128d3825800SRichard Henderson TRANS(RESTORE, ALL, do_add_special, a, do_restore)
4129d3825800SRichard Henderson 
41308f75b8a4SRichard Henderson static bool do_done_retry(DisasContext *dc, bool done)
41318f75b8a4SRichard Henderson {
41328f75b8a4SRichard Henderson     if (!supervisor(dc)) {
41338f75b8a4SRichard Henderson         return raise_priv(dc);
41348f75b8a4SRichard Henderson     }
41358f75b8a4SRichard Henderson     dc->npc = DYNAMIC_PC;
41368f75b8a4SRichard Henderson     dc->pc = DYNAMIC_PC;
41378f75b8a4SRichard Henderson     translator_io_start(&dc->base);
41388f75b8a4SRichard Henderson     if (done) {
41398f75b8a4SRichard Henderson         gen_helper_done(tcg_env);
41408f75b8a4SRichard Henderson     } else {
41418f75b8a4SRichard Henderson         gen_helper_retry(tcg_env);
41428f75b8a4SRichard Henderson     }
41438f75b8a4SRichard Henderson     return true;
41448f75b8a4SRichard Henderson }
41458f75b8a4SRichard Henderson 
41468f75b8a4SRichard Henderson TRANS(DONE, 64, do_done_retry, true)
41478f75b8a4SRichard Henderson TRANS(RETRY, 64, do_done_retry, false)
41488f75b8a4SRichard Henderson 
41490880d20bSRichard Henderson /*
41500880d20bSRichard Henderson  * Major opcode 11 -- load and store instructions
41510880d20bSRichard Henderson  */
41520880d20bSRichard Henderson 
41530880d20bSRichard Henderson static TCGv gen_ldst_addr(DisasContext *dc, int rs1, bool imm, int rs2_or_imm)
41540880d20bSRichard Henderson {
41550880d20bSRichard Henderson     TCGv addr, tmp = NULL;
41560880d20bSRichard Henderson 
41570880d20bSRichard Henderson     /* For simplicity, we under-decoded the rs2 form. */
41580880d20bSRichard Henderson     if (!imm && rs2_or_imm & ~0x1f) {
41590880d20bSRichard Henderson         return NULL;
41600880d20bSRichard Henderson     }
41610880d20bSRichard Henderson 
41620880d20bSRichard Henderson     addr = gen_load_gpr(dc, rs1);
41630880d20bSRichard Henderson     if (rs2_or_imm) {
41640880d20bSRichard Henderson         tmp = tcg_temp_new();
41650880d20bSRichard Henderson         if (imm) {
41660880d20bSRichard Henderson             tcg_gen_addi_tl(tmp, addr, rs2_or_imm);
41670880d20bSRichard Henderson         } else {
41680880d20bSRichard Henderson             tcg_gen_add_tl(tmp, addr, cpu_regs[rs2_or_imm]);
41690880d20bSRichard Henderson         }
41700880d20bSRichard Henderson         addr = tmp;
41710880d20bSRichard Henderson     }
41720880d20bSRichard Henderson     if (AM_CHECK(dc)) {
41730880d20bSRichard Henderson         if (!tmp) {
41740880d20bSRichard Henderson             tmp = tcg_temp_new();
41750880d20bSRichard Henderson         }
41760880d20bSRichard Henderson         tcg_gen_ext32u_tl(tmp, addr);
41770880d20bSRichard Henderson         addr = tmp;
41780880d20bSRichard Henderson     }
41790880d20bSRichard Henderson     return addr;
41800880d20bSRichard Henderson }
41810880d20bSRichard Henderson 
41820880d20bSRichard Henderson static bool do_ld_gpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp mop)
41830880d20bSRichard Henderson {
41840880d20bSRichard Henderson     TCGv reg, addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
41850880d20bSRichard Henderson     DisasASI da;
41860880d20bSRichard Henderson 
41870880d20bSRichard Henderson     if (addr == NULL) {
41880880d20bSRichard Henderson         return false;
41890880d20bSRichard Henderson     }
41900880d20bSRichard Henderson     da = resolve_asi(dc, a->asi, mop);
41910880d20bSRichard Henderson 
41920880d20bSRichard Henderson     reg = gen_dest_gpr(dc, a->rd);
419342071fc1SRichard Henderson     gen_ld_asi(dc, &da, reg, addr);
41940880d20bSRichard Henderson     gen_store_gpr(dc, a->rd, reg);
41950880d20bSRichard Henderson     return advance_pc(dc);
41960880d20bSRichard Henderson }
41970880d20bSRichard Henderson 
41980880d20bSRichard Henderson TRANS(LDUW, ALL, do_ld_gpr, a, MO_TEUL)
41990880d20bSRichard Henderson TRANS(LDUB, ALL, do_ld_gpr, a, MO_UB)
42000880d20bSRichard Henderson TRANS(LDUH, ALL, do_ld_gpr, a, MO_TEUW)
42010880d20bSRichard Henderson TRANS(LDSB, ALL, do_ld_gpr, a, MO_SB)
42020880d20bSRichard Henderson TRANS(LDSH, ALL, do_ld_gpr, a, MO_TESW)
42030880d20bSRichard Henderson TRANS(LDSW, 64, do_ld_gpr, a, MO_TESL)
42040880d20bSRichard Henderson TRANS(LDX, 64, do_ld_gpr, a, MO_TEUQ)
42050880d20bSRichard Henderson 
42060880d20bSRichard Henderson static bool do_st_gpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp mop)
42070880d20bSRichard Henderson {
42080880d20bSRichard Henderson     TCGv reg, addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
42090880d20bSRichard Henderson     DisasASI da;
42100880d20bSRichard Henderson 
42110880d20bSRichard Henderson     if (addr == NULL) {
42120880d20bSRichard Henderson         return false;
42130880d20bSRichard Henderson     }
42140880d20bSRichard Henderson     da = resolve_asi(dc, a->asi, mop);
42150880d20bSRichard Henderson 
42160880d20bSRichard Henderson     reg = gen_load_gpr(dc, a->rd);
421742071fc1SRichard Henderson     gen_st_asi(dc, &da, reg, addr);
42180880d20bSRichard Henderson     return advance_pc(dc);
42190880d20bSRichard Henderson }
42200880d20bSRichard Henderson 
42210880d20bSRichard Henderson TRANS(STW, ALL, do_st_gpr, a, MO_TEUL)
42220880d20bSRichard Henderson TRANS(STB, ALL, do_st_gpr, a, MO_UB)
42230880d20bSRichard Henderson TRANS(STH, ALL, do_st_gpr, a, MO_TEUW)
42240880d20bSRichard Henderson TRANS(STX, 64, do_st_gpr, a, MO_TEUQ)
42250880d20bSRichard Henderson 
42260880d20bSRichard Henderson static bool trans_LDD(DisasContext *dc, arg_r_r_ri_asi *a)
42270880d20bSRichard Henderson {
42280880d20bSRichard Henderson     TCGv addr;
42290880d20bSRichard Henderson     DisasASI da;
42300880d20bSRichard Henderson 
42310880d20bSRichard Henderson     if (a->rd & 1) {
42320880d20bSRichard Henderson         return false;
42330880d20bSRichard Henderson     }
42340880d20bSRichard Henderson     addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
42350880d20bSRichard Henderson     if (addr == NULL) {
42360880d20bSRichard Henderson         return false;
42370880d20bSRichard Henderson     }
42380880d20bSRichard Henderson     da = resolve_asi(dc, a->asi, MO_TEUQ);
423942071fc1SRichard Henderson     gen_ldda_asi(dc, &da, addr, a->rd);
42400880d20bSRichard Henderson     return advance_pc(dc);
42410880d20bSRichard Henderson }
42420880d20bSRichard Henderson 
42430880d20bSRichard Henderson static bool trans_STD(DisasContext *dc, arg_r_r_ri_asi *a)
42440880d20bSRichard Henderson {
42450880d20bSRichard Henderson     TCGv addr;
42460880d20bSRichard Henderson     DisasASI da;
42470880d20bSRichard Henderson 
42480880d20bSRichard Henderson     if (a->rd & 1) {
42490880d20bSRichard Henderson         return false;
42500880d20bSRichard Henderson     }
42510880d20bSRichard Henderson     addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
42520880d20bSRichard Henderson     if (addr == NULL) {
42530880d20bSRichard Henderson         return false;
42540880d20bSRichard Henderson     }
42550880d20bSRichard Henderson     da = resolve_asi(dc, a->asi, MO_TEUQ);
425642071fc1SRichard Henderson     gen_stda_asi(dc, &da, addr, a->rd);
42570880d20bSRichard Henderson     return advance_pc(dc);
42580880d20bSRichard Henderson }
42590880d20bSRichard Henderson 
4260cf07cd1eSRichard Henderson static bool trans_LDSTUB(DisasContext *dc, arg_r_r_ri_asi *a)
4261cf07cd1eSRichard Henderson {
4262cf07cd1eSRichard Henderson     TCGv addr, reg;
4263cf07cd1eSRichard Henderson     DisasASI da;
4264cf07cd1eSRichard Henderson 
4265cf07cd1eSRichard Henderson     addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
4266cf07cd1eSRichard Henderson     if (addr == NULL) {
4267cf07cd1eSRichard Henderson         return false;
4268cf07cd1eSRichard Henderson     }
4269cf07cd1eSRichard Henderson     da = resolve_asi(dc, a->asi, MO_UB);
4270cf07cd1eSRichard Henderson 
4271cf07cd1eSRichard Henderson     reg = gen_dest_gpr(dc, a->rd);
4272cf07cd1eSRichard Henderson     gen_ldstub_asi(dc, &da, reg, addr);
4273cf07cd1eSRichard Henderson     gen_store_gpr(dc, a->rd, reg);
4274cf07cd1eSRichard Henderson     return advance_pc(dc);
4275cf07cd1eSRichard Henderson }
4276cf07cd1eSRichard Henderson 
4277dca544b9SRichard Henderson static bool trans_SWAP(DisasContext *dc, arg_r_r_ri_asi *a)
4278dca544b9SRichard Henderson {
4279dca544b9SRichard Henderson     TCGv addr, dst, src;
4280dca544b9SRichard Henderson     DisasASI da;
4281dca544b9SRichard Henderson 
4282dca544b9SRichard Henderson     addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
4283dca544b9SRichard Henderson     if (addr == NULL) {
4284dca544b9SRichard Henderson         return false;
4285dca544b9SRichard Henderson     }
4286dca544b9SRichard Henderson     da = resolve_asi(dc, a->asi, MO_TEUL);
4287dca544b9SRichard Henderson 
4288dca544b9SRichard Henderson     dst = gen_dest_gpr(dc, a->rd);
4289dca544b9SRichard Henderson     src = gen_load_gpr(dc, a->rd);
4290dca544b9SRichard Henderson     gen_swap_asi(dc, &da, dst, src, addr);
4291dca544b9SRichard Henderson     gen_store_gpr(dc, a->rd, dst);
4292dca544b9SRichard Henderson     return advance_pc(dc);
4293dca544b9SRichard Henderson }
4294dca544b9SRichard Henderson 
4295d0a11d25SRichard Henderson static bool do_casa(DisasContext *dc, arg_r_r_ri_asi *a, MemOp mop)
4296d0a11d25SRichard Henderson {
4297d0a11d25SRichard Henderson     TCGv addr, o, n, c;
4298d0a11d25SRichard Henderson     DisasASI da;
4299d0a11d25SRichard Henderson 
4300d0a11d25SRichard Henderson     addr = gen_ldst_addr(dc, a->rs1, true, 0);
4301d0a11d25SRichard Henderson     if (addr == NULL) {
4302d0a11d25SRichard Henderson         return false;
4303d0a11d25SRichard Henderson     }
4304d0a11d25SRichard Henderson     da = resolve_asi(dc, a->asi, mop);
4305d0a11d25SRichard Henderson 
4306d0a11d25SRichard Henderson     o = gen_dest_gpr(dc, a->rd);
4307d0a11d25SRichard Henderson     n = gen_load_gpr(dc, a->rd);
4308d0a11d25SRichard Henderson     c = gen_load_gpr(dc, a->rs2_or_imm);
4309d0a11d25SRichard Henderson     gen_cas_asi(dc, &da, o, n, c, addr);
4310d0a11d25SRichard Henderson     gen_store_gpr(dc, a->rd, o);
4311d0a11d25SRichard Henderson     return advance_pc(dc);
4312d0a11d25SRichard Henderson }
4313d0a11d25SRichard Henderson 
4314d0a11d25SRichard Henderson TRANS(CASA, CASA, do_casa, a, MO_TEUL)
4315d0a11d25SRichard Henderson TRANS(CASXA, 64, do_casa, a, MO_TEUQ)
4316d0a11d25SRichard Henderson 
431706c060d9SRichard Henderson static bool do_ld_fpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp sz)
431806c060d9SRichard Henderson {
431906c060d9SRichard Henderson     TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
432006c060d9SRichard Henderson     DisasASI da;
432106c060d9SRichard Henderson 
432206c060d9SRichard Henderson     if (addr == NULL) {
432306c060d9SRichard Henderson         return false;
432406c060d9SRichard Henderson     }
432506c060d9SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
432606c060d9SRichard Henderson         return true;
432706c060d9SRichard Henderson     }
432806c060d9SRichard Henderson     if (sz == MO_128 && gen_trap_float128(dc)) {
432906c060d9SRichard Henderson         return true;
433006c060d9SRichard Henderson     }
433106c060d9SRichard Henderson     da = resolve_asi(dc, a->asi, MO_TE | sz);
4332287b1152SRichard Henderson     gen_ldf_asi(dc, &da, sz, addr, a->rd);
433306c060d9SRichard Henderson     gen_update_fprs_dirty(dc, a->rd);
433406c060d9SRichard Henderson     return advance_pc(dc);
433506c060d9SRichard Henderson }
433606c060d9SRichard Henderson 
433706c060d9SRichard Henderson TRANS(LDF, ALL, do_ld_fpr, a, MO_32)
433806c060d9SRichard Henderson TRANS(LDDF, ALL, do_ld_fpr, a, MO_64)
433906c060d9SRichard Henderson TRANS(LDQF, ALL, do_ld_fpr, a, MO_128)
434006c060d9SRichard Henderson 
4341287b1152SRichard Henderson TRANS(LDFA, 64, do_ld_fpr, a, MO_32)
4342287b1152SRichard Henderson TRANS(LDDFA, 64, do_ld_fpr, a, MO_64)
4343287b1152SRichard Henderson TRANS(LDQFA, 64, do_ld_fpr, a, MO_128)
4344287b1152SRichard Henderson 
434506c060d9SRichard Henderson static bool do_st_fpr(DisasContext *dc, arg_r_r_ri_asi *a, MemOp sz)
434606c060d9SRichard Henderson {
434706c060d9SRichard Henderson     TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
434806c060d9SRichard Henderson     DisasASI da;
434906c060d9SRichard Henderson 
435006c060d9SRichard Henderson     if (addr == NULL) {
435106c060d9SRichard Henderson         return false;
435206c060d9SRichard Henderson     }
435306c060d9SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
435406c060d9SRichard Henderson         return true;
435506c060d9SRichard Henderson     }
435606c060d9SRichard Henderson     if (sz == MO_128 && gen_trap_float128(dc)) {
435706c060d9SRichard Henderson         return true;
435806c060d9SRichard Henderson     }
435906c060d9SRichard Henderson     da = resolve_asi(dc, a->asi, MO_TE | sz);
4360287b1152SRichard Henderson     gen_stf_asi(dc, &da, sz, addr, a->rd);
436106c060d9SRichard Henderson     return advance_pc(dc);
436206c060d9SRichard Henderson }
436306c060d9SRichard Henderson 
436406c060d9SRichard Henderson TRANS(STF, ALL, do_st_fpr, a, MO_32)
436506c060d9SRichard Henderson TRANS(STDF, ALL, do_st_fpr, a, MO_64)
436606c060d9SRichard Henderson TRANS(STQF, ALL, do_st_fpr, a, MO_128)
436706c060d9SRichard Henderson 
4368287b1152SRichard Henderson TRANS(STFA, 64, do_st_fpr, a, MO_32)
4369287b1152SRichard Henderson TRANS(STDFA, 64, do_st_fpr, a, MO_64)
4370287b1152SRichard Henderson TRANS(STQFA, 64, do_st_fpr, a, MO_128)
4371287b1152SRichard Henderson 
437206c060d9SRichard Henderson static bool trans_STDFQ(DisasContext *dc, arg_STDFQ *a)
437306c060d9SRichard Henderson {
437406c060d9SRichard Henderson     if (!avail_32(dc)) {
437506c060d9SRichard Henderson         return false;
437606c060d9SRichard Henderson     }
437706c060d9SRichard Henderson     if (!supervisor(dc)) {
437806c060d9SRichard Henderson         return raise_priv(dc);
437906c060d9SRichard Henderson     }
438006c060d9SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
438106c060d9SRichard Henderson         return true;
438206c060d9SRichard Henderson     }
438306c060d9SRichard Henderson     gen_op_fpexception_im(dc, FSR_FTT_SEQ_ERROR);
438406c060d9SRichard Henderson     return true;
438506c060d9SRichard Henderson }
438606c060d9SRichard Henderson 
4387da681406SRichard Henderson static bool do_ldfsr(DisasContext *dc, arg_r_r_ri *a, MemOp mop,
4388da681406SRichard Henderson                      target_ulong new_mask, target_ulong old_mask)
43893d3c0673SRichard Henderson {
4390da681406SRichard Henderson     TCGv tmp, addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
43913d3c0673SRichard Henderson     if (addr == NULL) {
43923d3c0673SRichard Henderson         return false;
43933d3c0673SRichard Henderson     }
43943d3c0673SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
43953d3c0673SRichard Henderson         return true;
43963d3c0673SRichard Henderson     }
4397da681406SRichard Henderson     tmp = tcg_temp_new();
4398da681406SRichard Henderson     tcg_gen_qemu_ld_tl(tmp, addr, dc->mem_idx, mop | MO_ALIGN);
4399da681406SRichard Henderson     tcg_gen_andi_tl(tmp, tmp, new_mask);
4400da681406SRichard Henderson     tcg_gen_andi_tl(cpu_fsr, cpu_fsr, old_mask);
4401da681406SRichard Henderson     tcg_gen_or_tl(cpu_fsr, cpu_fsr, tmp);
4402da681406SRichard Henderson     gen_helper_set_fsr(tcg_env, cpu_fsr);
44033d3c0673SRichard Henderson     return advance_pc(dc);
44043d3c0673SRichard Henderson }
44053d3c0673SRichard Henderson 
4406da681406SRichard Henderson TRANS(LDFSR, ALL, do_ldfsr, a, MO_TEUL, FSR_LDFSR_MASK, FSR_LDFSR_OLDMASK)
4407da681406SRichard Henderson TRANS(LDXFSR, 64, do_ldfsr, a, MO_TEUQ, FSR_LDXFSR_MASK, FSR_LDXFSR_OLDMASK)
44083d3c0673SRichard Henderson 
44093d3c0673SRichard Henderson static bool do_stfsr(DisasContext *dc, arg_r_r_ri *a, MemOp mop)
44103d3c0673SRichard Henderson {
44113d3c0673SRichard Henderson     TCGv addr = gen_ldst_addr(dc, a->rs1, a->imm, a->rs2_or_imm);
44123d3c0673SRichard Henderson     if (addr == NULL) {
44133d3c0673SRichard Henderson         return false;
44143d3c0673SRichard Henderson     }
44153d3c0673SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
44163d3c0673SRichard Henderson         return true;
44173d3c0673SRichard Henderson     }
44183d3c0673SRichard Henderson     tcg_gen_qemu_st_tl(cpu_fsr, addr, dc->mem_idx, mop | MO_ALIGN);
44193d3c0673SRichard Henderson     return advance_pc(dc);
44203d3c0673SRichard Henderson }
44213d3c0673SRichard Henderson 
44223d3c0673SRichard Henderson TRANS(STFSR, ALL, do_stfsr, a, MO_TEUL)
44233d3c0673SRichard Henderson TRANS(STXFSR, 64, do_stfsr, a, MO_TEUQ)
44243d3c0673SRichard Henderson 
44253a38260eSRichard Henderson static bool do_fc(DisasContext *dc, int rd, bool c)
44263a38260eSRichard Henderson {
44273a38260eSRichard Henderson     uint64_t mask;
44283a38260eSRichard Henderson 
44293a38260eSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
44303a38260eSRichard Henderson         return true;
44313a38260eSRichard Henderson     }
44323a38260eSRichard Henderson 
44333a38260eSRichard Henderson     if (rd & 1) {
44343a38260eSRichard Henderson         mask = MAKE_64BIT_MASK(0, 32);
44353a38260eSRichard Henderson     } else {
44363a38260eSRichard Henderson         mask = MAKE_64BIT_MASK(32, 32);
44373a38260eSRichard Henderson     }
44383a38260eSRichard Henderson     if (c) {
44393a38260eSRichard Henderson         tcg_gen_ori_i64(cpu_fpr[rd / 2], cpu_fpr[rd / 2], mask);
44403a38260eSRichard Henderson     } else {
44413a38260eSRichard Henderson         tcg_gen_andi_i64(cpu_fpr[rd / 2], cpu_fpr[rd / 2], ~mask);
44423a38260eSRichard Henderson     }
44433a38260eSRichard Henderson     gen_update_fprs_dirty(dc, rd);
44443a38260eSRichard Henderson     return advance_pc(dc);
44453a38260eSRichard Henderson }
44463a38260eSRichard Henderson 
44473a38260eSRichard Henderson TRANS(FZEROs, VIS1, do_fc, a->rd, 0)
44483a38260eSRichard Henderson TRANS(FONEs, VIS1, do_fc, a->rd, 1)
44493a38260eSRichard Henderson 
44503a38260eSRichard Henderson static bool do_dc(DisasContext *dc, int rd, int64_t c)
44513a38260eSRichard Henderson {
44523a38260eSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
44533a38260eSRichard Henderson         return true;
44543a38260eSRichard Henderson     }
44553a38260eSRichard Henderson 
44563a38260eSRichard Henderson     tcg_gen_movi_i64(cpu_fpr[rd / 2], c);
44573a38260eSRichard Henderson     gen_update_fprs_dirty(dc, rd);
44583a38260eSRichard Henderson     return advance_pc(dc);
44593a38260eSRichard Henderson }
44603a38260eSRichard Henderson 
44613a38260eSRichard Henderson TRANS(FZEROd, VIS1, do_dc, a->rd, 0)
44623a38260eSRichard Henderson TRANS(FONEd, VIS1, do_dc, a->rd, -1)
44633a38260eSRichard Henderson 
4464baf3dbf2SRichard Henderson static bool do_ff(DisasContext *dc, arg_r_r *a,
4465baf3dbf2SRichard Henderson                   void (*func)(TCGv_i32, TCGv_i32))
4466baf3dbf2SRichard Henderson {
4467baf3dbf2SRichard Henderson     TCGv_i32 tmp;
4468baf3dbf2SRichard Henderson 
4469baf3dbf2SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4470baf3dbf2SRichard Henderson         return true;
4471baf3dbf2SRichard Henderson     }
4472baf3dbf2SRichard Henderson 
4473baf3dbf2SRichard Henderson     tmp = gen_load_fpr_F(dc, a->rs);
4474baf3dbf2SRichard Henderson     func(tmp, tmp);
4475baf3dbf2SRichard Henderson     gen_store_fpr_F(dc, a->rd, tmp);
4476baf3dbf2SRichard Henderson     return advance_pc(dc);
4477baf3dbf2SRichard Henderson }
4478baf3dbf2SRichard Henderson 
4479baf3dbf2SRichard Henderson TRANS(FMOVs, ALL, do_ff, a, gen_op_fmovs)
4480baf3dbf2SRichard Henderson TRANS(FNEGs, ALL, do_ff, a, gen_op_fnegs)
4481baf3dbf2SRichard Henderson TRANS(FABSs, ALL, do_ff, a, gen_op_fabss)
4482baf3dbf2SRichard Henderson TRANS(FSRCs, VIS1, do_ff, a, tcg_gen_mov_i32)
4483baf3dbf2SRichard Henderson TRANS(FNOTs, VIS1, do_ff, a, tcg_gen_not_i32)
4484baf3dbf2SRichard Henderson 
44852f722641SRichard Henderson static bool do_fd(DisasContext *dc, arg_r_r *a,
44862f722641SRichard Henderson                   void (*func)(TCGv_i32, TCGv_i64))
44872f722641SRichard Henderson {
44882f722641SRichard Henderson     TCGv_i32 dst;
44892f722641SRichard Henderson     TCGv_i64 src;
44902f722641SRichard Henderson 
44912f722641SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
44922f722641SRichard Henderson         return true;
44932f722641SRichard Henderson     }
44942f722641SRichard Henderson 
4495*388a6465SRichard Henderson     dst = tcg_temp_new_i32();
44962f722641SRichard Henderson     src = gen_load_fpr_D(dc, a->rs);
44972f722641SRichard Henderson     func(dst, src);
44982f722641SRichard Henderson     gen_store_fpr_F(dc, a->rd, dst);
44992f722641SRichard Henderson     return advance_pc(dc);
45002f722641SRichard Henderson }
45012f722641SRichard Henderson 
45022f722641SRichard Henderson TRANS(FPACK16, VIS1, do_fd, a, gen_op_fpack16)
45032f722641SRichard Henderson TRANS(FPACKFIX, VIS1, do_fd, a, gen_op_fpackfix)
45042f722641SRichard Henderson 
4505119cb94fSRichard Henderson static bool do_env_ff(DisasContext *dc, arg_r_r *a,
4506119cb94fSRichard Henderson                       void (*func)(TCGv_i32, TCGv_env, TCGv_i32))
4507119cb94fSRichard Henderson {
4508119cb94fSRichard Henderson     TCGv_i32 tmp;
4509119cb94fSRichard Henderson 
4510119cb94fSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4511119cb94fSRichard Henderson         return true;
4512119cb94fSRichard Henderson     }
4513119cb94fSRichard Henderson 
4514119cb94fSRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
4515119cb94fSRichard Henderson     tmp = gen_load_fpr_F(dc, a->rs);
4516119cb94fSRichard Henderson     func(tmp, tcg_env, tmp);
4517119cb94fSRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
4518119cb94fSRichard Henderson     gen_store_fpr_F(dc, a->rd, tmp);
4519119cb94fSRichard Henderson     return advance_pc(dc);
4520119cb94fSRichard Henderson }
4521119cb94fSRichard Henderson 
4522119cb94fSRichard Henderson TRANS(FSQRTs, ALL, do_env_ff, a, gen_helper_fsqrts)
4523119cb94fSRichard Henderson TRANS(FiTOs, ALL, do_env_ff, a, gen_helper_fitos)
4524119cb94fSRichard Henderson TRANS(FsTOi, ALL, do_env_ff, a, gen_helper_fstoi)
4525119cb94fSRichard Henderson 
45268c94bcd8SRichard Henderson static bool do_env_fd(DisasContext *dc, arg_r_r *a,
45278c94bcd8SRichard Henderson                       void (*func)(TCGv_i32, TCGv_env, TCGv_i64))
45288c94bcd8SRichard Henderson {
45298c94bcd8SRichard Henderson     TCGv_i32 dst;
45308c94bcd8SRichard Henderson     TCGv_i64 src;
45318c94bcd8SRichard Henderson 
45328c94bcd8SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
45338c94bcd8SRichard Henderson         return true;
45348c94bcd8SRichard Henderson     }
45358c94bcd8SRichard Henderson 
45368c94bcd8SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
4537*388a6465SRichard Henderson     dst = tcg_temp_new_i32();
45388c94bcd8SRichard Henderson     src = gen_load_fpr_D(dc, a->rs);
45398c94bcd8SRichard Henderson     func(dst, tcg_env, src);
45408c94bcd8SRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
45418c94bcd8SRichard Henderson     gen_store_fpr_F(dc, a->rd, dst);
45428c94bcd8SRichard Henderson     return advance_pc(dc);
45438c94bcd8SRichard Henderson }
45448c94bcd8SRichard Henderson 
45458c94bcd8SRichard Henderson TRANS(FdTOs, ALL, do_env_fd, a, gen_helper_fdtos)
45468c94bcd8SRichard Henderson TRANS(FdTOi, ALL, do_env_fd, a, gen_helper_fdtoi)
45478c94bcd8SRichard Henderson TRANS(FxTOs, 64, do_env_fd, a, gen_helper_fxtos)
45488c94bcd8SRichard Henderson 
4549c6d83e4fSRichard Henderson static bool do_dd(DisasContext *dc, arg_r_r *a,
4550c6d83e4fSRichard Henderson                   void (*func)(TCGv_i64, TCGv_i64))
4551c6d83e4fSRichard Henderson {
4552c6d83e4fSRichard Henderson     TCGv_i64 dst, src;
4553c6d83e4fSRichard Henderson 
4554c6d83e4fSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4555c6d83e4fSRichard Henderson         return true;
4556c6d83e4fSRichard Henderson     }
4557c6d83e4fSRichard Henderson 
4558c6d83e4fSRichard Henderson     dst = gen_dest_fpr_D(dc, a->rd);
4559c6d83e4fSRichard Henderson     src = gen_load_fpr_D(dc, a->rs);
4560c6d83e4fSRichard Henderson     func(dst, src);
4561c6d83e4fSRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
4562c6d83e4fSRichard Henderson     return advance_pc(dc);
4563c6d83e4fSRichard Henderson }
4564c6d83e4fSRichard Henderson 
4565c6d83e4fSRichard Henderson TRANS(FMOVd, 64, do_dd, a, gen_op_fmovd)
4566c6d83e4fSRichard Henderson TRANS(FNEGd, 64, do_dd, a, gen_op_fnegd)
4567c6d83e4fSRichard Henderson TRANS(FABSd, 64, do_dd, a, gen_op_fabsd)
4568c6d83e4fSRichard Henderson TRANS(FSRCd, VIS1, do_dd, a, tcg_gen_mov_i64)
4569c6d83e4fSRichard Henderson TRANS(FNOTd, VIS1, do_dd, a, tcg_gen_not_i64)
4570c6d83e4fSRichard Henderson 
45718aa418b3SRichard Henderson static bool do_env_dd(DisasContext *dc, arg_r_r *a,
45728aa418b3SRichard Henderson                       void (*func)(TCGv_i64, TCGv_env, TCGv_i64))
45738aa418b3SRichard Henderson {
45748aa418b3SRichard Henderson     TCGv_i64 dst, src;
45758aa418b3SRichard Henderson 
45768aa418b3SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
45778aa418b3SRichard Henderson         return true;
45788aa418b3SRichard Henderson     }
45798aa418b3SRichard Henderson 
45808aa418b3SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
45818aa418b3SRichard Henderson     dst = gen_dest_fpr_D(dc, a->rd);
45828aa418b3SRichard Henderson     src = gen_load_fpr_D(dc, a->rs);
45838aa418b3SRichard Henderson     func(dst, tcg_env, src);
45848aa418b3SRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
45858aa418b3SRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
45868aa418b3SRichard Henderson     return advance_pc(dc);
45878aa418b3SRichard Henderson }
45888aa418b3SRichard Henderson 
45898aa418b3SRichard Henderson TRANS(FSQRTd, ALL, do_env_dd, a, gen_helper_fsqrtd)
45908aa418b3SRichard Henderson TRANS(FxTOd, 64, do_env_dd, a, gen_helper_fxtod)
45918aa418b3SRichard Henderson TRANS(FdTOx, 64, do_env_dd, a, gen_helper_fdtox)
45928aa418b3SRichard Henderson 
4593199d43efSRichard Henderson static bool do_env_df(DisasContext *dc, arg_r_r *a,
4594199d43efSRichard Henderson                       void (*func)(TCGv_i64, TCGv_env, TCGv_i32))
4595199d43efSRichard Henderson {
4596199d43efSRichard Henderson     TCGv_i64 dst;
4597199d43efSRichard Henderson     TCGv_i32 src;
4598199d43efSRichard Henderson 
4599199d43efSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4600199d43efSRichard Henderson         return true;
4601199d43efSRichard Henderson     }
4602199d43efSRichard Henderson 
4603199d43efSRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
4604199d43efSRichard Henderson     dst = gen_dest_fpr_D(dc, a->rd);
4605199d43efSRichard Henderson     src = gen_load_fpr_F(dc, a->rs);
4606199d43efSRichard Henderson     func(dst, tcg_env, src);
4607199d43efSRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
4608199d43efSRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
4609199d43efSRichard Henderson     return advance_pc(dc);
4610199d43efSRichard Henderson }
4611199d43efSRichard Henderson 
4612199d43efSRichard Henderson TRANS(FiTOd, ALL, do_env_df, a, gen_helper_fitod)
4613199d43efSRichard Henderson TRANS(FsTOd, ALL, do_env_df, a, gen_helper_fstod)
4614199d43efSRichard Henderson TRANS(FsTOx, 64, do_env_df, a, gen_helper_fstox)
4615199d43efSRichard Henderson 
4616f4e18df5SRichard Henderson static bool trans_FMOVq(DisasContext *dc, arg_FMOVq *a)
4617f4e18df5SRichard Henderson {
4618f4e18df5SRichard Henderson     int rd, rs;
4619f4e18df5SRichard Henderson 
4620f4e18df5SRichard Henderson     if (!avail_64(dc)) {
4621f4e18df5SRichard Henderson         return false;
4622f4e18df5SRichard Henderson     }
4623f4e18df5SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4624f4e18df5SRichard Henderson         return true;
4625f4e18df5SRichard Henderson     }
4626f4e18df5SRichard Henderson     if (gen_trap_float128(dc)) {
4627f4e18df5SRichard Henderson         return true;
4628f4e18df5SRichard Henderson     }
4629f4e18df5SRichard Henderson 
4630f4e18df5SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
4631f4e18df5SRichard Henderson     rd = QFPREG(a->rd);
4632f4e18df5SRichard Henderson     rs = QFPREG(a->rs);
4633f4e18df5SRichard Henderson     tcg_gen_mov_i64(cpu_fpr[rd / 2], cpu_fpr[rs / 2]);
4634f4e18df5SRichard Henderson     tcg_gen_mov_i64(cpu_fpr[rd / 2 + 1], cpu_fpr[rs / 2 + 1]);
4635f4e18df5SRichard Henderson     gen_update_fprs_dirty(dc, rd);
4636f4e18df5SRichard Henderson     return advance_pc(dc);
4637f4e18df5SRichard Henderson }
4638f4e18df5SRichard Henderson 
4639f4e18df5SRichard Henderson static bool do_qq(DisasContext *dc, arg_r_r *a,
4640f4e18df5SRichard Henderson                   void (*func)(TCGv_env))
4641f4e18df5SRichard Henderson {
4642f4e18df5SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4643f4e18df5SRichard Henderson         return true;
4644f4e18df5SRichard Henderson     }
4645f4e18df5SRichard Henderson     if (gen_trap_float128(dc)) {
4646f4e18df5SRichard Henderson         return true;
4647f4e18df5SRichard Henderson     }
4648f4e18df5SRichard Henderson 
4649f4e18df5SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
4650f4e18df5SRichard Henderson     gen_op_load_fpr_QT1(QFPREG(a->rs));
4651f4e18df5SRichard Henderson     func(tcg_env);
4652f4e18df5SRichard Henderson     gen_op_store_QT0_fpr(QFPREG(a->rd));
4653f4e18df5SRichard Henderson     gen_update_fprs_dirty(dc, QFPREG(a->rd));
4654f4e18df5SRichard Henderson     return advance_pc(dc);
4655f4e18df5SRichard Henderson }
4656f4e18df5SRichard Henderson 
4657f4e18df5SRichard Henderson TRANS(FNEGq, 64, do_qq, a, gen_helper_fnegq)
4658f4e18df5SRichard Henderson TRANS(FABSq, 64, do_qq, a, gen_helper_fabsq)
4659f4e18df5SRichard Henderson 
4660c995216bSRichard Henderson static bool do_env_qq(DisasContext *dc, arg_r_r *a,
4661c995216bSRichard Henderson                        void (*func)(TCGv_env))
4662c995216bSRichard Henderson {
4663c995216bSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4664c995216bSRichard Henderson         return true;
4665c995216bSRichard Henderson     }
4666c995216bSRichard Henderson     if (gen_trap_float128(dc)) {
4667c995216bSRichard Henderson         return true;
4668c995216bSRichard Henderson     }
4669c995216bSRichard Henderson 
4670c995216bSRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
4671c995216bSRichard Henderson     gen_op_load_fpr_QT1(QFPREG(a->rs));
4672c995216bSRichard Henderson     func(tcg_env);
4673c995216bSRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
4674c995216bSRichard Henderson     gen_op_store_QT0_fpr(QFPREG(a->rd));
4675c995216bSRichard Henderson     gen_update_fprs_dirty(dc, QFPREG(a->rd));
4676c995216bSRichard Henderson     return advance_pc(dc);
4677c995216bSRichard Henderson }
4678c995216bSRichard Henderson 
4679c995216bSRichard Henderson TRANS(FSQRTq, ALL, do_env_qq, a, gen_helper_fsqrtq)
4680c995216bSRichard Henderson 
4681bd9c5c42SRichard Henderson static bool do_env_fq(DisasContext *dc, arg_r_r *a,
4682bd9c5c42SRichard Henderson                       void (*func)(TCGv_i32, TCGv_env))
4683bd9c5c42SRichard Henderson {
4684bd9c5c42SRichard Henderson     TCGv_i32 dst;
4685bd9c5c42SRichard Henderson 
4686bd9c5c42SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4687bd9c5c42SRichard Henderson         return true;
4688bd9c5c42SRichard Henderson     }
4689bd9c5c42SRichard Henderson     if (gen_trap_float128(dc)) {
4690bd9c5c42SRichard Henderson         return true;
4691bd9c5c42SRichard Henderson     }
4692bd9c5c42SRichard Henderson 
4693bd9c5c42SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
4694bd9c5c42SRichard Henderson     gen_op_load_fpr_QT1(QFPREG(a->rs));
4695*388a6465SRichard Henderson     dst = tcg_temp_new_i32();
4696bd9c5c42SRichard Henderson     func(dst, tcg_env);
4697bd9c5c42SRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
4698bd9c5c42SRichard Henderson     gen_store_fpr_F(dc, a->rd, dst);
4699bd9c5c42SRichard Henderson     return advance_pc(dc);
4700bd9c5c42SRichard Henderson }
4701bd9c5c42SRichard Henderson 
4702bd9c5c42SRichard Henderson TRANS(FqTOs, ALL, do_env_fq, a, gen_helper_fqtos)
4703bd9c5c42SRichard Henderson TRANS(FqTOi, ALL, do_env_fq, a, gen_helper_fqtoi)
4704bd9c5c42SRichard Henderson 
47051617586fSRichard Henderson static bool do_env_dq(DisasContext *dc, arg_r_r *a,
47061617586fSRichard Henderson                       void (*func)(TCGv_i64, TCGv_env))
47071617586fSRichard Henderson {
47081617586fSRichard Henderson     TCGv_i64 dst;
47091617586fSRichard Henderson 
47101617586fSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
47111617586fSRichard Henderson         return true;
47121617586fSRichard Henderson     }
47131617586fSRichard Henderson     if (gen_trap_float128(dc)) {
47141617586fSRichard Henderson         return true;
47151617586fSRichard Henderson     }
47161617586fSRichard Henderson 
47171617586fSRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
47181617586fSRichard Henderson     gen_op_load_fpr_QT1(QFPREG(a->rs));
47191617586fSRichard Henderson     dst = gen_dest_fpr_D(dc, a->rd);
47201617586fSRichard Henderson     func(dst, tcg_env);
47211617586fSRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
47221617586fSRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
47231617586fSRichard Henderson     return advance_pc(dc);
47241617586fSRichard Henderson }
47251617586fSRichard Henderson 
47261617586fSRichard Henderson TRANS(FqTOd, ALL, do_env_dq, a, gen_helper_fqtod)
47271617586fSRichard Henderson TRANS(FqTOx, 64, do_env_dq, a, gen_helper_fqtox)
47281617586fSRichard Henderson 
472913ebcc77SRichard Henderson static bool do_env_qf(DisasContext *dc, arg_r_r *a,
473013ebcc77SRichard Henderson                       void (*func)(TCGv_env, TCGv_i32))
473113ebcc77SRichard Henderson {
473213ebcc77SRichard Henderson     TCGv_i32 src;
473313ebcc77SRichard Henderson 
473413ebcc77SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
473513ebcc77SRichard Henderson         return true;
473613ebcc77SRichard Henderson     }
473713ebcc77SRichard Henderson     if (gen_trap_float128(dc)) {
473813ebcc77SRichard Henderson         return true;
473913ebcc77SRichard Henderson     }
474013ebcc77SRichard Henderson 
474113ebcc77SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
474213ebcc77SRichard Henderson     src = gen_load_fpr_F(dc, a->rs);
474313ebcc77SRichard Henderson     func(tcg_env, src);
474413ebcc77SRichard Henderson     gen_op_store_QT0_fpr(QFPREG(a->rd));
474513ebcc77SRichard Henderson     gen_update_fprs_dirty(dc, QFPREG(a->rd));
474613ebcc77SRichard Henderson     return advance_pc(dc);
474713ebcc77SRichard Henderson }
474813ebcc77SRichard Henderson 
474913ebcc77SRichard Henderson TRANS(FiTOq, ALL, do_env_qf, a, gen_helper_fitoq)
475013ebcc77SRichard Henderson TRANS(FsTOq, ALL, do_env_qf, a, gen_helper_fstoq)
475113ebcc77SRichard Henderson 
47527b8e3e1aSRichard Henderson static bool do_env_qd(DisasContext *dc, arg_r_r *a,
47537b8e3e1aSRichard Henderson                       void (*func)(TCGv_env, TCGv_i64))
47547b8e3e1aSRichard Henderson {
47557b8e3e1aSRichard Henderson     TCGv_i64 src;
47567b8e3e1aSRichard Henderson 
47577b8e3e1aSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
47587b8e3e1aSRichard Henderson         return true;
47597b8e3e1aSRichard Henderson     }
47607b8e3e1aSRichard Henderson     if (gen_trap_float128(dc)) {
47617b8e3e1aSRichard Henderson         return true;
47627b8e3e1aSRichard Henderson     }
47637b8e3e1aSRichard Henderson 
47647b8e3e1aSRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
47657b8e3e1aSRichard Henderson     src = gen_load_fpr_D(dc, a->rs);
47667b8e3e1aSRichard Henderson     func(tcg_env, src);
47677b8e3e1aSRichard Henderson     gen_op_store_QT0_fpr(QFPREG(a->rd));
47687b8e3e1aSRichard Henderson     gen_update_fprs_dirty(dc, QFPREG(a->rd));
47697b8e3e1aSRichard Henderson     return advance_pc(dc);
47707b8e3e1aSRichard Henderson }
47717b8e3e1aSRichard Henderson 
47727b8e3e1aSRichard Henderson TRANS(FdTOq, ALL, do_env_qd, a, gen_helper_fdtoq)
47737b8e3e1aSRichard Henderson TRANS(FxTOq, 64, do_env_qd, a, gen_helper_fxtoq)
47747b8e3e1aSRichard Henderson 
47757f10b52fSRichard Henderson static bool do_fff(DisasContext *dc, arg_r_r_r *a,
47767f10b52fSRichard Henderson                    void (*func)(TCGv_i32, TCGv_i32, TCGv_i32))
47777f10b52fSRichard Henderson {
47787f10b52fSRichard Henderson     TCGv_i32 src1, src2;
47797f10b52fSRichard Henderson 
47807f10b52fSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
47817f10b52fSRichard Henderson         return true;
47827f10b52fSRichard Henderson     }
47837f10b52fSRichard Henderson 
47847f10b52fSRichard Henderson     src1 = gen_load_fpr_F(dc, a->rs1);
47857f10b52fSRichard Henderson     src2 = gen_load_fpr_F(dc, a->rs2);
47867f10b52fSRichard Henderson     func(src1, src1, src2);
47877f10b52fSRichard Henderson     gen_store_fpr_F(dc, a->rd, src1);
47887f10b52fSRichard Henderson     return advance_pc(dc);
47897f10b52fSRichard Henderson }
47907f10b52fSRichard Henderson 
47917f10b52fSRichard Henderson TRANS(FPADD16s, VIS1, do_fff, a, tcg_gen_vec_add16_i32)
47927f10b52fSRichard Henderson TRANS(FPADD32s, VIS1, do_fff, a, tcg_gen_add_i32)
47937f10b52fSRichard Henderson TRANS(FPSUB16s, VIS1, do_fff, a, tcg_gen_vec_sub16_i32)
47947f10b52fSRichard Henderson TRANS(FPSUB32s, VIS1, do_fff, a, tcg_gen_sub_i32)
47957f10b52fSRichard Henderson TRANS(FNORs, VIS1, do_fff, a, tcg_gen_nor_i32)
47967f10b52fSRichard Henderson TRANS(FANDNOTs, VIS1, do_fff, a, tcg_gen_andc_i32)
47977f10b52fSRichard Henderson TRANS(FXORs, VIS1, do_fff, a, tcg_gen_xor_i32)
47987f10b52fSRichard Henderson TRANS(FNANDs, VIS1, do_fff, a, tcg_gen_nand_i32)
47997f10b52fSRichard Henderson TRANS(FANDs, VIS1, do_fff, a, tcg_gen_and_i32)
48007f10b52fSRichard Henderson TRANS(FXNORs, VIS1, do_fff, a, tcg_gen_eqv_i32)
48017f10b52fSRichard Henderson TRANS(FORNOTs, VIS1, do_fff, a, tcg_gen_orc_i32)
48027f10b52fSRichard Henderson TRANS(FORs, VIS1, do_fff, a, tcg_gen_or_i32)
48037f10b52fSRichard Henderson 
4804c1514961SRichard Henderson static bool do_env_fff(DisasContext *dc, arg_r_r_r *a,
4805c1514961SRichard Henderson                        void (*func)(TCGv_i32, TCGv_env, TCGv_i32, TCGv_i32))
4806c1514961SRichard Henderson {
4807c1514961SRichard Henderson     TCGv_i32 src1, src2;
4808c1514961SRichard Henderson 
4809c1514961SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4810c1514961SRichard Henderson         return true;
4811c1514961SRichard Henderson     }
4812c1514961SRichard Henderson 
4813c1514961SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
4814c1514961SRichard Henderson     src1 = gen_load_fpr_F(dc, a->rs1);
4815c1514961SRichard Henderson     src2 = gen_load_fpr_F(dc, a->rs2);
4816c1514961SRichard Henderson     func(src1, tcg_env, src1, src2);
4817c1514961SRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
4818c1514961SRichard Henderson     gen_store_fpr_F(dc, a->rd, src1);
4819c1514961SRichard Henderson     return advance_pc(dc);
4820c1514961SRichard Henderson }
4821c1514961SRichard Henderson 
4822c1514961SRichard Henderson TRANS(FADDs, ALL, do_env_fff, a, gen_helper_fadds)
4823c1514961SRichard Henderson TRANS(FSUBs, ALL, do_env_fff, a, gen_helper_fsubs)
4824c1514961SRichard Henderson TRANS(FMULs, ALL, do_env_fff, a, gen_helper_fmuls)
4825c1514961SRichard Henderson TRANS(FDIVs, ALL, do_env_fff, a, gen_helper_fdivs)
4826c1514961SRichard Henderson 
4827e06c9f83SRichard Henderson static bool do_ddd(DisasContext *dc, arg_r_r_r *a,
4828e06c9f83SRichard Henderson                    void (*func)(TCGv_i64, TCGv_i64, TCGv_i64))
4829e06c9f83SRichard Henderson {
4830e06c9f83SRichard Henderson     TCGv_i64 dst, src1, src2;
4831e06c9f83SRichard Henderson 
4832e06c9f83SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4833e06c9f83SRichard Henderson         return true;
4834e06c9f83SRichard Henderson     }
4835e06c9f83SRichard Henderson 
4836e06c9f83SRichard Henderson     dst = gen_dest_fpr_D(dc, a->rd);
4837e06c9f83SRichard Henderson     src1 = gen_load_fpr_D(dc, a->rs1);
4838e06c9f83SRichard Henderson     src2 = gen_load_fpr_D(dc, a->rs2);
4839e06c9f83SRichard Henderson     func(dst, src1, src2);
4840e06c9f83SRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
4841e06c9f83SRichard Henderson     return advance_pc(dc);
4842e06c9f83SRichard Henderson }
4843e06c9f83SRichard Henderson 
4844e06c9f83SRichard Henderson TRANS(FMUL8x16, VIS1, do_ddd, a, gen_helper_fmul8x16)
4845e06c9f83SRichard Henderson TRANS(FMUL8x16AU, VIS1, do_ddd, a, gen_helper_fmul8x16au)
4846e06c9f83SRichard Henderson TRANS(FMUL8x16AL, VIS1, do_ddd, a, gen_helper_fmul8x16al)
4847e06c9f83SRichard Henderson TRANS(FMUL8SUx16, VIS1, do_ddd, a, gen_helper_fmul8sux16)
4848e06c9f83SRichard Henderson TRANS(FMUL8ULx16, VIS1, do_ddd, a, gen_helper_fmul8ulx16)
4849e06c9f83SRichard Henderson TRANS(FMULD8SUx16, VIS1, do_ddd, a, gen_helper_fmuld8sux16)
4850e06c9f83SRichard Henderson TRANS(FMULD8ULx16, VIS1, do_ddd, a, gen_helper_fmuld8ulx16)
4851e06c9f83SRichard Henderson TRANS(FPMERGE, VIS1, do_ddd, a, gen_helper_fpmerge)
4852e06c9f83SRichard Henderson TRANS(FEXPAND, VIS1, do_ddd, a, gen_helper_fexpand)
4853e06c9f83SRichard Henderson 
4854e06c9f83SRichard Henderson TRANS(FPADD16, VIS1, do_ddd, a, tcg_gen_vec_add16_i64)
4855e06c9f83SRichard Henderson TRANS(FPADD32, VIS1, do_ddd, a, tcg_gen_vec_add32_i64)
4856e06c9f83SRichard Henderson TRANS(FPSUB16, VIS1, do_ddd, a, tcg_gen_vec_sub16_i64)
4857e06c9f83SRichard Henderson TRANS(FPSUB32, VIS1, do_ddd, a, tcg_gen_vec_sub32_i64)
4858e06c9f83SRichard Henderson TRANS(FNORd, VIS1, do_ddd, a, tcg_gen_nor_i64)
4859e06c9f83SRichard Henderson TRANS(FANDNOTd, VIS1, do_ddd, a, tcg_gen_andc_i64)
4860e06c9f83SRichard Henderson TRANS(FXORd, VIS1, do_ddd, a, tcg_gen_xor_i64)
4861e06c9f83SRichard Henderson TRANS(FNANDd, VIS1, do_ddd, a, tcg_gen_nand_i64)
4862e06c9f83SRichard Henderson TRANS(FANDd, VIS1, do_ddd, a, tcg_gen_and_i64)
4863e06c9f83SRichard Henderson TRANS(FXNORd, VIS1, do_ddd, a, tcg_gen_eqv_i64)
4864e06c9f83SRichard Henderson TRANS(FORNOTd, VIS1, do_ddd, a, tcg_gen_orc_i64)
4865e06c9f83SRichard Henderson TRANS(FORd, VIS1, do_ddd, a, tcg_gen_or_i64)
4866e06c9f83SRichard Henderson 
48674b6edc0aSRichard Henderson TRANS(FPACK32, VIS1, do_ddd, a, gen_op_fpack32)
48684b6edc0aSRichard Henderson TRANS(FALIGNDATAg, VIS1, do_ddd, a, gen_op_faligndata)
48694b6edc0aSRichard Henderson TRANS(BSHUFFLE, VIS2, do_ddd, a, gen_op_bshuffle)
48704b6edc0aSRichard Henderson 
4871e2fa6bd1SRichard Henderson static bool do_rdd(DisasContext *dc, arg_r_r_r *a,
4872e2fa6bd1SRichard Henderson                    void (*func)(TCGv, TCGv_i64, TCGv_i64))
4873e2fa6bd1SRichard Henderson {
4874e2fa6bd1SRichard Henderson     TCGv_i64 src1, src2;
4875e2fa6bd1SRichard Henderson     TCGv dst;
4876e2fa6bd1SRichard Henderson 
4877e2fa6bd1SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4878e2fa6bd1SRichard Henderson         return true;
4879e2fa6bd1SRichard Henderson     }
4880e2fa6bd1SRichard Henderson 
4881e2fa6bd1SRichard Henderson     dst = gen_dest_gpr(dc, a->rd);
4882e2fa6bd1SRichard Henderson     src1 = gen_load_fpr_D(dc, a->rs1);
4883e2fa6bd1SRichard Henderson     src2 = gen_load_fpr_D(dc, a->rs2);
4884e2fa6bd1SRichard Henderson     func(dst, src1, src2);
4885e2fa6bd1SRichard Henderson     gen_store_gpr(dc, a->rd, dst);
4886e2fa6bd1SRichard Henderson     return advance_pc(dc);
4887e2fa6bd1SRichard Henderson }
4888e2fa6bd1SRichard Henderson 
4889e2fa6bd1SRichard Henderson TRANS(FPCMPLE16, VIS1, do_rdd, a, gen_helper_fcmple16)
4890e2fa6bd1SRichard Henderson TRANS(FPCMPNE16, VIS1, do_rdd, a, gen_helper_fcmpne16)
4891e2fa6bd1SRichard Henderson TRANS(FPCMPGT16, VIS1, do_rdd, a, gen_helper_fcmpgt16)
4892e2fa6bd1SRichard Henderson TRANS(FPCMPEQ16, VIS1, do_rdd, a, gen_helper_fcmpeq16)
4893e2fa6bd1SRichard Henderson 
4894e2fa6bd1SRichard Henderson TRANS(FPCMPLE32, VIS1, do_rdd, a, gen_helper_fcmple32)
4895e2fa6bd1SRichard Henderson TRANS(FPCMPNE32, VIS1, do_rdd, a, gen_helper_fcmpne32)
4896e2fa6bd1SRichard Henderson TRANS(FPCMPGT32, VIS1, do_rdd, a, gen_helper_fcmpgt32)
4897e2fa6bd1SRichard Henderson TRANS(FPCMPEQ32, VIS1, do_rdd, a, gen_helper_fcmpeq32)
4898e2fa6bd1SRichard Henderson 
4899f2a59b0aSRichard Henderson static bool do_env_ddd(DisasContext *dc, arg_r_r_r *a,
4900f2a59b0aSRichard Henderson                        void (*func)(TCGv_i64, TCGv_env, TCGv_i64, TCGv_i64))
4901f2a59b0aSRichard Henderson {
4902f2a59b0aSRichard Henderson     TCGv_i64 dst, src1, src2;
4903f2a59b0aSRichard Henderson 
4904f2a59b0aSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4905f2a59b0aSRichard Henderson         return true;
4906f2a59b0aSRichard Henderson     }
4907f2a59b0aSRichard Henderson 
4908f2a59b0aSRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
4909f2a59b0aSRichard Henderson     dst = gen_dest_fpr_D(dc, a->rd);
4910f2a59b0aSRichard Henderson     src1 = gen_load_fpr_D(dc, a->rs1);
4911f2a59b0aSRichard Henderson     src2 = gen_load_fpr_D(dc, a->rs2);
4912f2a59b0aSRichard Henderson     func(dst, tcg_env, src1, src2);
4913f2a59b0aSRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
4914f2a59b0aSRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
4915f2a59b0aSRichard Henderson     return advance_pc(dc);
4916f2a59b0aSRichard Henderson }
4917f2a59b0aSRichard Henderson 
4918f2a59b0aSRichard Henderson TRANS(FADDd, ALL, do_env_ddd, a, gen_helper_faddd)
4919f2a59b0aSRichard Henderson TRANS(FSUBd, ALL, do_env_ddd, a, gen_helper_fsubd)
4920f2a59b0aSRichard Henderson TRANS(FMULd, ALL, do_env_ddd, a, gen_helper_fmuld)
4921f2a59b0aSRichard Henderson TRANS(FDIVd, ALL, do_env_ddd, a, gen_helper_fdivd)
4922f2a59b0aSRichard Henderson 
4923ff4c711bSRichard Henderson static bool trans_FsMULd(DisasContext *dc, arg_r_r_r *a)
4924ff4c711bSRichard Henderson {
4925ff4c711bSRichard Henderson     TCGv_i64 dst;
4926ff4c711bSRichard Henderson     TCGv_i32 src1, src2;
4927ff4c711bSRichard Henderson 
4928ff4c711bSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4929ff4c711bSRichard Henderson         return true;
4930ff4c711bSRichard Henderson     }
4931ff4c711bSRichard Henderson     if (!(dc->def->features & CPU_FEATURE_FSMULD)) {
4932ff4c711bSRichard Henderson         return raise_unimpfpop(dc);
4933ff4c711bSRichard Henderson     }
4934ff4c711bSRichard Henderson 
4935ff4c711bSRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
4936ff4c711bSRichard Henderson     dst = gen_dest_fpr_D(dc, a->rd);
4937ff4c711bSRichard Henderson     src1 = gen_load_fpr_F(dc, a->rs1);
4938ff4c711bSRichard Henderson     src2 = gen_load_fpr_F(dc, a->rs2);
4939ff4c711bSRichard Henderson     gen_helper_fsmuld(dst, tcg_env, src1, src2);
4940ff4c711bSRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
4941ff4c711bSRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
4942ff4c711bSRichard Henderson     return advance_pc(dc);
4943ff4c711bSRichard Henderson }
4944ff4c711bSRichard Henderson 
4945afb04344SRichard Henderson static bool do_dddd(DisasContext *dc, arg_r_r_r *a,
4946afb04344SRichard Henderson                     void (*func)(TCGv_i64, TCGv_i64, TCGv_i64, TCGv_i64))
4947afb04344SRichard Henderson {
4948afb04344SRichard Henderson     TCGv_i64 dst, src0, src1, src2;
4949afb04344SRichard Henderson 
4950afb04344SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4951afb04344SRichard Henderson         return true;
4952afb04344SRichard Henderson     }
4953afb04344SRichard Henderson 
4954afb04344SRichard Henderson     dst  = gen_dest_fpr_D(dc, a->rd);
4955afb04344SRichard Henderson     src0 = gen_load_fpr_D(dc, a->rd);
4956afb04344SRichard Henderson     src1 = gen_load_fpr_D(dc, a->rs1);
4957afb04344SRichard Henderson     src2 = gen_load_fpr_D(dc, a->rs2);
4958afb04344SRichard Henderson     func(dst, src0, src1, src2);
4959afb04344SRichard Henderson     gen_store_fpr_D(dc, a->rd, dst);
4960afb04344SRichard Henderson     return advance_pc(dc);
4961afb04344SRichard Henderson }
4962afb04344SRichard Henderson 
4963afb04344SRichard Henderson TRANS(PDIST, VIS1, do_dddd, a, gen_helper_pdist)
4964afb04344SRichard Henderson 
4965a4056239SRichard Henderson static bool do_env_qqq(DisasContext *dc, arg_r_r_r *a,
4966a4056239SRichard Henderson                        void (*func)(TCGv_env))
4967a4056239SRichard Henderson {
4968a4056239SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
4969a4056239SRichard Henderson         return true;
4970a4056239SRichard Henderson     }
4971a4056239SRichard Henderson     if (gen_trap_float128(dc)) {
4972a4056239SRichard Henderson         return true;
4973a4056239SRichard Henderson     }
4974a4056239SRichard Henderson 
4975a4056239SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
4976a4056239SRichard Henderson     gen_op_load_fpr_QT0(QFPREG(a->rs1));
4977a4056239SRichard Henderson     gen_op_load_fpr_QT1(QFPREG(a->rs2));
4978a4056239SRichard Henderson     func(tcg_env);
4979a4056239SRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
4980a4056239SRichard Henderson     gen_op_store_QT0_fpr(QFPREG(a->rd));
4981a4056239SRichard Henderson     gen_update_fprs_dirty(dc, QFPREG(a->rd));
4982a4056239SRichard Henderson     return advance_pc(dc);
4983a4056239SRichard Henderson }
4984a4056239SRichard Henderson 
4985a4056239SRichard Henderson TRANS(FADDq, ALL, do_env_qqq, a, gen_helper_faddq)
4986a4056239SRichard Henderson TRANS(FSUBq, ALL, do_env_qqq, a, gen_helper_fsubq)
4987a4056239SRichard Henderson TRANS(FMULq, ALL, do_env_qqq, a, gen_helper_fmulq)
4988a4056239SRichard Henderson TRANS(FDIVq, ALL, do_env_qqq, a, gen_helper_fdivq)
4989a4056239SRichard Henderson 
49905e3b17bbSRichard Henderson static bool trans_FdMULq(DisasContext *dc, arg_r_r_r *a)
49915e3b17bbSRichard Henderson {
49925e3b17bbSRichard Henderson     TCGv_i64 src1, src2;
49935e3b17bbSRichard Henderson 
49945e3b17bbSRichard Henderson     if (gen_trap_ifnofpu(dc)) {
49955e3b17bbSRichard Henderson         return true;
49965e3b17bbSRichard Henderson     }
49975e3b17bbSRichard Henderson     if (gen_trap_float128(dc)) {
49985e3b17bbSRichard Henderson         return true;
49995e3b17bbSRichard Henderson     }
50005e3b17bbSRichard Henderson 
50015e3b17bbSRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
50025e3b17bbSRichard Henderson     src1 = gen_load_fpr_D(dc, a->rs1);
50035e3b17bbSRichard Henderson     src2 = gen_load_fpr_D(dc, a->rs2);
50045e3b17bbSRichard Henderson     gen_helper_fdmulq(tcg_env, src1, src2);
50055e3b17bbSRichard Henderson     gen_helper_check_ieee_exceptions(cpu_fsr, tcg_env);
50065e3b17bbSRichard Henderson     gen_op_store_QT0_fpr(QFPREG(a->rd));
50075e3b17bbSRichard Henderson     gen_update_fprs_dirty(dc, QFPREG(a->rd));
50085e3b17bbSRichard Henderson     return advance_pc(dc);
50095e3b17bbSRichard Henderson }
50105e3b17bbSRichard Henderson 
5011f7ec8155SRichard Henderson static bool do_fmovr(DisasContext *dc, arg_FMOVRs *a, bool is_128,
5012f7ec8155SRichard Henderson                      void (*func)(DisasContext *, DisasCompare *, int, int))
5013f7ec8155SRichard Henderson {
5014f7ec8155SRichard Henderson     DisasCompare cmp;
5015f7ec8155SRichard Henderson 
50162c4f56c9SRichard Henderson     if (!gen_compare_reg(&cmp, a->cond, gen_load_gpr(dc, a->rs1))) {
50172c4f56c9SRichard Henderson         return false;
50182c4f56c9SRichard Henderson     }
5019f7ec8155SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
5020f7ec8155SRichard Henderson         return true;
5021f7ec8155SRichard Henderson     }
5022f7ec8155SRichard Henderson     if (is_128 && gen_trap_float128(dc)) {
5023f7ec8155SRichard Henderson         return true;
5024f7ec8155SRichard Henderson     }
5025f7ec8155SRichard Henderson 
5026f7ec8155SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
5027f7ec8155SRichard Henderson     func(dc, &cmp, a->rd, a->rs2);
5028f7ec8155SRichard Henderson     return advance_pc(dc);
5029f7ec8155SRichard Henderson }
5030f7ec8155SRichard Henderson 
5031f7ec8155SRichard Henderson TRANS(FMOVRs, 64, do_fmovr, a, false, gen_fmovs)
5032f7ec8155SRichard Henderson TRANS(FMOVRd, 64, do_fmovr, a, false, gen_fmovd)
5033f7ec8155SRichard Henderson TRANS(FMOVRq, 64, do_fmovr, a, true, gen_fmovq)
5034f7ec8155SRichard Henderson 
5035f7ec8155SRichard Henderson static bool do_fmovcc(DisasContext *dc, arg_FMOVscc *a, bool is_128,
5036f7ec8155SRichard Henderson                       void (*func)(DisasContext *, DisasCompare *, int, int))
5037f7ec8155SRichard Henderson {
5038f7ec8155SRichard Henderson     DisasCompare cmp;
5039f7ec8155SRichard Henderson 
5040f7ec8155SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
5041f7ec8155SRichard Henderson         return true;
5042f7ec8155SRichard Henderson     }
5043f7ec8155SRichard Henderson     if (is_128 && gen_trap_float128(dc)) {
5044f7ec8155SRichard Henderson         return true;
5045f7ec8155SRichard Henderson     }
5046f7ec8155SRichard Henderson 
5047f7ec8155SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
5048f7ec8155SRichard Henderson     gen_compare(&cmp, a->cc, a->cond, dc);
5049f7ec8155SRichard Henderson     func(dc, &cmp, a->rd, a->rs2);
5050f7ec8155SRichard Henderson     return advance_pc(dc);
5051f7ec8155SRichard Henderson }
5052f7ec8155SRichard Henderson 
5053f7ec8155SRichard Henderson TRANS(FMOVscc, 64, do_fmovcc, a, false, gen_fmovs)
5054f7ec8155SRichard Henderson TRANS(FMOVdcc, 64, do_fmovcc, a, false, gen_fmovd)
5055f7ec8155SRichard Henderson TRANS(FMOVqcc, 64, do_fmovcc, a, true, gen_fmovq)
5056f7ec8155SRichard Henderson 
5057f7ec8155SRichard Henderson static bool do_fmovfcc(DisasContext *dc, arg_FMOVsfcc *a, bool is_128,
5058f7ec8155SRichard Henderson                        void (*func)(DisasContext *, DisasCompare *, int, int))
5059f7ec8155SRichard Henderson {
5060f7ec8155SRichard Henderson     DisasCompare cmp;
5061f7ec8155SRichard Henderson 
5062f7ec8155SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
5063f7ec8155SRichard Henderson         return true;
5064f7ec8155SRichard Henderson     }
5065f7ec8155SRichard Henderson     if (is_128 && gen_trap_float128(dc)) {
5066f7ec8155SRichard Henderson         return true;
5067f7ec8155SRichard Henderson     }
5068f7ec8155SRichard Henderson 
5069f7ec8155SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
5070f7ec8155SRichard Henderson     gen_fcompare(&cmp, a->cc, a->cond);
5071f7ec8155SRichard Henderson     func(dc, &cmp, a->rd, a->rs2);
5072f7ec8155SRichard Henderson     return advance_pc(dc);
5073f7ec8155SRichard Henderson }
5074f7ec8155SRichard Henderson 
5075f7ec8155SRichard Henderson TRANS(FMOVsfcc, 64, do_fmovfcc, a, false, gen_fmovs)
5076f7ec8155SRichard Henderson TRANS(FMOVdfcc, 64, do_fmovfcc, a, false, gen_fmovd)
5077f7ec8155SRichard Henderson TRANS(FMOVqfcc, 64, do_fmovfcc, a, true, gen_fmovq)
5078f7ec8155SRichard Henderson 
507940f9ad21SRichard Henderson static bool do_fcmps(DisasContext *dc, arg_FCMPs *a, bool e)
508040f9ad21SRichard Henderson {
508140f9ad21SRichard Henderson     TCGv_i32 src1, src2;
508240f9ad21SRichard Henderson 
508340f9ad21SRichard Henderson     if (avail_32(dc) && a->cc != 0) {
508440f9ad21SRichard Henderson         return false;
508540f9ad21SRichard Henderson     }
508640f9ad21SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
508740f9ad21SRichard Henderson         return true;
508840f9ad21SRichard Henderson     }
508940f9ad21SRichard Henderson 
509040f9ad21SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
509140f9ad21SRichard Henderson     src1 = gen_load_fpr_F(dc, a->rs1);
509240f9ad21SRichard Henderson     src2 = gen_load_fpr_F(dc, a->rs2);
509340f9ad21SRichard Henderson     if (e) {
509440f9ad21SRichard Henderson         gen_op_fcmpes(a->cc, src1, src2);
509540f9ad21SRichard Henderson     } else {
509640f9ad21SRichard Henderson         gen_op_fcmps(a->cc, src1, src2);
509740f9ad21SRichard Henderson     }
509840f9ad21SRichard Henderson     return advance_pc(dc);
509940f9ad21SRichard Henderson }
510040f9ad21SRichard Henderson 
510140f9ad21SRichard Henderson TRANS(FCMPs, ALL, do_fcmps, a, false)
510240f9ad21SRichard Henderson TRANS(FCMPEs, ALL, do_fcmps, a, true)
510340f9ad21SRichard Henderson 
510440f9ad21SRichard Henderson static bool do_fcmpd(DisasContext *dc, arg_FCMPd *a, bool e)
510540f9ad21SRichard Henderson {
510640f9ad21SRichard Henderson     TCGv_i64 src1, src2;
510740f9ad21SRichard Henderson 
510840f9ad21SRichard Henderson     if (avail_32(dc) && a->cc != 0) {
510940f9ad21SRichard Henderson         return false;
511040f9ad21SRichard Henderson     }
511140f9ad21SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
511240f9ad21SRichard Henderson         return true;
511340f9ad21SRichard Henderson     }
511440f9ad21SRichard Henderson 
511540f9ad21SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
511640f9ad21SRichard Henderson     src1 = gen_load_fpr_D(dc, a->rs1);
511740f9ad21SRichard Henderson     src2 = gen_load_fpr_D(dc, a->rs2);
511840f9ad21SRichard Henderson     if (e) {
511940f9ad21SRichard Henderson         gen_op_fcmped(a->cc, src1, src2);
512040f9ad21SRichard Henderson     } else {
512140f9ad21SRichard Henderson         gen_op_fcmpd(a->cc, src1, src2);
512240f9ad21SRichard Henderson     }
512340f9ad21SRichard Henderson     return advance_pc(dc);
512440f9ad21SRichard Henderson }
512540f9ad21SRichard Henderson 
512640f9ad21SRichard Henderson TRANS(FCMPd, ALL, do_fcmpd, a, false)
512740f9ad21SRichard Henderson TRANS(FCMPEd, ALL, do_fcmpd, a, true)
512840f9ad21SRichard Henderson 
512940f9ad21SRichard Henderson static bool do_fcmpq(DisasContext *dc, arg_FCMPq *a, bool e)
513040f9ad21SRichard Henderson {
513140f9ad21SRichard Henderson     if (avail_32(dc) && a->cc != 0) {
513240f9ad21SRichard Henderson         return false;
513340f9ad21SRichard Henderson     }
513440f9ad21SRichard Henderson     if (gen_trap_ifnofpu(dc)) {
513540f9ad21SRichard Henderson         return true;
513640f9ad21SRichard Henderson     }
513740f9ad21SRichard Henderson     if (gen_trap_float128(dc)) {
513840f9ad21SRichard Henderson         return true;
513940f9ad21SRichard Henderson     }
514040f9ad21SRichard Henderson 
514140f9ad21SRichard Henderson     gen_op_clear_ieee_excp_and_FTT();
514240f9ad21SRichard Henderson     gen_op_load_fpr_QT0(QFPREG(a->rs1));
514340f9ad21SRichard Henderson     gen_op_load_fpr_QT1(QFPREG(a->rs2));
514440f9ad21SRichard Henderson     if (e) {
514540f9ad21SRichard Henderson         gen_op_fcmpeq(a->cc);
514640f9ad21SRichard Henderson     } else {
514740f9ad21SRichard Henderson         gen_op_fcmpq(a->cc);
514840f9ad21SRichard Henderson     }
514940f9ad21SRichard Henderson     return advance_pc(dc);
515040f9ad21SRichard Henderson }
515140f9ad21SRichard Henderson 
515240f9ad21SRichard Henderson TRANS(FCMPq, ALL, do_fcmpq, a, false)
515340f9ad21SRichard Henderson TRANS(FCMPEq, ALL, do_fcmpq, a, true)
515440f9ad21SRichard Henderson 
51556e61bc94SEmilio G. Cota static void sparc_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
5156fcf5ef2aSThomas Huth {
51576e61bc94SEmilio G. Cota     DisasContext *dc = container_of(dcbase, DisasContext, base);
5158b77af26eSRichard Henderson     CPUSPARCState *env = cpu_env(cs);
51596e61bc94SEmilio G. Cota     int bound;
5160af00be49SEmilio G. Cota 
5161af00be49SEmilio G. Cota     dc->pc = dc->base.pc_first;
51626e61bc94SEmilio G. Cota     dc->npc = (target_ulong)dc->base.tb->cs_base;
51636e61bc94SEmilio G. Cota     dc->mem_idx = dc->base.tb->flags & TB_FLAG_MMU_MASK;
5164576e1c4cSIgor Mammedov     dc->def = &env->def;
51656e61bc94SEmilio G. Cota     dc->fpu_enabled = tb_fpu_enabled(dc->base.tb->flags);
51666e61bc94SEmilio G. Cota     dc->address_mask_32bit = tb_am_enabled(dc->base.tb->flags);
5167c9b459aaSArtyom Tarasenko #ifndef CONFIG_USER_ONLY
51686e61bc94SEmilio G. Cota     dc->supervisor = (dc->base.tb->flags & TB_FLAG_SUPER) != 0;
5169c9b459aaSArtyom Tarasenko #endif
5170fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
5171fcf5ef2aSThomas Huth     dc->fprs_dirty = 0;
51726e61bc94SEmilio G. Cota     dc->asi = (dc->base.tb->flags >> TB_FLAG_ASI_SHIFT) & 0xff;
5173c9b459aaSArtyom Tarasenko #ifndef CONFIG_USER_ONLY
51746e61bc94SEmilio G. Cota     dc->hypervisor = (dc->base.tb->flags & TB_FLAG_HYPER) != 0;
5175c9b459aaSArtyom Tarasenko #endif
5176fcf5ef2aSThomas Huth #endif
51776e61bc94SEmilio G. Cota     /*
51786e61bc94SEmilio G. Cota      * if we reach a page boundary, we stop generation so that the
51796e61bc94SEmilio G. Cota      * PC of a TT_TFAULT exception is always in the right page
51806e61bc94SEmilio G. Cota      */
51816e61bc94SEmilio G. Cota     bound = -(dc->base.pc_first | TARGET_PAGE_MASK) / 4;
51826e61bc94SEmilio G. Cota     dc->base.max_insns = MIN(dc->base.max_insns, bound);
5183af00be49SEmilio G. Cota }
5184fcf5ef2aSThomas Huth 
51856e61bc94SEmilio G. Cota static void sparc_tr_tb_start(DisasContextBase *db, CPUState *cs)
51866e61bc94SEmilio G. Cota {
51876e61bc94SEmilio G. Cota }
51886e61bc94SEmilio G. Cota 
51896e61bc94SEmilio G. Cota static void sparc_tr_insn_start(DisasContextBase *dcbase, CPUState *cs)
51906e61bc94SEmilio G. Cota {
51916e61bc94SEmilio G. Cota     DisasContext *dc = container_of(dcbase, DisasContext, base);
5192633c4283SRichard Henderson     target_ulong npc = dc->npc;
51936e61bc94SEmilio G. Cota 
5194633c4283SRichard Henderson     if (npc & 3) {
5195633c4283SRichard Henderson         switch (npc) {
5196633c4283SRichard Henderson         case JUMP_PC:
5197fcf5ef2aSThomas Huth             assert(dc->jump_pc[1] == dc->pc + 4);
5198633c4283SRichard Henderson             npc = dc->jump_pc[0] | JUMP_PC;
5199633c4283SRichard Henderson             break;
5200633c4283SRichard Henderson         case DYNAMIC_PC:
5201633c4283SRichard Henderson         case DYNAMIC_PC_LOOKUP:
5202633c4283SRichard Henderson             npc = DYNAMIC_PC;
5203633c4283SRichard Henderson             break;
5204633c4283SRichard Henderson         default:
5205633c4283SRichard Henderson             g_assert_not_reached();
5206fcf5ef2aSThomas Huth         }
52076e61bc94SEmilio G. Cota     }
5208633c4283SRichard Henderson     tcg_gen_insn_start(dc->pc, npc);
5209633c4283SRichard Henderson }
5210fcf5ef2aSThomas Huth 
52116e61bc94SEmilio G. Cota static void sparc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs)
52126e61bc94SEmilio G. Cota {
52136e61bc94SEmilio G. Cota     DisasContext *dc = container_of(dcbase, DisasContext, base);
5214b77af26eSRichard Henderson     CPUSPARCState *env = cpu_env(cs);
52156e61bc94SEmilio G. Cota     unsigned int insn;
5216fcf5ef2aSThomas Huth 
52174e116893SIlya Leoshkevich     insn = translator_ldl(env, &dc->base, dc->pc);
5218af00be49SEmilio G. Cota     dc->base.pc_next += 4;
5219878cc677SRichard Henderson 
5220878cc677SRichard Henderson     if (!decode(dc, insn)) {
5221ba9c09b4SRichard Henderson         gen_exception(dc, TT_ILL_INSN);
5222878cc677SRichard Henderson     }
5223fcf5ef2aSThomas Huth 
5224af00be49SEmilio G. Cota     if (dc->base.is_jmp == DISAS_NORETURN) {
52256e61bc94SEmilio G. Cota         return;
5226c5e6ccdfSEmilio G. Cota     }
5227af00be49SEmilio G. Cota     if (dc->pc != dc->base.pc_next) {
52286e61bc94SEmilio G. Cota         dc->base.is_jmp = DISAS_TOO_MANY;
5229af00be49SEmilio G. Cota     }
52306e61bc94SEmilio G. Cota }
5231fcf5ef2aSThomas Huth 
52326e61bc94SEmilio G. Cota static void sparc_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)
52336e61bc94SEmilio G. Cota {
52346e61bc94SEmilio G. Cota     DisasContext *dc = container_of(dcbase, DisasContext, base);
5235186e7890SRichard Henderson     DisasDelayException *e, *e_next;
5236633c4283SRichard Henderson     bool may_lookup;
52376e61bc94SEmilio G. Cota 
523889527e3aSRichard Henderson     finishing_insn(dc);
523989527e3aSRichard Henderson 
524046bb0137SMark Cave-Ayland     switch (dc->base.is_jmp) {
524146bb0137SMark Cave-Ayland     case DISAS_NEXT:
524246bb0137SMark Cave-Ayland     case DISAS_TOO_MANY:
5243633c4283SRichard Henderson         if (((dc->pc | dc->npc) & 3) == 0) {
5244fcf5ef2aSThomas Huth             /* static PC and NPC: we can use direct chaining */
5245fcf5ef2aSThomas Huth             gen_goto_tb(dc, 0, dc->pc, dc->npc);
5246633c4283SRichard Henderson             break;
5247fcf5ef2aSThomas Huth         }
5248633c4283SRichard Henderson 
5249930f1865SRichard Henderson         may_lookup = true;
5250633c4283SRichard Henderson         if (dc->pc & 3) {
5251633c4283SRichard Henderson             switch (dc->pc) {
5252633c4283SRichard Henderson             case DYNAMIC_PC_LOOKUP:
5253633c4283SRichard Henderson                 break;
5254633c4283SRichard Henderson             case DYNAMIC_PC:
5255633c4283SRichard Henderson                 may_lookup = false;
5256633c4283SRichard Henderson                 break;
5257633c4283SRichard Henderson             default:
5258633c4283SRichard Henderson                 g_assert_not_reached();
5259633c4283SRichard Henderson             }
5260633c4283SRichard Henderson         } else {
5261633c4283SRichard Henderson             tcg_gen_movi_tl(cpu_pc, dc->pc);
5262633c4283SRichard Henderson         }
5263633c4283SRichard Henderson 
5264930f1865SRichard Henderson         if (dc->npc & 3) {
5265930f1865SRichard Henderson             switch (dc->npc) {
5266930f1865SRichard Henderson             case JUMP_PC:
5267930f1865SRichard Henderson                 gen_generic_branch(dc);
5268930f1865SRichard Henderson                 break;
5269930f1865SRichard Henderson             case DYNAMIC_PC:
5270930f1865SRichard Henderson                 may_lookup = false;
5271930f1865SRichard Henderson                 break;
5272930f1865SRichard Henderson             case DYNAMIC_PC_LOOKUP:
5273930f1865SRichard Henderson                 break;
5274930f1865SRichard Henderson             default:
5275930f1865SRichard Henderson                 g_assert_not_reached();
5276930f1865SRichard Henderson             }
5277930f1865SRichard Henderson         } else {
5278930f1865SRichard Henderson             tcg_gen_movi_tl(cpu_npc, dc->npc);
5279930f1865SRichard Henderson         }
5280633c4283SRichard Henderson         if (may_lookup) {
5281633c4283SRichard Henderson             tcg_gen_lookup_and_goto_ptr();
5282633c4283SRichard Henderson         } else {
528307ea28b4SRichard Henderson             tcg_gen_exit_tb(NULL, 0);
5284fcf5ef2aSThomas Huth         }
528546bb0137SMark Cave-Ayland         break;
528646bb0137SMark Cave-Ayland 
528746bb0137SMark Cave-Ayland     case DISAS_NORETURN:
528846bb0137SMark Cave-Ayland        break;
528946bb0137SMark Cave-Ayland 
529046bb0137SMark Cave-Ayland     case DISAS_EXIT:
529146bb0137SMark Cave-Ayland         /* Exit TB */
529246bb0137SMark Cave-Ayland         save_state(dc);
529346bb0137SMark Cave-Ayland         tcg_gen_exit_tb(NULL, 0);
529446bb0137SMark Cave-Ayland         break;
529546bb0137SMark Cave-Ayland 
529646bb0137SMark Cave-Ayland     default:
529746bb0137SMark Cave-Ayland         g_assert_not_reached();
5298fcf5ef2aSThomas Huth     }
5299186e7890SRichard Henderson 
5300186e7890SRichard Henderson     for (e = dc->delay_excp_list; e ; e = e_next) {
5301186e7890SRichard Henderson         gen_set_label(e->lab);
5302186e7890SRichard Henderson 
5303186e7890SRichard Henderson         tcg_gen_movi_tl(cpu_pc, e->pc);
5304186e7890SRichard Henderson         if (e->npc % 4 == 0) {
5305186e7890SRichard Henderson             tcg_gen_movi_tl(cpu_npc, e->npc);
5306186e7890SRichard Henderson         }
5307186e7890SRichard Henderson         gen_helper_raise_exception(tcg_env, e->excp);
5308186e7890SRichard Henderson 
5309186e7890SRichard Henderson         e_next = e->next;
5310186e7890SRichard Henderson         g_free(e);
5311186e7890SRichard Henderson     }
5312fcf5ef2aSThomas Huth }
53136e61bc94SEmilio G. Cota 
53148eb806a7SRichard Henderson static void sparc_tr_disas_log(const DisasContextBase *dcbase,
53158eb806a7SRichard Henderson                                CPUState *cpu, FILE *logfile)
53166e61bc94SEmilio G. Cota {
53178eb806a7SRichard Henderson     fprintf(logfile, "IN: %s\n", lookup_symbol(dcbase->pc_first));
53188eb806a7SRichard Henderson     target_disas(logfile, cpu, dcbase->pc_first, dcbase->tb->size);
53196e61bc94SEmilio G. Cota }
53206e61bc94SEmilio G. Cota 
53216e61bc94SEmilio G. Cota static const TranslatorOps sparc_tr_ops = {
53226e61bc94SEmilio G. Cota     .init_disas_context = sparc_tr_init_disas_context,
53236e61bc94SEmilio G. Cota     .tb_start           = sparc_tr_tb_start,
53246e61bc94SEmilio G. Cota     .insn_start         = sparc_tr_insn_start,
53256e61bc94SEmilio G. Cota     .translate_insn     = sparc_tr_translate_insn,
53266e61bc94SEmilio G. Cota     .tb_stop            = sparc_tr_tb_stop,
53276e61bc94SEmilio G. Cota     .disas_log          = sparc_tr_disas_log,
53286e61bc94SEmilio G. Cota };
53296e61bc94SEmilio G. Cota 
5330597f9b2dSRichard Henderson void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int *max_insns,
533132f0c394SAnton Johansson                            vaddr pc, void *host_pc)
53326e61bc94SEmilio G. Cota {
53336e61bc94SEmilio G. Cota     DisasContext dc = {};
53346e61bc94SEmilio G. Cota 
5335306c8721SRichard Henderson     translator_loop(cs, tb, max_insns, pc, host_pc, &sparc_tr_ops, &dc.base);
5336fcf5ef2aSThomas Huth }
5337fcf5ef2aSThomas Huth 
533855c3ceefSRichard Henderson void sparc_tcg_init(void)
5339fcf5ef2aSThomas Huth {
5340fcf5ef2aSThomas Huth     static const char gregnames[32][4] = {
5341fcf5ef2aSThomas Huth         "g0", "g1", "g2", "g3", "g4", "g5", "g6", "g7",
5342fcf5ef2aSThomas Huth         "o0", "o1", "o2", "o3", "o4", "o5", "o6", "o7",
5343fcf5ef2aSThomas Huth         "l0", "l1", "l2", "l3", "l4", "l5", "l6", "l7",
5344fcf5ef2aSThomas Huth         "i0", "i1", "i2", "i3", "i4", "i5", "i6", "i7",
5345fcf5ef2aSThomas Huth     };
5346fcf5ef2aSThomas Huth     static const char fregnames[32][4] = {
5347fcf5ef2aSThomas Huth         "f0", "f2", "f4", "f6", "f8", "f10", "f12", "f14",
5348fcf5ef2aSThomas Huth         "f16", "f18", "f20", "f22", "f24", "f26", "f28", "f30",
5349fcf5ef2aSThomas Huth         "f32", "f34", "f36", "f38", "f40", "f42", "f44", "f46",
5350fcf5ef2aSThomas Huth         "f48", "f50", "f52", "f54", "f56", "f58", "f60", "f62",
5351fcf5ef2aSThomas Huth     };
5352fcf5ef2aSThomas Huth 
5353fcf5ef2aSThomas Huth     static const struct { TCGv *ptr; int off; const char *name; } rtl[] = {
5354fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
5355fcf5ef2aSThomas Huth         { &cpu_gsr, offsetof(CPUSPARCState, gsr), "gsr" },
53562a1905c7SRichard Henderson         { &cpu_xcc_Z, offsetof(CPUSPARCState, xcc_Z), "xcc_Z" },
53572a1905c7SRichard Henderson         { &cpu_xcc_C, offsetof(CPUSPARCState, xcc_C), "xcc_C" },
5358fcf5ef2aSThomas Huth #endif
53592a1905c7SRichard Henderson         { &cpu_cc_N, offsetof(CPUSPARCState, cc_N), "cc_N" },
53602a1905c7SRichard Henderson         { &cpu_cc_V, offsetof(CPUSPARCState, cc_V), "cc_V" },
53612a1905c7SRichard Henderson         { &cpu_icc_Z, offsetof(CPUSPARCState, icc_Z), "icc_Z" },
53622a1905c7SRichard Henderson         { &cpu_icc_C, offsetof(CPUSPARCState, icc_C), "icc_C" },
5363fcf5ef2aSThomas Huth         { &cpu_cond, offsetof(CPUSPARCState, cond), "cond" },
5364fcf5ef2aSThomas Huth         { &cpu_fsr, offsetof(CPUSPARCState, fsr), "fsr" },
5365fcf5ef2aSThomas Huth         { &cpu_pc, offsetof(CPUSPARCState, pc), "pc" },
5366fcf5ef2aSThomas Huth         { &cpu_npc, offsetof(CPUSPARCState, npc), "npc" },
5367fcf5ef2aSThomas Huth         { &cpu_y, offsetof(CPUSPARCState, y), "y" },
5368fcf5ef2aSThomas Huth         { &cpu_tbr, offsetof(CPUSPARCState, tbr), "tbr" },
5369fcf5ef2aSThomas Huth     };
5370fcf5ef2aSThomas Huth 
5371fcf5ef2aSThomas Huth     unsigned int i;
5372fcf5ef2aSThomas Huth 
5373ad75a51eSRichard Henderson     cpu_regwptr = tcg_global_mem_new_ptr(tcg_env,
5374fcf5ef2aSThomas Huth                                          offsetof(CPUSPARCState, regwptr),
5375fcf5ef2aSThomas Huth                                          "regwptr");
5376fcf5ef2aSThomas Huth 
5377fcf5ef2aSThomas Huth     for (i = 0; i < ARRAY_SIZE(rtl); ++i) {
5378ad75a51eSRichard Henderson         *rtl[i].ptr = tcg_global_mem_new(tcg_env, rtl[i].off, rtl[i].name);
5379fcf5ef2aSThomas Huth     }
5380fcf5ef2aSThomas Huth 
5381f764718dSRichard Henderson     cpu_regs[0] = NULL;
5382fcf5ef2aSThomas Huth     for (i = 1; i < 8; ++i) {
5383ad75a51eSRichard Henderson         cpu_regs[i] = tcg_global_mem_new(tcg_env,
5384fcf5ef2aSThomas Huth                                          offsetof(CPUSPARCState, gregs[i]),
5385fcf5ef2aSThomas Huth                                          gregnames[i]);
5386fcf5ef2aSThomas Huth     }
5387fcf5ef2aSThomas Huth 
5388fcf5ef2aSThomas Huth     for (i = 8; i < 32; ++i) {
5389fcf5ef2aSThomas Huth         cpu_regs[i] = tcg_global_mem_new(cpu_regwptr,
5390fcf5ef2aSThomas Huth                                          (i - 8) * sizeof(target_ulong),
5391fcf5ef2aSThomas Huth                                          gregnames[i]);
5392fcf5ef2aSThomas Huth     }
5393fcf5ef2aSThomas Huth 
5394fcf5ef2aSThomas Huth     for (i = 0; i < TARGET_DPREGS; i++) {
5395ad75a51eSRichard Henderson         cpu_fpr[i] = tcg_global_mem_new_i64(tcg_env,
5396fcf5ef2aSThomas Huth                                             offsetof(CPUSPARCState, fpr[i]),
5397fcf5ef2aSThomas Huth                                             fregnames[i]);
5398fcf5ef2aSThomas Huth     }
5399b597eedcSRichard Henderson 
5400b597eedcSRichard Henderson #ifdef TARGET_SPARC64
5401b597eedcSRichard Henderson     cpu_fprs = tcg_global_mem_new_i32(tcg_env,
5402b597eedcSRichard Henderson                                       offsetof(CPUSPARCState, fprs), "fprs");
5403b597eedcSRichard Henderson #endif
5404fcf5ef2aSThomas Huth }
5405fcf5ef2aSThomas Huth 
5406f36aaa53SRichard Henderson void sparc_restore_state_to_opc(CPUState *cs,
5407f36aaa53SRichard Henderson                                 const TranslationBlock *tb,
5408f36aaa53SRichard Henderson                                 const uint64_t *data)
5409fcf5ef2aSThomas Huth {
5410f36aaa53SRichard Henderson     SPARCCPU *cpu = SPARC_CPU(cs);
5411f36aaa53SRichard Henderson     CPUSPARCState *env = &cpu->env;
5412fcf5ef2aSThomas Huth     target_ulong pc = data[0];
5413fcf5ef2aSThomas Huth     target_ulong npc = data[1];
5414fcf5ef2aSThomas Huth 
5415fcf5ef2aSThomas Huth     env->pc = pc;
5416fcf5ef2aSThomas Huth     if (npc == DYNAMIC_PC) {
5417fcf5ef2aSThomas Huth         /* dynamic NPC: already stored */
5418fcf5ef2aSThomas Huth     } else if (npc & JUMP_PC) {
5419fcf5ef2aSThomas Huth         /* jump PC: use 'cond' and the jump targets of the translation */
5420fcf5ef2aSThomas Huth         if (env->cond) {
5421fcf5ef2aSThomas Huth             env->npc = npc & ~3;
5422fcf5ef2aSThomas Huth         } else {
5423fcf5ef2aSThomas Huth             env->npc = pc + 4;
5424fcf5ef2aSThomas Huth         }
5425fcf5ef2aSThomas Huth     } else {
5426fcf5ef2aSThomas Huth         env->npc = npc;
5427fcf5ef2aSThomas Huth     }
5428fcf5ef2aSThomas Huth }
5429