]>
git.proxmox.com Git - mirror_qemu.git/blob - target/rx/translate.c
4 * Copyright (c) 2019 Yoshinori Sato
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2 or later, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "qemu/osdep.h"
20 #include "qemu/bswap.h"
21 #include "qemu/qemu-print.h"
23 #include "exec/exec-all.h"
24 #include "tcg/tcg-op.h"
25 #include "exec/cpu_ldst.h"
26 #include "exec/helper-proto.h"
27 #include "exec/helper-gen.h"
28 #include "exec/translator.h"
31 typedef struct DisasContext
{
32 DisasContextBase base
;
38 typedef struct DisasCompare
{
44 const char *rx_crname(uint8_t cr
)
46 static const char *cr_names
[] = {
47 "psw", "pc", "usp", "fpsw", "", "", "", "",
48 "bpsw", "bpc", "isp", "fintv", "intb", "", "", ""
50 if (cr
>= ARRAY_SIZE(cr_names
)) {
56 /* Target-specific values for dc->base.is_jmp. */
57 #define DISAS_JUMP DISAS_TARGET_0
58 #define DISAS_UPDATE DISAS_TARGET_1
59 #define DISAS_EXIT DISAS_TARGET_2
61 /* global register indexes */
62 static TCGv cpu_regs
[16];
63 static TCGv cpu_psw_o
, cpu_psw_s
, cpu_psw_z
, cpu_psw_c
;
64 static TCGv cpu_psw_i
, cpu_psw_pm
, cpu_psw_u
, cpu_psw_ipl
;
65 static TCGv cpu_usp
, cpu_fpsw
, cpu_bpsw
, cpu_bpc
, cpu_isp
;
66 static TCGv cpu_fintv
, cpu_intb
, cpu_pc
;
67 static TCGv_i64 cpu_acc
;
69 #define cpu_sp cpu_regs[0]
71 #include "exec/gen-icount.h"
74 static uint32_t decode_load_bytes(DisasContext
*ctx
, uint32_t insn
,
78 uint8_t b
= cpu_ldub_code(ctx
->env
, ctx
->base
.pc_next
++);
79 insn
|= b
<< (32 - i
* 8);
84 static uint32_t li(DisasContext
*ctx
, int sz
)
87 CPURXState
*env
= ctx
->env
;
88 addr
= ctx
->base
.pc_next
;
90 tcg_debug_assert(sz
< 4);
93 ctx
->base
.pc_next
+= 1;
94 return cpu_ldsb_code(env
, addr
);
96 ctx
->base
.pc_next
+= 2;
97 return cpu_ldsw_code(env
, addr
);
99 ctx
->base
.pc_next
+= 3;
100 tmp
= cpu_ldsb_code(env
, addr
+ 2) << 16;
101 tmp
|= cpu_lduw_code(env
, addr
) & 0xffff;
104 ctx
->base
.pc_next
+= 4;
105 return cpu_ldl_code(env
, addr
);
110 static int bdsp_s(DisasContext
*ctx
, int d
)
126 /* Include the auto-generated decoder. */
127 #include "decode-insns.c.inc"
129 void rx_cpu_dump_state(CPUState
*cs
, FILE *f
, int flags
)
131 RXCPU
*cpu
= RX_CPU(cs
);
132 CPURXState
*env
= &cpu
->env
;
136 psw
= rx_cpu_pack_psw(env
);
137 qemu_fprintf(f
, "pc=0x%08x psw=0x%08x\n",
139 for (i
= 0; i
< 16; i
+= 4) {
140 qemu_fprintf(f
, "r%d=0x%08x r%d=0x%08x r%d=0x%08x r%d=0x%08x\n",
141 i
, env
->regs
[i
], i
+ 1, env
->regs
[i
+ 1],
142 i
+ 2, env
->regs
[i
+ 2], i
+ 3, env
->regs
[i
+ 3]);
146 static void gen_goto_tb(DisasContext
*dc
, int n
, target_ulong dest
)
148 if (translator_use_goto_tb(&dc
->base
, dest
)) {
150 tcg_gen_movi_i32(cpu_pc
, dest
);
151 tcg_gen_exit_tb(dc
->base
.tb
, n
);
153 tcg_gen_movi_i32(cpu_pc
, dest
);
154 tcg_gen_lookup_and_goto_ptr();
156 dc
->base
.is_jmp
= DISAS_NORETURN
;
159 /* generic load wrapper */
160 static inline void rx_gen_ld(unsigned int size
, TCGv reg
, TCGv mem
)
162 tcg_gen_qemu_ld_i32(reg
, mem
, 0, size
| MO_SIGN
| MO_TE
);
165 /* unsigned load wrapper */
166 static inline void rx_gen_ldu(unsigned int size
, TCGv reg
, TCGv mem
)
168 tcg_gen_qemu_ld_i32(reg
, mem
, 0, size
| MO_TE
);
171 /* generic store wrapper */
172 static inline void rx_gen_st(unsigned int size
, TCGv reg
, TCGv mem
)
174 tcg_gen_qemu_st_i32(reg
, mem
, 0, size
| MO_TE
);
178 static inline void rx_gen_regindex(DisasContext
*ctx
, TCGv mem
,
179 int size
, int ri
, int rb
)
181 tcg_gen_shli_i32(mem
, cpu_regs
[ri
], size
);
182 tcg_gen_add_i32(mem
, mem
, cpu_regs
[rb
]);
186 static inline TCGv
rx_index_addr(DisasContext
*ctx
, TCGv mem
,
187 int ld
, int size
, int reg
)
191 tcg_debug_assert(ld
< 3);
194 return cpu_regs
[reg
];
196 dsp
= cpu_ldub_code(ctx
->env
, ctx
->base
.pc_next
) << size
;
197 tcg_gen_addi_i32(mem
, cpu_regs
[reg
], dsp
);
198 ctx
->base
.pc_next
+= 1;
201 dsp
= cpu_lduw_code(ctx
->env
, ctx
->base
.pc_next
) << size
;
202 tcg_gen_addi_i32(mem
, cpu_regs
[reg
], dsp
);
203 ctx
->base
.pc_next
+= 2;
209 static inline MemOp
mi_to_mop(unsigned mi
)
211 static const MemOp mop
[5] = { MO_SB
, MO_SW
, MO_UL
, MO_UW
, MO_UB
};
212 tcg_debug_assert(mi
< 5);
216 /* load source operand */
217 static inline TCGv
rx_load_source(DisasContext
*ctx
, TCGv mem
,
218 int ld
, int mi
, int rs
)
224 addr
= rx_index_addr(ctx
, mem
, ld
, mop
& MO_SIZE
, rs
);
225 tcg_gen_qemu_ld_i32(mem
, addr
, 0, mop
| MO_TE
);
232 /* Processor mode check */
233 static int is_privileged(DisasContext
*ctx
, int is_exception
)
235 if (FIELD_EX32(ctx
->tb_flags
, PSW
, PM
)) {
237 gen_helper_raise_privilege_violation(cpu_env
);
245 /* generate QEMU condition */
246 static void psw_cond(DisasCompare
*dc
, uint32_t cond
)
248 tcg_debug_assert(cond
< 16);
251 dc
->cond
= TCG_COND_EQ
;
252 dc
->value
= cpu_psw_z
;
255 dc
->cond
= TCG_COND_NE
;
256 dc
->value
= cpu_psw_z
;
259 dc
->cond
= TCG_COND_NE
;
260 dc
->value
= cpu_psw_c
;
263 dc
->cond
= TCG_COND_EQ
;
264 dc
->value
= cpu_psw_c
;
266 case 4: /* gtu (C& ~Z) == 1 */
267 case 5: /* leu (C& ~Z) == 0 */
268 tcg_gen_setcondi_i32(TCG_COND_NE
, dc
->temp
, cpu_psw_z
, 0);
269 tcg_gen_and_i32(dc
->temp
, dc
->temp
, cpu_psw_c
);
270 dc
->cond
= (cond
== 4) ? TCG_COND_NE
: TCG_COND_EQ
;
271 dc
->value
= dc
->temp
;
273 case 6: /* pz (S == 0) */
274 dc
->cond
= TCG_COND_GE
;
275 dc
->value
= cpu_psw_s
;
277 case 7: /* n (S == 1) */
278 dc
->cond
= TCG_COND_LT
;
279 dc
->value
= cpu_psw_s
;
281 case 8: /* ge (S^O)==0 */
282 case 9: /* lt (S^O)==1 */
283 tcg_gen_xor_i32(dc
->temp
, cpu_psw_o
, cpu_psw_s
);
284 dc
->cond
= (cond
== 8) ? TCG_COND_GE
: TCG_COND_LT
;
285 dc
->value
= dc
->temp
;
287 case 10: /* gt ((S^O)|Z)==0 */
288 case 11: /* le ((S^O)|Z)==1 */
289 tcg_gen_xor_i32(dc
->temp
, cpu_psw_o
, cpu_psw_s
);
290 tcg_gen_sari_i32(dc
->temp
, dc
->temp
, 31);
291 tcg_gen_andc_i32(dc
->temp
, cpu_psw_z
, dc
->temp
);
292 dc
->cond
= (cond
== 10) ? TCG_COND_NE
: TCG_COND_EQ
;
293 dc
->value
= dc
->temp
;
296 dc
->cond
= TCG_COND_LT
;
297 dc
->value
= cpu_psw_o
;
300 dc
->cond
= TCG_COND_GE
;
301 dc
->value
= cpu_psw_o
;
303 case 14: /* always true */
304 dc
->cond
= TCG_COND_ALWAYS
;
305 dc
->value
= dc
->temp
;
307 case 15: /* always false */
308 dc
->cond
= TCG_COND_NEVER
;
309 dc
->value
= dc
->temp
;
314 static void move_from_cr(TCGv ret
, int cr
, uint32_t pc
)
316 TCGv z
= tcg_const_i32(0);
319 gen_helper_pack_psw(ret
, cpu_env
);
322 tcg_gen_movi_i32(ret
, pc
);
325 tcg_gen_movcond_i32(TCG_COND_NE
, ret
,
326 cpu_psw_u
, z
, cpu_sp
, cpu_usp
);
329 tcg_gen_mov_i32(ret
, cpu_fpsw
);
332 tcg_gen_mov_i32(ret
, cpu_bpsw
);
335 tcg_gen_mov_i32(ret
, cpu_bpc
);
338 tcg_gen_movcond_i32(TCG_COND_EQ
, ret
,
339 cpu_psw_u
, z
, cpu_sp
, cpu_isp
);
342 tcg_gen_mov_i32(ret
, cpu_fintv
);
345 tcg_gen_mov_i32(ret
, cpu_intb
);
348 qemu_log_mask(LOG_GUEST_ERROR
, "Unimplement control register %d", cr
);
349 /* Unimplement registers return 0 */
350 tcg_gen_movi_i32(ret
, 0);
356 static void move_to_cr(DisasContext
*ctx
, TCGv val
, int cr
)
359 if (cr
>= 8 && !is_privileged(ctx
, 0)) {
360 /* Some control registers can only be written in privileged mode. */
361 qemu_log_mask(LOG_GUEST_ERROR
,
362 "disallow control register write %s", rx_crname(cr
));
365 z
= tcg_const_i32(0);
368 gen_helper_set_psw(cpu_env
, val
);
370 /* case 1: to PC not supported */
372 tcg_gen_mov_i32(cpu_usp
, val
);
373 tcg_gen_movcond_i32(TCG_COND_NE
, cpu_sp
,
374 cpu_psw_u
, z
, cpu_usp
, cpu_sp
);
377 gen_helper_set_fpsw(cpu_env
, val
);
380 tcg_gen_mov_i32(cpu_bpsw
, val
);
383 tcg_gen_mov_i32(cpu_bpc
, val
);
386 tcg_gen_mov_i32(cpu_isp
, val
);
387 /* if PSW.U is 0, copy isp to r0 */
388 tcg_gen_movcond_i32(TCG_COND_EQ
, cpu_sp
,
389 cpu_psw_u
, z
, cpu_isp
, cpu_sp
);
392 tcg_gen_mov_i32(cpu_fintv
, val
);
395 tcg_gen_mov_i32(cpu_intb
, val
);
398 qemu_log_mask(LOG_GUEST_ERROR
,
399 "Unimplement control register %d", cr
);
405 static void push(TCGv val
)
407 tcg_gen_subi_i32(cpu_sp
, cpu_sp
, 4);
408 rx_gen_st(MO_32
, val
, cpu_sp
);
411 static void pop(TCGv ret
)
413 rx_gen_ld(MO_32
, ret
, cpu_sp
);
414 tcg_gen_addi_i32(cpu_sp
, cpu_sp
, 4);
417 /* mov.<bwl> rs,dsp5[rd] */
418 static bool trans_MOV_rm(DisasContext
*ctx
, arg_MOV_rm
*a
)
421 mem
= tcg_temp_new();
422 tcg_gen_addi_i32(mem
, cpu_regs
[a
->rd
], a
->dsp
<< a
->sz
);
423 rx_gen_st(a
->sz
, cpu_regs
[a
->rs
], mem
);
428 /* mov.<bwl> dsp5[rs],rd */
429 static bool trans_MOV_mr(DisasContext
*ctx
, arg_MOV_mr
*a
)
432 mem
= tcg_temp_new();
433 tcg_gen_addi_i32(mem
, cpu_regs
[a
->rs
], a
->dsp
<< a
->sz
);
434 rx_gen_ld(a
->sz
, cpu_regs
[a
->rd
], mem
);
439 /* mov.l #uimm4,rd */
440 /* mov.l #uimm8,rd */
442 static bool trans_MOV_ir(DisasContext
*ctx
, arg_MOV_ir
*a
)
444 tcg_gen_movi_i32(cpu_regs
[a
->rd
], a
->imm
);
448 /* mov.<bwl> #uimm8,dsp[rd] */
449 /* mov.<bwl> #imm, dsp[rd] */
450 static bool trans_MOV_im(DisasContext
*ctx
, arg_MOV_im
*a
)
453 imm
= tcg_const_i32(a
->imm
);
454 mem
= tcg_temp_new();
455 tcg_gen_addi_i32(mem
, cpu_regs
[a
->rd
], a
->dsp
<< a
->sz
);
456 rx_gen_st(a
->sz
, imm
, mem
);
462 /* mov.<bwl> [ri,rb],rd */
463 static bool trans_MOV_ar(DisasContext
*ctx
, arg_MOV_ar
*a
)
466 mem
= tcg_temp_new();
467 rx_gen_regindex(ctx
, mem
, a
->sz
, a
->ri
, a
->rb
);
468 rx_gen_ld(a
->sz
, cpu_regs
[a
->rd
], mem
);
473 /* mov.<bwl> rd,[ri,rb] */
474 static bool trans_MOV_ra(DisasContext
*ctx
, arg_MOV_ra
*a
)
477 mem
= tcg_temp_new();
478 rx_gen_regindex(ctx
, mem
, a
->sz
, a
->ri
, a
->rb
);
479 rx_gen_st(a
->sz
, cpu_regs
[a
->rs
], mem
);
484 /* mov.<bwl> dsp[rs],dsp[rd] */
485 /* mov.<bwl> rs,dsp[rd] */
486 /* mov.<bwl> dsp[rs],rd */
487 /* mov.<bwl> rs,rd */
488 static bool trans_MOV_mm(DisasContext
*ctx
, arg_MOV_mm
*a
)
490 static void (* const mov
[])(TCGv ret
, TCGv arg
) = {
491 tcg_gen_ext8s_i32
, tcg_gen_ext16s_i32
, tcg_gen_mov_i32
,
494 if (a
->lds
== 3 && a
->ldd
== 3) {
495 /* mov.<bwl> rs,rd */
496 mov
[a
->sz
](cpu_regs
[a
->rd
], cpu_regs
[a
->rs
]);
500 mem
= tcg_temp_new();
502 /* mov.<bwl> rs,dsp[rd] */
503 addr
= rx_index_addr(ctx
, mem
, a
->ldd
, a
->sz
, a
->rs
);
504 rx_gen_st(a
->sz
, cpu_regs
[a
->rd
], addr
);
505 } else if (a
->ldd
== 3) {
506 /* mov.<bwl> dsp[rs],rd */
507 addr
= rx_index_addr(ctx
, mem
, a
->lds
, a
->sz
, a
->rs
);
508 rx_gen_ld(a
->sz
, cpu_regs
[a
->rd
], addr
);
510 /* mov.<bwl> dsp[rs],dsp[rd] */
511 tmp
= tcg_temp_new();
512 addr
= rx_index_addr(ctx
, mem
, a
->lds
, a
->sz
, a
->rs
);
513 rx_gen_ld(a
->sz
, tmp
, addr
);
514 addr
= rx_index_addr(ctx
, mem
, a
->ldd
, a
->sz
, a
->rd
);
515 rx_gen_st(a
->sz
, tmp
, addr
);
522 /* mov.<bwl> rs,[rd+] */
523 /* mov.<bwl> rs,[-rd] */
524 static bool trans_MOV_rp(DisasContext
*ctx
, arg_MOV_rp
*a
)
527 val
= tcg_temp_new();
528 tcg_gen_mov_i32(val
, cpu_regs
[a
->rs
]);
530 tcg_gen_subi_i32(cpu_regs
[a
->rd
], cpu_regs
[a
->rd
], 1 << a
->sz
);
532 rx_gen_st(a
->sz
, val
, cpu_regs
[a
->rd
]);
534 tcg_gen_addi_i32(cpu_regs
[a
->rd
], cpu_regs
[a
->rd
], 1 << a
->sz
);
540 /* mov.<bwl> [rd+],rs */
541 /* mov.<bwl> [-rd],rs */
542 static bool trans_MOV_pr(DisasContext
*ctx
, arg_MOV_pr
*a
)
545 val
= tcg_temp_new();
547 tcg_gen_subi_i32(cpu_regs
[a
->rd
], cpu_regs
[a
->rd
], 1 << a
->sz
);
549 rx_gen_ld(a
->sz
, val
, cpu_regs
[a
->rd
]);
551 tcg_gen_addi_i32(cpu_regs
[a
->rd
], cpu_regs
[a
->rd
], 1 << a
->sz
);
553 tcg_gen_mov_i32(cpu_regs
[a
->rs
], val
);
558 /* movu.<bw> dsp5[rs],rd */
559 /* movu.<bw> dsp[rs],rd */
560 static bool trans_MOVU_mr(DisasContext
*ctx
, arg_MOVU_mr
*a
)
563 mem
= tcg_temp_new();
564 tcg_gen_addi_i32(mem
, cpu_regs
[a
->rs
], a
->dsp
<< a
->sz
);
565 rx_gen_ldu(a
->sz
, cpu_regs
[a
->rd
], mem
);
570 /* movu.<bw> rs,rd */
571 static bool trans_MOVU_rr(DisasContext
*ctx
, arg_MOVU_rr
*a
)
573 static void (* const ext
[])(TCGv ret
, TCGv arg
) = {
574 tcg_gen_ext8u_i32
, tcg_gen_ext16u_i32
,
576 ext
[a
->sz
](cpu_regs
[a
->rd
], cpu_regs
[a
->rs
]);
580 /* movu.<bw> [ri,rb],rd */
581 static bool trans_MOVU_ar(DisasContext
*ctx
, arg_MOVU_ar
*a
)
584 mem
= tcg_temp_new();
585 rx_gen_regindex(ctx
, mem
, a
->sz
, a
->ri
, a
->rb
);
586 rx_gen_ldu(a
->sz
, cpu_regs
[a
->rd
], mem
);
591 /* movu.<bw> [rd+],rs */
592 /* mov.<bw> [-rd],rs */
593 static bool trans_MOVU_pr(DisasContext
*ctx
, arg_MOVU_pr
*a
)
596 val
= tcg_temp_new();
598 tcg_gen_subi_i32(cpu_regs
[a
->rd
], cpu_regs
[a
->rd
], 1 << a
->sz
);
600 rx_gen_ldu(a
->sz
, val
, cpu_regs
[a
->rd
]);
602 tcg_gen_addi_i32(cpu_regs
[a
->rd
], cpu_regs
[a
->rd
], 1 << a
->sz
);
604 tcg_gen_mov_i32(cpu_regs
[a
->rs
], val
);
611 static bool trans_POP(DisasContext
*ctx
, arg_POP
*a
)
613 /* mov.l [r0+], rd */
619 trans_MOV_pr(ctx
, &mov_a
);
624 static bool trans_POPC(DisasContext
*ctx
, arg_POPC
*a
)
627 val
= tcg_temp_new();
629 move_to_cr(ctx
, val
, a
->cr
);
630 if (a
->cr
== 0 && is_privileged(ctx
, 0)) {
631 /* PSW.I may be updated here. exit TB. */
632 ctx
->base
.is_jmp
= DISAS_UPDATE
;
639 static bool trans_POPM(DisasContext
*ctx
, arg_POPM
*a
)
642 if (a
->rd
== 0 || a
->rd
>= a
->rd2
) {
643 qemu_log_mask(LOG_GUEST_ERROR
,
644 "Invalid register ranges r%d-r%d", a
->rd
, a
->rd2
);
647 while (r
<= a
->rd2
&& r
< 16) {
655 static bool trans_PUSH_r(DisasContext
*ctx
, arg_PUSH_r
*a
)
658 val
= tcg_temp_new();
659 tcg_gen_mov_i32(val
, cpu_regs
[a
->rs
]);
660 tcg_gen_subi_i32(cpu_sp
, cpu_sp
, 4);
661 rx_gen_st(a
->sz
, val
, cpu_sp
);
666 /* push.<bwl> dsp[rs] */
667 static bool trans_PUSH_m(DisasContext
*ctx
, arg_PUSH_m
*a
)
670 mem
= tcg_temp_new();
671 val
= tcg_temp_new();
672 addr
= rx_index_addr(ctx
, mem
, a
->ld
, a
->sz
, a
->rs
);
673 rx_gen_ld(a
->sz
, val
, addr
);
674 tcg_gen_subi_i32(cpu_sp
, cpu_sp
, 4);
675 rx_gen_st(a
->sz
, val
, cpu_sp
);
682 static bool trans_PUSHC(DisasContext
*ctx
, arg_PUSHC
*a
)
685 val
= tcg_temp_new();
686 move_from_cr(val
, a
->cr
, ctx
->pc
);
693 static bool trans_PUSHM(DisasContext
*ctx
, arg_PUSHM
*a
)
697 if (a
->rs
== 0 || a
->rs
>= a
->rs2
) {
698 qemu_log_mask(LOG_GUEST_ERROR
,
699 "Invalid register ranges r%d-r%d", a
->rs
, a
->rs2
);
702 while (r
>= a
->rs
&& r
>= 0) {
709 static bool trans_XCHG_rr(DisasContext
*ctx
, arg_XCHG_rr
*a
)
712 tmp
= tcg_temp_new();
713 tcg_gen_mov_i32(tmp
, cpu_regs
[a
->rs
]);
714 tcg_gen_mov_i32(cpu_regs
[a
->rs
], cpu_regs
[a
->rd
]);
715 tcg_gen_mov_i32(cpu_regs
[a
->rd
], tmp
);
720 /* xchg dsp[rs].<mi>,rd */
721 static bool trans_XCHG_mr(DisasContext
*ctx
, arg_XCHG_mr
*a
)
724 mem
= tcg_temp_new();
726 case 0: /* dsp[rs].b */
727 case 1: /* dsp[rs].w */
728 case 2: /* dsp[rs].l */
729 addr
= rx_index_addr(ctx
, mem
, a
->ld
, a
->mi
, a
->rs
);
731 case 3: /* dsp[rs].uw */
732 case 4: /* dsp[rs].ub */
733 addr
= rx_index_addr(ctx
, mem
, a
->ld
, 4 - a
->mi
, a
->rs
);
736 g_assert_not_reached();
738 tcg_gen_atomic_xchg_i32(cpu_regs
[a
->rd
], addr
, cpu_regs
[a
->rd
],
739 0, mi_to_mop(a
->mi
));
744 static inline void stcond(TCGCond cond
, int rd
, int imm
)
748 z
= tcg_const_i32(0);
749 _imm
= tcg_const_i32(imm
);
750 tcg_gen_movcond_i32(cond
, cpu_regs
[rd
], cpu_psw_z
, z
,
757 static bool trans_STZ(DisasContext
*ctx
, arg_STZ
*a
)
759 stcond(TCG_COND_EQ
, a
->rd
, a
->imm
);
764 static bool trans_STNZ(DisasContext
*ctx
, arg_STNZ
*a
)
766 stcond(TCG_COND_NE
, a
->rd
, a
->imm
);
771 /* sccnd.<bwl> dsp:[rd] */
772 static bool trans_SCCnd(DisasContext
*ctx
, arg_SCCnd
*a
)
776 dc
.temp
= tcg_temp_new();
777 psw_cond(&dc
, a
->cd
);
779 val
= tcg_temp_new();
780 mem
= tcg_temp_new();
781 tcg_gen_setcondi_i32(dc
.cond
, val
, dc
.value
, 0);
782 addr
= rx_index_addr(ctx
, mem
, a
->sz
, a
->ld
, a
->rd
);
783 rx_gen_st(a
->sz
, val
, addr
);
787 tcg_gen_setcondi_i32(dc
.cond
, cpu_regs
[a
->rd
], dc
.value
, 0);
789 tcg_temp_free(dc
.temp
);
794 static bool trans_RTSD_i(DisasContext
*ctx
, arg_RTSD_i
*a
)
796 tcg_gen_addi_i32(cpu_sp
, cpu_sp
, a
->imm
<< 2);
798 ctx
->base
.is_jmp
= DISAS_JUMP
;
802 /* rtsd #imm, rd-rd2 */
803 static bool trans_RTSD_irr(DisasContext
*ctx
, arg_RTSD_irr
*a
)
808 if (a
->rd2
>= a
->rd
) {
809 adj
= a
->imm
- (a
->rd2
- a
->rd
+ 1);
811 adj
= a
->imm
- (15 - a
->rd
+ 1);
814 tcg_gen_addi_i32(cpu_sp
, cpu_sp
, adj
<< 2);
816 while (dst
<= a
->rd2
&& dst
< 16) {
817 pop(cpu_regs
[dst
++]);
820 ctx
->base
.is_jmp
= DISAS_JUMP
;
824 typedef void (*op2fn
)(TCGv ret
, TCGv arg1
);
825 typedef void (*op3fn
)(TCGv ret
, TCGv arg1
, TCGv arg2
);
827 static inline void rx_gen_op_rr(op2fn opr
, int dst
, int src
)
829 opr(cpu_regs
[dst
], cpu_regs
[src
]);
832 static inline void rx_gen_op_rrr(op3fn opr
, int dst
, int src
, int src2
)
834 opr(cpu_regs
[dst
], cpu_regs
[src
], cpu_regs
[src2
]);
837 static inline void rx_gen_op_irr(op3fn opr
, int dst
, int src
, uint32_t src2
)
839 TCGv imm
= tcg_const_i32(src2
);
840 opr(cpu_regs
[dst
], cpu_regs
[src
], imm
);
844 static inline void rx_gen_op_mr(op3fn opr
, DisasContext
*ctx
,
845 int dst
, int src
, int ld
, int mi
)
848 mem
= tcg_temp_new();
849 val
= rx_load_source(ctx
, mem
, ld
, mi
, src
);
850 opr(cpu_regs
[dst
], cpu_regs
[dst
], val
);
854 static void rx_and(TCGv ret
, TCGv arg1
, TCGv arg2
)
856 tcg_gen_and_i32(cpu_psw_s
, arg1
, arg2
);
857 tcg_gen_mov_i32(cpu_psw_z
, cpu_psw_s
);
858 tcg_gen_mov_i32(ret
, cpu_psw_s
);
861 /* and #uimm:4, rd */
863 static bool trans_AND_ir(DisasContext
*ctx
, arg_AND_ir
*a
)
865 rx_gen_op_irr(rx_and
, a
->rd
, a
->rd
, a
->imm
);
869 /* and dsp[rs], rd */
871 static bool trans_AND_mr(DisasContext
*ctx
, arg_AND_mr
*a
)
873 rx_gen_op_mr(rx_and
, ctx
, a
->rd
, a
->rs
, a
->ld
, a
->mi
);
878 static bool trans_AND_rrr(DisasContext
*ctx
, arg_AND_rrr
*a
)
880 rx_gen_op_rrr(rx_and
, a
->rd
, a
->rs
, a
->rs2
);
884 static void rx_or(TCGv ret
, TCGv arg1
, TCGv arg2
)
886 tcg_gen_or_i32(cpu_psw_s
, arg1
, arg2
);
887 tcg_gen_mov_i32(cpu_psw_z
, cpu_psw_s
);
888 tcg_gen_mov_i32(ret
, cpu_psw_s
);
893 static bool trans_OR_ir(DisasContext
*ctx
, arg_OR_ir
*a
)
895 rx_gen_op_irr(rx_or
, a
->rd
, a
->rd
, a
->imm
);
901 static bool trans_OR_mr(DisasContext
*ctx
, arg_OR_mr
*a
)
903 rx_gen_op_mr(rx_or
, ctx
, a
->rd
, a
->rs
, a
->ld
, a
->mi
);
908 static bool trans_OR_rrr(DisasContext
*ctx
, arg_OR_rrr
*a
)
910 rx_gen_op_rrr(rx_or
, a
->rd
, a
->rs
, a
->rs2
);
914 static void rx_xor(TCGv ret
, TCGv arg1
, TCGv arg2
)
916 tcg_gen_xor_i32(cpu_psw_s
, arg1
, arg2
);
917 tcg_gen_mov_i32(cpu_psw_z
, cpu_psw_s
);
918 tcg_gen_mov_i32(ret
, cpu_psw_s
);
922 static bool trans_XOR_ir(DisasContext
*ctx
, arg_XOR_ir
*a
)
924 rx_gen_op_irr(rx_xor
, a
->rd
, a
->rd
, a
->imm
);
928 /* xor dsp[rs], rd */
930 static bool trans_XOR_mr(DisasContext
*ctx
, arg_XOR_mr
*a
)
932 rx_gen_op_mr(rx_xor
, ctx
, a
->rd
, a
->rs
, a
->ld
, a
->mi
);
936 static void rx_tst(TCGv ret
, TCGv arg1
, TCGv arg2
)
938 tcg_gen_and_i32(cpu_psw_s
, arg1
, arg2
);
939 tcg_gen_mov_i32(cpu_psw_z
, cpu_psw_s
);
943 static bool trans_TST_ir(DisasContext
*ctx
, arg_TST_ir
*a
)
945 rx_gen_op_irr(rx_tst
, a
->rd
, a
->rd
, a
->imm
);
949 /* tst dsp[rs], rd */
951 static bool trans_TST_mr(DisasContext
*ctx
, arg_TST_mr
*a
)
953 rx_gen_op_mr(rx_tst
, ctx
, a
->rd
, a
->rs
, a
->ld
, a
->mi
);
957 static void rx_not(TCGv ret
, TCGv arg1
)
959 tcg_gen_not_i32(ret
, arg1
);
960 tcg_gen_mov_i32(cpu_psw_z
, ret
);
961 tcg_gen_mov_i32(cpu_psw_s
, ret
);
966 static bool trans_NOT_rr(DisasContext
*ctx
, arg_NOT_rr
*a
)
968 rx_gen_op_rr(rx_not
, a
->rd
, a
->rs
);
972 static void rx_neg(TCGv ret
, TCGv arg1
)
974 tcg_gen_setcondi_i32(TCG_COND_EQ
, cpu_psw_o
, arg1
, 0x80000000);
975 tcg_gen_neg_i32(ret
, arg1
);
976 tcg_gen_setcondi_i32(TCG_COND_EQ
, cpu_psw_c
, ret
, 0);
977 tcg_gen_mov_i32(cpu_psw_z
, ret
);
978 tcg_gen_mov_i32(cpu_psw_s
, ret
);
984 static bool trans_NEG_rr(DisasContext
*ctx
, arg_NEG_rr
*a
)
986 rx_gen_op_rr(rx_neg
, a
->rd
, a
->rs
);
990 /* ret = arg1 + arg2 + psw_c */
991 static void rx_adc(TCGv ret
, TCGv arg1
, TCGv arg2
)
994 z
= tcg_const_i32(0);
995 tcg_gen_add2_i32(cpu_psw_s
, cpu_psw_c
, arg1
, z
, cpu_psw_c
, z
);
996 tcg_gen_add2_i32(cpu_psw_s
, cpu_psw_c
, cpu_psw_s
, cpu_psw_c
, arg2
, z
);
997 tcg_gen_mov_i32(cpu_psw_z
, cpu_psw_s
);
998 tcg_gen_xor_i32(cpu_psw_o
, cpu_psw_s
, arg1
);
999 tcg_gen_xor_i32(z
, arg1
, arg2
);
1000 tcg_gen_andc_i32(cpu_psw_o
, cpu_psw_o
, z
);
1001 tcg_gen_mov_i32(ret
, cpu_psw_s
);
1006 static bool trans_ADC_ir(DisasContext
*ctx
, arg_ADC_ir
*a
)
1008 rx_gen_op_irr(rx_adc
, a
->rd
, a
->rd
, a
->imm
);
1013 static bool trans_ADC_rr(DisasContext
*ctx
, arg_ADC_rr
*a
)
1015 rx_gen_op_rrr(rx_adc
, a
->rd
, a
->rd
, a
->rs
);
1019 /* adc dsp[rs], rd */
1020 static bool trans_ADC_mr(DisasContext
*ctx
, arg_ADC_mr
*a
)
1026 rx_gen_op_mr(rx_adc
, ctx
, a
->rd
, a
->rs
, a
->ld
, a
->mi
);
1030 /* ret = arg1 + arg2 */
1031 static void rx_add(TCGv ret
, TCGv arg1
, TCGv arg2
)
1034 z
= tcg_const_i32(0);
1035 tcg_gen_add2_i32(cpu_psw_s
, cpu_psw_c
, arg1
, z
, arg2
, z
);
1036 tcg_gen_mov_i32(cpu_psw_z
, cpu_psw_s
);
1037 tcg_gen_xor_i32(cpu_psw_o
, cpu_psw_s
, arg1
);
1038 tcg_gen_xor_i32(z
, arg1
, arg2
);
1039 tcg_gen_andc_i32(cpu_psw_o
, cpu_psw_o
, z
);
1040 tcg_gen_mov_i32(ret
, cpu_psw_s
);
1044 /* add #uimm4, rd */
1045 /* add #imm, rs, rd */
1046 static bool trans_ADD_irr(DisasContext
*ctx
, arg_ADD_irr
*a
)
1048 rx_gen_op_irr(rx_add
, a
->rd
, a
->rs2
, a
->imm
);
1053 /* add dsp[rs], rd */
1054 static bool trans_ADD_mr(DisasContext
*ctx
, arg_ADD_mr
*a
)
1056 rx_gen_op_mr(rx_add
, ctx
, a
->rd
, a
->rs
, a
->ld
, a
->mi
);
1060 /* add rs, rs2, rd */
1061 static bool trans_ADD_rrr(DisasContext
*ctx
, arg_ADD_rrr
*a
)
1063 rx_gen_op_rrr(rx_add
, a
->rd
, a
->rs
, a
->rs2
);
1067 /* ret = arg1 - arg2 */
1068 static void rx_sub(TCGv ret
, TCGv arg1
, TCGv arg2
)
1071 tcg_gen_sub_i32(cpu_psw_s
, arg1
, arg2
);
1072 tcg_gen_mov_i32(cpu_psw_z
, cpu_psw_s
);
1073 tcg_gen_setcond_i32(TCG_COND_GEU
, cpu_psw_c
, arg1
, arg2
);
1074 tcg_gen_xor_i32(cpu_psw_o
, cpu_psw_s
, arg1
);
1075 temp
= tcg_temp_new_i32();
1076 tcg_gen_xor_i32(temp
, arg1
, arg2
);
1077 tcg_gen_and_i32(cpu_psw_o
, cpu_psw_o
, temp
);
1078 tcg_temp_free_i32(temp
);
1079 /* CMP not required return */
1081 tcg_gen_mov_i32(ret
, cpu_psw_s
);
1084 static void rx_cmp(TCGv dummy
, TCGv arg1
, TCGv arg2
)
1086 rx_sub(NULL
, arg1
, arg2
);
1088 /* ret = arg1 - arg2 - !psw_c */
1089 /* -> ret = arg1 + ~arg2 + psw_c */
1090 static void rx_sbb(TCGv ret
, TCGv arg1
, TCGv arg2
)
1093 temp
= tcg_temp_new();
1094 tcg_gen_not_i32(temp
, arg2
);
1095 rx_adc(ret
, arg1
, temp
);
1096 tcg_temp_free(temp
);
1099 /* cmp #imm4, rs2 */
1100 /* cmp #imm8, rs2 */
1102 static bool trans_CMP_ir(DisasContext
*ctx
, arg_CMP_ir
*a
)
1104 rx_gen_op_irr(rx_cmp
, 0, a
->rs2
, a
->imm
);
1109 /* cmp dsp[rs], rs2 */
1110 static bool trans_CMP_mr(DisasContext
*ctx
, arg_CMP_mr
*a
)
1112 rx_gen_op_mr(rx_cmp
, ctx
, a
->rd
, a
->rs
, a
->ld
, a
->mi
);
1117 static bool trans_SUB_ir(DisasContext
*ctx
, arg_SUB_ir
*a
)
1119 rx_gen_op_irr(rx_sub
, a
->rd
, a
->rd
, a
->imm
);
1124 /* sub dsp[rs], rd */
1125 static bool trans_SUB_mr(DisasContext
*ctx
, arg_SUB_mr
*a
)
1127 rx_gen_op_mr(rx_sub
, ctx
, a
->rd
, a
->rs
, a
->ld
, a
->mi
);
1131 /* sub rs2, rs, rd */
1132 static bool trans_SUB_rrr(DisasContext
*ctx
, arg_SUB_rrr
*a
)
1134 rx_gen_op_rrr(rx_sub
, a
->rd
, a
->rs2
, a
->rs
);
1139 static bool trans_SBB_rr(DisasContext
*ctx
, arg_SBB_rr
*a
)
1141 rx_gen_op_rrr(rx_sbb
, a
->rd
, a
->rd
, a
->rs
);
1145 /* sbb dsp[rs], rd */
1146 static bool trans_SBB_mr(DisasContext
*ctx
, arg_SBB_mr
*a
)
1152 rx_gen_op_mr(rx_sbb
, ctx
, a
->rd
, a
->rs
, a
->ld
, a
->mi
);
1156 static void rx_abs(TCGv ret
, TCGv arg1
)
1160 neg
= tcg_temp_new();
1161 zero
= tcg_const_i32(0);
1162 tcg_gen_neg_i32(neg
, arg1
);
1163 tcg_gen_movcond_i32(TCG_COND_LT
, ret
, arg1
, zero
, neg
, arg1
);
1165 tcg_temp_free(zero
);
1170 static bool trans_ABS_rr(DisasContext
*ctx
, arg_ABS_rr
*a
)
1172 rx_gen_op_rr(rx_abs
, a
->rd
, a
->rs
);
1177 static bool trans_MAX_ir(DisasContext
*ctx
, arg_MAX_ir
*a
)
1179 rx_gen_op_irr(tcg_gen_smax_i32
, a
->rd
, a
->rd
, a
->imm
);
1184 /* max dsp[rs], rd */
1185 static bool trans_MAX_mr(DisasContext
*ctx
, arg_MAX_mr
*a
)
1187 rx_gen_op_mr(tcg_gen_smax_i32
, ctx
, a
->rd
, a
->rs
, a
->ld
, a
->mi
);
1192 static bool trans_MIN_ir(DisasContext
*ctx
, arg_MIN_ir
*a
)
1194 rx_gen_op_irr(tcg_gen_smin_i32
, a
->rd
, a
->rd
, a
->imm
);
1199 /* min dsp[rs], rd */
1200 static bool trans_MIN_mr(DisasContext
*ctx
, arg_MIN_mr
*a
)
1202 rx_gen_op_mr(tcg_gen_smin_i32
, ctx
, a
->rd
, a
->rs
, a
->ld
, a
->mi
);
1206 /* mul #uimm4, rd */
1208 static bool trans_MUL_ir(DisasContext
*ctx
, arg_MUL_ir
*a
)
1210 rx_gen_op_irr(tcg_gen_mul_i32
, a
->rd
, a
->rd
, a
->imm
);
1215 /* mul dsp[rs], rd */
1216 static bool trans_MUL_mr(DisasContext
*ctx
, arg_MUL_mr
*a
)
1218 rx_gen_op_mr(tcg_gen_mul_i32
, ctx
, a
->rd
, a
->rs
, a
->ld
, a
->mi
);
1222 /* mul rs, rs2, rd */
1223 static bool trans_MUL_rrr(DisasContext
*ctx
, arg_MUL_rrr
*a
)
1225 rx_gen_op_rrr(tcg_gen_mul_i32
, a
->rd
, a
->rs
, a
->rs2
);
1230 static bool trans_EMUL_ir(DisasContext
*ctx
, arg_EMUL_ir
*a
)
1232 TCGv imm
= tcg_const_i32(a
->imm
);
1234 qemu_log_mask(LOG_GUEST_ERROR
, "rd too large %d", a
->rd
);
1236 tcg_gen_muls2_i32(cpu_regs
[a
->rd
], cpu_regs
[(a
->rd
+ 1) & 15],
1237 cpu_regs
[a
->rd
], imm
);
1243 /* emul dsp[rs], rd */
1244 static bool trans_EMUL_mr(DisasContext
*ctx
, arg_EMUL_mr
*a
)
1248 qemu_log_mask(LOG_GUEST_ERROR
, "rd too large %d", a
->rd
);
1250 mem
= tcg_temp_new();
1251 val
= rx_load_source(ctx
, mem
, a
->ld
, a
->mi
, a
->rs
);
1252 tcg_gen_muls2_i32(cpu_regs
[a
->rd
], cpu_regs
[(a
->rd
+ 1) & 15],
1253 cpu_regs
[a
->rd
], val
);
1258 /* emulu #imm, rd */
1259 static bool trans_EMULU_ir(DisasContext
*ctx
, arg_EMULU_ir
*a
)
1261 TCGv imm
= tcg_const_i32(a
->imm
);
1263 qemu_log_mask(LOG_GUEST_ERROR
, "rd too large %d", a
->rd
);
1265 tcg_gen_mulu2_i32(cpu_regs
[a
->rd
], cpu_regs
[(a
->rd
+ 1) & 15],
1266 cpu_regs
[a
->rd
], imm
);
1272 /* emulu dsp[rs], rd */
1273 static bool trans_EMULU_mr(DisasContext
*ctx
, arg_EMULU_mr
*a
)
1277 qemu_log_mask(LOG_GUEST_ERROR
, "rd too large %d", a
->rd
);
1279 mem
= tcg_temp_new();
1280 val
= rx_load_source(ctx
, mem
, a
->ld
, a
->mi
, a
->rs
);
1281 tcg_gen_mulu2_i32(cpu_regs
[a
->rd
], cpu_regs
[(a
->rd
+ 1) & 15],
1282 cpu_regs
[a
->rd
], val
);
1287 static void rx_div(TCGv ret
, TCGv arg1
, TCGv arg2
)
1289 gen_helper_div(ret
, cpu_env
, arg1
, arg2
);
1292 static void rx_divu(TCGv ret
, TCGv arg1
, TCGv arg2
)
1294 gen_helper_divu(ret
, cpu_env
, arg1
, arg2
);
1298 static bool trans_DIV_ir(DisasContext
*ctx
, arg_DIV_ir
*a
)
1300 rx_gen_op_irr(rx_div
, a
->rd
, a
->rd
, a
->imm
);
1305 /* div dsp[rs], rd */
1306 static bool trans_DIV_mr(DisasContext
*ctx
, arg_DIV_mr
*a
)
1308 rx_gen_op_mr(rx_div
, ctx
, a
->rd
, a
->rs
, a
->ld
, a
->mi
);
1313 static bool trans_DIVU_ir(DisasContext
*ctx
, arg_DIVU_ir
*a
)
1315 rx_gen_op_irr(rx_divu
, a
->rd
, a
->rd
, a
->imm
);
1320 /* divu dsp[rs], rd */
1321 static bool trans_DIVU_mr(DisasContext
*ctx
, arg_DIVU_mr
*a
)
1323 rx_gen_op_mr(rx_divu
, ctx
, a
->rd
, a
->rs
, a
->ld
, a
->mi
);
1328 /* shll #imm:5, rd */
1329 /* shll #imm:5, rs2, rd */
1330 static bool trans_SHLL_irr(DisasContext
*ctx
, arg_SHLL_irr
*a
)
1333 tmp
= tcg_temp_new();
1335 tcg_gen_sari_i32(cpu_psw_c
, cpu_regs
[a
->rs2
], 32 - a
->imm
);
1336 tcg_gen_shli_i32(cpu_regs
[a
->rd
], cpu_regs
[a
->rs2
], a
->imm
);
1337 tcg_gen_setcondi_i32(TCG_COND_EQ
, cpu_psw_o
, cpu_psw_c
, 0);
1338 tcg_gen_setcondi_i32(TCG_COND_EQ
, tmp
, cpu_psw_c
, 0xffffffff);
1339 tcg_gen_or_i32(cpu_psw_o
, cpu_psw_o
, tmp
);
1340 tcg_gen_setcondi_i32(TCG_COND_NE
, cpu_psw_c
, cpu_psw_c
, 0);
1342 tcg_gen_mov_i32(cpu_regs
[a
->rd
], cpu_regs
[a
->rs2
]);
1343 tcg_gen_movi_i32(cpu_psw_c
, 0);
1344 tcg_gen_movi_i32(cpu_psw_o
, 0);
1346 tcg_gen_mov_i32(cpu_psw_z
, cpu_regs
[a
->rd
]);
1347 tcg_gen_mov_i32(cpu_psw_s
, cpu_regs
[a
->rd
]);
1352 static bool trans_SHLL_rr(DisasContext
*ctx
, arg_SHLL_rr
*a
)
1354 TCGLabel
*noshift
, *done
;
1357 noshift
= gen_new_label();
1358 done
= gen_new_label();
1359 /* if (cpu_regs[a->rs]) { */
1360 tcg_gen_brcondi_i32(TCG_COND_EQ
, cpu_regs
[a
->rs
], 0, noshift
);
1361 count
= tcg_const_i32(32);
1362 tmp
= tcg_temp_new();
1363 tcg_gen_andi_i32(tmp
, cpu_regs
[a
->rs
], 31);
1364 tcg_gen_sub_i32(count
, count
, tmp
);
1365 tcg_gen_sar_i32(cpu_psw_c
, cpu_regs
[a
->rd
], count
);
1366 tcg_gen_shl_i32(cpu_regs
[a
->rd
], cpu_regs
[a
->rd
], tmp
);
1367 tcg_gen_setcondi_i32(TCG_COND_EQ
, cpu_psw_o
, cpu_psw_c
, 0);
1368 tcg_gen_setcondi_i32(TCG_COND_EQ
, tmp
, cpu_psw_c
, 0xffffffff);
1369 tcg_gen_or_i32(cpu_psw_o
, cpu_psw_o
, tmp
);
1370 tcg_gen_setcondi_i32(TCG_COND_NE
, cpu_psw_c
, cpu_psw_c
, 0);
1373 gen_set_label(noshift
);
1374 tcg_gen_movi_i32(cpu_psw_c
, 0);
1375 tcg_gen_movi_i32(cpu_psw_o
, 0);
1377 gen_set_label(done
);
1378 tcg_gen_mov_i32(cpu_psw_z
, cpu_regs
[a
->rd
]);
1379 tcg_gen_mov_i32(cpu_psw_s
, cpu_regs
[a
->rd
]);
1380 tcg_temp_free(count
);
1385 static inline void shiftr_imm(uint32_t rd
, uint32_t rs
, uint32_t imm
,
1388 static void (* const gen_sXri
[])(TCGv ret
, TCGv arg1
, int arg2
) = {
1389 tcg_gen_shri_i32
, tcg_gen_sari_i32
,
1391 tcg_debug_assert(alith
< 2);
1393 gen_sXri
[alith
](cpu_regs
[rd
], cpu_regs
[rs
], imm
- 1);
1394 tcg_gen_andi_i32(cpu_psw_c
, cpu_regs
[rd
], 0x00000001);
1395 gen_sXri
[alith
](cpu_regs
[rd
], cpu_regs
[rd
], 1);
1397 tcg_gen_mov_i32(cpu_regs
[rd
], cpu_regs
[rs
]);
1398 tcg_gen_movi_i32(cpu_psw_c
, 0);
1400 tcg_gen_movi_i32(cpu_psw_o
, 0);
1401 tcg_gen_mov_i32(cpu_psw_z
, cpu_regs
[rd
]);
1402 tcg_gen_mov_i32(cpu_psw_s
, cpu_regs
[rd
]);
1405 static inline void shiftr_reg(uint32_t rd
, uint32_t rs
, unsigned int alith
)
1407 TCGLabel
*noshift
, *done
;
1409 static void (* const gen_sXri
[])(TCGv ret
, TCGv arg1
, int arg2
) = {
1410 tcg_gen_shri_i32
, tcg_gen_sari_i32
,
1412 static void (* const gen_sXr
[])(TCGv ret
, TCGv arg1
, TCGv arg2
) = {
1413 tcg_gen_shr_i32
, tcg_gen_sar_i32
,
1415 tcg_debug_assert(alith
< 2);
1416 noshift
= gen_new_label();
1417 done
= gen_new_label();
1418 count
= tcg_temp_new();
1419 /* if (cpu_regs[rs]) { */
1420 tcg_gen_brcondi_i32(TCG_COND_EQ
, cpu_regs
[rs
], 0, noshift
);
1421 tcg_gen_andi_i32(count
, cpu_regs
[rs
], 31);
1422 tcg_gen_subi_i32(count
, count
, 1);
1423 gen_sXr
[alith
](cpu_regs
[rd
], cpu_regs
[rd
], count
);
1424 tcg_gen_andi_i32(cpu_psw_c
, cpu_regs
[rd
], 0x00000001);
1425 gen_sXri
[alith
](cpu_regs
[rd
], cpu_regs
[rd
], 1);
1428 gen_set_label(noshift
);
1429 tcg_gen_movi_i32(cpu_psw_c
, 0);
1431 gen_set_label(done
);
1432 tcg_gen_movi_i32(cpu_psw_o
, 0);
1433 tcg_gen_mov_i32(cpu_psw_z
, cpu_regs
[rd
]);
1434 tcg_gen_mov_i32(cpu_psw_s
, cpu_regs
[rd
]);
1435 tcg_temp_free(count
);
1438 /* shar #imm:5, rd */
1439 /* shar #imm:5, rs2, rd */
1440 static bool trans_SHAR_irr(DisasContext
*ctx
, arg_SHAR_irr
*a
)
1442 shiftr_imm(a
->rd
, a
->rs2
, a
->imm
, 1);
1447 static bool trans_SHAR_rr(DisasContext
*ctx
, arg_SHAR_rr
*a
)
1449 shiftr_reg(a
->rd
, a
->rs
, 1);
1453 /* shlr #imm:5, rd */
1454 /* shlr #imm:5, rs2, rd */
1455 static bool trans_SHLR_irr(DisasContext
*ctx
, arg_SHLR_irr
*a
)
1457 shiftr_imm(a
->rd
, a
->rs2
, a
->imm
, 0);
1462 static bool trans_SHLR_rr(DisasContext
*ctx
, arg_SHLR_rr
*a
)
1464 shiftr_reg(a
->rd
, a
->rs
, 0);
1469 static bool trans_ROLC(DisasContext
*ctx
, arg_ROLC
*a
)
1472 tmp
= tcg_temp_new();
1473 tcg_gen_shri_i32(tmp
, cpu_regs
[a
->rd
], 31);
1474 tcg_gen_shli_i32(cpu_regs
[a
->rd
], cpu_regs
[a
->rd
], 1);
1475 tcg_gen_or_i32(cpu_regs
[a
->rd
], cpu_regs
[a
->rd
], cpu_psw_c
);
1476 tcg_gen_mov_i32(cpu_psw_c
, tmp
);
1477 tcg_gen_mov_i32(cpu_psw_z
, cpu_regs
[a
->rd
]);
1478 tcg_gen_mov_i32(cpu_psw_s
, cpu_regs
[a
->rd
]);
1484 static bool trans_RORC(DisasContext
*ctx
, arg_RORC
*a
)
1487 tmp
= tcg_temp_new();
1488 tcg_gen_andi_i32(tmp
, cpu_regs
[a
->rd
], 0x00000001);
1489 tcg_gen_shri_i32(cpu_regs
[a
->rd
], cpu_regs
[a
->rd
], 1);
1490 tcg_gen_shli_i32(cpu_psw_c
, cpu_psw_c
, 31);
1491 tcg_gen_or_i32(cpu_regs
[a
->rd
], cpu_regs
[a
->rd
], cpu_psw_c
);
1492 tcg_gen_mov_i32(cpu_psw_c
, tmp
);
1493 tcg_gen_mov_i32(cpu_psw_z
, cpu_regs
[a
->rd
]);
1494 tcg_gen_mov_i32(cpu_psw_s
, cpu_regs
[a
->rd
]);
1498 enum {ROTR
= 0, ROTL
= 1};
1499 enum {ROT_IMM
= 0, ROT_REG
= 1};
1500 static inline void rx_rot(int ir
, int dir
, int rd
, int src
)
1504 if (ir
== ROT_IMM
) {
1505 tcg_gen_rotli_i32(cpu_regs
[rd
], cpu_regs
[rd
], src
);
1507 tcg_gen_rotl_i32(cpu_regs
[rd
], cpu_regs
[rd
], cpu_regs
[src
]);
1509 tcg_gen_andi_i32(cpu_psw_c
, cpu_regs
[rd
], 0x00000001);
1512 if (ir
== ROT_IMM
) {
1513 tcg_gen_rotri_i32(cpu_regs
[rd
], cpu_regs
[rd
], src
);
1515 tcg_gen_rotr_i32(cpu_regs
[rd
], cpu_regs
[rd
], cpu_regs
[src
]);
1517 tcg_gen_shri_i32(cpu_psw_c
, cpu_regs
[rd
], 31);
1520 tcg_gen_mov_i32(cpu_psw_z
, cpu_regs
[rd
]);
1521 tcg_gen_mov_i32(cpu_psw_s
, cpu_regs
[rd
]);
1525 static bool trans_ROTL_ir(DisasContext
*ctx
, arg_ROTL_ir
*a
)
1527 rx_rot(ROT_IMM
, ROTL
, a
->rd
, a
->imm
);
1532 static bool trans_ROTL_rr(DisasContext
*ctx
, arg_ROTL_rr
*a
)
1534 rx_rot(ROT_REG
, ROTL
, a
->rd
, a
->rs
);
1539 static bool trans_ROTR_ir(DisasContext
*ctx
, arg_ROTR_ir
*a
)
1541 rx_rot(ROT_IMM
, ROTR
, a
->rd
, a
->imm
);
1546 static bool trans_ROTR_rr(DisasContext
*ctx
, arg_ROTR_rr
*a
)
1548 rx_rot(ROT_REG
, ROTR
, a
->rd
, a
->rs
);
1553 static bool trans_REVL(DisasContext
*ctx
, arg_REVL
*a
)
1555 tcg_gen_bswap32_i32(cpu_regs
[a
->rd
], cpu_regs
[a
->rs
]);
1560 static bool trans_REVW(DisasContext
*ctx
, arg_REVW
*a
)
1563 tmp
= tcg_temp_new();
1564 tcg_gen_andi_i32(tmp
, cpu_regs
[a
->rs
], 0x00ff00ff);
1565 tcg_gen_shli_i32(tmp
, tmp
, 8);
1566 tcg_gen_shri_i32(cpu_regs
[a
->rd
], cpu_regs
[a
->rs
], 8);
1567 tcg_gen_andi_i32(cpu_regs
[a
->rd
], cpu_regs
[a
->rd
], 0x00ff00ff);
1568 tcg_gen_or_i32(cpu_regs
[a
->rd
], cpu_regs
[a
->rd
], tmp
);
1573 /* conditional branch helper */
1574 static void rx_bcnd_main(DisasContext
*ctx
, int cd
, int dst
)
1581 dc
.temp
= tcg_temp_new();
1583 t
= gen_new_label();
1584 done
= gen_new_label();
1585 tcg_gen_brcondi_i32(dc
.cond
, dc
.value
, 0, t
);
1586 gen_goto_tb(ctx
, 0, ctx
->base
.pc_next
);
1589 gen_goto_tb(ctx
, 1, ctx
->pc
+ dst
);
1590 gen_set_label(done
);
1591 tcg_temp_free(dc
.temp
);
1594 /* always true case */
1595 gen_goto_tb(ctx
, 0, ctx
->pc
+ dst
);
1598 /* always false case */
1604 /* beq dsp:3 / bne dsp:3 */
1605 /* beq dsp:8 / bne dsp:8 */
1606 /* bc dsp:8 / bnc dsp:8 */
1607 /* bgtu dsp:8 / bleu dsp:8 */
1608 /* bpz dsp:8 / bn dsp:8 */
1609 /* bge dsp:8 / blt dsp:8 */
1610 /* bgt dsp:8 / ble dsp:8 */
1611 /* bo dsp:8 / bno dsp:8 */
1612 /* beq dsp:16 / bne dsp:16 */
1613 static bool trans_BCnd(DisasContext
*ctx
, arg_BCnd
*a
)
1615 rx_bcnd_main(ctx
, a
->cd
, a
->dsp
);
1623 static bool trans_BRA(DisasContext
*ctx
, arg_BRA
*a
)
1625 rx_bcnd_main(ctx
, 14, a
->dsp
);
1630 static bool trans_BRA_l(DisasContext
*ctx
, arg_BRA_l
*a
)
1632 tcg_gen_addi_i32(cpu_pc
, cpu_regs
[a
->rd
], ctx
->pc
);
1633 ctx
->base
.is_jmp
= DISAS_JUMP
;
1637 static inline void rx_save_pc(DisasContext
*ctx
)
1639 TCGv pc
= tcg_const_i32(ctx
->base
.pc_next
);
1645 static bool trans_JMP(DisasContext
*ctx
, arg_JMP
*a
)
1647 tcg_gen_mov_i32(cpu_pc
, cpu_regs
[a
->rs
]);
1648 ctx
->base
.is_jmp
= DISAS_JUMP
;
1653 static bool trans_JSR(DisasContext
*ctx
, arg_JSR
*a
)
1656 tcg_gen_mov_i32(cpu_pc
, cpu_regs
[a
->rs
]);
1657 ctx
->base
.is_jmp
= DISAS_JUMP
;
1663 static bool trans_BSR(DisasContext
*ctx
, arg_BSR
*a
)
1666 rx_bcnd_main(ctx
, 14, a
->dsp
);
1671 static bool trans_BSR_l(DisasContext
*ctx
, arg_BSR_l
*a
)
1674 tcg_gen_addi_i32(cpu_pc
, cpu_regs
[a
->rd
], ctx
->pc
);
1675 ctx
->base
.is_jmp
= DISAS_JUMP
;
1680 static bool trans_RTS(DisasContext
*ctx
, arg_RTS
*a
)
1683 ctx
->base
.is_jmp
= DISAS_JUMP
;
1688 static bool trans_NOP(DisasContext
*ctx
, arg_NOP
*a
)
1694 static bool trans_SCMPU(DisasContext
*ctx
, arg_SCMPU
*a
)
1696 gen_helper_scmpu(cpu_env
);
1701 static bool trans_SMOVU(DisasContext
*ctx
, arg_SMOVU
*a
)
1703 gen_helper_smovu(cpu_env
);
1708 static bool trans_SMOVF(DisasContext
*ctx
, arg_SMOVF
*a
)
1710 gen_helper_smovf(cpu_env
);
1715 static bool trans_SMOVB(DisasContext
*ctx
, arg_SMOVB
*a
)
1717 gen_helper_smovb(cpu_env
);
1721 #define STRING(op) \
1723 TCGv size = tcg_const_i32(a->sz); \
1724 gen_helper_##op(cpu_env, size); \
1725 tcg_temp_free(size); \
1729 static bool trans_SUNTIL(DisasContext
*ctx
, arg_SUNTIL
*a
)
1736 static bool trans_SWHILE(DisasContext
*ctx
, arg_SWHILE
*a
)
1742 static bool trans_SSTR(DisasContext
*ctx
, arg_SSTR
*a
)
1749 static bool trans_RMPA(DisasContext
*ctx
, arg_RMPA
*a
)
1755 static void rx_mul64hi(TCGv_i64 ret
, int rs
, int rs2
)
1757 TCGv_i64 tmp0
, tmp1
;
1758 tmp0
= tcg_temp_new_i64();
1759 tmp1
= tcg_temp_new_i64();
1760 tcg_gen_ext_i32_i64(tmp0
, cpu_regs
[rs
]);
1761 tcg_gen_sari_i64(tmp0
, tmp0
, 16);
1762 tcg_gen_ext_i32_i64(tmp1
, cpu_regs
[rs2
]);
1763 tcg_gen_sari_i64(tmp1
, tmp1
, 16);
1764 tcg_gen_mul_i64(ret
, tmp0
, tmp1
);
1765 tcg_gen_shli_i64(ret
, ret
, 16);
1766 tcg_temp_free_i64(tmp0
);
1767 tcg_temp_free_i64(tmp1
);
1770 static void rx_mul64lo(TCGv_i64 ret
, int rs
, int rs2
)
1772 TCGv_i64 tmp0
, tmp1
;
1773 tmp0
= tcg_temp_new_i64();
1774 tmp1
= tcg_temp_new_i64();
1775 tcg_gen_ext_i32_i64(tmp0
, cpu_regs
[rs
]);
1776 tcg_gen_ext16s_i64(tmp0
, tmp0
);
1777 tcg_gen_ext_i32_i64(tmp1
, cpu_regs
[rs2
]);
1778 tcg_gen_ext16s_i64(tmp1
, tmp1
);
1779 tcg_gen_mul_i64(ret
, tmp0
, tmp1
);
1780 tcg_gen_shli_i64(ret
, ret
, 16);
1781 tcg_temp_free_i64(tmp0
);
1782 tcg_temp_free_i64(tmp1
);
1786 static bool trans_MULHI(DisasContext
*ctx
, arg_MULHI
*a
)
1788 rx_mul64hi(cpu_acc
, a
->rs
, a
->rs2
);
1793 static bool trans_MULLO(DisasContext
*ctx
, arg_MULLO
*a
)
1795 rx_mul64lo(cpu_acc
, a
->rs
, a
->rs2
);
1800 static bool trans_MACHI(DisasContext
*ctx
, arg_MACHI
*a
)
1803 tmp
= tcg_temp_new_i64();
1804 rx_mul64hi(tmp
, a
->rs
, a
->rs2
);
1805 tcg_gen_add_i64(cpu_acc
, cpu_acc
, tmp
);
1806 tcg_temp_free_i64(tmp
);
1811 static bool trans_MACLO(DisasContext
*ctx
, arg_MACLO
*a
)
1814 tmp
= tcg_temp_new_i64();
1815 rx_mul64lo(tmp
, a
->rs
, a
->rs2
);
1816 tcg_gen_add_i64(cpu_acc
, cpu_acc
, tmp
);
1817 tcg_temp_free_i64(tmp
);
1822 static bool trans_MVFACHI(DisasContext
*ctx
, arg_MVFACHI
*a
)
1824 tcg_gen_extrh_i64_i32(cpu_regs
[a
->rd
], cpu_acc
);
1829 static bool trans_MVFACMI(DisasContext
*ctx
, arg_MVFACMI
*a
)
1832 rd64
= tcg_temp_new_i64();
1833 tcg_gen_extract_i64(rd64
, cpu_acc
, 16, 32);
1834 tcg_gen_extrl_i64_i32(cpu_regs
[a
->rd
], rd64
);
1835 tcg_temp_free_i64(rd64
);
1840 static bool trans_MVTACHI(DisasContext
*ctx
, arg_MVTACHI
*a
)
1843 rs64
= tcg_temp_new_i64();
1844 tcg_gen_extu_i32_i64(rs64
, cpu_regs
[a
->rs
]);
1845 tcg_gen_deposit_i64(cpu_acc
, cpu_acc
, rs64
, 32, 32);
1846 tcg_temp_free_i64(rs64
);
1851 static bool trans_MVTACLO(DisasContext
*ctx
, arg_MVTACLO
*a
)
1854 rs64
= tcg_temp_new_i64();
1855 tcg_gen_extu_i32_i64(rs64
, cpu_regs
[a
->rs
]);
1856 tcg_gen_deposit_i64(cpu_acc
, cpu_acc
, rs64
, 0, 32);
1857 tcg_temp_free_i64(rs64
);
1862 static bool trans_RACW(DisasContext
*ctx
, arg_RACW
*a
)
1864 TCGv imm
= tcg_const_i32(a
->imm
+ 1);
1865 gen_helper_racw(cpu_env
, imm
);
1871 static bool trans_SAT(DisasContext
*ctx
, arg_SAT
*a
)
1874 tmp
= tcg_temp_new();
1875 z
= tcg_const_i32(0);
1876 /* S == 1 -> 0xffffffff / S == 0 -> 0x00000000 */
1877 tcg_gen_sari_i32(tmp
, cpu_psw_s
, 31);
1878 /* S == 1 -> 0x7fffffff / S == 0 -> 0x80000000 */
1879 tcg_gen_xori_i32(tmp
, tmp
, 0x80000000);
1880 tcg_gen_movcond_i32(TCG_COND_LT
, cpu_regs
[a
->rd
],
1881 cpu_psw_o
, z
, tmp
, cpu_regs
[a
->rd
]);
1888 static bool trans_SATR(DisasContext
*ctx
, arg_SATR
*a
)
1890 gen_helper_satr(cpu_env
);
1894 #define cat3(a, b, c) a##b##c
1895 #define FOP(name, op) \
1896 static bool cat3(trans_, name, _ir)(DisasContext *ctx, \
1897 cat3(arg_, name, _ir) * a) \
1899 TCGv imm = tcg_const_i32(li(ctx, 0)); \
1900 gen_helper_##op(cpu_regs[a->rd], cpu_env, \
1901 cpu_regs[a->rd], imm); \
1902 tcg_temp_free(imm); \
1905 static bool cat3(trans_, name, _mr)(DisasContext *ctx, \
1906 cat3(arg_, name, _mr) * a) \
1909 mem = tcg_temp_new(); \
1910 val = rx_load_source(ctx, mem, a->ld, MO_32, a->rs); \
1911 gen_helper_##op(cpu_regs[a->rd], cpu_env, \
1912 cpu_regs[a->rd], val); \
1913 tcg_temp_free(mem); \
1917 #define FCONVOP(name, op) \
1918 static bool trans_##name(DisasContext *ctx, arg_##name * a) \
1921 mem = tcg_temp_new(); \
1922 val = rx_load_source(ctx, mem, a->ld, MO_32, a->rs); \
1923 gen_helper_##op(cpu_regs[a->rd], cpu_env, val); \
1924 tcg_temp_free(mem); \
1934 static bool trans_FCMP_ir(DisasContext
*ctx
, arg_FCMP_ir
* a
)
1936 TCGv imm
= tcg_const_i32(li(ctx
, 0));
1937 gen_helper_fcmp(cpu_env
, cpu_regs
[a
->rd
], imm
);
1942 /* fcmp dsp[rs], rd */
1944 static bool trans_FCMP_mr(DisasContext
*ctx
, arg_FCMP_mr
*a
)
1947 mem
= tcg_temp_new();
1948 val
= rx_load_source(ctx
, mem
, a
->ld
, MO_32
, a
->rs
);
1949 gen_helper_fcmp(cpu_env
, cpu_regs
[a
->rd
], val
);
1955 FCONVOP(ROUND
, round
)
1958 /* itof dsp[rs], rd */
1959 static bool trans_ITOF(DisasContext
*ctx
, arg_ITOF
* a
)
1962 mem
= tcg_temp_new();
1963 val
= rx_load_source(ctx
, mem
, a
->ld
, a
->mi
, a
->rs
);
1964 gen_helper_itof(cpu_regs
[a
->rd
], cpu_env
, val
);
1969 static void rx_bsetm(TCGv mem
, TCGv mask
)
1972 val
= tcg_temp_new();
1973 rx_gen_ld(MO_8
, val
, mem
);
1974 tcg_gen_or_i32(val
, val
, mask
);
1975 rx_gen_st(MO_8
, val
, mem
);
1979 static void rx_bclrm(TCGv mem
, TCGv mask
)
1982 val
= tcg_temp_new();
1983 rx_gen_ld(MO_8
, val
, mem
);
1984 tcg_gen_andc_i32(val
, val
, mask
);
1985 rx_gen_st(MO_8
, val
, mem
);
1989 static void rx_btstm(TCGv mem
, TCGv mask
)
1992 val
= tcg_temp_new();
1993 rx_gen_ld(MO_8
, val
, mem
);
1994 tcg_gen_and_i32(val
, val
, mask
);
1995 tcg_gen_setcondi_i32(TCG_COND_NE
, cpu_psw_c
, val
, 0);
1996 tcg_gen_mov_i32(cpu_psw_z
, cpu_psw_c
);
2000 static void rx_bnotm(TCGv mem
, TCGv mask
)
2003 val
= tcg_temp_new();
2004 rx_gen_ld(MO_8
, val
, mem
);
2005 tcg_gen_xor_i32(val
, val
, mask
);
2006 rx_gen_st(MO_8
, val
, mem
);
2010 static void rx_bsetr(TCGv reg
, TCGv mask
)
2012 tcg_gen_or_i32(reg
, reg
, mask
);
2015 static void rx_bclrr(TCGv reg
, TCGv mask
)
2017 tcg_gen_andc_i32(reg
, reg
, mask
);
2020 static inline void rx_btstr(TCGv reg
, TCGv mask
)
2023 t0
= tcg_temp_new();
2024 tcg_gen_and_i32(t0
, reg
, mask
);
2025 tcg_gen_setcondi_i32(TCG_COND_NE
, cpu_psw_c
, t0
, 0);
2026 tcg_gen_mov_i32(cpu_psw_z
, cpu_psw_c
);
2030 static inline void rx_bnotr(TCGv reg
, TCGv mask
)
2032 tcg_gen_xor_i32(reg
, reg
, mask
);
2035 #define BITOP(name, op) \
2036 static bool cat3(trans_, name, _im)(DisasContext *ctx, \
2037 cat3(arg_, name, _im) * a) \
2039 TCGv mask, mem, addr; \
2040 mem = tcg_temp_new(); \
2041 mask = tcg_const_i32(1 << a->imm); \
2042 addr = rx_index_addr(ctx, mem, a->ld, MO_8, a->rs); \
2043 cat3(rx_, op, m)(addr, mask); \
2044 tcg_temp_free(mask); \
2045 tcg_temp_free(mem); \
2048 static bool cat3(trans_, name, _ir)(DisasContext *ctx, \
2049 cat3(arg_, name, _ir) * a) \
2052 mask = tcg_const_i32(1 << a->imm); \
2053 cat3(rx_, op, r)(cpu_regs[a->rd], mask); \
2054 tcg_temp_free(mask); \
2057 static bool cat3(trans_, name, _rr)(DisasContext *ctx, \
2058 cat3(arg_, name, _rr) * a) \
2061 mask = tcg_const_i32(1); \
2062 b = tcg_temp_new(); \
2063 tcg_gen_andi_i32(b, cpu_regs[a->rs], 31); \
2064 tcg_gen_shl_i32(mask, mask, b); \
2065 cat3(rx_, op, r)(cpu_regs[a->rd], mask); \
2066 tcg_temp_free(mask); \
2070 static bool cat3(trans_, name, _rm)(DisasContext *ctx, \
2071 cat3(arg_, name, _rm) * a) \
2073 TCGv mask, mem, addr, b; \
2074 mask = tcg_const_i32(1); \
2075 b = tcg_temp_new(); \
2076 tcg_gen_andi_i32(b, cpu_regs[a->rd], 7); \
2077 tcg_gen_shl_i32(mask, mask, b); \
2078 mem = tcg_temp_new(); \
2079 addr = rx_index_addr(ctx, mem, a->ld, MO_8, a->rs); \
2080 cat3(rx_, op, m)(addr, mask); \
2081 tcg_temp_free(mem); \
2082 tcg_temp_free(mask); \
2092 static inline void bmcnd_op(TCGv val
, TCGCond cond
, int pos
)
2096 dc
.temp
= tcg_temp_new();
2097 bit
= tcg_temp_new();
2098 psw_cond(&dc
, cond
);
2099 tcg_gen_andi_i32(val
, val
, ~(1 << pos
));
2100 tcg_gen_setcondi_i32(dc
.cond
, bit
, dc
.value
, 0);
2101 tcg_gen_deposit_i32(val
, val
, bit
, pos
, 1);
2103 tcg_temp_free(dc
.temp
);
2106 /* bmcnd #imm, dsp[rd] */
2107 static bool trans_BMCnd_im(DisasContext
*ctx
, arg_BMCnd_im
*a
)
2109 TCGv val
, mem
, addr
;
2110 val
= tcg_temp_new();
2111 mem
= tcg_temp_new();
2112 addr
= rx_index_addr(ctx
, mem
, a
->ld
, MO_8
, a
->rd
);
2113 rx_gen_ld(MO_8
, val
, addr
);
2114 bmcnd_op(val
, a
->cd
, a
->imm
);
2115 rx_gen_st(MO_8
, val
, addr
);
2121 /* bmcond #imm, rd */
2122 static bool trans_BMCnd_ir(DisasContext
*ctx
, arg_BMCnd_ir
*a
)
2124 bmcnd_op(cpu_regs
[a
->rd
], a
->cd
, a
->imm
);
2137 static inline void clrsetpsw(DisasContext
*ctx
, int cb
, int val
)
2142 tcg_gen_movi_i32(cpu_psw_c
, val
);
2145 tcg_gen_movi_i32(cpu_psw_z
, val
== 0);
2148 tcg_gen_movi_i32(cpu_psw_s
, val
? -1 : 0);
2151 tcg_gen_movi_i32(cpu_psw_o
, val
<< 31);
2154 qemu_log_mask(LOG_GUEST_ERROR
, "Invalid distination %d", cb
);
2157 } else if (is_privileged(ctx
, 0)) {
2160 tcg_gen_movi_i32(cpu_psw_i
, val
);
2161 ctx
->base
.is_jmp
= DISAS_UPDATE
;
2164 tcg_gen_movi_i32(cpu_psw_u
, val
);
2167 qemu_log_mask(LOG_GUEST_ERROR
, "Invalid distination %d", cb
);
2174 static bool trans_CLRPSW(DisasContext
*ctx
, arg_CLRPSW
*a
)
2176 clrsetpsw(ctx
, a
->cb
, 0);
2181 static bool trans_SETPSW(DisasContext
*ctx
, arg_SETPSW
*a
)
2183 clrsetpsw(ctx
, a
->cb
, 1);
2188 static bool trans_MVTIPL(DisasContext
*ctx
, arg_MVTIPL
*a
)
2190 if (is_privileged(ctx
, 1)) {
2191 tcg_gen_movi_i32(cpu_psw_ipl
, a
->imm
);
2192 ctx
->base
.is_jmp
= DISAS_UPDATE
;
2198 static bool trans_MVTC_i(DisasContext
*ctx
, arg_MVTC_i
*a
)
2202 imm
= tcg_const_i32(a
->imm
);
2203 move_to_cr(ctx
, imm
, a
->cr
);
2204 if (a
->cr
== 0 && is_privileged(ctx
, 0)) {
2205 ctx
->base
.is_jmp
= DISAS_UPDATE
;
2212 static bool trans_MVTC_r(DisasContext
*ctx
, arg_MVTC_r
*a
)
2214 move_to_cr(ctx
, cpu_regs
[a
->rs
], a
->cr
);
2215 if (a
->cr
== 0 && is_privileged(ctx
, 0)) {
2216 ctx
->base
.is_jmp
= DISAS_UPDATE
;
2222 static bool trans_MVFC(DisasContext
*ctx
, arg_MVFC
*a
)
2224 move_from_cr(cpu_regs
[a
->rd
], a
->cr
, ctx
->pc
);
2229 static bool trans_RTFI(DisasContext
*ctx
, arg_RTFI
*a
)
2232 if (is_privileged(ctx
, 1)) {
2233 psw
= tcg_temp_new();
2234 tcg_gen_mov_i32(cpu_pc
, cpu_bpc
);
2235 tcg_gen_mov_i32(psw
, cpu_bpsw
);
2236 gen_helper_set_psw_rte(cpu_env
, psw
);
2237 ctx
->base
.is_jmp
= DISAS_EXIT
;
2244 static bool trans_RTE(DisasContext
*ctx
, arg_RTE
*a
)
2247 if (is_privileged(ctx
, 1)) {
2248 psw
= tcg_temp_new();
2251 gen_helper_set_psw_rte(cpu_env
, psw
);
2252 ctx
->base
.is_jmp
= DISAS_EXIT
;
2259 static bool trans_BRK(DisasContext
*ctx
, arg_BRK
*a
)
2261 tcg_gen_movi_i32(cpu_pc
, ctx
->base
.pc_next
);
2262 gen_helper_rxbrk(cpu_env
);
2263 ctx
->base
.is_jmp
= DISAS_NORETURN
;
2268 static bool trans_INT(DisasContext
*ctx
, arg_INT
*a
)
2272 tcg_debug_assert(a
->imm
< 0x100);
2273 vec
= tcg_const_i32(a
->imm
);
2274 tcg_gen_movi_i32(cpu_pc
, ctx
->base
.pc_next
);
2275 gen_helper_rxint(cpu_env
, vec
);
2277 ctx
->base
.is_jmp
= DISAS_NORETURN
;
2282 static bool trans_WAIT(DisasContext
*ctx
, arg_WAIT
*a
)
2284 if (is_privileged(ctx
, 1)) {
2285 tcg_gen_addi_i32(cpu_pc
, cpu_pc
, 2);
2286 gen_helper_wait(cpu_env
);
2291 static void rx_tr_init_disas_context(DisasContextBase
*dcbase
, CPUState
*cs
)
2293 CPURXState
*env
= cs
->env_ptr
;
2294 DisasContext
*ctx
= container_of(dcbase
, DisasContext
, base
);
2296 ctx
->tb_flags
= ctx
->base
.tb
->flags
;
2299 static void rx_tr_tb_start(DisasContextBase
*dcbase
, CPUState
*cs
)
2303 static void rx_tr_insn_start(DisasContextBase
*dcbase
, CPUState
*cs
)
2305 DisasContext
*ctx
= container_of(dcbase
, DisasContext
, base
);
2307 tcg_gen_insn_start(ctx
->base
.pc_next
);
2310 static void rx_tr_translate_insn(DisasContextBase
*dcbase
, CPUState
*cs
)
2312 DisasContext
*ctx
= container_of(dcbase
, DisasContext
, base
);
2315 ctx
->pc
= ctx
->base
.pc_next
;
2316 insn
= decode_load(ctx
);
2317 if (!decode(ctx
, insn
)) {
2318 gen_helper_raise_illegal_instruction(cpu_env
);
2322 static void rx_tr_tb_stop(DisasContextBase
*dcbase
, CPUState
*cs
)
2324 DisasContext
*ctx
= container_of(dcbase
, DisasContext
, base
);
2326 switch (ctx
->base
.is_jmp
) {
2328 case DISAS_TOO_MANY
:
2329 gen_goto_tb(ctx
, 0, dcbase
->pc_next
);
2332 tcg_gen_lookup_and_goto_ptr();
2335 tcg_gen_movi_i32(cpu_pc
, ctx
->base
.pc_next
);
2338 tcg_gen_exit_tb(NULL
, 0);
2340 case DISAS_NORETURN
:
2343 g_assert_not_reached();
2347 static void rx_tr_disas_log(const DisasContextBase
*dcbase
,
2348 CPUState
*cs
, FILE *logfile
)
2350 fprintf(logfile
, "IN: %s\n", lookup_symbol(dcbase
->pc_first
));
2351 target_disas(logfile
, cs
, dcbase
->pc_first
, dcbase
->tb
->size
);
2354 static const TranslatorOps rx_tr_ops
= {
2355 .init_disas_context
= rx_tr_init_disas_context
,
2356 .tb_start
= rx_tr_tb_start
,
2357 .insn_start
= rx_tr_insn_start
,
2358 .translate_insn
= rx_tr_translate_insn
,
2359 .tb_stop
= rx_tr_tb_stop
,
2360 .disas_log
= rx_tr_disas_log
,
2363 void gen_intermediate_code(CPUState
*cs
, TranslationBlock
*tb
, int max_insns
)
2367 translator_loop(&rx_tr_ops
, &dc
.base
, cs
, tb
, max_insns
);
2370 void restore_state_to_opc(CPURXState
*env
, TranslationBlock
*tb
,
2376 #define ALLOC_REGISTER(sym, name) \
2377 cpu_##sym = tcg_global_mem_new_i32(cpu_env, \
2378 offsetof(CPURXState, sym), name)
2380 void rx_translate_init(void)
2382 static const char * const regnames
[NUM_REGS
] = {
2383 "R0", "R1", "R2", "R3", "R4", "R5", "R6", "R7",
2384 "R8", "R9", "R10", "R11", "R12", "R13", "R14", "R15"
2388 for (i
= 0; i
< NUM_REGS
; i
++) {
2389 cpu_regs
[i
] = tcg_global_mem_new_i32(cpu_env
,
2390 offsetof(CPURXState
, regs
[i
]),
2393 ALLOC_REGISTER(pc
, "PC");
2394 ALLOC_REGISTER(psw_o
, "PSW(O)");
2395 ALLOC_REGISTER(psw_s
, "PSW(S)");
2396 ALLOC_REGISTER(psw_z
, "PSW(Z)");
2397 ALLOC_REGISTER(psw_c
, "PSW(C)");
2398 ALLOC_REGISTER(psw_u
, "PSW(U)");
2399 ALLOC_REGISTER(psw_i
, "PSW(I)");
2400 ALLOC_REGISTER(psw_pm
, "PSW(PM)");
2401 ALLOC_REGISTER(psw_ipl
, "PSW(IPL)");
2402 ALLOC_REGISTER(usp
, "USP");
2403 ALLOC_REGISTER(fpsw
, "FPSW");
2404 ALLOC_REGISTER(bpsw
, "BPSW");
2405 ALLOC_REGISTER(bpc
, "BPC");
2406 ALLOC_REGISTER(isp
, "ISP");
2407 ALLOC_REGISTER(fintv
, "FINTV");
2408 ALLOC_REGISTER(intb
, "INTB");
2409 cpu_acc
= tcg_global_mem_new_i64(cpu_env
,
2410 offsetof(CPURXState
, acc
), "ACC");