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, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
39 //#define DEBUG_DISPATCH 1
41 /* Fake floating point. */
42 #define tcg_gen_mov_f64 tcg_gen_mov_i64
43 #define tcg_gen_qemu_ldf64 tcg_gen_qemu_ld64
44 #define tcg_gen_qemu_stf64 tcg_gen_qemu_st64
46 #define DEFO32(name, offset) static TCGv QREG_##name;
47 #define DEFO64(name, offset) static TCGv_i64 QREG_##name;
48 #define DEFF64(name, offset) static TCGv_i64 QREG_##name;
54 static TCGv_ptr cpu_env
;
56 static char cpu_reg_names
[3*8*3 + 5*4];
57 static TCGv cpu_dregs
[8];
58 static TCGv cpu_aregs
[8];
59 static TCGv_i64 cpu_fregs
[8];
60 static TCGv_i64 cpu_macc
[4];
62 #define DREG(insn, pos) cpu_dregs[((insn) >> (pos)) & 7]
63 #define AREG(insn, pos) cpu_aregs[((insn) >> (pos)) & 7]
64 #define FREG(insn, pos) cpu_fregs[((insn) >> (pos)) & 7]
65 #define MACREG(acc) cpu_macc[acc]
66 #define QREG_SP cpu_aregs[7]
68 static TCGv NULL_QREG
;
69 #define IS_NULL_QREG(t) (TCGV_EQUAL(t, NULL_QREG))
70 /* Used to distinguish stores from bad addressing modes. */
71 static TCGv store_dummy
;
73 #include "gen-icount.h"
75 void m68k_tcg_init(void)
80 #define DEFO32(name, offset) QREG_##name = tcg_global_mem_new_i32(TCG_AREG0, offsetof(CPUState, offset), #name);
81 #define DEFO64(name, offset) QREG_##name = tcg_global_mem_new_i64(TCG_AREG0, offsetof(CPUState, offset), #name);
82 #define DEFF64(name, offset) DEFO64(name, offset)
88 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
91 for (i
= 0; i
< 8; i
++) {
93 cpu_dregs
[i
] = tcg_global_mem_new(TCG_AREG0
,
94 offsetof(CPUM68KState
, dregs
[i
]), p
);
97 cpu_aregs
[i
] = tcg_global_mem_new(TCG_AREG0
,
98 offsetof(CPUM68KState
, aregs
[i
]), p
);
100 sprintf(p
, "F%d", i
);
101 cpu_fregs
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
102 offsetof(CPUM68KState
, fregs
[i
]), p
);
105 for (i
= 0; i
< 4; i
++) {
106 sprintf(p
, "ACC%d", i
);
107 cpu_macc
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
108 offsetof(CPUM68KState
, macc
[i
]), p
);
112 NULL_QREG
= tcg_global_mem_new(TCG_AREG0
, -4, "NULL");
113 store_dummy
= tcg_global_mem_new(TCG_AREG0
, -8, "NULL");
119 static inline void qemu_assert(int cond
, const char *msg
)
122 fprintf (stderr
, "badness: %s\n", msg
);
127 /* internal defines */
128 typedef struct DisasContext
{
130 target_ulong insn_pc
; /* Start of the current instruction. */
136 struct TranslationBlock
*tb
;
137 int singlestep_enabled
;
143 #define DISAS_JUMP_NEXT 4
145 #if defined(CONFIG_USER_ONLY)
148 #define IS_USER(s) s->user
151 /* XXX: move that elsewhere */
152 /* ??? Fix exceptions. */
153 static void *gen_throws_exception
;
154 #define gen_last_qop NULL
162 typedef void (*disas_proc
)(DisasContext
*, uint16_t);
164 #ifdef DEBUG_DISPATCH
165 #define DISAS_INSN(name) \
166 static void real_disas_##name (DisasContext *s, uint16_t insn); \
167 static void disas_##name (DisasContext *s, uint16_t insn) { \
168 qemu_log("Dispatch " #name "\n"); \
169 real_disas_##name(s, insn); } \
170 static void real_disas_##name (DisasContext *s, uint16_t insn)
172 #define DISAS_INSN(name) \
173 static void disas_##name (DisasContext *s, uint16_t insn)
176 /* FIXME: Remove this. */
177 #define gen_im32(val) tcg_const_i32(val)
179 /* Generate a load from the specified address. Narrow values are
180 sign extended to full register width. */
181 static inline TCGv
gen_load(DisasContext
* s
, int opsize
, TCGv addr
, int sign
)
184 int index
= IS_USER(s
);
186 tmp
= tcg_temp_new_i32();
190 tcg_gen_qemu_ld8s(tmp
, addr
, index
);
192 tcg_gen_qemu_ld8u(tmp
, addr
, index
);
196 tcg_gen_qemu_ld16s(tmp
, addr
, index
);
198 tcg_gen_qemu_ld16u(tmp
, addr
, index
);
202 tcg_gen_qemu_ld32u(tmp
, addr
, index
);
205 qemu_assert(0, "bad load size");
207 gen_throws_exception
= gen_last_qop
;
211 static inline TCGv_i64
gen_load64(DisasContext
* s
, TCGv addr
)
214 int index
= IS_USER(s
);
216 tmp
= tcg_temp_new_i64();
217 tcg_gen_qemu_ldf64(tmp
, addr
, index
);
218 gen_throws_exception
= gen_last_qop
;
222 /* Generate a store. */
223 static inline void gen_store(DisasContext
*s
, int opsize
, TCGv addr
, TCGv val
)
225 int index
= IS_USER(s
);
229 tcg_gen_qemu_st8(val
, addr
, index
);
232 tcg_gen_qemu_st16(val
, addr
, index
);
236 tcg_gen_qemu_st32(val
, addr
, index
);
239 qemu_assert(0, "bad store size");
241 gen_throws_exception
= gen_last_qop
;
244 static inline void gen_store64(DisasContext
*s
, TCGv addr
, TCGv_i64 val
)
246 int index
= IS_USER(s
);
248 tcg_gen_qemu_stf64(val
, addr
, index
);
249 gen_throws_exception
= gen_last_qop
;
258 /* Generate an unsigned load if VAL is 0 a signed load if val is -1,
259 otherwise generate a store. */
260 static TCGv
gen_ldst(DisasContext
*s
, int opsize
, TCGv addr
, TCGv val
,
263 if (what
== EA_STORE
) {
264 gen_store(s
, opsize
, addr
, val
);
267 return gen_load(s
, opsize
, addr
, what
== EA_LOADS
);
271 /* Read a 32-bit immediate constant. */
272 static inline uint32_t read_im32(DisasContext
*s
)
275 im
= ((uint32_t)lduw_code(s
->pc
)) << 16;
277 im
|= lduw_code(s
->pc
);
282 /* Calculate and address index. */
283 static TCGv
gen_addr_index(uint16_t ext
, TCGv tmp
)
288 add
= (ext
& 0x8000) ? AREG(ext
, 12) : DREG(ext
, 12);
289 if ((ext
& 0x800) == 0) {
290 tcg_gen_ext16s_i32(tmp
, add
);
293 scale
= (ext
>> 9) & 3;
295 tcg_gen_shli_i32(tmp
, add
, scale
);
301 /* Handle a base + index + displacement effective addresss.
302 A NULL_QREG base means pc-relative. */
303 static TCGv
gen_lea_indexed(DisasContext
*s
, int opsize
, TCGv base
)
312 ext
= lduw_code(s
->pc
);
315 if ((ext
& 0x800) == 0 && !m68k_feature(s
->env
, M68K_FEATURE_WORD_INDEX
))
319 /* full extension word format */
320 if (!m68k_feature(s
->env
, M68K_FEATURE_EXT_FULL
))
323 if ((ext
& 0x30) > 0x10) {
324 /* base displacement */
325 if ((ext
& 0x30) == 0x20) {
326 bd
= (int16_t)lduw_code(s
->pc
);
334 tmp
= tcg_temp_new();
335 if ((ext
& 0x44) == 0) {
337 add
= gen_addr_index(ext
, tmp
);
341 if ((ext
& 0x80) == 0) {
342 /* base not suppressed */
343 if (IS_NULL_QREG(base
)) {
344 base
= gen_im32(offset
+ bd
);
347 if (!IS_NULL_QREG(add
)) {
348 tcg_gen_add_i32(tmp
, add
, base
);
354 if (!IS_NULL_QREG(add
)) {
356 tcg_gen_addi_i32(tmp
, add
, bd
);
362 if ((ext
& 3) != 0) {
363 /* memory indirect */
364 base
= gen_load(s
, OS_LONG
, add
, 0);
365 if ((ext
& 0x44) == 4) {
366 add
= gen_addr_index(ext
, tmp
);
367 tcg_gen_add_i32(tmp
, add
, base
);
373 /* outer displacement */
374 if ((ext
& 3) == 2) {
375 od
= (int16_t)lduw_code(s
->pc
);
384 tcg_gen_addi_i32(tmp
, add
, od
);
389 /* brief extension word format */
390 tmp
= tcg_temp_new();
391 add
= gen_addr_index(ext
, tmp
);
392 if (!IS_NULL_QREG(base
)) {
393 tcg_gen_add_i32(tmp
, add
, base
);
395 tcg_gen_addi_i32(tmp
, tmp
, (int8_t)ext
);
397 tcg_gen_addi_i32(tmp
, add
, offset
+ (int8_t)ext
);
404 /* Update the CPU env CC_OP state. */
405 static inline void gen_flush_cc_op(DisasContext
*s
)
407 if (s
->cc_op
!= CC_OP_DYNAMIC
)
408 tcg_gen_movi_i32(QREG_CC_OP
, s
->cc_op
);
411 /* Evaluate all the CC flags. */
412 static inline void gen_flush_flags(DisasContext
*s
)
414 if (s
->cc_op
== CC_OP_FLAGS
)
417 gen_helper_flush_flags(cpu_env
, QREG_CC_OP
);
418 s
->cc_op
= CC_OP_FLAGS
;
421 static void gen_logic_cc(DisasContext
*s
, TCGv val
)
423 tcg_gen_mov_i32(QREG_CC_DEST
, val
);
424 s
->cc_op
= CC_OP_LOGIC
;
427 static void gen_update_cc_add(TCGv dest
, TCGv src
)
429 tcg_gen_mov_i32(QREG_CC_DEST
, dest
);
430 tcg_gen_mov_i32(QREG_CC_SRC
, src
);
433 static inline int opsize_bytes(int opsize
)
436 case OS_BYTE
: return 1;
437 case OS_WORD
: return 2;
438 case OS_LONG
: return 4;
439 case OS_SINGLE
: return 4;
440 case OS_DOUBLE
: return 8;
442 qemu_assert(0, "bad operand size");
447 /* Assign value to a register. If the width is less than the register width
448 only the low part of the register is set. */
449 static void gen_partset_reg(int opsize
, TCGv reg
, TCGv val
)
454 tcg_gen_andi_i32(reg
, reg
, 0xffffff00);
455 tmp
= tcg_temp_new();
456 tcg_gen_ext8u_i32(tmp
, val
);
457 tcg_gen_or_i32(reg
, reg
, tmp
);
460 tcg_gen_andi_i32(reg
, reg
, 0xffff0000);
461 tmp
= tcg_temp_new();
462 tcg_gen_ext16u_i32(tmp
, val
);
463 tcg_gen_or_i32(reg
, reg
, tmp
);
467 tcg_gen_mov_i32(reg
, val
);
470 qemu_assert(0, "Bad operand size");
475 /* Sign or zero extend a value. */
476 static inline TCGv
gen_extend(TCGv val
, int opsize
, int sign
)
482 tmp
= tcg_temp_new();
484 tcg_gen_ext8s_i32(tmp
, val
);
486 tcg_gen_ext8u_i32(tmp
, val
);
489 tmp
= tcg_temp_new();
491 tcg_gen_ext16s_i32(tmp
, val
);
493 tcg_gen_ext16u_i32(tmp
, val
);
500 qemu_assert(0, "Bad operand size");
505 /* Generate code for an "effective address". Does not adjust the base
506 register for autoincrement addressing modes. */
507 static TCGv
gen_lea(DisasContext
*s
, uint16_t insn
, int opsize
)
514 switch ((insn
>> 3) & 7) {
515 case 0: /* Data register direct. */
516 case 1: /* Address register direct. */
518 case 2: /* Indirect register */
519 case 3: /* Indirect postincrement. */
520 return AREG(insn
, 0);
521 case 4: /* Indirect predecrememnt. */
523 tmp
= tcg_temp_new();
524 tcg_gen_subi_i32(tmp
, reg
, opsize_bytes(opsize
));
526 case 5: /* Indirect displacement. */
528 tmp
= tcg_temp_new();
529 ext
= lduw_code(s
->pc
);
531 tcg_gen_addi_i32(tmp
, reg
, (int16_t)ext
);
533 case 6: /* Indirect index + displacement. */
535 return gen_lea_indexed(s
, opsize
, reg
);
538 case 0: /* Absolute short. */
539 offset
= ldsw_code(s
->pc
);
541 return gen_im32(offset
);
542 case 1: /* Absolute long. */
543 offset
= read_im32(s
);
544 return gen_im32(offset
);
545 case 2: /* pc displacement */
546 tmp
= tcg_temp_new();
548 offset
+= ldsw_code(s
->pc
);
550 return gen_im32(offset
);
551 case 3: /* pc index+displacement. */
552 return gen_lea_indexed(s
, opsize
, NULL_QREG
);
553 case 4: /* Immediate. */
558 /* Should never happen. */
562 /* Helper function for gen_ea. Reuse the computed address between the
563 for read/write operands. */
564 static inline TCGv
gen_ea_once(DisasContext
*s
, uint16_t insn
, int opsize
,
565 TCGv val
, TCGv
*addrp
, ea_what what
)
569 if (addrp
&& what
== EA_STORE
) {
572 tmp
= gen_lea(s
, insn
, opsize
);
573 if (IS_NULL_QREG(tmp
))
578 return gen_ldst(s
, opsize
, tmp
, val
, what
);
581 /* Generate code to load/store a value ito/from an EA. If VAL > 0 this is
582 a write otherwise it is a read (0 == sign extend, -1 == zero extend).
583 ADDRP is non-null for readwrite operands. */
584 static TCGv
gen_ea(DisasContext
*s
, uint16_t insn
, int opsize
, TCGv val
,
585 TCGv
*addrp
, ea_what what
)
591 switch ((insn
>> 3) & 7) {
592 case 0: /* Data register direct. */
594 if (what
== EA_STORE
) {
595 gen_partset_reg(opsize
, reg
, val
);
598 return gen_extend(reg
, opsize
, what
== EA_LOADS
);
600 case 1: /* Address register direct. */
602 if (what
== EA_STORE
) {
603 tcg_gen_mov_i32(reg
, val
);
606 return gen_extend(reg
, opsize
, what
== EA_LOADS
);
608 case 2: /* Indirect register */
610 return gen_ldst(s
, opsize
, reg
, val
, what
);
611 case 3: /* Indirect postincrement. */
613 result
= gen_ldst(s
, opsize
, reg
, val
, what
);
614 /* ??? This is not exception safe. The instruction may still
615 fault after this point. */
616 if (what
== EA_STORE
|| !addrp
)
617 tcg_gen_addi_i32(reg
, reg
, opsize_bytes(opsize
));
619 case 4: /* Indirect predecrememnt. */
622 if (addrp
&& what
== EA_STORE
) {
625 tmp
= gen_lea(s
, insn
, opsize
);
626 if (IS_NULL_QREG(tmp
))
631 result
= gen_ldst(s
, opsize
, tmp
, val
, what
);
632 /* ??? This is not exception safe. The instruction may still
633 fault after this point. */
634 if (what
== EA_STORE
|| !addrp
) {
636 tcg_gen_mov_i32(reg
, tmp
);
640 case 5: /* Indirect displacement. */
641 case 6: /* Indirect index + displacement. */
642 return gen_ea_once(s
, insn
, opsize
, val
, addrp
, what
);
645 case 0: /* Absolute short. */
646 case 1: /* Absolute long. */
647 case 2: /* pc displacement */
648 case 3: /* pc index+displacement. */
649 return gen_ea_once(s
, insn
, opsize
, val
, addrp
, what
);
650 case 4: /* Immediate. */
651 /* Sign extend values for consistency. */
654 if (what
== EA_LOADS
)
655 offset
= ldsb_code(s
->pc
+ 1);
657 offset
= ldub_code(s
->pc
+ 1);
661 if (what
== EA_LOADS
)
662 offset
= ldsw_code(s
->pc
);
664 offset
= lduw_code(s
->pc
);
668 offset
= read_im32(s
);
671 qemu_assert(0, "Bad immediate operand");
673 return tcg_const_i32(offset
);
678 /* Should never happen. */
682 /* This generates a conditional branch, clobbering all temporaries. */
683 static void gen_jmpcc(DisasContext
*s
, int cond
, int l1
)
687 /* TODO: Optimize compare/branch pairs rather than always flushing
688 flag state to CC_OP_FLAGS. */
696 case 2: /* HI (!C && !Z) */
697 tmp
= tcg_temp_new();
698 tcg_gen_andi_i32(tmp
, QREG_CC_DEST
, CCF_C
| CCF_Z
);
699 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, l1
);
701 case 3: /* LS (C || Z) */
702 tmp
= tcg_temp_new();
703 tcg_gen_andi_i32(tmp
, QREG_CC_DEST
, CCF_C
| CCF_Z
);
704 tcg_gen_brcondi_i32(TCG_COND_NE
, tmp
, 0, l1
);
706 case 4: /* CC (!C) */
707 tmp
= tcg_temp_new();
708 tcg_gen_andi_i32(tmp
, QREG_CC_DEST
, CCF_C
);
709 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, l1
);
712 tmp
= tcg_temp_new();
713 tcg_gen_andi_i32(tmp
, QREG_CC_DEST
, CCF_C
);
714 tcg_gen_brcondi_i32(TCG_COND_NE
, tmp
, 0, l1
);
716 case 6: /* NE (!Z) */
717 tmp
= tcg_temp_new();
718 tcg_gen_andi_i32(tmp
, QREG_CC_DEST
, CCF_Z
);
719 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, l1
);
722 tmp
= tcg_temp_new();
723 tcg_gen_andi_i32(tmp
, QREG_CC_DEST
, CCF_Z
);
724 tcg_gen_brcondi_i32(TCG_COND_NE
, tmp
, 0, l1
);
726 case 8: /* VC (!V) */
727 tmp
= tcg_temp_new();
728 tcg_gen_andi_i32(tmp
, QREG_CC_DEST
, CCF_V
);
729 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, l1
);
732 tmp
= tcg_temp_new();
733 tcg_gen_andi_i32(tmp
, QREG_CC_DEST
, CCF_V
);
734 tcg_gen_brcondi_i32(TCG_COND_NE
, tmp
, 0, l1
);
736 case 10: /* PL (!N) */
737 tmp
= tcg_temp_new();
738 tcg_gen_andi_i32(tmp
, QREG_CC_DEST
, CCF_N
);
739 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, l1
);
741 case 11: /* MI (N) */
742 tmp
= tcg_temp_new();
743 tcg_gen_andi_i32(tmp
, QREG_CC_DEST
, CCF_N
);
744 tcg_gen_brcondi_i32(TCG_COND_NE
, tmp
, 0, l1
);
746 case 12: /* GE (!(N ^ V)) */
747 tmp
= tcg_temp_new();
748 assert(CCF_V
== (CCF_N
>> 2));
749 tcg_gen_shri_i32(tmp
, QREG_CC_DEST
, 2);
750 tcg_gen_xor_i32(tmp
, tmp
, QREG_CC_DEST
);
751 tcg_gen_andi_i32(tmp
, tmp
, CCF_V
);
752 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, l1
);
754 case 13: /* LT (N ^ V) */
755 tmp
= tcg_temp_new();
756 assert(CCF_V
== (CCF_N
>> 2));
757 tcg_gen_shri_i32(tmp
, QREG_CC_DEST
, 2);
758 tcg_gen_xor_i32(tmp
, tmp
, QREG_CC_DEST
);
759 tcg_gen_andi_i32(tmp
, tmp
, CCF_V
);
760 tcg_gen_brcondi_i32(TCG_COND_NE
, tmp
, 0, l1
);
762 case 14: /* GT (!(Z || (N ^ V))) */
763 tmp
= tcg_temp_new();
764 assert(CCF_V
== (CCF_N
>> 2));
765 tcg_gen_andi_i32(tmp
, QREG_CC_DEST
, CCF_N
);
766 tcg_gen_shri_i32(tmp
, tmp
, 2);
767 tcg_gen_xor_i32(tmp
, tmp
, QREG_CC_DEST
);
768 tcg_gen_andi_i32(tmp
, tmp
, CCF_V
| CCF_Z
);
769 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, l1
);
771 case 15: /* LE (Z || (N ^ V)) */
772 tmp
= tcg_temp_new();
773 assert(CCF_V
== (CCF_N
>> 2));
774 tcg_gen_andi_i32(tmp
, QREG_CC_DEST
, CCF_N
);
775 tcg_gen_shri_i32(tmp
, tmp
, 2);
776 tcg_gen_xor_i32(tmp
, tmp
, QREG_CC_DEST
);
777 tcg_gen_andi_i32(tmp
, tmp
, CCF_V
| CCF_Z
);
778 tcg_gen_brcondi_i32(TCG_COND_NE
, tmp
, 0, l1
);
781 /* Should ever happen. */
792 l1
= gen_new_label();
793 cond
= (insn
>> 8) & 0xf;
795 tcg_gen_andi_i32(reg
, reg
, 0xffffff00);
796 /* This is safe because we modify the reg directly, with no other values
798 gen_jmpcc(s
, cond
^ 1, l1
);
799 tcg_gen_ori_i32(reg
, reg
, 0xff);
803 /* Force a TB lookup after an instruction that changes the CPU state. */
804 static void gen_lookup_tb(DisasContext
*s
)
807 tcg_gen_movi_i32(QREG_PC
, s
->pc
);
808 s
->is_jmp
= DISAS_UPDATE
;
811 /* Generate a jump to an immediate address. */
812 static void gen_jmp_im(DisasContext
*s
, uint32_t dest
)
815 tcg_gen_movi_i32(QREG_PC
, dest
);
816 s
->is_jmp
= DISAS_JUMP
;
819 /* Generate a jump to the address in qreg DEST. */
820 static void gen_jmp(DisasContext
*s
, TCGv dest
)
823 tcg_gen_mov_i32(QREG_PC
, dest
);
824 s
->is_jmp
= DISAS_JUMP
;
827 static void gen_exception(DisasContext
*s
, uint32_t where
, int nr
)
830 gen_jmp_im(s
, where
);
831 gen_helper_raise_exception(tcg_const_i32(nr
));
834 static inline void gen_addr_fault(DisasContext
*s
)
836 gen_exception(s
, s
->insn_pc
, EXCP_ADDRESS
);
839 #define SRC_EA(result, opsize, op_sign, addrp) do { \
840 result = gen_ea(s, insn, opsize, NULL_QREG, addrp, op_sign ? EA_LOADS : EA_LOADU); \
841 if (IS_NULL_QREG(result)) { \
847 #define DEST_EA(insn, opsize, val, addrp) do { \
848 TCGv ea_result = gen_ea(s, insn, opsize, val, addrp, EA_STORE); \
849 if (IS_NULL_QREG(ea_result)) { \
855 /* Generate a jump to an immediate address. */
856 static void gen_jmp_tb(DisasContext
*s
, int n
, uint32_t dest
)
858 TranslationBlock
*tb
;
861 if (unlikely(s
->singlestep_enabled
)) {
862 gen_exception(s
, dest
, EXCP_DEBUG
);
863 } else if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
) ||
864 (s
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
)) {
866 tcg_gen_movi_i32(QREG_PC
, dest
);
867 tcg_gen_exit_tb((long)tb
+ n
);
872 s
->is_jmp
= DISAS_TB_JUMP
;
875 DISAS_INSN(undef_mac
)
877 gen_exception(s
, s
->pc
- 2, EXCP_LINEA
);
880 DISAS_INSN(undef_fpu
)
882 gen_exception(s
, s
->pc
- 2, EXCP_LINEF
);
887 gen_exception(s
, s
->pc
- 2, EXCP_UNSUPPORTED
);
888 cpu_abort(cpu_single_env
, "Illegal instruction: %04x @ %08x",
899 sign
= (insn
& 0x100) != 0;
901 tmp
= tcg_temp_new();
903 tcg_gen_ext16s_i32(tmp
, reg
);
905 tcg_gen_ext16u_i32(tmp
, reg
);
906 SRC_EA(src
, OS_WORD
, sign
, NULL
);
907 tcg_gen_mul_i32(tmp
, tmp
, src
);
908 tcg_gen_mov_i32(reg
, tmp
);
909 /* Unlike m68k, coldfire always clears the overflow bit. */
910 gen_logic_cc(s
, tmp
);
920 sign
= (insn
& 0x100) != 0;
923 tcg_gen_ext16s_i32(QREG_DIV1
, reg
);
925 tcg_gen_ext16u_i32(QREG_DIV1
, reg
);
927 SRC_EA(src
, OS_WORD
, sign
, NULL
);
928 tcg_gen_mov_i32(QREG_DIV2
, src
);
930 gen_helper_divs(cpu_env
, tcg_const_i32(1));
932 gen_helper_divu(cpu_env
, tcg_const_i32(1));
935 tmp
= tcg_temp_new();
936 src
= tcg_temp_new();
937 tcg_gen_ext16u_i32(tmp
, QREG_DIV1
);
938 tcg_gen_shli_i32(src
, QREG_DIV2
, 16);
939 tcg_gen_or_i32(reg
, tmp
, src
);
940 s
->cc_op
= CC_OP_FLAGS
;
950 ext
= lduw_code(s
->pc
);
953 gen_exception(s
, s
->pc
- 4, EXCP_UNSUPPORTED
);
958 tcg_gen_mov_i32(QREG_DIV1
, num
);
959 SRC_EA(den
, OS_LONG
, 0, NULL
);
960 tcg_gen_mov_i32(QREG_DIV2
, den
);
962 gen_helper_divs(cpu_env
, tcg_const_i32(0));
964 gen_helper_divu(cpu_env
, tcg_const_i32(0));
966 if ((ext
& 7) == ((ext
>> 12) & 7)) {
968 tcg_gen_mov_i32 (reg
, QREG_DIV1
);
971 tcg_gen_mov_i32 (reg
, QREG_DIV2
);
973 s
->cc_op
= CC_OP_FLAGS
;
985 add
= (insn
& 0x4000) != 0;
987 dest
= tcg_temp_new();
989 SRC_EA(tmp
, OS_LONG
, 0, &addr
);
993 SRC_EA(src
, OS_LONG
, 0, NULL
);
996 tcg_gen_add_i32(dest
, tmp
, src
);
997 gen_helper_xflag_lt(QREG_CC_X
, dest
, src
);
998 s
->cc_op
= CC_OP_ADD
;
1000 gen_helper_xflag_lt(QREG_CC_X
, tmp
, src
);
1001 tcg_gen_sub_i32(dest
, tmp
, src
);
1002 s
->cc_op
= CC_OP_SUB
;
1004 gen_update_cc_add(dest
, src
);
1006 DEST_EA(insn
, OS_LONG
, dest
, &addr
);
1008 tcg_gen_mov_i32(reg
, dest
);
1013 /* Reverse the order of the bits in REG. */
1017 reg
= DREG(insn
, 0);
1018 gen_helper_bitrev(reg
, reg
);
1021 DISAS_INSN(bitop_reg
)
1031 if ((insn
& 0x38) != 0)
1035 op
= (insn
>> 6) & 3;
1036 SRC_EA(src1
, opsize
, 0, op
? &addr
: NULL
);
1037 src2
= DREG(insn
, 9);
1038 dest
= tcg_temp_new();
1041 tmp
= tcg_temp_new();
1042 if (opsize
== OS_BYTE
)
1043 tcg_gen_andi_i32(tmp
, src2
, 7);
1045 tcg_gen_andi_i32(tmp
, src2
, 31);
1047 tmp
= tcg_temp_new();
1048 tcg_gen_shr_i32(tmp
, src1
, src2
);
1049 tcg_gen_andi_i32(tmp
, tmp
, 1);
1050 tcg_gen_shli_i32(tmp
, tmp
, 2);
1051 /* Clear CCF_Z if bit set. */
1052 tcg_gen_ori_i32(QREG_CC_DEST
, QREG_CC_DEST
, CCF_Z
);
1053 tcg_gen_xor_i32(QREG_CC_DEST
, QREG_CC_DEST
, tmp
);
1055 tcg_gen_shl_i32(tmp
, tcg_const_i32(1), src2
);
1058 tcg_gen_xor_i32(dest
, src1
, tmp
);
1061 tcg_gen_not_i32(tmp
, tmp
);
1062 tcg_gen_and_i32(dest
, src1
, tmp
);
1065 tcg_gen_or_i32(dest
, src1
, tmp
);
1071 DEST_EA(insn
, opsize
, dest
, &addr
);
1077 reg
= DREG(insn
, 0);
1079 gen_helper_sats(reg
, reg
, QREG_CC_DEST
);
1080 gen_logic_cc(s
, reg
);
1083 static void gen_push(DisasContext
*s
, TCGv val
)
1087 tmp
= tcg_temp_new();
1088 tcg_gen_subi_i32(tmp
, QREG_SP
, 4);
1089 gen_store(s
, OS_LONG
, tmp
, val
);
1090 tcg_gen_mov_i32(QREG_SP
, tmp
);
1102 mask
= lduw_code(s
->pc
);
1104 tmp
= gen_lea(s
, insn
, OS_LONG
);
1105 if (IS_NULL_QREG(tmp
)) {
1109 addr
= tcg_temp_new();
1110 tcg_gen_mov_i32(addr
, tmp
);
1111 is_load
= ((insn
& 0x0400) != 0);
1112 for (i
= 0; i
< 16; i
++, mask
>>= 1) {
1119 tmp
= gen_load(s
, OS_LONG
, addr
, 0);
1120 tcg_gen_mov_i32(reg
, tmp
);
1122 gen_store(s
, OS_LONG
, addr
, reg
);
1125 tcg_gen_addi_i32(addr
, addr
, 4);
1130 DISAS_INSN(bitop_im
)
1140 if ((insn
& 0x38) != 0)
1144 op
= (insn
>> 6) & 3;
1146 bitnum
= lduw_code(s
->pc
);
1148 if (bitnum
& 0xff00) {
1149 disas_undef(s
, insn
);
1153 SRC_EA(src1
, opsize
, 0, op
? &addr
: NULL
);
1156 if (opsize
== OS_BYTE
)
1162 tmp
= tcg_temp_new();
1163 assert (CCF_Z
== (1 << 2));
1165 tcg_gen_shri_i32(tmp
, src1
, bitnum
- 2);
1166 else if (bitnum
< 2)
1167 tcg_gen_shli_i32(tmp
, src1
, 2 - bitnum
);
1169 tcg_gen_mov_i32(tmp
, src1
);
1170 tcg_gen_andi_i32(tmp
, tmp
, CCF_Z
);
1171 /* Clear CCF_Z if bit set. */
1172 tcg_gen_ori_i32(QREG_CC_DEST
, QREG_CC_DEST
, CCF_Z
);
1173 tcg_gen_xor_i32(QREG_CC_DEST
, QREG_CC_DEST
, tmp
);
1177 tcg_gen_xori_i32(tmp
, src1
, mask
);
1180 tcg_gen_andi_i32(tmp
, src1
, ~mask
);
1183 tcg_gen_ori_i32(tmp
, src1
, mask
);
1188 DEST_EA(insn
, opsize
, tmp
, &addr
);
1192 DISAS_INSN(arith_im
)
1200 op
= (insn
>> 9) & 7;
1201 SRC_EA(src1
, OS_LONG
, 0, (op
== 6) ? NULL
: &addr
);
1203 dest
= tcg_temp_new();
1206 tcg_gen_ori_i32(dest
, src1
, im
);
1207 gen_logic_cc(s
, dest
);
1210 tcg_gen_andi_i32(dest
, src1
, im
);
1211 gen_logic_cc(s
, dest
);
1214 tcg_gen_mov_i32(dest
, src1
);
1215 gen_helper_xflag_lt(QREG_CC_X
, dest
, gen_im32(im
));
1216 tcg_gen_subi_i32(dest
, dest
, im
);
1217 gen_update_cc_add(dest
, gen_im32(im
));
1218 s
->cc_op
= CC_OP_SUB
;
1221 tcg_gen_mov_i32(dest
, src1
);
1222 tcg_gen_addi_i32(dest
, dest
, im
);
1223 gen_update_cc_add(dest
, gen_im32(im
));
1224 gen_helper_xflag_lt(QREG_CC_X
, dest
, gen_im32(im
));
1225 s
->cc_op
= CC_OP_ADD
;
1228 tcg_gen_xori_i32(dest
, src1
, im
);
1229 gen_logic_cc(s
, dest
);
1232 tcg_gen_mov_i32(dest
, src1
);
1233 tcg_gen_subi_i32(dest
, dest
, im
);
1234 gen_update_cc_add(dest
, gen_im32(im
));
1235 s
->cc_op
= CC_OP_SUB
;
1241 DEST_EA(insn
, OS_LONG
, dest
, &addr
);
1249 reg
= DREG(insn
, 0);
1250 tcg_gen_bswap32_i32(reg
, reg
);
1260 switch (insn
>> 12) {
1261 case 1: /* move.b */
1264 case 2: /* move.l */
1267 case 3: /* move.w */
1273 SRC_EA(src
, opsize
, 1, NULL
);
1274 op
= (insn
>> 6) & 7;
1277 /* The value will already have been sign extended. */
1278 dest
= AREG(insn
, 9);
1279 tcg_gen_mov_i32(dest
, src
);
1283 dest_ea
= ((insn
>> 9) & 7) | (op
<< 3);
1284 DEST_EA(dest_ea
, opsize
, src
, NULL
);
1285 /* This will be correct because loads sign extend. */
1286 gen_logic_cc(s
, src
);
1295 reg
= DREG(insn
, 0);
1296 gen_helper_subx_cc(reg
, cpu_env
, tcg_const_i32(0), reg
);
1304 reg
= AREG(insn
, 9);
1305 tmp
= gen_lea(s
, insn
, OS_LONG
);
1306 if (IS_NULL_QREG(tmp
)) {
1310 tcg_gen_mov_i32(reg
, tmp
);
1317 switch ((insn
>> 6) & 3) {
1330 DEST_EA(insn
, opsize
, gen_im32(0), NULL
);
1331 gen_logic_cc(s
, gen_im32(0));
1334 static TCGv
gen_get_ccr(DisasContext
*s
)
1339 dest
= tcg_temp_new();
1340 tcg_gen_shli_i32(dest
, QREG_CC_X
, 4);
1341 tcg_gen_or_i32(dest
, dest
, QREG_CC_DEST
);
1345 DISAS_INSN(move_from_ccr
)
1350 ccr
= gen_get_ccr(s
);
1351 reg
= DREG(insn
, 0);
1352 gen_partset_reg(OS_WORD
, reg
, ccr
);
1360 reg
= DREG(insn
, 0);
1361 src1
= tcg_temp_new();
1362 tcg_gen_mov_i32(src1
, reg
);
1363 tcg_gen_neg_i32(reg
, src1
);
1364 s
->cc_op
= CC_OP_SUB
;
1365 gen_update_cc_add(reg
, src1
);
1366 gen_helper_xflag_lt(QREG_CC_X
, tcg_const_i32(0), src1
);
1367 s
->cc_op
= CC_OP_SUB
;
1370 static void gen_set_sr_im(DisasContext
*s
, uint16_t val
, int ccr_only
)
1372 tcg_gen_movi_i32(QREG_CC_DEST
, val
& 0xf);
1373 tcg_gen_movi_i32(QREG_CC_X
, (val
& 0x10) >> 4);
1375 gen_helper_set_sr(cpu_env
, tcg_const_i32(val
& 0xff00));
1379 static void gen_set_sr(DisasContext
*s
, uint16_t insn
, int ccr_only
)
1384 s
->cc_op
= CC_OP_FLAGS
;
1385 if ((insn
& 0x38) == 0)
1387 tmp
= tcg_temp_new();
1388 reg
= DREG(insn
, 0);
1389 tcg_gen_andi_i32(QREG_CC_DEST
, reg
, 0xf);
1390 tcg_gen_shri_i32(tmp
, reg
, 4);
1391 tcg_gen_andi_i32(QREG_CC_X
, tmp
, 1);
1393 gen_helper_set_sr(cpu_env
, reg
);
1396 else if ((insn
& 0x3f) == 0x3c)
1399 val
= lduw_code(s
->pc
);
1401 gen_set_sr_im(s
, val
, ccr_only
);
1404 disas_undef(s
, insn
);
1407 DISAS_INSN(move_to_ccr
)
1409 gen_set_sr(s
, insn
, 1);
1416 reg
= DREG(insn
, 0);
1417 tcg_gen_not_i32(reg
, reg
);
1418 gen_logic_cc(s
, reg
);
1427 src1
= tcg_temp_new();
1428 src2
= tcg_temp_new();
1429 reg
= DREG(insn
, 0);
1430 tcg_gen_shli_i32(src1
, reg
, 16);
1431 tcg_gen_shri_i32(src2
, reg
, 16);
1432 tcg_gen_or_i32(reg
, src1
, src2
);
1433 gen_logic_cc(s
, reg
);
1440 tmp
= gen_lea(s
, insn
, OS_LONG
);
1441 if (IS_NULL_QREG(tmp
)) {
1454 reg
= DREG(insn
, 0);
1455 op
= (insn
>> 6) & 7;
1456 tmp
= tcg_temp_new();
1458 tcg_gen_ext16s_i32(tmp
, reg
);
1460 tcg_gen_ext8s_i32(tmp
, reg
);
1462 gen_partset_reg(OS_WORD
, reg
, tmp
);
1464 tcg_gen_mov_i32(reg
, tmp
);
1465 gen_logic_cc(s
, tmp
);
1473 switch ((insn
>> 6) & 3) {
1486 SRC_EA(tmp
, opsize
, 1, NULL
);
1487 gen_logic_cc(s
, tmp
);
1492 /* Implemented as a NOP. */
1497 gen_exception(s
, s
->pc
- 2, EXCP_ILLEGAL
);
1500 /* ??? This should be atomic. */
1507 dest
= tcg_temp_new();
1508 SRC_EA(src1
, OS_BYTE
, 1, &addr
);
1509 gen_logic_cc(s
, src1
);
1510 tcg_gen_ori_i32(dest
, src1
, 0x80);
1511 DEST_EA(insn
, OS_BYTE
, dest
, &addr
);
1521 /* The upper 32 bits of the product are discarded, so
1522 muls.l and mulu.l are functionally equivalent. */
1523 ext
= lduw_code(s
->pc
);
1526 gen_exception(s
, s
->pc
- 4, EXCP_UNSUPPORTED
);
1529 reg
= DREG(ext
, 12);
1530 SRC_EA(src1
, OS_LONG
, 0, NULL
);
1531 dest
= tcg_temp_new();
1532 tcg_gen_mul_i32(dest
, src1
, reg
);
1533 tcg_gen_mov_i32(reg
, dest
);
1534 /* Unlike m68k, coldfire always clears the overflow bit. */
1535 gen_logic_cc(s
, dest
);
1544 offset
= ldsw_code(s
->pc
);
1546 reg
= AREG(insn
, 0);
1547 tmp
= tcg_temp_new();
1548 tcg_gen_subi_i32(tmp
, QREG_SP
, 4);
1549 gen_store(s
, OS_LONG
, tmp
, reg
);
1550 if ((insn
& 7) != 7)
1551 tcg_gen_mov_i32(reg
, tmp
);
1552 tcg_gen_addi_i32(QREG_SP
, tmp
, offset
);
1561 src
= tcg_temp_new();
1562 reg
= AREG(insn
, 0);
1563 tcg_gen_mov_i32(src
, reg
);
1564 tmp
= gen_load(s
, OS_LONG
, src
, 0);
1565 tcg_gen_mov_i32(reg
, tmp
);
1566 tcg_gen_addi_i32(QREG_SP
, src
, 4);
1577 tmp
= gen_load(s
, OS_LONG
, QREG_SP
, 0);
1578 tcg_gen_addi_i32(QREG_SP
, QREG_SP
, 4);
1586 /* Load the target address first to ensure correct exception
1588 tmp
= gen_lea(s
, insn
, OS_LONG
);
1589 if (IS_NULL_QREG(tmp
)) {
1593 if ((insn
& 0x40) == 0) {
1595 gen_push(s
, gen_im32(s
->pc
));
1608 SRC_EA(src1
, OS_LONG
, 0, &addr
);
1609 val
= (insn
>> 9) & 7;
1612 dest
= tcg_temp_new();
1613 tcg_gen_mov_i32(dest
, src1
);
1614 if ((insn
& 0x38) == 0x08) {
1615 /* Don't update condition codes if the destination is an
1616 address register. */
1617 if (insn
& 0x0100) {
1618 tcg_gen_subi_i32(dest
, dest
, val
);
1620 tcg_gen_addi_i32(dest
, dest
, val
);
1623 src2
= gen_im32(val
);
1624 if (insn
& 0x0100) {
1625 gen_helper_xflag_lt(QREG_CC_X
, dest
, src2
);
1626 tcg_gen_subi_i32(dest
, dest
, val
);
1627 s
->cc_op
= CC_OP_SUB
;
1629 tcg_gen_addi_i32(dest
, dest
, val
);
1630 gen_helper_xflag_lt(QREG_CC_X
, dest
, src2
);
1631 s
->cc_op
= CC_OP_ADD
;
1633 gen_update_cc_add(dest
, src2
);
1635 DEST_EA(insn
, OS_LONG
, dest
, &addr
);
1641 case 2: /* One extension word. */
1644 case 3: /* Two extension words. */
1647 case 4: /* No extension words. */
1650 disas_undef(s
, insn
);
1662 op
= (insn
>> 8) & 0xf;
1663 offset
= (int8_t)insn
;
1665 offset
= ldsw_code(s
->pc
);
1667 } else if (offset
== -1) {
1668 offset
= read_im32(s
);
1672 gen_push(s
, gen_im32(s
->pc
));
1677 l1
= gen_new_label();
1678 gen_jmpcc(s
, ((insn
>> 8) & 0xf) ^ 1, l1
);
1679 gen_jmp_tb(s
, 1, base
+ offset
);
1681 gen_jmp_tb(s
, 0, s
->pc
);
1683 /* Unconditional branch. */
1684 gen_jmp_tb(s
, 0, base
+ offset
);
1693 tcg_gen_movi_i32(DREG(insn
, 9), val
);
1694 gen_logic_cc(s
, tcg_const_i32(val
));
1707 SRC_EA(src
, opsize
, (insn
& 0x80) == 0, NULL
);
1708 reg
= DREG(insn
, 9);
1709 tcg_gen_mov_i32(reg
, src
);
1710 gen_logic_cc(s
, src
);
1720 reg
= DREG(insn
, 9);
1721 dest
= tcg_temp_new();
1723 SRC_EA(src
, OS_LONG
, 0, &addr
);
1724 tcg_gen_or_i32(dest
, src
, reg
);
1725 DEST_EA(insn
, OS_LONG
, dest
, &addr
);
1727 SRC_EA(src
, OS_LONG
, 0, NULL
);
1728 tcg_gen_or_i32(dest
, src
, reg
);
1729 tcg_gen_mov_i32(reg
, dest
);
1731 gen_logic_cc(s
, dest
);
1739 SRC_EA(src
, OS_LONG
, 0, NULL
);
1740 reg
= AREG(insn
, 9);
1741 tcg_gen_sub_i32(reg
, reg
, src
);
1750 reg
= DREG(insn
, 9);
1751 src
= DREG(insn
, 0);
1752 gen_helper_subx_cc(reg
, cpu_env
, reg
, src
);
1760 val
= (insn
>> 9) & 7;
1763 src
= gen_im32(val
);
1764 gen_logic_cc(s
, src
);
1765 DEST_EA(insn
, OS_LONG
, src
, NULL
);
1776 op
= (insn
>> 6) & 3;
1780 s
->cc_op
= CC_OP_CMPB
;
1784 s
->cc_op
= CC_OP_CMPW
;
1788 s
->cc_op
= CC_OP_SUB
;
1793 SRC_EA(src
, opsize
, 1, NULL
);
1794 reg
= DREG(insn
, 9);
1795 dest
= tcg_temp_new();
1796 tcg_gen_sub_i32(dest
, reg
, src
);
1797 gen_update_cc_add(dest
, src
);
1812 SRC_EA(src
, opsize
, 1, NULL
);
1813 reg
= AREG(insn
, 9);
1814 dest
= tcg_temp_new();
1815 tcg_gen_sub_i32(dest
, reg
, src
);
1816 gen_update_cc_add(dest
, src
);
1817 s
->cc_op
= CC_OP_SUB
;
1827 SRC_EA(src
, OS_LONG
, 0, &addr
);
1828 reg
= DREG(insn
, 9);
1829 dest
= tcg_temp_new();
1830 tcg_gen_xor_i32(dest
, src
, reg
);
1831 gen_logic_cc(s
, dest
);
1832 DEST_EA(insn
, OS_LONG
, dest
, &addr
);
1842 reg
= DREG(insn
, 9);
1843 dest
= tcg_temp_new();
1845 SRC_EA(src
, OS_LONG
, 0, &addr
);
1846 tcg_gen_and_i32(dest
, src
, reg
);
1847 DEST_EA(insn
, OS_LONG
, dest
, &addr
);
1849 SRC_EA(src
, OS_LONG
, 0, NULL
);
1850 tcg_gen_and_i32(dest
, src
, reg
);
1851 tcg_gen_mov_i32(reg
, dest
);
1853 gen_logic_cc(s
, dest
);
1861 SRC_EA(src
, OS_LONG
, 0, NULL
);
1862 reg
= AREG(insn
, 9);
1863 tcg_gen_add_i32(reg
, reg
, src
);
1872 reg
= DREG(insn
, 9);
1873 src
= DREG(insn
, 0);
1874 gen_helper_addx_cc(reg
, cpu_env
, reg
, src
);
1875 s
->cc_op
= CC_OP_FLAGS
;
1878 /* TODO: This could be implemented without helper functions. */
1879 DISAS_INSN(shift_im
)
1885 reg
= DREG(insn
, 0);
1886 tmp
= (insn
>> 9) & 7;
1889 shift
= gen_im32(tmp
);
1890 /* No need to flush flags becuse we know we will set C flag. */
1892 gen_helper_shl_cc(reg
, cpu_env
, reg
, shift
);
1895 gen_helper_shr_cc(reg
, cpu_env
, reg
, shift
);
1897 gen_helper_sar_cc(reg
, cpu_env
, reg
, shift
);
1900 s
->cc_op
= CC_OP_SHIFT
;
1903 DISAS_INSN(shift_reg
)
1908 reg
= DREG(insn
, 0);
1909 shift
= DREG(insn
, 9);
1910 /* Shift by zero leaves C flag unmodified. */
1913 gen_helper_shl_cc(reg
, cpu_env
, reg
, shift
);
1916 gen_helper_shr_cc(reg
, cpu_env
, reg
, shift
);
1918 gen_helper_sar_cc(reg
, cpu_env
, reg
, shift
);
1921 s
->cc_op
= CC_OP_SHIFT
;
1927 reg
= DREG(insn
, 0);
1928 gen_logic_cc(s
, reg
);
1929 gen_helper_ff1(reg
, reg
);
1932 static TCGv
gen_get_sr(DisasContext
*s
)
1937 ccr
= gen_get_ccr(s
);
1938 sr
= tcg_temp_new();
1939 tcg_gen_andi_i32(sr
, QREG_SR
, 0xffe0);
1940 tcg_gen_or_i32(sr
, sr
, ccr
);
1950 ext
= lduw_code(s
->pc
);
1952 if (ext
!= 0x46FC) {
1953 gen_exception(s
, addr
, EXCP_UNSUPPORTED
);
1956 ext
= lduw_code(s
->pc
);
1958 if (IS_USER(s
) || (ext
& SR_S
) == 0) {
1959 gen_exception(s
, addr
, EXCP_PRIVILEGE
);
1962 gen_push(s
, gen_get_sr(s
));
1963 gen_set_sr_im(s
, ext
, 0);
1966 DISAS_INSN(move_from_sr
)
1972 gen_exception(s
, s
->pc
- 2, EXCP_PRIVILEGE
);
1976 reg
= DREG(insn
, 0);
1977 gen_partset_reg(OS_WORD
, reg
, sr
);
1980 DISAS_INSN(move_to_sr
)
1983 gen_exception(s
, s
->pc
- 2, EXCP_PRIVILEGE
);
1986 gen_set_sr(s
, insn
, 0);
1990 DISAS_INSN(move_from_usp
)
1993 gen_exception(s
, s
->pc
- 2, EXCP_PRIVILEGE
);
1996 /* TODO: Implement USP. */
1997 gen_exception(s
, s
->pc
- 2, EXCP_ILLEGAL
);
2000 DISAS_INSN(move_to_usp
)
2003 gen_exception(s
, s
->pc
- 2, EXCP_PRIVILEGE
);
2006 /* TODO: Implement USP. */
2007 gen_exception(s
, s
->pc
- 2, EXCP_ILLEGAL
);
2012 gen_exception(s
, s
->pc
, EXCP_HALT_INSN
);
2020 gen_exception(s
, s
->pc
- 2, EXCP_PRIVILEGE
);
2024 ext
= lduw_code(s
->pc
);
2027 gen_set_sr_im(s
, ext
, 0);
2028 tcg_gen_movi_i32(QREG_HALTED
, 1);
2029 gen_exception(s
, s
->pc
, EXCP_HLT
);
2035 gen_exception(s
, s
->pc
- 2, EXCP_PRIVILEGE
);
2038 gen_exception(s
, s
->pc
- 2, EXCP_RTE
);
2047 gen_exception(s
, s
->pc
- 2, EXCP_PRIVILEGE
);
2051 ext
= lduw_code(s
->pc
);
2055 reg
= AREG(ext
, 12);
2057 reg
= DREG(ext
, 12);
2059 gen_helper_movec(cpu_env
, tcg_const_i32(ext
& 0xfff), reg
);
2066 gen_exception(s
, s
->pc
- 2, EXCP_PRIVILEGE
);
2069 /* ICache fetch. Implement as no-op. */
2075 gen_exception(s
, s
->pc
- 2, EXCP_PRIVILEGE
);
2078 /* Cache push/invalidate. Implement as no-op. */
2083 gen_exception(s
, s
->pc
- 2, EXCP_PRIVILEGE
);
2089 gen_exception(s
, s
->pc
- 2, EXCP_PRIVILEGE
);
2092 /* TODO: Implement wdebug. */
2093 qemu_assert(0, "WDEBUG not implemented");
2098 gen_exception(s
, s
->pc
- 2, EXCP_TRAP0
+ (insn
& 0xf));
2101 /* ??? FP exceptions are not implemented. Most exceptions are deferred until
2102 immediately before the next FP instruction is executed. */
2116 ext
= lduw_code(s
->pc
);
2118 opmode
= ext
& 0x7f;
2119 switch ((ext
>> 13) & 7) {
2124 case 3: /* fmove out */
2126 tmp32
= tcg_temp_new_i32();
2128 /* ??? TODO: Proper behavior on overflow. */
2129 switch ((ext
>> 10) & 7) {
2132 gen_helper_f64_to_i32(tmp32
, cpu_env
, src
);
2136 gen_helper_f64_to_f32(tmp32
, cpu_env
, src
);
2140 gen_helper_f64_to_i32(tmp32
, cpu_env
, src
);
2142 case 5: /* OS_DOUBLE */
2143 tcg_gen_mov_i32(tmp32
, AREG(insn
, 0));
2144 switch ((insn
>> 3) & 7) {
2149 tcg_gen_addi_i32(tmp32
, tmp32
, -8);
2152 offset
= ldsw_code(s
->pc
);
2154 tcg_gen_addi_i32(tmp32
, tmp32
, offset
);
2159 gen_store64(s
, tmp32
, src
);
2160 switch ((insn
>> 3) & 7) {
2162 tcg_gen_addi_i32(tmp32
, tmp32
, 8);
2163 tcg_gen_mov_i32(AREG(insn
, 0), tmp32
);
2166 tcg_gen_mov_i32(AREG(insn
, 0), tmp32
);
2169 tcg_temp_free_i32(tmp32
);
2173 gen_helper_f64_to_i32(tmp32
, cpu_env
, src
);
2178 DEST_EA(insn
, opsize
, tmp32
, NULL
);
2179 tcg_temp_free_i32(tmp32
);
2181 case 4: /* fmove to control register. */
2182 switch ((ext
>> 10) & 7) {
2184 /* Not implemented. Ignore writes. */
2189 cpu_abort(NULL
, "Unimplemented: fmove to control %d",
2193 case 5: /* fmove from control register. */
2194 switch ((ext
>> 10) & 7) {
2196 /* Not implemented. Always return zero. */
2197 tmp32
= gen_im32(0);
2202 cpu_abort(NULL
, "Unimplemented: fmove from control %d",
2206 DEST_EA(insn
, OS_LONG
, tmp32
, NULL
);
2208 case 6: /* fmovem */
2214 if ((ext
& 0x1f00) != 0x1000 || (ext
& 0xff) == 0)
2216 tmp32
= gen_lea(s
, insn
, OS_LONG
);
2217 if (IS_NULL_QREG(tmp32
)) {
2221 addr
= tcg_temp_new_i32();
2222 tcg_gen_mov_i32(addr
, tmp32
);
2224 for (i
= 0; i
< 8; i
++) {
2228 if (ext
& (1 << 13)) {
2230 tcg_gen_qemu_stf64(dest
, addr
, IS_USER(s
));
2233 tcg_gen_qemu_ldf64(dest
, addr
, IS_USER(s
));
2235 if (ext
& (mask
- 1))
2236 tcg_gen_addi_i32(addr
, addr
, 8);
2240 tcg_temp_free_i32(addr
);
2244 if (ext
& (1 << 14)) {
2245 /* Source effective address. */
2246 switch ((ext
>> 10) & 7) {
2247 case 0: opsize
= OS_LONG
; break;
2248 case 1: opsize
= OS_SINGLE
; break;
2249 case 4: opsize
= OS_WORD
; break;
2250 case 5: opsize
= OS_DOUBLE
; break;
2251 case 6: opsize
= OS_BYTE
; break;
2255 if (opsize
== OS_DOUBLE
) {
2256 tmp32
= tcg_temp_new_i32();
2257 tcg_gen_mov_i32(tmp32
, AREG(insn
, 0));
2258 switch ((insn
>> 3) & 7) {
2263 tcg_gen_addi_i32(tmp32
, tmp32
, -8);
2266 offset
= ldsw_code(s
->pc
);
2268 tcg_gen_addi_i32(tmp32
, tmp32
, offset
);
2271 offset
= ldsw_code(s
->pc
);
2272 offset
+= s
->pc
- 2;
2274 tcg_gen_addi_i32(tmp32
, tmp32
, offset
);
2279 src
= gen_load64(s
, tmp32
);
2280 switch ((insn
>> 3) & 7) {
2282 tcg_gen_addi_i32(tmp32
, tmp32
, 8);
2283 tcg_gen_mov_i32(AREG(insn
, 0), tmp32
);
2286 tcg_gen_mov_i32(AREG(insn
, 0), tmp32
);
2289 tcg_temp_free_i32(tmp32
);
2291 SRC_EA(tmp32
, opsize
, 1, NULL
);
2292 src
= tcg_temp_new_i64();
2297 gen_helper_i32_to_f64(src
, cpu_env
, tmp32
);
2300 gen_helper_f32_to_f64(src
, cpu_env
, tmp32
);
2305 /* Source register. */
2306 src
= FREG(ext
, 10);
2308 dest
= FREG(ext
, 7);
2309 res
= tcg_temp_new_i64();
2311 tcg_gen_mov_f64(res
, dest
);
2315 case 0: case 0x40: case 0x44: /* fmove */
2316 tcg_gen_mov_f64(res
, src
);
2319 gen_helper_iround_f64(res
, cpu_env
, src
);
2322 case 3: /* fintrz */
2323 gen_helper_itrunc_f64(res
, cpu_env
, src
);
2326 case 4: case 0x41: case 0x45: /* fsqrt */
2327 gen_helper_sqrt_f64(res
, cpu_env
, src
);
2329 case 0x18: case 0x58: case 0x5c: /* fabs */
2330 gen_helper_abs_f64(res
, src
);
2332 case 0x1a: case 0x5a: case 0x5e: /* fneg */
2333 gen_helper_chs_f64(res
, src
);
2335 case 0x20: case 0x60: case 0x64: /* fdiv */
2336 gen_helper_div_f64(res
, cpu_env
, res
, src
);
2338 case 0x22: case 0x62: case 0x66: /* fadd */
2339 gen_helper_add_f64(res
, cpu_env
, res
, src
);
2341 case 0x23: case 0x63: case 0x67: /* fmul */
2342 gen_helper_mul_f64(res
, cpu_env
, res
, src
);
2344 case 0x28: case 0x68: case 0x6c: /* fsub */
2345 gen_helper_sub_f64(res
, cpu_env
, res
, src
);
2347 case 0x38: /* fcmp */
2348 gen_helper_sub_cmp_f64(res
, cpu_env
, res
, src
);
2352 case 0x3a: /* ftst */
2353 tcg_gen_mov_f64(res
, src
);
2360 if (ext
& (1 << 14)) {
2361 tcg_temp_free_i64(src
);
2364 if (opmode
& 0x40) {
2365 if ((opmode
& 0x4) != 0)
2367 } else if ((s
->fpcr
& M68K_FPCR_PREC
) == 0) {
2372 TCGv tmp
= tcg_temp_new_i32();
2373 gen_helper_f64_to_f32(tmp
, cpu_env
, res
);
2374 gen_helper_f32_to_f64(res
, cpu_env
, tmp
);
2375 tcg_temp_free_i32(tmp
);
2377 tcg_gen_mov_f64(QREG_FP_RESULT
, res
);
2379 tcg_gen_mov_f64(dest
, res
);
2381 tcg_temp_free_i64(res
);
2384 /* FIXME: Is this right for offset addressing modes? */
2386 disas_undef_fpu(s
, insn
);
2397 offset
= ldsw_code(s
->pc
);
2399 if (insn
& (1 << 6)) {
2400 offset
= (offset
<< 16) | lduw_code(s
->pc
);
2404 l1
= gen_new_label();
2405 /* TODO: Raise BSUN exception. */
2406 flag
= tcg_temp_new();
2407 gen_helper_compare_f64(flag
, cpu_env
, QREG_FP_RESULT
);
2408 /* Jump to l1 if condition is true. */
2409 switch (insn
& 0xf) {
2412 case 1: /* eq (=0) */
2413 tcg_gen_brcond_i32(TCG_COND_EQ
, flag
, tcg_const_i32(0), l1
);
2415 case 2: /* ogt (=1) */
2416 tcg_gen_brcond_i32(TCG_COND_EQ
, flag
, tcg_const_i32(1), l1
);
2418 case 3: /* oge (=0 or =1) */
2419 tcg_gen_brcond_i32(TCG_COND_LEU
, flag
, tcg_const_i32(1), l1
);
2421 case 4: /* olt (=-1) */
2422 tcg_gen_brcond_i32(TCG_COND_LT
, flag
, tcg_const_i32(0), l1
);
2424 case 5: /* ole (=-1 or =0) */
2425 tcg_gen_brcond_i32(TCG_COND_LE
, flag
, tcg_const_i32(0), l1
);
2427 case 6: /* ogl (=-1 or =1) */
2428 tcg_gen_andi_i32(flag
, flag
, 1);
2429 tcg_gen_brcond_i32(TCG_COND_NE
, flag
, tcg_const_i32(0), l1
);
2431 case 7: /* or (=2) */
2432 tcg_gen_brcond_i32(TCG_COND_EQ
, flag
, tcg_const_i32(2), l1
);
2434 case 8: /* un (<2) */
2435 tcg_gen_brcond_i32(TCG_COND_LT
, flag
, tcg_const_i32(2), l1
);
2437 case 9: /* ueq (=0 or =2) */
2438 tcg_gen_andi_i32(flag
, flag
, 1);
2439 tcg_gen_brcond_i32(TCG_COND_EQ
, flag
, tcg_const_i32(0), l1
);
2441 case 10: /* ugt (>0) */
2442 tcg_gen_brcond_i32(TCG_COND_GT
, flag
, tcg_const_i32(0), l1
);
2444 case 11: /* uge (>=0) */
2445 tcg_gen_brcond_i32(TCG_COND_GE
, flag
, tcg_const_i32(0), l1
);
2447 case 12: /* ult (=-1 or =2) */
2448 tcg_gen_brcond_i32(TCG_COND_GEU
, flag
, tcg_const_i32(2), l1
);
2450 case 13: /* ule (!=1) */
2451 tcg_gen_brcond_i32(TCG_COND_NE
, flag
, tcg_const_i32(1), l1
);
2453 case 14: /* ne (!=0) */
2454 tcg_gen_brcond_i32(TCG_COND_NE
, flag
, tcg_const_i32(0), l1
);
2460 gen_jmp_tb(s
, 0, s
->pc
);
2462 gen_jmp_tb(s
, 1, addr
+ offset
);
2465 DISAS_INSN(frestore
)
2467 /* TODO: Implement frestore. */
2468 qemu_assert(0, "FRESTORE not implemented");
2473 /* TODO: Implement fsave. */
2474 qemu_assert(0, "FSAVE not implemented");
2477 static inline TCGv
gen_mac_extract_word(DisasContext
*s
, TCGv val
, int upper
)
2479 TCGv tmp
= tcg_temp_new();
2480 if (s
->env
->macsr
& MACSR_FI
) {
2482 tcg_gen_andi_i32(tmp
, val
, 0xffff0000);
2484 tcg_gen_shli_i32(tmp
, val
, 16);
2485 } else if (s
->env
->macsr
& MACSR_SU
) {
2487 tcg_gen_sari_i32(tmp
, val
, 16);
2489 tcg_gen_ext16s_i32(tmp
, val
);
2492 tcg_gen_shri_i32(tmp
, val
, 16);
2494 tcg_gen_ext16u_i32(tmp
, val
);
2499 static void gen_mac_clear_flags(void)
2501 tcg_gen_andi_i32(QREG_MACSR
, QREG_MACSR
,
2502 ~(MACSR_V
| MACSR_Z
| MACSR_N
| MACSR_EV
));
2518 s
->mactmp
= tcg_temp_new_i64();
2522 ext
= lduw_code(s
->pc
);
2525 acc
= ((insn
>> 7) & 1) | ((ext
>> 3) & 2);
2526 dual
= ((insn
& 0x30) != 0 && (ext
& 3) != 0);
2527 if (dual
&& !m68k_feature(s
->env
, M68K_FEATURE_CF_EMAC_B
)) {
2528 disas_undef(s
, insn
);
2532 /* MAC with load. */
2533 tmp
= gen_lea(s
, insn
, OS_LONG
);
2534 addr
= tcg_temp_new();
2535 tcg_gen_and_i32(addr
, tmp
, QREG_MAC_MASK
);
2536 /* Load the value now to ensure correct exception behavior.
2537 Perform writeback after reading the MAC inputs. */
2538 loadval
= gen_load(s
, OS_LONG
, addr
, 0);
2541 rx
= (ext
& 0x8000) ? AREG(ext
, 12) : DREG(insn
, 12);
2542 ry
= (ext
& 8) ? AREG(ext
, 0) : DREG(ext
, 0);
2544 loadval
= addr
= NULL_QREG
;
2545 rx
= (insn
& 0x40) ? AREG(insn
, 9) : DREG(insn
, 9);
2546 ry
= (insn
& 8) ? AREG(insn
, 0) : DREG(insn
, 0);
2549 gen_mac_clear_flags();
2552 /* Disabled because conditional branches clobber temporary vars. */
2553 if ((s
->env
->macsr
& MACSR_OMC
) != 0 && !dual
) {
2554 /* Skip the multiply if we know we will ignore it. */
2555 l1
= gen_new_label();
2556 tmp
= tcg_temp_new();
2557 tcg_gen_andi_i32(tmp
, QREG_MACSR
, 1 << (acc
+ 8));
2558 gen_op_jmp_nz32(tmp
, l1
);
2562 if ((ext
& 0x0800) == 0) {
2564 rx
= gen_mac_extract_word(s
, rx
, (ext
& 0x80) != 0);
2565 ry
= gen_mac_extract_word(s
, ry
, (ext
& 0x40) != 0);
2567 if (s
->env
->macsr
& MACSR_FI
) {
2568 gen_helper_macmulf(s
->mactmp
, cpu_env
, rx
, ry
);
2570 if (s
->env
->macsr
& MACSR_SU
)
2571 gen_helper_macmuls(s
->mactmp
, cpu_env
, rx
, ry
);
2573 gen_helper_macmulu(s
->mactmp
, cpu_env
, rx
, ry
);
2574 switch ((ext
>> 9) & 3) {
2576 tcg_gen_shli_i64(s
->mactmp
, s
->mactmp
, 1);
2579 tcg_gen_shri_i64(s
->mactmp
, s
->mactmp
, 1);
2585 /* Save the overflow flag from the multiply. */
2586 saved_flags
= tcg_temp_new();
2587 tcg_gen_mov_i32(saved_flags
, QREG_MACSR
);
2589 saved_flags
= NULL_QREG
;
2593 /* Disabled because conditional branches clobber temporary vars. */
2594 if ((s
->env
->macsr
& MACSR_OMC
) != 0 && dual
) {
2595 /* Skip the accumulate if the value is already saturated. */
2596 l1
= gen_new_label();
2597 tmp
= tcg_temp_new();
2598 gen_op_and32(tmp
, QREG_MACSR
, gen_im32(MACSR_PAV0
<< acc
));
2599 gen_op_jmp_nz32(tmp
, l1
);
2604 tcg_gen_sub_i64(MACREG(acc
), MACREG(acc
), s
->mactmp
);
2606 tcg_gen_add_i64(MACREG(acc
), MACREG(acc
), s
->mactmp
);
2608 if (s
->env
->macsr
& MACSR_FI
)
2609 gen_helper_macsatf(cpu_env
, tcg_const_i32(acc
));
2610 else if (s
->env
->macsr
& MACSR_SU
)
2611 gen_helper_macsats(cpu_env
, tcg_const_i32(acc
));
2613 gen_helper_macsatu(cpu_env
, tcg_const_i32(acc
));
2616 /* Disabled because conditional branches clobber temporary vars. */
2622 /* Dual accumulate variant. */
2623 acc
= (ext
>> 2) & 3;
2624 /* Restore the overflow flag from the multiplier. */
2625 tcg_gen_mov_i32(QREG_MACSR
, saved_flags
);
2627 /* Disabled because conditional branches clobber temporary vars. */
2628 if ((s
->env
->macsr
& MACSR_OMC
) != 0) {
2629 /* Skip the accumulate if the value is already saturated. */
2630 l1
= gen_new_label();
2631 tmp
= tcg_temp_new();
2632 gen_op_and32(tmp
, QREG_MACSR
, gen_im32(MACSR_PAV0
<< acc
));
2633 gen_op_jmp_nz32(tmp
, l1
);
2637 tcg_gen_sub_i64(MACREG(acc
), MACREG(acc
), s
->mactmp
);
2639 tcg_gen_add_i64(MACREG(acc
), MACREG(acc
), s
->mactmp
);
2640 if (s
->env
->macsr
& MACSR_FI
)
2641 gen_helper_macsatf(cpu_env
, tcg_const_i32(acc
));
2642 else if (s
->env
->macsr
& MACSR_SU
)
2643 gen_helper_macsats(cpu_env
, tcg_const_i32(acc
));
2645 gen_helper_macsatu(cpu_env
, tcg_const_i32(acc
));
2647 /* Disabled because conditional branches clobber temporary vars. */
2652 gen_helper_mac_set_flags(cpu_env
, tcg_const_i32(acc
));
2656 rw
= (insn
& 0x40) ? AREG(insn
, 9) : DREG(insn
, 9);
2657 tcg_gen_mov_i32(rw
, loadval
);
2658 /* FIXME: Should address writeback happen with the masked or
2660 switch ((insn
>> 3) & 7) {
2661 case 3: /* Post-increment. */
2662 tcg_gen_addi_i32(AREG(insn
, 0), addr
, 4);
2664 case 4: /* Pre-decrement. */
2665 tcg_gen_mov_i32(AREG(insn
, 0), addr
);
2670 DISAS_INSN(from_mac
)
2676 rx
= (insn
& 8) ? AREG(insn
, 0) : DREG(insn
, 0);
2677 accnum
= (insn
>> 9) & 3;
2678 acc
= MACREG(accnum
);
2679 if (s
->env
->macsr
& MACSR_FI
) {
2680 gen_helper_get_macf(rx
, cpu_env
, acc
);
2681 } else if ((s
->env
->macsr
& MACSR_OMC
) == 0) {
2682 tcg_gen_trunc_i64_i32(rx
, acc
);
2683 } else if (s
->env
->macsr
& MACSR_SU
) {
2684 gen_helper_get_macs(rx
, acc
);
2686 gen_helper_get_macu(rx
, acc
);
2689 tcg_gen_movi_i64(acc
, 0);
2690 tcg_gen_andi_i32(QREG_MACSR
, QREG_MACSR
, ~(MACSR_PAV0
<< accnum
));
2694 DISAS_INSN(move_mac
)
2696 /* FIXME: This can be done without a helper. */
2700 dest
= tcg_const_i32((insn
>> 9) & 3);
2701 gen_helper_mac_move(cpu_env
, dest
, tcg_const_i32(src
));
2702 gen_mac_clear_flags();
2703 gen_helper_mac_set_flags(cpu_env
, dest
);
2706 DISAS_INSN(from_macsr
)
2710 reg
= (insn
& 8) ? AREG(insn
, 0) : DREG(insn
, 0);
2711 tcg_gen_mov_i32(reg
, QREG_MACSR
);
2714 DISAS_INSN(from_mask
)
2717 reg
= (insn
& 8) ? AREG(insn
, 0) : DREG(insn
, 0);
2718 tcg_gen_mov_i32(reg
, QREG_MAC_MASK
);
2721 DISAS_INSN(from_mext
)
2725 reg
= (insn
& 8) ? AREG(insn
, 0) : DREG(insn
, 0);
2726 acc
= tcg_const_i32((insn
& 0x400) ? 2 : 0);
2727 if (s
->env
->macsr
& MACSR_FI
)
2728 gen_helper_get_mac_extf(reg
, cpu_env
, acc
);
2730 gen_helper_get_mac_exti(reg
, cpu_env
, acc
);
2733 DISAS_INSN(macsr_to_ccr
)
2735 tcg_gen_movi_i32(QREG_CC_X
, 0);
2736 tcg_gen_andi_i32(QREG_CC_DEST
, QREG_MACSR
, 0xf);
2737 s
->cc_op
= CC_OP_FLAGS
;
2745 accnum
= (insn
>> 9) & 3;
2746 acc
= MACREG(accnum
);
2747 SRC_EA(val
, OS_LONG
, 0, NULL
);
2748 if (s
->env
->macsr
& MACSR_FI
) {
2749 tcg_gen_ext_i32_i64(acc
, val
);
2750 tcg_gen_shli_i64(acc
, acc
, 8);
2751 } else if (s
->env
->macsr
& MACSR_SU
) {
2752 tcg_gen_ext_i32_i64(acc
, val
);
2754 tcg_gen_extu_i32_i64(acc
, val
);
2756 tcg_gen_andi_i32(QREG_MACSR
, QREG_MACSR
, ~(MACSR_PAV0
<< accnum
));
2757 gen_mac_clear_flags();
2758 gen_helper_mac_set_flags(cpu_env
, tcg_const_i32(accnum
));
2761 DISAS_INSN(to_macsr
)
2764 SRC_EA(val
, OS_LONG
, 0, NULL
);
2765 gen_helper_set_macsr(cpu_env
, val
);
2772 SRC_EA(val
, OS_LONG
, 0, NULL
);
2773 tcg_gen_ori_i32(QREG_MAC_MASK
, val
, 0xffff0000);
2780 SRC_EA(val
, OS_LONG
, 0, NULL
);
2781 acc
= tcg_const_i32((insn
& 0x400) ? 2 : 0);
2782 if (s
->env
->macsr
& MACSR_FI
)
2783 gen_helper_set_mac_extf(cpu_env
, val
, acc
);
2784 else if (s
->env
->macsr
& MACSR_SU
)
2785 gen_helper_set_mac_exts(cpu_env
, val
, acc
);
2787 gen_helper_set_mac_extu(cpu_env
, val
, acc
);
2790 static disas_proc opcode_table
[65536];
2793 register_opcode (disas_proc proc
, uint16_t opcode
, uint16_t mask
)
2799 /* Sanity check. All set bits must be included in the mask. */
2800 if (opcode
& ~mask
) {
2802 "qemu internal error: bogus opcode definition %04x/%04x\n",
2806 /* This could probably be cleverer. For now just optimize the case where
2807 the top bits are known. */
2808 /* Find the first zero bit in the mask. */
2810 while ((i
& mask
) != 0)
2812 /* Iterate over all combinations of this and lower bits. */
2817 from
= opcode
& ~(i
- 1);
2819 for (i
= from
; i
< to
; i
++) {
2820 if ((i
& mask
) == opcode
)
2821 opcode_table
[i
] = proc
;
2825 /* Register m68k opcode handlers. Order is important.
2826 Later insn override earlier ones. */
2827 void register_m68k_insns (CPUM68KState
*env
)
2829 #define INSN(name, opcode, mask, feature) do { \
2830 if (m68k_feature(env, M68K_FEATURE_##feature)) \
2831 register_opcode(disas_##name, 0x##opcode, 0x##mask); \
2833 INSN(undef
, 0000, 0000, CF_ISA_A
);
2834 INSN(arith_im
, 0080, fff8
, CF_ISA_A
);
2835 INSN(bitrev
, 00c0
, fff8
, CF_ISA_APLUSC
);
2836 INSN(bitop_reg
, 0100, f1c0
, CF_ISA_A
);
2837 INSN(bitop_reg
, 0140, f1c0
, CF_ISA_A
);
2838 INSN(bitop_reg
, 0180, f1c0
, CF_ISA_A
);
2839 INSN(bitop_reg
, 01c0
, f1c0
, CF_ISA_A
);
2840 INSN(arith_im
, 0280, fff8
, CF_ISA_A
);
2841 INSN(byterev
, 02c0
, fff8
, CF_ISA_APLUSC
);
2842 INSN(arith_im
, 0480, fff8
, CF_ISA_A
);
2843 INSN(ff1
, 04c0
, fff8
, CF_ISA_APLUSC
);
2844 INSN(arith_im
, 0680, fff8
, CF_ISA_A
);
2845 INSN(bitop_im
, 0800, ffc0
, CF_ISA_A
);
2846 INSN(bitop_im
, 0840, ffc0
, CF_ISA_A
);
2847 INSN(bitop_im
, 0880, ffc0
, CF_ISA_A
);
2848 INSN(bitop_im
, 08c0
, ffc0
, CF_ISA_A
);
2849 INSN(arith_im
, 0a80
, fff8
, CF_ISA_A
);
2850 INSN(arith_im
, 0c00
, ff38
, CF_ISA_A
);
2851 INSN(move
, 1000, f000
, CF_ISA_A
);
2852 INSN(move
, 2000, f000
, CF_ISA_A
);
2853 INSN(move
, 3000, f000
, CF_ISA_A
);
2854 INSN(strldsr
, 40e7
, ffff
, CF_ISA_APLUSC
);
2855 INSN(negx
, 4080, fff8
, CF_ISA_A
);
2856 INSN(move_from_sr
, 40c0
, fff8
, CF_ISA_A
);
2857 INSN(lea
, 41c0
, f1c0
, CF_ISA_A
);
2858 INSN(clr
, 4200, ff00
, CF_ISA_A
);
2859 INSN(undef
, 42c0
, ffc0
, CF_ISA_A
);
2860 INSN(move_from_ccr
, 42c0
, fff8
, CF_ISA_A
);
2861 INSN(neg
, 4480, fff8
, CF_ISA_A
);
2862 INSN(move_to_ccr
, 44c0
, ffc0
, CF_ISA_A
);
2863 INSN(not, 4680, fff8
, CF_ISA_A
);
2864 INSN(move_to_sr
, 46c0
, ffc0
, CF_ISA_A
);
2865 INSN(pea
, 4840, ffc0
, CF_ISA_A
);
2866 INSN(swap
, 4840, fff8
, CF_ISA_A
);
2867 INSN(movem
, 48c0
, fbc0
, CF_ISA_A
);
2868 INSN(ext
, 4880, fff8
, CF_ISA_A
);
2869 INSN(ext
, 48c0
, fff8
, CF_ISA_A
);
2870 INSN(ext
, 49c0
, fff8
, CF_ISA_A
);
2871 INSN(tst
, 4a00
, ff00
, CF_ISA_A
);
2872 INSN(tas
, 4ac0
, ffc0
, CF_ISA_B
);
2873 INSN(halt
, 4ac8
, ffff
, CF_ISA_A
);
2874 INSN(pulse
, 4acc
, ffff
, CF_ISA_A
);
2875 INSN(illegal
, 4afc
, ffff
, CF_ISA_A
);
2876 INSN(mull
, 4c00
, ffc0
, CF_ISA_A
);
2877 INSN(divl
, 4c40
, ffc0
, CF_ISA_A
);
2878 INSN(sats
, 4c80
, fff8
, CF_ISA_B
);
2879 INSN(trap
, 4e40
, fff0
, CF_ISA_A
);
2880 INSN(link
, 4e50
, fff8
, CF_ISA_A
);
2881 INSN(unlk
, 4e58
, fff8
, CF_ISA_A
);
2882 INSN(move_to_usp
, 4e60
, fff8
, USP
);
2883 INSN(move_from_usp
, 4e68
, fff8
, USP
);
2884 INSN(nop
, 4e71
, ffff
, CF_ISA_A
);
2885 INSN(stop
, 4e72
, ffff
, CF_ISA_A
);
2886 INSN(rte
, 4e73
, ffff
, CF_ISA_A
);
2887 INSN(rts
, 4e75
, ffff
, CF_ISA_A
);
2888 INSN(movec
, 4e7b
, ffff
, CF_ISA_A
);
2889 INSN(jump
, 4e80
, ffc0
, CF_ISA_A
);
2890 INSN(jump
, 4ec0
, ffc0
, CF_ISA_A
);
2891 INSN(addsubq
, 5180, f1c0
, CF_ISA_A
);
2892 INSN(scc
, 50c0
, f0f8
, CF_ISA_A
);
2893 INSN(addsubq
, 5080, f1c0
, CF_ISA_A
);
2894 INSN(tpf
, 51f8
, fff8
, CF_ISA_A
);
2896 /* Branch instructions. */
2897 INSN(branch
, 6000, f000
, CF_ISA_A
);
2898 /* Disable long branch instructions, then add back the ones we want. */
2899 INSN(undef
, 60ff
, f0ff
, CF_ISA_A
); /* All long branches. */
2900 INSN(branch
, 60ff
, f0ff
, CF_ISA_B
);
2901 INSN(undef
, 60ff
, ffff
, CF_ISA_B
); /* bra.l */
2902 INSN(branch
, 60ff
, ffff
, BRAL
);
2904 INSN(moveq
, 7000, f100
, CF_ISA_A
);
2905 INSN(mvzs
, 7100, f100
, CF_ISA_B
);
2906 INSN(or, 8000, f000
, CF_ISA_A
);
2907 INSN(divw
, 80c0
, f0c0
, CF_ISA_A
);
2908 INSN(addsub
, 9000, f000
, CF_ISA_A
);
2909 INSN(subx
, 9180, f1f8
, CF_ISA_A
);
2910 INSN(suba
, 91c0
, f1c0
, CF_ISA_A
);
2912 INSN(undef_mac
, a000
, f000
, CF_ISA_A
);
2913 INSN(mac
, a000
, f100
, CF_EMAC
);
2914 INSN(from_mac
, a180
, f9b0
, CF_EMAC
);
2915 INSN(move_mac
, a110
, f9fc
, CF_EMAC
);
2916 INSN(from_macsr
,a980
, f9f0
, CF_EMAC
);
2917 INSN(from_mask
, ad80
, fff0
, CF_EMAC
);
2918 INSN(from_mext
, ab80
, fbf0
, CF_EMAC
);
2919 INSN(macsr_to_ccr
, a9c0
, ffff
, CF_EMAC
);
2920 INSN(to_mac
, a100
, f9c0
, CF_EMAC
);
2921 INSN(to_macsr
, a900
, ffc0
, CF_EMAC
);
2922 INSN(to_mext
, ab00
, fbc0
, CF_EMAC
);
2923 INSN(to_mask
, ad00
, ffc0
, CF_EMAC
);
2925 INSN(mov3q
, a140
, f1c0
, CF_ISA_B
);
2926 INSN(cmp
, b000
, f1c0
, CF_ISA_B
); /* cmp.b */
2927 INSN(cmp
, b040
, f1c0
, CF_ISA_B
); /* cmp.w */
2928 INSN(cmpa
, b0c0
, f1c0
, CF_ISA_B
); /* cmpa.w */
2929 INSN(cmp
, b080
, f1c0
, CF_ISA_A
);
2930 INSN(cmpa
, b1c0
, f1c0
, CF_ISA_A
);
2931 INSN(eor
, b180
, f1c0
, CF_ISA_A
);
2932 INSN(and, c000
, f000
, CF_ISA_A
);
2933 INSN(mulw
, c0c0
, f0c0
, CF_ISA_A
);
2934 INSN(addsub
, d000
, f000
, CF_ISA_A
);
2935 INSN(addx
, d180
, f1f8
, CF_ISA_A
);
2936 INSN(adda
, d1c0
, f1c0
, CF_ISA_A
);
2937 INSN(shift_im
, e080
, f0f0
, CF_ISA_A
);
2938 INSN(shift_reg
, e0a0
, f0f0
, CF_ISA_A
);
2939 INSN(undef_fpu
, f000
, f000
, CF_ISA_A
);
2940 INSN(fpu
, f200
, ffc0
, CF_FPU
);
2941 INSN(fbcc
, f280
, ffc0
, CF_FPU
);
2942 INSN(frestore
, f340
, ffc0
, CF_FPU
);
2943 INSN(fsave
, f340
, ffc0
, CF_FPU
);
2944 INSN(intouch
, f340
, ffc0
, CF_ISA_A
);
2945 INSN(cpushl
, f428
, ff38
, CF_ISA_A
);
2946 INSN(wddata
, fb00
, ff00
, CF_ISA_A
);
2947 INSN(wdebug
, fbc0
, ffc0
, CF_ISA_A
);
2951 /* ??? Some of this implementation is not exception safe. We should always
2952 write back the result to memory before setting the condition codes. */
2953 static void disas_m68k_insn(CPUState
* env
, DisasContext
*s
)
2957 insn
= lduw_code(s
->pc
);
2960 opcode_table
[insn
](s
, insn
);
2963 /* generate intermediate code for basic block 'tb'. */
2965 gen_intermediate_code_internal(CPUState
*env
, TranslationBlock
*tb
,
2968 DisasContext dc1
, *dc
= &dc1
;
2969 uint16_t *gen_opc_end
;
2972 target_ulong pc_start
;
2978 /* generate intermediate code */
2983 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
2986 dc
->is_jmp
= DISAS_NEXT
;
2988 dc
->cc_op
= CC_OP_DYNAMIC
;
2989 dc
->singlestep_enabled
= env
->singlestep_enabled
;
2990 dc
->fpcr
= env
->fpcr
;
2991 dc
->user
= (env
->sr
& SR_S
) == 0;
2996 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
2998 max_insns
= CF_COUNT_MASK
;
3002 pc_offset
= dc
->pc
- pc_start
;
3003 gen_throws_exception
= NULL
;
3004 if (unlikely(!TAILQ_EMPTY(&env
->breakpoints
))) {
3005 TAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
3006 if (bp
->pc
== dc
->pc
) {
3007 gen_exception(dc
, dc
->pc
, EXCP_DEBUG
);
3008 dc
->is_jmp
= DISAS_JUMP
;
3016 j
= gen_opc_ptr
- gen_opc_buf
;
3020 gen_opc_instr_start
[lj
++] = 0;
3022 gen_opc_pc
[lj
] = dc
->pc
;
3023 gen_opc_instr_start
[lj
] = 1;
3024 gen_opc_icount
[lj
] = num_insns
;
3026 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
3028 last_cc_op
= dc
->cc_op
;
3029 dc
->insn_pc
= dc
->pc
;
3030 disas_m68k_insn(env
, dc
);
3032 } while (!dc
->is_jmp
&& gen_opc_ptr
< gen_opc_end
&&
3033 !env
->singlestep_enabled
&&
3034 (pc_offset
) < (TARGET_PAGE_SIZE
- 32) &&
3035 num_insns
< max_insns
);
3037 if (tb
->cflags
& CF_LAST_IO
)
3039 if (unlikely(env
->singlestep_enabled
)) {
3040 /* Make sure the pc is updated, and raise a debug exception. */
3042 gen_flush_cc_op(dc
);
3043 tcg_gen_movi_i32(QREG_PC
, dc
->pc
);
3045 gen_helper_raise_exception(tcg_const_i32(EXCP_DEBUG
));
3047 switch(dc
->is_jmp
) {
3049 gen_flush_cc_op(dc
);
3050 gen_jmp_tb(dc
, 0, dc
->pc
);
3055 gen_flush_cc_op(dc
);
3056 /* indicate that the hash table must be used to find the next TB */
3060 /* nothing more to generate */
3064 gen_icount_end(tb
, num_insns
);
3065 *gen_opc_ptr
= INDEX_op_end
;
3068 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
3069 qemu_log("----------------\n");
3070 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
3071 log_target_disas(pc_start
, dc
->pc
- pc_start
, 0);
3076 j
= gen_opc_ptr
- gen_opc_buf
;
3079 gen_opc_instr_start
[lj
++] = 0;
3081 tb
->size
= dc
->pc
- pc_start
;
3082 tb
->icount
= num_insns
;
3086 //expand_target_qops();
3089 void gen_intermediate_code(CPUState
*env
, TranslationBlock
*tb
)
3091 gen_intermediate_code_internal(env
, tb
, 0);
3094 void gen_intermediate_code_pc(CPUState
*env
, TranslationBlock
*tb
)
3096 gen_intermediate_code_internal(env
, tb
, 1);
3099 void cpu_dump_state(CPUState
*env
, FILE *f
,
3100 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
3106 for (i
= 0; i
< 8; i
++)
3108 u
.d
= env
->fregs
[i
];
3109 cpu_fprintf (f
, "D%d = %08x A%d = %08x F%d = %08x%08x (%12g)\n",
3110 i
, env
->dregs
[i
], i
, env
->aregs
[i
],
3111 i
, u
.l
.upper
, u
.l
.lower
, *(double *)&u
.d
);
3113 cpu_fprintf (f
, "PC = %08x ", env
->pc
);
3115 cpu_fprintf (f
, "SR = %04x %c%c%c%c%c ", sr
, (sr
& 0x10) ? 'X' : '-',
3116 (sr
& CCF_N
) ? 'N' : '-', (sr
& CCF_Z
) ? 'Z' : '-',
3117 (sr
& CCF_V
) ? 'V' : '-', (sr
& CCF_C
) ? 'C' : '-');
3118 cpu_fprintf (f
, "FPRESULT = %12g\n", *(double *)&env
->fp_result
);
3121 void gen_pc_load(CPUState
*env
, TranslationBlock
*tb
,
3122 unsigned long searched_pc
, int pc_pos
, void *puc
)
3124 env
->pc
= gen_opc_pc
[pc_pos
];