]>
Commit | Line | Data |
---|---|---|
e67db06e JL |
1 | /* |
2 | * OpenRISC translation | |
3 | * | |
4 | * Copyright (c) 2011-2012 Jia Liu <[email protected]> | |
5 | * Feng Gao <[email protected]> | |
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, see <http://www.gnu.org/licenses/>. | |
19 | */ | |
20 | ||
ed2decc6 | 21 | #include "qemu/osdep.h" |
e67db06e | 22 | #include "cpu.h" |
022c62cb | 23 | #include "exec/exec-all.h" |
76cad711 | 24 | #include "disas/disas.h" |
e67db06e JL |
25 | #include "tcg-op.h" |
26 | #include "qemu-common.h" | |
1de7afc9 | 27 | #include "qemu/log.h" |
1de7afc9 | 28 | #include "qemu/bitops.h" |
f08b6170 | 29 | #include "exec/cpu_ldst.h" |
77fc6f5e | 30 | #include "exec/translator.h" |
bbe418f2 | 31 | |
2ef6175a RH |
32 | #include "exec/helper-proto.h" |
33 | #include "exec/helper-gen.h" | |
7de9729f | 34 | #include "exec/gen-icount.h" |
e67db06e | 35 | |
a7e30d84 | 36 | #include "trace-tcg.h" |
508127e2 | 37 | #include "exec/log.h" |
a7e30d84 | 38 | |
111ece51 | 39 | #define LOG_DIS(str, ...) \ |
1ffa4bce EC |
40 | qemu_log_mask(CPU_LOG_TB_IN_ASM, "%08x: " str, dc->base.pc_next, \ |
41 | ## __VA_ARGS__) | |
e67db06e | 42 | |
77fc6f5e LV |
43 | /* is_jmp field values */ |
44 | #define DISAS_JUMP DISAS_TARGET_0 /* only pc was modified dynamically */ | |
45 | #define DISAS_UPDATE DISAS_TARGET_1 /* cpu state was modified dynamically */ | |
46 | #define DISAS_TB_JUMP DISAS_TARGET_2 /* only pc was modified statically */ | |
47 | ||
bbe418f2 | 48 | typedef struct DisasContext { |
1ffa4bce | 49 | DisasContextBase base; |
bbe418f2 | 50 | uint32_t mem_idx; |
a01deb36 | 51 | uint32_t tb_flags; |
bbe418f2 JL |
52 | uint32_t delayed_branch; |
53 | } DisasContext; | |
54 | ||
7de9729f RH |
55 | /* Include the auto-generated decoder. */ |
56 | #include "decode.inc.c" | |
57 | ||
bbe418f2 JL |
58 | static TCGv cpu_sr; |
59 | static TCGv cpu_R[32]; | |
6597c28d | 60 | static TCGv cpu_R0; |
bbe418f2 JL |
61 | static TCGv cpu_pc; |
62 | static TCGv jmp_pc; /* l.jr/l.jalr temp pc */ | |
bbe418f2 | 63 | static TCGv cpu_ppc; |
84775c43 | 64 | static TCGv cpu_sr_f; /* bf/bnf, F flag taken */ |
97458071 RH |
65 | static TCGv cpu_sr_cy; /* carry (unsigned overflow) */ |
66 | static TCGv cpu_sr_ov; /* signed overflow */ | |
930c3d00 RH |
67 | static TCGv cpu_lock_addr; |
68 | static TCGv cpu_lock_value; | |
bbe418f2 | 69 | static TCGv_i32 fpcsr; |
6f7332ba | 70 | static TCGv_i64 cpu_mac; /* MACHI:MACLO */ |
a01deb36 | 71 | static TCGv_i32 cpu_dflag; |
bbe418f2 | 72 | |
e67db06e JL |
73 | void openrisc_translate_init(void) |
74 | { | |
bbe418f2 JL |
75 | static const char * const regnames[] = { |
76 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", | |
77 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", | |
78 | "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", | |
79 | "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31", | |
80 | }; | |
81 | int i; | |
82 | ||
e1ccc054 | 83 | cpu_sr = tcg_global_mem_new(cpu_env, |
bbe418f2 | 84 | offsetof(CPUOpenRISCState, sr), "sr"); |
a01deb36 RH |
85 | cpu_dflag = tcg_global_mem_new_i32(cpu_env, |
86 | offsetof(CPUOpenRISCState, dflag), | |
87 | "dflag"); | |
e1ccc054 | 88 | cpu_pc = tcg_global_mem_new(cpu_env, |
bbe418f2 | 89 | offsetof(CPUOpenRISCState, pc), "pc"); |
e1ccc054 | 90 | cpu_ppc = tcg_global_mem_new(cpu_env, |
bbe418f2 | 91 | offsetof(CPUOpenRISCState, ppc), "ppc"); |
e1ccc054 | 92 | jmp_pc = tcg_global_mem_new(cpu_env, |
bbe418f2 | 93 | offsetof(CPUOpenRISCState, jmp_pc), "jmp_pc"); |
84775c43 RH |
94 | cpu_sr_f = tcg_global_mem_new(cpu_env, |
95 | offsetof(CPUOpenRISCState, sr_f), "sr_f"); | |
97458071 RH |
96 | cpu_sr_cy = tcg_global_mem_new(cpu_env, |
97 | offsetof(CPUOpenRISCState, sr_cy), "sr_cy"); | |
98 | cpu_sr_ov = tcg_global_mem_new(cpu_env, | |
99 | offsetof(CPUOpenRISCState, sr_ov), "sr_ov"); | |
930c3d00 RH |
100 | cpu_lock_addr = tcg_global_mem_new(cpu_env, |
101 | offsetof(CPUOpenRISCState, lock_addr), | |
102 | "lock_addr"); | |
103 | cpu_lock_value = tcg_global_mem_new(cpu_env, | |
104 | offsetof(CPUOpenRISCState, lock_value), | |
105 | "lock_value"); | |
e1ccc054 | 106 | fpcsr = tcg_global_mem_new_i32(cpu_env, |
bbe418f2 JL |
107 | offsetof(CPUOpenRISCState, fpcsr), |
108 | "fpcsr"); | |
6f7332ba RH |
109 | cpu_mac = tcg_global_mem_new_i64(cpu_env, |
110 | offsetof(CPUOpenRISCState, mac), | |
111 | "mac"); | |
bbe418f2 | 112 | for (i = 0; i < 32; i++) { |
e1ccc054 | 113 | cpu_R[i] = tcg_global_mem_new(cpu_env, |
d89e71e8 SH |
114 | offsetof(CPUOpenRISCState, |
115 | shadow_gpr[0][i]), | |
bbe418f2 JL |
116 | regnames[i]); |
117 | } | |
6597c28d | 118 | cpu_R0 = cpu_R[0]; |
bbe418f2 JL |
119 | } |
120 | ||
bbe418f2 JL |
121 | static void gen_exception(DisasContext *dc, unsigned int excp) |
122 | { | |
123 | TCGv_i32 tmp = tcg_const_i32(excp); | |
124 | gen_helper_exception(cpu_env, tmp); | |
125 | tcg_temp_free_i32(tmp); | |
126 | } | |
127 | ||
128 | static void gen_illegal_exception(DisasContext *dc) | |
129 | { | |
1ffa4bce | 130 | tcg_gen_movi_tl(cpu_pc, dc->base.pc_next); |
bbe418f2 | 131 | gen_exception(dc, EXCP_ILLEGAL); |
1ffa4bce | 132 | dc->base.is_jmp = DISAS_NORETURN; |
bbe418f2 JL |
133 | } |
134 | ||
135 | /* not used yet, open it when we need or64. */ | |
136 | /*#ifdef TARGET_OPENRISC64 | |
137 | static void check_ob64s(DisasContext *dc) | |
138 | { | |
139 | if (!(dc->flags & CPUCFGR_OB64S)) { | |
140 | gen_illegal_exception(dc); | |
141 | } | |
142 | } | |
143 | ||
144 | static void check_of64s(DisasContext *dc) | |
145 | { | |
146 | if (!(dc->flags & CPUCFGR_OF64S)) { | |
147 | gen_illegal_exception(dc); | |
148 | } | |
149 | } | |
150 | ||
151 | static void check_ov64s(DisasContext *dc) | |
152 | { | |
153 | if (!(dc->flags & CPUCFGR_OV64S)) { | |
154 | gen_illegal_exception(dc); | |
155 | } | |
156 | } | |
157 | #endif*/ | |
158 | ||
6597c28d RH |
159 | /* We're about to write to REG. On the off-chance that the user is |
160 | writing to R0, re-instate the architectural register. */ | |
161 | #define check_r0_write(reg) \ | |
162 | do { \ | |
163 | if (unlikely(reg == 0)) { \ | |
164 | cpu_R[0] = cpu_R0; \ | |
165 | } \ | |
166 | } while (0) | |
167 | ||
90aa39a1 SF |
168 | static inline bool use_goto_tb(DisasContext *dc, target_ulong dest) |
169 | { | |
1ffa4bce | 170 | if (unlikely(dc->base.singlestep_enabled)) { |
90aa39a1 SF |
171 | return false; |
172 | } | |
173 | ||
174 | #ifndef CONFIG_USER_ONLY | |
1ffa4bce | 175 | return (dc->base.tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK); |
90aa39a1 SF |
176 | #else |
177 | return true; | |
178 | #endif | |
179 | } | |
180 | ||
bbe418f2 JL |
181 | static void gen_goto_tb(DisasContext *dc, int n, target_ulong dest) |
182 | { | |
90aa39a1 | 183 | if (use_goto_tb(dc, dest)) { |
bbe418f2 JL |
184 | tcg_gen_movi_tl(cpu_pc, dest); |
185 | tcg_gen_goto_tb(n); | |
1ffa4bce | 186 | tcg_gen_exit_tb((uintptr_t)dc->base.tb + n); |
bbe418f2 JL |
187 | } else { |
188 | tcg_gen_movi_tl(cpu_pc, dest); | |
1ffa4bce | 189 | if (dc->base.singlestep_enabled) { |
bbe418f2 JL |
190 | gen_exception(dc, EXCP_DEBUG); |
191 | } | |
192 | tcg_gen_exit_tb(0); | |
193 | } | |
194 | } | |
195 | ||
97458071 | 196 | static void gen_ove_cy(DisasContext *dc) |
9ecaa27e | 197 | { |
0c53d734 | 198 | if (dc->tb_flags & SR_OVE) { |
97458071 | 199 | gen_helper_ove_cy(cpu_env); |
0c53d734 | 200 | } |
9ecaa27e RH |
201 | } |
202 | ||
97458071 | 203 | static void gen_ove_ov(DisasContext *dc) |
9ecaa27e | 204 | { |
0c53d734 | 205 | if (dc->tb_flags & SR_OVE) { |
97458071 | 206 | gen_helper_ove_ov(cpu_env); |
0c53d734 | 207 | } |
9ecaa27e RH |
208 | } |
209 | ||
97458071 | 210 | static void gen_ove_cyov(DisasContext *dc) |
9ecaa27e | 211 | { |
0c53d734 | 212 | if (dc->tb_flags & SR_OVE) { |
97458071 | 213 | gen_helper_ove_cyov(cpu_env); |
0c53d734 | 214 | } |
9ecaa27e RH |
215 | } |
216 | ||
217 | static void gen_add(DisasContext *dc, TCGv dest, TCGv srca, TCGv srcb) | |
218 | { | |
219 | TCGv t0 = tcg_const_tl(0); | |
220 | TCGv res = tcg_temp_new(); | |
9ecaa27e | 221 | |
97458071 RH |
222 | tcg_gen_add2_tl(res, cpu_sr_cy, srca, t0, srcb, t0); |
223 | tcg_gen_xor_tl(cpu_sr_ov, srca, srcb); | |
9ecaa27e | 224 | tcg_gen_xor_tl(t0, res, srcb); |
97458071 | 225 | tcg_gen_andc_tl(cpu_sr_ov, t0, cpu_sr_ov); |
9ecaa27e RH |
226 | tcg_temp_free(t0); |
227 | ||
228 | tcg_gen_mov_tl(dest, res); | |
229 | tcg_temp_free(res); | |
230 | ||
97458071 | 231 | gen_ove_cyov(dc); |
9ecaa27e RH |
232 | } |
233 | ||
234 | static void gen_addc(DisasContext *dc, TCGv dest, TCGv srca, TCGv srcb) | |
235 | { | |
236 | TCGv t0 = tcg_const_tl(0); | |
237 | TCGv res = tcg_temp_new(); | |
9ecaa27e | 238 | |
97458071 RH |
239 | tcg_gen_add2_tl(res, cpu_sr_cy, srca, t0, cpu_sr_cy, t0); |
240 | tcg_gen_add2_tl(res, cpu_sr_cy, res, cpu_sr_cy, srcb, t0); | |
241 | tcg_gen_xor_tl(cpu_sr_ov, srca, srcb); | |
9ecaa27e | 242 | tcg_gen_xor_tl(t0, res, srcb); |
97458071 | 243 | tcg_gen_andc_tl(cpu_sr_ov, t0, cpu_sr_ov); |
9ecaa27e RH |
244 | tcg_temp_free(t0); |
245 | ||
246 | tcg_gen_mov_tl(dest, res); | |
247 | tcg_temp_free(res); | |
248 | ||
97458071 | 249 | gen_ove_cyov(dc); |
9ecaa27e RH |
250 | } |
251 | ||
252 | static void gen_sub(DisasContext *dc, TCGv dest, TCGv srca, TCGv srcb) | |
253 | { | |
254 | TCGv res = tcg_temp_new(); | |
9ecaa27e RH |
255 | |
256 | tcg_gen_sub_tl(res, srca, srcb); | |
97458071 RH |
257 | tcg_gen_xor_tl(cpu_sr_cy, srca, srcb); |
258 | tcg_gen_xor_tl(cpu_sr_ov, res, srcb); | |
259 | tcg_gen_and_tl(cpu_sr_ov, cpu_sr_ov, cpu_sr_cy); | |
260 | tcg_gen_setcond_tl(TCG_COND_LTU, cpu_sr_cy, srca, srcb); | |
9ecaa27e RH |
261 | |
262 | tcg_gen_mov_tl(dest, res); | |
263 | tcg_temp_free(res); | |
264 | ||
97458071 | 265 | gen_ove_cyov(dc); |
9ecaa27e RH |
266 | } |
267 | ||
268 | static void gen_mul(DisasContext *dc, TCGv dest, TCGv srca, TCGv srcb) | |
269 | { | |
9ecaa27e RH |
270 | TCGv t0 = tcg_temp_new(); |
271 | ||
97458071 | 272 | tcg_gen_muls2_tl(dest, cpu_sr_ov, srca, srcb); |
9ecaa27e | 273 | tcg_gen_sari_tl(t0, dest, TARGET_LONG_BITS - 1); |
97458071 | 274 | tcg_gen_setcond_tl(TCG_COND_NE, cpu_sr_ov, cpu_sr_ov, t0); |
9ecaa27e RH |
275 | tcg_temp_free(t0); |
276 | ||
97458071 RH |
277 | tcg_gen_neg_tl(cpu_sr_ov, cpu_sr_ov); |
278 | gen_ove_ov(dc); | |
9ecaa27e RH |
279 | } |
280 | ||
281 | static void gen_mulu(DisasContext *dc, TCGv dest, TCGv srca, TCGv srcb) | |
282 | { | |
97458071 RH |
283 | tcg_gen_muls2_tl(dest, cpu_sr_cy, srca, srcb); |
284 | tcg_gen_setcondi_tl(TCG_COND_NE, cpu_sr_cy, cpu_sr_cy, 0); | |
9ecaa27e | 285 | |
97458071 | 286 | gen_ove_cy(dc); |
9ecaa27e RH |
287 | } |
288 | ||
289 | static void gen_div(DisasContext *dc, TCGv dest, TCGv srca, TCGv srcb) | |
290 | { | |
9ecaa27e RH |
291 | TCGv t0 = tcg_temp_new(); |
292 | ||
97458071 | 293 | tcg_gen_setcondi_tl(TCG_COND_EQ, cpu_sr_ov, srcb, 0); |
9ecaa27e RH |
294 | /* The result of divide-by-zero is undefined. |
295 | Supress the host-side exception by dividing by 1. */ | |
97458071 | 296 | tcg_gen_or_tl(t0, srcb, cpu_sr_ov); |
9ecaa27e RH |
297 | tcg_gen_div_tl(dest, srca, t0); |
298 | tcg_temp_free(t0); | |
299 | ||
97458071 RH |
300 | tcg_gen_neg_tl(cpu_sr_ov, cpu_sr_ov); |
301 | gen_ove_ov(dc); | |
9ecaa27e RH |
302 | } |
303 | ||
304 | static void gen_divu(DisasContext *dc, TCGv dest, TCGv srca, TCGv srcb) | |
305 | { | |
9ecaa27e RH |
306 | TCGv t0 = tcg_temp_new(); |
307 | ||
97458071 | 308 | tcg_gen_setcondi_tl(TCG_COND_EQ, cpu_sr_cy, srcb, 0); |
9ecaa27e RH |
309 | /* The result of divide-by-zero is undefined. |
310 | Supress the host-side exception by dividing by 1. */ | |
97458071 | 311 | tcg_gen_or_tl(t0, srcb, cpu_sr_cy); |
9ecaa27e RH |
312 | tcg_gen_divu_tl(dest, srca, t0); |
313 | tcg_temp_free(t0); | |
314 | ||
97458071 | 315 | gen_ove_cy(dc); |
9ecaa27e | 316 | } |
da1d7759 | 317 | |
cc5de49e RH |
318 | static void gen_muld(DisasContext *dc, TCGv srca, TCGv srcb) |
319 | { | |
320 | TCGv_i64 t1 = tcg_temp_new_i64(); | |
321 | TCGv_i64 t2 = tcg_temp_new_i64(); | |
322 | ||
323 | tcg_gen_ext_tl_i64(t1, srca); | |
324 | tcg_gen_ext_tl_i64(t2, srcb); | |
325 | if (TARGET_LONG_BITS == 32) { | |
326 | tcg_gen_mul_i64(cpu_mac, t1, t2); | |
327 | tcg_gen_movi_tl(cpu_sr_ov, 0); | |
328 | } else { | |
329 | TCGv_i64 high = tcg_temp_new_i64(); | |
330 | ||
331 | tcg_gen_muls2_i64(cpu_mac, high, t1, t2); | |
332 | tcg_gen_sari_i64(t1, cpu_mac, 63); | |
333 | tcg_gen_setcond_i64(TCG_COND_NE, t1, t1, high); | |
334 | tcg_temp_free_i64(high); | |
335 | tcg_gen_trunc_i64_tl(cpu_sr_ov, t1); | |
336 | tcg_gen_neg_tl(cpu_sr_ov, cpu_sr_ov); | |
337 | ||
338 | gen_ove_ov(dc); | |
339 | } | |
340 | tcg_temp_free_i64(t1); | |
341 | tcg_temp_free_i64(t2); | |
342 | } | |
343 | ||
344 | static void gen_muldu(DisasContext *dc, TCGv srca, TCGv srcb) | |
345 | { | |
346 | TCGv_i64 t1 = tcg_temp_new_i64(); | |
347 | TCGv_i64 t2 = tcg_temp_new_i64(); | |
348 | ||
349 | tcg_gen_extu_tl_i64(t1, srca); | |
350 | tcg_gen_extu_tl_i64(t2, srcb); | |
351 | if (TARGET_LONG_BITS == 32) { | |
352 | tcg_gen_mul_i64(cpu_mac, t1, t2); | |
353 | tcg_gen_movi_tl(cpu_sr_cy, 0); | |
354 | } else { | |
355 | TCGv_i64 high = tcg_temp_new_i64(); | |
356 | ||
357 | tcg_gen_mulu2_i64(cpu_mac, high, t1, t2); | |
358 | tcg_gen_setcondi_i64(TCG_COND_NE, high, high, 0); | |
359 | tcg_gen_trunc_i64_tl(cpu_sr_cy, high); | |
360 | tcg_temp_free_i64(high); | |
361 | ||
362 | gen_ove_cy(dc); | |
363 | } | |
364 | tcg_temp_free_i64(t1); | |
365 | tcg_temp_free_i64(t2); | |
366 | } | |
367 | ||
6f7332ba RH |
368 | static void gen_mac(DisasContext *dc, TCGv srca, TCGv srcb) |
369 | { | |
370 | TCGv_i64 t1 = tcg_temp_new_i64(); | |
371 | TCGv_i64 t2 = tcg_temp_new_i64(); | |
372 | ||
373 | tcg_gen_ext_tl_i64(t1, srca); | |
374 | tcg_gen_ext_tl_i64(t2, srcb); | |
375 | tcg_gen_mul_i64(t1, t1, t2); | |
376 | ||
377 | /* Note that overflow is only computed during addition stage. */ | |
378 | tcg_gen_xor_i64(t2, cpu_mac, t1); | |
379 | tcg_gen_add_i64(cpu_mac, cpu_mac, t1); | |
380 | tcg_gen_xor_i64(t1, t1, cpu_mac); | |
381 | tcg_gen_andc_i64(t1, t1, t2); | |
382 | tcg_temp_free_i64(t2); | |
383 | ||
384 | #if TARGET_LONG_BITS == 32 | |
385 | tcg_gen_extrh_i64_i32(cpu_sr_ov, t1); | |
386 | #else | |
387 | tcg_gen_mov_i64(cpu_sr_ov, t1); | |
388 | #endif | |
389 | tcg_temp_free_i64(t1); | |
390 | ||
391 | gen_ove_ov(dc); | |
392 | } | |
393 | ||
cc5de49e RH |
394 | static void gen_macu(DisasContext *dc, TCGv srca, TCGv srcb) |
395 | { | |
396 | TCGv_i64 t1 = tcg_temp_new_i64(); | |
397 | TCGv_i64 t2 = tcg_temp_new_i64(); | |
398 | ||
399 | tcg_gen_extu_tl_i64(t1, srca); | |
400 | tcg_gen_extu_tl_i64(t2, srcb); | |
401 | tcg_gen_mul_i64(t1, t1, t2); | |
402 | tcg_temp_free_i64(t2); | |
403 | ||
404 | /* Note that overflow is only computed during addition stage. */ | |
405 | tcg_gen_add_i64(cpu_mac, cpu_mac, t1); | |
406 | tcg_gen_setcond_i64(TCG_COND_LTU, t1, cpu_mac, t1); | |
407 | tcg_gen_trunc_i64_tl(cpu_sr_cy, t1); | |
408 | tcg_temp_free_i64(t1); | |
409 | ||
410 | gen_ove_cy(dc); | |
411 | } | |
412 | ||
6f7332ba RH |
413 | static void gen_msb(DisasContext *dc, TCGv srca, TCGv srcb) |
414 | { | |
415 | TCGv_i64 t1 = tcg_temp_new_i64(); | |
416 | TCGv_i64 t2 = tcg_temp_new_i64(); | |
417 | ||
418 | tcg_gen_ext_tl_i64(t1, srca); | |
419 | tcg_gen_ext_tl_i64(t2, srcb); | |
420 | tcg_gen_mul_i64(t1, t1, t2); | |
421 | ||
422 | /* Note that overflow is only computed during subtraction stage. */ | |
423 | tcg_gen_xor_i64(t2, cpu_mac, t1); | |
424 | tcg_gen_sub_i64(cpu_mac, cpu_mac, t1); | |
425 | tcg_gen_xor_i64(t1, t1, cpu_mac); | |
426 | tcg_gen_and_i64(t1, t1, t2); | |
427 | tcg_temp_free_i64(t2); | |
428 | ||
429 | #if TARGET_LONG_BITS == 32 | |
430 | tcg_gen_extrh_i64_i32(cpu_sr_ov, t1); | |
431 | #else | |
432 | tcg_gen_mov_i64(cpu_sr_ov, t1); | |
433 | #endif | |
434 | tcg_temp_free_i64(t1); | |
435 | ||
436 | gen_ove_ov(dc); | |
437 | } | |
438 | ||
cc5de49e RH |
439 | static void gen_msbu(DisasContext *dc, TCGv srca, TCGv srcb) |
440 | { | |
441 | TCGv_i64 t1 = tcg_temp_new_i64(); | |
442 | TCGv_i64 t2 = tcg_temp_new_i64(); | |
443 | ||
444 | tcg_gen_extu_tl_i64(t1, srca); | |
445 | tcg_gen_extu_tl_i64(t2, srcb); | |
446 | tcg_gen_mul_i64(t1, t1, t2); | |
447 | ||
448 | /* Note that overflow is only computed during subtraction stage. */ | |
449 | tcg_gen_setcond_i64(TCG_COND_LTU, t2, cpu_mac, t1); | |
450 | tcg_gen_sub_i64(cpu_mac, cpu_mac, t1); | |
451 | tcg_gen_trunc_i64_tl(cpu_sr_cy, t2); | |
452 | tcg_temp_free_i64(t2); | |
453 | tcg_temp_free_i64(t1); | |
454 | ||
455 | gen_ove_cy(dc); | |
456 | } | |
457 | ||
bbe418f2 JL |
458 | static void dec_calc(DisasContext *dc, uint32_t insn) |
459 | { | |
460 | uint32_t op0, op1, op2; | |
461 | uint32_t ra, rb, rd; | |
462 | op0 = extract32(insn, 0, 4); | |
463 | op1 = extract32(insn, 8, 2); | |
464 | op2 = extract32(insn, 6, 2); | |
465 | ra = extract32(insn, 16, 5); | |
466 | rb = extract32(insn, 11, 5); | |
467 | rd = extract32(insn, 21, 5); | |
468 | ||
cf2ae442 RH |
469 | switch (op1) { |
470 | case 0: | |
471 | switch (op0) { | |
472 | case 0x0: /* l.add */ | |
bbe418f2 | 473 | LOG_DIS("l.add r%d, r%d, r%d\n", rd, ra, rb); |
9ecaa27e | 474 | gen_add(dc, cpu_R[rd], cpu_R[ra], cpu_R[rb]); |
cf2ae442 | 475 | return; |
bbe418f2 | 476 | |
cf2ae442 | 477 | case 0x1: /* l.addc */ |
bbe418f2 | 478 | LOG_DIS("l.addc r%d, r%d, r%d\n", rd, ra, rb); |
9ecaa27e | 479 | gen_addc(dc, cpu_R[rd], cpu_R[ra], cpu_R[rb]); |
cf2ae442 | 480 | return; |
bbe418f2 | 481 | |
cf2ae442 | 482 | case 0x2: /* l.sub */ |
bbe418f2 | 483 | LOG_DIS("l.sub r%d, r%d, r%d\n", rd, ra, rb); |
9ecaa27e | 484 | gen_sub(dc, cpu_R[rd], cpu_R[ra], cpu_R[rb]); |
cf2ae442 | 485 | return; |
bbe418f2 | 486 | |
cf2ae442 | 487 | case 0x3: /* l.and */ |
bbe418f2 JL |
488 | LOG_DIS("l.and r%d, r%d, r%d\n", rd, ra, rb); |
489 | tcg_gen_and_tl(cpu_R[rd], cpu_R[ra], cpu_R[rb]); | |
cf2ae442 | 490 | return; |
bbe418f2 | 491 | |
cf2ae442 | 492 | case 0x4: /* l.or */ |
bbe418f2 JL |
493 | LOG_DIS("l.or r%d, r%d, r%d\n", rd, ra, rb); |
494 | tcg_gen_or_tl(cpu_R[rd], cpu_R[ra], cpu_R[rb]); | |
cf2ae442 | 495 | return; |
bbe418f2 | 496 | |
cf2ae442 | 497 | case 0x5: /* l.xor */ |
bbe418f2 JL |
498 | LOG_DIS("l.xor r%d, r%d, r%d\n", rd, ra, rb); |
499 | tcg_gen_xor_tl(cpu_R[rd], cpu_R[ra], cpu_R[rb]); | |
cf2ae442 | 500 | return; |
bbe418f2 | 501 | |
cf2ae442 RH |
502 | case 0x8: |
503 | switch (op2) { | |
504 | case 0: /* l.sll */ | |
505 | LOG_DIS("l.sll r%d, r%d, r%d\n", rd, ra, rb); | |
506 | tcg_gen_shl_tl(cpu_R[rd], cpu_R[ra], cpu_R[rb]); | |
507 | return; | |
508 | case 1: /* l.srl */ | |
509 | LOG_DIS("l.srl r%d, r%d, r%d\n", rd, ra, rb); | |
510 | tcg_gen_shr_tl(cpu_R[rd], cpu_R[ra], cpu_R[rb]); | |
511 | return; | |
512 | case 2: /* l.sra */ | |
513 | LOG_DIS("l.sra r%d, r%d, r%d\n", rd, ra, rb); | |
514 | tcg_gen_sar_tl(cpu_R[rd], cpu_R[ra], cpu_R[rb]); | |
515 | return; | |
516 | case 3: /* l.ror */ | |
517 | LOG_DIS("l.ror r%d, r%d, r%d\n", rd, ra, rb); | |
518 | tcg_gen_rotr_tl(cpu_R[rd], cpu_R[ra], cpu_R[rb]); | |
519 | return; | |
520 | } | |
bbe418f2 | 521 | break; |
bbe418f2 | 522 | |
cf2ae442 RH |
523 | case 0xc: |
524 | switch (op2) { | |
525 | case 0: /* l.exths */ | |
526 | LOG_DIS("l.exths r%d, r%d\n", rd, ra); | |
527 | tcg_gen_ext16s_tl(cpu_R[rd], cpu_R[ra]); | |
528 | return; | |
529 | case 1: /* l.extbs */ | |
530 | LOG_DIS("l.extbs r%d, r%d\n", rd, ra); | |
531 | tcg_gen_ext8s_tl(cpu_R[rd], cpu_R[ra]); | |
532 | return; | |
533 | case 2: /* l.exthz */ | |
534 | LOG_DIS("l.exthz r%d, r%d\n", rd, ra); | |
535 | tcg_gen_ext16u_tl(cpu_R[rd], cpu_R[ra]); | |
536 | return; | |
537 | case 3: /* l.extbz */ | |
538 | LOG_DIS("l.extbz r%d, r%d\n", rd, ra); | |
539 | tcg_gen_ext8u_tl(cpu_R[rd], cpu_R[ra]); | |
540 | return; | |
541 | } | |
bbe418f2 JL |
542 | break; |
543 | ||
cf2ae442 RH |
544 | case 0xd: |
545 | switch (op2) { | |
546 | case 0: /* l.extws */ | |
547 | LOG_DIS("l.extws r%d, r%d\n", rd, ra); | |
548 | tcg_gen_ext32s_tl(cpu_R[rd], cpu_R[ra]); | |
549 | return; | |
550 | case 1: /* l.extwz */ | |
551 | LOG_DIS("l.extwz r%d, r%d\n", rd, ra); | |
552 | tcg_gen_ext32u_tl(cpu_R[rd], cpu_R[ra]); | |
553 | return; | |
554 | } | |
bbe418f2 | 555 | break; |
bbe418f2 | 556 | |
cf2ae442 | 557 | case 0xe: /* l.cmov */ |
bbe418f2 JL |
558 | LOG_DIS("l.cmov r%d, r%d, r%d\n", rd, ra, rb); |
559 | { | |
784696d1 RH |
560 | TCGv zero = tcg_const_tl(0); |
561 | tcg_gen_movcond_tl(TCG_COND_NE, cpu_R[rd], cpu_sr_f, zero, | |
562 | cpu_R[ra], cpu_R[rb]); | |
563 | tcg_temp_free(zero); | |
bbe418f2 | 564 | } |
cf2ae442 | 565 | return; |
bbe418f2 | 566 | |
cf2ae442 | 567 | case 0xf: /* l.ff1 */ |
bbe418f2 | 568 | LOG_DIS("l.ff1 r%d, r%d, r%d\n", rd, ra, rb); |
555baef8 RH |
569 | tcg_gen_ctzi_tl(cpu_R[rd], cpu_R[ra], -1); |
570 | tcg_gen_addi_tl(cpu_R[rd], cpu_R[rd], 1); | |
cf2ae442 RH |
571 | return; |
572 | } | |
573 | break; | |
574 | ||
575 | case 1: | |
576 | switch (op0) { | |
577 | case 0xf: /* l.fl1 */ | |
bbe418f2 | 578 | LOG_DIS("l.fl1 r%d, r%d, r%d\n", rd, ra, rb); |
555baef8 RH |
579 | tcg_gen_clzi_tl(cpu_R[rd], cpu_R[ra], TARGET_LONG_BITS); |
580 | tcg_gen_subfi_tl(cpu_R[rd], TARGET_LONG_BITS, cpu_R[rd]); | |
cf2ae442 | 581 | return; |
bbe418f2 JL |
582 | } |
583 | break; | |
584 | ||
cf2ae442 | 585 | case 2: |
bbe418f2 JL |
586 | break; |
587 | ||
cf2ae442 RH |
588 | case 3: |
589 | switch (op0) { | |
590 | case 0x6: /* l.mul */ | |
591 | LOG_DIS("l.mul r%d, r%d, r%d\n", rd, ra, rb); | |
592 | gen_mul(dc, cpu_R[rd], cpu_R[ra], cpu_R[rb]); | |
593 | return; | |
bbe418f2 | 594 | |
cc5de49e RH |
595 | case 0x7: /* l.muld */ |
596 | LOG_DIS("l.muld r%d, r%d\n", ra, rb); | |
597 | gen_muld(dc, cpu_R[ra], cpu_R[rb]); | |
598 | break; | |
599 | ||
cf2ae442 RH |
600 | case 0x9: /* l.div */ |
601 | LOG_DIS("l.div r%d, r%d, r%d\n", rd, ra, rb); | |
602 | gen_div(dc, cpu_R[rd], cpu_R[ra], cpu_R[rb]); | |
603 | return; | |
bbe418f2 | 604 | |
cf2ae442 RH |
605 | case 0xa: /* l.divu */ |
606 | LOG_DIS("l.divu r%d, r%d, r%d\n", rd, ra, rb); | |
607 | gen_divu(dc, cpu_R[rd], cpu_R[ra], cpu_R[rb]); | |
608 | return; | |
bbe418f2 | 609 | |
cf2ae442 RH |
610 | case 0xb: /* l.mulu */ |
611 | LOG_DIS("l.mulu r%d, r%d, r%d\n", rd, ra, rb); | |
612 | gen_mulu(dc, cpu_R[rd], cpu_R[ra], cpu_R[rb]); | |
613 | return; | |
cc5de49e RH |
614 | |
615 | case 0xc: /* l.muldu */ | |
616 | LOG_DIS("l.muldu r%d, r%d\n", ra, rb); | |
617 | gen_muldu(dc, cpu_R[ra], cpu_R[rb]); | |
618 | return; | |
bbe418f2 JL |
619 | } |
620 | break; | |
bbe418f2 | 621 | } |
cf2ae442 | 622 | gen_illegal_exception(dc); |
bbe418f2 JL |
623 | } |
624 | ||
136e13ae RH |
625 | static bool trans_l_j(DisasContext *dc, arg_l_j *a, uint32_t insn) |
626 | { | |
627 | target_ulong tmp_pc = dc->base.pc_next + a->n * 4; | |
628 | ||
629 | LOG_DIS("l.j %d\n", a->n); | |
630 | tcg_gen_movi_tl(jmp_pc, tmp_pc); | |
631 | dc->delayed_branch = 2; | |
632 | return true; | |
633 | } | |
634 | ||
635 | static bool trans_l_jal(DisasContext *dc, arg_l_jal *a, uint32_t insn) | |
636 | { | |
637 | target_ulong tmp_pc = dc->base.pc_next + a->n * 4; | |
638 | target_ulong ret_pc = dc->base.pc_next + 8; | |
639 | ||
640 | LOG_DIS("l.jal %d\n", a->n); | |
641 | tcg_gen_movi_tl(cpu_R[9], ret_pc); | |
642 | /* Optimize jal being used to load the PC for PIC. */ | |
643 | if (tmp_pc != ret_pc) { | |
644 | tcg_gen_movi_tl(jmp_pc, tmp_pc); | |
645 | dc->delayed_branch = 2; | |
646 | } | |
647 | return true; | |
648 | } | |
649 | ||
650 | static void do_bf(DisasContext *dc, arg_l_bf *a, TCGCond cond) | |
651 | { | |
652 | target_ulong tmp_pc = dc->base.pc_next + a->n * 4; | |
653 | TCGv t_next = tcg_const_tl(dc->base.pc_next + 8); | |
654 | TCGv t_true = tcg_const_tl(tmp_pc); | |
655 | TCGv t_zero = tcg_const_tl(0); | |
656 | ||
657 | tcg_gen_movcond_tl(cond, jmp_pc, cpu_sr_f, t_zero, t_true, t_next); | |
658 | ||
659 | tcg_temp_free(t_next); | |
660 | tcg_temp_free(t_true); | |
661 | tcg_temp_free(t_zero); | |
662 | dc->delayed_branch = 2; | |
663 | } | |
664 | ||
665 | static bool trans_l_bf(DisasContext *dc, arg_l_bf *a, uint32_t insn) | |
666 | { | |
667 | LOG_DIS("l.bf %d\n", a->n); | |
668 | do_bf(dc, a, TCG_COND_NE); | |
669 | return true; | |
670 | } | |
671 | ||
672 | static bool trans_l_bnf(DisasContext *dc, arg_l_bf *a, uint32_t insn) | |
673 | { | |
674 | LOG_DIS("l.bnf %d\n", a->n); | |
675 | do_bf(dc, a, TCG_COND_EQ); | |
676 | return true; | |
677 | } | |
678 | ||
679 | static bool trans_l_jr(DisasContext *dc, arg_l_jr *a, uint32_t insn) | |
680 | { | |
681 | LOG_DIS("l.jr r%d\n", a->b); | |
682 | tcg_gen_mov_tl(jmp_pc, cpu_R[a->b]); | |
683 | dc->delayed_branch = 2; | |
684 | return true; | |
685 | } | |
686 | ||
687 | static bool trans_l_jalr(DisasContext *dc, arg_l_jalr *a, uint32_t insn) | |
688 | { | |
689 | LOG_DIS("l.jalr r%d\n", a->b); | |
690 | tcg_gen_mov_tl(jmp_pc, cpu_R[a->b]); | |
691 | tcg_gen_movi_tl(cpu_R[9], dc->base.pc_next + 8); | |
692 | dc->delayed_branch = 2; | |
693 | return true; | |
694 | } | |
695 | ||
d80bff19 RH |
696 | static bool trans_l_lwa(DisasContext *dc, arg_load *a, uint32_t insn) |
697 | { | |
698 | TCGv ea; | |
699 | ||
700 | LOG_DIS("l.lwa r%d, r%d, %d\n", a->d, a->a, a->i); | |
701 | ||
702 | check_r0_write(a->d); | |
703 | ea = tcg_temp_new(); | |
704 | tcg_gen_addi_tl(ea, cpu_R[a->a], a->i); | |
705 | tcg_gen_qemu_ld_tl(cpu_R[a->d], ea, dc->mem_idx, MO_TEUL); | |
706 | tcg_gen_mov_tl(cpu_lock_addr, ea); | |
707 | tcg_gen_mov_tl(cpu_lock_value, cpu_R[a->d]); | |
708 | tcg_temp_free(ea); | |
709 | return true; | |
710 | } | |
711 | ||
712 | static void do_load(DisasContext *dc, arg_load *a, TCGMemOp mop) | |
713 | { | |
714 | TCGv ea; | |
715 | ||
716 | check_r0_write(a->d); | |
717 | ea = tcg_temp_new(); | |
718 | tcg_gen_addi_tl(ea, cpu_R[a->a], a->i); | |
719 | tcg_gen_qemu_ld_tl(cpu_R[a->d], ea, dc->mem_idx, mop); | |
720 | tcg_temp_free(ea); | |
721 | } | |
722 | ||
723 | static bool trans_l_lwz(DisasContext *dc, arg_load *a, uint32_t insn) | |
724 | { | |
725 | LOG_DIS("l.lwz r%d, r%d, %d\n", a->d, a->a, a->i); | |
726 | do_load(dc, a, MO_TEUL); | |
727 | return true; | |
728 | } | |
729 | ||
730 | static bool trans_l_lws(DisasContext *dc, arg_load *a, uint32_t insn) | |
731 | { | |
732 | LOG_DIS("l.lws r%d, r%d, %d\n", a->d, a->a, a->i); | |
733 | do_load(dc, a, MO_TESL); | |
734 | return true; | |
735 | } | |
736 | ||
737 | static bool trans_l_lbz(DisasContext *dc, arg_load *a, uint32_t insn) | |
738 | { | |
739 | LOG_DIS("l.lbz r%d, r%d, %d\n", a->d, a->a, a->i); | |
740 | do_load(dc, a, MO_UB); | |
741 | return true; | |
742 | } | |
743 | ||
744 | static bool trans_l_lbs(DisasContext *dc, arg_load *a, uint32_t insn) | |
745 | { | |
746 | LOG_DIS("l.lbs r%d, r%d, %d\n", a->d, a->a, a->i); | |
747 | do_load(dc, a, MO_SB); | |
748 | return true; | |
749 | } | |
750 | ||
751 | static bool trans_l_lhz(DisasContext *dc, arg_load *a, uint32_t insn) | |
752 | { | |
753 | LOG_DIS("l.lhz r%d, r%d, %d\n", a->d, a->a, a->i); | |
754 | do_load(dc, a, MO_TEUW); | |
755 | return true; | |
756 | } | |
757 | ||
758 | static bool trans_l_lhs(DisasContext *dc, arg_load *a, uint32_t insn) | |
759 | { | |
760 | LOG_DIS("l.lhs r%d, r%d, %d\n", a->d, a->a, a->i); | |
761 | do_load(dc, a, MO_TESW); | |
762 | return true; | |
763 | } | |
764 | ||
765 | static bool trans_l_swa(DisasContext *dc, arg_store *a, uint32_t insn) | |
766 | { | |
767 | TCGv ea, val; | |
768 | TCGLabel *lab_fail, *lab_done; | |
769 | ||
770 | LOG_DIS("l.swa r%d, r%d, %d\n", a->a, a->b, a->i); | |
771 | ||
772 | ea = tcg_temp_new(); | |
773 | tcg_gen_addi_tl(ea, cpu_R[a->a], a->i); | |
774 | ||
775 | /* For TB_FLAGS_R0_0, the branch below invalidates the temporary assigned | |
776 | to cpu_R[0]. Since l.swa is quite often immediately followed by a | |
777 | branch, don't bother reallocating; finish the TB using the "real" R0. | |
778 | This also takes care of RB input across the branch. */ | |
779 | cpu_R[0] = cpu_R0; | |
780 | ||
781 | lab_fail = gen_new_label(); | |
782 | lab_done = gen_new_label(); | |
783 | tcg_gen_brcond_tl(TCG_COND_NE, ea, cpu_lock_addr, lab_fail); | |
784 | tcg_temp_free(ea); | |
785 | ||
786 | val = tcg_temp_new(); | |
787 | tcg_gen_atomic_cmpxchg_tl(val, cpu_lock_addr, cpu_lock_value, | |
788 | cpu_R[a->b], dc->mem_idx, MO_TEUL); | |
789 | tcg_gen_setcond_tl(TCG_COND_EQ, cpu_sr_f, val, cpu_lock_value); | |
790 | tcg_temp_free(val); | |
791 | ||
792 | tcg_gen_br(lab_done); | |
793 | ||
794 | gen_set_label(lab_fail); | |
795 | tcg_gen_movi_tl(cpu_sr_f, 0); | |
796 | ||
797 | gen_set_label(lab_done); | |
798 | tcg_gen_movi_tl(cpu_lock_addr, -1); | |
799 | return true; | |
800 | } | |
801 | ||
802 | static void do_store(DisasContext *dc, arg_store *a, TCGMemOp mop) | |
803 | { | |
804 | TCGv t0 = tcg_temp_new(); | |
805 | tcg_gen_addi_tl(t0, cpu_R[a->a], a->i); | |
806 | tcg_gen_qemu_st_tl(cpu_R[a->b], t0, dc->mem_idx, mop); | |
807 | tcg_temp_free(t0); | |
808 | } | |
809 | ||
810 | static bool trans_l_sw(DisasContext *dc, arg_store *a, uint32_t insn) | |
811 | { | |
812 | LOG_DIS("l.sw r%d, r%d, %d\n", a->a, a->b, a->i); | |
813 | do_store(dc, a, MO_TEUL); | |
814 | return true; | |
815 | } | |
816 | ||
817 | static bool trans_l_sb(DisasContext *dc, arg_store *a, uint32_t insn) | |
818 | { | |
819 | LOG_DIS("l.sb r%d, r%d, %d\n", a->a, a->b, a->i); | |
820 | do_store(dc, a, MO_UB); | |
821 | return true; | |
822 | } | |
823 | ||
824 | static bool trans_l_sh(DisasContext *dc, arg_store *a, uint32_t insn) | |
825 | { | |
826 | LOG_DIS("l.sh r%d, r%d, %d\n", a->a, a->b, a->i); | |
827 | do_store(dc, a, MO_TEUW); | |
828 | return true; | |
829 | } | |
830 | ||
bbe418f2 JL |
831 | static void dec_misc(DisasContext *dc, uint32_t insn) |
832 | { | |
833 | uint32_t op0, op1; | |
834 | uint32_t ra, rb, rd; | |
6da544a6 | 835 | uint32_t L6, K5, K16, K5_11; |
d80bff19 | 836 | int32_t I16; |
9ecaa27e | 837 | TCGv t0; |
5631e69c | 838 | |
bbe418f2 JL |
839 | op0 = extract32(insn, 26, 6); |
840 | op1 = extract32(insn, 24, 2); | |
841 | ra = extract32(insn, 16, 5); | |
842 | rb = extract32(insn, 11, 5); | |
843 | rd = extract32(insn, 21, 5); | |
bbe418f2 JL |
844 | L6 = extract32(insn, 5, 6); |
845 | K5 = extract32(insn, 0, 5); | |
6da544a6 RH |
846 | K16 = extract32(insn, 0, 16); |
847 | I16 = (int16_t)K16; | |
6da544a6 | 848 | K5_11 = (extract32(insn, 21, 5) << 11) | extract32(insn, 0, 11); |
bbe418f2 JL |
849 | |
850 | switch (op0) { | |
bbe418f2 JL |
851 | case 0x05: |
852 | switch (op1) { | |
853 | case 0x01: /* l.nop */ | |
854 | LOG_DIS("l.nop %d\n", I16); | |
855 | break; | |
856 | ||
857 | default: | |
858 | gen_illegal_exception(dc); | |
859 | break; | |
860 | } | |
861 | break; | |
862 | ||
bbe418f2 | 863 | case 0x13: /* l.maci */ |
6da544a6 | 864 | LOG_DIS("l.maci r%d, %d\n", ra, I16); |
6f7332ba RH |
865 | t0 = tcg_const_tl(I16); |
866 | gen_mac(dc, cpu_R[ra], t0); | |
867 | tcg_temp_free(t0); | |
bbe418f2 JL |
868 | break; |
869 | ||
870 | case 0x09: /* l.rfe */ | |
871 | LOG_DIS("l.rfe\n"); | |
872 | { | |
873 | #if defined(CONFIG_USER_ONLY) | |
874 | return; | |
875 | #else | |
876 | if (dc->mem_idx == MMU_USER_IDX) { | |
877 | gen_illegal_exception(dc); | |
878 | return; | |
879 | } | |
880 | gen_helper_rfe(cpu_env); | |
1ffa4bce | 881 | dc->base.is_jmp = DISAS_UPDATE; |
bbe418f2 JL |
882 | #endif |
883 | } | |
884 | break; | |
885 | ||
886 | case 0x1c: /* l.cust1 */ | |
887 | LOG_DIS("l.cust1\n"); | |
888 | break; | |
889 | ||
890 | case 0x1d: /* l.cust2 */ | |
891 | LOG_DIS("l.cust2\n"); | |
892 | break; | |
893 | ||
894 | case 0x1e: /* l.cust3 */ | |
895 | LOG_DIS("l.cust3\n"); | |
896 | break; | |
897 | ||
898 | case 0x1f: /* l.cust4 */ | |
899 | LOG_DIS("l.cust4\n"); | |
900 | break; | |
901 | ||
902 | case 0x3c: /* l.cust5 */ | |
903 | LOG_DIS("l.cust5 r%d, r%d, r%d, %d, %d\n", rd, ra, rb, L6, K5); | |
904 | break; | |
905 | ||
906 | case 0x3d: /* l.cust6 */ | |
907 | LOG_DIS("l.cust6\n"); | |
908 | break; | |
909 | ||
910 | case 0x3e: /* l.cust7 */ | |
911 | LOG_DIS("l.cust7\n"); | |
912 | break; | |
913 | ||
914 | case 0x3f: /* l.cust8 */ | |
915 | LOG_DIS("l.cust8\n"); | |
916 | break; | |
917 | ||
bbe418f2 JL |
918 | case 0x27: /* l.addi */ |
919 | LOG_DIS("l.addi r%d, r%d, %d\n", rd, ra, I16); | |
6597c28d | 920 | check_r0_write(rd); |
9ecaa27e RH |
921 | t0 = tcg_const_tl(I16); |
922 | gen_add(dc, cpu_R[rd], cpu_R[ra], t0); | |
923 | tcg_temp_free(t0); | |
bbe418f2 JL |
924 | break; |
925 | ||
926 | case 0x28: /* l.addic */ | |
927 | LOG_DIS("l.addic r%d, r%d, %d\n", rd, ra, I16); | |
6597c28d | 928 | check_r0_write(rd); |
9ecaa27e RH |
929 | t0 = tcg_const_tl(I16); |
930 | gen_addc(dc, cpu_R[rd], cpu_R[ra], t0); | |
931 | tcg_temp_free(t0); | |
bbe418f2 JL |
932 | break; |
933 | ||
934 | case 0x29: /* l.andi */ | |
6da544a6 | 935 | LOG_DIS("l.andi r%d, r%d, %d\n", rd, ra, K16); |
6597c28d | 936 | check_r0_write(rd); |
6da544a6 | 937 | tcg_gen_andi_tl(cpu_R[rd], cpu_R[ra], K16); |
bbe418f2 JL |
938 | break; |
939 | ||
940 | case 0x2a: /* l.ori */ | |
6da544a6 | 941 | LOG_DIS("l.ori r%d, r%d, %d\n", rd, ra, K16); |
6597c28d | 942 | check_r0_write(rd); |
6da544a6 | 943 | tcg_gen_ori_tl(cpu_R[rd], cpu_R[ra], K16); |
bbe418f2 JL |
944 | break; |
945 | ||
946 | case 0x2b: /* l.xori */ | |
947 | LOG_DIS("l.xori r%d, r%d, %d\n", rd, ra, I16); | |
6597c28d | 948 | check_r0_write(rd); |
6da544a6 | 949 | tcg_gen_xori_tl(cpu_R[rd], cpu_R[ra], I16); |
bbe418f2 JL |
950 | break; |
951 | ||
952 | case 0x2c: /* l.muli */ | |
953 | LOG_DIS("l.muli r%d, r%d, %d\n", rd, ra, I16); | |
6597c28d | 954 | check_r0_write(rd); |
9ecaa27e RH |
955 | t0 = tcg_const_tl(I16); |
956 | gen_mul(dc, cpu_R[rd], cpu_R[ra], t0); | |
957 | tcg_temp_free(t0); | |
bbe418f2 JL |
958 | break; |
959 | ||
960 | case 0x2d: /* l.mfspr */ | |
6da544a6 | 961 | LOG_DIS("l.mfspr r%d, r%d, %d\n", rd, ra, K16); |
6597c28d | 962 | check_r0_write(rd); |
4dd044c6 JL |
963 | { |
964 | #if defined(CONFIG_USER_ONLY) | |
965 | return; | |
966 | #else | |
6da544a6 | 967 | TCGv_i32 ti = tcg_const_i32(K16); |
4dd044c6 JL |
968 | if (dc->mem_idx == MMU_USER_IDX) { |
969 | gen_illegal_exception(dc); | |
970 | return; | |
971 | } | |
972 | gen_helper_mfspr(cpu_R[rd], cpu_env, cpu_R[rd], cpu_R[ra], ti); | |
973 | tcg_temp_free_i32(ti); | |
974 | #endif | |
975 | } | |
bbe418f2 JL |
976 | break; |
977 | ||
978 | case 0x30: /* l.mtspr */ | |
6da544a6 | 979 | LOG_DIS("l.mtspr r%d, r%d, %d\n", ra, rb, K5_11); |
4dd044c6 JL |
980 | { |
981 | #if defined(CONFIG_USER_ONLY) | |
982 | return; | |
983 | #else | |
6da544a6 | 984 | TCGv_i32 im = tcg_const_i32(K5_11); |
4dd044c6 JL |
985 | if (dc->mem_idx == MMU_USER_IDX) { |
986 | gen_illegal_exception(dc); | |
987 | return; | |
988 | } | |
989 | gen_helper_mtspr(cpu_env, cpu_R[ra], cpu_R[rb], im); | |
990 | tcg_temp_free_i32(im); | |
991 | #endif | |
992 | } | |
bbe418f2 JL |
993 | break; |
994 | ||
bbe418f2 JL |
995 | default: |
996 | gen_illegal_exception(dc); | |
997 | break; | |
998 | } | |
999 | } | |
1000 | ||
1001 | static void dec_mac(DisasContext *dc, uint32_t insn) | |
1002 | { | |
1003 | uint32_t op0; | |
1004 | uint32_t ra, rb; | |
1005 | op0 = extract32(insn, 0, 4); | |
1006 | ra = extract32(insn, 16, 5); | |
1007 | rb = extract32(insn, 11, 5); | |
1008 | ||
1009 | switch (op0) { | |
1010 | case 0x0001: /* l.mac */ | |
1011 | LOG_DIS("l.mac r%d, r%d\n", ra, rb); | |
6f7332ba | 1012 | gen_mac(dc, cpu_R[ra], cpu_R[rb]); |
bbe418f2 JL |
1013 | break; |
1014 | ||
1015 | case 0x0002: /* l.msb */ | |
1016 | LOG_DIS("l.msb r%d, r%d\n", ra, rb); | |
6f7332ba | 1017 | gen_msb(dc, cpu_R[ra], cpu_R[rb]); |
bbe418f2 JL |
1018 | break; |
1019 | ||
cc5de49e RH |
1020 | case 0x0003: /* l.macu */ |
1021 | LOG_DIS("l.macu r%d, r%d\n", ra, rb); | |
1022 | gen_macu(dc, cpu_R[ra], cpu_R[rb]); | |
1023 | break; | |
1024 | ||
1025 | case 0x0004: /* l.msbu */ | |
1026 | LOG_DIS("l.msbu r%d, r%d\n", ra, rb); | |
1027 | gen_msbu(dc, cpu_R[ra], cpu_R[rb]); | |
1028 | break; | |
1029 | ||
bbe418f2 JL |
1030 | default: |
1031 | gen_illegal_exception(dc); | |
1032 | break; | |
1033 | } | |
1034 | } | |
1035 | ||
1036 | static void dec_logic(DisasContext *dc, uint32_t insn) | |
1037 | { | |
1038 | uint32_t op0; | |
6da544a6 | 1039 | uint32_t rd, ra, L6, S6; |
bbe418f2 JL |
1040 | op0 = extract32(insn, 6, 2); |
1041 | rd = extract32(insn, 21, 5); | |
1042 | ra = extract32(insn, 16, 5); | |
1043 | L6 = extract32(insn, 0, 6); | |
6da544a6 | 1044 | S6 = L6 & (TARGET_LONG_BITS - 1); |
bbe418f2 | 1045 | |
6597c28d | 1046 | check_r0_write(rd); |
bbe418f2 JL |
1047 | switch (op0) { |
1048 | case 0x00: /* l.slli */ | |
1049 | LOG_DIS("l.slli r%d, r%d, %d\n", rd, ra, L6); | |
6da544a6 | 1050 | tcg_gen_shli_tl(cpu_R[rd], cpu_R[ra], S6); |
bbe418f2 JL |
1051 | break; |
1052 | ||
1053 | case 0x01: /* l.srli */ | |
1054 | LOG_DIS("l.srli r%d, r%d, %d\n", rd, ra, L6); | |
6da544a6 | 1055 | tcg_gen_shri_tl(cpu_R[rd], cpu_R[ra], S6); |
bbe418f2 JL |
1056 | break; |
1057 | ||
1058 | case 0x02: /* l.srai */ | |
1059 | LOG_DIS("l.srai r%d, r%d, %d\n", rd, ra, L6); | |
6da544a6 RH |
1060 | tcg_gen_sari_tl(cpu_R[rd], cpu_R[ra], S6); |
1061 | break; | |
bbe418f2 JL |
1062 | |
1063 | case 0x03: /* l.rori */ | |
1064 | LOG_DIS("l.rori r%d, r%d, %d\n", rd, ra, L6); | |
6da544a6 | 1065 | tcg_gen_rotri_tl(cpu_R[rd], cpu_R[ra], S6); |
bbe418f2 JL |
1066 | break; |
1067 | ||
1068 | default: | |
1069 | gen_illegal_exception(dc); | |
1070 | break; | |
1071 | } | |
1072 | } | |
1073 | ||
1074 | static void dec_M(DisasContext *dc, uint32_t insn) | |
1075 | { | |
1076 | uint32_t op0; | |
1077 | uint32_t rd; | |
1078 | uint32_t K16; | |
1079 | op0 = extract32(insn, 16, 1); | |
1080 | rd = extract32(insn, 21, 5); | |
1081 | K16 = extract32(insn, 0, 16); | |
1082 | ||
6597c28d | 1083 | check_r0_write(rd); |
bbe418f2 JL |
1084 | switch (op0) { |
1085 | case 0x0: /* l.movhi */ | |
1086 | LOG_DIS("l.movhi r%d, %d\n", rd, K16); | |
1087 | tcg_gen_movi_tl(cpu_R[rd], (K16 << 16)); | |
1088 | break; | |
1089 | ||
1090 | case 0x1: /* l.macrc */ | |
1091 | LOG_DIS("l.macrc r%d\n", rd); | |
6f7332ba RH |
1092 | tcg_gen_trunc_i64_tl(cpu_R[rd], cpu_mac); |
1093 | tcg_gen_movi_i64(cpu_mac, 0); | |
bbe418f2 JL |
1094 | break; |
1095 | ||
1096 | default: | |
1097 | gen_illegal_exception(dc); | |
1098 | break; | |
1099 | } | |
1100 | } | |
1101 | ||
1102 | static void dec_comp(DisasContext *dc, uint32_t insn) | |
1103 | { | |
1104 | uint32_t op0; | |
1105 | uint32_t ra, rb; | |
1106 | ||
1107 | op0 = extract32(insn, 21, 5); | |
1108 | ra = extract32(insn, 16, 5); | |
1109 | rb = extract32(insn, 11, 5); | |
1110 | ||
bbe418f2 JL |
1111 | /* unsigned integers */ |
1112 | tcg_gen_ext32u_tl(cpu_R[ra], cpu_R[ra]); | |
1113 | tcg_gen_ext32u_tl(cpu_R[rb], cpu_R[rb]); | |
1114 | ||
1115 | switch (op0) { | |
1116 | case 0x0: /* l.sfeq */ | |
1117 | LOG_DIS("l.sfeq r%d, r%d\n", ra, rb); | |
84775c43 | 1118 | tcg_gen_setcond_tl(TCG_COND_EQ, cpu_sr_f, cpu_R[ra], cpu_R[rb]); |
bbe418f2 JL |
1119 | break; |
1120 | ||
1121 | case 0x1: /* l.sfne */ | |
1122 | LOG_DIS("l.sfne r%d, r%d\n", ra, rb); | |
84775c43 | 1123 | tcg_gen_setcond_tl(TCG_COND_NE, cpu_sr_f, cpu_R[ra], cpu_R[rb]); |
bbe418f2 JL |
1124 | break; |
1125 | ||
1126 | case 0x2: /* l.sfgtu */ | |
1127 | LOG_DIS("l.sfgtu r%d, r%d\n", ra, rb); | |
84775c43 | 1128 | tcg_gen_setcond_tl(TCG_COND_GTU, cpu_sr_f, cpu_R[ra], cpu_R[rb]); |
bbe418f2 JL |
1129 | break; |
1130 | ||
1131 | case 0x3: /* l.sfgeu */ | |
1132 | LOG_DIS("l.sfgeu r%d, r%d\n", ra, rb); | |
84775c43 | 1133 | tcg_gen_setcond_tl(TCG_COND_GEU, cpu_sr_f, cpu_R[ra], cpu_R[rb]); |
bbe418f2 JL |
1134 | break; |
1135 | ||
1136 | case 0x4: /* l.sfltu */ | |
1137 | LOG_DIS("l.sfltu r%d, r%d\n", ra, rb); | |
84775c43 | 1138 | tcg_gen_setcond_tl(TCG_COND_LTU, cpu_sr_f, cpu_R[ra], cpu_R[rb]); |
bbe418f2 JL |
1139 | break; |
1140 | ||
1141 | case 0x5: /* l.sfleu */ | |
1142 | LOG_DIS("l.sfleu r%d, r%d\n", ra, rb); | |
84775c43 | 1143 | tcg_gen_setcond_tl(TCG_COND_LEU, cpu_sr_f, cpu_R[ra], cpu_R[rb]); |
bbe418f2 JL |
1144 | break; |
1145 | ||
1146 | case 0xa: /* l.sfgts */ | |
1147 | LOG_DIS("l.sfgts r%d, r%d\n", ra, rb); | |
84775c43 | 1148 | tcg_gen_setcond_tl(TCG_COND_GT, cpu_sr_f, cpu_R[ra], cpu_R[rb]); |
bbe418f2 JL |
1149 | break; |
1150 | ||
1151 | case 0xb: /* l.sfges */ | |
1152 | LOG_DIS("l.sfges r%d, r%d\n", ra, rb); | |
84775c43 | 1153 | tcg_gen_setcond_tl(TCG_COND_GE, cpu_sr_f, cpu_R[ra], cpu_R[rb]); |
bbe418f2 JL |
1154 | break; |
1155 | ||
1156 | case 0xc: /* l.sflts */ | |
1157 | LOG_DIS("l.sflts r%d, r%d\n", ra, rb); | |
84775c43 | 1158 | tcg_gen_setcond_tl(TCG_COND_LT, cpu_sr_f, cpu_R[ra], cpu_R[rb]); |
bbe418f2 JL |
1159 | break; |
1160 | ||
1161 | case 0xd: /* l.sfles */ | |
1162 | LOG_DIS("l.sfles r%d, r%d\n", ra, rb); | |
84775c43 | 1163 | tcg_gen_setcond_tl(TCG_COND_LE, cpu_sr_f, cpu_R[ra], cpu_R[rb]); |
bbe418f2 JL |
1164 | break; |
1165 | ||
1166 | default: | |
1167 | gen_illegal_exception(dc); | |
1168 | break; | |
1169 | } | |
bbe418f2 JL |
1170 | } |
1171 | ||
1172 | static void dec_compi(DisasContext *dc, uint32_t insn) | |
1173 | { | |
6da544a6 RH |
1174 | uint32_t op0, ra; |
1175 | int32_t I16; | |
bbe418f2 JL |
1176 | |
1177 | op0 = extract32(insn, 21, 5); | |
1178 | ra = extract32(insn, 16, 5); | |
6da544a6 | 1179 | I16 = sextract32(insn, 0, 16); |
bbe418f2 | 1180 | |
bbe418f2 JL |
1181 | switch (op0) { |
1182 | case 0x0: /* l.sfeqi */ | |
1183 | LOG_DIS("l.sfeqi r%d, %d\n", ra, I16); | |
84775c43 | 1184 | tcg_gen_setcondi_tl(TCG_COND_EQ, cpu_sr_f, cpu_R[ra], I16); |
bbe418f2 JL |
1185 | break; |
1186 | ||
1187 | case 0x1: /* l.sfnei */ | |
1188 | LOG_DIS("l.sfnei r%d, %d\n", ra, I16); | |
84775c43 | 1189 | tcg_gen_setcondi_tl(TCG_COND_NE, cpu_sr_f, cpu_R[ra], I16); |
bbe418f2 JL |
1190 | break; |
1191 | ||
1192 | case 0x2: /* l.sfgtui */ | |
1193 | LOG_DIS("l.sfgtui r%d, %d\n", ra, I16); | |
84775c43 | 1194 | tcg_gen_setcondi_tl(TCG_COND_GTU, cpu_sr_f, cpu_R[ra], I16); |
bbe418f2 JL |
1195 | break; |
1196 | ||
1197 | case 0x3: /* l.sfgeui */ | |
1198 | LOG_DIS("l.sfgeui r%d, %d\n", ra, I16); | |
84775c43 | 1199 | tcg_gen_setcondi_tl(TCG_COND_GEU, cpu_sr_f, cpu_R[ra], I16); |
bbe418f2 JL |
1200 | break; |
1201 | ||
1202 | case 0x4: /* l.sfltui */ | |
1203 | LOG_DIS("l.sfltui r%d, %d\n", ra, I16); | |
84775c43 | 1204 | tcg_gen_setcondi_tl(TCG_COND_LTU, cpu_sr_f, cpu_R[ra], I16); |
bbe418f2 JL |
1205 | break; |
1206 | ||
1207 | case 0x5: /* l.sfleui */ | |
1208 | LOG_DIS("l.sfleui r%d, %d\n", ra, I16); | |
84775c43 | 1209 | tcg_gen_setcondi_tl(TCG_COND_LEU, cpu_sr_f, cpu_R[ra], I16); |
bbe418f2 JL |
1210 | break; |
1211 | ||
1212 | case 0xa: /* l.sfgtsi */ | |
1213 | LOG_DIS("l.sfgtsi r%d, %d\n", ra, I16); | |
84775c43 | 1214 | tcg_gen_setcondi_tl(TCG_COND_GT, cpu_sr_f, cpu_R[ra], I16); |
bbe418f2 JL |
1215 | break; |
1216 | ||
1217 | case 0xb: /* l.sfgesi */ | |
1218 | LOG_DIS("l.sfgesi r%d, %d\n", ra, I16); | |
84775c43 | 1219 | tcg_gen_setcondi_tl(TCG_COND_GE, cpu_sr_f, cpu_R[ra], I16); |
bbe418f2 JL |
1220 | break; |
1221 | ||
1222 | case 0xc: /* l.sfltsi */ | |
1223 | LOG_DIS("l.sfltsi r%d, %d\n", ra, I16); | |
84775c43 | 1224 | tcg_gen_setcondi_tl(TCG_COND_LT, cpu_sr_f, cpu_R[ra], I16); |
bbe418f2 JL |
1225 | break; |
1226 | ||
1227 | case 0xd: /* l.sflesi */ | |
1228 | LOG_DIS("l.sflesi r%d, %d\n", ra, I16); | |
84775c43 | 1229 | tcg_gen_setcondi_tl(TCG_COND_LE, cpu_sr_f, cpu_R[ra], I16); |
bbe418f2 JL |
1230 | break; |
1231 | ||
1232 | default: | |
1233 | gen_illegal_exception(dc); | |
1234 | break; | |
1235 | } | |
bbe418f2 JL |
1236 | } |
1237 | ||
7de9729f | 1238 | static bool trans_l_sys(DisasContext *dc, arg_l_sys *a, uint32_t insn) |
bbe418f2 | 1239 | { |
7de9729f RH |
1240 | LOG_DIS("l.sys %d\n", a->k); |
1241 | tcg_gen_movi_tl(cpu_pc, dc->base.pc_next); | |
1242 | gen_exception(dc, EXCP_SYSCALL); | |
1243 | dc->base.is_jmp = DISAS_NORETURN; | |
1244 | return true; | |
1245 | } | |
bbe418f2 | 1246 | |
7de9729f RH |
1247 | static bool trans_l_trap(DisasContext *dc, arg_l_trap *a, uint32_t insn) |
1248 | { | |
1249 | LOG_DIS("l.trap %d\n", a->k); | |
1250 | tcg_gen_movi_tl(cpu_pc, dc->base.pc_next); | |
1251 | gen_exception(dc, EXCP_TRAP); | |
1252 | dc->base.is_jmp = DISAS_NORETURN; | |
1253 | return true; | |
1254 | } | |
bbe418f2 | 1255 | |
7de9729f RH |
1256 | static bool trans_l_msync(DisasContext *dc, arg_l_msync *a, uint32_t insn) |
1257 | { | |
1258 | LOG_DIS("l.msync\n"); | |
1259 | tcg_gen_mb(TCG_MO_ALL); | |
1260 | return true; | |
1261 | } | |
bbe418f2 | 1262 | |
7de9729f RH |
1263 | static bool trans_l_psync(DisasContext *dc, arg_l_psync *a, uint32_t insn) |
1264 | { | |
1265 | LOG_DIS("l.psync\n"); | |
1266 | return true; | |
1267 | } | |
bbe418f2 | 1268 | |
7de9729f RH |
1269 | static bool trans_l_csync(DisasContext *dc, arg_l_csync *a, uint32_t insn) |
1270 | { | |
1271 | LOG_DIS("l.csync\n"); | |
1272 | return true; | |
bbe418f2 JL |
1273 | } |
1274 | ||
1275 | static void dec_float(DisasContext *dc, uint32_t insn) | |
1276 | { | |
1277 | uint32_t op0; | |
1278 | uint32_t ra, rb, rd; | |
1279 | op0 = extract32(insn, 0, 8); | |
1280 | ra = extract32(insn, 16, 5); | |
1281 | rb = extract32(insn, 11, 5); | |
1282 | rd = extract32(insn, 21, 5); | |
1283 | ||
1284 | switch (op0) { | |
4e2d3007 | 1285 | case 0x00: /* lf.add.s */ |
bbe418f2 | 1286 | LOG_DIS("lf.add.s r%d, r%d, r%d\n", rd, ra, rb); |
6597c28d | 1287 | check_r0_write(rd); |
bbe418f2 | 1288 | gen_helper_float_add_s(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); |
4e2d3007 | 1289 | gen_helper_update_fpcsr(cpu_env); |
bbe418f2 JL |
1290 | break; |
1291 | ||
4e2d3007 | 1292 | case 0x01: /* lf.sub.s */ |
bbe418f2 | 1293 | LOG_DIS("lf.sub.s r%d, r%d, r%d\n", rd, ra, rb); |
6597c28d | 1294 | check_r0_write(rd); |
bbe418f2 | 1295 | gen_helper_float_sub_s(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); |
4e2d3007 | 1296 | gen_helper_update_fpcsr(cpu_env); |
bbe418f2 JL |
1297 | break; |
1298 | ||
bbe418f2 JL |
1299 | case 0x02: /* lf.mul.s */ |
1300 | LOG_DIS("lf.mul.s r%d, r%d, r%d\n", rd, ra, rb); | |
6597c28d RH |
1301 | check_r0_write(rd); |
1302 | gen_helper_float_mul_s(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); | |
4e2d3007 | 1303 | gen_helper_update_fpcsr(cpu_env); |
bbe418f2 JL |
1304 | break; |
1305 | ||
4e2d3007 | 1306 | case 0x03: /* lf.div.s */ |
bbe418f2 | 1307 | LOG_DIS("lf.div.s r%d, r%d, r%d\n", rd, ra, rb); |
6597c28d | 1308 | check_r0_write(rd); |
bbe418f2 | 1309 | gen_helper_float_div_s(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); |
4e2d3007 | 1310 | gen_helper_update_fpcsr(cpu_env); |
bbe418f2 JL |
1311 | break; |
1312 | ||
4e2d3007 | 1313 | case 0x04: /* lf.itof.s */ |
bbe418f2 | 1314 | LOG_DIS("lf.itof r%d, r%d\n", rd, ra); |
6597c28d | 1315 | check_r0_write(rd); |
bbe418f2 | 1316 | gen_helper_itofs(cpu_R[rd], cpu_env, cpu_R[ra]); |
4e2d3007 | 1317 | gen_helper_update_fpcsr(cpu_env); |
bbe418f2 JL |
1318 | break; |
1319 | ||
4e2d3007 | 1320 | case 0x05: /* lf.ftoi.s */ |
bbe418f2 | 1321 | LOG_DIS("lf.ftoi r%d, r%d\n", rd, ra); |
6597c28d | 1322 | check_r0_write(rd); |
bbe418f2 | 1323 | gen_helper_ftois(cpu_R[rd], cpu_env, cpu_R[ra]); |
4e2d3007 | 1324 | gen_helper_update_fpcsr(cpu_env); |
bbe418f2 JL |
1325 | break; |
1326 | ||
4e2d3007 | 1327 | case 0x06: /* lf.rem.s */ |
bbe418f2 | 1328 | LOG_DIS("lf.rem.s r%d, r%d, r%d\n", rd, ra, rb); |
6597c28d | 1329 | check_r0_write(rd); |
bbe418f2 | 1330 | gen_helper_float_rem_s(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); |
4e2d3007 | 1331 | gen_helper_update_fpcsr(cpu_env); |
bbe418f2 JL |
1332 | break; |
1333 | ||
4e2d3007 | 1334 | case 0x07: /* lf.madd.s */ |
bbe418f2 | 1335 | LOG_DIS("lf.madd.s r%d, r%d, r%d\n", rd, ra, rb); |
6597c28d | 1336 | check_r0_write(rd); |
762e22ed RH |
1337 | gen_helper_float_madd_s(cpu_R[rd], cpu_env, cpu_R[rd], |
1338 | cpu_R[ra], cpu_R[rb]); | |
4e2d3007 | 1339 | gen_helper_update_fpcsr(cpu_env); |
bbe418f2 JL |
1340 | break; |
1341 | ||
4e2d3007 | 1342 | case 0x08: /* lf.sfeq.s */ |
bbe418f2 | 1343 | LOG_DIS("lf.sfeq.s r%d, r%d\n", ra, rb); |
84775c43 | 1344 | gen_helper_float_eq_s(cpu_sr_f, cpu_env, cpu_R[ra], cpu_R[rb]); |
4e2d3007 | 1345 | gen_helper_update_fpcsr(cpu_env); |
bbe418f2 JL |
1346 | break; |
1347 | ||
4e2d3007 | 1348 | case 0x09: /* lf.sfne.s */ |
bbe418f2 | 1349 | LOG_DIS("lf.sfne.s r%d, r%d\n", ra, rb); |
4e2d3007 RH |
1350 | gen_helper_float_eq_s(cpu_sr_f, cpu_env, cpu_R[ra], cpu_R[rb]); |
1351 | tcg_gen_xori_tl(cpu_sr_f, cpu_sr_f, 1); | |
1352 | gen_helper_update_fpcsr(cpu_env); | |
bbe418f2 JL |
1353 | break; |
1354 | ||
4e2d3007 | 1355 | case 0x0a: /* lf.sfgt.s */ |
bbe418f2 | 1356 | LOG_DIS("lf.sfgt.s r%d, r%d\n", ra, rb); |
4e2d3007 RH |
1357 | gen_helper_float_lt_s(cpu_sr_f, cpu_env, cpu_R[rb], cpu_R[ra]); |
1358 | gen_helper_update_fpcsr(cpu_env); | |
bbe418f2 JL |
1359 | break; |
1360 | ||
4e2d3007 | 1361 | case 0x0b: /* lf.sfge.s */ |
bbe418f2 | 1362 | LOG_DIS("lf.sfge.s r%d, r%d\n", ra, rb); |
4e2d3007 RH |
1363 | gen_helper_float_le_s(cpu_sr_f, cpu_env, cpu_R[rb], cpu_R[ra]); |
1364 | gen_helper_update_fpcsr(cpu_env); | |
bbe418f2 JL |
1365 | break; |
1366 | ||
4e2d3007 | 1367 | case 0x0c: /* lf.sflt.s */ |
bbe418f2 | 1368 | LOG_DIS("lf.sflt.s r%d, r%d\n", ra, rb); |
84775c43 | 1369 | gen_helper_float_lt_s(cpu_sr_f, cpu_env, cpu_R[ra], cpu_R[rb]); |
4e2d3007 | 1370 | gen_helper_update_fpcsr(cpu_env); |
bbe418f2 JL |
1371 | break; |
1372 | ||
4e2d3007 | 1373 | case 0x0d: /* lf.sfle.s */ |
bbe418f2 | 1374 | LOG_DIS("lf.sfle.s r%d, r%d\n", ra, rb); |
84775c43 | 1375 | gen_helper_float_le_s(cpu_sr_f, cpu_env, cpu_R[ra], cpu_R[rb]); |
4e2d3007 | 1376 | gen_helper_update_fpcsr(cpu_env); |
bbe418f2 JL |
1377 | break; |
1378 | ||
4e2d3007 RH |
1379 | #ifdef TARGET_OPENRISC64 |
1380 | case 0x10: /* lf.add.d */ | |
bbe418f2 JL |
1381 | LOG_DIS("lf.add.d r%d, r%d, r%d\n", rd, ra, rb); |
1382 | check_of64s(dc); | |
6597c28d | 1383 | check_r0_write(rd); |
bbe418f2 | 1384 | gen_helper_float_add_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); |
4e2d3007 | 1385 | gen_helper_update_fpcsr(cpu_env); |
bbe418f2 JL |
1386 | break; |
1387 | ||
4e2d3007 | 1388 | case 0x11: /* lf.sub.d */ |
bbe418f2 JL |
1389 | LOG_DIS("lf.sub.d r%d, r%d, r%d\n", rd, ra, rb); |
1390 | check_of64s(dc); | |
6597c28d | 1391 | check_r0_write(rd); |
bbe418f2 | 1392 | gen_helper_float_sub_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); |
4e2d3007 | 1393 | gen_helper_update_fpcsr(cpu_env); |
bbe418f2 JL |
1394 | break; |
1395 | ||
4e2d3007 | 1396 | case 0x12: /* lf.mul.d */ |
bbe418f2 JL |
1397 | LOG_DIS("lf.mul.d r%d, r%d, r%d\n", rd, ra, rb); |
1398 | check_of64s(dc); | |
6597c28d RH |
1399 | check_r0_write(rd); |
1400 | gen_helper_float_mul_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); | |
4e2d3007 | 1401 | gen_helper_update_fpcsr(cpu_env); |
bbe418f2 JL |
1402 | break; |
1403 | ||
4e2d3007 | 1404 | case 0x13: /* lf.div.d */ |
bbe418f2 JL |
1405 | LOG_DIS("lf.div.d r%d, r%d, r%d\n", rd, ra, rb); |
1406 | check_of64s(dc); | |
6597c28d | 1407 | check_r0_write(rd); |
bbe418f2 | 1408 | gen_helper_float_div_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); |
4e2d3007 | 1409 | gen_helper_update_fpcsr(cpu_env); |
bbe418f2 JL |
1410 | break; |
1411 | ||
4e2d3007 | 1412 | case 0x14: /* lf.itof.d */ |
bbe418f2 JL |
1413 | LOG_DIS("lf.itof r%d, r%d\n", rd, ra); |
1414 | check_of64s(dc); | |
6597c28d | 1415 | check_r0_write(rd); |
bbe418f2 | 1416 | gen_helper_itofd(cpu_R[rd], cpu_env, cpu_R[ra]); |
4e2d3007 | 1417 | gen_helper_update_fpcsr(cpu_env); |
bbe418f2 JL |
1418 | break; |
1419 | ||
4e2d3007 | 1420 | case 0x15: /* lf.ftoi.d */ |
bbe418f2 JL |
1421 | LOG_DIS("lf.ftoi r%d, r%d\n", rd, ra); |
1422 | check_of64s(dc); | |
6597c28d | 1423 | check_r0_write(rd); |
bbe418f2 | 1424 | gen_helper_ftoid(cpu_R[rd], cpu_env, cpu_R[ra]); |
4e2d3007 | 1425 | gen_helper_update_fpcsr(cpu_env); |
bbe418f2 JL |
1426 | break; |
1427 | ||
4e2d3007 | 1428 | case 0x16: /* lf.rem.d */ |
bbe418f2 JL |
1429 | LOG_DIS("lf.rem.d r%d, r%d, r%d\n", rd, ra, rb); |
1430 | check_of64s(dc); | |
6597c28d | 1431 | check_r0_write(rd); |
bbe418f2 | 1432 | gen_helper_float_rem_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); |
4e2d3007 | 1433 | gen_helper_update_fpcsr(cpu_env); |
bbe418f2 JL |
1434 | break; |
1435 | ||
4e2d3007 | 1436 | case 0x17: /* lf.madd.d */ |
bbe418f2 JL |
1437 | LOG_DIS("lf.madd.d r%d, r%d, r%d\n", rd, ra, rb); |
1438 | check_of64s(dc); | |
6597c28d | 1439 | check_r0_write(rd); |
762e22ed RH |
1440 | gen_helper_float_madd_d(cpu_R[rd], cpu_env, cpu_R[rd], |
1441 | cpu_R[ra], cpu_R[rb]); | |
4e2d3007 | 1442 | gen_helper_update_fpcsr(cpu_env); |
bbe418f2 JL |
1443 | break; |
1444 | ||
4e2d3007 | 1445 | case 0x18: /* lf.sfeq.d */ |
bbe418f2 JL |
1446 | LOG_DIS("lf.sfeq.d r%d, r%d\n", ra, rb); |
1447 | check_of64s(dc); | |
84775c43 | 1448 | gen_helper_float_eq_d(cpu_sr_f, cpu_env, cpu_R[ra], cpu_R[rb]); |
4e2d3007 | 1449 | gen_helper_update_fpcsr(cpu_env); |
bbe418f2 JL |
1450 | break; |
1451 | ||
4e2d3007 | 1452 | case 0x1a: /* lf.sfgt.d */ |
bbe418f2 JL |
1453 | LOG_DIS("lf.sfgt.d r%d, r%d\n", ra, rb); |
1454 | check_of64s(dc); | |
4e2d3007 RH |
1455 | gen_helper_float_lt_d(cpu_sr_f, cpu_env, cpu_R[rb], cpu_R[ra]); |
1456 | gen_helper_update_fpcsr(cpu_env); | |
bbe418f2 JL |
1457 | break; |
1458 | ||
4e2d3007 | 1459 | case 0x1b: /* lf.sfge.d */ |
bbe418f2 JL |
1460 | LOG_DIS("lf.sfge.d r%d, r%d\n", ra, rb); |
1461 | check_of64s(dc); | |
4e2d3007 RH |
1462 | gen_helper_float_le_d(cpu_sr_f, cpu_env, cpu_R[rb], cpu_R[ra]); |
1463 | gen_helper_update_fpcsr(cpu_env); | |
bbe418f2 JL |
1464 | break; |
1465 | ||
4e2d3007 | 1466 | case 0x19: /* lf.sfne.d */ |
bbe418f2 JL |
1467 | LOG_DIS("lf.sfne.d r%d, r%d\n", ra, rb); |
1468 | check_of64s(dc); | |
4e2d3007 RH |
1469 | gen_helper_float_eq_d(cpu_sr_f, cpu_env, cpu_R[ra], cpu_R[rb]); |
1470 | tcg_gen_xori_tl(cpu_sr_f, cpu_sr_f, 1); | |
1471 | gen_helper_update_fpcsr(cpu_env); | |
bbe418f2 JL |
1472 | break; |
1473 | ||
4e2d3007 | 1474 | case 0x1c: /* lf.sflt.d */ |
bbe418f2 JL |
1475 | LOG_DIS("lf.sflt.d r%d, r%d\n", ra, rb); |
1476 | check_of64s(dc); | |
84775c43 | 1477 | gen_helper_float_lt_d(cpu_sr_f, cpu_env, cpu_R[ra], cpu_R[rb]); |
4e2d3007 | 1478 | gen_helper_update_fpcsr(cpu_env); |
bbe418f2 JL |
1479 | break; |
1480 | ||
4e2d3007 | 1481 | case 0x1d: /* lf.sfle.d */ |
bbe418f2 JL |
1482 | LOG_DIS("lf.sfle.d r%d, r%d\n", ra, rb); |
1483 | check_of64s(dc); | |
84775c43 | 1484 | gen_helper_float_le_d(cpu_sr_f, cpu_env, cpu_R[ra], cpu_R[rb]); |
4e2d3007 | 1485 | gen_helper_update_fpcsr(cpu_env); |
bbe418f2 | 1486 | break; |
4e2d3007 | 1487 | #endif |
bbe418f2 JL |
1488 | |
1489 | default: | |
1490 | gen_illegal_exception(dc); | |
1491 | break; | |
1492 | } | |
bbe418f2 JL |
1493 | } |
1494 | ||
1495 | static void disas_openrisc_insn(DisasContext *dc, OpenRISCCPU *cpu) | |
1496 | { | |
1497 | uint32_t op0; | |
7de9729f | 1498 | uint32_t insn = cpu_ldl_code(&cpu->env, dc->base.pc_next); |
bbe418f2 | 1499 | |
7de9729f RH |
1500 | /* Transition to the auto-generated decoder. */ |
1501 | if (decode(dc, insn)) { | |
1502 | return; | |
1503 | } | |
1504 | ||
1505 | op0 = extract32(insn, 26, 6); | |
bbe418f2 JL |
1506 | switch (op0) { |
1507 | case 0x06: | |
1508 | dec_M(dc, insn); | |
1509 | break; | |
1510 | ||
bbe418f2 JL |
1511 | case 0x2e: |
1512 | dec_logic(dc, insn); | |
1513 | break; | |
1514 | ||
1515 | case 0x2f: | |
1516 | dec_compi(dc, insn); | |
1517 | break; | |
1518 | ||
1519 | case 0x31: | |
1520 | dec_mac(dc, insn); | |
1521 | break; | |
1522 | ||
1523 | case 0x32: | |
1524 | dec_float(dc, insn); | |
1525 | break; | |
1526 | ||
1527 | case 0x38: | |
1528 | dec_calc(dc, insn); | |
1529 | break; | |
1530 | ||
1531 | case 0x39: | |
1532 | dec_comp(dc, insn); | |
1533 | break; | |
1534 | ||
1535 | default: | |
1536 | dec_misc(dc, insn); | |
1537 | break; | |
1538 | } | |
1539 | } | |
1540 | ||
a4fd3ec3 | 1541 | static void openrisc_tr_init_disas_context(DisasContextBase *dcb, CPUState *cs) |
e67db06e | 1542 | { |
a4fd3ec3 | 1543 | DisasContext *dc = container_of(dcb, DisasContext, base); |
9c489ea6 | 1544 | CPUOpenRISCState *env = cs->env_ptr; |
a4fd3ec3 | 1545 | int bound; |
1ffa4bce | 1546 | |
a4fd3ec3 | 1547 | dc->mem_idx = cpu_mmu_index(env, false); |
1ffa4bce | 1548 | dc->tb_flags = dc->base.tb->flags; |
a01deb36 | 1549 | dc->delayed_branch = (dc->tb_flags & TB_FLAGS_DFLAG) != 0; |
a4fd3ec3 EC |
1550 | bound = -(dc->base.pc_first | TARGET_PAGE_MASK) / 4; |
1551 | dc->base.max_insns = MIN(dc->base.max_insns, bound); | |
1552 | } | |
bbe418f2 | 1553 | |
a4fd3ec3 EC |
1554 | static void openrisc_tr_tb_start(DisasContextBase *db, CPUState *cs) |
1555 | { | |
1556 | DisasContext *dc = container_of(db, DisasContext, base); | |
bbe418f2 | 1557 | |
6597c28d RH |
1558 | /* Allow the TCG optimizer to see that R0 == 0, |
1559 | when it's true, which is the common case. */ | |
1560 | if (dc->tb_flags & TB_FLAGS_R0_0) { | |
1561 | cpu_R[0] = tcg_const_tl(0); | |
1562 | } else { | |
1563 | cpu_R[0] = cpu_R0; | |
1564 | } | |
a4fd3ec3 | 1565 | } |
6597c28d | 1566 | |
a4fd3ec3 EC |
1567 | static void openrisc_tr_insn_start(DisasContextBase *dcbase, CPUState *cs) |
1568 | { | |
1569 | DisasContext *dc = container_of(dcbase, DisasContext, base); | |
bbe418f2 | 1570 | |
a4fd3ec3 EC |
1571 | tcg_gen_insn_start(dc->base.pc_next, (dc->delayed_branch ? 1 : 0) |
1572 | | (dc->base.num_insns > 1 ? 2 : 0)); | |
1573 | } | |
b933066a | 1574 | |
a4fd3ec3 EC |
1575 | static bool openrisc_tr_breakpoint_check(DisasContextBase *dcbase, CPUState *cs, |
1576 | const CPUBreakpoint *bp) | |
1577 | { | |
1578 | DisasContext *dc = container_of(dcbase, DisasContext, base); | |
1579 | ||
1580 | tcg_gen_movi_tl(cpu_pc, dc->base.pc_next); | |
1581 | gen_exception(dc, EXCP_DEBUG); | |
1582 | dc->base.is_jmp = DISAS_NORETURN; | |
1583 | /* The address covered by the breakpoint must be included in | |
1584 | [tb->pc, tb->pc + tb->size) in order to for it to be | |
1585 | properly cleared -- thus we increment the PC here so that | |
1586 | the logic setting tb->size below does the right thing. */ | |
1587 | dc->base.pc_next += 4; | |
1588 | return true; | |
1589 | } | |
1590 | ||
1591 | static void openrisc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) | |
1592 | { | |
1593 | DisasContext *dc = container_of(dcbase, DisasContext, base); | |
1594 | OpenRISCCPU *cpu = OPENRISC_CPU(cs); | |
1595 | ||
1596 | disas_openrisc_insn(dc, cpu); | |
1597 | dc->base.pc_next += 4; | |
1598 | ||
1599 | /* delay slot */ | |
1600 | if (dc->delayed_branch) { | |
1601 | dc->delayed_branch--; | |
1602 | if (!dc->delayed_branch) { | |
1603 | tcg_gen_mov_tl(cpu_pc, jmp_pc); | |
1604 | tcg_gen_discard_tl(jmp_pc); | |
1605 | dc->base.is_jmp = DISAS_UPDATE; | |
1606 | return; | |
bbe418f2 | 1607 | } |
bbe418f2 | 1608 | } |
a4fd3ec3 EC |
1609 | } |
1610 | ||
1611 | static void openrisc_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs) | |
1612 | { | |
1613 | DisasContext *dc = container_of(dcbase, DisasContext, base); | |
24c32852 | 1614 | |
a01deb36 RH |
1615 | if ((dc->tb_flags & TB_FLAGS_DFLAG ? 1 : 0) != (dc->delayed_branch != 0)) { |
1616 | tcg_gen_movi_i32(cpu_dflag, dc->delayed_branch != 0); | |
1617 | } | |
1618 | ||
1ffa4bce EC |
1619 | tcg_gen_movi_tl(cpu_ppc, dc->base.pc_next - 4); |
1620 | if (dc->base.is_jmp == DISAS_NEXT) { | |
1621 | dc->base.is_jmp = DISAS_UPDATE; | |
1622 | tcg_gen_movi_tl(cpu_pc, dc->base.pc_next); | |
bbe418f2 | 1623 | } |
1ffa4bce | 1624 | if (unlikely(dc->base.singlestep_enabled)) { |
bbe418f2 JL |
1625 | gen_exception(dc, EXCP_DEBUG); |
1626 | } else { | |
1ffa4bce | 1627 | switch (dc->base.is_jmp) { |
a4fd3ec3 | 1628 | case DISAS_TOO_MANY: |
1ffa4bce | 1629 | gen_goto_tb(dc, 0, dc->base.pc_next); |
bbe418f2 | 1630 | break; |
1ffa4bce | 1631 | case DISAS_NORETURN: |
bbe418f2 | 1632 | case DISAS_JUMP: |
1ffa4bce | 1633 | case DISAS_TB_JUMP: |
bbe418f2 JL |
1634 | break; |
1635 | case DISAS_UPDATE: | |
1636 | /* indicate that the hash table must be used | |
1637 | to find the next TB */ | |
1638 | tcg_gen_exit_tb(0); | |
1639 | break; | |
a4fd3ec3 EC |
1640 | default: |
1641 | g_assert_not_reached(); | |
bbe418f2 JL |
1642 | } |
1643 | } | |
a4fd3ec3 | 1644 | } |
bbe418f2 | 1645 | |
a4fd3ec3 EC |
1646 | static void openrisc_tr_disas_log(const DisasContextBase *dcbase, CPUState *cs) |
1647 | { | |
1648 | DisasContext *s = container_of(dcbase, DisasContext, base); | |
0a7df5da | 1649 | |
a4fd3ec3 EC |
1650 | qemu_log("IN: %s\n", lookup_symbol(s->base.pc_first)); |
1651 | log_target_disas(cs, s->base.pc_first, s->base.tb->size); | |
1652 | } | |
bbe418f2 | 1653 | |
a4fd3ec3 EC |
1654 | static const TranslatorOps openrisc_tr_ops = { |
1655 | .init_disas_context = openrisc_tr_init_disas_context, | |
1656 | .tb_start = openrisc_tr_tb_start, | |
1657 | .insn_start = openrisc_tr_insn_start, | |
1658 | .breakpoint_check = openrisc_tr_breakpoint_check, | |
1659 | .translate_insn = openrisc_tr_translate_insn, | |
1660 | .tb_stop = openrisc_tr_tb_stop, | |
1661 | .disas_log = openrisc_tr_disas_log, | |
1662 | }; | |
1663 | ||
1664 | void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb) | |
1665 | { | |
1666 | DisasContext ctx; | |
1667 | ||
1668 | translator_loop(&openrisc_tr_ops, &ctx.base, cs, tb); | |
e67db06e JL |
1669 | } |
1670 | ||
878096ee AF |
1671 | void openrisc_cpu_dump_state(CPUState *cs, FILE *f, |
1672 | fprintf_function cpu_fprintf, | |
1673 | int flags) | |
e67db06e | 1674 | { |
878096ee AF |
1675 | OpenRISCCPU *cpu = OPENRISC_CPU(cs); |
1676 | CPUOpenRISCState *env = &cpu->env; | |
e67db06e | 1677 | int i; |
878096ee | 1678 | |
e67db06e JL |
1679 | cpu_fprintf(f, "PC=%08x\n", env->pc); |
1680 | for (i = 0; i < 32; ++i) { | |
d89e71e8 | 1681 | cpu_fprintf(f, "R%02d=%08x%c", i, cpu_get_gpr(env, i), |
e67db06e JL |
1682 | (i % 4) == 3 ? '\n' : ' '); |
1683 | } | |
1684 | } | |
1685 | ||
1686 | void restore_state_to_opc(CPUOpenRISCState *env, TranslationBlock *tb, | |
bad729e2 | 1687 | target_ulong *data) |
e67db06e | 1688 | { |
bad729e2 | 1689 | env->pc = data[0]; |
a01deb36 RH |
1690 | env->dflag = data[1] & 1; |
1691 | if (data[1] & 2) { | |
24c32852 RH |
1692 | env->ppc = env->pc - 4; |
1693 | } | |
e67db06e | 1694 | } |