]>
Commit | Line | Data |
---|---|---|
7a3f1944 FB |
1 | /* |
2 | SPARC translation | |
3 | ||
4 | Copyright (C) 2003 Thomas M. Ogrisegg <[email protected]> | |
3475187d | 5 | Copyright (C) 2003-2005 Fabrice Bellard |
7a3f1944 FB |
6 | |
7 | This library is free software; you can redistribute it and/or | |
8 | modify it under the terms of the GNU Lesser General Public | |
9 | License as published by the Free Software Foundation; either | |
10 | version 2 of the License, or (at your option) any later version. | |
11 | ||
12 | This library is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | Lesser General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU Lesser General Public | |
18 | License along with this library; if not, write to the Free Software | |
19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
20 | */ | |
21 | ||
22 | /* | |
7a3f1944 FB |
23 | TODO-list: |
24 | ||
3475187d | 25 | Rest of V9 instructions, VIS instructions |
bd497938 | 26 | NPC/PC static optimisations (use JUMP_TB when possible) |
7a3f1944 | 27 | Optimize synthetic instructions |
bd497938 | 28 | */ |
7a3f1944 FB |
29 | |
30 | #include <stdarg.h> | |
31 | #include <stdlib.h> | |
32 | #include <stdio.h> | |
33 | #include <string.h> | |
34 | #include <inttypes.h> | |
35 | ||
36 | #include "cpu.h" | |
37 | #include "exec-all.h" | |
38 | #include "disas.h" | |
1a2fb1c0 | 39 | #include "helper.h" |
57fec1fe | 40 | #include "tcg-op.h" |
7a3f1944 FB |
41 | |
42 | #define DEBUG_DISAS | |
43 | ||
72cbca10 FB |
44 | #define DYNAMIC_PC 1 /* dynamic pc value */ |
45 | #define JUMP_PC 2 /* dynamic pc value which takes only two values | |
46 | according to jump_pc[T2] */ | |
47 | ||
1a2fb1c0 | 48 | /* global register indexes */ |
d9bdab86 | 49 | static TCGv cpu_env, cpu_T[3], cpu_regwptr, cpu_cc_src, cpu_cc_src2, cpu_cc_dst; |
48d5c82b | 50 | static TCGv cpu_psr, cpu_fsr, cpu_pc, cpu_npc, cpu_gregs[8]; |
dc99a3f2 BS |
51 | #ifdef TARGET_SPARC64 |
52 | static TCGv cpu_xcc; | |
53 | #endif | |
1a2fb1c0 | 54 | /* local register indexes (only used inside old micro ops) */ |
8911f501 | 55 | static TCGv cpu_tmp0, cpu_tmp32, cpu_tmp64; |
1a2fb1c0 | 56 | |
7a3f1944 | 57 | typedef struct DisasContext { |
0f8a249a BS |
58 | target_ulong pc; /* current Program Counter: integer or DYNAMIC_PC */ |
59 | target_ulong npc; /* next PC: integer or DYNAMIC_PC or JUMP_PC */ | |
72cbca10 | 60 | target_ulong jump_pc[2]; /* used when JUMP_PC pc value is used */ |
cf495bcf | 61 | int is_br; |
e8af50a3 | 62 | int mem_idx; |
a80dde08 | 63 | int fpu_enabled; |
cf495bcf | 64 | struct TranslationBlock *tb; |
7a3f1944 FB |
65 | } DisasContext; |
66 | ||
aaed909a FB |
67 | typedef struct sparc_def_t sparc_def_t; |
68 | ||
62724a37 BS |
69 | struct sparc_def_t { |
70 | const unsigned char *name; | |
71 | target_ulong iu_version; | |
72 | uint32_t fpu_version; | |
73 | uint32_t mmu_version; | |
6d5f237a | 74 | uint32_t mmu_bm; |
3deaeab7 BS |
75 | uint32_t mmu_ctpr_mask; |
76 | uint32_t mmu_cxr_mask; | |
77 | uint32_t mmu_sfsr_mask; | |
78 | uint32_t mmu_trcr_mask; | |
62724a37 BS |
79 | }; |
80 | ||
aaed909a FB |
81 | static const sparc_def_t *cpu_sparc_find_by_name(const unsigned char *name); |
82 | ||
7a3f1944 FB |
83 | extern FILE *logfile; |
84 | extern int loglevel; | |
85 | ||
3475187d | 86 | // This function uses non-native bit order |
7a3f1944 FB |
87 | #define GET_FIELD(X, FROM, TO) \ |
88 | ((X) >> (31 - (TO)) & ((1 << ((TO) - (FROM) + 1)) - 1)) | |
89 | ||
3475187d FB |
90 | // This function uses the order in the manuals, i.e. bit 0 is 2^0 |
91 | #define GET_FIELD_SP(X, FROM, TO) \ | |
92 | GET_FIELD(X, 31 - (TO), 31 - (FROM)) | |
93 | ||
94 | #define GET_FIELDs(x,a,b) sign_extend (GET_FIELD(x,a,b), (b) - (a) + 1) | |
46d38ba8 | 95 | #define GET_FIELD_SPs(x,a,b) sign_extend (GET_FIELD_SP(x,a,b), ((b) - (a) + 1)) |
3475187d FB |
96 | |
97 | #ifdef TARGET_SPARC64 | |
19f329ad | 98 | #define FFPREG(r) (r) |
0387d928 | 99 | #define DFPREG(r) (((r & 1) << 5) | (r & 0x1e)) |
1f587329 | 100 | #define QFPREG(r) (((r & 1) << 5) | (r & 0x1c)) |
3475187d | 101 | #else |
19f329ad | 102 | #define FFPREG(r) (r) |
c185970a | 103 | #define DFPREG(r) (r & 0x1e) |
1f587329 | 104 | #define QFPREG(r) (r & 0x1c) |
3475187d FB |
105 | #endif |
106 | ||
107 | static int sign_extend(int x, int len) | |
108 | { | |
109 | len = 32 - len; | |
110 | return (x << len) >> len; | |
111 | } | |
112 | ||
7a3f1944 FB |
113 | #define IS_IMM (insn & (1<<13)) |
114 | ||
cf495bcf | 115 | static void disas_sparc_insn(DisasContext * dc); |
7a3f1944 | 116 | |
ff07ec83 BS |
117 | /* floating point registers moves */ |
118 | static void gen_op_load_fpr_FT0(unsigned int src) | |
119 | { | |
8911f501 BS |
120 | tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src])); |
121 | tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, ft0)); | |
3475187d | 122 | } |
ff07ec83 BS |
123 | |
124 | static void gen_op_load_fpr_FT1(unsigned int src) | |
125 | { | |
8911f501 BS |
126 | tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src])); |
127 | tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, ft1)); | |
e8af50a3 FB |
128 | } |
129 | ||
ff07ec83 BS |
130 | static void gen_op_store_FT0_fpr(unsigned int dst) |
131 | { | |
8911f501 BS |
132 | tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, ft0)); |
133 | tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst])); | |
ff07ec83 BS |
134 | } |
135 | ||
136 | static void gen_op_load_fpr_DT0(unsigned int src) | |
137 | { | |
8911f501 BS |
138 | tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src])); |
139 | tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt0) + offsetof(CPU_DoubleU, l.upper)); | |
140 | tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 1])); | |
141 | tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt0) + offsetof(CPU_DoubleU, l.lower)); | |
ff07ec83 BS |
142 | } |
143 | ||
144 | static void gen_op_load_fpr_DT1(unsigned int src) | |
145 | { | |
8911f501 BS |
146 | tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src])); |
147 | tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt1) + offsetof(CPU_DoubleU, l.upper)); | |
148 | tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 1])); | |
149 | tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt1) + offsetof(CPU_DoubleU, l.lower)); | |
ff07ec83 BS |
150 | } |
151 | ||
152 | static void gen_op_store_DT0_fpr(unsigned int dst) | |
153 | { | |
8911f501 BS |
154 | tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt0) + offsetof(CPU_DoubleU, l.upper)); |
155 | tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst])); | |
156 | tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt0) + offsetof(CPU_DoubleU, l.lower)); | |
157 | tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst + 1])); | |
ff07ec83 BS |
158 | } |
159 | ||
160 | #ifdef CONFIG_USER_ONLY | |
161 | static void gen_op_load_fpr_QT0(unsigned int src) | |
162 | { | |
8911f501 BS |
163 | tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src])); |
164 | tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) + offsetof(CPU_QuadU, l.upmost)); | |
165 | tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 1])); | |
166 | tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) + offsetof(CPU_QuadU, l.upper)); | |
167 | tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 2])); | |
168 | tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) + offsetof(CPU_QuadU, l.lower)); | |
169 | tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 3])); | |
170 | tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) + offsetof(CPU_QuadU, l.lowest)); | |
ff07ec83 BS |
171 | } |
172 | ||
173 | static void gen_op_load_fpr_QT1(unsigned int src) | |
174 | { | |
8911f501 BS |
175 | tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src])); |
176 | tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt1) + offsetof(CPU_QuadU, l.upmost)); | |
177 | tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 1])); | |
178 | tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt1) + offsetof(CPU_QuadU, l.upper)); | |
179 | tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 2])); | |
180 | tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt1) + offsetof(CPU_QuadU, l.lower)); | |
181 | tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 3])); | |
182 | tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt1) + offsetof(CPU_QuadU, l.lowest)); | |
ff07ec83 BS |
183 | } |
184 | ||
185 | static void gen_op_store_QT0_fpr(unsigned int dst) | |
186 | { | |
8911f501 BS |
187 | tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) + offsetof(CPU_QuadU, l.upmost)); |
188 | tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst])); | |
189 | tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) + offsetof(CPU_QuadU, l.upper)); | |
190 | tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst + 1])); | |
191 | tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) + offsetof(CPU_QuadU, l.lower)); | |
192 | tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst + 2])); | |
193 | tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) + offsetof(CPU_QuadU, l.lowest)); | |
194 | tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst + 3])); | |
ff07ec83 | 195 | } |
1f587329 BS |
196 | #endif |
197 | ||
81ad8ba2 BS |
198 | /* moves */ |
199 | #ifdef CONFIG_USER_ONLY | |
3475187d | 200 | #define supervisor(dc) 0 |
81ad8ba2 | 201 | #ifdef TARGET_SPARC64 |
e9ebed4d | 202 | #define hypervisor(dc) 0 |
81ad8ba2 | 203 | #endif |
3475187d | 204 | #define gen_op_ldst(name) gen_op_##name##_raw() |
3475187d | 205 | #else |
6f27aba6 | 206 | #define supervisor(dc) (dc->mem_idx >= 1) |
81ad8ba2 BS |
207 | #ifdef TARGET_SPARC64 |
208 | #define hypervisor(dc) (dc->mem_idx == 2) | |
6f27aba6 BS |
209 | #define OP_LD_TABLE(width) \ |
210 | static GenOpFunc * const gen_op_##width[] = { \ | |
211 | &gen_op_##width##_user, \ | |
212 | &gen_op_##width##_kernel, \ | |
213 | &gen_op_##width##_hypv, \ | |
214 | }; | |
215 | #else | |
0f8a249a | 216 | #define OP_LD_TABLE(width) \ |
a68156d0 | 217 | static GenOpFunc * const gen_op_##width[] = { \ |
0f8a249a BS |
218 | &gen_op_##width##_user, \ |
219 | &gen_op_##width##_kernel, \ | |
81ad8ba2 | 220 | }; |
3475187d | 221 | #endif |
6f27aba6 BS |
222 | #define gen_op_ldst(name) (*gen_op_##name[dc->mem_idx])() |
223 | #endif | |
e8af50a3 | 224 | |
81ad8ba2 | 225 | #ifndef CONFIG_USER_ONLY |
b25deda7 BS |
226 | #ifdef __i386__ |
227 | OP_LD_TABLE(std); | |
228 | #endif /* __i386__ */ | |
e8af50a3 FB |
229 | OP_LD_TABLE(stf); |
230 | OP_LD_TABLE(stdf); | |
231 | OP_LD_TABLE(ldf); | |
232 | OP_LD_TABLE(lddf); | |
81ad8ba2 BS |
233 | #endif |
234 | ||
1a2fb1c0 | 235 | #ifdef TARGET_ABI32 |
8911f501 | 236 | #define ABI32_MASK(addr) tcg_gen_andi_tl(addr, addr, 0xffffffffULL); |
1a2fb1c0 BS |
237 | #else |
238 | #define ABI32_MASK(addr) | |
239 | #endif | |
3391c818 | 240 | |
1a2fb1c0 | 241 | static inline void gen_movl_simm_T1(int32_t val) |
81ad8ba2 | 242 | { |
1a2fb1c0 | 243 | tcg_gen_movi_tl(cpu_T[1], val); |
81ad8ba2 BS |
244 | } |
245 | ||
1a2fb1c0 | 246 | static inline void gen_movl_reg_TN(int reg, TCGv tn) |
81ad8ba2 | 247 | { |
1a2fb1c0 BS |
248 | if (reg == 0) |
249 | tcg_gen_movi_tl(tn, 0); | |
250 | else if (reg < 8) | |
f5069b26 | 251 | tcg_gen_mov_tl(tn, cpu_gregs[reg]); |
1a2fb1c0 | 252 | else { |
1a2fb1c0 | 253 | tcg_gen_ld_tl(tn, cpu_regwptr, (reg - 8) * sizeof(target_ulong)); |
81ad8ba2 BS |
254 | } |
255 | } | |
256 | ||
1a2fb1c0 | 257 | static inline void gen_movl_reg_T0(int reg) |
81ad8ba2 | 258 | { |
1a2fb1c0 | 259 | gen_movl_reg_TN(reg, cpu_T[0]); |
81ad8ba2 BS |
260 | } |
261 | ||
1a2fb1c0 | 262 | static inline void gen_movl_reg_T1(int reg) |
81ad8ba2 | 263 | { |
1a2fb1c0 | 264 | gen_movl_reg_TN(reg, cpu_T[1]); |
81ad8ba2 BS |
265 | } |
266 | ||
b25deda7 BS |
267 | #ifdef __i386__ |
268 | static inline void gen_movl_reg_T2(int reg) | |
269 | { | |
270 | gen_movl_reg_TN(reg, cpu_T[2]); | |
271 | } | |
272 | ||
273 | #endif /* __i386__ */ | |
1a2fb1c0 | 274 | static inline void gen_movl_TN_reg(int reg, TCGv tn) |
81ad8ba2 | 275 | { |
1a2fb1c0 BS |
276 | if (reg == 0) |
277 | return; | |
278 | else if (reg < 8) | |
f5069b26 | 279 | tcg_gen_mov_tl(cpu_gregs[reg], tn); |
1a2fb1c0 | 280 | else { |
1a2fb1c0 | 281 | tcg_gen_st_tl(tn, cpu_regwptr, (reg - 8) * sizeof(target_ulong)); |
81ad8ba2 BS |
282 | } |
283 | } | |
284 | ||
1a2fb1c0 | 285 | static inline void gen_movl_T0_reg(int reg) |
3475187d | 286 | { |
1a2fb1c0 | 287 | gen_movl_TN_reg(reg, cpu_T[0]); |
3475187d FB |
288 | } |
289 | ||
1a2fb1c0 | 290 | static inline void gen_movl_T1_reg(int reg) |
3475187d | 291 | { |
1a2fb1c0 | 292 | gen_movl_TN_reg(reg, cpu_T[1]); |
3475187d FB |
293 | } |
294 | ||
1a2fb1c0 | 295 | static inline void gen_op_movl_T0_env(size_t offset) |
7a3f1944 | 296 | { |
8911f501 BS |
297 | tcg_gen_ld_i32(cpu_tmp32, cpu_env, offset); |
298 | tcg_gen_ext_i32_tl(cpu_T[0], cpu_tmp32); | |
7a3f1944 FB |
299 | } |
300 | ||
1a2fb1c0 | 301 | static inline void gen_op_movl_env_T0(size_t offset) |
7a3f1944 | 302 | { |
8911f501 BS |
303 | tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_T[0]); |
304 | tcg_gen_st_i32(cpu_tmp32, cpu_env, offset); | |
7a3f1944 FB |
305 | } |
306 | ||
1a2fb1c0 | 307 | static inline void gen_op_movtl_T0_env(size_t offset) |
7a3f1944 | 308 | { |
1a2fb1c0 | 309 | tcg_gen_ld_tl(cpu_T[0], cpu_env, offset); |
7a3f1944 FB |
310 | } |
311 | ||
1a2fb1c0 | 312 | static inline void gen_op_movtl_env_T0(size_t offset) |
7a3f1944 | 313 | { |
1a2fb1c0 | 314 | tcg_gen_st_tl(cpu_T[0], cpu_env, offset); |
7a3f1944 FB |
315 | } |
316 | ||
1a2fb1c0 | 317 | static inline void gen_op_add_T1_T0(void) |
7a3f1944 | 318 | { |
1a2fb1c0 | 319 | tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
7a3f1944 FB |
320 | } |
321 | ||
1a2fb1c0 | 322 | static inline void gen_op_or_T1_T0(void) |
7a3f1944 | 323 | { |
1a2fb1c0 | 324 | tcg_gen_or_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
7a3f1944 FB |
325 | } |
326 | ||
1a2fb1c0 | 327 | static inline void gen_op_xor_T1_T0(void) |
7a3f1944 | 328 | { |
1a2fb1c0 | 329 | tcg_gen_xor_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
7a3f1944 FB |
330 | } |
331 | ||
3475187d FB |
332 | static inline void gen_jmp_im(target_ulong pc) |
333 | { | |
48d5c82b | 334 | tcg_gen_movi_tl(cpu_pc, pc); |
3475187d FB |
335 | } |
336 | ||
337 | static inline void gen_movl_npc_im(target_ulong npc) | |
338 | { | |
48d5c82b | 339 | tcg_gen_movi_tl(cpu_npc, npc); |
3475187d FB |
340 | } |
341 | ||
5fafdf24 | 342 | static inline void gen_goto_tb(DisasContext *s, int tb_num, |
6e256c93 FB |
343 | target_ulong pc, target_ulong npc) |
344 | { | |
345 | TranslationBlock *tb; | |
346 | ||
347 | tb = s->tb; | |
348 | if ((pc & TARGET_PAGE_MASK) == (tb->pc & TARGET_PAGE_MASK) && | |
349 | (npc & TARGET_PAGE_MASK) == (tb->pc & TARGET_PAGE_MASK)) { | |
350 | /* jump to same page: we can use a direct jump */ | |
57fec1fe | 351 | tcg_gen_goto_tb(tb_num); |
6e256c93 FB |
352 | gen_jmp_im(pc); |
353 | gen_movl_npc_im(npc); | |
57fec1fe | 354 | tcg_gen_exit_tb((long)tb + tb_num); |
6e256c93 FB |
355 | } else { |
356 | /* jump to another page: currently not optimized */ | |
357 | gen_jmp_im(pc); | |
358 | gen_movl_npc_im(npc); | |
57fec1fe | 359 | tcg_gen_exit_tb(0); |
6e256c93 FB |
360 | } |
361 | } | |
362 | ||
19f329ad BS |
363 | // XXX suboptimal |
364 | static inline void gen_mov_reg_N(TCGv reg, TCGv src) | |
365 | { | |
8911f501 BS |
366 | tcg_gen_extu_i32_tl(reg, src); |
367 | tcg_gen_shri_tl(reg, reg, 23); | |
19f329ad BS |
368 | tcg_gen_andi_tl(reg, reg, 0x1); |
369 | } | |
370 | ||
371 | static inline void gen_mov_reg_Z(TCGv reg, TCGv src) | |
372 | { | |
8911f501 BS |
373 | tcg_gen_extu_i32_tl(reg, src); |
374 | tcg_gen_shri_tl(reg, reg, 22); | |
19f329ad BS |
375 | tcg_gen_andi_tl(reg, reg, 0x1); |
376 | } | |
377 | ||
378 | static inline void gen_mov_reg_V(TCGv reg, TCGv src) | |
379 | { | |
8911f501 BS |
380 | tcg_gen_extu_i32_tl(reg, src); |
381 | tcg_gen_shri_tl(reg, reg, 21); | |
19f329ad BS |
382 | tcg_gen_andi_tl(reg, reg, 0x1); |
383 | } | |
384 | ||
385 | static inline void gen_mov_reg_C(TCGv reg, TCGv src) | |
386 | { | |
8911f501 BS |
387 | tcg_gen_extu_i32_tl(reg, src); |
388 | tcg_gen_shri_tl(reg, reg, 20); | |
19f329ad BS |
389 | tcg_gen_andi_tl(reg, reg, 0x1); |
390 | } | |
391 | ||
dc99a3f2 BS |
392 | static inline void gen_op_exception(int exception) |
393 | { | |
8911f501 BS |
394 | tcg_gen_movi_i32(cpu_tmp32, exception); |
395 | tcg_gen_helper_0_1(raise_exception, cpu_tmp32); | |
dc99a3f2 BS |
396 | } |
397 | ||
398 | static inline void gen_cc_clear(void) | |
399 | { | |
400 | tcg_gen_movi_i32(cpu_psr, 0); | |
401 | #ifdef TARGET_SPARC64 | |
402 | tcg_gen_movi_i32(cpu_xcc, 0); | |
403 | #endif | |
404 | } | |
405 | ||
406 | /* old op: | |
407 | if (!T0) | |
408 | env->psr |= PSR_ZERO; | |
409 | if ((int32_t) T0 < 0) | |
410 | env->psr |= PSR_NEG; | |
411 | */ | |
412 | static inline void gen_cc_NZ(TCGv dst) | |
413 | { | |
8911f501 | 414 | TCGv r_temp; |
dc99a3f2 | 415 | int l1, l2; |
dc99a3f2 BS |
416 | |
417 | l1 = gen_new_label(); | |
418 | l2 = gen_new_label(); | |
8911f501 BS |
419 | r_temp = tcg_temp_new(TCG_TYPE_TL); |
420 | tcg_gen_andi_tl(r_temp, dst, 0xffffffffULL); | |
421 | tcg_gen_brcond_tl(TCG_COND_NE, r_temp, tcg_const_tl(0), l1); | |
dc99a3f2 BS |
422 | tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_ZERO); |
423 | gen_set_label(l1); | |
8911f501 BS |
424 | tcg_gen_andi_tl(r_temp, dst, 0xffffffffULL); |
425 | tcg_gen_brcond_tl(TCG_COND_GE, r_temp, tcg_const_tl(0), l2); | |
dc99a3f2 BS |
426 | tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_NEG); |
427 | gen_set_label(l2); | |
428 | #ifdef TARGET_SPARC64 | |
429 | { | |
430 | int l3, l4; | |
431 | ||
432 | l3 = gen_new_label(); | |
433 | l4 = gen_new_label(); | |
0425bee5 | 434 | tcg_gen_brcond_tl(TCG_COND_NE, dst, tcg_const_tl(0), l3); |
dc99a3f2 BS |
435 | tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_ZERO); |
436 | gen_set_label(l3); | |
0425bee5 | 437 | tcg_gen_brcond_tl(TCG_COND_GE, dst, tcg_const_tl(0), l4); |
dc99a3f2 BS |
438 | tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_NEG); |
439 | gen_set_label(l4); | |
440 | } | |
441 | #endif | |
442 | } | |
443 | ||
444 | /* old op: | |
445 | if (T0 < src1) | |
446 | env->psr |= PSR_CARRY; | |
447 | */ | |
448 | static inline void gen_cc_C_add(TCGv dst, TCGv src1) | |
449 | { | |
8911f501 | 450 | TCGv r_temp; |
dc99a3f2 BS |
451 | int l1; |
452 | ||
453 | l1 = gen_new_label(); | |
8911f501 BS |
454 | r_temp = tcg_temp_new(TCG_TYPE_TL); |
455 | tcg_gen_andi_tl(r_temp, dst, 0xffffffffULL); | |
456 | tcg_gen_brcond_tl(TCG_COND_GEU, dst, src1, l1); | |
dc99a3f2 BS |
457 | tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_CARRY); |
458 | gen_set_label(l1); | |
459 | #ifdef TARGET_SPARC64 | |
460 | { | |
461 | int l2; | |
462 | ||
463 | l2 = gen_new_label(); | |
464 | tcg_gen_brcond_tl(TCG_COND_GEU, dst, src1, l2); | |
465 | tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_CARRY); | |
466 | gen_set_label(l2); | |
467 | } | |
468 | #endif | |
469 | } | |
470 | ||
471 | /* old op: | |
472 | if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1 << 31)) | |
473 | env->psr |= PSR_OVF; | |
474 | */ | |
475 | static inline void gen_cc_V_add(TCGv dst, TCGv src1, TCGv src2) | |
476 | { | |
0425bee5 | 477 | TCGv r_temp; |
dc99a3f2 BS |
478 | int l1; |
479 | ||
480 | l1 = gen_new_label(); | |
481 | ||
482 | r_temp = tcg_temp_new(TCG_TYPE_TL); | |
dc99a3f2 BS |
483 | tcg_gen_xor_tl(r_temp, src1, src2); |
484 | tcg_gen_xori_tl(r_temp, r_temp, -1); | |
0425bee5 BS |
485 | tcg_gen_xor_tl(cpu_tmp0, src1, dst); |
486 | tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0); | |
487 | tcg_gen_andi_tl(r_temp, r_temp, (1 << 31)); | |
8911f501 | 488 | tcg_gen_brcond_tl(TCG_COND_EQ, r_temp, tcg_const_tl(0), l1); |
dc99a3f2 BS |
489 | tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_OVF); |
490 | gen_set_label(l1); | |
491 | #ifdef TARGET_SPARC64 | |
492 | { | |
493 | int l2; | |
494 | ||
495 | l2 = gen_new_label(); | |
dc99a3f2 BS |
496 | tcg_gen_xor_tl(r_temp, src1, src2); |
497 | tcg_gen_xori_tl(r_temp, r_temp, -1); | |
0425bee5 BS |
498 | tcg_gen_xor_tl(cpu_tmp0, src1, dst); |
499 | tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0); | |
500 | tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 63)); | |
501 | tcg_gen_brcond_tl(TCG_COND_EQ, r_temp, tcg_const_tl(0), l2); | |
dc99a3f2 BS |
502 | tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_OVF); |
503 | gen_set_label(l2); | |
504 | } | |
505 | #endif | |
0425bee5 | 506 | tcg_gen_discard_tl(r_temp); |
dc99a3f2 BS |
507 | } |
508 | ||
509 | static inline void gen_add_tv(TCGv dst, TCGv src1, TCGv src2) | |
510 | { | |
0425bee5 | 511 | TCGv r_temp; |
dc99a3f2 BS |
512 | int l1; |
513 | ||
514 | l1 = gen_new_label(); | |
515 | ||
516 | r_temp = tcg_temp_new(TCG_TYPE_TL); | |
dc99a3f2 BS |
517 | tcg_gen_xor_tl(r_temp, src1, src2); |
518 | tcg_gen_xori_tl(r_temp, r_temp, -1); | |
0425bee5 BS |
519 | tcg_gen_xor_tl(cpu_tmp0, src1, dst); |
520 | tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0); | |
521 | tcg_gen_andi_tl(r_temp, r_temp, (1 << 31)); | |
8911f501 | 522 | tcg_gen_brcond_tl(TCG_COND_EQ, r_temp, tcg_const_tl(0), l1); |
dc99a3f2 BS |
523 | gen_op_exception(TT_TOVF); |
524 | gen_set_label(l1); | |
525 | #ifdef TARGET_SPARC64 | |
526 | { | |
527 | int l2; | |
528 | ||
529 | l2 = gen_new_label(); | |
dc99a3f2 BS |
530 | tcg_gen_xor_tl(r_temp, src1, src2); |
531 | tcg_gen_xori_tl(r_temp, r_temp, -1); | |
0425bee5 BS |
532 | tcg_gen_xor_tl(cpu_tmp0, src1, dst); |
533 | tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0); | |
534 | tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 63)); | |
535 | tcg_gen_brcond_tl(TCG_COND_EQ, r_temp, tcg_const_tl(0), l2); | |
dc99a3f2 BS |
536 | gen_op_exception(TT_TOVF); |
537 | gen_set_label(l2); | |
538 | } | |
539 | #endif | |
0425bee5 | 540 | tcg_gen_discard_tl(r_temp); |
dc99a3f2 BS |
541 | } |
542 | ||
543 | static inline void gen_cc_V_tag(TCGv src1, TCGv src2) | |
544 | { | |
545 | int l1; | |
dc99a3f2 BS |
546 | |
547 | l1 = gen_new_label(); | |
0425bee5 BS |
548 | tcg_gen_or_tl(cpu_tmp0, src1, src2); |
549 | tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0x3); | |
550 | tcg_gen_brcond_tl(TCG_COND_EQ, cpu_tmp0, tcg_const_tl(0), l1); | |
dc99a3f2 BS |
551 | tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_OVF); |
552 | gen_set_label(l1); | |
553 | } | |
554 | ||
555 | static inline void gen_tag_tv(TCGv src1, TCGv src2) | |
556 | { | |
557 | int l1; | |
dc99a3f2 BS |
558 | |
559 | l1 = gen_new_label(); | |
0425bee5 BS |
560 | tcg_gen_or_tl(cpu_tmp0, src1, src2); |
561 | tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0x3); | |
562 | tcg_gen_brcond_tl(TCG_COND_EQ, cpu_tmp0, tcg_const_tl(0), l1); | |
dc99a3f2 BS |
563 | gen_op_exception(TT_TOVF); |
564 | gen_set_label(l1); | |
565 | } | |
566 | ||
567 | static inline void gen_op_add_T1_T0_cc(void) | |
568 | { | |
569 | tcg_gen_mov_tl(cpu_cc_src, cpu_T[0]); | |
570 | tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]); | |
571 | gen_cc_clear(); | |
572 | gen_cc_NZ(cpu_T[0]); | |
573 | gen_cc_C_add(cpu_T[0], cpu_cc_src); | |
574 | gen_cc_V_add(cpu_T[0], cpu_cc_src, cpu_T[1]); | |
575 | } | |
576 | ||
577 | static inline void gen_op_addx_T1_T0_cc(void) | |
578 | { | |
579 | tcg_gen_mov_tl(cpu_cc_src, cpu_T[0]); | |
580 | gen_mov_reg_C(cpu_tmp0, cpu_psr); | |
581 | tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_tmp0); | |
582 | gen_cc_clear(); | |
583 | gen_cc_C_add(cpu_T[0], cpu_cc_src); | |
584 | tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]); | |
585 | gen_cc_C_add(cpu_T[0], cpu_cc_src); | |
586 | gen_cc_NZ(cpu_T[0]); | |
587 | gen_cc_V_add(cpu_T[0], cpu_cc_src, cpu_T[1]); | |
588 | } | |
589 | ||
590 | static inline void gen_op_tadd_T1_T0_cc(void) | |
591 | { | |
592 | tcg_gen_mov_tl(cpu_cc_src, cpu_T[0]); | |
593 | tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]); | |
594 | gen_cc_clear(); | |
595 | gen_cc_NZ(cpu_T[0]); | |
596 | gen_cc_C_add(cpu_T[0], cpu_cc_src); | |
597 | gen_cc_V_add(cpu_T[0], cpu_cc_src, cpu_T[1]); | |
598 | gen_cc_V_tag(cpu_cc_src, cpu_T[1]); | |
599 | } | |
600 | ||
601 | static inline void gen_op_tadd_T1_T0_ccTV(void) | |
602 | { | |
603 | gen_tag_tv(cpu_T[0], cpu_T[1]); | |
604 | tcg_gen_mov_tl(cpu_cc_src, cpu_T[0]); | |
605 | tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]); | |
606 | gen_add_tv(cpu_T[0], cpu_cc_src, cpu_T[1]); | |
607 | gen_cc_clear(); | |
608 | gen_cc_NZ(cpu_T[0]); | |
609 | gen_cc_C_add(cpu_T[0], cpu_cc_src); | |
610 | } | |
611 | ||
612 | /* old op: | |
613 | if (src1 < T1) | |
614 | env->psr |= PSR_CARRY; | |
615 | */ | |
616 | static inline void gen_cc_C_sub(TCGv src1, TCGv src2) | |
617 | { | |
8911f501 | 618 | TCGv r_temp1, r_temp2; |
dc99a3f2 BS |
619 | int l1; |
620 | ||
621 | l1 = gen_new_label(); | |
8911f501 BS |
622 | r_temp1 = tcg_temp_new(TCG_TYPE_TL); |
623 | r_temp2 = tcg_temp_new(TCG_TYPE_TL); | |
624 | tcg_gen_andi_tl(r_temp1, src1, 0xffffffffULL); | |
625 | tcg_gen_andi_tl(r_temp2, src2, 0xffffffffULL); | |
626 | tcg_gen_brcond_tl(TCG_COND_GEU, r_temp1, r_temp2, l1); | |
dc99a3f2 BS |
627 | tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_CARRY); |
628 | gen_set_label(l1); | |
629 | #ifdef TARGET_SPARC64 | |
630 | { | |
631 | int l2; | |
632 | ||
633 | l2 = gen_new_label(); | |
634 | tcg_gen_brcond_tl(TCG_COND_GEU, src1, src2, l2); | |
635 | tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_CARRY); | |
636 | gen_set_label(l2); | |
637 | } | |
638 | #endif | |
639 | } | |
640 | ||
641 | /* old op: | |
642 | if (((src1 ^ T1) & (src1 ^ T0)) & (1 << 31)) | |
643 | env->psr |= PSR_OVF; | |
644 | */ | |
645 | static inline void gen_cc_V_sub(TCGv dst, TCGv src1, TCGv src2) | |
646 | { | |
0425bee5 | 647 | TCGv r_temp; |
dc99a3f2 BS |
648 | int l1; |
649 | ||
650 | l1 = gen_new_label(); | |
651 | ||
652 | r_temp = tcg_temp_new(TCG_TYPE_TL); | |
dc99a3f2 | 653 | tcg_gen_xor_tl(r_temp, src1, src2); |
0425bee5 BS |
654 | tcg_gen_xor_tl(cpu_tmp0, src1, dst); |
655 | tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0); | |
656 | tcg_gen_andi_tl(r_temp, r_temp, (1 << 31)); | |
8911f501 | 657 | tcg_gen_brcond_tl(TCG_COND_EQ, r_temp, tcg_const_tl(0), l1); |
dc99a3f2 BS |
658 | tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_OVF); |
659 | gen_set_label(l1); | |
660 | #ifdef TARGET_SPARC64 | |
661 | { | |
662 | int l2; | |
663 | ||
664 | l2 = gen_new_label(); | |
dc99a3f2 | 665 | tcg_gen_xor_tl(r_temp, src1, src2); |
0425bee5 BS |
666 | tcg_gen_xor_tl(cpu_tmp0, src1, dst); |
667 | tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0); | |
668 | tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 63)); | |
669 | tcg_gen_brcond_tl(TCG_COND_EQ, r_temp, tcg_const_tl(0), l2); | |
dc99a3f2 BS |
670 | tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_OVF); |
671 | gen_set_label(l2); | |
672 | } | |
673 | #endif | |
0425bee5 | 674 | tcg_gen_discard_tl(r_temp); |
dc99a3f2 BS |
675 | } |
676 | ||
677 | static inline void gen_sub_tv(TCGv dst, TCGv src1, TCGv src2) | |
678 | { | |
0425bee5 | 679 | TCGv r_temp; |
dc99a3f2 BS |
680 | int l1; |
681 | ||
682 | l1 = gen_new_label(); | |
683 | ||
684 | r_temp = tcg_temp_new(TCG_TYPE_TL); | |
dc99a3f2 | 685 | tcg_gen_xor_tl(r_temp, src1, src2); |
0425bee5 BS |
686 | tcg_gen_xor_tl(cpu_tmp0, src1, dst); |
687 | tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0); | |
688 | tcg_gen_andi_tl(r_temp, r_temp, (1 << 31)); | |
8911f501 | 689 | tcg_gen_brcond_tl(TCG_COND_EQ, r_temp, tcg_const_tl(0), l1); |
dc99a3f2 BS |
690 | gen_op_exception(TT_TOVF); |
691 | gen_set_label(l1); | |
692 | #ifdef TARGET_SPARC64 | |
693 | { | |
694 | int l2; | |
695 | ||
696 | l2 = gen_new_label(); | |
dc99a3f2 | 697 | tcg_gen_xor_tl(r_temp, src1, src2); |
0425bee5 BS |
698 | tcg_gen_xor_tl(cpu_tmp0, src1, dst); |
699 | tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0); | |
700 | tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 63)); | |
701 | tcg_gen_brcond_tl(TCG_COND_EQ, r_temp, tcg_const_tl(0), l2); | |
dc99a3f2 BS |
702 | gen_op_exception(TT_TOVF); |
703 | gen_set_label(l2); | |
704 | } | |
705 | #endif | |
0425bee5 | 706 | tcg_gen_discard_tl(r_temp); |
dc99a3f2 BS |
707 | } |
708 | ||
709 | static inline void gen_op_sub_T1_T0_cc(void) | |
710 | { | |
711 | tcg_gen_mov_tl(cpu_cc_src, cpu_T[0]); | |
712 | tcg_gen_sub_tl(cpu_T[0], cpu_T[0], cpu_T[1]); | |
713 | gen_cc_clear(); | |
714 | gen_cc_NZ(cpu_T[0]); | |
715 | gen_cc_C_sub(cpu_cc_src, cpu_T[1]); | |
716 | gen_cc_V_sub(cpu_T[0], cpu_cc_src, cpu_T[1]); | |
717 | } | |
718 | ||
719 | static inline void gen_op_subx_T1_T0_cc(void) | |
720 | { | |
721 | tcg_gen_mov_tl(cpu_cc_src, cpu_T[0]); | |
722 | gen_mov_reg_C(cpu_tmp0, cpu_psr); | |
723 | tcg_gen_sub_tl(cpu_T[0], cpu_T[0], cpu_tmp0); | |
724 | gen_cc_clear(); | |
725 | gen_cc_C_sub(cpu_T[0], cpu_cc_src); | |
726 | tcg_gen_sub_tl(cpu_T[0], cpu_T[0], cpu_T[1]); | |
727 | gen_cc_C_sub(cpu_T[0], cpu_cc_src); | |
728 | gen_cc_NZ(cpu_T[0]); | |
729 | gen_cc_V_sub(cpu_T[0], cpu_cc_src, cpu_T[1]); | |
730 | } | |
731 | ||
732 | static inline void gen_op_tsub_T1_T0_cc(void) | |
733 | { | |
734 | tcg_gen_mov_tl(cpu_cc_src, cpu_T[0]); | |
735 | tcg_gen_sub_tl(cpu_T[0], cpu_T[0], cpu_T[1]); | |
736 | gen_cc_clear(); | |
737 | gen_cc_NZ(cpu_T[0]); | |
738 | gen_cc_C_sub(cpu_cc_src, cpu_T[1]); | |
739 | gen_cc_V_sub(cpu_T[0], cpu_cc_src, cpu_T[1]); | |
740 | gen_cc_V_tag(cpu_cc_src, cpu_T[1]); | |
741 | } | |
742 | ||
743 | static inline void gen_op_tsub_T1_T0_ccTV(void) | |
744 | { | |
745 | gen_tag_tv(cpu_T[0], cpu_T[1]); | |
746 | tcg_gen_mov_tl(cpu_cc_src, cpu_T[0]); | |
747 | tcg_gen_sub_tl(cpu_T[0], cpu_T[0], cpu_T[1]); | |
748 | gen_sub_tv(cpu_T[0], cpu_cc_src, cpu_T[1]); | |
749 | gen_cc_clear(); | |
750 | gen_cc_NZ(cpu_T[0]); | |
751 | gen_cc_C_sub(cpu_cc_src, cpu_T[1]); | |
752 | } | |
753 | ||
d9bdab86 BS |
754 | static inline void gen_op_mulscc_T1_T0(void) |
755 | { | |
756 | TCGv r_temp; | |
757 | int l1, l2; | |
758 | ||
759 | l1 = gen_new_label(); | |
760 | l2 = gen_new_label(); | |
761 | r_temp = tcg_temp_new(TCG_TYPE_TL); | |
762 | ||
763 | /* old op: | |
764 | if (!(env->y & 1)) | |
765 | T1 = 0; | |
766 | */ | |
8911f501 BS |
767 | tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, y)); |
768 | tcg_gen_extu_i32_tl(r_temp, cpu_tmp32); | |
769 | tcg_gen_andi_tl(r_temp, r_temp, 0x1); | |
770 | tcg_gen_brcond_tl(TCG_COND_EQ, r_temp, tcg_const_tl(0), l1); | |
d9bdab86 | 771 | tcg_gen_mov_tl(cpu_cc_src2, cpu_T[1]); |
06b3e1b3 | 772 | tcg_gen_br(l2); |
d9bdab86 BS |
773 | gen_set_label(l1); |
774 | tcg_gen_movi_tl(cpu_cc_src2, 0); | |
775 | gen_set_label(l2); | |
776 | ||
777 | // b2 = T0 & 1; | |
778 | // env->y = (b2 << 31) | (env->y >> 1); | |
8911f501 BS |
779 | tcg_gen_shli_tl(r_temp, cpu_T[0], 31); |
780 | tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, y)); | |
781 | tcg_gen_shri_i32(cpu_tmp32, cpu_tmp32, 1); | |
782 | tcg_gen_or_i32(cpu_tmp32, cpu_tmp32, r_temp); | |
783 | tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, y)); | |
d9bdab86 BS |
784 | |
785 | // b1 = N ^ V; | |
786 | gen_mov_reg_N(cpu_tmp0, cpu_psr); | |
787 | gen_mov_reg_V(r_temp, cpu_psr); | |
788 | tcg_gen_xor_tl(cpu_tmp0, cpu_tmp0, r_temp); | |
789 | ||
790 | // T0 = (b1 << 31) | (T0 >> 1); | |
791 | // src1 = T0; | |
792 | tcg_gen_shli_tl(cpu_tmp0, cpu_tmp0, 31); | |
793 | tcg_gen_shri_tl(cpu_cc_src, cpu_T[0], 1); | |
794 | tcg_gen_or_tl(cpu_cc_src, cpu_cc_src, cpu_tmp0); | |
795 | ||
796 | /* do addition and update flags */ | |
797 | tcg_gen_add_tl(cpu_T[0], cpu_cc_src, cpu_cc_src2); | |
798 | tcg_gen_discard_tl(r_temp); | |
799 | ||
800 | gen_cc_clear(); | |
801 | gen_cc_NZ(cpu_T[0]); | |
802 | gen_cc_V_add(cpu_T[0], cpu_cc_src, cpu_cc_src2); | |
803 | gen_cc_C_add(cpu_T[0], cpu_cc_src); | |
804 | } | |
805 | ||
8879d139 BS |
806 | static inline void gen_op_umul_T1_T0(void) |
807 | { | |
808 | TCGv r_temp, r_temp2; | |
809 | ||
810 | r_temp = tcg_temp_new(TCG_TYPE_I64); | |
811 | r_temp2 = tcg_temp_new(TCG_TYPE_I64); | |
812 | ||
8911f501 BS |
813 | tcg_gen_extu_tl_i64(r_temp, cpu_T[1]); |
814 | tcg_gen_extu_tl_i64(r_temp2, cpu_T[0]); | |
8879d139 BS |
815 | tcg_gen_mul_i64(r_temp2, r_temp, r_temp2); |
816 | ||
817 | tcg_gen_shri_i64(r_temp, r_temp2, 32); | |
818 | tcg_gen_trunc_i64_i32(r_temp, r_temp); | |
819 | tcg_gen_st_i32(r_temp, cpu_env, offsetof(CPUSPARCState, y)); | |
820 | #ifdef TARGET_SPARC64 | |
821 | tcg_gen_mov_i64(cpu_T[0], r_temp2); | |
822 | #else | |
8911f501 | 823 | tcg_gen_trunc_i64_tl(cpu_T[0], r_temp2); |
8879d139 BS |
824 | #endif |
825 | ||
826 | tcg_gen_discard_i64(r_temp); | |
827 | tcg_gen_discard_i64(r_temp2); | |
828 | } | |
829 | ||
830 | static inline void gen_op_smul_T1_T0(void) | |
831 | { | |
832 | TCGv r_temp, r_temp2; | |
833 | ||
834 | r_temp = tcg_temp_new(TCG_TYPE_I64); | |
835 | r_temp2 = tcg_temp_new(TCG_TYPE_I64); | |
836 | ||
8911f501 BS |
837 | tcg_gen_ext_tl_i64(r_temp, cpu_T[1]); |
838 | tcg_gen_ext_tl_i64(r_temp2, cpu_T[0]); | |
8879d139 BS |
839 | tcg_gen_mul_i64(r_temp2, r_temp, r_temp2); |
840 | ||
841 | tcg_gen_shri_i64(r_temp, r_temp2, 32); | |
842 | tcg_gen_trunc_i64_i32(r_temp, r_temp); | |
843 | tcg_gen_st_i32(r_temp, cpu_env, offsetof(CPUSPARCState, y)); | |
844 | #ifdef TARGET_SPARC64 | |
845 | tcg_gen_mov_i64(cpu_T[0], r_temp2); | |
846 | #else | |
8911f501 | 847 | tcg_gen_trunc_i64_tl(cpu_T[0], r_temp2); |
8879d139 BS |
848 | #endif |
849 | ||
850 | tcg_gen_discard_i64(r_temp); | |
851 | tcg_gen_discard_i64(r_temp2); | |
852 | } | |
853 | ||
3b89f26c BS |
854 | static inline void gen_op_udiv_T1_T0(void) |
855 | { | |
856 | tcg_gen_helper_1_2(helper_udiv, cpu_T[0], cpu_T[0], cpu_T[1]); | |
857 | } | |
858 | ||
859 | static inline void gen_op_sdiv_T1_T0(void) | |
860 | { | |
861 | tcg_gen_helper_1_2(helper_sdiv, cpu_T[0], cpu_T[0], cpu_T[1]); | |
862 | } | |
863 | ||
1a7b60e7 | 864 | #ifdef TARGET_SPARC64 |
8911f501 | 865 | static inline void gen_trap_ifdivzero_tl(TCGv divisor) |
1a7b60e7 BS |
866 | { |
867 | int l1; | |
868 | ||
869 | l1 = gen_new_label(); | |
8911f501 | 870 | tcg_gen_brcond_tl(TCG_COND_NE, divisor, tcg_const_tl(0), l1); |
1a7b60e7 BS |
871 | gen_op_exception(TT_DIV_ZERO); |
872 | gen_set_label(l1); | |
873 | } | |
874 | ||
875 | static inline void gen_op_sdivx_T1_T0(void) | |
876 | { | |
877 | int l1, l2; | |
878 | ||
879 | l1 = gen_new_label(); | |
880 | l2 = gen_new_label(); | |
8911f501 BS |
881 | gen_trap_ifdivzero_tl(cpu_T[1]); |
882 | tcg_gen_brcond_tl(TCG_COND_NE, cpu_T[0], tcg_const_tl(INT64_MIN), l1); | |
883 | tcg_gen_brcond_tl(TCG_COND_NE, cpu_T[1], tcg_const_tl(-1), l1); | |
1a7b60e7 | 884 | tcg_gen_movi_i64(cpu_T[0], INT64_MIN); |
06b3e1b3 | 885 | tcg_gen_br(l2); |
1a7b60e7 BS |
886 | gen_set_label(l1); |
887 | tcg_gen_div_i64(cpu_T[0], cpu_T[0], cpu_T[1]); | |
888 | gen_set_label(l2); | |
889 | } | |
890 | #endif | |
891 | ||
dc99a3f2 BS |
892 | static inline void gen_op_div_cc(void) |
893 | { | |
894 | int l1; | |
dc99a3f2 BS |
895 | |
896 | gen_cc_clear(); | |
897 | gen_cc_NZ(cpu_T[0]); | |
898 | l1 = gen_new_label(); | |
3b89f26c BS |
899 | tcg_gen_ld_tl(cpu_tmp0, cpu_env, offsetof(CPUSPARCState, cc_src2)); |
900 | tcg_gen_brcond_tl(TCG_COND_EQ, cpu_tmp0, tcg_const_tl(0), l1); | |
dc99a3f2 BS |
901 | tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_OVF); |
902 | gen_set_label(l1); | |
903 | } | |
904 | ||
905 | static inline void gen_op_logic_T0_cc(void) | |
906 | { | |
907 | gen_cc_clear(); | |
908 | gen_cc_NZ(cpu_T[0]); | |
909 | } | |
910 | ||
19f329ad BS |
911 | // 1 |
912 | static inline void gen_op_eval_ba(TCGv dst) | |
913 | { | |
914 | tcg_gen_movi_tl(dst, 1); | |
915 | } | |
916 | ||
917 | // Z | |
918 | static inline void gen_op_eval_be(TCGv dst, TCGv src) | |
919 | { | |
920 | gen_mov_reg_Z(dst, src); | |
921 | } | |
922 | ||
923 | // Z | (N ^ V) | |
924 | static inline void gen_op_eval_ble(TCGv dst, TCGv src) | |
925 | { | |
0425bee5 | 926 | gen_mov_reg_N(cpu_tmp0, src); |
19f329ad | 927 | gen_mov_reg_V(dst, src); |
0425bee5 BS |
928 | tcg_gen_xor_tl(dst, dst, cpu_tmp0); |
929 | gen_mov_reg_Z(cpu_tmp0, src); | |
930 | tcg_gen_or_tl(dst, dst, cpu_tmp0); | |
19f329ad BS |
931 | } |
932 | ||
933 | // N ^ V | |
934 | static inline void gen_op_eval_bl(TCGv dst, TCGv src) | |
935 | { | |
0425bee5 | 936 | gen_mov_reg_V(cpu_tmp0, src); |
19f329ad | 937 | gen_mov_reg_N(dst, src); |
0425bee5 | 938 | tcg_gen_xor_tl(dst, dst, cpu_tmp0); |
19f329ad BS |
939 | } |
940 | ||
941 | // C | Z | |
942 | static inline void gen_op_eval_bleu(TCGv dst, TCGv src) | |
943 | { | |
0425bee5 | 944 | gen_mov_reg_Z(cpu_tmp0, src); |
19f329ad | 945 | gen_mov_reg_C(dst, src); |
0425bee5 | 946 | tcg_gen_or_tl(dst, dst, cpu_tmp0); |
19f329ad BS |
947 | } |
948 | ||
949 | // C | |
950 | static inline void gen_op_eval_bcs(TCGv dst, TCGv src) | |
951 | { | |
952 | gen_mov_reg_C(dst, src); | |
953 | } | |
954 | ||
955 | // V | |
956 | static inline void gen_op_eval_bvs(TCGv dst, TCGv src) | |
957 | { | |
958 | gen_mov_reg_V(dst, src); | |
959 | } | |
960 | ||
961 | // 0 | |
962 | static inline void gen_op_eval_bn(TCGv dst) | |
963 | { | |
964 | tcg_gen_movi_tl(dst, 0); | |
965 | } | |
966 | ||
967 | // N | |
968 | static inline void gen_op_eval_bneg(TCGv dst, TCGv src) | |
969 | { | |
970 | gen_mov_reg_N(dst, src); | |
971 | } | |
972 | ||
973 | // !Z | |
974 | static inline void gen_op_eval_bne(TCGv dst, TCGv src) | |
975 | { | |
976 | gen_mov_reg_Z(dst, src); | |
977 | tcg_gen_xori_tl(dst, dst, 0x1); | |
978 | } | |
979 | ||
980 | // !(Z | (N ^ V)) | |
981 | static inline void gen_op_eval_bg(TCGv dst, TCGv src) | |
982 | { | |
0425bee5 | 983 | gen_mov_reg_N(cpu_tmp0, src); |
19f329ad | 984 | gen_mov_reg_V(dst, src); |
0425bee5 BS |
985 | tcg_gen_xor_tl(dst, dst, cpu_tmp0); |
986 | gen_mov_reg_Z(cpu_tmp0, src); | |
987 | tcg_gen_or_tl(dst, dst, cpu_tmp0); | |
19f329ad BS |
988 | tcg_gen_xori_tl(dst, dst, 0x1); |
989 | } | |
990 | ||
991 | // !(N ^ V) | |
992 | static inline void gen_op_eval_bge(TCGv dst, TCGv src) | |
993 | { | |
0425bee5 | 994 | gen_mov_reg_V(cpu_tmp0, src); |
19f329ad | 995 | gen_mov_reg_N(dst, src); |
0425bee5 | 996 | tcg_gen_xor_tl(dst, dst, cpu_tmp0); |
19f329ad BS |
997 | tcg_gen_xori_tl(dst, dst, 0x1); |
998 | } | |
999 | ||
1000 | // !(C | Z) | |
1001 | static inline void gen_op_eval_bgu(TCGv dst, TCGv src) | |
1002 | { | |
0425bee5 | 1003 | gen_mov_reg_Z(cpu_tmp0, src); |
19f329ad | 1004 | gen_mov_reg_C(dst, src); |
0425bee5 | 1005 | tcg_gen_or_tl(dst, dst, cpu_tmp0); |
19f329ad BS |
1006 | tcg_gen_xori_tl(dst, dst, 0x1); |
1007 | } | |
1008 | ||
1009 | // !C | |
1010 | static inline void gen_op_eval_bcc(TCGv dst, TCGv src) | |
1011 | { | |
1012 | gen_mov_reg_C(dst, src); | |
1013 | tcg_gen_xori_tl(dst, dst, 0x1); | |
1014 | } | |
1015 | ||
1016 | // !N | |
1017 | static inline void gen_op_eval_bpos(TCGv dst, TCGv src) | |
1018 | { | |
1019 | gen_mov_reg_N(dst, src); | |
1020 | tcg_gen_xori_tl(dst, dst, 0x1); | |
1021 | } | |
1022 | ||
1023 | // !V | |
1024 | static inline void gen_op_eval_bvc(TCGv dst, TCGv src) | |
1025 | { | |
1026 | gen_mov_reg_V(dst, src); | |
1027 | tcg_gen_xori_tl(dst, dst, 0x1); | |
1028 | } | |
1029 | ||
1030 | /* | |
1031 | FPSR bit field FCC1 | FCC0: | |
1032 | 0 = | |
1033 | 1 < | |
1034 | 2 > | |
1035 | 3 unordered | |
1036 | */ | |
1037 | static inline void gen_mov_reg_FCC0(TCGv reg, TCGv src, | |
1038 | unsigned int fcc_offset) | |
1039 | { | |
8911f501 BS |
1040 | tcg_gen_extu_i32_tl(reg, src); |
1041 | tcg_gen_shri_tl(reg, reg, 10 + fcc_offset); | |
19f329ad BS |
1042 | tcg_gen_andi_tl(reg, reg, 0x1); |
1043 | } | |
1044 | ||
1045 | static inline void gen_mov_reg_FCC1(TCGv reg, TCGv src, | |
1046 | unsigned int fcc_offset) | |
1047 | { | |
8911f501 BS |
1048 | tcg_gen_extu_i32_tl(reg, src); |
1049 | tcg_gen_shri_tl(reg, reg, 11 + fcc_offset); | |
19f329ad BS |
1050 | tcg_gen_andi_tl(reg, reg, 0x1); |
1051 | } | |
1052 | ||
1053 | // !0: FCC0 | FCC1 | |
1054 | static inline void gen_op_eval_fbne(TCGv dst, TCGv src, | |
1055 | unsigned int fcc_offset) | |
1056 | { | |
19f329ad | 1057 | gen_mov_reg_FCC0(dst, src, fcc_offset); |
0425bee5 BS |
1058 | gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset); |
1059 | tcg_gen_or_tl(dst, dst, cpu_tmp0); | |
19f329ad BS |
1060 | } |
1061 | ||
1062 | // 1 or 2: FCC0 ^ FCC1 | |
1063 | static inline void gen_op_eval_fblg(TCGv dst, TCGv src, | |
1064 | unsigned int fcc_offset) | |
1065 | { | |
19f329ad | 1066 | gen_mov_reg_FCC0(dst, src, fcc_offset); |
0425bee5 BS |
1067 | gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset); |
1068 | tcg_gen_xor_tl(dst, dst, cpu_tmp0); | |
19f329ad BS |
1069 | } |
1070 | ||
1071 | // 1 or 3: FCC0 | |
1072 | static inline void gen_op_eval_fbul(TCGv dst, TCGv src, | |
1073 | unsigned int fcc_offset) | |
1074 | { | |
1075 | gen_mov_reg_FCC0(dst, src, fcc_offset); | |
1076 | } | |
1077 | ||
1078 | // 1: FCC0 & !FCC1 | |
1079 | static inline void gen_op_eval_fbl(TCGv dst, TCGv src, | |
1080 | unsigned int fcc_offset) | |
1081 | { | |
19f329ad | 1082 | gen_mov_reg_FCC0(dst, src, fcc_offset); |
0425bee5 BS |
1083 | gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset); |
1084 | tcg_gen_xori_tl(cpu_tmp0, cpu_tmp0, 0x1); | |
1085 | tcg_gen_and_tl(dst, dst, cpu_tmp0); | |
19f329ad BS |
1086 | } |
1087 | ||
1088 | // 2 or 3: FCC1 | |
1089 | static inline void gen_op_eval_fbug(TCGv dst, TCGv src, | |
1090 | unsigned int fcc_offset) | |
1091 | { | |
1092 | gen_mov_reg_FCC1(dst, src, fcc_offset); | |
1093 | } | |
1094 | ||
1095 | // 2: !FCC0 & FCC1 | |
1096 | static inline void gen_op_eval_fbg(TCGv dst, TCGv src, | |
1097 | unsigned int fcc_offset) | |
1098 | { | |
19f329ad BS |
1099 | gen_mov_reg_FCC0(dst, src, fcc_offset); |
1100 | tcg_gen_xori_tl(dst, dst, 0x1); | |
0425bee5 BS |
1101 | gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset); |
1102 | tcg_gen_and_tl(dst, dst, cpu_tmp0); | |
19f329ad BS |
1103 | } |
1104 | ||
1105 | // 3: FCC0 & FCC1 | |
1106 | static inline void gen_op_eval_fbu(TCGv dst, TCGv src, | |
1107 | unsigned int fcc_offset) | |
1108 | { | |
19f329ad | 1109 | gen_mov_reg_FCC0(dst, src, fcc_offset); |
0425bee5 BS |
1110 | gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset); |
1111 | tcg_gen_and_tl(dst, dst, cpu_tmp0); | |
19f329ad BS |
1112 | } |
1113 | ||
1114 | // 0: !(FCC0 | FCC1) | |
1115 | static inline void gen_op_eval_fbe(TCGv dst, TCGv src, | |
1116 | unsigned int fcc_offset) | |
1117 | { | |
19f329ad | 1118 | gen_mov_reg_FCC0(dst, src, fcc_offset); |
0425bee5 BS |
1119 | gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset); |
1120 | tcg_gen_or_tl(dst, dst, cpu_tmp0); | |
19f329ad BS |
1121 | tcg_gen_xori_tl(dst, dst, 0x1); |
1122 | } | |
1123 | ||
1124 | // 0 or 3: !(FCC0 ^ FCC1) | |
1125 | static inline void gen_op_eval_fbue(TCGv dst, TCGv src, | |
1126 | unsigned int fcc_offset) | |
1127 | { | |
19f329ad | 1128 | gen_mov_reg_FCC0(dst, src, fcc_offset); |
0425bee5 BS |
1129 | gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset); |
1130 | tcg_gen_xor_tl(dst, dst, cpu_tmp0); | |
19f329ad BS |
1131 | tcg_gen_xori_tl(dst, dst, 0x1); |
1132 | } | |
1133 | ||
1134 | // 0 or 2: !FCC0 | |
1135 | static inline void gen_op_eval_fbge(TCGv dst, TCGv src, | |
1136 | unsigned int fcc_offset) | |
1137 | { | |
1138 | gen_mov_reg_FCC0(dst, src, fcc_offset); | |
1139 | tcg_gen_xori_tl(dst, dst, 0x1); | |
1140 | } | |
1141 | ||
1142 | // !1: !(FCC0 & !FCC1) | |
1143 | static inline void gen_op_eval_fbuge(TCGv dst, TCGv src, | |
1144 | unsigned int fcc_offset) | |
1145 | { | |
19f329ad | 1146 | gen_mov_reg_FCC0(dst, src, fcc_offset); |
0425bee5 BS |
1147 | gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset); |
1148 | tcg_gen_xori_tl(cpu_tmp0, cpu_tmp0, 0x1); | |
1149 | tcg_gen_and_tl(dst, dst, cpu_tmp0); | |
19f329ad BS |
1150 | tcg_gen_xori_tl(dst, dst, 0x1); |
1151 | } | |
1152 | ||
1153 | // 0 or 1: !FCC1 | |
1154 | static inline void gen_op_eval_fble(TCGv dst, TCGv src, | |
1155 | unsigned int fcc_offset) | |
1156 | { | |
1157 | gen_mov_reg_FCC1(dst, src, fcc_offset); | |
1158 | tcg_gen_xori_tl(dst, dst, 0x1); | |
1159 | } | |
1160 | ||
1161 | // !2: !(!FCC0 & FCC1) | |
1162 | static inline void gen_op_eval_fbule(TCGv dst, TCGv src, | |
1163 | unsigned int fcc_offset) | |
1164 | { | |
19f329ad BS |
1165 | gen_mov_reg_FCC0(dst, src, fcc_offset); |
1166 | tcg_gen_xori_tl(dst, dst, 0x1); | |
0425bee5 BS |
1167 | gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset); |
1168 | tcg_gen_and_tl(dst, dst, cpu_tmp0); | |
19f329ad BS |
1169 | tcg_gen_xori_tl(dst, dst, 0x1); |
1170 | } | |
1171 | ||
1172 | // !3: !(FCC0 & FCC1) | |
1173 | static inline void gen_op_eval_fbo(TCGv dst, TCGv src, | |
1174 | unsigned int fcc_offset) | |
1175 | { | |
19f329ad | 1176 | gen_mov_reg_FCC0(dst, src, fcc_offset); |
0425bee5 BS |
1177 | gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset); |
1178 | tcg_gen_and_tl(dst, dst, cpu_tmp0); | |
19f329ad BS |
1179 | tcg_gen_xori_tl(dst, dst, 0x1); |
1180 | } | |
1181 | ||
46525e1f | 1182 | static inline void gen_branch2(DisasContext *dc, target_ulong pc1, |
19f329ad | 1183 | target_ulong pc2, TCGv r_cond) |
83469015 FB |
1184 | { |
1185 | int l1; | |
1186 | ||
1187 | l1 = gen_new_label(); | |
1188 | ||
0425bee5 | 1189 | tcg_gen_brcond_tl(TCG_COND_EQ, r_cond, tcg_const_tl(0), l1); |
83469015 | 1190 | |
6e256c93 | 1191 | gen_goto_tb(dc, 0, pc1, pc1 + 4); |
83469015 FB |
1192 | |
1193 | gen_set_label(l1); | |
6e256c93 | 1194 | gen_goto_tb(dc, 1, pc2, pc2 + 4); |
83469015 FB |
1195 | } |
1196 | ||
46525e1f | 1197 | static inline void gen_branch_a(DisasContext *dc, target_ulong pc1, |
19f329ad | 1198 | target_ulong pc2, TCGv r_cond) |
83469015 FB |
1199 | { |
1200 | int l1; | |
1201 | ||
1202 | l1 = gen_new_label(); | |
1203 | ||
0425bee5 | 1204 | tcg_gen_brcond_tl(TCG_COND_EQ, r_cond, tcg_const_tl(0), l1); |
83469015 | 1205 | |
6e256c93 | 1206 | gen_goto_tb(dc, 0, pc2, pc1); |
83469015 FB |
1207 | |
1208 | gen_set_label(l1); | |
6e256c93 | 1209 | gen_goto_tb(dc, 1, pc2 + 4, pc2 + 8); |
83469015 FB |
1210 | } |
1211 | ||
46525e1f BS |
1212 | static inline void gen_branch(DisasContext *dc, target_ulong pc, |
1213 | target_ulong npc) | |
83469015 | 1214 | { |
6e256c93 | 1215 | gen_goto_tb(dc, 0, pc, npc); |
83469015 FB |
1216 | } |
1217 | ||
19f329ad BS |
1218 | static inline void gen_generic_branch(target_ulong npc1, target_ulong npc2, |
1219 | TCGv r_cond) | |
83469015 FB |
1220 | { |
1221 | int l1, l2; | |
1222 | ||
1223 | l1 = gen_new_label(); | |
1224 | l2 = gen_new_label(); | |
19f329ad | 1225 | |
0425bee5 | 1226 | tcg_gen_brcond_tl(TCG_COND_EQ, r_cond, tcg_const_tl(0), l1); |
83469015 FB |
1227 | |
1228 | gen_movl_npc_im(npc1); | |
06b3e1b3 | 1229 | tcg_gen_br(l2); |
83469015 FB |
1230 | |
1231 | gen_set_label(l1); | |
1232 | gen_movl_npc_im(npc2); | |
1233 | gen_set_label(l2); | |
1234 | } | |
1235 | ||
1236 | /* call this function before using T2 as it may have been set for a jump */ | |
1237 | static inline void flush_T2(DisasContext * dc) | |
1238 | { | |
1239 | if (dc->npc == JUMP_PC) { | |
19f329ad | 1240 | gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cpu_T[2]); |
83469015 FB |
1241 | dc->npc = DYNAMIC_PC; |
1242 | } | |
1243 | } | |
1244 | ||
72cbca10 FB |
1245 | static inline void save_npc(DisasContext * dc) |
1246 | { | |
1247 | if (dc->npc == JUMP_PC) { | |
19f329ad | 1248 | gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cpu_T[2]); |
72cbca10 FB |
1249 | dc->npc = DYNAMIC_PC; |
1250 | } else if (dc->npc != DYNAMIC_PC) { | |
3475187d | 1251 | gen_movl_npc_im(dc->npc); |
72cbca10 FB |
1252 | } |
1253 | } | |
1254 | ||
1255 | static inline void save_state(DisasContext * dc) | |
1256 | { | |
3475187d | 1257 | gen_jmp_im(dc->pc); |
72cbca10 FB |
1258 | save_npc(dc); |
1259 | } | |
1260 | ||
0bee699e FB |
1261 | static inline void gen_mov_pc_npc(DisasContext * dc) |
1262 | { | |
1263 | if (dc->npc == JUMP_PC) { | |
19f329ad | 1264 | gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cpu_T[2]); |
48d5c82b | 1265 | tcg_gen_mov_tl(cpu_pc, cpu_npc); |
0bee699e FB |
1266 | dc->pc = DYNAMIC_PC; |
1267 | } else if (dc->npc == DYNAMIC_PC) { | |
48d5c82b | 1268 | tcg_gen_mov_tl(cpu_pc, cpu_npc); |
0bee699e FB |
1269 | dc->pc = DYNAMIC_PC; |
1270 | } else { | |
1271 | dc->pc = dc->npc; | |
1272 | } | |
1273 | } | |
1274 | ||
38bc628b BS |
1275 | static inline void gen_op_next_insn(void) |
1276 | { | |
48d5c82b BS |
1277 | tcg_gen_mov_tl(cpu_pc, cpu_npc); |
1278 | tcg_gen_addi_tl(cpu_npc, cpu_npc, 4); | |
38bc628b BS |
1279 | } |
1280 | ||
19f329ad BS |
1281 | static inline void gen_cond(TCGv r_dst, unsigned int cc, unsigned int cond) |
1282 | { | |
1283 | TCGv r_src; | |
3475187d | 1284 | |
3475187d | 1285 | #ifdef TARGET_SPARC64 |
19f329ad | 1286 | if (cc) |
dc99a3f2 | 1287 | r_src = cpu_xcc; |
19f329ad | 1288 | else |
dc99a3f2 | 1289 | r_src = cpu_psr; |
3475187d | 1290 | #else |
dc99a3f2 | 1291 | r_src = cpu_psr; |
3475187d | 1292 | #endif |
19f329ad BS |
1293 | switch (cond) { |
1294 | case 0x0: | |
1295 | gen_op_eval_bn(r_dst); | |
1296 | break; | |
1297 | case 0x1: | |
1298 | gen_op_eval_be(r_dst, r_src); | |
1299 | break; | |
1300 | case 0x2: | |
1301 | gen_op_eval_ble(r_dst, r_src); | |
1302 | break; | |
1303 | case 0x3: | |
1304 | gen_op_eval_bl(r_dst, r_src); | |
1305 | break; | |
1306 | case 0x4: | |
1307 | gen_op_eval_bleu(r_dst, r_src); | |
1308 | break; | |
1309 | case 0x5: | |
1310 | gen_op_eval_bcs(r_dst, r_src); | |
1311 | break; | |
1312 | case 0x6: | |
1313 | gen_op_eval_bneg(r_dst, r_src); | |
1314 | break; | |
1315 | case 0x7: | |
1316 | gen_op_eval_bvs(r_dst, r_src); | |
1317 | break; | |
1318 | case 0x8: | |
1319 | gen_op_eval_ba(r_dst); | |
1320 | break; | |
1321 | case 0x9: | |
1322 | gen_op_eval_bne(r_dst, r_src); | |
1323 | break; | |
1324 | case 0xa: | |
1325 | gen_op_eval_bg(r_dst, r_src); | |
1326 | break; | |
1327 | case 0xb: | |
1328 | gen_op_eval_bge(r_dst, r_src); | |
1329 | break; | |
1330 | case 0xc: | |
1331 | gen_op_eval_bgu(r_dst, r_src); | |
1332 | break; | |
1333 | case 0xd: | |
1334 | gen_op_eval_bcc(r_dst, r_src); | |
1335 | break; | |
1336 | case 0xe: | |
1337 | gen_op_eval_bpos(r_dst, r_src); | |
1338 | break; | |
1339 | case 0xf: | |
1340 | gen_op_eval_bvc(r_dst, r_src); | |
1341 | break; | |
1342 | } | |
1343 | } | |
7a3f1944 | 1344 | |
19f329ad | 1345 | static inline void gen_fcond(TCGv r_dst, unsigned int cc, unsigned int cond) |
e8af50a3 | 1346 | { |
19f329ad BS |
1347 | unsigned int offset; |
1348 | ||
19f329ad BS |
1349 | switch (cc) { |
1350 | default: | |
1351 | case 0x0: | |
1352 | offset = 0; | |
1353 | break; | |
1354 | case 0x1: | |
1355 | offset = 32 - 10; | |
1356 | break; | |
1357 | case 0x2: | |
1358 | offset = 34 - 10; | |
1359 | break; | |
1360 | case 0x3: | |
1361 | offset = 36 - 10; | |
1362 | break; | |
1363 | } | |
1364 | ||
1365 | switch (cond) { | |
1366 | case 0x0: | |
1367 | gen_op_eval_bn(r_dst); | |
1368 | break; | |
1369 | case 0x1: | |
87e92502 | 1370 | gen_op_eval_fbne(r_dst, cpu_fsr, offset); |
19f329ad BS |
1371 | break; |
1372 | case 0x2: | |
87e92502 | 1373 | gen_op_eval_fblg(r_dst, cpu_fsr, offset); |
19f329ad BS |
1374 | break; |
1375 | case 0x3: | |
87e92502 | 1376 | gen_op_eval_fbul(r_dst, cpu_fsr, offset); |
19f329ad BS |
1377 | break; |
1378 | case 0x4: | |
87e92502 | 1379 | gen_op_eval_fbl(r_dst, cpu_fsr, offset); |
19f329ad BS |
1380 | break; |
1381 | case 0x5: | |
87e92502 | 1382 | gen_op_eval_fbug(r_dst, cpu_fsr, offset); |
19f329ad BS |
1383 | break; |
1384 | case 0x6: | |
87e92502 | 1385 | gen_op_eval_fbg(r_dst, cpu_fsr, offset); |
19f329ad BS |
1386 | break; |
1387 | case 0x7: | |
87e92502 | 1388 | gen_op_eval_fbu(r_dst, cpu_fsr, offset); |
19f329ad BS |
1389 | break; |
1390 | case 0x8: | |
1391 | gen_op_eval_ba(r_dst); | |
1392 | break; | |
1393 | case 0x9: | |
87e92502 | 1394 | gen_op_eval_fbe(r_dst, cpu_fsr, offset); |
19f329ad BS |
1395 | break; |
1396 | case 0xa: | |
87e92502 | 1397 | gen_op_eval_fbue(r_dst, cpu_fsr, offset); |
19f329ad BS |
1398 | break; |
1399 | case 0xb: | |
87e92502 | 1400 | gen_op_eval_fbge(r_dst, cpu_fsr, offset); |
19f329ad BS |
1401 | break; |
1402 | case 0xc: | |
87e92502 | 1403 | gen_op_eval_fbuge(r_dst, cpu_fsr, offset); |
19f329ad BS |
1404 | break; |
1405 | case 0xd: | |
87e92502 | 1406 | gen_op_eval_fble(r_dst, cpu_fsr, offset); |
19f329ad BS |
1407 | break; |
1408 | case 0xe: | |
87e92502 | 1409 | gen_op_eval_fbule(r_dst, cpu_fsr, offset); |
19f329ad BS |
1410 | break; |
1411 | case 0xf: | |
87e92502 | 1412 | gen_op_eval_fbo(r_dst, cpu_fsr, offset); |
19f329ad BS |
1413 | break; |
1414 | } | |
e8af50a3 | 1415 | } |
00f219bf | 1416 | |
19f329ad | 1417 | #ifdef TARGET_SPARC64 |
00f219bf BS |
1418 | // Inverted logic |
1419 | static const int gen_tcg_cond_reg[8] = { | |
1420 | -1, | |
1421 | TCG_COND_NE, | |
1422 | TCG_COND_GT, | |
1423 | TCG_COND_GE, | |
1424 | -1, | |
1425 | TCG_COND_EQ, | |
1426 | TCG_COND_LE, | |
1427 | TCG_COND_LT, | |
1428 | }; | |
19f329ad BS |
1429 | |
1430 | static inline void gen_cond_reg(TCGv r_dst, int cond) | |
1431 | { | |
19f329ad BS |
1432 | int l1; |
1433 | ||
1434 | l1 = gen_new_label(); | |
0425bee5 BS |
1435 | tcg_gen_movi_tl(r_dst, 0); |
1436 | tcg_gen_brcond_tl(gen_tcg_cond_reg[cond], cpu_T[0], tcg_const_tl(0), l1); | |
19f329ad BS |
1437 | tcg_gen_movi_tl(r_dst, 1); |
1438 | gen_set_label(l1); | |
1439 | } | |
3475187d | 1440 | #endif |
cf495bcf | 1441 | |
0bee699e | 1442 | /* XXX: potentially incorrect if dynamic npc */ |
3475187d | 1443 | static void do_branch(DisasContext * dc, int32_t offset, uint32_t insn, int cc) |
7a3f1944 | 1444 | { |
cf495bcf | 1445 | unsigned int cond = GET_FIELD(insn, 3, 6), a = (insn & (1 << 29)); |
af7bf89b | 1446 | target_ulong target = dc->pc + offset; |
5fafdf24 | 1447 | |
cf495bcf | 1448 | if (cond == 0x0) { |
0f8a249a BS |
1449 | /* unconditional not taken */ |
1450 | if (a) { | |
1451 | dc->pc = dc->npc + 4; | |
1452 | dc->npc = dc->pc + 4; | |
1453 | } else { | |
1454 | dc->pc = dc->npc; | |
1455 | dc->npc = dc->pc + 4; | |
1456 | } | |
cf495bcf | 1457 | } else if (cond == 0x8) { |
0f8a249a BS |
1458 | /* unconditional taken */ |
1459 | if (a) { | |
1460 | dc->pc = target; | |
1461 | dc->npc = dc->pc + 4; | |
1462 | } else { | |
1463 | dc->pc = dc->npc; | |
1464 | dc->npc = target; | |
1465 | } | |
cf495bcf | 1466 | } else { |
72cbca10 | 1467 | flush_T2(dc); |
19f329ad | 1468 | gen_cond(cpu_T[2], cc, cond); |
0f8a249a | 1469 | if (a) { |
19f329ad | 1470 | gen_branch_a(dc, target, dc->npc, cpu_T[2]); |
cf495bcf | 1471 | dc->is_br = 1; |
0f8a249a | 1472 | } else { |
cf495bcf | 1473 | dc->pc = dc->npc; |
72cbca10 FB |
1474 | dc->jump_pc[0] = target; |
1475 | dc->jump_pc[1] = dc->npc + 4; | |
1476 | dc->npc = JUMP_PC; | |
0f8a249a | 1477 | } |
cf495bcf | 1478 | } |
7a3f1944 FB |
1479 | } |
1480 | ||
0bee699e | 1481 | /* XXX: potentially incorrect if dynamic npc */ |
3475187d | 1482 | static void do_fbranch(DisasContext * dc, int32_t offset, uint32_t insn, int cc) |
e8af50a3 FB |
1483 | { |
1484 | unsigned int cond = GET_FIELD(insn, 3, 6), a = (insn & (1 << 29)); | |
af7bf89b FB |
1485 | target_ulong target = dc->pc + offset; |
1486 | ||
e8af50a3 | 1487 | if (cond == 0x0) { |
0f8a249a BS |
1488 | /* unconditional not taken */ |
1489 | if (a) { | |
1490 | dc->pc = dc->npc + 4; | |
1491 | dc->npc = dc->pc + 4; | |
1492 | } else { | |
1493 | dc->pc = dc->npc; | |
1494 | dc->npc = dc->pc + 4; | |
1495 | } | |
e8af50a3 | 1496 | } else if (cond == 0x8) { |
0f8a249a BS |
1497 | /* unconditional taken */ |
1498 | if (a) { | |
1499 | dc->pc = target; | |
1500 | dc->npc = dc->pc + 4; | |
1501 | } else { | |
1502 | dc->pc = dc->npc; | |
1503 | dc->npc = target; | |
1504 | } | |
e8af50a3 FB |
1505 | } else { |
1506 | flush_T2(dc); | |
19f329ad | 1507 | gen_fcond(cpu_T[2], cc, cond); |
0f8a249a | 1508 | if (a) { |
19f329ad | 1509 | gen_branch_a(dc, target, dc->npc, cpu_T[2]); |
e8af50a3 | 1510 | dc->is_br = 1; |
0f8a249a | 1511 | } else { |
e8af50a3 FB |
1512 | dc->pc = dc->npc; |
1513 | dc->jump_pc[0] = target; | |
1514 | dc->jump_pc[1] = dc->npc + 4; | |
1515 | dc->npc = JUMP_PC; | |
0f8a249a | 1516 | } |
e8af50a3 FB |
1517 | } |
1518 | } | |
1519 | ||
3475187d FB |
1520 | #ifdef TARGET_SPARC64 |
1521 | /* XXX: potentially incorrect if dynamic npc */ | |
1522 | static void do_branch_reg(DisasContext * dc, int32_t offset, uint32_t insn) | |
7a3f1944 | 1523 | { |
3475187d FB |
1524 | unsigned int cond = GET_FIELD_SP(insn, 25, 27), a = (insn & (1 << 29)); |
1525 | target_ulong target = dc->pc + offset; | |
1526 | ||
1527 | flush_T2(dc); | |
19f329ad | 1528 | gen_cond_reg(cpu_T[2], cond); |
3475187d | 1529 | if (a) { |
19f329ad | 1530 | gen_branch_a(dc, target, dc->npc, cpu_T[2]); |
0f8a249a | 1531 | dc->is_br = 1; |
3475187d | 1532 | } else { |
0f8a249a BS |
1533 | dc->pc = dc->npc; |
1534 | dc->jump_pc[0] = target; | |
1535 | dc->jump_pc[1] = dc->npc + 4; | |
1536 | dc->npc = JUMP_PC; | |
3475187d | 1537 | } |
7a3f1944 FB |
1538 | } |
1539 | ||
3475187d | 1540 | static GenOpFunc * const gen_fcmps[4] = { |
7e8c2b6c BS |
1541 | helper_fcmps, |
1542 | helper_fcmps_fcc1, | |
1543 | helper_fcmps_fcc2, | |
1544 | helper_fcmps_fcc3, | |
3475187d FB |
1545 | }; |
1546 | ||
1547 | static GenOpFunc * const gen_fcmpd[4] = { | |
7e8c2b6c BS |
1548 | helper_fcmpd, |
1549 | helper_fcmpd_fcc1, | |
1550 | helper_fcmpd_fcc2, | |
1551 | helper_fcmpd_fcc3, | |
3475187d | 1552 | }; |
417454b0 | 1553 | |
1f587329 BS |
1554 | #if defined(CONFIG_USER_ONLY) |
1555 | static GenOpFunc * const gen_fcmpq[4] = { | |
7e8c2b6c BS |
1556 | helper_fcmpq, |
1557 | helper_fcmpq_fcc1, | |
1558 | helper_fcmpq_fcc2, | |
1559 | helper_fcmpq_fcc3, | |
1f587329 BS |
1560 | }; |
1561 | #endif | |
1562 | ||
417454b0 | 1563 | static GenOpFunc * const gen_fcmpes[4] = { |
7e8c2b6c BS |
1564 | helper_fcmpes, |
1565 | helper_fcmpes_fcc1, | |
1566 | helper_fcmpes_fcc2, | |
1567 | helper_fcmpes_fcc3, | |
417454b0 BS |
1568 | }; |
1569 | ||
1570 | static GenOpFunc * const gen_fcmped[4] = { | |
7e8c2b6c BS |
1571 | helper_fcmped, |
1572 | helper_fcmped_fcc1, | |
1573 | helper_fcmped_fcc2, | |
1574 | helper_fcmped_fcc3, | |
417454b0 BS |
1575 | }; |
1576 | ||
1f587329 BS |
1577 | #if defined(CONFIG_USER_ONLY) |
1578 | static GenOpFunc * const gen_fcmpeq[4] = { | |
7e8c2b6c BS |
1579 | helper_fcmpeq, |
1580 | helper_fcmpeq_fcc1, | |
1581 | helper_fcmpeq_fcc2, | |
1582 | helper_fcmpeq_fcc3, | |
1f587329 BS |
1583 | }; |
1584 | #endif | |
7e8c2b6c BS |
1585 | |
1586 | static inline void gen_op_fcmps(int fccno) | |
1587 | { | |
1588 | tcg_gen_helper_0_0(gen_fcmps[fccno]); | |
1589 | } | |
1590 | ||
1591 | static inline void gen_op_fcmpd(int fccno) | |
1592 | { | |
1593 | tcg_gen_helper_0_0(gen_fcmpd[fccno]); | |
1594 | } | |
1595 | ||
1596 | #if defined(CONFIG_USER_ONLY) | |
1597 | static inline void gen_op_fcmpq(int fccno) | |
1598 | { | |
1599 | tcg_gen_helper_0_0(gen_fcmpq[fccno]); | |
1600 | } | |
1601 | #endif | |
1602 | ||
1603 | static inline void gen_op_fcmpes(int fccno) | |
1604 | { | |
1605 | tcg_gen_helper_0_0(gen_fcmpes[fccno]); | |
1606 | } | |
1607 | ||
1608 | static inline void gen_op_fcmped(int fccno) | |
1609 | { | |
1610 | tcg_gen_helper_0_0(gen_fcmped[fccno]); | |
1611 | } | |
1612 | ||
1613 | #if defined(CONFIG_USER_ONLY) | |
1614 | static inline void gen_op_fcmpeq(int fccno) | |
1615 | { | |
1616 | tcg_gen_helper_0_0(gen_fcmpeq[fccno]); | |
1617 | } | |
1618 | #endif | |
1619 | ||
1620 | #else | |
1621 | ||
1622 | static inline void gen_op_fcmps(int fccno) | |
1623 | { | |
1624 | tcg_gen_helper_0_0(helper_fcmps); | |
1625 | } | |
1626 | ||
1627 | static inline void gen_op_fcmpd(int fccno) | |
1628 | { | |
1629 | tcg_gen_helper_0_0(helper_fcmpd); | |
1630 | } | |
1631 | ||
1632 | #if defined(CONFIG_USER_ONLY) | |
1633 | static inline void gen_op_fcmpq(int fccno) | |
1634 | { | |
1635 | tcg_gen_helper_0_0(helper_fcmpq); | |
1636 | } | |
1637 | #endif | |
1638 | ||
1639 | static inline void gen_op_fcmpes(int fccno) | |
1640 | { | |
1641 | tcg_gen_helper_0_0(helper_fcmpes); | |
1642 | } | |
1643 | ||
1644 | static inline void gen_op_fcmped(int fccno) | |
1645 | { | |
1646 | tcg_gen_helper_0_0(helper_fcmped); | |
1647 | } | |
1648 | ||
1649 | #if defined(CONFIG_USER_ONLY) | |
1650 | static inline void gen_op_fcmpeq(int fccno) | |
1651 | { | |
1652 | tcg_gen_helper_0_0(helper_fcmpeq); | |
1653 | } | |
1654 | #endif | |
1655 | ||
3475187d FB |
1656 | #endif |
1657 | ||
134d77a1 BS |
1658 | static inline void gen_op_fpexception_im(int fsr_flags) |
1659 | { | |
87e92502 BS |
1660 | tcg_gen_andi_tl(cpu_fsr, cpu_fsr, ~FSR_FTT_MASK); |
1661 | tcg_gen_ori_tl(cpu_fsr, cpu_fsr, fsr_flags); | |
134d77a1 BS |
1662 | gen_op_exception(TT_FP_EXCP); |
1663 | } | |
1664 | ||
a80dde08 FB |
1665 | static int gen_trap_ifnofpu(DisasContext * dc) |
1666 | { | |
1667 | #if !defined(CONFIG_USER_ONLY) | |
1668 | if (!dc->fpu_enabled) { | |
1669 | save_state(dc); | |
1670 | gen_op_exception(TT_NFPU_INSN); | |
1671 | dc->is_br = 1; | |
1672 | return 1; | |
1673 | } | |
1674 | #endif | |
1675 | return 0; | |
1676 | } | |
1677 | ||
7e8c2b6c BS |
1678 | static inline void gen_op_clear_ieee_excp_and_FTT(void) |
1679 | { | |
87e92502 | 1680 | tcg_gen_andi_tl(cpu_fsr, cpu_fsr, ~(FSR_FTT_MASK | FSR_CEXC_MASK)); |
7e8c2b6c BS |
1681 | } |
1682 | ||
1683 | static inline void gen_clear_float_exceptions(void) | |
1684 | { | |
1685 | tcg_gen_helper_0_0(helper_clear_float_exceptions); | |
1686 | } | |
1687 | ||
2b29924f BS |
1688 | static inline void gen_check_align(TCGv r_addr, int align) |
1689 | { | |
1690 | tcg_gen_helper_0_2(helper_check_align, r_addr, tcg_const_i32(align)); | |
1691 | } | |
1692 | ||
1693 | static inline void gen_op_check_align_T0_1(void) | |
1694 | { | |
1695 | gen_check_align(cpu_T[0], 1); | |
1696 | } | |
1697 | ||
1698 | static inline void gen_op_check_align_T0_3(void) | |
1699 | { | |
1700 | gen_check_align(cpu_T[0], 3); | |
1701 | } | |
1702 | ||
1703 | static inline void gen_op_check_align_T0_7(void) | |
1704 | { | |
1705 | gen_check_align(cpu_T[0], 7); | |
1706 | } | |
1707 | ||
1a2fb1c0 BS |
1708 | /* asi moves */ |
1709 | #ifdef TARGET_SPARC64 | |
0425bee5 | 1710 | static inline TCGv gen_get_asi(int insn, TCGv r_addr) |
1a2fb1c0 BS |
1711 | { |
1712 | int asi, offset; | |
0425bee5 | 1713 | TCGv r_asi; |
1a2fb1c0 | 1714 | |
1a2fb1c0 | 1715 | if (IS_IMM) { |
0425bee5 | 1716 | r_asi = tcg_temp_new(TCG_TYPE_I32); |
1a2fb1c0 | 1717 | offset = GET_FIELD(insn, 25, 31); |
0425bee5 BS |
1718 | tcg_gen_addi_tl(r_addr, r_addr, offset); |
1719 | tcg_gen_ld_i32(r_asi, cpu_env, offsetof(CPUSPARCState, asi)); | |
1a2fb1c0 BS |
1720 | } else { |
1721 | asi = GET_FIELD(insn, 19, 26); | |
0425bee5 | 1722 | r_asi = tcg_const_i32(asi); |
1a2fb1c0 | 1723 | } |
0425bee5 BS |
1724 | return r_asi; |
1725 | } | |
1726 | ||
1727 | static inline void gen_ld_asi(int insn, int size, int sign) | |
1728 | { | |
1729 | TCGv r_asi; | |
1730 | ||
1731 | r_asi = gen_get_asi(insn, cpu_T[0]); | |
1732 | tcg_gen_helper_1_4(helper_ld_asi, cpu_T[1], cpu_T[0], r_asi, | |
1733 | tcg_const_i32(size), tcg_const_i32(sign)); | |
1734 | tcg_gen_discard_i32(r_asi); | |
1a2fb1c0 BS |
1735 | } |
1736 | ||
1737 | static inline void gen_st_asi(int insn, int size) | |
1738 | { | |
0425bee5 | 1739 | TCGv r_asi; |
1a2fb1c0 | 1740 | |
0425bee5 BS |
1741 | r_asi = gen_get_asi(insn, cpu_T[0]); |
1742 | tcg_gen_helper_0_4(helper_st_asi, cpu_T[0], cpu_T[1], r_asi, | |
1743 | tcg_const_i32(size)); | |
1744 | tcg_gen_discard_i32(r_asi); | |
1a2fb1c0 BS |
1745 | } |
1746 | ||
1747 | static inline void gen_ldf_asi(int insn, int size, int rd) | |
1748 | { | |
0425bee5 | 1749 | TCGv r_asi; |
1a2fb1c0 | 1750 | |
0425bee5 BS |
1751 | r_asi = gen_get_asi(insn, cpu_T[0]); |
1752 | tcg_gen_helper_0_4(helper_ldf_asi, cpu_T[0], r_asi, tcg_const_i32(size), | |
1753 | tcg_const_i32(rd)); | |
1754 | tcg_gen_discard_i32(r_asi); | |
1a2fb1c0 BS |
1755 | } |
1756 | ||
1757 | static inline void gen_stf_asi(int insn, int size, int rd) | |
1758 | { | |
0425bee5 | 1759 | TCGv r_asi; |
1a2fb1c0 | 1760 | |
0425bee5 BS |
1761 | r_asi = gen_get_asi(insn, cpu_T[0]); |
1762 | tcg_gen_helper_0_4(helper_stf_asi, cpu_T[0], r_asi, tcg_const_i32(size), | |
1763 | tcg_const_i32(rd)); | |
1764 | tcg_gen_discard_i32(r_asi); | |
1a2fb1c0 BS |
1765 | } |
1766 | ||
1767 | static inline void gen_swap_asi(int insn) | |
1768 | { | |
0425bee5 | 1769 | TCGv r_temp, r_asi; |
1a2fb1c0 | 1770 | |
1a2fb1c0 | 1771 | r_temp = tcg_temp_new(TCG_TYPE_I32); |
0425bee5 BS |
1772 | r_asi = gen_get_asi(insn, cpu_T[0]); |
1773 | tcg_gen_helper_1_4(helper_ld_asi, r_temp, cpu_T[0], r_asi, | |
1774 | tcg_const_i32(4), tcg_const_i32(0)); | |
1775 | tcg_gen_helper_0_4(helper_st_asi, cpu_T[0], r_temp, r_asi, | |
1776 | tcg_const_i32(4)); | |
8911f501 | 1777 | tcg_gen_extu_i32_tl(cpu_T[1], r_temp); |
0425bee5 BS |
1778 | tcg_gen_discard_i32(r_asi); |
1779 | tcg_gen_discard_i32(r_temp); | |
1a2fb1c0 BS |
1780 | } |
1781 | ||
1782 | static inline void gen_ldda_asi(int insn) | |
1783 | { | |
8911f501 | 1784 | TCGv r_asi; |
1a2fb1c0 | 1785 | |
0425bee5 | 1786 | r_asi = gen_get_asi(insn, cpu_T[0]); |
8911f501 | 1787 | tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, cpu_T[0], r_asi, |
0425bee5 | 1788 | tcg_const_i32(8), tcg_const_i32(0)); |
8911f501 BS |
1789 | tcg_gen_andi_i64(cpu_T[0], cpu_tmp64, 0xffffffffULL); |
1790 | tcg_gen_shri_i64(cpu_tmp64, cpu_tmp64, 32); | |
1791 | tcg_gen_andi_i64(cpu_T[1], cpu_tmp64, 0xffffffffULL); | |
0425bee5 | 1792 | tcg_gen_discard_i32(r_asi); |
0425bee5 BS |
1793 | } |
1794 | ||
1795 | static inline void gen_stda_asi(int insn, int rd) | |
1796 | { | |
8911f501 | 1797 | TCGv r_temp, r_asi; |
0425bee5 | 1798 | |
0425bee5 BS |
1799 | r_temp = tcg_temp_new(TCG_TYPE_I32); |
1800 | gen_movl_reg_TN(rd + 1, r_temp); | |
8911f501 | 1801 | tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, cpu_T[1], |
0425bee5 BS |
1802 | r_temp); |
1803 | r_asi = gen_get_asi(insn, cpu_T[0]); | |
8911f501 | 1804 | tcg_gen_helper_0_4(helper_st_asi, cpu_T[0], cpu_tmp64, r_asi, |
0425bee5 BS |
1805 | tcg_const_i32(8)); |
1806 | tcg_gen_discard_i32(r_asi); | |
1807 | tcg_gen_discard_i32(r_temp); | |
1a2fb1c0 BS |
1808 | } |
1809 | ||
1810 | static inline void gen_cas_asi(int insn, int rd) | |
1811 | { | |
1a2fb1c0 BS |
1812 | TCGv r_val1, r_asi; |
1813 | ||
1814 | r_val1 = tcg_temp_new(TCG_TYPE_I32); | |
1a2fb1c0 | 1815 | gen_movl_reg_TN(rd, r_val1); |
0425bee5 | 1816 | r_asi = gen_get_asi(insn, cpu_T[0]); |
1a2fb1c0 BS |
1817 | tcg_gen_helper_1_4(helper_cas_asi, cpu_T[1], cpu_T[0], r_val1, cpu_T[1], |
1818 | r_asi); | |
0425bee5 BS |
1819 | tcg_gen_discard_i32(r_asi); |
1820 | tcg_gen_discard_i32(r_val1); | |
1a2fb1c0 BS |
1821 | } |
1822 | ||
1823 | static inline void gen_casx_asi(int insn, int rd) | |
1824 | { | |
8911f501 | 1825 | TCGv r_asi; |
1a2fb1c0 | 1826 | |
8911f501 | 1827 | gen_movl_reg_TN(rd, cpu_tmp64); |
0425bee5 | 1828 | r_asi = gen_get_asi(insn, cpu_T[0]); |
8911f501 | 1829 | tcg_gen_helper_1_4(helper_casx_asi, cpu_T[1], cpu_T[0], cpu_tmp64, cpu_T[1], |
1a2fb1c0 | 1830 | r_asi); |
0425bee5 | 1831 | tcg_gen_discard_i32(r_asi); |
1a2fb1c0 BS |
1832 | } |
1833 | ||
1834 | #elif !defined(CONFIG_USER_ONLY) | |
1835 | ||
1836 | static inline void gen_ld_asi(int insn, int size, int sign) | |
1837 | { | |
1838 | int asi; | |
1a2fb1c0 | 1839 | |
1a2fb1c0 | 1840 | asi = GET_FIELD(insn, 19, 26); |
8911f501 | 1841 | tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, cpu_T[0], tcg_const_i32(asi), |
0425bee5 | 1842 | tcg_const_i32(size), tcg_const_i32(sign)); |
8911f501 | 1843 | tcg_gen_trunc_i64_tl(cpu_T[1], cpu_tmp64); |
1a2fb1c0 BS |
1844 | } |
1845 | ||
1846 | static inline void gen_st_asi(int insn, int size) | |
1847 | { | |
1848 | int asi; | |
1a2fb1c0 | 1849 | |
8911f501 | 1850 | tcg_gen_extu_tl_i64(cpu_tmp64, cpu_T[1]); |
1a2fb1c0 | 1851 | asi = GET_FIELD(insn, 19, 26); |
8911f501 | 1852 | tcg_gen_helper_0_4(helper_st_asi, cpu_T[0], cpu_tmp64, tcg_const_i32(asi), |
0425bee5 | 1853 | tcg_const_i32(size)); |
1a2fb1c0 BS |
1854 | } |
1855 | ||
1856 | static inline void gen_swap_asi(int insn) | |
1857 | { | |
1858 | int asi; | |
0425bee5 | 1859 | TCGv r_temp; |
1a2fb1c0 | 1860 | |
1a2fb1c0 | 1861 | r_temp = tcg_temp_new(TCG_TYPE_I32); |
1a2fb1c0 | 1862 | asi = GET_FIELD(insn, 19, 26); |
0425bee5 BS |
1863 | tcg_gen_helper_1_4(helper_ld_asi, r_temp, cpu_T[0], tcg_const_i32(asi), |
1864 | tcg_const_i32(4), tcg_const_i32(0)); | |
1865 | tcg_gen_helper_0_4(helper_st_asi, cpu_T[0], cpu_T[1], tcg_const_i32(asi), | |
1866 | tcg_const_i32(4)); | |
8911f501 | 1867 | tcg_gen_extu_i32_tl(cpu_T[1], r_temp); |
0425bee5 | 1868 | tcg_gen_discard_i32(r_temp); |
1a2fb1c0 BS |
1869 | } |
1870 | ||
1871 | static inline void gen_ldda_asi(int insn) | |
1872 | { | |
1873 | int asi; | |
1a2fb1c0 | 1874 | |
1a2fb1c0 | 1875 | asi = GET_FIELD(insn, 19, 26); |
8911f501 | 1876 | tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, cpu_T[0], tcg_const_i32(asi), |
0425bee5 | 1877 | tcg_const_i32(8), tcg_const_i32(0)); |
8911f501 BS |
1878 | tcg_gen_trunc_i64_tl(cpu_T[0], cpu_tmp64); |
1879 | tcg_gen_shri_i64(cpu_tmp64, cpu_tmp64, 32); | |
1880 | tcg_gen_trunc_i64_tl(cpu_T[1], cpu_tmp64); | |
0425bee5 BS |
1881 | } |
1882 | ||
1883 | static inline void gen_stda_asi(int insn, int rd) | |
1884 | { | |
1885 | int asi; | |
8911f501 | 1886 | TCGv r_temp; |
0425bee5 | 1887 | |
0425bee5 BS |
1888 | r_temp = tcg_temp_new(TCG_TYPE_I32); |
1889 | gen_movl_reg_TN(rd + 1, r_temp); | |
8911f501 | 1890 | tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, cpu_T[1], r_temp); |
0425bee5 | 1891 | asi = GET_FIELD(insn, 19, 26); |
8911f501 | 1892 | tcg_gen_helper_0_4(helper_st_asi, cpu_T[0], cpu_tmp64, tcg_const_i32(asi), |
0425bee5 | 1893 | tcg_const_i32(8)); |
1a2fb1c0 BS |
1894 | } |
1895 | #endif | |
1896 | ||
1897 | #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64) | |
1898 | static inline void gen_ldstub_asi(int insn) | |
1899 | { | |
1900 | int asi; | |
1a2fb1c0 BS |
1901 | |
1902 | gen_ld_asi(insn, 1, 0); | |
1903 | ||
1a2fb1c0 | 1904 | asi = GET_FIELD(insn, 19, 26); |
8911f501 | 1905 | tcg_gen_helper_0_4(helper_st_asi, cpu_T[0], tcg_const_i64(0xffULL), |
0425bee5 | 1906 | tcg_const_i32(asi), tcg_const_i32(1)); |
1a2fb1c0 BS |
1907 | } |
1908 | #endif | |
1909 | ||
0bee699e | 1910 | /* before an instruction, dc->pc must be static */ |
cf495bcf FB |
1911 | static void disas_sparc_insn(DisasContext * dc) |
1912 | { | |
1913 | unsigned int insn, opc, rs1, rs2, rd; | |
7a3f1944 | 1914 | |
0fa85d43 | 1915 | insn = ldl_code(dc->pc); |
cf495bcf | 1916 | opc = GET_FIELD(insn, 0, 1); |
7a3f1944 | 1917 | |
cf495bcf FB |
1918 | rd = GET_FIELD(insn, 2, 6); |
1919 | switch (opc) { | |
0f8a249a BS |
1920 | case 0: /* branches/sethi */ |
1921 | { | |
1922 | unsigned int xop = GET_FIELD(insn, 7, 9); | |
1923 | int32_t target; | |
1924 | switch (xop) { | |
3475187d | 1925 | #ifdef TARGET_SPARC64 |
0f8a249a BS |
1926 | case 0x1: /* V9 BPcc */ |
1927 | { | |
1928 | int cc; | |
1929 | ||
1930 | target = GET_FIELD_SP(insn, 0, 18); | |
1931 | target = sign_extend(target, 18); | |
1932 | target <<= 2; | |
1933 | cc = GET_FIELD_SP(insn, 20, 21); | |
1934 | if (cc == 0) | |
1935 | do_branch(dc, target, insn, 0); | |
1936 | else if (cc == 2) | |
1937 | do_branch(dc, target, insn, 1); | |
1938 | else | |
1939 | goto illegal_insn; | |
1940 | goto jmp_insn; | |
1941 | } | |
1942 | case 0x3: /* V9 BPr */ | |
1943 | { | |
1944 | target = GET_FIELD_SP(insn, 0, 13) | | |
13846e70 | 1945 | (GET_FIELD_SP(insn, 20, 21) << 14); |
0f8a249a BS |
1946 | target = sign_extend(target, 16); |
1947 | target <<= 2; | |
1948 | rs1 = GET_FIELD(insn, 13, 17); | |
1949 | gen_movl_reg_T0(rs1); | |
1950 | do_branch_reg(dc, target, insn); | |
1951 | goto jmp_insn; | |
1952 | } | |
1953 | case 0x5: /* V9 FBPcc */ | |
1954 | { | |
1955 | int cc = GET_FIELD_SP(insn, 20, 21); | |
a80dde08 FB |
1956 | if (gen_trap_ifnofpu(dc)) |
1957 | goto jmp_insn; | |
0f8a249a BS |
1958 | target = GET_FIELD_SP(insn, 0, 18); |
1959 | target = sign_extend(target, 19); | |
1960 | target <<= 2; | |
1961 | do_fbranch(dc, target, insn, cc); | |
1962 | goto jmp_insn; | |
1963 | } | |
a4d17f19 | 1964 | #else |
0f8a249a BS |
1965 | case 0x7: /* CBN+x */ |
1966 | { | |
1967 | goto ncp_insn; | |
1968 | } | |
1969 | #endif | |
1970 | case 0x2: /* BN+x */ | |
1971 | { | |
1972 | target = GET_FIELD(insn, 10, 31); | |
1973 | target = sign_extend(target, 22); | |
1974 | target <<= 2; | |
1975 | do_branch(dc, target, insn, 0); | |
1976 | goto jmp_insn; | |
1977 | } | |
1978 | case 0x6: /* FBN+x */ | |
1979 | { | |
a80dde08 FB |
1980 | if (gen_trap_ifnofpu(dc)) |
1981 | goto jmp_insn; | |
0f8a249a BS |
1982 | target = GET_FIELD(insn, 10, 31); |
1983 | target = sign_extend(target, 22); | |
1984 | target <<= 2; | |
1985 | do_fbranch(dc, target, insn, 0); | |
1986 | goto jmp_insn; | |
1987 | } | |
1988 | case 0x4: /* SETHI */ | |
e80cfcfc FB |
1989 | #define OPTIM |
1990 | #if defined(OPTIM) | |
0f8a249a | 1991 | if (rd) { // nop |
e80cfcfc | 1992 | #endif |
0f8a249a | 1993 | uint32_t value = GET_FIELD(insn, 10, 31); |
1a2fb1c0 | 1994 | tcg_gen_movi_tl(cpu_T[0], value << 10); |
0f8a249a | 1995 | gen_movl_T0_reg(rd); |
e80cfcfc | 1996 | #if defined(OPTIM) |
0f8a249a | 1997 | } |
e80cfcfc | 1998 | #endif |
0f8a249a BS |
1999 | break; |
2000 | case 0x0: /* UNIMPL */ | |
2001 | default: | |
3475187d | 2002 | goto illegal_insn; |
0f8a249a BS |
2003 | } |
2004 | break; | |
2005 | } | |
2006 | break; | |
cf495bcf | 2007 | case 1: |
0f8a249a BS |
2008 | /*CALL*/ { |
2009 | target_long target = GET_FIELDs(insn, 2, 31) << 2; | |
cf495bcf | 2010 | |
48d5c82b | 2011 | gen_movl_TN_reg(15, tcg_const_tl(dc->pc)); |
0f8a249a | 2012 | target += dc->pc; |
0bee699e | 2013 | gen_mov_pc_npc(dc); |
0f8a249a BS |
2014 | dc->npc = target; |
2015 | } | |
2016 | goto jmp_insn; | |
2017 | case 2: /* FPU & Logical Operations */ | |
2018 | { | |
2019 | unsigned int xop = GET_FIELD(insn, 7, 12); | |
2020 | if (xop == 0x3a) { /* generate trap */ | |
cf495bcf | 2021 | int cond; |
3475187d | 2022 | |
cf495bcf FB |
2023 | rs1 = GET_FIELD(insn, 13, 17); |
2024 | gen_movl_reg_T0(rs1); | |
0f8a249a BS |
2025 | if (IS_IMM) { |
2026 | rs2 = GET_FIELD(insn, 25, 31); | |
1a2fb1c0 | 2027 | tcg_gen_addi_tl(cpu_T[0], cpu_T[0], rs2); |
cf495bcf FB |
2028 | } else { |
2029 | rs2 = GET_FIELD(insn, 27, 31); | |
e80cfcfc | 2030 | #if defined(OPTIM) |
0f8a249a | 2031 | if (rs2 != 0) { |
e80cfcfc | 2032 | #endif |
0f8a249a BS |
2033 | gen_movl_reg_T1(rs2); |
2034 | gen_op_add_T1_T0(); | |
e80cfcfc | 2035 | #if defined(OPTIM) |
0f8a249a | 2036 | } |
e80cfcfc | 2037 | #endif |
cf495bcf | 2038 | } |
cf495bcf FB |
2039 | cond = GET_FIELD(insn, 3, 6); |
2040 | if (cond == 0x8) { | |
a80dde08 | 2041 | save_state(dc); |
1a2fb1c0 | 2042 | tcg_gen_helper_0_1(helper_trap, cpu_T[0]); |
af7bf89b | 2043 | } else if (cond != 0) { |
748b9d8e | 2044 | TCGv r_cond = tcg_temp_new(TCG_TYPE_TL); |
3475187d | 2045 | #ifdef TARGET_SPARC64 |
0f8a249a BS |
2046 | /* V9 icc/xcc */ |
2047 | int cc = GET_FIELD_SP(insn, 11, 12); | |
748b9d8e | 2048 | |
a80dde08 | 2049 | save_state(dc); |
0f8a249a | 2050 | if (cc == 0) |
748b9d8e | 2051 | gen_cond(r_cond, 0, cond); |
0f8a249a | 2052 | else if (cc == 2) |
748b9d8e | 2053 | gen_cond(r_cond, 1, cond); |
0f8a249a BS |
2054 | else |
2055 | goto illegal_insn; | |
3475187d | 2056 | #else |
a80dde08 | 2057 | save_state(dc); |
748b9d8e | 2058 | gen_cond(r_cond, 0, cond); |
3475187d | 2059 | #endif |
748b9d8e | 2060 | tcg_gen_helper_0_2(helper_trapcc, cpu_T[0], r_cond); |
0425bee5 | 2061 | tcg_gen_discard_tl(r_cond); |
cf495bcf | 2062 | } |
a80dde08 | 2063 | gen_op_next_insn(); |
57fec1fe | 2064 | tcg_gen_exit_tb(0); |
a80dde08 FB |
2065 | dc->is_br = 1; |
2066 | goto jmp_insn; | |
cf495bcf FB |
2067 | } else if (xop == 0x28) { |
2068 | rs1 = GET_FIELD(insn, 13, 17); | |
2069 | switch(rs1) { | |
2070 | case 0: /* rdy */ | |
65fe7b09 BS |
2071 | #ifndef TARGET_SPARC64 |
2072 | case 0x01 ... 0x0e: /* undefined in the SPARCv8 | |
2073 | manual, rdy on the microSPARC | |
2074 | II */ | |
2075 | case 0x0f: /* stbar in the SPARCv8 manual, | |
2076 | rdy on the microSPARC II */ | |
2077 | case 0x10 ... 0x1f: /* implementation-dependent in the | |
2078 | SPARCv8 manual, rdy on the | |
2079 | microSPARC II */ | |
2080 | #endif | |
2081 | gen_op_movtl_T0_env(offsetof(CPUSPARCState, y)); | |
cf495bcf FB |
2082 | gen_movl_T0_reg(rd); |
2083 | break; | |
3475187d | 2084 | #ifdef TARGET_SPARC64 |
0f8a249a | 2085 | case 0x2: /* V9 rdccr */ |
d35527d9 | 2086 | tcg_gen_helper_1_0(helper_rdccr, cpu_T[0]); |
3475187d FB |
2087 | gen_movl_T0_reg(rd); |
2088 | break; | |
0f8a249a BS |
2089 | case 0x3: /* V9 rdasi */ |
2090 | gen_op_movl_T0_env(offsetof(CPUSPARCState, asi)); | |
3475187d FB |
2091 | gen_movl_T0_reg(rd); |
2092 | break; | |
0f8a249a | 2093 | case 0x4: /* V9 rdtick */ |
ccd4a219 BS |
2094 | { |
2095 | TCGv r_tickptr; | |
2096 | ||
2097 | r_tickptr = tcg_temp_new(TCG_TYPE_PTR); | |
2098 | tcg_gen_ld_ptr(r_tickptr, cpu_env, | |
2099 | offsetof(CPUState, tick)); | |
2100 | tcg_gen_helper_1_1(helper_tick_get_count, cpu_T[0], | |
2101 | r_tickptr); | |
2102 | gen_movl_T0_reg(rd); | |
0425bee5 | 2103 | tcg_gen_discard_ptr(r_tickptr); |
ccd4a219 | 2104 | } |
3475187d | 2105 | break; |
0f8a249a | 2106 | case 0x5: /* V9 rdpc */ |
1a2fb1c0 | 2107 | tcg_gen_movi_tl(cpu_T[0], dc->pc); |
0f8a249a BS |
2108 | gen_movl_T0_reg(rd); |
2109 | break; | |
2110 | case 0x6: /* V9 rdfprs */ | |
2111 | gen_op_movl_T0_env(offsetof(CPUSPARCState, fprs)); | |
3475187d FB |
2112 | gen_movl_T0_reg(rd); |
2113 | break; | |
65fe7b09 BS |
2114 | case 0xf: /* V9 membar */ |
2115 | break; /* no effect */ | |
0f8a249a | 2116 | case 0x13: /* Graphics Status */ |
725cb90b FB |
2117 | if (gen_trap_ifnofpu(dc)) |
2118 | goto jmp_insn; | |
0f8a249a | 2119 | gen_op_movtl_T0_env(offsetof(CPUSPARCState, gsr)); |
725cb90b FB |
2120 | gen_movl_T0_reg(rd); |
2121 | break; | |
0f8a249a BS |
2122 | case 0x17: /* Tick compare */ |
2123 | gen_op_movtl_T0_env(offsetof(CPUSPARCState, tick_cmpr)); | |
83469015 FB |
2124 | gen_movl_T0_reg(rd); |
2125 | break; | |
0f8a249a | 2126 | case 0x18: /* System tick */ |
ccd4a219 BS |
2127 | { |
2128 | TCGv r_tickptr; | |
2129 | ||
2130 | r_tickptr = tcg_temp_new(TCG_TYPE_PTR); | |
2131 | tcg_gen_ld_ptr(r_tickptr, cpu_env, | |
2132 | offsetof(CPUState, stick)); | |
2133 | tcg_gen_helper_1_1(helper_tick_get_count, cpu_T[0], | |
2134 | r_tickptr); | |
2135 | gen_movl_T0_reg(rd); | |
0425bee5 | 2136 | tcg_gen_discard_ptr(r_tickptr); |
ccd4a219 | 2137 | } |
83469015 | 2138 | break; |
0f8a249a BS |
2139 | case 0x19: /* System tick compare */ |
2140 | gen_op_movtl_T0_env(offsetof(CPUSPARCState, stick_cmpr)); | |
83469015 FB |
2141 | gen_movl_T0_reg(rd); |
2142 | break; | |
0f8a249a BS |
2143 | case 0x10: /* Performance Control */ |
2144 | case 0x11: /* Performance Instrumentation Counter */ | |
2145 | case 0x12: /* Dispatch Control */ | |
2146 | case 0x14: /* Softint set, WO */ | |
2147 | case 0x15: /* Softint clear, WO */ | |
2148 | case 0x16: /* Softint write */ | |
3475187d FB |
2149 | #endif |
2150 | default: | |
cf495bcf FB |
2151 | goto illegal_insn; |
2152 | } | |
e8af50a3 | 2153 | #if !defined(CONFIG_USER_ONLY) |
e9ebed4d | 2154 | } else if (xop == 0x29) { /* rdpsr / UA2005 rdhpr */ |
3475187d | 2155 | #ifndef TARGET_SPARC64 |
0f8a249a BS |
2156 | if (!supervisor(dc)) |
2157 | goto priv_insn; | |
1a2fb1c0 | 2158 | tcg_gen_helper_1_0(helper_rdpsr, cpu_T[0]); |
e9ebed4d BS |
2159 | #else |
2160 | if (!hypervisor(dc)) | |
2161 | goto priv_insn; | |
2162 | rs1 = GET_FIELD(insn, 13, 17); | |
2163 | switch (rs1) { | |
2164 | case 0: // hpstate | |
2165 | // gen_op_rdhpstate(); | |
2166 | break; | |
2167 | case 1: // htstate | |
2168 | // gen_op_rdhtstate(); | |
2169 | break; | |
2170 | case 3: // hintp | |
2171 | gen_op_movl_T0_env(offsetof(CPUSPARCState, hintp)); | |
2172 | break; | |
2173 | case 5: // htba | |
2174 | gen_op_movl_T0_env(offsetof(CPUSPARCState, htba)); | |
2175 | break; | |
2176 | case 6: // hver | |
2177 | gen_op_movl_T0_env(offsetof(CPUSPARCState, hver)); | |
2178 | break; | |
2179 | case 31: // hstick_cmpr | |
2180 | gen_op_movl_env_T0(offsetof(CPUSPARCState, hstick_cmpr)); | |
2181 | break; | |
2182 | default: | |
2183 | goto illegal_insn; | |
2184 | } | |
2185 | #endif | |
e8af50a3 FB |
2186 | gen_movl_T0_reg(rd); |
2187 | break; | |
3475187d | 2188 | } else if (xop == 0x2a) { /* rdwim / V9 rdpr */ |
0f8a249a BS |
2189 | if (!supervisor(dc)) |
2190 | goto priv_insn; | |
3475187d FB |
2191 | #ifdef TARGET_SPARC64 |
2192 | rs1 = GET_FIELD(insn, 13, 17); | |
0f8a249a BS |
2193 | switch (rs1) { |
2194 | case 0: // tpc | |
375ee38b BS |
2195 | { |
2196 | TCGv r_tsptr; | |
2197 | ||
2198 | r_tsptr = tcg_temp_new(TCG_TYPE_PTR); | |
2199 | tcg_gen_ld_ptr(r_tsptr, cpu_env, | |
2200 | offsetof(CPUState, tsptr)); | |
2201 | tcg_gen_ld_tl(cpu_T[0], r_tsptr, | |
2202 | offsetof(trap_state, tpc)); | |
0425bee5 | 2203 | tcg_gen_discard_ptr(r_tsptr); |
375ee38b | 2204 | } |
0f8a249a BS |
2205 | break; |
2206 | case 1: // tnpc | |
375ee38b BS |
2207 | { |
2208 | TCGv r_tsptr; | |
2209 | ||
2210 | r_tsptr = tcg_temp_new(TCG_TYPE_PTR); | |
2211 | tcg_gen_ld_ptr(r_tsptr, cpu_env, | |
2212 | offsetof(CPUState, tsptr)); | |
2213 | tcg_gen_ld_tl(cpu_T[0], r_tsptr, | |
2214 | offsetof(trap_state, tnpc)); | |
0425bee5 | 2215 | tcg_gen_discard_ptr(r_tsptr); |
375ee38b | 2216 | } |
0f8a249a BS |
2217 | break; |
2218 | case 2: // tstate | |
375ee38b BS |
2219 | { |
2220 | TCGv r_tsptr; | |
2221 | ||
2222 | r_tsptr = tcg_temp_new(TCG_TYPE_PTR); | |
2223 | tcg_gen_ld_ptr(r_tsptr, cpu_env, | |
2224 | offsetof(CPUState, tsptr)); | |
2225 | tcg_gen_ld_tl(cpu_T[0], r_tsptr, | |
2226 | offsetof(trap_state, tstate)); | |
0425bee5 | 2227 | tcg_gen_discard_ptr(r_tsptr); |
375ee38b | 2228 | } |
0f8a249a BS |
2229 | break; |
2230 | case 3: // tt | |
375ee38b BS |
2231 | { |
2232 | TCGv r_tsptr; | |
2233 | ||
2234 | r_tsptr = tcg_temp_new(TCG_TYPE_PTR); | |
2235 | tcg_gen_ld_ptr(r_tsptr, cpu_env, | |
2236 | offsetof(CPUState, tsptr)); | |
2237 | tcg_gen_ld_i32(cpu_T[0], r_tsptr, | |
2238 | offsetof(trap_state, tt)); | |
0425bee5 | 2239 | tcg_gen_discard_ptr(r_tsptr); |
375ee38b | 2240 | } |
0f8a249a BS |
2241 | break; |
2242 | case 4: // tick | |
ccd4a219 BS |
2243 | { |
2244 | TCGv r_tickptr; | |
2245 | ||
2246 | r_tickptr = tcg_temp_new(TCG_TYPE_PTR); | |
2247 | tcg_gen_ld_ptr(r_tickptr, cpu_env, | |
2248 | offsetof(CPUState, tick)); | |
2249 | tcg_gen_helper_1_1(helper_tick_get_count, cpu_T[0], | |
2250 | r_tickptr); | |
2251 | gen_movl_T0_reg(rd); | |
0425bee5 | 2252 | tcg_gen_discard_ptr(r_tickptr); |
ccd4a219 | 2253 | } |
0f8a249a BS |
2254 | break; |
2255 | case 5: // tba | |
2256 | gen_op_movtl_T0_env(offsetof(CPUSPARCState, tbr)); | |
2257 | break; | |
2258 | case 6: // pstate | |
1a2fb1c0 | 2259 | gen_op_movl_T0_env(offsetof(CPUSPARCState, pstate)); |
0f8a249a BS |
2260 | break; |
2261 | case 7: // tl | |
2262 | gen_op_movl_T0_env(offsetof(CPUSPARCState, tl)); | |
2263 | break; | |
2264 | case 8: // pil | |
2265 | gen_op_movl_T0_env(offsetof(CPUSPARCState, psrpil)); | |
2266 | break; | |
2267 | case 9: // cwp | |
d35527d9 | 2268 | tcg_gen_helper_1_0(helper_rdcwp, cpu_T[0]); |
0f8a249a BS |
2269 | break; |
2270 | case 10: // cansave | |
2271 | gen_op_movl_T0_env(offsetof(CPUSPARCState, cansave)); | |
2272 | break; | |
2273 | case 11: // canrestore | |
2274 | gen_op_movl_T0_env(offsetof(CPUSPARCState, canrestore)); | |
2275 | break; | |
2276 | case 12: // cleanwin | |
2277 | gen_op_movl_T0_env(offsetof(CPUSPARCState, cleanwin)); | |
2278 | break; | |
2279 | case 13: // otherwin | |
2280 | gen_op_movl_T0_env(offsetof(CPUSPARCState, otherwin)); | |
2281 | break; | |
2282 | case 14: // wstate | |
2283 | gen_op_movl_T0_env(offsetof(CPUSPARCState, wstate)); | |
2284 | break; | |
e9ebed4d BS |
2285 | case 16: // UA2005 gl |
2286 | gen_op_movl_T0_env(offsetof(CPUSPARCState, gl)); | |
2287 | break; | |
2288 | case 26: // UA2005 strand status | |
2289 | if (!hypervisor(dc)) | |
2290 | goto priv_insn; | |
2291 | gen_op_movl_T0_env(offsetof(CPUSPARCState, ssr)); | |
2292 | break; | |
0f8a249a BS |
2293 | case 31: // ver |
2294 | gen_op_movtl_T0_env(offsetof(CPUSPARCState, version)); | |
2295 | break; | |
2296 | case 15: // fq | |
2297 | default: | |
2298 | goto illegal_insn; | |
2299 | } | |
3475187d | 2300 | #else |
0f8a249a | 2301 | gen_op_movl_T0_env(offsetof(CPUSPARCState, wim)); |
3475187d | 2302 | #endif |
e8af50a3 FB |
2303 | gen_movl_T0_reg(rd); |
2304 | break; | |
3475187d FB |
2305 | } else if (xop == 0x2b) { /* rdtbr / V9 flushw */ |
2306 | #ifdef TARGET_SPARC64 | |
72a9747b | 2307 | tcg_gen_helper_0_0(helper_flushw); |
3475187d | 2308 | #else |
0f8a249a BS |
2309 | if (!supervisor(dc)) |
2310 | goto priv_insn; | |
2311 | gen_op_movtl_T0_env(offsetof(CPUSPARCState, tbr)); | |
e8af50a3 | 2312 | gen_movl_T0_reg(rd); |
3475187d | 2313 | #endif |
e8af50a3 FB |
2314 | break; |
2315 | #endif | |
0f8a249a | 2316 | } else if (xop == 0x34) { /* FPU Operations */ |
a80dde08 FB |
2317 | if (gen_trap_ifnofpu(dc)) |
2318 | goto jmp_insn; | |
0f8a249a | 2319 | gen_op_clear_ieee_excp_and_FTT(); |
e8af50a3 | 2320 | rs1 = GET_FIELD(insn, 13, 17); |
0f8a249a BS |
2321 | rs2 = GET_FIELD(insn, 27, 31); |
2322 | xop = GET_FIELD(insn, 18, 26); | |
2323 | switch (xop) { | |
2324 | case 0x1: /* fmovs */ | |
2325 | gen_op_load_fpr_FT0(rs2); | |
2326 | gen_op_store_FT0_fpr(rd); | |
2327 | break; | |
2328 | case 0x5: /* fnegs */ | |
2329 | gen_op_load_fpr_FT1(rs2); | |
44e7757c | 2330 | tcg_gen_helper_0_0(helper_fnegs); |
0f8a249a BS |
2331 | gen_op_store_FT0_fpr(rd); |
2332 | break; | |
2333 | case 0x9: /* fabss */ | |
2334 | gen_op_load_fpr_FT1(rs2); | |
7e8c2b6c | 2335 | tcg_gen_helper_0_0(helper_fabss); |
0f8a249a BS |
2336 | gen_op_store_FT0_fpr(rd); |
2337 | break; | |
2338 | case 0x29: /* fsqrts */ | |
2339 | gen_op_load_fpr_FT1(rs2); | |
7e8c2b6c BS |
2340 | gen_clear_float_exceptions(); |
2341 | tcg_gen_helper_0_0(helper_fsqrts); | |
2342 | tcg_gen_helper_0_0(helper_check_ieee_exceptions); | |
0f8a249a BS |
2343 | gen_op_store_FT0_fpr(rd); |
2344 | break; | |
2345 | case 0x2a: /* fsqrtd */ | |
2346 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
7e8c2b6c BS |
2347 | gen_clear_float_exceptions(); |
2348 | tcg_gen_helper_0_0(helper_fsqrtd); | |
2349 | tcg_gen_helper_0_0(helper_check_ieee_exceptions); | |
0f8a249a BS |
2350 | gen_op_store_DT0_fpr(DFPREG(rd)); |
2351 | break; | |
2352 | case 0x2b: /* fsqrtq */ | |
1f587329 BS |
2353 | #if defined(CONFIG_USER_ONLY) |
2354 | gen_op_load_fpr_QT1(QFPREG(rs2)); | |
7e8c2b6c BS |
2355 | gen_clear_float_exceptions(); |
2356 | tcg_gen_helper_0_0(helper_fsqrtq); | |
2357 | tcg_gen_helper_0_0(helper_check_ieee_exceptions); | |
1f587329 BS |
2358 | gen_op_store_QT0_fpr(QFPREG(rd)); |
2359 | break; | |
2360 | #else | |
0f8a249a | 2361 | goto nfpu_insn; |
1f587329 | 2362 | #endif |
0f8a249a BS |
2363 | case 0x41: |
2364 | gen_op_load_fpr_FT0(rs1); | |
2365 | gen_op_load_fpr_FT1(rs2); | |
7e8c2b6c | 2366 | gen_clear_float_exceptions(); |
44e7757c | 2367 | tcg_gen_helper_0_0(helper_fadds); |
7e8c2b6c | 2368 | tcg_gen_helper_0_0(helper_check_ieee_exceptions); |
0f8a249a BS |
2369 | gen_op_store_FT0_fpr(rd); |
2370 | break; | |
2371 | case 0x42: | |
2372 | gen_op_load_fpr_DT0(DFPREG(rs1)); | |
2373 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
7e8c2b6c | 2374 | gen_clear_float_exceptions(); |
44e7757c | 2375 | tcg_gen_helper_0_0(helper_faddd); |
7e8c2b6c | 2376 | tcg_gen_helper_0_0(helper_check_ieee_exceptions); |
0f8a249a BS |
2377 | gen_op_store_DT0_fpr(DFPREG(rd)); |
2378 | break; | |
2379 | case 0x43: /* faddq */ | |
1f587329 BS |
2380 | #if defined(CONFIG_USER_ONLY) |
2381 | gen_op_load_fpr_QT0(QFPREG(rs1)); | |
2382 | gen_op_load_fpr_QT1(QFPREG(rs2)); | |
7e8c2b6c | 2383 | gen_clear_float_exceptions(); |
44e7757c | 2384 | tcg_gen_helper_0_0(helper_faddq); |
7e8c2b6c | 2385 | tcg_gen_helper_0_0(helper_check_ieee_exceptions); |
1f587329 BS |
2386 | gen_op_store_QT0_fpr(QFPREG(rd)); |
2387 | break; | |
2388 | #else | |
0f8a249a | 2389 | goto nfpu_insn; |
1f587329 | 2390 | #endif |
0f8a249a BS |
2391 | case 0x45: |
2392 | gen_op_load_fpr_FT0(rs1); | |
2393 | gen_op_load_fpr_FT1(rs2); | |
7e8c2b6c | 2394 | gen_clear_float_exceptions(); |
44e7757c | 2395 | tcg_gen_helper_0_0(helper_fsubs); |
7e8c2b6c | 2396 | tcg_gen_helper_0_0(helper_check_ieee_exceptions); |
0f8a249a BS |
2397 | gen_op_store_FT0_fpr(rd); |
2398 | break; | |
2399 | case 0x46: | |
2400 | gen_op_load_fpr_DT0(DFPREG(rs1)); | |
2401 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
7e8c2b6c | 2402 | gen_clear_float_exceptions(); |
44e7757c | 2403 | tcg_gen_helper_0_0(helper_fsubd); |
7e8c2b6c | 2404 | tcg_gen_helper_0_0(helper_check_ieee_exceptions); |
0f8a249a BS |
2405 | gen_op_store_DT0_fpr(DFPREG(rd)); |
2406 | break; | |
2407 | case 0x47: /* fsubq */ | |
1f587329 BS |
2408 | #if defined(CONFIG_USER_ONLY) |
2409 | gen_op_load_fpr_QT0(QFPREG(rs1)); | |
2410 | gen_op_load_fpr_QT1(QFPREG(rs2)); | |
7e8c2b6c | 2411 | gen_clear_float_exceptions(); |
44e7757c | 2412 | tcg_gen_helper_0_0(helper_fsubq); |
7e8c2b6c | 2413 | tcg_gen_helper_0_0(helper_check_ieee_exceptions); |
1f587329 BS |
2414 | gen_op_store_QT0_fpr(QFPREG(rd)); |
2415 | break; | |
2416 | #else | |
0f8a249a | 2417 | goto nfpu_insn; |
1f587329 | 2418 | #endif |
0f8a249a BS |
2419 | case 0x49: |
2420 | gen_op_load_fpr_FT0(rs1); | |
2421 | gen_op_load_fpr_FT1(rs2); | |
7e8c2b6c | 2422 | gen_clear_float_exceptions(); |
44e7757c | 2423 | tcg_gen_helper_0_0(helper_fmuls); |
7e8c2b6c | 2424 | tcg_gen_helper_0_0(helper_check_ieee_exceptions); |
0f8a249a BS |
2425 | gen_op_store_FT0_fpr(rd); |
2426 | break; | |
2427 | case 0x4a: | |
2428 | gen_op_load_fpr_DT0(DFPREG(rs1)); | |
2429 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
7e8c2b6c | 2430 | gen_clear_float_exceptions(); |
44e7757c | 2431 | tcg_gen_helper_0_0(helper_fmuld); |
7e8c2b6c | 2432 | tcg_gen_helper_0_0(helper_check_ieee_exceptions); |
2382dc6b | 2433 | gen_op_store_DT0_fpr(DFPREG(rd)); |
0f8a249a BS |
2434 | break; |
2435 | case 0x4b: /* fmulq */ | |
1f587329 BS |
2436 | #if defined(CONFIG_USER_ONLY) |
2437 | gen_op_load_fpr_QT0(QFPREG(rs1)); | |
2438 | gen_op_load_fpr_QT1(QFPREG(rs2)); | |
7e8c2b6c | 2439 | gen_clear_float_exceptions(); |
44e7757c | 2440 | tcg_gen_helper_0_0(helper_fmulq); |
7e8c2b6c | 2441 | tcg_gen_helper_0_0(helper_check_ieee_exceptions); |
1f587329 BS |
2442 | gen_op_store_QT0_fpr(QFPREG(rd)); |
2443 | break; | |
2444 | #else | |
0f8a249a | 2445 | goto nfpu_insn; |
1f587329 | 2446 | #endif |
0f8a249a BS |
2447 | case 0x4d: |
2448 | gen_op_load_fpr_FT0(rs1); | |
2449 | gen_op_load_fpr_FT1(rs2); | |
7e8c2b6c | 2450 | gen_clear_float_exceptions(); |
44e7757c | 2451 | tcg_gen_helper_0_0(helper_fdivs); |
7e8c2b6c | 2452 | tcg_gen_helper_0_0(helper_check_ieee_exceptions); |
0f8a249a BS |
2453 | gen_op_store_FT0_fpr(rd); |
2454 | break; | |
2455 | case 0x4e: | |
2456 | gen_op_load_fpr_DT0(DFPREG(rs1)); | |
2457 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
7e8c2b6c | 2458 | gen_clear_float_exceptions(); |
44e7757c | 2459 | tcg_gen_helper_0_0(helper_fdivd); |
7e8c2b6c | 2460 | tcg_gen_helper_0_0(helper_check_ieee_exceptions); |
0f8a249a BS |
2461 | gen_op_store_DT0_fpr(DFPREG(rd)); |
2462 | break; | |
2463 | case 0x4f: /* fdivq */ | |
1f587329 BS |
2464 | #if defined(CONFIG_USER_ONLY) |
2465 | gen_op_load_fpr_QT0(QFPREG(rs1)); | |
2466 | gen_op_load_fpr_QT1(QFPREG(rs2)); | |
7e8c2b6c | 2467 | gen_clear_float_exceptions(); |
44e7757c | 2468 | tcg_gen_helper_0_0(helper_fdivq); |
7e8c2b6c | 2469 | tcg_gen_helper_0_0(helper_check_ieee_exceptions); |
1f587329 BS |
2470 | gen_op_store_QT0_fpr(QFPREG(rd)); |
2471 | break; | |
2472 | #else | |
0f8a249a | 2473 | goto nfpu_insn; |
1f587329 | 2474 | #endif |
0f8a249a BS |
2475 | case 0x69: |
2476 | gen_op_load_fpr_FT0(rs1); | |
2477 | gen_op_load_fpr_FT1(rs2); | |
7e8c2b6c | 2478 | gen_clear_float_exceptions(); |
44e7757c | 2479 | tcg_gen_helper_0_0(helper_fsmuld); |
7e8c2b6c | 2480 | tcg_gen_helper_0_0(helper_check_ieee_exceptions); |
0f8a249a BS |
2481 | gen_op_store_DT0_fpr(DFPREG(rd)); |
2482 | break; | |
2483 | case 0x6e: /* fdmulq */ | |
1f587329 BS |
2484 | #if defined(CONFIG_USER_ONLY) |
2485 | gen_op_load_fpr_DT0(DFPREG(rs1)); | |
2486 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
7e8c2b6c | 2487 | gen_clear_float_exceptions(); |
44e7757c | 2488 | tcg_gen_helper_0_0(helper_fdmulq); |
7e8c2b6c | 2489 | tcg_gen_helper_0_0(helper_check_ieee_exceptions); |
1f587329 BS |
2490 | gen_op_store_QT0_fpr(QFPREG(rd)); |
2491 | break; | |
2492 | #else | |
0f8a249a | 2493 | goto nfpu_insn; |
1f587329 | 2494 | #endif |
0f8a249a BS |
2495 | case 0xc4: |
2496 | gen_op_load_fpr_FT1(rs2); | |
7e8c2b6c | 2497 | gen_clear_float_exceptions(); |
44e7757c | 2498 | tcg_gen_helper_0_0(helper_fitos); |
7e8c2b6c | 2499 | tcg_gen_helper_0_0(helper_check_ieee_exceptions); |
0f8a249a BS |
2500 | gen_op_store_FT0_fpr(rd); |
2501 | break; | |
2502 | case 0xc6: | |
2503 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
7e8c2b6c | 2504 | gen_clear_float_exceptions(); |
44e7757c | 2505 | tcg_gen_helper_0_0(helper_fdtos); |
7e8c2b6c | 2506 | tcg_gen_helper_0_0(helper_check_ieee_exceptions); |
0f8a249a BS |
2507 | gen_op_store_FT0_fpr(rd); |
2508 | break; | |
2509 | case 0xc7: /* fqtos */ | |
1f587329 BS |
2510 | #if defined(CONFIG_USER_ONLY) |
2511 | gen_op_load_fpr_QT1(QFPREG(rs2)); | |
7e8c2b6c | 2512 | gen_clear_float_exceptions(); |
44e7757c | 2513 | tcg_gen_helper_0_0(helper_fqtos); |
7e8c2b6c | 2514 | tcg_gen_helper_0_0(helper_check_ieee_exceptions); |
1f587329 BS |
2515 | gen_op_store_FT0_fpr(rd); |
2516 | break; | |
2517 | #else | |
0f8a249a | 2518 | goto nfpu_insn; |
1f587329 | 2519 | #endif |
0f8a249a BS |
2520 | case 0xc8: |
2521 | gen_op_load_fpr_FT1(rs2); | |
44e7757c | 2522 | tcg_gen_helper_0_0(helper_fitod); |
0f8a249a BS |
2523 | gen_op_store_DT0_fpr(DFPREG(rd)); |
2524 | break; | |
2525 | case 0xc9: | |
2526 | gen_op_load_fpr_FT1(rs2); | |
44e7757c | 2527 | tcg_gen_helper_0_0(helper_fstod); |
0f8a249a BS |
2528 | gen_op_store_DT0_fpr(DFPREG(rd)); |
2529 | break; | |
2530 | case 0xcb: /* fqtod */ | |
1f587329 BS |
2531 | #if defined(CONFIG_USER_ONLY) |
2532 | gen_op_load_fpr_QT1(QFPREG(rs2)); | |
7e8c2b6c | 2533 | gen_clear_float_exceptions(); |
44e7757c | 2534 | tcg_gen_helper_0_0(helper_fqtod); |
7e8c2b6c | 2535 | tcg_gen_helper_0_0(helper_check_ieee_exceptions); |
1f587329 BS |
2536 | gen_op_store_DT0_fpr(DFPREG(rd)); |
2537 | break; | |
2538 | #else | |
0f8a249a | 2539 | goto nfpu_insn; |
1f587329 | 2540 | #endif |
0f8a249a | 2541 | case 0xcc: /* fitoq */ |
1f587329 BS |
2542 | #if defined(CONFIG_USER_ONLY) |
2543 | gen_op_load_fpr_FT1(rs2); | |
44e7757c | 2544 | tcg_gen_helper_0_0(helper_fitoq); |
1f587329 BS |
2545 | gen_op_store_QT0_fpr(QFPREG(rd)); |
2546 | break; | |
2547 | #else | |
0f8a249a | 2548 | goto nfpu_insn; |
1f587329 | 2549 | #endif |
0f8a249a | 2550 | case 0xcd: /* fstoq */ |
1f587329 BS |
2551 | #if defined(CONFIG_USER_ONLY) |
2552 | gen_op_load_fpr_FT1(rs2); | |
44e7757c | 2553 | tcg_gen_helper_0_0(helper_fstoq); |
1f587329 BS |
2554 | gen_op_store_QT0_fpr(QFPREG(rd)); |
2555 | break; | |
2556 | #else | |
0f8a249a | 2557 | goto nfpu_insn; |
1f587329 | 2558 | #endif |
0f8a249a | 2559 | case 0xce: /* fdtoq */ |
1f587329 BS |
2560 | #if defined(CONFIG_USER_ONLY) |
2561 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
44e7757c | 2562 | tcg_gen_helper_0_0(helper_fdtoq); |
1f587329 BS |
2563 | gen_op_store_QT0_fpr(QFPREG(rd)); |
2564 | break; | |
2565 | #else | |
0f8a249a | 2566 | goto nfpu_insn; |
1f587329 | 2567 | #endif |
0f8a249a BS |
2568 | case 0xd1: |
2569 | gen_op_load_fpr_FT1(rs2); | |
7e8c2b6c | 2570 | gen_clear_float_exceptions(); |
44e7757c | 2571 | tcg_gen_helper_0_0(helper_fstoi); |
7e8c2b6c | 2572 | tcg_gen_helper_0_0(helper_check_ieee_exceptions); |
0f8a249a BS |
2573 | gen_op_store_FT0_fpr(rd); |
2574 | break; | |
2575 | case 0xd2: | |
2382dc6b | 2576 | gen_op_load_fpr_DT1(DFPREG(rs2)); |
7e8c2b6c | 2577 | gen_clear_float_exceptions(); |
44e7757c | 2578 | tcg_gen_helper_0_0(helper_fdtoi); |
7e8c2b6c | 2579 | tcg_gen_helper_0_0(helper_check_ieee_exceptions); |
0f8a249a BS |
2580 | gen_op_store_FT0_fpr(rd); |
2581 | break; | |
2582 | case 0xd3: /* fqtoi */ | |
1f587329 BS |
2583 | #if defined(CONFIG_USER_ONLY) |
2584 | gen_op_load_fpr_QT1(QFPREG(rs2)); | |
7e8c2b6c | 2585 | gen_clear_float_exceptions(); |
44e7757c | 2586 | tcg_gen_helper_0_0(helper_fqtoi); |
7e8c2b6c | 2587 | tcg_gen_helper_0_0(helper_check_ieee_exceptions); |
1f587329 BS |
2588 | gen_op_store_FT0_fpr(rd); |
2589 | break; | |
2590 | #else | |
0f8a249a | 2591 | goto nfpu_insn; |
1f587329 | 2592 | #endif |
3475187d | 2593 | #ifdef TARGET_SPARC64 |
0f8a249a BS |
2594 | case 0x2: /* V9 fmovd */ |
2595 | gen_op_load_fpr_DT0(DFPREG(rs2)); | |
2596 | gen_op_store_DT0_fpr(DFPREG(rd)); | |
2597 | break; | |
1f587329 BS |
2598 | case 0x3: /* V9 fmovq */ |
2599 | #if defined(CONFIG_USER_ONLY) | |
2600 | gen_op_load_fpr_QT0(QFPREG(rs2)); | |
2601 | gen_op_store_QT0_fpr(QFPREG(rd)); | |
2602 | break; | |
2603 | #else | |
2604 | goto nfpu_insn; | |
2605 | #endif | |
0f8a249a BS |
2606 | case 0x6: /* V9 fnegd */ |
2607 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
44e7757c | 2608 | tcg_gen_helper_0_0(helper_fnegd); |
0f8a249a BS |
2609 | gen_op_store_DT0_fpr(DFPREG(rd)); |
2610 | break; | |
1f587329 BS |
2611 | case 0x7: /* V9 fnegq */ |
2612 | #if defined(CONFIG_USER_ONLY) | |
2613 | gen_op_load_fpr_QT1(QFPREG(rs2)); | |
44e7757c | 2614 | tcg_gen_helper_0_0(helper_fnegq); |
1f587329 BS |
2615 | gen_op_store_QT0_fpr(QFPREG(rd)); |
2616 | break; | |
2617 | #else | |
2618 | goto nfpu_insn; | |
2619 | #endif | |
0f8a249a BS |
2620 | case 0xa: /* V9 fabsd */ |
2621 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
7e8c2b6c | 2622 | tcg_gen_helper_0_0(helper_fabsd); |
0f8a249a BS |
2623 | gen_op_store_DT0_fpr(DFPREG(rd)); |
2624 | break; | |
1f587329 BS |
2625 | case 0xb: /* V9 fabsq */ |
2626 | #if defined(CONFIG_USER_ONLY) | |
2627 | gen_op_load_fpr_QT1(QFPREG(rs2)); | |
7e8c2b6c | 2628 | tcg_gen_helper_0_0(helper_fabsq); |
1f587329 BS |
2629 | gen_op_store_QT0_fpr(QFPREG(rd)); |
2630 | break; | |
2631 | #else | |
2632 | goto nfpu_insn; | |
2633 | #endif | |
0f8a249a BS |
2634 | case 0x81: /* V9 fstox */ |
2635 | gen_op_load_fpr_FT1(rs2); | |
7e8c2b6c | 2636 | gen_clear_float_exceptions(); |
44e7757c | 2637 | tcg_gen_helper_0_0(helper_fstox); |
7e8c2b6c | 2638 | tcg_gen_helper_0_0(helper_check_ieee_exceptions); |
0f8a249a BS |
2639 | gen_op_store_DT0_fpr(DFPREG(rd)); |
2640 | break; | |
2641 | case 0x82: /* V9 fdtox */ | |
2642 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
7e8c2b6c | 2643 | gen_clear_float_exceptions(); |
44e7757c | 2644 | tcg_gen_helper_0_0(helper_fdtox); |
7e8c2b6c | 2645 | tcg_gen_helper_0_0(helper_check_ieee_exceptions); |
0f8a249a BS |
2646 | gen_op_store_DT0_fpr(DFPREG(rd)); |
2647 | break; | |
1f587329 BS |
2648 | case 0x83: /* V9 fqtox */ |
2649 | #if defined(CONFIG_USER_ONLY) | |
2650 | gen_op_load_fpr_QT1(QFPREG(rs2)); | |
7e8c2b6c | 2651 | gen_clear_float_exceptions(); |
44e7757c | 2652 | tcg_gen_helper_0_0(helper_fqtox); |
7e8c2b6c | 2653 | tcg_gen_helper_0_0(helper_check_ieee_exceptions); |
1f587329 BS |
2654 | gen_op_store_DT0_fpr(DFPREG(rd)); |
2655 | break; | |
2656 | #else | |
2657 | goto nfpu_insn; | |
2658 | #endif | |
0f8a249a BS |
2659 | case 0x84: /* V9 fxtos */ |
2660 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
7e8c2b6c | 2661 | gen_clear_float_exceptions(); |
44e7757c | 2662 | tcg_gen_helper_0_0(helper_fxtos); |
7e8c2b6c | 2663 | tcg_gen_helper_0_0(helper_check_ieee_exceptions); |
0f8a249a BS |
2664 | gen_op_store_FT0_fpr(rd); |
2665 | break; | |
2666 | case 0x88: /* V9 fxtod */ | |
2667 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
7e8c2b6c | 2668 | gen_clear_float_exceptions(); |
44e7757c | 2669 | tcg_gen_helper_0_0(helper_fxtod); |
7e8c2b6c | 2670 | tcg_gen_helper_0_0(helper_check_ieee_exceptions); |
0f8a249a BS |
2671 | gen_op_store_DT0_fpr(DFPREG(rd)); |
2672 | break; | |
0f8a249a | 2673 | case 0x8c: /* V9 fxtoq */ |
1f587329 BS |
2674 | #if defined(CONFIG_USER_ONLY) |
2675 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
7e8c2b6c | 2676 | gen_clear_float_exceptions(); |
44e7757c | 2677 | tcg_gen_helper_0_0(helper_fxtoq); |
7e8c2b6c | 2678 | tcg_gen_helper_0_0(helper_check_ieee_exceptions); |
1f587329 BS |
2679 | gen_op_store_QT0_fpr(QFPREG(rd)); |
2680 | break; | |
2681 | #else | |
0f8a249a | 2682 | goto nfpu_insn; |
1f587329 | 2683 | #endif |
0f8a249a BS |
2684 | #endif |
2685 | default: | |
2686 | goto illegal_insn; | |
2687 | } | |
2688 | } else if (xop == 0x35) { /* FPU Operations */ | |
3475187d | 2689 | #ifdef TARGET_SPARC64 |
0f8a249a | 2690 | int cond; |
3475187d | 2691 | #endif |
a80dde08 FB |
2692 | if (gen_trap_ifnofpu(dc)) |
2693 | goto jmp_insn; | |
0f8a249a | 2694 | gen_op_clear_ieee_excp_and_FTT(); |
cf495bcf | 2695 | rs1 = GET_FIELD(insn, 13, 17); |
0f8a249a BS |
2696 | rs2 = GET_FIELD(insn, 27, 31); |
2697 | xop = GET_FIELD(insn, 18, 26); | |
3475187d | 2698 | #ifdef TARGET_SPARC64 |
0f8a249a | 2699 | if ((xop & 0x11f) == 0x005) { // V9 fmovsr |
dcf24905 BS |
2700 | int l1; |
2701 | ||
2702 | l1 = gen_new_label(); | |
0f8a249a | 2703 | cond = GET_FIELD_SP(insn, 14, 17); |
0f8a249a BS |
2704 | rs1 = GET_FIELD(insn, 13, 17); |
2705 | gen_movl_reg_T0(rs1); | |
0425bee5 BS |
2706 | tcg_gen_brcond_tl(gen_tcg_cond_reg[cond], cpu_T[0], |
2707 | tcg_const_tl(0), l1); | |
19f329ad | 2708 | gen_op_load_fpr_FT0(rs2); |
0f8a249a | 2709 | gen_op_store_FT0_fpr(rd); |
dcf24905 | 2710 | gen_set_label(l1); |
0f8a249a BS |
2711 | break; |
2712 | } else if ((xop & 0x11f) == 0x006) { // V9 fmovdr | |
dcf24905 BS |
2713 | int l1; |
2714 | ||
2715 | l1 = gen_new_label(); | |
0f8a249a | 2716 | cond = GET_FIELD_SP(insn, 14, 17); |
0f8a249a BS |
2717 | rs1 = GET_FIELD(insn, 13, 17); |
2718 | gen_movl_reg_T0(rs1); | |
0425bee5 BS |
2719 | tcg_gen_brcond_tl(gen_tcg_cond_reg[cond], cpu_T[0], |
2720 | tcg_const_tl(0), l1); | |
19f329ad | 2721 | gen_op_load_fpr_DT0(DFPREG(rs2)); |
2382dc6b | 2722 | gen_op_store_DT0_fpr(DFPREG(rd)); |
dcf24905 | 2723 | gen_set_label(l1); |
0f8a249a BS |
2724 | break; |
2725 | } else if ((xop & 0x11f) == 0x007) { // V9 fmovqr | |
1f587329 | 2726 | #if defined(CONFIG_USER_ONLY) |
dcf24905 BS |
2727 | int l1; |
2728 | ||
2729 | l1 = gen_new_label(); | |
1f587329 | 2730 | cond = GET_FIELD_SP(insn, 14, 17); |
1f587329 BS |
2731 | rs1 = GET_FIELD(insn, 13, 17); |
2732 | gen_movl_reg_T0(rs1); | |
0425bee5 BS |
2733 | tcg_gen_brcond_tl(gen_tcg_cond_reg[cond], cpu_T[0], |
2734 | tcg_const_tl(0), l1); | |
19f329ad | 2735 | gen_op_load_fpr_QT0(QFPREG(rs2)); |
1f587329 | 2736 | gen_op_store_QT0_fpr(QFPREG(rd)); |
dcf24905 | 2737 | gen_set_label(l1); |
1f587329 BS |
2738 | break; |
2739 | #else | |
0f8a249a | 2740 | goto nfpu_insn; |
1f587329 | 2741 | #endif |
0f8a249a BS |
2742 | } |
2743 | #endif | |
2744 | switch (xop) { | |
3475187d | 2745 | #ifdef TARGET_SPARC64 |
19f329ad BS |
2746 | #define FMOVCC(size_FDQ, fcc) \ |
2747 | { \ | |
0425bee5 | 2748 | TCGv r_cond; \ |
19f329ad BS |
2749 | int l1; \ |
2750 | \ | |
2751 | l1 = gen_new_label(); \ | |
19f329ad | 2752 | r_cond = tcg_temp_new(TCG_TYPE_TL); \ |
19f329ad BS |
2753 | cond = GET_FIELD_SP(insn, 14, 17); \ |
2754 | gen_fcond(r_cond, fcc, cond); \ | |
0425bee5 BS |
2755 | tcg_gen_brcond_tl(TCG_COND_EQ, r_cond, \ |
2756 | tcg_const_tl(0), l1); \ | |
19f329ad BS |
2757 | glue(glue(gen_op_load_fpr_, size_FDQ), T0)(glue(size_FDQ, FPREG(rs2))); \ |
2758 | glue(glue(gen_op_store_, size_FDQ), T0_fpr)(glue(size_FDQ, FPREG(rd))); \ | |
2759 | gen_set_label(l1); \ | |
0425bee5 | 2760 | tcg_gen_discard_tl(r_cond); \ |
19f329ad | 2761 | } |
0f8a249a | 2762 | case 0x001: /* V9 fmovscc %fcc0 */ |
19f329ad | 2763 | FMOVCC(F, 0); |
0f8a249a BS |
2764 | break; |
2765 | case 0x002: /* V9 fmovdcc %fcc0 */ | |
19f329ad | 2766 | FMOVCC(D, 0); |
0f8a249a BS |
2767 | break; |
2768 | case 0x003: /* V9 fmovqcc %fcc0 */ | |
1f587329 | 2769 | #if defined(CONFIG_USER_ONLY) |
19f329ad | 2770 | FMOVCC(Q, 0); |
1f587329 BS |
2771 | break; |
2772 | #else | |
0f8a249a | 2773 | goto nfpu_insn; |
1f587329 | 2774 | #endif |
0f8a249a | 2775 | case 0x041: /* V9 fmovscc %fcc1 */ |
19f329ad | 2776 | FMOVCC(F, 1); |
0f8a249a BS |
2777 | break; |
2778 | case 0x042: /* V9 fmovdcc %fcc1 */ | |
19f329ad | 2779 | FMOVCC(D, 1); |
0f8a249a BS |
2780 | break; |
2781 | case 0x043: /* V9 fmovqcc %fcc1 */ | |
1f587329 | 2782 | #if defined(CONFIG_USER_ONLY) |
19f329ad | 2783 | FMOVCC(Q, 1); |
1f587329 BS |
2784 | break; |
2785 | #else | |
0f8a249a | 2786 | goto nfpu_insn; |
1f587329 | 2787 | #endif |
0f8a249a | 2788 | case 0x081: /* V9 fmovscc %fcc2 */ |
19f329ad | 2789 | FMOVCC(F, 2); |
0f8a249a BS |
2790 | break; |
2791 | case 0x082: /* V9 fmovdcc %fcc2 */ | |
19f329ad | 2792 | FMOVCC(D, 2); |
0f8a249a BS |
2793 | break; |
2794 | case 0x083: /* V9 fmovqcc %fcc2 */ | |
1f587329 | 2795 | #if defined(CONFIG_USER_ONLY) |
19f329ad | 2796 | FMOVCC(Q, 2); |
1f587329 BS |
2797 | break; |
2798 | #else | |
0f8a249a | 2799 | goto nfpu_insn; |
1f587329 | 2800 | #endif |
0f8a249a | 2801 | case 0x0c1: /* V9 fmovscc %fcc3 */ |
19f329ad | 2802 | FMOVCC(F, 3); |
0f8a249a BS |
2803 | break; |
2804 | case 0x0c2: /* V9 fmovdcc %fcc3 */ | |
19f329ad | 2805 | FMOVCC(D, 3); |
0f8a249a BS |
2806 | break; |
2807 | case 0x0c3: /* V9 fmovqcc %fcc3 */ | |
1f587329 | 2808 | #if defined(CONFIG_USER_ONLY) |
19f329ad | 2809 | FMOVCC(Q, 3); |
1f587329 BS |
2810 | break; |
2811 | #else | |
0f8a249a | 2812 | goto nfpu_insn; |
1f587329 | 2813 | #endif |
19f329ad BS |
2814 | #undef FMOVCC |
2815 | #define FMOVCC(size_FDQ, icc) \ | |
2816 | { \ | |
0425bee5 | 2817 | TCGv r_cond; \ |
19f329ad BS |
2818 | int l1; \ |
2819 | \ | |
2820 | l1 = gen_new_label(); \ | |
19f329ad | 2821 | r_cond = tcg_temp_new(TCG_TYPE_TL); \ |
19f329ad BS |
2822 | cond = GET_FIELD_SP(insn, 14, 17); \ |
2823 | gen_cond(r_cond, icc, cond); \ | |
0425bee5 BS |
2824 | tcg_gen_brcond_tl(TCG_COND_EQ, r_cond, \ |
2825 | tcg_const_tl(0), l1); \ | |
19f329ad BS |
2826 | glue(glue(gen_op_load_fpr_, size_FDQ), T0)(glue(size_FDQ, FPREG(rs2))); \ |
2827 | glue(glue(gen_op_store_, size_FDQ), T0_fpr)(glue(size_FDQ, FPREG(rd))); \ | |
2828 | gen_set_label(l1); \ | |
0425bee5 | 2829 | tcg_gen_discard_tl(r_cond); \ |
19f329ad BS |
2830 | } |
2831 | ||
0f8a249a | 2832 | case 0x101: /* V9 fmovscc %icc */ |
19f329ad | 2833 | FMOVCC(F, 0); |
0f8a249a BS |
2834 | break; |
2835 | case 0x102: /* V9 fmovdcc %icc */ | |
19f329ad | 2836 | FMOVCC(D, 0); |
0f8a249a | 2837 | case 0x103: /* V9 fmovqcc %icc */ |
1f587329 | 2838 | #if defined(CONFIG_USER_ONLY) |
19f329ad | 2839 | FMOVCC(D, 0); |
1f587329 BS |
2840 | break; |
2841 | #else | |
0f8a249a | 2842 | goto nfpu_insn; |
1f587329 | 2843 | #endif |
0f8a249a | 2844 | case 0x181: /* V9 fmovscc %xcc */ |
19f329ad | 2845 | FMOVCC(F, 1); |
0f8a249a BS |
2846 | break; |
2847 | case 0x182: /* V9 fmovdcc %xcc */ | |
19f329ad | 2848 | FMOVCC(D, 1); |
0f8a249a BS |
2849 | break; |
2850 | case 0x183: /* V9 fmovqcc %xcc */ | |
1f587329 | 2851 | #if defined(CONFIG_USER_ONLY) |
19f329ad | 2852 | FMOVCC(Q, 1); |
1f587329 BS |
2853 | break; |
2854 | #else | |
0f8a249a BS |
2855 | goto nfpu_insn; |
2856 | #endif | |
19f329ad | 2857 | #undef FMOVCC |
1f587329 BS |
2858 | #endif |
2859 | case 0x51: /* fcmps, V9 %fcc */ | |
0f8a249a BS |
2860 | gen_op_load_fpr_FT0(rs1); |
2861 | gen_op_load_fpr_FT1(rs2); | |
7e8c2b6c | 2862 | gen_op_fcmps(rd & 3); |
0f8a249a | 2863 | break; |
1f587329 | 2864 | case 0x52: /* fcmpd, V9 %fcc */ |
0f8a249a BS |
2865 | gen_op_load_fpr_DT0(DFPREG(rs1)); |
2866 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
7e8c2b6c | 2867 | gen_op_fcmpd(rd & 3); |
0f8a249a | 2868 | break; |
1f587329 BS |
2869 | case 0x53: /* fcmpq, V9 %fcc */ |
2870 | #if defined(CONFIG_USER_ONLY) | |
2871 | gen_op_load_fpr_QT0(QFPREG(rs1)); | |
2872 | gen_op_load_fpr_QT1(QFPREG(rs2)); | |
7e8c2b6c | 2873 | gen_op_fcmpq(rd & 3); |
1f587329 BS |
2874 | break; |
2875 | #else /* !defined(CONFIG_USER_ONLY) */ | |
0f8a249a | 2876 | goto nfpu_insn; |
1f587329 | 2877 | #endif |
0f8a249a BS |
2878 | case 0x55: /* fcmpes, V9 %fcc */ |
2879 | gen_op_load_fpr_FT0(rs1); | |
2880 | gen_op_load_fpr_FT1(rs2); | |
7e8c2b6c | 2881 | gen_op_fcmpes(rd & 3); |
0f8a249a BS |
2882 | break; |
2883 | case 0x56: /* fcmped, V9 %fcc */ | |
2884 | gen_op_load_fpr_DT0(DFPREG(rs1)); | |
2885 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
7e8c2b6c | 2886 | gen_op_fcmped(rd & 3); |
0f8a249a | 2887 | break; |
1f587329 BS |
2888 | case 0x57: /* fcmpeq, V9 %fcc */ |
2889 | #if defined(CONFIG_USER_ONLY) | |
2890 | gen_op_load_fpr_QT0(QFPREG(rs1)); | |
2891 | gen_op_load_fpr_QT1(QFPREG(rs2)); | |
7e8c2b6c | 2892 | gen_op_fcmpeq(rd & 3); |
1f587329 BS |
2893 | break; |
2894 | #else/* !defined(CONFIG_USER_ONLY) */ | |
0f8a249a | 2895 | goto nfpu_insn; |
1f587329 | 2896 | #endif |
0f8a249a BS |
2897 | default: |
2898 | goto illegal_insn; | |
2899 | } | |
e80cfcfc | 2900 | #if defined(OPTIM) |
0f8a249a BS |
2901 | } else if (xop == 0x2) { |
2902 | // clr/mov shortcut | |
e80cfcfc FB |
2903 | |
2904 | rs1 = GET_FIELD(insn, 13, 17); | |
0f8a249a | 2905 | if (rs1 == 0) { |
1a2fb1c0 | 2906 | // or %g0, x, y -> mov T0, x; mov y, T0 |
0f8a249a BS |
2907 | if (IS_IMM) { /* immediate */ |
2908 | rs2 = GET_FIELDs(insn, 19, 31); | |
1a2fb1c0 | 2909 | tcg_gen_movi_tl(cpu_T[0], (int)rs2); |
0f8a249a BS |
2910 | } else { /* register */ |
2911 | rs2 = GET_FIELD(insn, 27, 31); | |
1a2fb1c0 | 2912 | gen_movl_reg_T0(rs2); |
0f8a249a | 2913 | } |
0f8a249a BS |
2914 | } else { |
2915 | gen_movl_reg_T0(rs1); | |
2916 | if (IS_IMM) { /* immediate */ | |
0f8a249a | 2917 | rs2 = GET_FIELDs(insn, 19, 31); |
1a2fb1c0 | 2918 | tcg_gen_ori_tl(cpu_T[0], cpu_T[0], (int)rs2); |
0f8a249a BS |
2919 | } else { /* register */ |
2920 | // or x, %g0, y -> mov T1, x; mov y, T1 | |
2921 | rs2 = GET_FIELD(insn, 27, 31); | |
2922 | if (rs2 != 0) { | |
2923 | gen_movl_reg_T1(rs2); | |
2924 | gen_op_or_T1_T0(); | |
2925 | } | |
2926 | } | |
0f8a249a | 2927 | } |
1a2fb1c0 | 2928 | gen_movl_T0_reg(rd); |
83469015 FB |
2929 | #endif |
2930 | #ifdef TARGET_SPARC64 | |
0f8a249a | 2931 | } else if (xop == 0x25) { /* sll, V9 sllx */ |
83469015 | 2932 | rs1 = GET_FIELD(insn, 13, 17); |
0f8a249a BS |
2933 | gen_movl_reg_T0(rs1); |
2934 | if (IS_IMM) { /* immediate */ | |
83469015 | 2935 | rs2 = GET_FIELDs(insn, 20, 31); |
1a2fb1c0 BS |
2936 | if (insn & (1 << 12)) { |
2937 | tcg_gen_shli_i64(cpu_T[0], cpu_T[0], rs2 & 0x3f); | |
2938 | } else { | |
2939 | tcg_gen_andi_i64(cpu_T[0], cpu_T[0], 0xffffffffULL); | |
2940 | tcg_gen_shli_i64(cpu_T[0], cpu_T[0], rs2 & 0x1f); | |
2941 | } | |
0f8a249a | 2942 | } else { /* register */ |
83469015 FB |
2943 | rs2 = GET_FIELD(insn, 27, 31); |
2944 | gen_movl_reg_T1(rs2); | |
1a2fb1c0 BS |
2945 | if (insn & (1 << 12)) { |
2946 | tcg_gen_andi_i64(cpu_T[1], cpu_T[1], 0x3f); | |
2947 | tcg_gen_shl_i64(cpu_T[0], cpu_T[0], cpu_T[1]); | |
2948 | } else { | |
2949 | tcg_gen_andi_i64(cpu_T[1], cpu_T[1], 0x1f); | |
2950 | tcg_gen_andi_i64(cpu_T[0], cpu_T[0], 0xffffffffULL); | |
2951 | tcg_gen_shl_i64(cpu_T[0], cpu_T[0], cpu_T[1]); | |
2952 | } | |
83469015 | 2953 | } |
0f8a249a BS |
2954 | gen_movl_T0_reg(rd); |
2955 | } else if (xop == 0x26) { /* srl, V9 srlx */ | |
83469015 | 2956 | rs1 = GET_FIELD(insn, 13, 17); |
0f8a249a BS |
2957 | gen_movl_reg_T0(rs1); |
2958 | if (IS_IMM) { /* immediate */ | |
83469015 | 2959 | rs2 = GET_FIELDs(insn, 20, 31); |
1a2fb1c0 BS |
2960 | if (insn & (1 << 12)) { |
2961 | tcg_gen_shri_i64(cpu_T[0], cpu_T[0], rs2 & 0x3f); | |
2962 | } else { | |
2963 | tcg_gen_andi_i64(cpu_T[0], cpu_T[0], 0xffffffffULL); | |
2964 | tcg_gen_shri_i64(cpu_T[0], cpu_T[0], rs2 & 0x1f); | |
2965 | } | |
0f8a249a | 2966 | } else { /* register */ |
83469015 FB |
2967 | rs2 = GET_FIELD(insn, 27, 31); |
2968 | gen_movl_reg_T1(rs2); | |
1a2fb1c0 BS |
2969 | if (insn & (1 << 12)) { |
2970 | tcg_gen_andi_i64(cpu_T[1], cpu_T[1], 0x3f); | |
2971 | tcg_gen_shr_i64(cpu_T[0], cpu_T[0], cpu_T[1]); | |
2972 | } else { | |
2973 | tcg_gen_andi_i64(cpu_T[1], cpu_T[1], 0x1f); | |
2974 | tcg_gen_andi_i64(cpu_T[0], cpu_T[0], 0xffffffffULL); | |
2975 | tcg_gen_shr_i64(cpu_T[0], cpu_T[0], cpu_T[1]); | |
2976 | } | |
83469015 | 2977 | } |
0f8a249a BS |
2978 | gen_movl_T0_reg(rd); |
2979 | } else if (xop == 0x27) { /* sra, V9 srax */ | |
83469015 | 2980 | rs1 = GET_FIELD(insn, 13, 17); |
0f8a249a BS |
2981 | gen_movl_reg_T0(rs1); |
2982 | if (IS_IMM) { /* immediate */ | |
83469015 | 2983 | rs2 = GET_FIELDs(insn, 20, 31); |
1a2fb1c0 BS |
2984 | if (insn & (1 << 12)) { |
2985 | tcg_gen_sari_i64(cpu_T[0], cpu_T[0], rs2 & 0x3f); | |
2986 | } else { | |
2987 | tcg_gen_andi_i64(cpu_T[0], cpu_T[0], 0xffffffffULL); | |
2988 | tcg_gen_ext_i32_i64(cpu_T[0], cpu_T[0]); | |
2989 | tcg_gen_sari_i64(cpu_T[0], cpu_T[0], rs2 & 0x1f); | |
2990 | } | |
0f8a249a | 2991 | } else { /* register */ |
83469015 FB |
2992 | rs2 = GET_FIELD(insn, 27, 31); |
2993 | gen_movl_reg_T1(rs2); | |
1a2fb1c0 BS |
2994 | if (insn & (1 << 12)) { |
2995 | tcg_gen_andi_i64(cpu_T[1], cpu_T[1], 0x3f); | |
2996 | tcg_gen_sar_i64(cpu_T[0], cpu_T[0], cpu_T[1]); | |
2997 | } else { | |
2998 | tcg_gen_andi_i64(cpu_T[1], cpu_T[1], 0x1f); | |
2999 | tcg_gen_andi_i64(cpu_T[0], cpu_T[0], 0xffffffffULL); | |
3000 | tcg_gen_sar_i64(cpu_T[0], cpu_T[0], cpu_T[1]); | |
3001 | } | |
83469015 | 3002 | } |
0f8a249a | 3003 | gen_movl_T0_reg(rd); |
e80cfcfc | 3004 | #endif |
fcc72045 | 3005 | } else if (xop < 0x36) { |
e80cfcfc | 3006 | rs1 = GET_FIELD(insn, 13, 17); |
0f8a249a BS |
3007 | gen_movl_reg_T0(rs1); |
3008 | if (IS_IMM) { /* immediate */ | |
cf495bcf | 3009 | rs2 = GET_FIELDs(insn, 19, 31); |
3475187d | 3010 | gen_movl_simm_T1(rs2); |
0f8a249a | 3011 | } else { /* register */ |
cf495bcf FB |
3012 | rs2 = GET_FIELD(insn, 27, 31); |
3013 | gen_movl_reg_T1(rs2); | |
3014 | } | |
3015 | if (xop < 0x20) { | |
3016 | switch (xop & ~0x10) { | |
3017 | case 0x0: | |
3018 | if (xop & 0x10) | |
3019 | gen_op_add_T1_T0_cc(); | |
3020 | else | |
3021 | gen_op_add_T1_T0(); | |
3022 | break; | |
3023 | case 0x1: | |
1a2fb1c0 | 3024 | tcg_gen_and_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
cf495bcf FB |
3025 | if (xop & 0x10) |
3026 | gen_op_logic_T0_cc(); | |
3027 | break; | |
3028 | case 0x2: | |
1a2fb1c0 | 3029 | tcg_gen_or_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
0f8a249a BS |
3030 | if (xop & 0x10) |
3031 | gen_op_logic_T0_cc(); | |
3032 | break; | |
cf495bcf | 3033 | case 0x3: |
1a2fb1c0 | 3034 | tcg_gen_xor_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
cf495bcf FB |
3035 | if (xop & 0x10) |
3036 | gen_op_logic_T0_cc(); | |
3037 | break; | |
3038 | case 0x4: | |
3039 | if (xop & 0x10) | |
3040 | gen_op_sub_T1_T0_cc(); | |
3041 | else | |
1a2fb1c0 | 3042 | tcg_gen_sub_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
cf495bcf FB |
3043 | break; |
3044 | case 0x5: | |
56ec06bb BS |
3045 | tcg_gen_xori_tl(cpu_T[1], cpu_T[1], -1); |
3046 | tcg_gen_and_tl(cpu_T[0], cpu_T[0], cpu_T[1]); | |
cf495bcf FB |
3047 | if (xop & 0x10) |
3048 | gen_op_logic_T0_cc(); | |
3049 | break; | |
3050 | case 0x6: | |
56ec06bb BS |
3051 | tcg_gen_xori_tl(cpu_T[1], cpu_T[1], -1); |
3052 | tcg_gen_or_tl(cpu_T[0], cpu_T[0], cpu_T[1]); | |
cf495bcf FB |
3053 | if (xop & 0x10) |
3054 | gen_op_logic_T0_cc(); | |
3055 | break; | |
3056 | case 0x7: | |
56ec06bb BS |
3057 | tcg_gen_xori_tl(cpu_T[1], cpu_T[1], -1); |
3058 | tcg_gen_xor_tl(cpu_T[0], cpu_T[0], cpu_T[1]); | |
cf495bcf FB |
3059 | if (xop & 0x10) |
3060 | gen_op_logic_T0_cc(); | |
3061 | break; | |
3062 | case 0x8: | |
cf495bcf | 3063 | if (xop & 0x10) |
af7bf89b | 3064 | gen_op_addx_T1_T0_cc(); |
38bc628b | 3065 | else { |
dc99a3f2 | 3066 | gen_mov_reg_C(cpu_tmp0, cpu_psr); |
38bc628b BS |
3067 | tcg_gen_add_tl(cpu_T[1], cpu_T[1], cpu_tmp0); |
3068 | tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]); | |
3069 | } | |
cf495bcf | 3070 | break; |
ded3ab80 | 3071 | #ifdef TARGET_SPARC64 |
0f8a249a | 3072 | case 0x9: /* V9 mulx */ |
1a2fb1c0 | 3073 | tcg_gen_mul_i64(cpu_T[0], cpu_T[0], cpu_T[1]); |
ded3ab80 PB |
3074 | break; |
3075 | #endif | |
cf495bcf FB |
3076 | case 0xa: |
3077 | gen_op_umul_T1_T0(); | |
3078 | if (xop & 0x10) | |
3079 | gen_op_logic_T0_cc(); | |
3080 | break; | |
3081 | case 0xb: | |
3082 | gen_op_smul_T1_T0(); | |
3083 | if (xop & 0x10) | |
3084 | gen_op_logic_T0_cc(); | |
3085 | break; | |
3086 | case 0xc: | |
cf495bcf | 3087 | if (xop & 0x10) |
af7bf89b | 3088 | gen_op_subx_T1_T0_cc(); |
38bc628b | 3089 | else { |
dc99a3f2 | 3090 | gen_mov_reg_C(cpu_tmp0, cpu_psr); |
38bc628b BS |
3091 | tcg_gen_add_tl(cpu_T[1], cpu_T[1], cpu_tmp0); |
3092 | tcg_gen_sub_tl(cpu_T[0], cpu_T[0], cpu_T[1]); | |
3093 | } | |
cf495bcf | 3094 | break; |
ded3ab80 | 3095 | #ifdef TARGET_SPARC64 |
0f8a249a | 3096 | case 0xd: /* V9 udivx */ |
8911f501 | 3097 | gen_trap_ifdivzero_tl(cpu_T[1]); |
1a7b60e7 | 3098 | tcg_gen_divu_i64(cpu_T[0], cpu_T[0], cpu_T[1]); |
ded3ab80 PB |
3099 | break; |
3100 | #endif | |
cf495bcf FB |
3101 | case 0xe: |
3102 | gen_op_udiv_T1_T0(); | |
3103 | if (xop & 0x10) | |
3104 | gen_op_div_cc(); | |
3105 | break; | |
3106 | case 0xf: | |
3107 | gen_op_sdiv_T1_T0(); | |
3108 | if (xop & 0x10) | |
3109 | gen_op_div_cc(); | |
3110 | break; | |
3111 | default: | |
3112 | goto illegal_insn; | |
3113 | } | |
0f8a249a | 3114 | gen_movl_T0_reg(rd); |
cf495bcf FB |
3115 | } else { |
3116 | switch (xop) { | |
0f8a249a BS |
3117 | case 0x20: /* taddcc */ |
3118 | gen_op_tadd_T1_T0_cc(); | |
3119 | gen_movl_T0_reg(rd); | |
3120 | break; | |
3121 | case 0x21: /* tsubcc */ | |
3122 | gen_op_tsub_T1_T0_cc(); | |
3123 | gen_movl_T0_reg(rd); | |
3124 | break; | |
3125 | case 0x22: /* taddcctv */ | |
90251fb9 | 3126 | save_state(dc); |
0f8a249a BS |
3127 | gen_op_tadd_T1_T0_ccTV(); |
3128 | gen_movl_T0_reg(rd); | |
3129 | break; | |
3130 | case 0x23: /* tsubcctv */ | |
90251fb9 | 3131 | save_state(dc); |
0f8a249a BS |
3132 | gen_op_tsub_T1_T0_ccTV(); |
3133 | gen_movl_T0_reg(rd); | |
3134 | break; | |
cf495bcf FB |
3135 | case 0x24: /* mulscc */ |
3136 | gen_op_mulscc_T1_T0(); | |
3137 | gen_movl_T0_reg(rd); | |
3138 | break; | |
83469015 | 3139 | #ifndef TARGET_SPARC64 |
0f8a249a | 3140 | case 0x25: /* sll */ |
8911f501 BS |
3141 | tcg_gen_andi_tl(cpu_T[1], cpu_T[1], 0x1f); |
3142 | tcg_gen_shl_tl(cpu_T[0], cpu_T[0], cpu_T[1]); | |
cf495bcf FB |
3143 | gen_movl_T0_reg(rd); |
3144 | break; | |
83469015 | 3145 | case 0x26: /* srl */ |
8911f501 BS |
3146 | tcg_gen_andi_tl(cpu_T[1], cpu_T[1], 0x1f); |
3147 | tcg_gen_shr_tl(cpu_T[0], cpu_T[0], cpu_T[1]); | |
cf495bcf FB |
3148 | gen_movl_T0_reg(rd); |
3149 | break; | |
83469015 | 3150 | case 0x27: /* sra */ |
8911f501 BS |
3151 | tcg_gen_andi_tl(cpu_T[1], cpu_T[1], 0x1f); |
3152 | tcg_gen_sar_tl(cpu_T[0], cpu_T[0], cpu_T[1]); | |
cf495bcf FB |
3153 | gen_movl_T0_reg(rd); |
3154 | break; | |
83469015 | 3155 | #endif |
cf495bcf FB |
3156 | case 0x30: |
3157 | { | |
cf495bcf | 3158 | switch(rd) { |
3475187d | 3159 | case 0: /* wry */ |
0f8a249a BS |
3160 | gen_op_xor_T1_T0(); |
3161 | gen_op_movtl_env_T0(offsetof(CPUSPARCState, y)); | |
cf495bcf | 3162 | break; |
65fe7b09 BS |
3163 | #ifndef TARGET_SPARC64 |
3164 | case 0x01 ... 0x0f: /* undefined in the | |
3165 | SPARCv8 manual, nop | |
3166 | on the microSPARC | |
3167 | II */ | |
3168 | case 0x10 ... 0x1f: /* implementation-dependent | |
3169 | in the SPARCv8 | |
3170 | manual, nop on the | |
3171 | microSPARC II */ | |
3172 | break; | |
3173 | #else | |
0f8a249a | 3174 | case 0x2: /* V9 wrccr */ |
ee0b03fd | 3175 | gen_op_xor_T1_T0(); |
d35527d9 | 3176 | tcg_gen_helper_0_1(helper_wrccr, cpu_T[0]); |
0f8a249a BS |
3177 | break; |
3178 | case 0x3: /* V9 wrasi */ | |
ee0b03fd | 3179 | gen_op_xor_T1_T0(); |
0f8a249a BS |
3180 | gen_op_movl_env_T0(offsetof(CPUSPARCState, asi)); |
3181 | break; | |
3182 | case 0x6: /* V9 wrfprs */ | |
3183 | gen_op_xor_T1_T0(); | |
3184 | gen_op_movl_env_T0(offsetof(CPUSPARCState, fprs)); | |
3299908c BS |
3185 | save_state(dc); |
3186 | gen_op_next_insn(); | |
57fec1fe | 3187 | tcg_gen_exit_tb(0); |
3299908c | 3188 | dc->is_br = 1; |
0f8a249a BS |
3189 | break; |
3190 | case 0xf: /* V9 sir, nop if user */ | |
3475187d | 3191 | #if !defined(CONFIG_USER_ONLY) |
0f8a249a | 3192 | if (supervisor(dc)) |
1a2fb1c0 | 3193 | ; // XXX |
3475187d | 3194 | #endif |
0f8a249a BS |
3195 | break; |
3196 | case 0x13: /* Graphics Status */ | |
725cb90b FB |
3197 | if (gen_trap_ifnofpu(dc)) |
3198 | goto jmp_insn; | |
ee0b03fd | 3199 | gen_op_xor_T1_T0(); |
0f8a249a BS |
3200 | gen_op_movtl_env_T0(offsetof(CPUSPARCState, gsr)); |
3201 | break; | |
3202 | case 0x17: /* Tick compare */ | |
83469015 | 3203 | #if !defined(CONFIG_USER_ONLY) |
0f8a249a BS |
3204 | if (!supervisor(dc)) |
3205 | goto illegal_insn; | |
83469015 | 3206 | #endif |
ccd4a219 BS |
3207 | { |
3208 | TCGv r_tickptr; | |
3209 | ||
3210 | gen_op_xor_T1_T0(); | |
3211 | gen_op_movtl_env_T0(offsetof(CPUSPARCState, | |
3212 | tick_cmpr)); | |
3213 | r_tickptr = tcg_temp_new(TCG_TYPE_PTR); | |
3214 | tcg_gen_ld_ptr(r_tickptr, cpu_env, | |
3215 | offsetof(CPUState, tick)); | |
3216 | tcg_gen_helper_0_2(helper_tick_set_limit, | |
3217 | r_tickptr, cpu_T[0]); | |
0425bee5 | 3218 | tcg_gen_discard_ptr(r_tickptr); |
ccd4a219 | 3219 | } |
0f8a249a BS |
3220 | break; |
3221 | case 0x18: /* System tick */ | |
83469015 | 3222 | #if !defined(CONFIG_USER_ONLY) |
0f8a249a BS |
3223 | if (!supervisor(dc)) |
3224 | goto illegal_insn; | |
83469015 | 3225 | #endif |
ccd4a219 BS |
3226 | { |
3227 | TCGv r_tickptr; | |
3228 | ||
3229 | gen_op_xor_T1_T0(); | |
3230 | r_tickptr = tcg_temp_new(TCG_TYPE_PTR); | |
3231 | tcg_gen_ld_ptr(r_tickptr, cpu_env, | |
3232 | offsetof(CPUState, stick)); | |
3233 | tcg_gen_helper_0_2(helper_tick_set_count, | |
3234 | r_tickptr, cpu_T[0]); | |
0425bee5 | 3235 | tcg_gen_discard_ptr(r_tickptr); |
ccd4a219 | 3236 | } |
0f8a249a BS |
3237 | break; |
3238 | case 0x19: /* System tick compare */ | |
83469015 | 3239 | #if !defined(CONFIG_USER_ONLY) |
0f8a249a BS |
3240 | if (!supervisor(dc)) |
3241 | goto illegal_insn; | |
3475187d | 3242 | #endif |
ccd4a219 BS |
3243 | { |
3244 | TCGv r_tickptr; | |
3245 | ||
3246 | gen_op_xor_T1_T0(); | |
3247 | gen_op_movtl_env_T0(offsetof(CPUSPARCState, | |
3248 | stick_cmpr)); | |
3249 | r_tickptr = tcg_temp_new(TCG_TYPE_PTR); | |
3250 | tcg_gen_ld_ptr(r_tickptr, cpu_env, | |
3251 | offsetof(CPUState, stick)); | |
3252 | tcg_gen_helper_0_2(helper_tick_set_limit, | |
3253 | r_tickptr, cpu_T[0]); | |
0425bee5 | 3254 | tcg_gen_discard_ptr(r_tickptr); |
ccd4a219 | 3255 | } |
0f8a249a | 3256 | break; |
83469015 | 3257 | |
0f8a249a BS |
3258 | case 0x10: /* Performance Control */ |
3259 | case 0x11: /* Performance Instrumentation Counter */ | |
3260 | case 0x12: /* Dispatch Control */ | |
3261 | case 0x14: /* Softint set */ | |
3262 | case 0x15: /* Softint clear */ | |
3263 | case 0x16: /* Softint write */ | |
83469015 | 3264 | #endif |
3475187d | 3265 | default: |
cf495bcf FB |
3266 | goto illegal_insn; |
3267 | } | |
3268 | } | |
3269 | break; | |
e8af50a3 | 3270 | #if !defined(CONFIG_USER_ONLY) |
af7bf89b | 3271 | case 0x31: /* wrpsr, V9 saved, restored */ |
e8af50a3 | 3272 | { |
0f8a249a BS |
3273 | if (!supervisor(dc)) |
3274 | goto priv_insn; | |
3475187d | 3275 | #ifdef TARGET_SPARC64 |
0f8a249a BS |
3276 | switch (rd) { |
3277 | case 0: | |
72a9747b | 3278 | tcg_gen_helper_0_0(helper_saved); |
0f8a249a BS |
3279 | break; |
3280 | case 1: | |
72a9747b | 3281 | tcg_gen_helper_0_0(helper_restored); |
0f8a249a | 3282 | break; |
e9ebed4d BS |
3283 | case 2: /* UA2005 allclean */ |
3284 | case 3: /* UA2005 otherw */ | |
3285 | case 4: /* UA2005 normalw */ | |
3286 | case 5: /* UA2005 invalw */ | |
3287 | // XXX | |
0f8a249a | 3288 | default: |
3475187d FB |
3289 | goto illegal_insn; |
3290 | } | |
3291 | #else | |
e8af50a3 | 3292 | gen_op_xor_T1_T0(); |
1a2fb1c0 | 3293 | tcg_gen_helper_0_1(helper_wrpsr, cpu_T[0]); |
9e61bde5 FB |
3294 | save_state(dc); |
3295 | gen_op_next_insn(); | |
57fec1fe | 3296 | tcg_gen_exit_tb(0); |
0f8a249a | 3297 | dc->is_br = 1; |
3475187d | 3298 | #endif |
e8af50a3 FB |
3299 | } |
3300 | break; | |
af7bf89b | 3301 | case 0x32: /* wrwim, V9 wrpr */ |
e8af50a3 | 3302 | { |
0f8a249a BS |
3303 | if (!supervisor(dc)) |
3304 | goto priv_insn; | |
e8af50a3 | 3305 | gen_op_xor_T1_T0(); |
3475187d | 3306 | #ifdef TARGET_SPARC64 |
0f8a249a BS |
3307 | switch (rd) { |
3308 | case 0: // tpc | |
375ee38b BS |
3309 | { |
3310 | TCGv r_tsptr; | |
3311 | ||
3312 | r_tsptr = tcg_temp_new(TCG_TYPE_PTR); | |
3313 | tcg_gen_ld_ptr(r_tsptr, cpu_env, | |
3314 | offsetof(CPUState, tsptr)); | |
3315 | tcg_gen_st_tl(cpu_T[0], r_tsptr, | |
3316 | offsetof(trap_state, tpc)); | |
0425bee5 | 3317 | tcg_gen_discard_ptr(r_tsptr); |
375ee38b | 3318 | } |
0f8a249a BS |
3319 | break; |
3320 | case 1: // tnpc | |
375ee38b BS |
3321 | { |
3322 | TCGv r_tsptr; | |
3323 | ||
3324 | r_tsptr = tcg_temp_new(TCG_TYPE_PTR); | |
3325 | tcg_gen_ld_ptr(r_tsptr, cpu_env, | |
3326 | offsetof(CPUState, tsptr)); | |
3327 | tcg_gen_st_tl(cpu_T[0], r_tsptr, | |
3328 | offsetof(trap_state, tnpc)); | |
0425bee5 | 3329 | tcg_gen_discard_ptr(r_tsptr); |
375ee38b | 3330 | } |
0f8a249a BS |
3331 | break; |
3332 | case 2: // tstate | |
375ee38b BS |
3333 | { |
3334 | TCGv r_tsptr; | |
3335 | ||
3336 | r_tsptr = tcg_temp_new(TCG_TYPE_PTR); | |
3337 | tcg_gen_ld_ptr(r_tsptr, cpu_env, | |
3338 | offsetof(CPUState, tsptr)); | |
3339 | tcg_gen_st_tl(cpu_T[0], r_tsptr, | |
3340 | offsetof(trap_state, tstate)); | |
0425bee5 | 3341 | tcg_gen_discard_ptr(r_tsptr); |
375ee38b | 3342 | } |
0f8a249a BS |
3343 | break; |
3344 | case 3: // tt | |
375ee38b BS |
3345 | { |
3346 | TCGv r_tsptr; | |
3347 | ||
3348 | r_tsptr = tcg_temp_new(TCG_TYPE_PTR); | |
3349 | tcg_gen_ld_ptr(r_tsptr, cpu_env, | |
3350 | offsetof(CPUState, tsptr)); | |
3351 | tcg_gen_st_i32(cpu_T[0], r_tsptr, | |
3352 | offsetof(trap_state, tt)); | |
0425bee5 | 3353 | tcg_gen_discard_ptr(r_tsptr); |
375ee38b | 3354 | } |
0f8a249a BS |
3355 | break; |
3356 | case 4: // tick | |
ccd4a219 BS |
3357 | { |
3358 | TCGv r_tickptr; | |
3359 | ||
3360 | r_tickptr = tcg_temp_new(TCG_TYPE_PTR); | |
3361 | tcg_gen_ld_ptr(r_tickptr, cpu_env, | |
3362 | offsetof(CPUState, tick)); | |
3363 | tcg_gen_helper_0_2(helper_tick_set_count, | |
3364 | r_tickptr, cpu_T[0]); | |
0425bee5 | 3365 | tcg_gen_discard_ptr(r_tickptr); |
ccd4a219 | 3366 | } |
0f8a249a BS |
3367 | break; |
3368 | case 5: // tba | |
3369 | gen_op_movtl_env_T0(offsetof(CPUSPARCState, tbr)); | |
3370 | break; | |
3371 | case 6: // pstate | |
ded3ab80 | 3372 | save_state(dc); |
1a2fb1c0 | 3373 | tcg_gen_helper_0_1(helper_wrpstate, cpu_T[0]); |
ded3ab80 | 3374 | gen_op_next_insn(); |
57fec1fe | 3375 | tcg_gen_exit_tb(0); |
ded3ab80 | 3376 | dc->is_br = 1; |
0f8a249a BS |
3377 | break; |
3378 | case 7: // tl | |
3379 | gen_op_movl_env_T0(offsetof(CPUSPARCState, tl)); | |
3380 | break; | |
3381 | case 8: // pil | |
3382 | gen_op_movl_env_T0(offsetof(CPUSPARCState, psrpil)); | |
3383 | break; | |
3384 | case 9: // cwp | |
d35527d9 | 3385 | tcg_gen_helper_0_1(helper_wrcwp, cpu_T[0]); |
0f8a249a BS |
3386 | break; |
3387 | case 10: // cansave | |
3388 | gen_op_movl_env_T0(offsetof(CPUSPARCState, cansave)); | |
3389 | break; | |
3390 | case 11: // canrestore | |
3391 | gen_op_movl_env_T0(offsetof(CPUSPARCState, canrestore)); | |
3392 | break; | |
3393 | case 12: // cleanwin | |
3394 | gen_op_movl_env_T0(offsetof(CPUSPARCState, cleanwin)); | |
3395 | break; | |
3396 | case 13: // otherwin | |
3397 | gen_op_movl_env_T0(offsetof(CPUSPARCState, otherwin)); | |
3398 | break; | |
3399 | case 14: // wstate | |
3400 | gen_op_movl_env_T0(offsetof(CPUSPARCState, wstate)); | |
3401 | break; | |
e9ebed4d BS |
3402 | case 16: // UA2005 gl |
3403 | gen_op_movl_env_T0(offsetof(CPUSPARCState, gl)); | |
3404 | break; | |
3405 | case 26: // UA2005 strand status | |
3406 | if (!hypervisor(dc)) | |
3407 | goto priv_insn; | |
3408 | gen_op_movl_env_T0(offsetof(CPUSPARCState, ssr)); | |
3409 | break; | |
0f8a249a BS |
3410 | default: |
3411 | goto illegal_insn; | |
3412 | } | |
3475187d | 3413 | #else |
8911f501 | 3414 | tcg_gen_andi_tl(cpu_T[0], cpu_T[0], ((1 << NWINDOWS) - 1)); |
1a2fb1c0 | 3415 | gen_op_movl_env_T0(offsetof(CPUSPARCState, wim)); |
3475187d | 3416 | #endif |
e8af50a3 FB |
3417 | } |
3418 | break; | |
e9ebed4d | 3419 | case 0x33: /* wrtbr, UA2005 wrhpr */ |
e8af50a3 | 3420 | { |
e9ebed4d | 3421 | #ifndef TARGET_SPARC64 |
0f8a249a BS |
3422 | if (!supervisor(dc)) |
3423 | goto priv_insn; | |
e8af50a3 | 3424 | gen_op_xor_T1_T0(); |
e9ebed4d BS |
3425 | gen_op_movtl_env_T0(offsetof(CPUSPARCState, tbr)); |
3426 | #else | |
3427 | if (!hypervisor(dc)) | |
3428 | goto priv_insn; | |
3429 | gen_op_xor_T1_T0(); | |
3430 | switch (rd) { | |
3431 | case 0: // hpstate | |
3432 | // XXX gen_op_wrhpstate(); | |
3433 | save_state(dc); | |
3434 | gen_op_next_insn(); | |
57fec1fe | 3435 | tcg_gen_exit_tb(0); |
e9ebed4d BS |
3436 | dc->is_br = 1; |
3437 | break; | |
3438 | case 1: // htstate | |
3439 | // XXX gen_op_wrhtstate(); | |
3440 | break; | |
3441 | case 3: // hintp | |
3442 | gen_op_movl_env_T0(offsetof(CPUSPARCState, hintp)); | |
3443 | break; | |
3444 | case 5: // htba | |
3445 | gen_op_movl_env_T0(offsetof(CPUSPARCState, htba)); | |
3446 | break; | |
3447 | case 31: // hstick_cmpr | |
ccd4a219 BS |
3448 | { |
3449 | TCGv r_tickptr; | |
3450 | ||
3451 | gen_op_movtl_env_T0(offsetof(CPUSPARCState, | |
3452 | hstick_cmpr)); | |
3453 | r_tickptr = tcg_temp_new(TCG_TYPE_PTR); | |
3454 | tcg_gen_ld_ptr(r_tickptr, cpu_env, | |
3455 | offsetof(CPUState, hstick)); | |
3456 | tcg_gen_helper_0_2(helper_tick_set_limit, | |
3457 | r_tickptr, cpu_T[0]); | |
0425bee5 | 3458 | tcg_gen_discard_ptr(r_tickptr); |
ccd4a219 | 3459 | } |
e9ebed4d BS |
3460 | break; |
3461 | case 6: // hver readonly | |
3462 | default: | |
3463 | goto illegal_insn; | |
3464 | } | |
3465 | #endif | |
e8af50a3 FB |
3466 | } |
3467 | break; | |
3468 | #endif | |
3475187d | 3469 | #ifdef TARGET_SPARC64 |
0f8a249a BS |
3470 | case 0x2c: /* V9 movcc */ |
3471 | { | |
3472 | int cc = GET_FIELD_SP(insn, 11, 12); | |
3473 | int cond = GET_FIELD_SP(insn, 14, 17); | |
748b9d8e | 3474 | TCGv r_cond; |
00f219bf BS |
3475 | int l1; |
3476 | ||
748b9d8e | 3477 | r_cond = tcg_temp_new(TCG_TYPE_TL); |
0f8a249a BS |
3478 | if (insn & (1 << 18)) { |
3479 | if (cc == 0) | |
748b9d8e | 3480 | gen_cond(r_cond, 0, cond); |
0f8a249a | 3481 | else if (cc == 2) |
748b9d8e | 3482 | gen_cond(r_cond, 1, cond); |
0f8a249a BS |
3483 | else |
3484 | goto illegal_insn; | |
3485 | } else { | |
748b9d8e | 3486 | gen_fcond(r_cond, cc, cond); |
0f8a249a | 3487 | } |
00f219bf BS |
3488 | |
3489 | l1 = gen_new_label(); | |
3490 | ||
748b9d8e BS |
3491 | tcg_gen_brcond_tl(TCG_COND_EQ, r_cond, |
3492 | tcg_const_tl(0), l1); | |
00f219bf BS |
3493 | if (IS_IMM) { /* immediate */ |
3494 | rs2 = GET_FIELD_SPs(insn, 0, 10); | |
3495 | gen_movl_simm_T1(rs2); | |
3496 | } else { | |
3497 | rs2 = GET_FIELD_SP(insn, 0, 4); | |
3498 | gen_movl_reg_T1(rs2); | |
3499 | } | |
3500 | gen_movl_T1_reg(rd); | |
3501 | gen_set_label(l1); | |
0425bee5 | 3502 | tcg_gen_discard_tl(r_cond); |
0f8a249a BS |
3503 | break; |
3504 | } | |
3505 | case 0x2d: /* V9 sdivx */ | |
3475187d | 3506 | gen_op_sdivx_T1_T0(); |
0f8a249a BS |
3507 | gen_movl_T0_reg(rd); |
3508 | break; | |
3509 | case 0x2e: /* V9 popc */ | |
3510 | { | |
3511 | if (IS_IMM) { /* immediate */ | |
3512 | rs2 = GET_FIELD_SPs(insn, 0, 12); | |
3513 | gen_movl_simm_T1(rs2); | |
3514 | // XXX optimize: popc(constant) | |
3515 | } | |
3516 | else { | |
3517 | rs2 = GET_FIELD_SP(insn, 0, 4); | |
3518 | gen_movl_reg_T1(rs2); | |
3519 | } | |
1a2fb1c0 BS |
3520 | tcg_gen_helper_1_1(helper_popc, cpu_T[0], |
3521 | cpu_T[1]); | |
0f8a249a BS |
3522 | gen_movl_T0_reg(rd); |
3523 | } | |
3524 | case 0x2f: /* V9 movr */ | |
3525 | { | |
3526 | int cond = GET_FIELD_SP(insn, 10, 12); | |
00f219bf BS |
3527 | int l1; |
3528 | ||
0f8a249a | 3529 | rs1 = GET_FIELD(insn, 13, 17); |
0f8a249a | 3530 | gen_movl_reg_T0(rs1); |
00f219bf BS |
3531 | |
3532 | l1 = gen_new_label(); | |
3533 | ||
0425bee5 BS |
3534 | tcg_gen_brcond_tl(gen_tcg_cond_reg[cond], cpu_T[0], |
3535 | tcg_const_tl(0), l1); | |
0f8a249a BS |
3536 | if (IS_IMM) { /* immediate */ |
3537 | rs2 = GET_FIELD_SPs(insn, 0, 9); | |
3538 | gen_movl_simm_T1(rs2); | |
00f219bf | 3539 | } else { |
0f8a249a BS |
3540 | rs2 = GET_FIELD_SP(insn, 0, 4); |
3541 | gen_movl_reg_T1(rs2); | |
3542 | } | |
00f219bf BS |
3543 | gen_movl_T1_reg(rd); |
3544 | gen_set_label(l1); | |
0f8a249a BS |
3545 | break; |
3546 | } | |
3547 | #endif | |
3548 | default: | |
3549 | goto illegal_insn; | |
3550 | } | |
3551 | } | |
3299908c BS |
3552 | } else if (xop == 0x36) { /* UltraSparc shutdown, VIS, V8 CPop1 */ |
3553 | #ifdef TARGET_SPARC64 | |
3554 | int opf = GET_FIELD_SP(insn, 5, 13); | |
3555 | rs1 = GET_FIELD(insn, 13, 17); | |
3556 | rs2 = GET_FIELD(insn, 27, 31); | |
e9ebed4d BS |
3557 | if (gen_trap_ifnofpu(dc)) |
3558 | goto jmp_insn; | |
3299908c BS |
3559 | |
3560 | switch (opf) { | |
e9ebed4d BS |
3561 | case 0x000: /* VIS I edge8cc */ |
3562 | case 0x001: /* VIS II edge8n */ | |
3563 | case 0x002: /* VIS I edge8lcc */ | |
3564 | case 0x003: /* VIS II edge8ln */ | |
3565 | case 0x004: /* VIS I edge16cc */ | |
3566 | case 0x005: /* VIS II edge16n */ | |
3567 | case 0x006: /* VIS I edge16lcc */ | |
3568 | case 0x007: /* VIS II edge16ln */ | |
3569 | case 0x008: /* VIS I edge32cc */ | |
3570 | case 0x009: /* VIS II edge32n */ | |
3571 | case 0x00a: /* VIS I edge32lcc */ | |
3572 | case 0x00b: /* VIS II edge32ln */ | |
3573 | // XXX | |
3574 | goto illegal_insn; | |
3575 | case 0x010: /* VIS I array8 */ | |
3576 | gen_movl_reg_T0(rs1); | |
3577 | gen_movl_reg_T1(rs2); | |
1f5063fb BS |
3578 | tcg_gen_helper_1_2(helper_array8, cpu_T[0], cpu_T[0], |
3579 | cpu_T[1]); | |
e9ebed4d BS |
3580 | gen_movl_T0_reg(rd); |
3581 | break; | |
3582 | case 0x012: /* VIS I array16 */ | |
3583 | gen_movl_reg_T0(rs1); | |
3584 | gen_movl_reg_T1(rs2); | |
1f5063fb BS |
3585 | tcg_gen_helper_1_2(helper_array8, cpu_T[0], cpu_T[0], |
3586 | cpu_T[1]); | |
3587 | tcg_gen_shli_i64(cpu_T[0], cpu_T[0], 1); | |
e9ebed4d BS |
3588 | gen_movl_T0_reg(rd); |
3589 | break; | |
3590 | case 0x014: /* VIS I array32 */ | |
3591 | gen_movl_reg_T0(rs1); | |
3592 | gen_movl_reg_T1(rs2); | |
1f5063fb BS |
3593 | tcg_gen_helper_1_2(helper_array8, cpu_T[0], cpu_T[0], |
3594 | cpu_T[1]); | |
3595 | tcg_gen_shli_i64(cpu_T[0], cpu_T[0], 2); | |
e9ebed4d BS |
3596 | gen_movl_T0_reg(rd); |
3597 | break; | |
3299908c | 3598 | case 0x018: /* VIS I alignaddr */ |
3299908c BS |
3599 | gen_movl_reg_T0(rs1); |
3600 | gen_movl_reg_T1(rs2); | |
1f5063fb BS |
3601 | tcg_gen_helper_1_2(helper_alignaddr, cpu_T[0], cpu_T[0], |
3602 | cpu_T[1]); | |
3299908c BS |
3603 | gen_movl_T0_reg(rd); |
3604 | break; | |
e9ebed4d | 3605 | case 0x019: /* VIS II bmask */ |
3299908c | 3606 | case 0x01a: /* VIS I alignaddrl */ |
3299908c | 3607 | // XXX |
e9ebed4d BS |
3608 | goto illegal_insn; |
3609 | case 0x020: /* VIS I fcmple16 */ | |
2382dc6b BS |
3610 | gen_op_load_fpr_DT0(DFPREG(rs1)); |
3611 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
44e7757c | 3612 | tcg_gen_helper_0_0(helper_fcmple16); |
2382dc6b | 3613 | gen_op_store_DT0_fpr(DFPREG(rd)); |
e9ebed4d BS |
3614 | break; |
3615 | case 0x022: /* VIS I fcmpne16 */ | |
2382dc6b BS |
3616 | gen_op_load_fpr_DT0(DFPREG(rs1)); |
3617 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
44e7757c | 3618 | tcg_gen_helper_0_0(helper_fcmpne16); |
2382dc6b | 3619 | gen_op_store_DT0_fpr(DFPREG(rd)); |
3299908c | 3620 | break; |
e9ebed4d | 3621 | case 0x024: /* VIS I fcmple32 */ |
2382dc6b BS |
3622 | gen_op_load_fpr_DT0(DFPREG(rs1)); |
3623 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
44e7757c | 3624 | tcg_gen_helper_0_0(helper_fcmple32); |
2382dc6b | 3625 | gen_op_store_DT0_fpr(DFPREG(rd)); |
e9ebed4d BS |
3626 | break; |
3627 | case 0x026: /* VIS I fcmpne32 */ | |
2382dc6b BS |
3628 | gen_op_load_fpr_DT0(DFPREG(rs1)); |
3629 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
44e7757c | 3630 | tcg_gen_helper_0_0(helper_fcmpne32); |
2382dc6b | 3631 | gen_op_store_DT0_fpr(DFPREG(rd)); |
e9ebed4d BS |
3632 | break; |
3633 | case 0x028: /* VIS I fcmpgt16 */ | |
2382dc6b BS |
3634 | gen_op_load_fpr_DT0(DFPREG(rs1)); |
3635 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
44e7757c | 3636 | tcg_gen_helper_0_0(helper_fcmpgt16); |
2382dc6b | 3637 | gen_op_store_DT0_fpr(DFPREG(rd)); |
e9ebed4d BS |
3638 | break; |
3639 | case 0x02a: /* VIS I fcmpeq16 */ | |
2382dc6b BS |
3640 | gen_op_load_fpr_DT0(DFPREG(rs1)); |
3641 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
44e7757c | 3642 | tcg_gen_helper_0_0(helper_fcmpeq16); |
2382dc6b | 3643 | gen_op_store_DT0_fpr(DFPREG(rd)); |
e9ebed4d BS |
3644 | break; |
3645 | case 0x02c: /* VIS I fcmpgt32 */ | |
2382dc6b BS |
3646 | gen_op_load_fpr_DT0(DFPREG(rs1)); |
3647 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
44e7757c | 3648 | tcg_gen_helper_0_0(helper_fcmpgt32); |
2382dc6b | 3649 | gen_op_store_DT0_fpr(DFPREG(rd)); |
e9ebed4d BS |
3650 | break; |
3651 | case 0x02e: /* VIS I fcmpeq32 */ | |
2382dc6b BS |
3652 | gen_op_load_fpr_DT0(DFPREG(rs1)); |
3653 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
44e7757c | 3654 | tcg_gen_helper_0_0(helper_fcmpeq32); |
2382dc6b | 3655 | gen_op_store_DT0_fpr(DFPREG(rd)); |
e9ebed4d BS |
3656 | break; |
3657 | case 0x031: /* VIS I fmul8x16 */ | |
2382dc6b BS |
3658 | gen_op_load_fpr_DT0(DFPREG(rs1)); |
3659 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
44e7757c | 3660 | tcg_gen_helper_0_0(helper_fmul8x16); |
2382dc6b | 3661 | gen_op_store_DT0_fpr(DFPREG(rd)); |
e9ebed4d BS |
3662 | break; |
3663 | case 0x033: /* VIS I fmul8x16au */ | |
2382dc6b BS |
3664 | gen_op_load_fpr_DT0(DFPREG(rs1)); |
3665 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
44e7757c | 3666 | tcg_gen_helper_0_0(helper_fmul8x16au); |
2382dc6b | 3667 | gen_op_store_DT0_fpr(DFPREG(rd)); |
e9ebed4d BS |
3668 | break; |
3669 | case 0x035: /* VIS I fmul8x16al */ | |
2382dc6b BS |
3670 | gen_op_load_fpr_DT0(DFPREG(rs1)); |
3671 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
44e7757c | 3672 | tcg_gen_helper_0_0(helper_fmul8x16al); |
2382dc6b | 3673 | gen_op_store_DT0_fpr(DFPREG(rd)); |
e9ebed4d BS |
3674 | break; |
3675 | case 0x036: /* VIS I fmul8sux16 */ | |
2382dc6b BS |
3676 | gen_op_load_fpr_DT0(DFPREG(rs1)); |
3677 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
44e7757c | 3678 | tcg_gen_helper_0_0(helper_fmul8sux16); |
2382dc6b | 3679 | gen_op_store_DT0_fpr(DFPREG(rd)); |
e9ebed4d BS |
3680 | break; |
3681 | case 0x037: /* VIS I fmul8ulx16 */ | |
2382dc6b BS |
3682 | gen_op_load_fpr_DT0(DFPREG(rs1)); |
3683 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
44e7757c | 3684 | tcg_gen_helper_0_0(helper_fmul8ulx16); |
2382dc6b | 3685 | gen_op_store_DT0_fpr(DFPREG(rd)); |
e9ebed4d BS |
3686 | break; |
3687 | case 0x038: /* VIS I fmuld8sux16 */ | |
2382dc6b BS |
3688 | gen_op_load_fpr_DT0(DFPREG(rs1)); |
3689 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
44e7757c | 3690 | tcg_gen_helper_0_0(helper_fmuld8sux16); |
2382dc6b | 3691 | gen_op_store_DT0_fpr(DFPREG(rd)); |
e9ebed4d BS |
3692 | break; |
3693 | case 0x039: /* VIS I fmuld8ulx16 */ | |
2382dc6b BS |
3694 | gen_op_load_fpr_DT0(DFPREG(rs1)); |
3695 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
44e7757c | 3696 | tcg_gen_helper_0_0(helper_fmuld8ulx16); |
2382dc6b | 3697 | gen_op_store_DT0_fpr(DFPREG(rd)); |
e9ebed4d BS |
3698 | break; |
3699 | case 0x03a: /* VIS I fpack32 */ | |
3700 | case 0x03b: /* VIS I fpack16 */ | |
3701 | case 0x03d: /* VIS I fpackfix */ | |
3702 | case 0x03e: /* VIS I pdist */ | |
3703 | // XXX | |
3704 | goto illegal_insn; | |
3299908c | 3705 | case 0x048: /* VIS I faligndata */ |
2382dc6b BS |
3706 | gen_op_load_fpr_DT0(DFPREG(rs1)); |
3707 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
44e7757c | 3708 | tcg_gen_helper_0_0(helper_faligndata); |
2382dc6b | 3709 | gen_op_store_DT0_fpr(DFPREG(rd)); |
3299908c | 3710 | break; |
e9ebed4d | 3711 | case 0x04b: /* VIS I fpmerge */ |
2382dc6b BS |
3712 | gen_op_load_fpr_DT0(DFPREG(rs1)); |
3713 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
44e7757c | 3714 | tcg_gen_helper_0_0(helper_fpmerge); |
2382dc6b | 3715 | gen_op_store_DT0_fpr(DFPREG(rd)); |
e9ebed4d BS |
3716 | break; |
3717 | case 0x04c: /* VIS II bshuffle */ | |
3718 | // XXX | |
3719 | goto illegal_insn; | |
3720 | case 0x04d: /* VIS I fexpand */ | |
2382dc6b BS |
3721 | gen_op_load_fpr_DT0(DFPREG(rs1)); |
3722 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
44e7757c | 3723 | tcg_gen_helper_0_0(helper_fexpand); |
2382dc6b | 3724 | gen_op_store_DT0_fpr(DFPREG(rd)); |
e9ebed4d BS |
3725 | break; |
3726 | case 0x050: /* VIS I fpadd16 */ | |
2382dc6b BS |
3727 | gen_op_load_fpr_DT0(DFPREG(rs1)); |
3728 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
44e7757c | 3729 | tcg_gen_helper_0_0(helper_fpadd16); |
2382dc6b | 3730 | gen_op_store_DT0_fpr(DFPREG(rd)); |
e9ebed4d BS |
3731 | break; |
3732 | case 0x051: /* VIS I fpadd16s */ | |
3733 | gen_op_load_fpr_FT0(rs1); | |
3734 | gen_op_load_fpr_FT1(rs2); | |
44e7757c | 3735 | tcg_gen_helper_0_0(helper_fpadd16s); |
e9ebed4d BS |
3736 | gen_op_store_FT0_fpr(rd); |
3737 | break; | |
3738 | case 0x052: /* VIS I fpadd32 */ | |
2382dc6b BS |
3739 | gen_op_load_fpr_DT0(DFPREG(rs1)); |
3740 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
44e7757c | 3741 | tcg_gen_helper_0_0(helper_fpadd32); |
2382dc6b | 3742 | gen_op_store_DT0_fpr(DFPREG(rd)); |
e9ebed4d BS |
3743 | break; |
3744 | case 0x053: /* VIS I fpadd32s */ | |
3745 | gen_op_load_fpr_FT0(rs1); | |
3746 | gen_op_load_fpr_FT1(rs2); | |
44e7757c | 3747 | tcg_gen_helper_0_0(helper_fpadd32s); |
e9ebed4d BS |
3748 | gen_op_store_FT0_fpr(rd); |
3749 | break; | |
3750 | case 0x054: /* VIS I fpsub16 */ | |
2382dc6b BS |
3751 | gen_op_load_fpr_DT0(DFPREG(rs1)); |
3752 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
44e7757c | 3753 | tcg_gen_helper_0_0(helper_fpsub16); |
2382dc6b | 3754 | gen_op_store_DT0_fpr(DFPREG(rd)); |
e9ebed4d BS |
3755 | break; |
3756 | case 0x055: /* VIS I fpsub16s */ | |
3757 | gen_op_load_fpr_FT0(rs1); | |
3758 | gen_op_load_fpr_FT1(rs2); | |
44e7757c | 3759 | tcg_gen_helper_0_0(helper_fpsub16s); |
e9ebed4d BS |
3760 | gen_op_store_FT0_fpr(rd); |
3761 | break; | |
3762 | case 0x056: /* VIS I fpsub32 */ | |
2382dc6b BS |
3763 | gen_op_load_fpr_DT0(DFPREG(rs1)); |
3764 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
44e7757c | 3765 | tcg_gen_helper_0_0(helper_fpadd32); |
2382dc6b | 3766 | gen_op_store_DT0_fpr(DFPREG(rd)); |
e9ebed4d BS |
3767 | break; |
3768 | case 0x057: /* VIS I fpsub32s */ | |
3769 | gen_op_load_fpr_FT0(rs1); | |
3770 | gen_op_load_fpr_FT1(rs2); | |
44e7757c | 3771 | tcg_gen_helper_0_0(helper_fpsub32s); |
e9ebed4d BS |
3772 | gen_op_store_FT0_fpr(rd); |
3773 | break; | |
3299908c | 3774 | case 0x060: /* VIS I fzero */ |
44e7757c | 3775 | tcg_gen_helper_0_0(helper_movl_DT0_0); |
2382dc6b | 3776 | gen_op_store_DT0_fpr(DFPREG(rd)); |
3299908c BS |
3777 | break; |
3778 | case 0x061: /* VIS I fzeros */ | |
44e7757c | 3779 | tcg_gen_helper_0_0(helper_movl_FT0_0); |
3299908c BS |
3780 | gen_op_store_FT0_fpr(rd); |
3781 | break; | |
e9ebed4d | 3782 | case 0x062: /* VIS I fnor */ |
2382dc6b BS |
3783 | gen_op_load_fpr_DT0(DFPREG(rs1)); |
3784 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
44e7757c | 3785 | tcg_gen_helper_0_0(helper_fnor); |
2382dc6b | 3786 | gen_op_store_DT0_fpr(DFPREG(rd)); |
e9ebed4d BS |
3787 | break; |
3788 | case 0x063: /* VIS I fnors */ | |
3789 | gen_op_load_fpr_FT0(rs1); | |
3790 | gen_op_load_fpr_FT1(rs2); | |
44e7757c | 3791 | tcg_gen_helper_0_0(helper_fnors); |
e9ebed4d BS |
3792 | gen_op_store_FT0_fpr(rd); |
3793 | break; | |
3794 | case 0x064: /* VIS I fandnot2 */ | |
2382dc6b BS |
3795 | gen_op_load_fpr_DT1(DFPREG(rs1)); |
3796 | gen_op_load_fpr_DT0(DFPREG(rs2)); | |
44e7757c | 3797 | tcg_gen_helper_0_0(helper_fandnot); |
2382dc6b | 3798 | gen_op_store_DT0_fpr(DFPREG(rd)); |
e9ebed4d BS |
3799 | break; |
3800 | case 0x065: /* VIS I fandnot2s */ | |
3801 | gen_op_load_fpr_FT1(rs1); | |
3802 | gen_op_load_fpr_FT0(rs2); | |
44e7757c | 3803 | tcg_gen_helper_0_0(helper_fandnots); |
e9ebed4d BS |
3804 | gen_op_store_FT0_fpr(rd); |
3805 | break; | |
3806 | case 0x066: /* VIS I fnot2 */ | |
2382dc6b | 3807 | gen_op_load_fpr_DT1(DFPREG(rs2)); |
44e7757c | 3808 | tcg_gen_helper_0_0(helper_fnot); |
2382dc6b | 3809 | gen_op_store_DT0_fpr(DFPREG(rd)); |
e9ebed4d BS |
3810 | break; |
3811 | case 0x067: /* VIS I fnot2s */ | |
3812 | gen_op_load_fpr_FT1(rs2); | |
44e7757c | 3813 | tcg_gen_helper_0_0(helper_fnot); |
e9ebed4d BS |
3814 | gen_op_store_FT0_fpr(rd); |
3815 | break; | |
3816 | case 0x068: /* VIS I fandnot1 */ | |
2382dc6b BS |
3817 | gen_op_load_fpr_DT0(DFPREG(rs1)); |
3818 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
44e7757c | 3819 | tcg_gen_helper_0_0(helper_fandnot); |
2382dc6b | 3820 | gen_op_store_DT0_fpr(DFPREG(rd)); |
e9ebed4d BS |
3821 | break; |
3822 | case 0x069: /* VIS I fandnot1s */ | |
3823 | gen_op_load_fpr_FT0(rs1); | |
3824 | gen_op_load_fpr_FT1(rs2); | |
44e7757c | 3825 | tcg_gen_helper_0_0(helper_fandnots); |
e9ebed4d BS |
3826 | gen_op_store_FT0_fpr(rd); |
3827 | break; | |
3828 | case 0x06a: /* VIS I fnot1 */ | |
2382dc6b | 3829 | gen_op_load_fpr_DT1(DFPREG(rs1)); |
44e7757c | 3830 | tcg_gen_helper_0_0(helper_fnot); |
2382dc6b | 3831 | gen_op_store_DT0_fpr(DFPREG(rd)); |
e9ebed4d BS |
3832 | break; |
3833 | case 0x06b: /* VIS I fnot1s */ | |
3834 | gen_op_load_fpr_FT1(rs1); | |
44e7757c | 3835 | tcg_gen_helper_0_0(helper_fnot); |
e9ebed4d BS |
3836 | gen_op_store_FT0_fpr(rd); |
3837 | break; | |
3838 | case 0x06c: /* VIS I fxor */ | |
2382dc6b BS |
3839 | gen_op_load_fpr_DT0(DFPREG(rs1)); |
3840 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
44e7757c | 3841 | tcg_gen_helper_0_0(helper_fxor); |
2382dc6b | 3842 | gen_op_store_DT0_fpr(DFPREG(rd)); |
e9ebed4d BS |
3843 | break; |
3844 | case 0x06d: /* VIS I fxors */ | |
3845 | gen_op_load_fpr_FT0(rs1); | |
3846 | gen_op_load_fpr_FT1(rs2); | |
44e7757c | 3847 | tcg_gen_helper_0_0(helper_fxors); |
e9ebed4d BS |
3848 | gen_op_store_FT0_fpr(rd); |
3849 | break; | |
3850 | case 0x06e: /* VIS I fnand */ | |
2382dc6b BS |
3851 | gen_op_load_fpr_DT0(DFPREG(rs1)); |
3852 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
44e7757c | 3853 | tcg_gen_helper_0_0(helper_fnand); |
2382dc6b | 3854 | gen_op_store_DT0_fpr(DFPREG(rd)); |
e9ebed4d BS |
3855 | break; |
3856 | case 0x06f: /* VIS I fnands */ | |
3857 | gen_op_load_fpr_FT0(rs1); | |
3858 | gen_op_load_fpr_FT1(rs2); | |
44e7757c | 3859 | tcg_gen_helper_0_0(helper_fnands); |
e9ebed4d BS |
3860 | gen_op_store_FT0_fpr(rd); |
3861 | break; | |
3862 | case 0x070: /* VIS I fand */ | |
2382dc6b BS |
3863 | gen_op_load_fpr_DT0(DFPREG(rs1)); |
3864 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
44e7757c | 3865 | tcg_gen_helper_0_0(helper_fand); |
2382dc6b | 3866 | gen_op_store_DT0_fpr(DFPREG(rd)); |
e9ebed4d BS |
3867 | break; |
3868 | case 0x071: /* VIS I fands */ | |
3869 | gen_op_load_fpr_FT0(rs1); | |
3870 | gen_op_load_fpr_FT1(rs2); | |
44e7757c | 3871 | tcg_gen_helper_0_0(helper_fands); |
e9ebed4d BS |
3872 | gen_op_store_FT0_fpr(rd); |
3873 | break; | |
3874 | case 0x072: /* VIS I fxnor */ | |
2382dc6b BS |
3875 | gen_op_load_fpr_DT0(DFPREG(rs1)); |
3876 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
44e7757c | 3877 | tcg_gen_helper_0_0(helper_fxnor); |
2382dc6b | 3878 | gen_op_store_DT0_fpr(DFPREG(rd)); |
e9ebed4d BS |
3879 | break; |
3880 | case 0x073: /* VIS I fxnors */ | |
3881 | gen_op_load_fpr_FT0(rs1); | |
3882 | gen_op_load_fpr_FT1(rs2); | |
44e7757c | 3883 | tcg_gen_helper_0_0(helper_fxnors); |
e9ebed4d BS |
3884 | gen_op_store_FT0_fpr(rd); |
3885 | break; | |
3299908c | 3886 | case 0x074: /* VIS I fsrc1 */ |
2382dc6b BS |
3887 | gen_op_load_fpr_DT0(DFPREG(rs1)); |
3888 | gen_op_store_DT0_fpr(DFPREG(rd)); | |
3299908c BS |
3889 | break; |
3890 | case 0x075: /* VIS I fsrc1s */ | |
3299908c BS |
3891 | gen_op_load_fpr_FT0(rs1); |
3892 | gen_op_store_FT0_fpr(rd); | |
3893 | break; | |
e9ebed4d | 3894 | case 0x076: /* VIS I fornot2 */ |
2382dc6b BS |
3895 | gen_op_load_fpr_DT1(DFPREG(rs1)); |
3896 | gen_op_load_fpr_DT0(DFPREG(rs2)); | |
44e7757c | 3897 | tcg_gen_helper_0_0(helper_fornot); |
2382dc6b | 3898 | gen_op_store_DT0_fpr(DFPREG(rd)); |
e9ebed4d BS |
3899 | break; |
3900 | case 0x077: /* VIS I fornot2s */ | |
3901 | gen_op_load_fpr_FT1(rs1); | |
3902 | gen_op_load_fpr_FT0(rs2); | |
44e7757c | 3903 | tcg_gen_helper_0_0(helper_fornots); |
e9ebed4d BS |
3904 | gen_op_store_FT0_fpr(rd); |
3905 | break; | |
3299908c | 3906 | case 0x078: /* VIS I fsrc2 */ |
2382dc6b BS |
3907 | gen_op_load_fpr_DT0(DFPREG(rs2)); |
3908 | gen_op_store_DT0_fpr(DFPREG(rd)); | |
3299908c BS |
3909 | break; |
3910 | case 0x079: /* VIS I fsrc2s */ | |
3299908c BS |
3911 | gen_op_load_fpr_FT0(rs2); |
3912 | gen_op_store_FT0_fpr(rd); | |
3913 | break; | |
e9ebed4d | 3914 | case 0x07a: /* VIS I fornot1 */ |
2382dc6b BS |
3915 | gen_op_load_fpr_DT0(DFPREG(rs1)); |
3916 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
44e7757c | 3917 | tcg_gen_helper_0_0(helper_fornot); |
2382dc6b | 3918 | gen_op_store_DT0_fpr(DFPREG(rd)); |
e9ebed4d BS |
3919 | break; |
3920 | case 0x07b: /* VIS I fornot1s */ | |
3921 | gen_op_load_fpr_FT0(rs1); | |
3922 | gen_op_load_fpr_FT1(rs2); | |
44e7757c | 3923 | tcg_gen_helper_0_0(helper_fornots); |
e9ebed4d BS |
3924 | gen_op_store_FT0_fpr(rd); |
3925 | break; | |
3926 | case 0x07c: /* VIS I for */ | |
2382dc6b BS |
3927 | gen_op_load_fpr_DT0(DFPREG(rs1)); |
3928 | gen_op_load_fpr_DT1(DFPREG(rs2)); | |
44e7757c | 3929 | tcg_gen_helper_0_0(helper_for); |
2382dc6b | 3930 | gen_op_store_DT0_fpr(DFPREG(rd)); |
e9ebed4d BS |
3931 | break; |
3932 | case 0x07d: /* VIS I fors */ | |
3933 | gen_op_load_fpr_FT0(rs1); | |
3934 | gen_op_load_fpr_FT1(rs2); | |
44e7757c | 3935 | tcg_gen_helper_0_0(helper_fors); |
e9ebed4d BS |
3936 | gen_op_store_FT0_fpr(rd); |
3937 | break; | |
3299908c | 3938 | case 0x07e: /* VIS I fone */ |
44e7757c | 3939 | tcg_gen_helper_0_0(helper_movl_DT0_1); |
2382dc6b | 3940 | gen_op_store_DT0_fpr(DFPREG(rd)); |
3299908c BS |
3941 | break; |
3942 | case 0x07f: /* VIS I fones */ | |
44e7757c | 3943 | tcg_gen_helper_0_0(helper_movl_FT0_1); |
3299908c BS |
3944 | gen_op_store_FT0_fpr(rd); |
3945 | break; | |
e9ebed4d BS |
3946 | case 0x080: /* VIS I shutdown */ |
3947 | case 0x081: /* VIS II siam */ | |
3948 | // XXX | |
3949 | goto illegal_insn; | |
3299908c BS |
3950 | default: |
3951 | goto illegal_insn; | |
3952 | } | |
3953 | #else | |
0f8a249a | 3954 | goto ncp_insn; |
3299908c BS |
3955 | #endif |
3956 | } else if (xop == 0x37) { /* V8 CPop2, V9 impdep2 */ | |
fcc72045 | 3957 | #ifdef TARGET_SPARC64 |
0f8a249a | 3958 | goto illegal_insn; |
fcc72045 | 3959 | #else |
0f8a249a | 3960 | goto ncp_insn; |
fcc72045 | 3961 | #endif |
3475187d | 3962 | #ifdef TARGET_SPARC64 |
0f8a249a | 3963 | } else if (xop == 0x39) { /* V9 return */ |
3475187d | 3964 | rs1 = GET_FIELD(insn, 13, 17); |
1ad21e69 | 3965 | save_state(dc); |
0f8a249a BS |
3966 | gen_movl_reg_T0(rs1); |
3967 | if (IS_IMM) { /* immediate */ | |
3968 | rs2 = GET_FIELDs(insn, 19, 31); | |
1a2fb1c0 | 3969 | tcg_gen_addi_tl(cpu_T[0], cpu_T[0], (int)rs2); |
0f8a249a | 3970 | } else { /* register */ |
3475187d FB |
3971 | rs2 = GET_FIELD(insn, 27, 31); |
3972 | #if defined(OPTIM) | |
0f8a249a | 3973 | if (rs2) { |
3475187d | 3974 | #endif |
0f8a249a BS |
3975 | gen_movl_reg_T1(rs2); |
3976 | gen_op_add_T1_T0(); | |
3475187d | 3977 | #if defined(OPTIM) |
0f8a249a | 3978 | } |
3475187d FB |
3979 | #endif |
3980 | } | |
72a9747b | 3981 | tcg_gen_helper_0_0(helper_restore); |
0f8a249a | 3982 | gen_mov_pc_npc(dc); |
6ea4a6c8 | 3983 | gen_op_check_align_T0_3(); |
48d5c82b | 3984 | tcg_gen_mov_tl(cpu_npc, cpu_T[0]); |
0f8a249a BS |
3985 | dc->npc = DYNAMIC_PC; |
3986 | goto jmp_insn; | |
3475187d | 3987 | #endif |
0f8a249a | 3988 | } else { |
e80cfcfc | 3989 | rs1 = GET_FIELD(insn, 13, 17); |
0f8a249a BS |
3990 | gen_movl_reg_T0(rs1); |
3991 | if (IS_IMM) { /* immediate */ | |
3992 | rs2 = GET_FIELDs(insn, 19, 31); | |
1a2fb1c0 | 3993 | tcg_gen_addi_tl(cpu_T[0], cpu_T[0], (int)rs2); |
0f8a249a | 3994 | } else { /* register */ |
e80cfcfc FB |
3995 | rs2 = GET_FIELD(insn, 27, 31); |
3996 | #if defined(OPTIM) | |
0f8a249a | 3997 | if (rs2) { |
e80cfcfc | 3998 | #endif |
0f8a249a BS |
3999 | gen_movl_reg_T1(rs2); |
4000 | gen_op_add_T1_T0(); | |
e80cfcfc | 4001 | #if defined(OPTIM) |
0f8a249a | 4002 | } |
e8af50a3 | 4003 | #endif |
cf495bcf | 4004 | } |
0f8a249a BS |
4005 | switch (xop) { |
4006 | case 0x38: /* jmpl */ | |
4007 | { | |
4008 | if (rd != 0) { | |
1a2fb1c0 | 4009 | tcg_gen_movi_tl(cpu_T[1], dc->pc); |
0f8a249a BS |
4010 | gen_movl_T1_reg(rd); |
4011 | } | |
0bee699e | 4012 | gen_mov_pc_npc(dc); |
6ea4a6c8 | 4013 | gen_op_check_align_T0_3(); |
48d5c82b | 4014 | tcg_gen_mov_tl(cpu_npc, cpu_T[0]); |
0f8a249a BS |
4015 | dc->npc = DYNAMIC_PC; |
4016 | } | |
4017 | goto jmp_insn; | |
3475187d | 4018 | #if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64) |
0f8a249a BS |
4019 | case 0x39: /* rett, V9 return */ |
4020 | { | |
4021 | if (!supervisor(dc)) | |
4022 | goto priv_insn; | |
0bee699e | 4023 | gen_mov_pc_npc(dc); |
6ea4a6c8 | 4024 | gen_op_check_align_T0_3(); |
48d5c82b | 4025 | tcg_gen_mov_tl(cpu_npc, cpu_T[0]); |
0f8a249a | 4026 | dc->npc = DYNAMIC_PC; |
1a2fb1c0 | 4027 | tcg_gen_helper_0_0(helper_rett); |
0f8a249a BS |
4028 | } |
4029 | goto jmp_insn; | |
4030 | #endif | |
4031 | case 0x3b: /* flush */ | |
1a2fb1c0 | 4032 | tcg_gen_helper_0_1(helper_flush, cpu_T[0]); |
0f8a249a BS |
4033 | break; |
4034 | case 0x3c: /* save */ | |
4035 | save_state(dc); | |
72a9747b | 4036 | tcg_gen_helper_0_0(helper_save); |
0f8a249a BS |
4037 | gen_movl_T0_reg(rd); |
4038 | break; | |
4039 | case 0x3d: /* restore */ | |
4040 | save_state(dc); | |
72a9747b | 4041 | tcg_gen_helper_0_0(helper_restore); |
0f8a249a BS |
4042 | gen_movl_T0_reg(rd); |
4043 | break; | |
3475187d | 4044 | #if !defined(CONFIG_USER_ONLY) && defined(TARGET_SPARC64) |
0f8a249a BS |
4045 | case 0x3e: /* V9 done/retry */ |
4046 | { | |
4047 | switch (rd) { | |
4048 | case 0: | |
4049 | if (!supervisor(dc)) | |
4050 | goto priv_insn; | |
4051 | dc->npc = DYNAMIC_PC; | |
4052 | dc->pc = DYNAMIC_PC; | |
1a2fb1c0 | 4053 | tcg_gen_helper_0_0(helper_done); |
0f8a249a BS |
4054 | goto jmp_insn; |
4055 | case 1: | |
4056 | if (!supervisor(dc)) | |
4057 | goto priv_insn; | |
4058 | dc->npc = DYNAMIC_PC; | |
4059 | dc->pc = DYNAMIC_PC; | |
1a2fb1c0 | 4060 | tcg_gen_helper_0_0(helper_retry); |
0f8a249a BS |
4061 | goto jmp_insn; |
4062 | default: | |
4063 | goto illegal_insn; | |
4064 | } | |
4065 | } | |
4066 | break; | |
4067 | #endif | |
4068 | default: | |
4069 | goto illegal_insn; | |
4070 | } | |
cf495bcf | 4071 | } |
0f8a249a BS |
4072 | break; |
4073 | } | |
4074 | break; | |
4075 | case 3: /* load/store instructions */ | |
4076 | { | |
4077 | unsigned int xop = GET_FIELD(insn, 7, 12); | |
4078 | rs1 = GET_FIELD(insn, 13, 17); | |
2371aaa2 | 4079 | save_state(dc); |
0f8a249a | 4080 | gen_movl_reg_T0(rs1); |
81ad8ba2 BS |
4081 | if (xop == 0x3c || xop == 0x3e) |
4082 | { | |
4083 | rs2 = GET_FIELD(insn, 27, 31); | |
4084 | gen_movl_reg_T1(rs2); | |
4085 | } | |
4086 | else if (IS_IMM) { /* immediate */ | |
0f8a249a | 4087 | rs2 = GET_FIELDs(insn, 19, 31); |
1a2fb1c0 | 4088 | tcg_gen_addi_tl(cpu_T[0], cpu_T[0], (int)rs2); |
0f8a249a BS |
4089 | } else { /* register */ |
4090 | rs2 = GET_FIELD(insn, 27, 31); | |
e80cfcfc | 4091 | #if defined(OPTIM) |
0f8a249a | 4092 | if (rs2 != 0) { |
e80cfcfc | 4093 | #endif |
0f8a249a BS |
4094 | gen_movl_reg_T1(rs2); |
4095 | gen_op_add_T1_T0(); | |
e80cfcfc | 4096 | #if defined(OPTIM) |
0f8a249a | 4097 | } |
e80cfcfc | 4098 | #endif |
0f8a249a | 4099 | } |
2f2ecb83 BS |
4100 | if (xop < 4 || (xop > 7 && xop < 0x14 && xop != 0x0e) || |
4101 | (xop > 0x17 && xop <= 0x1d ) || | |
4102 | (xop > 0x2c && xop <= 0x33) || xop == 0x1f || xop == 0x3d) { | |
0f8a249a | 4103 | switch (xop) { |
1a2fb1c0 | 4104 | case 0x0: /* load unsigned word */ |
6ea4a6c8 | 4105 | gen_op_check_align_T0_3(); |
1a2fb1c0 BS |
4106 | ABI32_MASK(cpu_T[0]); |
4107 | tcg_gen_qemu_ld32u(cpu_T[1], cpu_T[0], dc->mem_idx); | |
0f8a249a BS |
4108 | break; |
4109 | case 0x1: /* load unsigned byte */ | |
1a2fb1c0 BS |
4110 | ABI32_MASK(cpu_T[0]); |
4111 | tcg_gen_qemu_ld8u(cpu_T[1], cpu_T[0], dc->mem_idx); | |
0f8a249a BS |
4112 | break; |
4113 | case 0x2: /* load unsigned halfword */ | |
6ea4a6c8 | 4114 | gen_op_check_align_T0_1(); |
1a2fb1c0 BS |
4115 | ABI32_MASK(cpu_T[0]); |
4116 | tcg_gen_qemu_ld16u(cpu_T[1], cpu_T[0], dc->mem_idx); | |
0f8a249a BS |
4117 | break; |
4118 | case 0x3: /* load double word */ | |
0f8a249a | 4119 | if (rd & 1) |
d4218d99 | 4120 | goto illegal_insn; |
1a2fb1c0 | 4121 | else { |
1a2fb1c0 BS |
4122 | gen_op_check_align_T0_7(); |
4123 | ABI32_MASK(cpu_T[0]); | |
8911f501 BS |
4124 | tcg_gen_qemu_ld64(cpu_tmp64, cpu_T[0], dc->mem_idx); |
4125 | tcg_gen_trunc_i64_tl(cpu_T[0], cpu_tmp64); | |
4126 | tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 0xffffffffULL); | |
1a2fb1c0 | 4127 | gen_movl_T0_reg(rd + 1); |
8911f501 BS |
4128 | tcg_gen_shri_i64(cpu_tmp64, cpu_tmp64, 32); |
4129 | tcg_gen_trunc_i64_tl(cpu_T[1], cpu_tmp64); | |
4130 | tcg_gen_andi_tl(cpu_T[1], cpu_T[1], 0xffffffffULL); | |
1a2fb1c0 | 4131 | } |
0f8a249a BS |
4132 | break; |
4133 | case 0x9: /* load signed byte */ | |
1a2fb1c0 BS |
4134 | ABI32_MASK(cpu_T[0]); |
4135 | tcg_gen_qemu_ld8s(cpu_T[1], cpu_T[0], dc->mem_idx); | |
0f8a249a BS |
4136 | break; |
4137 | case 0xa: /* load signed halfword */ | |
6ea4a6c8 | 4138 | gen_op_check_align_T0_1(); |
1a2fb1c0 BS |
4139 | ABI32_MASK(cpu_T[0]); |
4140 | tcg_gen_qemu_ld16s(cpu_T[1], cpu_T[0], dc->mem_idx); | |
0f8a249a BS |
4141 | break; |
4142 | case 0xd: /* ldstub -- XXX: should be atomically */ | |
1a2fb1c0 BS |
4143 | ABI32_MASK(cpu_T[0]); |
4144 | tcg_gen_qemu_ld8s(cpu_T[1], cpu_T[0], dc->mem_idx); | |
8911f501 | 4145 | tcg_gen_qemu_st8(tcg_const_tl(0xff), cpu_T[0], dc->mem_idx); |
0f8a249a BS |
4146 | break; |
4147 | case 0x0f: /* swap register with memory. Also atomically */ | |
6ea4a6c8 | 4148 | gen_op_check_align_T0_3(); |
0f8a249a | 4149 | gen_movl_reg_T1(rd); |
1a2fb1c0 | 4150 | ABI32_MASK(cpu_T[0]); |
8911f501 | 4151 | tcg_gen_qemu_ld32u(cpu_tmp32, cpu_T[0], dc->mem_idx); |
1a2fb1c0 | 4152 | tcg_gen_qemu_st32(cpu_T[1], cpu_T[0], dc->mem_idx); |
8911f501 | 4153 | tcg_gen_extu_i32_tl(cpu_T[1], cpu_tmp32); |
0f8a249a | 4154 | break; |
3475187d | 4155 | #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64) |
0f8a249a | 4156 | case 0x10: /* load word alternate */ |
3475187d | 4157 | #ifndef TARGET_SPARC64 |
0f8a249a BS |
4158 | if (IS_IMM) |
4159 | goto illegal_insn; | |
4160 | if (!supervisor(dc)) | |
4161 | goto priv_insn; | |
6ea4a6c8 | 4162 | #endif |
8f577d3d | 4163 | gen_op_check_align_T0_3(); |
81ad8ba2 | 4164 | gen_ld_asi(insn, 4, 0); |
0f8a249a BS |
4165 | break; |
4166 | case 0x11: /* load unsigned byte alternate */ | |
3475187d | 4167 | #ifndef TARGET_SPARC64 |
0f8a249a BS |
4168 | if (IS_IMM) |
4169 | goto illegal_insn; | |
4170 | if (!supervisor(dc)) | |
4171 | goto priv_insn; | |
4172 | #endif | |
81ad8ba2 | 4173 | gen_ld_asi(insn, 1, 0); |
0f8a249a BS |
4174 | break; |
4175 | case 0x12: /* load unsigned halfword alternate */ | |
3475187d | 4176 | #ifndef TARGET_SPARC64 |
0f8a249a BS |
4177 | if (IS_IMM) |
4178 | goto illegal_insn; | |
4179 | if (!supervisor(dc)) | |
4180 | goto priv_insn; | |
3475187d | 4181 | #endif |
8f577d3d | 4182 | gen_op_check_align_T0_1(); |
81ad8ba2 | 4183 | gen_ld_asi(insn, 2, 0); |
0f8a249a BS |
4184 | break; |
4185 | case 0x13: /* load double word alternate */ | |
3475187d | 4186 | #ifndef TARGET_SPARC64 |
0f8a249a BS |
4187 | if (IS_IMM) |
4188 | goto illegal_insn; | |
4189 | if (!supervisor(dc)) | |
4190 | goto priv_insn; | |
3475187d | 4191 | #endif |
0f8a249a | 4192 | if (rd & 1) |
d4218d99 | 4193 | goto illegal_insn; |
6ea4a6c8 | 4194 | gen_op_check_align_T0_7(); |
81ad8ba2 | 4195 | gen_ldda_asi(insn); |
0f8a249a BS |
4196 | gen_movl_T0_reg(rd + 1); |
4197 | break; | |
4198 | case 0x19: /* load signed byte alternate */ | |
3475187d | 4199 | #ifndef TARGET_SPARC64 |
0f8a249a BS |
4200 | if (IS_IMM) |
4201 | goto illegal_insn; | |
4202 | if (!supervisor(dc)) | |
4203 | goto priv_insn; | |
4204 | #endif | |
81ad8ba2 | 4205 | gen_ld_asi(insn, 1, 1); |
0f8a249a BS |
4206 | break; |
4207 | case 0x1a: /* load signed halfword alternate */ | |
3475187d | 4208 | #ifndef TARGET_SPARC64 |
0f8a249a BS |
4209 | if (IS_IMM) |
4210 | goto illegal_insn; | |
4211 | if (!supervisor(dc)) | |
4212 | goto priv_insn; | |
3475187d | 4213 | #endif |
8f577d3d | 4214 | gen_op_check_align_T0_1(); |
81ad8ba2 | 4215 | gen_ld_asi(insn, 2, 1); |
0f8a249a BS |
4216 | break; |
4217 | case 0x1d: /* ldstuba -- XXX: should be atomically */ | |
3475187d | 4218 | #ifndef TARGET_SPARC64 |
0f8a249a BS |
4219 | if (IS_IMM) |
4220 | goto illegal_insn; | |
4221 | if (!supervisor(dc)) | |
4222 | goto priv_insn; | |
4223 | #endif | |
81ad8ba2 | 4224 | gen_ldstub_asi(insn); |
0f8a249a BS |
4225 | break; |
4226 | case 0x1f: /* swap reg with alt. memory. Also atomically */ | |
3475187d | 4227 | #ifndef TARGET_SPARC64 |
0f8a249a BS |
4228 | if (IS_IMM) |
4229 | goto illegal_insn; | |
4230 | if (!supervisor(dc)) | |
4231 | goto priv_insn; | |
6ea4a6c8 | 4232 | #endif |
8f577d3d | 4233 | gen_op_check_align_T0_3(); |
81ad8ba2 BS |
4234 | gen_movl_reg_T1(rd); |
4235 | gen_swap_asi(insn); | |
0f8a249a | 4236 | break; |
3475187d FB |
4237 | |
4238 | #ifndef TARGET_SPARC64 | |
0f8a249a BS |
4239 | case 0x30: /* ldc */ |
4240 | case 0x31: /* ldcsr */ | |
4241 | case 0x33: /* lddc */ | |
4242 | goto ncp_insn; | |
3475187d FB |
4243 | #endif |
4244 | #endif | |
4245 | #ifdef TARGET_SPARC64 | |
0f8a249a | 4246 | case 0x08: /* V9 ldsw */ |
6ea4a6c8 | 4247 | gen_op_check_align_T0_3(); |
1a2fb1c0 BS |
4248 | ABI32_MASK(cpu_T[0]); |
4249 | tcg_gen_qemu_ld32s(cpu_T[1], cpu_T[0], dc->mem_idx); | |
0f8a249a BS |
4250 | break; |
4251 | case 0x0b: /* V9 ldx */ | |
6ea4a6c8 | 4252 | gen_op_check_align_T0_7(); |
1a2fb1c0 BS |
4253 | ABI32_MASK(cpu_T[0]); |
4254 | tcg_gen_qemu_ld64(cpu_T[1], cpu_T[0], dc->mem_idx); | |
0f8a249a BS |
4255 | break; |
4256 | case 0x18: /* V9 ldswa */ | |
6ea4a6c8 | 4257 | gen_op_check_align_T0_3(); |
81ad8ba2 | 4258 | gen_ld_asi(insn, 4, 1); |
0f8a249a BS |
4259 | break; |
4260 | case 0x1b: /* V9 ldxa */ | |
6ea4a6c8 | 4261 | gen_op_check_align_T0_7(); |
81ad8ba2 | 4262 | gen_ld_asi(insn, 8, 0); |
0f8a249a BS |
4263 | break; |
4264 | case 0x2d: /* V9 prefetch, no effect */ | |
4265 | goto skip_move; | |
4266 | case 0x30: /* V9 ldfa */ | |
6ea4a6c8 | 4267 | gen_op_check_align_T0_3(); |
2382dc6b | 4268 | gen_ldf_asi(insn, 4, rd); |
81ad8ba2 | 4269 | goto skip_move; |
0f8a249a | 4270 | case 0x33: /* V9 lddfa */ |
3391c818 | 4271 | gen_op_check_align_T0_3(); |
2382dc6b | 4272 | gen_ldf_asi(insn, 8, DFPREG(rd)); |
81ad8ba2 | 4273 | goto skip_move; |
0f8a249a BS |
4274 | case 0x3d: /* V9 prefetcha, no effect */ |
4275 | goto skip_move; | |
4276 | case 0x32: /* V9 ldqfa */ | |
1f587329 BS |
4277 | #if defined(CONFIG_USER_ONLY) |
4278 | gen_op_check_align_T0_3(); | |
2382dc6b | 4279 | gen_ldf_asi(insn, 16, QFPREG(rd)); |
1f587329 BS |
4280 | goto skip_move; |
4281 | #else | |
0f8a249a | 4282 | goto nfpu_insn; |
1f587329 | 4283 | #endif |
0f8a249a BS |
4284 | #endif |
4285 | default: | |
4286 | goto illegal_insn; | |
4287 | } | |
4288 | gen_movl_T1_reg(rd); | |
3475187d | 4289 | #ifdef TARGET_SPARC64 |
0f8a249a | 4290 | skip_move: ; |
3475187d | 4291 | #endif |
0f8a249a | 4292 | } else if (xop >= 0x20 && xop < 0x24) { |
a80dde08 FB |
4293 | if (gen_trap_ifnofpu(dc)) |
4294 | goto jmp_insn; | |
0f8a249a BS |
4295 | switch (xop) { |
4296 | case 0x20: /* load fpreg */ | |
6ea4a6c8 | 4297 | gen_op_check_align_T0_3(); |
0f8a249a BS |
4298 | gen_op_ldst(ldf); |
4299 | gen_op_store_FT0_fpr(rd); | |
4300 | break; | |
4301 | case 0x21: /* load fsr */ | |
6ea4a6c8 | 4302 | gen_op_check_align_T0_3(); |
0f8a249a | 4303 | gen_op_ldst(ldf); |
7e8c2b6c | 4304 | tcg_gen_helper_0_0(helper_ldfsr); |
0f8a249a BS |
4305 | break; |
4306 | case 0x22: /* load quad fpreg */ | |
1f587329 BS |
4307 | #if defined(CONFIG_USER_ONLY) |
4308 | gen_op_check_align_T0_7(); | |
4309 | gen_op_ldst(ldqf); | |
4310 | gen_op_store_QT0_fpr(QFPREG(rd)); | |
4311 | break; | |
4312 | #else | |
0f8a249a | 4313 | goto nfpu_insn; |
1f587329 | 4314 | #endif |
0f8a249a | 4315 | case 0x23: /* load double fpreg */ |
6ea4a6c8 | 4316 | gen_op_check_align_T0_7(); |
0f8a249a BS |
4317 | gen_op_ldst(lddf); |
4318 | gen_op_store_DT0_fpr(DFPREG(rd)); | |
4319 | break; | |
4320 | default: | |
4321 | goto illegal_insn; | |
4322 | } | |
4323 | } else if (xop < 8 || (xop >= 0x14 && xop < 0x18) || \ | |
4324 | xop == 0xe || xop == 0x1e) { | |
4325 | gen_movl_reg_T1(rd); | |
4326 | switch (xop) { | |
1a2fb1c0 | 4327 | case 0x4: /* store word */ |
6ea4a6c8 | 4328 | gen_op_check_align_T0_3(); |
1a2fb1c0 BS |
4329 | ABI32_MASK(cpu_T[0]); |
4330 | tcg_gen_qemu_st32(cpu_T[1], cpu_T[0], dc->mem_idx); | |
0f8a249a | 4331 | break; |
1a2fb1c0 BS |
4332 | case 0x5: /* store byte */ |
4333 | ABI32_MASK(cpu_T[0]); | |
4334 | tcg_gen_qemu_st8(cpu_T[1], cpu_T[0], dc->mem_idx); | |
0f8a249a | 4335 | break; |
1a2fb1c0 | 4336 | case 0x6: /* store halfword */ |
6ea4a6c8 | 4337 | gen_op_check_align_T0_1(); |
1a2fb1c0 BS |
4338 | ABI32_MASK(cpu_T[0]); |
4339 | tcg_gen_qemu_st16(cpu_T[1], cpu_T[0], dc->mem_idx); | |
0f8a249a | 4340 | break; |
1a2fb1c0 | 4341 | case 0x7: /* store double word */ |
0f8a249a | 4342 | if (rd & 1) |
d4218d99 | 4343 | goto illegal_insn; |
b25deda7 | 4344 | #ifndef __i386__ |
1a2fb1c0 | 4345 | else { |
8911f501 | 4346 | TCGv r_low; |
1a2fb1c0 BS |
4347 | |
4348 | gen_op_check_align_T0_7(); | |
1a2fb1c0 BS |
4349 | r_low = tcg_temp_new(TCG_TYPE_I32); |
4350 | gen_movl_reg_TN(rd + 1, r_low); | |
8911f501 | 4351 | tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, cpu_T[1], |
1a2fb1c0 | 4352 | r_low); |
8911f501 | 4353 | tcg_gen_qemu_st64(cpu_tmp64, cpu_T[0], dc->mem_idx); |
1a2fb1c0 | 4354 | } |
b25deda7 BS |
4355 | #else /* __i386__ */ |
4356 | gen_op_check_align_T0_7(); | |
4357 | flush_T2(dc); | |
4358 | gen_movl_reg_T2(rd + 1); | |
4359 | gen_op_ldst(std); | |
4360 | #endif /* __i386__ */ | |
0f8a249a | 4361 | break; |
3475187d | 4362 | #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64) |
1a2fb1c0 | 4363 | case 0x14: /* store word alternate */ |
3475187d | 4364 | #ifndef TARGET_SPARC64 |
0f8a249a BS |
4365 | if (IS_IMM) |
4366 | goto illegal_insn; | |
4367 | if (!supervisor(dc)) | |
4368 | goto priv_insn; | |
6ea4a6c8 | 4369 | #endif |
6ea4a6c8 | 4370 | gen_op_check_align_T0_3(); |
81ad8ba2 | 4371 | gen_st_asi(insn, 4); |
d39c0b99 | 4372 | break; |
1a2fb1c0 | 4373 | case 0x15: /* store byte alternate */ |
3475187d | 4374 | #ifndef TARGET_SPARC64 |
0f8a249a BS |
4375 | if (IS_IMM) |
4376 | goto illegal_insn; | |
4377 | if (!supervisor(dc)) | |
4378 | goto priv_insn; | |
3475187d | 4379 | #endif |
81ad8ba2 | 4380 | gen_st_asi(insn, 1); |
d39c0b99 | 4381 | break; |
1a2fb1c0 | 4382 | case 0x16: /* store halfword alternate */ |
3475187d | 4383 | #ifndef TARGET_SPARC64 |
0f8a249a BS |
4384 | if (IS_IMM) |
4385 | goto illegal_insn; | |
4386 | if (!supervisor(dc)) | |
4387 | goto priv_insn; | |
6ea4a6c8 | 4388 | #endif |
6ea4a6c8 | 4389 | gen_op_check_align_T0_1(); |
81ad8ba2 | 4390 | gen_st_asi(insn, 2); |
d39c0b99 | 4391 | break; |
1a2fb1c0 | 4392 | case 0x17: /* store double word alternate */ |
3475187d | 4393 | #ifndef TARGET_SPARC64 |
0f8a249a BS |
4394 | if (IS_IMM) |
4395 | goto illegal_insn; | |
4396 | if (!supervisor(dc)) | |
4397 | goto priv_insn; | |
3475187d | 4398 | #endif |
0f8a249a | 4399 | if (rd & 1) |
d4218d99 | 4400 | goto illegal_insn; |
1a2fb1c0 | 4401 | else { |
1a2fb1c0 | 4402 | gen_op_check_align_T0_7(); |
0425bee5 | 4403 | gen_stda_asi(insn, rd); |
1a2fb1c0 | 4404 | } |
d39c0b99 | 4405 | break; |
e80cfcfc | 4406 | #endif |
3475187d | 4407 | #ifdef TARGET_SPARC64 |
0f8a249a | 4408 | case 0x0e: /* V9 stx */ |
6ea4a6c8 | 4409 | gen_op_check_align_T0_7(); |
1a2fb1c0 BS |
4410 | ABI32_MASK(cpu_T[0]); |
4411 | tcg_gen_qemu_st64(cpu_T[1], cpu_T[0], dc->mem_idx); | |
0f8a249a BS |
4412 | break; |
4413 | case 0x1e: /* V9 stxa */ | |
6ea4a6c8 | 4414 | gen_op_check_align_T0_7(); |
81ad8ba2 | 4415 | gen_st_asi(insn, 8); |
0f8a249a | 4416 | break; |
3475187d | 4417 | #endif |
0f8a249a BS |
4418 | default: |
4419 | goto illegal_insn; | |
4420 | } | |
4421 | } else if (xop > 0x23 && xop < 0x28) { | |
a80dde08 FB |
4422 | if (gen_trap_ifnofpu(dc)) |
4423 | goto jmp_insn; | |
0f8a249a BS |
4424 | switch (xop) { |
4425 | case 0x24: | |
6ea4a6c8 | 4426 | gen_op_check_align_T0_3(); |
e8af50a3 | 4427 | gen_op_load_fpr_FT0(rd); |
0f8a249a BS |
4428 | gen_op_ldst(stf); |
4429 | break; | |
4430 | case 0x25: /* stfsr, V9 stxfsr */ | |
6ea4a6c8 BS |
4431 | #ifdef CONFIG_USER_ONLY |
4432 | gen_op_check_align_T0_3(); | |
4433 | #endif | |
bb5529bb | 4434 | tcg_gen_helper_0_0(helper_stfsr); |
0f8a249a BS |
4435 | gen_op_ldst(stf); |
4436 | break; | |
1f587329 BS |
4437 | case 0x26: |
4438 | #ifdef TARGET_SPARC64 | |
4439 | #if defined(CONFIG_USER_ONLY) | |
4440 | /* V9 stqf, store quad fpreg */ | |
4441 | gen_op_check_align_T0_7(); | |
4442 | gen_op_load_fpr_QT0(QFPREG(rd)); | |
4443 | gen_op_ldst(stqf); | |
4444 | break; | |
4445 | #else | |
4446 | goto nfpu_insn; | |
4447 | #endif | |
4448 | #else /* !TARGET_SPARC64 */ | |
4449 | /* stdfq, store floating point queue */ | |
4450 | #if defined(CONFIG_USER_ONLY) | |
4451 | goto illegal_insn; | |
4452 | #else | |
0f8a249a BS |
4453 | if (!supervisor(dc)) |
4454 | goto priv_insn; | |
4455 | if (gen_trap_ifnofpu(dc)) | |
4456 | goto jmp_insn; | |
4457 | goto nfq_insn; | |
1f587329 | 4458 | #endif |
0f8a249a BS |
4459 | #endif |
4460 | case 0x27: | |
6ea4a6c8 | 4461 | gen_op_check_align_T0_7(); |
3475187d | 4462 | gen_op_load_fpr_DT0(DFPREG(rd)); |
0f8a249a BS |
4463 | gen_op_ldst(stdf); |
4464 | break; | |
4465 | default: | |
4466 | goto illegal_insn; | |
4467 | } | |
4468 | } else if (xop > 0x33 && xop < 0x3f) { | |
4469 | switch (xop) { | |
a4d17f19 | 4470 | #ifdef TARGET_SPARC64 |
0f8a249a | 4471 | case 0x34: /* V9 stfa */ |
6ea4a6c8 | 4472 | gen_op_check_align_T0_3(); |
3391c818 | 4473 | gen_op_load_fpr_FT0(rd); |
2382dc6b | 4474 | gen_stf_asi(insn, 4, rd); |
0f8a249a | 4475 | break; |
1f587329 BS |
4476 | case 0x36: /* V9 stqfa */ |
4477 | #if defined(CONFIG_USER_ONLY) | |
4478 | gen_op_check_align_T0_7(); | |
4479 | gen_op_load_fpr_QT0(QFPREG(rd)); | |
2382dc6b | 4480 | gen_stf_asi(insn, 16, QFPREG(rd)); |
1f587329 BS |
4481 | break; |
4482 | #else | |
4483 | goto nfpu_insn; | |
4484 | #endif | |
0f8a249a | 4485 | case 0x37: /* V9 stdfa */ |
3391c818 BS |
4486 | gen_op_check_align_T0_3(); |
4487 | gen_op_load_fpr_DT0(DFPREG(rd)); | |
2382dc6b | 4488 | gen_stf_asi(insn, 8, DFPREG(rd)); |
0f8a249a BS |
4489 | break; |
4490 | case 0x3c: /* V9 casa */ | |
6ea4a6c8 | 4491 | gen_op_check_align_T0_3(); |
1a2fb1c0 | 4492 | gen_cas_asi(insn, rd); |
81ad8ba2 | 4493 | gen_movl_T1_reg(rd); |
0f8a249a BS |
4494 | break; |
4495 | case 0x3e: /* V9 casxa */ | |
6ea4a6c8 | 4496 | gen_op_check_align_T0_7(); |
1a2fb1c0 | 4497 | gen_casx_asi(insn, rd); |
81ad8ba2 | 4498 | gen_movl_T1_reg(rd); |
0f8a249a | 4499 | break; |
a4d17f19 | 4500 | #else |
0f8a249a BS |
4501 | case 0x34: /* stc */ |
4502 | case 0x35: /* stcsr */ | |
4503 | case 0x36: /* stdcq */ | |
4504 | case 0x37: /* stdc */ | |
4505 | goto ncp_insn; | |
4506 | #endif | |
4507 | default: | |
4508 | goto illegal_insn; | |
4509 | } | |
e8af50a3 | 4510 | } |
0f8a249a BS |
4511 | else |
4512 | goto illegal_insn; | |
4513 | } | |
4514 | break; | |
cf495bcf FB |
4515 | } |
4516 | /* default case for non jump instructions */ | |
72cbca10 | 4517 | if (dc->npc == DYNAMIC_PC) { |
0f8a249a BS |
4518 | dc->pc = DYNAMIC_PC; |
4519 | gen_op_next_insn(); | |
72cbca10 FB |
4520 | } else if (dc->npc == JUMP_PC) { |
4521 | /* we can do a static jump */ | |
19f329ad | 4522 | gen_branch2(dc, dc->jump_pc[0], dc->jump_pc[1], cpu_T[2]); |
72cbca10 FB |
4523 | dc->is_br = 1; |
4524 | } else { | |
0f8a249a BS |
4525 | dc->pc = dc->npc; |
4526 | dc->npc = dc->npc + 4; | |
cf495bcf | 4527 | } |
e80cfcfc | 4528 | jmp_insn: |
cf495bcf FB |
4529 | return; |
4530 | illegal_insn: | |
72cbca10 | 4531 | save_state(dc); |
cf495bcf FB |
4532 | gen_op_exception(TT_ILL_INSN); |
4533 | dc->is_br = 1; | |
e8af50a3 | 4534 | return; |
e80cfcfc | 4535 | #if !defined(CONFIG_USER_ONLY) |
e8af50a3 FB |
4536 | priv_insn: |
4537 | save_state(dc); | |
4538 | gen_op_exception(TT_PRIV_INSN); | |
4539 | dc->is_br = 1; | |
e80cfcfc | 4540 | return; |
e80cfcfc FB |
4541 | nfpu_insn: |
4542 | save_state(dc); | |
4543 | gen_op_fpexception_im(FSR_FTT_UNIMPFPOP); | |
4544 | dc->is_br = 1; | |
fcc72045 | 4545 | return; |
1f587329 | 4546 | #ifndef TARGET_SPARC64 |
9143e598 BS |
4547 | nfq_insn: |
4548 | save_state(dc); | |
4549 | gen_op_fpexception_im(FSR_FTT_SEQ_ERROR); | |
4550 | dc->is_br = 1; | |
4551 | return; | |
4552 | #endif | |
1f587329 | 4553 | #endif |
fcc72045 BS |
4554 | #ifndef TARGET_SPARC64 |
4555 | ncp_insn: | |
4556 | save_state(dc); | |
4557 | gen_op_exception(TT_NCP_INSN); | |
4558 | dc->is_br = 1; | |
4559 | return; | |
4560 | #endif | |
7a3f1944 FB |
4561 | } |
4562 | ||
1a2fb1c0 BS |
4563 | static void tcg_macro_func(TCGContext *s, int macro_id, const int *dead_args) |
4564 | { | |
4565 | } | |
4566 | ||
cf495bcf | 4567 | static inline int gen_intermediate_code_internal(TranslationBlock * tb, |
0f8a249a | 4568 | int spc, CPUSPARCState *env) |
7a3f1944 | 4569 | { |
72cbca10 | 4570 | target_ulong pc_start, last_pc; |
cf495bcf FB |
4571 | uint16_t *gen_opc_end; |
4572 | DisasContext dc1, *dc = &dc1; | |
e8af50a3 | 4573 | int j, lj = -1; |
cf495bcf FB |
4574 | |
4575 | memset(dc, 0, sizeof(DisasContext)); | |
cf495bcf | 4576 | dc->tb = tb; |
72cbca10 | 4577 | pc_start = tb->pc; |
cf495bcf | 4578 | dc->pc = pc_start; |
e80cfcfc | 4579 | last_pc = dc->pc; |
72cbca10 | 4580 | dc->npc = (target_ulong) tb->cs_base; |
6f27aba6 BS |
4581 | dc->mem_idx = cpu_mmu_index(env); |
4582 | dc->fpu_enabled = cpu_fpu_enabled(env); | |
cf495bcf | 4583 | gen_opc_end = gen_opc_buf + OPC_MAX_SIZE; |
cf495bcf | 4584 | |
1a2fb1c0 | 4585 | cpu_tmp0 = tcg_temp_new(TCG_TYPE_TL); |
8911f501 BS |
4586 | cpu_tmp32 = tcg_temp_new(TCG_TYPE_I32); |
4587 | cpu_tmp64 = tcg_temp_new(TCG_TYPE_I64); | |
1a2fb1c0 | 4588 | |
cf495bcf | 4589 | do { |
e8af50a3 FB |
4590 | if (env->nb_breakpoints > 0) { |
4591 | for(j = 0; j < env->nb_breakpoints; j++) { | |
4592 | if (env->breakpoints[j] == dc->pc) { | |
0f8a249a BS |
4593 | if (dc->pc != pc_start) |
4594 | save_state(dc); | |
1a2fb1c0 | 4595 | tcg_gen_helper_0_0(helper_debug); |
57fec1fe | 4596 | tcg_gen_exit_tb(0); |
0f8a249a | 4597 | dc->is_br = 1; |
e80cfcfc | 4598 | goto exit_gen_loop; |
e8af50a3 FB |
4599 | } |
4600 | } | |
4601 | } | |
4602 | if (spc) { | |
4603 | if (loglevel > 0) | |
4604 | fprintf(logfile, "Search PC...\n"); | |
4605 | j = gen_opc_ptr - gen_opc_buf; | |
4606 | if (lj < j) { | |
4607 | lj++; | |
4608 | while (lj < j) | |
4609 | gen_opc_instr_start[lj++] = 0; | |
4610 | gen_opc_pc[lj] = dc->pc; | |
4611 | gen_opc_npc[lj] = dc->npc; | |
4612 | gen_opc_instr_start[lj] = 1; | |
4613 | } | |
4614 | } | |
0f8a249a BS |
4615 | last_pc = dc->pc; |
4616 | disas_sparc_insn(dc); | |
4617 | ||
4618 | if (dc->is_br) | |
4619 | break; | |
4620 | /* if the next PC is different, we abort now */ | |
4621 | if (dc->pc != (last_pc + 4)) | |
4622 | break; | |
d39c0b99 FB |
4623 | /* if we reach a page boundary, we stop generation so that the |
4624 | PC of a TT_TFAULT exception is always in the right page */ | |
4625 | if ((dc->pc & (TARGET_PAGE_SIZE - 1)) == 0) | |
4626 | break; | |
e80cfcfc FB |
4627 | /* if single step mode, we generate only one instruction and |
4628 | generate an exception */ | |
4629 | if (env->singlestep_enabled) { | |
3475187d | 4630 | gen_jmp_im(dc->pc); |
57fec1fe | 4631 | tcg_gen_exit_tb(0); |
e80cfcfc FB |
4632 | break; |
4633 | } | |
cf495bcf | 4634 | } while ((gen_opc_ptr < gen_opc_end) && |
0f8a249a | 4635 | (dc->pc - pc_start) < (TARGET_PAGE_SIZE - 32)); |
e80cfcfc FB |
4636 | |
4637 | exit_gen_loop: | |
72cbca10 | 4638 | if (!dc->is_br) { |
5fafdf24 | 4639 | if (dc->pc != DYNAMIC_PC && |
72cbca10 FB |
4640 | (dc->npc != DYNAMIC_PC && dc->npc != JUMP_PC)) { |
4641 | /* static PC and NPC: we can use direct chaining */ | |
46525e1f | 4642 | gen_branch(dc, dc->pc, dc->npc); |
72cbca10 FB |
4643 | } else { |
4644 | if (dc->pc != DYNAMIC_PC) | |
3475187d | 4645 | gen_jmp_im(dc->pc); |
72cbca10 | 4646 | save_npc(dc); |
57fec1fe | 4647 | tcg_gen_exit_tb(0); |
72cbca10 FB |
4648 | } |
4649 | } | |
cf495bcf | 4650 | *gen_opc_ptr = INDEX_op_end; |
e8af50a3 FB |
4651 | if (spc) { |
4652 | j = gen_opc_ptr - gen_opc_buf; | |
4653 | lj++; | |
4654 | while (lj <= j) | |
4655 | gen_opc_instr_start[lj++] = 0; | |
e8af50a3 FB |
4656 | #if 0 |
4657 | if (loglevel > 0) { | |
4658 | page_dump(logfile); | |
4659 | } | |
4660 | #endif | |
c3278b7b FB |
4661 | gen_opc_jump_pc[0] = dc->jump_pc[0]; |
4662 | gen_opc_jump_pc[1] = dc->jump_pc[1]; | |
e8af50a3 | 4663 | } else { |
e80cfcfc | 4664 | tb->size = last_pc + 4 - pc_start; |
e8af50a3 | 4665 | } |
7a3f1944 | 4666 | #ifdef DEBUG_DISAS |
e19e89a5 | 4667 | if (loglevel & CPU_LOG_TB_IN_ASM) { |
0f8a249a BS |
4668 | fprintf(logfile, "--------------\n"); |
4669 | fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start)); | |
4670 | target_disas(logfile, pc_start, last_pc + 4 - pc_start, 0); | |
4671 | fprintf(logfile, "\n"); | |
cf495bcf | 4672 | } |
7a3f1944 | 4673 | #endif |
cf495bcf | 4674 | return 0; |
7a3f1944 FB |
4675 | } |
4676 | ||
cf495bcf | 4677 | int gen_intermediate_code(CPUSPARCState * env, TranslationBlock * tb) |
7a3f1944 | 4678 | { |
e8af50a3 | 4679 | return gen_intermediate_code_internal(tb, 0, env); |
7a3f1944 FB |
4680 | } |
4681 | ||
cf495bcf | 4682 | int gen_intermediate_code_pc(CPUSPARCState * env, TranslationBlock * tb) |
7a3f1944 | 4683 | { |
e8af50a3 | 4684 | return gen_intermediate_code_internal(tb, 1, env); |
7a3f1944 FB |
4685 | } |
4686 | ||
e80cfcfc FB |
4687 | void cpu_reset(CPUSPARCState *env) |
4688 | { | |
bb05683b | 4689 | tlb_flush(env, 1); |
cf495bcf FB |
4690 | env->cwp = 0; |
4691 | env->wim = 1; | |
4692 | env->regwptr = env->regbase + (env->cwp * 16); | |
e8af50a3 | 4693 | #if defined(CONFIG_USER_ONLY) |
cf495bcf | 4694 | env->user_mode_only = 1; |
5ef54116 | 4695 | #ifdef TARGET_SPARC64 |
6ef905f6 BS |
4696 | env->cleanwin = NWINDOWS - 2; |
4697 | env->cansave = NWINDOWS - 2; | |
4698 | env->pstate = PS_RMO | PS_PEF | PS_IE; | |
4699 | env->asi = 0x82; // Primary no-fault | |
5ef54116 | 4700 | #endif |
e8af50a3 | 4701 | #else |
32af58f9 | 4702 | env->psret = 0; |
e8af50a3 | 4703 | env->psrs = 1; |
0bee699e | 4704 | env->psrps = 1; |
3475187d | 4705 | #ifdef TARGET_SPARC64 |
83469015 | 4706 | env->pstate = PS_PRIV; |
6f27aba6 | 4707 | env->hpstate = HS_PRIV; |
83469015 | 4708 | env->pc = 0x1fff0000000ULL; |
375ee38b | 4709 | env->tsptr = &env->ts[env->tl]; |
3475187d | 4710 | #else |
40ce0a9a | 4711 | env->pc = 0; |
32af58f9 | 4712 | env->mmuregs[0] &= ~(MMU_E | MMU_NF); |
6d5f237a | 4713 | env->mmuregs[0] |= env->mmu_bm; |
3475187d | 4714 | #endif |
83469015 | 4715 | env->npc = env->pc + 4; |
e8af50a3 | 4716 | #endif |
e80cfcfc FB |
4717 | } |
4718 | ||
aaed909a | 4719 | CPUSPARCState *cpu_sparc_init(const char *cpu_model) |
e80cfcfc FB |
4720 | { |
4721 | CPUSPARCState *env; | |
aaed909a | 4722 | const sparc_def_t *def; |
1a2fb1c0 | 4723 | static int inited; |
f5069b26 BS |
4724 | unsigned int i; |
4725 | static const char * const gregnames[8] = { | |
4726 | NULL, // g0 not used | |
4727 | "g1", | |
4728 | "g2", | |
4729 | "g3", | |
4730 | "g4", | |
4731 | "g5", | |
4732 | "g6", | |
4733 | "g7", | |
4734 | }; | |
aaed909a FB |
4735 | |
4736 | def = cpu_sparc_find_by_name(cpu_model); | |
4737 | if (!def) | |
4738 | return NULL; | |
e80cfcfc | 4739 | |
c68ea704 FB |
4740 | env = qemu_mallocz(sizeof(CPUSPARCState)); |
4741 | if (!env) | |
0f8a249a | 4742 | return NULL; |
c68ea704 | 4743 | cpu_exec_init(env); |
01ba9816 | 4744 | env->cpu_model_str = cpu_model; |
aaed909a FB |
4745 | env->version = def->iu_version; |
4746 | env->fsr = def->fpu_version; | |
4747 | #if !defined(TARGET_SPARC64) | |
4748 | env->mmu_bm = def->mmu_bm; | |
3deaeab7 BS |
4749 | env->mmu_ctpr_mask = def->mmu_ctpr_mask; |
4750 | env->mmu_cxr_mask = def->mmu_cxr_mask; | |
4751 | env->mmu_sfsr_mask = def->mmu_sfsr_mask; | |
4752 | env->mmu_trcr_mask = def->mmu_trcr_mask; | |
aaed909a FB |
4753 | env->mmuregs[0] |= def->mmu_version; |
4754 | cpu_sparc_set_id(env, 0); | |
4755 | #endif | |
1a2fb1c0 BS |
4756 | |
4757 | /* init various static tables */ | |
4758 | if (!inited) { | |
4759 | inited = 1; | |
4760 | ||
4761 | tcg_set_macro_func(&tcg_ctx, tcg_macro_func); | |
4762 | cpu_env = tcg_global_reg_new(TCG_TYPE_PTR, TCG_AREG0, "env"); | |
db4a4ea4 BS |
4763 | cpu_regwptr = tcg_global_mem_new(TCG_TYPE_PTR, TCG_AREG0, |
4764 | offsetof(CPUState, regwptr), | |
4765 | "regwptr"); | |
1a2fb1c0 BS |
4766 | //#if TARGET_LONG_BITS > HOST_LONG_BITS |
4767 | #ifdef TARGET_SPARC64 | |
4768 | cpu_T[0] = tcg_global_mem_new(TCG_TYPE_TL, | |
4769 | TCG_AREG0, offsetof(CPUState, t0), "T0"); | |
4770 | cpu_T[1] = tcg_global_mem_new(TCG_TYPE_TL, | |
4771 | TCG_AREG0, offsetof(CPUState, t1), "T1"); | |
4772 | cpu_T[2] = tcg_global_mem_new(TCG_TYPE_TL, | |
4773 | TCG_AREG0, offsetof(CPUState, t2), "T2"); | |
dc99a3f2 BS |
4774 | cpu_xcc = tcg_global_mem_new(TCG_TYPE_I32, |
4775 | TCG_AREG0, offsetof(CPUState, xcc), | |
4776 | "xcc"); | |
1a2fb1c0 BS |
4777 | #else |
4778 | cpu_T[0] = tcg_global_reg_new(TCG_TYPE_TL, TCG_AREG1, "T0"); | |
4779 | cpu_T[1] = tcg_global_reg_new(TCG_TYPE_TL, TCG_AREG2, "T1"); | |
4780 | cpu_T[2] = tcg_global_reg_new(TCG_TYPE_TL, TCG_AREG3, "T2"); | |
4781 | #endif | |
dc99a3f2 BS |
4782 | cpu_cc_src = tcg_global_mem_new(TCG_TYPE_TL, |
4783 | TCG_AREG0, offsetof(CPUState, cc_src), | |
4784 | "cc_src"); | |
d9bdab86 BS |
4785 | cpu_cc_src2 = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0, |
4786 | offsetof(CPUState, cc_src2), | |
4787 | "cc_src2"); | |
dc99a3f2 BS |
4788 | cpu_cc_dst = tcg_global_mem_new(TCG_TYPE_TL, |
4789 | TCG_AREG0, offsetof(CPUState, cc_dst), | |
4790 | "cc_dst"); | |
4791 | cpu_psr = tcg_global_mem_new(TCG_TYPE_I32, | |
4792 | TCG_AREG0, offsetof(CPUState, psr), | |
4793 | "psr"); | |
87e92502 BS |
4794 | cpu_fsr = tcg_global_mem_new(TCG_TYPE_TL, |
4795 | TCG_AREG0, offsetof(CPUState, fsr), | |
4796 | "fsr"); | |
48d5c82b BS |
4797 | cpu_pc = tcg_global_mem_new(TCG_TYPE_TL, |
4798 | TCG_AREG0, offsetof(CPUState, pc), | |
4799 | "pc"); | |
4800 | cpu_npc = tcg_global_mem_new(TCG_TYPE_TL, | |
4801 | TCG_AREG0, offsetof(CPUState, npc), | |
4802 | "npc"); | |
f5069b26 BS |
4803 | for (i = 1; i < 8; i++) |
4804 | cpu_gregs[i] = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0, | |
4805 | offsetof(CPUState, gregs[i]), | |
4806 | gregnames[i]); | |
1a2fb1c0 BS |
4807 | } |
4808 | ||
aaed909a FB |
4809 | cpu_reset(env); |
4810 | ||
4811 | return env; | |
4812 | } | |
4813 | ||
4814 | void cpu_sparc_set_id(CPUSPARCState *env, unsigned int cpu) | |
4815 | { | |
4816 | #if !defined(TARGET_SPARC64) | |
4817 | env->mxccregs[7] = ((cpu + 8) & 0xf) << 24; | |
4818 | #endif | |
7a3f1944 FB |
4819 | } |
4820 | ||
62724a37 BS |
4821 | static const sparc_def_t sparc_defs[] = { |
4822 | #ifdef TARGET_SPARC64 | |
7d77bf20 BS |
4823 | { |
4824 | .name = "Fujitsu Sparc64", | |
4825 | .iu_version = ((0x04ULL << 48) | (0x02ULL << 32) | (0ULL << 24) | |
4826 | | (MAXTL << 8) | (NWINDOWS - 1)), | |
4827 | .fpu_version = 0x00000000, | |
4828 | .mmu_version = 0, | |
4829 | }, | |
4830 | { | |
4831 | .name = "Fujitsu Sparc64 III", | |
4832 | .iu_version = ((0x04ULL << 48) | (0x03ULL << 32) | (0ULL << 24) | |
4833 | | (MAXTL << 8) | (NWINDOWS - 1)), | |
4834 | .fpu_version = 0x00000000, | |
4835 | .mmu_version = 0, | |
4836 | }, | |
4837 | { | |
4838 | .name = "Fujitsu Sparc64 IV", | |
4839 | .iu_version = ((0x04ULL << 48) | (0x04ULL << 32) | (0ULL << 24) | |
4840 | | (MAXTL << 8) | (NWINDOWS - 1)), | |
4841 | .fpu_version = 0x00000000, | |
4842 | .mmu_version = 0, | |
4843 | }, | |
4844 | { | |
4845 | .name = "Fujitsu Sparc64 V", | |
4846 | .iu_version = ((0x04ULL << 48) | (0x05ULL << 32) | (0x51ULL << 24) | |
4847 | | (MAXTL << 8) | (NWINDOWS - 1)), | |
4848 | .fpu_version = 0x00000000, | |
4849 | .mmu_version = 0, | |
4850 | }, | |
4851 | { | |
4852 | .name = "TI UltraSparc I", | |
4853 | .iu_version = ((0x17ULL << 48) | (0x10ULL << 32) | (0x40ULL << 24) | |
4854 | | (MAXTL << 8) | (NWINDOWS - 1)), | |
4855 | .fpu_version = 0x00000000, | |
4856 | .mmu_version = 0, | |
4857 | }, | |
62724a37 BS |
4858 | { |
4859 | .name = "TI UltraSparc II", | |
7d77bf20 BS |
4860 | .iu_version = ((0x17ULL << 48) | (0x11ULL << 32) | (0x20ULL << 24) |
4861 | | (MAXTL << 8) | (NWINDOWS - 1)), | |
4862 | .fpu_version = 0x00000000, | |
4863 | .mmu_version = 0, | |
4864 | }, | |
4865 | { | |
4866 | .name = "TI UltraSparc IIi", | |
4867 | .iu_version = ((0x17ULL << 48) | (0x12ULL << 32) | (0x91ULL << 24) | |
4868 | | (MAXTL << 8) | (NWINDOWS - 1)), | |
4869 | .fpu_version = 0x00000000, | |
4870 | .mmu_version = 0, | |
4871 | }, | |
4872 | { | |
4873 | .name = "TI UltraSparc IIe", | |
4874 | .iu_version = ((0x17ULL << 48) | (0x13ULL << 32) | (0x14ULL << 24) | |
4875 | | (MAXTL << 8) | (NWINDOWS - 1)), | |
4876 | .fpu_version = 0x00000000, | |
4877 | .mmu_version = 0, | |
4878 | }, | |
4879 | { | |
4880 | .name = "Sun UltraSparc III", | |
4881 | .iu_version = ((0x3eULL << 48) | (0x14ULL << 32) | (0x34ULL << 24) | |
4882 | | (MAXTL << 8) | (NWINDOWS - 1)), | |
4883 | .fpu_version = 0x00000000, | |
4884 | .mmu_version = 0, | |
4885 | }, | |
4886 | { | |
4887 | .name = "Sun UltraSparc III Cu", | |
4888 | .iu_version = ((0x3eULL << 48) | (0x15ULL << 32) | (0x41ULL << 24) | |
4889 | | (MAXTL << 8) | (NWINDOWS - 1)), | |
4890 | .fpu_version = 0x00000000, | |
4891 | .mmu_version = 0, | |
4892 | }, | |
4893 | { | |
4894 | .name = "Sun UltraSparc IIIi", | |
4895 | .iu_version = ((0x3eULL << 48) | (0x16ULL << 32) | (0x34ULL << 24) | |
4896 | | (MAXTL << 8) | (NWINDOWS - 1)), | |
4897 | .fpu_version = 0x00000000, | |
4898 | .mmu_version = 0, | |
4899 | }, | |
4900 | { | |
4901 | .name = "Sun UltraSparc IV", | |
4902 | .iu_version = ((0x3eULL << 48) | (0x18ULL << 32) | (0x31ULL << 24) | |
4903 | | (MAXTL << 8) | (NWINDOWS - 1)), | |
4904 | .fpu_version = 0x00000000, | |
4905 | .mmu_version = 0, | |
4906 | }, | |
4907 | { | |
4908 | .name = "Sun UltraSparc IV+", | |
4909 | .iu_version = ((0x3eULL << 48) | (0x19ULL << 32) | (0x22ULL << 24) | |
4910 | | (MAXTL << 8) | (NWINDOWS - 1)), | |
4911 | .fpu_version = 0x00000000, | |
4912 | .mmu_version = 0, | |
4913 | }, | |
4914 | { | |
4915 | .name = "Sun UltraSparc IIIi+", | |
4916 | .iu_version = ((0x3eULL << 48) | (0x22ULL << 32) | (0ULL << 24) | |
4917 | | (MAXTL << 8) | (NWINDOWS - 1)), | |
4918 | .fpu_version = 0x00000000, | |
4919 | .mmu_version = 0, | |
4920 | }, | |
4921 | { | |
4922 | .name = "NEC UltraSparc I", | |
4923 | .iu_version = ((0x22ULL << 48) | (0x10ULL << 32) | (0x40ULL << 24) | |
62724a37 BS |
4924 | | (MAXTL << 8) | (NWINDOWS - 1)), |
4925 | .fpu_version = 0x00000000, | |
4926 | .mmu_version = 0, | |
4927 | }, | |
4928 | #else | |
406f82e8 BS |
4929 | { |
4930 | .name = "Fujitsu MB86900", | |
4931 | .iu_version = 0x00 << 24, /* Impl 0, ver 0 */ | |
4932 | .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */ | |
4933 | .mmu_version = 0x00 << 24, /* Impl 0, ver 0 */ | |
4934 | .mmu_bm = 0x00004000, | |
3deaeab7 BS |
4935 | .mmu_ctpr_mask = 0x007ffff0, |
4936 | .mmu_cxr_mask = 0x0000003f, | |
4937 | .mmu_sfsr_mask = 0xffffffff, | |
4938 | .mmu_trcr_mask = 0xffffffff, | |
406f82e8 | 4939 | }, |
62724a37 BS |
4940 | { |
4941 | .name = "Fujitsu MB86904", | |
4942 | .iu_version = 0x04 << 24, /* Impl 0, ver 4 */ | |
4943 | .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */ | |
4944 | .mmu_version = 0x04 << 24, /* Impl 0, ver 4 */ | |
6d5f237a | 4945 | .mmu_bm = 0x00004000, |
3deaeab7 BS |
4946 | .mmu_ctpr_mask = 0x00ffffc0, |
4947 | .mmu_cxr_mask = 0x000000ff, | |
4948 | .mmu_sfsr_mask = 0x00016fff, | |
4949 | .mmu_trcr_mask = 0x00ffffff, | |
62724a37 | 4950 | }, |
e0353fe2 | 4951 | { |
5ef62c5c BS |
4952 | .name = "Fujitsu MB86907", |
4953 | .iu_version = 0x05 << 24, /* Impl 0, ver 5 */ | |
4954 | .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */ | |
4955 | .mmu_version = 0x05 << 24, /* Impl 0, ver 5 */ | |
6d5f237a | 4956 | .mmu_bm = 0x00004000, |
3deaeab7 BS |
4957 | .mmu_ctpr_mask = 0xffffffc0, |
4958 | .mmu_cxr_mask = 0x000000ff, | |
4959 | .mmu_sfsr_mask = 0x00016fff, | |
4960 | .mmu_trcr_mask = 0xffffffff, | |
5ef62c5c | 4961 | }, |
406f82e8 BS |
4962 | { |
4963 | .name = "LSI L64811", | |
4964 | .iu_version = 0x10 << 24, /* Impl 1, ver 0 */ | |
4965 | .fpu_version = 1 << 17, /* FPU version 1 (LSI L64814) */ | |
4966 | .mmu_version = 0x10 << 24, | |
4967 | .mmu_bm = 0x00004000, | |
3deaeab7 BS |
4968 | .mmu_ctpr_mask = 0x007ffff0, |
4969 | .mmu_cxr_mask = 0x0000003f, | |
4970 | .mmu_sfsr_mask = 0xffffffff, | |
4971 | .mmu_trcr_mask = 0xffffffff, | |
406f82e8 BS |
4972 | }, |
4973 | { | |
4974 | .name = "Cypress CY7C601", | |
4975 | .iu_version = 0x11 << 24, /* Impl 1, ver 1 */ | |
4976 | .fpu_version = 3 << 17, /* FPU version 3 (Cypress CY7C602) */ | |
4977 | .mmu_version = 0x10 << 24, | |
4978 | .mmu_bm = 0x00004000, | |
3deaeab7 BS |
4979 | .mmu_ctpr_mask = 0x007ffff0, |
4980 | .mmu_cxr_mask = 0x0000003f, | |
4981 | .mmu_sfsr_mask = 0xffffffff, | |
4982 | .mmu_trcr_mask = 0xffffffff, | |
406f82e8 BS |
4983 | }, |
4984 | { | |
4985 | .name = "Cypress CY7C611", | |
4986 | .iu_version = 0x13 << 24, /* Impl 1, ver 3 */ | |
4987 | .fpu_version = 3 << 17, /* FPU version 3 (Cypress CY7C602) */ | |
4988 | .mmu_version = 0x10 << 24, | |
4989 | .mmu_bm = 0x00004000, | |
3deaeab7 BS |
4990 | .mmu_ctpr_mask = 0x007ffff0, |
4991 | .mmu_cxr_mask = 0x0000003f, | |
4992 | .mmu_sfsr_mask = 0xffffffff, | |
4993 | .mmu_trcr_mask = 0xffffffff, | |
406f82e8 BS |
4994 | }, |
4995 | { | |
4996 | .name = "TI SuperSparc II", | |
4997 | .iu_version = 0x40000000, | |
4998 | .fpu_version = 0 << 17, | |
4999 | .mmu_version = 0x04000000, | |
5000 | .mmu_bm = 0x00002000, | |
3deaeab7 BS |
5001 | .mmu_ctpr_mask = 0xffffffc0, |
5002 | .mmu_cxr_mask = 0x0000ffff, | |
5003 | .mmu_sfsr_mask = 0xffffffff, | |
5004 | .mmu_trcr_mask = 0xffffffff, | |
406f82e8 | 5005 | }, |
5ef62c5c BS |
5006 | { |
5007 | .name = "TI MicroSparc I", | |
5008 | .iu_version = 0x41000000, | |
5009 | .fpu_version = 4 << 17, | |
5010 | .mmu_version = 0x41000000, | |
6d5f237a | 5011 | .mmu_bm = 0x00004000, |
3deaeab7 BS |
5012 | .mmu_ctpr_mask = 0x007ffff0, |
5013 | .mmu_cxr_mask = 0x0000003f, | |
5014 | .mmu_sfsr_mask = 0x00016fff, | |
5015 | .mmu_trcr_mask = 0x0000003f, | |
5ef62c5c BS |
5016 | }, |
5017 | { | |
406f82e8 BS |
5018 | .name = "TI MicroSparc II", |
5019 | .iu_version = 0x42000000, | |
5020 | .fpu_version = 4 << 17, | |
5021 | .mmu_version = 0x02000000, | |
5022 | .mmu_bm = 0x00004000, | |
3deaeab7 BS |
5023 | .mmu_ctpr_mask = 0x00ffffc0, |
5024 | .mmu_cxr_mask = 0x000000ff, | |
a3ffaf30 | 5025 | .mmu_sfsr_mask = 0x00016fff, |
3deaeab7 | 5026 | .mmu_trcr_mask = 0x00ffffff, |
406f82e8 BS |
5027 | }, |
5028 | { | |
5029 | .name = "TI MicroSparc IIep", | |
5030 | .iu_version = 0x42000000, | |
5031 | .fpu_version = 4 << 17, | |
5032 | .mmu_version = 0x04000000, | |
5033 | .mmu_bm = 0x00004000, | |
3deaeab7 BS |
5034 | .mmu_ctpr_mask = 0x00ffffc0, |
5035 | .mmu_cxr_mask = 0x000000ff, | |
5036 | .mmu_sfsr_mask = 0x00016bff, | |
5037 | .mmu_trcr_mask = 0x00ffffff, | |
406f82e8 BS |
5038 | }, |
5039 | { | |
5040 | .name = "TI SuperSparc 51", | |
5041 | .iu_version = 0x43000000, | |
5ef62c5c BS |
5042 | .fpu_version = 0 << 17, |
5043 | .mmu_version = 0x04000000, | |
6d5f237a | 5044 | .mmu_bm = 0x00002000, |
3deaeab7 BS |
5045 | .mmu_ctpr_mask = 0xffffffc0, |
5046 | .mmu_cxr_mask = 0x0000ffff, | |
5047 | .mmu_sfsr_mask = 0xffffffff, | |
5048 | .mmu_trcr_mask = 0xffffffff, | |
5ef62c5c BS |
5049 | }, |
5050 | { | |
406f82e8 BS |
5051 | .name = "TI SuperSparc 61", |
5052 | .iu_version = 0x44000000, | |
5053 | .fpu_version = 0 << 17, | |
5054 | .mmu_version = 0x04000000, | |
5055 | .mmu_bm = 0x00002000, | |
3deaeab7 BS |
5056 | .mmu_ctpr_mask = 0xffffffc0, |
5057 | .mmu_cxr_mask = 0x0000ffff, | |
5058 | .mmu_sfsr_mask = 0xffffffff, | |
5059 | .mmu_trcr_mask = 0xffffffff, | |
406f82e8 BS |
5060 | }, |
5061 | { | |
5062 | .name = "Ross RT625", | |
5ef62c5c BS |
5063 | .iu_version = 0x1e000000, |
5064 | .fpu_version = 1 << 17, | |
406f82e8 BS |
5065 | .mmu_version = 0x1e000000, |
5066 | .mmu_bm = 0x00004000, | |
3deaeab7 BS |
5067 | .mmu_ctpr_mask = 0x007ffff0, |
5068 | .mmu_cxr_mask = 0x0000003f, | |
5069 | .mmu_sfsr_mask = 0xffffffff, | |
5070 | .mmu_trcr_mask = 0xffffffff, | |
406f82e8 BS |
5071 | }, |
5072 | { | |
5073 | .name = "Ross RT620", | |
5074 | .iu_version = 0x1f000000, | |
5075 | .fpu_version = 1 << 17, | |
5076 | .mmu_version = 0x1f000000, | |
5077 | .mmu_bm = 0x00004000, | |
3deaeab7 BS |
5078 | .mmu_ctpr_mask = 0x007ffff0, |
5079 | .mmu_cxr_mask = 0x0000003f, | |
5080 | .mmu_sfsr_mask = 0xffffffff, | |
5081 | .mmu_trcr_mask = 0xffffffff, | |
406f82e8 BS |
5082 | }, |
5083 | { | |
5084 | .name = "BIT B5010", | |
5085 | .iu_version = 0x20000000, | |
5086 | .fpu_version = 0 << 17, /* B5010/B5110/B5120/B5210 */ | |
5087 | .mmu_version = 0x20000000, | |
5088 | .mmu_bm = 0x00004000, | |
3deaeab7 BS |
5089 | .mmu_ctpr_mask = 0x007ffff0, |
5090 | .mmu_cxr_mask = 0x0000003f, | |
5091 | .mmu_sfsr_mask = 0xffffffff, | |
5092 | .mmu_trcr_mask = 0xffffffff, | |
406f82e8 BS |
5093 | }, |
5094 | { | |
5095 | .name = "Matsushita MN10501", | |
5096 | .iu_version = 0x50000000, | |
5097 | .fpu_version = 0 << 17, | |
5098 | .mmu_version = 0x50000000, | |
5099 | .mmu_bm = 0x00004000, | |
3deaeab7 BS |
5100 | .mmu_ctpr_mask = 0x007ffff0, |
5101 | .mmu_cxr_mask = 0x0000003f, | |
5102 | .mmu_sfsr_mask = 0xffffffff, | |
5103 | .mmu_trcr_mask = 0xffffffff, | |
406f82e8 BS |
5104 | }, |
5105 | { | |
5106 | .name = "Weitek W8601", | |
5107 | .iu_version = 0x90 << 24, /* Impl 9, ver 0 */ | |
5108 | .fpu_version = 3 << 17, /* FPU version 3 (Weitek WTL3170/2) */ | |
5109 | .mmu_version = 0x10 << 24, | |
5110 | .mmu_bm = 0x00004000, | |
3deaeab7 BS |
5111 | .mmu_ctpr_mask = 0x007ffff0, |
5112 | .mmu_cxr_mask = 0x0000003f, | |
5113 | .mmu_sfsr_mask = 0xffffffff, | |
5114 | .mmu_trcr_mask = 0xffffffff, | |
406f82e8 BS |
5115 | }, |
5116 | { | |
5117 | .name = "LEON2", | |
5118 | .iu_version = 0xf2000000, | |
5119 | .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */ | |
5120 | .mmu_version = 0xf2000000, | |
5121 | .mmu_bm = 0x00004000, | |
3deaeab7 BS |
5122 | .mmu_ctpr_mask = 0x007ffff0, |
5123 | .mmu_cxr_mask = 0x0000003f, | |
5124 | .mmu_sfsr_mask = 0xffffffff, | |
5125 | .mmu_trcr_mask = 0xffffffff, | |
406f82e8 BS |
5126 | }, |
5127 | { | |
5128 | .name = "LEON3", | |
5129 | .iu_version = 0xf3000000, | |
5130 | .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */ | |
5131 | .mmu_version = 0xf3000000, | |
6d5f237a | 5132 | .mmu_bm = 0x00004000, |
3deaeab7 BS |
5133 | .mmu_ctpr_mask = 0x007ffff0, |
5134 | .mmu_cxr_mask = 0x0000003f, | |
5135 | .mmu_sfsr_mask = 0xffffffff, | |
5136 | .mmu_trcr_mask = 0xffffffff, | |
e0353fe2 | 5137 | }, |
62724a37 BS |
5138 | #endif |
5139 | }; | |
5140 | ||
aaed909a | 5141 | static const sparc_def_t *cpu_sparc_find_by_name(const unsigned char *name) |
62724a37 | 5142 | { |
62724a37 BS |
5143 | unsigned int i; |
5144 | ||
62724a37 BS |
5145 | for (i = 0; i < sizeof(sparc_defs) / sizeof(sparc_def_t); i++) { |
5146 | if (strcasecmp(name, sparc_defs[i].name) == 0) { | |
aaed909a | 5147 | return &sparc_defs[i]; |
62724a37 BS |
5148 | } |
5149 | } | |
aaed909a | 5150 | return NULL; |
62724a37 BS |
5151 | } |
5152 | ||
5153 | void sparc_cpu_list (FILE *f, int (*cpu_fprintf)(FILE *f, const char *fmt, ...)) | |
5154 | { | |
5155 | unsigned int i; | |
5156 | ||
5157 | for (i = 0; i < sizeof(sparc_defs) / sizeof(sparc_def_t); i++) { | |
5158 | (*cpu_fprintf)(f, "Sparc %16s IU " TARGET_FMT_lx " FPU %08x MMU %08x\n", | |
5159 | sparc_defs[i].name, | |
5160 | sparc_defs[i].iu_version, | |
5161 | sparc_defs[i].fpu_version, | |
5162 | sparc_defs[i].mmu_version); | |
5163 | } | |
5164 | } | |
5165 | ||
7a3f1944 FB |
5166 | #define GET_FLAG(a,b) ((env->psr & a)?b:'-') |
5167 | ||
5fafdf24 | 5168 | void cpu_dump_state(CPUState *env, FILE *f, |
7fe48483 FB |
5169 | int (*cpu_fprintf)(FILE *f, const char *fmt, ...), |
5170 | int flags) | |
7a3f1944 | 5171 | { |
cf495bcf FB |
5172 | int i, x; |
5173 | ||
af7bf89b | 5174 | cpu_fprintf(f, "pc: " TARGET_FMT_lx " npc: " TARGET_FMT_lx "\n", env->pc, env->npc); |
7fe48483 | 5175 | cpu_fprintf(f, "General Registers:\n"); |
cf495bcf | 5176 | for (i = 0; i < 4; i++) |
0f8a249a | 5177 | cpu_fprintf(f, "%%g%c: " TARGET_FMT_lx "\t", i + '0', env->gregs[i]); |
7fe48483 | 5178 | cpu_fprintf(f, "\n"); |
cf495bcf | 5179 | for (; i < 8; i++) |
0f8a249a | 5180 | cpu_fprintf(f, "%%g%c: " TARGET_FMT_lx "\t", i + '0', env->gregs[i]); |
7fe48483 | 5181 | cpu_fprintf(f, "\nCurrent Register Window:\n"); |
cf495bcf | 5182 | for (x = 0; x < 3; x++) { |
0f8a249a BS |
5183 | for (i = 0; i < 4; i++) |
5184 | cpu_fprintf(f, "%%%c%d: " TARGET_FMT_lx "\t", | |
5185 | (x == 0 ? 'o' : (x == 1 ? 'l' : 'i')), i, | |
5186 | env->regwptr[i + x * 8]); | |
5187 | cpu_fprintf(f, "\n"); | |
5188 | for (; i < 8; i++) | |
5189 | cpu_fprintf(f, "%%%c%d: " TARGET_FMT_lx "\t", | |
5190 | (x == 0 ? 'o' : x == 1 ? 'l' : 'i'), i, | |
5191 | env->regwptr[i + x * 8]); | |
5192 | cpu_fprintf(f, "\n"); | |
cf495bcf | 5193 | } |
7fe48483 | 5194 | cpu_fprintf(f, "\nFloating Point Registers:\n"); |
e8af50a3 FB |
5195 | for (i = 0; i < 32; i++) { |
5196 | if ((i & 3) == 0) | |
7fe48483 FB |
5197 | cpu_fprintf(f, "%%f%02d:", i); |
5198 | cpu_fprintf(f, " %016lf", env->fpr[i]); | |
e8af50a3 | 5199 | if ((i & 3) == 3) |
7fe48483 | 5200 | cpu_fprintf(f, "\n"); |
e8af50a3 | 5201 | } |
ded3ab80 | 5202 | #ifdef TARGET_SPARC64 |
3299908c | 5203 | cpu_fprintf(f, "pstate: 0x%08x ccr: 0x%02x asi: 0x%02x tl: %d fprs: %d\n", |
0f8a249a | 5204 | env->pstate, GET_CCR(env), env->asi, env->tl, env->fprs); |
ded3ab80 | 5205 | cpu_fprintf(f, "cansave: %d canrestore: %d otherwin: %d wstate %d cleanwin %d cwp %d\n", |
0f8a249a BS |
5206 | env->cansave, env->canrestore, env->otherwin, env->wstate, |
5207 | env->cleanwin, NWINDOWS - 1 - env->cwp); | |
ded3ab80 | 5208 | #else |
7fe48483 | 5209 | cpu_fprintf(f, "psr: 0x%08x -> %c%c%c%c %c%c%c wim: 0x%08x\n", GET_PSR(env), |
0f8a249a BS |
5210 | GET_FLAG(PSR_ZERO, 'Z'), GET_FLAG(PSR_OVF, 'V'), |
5211 | GET_FLAG(PSR_NEG, 'N'), GET_FLAG(PSR_CARRY, 'C'), | |
5212 | env->psrs?'S':'-', env->psrps?'P':'-', | |
5213 | env->psret?'E':'-', env->wim); | |
ded3ab80 | 5214 | #endif |
3475187d | 5215 | cpu_fprintf(f, "fsr: 0x%08x\n", GET_FSR32(env)); |
7a3f1944 | 5216 | } |
edfcbd99 | 5217 | |
e80cfcfc | 5218 | #if defined(CONFIG_USER_ONLY) |
9b3c35e0 | 5219 | target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr) |
edfcbd99 FB |
5220 | { |
5221 | return addr; | |
5222 | } | |
658138bc | 5223 | |
e80cfcfc | 5224 | #else |
af7bf89b FB |
5225 | extern int get_physical_address (CPUState *env, target_phys_addr_t *physical, int *prot, |
5226 | int *access_index, target_ulong address, int rw, | |
6ebbf390 | 5227 | int mmu_idx); |
0fa85d43 | 5228 | |
9b3c35e0 | 5229 | target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr) |
e80cfcfc | 5230 | { |
af7bf89b | 5231 | target_phys_addr_t phys_addr; |
e80cfcfc FB |
5232 | int prot, access_index; |
5233 | ||
9e31b9e2 BS |
5234 | if (get_physical_address(env, &phys_addr, &prot, &access_index, addr, 2, |
5235 | MMU_KERNEL_IDX) != 0) | |
5236 | if (get_physical_address(env, &phys_addr, &prot, &access_index, addr, | |
5237 | 0, MMU_KERNEL_IDX) != 0) | |
6b1575b7 | 5238 | return -1; |
6c36d3fa BS |
5239 | if (cpu_get_physical_page_desc(phys_addr) == IO_MEM_UNASSIGNED) |
5240 | return -1; | |
e80cfcfc FB |
5241 | return phys_addr; |
5242 | } | |
5243 | #endif | |
5244 | ||
658138bc FB |
5245 | void helper_flush(target_ulong addr) |
5246 | { | |
5247 | addr &= ~7; | |
5248 | tb_invalidate_page_range(addr, addr + 8); | |
5249 | } |