2 * CRIS emulation for qemu: main translation routines.
4 * Copyright (c) 2007 AXIS Communications AB
5 * Written by Edgar E. Iglesias.
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, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * This file implements a CRIS decoder-stage in SW. The decoder translates the
24 * guest (CRIS) machine-code into host machine code via dyngen using the
25 * micro-operations described in op.c
27 * The micro-operations for CRIS translation implement a RISC style ISA.
28 * Note that the micro-operations typically order their operands
29 * starting with the dst. CRIS asm, does the opposite.
31 * For example the following CRIS code:
36 * gen_movl_T0_reg(0); // Fetch $r0 into T0
37 * gen_load_T0_T0(); // Load T0, @T0
38 * gen_movl_reg_T0(1); // Writeback T0 into $r1
40 * The actual names for the micro-code generators vary but the example
41 * illustrates the point.
55 #include "crisv32-decode.h"
71 #define BUG() (gen_BUG(dc, __FILE__, __LINE__))
72 #define BUG_ON(x) ({if (x) BUG();})
76 /* Used by the decoder. */
77 #define EXTRACT_FIELD(src, start, end) \
78 (((src) >> start) & ((1 << (end - start + 1)) - 1))
80 #define CC_MASK_NZ 0xc
81 #define CC_MASK_NZV 0xe
82 #define CC_MASK_NZVC 0xf
83 #define CC_MASK_RNZV 0x10e
85 /* This is the state at translation time. */
86 typedef struct DisasContext
{
88 target_ulong pc
, insn_pc
;
95 unsigned int zsize
, zzsize
;
106 uint32_t tb_entry_flags
;
108 int memidx
; /* user or kernel mode. */
117 struct TranslationBlock
*tb
;
118 int singlestep_enabled
;
121 void cris_prepare_jmp (DisasContext
*dc
, uint32_t dst
);
122 static void gen_BUG(DisasContext
*dc
, char *file
, int line
)
124 printf ("BUG: pc=%x %s %d\n", dc
->pc
, file
, line
);
125 fprintf (logfile
, "BUG: pc=%x %s %d\n", dc
->pc
, file
, line
);
126 cpu_dump_state (dc
->env
, stdout
, fprintf
, 0);
128 cris_prepare_jmp (dc
, 0x70000000 + line
);
131 /* Table to generate quick moves from T0 onto any register. */
132 static GenOpFunc
*gen_movl_reg_T0
[16] =
134 gen_op_movl_r0_T0
, gen_op_movl_r1_T0
,
135 gen_op_movl_r2_T0
, gen_op_movl_r3_T0
,
136 gen_op_movl_r4_T0
, gen_op_movl_r5_T0
,
137 gen_op_movl_r6_T0
, gen_op_movl_r7_T0
,
138 gen_op_movl_r8_T0
, gen_op_movl_r9_T0
,
139 gen_op_movl_r10_T0
, gen_op_movl_r11_T0
,
140 gen_op_movl_r12_T0
, gen_op_movl_r13_T0
,
141 gen_op_movl_r14_T0
, gen_op_movl_r15_T0
,
143 static GenOpFunc
*gen_movl_T0_reg
[16] =
145 gen_op_movl_T0_r0
, gen_op_movl_T0_r1
,
146 gen_op_movl_T0_r2
, gen_op_movl_T0_r3
,
147 gen_op_movl_T0_r4
, gen_op_movl_T0_r5
,
148 gen_op_movl_T0_r6
, gen_op_movl_T0_r7
,
149 gen_op_movl_T0_r8
, gen_op_movl_T0_r9
,
150 gen_op_movl_T0_r10
, gen_op_movl_T0_r11
,
151 gen_op_movl_T0_r12
, gen_op_movl_T0_r13
,
152 gen_op_movl_T0_r14
, gen_op_movl_T0_r15
,
155 static void noop_write(void) {
159 static void gen_vr_read(void) {
160 gen_op_movl_T0_im(32);
163 static void gen_movl_T0_p0(void) {
164 gen_op_movl_T0_im(0);
167 static void gen_ccs_read(void) {
168 gen_op_movl_T0_p13();
171 static void gen_ccs_write(void) {
172 gen_op_movl_p13_T0();
175 /* Table to generate quick moves from T0 onto any register. */
176 static GenOpFunc
*gen_movl_preg_T0
[16] =
178 noop_write
, /* bz, not writeable. */
179 noop_write
, /* vr, not writeable. */
180 gen_op_movl_p2_T0
, gen_op_movl_p3_T0
,
181 noop_write
, /* wz, not writeable. */
183 gen_op_movl_p6_T0
, gen_op_movl_p7_T0
,
184 noop_write
, /* dz, not writeable. */
186 gen_op_movl_p10_T0
, gen_op_movl_p11_T0
,
188 gen_ccs_write
, /* ccs needs special treatment. */
189 gen_op_movl_p14_T0
, gen_op_movl_p15_T0
,
191 static GenOpFunc
*gen_movl_T0_preg
[16] =
195 gen_op_movl_T0_p2
, gen_op_movl_T0_p3
,
196 gen_op_movl_T0_p4
, gen_op_movl_T0_p5
,
197 gen_op_movl_T0_p6
, gen_op_movl_T0_p7
,
198 gen_op_movl_T0_p8
, gen_op_movl_T0_p9
,
199 gen_op_movl_T0_p10
, gen_op_movl_T0_p11
,
201 gen_ccs_read
, /* ccs needs special treatment. */
202 gen_op_movl_T0_p14
, gen_op_movl_T0_p15
,
205 /* We need this table to handle moves with implicit width. */
217 #ifdef CONFIG_USER_ONLY
218 #define GEN_OP_LD(width, reg) \
219 void gen_op_ld##width##_T0_##reg (DisasContext *dc) { \
220 gen_op_ld##width##_T0_##reg##_raw(); \
222 #define GEN_OP_ST(width, reg) \
223 void gen_op_st##width##_##reg##_T1 (DisasContext *dc) { \
224 gen_op_st##width##_##reg##_T1_raw(); \
227 #define GEN_OP_LD(width, reg) \
228 void gen_op_ld##width##_T0_##reg (DisasContext *dc) { \
229 if (dc->memidx) gen_op_ld##width##_T0_##reg##_kernel(); \
230 else gen_op_ld##width##_T0_##reg##_user();\
232 #define GEN_OP_ST(width, reg) \
233 void gen_op_st##width##_##reg##_T1 (DisasContext *dc) { \
234 if (dc->memidx) gen_op_st##width##_##reg##_T1_kernel(); \
235 else gen_op_st##width##_##reg##_T1_user();\
248 static void gen_goto_tb(DisasContext
*dc
, int n
, target_ulong dest
)
250 TranslationBlock
*tb
;
252 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
)) {
254 /* XXX: this code is not finished */
263 /* Sign extend at translation time. */
264 static int sign_extend(unsigned int val
, unsigned int width
)
276 static void cris_evaluate_flags(DisasContext
*dc
)
278 if (!dc
->flags_live
) {
283 gen_op_evaluate_flags_mcp ();
286 gen_op_evaluate_flags_muls ();
289 gen_op_evaluate_flags_mulu ();
295 gen_op_evaluate_flags_move_4();
298 gen_op_evaluate_flags_move_2();
301 gen_op_evaluate_flags ();
311 gen_op_evaluate_flags_alu_4 ();
314 gen_op_evaluate_flags ();
324 static void cris_cc_mask(DisasContext
*dc
, unsigned int mask
)
328 /* Check if we need to evaluate the condition codes due to
330 ovl
= (dc
->cc_mask
^ mask
) & ~mask
;
332 /* TODO: optimize this case. It trigs all the time. */
333 cris_evaluate_flags (dc
);
341 gen_op_update_cc_mask(mask
);
346 static void cris_update_cc_op(DisasContext
*dc
, int op
)
349 gen_op_update_cc_op(op
);
352 static void cris_update_cc_size(DisasContext
*dc
, int size
)
355 gen_op_update_cc_size_im(size
);
358 /* op is the operation.
359 T0, T1 are the operands.
360 dst is the destination reg.
362 static void crisv32_alu_op(DisasContext
*dc
, int op
, int rd
, int size
)
366 cris_update_cc_op(dc
, op
);
367 cris_update_cc_size(dc
, size
);
368 gen_op_update_cc_x(dc
->flagx_live
, dc
->flags_x
);
369 gen_op_update_cc_dest_T0();
372 /* Emit the ALU insns. */
377 /* Extended arithmetics. */
380 else if (dc
->flags_x
)
394 /* CRIS flag evaluation needs ~src. */
398 /* Extended arithmetics. */
401 else if (dc
->flags_x
)
427 /* Extended arithmetics. */
444 gen_op_dstep_T0_T1();
447 gen_op_bound_T0_T1();
452 /* CRIS flag evaluation needs ~src. */
456 /* Extended arithmetics. */
461 fprintf (logfile
, "illegal ALU op.\n");
467 gen_op_update_cc_src_T1();
470 gen_op_andl_T0_im(0xff);
472 gen_op_andl_T0_im(0xffff);
476 gen_movl_reg_T0
[rd
]();
479 gen_movl_T0_reg
[rd
]();
481 gen_op_andl_T0_im(~0xff);
483 gen_op_andl_T0_im(~0xffff);
485 gen_movl_reg_T0
[rd
]();
490 gen_op_update_cc_result_T0();
493 /* TODO: Optimize this. */
495 cris_evaluate_flags(dc
);
499 static int arith_cc(DisasContext
*dc
)
503 case CC_OP_ADD
: return 1;
504 case CC_OP_SUB
: return 1;
505 case CC_OP_LSL
: return 1;
506 case CC_OP_LSR
: return 1;
507 case CC_OP_ASR
: return 1;
508 case CC_OP_CMP
: return 1;
516 static void gen_tst_cc (DisasContext
*dc
, int cond
)
520 /* TODO: optimize more condition codes. */
521 arith_opt
= arith_cc(dc
) && !dc
->flags_live
;
525 gen_op_tst_cc_eq_fast ();
527 cris_evaluate_flags(dc
);
533 gen_op_tst_cc_ne_fast ();
535 cris_evaluate_flags(dc
);
540 cris_evaluate_flags(dc
);
544 cris_evaluate_flags(dc
);
548 cris_evaluate_flags(dc
);
552 cris_evaluate_flags(dc
);
557 gen_op_tst_cc_pl_fast ();
559 cris_evaluate_flags(dc
);
565 gen_op_tst_cc_mi_fast ();
567 cris_evaluate_flags(dc
);
572 cris_evaluate_flags(dc
);
576 cris_evaluate_flags(dc
);
580 cris_evaluate_flags(dc
);
584 cris_evaluate_flags(dc
);
588 cris_evaluate_flags(dc
);
592 cris_evaluate_flags(dc
);
596 cris_evaluate_flags(dc
);
600 cris_evaluate_flags(dc
);
601 gen_op_movl_T0_im (1);
609 static void cris_prepare_cc_branch (DisasContext
*dc
, int offset
, int cond
)
611 /* This helps us re-schedule the micro-code to insns in delay-slots
612 before the actual jump. */
613 dc
->delayed_branch
= 2;
614 dc
->delayed_pc
= dc
->pc
+ offset
;
618 gen_tst_cc (dc
, cond
);
619 gen_op_evaluate_bcc ();
621 gen_op_movl_T0_im (dc
->delayed_pc
);
622 gen_op_movl_btarget_T0 ();
625 /* Dynamic jumps, when the dest is in a live reg for example. */
626 void cris_prepare_dyn_jmp (DisasContext
*dc
)
628 /* This helps us re-schedule the micro-code to insns in delay-slots
629 before the actual jump. */
630 dc
->delayed_branch
= 2;
635 void cris_prepare_jmp (DisasContext
*dc
, uint32_t dst
)
637 /* This helps us re-schedule the micro-code to insns in delay-slots
638 before the actual jump. */
639 dc
->delayed_branch
= 2;
640 dc
->delayed_pc
= dst
;
645 void gen_load_T0_T0 (DisasContext
*dc
, unsigned int size
, int sign
)
649 gen_op_ldb_T0_T0(dc
);
651 gen_op_ldub_T0_T0(dc
);
653 else if (size
== 2) {
655 gen_op_ldw_T0_T0(dc
);
657 gen_op_lduw_T0_T0(dc
);
660 gen_op_ldl_T0_T0(dc
);
664 void gen_store_T0_T1 (DisasContext
*dc
, unsigned int size
)
666 /* Remember, operands are flipped. CRIS has reversed order. */
668 gen_op_stb_T0_T1(dc
);
670 else if (size
== 2) {
671 gen_op_stw_T0_T1(dc
);
674 gen_op_stl_T0_T1(dc
);
677 /* sign extend T1 according to size. */
678 static void gen_sext_T1_T0(int size
)
686 static void gen_sext_T1_T1(int size
)
694 static void gen_sext_T0_T0(int size
)
702 static void gen_zext_T0_T0(int size
)
705 gen_op_zextb_T0_T0();
707 gen_op_zextw_T0_T0();
710 static void gen_zext_T1_T0(int size
)
713 gen_op_zextb_T1_T0();
715 gen_op_zextw_T1_T0();
718 static void gen_zext_T1_T1(int size
)
721 gen_op_zextb_T1_T1();
723 gen_op_zextw_T1_T1();
727 static char memsize_char(int size
)
731 case 1: return 'b'; break;
732 case 2: return 'w'; break;
733 case 4: return 'd'; break;
741 static unsigned int memsize_z(DisasContext
*dc
)
743 return dc
->zsize
+ 1;
746 static unsigned int memsize_zz(DisasContext
*dc
)
757 static void do_postinc (DisasContext
*dc
, int size
)
761 gen_movl_T0_reg
[dc
->op1
]();
762 gen_op_addl_T0_im(size
);
763 gen_movl_reg_T0
[dc
->op1
]();
767 static void dec_prep_move_r(DisasContext
*dc
, int rs
, int rd
,
770 gen_movl_T0_reg
[rs
]();
773 gen_sext_T1_T1(size
);
775 gen_zext_T1_T1(size
);
778 /* Prepare T0 and T1 for a register alu operation.
779 s_ext decides if the operand1 should be sign-extended or zero-extended when
781 static void dec_prep_alu_r(DisasContext
*dc
, int rs
, int rd
,
784 dec_prep_move_r(dc
, rs
, rd
, size
, s_ext
);
786 gen_movl_T0_reg
[rd
]();
788 gen_sext_T0_T0(size
);
790 gen_zext_T0_T0(size
);
793 /* Prepare T0 and T1 for a memory + alu operation.
794 s_ext decides if the operand1 should be sign-extended or zero-extended when
796 static int dec_prep_alu_m(DisasContext
*dc
, int s_ext
, int memsize
)
805 is_imm
= rs
== 15 && dc
->postinc
;
807 /* Load [$rs] onto T1. */
809 insn_len
= 2 + memsize
;
813 imm
= ldl_code(dc
->pc
+ 2);
816 imm
= sign_extend(imm
, (memsize
* 8) - 1);
824 DIS(fprintf (logfile
, "imm=%x rd=%d sext=%d ms=%d\n",
825 imm
, rd
, s_ext
, memsize
));
826 gen_op_movl_T1_im (imm
);
829 gen_movl_T0_reg
[rs
]();
830 gen_load_T0_T0(dc
, memsize
, 0);
833 gen_sext_T1_T1(memsize
);
835 gen_zext_T1_T1(memsize
);
838 /* put dest in T0. */
839 gen_movl_T0_reg
[rd
]();
844 static const char *cc_name(int cc
)
846 static char *cc_names
[16] = {
847 "cc", "cs", "ne", "eq", "vc", "vs", "pl", "mi",
848 "ls", "hi", "ge", "lt", "gt", "le", "a", "p"
855 static unsigned int dec_bccq(DisasContext
*dc
)
859 uint32_t cond
= dc
->op2
;
862 offset
= EXTRACT_FIELD (dc
->ir
, 1, 7);
863 sign
= EXTRACT_FIELD(dc
->ir
, 0, 0);
868 offset
= sign_extend(offset
, 8);
870 /* op2 holds the condition-code. */
872 cris_prepare_cc_branch (dc
, offset
, cond
);
875 static unsigned int dec_addoq(DisasContext
*dc
)
879 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 7);
880 imm
= sign_extend(dc
->op1
, 7);
882 DIS(fprintf (logfile
, "addoq %d, $r%u\n", imm
, dc
->op2
));
884 /* Fetch register operand, */
885 gen_movl_T0_reg
[dc
->op2
]();
886 gen_op_movl_T1_im(imm
);
887 crisv32_alu_op(dc
, CC_OP_ADD
, R_ACR
, 4);
890 static unsigned int dec_addq(DisasContext
*dc
)
892 DIS(fprintf (logfile
, "addq %u, $r%u\n", dc
->op1
, dc
->op2
));
894 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
896 cris_cc_mask(dc
, CC_MASK_NZVC
);
897 /* Fetch register operand, */
898 gen_movl_T0_reg
[dc
->op2
]();
899 gen_op_movl_T1_im(dc
->op1
);
900 crisv32_alu_op(dc
, CC_OP_ADD
, dc
->op2
, 4);
903 static unsigned int dec_moveq(DisasContext
*dc
)
907 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
908 imm
= sign_extend(dc
->op1
, 5);
909 DIS(fprintf (logfile
, "moveq %d, $r%u\n", imm
, dc
->op2
));
912 gen_op_movl_T1_im(imm
);
913 crisv32_alu_op(dc
, CC_OP_MOVE
, dc
->op2
, 4);
917 static unsigned int dec_subq(DisasContext
*dc
)
919 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
921 DIS(fprintf (logfile
, "subq %u, $r%u\n", dc
->op1
, dc
->op2
));
923 cris_cc_mask(dc
, CC_MASK_NZVC
);
924 /* Fetch register operand, */
925 gen_movl_T0_reg
[dc
->op2
]();
926 gen_op_movl_T1_im(dc
->op1
);
927 crisv32_alu_op(dc
, CC_OP_SUB
, dc
->op2
, 4);
930 static unsigned int dec_cmpq(DisasContext
*dc
)
933 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
934 imm
= sign_extend(dc
->op1
, 5);
936 DIS(fprintf (logfile
, "cmpq %d, $r%d\n", imm
, dc
->op2
));
937 cris_cc_mask(dc
, CC_MASK_NZVC
);
938 gen_movl_T0_reg
[dc
->op2
]();
939 gen_op_movl_T1_im(imm
);
940 crisv32_alu_op(dc
, CC_OP_CMP
, dc
->op2
, 4);
943 static unsigned int dec_andq(DisasContext
*dc
)
946 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
947 imm
= sign_extend(dc
->op1
, 5);
949 DIS(fprintf (logfile
, "andq %d, $r%d\n", imm
, dc
->op2
));
950 cris_cc_mask(dc
, CC_MASK_NZ
);
951 gen_movl_T0_reg
[dc
->op2
]();
952 gen_op_movl_T1_im(imm
);
953 crisv32_alu_op(dc
, CC_OP_AND
, dc
->op2
, 4);
956 static unsigned int dec_orq(DisasContext
*dc
)
959 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 5);
960 imm
= sign_extend(dc
->op1
, 5);
961 DIS(fprintf (logfile
, "orq %d, $r%d\n", imm
, dc
->op2
));
962 cris_cc_mask(dc
, CC_MASK_NZ
);
963 gen_movl_T0_reg
[dc
->op2
]();
964 gen_op_movl_T1_im(imm
);
965 crisv32_alu_op(dc
, CC_OP_OR
, dc
->op2
, 4);
968 static unsigned int dec_btstq(DisasContext
*dc
)
970 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
971 DIS(fprintf (logfile
, "btstq %u, $r%d\n", dc
->op1
, dc
->op2
));
972 cris_cc_mask(dc
, CC_MASK_NZ
);
973 gen_movl_T0_reg
[dc
->op2
]();
974 gen_op_movl_T1_im(dc
->op1
);
975 crisv32_alu_op(dc
, CC_OP_BTST
, dc
->op2
, 4);
977 cris_update_cc_op(dc
, CC_OP_FLAGS
);
978 gen_op_movl_flags_T0();
982 static unsigned int dec_asrq(DisasContext
*dc
)
984 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
985 DIS(fprintf (logfile
, "asrq %u, $r%d\n", dc
->op1
, dc
->op2
));
986 cris_cc_mask(dc
, CC_MASK_NZ
);
987 gen_movl_T0_reg
[dc
->op2
]();
988 gen_op_movl_T1_im(dc
->op1
);
989 crisv32_alu_op(dc
, CC_OP_ASR
, dc
->op2
, 4);
992 static unsigned int dec_lslq(DisasContext
*dc
)
994 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
995 DIS(fprintf (logfile
, "lslq %u, $r%d\n", dc
->op1
, dc
->op2
));
997 cris_cc_mask(dc
, CC_MASK_NZ
);
998 gen_movl_T0_reg
[dc
->op2
]();
999 gen_op_movl_T1_im(dc
->op1
);
1000 crisv32_alu_op(dc
, CC_OP_LSL
, dc
->op2
, 4);
1003 static unsigned int dec_lsrq(DisasContext
*dc
)
1005 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 4);
1006 DIS(fprintf (logfile
, "lsrq %u, $r%d\n", dc
->op1
, dc
->op2
));
1008 cris_cc_mask(dc
, CC_MASK_NZ
);
1009 gen_movl_T0_reg
[dc
->op2
]();
1010 gen_op_movl_T1_im(dc
->op1
);
1011 crisv32_alu_op(dc
, CC_OP_LSR
, dc
->op2
, 4);
1015 static unsigned int dec_move_r(DisasContext
*dc
)
1017 int size
= memsize_zz(dc
);
1019 DIS(fprintf (logfile
, "move.%c $r%u, $r%u\n",
1020 memsize_char(size
), dc
->op1
, dc
->op2
));
1022 cris_cc_mask(dc
, CC_MASK_NZ
);
1023 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0);
1024 crisv32_alu_op(dc
, CC_OP_MOVE
, dc
->op2
, size
);
1028 static unsigned int dec_scc_r(DisasContext
*dc
)
1032 DIS(fprintf (logfile
, "s%s $r%u\n",
1033 cc_name(cond
), dc
->op1
));
1037 gen_tst_cc (dc
, cond
);
1038 gen_op_movl_T1_T0();
1041 gen_op_movl_T1_im(1);
1043 cris_cc_mask(dc
, 0);
1044 crisv32_alu_op(dc
, CC_OP_MOVE
, dc
->op1
, 4);
1048 static unsigned int dec_and_r(DisasContext
*dc
)
1050 int size
= memsize_zz(dc
);
1052 DIS(fprintf (logfile
, "and.%c $r%u, $r%u\n",
1053 memsize_char(size
), dc
->op1
, dc
->op2
));
1054 cris_cc_mask(dc
, CC_MASK_NZ
);
1055 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0);
1056 crisv32_alu_op(dc
, CC_OP_AND
, dc
->op2
, size
);
1060 static unsigned int dec_lz_r(DisasContext
*dc
)
1062 DIS(fprintf (logfile
, "lz $r%u, $r%u\n",
1064 cris_cc_mask(dc
, CC_MASK_NZ
);
1065 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, 4, 0);
1066 crisv32_alu_op(dc
, CC_OP_LZ
, dc
->op2
, 4);
1070 static unsigned int dec_lsl_r(DisasContext
*dc
)
1072 int size
= memsize_zz(dc
);
1074 DIS(fprintf (logfile
, "lsl.%c $r%u, $r%u\n",
1075 memsize_char(size
), dc
->op1
, dc
->op2
));
1076 cris_cc_mask(dc
, CC_MASK_NZ
);
1077 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0);
1078 gen_op_andl_T1_im(63);
1079 crisv32_alu_op(dc
, CC_OP_LSL
, dc
->op2
, size
);
1083 static unsigned int dec_lsr_r(DisasContext
*dc
)
1085 int size
= memsize_zz(dc
);
1087 DIS(fprintf (logfile
, "lsr.%c $r%u, $r%u\n",
1088 memsize_char(size
), dc
->op1
, dc
->op2
));
1089 cris_cc_mask(dc
, CC_MASK_NZ
);
1090 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0);
1091 gen_op_andl_T1_im(63);
1092 crisv32_alu_op(dc
, CC_OP_LSR
, dc
->op2
, size
);
1096 static unsigned int dec_asr_r(DisasContext
*dc
)
1098 int size
= memsize_zz(dc
);
1100 DIS(fprintf (logfile
, "asr.%c $r%u, $r%u\n",
1101 memsize_char(size
), dc
->op1
, dc
->op2
));
1102 cris_cc_mask(dc
, CC_MASK_NZ
);
1103 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 1);
1104 gen_op_andl_T1_im(63);
1105 crisv32_alu_op(dc
, CC_OP_ASR
, dc
->op2
, size
);
1109 static unsigned int dec_muls_r(DisasContext
*dc
)
1111 int size
= memsize_zz(dc
);
1113 DIS(fprintf (logfile
, "muls.%c $r%u, $r%u\n",
1114 memsize_char(size
), dc
->op1
, dc
->op2
));
1115 cris_cc_mask(dc
, CC_MASK_NZV
);
1116 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 1);
1117 gen_sext_T0_T0(size
);
1118 crisv32_alu_op(dc
, CC_OP_MULS
, dc
->op2
, 4);
1122 static unsigned int dec_mulu_r(DisasContext
*dc
)
1124 int size
= memsize_zz(dc
);
1126 DIS(fprintf (logfile
, "mulu.%c $r%u, $r%u\n",
1127 memsize_char(size
), dc
->op1
, dc
->op2
));
1128 cris_cc_mask(dc
, CC_MASK_NZV
);
1129 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0);
1130 gen_zext_T0_T0(size
);
1131 crisv32_alu_op(dc
, CC_OP_MULU
, dc
->op2
, 4);
1136 static unsigned int dec_dstep_r(DisasContext
*dc
)
1138 DIS(fprintf (logfile
, "dstep $r%u, $r%u\n", dc
->op1
, dc
->op2
));
1139 cris_cc_mask(dc
, CC_MASK_NZ
);
1140 gen_movl_T0_reg
[dc
->op1
]();
1141 gen_op_movl_T1_T0();
1142 gen_movl_T0_reg
[dc
->op2
]();
1143 crisv32_alu_op(dc
, CC_OP_DSTEP
, dc
->op2
, 4);
1147 static unsigned int dec_xor_r(DisasContext
*dc
)
1149 int size
= memsize_zz(dc
);
1150 DIS(fprintf (logfile
, "xor.%c $r%u, $r%u\n",
1151 memsize_char(size
), dc
->op1
, dc
->op2
));
1152 BUG_ON(size
!= 4); /* xor is dword. */
1153 cris_cc_mask(dc
, CC_MASK_NZ
);
1154 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0);
1155 crisv32_alu_op(dc
, CC_OP_XOR
, dc
->op2
, 4);
1159 static unsigned int dec_bound_r(DisasContext
*dc
)
1161 int size
= memsize_zz(dc
);
1162 DIS(fprintf (logfile
, "bound.%c $r%u, $r%u\n",
1163 memsize_char(size
), dc
->op1
, dc
->op2
));
1164 cris_cc_mask(dc
, CC_MASK_NZ
);
1165 /* TODO: needs optmimization. */
1166 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0);
1167 /* rd should be 4. */
1168 gen_movl_T0_reg
[dc
->op2
]();
1169 crisv32_alu_op(dc
, CC_OP_BOUND
, dc
->op2
, 4);
1173 static unsigned int dec_cmp_r(DisasContext
*dc
)
1175 int size
= memsize_zz(dc
);
1176 DIS(fprintf (logfile
, "cmp.%c $r%u, $r%u\n",
1177 memsize_char(size
), dc
->op1
, dc
->op2
));
1178 cris_cc_mask(dc
, CC_MASK_NZVC
);
1179 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0);
1180 crisv32_alu_op(dc
, CC_OP_CMP
, dc
->op2
, size
);
1184 static unsigned int dec_abs_r(DisasContext
*dc
)
1186 DIS(fprintf (logfile
, "abs $r%u, $r%u\n",
1188 cris_cc_mask(dc
, CC_MASK_NZ
);
1189 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, 4, 0);
1190 gen_op_absl_T1_T1();
1191 crisv32_alu_op(dc
, CC_OP_MOVE
, dc
->op2
, 4);
1195 static unsigned int dec_add_r(DisasContext
*dc
)
1197 int size
= memsize_zz(dc
);
1198 DIS(fprintf (logfile
, "add.%c $r%u, $r%u\n",
1199 memsize_char(size
), dc
->op1
, dc
->op2
));
1200 cris_cc_mask(dc
, CC_MASK_NZVC
);
1201 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0);
1202 crisv32_alu_op(dc
, CC_OP_ADD
, dc
->op2
, size
);
1206 static unsigned int dec_addc_r(DisasContext
*dc
)
1208 DIS(fprintf (logfile
, "addc $r%u, $r%u\n",
1210 cris_evaluate_flags(dc
);
1211 cris_cc_mask(dc
, CC_MASK_NZVC
);
1212 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, 4, 0);
1213 crisv32_alu_op(dc
, CC_OP_ADDC
, dc
->op2
, 4);
1217 static unsigned int dec_mcp_r(DisasContext
*dc
)
1219 DIS(fprintf (logfile
, "mcp $p%u, $r%u\n",
1221 cris_evaluate_flags(dc
);
1222 cris_cc_mask(dc
, CC_MASK_RNZV
);
1223 gen_movl_T0_preg
[dc
->op2
]();
1224 gen_op_movl_T1_T0();
1225 gen_movl_T0_reg
[dc
->op1
]();
1226 crisv32_alu_op(dc
, CC_OP_MCP
, dc
->op1
, 4);
1231 static char * swapmode_name(int mode
, char *modename
) {
1234 modename
[i
++] = 'n';
1236 modename
[i
++] = 'w';
1238 modename
[i
++] = 'b';
1240 modename
[i
++] = 'r';
1246 static unsigned int dec_swap_r(DisasContext
*dc
)
1248 DIS(char modename
[4]);
1249 DIS(fprintf (logfile
, "swap%s $r%u\n",
1250 swapmode_name(dc
->op2
, modename
), dc
->op1
));
1252 cris_cc_mask(dc
, CC_MASK_NZ
);
1253 gen_movl_T0_reg
[dc
->op1
]();
1257 gen_op_swapw_T0_T0();
1259 gen_op_swapb_T0_T0();
1261 gen_op_swapr_T0_T0();
1262 gen_op_movl_T1_T0();
1263 crisv32_alu_op(dc
, CC_OP_MOVE
, dc
->op1
, 4);
1267 static unsigned int dec_or_r(DisasContext
*dc
)
1269 int size
= memsize_zz(dc
);
1270 DIS(fprintf (logfile
, "or.%c $r%u, $r%u\n",
1271 memsize_char(size
), dc
->op1
, dc
->op2
));
1272 cris_cc_mask(dc
, CC_MASK_NZ
);
1273 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0);
1274 crisv32_alu_op(dc
, CC_OP_OR
, dc
->op2
, size
);
1278 static unsigned int dec_addi_r(DisasContext
*dc
)
1280 DIS(fprintf (logfile
, "addi.%c $r%u, $r%u\n",
1281 memsize_char(memsize_zz(dc
)), dc
->op2
, dc
->op1
));
1282 cris_cc_mask(dc
, 0);
1283 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, 4, 0);
1284 gen_op_lsll_T0_im(dc
->zzsize
);
1285 gen_op_addl_T0_T1();
1286 gen_movl_reg_T0
[dc
->op1
]();
1290 static unsigned int dec_addi_acr(DisasContext
*dc
)
1292 DIS(fprintf (logfile
, "addi.%c $r%u, $r%u, $acr\n",
1293 memsize_char(memsize_zz(dc
)), dc
->op2
, dc
->op1
));
1294 cris_cc_mask(dc
, 0);
1295 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, 4, 0);
1296 gen_op_lsll_T0_im(dc
->zzsize
);
1297 gen_op_addl_T0_T1();
1298 gen_movl_reg_T0
[R_ACR
]();
1302 static unsigned int dec_neg_r(DisasContext
*dc
)
1304 int size
= memsize_zz(dc
);
1305 DIS(fprintf (logfile
, "neg.%c $r%u, $r%u\n",
1306 memsize_char(size
), dc
->op1
, dc
->op2
));
1307 cris_cc_mask(dc
, CC_MASK_NZVC
);
1308 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0);
1309 crisv32_alu_op(dc
, CC_OP_NEG
, dc
->op2
, size
);
1313 static unsigned int dec_btst_r(DisasContext
*dc
)
1315 DIS(fprintf (logfile
, "btst $r%u, $r%u\n",
1317 cris_cc_mask(dc
, CC_MASK_NZ
);
1318 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, 4, 0);
1319 crisv32_alu_op(dc
, CC_OP_BTST
, dc
->op2
, 4);
1321 cris_update_cc_op(dc
, CC_OP_FLAGS
);
1322 gen_op_movl_flags_T0();
1327 static unsigned int dec_sub_r(DisasContext
*dc
)
1329 int size
= memsize_zz(dc
);
1330 DIS(fprintf (logfile
, "sub.%c $r%u, $r%u\n",
1331 memsize_char(size
), dc
->op1
, dc
->op2
));
1332 cris_cc_mask(dc
, CC_MASK_NZVC
);
1333 dec_prep_alu_r(dc
, dc
->op1
, dc
->op2
, size
, 0);
1334 crisv32_alu_op(dc
, CC_OP_SUB
, dc
->op2
, size
);
1338 /* Zero extension. From size to dword. */
1339 static unsigned int dec_movu_r(DisasContext
*dc
)
1341 int size
= memsize_z(dc
);
1342 DIS(fprintf (logfile
, "movu.%c $r%u, $r%u\n",
1346 cris_cc_mask(dc
, CC_MASK_NZ
);
1347 dec_prep_move_r(dc
, dc
->op1
, dc
->op2
, size
, 0);
1348 crisv32_alu_op(dc
, CC_OP_MOVE
, dc
->op2
, 4);
1352 /* Sign extension. From size to dword. */
1353 static unsigned int dec_movs_r(DisasContext
*dc
)
1355 int size
= memsize_z(dc
);
1356 DIS(fprintf (logfile
, "movs.%c $r%u, $r%u\n",
1360 cris_cc_mask(dc
, CC_MASK_NZ
);
1361 gen_movl_T0_reg
[dc
->op1
]();
1362 /* Size can only be qi or hi. */
1363 gen_sext_T1_T0(size
);
1364 crisv32_alu_op(dc
, CC_OP_MOVE
, dc
->op2
, 4);
1368 /* zero extension. From size to dword. */
1369 static unsigned int dec_addu_r(DisasContext
*dc
)
1371 int size
= memsize_z(dc
);
1372 DIS(fprintf (logfile
, "addu.%c $r%u, $r%u\n",
1376 cris_cc_mask(dc
, CC_MASK_NZVC
);
1377 gen_movl_T0_reg
[dc
->op1
]();
1378 /* Size can only be qi or hi. */
1379 gen_zext_T1_T0(size
);
1380 gen_movl_T0_reg
[dc
->op2
]();
1381 crisv32_alu_op(dc
, CC_OP_ADD
, dc
->op2
, 4);
1384 /* Sign extension. From size to dword. */
1385 static unsigned int dec_adds_r(DisasContext
*dc
)
1387 int size
= memsize_z(dc
);
1388 DIS(fprintf (logfile
, "adds.%c $r%u, $r%u\n",
1392 cris_cc_mask(dc
, CC_MASK_NZVC
);
1393 gen_movl_T0_reg
[dc
->op1
]();
1394 /* Size can only be qi or hi. */
1395 gen_sext_T1_T0(size
);
1396 gen_movl_T0_reg
[dc
->op2
]();
1397 crisv32_alu_op(dc
, CC_OP_ADD
, dc
->op2
, 4);
1401 /* Zero extension. From size to dword. */
1402 static unsigned int dec_subu_r(DisasContext
*dc
)
1404 int size
= memsize_z(dc
);
1405 DIS(fprintf (logfile
, "subu.%c $r%u, $r%u\n",
1409 cris_cc_mask(dc
, CC_MASK_NZVC
);
1410 gen_movl_T0_reg
[dc
->op1
]();
1411 /* Size can only be qi or hi. */
1412 gen_zext_T1_T0(size
);
1413 gen_movl_T0_reg
[dc
->op2
]();
1414 crisv32_alu_op(dc
, CC_OP_SUB
, dc
->op2
, 4);
1418 /* Sign extension. From size to dword. */
1419 static unsigned int dec_subs_r(DisasContext
*dc
)
1421 int size
= memsize_z(dc
);
1422 DIS(fprintf (logfile
, "subs.%c $r%u, $r%u\n",
1426 cris_cc_mask(dc
, CC_MASK_NZVC
);
1427 gen_movl_T0_reg
[dc
->op1
]();
1428 /* Size can only be qi or hi. */
1429 gen_sext_T1_T0(size
);
1430 gen_movl_T0_reg
[dc
->op2
]();
1431 crisv32_alu_op(dc
, CC_OP_SUB
, dc
->op2
, 4);
1435 static unsigned int dec_setclrf(DisasContext
*dc
)
1438 int set
= (~dc
->opcode
>> 2) & 1;
1440 flags
= (EXTRACT_FIELD(dc
->ir
, 12, 15) << 4)
1441 | EXTRACT_FIELD(dc
->ir
, 0, 3);
1442 DIS(fprintf (logfile
, "set=%d flags=%x\n", set
, flags
));
1443 if (set
&& flags
== 0)
1444 DIS(fprintf (logfile
, "nop\n"));
1445 else if (!set
&& (flags
& 0x20))
1446 DIS(fprintf (logfile
, "di\n"));
1448 DIS(fprintf (logfile
, "%sf %x\n",
1449 set
? "set" : "clr",
1452 if (set
&& (flags
& X_FLAG
)) {
1457 /* Simply decode the flags. */
1458 cris_evaluate_flags (dc
);
1459 cris_update_cc_op(dc
, CC_OP_FLAGS
);
1461 gen_op_setf (flags
);
1463 gen_op_clrf (flags
);
1468 static unsigned int dec_move_rs(DisasContext
*dc
)
1470 DIS(fprintf (logfile
, "move $r%u, $s%u\n", dc
->op1
, dc
->op2
));
1471 cris_cc_mask(dc
, 0);
1472 gen_movl_T0_reg
[dc
->op1
]();
1473 gen_op_movl_sreg_T0(dc
->op2
);
1475 if (dc
->op2
== 5) /* srs is checked at runtime. */
1476 gen_op_movl_tlb_lo_T0();
1479 static unsigned int dec_move_sr(DisasContext
*dc
)
1481 DIS(fprintf (logfile
, "move $s%u, $r%u\n", dc
->op1
, dc
->op2
));
1482 cris_cc_mask(dc
, 0);
1483 gen_op_movl_T0_sreg(dc
->op1
);
1484 gen_op_movl_T1_T0();
1485 crisv32_alu_op(dc
, CC_OP_MOVE
, dc
->op2
, 4);
1488 static unsigned int dec_move_rp(DisasContext
*dc
)
1490 DIS(fprintf (logfile
, "move $r%u, $p%u\n", dc
->op1
, dc
->op2
));
1491 cris_cc_mask(dc
, 0);
1492 gen_movl_T0_reg
[dc
->op1
]();
1493 gen_op_movl_T1_T0();
1494 gen_movl_preg_T0
[dc
->op2
]();
1497 static unsigned int dec_move_pr(DisasContext
*dc
)
1499 DIS(fprintf (logfile
, "move $p%u, $r%u\n", dc
->op1
, dc
->op2
));
1500 cris_cc_mask(dc
, 0);
1501 /* Support register 0 is hardwired to zero.
1502 Treat it specially. */
1504 gen_op_movl_T1_im(0);
1506 gen_movl_T0_preg
[dc
->op2
]();
1507 gen_op_movl_T1_T0();
1509 crisv32_alu_op(dc
, CC_OP_MOVE
, dc
->op1
, preg_sizes
[dc
->op2
]);
1513 static unsigned int dec_move_mr(DisasContext
*dc
)
1515 int memsize
= memsize_zz(dc
);
1517 DIS(fprintf (logfile
, "move.%c [$r%u%s, $r%u\n",
1518 memsize_char(memsize
),
1519 dc
->op1
, dc
->postinc
? "+]" : "]",
1522 cris_cc_mask(dc
, CC_MASK_NZ
);
1523 insn_len
= dec_prep_alu_m(dc
, 0, memsize
);
1524 crisv32_alu_op(dc
, CC_OP_MOVE
, dc
->op2
, memsize
);
1525 do_postinc(dc
, memsize
);
1529 static unsigned int dec_movs_m(DisasContext
*dc
)
1531 int memsize
= memsize_z(dc
);
1533 DIS(fprintf (logfile
, "movs.%c [$r%u%s, $r%u\n",
1534 memsize_char(memsize
),
1535 dc
->op1
, dc
->postinc
? "+]" : "]",
1539 cris_cc_mask(dc
, CC_MASK_NZ
);
1540 insn_len
= dec_prep_alu_m(dc
, 1, memsize
);
1541 crisv32_alu_op(dc
, CC_OP_MOVE
, dc
->op2
, 4);
1542 do_postinc(dc
, memsize
);
1546 static unsigned int dec_addu_m(DisasContext
*dc
)
1548 int memsize
= memsize_z(dc
);
1550 DIS(fprintf (logfile
, "addu.%c [$r%u%s, $r%u\n",
1551 memsize_char(memsize
),
1552 dc
->op1
, dc
->postinc
? "+]" : "]",
1556 cris_cc_mask(dc
, CC_MASK_NZVC
);
1557 insn_len
= dec_prep_alu_m(dc
, 0, memsize
);
1558 crisv32_alu_op(dc
, CC_OP_ADD
, dc
->op2
, 4);
1559 do_postinc(dc
, memsize
);
1563 static unsigned int dec_adds_m(DisasContext
*dc
)
1565 int memsize
= memsize_z(dc
);
1567 DIS(fprintf (logfile
, "adds.%c [$r%u%s, $r%u\n",
1568 memsize_char(memsize
),
1569 dc
->op1
, dc
->postinc
? "+]" : "]",
1573 cris_cc_mask(dc
, CC_MASK_NZVC
);
1574 insn_len
= dec_prep_alu_m(dc
, 1, memsize
);
1575 crisv32_alu_op(dc
, CC_OP_ADD
, dc
->op2
, 4);
1576 do_postinc(dc
, memsize
);
1580 static unsigned int dec_subu_m(DisasContext
*dc
)
1582 int memsize
= memsize_z(dc
);
1584 DIS(fprintf (logfile
, "subu.%c [$r%u%s, $r%u\n",
1585 memsize_char(memsize
),
1586 dc
->op1
, dc
->postinc
? "+]" : "]",
1590 cris_cc_mask(dc
, CC_MASK_NZVC
);
1591 insn_len
= dec_prep_alu_m(dc
, 0, memsize
);
1592 crisv32_alu_op(dc
, CC_OP_SUB
, dc
->op2
, 4);
1593 do_postinc(dc
, memsize
);
1597 static unsigned int dec_subs_m(DisasContext
*dc
)
1599 int memsize
= memsize_z(dc
);
1601 DIS(fprintf (logfile
, "subs.%c [$r%u%s, $r%u\n",
1602 memsize_char(memsize
),
1603 dc
->op1
, dc
->postinc
? "+]" : "]",
1607 cris_cc_mask(dc
, CC_MASK_NZVC
);
1608 insn_len
= dec_prep_alu_m(dc
, 1, memsize
);
1609 crisv32_alu_op(dc
, CC_OP_SUB
, dc
->op2
, 4);
1610 do_postinc(dc
, memsize
);
1614 static unsigned int dec_movu_m(DisasContext
*dc
)
1616 int memsize
= memsize_z(dc
);
1619 DIS(fprintf (logfile
, "movu.%c [$r%u%s, $r%u\n",
1620 memsize_char(memsize
),
1621 dc
->op1
, dc
->postinc
? "+]" : "]",
1624 cris_cc_mask(dc
, CC_MASK_NZ
);
1625 insn_len
= dec_prep_alu_m(dc
, 0, memsize
);
1626 crisv32_alu_op(dc
, CC_OP_MOVE
, dc
->op2
, 4);
1627 do_postinc(dc
, memsize
);
1631 static unsigned int dec_cmpu_m(DisasContext
*dc
)
1633 int memsize
= memsize_z(dc
);
1635 DIS(fprintf (logfile
, "cmpu.%c [$r%u%s, $r%u\n",
1636 memsize_char(memsize
),
1637 dc
->op1
, dc
->postinc
? "+]" : "]",
1640 cris_cc_mask(dc
, CC_MASK_NZVC
);
1641 insn_len
= dec_prep_alu_m(dc
, 0, memsize
);
1642 crisv32_alu_op(dc
, CC_OP_CMP
, dc
->op2
, 4);
1643 do_postinc(dc
, memsize
);
1647 static unsigned int dec_cmps_m(DisasContext
*dc
)
1649 int memsize
= memsize_z(dc
);
1651 DIS(fprintf (logfile
, "cmps.%c [$r%u%s, $r%u\n",
1652 memsize_char(memsize
),
1653 dc
->op1
, dc
->postinc
? "+]" : "]",
1656 cris_cc_mask(dc
, CC_MASK_NZVC
);
1657 insn_len
= dec_prep_alu_m(dc
, 1, memsize
);
1658 crisv32_alu_op(dc
, CC_OP_CMP
, dc
->op2
, memsize_zz(dc
));
1659 do_postinc(dc
, memsize
);
1663 static unsigned int dec_cmp_m(DisasContext
*dc
)
1665 int memsize
= memsize_zz(dc
);
1667 DIS(fprintf (logfile
, "cmp.%c [$r%u%s, $r%u\n",
1668 memsize_char(memsize
),
1669 dc
->op1
, dc
->postinc
? "+]" : "]",
1672 cris_cc_mask(dc
, CC_MASK_NZVC
);
1673 insn_len
= dec_prep_alu_m(dc
, 0, memsize
);
1674 crisv32_alu_op(dc
, CC_OP_CMP
, dc
->op2
, memsize_zz(dc
));
1675 do_postinc(dc
, memsize
);
1679 static unsigned int dec_test_m(DisasContext
*dc
)
1681 int memsize
= memsize_zz(dc
);
1683 DIS(fprintf (logfile
, "test.%d [$r%u%s] op2=%x\n",
1684 memsize_char(memsize
),
1685 dc
->op1
, dc
->postinc
? "+]" : "]",
1688 cris_cc_mask(dc
, CC_MASK_NZ
);
1690 insn_len
= dec_prep_alu_m(dc
, 0, memsize
);
1692 gen_op_movl_T1_im(0);
1693 crisv32_alu_op(dc
, CC_OP_CMP
, dc
->op2
, memsize_zz(dc
));
1694 do_postinc(dc
, memsize
);
1698 static unsigned int dec_and_m(DisasContext
*dc
)
1700 int memsize
= memsize_zz(dc
);
1702 DIS(fprintf (logfile
, "and.%d [$r%u%s, $r%u\n",
1703 memsize_char(memsize
),
1704 dc
->op1
, dc
->postinc
? "+]" : "]",
1707 cris_cc_mask(dc
, CC_MASK_NZ
);
1708 insn_len
= dec_prep_alu_m(dc
, 0, memsize
);
1709 crisv32_alu_op(dc
, CC_OP_AND
, dc
->op2
, memsize_zz(dc
));
1710 do_postinc(dc
, memsize
);
1714 static unsigned int dec_add_m(DisasContext
*dc
)
1716 int memsize
= memsize_zz(dc
);
1718 DIS(fprintf (logfile
, "add.%d [$r%u%s, $r%u\n",
1719 memsize_char(memsize
),
1720 dc
->op1
, dc
->postinc
? "+]" : "]",
1723 cris_cc_mask(dc
, CC_MASK_NZVC
);
1724 insn_len
= dec_prep_alu_m(dc
, 0, memsize
);
1725 crisv32_alu_op(dc
, CC_OP_ADD
, dc
->op2
, memsize_zz(dc
));
1726 do_postinc(dc
, memsize
);
1730 static unsigned int dec_addo_m(DisasContext
*dc
)
1732 int memsize
= memsize_zz(dc
);
1734 DIS(fprintf (logfile
, "add.%d [$r%u%s, $r%u\n",
1735 memsize_char(memsize
),
1736 dc
->op1
, dc
->postinc
? "+]" : "]",
1739 cris_cc_mask(dc
, 0);
1740 insn_len
= dec_prep_alu_m(dc
, 1, memsize
);
1741 crisv32_alu_op(dc
, CC_OP_ADD
, R_ACR
, 4);
1742 do_postinc(dc
, memsize
);
1746 static unsigned int dec_bound_m(DisasContext
*dc
)
1748 int memsize
= memsize_zz(dc
);
1750 DIS(fprintf (logfile
, "bound.%d [$r%u%s, $r%u\n",
1751 memsize_char(memsize
),
1752 dc
->op1
, dc
->postinc
? "+]" : "]",
1755 cris_cc_mask(dc
, CC_MASK_NZ
);
1756 insn_len
= dec_prep_alu_m(dc
, 0, memsize
);
1757 crisv32_alu_op(dc
, CC_OP_BOUND
, dc
->op2
, 4);
1758 do_postinc(dc
, memsize
);
1762 static unsigned int dec_addc_mr(DisasContext
*dc
)
1765 DIS(fprintf (logfile
, "addc [$r%u%s, $r%u\n",
1766 dc
->op1
, dc
->postinc
? "+]" : "]",
1769 cris_evaluate_flags(dc
);
1770 cris_cc_mask(dc
, CC_MASK_NZVC
);
1771 insn_len
= dec_prep_alu_m(dc
, 0, 4);
1772 crisv32_alu_op(dc
, CC_OP_ADDC
, dc
->op2
, 4);
1777 static unsigned int dec_sub_m(DisasContext
*dc
)
1779 int memsize
= memsize_zz(dc
);
1781 DIS(fprintf (logfile
, "sub.%c [$r%u%s, $r%u ir=%x zz=%x\n",
1782 memsize_char(memsize
),
1783 dc
->op1
, dc
->postinc
? "+]" : "]",
1784 dc
->op2
, dc
->ir
, dc
->zzsize
));
1786 cris_cc_mask(dc
, CC_MASK_NZVC
);
1787 insn_len
= dec_prep_alu_m(dc
, 0, memsize
);
1788 crisv32_alu_op(dc
, CC_OP_SUB
, dc
->op2
, memsize
);
1789 do_postinc(dc
, memsize
);
1793 static unsigned int dec_or_m(DisasContext
*dc
)
1795 int memsize
= memsize_zz(dc
);
1797 DIS(fprintf (logfile
, "or.%d [$r%u%s, $r%u pc=%x\n",
1798 memsize_char(memsize
),
1799 dc
->op1
, dc
->postinc
? "+]" : "]",
1802 cris_cc_mask(dc
, CC_MASK_NZ
);
1803 insn_len
= dec_prep_alu_m(dc
, 0, memsize
);
1804 crisv32_alu_op(dc
, CC_OP_OR
, dc
->op2
, memsize_zz(dc
));
1805 do_postinc(dc
, memsize
);
1809 static unsigned int dec_move_mp(DisasContext
*dc
)
1811 int memsize
= memsize_zz(dc
);
1814 DIS(fprintf (logfile
, "move.%c [$r%u%s, $p%u\n",
1815 memsize_char(memsize
),
1817 dc
->postinc
? "+]" : "]",
1820 cris_cc_mask(dc
, 0);
1821 insn_len
= dec_prep_alu_m(dc
, 0, memsize
);
1822 gen_op_movl_T0_T1();
1823 gen_movl_preg_T0
[dc
->op2
]();
1825 do_postinc(dc
, memsize
);
1829 static unsigned int dec_move_pm(DisasContext
*dc
)
1833 memsize
= preg_sizes
[dc
->op2
];
1835 DIS(fprintf (logfile
, "move.%c $p%u, [$r%u%s\n",
1836 memsize_char(memsize
),
1837 dc
->op2
, dc
->op1
, dc
->postinc
? "+]" : "]"));
1839 cris_cc_mask(dc
, 0);
1840 /* prepare store. Address in T0, value in T1. */
1841 /* Support register 0 is hardwired to zero.
1842 Treat it specially. */
1844 gen_op_movl_T1_im(0);
1847 gen_movl_T0_preg
[dc
->op2
]();
1848 gen_op_movl_T1_T0();
1850 gen_movl_T0_reg
[dc
->op1
]();
1851 gen_store_T0_T1(dc
, memsize
);
1854 gen_op_addl_T0_im(memsize
);
1855 gen_movl_reg_T0
[dc
->op1
]();
1860 static unsigned int dec_movem_mr(DisasContext
*dc
)
1864 DIS(fprintf (logfile
, "movem [$r%u%s, $r%u\n", dc
->op1
,
1865 dc
->postinc
? "+]" : "]", dc
->op2
));
1867 cris_cc_mask(dc
, 0);
1868 /* fetch the address into T1. */
1869 gen_movl_T0_reg
[dc
->op1
]();
1870 gen_op_movl_T1_T0();
1871 for (i
= 0; i
<= dc
->op2
; i
++) {
1872 /* Perform the load onto regnum i. Always dword wide. */
1873 gen_load_T0_T0(dc
, 4, 0);
1874 gen_movl_reg_T0
[i
]();
1875 /* Update the address. */
1876 gen_op_addl_T1_im(4);
1877 gen_op_movl_T0_T1();
1880 /* writeback the updated pointer value. */
1881 gen_movl_reg_T0
[dc
->op1
]();
1886 static unsigned int dec_movem_rm(DisasContext
*dc
)
1890 DIS(fprintf (logfile
, "movem $r%u, [$r%u%s\n", dc
->op2
, dc
->op1
,
1891 dc
->postinc
? "+]" : "]"));
1893 cris_cc_mask(dc
, 0);
1894 for (i
= 0; i
<= dc
->op2
; i
++) {
1895 /* Fetch register i into T1. */
1896 gen_movl_T0_reg
[i
]();
1897 gen_op_movl_T1_T0();
1899 /* Fetch the address into T0. */
1900 gen_movl_T0_reg
[dc
->op1
]();
1902 gen_op_addl_T0_im(i
* 4);
1904 /* Perform the store. */
1905 gen_store_T0_T1(dc
, 4);
1908 /* Update the address. */
1909 gen_op_addl_T0_im(4);
1910 /* writeback the updated pointer value. */
1911 gen_movl_reg_T0
[dc
->op1
]();
1916 static unsigned int dec_move_rm(DisasContext
*dc
)
1920 memsize
= memsize_zz(dc
);
1922 DIS(fprintf (logfile
, "move.%d $r%u, [$r%u]\n",
1923 memsize
, dc
->op2
, dc
->op1
));
1925 cris_cc_mask(dc
, 0);
1926 /* prepare store. */
1927 gen_movl_T0_reg
[dc
->op2
]();
1928 gen_op_movl_T1_T0();
1929 gen_movl_T0_reg
[dc
->op1
]();
1930 gen_store_T0_T1(dc
, memsize
);
1933 gen_op_addl_T0_im(memsize
);
1934 gen_movl_reg_T0
[dc
->op1
]();
1940 static unsigned int dec_lapcq(DisasContext
*dc
)
1942 DIS(fprintf (logfile
, "lapcq %x, $r%u\n",
1943 dc
->pc
+ dc
->op1
*2, dc
->op2
));
1944 cris_cc_mask(dc
, 0);
1945 gen_op_movl_T1_im(dc
->pc
+ dc
->op1
*2);
1946 crisv32_alu_op(dc
, CC_OP_MOVE
, dc
->op2
, 4);
1950 static unsigned int dec_lapc_im(DisasContext
*dc
)
1958 cris_cc_mask(dc
, 0);
1959 imm
= ldl_code(dc
->pc
+ 2);
1960 DIS(fprintf (logfile
, "lapc 0x%x, $r%u\n", imm
+ dc
->pc
, dc
->op2
));
1961 gen_op_movl_T0_im (dc
->pc
+ imm
);
1962 gen_movl_reg_T0
[rd
] ();
1966 /* Jump to special reg. */
1967 static unsigned int dec_jump_p(DisasContext
*dc
)
1969 DIS(fprintf (logfile
, "jump $p%u\n", dc
->op2
));
1970 cris_cc_mask(dc
, 0);
1971 /* Store the return address in Pd. */
1972 gen_movl_T0_preg
[dc
->op2
]();
1973 gen_op_movl_btarget_T0();
1974 cris_prepare_dyn_jmp(dc
);
1978 /* Jump and save. */
1979 static unsigned int dec_jas_r(DisasContext
*dc
)
1981 DIS(fprintf (logfile
, "jas $r%u, $p%u\n", dc
->op1
, dc
->op2
));
1982 cris_cc_mask(dc
, 0);
1983 /* Stor the return address in Pd. */
1984 gen_movl_T0_reg
[dc
->op1
]();
1985 gen_op_movl_btarget_T0();
1986 gen_op_movl_T0_im(dc
->pc
+ 4);
1987 gen_movl_preg_T0
[dc
->op2
]();
1988 cris_prepare_dyn_jmp(dc
);
1992 static unsigned int dec_jas_im(DisasContext
*dc
)
1996 imm
= ldl_code(dc
->pc
+ 2);
1998 DIS(fprintf (logfile
, "jas 0x%x\n", imm
));
1999 cris_cc_mask(dc
, 0);
2000 /* Stor the return address in Pd. */
2001 gen_op_movl_T0_im(imm
);
2002 gen_op_movl_btarget_T0();
2003 gen_op_movl_T0_im(dc
->pc
+ 8);
2004 gen_movl_preg_T0
[dc
->op2
]();
2005 cris_prepare_dyn_jmp(dc
);
2009 static unsigned int dec_jasc_im(DisasContext
*dc
)
2013 imm
= ldl_code(dc
->pc
+ 2);
2015 DIS(fprintf (logfile
, "jasc 0x%x\n", imm
));
2016 cris_cc_mask(dc
, 0);
2017 /* Stor the return address in Pd. */
2018 gen_op_movl_T0_im(imm
);
2019 gen_op_movl_btarget_T0();
2020 gen_op_movl_T0_im(dc
->pc
+ 8 + 4);
2021 gen_movl_preg_T0
[dc
->op2
]();
2022 cris_prepare_dyn_jmp(dc
);
2026 static unsigned int dec_jasc_r(DisasContext
*dc
)
2028 DIS(fprintf (logfile
, "jasc_r $r%u, $p%u\n", dc
->op1
, dc
->op2
));
2029 cris_cc_mask(dc
, 0);
2030 /* Stor the return address in Pd. */
2031 gen_movl_T0_reg
[dc
->op1
]();
2032 gen_op_movl_btarget_T0();
2033 gen_op_movl_T0_im(dc
->pc
+ 4 + 4);
2034 gen_movl_preg_T0
[dc
->op2
]();
2035 cris_prepare_dyn_jmp(dc
);
2039 static unsigned int dec_bcc_im(DisasContext
*dc
)
2042 uint32_t cond
= dc
->op2
;
2044 offset
= ldl_code(dc
->pc
+ 2);
2045 offset
= sign_extend(offset
, 15);
2047 DIS(fprintf (logfile
, "b%s %d pc=%x dst=%x\n",
2048 cc_name(cond
), offset
,
2049 dc
->pc
, dc
->pc
+ offset
));
2051 cris_cc_mask(dc
, 0);
2052 /* op2 holds the condition-code. */
2053 cris_prepare_cc_branch (dc
, offset
, cond
);
2057 static unsigned int dec_bas_im(DisasContext
*dc
)
2062 simm
= ldl_code(dc
->pc
+ 2);
2064 DIS(fprintf (logfile
, "bas 0x%x, $p%u\n", dc
->pc
+ simm
, dc
->op2
));
2065 cris_cc_mask(dc
, 0);
2066 /* Stor the return address in Pd. */
2067 gen_op_movl_T0_im(dc
->pc
+ simm
);
2068 gen_op_movl_btarget_T0();
2069 gen_op_movl_T0_im(dc
->pc
+ 8);
2070 gen_movl_preg_T0
[dc
->op2
]();
2071 cris_prepare_dyn_jmp(dc
);
2075 static unsigned int dec_basc_im(DisasContext
*dc
)
2078 simm
= ldl_code(dc
->pc
+ 2);
2080 DIS(fprintf (logfile
, "basc 0x%x, $p%u\n", dc
->pc
+ simm
, dc
->op2
));
2081 cris_cc_mask(dc
, 0);
2082 /* Stor the return address in Pd. */
2083 gen_op_movl_T0_im(dc
->pc
+ simm
);
2084 gen_op_movl_btarget_T0();
2085 gen_op_movl_T0_im(dc
->pc
+ 12);
2086 gen_movl_preg_T0
[dc
->op2
]();
2087 cris_prepare_dyn_jmp(dc
);
2091 static unsigned int dec_rfe_etc(DisasContext
*dc
)
2093 DIS(fprintf (logfile
, "rfe_etc opc=%x pc=0x%x op1=%d op2=%d\n",
2094 dc
->opcode
, dc
->pc
, dc
->op1
, dc
->op2
));
2096 cris_cc_mask(dc
, 0);
2098 if (dc
->op2
== 15) /* ignore halt. */
2101 switch (dc
->op2
& 7) {
2104 cris_evaluate_flags(dc
);
2105 gen_op_ccs_rshift();
2113 gen_op_movl_T0_im(dc
->pc
);
2114 gen_op_movl_pc_T0();
2115 /* Breaks start at 16 in the exception vector. */
2116 gen_op_break_im(dc
->op1
+ 16);
2117 dc
->is_jmp
= DISAS_SWI
;
2120 printf ("op2=%x\n", dc
->op2
);
2129 static unsigned int dec_ftag_fidx_d_m(DisasContext
*dc
)
2131 /* Ignore D-cache flushes. */
2135 static unsigned int dec_ftag_fidx_i_m(DisasContext
*dc
)
2137 /* Ignore I-cache flushes. */
2141 static unsigned int dec_null(DisasContext
*dc
)
2143 printf ("unknown insn pc=%x opc=%x op1=%x op2=%x\n",
2144 dc
->pc
, dc
->opcode
, dc
->op1
, dc
->op2
);
2150 struct decoder_info
{
2155 unsigned int (*dec
)(DisasContext
*dc
);
2157 /* Order matters here. */
2158 {DEC_MOVEQ
, dec_moveq
},
2159 {DEC_BTSTQ
, dec_btstq
},
2160 {DEC_CMPQ
, dec_cmpq
},
2161 {DEC_ADDOQ
, dec_addoq
},
2162 {DEC_ADDQ
, dec_addq
},
2163 {DEC_SUBQ
, dec_subq
},
2164 {DEC_ANDQ
, dec_andq
},
2166 {DEC_ASRQ
, dec_asrq
},
2167 {DEC_LSLQ
, dec_lslq
},
2168 {DEC_LSRQ
, dec_lsrq
},
2169 {DEC_BCCQ
, dec_bccq
},
2171 {DEC_BCC_IM
, dec_bcc_im
},
2172 {DEC_JAS_IM
, dec_jas_im
},
2173 {DEC_JAS_R
, dec_jas_r
},
2174 {DEC_JASC_IM
, dec_jasc_im
},
2175 {DEC_JASC_R
, dec_jasc_r
},
2176 {DEC_BAS_IM
, dec_bas_im
},
2177 {DEC_BASC_IM
, dec_basc_im
},
2178 {DEC_JUMP_P
, dec_jump_p
},
2179 {DEC_LAPC_IM
, dec_lapc_im
},
2180 {DEC_LAPCQ
, dec_lapcq
},
2182 {DEC_RFE_ETC
, dec_rfe_etc
},
2183 {DEC_ADDC_MR
, dec_addc_mr
},
2185 {DEC_MOVE_MP
, dec_move_mp
},
2186 {DEC_MOVE_PM
, dec_move_pm
},
2187 {DEC_MOVEM_MR
, dec_movem_mr
},
2188 {DEC_MOVEM_RM
, dec_movem_rm
},
2189 {DEC_MOVE_PR
, dec_move_pr
},
2190 {DEC_SCC_R
, dec_scc_r
},
2191 {DEC_SETF
, dec_setclrf
},
2192 {DEC_CLEARF
, dec_setclrf
},
2194 {DEC_MOVE_SR
, dec_move_sr
},
2195 {DEC_MOVE_RP
, dec_move_rp
},
2196 {DEC_SWAP_R
, dec_swap_r
},
2197 {DEC_ABS_R
, dec_abs_r
},
2198 {DEC_LZ_R
, dec_lz_r
},
2199 {DEC_MOVE_RS
, dec_move_rs
},
2200 {DEC_BTST_R
, dec_btst_r
},
2201 {DEC_ADDC_R
, dec_addc_r
},
2203 {DEC_DSTEP_R
, dec_dstep_r
},
2204 {DEC_XOR_R
, dec_xor_r
},
2205 {DEC_MCP_R
, dec_mcp_r
},
2206 {DEC_CMP_R
, dec_cmp_r
},
2208 {DEC_ADDI_R
, dec_addi_r
},
2209 {DEC_ADDI_ACR
, dec_addi_acr
},
2211 {DEC_ADD_R
, dec_add_r
},
2212 {DEC_SUB_R
, dec_sub_r
},
2214 {DEC_ADDU_R
, dec_addu_r
},
2215 {DEC_ADDS_R
, dec_adds_r
},
2216 {DEC_SUBU_R
, dec_subu_r
},
2217 {DEC_SUBS_R
, dec_subs_r
},
2218 {DEC_LSL_R
, dec_lsl_r
},
2220 {DEC_AND_R
, dec_and_r
},
2221 {DEC_OR_R
, dec_or_r
},
2222 {DEC_BOUND_R
, dec_bound_r
},
2223 {DEC_ASR_R
, dec_asr_r
},
2224 {DEC_LSR_R
, dec_lsr_r
},
2226 {DEC_MOVU_R
, dec_movu_r
},
2227 {DEC_MOVS_R
, dec_movs_r
},
2228 {DEC_NEG_R
, dec_neg_r
},
2229 {DEC_MOVE_R
, dec_move_r
},
2231 {DEC_FTAG_FIDX_I_M
, dec_ftag_fidx_i_m
},
2232 {DEC_FTAG_FIDX_D_M
, dec_ftag_fidx_d_m
},
2234 {DEC_MULS_R
, dec_muls_r
},
2235 {DEC_MULU_R
, dec_mulu_r
},
2237 {DEC_ADDU_M
, dec_addu_m
},
2238 {DEC_ADDS_M
, dec_adds_m
},
2239 {DEC_SUBU_M
, dec_subu_m
},
2240 {DEC_SUBS_M
, dec_subs_m
},
2242 {DEC_CMPU_M
, dec_cmpu_m
},
2243 {DEC_CMPS_M
, dec_cmps_m
},
2244 {DEC_MOVU_M
, dec_movu_m
},
2245 {DEC_MOVS_M
, dec_movs_m
},
2247 {DEC_CMP_M
, dec_cmp_m
},
2248 {DEC_ADDO_M
, dec_addo_m
},
2249 {DEC_BOUND_M
, dec_bound_m
},
2250 {DEC_ADD_M
, dec_add_m
},
2251 {DEC_SUB_M
, dec_sub_m
},
2252 {DEC_AND_M
, dec_and_m
},
2253 {DEC_OR_M
, dec_or_m
},
2254 {DEC_MOVE_RM
, dec_move_rm
},
2255 {DEC_TEST_M
, dec_test_m
},
2256 {DEC_MOVE_MR
, dec_move_mr
},
2261 static inline unsigned int
2262 cris_decoder(DisasContext
*dc
)
2264 unsigned int insn_len
= 2;
2268 /* Load a halfword onto the instruction register. */
2269 tmp
= ldl_code(dc
->pc
);
2270 dc
->ir
= tmp
& 0xffff;
2272 /* Now decode it. */
2273 dc
->opcode
= EXTRACT_FIELD(dc
->ir
, 4, 11);
2274 dc
->op1
= EXTRACT_FIELD(dc
->ir
, 0, 3);
2275 dc
->op2
= EXTRACT_FIELD(dc
->ir
, 12, 15);
2276 dc
->zsize
= EXTRACT_FIELD(dc
->ir
, 4, 4);
2277 dc
->zzsize
= EXTRACT_FIELD(dc
->ir
, 4, 5);
2278 dc
->postinc
= EXTRACT_FIELD(dc
->ir
, 10, 10);
2280 /* Large switch for all insns. */
2281 for (i
= 0; i
< sizeof decinfo
/ sizeof decinfo
[0]; i
++) {
2282 if ((dc
->opcode
& decinfo
[i
].mask
) == decinfo
[i
].bits
)
2284 insn_len
= decinfo
[i
].dec(dc
);
2292 static void check_breakpoint(CPUState
*env
, DisasContext
*dc
)
2295 if (env
->nb_breakpoints
> 0) {
2296 for(j
= 0; j
< env
->nb_breakpoints
; j
++) {
2297 if (env
->breakpoints
[j
] == dc
->pc
) {
2298 cris_evaluate_flags (dc
);
2299 gen_op_movl_T0_im((long)dc
->pc
);
2300 gen_op_movl_pc_T0();
2302 dc
->is_jmp
= DISAS_UPDATE
;
2309 /* generate intermediate code for basic block 'tb'. */
2310 struct DisasContext ctx
;
2312 gen_intermediate_code_internal(CPUState
*env
, TranslationBlock
*tb
,
2315 uint16_t *gen_opc_end
;
2317 unsigned int insn_len
;
2319 struct DisasContext
*dc
= &ctx
;
2320 uint32_t next_page_start
;
2326 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
2328 dc
->is_jmp
= DISAS_NEXT
;
2330 dc
->singlestep_enabled
= env
->singlestep_enabled
;
2333 next_page_start
= (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
2337 check_breakpoint(env
, dc
);
2338 if (dc
->is_jmp
== DISAS_JUMP
2339 || dc
->is_jmp
== DISAS_SWI
)
2343 j
= gen_opc_ptr
- gen_opc_buf
;
2347 gen_opc_instr_start
[lj
++] = 0;
2349 gen_opc_pc
[lj
] = dc
->pc
;
2350 gen_opc_instr_start
[lj
] = 1;
2353 insn_len
= cris_decoder(dc
);
2354 STATS(gen_op_exec_insn());
2357 || (dc
->flagx_live
&&
2358 !(dc
->cc_op
== CC_OP_FLAGS
&& dc
->flags_x
))) {
2359 gen_movl_T0_preg
[PR_CCS
]();
2360 gen_op_andl_T0_im(~X_FLAG
);
2361 gen_movl_preg_T0
[PR_CCS
]();
2366 /* Check for delayed branches here. If we do it before
2367 actually genereating any host code, the simulator will just
2368 loop doing nothing for on this program location. */
2369 if (dc
->delayed_branch
) {
2370 dc
->delayed_branch
--;
2371 if (dc
->delayed_branch
== 0)
2373 if (dc
->bcc
== CC_A
) {
2375 dc
->is_jmp
= DISAS_UPDATE
;
2378 /* Conditional jmp. */
2379 gen_op_cc_jmp (dc
->delayed_pc
, dc
->pc
);
2380 dc
->is_jmp
= DISAS_UPDATE
;
2385 if (env
->singlestep_enabled
)
2387 } while (!dc
->is_jmp
&& gen_opc_ptr
< gen_opc_end
2388 && dc
->pc
< next_page_start
);
2391 gen_op_movl_T0_im((long)dc
->pc
);
2392 gen_op_movl_pc_T0();
2395 cris_evaluate_flags (dc
);
2397 if (__builtin_expect(env
->singlestep_enabled
, 0)) {
2400 switch(dc
->is_jmp
) {
2402 gen_goto_tb(dc
, 1, dc
->pc
);
2407 /* indicate that the hash table must be used
2408 to find the next TB */
2413 /* nothing more to generate */
2417 *gen_opc_ptr
= INDEX_op_end
;
2419 j
= gen_opc_ptr
- gen_opc_buf
;
2422 gen_opc_instr_start
[lj
++] = 0;
2424 tb
->size
= dc
->pc
- pc_start
;
2428 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
2429 fprintf(logfile
, "--------------\n");
2430 fprintf(logfile
, "IN: %s\n", lookup_symbol(pc_start
));
2431 target_disas(logfile
, pc_start
, dc
->pc
+ 4 - pc_start
, 0);
2432 fprintf(logfile
, "\n");
2438 int gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
2440 return gen_intermediate_code_internal(env
, tb
, 0);
2443 int gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
2445 return gen_intermediate_code_internal(env
, tb
, 1);
2448 void cpu_dump_state (CPUState
*env
, FILE *f
,
2449 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
2458 cpu_fprintf(f
, "PC=%x CCS=%x btaken=%d btarget=%x\n"
2459 "cc_op=%d cc_src=%d cc_dest=%d cc_result=%x cc_mask=%x\n"
2461 env
->pc
, env
->pregs
[PR_CCS
], env
->btaken
, env
->btarget
,
2463 env
->cc_src
, env
->cc_dest
, env
->cc_result
, env
->cc_mask
,
2464 env
->debug1
, env
->debug2
, env
->debug3
);
2466 for (i
= 0; i
< 16; i
++) {
2467 cpu_fprintf(f
, "r%2.2d=%8.8x ", i
, env
->regs
[i
]);
2468 if ((i
+ 1) % 4 == 0)
2469 cpu_fprintf(f
, "\n");
2471 cpu_fprintf(f
, "\nspecial regs:\n");
2472 for (i
= 0; i
< 16; i
++) {
2473 cpu_fprintf(f
, "p%2.2d=%8.8x ", i
, env
->pregs
[i
]);
2474 if ((i
+ 1) % 4 == 0)
2475 cpu_fprintf(f
, "\n");
2477 srs
= env
->pregs
[PR_SRS
];
2478 cpu_fprintf(f
, "\nsupport function regs bank %d:\n", srs
);
2480 for (i
= 0; i
< 16; i
++) {
2481 cpu_fprintf(f
, "s%2.2d=%8.8x ",
2482 i
, env
->sregs
[srs
][i
]);
2483 if ((i
+ 1) % 4 == 0)
2484 cpu_fprintf(f
, "\n");
2487 cpu_fprintf(f
, "\n\n");
2491 CPUCRISState
*cpu_cris_init (const char *cpu_model
)
2495 env
= qemu_mallocz(sizeof(CPUCRISState
));
2503 void cpu_reset (CPUCRISState
*env
)
2505 memset(env
, 0, offsetof(CPUCRISState
, breakpoints
));