4 * Copyright (c) 2011-2012 Jia Liu <proljc@gmail.com>
5 * Feng Gao <gf91597@gmail.com>
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.
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.
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/>.
22 #include "exec/exec-all.h"
23 #include "disas/disas.h"
25 #include "qemu-common.h"
28 #include "qemu/bitops.h"
29 #include "exec/cpu_ldst.h"
31 #include "exec/helper-proto.h"
32 #include "exec/helper-gen.h"
34 #include "trace-tcg.h"
37 #define OPENRISC_DISAS
40 # define LOG_DIS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
42 # define LOG_DIS(...) do { } while (0)
45 typedef struct DisasContext
{
47 target_ulong pc
, ppc
, npc
;
48 uint32_t tb_flags
, synced_flags
, flags
;
51 int singlestep_enabled
;
52 uint32_t delayed_branch
;
55 static TCGv_ptr cpu_env
;
57 static TCGv cpu_R
[32];
59 static TCGv jmp_pc
; /* l.jr/l.jalr temp pc */
62 static TCGv_i32 env_btaken
; /* bf/bnf , F flag taken */
63 static TCGv_i32 fpcsr
;
64 static TCGv machi
, maclo
;
65 static TCGv fpmaddhi
, fpmaddlo
;
66 static TCGv_i32 env_flags
;
67 #include "exec/gen-icount.h"
69 void openrisc_translate_init(void)
71 static const char * const regnames
[] = {
72 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
73 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
74 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
75 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
79 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
80 cpu_sr
= tcg_global_mem_new(TCG_AREG0
,
81 offsetof(CPUOpenRISCState
, sr
), "sr");
82 env_flags
= tcg_global_mem_new_i32(TCG_AREG0
,
83 offsetof(CPUOpenRISCState
, flags
),
85 cpu_pc
= tcg_global_mem_new(TCG_AREG0
,
86 offsetof(CPUOpenRISCState
, pc
), "pc");
87 cpu_npc
= tcg_global_mem_new(TCG_AREG0
,
88 offsetof(CPUOpenRISCState
, npc
), "npc");
89 cpu_ppc
= tcg_global_mem_new(TCG_AREG0
,
90 offsetof(CPUOpenRISCState
, ppc
), "ppc");
91 jmp_pc
= tcg_global_mem_new(TCG_AREG0
,
92 offsetof(CPUOpenRISCState
, jmp_pc
), "jmp_pc");
93 env_btaken
= tcg_global_mem_new_i32(TCG_AREG0
,
94 offsetof(CPUOpenRISCState
, btaken
),
96 fpcsr
= tcg_global_mem_new_i32(TCG_AREG0
,
97 offsetof(CPUOpenRISCState
, fpcsr
),
99 machi
= tcg_global_mem_new(TCG_AREG0
,
100 offsetof(CPUOpenRISCState
, machi
),
102 maclo
= tcg_global_mem_new(TCG_AREG0
,
103 offsetof(CPUOpenRISCState
, maclo
),
105 fpmaddhi
= tcg_global_mem_new(TCG_AREG0
,
106 offsetof(CPUOpenRISCState
, fpmaddhi
),
108 fpmaddlo
= tcg_global_mem_new(TCG_AREG0
,
109 offsetof(CPUOpenRISCState
, fpmaddlo
),
111 for (i
= 0; i
< 32; i
++) {
112 cpu_R
[i
] = tcg_global_mem_new(TCG_AREG0
,
113 offsetof(CPUOpenRISCState
, gpr
[i
]),
118 /* Writeback SR_F translation space to execution space. */
119 static inline void wb_SR_F(void)
123 label
= gen_new_label();
124 tcg_gen_andi_tl(cpu_sr
, cpu_sr
, ~SR_F
);
125 tcg_gen_brcondi_tl(TCG_COND_EQ
, env_btaken
, 0, label
);
126 tcg_gen_ori_tl(cpu_sr
, cpu_sr
, SR_F
);
127 gen_set_label(label
);
130 static inline int zero_extend(unsigned int val
, int width
)
132 return val
& ((1 << width
) - 1);
135 static inline int sign_extend(unsigned int val
, int width
)
140 val
<<= TARGET_LONG_BITS
- width
;
143 sval
>>= TARGET_LONG_BITS
- width
;
147 static inline void gen_sync_flags(DisasContext
*dc
)
149 /* Sync the tb dependent flag between translate and runtime. */
150 if (dc
->tb_flags
!= dc
->synced_flags
) {
151 tcg_gen_movi_tl(env_flags
, dc
->tb_flags
);
152 dc
->synced_flags
= dc
->tb_flags
;
156 static void gen_exception(DisasContext
*dc
, unsigned int excp
)
158 TCGv_i32 tmp
= tcg_const_i32(excp
);
159 gen_helper_exception(cpu_env
, tmp
);
160 tcg_temp_free_i32(tmp
);
163 static void gen_illegal_exception(DisasContext
*dc
)
165 tcg_gen_movi_tl(cpu_pc
, dc
->pc
);
166 gen_exception(dc
, EXCP_ILLEGAL
);
167 dc
->is_jmp
= DISAS_UPDATE
;
170 /* not used yet, open it when we need or64. */
171 /*#ifdef TARGET_OPENRISC64
172 static void check_ob64s(DisasContext *dc)
174 if (!(dc->flags & CPUCFGR_OB64S)) {
175 gen_illegal_exception(dc);
179 static void check_of64s(DisasContext *dc)
181 if (!(dc->flags & CPUCFGR_OF64S)) {
182 gen_illegal_exception(dc);
186 static void check_ov64s(DisasContext *dc)
188 if (!(dc->flags & CPUCFGR_OV64S)) {
189 gen_illegal_exception(dc);
194 static void gen_goto_tb(DisasContext
*dc
, int n
, target_ulong dest
)
196 TranslationBlock
*tb
;
198 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
) &&
199 likely(!dc
->singlestep_enabled
)) {
200 tcg_gen_movi_tl(cpu_pc
, dest
);
202 tcg_gen_exit_tb((uintptr_t)tb
+ n
);
204 tcg_gen_movi_tl(cpu_pc
, dest
);
205 if (dc
->singlestep_enabled
) {
206 gen_exception(dc
, EXCP_DEBUG
);
212 static void gen_jump(DisasContext
*dc
, uint32_t imm
, uint32_t reg
, uint32_t op0
)
215 /* N26, 26bits imm */
216 tmp_pc
= sign_extend((imm
<<2), 26) + dc
->pc
;
220 tcg_gen_movi_tl(jmp_pc
, tmp_pc
);
222 case 0x01: /* l.jal */
223 tcg_gen_movi_tl(cpu_R
[9], (dc
->pc
+ 8));
224 tcg_gen_movi_tl(jmp_pc
, tmp_pc
);
226 case 0x03: /* l.bnf */
227 case 0x04: /* l.bf */
229 int lab
= gen_new_label();
230 TCGv sr_f
= tcg_temp_new();
231 tcg_gen_movi_tl(jmp_pc
, dc
->pc
+8);
232 tcg_gen_andi_tl(sr_f
, cpu_sr
, SR_F
);
233 tcg_gen_brcondi_i32(op0
== 0x03 ? TCG_COND_EQ
: TCG_COND_NE
,
235 tcg_gen_movi_tl(jmp_pc
, tmp_pc
);
240 case 0x11: /* l.jr */
241 tcg_gen_mov_tl(jmp_pc
, cpu_R
[reg
]);
243 case 0x12: /* l.jalr */
244 tcg_gen_movi_tl(cpu_R
[9], (dc
->pc
+ 8));
245 tcg_gen_mov_tl(jmp_pc
, cpu_R
[reg
]);
248 gen_illegal_exception(dc
);
252 dc
->delayed_branch
= 2;
253 dc
->tb_flags
|= D_FLAG
;
258 static void dec_calc(DisasContext
*dc
, uint32_t insn
)
260 uint32_t op0
, op1
, op2
;
262 op0
= extract32(insn
, 0, 4);
263 op1
= extract32(insn
, 8, 2);
264 op2
= extract32(insn
, 6, 2);
265 ra
= extract32(insn
, 16, 5);
266 rb
= extract32(insn
, 11, 5);
267 rd
= extract32(insn
, 21, 5);
272 case 0x00: /* l.add */
273 LOG_DIS("l.add r%d, r%d, r%d\n", rd
, ra
, rb
);
275 int lab
= gen_new_label();
276 TCGv_i64 ta
= tcg_temp_new_i64();
277 TCGv_i64 tb
= tcg_temp_new_i64();
278 TCGv_i64 td
= tcg_temp_local_new_i64();
279 TCGv_i32 res
= tcg_temp_local_new_i32();
280 TCGv_i32 sr_ove
= tcg_temp_local_new_i32();
281 tcg_gen_extu_i32_i64(ta
, cpu_R
[ra
]);
282 tcg_gen_extu_i32_i64(tb
, cpu_R
[rb
]);
283 tcg_gen_add_i64(td
, ta
, tb
);
284 tcg_gen_trunc_i64_i32(res
, td
);
285 tcg_gen_shri_i64(td
, td
, 31);
286 tcg_gen_andi_i64(td
, td
, 0x3);
287 /* Jump to lab when no overflow. */
288 tcg_gen_brcondi_i64(TCG_COND_EQ
, td
, 0x0, lab
);
289 tcg_gen_brcondi_i64(TCG_COND_EQ
, td
, 0x3, lab
);
290 tcg_gen_ori_i32(cpu_sr
, cpu_sr
, (SR_OV
| SR_CY
));
291 tcg_gen_andi_i32(sr_ove
, cpu_sr
, SR_OVE
);
292 tcg_gen_brcondi_i32(TCG_COND_NE
, sr_ove
, SR_OVE
, lab
);
293 gen_exception(dc
, EXCP_RANGE
);
295 tcg_gen_mov_i32(cpu_R
[rd
], res
);
296 tcg_temp_free_i64(ta
);
297 tcg_temp_free_i64(tb
);
298 tcg_temp_free_i64(td
);
299 tcg_temp_free_i32(res
);
300 tcg_temp_free_i32(sr_ove
);
304 gen_illegal_exception(dc
);
309 case 0x0001: /* l.addc */
312 LOG_DIS("l.addc r%d, r%d, r%d\n", rd
, ra
, rb
);
314 int lab
= gen_new_label();
315 TCGv_i64 ta
= tcg_temp_new_i64();
316 TCGv_i64 tb
= tcg_temp_new_i64();
317 TCGv_i64 tcy
= tcg_temp_local_new_i64();
318 TCGv_i64 td
= tcg_temp_local_new_i64();
319 TCGv_i32 res
= tcg_temp_local_new_i32();
320 TCGv_i32 sr_cy
= tcg_temp_local_new_i32();
321 TCGv_i32 sr_ove
= tcg_temp_local_new_i32();
322 tcg_gen_extu_i32_i64(ta
, cpu_R
[ra
]);
323 tcg_gen_extu_i32_i64(tb
, cpu_R
[rb
]);
324 tcg_gen_andi_i32(sr_cy
, cpu_sr
, SR_CY
);
325 tcg_gen_extu_i32_i64(tcy
, sr_cy
);
326 tcg_gen_shri_i64(tcy
, tcy
, 10);
327 tcg_gen_add_i64(td
, ta
, tb
);
328 tcg_gen_add_i64(td
, td
, tcy
);
329 tcg_gen_trunc_i64_i32(res
, td
);
330 tcg_gen_shri_i64(td
, td
, 32);
331 tcg_gen_andi_i64(td
, td
, 0x3);
332 /* Jump to lab when no overflow. */
333 tcg_gen_brcondi_i64(TCG_COND_EQ
, td
, 0x0, lab
);
334 tcg_gen_brcondi_i64(TCG_COND_EQ
, td
, 0x3, lab
);
335 tcg_gen_ori_i32(cpu_sr
, cpu_sr
, (SR_OV
| SR_CY
));
336 tcg_gen_andi_i32(sr_ove
, cpu_sr
, SR_OVE
);
337 tcg_gen_brcondi_i32(TCG_COND_NE
, sr_ove
, SR_OVE
, lab
);
338 gen_exception(dc
, EXCP_RANGE
);
340 tcg_gen_mov_i32(cpu_R
[rd
], res
);
341 tcg_temp_free_i64(ta
);
342 tcg_temp_free_i64(tb
);
343 tcg_temp_free_i64(tcy
);
344 tcg_temp_free_i64(td
);
345 tcg_temp_free_i32(res
);
346 tcg_temp_free_i32(sr_cy
);
347 tcg_temp_free_i32(sr_ove
);
351 gen_illegal_exception(dc
);
356 case 0x0002: /* l.sub */
359 LOG_DIS("l.sub r%d, r%d, r%d\n", rd
, ra
, rb
);
361 int lab
= gen_new_label();
362 TCGv_i64 ta
= tcg_temp_new_i64();
363 TCGv_i64 tb
= tcg_temp_new_i64();
364 TCGv_i64 td
= tcg_temp_local_new_i64();
365 TCGv_i32 res
= tcg_temp_local_new_i32();
366 TCGv_i32 sr_ove
= tcg_temp_local_new_i32();
368 tcg_gen_extu_i32_i64(ta
, cpu_R
[ra
]);
369 tcg_gen_extu_i32_i64(tb
, cpu_R
[rb
]);
370 tcg_gen_sub_i64(td
, ta
, tb
);
371 tcg_gen_trunc_i64_i32(res
, td
);
372 tcg_gen_shri_i64(td
, td
, 31);
373 tcg_gen_andi_i64(td
, td
, 0x3);
374 /* Jump to lab when no overflow. */
375 tcg_gen_brcondi_i64(TCG_COND_EQ
, td
, 0x0, lab
);
376 tcg_gen_brcondi_i64(TCG_COND_EQ
, td
, 0x3, lab
);
377 tcg_gen_ori_i32(cpu_sr
, cpu_sr
, (SR_OV
| SR_CY
));
378 tcg_gen_andi_i32(sr_ove
, cpu_sr
, SR_OVE
);
379 tcg_gen_brcondi_i32(TCG_COND_NE
, sr_ove
, SR_OVE
, lab
);
380 gen_exception(dc
, EXCP_RANGE
);
382 tcg_gen_mov_i32(cpu_R
[rd
], res
);
383 tcg_temp_free_i64(ta
);
384 tcg_temp_free_i64(tb
);
385 tcg_temp_free_i64(td
);
386 tcg_temp_free_i32(res
);
387 tcg_temp_free_i32(sr_ove
);
391 gen_illegal_exception(dc
);
396 case 0x0003: /* l.and */
399 LOG_DIS("l.and r%d, r%d, r%d\n", rd
, ra
, rb
);
400 tcg_gen_and_tl(cpu_R
[rd
], cpu_R
[ra
], cpu_R
[rb
]);
403 gen_illegal_exception(dc
);
408 case 0x0004: /* l.or */
411 LOG_DIS("l.or r%d, r%d, r%d\n", rd
, ra
, rb
);
412 tcg_gen_or_tl(cpu_R
[rd
], cpu_R
[ra
], cpu_R
[rb
]);
415 gen_illegal_exception(dc
);
422 case 0x00: /* l.xor */
423 LOG_DIS("l.xor r%d, r%d, r%d\n", rd
, ra
, rb
);
424 tcg_gen_xor_tl(cpu_R
[rd
], cpu_R
[ra
], cpu_R
[rb
]);
427 gen_illegal_exception(dc
);
434 case 0x03: /* l.mul */
435 LOG_DIS("l.mul r%d, r%d, r%d\n", rd
, ra
, rb
);
436 if (ra
!= 0 && rb
!= 0) {
437 gen_helper_mul32(cpu_R
[rd
], cpu_env
, cpu_R
[ra
], cpu_R
[rb
]);
439 tcg_gen_movi_tl(cpu_R
[rd
], 0x0);
443 gen_illegal_exception(dc
);
450 case 0x03: /* l.div */
451 LOG_DIS("l.div r%d, r%d, r%d\n", rd
, ra
, rb
);
453 int lab0
= gen_new_label();
454 int lab1
= gen_new_label();
455 int lab2
= gen_new_label();
456 int lab3
= gen_new_label();
457 TCGv_i32 sr_ove
= tcg_temp_local_new_i32();
459 tcg_gen_ori_tl(cpu_sr
, cpu_sr
, (SR_OV
| SR_CY
));
460 tcg_gen_andi_tl(sr_ove
, cpu_sr
, SR_OVE
);
461 tcg_gen_brcondi_tl(TCG_COND_NE
, sr_ove
, SR_OVE
, lab0
);
462 gen_exception(dc
, EXCP_RANGE
);
465 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_R
[rb
],
467 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_R
[ra
],
469 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_R
[rb
],
472 tcg_gen_ori_tl(cpu_sr
, cpu_sr
, (SR_OV
| SR_CY
));
473 tcg_gen_andi_tl(sr_ove
, cpu_sr
, SR_OVE
);
474 tcg_gen_brcondi_tl(TCG_COND_NE
, sr_ove
, SR_OVE
, lab3
);
475 gen_exception(dc
, EXCP_RANGE
);
477 tcg_gen_div_tl(cpu_R
[rd
], cpu_R
[ra
], cpu_R
[rb
]);
480 tcg_temp_free_i32(sr_ove
);
485 gen_illegal_exception(dc
);
492 case 0x03: /* l.divu */
493 LOG_DIS("l.divu r%d, r%d, r%d\n", rd
, ra
, rb
);
495 int lab0
= gen_new_label();
496 int lab1
= gen_new_label();
497 int lab2
= gen_new_label();
498 TCGv_i32 sr_ove
= tcg_temp_local_new_i32();
500 tcg_gen_ori_tl(cpu_sr
, cpu_sr
, (SR_OV
| SR_CY
));
501 tcg_gen_andi_tl(sr_ove
, cpu_sr
, SR_OVE
);
502 tcg_gen_brcondi_tl(TCG_COND_NE
, sr_ove
, SR_OVE
, lab0
);
503 gen_exception(dc
, EXCP_RANGE
);
506 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_R
[rb
],
508 tcg_gen_ori_tl(cpu_sr
, cpu_sr
, (SR_OV
| SR_CY
));
509 tcg_gen_andi_tl(sr_ove
, cpu_sr
, SR_OVE
);
510 tcg_gen_brcondi_tl(TCG_COND_NE
, sr_ove
, SR_OVE
, lab2
);
511 gen_exception(dc
, EXCP_RANGE
);
513 tcg_gen_divu_tl(cpu_R
[rd
], cpu_R
[ra
], cpu_R
[rb
]);
516 tcg_temp_free_i32(sr_ove
);
521 gen_illegal_exception(dc
);
528 case 0x03: /* l.mulu */
529 LOG_DIS("l.mulu r%d, r%d, r%d\n", rd
, ra
, rb
);
530 if (rb
!= 0 && ra
!= 0) {
531 TCGv_i64 result
= tcg_temp_local_new_i64();
532 TCGv_i64 tra
= tcg_temp_local_new_i64();
533 TCGv_i64 trb
= tcg_temp_local_new_i64();
534 TCGv_i64 high
= tcg_temp_new_i64();
535 TCGv_i32 sr_ove
= tcg_temp_local_new_i32();
536 int lab
= gen_new_label();
537 /* Calculate each result. */
538 tcg_gen_extu_i32_i64(tra
, cpu_R
[ra
]);
539 tcg_gen_extu_i32_i64(trb
, cpu_R
[rb
]);
540 tcg_gen_mul_i64(result
, tra
, trb
);
541 tcg_temp_free_i64(tra
);
542 tcg_temp_free_i64(trb
);
543 tcg_gen_shri_i64(high
, result
, TARGET_LONG_BITS
);
544 /* Overflow or not. */
545 tcg_gen_brcondi_i64(TCG_COND_EQ
, high
, 0x00000000, lab
);
546 tcg_gen_ori_tl(cpu_sr
, cpu_sr
, (SR_OV
| SR_CY
));
547 tcg_gen_andi_tl(sr_ove
, cpu_sr
, SR_OVE
);
548 tcg_gen_brcondi_tl(TCG_COND_NE
, sr_ove
, SR_OVE
, lab
);
549 gen_exception(dc
, EXCP_RANGE
);
551 tcg_temp_free_i64(high
);
552 tcg_gen_trunc_i64_tl(cpu_R
[rd
], result
);
553 tcg_temp_free_i64(result
);
554 tcg_temp_free_i32(sr_ove
);
556 tcg_gen_movi_tl(cpu_R
[rd
], 0);
561 gen_illegal_exception(dc
);
568 case 0x00: /* l.cmov */
569 LOG_DIS("l.cmov r%d, r%d, r%d\n", rd
, ra
, rb
);
571 int lab
= gen_new_label();
572 TCGv res
= tcg_temp_local_new();
573 TCGv sr_f
= tcg_temp_new();
574 tcg_gen_andi_tl(sr_f
, cpu_sr
, SR_F
);
575 tcg_gen_mov_tl(res
, cpu_R
[rb
]);
576 tcg_gen_brcondi_tl(TCG_COND_NE
, sr_f
, SR_F
, lab
);
577 tcg_gen_mov_tl(res
, cpu_R
[ra
]);
579 tcg_gen_mov_tl(cpu_R
[rd
], res
);
586 gen_illegal_exception(dc
);
593 case 0x00: /* l.ff1 */
594 LOG_DIS("l.ff1 r%d, r%d, r%d\n", rd
, ra
, rb
);
595 gen_helper_ff1(cpu_R
[rd
], cpu_R
[ra
]);
597 case 0x01: /* l.fl1 */
598 LOG_DIS("l.fl1 r%d, r%d, r%d\n", rd
, ra
, rb
);
599 gen_helper_fl1(cpu_R
[rd
], cpu_R
[ra
]);
603 gen_illegal_exception(dc
);
612 case 0x00: /* l.sll */
613 LOG_DIS("l.sll r%d, r%d, r%d\n", rd
, ra
, rb
);
614 tcg_gen_shl_tl(cpu_R
[rd
], cpu_R
[ra
], cpu_R
[rb
]);
616 case 0x01: /* l.srl */
617 LOG_DIS("l.srl r%d, r%d, r%d\n", rd
, ra
, rb
);
618 tcg_gen_shr_tl(cpu_R
[rd
], cpu_R
[ra
], cpu_R
[rb
]);
620 case 0x02: /* l.sra */
621 LOG_DIS("l.sra r%d, r%d, r%d\n", rd
, ra
, rb
);
622 tcg_gen_sar_tl(cpu_R
[rd
], cpu_R
[ra
], cpu_R
[rb
]);
624 case 0x03: /* l.ror */
625 LOG_DIS("l.ror r%d, r%d, r%d\n", rd
, ra
, rb
);
626 tcg_gen_rotr_tl(cpu_R
[rd
], cpu_R
[ra
], cpu_R
[rb
]);
630 gen_illegal_exception(dc
);
636 gen_illegal_exception(dc
);
645 case 0x00: /* l.exths */
646 LOG_DIS("l.exths r%d, r%d\n", rd
, ra
);
647 tcg_gen_ext16s_tl(cpu_R
[rd
], cpu_R
[ra
]);
649 case 0x01: /* l.extbs */
650 LOG_DIS("l.extbs r%d, r%d\n", rd
, ra
);
651 tcg_gen_ext8s_tl(cpu_R
[rd
], cpu_R
[ra
]);
653 case 0x02: /* l.exthz */
654 LOG_DIS("l.exthz r%d, r%d\n", rd
, ra
);
655 tcg_gen_ext16u_tl(cpu_R
[rd
], cpu_R
[ra
]);
657 case 0x03: /* l.extbz */
658 LOG_DIS("l.extbz r%d, r%d\n", rd
, ra
);
659 tcg_gen_ext8u_tl(cpu_R
[rd
], cpu_R
[ra
]);
663 gen_illegal_exception(dc
);
669 gen_illegal_exception(dc
);
678 case 0x00: /* l.extws */
679 LOG_DIS("l.extws r%d, r%d\n", rd
, ra
);
680 tcg_gen_ext32s_tl(cpu_R
[rd
], cpu_R
[ra
]);
682 case 0x01: /* l.extwz */
683 LOG_DIS("l.extwz r%d, r%d\n", rd
, ra
);
684 tcg_gen_ext32u_tl(cpu_R
[rd
], cpu_R
[ra
]);
688 gen_illegal_exception(dc
);
694 gen_illegal_exception(dc
);
700 gen_illegal_exception(dc
);
705 static void dec_misc(DisasContext
*dc
, uint32_t insn
)
709 #ifdef OPENRISC_DISAS
712 uint32_t I16
, I5
, I11
, N26
, tmp
;
715 op0
= extract32(insn
, 26, 6);
716 op1
= extract32(insn
, 24, 2);
717 ra
= extract32(insn
, 16, 5);
718 rb
= extract32(insn
, 11, 5);
719 rd
= extract32(insn
, 21, 5);
720 #ifdef OPENRISC_DISAS
721 L6
= extract32(insn
, 5, 6);
722 K5
= extract32(insn
, 0, 5);
724 I16
= extract32(insn
, 0, 16);
725 I5
= extract32(insn
, 21, 5);
726 I11
= extract32(insn
, 0, 11);
727 N26
= extract32(insn
, 0, 26);
728 tmp
= (I5
<<11) + I11
;
732 LOG_DIS("l.j %d\n", N26
);
733 gen_jump(dc
, N26
, 0, op0
);
736 case 0x01: /* l.jal */
737 LOG_DIS("l.jal %d\n", N26
);
738 gen_jump(dc
, N26
, 0, op0
);
741 case 0x03: /* l.bnf */
742 LOG_DIS("l.bnf %d\n", N26
);
743 gen_jump(dc
, N26
, 0, op0
);
746 case 0x04: /* l.bf */
747 LOG_DIS("l.bf %d\n", N26
);
748 gen_jump(dc
, N26
, 0, op0
);
753 case 0x01: /* l.nop */
754 LOG_DIS("l.nop %d\n", I16
);
758 gen_illegal_exception(dc
);
763 case 0x11: /* l.jr */
764 LOG_DIS("l.jr r%d\n", rb
);
765 gen_jump(dc
, 0, rb
, op0
);
768 case 0x12: /* l.jalr */
769 LOG_DIS("l.jalr r%d\n", rb
);
770 gen_jump(dc
, 0, rb
, op0
);
773 case 0x13: /* l.maci */
774 LOG_DIS("l.maci %d, r%d, %d\n", I5
, ra
, I11
);
776 TCGv_i64 t1
= tcg_temp_new_i64();
777 TCGv_i64 t2
= tcg_temp_new_i64();
778 TCGv_i32 dst
= tcg_temp_new_i32();
779 TCGv ttmp
= tcg_const_tl(tmp
);
780 tcg_gen_mul_tl(dst
, cpu_R
[ra
], ttmp
);
781 tcg_gen_ext_i32_i64(t1
, dst
);
782 tcg_gen_concat_i32_i64(t2
, maclo
, machi
);
783 tcg_gen_add_i64(t2
, t2
, t1
);
784 tcg_gen_trunc_i64_i32(maclo
, t2
);
785 tcg_gen_shri_i64(t2
, t2
, 32);
786 tcg_gen_trunc_i64_i32(machi
, t2
);
787 tcg_temp_free_i32(dst
);
789 tcg_temp_free_i64(t1
);
790 tcg_temp_free_i64(t2
);
794 case 0x09: /* l.rfe */
797 #if defined(CONFIG_USER_ONLY)
800 if (dc
->mem_idx
== MMU_USER_IDX
) {
801 gen_illegal_exception(dc
);
804 gen_helper_rfe(cpu_env
);
805 dc
->is_jmp
= DISAS_UPDATE
;
810 case 0x1c: /* l.cust1 */
811 LOG_DIS("l.cust1\n");
814 case 0x1d: /* l.cust2 */
815 LOG_DIS("l.cust2\n");
818 case 0x1e: /* l.cust3 */
819 LOG_DIS("l.cust3\n");
822 case 0x1f: /* l.cust4 */
823 LOG_DIS("l.cust4\n");
826 case 0x3c: /* l.cust5 */
827 LOG_DIS("l.cust5 r%d, r%d, r%d, %d, %d\n", rd
, ra
, rb
, L6
, K5
);
830 case 0x3d: /* l.cust6 */
831 LOG_DIS("l.cust6\n");
834 case 0x3e: /* l.cust7 */
835 LOG_DIS("l.cust7\n");
838 case 0x3f: /* l.cust8 */
839 LOG_DIS("l.cust8\n");
842 /* not used yet, open it when we need or64. */
843 /*#ifdef TARGET_OPENRISC64
845 LOG_DIS("l.ld r%d, r%d, %d\n", rd, ra, I16);
851 case 0x21: /* l.lwz */
852 LOG_DIS("l.lwz r%d, r%d, %d\n", rd
, ra
, I16
);
856 case 0x22: /* l.lws */
857 LOG_DIS("l.lws r%d, r%d, %d\n", rd
, ra
, I16
);
861 case 0x23: /* l.lbz */
862 LOG_DIS("l.lbz r%d, r%d, %d\n", rd
, ra
, I16
);
866 case 0x24: /* l.lbs */
867 LOG_DIS("l.lbs r%d, r%d, %d\n", rd
, ra
, I16
);
871 case 0x25: /* l.lhz */
872 LOG_DIS("l.lhz r%d, r%d, %d\n", rd
, ra
, I16
);
876 case 0x26: /* l.lhs */
877 LOG_DIS("l.lhs r%d, r%d, %d\n", rd
, ra
, I16
);
883 TCGv t0
= tcg_temp_new();
884 tcg_gen_addi_tl(t0
, cpu_R
[ra
], sign_extend(I16
, 16));
885 tcg_gen_qemu_ld_tl(cpu_R
[rd
], t0
, dc
->mem_idx
, mop
);
890 case 0x27: /* l.addi */
891 LOG_DIS("l.addi r%d, r%d, %d\n", rd
, ra
, I16
);
894 tcg_gen_mov_tl(cpu_R
[rd
], cpu_R
[ra
]);
896 int lab
= gen_new_label();
897 TCGv_i64 ta
= tcg_temp_new_i64();
898 TCGv_i64 td
= tcg_temp_local_new_i64();
899 TCGv_i32 res
= tcg_temp_local_new_i32();
900 TCGv_i32 sr_ove
= tcg_temp_local_new_i32();
901 tcg_gen_extu_i32_i64(ta
, cpu_R
[ra
]);
902 tcg_gen_addi_i64(td
, ta
, sign_extend(I16
, 16));
903 tcg_gen_trunc_i64_i32(res
, td
);
904 tcg_gen_shri_i64(td
, td
, 32);
905 tcg_gen_andi_i64(td
, td
, 0x3);
906 /* Jump to lab when no overflow. */
907 tcg_gen_brcondi_i64(TCG_COND_EQ
, td
, 0x0, lab
);
908 tcg_gen_brcondi_i64(TCG_COND_EQ
, td
, 0x3, lab
);
909 tcg_gen_ori_i32(cpu_sr
, cpu_sr
, (SR_OV
| SR_CY
));
910 tcg_gen_andi_i32(sr_ove
, cpu_sr
, SR_OVE
);
911 tcg_gen_brcondi_i32(TCG_COND_NE
, sr_ove
, SR_OVE
, lab
);
912 gen_exception(dc
, EXCP_RANGE
);
914 tcg_gen_mov_i32(cpu_R
[rd
], res
);
915 tcg_temp_free_i64(ta
);
916 tcg_temp_free_i64(td
);
917 tcg_temp_free_i32(res
);
918 tcg_temp_free_i32(sr_ove
);
923 case 0x28: /* l.addic */
924 LOG_DIS("l.addic r%d, r%d, %d\n", rd
, ra
, I16
);
926 int lab
= gen_new_label();
927 TCGv_i64 ta
= tcg_temp_new_i64();
928 TCGv_i64 td
= tcg_temp_local_new_i64();
929 TCGv_i64 tcy
= tcg_temp_local_new_i64();
930 TCGv_i32 res
= tcg_temp_local_new_i32();
931 TCGv_i32 sr_cy
= tcg_temp_local_new_i32();
932 TCGv_i32 sr_ove
= tcg_temp_local_new_i32();
933 tcg_gen_extu_i32_i64(ta
, cpu_R
[ra
]);
934 tcg_gen_andi_i32(sr_cy
, cpu_sr
, SR_CY
);
935 tcg_gen_shri_i32(sr_cy
, sr_cy
, 10);
936 tcg_gen_extu_i32_i64(tcy
, sr_cy
);
937 tcg_gen_addi_i64(td
, ta
, sign_extend(I16
, 16));
938 tcg_gen_add_i64(td
, td
, tcy
);
939 tcg_gen_trunc_i64_i32(res
, td
);
940 tcg_gen_shri_i64(td
, td
, 32);
941 tcg_gen_andi_i64(td
, td
, 0x3);
942 /* Jump to lab when no overflow. */
943 tcg_gen_brcondi_i64(TCG_COND_EQ
, td
, 0x0, lab
);
944 tcg_gen_brcondi_i64(TCG_COND_EQ
, td
, 0x3, lab
);
945 tcg_gen_ori_i32(cpu_sr
, cpu_sr
, (SR_OV
| SR_CY
));
946 tcg_gen_andi_i32(sr_ove
, cpu_sr
, SR_OVE
);
947 tcg_gen_brcondi_i32(TCG_COND_NE
, sr_ove
, SR_OVE
, lab
);
948 gen_exception(dc
, EXCP_RANGE
);
950 tcg_gen_mov_i32(cpu_R
[rd
], res
);
951 tcg_temp_free_i64(ta
);
952 tcg_temp_free_i64(td
);
953 tcg_temp_free_i64(tcy
);
954 tcg_temp_free_i32(res
);
955 tcg_temp_free_i32(sr_cy
);
956 tcg_temp_free_i32(sr_ove
);
960 case 0x29: /* l.andi */
961 LOG_DIS("l.andi r%d, r%d, %d\n", rd
, ra
, I16
);
962 tcg_gen_andi_tl(cpu_R
[rd
], cpu_R
[ra
], zero_extend(I16
, 16));
965 case 0x2a: /* l.ori */
966 LOG_DIS("l.ori r%d, r%d, %d\n", rd
, ra
, I16
);
967 tcg_gen_ori_tl(cpu_R
[rd
], cpu_R
[ra
], zero_extend(I16
, 16));
970 case 0x2b: /* l.xori */
971 LOG_DIS("l.xori r%d, r%d, %d\n", rd
, ra
, I16
);
972 tcg_gen_xori_tl(cpu_R
[rd
], cpu_R
[ra
], sign_extend(I16
, 16));
975 case 0x2c: /* l.muli */
976 LOG_DIS("l.muli r%d, r%d, %d\n", rd
, ra
, I16
);
977 if (ra
!= 0 && I16
!= 0) {
978 TCGv_i32 im
= tcg_const_i32(I16
);
979 gen_helper_mul32(cpu_R
[rd
], cpu_env
, cpu_R
[ra
], im
);
980 tcg_temp_free_i32(im
);
982 tcg_gen_movi_tl(cpu_R
[rd
], 0x0);
986 case 0x2d: /* l.mfspr */
987 LOG_DIS("l.mfspr r%d, r%d, %d\n", rd
, ra
, I16
);
989 #if defined(CONFIG_USER_ONLY)
992 TCGv_i32 ti
= tcg_const_i32(I16
);
993 if (dc
->mem_idx
== MMU_USER_IDX
) {
994 gen_illegal_exception(dc
);
997 gen_helper_mfspr(cpu_R
[rd
], cpu_env
, cpu_R
[rd
], cpu_R
[ra
], ti
);
998 tcg_temp_free_i32(ti
);
1003 case 0x30: /* l.mtspr */
1004 LOG_DIS("l.mtspr %d, r%d, r%d, %d\n", I5
, ra
, rb
, I11
);
1006 #if defined(CONFIG_USER_ONLY)
1009 TCGv_i32 im
= tcg_const_i32(tmp
);
1010 if (dc
->mem_idx
== MMU_USER_IDX
) {
1011 gen_illegal_exception(dc
);
1014 gen_helper_mtspr(cpu_env
, cpu_R
[ra
], cpu_R
[rb
], im
);
1015 tcg_temp_free_i32(im
);
1020 /* not used yet, open it when we need or64. */
1021 /*#ifdef TARGET_OPENRISC64
1023 LOG_DIS("l.sd %d, r%d, r%d, %d\n", I5, ra, rb, I11);
1029 case 0x35: /* l.sw */
1030 LOG_DIS("l.sw %d, r%d, r%d, %d\n", I5
, ra
, rb
, I11
);
1034 case 0x36: /* l.sb */
1035 LOG_DIS("l.sb %d, r%d, r%d, %d\n", I5
, ra
, rb
, I11
);
1039 case 0x37: /* l.sh */
1040 LOG_DIS("l.sh %d, r%d, r%d, %d\n", I5
, ra
, rb
, I11
);
1046 TCGv t0
= tcg_temp_new();
1047 tcg_gen_addi_tl(t0
, cpu_R
[ra
], sign_extend(tmp
, 16));
1048 tcg_gen_qemu_st_tl(cpu_R
[rb
], t0
, dc
->mem_idx
, mop
);
1054 gen_illegal_exception(dc
);
1059 static void dec_mac(DisasContext
*dc
, uint32_t insn
)
1063 op0
= extract32(insn
, 0, 4);
1064 ra
= extract32(insn
, 16, 5);
1065 rb
= extract32(insn
, 11, 5);
1068 case 0x0001: /* l.mac */
1069 LOG_DIS("l.mac r%d, r%d\n", ra
, rb
);
1071 TCGv_i32 t0
= tcg_temp_new_i32();
1072 TCGv_i64 t1
= tcg_temp_new_i64();
1073 TCGv_i64 t2
= tcg_temp_new_i64();
1074 tcg_gen_mul_tl(t0
, cpu_R
[ra
], cpu_R
[rb
]);
1075 tcg_gen_ext_i32_i64(t1
, t0
);
1076 tcg_gen_concat_i32_i64(t2
, maclo
, machi
);
1077 tcg_gen_add_i64(t2
, t2
, t1
);
1078 tcg_gen_trunc_i64_i32(maclo
, t2
);
1079 tcg_gen_shri_i64(t2
, t2
, 32);
1080 tcg_gen_trunc_i64_i32(machi
, t2
);
1081 tcg_temp_free_i32(t0
);
1082 tcg_temp_free_i64(t1
);
1083 tcg_temp_free_i64(t2
);
1087 case 0x0002: /* l.msb */
1088 LOG_DIS("l.msb r%d, r%d\n", ra
, rb
);
1090 TCGv_i32 t0
= tcg_temp_new_i32();
1091 TCGv_i64 t1
= tcg_temp_new_i64();
1092 TCGv_i64 t2
= tcg_temp_new_i64();
1093 tcg_gen_mul_tl(t0
, cpu_R
[ra
], cpu_R
[rb
]);
1094 tcg_gen_ext_i32_i64(t1
, t0
);
1095 tcg_gen_concat_i32_i64(t2
, maclo
, machi
);
1096 tcg_gen_sub_i64(t2
, t2
, t1
);
1097 tcg_gen_trunc_i64_i32(maclo
, t2
);
1098 tcg_gen_shri_i64(t2
, t2
, 32);
1099 tcg_gen_trunc_i64_i32(machi
, t2
);
1100 tcg_temp_free_i32(t0
);
1101 tcg_temp_free_i64(t1
);
1102 tcg_temp_free_i64(t2
);
1107 gen_illegal_exception(dc
);
1112 static void dec_logic(DisasContext
*dc
, uint32_t insn
)
1115 uint32_t rd
, ra
, L6
;
1116 op0
= extract32(insn
, 6, 2);
1117 rd
= extract32(insn
, 21, 5);
1118 ra
= extract32(insn
, 16, 5);
1119 L6
= extract32(insn
, 0, 6);
1122 case 0x00: /* l.slli */
1123 LOG_DIS("l.slli r%d, r%d, %d\n", rd
, ra
, L6
);
1124 tcg_gen_shli_tl(cpu_R
[rd
], cpu_R
[ra
], (L6
& 0x1f));
1127 case 0x01: /* l.srli */
1128 LOG_DIS("l.srli r%d, r%d, %d\n", rd
, ra
, L6
);
1129 tcg_gen_shri_tl(cpu_R
[rd
], cpu_R
[ra
], (L6
& 0x1f));
1132 case 0x02: /* l.srai */
1133 LOG_DIS("l.srai r%d, r%d, %d\n", rd
, ra
, L6
);
1134 tcg_gen_sari_tl(cpu_R
[rd
], cpu_R
[ra
], (L6
& 0x1f)); break;
1136 case 0x03: /* l.rori */
1137 LOG_DIS("l.rori r%d, r%d, %d\n", rd
, ra
, L6
);
1138 tcg_gen_rotri_tl(cpu_R
[rd
], cpu_R
[ra
], (L6
& 0x1f));
1142 gen_illegal_exception(dc
);
1147 static void dec_M(DisasContext
*dc
, uint32_t insn
)
1152 op0
= extract32(insn
, 16, 1);
1153 rd
= extract32(insn
, 21, 5);
1154 K16
= extract32(insn
, 0, 16);
1157 case 0x0: /* l.movhi */
1158 LOG_DIS("l.movhi r%d, %d\n", rd
, K16
);
1159 tcg_gen_movi_tl(cpu_R
[rd
], (K16
<< 16));
1162 case 0x1: /* l.macrc */
1163 LOG_DIS("l.macrc r%d\n", rd
);
1164 tcg_gen_mov_tl(cpu_R
[rd
], maclo
);
1165 tcg_gen_movi_tl(maclo
, 0x0);
1166 tcg_gen_movi_tl(machi
, 0x0);
1170 gen_illegal_exception(dc
);
1175 static void dec_comp(DisasContext
*dc
, uint32_t insn
)
1180 op0
= extract32(insn
, 21, 5);
1181 ra
= extract32(insn
, 16, 5);
1182 rb
= extract32(insn
, 11, 5);
1184 tcg_gen_movi_i32(env_btaken
, 0x0);
1185 /* unsigned integers */
1186 tcg_gen_ext32u_tl(cpu_R
[ra
], cpu_R
[ra
]);
1187 tcg_gen_ext32u_tl(cpu_R
[rb
], cpu_R
[rb
]);
1190 case 0x0: /* l.sfeq */
1191 LOG_DIS("l.sfeq r%d, r%d\n", ra
, rb
);
1192 tcg_gen_setcond_tl(TCG_COND_EQ
, env_btaken
, cpu_R
[ra
], cpu_R
[rb
]);
1195 case 0x1: /* l.sfne */
1196 LOG_DIS("l.sfne r%d, r%d\n", ra
, rb
);
1197 tcg_gen_setcond_tl(TCG_COND_NE
, env_btaken
, cpu_R
[ra
], cpu_R
[rb
]);
1200 case 0x2: /* l.sfgtu */
1201 LOG_DIS("l.sfgtu r%d, r%d\n", ra
, rb
);
1202 tcg_gen_setcond_tl(TCG_COND_GTU
, env_btaken
, cpu_R
[ra
], cpu_R
[rb
]);
1205 case 0x3: /* l.sfgeu */
1206 LOG_DIS("l.sfgeu r%d, r%d\n", ra
, rb
);
1207 tcg_gen_setcond_tl(TCG_COND_GEU
, env_btaken
, cpu_R
[ra
], cpu_R
[rb
]);
1210 case 0x4: /* l.sfltu */
1211 LOG_DIS("l.sfltu r%d, r%d\n", ra
, rb
);
1212 tcg_gen_setcond_tl(TCG_COND_LTU
, env_btaken
, cpu_R
[ra
], cpu_R
[rb
]);
1215 case 0x5: /* l.sfleu */
1216 LOG_DIS("l.sfleu r%d, r%d\n", ra
, rb
);
1217 tcg_gen_setcond_tl(TCG_COND_LEU
, env_btaken
, cpu_R
[ra
], cpu_R
[rb
]);
1220 case 0xa: /* l.sfgts */
1221 LOG_DIS("l.sfgts r%d, r%d\n", ra
, rb
);
1222 tcg_gen_setcond_tl(TCG_COND_GT
, env_btaken
, cpu_R
[ra
], cpu_R
[rb
]);
1225 case 0xb: /* l.sfges */
1226 LOG_DIS("l.sfges r%d, r%d\n", ra
, rb
);
1227 tcg_gen_setcond_tl(TCG_COND_GE
, env_btaken
, cpu_R
[ra
], cpu_R
[rb
]);
1230 case 0xc: /* l.sflts */
1231 LOG_DIS("l.sflts r%d, r%d\n", ra
, rb
);
1232 tcg_gen_setcond_tl(TCG_COND_LT
, env_btaken
, cpu_R
[ra
], cpu_R
[rb
]);
1235 case 0xd: /* l.sfles */
1236 LOG_DIS("l.sfles r%d, r%d\n", ra
, rb
);
1237 tcg_gen_setcond_tl(TCG_COND_LE
, env_btaken
, cpu_R
[ra
], cpu_R
[rb
]);
1241 gen_illegal_exception(dc
);
1247 static void dec_compi(DisasContext
*dc
, uint32_t insn
)
1252 op0
= extract32(insn
, 21, 5);
1253 ra
= extract32(insn
, 16, 5);
1254 I16
= extract32(insn
, 0, 16);
1256 tcg_gen_movi_i32(env_btaken
, 0x0);
1257 I16
= sign_extend(I16
, 16);
1260 case 0x0: /* l.sfeqi */
1261 LOG_DIS("l.sfeqi r%d, %d\n", ra
, I16
);
1262 tcg_gen_setcondi_tl(TCG_COND_EQ
, env_btaken
, cpu_R
[ra
], I16
);
1265 case 0x1: /* l.sfnei */
1266 LOG_DIS("l.sfnei r%d, %d\n", ra
, I16
);
1267 tcg_gen_setcondi_tl(TCG_COND_NE
, env_btaken
, cpu_R
[ra
], I16
);
1270 case 0x2: /* l.sfgtui */
1271 LOG_DIS("l.sfgtui r%d, %d\n", ra
, I16
);
1272 tcg_gen_setcondi_tl(TCG_COND_GTU
, env_btaken
, cpu_R
[ra
], I16
);
1275 case 0x3: /* l.sfgeui */
1276 LOG_DIS("l.sfgeui r%d, %d\n", ra
, I16
);
1277 tcg_gen_setcondi_tl(TCG_COND_GEU
, env_btaken
, cpu_R
[ra
], I16
);
1280 case 0x4: /* l.sfltui */
1281 LOG_DIS("l.sfltui r%d, %d\n", ra
, I16
);
1282 tcg_gen_setcondi_tl(TCG_COND_LTU
, env_btaken
, cpu_R
[ra
], I16
);
1285 case 0x5: /* l.sfleui */
1286 LOG_DIS("l.sfleui r%d, %d\n", ra
, I16
);
1287 tcg_gen_setcondi_tl(TCG_COND_LEU
, env_btaken
, cpu_R
[ra
], I16
);
1290 case 0xa: /* l.sfgtsi */
1291 LOG_DIS("l.sfgtsi r%d, %d\n", ra
, I16
);
1292 tcg_gen_setcondi_tl(TCG_COND_GT
, env_btaken
, cpu_R
[ra
], I16
);
1295 case 0xb: /* l.sfgesi */
1296 LOG_DIS("l.sfgesi r%d, %d\n", ra
, I16
);
1297 tcg_gen_setcondi_tl(TCG_COND_GE
, env_btaken
, cpu_R
[ra
], I16
);
1300 case 0xc: /* l.sfltsi */
1301 LOG_DIS("l.sfltsi r%d, %d\n", ra
, I16
);
1302 tcg_gen_setcondi_tl(TCG_COND_LT
, env_btaken
, cpu_R
[ra
], I16
);
1305 case 0xd: /* l.sflesi */
1306 LOG_DIS("l.sflesi r%d, %d\n", ra
, I16
);
1307 tcg_gen_setcondi_tl(TCG_COND_LE
, env_btaken
, cpu_R
[ra
], I16
);
1311 gen_illegal_exception(dc
);
1317 static void dec_sys(DisasContext
*dc
, uint32_t insn
)
1320 #ifdef OPENRISC_DISAS
1323 op0
= extract32(insn
, 16, 10);
1324 #ifdef OPENRISC_DISAS
1325 K16
= extract32(insn
, 0, 16);
1329 case 0x000: /* l.sys */
1330 LOG_DIS("l.sys %d\n", K16
);
1331 tcg_gen_movi_tl(cpu_pc
, dc
->pc
);
1332 gen_exception(dc
, EXCP_SYSCALL
);
1333 dc
->is_jmp
= DISAS_UPDATE
;
1336 case 0x100: /* l.trap */
1337 LOG_DIS("l.trap %d\n", K16
);
1338 #if defined(CONFIG_USER_ONLY)
1341 if (dc
->mem_idx
== MMU_USER_IDX
) {
1342 gen_illegal_exception(dc
);
1345 tcg_gen_movi_tl(cpu_pc
, dc
->pc
);
1346 gen_exception(dc
, EXCP_TRAP
);
1350 case 0x300: /* l.csync */
1351 LOG_DIS("l.csync\n");
1352 #if defined(CONFIG_USER_ONLY)
1355 if (dc
->mem_idx
== MMU_USER_IDX
) {
1356 gen_illegal_exception(dc
);
1362 case 0x200: /* l.msync */
1363 LOG_DIS("l.msync\n");
1364 #if defined(CONFIG_USER_ONLY)
1367 if (dc
->mem_idx
== MMU_USER_IDX
) {
1368 gen_illegal_exception(dc
);
1374 case 0x270: /* l.psync */
1375 LOG_DIS("l.psync\n");
1376 #if defined(CONFIG_USER_ONLY)
1379 if (dc
->mem_idx
== MMU_USER_IDX
) {
1380 gen_illegal_exception(dc
);
1387 gen_illegal_exception(dc
);
1392 static void dec_float(DisasContext
*dc
, uint32_t insn
)
1395 uint32_t ra
, rb
, rd
;
1396 op0
= extract32(insn
, 0, 8);
1397 ra
= extract32(insn
, 16, 5);
1398 rb
= extract32(insn
, 11, 5);
1399 rd
= extract32(insn
, 21, 5);
1402 case 0x00: /* lf.add.s */
1403 LOG_DIS("lf.add.s r%d, r%d, r%d\n", rd
, ra
, rb
);
1404 gen_helper_float_add_s(cpu_R
[rd
], cpu_env
, cpu_R
[ra
], cpu_R
[rb
]);
1407 case 0x01: /* lf.sub.s */
1408 LOG_DIS("lf.sub.s r%d, r%d, r%d\n", rd
, ra
, rb
);
1409 gen_helper_float_sub_s(cpu_R
[rd
], cpu_env
, cpu_R
[ra
], cpu_R
[rb
]);
1413 case 0x02: /* lf.mul.s */
1414 LOG_DIS("lf.mul.s r%d, r%d, r%d\n", rd
, ra
, rb
);
1415 if (ra
!= 0 && rb
!= 0) {
1416 gen_helper_float_mul_s(cpu_R
[rd
], cpu_env
, cpu_R
[ra
], cpu_R
[rb
]);
1418 tcg_gen_ori_tl(fpcsr
, fpcsr
, FPCSR_ZF
);
1419 tcg_gen_movi_i32(cpu_R
[rd
], 0x0);
1423 case 0x03: /* lf.div.s */
1424 LOG_DIS("lf.div.s r%d, r%d, r%d\n", rd
, ra
, rb
);
1425 gen_helper_float_div_s(cpu_R
[rd
], cpu_env
, cpu_R
[ra
], cpu_R
[rb
]);
1428 case 0x04: /* lf.itof.s */
1429 LOG_DIS("lf.itof r%d, r%d\n", rd
, ra
);
1430 gen_helper_itofs(cpu_R
[rd
], cpu_env
, cpu_R
[ra
]);
1433 case 0x05: /* lf.ftoi.s */
1434 LOG_DIS("lf.ftoi r%d, r%d\n", rd
, ra
);
1435 gen_helper_ftois(cpu_R
[rd
], cpu_env
, cpu_R
[ra
]);
1438 case 0x06: /* lf.rem.s */
1439 LOG_DIS("lf.rem.s r%d, r%d, r%d\n", rd
, ra
, rb
);
1440 gen_helper_float_rem_s(cpu_R
[rd
], cpu_env
, cpu_R
[ra
], cpu_R
[rb
]);
1443 case 0x07: /* lf.madd.s */
1444 LOG_DIS("lf.madd.s r%d, r%d, r%d\n", rd
, ra
, rb
);
1445 gen_helper_float_muladd_s(cpu_R
[rd
], cpu_env
, cpu_R
[ra
], cpu_R
[rb
]);
1448 case 0x08: /* lf.sfeq.s */
1449 LOG_DIS("lf.sfeq.s r%d, r%d\n", ra
, rb
);
1450 gen_helper_float_eq_s(env_btaken
, cpu_env
, cpu_R
[ra
], cpu_R
[rb
]);
1453 case 0x09: /* lf.sfne.s */
1454 LOG_DIS("lf.sfne.s r%d, r%d\n", ra
, rb
);
1455 gen_helper_float_ne_s(env_btaken
, cpu_env
, cpu_R
[ra
], cpu_R
[rb
]);
1458 case 0x0a: /* lf.sfgt.s */
1459 LOG_DIS("lf.sfgt.s r%d, r%d\n", ra
, rb
);
1460 gen_helper_float_gt_s(env_btaken
, cpu_env
, cpu_R
[ra
], cpu_R
[rb
]);
1463 case 0x0b: /* lf.sfge.s */
1464 LOG_DIS("lf.sfge.s r%d, r%d\n", ra
, rb
);
1465 gen_helper_float_ge_s(env_btaken
, cpu_env
, cpu_R
[ra
], cpu_R
[rb
]);
1468 case 0x0c: /* lf.sflt.s */
1469 LOG_DIS("lf.sflt.s r%d, r%d\n", ra
, rb
);
1470 gen_helper_float_lt_s(env_btaken
, cpu_env
, cpu_R
[ra
], cpu_R
[rb
]);
1473 case 0x0d: /* lf.sfle.s */
1474 LOG_DIS("lf.sfle.s r%d, r%d\n", ra
, rb
);
1475 gen_helper_float_le_s(env_btaken
, cpu_env
, cpu_R
[ra
], cpu_R
[rb
]);
1478 /* not used yet, open it when we need or64. */
1479 /*#ifdef TARGET_OPENRISC64
1481 LOG_DIS("lf.add.d r%d, r%d, r%d\n", rd, ra, rb);
1483 gen_helper_float_add_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]);
1487 LOG_DIS("lf.sub.d r%d, r%d, r%d\n", rd, ra, rb);
1489 gen_helper_float_sub_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]);
1493 LOG_DIS("lf.mul.d r%d, r%d, r%d\n", rd, ra, rb);
1495 if (ra != 0 && rb != 0) {
1496 gen_helper_float_mul_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]);
1498 tcg_gen_ori_tl(fpcsr, fpcsr, FPCSR_ZF);
1499 tcg_gen_movi_i64(cpu_R[rd], 0x0);
1504 LOG_DIS("lf.div.d r%d, r%d, r%d\n", rd, ra, rb);
1506 gen_helper_float_div_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]);
1509 case 0x14: lf.itof.d
1510 LOG_DIS("lf.itof r%d, r%d\n", rd, ra);
1512 gen_helper_itofd(cpu_R[rd], cpu_env, cpu_R[ra]);
1515 case 0x15: lf.ftoi.d
1516 LOG_DIS("lf.ftoi r%d, r%d\n", rd, ra);
1518 gen_helper_ftoid(cpu_R[rd], cpu_env, cpu_R[ra]);
1522 LOG_DIS("lf.rem.d r%d, r%d, r%d\n", rd, ra, rb);
1524 gen_helper_float_rem_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]);
1527 case 0x17: lf.madd.d
1528 LOG_DIS("lf.madd.d r%d, r%d, r%d\n", rd, ra, rb);
1530 gen_helper_float_muladd_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]);
1533 case 0x18: lf.sfeq.d
1534 LOG_DIS("lf.sfeq.d r%d, r%d\n", ra, rb);
1536 gen_helper_float_eq_d(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]);
1539 case 0x1a: lf.sfgt.d
1540 LOG_DIS("lf.sfgt.d r%d, r%d\n", ra, rb);
1542 gen_helper_float_gt_d(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]);
1545 case 0x1b: lf.sfge.d
1546 LOG_DIS("lf.sfge.d r%d, r%d\n", ra, rb);
1548 gen_helper_float_ge_d(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]);
1551 case 0x19: lf.sfne.d
1552 LOG_DIS("lf.sfne.d r%d, r%d\n", ra, rb);
1554 gen_helper_float_ne_d(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]);
1557 case 0x1c: lf.sflt.d
1558 LOG_DIS("lf.sflt.d r%d, r%d\n", ra, rb);
1560 gen_helper_float_lt_d(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]);
1563 case 0x1d: lf.sfle.d
1564 LOG_DIS("lf.sfle.d r%d, r%d\n", ra, rb);
1566 gen_helper_float_le_d(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]);
1571 gen_illegal_exception(dc
);
1577 static void disas_openrisc_insn(DisasContext
*dc
, OpenRISCCPU
*cpu
)
1581 insn
= cpu_ldl_code(&cpu
->env
, dc
->pc
);
1582 op0
= extract32(insn
, 26, 6);
1594 dec_logic(dc
, insn
);
1598 dec_compi(dc
, insn
);
1606 dec_float(dc
, insn
);
1623 static void check_breakpoint(OpenRISCCPU
*cpu
, DisasContext
*dc
)
1625 CPUState
*cs
= CPU(cpu
);
1628 if (unlikely(!QTAILQ_EMPTY(&cs
->breakpoints
))) {
1629 QTAILQ_FOREACH(bp
, &cs
->breakpoints
, entry
) {
1630 if (bp
->pc
== dc
->pc
) {
1631 tcg_gen_movi_tl(cpu_pc
, dc
->pc
);
1632 gen_exception(dc
, EXCP_DEBUG
);
1633 dc
->is_jmp
= DISAS_UPDATE
;
1639 static inline void gen_intermediate_code_internal(OpenRISCCPU
*cpu
,
1640 TranslationBlock
*tb
,
1643 CPUState
*cs
= CPU(cpu
);
1644 struct DisasContext ctx
, *dc
= &ctx
;
1645 uint16_t *gen_opc_end
;
1648 uint32_t next_page_start
;
1655 gen_opc_end
= tcg_ctx
.gen_opc_buf
+ OPC_MAX_SIZE
;
1656 dc
->is_jmp
= DISAS_NEXT
;
1659 dc
->flags
= cpu
->env
.cpucfgr
;
1660 dc
->mem_idx
= cpu_mmu_index(&cpu
->env
);
1661 dc
->synced_flags
= dc
->tb_flags
= tb
->flags
;
1662 dc
->delayed_branch
= !!(dc
->tb_flags
& D_FLAG
);
1663 dc
->singlestep_enabled
= cs
->singlestep_enabled
;
1664 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
1665 qemu_log("-----------------------------------------\n");
1666 log_cpu_state(CPU(cpu
), 0);
1669 next_page_start
= (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
1672 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
1674 if (max_insns
== 0) {
1675 max_insns
= CF_COUNT_MASK
;
1681 check_breakpoint(cpu
, dc
);
1683 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
1687 tcg_ctx
.gen_opc_instr_start
[k
++] = 0;
1690 tcg_ctx
.gen_opc_pc
[k
] = dc
->pc
;
1691 tcg_ctx
.gen_opc_instr_start
[k
] = 1;
1692 tcg_ctx
.gen_opc_icount
[k
] = num_insns
;
1695 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
1696 tcg_gen_debug_insn_start(dc
->pc
);
1699 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
1702 dc
->ppc
= dc
->pc
- 4;
1703 dc
->npc
= dc
->pc
+ 4;
1704 tcg_gen_movi_tl(cpu_ppc
, dc
->ppc
);
1705 tcg_gen_movi_tl(cpu_npc
, dc
->npc
);
1706 disas_openrisc_insn(dc
, cpu
);
1710 if (dc
->delayed_branch
) {
1711 dc
->delayed_branch
--;
1712 if (!dc
->delayed_branch
) {
1713 dc
->tb_flags
&= ~D_FLAG
;
1715 tcg_gen_mov_tl(cpu_pc
, jmp_pc
);
1716 tcg_gen_mov_tl(cpu_npc
, jmp_pc
);
1717 tcg_gen_movi_tl(jmp_pc
, 0);
1719 dc
->is_jmp
= DISAS_JUMP
;
1723 } while (!dc
->is_jmp
1724 && tcg_ctx
.gen_opc_ptr
< gen_opc_end
1725 && !cs
->singlestep_enabled
1727 && (dc
->pc
< next_page_start
)
1728 && num_insns
< max_insns
);
1730 if (tb
->cflags
& CF_LAST_IO
) {
1733 if (dc
->is_jmp
== DISAS_NEXT
) {
1734 dc
->is_jmp
= DISAS_UPDATE
;
1735 tcg_gen_movi_tl(cpu_pc
, dc
->pc
);
1737 if (unlikely(cs
->singlestep_enabled
)) {
1738 if (dc
->is_jmp
== DISAS_NEXT
) {
1739 tcg_gen_movi_tl(cpu_pc
, dc
->pc
);
1741 gen_exception(dc
, EXCP_DEBUG
);
1743 switch (dc
->is_jmp
) {
1745 gen_goto_tb(dc
, 0, dc
->pc
);
1751 /* indicate that the hash table must be used
1752 to find the next TB */
1756 /* nothing more to generate */
1761 gen_tb_end(tb
, num_insns
);
1762 *tcg_ctx
.gen_opc_ptr
= INDEX_op_end
;
1764 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
1767 tcg_ctx
.gen_opc_instr_start
[k
++] = 0;
1770 tb
->size
= dc
->pc
- pc_start
;
1771 tb
->icount
= num_insns
;
1775 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
1777 log_target_disas(&cpu
->env
, pc_start
, dc
->pc
- pc_start
, 0);
1778 qemu_log("\nisize=%d osize=%td\n",
1779 dc
->pc
- pc_start
, tcg_ctx
.gen_opc_ptr
-
1780 tcg_ctx
.gen_opc_buf
);
1785 void gen_intermediate_code(CPUOpenRISCState
*env
, struct TranslationBlock
*tb
)
1787 gen_intermediate_code_internal(openrisc_env_get_cpu(env
), tb
, 0);
1790 void gen_intermediate_code_pc(CPUOpenRISCState
*env
,
1791 struct TranslationBlock
*tb
)
1793 gen_intermediate_code_internal(openrisc_env_get_cpu(env
), tb
, 1);
1796 void openrisc_cpu_dump_state(CPUState
*cs
, FILE *f
,
1797 fprintf_function cpu_fprintf
,
1800 OpenRISCCPU
*cpu
= OPENRISC_CPU(cs
);
1801 CPUOpenRISCState
*env
= &cpu
->env
;
1804 cpu_fprintf(f
, "PC=%08x\n", env
->pc
);
1805 for (i
= 0; i
< 32; ++i
) {
1806 cpu_fprintf(f
, "R%02d=%08x%c", i
, env
->gpr
[i
],
1807 (i
% 4) == 3 ? '\n' : ' ');
1811 void restore_state_to_opc(CPUOpenRISCState
*env
, TranslationBlock
*tb
,
1814 env
->pc
= tcg_ctx
.gen_opc_pc
[pc_pos
];