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 #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 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
;
712 op0
= extract32(insn
, 26, 6);
713 op1
= extract32(insn
, 24, 2);
714 ra
= extract32(insn
, 16, 5);
715 rb
= extract32(insn
, 11, 5);
716 rd
= extract32(insn
, 21, 5);
717 #ifdef OPENRISC_DISAS
718 L6
= extract32(insn
, 5, 6);
719 K5
= extract32(insn
, 0, 5);
721 I16
= extract32(insn
, 0, 16);
722 I5
= extract32(insn
, 21, 5);
723 I11
= extract32(insn
, 0, 11);
724 N26
= extract32(insn
, 0, 26);
725 tmp
= (I5
<<11) + I11
;
729 LOG_DIS("l.j %d\n", N26
);
730 gen_jump(dc
, N26
, 0, op0
);
733 case 0x01: /* l.jal */
734 LOG_DIS("l.jal %d\n", N26
);
735 gen_jump(dc
, N26
, 0, op0
);
738 case 0x03: /* l.bnf */
739 LOG_DIS("l.bnf %d\n", N26
);
740 gen_jump(dc
, N26
, 0, op0
);
743 case 0x04: /* l.bf */
744 LOG_DIS("l.bf %d\n", N26
);
745 gen_jump(dc
, N26
, 0, op0
);
750 case 0x01: /* l.nop */
751 LOG_DIS("l.nop %d\n", I16
);
755 gen_illegal_exception(dc
);
760 case 0x11: /* l.jr */
761 LOG_DIS("l.jr r%d\n", rb
);
762 gen_jump(dc
, 0, rb
, op0
);
765 case 0x12: /* l.jalr */
766 LOG_DIS("l.jalr r%d\n", rb
);
767 gen_jump(dc
, 0, rb
, op0
);
770 case 0x13: /* l.maci */
771 LOG_DIS("l.maci %d, r%d, %d\n", I5
, ra
, I11
);
773 TCGv_i64 t1
= tcg_temp_new_i64();
774 TCGv_i64 t2
= tcg_temp_new_i64();
775 TCGv_i32 dst
= tcg_temp_new_i32();
776 TCGv ttmp
= tcg_const_tl(tmp
);
777 tcg_gen_mul_tl(dst
, cpu_R
[ra
], ttmp
);
778 tcg_gen_ext_i32_i64(t1
, dst
);
779 tcg_gen_concat_i32_i64(t2
, maclo
, machi
);
780 tcg_gen_add_i64(t2
, t2
, t1
);
781 tcg_gen_trunc_i64_i32(maclo
, t2
);
782 tcg_gen_shri_i64(t2
, t2
, 32);
783 tcg_gen_trunc_i64_i32(machi
, t2
);
784 tcg_temp_free_i32(dst
);
786 tcg_temp_free_i64(t1
);
787 tcg_temp_free_i64(t2
);
791 case 0x09: /* l.rfe */
794 #if defined(CONFIG_USER_ONLY)
797 if (dc
->mem_idx
== MMU_USER_IDX
) {
798 gen_illegal_exception(dc
);
801 gen_helper_rfe(cpu_env
);
802 dc
->is_jmp
= DISAS_UPDATE
;
807 case 0x1c: /* l.cust1 */
808 LOG_DIS("l.cust1\n");
811 case 0x1d: /* l.cust2 */
812 LOG_DIS("l.cust2\n");
815 case 0x1e: /* l.cust3 */
816 LOG_DIS("l.cust3\n");
819 case 0x1f: /* l.cust4 */
820 LOG_DIS("l.cust4\n");
823 case 0x3c: /* l.cust5 */
824 LOG_DIS("l.cust5 r%d, r%d, r%d, %d, %d\n", rd
, ra
, rb
, L6
, K5
);
827 case 0x3d: /* l.cust6 */
828 LOG_DIS("l.cust6\n");
831 case 0x3e: /* l.cust7 */
832 LOG_DIS("l.cust7\n");
835 case 0x3f: /* l.cust8 */
836 LOG_DIS("l.cust8\n");
839 /* not used yet, open it when we need or64. */
840 /*#ifdef TARGET_OPENRISC64
842 LOG_DIS("l.ld r%d, r%d, %d\n", rd, ra, I16);
848 case 0x21: /* l.lwz */
849 LOG_DIS("l.lwz r%d, r%d, %d\n", rd
, ra
, I16
);
853 case 0x22: /* l.lws */
854 LOG_DIS("l.lws r%d, r%d, %d\n", rd
, ra
, I16
);
858 case 0x23: /* l.lbz */
859 LOG_DIS("l.lbz r%d, r%d, %d\n", rd
, ra
, I16
);
863 case 0x24: /* l.lbs */
864 LOG_DIS("l.lbs r%d, r%d, %d\n", rd
, ra
, I16
);
868 case 0x25: /* l.lhz */
869 LOG_DIS("l.lhz r%d, r%d, %d\n", rd
, ra
, I16
);
873 case 0x26: /* l.lhs */
874 LOG_DIS("l.lhs r%d, r%d, %d\n", rd
, ra
, I16
);
880 TCGv t0
= tcg_temp_new();
881 tcg_gen_addi_tl(t0
, cpu_R
[ra
], sign_extend(I16
, 16));
882 tcg_gen_qemu_ld_tl(cpu_R
[rd
], t0
, dc
->mem_idx
, mop
);
887 case 0x27: /* l.addi */
888 LOG_DIS("l.addi r%d, r%d, %d\n", rd
, ra
, I16
);
891 tcg_gen_mov_tl(cpu_R
[rd
], cpu_R
[ra
]);
893 int lab
= gen_new_label();
894 TCGv_i64 ta
= tcg_temp_new_i64();
895 TCGv_i64 td
= tcg_temp_local_new_i64();
896 TCGv_i32 res
= tcg_temp_local_new_i32();
897 TCGv_i32 sr_ove
= tcg_temp_local_new_i32();
898 tcg_gen_extu_i32_i64(ta
, cpu_R
[ra
]);
899 tcg_gen_addi_i64(td
, ta
, sign_extend(I16
, 16));
900 tcg_gen_trunc_i64_i32(res
, td
);
901 tcg_gen_shri_i64(td
, td
, 32);
902 tcg_gen_andi_i64(td
, td
, 0x3);
903 /* Jump to lab when no overflow. */
904 tcg_gen_brcondi_i64(TCG_COND_EQ
, td
, 0x0, lab
);
905 tcg_gen_brcondi_i64(TCG_COND_EQ
, td
, 0x3, lab
);
906 tcg_gen_ori_i32(cpu_sr
, cpu_sr
, (SR_OV
| SR_CY
));
907 tcg_gen_andi_i32(sr_ove
, cpu_sr
, SR_OVE
);
908 tcg_gen_brcondi_i32(TCG_COND_NE
, sr_ove
, SR_OVE
, lab
);
909 gen_exception(dc
, EXCP_RANGE
);
911 tcg_gen_mov_i32(cpu_R
[rd
], res
);
912 tcg_temp_free_i64(ta
);
913 tcg_temp_free_i64(td
);
914 tcg_temp_free_i32(res
);
915 tcg_temp_free_i32(sr_ove
);
920 case 0x28: /* l.addic */
921 LOG_DIS("l.addic r%d, r%d, %d\n", rd
, ra
, I16
);
923 int lab
= gen_new_label();
924 TCGv_i64 ta
= tcg_temp_new_i64();
925 TCGv_i64 td
= tcg_temp_local_new_i64();
926 TCGv_i64 tcy
= tcg_temp_local_new_i64();
927 TCGv_i32 res
= tcg_temp_local_new_i32();
928 TCGv_i32 sr_cy
= tcg_temp_local_new_i32();
929 TCGv_i32 sr_ove
= tcg_temp_local_new_i32();
930 tcg_gen_extu_i32_i64(ta
, cpu_R
[ra
]);
931 tcg_gen_andi_i32(sr_cy
, cpu_sr
, SR_CY
);
932 tcg_gen_shri_i32(sr_cy
, sr_cy
, 10);
933 tcg_gen_extu_i32_i64(tcy
, sr_cy
);
934 tcg_gen_addi_i64(td
, ta
, sign_extend(I16
, 16));
935 tcg_gen_add_i64(td
, td
, tcy
);
936 tcg_gen_trunc_i64_i32(res
, td
);
937 tcg_gen_shri_i64(td
, td
, 32);
938 tcg_gen_andi_i64(td
, td
, 0x3);
939 /* Jump to lab when no overflow. */
940 tcg_gen_brcondi_i64(TCG_COND_EQ
, td
, 0x0, lab
);
941 tcg_gen_brcondi_i64(TCG_COND_EQ
, td
, 0x3, lab
);
942 tcg_gen_ori_i32(cpu_sr
, cpu_sr
, (SR_OV
| SR_CY
));
943 tcg_gen_andi_i32(sr_ove
, cpu_sr
, SR_OVE
);
944 tcg_gen_brcondi_i32(TCG_COND_NE
, sr_ove
, SR_OVE
, lab
);
945 gen_exception(dc
, EXCP_RANGE
);
947 tcg_gen_mov_i32(cpu_R
[rd
], res
);
948 tcg_temp_free_i64(ta
);
949 tcg_temp_free_i64(td
);
950 tcg_temp_free_i64(tcy
);
951 tcg_temp_free_i32(res
);
952 tcg_temp_free_i32(sr_cy
);
953 tcg_temp_free_i32(sr_ove
);
957 case 0x29: /* l.andi */
958 LOG_DIS("l.andi r%d, r%d, %d\n", rd
, ra
, I16
);
959 tcg_gen_andi_tl(cpu_R
[rd
], cpu_R
[ra
], zero_extend(I16
, 16));
962 case 0x2a: /* l.ori */
963 LOG_DIS("l.ori r%d, r%d, %d\n", rd
, ra
, I16
);
964 tcg_gen_ori_tl(cpu_R
[rd
], cpu_R
[ra
], zero_extend(I16
, 16));
967 case 0x2b: /* l.xori */
968 LOG_DIS("l.xori r%d, r%d, %d\n", rd
, ra
, I16
);
969 tcg_gen_xori_tl(cpu_R
[rd
], cpu_R
[ra
], sign_extend(I16
, 16));
972 case 0x2c: /* l.muli */
973 LOG_DIS("l.muli r%d, r%d, %d\n", rd
, ra
, I16
);
974 if (ra
!= 0 && I16
!= 0) {
975 TCGv_i32 im
= tcg_const_i32(I16
);
976 gen_helper_mul32(cpu_R
[rd
], cpu_env
, cpu_R
[ra
], im
);
977 tcg_temp_free_i32(im
);
979 tcg_gen_movi_tl(cpu_R
[rd
], 0x0);
983 case 0x2d: /* l.mfspr */
984 LOG_DIS("l.mfspr r%d, r%d, %d\n", rd
, ra
, I16
);
986 #if defined(CONFIG_USER_ONLY)
989 TCGv_i32 ti
= tcg_const_i32(I16
);
990 if (dc
->mem_idx
== MMU_USER_IDX
) {
991 gen_illegal_exception(dc
);
994 gen_helper_mfspr(cpu_R
[rd
], cpu_env
, cpu_R
[rd
], cpu_R
[ra
], ti
);
995 tcg_temp_free_i32(ti
);
1000 case 0x30: /* l.mtspr */
1001 LOG_DIS("l.mtspr %d, r%d, r%d, %d\n", I5
, ra
, rb
, I11
);
1003 #if defined(CONFIG_USER_ONLY)
1006 TCGv_i32 im
= tcg_const_i32(tmp
);
1007 if (dc
->mem_idx
== MMU_USER_IDX
) {
1008 gen_illegal_exception(dc
);
1011 gen_helper_mtspr(cpu_env
, cpu_R
[ra
], cpu_R
[rb
], im
);
1012 tcg_temp_free_i32(im
);
1017 /* not used yet, open it when we need or64. */
1018 /*#ifdef TARGET_OPENRISC64
1020 LOG_DIS("l.sd %d, r%d, r%d, %d\n", I5, ra, rb, I11);
1026 case 0x35: /* l.sw */
1027 LOG_DIS("l.sw %d, r%d, r%d, %d\n", I5
, ra
, rb
, I11
);
1031 case 0x36: /* l.sb */
1032 LOG_DIS("l.sb %d, r%d, r%d, %d\n", I5
, ra
, rb
, I11
);
1036 case 0x37: /* l.sh */
1037 LOG_DIS("l.sh %d, r%d, r%d, %d\n", I5
, ra
, rb
, I11
);
1043 TCGv t0
= tcg_temp_new();
1044 tcg_gen_addi_tl(t0
, cpu_R
[ra
], sign_extend(tmp
, 16));
1045 tcg_gen_qemu_st_tl(cpu_R
[rb
], t0
, dc
->mem_idx
, mop
);
1051 gen_illegal_exception(dc
);
1056 static void dec_mac(DisasContext
*dc
, uint32_t insn
)
1060 op0
= extract32(insn
, 0, 4);
1061 ra
= extract32(insn
, 16, 5);
1062 rb
= extract32(insn
, 11, 5);
1065 case 0x0001: /* l.mac */
1066 LOG_DIS("l.mac r%d, r%d\n", ra
, rb
);
1068 TCGv_i32 t0
= tcg_temp_new_i32();
1069 TCGv_i64 t1
= tcg_temp_new_i64();
1070 TCGv_i64 t2
= tcg_temp_new_i64();
1071 tcg_gen_mul_tl(t0
, cpu_R
[ra
], cpu_R
[rb
]);
1072 tcg_gen_ext_i32_i64(t1
, t0
);
1073 tcg_gen_concat_i32_i64(t2
, maclo
, machi
);
1074 tcg_gen_add_i64(t2
, t2
, t1
);
1075 tcg_gen_trunc_i64_i32(maclo
, t2
);
1076 tcg_gen_shri_i64(t2
, t2
, 32);
1077 tcg_gen_trunc_i64_i32(machi
, t2
);
1078 tcg_temp_free_i32(t0
);
1079 tcg_temp_free_i64(t1
);
1080 tcg_temp_free_i64(t2
);
1084 case 0x0002: /* l.msb */
1085 LOG_DIS("l.msb r%d, r%d\n", ra
, rb
);
1087 TCGv_i32 t0
= tcg_temp_new_i32();
1088 TCGv_i64 t1
= tcg_temp_new_i64();
1089 TCGv_i64 t2
= tcg_temp_new_i64();
1090 tcg_gen_mul_tl(t0
, cpu_R
[ra
], cpu_R
[rb
]);
1091 tcg_gen_ext_i32_i64(t1
, t0
);
1092 tcg_gen_concat_i32_i64(t2
, maclo
, machi
);
1093 tcg_gen_sub_i64(t2
, t2
, t1
);
1094 tcg_gen_trunc_i64_i32(maclo
, t2
);
1095 tcg_gen_shri_i64(t2
, t2
, 32);
1096 tcg_gen_trunc_i64_i32(machi
, t2
);
1097 tcg_temp_free_i32(t0
);
1098 tcg_temp_free_i64(t1
);
1099 tcg_temp_free_i64(t2
);
1104 gen_illegal_exception(dc
);
1109 static void dec_logic(DisasContext
*dc
, uint32_t insn
)
1112 uint32_t rd
, ra
, L6
;
1113 op0
= extract32(insn
, 6, 2);
1114 rd
= extract32(insn
, 21, 5);
1115 ra
= extract32(insn
, 16, 5);
1116 L6
= extract32(insn
, 0, 6);
1119 case 0x00: /* l.slli */
1120 LOG_DIS("l.slli r%d, r%d, %d\n", rd
, ra
, L6
);
1121 tcg_gen_shli_tl(cpu_R
[rd
], cpu_R
[ra
], (L6
& 0x1f));
1124 case 0x01: /* l.srli */
1125 LOG_DIS("l.srli r%d, r%d, %d\n", rd
, ra
, L6
);
1126 tcg_gen_shri_tl(cpu_R
[rd
], cpu_R
[ra
], (L6
& 0x1f));
1129 case 0x02: /* l.srai */
1130 LOG_DIS("l.srai r%d, r%d, %d\n", rd
, ra
, L6
);
1131 tcg_gen_sari_tl(cpu_R
[rd
], cpu_R
[ra
], (L6
& 0x1f)); break;
1133 case 0x03: /* l.rori */
1134 LOG_DIS("l.rori r%d, r%d, %d\n", rd
, ra
, L6
);
1135 tcg_gen_rotri_tl(cpu_R
[rd
], cpu_R
[ra
], (L6
& 0x1f));
1139 gen_illegal_exception(dc
);
1144 static void dec_M(DisasContext
*dc
, uint32_t insn
)
1149 op0
= extract32(insn
, 16, 1);
1150 rd
= extract32(insn
, 21, 5);
1151 K16
= extract32(insn
, 0, 16);
1154 case 0x0: /* l.movhi */
1155 LOG_DIS("l.movhi r%d, %d\n", rd
, K16
);
1156 tcg_gen_movi_tl(cpu_R
[rd
], (K16
<< 16));
1159 case 0x1: /* l.macrc */
1160 LOG_DIS("l.macrc r%d\n", rd
);
1161 tcg_gen_mov_tl(cpu_R
[rd
], maclo
);
1162 tcg_gen_movi_tl(maclo
, 0x0);
1163 tcg_gen_movi_tl(machi
, 0x0);
1167 gen_illegal_exception(dc
);
1172 static void dec_comp(DisasContext
*dc
, uint32_t insn
)
1177 op0
= extract32(insn
, 21, 5);
1178 ra
= extract32(insn
, 16, 5);
1179 rb
= extract32(insn
, 11, 5);
1181 tcg_gen_movi_i32(env_btaken
, 0x0);
1182 /* unsigned integers */
1183 tcg_gen_ext32u_tl(cpu_R
[ra
], cpu_R
[ra
]);
1184 tcg_gen_ext32u_tl(cpu_R
[rb
], cpu_R
[rb
]);
1187 case 0x0: /* l.sfeq */
1188 LOG_DIS("l.sfeq r%d, r%d\n", ra
, rb
);
1189 tcg_gen_setcond_tl(TCG_COND_EQ
, env_btaken
, cpu_R
[ra
], cpu_R
[rb
]);
1192 case 0x1: /* l.sfne */
1193 LOG_DIS("l.sfne r%d, r%d\n", ra
, rb
);
1194 tcg_gen_setcond_tl(TCG_COND_NE
, env_btaken
, cpu_R
[ra
], cpu_R
[rb
]);
1197 case 0x2: /* l.sfgtu */
1198 LOG_DIS("l.sfgtu r%d, r%d\n", ra
, rb
);
1199 tcg_gen_setcond_tl(TCG_COND_GTU
, env_btaken
, cpu_R
[ra
], cpu_R
[rb
]);
1202 case 0x3: /* l.sfgeu */
1203 LOG_DIS("l.sfgeu r%d, r%d\n", ra
, rb
);
1204 tcg_gen_setcond_tl(TCG_COND_GEU
, env_btaken
, cpu_R
[ra
], cpu_R
[rb
]);
1207 case 0x4: /* l.sfltu */
1208 LOG_DIS("l.sfltu r%d, r%d\n", ra
, rb
);
1209 tcg_gen_setcond_tl(TCG_COND_LTU
, env_btaken
, cpu_R
[ra
], cpu_R
[rb
]);
1212 case 0x5: /* l.sfleu */
1213 LOG_DIS("l.sfleu r%d, r%d\n", ra
, rb
);
1214 tcg_gen_setcond_tl(TCG_COND_LEU
, env_btaken
, cpu_R
[ra
], cpu_R
[rb
]);
1217 case 0xa: /* l.sfgts */
1218 LOG_DIS("l.sfgts r%d, r%d\n", ra
, rb
);
1219 tcg_gen_setcond_tl(TCG_COND_GT
, env_btaken
, cpu_R
[ra
], cpu_R
[rb
]);
1222 case 0xb: /* l.sfges */
1223 LOG_DIS("l.sfges r%d, r%d\n", ra
, rb
);
1224 tcg_gen_setcond_tl(TCG_COND_GE
, env_btaken
, cpu_R
[ra
], cpu_R
[rb
]);
1227 case 0xc: /* l.sflts */
1228 LOG_DIS("l.sflts r%d, r%d\n", ra
, rb
);
1229 tcg_gen_setcond_tl(TCG_COND_LT
, env_btaken
, cpu_R
[ra
], cpu_R
[rb
]);
1232 case 0xd: /* l.sfles */
1233 LOG_DIS("l.sfles r%d, r%d\n", ra
, rb
);
1234 tcg_gen_setcond_tl(TCG_COND_LE
, env_btaken
, cpu_R
[ra
], cpu_R
[rb
]);
1238 gen_illegal_exception(dc
);
1244 static void dec_compi(DisasContext
*dc
, uint32_t insn
)
1249 op0
= extract32(insn
, 21, 5);
1250 ra
= extract32(insn
, 16, 5);
1251 I16
= extract32(insn
, 0, 16);
1253 tcg_gen_movi_i32(env_btaken
, 0x0);
1254 I16
= sign_extend(I16
, 16);
1257 case 0x0: /* l.sfeqi */
1258 LOG_DIS("l.sfeqi r%d, %d\n", ra
, I16
);
1259 tcg_gen_setcondi_tl(TCG_COND_EQ
, env_btaken
, cpu_R
[ra
], I16
);
1262 case 0x1: /* l.sfnei */
1263 LOG_DIS("l.sfnei r%d, %d\n", ra
, I16
);
1264 tcg_gen_setcondi_tl(TCG_COND_NE
, env_btaken
, cpu_R
[ra
], I16
);
1267 case 0x2: /* l.sfgtui */
1268 LOG_DIS("l.sfgtui r%d, %d\n", ra
, I16
);
1269 tcg_gen_setcondi_tl(TCG_COND_GTU
, env_btaken
, cpu_R
[ra
], I16
);
1272 case 0x3: /* l.sfgeui */
1273 LOG_DIS("l.sfgeui r%d, %d\n", ra
, I16
);
1274 tcg_gen_setcondi_tl(TCG_COND_GEU
, env_btaken
, cpu_R
[ra
], I16
);
1277 case 0x4: /* l.sfltui */
1278 LOG_DIS("l.sfltui r%d, %d\n", ra
, I16
);
1279 tcg_gen_setcondi_tl(TCG_COND_LTU
, env_btaken
, cpu_R
[ra
], I16
);
1282 case 0x5: /* l.sfleui */
1283 LOG_DIS("l.sfleui r%d, %d\n", ra
, I16
);
1284 tcg_gen_setcondi_tl(TCG_COND_LEU
, env_btaken
, cpu_R
[ra
], I16
);
1287 case 0xa: /* l.sfgtsi */
1288 LOG_DIS("l.sfgtsi r%d, %d\n", ra
, I16
);
1289 tcg_gen_setcondi_tl(TCG_COND_GT
, env_btaken
, cpu_R
[ra
], I16
);
1292 case 0xb: /* l.sfgesi */
1293 LOG_DIS("l.sfgesi r%d, %d\n", ra
, I16
);
1294 tcg_gen_setcondi_tl(TCG_COND_GE
, env_btaken
, cpu_R
[ra
], I16
);
1297 case 0xc: /* l.sfltsi */
1298 LOG_DIS("l.sfltsi r%d, %d\n", ra
, I16
);
1299 tcg_gen_setcondi_tl(TCG_COND_LT
, env_btaken
, cpu_R
[ra
], I16
);
1302 case 0xd: /* l.sflesi */
1303 LOG_DIS("l.sflesi r%d, %d\n", ra
, I16
);
1304 tcg_gen_setcondi_tl(TCG_COND_LE
, env_btaken
, cpu_R
[ra
], I16
);
1308 gen_illegal_exception(dc
);
1314 static void dec_sys(DisasContext
*dc
, uint32_t insn
)
1317 #ifdef OPENRISC_DISAS
1320 op0
= extract32(insn
, 16, 8);
1321 #ifdef OPENRISC_DISAS
1322 K16
= extract32(insn
, 0, 16);
1326 case 0x000: /* l.sys */
1327 LOG_DIS("l.sys %d\n", K16
);
1328 tcg_gen_movi_tl(cpu_pc
, dc
->pc
);
1329 gen_exception(dc
, EXCP_SYSCALL
);
1330 dc
->is_jmp
= DISAS_UPDATE
;
1333 case 0x100: /* l.trap */
1334 LOG_DIS("l.trap %d\n", K16
);
1335 #if defined(CONFIG_USER_ONLY)
1338 if (dc
->mem_idx
== MMU_USER_IDX
) {
1339 gen_illegal_exception(dc
);
1342 tcg_gen_movi_tl(cpu_pc
, dc
->pc
);
1343 gen_exception(dc
, EXCP_TRAP
);
1347 case 0x300: /* l.csync */
1348 LOG_DIS("l.csync\n");
1349 #if defined(CONFIG_USER_ONLY)
1352 if (dc
->mem_idx
== MMU_USER_IDX
) {
1353 gen_illegal_exception(dc
);
1359 case 0x200: /* l.msync */
1360 LOG_DIS("l.msync\n");
1361 #if defined(CONFIG_USER_ONLY)
1364 if (dc
->mem_idx
== MMU_USER_IDX
) {
1365 gen_illegal_exception(dc
);
1371 case 0x270: /* l.psync */
1372 LOG_DIS("l.psync\n");
1373 #if defined(CONFIG_USER_ONLY)
1376 if (dc
->mem_idx
== MMU_USER_IDX
) {
1377 gen_illegal_exception(dc
);
1384 gen_illegal_exception(dc
);
1389 static void dec_float(DisasContext
*dc
, uint32_t insn
)
1392 uint32_t ra
, rb
, rd
;
1393 op0
= extract32(insn
, 0, 8);
1394 ra
= extract32(insn
, 16, 5);
1395 rb
= extract32(insn
, 11, 5);
1396 rd
= extract32(insn
, 21, 5);
1399 case 0x00: /* lf.add.s */
1400 LOG_DIS("lf.add.s r%d, r%d, r%d\n", rd
, ra
, rb
);
1401 gen_helper_float_add_s(cpu_R
[rd
], cpu_env
, cpu_R
[ra
], cpu_R
[rb
]);
1404 case 0x01: /* lf.sub.s */
1405 LOG_DIS("lf.sub.s r%d, r%d, r%d\n", rd
, ra
, rb
);
1406 gen_helper_float_sub_s(cpu_R
[rd
], cpu_env
, cpu_R
[ra
], cpu_R
[rb
]);
1410 case 0x02: /* lf.mul.s */
1411 LOG_DIS("lf.mul.s r%d, r%d, r%d\n", rd
, ra
, rb
);
1412 if (ra
!= 0 && rb
!= 0) {
1413 gen_helper_float_mul_s(cpu_R
[rd
], cpu_env
, cpu_R
[ra
], cpu_R
[rb
]);
1415 tcg_gen_ori_tl(fpcsr
, fpcsr
, FPCSR_ZF
);
1416 tcg_gen_movi_i32(cpu_R
[rd
], 0x0);
1420 case 0x03: /* lf.div.s */
1421 LOG_DIS("lf.div.s r%d, r%d, r%d\n", rd
, ra
, rb
);
1422 gen_helper_float_div_s(cpu_R
[rd
], cpu_env
, cpu_R
[ra
], cpu_R
[rb
]);
1425 case 0x04: /* lf.itof.s */
1426 LOG_DIS("lf.itof r%d, r%d\n", rd
, ra
);
1427 gen_helper_itofs(cpu_R
[rd
], cpu_env
, cpu_R
[ra
]);
1430 case 0x05: /* lf.ftoi.s */
1431 LOG_DIS("lf.ftoi r%d, r%d\n", rd
, ra
);
1432 gen_helper_ftois(cpu_R
[rd
], cpu_env
, cpu_R
[ra
]);
1435 case 0x06: /* lf.rem.s */
1436 LOG_DIS("lf.rem.s r%d, r%d, r%d\n", rd
, ra
, rb
);
1437 gen_helper_float_rem_s(cpu_R
[rd
], cpu_env
, cpu_R
[ra
], cpu_R
[rb
]);
1440 case 0x07: /* lf.madd.s */
1441 LOG_DIS("lf.madd.s r%d, r%d, r%d\n", rd
, ra
, rb
);
1442 gen_helper_float_muladd_s(cpu_R
[rd
], cpu_env
, cpu_R
[ra
], cpu_R
[rb
]);
1445 case 0x08: /* lf.sfeq.s */
1446 LOG_DIS("lf.sfeq.s r%d, r%d\n", ra
, rb
);
1447 gen_helper_float_eq_s(env_btaken
, cpu_env
, cpu_R
[ra
], cpu_R
[rb
]);
1450 case 0x09: /* lf.sfne.s */
1451 LOG_DIS("lf.sfne.s r%d, r%d\n", ra
, rb
);
1452 gen_helper_float_ne_s(env_btaken
, cpu_env
, cpu_R
[ra
], cpu_R
[rb
]);
1455 case 0x0a: /* lf.sfgt.s */
1456 LOG_DIS("lf.sfgt.s r%d, r%d\n", ra
, rb
);
1457 gen_helper_float_gt_s(env_btaken
, cpu_env
, cpu_R
[ra
], cpu_R
[rb
]);
1460 case 0x0b: /* lf.sfge.s */
1461 LOG_DIS("lf.sfge.s r%d, r%d\n", ra
, rb
);
1462 gen_helper_float_ge_s(env_btaken
, cpu_env
, cpu_R
[ra
], cpu_R
[rb
]);
1465 case 0x0c: /* lf.sflt.s */
1466 LOG_DIS("lf.sflt.s r%d, r%d\n", ra
, rb
);
1467 gen_helper_float_lt_s(env_btaken
, cpu_env
, cpu_R
[ra
], cpu_R
[rb
]);
1470 case 0x0d: /* lf.sfle.s */
1471 LOG_DIS("lf.sfle.s r%d, r%d\n", ra
, rb
);
1472 gen_helper_float_le_s(env_btaken
, cpu_env
, cpu_R
[ra
], cpu_R
[rb
]);
1475 /* not used yet, open it when we need or64. */
1476 /*#ifdef TARGET_OPENRISC64
1478 LOG_DIS("lf.add.d r%d, r%d, r%d\n", rd, ra, rb);
1480 gen_helper_float_add_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]);
1484 LOG_DIS("lf.sub.d r%d, r%d, r%d\n", rd, ra, rb);
1486 gen_helper_float_sub_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]);
1490 LOG_DIS("lf.mul.d r%d, r%d, r%d\n", rd, ra, rb);
1492 if (ra != 0 && rb != 0) {
1493 gen_helper_float_mul_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]);
1495 tcg_gen_ori_tl(fpcsr, fpcsr, FPCSR_ZF);
1496 tcg_gen_movi_i64(cpu_R[rd], 0x0);
1501 LOG_DIS("lf.div.d r%d, r%d, r%d\n", rd, ra, rb);
1503 gen_helper_float_div_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]);
1506 case 0x14: lf.itof.d
1507 LOG_DIS("lf.itof r%d, r%d\n", rd, ra);
1509 gen_helper_itofd(cpu_R[rd], cpu_env, cpu_R[ra]);
1512 case 0x15: lf.ftoi.d
1513 LOG_DIS("lf.ftoi r%d, r%d\n", rd, ra);
1515 gen_helper_ftoid(cpu_R[rd], cpu_env, cpu_R[ra]);
1519 LOG_DIS("lf.rem.d r%d, r%d, r%d\n", rd, ra, rb);
1521 gen_helper_float_rem_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]);
1524 case 0x17: lf.madd.d
1525 LOG_DIS("lf.madd.d r%d, r%d, r%d\n", rd, ra, rb);
1527 gen_helper_float_muladd_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]);
1530 case 0x18: lf.sfeq.d
1531 LOG_DIS("lf.sfeq.d r%d, r%d\n", ra, rb);
1533 gen_helper_float_eq_d(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]);
1536 case 0x1a: lf.sfgt.d
1537 LOG_DIS("lf.sfgt.d r%d, r%d\n", ra, rb);
1539 gen_helper_float_gt_d(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]);
1542 case 0x1b: lf.sfge.d
1543 LOG_DIS("lf.sfge.d r%d, r%d\n", ra, rb);
1545 gen_helper_float_ge_d(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]);
1548 case 0x19: lf.sfne.d
1549 LOG_DIS("lf.sfne.d r%d, r%d\n", ra, rb);
1551 gen_helper_float_ne_d(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]);
1554 case 0x1c: lf.sflt.d
1555 LOG_DIS("lf.sflt.d r%d, r%d\n", ra, rb);
1557 gen_helper_float_lt_d(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]);
1560 case 0x1d: lf.sfle.d
1561 LOG_DIS("lf.sfle.d r%d, r%d\n", ra, rb);
1563 gen_helper_float_le_d(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]);
1568 gen_illegal_exception(dc
);
1574 static void disas_openrisc_insn(DisasContext
*dc
, OpenRISCCPU
*cpu
)
1578 insn
= cpu_ldl_code(&cpu
->env
, dc
->pc
);
1579 op0
= extract32(insn
, 26, 6);
1591 dec_logic(dc
, insn
);
1595 dec_compi(dc
, insn
);
1603 dec_float(dc
, insn
);
1620 static void check_breakpoint(OpenRISCCPU
*cpu
, DisasContext
*dc
)
1622 CPUState
*cs
= CPU(cpu
);
1625 if (unlikely(!QTAILQ_EMPTY(&cs
->breakpoints
))) {
1626 QTAILQ_FOREACH(bp
, &cs
->breakpoints
, entry
) {
1627 if (bp
->pc
== dc
->pc
) {
1628 tcg_gen_movi_tl(cpu_pc
, dc
->pc
);
1629 gen_exception(dc
, EXCP_DEBUG
);
1630 dc
->is_jmp
= DISAS_UPDATE
;
1636 static inline void gen_intermediate_code_internal(OpenRISCCPU
*cpu
,
1637 TranslationBlock
*tb
,
1640 CPUState
*cs
= CPU(cpu
);
1641 struct DisasContext ctx
, *dc
= &ctx
;
1642 uint16_t *gen_opc_end
;
1645 uint32_t next_page_start
;
1652 gen_opc_end
= tcg_ctx
.gen_opc_buf
+ OPC_MAX_SIZE
;
1653 dc
->is_jmp
= DISAS_NEXT
;
1656 dc
->flags
= cpu
->env
.cpucfgr
;
1657 dc
->mem_idx
= cpu_mmu_index(&cpu
->env
);
1658 dc
->synced_flags
= dc
->tb_flags
= tb
->flags
;
1659 dc
->delayed_branch
= !!(dc
->tb_flags
& D_FLAG
);
1660 dc
->singlestep_enabled
= cs
->singlestep_enabled
;
1661 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
1662 qemu_log("-----------------------------------------\n");
1663 log_cpu_state(CPU(cpu
), 0);
1666 next_page_start
= (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
1669 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
1671 if (max_insns
== 0) {
1672 max_insns
= CF_COUNT_MASK
;
1678 check_breakpoint(cpu
, dc
);
1680 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
1684 tcg_ctx
.gen_opc_instr_start
[k
++] = 0;
1687 tcg_ctx
.gen_opc_pc
[k
] = dc
->pc
;
1688 tcg_ctx
.gen_opc_instr_start
[k
] = 1;
1689 tcg_ctx
.gen_opc_icount
[k
] = num_insns
;
1692 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
1693 tcg_gen_debug_insn_start(dc
->pc
);
1696 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
1699 dc
->ppc
= dc
->pc
- 4;
1700 dc
->npc
= dc
->pc
+ 4;
1701 tcg_gen_movi_tl(cpu_ppc
, dc
->ppc
);
1702 tcg_gen_movi_tl(cpu_npc
, dc
->npc
);
1703 disas_openrisc_insn(dc
, cpu
);
1707 if (dc
->delayed_branch
) {
1708 dc
->delayed_branch
--;
1709 if (!dc
->delayed_branch
) {
1710 dc
->tb_flags
&= ~D_FLAG
;
1712 tcg_gen_mov_tl(cpu_pc
, jmp_pc
);
1713 tcg_gen_mov_tl(cpu_npc
, jmp_pc
);
1714 tcg_gen_movi_tl(jmp_pc
, 0);
1716 dc
->is_jmp
= DISAS_JUMP
;
1720 } while (!dc
->is_jmp
1721 && tcg_ctx
.gen_opc_ptr
< gen_opc_end
1722 && !cs
->singlestep_enabled
1724 && (dc
->pc
< next_page_start
)
1725 && num_insns
< max_insns
);
1727 if (tb
->cflags
& CF_LAST_IO
) {
1730 if (dc
->is_jmp
== DISAS_NEXT
) {
1731 dc
->is_jmp
= DISAS_UPDATE
;
1732 tcg_gen_movi_tl(cpu_pc
, dc
->pc
);
1734 if (unlikely(cs
->singlestep_enabled
)) {
1735 if (dc
->is_jmp
== DISAS_NEXT
) {
1736 tcg_gen_movi_tl(cpu_pc
, dc
->pc
);
1738 gen_exception(dc
, EXCP_DEBUG
);
1740 switch (dc
->is_jmp
) {
1742 gen_goto_tb(dc
, 0, dc
->pc
);
1748 /* indicate that the hash table must be used
1749 to find the next TB */
1753 /* nothing more to generate */
1758 gen_tb_end(tb
, num_insns
);
1759 *tcg_ctx
.gen_opc_ptr
= INDEX_op_end
;
1761 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
1764 tcg_ctx
.gen_opc_instr_start
[k
++] = 0;
1767 tb
->size
= dc
->pc
- pc_start
;
1768 tb
->icount
= num_insns
;
1772 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
1774 log_target_disas(&cpu
->env
, pc_start
, dc
->pc
- pc_start
, 0);
1775 qemu_log("\nisize=%d osize=%td\n",
1776 dc
->pc
- pc_start
, tcg_ctx
.gen_opc_ptr
-
1777 tcg_ctx
.gen_opc_buf
);
1782 void gen_intermediate_code(CPUOpenRISCState
*env
, struct TranslationBlock
*tb
)
1784 gen_intermediate_code_internal(openrisc_env_get_cpu(env
), tb
, 0);
1787 void gen_intermediate_code_pc(CPUOpenRISCState
*env
,
1788 struct TranslationBlock
*tb
)
1790 gen_intermediate_code_internal(openrisc_env_get_cpu(env
), tb
, 1);
1793 void openrisc_cpu_dump_state(CPUState
*cs
, FILE *f
,
1794 fprintf_function cpu_fprintf
,
1797 OpenRISCCPU
*cpu
= OPENRISC_CPU(cs
);
1798 CPUOpenRISCState
*env
= &cpu
->env
;
1801 cpu_fprintf(f
, "PC=%08x\n", env
->pc
);
1802 for (i
= 0; i
< 32; ++i
) {
1803 cpu_fprintf(f
, "R%02d=%08x%c", i
, env
->gpr
[i
],
1804 (i
% 4) == 3 ? '\n' : ' ');
1808 void restore_state_to_opc(CPUOpenRISCState
*env
, TranslationBlock
*tb
,
1811 env
->pc
= tcg_ctx
.gen_opc_pc
[pc_pos
];