4 * Copyright (c) 2005-2007 CodeSourcery
5 * Written by Paul Brook
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 * 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/>.
30 //#define DEBUG_DISPATCH 1
32 /* Fake floating point. */
33 #define tcg_gen_mov_f64 tcg_gen_mov_i64
34 #define tcg_gen_qemu_ldf64 tcg_gen_qemu_ld64
35 #define tcg_gen_qemu_stf64 tcg_gen_qemu_st64
37 #define DEFO32(name, offset) static TCGv QREG_##name;
38 #define DEFO64(name, offset) static TCGv_i64 QREG_##name;
39 #define DEFF64(name, offset) static TCGv_i64 QREG_##name;
45 static TCGv_ptr cpu_env
;
47 static char cpu_reg_names
[3*8*3 + 5*4];
48 static TCGv cpu_dregs
[8];
49 static TCGv cpu_aregs
[8];
50 static TCGv_i64 cpu_fregs
[8];
51 static TCGv_i64 cpu_macc
[4];
53 #define DREG(insn, pos) cpu_dregs[((insn) >> (pos)) & 7]
54 #define AREG(insn, pos) cpu_aregs[((insn) >> (pos)) & 7]
55 #define FREG(insn, pos) cpu_fregs[((insn) >> (pos)) & 7]
56 #define MACREG(acc) cpu_macc[acc]
57 #define QREG_SP cpu_aregs[7]
59 static TCGv NULL_QREG
;
60 #define IS_NULL_QREG(t) (TCGV_EQUAL(t, NULL_QREG))
61 /* Used to distinguish stores from bad addressing modes. */
62 static TCGv store_dummy
;
64 #include "gen-icount.h"
66 void m68k_tcg_init(void)
71 #define DEFO32(name, offset) QREG_##name = tcg_global_mem_new_i32(TCG_AREG0, offsetof(CPUM68KState, offset), #name);
72 #define DEFO64(name, offset) QREG_##name = tcg_global_mem_new_i64(TCG_AREG0, offsetof(CPUM68KState, offset), #name);
73 #define DEFF64(name, offset) DEFO64(name, offset)
79 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
82 for (i
= 0; i
< 8; i
++) {
84 cpu_dregs
[i
] = tcg_global_mem_new(TCG_AREG0
,
85 offsetof(CPUM68KState
, dregs
[i
]), p
);
88 cpu_aregs
[i
] = tcg_global_mem_new(TCG_AREG0
,
89 offsetof(CPUM68KState
, aregs
[i
]), p
);
92 cpu_fregs
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
93 offsetof(CPUM68KState
, fregs
[i
]), p
);
96 for (i
= 0; i
< 4; i
++) {
97 sprintf(p
, "ACC%d", i
);
98 cpu_macc
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
99 offsetof(CPUM68KState
, macc
[i
]), p
);
103 NULL_QREG
= tcg_global_mem_new(TCG_AREG0
, -4, "NULL");
104 store_dummy
= tcg_global_mem_new(TCG_AREG0
, -8, "NULL");
110 static inline void qemu_assert(int cond
, const char *msg
)
113 fprintf (stderr
, "badness: %s\n", msg
);
118 /* internal defines */
119 typedef struct DisasContext
{
121 target_ulong insn_pc
; /* Start of the current instruction. */
127 struct TranslationBlock
*tb
;
128 int singlestep_enabled
;
134 #define DISAS_JUMP_NEXT 4
136 #if defined(CONFIG_USER_ONLY)
139 #define IS_USER(s) s->user
142 /* XXX: move that elsewhere */
143 /* ??? Fix exceptions. */
144 static void *gen_throws_exception
;
145 #define gen_last_qop NULL
153 typedef void (*disas_proc
)(DisasContext
*, uint16_t);
155 #ifdef DEBUG_DISPATCH
156 #define DISAS_INSN(name) \
157 static void real_disas_##name (DisasContext *s, uint16_t insn); \
158 static void disas_##name (DisasContext *s, uint16_t insn) { \
159 qemu_log("Dispatch " #name "\n"); \
160 real_disas_##name(s, insn); } \
161 static void real_disas_##name (DisasContext *s, uint16_t insn)
163 #define DISAS_INSN(name) \
164 static void disas_##name (DisasContext *s, uint16_t insn)
167 /* Generate a load from the specified address. Narrow values are
168 sign extended to full register width. */
169 static inline TCGv
gen_load(DisasContext
* s
, int opsize
, TCGv addr
, int sign
)
172 int index
= IS_USER(s
);
174 tmp
= tcg_temp_new_i32();
178 tcg_gen_qemu_ld8s(tmp
, addr
, index
);
180 tcg_gen_qemu_ld8u(tmp
, addr
, index
);
184 tcg_gen_qemu_ld16s(tmp
, addr
, index
);
186 tcg_gen_qemu_ld16u(tmp
, addr
, index
);
190 tcg_gen_qemu_ld32u(tmp
, addr
, index
);
193 qemu_assert(0, "bad load size");
195 gen_throws_exception
= gen_last_qop
;
199 static inline TCGv_i64
gen_load64(DisasContext
* s
, TCGv addr
)
202 int index
= IS_USER(s
);
204 tmp
= tcg_temp_new_i64();
205 tcg_gen_qemu_ldf64(tmp
, addr
, index
);
206 gen_throws_exception
= gen_last_qop
;
210 /* Generate a store. */
211 static inline void gen_store(DisasContext
*s
, int opsize
, TCGv addr
, TCGv val
)
213 int index
= IS_USER(s
);
217 tcg_gen_qemu_st8(val
, addr
, index
);
220 tcg_gen_qemu_st16(val
, addr
, index
);
224 tcg_gen_qemu_st32(val
, addr
, index
);
227 qemu_assert(0, "bad store size");
229 gen_throws_exception
= gen_last_qop
;
232 static inline void gen_store64(DisasContext
*s
, TCGv addr
, TCGv_i64 val
)
234 int index
= IS_USER(s
);
236 tcg_gen_qemu_stf64(val
, addr
, index
);
237 gen_throws_exception
= gen_last_qop
;
246 /* Generate an unsigned load if VAL is 0 a signed load if val is -1,
247 otherwise generate a store. */
248 static TCGv
gen_ldst(DisasContext
*s
, int opsize
, TCGv addr
, TCGv val
,
251 if (what
== EA_STORE
) {
252 gen_store(s
, opsize
, addr
, val
);
255 return gen_load(s
, opsize
, addr
, what
== EA_LOADS
);
259 /* Read a 32-bit immediate constant. */
260 static inline uint32_t read_im32(DisasContext
*s
)
263 im
= ((uint32_t)lduw_code(s
->pc
)) << 16;
265 im
|= lduw_code(s
->pc
);
270 /* Calculate and address index. */
271 static TCGv
gen_addr_index(uint16_t ext
, TCGv tmp
)
276 add
= (ext
& 0x8000) ? AREG(ext
, 12) : DREG(ext
, 12);
277 if ((ext
& 0x800) == 0) {
278 tcg_gen_ext16s_i32(tmp
, add
);
281 scale
= (ext
>> 9) & 3;
283 tcg_gen_shli_i32(tmp
, add
, scale
);
289 /* Handle a base + index + displacement effective addresss.
290 A NULL_QREG base means pc-relative. */
291 static TCGv
gen_lea_indexed(DisasContext
*s
, int opsize
, TCGv base
)
300 ext
= lduw_code(s
->pc
);
303 if ((ext
& 0x800) == 0 && !m68k_feature(s
->env
, M68K_FEATURE_WORD_INDEX
))
307 /* full extension word format */
308 if (!m68k_feature(s
->env
, M68K_FEATURE_EXT_FULL
))
311 if ((ext
& 0x30) > 0x10) {
312 /* base displacement */
313 if ((ext
& 0x30) == 0x20) {
314 bd
= (int16_t)lduw_code(s
->pc
);
322 tmp
= tcg_temp_new();
323 if ((ext
& 0x44) == 0) {
325 add
= gen_addr_index(ext
, tmp
);
329 if ((ext
& 0x80) == 0) {
330 /* base not suppressed */
331 if (IS_NULL_QREG(base
)) {
332 base
= tcg_const_i32(offset
+ bd
);
335 if (!IS_NULL_QREG(add
)) {
336 tcg_gen_add_i32(tmp
, add
, base
);
342 if (!IS_NULL_QREG(add
)) {
344 tcg_gen_addi_i32(tmp
, add
, bd
);
348 add
= tcg_const_i32(bd
);
350 if ((ext
& 3) != 0) {
351 /* memory indirect */
352 base
= gen_load(s
, OS_LONG
, add
, 0);
353 if ((ext
& 0x44) == 4) {
354 add
= gen_addr_index(ext
, tmp
);
355 tcg_gen_add_i32(tmp
, add
, base
);
361 /* outer displacement */
362 if ((ext
& 3) == 2) {
363 od
= (int16_t)lduw_code(s
->pc
);
372 tcg_gen_addi_i32(tmp
, add
, od
);
377 /* brief extension word format */
378 tmp
= tcg_temp_new();
379 add
= gen_addr_index(ext
, tmp
);
380 if (!IS_NULL_QREG(base
)) {
381 tcg_gen_add_i32(tmp
, add
, base
);
383 tcg_gen_addi_i32(tmp
, tmp
, (int8_t)ext
);
385 tcg_gen_addi_i32(tmp
, add
, offset
+ (int8_t)ext
);
392 /* Update the CPU env CC_OP state. */
393 static inline void gen_flush_cc_op(DisasContext
*s
)
395 if (s
->cc_op
!= CC_OP_DYNAMIC
)
396 tcg_gen_movi_i32(QREG_CC_OP
, s
->cc_op
);
399 /* Evaluate all the CC flags. */
400 static inline void gen_flush_flags(DisasContext
*s
)
402 if (s
->cc_op
== CC_OP_FLAGS
)
405 gen_helper_flush_flags(cpu_env
, QREG_CC_OP
);
406 s
->cc_op
= CC_OP_FLAGS
;
409 static void gen_logic_cc(DisasContext
*s
, TCGv val
)
411 tcg_gen_mov_i32(QREG_CC_DEST
, val
);
412 s
->cc_op
= CC_OP_LOGIC
;
415 static void gen_update_cc_add(TCGv dest
, TCGv src
)
417 tcg_gen_mov_i32(QREG_CC_DEST
, dest
);
418 tcg_gen_mov_i32(QREG_CC_SRC
, src
);
421 static inline int opsize_bytes(int opsize
)
424 case OS_BYTE
: return 1;
425 case OS_WORD
: return 2;
426 case OS_LONG
: return 4;
427 case OS_SINGLE
: return 4;
428 case OS_DOUBLE
: return 8;
430 qemu_assert(0, "bad operand size");
435 /* Assign value to a register. If the width is less than the register width
436 only the low part of the register is set. */
437 static void gen_partset_reg(int opsize
, TCGv reg
, TCGv val
)
442 tcg_gen_andi_i32(reg
, reg
, 0xffffff00);
443 tmp
= tcg_temp_new();
444 tcg_gen_ext8u_i32(tmp
, val
);
445 tcg_gen_or_i32(reg
, reg
, tmp
);
448 tcg_gen_andi_i32(reg
, reg
, 0xffff0000);
449 tmp
= tcg_temp_new();
450 tcg_gen_ext16u_i32(tmp
, val
);
451 tcg_gen_or_i32(reg
, reg
, tmp
);
455 tcg_gen_mov_i32(reg
, val
);
458 qemu_assert(0, "Bad operand size");
463 /* Sign or zero extend a value. */
464 static inline TCGv
gen_extend(TCGv val
, int opsize
, int sign
)
470 tmp
= tcg_temp_new();
472 tcg_gen_ext8s_i32(tmp
, val
);
474 tcg_gen_ext8u_i32(tmp
, val
);
477 tmp
= tcg_temp_new();
479 tcg_gen_ext16s_i32(tmp
, val
);
481 tcg_gen_ext16u_i32(tmp
, val
);
488 qemu_assert(0, "Bad operand size");
493 /* Generate code for an "effective address". Does not adjust the base
494 register for autoincrement addressing modes. */
495 static TCGv
gen_lea(DisasContext
*s
, uint16_t insn
, int opsize
)
502 switch ((insn
>> 3) & 7) {
503 case 0: /* Data register direct. */
504 case 1: /* Address register direct. */
506 case 2: /* Indirect register */
507 case 3: /* Indirect postincrement. */
508 return AREG(insn
, 0);
509 case 4: /* Indirect predecrememnt. */
511 tmp
= tcg_temp_new();
512 tcg_gen_subi_i32(tmp
, reg
, opsize_bytes(opsize
));
514 case 5: /* Indirect displacement. */
516 tmp
= tcg_temp_new();
517 ext
= lduw_code(s
->pc
);
519 tcg_gen_addi_i32(tmp
, reg
, (int16_t)ext
);
521 case 6: /* Indirect index + displacement. */
523 return gen_lea_indexed(s
, opsize
, reg
);
526 case 0: /* Absolute short. */
527 offset
= ldsw_code(s
->pc
);
529 return tcg_const_i32(offset
);
530 case 1: /* Absolute long. */
531 offset
= read_im32(s
);
532 return tcg_const_i32(offset
);
533 case 2: /* pc displacement */
535 offset
+= ldsw_code(s
->pc
);
537 return tcg_const_i32(offset
);
538 case 3: /* pc index+displacement. */
539 return gen_lea_indexed(s
, opsize
, NULL_QREG
);
540 case 4: /* Immediate. */
545 /* Should never happen. */
549 /* Helper function for gen_ea. Reuse the computed address between the
550 for read/write operands. */
551 static inline TCGv
gen_ea_once(DisasContext
*s
, uint16_t insn
, int opsize
,
552 TCGv val
, TCGv
*addrp
, ea_what what
)
556 if (addrp
&& what
== EA_STORE
) {
559 tmp
= gen_lea(s
, insn
, opsize
);
560 if (IS_NULL_QREG(tmp
))
565 return gen_ldst(s
, opsize
, tmp
, val
, what
);
568 /* Generate code to load/store a value ito/from an EA. If VAL > 0 this is
569 a write otherwise it is a read (0 == sign extend, -1 == zero extend).
570 ADDRP is non-null for readwrite operands. */
571 static TCGv
gen_ea(DisasContext
*s
, uint16_t insn
, int opsize
, TCGv val
,
572 TCGv
*addrp
, ea_what what
)
578 switch ((insn
>> 3) & 7) {
579 case 0: /* Data register direct. */
581 if (what
== EA_STORE
) {
582 gen_partset_reg(opsize
, reg
, val
);
585 return gen_extend(reg
, opsize
, what
== EA_LOADS
);
587 case 1: /* Address register direct. */
589 if (what
== EA_STORE
) {
590 tcg_gen_mov_i32(reg
, val
);
593 return gen_extend(reg
, opsize
, what
== EA_LOADS
);
595 case 2: /* Indirect register */
597 return gen_ldst(s
, opsize
, reg
, val
, what
);
598 case 3: /* Indirect postincrement. */
600 result
= gen_ldst(s
, opsize
, reg
, val
, what
);
601 /* ??? This is not exception safe. The instruction may still
602 fault after this point. */
603 if (what
== EA_STORE
|| !addrp
)
604 tcg_gen_addi_i32(reg
, reg
, opsize_bytes(opsize
));
606 case 4: /* Indirect predecrememnt. */
609 if (addrp
&& what
== EA_STORE
) {
612 tmp
= gen_lea(s
, insn
, opsize
);
613 if (IS_NULL_QREG(tmp
))
618 result
= gen_ldst(s
, opsize
, tmp
, val
, what
);
619 /* ??? This is not exception safe. The instruction may still
620 fault after this point. */
621 if (what
== EA_STORE
|| !addrp
) {
623 tcg_gen_mov_i32(reg
, tmp
);
627 case 5: /* Indirect displacement. */
628 case 6: /* Indirect index + displacement. */
629 return gen_ea_once(s
, insn
, opsize
, val
, addrp
, what
);
632 case 0: /* Absolute short. */
633 case 1: /* Absolute long. */
634 case 2: /* pc displacement */
635 case 3: /* pc index+displacement. */
636 return gen_ea_once(s
, insn
, opsize
, val
, addrp
, what
);
637 case 4: /* Immediate. */
638 /* Sign extend values for consistency. */
641 if (what
== EA_LOADS
)
642 offset
= ldsb_code(s
->pc
+ 1);
644 offset
= ldub_code(s
->pc
+ 1);
648 if (what
== EA_LOADS
)
649 offset
= ldsw_code(s
->pc
);
651 offset
= lduw_code(s
->pc
);
655 offset
= read_im32(s
);
658 qemu_assert(0, "Bad immediate operand");
660 return tcg_const_i32(offset
);
665 /* Should never happen. */
669 /* This generates a conditional branch, clobbering all temporaries. */
670 static void gen_jmpcc(DisasContext
*s
, int cond
, int l1
)
674 /* TODO: Optimize compare/branch pairs rather than always flushing
675 flag state to CC_OP_FLAGS. */
683 case 2: /* HI (!C && !Z) */
684 tmp
= tcg_temp_new();
685 tcg_gen_andi_i32(tmp
, QREG_CC_DEST
, CCF_C
| CCF_Z
);
686 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, l1
);
688 case 3: /* LS (C || Z) */
689 tmp
= tcg_temp_new();
690 tcg_gen_andi_i32(tmp
, QREG_CC_DEST
, CCF_C
| CCF_Z
);
691 tcg_gen_brcondi_i32(TCG_COND_NE
, tmp
, 0, l1
);
693 case 4: /* CC (!C) */
694 tmp
= tcg_temp_new();
695 tcg_gen_andi_i32(tmp
, QREG_CC_DEST
, CCF_C
);
696 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, l1
);
699 tmp
= tcg_temp_new();
700 tcg_gen_andi_i32(tmp
, QREG_CC_DEST
, CCF_C
);
701 tcg_gen_brcondi_i32(TCG_COND_NE
, tmp
, 0, l1
);
703 case 6: /* NE (!Z) */
704 tmp
= tcg_temp_new();
705 tcg_gen_andi_i32(tmp
, QREG_CC_DEST
, CCF_Z
);
706 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, l1
);
709 tmp
= tcg_temp_new();
710 tcg_gen_andi_i32(tmp
, QREG_CC_DEST
, CCF_Z
);
711 tcg_gen_brcondi_i32(TCG_COND_NE
, tmp
, 0, l1
);
713 case 8: /* VC (!V) */
714 tmp
= tcg_temp_new();
715 tcg_gen_andi_i32(tmp
, QREG_CC_DEST
, CCF_V
);
716 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, l1
);
719 tmp
= tcg_temp_new();
720 tcg_gen_andi_i32(tmp
, QREG_CC_DEST
, CCF_V
);
721 tcg_gen_brcondi_i32(TCG_COND_NE
, tmp
, 0, l1
);
723 case 10: /* PL (!N) */
724 tmp
= tcg_temp_new();
725 tcg_gen_andi_i32(tmp
, QREG_CC_DEST
, CCF_N
);
726 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, l1
);
728 case 11: /* MI (N) */
729 tmp
= tcg_temp_new();
730 tcg_gen_andi_i32(tmp
, QREG_CC_DEST
, CCF_N
);
731 tcg_gen_brcondi_i32(TCG_COND_NE
, tmp
, 0, l1
);
733 case 12: /* GE (!(N ^ V)) */
734 tmp
= tcg_temp_new();
735 assert(CCF_V
== (CCF_N
>> 2));
736 tcg_gen_shri_i32(tmp
, QREG_CC_DEST
, 2);
737 tcg_gen_xor_i32(tmp
, tmp
, QREG_CC_DEST
);
738 tcg_gen_andi_i32(tmp
, tmp
, CCF_V
);
739 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, l1
);
741 case 13: /* LT (N ^ V) */
742 tmp
= tcg_temp_new();
743 assert(CCF_V
== (CCF_N
>> 2));
744 tcg_gen_shri_i32(tmp
, QREG_CC_DEST
, 2);
745 tcg_gen_xor_i32(tmp
, tmp
, QREG_CC_DEST
);
746 tcg_gen_andi_i32(tmp
, tmp
, CCF_V
);
747 tcg_gen_brcondi_i32(TCG_COND_NE
, tmp
, 0, l1
);
749 case 14: /* GT (!(Z || (N ^ V))) */
750 tmp
= tcg_temp_new();
751 assert(CCF_V
== (CCF_N
>> 2));
752 tcg_gen_andi_i32(tmp
, QREG_CC_DEST
, CCF_N
);
753 tcg_gen_shri_i32(tmp
, tmp
, 2);
754 tcg_gen_xor_i32(tmp
, tmp
, QREG_CC_DEST
);
755 tcg_gen_andi_i32(tmp
, tmp
, CCF_V
| CCF_Z
);
756 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, l1
);
758 case 15: /* LE (Z || (N ^ V)) */
759 tmp
= tcg_temp_new();
760 assert(CCF_V
== (CCF_N
>> 2));
761 tcg_gen_andi_i32(tmp
, QREG_CC_DEST
, CCF_N
);
762 tcg_gen_shri_i32(tmp
, tmp
, 2);
763 tcg_gen_xor_i32(tmp
, tmp
, QREG_CC_DEST
);
764 tcg_gen_andi_i32(tmp
, tmp
, CCF_V
| CCF_Z
);
765 tcg_gen_brcondi_i32(TCG_COND_NE
, tmp
, 0, l1
);
768 /* Should ever happen. */
779 l1
= gen_new_label();
780 cond
= (insn
>> 8) & 0xf;
782 tcg_gen_andi_i32(reg
, reg
, 0xffffff00);
783 /* This is safe because we modify the reg directly, with no other values
785 gen_jmpcc(s
, cond
^ 1, l1
);
786 tcg_gen_ori_i32(reg
, reg
, 0xff);
790 /* Force a TB lookup after an instruction that changes the CPU state. */
791 static void gen_lookup_tb(DisasContext
*s
)
794 tcg_gen_movi_i32(QREG_PC
, s
->pc
);
795 s
->is_jmp
= DISAS_UPDATE
;
798 /* Generate a jump to an immediate address. */
799 static void gen_jmp_im(DisasContext
*s
, uint32_t dest
)
802 tcg_gen_movi_i32(QREG_PC
, dest
);
803 s
->is_jmp
= DISAS_JUMP
;
806 /* Generate a jump to the address in qreg DEST. */
807 static void gen_jmp(DisasContext
*s
, TCGv dest
)
810 tcg_gen_mov_i32(QREG_PC
, dest
);
811 s
->is_jmp
= DISAS_JUMP
;
814 static void gen_exception(DisasContext
*s
, uint32_t where
, int nr
)
817 gen_jmp_im(s
, where
);
818 gen_helper_raise_exception(tcg_const_i32(nr
));
821 static inline void gen_addr_fault(DisasContext
*s
)
823 gen_exception(s
, s
->insn_pc
, EXCP_ADDRESS
);
826 #define SRC_EA(result, opsize, op_sign, addrp) do { \
827 result = gen_ea(s, insn, opsize, NULL_QREG, addrp, op_sign ? EA_LOADS : EA_LOADU); \
828 if (IS_NULL_QREG(result)) { \
834 #define DEST_EA(insn, opsize, val, addrp) do { \
835 TCGv ea_result = gen_ea(s, insn, opsize, val, addrp, EA_STORE); \
836 if (IS_NULL_QREG(ea_result)) { \
842 /* Generate a jump to an immediate address. */
843 static void gen_jmp_tb(DisasContext
*s
, int n
, uint32_t dest
)
845 TranslationBlock
*tb
;
848 if (unlikely(s
->singlestep_enabled
)) {
849 gen_exception(s
, dest
, EXCP_DEBUG
);
850 } else if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
) ||
851 (s
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
)) {
853 tcg_gen_movi_i32(QREG_PC
, dest
);
854 tcg_gen_exit_tb((tcg_target_long
)tb
+ n
);
859 s
->is_jmp
= DISAS_TB_JUMP
;
862 DISAS_INSN(undef_mac
)
864 gen_exception(s
, s
->pc
- 2, EXCP_LINEA
);
867 DISAS_INSN(undef_fpu
)
869 gen_exception(s
, s
->pc
- 2, EXCP_LINEF
);
874 gen_exception(s
, s
->pc
- 2, EXCP_UNSUPPORTED
);
875 cpu_abort(cpu_single_env
, "Illegal instruction: %04x @ %08x",
886 sign
= (insn
& 0x100) != 0;
888 tmp
= tcg_temp_new();
890 tcg_gen_ext16s_i32(tmp
, reg
);
892 tcg_gen_ext16u_i32(tmp
, reg
);
893 SRC_EA(src
, OS_WORD
, sign
, NULL
);
894 tcg_gen_mul_i32(tmp
, tmp
, src
);
895 tcg_gen_mov_i32(reg
, tmp
);
896 /* Unlike m68k, coldfire always clears the overflow bit. */
897 gen_logic_cc(s
, tmp
);
907 sign
= (insn
& 0x100) != 0;
910 tcg_gen_ext16s_i32(QREG_DIV1
, reg
);
912 tcg_gen_ext16u_i32(QREG_DIV1
, reg
);
914 SRC_EA(src
, OS_WORD
, sign
, NULL
);
915 tcg_gen_mov_i32(QREG_DIV2
, src
);
917 gen_helper_divs(cpu_env
, tcg_const_i32(1));
919 gen_helper_divu(cpu_env
, tcg_const_i32(1));
922 tmp
= tcg_temp_new();
923 src
= tcg_temp_new();
924 tcg_gen_ext16u_i32(tmp
, QREG_DIV1
);
925 tcg_gen_shli_i32(src
, QREG_DIV2
, 16);
926 tcg_gen_or_i32(reg
, tmp
, src
);
927 s
->cc_op
= CC_OP_FLAGS
;
937 ext
= lduw_code(s
->pc
);
940 gen_exception(s
, s
->pc
- 4, EXCP_UNSUPPORTED
);
945 tcg_gen_mov_i32(QREG_DIV1
, num
);
946 SRC_EA(den
, OS_LONG
, 0, NULL
);
947 tcg_gen_mov_i32(QREG_DIV2
, den
);
949 gen_helper_divs(cpu_env
, tcg_const_i32(0));
951 gen_helper_divu(cpu_env
, tcg_const_i32(0));
953 if ((ext
& 7) == ((ext
>> 12) & 7)) {
955 tcg_gen_mov_i32 (reg
, QREG_DIV1
);
958 tcg_gen_mov_i32 (reg
, QREG_DIV2
);
960 s
->cc_op
= CC_OP_FLAGS
;
972 add
= (insn
& 0x4000) != 0;
974 dest
= tcg_temp_new();
976 SRC_EA(tmp
, OS_LONG
, 0, &addr
);
980 SRC_EA(src
, OS_LONG
, 0, NULL
);
983 tcg_gen_add_i32(dest
, tmp
, src
);
984 gen_helper_xflag_lt(QREG_CC_X
, dest
, src
);
985 s
->cc_op
= CC_OP_ADD
;
987 gen_helper_xflag_lt(QREG_CC_X
, tmp
, src
);
988 tcg_gen_sub_i32(dest
, tmp
, src
);
989 s
->cc_op
= CC_OP_SUB
;
991 gen_update_cc_add(dest
, src
);
993 DEST_EA(insn
, OS_LONG
, dest
, &addr
);
995 tcg_gen_mov_i32(reg
, dest
);
1000 /* Reverse the order of the bits in REG. */
1004 reg
= DREG(insn
, 0);
1005 gen_helper_bitrev(reg
, reg
);
1008 DISAS_INSN(bitop_reg
)
1018 if ((insn
& 0x38) != 0)
1022 op
= (insn
>> 6) & 3;
1023 SRC_EA(src1
, opsize
, 0, op
? &addr
: NULL
);
1024 src2
= DREG(insn
, 9);
1025 dest
= tcg_temp_new();
1028 tmp
= tcg_temp_new();
1029 if (opsize
== OS_BYTE
)
1030 tcg_gen_andi_i32(tmp
, src2
, 7);
1032 tcg_gen_andi_i32(tmp
, src2
, 31);
1034 tmp
= tcg_temp_new();
1035 tcg_gen_shr_i32(tmp
, src1
, src2
);
1036 tcg_gen_andi_i32(tmp
, tmp
, 1);
1037 tcg_gen_shli_i32(tmp
, tmp
, 2);
1038 /* Clear CCF_Z if bit set. */
1039 tcg_gen_ori_i32(QREG_CC_DEST
, QREG_CC_DEST
, CCF_Z
);
1040 tcg_gen_xor_i32(QREG_CC_DEST
, QREG_CC_DEST
, tmp
);
1042 tcg_gen_shl_i32(tmp
, tcg_const_i32(1), src2
);
1045 tcg_gen_xor_i32(dest
, src1
, tmp
);
1048 tcg_gen_not_i32(tmp
, tmp
);
1049 tcg_gen_and_i32(dest
, src1
, tmp
);
1052 tcg_gen_or_i32(dest
, src1
, tmp
);
1058 DEST_EA(insn
, opsize
, dest
, &addr
);
1064 reg
= DREG(insn
, 0);
1066 gen_helper_sats(reg
, reg
, QREG_CC_DEST
);
1067 gen_logic_cc(s
, reg
);
1070 static void gen_push(DisasContext
*s
, TCGv val
)
1074 tmp
= tcg_temp_new();
1075 tcg_gen_subi_i32(tmp
, QREG_SP
, 4);
1076 gen_store(s
, OS_LONG
, tmp
, val
);
1077 tcg_gen_mov_i32(QREG_SP
, tmp
);
1089 mask
= lduw_code(s
->pc
);
1091 tmp
= gen_lea(s
, insn
, OS_LONG
);
1092 if (IS_NULL_QREG(tmp
)) {
1096 addr
= tcg_temp_new();
1097 tcg_gen_mov_i32(addr
, tmp
);
1098 is_load
= ((insn
& 0x0400) != 0);
1099 for (i
= 0; i
< 16; i
++, mask
>>= 1) {
1106 tmp
= gen_load(s
, OS_LONG
, addr
, 0);
1107 tcg_gen_mov_i32(reg
, tmp
);
1109 gen_store(s
, OS_LONG
, addr
, reg
);
1112 tcg_gen_addi_i32(addr
, addr
, 4);
1117 DISAS_INSN(bitop_im
)
1127 if ((insn
& 0x38) != 0)
1131 op
= (insn
>> 6) & 3;
1133 bitnum
= lduw_code(s
->pc
);
1135 if (bitnum
& 0xff00) {
1136 disas_undef(s
, insn
);
1140 SRC_EA(src1
, opsize
, 0, op
? &addr
: NULL
);
1143 if (opsize
== OS_BYTE
)
1149 tmp
= tcg_temp_new();
1150 assert (CCF_Z
== (1 << 2));
1152 tcg_gen_shri_i32(tmp
, src1
, bitnum
- 2);
1153 else if (bitnum
< 2)
1154 tcg_gen_shli_i32(tmp
, src1
, 2 - bitnum
);
1156 tcg_gen_mov_i32(tmp
, src1
);
1157 tcg_gen_andi_i32(tmp
, tmp
, CCF_Z
);
1158 /* Clear CCF_Z if bit set. */
1159 tcg_gen_ori_i32(QREG_CC_DEST
, QREG_CC_DEST
, CCF_Z
);
1160 tcg_gen_xor_i32(QREG_CC_DEST
, QREG_CC_DEST
, tmp
);
1164 tcg_gen_xori_i32(tmp
, src1
, mask
);
1167 tcg_gen_andi_i32(tmp
, src1
, ~mask
);
1170 tcg_gen_ori_i32(tmp
, src1
, mask
);
1175 DEST_EA(insn
, opsize
, tmp
, &addr
);
1179 DISAS_INSN(arith_im
)
1187 op
= (insn
>> 9) & 7;
1188 SRC_EA(src1
, OS_LONG
, 0, (op
== 6) ? NULL
: &addr
);
1190 dest
= tcg_temp_new();
1193 tcg_gen_ori_i32(dest
, src1
, im
);
1194 gen_logic_cc(s
, dest
);
1197 tcg_gen_andi_i32(dest
, src1
, im
);
1198 gen_logic_cc(s
, dest
);
1201 tcg_gen_mov_i32(dest
, src1
);
1202 gen_helper_xflag_lt(QREG_CC_X
, dest
, tcg_const_i32(im
));
1203 tcg_gen_subi_i32(dest
, dest
, im
);
1204 gen_update_cc_add(dest
, tcg_const_i32(im
));
1205 s
->cc_op
= CC_OP_SUB
;
1208 tcg_gen_mov_i32(dest
, src1
);
1209 tcg_gen_addi_i32(dest
, dest
, im
);
1210 gen_update_cc_add(dest
, tcg_const_i32(im
));
1211 gen_helper_xflag_lt(QREG_CC_X
, dest
, tcg_const_i32(im
));
1212 s
->cc_op
= CC_OP_ADD
;
1215 tcg_gen_xori_i32(dest
, src1
, im
);
1216 gen_logic_cc(s
, dest
);
1219 tcg_gen_mov_i32(dest
, src1
);
1220 tcg_gen_subi_i32(dest
, dest
, im
);
1221 gen_update_cc_add(dest
, tcg_const_i32(im
));
1222 s
->cc_op
= CC_OP_SUB
;
1228 DEST_EA(insn
, OS_LONG
, dest
, &addr
);
1236 reg
= DREG(insn
, 0);
1237 tcg_gen_bswap32_i32(reg
, reg
);
1247 switch (insn
>> 12) {
1248 case 1: /* move.b */
1251 case 2: /* move.l */
1254 case 3: /* move.w */
1260 SRC_EA(src
, opsize
, 1, NULL
);
1261 op
= (insn
>> 6) & 7;
1264 /* The value will already have been sign extended. */
1265 dest
= AREG(insn
, 9);
1266 tcg_gen_mov_i32(dest
, src
);
1270 dest_ea
= ((insn
>> 9) & 7) | (op
<< 3);
1271 DEST_EA(dest_ea
, opsize
, src
, NULL
);
1272 /* This will be correct because loads sign extend. */
1273 gen_logic_cc(s
, src
);
1282 reg
= DREG(insn
, 0);
1283 gen_helper_subx_cc(reg
, cpu_env
, tcg_const_i32(0), reg
);
1291 reg
= AREG(insn
, 9);
1292 tmp
= gen_lea(s
, insn
, OS_LONG
);
1293 if (IS_NULL_QREG(tmp
)) {
1297 tcg_gen_mov_i32(reg
, tmp
);
1304 switch ((insn
>> 6) & 3) {
1317 DEST_EA(insn
, opsize
, tcg_const_i32(0), NULL
);
1318 gen_logic_cc(s
, tcg_const_i32(0));
1321 static TCGv
gen_get_ccr(DisasContext
*s
)
1326 dest
= tcg_temp_new();
1327 tcg_gen_shli_i32(dest
, QREG_CC_X
, 4);
1328 tcg_gen_or_i32(dest
, dest
, QREG_CC_DEST
);
1332 DISAS_INSN(move_from_ccr
)
1337 ccr
= gen_get_ccr(s
);
1338 reg
= DREG(insn
, 0);
1339 gen_partset_reg(OS_WORD
, reg
, ccr
);
1347 reg
= DREG(insn
, 0);
1348 src1
= tcg_temp_new();
1349 tcg_gen_mov_i32(src1
, reg
);
1350 tcg_gen_neg_i32(reg
, src1
);
1351 s
->cc_op
= CC_OP_SUB
;
1352 gen_update_cc_add(reg
, src1
);
1353 gen_helper_xflag_lt(QREG_CC_X
, tcg_const_i32(0), src1
);
1354 s
->cc_op
= CC_OP_SUB
;
1357 static void gen_set_sr_im(DisasContext
*s
, uint16_t val
, int ccr_only
)
1359 tcg_gen_movi_i32(QREG_CC_DEST
, val
& 0xf);
1360 tcg_gen_movi_i32(QREG_CC_X
, (val
& 0x10) >> 4);
1362 gen_helper_set_sr(cpu_env
, tcg_const_i32(val
& 0xff00));
1366 static void gen_set_sr(DisasContext
*s
, uint16_t insn
, int ccr_only
)
1371 s
->cc_op
= CC_OP_FLAGS
;
1372 if ((insn
& 0x38) == 0)
1374 tmp
= tcg_temp_new();
1375 reg
= DREG(insn
, 0);
1376 tcg_gen_andi_i32(QREG_CC_DEST
, reg
, 0xf);
1377 tcg_gen_shri_i32(tmp
, reg
, 4);
1378 tcg_gen_andi_i32(QREG_CC_X
, tmp
, 1);
1380 gen_helper_set_sr(cpu_env
, reg
);
1383 else if ((insn
& 0x3f) == 0x3c)
1386 val
= lduw_code(s
->pc
);
1388 gen_set_sr_im(s
, val
, ccr_only
);
1391 disas_undef(s
, insn
);
1394 DISAS_INSN(move_to_ccr
)
1396 gen_set_sr(s
, insn
, 1);
1403 reg
= DREG(insn
, 0);
1404 tcg_gen_not_i32(reg
, reg
);
1405 gen_logic_cc(s
, reg
);
1414 src1
= tcg_temp_new();
1415 src2
= tcg_temp_new();
1416 reg
= DREG(insn
, 0);
1417 tcg_gen_shli_i32(src1
, reg
, 16);
1418 tcg_gen_shri_i32(src2
, reg
, 16);
1419 tcg_gen_or_i32(reg
, src1
, src2
);
1420 gen_logic_cc(s
, reg
);
1427 tmp
= gen_lea(s
, insn
, OS_LONG
);
1428 if (IS_NULL_QREG(tmp
)) {
1441 reg
= DREG(insn
, 0);
1442 op
= (insn
>> 6) & 7;
1443 tmp
= tcg_temp_new();
1445 tcg_gen_ext16s_i32(tmp
, reg
);
1447 tcg_gen_ext8s_i32(tmp
, reg
);
1449 gen_partset_reg(OS_WORD
, reg
, tmp
);
1451 tcg_gen_mov_i32(reg
, tmp
);
1452 gen_logic_cc(s
, tmp
);
1460 switch ((insn
>> 6) & 3) {
1473 SRC_EA(tmp
, opsize
, 1, NULL
);
1474 gen_logic_cc(s
, tmp
);
1479 /* Implemented as a NOP. */
1484 gen_exception(s
, s
->pc
- 2, EXCP_ILLEGAL
);
1487 /* ??? This should be atomic. */
1494 dest
= tcg_temp_new();
1495 SRC_EA(src1
, OS_BYTE
, 1, &addr
);
1496 gen_logic_cc(s
, src1
);
1497 tcg_gen_ori_i32(dest
, src1
, 0x80);
1498 DEST_EA(insn
, OS_BYTE
, dest
, &addr
);
1508 /* The upper 32 bits of the product are discarded, so
1509 muls.l and mulu.l are functionally equivalent. */
1510 ext
= lduw_code(s
->pc
);
1513 gen_exception(s
, s
->pc
- 4, EXCP_UNSUPPORTED
);
1516 reg
= DREG(ext
, 12);
1517 SRC_EA(src1
, OS_LONG
, 0, NULL
);
1518 dest
= tcg_temp_new();
1519 tcg_gen_mul_i32(dest
, src1
, reg
);
1520 tcg_gen_mov_i32(reg
, dest
);
1521 /* Unlike m68k, coldfire always clears the overflow bit. */
1522 gen_logic_cc(s
, dest
);
1531 offset
= ldsw_code(s
->pc
);
1533 reg
= AREG(insn
, 0);
1534 tmp
= tcg_temp_new();
1535 tcg_gen_subi_i32(tmp
, QREG_SP
, 4);
1536 gen_store(s
, OS_LONG
, tmp
, reg
);
1537 if ((insn
& 7) != 7)
1538 tcg_gen_mov_i32(reg
, tmp
);
1539 tcg_gen_addi_i32(QREG_SP
, tmp
, offset
);
1548 src
= tcg_temp_new();
1549 reg
= AREG(insn
, 0);
1550 tcg_gen_mov_i32(src
, reg
);
1551 tmp
= gen_load(s
, OS_LONG
, src
, 0);
1552 tcg_gen_mov_i32(reg
, tmp
);
1553 tcg_gen_addi_i32(QREG_SP
, src
, 4);
1564 tmp
= gen_load(s
, OS_LONG
, QREG_SP
, 0);
1565 tcg_gen_addi_i32(QREG_SP
, QREG_SP
, 4);
1573 /* Load the target address first to ensure correct exception
1575 tmp
= gen_lea(s
, insn
, OS_LONG
);
1576 if (IS_NULL_QREG(tmp
)) {
1580 if ((insn
& 0x40) == 0) {
1582 gen_push(s
, tcg_const_i32(s
->pc
));
1595 SRC_EA(src1
, OS_LONG
, 0, &addr
);
1596 val
= (insn
>> 9) & 7;
1599 dest
= tcg_temp_new();
1600 tcg_gen_mov_i32(dest
, src1
);
1601 if ((insn
& 0x38) == 0x08) {
1602 /* Don't update condition codes if the destination is an
1603 address register. */
1604 if (insn
& 0x0100) {
1605 tcg_gen_subi_i32(dest
, dest
, val
);
1607 tcg_gen_addi_i32(dest
, dest
, val
);
1610 src2
= tcg_const_i32(val
);
1611 if (insn
& 0x0100) {
1612 gen_helper_xflag_lt(QREG_CC_X
, dest
, src2
);
1613 tcg_gen_subi_i32(dest
, dest
, val
);
1614 s
->cc_op
= CC_OP_SUB
;
1616 tcg_gen_addi_i32(dest
, dest
, val
);
1617 gen_helper_xflag_lt(QREG_CC_X
, dest
, src2
);
1618 s
->cc_op
= CC_OP_ADD
;
1620 gen_update_cc_add(dest
, src2
);
1622 DEST_EA(insn
, OS_LONG
, dest
, &addr
);
1628 case 2: /* One extension word. */
1631 case 3: /* Two extension words. */
1634 case 4: /* No extension words. */
1637 disas_undef(s
, insn
);
1649 op
= (insn
>> 8) & 0xf;
1650 offset
= (int8_t)insn
;
1652 offset
= ldsw_code(s
->pc
);
1654 } else if (offset
== -1) {
1655 offset
= read_im32(s
);
1659 gen_push(s
, tcg_const_i32(s
->pc
));
1664 l1
= gen_new_label();
1665 gen_jmpcc(s
, ((insn
>> 8) & 0xf) ^ 1, l1
);
1666 gen_jmp_tb(s
, 1, base
+ offset
);
1668 gen_jmp_tb(s
, 0, s
->pc
);
1670 /* Unconditional branch. */
1671 gen_jmp_tb(s
, 0, base
+ offset
);
1680 tcg_gen_movi_i32(DREG(insn
, 9), val
);
1681 gen_logic_cc(s
, tcg_const_i32(val
));
1694 SRC_EA(src
, opsize
, (insn
& 0x80) == 0, NULL
);
1695 reg
= DREG(insn
, 9);
1696 tcg_gen_mov_i32(reg
, src
);
1697 gen_logic_cc(s
, src
);
1707 reg
= DREG(insn
, 9);
1708 dest
= tcg_temp_new();
1710 SRC_EA(src
, OS_LONG
, 0, &addr
);
1711 tcg_gen_or_i32(dest
, src
, reg
);
1712 DEST_EA(insn
, OS_LONG
, dest
, &addr
);
1714 SRC_EA(src
, OS_LONG
, 0, NULL
);
1715 tcg_gen_or_i32(dest
, src
, reg
);
1716 tcg_gen_mov_i32(reg
, dest
);
1718 gen_logic_cc(s
, dest
);
1726 SRC_EA(src
, OS_LONG
, 0, NULL
);
1727 reg
= AREG(insn
, 9);
1728 tcg_gen_sub_i32(reg
, reg
, src
);
1737 reg
= DREG(insn
, 9);
1738 src
= DREG(insn
, 0);
1739 gen_helper_subx_cc(reg
, cpu_env
, reg
, src
);
1747 val
= (insn
>> 9) & 7;
1750 src
= tcg_const_i32(val
);
1751 gen_logic_cc(s
, src
);
1752 DEST_EA(insn
, OS_LONG
, src
, NULL
);
1763 op
= (insn
>> 6) & 3;
1767 s
->cc_op
= CC_OP_CMPB
;
1771 s
->cc_op
= CC_OP_CMPW
;
1775 s
->cc_op
= CC_OP_SUB
;
1780 SRC_EA(src
, opsize
, 1, NULL
);
1781 reg
= DREG(insn
, 9);
1782 dest
= tcg_temp_new();
1783 tcg_gen_sub_i32(dest
, reg
, src
);
1784 gen_update_cc_add(dest
, src
);
1799 SRC_EA(src
, opsize
, 1, NULL
);
1800 reg
= AREG(insn
, 9);
1801 dest
= tcg_temp_new();
1802 tcg_gen_sub_i32(dest
, reg
, src
);
1803 gen_update_cc_add(dest
, src
);
1804 s
->cc_op
= CC_OP_SUB
;
1814 SRC_EA(src
, OS_LONG
, 0, &addr
);
1815 reg
= DREG(insn
, 9);
1816 dest
= tcg_temp_new();
1817 tcg_gen_xor_i32(dest
, src
, reg
);
1818 gen_logic_cc(s
, dest
);
1819 DEST_EA(insn
, OS_LONG
, dest
, &addr
);
1829 reg
= DREG(insn
, 9);
1830 dest
= tcg_temp_new();
1832 SRC_EA(src
, OS_LONG
, 0, &addr
);
1833 tcg_gen_and_i32(dest
, src
, reg
);
1834 DEST_EA(insn
, OS_LONG
, dest
, &addr
);
1836 SRC_EA(src
, OS_LONG
, 0, NULL
);
1837 tcg_gen_and_i32(dest
, src
, reg
);
1838 tcg_gen_mov_i32(reg
, dest
);
1840 gen_logic_cc(s
, dest
);
1848 SRC_EA(src
, OS_LONG
, 0, NULL
);
1849 reg
= AREG(insn
, 9);
1850 tcg_gen_add_i32(reg
, reg
, src
);
1859 reg
= DREG(insn
, 9);
1860 src
= DREG(insn
, 0);
1861 gen_helper_addx_cc(reg
, cpu_env
, reg
, src
);
1862 s
->cc_op
= CC_OP_FLAGS
;
1865 /* TODO: This could be implemented without helper functions. */
1866 DISAS_INSN(shift_im
)
1872 reg
= DREG(insn
, 0);
1873 tmp
= (insn
>> 9) & 7;
1876 shift
= tcg_const_i32(tmp
);
1877 /* No need to flush flags becuse we know we will set C flag. */
1879 gen_helper_shl_cc(reg
, cpu_env
, reg
, shift
);
1882 gen_helper_shr_cc(reg
, cpu_env
, reg
, shift
);
1884 gen_helper_sar_cc(reg
, cpu_env
, reg
, shift
);
1887 s
->cc_op
= CC_OP_SHIFT
;
1890 DISAS_INSN(shift_reg
)
1895 reg
= DREG(insn
, 0);
1896 shift
= DREG(insn
, 9);
1897 /* Shift by zero leaves C flag unmodified. */
1900 gen_helper_shl_cc(reg
, cpu_env
, reg
, shift
);
1903 gen_helper_shr_cc(reg
, cpu_env
, reg
, shift
);
1905 gen_helper_sar_cc(reg
, cpu_env
, reg
, shift
);
1908 s
->cc_op
= CC_OP_SHIFT
;
1914 reg
= DREG(insn
, 0);
1915 gen_logic_cc(s
, reg
);
1916 gen_helper_ff1(reg
, reg
);
1919 static TCGv
gen_get_sr(DisasContext
*s
)
1924 ccr
= gen_get_ccr(s
);
1925 sr
= tcg_temp_new();
1926 tcg_gen_andi_i32(sr
, QREG_SR
, 0xffe0);
1927 tcg_gen_or_i32(sr
, sr
, ccr
);
1937 ext
= lduw_code(s
->pc
);
1939 if (ext
!= 0x46FC) {
1940 gen_exception(s
, addr
, EXCP_UNSUPPORTED
);
1943 ext
= lduw_code(s
->pc
);
1945 if (IS_USER(s
) || (ext
& SR_S
) == 0) {
1946 gen_exception(s
, addr
, EXCP_PRIVILEGE
);
1949 gen_push(s
, gen_get_sr(s
));
1950 gen_set_sr_im(s
, ext
, 0);
1953 DISAS_INSN(move_from_sr
)
1959 gen_exception(s
, s
->pc
- 2, EXCP_PRIVILEGE
);
1963 reg
= DREG(insn
, 0);
1964 gen_partset_reg(OS_WORD
, reg
, sr
);
1967 DISAS_INSN(move_to_sr
)
1970 gen_exception(s
, s
->pc
- 2, EXCP_PRIVILEGE
);
1973 gen_set_sr(s
, insn
, 0);
1977 DISAS_INSN(move_from_usp
)
1980 gen_exception(s
, s
->pc
- 2, EXCP_PRIVILEGE
);
1983 /* TODO: Implement USP. */
1984 gen_exception(s
, s
->pc
- 2, EXCP_ILLEGAL
);
1987 DISAS_INSN(move_to_usp
)
1990 gen_exception(s
, s
->pc
- 2, EXCP_PRIVILEGE
);
1993 /* TODO: Implement USP. */
1994 gen_exception(s
, s
->pc
- 2, EXCP_ILLEGAL
);
1999 gen_exception(s
, s
->pc
, EXCP_HALT_INSN
);
2007 gen_exception(s
, s
->pc
- 2, EXCP_PRIVILEGE
);
2011 ext
= lduw_code(s
->pc
);
2014 gen_set_sr_im(s
, ext
, 0);
2015 tcg_gen_movi_i32(QREG_HALTED
, 1);
2016 gen_exception(s
, s
->pc
, EXCP_HLT
);
2022 gen_exception(s
, s
->pc
- 2, EXCP_PRIVILEGE
);
2025 gen_exception(s
, s
->pc
- 2, EXCP_RTE
);
2034 gen_exception(s
, s
->pc
- 2, EXCP_PRIVILEGE
);
2038 ext
= lduw_code(s
->pc
);
2042 reg
= AREG(ext
, 12);
2044 reg
= DREG(ext
, 12);
2046 gen_helper_movec(cpu_env
, tcg_const_i32(ext
& 0xfff), reg
);
2053 gen_exception(s
, s
->pc
- 2, EXCP_PRIVILEGE
);
2056 /* ICache fetch. Implement as no-op. */
2062 gen_exception(s
, s
->pc
- 2, EXCP_PRIVILEGE
);
2065 /* Cache push/invalidate. Implement as no-op. */
2070 gen_exception(s
, s
->pc
- 2, EXCP_PRIVILEGE
);
2076 gen_exception(s
, s
->pc
- 2, EXCP_PRIVILEGE
);
2079 /* TODO: Implement wdebug. */
2080 qemu_assert(0, "WDEBUG not implemented");
2085 gen_exception(s
, s
->pc
- 2, EXCP_TRAP0
+ (insn
& 0xf));
2088 /* ??? FP exceptions are not implemented. Most exceptions are deferred until
2089 immediately before the next FP instruction is executed. */
2103 ext
= lduw_code(s
->pc
);
2105 opmode
= ext
& 0x7f;
2106 switch ((ext
>> 13) & 7) {
2111 case 3: /* fmove out */
2113 tmp32
= tcg_temp_new_i32();
2115 /* ??? TODO: Proper behavior on overflow. */
2116 switch ((ext
>> 10) & 7) {
2119 gen_helper_f64_to_i32(tmp32
, cpu_env
, src
);
2123 gen_helper_f64_to_f32(tmp32
, cpu_env
, src
);
2127 gen_helper_f64_to_i32(tmp32
, cpu_env
, src
);
2129 case 5: /* OS_DOUBLE */
2130 tcg_gen_mov_i32(tmp32
, AREG(insn
, 0));
2131 switch ((insn
>> 3) & 7) {
2136 tcg_gen_addi_i32(tmp32
, tmp32
, -8);
2139 offset
= ldsw_code(s
->pc
);
2141 tcg_gen_addi_i32(tmp32
, tmp32
, offset
);
2146 gen_store64(s
, tmp32
, src
);
2147 switch ((insn
>> 3) & 7) {
2149 tcg_gen_addi_i32(tmp32
, tmp32
, 8);
2150 tcg_gen_mov_i32(AREG(insn
, 0), tmp32
);
2153 tcg_gen_mov_i32(AREG(insn
, 0), tmp32
);
2156 tcg_temp_free_i32(tmp32
);
2160 gen_helper_f64_to_i32(tmp32
, cpu_env
, src
);
2165 DEST_EA(insn
, opsize
, tmp32
, NULL
);
2166 tcg_temp_free_i32(tmp32
);
2168 case 4: /* fmove to control register. */
2169 switch ((ext
>> 10) & 7) {
2171 /* Not implemented. Ignore writes. */
2176 cpu_abort(NULL
, "Unimplemented: fmove to control %d",
2180 case 5: /* fmove from control register. */
2181 switch ((ext
>> 10) & 7) {
2183 /* Not implemented. Always return zero. */
2184 tmp32
= tcg_const_i32(0);
2189 cpu_abort(NULL
, "Unimplemented: fmove from control %d",
2193 DEST_EA(insn
, OS_LONG
, tmp32
, NULL
);
2195 case 6: /* fmovem */
2201 if ((ext
& 0x1f00) != 0x1000 || (ext
& 0xff) == 0)
2203 tmp32
= gen_lea(s
, insn
, OS_LONG
);
2204 if (IS_NULL_QREG(tmp32
)) {
2208 addr
= tcg_temp_new_i32();
2209 tcg_gen_mov_i32(addr
, tmp32
);
2211 for (i
= 0; i
< 8; i
++) {
2215 if (ext
& (1 << 13)) {
2217 tcg_gen_qemu_stf64(dest
, addr
, IS_USER(s
));
2220 tcg_gen_qemu_ldf64(dest
, addr
, IS_USER(s
));
2222 if (ext
& (mask
- 1))
2223 tcg_gen_addi_i32(addr
, addr
, 8);
2227 tcg_temp_free_i32(addr
);
2231 if (ext
& (1 << 14)) {
2232 /* Source effective address. */
2233 switch ((ext
>> 10) & 7) {
2234 case 0: opsize
= OS_LONG
; break;
2235 case 1: opsize
= OS_SINGLE
; break;
2236 case 4: opsize
= OS_WORD
; break;
2237 case 5: opsize
= OS_DOUBLE
; break;
2238 case 6: opsize
= OS_BYTE
; break;
2242 if (opsize
== OS_DOUBLE
) {
2243 tmp32
= tcg_temp_new_i32();
2244 tcg_gen_mov_i32(tmp32
, AREG(insn
, 0));
2245 switch ((insn
>> 3) & 7) {
2250 tcg_gen_addi_i32(tmp32
, tmp32
, -8);
2253 offset
= ldsw_code(s
->pc
);
2255 tcg_gen_addi_i32(tmp32
, tmp32
, offset
);
2258 offset
= ldsw_code(s
->pc
);
2259 offset
+= s
->pc
- 2;
2261 tcg_gen_addi_i32(tmp32
, tmp32
, offset
);
2266 src
= gen_load64(s
, tmp32
);
2267 switch ((insn
>> 3) & 7) {
2269 tcg_gen_addi_i32(tmp32
, tmp32
, 8);
2270 tcg_gen_mov_i32(AREG(insn
, 0), tmp32
);
2273 tcg_gen_mov_i32(AREG(insn
, 0), tmp32
);
2276 tcg_temp_free_i32(tmp32
);
2278 SRC_EA(tmp32
, opsize
, 1, NULL
);
2279 src
= tcg_temp_new_i64();
2284 gen_helper_i32_to_f64(src
, cpu_env
, tmp32
);
2287 gen_helper_f32_to_f64(src
, cpu_env
, tmp32
);
2292 /* Source register. */
2293 src
= FREG(ext
, 10);
2295 dest
= FREG(ext
, 7);
2296 res
= tcg_temp_new_i64();
2298 tcg_gen_mov_f64(res
, dest
);
2302 case 0: case 0x40: case 0x44: /* fmove */
2303 tcg_gen_mov_f64(res
, src
);
2306 gen_helper_iround_f64(res
, cpu_env
, src
);
2309 case 3: /* fintrz */
2310 gen_helper_itrunc_f64(res
, cpu_env
, src
);
2313 case 4: case 0x41: case 0x45: /* fsqrt */
2314 gen_helper_sqrt_f64(res
, cpu_env
, src
);
2316 case 0x18: case 0x58: case 0x5c: /* fabs */
2317 gen_helper_abs_f64(res
, src
);
2319 case 0x1a: case 0x5a: case 0x5e: /* fneg */
2320 gen_helper_chs_f64(res
, src
);
2322 case 0x20: case 0x60: case 0x64: /* fdiv */
2323 gen_helper_div_f64(res
, cpu_env
, res
, src
);
2325 case 0x22: case 0x62: case 0x66: /* fadd */
2326 gen_helper_add_f64(res
, cpu_env
, res
, src
);
2328 case 0x23: case 0x63: case 0x67: /* fmul */
2329 gen_helper_mul_f64(res
, cpu_env
, res
, src
);
2331 case 0x28: case 0x68: case 0x6c: /* fsub */
2332 gen_helper_sub_f64(res
, cpu_env
, res
, src
);
2334 case 0x38: /* fcmp */
2335 gen_helper_sub_cmp_f64(res
, cpu_env
, res
, src
);
2339 case 0x3a: /* ftst */
2340 tcg_gen_mov_f64(res
, src
);
2347 if (ext
& (1 << 14)) {
2348 tcg_temp_free_i64(src
);
2351 if (opmode
& 0x40) {
2352 if ((opmode
& 0x4) != 0)
2354 } else if ((s
->fpcr
& M68K_FPCR_PREC
) == 0) {
2359 TCGv tmp
= tcg_temp_new_i32();
2360 gen_helper_f64_to_f32(tmp
, cpu_env
, res
);
2361 gen_helper_f32_to_f64(res
, cpu_env
, tmp
);
2362 tcg_temp_free_i32(tmp
);
2364 tcg_gen_mov_f64(QREG_FP_RESULT
, res
);
2366 tcg_gen_mov_f64(dest
, res
);
2368 tcg_temp_free_i64(res
);
2371 /* FIXME: Is this right for offset addressing modes? */
2373 disas_undef_fpu(s
, insn
);
2384 offset
= ldsw_code(s
->pc
);
2386 if (insn
& (1 << 6)) {
2387 offset
= (offset
<< 16) | lduw_code(s
->pc
);
2391 l1
= gen_new_label();
2392 /* TODO: Raise BSUN exception. */
2393 flag
= tcg_temp_new();
2394 gen_helper_compare_f64(flag
, cpu_env
, QREG_FP_RESULT
);
2395 /* Jump to l1 if condition is true. */
2396 switch (insn
& 0xf) {
2399 case 1: /* eq (=0) */
2400 tcg_gen_brcond_i32(TCG_COND_EQ
, flag
, tcg_const_i32(0), l1
);
2402 case 2: /* ogt (=1) */
2403 tcg_gen_brcond_i32(TCG_COND_EQ
, flag
, tcg_const_i32(1), l1
);
2405 case 3: /* oge (=0 or =1) */
2406 tcg_gen_brcond_i32(TCG_COND_LEU
, flag
, tcg_const_i32(1), l1
);
2408 case 4: /* olt (=-1) */
2409 tcg_gen_brcond_i32(TCG_COND_LT
, flag
, tcg_const_i32(0), l1
);
2411 case 5: /* ole (=-1 or =0) */
2412 tcg_gen_brcond_i32(TCG_COND_LE
, flag
, tcg_const_i32(0), l1
);
2414 case 6: /* ogl (=-1 or =1) */
2415 tcg_gen_andi_i32(flag
, flag
, 1);
2416 tcg_gen_brcond_i32(TCG_COND_NE
, flag
, tcg_const_i32(0), l1
);
2418 case 7: /* or (=2) */
2419 tcg_gen_brcond_i32(TCG_COND_EQ
, flag
, tcg_const_i32(2), l1
);
2421 case 8: /* un (<2) */
2422 tcg_gen_brcond_i32(TCG_COND_LT
, flag
, tcg_const_i32(2), l1
);
2424 case 9: /* ueq (=0 or =2) */
2425 tcg_gen_andi_i32(flag
, flag
, 1);
2426 tcg_gen_brcond_i32(TCG_COND_EQ
, flag
, tcg_const_i32(0), l1
);
2428 case 10: /* ugt (>0) */
2429 tcg_gen_brcond_i32(TCG_COND_GT
, flag
, tcg_const_i32(0), l1
);
2431 case 11: /* uge (>=0) */
2432 tcg_gen_brcond_i32(TCG_COND_GE
, flag
, tcg_const_i32(0), l1
);
2434 case 12: /* ult (=-1 or =2) */
2435 tcg_gen_brcond_i32(TCG_COND_GEU
, flag
, tcg_const_i32(2), l1
);
2437 case 13: /* ule (!=1) */
2438 tcg_gen_brcond_i32(TCG_COND_NE
, flag
, tcg_const_i32(1), l1
);
2440 case 14: /* ne (!=0) */
2441 tcg_gen_brcond_i32(TCG_COND_NE
, flag
, tcg_const_i32(0), l1
);
2447 gen_jmp_tb(s
, 0, s
->pc
);
2449 gen_jmp_tb(s
, 1, addr
+ offset
);
2452 DISAS_INSN(frestore
)
2454 /* TODO: Implement frestore. */
2455 qemu_assert(0, "FRESTORE not implemented");
2460 /* TODO: Implement fsave. */
2461 qemu_assert(0, "FSAVE not implemented");
2464 static inline TCGv
gen_mac_extract_word(DisasContext
*s
, TCGv val
, int upper
)
2466 TCGv tmp
= tcg_temp_new();
2467 if (s
->env
->macsr
& MACSR_FI
) {
2469 tcg_gen_andi_i32(tmp
, val
, 0xffff0000);
2471 tcg_gen_shli_i32(tmp
, val
, 16);
2472 } else if (s
->env
->macsr
& MACSR_SU
) {
2474 tcg_gen_sari_i32(tmp
, val
, 16);
2476 tcg_gen_ext16s_i32(tmp
, val
);
2479 tcg_gen_shri_i32(tmp
, val
, 16);
2481 tcg_gen_ext16u_i32(tmp
, val
);
2486 static void gen_mac_clear_flags(void)
2488 tcg_gen_andi_i32(QREG_MACSR
, QREG_MACSR
,
2489 ~(MACSR_V
| MACSR_Z
| MACSR_N
| MACSR_EV
));
2505 s
->mactmp
= tcg_temp_new_i64();
2509 ext
= lduw_code(s
->pc
);
2512 acc
= ((insn
>> 7) & 1) | ((ext
>> 3) & 2);
2513 dual
= ((insn
& 0x30) != 0 && (ext
& 3) != 0);
2514 if (dual
&& !m68k_feature(s
->env
, M68K_FEATURE_CF_EMAC_B
)) {
2515 disas_undef(s
, insn
);
2519 /* MAC with load. */
2520 tmp
= gen_lea(s
, insn
, OS_LONG
);
2521 addr
= tcg_temp_new();
2522 tcg_gen_and_i32(addr
, tmp
, QREG_MAC_MASK
);
2523 /* Load the value now to ensure correct exception behavior.
2524 Perform writeback after reading the MAC inputs. */
2525 loadval
= gen_load(s
, OS_LONG
, addr
, 0);
2528 rx
= (ext
& 0x8000) ? AREG(ext
, 12) : DREG(insn
, 12);
2529 ry
= (ext
& 8) ? AREG(ext
, 0) : DREG(ext
, 0);
2531 loadval
= addr
= NULL_QREG
;
2532 rx
= (insn
& 0x40) ? AREG(insn
, 9) : DREG(insn
, 9);
2533 ry
= (insn
& 8) ? AREG(insn
, 0) : DREG(insn
, 0);
2536 gen_mac_clear_flags();
2539 /* Disabled because conditional branches clobber temporary vars. */
2540 if ((s
->env
->macsr
& MACSR_OMC
) != 0 && !dual
) {
2541 /* Skip the multiply if we know we will ignore it. */
2542 l1
= gen_new_label();
2543 tmp
= tcg_temp_new();
2544 tcg_gen_andi_i32(tmp
, QREG_MACSR
, 1 << (acc
+ 8));
2545 gen_op_jmp_nz32(tmp
, l1
);
2549 if ((ext
& 0x0800) == 0) {
2551 rx
= gen_mac_extract_word(s
, rx
, (ext
& 0x80) != 0);
2552 ry
= gen_mac_extract_word(s
, ry
, (ext
& 0x40) != 0);
2554 if (s
->env
->macsr
& MACSR_FI
) {
2555 gen_helper_macmulf(s
->mactmp
, cpu_env
, rx
, ry
);
2557 if (s
->env
->macsr
& MACSR_SU
)
2558 gen_helper_macmuls(s
->mactmp
, cpu_env
, rx
, ry
);
2560 gen_helper_macmulu(s
->mactmp
, cpu_env
, rx
, ry
);
2561 switch ((ext
>> 9) & 3) {
2563 tcg_gen_shli_i64(s
->mactmp
, s
->mactmp
, 1);
2566 tcg_gen_shri_i64(s
->mactmp
, s
->mactmp
, 1);
2572 /* Save the overflow flag from the multiply. */
2573 saved_flags
= tcg_temp_new();
2574 tcg_gen_mov_i32(saved_flags
, QREG_MACSR
);
2576 saved_flags
= NULL_QREG
;
2580 /* Disabled because conditional branches clobber temporary vars. */
2581 if ((s
->env
->macsr
& MACSR_OMC
) != 0 && dual
) {
2582 /* Skip the accumulate if the value is already saturated. */
2583 l1
= gen_new_label();
2584 tmp
= tcg_temp_new();
2585 gen_op_and32(tmp
, QREG_MACSR
, tcg_const_i32(MACSR_PAV0
<< acc
));
2586 gen_op_jmp_nz32(tmp
, l1
);
2591 tcg_gen_sub_i64(MACREG(acc
), MACREG(acc
), s
->mactmp
);
2593 tcg_gen_add_i64(MACREG(acc
), MACREG(acc
), s
->mactmp
);
2595 if (s
->env
->macsr
& MACSR_FI
)
2596 gen_helper_macsatf(cpu_env
, tcg_const_i32(acc
));
2597 else if (s
->env
->macsr
& MACSR_SU
)
2598 gen_helper_macsats(cpu_env
, tcg_const_i32(acc
));
2600 gen_helper_macsatu(cpu_env
, tcg_const_i32(acc
));
2603 /* Disabled because conditional branches clobber temporary vars. */
2609 /* Dual accumulate variant. */
2610 acc
= (ext
>> 2) & 3;
2611 /* Restore the overflow flag from the multiplier. */
2612 tcg_gen_mov_i32(QREG_MACSR
, saved_flags
);
2614 /* Disabled because conditional branches clobber temporary vars. */
2615 if ((s
->env
->macsr
& MACSR_OMC
) != 0) {
2616 /* Skip the accumulate if the value is already saturated. */
2617 l1
= gen_new_label();
2618 tmp
= tcg_temp_new();
2619 gen_op_and32(tmp
, QREG_MACSR
, tcg_const_i32(MACSR_PAV0
<< acc
));
2620 gen_op_jmp_nz32(tmp
, l1
);
2624 tcg_gen_sub_i64(MACREG(acc
), MACREG(acc
), s
->mactmp
);
2626 tcg_gen_add_i64(MACREG(acc
), MACREG(acc
), s
->mactmp
);
2627 if (s
->env
->macsr
& MACSR_FI
)
2628 gen_helper_macsatf(cpu_env
, tcg_const_i32(acc
));
2629 else if (s
->env
->macsr
& MACSR_SU
)
2630 gen_helper_macsats(cpu_env
, tcg_const_i32(acc
));
2632 gen_helper_macsatu(cpu_env
, tcg_const_i32(acc
));
2634 /* Disabled because conditional branches clobber temporary vars. */
2639 gen_helper_mac_set_flags(cpu_env
, tcg_const_i32(acc
));
2643 rw
= (insn
& 0x40) ? AREG(insn
, 9) : DREG(insn
, 9);
2644 tcg_gen_mov_i32(rw
, loadval
);
2645 /* FIXME: Should address writeback happen with the masked or
2647 switch ((insn
>> 3) & 7) {
2648 case 3: /* Post-increment. */
2649 tcg_gen_addi_i32(AREG(insn
, 0), addr
, 4);
2651 case 4: /* Pre-decrement. */
2652 tcg_gen_mov_i32(AREG(insn
, 0), addr
);
2657 DISAS_INSN(from_mac
)
2663 rx
= (insn
& 8) ? AREG(insn
, 0) : DREG(insn
, 0);
2664 accnum
= (insn
>> 9) & 3;
2665 acc
= MACREG(accnum
);
2666 if (s
->env
->macsr
& MACSR_FI
) {
2667 gen_helper_get_macf(rx
, cpu_env
, acc
);
2668 } else if ((s
->env
->macsr
& MACSR_OMC
) == 0) {
2669 tcg_gen_trunc_i64_i32(rx
, acc
);
2670 } else if (s
->env
->macsr
& MACSR_SU
) {
2671 gen_helper_get_macs(rx
, acc
);
2673 gen_helper_get_macu(rx
, acc
);
2676 tcg_gen_movi_i64(acc
, 0);
2677 tcg_gen_andi_i32(QREG_MACSR
, QREG_MACSR
, ~(MACSR_PAV0
<< accnum
));
2681 DISAS_INSN(move_mac
)
2683 /* FIXME: This can be done without a helper. */
2687 dest
= tcg_const_i32((insn
>> 9) & 3);
2688 gen_helper_mac_move(cpu_env
, dest
, tcg_const_i32(src
));
2689 gen_mac_clear_flags();
2690 gen_helper_mac_set_flags(cpu_env
, dest
);
2693 DISAS_INSN(from_macsr
)
2697 reg
= (insn
& 8) ? AREG(insn
, 0) : DREG(insn
, 0);
2698 tcg_gen_mov_i32(reg
, QREG_MACSR
);
2701 DISAS_INSN(from_mask
)
2704 reg
= (insn
& 8) ? AREG(insn
, 0) : DREG(insn
, 0);
2705 tcg_gen_mov_i32(reg
, QREG_MAC_MASK
);
2708 DISAS_INSN(from_mext
)
2712 reg
= (insn
& 8) ? AREG(insn
, 0) : DREG(insn
, 0);
2713 acc
= tcg_const_i32((insn
& 0x400) ? 2 : 0);
2714 if (s
->env
->macsr
& MACSR_FI
)
2715 gen_helper_get_mac_extf(reg
, cpu_env
, acc
);
2717 gen_helper_get_mac_exti(reg
, cpu_env
, acc
);
2720 DISAS_INSN(macsr_to_ccr
)
2722 tcg_gen_movi_i32(QREG_CC_X
, 0);
2723 tcg_gen_andi_i32(QREG_CC_DEST
, QREG_MACSR
, 0xf);
2724 s
->cc_op
= CC_OP_FLAGS
;
2732 accnum
= (insn
>> 9) & 3;
2733 acc
= MACREG(accnum
);
2734 SRC_EA(val
, OS_LONG
, 0, NULL
);
2735 if (s
->env
->macsr
& MACSR_FI
) {
2736 tcg_gen_ext_i32_i64(acc
, val
);
2737 tcg_gen_shli_i64(acc
, acc
, 8);
2738 } else if (s
->env
->macsr
& MACSR_SU
) {
2739 tcg_gen_ext_i32_i64(acc
, val
);
2741 tcg_gen_extu_i32_i64(acc
, val
);
2743 tcg_gen_andi_i32(QREG_MACSR
, QREG_MACSR
, ~(MACSR_PAV0
<< accnum
));
2744 gen_mac_clear_flags();
2745 gen_helper_mac_set_flags(cpu_env
, tcg_const_i32(accnum
));
2748 DISAS_INSN(to_macsr
)
2751 SRC_EA(val
, OS_LONG
, 0, NULL
);
2752 gen_helper_set_macsr(cpu_env
, val
);
2759 SRC_EA(val
, OS_LONG
, 0, NULL
);
2760 tcg_gen_ori_i32(QREG_MAC_MASK
, val
, 0xffff0000);
2767 SRC_EA(val
, OS_LONG
, 0, NULL
);
2768 acc
= tcg_const_i32((insn
& 0x400) ? 2 : 0);
2769 if (s
->env
->macsr
& MACSR_FI
)
2770 gen_helper_set_mac_extf(cpu_env
, val
, acc
);
2771 else if (s
->env
->macsr
& MACSR_SU
)
2772 gen_helper_set_mac_exts(cpu_env
, val
, acc
);
2774 gen_helper_set_mac_extu(cpu_env
, val
, acc
);
2777 static disas_proc opcode_table
[65536];
2780 register_opcode (disas_proc proc
, uint16_t opcode
, uint16_t mask
)
2786 /* Sanity check. All set bits must be included in the mask. */
2787 if (opcode
& ~mask
) {
2789 "qemu internal error: bogus opcode definition %04x/%04x\n",
2793 /* This could probably be cleverer. For now just optimize the case where
2794 the top bits are known. */
2795 /* Find the first zero bit in the mask. */
2797 while ((i
& mask
) != 0)
2799 /* Iterate over all combinations of this and lower bits. */
2804 from
= opcode
& ~(i
- 1);
2806 for (i
= from
; i
< to
; i
++) {
2807 if ((i
& mask
) == opcode
)
2808 opcode_table
[i
] = proc
;
2812 /* Register m68k opcode handlers. Order is important.
2813 Later insn override earlier ones. */
2814 void register_m68k_insns (CPUM68KState
*env
)
2816 #define INSN(name, opcode, mask, feature) do { \
2817 if (m68k_feature(env, M68K_FEATURE_##feature)) \
2818 register_opcode(disas_##name, 0x##opcode, 0x##mask); \
2820 INSN(undef
, 0000, 0000, CF_ISA_A
);
2821 INSN(arith_im
, 0080, fff8
, CF_ISA_A
);
2822 INSN(bitrev
, 00c0
, fff8
, CF_ISA_APLUSC
);
2823 INSN(bitop_reg
, 0100, f1c0
, CF_ISA_A
);
2824 INSN(bitop_reg
, 0140, f1c0
, CF_ISA_A
);
2825 INSN(bitop_reg
, 0180, f1c0
, CF_ISA_A
);
2826 INSN(bitop_reg
, 01c0
, f1c0
, CF_ISA_A
);
2827 INSN(arith_im
, 0280, fff8
, CF_ISA_A
);
2828 INSN(byterev
, 02c0
, fff8
, CF_ISA_APLUSC
);
2829 INSN(arith_im
, 0480, fff8
, CF_ISA_A
);
2830 INSN(ff1
, 04c0
, fff8
, CF_ISA_APLUSC
);
2831 INSN(arith_im
, 0680, fff8
, CF_ISA_A
);
2832 INSN(bitop_im
, 0800, ffc0
, CF_ISA_A
);
2833 INSN(bitop_im
, 0840, ffc0
, CF_ISA_A
);
2834 INSN(bitop_im
, 0880, ffc0
, CF_ISA_A
);
2835 INSN(bitop_im
, 08c0
, ffc0
, CF_ISA_A
);
2836 INSN(arith_im
, 0a80
, fff8
, CF_ISA_A
);
2837 INSN(arith_im
, 0c00
, ff38
, CF_ISA_A
);
2838 INSN(move
, 1000, f000
, CF_ISA_A
);
2839 INSN(move
, 2000, f000
, CF_ISA_A
);
2840 INSN(move
, 3000, f000
, CF_ISA_A
);
2841 INSN(strldsr
, 40e7
, ffff
, CF_ISA_APLUSC
);
2842 INSN(negx
, 4080, fff8
, CF_ISA_A
);
2843 INSN(move_from_sr
, 40c0
, fff8
, CF_ISA_A
);
2844 INSN(lea
, 41c0
, f1c0
, CF_ISA_A
);
2845 INSN(clr
, 4200, ff00
, CF_ISA_A
);
2846 INSN(undef
, 42c0
, ffc0
, CF_ISA_A
);
2847 INSN(move_from_ccr
, 42c0
, fff8
, CF_ISA_A
);
2848 INSN(neg
, 4480, fff8
, CF_ISA_A
);
2849 INSN(move_to_ccr
, 44c0
, ffc0
, CF_ISA_A
);
2850 INSN(not, 4680, fff8
, CF_ISA_A
);
2851 INSN(move_to_sr
, 46c0
, ffc0
, CF_ISA_A
);
2852 INSN(pea
, 4840, ffc0
, CF_ISA_A
);
2853 INSN(swap
, 4840, fff8
, CF_ISA_A
);
2854 INSN(movem
, 48c0
, fbc0
, CF_ISA_A
);
2855 INSN(ext
, 4880, fff8
, CF_ISA_A
);
2856 INSN(ext
, 48c0
, fff8
, CF_ISA_A
);
2857 INSN(ext
, 49c0
, fff8
, CF_ISA_A
);
2858 INSN(tst
, 4a00
, ff00
, CF_ISA_A
);
2859 INSN(tas
, 4ac0
, ffc0
, CF_ISA_B
);
2860 INSN(halt
, 4ac8
, ffff
, CF_ISA_A
);
2861 INSN(pulse
, 4acc
, ffff
, CF_ISA_A
);
2862 INSN(illegal
, 4afc
, ffff
, CF_ISA_A
);
2863 INSN(mull
, 4c00
, ffc0
, CF_ISA_A
);
2864 INSN(divl
, 4c40
, ffc0
, CF_ISA_A
);
2865 INSN(sats
, 4c80
, fff8
, CF_ISA_B
);
2866 INSN(trap
, 4e40
, fff0
, CF_ISA_A
);
2867 INSN(link
, 4e50
, fff8
, CF_ISA_A
);
2868 INSN(unlk
, 4e58
, fff8
, CF_ISA_A
);
2869 INSN(move_to_usp
, 4e60
, fff8
, USP
);
2870 INSN(move_from_usp
, 4e68
, fff8
, USP
);
2871 INSN(nop
, 4e71
, ffff
, CF_ISA_A
);
2872 INSN(stop
, 4e72
, ffff
, CF_ISA_A
);
2873 INSN(rte
, 4e73
, ffff
, CF_ISA_A
);
2874 INSN(rts
, 4e75
, ffff
, CF_ISA_A
);
2875 INSN(movec
, 4e7b
, ffff
, CF_ISA_A
);
2876 INSN(jump
, 4e80
, ffc0
, CF_ISA_A
);
2877 INSN(jump
, 4ec0
, ffc0
, CF_ISA_A
);
2878 INSN(addsubq
, 5180, f1c0
, CF_ISA_A
);
2879 INSN(scc
, 50c0
, f0f8
, CF_ISA_A
);
2880 INSN(addsubq
, 5080, f1c0
, CF_ISA_A
);
2881 INSN(tpf
, 51f8
, fff8
, CF_ISA_A
);
2883 /* Branch instructions. */
2884 INSN(branch
, 6000, f000
, CF_ISA_A
);
2885 /* Disable long branch instructions, then add back the ones we want. */
2886 INSN(undef
, 60ff
, f0ff
, CF_ISA_A
); /* All long branches. */
2887 INSN(branch
, 60ff
, f0ff
, CF_ISA_B
);
2888 INSN(undef
, 60ff
, ffff
, CF_ISA_B
); /* bra.l */
2889 INSN(branch
, 60ff
, ffff
, BRAL
);
2891 INSN(moveq
, 7000, f100
, CF_ISA_A
);
2892 INSN(mvzs
, 7100, f100
, CF_ISA_B
);
2893 INSN(or, 8000, f000
, CF_ISA_A
);
2894 INSN(divw
, 80c0
, f0c0
, CF_ISA_A
);
2895 INSN(addsub
, 9000, f000
, CF_ISA_A
);
2896 INSN(subx
, 9180, f1f8
, CF_ISA_A
);
2897 INSN(suba
, 91c0
, f1c0
, CF_ISA_A
);
2899 INSN(undef_mac
, a000
, f000
, CF_ISA_A
);
2900 INSN(mac
, a000
, f100
, CF_EMAC
);
2901 INSN(from_mac
, a180
, f9b0
, CF_EMAC
);
2902 INSN(move_mac
, a110
, f9fc
, CF_EMAC
);
2903 INSN(from_macsr
,a980
, f9f0
, CF_EMAC
);
2904 INSN(from_mask
, ad80
, fff0
, CF_EMAC
);
2905 INSN(from_mext
, ab80
, fbf0
, CF_EMAC
);
2906 INSN(macsr_to_ccr
, a9c0
, ffff
, CF_EMAC
);
2907 INSN(to_mac
, a100
, f9c0
, CF_EMAC
);
2908 INSN(to_macsr
, a900
, ffc0
, CF_EMAC
);
2909 INSN(to_mext
, ab00
, fbc0
, CF_EMAC
);
2910 INSN(to_mask
, ad00
, ffc0
, CF_EMAC
);
2912 INSN(mov3q
, a140
, f1c0
, CF_ISA_B
);
2913 INSN(cmp
, b000
, f1c0
, CF_ISA_B
); /* cmp.b */
2914 INSN(cmp
, b040
, f1c0
, CF_ISA_B
); /* cmp.w */
2915 INSN(cmpa
, b0c0
, f1c0
, CF_ISA_B
); /* cmpa.w */
2916 INSN(cmp
, b080
, f1c0
, CF_ISA_A
);
2917 INSN(cmpa
, b1c0
, f1c0
, CF_ISA_A
);
2918 INSN(eor
, b180
, f1c0
, CF_ISA_A
);
2919 INSN(and, c000
, f000
, CF_ISA_A
);
2920 INSN(mulw
, c0c0
, f0c0
, CF_ISA_A
);
2921 INSN(addsub
, d000
, f000
, CF_ISA_A
);
2922 INSN(addx
, d180
, f1f8
, CF_ISA_A
);
2923 INSN(adda
, d1c0
, f1c0
, CF_ISA_A
);
2924 INSN(shift_im
, e080
, f0f0
, CF_ISA_A
);
2925 INSN(shift_reg
, e0a0
, f0f0
, CF_ISA_A
);
2926 INSN(undef_fpu
, f000
, f000
, CF_ISA_A
);
2927 INSN(fpu
, f200
, ffc0
, CF_FPU
);
2928 INSN(fbcc
, f280
, ffc0
, CF_FPU
);
2929 INSN(frestore
, f340
, ffc0
, CF_FPU
);
2930 INSN(fsave
, f340
, ffc0
, CF_FPU
);
2931 INSN(intouch
, f340
, ffc0
, CF_ISA_A
);
2932 INSN(cpushl
, f428
, ff38
, CF_ISA_A
);
2933 INSN(wddata
, fb00
, ff00
, CF_ISA_A
);
2934 INSN(wdebug
, fbc0
, ffc0
, CF_ISA_A
);
2938 /* ??? Some of this implementation is not exception safe. We should always
2939 write back the result to memory before setting the condition codes. */
2940 static void disas_m68k_insn(CPUM68KState
* env
, DisasContext
*s
)
2944 insn
= lduw_code(s
->pc
);
2947 opcode_table
[insn
](s
, insn
);
2950 /* generate intermediate code for basic block 'tb'. */
2952 gen_intermediate_code_internal(CPUM68KState
*env
, TranslationBlock
*tb
,
2955 DisasContext dc1
, *dc
= &dc1
;
2956 uint16_t *gen_opc_end
;
2959 target_ulong pc_start
;
2964 /* generate intermediate code */
2969 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
2972 dc
->is_jmp
= DISAS_NEXT
;
2974 dc
->cc_op
= CC_OP_DYNAMIC
;
2975 dc
->singlestep_enabled
= env
->singlestep_enabled
;
2976 dc
->fpcr
= env
->fpcr
;
2977 dc
->user
= (env
->sr
& SR_S
) == 0;
2982 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
2984 max_insns
= CF_COUNT_MASK
;
2988 pc_offset
= dc
->pc
- pc_start
;
2989 gen_throws_exception
= NULL
;
2990 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
2991 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
2992 if (bp
->pc
== dc
->pc
) {
2993 gen_exception(dc
, dc
->pc
, EXCP_DEBUG
);
2994 dc
->is_jmp
= DISAS_JUMP
;
3002 j
= gen_opc_ptr
- gen_opc_buf
;
3006 gen_opc_instr_start
[lj
++] = 0;
3008 gen_opc_pc
[lj
] = dc
->pc
;
3009 gen_opc_instr_start
[lj
] = 1;
3010 gen_opc_icount
[lj
] = num_insns
;
3012 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
3014 dc
->insn_pc
= dc
->pc
;
3015 disas_m68k_insn(env
, dc
);
3017 } while (!dc
->is_jmp
&& gen_opc_ptr
< gen_opc_end
&&
3018 !env
->singlestep_enabled
&&
3020 (pc_offset
) < (TARGET_PAGE_SIZE
- 32) &&
3021 num_insns
< max_insns
);
3023 if (tb
->cflags
& CF_LAST_IO
)
3025 if (unlikely(env
->singlestep_enabled
)) {
3026 /* Make sure the pc is updated, and raise a debug exception. */
3028 gen_flush_cc_op(dc
);
3029 tcg_gen_movi_i32(QREG_PC
, dc
->pc
);
3031 gen_helper_raise_exception(tcg_const_i32(EXCP_DEBUG
));
3033 switch(dc
->is_jmp
) {
3035 gen_flush_cc_op(dc
);
3036 gen_jmp_tb(dc
, 0, dc
->pc
);
3041 gen_flush_cc_op(dc
);
3042 /* indicate that the hash table must be used to find the next TB */
3046 /* nothing more to generate */
3050 gen_icount_end(tb
, num_insns
);
3051 *gen_opc_ptr
= INDEX_op_end
;
3054 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
3055 qemu_log("----------------\n");
3056 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
3057 log_target_disas(pc_start
, dc
->pc
- pc_start
, 0);
3062 j
= gen_opc_ptr
- gen_opc_buf
;
3065 gen_opc_instr_start
[lj
++] = 0;
3067 tb
->size
= dc
->pc
- pc_start
;
3068 tb
->icount
= num_insns
;
3072 //expand_target_qops();
3075 void gen_intermediate_code(CPUM68KState
*env
, TranslationBlock
*tb
)
3077 gen_intermediate_code_internal(env
, tb
, 0);
3080 void gen_intermediate_code_pc(CPUM68KState
*env
, TranslationBlock
*tb
)
3082 gen_intermediate_code_internal(env
, tb
, 1);
3085 void cpu_dump_state(CPUM68KState
*env
, FILE *f
, fprintf_function cpu_fprintf
,
3091 for (i
= 0; i
< 8; i
++)
3093 u
.d
= env
->fregs
[i
];
3094 cpu_fprintf (f
, "D%d = %08x A%d = %08x F%d = %08x%08x (%12g)\n",
3095 i
, env
->dregs
[i
], i
, env
->aregs
[i
],
3096 i
, u
.l
.upper
, u
.l
.lower
, *(double *)&u
.d
);
3098 cpu_fprintf (f
, "PC = %08x ", env
->pc
);
3100 cpu_fprintf (f
, "SR = %04x %c%c%c%c%c ", sr
, (sr
& 0x10) ? 'X' : '-',
3101 (sr
& CCF_N
) ? 'N' : '-', (sr
& CCF_Z
) ? 'Z' : '-',
3102 (sr
& CCF_V
) ? 'V' : '-', (sr
& CCF_C
) ? 'C' : '-');
3103 cpu_fprintf (f
, "FPRESULT = %12g\n", *(double *)&env
->fp_result
);
3106 void restore_state_to_opc(CPUM68KState
*env
, TranslationBlock
*tb
, int pc_pos
)
3108 env
->pc
= gen_opc_pc
[pc_pos
];