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"
34 #define OPENRISC_DISAS
37 # define LOG_DIS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
39 # define LOG_DIS(...) do { } while (0)
42 typedef struct DisasContext
{
44 target_ulong pc
, ppc
, npc
;
45 uint32_t tb_flags
, synced_flags
, flags
;
48 int singlestep_enabled
;
49 uint32_t delayed_branch
;
52 static TCGv_ptr cpu_env
;
54 static TCGv cpu_R
[32];
56 static TCGv jmp_pc
; /* l.jr/l.jalr temp pc */
59 static TCGv_i32 env_btaken
; /* bf/bnf , F flag taken */
60 static TCGv_i32 fpcsr
;
61 static TCGv machi
, maclo
;
62 static TCGv fpmaddhi
, fpmaddlo
;
63 static TCGv_i32 env_flags
;
64 #include "exec/gen-icount.h"
66 void openrisc_translate_init(void)
68 static const char * const regnames
[] = {
69 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
70 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
71 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
72 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
76 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
77 cpu_sr
= tcg_global_mem_new(TCG_AREG0
,
78 offsetof(CPUOpenRISCState
, sr
), "sr");
79 env_flags
= tcg_global_mem_new_i32(TCG_AREG0
,
80 offsetof(CPUOpenRISCState
, flags
),
82 cpu_pc
= tcg_global_mem_new(TCG_AREG0
,
83 offsetof(CPUOpenRISCState
, pc
), "pc");
84 cpu_npc
= tcg_global_mem_new(TCG_AREG0
,
85 offsetof(CPUOpenRISCState
, npc
), "npc");
86 cpu_ppc
= tcg_global_mem_new(TCG_AREG0
,
87 offsetof(CPUOpenRISCState
, ppc
), "ppc");
88 jmp_pc
= tcg_global_mem_new(TCG_AREG0
,
89 offsetof(CPUOpenRISCState
, jmp_pc
), "jmp_pc");
90 env_btaken
= tcg_global_mem_new_i32(TCG_AREG0
,
91 offsetof(CPUOpenRISCState
, btaken
),
93 fpcsr
= tcg_global_mem_new_i32(TCG_AREG0
,
94 offsetof(CPUOpenRISCState
, fpcsr
),
96 machi
= tcg_global_mem_new(TCG_AREG0
,
97 offsetof(CPUOpenRISCState
, machi
),
99 maclo
= tcg_global_mem_new(TCG_AREG0
,
100 offsetof(CPUOpenRISCState
, maclo
),
102 fpmaddhi
= tcg_global_mem_new(TCG_AREG0
,
103 offsetof(CPUOpenRISCState
, fpmaddhi
),
105 fpmaddlo
= tcg_global_mem_new(TCG_AREG0
,
106 offsetof(CPUOpenRISCState
, fpmaddlo
),
108 for (i
= 0; i
< 32; i
++) {
109 cpu_R
[i
] = tcg_global_mem_new(TCG_AREG0
,
110 offsetof(CPUOpenRISCState
, gpr
[i
]),
115 /* Writeback SR_F translation space to execution space. */
116 static inline void wb_SR_F(void)
120 label
= gen_new_label();
121 tcg_gen_andi_tl(cpu_sr
, cpu_sr
, ~SR_F
);
122 tcg_gen_brcondi_tl(TCG_COND_EQ
, env_btaken
, 0, label
);
123 tcg_gen_ori_tl(cpu_sr
, cpu_sr
, SR_F
);
124 gen_set_label(label
);
127 static inline int zero_extend(unsigned int val
, int width
)
129 return val
& ((1 << width
) - 1);
132 static inline int sign_extend(unsigned int val
, int width
)
137 val
<<= TARGET_LONG_BITS
- width
;
140 sval
>>= TARGET_LONG_BITS
- width
;
144 static inline void gen_sync_flags(DisasContext
*dc
)
146 /* Sync the tb dependent flag between translate and runtime. */
147 if (dc
->tb_flags
!= dc
->synced_flags
) {
148 tcg_gen_movi_tl(env_flags
, dc
->tb_flags
);
149 dc
->synced_flags
= dc
->tb_flags
;
153 static void gen_exception(DisasContext
*dc
, unsigned int excp
)
155 TCGv_i32 tmp
= tcg_const_i32(excp
);
156 gen_helper_exception(cpu_env
, tmp
);
157 tcg_temp_free_i32(tmp
);
160 static void gen_illegal_exception(DisasContext
*dc
)
162 tcg_gen_movi_tl(cpu_pc
, dc
->pc
);
163 gen_exception(dc
, EXCP_ILLEGAL
);
164 dc
->is_jmp
= DISAS_UPDATE
;
167 /* not used yet, open it when we need or64. */
168 /*#ifdef TARGET_OPENRISC64
169 static void check_ob64s(DisasContext *dc)
171 if (!(dc->flags & CPUCFGR_OB64S)) {
172 gen_illegal_exception(dc);
176 static void check_of64s(DisasContext *dc)
178 if (!(dc->flags & CPUCFGR_OF64S)) {
179 gen_illegal_exception(dc);
183 static void check_ov64s(DisasContext *dc)
185 if (!(dc->flags & CPUCFGR_OV64S)) {
186 gen_illegal_exception(dc);
191 static void gen_goto_tb(DisasContext
*dc
, int n
, target_ulong dest
)
193 TranslationBlock
*tb
;
195 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
) &&
196 likely(!dc
->singlestep_enabled
)) {
197 tcg_gen_movi_tl(cpu_pc
, dest
);
199 tcg_gen_exit_tb((uintptr_t)tb
+ n
);
201 tcg_gen_movi_tl(cpu_pc
, dest
);
202 if (dc
->singlestep_enabled
) {
203 gen_exception(dc
, EXCP_DEBUG
);
209 static void gen_jump(DisasContext
*dc
, uint32_t imm
, uint32_t reg
, uint32_t op0
)
212 /* N26, 26bits imm */
213 tmp_pc
= sign_extend((imm
<<2), 26) + dc
->pc
;
217 tcg_gen_movi_tl(jmp_pc
, tmp_pc
);
219 case 0x01: /* l.jal */
220 tcg_gen_movi_tl(cpu_R
[9], (dc
->pc
+ 8));
221 tcg_gen_movi_tl(jmp_pc
, tmp_pc
);
223 case 0x03: /* l.bnf */
224 case 0x04: /* l.bf */
226 int lab
= gen_new_label();
227 TCGv sr_f
= tcg_temp_new();
228 tcg_gen_movi_tl(jmp_pc
, dc
->pc
+8);
229 tcg_gen_andi_tl(sr_f
, cpu_sr
, SR_F
);
230 tcg_gen_brcondi_i32(op0
== 0x03 ? TCG_COND_EQ
: TCG_COND_NE
,
232 tcg_gen_movi_tl(jmp_pc
, tmp_pc
);
237 case 0x11: /* l.jr */
238 tcg_gen_mov_tl(jmp_pc
, cpu_R
[reg
]);
240 case 0x12: /* l.jalr */
241 tcg_gen_movi_tl(cpu_R
[9], (dc
->pc
+ 8));
242 tcg_gen_mov_tl(jmp_pc
, cpu_R
[reg
]);
245 gen_illegal_exception(dc
);
249 dc
->delayed_branch
= 2;
250 dc
->tb_flags
|= D_FLAG
;
255 static void dec_calc(DisasContext
*dc
, uint32_t insn
)
257 uint32_t op0
, op1
, op2
;
259 op0
= extract32(insn
, 0, 4);
260 op1
= extract32(insn
, 8, 2);
261 op2
= extract32(insn
, 6, 2);
262 ra
= extract32(insn
, 16, 5);
263 rb
= extract32(insn
, 11, 5);
264 rd
= extract32(insn
, 21, 5);
269 case 0x00: /* l.add */
270 LOG_DIS("l.add r%d, r%d, r%d\n", rd
, ra
, rb
);
272 int lab
= gen_new_label();
273 TCGv_i64 ta
= tcg_temp_new_i64();
274 TCGv_i64 tb
= tcg_temp_new_i64();
275 TCGv_i64 td
= tcg_temp_local_new_i64();
276 TCGv_i32 res
= tcg_temp_local_new_i32();
277 TCGv_i32 sr_ove
= tcg_temp_local_new_i32();
278 tcg_gen_extu_i32_i64(ta
, cpu_R
[ra
]);
279 tcg_gen_extu_i32_i64(tb
, cpu_R
[rb
]);
280 tcg_gen_add_i64(td
, ta
, tb
);
281 tcg_gen_trunc_i64_i32(res
, td
);
282 tcg_gen_shri_i64(td
, td
, 31);
283 tcg_gen_andi_i64(td
, td
, 0x3);
284 /* Jump to lab when no overflow. */
285 tcg_gen_brcondi_i64(TCG_COND_EQ
, td
, 0x0, lab
);
286 tcg_gen_brcondi_i64(TCG_COND_EQ
, td
, 0x3, lab
);
287 tcg_gen_ori_i32(cpu_sr
, cpu_sr
, (SR_OV
| SR_CY
));
288 tcg_gen_andi_i32(sr_ove
, cpu_sr
, SR_OVE
);
289 tcg_gen_brcondi_i32(TCG_COND_NE
, sr_ove
, SR_OVE
, lab
);
290 gen_exception(dc
, EXCP_RANGE
);
292 tcg_gen_mov_i32(cpu_R
[rd
], res
);
293 tcg_temp_free_i64(ta
);
294 tcg_temp_free_i64(tb
);
295 tcg_temp_free_i64(td
);
296 tcg_temp_free_i32(res
);
297 tcg_temp_free_i32(sr_ove
);
301 gen_illegal_exception(dc
);
306 case 0x0001: /* l.addc */
309 LOG_DIS("l.addc r%d, r%d, r%d\n", rd
, ra
, rb
);
311 int lab
= gen_new_label();
312 TCGv_i64 ta
= tcg_temp_new_i64();
313 TCGv_i64 tb
= tcg_temp_new_i64();
314 TCGv_i64 tcy
= tcg_temp_local_new_i64();
315 TCGv_i64 td
= tcg_temp_local_new_i64();
316 TCGv_i32 res
= tcg_temp_local_new_i32();
317 TCGv_i32 sr_cy
= tcg_temp_local_new_i32();
318 TCGv_i32 sr_ove
= tcg_temp_local_new_i32();
319 tcg_gen_extu_i32_i64(ta
, cpu_R
[ra
]);
320 tcg_gen_extu_i32_i64(tb
, cpu_R
[rb
]);
321 tcg_gen_andi_i32(sr_cy
, cpu_sr
, SR_CY
);
322 tcg_gen_extu_i32_i64(tcy
, sr_cy
);
323 tcg_gen_shri_i64(tcy
, tcy
, 10);
324 tcg_gen_add_i64(td
, ta
, tb
);
325 tcg_gen_add_i64(td
, td
, tcy
);
326 tcg_gen_trunc_i64_i32(res
, td
);
327 tcg_gen_shri_i64(td
, td
, 32);
328 tcg_gen_andi_i64(td
, td
, 0x3);
329 /* Jump to lab when no overflow. */
330 tcg_gen_brcondi_i64(TCG_COND_EQ
, td
, 0x0, lab
);
331 tcg_gen_brcondi_i64(TCG_COND_EQ
, td
, 0x3, lab
);
332 tcg_gen_ori_i32(cpu_sr
, cpu_sr
, (SR_OV
| SR_CY
));
333 tcg_gen_andi_i32(sr_ove
, cpu_sr
, SR_OVE
);
334 tcg_gen_brcondi_i32(TCG_COND_NE
, sr_ove
, SR_OVE
, lab
);
335 gen_exception(dc
, EXCP_RANGE
);
337 tcg_gen_mov_i32(cpu_R
[rd
], res
);
338 tcg_temp_free_i64(ta
);
339 tcg_temp_free_i64(tb
);
340 tcg_temp_free_i64(tcy
);
341 tcg_temp_free_i64(td
);
342 tcg_temp_free_i32(res
);
343 tcg_temp_free_i32(sr_cy
);
344 tcg_temp_free_i32(sr_ove
);
348 gen_illegal_exception(dc
);
353 case 0x0002: /* l.sub */
356 LOG_DIS("l.sub r%d, r%d, r%d\n", rd
, ra
, rb
);
358 int lab
= gen_new_label();
359 TCGv_i64 ta
= tcg_temp_new_i64();
360 TCGv_i64 tb
= tcg_temp_new_i64();
361 TCGv_i64 td
= tcg_temp_local_new_i64();
362 TCGv_i32 res
= tcg_temp_local_new_i32();
363 TCGv_i32 sr_ove
= tcg_temp_local_new_i32();
365 tcg_gen_extu_i32_i64(ta
, cpu_R
[ra
]);
366 tcg_gen_extu_i32_i64(tb
, cpu_R
[rb
]);
367 tcg_gen_sub_i64(td
, ta
, tb
);
368 tcg_gen_trunc_i64_i32(res
, td
);
369 tcg_gen_shri_i64(td
, td
, 31);
370 tcg_gen_andi_i64(td
, td
, 0x3);
371 /* Jump to lab when no overflow. */
372 tcg_gen_brcondi_i64(TCG_COND_EQ
, td
, 0x0, lab
);
373 tcg_gen_brcondi_i64(TCG_COND_EQ
, td
, 0x3, lab
);
374 tcg_gen_ori_i32(cpu_sr
, cpu_sr
, (SR_OV
| SR_CY
));
375 tcg_gen_andi_i32(sr_ove
, cpu_sr
, SR_OVE
);
376 tcg_gen_brcondi_i32(TCG_COND_NE
, sr_ove
, SR_OVE
, lab
);
377 gen_exception(dc
, EXCP_RANGE
);
379 tcg_gen_mov_i32(cpu_R
[rd
], res
);
380 tcg_temp_free_i64(ta
);
381 tcg_temp_free_i64(tb
);
382 tcg_temp_free_i64(td
);
383 tcg_temp_free_i32(res
);
384 tcg_temp_free_i32(sr_ove
);
388 gen_illegal_exception(dc
);
393 case 0x0003: /* l.and */
396 LOG_DIS("l.and r%d, r%d, r%d\n", rd
, ra
, rb
);
397 tcg_gen_and_tl(cpu_R
[rd
], cpu_R
[ra
], cpu_R
[rb
]);
400 gen_illegal_exception(dc
);
405 case 0x0004: /* l.or */
408 LOG_DIS("l.or r%d, r%d, r%d\n", rd
, ra
, rb
);
409 tcg_gen_or_tl(cpu_R
[rd
], cpu_R
[ra
], cpu_R
[rb
]);
412 gen_illegal_exception(dc
);
419 case 0x00: /* l.xor */
420 LOG_DIS("l.xor r%d, r%d, r%d\n", rd
, ra
, rb
);
421 tcg_gen_xor_tl(cpu_R
[rd
], cpu_R
[ra
], cpu_R
[rb
]);
424 gen_illegal_exception(dc
);
431 case 0x03: /* l.mul */
432 LOG_DIS("l.mul r%d, r%d, r%d\n", rd
, ra
, rb
);
433 if (ra
!= 0 && rb
!= 0) {
434 gen_helper_mul32(cpu_R
[rd
], cpu_env
, cpu_R
[ra
], cpu_R
[rb
]);
436 tcg_gen_movi_tl(cpu_R
[rd
], 0x0);
440 gen_illegal_exception(dc
);
447 case 0x03: /* l.div */
448 LOG_DIS("l.div r%d, r%d, r%d\n", rd
, ra
, rb
);
450 int lab0
= gen_new_label();
451 int lab1
= gen_new_label();
452 int lab2
= gen_new_label();
453 int lab3
= gen_new_label();
454 TCGv_i32 sr_ove
= tcg_temp_local_new_i32();
456 tcg_gen_ori_tl(cpu_sr
, cpu_sr
, (SR_OV
| SR_CY
));
457 tcg_gen_andi_tl(sr_ove
, cpu_sr
, SR_OVE
);
458 tcg_gen_brcondi_tl(TCG_COND_NE
, sr_ove
, SR_OVE
, lab0
);
459 gen_exception(dc
, EXCP_RANGE
);
462 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_R
[rb
],
464 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_R
[ra
],
466 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_R
[rb
],
469 tcg_gen_ori_tl(cpu_sr
, cpu_sr
, (SR_OV
| SR_CY
));
470 tcg_gen_andi_tl(sr_ove
, cpu_sr
, SR_OVE
);
471 tcg_gen_brcondi_tl(TCG_COND_NE
, sr_ove
, SR_OVE
, lab3
);
472 gen_exception(dc
, EXCP_RANGE
);
474 tcg_gen_div_tl(cpu_R
[rd
], cpu_R
[ra
], cpu_R
[rb
]);
477 tcg_temp_free_i32(sr_ove
);
482 gen_illegal_exception(dc
);
489 case 0x03: /* l.divu */
490 LOG_DIS("l.divu r%d, r%d, r%d\n", rd
, ra
, rb
);
492 int lab0
= gen_new_label();
493 int lab1
= gen_new_label();
494 int lab2
= gen_new_label();
495 TCGv_i32 sr_ove
= tcg_temp_local_new_i32();
497 tcg_gen_ori_tl(cpu_sr
, cpu_sr
, (SR_OV
| SR_CY
));
498 tcg_gen_andi_tl(sr_ove
, cpu_sr
, SR_OVE
);
499 tcg_gen_brcondi_tl(TCG_COND_NE
, sr_ove
, SR_OVE
, lab0
);
500 gen_exception(dc
, EXCP_RANGE
);
503 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_R
[rb
],
505 tcg_gen_ori_tl(cpu_sr
, cpu_sr
, (SR_OV
| SR_CY
));
506 tcg_gen_andi_tl(sr_ove
, cpu_sr
, SR_OVE
);
507 tcg_gen_brcondi_tl(TCG_COND_NE
, sr_ove
, SR_OVE
, lab2
);
508 gen_exception(dc
, EXCP_RANGE
);
510 tcg_gen_divu_tl(cpu_R
[rd
], cpu_R
[ra
], cpu_R
[rb
]);
513 tcg_temp_free_i32(sr_ove
);
518 gen_illegal_exception(dc
);
525 case 0x03: /* l.mulu */
526 LOG_DIS("l.mulu r%d, r%d, r%d\n", rd
, ra
, rb
);
527 if (rb
!= 0 && ra
!= 0) {
528 TCGv_i64 result
= tcg_temp_local_new_i64();
529 TCGv_i64 tra
= tcg_temp_local_new_i64();
530 TCGv_i64 trb
= tcg_temp_local_new_i64();
531 TCGv_i64 high
= tcg_temp_new_i64();
532 TCGv_i32 sr_ove
= tcg_temp_local_new_i32();
533 int lab
= gen_new_label();
534 /* Calculate the each result. */
535 tcg_gen_extu_i32_i64(tra
, cpu_R
[ra
]);
536 tcg_gen_extu_i32_i64(trb
, cpu_R
[rb
]);
537 tcg_gen_mul_i64(result
, tra
, trb
);
538 tcg_temp_free_i64(tra
);
539 tcg_temp_free_i64(trb
);
540 tcg_gen_shri_i64(high
, result
, TARGET_LONG_BITS
);
541 /* Overflow or not. */
542 tcg_gen_brcondi_i64(TCG_COND_EQ
, high
, 0x00000000, lab
);
543 tcg_gen_ori_tl(cpu_sr
, cpu_sr
, (SR_OV
| SR_CY
));
544 tcg_gen_andi_tl(sr_ove
, cpu_sr
, SR_OVE
);
545 tcg_gen_brcondi_tl(TCG_COND_NE
, sr_ove
, SR_OVE
, lab
);
546 gen_exception(dc
, EXCP_RANGE
);
548 tcg_temp_free_i64(high
);
549 tcg_gen_trunc_i64_tl(cpu_R
[rd
], result
);
550 tcg_temp_free_i64(result
);
551 tcg_temp_free_i32(sr_ove
);
553 tcg_gen_movi_tl(cpu_R
[rd
], 0);
558 gen_illegal_exception(dc
);
565 case 0x00: /* l.cmov */
566 LOG_DIS("l.cmov r%d, r%d, r%d\n", rd
, ra
, rb
);
568 int lab
= gen_new_label();
569 TCGv res
= tcg_temp_local_new();
570 TCGv sr_f
= tcg_temp_new();
571 tcg_gen_andi_tl(sr_f
, cpu_sr
, SR_F
);
572 tcg_gen_mov_tl(res
, cpu_R
[rb
]);
573 tcg_gen_brcondi_tl(TCG_COND_NE
, sr_f
, SR_F
, lab
);
574 tcg_gen_mov_tl(res
, cpu_R
[ra
]);
576 tcg_gen_mov_tl(cpu_R
[rd
], res
);
583 gen_illegal_exception(dc
);
590 case 0x00: /* l.ff1 */
591 LOG_DIS("l.ff1 r%d, r%d, r%d\n", rd
, ra
, rb
);
592 gen_helper_ff1(cpu_R
[rd
], cpu_R
[ra
]);
594 case 0x01: /* l.fl1 */
595 LOG_DIS("l.fl1 r%d, r%d, r%d\n", rd
, ra
, rb
);
596 gen_helper_fl1(cpu_R
[rd
], cpu_R
[ra
]);
600 gen_illegal_exception(dc
);
609 case 0x00: /* l.sll */
610 LOG_DIS("l.sll r%d, r%d, r%d\n", rd
, ra
, rb
);
611 tcg_gen_shl_tl(cpu_R
[rd
], cpu_R
[ra
], cpu_R
[rb
]);
613 case 0x01: /* l.srl */
614 LOG_DIS("l.srl r%d, r%d, r%d\n", rd
, ra
, rb
);
615 tcg_gen_shr_tl(cpu_R
[rd
], cpu_R
[ra
], cpu_R
[rb
]);
617 case 0x02: /* l.sra */
618 LOG_DIS("l.sra r%d, r%d, r%d\n", rd
, ra
, rb
);
619 tcg_gen_sar_tl(cpu_R
[rd
], cpu_R
[ra
], cpu_R
[rb
]);
621 case 0x03: /* l.ror */
622 LOG_DIS("l.ror r%d, r%d, r%d\n", rd
, ra
, rb
);
623 tcg_gen_rotr_tl(cpu_R
[rd
], cpu_R
[ra
], cpu_R
[rb
]);
627 gen_illegal_exception(dc
);
633 gen_illegal_exception(dc
);
642 case 0x00: /* l.exths */
643 LOG_DIS("l.exths r%d, r%d\n", rd
, ra
);
644 tcg_gen_ext16s_tl(cpu_R
[rd
], cpu_R
[ra
]);
646 case 0x01: /* l.extbs */
647 LOG_DIS("l.extbs r%d, r%d\n", rd
, ra
);
648 tcg_gen_ext8s_tl(cpu_R
[rd
], cpu_R
[ra
]);
650 case 0x02: /* l.exthz */
651 LOG_DIS("l.exthz r%d, r%d\n", rd
, ra
);
652 tcg_gen_ext16u_tl(cpu_R
[rd
], cpu_R
[ra
]);
654 case 0x03: /* l.extbz */
655 LOG_DIS("l.extbz r%d, r%d\n", rd
, ra
);
656 tcg_gen_ext8u_tl(cpu_R
[rd
], cpu_R
[ra
]);
660 gen_illegal_exception(dc
);
666 gen_illegal_exception(dc
);
675 case 0x00: /* l.extws */
676 LOG_DIS("l.extws r%d, r%d\n", rd
, ra
);
677 tcg_gen_ext32s_tl(cpu_R
[rd
], cpu_R
[ra
]);
679 case 0x01: /* l.extwz */
680 LOG_DIS("l.extwz r%d, r%d\n", rd
, ra
);
681 tcg_gen_ext32u_tl(cpu_R
[rd
], cpu_R
[ra
]);
685 gen_illegal_exception(dc
);
691 gen_illegal_exception(dc
);
697 gen_illegal_exception(dc
);
702 static void dec_misc(DisasContext
*dc
, uint32_t insn
)
706 #ifdef OPENRISC_DISAS
709 uint32_t I16
, I5
, I11
, N26
, tmp
;
710 op0
= extract32(insn
, 26, 6);
711 op1
= extract32(insn
, 24, 2);
712 ra
= extract32(insn
, 16, 5);
713 rb
= extract32(insn
, 11, 5);
714 rd
= extract32(insn
, 21, 5);
715 #ifdef OPENRISC_DISAS
716 L6
= extract32(insn
, 5, 6);
717 K5
= extract32(insn
, 0, 5);
719 I16
= extract32(insn
, 0, 16);
720 I5
= extract32(insn
, 21, 5);
721 I11
= extract32(insn
, 0, 11);
722 N26
= extract32(insn
, 0, 26);
723 tmp
= (I5
<<11) + I11
;
727 LOG_DIS("l.j %d\n", N26
);
728 gen_jump(dc
, N26
, 0, op0
);
731 case 0x01: /* l.jal */
732 LOG_DIS("l.jal %d\n", N26
);
733 gen_jump(dc
, N26
, 0, op0
);
736 case 0x03: /* l.bnf */
737 LOG_DIS("l.bnf %d\n", N26
);
738 gen_jump(dc
, N26
, 0, op0
);
741 case 0x04: /* l.bf */
742 LOG_DIS("l.bf %d\n", N26
);
743 gen_jump(dc
, N26
, 0, op0
);
748 case 0x01: /* l.nop */
749 LOG_DIS("l.nop %d\n", I16
);
753 gen_illegal_exception(dc
);
758 case 0x11: /* l.jr */
759 LOG_DIS("l.jr r%d\n", rb
);
760 gen_jump(dc
, 0, rb
, op0
);
763 case 0x12: /* l.jalr */
764 LOG_DIS("l.jalr r%d\n", rb
);
765 gen_jump(dc
, 0, rb
, op0
);
768 case 0x13: /* l.maci */
769 LOG_DIS("l.maci %d, r%d, %d\n", I5
, ra
, I11
);
771 TCGv_i64 t1
= tcg_temp_new_i64();
772 TCGv_i64 t2
= tcg_temp_new_i64();
773 TCGv_i32 dst
= tcg_temp_new_i32();
774 TCGv ttmp
= tcg_const_tl(tmp
);
775 tcg_gen_mul_tl(dst
, cpu_R
[ra
], ttmp
);
776 tcg_gen_ext_i32_i64(t1
, dst
);
777 tcg_gen_concat_i32_i64(t2
, maclo
, machi
);
778 tcg_gen_add_i64(t2
, t2
, t1
);
779 tcg_gen_trunc_i64_i32(maclo
, t2
);
780 tcg_gen_shri_i64(t2
, t2
, 32);
781 tcg_gen_trunc_i64_i32(machi
, t2
);
782 tcg_temp_free_i32(dst
);
784 tcg_temp_free_i64(t1
);
785 tcg_temp_free_i64(t2
);
789 case 0x09: /* l.rfe */
792 #if defined(CONFIG_USER_ONLY)
795 if (dc
->mem_idx
== MMU_USER_IDX
) {
796 gen_illegal_exception(dc
);
799 gen_helper_rfe(cpu_env
);
800 dc
->is_jmp
= DISAS_UPDATE
;
805 case 0x1c: /* l.cust1 */
806 LOG_DIS("l.cust1\n");
809 case 0x1d: /* l.cust2 */
810 LOG_DIS("l.cust2\n");
813 case 0x1e: /* l.cust3 */
814 LOG_DIS("l.cust3\n");
817 case 0x1f: /* l.cust4 */
818 LOG_DIS("l.cust4\n");
821 case 0x3c: /* l.cust5 */
822 LOG_DIS("l.cust5 r%d, r%d, r%d, %d, %d\n", rd
, ra
, rb
, L6
, K5
);
825 case 0x3d: /* l.cust6 */
826 LOG_DIS("l.cust6\n");
829 case 0x3e: /* l.cust7 */
830 LOG_DIS("l.cust7\n");
833 case 0x3f: /* l.cust8 */
834 LOG_DIS("l.cust8\n");
837 /* not used yet, open it when we need or64. */
838 /*#ifdef TARGET_OPENRISC64
840 LOG_DIS("l.ld r%d, r%d, %d\n", rd, ra, I16);
843 TCGv_i64 t0 = tcg_temp_new_i64();
844 tcg_gen_addi_i64(t0, cpu_R[ra], sign_extend(I16, 16));
845 tcg_gen_qemu_ld64(cpu_R[rd], t0, dc->mem_idx);
846 tcg_temp_free_i64(t0);
851 case 0x21: /* l.lwz */
852 LOG_DIS("l.lwz r%d, r%d, %d\n", rd
, ra
, I16
);
854 TCGv t0
= tcg_temp_new();
855 tcg_gen_addi_tl(t0
, cpu_R
[ra
], sign_extend(I16
, 16));
856 tcg_gen_qemu_ld32u(cpu_R
[rd
], t0
, dc
->mem_idx
);
861 case 0x22: /* l.lws */
862 LOG_DIS("l.lws r%d, r%d, %d\n", rd
, ra
, I16
);
864 TCGv t0
= tcg_temp_new();
865 tcg_gen_addi_tl(t0
, cpu_R
[ra
], sign_extend(I16
, 16));
866 tcg_gen_qemu_ld32s(cpu_R
[rd
], t0
, dc
->mem_idx
);
871 case 0x23: /* l.lbz */
872 LOG_DIS("l.lbz r%d, r%d, %d\n", rd
, ra
, I16
);
874 TCGv t0
= tcg_temp_new();
875 tcg_gen_addi_tl(t0
, cpu_R
[ra
], sign_extend(I16
, 16));
876 tcg_gen_qemu_ld8u(cpu_R
[rd
], t0
, dc
->mem_idx
);
881 case 0x24: /* l.lbs */
882 LOG_DIS("l.lbs r%d, r%d, %d\n", rd
, ra
, I16
);
884 TCGv t0
= tcg_temp_new();
885 tcg_gen_addi_tl(t0
, cpu_R
[ra
], sign_extend(I16
, 16));
886 tcg_gen_qemu_ld8s(cpu_R
[rd
], t0
, dc
->mem_idx
);
891 case 0x25: /* l.lhz */
892 LOG_DIS("l.lhz r%d, r%d, %d\n", rd
, ra
, I16
);
894 TCGv t0
= tcg_temp_new();
895 tcg_gen_addi_tl(t0
, cpu_R
[ra
], sign_extend(I16
, 16));
896 tcg_gen_qemu_ld16u(cpu_R
[rd
], t0
, dc
->mem_idx
);
901 case 0x26: /* l.lhs */
902 LOG_DIS("l.lhs r%d, r%d, %d\n", rd
, ra
, I16
);
904 TCGv t0
= tcg_temp_new();
905 tcg_gen_addi_tl(t0
, cpu_R
[ra
], sign_extend(I16
, 16));
906 tcg_gen_qemu_ld16s(cpu_R
[rd
], t0
, dc
->mem_idx
);
911 case 0x27: /* l.addi */
912 LOG_DIS("l.addi r%d, r%d, %d\n", rd
, ra
, I16
);
915 tcg_gen_mov_tl(cpu_R
[rd
], cpu_R
[ra
]);
917 int lab
= gen_new_label();
918 TCGv_i64 ta
= tcg_temp_new_i64();
919 TCGv_i64 td
= tcg_temp_local_new_i64();
920 TCGv_i32 res
= tcg_temp_local_new_i32();
921 TCGv_i32 sr_ove
= tcg_temp_local_new_i32();
922 tcg_gen_extu_i32_i64(ta
, cpu_R
[ra
]);
923 tcg_gen_addi_i64(td
, ta
, sign_extend(I16
, 16));
924 tcg_gen_trunc_i64_i32(res
, td
);
925 tcg_gen_shri_i64(td
, td
, 32);
926 tcg_gen_andi_i64(td
, td
, 0x3);
927 /* Jump to lab when no overflow. */
928 tcg_gen_brcondi_i64(TCG_COND_EQ
, td
, 0x0, lab
);
929 tcg_gen_brcondi_i64(TCG_COND_EQ
, td
, 0x3, lab
);
930 tcg_gen_ori_i32(cpu_sr
, cpu_sr
, (SR_OV
| SR_CY
));
931 tcg_gen_andi_i32(sr_ove
, cpu_sr
, SR_OVE
);
932 tcg_gen_brcondi_i32(TCG_COND_NE
, sr_ove
, SR_OVE
, lab
);
933 gen_exception(dc
, EXCP_RANGE
);
935 tcg_gen_mov_i32(cpu_R
[rd
], res
);
936 tcg_temp_free_i64(ta
);
937 tcg_temp_free_i64(td
);
938 tcg_temp_free_i32(res
);
939 tcg_temp_free_i32(sr_ove
);
944 case 0x28: /* l.addic */
945 LOG_DIS("l.addic r%d, r%d, %d\n", rd
, ra
, I16
);
947 int lab
= gen_new_label();
948 TCGv_i64 ta
= tcg_temp_new_i64();
949 TCGv_i64 td
= tcg_temp_local_new_i64();
950 TCGv_i64 tcy
= tcg_temp_local_new_i64();
951 TCGv_i32 res
= tcg_temp_local_new_i32();
952 TCGv_i32 sr_cy
= tcg_temp_local_new_i32();
953 TCGv_i32 sr_ove
= tcg_temp_local_new_i32();
954 tcg_gen_extu_i32_i64(ta
, cpu_R
[ra
]);
955 tcg_gen_andi_i32(sr_cy
, cpu_sr
, SR_CY
);
956 tcg_gen_shri_i32(sr_cy
, sr_cy
, 10);
957 tcg_gen_extu_i32_i64(tcy
, sr_cy
);
958 tcg_gen_addi_i64(td
, ta
, sign_extend(I16
, 16));
959 tcg_gen_add_i64(td
, td
, tcy
);
960 tcg_gen_trunc_i64_i32(res
, td
);
961 tcg_gen_shri_i64(td
, td
, 32);
962 tcg_gen_andi_i64(td
, td
, 0x3);
963 /* Jump to lab when no overflow. */
964 tcg_gen_brcondi_i64(TCG_COND_EQ
, td
, 0x0, lab
);
965 tcg_gen_brcondi_i64(TCG_COND_EQ
, td
, 0x3, lab
);
966 tcg_gen_ori_i32(cpu_sr
, cpu_sr
, (SR_OV
| SR_CY
));
967 tcg_gen_andi_i32(sr_ove
, cpu_sr
, SR_OVE
);
968 tcg_gen_brcondi_i32(TCG_COND_NE
, sr_ove
, SR_OVE
, lab
);
969 gen_exception(dc
, EXCP_RANGE
);
971 tcg_gen_mov_i32(cpu_R
[rd
], res
);
972 tcg_temp_free_i64(ta
);
973 tcg_temp_free_i64(td
);
974 tcg_temp_free_i64(tcy
);
975 tcg_temp_free_i32(res
);
976 tcg_temp_free_i32(sr_cy
);
977 tcg_temp_free_i32(sr_ove
);
981 case 0x29: /* l.andi */
982 LOG_DIS("l.andi r%d, r%d, %d\n", rd
, ra
, I16
);
983 tcg_gen_andi_tl(cpu_R
[rd
], cpu_R
[ra
], zero_extend(I16
, 16));
986 case 0x2a: /* l.ori */
987 LOG_DIS("l.ori r%d, r%d, %d\n", rd
, ra
, I16
);
988 tcg_gen_ori_tl(cpu_R
[rd
], cpu_R
[ra
], zero_extend(I16
, 16));
991 case 0x2b: /* l.xori */
992 LOG_DIS("l.xori r%d, r%d, %d\n", rd
, ra
, I16
);
993 tcg_gen_xori_tl(cpu_R
[rd
], cpu_R
[ra
], sign_extend(I16
, 16));
996 case 0x2c: /* l.muli */
997 LOG_DIS("l.muli r%d, r%d, %d\n", rd
, ra
, I16
);
998 if (ra
!= 0 && I16
!= 0) {
999 TCGv_i32 im
= tcg_const_i32(I16
);
1000 gen_helper_mul32(cpu_R
[rd
], cpu_env
, cpu_R
[ra
], im
);
1001 tcg_temp_free_i32(im
);
1003 tcg_gen_movi_tl(cpu_R
[rd
], 0x0);
1007 case 0x2d: /* l.mfspr */
1008 LOG_DIS("l.mfspr r%d, r%d, %d\n", rd
, ra
, I16
);
1010 #if defined(CONFIG_USER_ONLY)
1013 TCGv_i32 ti
= tcg_const_i32(I16
);
1014 if (dc
->mem_idx
== MMU_USER_IDX
) {
1015 gen_illegal_exception(dc
);
1018 gen_helper_mfspr(cpu_R
[rd
], cpu_env
, cpu_R
[rd
], cpu_R
[ra
], ti
);
1019 tcg_temp_free_i32(ti
);
1024 case 0x30: /* l.mtspr */
1025 LOG_DIS("l.mtspr %d, r%d, r%d, %d\n", I5
, ra
, rb
, I11
);
1027 #if defined(CONFIG_USER_ONLY)
1030 TCGv_i32 im
= tcg_const_i32(tmp
);
1031 if (dc
->mem_idx
== MMU_USER_IDX
) {
1032 gen_illegal_exception(dc
);
1035 gen_helper_mtspr(cpu_env
, cpu_R
[ra
], cpu_R
[rb
], im
);
1036 tcg_temp_free_i32(im
);
1041 /* not used yet, open it when we need or64. */
1042 /*#ifdef TARGET_OPENRISC64
1044 LOG_DIS("l.sd %d, r%d, r%d, %d\n", I5, ra, rb, I11);
1047 TCGv_i64 t0 = tcg_temp_new_i64();
1048 tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(tmp, 16));
1049 tcg_gen_qemu_st64(cpu_R[rb], t0, dc->mem_idx);
1050 tcg_temp_free_i64(t0);
1055 case 0x35: /* l.sw */
1056 LOG_DIS("l.sw %d, r%d, r%d, %d\n", I5
, ra
, rb
, I11
);
1058 TCGv t0
= tcg_temp_new();
1059 tcg_gen_addi_tl(t0
, cpu_R
[ra
], sign_extend(tmp
, 16));
1060 tcg_gen_qemu_st32(cpu_R
[rb
], t0
, dc
->mem_idx
);
1065 case 0x36: /* l.sb */
1066 LOG_DIS("l.sb %d, r%d, r%d, %d\n", I5
, ra
, rb
, I11
);
1068 TCGv t0
= tcg_temp_new();
1069 tcg_gen_addi_tl(t0
, cpu_R
[ra
], sign_extend(tmp
, 16));
1070 tcg_gen_qemu_st8(cpu_R
[rb
], t0
, dc
->mem_idx
);
1075 case 0x37: /* l.sh */
1076 LOG_DIS("l.sh %d, r%d, r%d, %d\n", I5
, ra
, rb
, I11
);
1078 TCGv t0
= tcg_temp_new();
1079 tcg_gen_addi_tl(t0
, cpu_R
[ra
], sign_extend(tmp
, 16));
1080 tcg_gen_qemu_st16(cpu_R
[rb
], t0
, dc
->mem_idx
);
1086 gen_illegal_exception(dc
);
1091 static void dec_mac(DisasContext
*dc
, uint32_t insn
)
1095 op0
= extract32(insn
, 0, 4);
1096 ra
= extract32(insn
, 16, 5);
1097 rb
= extract32(insn
, 11, 5);
1100 case 0x0001: /* l.mac */
1101 LOG_DIS("l.mac r%d, r%d\n", ra
, rb
);
1103 TCGv_i32 t0
= tcg_temp_new_i32();
1104 TCGv_i64 t1
= tcg_temp_new_i64();
1105 TCGv_i64 t2
= tcg_temp_new_i64();
1106 tcg_gen_mul_tl(t0
, cpu_R
[ra
], cpu_R
[rb
]);
1107 tcg_gen_ext_i32_i64(t1
, t0
);
1108 tcg_gen_concat_i32_i64(t2
, maclo
, machi
);
1109 tcg_gen_add_i64(t2
, t2
, t1
);
1110 tcg_gen_trunc_i64_i32(maclo
, t2
);
1111 tcg_gen_shri_i64(t2
, t2
, 32);
1112 tcg_gen_trunc_i64_i32(machi
, t2
);
1113 tcg_temp_free_i32(t0
);
1114 tcg_temp_free_i64(t1
);
1115 tcg_temp_free_i64(t2
);
1119 case 0x0002: /* l.msb */
1120 LOG_DIS("l.msb r%d, r%d\n", ra
, rb
);
1122 TCGv_i32 t0
= tcg_temp_new_i32();
1123 TCGv_i64 t1
= tcg_temp_new_i64();
1124 TCGv_i64 t2
= tcg_temp_new_i64();
1125 tcg_gen_mul_tl(t0
, cpu_R
[ra
], cpu_R
[rb
]);
1126 tcg_gen_ext_i32_i64(t1
, t0
);
1127 tcg_gen_concat_i32_i64(t2
, maclo
, machi
);
1128 tcg_gen_sub_i64(t2
, t2
, t1
);
1129 tcg_gen_trunc_i64_i32(maclo
, t2
);
1130 tcg_gen_shri_i64(t2
, t2
, 32);
1131 tcg_gen_trunc_i64_i32(machi
, t2
);
1132 tcg_temp_free_i32(t0
);
1133 tcg_temp_free_i64(t1
);
1134 tcg_temp_free_i64(t2
);
1139 gen_illegal_exception(dc
);
1144 static void dec_logic(DisasContext
*dc
, uint32_t insn
)
1147 uint32_t rd
, ra
, L6
;
1148 op0
= extract32(insn
, 6, 2);
1149 rd
= extract32(insn
, 21, 5);
1150 ra
= extract32(insn
, 16, 5);
1151 L6
= extract32(insn
, 0, 6);
1154 case 0x00: /* l.slli */
1155 LOG_DIS("l.slli r%d, r%d, %d\n", rd
, ra
, L6
);
1156 tcg_gen_shli_tl(cpu_R
[rd
], cpu_R
[ra
], (L6
& 0x1f));
1159 case 0x01: /* l.srli */
1160 LOG_DIS("l.srli r%d, r%d, %d\n", rd
, ra
, L6
);
1161 tcg_gen_shri_tl(cpu_R
[rd
], cpu_R
[ra
], (L6
& 0x1f));
1164 case 0x02: /* l.srai */
1165 LOG_DIS("l.srai r%d, r%d, %d\n", rd
, ra
, L6
);
1166 tcg_gen_sari_tl(cpu_R
[rd
], cpu_R
[ra
], (L6
& 0x1f)); break;
1168 case 0x03: /* l.rori */
1169 LOG_DIS("l.rori r%d, r%d, %d\n", rd
, ra
, L6
);
1170 tcg_gen_rotri_tl(cpu_R
[rd
], cpu_R
[ra
], (L6
& 0x1f));
1174 gen_illegal_exception(dc
);
1179 static void dec_M(DisasContext
*dc
, uint32_t insn
)
1184 op0
= extract32(insn
, 16, 1);
1185 rd
= extract32(insn
, 21, 5);
1186 K16
= extract32(insn
, 0, 16);
1189 case 0x0: /* l.movhi */
1190 LOG_DIS("l.movhi r%d, %d\n", rd
, K16
);
1191 tcg_gen_movi_tl(cpu_R
[rd
], (K16
<< 16));
1194 case 0x1: /* l.macrc */
1195 LOG_DIS("l.macrc r%d\n", rd
);
1196 tcg_gen_mov_tl(cpu_R
[rd
], maclo
);
1197 tcg_gen_movi_tl(maclo
, 0x0);
1198 tcg_gen_movi_tl(machi
, 0x0);
1202 gen_illegal_exception(dc
);
1207 static void dec_comp(DisasContext
*dc
, uint32_t insn
)
1212 op0
= extract32(insn
, 21, 5);
1213 ra
= extract32(insn
, 16, 5);
1214 rb
= extract32(insn
, 11, 5);
1216 tcg_gen_movi_i32(env_btaken
, 0x0);
1217 /* unsigned integers */
1218 tcg_gen_ext32u_tl(cpu_R
[ra
], cpu_R
[ra
]);
1219 tcg_gen_ext32u_tl(cpu_R
[rb
], cpu_R
[rb
]);
1222 case 0x0: /* l.sfeq */
1223 LOG_DIS("l.sfeq r%d, r%d\n", ra
, rb
);
1224 tcg_gen_setcond_tl(TCG_COND_EQ
, env_btaken
, cpu_R
[ra
], cpu_R
[rb
]);
1227 case 0x1: /* l.sfne */
1228 LOG_DIS("l.sfne r%d, r%d\n", ra
, rb
);
1229 tcg_gen_setcond_tl(TCG_COND_NE
, env_btaken
, cpu_R
[ra
], cpu_R
[rb
]);
1232 case 0x2: /* l.sfgtu */
1233 LOG_DIS("l.sfgtu r%d, r%d\n", ra
, rb
);
1234 tcg_gen_setcond_tl(TCG_COND_GTU
, env_btaken
, cpu_R
[ra
], cpu_R
[rb
]);
1237 case 0x3: /* l.sfgeu */
1238 LOG_DIS("l.sfgeu r%d, r%d\n", ra
, rb
);
1239 tcg_gen_setcond_tl(TCG_COND_GEU
, env_btaken
, cpu_R
[ra
], cpu_R
[rb
]);
1242 case 0x4: /* l.sfltu */
1243 LOG_DIS("l.sfltu r%d, r%d\n", ra
, rb
);
1244 tcg_gen_setcond_tl(TCG_COND_LTU
, env_btaken
, cpu_R
[ra
], cpu_R
[rb
]);
1247 case 0x5: /* l.sfleu */
1248 LOG_DIS("l.sfleu r%d, r%d\n", ra
, rb
);
1249 tcg_gen_setcond_tl(TCG_COND_LEU
, env_btaken
, cpu_R
[ra
], cpu_R
[rb
]);
1252 case 0xa: /* l.sfgts */
1253 LOG_DIS("l.sfgts r%d, r%d\n", ra
, rb
);
1254 tcg_gen_setcond_tl(TCG_COND_GT
, env_btaken
, cpu_R
[ra
], cpu_R
[rb
]);
1257 case 0xb: /* l.sfges */
1258 LOG_DIS("l.sfges r%d, r%d\n", ra
, rb
);
1259 tcg_gen_setcond_tl(TCG_COND_GE
, env_btaken
, cpu_R
[ra
], cpu_R
[rb
]);
1262 case 0xc: /* l.sflts */
1263 LOG_DIS("l.sflts r%d, r%d\n", ra
, rb
);
1264 tcg_gen_setcond_tl(TCG_COND_LT
, env_btaken
, cpu_R
[ra
], cpu_R
[rb
]);
1267 case 0xd: /* l.sfles */
1268 LOG_DIS("l.sfles r%d, r%d\n", ra
, rb
);
1269 tcg_gen_setcond_tl(TCG_COND_LE
, env_btaken
, cpu_R
[ra
], cpu_R
[rb
]);
1273 gen_illegal_exception(dc
);
1279 static void dec_compi(DisasContext
*dc
, uint32_t insn
)
1284 op0
= extract32(insn
, 21, 5);
1285 ra
= extract32(insn
, 16, 5);
1286 I16
= extract32(insn
, 0, 16);
1288 tcg_gen_movi_i32(env_btaken
, 0x0);
1289 I16
= sign_extend(I16
, 16);
1292 case 0x0: /* l.sfeqi */
1293 LOG_DIS("l.sfeqi r%d, %d\n", ra
, I16
);
1294 tcg_gen_setcondi_tl(TCG_COND_EQ
, env_btaken
, cpu_R
[ra
], I16
);
1297 case 0x1: /* l.sfnei */
1298 LOG_DIS("l.sfnei r%d, %d\n", ra
, I16
);
1299 tcg_gen_setcondi_tl(TCG_COND_NE
, env_btaken
, cpu_R
[ra
], I16
);
1302 case 0x2: /* l.sfgtui */
1303 LOG_DIS("l.sfgtui r%d, %d\n", ra
, I16
);
1304 tcg_gen_setcondi_tl(TCG_COND_GTU
, env_btaken
, cpu_R
[ra
], I16
);
1307 case 0x3: /* l.sfgeui */
1308 LOG_DIS("l.sfgeui r%d, %d\n", ra
, I16
);
1309 tcg_gen_setcondi_tl(TCG_COND_GEU
, env_btaken
, cpu_R
[ra
], I16
);
1312 case 0x4: /* l.sfltui */
1313 LOG_DIS("l.sfltui r%d, %d\n", ra
, I16
);
1314 tcg_gen_setcondi_tl(TCG_COND_LTU
, env_btaken
, cpu_R
[ra
], I16
);
1317 case 0x5: /* l.sfleui */
1318 LOG_DIS("l.sfleui r%d, %d\n", ra
, I16
);
1319 tcg_gen_setcondi_tl(TCG_COND_LEU
, env_btaken
, cpu_R
[ra
], I16
);
1322 case 0xa: /* l.sfgtsi */
1323 LOG_DIS("l.sfgtsi r%d, %d\n", ra
, I16
);
1324 tcg_gen_setcondi_tl(TCG_COND_GT
, env_btaken
, cpu_R
[ra
], I16
);
1327 case 0xb: /* l.sfgesi */
1328 LOG_DIS("l.sfgesi r%d, %d\n", ra
, I16
);
1329 tcg_gen_setcondi_tl(TCG_COND_GE
, env_btaken
, cpu_R
[ra
], I16
);
1332 case 0xc: /* l.sfltsi */
1333 LOG_DIS("l.sfltsi r%d, %d\n", ra
, I16
);
1334 tcg_gen_setcondi_tl(TCG_COND_LT
, env_btaken
, cpu_R
[ra
], I16
);
1337 case 0xd: /* l.sflesi */
1338 LOG_DIS("l.sflesi r%d, %d\n", ra
, I16
);
1339 tcg_gen_setcondi_tl(TCG_COND_LE
, env_btaken
, cpu_R
[ra
], I16
);
1343 gen_illegal_exception(dc
);
1349 static void dec_sys(DisasContext
*dc
, uint32_t insn
)
1352 #ifdef OPENRISC_DISAS
1355 op0
= extract32(insn
, 16, 8);
1356 #ifdef OPENRISC_DISAS
1357 K16
= extract32(insn
, 0, 16);
1361 case 0x000: /* l.sys */
1362 LOG_DIS("l.sys %d\n", K16
);
1363 tcg_gen_movi_tl(cpu_pc
, dc
->pc
);
1364 gen_exception(dc
, EXCP_SYSCALL
);
1365 dc
->is_jmp
= DISAS_UPDATE
;
1368 case 0x100: /* l.trap */
1369 LOG_DIS("l.trap %d\n", K16
);
1370 #if defined(CONFIG_USER_ONLY)
1373 if (dc
->mem_idx
== MMU_USER_IDX
) {
1374 gen_illegal_exception(dc
);
1377 tcg_gen_movi_tl(cpu_pc
, dc
->pc
);
1378 gen_exception(dc
, EXCP_TRAP
);
1382 case 0x300: /* l.csync */
1383 LOG_DIS("l.csync\n");
1384 #if defined(CONFIG_USER_ONLY)
1387 if (dc
->mem_idx
== MMU_USER_IDX
) {
1388 gen_illegal_exception(dc
);
1394 case 0x200: /* l.msync */
1395 LOG_DIS("l.msync\n");
1396 #if defined(CONFIG_USER_ONLY)
1399 if (dc
->mem_idx
== MMU_USER_IDX
) {
1400 gen_illegal_exception(dc
);
1406 case 0x270: /* l.psync */
1407 LOG_DIS("l.psync\n");
1408 #if defined(CONFIG_USER_ONLY)
1411 if (dc
->mem_idx
== MMU_USER_IDX
) {
1412 gen_illegal_exception(dc
);
1419 gen_illegal_exception(dc
);
1424 static void dec_float(DisasContext
*dc
, uint32_t insn
)
1427 uint32_t ra
, rb
, rd
;
1428 op0
= extract32(insn
, 0, 8);
1429 ra
= extract32(insn
, 16, 5);
1430 rb
= extract32(insn
, 11, 5);
1431 rd
= extract32(insn
, 21, 5);
1434 case 0x00: /* lf.add.s */
1435 LOG_DIS("lf.add.s r%d, r%d, r%d\n", rd
, ra
, rb
);
1436 gen_helper_float_add_s(cpu_R
[rd
], cpu_env
, cpu_R
[ra
], cpu_R
[rb
]);
1439 case 0x01: /* lf.sub.s */
1440 LOG_DIS("lf.sub.s r%d, r%d, r%d\n", rd
, ra
, rb
);
1441 gen_helper_float_sub_s(cpu_R
[rd
], cpu_env
, cpu_R
[ra
], cpu_R
[rb
]);
1445 case 0x02: /* lf.mul.s */
1446 LOG_DIS("lf.mul.s r%d, r%d, r%d\n", rd
, ra
, rb
);
1447 if (ra
!= 0 && rb
!= 0) {
1448 gen_helper_float_mul_s(cpu_R
[rd
], cpu_env
, cpu_R
[ra
], cpu_R
[rb
]);
1450 tcg_gen_ori_tl(fpcsr
, fpcsr
, FPCSR_ZF
);
1451 tcg_gen_movi_i32(cpu_R
[rd
], 0x0);
1455 case 0x03: /* lf.div.s */
1456 LOG_DIS("lf.div.s r%d, r%d, r%d\n", rd
, ra
, rb
);
1457 gen_helper_float_div_s(cpu_R
[rd
], cpu_env
, cpu_R
[ra
], cpu_R
[rb
]);
1460 case 0x04: /* lf.itof.s */
1461 LOG_DIS("lf.itof r%d, r%d\n", rd
, ra
);
1462 gen_helper_itofs(cpu_R
[rd
], cpu_env
, cpu_R
[ra
]);
1465 case 0x05: /* lf.ftoi.s */
1466 LOG_DIS("lf.ftoi r%d, r%d\n", rd
, ra
);
1467 gen_helper_ftois(cpu_R
[rd
], cpu_env
, cpu_R
[ra
]);
1470 case 0x06: /* lf.rem.s */
1471 LOG_DIS("lf.rem.s r%d, r%d, r%d\n", rd
, ra
, rb
);
1472 gen_helper_float_rem_s(cpu_R
[rd
], cpu_env
, cpu_R
[ra
], cpu_R
[rb
]);
1475 case 0x07: /* lf.madd.s */
1476 LOG_DIS("lf.madd.s r%d, r%d, r%d\n", rd
, ra
, rb
);
1477 gen_helper_float_muladd_s(cpu_R
[rd
], cpu_env
, cpu_R
[ra
], cpu_R
[rb
]);
1480 case 0x08: /* lf.sfeq.s */
1481 LOG_DIS("lf.sfeq.s r%d, r%d\n", ra
, rb
);
1482 gen_helper_float_eq_s(env_btaken
, cpu_env
, cpu_R
[ra
], cpu_R
[rb
]);
1485 case 0x09: /* lf.sfne.s */
1486 LOG_DIS("lf.sfne.s r%d, r%d\n", ra
, rb
);
1487 gen_helper_float_ne_s(env_btaken
, cpu_env
, cpu_R
[ra
], cpu_R
[rb
]);
1490 case 0x0a: /* lf.sfgt.s */
1491 LOG_DIS("lf.sfgt.s r%d, r%d\n", ra
, rb
);
1492 gen_helper_float_gt_s(env_btaken
, cpu_env
, cpu_R
[ra
], cpu_R
[rb
]);
1495 case 0x0b: /* lf.sfge.s */
1496 LOG_DIS("lf.sfge.s r%d, r%d\n", ra
, rb
);
1497 gen_helper_float_ge_s(env_btaken
, cpu_env
, cpu_R
[ra
], cpu_R
[rb
]);
1500 case 0x0c: /* lf.sflt.s */
1501 LOG_DIS("lf.sflt.s r%d, r%d\n", ra
, rb
);
1502 gen_helper_float_lt_s(env_btaken
, cpu_env
, cpu_R
[ra
], cpu_R
[rb
]);
1505 case 0x0d: /* lf.sfle.s */
1506 LOG_DIS("lf.sfle.s r%d, r%d\n", ra
, rb
);
1507 gen_helper_float_le_s(env_btaken
, cpu_env
, cpu_R
[ra
], cpu_R
[rb
]);
1510 /* not used yet, open it when we need or64. */
1511 /*#ifdef TARGET_OPENRISC64
1513 LOG_DIS("lf.add.d r%d, r%d, r%d\n", rd, ra, rb);
1515 gen_helper_float_add_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]);
1519 LOG_DIS("lf.sub.d r%d, r%d, r%d\n", rd, ra, rb);
1521 gen_helper_float_sub_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]);
1525 LOG_DIS("lf.mul.d r%d, r%d, r%d\n", rd, ra, rb);
1527 if (ra != 0 && rb != 0) {
1528 gen_helper_float_mul_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]);
1530 tcg_gen_ori_tl(fpcsr, fpcsr, FPCSR_ZF);
1531 tcg_gen_movi_i64(cpu_R[rd], 0x0);
1536 LOG_DIS("lf.div.d r%d, r%d, r%d\n", rd, ra, rb);
1538 gen_helper_float_div_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]);
1541 case 0x14: lf.itof.d
1542 LOG_DIS("lf.itof r%d, r%d\n", rd, ra);
1544 gen_helper_itofd(cpu_R[rd], cpu_env, cpu_R[ra]);
1547 case 0x15: lf.ftoi.d
1548 LOG_DIS("lf.ftoi r%d, r%d\n", rd, ra);
1550 gen_helper_ftoid(cpu_R[rd], cpu_env, cpu_R[ra]);
1554 LOG_DIS("lf.rem.d r%d, r%d, r%d\n", rd, ra, rb);
1556 gen_helper_float_rem_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]);
1559 case 0x17: lf.madd.d
1560 LOG_DIS("lf.madd.d r%d, r%d, r%d\n", rd, ra, rb);
1562 gen_helper_float_muladd_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]);
1565 case 0x18: lf.sfeq.d
1566 LOG_DIS("lf.sfeq.d r%d, r%d\n", ra, rb);
1568 gen_helper_float_eq_d(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]);
1571 case 0x1a: lf.sfgt.d
1572 LOG_DIS("lf.sfgt.d r%d, r%d\n", ra, rb);
1574 gen_helper_float_gt_d(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]);
1577 case 0x1b: lf.sfge.d
1578 LOG_DIS("lf.sfge.d r%d, r%d\n", ra, rb);
1580 gen_helper_float_ge_d(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]);
1583 case 0x19: lf.sfne.d
1584 LOG_DIS("lf.sfne.d r%d, r%d\n", ra, rb);
1586 gen_helper_float_ne_d(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]);
1589 case 0x1c: lf.sflt.d
1590 LOG_DIS("lf.sflt.d r%d, r%d\n", ra, rb);
1592 gen_helper_float_lt_d(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]);
1595 case 0x1d: lf.sfle.d
1596 LOG_DIS("lf.sfle.d r%d, r%d\n", ra, rb);
1598 gen_helper_float_le_d(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]);
1603 gen_illegal_exception(dc
);
1609 static void disas_openrisc_insn(DisasContext
*dc
, OpenRISCCPU
*cpu
)
1613 insn
= cpu_ldl_code(&cpu
->env
, dc
->pc
);
1614 op0
= extract32(insn
, 26, 6);
1626 dec_logic(dc
, insn
);
1630 dec_compi(dc
, insn
);
1638 dec_float(dc
, insn
);
1655 static void check_breakpoint(OpenRISCCPU
*cpu
, DisasContext
*dc
)
1659 if (unlikely(!QTAILQ_EMPTY(&cpu
->env
.breakpoints
))) {
1660 QTAILQ_FOREACH(bp
, &cpu
->env
.breakpoints
, entry
) {
1661 if (bp
->pc
== dc
->pc
) {
1662 tcg_gen_movi_tl(cpu_pc
, dc
->pc
);
1663 gen_exception(dc
, EXCP_DEBUG
);
1664 dc
->is_jmp
= DISAS_UPDATE
;
1670 static inline void gen_intermediate_code_internal(OpenRISCCPU
*cpu
,
1671 TranslationBlock
*tb
,
1674 CPUState
*cs
= CPU(cpu
);
1675 struct DisasContext ctx
, *dc
= &ctx
;
1676 uint16_t *gen_opc_end
;
1679 uint32_t next_page_start
;
1686 gen_opc_end
= tcg_ctx
.gen_opc_buf
+ OPC_MAX_SIZE
;
1687 dc
->is_jmp
= DISAS_NEXT
;
1690 dc
->flags
= cpu
->env
.cpucfgr
;
1691 dc
->mem_idx
= cpu_mmu_index(&cpu
->env
);
1692 dc
->synced_flags
= dc
->tb_flags
= tb
->flags
;
1693 dc
->delayed_branch
= !!(dc
->tb_flags
& D_FLAG
);
1694 dc
->singlestep_enabled
= cs
->singlestep_enabled
;
1695 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
1696 qemu_log("-----------------------------------------\n");
1697 log_cpu_state(CPU(cpu
), 0);
1700 next_page_start
= (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
1703 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
1705 if (max_insns
== 0) {
1706 max_insns
= CF_COUNT_MASK
;
1712 check_breakpoint(cpu
, dc
);
1714 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
1718 tcg_ctx
.gen_opc_instr_start
[k
++] = 0;
1721 tcg_ctx
.gen_opc_pc
[k
] = dc
->pc
;
1722 tcg_ctx
.gen_opc_instr_start
[k
] = 1;
1723 tcg_ctx
.gen_opc_icount
[k
] = num_insns
;
1726 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
1727 tcg_gen_debug_insn_start(dc
->pc
);
1730 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
1733 dc
->ppc
= dc
->pc
- 4;
1734 dc
->npc
= dc
->pc
+ 4;
1735 tcg_gen_movi_tl(cpu_ppc
, dc
->ppc
);
1736 tcg_gen_movi_tl(cpu_npc
, dc
->npc
);
1737 disas_openrisc_insn(dc
, cpu
);
1741 if (dc
->delayed_branch
) {
1742 dc
->delayed_branch
--;
1743 if (!dc
->delayed_branch
) {
1744 dc
->tb_flags
&= ~D_FLAG
;
1746 tcg_gen_mov_tl(cpu_pc
, jmp_pc
);
1747 tcg_gen_mov_tl(cpu_npc
, jmp_pc
);
1748 tcg_gen_movi_tl(jmp_pc
, 0);
1750 dc
->is_jmp
= DISAS_JUMP
;
1754 } while (!dc
->is_jmp
1755 && tcg_ctx
.gen_opc_ptr
< gen_opc_end
1756 && !cs
->singlestep_enabled
1758 && (dc
->pc
< next_page_start
)
1759 && num_insns
< max_insns
);
1761 if (tb
->cflags
& CF_LAST_IO
) {
1764 if (dc
->is_jmp
== DISAS_NEXT
) {
1765 dc
->is_jmp
= DISAS_UPDATE
;
1766 tcg_gen_movi_tl(cpu_pc
, dc
->pc
);
1768 if (unlikely(cs
->singlestep_enabled
)) {
1769 if (dc
->is_jmp
== DISAS_NEXT
) {
1770 tcg_gen_movi_tl(cpu_pc
, dc
->pc
);
1772 gen_exception(dc
, EXCP_DEBUG
);
1774 switch (dc
->is_jmp
) {
1776 gen_goto_tb(dc
, 0, dc
->pc
);
1782 /* indicate that the hash table must be used
1783 to find the next TB */
1787 /* nothing more to generate */
1792 gen_tb_end(tb
, num_insns
);
1793 *tcg_ctx
.gen_opc_ptr
= INDEX_op_end
;
1795 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
1798 tcg_ctx
.gen_opc_instr_start
[k
++] = 0;
1801 tb
->size
= dc
->pc
- pc_start
;
1802 tb
->icount
= num_insns
;
1806 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
1808 log_target_disas(&cpu
->env
, pc_start
, dc
->pc
- pc_start
, 0);
1809 qemu_log("\nisize=%d osize=%td\n",
1810 dc
->pc
- pc_start
, tcg_ctx
.gen_opc_ptr
-
1811 tcg_ctx
.gen_opc_buf
);
1816 void gen_intermediate_code(CPUOpenRISCState
*env
, struct TranslationBlock
*tb
)
1818 gen_intermediate_code_internal(openrisc_env_get_cpu(env
), tb
, 0);
1821 void gen_intermediate_code_pc(CPUOpenRISCState
*env
,
1822 struct TranslationBlock
*tb
)
1824 gen_intermediate_code_internal(openrisc_env_get_cpu(env
), tb
, 1);
1827 void openrisc_cpu_dump_state(CPUState
*cs
, FILE *f
,
1828 fprintf_function cpu_fprintf
,
1831 OpenRISCCPU
*cpu
= OPENRISC_CPU(cs
);
1832 CPUOpenRISCState
*env
= &cpu
->env
;
1835 cpu_fprintf(f
, "PC=%08x\n", env
->pc
);
1836 for (i
= 0; i
< 32; ++i
) {
1837 cpu_fprintf(f
, "R%02d=%08x%c", i
, env
->gpr
[i
],
1838 (i
% 4) == 3 ? '\n' : ' ');
1842 void restore_state_to_opc(CPUOpenRISCState
*env
, TranslationBlock
*tb
,
1845 env
->pc
= tcg_ctx
.gen_opc_pc
[pc_pos
];