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.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
21 #include "qemu/osdep.h"
23 #include "disas/disas.h"
24 #include "exec/exec-all.h"
25 #include "tcg/tcg-op.h"
27 #include "qemu/qemu-print.h"
28 #include "exec/cpu_ldst.h"
29 #include "exec/translator.h"
31 #include "exec/helper-proto.h"
32 #include "exec/helper-gen.h"
35 #include "fpu/softfloat.h"
37 #define HELPER_H "helper.h"
38 #include "exec/helper-info.c.inc"
41 //#define DEBUG_DISPATCH 1
43 #define DEFO32(name, offset) static TCGv QREG_##name;
44 #define DEFO64(name, offset) static TCGv_i64 QREG_##name;
45 #include "qregs.h.inc"
49 static TCGv_i32 cpu_halted
;
50 static TCGv_i32 cpu_exception_index
;
52 static char cpu_reg_names
[2 * 8 * 3 + 5 * 4];
53 static TCGv cpu_dregs
[8];
54 static TCGv cpu_aregs
[8];
55 static TCGv_i64 cpu_macc
[4];
57 #define REG(insn, pos) (((insn) >> (pos)) & 7)
58 #define DREG(insn, pos) cpu_dregs[REG(insn, pos)]
59 #define AREG(insn, pos) get_areg(s, REG(insn, pos))
60 #define MACREG(acc) cpu_macc[acc]
61 #define QREG_SP get_areg(s, 7)
63 static TCGv NULL_QREG
;
64 #define IS_NULL_QREG(t) (t == NULL_QREG)
65 /* Used to distinguish stores from bad addressing modes. */
66 static TCGv store_dummy
;
68 void m68k_tcg_init(void)
73 #define DEFO32(name, offset) \
74 QREG_##name = tcg_global_mem_new_i32(cpu_env, \
75 offsetof(CPUM68KState, offset), #name);
76 #define DEFO64(name, offset) \
77 QREG_##name = tcg_global_mem_new_i64(cpu_env, \
78 offsetof(CPUM68KState, offset), #name);
79 #include "qregs.h.inc"
83 cpu_halted
= tcg_global_mem_new_i32(cpu_env
,
84 -offsetof(M68kCPU
, env
) +
85 offsetof(CPUState
, halted
), "HALTED");
86 cpu_exception_index
= tcg_global_mem_new_i32(cpu_env
,
87 -offsetof(M68kCPU
, env
) +
88 offsetof(CPUState
, exception_index
),
92 for (i
= 0; i
< 8; i
++) {
94 cpu_dregs
[i
] = tcg_global_mem_new(cpu_env
,
95 offsetof(CPUM68KState
, dregs
[i
]), p
);
98 cpu_aregs
[i
] = tcg_global_mem_new(cpu_env
,
99 offsetof(CPUM68KState
, aregs
[i
]), p
);
102 for (i
= 0; i
< 4; i
++) {
103 sprintf(p
, "ACC%d", i
);
104 cpu_macc
[i
] = tcg_global_mem_new_i64(cpu_env
,
105 offsetof(CPUM68KState
, macc
[i
]), p
);
109 NULL_QREG
= tcg_global_mem_new(cpu_env
, -4, "NULL");
110 store_dummy
= tcg_global_mem_new(cpu_env
, -8, "NULL");
113 /* internal defines */
114 typedef struct DisasContext
{
115 DisasContextBase base
;
118 target_ulong pc_prev
;
119 CCOp cc_op
; /* Current CC operation */
128 static TCGv
get_areg(DisasContext
*s
, unsigned regno
)
130 if (s
->writeback_mask
& (1 << regno
)) {
131 return s
->writeback
[regno
];
133 return cpu_aregs
[regno
];
137 static void delay_set_areg(DisasContext
*s
, unsigned regno
,
138 TCGv val
, bool give_temp
)
140 if (s
->writeback_mask
& (1 << regno
)) {
142 s
->writeback
[regno
] = val
;
144 tcg_gen_mov_i32(s
->writeback
[regno
], val
);
147 s
->writeback_mask
|= 1 << regno
;
149 s
->writeback
[regno
] = val
;
151 TCGv tmp
= tcg_temp_new();
152 s
->writeback
[regno
] = tmp
;
153 tcg_gen_mov_i32(tmp
, val
);
158 static void do_writebacks(DisasContext
*s
)
160 unsigned mask
= s
->writeback_mask
;
162 s
->writeback_mask
= 0;
164 unsigned regno
= ctz32(mask
);
165 tcg_gen_mov_i32(cpu_aregs
[regno
], s
->writeback
[regno
]);
171 /* is_jmp field values */
172 #define DISAS_JUMP DISAS_TARGET_0 /* only pc was modified dynamically */
173 #define DISAS_EXIT DISAS_TARGET_1 /* cpu state was modified dynamically */
175 #if defined(CONFIG_USER_ONLY)
178 #define IS_USER(s) (!(s->base.tb->flags & TB_FLAGS_MSR_S))
179 #define SFC_INDEX(s) ((s->base.tb->flags & TB_FLAGS_SFC_S) ? \
180 MMU_KERNEL_IDX : MMU_USER_IDX)
181 #define DFC_INDEX(s) ((s->base.tb->flags & TB_FLAGS_DFC_S) ? \
182 MMU_KERNEL_IDX : MMU_USER_IDX)
185 typedef void (*disas_proc
)(CPUM68KState
*env
, DisasContext
*s
, uint16_t insn
);
187 #ifdef DEBUG_DISPATCH
188 #define DISAS_INSN(name) \
189 static void real_disas_##name(CPUM68KState *env, DisasContext *s, \
191 static void disas_##name(CPUM68KState *env, DisasContext *s, \
194 qemu_log("Dispatch " #name "\n"); \
195 real_disas_##name(env, s, insn); \
197 static void real_disas_##name(CPUM68KState *env, DisasContext *s, \
200 #define DISAS_INSN(name) \
201 static void disas_##name(CPUM68KState *env, DisasContext *s, \
205 static const uint8_t cc_op_live
[CC_OP_NB
] = {
206 [CC_OP_DYNAMIC
] = CCF_C
| CCF_V
| CCF_Z
| CCF_N
| CCF_X
,
207 [CC_OP_FLAGS
] = CCF_C
| CCF_V
| CCF_Z
| CCF_N
| CCF_X
,
208 [CC_OP_ADDB
... CC_OP_ADDL
] = CCF_X
| CCF_N
| CCF_V
,
209 [CC_OP_SUBB
... CC_OP_SUBL
] = CCF_X
| CCF_N
| CCF_V
,
210 [CC_OP_CMPB
... CC_OP_CMPL
] = CCF_X
| CCF_N
| CCF_V
,
211 [CC_OP_LOGIC
] = CCF_X
| CCF_N
214 static void set_cc_op(DisasContext
*s
, CCOp op
)
216 CCOp old_op
= s
->cc_op
;
226 * Discard CC computation that will no longer be used.
227 * Note that X and N are never dead.
229 dead
= cc_op_live
[old_op
] & ~cc_op_live
[op
];
231 tcg_gen_discard_i32(QREG_CC_C
);
234 tcg_gen_discard_i32(QREG_CC_Z
);
237 tcg_gen_discard_i32(QREG_CC_V
);
241 /* Update the CPU env CC_OP state. */
242 static void update_cc_op(DisasContext
*s
)
244 if (!s
->cc_op_synced
) {
246 tcg_gen_movi_i32(QREG_CC_OP
, s
->cc_op
);
250 /* Generate a jump to an immediate address. */
251 static void gen_jmp_im(DisasContext
*s
, uint32_t dest
)
254 tcg_gen_movi_i32(QREG_PC
, dest
);
255 s
->base
.is_jmp
= DISAS_JUMP
;
258 /* Generate a jump to the address in qreg DEST. */
259 static void gen_jmp(DisasContext
*s
, TCGv dest
)
262 tcg_gen_mov_i32(QREG_PC
, dest
);
263 s
->base
.is_jmp
= DISAS_JUMP
;
266 static void gen_raise_exception(int nr
)
268 gen_helper_raise_exception(cpu_env
, tcg_constant_i32(nr
));
271 static void gen_raise_exception_format2(DisasContext
*s
, int nr
,
272 target_ulong this_pc
)
275 * Pass the address of the insn to the exception handler,
276 * for recording in the Format $2 (6-word) stack frame.
277 * Re-use mmu.ar for the purpose, since that's only valid
280 tcg_gen_st_i32(tcg_constant_i32(this_pc
), cpu_env
,
281 offsetof(CPUM68KState
, mmu
.ar
));
282 gen_raise_exception(nr
);
283 s
->base
.is_jmp
= DISAS_NORETURN
;
286 static void gen_exception(DisasContext
*s
, uint32_t dest
, int nr
)
289 tcg_gen_movi_i32(QREG_PC
, dest
);
291 gen_raise_exception(nr
);
293 s
->base
.is_jmp
= DISAS_NORETURN
;
296 static inline void gen_addr_fault(DisasContext
*s
)
298 gen_exception(s
, s
->base
.pc_next
, EXCP_ADDRESS
);
302 * Generate a load from the specified address. Narrow values are
303 * sign extended to full register width.
305 static inline TCGv
gen_load(DisasContext
*s
, int opsize
, TCGv addr
,
308 TCGv tmp
= tcg_temp_new_i32();
314 tcg_gen_qemu_ld_tl(tmp
, addr
, index
,
315 opsize
| (sign
? MO_SIGN
: 0) | MO_TE
);
318 g_assert_not_reached();
323 /* Generate a store. */
324 static inline void gen_store(DisasContext
*s
, int opsize
, TCGv addr
, TCGv val
,
331 tcg_gen_qemu_st_tl(val
, addr
, index
, opsize
| MO_TE
);
334 g_assert_not_reached();
345 * Generate an unsigned load if VAL is 0 a signed load if val is -1,
346 * otherwise generate a store.
348 static TCGv
gen_ldst(DisasContext
*s
, int opsize
, TCGv addr
, TCGv val
,
349 ea_what what
, int index
)
351 if (what
== EA_STORE
) {
352 gen_store(s
, opsize
, addr
, val
, index
);
355 return gen_load(s
, opsize
, addr
, what
== EA_LOADS
, index
);
359 /* Read a 16-bit immediate constant */
360 static inline uint16_t read_im16(CPUM68KState
*env
, DisasContext
*s
)
363 im
= translator_lduw(env
, &s
->base
, s
->pc
);
368 /* Read an 8-bit immediate constant */
369 static inline uint8_t read_im8(CPUM68KState
*env
, DisasContext
*s
)
371 return read_im16(env
, s
);
374 /* Read a 32-bit immediate constant. */
375 static inline uint32_t read_im32(CPUM68KState
*env
, DisasContext
*s
)
378 im
= read_im16(env
, s
) << 16;
379 im
|= 0xffff & read_im16(env
, s
);
383 /* Read a 64-bit immediate constant. */
384 static inline uint64_t read_im64(CPUM68KState
*env
, DisasContext
*s
)
387 im
= (uint64_t)read_im32(env
, s
) << 32;
388 im
|= (uint64_t)read_im32(env
, s
);
392 /* Calculate and address index. */
393 static TCGv
gen_addr_index(DisasContext
*s
, uint16_t ext
, TCGv tmp
)
398 add
= (ext
& 0x8000) ? AREG(ext
, 12) : DREG(ext
, 12);
399 if ((ext
& 0x800) == 0) {
400 tcg_gen_ext16s_i32(tmp
, add
);
403 scale
= (ext
>> 9) & 3;
405 tcg_gen_shli_i32(tmp
, add
, scale
);
412 * Handle a base + index + displacement effective address.
413 * A NULL_QREG base means pc-relative.
415 static TCGv
gen_lea_indexed(CPUM68KState
*env
, DisasContext
*s
, TCGv base
)
424 ext
= read_im16(env
, s
);
426 if ((ext
& 0x800) == 0 && !m68k_feature(s
->env
, M68K_FEATURE_WORD_INDEX
))
429 if (m68k_feature(s
->env
, M68K_FEATURE_M68K
) &&
430 !m68k_feature(s
->env
, M68K_FEATURE_SCALED_INDEX
)) {
435 /* full extension word format */
436 if (!m68k_feature(s
->env
, M68K_FEATURE_EXT_FULL
))
439 if ((ext
& 0x30) > 0x10) {
440 /* base displacement */
441 if ((ext
& 0x30) == 0x20) {
442 bd
= (int16_t)read_im16(env
, s
);
444 bd
= read_im32(env
, s
);
449 tmp
= tcg_temp_new();
450 if ((ext
& 0x44) == 0) {
452 add
= gen_addr_index(s
, ext
, tmp
);
456 if ((ext
& 0x80) == 0) {
457 /* base not suppressed */
458 if (IS_NULL_QREG(base
)) {
459 base
= tcg_constant_i32(offset
+ bd
);
462 if (!IS_NULL_QREG(add
)) {
463 tcg_gen_add_i32(tmp
, add
, base
);
469 if (!IS_NULL_QREG(add
)) {
471 tcg_gen_addi_i32(tmp
, add
, bd
);
475 add
= tcg_constant_i32(bd
);
477 if ((ext
& 3) != 0) {
478 /* memory indirect */
479 base
= gen_load(s
, OS_LONG
, add
, 0, IS_USER(s
));
480 if ((ext
& 0x44) == 4) {
481 add
= gen_addr_index(s
, ext
, tmp
);
482 tcg_gen_add_i32(tmp
, add
, base
);
488 /* outer displacement */
489 if ((ext
& 3) == 2) {
490 od
= (int16_t)read_im16(env
, s
);
492 od
= read_im32(env
, s
);
498 tcg_gen_addi_i32(tmp
, add
, od
);
503 /* brief extension word format */
504 tmp
= tcg_temp_new();
505 add
= gen_addr_index(s
, ext
, tmp
);
506 if (!IS_NULL_QREG(base
)) {
507 tcg_gen_add_i32(tmp
, add
, base
);
509 tcg_gen_addi_i32(tmp
, tmp
, (int8_t)ext
);
511 tcg_gen_addi_i32(tmp
, add
, offset
+ (int8_t)ext
);
518 /* Sign or zero extend a value. */
520 static inline void gen_ext(TCGv res
, TCGv val
, int opsize
, int sign
)
525 tcg_gen_ext8s_i32(res
, val
);
527 tcg_gen_ext8u_i32(res
, val
);
532 tcg_gen_ext16s_i32(res
, val
);
534 tcg_gen_ext16u_i32(res
, val
);
538 tcg_gen_mov_i32(res
, val
);
541 g_assert_not_reached();
545 /* Evaluate all the CC flags. */
547 static void gen_flush_flags(DisasContext
*s
)
558 tcg_gen_mov_i32(QREG_CC_C
, QREG_CC_X
);
559 tcg_gen_mov_i32(QREG_CC_Z
, QREG_CC_N
);
560 /* Compute signed overflow for addition. */
563 tcg_gen_sub_i32(t0
, QREG_CC_N
, QREG_CC_V
);
564 gen_ext(t0
, t0
, s
->cc_op
- CC_OP_ADDB
, 1);
565 tcg_gen_xor_i32(t1
, QREG_CC_N
, QREG_CC_V
);
566 tcg_gen_xor_i32(QREG_CC_V
, QREG_CC_V
, t0
);
567 tcg_gen_andc_i32(QREG_CC_V
, t1
, QREG_CC_V
);
573 tcg_gen_mov_i32(QREG_CC_C
, QREG_CC_X
);
574 tcg_gen_mov_i32(QREG_CC_Z
, QREG_CC_N
);
575 /* Compute signed overflow for subtraction. */
578 tcg_gen_add_i32(t0
, QREG_CC_N
, QREG_CC_V
);
579 gen_ext(t0
, t0
, s
->cc_op
- CC_OP_SUBB
, 1);
580 tcg_gen_xor_i32(t1
, QREG_CC_N
, t0
);
581 tcg_gen_xor_i32(QREG_CC_V
, QREG_CC_V
, t0
);
582 tcg_gen_and_i32(QREG_CC_V
, QREG_CC_V
, t1
);
588 tcg_gen_setcond_i32(TCG_COND_LTU
, QREG_CC_C
, QREG_CC_N
, QREG_CC_V
);
589 tcg_gen_sub_i32(QREG_CC_Z
, QREG_CC_N
, QREG_CC_V
);
590 gen_ext(QREG_CC_Z
, QREG_CC_Z
, s
->cc_op
- CC_OP_CMPB
, 1);
591 /* Compute signed overflow for subtraction. */
593 tcg_gen_xor_i32(t0
, QREG_CC_Z
, QREG_CC_N
);
594 tcg_gen_xor_i32(QREG_CC_V
, QREG_CC_V
, QREG_CC_N
);
595 tcg_gen_and_i32(QREG_CC_V
, QREG_CC_V
, t0
);
596 tcg_gen_mov_i32(QREG_CC_N
, QREG_CC_Z
);
600 tcg_gen_mov_i32(QREG_CC_Z
, QREG_CC_N
);
601 tcg_gen_movi_i32(QREG_CC_C
, 0);
602 tcg_gen_movi_i32(QREG_CC_V
, 0);
606 gen_helper_flush_flags(cpu_env
, QREG_CC_OP
);
611 gen_helper_flush_flags(cpu_env
, tcg_constant_i32(s
->cc_op
));
616 /* Note that flush_flags also assigned to env->cc_op. */
617 s
->cc_op
= CC_OP_FLAGS
;
620 static inline TCGv
gen_extend(DisasContext
*s
, TCGv val
, int opsize
, int sign
)
624 if (opsize
== OS_LONG
) {
627 tmp
= tcg_temp_new();
628 gen_ext(tmp
, val
, opsize
, sign
);
634 static void gen_logic_cc(DisasContext
*s
, TCGv val
, int opsize
)
636 gen_ext(QREG_CC_N
, val
, opsize
, 1);
637 set_cc_op(s
, CC_OP_LOGIC
);
640 static void gen_update_cc_cmp(DisasContext
*s
, TCGv dest
, TCGv src
, int opsize
)
642 tcg_gen_mov_i32(QREG_CC_N
, dest
);
643 tcg_gen_mov_i32(QREG_CC_V
, src
);
644 set_cc_op(s
, CC_OP_CMPB
+ opsize
);
647 static void gen_update_cc_add(TCGv dest
, TCGv src
, int opsize
)
649 gen_ext(QREG_CC_N
, dest
, opsize
, 1);
650 tcg_gen_mov_i32(QREG_CC_V
, src
);
653 static inline int opsize_bytes(int opsize
)
656 case OS_BYTE
: return 1;
657 case OS_WORD
: return 2;
658 case OS_LONG
: return 4;
659 case OS_SINGLE
: return 4;
660 case OS_DOUBLE
: return 8;
661 case OS_EXTENDED
: return 12;
662 case OS_PACKED
: return 12;
664 g_assert_not_reached();
668 static inline int insn_opsize(int insn
)
670 switch ((insn
>> 6) & 3) {
671 case 0: return OS_BYTE
;
672 case 1: return OS_WORD
;
673 case 2: return OS_LONG
;
675 g_assert_not_reached();
679 static inline int ext_opsize(int ext
, int pos
)
681 switch ((ext
>> pos
) & 7) {
682 case 0: return OS_LONG
;
683 case 1: return OS_SINGLE
;
684 case 2: return OS_EXTENDED
;
685 case 3: return OS_PACKED
;
686 case 4: return OS_WORD
;
687 case 5: return OS_DOUBLE
;
688 case 6: return OS_BYTE
;
690 g_assert_not_reached();
695 * Assign value to a register. If the width is less than the register width
696 * only the low part of the register is set.
698 static void gen_partset_reg(int opsize
, TCGv reg
, TCGv val
)
702 tcg_gen_deposit_i32(reg
, reg
, val
, 0, 8);
705 tcg_gen_deposit_i32(reg
, reg
, val
, 0, 16);
709 tcg_gen_mov_i32(reg
, val
);
712 g_assert_not_reached();
717 * Generate code for an "effective address". Does not adjust the base
718 * register for autoincrement addressing modes.
720 static TCGv
gen_lea_mode(CPUM68KState
*env
, DisasContext
*s
,
721 int mode
, int reg0
, int opsize
)
729 case 0: /* Data register direct. */
730 case 1: /* Address register direct. */
732 case 3: /* Indirect postincrement. */
733 if (opsize
== OS_UNSIZED
) {
737 case 2: /* Indirect register */
738 return get_areg(s
, reg0
);
739 case 4: /* Indirect predecrememnt. */
740 if (opsize
== OS_UNSIZED
) {
743 reg
= get_areg(s
, reg0
);
744 tmp
= tcg_temp_new();
745 if (reg0
== 7 && opsize
== OS_BYTE
&&
746 m68k_feature(s
->env
, M68K_FEATURE_M68K
)) {
747 tcg_gen_subi_i32(tmp
, reg
, 2);
749 tcg_gen_subi_i32(tmp
, reg
, opsize_bytes(opsize
));
752 case 5: /* Indirect displacement. */
753 reg
= get_areg(s
, reg0
);
754 tmp
= tcg_temp_new();
755 ext
= read_im16(env
, s
);
756 tcg_gen_addi_i32(tmp
, reg
, (int16_t)ext
);
758 case 6: /* Indirect index + displacement. */
759 reg
= get_areg(s
, reg0
);
760 return gen_lea_indexed(env
, s
, reg
);
763 case 0: /* Absolute short. */
764 offset
= (int16_t)read_im16(env
, s
);
765 return tcg_constant_i32(offset
);
766 case 1: /* Absolute long. */
767 offset
= read_im32(env
, s
);
768 return tcg_constant_i32(offset
);
769 case 2: /* pc displacement */
771 offset
+= (int16_t)read_im16(env
, s
);
772 return tcg_constant_i32(offset
);
773 case 3: /* pc index+displacement. */
774 return gen_lea_indexed(env
, s
, NULL_QREG
);
775 case 4: /* Immediate. */
780 /* Should never happen. */
784 static TCGv
gen_lea(CPUM68KState
*env
, DisasContext
*s
, uint16_t insn
,
787 int mode
= extract32(insn
, 3, 3);
788 int reg0
= REG(insn
, 0);
789 return gen_lea_mode(env
, s
, mode
, reg0
, opsize
);
793 * Generate code to load/store a value from/into an EA. If WHAT > 0 this is
794 * a write otherwise it is a read (0 == sign extend, -1 == zero extend).
795 * ADDRP is non-null for readwrite operands.
797 static TCGv
gen_ea_mode(CPUM68KState
*env
, DisasContext
*s
, int mode
, int reg0
,
798 int opsize
, TCGv val
, TCGv
*addrp
, ea_what what
,
801 TCGv reg
, tmp
, result
;
805 case 0: /* Data register direct. */
806 reg
= cpu_dregs
[reg0
];
807 if (what
== EA_STORE
) {
808 gen_partset_reg(opsize
, reg
, val
);
811 return gen_extend(s
, reg
, opsize
, what
== EA_LOADS
);
813 case 1: /* Address register direct. */
814 reg
= get_areg(s
, reg0
);
815 if (what
== EA_STORE
) {
816 tcg_gen_mov_i32(reg
, val
);
819 return gen_extend(s
, reg
, opsize
, what
== EA_LOADS
);
821 case 2: /* Indirect register */
822 reg
= get_areg(s
, reg0
);
823 return gen_ldst(s
, opsize
, reg
, val
, what
, index
);
824 case 3: /* Indirect postincrement. */
825 reg
= get_areg(s
, reg0
);
826 result
= gen_ldst(s
, opsize
, reg
, val
, what
, index
);
827 if (what
== EA_STORE
|| !addrp
) {
828 TCGv tmp
= tcg_temp_new();
829 if (reg0
== 7 && opsize
== OS_BYTE
&&
830 m68k_feature(s
->env
, M68K_FEATURE_M68K
)) {
831 tcg_gen_addi_i32(tmp
, reg
, 2);
833 tcg_gen_addi_i32(tmp
, reg
, opsize_bytes(opsize
));
835 delay_set_areg(s
, reg0
, tmp
, true);
838 case 4: /* Indirect predecrememnt. */
839 if (addrp
&& what
== EA_STORE
) {
842 tmp
= gen_lea_mode(env
, s
, mode
, reg0
, opsize
);
843 if (IS_NULL_QREG(tmp
)) {
850 result
= gen_ldst(s
, opsize
, tmp
, val
, what
, index
);
851 if (what
== EA_STORE
|| !addrp
) {
852 delay_set_areg(s
, reg0
, tmp
, false);
855 case 5: /* Indirect displacement. */
856 case 6: /* Indirect index + displacement. */
858 if (addrp
&& what
== EA_STORE
) {
861 tmp
= gen_lea_mode(env
, s
, mode
, reg0
, opsize
);
862 if (IS_NULL_QREG(tmp
)) {
869 return gen_ldst(s
, opsize
, tmp
, val
, what
, index
);
872 case 0: /* Absolute short. */
873 case 1: /* Absolute long. */
874 case 2: /* pc displacement */
875 case 3: /* pc index+displacement. */
877 case 4: /* Immediate. */
878 /* Sign extend values for consistency. */
881 if (what
== EA_LOADS
) {
882 offset
= (int8_t)read_im8(env
, s
);
884 offset
= read_im8(env
, s
);
888 if (what
== EA_LOADS
) {
889 offset
= (int16_t)read_im16(env
, s
);
891 offset
= read_im16(env
, s
);
895 offset
= read_im32(env
, s
);
898 g_assert_not_reached();
900 return tcg_constant_i32(offset
);
905 /* Should never happen. */
909 static TCGv
gen_ea(CPUM68KState
*env
, DisasContext
*s
, uint16_t insn
,
910 int opsize
, TCGv val
, TCGv
*addrp
, ea_what what
, int index
)
912 int mode
= extract32(insn
, 3, 3);
913 int reg0
= REG(insn
, 0);
914 return gen_ea_mode(env
, s
, mode
, reg0
, opsize
, val
, addrp
, what
, index
);
917 static TCGv_ptr
gen_fp_ptr(int freg
)
919 TCGv_ptr fp
= tcg_temp_new_ptr();
920 tcg_gen_addi_ptr(fp
, cpu_env
, offsetof(CPUM68KState
, fregs
[freg
]));
924 static TCGv_ptr
gen_fp_result_ptr(void)
926 TCGv_ptr fp
= tcg_temp_new_ptr();
927 tcg_gen_addi_ptr(fp
, cpu_env
, offsetof(CPUM68KState
, fp_result
));
931 static void gen_fp_move(TCGv_ptr dest
, TCGv_ptr src
)
936 t32
= tcg_temp_new();
937 tcg_gen_ld16u_i32(t32
, src
, offsetof(FPReg
, l
.upper
));
938 tcg_gen_st16_i32(t32
, dest
, offsetof(FPReg
, l
.upper
));
940 t64
= tcg_temp_new_i64();
941 tcg_gen_ld_i64(t64
, src
, offsetof(FPReg
, l
.lower
));
942 tcg_gen_st_i64(t64
, dest
, offsetof(FPReg
, l
.lower
));
945 static void gen_load_fp(DisasContext
*s
, int opsize
, TCGv addr
, TCGv_ptr fp
,
951 t64
= tcg_temp_new_i64();
952 tmp
= tcg_temp_new();
957 tcg_gen_qemu_ld_tl(tmp
, addr
, index
, opsize
| MO_SIGN
| MO_TE
);
958 gen_helper_exts32(cpu_env
, fp
, tmp
);
961 tcg_gen_qemu_ld_tl(tmp
, addr
, index
, MO_TEUL
);
962 gen_helper_extf32(cpu_env
, fp
, tmp
);
965 tcg_gen_qemu_ld_i64(t64
, addr
, index
, MO_TEUQ
);
966 gen_helper_extf64(cpu_env
, fp
, t64
);
969 if (m68k_feature(s
->env
, M68K_FEATURE_CF_FPU
)) {
970 gen_exception(s
, s
->base
.pc_next
, EXCP_FP_UNIMP
);
973 tcg_gen_qemu_ld_i32(tmp
, addr
, index
, MO_TEUL
);
974 tcg_gen_shri_i32(tmp
, tmp
, 16);
975 tcg_gen_st16_i32(tmp
, fp
, offsetof(FPReg
, l
.upper
));
976 tcg_gen_addi_i32(tmp
, addr
, 4);
977 tcg_gen_qemu_ld_i64(t64
, tmp
, index
, MO_TEUQ
);
978 tcg_gen_st_i64(t64
, fp
, offsetof(FPReg
, l
.lower
));
982 * unimplemented data type on 68040/ColdFire
983 * FIXME if needed for another FPU
985 gen_exception(s
, s
->base
.pc_next
, EXCP_FP_UNIMP
);
988 g_assert_not_reached();
992 static void gen_store_fp(DisasContext
*s
, int opsize
, TCGv addr
, TCGv_ptr fp
,
998 t64
= tcg_temp_new_i64();
999 tmp
= tcg_temp_new();
1004 gen_helper_reds32(tmp
, cpu_env
, fp
);
1005 tcg_gen_qemu_st_tl(tmp
, addr
, index
, opsize
| MO_TE
);
1008 gen_helper_redf32(tmp
, cpu_env
, fp
);
1009 tcg_gen_qemu_st_tl(tmp
, addr
, index
, MO_TEUL
);
1012 gen_helper_redf64(t64
, cpu_env
, fp
);
1013 tcg_gen_qemu_st_i64(t64
, addr
, index
, MO_TEUQ
);
1016 if (m68k_feature(s
->env
, M68K_FEATURE_CF_FPU
)) {
1017 gen_exception(s
, s
->base
.pc_next
, EXCP_FP_UNIMP
);
1020 tcg_gen_ld16u_i32(tmp
, fp
, offsetof(FPReg
, l
.upper
));
1021 tcg_gen_shli_i32(tmp
, tmp
, 16);
1022 tcg_gen_qemu_st_i32(tmp
, addr
, index
, MO_TEUL
);
1023 tcg_gen_addi_i32(tmp
, addr
, 4);
1024 tcg_gen_ld_i64(t64
, fp
, offsetof(FPReg
, l
.lower
));
1025 tcg_gen_qemu_st_i64(t64
, tmp
, index
, MO_TEUQ
);
1029 * unimplemented data type on 68040/ColdFire
1030 * FIXME if needed for another FPU
1032 gen_exception(s
, s
->base
.pc_next
, EXCP_FP_UNIMP
);
1035 g_assert_not_reached();
1039 static void gen_ldst_fp(DisasContext
*s
, int opsize
, TCGv addr
,
1040 TCGv_ptr fp
, ea_what what
, int index
)
1042 if (what
== EA_STORE
) {
1043 gen_store_fp(s
, opsize
, addr
, fp
, index
);
1045 gen_load_fp(s
, opsize
, addr
, fp
, index
);
1049 static int gen_ea_mode_fp(CPUM68KState
*env
, DisasContext
*s
, int mode
,
1050 int reg0
, int opsize
, TCGv_ptr fp
, ea_what what
,
1053 TCGv reg
, addr
, tmp
;
1057 case 0: /* Data register direct. */
1058 reg
= cpu_dregs
[reg0
];
1059 if (what
== EA_STORE
) {
1064 gen_helper_reds32(reg
, cpu_env
, fp
);
1067 gen_helper_redf32(reg
, cpu_env
, fp
);
1070 g_assert_not_reached();
1073 tmp
= tcg_temp_new();
1076 tcg_gen_ext8s_i32(tmp
, reg
);
1077 gen_helper_exts32(cpu_env
, fp
, tmp
);
1080 tcg_gen_ext16s_i32(tmp
, reg
);
1081 gen_helper_exts32(cpu_env
, fp
, tmp
);
1084 gen_helper_exts32(cpu_env
, fp
, reg
);
1087 gen_helper_extf32(cpu_env
, fp
, reg
);
1090 g_assert_not_reached();
1094 case 1: /* Address register direct. */
1096 case 2: /* Indirect register */
1097 addr
= get_areg(s
, reg0
);
1098 gen_ldst_fp(s
, opsize
, addr
, fp
, what
, index
);
1100 case 3: /* Indirect postincrement. */
1101 addr
= cpu_aregs
[reg0
];
1102 gen_ldst_fp(s
, opsize
, addr
, fp
, what
, index
);
1103 tcg_gen_addi_i32(addr
, addr
, opsize_bytes(opsize
));
1105 case 4: /* Indirect predecrememnt. */
1106 addr
= gen_lea_mode(env
, s
, mode
, reg0
, opsize
);
1107 if (IS_NULL_QREG(addr
)) {
1110 gen_ldst_fp(s
, opsize
, addr
, fp
, what
, index
);
1111 tcg_gen_mov_i32(cpu_aregs
[reg0
], addr
);
1113 case 5: /* Indirect displacement. */
1114 case 6: /* Indirect index + displacement. */
1116 addr
= gen_lea_mode(env
, s
, mode
, reg0
, opsize
);
1117 if (IS_NULL_QREG(addr
)) {
1120 gen_ldst_fp(s
, opsize
, addr
, fp
, what
, index
);
1124 case 0: /* Absolute short. */
1125 case 1: /* Absolute long. */
1126 case 2: /* pc displacement */
1127 case 3: /* pc index+displacement. */
1129 case 4: /* Immediate. */
1130 if (what
== EA_STORE
) {
1135 tmp
= tcg_constant_i32((int8_t)read_im8(env
, s
));
1136 gen_helper_exts32(cpu_env
, fp
, tmp
);
1139 tmp
= tcg_constant_i32((int16_t)read_im16(env
, s
));
1140 gen_helper_exts32(cpu_env
, fp
, tmp
);
1143 tmp
= tcg_constant_i32(read_im32(env
, s
));
1144 gen_helper_exts32(cpu_env
, fp
, tmp
);
1147 tmp
= tcg_constant_i32(read_im32(env
, s
));
1148 gen_helper_extf32(cpu_env
, fp
, tmp
);
1151 t64
= tcg_constant_i64(read_im64(env
, s
));
1152 gen_helper_extf64(cpu_env
, fp
, t64
);
1155 if (m68k_feature(s
->env
, M68K_FEATURE_CF_FPU
)) {
1156 gen_exception(s
, s
->base
.pc_next
, EXCP_FP_UNIMP
);
1159 tmp
= tcg_constant_i32(read_im32(env
, s
) >> 16);
1160 tcg_gen_st16_i32(tmp
, fp
, offsetof(FPReg
, l
.upper
));
1161 t64
= tcg_constant_i64(read_im64(env
, s
));
1162 tcg_gen_st_i64(t64
, fp
, offsetof(FPReg
, l
.lower
));
1166 * unimplemented data type on 68040/ColdFire
1167 * FIXME if needed for another FPU
1169 gen_exception(s
, s
->base
.pc_next
, EXCP_FP_UNIMP
);
1172 g_assert_not_reached();
1182 static int gen_ea_fp(CPUM68KState
*env
, DisasContext
*s
, uint16_t insn
,
1183 int opsize
, TCGv_ptr fp
, ea_what what
, int index
)
1185 int mode
= extract32(insn
, 3, 3);
1186 int reg0
= REG(insn
, 0);
1187 return gen_ea_mode_fp(env
, s
, mode
, reg0
, opsize
, fp
, what
, index
);
1196 static void gen_cc_cond(DisasCompare
*c
, DisasContext
*s
, int cond
)
1202 /* The CC_OP_CMP form can handle most normal comparisons directly. */
1203 if (op
== CC_OP_CMPB
|| op
== CC_OP_CMPW
|| op
== CC_OP_CMPL
) {
1209 tcond
= TCG_COND_LEU
;
1213 tcond
= TCG_COND_LTU
;
1217 tcond
= TCG_COND_EQ
;
1221 c
->v2
= tcg_constant_i32(0);
1222 c
->v1
= tmp
= tcg_temp_new();
1223 tcg_gen_sub_i32(tmp
, QREG_CC_N
, QREG_CC_V
);
1224 gen_ext(tmp
, tmp
, op
- CC_OP_CMPB
, 1);
1228 tcond
= TCG_COND_LT
;
1232 tcond
= TCG_COND_LE
;
1237 c
->v2
= tcg_constant_i32(0);
1243 tcond
= TCG_COND_NEVER
;
1245 case 14: /* GT (!(Z || (N ^ V))) */
1246 case 15: /* LE (Z || (N ^ V)) */
1248 * Logic operations clear V, which simplifies LE to (Z || N),
1249 * and since Z and N are co-located, this becomes a normal
1252 if (op
== CC_OP_LOGIC
) {
1254 tcond
= TCG_COND_LE
;
1258 case 12: /* GE (!(N ^ V)) */
1259 case 13: /* LT (N ^ V) */
1260 /* Logic operations clear V, which simplifies this to N. */
1261 if (op
!= CC_OP_LOGIC
) {
1265 case 10: /* PL (!N) */
1266 case 11: /* MI (N) */
1267 /* Several cases represent N normally. */
1268 if (op
== CC_OP_ADDB
|| op
== CC_OP_ADDW
|| op
== CC_OP_ADDL
||
1269 op
== CC_OP_SUBB
|| op
== CC_OP_SUBW
|| op
== CC_OP_SUBL
||
1270 op
== CC_OP_LOGIC
) {
1272 tcond
= TCG_COND_LT
;
1276 case 6: /* NE (!Z) */
1277 case 7: /* EQ (Z) */
1278 /* Some cases fold Z into N. */
1279 if (op
== CC_OP_ADDB
|| op
== CC_OP_ADDW
|| op
== CC_OP_ADDL
||
1280 op
== CC_OP_SUBB
|| op
== CC_OP_SUBW
|| op
== CC_OP_SUBL
||
1281 op
== CC_OP_LOGIC
) {
1282 tcond
= TCG_COND_EQ
;
1287 case 4: /* CC (!C) */
1288 case 5: /* CS (C) */
1289 /* Some cases fold C into X. */
1290 if (op
== CC_OP_ADDB
|| op
== CC_OP_ADDW
|| op
== CC_OP_ADDL
||
1291 op
== CC_OP_SUBB
|| op
== CC_OP_SUBW
|| op
== CC_OP_SUBL
) {
1292 tcond
= TCG_COND_NE
;
1297 case 8: /* VC (!V) */
1298 case 9: /* VS (V) */
1299 /* Logic operations clear V and C. */
1300 if (op
== CC_OP_LOGIC
) {
1301 tcond
= TCG_COND_NEVER
;
1308 /* Otherwise, flush flag state to CC_OP_FLAGS. */
1315 /* Invalid, or handled above. */
1317 case 2: /* HI (!C && !Z) -> !(C || Z)*/
1318 case 3: /* LS (C || Z) */
1319 c
->v1
= tmp
= tcg_temp_new();
1320 tcg_gen_setcond_i32(TCG_COND_EQ
, tmp
, QREG_CC_Z
, c
->v2
);
1321 tcg_gen_or_i32(tmp
, tmp
, QREG_CC_C
);
1322 tcond
= TCG_COND_NE
;
1324 case 4: /* CC (!C) */
1325 case 5: /* CS (C) */
1327 tcond
= TCG_COND_NE
;
1329 case 6: /* NE (!Z) */
1330 case 7: /* EQ (Z) */
1332 tcond
= TCG_COND_EQ
;
1334 case 8: /* VC (!V) */
1335 case 9: /* VS (V) */
1337 tcond
= TCG_COND_LT
;
1339 case 10: /* PL (!N) */
1340 case 11: /* MI (N) */
1342 tcond
= TCG_COND_LT
;
1344 case 12: /* GE (!(N ^ V)) */
1345 case 13: /* LT (N ^ V) */
1346 c
->v1
= tmp
= tcg_temp_new();
1347 tcg_gen_xor_i32(tmp
, QREG_CC_N
, QREG_CC_V
);
1348 tcond
= TCG_COND_LT
;
1350 case 14: /* GT (!(Z || (N ^ V))) */
1351 case 15: /* LE (Z || (N ^ V)) */
1352 c
->v1
= tmp
= tcg_temp_new();
1353 tcg_gen_setcond_i32(TCG_COND_EQ
, tmp
, QREG_CC_Z
, c
->v2
);
1354 tcg_gen_neg_i32(tmp
, tmp
);
1355 tmp2
= tcg_temp_new();
1356 tcg_gen_xor_i32(tmp2
, QREG_CC_N
, QREG_CC_V
);
1357 tcg_gen_or_i32(tmp
, tmp
, tmp2
);
1358 tcond
= TCG_COND_LT
;
1363 if ((cond
& 1) == 0) {
1364 tcond
= tcg_invert_cond(tcond
);
1369 static void gen_jmpcc(DisasContext
*s
, int cond
, TCGLabel
*l1
)
1373 gen_cc_cond(&c
, s
, cond
);
1375 tcg_gen_brcond_i32(c
.tcond
, c
.v1
, c
.v2
, l1
);
1378 /* Force a TB lookup after an instruction that changes the CPU state. */
1379 static void gen_exit_tb(DisasContext
*s
)
1382 tcg_gen_movi_i32(QREG_PC
, s
->pc
);
1383 s
->base
.is_jmp
= DISAS_EXIT
;
1386 #define SRC_EA(env, result, opsize, op_sign, addrp) do { \
1387 result = gen_ea(env, s, insn, opsize, NULL_QREG, addrp, \
1388 op_sign ? EA_LOADS : EA_LOADU, IS_USER(s)); \
1389 if (IS_NULL_QREG(result)) { \
1390 gen_addr_fault(s); \
1395 #define DEST_EA(env, insn, opsize, val, addrp) do { \
1396 TCGv ea_result = gen_ea(env, s, insn, opsize, val, addrp, \
1397 EA_STORE, IS_USER(s)); \
1398 if (IS_NULL_QREG(ea_result)) { \
1399 gen_addr_fault(s); \
1404 /* Generate a jump to an immediate address. */
1405 static void gen_jmp_tb(DisasContext
*s
, int n
, target_ulong dest
,
1408 if (unlikely(s
->ss_active
)) {
1410 tcg_gen_movi_i32(QREG_PC
, dest
);
1411 gen_raise_exception_format2(s
, EXCP_TRACE
, src
);
1412 } else if (translator_use_goto_tb(&s
->base
, dest
)) {
1414 tcg_gen_movi_i32(QREG_PC
, dest
);
1415 tcg_gen_exit_tb(s
->base
.tb
, n
);
1417 gen_jmp_im(s
, dest
);
1418 tcg_gen_exit_tb(NULL
, 0);
1420 s
->base
.is_jmp
= DISAS_NORETURN
;
1429 cond
= (insn
>> 8) & 0xf;
1430 gen_cc_cond(&c
, s
, cond
);
1432 tmp
= tcg_temp_new();
1433 tcg_gen_setcond_i32(c
.tcond
, tmp
, c
.v1
, c
.v2
);
1435 tcg_gen_neg_i32(tmp
, tmp
);
1436 DEST_EA(env
, insn
, OS_BYTE
, tmp
, NULL
);
1447 reg
= DREG(insn
, 0);
1449 offset
= (int16_t)read_im16(env
, s
);
1450 l1
= gen_new_label();
1451 gen_jmpcc(s
, (insn
>> 8) & 0xf, l1
);
1453 tmp
= tcg_temp_new();
1454 tcg_gen_ext16s_i32(tmp
, reg
);
1455 tcg_gen_addi_i32(tmp
, tmp
, -1);
1456 gen_partset_reg(OS_WORD
, reg
, tmp
);
1457 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, -1, l1
);
1458 gen_jmp_tb(s
, 1, base
+ offset
, s
->base
.pc_next
);
1460 gen_jmp_tb(s
, 0, s
->pc
, s
->base
.pc_next
);
1463 DISAS_INSN(undef_mac
)
1465 gen_exception(s
, s
->base
.pc_next
, EXCP_LINEA
);
1468 DISAS_INSN(undef_fpu
)
1470 gen_exception(s
, s
->base
.pc_next
, EXCP_LINEF
);
1476 * ??? This is both instructions that are as yet unimplemented
1477 * for the 680x0 series, as well as those that are implemented
1478 * but actually illegal for CPU32 or pre-68020.
1480 qemu_log_mask(LOG_UNIMP
, "Illegal instruction: %04x @ %08x\n",
1481 insn
, s
->base
.pc_next
);
1482 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
1492 sign
= (insn
& 0x100) != 0;
1493 reg
= DREG(insn
, 9);
1494 tmp
= tcg_temp_new();
1496 tcg_gen_ext16s_i32(tmp
, reg
);
1498 tcg_gen_ext16u_i32(tmp
, reg
);
1499 SRC_EA(env
, src
, OS_WORD
, sign
, NULL
);
1500 tcg_gen_mul_i32(tmp
, tmp
, src
);
1501 tcg_gen_mov_i32(reg
, tmp
);
1502 gen_logic_cc(s
, tmp
, OS_LONG
);
1512 /* divX.w <EA>,Dn 32/16 -> 16r:16q */
1514 sign
= (insn
& 0x100) != 0;
1516 /* dest.l / src.w */
1518 SRC_EA(env
, src
, OS_WORD
, sign
, NULL
);
1519 destr
= tcg_constant_i32(REG(insn
, 9));
1520 ilen
= tcg_constant_i32(s
->pc
- s
->base
.pc_next
);
1522 gen_helper_divsw(cpu_env
, destr
, src
, ilen
);
1524 gen_helper_divuw(cpu_env
, destr
, src
, ilen
);
1527 set_cc_op(s
, CC_OP_FLAGS
);
1532 TCGv num
, reg
, den
, ilen
;
1536 ext
= read_im16(env
, s
);
1538 sign
= (ext
& 0x0800) != 0;
1541 if (!m68k_feature(s
->env
, M68K_FEATURE_QUAD_MULDIV
)) {
1542 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
1546 /* divX.l <EA>, Dr:Dq 64/32 -> 32r:32q */
1548 SRC_EA(env
, den
, OS_LONG
, 0, NULL
);
1549 num
= tcg_constant_i32(REG(ext
, 12));
1550 reg
= tcg_constant_i32(REG(ext
, 0));
1551 ilen
= tcg_constant_i32(s
->pc
- s
->base
.pc_next
);
1553 gen_helper_divsll(cpu_env
, num
, reg
, den
, ilen
);
1555 gen_helper_divull(cpu_env
, num
, reg
, den
, ilen
);
1557 set_cc_op(s
, CC_OP_FLAGS
);
1561 /* divX.l <EA>, Dq 32/32 -> 32q */
1562 /* divXl.l <EA>, Dr:Dq 32/32 -> 32r:32q */
1564 SRC_EA(env
, den
, OS_LONG
, 0, NULL
);
1565 num
= tcg_constant_i32(REG(ext
, 12));
1566 reg
= tcg_constant_i32(REG(ext
, 0));
1567 ilen
= tcg_constant_i32(s
->pc
- s
->base
.pc_next
);
1569 gen_helper_divsl(cpu_env
, num
, reg
, den
, ilen
);
1571 gen_helper_divul(cpu_env
, num
, reg
, den
, ilen
);
1574 set_cc_op(s
, CC_OP_FLAGS
);
1577 static void bcd_add(TCGv dest
, TCGv src
)
1582 * dest10 = dest10 + src10 + X
1586 * t3 = t2 + dest + X
1590 * t7 = (t6 >> 2) | (t6 >> 3)
1595 * t1 = (src + 0x066) + dest + X
1596 * = result with some possible exceeding 0x6
1599 t0
= tcg_temp_new();
1600 tcg_gen_addi_i32(t0
, src
, 0x066);
1602 t1
= tcg_temp_new();
1603 tcg_gen_add_i32(t1
, t0
, dest
);
1604 tcg_gen_add_i32(t1
, t1
, QREG_CC_X
);
1606 /* we will remove exceeding 0x6 where there is no carry */
1609 * t0 = (src + 0x0066) ^ dest
1610 * = t1 without carries
1613 tcg_gen_xor_i32(t0
, t0
, dest
);
1616 * extract the carries
1618 * = only the carries
1621 tcg_gen_xor_i32(t0
, t0
, t1
);
1624 * generate 0x1 where there is no carry
1625 * and for each 0x10, generate a 0x6
1628 tcg_gen_shri_i32(t0
, t0
, 3);
1629 tcg_gen_not_i32(t0
, t0
);
1630 tcg_gen_andi_i32(t0
, t0
, 0x22);
1631 tcg_gen_add_i32(dest
, t0
, t0
);
1632 tcg_gen_add_i32(dest
, dest
, t0
);
1635 * remove the exceeding 0x6
1636 * for digits that have not generated a carry
1639 tcg_gen_sub_i32(dest
, t1
, dest
);
1642 static void bcd_sub(TCGv dest
, TCGv src
)
1647 * dest10 = dest10 - src10 - X
1648 * = bcd_add(dest + 1 - X, 0x199 - src)
1651 /* t0 = 0x066 + (0x199 - src) */
1653 t0
= tcg_temp_new();
1654 tcg_gen_subfi_i32(t0
, 0x1ff, src
);
1656 /* t1 = t0 + dest + 1 - X*/
1658 t1
= tcg_temp_new();
1659 tcg_gen_add_i32(t1
, t0
, dest
);
1660 tcg_gen_addi_i32(t1
, t1
, 1);
1661 tcg_gen_sub_i32(t1
, t1
, QREG_CC_X
);
1663 /* t2 = t0 ^ dest */
1665 t2
= tcg_temp_new();
1666 tcg_gen_xor_i32(t2
, t0
, dest
);
1670 tcg_gen_xor_i32(t0
, t1
, t2
);
1674 * t0 = (t2 >> 2) | (t2 >> 3)
1676 * to fit on 8bit operands, changed in:
1678 * t2 = ~(t0 >> 3) & 0x22
1683 tcg_gen_shri_i32(t2
, t0
, 3);
1684 tcg_gen_not_i32(t2
, t2
);
1685 tcg_gen_andi_i32(t2
, t2
, 0x22);
1686 tcg_gen_add_i32(t0
, t2
, t2
);
1687 tcg_gen_add_i32(t0
, t0
, t2
);
1689 /* return t1 - t0 */
1691 tcg_gen_sub_i32(dest
, t1
, t0
);
1694 static void bcd_flags(TCGv val
)
1696 tcg_gen_andi_i32(QREG_CC_C
, val
, 0x0ff);
1697 tcg_gen_or_i32(QREG_CC_Z
, QREG_CC_Z
, QREG_CC_C
);
1699 tcg_gen_extract_i32(QREG_CC_C
, val
, 8, 1);
1701 tcg_gen_mov_i32(QREG_CC_X
, QREG_CC_C
);
1704 DISAS_INSN(abcd_reg
)
1709 gen_flush_flags(s
); /* !Z is sticky */
1711 src
= gen_extend(s
, DREG(insn
, 0), OS_BYTE
, 0);
1712 dest
= gen_extend(s
, DREG(insn
, 9), OS_BYTE
, 0);
1714 gen_partset_reg(OS_BYTE
, DREG(insn
, 9), dest
);
1719 DISAS_INSN(abcd_mem
)
1721 TCGv src
, dest
, addr
;
1723 gen_flush_flags(s
); /* !Z is sticky */
1725 /* Indirect pre-decrement load (mode 4) */
1727 src
= gen_ea_mode(env
, s
, 4, REG(insn
, 0), OS_BYTE
,
1728 NULL_QREG
, NULL
, EA_LOADU
, IS_USER(s
));
1729 dest
= gen_ea_mode(env
, s
, 4, REG(insn
, 9), OS_BYTE
,
1730 NULL_QREG
, &addr
, EA_LOADU
, IS_USER(s
));
1734 gen_ea_mode(env
, s
, 4, REG(insn
, 9), OS_BYTE
, dest
, &addr
,
1735 EA_STORE
, IS_USER(s
));
1740 DISAS_INSN(sbcd_reg
)
1744 gen_flush_flags(s
); /* !Z is sticky */
1746 src
= gen_extend(s
, DREG(insn
, 0), OS_BYTE
, 0);
1747 dest
= gen_extend(s
, DREG(insn
, 9), OS_BYTE
, 0);
1751 gen_partset_reg(OS_BYTE
, DREG(insn
, 9), dest
);
1756 DISAS_INSN(sbcd_mem
)
1758 TCGv src
, dest
, addr
;
1760 gen_flush_flags(s
); /* !Z is sticky */
1762 /* Indirect pre-decrement load (mode 4) */
1764 src
= gen_ea_mode(env
, s
, 4, REG(insn
, 0), OS_BYTE
,
1765 NULL_QREG
, NULL
, EA_LOADU
, IS_USER(s
));
1766 dest
= gen_ea_mode(env
, s
, 4, REG(insn
, 9), OS_BYTE
,
1767 NULL_QREG
, &addr
, EA_LOADU
, IS_USER(s
));
1771 gen_ea_mode(env
, s
, 4, REG(insn
, 9), OS_BYTE
, dest
, &addr
,
1772 EA_STORE
, IS_USER(s
));
1782 gen_flush_flags(s
); /* !Z is sticky */
1784 SRC_EA(env
, src
, OS_BYTE
, 0, &addr
);
1786 dest
= tcg_temp_new();
1787 tcg_gen_movi_i32(dest
, 0);
1790 DEST_EA(env
, insn
, OS_BYTE
, dest
, &addr
);
1805 add
= (insn
& 0x4000) != 0;
1806 opsize
= insn_opsize(insn
);
1807 reg
= gen_extend(s
, DREG(insn
, 9), opsize
, 1);
1808 dest
= tcg_temp_new();
1810 SRC_EA(env
, tmp
, opsize
, 1, &addr
);
1814 SRC_EA(env
, src
, opsize
, 1, NULL
);
1817 tcg_gen_add_i32(dest
, tmp
, src
);
1818 tcg_gen_setcond_i32(TCG_COND_LTU
, QREG_CC_X
, dest
, src
);
1819 set_cc_op(s
, CC_OP_ADDB
+ opsize
);
1821 tcg_gen_setcond_i32(TCG_COND_LTU
, QREG_CC_X
, tmp
, src
);
1822 tcg_gen_sub_i32(dest
, tmp
, src
);
1823 set_cc_op(s
, CC_OP_SUBB
+ opsize
);
1825 gen_update_cc_add(dest
, src
, opsize
);
1827 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
1829 gen_partset_reg(opsize
, DREG(insn
, 9), dest
);
1833 /* Reverse the order of the bits in REG. */
1837 reg
= DREG(insn
, 0);
1838 gen_helper_bitrev(reg
, reg
);
1841 DISAS_INSN(bitop_reg
)
1851 if ((insn
& 0x38) != 0)
1855 op
= (insn
>> 6) & 3;
1856 SRC_EA(env
, src1
, opsize
, 0, op
? &addr
: NULL
);
1859 src2
= tcg_temp_new();
1860 if (opsize
== OS_BYTE
)
1861 tcg_gen_andi_i32(src2
, DREG(insn
, 9), 7);
1863 tcg_gen_andi_i32(src2
, DREG(insn
, 9), 31);
1865 tmp
= tcg_temp_new();
1866 tcg_gen_shl_i32(tmp
, tcg_constant_i32(1), src2
);
1868 tcg_gen_and_i32(QREG_CC_Z
, src1
, tmp
);
1870 dest
= tcg_temp_new();
1873 tcg_gen_xor_i32(dest
, src1
, tmp
);
1876 tcg_gen_andc_i32(dest
, src1
, tmp
);
1879 tcg_gen_or_i32(dest
, src1
, tmp
);
1885 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
1892 reg
= DREG(insn
, 0);
1894 gen_helper_sats(reg
, reg
, QREG_CC_V
);
1895 gen_logic_cc(s
, reg
, OS_LONG
);
1898 static void gen_push(DisasContext
*s
, TCGv val
)
1902 tmp
= tcg_temp_new();
1903 tcg_gen_subi_i32(tmp
, QREG_SP
, 4);
1904 gen_store(s
, OS_LONG
, tmp
, val
, IS_USER(s
));
1905 tcg_gen_mov_i32(QREG_SP
, tmp
);
1908 static TCGv
mreg(int reg
)
1912 return cpu_dregs
[reg
];
1915 return cpu_aregs
[reg
& 7];
1920 TCGv addr
, incr
, tmp
, r
[16];
1921 int is_load
= (insn
& 0x0400) != 0;
1922 int opsize
= (insn
& 0x40) != 0 ? OS_LONG
: OS_WORD
;
1923 uint16_t mask
= read_im16(env
, s
);
1924 int mode
= extract32(insn
, 3, 3);
1925 int reg0
= REG(insn
, 0);
1928 tmp
= cpu_aregs
[reg0
];
1931 case 0: /* data register direct */
1932 case 1: /* addr register direct */
1937 case 2: /* indirect */
1940 case 3: /* indirect post-increment */
1942 /* post-increment is not allowed */
1947 case 4: /* indirect pre-decrement */
1949 /* pre-decrement is not allowed */
1953 * We want a bare copy of the address reg, without any pre-decrement
1954 * adjustment, as gen_lea would provide.
1959 tmp
= gen_lea_mode(env
, s
, mode
, reg0
, opsize
);
1960 if (IS_NULL_QREG(tmp
)) {
1966 addr
= tcg_temp_new();
1967 tcg_gen_mov_i32(addr
, tmp
);
1968 incr
= tcg_constant_i32(opsize_bytes(opsize
));
1971 /* memory to register */
1972 for (i
= 0; i
< 16; i
++) {
1973 if (mask
& (1 << i
)) {
1974 r
[i
] = gen_load(s
, opsize
, addr
, 1, IS_USER(s
));
1975 tcg_gen_add_i32(addr
, addr
, incr
);
1978 for (i
= 0; i
< 16; i
++) {
1979 if (mask
& (1 << i
)) {
1980 tcg_gen_mov_i32(mreg(i
), r
[i
]);
1984 /* post-increment: movem (An)+,X */
1985 tcg_gen_mov_i32(cpu_aregs
[reg0
], addr
);
1988 /* register to memory */
1990 /* pre-decrement: movem X,-(An) */
1991 for (i
= 15; i
>= 0; i
--) {
1992 if ((mask
<< i
) & 0x8000) {
1993 tcg_gen_sub_i32(addr
, addr
, incr
);
1994 if (reg0
+ 8 == i
&&
1995 m68k_feature(s
->env
, M68K_FEATURE_EXT_FULL
)) {
1997 * M68020+: if the addressing register is the
1998 * register moved to memory, the value written
1999 * is the initial value decremented by the size of
2000 * the operation, regardless of how many actual
2001 * stores have been performed until this point.
2002 * M68000/M68010: the value is the initial value.
2004 tmp
= tcg_temp_new();
2005 tcg_gen_sub_i32(tmp
, cpu_aregs
[reg0
], incr
);
2006 gen_store(s
, opsize
, addr
, tmp
, IS_USER(s
));
2008 gen_store(s
, opsize
, addr
, mreg(i
), IS_USER(s
));
2012 tcg_gen_mov_i32(cpu_aregs
[reg0
], addr
);
2014 for (i
= 0; i
< 16; i
++) {
2015 if (mask
& (1 << i
)) {
2016 gen_store(s
, opsize
, addr
, mreg(i
), IS_USER(s
));
2017 tcg_gen_add_i32(addr
, addr
, incr
);
2033 displ
= read_im16(env
, s
);
2035 addr
= AREG(insn
, 0);
2036 reg
= DREG(insn
, 9);
2038 abuf
= tcg_temp_new();
2039 tcg_gen_addi_i32(abuf
, addr
, displ
);
2040 dbuf
= tcg_temp_new();
2049 for ( ; i
> 0 ; i
--) {
2050 tcg_gen_shri_i32(dbuf
, reg
, (i
- 1) * 8);
2051 tcg_gen_qemu_st_i32(dbuf
, abuf
, IS_USER(s
), MO_UB
);
2053 tcg_gen_addi_i32(abuf
, abuf
, 2);
2057 for ( ; i
> 0 ; i
--) {
2058 tcg_gen_qemu_ld_tl(dbuf
, abuf
, IS_USER(s
), MO_UB
);
2059 tcg_gen_deposit_i32(reg
, reg
, dbuf
, (i
- 1) * 8, 8);
2061 tcg_gen_addi_i32(abuf
, abuf
, 2);
2067 DISAS_INSN(bitop_im
)
2077 if ((insn
& 0x38) != 0)
2081 op
= (insn
>> 6) & 3;
2083 bitnum
= read_im16(env
, s
);
2084 if (m68k_feature(s
->env
, M68K_FEATURE_M68K
)) {
2085 if (bitnum
& 0xfe00) {
2086 disas_undef(env
, s
, insn
);
2090 if (bitnum
& 0xff00) {
2091 disas_undef(env
, s
, insn
);
2096 SRC_EA(env
, src1
, opsize
, 0, op
? &addr
: NULL
);
2099 if (opsize
== OS_BYTE
)
2105 tcg_gen_andi_i32(QREG_CC_Z
, src1
, mask
);
2108 tmp
= tcg_temp_new();
2111 tcg_gen_xori_i32(tmp
, src1
, mask
);
2114 tcg_gen_andi_i32(tmp
, src1
, ~mask
);
2117 tcg_gen_ori_i32(tmp
, src1
, mask
);
2122 DEST_EA(env
, insn
, opsize
, tmp
, &addr
);
2126 static TCGv
gen_get_ccr(DisasContext
*s
)
2131 dest
= tcg_temp_new();
2132 gen_helper_get_ccr(dest
, cpu_env
);
2136 static TCGv
gen_get_sr(DisasContext
*s
)
2141 ccr
= gen_get_ccr(s
);
2142 sr
= tcg_temp_new();
2143 tcg_gen_andi_i32(sr
, QREG_SR
, 0xffe0);
2144 tcg_gen_or_i32(sr
, sr
, ccr
);
2148 static void gen_set_sr_im(DisasContext
*s
, uint16_t val
, int ccr_only
)
2151 tcg_gen_movi_i32(QREG_CC_C
, val
& CCF_C
? 1 : 0);
2152 tcg_gen_movi_i32(QREG_CC_V
, val
& CCF_V
? -1 : 0);
2153 tcg_gen_movi_i32(QREG_CC_Z
, val
& CCF_Z
? 0 : 1);
2154 tcg_gen_movi_i32(QREG_CC_N
, val
& CCF_N
? -1 : 0);
2155 tcg_gen_movi_i32(QREG_CC_X
, val
& CCF_X
? 1 : 0);
2157 /* Must writeback before changing security state. */
2159 gen_helper_set_sr(cpu_env
, tcg_constant_i32(val
));
2161 set_cc_op(s
, CC_OP_FLAGS
);
2164 static void gen_set_sr(DisasContext
*s
, TCGv val
, int ccr_only
)
2167 gen_helper_set_ccr(cpu_env
, val
);
2169 /* Must writeback before changing security state. */
2171 gen_helper_set_sr(cpu_env
, val
);
2173 set_cc_op(s
, CC_OP_FLAGS
);
2176 static void gen_move_to_sr(CPUM68KState
*env
, DisasContext
*s
, uint16_t insn
,
2179 if ((insn
& 0x3f) == 0x3c) {
2181 val
= read_im16(env
, s
);
2182 gen_set_sr_im(s
, val
, ccr_only
);
2185 SRC_EA(env
, src
, OS_WORD
, 0, NULL
);
2186 gen_set_sr(s
, src
, ccr_only
);
2190 DISAS_INSN(arith_im
)
2198 bool with_SR
= ((insn
& 0x3f) == 0x3c);
2200 op
= (insn
>> 9) & 7;
2201 opsize
= insn_opsize(insn
);
2204 im
= tcg_constant_i32((int8_t)read_im8(env
, s
));
2207 im
= tcg_constant_i32((int16_t)read_im16(env
, s
));
2210 im
= tcg_constant_i32(read_im32(env
, s
));
2213 g_assert_not_reached();
2217 /* SR/CCR can only be used with andi/eori/ori */
2218 if (op
== 2 || op
== 3 || op
== 6) {
2219 disas_undef(env
, s
, insn
);
2224 src1
= gen_get_ccr(s
);
2228 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
2231 src1
= gen_get_sr(s
);
2234 /* OS_LONG; others already g_assert_not_reached. */
2235 disas_undef(env
, s
, insn
);
2239 SRC_EA(env
, src1
, opsize
, 1, (op
== 6) ? NULL
: &addr
);
2241 dest
= tcg_temp_new();
2244 tcg_gen_or_i32(dest
, src1
, im
);
2246 gen_set_sr(s
, dest
, opsize
== OS_BYTE
);
2249 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
2250 gen_logic_cc(s
, dest
, opsize
);
2254 tcg_gen_and_i32(dest
, src1
, im
);
2256 gen_set_sr(s
, dest
, opsize
== OS_BYTE
);
2259 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
2260 gen_logic_cc(s
, dest
, opsize
);
2264 tcg_gen_setcond_i32(TCG_COND_LTU
, QREG_CC_X
, src1
, im
);
2265 tcg_gen_sub_i32(dest
, src1
, im
);
2266 gen_update_cc_add(dest
, im
, opsize
);
2267 set_cc_op(s
, CC_OP_SUBB
+ opsize
);
2268 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
2271 tcg_gen_add_i32(dest
, src1
, im
);
2272 gen_update_cc_add(dest
, im
, opsize
);
2273 tcg_gen_setcond_i32(TCG_COND_LTU
, QREG_CC_X
, dest
, im
);
2274 set_cc_op(s
, CC_OP_ADDB
+ opsize
);
2275 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
2278 tcg_gen_xor_i32(dest
, src1
, im
);
2280 gen_set_sr(s
, dest
, opsize
== OS_BYTE
);
2283 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
2284 gen_logic_cc(s
, dest
, opsize
);
2288 gen_update_cc_cmp(s
, src1
, im
, opsize
);
2304 switch ((insn
>> 9) & 3) {
2318 g_assert_not_reached();
2321 ext
= read_im16(env
, s
);
2323 /* cas Dc,Du,<EA> */
2325 addr
= gen_lea(env
, s
, insn
, opsize
);
2326 if (IS_NULL_QREG(addr
)) {
2331 cmp
= gen_extend(s
, DREG(ext
, 0), opsize
, 1);
2334 * if <EA> == Dc then
2336 * Dc = <EA> (because <EA> == Dc)
2341 load
= tcg_temp_new();
2342 tcg_gen_atomic_cmpxchg_i32(load
, addr
, cmp
, DREG(ext
, 6),
2344 /* update flags before setting cmp to load */
2345 gen_update_cc_cmp(s
, load
, cmp
, opsize
);
2346 gen_partset_reg(opsize
, DREG(ext
, 0), load
);
2348 switch (extract32(insn
, 3, 3)) {
2349 case 3: /* Indirect postincrement. */
2350 tcg_gen_addi_i32(AREG(insn
, 0), addr
, opsize_bytes(opsize
));
2352 case 4: /* Indirect predecrememnt. */
2353 tcg_gen_mov_i32(AREG(insn
, 0), addr
);
2360 uint16_t ext1
, ext2
;
2363 /* cas2 Dc1:Dc2,Du1:Du2,(Rn1):(Rn2) */
2365 ext1
= read_im16(env
, s
);
2367 if (ext1
& 0x8000) {
2368 /* Address Register */
2369 addr1
= AREG(ext1
, 12);
2372 addr1
= DREG(ext1
, 12);
2375 ext2
= read_im16(env
, s
);
2376 if (ext2
& 0x8000) {
2377 /* Address Register */
2378 addr2
= AREG(ext2
, 12);
2381 addr2
= DREG(ext2
, 12);
2385 * if (R1) == Dc1 && (R2) == Dc2 then
2393 if (tb_cflags(s
->base
.tb
) & CF_PARALLEL
) {
2394 gen_helper_exit_atomic(cpu_env
);
2396 TCGv regs
= tcg_constant_i32(REG(ext2
, 6) |
2397 (REG(ext1
, 6) << 3) |
2398 (REG(ext2
, 0) << 6) |
2399 (REG(ext1
, 0) << 9));
2400 gen_helper_cas2w(cpu_env
, regs
, addr1
, addr2
);
2403 /* Note that cas2w also assigned to env->cc_op. */
2404 s
->cc_op
= CC_OP_CMPW
;
2405 s
->cc_op_synced
= 1;
2410 uint16_t ext1
, ext2
;
2411 TCGv addr1
, addr2
, regs
;
2413 /* cas2 Dc1:Dc2,Du1:Du2,(Rn1):(Rn2) */
2415 ext1
= read_im16(env
, s
);
2417 if (ext1
& 0x8000) {
2418 /* Address Register */
2419 addr1
= AREG(ext1
, 12);
2422 addr1
= DREG(ext1
, 12);
2425 ext2
= read_im16(env
, s
);
2426 if (ext2
& 0x8000) {
2427 /* Address Register */
2428 addr2
= AREG(ext2
, 12);
2431 addr2
= DREG(ext2
, 12);
2435 * if (R1) == Dc1 && (R2) == Dc2 then
2443 regs
= tcg_constant_i32(REG(ext2
, 6) |
2444 (REG(ext1
, 6) << 3) |
2445 (REG(ext2
, 0) << 6) |
2446 (REG(ext1
, 0) << 9));
2447 if (tb_cflags(s
->base
.tb
) & CF_PARALLEL
) {
2448 gen_helper_cas2l_parallel(cpu_env
, regs
, addr1
, addr2
);
2450 gen_helper_cas2l(cpu_env
, regs
, addr1
, addr2
);
2453 /* Note that cas2l also assigned to env->cc_op. */
2454 s
->cc_op
= CC_OP_CMPL
;
2455 s
->cc_op_synced
= 1;
2462 reg
= DREG(insn
, 0);
2463 tcg_gen_bswap32_i32(reg
, reg
);
2473 switch (insn
>> 12) {
2474 case 1: /* move.b */
2477 case 2: /* move.l */
2480 case 3: /* move.w */
2486 SRC_EA(env
, src
, opsize
, 1, NULL
);
2487 op
= (insn
>> 6) & 7;
2490 /* The value will already have been sign extended. */
2491 dest
= AREG(insn
, 9);
2492 tcg_gen_mov_i32(dest
, src
);
2496 dest_ea
= ((insn
>> 9) & 7) | (op
<< 3);
2497 DEST_EA(env
, dest_ea
, opsize
, src
, NULL
);
2498 /* This will be correct because loads sign extend. */
2499 gen_logic_cc(s
, src
, opsize
);
2510 opsize
= insn_opsize(insn
);
2511 SRC_EA(env
, src
, opsize
, 1, &addr
);
2513 gen_flush_flags(s
); /* compute old Z */
2516 * Perform subtract with borrow.
2517 * (X, N) = -(src + X);
2520 z
= tcg_constant_i32(0);
2521 tcg_gen_add2_i32(QREG_CC_N
, QREG_CC_X
, src
, z
, QREG_CC_X
, z
);
2522 tcg_gen_sub2_i32(QREG_CC_N
, QREG_CC_X
, z
, z
, QREG_CC_N
, QREG_CC_X
);
2523 gen_ext(QREG_CC_N
, QREG_CC_N
, opsize
, 1);
2525 tcg_gen_andi_i32(QREG_CC_X
, QREG_CC_X
, 1);
2528 * Compute signed-overflow for negation. The normal formula for
2529 * subtraction is (res ^ src) & (src ^ dest), but with dest==0
2530 * this simplifies to res & src.
2533 tcg_gen_and_i32(QREG_CC_V
, QREG_CC_N
, src
);
2535 /* Copy the rest of the results into place. */
2536 tcg_gen_or_i32(QREG_CC_Z
, QREG_CC_Z
, QREG_CC_N
); /* !Z is sticky */
2537 tcg_gen_mov_i32(QREG_CC_C
, QREG_CC_X
);
2539 set_cc_op(s
, CC_OP_FLAGS
);
2541 /* result is in QREG_CC_N */
2543 DEST_EA(env
, insn
, opsize
, QREG_CC_N
, &addr
);
2551 reg
= AREG(insn
, 9);
2552 tmp
= gen_lea(env
, s
, insn
, OS_LONG
);
2553 if (IS_NULL_QREG(tmp
)) {
2557 tcg_gen_mov_i32(reg
, tmp
);
2565 zero
= tcg_constant_i32(0);
2566 opsize
= insn_opsize(insn
);
2567 DEST_EA(env
, insn
, opsize
, zero
, NULL
);
2568 gen_logic_cc(s
, zero
, opsize
);
2571 DISAS_INSN(move_from_ccr
)
2575 ccr
= gen_get_ccr(s
);
2576 DEST_EA(env
, insn
, OS_WORD
, ccr
, NULL
);
2586 opsize
= insn_opsize(insn
);
2587 SRC_EA(env
, src1
, opsize
, 1, &addr
);
2588 dest
= tcg_temp_new();
2589 tcg_gen_neg_i32(dest
, src1
);
2590 set_cc_op(s
, CC_OP_SUBB
+ opsize
);
2591 gen_update_cc_add(dest
, src1
, opsize
);
2592 tcg_gen_setcondi_i32(TCG_COND_NE
, QREG_CC_X
, dest
, 0);
2593 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
2596 DISAS_INSN(move_to_ccr
)
2598 gen_move_to_sr(env
, s
, insn
, true);
2608 opsize
= insn_opsize(insn
);
2609 SRC_EA(env
, src1
, opsize
, 1, &addr
);
2610 dest
= tcg_temp_new();
2611 tcg_gen_not_i32(dest
, src1
);
2612 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
2613 gen_logic_cc(s
, dest
, opsize
);
2622 src1
= tcg_temp_new();
2623 src2
= tcg_temp_new();
2624 reg
= DREG(insn
, 0);
2625 tcg_gen_shli_i32(src1
, reg
, 16);
2626 tcg_gen_shri_i32(src2
, reg
, 16);
2627 tcg_gen_or_i32(reg
, src1
, src2
);
2628 gen_logic_cc(s
, reg
, OS_LONG
);
2633 #if defined(CONFIG_USER_ONLY)
2634 gen_exception(s
, s
->base
.pc_next
, EXCP_DEBUG
);
2636 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
2644 tmp
= gen_lea(env
, s
, insn
, OS_LONG
);
2645 if (IS_NULL_QREG(tmp
)) {
2658 reg
= DREG(insn
, 0);
2659 op
= (insn
>> 6) & 7;
2660 tmp
= tcg_temp_new();
2662 tcg_gen_ext16s_i32(tmp
, reg
);
2664 tcg_gen_ext8s_i32(tmp
, reg
);
2666 gen_partset_reg(OS_WORD
, reg
, tmp
);
2668 tcg_gen_mov_i32(reg
, tmp
);
2669 gen_logic_cc(s
, tmp
, OS_LONG
);
2677 opsize
= insn_opsize(insn
);
2678 SRC_EA(env
, tmp
, opsize
, 1, NULL
);
2679 gen_logic_cc(s
, tmp
, opsize
);
2684 /* Implemented as a NOP. */
2689 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
2694 int mode
= extract32(insn
, 3, 3);
2695 int reg0
= REG(insn
, 0);
2698 /* data register direct */
2699 TCGv dest
= cpu_dregs
[reg0
];
2700 gen_logic_cc(s
, dest
, OS_BYTE
);
2701 tcg_gen_ori_tl(dest
, dest
, 0x80);
2705 addr
= gen_lea_mode(env
, s
, mode
, reg0
, OS_BYTE
);
2706 if (IS_NULL_QREG(addr
)) {
2710 src1
= tcg_temp_new();
2711 tcg_gen_atomic_fetch_or_tl(src1
, addr
, tcg_constant_tl(0x80),
2713 gen_logic_cc(s
, src1
, OS_BYTE
);
2716 case 3: /* Indirect postincrement. */
2717 tcg_gen_addi_i32(AREG(insn
, 0), addr
, 1);
2719 case 4: /* Indirect predecrememnt. */
2720 tcg_gen_mov_i32(AREG(insn
, 0), addr
);
2732 ext
= read_im16(env
, s
);
2737 if (!m68k_feature(s
->env
, M68K_FEATURE_QUAD_MULDIV
)) {
2738 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
2742 SRC_EA(env
, src1
, OS_LONG
, 0, NULL
);
2745 tcg_gen_muls2_i32(QREG_CC_Z
, QREG_CC_N
, src1
, DREG(ext
, 12));
2747 tcg_gen_mulu2_i32(QREG_CC_Z
, QREG_CC_N
, src1
, DREG(ext
, 12));
2749 /* if Dl == Dh, 68040 returns low word */
2750 tcg_gen_mov_i32(DREG(ext
, 0), QREG_CC_N
);
2751 tcg_gen_mov_i32(DREG(ext
, 12), QREG_CC_Z
);
2752 tcg_gen_or_i32(QREG_CC_Z
, QREG_CC_Z
, QREG_CC_N
);
2754 tcg_gen_movi_i32(QREG_CC_V
, 0);
2755 tcg_gen_movi_i32(QREG_CC_C
, 0);
2757 set_cc_op(s
, CC_OP_FLAGS
);
2760 SRC_EA(env
, src1
, OS_LONG
, 0, NULL
);
2761 if (m68k_feature(s
->env
, M68K_FEATURE_M68K
)) {
2762 tcg_gen_movi_i32(QREG_CC_C
, 0);
2764 tcg_gen_muls2_i32(QREG_CC_N
, QREG_CC_V
, src1
, DREG(ext
, 12));
2765 /* QREG_CC_V is -(QREG_CC_V != (QREG_CC_N >> 31)) */
2766 tcg_gen_sari_i32(QREG_CC_Z
, QREG_CC_N
, 31);
2767 tcg_gen_setcond_i32(TCG_COND_NE
, QREG_CC_V
, QREG_CC_V
, QREG_CC_Z
);
2769 tcg_gen_mulu2_i32(QREG_CC_N
, QREG_CC_V
, src1
, DREG(ext
, 12));
2770 /* QREG_CC_V is -(QREG_CC_V != 0), use QREG_CC_C as 0 */
2771 tcg_gen_setcond_i32(TCG_COND_NE
, QREG_CC_V
, QREG_CC_V
, QREG_CC_C
);
2773 tcg_gen_neg_i32(QREG_CC_V
, QREG_CC_V
);
2774 tcg_gen_mov_i32(DREG(ext
, 12), QREG_CC_N
);
2776 tcg_gen_mov_i32(QREG_CC_Z
, QREG_CC_N
);
2778 set_cc_op(s
, CC_OP_FLAGS
);
2781 * The upper 32 bits of the product are discarded, so
2782 * muls.l and mulu.l are functionally equivalent.
2784 tcg_gen_mul_i32(DREG(ext
, 12), src1
, DREG(ext
, 12));
2785 gen_logic_cc(s
, DREG(ext
, 12), OS_LONG
);
2789 static void gen_link(DisasContext
*s
, uint16_t insn
, int32_t offset
)
2794 reg
= AREG(insn
, 0);
2795 tmp
= tcg_temp_new();
2796 tcg_gen_subi_i32(tmp
, QREG_SP
, 4);
2797 gen_store(s
, OS_LONG
, tmp
, reg
, IS_USER(s
));
2798 if ((insn
& 7) != 7) {
2799 tcg_gen_mov_i32(reg
, tmp
);
2801 tcg_gen_addi_i32(QREG_SP
, tmp
, offset
);
2808 offset
= read_im16(env
, s
);
2809 gen_link(s
, insn
, offset
);
2816 offset
= read_im32(env
, s
);
2817 gen_link(s
, insn
, offset
);
2826 src
= tcg_temp_new();
2827 reg
= AREG(insn
, 0);
2828 tcg_gen_mov_i32(src
, reg
);
2829 tmp
= gen_load(s
, OS_LONG
, src
, 0, IS_USER(s
));
2830 tcg_gen_mov_i32(reg
, tmp
);
2831 tcg_gen_addi_i32(QREG_SP
, src
, 4);
2834 #if !defined(CONFIG_USER_ONLY)
2838 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
2842 gen_helper_reset(cpu_env
);
2853 int16_t offset
= read_im16(env
, s
);
2855 tmp
= gen_load(s
, OS_LONG
, QREG_SP
, 0, IS_USER(s
));
2856 tcg_gen_addi_i32(QREG_SP
, QREG_SP
, offset
+ 4);
2866 sp
= tcg_temp_new();
2867 ccr
= gen_load(s
, OS_WORD
, QREG_SP
, 0, IS_USER(s
));
2868 tcg_gen_addi_i32(sp
, QREG_SP
, 2);
2869 tmp
= gen_load(s
, OS_LONG
, sp
, 0, IS_USER(s
));
2870 tcg_gen_addi_i32(QREG_SP
, sp
, 4);
2872 gen_set_sr(s
, ccr
, true);
2881 tmp
= gen_load(s
, OS_LONG
, QREG_SP
, 0, IS_USER(s
));
2882 tcg_gen_addi_i32(QREG_SP
, QREG_SP
, 4);
2891 * Load the target address first to ensure correct exception
2894 tmp
= gen_lea(env
, s
, insn
, OS_LONG
);
2895 if (IS_NULL_QREG(tmp
)) {
2899 if ((insn
& 0x40) == 0) {
2901 gen_push(s
, tcg_constant_i32(s
->pc
));
2915 if ((insn
& 070) == 010) {
2916 /* Operation on address register is always long. */
2919 opsize
= insn_opsize(insn
);
2921 SRC_EA(env
, src
, opsize
, 1, &addr
);
2922 imm
= (insn
>> 9) & 7;
2926 val
= tcg_constant_i32(imm
);
2927 dest
= tcg_temp_new();
2928 tcg_gen_mov_i32(dest
, src
);
2929 if ((insn
& 0x38) == 0x08) {
2931 * Don't update condition codes if the destination is an
2934 if (insn
& 0x0100) {
2935 tcg_gen_sub_i32(dest
, dest
, val
);
2937 tcg_gen_add_i32(dest
, dest
, val
);
2940 if (insn
& 0x0100) {
2941 tcg_gen_setcond_i32(TCG_COND_LTU
, QREG_CC_X
, dest
, val
);
2942 tcg_gen_sub_i32(dest
, dest
, val
);
2943 set_cc_op(s
, CC_OP_SUBB
+ opsize
);
2945 tcg_gen_add_i32(dest
, dest
, val
);
2946 tcg_gen_setcond_i32(TCG_COND_LTU
, QREG_CC_X
, dest
, val
);
2947 set_cc_op(s
, CC_OP_ADDB
+ opsize
);
2949 gen_update_cc_add(dest
, val
, opsize
);
2951 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
2961 op
= (insn
>> 8) & 0xf;
2962 offset
= (int8_t)insn
;
2964 offset
= (int16_t)read_im16(env
, s
);
2965 } else if (offset
== -1) {
2966 offset
= read_im32(env
, s
);
2970 gen_push(s
, tcg_constant_i32(s
->pc
));
2974 TCGLabel
*l1
= gen_new_label();
2975 gen_jmpcc(s
, ((insn
>> 8) & 0xf) ^ 1, l1
);
2976 gen_jmp_tb(s
, 1, base
+ offset
, s
->base
.pc_next
);
2978 gen_jmp_tb(s
, 0, s
->pc
, s
->base
.pc_next
);
2980 /* Unconditional branch. */
2982 gen_jmp_tb(s
, 0, base
+ offset
, s
->base
.pc_next
);
2988 tcg_gen_movi_i32(DREG(insn
, 9), (int8_t)insn
);
2989 gen_logic_cc(s
, DREG(insn
, 9), OS_LONG
);
3002 SRC_EA(env
, src
, opsize
, (insn
& 0x80) == 0, NULL
);
3003 reg
= DREG(insn
, 9);
3004 tcg_gen_mov_i32(reg
, src
);
3005 gen_logic_cc(s
, src
, opsize
);
3016 opsize
= insn_opsize(insn
);
3017 reg
= gen_extend(s
, DREG(insn
, 9), opsize
, 0);
3018 dest
= tcg_temp_new();
3020 SRC_EA(env
, src
, opsize
, 0, &addr
);
3021 tcg_gen_or_i32(dest
, src
, reg
);
3022 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
3024 SRC_EA(env
, src
, opsize
, 0, NULL
);
3025 tcg_gen_or_i32(dest
, src
, reg
);
3026 gen_partset_reg(opsize
, DREG(insn
, 9), dest
);
3028 gen_logic_cc(s
, dest
, opsize
);
3036 SRC_EA(env
, src
, (insn
& 0x100) ? OS_LONG
: OS_WORD
, 1, NULL
);
3037 reg
= AREG(insn
, 9);
3038 tcg_gen_sub_i32(reg
, reg
, src
);
3041 static inline void gen_subx(DisasContext
*s
, TCGv src
, TCGv dest
, int opsize
)
3045 gen_flush_flags(s
); /* compute old Z */
3048 * Perform subtract with borrow.
3049 * (X, N) = dest - (src + X);
3052 zero
= tcg_constant_i32(0);
3053 tcg_gen_add2_i32(QREG_CC_N
, QREG_CC_X
, src
, zero
, QREG_CC_X
, zero
);
3054 tcg_gen_sub2_i32(QREG_CC_N
, QREG_CC_X
, dest
, zero
, QREG_CC_N
, QREG_CC_X
);
3055 gen_ext(QREG_CC_N
, QREG_CC_N
, opsize
, 1);
3056 tcg_gen_andi_i32(QREG_CC_X
, QREG_CC_X
, 1);
3058 /* Compute signed-overflow for subtract. */
3060 tmp
= tcg_temp_new();
3061 tcg_gen_xor_i32(QREG_CC_V
, QREG_CC_N
, dest
);
3062 tcg_gen_xor_i32(tmp
, dest
, src
);
3063 tcg_gen_and_i32(QREG_CC_V
, QREG_CC_V
, tmp
);
3065 /* Copy the rest of the results into place. */
3066 tcg_gen_or_i32(QREG_CC_Z
, QREG_CC_Z
, QREG_CC_N
); /* !Z is sticky */
3067 tcg_gen_mov_i32(QREG_CC_C
, QREG_CC_X
);
3069 set_cc_op(s
, CC_OP_FLAGS
);
3071 /* result is in QREG_CC_N */
3074 DISAS_INSN(subx_reg
)
3080 opsize
= insn_opsize(insn
);
3082 src
= gen_extend(s
, DREG(insn
, 0), opsize
, 1);
3083 dest
= gen_extend(s
, DREG(insn
, 9), opsize
, 1);
3085 gen_subx(s
, src
, dest
, opsize
);
3087 gen_partset_reg(opsize
, DREG(insn
, 9), QREG_CC_N
);
3090 DISAS_INSN(subx_mem
)
3098 opsize
= insn_opsize(insn
);
3100 addr_src
= AREG(insn
, 0);
3101 tcg_gen_subi_i32(addr_src
, addr_src
, opsize_bytes(opsize
));
3102 src
= gen_load(s
, opsize
, addr_src
, 1, IS_USER(s
));
3104 addr_dest
= AREG(insn
, 9);
3105 tcg_gen_subi_i32(addr_dest
, addr_dest
, opsize_bytes(opsize
));
3106 dest
= gen_load(s
, opsize
, addr_dest
, 1, IS_USER(s
));
3108 gen_subx(s
, src
, dest
, opsize
);
3110 gen_store(s
, opsize
, addr_dest
, QREG_CC_N
, IS_USER(s
));
3118 val
= (insn
>> 9) & 7;
3122 src
= tcg_constant_i32(val
);
3123 gen_logic_cc(s
, src
, OS_LONG
);
3124 DEST_EA(env
, insn
, OS_LONG
, src
, NULL
);
3133 opsize
= insn_opsize(insn
);
3134 SRC_EA(env
, src
, opsize
, 1, NULL
);
3135 reg
= gen_extend(s
, DREG(insn
, 9), opsize
, 1);
3136 gen_update_cc_cmp(s
, reg
, src
, opsize
);
3150 SRC_EA(env
, src
, opsize
, 1, NULL
);
3151 reg
= AREG(insn
, 9);
3152 gen_update_cc_cmp(s
, reg
, src
, OS_LONG
);
3157 int opsize
= insn_opsize(insn
);
3160 /* Post-increment load (mode 3) from Ay. */
3161 src
= gen_ea_mode(env
, s
, 3, REG(insn
, 0), opsize
,
3162 NULL_QREG
, NULL
, EA_LOADS
, IS_USER(s
));
3163 /* Post-increment load (mode 3) from Ax. */
3164 dst
= gen_ea_mode(env
, s
, 3, REG(insn
, 9), opsize
,
3165 NULL_QREG
, NULL
, EA_LOADS
, IS_USER(s
));
3167 gen_update_cc_cmp(s
, dst
, src
, opsize
);
3177 opsize
= insn_opsize(insn
);
3179 SRC_EA(env
, src
, opsize
, 0, &addr
);
3180 dest
= tcg_temp_new();
3181 tcg_gen_xor_i32(dest
, src
, DREG(insn
, 9));
3182 gen_logic_cc(s
, dest
, opsize
);
3183 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
3186 static void do_exg(TCGv reg1
, TCGv reg2
)
3188 TCGv temp
= tcg_temp_new();
3189 tcg_gen_mov_i32(temp
, reg1
);
3190 tcg_gen_mov_i32(reg1
, reg2
);
3191 tcg_gen_mov_i32(reg2
, temp
);
3196 /* exchange Dx and Dy */
3197 do_exg(DREG(insn
, 9), DREG(insn
, 0));
3202 /* exchange Ax and Ay */
3203 do_exg(AREG(insn
, 9), AREG(insn
, 0));
3208 /* exchange Dx and Ay */
3209 do_exg(DREG(insn
, 9), AREG(insn
, 0));
3220 dest
= tcg_temp_new();
3222 opsize
= insn_opsize(insn
);
3223 reg
= DREG(insn
, 9);
3225 SRC_EA(env
, src
, opsize
, 0, &addr
);
3226 tcg_gen_and_i32(dest
, src
, reg
);
3227 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
3229 SRC_EA(env
, src
, opsize
, 0, NULL
);
3230 tcg_gen_and_i32(dest
, src
, reg
);
3231 gen_partset_reg(opsize
, reg
, dest
);
3233 gen_logic_cc(s
, dest
, opsize
);
3241 SRC_EA(env
, src
, (insn
& 0x100) ? OS_LONG
: OS_WORD
, 1, NULL
);
3242 reg
= AREG(insn
, 9);
3243 tcg_gen_add_i32(reg
, reg
, src
);
3246 static inline void gen_addx(DisasContext
*s
, TCGv src
, TCGv dest
, int opsize
)
3250 gen_flush_flags(s
); /* compute old Z */
3253 * Perform addition with carry.
3254 * (X, N) = src + dest + X;
3257 zero
= tcg_constant_i32(0);
3258 tcg_gen_add2_i32(QREG_CC_N
, QREG_CC_X
, QREG_CC_X
, zero
, dest
, zero
);
3259 tcg_gen_add2_i32(QREG_CC_N
, QREG_CC_X
, QREG_CC_N
, QREG_CC_X
, src
, zero
);
3260 gen_ext(QREG_CC_N
, QREG_CC_N
, opsize
, 1);
3262 /* Compute signed-overflow for addition. */
3264 tmp
= tcg_temp_new();
3265 tcg_gen_xor_i32(QREG_CC_V
, QREG_CC_N
, src
);
3266 tcg_gen_xor_i32(tmp
, dest
, src
);
3267 tcg_gen_andc_i32(QREG_CC_V
, QREG_CC_V
, tmp
);
3269 /* Copy the rest of the results into place. */
3270 tcg_gen_or_i32(QREG_CC_Z
, QREG_CC_Z
, QREG_CC_N
); /* !Z is sticky */
3271 tcg_gen_mov_i32(QREG_CC_C
, QREG_CC_X
);
3273 set_cc_op(s
, CC_OP_FLAGS
);
3275 /* result is in QREG_CC_N */
3278 DISAS_INSN(addx_reg
)
3284 opsize
= insn_opsize(insn
);
3286 dest
= gen_extend(s
, DREG(insn
, 9), opsize
, 1);
3287 src
= gen_extend(s
, DREG(insn
, 0), opsize
, 1);
3289 gen_addx(s
, src
, dest
, opsize
);
3291 gen_partset_reg(opsize
, DREG(insn
, 9), QREG_CC_N
);
3294 DISAS_INSN(addx_mem
)
3302 opsize
= insn_opsize(insn
);
3304 addr_src
= AREG(insn
, 0);
3305 tcg_gen_subi_i32(addr_src
, addr_src
, opsize_bytes(opsize
));
3306 src
= gen_load(s
, opsize
, addr_src
, 1, IS_USER(s
));
3308 addr_dest
= AREG(insn
, 9);
3309 tcg_gen_subi_i32(addr_dest
, addr_dest
, opsize_bytes(opsize
));
3310 dest
= gen_load(s
, opsize
, addr_dest
, 1, IS_USER(s
));
3312 gen_addx(s
, src
, dest
, opsize
);
3314 gen_store(s
, opsize
, addr_dest
, QREG_CC_N
, IS_USER(s
));
3317 static inline void shift_im(DisasContext
*s
, uint16_t insn
, int opsize
)
3319 int count
= (insn
>> 9) & 7;
3320 int logical
= insn
& 8;
3321 int left
= insn
& 0x100;
3322 int bits
= opsize_bytes(opsize
) * 8;
3323 TCGv reg
= gen_extend(s
, DREG(insn
, 0), opsize
, !logical
);
3329 tcg_gen_movi_i32(QREG_CC_V
, 0);
3331 tcg_gen_shri_i32(QREG_CC_C
, reg
, bits
- count
);
3332 tcg_gen_shli_i32(QREG_CC_N
, reg
, count
);
3335 * Note that ColdFire always clears V (done above),
3336 * while M68000 sets if the most significant bit is changed at
3337 * any time during the shift operation.
3339 if (!logical
&& m68k_feature(s
->env
, M68K_FEATURE_M68K
)) {
3340 /* if shift count >= bits, V is (reg != 0) */
3341 if (count
>= bits
) {
3342 tcg_gen_setcond_i32(TCG_COND_NE
, QREG_CC_V
, reg
, QREG_CC_V
);
3344 TCGv t0
= tcg_temp_new();
3345 tcg_gen_sari_i32(QREG_CC_V
, reg
, bits
- 1);
3346 tcg_gen_sari_i32(t0
, reg
, bits
- count
- 1);
3347 tcg_gen_setcond_i32(TCG_COND_NE
, QREG_CC_V
, QREG_CC_V
, t0
);
3349 tcg_gen_neg_i32(QREG_CC_V
, QREG_CC_V
);
3352 tcg_gen_shri_i32(QREG_CC_C
, reg
, count
- 1);
3354 tcg_gen_shri_i32(QREG_CC_N
, reg
, count
);
3356 tcg_gen_sari_i32(QREG_CC_N
, reg
, count
);
3360 gen_ext(QREG_CC_N
, QREG_CC_N
, opsize
, 1);
3361 tcg_gen_andi_i32(QREG_CC_C
, QREG_CC_C
, 1);
3362 tcg_gen_mov_i32(QREG_CC_Z
, QREG_CC_N
);
3363 tcg_gen_mov_i32(QREG_CC_X
, QREG_CC_C
);
3365 gen_partset_reg(opsize
, DREG(insn
, 0), QREG_CC_N
);
3366 set_cc_op(s
, CC_OP_FLAGS
);
3369 static inline void shift_reg(DisasContext
*s
, uint16_t insn
, int opsize
)
3371 int logical
= insn
& 8;
3372 int left
= insn
& 0x100;
3373 int bits
= opsize_bytes(opsize
) * 8;
3374 TCGv reg
= gen_extend(s
, DREG(insn
, 0), opsize
, !logical
);
3378 t64
= tcg_temp_new_i64();
3379 s64
= tcg_temp_new_i64();
3380 s32
= tcg_temp_new();
3383 * Note that m68k truncates the shift count modulo 64, not 32.
3384 * In addition, a 64-bit shift makes it easy to find "the last
3385 * bit shifted out", for the carry flag.
3387 tcg_gen_andi_i32(s32
, DREG(insn
, 9), 63);
3388 tcg_gen_extu_i32_i64(s64
, s32
);
3389 tcg_gen_extu_i32_i64(t64
, reg
);
3391 /* Optimistically set V=0. Also used as a zero source below. */
3392 tcg_gen_movi_i32(QREG_CC_V
, 0);
3394 tcg_gen_shl_i64(t64
, t64
, s64
);
3396 if (opsize
== OS_LONG
) {
3397 tcg_gen_extr_i64_i32(QREG_CC_N
, QREG_CC_C
, t64
);
3398 /* Note that C=0 if shift count is 0, and we get that for free. */
3400 TCGv zero
= tcg_constant_i32(0);
3401 tcg_gen_extrl_i64_i32(QREG_CC_N
, t64
);
3402 tcg_gen_shri_i32(QREG_CC_C
, QREG_CC_N
, bits
);
3403 tcg_gen_movcond_i32(TCG_COND_EQ
, QREG_CC_C
,
3404 s32
, zero
, zero
, QREG_CC_C
);
3406 tcg_gen_andi_i32(QREG_CC_C
, QREG_CC_C
, 1);
3408 /* X = C, but only if the shift count was non-zero. */
3409 tcg_gen_movcond_i32(TCG_COND_NE
, QREG_CC_X
, s32
, QREG_CC_V
,
3410 QREG_CC_C
, QREG_CC_X
);
3413 * M68000 sets V if the most significant bit is changed at
3414 * any time during the shift operation. Do this via creating
3415 * an extension of the sign bit, comparing, and discarding
3416 * the bits below the sign bit. I.e.
3417 * int64_t s = (intN_t)reg;
3418 * int64_t t = (int64_t)(intN_t)reg << count;
3419 * V = ((s ^ t) & (-1 << (bits - 1))) != 0
3421 if (!logical
&& m68k_feature(s
->env
, M68K_FEATURE_M68K
)) {
3422 TCGv_i64 tt
= tcg_constant_i64(32);
3423 /* if shift is greater than 32, use 32 */
3424 tcg_gen_movcond_i64(TCG_COND_GT
, s64
, s64
, tt
, tt
, s64
);
3425 /* Sign extend the input to 64 bits; re-do the shift. */
3426 tcg_gen_ext_i32_i64(t64
, reg
);
3427 tcg_gen_shl_i64(s64
, t64
, s64
);
3428 /* Clear all bits that are unchanged. */
3429 tcg_gen_xor_i64(t64
, t64
, s64
);
3430 /* Ignore the bits below the sign bit. */
3431 tcg_gen_andi_i64(t64
, t64
, -1ULL << (bits
- 1));
3432 /* If any bits remain set, we have overflow. */
3433 tcg_gen_setcondi_i64(TCG_COND_NE
, t64
, t64
, 0);
3434 tcg_gen_extrl_i64_i32(QREG_CC_V
, t64
);
3435 tcg_gen_neg_i32(QREG_CC_V
, QREG_CC_V
);
3438 tcg_gen_shli_i64(t64
, t64
, 32);
3440 tcg_gen_shr_i64(t64
, t64
, s64
);
3442 tcg_gen_sar_i64(t64
, t64
, s64
);
3444 tcg_gen_extr_i64_i32(QREG_CC_C
, QREG_CC_N
, t64
);
3446 /* Note that C=0 if shift count is 0, and we get that for free. */
3447 tcg_gen_shri_i32(QREG_CC_C
, QREG_CC_C
, 31);
3449 /* X = C, but only if the shift count was non-zero. */
3450 tcg_gen_movcond_i32(TCG_COND_NE
, QREG_CC_X
, s32
, QREG_CC_V
,
3451 QREG_CC_C
, QREG_CC_X
);
3453 gen_ext(QREG_CC_N
, QREG_CC_N
, opsize
, 1);
3454 tcg_gen_mov_i32(QREG_CC_Z
, QREG_CC_N
);
3456 /* Write back the result. */
3457 gen_partset_reg(opsize
, DREG(insn
, 0), QREG_CC_N
);
3458 set_cc_op(s
, CC_OP_FLAGS
);
3461 DISAS_INSN(shift8_im
)
3463 shift_im(s
, insn
, OS_BYTE
);
3466 DISAS_INSN(shift16_im
)
3468 shift_im(s
, insn
, OS_WORD
);
3471 DISAS_INSN(shift_im
)
3473 shift_im(s
, insn
, OS_LONG
);
3476 DISAS_INSN(shift8_reg
)
3478 shift_reg(s
, insn
, OS_BYTE
);
3481 DISAS_INSN(shift16_reg
)
3483 shift_reg(s
, insn
, OS_WORD
);
3486 DISAS_INSN(shift_reg
)
3488 shift_reg(s
, insn
, OS_LONG
);
3491 DISAS_INSN(shift_mem
)
3493 int logical
= insn
& 8;
3494 int left
= insn
& 0x100;
3498 SRC_EA(env
, src
, OS_WORD
, !logical
, &addr
);
3499 tcg_gen_movi_i32(QREG_CC_V
, 0);
3501 tcg_gen_shri_i32(QREG_CC_C
, src
, 15);
3502 tcg_gen_shli_i32(QREG_CC_N
, src
, 1);
3505 * Note that ColdFire always clears V,
3506 * while M68000 sets if the most significant bit is changed at
3507 * any time during the shift operation
3509 if (!logical
&& m68k_feature(s
->env
, M68K_FEATURE_M68K
)) {
3510 src
= gen_extend(s
, src
, OS_WORD
, 1);
3511 tcg_gen_xor_i32(QREG_CC_V
, QREG_CC_N
, src
);
3514 tcg_gen_mov_i32(QREG_CC_C
, src
);
3516 tcg_gen_shri_i32(QREG_CC_N
, src
, 1);
3518 tcg_gen_sari_i32(QREG_CC_N
, src
, 1);
3522 gen_ext(QREG_CC_N
, QREG_CC_N
, OS_WORD
, 1);
3523 tcg_gen_andi_i32(QREG_CC_C
, QREG_CC_C
, 1);
3524 tcg_gen_mov_i32(QREG_CC_Z
, QREG_CC_N
);
3525 tcg_gen_mov_i32(QREG_CC_X
, QREG_CC_C
);
3527 DEST_EA(env
, insn
, OS_WORD
, QREG_CC_N
, &addr
);
3528 set_cc_op(s
, CC_OP_FLAGS
);
3531 static void rotate(TCGv reg
, TCGv shift
, int left
, int size
)
3535 /* Replicate the 8-bit input so that a 32-bit rotate works. */
3536 tcg_gen_ext8u_i32(reg
, reg
);
3537 tcg_gen_muli_i32(reg
, reg
, 0x01010101);
3540 /* Replicate the 16-bit input so that a 32-bit rotate works. */
3541 tcg_gen_deposit_i32(reg
, reg
, reg
, 16, 16);
3546 tcg_gen_rotl_i32(reg
, reg
, shift
);
3548 tcg_gen_rotr_i32(reg
, reg
, shift
);
3556 tcg_gen_ext8s_i32(reg
, reg
);
3559 tcg_gen_ext16s_i32(reg
, reg
);
3565 /* QREG_CC_X is not affected */
3567 tcg_gen_mov_i32(QREG_CC_N
, reg
);
3568 tcg_gen_mov_i32(QREG_CC_Z
, reg
);
3571 tcg_gen_andi_i32(QREG_CC_C
, reg
, 1);
3573 tcg_gen_shri_i32(QREG_CC_C
, reg
, 31);
3576 tcg_gen_movi_i32(QREG_CC_V
, 0); /* always cleared */
3579 static void rotate_x_flags(TCGv reg
, TCGv X
, int size
)
3583 tcg_gen_ext8s_i32(reg
, reg
);
3586 tcg_gen_ext16s_i32(reg
, reg
);
3591 tcg_gen_mov_i32(QREG_CC_N
, reg
);
3592 tcg_gen_mov_i32(QREG_CC_Z
, reg
);
3593 tcg_gen_mov_i32(QREG_CC_X
, X
);
3594 tcg_gen_mov_i32(QREG_CC_C
, X
);
3595 tcg_gen_movi_i32(QREG_CC_V
, 0);
3598 /* Result of rotate_x() is valid if 0 <= shift <= size */
3599 static TCGv
rotate_x(TCGv reg
, TCGv shift
, int left
, int size
)
3601 TCGv X
, shl
, shr
, shx
, sz
, zero
;
3603 sz
= tcg_constant_i32(size
);
3605 shr
= tcg_temp_new();
3606 shl
= tcg_temp_new();
3607 shx
= tcg_temp_new();
3609 tcg_gen_mov_i32(shl
, shift
); /* shl = shift */
3610 tcg_gen_movi_i32(shr
, size
+ 1);
3611 tcg_gen_sub_i32(shr
, shr
, shift
); /* shr = size + 1 - shift */
3612 tcg_gen_subi_i32(shx
, shift
, 1); /* shx = shift - 1 */
3613 /* shx = shx < 0 ? size : shx; */
3614 zero
= tcg_constant_i32(0);
3615 tcg_gen_movcond_i32(TCG_COND_LT
, shx
, shx
, zero
, sz
, shx
);
3617 tcg_gen_mov_i32(shr
, shift
); /* shr = shift */
3618 tcg_gen_movi_i32(shl
, size
+ 1);
3619 tcg_gen_sub_i32(shl
, shl
, shift
); /* shl = size + 1 - shift */
3620 tcg_gen_sub_i32(shx
, sz
, shift
); /* shx = size - shift */
3623 /* reg = (reg << shl) | (reg >> shr) | (x << shx); */
3625 tcg_gen_shl_i32(shl
, reg
, shl
);
3626 tcg_gen_shr_i32(shr
, reg
, shr
);
3627 tcg_gen_or_i32(reg
, shl
, shr
);
3628 tcg_gen_shl_i32(shx
, QREG_CC_X
, shx
);
3629 tcg_gen_or_i32(reg
, reg
, shx
);
3631 /* X = (reg >> size) & 1 */
3634 tcg_gen_extract_i32(X
, reg
, size
, 1);
3639 /* Result of rotate32_x() is valid if 0 <= shift < 33 */
3640 static TCGv
rotate32_x(TCGv reg
, TCGv shift
, int left
)
3642 TCGv_i64 t0
, shift64
;
3643 TCGv X
, lo
, hi
, zero
;
3645 shift64
= tcg_temp_new_i64();
3646 tcg_gen_extu_i32_i64(shift64
, shift
);
3648 t0
= tcg_temp_new_i64();
3651 lo
= tcg_temp_new();
3652 hi
= tcg_temp_new();
3655 /* create [reg:X:..] */
3657 tcg_gen_shli_i32(lo
, QREG_CC_X
, 31);
3658 tcg_gen_concat_i32_i64(t0
, lo
, reg
);
3662 tcg_gen_rotl_i64(t0
, t0
, shift64
);
3664 /* result is [reg:..:reg:X] */
3666 tcg_gen_extr_i64_i32(lo
, hi
, t0
);
3667 tcg_gen_andi_i32(X
, lo
, 1);
3669 tcg_gen_shri_i32(lo
, lo
, 1);
3671 /* create [..:X:reg] */
3673 tcg_gen_concat_i32_i64(t0
, reg
, QREG_CC_X
);
3675 tcg_gen_rotr_i64(t0
, t0
, shift64
);
3677 /* result is value: [X:reg:..:reg] */
3679 tcg_gen_extr_i64_i32(lo
, hi
, t0
);
3683 tcg_gen_shri_i32(X
, hi
, 31);
3685 /* extract result */
3687 tcg_gen_shli_i32(hi
, hi
, 1);
3689 tcg_gen_or_i32(lo
, lo
, hi
);
3691 /* if shift == 0, register and X are not affected */
3693 zero
= tcg_constant_i32(0);
3694 tcg_gen_movcond_i32(TCG_COND_EQ
, X
, shift
, zero
, QREG_CC_X
, X
);
3695 tcg_gen_movcond_i32(TCG_COND_EQ
, reg
, shift
, zero
, reg
, lo
);
3700 DISAS_INSN(rotate_im
)
3704 int left
= (insn
& 0x100);
3706 tmp
= (insn
>> 9) & 7;
3711 shift
= tcg_constant_i32(tmp
);
3713 rotate(DREG(insn
, 0), shift
, left
, 32);
3715 TCGv X
= rotate32_x(DREG(insn
, 0), shift
, left
);
3716 rotate_x_flags(DREG(insn
, 0), X
, 32);
3719 set_cc_op(s
, CC_OP_FLAGS
);
3722 DISAS_INSN(rotate8_im
)
3724 int left
= (insn
& 0x100);
3729 reg
= gen_extend(s
, DREG(insn
, 0), OS_BYTE
, 0);
3731 tmp
= (insn
>> 9) & 7;
3736 shift
= tcg_constant_i32(tmp
);
3738 rotate(reg
, shift
, left
, 8);
3740 TCGv X
= rotate_x(reg
, shift
, left
, 8);
3741 rotate_x_flags(reg
, X
, 8);
3743 gen_partset_reg(OS_BYTE
, DREG(insn
, 0), reg
);
3744 set_cc_op(s
, CC_OP_FLAGS
);
3747 DISAS_INSN(rotate16_im
)
3749 int left
= (insn
& 0x100);
3754 reg
= gen_extend(s
, DREG(insn
, 0), OS_WORD
, 0);
3755 tmp
= (insn
>> 9) & 7;
3760 shift
= tcg_constant_i32(tmp
);
3762 rotate(reg
, shift
, left
, 16);
3764 TCGv X
= rotate_x(reg
, shift
, left
, 16);
3765 rotate_x_flags(reg
, X
, 16);
3767 gen_partset_reg(OS_WORD
, DREG(insn
, 0), reg
);
3768 set_cc_op(s
, CC_OP_FLAGS
);
3771 DISAS_INSN(rotate_reg
)
3776 int left
= (insn
& 0x100);
3778 reg
= DREG(insn
, 0);
3779 src
= DREG(insn
, 9);
3780 /* shift in [0..63] */
3781 t0
= tcg_temp_new();
3782 tcg_gen_andi_i32(t0
, src
, 63);
3783 t1
= tcg_temp_new_i32();
3785 tcg_gen_andi_i32(t1
, src
, 31);
3786 rotate(reg
, t1
, left
, 32);
3787 /* if shift == 0, clear C */
3788 tcg_gen_movcond_i32(TCG_COND_EQ
, QREG_CC_C
,
3789 t0
, QREG_CC_V
/* 0 */,
3790 QREG_CC_V
/* 0 */, QREG_CC_C
);
3794 tcg_gen_movi_i32(t1
, 33);
3795 tcg_gen_remu_i32(t1
, t0
, t1
);
3796 X
= rotate32_x(DREG(insn
, 0), t1
, left
);
3797 rotate_x_flags(DREG(insn
, 0), X
, 32);
3799 set_cc_op(s
, CC_OP_FLAGS
);
3802 DISAS_INSN(rotate8_reg
)
3807 int left
= (insn
& 0x100);
3809 reg
= gen_extend(s
, DREG(insn
, 0), OS_BYTE
, 0);
3810 src
= DREG(insn
, 9);
3811 /* shift in [0..63] */
3812 t0
= tcg_temp_new_i32();
3813 tcg_gen_andi_i32(t0
, src
, 63);
3814 t1
= tcg_temp_new_i32();
3816 tcg_gen_andi_i32(t1
, src
, 7);
3817 rotate(reg
, t1
, left
, 8);
3818 /* if shift == 0, clear C */
3819 tcg_gen_movcond_i32(TCG_COND_EQ
, QREG_CC_C
,
3820 t0
, QREG_CC_V
/* 0 */,
3821 QREG_CC_V
/* 0 */, QREG_CC_C
);
3825 tcg_gen_movi_i32(t1
, 9);
3826 tcg_gen_remu_i32(t1
, t0
, t1
);
3827 X
= rotate_x(reg
, t1
, left
, 8);
3828 rotate_x_flags(reg
, X
, 8);
3830 gen_partset_reg(OS_BYTE
, DREG(insn
, 0), reg
);
3831 set_cc_op(s
, CC_OP_FLAGS
);
3834 DISAS_INSN(rotate16_reg
)
3839 int left
= (insn
& 0x100);
3841 reg
= gen_extend(s
, DREG(insn
, 0), OS_WORD
, 0);
3842 src
= DREG(insn
, 9);
3843 /* shift in [0..63] */
3844 t0
= tcg_temp_new_i32();
3845 tcg_gen_andi_i32(t0
, src
, 63);
3846 t1
= tcg_temp_new_i32();
3848 tcg_gen_andi_i32(t1
, src
, 15);
3849 rotate(reg
, t1
, left
, 16);
3850 /* if shift == 0, clear C */
3851 tcg_gen_movcond_i32(TCG_COND_EQ
, QREG_CC_C
,
3852 t0
, QREG_CC_V
/* 0 */,
3853 QREG_CC_V
/* 0 */, QREG_CC_C
);
3857 tcg_gen_movi_i32(t1
, 17);
3858 tcg_gen_remu_i32(t1
, t0
, t1
);
3859 X
= rotate_x(reg
, t1
, left
, 16);
3860 rotate_x_flags(reg
, X
, 16);
3862 gen_partset_reg(OS_WORD
, DREG(insn
, 0), reg
);
3863 set_cc_op(s
, CC_OP_FLAGS
);
3866 DISAS_INSN(rotate_mem
)
3871 int left
= (insn
& 0x100);
3873 SRC_EA(env
, src
, OS_WORD
, 0, &addr
);
3875 shift
= tcg_constant_i32(1);
3876 if (insn
& 0x0200) {
3877 rotate(src
, shift
, left
, 16);
3879 TCGv X
= rotate_x(src
, shift
, left
, 16);
3880 rotate_x_flags(src
, X
, 16);
3882 DEST_EA(env
, insn
, OS_WORD
, src
, &addr
);
3883 set_cc_op(s
, CC_OP_FLAGS
);
3886 DISAS_INSN(bfext_reg
)
3888 int ext
= read_im16(env
, s
);
3889 int is_sign
= insn
& 0x200;
3890 TCGv src
= DREG(insn
, 0);
3891 TCGv dst
= DREG(ext
, 12);
3892 int len
= ((extract32(ext
, 0, 5) - 1) & 31) + 1;
3893 int ofs
= extract32(ext
, 6, 5); /* big bit-endian */
3894 int pos
= 32 - ofs
- len
; /* little bit-endian */
3895 TCGv tmp
= tcg_temp_new();
3899 * In general, we're going to rotate the field so that it's at the
3900 * top of the word and then right-shift by the complement of the
3901 * width to extend the field.
3904 /* Variable width. */
3906 /* Variable offset. */
3907 tcg_gen_andi_i32(tmp
, DREG(ext
, 6), 31);
3908 tcg_gen_rotl_i32(tmp
, src
, tmp
);
3910 tcg_gen_rotli_i32(tmp
, src
, ofs
);
3913 shift
= tcg_temp_new();
3914 tcg_gen_neg_i32(shift
, DREG(ext
, 0));
3915 tcg_gen_andi_i32(shift
, shift
, 31);
3916 tcg_gen_sar_i32(QREG_CC_N
, tmp
, shift
);
3918 tcg_gen_mov_i32(dst
, QREG_CC_N
);
3920 tcg_gen_shr_i32(dst
, tmp
, shift
);
3923 /* Immediate width. */
3925 /* Variable offset */
3926 tcg_gen_andi_i32(tmp
, DREG(ext
, 6), 31);
3927 tcg_gen_rotl_i32(tmp
, src
, tmp
);
3932 * Immediate offset. If the field doesn't wrap around the
3933 * end of the word, rely on (s)extract completely.
3936 tcg_gen_rotli_i32(tmp
, src
, ofs
);
3942 tcg_gen_sextract_i32(QREG_CC_N
, src
, pos
, len
);
3944 tcg_gen_mov_i32(dst
, QREG_CC_N
);
3946 tcg_gen_extract_i32(dst
, src
, pos
, len
);
3950 set_cc_op(s
, CC_OP_LOGIC
);
3953 DISAS_INSN(bfext_mem
)
3955 int ext
= read_im16(env
, s
);
3956 int is_sign
= insn
& 0x200;
3957 TCGv dest
= DREG(ext
, 12);
3958 TCGv addr
, len
, ofs
;
3960 addr
= gen_lea(env
, s
, insn
, OS_UNSIZED
);
3961 if (IS_NULL_QREG(addr
)) {
3969 len
= tcg_constant_i32(extract32(ext
, 0, 5));
3974 ofs
= tcg_constant_i32(extract32(ext
, 6, 5));
3978 gen_helper_bfexts_mem(dest
, cpu_env
, addr
, ofs
, len
);
3979 tcg_gen_mov_i32(QREG_CC_N
, dest
);
3981 TCGv_i64 tmp
= tcg_temp_new_i64();
3982 gen_helper_bfextu_mem(tmp
, cpu_env
, addr
, ofs
, len
);
3983 tcg_gen_extr_i64_i32(dest
, QREG_CC_N
, tmp
);
3985 set_cc_op(s
, CC_OP_LOGIC
);
3988 DISAS_INSN(bfop_reg
)
3990 int ext
= read_im16(env
, s
);
3991 TCGv src
= DREG(insn
, 0);
3992 int len
= ((extract32(ext
, 0, 5) - 1) & 31) + 1;
3993 int ofs
= extract32(ext
, 6, 5); /* big bit-endian */
3994 TCGv mask
, tofs
= NULL
, tlen
= NULL
;
3995 bool is_bfffo
= (insn
& 0x0f00) == 0x0d00;
3997 if ((ext
& 0x820) == 0) {
3998 /* Immediate width and offset. */
3999 uint32_t maski
= 0x7fffffffu
>> (len
- 1);
4000 if (ofs
+ len
<= 32) {
4001 tcg_gen_shli_i32(QREG_CC_N
, src
, ofs
);
4003 tcg_gen_rotli_i32(QREG_CC_N
, src
, ofs
);
4005 tcg_gen_andi_i32(QREG_CC_N
, QREG_CC_N
, ~maski
);
4007 mask
= tcg_constant_i32(ror32(maski
, ofs
));
4009 tofs
= tcg_constant_i32(ofs
);
4010 tlen
= tcg_constant_i32(len
);
4013 TCGv tmp
= tcg_temp_new();
4015 mask
= tcg_temp_new();
4017 /* Variable width */
4018 tcg_gen_subi_i32(tmp
, DREG(ext
, 0), 1);
4019 tcg_gen_andi_i32(tmp
, tmp
, 31);
4020 tcg_gen_shr_i32(mask
, tcg_constant_i32(0x7fffffffu
), tmp
);
4022 tlen
= tcg_temp_new();
4023 tcg_gen_addi_i32(tlen
, tmp
, 1);
4026 /* Immediate width */
4027 tcg_gen_movi_i32(mask
, 0x7fffffffu
>> (len
- 1));
4029 tlen
= tcg_constant_i32(len
);
4034 /* Variable offset */
4035 tcg_gen_andi_i32(tmp
, DREG(ext
, 6), 31);
4036 tcg_gen_rotl_i32(QREG_CC_N
, src
, tmp
);
4037 tcg_gen_andc_i32(QREG_CC_N
, QREG_CC_N
, mask
);
4038 tcg_gen_rotr_i32(mask
, mask
, tmp
);
4043 /* Immediate offset (and variable width) */
4044 tcg_gen_rotli_i32(QREG_CC_N
, src
, ofs
);
4045 tcg_gen_andc_i32(QREG_CC_N
, QREG_CC_N
, mask
);
4046 tcg_gen_rotri_i32(mask
, mask
, ofs
);
4048 tofs
= tcg_constant_i32(ofs
);
4052 set_cc_op(s
, CC_OP_LOGIC
);
4054 switch (insn
& 0x0f00) {
4055 case 0x0a00: /* bfchg */
4056 tcg_gen_eqv_i32(src
, src
, mask
);
4058 case 0x0c00: /* bfclr */
4059 tcg_gen_and_i32(src
, src
, mask
);
4061 case 0x0d00: /* bfffo */
4062 gen_helper_bfffo_reg(DREG(ext
, 12), QREG_CC_N
, tofs
, tlen
);
4064 case 0x0e00: /* bfset */
4065 tcg_gen_orc_i32(src
, src
, mask
);
4067 case 0x0800: /* bftst */
4068 /* flags already set; no other work to do. */
4071 g_assert_not_reached();
4075 DISAS_INSN(bfop_mem
)
4077 int ext
= read_im16(env
, s
);
4078 TCGv addr
, len
, ofs
;
4081 addr
= gen_lea(env
, s
, insn
, OS_UNSIZED
);
4082 if (IS_NULL_QREG(addr
)) {
4090 len
= tcg_constant_i32(extract32(ext
, 0, 5));
4095 ofs
= tcg_constant_i32(extract32(ext
, 6, 5));
4098 switch (insn
& 0x0f00) {
4099 case 0x0a00: /* bfchg */
4100 gen_helper_bfchg_mem(QREG_CC_N
, cpu_env
, addr
, ofs
, len
);
4102 case 0x0c00: /* bfclr */
4103 gen_helper_bfclr_mem(QREG_CC_N
, cpu_env
, addr
, ofs
, len
);
4105 case 0x0d00: /* bfffo */
4106 t64
= tcg_temp_new_i64();
4107 gen_helper_bfffo_mem(t64
, cpu_env
, addr
, ofs
, len
);
4108 tcg_gen_extr_i64_i32(DREG(ext
, 12), QREG_CC_N
, t64
);
4110 case 0x0e00: /* bfset */
4111 gen_helper_bfset_mem(QREG_CC_N
, cpu_env
, addr
, ofs
, len
);
4113 case 0x0800: /* bftst */
4114 gen_helper_bfexts_mem(QREG_CC_N
, cpu_env
, addr
, ofs
, len
);
4117 g_assert_not_reached();
4119 set_cc_op(s
, CC_OP_LOGIC
);
4122 DISAS_INSN(bfins_reg
)
4124 int ext
= read_im16(env
, s
);
4125 TCGv dst
= DREG(insn
, 0);
4126 TCGv src
= DREG(ext
, 12);
4127 int len
= ((extract32(ext
, 0, 5) - 1) & 31) + 1;
4128 int ofs
= extract32(ext
, 6, 5); /* big bit-endian */
4129 int pos
= 32 - ofs
- len
; /* little bit-endian */
4132 tmp
= tcg_temp_new();
4135 /* Variable width */
4136 tcg_gen_neg_i32(tmp
, DREG(ext
, 0));
4137 tcg_gen_andi_i32(tmp
, tmp
, 31);
4138 tcg_gen_shl_i32(QREG_CC_N
, src
, tmp
);
4140 /* Immediate width */
4141 tcg_gen_shli_i32(QREG_CC_N
, src
, 32 - len
);
4143 set_cc_op(s
, CC_OP_LOGIC
);
4145 /* Immediate width and offset */
4146 if ((ext
& 0x820) == 0) {
4147 /* Check for suitability for deposit. */
4149 tcg_gen_deposit_i32(dst
, dst
, src
, pos
, len
);
4151 uint32_t maski
= -2U << (len
- 1);
4152 uint32_t roti
= (ofs
+ len
) & 31;
4153 tcg_gen_andi_i32(tmp
, src
, ~maski
);
4154 tcg_gen_rotri_i32(tmp
, tmp
, roti
);
4155 tcg_gen_andi_i32(dst
, dst
, ror32(maski
, roti
));
4156 tcg_gen_or_i32(dst
, dst
, tmp
);
4159 TCGv mask
= tcg_temp_new();
4160 TCGv rot
= tcg_temp_new();
4163 /* Variable width */
4164 tcg_gen_subi_i32(rot
, DREG(ext
, 0), 1);
4165 tcg_gen_andi_i32(rot
, rot
, 31);
4166 tcg_gen_movi_i32(mask
, -2);
4167 tcg_gen_shl_i32(mask
, mask
, rot
);
4168 tcg_gen_mov_i32(rot
, DREG(ext
, 0));
4169 tcg_gen_andc_i32(tmp
, src
, mask
);
4171 /* Immediate width (variable offset) */
4172 uint32_t maski
= -2U << (len
- 1);
4173 tcg_gen_andi_i32(tmp
, src
, ~maski
);
4174 tcg_gen_movi_i32(mask
, maski
);
4175 tcg_gen_movi_i32(rot
, len
& 31);
4178 /* Variable offset */
4179 tcg_gen_add_i32(rot
, rot
, DREG(ext
, 6));
4181 /* Immediate offset (variable width) */
4182 tcg_gen_addi_i32(rot
, rot
, ofs
);
4184 tcg_gen_andi_i32(rot
, rot
, 31);
4185 tcg_gen_rotr_i32(mask
, mask
, rot
);
4186 tcg_gen_rotr_i32(tmp
, tmp
, rot
);
4187 tcg_gen_and_i32(dst
, dst
, mask
);
4188 tcg_gen_or_i32(dst
, dst
, tmp
);
4192 DISAS_INSN(bfins_mem
)
4194 int ext
= read_im16(env
, s
);
4195 TCGv src
= DREG(ext
, 12);
4196 TCGv addr
, len
, ofs
;
4198 addr
= gen_lea(env
, s
, insn
, OS_UNSIZED
);
4199 if (IS_NULL_QREG(addr
)) {
4207 len
= tcg_constant_i32(extract32(ext
, 0, 5));
4212 ofs
= tcg_constant_i32(extract32(ext
, 6, 5));
4215 gen_helper_bfins_mem(QREG_CC_N
, cpu_env
, addr
, src
, ofs
, len
);
4216 set_cc_op(s
, CC_OP_LOGIC
);
4222 reg
= DREG(insn
, 0);
4223 gen_logic_cc(s
, reg
, OS_LONG
);
4224 gen_helper_ff1(reg
, reg
);
4232 switch ((insn
>> 7) & 3) {
4237 if (m68k_feature(env
, M68K_FEATURE_CHK2
)) {
4243 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
4246 SRC_EA(env
, src
, opsize
, 1, NULL
);
4247 reg
= gen_extend(s
, DREG(insn
, 9), opsize
, 1);
4250 gen_helper_chk(cpu_env
, reg
, src
);
4256 TCGv addr1
, addr2
, bound1
, bound2
, reg
;
4259 switch ((insn
>> 9) & 3) {
4270 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
4274 ext
= read_im16(env
, s
);
4275 if ((ext
& 0x0800) == 0) {
4276 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
4280 addr1
= gen_lea(env
, s
, insn
, OS_UNSIZED
);
4281 addr2
= tcg_temp_new();
4282 tcg_gen_addi_i32(addr2
, addr1
, opsize_bytes(opsize
));
4284 bound1
= gen_load(s
, opsize
, addr1
, 1, IS_USER(s
));
4285 bound2
= gen_load(s
, opsize
, addr2
, 1, IS_USER(s
));
4287 reg
= tcg_temp_new();
4289 tcg_gen_mov_i32(reg
, AREG(ext
, 12));
4291 gen_ext(reg
, DREG(ext
, 12), opsize
, 1);
4295 gen_helper_chk2(cpu_env
, reg
, bound1
, bound2
);
4298 static void m68k_copy_line(TCGv dst
, TCGv src
, int index
)
4303 addr
= tcg_temp_new();
4305 t0
= tcg_temp_new_i64();
4306 t1
= tcg_temp_new_i64();
4308 tcg_gen_andi_i32(addr
, src
, ~15);
4309 tcg_gen_qemu_ld_i64(t0
, addr
, index
, MO_TEUQ
);
4310 tcg_gen_addi_i32(addr
, addr
, 8);
4311 tcg_gen_qemu_ld_i64(t1
, addr
, index
, MO_TEUQ
);
4313 tcg_gen_andi_i32(addr
, dst
, ~15);
4314 tcg_gen_qemu_st_i64(t0
, addr
, index
, MO_TEUQ
);
4315 tcg_gen_addi_i32(addr
, addr
, 8);
4316 tcg_gen_qemu_st_i64(t1
, addr
, index
, MO_TEUQ
);
4319 DISAS_INSN(move16_reg
)
4321 int index
= IS_USER(s
);
4325 ext
= read_im16(env
, s
);
4326 if ((ext
& (1 << 15)) == 0) {
4327 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
4330 m68k_copy_line(AREG(ext
, 12), AREG(insn
, 0), index
);
4332 /* Ax can be Ay, so save Ay before incrementing Ax */
4333 tmp
= tcg_temp_new();
4334 tcg_gen_mov_i32(tmp
, AREG(ext
, 12));
4335 tcg_gen_addi_i32(AREG(insn
, 0), AREG(insn
, 0), 16);
4336 tcg_gen_addi_i32(AREG(ext
, 12), tmp
, 16);
4339 DISAS_INSN(move16_mem
)
4341 int index
= IS_USER(s
);
4344 reg
= AREG(insn
, 0);
4345 addr
= tcg_constant_i32(read_im32(env
, s
));
4347 if ((insn
>> 3) & 1) {
4348 /* MOVE16 (xxx).L, (Ay) */
4349 m68k_copy_line(reg
, addr
, index
);
4351 /* MOVE16 (Ay), (xxx).L */
4352 m68k_copy_line(addr
, reg
, index
);
4355 if (((insn
>> 3) & 2) == 0) {
4357 tcg_gen_addi_i32(reg
, reg
, 16);
4367 ext
= read_im16(env
, s
);
4368 if (ext
!= 0x46FC) {
4369 gen_exception(s
, addr
, EXCP_ILLEGAL
);
4372 ext
= read_im16(env
, s
);
4373 if (IS_USER(s
) || (ext
& SR_S
) == 0) {
4374 gen_exception(s
, addr
, EXCP_PRIVILEGE
);
4377 gen_push(s
, gen_get_sr(s
));
4378 gen_set_sr_im(s
, ext
, 0);
4382 DISAS_INSN(move_from_sr
)
4386 if (IS_USER(s
) && m68k_feature(env
, M68K_FEATURE_MOVEFROMSR_PRIV
)) {
4387 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4391 DEST_EA(env
, insn
, OS_WORD
, sr
, NULL
);
4394 #if !defined(CONFIG_USER_ONLY)
4404 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4408 ext
= read_im16(env
, s
);
4410 opsize
= insn_opsize(insn
);
4413 /* address register */
4414 reg
= AREG(ext
, 12);
4418 reg
= DREG(ext
, 12);
4422 addr
= gen_lea(env
, s
, insn
, opsize
);
4423 if (IS_NULL_QREG(addr
)) {
4429 /* from reg to ea */
4430 gen_store(s
, opsize
, addr
, reg
, DFC_INDEX(s
));
4432 /* from ea to reg */
4433 TCGv tmp
= gen_load(s
, opsize
, addr
, 0, SFC_INDEX(s
));
4435 gen_ext(reg
, tmp
, opsize
, 1);
4437 gen_partset_reg(opsize
, reg
, tmp
);
4440 switch (extract32(insn
, 3, 3)) {
4441 case 3: /* Indirect postincrement. */
4442 tcg_gen_addi_i32(AREG(insn
, 0), addr
,
4443 REG(insn
, 0) == 7 && opsize
== OS_BYTE
4445 : opsize_bytes(opsize
));
4447 case 4: /* Indirect predecrememnt. */
4448 tcg_gen_mov_i32(AREG(insn
, 0), addr
);
4453 DISAS_INSN(move_to_sr
)
4456 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4459 gen_move_to_sr(env
, s
, insn
, false);
4463 DISAS_INSN(move_from_usp
)
4466 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4469 tcg_gen_ld_i32(AREG(insn
, 0), cpu_env
,
4470 offsetof(CPUM68KState
, sp
[M68K_USP
]));
4473 DISAS_INSN(move_to_usp
)
4476 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4479 tcg_gen_st_i32(AREG(insn
, 0), cpu_env
,
4480 offsetof(CPUM68KState
, sp
[M68K_USP
]));
4486 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4490 gen_exception(s
, s
->pc
, EXCP_HALT_INSN
);
4498 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4502 ext
= read_im16(env
, s
);
4504 gen_set_sr_im(s
, ext
, 0);
4505 tcg_gen_movi_i32(cpu_halted
, 1);
4506 gen_exception(s
, s
->pc
, EXCP_HLT
);
4512 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4515 gen_exception(s
, s
->base
.pc_next
, EXCP_RTE
);
4518 DISAS_INSN(cf_movec
)
4524 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4528 ext
= read_im16(env
, s
);
4531 reg
= AREG(ext
, 12);
4533 reg
= DREG(ext
, 12);
4535 gen_helper_cf_movec_to(cpu_env
, tcg_constant_i32(ext
& 0xfff), reg
);
4539 DISAS_INSN(m68k_movec
)
4545 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4549 ext
= read_im16(env
, s
);
4552 reg
= AREG(ext
, 12);
4554 reg
= DREG(ext
, 12);
4556 creg
= tcg_constant_i32(ext
& 0xfff);
4558 gen_helper_m68k_movec_to(cpu_env
, creg
, reg
);
4560 gen_helper_m68k_movec_from(reg
, cpu_env
, creg
);
4568 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4571 /* ICache fetch. Implement as no-op. */
4577 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4580 /* Cache push/invalidate. Implement as no-op. */
4586 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4589 /* Cache push/invalidate. Implement as no-op. */
4595 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4598 /* Invalidate cache line. Implement as no-op. */
4601 #if !defined(CONFIG_USER_ONLY)
4607 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4611 opmode
= tcg_constant_i32((insn
>> 3) & 3);
4612 gen_helper_pflush(cpu_env
, AREG(insn
, 0), opmode
);
4620 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4623 is_read
= tcg_constant_i32((insn
>> 5) & 1);
4624 gen_helper_ptest(cpu_env
, AREG(insn
, 0), is_read
);
4630 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4636 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4639 /* TODO: Implement wdebug. */
4640 cpu_abort(env_cpu(env
), "WDEBUG not implemented");
4646 gen_exception(s
, s
->pc
, EXCP_TRAP0
+ (insn
& 0xf));
4649 static void do_trapcc(DisasContext
*s
, DisasCompare
*c
)
4651 if (c
->tcond
!= TCG_COND_NEVER
) {
4652 TCGLabel
*over
= NULL
;
4656 if (c
->tcond
!= TCG_COND_ALWAYS
) {
4657 /* Jump over if !c. */
4658 over
= gen_new_label();
4659 tcg_gen_brcond_i32(tcg_invert_cond(c
->tcond
), c
->v1
, c
->v2
, over
);
4662 tcg_gen_movi_i32(QREG_PC
, s
->pc
);
4663 gen_raise_exception_format2(s
, EXCP_TRAPCC
, s
->base
.pc_next
);
4666 gen_set_label(over
);
4667 s
->base
.is_jmp
= DISAS_NEXT
;
4676 /* Consume and discard the immediate operand. */
4677 switch (extract32(insn
, 0, 3)) {
4678 case 2: /* trapcc.w */
4679 (void)read_im16(env
, s
);
4681 case 3: /* trapcc.l */
4682 (void)read_im32(env
, s
);
4684 case 4: /* trapcc (no operand) */
4687 /* trapcc registered with only valid opmodes */
4688 g_assert_not_reached();
4691 gen_cc_cond(&c
, s
, extract32(insn
, 8, 4));
4699 gen_cc_cond(&c
, s
, 9); /* V set */
4703 static void gen_load_fcr(DisasContext
*s
, TCGv res
, int reg
)
4707 tcg_gen_movi_i32(res
, 0);
4710 tcg_gen_ld_i32(res
, cpu_env
, offsetof(CPUM68KState
, fpsr
));
4713 tcg_gen_ld_i32(res
, cpu_env
, offsetof(CPUM68KState
, fpcr
));
4718 static void gen_store_fcr(DisasContext
*s
, TCGv val
, int reg
)
4724 tcg_gen_st_i32(val
, cpu_env
, offsetof(CPUM68KState
, fpsr
));
4727 gen_helper_set_fpcr(cpu_env
, val
);
4732 static void gen_qemu_store_fcr(DisasContext
*s
, TCGv addr
, int reg
)
4734 int index
= IS_USER(s
);
4737 tmp
= tcg_temp_new();
4738 gen_load_fcr(s
, tmp
, reg
);
4739 tcg_gen_qemu_st_tl(tmp
, addr
, index
, MO_TEUL
);
4742 static void gen_qemu_load_fcr(DisasContext
*s
, TCGv addr
, int reg
)
4744 int index
= IS_USER(s
);
4747 tmp
= tcg_temp_new();
4748 tcg_gen_qemu_ld_tl(tmp
, addr
, index
, MO_TEUL
);
4749 gen_store_fcr(s
, tmp
, reg
);
4753 static void gen_op_fmove_fcr(CPUM68KState
*env
, DisasContext
*s
,
4754 uint32_t insn
, uint32_t ext
)
4756 int mask
= (ext
>> 10) & 7;
4757 int is_write
= (ext
>> 13) & 1;
4758 int mode
= extract32(insn
, 3, 3);
4764 if (mask
!= M68K_FPIAR
&& mask
!= M68K_FPSR
&& mask
!= M68K_FPCR
) {
4765 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
4769 gen_load_fcr(s
, DREG(insn
, 0), mask
);
4771 gen_store_fcr(s
, DREG(insn
, 0), mask
);
4774 case 1: /* An, only with FPIAR */
4775 if (mask
!= M68K_FPIAR
) {
4776 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
4780 gen_load_fcr(s
, AREG(insn
, 0), mask
);
4782 gen_store_fcr(s
, AREG(insn
, 0), mask
);
4785 case 7: /* Immediate */
4786 if (REG(insn
, 0) == 4) {
4788 (mask
!= M68K_FPIAR
&& mask
!= M68K_FPSR
&&
4789 mask
!= M68K_FPCR
)) {
4790 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
4793 tmp
= tcg_constant_i32(read_im32(env
, s
));
4794 gen_store_fcr(s
, tmp
, mask
);
4802 tmp
= gen_lea(env
, s
, insn
, OS_LONG
);
4803 if (IS_NULL_QREG(tmp
)) {
4808 addr
= tcg_temp_new();
4809 tcg_gen_mov_i32(addr
, tmp
);
4814 * 0b100 Floating-Point Control Register
4815 * 0b010 Floating-Point Status Register
4816 * 0b001 Floating-Point Instruction Address Register
4820 if (is_write
&& mode
== 4) {
4821 for (i
= 2; i
>= 0; i
--, mask
>>= 1) {
4823 gen_qemu_store_fcr(s
, addr
, 1 << i
);
4825 tcg_gen_subi_i32(addr
, addr
, opsize_bytes(OS_LONG
));
4829 tcg_gen_mov_i32(AREG(insn
, 0), addr
);
4831 for (i
= 0; i
< 3; i
++, mask
>>= 1) {
4834 gen_qemu_store_fcr(s
, addr
, 1 << i
);
4836 gen_qemu_load_fcr(s
, addr
, 1 << i
);
4838 if (mask
!= 1 || mode
== 3) {
4839 tcg_gen_addi_i32(addr
, addr
, opsize_bytes(OS_LONG
));
4844 tcg_gen_mov_i32(AREG(insn
, 0), addr
);
4849 static void gen_op_fmovem(CPUM68KState
*env
, DisasContext
*s
,
4850 uint32_t insn
, uint32_t ext
)
4854 int mode
= (ext
>> 11) & 0x3;
4855 int is_load
= ((ext
& 0x2000) == 0);
4857 if (m68k_feature(s
->env
, M68K_FEATURE_FPU
)) {
4858 opsize
= OS_EXTENDED
;
4860 opsize
= OS_DOUBLE
; /* FIXME */
4863 addr
= gen_lea(env
, s
, insn
, opsize
);
4864 if (IS_NULL_QREG(addr
)) {
4869 tmp
= tcg_temp_new();
4871 /* Dynamic register list */
4872 tcg_gen_ext8u_i32(tmp
, DREG(ext
, 4));
4874 /* Static register list */
4875 tcg_gen_movi_i32(tmp
, ext
& 0xff);
4878 if (!is_load
&& (mode
& 2) == 0) {
4880 * predecrement addressing mode
4881 * only available to store register to memory
4883 if (opsize
== OS_EXTENDED
) {
4884 gen_helper_fmovemx_st_predec(tmp
, cpu_env
, addr
, tmp
);
4886 gen_helper_fmovemd_st_predec(tmp
, cpu_env
, addr
, tmp
);
4889 /* postincrement addressing mode */
4890 if (opsize
== OS_EXTENDED
) {
4892 gen_helper_fmovemx_ld_postinc(tmp
, cpu_env
, addr
, tmp
);
4894 gen_helper_fmovemx_st_postinc(tmp
, cpu_env
, addr
, tmp
);
4898 gen_helper_fmovemd_ld_postinc(tmp
, cpu_env
, addr
, tmp
);
4900 gen_helper_fmovemd_st_postinc(tmp
, cpu_env
, addr
, tmp
);
4904 if ((insn
& 070) == 030 || (insn
& 070) == 040) {
4905 tcg_gen_mov_i32(AREG(insn
, 0), tmp
);
4910 * ??? FP exceptions are not implemented. Most exceptions are deferred until
4911 * immediately before the next FP instruction is executed.
4918 TCGv_ptr cpu_src
, cpu_dest
;
4920 ext
= read_im16(env
, s
);
4921 opmode
= ext
& 0x7f;
4922 switch ((ext
>> 13) & 7) {
4928 if (insn
== 0xf200 && (ext
& 0xfc00) == 0x5c00) {
4930 TCGv rom_offset
= tcg_constant_i32(opmode
);
4931 cpu_dest
= gen_fp_ptr(REG(ext
, 7));
4932 gen_helper_fconst(cpu_env
, cpu_dest
, rom_offset
);
4936 case 3: /* fmove out */
4937 cpu_src
= gen_fp_ptr(REG(ext
, 7));
4938 opsize
= ext_opsize(ext
, 10);
4939 if (gen_ea_fp(env
, s
, insn
, opsize
, cpu_src
,
4940 EA_STORE
, IS_USER(s
)) == -1) {
4943 gen_helper_ftst(cpu_env
, cpu_src
);
4945 case 4: /* fmove to control register. */
4946 case 5: /* fmove from control register. */
4947 gen_op_fmove_fcr(env
, s
, insn
, ext
);
4949 case 6: /* fmovem */
4951 if ((ext
& 0x1000) == 0 && !m68k_feature(s
->env
, M68K_FEATURE_FPU
)) {
4954 gen_op_fmovem(env
, s
, insn
, ext
);
4957 if (ext
& (1 << 14)) {
4958 /* Source effective address. */
4959 opsize
= ext_opsize(ext
, 10);
4960 cpu_src
= gen_fp_result_ptr();
4961 if (gen_ea_fp(env
, s
, insn
, opsize
, cpu_src
,
4962 EA_LOADS
, IS_USER(s
)) == -1) {
4967 /* Source register. */
4968 opsize
= OS_EXTENDED
;
4969 cpu_src
= gen_fp_ptr(REG(ext
, 10));
4971 cpu_dest
= gen_fp_ptr(REG(ext
, 7));
4974 gen_fp_move(cpu_dest
, cpu_src
);
4976 case 0x40: /* fsmove */
4977 gen_helper_fsround(cpu_env
, cpu_dest
, cpu_src
);
4979 case 0x44: /* fdmove */
4980 gen_helper_fdround(cpu_env
, cpu_dest
, cpu_src
);
4983 gen_helper_firound(cpu_env
, cpu_dest
, cpu_src
);
4986 gen_helper_fsinh(cpu_env
, cpu_dest
, cpu_src
);
4988 case 3: /* fintrz */
4989 gen_helper_fitrunc(cpu_env
, cpu_dest
, cpu_src
);
4992 gen_helper_fsqrt(cpu_env
, cpu_dest
, cpu_src
);
4994 case 0x41: /* fssqrt */
4995 gen_helper_fssqrt(cpu_env
, cpu_dest
, cpu_src
);
4997 case 0x45: /* fdsqrt */
4998 gen_helper_fdsqrt(cpu_env
, cpu_dest
, cpu_src
);
5000 case 0x06: /* flognp1 */
5001 gen_helper_flognp1(cpu_env
, cpu_dest
, cpu_src
);
5003 case 0x08: /* fetoxm1 */
5004 gen_helper_fetoxm1(cpu_env
, cpu_dest
, cpu_src
);
5006 case 0x09: /* ftanh */
5007 gen_helper_ftanh(cpu_env
, cpu_dest
, cpu_src
);
5009 case 0x0a: /* fatan */
5010 gen_helper_fatan(cpu_env
, cpu_dest
, cpu_src
);
5012 case 0x0c: /* fasin */
5013 gen_helper_fasin(cpu_env
, cpu_dest
, cpu_src
);
5015 case 0x0d: /* fatanh */
5016 gen_helper_fatanh(cpu_env
, cpu_dest
, cpu_src
);
5018 case 0x0e: /* fsin */
5019 gen_helper_fsin(cpu_env
, cpu_dest
, cpu_src
);
5021 case 0x0f: /* ftan */
5022 gen_helper_ftan(cpu_env
, cpu_dest
, cpu_src
);
5024 case 0x10: /* fetox */
5025 gen_helper_fetox(cpu_env
, cpu_dest
, cpu_src
);
5027 case 0x11: /* ftwotox */
5028 gen_helper_ftwotox(cpu_env
, cpu_dest
, cpu_src
);
5030 case 0x12: /* ftentox */
5031 gen_helper_ftentox(cpu_env
, cpu_dest
, cpu_src
);
5033 case 0x14: /* flogn */
5034 gen_helper_flogn(cpu_env
, cpu_dest
, cpu_src
);
5036 case 0x15: /* flog10 */
5037 gen_helper_flog10(cpu_env
, cpu_dest
, cpu_src
);
5039 case 0x16: /* flog2 */
5040 gen_helper_flog2(cpu_env
, cpu_dest
, cpu_src
);
5042 case 0x18: /* fabs */
5043 gen_helper_fabs(cpu_env
, cpu_dest
, cpu_src
);
5045 case 0x58: /* fsabs */
5046 gen_helper_fsabs(cpu_env
, cpu_dest
, cpu_src
);
5048 case 0x5c: /* fdabs */
5049 gen_helper_fdabs(cpu_env
, cpu_dest
, cpu_src
);
5051 case 0x19: /* fcosh */
5052 gen_helper_fcosh(cpu_env
, cpu_dest
, cpu_src
);
5054 case 0x1a: /* fneg */
5055 gen_helper_fneg(cpu_env
, cpu_dest
, cpu_src
);
5057 case 0x5a: /* fsneg */
5058 gen_helper_fsneg(cpu_env
, cpu_dest
, cpu_src
);
5060 case 0x5e: /* fdneg */
5061 gen_helper_fdneg(cpu_env
, cpu_dest
, cpu_src
);
5063 case 0x1c: /* facos */
5064 gen_helper_facos(cpu_env
, cpu_dest
, cpu_src
);
5066 case 0x1d: /* fcos */
5067 gen_helper_fcos(cpu_env
, cpu_dest
, cpu_src
);
5069 case 0x1e: /* fgetexp */
5070 gen_helper_fgetexp(cpu_env
, cpu_dest
, cpu_src
);
5072 case 0x1f: /* fgetman */
5073 gen_helper_fgetman(cpu_env
, cpu_dest
, cpu_src
);
5075 case 0x20: /* fdiv */
5076 gen_helper_fdiv(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5078 case 0x60: /* fsdiv */
5079 gen_helper_fsdiv(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5081 case 0x64: /* fddiv */
5082 gen_helper_fddiv(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5084 case 0x21: /* fmod */
5085 gen_helper_fmod(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5087 case 0x22: /* fadd */
5088 gen_helper_fadd(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5090 case 0x62: /* fsadd */
5091 gen_helper_fsadd(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5093 case 0x66: /* fdadd */
5094 gen_helper_fdadd(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5096 case 0x23: /* fmul */
5097 gen_helper_fmul(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5099 case 0x63: /* fsmul */
5100 gen_helper_fsmul(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5102 case 0x67: /* fdmul */
5103 gen_helper_fdmul(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5105 case 0x24: /* fsgldiv */
5106 gen_helper_fsgldiv(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5108 case 0x25: /* frem */
5109 gen_helper_frem(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5111 case 0x26: /* fscale */
5112 gen_helper_fscale(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5114 case 0x27: /* fsglmul */
5115 gen_helper_fsglmul(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5117 case 0x28: /* fsub */
5118 gen_helper_fsub(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5120 case 0x68: /* fssub */
5121 gen_helper_fssub(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5123 case 0x6c: /* fdsub */
5124 gen_helper_fdsub(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5126 case 0x30: case 0x31: case 0x32:
5127 case 0x33: case 0x34: case 0x35:
5128 case 0x36: case 0x37: {
5129 TCGv_ptr cpu_dest2
= gen_fp_ptr(REG(ext
, 0));
5130 gen_helper_fsincos(cpu_env
, cpu_dest
, cpu_dest2
, cpu_src
);
5133 case 0x38: /* fcmp */
5134 gen_helper_fcmp(cpu_env
, cpu_src
, cpu_dest
);
5136 case 0x3a: /* ftst */
5137 gen_helper_ftst(cpu_env
, cpu_src
);
5142 gen_helper_ftst(cpu_env
, cpu_dest
);
5145 /* FIXME: Is this right for offset addressing modes? */
5147 disas_undef_fpu(env
, s
, insn
);
5150 static void gen_fcc_cond(DisasCompare
*c
, DisasContext
*s
, int cond
)
5154 c
->v2
= tcg_constant_i32(0);
5155 /* TODO: Raise BSUN exception. */
5156 fpsr
= tcg_temp_new();
5157 gen_load_fcr(s
, fpsr
, M68K_FPSR
);
5160 case 16: /* Signaling False */
5162 c
->tcond
= TCG_COND_NEVER
;
5164 case 1: /* EQual Z */
5165 case 17: /* Signaling EQual Z */
5166 c
->v1
= tcg_temp_new();
5167 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_Z
);
5168 c
->tcond
= TCG_COND_NE
;
5170 case 2: /* Ordered Greater Than !(A || Z || N) */
5171 case 18: /* Greater Than !(A || Z || N) */
5172 c
->v1
= tcg_temp_new();
5173 tcg_gen_andi_i32(c
->v1
, fpsr
,
5174 FPSR_CC_A
| FPSR_CC_Z
| FPSR_CC_N
);
5175 c
->tcond
= TCG_COND_EQ
;
5177 case 3: /* Ordered Greater than or Equal Z || !(A || N) */
5178 case 19: /* Greater than or Equal Z || !(A || N) */
5179 c
->v1
= tcg_temp_new();
5180 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_A
);
5181 tcg_gen_shli_i32(c
->v1
, c
->v1
, ctz32(FPSR_CC_N
) - ctz32(FPSR_CC_A
));
5182 tcg_gen_andi_i32(fpsr
, fpsr
, FPSR_CC_Z
| FPSR_CC_N
);
5183 tcg_gen_or_i32(c
->v1
, c
->v1
, fpsr
);
5184 tcg_gen_xori_i32(c
->v1
, c
->v1
, FPSR_CC_N
);
5185 c
->tcond
= TCG_COND_NE
;
5187 case 4: /* Ordered Less Than !(!N || A || Z); */
5188 case 20: /* Less Than !(!N || A || Z); */
5189 c
->v1
= tcg_temp_new();
5190 tcg_gen_xori_i32(c
->v1
, fpsr
, FPSR_CC_N
);
5191 tcg_gen_andi_i32(c
->v1
, c
->v1
, FPSR_CC_N
| FPSR_CC_A
| FPSR_CC_Z
);
5192 c
->tcond
= TCG_COND_EQ
;
5194 case 5: /* Ordered Less than or Equal Z || (N && !A) */
5195 case 21: /* Less than or Equal Z || (N && !A) */
5196 c
->v1
= tcg_temp_new();
5197 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_A
);
5198 tcg_gen_shli_i32(c
->v1
, c
->v1
, ctz32(FPSR_CC_N
) - ctz32(FPSR_CC_A
));
5199 tcg_gen_andc_i32(c
->v1
, fpsr
, c
->v1
);
5200 tcg_gen_andi_i32(c
->v1
, c
->v1
, FPSR_CC_Z
| FPSR_CC_N
);
5201 c
->tcond
= TCG_COND_NE
;
5203 case 6: /* Ordered Greater or Less than !(A || Z) */
5204 case 22: /* Greater or Less than !(A || Z) */
5205 c
->v1
= tcg_temp_new();
5206 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_A
| FPSR_CC_Z
);
5207 c
->tcond
= TCG_COND_EQ
;
5209 case 7: /* Ordered !A */
5210 case 23: /* Greater, Less or Equal !A */
5211 c
->v1
= tcg_temp_new();
5212 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_A
);
5213 c
->tcond
= TCG_COND_EQ
;
5215 case 8: /* Unordered A */
5216 case 24: /* Not Greater, Less or Equal A */
5217 c
->v1
= tcg_temp_new();
5218 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_A
);
5219 c
->tcond
= TCG_COND_NE
;
5221 case 9: /* Unordered or Equal A || Z */
5222 case 25: /* Not Greater or Less then A || Z */
5223 c
->v1
= tcg_temp_new();
5224 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_A
| FPSR_CC_Z
);
5225 c
->tcond
= TCG_COND_NE
;
5227 case 10: /* Unordered or Greater Than A || !(N || Z)) */
5228 case 26: /* Not Less or Equal A || !(N || Z)) */
5229 c
->v1
= tcg_temp_new();
5230 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_Z
);
5231 tcg_gen_shli_i32(c
->v1
, c
->v1
, ctz32(FPSR_CC_N
) - ctz32(FPSR_CC_Z
));
5232 tcg_gen_andi_i32(fpsr
, fpsr
, FPSR_CC_A
| FPSR_CC_N
);
5233 tcg_gen_or_i32(c
->v1
, c
->v1
, fpsr
);
5234 tcg_gen_xori_i32(c
->v1
, c
->v1
, FPSR_CC_N
);
5235 c
->tcond
= TCG_COND_NE
;
5237 case 11: /* Unordered or Greater or Equal A || Z || !N */
5238 case 27: /* Not Less Than A || Z || !N */
5239 c
->v1
= tcg_temp_new();
5240 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_A
| FPSR_CC_Z
| FPSR_CC_N
);
5241 tcg_gen_xori_i32(c
->v1
, c
->v1
, FPSR_CC_N
);
5242 c
->tcond
= TCG_COND_NE
;
5244 case 12: /* Unordered or Less Than A || (N && !Z) */
5245 case 28: /* Not Greater than or Equal A || (N && !Z) */
5246 c
->v1
= tcg_temp_new();
5247 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_Z
);
5248 tcg_gen_shli_i32(c
->v1
, c
->v1
, ctz32(FPSR_CC_N
) - ctz32(FPSR_CC_Z
));
5249 tcg_gen_andc_i32(c
->v1
, fpsr
, c
->v1
);
5250 tcg_gen_andi_i32(c
->v1
, c
->v1
, FPSR_CC_A
| FPSR_CC_N
);
5251 c
->tcond
= TCG_COND_NE
;
5253 case 13: /* Unordered or Less or Equal A || Z || N */
5254 case 29: /* Not Greater Than A || Z || N */
5255 c
->v1
= tcg_temp_new();
5256 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_A
| FPSR_CC_Z
| FPSR_CC_N
);
5257 c
->tcond
= TCG_COND_NE
;
5259 case 14: /* Not Equal !Z */
5260 case 30: /* Signaling Not Equal !Z */
5261 c
->v1
= tcg_temp_new();
5262 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_Z
);
5263 c
->tcond
= TCG_COND_EQ
;
5266 case 31: /* Signaling True */
5268 c
->tcond
= TCG_COND_ALWAYS
;
5273 static void gen_fjmpcc(DisasContext
*s
, int cond
, TCGLabel
*l1
)
5277 gen_fcc_cond(&c
, s
, cond
);
5279 tcg_gen_brcond_i32(c
.tcond
, c
.v1
, c
.v2
, l1
);
5289 offset
= (int16_t)read_im16(env
, s
);
5290 if (insn
& (1 << 6)) {
5291 offset
= (offset
<< 16) | read_im16(env
, s
);
5294 l1
= gen_new_label();
5296 gen_fjmpcc(s
, insn
& 0x3f, l1
);
5297 gen_jmp_tb(s
, 0, s
->pc
, s
->base
.pc_next
);
5299 gen_jmp_tb(s
, 1, base
+ offset
, s
->base
.pc_next
);
5309 ext
= read_im16(env
, s
);
5311 gen_fcc_cond(&c
, s
, cond
);
5313 tmp
= tcg_temp_new();
5314 tcg_gen_setcond_i32(c
.tcond
, tmp
, c
.v1
, c
.v2
);
5316 tcg_gen_neg_i32(tmp
, tmp
);
5317 DEST_EA(env
, insn
, OS_BYTE
, tmp
, NULL
);
5326 ext
= read_im16(env
, s
);
5329 /* Consume and discard the immediate operand. */
5330 switch (extract32(insn
, 0, 3)) {
5331 case 2: /* ftrapcc.w */
5332 (void)read_im16(env
, s
);
5334 case 3: /* ftrapcc.l */
5335 (void)read_im32(env
, s
);
5337 case 4: /* ftrapcc (no operand) */
5340 /* ftrapcc registered with only valid opmodes */
5341 g_assert_not_reached();
5344 gen_fcc_cond(&c
, s
, cond
);
5348 #if !defined(CONFIG_USER_ONLY)
5349 DISAS_INSN(frestore
)
5354 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
5357 if (m68k_feature(s
->env
, M68K_FEATURE_M68040
)) {
5358 SRC_EA(env
, addr
, OS_LONG
, 0, NULL
);
5359 /* FIXME: check the state frame */
5361 disas_undef(env
, s
, insn
);
5368 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
5372 if (m68k_feature(s
->env
, M68K_FEATURE_M68040
)) {
5373 /* always write IDLE */
5374 TCGv idle
= tcg_constant_i32(0x41000000);
5375 DEST_EA(env
, insn
, OS_LONG
, idle
, NULL
);
5377 disas_undef(env
, s
, insn
);
5382 static inline TCGv
gen_mac_extract_word(DisasContext
*s
, TCGv val
, int upper
)
5384 TCGv tmp
= tcg_temp_new();
5385 if (s
->env
->macsr
& MACSR_FI
) {
5387 tcg_gen_andi_i32(tmp
, val
, 0xffff0000);
5389 tcg_gen_shli_i32(tmp
, val
, 16);
5390 } else if (s
->env
->macsr
& MACSR_SU
) {
5392 tcg_gen_sari_i32(tmp
, val
, 16);
5394 tcg_gen_ext16s_i32(tmp
, val
);
5397 tcg_gen_shri_i32(tmp
, val
, 16);
5399 tcg_gen_ext16u_i32(tmp
, val
);
5404 static void gen_mac_clear_flags(void)
5406 tcg_gen_andi_i32(QREG_MACSR
, QREG_MACSR
,
5407 ~(MACSR_V
| MACSR_Z
| MACSR_N
| MACSR_EV
));
5423 s
->mactmp
= tcg_temp_new_i64();
5427 ext
= read_im16(env
, s
);
5429 acc
= ((insn
>> 7) & 1) | ((ext
>> 3) & 2);
5430 dual
= ((insn
& 0x30) != 0 && (ext
& 3) != 0);
5431 if (dual
&& !m68k_feature(s
->env
, M68K_FEATURE_CF_EMAC_B
)) {
5432 disas_undef(env
, s
, insn
);
5436 /* MAC with load. */
5437 tmp
= gen_lea(env
, s
, insn
, OS_LONG
);
5438 addr
= tcg_temp_new();
5439 tcg_gen_and_i32(addr
, tmp
, QREG_MAC_MASK
);
5441 * Load the value now to ensure correct exception behavior.
5442 * Perform writeback after reading the MAC inputs.
5444 loadval
= gen_load(s
, OS_LONG
, addr
, 0, IS_USER(s
));
5447 rx
= (ext
& 0x8000) ? AREG(ext
, 12) : DREG(insn
, 12);
5448 ry
= (ext
& 8) ? AREG(ext
, 0) : DREG(ext
, 0);
5450 loadval
= addr
= NULL_QREG
;
5451 rx
= (insn
& 0x40) ? AREG(insn
, 9) : DREG(insn
, 9);
5452 ry
= (insn
& 8) ? AREG(insn
, 0) : DREG(insn
, 0);
5455 gen_mac_clear_flags();
5458 /* Disabled because conditional branches clobber temporary vars. */
5459 if ((s
->env
->macsr
& MACSR_OMC
) != 0 && !dual
) {
5460 /* Skip the multiply if we know we will ignore it. */
5461 l1
= gen_new_label();
5462 tmp
= tcg_temp_new();
5463 tcg_gen_andi_i32(tmp
, QREG_MACSR
, 1 << (acc
+ 8));
5464 gen_op_jmp_nz32(tmp
, l1
);
5468 if ((ext
& 0x0800) == 0) {
5470 rx
= gen_mac_extract_word(s
, rx
, (ext
& 0x80) != 0);
5471 ry
= gen_mac_extract_word(s
, ry
, (ext
& 0x40) != 0);
5473 if (s
->env
->macsr
& MACSR_FI
) {
5474 gen_helper_macmulf(s
->mactmp
, cpu_env
, rx
, ry
);
5476 if (s
->env
->macsr
& MACSR_SU
)
5477 gen_helper_macmuls(s
->mactmp
, cpu_env
, rx
, ry
);
5479 gen_helper_macmulu(s
->mactmp
, cpu_env
, rx
, ry
);
5480 switch ((ext
>> 9) & 3) {
5482 tcg_gen_shli_i64(s
->mactmp
, s
->mactmp
, 1);
5485 tcg_gen_shri_i64(s
->mactmp
, s
->mactmp
, 1);
5491 /* Save the overflow flag from the multiply. */
5492 saved_flags
= tcg_temp_new();
5493 tcg_gen_mov_i32(saved_flags
, QREG_MACSR
);
5495 saved_flags
= NULL_QREG
;
5499 /* Disabled because conditional branches clobber temporary vars. */
5500 if ((s
->env
->macsr
& MACSR_OMC
) != 0 && dual
) {
5501 /* Skip the accumulate if the value is already saturated. */
5502 l1
= gen_new_label();
5503 tmp
= tcg_temp_new();
5504 gen_op_and32(tmp
, QREG_MACSR
, tcg_constant_i32(MACSR_PAV0
<< acc
));
5505 gen_op_jmp_nz32(tmp
, l1
);
5510 tcg_gen_sub_i64(MACREG(acc
), MACREG(acc
), s
->mactmp
);
5512 tcg_gen_add_i64(MACREG(acc
), MACREG(acc
), s
->mactmp
);
5514 if (s
->env
->macsr
& MACSR_FI
)
5515 gen_helper_macsatf(cpu_env
, tcg_constant_i32(acc
));
5516 else if (s
->env
->macsr
& MACSR_SU
)
5517 gen_helper_macsats(cpu_env
, tcg_constant_i32(acc
));
5519 gen_helper_macsatu(cpu_env
, tcg_constant_i32(acc
));
5522 /* Disabled because conditional branches clobber temporary vars. */
5528 /* Dual accumulate variant. */
5529 acc
= (ext
>> 2) & 3;
5530 /* Restore the overflow flag from the multiplier. */
5531 tcg_gen_mov_i32(QREG_MACSR
, saved_flags
);
5533 /* Disabled because conditional branches clobber temporary vars. */
5534 if ((s
->env
->macsr
& MACSR_OMC
) != 0) {
5535 /* Skip the accumulate if the value is already saturated. */
5536 l1
= gen_new_label();
5537 tmp
= tcg_temp_new();
5538 gen_op_and32(tmp
, QREG_MACSR
, tcg_constant_i32(MACSR_PAV0
<< acc
));
5539 gen_op_jmp_nz32(tmp
, l1
);
5543 tcg_gen_sub_i64(MACREG(acc
), MACREG(acc
), s
->mactmp
);
5545 tcg_gen_add_i64(MACREG(acc
), MACREG(acc
), s
->mactmp
);
5546 if (s
->env
->macsr
& MACSR_FI
)
5547 gen_helper_macsatf(cpu_env
, tcg_constant_i32(acc
));
5548 else if (s
->env
->macsr
& MACSR_SU
)
5549 gen_helper_macsats(cpu_env
, tcg_constant_i32(acc
));
5551 gen_helper_macsatu(cpu_env
, tcg_constant_i32(acc
));
5553 /* Disabled because conditional branches clobber temporary vars. */
5558 gen_helper_mac_set_flags(cpu_env
, tcg_constant_i32(acc
));
5562 rw
= (insn
& 0x40) ? AREG(insn
, 9) : DREG(insn
, 9);
5563 tcg_gen_mov_i32(rw
, loadval
);
5565 * FIXME: Should address writeback happen with the masked or
5568 switch ((insn
>> 3) & 7) {
5569 case 3: /* Post-increment. */
5570 tcg_gen_addi_i32(AREG(insn
, 0), addr
, 4);
5572 case 4: /* Pre-decrement. */
5573 tcg_gen_mov_i32(AREG(insn
, 0), addr
);
5578 DISAS_INSN(from_mac
)
5584 rx
= (insn
& 8) ? AREG(insn
, 0) : DREG(insn
, 0);
5585 accnum
= (insn
>> 9) & 3;
5586 acc
= MACREG(accnum
);
5587 if (s
->env
->macsr
& MACSR_FI
) {
5588 gen_helper_get_macf(rx
, cpu_env
, acc
);
5589 } else if ((s
->env
->macsr
& MACSR_OMC
) == 0) {
5590 tcg_gen_extrl_i64_i32(rx
, acc
);
5591 } else if (s
->env
->macsr
& MACSR_SU
) {
5592 gen_helper_get_macs(rx
, acc
);
5594 gen_helper_get_macu(rx
, acc
);
5597 tcg_gen_movi_i64(acc
, 0);
5598 tcg_gen_andi_i32(QREG_MACSR
, QREG_MACSR
, ~(MACSR_PAV0
<< accnum
));
5602 DISAS_INSN(move_mac
)
5604 /* FIXME: This can be done without a helper. */
5608 dest
= tcg_constant_i32((insn
>> 9) & 3);
5609 gen_helper_mac_move(cpu_env
, dest
, tcg_constant_i32(src
));
5610 gen_mac_clear_flags();
5611 gen_helper_mac_set_flags(cpu_env
, dest
);
5614 DISAS_INSN(from_macsr
)
5618 reg
= (insn
& 8) ? AREG(insn
, 0) : DREG(insn
, 0);
5619 tcg_gen_mov_i32(reg
, QREG_MACSR
);
5622 DISAS_INSN(from_mask
)
5625 reg
= (insn
& 8) ? AREG(insn
, 0) : DREG(insn
, 0);
5626 tcg_gen_mov_i32(reg
, QREG_MAC_MASK
);
5629 DISAS_INSN(from_mext
)
5633 reg
= (insn
& 8) ? AREG(insn
, 0) : DREG(insn
, 0);
5634 acc
= tcg_constant_i32((insn
& 0x400) ? 2 : 0);
5635 if (s
->env
->macsr
& MACSR_FI
)
5636 gen_helper_get_mac_extf(reg
, cpu_env
, acc
);
5638 gen_helper_get_mac_exti(reg
, cpu_env
, acc
);
5641 DISAS_INSN(macsr_to_ccr
)
5643 TCGv tmp
= tcg_temp_new();
5645 /* Note that X and C are always cleared. */
5646 tcg_gen_andi_i32(tmp
, QREG_MACSR
, CCF_N
| CCF_Z
| CCF_V
);
5647 gen_helper_set_ccr(cpu_env
, tmp
);
5648 set_cc_op(s
, CC_OP_FLAGS
);
5656 accnum
= (insn
>> 9) & 3;
5657 acc
= MACREG(accnum
);
5658 SRC_EA(env
, val
, OS_LONG
, 0, NULL
);
5659 if (s
->env
->macsr
& MACSR_FI
) {
5660 tcg_gen_ext_i32_i64(acc
, val
);
5661 tcg_gen_shli_i64(acc
, acc
, 8);
5662 } else if (s
->env
->macsr
& MACSR_SU
) {
5663 tcg_gen_ext_i32_i64(acc
, val
);
5665 tcg_gen_extu_i32_i64(acc
, val
);
5667 tcg_gen_andi_i32(QREG_MACSR
, QREG_MACSR
, ~(MACSR_PAV0
<< accnum
));
5668 gen_mac_clear_flags();
5669 gen_helper_mac_set_flags(cpu_env
, tcg_constant_i32(accnum
));
5672 DISAS_INSN(to_macsr
)
5675 SRC_EA(env
, val
, OS_LONG
, 0, NULL
);
5676 gen_helper_set_macsr(cpu_env
, val
);
5683 SRC_EA(env
, val
, OS_LONG
, 0, NULL
);
5684 tcg_gen_ori_i32(QREG_MAC_MASK
, val
, 0xffff0000);
5691 SRC_EA(env
, val
, OS_LONG
, 0, NULL
);
5692 acc
= tcg_constant_i32((insn
& 0x400) ? 2 : 0);
5693 if (s
->env
->macsr
& MACSR_FI
)
5694 gen_helper_set_mac_extf(cpu_env
, val
, acc
);
5695 else if (s
->env
->macsr
& MACSR_SU
)
5696 gen_helper_set_mac_exts(cpu_env
, val
, acc
);
5698 gen_helper_set_mac_extu(cpu_env
, val
, acc
);
5701 static disas_proc opcode_table
[65536];
5704 register_opcode (disas_proc proc
, uint16_t opcode
, uint16_t mask
)
5710 /* Sanity check. All set bits must be included in the mask. */
5711 if (opcode
& ~mask
) {
5713 "qemu internal error: bogus opcode definition %04x/%04x\n",
5718 * This could probably be cleverer. For now just optimize the case where
5719 * the top bits are known.
5721 /* Find the first zero bit in the mask. */
5723 while ((i
& mask
) != 0)
5725 /* Iterate over all combinations of this and lower bits. */
5730 from
= opcode
& ~(i
- 1);
5732 for (i
= from
; i
< to
; i
++) {
5733 if ((i
& mask
) == opcode
)
5734 opcode_table
[i
] = proc
;
5739 * Register m68k opcode handlers. Order is important.
5740 * Later insn override earlier ones.
5742 void register_m68k_insns (CPUM68KState
*env
)
5745 * Build the opcode table only once to avoid
5746 * multithreading issues.
5748 if (opcode_table
[0] != NULL
) {
5753 * use BASE() for instruction available
5754 * for CF_ISA_A and M68000.
5756 #define BASE(name, opcode, mask) \
5757 register_opcode(disas_##name, 0x##opcode, 0x##mask)
5758 #define INSN(name, opcode, mask, feature) do { \
5759 if (m68k_feature(env, M68K_FEATURE_##feature)) \
5760 BASE(name, opcode, mask); \
5762 BASE(undef
, 0000, 0000);
5763 INSN(arith_im
, 0080, fff8
, CF_ISA_A
);
5764 INSN(arith_im
, 0000, ff00
, M68K
);
5765 INSN(chk2
, 00c0
, f9c0
, CHK2
);
5766 INSN(bitrev
, 00c0
, fff8
, CF_ISA_APLUSC
);
5767 BASE(bitop_reg
, 0100, f1c0
);
5768 BASE(bitop_reg
, 0140, f1c0
);
5769 BASE(bitop_reg
, 0180, f1c0
);
5770 BASE(bitop_reg
, 01c0
, f1c0
);
5771 INSN(movep
, 0108, f138
, MOVEP
);
5772 INSN(arith_im
, 0280, fff8
, CF_ISA_A
);
5773 INSN(arith_im
, 0200, ff00
, M68K
);
5774 INSN(undef
, 02c0
, ffc0
, M68K
);
5775 INSN(byterev
, 02c0
, fff8
, CF_ISA_APLUSC
);
5776 INSN(arith_im
, 0480, fff8
, CF_ISA_A
);
5777 INSN(arith_im
, 0400, ff00
, M68K
);
5778 INSN(undef
, 04c0
, ffc0
, M68K
);
5779 INSN(arith_im
, 0600, ff00
, M68K
);
5780 INSN(undef
, 06c0
, ffc0
, M68K
);
5781 INSN(ff1
, 04c0
, fff8
, CF_ISA_APLUSC
);
5782 INSN(arith_im
, 0680, fff8
, CF_ISA_A
);
5783 INSN(arith_im
, 0c00
, ff38
, CF_ISA_A
);
5784 INSN(arith_im
, 0c00
, ff00
, M68K
);
5785 BASE(bitop_im
, 0800, ffc0
);
5786 BASE(bitop_im
, 0840, ffc0
);
5787 BASE(bitop_im
, 0880, ffc0
);
5788 BASE(bitop_im
, 08c0
, ffc0
);
5789 INSN(arith_im
, 0a80
, fff8
, CF_ISA_A
);
5790 INSN(arith_im
, 0a00
, ff00
, M68K
);
5791 #if !defined(CONFIG_USER_ONLY)
5792 INSN(moves
, 0e00
, ff00
, M68K
);
5794 INSN(cas
, 0ac0
, ffc0
, CAS
);
5795 INSN(cas
, 0cc0
, ffc0
, CAS
);
5796 INSN(cas
, 0ec0
, ffc0
, CAS
);
5797 INSN(cas2w
, 0cfc
, ffff
, CAS
);
5798 INSN(cas2l
, 0efc
, ffff
, CAS
);
5799 BASE(move
, 1000, f000
);
5800 BASE(move
, 2000, f000
);
5801 BASE(move
, 3000, f000
);
5802 INSN(chk
, 4000, f040
, M68K
);
5803 INSN(strldsr
, 40e7
, ffff
, CF_ISA_APLUSC
);
5804 INSN(negx
, 4080, fff8
, CF_ISA_A
);
5805 INSN(negx
, 4000, ff00
, M68K
);
5806 INSN(undef
, 40c0
, ffc0
, M68K
);
5807 INSN(move_from_sr
, 40c0
, fff8
, CF_ISA_A
);
5808 INSN(move_from_sr
, 40c0
, ffc0
, M68K
);
5809 BASE(lea
, 41c0
, f1c0
);
5810 BASE(clr
, 4200, ff00
);
5811 BASE(undef
, 42c0
, ffc0
);
5812 INSN(move_from_ccr
, 42c0
, fff8
, CF_ISA_A
);
5813 INSN(move_from_ccr
, 42c0
, ffc0
, M68K
);
5814 INSN(neg
, 4480, fff8
, CF_ISA_A
);
5815 INSN(neg
, 4400, ff00
, M68K
);
5816 INSN(undef
, 44c0
, ffc0
, M68K
);
5817 BASE(move_to_ccr
, 44c0
, ffc0
);
5818 INSN(not, 4680, fff8
, CF_ISA_A
);
5819 INSN(not, 4600, ff00
, M68K
);
5820 #if !defined(CONFIG_USER_ONLY)
5821 BASE(move_to_sr
, 46c0
, ffc0
);
5823 INSN(nbcd
, 4800, ffc0
, M68K
);
5824 INSN(linkl
, 4808, fff8
, M68K
);
5825 BASE(pea
, 4840, ffc0
);
5826 BASE(swap
, 4840, fff8
);
5827 INSN(bkpt
, 4848, fff8
, BKPT
);
5828 INSN(movem
, 48d0
, fbf8
, CF_ISA_A
);
5829 INSN(movem
, 48e8
, fbf8
, CF_ISA_A
);
5830 INSN(movem
, 4880, fb80
, M68K
);
5831 BASE(ext
, 4880, fff8
);
5832 BASE(ext
, 48c0
, fff8
);
5833 BASE(ext
, 49c0
, fff8
);
5834 BASE(tst
, 4a00
, ff00
);
5835 INSN(tas
, 4ac0
, ffc0
, CF_ISA_B
);
5836 INSN(tas
, 4ac0
, ffc0
, M68K
);
5837 #if !defined(CONFIG_USER_ONLY)
5838 INSN(halt
, 4ac8
, ffff
, CF_ISA_A
);
5839 INSN(halt
, 4ac8
, ffff
, M68K
);
5841 INSN(pulse
, 4acc
, ffff
, CF_ISA_A
);
5842 BASE(illegal
, 4afc
, ffff
);
5843 INSN(mull
, 4c00
, ffc0
, CF_ISA_A
);
5844 INSN(mull
, 4c00
, ffc0
, LONG_MULDIV
);
5845 INSN(divl
, 4c40
, ffc0
, CF_ISA_A
);
5846 INSN(divl
, 4c40
, ffc0
, LONG_MULDIV
);
5847 INSN(sats
, 4c80
, fff8
, CF_ISA_B
);
5848 BASE(trap
, 4e40
, fff0
);
5849 BASE(link
, 4e50
, fff8
);
5850 BASE(unlk
, 4e58
, fff8
);
5851 #if !defined(CONFIG_USER_ONLY)
5852 INSN(move_to_usp
, 4e60
, fff8
, USP
);
5853 INSN(move_from_usp
, 4e68
, fff8
, USP
);
5854 INSN(reset
, 4e70
, ffff
, M68K
);
5855 BASE(stop
, 4e72
, ffff
);
5856 BASE(rte
, 4e73
, ffff
);
5857 INSN(cf_movec
, 4e7b
, ffff
, CF_ISA_A
);
5858 INSN(m68k_movec
, 4e7a
, fffe
, MOVEC
);
5860 BASE(nop
, 4e71
, ffff
);
5861 INSN(rtd
, 4e74
, ffff
, RTD
);
5862 BASE(rts
, 4e75
, ffff
);
5863 INSN(trapv
, 4e76
, ffff
, M68K
);
5864 INSN(rtr
, 4e77
, ffff
, M68K
);
5865 BASE(jump
, 4e80
, ffc0
);
5866 BASE(jump
, 4ec0
, ffc0
);
5867 INSN(addsubq
, 5000, f080
, M68K
);
5868 BASE(addsubq
, 5080, f0c0
);
5869 INSN(scc
, 50c0
, f0f8
, CF_ISA_A
); /* Scc.B Dx */
5870 INSN(scc
, 50c0
, f0c0
, M68K
); /* Scc.B <EA> */
5871 INSN(dbcc
, 50c8
, f0f8
, M68K
);
5872 INSN(trapcc
, 50fa
, f0fe
, TRAPCC
); /* opmode 010, 011 */
5873 INSN(trapcc
, 50fc
, f0ff
, TRAPCC
); /* opmode 100 */
5874 INSN(trapcc
, 51fa
, fffe
, CF_ISA_A
); /* TPF (trapf) opmode 010, 011 */
5875 INSN(trapcc
, 51fc
, ffff
, CF_ISA_A
); /* TPF (trapf) opmode 100 */
5877 /* Branch instructions. */
5878 BASE(branch
, 6000, f000
);
5879 /* Disable long branch instructions, then add back the ones we want. */
5880 BASE(undef
, 60ff
, f0ff
); /* All long branches. */
5881 INSN(branch
, 60ff
, f0ff
, CF_ISA_B
);
5882 INSN(undef
, 60ff
, ffff
, CF_ISA_B
); /* bra.l */
5883 INSN(branch
, 60ff
, ffff
, BRAL
);
5884 INSN(branch
, 60ff
, f0ff
, BCCL
);
5886 BASE(moveq
, 7000, f100
);
5887 INSN(mvzs
, 7100, f100
, CF_ISA_B
);
5888 BASE(or, 8000, f000
);
5889 BASE(divw
, 80c0
, f0c0
);
5890 INSN(sbcd_reg
, 8100, f1f8
, M68K
);
5891 INSN(sbcd_mem
, 8108, f1f8
, M68K
);
5892 BASE(addsub
, 9000, f000
);
5893 INSN(undef
, 90c0
, f0c0
, CF_ISA_A
);
5894 INSN(subx_reg
, 9180, f1f8
, CF_ISA_A
);
5895 INSN(subx_reg
, 9100, f138
, M68K
);
5896 INSN(subx_mem
, 9108, f138
, M68K
);
5897 INSN(suba
, 91c0
, f1c0
, CF_ISA_A
);
5898 INSN(suba
, 90c0
, f0c0
, M68K
);
5900 BASE(undef_mac
, a000
, f000
);
5901 INSN(mac
, a000
, f100
, CF_EMAC
);
5902 INSN(from_mac
, a180
, f9b0
, CF_EMAC
);
5903 INSN(move_mac
, a110
, f9fc
, CF_EMAC
);
5904 INSN(from_macsr
,a980
, f9f0
, CF_EMAC
);
5905 INSN(from_mask
, ad80
, fff0
, CF_EMAC
);
5906 INSN(from_mext
, ab80
, fbf0
, CF_EMAC
);
5907 INSN(macsr_to_ccr
, a9c0
, ffff
, CF_EMAC
);
5908 INSN(to_mac
, a100
, f9c0
, CF_EMAC
);
5909 INSN(to_macsr
, a900
, ffc0
, CF_EMAC
);
5910 INSN(to_mext
, ab00
, fbc0
, CF_EMAC
);
5911 INSN(to_mask
, ad00
, ffc0
, CF_EMAC
);
5913 INSN(mov3q
, a140
, f1c0
, CF_ISA_B
);
5914 INSN(cmp
, b000
, f1c0
, CF_ISA_B
); /* cmp.b */
5915 INSN(cmp
, b040
, f1c0
, CF_ISA_B
); /* cmp.w */
5916 INSN(cmpa
, b0c0
, f1c0
, CF_ISA_B
); /* cmpa.w */
5917 INSN(cmp
, b080
, f1c0
, CF_ISA_A
);
5918 INSN(cmpa
, b1c0
, f1c0
, CF_ISA_A
);
5919 INSN(cmp
, b000
, f100
, M68K
);
5920 INSN(eor
, b100
, f100
, M68K
);
5921 INSN(cmpm
, b108
, f138
, M68K
);
5922 INSN(cmpa
, b0c0
, f0c0
, M68K
);
5923 INSN(eor
, b180
, f1c0
, CF_ISA_A
);
5924 BASE(and, c000
, f000
);
5925 INSN(exg_dd
, c140
, f1f8
, M68K
);
5926 INSN(exg_aa
, c148
, f1f8
, M68K
);
5927 INSN(exg_da
, c188
, f1f8
, M68K
);
5928 BASE(mulw
, c0c0
, f0c0
);
5929 INSN(abcd_reg
, c100
, f1f8
, M68K
);
5930 INSN(abcd_mem
, c108
, f1f8
, M68K
);
5931 BASE(addsub
, d000
, f000
);
5932 INSN(undef
, d0c0
, f0c0
, CF_ISA_A
);
5933 INSN(addx_reg
, d180
, f1f8
, CF_ISA_A
);
5934 INSN(addx_reg
, d100
, f138
, M68K
);
5935 INSN(addx_mem
, d108
, f138
, M68K
);
5936 INSN(adda
, d1c0
, f1c0
, CF_ISA_A
);
5937 INSN(adda
, d0c0
, f0c0
, M68K
);
5938 INSN(shift_im
, e080
, f0f0
, CF_ISA_A
);
5939 INSN(shift_reg
, e0a0
, f0f0
, CF_ISA_A
);
5940 INSN(shift8_im
, e000
, f0f0
, M68K
);
5941 INSN(shift16_im
, e040
, f0f0
, M68K
);
5942 INSN(shift_im
, e080
, f0f0
, M68K
);
5943 INSN(shift8_reg
, e020
, f0f0
, M68K
);
5944 INSN(shift16_reg
, e060
, f0f0
, M68K
);
5945 INSN(shift_reg
, e0a0
, f0f0
, M68K
);
5946 INSN(shift_mem
, e0c0
, fcc0
, M68K
);
5947 INSN(rotate_im
, e090
, f0f0
, M68K
);
5948 INSN(rotate8_im
, e010
, f0f0
, M68K
);
5949 INSN(rotate16_im
, e050
, f0f0
, M68K
);
5950 INSN(rotate_reg
, e0b0
, f0f0
, M68K
);
5951 INSN(rotate8_reg
, e030
, f0f0
, M68K
);
5952 INSN(rotate16_reg
, e070
, f0f0
, M68K
);
5953 INSN(rotate_mem
, e4c0
, fcc0
, M68K
);
5954 INSN(bfext_mem
, e9c0
, fdc0
, BITFIELD
); /* bfextu & bfexts */
5955 INSN(bfext_reg
, e9c0
, fdf8
, BITFIELD
);
5956 INSN(bfins_mem
, efc0
, ffc0
, BITFIELD
);
5957 INSN(bfins_reg
, efc0
, fff8
, BITFIELD
);
5958 INSN(bfop_mem
, eac0
, ffc0
, BITFIELD
); /* bfchg */
5959 INSN(bfop_reg
, eac0
, fff8
, BITFIELD
); /* bfchg */
5960 INSN(bfop_mem
, ecc0
, ffc0
, BITFIELD
); /* bfclr */
5961 INSN(bfop_reg
, ecc0
, fff8
, BITFIELD
); /* bfclr */
5962 INSN(bfop_mem
, edc0
, ffc0
, BITFIELD
); /* bfffo */
5963 INSN(bfop_reg
, edc0
, fff8
, BITFIELD
); /* bfffo */
5964 INSN(bfop_mem
, eec0
, ffc0
, BITFIELD
); /* bfset */
5965 INSN(bfop_reg
, eec0
, fff8
, BITFIELD
); /* bfset */
5966 INSN(bfop_mem
, e8c0
, ffc0
, BITFIELD
); /* bftst */
5967 INSN(bfop_reg
, e8c0
, fff8
, BITFIELD
); /* bftst */
5968 BASE(undef_fpu
, f000
, f000
);
5969 INSN(fpu
, f200
, ffc0
, CF_FPU
);
5970 INSN(fbcc
, f280
, ffc0
, CF_FPU
);
5971 INSN(fpu
, f200
, ffc0
, FPU
);
5972 INSN(fscc
, f240
, ffc0
, FPU
);
5973 INSN(ftrapcc
, f27a
, fffe
, FPU
); /* opmode 010, 011 */
5974 INSN(ftrapcc
, f27c
, ffff
, FPU
); /* opmode 100 */
5975 INSN(fbcc
, f280
, ff80
, FPU
);
5976 #if !defined(CONFIG_USER_ONLY)
5977 INSN(frestore
, f340
, ffc0
, CF_FPU
);
5978 INSN(fsave
, f300
, ffc0
, CF_FPU
);
5979 INSN(frestore
, f340
, ffc0
, FPU
);
5980 INSN(fsave
, f300
, ffc0
, FPU
);
5981 INSN(intouch
, f340
, ffc0
, CF_ISA_A
);
5982 INSN(cpushl
, f428
, ff38
, CF_ISA_A
);
5983 INSN(cpush
, f420
, ff20
, M68040
);
5984 INSN(cinv
, f400
, ff20
, M68040
);
5985 INSN(pflush
, f500
, ffe0
, M68040
);
5986 INSN(ptest
, f548
, ffd8
, M68040
);
5987 INSN(wddata
, fb00
, ff00
, CF_ISA_A
);
5988 INSN(wdebug
, fbc0
, ffc0
, CF_ISA_A
);
5990 INSN(move16_mem
, f600
, ffe0
, M68040
);
5991 INSN(move16_reg
, f620
, fff8
, M68040
);
5995 static void m68k_tr_init_disas_context(DisasContextBase
*dcbase
, CPUState
*cpu
)
5997 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
5998 CPUM68KState
*env
= cpu
->env_ptr
;
6001 dc
->pc
= dc
->base
.pc_first
;
6002 /* This value will always be filled in properly before m68k_tr_tb_stop. */
6003 dc
->pc_prev
= 0xdeadbeef;
6004 dc
->cc_op
= CC_OP_DYNAMIC
;
6005 dc
->cc_op_synced
= 1;
6007 dc
->writeback_mask
= 0;
6009 dc
->ss_active
= (M68K_SR_TRACE(env
->sr
) == M68K_SR_TRACE_ANY_INS
);
6010 /* If architectural single step active, limit to 1 */
6011 if (dc
->ss_active
) {
6012 dc
->base
.max_insns
= 1;
6016 static void m68k_tr_tb_start(DisasContextBase
*dcbase
, CPUState
*cpu
)
6020 static void m68k_tr_insn_start(DisasContextBase
*dcbase
, CPUState
*cpu
)
6022 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
6023 tcg_gen_insn_start(dc
->base
.pc_next
, dc
->cc_op
);
6026 static void m68k_tr_translate_insn(DisasContextBase
*dcbase
, CPUState
*cpu
)
6028 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
6029 CPUM68KState
*env
= cpu
->env_ptr
;
6030 uint16_t insn
= read_im16(env
, dc
);
6032 opcode_table
[insn
](env
, dc
, insn
);
6035 dc
->pc_prev
= dc
->base
.pc_next
;
6036 dc
->base
.pc_next
= dc
->pc
;
6038 if (dc
->base
.is_jmp
== DISAS_NEXT
) {
6040 * Stop translation when the next insn might touch a new page.
6041 * This ensures that prefetch aborts at the right place.
6043 * We cannot determine the size of the next insn without
6044 * completely decoding it. However, the maximum insn size
6045 * is 32 bytes, so end if we do not have that much remaining.
6046 * This may produce several small TBs at the end of each page,
6047 * but they will all be linked with goto_tb.
6049 * ??? ColdFire maximum is 4 bytes; MC68000's maximum is also
6050 * smaller than MC68020's.
6052 target_ulong start_page_offset
6053 = dc
->pc
- (dc
->base
.pc_first
& TARGET_PAGE_MASK
);
6055 if (start_page_offset
>= TARGET_PAGE_SIZE
- 32) {
6056 dc
->base
.is_jmp
= DISAS_TOO_MANY
;
6061 static void m68k_tr_tb_stop(DisasContextBase
*dcbase
, CPUState
*cpu
)
6063 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
6065 switch (dc
->base
.is_jmp
) {
6066 case DISAS_NORETURN
:
6068 case DISAS_TOO_MANY
:
6070 gen_jmp_tb(dc
, 0, dc
->pc
, dc
->pc_prev
);
6073 /* We updated CC_OP and PC in gen_jmp/gen_jmp_im. */
6074 if (dc
->ss_active
) {
6075 gen_raise_exception_format2(dc
, EXCP_TRACE
, dc
->pc_prev
);
6077 tcg_gen_lookup_and_goto_ptr();
6082 * We updated CC_OP and PC in gen_exit_tb, but also modified
6083 * other state that may require returning to the main loop.
6085 if (dc
->ss_active
) {
6086 gen_raise_exception_format2(dc
, EXCP_TRACE
, dc
->pc_prev
);
6088 tcg_gen_exit_tb(NULL
, 0);
6092 g_assert_not_reached();
6096 static void m68k_tr_disas_log(const DisasContextBase
*dcbase
,
6097 CPUState
*cpu
, FILE *logfile
)
6099 fprintf(logfile
, "IN: %s\n", lookup_symbol(dcbase
->pc_first
));
6100 target_disas(logfile
, cpu
, dcbase
->pc_first
, dcbase
->tb
->size
);
6103 static const TranslatorOps m68k_tr_ops
= {
6104 .init_disas_context
= m68k_tr_init_disas_context
,
6105 .tb_start
= m68k_tr_tb_start
,
6106 .insn_start
= m68k_tr_insn_start
,
6107 .translate_insn
= m68k_tr_translate_insn
,
6108 .tb_stop
= m68k_tr_tb_stop
,
6109 .disas_log
= m68k_tr_disas_log
,
6112 void gen_intermediate_code(CPUState
*cpu
, TranslationBlock
*tb
, int *max_insns
,
6113 target_ulong pc
, void *host_pc
)
6116 translator_loop(cpu
, tb
, max_insns
, pc
, host_pc
, &m68k_tr_ops
, &dc
.base
);
6119 static double floatx80_to_double(CPUM68KState
*env
, uint16_t high
, uint64_t low
)
6121 floatx80 a
= { .high
= high
, .low
= low
};
6127 u
.f64
= floatx80_to_float64(a
, &env
->fp_status
);
6131 void m68k_cpu_dump_state(CPUState
*cs
, FILE *f
, int flags
)
6133 M68kCPU
*cpu
= M68K_CPU(cs
);
6134 CPUM68KState
*env
= &cpu
->env
;
6137 for (i
= 0; i
< 8; i
++) {
6138 qemu_fprintf(f
, "D%d = %08x A%d = %08x "
6139 "F%d = %04x %016"PRIx64
" (%12g)\n",
6140 i
, env
->dregs
[i
], i
, env
->aregs
[i
],
6141 i
, env
->fregs
[i
].l
.upper
, env
->fregs
[i
].l
.lower
,
6142 floatx80_to_double(env
, env
->fregs
[i
].l
.upper
,
6143 env
->fregs
[i
].l
.lower
));
6145 qemu_fprintf(f
, "PC = %08x ", env
->pc
);
6146 sr
= env
->sr
| cpu_m68k_get_ccr(env
);
6147 qemu_fprintf(f
, "SR = %04x T:%x I:%x %c%c %c%c%c%c%c\n",
6148 sr
, (sr
& SR_T
) >> SR_T_SHIFT
, (sr
& SR_I
) >> SR_I_SHIFT
,
6149 (sr
& SR_S
) ? 'S' : 'U', (sr
& SR_M
) ? '%' : 'I',
6150 (sr
& CCF_X
) ? 'X' : '-', (sr
& CCF_N
) ? 'N' : '-',
6151 (sr
& CCF_Z
) ? 'Z' : '-', (sr
& CCF_V
) ? 'V' : '-',
6152 (sr
& CCF_C
) ? 'C' : '-');
6153 qemu_fprintf(f
, "FPSR = %08x %c%c%c%c ", env
->fpsr
,
6154 (env
->fpsr
& FPSR_CC_A
) ? 'A' : '-',
6155 (env
->fpsr
& FPSR_CC_I
) ? 'I' : '-',
6156 (env
->fpsr
& FPSR_CC_Z
) ? 'Z' : '-',
6157 (env
->fpsr
& FPSR_CC_N
) ? 'N' : '-');
6158 qemu_fprintf(f
, "\n "
6159 "FPCR = %04x ", env
->fpcr
);
6160 switch (env
->fpcr
& FPCR_PREC_MASK
) {
6162 qemu_fprintf(f
, "X ");
6165 qemu_fprintf(f
, "S ");
6168 qemu_fprintf(f
, "D ");
6171 switch (env
->fpcr
& FPCR_RND_MASK
) {
6173 qemu_fprintf(f
, "RN ");
6176 qemu_fprintf(f
, "RZ ");
6179 qemu_fprintf(f
, "RM ");
6182 qemu_fprintf(f
, "RP ");
6185 qemu_fprintf(f
, "\n");
6186 #ifndef CONFIG_USER_ONLY
6187 qemu_fprintf(f
, "%sA7(MSP) = %08x %sA7(USP) = %08x %sA7(ISP) = %08x\n",
6188 env
->current_sp
== M68K_SSP
? "->" : " ", env
->sp
[M68K_SSP
],
6189 env
->current_sp
== M68K_USP
? "->" : " ", env
->sp
[M68K_USP
],
6190 env
->current_sp
== M68K_ISP
? "->" : " ", env
->sp
[M68K_ISP
]);
6191 qemu_fprintf(f
, "VBR = 0x%08x\n", env
->vbr
);
6192 qemu_fprintf(f
, "SFC = %x DFC %x\n", env
->sfc
, env
->dfc
);
6193 qemu_fprintf(f
, "SSW %08x TCR %08x URP %08x SRP %08x\n",
6194 env
->mmu
.ssw
, env
->mmu
.tcr
, env
->mmu
.urp
, env
->mmu
.srp
);
6195 qemu_fprintf(f
, "DTTR0/1: %08x/%08x ITTR0/1: %08x/%08x\n",
6196 env
->mmu
.ttr
[M68K_DTTR0
], env
->mmu
.ttr
[M68K_DTTR1
],
6197 env
->mmu
.ttr
[M68K_ITTR0
], env
->mmu
.ttr
[M68K_ITTR1
]);
6198 qemu_fprintf(f
, "MMUSR %08x, fault at %08x\n",
6199 env
->mmu
.mmusr
, env
->mmu
.ar
);
6200 #endif /* !CONFIG_USER_ONLY */