2 * CRISv10 emulation for qemu: main translation routines.
4 * Copyright (c) 2010 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, see <http://www.gnu.org/licenses/>.
21 #include "crisv10-decode.h"
23 static const char *regnames_v10
[] =
25 "$r0", "$r1", "$r2", "$r3",
26 "$r4", "$r5", "$r6", "$r7",
27 "$r8", "$r9", "$r10", "$r11",
28 "$r12", "$r13", "$sp", "$pc",
31 static const char *pregnames_v10
[] =
33 "$bz", "$vr", "$p2", "$p3",
34 "$wz", "$ccr", "$p6-prefix", "$mof",
35 "$dz", "$ibr", "$irp", "$srp",
36 "$bar", "$dccr", "$brp", "$usp",
39 /* We need this table to handle preg-moves with implicit width. */
40 static int preg_sizes_v10
[] = {
51 static inline int dec10_size(unsigned int size
)
59 static inline void cris_illegal_insn(DisasContext
*dc
)
61 qemu_log("illegal insn at pc=%x\n", dc
->pc
);
62 t_gen_raise_exception(EXCP_BREAK
);
65 /* Prefix flag and register are used to handle the more complex
67 static void cris_set_prefix(DisasContext
*dc
)
70 dc
->tb_flags
|= PFIX_FLAG
;
71 tcg_gen_ori_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], PFIX_FLAG
);
73 /* prefix insns dont clear the x flag. */
78 static void crisv10_prepare_memaddr(DisasContext
*dc
,
79 TCGv addr
, unsigned int size
)
81 if (dc
->tb_flags
& PFIX_FLAG
) {
82 tcg_gen_mov_tl(addr
, cpu_PR
[PR_PREFIX
]);
84 tcg_gen_mov_tl(addr
, cpu_R
[dc
->src
]);
88 static unsigned int crisv10_post_memaddr(DisasContext
*dc
, unsigned int size
)
90 unsigned int insn_len
= 0;
92 if (dc
->tb_flags
& PFIX_FLAG
) {
93 if (dc
->mode
== CRISV10_MODE_AUTOINC
) {
94 tcg_gen_mov_tl(cpu_R
[dc
->src
], cpu_PR
[PR_PREFIX
]);
97 if (dc
->mode
== CRISV10_MODE_AUTOINC
) {
99 insn_len
+= size
& ~1;
101 tcg_gen_addi_tl(cpu_R
[dc
->src
], cpu_R
[dc
->src
], size
);
108 static int dec10_prep_move_m(DisasContext
*dc
, int s_ext
, int memsize
,
118 is_imm
= rs
== 15 && !(dc
->tb_flags
& PFIX_FLAG
);
119 LOG_DIS("rs=%d rd=%d is_imm=%d mode=%d pfix=%d\n",
120 rs
, rd
, is_imm
, dc
->mode
, dc
->tb_flags
& PFIX_FLAG
);
122 /* Load [$rs] onto T1. */
127 imm
= ldsb_code(dc
->pc
+ 2);
129 imm
= ldsw_code(dc
->pc
+ 2);
132 imm
= ldub_code(dc
->pc
+ 2);
134 imm
= lduw_code(dc
->pc
+ 2);
137 imm
= ldl_code(dc
->pc
+ 2);
139 tcg_gen_movi_tl(dst
, imm
);
141 if (dc
->mode
== CRISV10_MODE_AUTOINC
) {
145 tcg_gen_addi_tl(cpu_R
[15], cpu_R
[15], insn_len
);
150 addr
= tcg_temp_new();
151 cris_flush_cc_state(dc
);
152 crisv10_prepare_memaddr(dc
, addr
, memsize
);
153 gen_load(dc
, dst
, addr
, memsize
, 0);
155 t_gen_sext(dst
, dst
, memsize
);
157 t_gen_zext(dst
, dst
, memsize
);
158 insn_len
+= crisv10_post_memaddr(dc
, memsize
);
162 if (dc
->mode
== CRISV10_MODE_INDIRECT
&& (dc
->tb_flags
& PFIX_FLAG
)) {
168 static unsigned int dec10_quick_imm(DisasContext
*dc
)
174 imm
= dc
->ir
& ((1 << 6) - 1);
175 simm
= (int8_t) (imm
<< 2);
177 switch (dc
->opcode
) {
178 case CRISV10_QIMM_BDAP_R0
:
179 case CRISV10_QIMM_BDAP_R1
:
180 case CRISV10_QIMM_BDAP_R2
:
181 case CRISV10_QIMM_BDAP_R3
:
182 simm
= (int8_t)dc
->ir
;
183 LOG_DIS("bdap %d $r%d\n", simm
, dc
->dst
);
184 LOG_DIS("pc=%x mode=%x quickimm %d r%d r%d\n",
185 dc
->pc
, dc
->mode
, dc
->opcode
, dc
->src
, dc
->dst
);
188 tcg_gen_movi_tl(cpu_PR
[PR_PREFIX
], dc
->pc
+ 2 + simm
);
190 tcg_gen_addi_tl(cpu_PR
[PR_PREFIX
], cpu_R
[dc
->dst
], simm
);
194 case CRISV10_QIMM_MOVEQ
:
195 LOG_DIS("moveq %d, $r%d\n", simm
, dc
->dst
);
197 cris_cc_mask(dc
, CC_MASK_NZVC
);
198 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->dst
],
199 cpu_R
[dc
->dst
], tcg_const_tl(simm
), 4);
201 case CRISV10_QIMM_CMPQ
:
202 LOG_DIS("cmpq %d, $r%d\n", simm
, dc
->dst
);
204 cris_cc_mask(dc
, CC_MASK_NZVC
);
205 cris_alu(dc
, CC_OP_CMP
, cpu_R
[dc
->dst
],
206 cpu_R
[dc
->dst
], tcg_const_tl(simm
), 4);
208 case CRISV10_QIMM_ADDQ
:
209 LOG_DIS("addq %d, $r%d\n", imm
, dc
->dst
);
211 cris_cc_mask(dc
, CC_MASK_NZVC
);
212 cris_alu(dc
, CC_OP_ADD
, cpu_R
[dc
->dst
],
213 cpu_R
[dc
->dst
], tcg_const_tl(imm
), 4);
215 case CRISV10_QIMM_ANDQ
:
216 LOG_DIS("andq %d, $r%d\n", simm
, dc
->dst
);
218 cris_cc_mask(dc
, CC_MASK_NZVC
);
219 cris_alu(dc
, CC_OP_AND
, cpu_R
[dc
->dst
],
220 cpu_R
[dc
->dst
], tcg_const_tl(simm
), 4);
222 case CRISV10_QIMM_ASHQ
:
223 LOG_DIS("ashq %d, $r%d\n", simm
, dc
->dst
);
225 cris_cc_mask(dc
, CC_MASK_NZVC
);
229 cris_alu(dc
, CC_OP_ASR
, cpu_R
[dc
->dst
],
230 cpu_R
[dc
->dst
], tcg_const_tl(imm
), 4);
233 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
234 gen_helper_btst(cpu_PR
[PR_CCS
], cpu_R
[dc
->dst
],
235 tcg_const_tl(imm
), cpu_PR
[PR_CCS
]);
238 case CRISV10_QIMM_LSHQ
:
239 LOG_DIS("lshq %d, $r%d\n", simm
, dc
->dst
);
242 if (imm
& (1 << 5)) {
246 cris_cc_mask(dc
, CC_MASK_NZVC
);
247 cris_alu(dc
, op
, cpu_R
[dc
->dst
],
248 cpu_R
[dc
->dst
], tcg_const_tl(imm
), 4);
250 case CRISV10_QIMM_SUBQ
:
251 LOG_DIS("subq %d, $r%d\n", imm
, dc
->dst
);
253 cris_cc_mask(dc
, CC_MASK_NZVC
);
254 cris_alu(dc
, CC_OP_SUB
, cpu_R
[dc
->dst
],
255 cpu_R
[dc
->dst
], tcg_const_tl(imm
), 4);
257 case CRISV10_QIMM_ORQ
:
258 LOG_DIS("andq %d, $r%d\n", simm
, dc
->dst
);
260 cris_cc_mask(dc
, CC_MASK_NZVC
);
261 cris_alu(dc
, CC_OP_OR
, cpu_R
[dc
->dst
],
262 cpu_R
[dc
->dst
], tcg_const_tl(simm
), 4);
265 case CRISV10_QIMM_BCC_R0
:
267 cpu_abort(dc
->env
, "opcode zero\n");
269 case CRISV10_QIMM_BCC_R1
:
270 case CRISV10_QIMM_BCC_R2
:
271 case CRISV10_QIMM_BCC_R3
:
273 /* bit 0 is a sign bit. */
275 imm
|= 0xffffff00; /* sign extend. */
276 imm
&= ~1; /* get rid of the sign bit. */
279 LOG_DIS("b%s %d\n", cc_name(dc
->cond
), imm
);
282 cris_prepare_cc_branch(dc
, imm
, dc
->cond
);
286 LOG_DIS("pc=%x mode=%x quickimm %d r%d r%d\n",
287 dc
->pc
, dc
->mode
, dc
->opcode
, dc
->src
, dc
->dst
);
288 cpu_abort(dc
->env
, "Unhandled quickimm\n");
294 static unsigned int dec10_setclrf(DisasContext
*dc
)
297 unsigned int set
= ~dc
->opcode
& 1;
299 flags
= EXTRACT_FIELD(dc
->ir
, 0, 3)
300 | (EXTRACT_FIELD(dc
->ir
, 12, 15) << 4);
301 LOG_DIS("%s set=%d flags=%x\n", __func__
, set
, flags
);
304 if (flags
& X_FLAG
) {
307 dc
->flags_x
= X_FLAG
;
312 cris_evaluate_flags (dc
);
313 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
314 cris_update_cc_x(dc
);
315 tcg_gen_movi_tl(cc_op
, dc
->cc_op
);
318 tcg_gen_ori_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], flags
);
320 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~flags
);
323 dc
->flags_uptodate
= 1;
329 static inline void dec10_reg_prep_sext(DisasContext
*dc
, int size
, int sext
,
330 TCGv dd
, TCGv ds
, TCGv sd
, TCGv ss
)
333 t_gen_sext(dd
, sd
, size
);
334 t_gen_sext(ds
, ss
, size
);
336 t_gen_zext(dd
, sd
, size
);
337 t_gen_zext(ds
, ss
, size
);
341 static void dec10_reg_alu(DisasContext
*dc
, int op
, int size
, int sext
)
345 t
[0] = tcg_temp_new();
346 t
[1] = tcg_temp_new();
347 dec10_reg_prep_sext(dc
, size
, sext
,
348 t
[0], t
[1], cpu_R
[dc
->dst
], cpu_R
[dc
->src
]);
350 if (op
== CC_OP_LSL
|| op
== CC_OP_LSR
|| op
== CC_OP_ASR
) {
351 tcg_gen_andi_tl(t
[1], t
[1], 63);
354 assert(dc
->dst
!= 15);
355 cris_alu(dc
, op
, cpu_R
[dc
->dst
], t
[0], t
[1], size
);
360 static void dec10_reg_bound(DisasContext
*dc
, int size
)
364 t
= tcg_temp_local_new();
365 t_gen_zext(t
, cpu_R
[dc
->src
], size
);
366 cris_alu(dc
, CC_OP_BOUND
, cpu_R
[dc
->dst
], cpu_R
[dc
->dst
], t
, 4);
370 static void dec10_reg_mul(DisasContext
*dc
, int size
, int sext
)
372 int op
= sext
? CC_OP_MULS
: CC_OP_MULU
;
375 t
[0] = tcg_temp_new();
376 t
[1] = tcg_temp_new();
377 dec10_reg_prep_sext(dc
, size
, sext
,
378 t
[0], t
[1], cpu_R
[dc
->dst
], cpu_R
[dc
->src
]);
380 cris_alu(dc
, op
, cpu_R
[dc
->dst
], t
[0], t
[1], 4);
387 static void dec10_reg_movs(DisasContext
*dc
)
389 int size
= (dc
->size
& 1) + 1;
392 LOG_DIS("movx.%d $r%d, $r%d\n", size
, dc
->src
, dc
->dst
);
393 cris_cc_mask(dc
, CC_MASK_NZVC
);
397 t_gen_sext(t
, cpu_R
[dc
->src
], size
);
399 t_gen_zext(t
, cpu_R
[dc
->src
], size
);
401 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->dst
], cpu_R
[dc
->dst
], t
, 4);
405 static void dec10_reg_alux(DisasContext
*dc
, int op
)
407 int size
= (dc
->size
& 1) + 1;
410 LOG_DIS("movx.%d $r%d, $r%d\n", size
, dc
->src
, dc
->dst
);
411 cris_cc_mask(dc
, CC_MASK_NZVC
);
415 t_gen_sext(t
, cpu_R
[dc
->src
], size
);
417 t_gen_zext(t
, cpu_R
[dc
->src
], size
);
419 cris_alu(dc
, op
, cpu_R
[dc
->dst
], cpu_R
[dc
->dst
], t
, 4);
423 static void dec10_reg_mov_pr(DisasContext
*dc
)
425 LOG_DIS("move p%d r%d sz=%d\n", dc
->dst
, dc
->src
, preg_sizes_v10
[dc
->dst
]);
428 tcg_gen_mov_tl(env_btarget
, cpu_PR
[dc
->dst
]);
429 cris_prepare_jmp(dc
, JMP_INDIRECT
);
432 if (dc
->dst
== PR_CCS
) {
433 cris_evaluate_flags(dc
);
435 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->src
],
436 cpu_R
[dc
->src
], cpu_PR
[dc
->dst
], preg_sizes_v10
[dc
->dst
]);
439 static void dec10_reg_abs(DisasContext
*dc
)
443 LOG_DIS("abs $r%u, $r%u\n", dc
->src
, dc
->dst
);
445 assert(dc
->dst
!= 15);
447 tcg_gen_sari_tl(t0
, cpu_R
[dc
->src
], 31);
448 tcg_gen_xor_tl(cpu_R
[dc
->dst
], cpu_R
[dc
->src
], t0
);
449 tcg_gen_sub_tl(t0
, cpu_R
[dc
->dst
], t0
);
451 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->dst
], cpu_R
[dc
->dst
], t0
, 4);
455 static void dec10_reg_swap(DisasContext
*dc
)
459 LOG_DIS("not $r%d, $r%d\n", dc
->src
, dc
->dst
);
461 cris_cc_mask(dc
, CC_MASK_NZVC
);
463 t_gen_mov_TN_reg(t0
, dc
->src
);
465 tcg_gen_not_tl(t0
, t0
);
472 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->src
], cpu_R
[dc
->src
], t0
, 4);
476 static void dec10_reg_scc(DisasContext
*dc
)
480 LOG_DIS("s%s $r%u\n", cc_name(cond
), dc
->src
);
486 gen_tst_cc (dc
, cpu_R
[dc
->src
], cond
);
487 l1
= gen_new_label();
488 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_R
[dc
->src
], 0, l1
);
489 tcg_gen_movi_tl(cpu_R
[dc
->src
], 1);
492 tcg_gen_movi_tl(cpu_R
[dc
->src
], 1);
498 static unsigned int dec10_reg(DisasContext
*dc
)
501 unsigned int insn_len
= 2;
502 unsigned int size
= dec10_size(dc
->size
);
506 switch (dc
->opcode
) {
507 case CRISV10_REG_MOVE_R
:
508 LOG_DIS("move.%d $r%d, $r%d\n", dc
->size
, dc
->src
, dc
->dst
);
509 cris_cc_mask(dc
, CC_MASK_NZVC
);
510 dec10_reg_alu(dc
, CC_OP_MOVE
, size
, 0);
512 tcg_gen_mov_tl(env_btarget
, cpu_R
[dc
->dst
]);
513 cris_prepare_jmp(dc
, JMP_INDIRECT
);
514 dc
->delayed_branch
= 1;
517 case CRISV10_REG_MOVX
:
518 cris_cc_mask(dc
, CC_MASK_NZVC
);
521 case CRISV10_REG_ADDX
:
522 cris_cc_mask(dc
, CC_MASK_NZVC
);
523 dec10_reg_alux(dc
, CC_OP_ADD
);
525 case CRISV10_REG_SUBX
:
526 cris_cc_mask(dc
, CC_MASK_NZVC
);
527 dec10_reg_alux(dc
, CC_OP_SUB
);
529 case CRISV10_REG_ADD
:
530 LOG_DIS("add $r%d, $r%d sz=%d\n", dc
->src
, dc
->dst
, size
);
531 cris_cc_mask(dc
, CC_MASK_NZVC
);
532 dec10_reg_alu(dc
, CC_OP_ADD
, size
, 0);
534 case CRISV10_REG_SUB
:
535 LOG_DIS("sub $r%d, $r%d sz=%d\n", dc
->src
, dc
->dst
, size
);
536 cris_cc_mask(dc
, CC_MASK_NZVC
);
537 dec10_reg_alu(dc
, CC_OP_SUB
, size
, 0);
539 case CRISV10_REG_CMP
:
540 LOG_DIS("cmp $r%d, $r%d sz=%d\n", dc
->src
, dc
->dst
, size
);
541 cris_cc_mask(dc
, CC_MASK_NZVC
);
542 dec10_reg_alu(dc
, CC_OP_CMP
, size
, 0);
544 case CRISV10_REG_BOUND
:
545 LOG_DIS("bound $r%d, $r%d sz=%d\n", dc
->src
, dc
->dst
, size
);
546 cris_cc_mask(dc
, CC_MASK_NZVC
);
547 dec10_reg_bound(dc
, size
);
549 case CRISV10_REG_AND
:
550 LOG_DIS("and $r%d, $r%d sz=%d\n", dc
->src
, dc
->dst
, size
);
551 cris_cc_mask(dc
, CC_MASK_NZVC
);
552 dec10_reg_alu(dc
, CC_OP_AND
, size
, 0);
554 case CRISV10_REG_ADDI
:
560 LOG_DIS("addi r%d r%d size=%d\n", dc
->src
, dc
->dst
, dc
->size
);
561 tcg_gen_shli_tl(t
, cpu_R
[dc
->dst
], dc
->size
& 3);
562 tcg_gen_add_tl(cpu_R
[dc
->src
], cpu_R
[dc
->src
], t
);
565 case CRISV10_REG_LSL
:
566 LOG_DIS("lsl $r%d, $r%d sz=%d\n", dc
->src
, dc
->dst
, size
);
567 cris_cc_mask(dc
, CC_MASK_NZVC
);
568 dec10_reg_alu(dc
, CC_OP_LSL
, size
, 0);
570 case CRISV10_REG_LSR
:
571 LOG_DIS("lsr $r%d, $r%d sz=%d\n", dc
->src
, dc
->dst
, size
);
572 cris_cc_mask(dc
, CC_MASK_NZVC
);
573 dec10_reg_alu(dc
, CC_OP_LSR
, size
, 0);
575 case CRISV10_REG_ASR
:
576 LOG_DIS("asr $r%d, $r%d sz=%d\n", dc
->src
, dc
->dst
, size
);
577 cris_cc_mask(dc
, CC_MASK_NZVC
);
578 dec10_reg_alu(dc
, CC_OP_ASR
, size
, 1);
581 LOG_DIS("or $r%d, $r%d sz=%d\n", dc
->src
, dc
->dst
, size
);
582 cris_cc_mask(dc
, CC_MASK_NZVC
);
583 dec10_reg_alu(dc
, CC_OP_OR
, size
, 0);
585 case CRISV10_REG_NEG
:
586 LOG_DIS("neg $r%d, $r%d sz=%d\n", dc
->src
, dc
->dst
, size
);
587 cris_cc_mask(dc
, CC_MASK_NZVC
);
588 dec10_reg_alu(dc
, CC_OP_NEG
, size
, 0);
590 case CRISV10_REG_BIAP
:
591 LOG_DIS("BIAP pc=%x reg %d r%d r%d size=%d\n", dc
->pc
,
592 dc
->opcode
, dc
->src
, dc
->dst
, size
);
594 case 4: tmp
= 2; break;
595 case 2: tmp
= 1; break;
596 case 1: tmp
= 0; break;
598 cpu_abort(dc
->env
, "Unhandled BIAP");
603 tcg_gen_shli_tl(t
, cpu_R
[dc
->dst
], tmp
);
605 tcg_gen_addi_tl(cpu_PR
[PR_PREFIX
], t
, ((dc
->pc
+2)| 1) + 1);
607 tcg_gen_add_tl(cpu_PR
[PR_PREFIX
], cpu_R
[dc
->src
], t
);
614 LOG_DIS("pc=%x reg %d r%d r%d\n", dc
->pc
,
615 dc
->opcode
, dc
->src
, dc
->dst
);
616 cpu_abort(dc
->env
, "Unhandled opcode");
620 switch (dc
->opcode
) {
621 case CRISV10_REG_MOVX
:
622 cris_cc_mask(dc
, CC_MASK_NZVC
);
625 case CRISV10_REG_ADDX
:
626 cris_cc_mask(dc
, CC_MASK_NZVC
);
627 dec10_reg_alux(dc
, CC_OP_ADD
);
629 case CRISV10_REG_SUBX
:
630 cris_cc_mask(dc
, CC_MASK_NZVC
);
631 dec10_reg_alux(dc
, CC_OP_SUB
);
633 case CRISV10_REG_MOVE_SPR_R
:
634 cris_evaluate_flags(dc
);
636 dec10_reg_mov_pr(dc
);
638 case CRISV10_REG_MOVE_R_SPR
:
639 LOG_DIS("move r%d p%d\n", dc
->src
, dc
->dst
);
640 cris_evaluate_flags(dc
);
641 if (dc
->src
!= 11) /* fast for srp. */
642 dc
->cpustate_changed
= 1;
643 t_gen_mov_preg_TN(dc
, dc
->dst
, cpu_R
[dc
->src
]);
645 case CRISV10_REG_SETF
:
646 case CRISV10_REG_CLEARF
:
649 case CRISV10_REG_SWAP
:
652 case CRISV10_REG_ABS
:
653 cris_cc_mask(dc
, CC_MASK_NZVC
);
657 LOG_DIS("lz $r%d, $r%d sz=%d\n", dc
->src
, dc
->dst
, size
);
658 cris_cc_mask(dc
, CC_MASK_NZVC
);
659 dec10_reg_alu(dc
, CC_OP_LZ
, 4, 0);
661 case CRISV10_REG_XOR
:
662 LOG_DIS("xor $r%d, $r%d sz=%d\n", dc
->src
, dc
->dst
, size
);
663 cris_cc_mask(dc
, CC_MASK_NZVC
);
664 dec10_reg_alu(dc
, CC_OP_XOR
, 4, 0);
666 case CRISV10_REG_BTST
:
667 LOG_DIS("btst $r%d, $r%d sz=%d\n", dc
->src
, dc
->dst
, size
);
668 cris_cc_mask(dc
, CC_MASK_NZVC
);
669 cris_update_cc_op(dc
, CC_OP_FLAGS
, 4);
670 gen_helper_btst(cpu_PR
[PR_CCS
], cpu_R
[dc
->dst
],
671 cpu_R
[dc
->src
], cpu_PR
[PR_CCS
]);
673 case CRISV10_REG_DSTEP
:
674 LOG_DIS("dstep $r%d, $r%d sz=%d\n", dc
->src
, dc
->dst
, size
);
675 cris_cc_mask(dc
, CC_MASK_NZVC
);
676 cris_alu(dc
, CC_OP_DSTEP
, cpu_R
[dc
->dst
],
677 cpu_R
[dc
->dst
], cpu_R
[dc
->src
], 4);
679 case CRISV10_REG_MSTEP
:
680 LOG_DIS("mstep $r%d, $r%d sz=%d\n", dc
->src
, dc
->dst
, size
);
681 cris_evaluate_flags(dc
);
682 cris_cc_mask(dc
, CC_MASK_NZVC
);
683 cris_alu(dc
, CC_OP_MSTEP
, cpu_R
[dc
->dst
],
684 cpu_R
[dc
->dst
], cpu_R
[dc
->src
], 4);
686 case CRISV10_REG_SCC
:
690 LOG_DIS("pc=%x reg %d r%d r%d\n", dc
->pc
,
691 dc
->opcode
, dc
->src
, dc
->dst
);
692 cpu_abort(dc
->env
, "Unhandled opcode");
699 static unsigned int dec10_ind_move_m_r(DisasContext
*dc
, unsigned int size
)
701 unsigned int insn_len
= 2;
704 LOG_DIS("%s: move.%d [$r%d], $r%d\n", __func__
,
705 size
, dc
->src
, dc
->dst
);
707 cris_cc_mask(dc
, CC_MASK_NZVC
);
709 insn_len
+= dec10_prep_move_m(dc
, 0, size
, t
);
710 cris_alu(dc
, CC_OP_MOVE
, cpu_R
[dc
->dst
], cpu_R
[dc
->dst
], t
, size
);
712 tcg_gen_mov_tl(env_btarget
, cpu_R
[dc
->dst
]);
713 cris_prepare_jmp(dc
, JMP_INDIRECT
);
714 dc
->delayed_branch
= 1;
722 static unsigned int dec10_ind_move_r_m(DisasContext
*dc
, unsigned int size
)
724 unsigned int insn_len
= 2;
727 LOG_DIS("move.%d $r%d, [$r%d]\n", dc
->size
, dc
->src
, dc
->dst
);
728 addr
= tcg_temp_new();
729 crisv10_prepare_memaddr(dc
, addr
, size
);
730 gen_store(dc
, addr
, cpu_R
[dc
->dst
], size
);
731 insn_len
+= crisv10_post_memaddr(dc
, size
);
736 static unsigned int dec10_ind_move_m_pr(DisasContext
*dc
)
738 unsigned int insn_len
= 2, rd
= dc
->dst
;
741 LOG_DIS("move.%d $p%d, [$r%d]\n", dc
->size
, dc
->dst
, dc
->src
);
744 addr
= tcg_temp_new();
746 insn_len
+= dec10_prep_move_m(dc
, 0, 4, t
);
748 tcg_gen_mov_tl(env_btarget
, t
);
749 cris_prepare_jmp(dc
, JMP_INDIRECT
);
750 dc
->delayed_branch
= 1;
754 tcg_gen_mov_tl(cpu_PR
[rd
], t
);
755 dc
->cpustate_changed
= 1;
761 static unsigned int dec10_ind_move_pr_m(DisasContext
*dc
)
763 unsigned int insn_len
= 2, size
= preg_sizes_v10
[dc
->dst
];
766 LOG_DIS("move.%d $p%d, [$r%d]\n", dc
->size
, dc
->dst
, dc
->src
);
768 addr
= tcg_temp_new();
769 crisv10_prepare_memaddr(dc
, addr
, size
);
770 if (dc
->dst
== PR_CCS
) {
772 cris_evaluate_flags(dc
);
773 tcg_gen_andi_tl(t0
, cpu_PR
[PR_CCS
], ~PFIX_FLAG
);
774 gen_store(dc
, addr
, t0
, size
);
777 gen_store(dc
, addr
, cpu_PR
[dc
->dst
], size
);
780 insn_len
+= crisv10_post_memaddr(dc
, size
);
786 static void dec10_movem_r_m(DisasContext
*dc
)
788 int i
, pfix
= dc
->tb_flags
& PFIX_FLAG
;
791 LOG_DIS("%s r%d, [r%d] pi=%d ir=%x\n", __func__
,
792 dc
->dst
, dc
->src
, dc
->postinc
, dc
->ir
);
794 addr
= tcg_temp_new();
796 crisv10_prepare_memaddr(dc
, addr
, 4);
797 tcg_gen_mov_tl(t0
, addr
);
798 for (i
= dc
->dst
; i
>= 0; i
--) {
799 if ((pfix
&& dc
->mode
== CRISV10_MODE_AUTOINC
) && dc
->src
== i
) {
800 gen_store(dc
, addr
, t0
, 4);
802 gen_store(dc
, addr
, cpu_R
[i
], 4);
804 tcg_gen_addi_tl(addr
, addr
, 4);
807 if (pfix
&& dc
->mode
== CRISV10_MODE_AUTOINC
) {
808 tcg_gen_mov_tl(cpu_R
[dc
->src
], t0
);
811 if (!pfix
&& dc
->mode
== CRISV10_MODE_AUTOINC
) {
812 tcg_gen_mov_tl(cpu_R
[dc
->src
], addr
);
818 static void dec10_movem_m_r(DisasContext
*dc
)
820 int i
, pfix
= dc
->tb_flags
& PFIX_FLAG
;
823 LOG_DIS("%s [r%d], r%d pi=%d ir=%x\n", __func__
,
824 dc
->src
, dc
->dst
, dc
->postinc
, dc
->ir
);
826 addr
= tcg_temp_new();
828 crisv10_prepare_memaddr(dc
, addr
, 4);
829 tcg_gen_mov_tl(t0
, addr
);
830 for (i
= dc
->dst
; i
>= 0; i
--) {
831 gen_load(dc
, cpu_R
[i
], addr
, 4, 0);
832 tcg_gen_addi_tl(addr
, addr
, 4);
835 if (pfix
&& dc
->mode
== CRISV10_MODE_AUTOINC
) {
836 tcg_gen_mov_tl(cpu_R
[dc
->src
], t0
);
839 if (!pfix
&& dc
->mode
== CRISV10_MODE_AUTOINC
) {
840 tcg_gen_mov_tl(cpu_R
[dc
->src
], addr
);
846 static int dec10_ind_alu(DisasContext
*dc
, int op
, unsigned int size
)
852 cris_alu_m_alloc_temps(t
);
853 insn_len
+= dec10_prep_move_m(dc
, 0, size
, t
[0]);
854 cris_alu(dc
, op
, cpu_R
[dc
->dst
], cpu_R
[rd
], t
[0], size
);
856 tcg_gen_mov_tl(env_btarget
, cpu_R
[dc
->dst
]);
857 cris_prepare_jmp(dc
, JMP_INDIRECT
);
858 dc
->delayed_branch
= 1;
862 cris_alu_m_free_temps(t
);
867 static int dec10_ind_bound(DisasContext
*dc
, unsigned int size
)
873 t
= tcg_temp_local_new();
874 insn_len
+= dec10_prep_move_m(dc
, 0, size
, t
);
875 cris_alu(dc
, CC_OP_BOUND
, cpu_R
[dc
->dst
], cpu_R
[rd
], t
, 4);
877 tcg_gen_mov_tl(env_btarget
, cpu_R
[dc
->dst
]);
878 cris_prepare_jmp(dc
, JMP_INDIRECT
);
879 dc
->delayed_branch
= 1;
887 static int dec10_alux_m(DisasContext
*dc
, int op
)
889 unsigned int size
= (dc
->size
& 1) ? 2 : 1;
890 unsigned int sx
= !!(dc
->size
& 2);
895 LOG_DIS("addx size=%d sx=%d op=%d %d\n", size
, sx
, dc
->src
, dc
->dst
);
899 cris_cc_mask(dc
, CC_MASK_NZVC
);
900 insn_len
+= dec10_prep_move_m(dc
, sx
, size
, t
);
901 cris_alu(dc
, op
, cpu_R
[dc
->dst
], cpu_R
[rd
], t
, 4);
903 tcg_gen_mov_tl(env_btarget
, cpu_R
[dc
->dst
]);
904 cris_prepare_jmp(dc
, JMP_INDIRECT
);
905 dc
->delayed_branch
= 1;
913 static int dec10_dip(DisasContext
*dc
)
918 LOG_DIS("dip pc=%x opcode=%d r%d r%d\n",
919 dc
->pc
, dc
->opcode
, dc
->src
, dc
->dst
);
921 imm
= ldl_code(dc
->pc
+ 2);
922 tcg_gen_movi_tl(cpu_PR
[PR_PREFIX
], imm
);
925 tcg_gen_addi_tl(cpu_R
[15], cpu_R
[15], insn_len
- 2);
927 gen_load(dc
, cpu_PR
[PR_PREFIX
], cpu_R
[dc
->src
], 4, 0);
929 tcg_gen_addi_tl(cpu_R
[dc
->src
], cpu_R
[dc
->src
], 4);
936 static int dec10_bdap_m(DisasContext
*dc
, int size
)
941 LOG_DIS("bdap_m pc=%x opcode=%d r%d r%d sz=%d\n",
942 dc
->pc
, dc
->opcode
, dc
->src
, dc
->dst
, size
);
944 assert(dc
->dst
!= 15);
946 /* 8bit embedded offset? */
947 if (!dc
->postinc
&& (dc
->ir
& (1 << 11))) {
948 int simm
= dc
->ir
& 0xff;
950 /* cpu_abort(dc->env, "Unhandled opcode"); */
954 tcg_gen_addi_tl(cpu_PR
[PR_PREFIX
], cpu_R
[dc
->dst
], simm
);
960 /* Now the rest of the modes are truely indirect. */
961 insn_len
+= dec10_prep_move_m(dc
, 1, size
, cpu_PR
[PR_PREFIX
]);
962 tcg_gen_add_tl(cpu_PR
[PR_PREFIX
], cpu_PR
[PR_PREFIX
], cpu_R
[rd
]);
967 static unsigned int dec10_ind(DisasContext
*dc
)
969 unsigned int insn_len
= 2;
970 unsigned int size
= dec10_size(dc
->size
);
976 switch (dc
->opcode
) {
977 case CRISV10_IND_MOVE_M_R
:
978 return dec10_ind_move_m_r(dc
, size
);
980 case CRISV10_IND_MOVE_R_M
:
981 return dec10_ind_move_r_m(dc
, size
);
983 case CRISV10_IND_CMP
:
984 LOG_DIS("cmp size=%d op=%d %d\n", size
, dc
->src
, dc
->dst
);
985 cris_cc_mask(dc
, CC_MASK_NZVC
);
986 insn_len
+= dec10_ind_alu(dc
, CC_OP_CMP
, size
);
988 case CRISV10_IND_TEST
:
989 LOG_DIS("test size=%d op=%d %d\n", size
, dc
->src
, dc
->dst
);
991 cris_evaluate_flags(dc
);
992 cris_cc_mask(dc
, CC_MASK_NZVC
);
993 cris_alu_m_alloc_temps(t
);
994 insn_len
+= dec10_prep_move_m(dc
, 0, size
, t
[0]);
995 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~3);
996 cris_alu(dc
, CC_OP_CMP
, cpu_R
[dc
->dst
],
997 t
[0], tcg_const_tl(0), size
);
998 cris_alu_m_free_temps(t
);
1000 case CRISV10_IND_ADD
:
1001 LOG_DIS("add size=%d op=%d %d\n", size
, dc
->src
, dc
->dst
);
1002 cris_cc_mask(dc
, CC_MASK_NZVC
);
1003 insn_len
+= dec10_ind_alu(dc
, CC_OP_ADD
, size
);
1005 case CRISV10_IND_SUB
:
1006 LOG_DIS("sub size=%d op=%d %d\n", size
, dc
->src
, dc
->dst
);
1007 cris_cc_mask(dc
, CC_MASK_NZVC
);
1008 insn_len
+= dec10_ind_alu(dc
, CC_OP_SUB
, size
);
1010 case CRISV10_IND_BOUND
:
1011 LOG_DIS("bound size=%d op=%d %d\n", size
, dc
->src
, dc
->dst
);
1012 cris_cc_mask(dc
, CC_MASK_NZVC
);
1013 insn_len
+= dec10_ind_bound(dc
, size
);
1015 case CRISV10_IND_AND
:
1016 LOG_DIS("and size=%d op=%d %d\n", size
, dc
->src
, dc
->dst
);
1017 cris_cc_mask(dc
, CC_MASK_NZVC
);
1018 insn_len
+= dec10_ind_alu(dc
, CC_OP_AND
, size
);
1020 case CRISV10_IND_OR
:
1021 LOG_DIS("or size=%d op=%d %d\n", size
, dc
->src
, dc
->dst
);
1022 cris_cc_mask(dc
, CC_MASK_NZVC
);
1023 insn_len
+= dec10_ind_alu(dc
, CC_OP_OR
, size
);
1025 case CRISV10_IND_MOVX
:
1026 insn_len
= dec10_alux_m(dc
, CC_OP_MOVE
);
1028 case CRISV10_IND_ADDX
:
1029 insn_len
= dec10_alux_m(dc
, CC_OP_ADD
);
1031 case CRISV10_IND_SUBX
:
1032 insn_len
= dec10_alux_m(dc
, CC_OP_SUB
);
1034 case CRISV10_IND_CMPX
:
1035 insn_len
= dec10_alux_m(dc
, CC_OP_CMP
);
1037 case CRISV10_IND_MUL
:
1038 /* This is a reg insn coded in the mem indir space. */
1039 LOG_DIS("mul pc=%x opcode=%d\n", dc
->pc
, dc
->opcode
);
1040 cris_cc_mask(dc
, CC_MASK_NZVC
);
1041 dec10_reg_mul(dc
, size
, dc
->ir
& (1 << 10));
1043 case CRISV10_IND_BDAP_M
:
1044 insn_len
= dec10_bdap_m(dc
, size
);
1047 LOG_DIS("pc=%x var-ind.%d %d r%d r%d\n",
1048 dc
->pc
, size
, dc
->opcode
, dc
->src
, dc
->dst
);
1049 cpu_abort(dc
->env
, "Unhandled opcode");
1055 switch (dc
->opcode
) {
1056 case CRISV10_IND_MOVE_M_SPR
:
1057 insn_len
= dec10_ind_move_m_pr(dc
);
1059 case CRISV10_IND_MOVE_SPR_M
:
1060 insn_len
= dec10_ind_move_pr_m(dc
);
1062 case CRISV10_IND_JUMP_M
:
1063 if (dc
->src
== 15) {
1064 LOG_DIS("jump.%d %d r%d r%d\n", size
,
1065 dc
->opcode
, dc
->src
, dc
->dst
);
1066 imm
= ldl_code(dc
->pc
+ 2);
1067 if (dc
->mode
== CRISV10_MODE_AUTOINC
)
1070 t_gen_mov_preg_TN(dc
, dc
->dst
, tcg_const_tl(dc
->pc
+ insn_len
));
1071 tcg_gen_movi_tl(env_btarget
, imm
);
1072 cris_prepare_jmp(dc
, JMP_INDIRECT
);
1073 dc
->delayed_branch
--; /* v10 has no dslot here. */
1075 if (dc
->dst
== 14) {
1076 LOG_DIS("break %d\n", dc
->src
);
1077 cris_evaluate_flags(dc
);
1078 tcg_gen_movi_tl(env_pc
, dc
->pc
+ 2);
1079 t_gen_raise_exception(EXCP_BREAK
);
1080 dc
->is_jmp
= DISAS_UPDATE
;
1083 LOG_DIS("%d: jump.%d %d r%d r%d\n", __LINE__
, size
,
1084 dc
->opcode
, dc
->src
, dc
->dst
);
1085 t
[0] = tcg_temp_new();
1086 t_gen_mov_preg_TN(dc
, dc
->dst
, tcg_const_tl(dc
->pc
+ insn_len
));
1087 crisv10_prepare_memaddr(dc
, t
[0], size
);
1088 gen_load(dc
, env_btarget
, t
[0], 4, 0);
1089 insn_len
+= crisv10_post_memaddr(dc
, size
);
1090 cris_prepare_jmp(dc
, JMP_INDIRECT
);
1091 dc
->delayed_branch
--; /* v10 has no dslot here. */
1092 tcg_temp_free(t
[0]);
1096 case CRISV10_IND_MOVEM_R_M
:
1097 LOG_DIS("movem_r_m pc=%x opcode=%d r%d r%d\n",
1098 dc
->pc
, dc
->opcode
, dc
->dst
, dc
->src
);
1099 dec10_movem_r_m(dc
);
1101 case CRISV10_IND_MOVEM_M_R
:
1102 LOG_DIS("movem_m_r pc=%x opcode=%d\n", dc
->pc
, dc
->opcode
);
1103 dec10_movem_m_r(dc
);
1105 case CRISV10_IND_JUMP_R
:
1106 LOG_DIS("jmp pc=%x opcode=%d r%d r%d\n",
1107 dc
->pc
, dc
->opcode
, dc
->dst
, dc
->src
);
1108 tcg_gen_mov_tl(env_btarget
, cpu_R
[dc
->src
]);
1109 t_gen_mov_preg_TN(dc
, dc
->dst
, tcg_const_tl(dc
->pc
+ insn_len
));
1110 cris_prepare_jmp(dc
, JMP_INDIRECT
);
1111 dc
->delayed_branch
--; /* v10 has no dslot here. */
1113 case CRISV10_IND_MOVX
:
1114 insn_len
= dec10_alux_m(dc
, CC_OP_MOVE
);
1116 case CRISV10_IND_ADDX
:
1117 insn_len
= dec10_alux_m(dc
, CC_OP_ADD
);
1119 case CRISV10_IND_SUBX
:
1120 insn_len
= dec10_alux_m(dc
, CC_OP_SUB
);
1122 case CRISV10_IND_CMPX
:
1123 insn_len
= dec10_alux_m(dc
, CC_OP_CMP
);
1125 case CRISV10_IND_DIP
:
1126 insn_len
= dec10_dip(dc
);
1128 case CRISV10_IND_BCC_M
:
1130 cris_cc_mask(dc
, 0);
1131 imm
= ldsw_code(dc
->pc
+ 2);
1132 simm
= (int16_t)imm
;
1135 LOG_DIS("bcc_m: b%s %x\n", cc_name(dc
->cond
), dc
->pc
+ simm
);
1136 cris_prepare_cc_branch(dc
, simm
, dc
->cond
);
1140 LOG_DIS("ERROR pc=%x opcode=%d\n", dc
->pc
, dc
->opcode
);
1141 cpu_abort(dc
->env
, "Unhandled opcode");
1148 static unsigned int crisv10_decoder(DisasContext
*dc
)
1150 unsigned int insn_len
= 2;
1152 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
)))
1153 tcg_gen_debug_insn_start(dc
->pc
);
1155 /* Load a halfword onto the instruction register. */
1156 dc
->ir
= lduw_code(dc
->pc
);
1158 /* Now decode it. */
1159 dc
->opcode
= EXTRACT_FIELD(dc
->ir
, 6, 9);
1160 dc
->mode
= EXTRACT_FIELD(dc
->ir
, 10, 11);
1161 dc
->src
= EXTRACT_FIELD(dc
->ir
, 0, 3);
1162 dc
->size
= EXTRACT_FIELD(dc
->ir
, 4, 5);
1163 dc
->cond
= dc
->dst
= EXTRACT_FIELD(dc
->ir
, 12, 15);
1164 dc
->postinc
= EXTRACT_FIELD(dc
->ir
, 10, 10);
1166 dc
->clear_prefix
= 1;
1168 /* FIXME: What if this insn insn't 2 in length?? */
1169 if (dc
->src
== 15 || dc
->dst
== 15)
1170 tcg_gen_movi_tl(cpu_R
[15], dc
->pc
+ 2);
1173 case CRISV10_MODE_QIMMEDIATE
:
1174 insn_len
= dec10_quick_imm(dc
);
1176 case CRISV10_MODE_REG
:
1177 insn_len
= dec10_reg(dc
);
1179 case CRISV10_MODE_AUTOINC
:
1180 case CRISV10_MODE_INDIRECT
:
1181 insn_len
= dec10_ind(dc
);
1185 if (dc
->clear_prefix
&& dc
->tb_flags
& PFIX_FLAG
) {
1186 dc
->tb_flags
&= ~PFIX_FLAG
;
1187 tcg_gen_andi_tl(cpu_PR
[PR_CCS
], cpu_PR
[PR_CCS
], ~PFIX_FLAG
);
1188 dc
->cpustate_changed
= 1;
1191 /* CRISv10 locks out interrupts on dslots. */
1192 if (dc
->delayed_branch
== 2) {
1198 static CPUCRISState
*cpu_crisv10_init (CPUState
*env
)
1202 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
1203 cc_x
= tcg_global_mem_new(TCG_AREG0
,
1204 offsetof(CPUState
, cc_x
), "cc_x");
1205 cc_src
= tcg_global_mem_new(TCG_AREG0
,
1206 offsetof(CPUState
, cc_src
), "cc_src");
1207 cc_dest
= tcg_global_mem_new(TCG_AREG0
,
1208 offsetof(CPUState
, cc_dest
),
1210 cc_result
= tcg_global_mem_new(TCG_AREG0
,
1211 offsetof(CPUState
, cc_result
),
1213 cc_op
= tcg_global_mem_new(TCG_AREG0
,
1214 offsetof(CPUState
, cc_op
), "cc_op");
1215 cc_size
= tcg_global_mem_new(TCG_AREG0
,
1216 offsetof(CPUState
, cc_size
),
1218 cc_mask
= tcg_global_mem_new(TCG_AREG0
,
1219 offsetof(CPUState
, cc_mask
),
1222 env_pc
= tcg_global_mem_new(TCG_AREG0
,
1223 offsetof(CPUState
, pc
),
1225 env_btarget
= tcg_global_mem_new(TCG_AREG0
,
1226 offsetof(CPUState
, btarget
),
1228 env_btaken
= tcg_global_mem_new(TCG_AREG0
,
1229 offsetof(CPUState
, btaken
),
1231 for (i
= 0; i
< 16; i
++) {
1232 cpu_R
[i
] = tcg_global_mem_new(TCG_AREG0
,
1233 offsetof(CPUState
, regs
[i
]),
1236 for (i
= 0; i
< 16; i
++) {
1237 cpu_PR
[i
] = tcg_global_mem_new(TCG_AREG0
,
1238 offsetof(CPUState
, pregs
[i
]),