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